Adding Maya osdPolySmooth plugin into OpenSubdiv examples.

Developed by Autodesk Consulting.
This commit is contained in:
Scot Brew 2013-11-13 14:49:33 -08:00
parent 3c4a06dba8
commit b666fa8108
5 changed files with 1392 additions and 0 deletions

View File

@ -4,3 +4,4 @@
This product includes software developed at
Pixar (http://www.pixar.com/).
Autodesk, Inc. (http://www.autodesk.com/).

View File

@ -0,0 +1,110 @@
#
# 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.
#
set(MAYA_FIND_QUIETLY TRUE)
if(NOT MAYA_FOUND)
message(STATUS
"Maya could not be found, so the OpenSubdiv osdPolySmooth plugin "
"will not be available. If you do have Maya installed and see this message, "
"please add your Maya path to cmake/FindMaya.cmake or set it in "
"the MAYA_LOCATION environment variable."
)
return()
endif()
set(PLATFORM_LIBRARIES
${OSD_LINK_TARGET}
)
include_directories(
${PROJECT_SOURCE_DIR}/opensubdiv
${MAYA_INCLUDE_DIRS}
)
set(SHADER_FILES
)
set(SOURCE_FILES
osdPolySmooth.cpp
)
set(HEADER_FILES
)
if(UNIX)
set(PLATFORM_COMPILE_FLAGS
-D_BOOL
-DREQUIRE_IOSTREAM
-DLINUX
)
set(PLATFORM_PLUGIN_EXTENSION
.so
)
set(PLATFORM_LINK_FLAGS
)
endif(UNIX)
if(WIN32)
set(PLATFORM_COMPILE_FLAGS
/D_AFXDLL
/DNT_PLUGIN
/DREQUIRE_IOSTREAM
)
set(PLATFORM_PLUGIN_EXTENSION
.mll
)
set(PLATFORM_LINK_FLAGS
"/export:initializePlugin /export:uninitializePlugin"
)
endif(WIN32)
add_definitions(
${PLATFORM_COMPILE_FLAGS}
)
add_library(maya_polySmoothNode SHARED
${SOURCE_FILES}
${HEADER_FILES}
${SHADER_FILES}
${INC_FILES}
)
set_target_properties(maya_polySmoothNode
PROPERTIES
OUTPUT_NAME "osdPolySmooth"
PREFIX ""
SUFFIX ${PLATFORM_PLUGIN_EXTENSION}
LINK_FLAGS "${PLATFORM_LINK_FLAGS}"
)
target_link_libraries(maya_polySmoothNode
${MAYA_Foundation_LIBRARY}
${MAYA_OpenMaya_LIBRARY}
${MAYA_OpenMayaRender_LIBRARY}
${MAYA_OpenMayaUI_LIBRARY}
${PLATFORM_LIBRARIES}
)
install(TARGETS maya_polySmoothNode DESTINATION ${CMAKE_PLUGINDIR_BASE})

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,72 @@
//
// 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.
//
#ifndef _OsdPolySmooth
#define _OsdPolySmooth
#include <maya/MPxNode.h>
#include <maya/MTypeId.h>
class OsdPolySmooth : public MPxNode
{
public:
OsdPolySmooth();
virtual ~OsdPolySmooth();
// Basic MPxNode static and virtual functions
virtual MStatus compute( const MPlug& plug, MDataBlock& data );
static void* creator();
static MStatus initialize();
// Additional class functions here
public:
// There needs to be a MObject handle declared for each attribute that
// the node will have. These handles are needed for getting and setting
// the values later.
//
// MAYA_NODE_BUILDER:BEG [ATTRIBUTE DECLARATION] ==========
static MObject a_inputPolymesh; // This is a description for this attribute
static MObject a_output; // This is a description for this attribute
static MObject a_subdivisionLevels; // The number of recursive quad subdivisions to perform on each face.
static MObject a_vertBoundaryMethod; // Controls how boundary edges and vertices are interpolated. <ul> <li>Smooth, Edges: Renderman: InterpolateBoundaryEdgeOnly</li> <li>Smooth, Edges and Corners: Renderman: InterpolateBoundaryEdgeAndCorner</li> </ul>
static MObject a_fvarBoundaryMethod; // Controls how boundaries are treated for face-varying data (UVs and Vertex Colors). <ul> <li>Bi-linear (None): Renderman: InterpolateBoundaryNone</li> <li>Smooth, (Edge Only): Renderman: InterpolateBoundaryEdgeOnly</li> <li>Smooth, (Edges and Corners: Renderman: InterpolateBoundaryEdgeAndCorner</li> <li>Smooth, (ZBrush and Maya "Smooth Internal Only"): Renderman: InterpolateBoundaryAlwaysSharp</li> </ul>
static MObject a_fvarPropagateCorners; //
static MObject a_smoothTriangles; // Apply a special subdivision rule be applied to all triangular faces that was empirically determined to make triangles subdivide more smoothly.
static MObject a_creaseMethod; // Controls how boundary edges and vertices are interpolated. <ul> <li>Normal</li> <li>Chaikin: Improves the appearance of multiedge creases with varying weight</li> </ul>
// MAYA_NODE_BUILDER:END [ATTRIBUTE DECLARATION] ==========
// The typeid is a unique 32bit indentifier that describes this node.
// It is used to save and retrieve nodes of this type from the binary
// file format. If it is not unique, it will cause file IO problems.
//
static const MTypeId id;
static const MString typeNameStr;
};
#endif // _OsdPolySmooth

View File

@ -0,0 +1,124 @@
//
// 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;
}