mirror of
https://github.com/lighttransport/tinyusdz.git
synced 2026-01-18 01:11:17 +01:00
Initial support for building with OpenSubdiv.
This commit is contained in:
@@ -9,6 +9,7 @@ project(${BUILD_TARGET} CXX)
|
||||
option(TINYUSDZ_USE_CCACHE "Use ccache for faster recompile." ON)
|
||||
option(TINYUSDZ_BUILD_TESTS "Build tests" ON)
|
||||
option(TINYUSDZ_BUILD_EXAMPLES "Build examples(but not all examples area built in `examples` folder)" ON)
|
||||
option(TINYUSDZ_WITH_OPENSUBDIV "Build with OpenSubdiv(osdCPU. Set `osd_DIR` to specify the path to OpenSubdiv)" OFF)
|
||||
|
||||
# cmake modules
|
||||
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
|
||||
@@ -54,12 +55,48 @@ set(TINYUSDZ_DEP_SOURCES
|
||||
${PROJECT_SOURCE_DIR}/src/pxrLZ4/lz4.cpp
|
||||
)
|
||||
|
||||
if (TINYUSDZ_WITH_OPENSUBDIV)
|
||||
|
||||
# https://stackoverflow.com/questions/41700463/push-pop-a-cmake-variable
|
||||
function ( ADD_OSD_LIB )
|
||||
|
||||
set(NO_TUTORIALS ON CACHE INTERNAL "" FORCE)
|
||||
set(NO_EXAMPLES ON CACHE INTERNAL "" FORCE)
|
||||
set(NO_REGRESSION ON CACHE INTERNAL "" FORCE)
|
||||
set(NO_DOC ON CACHE INTERNAL "" FORCE)
|
||||
set(NO_OMP ON CACHE INTERNAL "" FORCE)
|
||||
set(NO_TBB ON CACHE INTERNAL "" FORCE)
|
||||
set(NO_CUDA ON CACHE INTERNAL "" FORCE)
|
||||
set(NO_OPENCL ON CACHE INTERNAL "" FORCE)
|
||||
set(NO_OPENGL ON CACHE INTERNAL "" FORCE)
|
||||
set(NO_TESTS ON CACHE INTERNAL "" FORCE)
|
||||
set(NO_GLTESTS ON CACHE INTERNAL "" FORCE)
|
||||
set(NO_GLFW ON CACHE INTERNAL "" FORCE)
|
||||
set(NO_PTEX ON CACHE INTERNAL "" FORCE)
|
||||
|
||||
# Only build libosdCPU.a
|
||||
set(BUILD_SHARED_LIBS OFF CACHE INTERNAL "" FORCE)
|
||||
|
||||
add_subdirectory(${osd_DIR})
|
||||
|
||||
endfunction ()
|
||||
|
||||
ADD_OSD_LIB()
|
||||
list(APPEND TINYUSDZ_EXT_LIBRARIES osd_static_cpu)
|
||||
|
||||
endif (TINYUSDZ_WITH_OPENSUBDIV)
|
||||
|
||||
add_library(${BUILD_TARGET} ${TINYUSDZ_SOURCES} ${TINYUSDZ_DEP_SOURCES})
|
||||
add_sanitizers(${BUILD_TARGET})
|
||||
|
||||
target_include_directories(${BUILD_TARGET} PRIVATE ${PROJECT_SOURCE_DIR}/src)
|
||||
target_link_libraries(${BUILD_TARGET} ${TINYUSDZ_EXT_LIBRARIES} ${CMAKE_DL_LIBS})
|
||||
|
||||
if (TINYUSDZ_WITH_OPENSUBDIV)
|
||||
target_include_directories(${BUILD_TARGET} PRIVATE ${osd_DIR})
|
||||
target_compile_definitions(${BUILD_TARGET} PRIVATE "TINYUSDZ_USE_OPENSUBDIV")
|
||||
endif (TINYUSDZ_WITH_OPENSUBDIV)
|
||||
|
||||
# Increase warning level for clang.
|
||||
IF (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||
set_source_files_properties(${TINYUSDZ_SOURCES} PROPERTIES COMPILE_FLAGS "-Weverything -Werror -Wno-padded -Wno-c++98-compat-pedantic -Wno-documentation")
|
||||
@@ -80,7 +117,12 @@ if (TINYUSDZ_BUILD_TESTS)
|
||||
|
||||
target_include_directories(${TEST_TARGET} PRIVATE ${PROJECT_SOURCE_DIR}/src
|
||||
${PROJECT_SOURCE_DIR}/tests)
|
||||
target_link_libraries(${TEST_TARGET} ${BUILD_TARGET})
|
||||
target_link_libraries(${TEST_TARGET} PRIVATE ${BUILD_TARGET})
|
||||
|
||||
if (TINYUSDZ_WITH_OPENSUBDIV)
|
||||
target_compile_definitions(${TEST_TARGET} PRIVATE "TINYUSDZ_USE_OPENSUBDIV")
|
||||
endif (TINYUSDZ_WITH_OPENSUBDIV)
|
||||
|
||||
endif (TINYUSDZ_BUILD_TESTS)
|
||||
|
||||
# [VisualStudio]
|
||||
|
||||
@@ -17,6 +17,10 @@ USDZ contains usdc(binary) and resources(e.g. image file)
|
||||
|
||||
Recomended way is simply copy `src` and `include` folder to your app, and add `*.cc` files to your app's build system.
|
||||
|
||||
### Compiler defines
|
||||
|
||||
* `TINYUSDZ_USE_OPENSUBDIV` : Use OpenSubviv for subdivision surface(to get smooth mesh from USD(Z) primitive).
|
||||
|
||||
### CMake
|
||||
|
||||
cmake build is still provided, but not recommended
|
||||
@@ -28,11 +32,12 @@ $ cmake ..
|
||||
$ make
|
||||
```
|
||||
|
||||
#### Build options
|
||||
#### CMake build options
|
||||
|
||||
* `TINYUSDZ_BUILD_TESTS` : Build tests
|
||||
* `TINYUSDZ_BUILD_EXAMPLES` : Build examples(note that not all examples in `examples` folder are built)
|
||||
* `TINYUSDZ_USE_OPENSUBDIV` : Use OpenSubviv to tessellate subdivision surface.
|
||||
* `TINYUSDZ_WITH_OPENSUBDIV` : Use OpenSubviv to tessellate subdivision surface.
|
||||
* `osd_DIR` to specify the path to OpenSubdiv repo(I recommend to use https://github.com/syoyo/OpenSubdiv-aarch64 )
|
||||
|
||||
### Meson
|
||||
|
||||
|
||||
17
scripts/bootstrap-cmake-linux-with-osd.sh
Executable file
17
scripts/bootstrap-cmake-linux-with-osd.sh
Executable file
@@ -0,0 +1,17 @@
|
||||
curdir=`pwd`
|
||||
|
||||
# Set path to OpenSubdiv
|
||||
osd_path=${curdir}/deps/OpenSubdiv
|
||||
|
||||
builddir=${curdir}/build
|
||||
|
||||
rm -rf ${builddir}
|
||||
mkdir ${builddir}
|
||||
|
||||
|
||||
cd ${builddir} && cmake \
|
||||
-DCMAKE_VERBOSE_MAKEFILE=1 \
|
||||
-DTINYUSDZ_WITH_OPENSUBDIV=On \
|
||||
-Dosd_DIR=${osd_path} \
|
||||
..
|
||||
|
||||
@@ -15,6 +15,22 @@
|
||||
#include "stream-reader.hh"
|
||||
#include "tinyusdz.hh"
|
||||
|
||||
#if defined(TINYUSDZ_USE_OPENSUBDIV)
|
||||
|
||||
#ifdef __clang__
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Weverything"
|
||||
#endif
|
||||
|
||||
#include <opensubdiv/far/primvarRefiner.h>
|
||||
#include <opensubdiv/far/topologyDescriptor.h>
|
||||
|
||||
#ifdef __clang__
|
||||
#pragma clang diagnostic pop
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#include <iostream> // dbg
|
||||
|
||||
namespace tinyusdz {
|
||||
|
||||
Reference in New Issue
Block a user