home *** CD-ROM | disk | FTP | other *** search
- // Copyright (C) 1997-2000 Alias|Wavefront,
- // a division of Silicon Graphics Limited.
- //
- // The information in this file is provided for the exclusive use of the
- // licensees of Alias|Wavefront. Such users have the right to use, modify,
- // and incorporate this code into other products for purposes authorized
- // by the Alias|Wavefront license agreement, without fee.
- //
- // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- //
- // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- // PERFORMANCE OF THIS SOFTWARE.
- // Alias|Wavefront Script File
- // MODIFY THIS AT YOUR OWN RISK
- //
- //
- // Creation Date: Sept 1998
- // Author: Duncan Brinsmead
- //
- // Procedure Name:
- // phoneCord
- //
- // Description:
- // Creates a curve that spirals around a control curve
- // relating the spiral curve to the control with expressions.
- // A loop offset parameter is created for the spiral curve
- // to allow one to dynamically change the size of the loops.
- // The number of loops, however, is fixed at create time.
- //
- // Input Arguments:
- // the name of the control curve
- // the number of loops in the spiral
- //
- // Return Value:
- // None.
- //
-
-
- global proc phoneCord( string $curv, float $numLoops )
- {
- int $numCvs, $i;
- float $p, $min, $max, $angle, $uoff, $voff;
- string $exp_str, $crv, $p_on_c;
- int $cvsPerLoop = 4;
-
- // We base the number of cvs on
- $numCvs = (int) ($numLoops+.5) * $cvsPerLoop;
- $crv = curve( "-d", 3, "-p", 0, 0, 0, "-k", 0, "-k", 0, "-k", 0 );
- $min = getAttr( $curv + ".min" );
- $max = getAttr( $curv + ".max" );
-
- // create a curve with the required number of cvs
- for( $i = 1; $i <= $numCvs; $i++ )
- {
- curve -a -p ((float)$i) 0 0 $crv ;
- }
-
- // Add a loopOffset attribute to the spiral curve
- addAttr -sn loff -ln loopOffset -dv 1.0 -min 0 -max 10 $crv;
- setAttr -keyable on ($crv + ".loopOffset");
-
- for( $i = 0; $i <= $numCvs; $i++ )
- {
- $p = (float)$i/$numCvs;
- $angle = $p * $numLoops * 6.28;
- $uoff = -sin( $angle );
- $voff = cos( $angle );
-
- // we set the offset to zero for the start and end cvs
- if( $i == 0 || $i == $numCvs )
- {
- $uoff = 0;
- $voff = 0;
- }
-
- $p = $min + ($max -$min) * $p;
- // create a pointOnCurve node on the source curve
- $p_on_c = pointOnCurve( "-ch", 1, "-parameter", $p, $curv );
-
- // Create an expression to position the spiral
- // cvs relative to the source curve using the
- // point, normal and tangent from the pointOnCurve node
- // A cross product is performed to give a vector perpendicular
- // to the normal and tangent. The 2D rotation is then mapped to
- // this vector and the normal.
- expression -s ("$u = " + $uoff + " * " + $crv + ".loff;\n"
- + "$v = " + $voff + " * " + $crv + ".loff;\n"
- + "$nx = " + $p_on_c + ".nnx;\n"
- + "$ny = " + $p_on_c + ".nny;\n"
- + "$nz = " + $p_on_c + ".nnz;\n"
- + "$tx = " + $p_on_c + ".ntx;\n"
- + "$ty = " + $p_on_c + ".nty;\n"
- + "$tz = " + $p_on_c + ".ntz;\n"
- + $crv + ".cp[" + $i + "].xv = " + $p_on_c
- + ".px + ($ny * $tz - $ty * $nz) * $u + $nx * $v;\n"
- + $crv + ".cp[" + $i + "].yv = " + $p_on_c
- + ".py + ($tx * $nz - $nx * $tz) * $u + $ny * $v;\n"
- + $crv + ".cp[" + $i + "].zv = " + $p_on_c
- + ".pz + ($nx * $ty - $tx * $ny) * $u + $nz * $v;\n");
- }
-
- }
-