// =========================================================================== // 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: Mar. 14, 1997 // // Description: // The breakTangent() procedure adds enough knots at the selected // isoparams that the tangent can be broken once you start editing. // // Input Arguments: // None. // // Return Value: // None. // proc performBreakTangentPreset( int $history, int $whichDirection, string $surfaces[], string $results[] ) // // Description: // This proc takes the given surface isoparms and groups // them according to the surface, then executes an "insertKnotSurface" // command on each surface, with the high enough multiplicity // to give us a full multiple knot and thus "Bezier" patches. // So, not really just allowing a tangent break. // // whichDirection = 0 - whatever the selection is // whichDirection = 1 - if points selected, only insert in U // whichDirection = 2 - if points selected, only insert in V { int $addOrComplement = true; int $multi = false; int $numKnots = 7; int $rpo = true; // We're just using insert to do it... string $cmd = "insertKnotSurface" + " -ch " + $history + " -nk " + $numKnots + " -add " + $addOrComplement + " -ib " + $multi; string $insertResults[]; // for each string returned from groupObjectsByName, put together // an insertKnotSurface cmd and execute it. // string $groupStrings[]; $groupStrings = groupObjectsByName( $surfaces, "\\." ); int $numStrings = size( $groupStrings ); string $execCmd; for( $i = 0; $i < $numStrings; $i ++ ) { // append appropriate replaceOriginal flag here $execCmd = $cmd + " -rpo " + $rpo + " "; string $parms[]; $numParms = `tokenize $groupStrings[$i] $parms`; string $foundUStr = `match "\\.u\\[" $groupStrings[$i]`; string $foundVStr = `match "\\.v\\[" $groupStrings[$i]`; string $foundUVStr = `match "\\.uv\\[" $groupStrings[$i]`; int $foundU = (size($foundUStr) > 0); int $foundV = (size($foundVStr) > 0); int $foundUV = (size($foundUVStr) > 0); if( $numParms > 1 || $foundUV ) { // Get the surface name // string $surfaceName[]; tokenize $groupStrings[$i] "\\." $surfaceName; int $doneSome = false; // Format the parameter values with "-p" flag // Direction is set with "-d 1" flag // if( $foundU > 0 || ($foundUV > 0 && ((0 == $whichDirection) || (1 == $whichDirection)))) { $execCmd += " -d 1 "; $doneSome = true; int $p; for( $p = 0; $p < $numParms; $p ++ ) { string $regularExpr = "\\.u\\[.*\\]"; string $parm = match($regularExpr, $parms[$p]); $strLen = size($parm); if( $strLen > 0 ) { // we could have an isoparam like .u[][a:b] // so, we also do a tokenize filtering only the .u[] // portion out. // string $ucomp[] ; int $nc ; $nc = `tokenize $parm "]" $ucomp` ; if( size($ucomp) > 0 ) { $parm = substring( $ucomp[0], 4, $strLen-1 ); // append to $execCmd as a -p flag // $execCmd += " -p "; $execCmd += $parm; } } else { string $regularExpr = "\\.uv\\[.*\\]\\[.*\\]"; string $parm = match($regularExpr, $parms[$p]); $strLen = size($parm); if( $strLen > 0 ) { // change ".uv[0.444][0.66]" to ".uv[0.44" $parm = substitute( "\\]\\[.*\\]", $parm, "" ); $strLen = size($parm); $parm = substring( $parm, 5, $strLen ); $execCmd += " -p "; $execCmd += $parm; } } } // Add the surface name // $execCmd += " "; $execCmd += $surfaceName[0]; // If V direction is also specified, then execute // the U direction insert cmd right here // if( ($foundV > 0 || $foundUV > 0) ) { // Insert command returns the new surface and surface node. // Substitute the new surface as the surface name so if // inserting in the V direction too, it will be // chained in sequence. // Also, copy the results for this insert commadn to // the results array. // string $tempResults[]; $tempResults = evalEcho( $execCmd ); int $numTempResults = size( $tempResults ); if( $numTempResults == 2) { $surfaceName[0] = $tempResults[0]; int $numResults = size( $results ); for( $j = 0; $j < $numTempResults; $j ++, $numResults ++ ) { $results[$numResults] = $tempResults[$j]; } } } } if( $foundV > 0 || ($foundUV > 0 && ((0 == $whichDirection) || (2 == $whichDirection)))) { // If U direction was already executed, then make sure // we do "-rpo 1". Otherwise, just set the direction. // if( $doneSome ) { $execCmd = $cmd + " -rpo 1 -d 0"; } else { // not sure why this did not do rpo before. So // make it do it now (mwatt) $execCmd = $cmd + " -rpo 1 -d 0 "; } int $p; for( $p = 0; $p < $numParms; $p ++ ) { string $regularExpr = "\\.v\\[.*\\]"; string $parm = match($regularExpr, $parms[$p]); $strLen = size($parm); if( $strLen > 0 ) { // we could have an isoparam like .v[][a:b] // so, we also do a tokenize filtering only the .v[] // portion out. // string $vcomp[] ; int $nc ; $nc = `tokenize $parm "]" $vcomp` ; if( size($vcomp) > 0 ) { $parm = substring( $vcomp[0], 4, $strLen-1 ); // append to $execCmd as a -p flag $execCmd += " -p "; $execCmd += $parm; } } else { string $regularExpr = "\\.uv\\[.*\\]\\[.*\\]"; string $parm = match($regularExpr, $parms[$p]); $strLen = size($parm); if( $strLen > 0 ) { // change ".uv[0.444][0.66]" to "0.66]" $parm = substitute( "\\.uv\\[.*\\]\\[",$parm,""); $strLen = size($parm); $parm = substring( $parm, 1, $strLen-1 ); $execCmd += " -p "; $execCmd += $parm; } } } // Add the surface name // $execCmd += " "; $execCmd += $surfaceName[0]; } } else { $execCmd += $groupStrings[$i]; } // execute $cmd + $groupStrings[$i] if( catch( $insertResults = evalEcho( $execCmd))) { warning(`format -s $cmd -s $groupStrings[$i] (uiRes("m_breakTangent.kWarningProblemEvaluatingBreakTangent"))` ); } else { int $j; int $numResults = size( $results ); int $numInsertResults = size( $insertResults ); for( $j = 0; $j < $numInsertResults; $j ++, $numResults ++ ) { $results[$numResults] = $insertResults[$j]; } } } if( 0 == size($results) ) { error (uiRes("m_breakTangent.kBreakTangentFailed")); } } global proc breakTangent() { int $doHistory = `constructionHistory -q -tgl`; int $doHilite = false; // Get a list of each type of acceptable object type - surfaces and curves. // global int $gSelectSurfaceParmPointsBit; global int $gSelectEditPointsBit; global int $gSelectIsoparmsBit; string $surfaceIsoparmList[] = `filterExpand -ex true -sm $gSelectIsoparmsBit -sm $gSelectSurfaceParmPointsBit`; if( 0 == size($surfaceIsoparmList) ) { error (uiRes("m_breakTangent.kBreakTangentInvalSelection")); return; } string $curr = `currentCtx`; int $whichDirection = 0; if( `curveEditorCtx -exists $curr` ) { $whichDirection = `curveEditorCtx -q -dir $curr`; } string $surfaceResults[]; // if( size($surfaceIsoparmList) > 0 ) { if( !$doHilite ) $doHilite = `shouldHiliteAfterCompute`; performBreakTangentPreset( $doHistory, $whichDirection, $surfaceIsoparmList, $surfaceResults ); } if( size($surfaceResults) == 0 ) { error (uiRes("m_breakTangent.kBreakTangentImproperSelection")); } else { // Select all the results with one select command. // string $selectString; $selectString = "select -r "; int $i; int $numSurfaces = size($surfaceIsoparmList); for( $i = 0; $i < $numSurfaces; $i ++ ) { $selectString += $surfaceIsoparmList[$i]; $selectString += " "; } $selectString += ";"; if( $doHilite ) $selectString += "hilite;"; eval($selectString); } }