ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

# 2d bounding box from 3d layer

FAQ   •   VIEW ALL
 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);
R=L.sourceRectAtTime(time,false);
N=L.toComp([R.left+L.width,R.top+L.height])-L.toComp(anchorPoint);
O=L.toComp([R.left-L.width,R.top+L.height])-L.toComp(anchorPoint);

[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.

Thanks

Daniele

 Return to posts index

 Re: 2d bounding box from 3d layeron Sep 1, 2017 at 6:00:01 pm

This seems to work.

Common to position and scale expressions:

L=thisComp.layer("3d layer");
R=L.sourceRectAtTime(time,false);
UL = L.toComp([R.left,R.top]);
UR = L.toComp([R.left+R.width,R.top]);
LR = L.toComp([R.left+R.width,R.top+R.height]);
LL = L.toComp([R.left,R.top+R.height]);
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:

[maxX+minX,maxY+minY]/2;

Add this for scale:

w = maxX - minX;
h = maxY - minY;
[(w/width),h/height]*100

Dan

 Return to posts index

 Re: 2d bounding box from 3d layeron 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!🐮

Daniele

 Return to posts index

© 2018 CreativeCOW.net All Rights Reserved
[TOP]