ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

link visually two 3D layers on X despite different Z

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Christophe Clarey
link visually two 3D layers on X despite different Z
on Dec 4, 2018 at 10:12:05 am

Hello,

I'm struggling with the toComp/toWorld expressions. I thought I've kind of understood the basics, but I'm missing something somewhere to make it work.

So I have the following structure :

Parent 1 (parented as well, not not relevant here)
- Layer 1 (child of Parent 1, 3D, with a Z1 depth)
- Layer 2 (child of Parent 1, 3D, with a Z2 depth different than Z1, with Z2 fixed, like Z2 = Z1 + 400)


So basically, what I want to do is control Layer 2 position, that it's placed, visually, and the same X at the Layer 1 (despite a different Z).

If I use in position of Layer 2 :
L1 = thisComp.layer("Layer 1");
L1.toComp([thisComp.width/2,thisComp.height/2,0])[0];

I get the two layers linked on the X in the comp, despite the Z, but with an offset, because of the Z, if Z1 = Z2, I get what I want.
But how can I compensate for the Z difference.

Thank you in advance!


Best regards,

Christophe.


Return to posts index

Christophe Clarey
Re: link visually two 3D layers on X despite different Z
on Dec 6, 2018 at 10:00:19 am

Hello!
I had also posted this question on Adobe Forums, and Dan Ebberts had replied with the answer.
I post it here, for anyone who has the same question 😉
Thank you again Dan!

Dan Ebberts (to Christophe Clarey)
It's tricky. If your comp doesn't have a camera, it would be something like this:


zOffset = 400;
L = thisComp.layer("Layer 1");
p = L.toWorld(L.anchorPoint);
w = thisComp.width * thisComp.pixelAspect;
z = (w/2)/Math.tan(degreesToRadians(19.799));
c = [thisComp.width/2,thisComp.height/2,-z];
v = normalize(p - c);

if(hasParent){
parent.fromWorld(p + v*(zOffset/v[2]));
}else{
p + v*(zOffset/v[2]);
}


If it does have a camera, it would be like this:

zOffset = 400;
L = thisComp.layer("Layer 1");
p = L.toWorld(L.anchorPoint);
c = thisComp.layer("Camera 1").toWorld([0,0,0]);;
v = normalize(p - c);

if(hasParent){
parent.fromWorld(p + v*(zOffset/v[2]));
}else{
p + v*(zOffset/v[2]);
}



Dan


Christophe.


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]