From 148b880bb1d7049e16cf0aafd7d9843fc707f63b Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Thu, 16 Oct 2014 14:32:07 -0700 Subject: [PATCH] handle case of meshes with multiple parts with different materials better, don't mix them in with single material meshes --- interface/src/renderer/Model.cpp | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/interface/src/renderer/Model.cpp b/interface/src/renderer/Model.cpp index 1471f72b3a..1228a458b2 100644 --- a/interface/src/renderer/Model.cpp +++ b/interface/src/renderer/Model.cpp @@ -1334,7 +1334,22 @@ void Model::segregateMeshGroups() { bool hasTangents = !mesh.tangents.isEmpty(); bool hasSpecular = mesh.hasSpecularTexture(); bool isSkinned = state.clusterMatrices.size() > 1; - QString materialID = mesh.parts.at(0).materialID; + QString materialID; + + // create a material name from all the parts. If there's one part, this will be a single material and its + // true name. If however the mesh has multiple parts the name will be all the part's materials mashed together + // which will result in those parts being sorted away from single material parts. + QString lastPartMaterialID; + foreach(FBXMeshPart part, mesh.parts) { + if (part.materialID != lastPartMaterialID) { + materialID += part.materialID; + } + lastPartMaterialID = part.materialID; + } + const bool wantDebug = false; + if (wantDebug) { + qDebug() << "materialID:" << materialID << "parts:" << mesh.parts.size(); + } if (translucentMesh && !hasTangents && !hasSpecular && !isSkinned) { @@ -1712,8 +1727,12 @@ int Model::renderMeshes(RenderMode mode, bool translucent, float alphaThreshold, } else { if (dontReduceMaterialSwitches || lastMaterialID != part.materialID) { - //qDebug() << "Material Changed ---------------------------------------------"; - //qDebug() << "NEW part.materialID:" << part.materialID; + const bool wantDebug = false; + if (wantDebug) { + qDebug() << "Material Changed ---------------------------------------------"; + qDebug() << "part INDEX:" << j; + qDebug() << "NEW part.materialID:" << part.materialID; + } glm::vec4 diffuse = glm::vec4(part.diffuseColor, part.opacity); if (!(translucent && alphaThreshold == 0.0f)) {