diff options
| author | Andrey Kleshchev <andreykproductengine@lindenlab.com> | 2022-09-29 22:38:40 +0300 |
|---|---|---|
| committer | Andrey Kleshchev <andreykproductengine@lindenlab.com> | 2022-09-29 22:39:32 +0300 |
| commit | 9346b45188462056698083f4f83fe8fecbe19bdf (patch) | |
| tree | 9d0ac5c1633c27d85ffb9e44d62c6d4f6c1a2a27 /indra/newview/lltinygltfhelper.cpp | |
| parent | 02df55b9b366f3df98fc4b861dffa779c9d0a536 (diff) | |
SL-17653 Multi-material file support for local materials
Diffstat (limited to 'indra/newview/lltinygltfhelper.cpp')
| -rw-r--r-- | indra/newview/lltinygltfhelper.cpp | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/indra/newview/lltinygltfhelper.cpp b/indra/newview/lltinygltfhelper.cpp index 3125cacbd5..c3dc10c2a0 100644 --- a/indra/newview/lltinygltfhelper.cpp +++ b/indra/newview/lltinygltfhelper.cpp @@ -122,17 +122,20 @@ void LLTinyGLTFHelper::initFetchedTextures(tinygltf::Material& material, } } -void LLTinyGLTFHelper::setFromModel(LLGLTFMaterial* mat, tinygltf::Model& model) +void LLTinyGLTFHelper::setFromModel(LLGLTFMaterial* mat, tinygltf::Model& model, S32 mat_index) { - S32 index; + if (model.materials.size() <= mat_index) + { + return; + } - auto& material_in = model.materials[0]; + tinygltf::Material& material_in = model.materials[mat_index]; // get base color texture - index = material_in.pbrMetallicRoughness.baseColorTexture.index; - if (index >= 0) + S32 tex_index = material_in.pbrMetallicRoughness.baseColorTexture.index; + if (tex_index >= 0) { - mat->mBaseColorId.set(model.images[index].uri); + mat->mBaseColorId.set(model.images[tex_index].uri); } else { @@ -140,10 +143,10 @@ void LLTinyGLTFHelper::setFromModel(LLGLTFMaterial* mat, tinygltf::Model& model) } // get normal map - index = material_in.normalTexture.index; - if (index >= 0) + tex_index = material_in.normalTexture.index; + if (tex_index >= 0) { - mat->mNormalId.set(model.images[index].uri); + mat->mNormalId.set(model.images[tex_index].uri); } else { @@ -151,10 +154,10 @@ void LLTinyGLTFHelper::setFromModel(LLGLTFMaterial* mat, tinygltf::Model& model) } // get metallic-roughness texture - index = material_in.pbrMetallicRoughness.metallicRoughnessTexture.index; - if (index >= 0) + tex_index = material_in.pbrMetallicRoughness.metallicRoughnessTexture.index; + if (tex_index >= 0) { - mat->mMetallicRoughnessId.set(model.images[index].uri); + mat->mMetallicRoughnessId.set(model.images[tex_index].uri); } else { @@ -162,10 +165,10 @@ void LLTinyGLTFHelper::setFromModel(LLGLTFMaterial* mat, tinygltf::Model& model) } // get emissive texture - index = material_in.emissiveTexture.index; - if (index >= 0) + tex_index = material_in.emissiveTexture.index; + if (tex_index >= 0) { - mat->mEmissiveId.set(model.images[index].uri); + mat->mEmissiveId.set(model.images[tex_index].uri); } else { |
