mirror of
https://github.com/lighttransport/tinyusdz.git
synced 2026-01-18 01:11:17 +01:00
Apply formatter.
This commit is contained in:
@@ -6,17 +6,23 @@ set(BUILD_TARGET "usdz_view")
|
||||
project(${BUILD_TARGET} CXX C)
|
||||
|
||||
option(TINYUSDZ_USE_CCACHE "Use ccache for faster recompile." ON)
|
||||
option(TINYUSDZ_WITH_OPENSUBDIV "Build with OpenSubdiv(osdCPU. if required, set `osd_DIR` to specify the path to your own OpenSubdiv)" ON)
|
||||
option(USDVIEW_USE_NATIVEFILEDIALOG "Use nativefiledialog. Requires gtk+-3 libs on linux to build" ON)
|
||||
option(
|
||||
TINYUSDZ_WITH_OPENSUBDIV
|
||||
"Build with OpenSubdiv(osdCPU. if required, set `osd_DIR` to specify the path to your own OpenSubdiv)"
|
||||
ON)
|
||||
option(USDVIEW_USE_NATIVEFILEDIALOG
|
||||
"Use nativefiledialog. Requires gtk+-3 libs on linux to build" ON)
|
||||
option(USDVIEW_ENABLE_PHYSICS "Enable Physics(through Bullet3)" OFF)
|
||||
|
||||
if (EMSCRIPTEN)
|
||||
if(EMSCRIPTEN)
|
||||
# Disable nfd
|
||||
set(USDVIEW_USE_NATIVEFILEDIALOG OFF CACHE INTERNAL "" FORCE)
|
||||
endif ()
|
||||
set(USDVIEW_USE_NATIVEFILEDIALOG
|
||||
OFF
|
||||
CACHE INTERNAL "" FORCE)
|
||||
endif()
|
||||
|
||||
# Use embedded version of OpenSubdiv code by default
|
||||
set(osd_DIR ${PROJECT_SOURCE_DIR}/../../src/osd)
|
||||
set(osd_DIR ${PROJECT_SOURCE_DIR}/../../src/osd)
|
||||
|
||||
# imgui_sdl requires C++14
|
||||
set(CMAKE_CXX_STANDARD 14)
|
||||
@@ -28,25 +34,34 @@ list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/../../cmake)
|
||||
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/../../cmake/sanitizers)
|
||||
find_package(Sanitizers) # Address sanitizer (-DSANITIZE_ADDRESS=ON)
|
||||
|
||||
if (USDVIEW_USE_NATIVEFILEDIALOG)
|
||||
add_subdirectory(${PROJECT_SOURCE_DIR}/../common/nativefiledialog-extended nfd_build)
|
||||
if(USDVIEW_USE_NATIVEFILEDIALOG)
|
||||
add_subdirectory(${PROJECT_SOURCE_DIR}/../common/nativefiledialog-extended
|
||||
nfd_build)
|
||||
endif()
|
||||
|
||||
if (USDVIEW_ENABLE_PHYSICS)
|
||||
if(USDVIEW_ENABLE_PHYSICS)
|
||||
|
||||
# https://stackoverflow.com/questions/41700463/push-pop-a-cmake-variable
|
||||
function ( ADD_BULLET3_LIB )
|
||||
set(BUILD_CPU_DEMOS OFF CACHE INTERNAL "" FORCE)
|
||||
set(BUILD_UNIT_TESTS OFF CACHE INTERNAL "" FORCE)
|
||||
set(BUILD_EXTRAS OFF CACHE INTERNAL "" FORCE)
|
||||
if (MSVC)
|
||||
# StaticLib conflicts usd_view build itself. so link with dll as a work around.
|
||||
set(USE_MSVC_RUNTIME_LIBRARY_DLL ON CACHE INTERNAL "" FORCE)
|
||||
endif()
|
||||
function(ADD_BULLET3_LIB)
|
||||
set(BUILD_CPU_DEMOS
|
||||
OFF
|
||||
CACHE INTERNAL "" FORCE)
|
||||
set(BUILD_UNIT_TESTS
|
||||
OFF
|
||||
CACHE INTERNAL "" FORCE)
|
||||
set(BUILD_EXTRAS
|
||||
OFF
|
||||
CACHE INTERNAL "" FORCE)
|
||||
if(MSVC)
|
||||
# StaticLib conflicts usd_view build itself. so link with dll as a work around.
|
||||
set(USE_MSVC_RUNTIME_LIBRARY_DLL
|
||||
ON
|
||||
CACHE INTERNAL "" FORCE)
|
||||
endif()
|
||||
add_subdirectory(../common/bullet3 bullet3_build)
|
||||
endfunction ()
|
||||
endfunction()
|
||||
|
||||
ADD_BULLET3_LIB()
|
||||
add_bullet3_lib()
|
||||
endif()
|
||||
|
||||
# [ccache]
|
||||
@@ -80,79 +95,122 @@ endif()
|
||||
#find_package(OpenGL REQUIRED)
|
||||
|
||||
# https://stackoverflow.com/questions/41700463/push-pop-a-cmake-variable
|
||||
function ( ADD_SDL2_LIB )
|
||||
function(ADD_SDL2_LIB)
|
||||
# Disable OpenGL
|
||||
set(VIDEO_OPENGL OFF CACHE INTERNAL "" FORCE)
|
||||
set(VIDEO_OPENGLES OFF CACHE INTERNAL "" FORCE)
|
||||
set(VIDEO_WAYLAND OFF CACHE INTERNAL "" FORCE)
|
||||
set(VIDEO_OPENGL
|
||||
OFF
|
||||
CACHE INTERNAL "" FORCE)
|
||||
set(VIDEO_OPENGLES
|
||||
OFF
|
||||
CACHE INTERNAL "" FORCE)
|
||||
set(VIDEO_WAYLAND
|
||||
OFF
|
||||
CACHE INTERNAL "" FORCE)
|
||||
|
||||
# Enable static lib only
|
||||
set(SDL_SAHARED OFF CACHE INTERNAL "" FORCE)
|
||||
set(SDL_STATIC ON CACHE INTERNAL "" FORCE)
|
||||
set(SDL_SAHARED
|
||||
OFF
|
||||
CACHE INTERNAL "" FORCE)
|
||||
set(SDL_STATIC
|
||||
ON
|
||||
CACHE INTERNAL "" FORCE)
|
||||
add_subdirectory(../common/SDL2-2.0.22/ SDL2)
|
||||
endfunction ()
|
||||
endfunction()
|
||||
|
||||
if (EMSCRIPTEN)
|
||||
if(EMSCRIPTEN)
|
||||
# Use emcc ported SDL2
|
||||
# https://stackoverflow.com/questions/61590519/how-to-use-emscripten-ports-sdl2-and-freetype-with-cmake
|
||||
|
||||
# Assume `suzanne.usdc` is coped to build directory with PRE_BUILD custom command
|
||||
# TODO: Read USD file from JS world
|
||||
# TODO: Use max memory size.
|
||||
set(USE_FLAGS "-s ASSERTIONS=1 -s USE_SDL=2 -s USE_FREETYPE=1 --embed-file suzanne.usdc")
|
||||
set(USE_FLAGS
|
||||
"-s ASSERTIONS=1 -s USE_SDL=2 -s USE_FREETYPE=1 --embed-file suzanne.usdc"
|
||||
)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${USE_FLAGS}")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${USE_FLAGS}")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${USE_FLAGS} -s ALLOW_MEMORY_GROWTH=1")
|
||||
set(CMAKE_EXE_LINKER_FLAGS
|
||||
"${CMAKE_EXE_LINKER_FLAGS} ${USE_FLAGS} -s ALLOW_MEMORY_GROWTH=1")
|
||||
set(CMAKE_EXECUTABLE_SUFFIX .html)
|
||||
|
||||
set(USDVIEW_SDL2_LIBRARIES ${SDL2_LIBRARIES})
|
||||
else()
|
||||
ADD_SDL2_LIB()
|
||||
add_sdl2_lib()
|
||||
set(USDVIEW_SDL2_LIBRARIES SDL2-static SDL2main)
|
||||
endif()
|
||||
|
||||
|
||||
if(WIN32)
|
||||
# do nothing.
|
||||
# do nothing.
|
||||
elseif(APPLE)
|
||||
find_library(COCOA Cocoa REQUIRED)
|
||||
find_library(COCOA Cocoa REQUIRED)
|
||||
elseif(EMSCRIPTEN)
|
||||
# do nothing
|
||||
# do nothing
|
||||
else()
|
||||
find_package(X11 REQUIRED)
|
||||
find_package(X11 REQUIRED)
|
||||
endif()
|
||||
|
||||
if (TINYUSDZ_WITH_OPENSUBDIV)
|
||||
if(TINYUSDZ_WITH_OPENSUBDIV)
|
||||
|
||||
# add dummy macros
|
||||
macro(_add_doxy_headers headers)
|
||||
endmacro()
|
||||
|
||||
# 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)
|
||||
endmacro()
|
||||
|
||||
# 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)
|
||||
set(BUILD_SHARED_LIBS
|
||||
OFF
|
||||
CACHE INTERNAL "" FORCE)
|
||||
|
||||
# add_subdirectory(${osd_DIR})
|
||||
|
||||
# CMakeLists of OSD package is problematic,
|
||||
# so provide our own one.
|
||||
list(APPEND OSD_FAR_SOURCES
|
||||
list(
|
||||
APPEND
|
||||
OSD_FAR_SOURCES
|
||||
${osd_DIR}/opensubdiv/far/bilinearPatchBuilder.cpp
|
||||
${osd_DIR}/opensubdiv/far/catmarkPatchBuilder.cpp
|
||||
${osd_DIR}/opensubdiv/far/error.cpp
|
||||
@@ -169,66 +227,65 @@ if (TINYUSDZ_WITH_OPENSUBDIV)
|
||||
${osd_DIR}/opensubdiv/far/stencilBuilder.cpp
|
||||
${osd_DIR}/opensubdiv/far/topologyDescriptor.cpp
|
||||
${osd_DIR}/opensubdiv/far/topologyRefiner.cpp
|
||||
${osd_DIR}/opensubdiv/far/topologyRefinerFactory.cpp
|
||||
)
|
||||
${osd_DIR}/opensubdiv/far/topologyRefinerFactory.cpp)
|
||||
|
||||
# CPU only
|
||||
list(APPEND OSD_OSD_SOURCES
|
||||
list(
|
||||
APPEND
|
||||
OSD_OSD_SOURCES
|
||||
${osd_DIR}/opensubdiv/osd/cpuEvaluator.cpp
|
||||
${osd_DIR}/opensubdiv/osd/cpuKernel.cpp
|
||||
${osd_DIR}/opensubdiv/osd/cpuPatchTable.cpp
|
||||
${osd_DIR}/opensubdiv/osd/cpuVertexBuffer.cpp
|
||||
)
|
||||
${osd_DIR}/opensubdiv/osd/cpuVertexBuffer.cpp)
|
||||
|
||||
list(APPEND OSD_SDC_SOURCES
|
||||
${osd_DIR}/opensubdiv/sdc/typeTraits.cpp
|
||||
${osd_DIR}/opensubdiv/sdc/crease.cpp
|
||||
)
|
||||
list(APPEND OSD_SDC_SOURCES ${osd_DIR}/opensubdiv/sdc/typeTraits.cpp
|
||||
${osd_DIR}/opensubdiv/sdc/crease.cpp)
|
||||
|
||||
list(APPEND OSD_VTR_SOURCES
|
||||
list(
|
||||
APPEND
|
||||
OSD_VTR_SOURCES
|
||||
${osd_DIR}/opensubdiv/vtr/fvarLevel.cpp
|
||||
${osd_DIR}/opensubdiv/vtr/fvarRefinement.cpp
|
||||
${osd_DIR}/opensubdiv/vtr/level.cpp
|
||||
${osd_DIR}/opensubdiv/vtr/quadRefinement.cpp
|
||||
${osd_DIR}/opensubdiv/vtr/refinement.cpp
|
||||
${osd_DIR}/opensubdiv/vtr/sparseSelector.cpp
|
||||
${osd_DIR}/opensubdiv/vtr/triRefinement.cpp
|
||||
)
|
||||
|
||||
${osd_DIR}/opensubdiv/vtr/triRefinement.cpp)
|
||||
|
||||
add_library(osd_cpu ${OSD_FAR_SOURCES} ${OSD_OSD_SOURCES})
|
||||
target_include_directories(osd_cpu PRIVATE ${osd_DIR})
|
||||
|
||||
endfunction ()
|
||||
endfunction()
|
||||
|
||||
ADD_OSD_LIB()
|
||||
add_osd_lib()
|
||||
|
||||
list(APPEND EXT_LIBRARIES osd_cpu)
|
||||
list(APPEND EXT_LIBRARIES osd_cpu)
|
||||
|
||||
list(APPEND SOUECES ${PROJECT_SOURCE_DIR}/src/subdiv.cc)
|
||||
|
||||
endif (TINYUSDZ_WITH_OPENSUBDIV)
|
||||
endif(TINYUSDZ_WITH_OPENSUBDIV)
|
||||
|
||||
list(APPEND SOURCES
|
||||
main.cc
|
||||
simple-render.cc
|
||||
gui.cc
|
||||
#render.cc
|
||||
#render-config.cc
|
||||
|
||||
# tinyusdz
|
||||
../../src/tinyusdz.cc
|
||||
../../src/io-util.cc
|
||||
../../src/prim-types.cc
|
||||
../../src/pprinter.cc
|
||||
../../src/primvar.cc
|
||||
../../src/usda-parser.cc
|
||||
../../src/usda-writer.cc
|
||||
../../src/image-loader.cc
|
||||
../../src/usdObj.cc
|
||||
#../../src/integerCoding.cpp
|
||||
#../../src/pxrLZ4/lz4.cpp
|
||||
#../../src/lz4-compression.cc
|
||||
list(
|
||||
APPEND
|
||||
SOURCES
|
||||
main.cc
|
||||
simple-render.cc
|
||||
gui.cc
|
||||
#render.cc
|
||||
#render-config.cc
|
||||
# tinyusdz
|
||||
../../src/tinyusdz.cc
|
||||
../../src/io-util.cc
|
||||
../../src/prim-types.cc
|
||||
../../src/pprinter.cc
|
||||
../../src/primvar.cc
|
||||
../../src/usda-parser.cc
|
||||
../../src/usda-writer.cc
|
||||
../../src/image-loader.cc
|
||||
../../src/usdObj.cc
|
||||
#../../src/integerCoding.cpp
|
||||
#../../src/pxrLZ4/lz4.cpp
|
||||
#../../src/lz4-compression.cc
|
||||
)
|
||||
|
||||
set(TINYUSDZ_DEP_SOURCES
|
||||
@@ -241,7 +298,6 @@ set(TINYUSDZ_DEP_SOURCES
|
||||
../../src/external/ryu/ryu/s2d.c
|
||||
../../src/external/ryu/ryu/s2f.c)
|
||||
|
||||
|
||||
set(GUI_SOURCES
|
||||
../common/trackball.cc
|
||||
../common/matrix.cc
|
||||
@@ -249,72 +305,73 @@ set(GUI_SOURCES
|
||||
../common/imgui/imgui_draw.cpp
|
||||
../common/imgui/imgui_widgets.cpp
|
||||
../common/imgui/imgui_tables.cpp
|
||||
|
||||
../common/imgui/imgui_impl_sdl.cpp
|
||||
../common/imgui/imgui_impl_sdlrenderer.cpp
|
||||
|
||||
# imnodes
|
||||
../common/imnodes/imnodes.cpp
|
||||
)
|
||||
../common/imnodes/imnodes.cpp)
|
||||
|
||||
add_executable(${BUILD_TARGET} ${SOURCES} ${GUI_SOURCES} ${TINYUSDZ_DEP_SOURCES})
|
||||
add_executable(${BUILD_TARGET} ${SOURCES} ${GUI_SOURCES}
|
||||
${TINYUSDZ_DEP_SOURCES})
|
||||
add_sanitizers(${BUILD_TARGET})
|
||||
target_compile_options(${BUILD_TARGET} PRIVATE ${EXT_COMPILE_OPTIONS})
|
||||
|
||||
if (UNIX)
|
||||
if(UNIX)
|
||||
target_include_directories(${BUILD_TARGET} PUBLIC ${X11_INCLUDE_DIR})
|
||||
endif()
|
||||
|
||||
target_include_directories(${BUILD_TARGET} PRIVATE "${PROJECT_SOURCE_DIR}/../common")
|
||||
target_include_directories(${BUILD_TARGET} PRIVATE "${PROJECT_SOURCE_DIR}/../common/imgui")
|
||||
target_include_directories(${BUILD_TARGET} PRIVATE "${PROJECT_SOURCE_DIR}/../common/imnodes")
|
||||
target_include_directories(${BUILD_TARGET}
|
||||
PRIVATE "${PROJECT_SOURCE_DIR}/../common")
|
||||
target_include_directories(${BUILD_TARGET}
|
||||
PRIVATE "${PROJECT_SOURCE_DIR}/../common/imgui")
|
||||
target_include_directories(${BUILD_TARGET}
|
||||
PRIVATE "${PROJECT_SOURCE_DIR}/../common/imnodes")
|
||||
|
||||
# tinyusdz dir
|
||||
target_include_directories(${BUILD_TARGET} PRIVATE "${PROJECT_SOURCE_DIR}/../../src/")
|
||||
target_include_directories(${BUILD_TARGET}
|
||||
PRIVATE "${PROJECT_SOURCE_DIR}/../../src/")
|
||||
|
||||
# ryu
|
||||
target_include_directories(${BUILD_TARGET}
|
||||
PRIVATE ${PROJECT_SOURCE_DIR}/../../src/external/ryu/)
|
||||
|
||||
target_include_directories(
|
||||
${BUILD_TARGET} PRIVATE ${PROJECT_SOURCE_DIR}/../../src/external/ryu/)
|
||||
|
||||
#target_include_directories(${BUILD_TARGET} PRIVATE "${PROJECT_SOURCE_DIR}/../common/SDL2-2.0.12/include"
|
||||
|
||||
if (USDVIEW_USE_NATIVEFILEDIALOG)
|
||||
target_compile_definitions(${BUILD_TARGET} PRIVATE "USDVIEW_USE_NATIVEFILEDIALOG")
|
||||
if(USDVIEW_USE_NATIVEFILEDIALOG)
|
||||
target_compile_definitions(${BUILD_TARGET}
|
||||
PRIVATE "USDVIEW_USE_NATIVEFILEDIALOG")
|
||||
list(APPEND EXT_LIBRARIES nfd)
|
||||
endif()
|
||||
|
||||
if (USDVIEW_ENABLE_PHYSICS)
|
||||
if(USDVIEW_ENABLE_PHYSICS)
|
||||
target_compile_definitions(${BUILD_TARGET} PRIVATE "USDVIEW_USE_BULLET3")
|
||||
target_include_directories(${BUILD_TARGET} PRIVATE "${PROJECT_SOURCE_DIR}/../common/bullet3/src")
|
||||
list(APPEND EXT_LIBRARIES BulletDynamics BulletCollision Bullet3Common LinearMath)
|
||||
target_include_directories(
|
||||
${BUILD_TARGET} PRIVATE "${PROJECT_SOURCE_DIR}/../common/bullet3/src")
|
||||
list(APPEND EXT_LIBRARIES BulletDynamics BulletCollision Bullet3Common
|
||||
LinearMath)
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
# nothing.
|
||||
# nothing.
|
||||
elseif(APPLE)
|
||||
list(APPEND EXT_LIBRARIES ${COCOA})
|
||||
list(APPEND EXT_LIBRARIES ${COCOA})
|
||||
else()
|
||||
list(APPEND EXT_LIBRARIES ${X11_LIBRARIES})
|
||||
list(APPEND EXT_LIBRARIES ${X11_LIBRARIES})
|
||||
endif()
|
||||
|
||||
target_link_libraries(
|
||||
${BUILD_TARGET}
|
||||
PRIVATE
|
||||
${USDVIEW_SDL2_LIBRARIES}
|
||||
${EXT_LIBRARIES}
|
||||
${CMAKE_DL_LIBS}
|
||||
)
|
||||
target_link_libraries(${BUILD_TARGET} PRIVATE ${USDVIEW_SDL2_LIBRARIES}
|
||||
${EXT_LIBRARIES} ${CMAKE_DL_LIBS})
|
||||
|
||||
if (EMSCRIPTEN)
|
||||
add_custom_command(TARGET ${BUILD_TARGET} PRE_BUILD # Adds a post-build event to MyTest
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different # which executes "cmake - E copy_if_different..."
|
||||
"${PROJECT_SOURCE_DIR}/../../models/suzanne.usdc" # src
|
||||
$<TARGET_FILE_DIR:${BUILD_TARGET}>) # dest
|
||||
if(EMSCRIPTEN)
|
||||
add_custom_command(
|
||||
TARGET ${BUILD_TARGET}
|
||||
PRE_BUILD # Adds a post-build event to MyTest
|
||||
COMMAND
|
||||
${CMAKE_COMMAND} -E
|
||||
copy_if_different # which executes "cmake - E copy_if_different..."
|
||||
"${PROJECT_SOURCE_DIR}/../../models/suzanne.usdc" # src
|
||||
$<TARGET_FILE_DIR:${BUILD_TARGET}>) # dest
|
||||
endif()
|
||||
|
||||
|
||||
|
||||
source_group("Source Files" FILES ${SOURCES})
|
||||
|
||||
# [VisualStudio]
|
||||
@@ -325,9 +382,8 @@ if(WIN32)
|
||||
# For easier debugging in VS IDE(cmake 3.8.0 or later required) Set working
|
||||
# directory to ${LIDIA_BUILD_TARGET} git repo root.
|
||||
if(CMAKE_VERSION VERSION_GREATER 3.8.0)
|
||||
set_target_properties(${BUILD_TARGET}
|
||||
PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
set_target_properties(
|
||||
${BUILD_TARGET} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
||||
@@ -34,10 +34,10 @@
|
||||
#include "roboto_mono_embed.inc.h"
|
||||
|
||||
//
|
||||
#include "gui.hh"
|
||||
#include "simple-render.hh"
|
||||
#include "tinyusdz.hh"
|
||||
#include "trackball.h"
|
||||
#include "gui.hh"
|
||||
|
||||
#if defined(USDVIEW_USE_NATIVEFILEDIALOG)
|
||||
#include "nfd.h"
|
||||
@@ -64,7 +64,6 @@ struct GUIContext {
|
||||
};
|
||||
int aov_mode{AOV_COLOR};
|
||||
|
||||
|
||||
example::AOV aov; // framebuffer
|
||||
|
||||
int width = 1024;
|
||||
@@ -110,7 +109,8 @@ struct GUIContext {
|
||||
#if __EMSCRIPTEN__ || defined(EMULATE_EMSCRIPTEN)
|
||||
bool render_finished{false};
|
||||
int current_render_line = 0;
|
||||
int render_line_size = 32; // render images with this lines per animation loop.
|
||||
int render_line_size =
|
||||
32; // render images with this lines per animation loop.
|
||||
// for emscripten environment
|
||||
#endif
|
||||
};
|
||||
@@ -338,7 +338,6 @@ bool LoadModel(const std::string& filename, tinyusdz::Scene* scene) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void RenderThread(GUIContext* ctx) {
|
||||
bool done = false;
|
||||
|
||||
@@ -348,7 +347,7 @@ void RenderThread(GUIContext* ctx) {
|
||||
}
|
||||
|
||||
if (ctx->request_reload) {
|
||||
ctx->scene = tinyusdz::Scene(); // reset
|
||||
ctx->scene = tinyusdz::Scene(); // reset
|
||||
|
||||
if (LoadModel(ctx->filename, &ctx->scene)) {
|
||||
Proc(ctx->scene);
|
||||
@@ -430,7 +429,6 @@ static void HelpMarker(const char* desc) {
|
||||
#if defined(__EMSCRIPTEN__) || defined(EMULATE_EMSCRIPTEN)
|
||||
|
||||
EM_BOOL em_main_loop_frame(double tm, void* user) {
|
||||
|
||||
#if 1
|
||||
// Render image fragment
|
||||
if (g_gui_ctx.redraw) {
|
||||
@@ -442,7 +440,9 @@ EM_BOOL em_main_loop_frame(double tm, void* user) {
|
||||
|
||||
if (!g_gui_ctx.render_finished) {
|
||||
std::cout << "RenderLines: " << g_gui_ctx.current_render_line << "\n";
|
||||
RenderLines(g_gui_ctx.current_render_line, g_gui_ctx.current_render_line + g_gui_ctx.render_line_size, g_gui_ctx.render_scene, g_gui_ctx.camera, &g_gui_ctx.aov);
|
||||
RenderLines(g_gui_ctx.current_render_line,
|
||||
g_gui_ctx.current_render_line + g_gui_ctx.render_line_size,
|
||||
g_gui_ctx.render_scene, g_gui_ctx.camera, &g_gui_ctx.aov);
|
||||
|
||||
g_gui_ctx.current_render_line += g_gui_ctx.render_line_size;
|
||||
if (g_gui_ctx.current_render_line >= g_gui_ctx.render_height) {
|
||||
@@ -506,38 +506,38 @@ EM_BOOL em_main_loop_frame(double tm, void* user) {
|
||||
bool update_display = false;
|
||||
ImGui::Begin("Scene");
|
||||
|
||||
update |=
|
||||
ImGui::SliderFloat("eye.z", &g_gui_ctx.camera.eye[2], -1000.0, 1000.0f);
|
||||
update |= ImGui::SliderFloat("fov", &g_gui_ctx.camera.fov, 0.01f, 140.0f);
|
||||
update |=
|
||||
ImGui::SliderFloat("eye.z", &g_gui_ctx.camera.eye[2], -1000.0, 1000.0f);
|
||||
update |= ImGui::SliderFloat("fov", &g_gui_ctx.camera.fov, 0.01f, 140.0f);
|
||||
|
||||
// TODO: Validate coordinate definition.
|
||||
if (ImGui::SliderFloat("yaw", &g_gui_ctx.yaw, -360.0f, 360.0f)) {
|
||||
auto q = ToQuaternion(radians(g_gui_ctx.yaw), radians(g_gui_ctx.pitch),
|
||||
radians(g_gui_ctx.roll));
|
||||
g_gui_ctx.camera.quat[0] = q[0];
|
||||
g_gui_ctx.camera.quat[1] = q[1];
|
||||
g_gui_ctx.camera.quat[2] = q[2];
|
||||
g_gui_ctx.camera.quat[3] = q[3];
|
||||
update = true;
|
||||
}
|
||||
if (ImGui::SliderFloat("pitch", &g_gui_ctx.pitch, -360.0f, 360.0f)) {
|
||||
auto q = ToQuaternion(radians(g_gui_ctx.yaw), radians(g_gui_ctx.pitch),
|
||||
radians(g_gui_ctx.roll));
|
||||
g_gui_ctx.camera.quat[0] = q[0];
|
||||
g_gui_ctx.camera.quat[1] = q[1];
|
||||
g_gui_ctx.camera.quat[2] = q[2];
|
||||
g_gui_ctx.camera.quat[3] = q[3];
|
||||
update = true;
|
||||
}
|
||||
if (ImGui::SliderFloat("roll", &g_gui_ctx.roll, -360.0f, 360.0f)) {
|
||||
auto q = ToQuaternion(radians(g_gui_ctx.yaw), radians(g_gui_ctx.pitch),
|
||||
radians(g_gui_ctx.roll));
|
||||
g_gui_ctx.camera.quat[0] = q[0];
|
||||
g_gui_ctx.camera.quat[1] = q[1];
|
||||
g_gui_ctx.camera.quat[2] = q[2];
|
||||
g_gui_ctx.camera.quat[3] = q[3];
|
||||
update = true;
|
||||
}
|
||||
// TODO: Validate coordinate definition.
|
||||
if (ImGui::SliderFloat("yaw", &g_gui_ctx.yaw, -360.0f, 360.0f)) {
|
||||
auto q = ToQuaternion(radians(g_gui_ctx.yaw), radians(g_gui_ctx.pitch),
|
||||
radians(g_gui_ctx.roll));
|
||||
g_gui_ctx.camera.quat[0] = q[0];
|
||||
g_gui_ctx.camera.quat[1] = q[1];
|
||||
g_gui_ctx.camera.quat[2] = q[2];
|
||||
g_gui_ctx.camera.quat[3] = q[3];
|
||||
update = true;
|
||||
}
|
||||
if (ImGui::SliderFloat("pitch", &g_gui_ctx.pitch, -360.0f, 360.0f)) {
|
||||
auto q = ToQuaternion(radians(g_gui_ctx.yaw), radians(g_gui_ctx.pitch),
|
||||
radians(g_gui_ctx.roll));
|
||||
g_gui_ctx.camera.quat[0] = q[0];
|
||||
g_gui_ctx.camera.quat[1] = q[1];
|
||||
g_gui_ctx.camera.quat[2] = q[2];
|
||||
g_gui_ctx.camera.quat[3] = q[3];
|
||||
update = true;
|
||||
}
|
||||
if (ImGui::SliderFloat("roll", &g_gui_ctx.roll, -360.0f, 360.0f)) {
|
||||
auto q = ToQuaternion(radians(g_gui_ctx.yaw), radians(g_gui_ctx.pitch),
|
||||
radians(g_gui_ctx.roll));
|
||||
g_gui_ctx.camera.quat[0] = q[0];
|
||||
g_gui_ctx.camera.quat[1] = q[1];
|
||||
g_gui_ctx.camera.quat[2] = q[2];
|
||||
g_gui_ctx.camera.quat[3] = q[3];
|
||||
update = true;
|
||||
}
|
||||
|
||||
ImGui::End();
|
||||
|
||||
@@ -570,7 +570,6 @@ EM_BOOL em_main_loop_frame(double tm, void* user) {
|
||||
|
||||
SDL_RenderPresent(g_gui_ctx.renderer);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
return EM_TRUE;
|
||||
@@ -580,7 +579,7 @@ EM_BOOL em_main_loop_frame(double tm, void* user) {
|
||||
|
||||
void NodeTreeSubWindow(const tinyusdz::Node& node, uint32_t indent) {
|
||||
if (node.name.empty()) {
|
||||
// Do not traverse children of the node without name
|
||||
// Do not traverse children of the node without name
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -593,9 +592,7 @@ void NodeTreeSubWindow(const tinyusdz::Node& node, uint32_t indent) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void NodeTreeWindow(const tinyusdz::Scene& scene) {
|
||||
|
||||
ImGui::Begin("Node");
|
||||
|
||||
if (scene.nodes.size()) {
|
||||
@@ -607,20 +604,18 @@ void NodeTreeWindow(const tinyusdz::Scene& scene) {
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
|
||||
void ShaderParamWindow(const tinyusdz::Scene& scene) {
|
||||
ImGui::Begin("Shaders");
|
||||
|
||||
for (const auto& item : scene.shaders) {
|
||||
if (item.name.empty()) {
|
||||
continue;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ImGui::TreeNode(item.name.c_str())) {
|
||||
if (nonstd::get_if<tinyusdz::PreviewSurface>(&item.value)) {
|
||||
ImGui::Text("type:id UsdPreviewSurface");
|
||||
|
||||
|
||||
} else if (nonstd::get_if<tinyusdz::UVTexture>(&item.value)) {
|
||||
ImGui::Text("type:id UVTexture");
|
||||
} else if (nonstd::get_if<tinyusdz::PrimvarReader_float2>(&item.value)) {
|
||||
@@ -640,10 +635,9 @@ void MaterialsParamWindow(const tinyusdz::Scene& scene) {
|
||||
for (const auto& item : scene.materials) {
|
||||
if (!item.name.empty()) {
|
||||
if (ImGui::TreeNode(item.name.c_str())) {
|
||||
|
||||
int nrow = 1;
|
||||
|
||||
ImGui::BeginTable("props", /* columns*/2);
|
||||
ImGui::BeginTable("props", /* columns*/ 2);
|
||||
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableSetColumnIndex(0);
|
||||
@@ -661,8 +655,7 @@ void MaterialsParamWindow(const tinyusdz::Scene& scene) {
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
void UVTextureNode(int node_id, const tinyusdz::UVTexture &texture) {
|
||||
|
||||
void UVTextureNode(int node_id, const tinyusdz::UVTexture& texture) {
|
||||
constexpr int kMaxSlots = 100;
|
||||
constexpr int kOutputOffset = kMaxSlots / 2;
|
||||
|
||||
@@ -690,10 +683,9 @@ void UVTextureNode(int node_id, const tinyusdz::UVTexture &texture) {
|
||||
ImNodes::EndOutputAttribute();
|
||||
|
||||
ImNodes::EndNode();
|
||||
|
||||
}
|
||||
|
||||
void ShaderGraphWindow(const tinyusdz::Scene &scene) {
|
||||
void ShaderGraphWindow(const tinyusdz::Scene& scene) {
|
||||
ImGui::Begin("Shader graph");
|
||||
|
||||
ImNodes::BeginNodeEditor();
|
||||
@@ -704,9 +696,9 @@ void ShaderGraphWindow(const tinyusdz::Scene &scene) {
|
||||
ImGui::TextUnformatted("File");
|
||||
ImNodes::EndNodeTitleBar();
|
||||
|
||||
//ImNodes::BeginInputAttribute(2);
|
||||
//ImGui::Text("file");
|
||||
//ImNodes::EndInputAttribute();
|
||||
// ImNodes::BeginInputAttribute(2);
|
||||
// ImGui::Text("file");
|
||||
// ImNodes::EndInputAttribute();
|
||||
|
||||
ImNodes::BeginOutputAttribute(3);
|
||||
ImGui::Indent(40);
|
||||
@@ -729,9 +721,9 @@ void ShaderGraphWindow(const tinyusdz::Scene &scene) {
|
||||
} // namespace
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
|
||||
#if defined(USDVIEW_USE_BULLET3)
|
||||
btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration();
|
||||
btDefaultCollisionConfiguration* collisionConfiguration =
|
||||
new btDefaultCollisionConfiguration();
|
||||
#endif
|
||||
|
||||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0) {
|
||||
@@ -739,9 +731,9 @@ int main(int argc, char** argv) {
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
SDL_Window* window =
|
||||
SDL_CreateWindow("Simple USDZ viewer", SDL_WINDOWPOS_CENTERED,
|
||||
SDL_WINDOWPOS_CENTERED, 1600, 800, SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI) ;
|
||||
SDL_Window* window = SDL_CreateWindow(
|
||||
"Simple USDZ viewer", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
|
||||
1600, 800, SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI);
|
||||
if (!window) {
|
||||
std::cerr << "Failed to create SDL2 window. If you are running on Linux, "
|
||||
"probably X11 Display is not setup correctly. Check your "
|
||||
@@ -749,8 +741,8 @@ int main(int argc, char** argv) {
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
SDL_Renderer* renderer =
|
||||
SDL_CreateRenderer(window, -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED);
|
||||
SDL_Renderer* renderer = SDL_CreateRenderer(
|
||||
window, -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED);
|
||||
|
||||
if (!renderer) {
|
||||
std::cerr << "Failed to create SDL2 renderer. If you are running on "
|
||||
@@ -780,7 +772,7 @@ int main(int argc, char** argv) {
|
||||
|
||||
std::cout << "Loading file " << filename << "\n";
|
||||
|
||||
//tinyusdz::Scene scene;
|
||||
// tinyusdz::Scene scene;
|
||||
|
||||
bool init_with_empty = false;
|
||||
|
||||
@@ -832,7 +824,6 @@ int main(int argc, char** argv) {
|
||||
font_size, &roboto_config);
|
||||
}
|
||||
|
||||
|
||||
ImGui_ImplSDL2_InitForSDLRenderer(window, renderer);
|
||||
ImGui_ImplSDLRenderer_Init(renderer);
|
||||
|
||||
@@ -891,7 +882,7 @@ int main(int argc, char** argv) {
|
||||
std::cout << "enter loop\n";
|
||||
emscripten_request_animation_frame_loop(em_main_loop_frame, /* fps */ 0);
|
||||
|
||||
//render_thread.join();
|
||||
// render_thread.join();
|
||||
std::cout << "quit\n";
|
||||
#else
|
||||
|
||||
@@ -908,7 +899,7 @@ int main(int argc, char** argv) {
|
||||
// Enable drop file
|
||||
SDL_EventState(SDL_DROPFILE, SDL_ENABLE);
|
||||
|
||||
#if 0
|
||||
#if 0
|
||||
// Enable Docking;
|
||||
{
|
||||
ImGuiIO& io& io = ImGui::GetIO();
|
||||
@@ -916,7 +907,7 @@ int main(int argc, char** argv) {
|
||||
// Enable docking(available in imgui `docking` branch at the moment)
|
||||
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
while (!done) {
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
@@ -938,8 +929,6 @@ int main(int argc, char** argv) {
|
||||
g_gui_ctx.filename = fname;
|
||||
g_gui_ctx.request_reload = true;
|
||||
|
||||
|
||||
|
||||
SDL_free(filepath);
|
||||
|
||||
} else if (e.type == SDL_WINDOWEVENT) {
|
||||
@@ -1038,7 +1027,6 @@ int main(int argc, char** argv) {
|
||||
ImVec2(gui_ctx.render_width, gui_ctx.render_height));
|
||||
ImGui::End();
|
||||
|
||||
|
||||
NodeTreeWindow(gui_ctx.scene);
|
||||
MaterialsParamWindow(gui_ctx.scene);
|
||||
ShaderParamWindow(gui_ctx.scene);
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#include "trackball.h"
|
||||
|
||||
#define PAR_SHAPES_IMPLEMENTATION
|
||||
#include "par_shapes.h" // For meshing
|
||||
#include "par_shapes.h" // For meshing
|
||||
|
||||
const float kPI = 3.141592f;
|
||||
|
||||
@@ -21,18 +21,16 @@ typedef nanort::real3<float> float3;
|
||||
|
||||
namespace example {
|
||||
|
||||
struct DifferentialGeometry
|
||||
{
|
||||
float t; // hit t
|
||||
float bary_u, bary_v; // barycentric coordinate.
|
||||
uint32_t geom_id; // geom id(Currently GeomMesh only)
|
||||
float tex_u, tex_v; // texture u and v
|
||||
struct DifferentialGeometry {
|
||||
float t; // hit t
|
||||
float bary_u, bary_v; // barycentric coordinate.
|
||||
uint32_t geom_id; // geom id(Currently GeomMesh only)
|
||||
float tex_u, tex_v; // texture u and v
|
||||
|
||||
float3 shading_normal;
|
||||
float3 geometric_normal;
|
||||
};
|
||||
|
||||
|
||||
inline float3 Lerp3(float3 v0, float3 v1, float3 v2, float u, float v) {
|
||||
return (1.0f - u - v) * v0 + u * v1 + v * v2;
|
||||
}
|
||||
@@ -45,17 +43,18 @@ inline void CalcNormal(float3& N, float3 v0, float3 v1, float3 v2) {
|
||||
N = vnormalize(N);
|
||||
}
|
||||
|
||||
bool ConvertToRenderMesh(const tinyusdz::GeomSphere& sphere, DrawGeomMesh* dst) {
|
||||
|
||||
bool ConvertToRenderMesh(const tinyusdz::GeomSphere& sphere,
|
||||
DrawGeomMesh* dst) {
|
||||
// TODO: Write our own sphere -> polygon converter
|
||||
|
||||
|
||||
// TODO: Read subdivision parameter from somewhere.
|
||||
int slices = 16;
|
||||
int stacks = 8;
|
||||
|
||||
// icohedron subdivision does not generate UV coordinate, so use par_shapes_create_parametric_sphere for now
|
||||
par_shapes_mesh* par_mesh = par_shapes_create_parametric_sphere(slices, stacks);
|
||||
// icohedron subdivision does not generate UV coordinate, so use
|
||||
// par_shapes_create_parametric_sphere for now
|
||||
par_shapes_mesh* par_mesh =
|
||||
par_shapes_create_parametric_sphere(slices, stacks);
|
||||
|
||||
dst->vertices.resize(par_mesh->npoints * 3);
|
||||
|
||||
@@ -111,11 +110,9 @@ bool ConvertToRenderMesh(const tinyusdz::GeomSphere& sphere, DrawGeomMesh* dst)
|
||||
|
||||
par_shapes_free_mesh(par_mesh);
|
||||
|
||||
|
||||
dst->facevertex_indices = facevertex_indices;
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
bool ConvertToRenderMesh(const tinyusdz::GeomMesh& mesh, DrawGeomMesh* dst) {
|
||||
@@ -129,7 +126,8 @@ bool ConvertToRenderMesh(const tinyusdz::GeomMesh& mesh, DrawGeomMesh* dst) {
|
||||
}
|
||||
#endif
|
||||
dst->vertices.resize(mesh.points.size() * 3);
|
||||
memcpy(dst->vertices.data(), mesh.points.data(), dst->vertices.size() * sizeof(float));
|
||||
memcpy(dst->vertices.data(), mesh.points.data(),
|
||||
dst->vertices.size() * sizeof(float));
|
||||
std::cout << __func__ << ": mesh.points = " << mesh.points.size() * 3 << "\n";
|
||||
|
||||
std::vector<float> facevarying_normals;
|
||||
@@ -139,7 +137,8 @@ bool ConvertToRenderMesh(const tinyusdz::GeomMesh& mesh, DrawGeomMesh* dst) {
|
||||
|
||||
std::vector<float> facevarying_texcoords;
|
||||
if (!mesh.GetFacevaryingTexcoords(&facevarying_texcoords)) {
|
||||
std::cout << __func__ << ":Warn: failed to retrieve facevarying texcoords\n";
|
||||
std::cout << __func__
|
||||
<< ":Warn: failed to retrieve facevarying texcoords\n";
|
||||
}
|
||||
|
||||
std::cout << "# of facevarying normals = " << facevarying_normals.size() / 3
|
||||
@@ -270,7 +269,7 @@ bool ConvertToRenderMesh(const tinyusdz::GeomMesh& mesh, DrawGeomMesh* dst) {
|
||||
}
|
||||
}
|
||||
|
||||
#if 0 // TODO: Rewrite
|
||||
#if 0 // TODO: Rewrite
|
||||
// Other facevarying attributes(property, primvars)
|
||||
dst->float_primvars.clear();
|
||||
dst->float_primvars_map.clear();
|
||||
@@ -325,13 +324,13 @@ bool ConvertToRenderMesh(const tinyusdz::GeomMesh& mesh, DrawGeomMesh* dst) {
|
||||
#endif
|
||||
|
||||
std::cout << "num points = " << dst->vertices.size() / 3 << "\n";
|
||||
std::cout << "num triangulated faces = "
|
||||
<< dst->facevertex_indices.size() / 3 << "\n";
|
||||
std::cout << "num triangulated faces = " << dst->facevertex_indices.size() / 3
|
||||
<< "\n";
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
float3 Shade(const DrawGeomMesh& mesh, DifferentialGeometry &dg) {
|
||||
float3 Shade(const DrawGeomMesh& mesh, DifferentialGeometry& dg) {
|
||||
// TODO
|
||||
|
||||
float3 color;
|
||||
@@ -486,9 +485,7 @@ bool Render(const RenderScene& scene, const Camera& cam, AOV* output) {
|
||||
output->rgb[3 * pixel_idx + 1] = 0.0f;
|
||||
output->rgb[3 * pixel_idx + 2] = 0.0f;
|
||||
|
||||
|
||||
if (scene.draw_meshes.size()) {
|
||||
|
||||
// FIXME(syoyo): Use NanoSG to trace meshes in the scene.
|
||||
const DrawGeomMesh& mesh = scene.draw_meshes[0];
|
||||
|
||||
@@ -579,7 +576,7 @@ bool Render(const RenderScene& scene, const Camera& cam, AOV* output) {
|
||||
dg.tex_v = texcoord[1];
|
||||
dg.bary_u = isect.u;
|
||||
dg.bary_v = isect.v;
|
||||
dg.geom_id = 0; // FIXME
|
||||
dg.geom_id = 0; // FIXME
|
||||
dg.geometric_normal = Ng;
|
||||
dg.shading_normal = Ns;
|
||||
|
||||
@@ -602,8 +599,6 @@ bool Render(const RenderScene& scene, const Camera& cam, AOV* output) {
|
||||
}
|
||||
|
||||
if (!hit) {
|
||||
|
||||
|
||||
output->geometric_normal[3 * pixel_idx + 0] = 0.0f;
|
||||
output->geometric_normal[3 * pixel_idx + 1] = 0.0f;
|
||||
output->geometric_normal[3 * pixel_idx + 2] = 0.0f;
|
||||
|
||||
@@ -2,10 +2,9 @@
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
#include "tinyusdz.hh"
|
||||
|
||||
#include "nanort.h"
|
||||
#include "nanosg.h"
|
||||
#include "tinyusdz.hh"
|
||||
|
||||
namespace example {
|
||||
|
||||
@@ -15,10 +14,10 @@ struct AOV {
|
||||
size_t width;
|
||||
size_t height;
|
||||
|
||||
std::vector<float> rgb; // 3 x width x height
|
||||
std::vector<float> shading_normal; // 3 x width x height
|
||||
std::vector<float> geometric_normal; // 3 x width x height
|
||||
std::vector<float> texcoords; // 2 x width x height
|
||||
std::vector<float> rgb; // 3 x width x height
|
||||
std::vector<float> shading_normal; // 3 x width x height
|
||||
std::vector<float> geometric_normal; // 3 x width x height
|
||||
std::vector<float> texcoords; // 2 x width x height
|
||||
|
||||
void Resize(size_t w, size_t h) {
|
||||
width = w;
|
||||
@@ -36,22 +35,19 @@ struct AOV {
|
||||
texcoords.resize(width * height * 2);
|
||||
memset(texcoords.data(), 0, sizeof(float) * texcoords.size());
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
struct Camera
|
||||
{
|
||||
struct Camera {
|
||||
float eye[3] = {0.0f, 0.0f, 25.0f};
|
||||
float up[3] = {0.0f, 1.0f, 0.0f};
|
||||
float look_at[3] = {0.0f, 0.0f, 0.0f};
|
||||
float quat[4] = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||
float fov = 60.0f; // in degree
|
||||
float fov = 60.0f; // in degree
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct Buffer
|
||||
{
|
||||
size_t num_coords{1}; // e.g. 3 for vec3 type.
|
||||
template <typename T>
|
||||
struct Buffer {
|
||||
size_t num_coords{1}; // e.g. 3 for vec3 type.
|
||||
std::vector<T> data;
|
||||
};
|
||||
|
||||
@@ -59,10 +55,9 @@ struct Buffer
|
||||
// Renderable Node class for NanoSG. Includes xform
|
||||
//
|
||||
struct DrawNode {
|
||||
|
||||
std::array<float, 3> translation{0.0f, 0.0f, 0.0f};
|
||||
std::array<float, 3> rotation{0.0f, 0.0f, 0.0f}; // euler rotation
|
||||
std::array<float, 3> scale{1.0f, 1.0f, 1.0f};
|
||||
std::array<float, 3> translation{0.0f, 0.0f, 0.0f};
|
||||
std::array<float, 3> rotation{0.0f, 0.0f, 0.0f}; // euler rotation
|
||||
std::array<float, 3> scale{1.0f, 1.0f, 1.0f};
|
||||
};
|
||||
|
||||
//
|
||||
@@ -70,7 +65,6 @@ struct DrawNode {
|
||||
// Mesh data is converted to triangle meshes.
|
||||
//
|
||||
struct DrawGeomMesh {
|
||||
|
||||
DrawGeomMesh(const tinyusdz::GeomMesh *p) : ref_mesh(p) {}
|
||||
|
||||
// Pointer to Reference GeomMesh.
|
||||
@@ -80,34 +74,35 @@ struct DrawGeomMesh {
|
||||
/// Required accessor API for NanoSG
|
||||
///
|
||||
const float *GetVertices() const {
|
||||
return reinterpret_cast<const float*>(ref_mesh->points.data());
|
||||
return reinterpret_cast<const float *>(ref_mesh->points.data());
|
||||
}
|
||||
|
||||
size_t GetVertexStrideBytes() const {
|
||||
return sizeof(float) * 3;
|
||||
}
|
||||
size_t GetVertexStrideBytes() const { return sizeof(float) * 3; }
|
||||
|
||||
std::vector<float> vertices; // vec3f
|
||||
std::vector<uint32_t> facevertex_indices; // triangulated indices. 3 x num_faces
|
||||
std::vector<float> facevarying_normals; // 3 x 3 x num_faces
|
||||
std::vector<float> facevarying_texcoords; // 2 x 3 x num_faces
|
||||
std::vector<uint32_t>
|
||||
facevertex_indices; // triangulated indices. 3 x num_faces
|
||||
std::vector<float> facevarying_normals; // 3 x 3 x num_faces
|
||||
std::vector<float> facevarying_texcoords; // 2 x 3 x num_faces
|
||||
|
||||
// arbitrary primvars(including texcoords(float2))
|
||||
std::vector<Buffer<float>> float_primvars;
|
||||
std::map<std::string, size_t> float_primvars_map; // <name, index to `float_primvars`>
|
||||
std::map<std::string, size_t>
|
||||
float_primvars_map; // <name, index to `float_primvars`>
|
||||
|
||||
// arbitrary primvars in int type(e.g. texcoord indices(int3))
|
||||
std::vector<Buffer<int32_t>> int_primvars;
|
||||
std::map<std::string, size_t> int_primvars_map; // <name, index to `int_primvars`>
|
||||
std::map<std::string, size_t>
|
||||
int_primvars_map; // <name, index to `int_primvars`>
|
||||
|
||||
int material_id{-1}; // per-geom material. index to `RenderScene::materials`
|
||||
int material_id{-1}; // per-geom material. index to `RenderScene::materials`
|
||||
|
||||
nanort::BVHAccel<float> accel;
|
||||
};
|
||||
|
||||
struct UVReader {
|
||||
int32_t st_id{-1}; // index to DrawGeomMesh::float_primvars
|
||||
int32_t indices_id{-1}; // index to DrawGeomMesh::int_primvars
|
||||
int32_t st_id{-1}; // index to DrawGeomMesh::float_primvars
|
||||
int32_t indices_id{-1}; // index to DrawGeomMesh::int_primvars
|
||||
|
||||
// Fetch interpolated UV coordinate
|
||||
std::array<float, 2> fetch_uv(size_t face_id, float varyu, float varyv);
|
||||
@@ -122,18 +117,19 @@ struct Texture {
|
||||
TEXTURE_CHANNEL_RGBA,
|
||||
};
|
||||
|
||||
UVReader uv_reader;
|
||||
UVReader uv_reader;
|
||||
int32_t image_id{-1};
|
||||
|
||||
// NOTE: for single channel(e.g. R), [0] will be filled for the return value.
|
||||
std::array<float, 4> fetch(size_t face_id, float varyu, float varyv, Channel channel);
|
||||
|
||||
std::array<float, 4> fetch(size_t face_id, float varyu, float varyv,
|
||||
Channel channel);
|
||||
};
|
||||
|
||||
// https://graphics.pixar.com/usd/release/spec_usdpreviewsurface.html#texture-reader
|
||||
// https://learn.foundry.com/modo/901/content/help/pages/uving/udim_workflow.html
|
||||
// Up to 10 tiles for U direction.
|
||||
// Not sure there is an limitation for V direction. Anyway maximum tile id is 9999.
|
||||
// Not sure there is an limitation for V direction. Anyway maximum tile id is
|
||||
// 9999.
|
||||
|
||||
#if 0
|
||||
static uint32_t GetUDIMTileId(uint32_t u, uint32_t v)
|
||||
@@ -144,35 +140,31 @@ static uint32_t GetUDIMTileId(uint32_t u, uint32_t v)
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
struct UDIMTexture {
|
||||
UVReader uv_reader;
|
||||
std::unordered_map<uint32_t, int32_t> images; // key: udim tile_id, value: image_id
|
||||
std::unordered_map<uint32_t, int32_t>
|
||||
images; // key: udim tile_id, value: image_id
|
||||
|
||||
|
||||
// NOTE: for single channel(e.g. R), [0] will be filled for the return value.
|
||||
std::array<float, 4> fetch(size_t face_id, float varyu, float varyv, Texture::Channel channel);
|
||||
std::array<float, 4> fetch(size_t face_id, float varyu, float varyv,
|
||||
Texture::Channel channel);
|
||||
};
|
||||
|
||||
// base color(fallback color) or Texture
|
||||
template<typename T>
|
||||
template <typename T>
|
||||
struct ShaderParam {
|
||||
ShaderParam(const T& t) {
|
||||
value = t;
|
||||
}
|
||||
ShaderParam(const T &t) { value = t; }
|
||||
|
||||
T value;
|
||||
int32_t texture_id{-1};
|
||||
|
||||
};
|
||||
|
||||
// UsdPreviewSurface
|
||||
// UsdPreviewSurface
|
||||
struct PreviewSurfaceShader {
|
||||
|
||||
bool useSpecularWorkFlow{false};
|
||||
|
||||
ShaderParam<vec3> diffuseColor{{0.18f, 0.18f, 0.18f}};
|
||||
ShaderParam<float> metallic{0.0f};
|
||||
ShaderParam<float> metallic{0.0f};
|
||||
ShaderParam<float> roughness{0.5f};
|
||||
ShaderParam<float> clearcoat{0.0f};
|
||||
ShaderParam<float> clearcoatRoughness{0.01f};
|
||||
@@ -182,7 +174,6 @@ struct PreviewSurfaceShader {
|
||||
ShaderParam<vec3> normal{{0.0f, 0.0f, 1.0f}};
|
||||
ShaderParam<float> displacement{0.0f};
|
||||
ShaderParam<float> occlusion{0.0f};
|
||||
|
||||
};
|
||||
|
||||
struct Material {
|
||||
@@ -194,7 +185,7 @@ struct Image {
|
||||
std::vector<uint8_t> image;
|
||||
int32_t width{-1};
|
||||
int32_t height{-1};
|
||||
int32_t channels{-1}; // e.g. 3 for RGB.
|
||||
int32_t channels{-1}; // e.g. 3 for RGB.
|
||||
};
|
||||
|
||||
class RenderScene {
|
||||
@@ -211,19 +202,11 @@ class RenderScene {
|
||||
bool Setup();
|
||||
};
|
||||
|
||||
|
||||
bool Render(
|
||||
const RenderScene &scene,
|
||||
const Camera &cam,
|
||||
AOV *output);
|
||||
bool Render(const RenderScene &scene, const Camera &cam, AOV *output);
|
||||
|
||||
// Render images for lines [start_y, end_y]
|
||||
// single-threaded. for webassembly.
|
||||
bool RenderLines(
|
||||
int start_y,
|
||||
int end_y,
|
||||
const RenderScene &scene,
|
||||
const Camera &cam,
|
||||
AOV *output);
|
||||
bool RenderLines(int start_y, int end_y, const RenderScene &scene,
|
||||
const Camera &cam, AOV *output);
|
||||
|
||||
} // namespace example
|
||||
} // namespace example
|
||||
|
||||
Reference in New Issue
Block a user