0

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:

Walking anim

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.

Andy Jazz
  • 49,178
  • 17
  • 136
  • 220
Seyren Windsor
  • 115
  • 1
  • 2
  • 12

1 Answers1

0

You might try running the maya Euler Filter on your animated character; since quaternion to euler conversion is not deterministic you can't be sure that the eulerization for one frame is in the same quadrant as the one for the next, and the interpolation is wacky.

https://www.youtube.com/watch?v=zo0xhw1B2dE

theodox
  • 12,028
  • 3
  • 23
  • 36
  • Although it totally looks this is the case, apparently it is not for some reason, and it's not that a key is set in the weird frame. I will have to keep looking for other solutions, but this is actually really helpful for making my animations, thanks a lot :). – Seyren Windsor Sep 02 '15 at 13:03