home *** CD-ROM | disk | FTP | other *** search
/ Learning Maya 3 / Learning_Maya_3.iso / docs / mel_scripts / includes / nurbsCurveInformation.mel < prev    next >
Encoding:
Text File  |  2000-05-17  |  4.7 KB  |  191 lines

  1. // Copyright (C) 1997-2000 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. // get lots of information about a nurbs curve
  18. proc float[] getNurbsCurveKnots( 
  19.     string $crvName )
  20. //
  21. //    Description :     This script will print information about the selected curve
  22. //                in the script editor.
  23. //    Usage:         select curve and type nurbsCurveInformation in the command line.
  24. //
  25. {
  26.     float $knots[] ;
  27.     string $infoNode ;
  28.  
  29.     // create info Node.
  30.     if( catch( $infoNode = `createNode curveInfo` ) ) {
  31.         return $knots ;
  32.     } 
  33.  
  34.     // connect curve on to the info node.
  35.     //
  36.     string $outAttr = $crvName + ".local" ; 
  37.     string $inAttr = $infoNode + ".ic" ;
  38.     connectAttr $outAttr $inAttr ;
  39.  
  40.     // read the knots.
  41.     //
  42.     $outAttr = $infoNode + ".knots" ; 
  43.     $knots = `getAttr $outAttr` ;    
  44.  
  45.     // delete curve info node.
  46.     //
  47.     delete $infoNode ;
  48.  
  49.     // return the knots.
  50.     //
  51.     return $knots;
  52. }
  53.  
  54. global proc printNurbsCurveMiscInfo(string $crv)
  55. // Description :
  56. //  prints the knot values
  57. {
  58.     // form
  59.     int $form = eval("getAttr " + $crv + ".form");
  60.     $w = "Form: " + $form + " (0 = open, 1 = closed, 2 = periodic)\n";
  61.     print $w;
  62.     
  63.     // degree
  64.     int $degree = eval("getAttr " + $crv + ".degree");
  65.     $w = "Degree: " + $degree + "\n";
  66.     print $w;
  67.     
  68.     // number of spans
  69.     int $nspans = eval("getAttr " + $crv + ".spans");
  70.     $w = "Nspans: " + $nspans + "\n";
  71.     print $w;
  72.     
  73.     // bounding box (what if it is 2d??)
  74.     float $minBox[] = eval("getAttr " + $crv + ".boundingBoxMin");
  75.     $w = "Bounding box min: " + $minBox[0] + " " + $minBox[1] + " " + $minBox[2] + "\n";
  76.     print $w;
  77.     
  78.     float $maxBox[] = eval("getAttr " + $crv + ".boundingBoxMax");
  79.     $w = "             max: " + $maxBox[0] + " " + $maxBox[1] + " " + $maxBox[2] + "\n";
  80.     print $w;
  81.     
  82. }
  83.  
  84. global proc printNurbsCurveKnots(string $crv)
  85. // Description :
  86. //  prints the knot values
  87. {
  88.  
  89.     float $knots[] = getNurbsCurveKnots($crv);
  90.     print "Knots: ";
  91.     int $numKnots = size($knots);
  92.     for($i=0; $i<$numKnots; $i++) {
  93.         $w = " " + $knots[$i];
  94.         print $w;
  95.     }
  96.     print "\n";
  97.         
  98. }
  99.  
  100. global proc printNurbsCurveCVs(string $crv)
  101. // Description :
  102. //  prints the CV positions in world space
  103. {
  104.         
  105.     // create info Node.
  106.     string $infoNode = `createNode curveInfo`;
  107.     
  108.     // connect curve on to the info node.
  109.     string $outAttr = $crv + ".ws[0]" ;
  110.     string $inAttr = $infoNode + ".ic" ;
  111.     connectAttr $outAttr $inAttr ;
  112.     
  113.     // CVs 
  114.     int $numCVs = `getAttr -size ($infoNode + ".cp")`;
  115.     
  116.     $w = "Number of CVs: " + $numCVs + "\n";
  117.     print $w;
  118.     
  119.     float $cv0[] = `getAttr ($infoNode + ".cp[0]")`;
  120.     int $dim = size($cv0);
  121.     $w = "Dimension of curve: " + $dim + "\n";
  122.     print $w;
  123.     
  124.     // print out the CV positions
  125.     print "CVs in world space:\n";
  126.     for($i=0; $i<$numCVs; $i++) {
  127.         float $cvs[] = `getAttr ($infoNode + ".cp[" + $i + "]")`;
  128.         $w = $i + ": ";
  129.         for($j=0; $j<$dim; $j++) {
  130.             $w +=  $cvs[$j] + " ";
  131.         }
  132.         $w += "\n";
  133.         print $w;
  134.     }
  135.     
  136.     // tidy up
  137.     delete $infoNode ;
  138. }
  139.  
  140. global proc nurbsCurveInformation()
  141. {
  142.     string $w; // for messages
  143.  
  144.     // 0. Grab the select list.
  145.     //
  146.     string $selList[] = `ls -sl`;
  147.  
  148.     // 1. Run filter to select only the NURBS curves and curves on surface
  149.     //
  150.     global int $gSelectNurbsCurvesBit ;
  151.     global int $gSelectCurvesOnSurfacesBit;
  152.  
  153.     string $crvList[] = `filterExpand -ex true 
  154.         -sm $gSelectNurbsCurvesBit 
  155.         -sm $gSelectCurvesOnSurfacesBit $selList` ;    
  156.     int $len = size($crvList) ;
  157.     if( $len == 0 ) {
  158.         print "No NURBS curve selected" ;
  159.         return;
  160.     }
  161.  
  162.     // 2. Work on the last item if more than one NURBS curve in list.
  163.     //
  164.     for($crvNum = 0; $crvNum < $len; $crvNum++) {
  165.         string $crv = $crvList[$crvNum] ;
  166.  
  167.         // print separator if more than one curve
  168.         if($len>1) print "----------------------------------\n";
  169.  
  170.         // curve name
  171.         $w = "Curve: " + $crv + "\n";
  172.         print $w;
  173.         
  174.         // print out the form,degree,nspans,bbox
  175.         printNurbsCurveMiscInfo($crv);
  176.  
  177.         // print out the knots
  178.         printNurbsCurveKnots($crv);
  179.  
  180.         // print out the CVs
  181.         printNurbsCurveCVs($crv);
  182.     }
  183.  
  184.     // print separator if more than one curve
  185.     if($len>1) print "----------------------------------\n";
  186.  
  187.     // reselect curve for which information was returned
  188.     select -r $selList;
  189. }
  190.  
  191.