From 7c7e632589eb25608c82a830ebaf9931672d32e4 Mon Sep 17 00:00:00 2001 From: amantley Date: Mon, 11 Mar 2019 17:50:20 -0700 Subject: [PATCH 1/4] debug statements to find the node parsing error --- libraries/animation/src/AnimClip.cpp | 2 +- libraries/fbx/src/FBXSerializer.cpp | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/libraries/animation/src/AnimClip.cpp b/libraries/animation/src/AnimClip.cpp index 4fe02e9307..5d846a8f84 100644 --- a/libraries/animation/src/AnimClip.cpp +++ b/libraries/animation/src/AnimClip.cpp @@ -154,7 +154,7 @@ void AnimClip::copyFromNetworkAnim() { const float avatarToAnimationHeightRatio = avatarHeightInMeters / animHeightInMeters; const float unitsRatio = 1.0f / (avatarUnitScale / animationUnitScale); const float parentScaleRatio = 1.0f / (avatarHipsParentScale / animHipsParentScale); - + qCDebug(animation) << " avatar unit scale " << avatarUnitScale << " animation unit scale " << animationUnitScale << " avatar height " << avatarHeightInMeters << " animation height " << animHeightInMeters << " avatar scale " << avatarHipsParentScale << " animation scale " << animHipsParentScale; boneLengthScale = avatarToAnimationHeightRatio * unitsRatio * parentScaleRatio; } diff --git a/libraries/fbx/src/FBXSerializer.cpp b/libraries/fbx/src/FBXSerializer.cpp index 5246242a1e..e6e3d73815 100644 --- a/libraries/fbx/src/FBXSerializer.cpp +++ b/libraries/fbx/src/FBXSerializer.cpp @@ -142,6 +142,7 @@ glm::mat4 getGlobalTransform(const QMultiMap& _connectionParen visitedNodes.append(nodeID); // Append each node we visit const FBXModel& fbxModel = fbxModels.value(nodeID); + qCDebug(modelformat) << "this fbx model name is " << fbxModel.name; globalTransform = glm::translate(fbxModel.translation) * fbxModel.preTransform * glm::mat4_cast(fbxModel.preRotation * fbxModel.rotation * fbxModel.postRotation) * fbxModel.postTransform * globalTransform; if (fbxModel.hasGeometricOffset) { @@ -201,13 +202,23 @@ public: void appendModelIDs(const QString& parentID, const QMultiMap& connectionChildMap, QHash& fbxModels, QSet& remainingModels, QVector& modelIDs, bool isRootNode = false) { if (remainingModels.contains(parentID)) { + qCDebug(modelformat) << " remaining models contains parent " << parentID; modelIDs.append(parentID); remainingModels.remove(parentID); } - int parentIndex = isRootNode ? -1 : modelIDs.size() - 1; + int parentIndex = 1000; + if (isRootNode) { + qCDebug(modelformat) << " found a root node " << parentID; + parentIndex = -1; + } else { + parentIndex = modelIDs.size() - 1; + } + //int parentIndex = isRootNode ? -1 : modelIDs.size() - 1; foreach (const QString& childID, connectionChildMap.values(parentID)) { + qCDebug(modelformat) << " searching children, parent id " << parentID; if (remainingModels.contains(childID)) { FBXModel& fbxModel = fbxModels[childID]; + qCDebug(modelformat) << " child id " << fbxModel.name; if (fbxModel.parentIndex == -1) { fbxModel.parentIndex = parentIndex; appendModelIDs(childID, connectionChildMap, fbxModels, remainingModels, modelIDs); @@ -441,6 +452,7 @@ HFMModel* FBXSerializer::extractHFMModel(const QVariantHash& mapping, const QStr QString hifiGlobalNodeID; unsigned int meshIndex = 0; haveReportedUnhandledRotationOrder = false; + int nodeParentId = -1; foreach (const FBXNode& child, node.children) { if (child.name == "FBXHeaderExtension") { @@ -497,6 +509,7 @@ HFMModel* FBXSerializer::extractHFMModel(const QVariantHash& mapping, const QStr } } else if (child.name == "Objects") { foreach (const FBXNode& object, child.children) { + nodeParentId++; if (object.name == "Geometry") { if (object.properties.at(2) == "Mesh") { meshes.insert(getID(object.properties), extractMesh(object, meshIndex)); @@ -505,6 +518,7 @@ HFMModel* FBXSerializer::extractHFMModel(const QVariantHash& mapping, const QStr blendshapes.append(extracted); } } else if (object.name == "Model") { + qCDebug(modelformat) << "model name from object properties " << getName(object.properties) << " node parentID " << nodeParentId; QString name = getName(object.properties); QString id = getID(object.properties); modelIDsToNames.insert(id, name); @@ -1181,6 +1195,7 @@ HFMModel* FBXSerializer::extractHFMModel(const QVariantHash& mapping, const QStr #endif } + // TODO: check if is code is needed if (!lights.empty()) { if (hifiGlobalNodeID.isEmpty()) { @@ -1211,6 +1226,7 @@ HFMModel* FBXSerializer::extractHFMModel(const QVariantHash& mapping, const QStr for (QHash::const_iterator fbxModel = fbxModels.constBegin(); fbxModel != fbxModels.constEnd(); fbxModel++) { // models with clusters must be parented to the cluster top // Unless the model is a root node. + qCDebug(modelformat) << "fbx model name " << fbxModel.key(); bool isARootNode = !modelIDs.contains(_connectionParentMap.value(fbxModel.key())); if (!isARootNode) { foreach(const QString& deformerID, _connectionChildMap.values(fbxModel.key())) { @@ -1266,6 +1282,8 @@ HFMModel* FBXSerializer::extractHFMModel(const QVariantHash& mapping, const QStr joint.parentIndex = fbxModel.parentIndex; int jointIndex = hfmModel.joints.size(); + qCDebug(modelformat) << "fbx joint name " << fbxModel.name << " joint index " << jointIndex << " parent index " << joint.parentIndex; + joint.translation = fbxModel.translation; // these are usually in centimeters joint.preTransform = fbxModel.preTransform; joint.preRotation = fbxModel.preRotation; From 7567e0d355b8ac58ae6b40f1c9c7953465f128d0 Mon Sep 17 00:00:00 2001 From: amantley Date: Tue, 12 Mar 2019 15:48:42 -0700 Subject: [PATCH 2/4] debugging the root of the fbx, it is not 0 in some cases --- libraries/fbx/src/FBXSerializer.cpp | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/libraries/fbx/src/FBXSerializer.cpp b/libraries/fbx/src/FBXSerializer.cpp index e6e3d73815..f91eeb6519 100644 --- a/libraries/fbx/src/FBXSerializer.cpp +++ b/libraries/fbx/src/FBXSerializer.cpp @@ -508,6 +508,7 @@ HFMModel* FBXSerializer::extractHFMModel(const QVariantHash& mapping, const QStr } } } else if (child.name == "Objects") { + //qCDebug(modelformat) << " the root model id is " << getID(child.properties); foreach (const FBXNode& object, child.children) { nodeParentId++; if (object.name == "Geometry") { @@ -1169,8 +1170,19 @@ HFMModel* FBXSerializer::extractHFMModel(const QVariantHash& mapping, const QStr counter++; } } - _connectionParentMap.insert(getID(connection.properties, 1), getID(connection.properties, 2)); - _connectionChildMap.insert(getID(connection.properties, 2), getID(connection.properties, 1)); + + if ("2830302416448" == getID(connection.properties, 1) || "2830302416448" == getID(connection.properties, 2)) { + if ("2829544143536" == getID(connection.properties, 1)) { + _connectionParentMap.insert(getID(connection.properties, 1), "0"); + _connectionChildMap.insert("0", getID(connection.properties, 1)); + } + qCDebug(modelformat) << " parent map inserted with id " << getID(connection.properties, 1) << " name " << modelIDsToNames.value(getID(connection.properties, 1)) << " id " << getID(connection.properties, 2) << " name " << modelIDsToNames.value(getID(connection.properties, 2)); + } else { + _connectionParentMap.insert(getID(connection.properties, 1), getID(connection.properties, 2)); + _connectionChildMap.insert(getID(connection.properties, 2), getID(connection.properties, 1)); + } + + // qCDebug(modelformat) << " child map inserted with id " << getID(connection.properties, 2) << " name " << modelIDsToNames.value(getID(connection.properties, 2)) << " id " << getID(connection.properties, 1) << " name " << modelIDsToNames.value(getID(connection.properties, 1)); } } } @@ -1220,13 +1232,16 @@ HFMModel* FBXSerializer::extractHFMModel(const QVariantHash& mapping, const QStr mapping.value("tz").toFloat())) * glm::mat4_cast(offsetRotation) * glm::scale(glm::vec3(offsetScale, offsetScale, offsetScale)); + for (QHash::const_iterator modelIDPair = modelIDsToNames.constBegin(); modelIDPair != modelIDsToNames.constEnd(); modelIDPair++) { + qCDebug(modelformat) << " model ID " << modelIDPair.key() << " name " << modelIDPair.value(); + } + // get the list of models in depth-first traversal order QVector modelIDs; QSet remainingFBXModels; for (QHash::const_iterator fbxModel = fbxModels.constBegin(); fbxModel != fbxModels.constEnd(); fbxModel++) { // models with clusters must be parented to the cluster top // Unless the model is a root node. - qCDebug(modelformat) << "fbx model name " << fbxModel.key(); bool isARootNode = !modelIDs.contains(_connectionParentMap.value(fbxModel.key())); if (!isARootNode) { foreach(const QString& deformerID, _connectionChildMap.values(fbxModel.key())) { @@ -1235,6 +1250,7 @@ HFMModel* FBXSerializer::extractHFMModel(const QVariantHash& mapping, const QStr continue; } QString topID = getTopModelID(_connectionParentMap, fbxModels, _connectionChildMap.value(clusterID), url); + qCDebug(modelformat) << "fbx model name " << fbxModel.value().name << " top id " << topID << " modelID " << fbxModel.key(); _connectionChildMap.remove(_connectionParentMap.take(fbxModel.key()), fbxModel.key()); _connectionParentMap.insert(fbxModel.key(), topID); goto outerBreak; @@ -1258,6 +1274,8 @@ HFMModel* FBXSerializer::extractHFMModel(const QVariantHash& mapping, const QStr } } QString topID = getTopModelID(_connectionParentMap, fbxModels, first, url); + qCDebug(modelformat) << "topper name fbx name " << modelIDsToNames.value(first) << " top id " << topID << " top name " << modelIDsToNames.value(topID); + qCDebug(modelformat) << "parent id " << _connectionParentMap.value(topID) << " parent name " << modelIDsToNames.value(_connectionParentMap.value(topID)) << " remaining models parent value " << remainingFBXModels.contains(_connectionParentMap.value(topID)); appendModelIDs(_connectionParentMap.value(topID), _connectionChildMap, fbxModels, remainingFBXModels, modelIDs, true); } From 93d7a4ae3b4ade0ac97017ee4737622cad825f5c Mon Sep 17 00:00:00 2001 From: amantley Date: Wed, 13 Mar 2019 11:14:15 -0700 Subject: [PATCH 3/4] will no longer allow a non-zero parent of the root of an fbx model --- libraries/animation/src/AnimClip.cpp | 2 +- libraries/fbx/src/FBXSerializer.cpp | 39 +++------------------------- 2 files changed, 5 insertions(+), 36 deletions(-) diff --git a/libraries/animation/src/AnimClip.cpp b/libraries/animation/src/AnimClip.cpp index 5d846a8f84..4fe02e9307 100644 --- a/libraries/animation/src/AnimClip.cpp +++ b/libraries/animation/src/AnimClip.cpp @@ -154,7 +154,7 @@ void AnimClip::copyFromNetworkAnim() { const float avatarToAnimationHeightRatio = avatarHeightInMeters / animHeightInMeters; const float unitsRatio = 1.0f / (avatarUnitScale / animationUnitScale); const float parentScaleRatio = 1.0f / (avatarHipsParentScale / animHipsParentScale); - qCDebug(animation) << " avatar unit scale " << avatarUnitScale << " animation unit scale " << animationUnitScale << " avatar height " << avatarHeightInMeters << " animation height " << animHeightInMeters << " avatar scale " << avatarHipsParentScale << " animation scale " << animHipsParentScale; + boneLengthScale = avatarToAnimationHeightRatio * unitsRatio * parentScaleRatio; } diff --git a/libraries/fbx/src/FBXSerializer.cpp b/libraries/fbx/src/FBXSerializer.cpp index c542eef6a6..4bb499bd84 100644 --- a/libraries/fbx/src/FBXSerializer.cpp +++ b/libraries/fbx/src/FBXSerializer.cpp @@ -142,7 +142,6 @@ glm::mat4 getGlobalTransform(const QMultiMap& _connectionParen visitedNodes.append(nodeID); // Append each node we visit const FBXModel& fbxModel = fbxModels.value(nodeID); - qCDebug(modelformat) << "this fbx model name is " << fbxModel.name; globalTransform = glm::translate(fbxModel.translation) * fbxModel.preTransform * glm::mat4_cast(fbxModel.preRotation * fbxModel.rotation * fbxModel.postRotation) * fbxModel.postTransform * globalTransform; if (fbxModel.hasGeometricOffset) { @@ -202,23 +201,13 @@ public: void appendModelIDs(const QString& parentID, const QMultiMap& connectionChildMap, QHash& fbxModels, QSet& remainingModels, QVector& modelIDs, bool isRootNode = false) { if (remainingModels.contains(parentID)) { - qCDebug(modelformat) << " remaining models contains parent " << parentID; modelIDs.append(parentID); remainingModels.remove(parentID); } - int parentIndex = 1000; - if (isRootNode) { - qCDebug(modelformat) << " found a root node " << parentID; - parentIndex = -1; - } else { - parentIndex = modelIDs.size() - 1; - } - //int parentIndex = isRootNode ? -1 : modelIDs.size() - 1; + int parentIndex = isRootNode ? -1 : modelIDs.size() - 1; foreach (const QString& childID, connectionChildMap.values(parentID)) { - qCDebug(modelformat) << " searching children, parent id " << parentID; if (remainingModels.contains(childID)) { FBXModel& fbxModel = fbxModels[childID]; - qCDebug(modelformat) << " child id " << fbxModel.name; if (fbxModel.parentIndex == -1) { fbxModel.parentIndex = parentIndex; appendModelIDs(childID, connectionChildMap, fbxModels, remainingModels, modelIDs); @@ -452,7 +441,6 @@ HFMModel* FBXSerializer::extractHFMModel(const QVariantHash& mapping, const QStr QString hifiGlobalNodeID; unsigned int meshIndex = 0; haveReportedUnhandledRotationOrder = false; - int nodeParentId = -1; foreach (const FBXNode& child, node.children) { if (child.name == "FBXHeaderExtension") { @@ -508,9 +496,7 @@ HFMModel* FBXSerializer::extractHFMModel(const QVariantHash& mapping, const QStr } } } else if (child.name == "Objects") { - //qCDebug(modelformat) << " the root model id is " << getID(child.properties); foreach (const FBXNode& object, child.children) { - nodeParentId++; if (object.name == "Geometry") { if (object.properties.at(2) == "Mesh") { meshes.insert(getID(object.properties), extractMesh(object, meshIndex)); @@ -519,7 +505,6 @@ HFMModel* FBXSerializer::extractHFMModel(const QVariantHash& mapping, const QStr blendshapes.append(extracted); } } else if (object.name == "Model") { - qCDebug(modelformat) << "model name from object properties " << getName(object.properties) << " node parentID " << nodeParentId; QString name = getName(object.properties); QString id = getID(object.properties); modelIDsToNames.insert(id, name); @@ -1174,19 +1159,13 @@ HFMModel* FBXSerializer::extractHFMModel(const QVariantHash& mapping, const QStr counter++; } } - - if ("2830302416448" == getID(connection.properties, 1) || "2830302416448" == getID(connection.properties, 2)) { - if ("2829544143536" == getID(connection.properties, 1)) { - _connectionParentMap.insert(getID(connection.properties, 1), "0"); - _connectionChildMap.insert("0", getID(connection.properties, 1)); - } - qCDebug(modelformat) << " parent map inserted with id " << getID(connection.properties, 1) << " name " << modelIDsToNames.value(getID(connection.properties, 1)) << " id " << getID(connection.properties, 2) << " name " << modelIDsToNames.value(getID(connection.properties, 2)); + if (_connectionParentMap.value(getID(connection.properties, 1)) == "0") { + // don't assign the new parent + qCDebug(modelformat) << "root node " << getID(connection.properties, 1) << " has discarded parent " << getID(connection.properties, 2); } else { _connectionParentMap.insert(getID(connection.properties, 1), getID(connection.properties, 2)); _connectionChildMap.insert(getID(connection.properties, 2), getID(connection.properties, 1)); } - - // qCDebug(modelformat) << " child map inserted with id " << getID(connection.properties, 2) << " name " << modelIDsToNames.value(getID(connection.properties, 2)) << " id " << getID(connection.properties, 1) << " name " << modelIDsToNames.value(getID(connection.properties, 1)); } } } @@ -1211,7 +1190,6 @@ HFMModel* FBXSerializer::extractHFMModel(const QVariantHash& mapping, const QStr #endif } - // TODO: check if is code is needed if (!lights.empty()) { if (hifiGlobalNodeID.isEmpty()) { @@ -1236,10 +1214,6 @@ HFMModel* FBXSerializer::extractHFMModel(const QVariantHash& mapping, const QStr mapping.value("tz").toFloat())) * glm::mat4_cast(offsetRotation) * glm::scale(glm::vec3(offsetScale, offsetScale, offsetScale)); - for (QHash::const_iterator modelIDPair = modelIDsToNames.constBegin(); modelIDPair != modelIDsToNames.constEnd(); modelIDPair++) { - qCDebug(modelformat) << " model ID " << modelIDPair.key() << " name " << modelIDPair.value(); - } - // get the list of models in depth-first traversal order QVector modelIDs; QSet remainingFBXModels; @@ -1254,7 +1228,6 @@ HFMModel* FBXSerializer::extractHFMModel(const QVariantHash& mapping, const QStr continue; } QString topID = getTopModelID(_connectionParentMap, fbxModels, _connectionChildMap.value(clusterID), url); - qCDebug(modelformat) << "fbx model name " << fbxModel.value().name << " top id " << topID << " modelID " << fbxModel.key(); _connectionChildMap.remove(_connectionParentMap.take(fbxModel.key()), fbxModel.key()); _connectionParentMap.insert(fbxModel.key(), topID); goto outerBreak; @@ -1278,8 +1251,6 @@ HFMModel* FBXSerializer::extractHFMModel(const QVariantHash& mapping, const QStr } } QString topID = getTopModelID(_connectionParentMap, fbxModels, first, url); - qCDebug(modelformat) << "topper name fbx name " << modelIDsToNames.value(first) << " top id " << topID << " top name " << modelIDsToNames.value(topID); - qCDebug(modelformat) << "parent id " << _connectionParentMap.value(topID) << " parent name " << modelIDsToNames.value(_connectionParentMap.value(topID)) << " remaining models parent value " << remainingFBXModels.contains(_connectionParentMap.value(topID)); appendModelIDs(_connectionParentMap.value(topID), _connectionChildMap, fbxModels, remainingFBXModels, modelIDs, true); } @@ -1304,8 +1275,6 @@ HFMModel* FBXSerializer::extractHFMModel(const QVariantHash& mapping, const QStr joint.parentIndex = fbxModel.parentIndex; int jointIndex = hfmModel.joints.size(); - qCDebug(modelformat) << "fbx joint name " << fbxModel.name << " joint index " << jointIndex << " parent index " << joint.parentIndex; - joint.translation = fbxModel.translation; // these are usually in centimeters joint.preTransform = fbxModel.preTransform; joint.preRotation = fbxModel.preRotation; From 9d739277c8a358376532ded6156d587ca638871b Mon Sep 17 00:00:00 2001 From: amantley Date: Wed, 13 Mar 2019 14:26:27 -0700 Subject: [PATCH 4/4] changed the fix so that we allow the root to be child --- libraries/fbx/src/FBXSerializer.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries/fbx/src/FBXSerializer.cpp b/libraries/fbx/src/FBXSerializer.cpp index 4bb499bd84..f4eb1d57d9 100644 --- a/libraries/fbx/src/FBXSerializer.cpp +++ b/libraries/fbx/src/FBXSerializer.cpp @@ -1162,6 +1162,7 @@ HFMModel* FBXSerializer::extractHFMModel(const QVariantHash& mapping, const QStr if (_connectionParentMap.value(getID(connection.properties, 1)) == "0") { // don't assign the new parent qCDebug(modelformat) << "root node " << getID(connection.properties, 1) << " has discarded parent " << getID(connection.properties, 2); + _connectionChildMap.insert(getID(connection.properties, 2), getID(connection.properties, 1)); } else { _connectionParentMap.insert(getID(connection.properties, 1), getID(connection.properties, 2)); _connectionChildMap.insert(getID(connection.properties, 2), getID(connection.properties, 1));