Skip to content

Commit 76d22e5

Browse files
authored
USD updates: properly place meshes into nodes (instead of all meshes getting added to the rool node). Adding animation framerate. (assimp#5915)
Signed-off-by: AMZN-Gene <[email protected]>
1 parent f12e521 commit 76d22e5

File tree

2 files changed

+10
-50
lines changed

2 files changed

+10
-50
lines changed

code/AssetLib/USD/USDLoaderImplTinyusdz.cpp

Lines changed: 10 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,7 @@ void USDImporterImplTinyusdz::InternReadFile(
219219
textures(render_scene, pScene, nameWExt);
220220
textureImages(render_scene, pScene, nameWExt);
221221
buffers(render_scene, pScene, nameWExt);
222-
223-
setupNodes(render_scene, pScene, nameWExt);
222+
pScene->mRootNode = nodesRecursive(nullptr, render_scene.nodes[0], render_scene.skeletons);
224223

225224
setupBlendShapes(render_scene, pScene, nameWExt);
226225
}
@@ -249,6 +248,7 @@ void USDImporterImplTinyusdz::animations(
249248
}
250249

251250
// each channel affects a node (joint)
251+
newAiAnimation->mTicksPerSecond = render_scene.meta.framesPerSecond;
252252
newAiAnimation->mNumChannels = animation.channels_map.size();
253253
newAiAnimation->mChannels = new aiNodeAnim *[newAiAnimation->mNumChannels];
254254
int channelIndex = 0;
@@ -797,44 +797,6 @@ void USDImporterImplTinyusdz::buffers(
797797
}
798798
}
799799

800-
void USDImporterImplTinyusdz::setupNodes(
801-
const tinyusdz::tydra::RenderScene &render_scene,
802-
aiScene *pScene,
803-
const std::string &nameWExt) {
804-
stringstream ss;
805-
806-
pScene->mRootNode = nodes(render_scene, nameWExt);
807-
if (pScene->mRootNode == nullptr) {
808-
return;
809-
}
810-
811-
pScene->mRootNode->mNumMeshes = pScene->mNumMeshes;
812-
pScene->mRootNode->mMeshes = new unsigned int[pScene->mRootNode->mNumMeshes];
813-
814-
ss.str("");
815-
ss << "setupNodes(): pScene->mNumMeshes: " << pScene->mNumMeshes;
816-
ss << ", mRootNode->mNumMeshes: " << pScene->mRootNode->mNumMeshes;
817-
TINYUSDZLOGD(TAG, "%s", ss.str().c_str());
818-
819-
for (unsigned int meshIdx = 0; meshIdx < pScene->mNumMeshes; meshIdx++) {
820-
pScene->mRootNode->mMeshes[meshIdx] = meshIdx;
821-
}
822-
}
823-
824-
aiNode *USDImporterImplTinyusdz::nodes(
825-
const tinyusdz::tydra::RenderScene &render_scene,
826-
const std::string &nameWExt) {
827-
const size_t numNodes{render_scene.nodes.size()};
828-
(void) numNodes; // Ignore unused variable when -Werror enabled
829-
stringstream ss;
830-
ss.str("");
831-
ss << "nodes(): model" << nameWExt << ", numNodes: " << numNodes;
832-
TINYUSDZLOGD(TAG, "%s", ss.str().c_str());
833-
834-
aiNode *rootNode = nodesRecursive(nullptr, render_scene.nodes[0], render_scene.skeletons);
835-
return rootNode;
836-
}
837-
838800
using Assimp::tinyusdzNodeTypeFor;
839801
using Assimp::tinyUsdzMat4ToAiMat4;
840802
using tinyusdz::tydra::NodeType;
@@ -847,6 +809,13 @@ aiNode *USDImporterImplTinyusdz::nodesRecursive(
847809
cNode->mParent = pNodeParent;
848810
cNode->mName.Set(node.prim_name);
849811
cNode->mTransformation = tinyUsdzMat4ToAiMat4(node.local_matrix.m);
812+
813+
if (node.nodeType == NodeType::Mesh) {
814+
cNode->mNumMeshes = 1;
815+
cNode->mMeshes = new unsigned int[cNode->mNumMeshes];
816+
cNode->mMeshes[0] = node.id;
817+
}
818+
850819
ss.str("");
851820
ss << "nodesRecursive(): node " << cNode->mName.C_Str() <<
852821
" type: |" << tinyusdzNodeTypeFor(node.nodeType) <<
@@ -855,7 +824,7 @@ aiNode *USDImporterImplTinyusdz::nodesRecursive(
855824
ss << " (parent " << cNode->mParent->mName.C_Str() << ")";
856825
}
857826
ss << " has " << node.children.size() << " children";
858-
if (node.id != -1) {
827+
if (node.nodeType == NodeType::Mesh) {
859828
ss << "\n node mesh id: " << node.id << " (node type: " << tinyusdzNodeTypeFor(node.nodeType) << ")";
860829
}
861830
TINYUSDZLOGD(TAG, "%s", ss.str().c_str());

code/AssetLib/USD/USDLoaderImplTinyusdz.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -124,15 +124,6 @@ class USDImporterImplTinyusdz {
124124
aiScene *pScene,
125125
const std::string &nameWExt);
126126

127-
void setupNodes(
128-
const tinyusdz::tydra::RenderScene &render_scene,
129-
aiScene *pScene,
130-
const std::string &nameWExt);
131-
132-
aiNode *nodes(
133-
const tinyusdz::tydra::RenderScene &render_scene,
134-
const std::string &nameWExt);
135-
136127
aiNode *nodesRecursive(
137128
aiNode *pNodeParent,
138129
const tinyusdz::tydra::Node &node,

0 commit comments

Comments
 (0)