Fix geometric pivots.
This commit is contained in:
parent
43fc8b3552
commit
c8eb9b2f55
|
@ -9,7 +9,7 @@ from conans import ConanFile, CMake
|
||||||
class FBX2glTFConan(ConanFile):
|
class FBX2glTFConan(ConanFile):
|
||||||
settings = "os", "compiler", "build_type", "arch"
|
settings = "os", "compiler", "build_type", "arch"
|
||||||
requires = (
|
requires = (
|
||||||
("boost/1.76.0"),
|
("boost/1.78.0"),
|
||||||
("libiconv/1.15"),
|
("libiconv/1.15"),
|
||||||
("zlib/1.2.11"),
|
("zlib/1.2.11"),
|
||||||
("libxml2/2.9.12"),
|
("libxml2/2.9.12"),
|
||||||
|
|
|
@ -733,8 +733,31 @@ static void ReadNodeHierarchy(
|
||||||
node.rotation = toQuatf(localRotation);
|
node.rotation = toQuatf(localRotation);
|
||||||
node.scale = toVec3f(localScaling);
|
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) {
|
if (parentId) {
|
||||||
RawNode& parentNode = raw.GetNode(raw.GetNodeById(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.
|
// Add unique child name to the parent node.
|
||||||
if (std::find(parentNode.childIds.begin(), parentNode.childIds.end(), nodeId) ==
|
if (std::find(parentNode.childIds.begin(), parentNode.childIds.end(), nodeId) ==
|
||||||
parentNode.childIds.end()) {
|
parentNode.childIds.end()) {
|
||||||
|
@ -744,9 +767,14 @@ static void ReadNodeHierarchy(
|
||||||
// If there is no parent then this is the root node.
|
// If there is no parent then this is the root node.
|
||||||
raw.SetRootNode(nodeId);
|
raw.SetRootNode(nodeId);
|
||||||
}
|
}
|
||||||
|
matrixGeo = matrixGeo.Inverse();
|
||||||
for (int child = 0; child < pNode->GetChildCount(); child++) {
|
for (int child = 0; child < pNode->GetChildCount(); child++) {
|
||||||
ReadNodeHierarchy(raw, pScene, pNode->GetChild(child), nodeId, newPath);
|
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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue