Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions 2d bounding box from 3d layer

  • 2d bounding box from 3d layer

    Posted by Daniele Zacchi on September 1, 2017 at 2:34 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

    Daniele Zacchi replied 8 years, 8 months ago 2 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    September 1, 2017 at 6:00 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

  • Daniele Zacchi

    September 4, 2017 at 10:01 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

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy