From b0523414ba6fa17d92592790d937abbe83ced68a Mon Sep 17 00:00:00 2001 From: Syoyo Fujita Date: Sun, 12 May 2024 06:51:06 +0900 Subject: [PATCH] [Tydra] [RenderScene] Fix node's xform is not setup correctly --- models/translated-cube-001.usda | 26 +++++++++++++++++++++++++ src/tydra/render-data.cc | 34 ++++++++++++++++++++++++++++----- 2 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 models/translated-cube-001.usda diff --git a/models/translated-cube-001.usda b/models/translated-cube-001.usda new file mode 100644 index 00000000..9863b398 --- /dev/null +++ b/models/translated-cube-001.usda @@ -0,0 +1,26 @@ +#usda 1.0 +( + doc = "Blender v3.1.0" + metersPerUnit = 1 + upAxis = "Z" +) + +def Xform "Cube" +{ + matrix4d xformOp:transform = ( (2, 0, 0, 0), (0, 3, 0, 0), (0, 0, 4, 0), (-1.1853550672531128, 0, 1.9550952911376953, 1) ) + uniform token[] xformOpOrder = ["xformOp:transform"] + + def Mesh "Cube" + { + matrix4d xformOp:transform = ( (1, 0, 0, 0), (0, 1, 0, 0), (0, 0, 1, 0), (100, 200, 300, 1) ) + uniform token[] xformOpOrder = ["xformOp:transform"] + + 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)] + uniform token subdivisionScheme = "none" + } +} diff --git a/src/tydra/render-data.cc b/src/tydra/render-data.cc index 707ea36d..c4df3f75 100644 --- a/src/tydra/render-data.cc +++ b/src/tydra/render-data.cc @@ -5700,10 +5700,16 @@ bool RenderSceneConverter::BuildNodeHierarchyImpl( rnode.display_name = prim->metas().displayName.value_or(""); DCOUT("rnode.prim_name " << rnode.prim_name); + DCOUT("node.local_mat " << node.get_local_matrix()); + DCOUT("node.has_resetXform " << node.has_resetXformStack()); + DCOUT("prim.type_name " << prim->type_name()); + DCOUT("prim.type_id " << prim->type_id()); + DCOUT("xform " << value::TYPE_ID_GEOM_XFORM); if (prim->type_id() == value::TYPE_ID_GEOM_MESH) { // GeomMesh(GPrim) also has xform. rnode.local_matrix = node.get_local_matrix(); + rnode.global_matrix = node.get_world_matrix(); rnode.nodeType = NodeType::Mesh; rnode.has_resetXform = node.has_resetXformStack(); @@ -5714,22 +5720,31 @@ bool RenderSceneConverter::BuildNodeHierarchyImpl( } } else if (prim->type_id() == value::TYPE_ID_GEOM_CAMERA) { rnode.local_matrix = node.get_local_matrix(); + rnode.global_matrix = node.get_world_matrix(); rnode.nodeType = NodeType::Mesh; rnode.has_resetXform = node.has_resetXformStack(); rnode.nodeType = NodeType::Camera; rnode.id = -1; // TODO: Assign index to cameras - } else if (prim->prim_id() == value::TYPE_ID_GEOM_XFORM) { + } else if (prim->type_id() == value::TYPE_ID_GEOM_XFORM) { rnode.local_matrix = node.get_local_matrix(); rnode.global_matrix = node.get_world_matrix(); + DCOUT("rnode.local_matrix " << rnode.local_matrix); + rnode.global_matrix = node.get_world_matrix(); rnode.has_resetXform = node.has_resetXformStack(); rnode.nodeType = NodeType::Xform; - } else if (prim->prim_id() == value::TYPE_ID_SCOPE) { + } else if (prim->type_id() == value::TYPE_ID_SCOPE) { // NOTE: get_local_matrix() should return identity matrix. rnode.local_matrix = node.get_local_matrix(); rnode.global_matrix = node.get_world_matrix(); rnode.has_resetXform = node.has_resetXformStack(); rnode.nodeType = NodeType::Xform; - } else if (prim->prim_id() == value::TYPE_ID_MODEL) { + } else if (prim->type_id() == value::TYPE_ID_MODEL) { + rnode.local_matrix = node.get_local_matrix(); + rnode.global_matrix = node.get_world_matrix(); + rnode.has_resetXform = node.has_resetXformStack(); + rnode.nodeType = NodeType::Xform; + } else if ((prim->type_id() > value::TYPE_ID_MODEL_BEGIN) && (prim->type_id() < value::TYPE_ID_GEOM_END)) { + // Other Geom prims(e.g. GeomCube) rnode.local_matrix = node.get_local_matrix(); rnode.global_matrix = node.get_world_matrix(); rnode.has_resetXform = node.has_resetXformStack(); @@ -5738,9 +5753,9 @@ bool RenderSceneConverter::BuildNodeHierarchyImpl( rnode.local_matrix = node.get_local_matrix(); rnode.global_matrix = node.get_world_matrix(); rnode.has_resetXform = node.has_resetXformStack(); - if (prim->prim_id() == value::TYPE_ID_LUX_DISTANT) { + if (prim->type_id() == value::TYPE_ID_LUX_DISTANT) { rnode.nodeType = NodeType::DirectionalLight; - } else if (prim->prim_id() == value::TYPE_ID_LUX_SPHERE) { + } else if (prim->type_id() == value::TYPE_ID_LUX_SPHERE) { // treat sphereLight as pointLight rnode.nodeType = NodeType::PointLight; } else { @@ -5750,6 +5765,13 @@ bool RenderSceneConverter::BuildNodeHierarchyImpl( rnode.id = -1; // TODO: index to lights } else { // ignore other node types. + DCOUT("Unknown/Unsupported prim. " << prim->type_name()); + + // Setup as xform for now. + rnode.local_matrix = node.get_local_matrix(); + rnode.global_matrix = node.get_world_matrix(); + rnode.has_resetXform = node.has_resetXformStack(); + rnode.nodeType = NodeType::Xform; } } @@ -6601,6 +6623,8 @@ std::string DumpNode(const Node &node, uint32_t indent) { << quote(node.display_name) << "\n"; ss << pprint::Indent(indent + 1) << "local_matrix " << quote(tinyusdz::to_string(node.local_matrix)) << "\n"; + ss << pprint::Indent(indent + 1) << "global_matrix " + << quote(tinyusdz::to_string(node.global_matrix)) << "\n"; if (node.children.size()) { ss << pprint::Indent(indent + 1) << "children {\n";