mirror of
https://github.com/lighttransport/tinyusdz.git
synced 2026-01-18 01:11:17 +01:00
Fix sdlviewer build.
This commit is contained in:
@@ -282,6 +282,7 @@ list(
|
||||
../../src/crate-reader.cc
|
||||
../../src/crate-format.cc
|
||||
../../src/crate-pprint.cc
|
||||
../../src/audio-loader.cc
|
||||
../../src/ascii-parser.cc
|
||||
../../src/usdc-reader.cc
|
||||
../../src/usda-reader.cc
|
||||
@@ -290,7 +291,10 @@ list(
|
||||
../../src/value-types.cc
|
||||
../../src/value-pprint.cc
|
||||
../../src/usdObj.cc
|
||||
../../src/tydra/tiny-render-data.cc
|
||||
../../src/usdGeom.cc
|
||||
../../src/usdLux.cc
|
||||
../../src/usdShade.cc
|
||||
../../src/tydra/render-data.cc
|
||||
#../../src/integerCoding.cpp
|
||||
#../../src/pxrLZ4/lz4.cpp
|
||||
#../../src/lz4-compression.cc
|
||||
|
||||
@@ -102,7 +102,7 @@ struct GUIContext {
|
||||
int render_height = 512;
|
||||
|
||||
// scene reload
|
||||
tinyusdz::HighLevelScene scene;
|
||||
tinyusdz::Stage stage;
|
||||
std::atomic<bool> request_reload{false};
|
||||
std::string filename;
|
||||
|
||||
@@ -160,8 +160,8 @@ static void DrawNode(const tinyusdz::Scene& scene, const tinyusdz::Node& node) {
|
||||
}
|
||||
#endif
|
||||
|
||||
static void Proc(const tinyusdz::HighLevelScene& scene) {
|
||||
(void)scene;
|
||||
static void Proc(const tinyusdz::Stage& stage) {
|
||||
(void)stage;
|
||||
|
||||
//std::cout << "num geom_meshes = " << scene.geom_meshes.size() << "\n";
|
||||
//for (auto& mesh : scene.geom_meshes) {
|
||||
@@ -289,7 +289,7 @@ static void ScreenActivate(SDL_Window* window) {
|
||||
#endif
|
||||
}
|
||||
|
||||
bool LoadModel(const std::string& filename, tinyusdz::HighLevelScene* scene) {
|
||||
bool LoadModel(const std::string& filename, tinyusdz::Stage* stage) {
|
||||
std::string ext = str_tolower(GetFileExtension(filename));
|
||||
|
||||
std::string warn;
|
||||
@@ -297,7 +297,7 @@ bool LoadModel(const std::string& filename, tinyusdz::HighLevelScene* scene) {
|
||||
|
||||
if (ext.compare("usdz") == 0) {
|
||||
std::cout << "usdz\n";
|
||||
bool ret = tinyusdz::LoadUSDZFromFile(filename, scene, &warn, &err);
|
||||
bool ret = tinyusdz::LoadUSDZFromFile(filename, stage, &warn, &err);
|
||||
if (!warn.empty()) {
|
||||
std::cerr << "WARN : " << warn << "\n";
|
||||
}
|
||||
@@ -311,7 +311,7 @@ bool LoadModel(const std::string& filename, tinyusdz::HighLevelScene* scene) {
|
||||
}
|
||||
} else if (ext.compare("usda") == 0) {
|
||||
std::cout << "usda\n";
|
||||
bool ret = tinyusdz::LoadUSDAFromFile(filename, scene, &warn, &err);
|
||||
bool ret = tinyusdz::LoadUSDAFromFile(filename, stage, &warn, &err);
|
||||
if (!warn.empty()) {
|
||||
std::cerr << "WARN : " << warn << "\n";
|
||||
}
|
||||
@@ -324,7 +324,7 @@ bool LoadModel(const std::string& filename, tinyusdz::HighLevelScene* scene) {
|
||||
return false;
|
||||
}
|
||||
} else { // assume usdc
|
||||
bool ret = tinyusdz::LoadUSDCFromFile(filename, scene, &warn, &err);
|
||||
bool ret = tinyusdz::LoadUSDCFromFile(filename, stage, &warn, &err);
|
||||
if (!warn.empty()) {
|
||||
std::cerr << "WARN : " << warn << "\n";
|
||||
}
|
||||
@@ -350,10 +350,10 @@ void RenderThread(GUIContext* ctx) {
|
||||
}
|
||||
|
||||
if (ctx->request_reload) {
|
||||
ctx->scene = tinyusdz::HighLevelScene(); // reset
|
||||
ctx->stage = tinyusdz::Stage(); // reset
|
||||
|
||||
if (LoadModel(ctx->filename, &ctx->scene)) {
|
||||
Proc(ctx->scene);
|
||||
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";
|
||||
@@ -768,14 +768,14 @@ int main(int argc, char** argv) {
|
||||
|
||||
bool init_with_empty = false;
|
||||
|
||||
if (!LoadModel(filename, &g_gui_ctx.scene)) {
|
||||
if (!LoadModel(filename, &g_gui_ctx.stage)) {
|
||||
init_with_empty = true;
|
||||
}
|
||||
|
||||
if (!init_with_empty) {
|
||||
std::cout << "Loaded USDC file\n";
|
||||
|
||||
Proc(g_gui_ctx.scene);
|
||||
Proc(g_gui_ctx.stage);
|
||||
//if (g_gui_ctx.scene.geom_meshes.empty()) {
|
||||
// std::cerr << "The scene contains no GeomMesh\n";
|
||||
// exit(-1);
|
||||
|
||||
@@ -165,27 +165,27 @@ 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));
|
||||
std::cout << __func__ << ": mesh.points = " << mesh.points.size() * 3 << "\n";
|
||||
dst->vertices.size() * sizeof(tinyusdz::value::point3f));
|
||||
std::cout << __func__ << "# of mesh.points = " << mesh.points.size() << "\n";
|
||||
|
||||
std::vector<float> facevarying_normals;
|
||||
if (!mesh.GetFacevaryingNormals(&facevarying_normals)) {
|
||||
std::cout << __func__ << ":Warn: failed to retrieve facevarying normals\n";
|
||||
}
|
||||
//std::vector<float> facevarying_normals;
|
||||
//if (!mesh.GetFacevaryingNormals(&facevarying_normals)) {
|
||||
// std::cout << __func__ << ":Warn: failed to retrieve facevarying normals\n";
|
||||
//}
|
||||
|
||||
std::vector<float> facevarying_texcoords;
|
||||
if (!mesh.GetFacevaryingTexcoords(&facevarying_texcoords)) {
|
||||
std::cout << __func__
|
||||
<< ":Warn: failed to retrieve facevarying texcoords\n";
|
||||
}
|
||||
//std::vector<float> facevarying_texcoords;
|
||||
//if (!mesh.GetFacevaryingTexcoords(&facevarying_texcoords)) {
|
||||
// std::cout << __func__
|
||||
// << ":Warn: failed to retrieve facevarying texcoords\n";
|
||||
//}
|
||||
|
||||
std::cout << "# of facevarying normals = " << facevarying_normals.size() / 3
|
||||
<< "\n";
|
||||
//std::cout << "# of facevarying normals = " << facevarying_normals.size() / 3
|
||||
// << "\n";
|
||||
|
||||
std::cout << "# of faceVertexCounts: " << mesh.faceVertexCounts.size()
|
||||
<< "\n";
|
||||
std::cout << "# of faceVertexIndices: " << mesh.faceVertexIndices.size()
|
||||
<< "\n";
|
||||
//std::cout << "# of faceVertexCounts: " << mesh.faceVertexCounts.size()
|
||||
// << "\n";
|
||||
//std::cout << "# of faceVertexIndices: " << mesh.faceVertexIndices.size()
|
||||
// << "\n";
|
||||
|
||||
// for (size_t i = 0; i < facevarying_normals.size() / 3; i++) {
|
||||
// std::cout << "fid[" << i << "] = " << facevarying_normals[3 * i + 0] << ",
|
||||
@@ -214,6 +214,7 @@ bool ConvertToRenderMesh(const tinyusdz::GeomMesh& mesh, DrawGeomMesh* dst) {
|
||||
dst->facevertex_indices.push_back(
|
||||
mesh.faceVertexIndices[face_offset + f]);
|
||||
|
||||
#if 0
|
||||
if (facevarying_normals.size()) {
|
||||
// x, y, z
|
||||
dst->facevarying_normals.push_back(
|
||||
@@ -231,6 +232,7 @@ bool ConvertToRenderMesh(const tinyusdz::GeomMesh& mesh, DrawGeomMesh* dst) {
|
||||
dst->facevarying_texcoords.push_back(
|
||||
facevarying_texcoords[2 * (face_offset + f) + 1]);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
} else {
|
||||
@@ -249,6 +251,7 @@ bool ConvertToRenderMesh(const tinyusdz::GeomMesh& mesh, DrawGeomMesh* dst) {
|
||||
dst->facevertex_indices.push_back(
|
||||
mesh.faceVertexIndices[face_offset + f2]);
|
||||
|
||||
#if 0
|
||||
if (facevarying_normals.size()) {
|
||||
size_t fid0 = face_offset + f0;
|
||||
size_t fid1 = face_offset + f1;
|
||||
@@ -301,6 +304,7 @@ bool ConvertToRenderMesh(const tinyusdz::GeomMesh& mesh, DrawGeomMesh* dst) {
|
||||
dst->facevarying_texcoords.push_back(
|
||||
facevarying_texcoords[2 * fid2 + 1]);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
face_offset += f_count;
|
||||
|
||||
@@ -8,7 +8,11 @@
|
||||
|
||||
namespace example {
|
||||
|
||||
using vec3 = std::array<float, 3>;
|
||||
// GLES-like naming
|
||||
|
||||
using vec3 = tinyusdz::value::float3;
|
||||
using vec2 = tinyusdz::value::float2;
|
||||
using mat2 = tinyusdz::value::matrix2f;
|
||||
|
||||
struct AOV {
|
||||
size_t width;
|
||||
@@ -100,12 +104,19 @@ struct DrawGeomMesh {
|
||||
nanort::BVHAccel<float> accel;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct UVReader {
|
||||
|
||||
static_assert(std::is_same<T, float>::value || std::is_same<T, vec2>::value || std::is_same<T, vec3>::value,
|
||||
"Unsupported type for UVReader");
|
||||
|
||||
int32_t st_id{-1}; // index to DrawGeomMesh::float_primvars
|
||||
int32_t indices_id{-1}; // index to DrawGeomMesh::int_primvars
|
||||
|
||||
mat2 uv_transform;
|
||||
|
||||
// Fetch interpolated UV coordinate
|
||||
std::array<float, 2> fetch_uv(size_t face_id, float varyu, float varyv);
|
||||
T fetch_uv(size_t face_id, float varyu, float varyv);
|
||||
};
|
||||
|
||||
struct Texture {
|
||||
@@ -117,7 +128,7 @@ struct Texture {
|
||||
TEXTURE_CHANNEL_RGBA,
|
||||
};
|
||||
|
||||
UVReader uv_reader;
|
||||
UVReader<vec2> uv_reader;
|
||||
int32_t image_id{-1};
|
||||
|
||||
// NOTE: for single channel(e.g. R), [0] will be filled for the return value.
|
||||
@@ -141,7 +152,7 @@ static uint32_t GetUDIMTileId(uint32_t u, uint32_t v)
|
||||
#endif
|
||||
|
||||
struct UDIMTexture {
|
||||
UVReader uv_reader;
|
||||
UVReader<vec2> uv_reader;
|
||||
std::unordered_map<uint32_t, int32_t>
|
||||
images; // key: udim tile_id, value: image_id
|
||||
|
||||
|
||||
Reference in New Issue
Block a user