USD updates: properly place meshes into nodes (instead of all meshes getting added to the rool node). Adding animation framerate. (#5915)

Signed-off-by: AMZN-Gene <genewalt@amazon.com>
This commit is contained in:
Gene Walters
2024-12-11 07:32:40 -08:00
committed by GitHub
parent f12e521986
commit 76d22e5fbe
2 changed files with 10 additions and 50 deletions

View File

@@ -219,8 +219,7 @@ void USDImporterImplTinyusdz::InternReadFile(
textures(render_scene, pScene, nameWExt);
textureImages(render_scene, pScene, nameWExt);
buffers(render_scene, pScene, nameWExt);
setupNodes(render_scene, pScene, nameWExt);
pScene->mRootNode = nodesRecursive(nullptr, render_scene.nodes[0], render_scene.skeletons);
setupBlendShapes(render_scene, pScene, nameWExt);
}
@@ -249,6 +248,7 @@ void USDImporterImplTinyusdz::animations(
}
// each channel affects a node (joint)
newAiAnimation->mTicksPerSecond = render_scene.meta.framesPerSecond;
newAiAnimation->mNumChannels = animation.channels_map.size();
newAiAnimation->mChannels = new aiNodeAnim *[newAiAnimation->mNumChannels];
int channelIndex = 0;
@@ -797,44 +797,6 @@ void USDImporterImplTinyusdz::buffers(
}
}
void USDImporterImplTinyusdz::setupNodes(
const tinyusdz::tydra::RenderScene &render_scene,
aiScene *pScene,
const std::string &nameWExt) {
stringstream ss;
pScene->mRootNode = nodes(render_scene, nameWExt);
if (pScene->mRootNode == nullptr) {
return;
}
pScene->mRootNode->mNumMeshes = pScene->mNumMeshes;
pScene->mRootNode->mMeshes = new unsigned int[pScene->mRootNode->mNumMeshes];
ss.str("");
ss << "setupNodes(): pScene->mNumMeshes: " << pScene->mNumMeshes;
ss << ", mRootNode->mNumMeshes: " << pScene->mRootNode->mNumMeshes;
TINYUSDZLOGD(TAG, "%s", ss.str().c_str());
for (unsigned int meshIdx = 0; meshIdx < pScene->mNumMeshes; meshIdx++) {
pScene->mRootNode->mMeshes[meshIdx] = meshIdx;
}
}
aiNode *USDImporterImplTinyusdz::nodes(
const tinyusdz::tydra::RenderScene &render_scene,
const std::string &nameWExt) {
const size_t numNodes{render_scene.nodes.size()};
(void) numNodes; // Ignore unused variable when -Werror enabled
stringstream ss;
ss.str("");
ss << "nodes(): model" << nameWExt << ", numNodes: " << numNodes;
TINYUSDZLOGD(TAG, "%s", ss.str().c_str());
aiNode *rootNode = nodesRecursive(nullptr, render_scene.nodes[0], render_scene.skeletons);
return rootNode;
}
using Assimp::tinyusdzNodeTypeFor;
using Assimp::tinyUsdzMat4ToAiMat4;
using tinyusdz::tydra::NodeType;
@@ -847,6 +809,13 @@ aiNode *USDImporterImplTinyusdz::nodesRecursive(
cNode->mParent = pNodeParent;
cNode->mName.Set(node.prim_name);
cNode->mTransformation = tinyUsdzMat4ToAiMat4(node.local_matrix.m);
if (node.nodeType == NodeType::Mesh) {
cNode->mNumMeshes = 1;
cNode->mMeshes = new unsigned int[cNode->mNumMeshes];
cNode->mMeshes[0] = node.id;
}
ss.str("");
ss << "nodesRecursive(): node " << cNode->mName.C_Str() <<
" type: |" << tinyusdzNodeTypeFor(node.nodeType) <<
@@ -855,7 +824,7 @@ aiNode *USDImporterImplTinyusdz::nodesRecursive(
ss << " (parent " << cNode->mParent->mName.C_Str() << ")";
}
ss << " has " << node.children.size() << " children";
if (node.id != -1) {
if (node.nodeType == NodeType::Mesh) {
ss << "\n node mesh id: " << node.id << " (node type: " << tinyusdzNodeTypeFor(node.nodeType) << ")";
}
TINYUSDZLOGD(TAG, "%s", ss.str().c_str());

View File

@@ -124,15 +124,6 @@ public:
aiScene *pScene,
const std::string &nameWExt);
void setupNodes(
const tinyusdz::tydra::RenderScene &render_scene,
aiScene *pScene,
const std::string &nameWExt);
aiNode *nodes(
const tinyusdz::tydra::RenderScene &render_scene,
const std::string &nameWExt);
aiNode *nodesRecursive(
aiNode *pNodeParent,
const tinyusdz::tydra::Node &node,