Materials of baked models fbx are loading correctly, still using the name/id of the mateiral in the part struct

This commit is contained in:
Sam Gateau 2019-10-09 16:44:06 -07:00
parent 9df2186696
commit 9905fc076c
2 changed files with 35 additions and 8 deletions

View file

@ -1480,6 +1480,12 @@ HFMModel* FBXSerializer::extractHFMModel(const hifi::VariantHash& mapping, const
// meshShapes will be added to hfmModel at the very end
std::vector<hfm::Shape> meshShapes;
meshShapes.reserve(instanceModelIDs.size() * mesh.parts.size());
if (instanceModelIDs.size() > 1) {
qCDebug(modelformat) << "Mesh " << meshID << " made of " << mesh.parts.size() << " parts is instanced " << instanceModelIDs.size() << " times!!!";
}
if (mesh.parts.size() < 1) {
qCDebug(modelformat) << "Mesh " << meshID << " made of " << mesh.parts.size() << " parts !!!!! ";
}
for (const QString& modelID : instanceModelIDs) {
// The transform node has the same indexing order as the joints
const uint32_t transformIndex = (uint32_t)modelIDs.indexOf(modelID);
@ -1501,6 +1507,14 @@ HFMModel* FBXSerializer::extractHFMModel(const hifi::VariantHash& mapping, const
shape.meshPart = i;
shape.transform = transformIndex;
auto matName = mesh.parts[i].materialID;
auto materialIt = materialNameToID.find(matName.toStdString());
if (materialIt != materialNameToID.end()) {
shape.material = materialIt->second;
} else {
qCDebug(modelformat) << "Unknown material ? " << matName;
}
shape.transformedExtents.reset();
// compute the shape extents from the transformed vertices
for (const glm::vec3& vertex : mesh.vertices) {
@ -1546,6 +1560,7 @@ 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()) {
for (uint32_t i = 0; i < (uint32_t)extracted.materialIDPerMeshPart.size(); ++i) {
hfm::Shape& shape = partShapes[i];
const std::string& materialID = extracted.materialIDPerMeshPart[i];
@ -1554,6 +1569,12 @@ HFMModel* FBXSerializer::extractHFMModel(const hifi::VariantHash& mapping, const
shape.material = materialIt->second;
}
}
} else {
for (int p = 0; p < mesh.parts.size(); p++) {
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

View file

@ -492,9 +492,15 @@ ExtractedMesh FBXSerializer::extractMesh(const FBXNode& object, unsigned int& me
int& partIndexPlusOne = materialTextureParts[materialTexture];
if (partIndexPlusOne == 0) {
data.extracted.mesh.parts.resize(data.extracted.mesh.parts.size() + 1);
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) {
if (dracoMeshNodeVersion >= 2) {
// Define the materialID now
if (materialID < dracoMaterialList.size()) {
part.materialID = QString(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);
}