Calculate volume in maya

Discussion in 'Software and Applications' started by 422484_deleted, Sep 22, 2013.

  1. Hello,

    Quick question.

    I found the following MEL command to calculate the volume of polygonal objects:

    computePolysetVolume( Documentation link )

    I'm wondering if anyone can verify the accuracy of this compared to Shapeways' volume calculation?

    I tried it on the following 2 STL's provided by webmaster_duann:
    iPhone 5 bumper:
    Code:
    // iphone_bumper faces = 14786 //
    // TOTAL VOLUME = 4.404315761 //
    // 4.404316 // 
    
    iPhone 5 case:
    Code:
    // iphone_case faces = 14838 //
    // TOTAL VOLUME = 13.99083778 //
    // Result: 13.990838 // 
    
    My maya working units is set to centimeters, so I would assume this is cm3?

    Anyone here that could verify or give more information on the accuracy of the volume calculation?

    Thanks in advance

     
    Last edited: Sep 22, 2013
  2. Quick update.

    I found the following MEL script on vfx overflow:
    ( vfxoverflow.com link )

    Code:
    global proc vector faceNormal(string $face ) {
        string $res[] = `polyInfo -fn $face`;
        string $buff[];
        tokenize($res[0] ,":" , $buff);
        tokenize($buff[1] ," " , $buff);
        return unit( << float($buff[0]) , float($buff[1]) ,float($buff[2]) >>);
    }
    
    global proc float xyArea(vector $v1,vector $v2,vector $v3 ) {
        return abs((($v1.x)*(($v3.y)-($v2.y)))+(($v2.x)*(($v1.y)-($v3.y)))+(($v3.x)*(($v2.y)-($v1.y)))) *0.5;
    }
    
    
    global proc float prismVolume(string $triangle) {
        string $triVerts[] = `polyListComponentConversion -tv $triangle`;
        $triVerts = `ls -flatten $triVerts`;
    
        if (`size $triVerts` != 3) error($triangle +" is not a triangle");
    
        vector $v1 = `pointPosition -w $triVerts[0]`; 
        vector $v2 = `pointPosition -w $triVerts[1]`; 
        vector $v3 = `pointPosition -w $triVerts[2]`; 
    
        vector $normal = faceNormal( $triangle );
        float $area = xyArea( $v1, $v2, $v3 );
        float $pVolume = ((($v1.z)+($v2.z)+($v3.z))/3.0)*$area ;
        if (($normal.z) < 0) $pVolume = -$pVolume;
    
        return $pVolume;
    }
    
    // pick a mesh and type meshVolume();
    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;
    }
    
    This script gives the following results for the bumper and case:

    Bumper:
    Code:
    // Result: 4.404317 // 
    Case:
    Code:
    // Result: 13.990835 // 
    Again, would like to know if there is a way to find out how accurate this is.

    Thanks in advance.
     
  3. AmLachDesigns
    AmLachDesigns Well-Known Member
    This matches the figures given by Netfabb Studio Basic.
    And yes, it is cm3.
     
  4. Thanks!

    Still trying to get my way around, but this is really useful. :)
     
  5. AmLachDesigns
    AmLachDesigns Well-Known Member
    No problem.

    I should have mentioned that lots of designers here use Netfabb, and the version I referenced is free. You can find errors in the mesh, fix some errors, take measurements, convert file formats, convert your model to slices and scale models. I'm sure it does other stuff too...
     
  6. Thanks again for the help.

    I found the tutorial on Netfabb after you mentioned it, very useful.