Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:syoyo/tinyusdz into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
syoyo committed Jul 6, 2024
2 parents f89a18e + 2bc89c5 commit ef23558
Show file tree
Hide file tree
Showing 18 changed files with 253 additions and 81 deletions.
19 changes: 19 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,25 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
PROPERTIES COMPILE_FLAGS ${TUSDZ_COMPILE_FLAGS})
endif()

# Increase warning level for gcc.
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU")

set(TUSDZ_COMPILE_FLAGS
"-Wall "
)

option(TINYUSDZ_NO_WERROR "Don't set -Werror when building the tinyusdz library" ${TINYUSDZ_DEFAULT_NO_WERROR})
if (NOT TINYUSDZ_NO_WERROR)
set(TUSDZ_COMPILE_FLAGS "${TUSDZ_COMPILE_FLAGS} -Werror")
endif()

set_source_files_properties(${TINYUSDZ_SOURCES}
PROPERTIES COMPILE_FLAGS ${TUSDZ_COMPILE_FLAGS})

if (TINYUSDZ_WITH_C_API)
set_source_files_properties(${TINYUSDZ_C_API_SOURCES}
PROPERTIES COMPILE_FLAGS ${TUSDZ_COMPILE_FLAGS})
endif()
endif()

if(TINYUSDZ_CUSTOM_COMPILE_FLAGS)
Expand Down
8 changes: 1 addition & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* [examples/openglviewer](examples/openglviewer) OpenGL viewer
* [examples/sdlviewer](examples/sdlviewer) Software raytracing viewer
* For Vulkan and Android Vulkan example, please refer https://github.com/syoyo/Vulkan-glTF-USDZ-PBR for a while
* For OpenGL + MaterialX example, please refer ASF MaterialXViewer fork to load USD model through TinyUSDZ https://github.com/lighttransport/materialx

## Mid-term todo

Expand Down Expand Up @@ -154,13 +155,6 @@ USD itself is a generic container of 3D scene data.
Tydra is an interface to Renderers/Viewers and other DCCs.
Tydra may be something like Tiny version of pxrUSD Hydra, but its API is completely different. See [src/tydra/README.md](src/tydra/README.md) for the background.

* Image color space
* sRGB
* Linear
* Rec.709
* [ ] Partial support of OCIO(OpenColor IO) through TinyColorIO https://github.com/syoyo/tinycolorio . Currently SPI3DLut only.
* More details are T.B.W.

## Notice

TinyUSDZ does not support Reality Composer file format(`.reality`) since it uses proprietary file format and we cannot understand it(so no conversion support from/to Reality also).
Expand Down
8 changes: 4 additions & 4 deletions doc/status.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ NOTE: USDC(Binary) = Read only
| ----------- | ----- | ---- | ------- |
| Xform ||| |
| Mesh ||| |
| GeomSubset | 🚧 | 🚧 | |
| GeomSubset | | | |
| Points ||| |
| Cube ||| |
| Cylinder ||| |
Expand Down Expand Up @@ -62,8 +62,8 @@ NOTE: USDC(Binary) = Read only
| type | Ascii | USDC | Comment |
| ----------- | ----- | ---- | ------- |
| UsdPreviewSurface ||| |
| UsdUVTexture | | | 1. |
| UsdPrimvarReader ||| 2. |
| UsdUVTexture | | | 1. |
| UsdPrimvarReader ||| |


1. UDIM texture is not supported.
Expand All @@ -90,7 +90,7 @@ NOTE: USDC(Binary) = Read only
* [ ] VariantSet(SpecTypeVariant) Crate write
* [ ] USDC serialization
* [ ] Skinning evaluation/validation
* [ ] Tydra(scene/render delegation)
* [x] Tydra(scene/render delegation)
* [ ] usdObj(wavefront .obj) support.
* Please see [usdObj.md](usdObj.md)
* [ ] C-API for other languages
Expand Down
4 changes: 4 additions & 0 deletions examples/sdlviewer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
This viewer uses NanoRT(SW ray tracer) to render the model and display it using SDL2
(So no OpenGL dependency)

## Status

W.I.P.

## Requirements

* C++14 compiler
Expand Down
58 changes: 32 additions & 26 deletions examples/sdlviewer/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
#include <emscripten/html5.h>
#endif

// To avoid some C define symbol conflict with SDL(e.g. 'Bool')
// tinyusdz headers muet be included before SDL
#include "tinyusdz.hh"
#include "tydra/render-data.hh"


// ../common/SDL2
#include <SDL.h>

Expand All @@ -33,6 +39,7 @@
#include "imnodes.h"
#include "roboto_mono_embed.inc.h"
#include "virtualGizmo3D/vGizmo.h"
#include "trackball.h"

//
#include "gui.hh"
Expand Down Expand Up @@ -91,7 +98,7 @@ struct GUIContext {
// std::array<float, 3> lookat = {0.0f, 0.0f, 0.0f};
// std::array<float, 3> up = {0.0f, 1.0f, 0.0f};

//example::RenderScene render_scene;
example::RTRenderScene rt_render_scene;

example::Camera camera;

Expand All @@ -104,8 +111,8 @@ struct GUIContext {
int render_width = 512;
int render_height = 512;

tinyusdz::Stage stage;
std::string filename;
//tinyusdz::Stage stage;
std::string usd_filename;

// RenderScene: Scene graph object which is suited for GL/Vulkan renderer.
// Constructed from `tinyusdz::Stage`
Expand Down Expand Up @@ -308,17 +315,20 @@ bool LoadModel(const std::string& filename, /* out */tinyusdz::Stage* stage) {
std::string warn;
std::string err;

bool ret = tinyusdz::LoadUSDFromFile(filename, stage, &warn, &err);
if (!warn.empty()) {
std::cerr << "WARN : " << warn << "\n";
if (!tinyusdz::IsUSD(filename)) {
std::cerr << "ERR: file not found or file is not USD format : " << filename << "\n";
return false;
}

if (!err.empty()) {
std::cerr << "ERR : " << err << "\n";
bool ret = tinyusdz::LoadUSDFromFile(filename, stage, &warn, &err);
if (warn.size()) {
std::cerr << "WARN : " << warn << "\n";
}

if (!ret) {
std::cerr << "Failed to load USD file: " << filename << "\n";
if (!err.empty()) {
std::cerr << "ERR : " << err << "\n";
}
return false;
}

Expand All @@ -334,11 +344,11 @@ void RenderThread(GUIContext* ctx) {
}

if (ctx->request_reload) {
ctx->stage = tinyusdz::Stage(); // reset
//ctx->stage = tinyusdz::Stage(); // reset

#if 0 // TODO
if (LoadModel(ctx->filename, &ctx->stage)) {
Proc(ctx->stage);
#if 0
if (ctx->scene.geom_meshes.empty()) {
std::cerr << "The scene contains no GeomMesh\n";
} else {
Expand All @@ -356,8 +366,8 @@ void RenderThread(GUIContext* ctx) {
}
std::cout << "Setup render mesh\n";
}
#endif
}
#endif

ctx->request_reload = false;

Expand All @@ -370,7 +380,7 @@ void RenderThread(GUIContext* ctx) {
continue;
}

//example::Render(ctx->render_scene, ctx->camera, &ctx->aov);
example::Render(ctx->rt_render_scene, ctx->camera, &ctx->aov);

ctx->update_texture = true;

Expand Down Expand Up @@ -746,14 +756,9 @@ int main(int argc, char** argv) {
filename = std::string(argv[1]);
}

std::cout << "Loading file " << filename << "\n";

bool init_with_empty = false;

if (!LoadModel(filename, &g_gui_ctx.stage)) {
init_with_empty = true;
}
g_gui_ctx.usd_filename = filename;

#if 0
if (!init_with_empty) {
std::cout << "Loaded USDC file\n";

Expand All @@ -763,6 +768,7 @@ int main(int argc, char** argv) {
// exit(-1);
//}
}
#endif

// Assume single monitor
SDL_DisplayMode DM;
Expand Down Expand Up @@ -818,17 +824,17 @@ int main(int argc, char** argv) {
GUIContext& gui_ctx = g_gui_ctx;
gui_ctx.renderer = renderer;

if (!init_with_empty) {
if (gui_ctx.usd_filename.size()) {
//for (size_t i = 0; i < g_gui_ctx.scene.geom_meshes.size(); i++) {
// example::DrawGeomMesh draw_mesh(&g_gui_ctx.scene.geom_meshes[i]);
// gui_ctx.render_scene.draw_meshes.push_back(draw_mesh);
//}

// Setup render mesh
//if (!gui_ctx.render_scene.Setup()) {
// std::cerr << "Failed to setup render mesh.\n";
// exit(-1);
//}
if (!gui_ctx.rt_render_scene.SetupFromUSDFile(gui_ctx.usd_filename)) {
std::cerr << "Failed to setup render mesh.\n";
exit(-1);
}
std::cout << "Setup render mesh\n";
}

Expand Down Expand Up @@ -973,7 +979,7 @@ int main(int argc, char** argv) {
std::string fname = filepath;

// Scene reloading is done in render thread.
g_gui_ctx.filename = fname;
g_gui_ctx.usd_filename = fname;
g_gui_ctx.request_reload = true;

SDL_free(filepath);
Expand Down
37 changes: 28 additions & 9 deletions examples/sdlviewer/simple-render.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
#include <cassert>
#include <thread>

// tinyusdz Tydra
// tinyusdz & Tydra
#include "io-util.hh"
#include "tydra/render-data.hh"

//
Expand Down Expand Up @@ -494,7 +495,7 @@ void BuildCameraFrame(float3* origin, float3* corner, float3* u, float3* v,
}
}

bool Render(const RenderScene& scene, const Camera& cam, AOV* output) {
bool Render(const RTRenderScene& scene, const Camera& cam, AOV* output) {
int width = output->width;
int height = output->height;

Expand Down Expand Up @@ -685,7 +686,7 @@ bool Render(const RenderScene& scene, const Camera& cam, AOV* output) {
return true;
}

bool RenderLines(int start_y, int end_y, const RenderScene& scene,
bool RenderLines(int start_y, int end_y, const RTRenderScene& scene,
const Camera& cam, AOV* output) {
int width = output->width;
int height = output->height;
Expand Down Expand Up @@ -840,14 +841,32 @@ bool RenderLines(int start_y, int end_y, const RenderScene& scene,
return true;
}

bool RenderScene::SetupFromUSDFile(const std::string &usd_filename) {
bool RTRenderScene::SetupFromUSDFile(const std::string &usd_filename) {

if (!tinyusdz::IsUSD(usd_filename)) {
std::cerr << "File not found or not a USD file: " << usd_filename << "\n";
return false;
}

std::string warn, err;
tinyusdz::Stage stage;
bool ret = tinyusdz::LoadUSDFromFile(usd_filename, &stage, &warn, &err);
if (warn.size()) {
std::cout << "WARN: " << warn << "\n";
}

if (!ret) {
std::cerr << "USD load error: " << err << "\n";
return false;
}

warn.clear();

// Convert USD Scene(Stage) to Vulkan-friendly scene data using TinyUSDZ Tydra
tinyusdz::tydra::RenderScene render_scene;
tinyusdz::tydra::RenderSceneConverter converter;
tinyusdz::tydra::RenderSceneConverterEnv env(stage);

std::string warn, err;

bool is_usdz = tinyusdz::IsUSDZ(usd_filename);

Expand All @@ -868,7 +887,7 @@ bool RenderScene::SetupFromUSDFile(const std::string &usd_filename) {
// Setup AssetResolutionResolver to read a asset(file) from memory.
if (!tinyusdz::ReadUSDZAssetInfoFromFile(usd_filename, &usdz_asset, &warn, &err )) {
std::cerr << "Failed to read USDZ assetInfo from file: " << err << "\n";
return;
return false;
}

if (warn.size()) {
Expand All @@ -880,7 +899,7 @@ bool RenderScene::SetupFromUSDFile(const std::string &usd_filename) {
// NOTE: Pointer address of usdz_asset must be valid until the call of RenderSce neConverter::ConvertToRenderScene.
if (!tinyusdz::SetupUSDZAssetResolution(arr, &usdz_asset)) {
std::cerr << "Failed to setup AssetResolution for USDZ asset\n";
return;
return false;
};

env.asset_resolver = arr;
Expand All @@ -890,10 +909,10 @@ bool RenderScene::SetupFromUSDFile(const std::string &usd_filename) {
}

env.timecode = tinyusdz::value::TimeCode::Default();
bool ret = converter.ConvertToRenderScene(env, &render_scene);
ret = converter.ConvertToRenderScene(env, &render_scene);
if (!ret) {
std::cerr << "Failed to convert USD Stage to RenderScene: \n" << converter.GetError() << "\n";
return;
return false;
}

if (converter.GetWarning().size()) {
Expand Down
11 changes: 6 additions & 5 deletions examples/sdlviewer/simple-render.hh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

#include "nanort.h"
#include "nanosg.h"
//
#include "tinyusdz.hh"
#include "tydra/render-data.hh"

namespace example {

Expand Down Expand Up @@ -201,7 +203,7 @@ struct Image {
int32_t channels{-1}; // e.g. 3 for RGB.
};

class RenderScene {
class RTRenderScene {
public:
std::vector<DrawGeomMesh> draw_meshes;
std::vector<Material> materials;
Expand All @@ -211,15 +213,14 @@ class RenderScene {
std::vector<nanosg::Node<float, DrawGeomMesh>> nodes;
nanosg::Scene<float, DrawGeomMesh> scene;

// Convert scene and build BVH
bool SetupFromStage(const tinyusdz::Stage &stage);
bool SetupFromUSDFile(const std::string &usd_filename);
};

bool Render(const RenderScene &scene, const Camera &cam, AOV *output);
bool Render(const RTRenderScene &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,
bool RenderLines(int start_y, int end_y, const RTRenderScene &scene,
const Camera &cam, AOV *output);

} // namespace example
2 changes: 1 addition & 1 deletion src/crate-reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2795,7 +2795,7 @@ bool CrateReader::UnpackValueRep(const crate::ValueRep &rep,

CHECK_MEMORY_USAGE(sizeof(double));

double v;
double v{0.0};
if (!_sr->read_double(&v)) {
PUSH_ERROR("Failed to read Double value.");
return false;
Expand Down
Loading

0 comments on commit ef23558

Please sign in to comment.