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

  1. //
  2. // Copyright (C) 1997-2000 Alias|Wavefront,
  3. // a division of Silicon Graphics Limited.
  4. //
  5. // The information in this file is provided for the exclusive use of the
  6. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  7. // and incorporate this code into other products for purposes authorized
  8. // by the Alias|Wavefront license agreement, without fee.
  9. //
  10. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  11. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  12. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  13. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  14. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  15. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  16. // PERFORMANCE OF THIS SOFTWARE.
  17. //
  18. // Alias|Wavefront Script File
  19. // MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Creation Date:  Oct 23, 1997
  22. //  Author:        mgr 
  23. //
  24. //  Description:
  25. //      The attachBlendCurve() procedure takes the selected curve and 
  26. //        closes it. The selected curve must be open. The result is a periodic
  27. //         curve with the same number of cvs as the original curve.
  28. //
  29. //  Input Arguments:
  30. //      None.
  31. //
  32. //  Return Value:
  33. //      String.
  34. //
  35.  
  36. global proc string attachBlendCurve()
  37. {
  38.     global int $gSelectNurbsCurvesBit;
  39.     string $curvesList[] = `filterExpand -ex true -sm $gSelectNurbsCurvesBit`;
  40.  
  41.     int $numCurves = size($curvesList);
  42.     if ( $numCurves == 0 )
  43.     {
  44.         error("Need to select a curve.");
  45.         return "";
  46.     }
  47.  
  48.     if ( $numCurves > 1 )
  49.     {
  50.         warning("Only the last selected curve will be used for attachBlend.");
  51.     }
  52.  
  53.     string $curve = $curvesList[$numCurves-1];
  54.     
  55.     // check that we have the required # of spans on the curve in order to
  56.     // do the attach blend
  57.     //
  58.     int $degree = eval("getAttr " + $curve + ".degree");
  59.     int $numSpans = eval("getAttr " + $curve + ".spans");
  60.     int $minSpans;
  61.     if ( $degree == 1 ) $minSpans = 3;
  62.     else if ( $degree == 2 ) $minSpans = 4;
  63.     else $minSpans = 2 * ($degree - 1);
  64.     if ( $numSpans < $minSpans ) 
  65.     {
  66.         warning("The degree " + $degree + " curve has to have at least " + $minSpans + " spans in order to do attach blend.");
  67.         return "";
  68.     }
  69.  
  70.     // close the curve with preserve shape off and keep original on
  71.     //
  72.     string $results[] = `closeCurve -ch 0 -rpo 0 -ps 0 $curve`;
  73.  
  74.     int $resultCount = size($results);
  75.     if ( $resultCount == 0 ) 
  76.     {
  77.         error("Closing curve failed.");
  78.         return "";
  79.     }
  80.  
  81.     // rebuild the closed curve result to have the #spans as the original curve
  82.     //
  83.     $results = `rebuildCurve -ch 0 -rpo 1 -rt 0 -kr 0 -kcp 0 -kep 1 -kt 0 -s $numSpans -d $degree -tol 0.05 $results[0]`;
  84.  
  85.     $resultCount = size($results);
  86.     if ( $resultCount == 0 ) 
  87.     {
  88.         error("Rebuilding curve failed.");
  89.         return "";
  90.     }
  91.  
  92.     // set interior cvs on new periodic curve to match cvs from original curve
  93.     //
  94.     float $origCvs[];
  95.     int $i, $j;
  96.     for ( $i = 1, $j = $i+1; $i < $numSpans; $i++, $j++ )
  97.     {
  98.         $origCvs = eval("getAttr " + $curve + ".controlPoints[" + $j + "]");
  99.         eval("setAttr " + $results[0] + ".controlPoints[" + $i + "] -type double3 " + $origCvs[0] + " " + $origCvs[1] + " " + $origCvs[2]);
  100.     }
  101.  
  102.     // set start cv on new periodic curve to be at the midpoint between the
  103.     // start and end of original curve
  104.     //
  105.     $origCvs = eval("getAttr " + $curve + ".controlPoints[0]");
  106.     float $origCvsEnd[];
  107.     int $numCvsOrig = $numSpans + $degree - 1;
  108.     $origCvsEnd = eval("getAttr " + $curve + ".controlPoints[" + $numCvsOrig + "]");
  109.     for ( $i = 0; $i < 3; $i++ )
  110.     {
  111.         $origCvs[$i] = ($origCvs[$i] + $origCvsEnd[$i]) * 0.5;
  112.     }
  113.     eval("setAttr " + $results[0] + ".controlPoints[0] -type double3 " + $origCvs[0] + " " + $origCvs[1] + " " + $origCvs[2]);
  114.  
  115.     eval("select -r " + $results[0]);
  116.  
  117.     // return the final result curve
  118.     return $results[0];
  119. }
  120.