Under USD related investigation
For the time being, it seems good to be able to handle USD in Python. We will use NVIDIA pre-build.
https://developer.nvidia.com/usd
ʻUSD 20.08, use Python 3.6`.
I put it in C: / Python36
Expanded to C: / Python36 / usd-20-08 and set the environment variable ʻUSDROOT` here.
usd-20-08-win64_py36_release.zip README.txt excerpt
== Python 3.6 ==
(Tested on python 3.6.7)
- Add %USDROOT%\bin and %USDROOT%\lib to the front of %PATH%
- Add %USDROOT%\lib\python to the front of %PYTHONPATH%
- Install PySide2 and PyOpenGL to python, e.g., python -m pip install PySide2 PyOpenGL
It is necessary to set PYTHONPATH and PATH. I will set it locally in the project with vscode.
vscode project
Create a hello_usd folder. Open the folder with vscode. Since it is usually python3.8, use python3.6 only for this project and set the environment variables for python locally.
.vscode/settings.json
{
    "python.pythonPath": "C:\\Python36\\python.exe",
    "python.envFile": "${workspaceFolder}/.env",
}
Variable expansion of .env is similar to settings.json, and environment variables are $ {env: XXX}.
.env
PYTHONPATH=${env:USDROOT}\\lib\\python
PATH=${env:USDROOT}\\bin;${env:USDROOT}\\lib;$PATH
import sys
import os
import pathlib
USDROOT = pathlib.Path(os.environ['USDROOT'])
def main(teapot: pathlib.Path):
    from pxr import Usd
    stage_ref = Usd.Stage.Open(str(teapot))
    prim = stage_ref.GetDefaultPrim()
    print(f'{prim.GetPath()}')
    print(f'type: {prim.GetTypeName()}')
    for child in prim.GetChildren():
        print(f'{child.GetPath()}, type: {child.GetTypeName()}')
        # if child.GetTypeName() == 'Mesh':
        for attr in child.GetAttributes():
            print(f'   {attr}')
if __name__ == "__main__":
    teapot = USDROOT / "tests/ctest/testUsdLuxListAPI/teapot.usda"
    main(teapot)
Somehow it worked. For what you do with Python,
The combination of is relatively easy.
Toolset
https://graphics.pixar.com/usd/docs/USD-Toolset.html
usdview
The usd package bin / usdview is the command to start the viewer.
https://github.com/PixarAnimationStudios/USD/blob/release/pxr/usdImaging/bin/usdview/usdview.py
We will modify usdview.cmd a little to prepare environment variables.
usdview.cmd
set PYTHONPATH=%USDROOT%\lib\python
set PATH=%USDROOT%\bin;%USDROOT%\lib;%PATH%
@py -3.6 "%~dp0usdview" %*
I tried to associate ʻusda, ʻusdc, ʻusdz` with bin / usdview.cmd.

Viewpoint operation with alt + drag (l, r, m)
It was easy to get the USD source and build with build_usd.py.
build_usd.py
Automatically build with build_scripts / build_usd.py that comes with the USD source.
First, open the dos window from x64 Native Tools Command Prompt for VS2019 which can be done by installing vc.
# cl.The exe is in the path.
> cl.exe
Microsoft (R) C/C++ Optimizing Compiler Version 19.27.29111 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.
usage: cl [ option... ] filename... [ /link linkoption... ]
Go to the usd source folder. Execute after passing python to PATH.
> set PATH=C:\Python36;%PATH%
> C:\Python36\python.exe build_scripts\build_usd.py
usage: build_usd.py [-h] [-n] [-v | -q] [-j JOBS] [--build BUILD]
                    [--build-args [BUILD_ARGS [BUILD_ARGS ...]]]
                    [--force FORCE_BUILD] [--force-all]
                    [--generator GENERATOR] [--src SRC] [--inst INST]
                    [--build-shared | --build-monolithic] [--debug]
                    [--tests | --no-tests] [--examples | --no-examples]
                    [--tutorials | --no-tutorials] [--tools | --no-tools]
                    [--docs | --no-docs] [--python | --no-python]
                    [--imaging | --usd-imaging | --no-imaging]
                    [--ptex | --no-ptex] [--openvdb | --no-openvdb]
                    [--usdview | --no-usdview] [--embree | --no-embree]
                    [--prman | --no-prman] [--prman-location PRMAN_LOCATION]
                    [--openimageio | --no-openimageio]
                    [--opencolorio | --no-opencolorio]
                    [--alembic | --no-alembic] [--hdf5 | --no-hdf5]
                    [--draco | --no-draco] [--draco-location DRACO_LOCATION]
                    [--materialx | --no-materialx]
                    install_dir
build_usd.py: error: the following arguments are required: install_dir
There are many options, so choose according to your needs. This time, I did the following because I want to do a debug build related to hydra.
> C:\Python36\python.exe build_scripts\build_usd.py --debug --build-monolithic --no-tests --no-examples --no-tutorials --no-docs --no-python --usd-imaging C:\usd_debug
Building with settings:
  USD source directory          C:\USD
  USD install directory         C:\usd_debug
  3rd-party source directory    C:\usd_debug\src
  3rd-party install directory   C:\usd_debug
  Build directory               C:\usd_debug\build
  CMake generator               Default
  Downloader                    curl
  Building                      Shared libraries
    Config                      Debug
    Imaging                     On
      Ptex support:             Off
      OpenVDB support:          Off
      OpenImageIO support:      Off
      OpenColorIO support:      Off
      PRMan support:            Off
    UsdImaging                  On
      usdview:                  Off
    Python support              Off
      Python 3:                 On
    Documentation               Off
    Tests                       Off
    Examples                    Off
    Tutorials                   Off
    Tools                       On
    Alembic Plugin              Off
      HDF5 support:             Off
    Draco Plugin                Off
    MaterialX Plugin            Off
  Dependencies                  zlib, boost, TBB, GLEW, OpenSubdiv
STATUS: Installing zlib...
STATUS: Installing boost...
STATUS: Installing TBB...
STATUS: Installing GLEW...
STATUS: Installing OpenSubdiv...
STATUS: Installing USD...
Success! To use USD, please ensure that you have:
    The following in your PATH environment variable:
    C:\usd_debug\bin
    C:\usd_debug\lib
I was able to build in about 10 minutes.
https://github.com/ousttrue/usd_cpp_samples
project(cpp_usd)
cmake_minimum_required(VERSION 3.0.0)
set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/Debug/lib)
set (CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/Debug/lib)
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/Debug/bin)
set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/Release/lib)
set (CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/Release/lib)
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/Release/bin)
find_package(pxr CONFIG REQUIRED)
link_directories(
    $ENV{VCPKG_DIR}/installed/x64-windows/lib
)
add_executable(cpp_usd
    main.cpp
)
target_include_directories(cpp_usd
PRIVATE
    C:/usd_debug/include
    C:/usd_debug/include/boost-1_70
)
target_compile_options(cpp_usd
PRIVATE
    /wd4244
    /wd4305
    )
target_link_libraries(cpp_usd
PRIVATE
    C:/usd_debug/lib/usd_ms.lib #I built it with monolithic, so tf, gf, sdf, usd,usdGeom etc. are gathered together
    C:/usd_debug/lib/tbb_debug.lib
)
It worked if I put the PATH in C: / usd_debug / bin and C: / usd_debug / lib at runtime.
vcpkg
No ALEMBIC or Python.
./vcpkg install usd
did it.
https://fereria.github.io/reincarnation_tech/11_Pipeline/30_USD_Programming/00_CPP/00_start_cpp/
I will try. I was able to build.
CMakeLists.txt
project(cpp_usd)
cmake_minimum_required(VERSION 3.0.0)
set(USD_DIR $ENV{VCPKG_DIR}/installed/x64-windows)
set(BOOST_INCLUDE_DIR $ENV{VCPKG_DIR}/installed/x64-winddows/include)
# tbb_debug.lib is#Since it is specified by pragma, for the time being
link_directories(
    ${USD_DIR}/lib
    ${USD_DIR}/debug/lib
)
add_executable(cpp_usd
main.cpp
)
target_include_directories(cpp_usd
PRIVATE
    ${USD_DIR}/include
    ${BOOST_INCLUDE_DIR}
)
target_compile_definitions(cpp_usd
PRIVATE
    TBB_USE_DEBUG=0 #Since tbb causes a compile error, for the time being
)
target_compile_options(cpp_usd
PRIVATE
    /wd4244
    /wd4305
    )
target_link_libraries(cpp_usd
PRIVATE
    ${USD_DIR}/lib/tf.lib
    ${USD_DIR}/lib/sdf.lib
    ${USD_DIR}/lib/usd.lib
    ${USD_DIR}/lib/usdgeom.lib
    ${USD_DIR}/lib/trace.lib
)
But it fits.
Coding Error: in CreateAnonymous at line 313 of C:\vcpkg\buildtrees\usd\src\2cd10d91c8-241e05f4dd.clean\pxr\usd\sdf\layer.cpp -- Cannot determine file format for anonymous SdfLayer
Coding Error: in Open at line 994 of C:\vcpkg\buildtrees\usd\src\2cd10d91c8-241e05f4dd.clean\pxr\usd\usd\stage.cpp -- Invalid root layer
vcpkg can also make debug builds, so I attached and tracked the debugger.
The environment variable PXR_PLUGINPATH_NAME should point to the location of plugInfo.json.
${env:VCPKG_DIR}\\installed\\x64-windows\\lib\\usd${env:VCPKG_DIR}\\installed\\x64-windows\\plugin\\usdcmake/macros/Private.cmake
            PXR_BUILD_LOCATION=usd
            PXR_PLUGIN_BUILD_LOCATION=../plugin/usd
It doesn't seem to work if the folder structure changes
It doesn't work yet. Next error
Coding Error: in _Load at line 248 of C:\vcpkg\buildtrees\usd\src\2cd10d91c8-241e05f4dd.clean\pxr\base\plug\plugin.cpp -- Load of 'c:/vcpkg/installed/x64-windows/lib/usd.dll' for 'usd' failed:The specified module cannot be found.
Coding Error: in _Load at line 248 of C:\vcpkg\buildtrees\usd\src\2cd10d91c8-241e05f4dd.clean\pxr\base\plug\plugin.cpp -- Load of 'c:/vcpkg/installed/x64-windows/lib/usd.dll' for 'usd' failed:The specified module cannot be found.
Not c: /vcpkg/installed/x64-windows/lib/usd.dll, but c: /vcpkg/installed/x64-windows/bin/usd.dll.
Fixed the contents of pluginfo.json.
lib/usd/**/plulgInfo.json
"LibraryPath": "../../ndr.dll", 
//Fix
"LibraryPath": "../../../bin/ndr.dll", 
It finally worked.
https://github.com/microsoft/vcpkg/pull/13687
lib
  usd.dll
  sdf.dll
  usd
     plugInfo.json # PXR_PLUGINPATH_Can be specified with the NAME environment variable
     
     usd/resources/plugInfo.json
     sdf/resources/plugInfo.json
plugin
  usd
    plugInfo.json # PXR_PLUGINPATH_Can be specified with the NAME environment variable
    
    usdShaders.dll
    usdShaders/resources/plugInfo.json
If you change the folder structure like this, you need to pay attention to the contents of the PXR_PLUGINPATH_NAME environment variable and plugInfo.json.
If you make a mistake
auto stage = pxr::UsdStage::CreateInMemory(); //plugin fails to load and becomes null
Something like that happens.
// plug.dll
Plug_InitConfig
// "C:\\vcpkg\\installed\\x64-windows\\debug\\bin\\plug.dll" <= GetModule
// sharedLibPath = "C:\\vcpkg\\installed\\x64-windows\\debug\\bin reference directory
Plug_SetPaths
  PXR_PLUGINPATH_NAME
  sharedLibPath + PXR_BUILD_LOCATION=usd
  sharedLibPath + PXR_PLUGIN_BUILD_LOCATION=../plugin/usd
Source
extras
  imaging
    examples
      hdTiny #hydra sample
  usd
    examples
    tutorials
Blender-2.83
It seems that UsdSkel support is not yet available, so I feel like I can't put out a model with bones.
The USD Import / Export is a c ++ implementation rather than a python addon. The USD Python binding doesn't seem to be enabled. Boost-Python is annoying. Recognize.
Unity
It seems that there are already some places that are likely to be used up to Skinning Mesh.
Wrap usd with swig so that it can be used from C #
Unknown
Since usd is a c ++ dll, it is confusing that functions cannot be easily called from other languages.
I hope there is an interface for C.
It might be a good idea to make a python version from the unity version of swig.
Recommended Posts