/*
***************************************************************************
This is a library of functions to perform tests as to whether a point is inside
or outside of an object. currently the two functions, aa_isInside and aa_isInsideGroup work
only based on bounding boxes, so more complexly shaped forms will be only evaluated
based on their extents.
aa_isInside(string $object,float $x, float $y, float$z)
takes the name of an object and an x,y,z coordinate and checks whether the point is
inside or outside of the bounding box of the object.
Returns 1 for is inside and 0 if not inside.
aa_isInsideGroup(string $group, float $x, float $y, float $z)
Takes the name of a group of objects and performs the aa_isInside test for each
object in the group and the x,y,z coordinates supplied
Returns 1 if the point is inside of any object in the group, 0 if outside of all objects in group.
example:
//create object
sphere -name sphere1;
//Test if point (1,1,1) is inside of the object's bounding box
if(aa_isInside("sphere1",1,1,1) == 1){
print("Yes");
}else{
print("No");
}
//Test if point (100,100,100) is inside of the object's bounding box
if(aa_isInside("sphere1",100,100,100) == 1){
print("Yes");
}else{
print("No");
}
copyright
Cory Clarke cory@nthd.org
***************************************************************************
*/
global proc int aa_isInside(string $object,float $x, float $y, float $z){
float $transl[];
$mincmd = "getAttr " + $object + ".boundingBoxMin";
$min = eval($mincmd);
$maxcmd = "getAttr " + $object + ".boundingBoxMax";
$max = eval($maxcmd);
if($x < ($max[0]) && $x > ($min[0]) && $y < ($max[1]) && $y > ($min[1]) && $z < ($max[2]) && $z > ($min[2])){
return 1;
}
return 0;
}
global proc int aa_isInsideGroup(string $group,float $x, float $y, float $z){
string $listofgroup[];
string $statement;
$statement = "ls -dag -tr " + $group;
$listofgroup = eval($statement);
//first object in group is the group itself, so start at second
int $i = 1;
while($i < size($listofgroup)){
if(aa_isInside($listofgroup[$i],$x,$y,$z) == 1){
return 1;
}
$i++;
}
return 0;
}
global proc int aa_isInsideCurve ( string $lineCurve, float $x, float $z ) {
// step through each set of 2 points in the curve
// find the formula of the line between and the intersection with the point
// if the points greater are more than the points less along that axis, then it is inside if they are even, it is outside
select $lineCurve;
$num = `getAttr ".spans"`;
$num++;
float $x2, $z2, $x1, $z1, $m,$b, $xVals[], $p2[];
int $i = 0, $j = 0;
while ($i < $num) {
if ( $i > 0 ) {
$x1 = $x2;
$z1 = $z2;
}
$cmd = "xform -ws -q -t " + $lineCurve + ".controlPoints[" + $i + "]";
$p2 = eval ($cmd);
$x2 = $p2[0];
$z2 = $p2[2];
if ( $i > 0 ) {
if ( ($z2 > $z && $z1 < $z) || ($z1 > $z && $z2 < $z) ) {
// the line crosses the z of the test point - check where x val of intersection. Form line using (x2,z2) and (x1,z1)
if ($x2 == $x1) {
$xVals[$j] = $x2;
} else {
$m = ($z1 - $z2) / ($x1 -$x2);
$b = $z1 - $m * $x1;
// now z = mx + b OR x = (z-b)/m
$xVals[$j] = ($z-$b)/$m;
}
$j++;
}
}
$i++;
}
$xVals = sort ($xVals);
$k = 0;
while ($k < size($xVals)) {
$xa = $xVals[$k]; $k++;
$xb = $xVals[$k]; $k++;
if ($xa < $x && $xb > $x) {
//print ("is Inside!");
return 1;
}
}
//print ("is outside...");
return 0;
}
global proc int aa_isInsideBlob(string $blob, float $x, float $y, float $z ) {
// find a curve intersection at $y
//check if it is even inside the bounding box
$checkBox = aa_isInside($blob, $x, $y, $z);
//if it is not inside bounding box return
if ($checkBox == 0) {
print ("Outside Box...\n/\n"); return 0;
}
//create 'infinitely' large plane to interest surface
$planeArray = `nurbsPlane -p 0 $y 0 -ax 0 1 0 -w 10000 -lr 1 -d 3 -u 3 -v 3 -ch 1`;
$plane = $planeArray[0];
//intersect and get curve
$curveArray = `intersect -ch true -fs 0 -cos 0 -tol 0.01 $plane $blob` ;
$curve = $curveArray[0] + "_1";
//check if point is inside of intersected curve
$return = aa_isInsideCurve( $curve , $x, $z);
//do cleanup
delete $curve;
delete $plane;
//return results
return $return;
}
print("aa_isInside....loaded\n");
There are no threads for this page.
Be the first to start a new thread.