Julian,
Your method is more accurate than computePolysetVolume - which can return outlandish values for arbitrarily faceted meshes (such as those generated via Voronoi shatter). Thanks for sharing.
EDIT:
One small optimization here for meshVolume() - unfrozen transforms can produce varied results, this tweak simply freezes the duplicate. The result is consistent volume computation and any orientation.
global proc float meshVolume() {
string $sel[] = `ls -sl -dag -leaf -type "mesh"`;
string $dup[] = `duplicate -rr $sel[0]`;
makeIdentity -apply true -t 1 -r 1 -s 1 -n 0 $dup[0]; //freeze
polyTriangulate $dup[0];
string $tris[] = `ls -flatten ($dup[0] +".f[*]")`;
float $volume = 0.0;
for ($t in $tris) $volume += prismVolume($t) ;
delete $dup;
return $volume;
}
By:
Michael Baker
[ Editor ]