I got this code from motionscript and I would like to change it to check a specific layer instead of all the layers for a collision. Maybe within the function checklayers() and then there's the if checklayers() at the last line ??
function getMin(a, b, c, d){
return Math.min(Math.min(a,b),Math.min(c,d));
}
function getMax(a, b, c, d){
return Math.max(Math.max(a,b),Math.max(c,d));
}
function getBoundingBox(theLayer){
bb = [];
c1 = theLayer.toWorld([0,0]);
c2 = theLayer.toWorld([theLayer.width,0]);
c3 = theLayer.toWorld([theLayer.width,theLayer.height]);
c4 = theLayer.toWorld([0,theLayer.height]);
bb[0] = getMin(c1[0],c2[0],c3[0],c4[0]);
bb[1] = getMin(c1[1],c2[1],c3[1],c4[1]);
bb[2] = getMax(c1[0],c2[0],c3[0],c4[0]);
bb[3] = getMax(c1[1],c2[1],c3[1],c4[1]);
return bb;
}
function checkLayers(){
cUL = [];
cLR = [];
for ( idx = 1; idx <= thisComp.numLayers; idx++){
if (index == idx) continue;
L = thisComp.layer(idx);
if (! L.active) continue;
BB = getBoundingBox(L);
UL = [BB[0],BB[1]];
LR = [BB[2],BB[3]];
if (!(myLR[1] < UL[1] || LR[1] < myUL[1] ||
myLR[0] < UL[0] || LR[0] < myUL[0])){
if (myUL[1] < UL[1]) cUL[1]=UL[1] else cUL[1]=myUL[1];
if (myUL[0] < UL[0]) cUL[0]=UL[0] else cUL[0]=myUL[0];
if (myLR[1] < LR[1]) cLR[1]=myLR[1] else cLR[1]=LR[1];
if (myLR[0] < LR[0]) cLR[0]=myLR[0] else cLR[0]=LR[0];
for(i = cUL[0]; i <= cLR[0]; i++){
for (j = cUL[1]; j <= cLR[1]; j++){
if (sampleImage(fromWorld([i,j]))[3] > 0 &&
L.sampleImage(L.fromWorld([i,j]))[3] > 0){
return true;
}
}
}
}
}
return false;
}
myBB = getBoundingBox(thisLayer);
myUL = [myBB[0],myBB[1]];
myLR = [myBB[2],myBB[3]];
if (checkLayers()) 1 else 0