View Full Version : volume of bounding box
brainspoon 04-29-2003, 04:58 PM is anybody here who can help me with a script that calculates the volume of the bounding box of the selected object to asign the value as the mass for the rigid body? i want to use it as rough randomisation of the rigid bodys
thanks in advance
andreas
|
|
dstripinis
04-29-2003, 06:56 PM
string $sel[] = `ls -sl`;
for ( $each in $sel )
{
float $minX = `getAttr ( $each + ".boundingBoxMinX" )`;
float $maxX = `getAttr ( $each + ".boundingBoxMaxX" )`;
float $minY = `getAttr ( $each + ".boundingBoxMinY" )`;
float $maxY = `getAttr ( $each + ".boundingBoxMaxY" )`;
float $minZ = `getAttr ( $each + ".boundingBoxMinZ" )`;
float $maxZ = `getAttr ( $each + ".boundingBoxMaxZ" )`;
float $xLen = ( $maxX - $minX );
float $yLen = ( $maxY - $minY );
float $zLen = ( $maxZ - $minZ );
float $vol = ( $xLen * $yLen * $zLen );
print ( $each + " has a volume of " + $vol + " units.\n" );
}
brainspoon
04-30-2003, 10:20 AM
thanks for your help.
i think it would work. now i need some help with getting the rigid body of the selected object. it is next to its shape node
brainspoon
04-30-2003, 11:17 AM
now i am this far
string $sel[] = `ls -sl`;
for ( $each in $sel )
{
float $minX = `getAttr ( $each + ".boundingBoxMinX" )`;
float $maxX = `getAttr ( $each + ".boundingBoxMaxX" )`;
float $minY = `getAttr ( $each + ".boundingBoxMinY" )`;
float $maxY = `getAttr ( $each + ".boundingBoxMaxY" )`;
float $minZ = `getAttr ( $each + ".boundingBoxMinZ" )`;
float $maxZ = `getAttr ( $each + ".boundingBoxMaxZ" )`;
float $xLen = ( $maxX - $minX );
float $yLen = ( $maxY - $minY );
float $zLen = ( $maxZ - $minZ );
float $vol = ( $xLen * $yLen * $zLen );
pickWalk -d down;
$rigid=`pickWalk -d right`;
eval ( "setAttr " + $rigid[0] + ".mass " + $vol);
};
the problem is that it stops calculating after the first object with this message
// Error: No object matches name: polySurfaceShape93.mass //
i think that is becaus i used pickwalk which might be not the best way to get the rigid body
brainspoon
04-30-2003, 03:05 PM
now i got it.. thanks to all helpers. here is the script for all who want to use it
string $sel[] = `ls -sl`;
for ( $each in $sel )
{
float $minX = `getAttr ( $each + ".boundingBoxMinX" )`;
float $maxX = `getAttr ( $each + ".boundingBoxMaxX" )`;
float $minY = `getAttr ( $each + ".boundingBoxMinY" )`;
float $maxY = `getAttr ( $each + ".boundingBoxMaxY" )`;
float $minZ = `getAttr ( $each + ".boundingBoxMinZ" )`;
float $maxZ = `getAttr ( $each + ".boundingBoxMaxZ" )`;
float $xLen = ( $maxX - $minX );
float $yLen = ( $maxY - $minY );
float $zLen = ( $maxZ - $minZ );
float $vol = ( $xLen * $yLen * $zLen );
string $rB=`rigidBody -q -name $each`;
select $rB;
rigidBody -e -m $vol;
};
CGTalk Moderation
01-15-2006, 12:00 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2013, Jelsoft Enterprises Ltd.