Does anybody know how to get the bounding box for a selection of multiple objects?
Thanks,
-bN
Does anybody know how to get the bounding box for a selection of multiple objects?
Thanks,
-bN
this is from a larger script that gets a single animated bounding box for multiple mesh objects. happy to share it if you need it.
//takes a list of mesh objects, and returns an array containing: minBBX, minBBY, minBBZ, maxBBX, maxBBY, maxBBZ of the whole collection of mesh objects
global proc float[] getAnimatedBoundsForMeshes( string $skinList[] ) {
float $bounds[];
float $skinMinBoundsX[];
float $skinMinBoundsY[];
float $skinMinBoundsZ[];
float $skinMaxBoundsX[];
float $skinMaxBoundsY[];
float $skinMaxBoundsZ[];
for( $skin in $skinList ) {
$skinMinBoundsX[( `size $skinMinBoundsX` )] = `getAttr ( $skin + ".boundingBoxMinX" )`;
$skinMinBoundsY[( `size $skinMinBoundsY` )] = `getAttr ( $skin + ".boundingBoxMinY" )`;
$skinMinBoundsZ[( `size $skinMinBoundsZ` )] = `getAttr ( $skin + ".boundingBoxMinZ" )`;
$skinMaxBoundsX[( `size $skinMaxBoundsX` )] = `getAttr ( $skin + ".boundingBoxMaxX" )`;
$skinMaxBoundsY[( `size $skinMaxBoundsY` )] = `getAttr ( $skin + ".boundingBoxMaxY" )`;
$skinMaxBoundsZ[( `size $skinMaxBoundsZ` )] = `getAttr ( $skin + ".boundingBoxMaxZ" )`;
}
$skinMinBoundsX = `sort $skinMinBoundsX`;
$skinMinBoundsY = `sort $skinMinBoundsY`;
$skinMinBoundsZ = `sort $skinMinBoundsZ`;
$skinMaxBoundsX = `sort $skinMaxBoundsX`;
$skinMaxBoundsY = `sort $skinMaxBoundsY`;
$skinMaxBoundsZ = `sort $skinMaxBoundsZ`;
$bounds[0] = $skinMinBoundsX[0];
$bounds[1] = $skinMinBoundsY[0];
$bounds[2] = $skinMinBoundsZ[0];
$bounds[3] = $skinMaxBoundsX[( `size $skinMaxBoundsX` - 1 )];
$bounds[4] = $skinMaxBoundsY[( `size $skinMaxBoundsY` - 1 )];
$bounds[5] = $skinMaxBoundsZ[( `size $skinMaxBoundsZ` - 1 )];
return $bounds;
}
Thanks! I was going to write it if there wasn't a simple flag I was missing, but now I don't have to. Whee!
well, if there was a simple flag, i missed it too. ![]()
If you want a shorter version of this I wrote this procedure:
global proc float[] GetMultipleBB(string $sel[]){
float $bb[];
// go through selection
for($i=0; $i<size($sel); $i++){
float $thisBB[] = xform -q -ws -bb $sel[$i];
// First check if bb[] is null, if so, just set the values
if(size($bb) == 0){
$bb = $thisBB;
}
else{
if($thisBB[0] < $bb[0]) $bb[0] = $thisBB[0];
if($thisBB[1] < $bb[1]) $bb[1] = $thisBB[1];
if($thisBB[2] < $bb[2]) $bb[2] = $thisBB[2];
if($thisBB[3] > $bb[3]) $bb[3] = $thisBB[3];
if($thisBB[4] > $bb[4]) $bb[4] = $thisBB[4];
if($thisBB[5] > $bb[5]) $bb[5] = $thisBB[5];
}
}
return $bb;
[b]}
[/b]Just pass in an object selction like this:
string $sel[] = ls -sl -fl;
float $selBB[] = GetMultipleBB($sel);
Also if you would like to find the center of all the selected objects I wrote this procedure as well:
global proc vector GetBBCenter(float $bb[]){
vector $center;
float $x = ($bb[0] + $bb[3]) / 2;
float $y = ($bb[1] + $bb[4]) / 2;
float $z = ($bb[2] + $bb[5]) / 2;
$center = <>;
return $center;
[b]}
[/b]Just pass in the float array you recieved from GetMultipleBB() like so:
string $sel[] = ls -sl -fl;
float $selBB[] = GetMultipleBB($sel);
vector $center = GetBBCenter($selBB);
An even shorter version is to use this command in mel:
exactWorldBoundingBox
This takes a list of multiple objects as argument and returns the collective boundingBox of specified objects.