// =========================================================================== // Copyright 2018 Autodesk, Inc. All rights reserved. // // Use of this software is subject to the terms of the Autodesk license // agreement provided at the time of installation or download, or which // otherwise accompanies this software in either electronic or hard copy form. // =========================================================================== // // // Creation Date: Jan 12, 1998 // // Description: // The attachCurveTangent() procedure takes the selected two curves and // creates a one span curve between them that is tangent to the end of // curve1 and the start of curve2. The result will always be at least a // degree 3 curve. If you don't want to attach the curves then call this // proc with $doAttach = 0. // // Input Arguments: // $doAttach - if 1 attach results otherwise just create new curve // // Return Value: // String. // global proc string attachCurveTangent( int $doAttach ) { global int $gSelectNurbsCurvesBit; string $curvesList[] = `filterExpand -ex true -sm $gSelectNurbsCurvesBit`; int $numCurves = size($curvesList); if ( $numCurves < 2 ) { error((uiRes("m_attachCurveTangent.kErrorSelectTwoCurves")) ); return ""; } // get the last 2 cvs on the first curve and the first 2 cvs on the // second curve // int $degree = eval("getAttr " + $curvesList[0] + ".degree"); int $numSpans = eval("getAttr " + $curvesList[0] + ".spans"); int $numCVs1 = $degree + $numSpans; $degree = eval("getAttr " + $curvesList[1] + ".degree"); $numSpans = eval("getAttr " + $curvesList[1] + ".spans"); int $numCVs2 = $degree + $numSpans; if ( $numCVs1 < 2 || $numCVs2 < 2 ) { error((uiRes("m_attachCurveTangent.kErrorTooFewCVs")) ); return ""; } int $lastCV = $numCVs1 - 1; float $cvLastCurve1[] = `getAttr ($curvesList[0] + ".cp[" + $lastCV + "]")`; $lastCV--; float $cv2ndLastCurve1[] = `getAttr ($curvesList[0] + ".cp[" + $lastCV + "]")`; float $cvOneCurve2[] = `getAttr ($curvesList[1] + ".cp[0]")`; float $cvTwoCurve2[] = `getAttr ($curvesList[1] + ".cp[1]")`; // this is the vector between the two cvs on the first curve // float $vector[3]; $vector[0] = $cvLastCurve1[0] - $cv2ndLastCurve1[0]; $vector[1] = $cvLastCurve1[1] - $cv2ndLastCurve1[1]; $vector[2] = $cvLastCurve1[2] - $cv2ndLastCurve1[2]; // calculate a cv on the line between the two end cvs so that it will // be tangent // float $cvNew1[3]; $cvNew1[0] = $cvLastCurve1[0] + $vector[0]; $cvNew1[1] = $cvLastCurve1[1] + $vector[1]; $cvNew1[2] = $cvLastCurve1[2] + $vector[2]; // this is the vector between the two cvs on the second curve // $vector[0] = $cvOneCurve2[0] - $cvTwoCurve2[0]; $vector[1] = $cvOneCurve2[1] - $cvTwoCurve2[1]; $vector[2] = $cvOneCurve2[2] - $cvTwoCurve2[2]; // calculate a cv on the line between the two start cvs so that it will // be tangent // float $cvNew2[3]; $cvNew2[0] = $cvOneCurve2[0] + $vector[0]; $cvNew2[1] = $cvOneCurve2[1] + $vector[1]; $cvNew2[2] = $cvOneCurve2[2] + $vector[2]; // create the degree 3 curve // string $resultCurve = eval("curve -p " + $cvLastCurve1[0] + " " + $cvLastCurve1[1] + " " + $cvLastCurve1[2] + " -p " + $cvNew1[0] + " " + $cvNew1[1] + " " + $cvNew1[2] + " -p " + $cvNew2[0] + " " + $cvNew2[1] + " " + $cvNew2[2] + " -p " + $cvOneCurve2[0] + " " + $cvOneCurve2[1] + " " + $cvOneCurve2[2] + " -k 0 -k 0 -k 0 -k 1 -k 1 -k 1"); // attach all 3 curves if required // if ( $doAttach == 1 ) { // attach curve1 to the new curve // string $attachedCurve[] = eval("attachCurve -ch 0 -rpo 0 -kmk 1 " + $curvesList[0] + " " + $resultCurve); // the tangent curve is no longer needed // delete $resultCurve; // attach curve2 to the previously attached curves // $attachedCurve = eval("attachCurve -ch 0 -rpo 1 -kmk 1 " + $attachedCurve[0] + " " + $curvesList[1]); $resultCurve = $attachedCurve[0]; } select -r $resultCurve; return $resultCurve; }