Make small improvements to FBXSerializer code changes

This commit is contained in:
sabrina-shanman 2019-10-03 10:49:14 -07:00
parent ff5fef9c3a
commit ba6833df8f
2 changed files with 37 additions and 43 deletions

View file

@ -1263,13 +1263,11 @@ HFMModel* FBXSerializer::extractHFMModel(const hifi::VariantHash& mapping, const
// convert the models to joints
hfmModel.hasSkeletonJoints = false;
// Note that these transform nodes are initially defined in world space
bool needMixamoHack = hfmModel.applicationName == "mixamo.com";
hfmModel.transforms.reserve(modelIDs.size());
std::vector<glm::mat4> globalTransforms;
globalTransforms.reserve(modelIDs.size());
int jointIndex = 0;
for (const QString& modelID : modelIDs) {
const FBXModel& fbxModel = fbxModels[modelID];
HFMJoint joint;
@ -1378,13 +1376,8 @@ HFMModel* FBXSerializer::extractHFMModel(const hifi::VariantHash& mapping, const
transformNode.transform = Transform(localTransform);
globalTransforms.push_back(globalTransform);
hfmModel.transforms.push_back(transformNode);
++jointIndex;
}
// NOTE: shapeVertices are in joint-frame
hfmModel.shapeVertices.resize(std::max((size_t)1, hfmModel.joints.size()) );
hfmModel.bindExtents.reset();
hfmModel.meshExtents.reset();
@ -1482,6 +1475,7 @@ HFMModel* FBXSerializer::extractHFMModel(const hifi::VariantHash& mapping, const
}
// For FBX_DRACO_MESH_VERSION < 2, or unbaked models, get materials from the partMaterialTextures
if (!partMaterialTextures.empty()) {
int materialIndex = 0;
int textureIndex = 0;
QList<QString> children = _connectionChildMap.values(modelID);
@ -1513,6 +1507,7 @@ HFMModel* FBXSerializer::extractHFMModel(const hifi::VariantHash& mapping, const
textureIndex++;
}
}
}
// For baked models with FBX_DRACO_MESH_VERSION >= 2, get materials from extracted.materialIDPerMeshPart
if (!extracted.materialIDPerMeshPart.empty()) {
for (uint32_t i = 0; i < (uint32_t)extracted.materialIDPerMeshPart.size(); ++i) {

View file

@ -369,6 +369,11 @@ 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;
@ -467,8 +472,6 @@ ExtractedMesh FBXSerializer::extractMesh(const FBXNode& object, unsigned int& me
}
}
ExtractedMesh& extracted = data.extracted;
extracted.materialIDPerMeshPart.resize(dracoMaterialList.size());
for (uint32_t i = 0; i < dracoMesh->num_faces(); ++i) {
// grab the material ID and texture ID for this face, if we have it
auto& dracoFace = dracoMesh->face(draco::FaceIndex(i));
@ -489,18 +492,14 @@ 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 = extracted.mesh.parts.back();
HFMMeshPart& part = data.extracted.mesh.parts.back();
// Figure out what material this part is
if (dracoMeshNodeVersion >= 2) {
// Define the materialID now
if (materialID < dracoMaterialList.size()) {
extracted.materialIDPerMeshPart[materialID] = dracoMaterialList[materialID];
}
} else {
// Figure out if this is the older way of defining the per-part material for baked FBX
if (dracoMeshNodeVersion < 2) {
// Define the materialID later, based on the order of first appearance of the materials in the _connectionChildMap
data.extracted.partMaterialTextures.append(materialTexture);
}
// in dracoMeshNodeVersion >= 2, fbx meshes have their per-part materials already defined in data.extracted.materialIDPerMeshPart
partIndexPlusOne = (int)data.extracted.mesh.parts.size();
}