Expressions/Scripts/Presets

Moderators: Disciple, zlovatt

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

baking camera for export - trouble with 3D rotations!

Sun Feb 24, 2008 3:44 am

baking the AE camera for export to 3D packages - trouble with 3D rotation

I'm trying to share my AE camera with a number of 3D packages. What often helps is having a free camera that does not use a POI (target) or parenting before you export. So I was trying to write an expression to convert all values to global values to "unparent" my camera. The position so far works fine. I used Dan Ebberts' 2D Auto Orientation script for the rotations as a starting point...which works fine one at a time, but not when the the axes are combined. Does it not work because of the rotation order? Anyone tackled this before?

The layer "c" is my keyframeless child camera layer controlled by a parent null. Below are the expressions applied to the new free camera.

Position

L=thisComp.layer("c");L.toWorld(L.anchorPoint)

X Rotation

L = thisComp.layer("c");
u = L.toWorldVec([0,0,1]);
-radiansToDegrees(Math.atan2(u[1],u[2]))

Y Rotation

L = thisComp.layer("c");
u = L.toWorldVec([1,0,0]);
-radiansToDegrees(Math.atan2(u[2],u[0]))

Z Rotation

L = thisComp.layer("c");
u = L.toWorldVec([1,0,0]);
radiansToDegrees(Math.atan2(u[1],u[0]))
 
Mylenium
Posts: 139
Joined: Wed Jul 20, 2005 12:07 am

Re: baking camera for export - trouble with 3D rotations!

Sun Feb 24, 2008 6:07 am

urbanspaceman wrote:
Does it not work because of the rotation order? Anyone tackled this before?


I'm crap at vectors, 'cos I never learned that stuff at school (but then again I'm crap at most math stuff), but I would assume that you would need a cross product based on the first two vector components somewhere to get a stable rotation value, similar to SLERPs. Not sure though, perhaps Master Dan can provide some clues. I'm overflooded with new impressions from installing Mac Software and Windows Vista this weekend, anyways. ;-)

Mylenium
[Pour Mylène, ange sur terre]
 
urbanspaceman
Topic Author
Posts: 54
Joined: Wed Dec 12, 2007 9:56 am
Location: London
Contact:

Re: baking camera for export - trouble with 3D rotations!

Sun Feb 24, 2008 10:03 am

Well, Mylenium, I'm super crap at vectors, because I went to art school! I've been googling and it looks like it's a common 3D rotation problem called "Euler angle flipping". Haven't figured out how to solve it just yet....
 
Dan Ebberts
Posts: 318
Joined: Sat Jun 26, 2004 10:01 am
Location: Folsom, CA
Contact:

Re: baking camera for export - trouble with 3D rotations!

Sun Feb 24, 2008 11:58 am

The angles interact, so you need to do it all in one calculation. This should give you the orientation:

C = this_comp.layer("c"); 
u = C.to_world_vec([1,0,0]); 
v = C.to_world_vec([0,1,0]); 
w = C.to_world_vec([0,0,1]);
sinb = clamp(w[0],-1,1); 
 b = Math.asin(sinb/this_comp.pixel_aspect); 
cosb = Math.cos(b); 
if (Math.abs(cosb) > .0005){ 
  c = -Math.atan2(v[0],u[0]); 
  a = -Math.atan2(w[1],w[2]); 
}else{ 
  a = Math.atan2(u[1],v[1]); 
  c = 0; 

[radians_to_degrees(a),radians_to_degrees(b),radians_to_degrees(c)]


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

Re: baking camera for export - trouble with 3D rotations!

Sun Feb 24, 2008 1:30 pm

Thanks a million, Dan! Works like a charm.
 
urbanspaceman
Topic Author
Posts: 54
Joined: Wed Dec 12, 2007 9:56 am
Location: London
Contact:

Re: baking camera for export - trouble with 3D rotations!

Sun Feb 24, 2008 6:33 pm

I'll make a copy of this in the Scripting thread as well...

I was able to take Dan's code and turn it into an easy to use script. All you have to do is set your work area, highlight your camera, and it will make a copy of it with all the keyframes baked. It shouldn't matter what rotation methods and parenting the original camera has, as it translates all of that into a free camera. Thanks again, Dan!

http://www.urbanspaceman.net/shared/AEs ... raBake.jsx

(ps. there is no error checking in the script, so if you don't highlight the camera it just quits at the moment).

Who is online

Users browsing this forum: No registered users and 3 guests