summaryrefslogtreecommitdiff
path: root/indra/newview/gltf/llgltfloader.cpp
diff options
context:
space:
mode:
authorMnikolenko Productengine <mnikolenko@productengine.com>2025-12-04 14:19:04 +0200
committerMnikolenko Productengine <mnikolenko@productengine.com>2025-12-04 14:19:22 +0200
commita377ec310848657ca6f4b76bdf74aca9cfc6f9da (patch)
treedfb181330de5d5d64981d50171f37c3d0d376ee1 /indra/newview/gltf/llgltfloader.cpp
parent1073444a44c5d0a877fb91dbdde06aa37fea7644 (diff)
parentc4ec3d866082d588de671e833413474d7ab19524 (diff)
Merge branch 'release/2026.01' into maxim/2025.07-Flat-UI
Diffstat (limited to 'indra/newview/gltf/llgltfloader.cpp')
-rw-r--r--indra/newview/gltf/llgltfloader.cpp50
1 files changed, 34 insertions, 16 deletions
diff --git a/indra/newview/gltf/llgltfloader.cpp b/indra/newview/gltf/llgltfloader.cpp
index dd1d327683..3a1d8079a9 100644
--- a/indra/newview/gltf/llgltfloader.cpp
+++ b/indra/newview/gltf/llgltfloader.cpp
@@ -412,17 +412,14 @@ void LLGLTFLoader::processNodeHierarchy(S32 node_idx, std::map<std::string, S32>
// Process this node's mesh if it has one
if (node.mMesh >= 0 && node.mMesh < mGLTFAsset.mMeshes.size())
{
- LLMatrix4 transformation;
- material_map mats;
-
- LLModel* pModel = new LLModel(volume_params, 0.f);
- const LL::GLTF::Mesh& mesh = mGLTFAsset.mMeshes[node.mMesh];
-
- // Get base mesh name and track usage
- std::string base_name = getLodlessLabel(mesh);
+ // Get base node name and track usage
+ // Potentially multiple nodes can reuse the same mesh and Collada used
+ // node name instead of mesh name, so for consistency use node name if
+ // avaliable, node index otherwise.
+ std::string base_name = getLodlessLabel(node);
if (base_name.empty())
{
- base_name = "mesh_" + std::to_string(node.mMesh);
+ base_name = "node_" + std::to_string(node_idx);
}
S32 instance_count = mesh_name_counts[base_name]++;
@@ -433,6 +430,12 @@ void LLGLTFLoader::processNodeHierarchy(S32 node_idx, std::map<std::string, S32>
base_name = base_name + "_copy_" + std::to_string(instance_count);
}
+ LLMatrix4 transformation;
+ material_map mats;
+
+ LLModel* pModel = new LLModel(volume_params, 0.f);
+ const LL::GLTF::Mesh& mesh = mGLTFAsset.mMeshes[node.mMesh];
+
if (populateModelFromMesh(pModel, base_name, mesh, node, mats) &&
(LLModel::NO_ERRORS == pModel->getStatus()) &&
validate_model(pModel))
@@ -599,11 +602,12 @@ LLGLTFLoader::LLGLTFImportMaterial LLGLTFLoader::processMaterial(S32 material_in
if (material->mPbrMetallicRoughness.mBaseColorTexture.mIndex >= 0)
{
S32 texIndex = material->mPbrMetallicRoughness.mBaseColorTexture.mIndex;
- std::string filename = processTexture(texIndex, "base_color", material->mName);
+ std::string full_path;
+ std::string filename = processTexture(full_path, texIndex, "base_color", material->mName);
if (!filename.empty())
{
- impMat.mDiffuseMapFilename = filename;
+ impMat.mDiffuseMapFilename = full_path;
impMat.mDiffuseMapLabel = material->mName.empty() ? filename : material->mName;
// Check if the texture is already loaded
@@ -634,7 +638,7 @@ LLGLTFLoader::LLGLTFImportMaterial LLGLTFLoader::processMaterial(S32 material_in
return cachedMat;
}
-std::string LLGLTFLoader::processTexture(S32 texture_index, const std::string& texture_type, const std::string& material_name)
+std::string LLGLTFLoader::processTexture(std::string& full_path_out, S32 texture_index, const std::string& texture_type, const std::string& material_name)
{
S32 sourceIndex;
if (!validateTextureIndex(texture_index, sourceIndex))
@@ -652,6 +656,20 @@ std::string LLGLTFLoader::processTexture(S32 texture_index, const std::string& t
filename = filename.substr(pos + 1);
}
+ std::string dir = gDirUtilp->getDirName(mFilename);
+ std::string full_path = dir + gDirUtilp->getDirDelimiter() + filename;
+ if (!gDirUtilp->fileExists(full_path) && filename.find("data:") == std::string::npos)
+ {
+ // Uri might be escaped
+ filename = LLURI::unescape(filename);
+ full_path = dir + gDirUtilp->getDirDelimiter() + filename;
+ }
+
+ if (gDirUtilp->fileExists(full_path))
+ {
+ full_path_out = full_path;
+ }
+
LL_INFOS("GLTF_IMPORT") << "Found texture: " << filename << " for material: " << material_name << LL_ENDL;
LLSD args;
@@ -1810,13 +1828,13 @@ size_t LLGLTFLoader::getSuffixPosition(const std::string &label)
return -1;
}
-std::string LLGLTFLoader::getLodlessLabel(const LL::GLTF::Mesh& mesh)
+std::string LLGLTFLoader::getLodlessLabel(const LL::GLTF::Node& node)
{
- size_t ext_pos = getSuffixPosition(mesh.mName);
+ size_t ext_pos = getSuffixPosition(node.mName);
if (ext_pos != -1)
{
- return mesh.mName.substr(0, ext_pos);
+ return node.mName.substr(0, ext_pos);
}
- return mesh.mName;
+ return node.mName;
}