Skip to content

Commit

Permalink
Cherrypick mesh node fix (assimp/assimp#5915) required for O3DE
Browse files Browse the repository at this point in the history
Signed-off-by: AMZN-Gene <[email protected]>
  • Loading branch information
AMZN-Gene committed Dec 7, 2024
1 parent f454e04 commit 25a304a
Showing 1 changed file with 64 additions and 55 deletions.
119 changes: 64 additions & 55 deletions package-system/assimp/usd_animations-on-top-of-v5.4.3.patch
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/code/AssetLib/USD/USDLoaderImplTinyusdz.cpp b/code/AssetLib/USD/USDLoaderImplTinyusdz.cpp
index 3e32917f9..a817afdbd 100644
index 3e32917f9..b4fd6a51b 100644
--- a/code/AssetLib/USD/USDLoaderImplTinyusdz.cpp
+++ b/code/AssetLib/USD/USDLoaderImplTinyusdz.cpp
@@ -58,6 +58,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Expand Down Expand Up @@ -95,10 +95,10 @@ index 3e32917f9..a817afdbd 100644
textures(render_scene, pScene, nameWExt);
textureImages(render_scene, pScene, nameWExt);
buffers(render_scene, pScene, nameWExt);
-
- std::map<size_t, tinyusdz::tydra::Node> meshNodes;
- setupNodes(render_scene, pScene, meshNodes, nameWExt);
+ setupNodes(render_scene, pScene, nameWExt);
+ pScene->mRootNode = nodesRecursive(nullptr, render_scene.nodes[0], render_scene.skeletons);

setupBlendShapes(render_scene, pScene, nameWExt);
}
Expand Down Expand Up @@ -127,6 +127,7 @@ index 3e32917f9..a817afdbd 100644
+ }
+
+ // 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;
Expand Down Expand Up @@ -295,55 +296,49 @@ index 3e32917f9..a817afdbd 100644
for (size_t j = 0; j < pScene->mMeshes[meshIdx]->mNumVertices; ++j) {
pScene->mMeshes[meshIdx]->mVertices[j].x = render_scene.meshes[meshIdx].points[j][0];
pScene->mMeshes[meshIdx]->mVertices[j].y = render_scene.meshes[meshIdx].points[j][1];
@@ -598,29 +800,29 @@ void USDImporterImplTinyusdz::buffers(
void USDImporterImplTinyusdz::setupNodes(
const tinyusdz::tydra::RenderScene &render_scene,
aiScene *pScene,
- std::map<size_t, tinyusdz::tydra::Node> &meshNodes,
const std::string &nameWExt) {
stringstream ss;
@@ -595,54 +797,25 @@ void USDImporterImplTinyusdz::buffers(
}
}

-void USDImporterImplTinyusdz::setupNodes(
- const tinyusdz::tydra::RenderScene &render_scene,
- aiScene *pScene,
- std::map<size_t, tinyusdz::tydra::Node> &meshNodes,
- const std::string &nameWExt) {
- stringstream ss;
-
- pScene->mRootNode = nodes(render_scene, meshNodes, nameWExt);
+ 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;
- pScene->mRootNode->mNumMeshes = pScene->mNumMeshes;
- pScene->mRootNode->mMeshes = new unsigned int[pScene->mRootNode->mNumMeshes];
- ss.str("");
- ss << "setupNodes(): pScene->mNumMeshes: " << pScene->mNumMeshes;
- if (pScene->mRootNode != nullptr) {
- ss << ", mRootNode->mNumMeshes: " << pScene->mRootNode->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;
}
- TINYUSDZLOGD(TAG, "%s", ss.str().c_str());
-
}

aiNode *USDImporterImplTinyusdz::nodes(
const tinyusdz::tydra::RenderScene &render_scene,
- for (unsigned int meshIdx = 0; meshIdx < pScene->mNumMeshes; meshIdx++) {
- pScene->mRootNode->mMeshes[meshIdx] = meshIdx;
- }
-
-}
-
-aiNode *USDImporterImplTinyusdz::nodes(
- const tinyusdz::tydra::RenderScene &render_scene,
- std::map<size_t, tinyusdz::tydra::Node> &meshNodes,
const std::string &nameWExt) {
const size_t numNodes{render_scene.nodes.size()};
(void) numNodes; // Ignore unused variable when -Werror enabled
@@ -628,7 +830,9 @@ aiNode *USDImporterImplTinyusdz::nodes(
ss.str("");
ss << "nodes(): model" << nameWExt << ", numNodes: " << numNodes;
TINYUSDZLOGD(TAG, "%s", ss.str().c_str());
- 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());
- return nodesRecursive(nullptr, render_scene.nodes[0], meshNodes);
+
+ aiNode *rootNode = nodesRecursive(nullptr, render_scene.nodes[0], render_scene.skeletons);
+ return rootNode;
}

-}
-
using Assimp::tinyusdzNodeTypeFor;
@@ -637,7 +841,7 @@ using tinyusdz::tydra::NodeType;
using Assimp::tinyUsdzMat4ToAiMat4;
using tinyusdz::tydra::NodeType;
aiNode *USDImporterImplTinyusdz::nodesRecursive(
aiNode *pNodeParent,
const tinyusdz::tydra::Node &node,
Expand All @@ -352,12 +347,24 @@ index 3e32917f9..a817afdbd 100644
stringstream ss;
aiNode *cNode = new aiNode();
cNode->mParent = pNodeParent;
@@ -651,21 +855,69 @@ aiNode *USDImporterImplTinyusdz::nodesRecursive(
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) <<
@@ -651,21 +824,69 @@ aiNode *USDImporterImplTinyusdz::nodesRecursive(
ss << " (parent " << cNode->mParent->mName.C_Str() << ")";
}
ss << " has " << node.children.size() << " children";
- if (node.id > -1) {
+ if (node.id != -1) {
+ if (node.nodeType == NodeType::Mesh) {
ss << "\n node mesh id: " << node.id << " (node type: " << tinyusdzNodeTypeFor(node.nodeType) << ")";
- meshNodes[node.id] = node;
}
Expand Down Expand Up @@ -431,7 +438,7 @@ index 3e32917f9..a817afdbd 100644
}

diff --git a/code/AssetLib/USD/USDLoaderImplTinyusdz.h b/code/AssetLib/USD/USDLoaderImplTinyusdz.h
index 69f8c125c..601ddc066 100644
index 69f8c125c..8d52cc383 100644
--- a/code/AssetLib/USD/USDLoaderImplTinyusdz.h
+++ b/code/AssetLib/USD/USDLoaderImplTinyusdz.h
@@ -65,6 +65,10 @@ public:
Expand All @@ -445,20 +452,22 @@ index 69f8c125c..601ddc066 100644
void meshes(
const tinyusdz::tydra::RenderScene &render_scene,
aiScene *pScene,
@@ -123,19 +127,20 @@ public:
void setupNodes(
const tinyusdz::tydra::RenderScene &render_scene,
@@ -120,22 +124,14 @@ public:
aiScene *pScene,
const std::string &nameWExt);

- void setupNodes(
- const tinyusdz::tydra::RenderScene &render_scene,
- aiScene *pScene,
- std::map<size_t, tinyusdz::tydra::Node> &meshNodes,
- const std::string &nameWExt
- );
+ const std::string &nameWExt);

aiNode *nodes(
const tinyusdz::tydra::RenderScene &render_scene,
-
- aiNode *nodes(
- const tinyusdz::tydra::RenderScene &render_scene,
- std::map<size_t, tinyusdz::tydra::Node> &meshNodes,
const std::string &nameWExt);
- const std::string &nameWExt);
-
aiNode *nodesRecursive(
aiNode *pNodeParent,
const tinyusdz::tydra::Node &node,
Expand Down

0 comments on commit 25a304a

Please sign in to comment.