// =========================================================================== // 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. // =========================================================================== // // // // // // // To run: Select surfaces. Type bezierPatches( true, true ); // // Get Bezier patches or Bezier mesh at the current surface degree or // forced to quadratic. // // If you want all surfaces to first be rebuilt into quadratic surfaces, // use "true" for the first argument; otherwise, use false and have the // degree not change. If you choose true, this will do a uniform // rebuild that maintains the number of cvs. For example, a single // cubic patch will become 2x2 quadratic patches. Note, however, that // this will work properly only when you have the default drawing scheme // set for the original surfaces (Hotkey 1). Similarly, periodic surfaces // have problems with rebuild set. // // If you use true as the second argument, you will get a Bezier mesh (single // surface for each surface you start with.) If false, you will get a // separate surface for each Bezier patch. // // To make things cleaner, construction history and "keep originals" // options are forced to false. If you search for "BEHAVIOUR" in this // file, you can edit a couple of variables in that section and change // this. proc rebuildIntoQuadratics( int $v2 ) { // Save the values that we're changing: int $oldType = `optionVar -q rebuildSurfaceType`; int $degU = `optionVar -q rebuildSurfaceTypUniformDegreeU`; int $degV = `optionVar -q rebuildSurfaceTypUniformDegreeV`; int $kcv = `optionVar -q rebuildSurfaceKeepControlPoints`; // Force uniform rebuild into bi-quadratic, same # cvs: optionVar -iv rebuildSurfaceType 0; optionVar -iv rebuildSurfaceTypUniformDegreeU 2; optionVar -iv rebuildSurfaceTypUniformDegreeV 2; optionVar -iv rebuildSurfaceKeepControlPoints 1; string $cmd; if( $v2 ) { $cmd = "performRebuildSurface( 0 )"; } else { $cmd = "rebuildSurfaceToolScript( 0 )"; } eval($cmd); // Restore the values we changed: optionVar -iv rebuildSurfaceType $oldType; optionVar -iv rebuildSurfaceTypUniformDegreeU $degU; optionVar -iv rebuildSurfaceTypUniformDegreeV $degV; optionVar -iv rebuildSurfaceKeepControlPoints $kcv; } proc extractBezierPatches( int $v2, int $dir, int $mesh ) { global int $gSelectNurbsSurfacesBit; string $surfaces[] = `filterExpand -ex true -sm $gSelectNurbsSurfacesBit`; string $tmpSurf[]; string $isos[]; string $cmd; int $openIt; int $i, $n = size($surfaces); if( $n > 0 ) { // If some are periodic, make them open first: for( $i=0; $i<$n; $i+=1 ) { $tmpSurf[0] = $surfaces[$i]; $openIt = false; if( 0 == $dir ) { if( 2 == `getAttr ($tmpSurf[0] + ".fu")` ) { $openIt = true; } } else { if( 2 == `getAttr ($tmpSurf[0] + ".fv")` ) { $openIt = true; } } if( $openIt ) { selectVisibleIsoparms( $tmpSurf, $isos, 0, $dir, true ); if( size($isos) > 0 ) { select -r $isos[0]; if( $v2 ) { $cmd = "performDetach( 0, \"Surface\" )"; } else { $cmd = "detachSurfaceToolScript( 0 )"; } eval( $cmd ); } } } int $ignoredTrims = selectVisibleIsoparms( $surfaces, $isos, 0, $dir, false ); if( $ignoredTrims > 0 ) { warning( `format -s $ignoredTrims (uiRes("m_bezierPatches.kWarningIgnoredTrimInfo"))` ); } $cmd = "select -r "; $n = size($isos); for( $i=0; $i<$n; $i+=1 ) { $cmd += $isos[$i] + " "; } eval($cmd); if( $mesh ) { if( $v2 ) { $cmd = "performInsertKnot( 0, \"Surface\" )"; } else { $cmd = "insertSurfaceToolScript( 0 )"; } } else { if( $v2 ) { $cmd = "performDetach( 0, \"Surface\" )"; } else { $cmd = "detachSurfaceToolScript( 0 )"; } } eval($cmd); deleteInvalidNurbs 1; } } global proc bezierPatches( int $rebuild, int $mesh ) { // BEHAVIOUR: // You can change the value here if you want a different behaviour. int $forceConstructionHistoryTo = false; int $forceKeepOriginalsTo = false; // Remember the original values for history and keep originals: int $origConstructionHistory = `constructionHistory -q -tgl`; int $origKeepOriginalsRebuild = `optionVar -q rebuildSurfaceKeepOriginal`; int $origKeepOriginalsDetach = `optionVar -q detachKeepOriginal`; int $origKeepOriginalsInsert = `optionVar -q insertKnotKeepOriginal`; int $origInsertKnotNumber = `optionVar -q insertKnotNumberOfKnotsToInsert`; int $origInsertKnotAdd = `optionVar -q insertKnotAddOrComplement`; int $origInsertBetween = `optionVar -q insertKnotBetween`; // Force the new values: constructionHistory -tgl $forceConstructionHistoryTo; optionVar -iv rebuildSurfaceKeepOriginal $forceKeepOriginalsTo; optionVar -iv detachKeepOriginal $forceKeepOriginalsTo; optionVar -iv insertKnotKeepOriginal $forceKeepOriginalsTo; optionVar -iv insertKnotAddOrComplement 0; optionVar -iv insertKnotBetween 0; if( $rebuild ) optionVar -iv insertKnotNumberOfKnotsToInsert 2; else optionVar -iv insertKnotNumberOfKnotsToInsert 3; int $version2 = false; // old flag when running Maya 2.0 only if( $rebuild ) { rebuildIntoQuadratics( $version2 ); } extractBezierPatches( $version2, 0, $mesh ); extractBezierPatches( $version2, 1, $mesh ); ls -sl; // Reset the original values: constructionHistory -tgl $origConstructionHistory; optionVar -iv rebuildSurfaceKeepOriginal $origKeepOriginalsRebuild; optionVar -iv detachKeepOriginal $origKeepOriginalsDetach; optionVar -iv insertKnotKeepOriginal $origKeepOriginalsInsert; optionVar -iv insertKnotNumberOfKnotsToInsert $origInsertKnotNumber; optionVar -iv insertKnotAddOrComplement $origInsertKnotAdd; optionVar -iv insertKnotBetween $origInsertBetween; }