// // Copyright 2013 Autodesk, Inc. // // Licensed under the Apache License, Version 2.0 (the "Apache License") // with the following modification; you may not use this file except in // compliance with the Apache License and the following modification to it: // Section 6. Trademarks. is deleted and replaced with: // // 6. Trademarks. This License does not grant permission to use the trade // names, trademarks, service marks, or product names of the Licensor // and its affiliates, except as required to comply with Section 4(c) of // the License and to reproduce the content of the NOTICE file. // // You may obtain a copy of the Apache License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the Apache License with the above modification is // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the Apache License for the specific // language governing permissions and limitations under the Apache License. // // =========================== // USER INTERFACE // =========================== // // Add the UI for the mayaPolySmooth plugin // global proc mayaPolySmooth_addUI() { mayaPolySmooth_removeUI(); // Make sure the "Edit Mesh" menu has been built global string $gPolygonsEditMeshMenu; string $editMeshCreateCmd = `menu -q -pmc $gPolygonsEditMeshMenu`; eval($editMeshCreateCmd); // Add to the menu setParent -m $gPolygonsEditMeshMenu; menuItem -label "+ OSD Subdivide Meshes" -command "mayaPolySmooth({})" "mayaPolySmooth_menuItem"; } // // Remove the UI for the mayaPolySmooth plugin // global proc mayaPolySmooth_removeUI() { if (`menuItem -ex "mayaPolySmooth_menuItem"`) { deleteUI -mi "mayaPolySmooth_menuItem"; } } global proc AEmayaPolySmoothTemplate( string $nodeName ) { editorTemplate -beginScrollLayout; editorTemplate -beginLayout "Subdivision Attributes" -collapse 0; editorTemplate -addControl "displayMesh"; editorTemplate -addControl "subdivisionLevels"; editorTemplate -addControl "recommendedIsolation"; editorTemplate -addControl "vertBoundaryMethod"; editorTemplate -addControl "fvarBoundaryMethod"; editorTemplate -addControl "fvarPropagateCorners"; editorTemplate -addControl "smoothTriangles"; editorTemplate -addControl "creaseMethod"; editorTemplate -endLayout; editorTemplate -addExtraControls; editorTemplate -endScrollLayout; } // =========================== // COMMANDS // =========================== // // Command to OSD Subdivide the selected or specified meshes // global proc string[] mayaPolySmooth(string $meshes[]) { string $mayaPolySmoothNodes[]; // parameter to conditionally insert an intermediate mesh node before the // mayaPolySmooth node to allow editing the base mesh int $showBaseMesh = 1; // Store off the original selection so can restore it below string $origSel[] = `ls -sl`; // If no meshes specified on the commandline, then act on all selected meshes if (`size $meshes` == 0) { $meshes = `ls -sl -dag -type mesh`; } // Loop over each specified mesh and add mayaPolySmooth mesh operator for ($mesh in $meshes) { // Create a temp mesh operation that will guarantee we have construction history string $tmpMeshOp[] = `polyTriangulate -name "dummyMeshOperation#" -ch true -nodeState 1 $mesh`; string $inMeshAttr[] = `listConnections -plugs true ($tmpMeshOp[0]+".inputPolymesh")`; string $outMeshAttr[] = `listConnections -plugs true ($tmpMeshOp[0]+".output")`; // Insert base mesh node string $baseMeshShape; if ($showBaseMesh) { string $meshT[] = `listRelatives -parent $mesh`; $baseMeshShape = `createNode mesh -parent $meshT[0] -name ($mesh+"_base")`; setAttr ($baseMeshShape+".overrideEnabled") 1; setAttr ($baseMeshShape+".overrideShading") 0; connectAttr ($inMeshAttr[0]) ($baseMeshShape+".inMesh"); $inMeshAttr[0] = ($baseMeshShape+".outMesh"); } // Create and connect the mayaPolySmooth node string $mayaPolySmooth = `createNode mayaPolySmooth`; connectAttr ($inMeshAttr[0]) ($mayaPolySmooth+".inputPolymesh"); connectAttr -force ($mayaPolySmooth+".output") ($outMeshAttr[0]); polyMergeUV -d 0.01 -ch 1 $mesh; if ($showBaseMesh) { addAttr -ln "displayMesh" -at "enum" -en "Cage:Smooth:Cage+Smooth" -defaultValue 2 $mayaPolySmooth; setAttr -e-keyable true ($mayaPolySmooth+".displayMesh"); expression -name ($mayaPolySmooth+"_expr") -string ($mesh+".visibility = ("+$mayaPolySmooth+".displayMesh != 0);\nif ("+$mayaPolySmooth+".displayMesh == 1)\n\t"+$mesh+".overrideDisplayType = 0;\nelse\n\t"+$mesh+".overrideDisplayType = 2;\n"+$baseMeshShape+".intermediateObject = ("+$mayaPolySmooth+".displayMesh == 1);") -alwaysEvaluate 0 -unitConversion "none"; setAttr ($mesh+".overrideEnabled") 1; } // Remove the temp mesh operation delete $tmpMeshOp[0]; // Append to the list of nodes that were created $mayaPolySmoothNodes[`size $mayaPolySmoothNodes`] = $mayaPolySmooth; } // Restore original selection select $origSel; // Return created mayaPolySmooth nodes return $mayaPolySmoothNodes; } // // Clearnup the DAG from nodes created with mayaPolySmooth // global proc mayaPolySmoothCleanup() { string $nodes[] = `ls -type mayaPolySmooth`; for ($node in $nodes) { string $mergeUVNodes[] = `listConnections -s on -sh on -t polyMergeUV ($node+".output")`; string $expressionNodes[] = `listConnections -s on -t expression ($node+".displayMesh")`; string $refinedNodes[] = `listConnections -s on -sh on -t mesh ($mergeUVNodes[0]+".output")`; delete $node $mergeUVNodes[0] $refinedNodes[0] $expressionNodes[0]; } }