ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

2d bounding box from 3d layer

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
daniele zacchi
2d bounding box from 3d layer
on Sep 1, 2017 at 2:34:42 pm

Hello folks,

I'm trying to create a bounding box of a 3d solid, with a 2d solid which should stick to the 3d layer and follow his scale on the relative x,y 2d space. I'm using this expression on a point control:

L=thisComp.layer(3d layer);

[Math.max(Math.abs(N[0]), Math.abs(O[0])), Math.max(Math.abs(N[1]), Math.abs(O[1]))]

this on the scale of the 2d layer

P=thisComp.layer(ref).effect("Point Control")("Point")[0];

J=thisComp.layer(ref).effect("Point Control")("Point")[1];

F = linear(P,0,1920,0,100);

G = linear(J,0,1080,0,100);

and this on his positions:

L = thisComp.layer(index -1);

L.toComp([L.width/2, L.height/2, 0]);

everything seems to work (scale, rotations, positions and camera movement) until the Z axis of the 3d layer is facing the camera.
When it doesn't, it continues to follow the transformations, more or less, but not precisely around the extremes of my layer.

Any clues? I would be immensely grateful.



Return to posts index

Dan Ebberts
Re: 2d bounding box from 3d layer
on Sep 1, 2017 at 6:00:01 pm

This seems to work.

Common to position and scale expressions:

L=thisComp.layer("3d layer");
UL = L.toComp([R.left,]);
UR = L.toComp([R.left+R.width,]);
LR = L.toComp([R.left+R.width,]);
LL = L.toComp([R.left,]);
maxX = Math.max(UL[0],UR[0],LR[0],LL[0]);
minX = Math.min(UL[0],UR[0],LR[0],LL[0]);
maxY = Math.max(UL[1],UR[1],LR[1],LL[1]);
minY = Math.min(UL[1],UR[1],LR[1],LL[1]);

Add this for position:


Add this for scale:

w = maxX - minX;
h = maxY - minY;


Return to posts index

daniele zacchi
Re: 2d bounding box from 3d layer
on Sep 4, 2017 at 10:01:56 am

Thanks Dan,
you are my hero!!
This works beautifully!
It would be great to understand how you made it, I am trying to understand how the expression works, but I think not getting it yet. 😆

Thanks a LOT!🐮


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 All Rights Reserved