├── CMakeLists.txt
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── common
├── CMakeLists.txt
├── common.h
├── common_util.h
├── config.cc
├── config.h
├── logging.cc
├── logging.h
├── messages.inl
├── platform.cc
├── platform.h
├── scheduler.cc
└── scheduler.h
├── convert
├── CMakeLists.txt
├── convert_common.h
├── convert_context.h
├── convert_util.cc
├── convert_util.h
├── converter.cc
├── converter.h
├── materializer.cc
├── materializer.h
├── package.cc
├── package.h
├── texturator.cc
├── texturator.h
├── tokens.cc
└── tokens.h
├── gltf
├── CMakeLists.txt
├── cache.cc
├── cache.h
├── disk_stream.cc
├── disk_stream.h
├── disk_util.cc
├── disk_util.h
├── glb_stream.cc
├── glb_stream.h
├── gltf.cc
├── gltf.h
├── image_parsing.cc
├── image_parsing.h
├── internal_util.cc
├── internal_util.h
├── load.cc
├── load.h
├── memory_stream.cc
├── memory_stream.h
├── message.cc
├── message.h
├── messages.inl
├── stream.cc
├── stream.h
├── validate.cc
└── validate.h
├── process
├── CMakeLists.txt
├── access.h
├── animation.cc
├── animation.h
├── color.cc
├── color.h
├── float_image.cc
├── float_image.h
├── image.cc
├── image.h
├── image_fallback.cc
├── image_fallback.h
├── image_gif.cc
├── image_gif.h
├── image_jpg.cc
├── image_jpg.h
├── image_png.cc
├── image_png.h
├── math.cc
├── math.h
├── mesh.cc
├── mesh.h
├── process_util.cc
├── process_util.h
├── skin.cc
└── skin.h
├── testdata
├── ref.csv
├── samp_draco.csv
├── samp_embed.csv
├── samp_glb.csv
├── samp_gltf.csv
└── samp_specgloss.csv
├── tools
├── ufgbatch
│ ├── html_resources
│ │ └── usdz_icon.png
│ ├── ufgbatch.py
│ ├── ufgcommon
│ │ ├── __init__.py
│ │ ├── deploy.py
│ │ ├── diff.py
│ │ ├── process.py
│ │ ├── task.py
│ │ └── util.py
│ ├── ufgtest.py
│ ├── ufgtest.pyproj
│ ├── ufgvalidate.py
│ └── ufgvalidate.pyproj
├── ufginstall
│ ├── patches
│ │ ├── giflib
│ │ │ ├── CMakeLists.txt
│ │ │ ├── giflib-config.cmake
│ │ │ └── unistd.h
│ │ ├── json
│ │ │ ├── CMakeLists.txt
│ │ │ └── json-config.cmake
│ │ ├── stb_image
│ │ │ ├── CMakeLists.txt
│ │ │ ├── stb_image-config.cmake
│ │ │ └── stb_image.cc
│ │ └── tclap
│ │ │ ├── CMakeLists.txt
│ │ │ └── tclap-config.cmake
│ └── ufginstall.py
└── usdviewer.bat
├── ufg-config.cmake
├── ufg_plugin
├── CMakeLists.txt
├── plugInfo.json
├── ufg_plugin.cc
└── ufg_plugin.h
└── usd_from_gltf
├── CMakeLists.txt
├── args.cc
├── args.h
└── usd_from_gltf.cc
/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | cmake_minimum_required (VERSION 3.0)
16 | project (usd_from_gltf)
17 |
18 | # We don't use Python in this tool, but when the USD library is built with
19 | # PXR_PYTHON_SUPPORT_ENABLED it references it anyway.
20 | if (EXISTS "${USD_DIR}/lib/python/")
21 | find_package(Python COMPONENTS Development)
22 | if (NOT Python_FOUND)
23 | message(FATAL_ERROR "Missing python libs.")
24 | endif (NOT Python_FOUND)
25 | endif (EXISTS "${USD_DIR}/lib/python/")
26 |
27 | set(USD_INCLUDE_DIRS
28 | "${USD_DIR}/include"
29 | "${USD_DIR}/include/boost-1_61"
30 | # Visual Studio 2017 requires boost 1.65.1.
31 | "${USD_DIR}/include/boost-1_65_1"
32 | ${Python_INCLUDE_DIRS}
33 | )
34 |
35 | link_directories(
36 | "${USD_DIR}/lib"
37 | ${Python_LIBRARY_DIRS}
38 | )
39 |
40 | if (MSVC)
41 | set(USD_LIBS
42 | gf.lib
43 | plug.lib
44 | sdf.lib
45 | tf.lib
46 | usd.lib
47 | usdGeom.lib
48 | usdShade.lib
49 | usdSkel.lib
50 | usdUtils.lib
51 | vt.lib
52 | )
53 | elseif (APPLE)
54 | set(USD_LIBS
55 | ${Python_LIBRARIES}
56 | -lpthread
57 | libgf.dylib
58 | libplug.dylib
59 | libsdf.dylib
60 | libtf.dylib
61 | libusd.dylib
62 | libusdGeom.dylib
63 | libusdShade.dylib
64 | libusdSkel.dylib
65 | libusdUtils.dylib
66 | libvt.dylib
67 | )
68 | if (Python_FOUND)
69 | list(APPEND USD_LIBS "${USD_DIR}/lib/libboost_python.dylib")
70 | endif (Python_FOUND)
71 | else ()
72 | set(USD_LIBS
73 | ${Python_LIBRARIES}
74 | -lpthread
75 | libgf.so
76 | libplug.so
77 | libsdf.so
78 | libtf.so
79 | libusd.so
80 | libusdGeom.so
81 | libusdShade.so
82 | libusdSkel.so
83 | libusdUtils.so
84 | libvt.so
85 | )
86 | if (Python_FOUND)
87 | list(APPEND USD_LIBS "${USD_DIR}/lib/libboost_python.so")
88 | endif (Python_FOUND)
89 | endif ()
90 |
91 | if (MSVC)
92 | add_compile_definitions(
93 | _CRT_SECURE_NO_WARNINGS
94 | )
95 | add_compile_options(
96 | /wd4996 # Call to 'std::copy' with parameters that may be unsafe
97 | )
98 |
99 | # Use the release runtime for all builds so we can compile the library in Debug
100 | # without having to recompile dependencies.
101 | set(CompilerFlags
102 | CMAKE_CXX_FLAGS
103 | CMAKE_CXX_FLAGS_DEBUG
104 | CMAKE_CXX_FLAGS_RELEASE
105 | CMAKE_C_FLAGS
106 | CMAKE_C_FLAGS_DEBUG
107 | CMAKE_C_FLAGS_RELEASE
108 | )
109 | foreach(CompilerFlag ${CompilerFlags})
110 | string(REPLACE "/MDd" "/MD" ${CompilerFlag} "${${CompilerFlag}}")
111 | string(REPLACE "/RTC1" "" ${CompilerFlag} "${${CompilerFlag}}")
112 | endforeach()
113 |
114 | else (MSVC)
115 | add_compile_options(
116 | -Wno-deprecated # Silence deprecation warnings due to USD headers.
117 | -std=c++14
118 | )
119 |
120 | endif (MSVC)
121 |
122 | # PIC is necessary for building the plugin shared library.
123 | set(CMAKE_POSITION_INDEPENDENT_CODE ON)
124 |
125 | # Set RPATH to locate USD shared libraries on Linux/OSX.
126 | set(CMAKE_INSTALL_RPATH "${USD_DIR}/lib")
127 | set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
128 |
129 | add_subdirectory(common)
130 | add_subdirectory(convert)
131 | add_subdirectory(gltf)
132 | add_subdirectory(process)
133 | add_subdirectory(usd_from_gltf)
134 | add_subdirectory(ufg_plugin)
135 |
136 | install(EXPORT ufglib DESTINATION lib/ufg)
137 | install(FILES ufg-config.cmake DESTINATION .)
138 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # How to Contribute
2 |
3 | We'd love to accept your patches and contributions to this project. There are
4 | just a few small guidelines you need to follow.
5 |
6 | ## Contributor License Agreement
7 |
8 | Contributions to this project must be accompanied by a Contributor License
9 | Agreement. You (or your employer) retain the copyright to your contribution;
10 | this simply gives us permission to use and redistribute your contributions as
11 | part of the project. Head over to to see
12 | your current agreements on file or to sign a new one.
13 |
14 | You generally only need to submit a CLA once, so if you've already submitted one
15 | (even if it was for a different project), you probably don't need to do it
16 | again.
17 |
18 | ## Code reviews
19 |
20 | All submissions, including submissions by project members, require review. We
21 | use GitHub pull requests for this purpose. Consult
22 | [GitHub Help](https://help.github.com/articles/about-pull-requests/) for more
23 | information on using pull requests.
24 |
25 | ## Community Guidelines
26 |
27 | This project follows [Google's Open Source Community
28 | Guidelines](https://opensource.google.com/conduct/).
29 |
--------------------------------------------------------------------------------
/common/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | include_directories(
16 | ..
17 | ${USD_INCLUDE_DIRS}
18 | )
19 |
20 | add_library(common
21 | common.h
22 | common_util.h
23 | config.cc
24 | config.h
25 | logging.cc
26 | logging.h
27 | messages.inl
28 | platform.cc
29 | platform.h
30 | )
31 |
32 | file(GLOB COMMON_HEADERS "*.h")
33 | set_target_properties(common PROPERTIES PUBLIC_HEADER "${COMMON_HEADERS}")
34 |
35 | target_link_libraries(common gltf)
36 |
37 | install(TARGETS common EXPORT ufglib DESTINATION lib/ufg PUBLIC_HEADER DESTINATION include/ufg/common)
38 |
--------------------------------------------------------------------------------
/common/common.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #ifndef UFG_COMMON_COMMON_H_
18 | #define UFG_COMMON_COMMON_H_
19 |
20 | #include
21 | #include "common/platform.h"
22 |
23 | // Disable warnings originating in the USD headers.
24 | #ifdef _MSC_VER
25 | #pragma warning(push)
26 | #pragma warning(disable : 4244) // Conversion from 'double' to 'float'.
27 | #pragma warning(disable : 4305) // Truncation from 'double' to 'float'.
28 | #endif // _MSC_VER
29 | #include "pxr/base/gf/bbox3d.h"
30 | #include "pxr/base/gf/matrix3d.h"
31 | #include "pxr/base/gf/matrix3f.h"
32 | #include "pxr/base/gf/matrix4d.h"
33 | #include "pxr/base/gf/matrix4f.h"
34 | #include "pxr/base/gf/quatd.h"
35 | #include "pxr/base/gf/quatf.h"
36 | #include "pxr/base/gf/quath.h"
37 | #include "pxr/base/gf/range3f.h"
38 | #include "pxr/base/gf/rotation.h"
39 | #include "pxr/base/gf/vec2d.h"
40 | #include "pxr/base/gf/vec2f.h"
41 | #include "pxr/base/gf/vec3d.h"
42 | #include "pxr/base/gf/vec3f.h"
43 | #include "pxr/base/gf/vec3h.h"
44 | #include "pxr/base/gf/vec4d.h"
45 | #include "pxr/base/gf/vec4f.h"
46 | #include "pxr/base/gf/vec4h.h"
47 | #ifdef _MSC_VER
48 | #pragma warning(pop)
49 | #endif // _MSC_VER
50 |
51 | // Enable asserts.
52 | // * This only increases executation time by ~5%, so it's enabled in all builds.
53 | #define UFG_ASSERTS 1
54 |
55 | #if _MSC_VER
56 | #define UFG_BREAK_ON_ASSERT (1 && UFG_ASSERTS)
57 | #else // _MSC_VER
58 | #define UFG_BREAK_ON_ASSERT 0
59 | #endif // _MSC_VER
60 |
61 | namespace ufg {
62 | // NOLINTNEXTLINE: Disable warning about old-style cast (it's not a cast!)
63 | template char(&ArraySizeHelper(T(&)[LEN]))[LEN];
64 | #define UFG_ARRAY_SIZE(array) (sizeof(ufg::ArraySizeHelper(array)))
65 |
66 | #define UFG_CONST_STRLEN(s) (UFG_ARRAY_SIZE(s) - 1)
67 |
68 | template
69 | inline constexpr T Square(T a) {
70 | return a * a;
71 | }
72 | } // namespace ufg
73 |
74 | #endif // UFG_COMMON_COMMON_H_
75 |
--------------------------------------------------------------------------------
/common/common_util.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #ifndef UFG_COMMON_COMMON_UTIL_H_
18 | #define UFG_COMMON_COMMON_UTIL_H_
19 |
20 | #include
21 | #include
22 | #include "common/common.h"
23 |
24 | namespace ufg {
25 | // Return std::vector data, or null if the vector is empty.
26 | template
27 | inline typename Vector::value_type* GetDataOrNull(Vector& v) {
28 | return v.empty() ? nullptr : v.data();
29 | }
30 | template
31 | inline const typename Vector::value_type* GetDataOrNull(const Vector& v) {
32 | return v.empty() ? nullptr : v.data();
33 | }
34 |
35 | struct FileReference {
36 | std::string disk_path;
37 | std::string usd_path;
38 | friend bool operator<(const FileReference& a, const FileReference& b) {
39 | return a.usd_path < b.usd_path;
40 | }
41 | friend bool operator==(const FileReference& a, const FileReference& b) {
42 | return a.usd_path == b.usd_path;
43 | }
44 | friend bool operator!=(const FileReference& a, const FileReference& b) {
45 | return a.usd_path != b.usd_path;
46 | }
47 | };
48 |
49 | inline std::string AppendNumber(const char* prefix, size_t prefix_len,
50 | size_t index) {
51 | const size_t len_max = prefix_len + 24;
52 | std::string text(len_max, 0);
53 | const size_t len = snprintf(&text[0], len_max, "%s%zu", prefix, index);
54 | text.resize(len);
55 | return text;
56 | }
57 |
58 | inline std::string AppendNumber(const char* prefix, size_t index) {
59 | return AppendNumber(prefix, strlen(prefix), index);
60 | }
61 |
62 | inline std::string AppendNumber(const std::string& prefix, size_t index) {
63 | return AppendNumber(prefix.c_str(), prefix.length(), index);
64 | }
65 |
66 | inline std::string AddFileNameSuffix(const std::string& path,
67 | const char* suffix) {
68 | const size_t last_dot_pos = path.rfind('.');
69 | if (last_dot_pos == std::string::npos) {
70 | return path + suffix;
71 | } else {
72 | const char* const ext = path.c_str() + last_dot_pos;
73 | return path.substr(0, last_dot_pos) + suffix + ext;
74 | }
75 | }
76 |
77 | inline const char* GetFileName(const std::string& path) {
78 | const size_t last_slash_pos = path.find_last_of("\\/");
79 | return last_slash_pos == std::string::npos
80 | ? path.c_str()
81 | : path.c_str() + last_slash_pos + 1;
82 | }
83 |
84 | inline std::string GetFileDirectory(const std::string& path) {
85 | const size_t last_slash_pos = path.find_last_of("\\/");
86 | return last_slash_pos == std::string::npos
87 | ? std::string()
88 | : std::string(path.c_str(), last_slash_pos);
89 | }
90 | } // namespace ufg
91 |
92 | #endif // UFG_COMMON_COMMON_UTIL_H_
93 |
--------------------------------------------------------------------------------
/common/config.cc:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #include "common/config.h"
18 |
19 | namespace ufg {
20 | const GfVec3f kColorBlack(0.0f, 0.0f, 0.0f);
21 | const GfVec4f kFallbackBase(1.0f, 0.0f, 1.0f, 1.0f);
22 | const GfVec3f kFallbackDiffuse(1.0f, 0.0f, 1.0f);
23 | const GfVec3f kFallbackNormal(0.0f, 0.0f, 1.0f);
24 | const GfVec3f kFallbackEmissive(0.5f, 0.0f, 0.5f);
25 | const GfVec3f kFallbackSpecular(1.0f, 0.0f, 1.0f);
26 |
27 | const ConvertSettings ConvertSettings::kDefault;
28 | } // namespace ufg
29 |
--------------------------------------------------------------------------------
/common/logging.cc:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #include "common/logging.h"
18 |
19 | namespace ufg {
20 | namespace {
21 | constexpr size_t kFormatTextMax = 8 * 1024;
22 | constexpr size_t kOnceNameMax = 3;
23 |
24 | constexpr Severity WHAT_SEVERITY_INFO = kSeverityNone; // NOLINT: unused
25 | constexpr Severity WHAT_SEVERITY_WARN = kSeverityWarning;
26 | constexpr Severity WHAT_SEVERITY_ERROR = kSeverityError;
27 |
28 | std::string GetAssertText(const char* file, int line, const char* expression) {
29 | char text[kFormatTextMax];
30 | snprintf(text, sizeof(text), "%s(%d) : ASSERT(%s)", file, line, expression);
31 | return text;
32 | }
33 | } // namespace
34 |
35 | const WhatInfo kWhatInfos[UFG_WHAT_COUNT] = {
36 | #define UFG_MSG(severity, id, format) \
37 | {WHAT_SEVERITY_##severity, "UFG_" #severity "_" #id, format},
38 | #include "messages.inl" // NOLINT: Multiple inclusion.
39 | };
40 |
41 | AssertException::AssertException(const char* file, int line,
42 | const char* expression)
43 | : std::runtime_error(GetAssertText(file, line, expression)),
44 | file_(file),
45 | line_(line),
46 | expression_(expression) {}
47 |
48 | ProfileSentry::ProfileSentry(const char* label, bool enable)
49 | : label_(enable ? label : nullptr) {
50 | if (label_) {
51 | time_begin_ = std::clock();
52 | }
53 | }
54 |
55 | ProfileSentry::~ProfileSentry() {
56 | if (label_) {
57 | const std::clock_t time_end = std::clock();
58 | const float elapsed =
59 | static_cast(time_end - time_begin_) / CLOCKS_PER_SEC;
60 | printf("%s: Completed in %.3f seconds.\n", label_, elapsed);
61 | }
62 | }
63 | } // namespace ufg
64 |
--------------------------------------------------------------------------------
/common/messages.inl:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #ifndef UFG_MSG0
18 | #define UFG_MSG0(severity, id, format, ...) UFG_MSG(severity, id, format)
19 | #define UFG_MSG1(severity, id, format, ...) UFG_MSG(severity, id, format)
20 | #define UFG_MSG2(severity, id, format, ...) UFG_MSG(severity, id, format)
21 | #define UFG_MSG3(severity, id, format, ...) UFG_MSG(severity, id, format)
22 | #define UFG_MSG4(severity, id, format, ...) UFG_MSG(severity, id, format)
23 | #define UFG_MSG5(severity, id, format, ...) UFG_MSG(severity, id, format)
24 | #define UFG_MSG6(severity, id, format, ...) UFG_MSG(severity, id, format)
25 | #endif // UFG_MSG0
26 |
27 | UFG_MSG3(ERROR, ASSERT , "%s(%d) : ASSERT(%s)", const char*, file, int, line, const char*, expression)
28 | UFG_MSG1(ERROR, LOAD_PLUGINS , "Unable to load USD plugins. %s", const char*, why)
29 | UFG_MSG1(ERROR, ARGUMENT_UNKNOWN , "Unknown flag: %s", const char*, text)
30 | UFG_MSG0(ERROR, ARGUMENT_PATHS , "Non-even number of paths. Expected: src dst [src dst ...].")
31 | UFG_MSG2(ERROR, ARGUMENT_EXCEPTION , "%s: %s", const char*, id, const char*, err)
32 | UFG_MSG1(ERROR, IO_WRITE_USD , "Cannot write USD: \"%s\"", const char*, path)
33 | UFG_MSG1(ERROR, IO_WRITE_IMAGE , "Cannot write image: \"%s\"", const char*, path)
34 | UFG_MSG1(WARN , IO_DELETE , "Cannot delete file: %s", const char*, path)
35 | UFG_MSG1(ERROR, STOMP , "Would stomp source file: \"%s\"", const char*, path)
36 | UFG_MSG4(WARN , NON_TRIANGLES , "Skipping unsupported %s primitive. Mesh: mesh[%zu].primitives[%zu], name=%s", const char*, prim_type, size_t, mesh_i, size_t, prim_i, const char*, name)
37 | UFG_MSG3(WARN , TEXTURE_LIMIT , "Can't make %zu texture(s) fit in decompressed limit (%zu bytes). Reducing to minimum (%zu bytes).", size_t, count, size_t, decompressed_limit, size_t, decompressed_total)
38 | UFG_MSG2(ERROR, LAYER_CREATE , "Cannot create layer '%s' at: %s", const char*, src_name, const char*, dst_path)
39 | UFG_MSG2(ERROR, USD , "USD: %s (%s)", const char*, commentary, const char*, function)
40 | UFG_MSG2(WARN , USD , "USD: %s (%s)", const char*, commentary, const char*, function)
41 | UFG_MSG2(INFO , USD , "USD: %s (%s)", const char*, commentary, const char*, function)
42 | UFG_MSG2(ERROR, USD_FATAL , "USD: FATAL: %s (%s)", const char*, commentary, const char*, function)
43 | UFG_MSG0(WARN , ALPHA_MASK_UNSUPPORTED , "Alpha mask currently unsupported.")
44 | UFG_MSG0(WARN , CAMERAS_UNSUPPORTED , "Cameras currently unsupported.")
45 | UFG_MSG0(WARN , MORPH_TARGETS_UNSUPPORTED , "Morph targets currently unsupported.")
46 | UFG_MSG0(WARN , MULTIPLE_UVSETS_UNSUPPORTED , "Multiple UV sets unsupported on iOS viewer.")
47 | UFG_MSG0(WARN , SECONDARY_UVSET_DISABLED , "Disabling secondary UV set.")
48 | UFG_MSG0(WARN , SPECULAR_WORKFLOW_UNSUPPORTED, "Specular workflow unsupported on iOS viewer.")
49 | UFG_MSG2(WARN , TEXTURE_WRAP_UNSUPPORTED , "Texture wrap mode [S=%s, T=%s] unsupported on iOS viewer.", const char*, s_mode, const char*, t_mode)
50 | UFG_MSG2(WARN , TEXTURE_FILTER_UNSUPPORTED , "Texture filter mode [min=%s, mag=%s] unsupported on iOS viewer.", const char*, min_filter, const char*, mag_filter)
51 | UFG_MSG0(WARN , VERTEX_COLORS_UNSUPPORTED , "Vertex colors currently unsupported.")
52 | UFG_MSG0(ERROR, IMAGE_FALLBACK_DECODE , "Failed decoding image with fallback decoder.")
53 | UFG_MSG1(ERROR, GIF_RECORD_TYPE , "GIF: Failed getting record type. Error code: %d", int, code)
54 | UFG_MSG1(ERROR, GIF_IMAGE_DESC , "GIF: Failed getting image desc. Error code: %d", int, code)
55 | UFG_MSG1(ERROR, GIF_EXTENSION , "GIF: Failed getting extension. Error code: %d", int, code)
56 | UFG_MSG0(ERROR, GIF_BAD_GCB , "GIF: Invalid Graphics Control Block (GCB).")
57 | UFG_MSG0(ERROR, GIF_NO_RECORDS , "GIF: No image records.")
58 | UFG_MSG1(ERROR, GIF_OPEN , "GIF: Failed opening with error code: %d", int, code)
59 | UFG_MSG2(ERROR, GIF_BAD_SIZE , "GIF: Unexpected image size: <%d, %d>", int, width, int, height)
60 | UFG_MSG6(ERROR, GIF_FRAME_BOUNDS , "GIF: Frame 0 bounds <%u, %u>-<%u, %u> exceeds image size <%u, %u>", uint32_t, x0, uint32_t, y0, uint32_t, x1, uint32_t, y1, uint32_t, width, uint32_t, height)
61 | UFG_MSG1(ERROR, JPG_DECODE_HEADER , "JPG: Failed decoding header with error: %s", const char*, info)
62 | UFG_MSG1(ERROR, JPG_DECOMPRESS , "JPG: Failed decompressing with error: %s", const char*, info)
63 | UFG_MSG1(ERROR, JPG_COMPRESS , "JPG: Failed compressing with error: %s", const char*, info)
64 | UFG_MSG1(ERROR, PNG_DECODE , "PNG: %s", const char*, info)
65 | UFG_MSG1(WARN , PNG_DECODE , "PNG: %s", const char*, info)
66 | UFG_MSG1(ERROR, PNG_ENCODE , "PNG: %s", const char*, info)
67 | UFG_MSG1(WARN , PNG_ENCODE , "PNG: %s", const char*, info)
68 | UFG_MSG0(ERROR, PNG_READ_INIT , "PNG: Failed to initialize for read.")
69 | UFG_MSG2(ERROR, PNG_READ_SHORT , "PNG: Attempt to read %zu bytes, only %zu remain.", size_t, size, size_t, remain)
70 | UFG_MSG0(ERROR, PNG_WRITE_INIT , "PNG: Failed to initialize for write.")
71 | UFG_MSG3(ERROR, DRACO_UNKNOWN , "Draco: Cannot determine geometry type for mesh: mesh[%zu].primitives[%zu], name=%s", size_t, mesh_i, size_t, prim_i, const char*, name)
72 | UFG_MSG3(ERROR, DRACO_LOAD , "Draco: Cannot load data for mesh: mesh[%zu].primitives[%zu], name=%s", size_t, mesh_i, size_t, prim_i, const char*, name)
73 | UFG_MSG3(ERROR, DRACO_DECODE , "Draco: Failed to decode mesh: mesh[%zu].primitives[%zu], name=%s", size_t, mesh_i, size_t, prim_i, const char*, name)
74 | UFG_MSG3(ERROR, DRACO_NON_TRIANGLES , "Draco: Non-triangular mesh: mesh[%zu].primitives[%zu], name=%s", size_t, mesh_i, size_t, prim_i, const char*, name)
75 |
76 | #undef UFG_MSG
77 | #undef UFG_MSG0
78 | #undef UFG_MSG1
79 | #undef UFG_MSG2
80 | #undef UFG_MSG3
81 | #undef UFG_MSG4
82 | #undef UFG_MSG5
83 | #undef UFG_MSG6
84 |
--------------------------------------------------------------------------------
/common/platform.cc:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #include "common/platform.h"
18 |
19 | #ifdef _MSC_VER
20 | #include
21 | #pragma warning(disable : 4996) // 'getcwd' POSIX name is deprecated.
22 | #else // _MSC_VER
23 | #include
24 | #include
25 | #include
26 | #endif // _MSC_VER
27 |
28 | namespace ufg {
29 | std::string GetCwd() {
30 | char buffer[4 * 1024];
31 | const char* const dir = getcwd(buffer, sizeof(buffer));
32 | return dir ? dir : std::string();
33 | }
34 |
35 | void SetCwd(const char* dir) {
36 | if (dir && dir[0]) {
37 | chdir(dir);
38 | }
39 | }
40 | } // namespace ufg
41 |
--------------------------------------------------------------------------------
/common/platform.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #ifndef UFG_COMMON_PLATFORM_H_
18 | #define UFG_COMMON_PLATFORM_H_
19 |
20 | #include
21 |
22 | // Used for DebugBreak.
23 | #ifdef _MSC_VER
24 | #define NOMINMAX
25 | #define WIN32_LEAN_AND_MEAN
26 | #include
27 |
28 | #ifdef ERROR
29 | #undef ERROR
30 | #endif // ERROR
31 | #endif // _MSC_VER
32 |
33 | namespace ufg {
34 | std::string GetCwd();
35 | void SetCwd(const char* dir);
36 | } // namespace ufg
37 |
38 | #endif // UFG_COMMON_PLATFORM_H_
39 |
--------------------------------------------------------------------------------
/common/scheduler.cc:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #include "common/scheduler.h"
18 |
19 | #include "common/logging.h"
20 |
21 | namespace ufg {
22 | namespace {
23 | constexpr size_t kWorkerMax = 64;
24 | } // namespace
25 |
26 | Scheduler::Scheduler() : stopping_(false) {
27 | }
28 |
29 | void Scheduler::Start(size_t worker_count) {
30 | worker_count = std::min(worker_count, kWorkerMax);
31 |
32 | UFG_ASSERT_LOGIC(!stopping_);
33 | UFG_ASSERT_LOGIC(workers_.empty());
34 | UFG_ASSERT_LOGIC(job_queue_.empty());
35 | stopping_ = false;
36 | workers_.reserve(worker_count);
37 | for (size_t worker_index = 0; worker_index != worker_count; ++worker_index) {
38 | workers_.emplace_back(WorkerThread, this, worker_index);
39 | }
40 | }
41 |
42 | void Scheduler::Stop() {
43 | {
44 | std::unique_lock lock(mutex_);
45 | stopping_ = true;
46 | add_or_stop_event_.notify_all();
47 | }
48 | for (std::thread& worker : workers_) {
49 | worker.join();
50 | }
51 | if (!exceptions_.empty()) {
52 | std::rethrow_exception(exceptions_.front());
53 | }
54 | workers_.clear();
55 | UFG_ASSERT_LOGIC(job_queue_.empty());
56 | }
57 |
58 | void Scheduler::WaitForAllComplete() {
59 | std::queue exceptions;
60 | for (;;) {
61 | std::unique_lock lock(mutex_);
62 | if (job_queue_.empty()) {
63 | exceptions.swap(exceptions_);
64 | break;
65 | }
66 | job_done_event_.wait(lock);
67 | }
68 | if (!exceptions.empty()) {
69 | std::rethrow_exception(exceptions.front());
70 | }
71 | }
72 |
73 | void Scheduler::WorkerThread(Scheduler* scheduler, size_t index) {
74 | while (!scheduler->stopping_) {
75 | bool have_job = false;
76 | JobFunction func;
77 | {
78 | std::unique_lock lock(scheduler->mutex_);
79 | if (!scheduler->job_queue_.empty()) {
80 | func.swap(scheduler->job_queue_.front().func);
81 | scheduler->job_queue_.pop();
82 | have_job = true;
83 | } else {
84 | // Wait for a job to become available, or the signal to stop.
85 | // * Don't wait if we're stopping so the event isn't prematurely cleared
86 | // (which could cause a deadlock).
87 | if (!scheduler->stopping_) {
88 | scheduler->add_or_stop_event_.wait(lock);
89 | if (scheduler->stopping_) {
90 | // Waiting on the event clears it, so we need to re-signal it to
91 | // ensure any remaining workers wake up to stop.
92 | scheduler->add_or_stop_event_.notify_all();
93 | }
94 | }
95 | }
96 | }
97 | if (have_job) {
98 | try {
99 | func();
100 | } catch (...) {
101 | std::unique_lock lock(scheduler->mutex_);
102 | scheduler->exceptions_.push(std::current_exception());
103 | }
104 | scheduler->job_done_event_.notify_all();
105 | }
106 | }
107 | }
108 |
109 | void Scheduler::AddJob(JobFunction&& func) {
110 | std::unique_lock lock(mutex_);
111 | job_queue_.push(Job(std::move(func)));
112 | add_or_stop_event_.notify_all();
113 | }
114 | } // namespace ufg
115 |
--------------------------------------------------------------------------------
/common/scheduler.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #ifndef UFG_COMMON_SCHEDULER_H_
18 | #define UFG_COMMON_SCHEDULER_H_
19 |
20 | #include // NOLINT: Unapproved C++11 header.
21 | #include
22 | #include // NOLINT: Unapproved C++11 header.
23 | #include
24 | #include // NOLINT: Unapproved C++11 header.
25 | #include
26 | #include "common/common.h"
27 | #include "common/platform.h"
28 |
29 | namespace ufg {
30 | // Simple multithreaded job scheduler, used to run conversion tasks in parallel.
31 | class Scheduler {
32 | public:
33 | Scheduler();
34 |
35 | // Start worker threads.
36 | // * If worker_count is 0, the scheduler runs jobs immediately in the calling
37 | // thread.
38 | void Start(size_t worker_count);
39 |
40 | // Stop worker threads. This will wait for all queued jobs to complete.
41 | void Stop();
42 |
43 | // Schedule a function to run on a worker thread.
44 | // * The function should have a void() signature.
45 | template
46 | void Schedule(Func func) {
47 | if (workers_.empty()) {
48 | func();
49 | } else {
50 | AddJob(JobFunction(func));
51 | }
52 | }
53 |
54 | // Wait for all scheduled jobs to complete.
55 | void WaitForAllComplete();
56 |
57 | private:
58 | using JobFunction = std::function;
59 | struct Job {
60 | JobFunction func;
61 | Job() {}
62 | explicit Job(JobFunction&& func) : func(func) {}
63 | };
64 | bool stopping_;
65 | std::condition_variable add_or_stop_event_;
66 | std::condition_variable job_done_event_;
67 | std::mutex mutex_;
68 | std::vector workers_;
69 | std::queue job_queue_;
70 | std::queue exceptions_;
71 |
72 | static void WorkerThread(Scheduler* scheduler, size_t index);
73 | void AddJob(JobFunction&& func);
74 | };
75 | } // namespace ufg
76 | #endif // UFG_COMMON_SCHEDULER_H_
77 |
--------------------------------------------------------------------------------
/convert/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | include_directories(
16 | ..
17 | ${USD_INCLUDE_DIRS}
18 | )
19 |
20 | add_library(convert
21 | tokens.cc
22 | tokens.h
23 | convert_common.h
24 | convert_context.h
25 | convert_util.cc
26 | convert_util.h
27 | converter.cc
28 | converter.h
29 | materializer.cc
30 | materializer.h
31 | package.cc
32 | package.h
33 | texturator.cc
34 | texturator.h
35 | )
36 |
37 | file(GLOB CONVERT_HEADERS "*.h")
38 | set_target_properties(convert PROPERTIES PUBLIC_HEADER "${CONVERT_HEADERS}")
39 |
40 | target_link_libraries(convert process)
41 |
42 | install(TARGETS convert EXPORT ufglib DESTINATION lib/ufg PUBLIC_HEADER DESTINATION include/ufg/convert)
43 |
--------------------------------------------------------------------------------
/convert/convert_common.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #ifndef UFG_CONVERT_CONVERT_COMMON_H_
18 | #define UFG_CONVERT_CONVERT_COMMON_H_
19 |
20 | #include "common/common.h"
21 |
22 | // Disable warnings originating in the USD headers.
23 | #ifdef _MSC_VER
24 | #pragma warning(push)
25 | // not enough actual parameters for macro 'BOOST_*'
26 | #pragma warning(disable : 4003)
27 | // conversion from 'Py_ssize_t' to 'unsigned int', possible loss of data
28 | #pragma warning(disable : 4244)
29 | // conversion from 'size_t' to 'int', possible loss of data
30 | #pragma warning(disable : 4267)
31 | #endif // _MSC_VER
32 |
33 | #include "pxr/usd/usdGeom/scope.h"
34 | #include "pxr/usd/usdGeom/xform.h"
35 | #include "pxr/usd/usdShade/material.h"
36 | #include "pxr/usd/usdShade/shader.h"
37 |
38 | #ifdef _MSC_VER
39 | #pragma warning(pop)
40 | #endif // _MSC_VER
41 |
42 | #endif // UFG_CONVERT_CONVERT_COMMON_H_
43 |
--------------------------------------------------------------------------------
/convert/convert_context.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #ifndef UFG_CONVERT_CONVERT_CONTEXT_H_
18 | #define UFG_CONVERT_CONVERT_CONTEXT_H_
19 |
20 | #include "common/common.h"
21 | #include "common/common_util.h"
22 | #include "common/config.h"
23 | #include "common/logging.h"
24 | #include "convert/convert_util.h"
25 | #include "gltf/cache.h"
26 | #include "gltf/gltf.h"
27 |
28 | namespace ufg {
29 | using PXR_NS::UsdStageRefPtr;
30 |
31 | struct ConvertContext {
32 | std::string src_dir;
33 | std::string dst_dir;
34 | ConvertSettings settings;
35 | const Gltf* gltf;
36 | PathTable path_table;
37 | GltfCache gltf_cache;
38 | Logger* logger;
39 | GltfOnceLogger once_logger;
40 | UsdStageRefPtr stage;
41 | SdfPath root_path;
42 |
43 | void Reset(Logger* logger) {
44 | src_dir.clear();
45 | dst_dir.clear();
46 | settings = ConvertSettings::kDefault;
47 | gltf = nullptr;
48 | path_table.Clear();
49 | gltf_cache.Reset();
50 | this->logger = logger;
51 | once_logger.Reset(logger);
52 | stage = UsdStageRefPtr();
53 | root_path = SdfPath::EmptyPath();
54 | }
55 | };
56 | } // namespace ufg
57 |
58 | #endif // UFG_CONVERT_CONVERT_CONTEXT_H_
59 |
--------------------------------------------------------------------------------
/convert/convert_util.cc:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #include "convert/convert_util.h"
18 |
19 | #include "common/common_util.h"
20 | #include "common/config.h"
21 | #include "pxr/base/tf/stringUtils.h"
22 |
23 | namespace ufg {
24 | std::string MakeValidUsdName(const char* prefix, const std::string& in,
25 | size_t index) {
26 | return in.empty() ? AppendNumber(prefix, index)
27 | : PXR_NS::TfMakeValidIdentifier(in);
28 | }
29 |
30 | UsdTimeCode GetTimeCode(float t) {
31 | const float s = kFps * t;
32 | const float r = std::roundf(s);
33 | return UsdTimeCode(std::abs(s - r) < kSnapTimeCodeTol ? r : s);
34 | }
35 |
36 | void PathTable::Clear() {
37 | paths_.clear();
38 | }
39 |
40 | std::string PathTable::MakeUnique(const SdfPath& parent_path,
41 | const char* prefix, const std::string& in,
42 | size_t index) {
43 | const std::string orig_name = MakeValidUsdName(prefix, in, index);
44 | std::string name = orig_name;
45 | size_t duplicate_count = 0;
46 | for (;;) {
47 | const SdfPath path = parent_path.AppendElementString(name);
48 | const std::string& path_str = path.GetString();
49 | const auto insert_result = paths_.insert(path_str);
50 | if (insert_result.second) {
51 | return path_str;
52 | }
53 | name = AppendNumber(orig_name + '_', ++duplicate_count);
54 | }
55 | }
56 |
57 | } // namespace ufg
58 |
--------------------------------------------------------------------------------
/convert/convert_util.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #ifndef UFG_CONVERT_CONVERT_UTIL_H_
18 | #define UFG_CONVERT_CONVERT_UTIL_H_
19 |
20 | #include
21 | #include
22 | #include "convert/convert_common.h"
23 | #include "convert/tokens.h"
24 | #include "gltf/gltf.h"
25 | #include "pxr/base/tf/token.h"
26 | #include "pxr/usd/sdf/types.h"
27 | #include "pxr/usd/usd/timeCode.h"
28 | #include "pxr/usd/usdShade/shader.h"
29 |
30 | namespace ufg {
31 | using PXR_NS::TfToken;
32 | using PXR_NS::UsdShadeShader;
33 | using PXR_NS::UsdTimeCode;
34 | using PXR_NS::SdfPath;
35 | using PXR_NS::SdfValueTypeNames;
36 |
37 | std::string MakeValidUsdName(const char* prefix, const std::string& in,
38 | size_t index);
39 |
40 | inline std::string MakeValidUsdName(const char* prefix, const std::string& in,
41 | Gltf::Id id) {
42 | return MakeValidUsdName(prefix, in, Gltf::IdToIndex(id));
43 | }
44 |
45 | template
46 | void CreateEnumInput(const TfToken& name_tok, T value,
47 | const TfToken& default_tok, UsdShadeShader* tex) {
48 | const TfToken& value_tok = ToToken(value);
49 | if (value_tok != default_tok) {
50 | tex->CreateInput(name_tok, SdfValueTypeNames->Token).Set(value_tok);
51 | }
52 | }
53 |
54 | UsdTimeCode GetTimeCode(float t);
55 |
56 | class PathTable {
57 | public:
58 | void Clear();
59 | std::string MakeUnique(const SdfPath& parent_path, const char* prefix,
60 | const std::string& in, size_t index);
61 |
62 | private:
63 | std::unordered_set paths_;
64 | };
65 | } // namespace ufg
66 |
67 | #endif // UFG_CONVERT_CONVERT_UTIL_H_
68 |
--------------------------------------------------------------------------------
/convert/converter.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #ifndef UFG_CONVERT_CONVERTER_H_
18 | #define UFG_CONVERT_CONVERTER_H_
19 |
20 | #include
21 | #include
22 | #include "common/common_util.h"
23 | #include "common/config.h"
24 | #include "convert/convert_common.h"
25 | #include "convert/convert_context.h"
26 | #include "convert/convert_util.h"
27 | #include "convert/materializer.h"
28 | #include "gltf/gltf.h"
29 | #include "process/animation.h"
30 | #include "process/image.h"
31 | #include "process/mesh.h"
32 | #include "process/skin.h"
33 | #include "pxr/usd/sdf/layer.h"
34 | #include "pxr/usd/sdf/path.h"
35 | #include "pxr/base/tf/token.h"
36 | #include "pxr/base/vt/array.h"
37 | #include "pxr/usd/usd/stage.h"
38 | #include "pxr/usd/usdShade/material.h"
39 | #include "pxr/usd/usdShade/shader.h"
40 |
41 | namespace ufg {
42 | using PXR_NS::SdfLayerRefPtr;
43 | using PXR_NS::SdfPath;
44 | using PXR_NS::SdfValueTypeName;
45 | using PXR_NS::TfToken;
46 | using PXR_NS::UsdShadeMaterial;
47 | using PXR_NS::UsdShadeShader;
48 | using PXR_NS::UsdStageRefPtr;
49 | using PXR_NS::VtArray;
50 |
51 | class Converter {
52 | public:
53 | void Reset(Logger* logger);
54 | bool Convert(const ConvertSettings& settings, const Gltf& gltf,
55 | GltfStream* gltf_stream, const std::string& src_dir,
56 | const std::string& dst_dir, const std::string& dst_filename,
57 | const SdfLayerRefPtr& layer, Logger* logger);
58 | const std::vector& GetWritten() const {
59 | return materializer_.GetWritten();
60 | }
61 | const std::vector& GetCreatedDirectories() const {
62 | return materializer_.GetCreatedDirectories();
63 | }
64 |
65 | private:
66 | struct SkinnedMeshContext {
67 | SdfPath skeleton_path;
68 | SdfPath anim_path;
69 | const uint16_t* gjoint_to_ujoint_map;
70 | size_t gjoint_count;
71 | const GfMatrix3f* bake_norm_mats; // Null if not baking normals.
72 | };
73 |
74 | ConvertContext cc_;
75 | Pass curr_pass_;
76 | Materializer materializer_;
77 |
78 | // TODO: A node can exist in multiple places in the hierarchy, so
79 | // each node could have multiple parents. I haven't found any models that
80 | // actually do this, though.
81 | std::vector node_parents_;
82 |
83 | NodeInfo root_node_info_;
84 | std::vector node_infos_;
85 | std::vector mesh_infos_;
86 | std::vector used_skin_infos_;
87 | std::vector gltf_skin_srcs_;
88 | AnimInfo anim_info_;
89 | UsdShadeMaterial debug_bone_material_;
90 |
91 | void CreateStage(const SdfLayerRefPtr& layer,
92 | const std::string& dst_filename);
93 | void CreateDebugBoneMesh(const SdfPath& parent_path, bool reverse_winding);
94 | void CreateSkeleton(const SdfPath& path, const SkinInfo& skin_info);
95 | GfVec3f CreateSkelAnim(const SdfPath& path, const SkinInfo& skin_info,
96 | const AnimInfo& anim_info,
97 | std::vector* out_frame0_rots,
98 | std::vector* out_frame0_scales);
99 | void CreateMesh(size_t mesh_index, const SdfPath& parent_path,
100 | bool reverse_winding,
101 | const SkinnedMeshContext* skinned_mesh_context);
102 | void CreateSkinnedMeshes(const SdfPath& parent_path,
103 | const std::vector& node_ids,
104 | bool reverse_winding);
105 | void CreateNodeHierarchy(Gltf::Id node_id, const SdfPath& parent_path,
106 | const GfMatrix4d& parent_world_mat);
107 | void CreateNodes(const std::vector& root_nodes);
108 | void CreateAnimation(const AnimInfo& anim_info);
109 | void ConvertImpl(const ConvertSettings& settings, const Gltf& gltf,
110 | GltfStream* gltf_stream, const std::string& src_dir,
111 | const std::string& dst_dir, const std::string& dst_filename,
112 | const SdfLayerRefPtr& layer, Logger* logger);
113 | };
114 |
115 | } // namespace ufg
116 |
117 | #endif // UFG_CONVERT_CONVERTER_H_
118 |
--------------------------------------------------------------------------------
/convert/materializer.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #ifndef UFG_CONVERT_MATERIALIZER_H_
18 | #define UFG_CONVERT_MATERIALIZER_H_
19 |
20 | #include