Activity › Forums › Adobe After Effects Expressions › Layer Space Transform question
-
Layer Space Transform question
Posted by Lloyd Alvarez on May 7, 2008 at 3:08 pmI have a cube that is in a pre-comp. This precomp has collapse transformations turned on and is a 3D layer in the parent comp where the camera is. What I need to do is match a 3D null in the parent comp to the anchor point of one of the sides of my cube in the pre-comp.
I have a small test project that has the setup in case my description doesnt make any sense.
https://aescripts.com/temp/transforms_help.aep.zip
Thanks in advance!
-Lloyd
Kevin Schires replied 13 years, 8 months ago 5 Members · 11 Replies -
11 Replies
-
Darby Edelen
May 7, 2008 at 3:32 pmI think you may need two instances of toWorld(), one to convert the anchor point of the layer to its world position inside the composition and another to convert that position to a world position in the current comp… I can’t test these until I get to work but I think something like this may work:
l = comp("myComp").layer("myLayer"); //myComp is the composition with the layer (myLayer) that we want to retrieve the anchor point oftoWorld(l.toWorld(anchorPoint));
This is assuming that the first call to
l.toWorld(anchorPoint)will return the position of the anchor point in the nested composition, and I’m not entirely confident of that. I don’t usually use layer space transforms between comps =ODarby Edelen
Lead Designer
Left Coast Digital
Santa Cruz, CA -
Dan Ebberts
May 7, 2008 at 3:45 pmLloyd,
I think this is what you’re looking for:
L = comp(“Pre-Comp”).layer(“FOLDING SIDE”);
CL = thisComp.layer(“Pre-Comp”);
CL.toWorld(L.toWorld(L.anchorPoint));Dan
-
Lloyd Alvarez
May 7, 2008 at 3:55 pmThanks! That did the trick, but I forgot to mention that I also need the rotations (and orientation) of the null. Seems toWorld only works with vectors or length 2 or 3 (at least that’s what the error message says 😉
-Lloyd
-
Dan Ebberts
May 7, 2008 at 4:22 pmThat’s a lot tougher. I think the best you can do is to match the world orientation. Give this a try:
L = comp(“Pre-Comp”).layer(“FOLDING SIDE”);
CL = thisComp.layer(“Pre-Comp”);
u = CL.toWorldVec(L.toWorldVec([1,0,0]));
v = CL.toWorldVec(L.toWorldVec([0,1,0]));
w = CL.toWorldVec(L.toWorldVec([0,0,1]));sinb = clamp(w[0],-1,1);
b = Math.asin(sinb);
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;
}
[radiansToDegrees(a),radiansToDegrees(b),radiansToDegrees(c)]Dan
-
Lloyd Alvarez
May 7, 2008 at 4:42 pmWow Dan! That’s some serious math going on there!
Well, I am happy to report that it works!!
Thank again!-Lloyd
-
Darby Edelen
May 7, 2008 at 7:36 pm[Dan Ebberts] “L = comp(“Pre-Comp”).layer(“FOLDING SIDE”);
CL = thisComp.layer(“Pre-Comp”);
CL.toWorld(L.toWorld(L.anchorPoint)); “Woops, heh… I had assumed when I started writing my code that the expression would be applied to the pre-comp, but when I realized that probably wouldn’t be the case I went back and revised it slightly… of course I forgot to get a reference to the pre-comp layer =O
Darby Edelen
Lead Designer
Left Coast Digital
Santa Cruz, CA -
Jonas Espinoza
August 27, 2008 at 10:02 pmL = comp(“Pre-Comp”).layer(“FOLDING SIDE”);
CL = thisComp.layer(“Pre-Comp”);
CL.toWorld(L.toWorld(L.anchorPoint));can i ask about the coding of this?
I’m a little confused, within the parenthesis you get a 3-value for the world location of the anchor point in the pre-comp, but from that, how does that array interface/translate with the last statement “CL.toWorld”
why couldnt you just take “CL.toWorld(L.anchorPoint)”
if anyone gets to this, thanks
-
Dan Ebberts
August 27, 2008 at 10:25 pmThe inner toWorld() translates layer “FOLDING SIDE”‘s positon into comp “Pre-Comp”‘s world space. The outer toWorld() takes the inner value as being in the layer space of the layer “Pre-Comp” which is nested within the outer comp and translates it to the outer comp’s world space.
Probably not necessary if Pre-Comp is the same size as the main comp and has not been moved or rotated from the center of the main comp.
Dan
-
Jonas Espinoza
August 27, 2008 at 10:45 pmthanks you, that helps a lot
so in expressions language:
Layer1.toWorld(x,y,z)
within the () are the layer-space values being translated “toWorld”
i guess i wrongly thought to always have the value being fed to the “toWorld” coming to the left of it
-
Kevin Schires
August 22, 2012 at 10:38 amI feel quite bad/scared questionning Mr. Ebberts’s post, as I learned everything about scripting on motionscript.com. I was wondering if there should be -1 or +1 factor based on the value of b in the lign “a = Math.atan2(u[1],v[1]);”
I slightly modified the expression but I don’t think I introduced any error, here is what I use:
u = normalize(toWorldVec([1,0,0]));
v = normalize(toWorldVec([0,1,0]));
w = normalize(toWorldVec([0,0,1]));
sinb = w[0];
b = Math.asin(sinb);
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 = ( (sinb < 0) ? -1 : 1 )*Math.atan2(u[1],v[1]);
c = 0;
}
[radiansToDegrees(a), radiansToDegrees(b), radiansToDegrees(c)];
Otherwise it seems it would return the opposite of what a should be if b is in the range 270º +/- 0.0005.
Reply to this Discussion! Login or Sign Up