OpenSubdiv/examples/osdPolySmooth/osdPolySmooth.mel

124 lines
4.7 KiB
Plaintext
Raw Normal View History

//
// 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 osdPolySmooth plugin
//
global proc osdPolySmooth_addUI()
{
osdPolySmooth_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 "osdPolySmooth({})"
"osdPolySmooth_menuItem";
}
//
// Remove the UI for the osdPolySmooth plugin
//
global proc osdPolySmooth_removeUI()
{
if (`menuItem -ex "osdPolySmooth_menuItem"`) {
deleteUI -mi "osdPolySmooth_menuItem";
}
}
// ===========================
// COMMANDS
// ===========================
//
// Command to OSD Subdivide the selected or specified meshes
//
global proc string[] osdPolySmooth(string $meshes[])
{
string $osdPolySmoothNodes[];
// parameter to conditionally insert an intermediate mesh node before the
// osdPolySmooth 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 osdPolySmooth 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 osdPolySmooth node
string $osdPolySmooth = `createNode osdPolySmooth`;
connectAttr ($inMeshAttr[0]) ($osdPolySmooth+".inputPolymesh");
connectAttr -force ($osdPolySmooth+".output") ($outMeshAttr[0]);
if ($showBaseMesh) {
addAttr -ln "displayMesh" -at "enum" -en "Cage:Smooth:Cage+Smooth" -defaultValue 2 $osdPolySmooth;
setAttr -e-keyable true ($osdPolySmooth+".displayMesh");
expression -name ($osdPolySmooth+"_expr") -string ($mesh+".visibility = ("+$osdPolySmooth+".displayMesh != 0);\nif ("+$osdPolySmooth+".displayMesh == 1)\n\t"+$mesh+".overrideDisplayType = 0;\nelse\n\t"+$mesh+".overrideDisplayType = 2;\n"+$baseMeshShape+".intermediateObject = ("+$osdPolySmooth+".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
$osdPolySmoothNodes[`size $osdPolySmoothNodes`] = $osdPolySmooth;
}
// Restore original selection
select $origSel;
// Return created osdPolySmooth nodes
return $osdPolySmoothNodes;
}