From fa51ec3dafa766734e77e0a1aa7733fbe601e7c0 Mon Sep 17 00:00:00 2001 From: sabrina-shanman Date: Thu, 24 Oct 2019 18:02:19 -0700 Subject: [PATCH] (WIP) (has debug) Fix baked FBX materials --- libraries/fbx/src/FBXSerializer.cpp | 5 +++-- libraries/fbx/src/FBXSerializer_Mesh.cpp | 14 ++++---------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/libraries/fbx/src/FBXSerializer.cpp b/libraries/fbx/src/FBXSerializer.cpp index 2c03c3c3ae..8c1204d783 100644 --- a/libraries/fbx/src/FBXSerializer.cpp +++ b/libraries/fbx/src/FBXSerializer.cpp @@ -1562,7 +1562,8 @@ HFMModel* FBXSerializer::extractHFMModel(const hifi::VariantHash& mapping, const } // For baked models with FBX_DRACO_MESH_VERSION >= 2, get materials from extracted.materialIDPerMeshPart if (!extracted.materialIDPerMeshPart.empty()) { - /* if (partShapes.size() == extracted.materialIDPerMeshPart.size()) { + // TODO: Verify this code works as intended by testing baked FBX models, then remove the verification/debug + if (partShapes.size() == extracted.materialIDPerMeshPart.size()) { for (uint32_t i = 0; i < (uint32_t)extracted.materialIDPerMeshPart.size(); ++i) { hfm::Shape& shape = partShapes[i]; const std::string& materialID = extracted.materialIDPerMeshPart[i]; @@ -1576,7 +1577,7 @@ HFMModel* FBXSerializer::extractHFMModel(const hifi::VariantHash& mapping, const qCDebug(modelformat) << "mesh.parts[" << p <<"] is " << mesh.parts[p].materialID; } qCDebug(modelformat) << "partShapes is not the same size as materialIDPerMeshPart ?"; - }*/ + } } // find the clusters with which the mesh is associated diff --git a/libraries/fbx/src/FBXSerializer_Mesh.cpp b/libraries/fbx/src/FBXSerializer_Mesh.cpp index 37f2c9ec1b..e9884f3087 100644 --- a/libraries/fbx/src/FBXSerializer_Mesh.cpp +++ b/libraries/fbx/src/FBXSerializer_Mesh.cpp @@ -369,11 +369,6 @@ ExtractedMesh FBXSerializer::extractMesh(const FBXNode& object, unsigned int& me } } - if (dracoMeshNodeVersion >= 2) { - // Define the materialIDs now - data.extracted.materialIDPerMeshPart = dracoMaterialList; - } - // load the draco mesh from the FBX and create a draco::Mesh draco::Decoder decoder; draco::DecoderBuffer decodedBuffer; @@ -491,15 +486,14 @@ ExtractedMesh FBXSerializer::extractMesh(const FBXNode& object, unsigned int& me // grab or setup the HFMMeshPart for the part this face belongs to int& partIndexPlusOne = materialTextureParts[materialTexture]; if (partIndexPlusOne == 0) { - data.extracted.mesh.parts.resize(data.extracted.mesh.parts.size() + 1); + data.extracted.mesh.parts.emplace_back(); HFMMeshPart& part = data.extracted.mesh.parts.back(); // Figure out if this is the older way of defining the per-part material for baked FBX if (dracoMeshNodeVersion >= 2) { - // Define the materialID now - if (materialID < dracoMaterialList.size()) { - part.materialID = QString(dracoMaterialList[materialID].c_str()); - } + // Define the materialID for this mesh part index + uint16_t safeMaterialID = materialID < dracoMaterialList.size() ? materialID : 0; + data.extracted.materialIDPerMeshPart.push_back(dracoMaterialList[materialID].c_str()); } else { // Define the materialID later, based on the order of first appearance of the materials in the _connectionChildMap data.extracted.partMaterialTextures.append(materialTexture);