# Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Expressions Convert a 3D position to 2D position *and scale*

• # Convert a 3D position to 2D position *and scale*

3 Members · 4 Posts
• ### Gabriel Grenier

November 17, 2021 at 2:22 pm

Hi !

.toComp() will give me the 2D position of a 3D layer. But what if that 3D layer also has its Z position animated and I wanted to translate this to 2D position and Scale, so the resulting 2D layer appears to sit perfectly where the 3D layer is?

In other words:
If 3D position [500,400,0] = 2D position [500,400] and a scale of 100%,
a 3D position of [500,400,-300] would give me a scale of 130% (example)

What would be the expression for the scale? (relative to the active Camera I would assume)

• ### Kevin Camp

November 18, 2021 at 11:22 pm

Have you tried leaving the layer 3d but enabling auto-orient towards camera? I think it might accomplish what you are trying to do…

• ### Meng Zhiqun

November 19, 2021 at 3:16 am

Hi Gabriel,

.toComp() is generally used for 2d layers. Have you tried .toWorld(), which is used for 3d layers?

• ### Gabriel Grenier

November 27, 2021 at 6:16 pm

I’ll put the working solution here for future reference.

The following expressions assume that the target 3D layer is the next one, right under the 2D layer (index+1), but that could be changed of course.

Expression for position:
thisComp.layer(index+1).toComp(thisComp.layer(index+1).transform.anchorPoint)

Expression for Scale:

L = thisComp.layer(index+1);

C = thisComp.activeCamera;

CP = C.toWorld([0,0,0]);

LP = L.toWorld(thisComp.layer(index+1).anchorPoint);

dis = length(CP,LP);

CZ = C.cameraOption.zoom;

LS = L.transform.scale[0];

S = LS*CZ/dis;

[S,S];

Viewing 1 - 4 of 4 posts