Be strict about non representable translation, rotation and scale values.

This commit is contained in:
K. S. Ernest (iFire) Lee 2022-04-03 19:42:05 -07:00
parent 31752b14c5
commit 0c40c08662
1 changed files with 47 additions and 14 deletions

View File

@ -725,26 +725,59 @@ static void ReadNodeHierarchy(
// Set the initial node transform. // Set the initial node transform.
const FbxAMatrix localTransform = pNode->EvaluateLocalTransform(); const FbxAMatrix localTransform = pNode->EvaluateLocalTransform();
const FbxVector4 localTranslation = localTransform.GetT(); FbxVector4 localTranslation = localTransform.GetT();
const FbxQuaternion localRotation = localTransform.GetQ(); localTranslation.FixIncorrectValue();
const FbxVector4 localScaling = computeLocalScale(pNode); for (int32_t i = 0; i < 3; i++) {
if (localTranslation[i] < FBXSDK_FLOAT_MIN ||
localTranslation[i] > FBXSDK_FLOAT_MAX) {
localTranslation[i] = 0.0;
}
}
FbxQuaternion localRotation = localTransform.GetQ();
for (int32_t i = 0; i < 4; i++) {
if (localRotation[i] < FBXSDK_FLOAT_MIN ||
localRotation[i] > FBXSDK_FLOAT_MAX) {
localRotation[i] = 0.0;
}
}
FbxVector4 localScaling = computeLocalScale(pNode);
localScaling.FixIncorrectValue();
for (int32_t i = 0; i < 3; i++) {
if (localScaling[i] < FBXSDK_FLOAT_MIN ||
localScaling[i] > FBXSDK_FLOAT_MAX ||
abs(localScaling[i]) < FBXSDK_FLOAT_EPSILON) {
localScaling[i] = 1.0;
}
}
node.translation = toVec3f(localTranslation) * scaleFactor; node.translation = toVec3f(localTranslation) * scaleFactor;
node.rotation = toQuatf(localRotation); node.rotation = toQuatf(localRotation);
node.scale = toVec3f(localScaling); node.scale = toVec3f(localScaling);
const FbxVector4 nodeGeometricTranslationPivot = FbxVector4 nodeGeometricTranslationPivot = pNode->GetGeometricTranslation(FbxNode::eSourcePivot);
pNode->GetGeometricTranslation(FbxNode::eSourcePivot); nodeGeometricTranslationPivot.FixIncorrectValue();
const FbxVector4 nodeGeometricRotationPivot = pNode->GetGeometricRotation(FbxNode::eSourcePivot); for (int32_t i = 0; i < 3; i++) {
if (nodeGeometricTranslationPivot[i] < FBXSDK_FLOAT_MIN ||
nodeGeometricTranslationPivot[i] > FBXSDK_FLOAT_MAX) {
nodeGeometricTranslationPivot[i] = 0.0;
}
}
FbxVector4 nodeGeometricRotationPivot = pNode->GetGeometricRotation(FbxNode::eSourcePivot);
nodeGeometricRotationPivot.FixIncorrectValue();
for (int32_t i = 0; i < 3; i++) {
if (nodeGeometricRotationPivot[i] < FBXSDK_FLOAT_MIN ||
nodeGeometricRotationPivot[i] > FBXSDK_FLOAT_MAX) {
nodeGeometricRotationPivot[i] = 0.0;
}
}
FbxVector4 nodeGeometricScalePivot = pNode->GetGeometricScaling(FbxNode::eSourcePivot); FbxVector4 nodeGeometricScalePivot = pNode->GetGeometricScaling(FbxNode::eSourcePivot);
if (abs(nodeGeometricScalePivot[0]) < FBXSDK_FLOAT_EPSILON) { nodeGeometricScalePivot.FixIncorrectValue();
nodeGeometricScalePivot[0] = 1.0; for (int32_t i = 0; i < 3; i++) {
} if (nodeGeometricScalePivot[i] < FBXSDK_FLOAT_MIN ||
if (abs(nodeGeometricScalePivot[1]) < FBXSDK_FLOAT_EPSILON) { nodeGeometricScalePivot[i] > FBXSDK_FLOAT_MAX ||
nodeGeometricScalePivot[1] = 1.0; abs(nodeGeometricScalePivot[i]) < FBXSDK_FLOAT_EPSILON) {
} nodeGeometricScalePivot[i] = 1.0;
if (abs(nodeGeometricScalePivot[2]) < FBXSDK_FLOAT_EPSILON) { }
nodeGeometricScalePivot[2] = 1.0;
} }
FbxAMatrix matrixGeo; FbxAMatrix matrixGeo;
matrixGeo.SetIdentity(); matrixGeo.SetIdentity();