home *** CD-ROM | disk | FTP | other *** search
/ Learning Maya 3 / Learning_Maya_3.iso / docs / mel_scripts / includes / phoneCord.mel < prev    next >
Encoding:
Text File  |  2000-05-17  |  3.9 KB  |  107 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. //
  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. //  Alias|Wavefront Script File
  18. //  MODIFY THIS AT YOUR OWN RISK
  19. //
  20. //
  21. //  Creation Date:  Sept 1998
  22. //  Author:         Duncan Brinsmead
  23. //
  24. //  Procedure Name:
  25. //      phoneCord
  26. //
  27. //  Description:
  28. //      Creates a curve that spirals around a control curve
  29. //      relating the spiral curve to the control with expressions.
  30. //      A loop offset parameter is created for the spiral curve
  31. //      to allow one to dynamically change the size of the loops.
  32. //      The number of loops, however, is fixed at create time.
  33. //
  34. //  Input Arguments:
  35. //      the name of the control curve
  36. //      the number of loops in the spiral
  37. //
  38. //  Return Value:
  39. //      None.
  40. //
  41.  
  42.  
  43. global proc phoneCord( string $curv, float $numLoops )
  44. {
  45.     int $numCvs, $i;
  46.     float $p, $min, $max, $angle, $uoff, $voff;
  47.     string $exp_str, $crv, $p_on_c;
  48.     int $cvsPerLoop = 4;
  49.  
  50.     // We base the number of cvs on
  51.     $numCvs = (int) ($numLoops+.5) * $cvsPerLoop;
  52.     $crv =  curve( "-d", 3, "-p", 0, 0, 0, "-k", 0, "-k", 0, "-k", 0 );
  53.     $min = getAttr( $curv + ".min" );
  54.     $max = getAttr( $curv + ".max" );
  55.  
  56.     // create a curve with the required number of cvs
  57.     for( $i = 1; $i <= $numCvs; $i++ )
  58.     {
  59.          curve -a -p ((float)$i) 0 0 $crv ;
  60.     }
  61.         
  62.     // Add a loopOffset attribute to the spiral curve   
  63.     addAttr -sn loff -ln loopOffset  -dv 1.0 -min 0 -max 10 $crv;
  64.     setAttr -keyable on ($crv + ".loopOffset");
  65.  
  66.     for( $i = 0; $i <= $numCvs; $i++ )
  67.     {
  68.         $p = (float)$i/$numCvs;
  69.         $angle = $p * $numLoops * 6.28;
  70.         $uoff = -sin( $angle );
  71.         $voff = cos( $angle );
  72.  
  73.         // we set the offset to zero for the start and end cvs
  74.         if( $i == 0 || $i == $numCvs )
  75.         {
  76.             $uoff = 0;
  77.             $voff = 0;
  78.         }
  79.  
  80.         $p = $min + ($max -$min) * $p;
  81.         // create a pointOnCurve node on the source curve
  82.         $p_on_c = pointOnCurve( "-ch", 1, "-parameter", $p, $curv  );
  83.  
  84.         // Create an expression to position the spiral
  85.         // cvs relative to the source curve using the
  86.         // point, normal and tangent from the pointOnCurve node
  87.         // A cross product is performed to give a vector perpendicular
  88.         // to the normal and tangent. The 2D rotation is then mapped to
  89.         // this vector and the normal.
  90.         expression -s ("$u = " + $uoff + " * " + $crv + ".loff;\n"
  91.                  + "$v = " + $voff + " * " + $crv + ".loff;\n"
  92.                  + "$nx = " + $p_on_c + ".nnx;\n"
  93.                  + "$ny = " + $p_on_c + ".nny;\n"
  94.                  + "$nz = " + $p_on_c + ".nnz;\n"
  95.                  + "$tx = " + $p_on_c + ".ntx;\n"
  96.                  + "$ty = " + $p_on_c + ".nty;\n"
  97.                  + "$tz = " + $p_on_c + ".ntz;\n"
  98.                  + $crv + ".cp[" + $i + "].xv = " + $p_on_c
  99.                   + ".px + ($ny * $tz - $ty * $nz) * $u + $nx * $v;\n"
  100.                  + $crv + ".cp[" + $i + "].yv = " + $p_on_c
  101.                   + ".py + ($tx * $nz - $nx * $tz) * $u + $ny * $v;\n"
  102.                  + $crv + ".cp[" + $i + "].zv = " + $p_on_c
  103.                   + ".pz + ($nx * $ty - $tx * $ny) * $u + $nz * $v;\n");
  104.     }
  105.    
  106. }
  107.