Skip to content

Commit b423900

Browse files
committed
#4105 Fix duplicate GLTF model instances causing upload errors
1 parent d6419f7 commit b423900

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

indra/newview/gltf/llgltfloader.cpp

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ bool LLGLTFLoader::parseMeshes()
153153
node.makeMatrixValid();
154154
}
155155

156+
// Track how many times each mesh name has been used
157+
std::map<std::string, S32> mesh_name_counts;
158+
156159
// Process each node
157160
for (auto& node : mGLTFAsset.mNodes)
158161
{
@@ -166,7 +169,17 @@ bool LLGLTFLoader::parseMeshes()
166169
{
167170
LLModel* pModel = new LLModel(volume_params, 0.f);
168171
auto mesh = mGLTFAsset.mMeshes[meshidx];
169-
if (populateModelFromMesh(pModel, mesh, node, mats) &&
172+
173+
// Get base mesh name and track usage
174+
std::string base_name = mesh.mName;
175+
if (base_name.empty())
176+
{
177+
base_name = "mesh_" + std::to_string(meshidx);
178+
}
179+
180+
S32 instance_count = mesh_name_counts[base_name]++;
181+
182+
if (populateModelFromMesh(pModel, mesh, node, mats, instance_count) &&
170183
(LLModel::NO_ERRORS == pModel->getStatus()) &&
171184
validate_model(pModel))
172185
{
@@ -244,9 +257,25 @@ void LLGLTFLoader::computeCombinedNodeTransform(const LL::GLTF::Asset& asset, S3
244257
combined_transform = node_transform;
245258
}
246259

247-
bool LLGLTFLoader::populateModelFromMesh(LLModel* pModel, const LL::GLTF::Mesh& mesh, const LL::GLTF::Node& nodeno, material_map& mats)
260+
bool LLGLTFLoader::populateModelFromMesh(LLModel* pModel, const LL::GLTF::Mesh& mesh, const LL::GLTF::Node& nodeno, material_map& mats, S32 instance_count)
248261
{
249-
pModel->mLabel = mesh.mName;
262+
// Create unique model name
263+
std::string base_name = mesh.mName;
264+
if (base_name.empty())
265+
{
266+
S32 mesh_index = static_cast<S32>(&mesh - &mGLTFAsset.mMeshes[0]);
267+
base_name = "mesh_" + std::to_string(mesh_index);
268+
}
269+
270+
if (instance_count > 0)
271+
{
272+
pModel->mLabel = base_name + "_copy_" + std::to_string(instance_count);
273+
}
274+
else
275+
{
276+
pModel->mLabel = base_name;
277+
}
278+
250279
pModel->ClearFacesAndMaterials();
251280

252281
S32 skinIdx = nodeno.mSkin;

indra/newview/gltf/llgltfloader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ class LLGLTFLoader : public LLModelLoader
168168
bool parseMaterials();
169169
void uploadMaterials();
170170
void computeCombinedNodeTransform(const LL::GLTF::Asset& asset, S32 node_index, glm::mat4& combined_transform);
171-
bool populateModelFromMesh(LLModel* pModel, const LL::GLTF::Mesh &mesh, const LL::GLTF::Node &node, material_map& mats);
171+
bool populateModelFromMesh(LLModel* pModel, const LL::GLTF::Mesh &mesh, const LL::GLTF::Node &node, material_map& mats, S32 instance_count);
172172
void populateJointFromSkin(const LL::GLTF::Skin& skin);
173173
LLUUID imageBufferToTextureUUID(const gltf_texture& tex);
174174

0 commit comments

Comments
 (0)