Fix geometric pivots.

This commit is contained in:
K. S. Ernest (iFire) Lee 2022-04-03 14:47:32 -07:00
parent 43fc8b3552
commit c8eb9b2f55
2 changed files with 30 additions and 2 deletions

View File

@ -9,7 +9,7 @@ from conans import ConanFile, CMake
class FBX2glTFConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
requires = (
("boost/1.76.0"),
("boost/1.78.0"),
("libiconv/1.15"),
("zlib/1.2.11"),
("libxml2/2.9.12"),

View File

@ -733,8 +733,31 @@ static void ReadNodeHierarchy(
node.rotation = toQuatf(localRotation);
node.scale = toVec3f(localScaling);
const FbxVector4 nodeGeometricTranslationPivot =
pNode->GetGeometricTranslation(FbxNode::eSourcePivot);
const FbxVector4 nodeGeometricRotationPivot = pNode->GetGeometricRotation(FbxNode::eSourcePivot);
FbxVector4 nodeGeometricScalePivot = pNode->GetGeometricScaling(FbxNode::eSourcePivot);
if (abs(nodeGeometricScalePivot[0]) < FBXSDK_FLOAT_EPSILON) {
nodeGeometricScalePivot[0] = 1.0;
}
if (abs(nodeGeometricScalePivot[1]) < FBXSDK_FLOAT_EPSILON) {
nodeGeometricScalePivot[1] = 1.0;
}
if (abs(nodeGeometricScalePivot[2]) < FBXSDK_FLOAT_EPSILON) {
nodeGeometricScalePivot[2] = 1.0;
}
FbxAMatrix matrixGeo;
matrixGeo.SetIdentity();
matrixGeo.SetT(nodeGeometricTranslationPivot);
matrixGeo.SetR(nodeGeometricRotationPivot);
matrixGeo.SetS(nodeGeometricScalePivot);
if (parentId) {
RawNode& parentNode = raw.GetNode(raw.GetNodeById(parentId));
parentNode.translation += toVec3f(matrixGeo.GetT());
const FbxQuaternion nodeRotation = matrixGeo.GetQ();
parentNode.rotation = parentNode.rotation * toQuatf(nodeRotation);
parentNode.scale *= toVec3f(matrixGeo.GetS());
// Add unique child name to the parent node.
if (std::find(parentNode.childIds.begin(), parentNode.childIds.end(), nodeId) ==
parentNode.childIds.end()) {
@ -744,9 +767,14 @@ static void ReadNodeHierarchy(
// If there is no parent then this is the root node.
raw.SetRootNode(nodeId);
}
matrixGeo = matrixGeo.Inverse();
for (int child = 0; child < pNode->GetChildCount(); child++) {
ReadNodeHierarchy(raw, pScene, pNode->GetChild(child), nodeId, newPath);
RawNode& childNode = raw.GetNode(child);
childNode.translation += toVec3f(matrixGeo.GetT());
const FbxQuaternion nodeRotation = matrixGeo.GetQ();
childNode.rotation = childNode.rotation * toQuatf(nodeRotation);
childNode.scale *= toVec3f(matrixGeo.GetS());
}
}