From 338abded1284b4390a14e179722fc89639fc72bf Mon Sep 17 00:00:00 2001 From: contriteobserver Date: Sat, 23 Jan 2021 02:20:58 -0800 Subject: [PATCH 1/3] ColladaLoader now assigns individual materials to submeshes as needed Optional assignment of individual materials to submeshes, addresses #3606 --- code/AssetLib/Collada/ColladaLoader.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/code/AssetLib/Collada/ColladaLoader.cpp b/code/AssetLib/Collada/ColladaLoader.cpp index 99cb8c305..3bd2a7d02 100644 --- a/code/AssetLib/Collada/ColladaLoader.cpp +++ b/code/AssetLib/Collada/ColladaLoader.cpp @@ -557,7 +557,12 @@ void ColladaLoader::BuildMeshesForNode(const ColladaParser &pParser, const Colla faceStart += submesh.mNumFaces; // assign the material index - dstMesh->mMaterialIndex = matIdx; + std::map::const_iterator matIt = mMaterialIndexByName.find(submesh.mMaterial); + if (matIt != mMaterialIndexByName.end()) { + dstMesh->mMaterialIndex = matIt->second; + } else { + dstMesh->mMaterialIndex = matIdx; + } if (dstMesh->mName.length == 0) { dstMesh->mName = mid.mMeshOrController; } From 69fc809307878601557053381617b6aad942783c Mon Sep 17 00:00:00 2001 From: contriteobserver Date: Tue, 26 Jan 2021 01:01:59 -0800 Subject: [PATCH 2/3] size_t is not the same as unsigned int on some systems --- code/AssetLib/Collada/ColladaLoader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/AssetLib/Collada/ColladaLoader.cpp b/code/AssetLib/Collada/ColladaLoader.cpp index 3bd2a7d02..297616b4e 100644 --- a/code/AssetLib/Collada/ColladaLoader.cpp +++ b/code/AssetLib/Collada/ColladaLoader.cpp @@ -559,7 +559,7 @@ void ColladaLoader::BuildMeshesForNode(const ColladaParser &pParser, const Colla // assign the material index std::map::const_iterator matIt = mMaterialIndexByName.find(submesh.mMaterial); if (matIt != mMaterialIndexByName.end()) { - dstMesh->mMaterialIndex = matIt->second; + dstMesh->mMaterialIndex = static_cast(matIt->second); } else { dstMesh->mMaterialIndex = matIdx; } From d7bf5132500d7f568bb9c0ce31f83e86548cd230 Mon Sep 17 00:00:00 2001 From: contriteobserver Date: Tue, 26 Jan 2021 01:36:12 -0800 Subject: [PATCH 3/3] renaming iterator to avoid any possibility of scop collisions --- code/AssetLib/Collada/ColladaLoader.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/code/AssetLib/Collada/ColladaLoader.cpp b/code/AssetLib/Collada/ColladaLoader.cpp index 297616b4e..96599f22f 100644 --- a/code/AssetLib/Collada/ColladaLoader.cpp +++ b/code/AssetLib/Collada/ColladaLoader.cpp @@ -557,9 +557,9 @@ void ColladaLoader::BuildMeshesForNode(const ColladaParser &pParser, const Colla faceStart += submesh.mNumFaces; // assign the material index - std::map::const_iterator matIt = mMaterialIndexByName.find(submesh.mMaterial); - if (matIt != mMaterialIndexByName.end()) { - dstMesh->mMaterialIndex = static_cast(matIt->second); + std::map::const_iterator subMatIt = mMaterialIndexByName.find(submesh.mMaterial); + if (subMatIt != mMaterialIndexByName.end()) { + dstMesh->mMaterialIndex = static_cast(subMatIt->second); } else { dstMesh->mMaterialIndex = matIdx; }