I've trying to build and rebuild a format for game engines, and when trying to put it back to Maya it gives weird results.
This is not really an error or anything of the sort, but the results from the animation are weird.
I really need to have it in Quaternion
in the format for the purposes of the engine since it handles it better than Euler axis
, but when trying to apply it to Maya I can't find a proper way to.
This is what i do since I can't really find a direct way of applying just Quaternion
:
arot_count = struct.unpack( "<L", f.read( 4 ) )[ 0 ] # Reads the number of animation frames
for i in range( 0, arot_count ):
keytime = ( struct.unpack( "<L", f.read( 4 ) )[ 0 ]/80 ) # Keyframe
arot = om.MQuaternion( struct.unpack( "f", f.read( 4 ) )[ 0 ], struct.unpack( "f", f.read( 4 )[ 0 ], struct.unpack( "f", f.read( 4 ) )[ 0 ], struct.unpack( "f", f.read( 4 ) )[ 0 ])# Reads quat from file
narot = arot.normal() # Normalizes the quaternion
rot = narot.asEulerRotation() # Converts it to euler angles
if isMesh == False:
cmds.setAttr( ( obj.name + ".rotate" ), rot.x * 180 / math.pi, rot.y * 180 / math.pi, rot.z * 180 / math.pi )
cmds.setKeyframe( obj.name, time = keytime )
Here's the result:
You can see it's easy to tell what is the animation doing but you can see those weird frames between that the arm or the leg goes of flying for a little moment and screws up the whole animation in general.
I believe this is because of the data loss of the conversion I did with the code. I basically normalised the Quaternion
(which actually does nothing since it gives the same result but a lot of people recommends to), then I convert it to Euler
angles from Maya API, and then I just pass the radians to degrees with good old math but this does not seem the way to go and may be the result of some data loss of the file.
What I wonder if there is a better way to apply the rotation in a keyframe than this, I would appreciate it a lot.
Thanks in advance.