Expressions/Scripts/Presets

Moderator: Paul Tuersley

urbanspaceman
Topic Author
Posts: 54
Joined: Wed Dec 12, 2007 9:56 am
Location: London
Contact:

### AE camera to Maya -- still trouble with 3D rotations.

I thought I'd solved it...Dan helped me to create my AE camera bake script, and I thought I was on my way to sharing my AE camera with Maya. I've tried to do this on and off for years...there's been many times when I would do animatics in AE and then ask a 3D animator to recreate my camera moves. It's always a loss of time because I can't just transfer the camera over. I seem to be one of the few people around who prefer this workflow.

Once I had a baked AE camera, I thought it was a matter of just using MoCon ( http://3dmation.com ) and success would be in my grasp. But, I soon found out that the author's script only works with one rotation axis rendered at a time.

I don't really know how to do complex matrix math to convert 3D rotations, so I could sure use help with this. If I could convert AE XYZ rotation values into Maya's YXZ rotation values (I THINK I have that right) then the camera might be pointing in the right direction in Maya. I realize you can change the order in Maya, but my 3D animator hasn't had success with this yet.

urbanspaceman
Topic Author
Posts: 54
Joined: Wed Dec 12, 2007 9:56 am
Location: London
Contact:

### Re: AE camera to Maya -- still trouble with 3D rotations.

I'm back a month later, having beefed up my algebra, and I finally have a handle on this problem. 3D rotations are much more complicated than I thought.

For anyone new to this, I'll give a quick explanation. The system of rotation most animators are familiar with, represented by degrees about the XYZ axes, is only one of many mathematical representations possible. The advantage to this system, called Euler angles, is that you only need 3 numbers to represent rotation. The disadvantage is that if the axes are rotated in different orders the same numbers actually could get confused with your object pointing in entirely different directions. This is what cropped up in transferring the AE camera to Maya. Maya's default rotation is ZYX, the exact opposite of AE's default rotation, which is XYZ.

So how do you translate one into the other?

The first part of the answer is to change rotation into a representation where a set of numbers always means your object is pointing in such and such a direction with no confusion. It turns out, I've learned, that your animation program is doing this behind the scenes anyway. To do this, we need more numbers than 3. Euler representations can be converted into 3x3, 9 number matrix notations.

The rest rotation we usually think of as

[0,0,0]

looks like this

|1,0,0|
|0,1,0|
|0,0,1|

So the trick in converting XYZ rotation into ZYX rotation is to convert to the matrix notation in between, going XYZ --> Matrix --> ZYX. To do this you not only have to have good trigonometry skills, but also be able to multiply matrices, which can be tricky algebra.

This, for example, this is what ends up as the X rotation expression I put on a ZYX camera in AE:

L=this_comp.layer("Camera");
u=L.toWorldVec([1,0,0]);
v=L.toWorldVec([0,1,0]);
w=L.toWorldVec([0,0,1);
hLock=clamp(u[2],-1,1);h=Math.asin(-hLock);cosH=Math.cos(h);
if (Math.abs(cosH) > 0.0005){
p=Math.atan2(v[2], w[2]);
b=Math.atan2(u[1],u[0]/thisComp.pixelAspect);
}else{
b=Math.atan2(w[1], v[1]);
p=0;
}