├── .gitignore ├── CMakeLists.txt ├── LICENSE ├── README.md ├── cmake ├── FindTBB.cmake ├── FindUsd.cmake └── Utilities.cmake ├── include └── tinyusd_SceneProxy.h ├── packages └── README.md └── src └── main.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | packages/ 3 | 4 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | cmake_minimum_required(VERSION 3.11) 3 | project(tinyusd) 4 | 5 | set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) 6 | include(Utilities) 7 | find_package(pxr) 8 | find_package(TBB) 9 | 10 | set(TINYUSD_ROOT "${CMAKE_CURRENT_SOURCE_DIR}") 11 | message(INFO, "TinyUSD root is ${TINYUSD_ROOT}") 12 | add_executable(tinyusd "") 13 | lab_default_definitions(tinyusd) 14 | lab_set_cxx_version(tinyusd 17) 15 | 16 | file(GLOB SRC "src/*.cpp") 17 | file(GLOB HEADERS "include/*.h") 18 | target_sources(tinyusd PRIVATE ${SRC}) 19 | target_sources(tinyusd PRIVATE ${HEADERS}) 20 | 21 | target_compile_definitions(tinyusd PUBLIC ${USD_DEFINES} PXR_STATIC) 22 | 23 | target_include_directories(tinyusd PRIVATE 24 | ${USD_INCLUDE_DIR} 25 | ${TBB_INCLUDE_DIRS} 26 | ${TINYUSD_ROOT}/include 27 | ${TINYUSD_ROOT}/src) 28 | 29 | # note: target_link_libraries requires the optimized/debug keyword to be 30 | # applied per library, not to a list. 31 | #foreach(lib ${PXR_LIBRARIES}) 32 | # target_link_libraries(tinyusd optimized ${lib}) 33 | #endforeach() 34 | #foreach(lib ${PXR_DEBUG_LIBRARIES}) 35 | # target_link_libraries(tinyusd debug ${lib}) 36 | #endforeach() 37 | 38 | # Note - there is currently a bug in the generate PxrConfig.cmake file; 39 | # It outputs many file names in the monolithic static variant, incorrectly 40 | target_link_libraries(tinyusd optimized ${CMAKE_PREFIX_PATH}/lib/libusd_ms.dylib) 41 | target_link_libraries(tinyusd debug ${CMAKE_PREFIX_PATH}/lib/libusd_ms.dylib) 42 | 43 | if (MSVC) 44 | target_link_libraries(tinyusd Shlwapi.lib Dbghelp.lib WSock32.lib) 45 | target_link_libraries(tinyusd optimized ${TBB_tbb_LIBRARY_RELEASE} debug ${TBB_tbb_LIBRARY_DEBUG}) 46 | else () 47 | target_link_libraries(tinyusd ${TBB_tbb_LIBRARY}) 48 | endif() 49 | 50 | set_target_properties(tinyusd 51 | PROPERTIES 52 | ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" 53 | LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" 54 | RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" 55 | ) 56 | 57 | install (TARGETS tinyusd 58 | ARCHIVE DESTINATION lib 59 | LIBRARY DESTINATION lib 60 | RUNTIME DESTINATION bin) 61 | 62 | install (TARGETS tinyusd DESTINATION bin) 63 | 64 | source_group(source FILES ${SRC}) 65 | source_group(headers FILES ${HEADERS}) 66 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Nick Porcino 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # Tiny USD 3 | 4 | A tutorial on creating the smallest possible viable USD program, using 5 | the dev branch of the official usd distribution. 6 | 7 | Note that this currently highly work in progress, the mac recipe is the only 8 | one fully worked for cmake. The windows recipe still uses build_usd.py, and 9 | ubuntu remains a struggle. 10 | 11 | Help wanted! 12 | 13 | # USD Build Club 14 | 15 | ## Environment Setup 16 | -------------------- 17 | 18 | Before building USD, set up your environment variables according to your platform. You can customize these paths to match your specific setup. 19 | 20 | ### Environment Variables Overview 21 | - `USD_SOURCE_DIR`: Location of the USD source code 22 | - `USD_DEPS_DIR`: Directory for building and installing dependencies 23 | - `USD_BUILD_DIR`: Directory for building USD 24 | - `USD_INSTALL_DIR`: Directory where USD will be installed 25 | - `USD_PYTHON_ROOT`: Base directory of your Python installation 26 | - `USD_PYTHON_EXE`: Path to the Python executable 27 | 28 | ### MacOS Environment 29 | ```.sh 30 | # Set up environment variables for paths, adjust as necessary. 31 | export USD_SOURCE_DIR=~/dev/OpenUSD # USD source code location 32 | export USD_DEPS_DIR=/var/tmp/usd-test/__deps # Dependencies directory 33 | export USD_BUILD_DIR=/var/tmp/usd-build # USD build directory 34 | export USD_INSTALL_DIR=${USD_BUILD_DIR}/install # USD installation directory 35 | export USD_PYTHON_ROOT=/usr/local/bin # Python installation directory 36 | export USD_PYTHON_EXE=${USD_PYTHON_ROOT}/python # Python executable 37 | 38 | # Create necessary directories 39 | mkdir -p ${USD_DEPS_DIR} 40 | mkdir -p ${USD_DEPS_DIR}/install 41 | mkdir -p ${USD_BUILD_DIR} 42 | ``` 43 | 44 | ### Windows Environment 45 | ```.bat 46 | :: Set up environment variables for paths 47 | :: Adjust these paths according to your setup 48 | set USD_SOURCE_DIR=%USERPROFILE%\dev\OpenUSD :: USD source code location 49 | set USD_DEPS_DIR=%USERPROFILE%\dev\deps :: Dependencies directory 50 | set USD_BUILD_DIR=%USERPROFILE%\dev\build\usd :: USD build directory 51 | set USD_INSTALL_DIR=%USD_BUILD_DIR%\install :: USD installation directory 52 | set USD_PYTHON_ROOT=%LOCALAPPDATA%\Programs\Python\Python39 :: Python installation directory 53 | set USD_PYTHON_EXE=%USD_PYTHON_ROOT%\python.exe :: Python executable 54 | 55 | :: Create necessary directories 56 | mkdir %USD_DEPS_DIR% 57 | mkdir %USD_DEPS_DIR%\install 58 | mkdir %USD_BUILD_DIR% 59 | ``` 60 | 61 | ### Linux Environment 62 | ```.sh 63 | # Set up environment variables for paths 64 | export USD_SOURCE_DIR=~/dev/OpenUSD # USD source code location 65 | export USD_DEPS_DIR=~/deps # Dependencies directory 66 | export USD_BUILD_DIR=~/build/usd # USD build directory 67 | export USD_INSTALL_DIR=~/install/USD # USD installation directory 68 | 69 | # Python path - adjust based on your distribution and Python version 70 | # For system Python: 71 | export USD_PYTHON_ROOT=/usr/bin 72 | export USD_PYTHON_EXE=${USD_PYTHON_ROOT}/python3 73 | # For conda environments (uncomment if using conda): 74 | #export USD_PYTHON_ROOT=$CONDA_PREFIX 75 | #export USD_PYTHON_EXE=${USD_PYTHON_ROOT}/bin/python 76 | 77 | # Create necessary directories 78 | mkdir -p ${USD_DEPS_DIR} 79 | mkdir -p ${USD_DEPS_DIR}/install 80 | mkdir -p ${USD_BUILD_DIR} 81 | ``` 82 | 83 | ## Toolchain 84 | ------------ 85 | 86 | - git 87 | - cmake 3.26 or greater installed for the command line 88 | - For MacOS: Xcode command line tools 89 | 90 | ## Building Dependencies 91 | ------------------------ 92 | 93 | ### MacOS and Linux Prerequisites 94 | 95 | ```.sh 96 | # Change to dependencies directory 97 | cd ${USD_DEPS_DIR} 98 | 99 | # OneTBB 100 | curl -L https://github.com/oneapi-src/oneTBB/archive/refs/tags/v2021.9.0.zip --output oneTBB-2021.9.0.zip 101 | unzip oneTBB-2021.9.0.zip && mv oneTBB-2021.9.0/ oneTBB 102 | cd oneTBB && mkdir -p build && cd build 103 | cmake .. -DTBB_TEST=OFF -DTBB_STRICT=OFF -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=${USD_DEPS_DIR}/install 104 | cmake --build . --config Release && cmake --install . 105 | cd ../.. 106 | 107 | # OpenSubdiv 108 | curl -L https://github.com/PixarAnimationStudios/OpenSubdiv/archive/v3_6_0.zip --output OpenSubdiv.3.6.0.zip 109 | unzip OpenSubdiv.3.6.0.zip && mv OpenSubdiv-3_6_0/ OpenSubdiv 110 | cd OpenSubdiv && mkdir build && cd build 111 | cmake .. -DNO_OPENGL=ON -DNO_EXAMPLES=ON -DNO_TUTORIALS=ON -DNO_REGRESSION=ON -DNO_DOC=ON -DNO_OMP=ON -DNO_CUDA=ON -DNO_OPENCL=ON -DNO_DX=ON -DNO_TESTS=ON -DNO_GLEW=ON -DNO_GLFW=ON -DNO_PTEX=ON -DNO_TBB=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=${USD_DEPS_DIR}/install 112 | cmake --build . --config Release && cmake --install . 113 | cd ../.. 114 | ``` 115 | 116 | ## Building USD with CMake 117 | -------------------------- 118 | 119 | ### MacOS Build (With Python) 120 | 121 | ```.sh 122 | cmake ${USD_SOURCE_DIR} -G Xcode -DCMAKE_INSTALL_PREFIX=${USD_INSTALL_DIR} -DPython3_ROOT="${USD_PYTHON_ROOT}" -DPython3_EXECUTABLE="${USD_PYTHON_EXE}" 123 | ``` 124 | 125 | ### MacOS Build (No Python) 126 | 127 | Note that we may point to the python for tools to use even though we are building USD without python runtime support. 128 | 129 | First, delete cmake/modules/FindOpenSubdiv.cmake as it is not compatible with the cmake config file OpenSubdiv installs. 130 | 131 | ```.sh 132 | cd ${USD_BUILD_DIR} 133 | 134 | cmake ${USD_SOURCE_DIR} -G Xcode -DCMAKE_INSTALL_PREFIX=${USD_INSTALL_DIR} -DPython3_ROOT="${USD_PYTHON_ROOT}" -DPython3_EXECUTABLE="${USD_PYTHON_EXE}" -DPXR_ENABLE_PYTHON_SUPPORT=OFF -DCMAKE_PREFIX_PATH=${USD_DEPS_DIR}/install -DTBB_ROOT=${USD_DEPS_DIR}/install 135 | ``` 136 | 137 | ## Building USD with build_usd.py 138 | --------------------------------- 139 | 140 | ### MacOS Dynamic Framework (No Python) 141 | 142 | ```.sh 143 | # Build USD without Python support 144 | ${USD_PYTHON_EXE} ${USD_SOURCE_DIR}/build_scripts/build_usd.py \ 145 | --generator Xcode \ 146 | --tests \ 147 | --no-python \ 148 | --no-openimageio \ 149 | --opencolorio \ 150 | --build-variant relwithdebuginfo \ 151 | ${USD_BUILD_DIR} \ 152 | | grep -v -e "note: Run script build phase" \ 153 | -e "RegisterExecutionPolicyException" \ 154 | -e "PhaseScriptExecution" \ 155 | -e "ClangStatCache" \ 156 | -e " cd" \ 157 | -e "note: Removed stale file" \ 158 | -e "ProcessProductPackaging" 159 | ``` 160 | 161 | ### MacOS Dynamic Framework (With Python) 162 | 163 | ```.sh 164 | # Build USD with Python support 165 | ${USD_PYTHON_EXE} ${USD_SOURCE_DIR}/build_scripts/build_usd.py \ 166 | --generator Xcode \ 167 | --tests \ 168 | --no-openimageio \ 169 | --opencolorio \ 170 | --build-variant relwithdebuginfo \ 171 | ${USD_BUILD_DIR} \ 172 | | grep -v -e "note: Run script build phase" \ 173 | -e "RegisterExecutionPolicyException" \ 174 | -e "PhaseScriptExecution" \ 175 | -e "ClangStatCache" \ 176 | -e " cd" \ 177 | -e "note: Removed stale file" \ 178 | -e "ProcessProductPackaging" 179 | ``` 180 | 181 | ### Windows Build 182 | 183 | ```.bat 184 | :: Build USD without Python support 185 | %USD_PYTHON_EXE% %USD_SOURCE_DIR%\build_scripts\build_usd.py ^ 186 | --no-openimageio ^ 187 | --opencolorio ^ 188 | --no-python ^ 189 | --build-variant=relwithdebuginfo ^ 190 | %USD_BUILD_DIR% 191 | ``` 192 | 193 | ### Ubuntu Build 194 | 195 | First, install required system dependencies: 196 | ```.sh 197 | sudo apt install libx11-dev libxt-dev libxrandr-dev 198 | ``` 199 | 200 | Set up Python environment: 201 | 1. Create a venv or conda environment 202 | 2. Install required packages: 203 | ```sh 204 | pip install PySide6 pyopengl 205 | ``` 206 | 207 | Build USD without Python support: 208 | ```.sh 209 | ${USD_PYTHON_EXE} ${USD_SOURCE_DIR}/build_scripts/build_usd.py \ 210 | --no-python \ 211 | ${USD_INSTALL_DIR} 212 | ``` 213 | Note: If build fails, modify `src/oneTBB-2020.3.1/build/common.inc` to add detection for "linux" in addition to "Linux" 214 | 215 | Build USD with Python support (requires Python development libraries): 216 | ```.sh 217 | ${USD_PYTHON_EXE} ${USD_SOURCE_DIR}/build_scripts/build_usd.py \ 218 | ${USD_INSTALL_DIR} 219 | ``` 220 | Note: Ensure your conda environment includes the appropriate Python development libraries (e.g., python3.12.a) 221 | 222 | ## Additional Configuration 223 | --------------------------- 224 | 225 | ### Xcode Debugging Setup 226 | To configure Xcode for USD development: 227 | 1. Edit Scheme > Arguments 228 | 2. Add a USD_INSTALL_DIR environment variable corresponding to the set up above. 229 | 2. Add the PXR_PLUGINPATH_NAME variable so plugins will be discovered: 230 | ```.sh 231 | PXR_PLUGINPATH_NAME=${USD_INSTALL_DIR}/lib/usd 232 | ``` 233 | 234 | 235 | ## Double check your work 236 | ------------------------- 237 | 238 | There is an executable in the bin directory called sdfdump. Running it 239 | should result in the executable describing its input arguments, without any complaints of missing dylibs. 240 | 241 | ## TinyUsd 242 | ---------- 243 | 244 | Go back into the packages directory we made earlier, and create a tinyusd-build directory, 245 | and cd into it. 246 | 247 | ```sh 248 | mkdir tinyusd-build && cd tinyusd-build 249 | ``` 250 | 251 | Then, configure the cmake build files. Once again, make sure 252 | the INSTALL_PREFIX and TOOLCHAIN variables are pointed appropriately. 253 | 254 | ```sh 255 | cmake -G "Xcode" ../.. -DCMAKE_INSTALL_PREFIX=.. -DCMAKE_PREFIX_PATH=$USD_INSTALL_DIR 256 | ``` 257 | 258 | Build tinyusd. 259 | 260 | ```sh 261 | cmake --build . --config Release --target install 262 | ``` 263 | 264 | Haven't got the rpath installation set up correctly in the cmake file yet, so go to the bin directory, and add it. 265 | 266 | ```sh 267 | cd ../bin 268 | install_name_tool -add_rpath ../lib tinyusd 269 | ``` 270 | 271 | Now, run tinyusd. 272 | 273 | ```sh 274 | ./tinyusd 275 | ``` 276 | 277 | Sanity check that tinyusd generated a file named test.usd, containing the following: 278 | 279 | ```usd 280 | #usda 1.0 281 | 282 | def Cube "Box" 283 | { 284 | float3 xformOp:scale = (5, 5, 5) 285 | uniform token[] xformOpOrder = ["xformOp:scale"] 286 | } 287 | 288 | ``` 289 | -------------------------------------------------------------------------------- /cmake/FindTBB.cmake: -------------------------------------------------------------------------------- 1 | # The MIT License (MIT) 2 | # 3 | # Copyright (c) 2015 Justus Calvin 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | # 24 | # FindTBB 25 | # ------- 26 | # 27 | # Find TBB include directories and libraries. 28 | # 29 | # Usage: 30 | # 31 | # find_package(TBB [major[.minor]] [EXACT] 32 | # [QUIET] [REQUIRED] 33 | # [[COMPONENTS] [components...]] 34 | # [OPTIONAL_COMPONENTS components...]) 35 | # 36 | # where the allowed components are tbbmalloc and tbb_preview. Users may modify 37 | # the behavior of this module with the following variables: 38 | # 39 | # * TBB_ROOT_DIR - The base directory the of TBB installation. 40 | # * TBB_INCLUDE_DIR - The directory that contains the TBB headers files. 41 | # * TBB_LIBRARY - The directory that contains the TBB library files. 42 | # * TBB__LIBRARY - The path of the TBB the corresponding TBB library. 43 | # These libraries, if specified, override the 44 | # corresponding library search results, where 45 | # may be tbb, tbb_debug, tbbmalloc, tbbmalloc_debug, 46 | # tbb_preview, or tbb_preview_debug. 47 | # * TBB_USE_DEBUG_BUILD - The debug version of tbb libraries, if present, will 48 | # be used instead of the release version. 49 | # 50 | # Users may modify the behavior of this module with the following environment 51 | # variables: 52 | # 53 | # * TBB_INSTALL_DIR 54 | # * TBBROOT 55 | # * LIBRARY_PATH 56 | # 57 | # This module will set the following variables: 58 | # 59 | # * TBB_FOUND - Set to false, or undefined, if we haven’t found, or 60 | # don’t want to use TBB. 61 | # * TBB__FOUND - If False, optional part of TBB sytem is 62 | # not available. 63 | # * TBB_VERSION - The full version string 64 | # * TBB_VERSION_MAJOR - The major version 65 | # * TBB_VERSION_MINOR - The minor version 66 | # * TBB_INTERFACE_VERSION - The interface version number defined in 67 | # tbb/tbb_stddef.h. 68 | # * TBB__LIBRARY_RELEASE - The path of the TBB release version of 69 | # , where may be tbb, tbb_debug, 70 | # tbbmalloc, tbbmalloc_debug, tbb_preview, or 71 | # tbb_preview_debug. 72 | # * TBB__LIBRARY_DEGUG - The path of the TBB release version of 73 | # , where may be tbb, tbb_debug, 74 | # tbbmalloc, tbbmalloc_debug, tbb_preview, or 75 | # tbb_preview_debug. 76 | # 77 | # The following varibles should be used to build and link with TBB: 78 | # 79 | # * TBB_INCLUDE_DIRS - The include directory for TBB. 80 | # * TBB_LIBRARIES - The libraries to link against to use TBB. 81 | # * TBB_DEFINITIONS - Definitions to use when compiling code that uses TBB. 82 | 83 | include_guard() 84 | 85 | include(FindPackageHandleStandardArgs) 86 | 87 | if(NOT TBB_FOUND) 88 | 89 | ################################## 90 | # Check the build type 91 | ################################## 92 | 93 | if(NOT DEFINED TBB_USE_DEBUG_BUILD) 94 | if(CMAKE_BUILD_TYPE MATCHES "Debug|DEBUG|debug") 95 | set(TBB_USE_DEBUG_BUILD TRUE) 96 | else() 97 | set(TBB_USE_DEBUG_BUILD FALSE) 98 | endif() 99 | endif() 100 | 101 | ################################## 102 | # Set the TBB search directories 103 | ################################## 104 | 105 | # Define search paths based on user input and environment variables 106 | set(TBB_SEARCH_DIR ${TBB_ROOT_DIR} $ENV{TBB_INSTALL_DIR} $ENV{TBBROOT}) 107 | 108 | # Define the search directories based on the current platform 109 | if(CMAKE_SYSTEM_NAME STREQUAL "Windows") 110 | set(TBB_DEFAULT_SEARCH_DIR 111 | ${TBB_ROOT_DIR} 112 | ${LAB_PACKAGE_ROOT} 113 | "C:/Program Files/Intel/TBB" 114 | "C:/Program Files (x86)/Intel/TBB") 115 | 116 | set(TBB_LIB_PATH_SUFFIX "lib") 117 | set(TBB_DEBUG_LIB_PATH_SUFFIX "debug/lib") 118 | 119 | elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin") 120 | # OS X 121 | set(TBB_DEFAULT_SEARCH_DIR "/opt/intel/tbb") 122 | 123 | # TODO: Check to see which C++ library is being used by the compiler. 124 | if(NOT ${CMAKE_SYSTEM_VERSION} VERSION_LESS 13.0) 125 | # The default C++ library on OS X 10.9 and later is libc++ 126 | set(TBB_LIB_PATH_SUFFIX "lib/libc++") 127 | else() 128 | set(TBB_LIB_PATH_SUFFIX "lib") 129 | endif() 130 | elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux") 131 | # Linux 132 | set(TBB_DEFAULT_SEARCH_DIR "/opt/intel/tbb") 133 | 134 | # TODO: Check compiler version to see the suffix should be /gcc4.1 or 135 | # /gcc4.1. For now, assume that the compiler is more recent than 136 | # gcc 4.4.x or later. 137 | if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64") 138 | set(TBB_LIB_PATH_SUFFIX "lib/intel64/gcc4.4") 139 | elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^i.86$") 140 | set(TBB_LIB_PATH_SUFFIX "lib/ia32/gcc4.4") 141 | endif() 142 | endif() 143 | 144 | ################################## 145 | # Find the TBB include dir 146 | ################################## 147 | 148 | find_path(TBB_INCLUDE_DIRS tbb/tbb.h 149 | HINTS ${TBB_INCLUDE_DIR} ${TBB_SEARCH_DIR} 150 | PATHS ${TBB_DEFAULT_SEARCH_DIR} 151 | PATH_SUFFIXES include) 152 | 153 | ################################## 154 | # Find TBB components 155 | ################################## 156 | 157 | # Find each component 158 | foreach(_comp tbb_preview tbbmalloc tbb) 159 | # Search for the libraries 160 | find_library(TBB_${_comp}_LIBRARY_RELEASE ${_comp} 161 | HINTS ${TBB_LIBRARY} ${TBB_SEARCH_DIR} 162 | PATHS ${TBB_DEFAULT_SEARCH_DIR} 163 | PATH_SUFFIXES 164 | ${TBB_LIB_PATH_SUFFIX}) 165 | 166 | find_library(TBB_${_comp}_LIBRARY_DEBUG ${_comp}_debug 167 | HINTS ${TBB_LIBRARY} ${TBB_SEARCH_DIR} 168 | PATHS ${TBB_DEFAULT_SEARCH_DIR} ENV LIBRARY_PATH 169 | PATH_SUFFIXES 170 | ${TBB_DEBUG_LIB_PATH_SUFFIX} 171 | ${TBB_LIB_PATH_SUFFIX}) 172 | 173 | 174 | # Set the library to be used for the component 175 | if(NOT TBB_${_comp}_LIBRARY) 176 | if(TBB_USE_DEBUG_BUILD AND TBB_${_comp}_LIBRARY_DEBUG) 177 | set(TBB_${_comp}_LIBRARY "${TBB_${_comp}_LIBRARY_DEBUG}") 178 | elseif(TBB_${_comp}_LIBRARY_RELEASE) 179 | set(TBB_${_comp}_LIBRARY "${TBB_${_comp}_LIBRARY_RELEASE}") 180 | elseif(TBB_${_comp}_LIBRARY_DEBUG) 181 | set(TBB_${_comp}_LIBRARY "${TBB_${_comp}_LIBRARY_DEBUG}") 182 | endif() 183 | endif() 184 | 185 | # Set the TBB library list and component found variables 186 | if(TBB_${_comp}_LIBRARY) 187 | list(APPEND TBB_LIBRARIES "${TBB_${_comp}_LIBRARY}") 188 | set(TBB_${_comp}_FOUND TRUE) 189 | else() 190 | set(TBB_${_comp}_FOUND FALSE) 191 | endif() 192 | 193 | mark_as_advanced(TBB_${_comp}_LIBRARY_RELEASE) 194 | mark_as_advanced(TBB_${_comp}_LIBRARY_DEBUG) 195 | mark_as_advanced(TBB_${_comp}_LIBRARY) 196 | 197 | endforeach() 198 | 199 | ################################## 200 | # Set compile flags 201 | ################################## 202 | 203 | if(TBB_tbb_LIBRARY MATCHES "debug") 204 | set(TBB_DEFINITIONS "-DTBB_USE_DEBUG=1") 205 | endif() 206 | 207 | ################################## 208 | # Set version strings 209 | ################################## 210 | 211 | if(TBB_INCLUDE_DIRS) 212 | file(READ "${TBB_INCLUDE_DIRS}/tbb/tbb_stddef.h" _tbb_version_file) 213 | string(REGEX REPLACE ".*#define TBB_VERSION_MAJOR ([0-9]+).*" "\\1" 214 | TBB_VERSION_MAJOR "${_tbb_version_file}") 215 | string(REGEX REPLACE ".*#define TBB_VERSION_MINOR ([0-9]+).*" "\\1" 216 | TBB_VERSION_MINOR "${_tbb_version_file}") 217 | string(REGEX REPLACE ".*#define TBB_INTERFACE_VERSION ([0-9]+).*" "\\1" 218 | TBB_INTERFACE_VERSION "${_tbb_version_file}") 219 | set(TBB_VERSION "${TBB_VERSION_MAJOR}.${TBB_VERSION_MINOR}") 220 | endif() 221 | 222 | find_package_handle_standard_args(TBB 223 | REQUIRED_VARS TBB_INCLUDE_DIRS TBB_LIBRARIES 224 | HANDLE_COMPONENTS 225 | VERSION_VAR TBB_VERSION) 226 | 227 | mark_as_advanced(TBB_INCLUDE_DIRS TBB_LIBRARIES) 228 | 229 | endif() 230 | -------------------------------------------------------------------------------- /cmake/FindUsd.cmake: -------------------------------------------------------------------------------- 1 | 2 | # author: Nick Porcino 3 | # license: MIT 4 | 5 | include_guard() 6 | 7 | include(FindPackageHandleStandardArgs) 8 | 9 | if(EXISTS "$ENV{USD_ROOT}") 10 | set(USD_ROOT $ENV{USD_ROOT}) 11 | endif() 12 | 13 | find_package(Alembic) 14 | find_package(Embree) 15 | find_package(Houdini) 16 | find_package(KatanaAPI) 17 | find_package(Maya) 18 | 19 | find_path(USD_INCLUDE_DIR pxr/pxr.h 20 | PATHS ${USD_LOCATION} 21 | ${USD_ROOT} 22 | /usr 23 | /usr/local 24 | /sw 25 | /opt/local 26 | 27 | PATH_SUFFIXES 28 | /include 29 | 30 | DOC "USD include directory") 31 | 32 | if(WIN32) 33 | set(LIB_EXT "lib") 34 | set(DYLIB_EXT "dll") 35 | elseif(APPLE) 36 | set(LIB_EXT "a") 37 | set(DYLIB_EXT "dylib") 38 | else() 39 | set(LIB_EXT "a") 40 | set(DYLIB_EXT "so") 41 | endif() 42 | 43 | find_path(USD_LIBRARY_DIR 44 | NAMES libusd.${LIB_EXT} usd_ms.${LIB_EXT} 45 | PATHS ${USD_INCLUDE_DIR}/../lib 46 | DOC "USD Libraries directory") 47 | 48 | find_file(USD_GENSCHEMA 49 | names usdGenSchema 50 | PATHS ${USD_INCLUDE_DIR}/../bin 51 | DOC "USD Gen schema application") 52 | 53 | # note that bin dir won't exist in the case that USD was built monolithically 54 | 55 | find_path(USD_BIN_DIR usdview 56 | PATHS ${USD_INCLUDE_DIR}/../bin 57 | DOC "USD Bin directory") 58 | 59 | if(Katana_FOUND) 60 | find_path(USD_KATANA_INCLUDE_DIR usdKatana/api.h 61 | PATHS ${USD_INCLUDE_DIR}/../third_party/katana/include ${KATANA_INCLUDE_DIR} 62 | DOC "USD Katana Include directory") 63 | 64 | find_path(USD_KATANA_LIBRARY_DIR libusdKatana.${DYLIB_EXT} 65 | PATHS ${USD_INCLUDE_DIR}/../third_party/katana/lib ${KATANA_LIBRARY_DIR} 66 | DOC "USD Katana Library directory") 67 | 68 | if(USD_KATANA_LIBRARY_DIR) 69 | mark_as_advanced(USD_KATANA_LIBRARY_DIR USD_KATANA_INCLUDE_DIR) 70 | endif() 71 | endif() 72 | 73 | if(Maya_FOUND) 74 | find_path(USD_MAYA_INCLUDE_DIR usdMaya/api.h 75 | PATHS ${USD_INCLUDE_DIR}/../third_party/maya/include ${MAYA_INCLUDE_DIR} 76 | DOC "USD Maya Include directory") 77 | 78 | find_path(USD_MAYA_LIBRARY_DIR libusdMaya.${DYLIB_EXT} 79 | PATHS ${USD_INCLUDE_DIR}/../third_party/maya/lib ${MAYA_LIBRARY_DIR} 80 | DOC "USD Maya Library directory") 81 | 82 | if(USD_MAYA_LIBRARY_DIR) 83 | mark_as_advanced(USD_MAYA_LIBRARY_DIR USD_MAYA_INCLUDE_DIR) 84 | endif() 85 | endif() 86 | 87 | if (Houdini_FOUND) 88 | endif() 89 | 90 | # prefer the monolithic static library, if it can be found 91 | find_library(USD_MS_LIB_RELEASE usd_ms.${LIB_EXT} 92 | HINTS ${USD_LIBRARY_DIR} ${USD_INCLUDE_DIR}/.. 93 | 94 | PATHS 95 | ${USD_LOCATION} 96 | ${USD_ROOT} 97 | /usr 98 | /usr/local 99 | /sw 100 | /opt/local 101 | 102 | PATH_SUFFIXES 103 | /lib 104 | 105 | DOC "USD library ${LIB}" 106 | ) 107 | 108 | if (USD_MS_LIB_RELEASE) 109 | set(USD_LIB_NAMES usd_ms) 110 | else() 111 | set(USD_LIB_NAMES 112 | ar arch gf js kind ndr pcp plug sdf sdr tf trace 113 | usd usdGeom usdHydra usdLux usdRi usdShade usdSkel usdUI 114 | usdUtils usdVol vt work 115 | ) 116 | endif() 117 | 118 | if(Embree_FOUND) 119 | set(USD_LIB_NAMES ${USD_LIB_NAMES} hdEmbree) 120 | endif() 121 | 122 | if(Alembic_FOUND) 123 | set(USD_LIB_NAMES ${USD_LIB_NAMES} usdAbc) 124 | endif() 125 | 126 | foreach(_lib ${USD_LIB_NAMES}) 127 | find_library(USD_${_lib}_LIB_RELEASE lib${_lib} 128 | HINTS ${USD_LIBRARY_DIR} ${USD_INCLUDE_DIR}/.. 129 | 130 | PATHS 131 | ${USD_LOCATION} 132 | ${USD_ROOT} 133 | /usr 134 | /usr/local 135 | /sw 136 | /opt/local 137 | 138 | PATH_SUFFIXES 139 | /lib 140 | 141 | DOC "USD library ${LIB}" 142 | ) 143 | 144 | if(USD_${_lib}_LIB_RELEASE) 145 | list(APPEND USD_LIBRARIES "${USD_${_lib}_LIB_RELEASE}") 146 | set(USD_${_lib}_FOUND TRUE) 147 | set(USD_${_lib}_LIBRARY "${USD_${_lib}_LIB_RELEASE}") 148 | list(APPEND USD_LIBRARIES "${USD_${_lib}_LIBRARY}") 149 | mark_as_advanced(USD_${_lib}_LIB_RELEASE) 150 | else() 151 | set(USD_${_lib}_FOUND FALSE) 152 | endif() 153 | 154 | find_library(USD_${_lib}_LIB_DEBUG lib${_lib}_d 155 | HINTS ${USD_LIBRARY_DIR} ${USD_INCLUDE_DIR}/.. 156 | 157 | PATHS 158 | ${USD_LOCATION} 159 | ${USD_ROOT} 160 | /usr 161 | /usr/local 162 | /sw 163 | /opt/local 164 | 165 | PATH_SUFFIXES 166 | /lib 167 | 168 | DOC "USD library ${LIB}" 169 | ) 170 | 171 | if(USD_${_lib}_LIB_DEBUG) 172 | list(APPEND USD_DEBUG_LIBRARIES "${USD_${_lib}_LIB_DEBUG}") 173 | set(USD_${_lib}_FOUND TRUE) 174 | set(USD_${_lib}_DEBUG_LIBRARY "${USD_${_lib}_LIB_DEBUG}") 175 | mark_as_advanced(USD_${_lib}_LIB_DEBUG) 176 | else() 177 | set(USD_${_lib}_DEBUG_FOUND FALSE) 178 | endif() 179 | 180 | endforeach() 181 | 182 | if (WIN32 OR APPLE) 183 | set(USD_DEFINES TF_NO_GNU_EXT) 184 | endif() 185 | 186 | find_package_handle_standard_args(USD 187 | REQUIRED_VARS 188 | USD_INCLUDE_DIR 189 | USD_LIBRARY_DIR 190 | USD_LIBRARIES 191 | USD_DEFINES) 192 | -------------------------------------------------------------------------------- /cmake/Utilities.cmake: -------------------------------------------------------------------------------- 1 | 2 | # Turn on folder usage 3 | set_property(GLOBAL PROPERTY USE_FOLDERS ON) 4 | 5 | # Default build type 6 | if(NOT CMAKE_BUILD_TYPE) 7 | set(CMAKE_BUILD_TYPE "Release") 8 | endif() 9 | 10 | set(CMAKE_BUILD_TYPE Release) 11 | 12 | # override cmake install prefix if it's not set, 13 | # per: http://public.kitware.com/pipermail/cmake/2010-December/041135.html 14 | IF(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) 15 | SET(CMAKE_INSTALL_PREFIX ${LOCAL_ROOT} CACHE PATH "Install set to local" FORCE) 16 | ENDIF(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) 17 | 18 | function(lab_set_cxx_version proj vers) 19 | target_compile_features(${proj} INTERFACE cxx_std_${vers}) 20 | set_property(TARGET ${proj} PROPERTY CXX_STANDARD ${vers}) 21 | set_property(TARGET ${proj} PROPERTY CXX_STANDARD_REQUIRED ON) 22 | endfunction() 23 | 24 | 25 | 26 | 27 | #if (MSVC_VERSION GREATER_EQUAL "1900") 28 | # include(CheckCXXCompilerFlag) 29 | # CHECK_CXX_COMPILER_FLAG("/std:c++latest" _cpp_latest_flag_supported) 30 | # if (_cpp_latest_flag_supported) 31 | # add_compile_options("/std:c++latest") 32 | # endif() 33 | #endif() 34 | 35 | 36 | 37 | 38 | function(lab_default_definitions PROJ) 39 | 40 | if (WIN32) 41 | target_compile_definitions(${PROJ} PUBLIC PLATFORM_WINDOWS) 42 | 43 | target_compile_definitions(${PROJ} PUBLIC __TBB_NO_IMPLICIT_LINKAGE=1) 44 | target_compile_definitions(${PROJ} PUBLIC __TBBMALLOC_NO_IMPLICIT_LINKAGE=1) 45 | target_compile_definitions(${PROJ} PUBLIC NOMINMAX) 46 | target_compile_definitions(${PROJ} PUBLIC _CRT_SECURE_NO_WARNINGS) 47 | target_compile_definitions(${PROJ} PUBLIC _SCL_SECURE_NO_WARNINGS) 48 | target_compile_options(${PROJ} PRIVATE /arch:AVX /Zi ) 49 | # set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /DEBUG /OPT:REF /OPT:ICF" CACHE STRING "" FORCE) 50 | if (MSVC_IDE) 51 | # hack to get around the "Debug" and "Release" directories cmake tries to add on Windows 52 | #set_target_properties(LabRender PROPERTIES PREFIX "../") 53 | #set_target_properties(${PROJ} PROPERTIES IMPORT_PREFIX "../") 54 | endif() 55 | elseif (APPLE) 56 | target_compile_definitions(${PROJ} PUBLIC PLATFORM_DARWIN) 57 | target_compile_definitions(${PROJ} PUBLIC PLATFORM_MACOS) 58 | else() 59 | target_compile_definitions(${PROJ} PUBLIC PLATFORM_LINUX) 60 | endif() 61 | 62 | target_compile_definitions(${PROJ} PRIVATE 63 | LABRENDER_BINDER_DLL 64 | LABRENDER_MODELLOADER_DLL) 65 | 66 | add_definitions(${_PXR_CXX_DEFINITIONS}) 67 | set(CMAKE_CXX_FLAGS "${_PXR_CXX_FLAGS} ${CMAKE_CXX_FLAGS}") 68 | endfunction() 69 | 70 | 71 | -------------------------------------------------------------------------------- /include/tinyusd_SceneProxy.h: -------------------------------------------------------------------------------- 1 | // 2 | // tinyusd_SceneProxy.h 3 | // TinyUSDTester 4 | // 5 | // Copyright © 2019 Nick Porcino 6 | // 7 | 8 | #ifndef SceneProxy_h 9 | #define SceneProxy_h 10 | 11 | #ifdef _MSC_VER 12 | #pragma warning(disable:4244) 13 | #pragma warning(disable:4305) 14 | #endif 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | PXR_NAMESPACE_USING_DIRECTIVE 24 | 25 | class SceneProxy : public TfWeakBase // in order to register for Tf events 26 | { 27 | // For changes from UsdStage. 28 | TfNotice::Key _objectsChangedNoticeKey; 29 | UsdStageRefPtr stage; 30 | public: 31 | 32 | ~SceneProxy(); 33 | 34 | void _OnObjectsChanged(UsdNotice::ObjectsChanged const& notice, UsdStageWeakPtr const& sender); 35 | 36 | void create_new_stage(std::string const& path); 37 | void load_stage(std::string const& filePath); 38 | void save_stage(); 39 | }; 40 | 41 | 42 | #endif /* SceneProxy_h */ 43 | 44 | #ifdef TINYUSD_SCENEPROXY_DRY 45 | 46 | SceneProxy::~SceneProxy() 47 | { 48 | TfNotice::Revoke(_objectsChangedNoticeKey); 49 | } 50 | 51 | void SceneProxy::_OnObjectsChanged(UsdNotice::ObjectsChanged const& notice, UsdStageWeakPtr const& sender) 52 | { 53 | printf("GetResyncedPaths\n"); 54 | auto pathsToResync = notice.GetResyncedPaths(); 55 | for (auto & i : pathsToResync) 56 | { 57 | printf("%s\n", i.GetString().c_str()); 58 | } 59 | printf("GetChangedInfoOnlyPaths\n"); 60 | auto infoPaths = notice.GetChangedInfoOnlyPaths(); 61 | for (auto & i : infoPaths) 62 | { 63 | printf("%s\n", i.GetString().c_str()); 64 | } 65 | } 66 | 67 | void SceneProxy::create_new_stage(std::string const& path) 68 | { 69 | TfNotice::Revoke(_objectsChangedNoticeKey); 70 | 71 | stage = UsdStage::CreateNew(path); 72 | 73 | // Start listening for change notices from this stage. 74 | auto self = TfCreateWeakPtr(this); 75 | _objectsChangedNoticeKey = TfNotice::Register(self, &SceneProxy::_OnObjectsChanged, stage); 76 | 77 | // create a cube on the stage 78 | stage->DefinePrim(SdfPath("/Box"), TfToken("Cube")); 79 | UsdPrim cube = stage->GetPrimAtPath(SdfPath("/Box")); 80 | GfVec3f scaleVec = { 5.f, 5.f, 5.f }; 81 | UsdGeomXformable cubeXf(cube); 82 | cubeXf.AddScaleOp().Set(scaleVec); 83 | } 84 | 85 | void SceneProxy::load_stage(std::string const& filePath) 86 | { 87 | printf("\nLoad_Stage : %s\n", filePath.c_str()); 88 | auto supported = UsdStage::IsSupportedFile(filePath); 89 | if (supported) 90 | { 91 | printf("File format supported\n"); 92 | } 93 | else 94 | { 95 | fprintf(stderr, "%s : File format not supported\n", filePath.c_str()); 96 | return; 97 | } 98 | 99 | UsdStageRefPtr loadedStage = UsdStage::Open(filePath); 100 | 101 | if (loadedStage) 102 | { 103 | auto pseudoRoot = loadedStage->GetPseudoRoot(); 104 | printf("Pseudo root path: %s\n", pseudoRoot.GetPath().GetString().c_str()); 105 | for (auto const& c : pseudoRoot.GetChildren()) 106 | { 107 | printf("\tChild path: %s\n", c.GetPath().GetString().c_str()); 108 | } 109 | } 110 | else 111 | { 112 | fprintf(stderr, "Stage was not loaded"); 113 | } 114 | } 115 | 116 | void SceneProxy::save_stage() 117 | { 118 | if (stage) 119 | stage->GetRootLayer()->Save(); 120 | } 121 | 122 | 123 | #endif -------------------------------------------------------------------------------- /packages/README.md: -------------------------------------------------------------------------------- 1 | shallow clone USD dev branch here, via 2 | 3 | `git clone --depth 1 https://github.com/PixarAnimationStudios/USD.git -b dev` 4 | 5 | -------------------------------------------------------------------------------- /src/main.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // SublayerZ.cpp 3 | // AllHail 4 | // 5 | // Created by Michael B. Johnson on 1/28/25. 6 | // 7 | 8 | // Build USD thusly: 9 | /* 10 | python3 ./build_scripts/build_usd.py \ 11 | --build-monolithic \ 12 | --no-examples --no-tools --no-docs \ 13 | --no-materialx \ 14 | --no-python \ 15 | --no-usdValidation \ 16 | --no-imaging \ 17 | --no-tutorials \ 18 | /opt/local/OpenUSD_V25_02MinMono 19 | */ 20 | 21 | // will have to either copy next to executable: 22 | // - libtbb.dylib 23 | // - libtbbmalloc.dylib 24 | // - libusd_ms.dylib 25 | // or do: 26 | // export DYLD_FALLBACK_LIBRARY_PATH=/opt/local/OpenUSD_V25_02MinMono/lib 27 | 28 | 29 | #include 30 | #include 31 | 32 | int main(int argc, char* argv[]) { 33 | // Create a new USD stage (or open an existing one) 34 | const std::string stageFile = "scene.usda"; 35 | pxr::UsdStageRefPtr stage = pxr::UsdStage::CreateNew(stageFile); 36 | if (!stage) { 37 | std::cerr << "Failed to create USD stage." << std::endl; 38 | return 1; 39 | } 40 | auto rootLayer = stage->GetRootLayer(); 41 | if (!rootLayer) { 42 | std::cerr << "Failed to root layer." << std::endl; 43 | return 1; 44 | } 45 | std::string subLayerPath("./ShinyBall.usdz"); 46 | // insert this USDZ as the top subLayer 47 | rootLayer->InsertSubLayerPath(subLayerPath, 0); 48 | 49 | // Save the USD stage to disk 50 | rootLayer->Save(); 51 | 52 | std::cout << "USD stage created and saved: " << stageFile << std::endl; 53 | return 0; 54 | } 55 | 56 | /* 57 | 58 | Works fine in 24.08 and 24.11: 59 | 60 | #usda 1.0 61 | ( 62 | subLayers = [ 63 | @./ShinyBall.usdz@ 64 | ] 65 | ) 66 | 67 | 68 | In 25.02: 69 | 70 | Coding Error: in _CreateAnonymousWithFormat at line 370 of /Users/drwave/git/OpenUSD/pxr/usd/sdf/layer.cpp -- Cannot create anonymous layer: creating package usdz layer is not allowed through this API. 71 | 72 | ----------------------------- SublayerZ terminated ----------------------------- 73 | SublayerZ crashed. FATAL ERROR: attempted member lookup on NULL TfRefPtr 74 | in operator-> at line 933 of /Users/drwave/git/OpenUSD/pxr/base/tf/refPtr.h 75 | writing crash report to [ Mac.localdomain:/var/folders/8q/4zz9spc91c7fx9vh8p9msc5m0000gp/T//st_SublayerZ.40311 ] ... done. 76 | -------------------------------------------------------------------------------- 77 | 78 | */ 79 | --------------------------------------------------------------------------------