AE ENHANCERS

Expressions/Scripts/Presets
It is currently Sun Nov 23, 2014 12:36 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: baking camera for export - trouble with 3D rotations!
PostPosted: Sun Feb 24, 2008 3:44 am 
Offline

Joined: Wed Dec 12, 2007 9:56 am
Posts: 54
Location: London
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]))


Top
 Profile  
 
 Post subject: Re: baking camera for export - trouble with 3D rotations!
PostPosted: Sun Feb 24, 2008 6:07 am 
Offline

Joined: Wed Jul 20, 2005 12:07 am
Posts: 139
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]


Top
 Profile  
 
 Post subject: Re: baking camera for export - trouble with 3D rotations!
PostPosted: Sun Feb 24, 2008 10:03 am 
Offline

Joined: Wed Dec 12, 2007 9:56 am
Posts: 54
Location: London
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....


Top
 Profile  
 
 Post subject: Re: baking camera for export - trouble with 3D rotations!
PostPosted: Sun Feb 24, 2008 11:58 am 
Offline

Joined: Sat Jun 26, 2004 10:01 am
Posts: 309
Location: Folsom, CA
The angles interact, so you need to do it all in one calculation. This should give you the orientation:

Code:
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

_________________
http://www.motionscript.com


Top
 Profile  
 
 Post subject: Re: baking camera for export - trouble with 3D rotations!
PostPosted: Sun Feb 24, 2008 1:30 pm 
Offline

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


Top
 Profile  
 
 Post subject: Re: baking camera for export - trouble with 3D rotations!
PostPosted: Sun Feb 24, 2008 6:33 pm 
Offline

Joined: Wed Dec 12, 2007 9:56 am
Posts: 54
Location: London
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).


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group