Skip to content

Adding OpenUSD example #642

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ build/
/build*
/.vscode
*.DS_Store
install/
venv/
132 changes: 132 additions & 0 deletions examples/OpenUSD/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)

project(CPMExampleOpenUSD)

# ---- Tools ----

macro(find_targets targets dir)
get_property(subdirectories DIRECTORY ${dir} PROPERTY SUBDIRECTORIES)
foreach(subdir ${subdirectories})
find_targets(${targets} ${subdir})
endforeach()
get_property(current_targets DIRECTORY ${dir} PROPERTY BUILDSYSTEM_TARGETS)
list(APPEND ${targets} ${current_targets})
endmacro()

function(add_prefix_to_folder prefix)
if(CMAKE_GENERATOR MATCHES "Visual Studio")
foreach(target ${ARGN})
get_target_property(folder ${target} FOLDER)
if(folder STREQUAL "folder-NOTFOUND")
set(folder "${prefix}")
else()
set(folder "${prefix}/${folder}")
endif()
set_property(TARGET ${target} PROPERTY FOLDER "${folder}")
endforeach()
endif()
endfunction(add_prefix_to_folder)

# ---- Dependencies ----

include(../../cmake/CPM.cmake)

include(${CMAKE_CURRENT_SOURCE_DIR}/VEnv.cmake)

# Do not use the latest version (2022.0.0) as it fails to compile.
# The error occurs in openusd\pxr\base\work\dispatcher.cpp at line 36.
CPMAddPackage(
NAME TBB
VERSION 2021.13.0
GITHUB_REPOSITORY uxlfoundation/oneTBB
OPTIONS
"TBB_TEST OFF")
find_targets(TBB_targets ${TBB_SOURCE_DIR})
add_prefix_to_folder(TBB ${TBB_targets})
set(TBB_INCLUDE_DIRS "")
set(TBB_tbb_LIBRARY tbb)

CPMAddPackage(
NAME OpenSubdiv
VERSION 3.6.0
GITHUB_REPOSITORY PixarAnimationStudios/OpenSubdiv
GIT_TAG v3_6_0
OPTIONS
"NO_EXAMPLES ON"
"NO_TUTORIALS ON"
"NO_REGRESSION ON"
"NO_DOC ON"
"NO_TESTS ON")
find_targets(OpenSubdiv_targets ${OpenSubdiv_SOURCE_DIR})
add_prefix_to_folder(OpenSubdiv ${OpenSubdiv_targets})
target_include_directories(osd_static_cpu SYSTEM PUBLIC $<BUILD_INTERFACE:${OpenSubdiv_SOURCE_DIR}>)
target_include_directories(osd_static_gpu SYSTEM PUBLIC $<BUILD_INTERFACE:${OpenSubdiv_SOURCE_DIR}>)
set(OPENSUBDIV_INCLUDE_DIR "")
set(OPENSUBDIV_OSDCPU_LIBRARY osd_static_cpu)
set(OPENSUBDIV_LIBRARIES osd_static_cpu osd_static_gpu)

CPMAddPackage(
NAME OpenUSD
VERSION 24.11
GITHUB_REPOSITORY PixarAnimationStudios/OpenUSD
PATCHES "OpenUSD.patch" # Avoid the error "The solution already contains an item named 'boost'"
# and use the latest version of PySide.
OPTIONS
"PXR_BUILD_TESTS OFF"
"PXR_BUILD_EXAMPLES OFF"
"PXR_BUILD_TUTORIALS OFF"
"PXR_BUILD_HTML_DOCUMENTATION OFF")
find_targets(OpenUSD_targets ${OpenUSD_SOURCE_DIR})
add_prefix_to_folder(OpenUSD ${OpenUSD_targets})
set(OpenUSD_INCLUDE_DIR "${OpenUSD_BINARY_DIR}/include")
foreach(OpenUSD_target ${OpenUSD_targets})
get_target_property(OpenUSD_target_TYPE ${OpenUSD_target} TYPE)
if(OpenUSD_target_TYPE STREQUAL "SHARED_LIBRARY")
target_include_directories(${OpenUSD_target} SYSTEM PUBLIC $<BUILD_INTERFACE:${OpenUSD_INCLUDE_DIR}>)
elseif(OpenUSD_target_TYPE STREQUAL "EXECUTABLE")
# It's easier to set the Path than to configure the installation of different libraries
# TODO! Fix install
set_target_properties(${OpenUSD_target} PROPERTIES
VS_DEBUGGER_ENVIRONMENT "PATH=${CMAKE_INSTALL_PREFIX}/bin;${CMAKE_INSTALL_PREFIX}/lib")
elseif(OpenUSD_target_TYPE STREQUAL "UTILITY")
continue()
else()
message(FATAL_ERROR "Unknown target type: ${OpenUSD_target_TYPE} (${OpenUSD_target})")
endif()
endforeach()

CPMAddPackage(
NAME glfw
VERSION 3.4
GITHUB_REPOSITORY glfw/glfw
GIT_TAG 3.4
OPTIONS "BUILD_SHARED_LIBS ON"
"GLFW_BUILD_EXAMPLES OFF"
"GLFW_BUILD_TESTS OFF"
"GLFW_BUILD_DOCS OFF")
find_targets(glfw_targets ${glfw_SOURCE_DIR})
add_prefix_to_folder(glfw ${glfw_targets})

# ---- Executable ----

add_executable(CPMExampleOpenUSD main.cpp)
target_compile_features(CPMExampleOpenUSD PRIVATE cxx_std_17)
target_link_libraries(CPMExampleOpenUSD glfw glf hgiGL)

install(TARGETS CPMExampleOpenUSD RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
if(MSVC)
install(FILES $<TARGET_PDB_FILE:CPMExampleOpenUSD> DESTINATION ${CMAKE_INSTALL_BINDIR} OPTIONAL)
# It's easier to set the Path than to configure the installation of different libraries
# TODO! Fix install
set_target_properties(CPMExampleOpenUSD PROPERTIES
VS_DEBUGGER_ENVIRONMENT "PATH=${CMAKE_INSTALL_PREFIX}/bin;${CMAKE_INSTALL_PREFIX}/lib")
endif()

if(MSVC)
add_custom_target(usdview)
set_target_properties(usdview PROPERTIES
VS_DEBUGGER_COMMAND "${Python3_EXECUTABLE}"
VS_DEBUGGER_COMMAND_ARGUMENTS "${CMAKE_INSTALL_PREFIX}/bin/usdview ${CMAKE_SOURCE_DIR}/cube.usda"
VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_INSTALL_PREFIX}/bin"
VS_DEBUGGER_ENVIRONMENT "PYTHONPATH=$ENV{PYTHONPATH};${CMAKE_INSTALL_PREFIX}/lib/python\nPATH=$ENV{PATH};${CMAKE_INSTALL_PREFIX}/bin;${CMAKE_INSTALL_PREFIX}/lib")
endif()
55 changes: 55 additions & 0 deletions examples/OpenUSD/OpenUSD.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
diff --git a/cmake/modules/FindPySide.cmake b/cmake/modules/FindPySide.cmake
index 1fd02ff88..a20b3fe4c 100644
--- a/cmake/modules/FindPySide.cmake
+++ b/cmake/modules/FindPySide.cmake
@@ -16,7 +16,7 @@ execute_process(
)
if (pySideImportResult EQUAL 0)
set(pySideImportResult "PySide6")
- set(pySideUIC pyside6-uic python3-pyside6-uic)
+ set(pySideUIC uic pyside6-uic python3-pyside6-uic)
endif()

# PySide6 not found OR PYSIDE2 explicitly requested
diff --git a/pxr/external/boost/CMakeLists.txt b/pxr/external/boost/CMakeLists.txt
index c34d0bf21..0a1fb5988 100644
--- a/pxr/external/boost/CMakeLists.txt
+++ b/pxr/external/boost/CMakeLists.txt
@@ -1,5 +1,5 @@
set(PXR_PREFIX pxr/external)
-set(PXR_PACKAGE boost)
+set(PXR_PACKAGE usd_boost)

# This subdirectory currently only contains Python-related
# libraries, so skip it entirely if Python support is disabled.
@@ -7,7 +7,7 @@ if (NOT PXR_ENABLE_PYTHON_SUPPORT AND NOT TARGET python_modules)
return()
endif()

-pxr_library(boost
+pxr_library(usd_boost
PUBLIC_HEADERS
python.hpp

@@ -22,7 +22,7 @@ pxr_library(boost
# otherwise the build will error out at link time because no
# .lib file will be generated. Using this setting is OK because
# we only expect there to be one exportable symbol in this library.
-set_target_properties(boost
+set_target_properties(usd_boost
PROPERTIES
WINDOWS_EXPORT_ALL_SYMBOLS TRUE
)
diff --git a/pxr/external/boost/python/CMakeLists.txt b/pxr/external/boost/python/CMakeLists.txt
index ec85789f7..bfdbb3570 100644
--- a/pxr/external/boost/python/CMakeLists.txt
+++ b/pxr/external/boost/python/CMakeLists.txt
@@ -101,7 +101,7 @@ endif()

pxr_library(python
LIBRARIES
- boost
+ usd_boost
${libs}

INCLUDE_DIRS
29 changes: 29 additions & 0 deletions examples/OpenUSD/VEnv.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# https://discourse.cmake.org/t/possible-to-create-a-python-virtual-env-from-cmake-and-then-find-it-with-findpython3/1132
find_package(Python3 COMPONENTS Interpreter Development REQUIRED)

set(VENV_PATH "${CMAKE_CURRENT_SOURCE_DIR}/venv")

if(NOT EXISTS "${VENV_PATH}")
execute_process(COMMAND "${Python3_EXECUTABLE}" -m venv "${VENV_PATH}")
endif()

set(ENV{VIRTUAL_ENV} "${VENV_PATH}")
set(Python3_FIND_VIRTUALENV FIRST)
unset(Python3_EXECUTABLE)

find_package(Python3 COMPONENTS Interpreter Development REQUIRED)

execute_process(COMMAND "${Python3_EXECUTABLE}"
-m pip install
-r "${CMAKE_CURRENT_SOURCE_DIR}/pyrequirements.txt")

execute_process(COMMAND "${Python3_EXECUTABLE}"
-c "import PySide6; print(PySide6.__file__)"
OUTPUT_VARIABLE PYSIDE_BIN_DIR)

get_filename_component(PYSIDE_BIN_DIR "${PYSIDE_BIN_DIR}" DIRECTORY)
set(PYSIDE_BIN_DIR "${PYSIDE_BIN_DIR}")

install(FILES
${Python3_RUNTIME_LIBRARY_DIRS}/python${Python3_VERSION_MAJOR}${Python3_VERSION_MINOR}.dll
DESTINATION "${CMAKE_INSTALL_PREFIX}/bin")
26 changes: 26 additions & 0 deletions examples/OpenUSD/cube.usda
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#usda 1.0
(
metersPerUnit = 1
upAxis = "Z"
)

def Mesh "Cube" (
active = true
)
{
uniform bool doubleSided = 1
float3[] extent = [(-1, -1, -1), (1, 1, 1)]
int[] faceVertexCounts = [4, 4, 4, 4, 4, 4]
int[] faceVertexIndices = [0, 4, 6, 2, 3, 2, 6, 7, 7, 6, 4, 5, 5, 1, 3, 7, 1, 0, 2, 3, 5, 4, 0, 1]
normal3f[] normals = [(0, 0, 1), (0, 0, 1), (0, 0, 1), (0, 0, 1), (0, -1, 0), (0, -1, 0), (0, -1, 0), (0, -1, 0), (-1, 0, 0), (-1, 0, 0), (-1, 0, 0), (-1, 0, 0), (0, 0, -1), (0, 0, -1), (0, 0, -1), (0, 0, -1), (1, 0, 0), (1, 0, 0), (1, 0, 0), (1, 0, 0), (0, 1, 0), (0, 1, 0), (0, 1, 0), (0, 1, 0)] (
interpolation = "faceVarying"
)
point3f[] points = [(1, 1, 1), (1, 1, -1), (1, -1, 1), (1, -1, -1), (-1, 1, 1), (-1, 1, -1), (-1, -1, 1), (-1, -1, -1)]
bool[] primvars:sharp_face = [1, 1, 1, 1, 1, 1] (
interpolation = "uniform"
)
texCoord2f[] primvars:st = [(0.625, 0.5), (0.875, 0.5), (0.875, 0.75), (0.625, 0.75), (0.375, 0.75), (0.625, 0.75), (0.625, 1), (0.375, 1), (0.375, 0), (0.625, 0), (0.625, 0.25), (0.375, 0.25), (0.125, 0.5), (0.375, 0.5), (0.375, 0.75), (0.125, 0.75), (0.375, 0.5), (0.625, 0.5), (0.625, 0.75), (0.375, 0.75), (0.375, 0.25), (0.625, 0.25), (0.625, 0.5), (0.375, 0.5)] (
interpolation = "faceVarying"
)
uniform token subdivisionScheme = "none"
}
Loading