Feedback

What's your question?

By: Asked

getting the volume of an arbitrary closed mesh

Hopefully using Mel in Maya, I'd like to find the volume of a closed polygonal mesh. Anyone know how to do this, or if it's even possible?

Thanks,

Matt

  • 0

mbakr [ Editor ]

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;
}
or Cancel