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

  1. // Copyright (C) 1997-2000 Alias|Wavefront,
  2.  
  3. // a division of Silicon Graphics Limited.
  4.  
  5. //
  6.  
  7. // The information in this file is provided for the exclusive use of the
  8.  
  9. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  10.  
  11. // and incorporate this code into other products for purposes authorized
  12.  
  13. // by the Alias|Wavefront license agreement, without fee.
  14.  
  15. //
  16.  
  17. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  18.  
  19. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  20.  
  21. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  22.  
  23. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  24.  
  25. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  26.  
  27. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  28.  
  29. // PERFORMANCE OF THIS SOFTWARE.
  30.  
  31. //
  32.  
  33. proc int getNurbsSurfaceKnots( 
  34.  
  35.         string $srfName, float $uKnots[], float $vKnots[] )
  36.  
  37. //
  38.  
  39. //      Description : This script will give all the information
  40.  
  41. //      for a NURBS surface.
  42.  
  43. //      
  44.  
  45. //      Usage: select the surface and enter nurbsSurfaceInformation in the command line.
  46.  
  47. {
  48.  
  49.  
  50.  
  51.         // create info Node.
  52.  
  53.         string $infoNode ;
  54.  
  55.         if( catch( $infoNode = `createNode surfaceInfo` ) ) {
  56.  
  57.                 return 1; // failed
  58.  
  59.         } 
  60.  
  61.  
  62.  
  63.         // connect surface on to the info node.
  64.  
  65.         string $outAttr = $srfName + ".local" ; 
  66.  
  67.         string $inAttr = $infoNode + ".is" ;
  68.  
  69.         connectAttr $outAttr $inAttr ;
  70.  
  71.  
  72.  
  73.         // read the knots.
  74.  
  75.         $uKnots = `getAttr ($infoNode + ".knotsU")`;    
  76.  
  77.         $vKnots = `getAttr ($infoNode + ".knotsV")`;    
  78.  
  79.  
  80.  
  81.         // delete surface info node.
  82.  
  83.         delete $infoNode ;
  84.  
  85.  
  86.  
  87.         // worked
  88.  
  89.         return 0;
  90.  
  91. }
  92.  
  93.  
  94.  
  95. global proc string printNurbsSurfaceMiscInfo(string $srf)
  96.  
  97. // Description :
  98.  
  99. //  returns the knot values in a string
  100.  
  101. {
  102.  
  103.         string $w;
  104.  
  105.  
  106.  
  107.         // form
  108.  
  109.         int $formU = eval("getAttr " + $srf + ".formU");
  110.  
  111.         int $formV = eval("getAttr " + $srf + ".formV");
  112.  
  113.         $w = "Form along U, V: " + $formU + " " + $formV + " (0 = open, 1 = closed, 2 = periodic)\n";
  114.  
  115.  
  116.  
  117.         // degree
  118.  
  119.         int $degreeU = eval("getAttr " + $srf + ".degreeU");
  120.  
  121.         int $degreeV = eval("getAttr " + $srf + ".degreeV");
  122.  
  123.         $w += "Degree along U, V: " + $degreeU + " " + $degreeV + "\n";
  124.  
  125.         
  126.  
  127.         // number of spans
  128.  
  129.         int $nspansU = eval("getAttr " + $srf + ".spansU");
  130.  
  131.         int $nspansV = eval("getAttr " + $srf + ".spansV");
  132.  
  133.         $w += "Nspans along U, V: " + $nspansU + " " + $nspansV + "\n";
  134.  
  135.         
  136.  
  137.         // bounding box (what if it is 2d??)
  138.  
  139.         float $minBox[] = eval("getAttr " + $srf + ".boundingBoxMin");
  140.  
  141.         $w += "Bounding box min: " + $minBox[0] + " " + $minBox[1] + " " + $minBox[2];
  142.  
  143.         $w += "\n";
  144.  
  145.         
  146.  
  147.         float $maxBox[] = eval("getAttr " + $srf + ".boundingBoxMax");
  148.  
  149.         $w += "             max: " + $maxBox[0] + " " + $maxBox[1] + " " + $maxBox[2];
  150.  
  151.         $w += "\n";
  152.  
  153.  
  154.  
  155.         return $w;
  156.  
  157. }
  158.  
  159.  
  160.  
  161. global proc string printNurbsSurfaceKnots(string $srf)
  162.  
  163. // Description :
  164.  
  165. //  prints the knot values
  166.  
  167. {
  168.  
  169.         string $w;
  170.  
  171.  
  172.  
  173.         float $uKnots[];
  174.  
  175.         float $vKnots[];
  176.  
  177.         if(getNurbsSurfaceKnots($srf, $uKnots, $vKnots)) {
  178.  
  179.                 return 1; // failed
  180.  
  181.         }
  182.  
  183.  
  184.  
  185.         $w = "Knots along U: ";
  186.  
  187.         int $numKnots = size($uKnots);
  188.  
  189.         for($i=0; $i<$numKnots; $i++) {
  190.  
  191.                 $w += " " + $uKnots[$i];
  192.  
  193.         }
  194.  
  195.         $w += "\n";
  196.  
  197.  
  198.  
  199.         $w += "Knots along V: ";
  200.  
  201.         int $numKnots = size($vKnots);
  202.  
  203.         for($i=0; $i<$numKnots; $i++) {
  204.  
  205.                 $w += " " + $vKnots[$i];
  206.  
  207.         }
  208.  
  209.         $w += "\n";
  210.  
  211.         return $w;
  212.  
  213. }
  214.  
  215.  
  216.  
  217. global proc string printNurbsSurfaceCVs(string $srf)
  218.  
  219. // Description :
  220.  
  221. //  prints the CV positions in world space
  222.  
  223. {
  224.  
  225.                 
  226.  
  227.         string $w;
  228.  
  229.  
  230.  
  231.         // create info Node.
  232.  
  233.         string $infoNode = `createNode surfaceInfo`;
  234.  
  235.         
  236.  
  237.         // connect surface on to the info node.
  238.  
  239.         string $outAttr = $srf + ".ws[0]" ;
  240.  
  241.         string $inAttr = $infoNode + ".is" ;
  242.  
  243.         connectAttr $outAttr $inAttr ;
  244.  
  245.  
  246.  
  247.         // get number of CVs in U and V (always degree+spans even
  248.  
  249.         // for periodics since overlapping CVs are available separately)
  250.  
  251.         int $degreeU = eval("getAttr " + $srf + ".degreeU");
  252.  
  253.         int $nspansU = eval("getAttr " + $srf + ".spansU");
  254.  
  255.         int $numCVsAlongU = $nspansU + $degreeU;
  256.  
  257.  
  258.  
  259.         int $degreeV = eval("getAttr " + $srf + ".degreeV");
  260.  
  261.         int $nspansV = eval("getAttr " + $srf + ".spansV");
  262.  
  263.         int $numCVsAlongV = $nspansV + $degreeV;
  264.  
  265.  
  266.  
  267.         // inform caller that
  268.  
  269.         int $formU = eval("getAttr " + $srf + ".formU");
  270.  
  271.         int $formV = eval("getAttr " + $srf + ".formV");
  272.  
  273.         if($formU == 2 || $formV == 2) {
  274.  
  275.                 print "Note - surface is periodic. CV count and display will including overlapping ones along seam\n";
  276.  
  277.         }
  278.  
  279.  
  280.  
  281.         $w = "Number of CVs in U, V: " + $numCVsAlongU + " " + $numCVsAlongV + "\n";
  282.  
  283.         
  284.  
  285.         // dimension of each CV
  286.  
  287.         int $dim = 0;
  288.  
  289.         if( size(`ls ($srf + ".cv[0][0]")`) > 0 ) {
  290.  
  291.                 $dim = size (eval("getAttr " + $srf + ".cv[0][0]"));
  292.  
  293.                 $w += "Dimension of surface: " + $dim + "\n";
  294.  
  295.         } else {
  296.  
  297.                 $w += "Dimension of surface: No CVs, Dimension unknown\n";
  298.  
  299.         }
  300.  
  301.         
  302.  
  303.         // Get the CV positions including overlapping ones
  304.  
  305.         $w += "CVs in world space:\n";
  306.  
  307.         int $numCV = -1;
  308.  
  309.         for($i=0; $i<$numCVsAlongU; $i++) {
  310.  
  311.                 for($j=0; $j<$numCVsAlongV; $j++) {
  312.  
  313.                         $numCV++;
  314.  
  315.                         float $cvs[] = `getAttr ($infoNode + ".cp["+$numCV+"]")`;
  316.  
  317.                         $w += $i + " " + $j + ": ";
  318.  
  319.                         for($k=0; $k<$dim; $k++) {
  320.  
  321.                                 $w +=  $cvs[$k] + " ";
  322.  
  323.                         }
  324.  
  325.                         $w += "\n";
  326.  
  327.                 }
  328.  
  329.         }
  330.  
  331.         return $w;      
  332.  
  333. }
  334.  
  335.  
  336.  
  337. global proc string getSurfaceInformation( string $srf )
  338.  
  339. {
  340.  
  341.         string $info;
  342.  
  343.  
  344.  
  345.         // get the form,degree,nspans,bbox
  346.  
  347.         $info = printNurbsSurfaceMiscInfo($srf);
  348.  
  349.  
  350.  
  351.         // get the knots
  352.  
  353.         $info += printNurbsSurfaceKnots($srf);
  354.  
  355.  
  356.  
  357.         // get the CVs
  358.  
  359.         $info += printNurbsSurfaceCVs($srf);
  360.  
  361.  
  362.  
  363.         return $info;
  364.  
  365. }
  366.  
  367.  
  368.  
  369. global proc string getSurfacesInformation( string $srf[] )
  370.  
  371. {
  372.  
  373.         string $info = "";
  374.  
  375.         global int $gSelectNurbsSurfacesBit ;
  376.  
  377.         string $srfList[] = `filterExpand -ex true
  378.  
  379.                         -sm $gSelectNurbsSurfacesBit $srf`;
  380.  
  381.  
  382.  
  383.         int $len = size($srfList) ;
  384.  
  385.         if( $len == 0 ) {
  386.  
  387.                 return $info;
  388.  
  389.         }
  390.  
  391.  
  392.  
  393.         for($srfNum = 0; $srfNum < $len; $srfNum++) {
  394.  
  395.                 $info += getSurfaceInformation( $srfList[$srfNum] );
  396.  
  397.         }
  398.  
  399.         return $info;
  400.  
  401. }
  402.  
  403.  
  404.  
  405. global proc nurbsSurfaceInformation()
  406.  
  407. {
  408.  
  409.         string $w; // for messages
  410.  
  411.  
  412.  
  413.         // Get the select list.
  414.  
  415.         string $selList[] = `ls -sl`;
  416.  
  417.  
  418.  
  419.         // Run filter to select only the NURBS surfaces
  420.  
  421.         global int $gSelectNurbsSurfacesBit ;
  422.  
  423.  
  424.  
  425.         string $srfList[] = `filterExpand -ex true 
  426.  
  427.                 -sm $gSelectNurbsSurfacesBit`;
  428.  
  429.         int $len = size($srfList) ;
  430.  
  431.         if( $len == 0 ) {
  432.  
  433.                 print "No NURBS surfaces selected\n" ;
  434.  
  435.                 return;
  436.  
  437.         }
  438.  
  439.  
  440.  
  441.         // Work on the last item if more than one NURBS surface in list.
  442.  
  443.         for($srfNum = 0; $srfNum < $len; $srfNum++) {
  444.  
  445.                 string $srf = $srfList[$srfNum] ;
  446.  
  447.  
  448.  
  449.                 // print separator if more than one surface
  450.  
  451.                 if($len>1) print "----------------------------------\n";
  452.  
  453.  
  454.  
  455.                 // surface name
  456.  
  457.                 $w = "Surface: " + $srf + "\n";
  458.  
  459.                 print $w;
  460.  
  461.  
  462.  
  463.                 string $info = getSurfaceInformation( $srf );
  464.  
  465.                 print $info;
  466.  
  467.         }
  468.  
  469.  
  470.  
  471.         // print separator if more than one surface
  472.  
  473.         if($len>1) print "----------------------------------\n";
  474.  
  475.  
  476.  
  477.         // reselect surface for which information was returned
  478.  
  479.         select -r $selList;
  480.  
  481. }
  482.  
  483.