summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrey Lihatskiy <alihatskiy@productengine.com>2025-05-26 22:03:55 +0300
committerAndrey Lihatskiy <alihatskiy@productengine.com>2025-05-27 01:54:05 +0300
commit3f0aa3383a25d203dcdf35d0b7937cbcba3ea5e3 (patch)
tree2af683d2f2fc41ad25e2685097a943f94b037730
parentd9d800886d9694121c987654b72c40b972516aac (diff)
#4109 Improve LLGLTFLoader::computeCombinedNodeTransform()
-rw-r--r--indra/newview/gltf/llgltfloader.cpp39
1 files changed, 22 insertions, 17 deletions
diff --git a/indra/newview/gltf/llgltfloader.cpp b/indra/newview/gltf/llgltfloader.cpp
index 82666761df..5922385358 100644
--- a/indra/newview/gltf/llgltfloader.cpp
+++ b/indra/newview/gltf/llgltfloader.cpp
@@ -251,30 +251,35 @@ bool LLGLTFLoader::parseMeshes()
void LLGLTFLoader::computeCombinedNodeTransform(const LL::GLTF::Asset& asset, S32 node_index, glm::mat4& combined_transform)
{
- auto& node = asset.mNodes[node_index];
+ if (node_index < 0 || node_index >= static_cast<S32>(asset.mNodes.size()))
+ {
+ combined_transform = glm::mat4(1.0f);
+ return;
+ }
+
+ const auto& node = asset.mNodes[node_index];
+
+ // Ensure the node's matrix is valid
+ const_cast<LL::GLTF::Node&>(node).makeMatrixValid();
// Start with this node's transform
- glm::mat4 node_transform = node.mMatrix;
+ combined_transform = node.mMatrix;
- // Find parent node and apply its transform if it exists
- for (auto& other_node : asset.mNodes)
+ // Find and apply parent transform if it exists
+ for (size_t i = 0; i < asset.mNodes.size(); ++i)
{
- for (auto& child_index : other_node.mChildren)
- {
- if (child_index == node_index)
- {
- // Found a parent, recursively get its combined transform
- glm::mat4 parent_transform;
- computeCombinedNodeTransform(asset, static_cast<S32>(&other_node - &asset.mNodes[0]), parent_transform);
+ const auto& potential_parent = asset.mNodes[i];
+ auto it = std::find(potential_parent.mChildren.begin(), potential_parent.mChildren.end(), node_index);
- // Apply parent transform to current node transform
- node_transform = parent_transform * node_transform;
- break;
- }
+ if (it != potential_parent.mChildren.end())
+ {
+ // Found parent - recursively get its combined transform and apply it
+ glm::mat4 parent_transform;
+ computeCombinedNodeTransform(asset, static_cast<S32>(i), parent_transform);
+ combined_transform = parent_transform * combined_transform;
+ return; // Early exit - a node can only have one parent
}
}
-
- combined_transform = node_transform;
}
bool LLGLTFLoader::populateModelFromMesh(LLModel* pModel, const LL::GLTF::Mesh& mesh, const LL::GLTF::Node& nodeno, material_map& mats, S32 instance_count)