// =========================================================================== // 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 attachCurveMidPoint() procedure takes the selected two curves // (the end of curve1 and the start of curve2) and joins them at the // midpoint of the ends. If you don't want to attach the curves then // call this proc with $doAttach = 0. // // Input Arguments: // $doAttach - if 0 just move cvs, if 1 attach results // // Return Value: // String array. // global proc string[] attachCurveMidPoint( int $doAttach ) { global int $gSelectNurbsCurvesBit; string $curvesList[] = `filterExpand -ex true -sm $gSelectNurbsCurvesBit`; string $resultCurve[]; int $numCurves = size($curvesList); if ( $numCurves < 2 ) { error((uiRes("m_attachCurveMidPoint.kErrorSelectTwoCurves")) ); return $resultCurve; } // make copies of the two curves // $curvesList = `duplicate`; // get the last cv on the first curve and the first cv on the second curve // int $degree = eval("getAttr " + $curvesList[0] + ".degree"); int $numSpans = eval("getAttr " + $curvesList[0] + ".spans"); int $numCVs = $degree + $numSpans; int $lastCV = $numCVs - 1; float $cvCurve1[] = `getAttr ($curvesList[0] + ".cp[" + $lastCV + "]")`; float $cvCurve2[] = `getAttr ($curvesList[1] + ".cp[0]")`; // this is the vector between the two cvs // float $vector[3]; $vector[0] = $cvCurve2[0] - $cvCurve1[0]; $vector[1] = $cvCurve2[1] - $cvCurve1[1]; $vector[2] = $cvCurve2[2] - $cvCurve1[2]; // calculate the midpoint between the two cvs // float $cvNew[3]; $cvNew[0] = $cvCurve1[0] + ($vector[0] * 0.5); $cvNew[1] = $cvCurve1[1] + ($vector[1] * 0.5); $cvNew[2] = $cvCurve1[2] + ($vector[2] * 0.5); // move the end cv of curve1 and the start cv of curve2 to the midpoint // eval("select -r " + $curvesList[0] + ".cv[" + $lastCV + "] " + $curvesList[1] + ".cv[0]"); move -a $cvNew[0] $cvNew[1] $cvNew[2]; // attach the 2 curves if required // if ( $doAttach == 1 ) { // attach curve1 to curve2 // string $attachedCurve[] = eval("attachCurve -ch 0 -rpo 1 -kmk 1 " + $curvesList[0] + " " + $curvesList[1]); // the second copied curve is no longer needed // delete $curvesList[1]; $resultCurve[0] = $attachedCurve[0]; } else { $resultCurve[0] = $curvesList[0]; $resultCurve[1] = $curvesList[1]; } select -r $resultCurve; return $resultCurve; }