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: Oct 23, 1997
- // Author: mgr
- //
- // Description:
- // The attachBlendCurve() procedure takes the selected curve and
- // closes it. The selected curve must be open. The result is a periodic
- // curve with the same number of cvs as the original curve.
- //
- // Input Arguments:
- // None.
- //
- // Return Value:
- // String.
- //
-
- global proc string attachBlendCurve()
- {
- global int $gSelectNurbsCurvesBit;
- string $curvesList[] = `filterExpand -ex true -sm $gSelectNurbsCurvesBit`;
-
- int $numCurves = size($curvesList);
- if ( $numCurves == 0 )
- {
- error("Need to select a curve.");
- return "";
- }
-
- if ( $numCurves > 1 )
- {
- warning("Only the last selected curve will be used for attachBlend.");
- }
-
- string $curve = $curvesList[$numCurves-1];
-
- // check that we have the required # of spans on the curve in order to
- // do the attach blend
- //
- int $degree = eval("getAttr " + $curve + ".degree");
- int $numSpans = eval("getAttr " + $curve + ".spans");
- int $minSpans;
- if ( $degree == 1 ) $minSpans = 3;
- else if ( $degree == 2 ) $minSpans = 4;
- else $minSpans = 2 * ($degree - 1);
- if ( $numSpans < $minSpans )
- {
- warning("The degree " + $degree + " curve has to have at least " + $minSpans + " spans in order to do attach blend.");
- return "";
- }
-
- // close the curve with preserve shape off and keep original on
- //
- string $results[] = `closeCurve -ch 0 -rpo 0 -ps 0 $curve`;
-
- int $resultCount = size($results);
- if ( $resultCount == 0 )
- {
- error("Closing curve failed.");
- return "";
- }
-
- // rebuild the closed curve result to have the #spans as the original curve
- //
- $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]`;
-
- $resultCount = size($results);
- if ( $resultCount == 0 )
- {
- error("Rebuilding curve failed.");
- return "";
- }
-
- // set interior cvs on new periodic curve to match cvs from original curve
- //
- float $origCvs[];
- int $i, $j;
- for ( $i = 1, $j = $i+1; $i < $numSpans; $i++, $j++ )
- {
- $origCvs = eval("getAttr " + $curve + ".controlPoints[" + $j + "]");
- eval("setAttr " + $results[0] + ".controlPoints[" + $i + "] -type double3 " + $origCvs[0] + " " + $origCvs[1] + " " + $origCvs[2]);
- }
-
- // set start cv on new periodic curve to be at the midpoint between the
- // start and end of original curve
- //
- $origCvs = eval("getAttr " + $curve + ".controlPoints[0]");
- float $origCvsEnd[];
- int $numCvsOrig = $numSpans + $degree - 1;
- $origCvsEnd = eval("getAttr " + $curve + ".controlPoints[" + $numCvsOrig + "]");
- for ( $i = 0; $i < 3; $i++ )
- {
- $origCvs[$i] = ($origCvs[$i] + $origCvsEnd[$i]) * 0.5;
- }
- eval("setAttr " + $results[0] + ".controlPoints[0] -type double3 " + $origCvs[0] + " " + $origCvs[1] + " " + $origCvs[2]);
-
- eval("select -r " + $results[0]);
-
- // return the final result curve
- return $results[0];
- }
-