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 // convert the models to joints
hfmModel.hasSkeletonJoints = false; hfmModel.hasSkeletonJoints = false;
// Note that these transform nodes are initially defined in world space
bool needMixamoHack = hfmModel.applicationName == "mixamo.com"; bool needMixamoHack = hfmModel.applicationName == "mixamo.com";
hfmModel.transforms.reserve(modelIDs.size()); hfmModel.transforms.reserve(modelIDs.size());
std::vector<glm::mat4> globalTransforms; std::vector<glm::mat4> globalTransforms;
globalTransforms.reserve(modelIDs.size()); globalTransforms.reserve(modelIDs.size());
int jointIndex = 0;
for (const QString& modelID : modelIDs) { for (const QString& modelID : modelIDs) {
const FBXModel& fbxModel = fbxModels[modelID]; const FBXModel& fbxModel = fbxModels[modelID];
HFMJoint joint; HFMJoint joint;
@ -1378,13 +1376,8 @@ HFMModel* FBXSerializer::extractHFMModel(const hifi::VariantHash& mapping, const
transformNode.transform = Transform(localTransform); transformNode.transform = Transform(localTransform);
globalTransforms.push_back(globalTransform); globalTransforms.push_back(globalTransform);
hfmModel.transforms.push_back(transformNode); 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.bindExtents.reset();
hfmModel.meshExtents.reset(); hfmModel.meshExtents.reset();
@ -1482,35 +1475,37 @@ HFMModel* FBXSerializer::extractHFMModel(const hifi::VariantHash& mapping, const
} }
// For FBX_DRACO_MESH_VERSION < 2, or unbaked models, get materials from the partMaterialTextures // For FBX_DRACO_MESH_VERSION < 2, or unbaked models, get materials from the partMaterialTextures
int materialIndex = 0; if (!partMaterialTextures.empty()) {
int textureIndex = 0; int materialIndex = 0;
QList<QString> children = _connectionChildMap.values(modelID); int textureIndex = 0;
for (int i = children.size() - 1; i >= 0; i--) { QList<QString> children = _connectionChildMap.values(modelID);
const QString& childID = children.at(i); for (int i = children.size() - 1; i >= 0; i--) {
if (_hfmMaterials.contains(childID)) { const QString& childID = children.at(i);
// the pure material associated with this part if (_hfmMaterials.contains(childID)) {
const HFMMaterial& material = _hfmMaterials.value(childID); // the pure material associated with this part
for (int j = 0; j < partMaterialTextures.size(); j++) { const HFMMaterial& material = _hfmMaterials.value(childID);
if (partMaterialTextures.at(j).first == materialIndex) { for (int j = 0; j < partMaterialTextures.size(); j++) {
hfm::Shape& shape = partShapes[j]; if (partMaterialTextures.at(j).first == materialIndex) {
shape.material = materialNameToID[material.materialID.toStdString()]; hfm::Shape& shape = partShapes[j];
shape.material = materialNameToID[material.materialID.toStdString()];
}
} }
} materialIndex++;
materialIndex++; } else if (_textureFilenames.contains(childID)) {
} else if (_textureFilenames.contains(childID)) { // NOTE (Sabrina 2019/01/11): getTextures now takes in the materialID as a second parameter, because FBX material nodes can sometimes have uv transform information (ex: "Maya|uv_scale")
// NOTE (Sabrina 2019/01/11): getTextures now takes in the materialID as a second parameter, because FBX material nodes can sometimes have uv transform information (ex: "Maya|uv_scale") // I'm leaving the second parameter blank right now as this code may never be used.
// I'm leaving the second parameter blank right now as this code may never be used. HFMTexture texture = getTexture(childID, "");
HFMTexture texture = getTexture(childID, ""); for (int j = 0; j < partMaterialTextures.size(); j++) {
for (int j = 0; j < partMaterialTextures.size(); j++) { int partTexture = partMaterialTextures.at(j).second;
int partTexture = partMaterialTextures.at(j).second; if (partTexture == textureIndex && !(partTexture == 0 && materialsHaveTextures)) {
if (partTexture == textureIndex && !(partTexture == 0 && materialsHaveTextures)) { // TODO: DO something here that replaces this legacy code
// TODO: DO something here that replaces this legacy code // Maybe create a material just for this part with the correct textures?
// Maybe create a material just for this part with the correct textures? // material.albedoTexture = texture;
// material.albedoTexture = texture; // partShapes[j].material = materialIndex;
// partShapes[j].material = materialIndex; }
} }
textureIndex++;
} }
textureIndex++;
} }
} }
// 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

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 // load the draco mesh from the FBX and create a draco::Mesh
draco::Decoder decoder; draco::Decoder decoder;
draco::DecoderBuffer decodedBuffer; 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) { for (uint32_t i = 0; i < dracoMesh->num_faces(); ++i) {
// grab the material ID and texture ID for this face, if we have it // grab the material ID and texture ID for this face, if we have it
auto& dracoFace = dracoMesh->face(draco::FaceIndex(i)); auto& dracoFace = dracoMesh->face(draco::FaceIndex(i));
@ -489,18 +492,14 @@ 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 = extracted.mesh.parts.back(); HFMMeshPart& part = data.extracted.mesh.parts.back();
// Figure out what material this part is // 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()) {
extracted.materialIDPerMeshPart[materialID] = dracoMaterialList[materialID];
}
} 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);
} }
// in dracoMeshNodeVersion >= 2, fbx meshes have their per-part materials already defined in data.extracted.materialIDPerMeshPart
partIndexPlusOne = (int)data.extracted.mesh.parts.size(); partIndexPlusOne = (int)data.extracted.mesh.parts.size();
} }