mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-29 21:23:05 +02:00
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:
parent
9df2186696
commit
9905fc076c
2 changed files with 35 additions and 8 deletions
|
@ -1480,6 +1480,12 @@ HFMModel* FBXSerializer::extractHFMModel(const hifi::VariantHash& mapping, const
|
||||||
// meshShapes will be added to hfmModel at the very end
|
// meshShapes will be added to hfmModel at the very end
|
||||||
std::vector<hfm::Shape> meshShapes;
|
std::vector<hfm::Shape> meshShapes;
|
||||||
meshShapes.reserve(instanceModelIDs.size() * mesh.parts.size());
|
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) {
|
for (const QString& modelID : instanceModelIDs) {
|
||||||
// The transform node has the same indexing order as the joints
|
// The transform node has the same indexing order as the joints
|
||||||
const uint32_t transformIndex = (uint32_t)modelIDs.indexOf(modelID);
|
const uint32_t transformIndex = (uint32_t)modelIDs.indexOf(modelID);
|
||||||
|
@ -1500,6 +1506,14 @@ HFMModel* FBXSerializer::extractHFMModel(const hifi::VariantHash& mapping, const
|
||||||
shape.mesh = meshIndex;
|
shape.mesh = meshIndex;
|
||||||
shape.meshPart = i;
|
shape.meshPart = i;
|
||||||
shape.transform = transformIndex;
|
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();
|
shape.transformedExtents.reset();
|
||||||
// compute the shape extents from the transformed vertices
|
// compute the shape extents from the transformed vertices
|
||||||
|
@ -1546,14 +1560,21 @@ HFMModel* FBXSerializer::extractHFMModel(const hifi::VariantHash& mapping, const
|
||||||
}
|
}
|
||||||
// For baked models with FBX_DRACO_MESH_VERSION >= 2, get materials from extracted.materialIDPerMeshPart
|
// For baked models with FBX_DRACO_MESH_VERSION >= 2, get materials from extracted.materialIDPerMeshPart
|
||||||
if (!extracted.materialIDPerMeshPart.empty()) {
|
if (!extracted.materialIDPerMeshPart.empty()) {
|
||||||
for (uint32_t i = 0; i < (uint32_t)extracted.materialIDPerMeshPart.size(); ++i) {
|
/* if (partShapes.size() == extracted.materialIDPerMeshPart.size()) {
|
||||||
hfm::Shape& shape = partShapes[i];
|
for (uint32_t i = 0; i < (uint32_t)extracted.materialIDPerMeshPart.size(); ++i) {
|
||||||
const std::string& materialID = extracted.materialIDPerMeshPart[i];
|
hfm::Shape& shape = partShapes[i];
|
||||||
auto materialIt = materialNameToID.find(materialID);
|
const std::string& materialID = extracted.materialIDPerMeshPart[i];
|
||||||
if (materialIt != materialNameToID.end()) {
|
auto materialIt = materialNameToID.find(materialID);
|
||||||
shape.material = materialIt->second;
|
if (materialIt != materialNameToID.end()) {
|
||||||
|
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
|
// find the clusters with which the mesh is associated
|
||||||
|
|
|
@ -492,9 +492,15 @@ ExtractedMesh FBXSerializer::extractMesh(const FBXNode& object, unsigned int& me
|
||||||
int& partIndexPlusOne = materialTextureParts[materialTexture];
|
int& partIndexPlusOne = materialTextureParts[materialTexture];
|
||||||
if (partIndexPlusOne == 0) {
|
if (partIndexPlusOne == 0) {
|
||||||
data.extracted.mesh.parts.resize(data.extracted.mesh.parts.size() + 1);
|
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
|
// 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
|
// Define the materialID later, based on the order of first appearance of the materials in the _connectionChildMap
|
||||||
data.extracted.partMaterialTextures.append(materialTexture);
|
data.extracted.partMaterialTextures.append(materialTexture);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue