Skip to main content
The_Kitty
Inspiring
October 23, 2022
Answered

check if a layer is outside the camera area

  • October 23, 2022
  • 2 replies
  • 382 views
 

Hi, is there any way to check if a layer is outside the camera area ?

example

if(ouside){opacity=100}

else {opacity=0}

Thank !!!

 

 
This topic has been closed for replies.
Correct answer Dan Ebberts

Depending on what you're doing, variable visible should be true if any of  the bounding rectangle of your target layer appears within the camera view:

 

L = thisComp.layer("Target Layer");
w = thisComp.width;
h = thisComp.height;
r = L.sourceRectAtTime(time,false);
ul = L.toComp([r.left,r.top]);
ur = L.toComp([r.left+r.width,r.top]);
ll = L.toComp([r.left,r.top+r.height]);
lr = L.toComp([r.left+r.width,r.top+r.height]);
visible = ((ul[0] >=0 && ul[0] <= w) && (ul[1] >=0 && ul[1] <= h)) ||
((ur[0] >=0 && ur[0] <= w) && (ur[1] >=0 && ur[1] <= h)) ||
((ll[0] >=0 && ll[0] <= w) && (ll[1] >=0 && ll[1] <= h)) ||
((lr[0] >=0 && lr[0] <= w) && (lr[1] >=0 && lr[1] <= h));

 

 

2 replies

Dan Ebberts
Community Expert
Dan EbbertsCommunity ExpertCorrect answer
Community Expert
October 23, 2022

Depending on what you're doing, variable visible should be true if any of  the bounding rectangle of your target layer appears within the camera view:

 

L = thisComp.layer("Target Layer");
w = thisComp.width;
h = thisComp.height;
r = L.sourceRectAtTime(time,false);
ul = L.toComp([r.left,r.top]);
ur = L.toComp([r.left+r.width,r.top]);
ll = L.toComp([r.left,r.top+r.height]);
lr = L.toComp([r.left+r.width,r.top+r.height]);
visible = ((ul[0] >=0 && ul[0] <= w) && (ul[1] >=0 && ul[1] <= h)) ||
((ur[0] >=0 && ur[0] <= w) && (ur[1] >=0 && ur[1] <= h)) ||
((ll[0] >=0 && ll[0] <= w) && (ll[1] >=0 && ll[1] <= h)) ||
((lr[0] >=0 && lr[0] <= w) && (lr[1] >=0 && lr[1] <= h));

 

 

The_Kitty
The_KittyAuthor
Inspiring
October 23, 2022

Oh you're great, thank you so much !!!
It works as expected

Community Expert
October 23, 2022

It would not be a simple expression. With a 2-node camera, you would need to include the Point of Interest, the Zoom value, the distance from the camera, and the layer width combined with the Anchor Point. You would also have to throw in the angles for a one-node camera.  You should also probably compensate for scale. 

 

The basic math would be as follows:

Calculate the distance from the camera and the distance from the center of the camera's view. Factor in the Zoom (angle of view) layer size multiplied by scale and a couple of other things. 

 

I have animation presets that put a 2D layer just outside the composition boundary, move it into position based on in-point and timing sliders, and then move the layer out of the frame based on out-point. I have thought about modifying them to work with 3D layers but have never taken the time to do so.