@@ -188,6 +188,7 @@ bool LLGLTFLoader::OpenFile(const std::string &filename)
188188
189189void LLGLTFLoader::addModelToScene (
190190 LLModel* pModel,
191+ const std::string& model_name,
191192 U32 submodel_limit,
192193 const LLMatrix4& transformation,
193194 const LLVolumeParams& volume_params,
@@ -239,7 +240,7 @@ void LLGLTFLoader::addModelToScene(
239240 LLModel* next = new LLModel (volume_params, 0 .f );
240241 next->ClearFacesAndMaterials ();
241242 next->mSubmodelID = ++submodelID;
242- next->mLabel = pModel-> mLabel + (char )((int )' a' + next->mSubmodelID ) + lod_suffix[mLod ];
243+ next->mLabel = model_name + (char )((int )' a' + next->mSubmodelID ) + lod_suffix[mLod ];
243244 next->getVolumeFaces () = remainder;
244245 next->mNormalizedScale = current_model->mNormalizedScale ;
245246 next->mNormalizedTranslation = current_model->mNormalizedTranslation ;
@@ -289,7 +290,12 @@ void LLGLTFLoader::addModelToScene(
289290 materials[model->mMaterialList [i]] = LLImportMaterial ();
290291 }
291292 }
292- mScene [transformation].push_back (LLModelInstance (model, model->mLabel , transformation, materials));
293+ std::string base_name = model_name;
294+ if (model->mSubmodelID > 0 )
295+ {
296+ base_name += (char )((int )' a' + model->mSubmodelID );
297+ }
298+ mScene [transformation].push_back (LLModelInstance (model, base_name, transformation, materials));
293299 stretch_extents (model, transformation);
294300 }
295301}
@@ -387,15 +393,21 @@ void LLGLTFLoader::processNodeHierarchy(S32 node_idx, std::map<std::string, S32>
387393 const LL::GLTF::Mesh& mesh = mGLTFAsset .mMeshes [node.mMesh ];
388394
389395 // Get base mesh name and track usage
390- std::string base_name = mesh. mName ;
396+ std::string base_name = getLodlessLabel ( mesh) ;
391397 if (base_name.empty ())
392398 {
393399 base_name = " mesh_" + std::to_string (node.mMesh );
394400 }
395401
396402 S32 instance_count = mesh_name_counts[base_name]++;
397403
398- if (populateModelFromMesh (pModel, mesh, node, mats, instance_count) &&
404+ // make name unique
405+ if (instance_count > 0 )
406+ {
407+ base_name = base_name + " _copy_" + std::to_string (instance_count);
408+ }
409+
410+ if (populateModelFromMesh (pModel, base_name, mesh, node, mats) &&
399411 (LLModel::NO_ERRORS == pModel->getStatus ()) &&
400412 validate_model (pModel))
401413 {
@@ -443,7 +455,7 @@ void LLGLTFLoader::processNodeHierarchy(S32 node_idx, std::map<std::string, S32>
443455 mWarningsArray .append (args);
444456 }
445457
446- addModelToScene (pModel, submodel_limit, transformation, volume_params, mats);
458+ addModelToScene (pModel, base_name, submodel_limit, transformation, volume_params, mats);
447459 mats.clear ();
448460 }
449461 else
@@ -529,29 +541,16 @@ bool LLGLTFLoader::addJointToModelSkin(LLMeshSkinInfo& skin_info, S32 gltf_skin_
529541 return true ;
530542}
531543
532- bool LLGLTFLoader::populateModelFromMesh (LLModel* pModel, const LL::GLTF::Mesh& mesh, const LL::GLTF::Node& nodeno, material_map& mats, S32 instance_count )
544+ bool LLGLTFLoader::populateModelFromMesh (LLModel* pModel, const std::string& base_name, const LL::GLTF::Mesh& mesh, const LL::GLTF::Node& nodeno, material_map& mats)
533545{
534546 // Set the requested label for the floater display and uploading
535547 pModel->mRequestedLabel = gDirUtilp ->getBaseFileName (mFilename , true );
548+ // Set name and suffix. Suffix is nessesary for model matching logic
549+ // because sometimes higher lod can be used as a lower one, so they
550+ // need unique names not just in scope of one lod, but across lods.
551+ pModel->mLabel = base_name + lod_suffix[mLod ];
536552
537- // Create unique model name
538- std::string base_name = mesh.mName ;
539- if (base_name.empty ())
540- {
541- S32 mesh_index = static_cast <S32>(&mesh - &mGLTFAsset .mMeshes [0 ]);
542- base_name = " mesh_" + std::to_string (mesh_index);
543- }
544-
545- LL_DEBUGS (" GLTF_DEBUG" ) << " Processing model " << base_name << LL_ENDL;
546-
547- if (instance_count > 0 )
548- {
549- pModel->mLabel = base_name + " _copy_" + std::to_string (instance_count);
550- }
551- else
552- {
553- pModel->mLabel = base_name;
554- }
553+ LL_DEBUGS (" GLTF_DEBUG" ) << " Processing model " << pModel->mLabel << LL_ENDL;
555554
556555 pModel->ClearFacesAndMaterials ();
557556
@@ -1723,3 +1722,22 @@ void LLGLTFLoader::notifyUnsupportedExtension(bool unsupported)
17231722 }
17241723}
17251724
1725+ size_t LLGLTFLoader::getSuffixPosition (const std::string &label)
1726+ {
1727+ if ((label.find (" _LOD" ) != -1 ) || (label.find (" _PHYS" ) != -1 ))
1728+ {
1729+ return label.rfind (' _' );
1730+ }
1731+ return -1 ;
1732+ }
1733+
1734+ std::string LLGLTFLoader::getLodlessLabel (const LL::GLTF::Mesh& mesh)
1735+ {
1736+ size_t ext_pos = getSuffixPosition (mesh.mName );
1737+ if (ext_pos != -1 )
1738+ {
1739+ return mesh.mName .substr (0 , ext_pos);
1740+ }
1741+ return mesh.mName ;
1742+ }
1743+
0 commit comments