OpenSubdiv/examples/osdPolySmooth/osdPolySmooth.mel
manuelk b79ebd796c Fix UV merging in osdPolySmooth code example
Because our plugin sets UVs with individual face-varying vertices,
Maya interprets the buffer as discontinuous everywhere. Adding a
node in the graph that merges UVs along non-boundary edges resolves
this problem (until the plugin outputs the UV vertex indices in
an aggregated manner).
2014-01-17 15:16:46 -08:00

148 lines
5.4 KiB
Plaintext

//
// 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";
}
}
global proc AEosdPolySmoothTemplate( 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[] 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]);
polyMergeUV -d 0.01 -ch 1 $mesh;
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;
}