Skip to content

Commit b4fb66c

Browse files
committed
#4170 Use GLTF scene definition for node traversal
Process nodes through the scene hierarchy as defined in the GLTF file instead of attempting to reconstruct parent-child relationships. This ensures proper import of models created by GLTF transform tools.
1 parent b20d10c commit b4fb66c

File tree

1 file changed

+29
-18
lines changed

1 file changed

+29
-18
lines changed

indra/newview/gltf/llgltfloader.cpp

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -265,31 +265,32 @@ bool LLGLTFLoader::parseMeshes()
265265
std::map<std::string, S32> mesh_name_counts;
266266
U32 submodel_limit = mGLTFAsset.mNodes.size() > 0 ? mGeneratedModelLimit / (U32)mGLTFAsset.mNodes.size() : 0;
267267

268-
// Build parent mapping for efficient traversal
269-
std::vector<S32> node_parents(mGLTFAsset.mNodes.size(), -1);
270-
std::vector<bool> is_root(mGLTFAsset.mNodes.size(), true);
271-
272-
// Build parent relationships
273-
for (size_t parent_idx = 0; parent_idx < mGLTFAsset.mNodes.size(); parent_idx++)
268+
// Check if we have scenes defined
269+
if (!mGLTFAsset.mScenes.empty())
274270
{
275-
const auto& parent_node = mGLTFAsset.mNodes[parent_idx];
276-
for (S32 child_idx : parent_node.mChildren)
271+
// Process the default scene (or first scene if no default)
272+
S32 scene_idx = mGLTFAsset.mScene >= 0 ? mGLTFAsset.mScene : 0;
273+
274+
if (scene_idx < mGLTFAsset.mScenes.size())
277275
{
278-
if (child_idx >= 0 && child_idx < static_cast<S32>(mGLTFAsset.mNodes.size()))
276+
const LL::GLTF::Scene& scene = mGLTFAsset.mScenes[scene_idx];
277+
278+
LL_INFOS("GLTF_IMPORT") << "Processing scene " << scene_idx << " with " << scene.mNodes.size() << " root nodes" << LL_ENDL;
279+
280+
// Process all root nodes defined in the scene
281+
for (S32 root_idx : scene.mNodes)
279282
{
280-
node_parents[child_idx] = static_cast<S32>(parent_idx);
281-
is_root[child_idx] = false;
283+
if (root_idx >= 0 && root_idx < static_cast<S32>(mGLTFAsset.mNodes.size()))
284+
{
285+
processNodeHierarchy(root_idx, mesh_name_counts, submodel_limit, volume_params);
286+
}
282287
}
283288
}
284289
}
285-
286-
// Process all root nodes and their hierarchies
287-
for (size_t node_idx = 0; node_idx < mGLTFAsset.mNodes.size(); node_idx++)
290+
else
288291
{
289-
if (is_root[node_idx])
290-
{
291-
processNodeHierarchy(static_cast<S32>(node_idx), mesh_name_counts, submodel_limit, volume_params);
292-
}
292+
LL_WARNS("GLTF_IMPORT") << "No scenes defined in GLTF file" << LL_ENDL;
293+
return false;
293294
}
294295

295296
return true;
@@ -302,6 +303,10 @@ void LLGLTFLoader::processNodeHierarchy(S32 node_idx, std::map<std::string, S32>
302303

303304
auto& node = mGLTFAsset.mNodes[node_idx];
304305

306+
LL_INFOS("GLTF_IMPORT") << "Processing node " << node_idx << " (" << node.mName << ")"
307+
<< " - has mesh: " << (node.mMesh >= 0 ? "yes" : "no")
308+
<< " - children: " << node.mChildren.size() << LL_ENDL;
309+
305310
// Process this node's mesh if it has one
306311
if (node.mMesh >= 0 && node.mMesh < mGLTFAsset.mMeshes.size())
307312
{
@@ -378,6 +383,12 @@ void LLGLTFLoader::processNodeHierarchy(S32 node_idx, std::map<std::string, S32>
378383
return;
379384
}
380385
}
386+
else if (node.mMesh >= 0)
387+
{
388+
// Log invalid mesh reference
389+
LL_WARNS("GLTF_IMPORT") << "Node " << node_idx << " references invalid mesh " << node.mMesh
390+
<< " (total meshes: " << mGLTFAsset.mMeshes.size() << ")" << LL_ENDL;
391+
}
381392

382393
// Process all children recursively
383394
for (S32 child_idx : node.mChildren)

0 commit comments

Comments
 (0)