Fix incorrect deg->radian conversion

It seems that rotation matrices later expect radians.
This conversion breaks it, and was validated on the conversion of
`cesium_man.glb` --> `cesium_man.fbx`
pull/5282/head
julianknodt 2023-10-15 22:03:31 -07:00 committed by Kim Kulling
parent 46b19cc6a4
commit 28ab0a094a
2 changed files with 15 additions and 16 deletions

View File

@ -577,16 +577,17 @@ void FBXConverter::GetRotationMatrix(Model::RotOrder mode, const aiVector3D &rot
bool is_id[3] = { true, true, true };
aiMatrix4x4 temp[3];
if (std::fabs(rotation.z) > angle_epsilon) {
aiMatrix4x4::RotationZ(AI_DEG_TO_RAD(rotation.z), temp[2]);
const auto rot = AI_DEG_TO_RAD(rotation);
if (std::fabs(rot.z) > angle_epsilon) {
aiMatrix4x4::RotationZ(rot.z, temp[2]);
is_id[2] = false;
}
if (std::fabs(rotation.y) > angle_epsilon) {
aiMatrix4x4::RotationY(AI_DEG_TO_RAD(rotation.y), temp[1]);
if (std::fabs(rot.y) > angle_epsilon) {
aiMatrix4x4::RotationY(rot.y, temp[1]);
is_id[1] = false;
}
if (std::fabs(rotation.x) > angle_epsilon) {
aiMatrix4x4::RotationX(AI_DEG_TO_RAD(rotation.x), temp[0]);
if (std::fabs(rot.x) > angle_epsilon) {
aiMatrix4x4::RotationX(rot.x, temp[0]);
is_id[0] = false;
}
@ -3225,7 +3226,6 @@ aiNodeAnim* FBXConverter::GenerateSimpleNodeAnim(const std::string& name,
aiVector3D defTranslate = PropertyGet(props, "Lcl Translation", aiVector3D(0.f, 0.f, 0.f));
aiVector3D defRotation = PropertyGet(props, "Lcl Rotation", aiVector3D(0.f, 0.f, 0.f));
aiVector3D defScale = PropertyGet(props, "Lcl Scaling", aiVector3D(1.f, 1.f, 1.f));
aiQuaternion defQuat = EulerToQuaternion(defRotation, rotOrder);
aiVectorKey* outTranslations = new aiVectorKey[keyCount];
aiQuatKey* outRotations = new aiQuatKey[keyCount];
@ -3241,8 +3241,9 @@ aiNodeAnim* FBXConverter::GenerateSimpleNodeAnim(const std::string& name,
}
if (keyframeLists[TransformationComp_Rotation].size() > 0) {
InterpolateKeys(outRotations, keytimes, keyframeLists[TransformationComp_Rotation], defRotation, maxTime, minTime, rotOrder);
InterpolateKeys(outRotations, keytimes, keyframeLists[TransformationComp_Rotation], AI_DEG_TO_RAD(defRotation), maxTime, minTime, rotOrder);
} else {
aiQuaternion defQuat = EulerToQuaternion(AI_DEG_TO_RAD(defRotation), rotOrder);
for (size_t i = 0; i < keyCount; ++i) {
outRotations[i].mTime = CONVERT_FBX_TIME(keytimes[i]) * anim_fps;
outRotations[i].mValue = defQuat;
@ -3264,7 +3265,7 @@ aiNodeAnim* FBXConverter::GenerateSimpleNodeAnim(const std::string& name,
const aiVector3D& preRotation = PropertyGet<aiVector3D>(props, "PreRotation", ok);
if (ok && preRotation.SquareLength() > zero_epsilon) {
const aiQuaternion preQuat = EulerToQuaternion(preRotation, Model::RotOrder_EulerXYZ);
const aiQuaternion preQuat = EulerToQuaternion(AI_DEG_TO_RAD(preRotation), Model::RotOrder_EulerXYZ);
for (size_t i = 0; i < keyCount; ++i) {
outRotations[i].mValue = preQuat * outRotations[i].mValue;
}
@ -3272,7 +3273,7 @@ aiNodeAnim* FBXConverter::GenerateSimpleNodeAnim(const std::string& name,
const aiVector3D& postRotation = PropertyGet<aiVector3D>(props, "PostRotation", ok);
if (ok && postRotation.SquareLength() > zero_epsilon) {
const aiQuaternion postQuat = EulerToQuaternion(postRotation, Model::RotOrder_EulerXYZ);
const aiQuaternion postQuat = EulerToQuaternion(AI_DEG_TO_RAD(postRotation), Model::RotOrder_EulerXYZ);
for (size_t i = 0; i < keyCount; ++i) {
outRotations[i].mValue = outRotations[i].mValue * postQuat;
}

View File

@ -74,8 +74,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// https://code.blender.org/2013/08/fbx-binary-file-format-specification/
// https://wiki.blender.org/index.php/User:Mont29/Foundation/FBX_File_Structure
const ai_real DEG = ai_real( 57.29577951308232087679815481 ); // degrees per radian
using namespace Assimp;
using namespace Assimp::FBX;
@ -2434,7 +2432,7 @@ void FBXExporter::WriteObjects ()
aiMatrix4x4 m(k.mValue.GetMatrix());
aiVector3D qs, qr, qt;
m.Decompose(qs, qr, qt);
qr *= DEG;
qr = AI_RAD_TO_DEG(qr);
xval.push_back(qr.x);
yval.push_back(qr.y);
zval.push_back(qr.z);
@ -2515,9 +2513,10 @@ void FBXExporter::WriteModelNode(
);
}
if (r != zero) {
r = AI_RAD_TO_DEG(r);
p.AddP70(
"Lcl Rotation", "Lcl Rotation", "", "A",
double(DEG*r.x), double(DEG*r.y), double(DEG*r.z)
double(r.x), double(r.y), double(r.z)
);
}
if (s != one) {
@ -2601,8 +2600,7 @@ void FBXExporter::WriteModelNodes(
transform_chain.emplace_back(elem->first, t);
break;
case 'r': // rotation
r *= float(DEG);
transform_chain.emplace_back(elem->first, r);
transform_chain.emplace_back(elem->first, AI_RAD_TO_DEG(r));
break;
case 's': // scale
transform_chain.emplace_back(elem->first, s);