Skip to content

Commit d9db7bb

Browse files
committed
p#480 Collada vs GLTF Mesh Import Naming Convention
Both collada and gltf have a node and a mesh. Collada uses node-name, gltf was using mesh-name. GLTF format permits reusing single mesh for multiple nodes, but nodes are warrantied to not be reused. Switch to using node-names for better dupplicate avoidance and to be more in line with collada.
1 parent 9c28607 commit d9db7bb

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

indra/newview/gltf/llgltfloader.cpp

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -412,17 +412,14 @@ void LLGLTFLoader::processNodeHierarchy(S32 node_idx, std::map<std::string, S32>
412412
// Process this node's mesh if it has one
413413
if (node.mMesh >= 0 && node.mMesh < mGLTFAsset.mMeshes.size())
414414
{
415-
LLMatrix4 transformation;
416-
material_map mats;
417-
418-
LLModel* pModel = new LLModel(volume_params, 0.f);
419-
const LL::GLTF::Mesh& mesh = mGLTFAsset.mMeshes[node.mMesh];
420-
421-
// Get base mesh name and track usage
422-
std::string base_name = getLodlessLabel(mesh);
415+
// Get base node name and track usage
416+
// Potentially multiple nodes can reuse the same mesh and Collada used
417+
// node name instead of mesh name, so for consistency use node name if
418+
// avaliable, node index otherwise.
419+
std::string base_name = getLodlessLabel(node);
423420
if (base_name.empty())
424421
{
425-
base_name = "mesh_" + std::to_string(node.mMesh);
422+
base_name = "node_" + std::to_string(node_idx);
426423
}
427424

428425
S32 instance_count = mesh_name_counts[base_name]++;
@@ -433,6 +430,12 @@ void LLGLTFLoader::processNodeHierarchy(S32 node_idx, std::map<std::string, S32>
433430
base_name = base_name + "_copy_" + std::to_string(instance_count);
434431
}
435432

433+
LLMatrix4 transformation;
434+
material_map mats;
435+
436+
LLModel* pModel = new LLModel(volume_params, 0.f);
437+
const LL::GLTF::Mesh& mesh = mGLTFAsset.mMeshes[node.mMesh];
438+
436439
if (populateModelFromMesh(pModel, base_name, mesh, node, mats) &&
437440
(LLModel::NO_ERRORS == pModel->getStatus()) &&
438441
validate_model(pModel))
@@ -1818,13 +1821,13 @@ size_t LLGLTFLoader::getSuffixPosition(const std::string &label)
18181821
return -1;
18191822
}
18201823

1821-
std::string LLGLTFLoader::getLodlessLabel(const LL::GLTF::Mesh& mesh)
1824+
std::string LLGLTFLoader::getLodlessLabel(const LL::GLTF::Node& node)
18221825
{
1823-
size_t ext_pos = getSuffixPosition(mesh.mName);
1826+
size_t ext_pos = getSuffixPosition(node.mName);
18241827
if (ext_pos != -1)
18251828
{
1826-
return mesh.mName.substr(0, ext_pos);
1829+
return node.mName.substr(0, ext_pos);
18271830
}
1828-
return mesh.mName;
1831+
return node.mName;
18291832
}
18301833

indra/newview/gltf/llgltfloader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ class LLGLTFLoader : public LLModelLoader
170170
void notifyUnsupportedExtension(bool unsupported);
171171

172172
static size_t getSuffixPosition(const std::string& label);
173-
static std::string getLodlessLabel(const LL::GLTF::Mesh& mesh);
173+
static std::string getLodlessLabel(const LL::GLTF::Node& mesh);
174174

175175
// bool mPreprocessGLTF;
176176

0 commit comments

Comments
 (0)