c#: converting MAYA rotation (yUp, right handed, xyz order) to UNITY rotation (yUp, left handed, zxy order)

2.2k Views Asked by At

I sadly don't have experience in matrix / euler calculations, but need to solve the following in c#, in Unity to the orientations match.

convert:

3 floats (orientation) of an object originating from Maya (yUp, right handed, xyz rotation order)

to: quaternion rotation in Unity (yUp, left handed, zxy rotation order)

any input most welcome! m.

2

There are 2 best solutions below

3
On

Quaternions can be used to represent the orientation or rotation of an object. It depends on the Pivot of the GameObject. take a look here

0
On

Ok, I got the solution, with a hint to the following thread by a friend: https://forum.unity3d.com/threads/right-hand-to-left-handed-conversions.80679/ The solution is posted by the user by the 'guavaman'.

The code I'm now using is of this structure:

  • // translation
  • var unityPosition = new Vector3(-maya_translation.x, maya_translation.y, maya_translation.z);
  • // rotation
  • var flippedRotation = new Vector3(maya_euler_rotation.x, -maya_euler_rotation.y, -maya_euler_rotation.z);
  • var qx = Quaternion.AngleAxis(flippedRotation.x, Vector3.right);
  • var qy = Quaternion.AngleAxis(flippedRotation.y, Vector3.up);
  • var qz = Quaternion.AngleAxis(flippedRotation.z, Vector3.forward);
  • var unityRotationQuaternion = qz * qy * qx; // exact order!
  • // scale
  • var unityScaling = new Vector3(maya_scale.x, maya_scale.y, maya_scale.z);

Thanks for all the inputs and to 'guavaman'.