Skip to content

Commit f443792

Browse files
authored
Merge pull request #515 from Unity-Technologies/UT-3389-fix-bone-position-lost-on-export
UT-3389 export bones in original position instead of bindpose
2 parents 11ca5b7 + 1281b0e commit f443792

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

com.unity.formats.fbx/Editor/FbxExporter.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,31 @@ SkinnedMeshRenderer unitySkin
955955

956956
// add bind pose
957957
ExportBindPose (unitySkin, fbxNode, fbxScene, skinnedMeshToBonesMap);
958+
959+
// now that the skin and bindpose are set, make sure that each of the bones
960+
// is set to its original position
961+
var bones = unitySkin.bones;
962+
foreach (var bone in bones)
963+
{
964+
var fbxBone = MapUnityObjectToFbxNode[bone.gameObject];
965+
ExportTransform(bone, fbxBone, newCenter: Vector3.zero, TransformExportType.Local);
966+
967+
// Cancel out the pre-rotation from the exported rotation
968+
969+
// Get prerotation
970+
var fbxPreRotationEuler = fbxBone.GetPreRotation(FbxNode.EPivotSet.eSourcePivot);
971+
// Convert the prerotation to a Quaternion
972+
var fbxPreRotationQuaternion = EulerToQuaternion(fbxPreRotationEuler);
973+
// Inverse of the prerotation
974+
fbxPreRotationQuaternion.Inverse();
975+
976+
// Multiply LclRotation by pre-rotation inverse to get the LclRotation without pre-rotation applied
977+
var finalLclRotationQuat = fbxPreRotationQuaternion * EulerToQuaternion(new FbxVector4(fbxBone.LclRotation.Get()));
978+
979+
// Convert to Euler without axis conversion (Pre-rotation and LclRotation were already in Maya axis)
980+
// and update LclRotation
981+
fbxBone.LclRotation.Set(ToFbxDouble3(QuaternionToEuler(finalLclRotationQuat)));
982+
}
958983
}
959984

960985
return true;

0 commit comments

Comments
 (0)