home *** CD-ROM | disk | FTP | other *** search
/ Learning Maya 3 / Learning_Maya_3.iso / docs / mel_scripts / includes / capNurbsPrimitive.mel < prev    next >
Encoding:
Text File  |  2000-05-17  |  6.3 KB  |  203 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. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Creation Date:  Nov. 18, 1997
  22. //
  23. //
  24. //  Description:
  25. //      Given a selected surface that has nurbs primitive as its immediate
  26. //      creator, cap it with a degenerate surface.
  27. //
  28.  
  29. proc string capDummyCurve( string $parent )
  30. {
  31.     // Make a default curve and parent it under the surface:
  32.     string $curve = `createNode nurbsCurve -p $parent`;
  33.         setAttr -k off ".v";
  34.         setAttr ".cc" -type "nurbsCurve"
  35.             1 1 0 no 3
  36.             2 0 1
  37.             2
  38.             0 0 0
  39.             1 0 0
  40.             ;
  41.         setAttr ".v" false;
  42.         setAttr ".dcv" yes;
  43.         setAttr ".dep" yes;
  44.         setAttr ".dh" yes;
  45.  
  46.     return $curve;
  47. }
  48.  
  49. proc string capSurface( string $maker, string $curve, string $parent )
  50. {
  51.     // Now revolve
  52.     string $revNode = `createNode revolve`;
  53.     setAttr ($revNode + ".ssw") 0.0;
  54.  
  55.     connectAttr ($curve + ".l") ($revNode + ".ic");
  56.     connectAttr ($maker + ".p") ($revNode + ".p");
  57.     connectAttr ($maker + ".ax") ($revNode + ".ax");
  58.  
  59.     expression -s ($revNode + ".esw = " + $maker + ".esw - " + $maker + ".ssw");
  60.     string $cap = `createNode nurbsSurface -p $parent`;
  61.     connectAttr ($revNode + ".os") ($cap + ".cr");
  62.  
  63.     return $cap;
  64. }
  65.  
  66. proc string capCone( string $parent, string $shape, string $cone )
  67. {
  68.     // Make the info node and connect it:
  69.     string $info = `createNode pointOnSurfaceInfo`;
  70.         setAttr ".top" 1;
  71.         setAttr ".u" 0.0;
  72.         setAttr ".v" 0.0;
  73.     connectAttr ($shape + ".local") ($info + ".is");
  74.  
  75.     string $curve = `capDummyCurve $parent`;
  76.  
  77.     // Connect the CVs
  78.     connectAttr ($cone + ".p") ($curve + ".cp[0]");
  79.     connectAttr ($info + ".p") ($curve + ".cp[1]");
  80.  
  81.     string $cap = `capSurface $cone $curve $parent`;
  82.     return $cap;
  83. }
  84.  
  85. proc string capCylinder( string $parent, string $shape, string $cylinder )
  86. {
  87.     // Make the info nodes and connect them:
  88.     string $info1 = `createNode pointOnSurfaceInfo`;
  89.         setAttr ".top" 1;
  90.         setAttr ".u" 0.0;
  91.         setAttr ".v" 0.0;
  92.     connectAttr ($shape + ".local") ($info1 + ".is");
  93.  
  94.     string $info2 = `createNode pointOnSurfaceInfo`;
  95.         setAttr ".top" 1;
  96.         setAttr ".u" 1.0;
  97.         setAttr ".v" 0.0;
  98.     connectAttr ($shape + ".local") ($info2 + ".is");
  99.  
  100.     // Make a default curve:
  101.     string $curve1 = `capDummyCurve $parent`;
  102.  
  103.     // Connect the CVs:
  104.     expression -s ($curve1 + ".cp[0].xv = " + $cylinder + ".px - " + $cylinder +
  105.                    ".r * " + $cylinder + ".hr * 0.5 * " + $cylinder + ".axx");
  106.     expression -s ($curve1 + ".cp[0].yv = " + $cylinder + ".py - " + $cylinder +
  107.                    ".r * " + $cylinder + ".hr * 0.5 * " + $cylinder + ".axy");
  108.     expression -s ($curve1 + ".cp[0].zv = " + $cylinder + ".pz - " + $cylinder +
  109.                    ".r * " + $cylinder + ".hr * 0.5 * " + $cylinder + ".axz");
  110.     connectAttr ($info1 + ".p") ($curve1 + ".cp[1]");
  111.     string $cap1 = `capSurface $cylinder $curve1 $parent`;
  112.  
  113.  
  114.     // Make the second curve:
  115.     string $curve2 = `capDummyCurve $parent`;
  116.  
  117.     // Connect the CVs:
  118.     expression -s ($curve2 + ".cp[0].xv = " + $cylinder + ".px + " + $cylinder +
  119.                    ".r * " + $cylinder + ".hr * 0.5 * " + $cylinder + ".axx");
  120.     expression -s ($curve2 + ".cp[0].yv = " + $cylinder + ".py + " + $cylinder +
  121.                    ".r * " + $cylinder + ".hr * 0.5 * " + $cylinder + ".axy");
  122.     expression -s ($curve2 + ".cp[0].zv = " + $cylinder + ".pz + " + $cylinder +
  123.                    ".r * " + $cylinder + ".hr * 0.5 * " + $cylinder + ".axz");
  124.     connectAttr ($info2 + ".p") ($curve2 + ".cp[1]");
  125.     string $cap2 = `capSurface $cylinder $curve2 $parent`;
  126.  
  127.     return ($cap1 + " " + $cap2);
  128. }
  129.  
  130. proc string capRevolved( string $parent, string $shape, string $revolve )
  131. {
  132.     // Make the info nodes and connect them:
  133.     string $info1 = `createNode pointOnSurfaceInfo`;
  134.         setAttr ".top" 1;
  135.         setAttr ".u" 0.0;
  136.         setAttr ".v" 0.0;
  137.     connectAttr ($shape + ".local") ($info1 + ".is");
  138.  
  139.     string $info2 = `createNode pointOnSurfaceInfo`;
  140.         setAttr ".top" 1;
  141.         setAttr ".u" 1.0;
  142.         setAttr ".v" 0.0;
  143.     connectAttr ($shape + ".local") ($info2 + ".is");
  144.  
  145.     // Make a default curve:
  146.     string $curve1 = `capDummyCurve $parent`;
  147.  
  148.     // Connect the CVs:
  149.     expression -s ($curve1 + ".cp[0].xv = (" + $info1 + ".px - " + $revolve +
  150.                    ".px) * " + $revolve + ".axx");
  151.     expression -s ($curve1 + ".cp[0].yv = (" + $info1 + ".py - " + $revolve +
  152.                    ".py) * " + $revolve + ".axy");
  153.     expression -s ($curve1 + ".cp[0].zv = (" + $info1 + ".pz - " + $revolve +
  154.                    ".pz) * " + $revolve + ".axz");
  155.     connectAttr ($info1 + ".p") ($curve1 + ".cp[1]");
  156.     string $cap1 = `capSurface $revolve $curve1 $parent`;
  157.  
  158.  
  159.     // Make the second curve:
  160.     string $curve2 = `capDummyCurve $parent`;
  161.  
  162.     // Connect the CVs:
  163.     expression -s ($curve2 + ".cp[0].xv = (" + $info2 + ".px - " + $revolve +
  164.                    ".px) * " + $revolve + ".axx");
  165.     expression -s ($curve2 + ".cp[0].yv = (" + $info2 + ".py - " + $revolve +
  166.                    ".py) * " + $revolve + ".axy");
  167.     expression -s ($curve2 + ".cp[0].zv = (" + $info2 + ".pz - " + $revolve +
  168.                    ".pz) * " + $revolve + ".axz");
  169.     connectAttr ($info2 + ".p") ($curve2 + ".cp[1]");
  170.     string $cap2 = `capSurface $revolve $curve2 $parent`;
  171.  
  172.     return ($cap1 + " " + $cap2);
  173. }
  174.  
  175. global proc capNurbsPrimitive()
  176. {
  177.     string $objs[] = `ls -sl -type dagNode`;
  178.     string $chain[];
  179.     string $nt, $parent[];
  180.  
  181.     int $n = size($objs);
  182.     int $i;
  183.     for( $i=0; $i<$n; $i+=1 ) {
  184.         $chain = `listHistory -lf 1 -f 0 $objs[$i]`;
  185.         if( size($chain) > 1 ) {
  186.             $nt = `nodeType $chain[1]`;
  187.             if( "makeNurbCylinder" == $nt ) {
  188.                 $parent = `listRelatives -p $chain[0]`;
  189.                 capCylinder $parent[0] $chain[0] $chain[1];
  190.             }
  191.             else if( "makeNurbCone" == $nt ) {
  192.                 $parent = `listRelatives -p $chain[0]`;
  193.                 capCone $parent[0] $chain[0] $chain[1];
  194.             }
  195.             else if( "revolve" == $nt ) {
  196.                 $parent = `listRelatives -p $chain[0]`;
  197.                 capRevolved $parent[0] $chain[0] $chain[1];
  198.             }
  199.         }
  200.     }
  201. }
  202.  
  203.