diff --git a/.travis.yml b/.travis.yml index 2c0abe8e..b96d31ca 100644 --- a/.travis.yml +++ b/.travis.yml @@ -60,7 +60,7 @@ before_script: script: - mkdir build && cd build - - cmake -DNO_TBB=1 -DNO_OMP=1 -DNO_CUDA=1 -DNO_OPENCL=1 -DNO_MAYA=1 -DNO_PTEX=1 -DNO_GLTESTS=1 -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ .. + - cmake -DNO_TBB=1 -DNO_OMP=1 -DNO_CUDA=1 -DNO_OPENCL=1 -DNO_PTEX=1 -DNO_GLTESTS=1 -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ .. - make - make test diff --git a/CMakeLists.txt b/CMakeLists.txt index 98c09afc..11318499 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -267,13 +267,11 @@ set(CMAKE_SUPPRESS_REGENERATION TRUE) option(PTEX_LOCATION "Path to Ptex" "") option(GLEW_LOCATION "Path to GLEW" "") option(GLFW_LOCATION "Path to GLFW" "") -option(MAYA_LOCATION "Path to Maya" "") option(NO_LIB "Disable the opensubdiv libs build (caveat emptor)" OFF) option(NO_EXAMPLES "Disable examples build" OFF) option(NO_TUTORIALS "Disable tutorials build" OFF) option(NO_REGRESSION "Disable regression tests build" OFF) -option(NO_MAYA "Disable Maya plugin build" OFF) option(NO_PTEX "Disable PTex support" OFF) option(NO_DOC "Disable documentation build" OFF) option(NO_OMP "Disable OpenMP backend" OFF) @@ -334,10 +332,6 @@ if (WIN32 AND NOT NO_DX) find_package(DXSDK) endif() -if (NOT NO_MAYA) -find_package(Maya 201200) -endif() - if (NOT NO_DOC) find_package(Doxygen 1.8.4) find_package(Docutils 0.9) @@ -506,22 +500,6 @@ else() endif() endif() -if (NOT NO_MAYA) - if(MAYA_FOUND) - add_definitions( - -DOPENSUBDIV_HAS_MAYA - ) - else() - message(WARNING - "Maya was not found : the OpenSubdiv mayaViwer plugin will not be " - "available. If you do have Maya installed and see this message, " - "please add your Maya path to FindMaya.cmake in " - "${PROJECT_SOURCE_DIR}/cmake or set it through the MAYA_LOCATION " - "cmake command line argument or environment variable." - ) - endif() -endif() - # Link examples & regressions dynamically against Osd if( OSD_GPU ) set( OSD_LINK_TARGET osd_dynamic_cpu osd_dynamic_gpu ) diff --git a/README.md b/README.md index 2f1272ba..b8ca21b4 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,7 @@ For more details about OpenSubdiv, see [Pixar Graphics Technologies](http://grap ``` "c:/Program Files (x86)/CMake/bin/cmake.exe" ^ -G "Visual Studio 12 Win64" ^ - -D NO_MAYA=1 -D NO_PTEX=1 -D NO_DOC=1 ^ + -D -D NO_PTEX=1 -D NO_DOC=1 ^ -D NO_OMP=1 -D NO_TBB=1 -D NO_CUDA=1 -D NO_OPENCL=1 -D NO_CLEW=1 ^ -D "GLEW_LOCATION=*YOUR GLEW INSTALL LOCATION*" ^ -D "GLFW_LOCATION=*YOUR GLFW INSTALL LOCATION*" ^ @@ -95,7 +95,7 @@ For more details about OpenSubdiv, see [Pixar Graphics Technologies](http://grap ### Linux ``` -cmake -D NO_MAYA=1 -D NO_PTEX=1 -D NO_DOC=1 \ +cmake -D -D NO_PTEX=1 -D NO_DOC=1 \ -D NO_OMP=1 -D NO_TBB=1 -D NO_CUDA=1 -D NO_OPENCL=1 -D NO_CLEW=1 \ -D GLEW_LOCATION="*YOUR GLEW INSTALL LOCATION*" \ -D GLFW_LOCATION="*YOUR GLFW INSTALL LOCATION*" \ @@ -106,7 +106,7 @@ make ### OSX ``` -cmake -D NO_MAYA=1 -D NO_PTEX=1 -D NO_DOC=1 \ +cmake -D -D NO_PTEX=1 -D NO_DOC=1 \ -D NO_OMP=1 -D NO_TBB=1 -D NO_CUDA=1 -D NO_OPENCL=1 -D NO_CLEW=1 \ -D GLFW_LOCATION="*YOUR GLFW INSTALL LOCATION*" \ .. @@ -125,13 +125,11 @@ make -DPTEX_LOCATION=[path to Ptex] -DGLEW_LOCATION=[path to GLEW] -DGLFW_LOCATION=[path to GLFW] --DMAYA_LOCATION=[path to Maya] -DNO_LIB=1 // disable the opensubdiv libs build (caveat emptor) -DNO_EXAMPLES=1 // disable examples build -DNO_TUTORIALS=1 // disable tutorials build -DNO_REGRESSION=1 // disable regression tests build --DNO_MAYA=1 // disable Maya plugin build -DNO_PTEX=1 // disable PTex support -DNO_DOC=1 // disable documentation build -DNO_OMP=1 // disable OpenMP diff --git a/appveyor.yml b/appveyor.yml index 54fb5fb2..8f8b77df 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -20,7 +20,7 @@ build_script: - mkdir build - cd build - cmake --version - - cmake -G "Visual Studio %Configuration%" -DNO_TBB=1 -DNO_OMP=1 -DNO_CUDA=1 -DNO_MAYA=1 -DNO_PTEX=1 -DNO_DOC=1 -DNO_CLEW=1 -DNO_OPENGL=1 -DNO_OPENCL=1 .. + - cmake -G "Visual Studio %Configuration%" -DNO_TBB=1 -DNO_OMP=1 -DNO_CUDA=1 -DNO_PTEX=1 -DNO_DOC=1 -DNO_CLEW=1 -DNO_OPENGL=1 -DNO_OPENCL=1 .. - cmake --build . --config Release test_script: diff --git a/cmake/FindMaya.cmake b/cmake/FindMaya.cmake deleted file mode 100644 index d4027c72..00000000 --- a/cmake/FindMaya.cmake +++ /dev/null @@ -1,256 +0,0 @@ -# -# Copyright 2013 Pixar -# -# 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. -# - -# - Maya finder module -# This module searches for a valid Maya instalation. -# It searches for Maya's devkit, libraries, executables -# and related paths (scripts) -# -# Variables that will be defined: -# MAYA_FOUND Defined if a Maya installation has been detected -# MAYA_EXECUTABLE Path to Maya's executable -# MAYA__FOUND Defined if has been found -# MAYA__LIBRARY Path to library -# MAYA_INCLUDE_DIRS Path to the devkit's include directories -# MAYA_API_VERSION Maya version (6 digits) -# -# IMPORTANT: Currently, there's only support for OSX platform and Maya version 2012. - -#============================================================================= -# Copyright 2011-2012 Francisco Requena -# -# Distributed under the OSI-approved BSD License (the "License"); -# see accompanying file Copyright.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even the -# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -# See the License for more information. -#============================================================================= -# (To distribute this file outside of CMake, substitute the full -# License text for the above reference.) - -if(APPLE) - find_path(MAYA_BASE_DIR - ../../devkit/include/maya/MFn.h - HINTS - "${MAYA_LOCATION}" - "$ENV{MAYA_LOCATION}" - "/Applications/Autodesk/maya2015/Maya.app/Contents" - "/Applications/Autodesk/maya2014/Maya.app/Contents" - "/Applications/Autodesk/maya2013.5/Maya.app/Contents" - "/Applications/Autodesk/maya2013/Maya.app/Contents" - "/Applications/Autodesk/maya2012.17/Maya.app/Contents" - "/Applications/Autodesk/maya2012/Maya.app/Contents" - "/Applications/Autodesk/maya2011/Maya.app/Contents" - "/Applications/Autodesk/maya2010/Maya.app/Contents" - ) - find_path(MAYA_LIBRARY_DIR libOpenMaya.dylib - HINTS - "${MAYA_LOCATION}" - "$ENV{MAYA_LOCATION}" - "${MAYA_BASE_DIR}" - PATH_SUFFIXES - Maya.app/contents/MacOS/ - DOC - "Maya's libraries path" - ) -endif(APPLE) - -if(UNIX) - find_path(MAYA_BASE_DIR - include/maya/MFn.h - HINTS - "${MAYA_LOCATION}" - "$ENV{MAYA_LOCATION}" - "/usr/autodesk/maya2015-x64" - "/usr/autodesk/maya2014-x64" - "/usr/autodesk/maya2013-x64" - "/usr/autodesk/maya2012.17-x64" - "/usr/autodesk/maya2012-x64" - "/usr/autodesk/maya2011-x64" - "/usr/autodesk/maya2010-x64" - ) - find_path(MAYA_LIBRARY_DIR - libOpenMaya.so - HINTS - "${MAYA_LOCATION}" - "$ENV{MAYA_LOCATION}" - "${MAYA_BASE_DIR}" - PATH_SUFFIXES - lib/ - DOC - "Maya's libraries path" - ) -endif(UNIX) - -if(WIN32) - find_path(MAYA_BASE_DIR - include/maya/MFn.h - HINTS - "${MAYA_LOCATION}" - "$ENV{MAYA_LOCATION}" - "C:/Program Files/Autodesk/Maya2015.5-x64" - "C:/Program Files/Autodesk/Maya2015.5" - "C:/Program Files/Autodesk/Maya2014.5-x64" - "C:/Program Files/Autodesk/Maya2014.5" - "C:/Program Files/Autodesk/Maya2013.5-x64" - "C:/Program Files/Autodesk/Maya2013.5" - "C:/Program Files (x86)/Autodesk/Maya2013.5" - "C:/Autodesk/maya-2013.5x64" - "C:/Program Files/Autodesk/Maya2013-x64" - "C:/Program Files/Autodesk/Maya2013" - "C:/Program Files (x86)/Autodesk/Maya2013" - "C:/Autodesk/maya-2013x64" - "C:/Program Files/Autodesk/Maya2012-x64" - "C:/Program Files/Autodesk/Maya2012" - "C:/Program Files (x86)/Autodesk/Maya2012" - "C:/Autodesk/maya-2012x64" - "C:/Program Files/Autodesk/Maya2011-x64" - "C:/Program Files/Autodesk/Maya2011" - "C:/Program Files (x86)/Autodesk/Maya2011" - "C:/Autodesk/maya-2011x64" - "C:/Program Files/Autodesk/Maya2010-x64" - "C:/Program Files/Autodesk/Maya2010" - "C:/Program Files (x86)/Autodesk/Maya2010" - "C:/Autodesk/maya-2010x64" - ) - find_path(MAYA_LIBRARY_DIR - OpenMaya.lib - HINTS - "${MAYA_LOCATION}" - "$ENV{MAYA_LOCATION}" - "${MAYA_BASE_DIR}" - PATH_SUFFIXES - lib/ - DOC - "Maya's libraries path" - ) -endif(WIN32) - -find_path(MAYA_INCLUDE_DIR - maya/MFn.h - HINTS - "${MAYA_LOCATION}" - "$ENV{MAYA_LOCATION}" - "${MAYA_BASE_DIR}" - PATH_SUFFIXES - ../../devkit/include/ - include/ - DOC - "Maya's devkit headers path" -) - -find_path(MAYA_LIBRARY_DIR - OpenMaya - HINTS - "${MAYA_LOCATION}" - "$ENV{MAYA_LOCATION}" - "${MAYA_BASE_DIR}" - PATH_SUFFIXES - ../../devkit/include/ - include/ - DOC - "Maya's devkit headers path" -) - -list(APPEND MAYA_INCLUDE_DIRS ${MAYA_INCLUDE_DIR}) - -find_path(MAYA_DEVKIT_INC_DIR - GL/glext.h - HINTS - "${MAYA_LOCATION}" - "$ENV{MAYA_LOCATION}" - "${MAYA_BASE_DIR}" - PATH_SUFFIXES - /devkit/plug-ins/ - DOC - "Maya's devkit headers path" -) - -list(APPEND MAYA_INCLUDE_DIRS ${MAYA_DEVKIT_INC_DIR}) - -foreach(MAYA_LIB - OpenMaya - OpenMayaAnim - OpenMayaFX - OpenMayaRender - OpenMayaUI - Image - Foundation - IMFbase - tbb - cg - cgGL) - - find_library(MAYA_${MAYA_LIB}_LIBRARY - ${MAYA_LIB} - HINTS - "${MAYA_LOCATION}" - "$ENV{MAYA_LOCATION}" - "${MAYA_BASE_DIR}" - PATH_SUFFIXES - MacOS/ - lib/ - DOC - "Maya's ${MAYA_LIB} library path" - ) - - - if (MAYA_${MAYA_LIB}_LIBRARY) - list(APPEND MAYA_LIBRARIES ${MAYA_${MAYA_LIB}_LIBRARY}) - endif() -endforeach(MAYA_LIB) - -find_program(MAYA_EXECUTABLE - maya - HINTS - "${MAYA_LOCATION}" - "$ENV{MAYA_LOCATION}" - "${MAYA_BASE_DIR}" - PATH_SUFFIXES - MacOS/ - bin/ - DOC - "Maya's executable path" -) - -if(MAYA_INCLUDE_DIRS AND EXISTS "${MAYA_INCLUDE_DIR}/maya/MTypes.h") - - # Tease the MAYA_API_VERSION numbers from the lib headers - file(STRINGS ${MAYA_INCLUDE_DIR}/maya/MTypes.h TMP REGEX "#define MAYA_API_VERSION.*$") - string(REGEX MATCHALL "[0-9]+" MAYA_API_VERSION ${TMP}) -endif() - -# handle the QUIETLY and REQUIRED arguments and set MAYA_FOUND to TRUE if -# all listed variables are TRUE -include(FindPackageHandleStandardArgs) - -find_package_handle_standard_args(Maya - REQUIRED_VARS - MAYA_EXECUTABLE - MAYA_INCLUDE_DIRS - MAYA_LIBRARIES - VERSION_VAR - MAYA_API_VERSION -) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 52c767da..103a4a44 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -79,7 +79,3 @@ if (DXSDK_FOUND AND NOT NO_DX) endif() - -if (MAYA_FOUND AND (NOT NO_MAYA)) - add_subdirectory(mayaPolySmooth) -endif() diff --git a/examples/common/maya_util.h b/examples/common/maya_util.h deleted file mode 100644 index 37131415..00000000 --- a/examples/common/maya_util.h +++ /dev/null @@ -1,137 +0,0 @@ -// -// Copyright 2013 Pixar -// -// 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 _EXAMPLE_MAYA_UTIL_H_ -#define _EXAMPLE_MAYA_UTIL_H_ - -#include -#include -#include -#include -#include -#include -#include -#include - - -#define CHECK_GL_ERROR(...) \ - if (GLuint err = glGetError()) { \ - fprintf(stderr, "GL error %x :", err); \ - fprintf(stderr, "%s", __VA_ARGS__); \ - } - - -#define MERROR(status, msg) \ - { \ - MGlobal::displayError(MString(msg)); \ - fprintf(stderr, "%s [ %s:%d ]\n", msg, __FILE__, __LINE__); \ - } - -#define MCHECK_PRINT(status, msg) \ - if (status.error()) \ - { \ - MGlobal::displayError(MString(msg)); \ - fprintf(stderr, "%s [ %s:%d ]\n", msg, __FILE__, __LINE__); \ - } - -#define MCHECK_RETURN(status, msg) \ - if (status.error()) \ - { \ - MGlobal::displayError(MString(msg)); \ - fprintf(stderr, "%s [ %s:%d ]\n", msg, __FILE__, __LINE__); \ - return status; \ - } - - -// -// Templated funtions able to retrieve any attribute that -// can be retrieved via the overloaded MPlug::getValue() -// methods. Any attributes that need MPlug::getData() -// Need to use non-templated functions below -// -template static int -findAttribute( MFnDependencyNode &depFn, const char *attr, T *val ) -{ - MStatus stat; - MPlug plug; - T tmp; - - // careful version - returns -1 if attribute missing - plug = depFn.findPlug(attr, &stat); - if (stat != MS::kSuccess) return -1; - - stat = plug.getValue(tmp); - if ( stat != MS::kSuccess ) return -1; - - *val = tmp; - return 0; -} - - -template static void -getAttribute( MObject& object, MObject& attr, T *val ) -{ - // fast version - crash & burn if attribute missing - MPlug plug(object, attr); - plug.getValue(*val); -} - - -static MColor -getColor(MObject object, MObject attr) -{ - MPlug plug(object, attr); - MObject data; - plug.getValue(data); - MFnNumericData numFn(data); - float color[3]; - numFn.getData(color[0], color[1], color[2]); - return MColor(color[0], color[1], color[2]); -} - -static MFloatVector -getVector(MObject object, MObject attr) -{ - MPlug plug(object, attr); - MObject data; - plug.getValue(data); - MFnNumericData numFn(data); - float color[3]; - numFn.getData(color[0], color[1], color[2]); - return MVector(color[0], color[1], color[2]); -} - - -static void -// reverse to dst,src ? -setMatrix(const MMatrix &mat, float *dst) -{ - for (int i = 0; i < 4; ++i) - for (int j = 0; j < 4; ++j) - dst[i*4+j] = float(mat(i, j)); -} - - -#endif // _EXAMPLE_MAYA_UTIL_H_ - diff --git a/examples/mayaPolySmooth/CMakeLists.txt b/examples/mayaPolySmooth/CMakeLists.txt deleted file mode 100644 index 84766046..00000000 --- a/examples/mayaPolySmooth/CMakeLists.txt +++ /dev/null @@ -1,130 +0,0 @@ -# -# 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. -# - -# *** mayaPolySmooth *** - -set(MAYA_FIND_QUIETLY TRUE) - -if(NOT MAYA_FOUND) - message(STATUS - "Maya could not be found, so the OpenSubdiv mayaPolySmooth 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( - "${OPENSUBDIV_INCLUDE_DIR}" - "${MAYA_INCLUDE_DIRS}" -) - -set(SOURCE_FILES - mayaPolySmooth.cpp -) - -set(HEADER_FILES - mayaPolySmooth.h -) - -if(UNIX) - set(PLATFORM_COMPILE_FLAGS - -D_BOOL - -DREQUIRE_IOSTREAM - -DLINUX - ) - set(PLATFORM_PLUGIN_EXTENSION - .so - ) - set(PLATFORM_LINK_FLAGS - ) -elseif(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() - -add_definitions( - ${PLATFORM_COMPILE_FLAGS} -) - -add_library(maya_polySmoothNode SHARED - ${SOURCE_FILES} - ${HEADER_FILES} - $ - $ - $ -) - -set_target_properties(maya_polySmoothNode - PROPERTIES - OUTPUT_NAME "mayaPolySmooth" - 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}" -) - -install(TARGETS maya_polySmoothNode DESTINATION "${CMAKE_PLUGINDIR_BASE}") - -add_custom_target(maya_polySmoothNode_melScripts - COMMAND - ${CMAKE_COMMAND} -E copy - "${CMAKE_CURRENT_SOURCE_DIR}/mayaPolySmooth.mel" - "${OpenSubdiv_BINARY_DIR}/${CMAKE_LIBDIR_BASE}/mayaPolySmooth.mel" - DEPENDS - "${CMAKE_CURRENT_SOURCE_DIR}/mayaPolySmooth.mel" -) - -install( - FILES - "${OpenSubdiv_BINARY_DIR}/${CMAKE_LIBDIR_BASE}/mayaPolySmooth.mel" - DESTINATION - "${CMAKE_PLUGINDIR_BASE}" -) - -add_custom_target(mayaPolySmooth - ALL - DEPENDS - maya_polySmoothNode maya_polySmoothNode_melScripts -) diff --git a/examples/mayaPolySmooth/mayaPolySmooth.cpp b/examples/mayaPolySmooth/mayaPolySmooth.cpp deleted file mode 100644 index c7310838..00000000 --- a/examples/mayaPolySmooth/mayaPolySmooth.cpp +++ /dev/null @@ -1,1238 +0,0 @@ -// -// 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. -// - -#include "mayaPolySmooth.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include - -#if defined(_MSV_VER) and (not defined(__INTEL_COMPILER)) - #pragma warning( disable : 174 593 ) -#endif - -// OpenSubdiv includes -#include -#include -#include - -#include -#include - - -// ==================================== -// Static Initialization -// ==================================== - -// MAYA_NODE_BUILDER:BEG [ATTRIBUTE INITIALIZATION] ========== -const MTypeId MayaPolySmooth::id( 0x0010a25b ); -const MString MayaPolySmooth::typeNameStr("mayaPolySmooth"); -MObject MayaPolySmooth::a_inputPolymesh; -MObject MayaPolySmooth::a_output; -MObject MayaPolySmooth::a_subdivisionLevels; -MObject MayaPolySmooth::a_recommendedIsolation; -MObject MayaPolySmooth::a_vertBoundaryMethod; -MObject MayaPolySmooth::a_fvarBoundaryMethod; -MObject MayaPolySmooth::a_fvarPropagateCorners; -MObject MayaPolySmooth::a_smoothTriangles; -MObject MayaPolySmooth::a_creaseMethod; -// MAYA_NODE_BUILDER:END [ATTRIBUTE INITIALIZATION] ========== - -// ATTR ENUMS -// Note: Do not change these values as these are serialized numerically in the Maya scenes) -// -enum BoundaryMethod { - k_BoundaryMethod_InterpolateBoundaryNone = 0, - k_BoundaryMethod_InterpolateBoundaryEdgeOnly = 1, - k_BoundaryMethod_InterpolateBoundaryEdgeAndCorner = 2, - k_BoundaryMethod_InterpolateBoundaryAlwaysSharp = 3 -}; - -enum CreaseMethod { - k_creaseMethod_normal = 0, - k_creaseMethod_chaikin = 1 -}; - -static OpenSubdiv::Sdc::Options::VtxBoundaryInterpolation -ConvertMayaVtxBoundary(short boundaryMethod) { - - typedef OpenSubdiv::Sdc::Options Sdc; - - switch (boundaryMethod) { - case k_BoundaryMethod_InterpolateBoundaryNone : return Sdc::VTX_BOUNDARY_NONE; - case k_BoundaryMethod_InterpolateBoundaryEdgeOnly : return Sdc::VTX_BOUNDARY_EDGE_ONLY; - case k_BoundaryMethod_InterpolateBoundaryEdgeAndCorner : return Sdc::VTX_BOUNDARY_EDGE_AND_CORNER; - default: ; - } - MGlobal::displayError("VTX InterpolateBoundaryMethod value out of range. Using \"none\""); - return Sdc::VTX_BOUNDARY_NONE; -} - -// XXXX note: This function converts the options exposed in Maya's GUI which are -// based on prman legacy face-varying boundary interpolation rules. -// As a result, some OpenSubdiv 3.0 FVar interpolation rules are not -// exposed, and the some of the ones exposed fix incorrect behavior -// from legacy prman code, so the results are not 100% backward compatible. -static OpenSubdiv::Sdc::Options::FVarLinearInterpolation -ConvertMayaFVarBoundary(short boundaryMethod, bool propagateCorner) { - - typedef OpenSubdiv::Sdc::Options Sdc; - - switch (boundaryMethod) { - case k_BoundaryMethod_InterpolateBoundaryNone : return Sdc::FVAR_LINEAR_ALL; - case k_BoundaryMethod_InterpolateBoundaryEdgeOnly : return Sdc::FVAR_LINEAR_NONE; - case k_BoundaryMethod_InterpolateBoundaryEdgeAndCorner : - return propagateCorner ? Sdc::FVAR_LINEAR_CORNERS_PLUS2 : Sdc::FVAR_LINEAR_CORNERS_PLUS1; - case k_BoundaryMethod_InterpolateBoundaryAlwaysSharp : return Sdc::FVAR_LINEAR_BOUNDARIES; - default: ; - } - MGlobal::displayError("FVar InterpolateMethod value out of range. Using \"none\""); - return Sdc::FVAR_LINEAR_ALL; -} - -// ==================================== -// Macros -// ==================================== -#define MCHECKERR(status,message) \ - if( MStatus::kSuccess != status ) { \ - cerr << "ERROR: " << message << "[" << status << "]" << endl; \ - return status; \ - } - -#define MWARNERR(status,message) \ - if( MStatus::kSuccess != status ) { \ - cerr << "ERROR: " << message << "[" << status << "]" << endl; \ - } - -#define CHANNELUV 0 - -#define CHANNELCOLOR 1 - -// ==================================== -// Constructors/Destructors -// ==================================== -MayaPolySmooth::MayaPolySmooth() {} - -MayaPolySmooth::~MayaPolySmooth() {} - - -// ==================================== -// Helper Functions -// ==================================== -// Create component groups -void -createComp(MFnMeshData &dataCreator, MFn::Type compType, unsigned compId, MIntArray &compList) { - - MStatus returnStatus; - - MFnSingleIndexedComponent comp; - MObject compObj = comp.create(compType,&returnStatus); - MWARNERR(returnStatus, "cannot create MFnSingleIndexedComponent"); - - returnStatus = comp.addElements(compList); - MWARNERR(returnStatus, "Error in addElements() for MFnSingleIndexedComponent"); - - returnStatus = dataCreator.addObjectGroup(compId); - MWARNERR(returnStatus, "Error in addObjectGroup()"); - - returnStatus = dataCreator.setObjectGroupComponent(compId, compObj); - MWARNERR(returnStatus, "Error in setObjectGroupComponent()"); -} - - -// ==================================== -// OpenSubdiv Functions -// ==================================== - -typedef OpenSubdiv::Far::TopologyDescriptor Descriptor; - -// Reference: OSD shape_utils.h:: applyTags() "crease" -static float -getCreaseEdges(MFnMesh const & inMeshFn, Descriptor & outDesc) { - - MUintArray tEdgeIds; - MDoubleArray tCreaseData; - float maxCreaseValue = 0.0f; - - if (inMeshFn.getCreaseEdges(tEdgeIds, tCreaseData)) { - - assert( tEdgeIds.length() == tCreaseData.length() ); - - int ncreases = tEdgeIds.length(); - int * vertPairs = new int[ncreases*2]; - float * weights = new float[ncreases]; - - int2 edgeVerts; - for (unsigned int j=0; j < tEdgeIds.length(); j++) { - - assert( tCreaseData[j] >= 0.0 ); - inMeshFn.getEdgeVertices(tEdgeIds[j], edgeVerts); - - vertPairs[j*2 ] = edgeVerts[0]; - vertPairs[j*2+1] = edgeVerts[1]; - weights[j] = float(tCreaseData[j]); - maxCreaseValue = std::max(float(tCreaseData[j]), maxCreaseValue); - } - - outDesc.numCreases = ncreases; - outDesc.creaseVertexIndexPairs = vertPairs; - outDesc.creaseWeights = weights; - } - return maxCreaseValue; -} - - -// Reference: OSD shape_utils.h:: applyTags() "corner" -static float -getCreaseVertices( MFnMesh const & inMeshFn, Descriptor & outDesc) { - - MUintArray tVertexIds; - MDoubleArray tCreaseData; - float maxCreaseValue = 0.0f; - - if ( inMeshFn.getCreaseVertices(tVertexIds, tCreaseData) ) { - - assert( tVertexIds.length() == tCreaseData.length() ); - - int ncorners = tVertexIds.length(); - int * verts = new int[ncorners*2]; - float * weights = new float[ncorners]; - - // Has crease vertices - for (unsigned int j=0; j < tVertexIds.length(); j++) { - - assert( tCreaseData[j] >= 0.0 ); - - verts[j] = tVertexIds[j]; - weights[j] = float(tCreaseData[j]); - - maxCreaseValue = std::max(float(tCreaseData[j]), maxCreaseValue); - } - - outDesc.numCorners = ncorners; - outDesc.cornerVertexIndices = verts; - outDesc.cornerWeights = weights; - } - return maxCreaseValue; -} - -// XXX -- Future Data Optimization: Implement varying data instead of forcing face-varying for ColorSets. - -// Collect UVs and ColorSet info to represent them as face-varying in OpenSubdiv -static MStatus -getMayaFvarFieldParams( - MFnMesh const & inMeshFn, - MStringArray & uvSetNames, - MStringArray & colorSetNames, - std::vector & colorSetChannels, - std::vector &colorSetReps, - int & totalColorSetChannels) { - - MStatus returnStatus; - - returnStatus = inMeshFn.getUVSetNames(uvSetNames); - MCHECKERR(returnStatus, "Cannot get uvSet names"); - - returnStatus = inMeshFn.getColorSetNames(colorSetNames); - MCHECKERR(returnStatus, "Cannot get colorSet names"); - - colorSetChannels.resize(colorSetNames.length()); - colorSetReps.resize(colorSetNames.length()); - totalColorSetChannels = 0; - - for (unsigned int i=0; i < colorSetNames.length(); i++) { - - colorSetReps[i] = inMeshFn.getColorRepresentation(colorSetNames[i], &returnStatus); - MCHECKERR(returnStatus, "Cannot get colorSet representation"); - - if (colorSetReps[i] == MFnMesh::kAlpha) { - colorSetChannels[i] = 1; - } else if (colorSetReps[i] == MFnMesh::kRGB) { - colorSetChannels[i] = 3; - } else { - colorSetChannels[i] = 4; // kRGBA - } - totalColorSetChannels += colorSetChannels[i]; - } - return MS::kSuccess; -} - - -//! Caller is expected to delete the returned value -static OpenSubdiv::Far::TopologyRefiner * -gatherTopology( MFnMesh & inMeshFn, - MItMeshPolygon & inMeshItPolygon, - OpenSubdiv::Sdc::SchemeType type, - OpenSubdiv::Sdc::Options options, - bool * hasUVs, bool * hasColors, - std::vector & uvSet_uCoords, - std::vector & uvSet_vCoords, - std::vector & colorSet_colors, - float * maxCreaseSharpness=0 ) { - - MStatus returnStatus; - - // Gather FVarData - MStringArray uvSetNames; - MStringArray colorSetNames; - std::vector colorSetChannels; - std::vector colorSetReps; - int totalColorSetChannels = 0; - returnStatus = getMayaFvarFieldParams(inMeshFn, uvSetNames, colorSetNames, - colorSetChannels, colorSetReps, totalColorSetChannels); - MWARNERR(returnStatus, "Failed to retrieve Maya face-varying parameters"); - - // Storage for UVs and ColorSets for face-vertex - MIntArray fvArray; // face vertex array - uvSet_uCoords.clear(); uvSet_uCoords.resize(uvSetNames.length()); - uvSet_vCoords.clear(); uvSet_vCoords.resize(uvSetNames.length()); - colorSet_colors.clear();colorSet_colors.resize(colorSetNames.length()); - - // Put the data in the format needed for OSD - Descriptor desc; - - int numFaceVertices = inMeshFn.numFaceVertices(); - - desc.numVertices = inMeshFn.numVertices(); - desc.numFaces = inMeshItPolygon.count(); - - int * vertsPerFace = new int[desc.numFaces], - * vertIndices = new int[numFaceVertices]; - - desc.numVertsPerFace = vertsPerFace; - desc.vertIndicesPerFace = vertIndices; - - // Create Topology - for (inMeshItPolygon.reset(); !inMeshItPolygon.isDone(); inMeshItPolygon.next()) { - - inMeshItPolygon.getVertices(fvArray); - int nverts = fvArray.length(); - - vertsPerFace[inMeshItPolygon.index()] = nverts; - - for (int i=0; i 0 && uvSet_vCoords.size() > 0; - *hasColors = colorSet_colors.size() > 0; - - // Note : Only supports 1 channel of UVs and 1 channel of color - if (*hasUVs || *hasColors) { - - // Create 2 face-varying channel descriptor that will hold UVs and color - desc.numFVarChannels = 2; - channels = new Descriptor::FVarChannel[desc.numFVarChannels]; - desc.fvarChannels = channels; - - int * uvIndices = new int[numFaceVertices]; - channels[CHANNELUV].valueIndices = uvIndices; - channels[CHANNELUV].numValues = 0; - - int * colorIndices = new int[numFaceVertices]; - channels[CHANNELCOLOR].valueIndices = colorIndices; - channels[CHANNELCOLOR].numValues = 0; - - // Obtain UV information - if (*hasUVs) { - inMeshFn.getUVs(uvSet_uCoords[0], uvSet_vCoords[0], &uvSetNames[0]); - assert( uvSet_uCoords[0].length() == uvSet_vCoords[0].length() ); - - int uvId = 0, nUVs = 0; - for (int faceIndex = 0; faceIndex < inMeshFn.numPolygons(); ++faceIndex) - { - int numVertices = inMeshFn.polygonVertexCount(faceIndex); - for (int v = 0; v < numVertices; v++) - { - inMeshFn.getPolygonUVid(faceIndex, v, uvId, &uvSetNames[0]); - uvIndices[nUVs++] = uvId; - } - } - - channels[CHANNELUV].numValues = uvSet_uCoords[0].length(); - } - - // Obtain color information - if (*hasColors) { - inMeshFn.getColors(colorSet_colors[0], &colorSetNames[0]); - - int colorId = 0, nColors = 0; - bool addDefaultColor = true; - for (int faceIndex = 0; faceIndex < inMeshFn.numPolygons(); ++faceIndex) - { - int numVertices = inMeshFn.polygonVertexCount(faceIndex); - for ( int v = 0 ; v < numVertices; v++ ) - { - inMeshFn.getColorIndex(faceIndex, v, colorId, &colorSetNames[0]); - if (colorId == -1) - { - if (addDefaultColor) - { - addDefaultColor = false; - colorSet_colors[0].append(MColor(1.0, 1.0, 1.0, 1.0)); - } - colorId = colorSet_colors[0].length() - 1; - } - colorIndices[nColors ++] = colorId; - } - } - - channels[CHANNELCOLOR].numValues = colorSet_colors[0].length(); - } - } - - // Apply Creases - float maxEdgeCrease = getCreaseEdges( inMeshFn, desc ); - float maxVertexCrease = getCreaseVertices( inMeshFn, desc ); - - OpenSubdiv::Far::TopologyRefiner * refiner = - OpenSubdiv::Far::TopologyRefinerFactory::Create(desc, - OpenSubdiv::Far::TopologyRefinerFactory::Options(type, options)); - - delete [] desc.numVertsPerFace; - delete [] desc.vertIndicesPerFace; - delete [] desc.creaseVertexIndexPairs; - delete [] desc.creaseWeights; - delete [] desc.cornerVertexIndices; - delete [] desc.cornerWeights; - - if (*hasUVs || *hasColors) { - for(int i = 0 ; i < desc.numFVarChannels ; i ++) { - delete [] channels[i].valueIndices; - } - delete [] channels; - } - - if (maxCreaseSharpness) { - *maxCreaseSharpness = std::max(maxEdgeCrease, maxVertexCrease); - } - - return refiner; -} - -static inline int -computeNumSubfaces( int nverts, int level ) { - - return nverts==4 ? 1<<(level<<1) : nverts*(1<<((level-1)<<1)); -} - -// Propagate objectGroups from inMesh to subdivided outMesh -// Note: Currently only supporting facet groups (for per-facet shading) -MStatus -createSmoothMesh_objectGroups( MFnMesh const & inMeshFn, - MFnMeshData const & inMeshDat, MFnMeshData &newMeshDat, int level, int numSubfaces ) { - - MStatus status; - - MIntArray newCompElems; - - std::vector offsets; // mapping of offsets for subdivided faces - - for(unsigned int gi=0; gi const & refinedVerts, - bool hasUVs, std::vector const & refinedUVs, - bool hasColors, std::vector const & refinedColors, - MFnMesh & inMeshFn, MObject newMeshDataObj) { - - MStatus status; - - typedef OpenSubdiv::Far::ConstIndexArray IndexArray; - - int maxlevel = refiner.GetMaxLevel(); - - OpenSubdiv::Far::TopologyLevel const & refLastLevel - = refiner.GetLevel(maxlevel); - - int nfaces = refLastLevel.GetNumFaces(); - - // Init Maya Data - - // Face Counts - MIntArray faceCounts(nfaces); - for (int face=0; face < nfaces; ++face) { - faceCounts[face] = 4; - } - - // Face Connects - MIntArray faceConnects(nfaces*4); - for (int face=0, idx=0; face < nfaces; ++face) { - IndexArray fverts = refLastLevel.GetFaceVertices(face); - for (int vert=0; vert < fverts.size(); ++vert) { - faceConnects[idx++] = fverts[vert]; - } - } - - // Points - int nverts = refLastLevel.GetNumVertices(); - int firstOfLastVert = refiner.GetNumVerticesTotal() - - nverts - - refiner.GetLevel(0).GetNumVertices(); - - MFloatPointArray points(nverts); - for (int vIt = 0; vIt < nverts; ++vIt) { - Vertex const & v = refinedVerts[firstOfLastVert + vIt]; - points.set(vIt, v.position[0], v.position[1], v.position[2]); - } - - // Create New Mesh from MFnMesh - MFnMesh newMeshFn; - MObject newMeshObj = newMeshFn.create(points.length(), faceCounts.length(), - points, faceCounts, faceConnects, newMeshDataObj, &status); - MCHECKERR(status, "Cannot create new mesh"); - - // Get face-varying set names and other info from the inMesh - MStringArray uvSetNames; - MStringArray colorSetNames; - std::vector colorSetChannels; - std::vector colorSetReps; - int totalColorSetChannels = 0; - status = getMayaFvarFieldParams(inMeshFn, uvSetNames, colorSetNames, - colorSetChannels, colorSetReps, totalColorSetChannels); - - // Add new UVs back to the mesh if needed - if (hasUVs) { - - MIntArray fvarConnects(faceConnects.length()); - int count = 0; - for (int f = 0; f < refLastLevel.GetNumFaces(); ++f) { - IndexArray faceIndices = refLastLevel.GetFaceFVarValues(f, CHANNELUV); - for (int index = 0 ; index < faceIndices.size() ; ++index) { - fvarConnects[count++] = faceIndices[index]; - } - } - - int nuvs = refLastLevel.GetNumFVarValues(CHANNELUV); - int firstOfLastUvs = refiner.GetNumFVarValuesTotal(CHANNELUV) - - nuvs - - refiner.GetLevel(0).GetNumFVarValues(CHANNELUV); - - MFloatArray uCoord(nuvs), vCoord(nuvs); - for (int uvIt = 0; uvIt < nuvs; ++uvIt) { - FVarVertexUV const & uv = refinedUVs[firstOfLastUvs + uvIt]; - uCoord[uvIt] = uv.u; - vCoord[uvIt] = uv.v; - } - - // Currently, the plugin only supports one UV set - int uvSetIndex = 0; - if (uvSetIndex > 0) { - status = newMeshFn.createUVSetDataMesh( uvSetNames[uvSetIndex] ); - MCHECKERR(status, "Cannot create UVSet"); - } - static MString defaultUVName("map1"); - MString const * uvname = uvSetIndex==0 ? - &defaultUVName : &uvSetNames[uvSetIndex]; - status = newMeshFn.setUVs(uCoord, vCoord, uvname); - MCHECKERR(status, "Cannot set UVs for set : "+*uvname); - - status = newMeshFn.assignUVs(faceCounts, fvarConnects, uvname); - MCHECKERR(status, "Cannot assign UVs"); - } - - // Add new colors back to the mesh if needed - if (hasColors) { - - int count = 0; - MIntArray fvarConnects2(faceConnects.length()); - for (int f = 0 ; f < refLastLevel.GetNumFaces(); ++f) { - IndexArray faceIndices = refLastLevel.GetFaceFVarValues(f, CHANNELCOLOR); - for (int index = 0 ; index < faceIndices.size() ; ++index) { - fvarConnects2[count++] = faceIndices[index]; - } - } - - int ncols = refLastLevel.GetNumFVarValues(CHANNELCOLOR); - int firstOfLastCols = refiner.GetNumFVarValuesTotal(CHANNELCOLOR) - - ncols - - refiner.GetLevel(0).GetNumFVarValues(CHANNELCOLOR); - - MColorArray colorArray(ncols); - for (int colIt = 0; colIt < ncols; ++colIt) { - FVarVertexColor const & c = refinedColors[firstOfLastCols + colIt]; - colorArray.set(colIt, c.r, c.g, c.b, c.a); - } - - // Currently, the plugin only supports one color sets - int colorSetIndex = 0; - - // Assign color buffer and map the ids for each face-vertex - // API Limitation: Cannot set MColorRepresentation here - status = newMeshFn.createColorSetDataMesh( - colorSetNames[colorSetIndex]); - MCHECKERR(status, "Cannot create ColorSet"); - - bool isColorClamped = inMeshFn.isColorClamped( - colorSetNames[colorSetIndex], &status); - MCHECKERR(status, "Can not get Color Clamped "); - - status = newMeshFn.setIsColorClamped( - colorSetNames[colorSetIndex], isColorClamped); - MCHECKERR(status, "Can not set Color Clamped : " + isColorClamped); - - status = newMeshFn.setColors( - colorArray, &colorSetNames[colorSetIndex], - colorSetReps[colorSetIndex]); - MCHECKERR(status, "Can not set Colors"); - - status = newMeshFn.assignColors( - fvarConnects2, &colorSetNames[colorSetIndex]); - MCHECKERR(status, "Can not assign Colors"); - } - - return MS::kSuccess; -} - -MStatus -MayaPolySmooth::compute( const MPlug& plug, MDataBlock& data ) { - - MStatus status; - - // Check which output attribute we have been asked to compute. If this - // node doesn't know how to compute it, we must return - // MS::kUnknownParameter. - // - - if( plug == a_output ) { - - bool createdSubdMesh = false; - - int subdivisionLevel = data.inputValue(a_subdivisionLevels).asInt(); - short stateH = data.inputValue(state).asShort(); - - if ((subdivisionLevel > 0) && (stateH !=1)) { - - // == Retrieve input mesh ==================================== - // Get attr values - MObject inMeshObj = data.inputValue(a_inputPolymesh).asMesh(); - short vertBoundaryMethod = data.inputValue(a_vertBoundaryMethod).asShort(); - short fvarBoundaryMethod = data.inputValue(a_fvarBoundaryMethod).asShort(); - bool fvarPropCorners = data.inputValue(a_fvarPropagateCorners).asBool(); - bool smoothTriangles = data.inputValue(a_smoothTriangles).asBool(); - short creaseMethodVal = data.inputValue(a_creaseMethod).asShort(); - - // == Get Mesh Functions and Iterators ========================== - MFnMeshData inMeshDat(inMeshObj); - MFnMesh inMeshFn(inMeshObj, &status); - MCHECKERR(status, "ERROR getting inMeshFn\n"); - MItMeshPolygon inMeshItPolygon(inMeshObj, &status); - MCHECKERR(status, "ERROR getting inMeshItPolygon\n"); - - // Convert attr values to OSD enums - OpenSubdiv::Sdc::SchemeType type = OpenSubdiv::Sdc::SCHEME_CATMARK; - - // == Create Far topology ========================== - OpenSubdiv::Sdc::Options options; - options.SetVtxBoundaryInterpolation(ConvertMayaVtxBoundary(vertBoundaryMethod)); - options.SetFVarLinearInterpolation(ConvertMayaFVarBoundary(fvarBoundaryMethod, fvarPropCorners)); - options.SetCreasingMethod(creaseMethodVal ? - OpenSubdiv::Sdc::Options::CREASE_CHAIKIN : OpenSubdiv::Sdc::Options::CREASE_UNIFORM); - options.SetTriangleSubdivision(smoothTriangles ? - OpenSubdiv::Sdc::Options::TRI_SUB_SMOOTH : OpenSubdiv::Sdc::Options::TRI_SUB_CATMARK); - - // Storage for face-varying values (UV sets, vertex colors...) - std::vector uvSet_uCoords; - std::vector uvSet_vCoords; - std::vector colorSet_colors; - - bool hasUVs = false, hasColors = false; - float maxCreaseSharpness=0.0f; - OpenSubdiv::Far::TopologyRefiner * refiner = gatherTopology( - inMeshFn, inMeshItPolygon, type, options, &hasUVs, &hasColors, - uvSet_uCoords, uvSet_vCoords, colorSet_colors, &maxCreaseSharpness); - - assert(refiner); - - // == Refine & Interpolate ========================== - refiner->RefineUniform(OpenSubdiv::Far::TopologyRefiner::UniformOptions(subdivisionLevel)); - - // Prepare vertex information - Vertex const * initialVerts = - reinterpret_cast(inMeshFn.getRawPoints(&status)); - std::vector refinedVerts( - refiner->GetNumVerticesTotal() - refiner->GetLevel(0).GetNumVertices()); - Vertex const * srcVerts = &initialVerts[0]; - Vertex * dstVerts = &refinedVerts[0]; - - // Verify the refiner has the correct number of values - // needed to interpolate the different channels - int numInitialUVs = refiner->GetLevel(0).GetNumFVarValues(CHANNELUV); - int numInitialColors = refiner->GetLevel(0).GetNumFVarValues(CHANNELCOLOR); - - if (hasUVs && numInitialUVs <= 0) { - hasUVs = false; - MGlobal::displayError("Model with incorrect data, the UV channel will not be interpolated."); - } - - if (hasColors && numInitialColors <= 0) { - hasColors = false; - MGlobal::displayError("Model with incorrect data, the color channel will not be interpolated."); - } - - // Prepare UV information if needed - std::vector initialUVs, refinedUVs; - FVarVertexUV const * srcUV = NULL; - FVarVertexUV * dstUV = NULL; - if(hasUVs) { - initialUVs.resize(numInitialUVs); - refinedUVs.resize(refiner->GetNumFVarValuesTotal(CHANNELUV)); - for (int i=0; i initialColors, refinedColors; - FVarVertexColor const * srcColor = NULL; - FVarVertexColor * dstColor = NULL; - if(hasColors) { - initialColors.resize(numInitialColors); - refinedColors.resize(refiner->GetNumFVarValuesTotal(CHANNELCOLOR)); - for (int i=0; iGetLevel(level).GetNumVertices(); - - // Interpolate the uv set - if(hasUVs) { - primvarRefiner.InterpolateFaceVarying(level, srcUV, dstUV, CHANNELUV); - srcUV = dstUV; - dstUV += refiner->GetLevel(level).GetNumFVarValues(CHANNELUV); - } - - // Interpolate any color set - if(hasColors) { - primvarRefiner.InterpolateFaceVarying(level, srcColor, dstColor, CHANNELCOLOR); - srcColor = dstColor; - dstColor += refiner->GetLevel(level).GetNumFVarValues(CHANNELCOLOR); - } - } - - // == Convert subdivided OpenSubdiv mesh to MFnMesh Data outputMesh ============= - - // Create New Mesh Data Object - MFnMeshData newMeshData; - MObject newMeshDataObj = newMeshData.create(&status); - MCHECKERR(status, "ERROR creating outputData"); - - // Create out mesh - status = convertToMayaMeshData(*refiner, refinedVerts, hasUVs, - refinedUVs, hasColors, refinedColors, inMeshFn, newMeshDataObj); - MCHECKERR(status, "ERROR convertOsdFarToMayaMesh"); - - // Propagate objectGroups from inMesh to outMesh (for per-facet shading, etc) - status = createSmoothMesh_objectGroups(inMeshFn, inMeshDat, - newMeshData, subdivisionLevel, refiner->GetLevel(subdivisionLevel).GetNumFaces()); - - // Write to output plug - MDataHandle outMeshH = data.outputValue(a_output, &status); - MCHECKERR(status, "ERROR getting polygon data handle\n"); - outMeshH.set(newMeshDataObj); - - int isolation = std::min(10,(int)ceil(maxCreaseSharpness)+1); - data.outputValue(a_recommendedIsolation).set(isolation); - - // == Cleanup OSD ============================================ - - // REVISIT: Re-add these deletes - delete refiner; - - // note that the subd mesh was created (see the section below if !createdSubdMesh) - createdSubdMesh = true; - } - - // Pass-through inMesh to outMesh if not created the subd mesh - if (!createdSubdMesh) { - MDataHandle outMeshH = data.outputValue(a_output, &status); - status = outMeshH.copy(data.outputValue(a_inputPolymesh, &status)); - MCHECKERR(status, "ERROR getting polygon data handle\n"); - } - - // Clean up Maya Plugs - data.setClean(plug); - - } else { - // Unhandled parameter in this compute function, so return MS::kUnknownParameter - // so it is handled in a parent compute() function. - return MS::kUnknownParameter; - } - return MS::kSuccess; -} - -// Creator -// -// Description: -// this method exists to give Maya a way to create new objects -// of this type. -// -// Return Value: -// a new object of this type -// -void* MayaPolySmooth::creator() { - - return new MayaPolySmooth; -} - -// Create and Add Attributes -// -// Description: -// This method is called to create and initialize all of the attributes -// and attribute dependencies for this node type. This is only called -// once when the node type is registered with Maya. -// -// Return Values: -// MS::kSuccess -// MS::kFailure -// -MStatus -MayaPolySmooth::initialize() { - - MStatus stat; - - MFnCompoundAttribute cAttr; - MFnEnumAttribute eAttr; - MFnGenericAttribute gAttr; - MFnLightDataAttribute lAttr; - MFnMatrixAttribute mAttr; - MFnMessageAttribute msgAttr; - MFnNumericAttribute nAttr; - MFnTypedAttribute tAttr; - MFnUnitAttribute uAttr; - - // MAYA_NODE_BUILDER:BEG [ATTRIBUTE CREATION] ========== - // a_inputPolymesh : This is a description for this attribute - a_inputPolymesh = tAttr.create("inputPolymesh", "ip", MFnData::kMesh, MObject::kNullObj, &stat); - MCHECKERR( stat, "cannot create MayaPolySmooth::inputPolymesh" ); - stat = tAttr.setReadable(true); - MCHECKERR( stat, "cannot MayaPolySmooth::inputPolymesh.setReadable()" ); - stat = tAttr.setWritable(true); - MCHECKERR( stat, "cannot MayaPolySmooth::inputPolymesh.setWritable()" ); - stat = tAttr.setHidden(true); - MCHECKERR( stat, "cannot MayaPolySmooth::inputPolymesh.setHidden()" ); - stat = addAttribute( a_inputPolymesh ); - MCHECKERR( stat, "cannot MayaPolySmooth::addAttribute(a_inputPolymesh)" ); - - // a_output : This is a description for this attribute - a_output = tAttr.create("output", "out", MFnData::kMesh, MObject::kNullObj, &stat); - MCHECKERR( stat, "cannot create MayaPolySmooth::output" ); - stat = tAttr.setReadable(true); - MCHECKERR( stat, "cannot MayaPolySmooth::output.setReadable()" ); - stat = tAttr.setWritable(false); - MCHECKERR( stat, "cannot MayaPolySmooth::output.setWritable()" ); - stat = tAttr.setHidden(true); - MCHECKERR( stat, "cannot MayaPolySmooth::output.setHidden()" ); - stat = addAttribute( a_output ); - MCHECKERR( stat, "cannot MayaPolySmooth::addAttribute(a_output)" ); - - // a_subdivisionLevels : The number of recursive quad subdivisions to perform on each face. - a_subdivisionLevels = nAttr.create("subdivisionLevels", "sl", MFnNumericData::kInt, 0.0, &stat); - MCHECKERR( stat, "cannot create MayaPolySmooth::subdivisionLevels" ); - stat = nAttr.setDefault(2); - MCHECKERR( stat, "cannot MayaPolySmooth::subdivisionLevels.setDefault(2)" ); - stat = nAttr.setMin(0); - MCHECKERR( stat, "cannot MayaPolySmooth::subdivisionLevels.setMin(0)" ); - stat = nAttr.setMax(10); - MCHECKERR( stat, "cannot MayaPolySmooth::subdivisionLevels.setMax(10)" ); - stat = nAttr.setSoftMax(4); - MCHECKERR( stat, "cannot MayaPolySmooth::subdivisionLevels.setSoftMax(4)" ); - stat = nAttr.setReadable(true); - MCHECKERR( stat, "cannot MayaPolySmooth::subdivisionLevels.setReadable()" ); - stat = nAttr.setWritable(true); - MCHECKERR( stat, "cannot MayaPolySmooth::subdivisionLevels.setWritable()" ); - stat = addAttribute( a_subdivisionLevels ); - MCHECKERR( stat, "cannot MayaPolySmooth::addAttribute(a_subdivisionLevels)" ); - - // a_recommendedIsolation : The number of recursive quad subdivisions to perform on each face. - a_recommendedIsolation = nAttr.create("recommendedIsolation", "ri", MFnNumericData::kInt, 0.0, &stat); - MCHECKERR( stat, "cannot create MayaPolySmooth::recommendedIsolation" ); - stat = nAttr.setDefault(2); - MCHECKERR( stat, "cannot MayaPolySmooth::recommendedIsolation.setDefault(0)" ); - stat = nAttr.setMin(0); - MCHECKERR( stat, "cannot MayaPolySmooth::recommendedIsolation.setMin(0)" ); - stat = nAttr.setMax(10); - MCHECKERR( stat, "cannot MayaPolySmooth::recommendedIsolation.setSoftMax(10)" ); - stat = nAttr.setReadable(true); - MCHECKERR( stat, "cannot MayaPolySmooth::recommendedIsolation.setReadable()" ); - stat = nAttr.setWritable(false); - MCHECKERR( stat, "cannot MayaPolySmooth::recommendedIsolation.setWritable()" ); - stat = nAttr.setHidden(false); - MCHECKERR( stat, "cannot MayaPolySmooth::recommendedIsolation.setHidden()" ); - stat = addAttribute( a_recommendedIsolation ); - MCHECKERR( stat, "cannot MayaPolySmooth::addAttribute(a_recommendedIsolation)" ); - - // a_vertBoundaryMethod : Controls how boundary edges and vertices are interpolated.
  • Smooth, Edges: Renderman: InterpolateBoundaryEdgeOnly
  • Smooth, Edges and Corners: Renderman: InterpolateBoundaryEdgeAndCorner
- a_vertBoundaryMethod = eAttr.create("vertBoundaryMethod", "vbm", 0, &stat); - MCHECKERR( stat, "cannot create MayaPolySmooth::vertBoundaryMethod" ); - stat = eAttr.addField("Interpolate Edges", k_BoundaryMethod_InterpolateBoundaryEdgeOnly); - MCHECKERR( stat, "cannot MayaPolySmooth::vertBoundaryMethod.addField(Interpolate Edges, k_BoundaryMethod_InterpolateBoundaryEdgeOnly)" ); - stat = eAttr.addField("Interpolate Edges And Corners", k_BoundaryMethod_InterpolateBoundaryEdgeAndCorner); - MCHECKERR( stat, "cannot MayaPolySmooth::vertBoundaryMethod.addField(Interpolate Edges And Corners, k_BoundaryMethod_InterpolateBoundaryEdgeAndCorner)" ); - stat = eAttr.setDefault(k_BoundaryMethod_InterpolateBoundaryEdgeOnly); - MCHECKERR( stat, "cannot MayaPolySmooth::vertBoundaryMethod.setDefault(k_BoundaryMethod_InterpolateBoundaryEdgeOnly)" ); - stat = eAttr.setReadable(true); - MCHECKERR( stat, "cannot MayaPolySmooth::vertBoundaryMethod.setReadable()" ); - stat = eAttr.setWritable(true); - MCHECKERR( stat, "cannot MayaPolySmooth::vertBoundaryMethod.setWritable()" ); - stat = addAttribute( a_vertBoundaryMethod ); - MCHECKERR( stat, "cannot MayaPolySmooth::addAttribute(a_vertBoundaryMethod)" ); - - // a_fvarBoundaryMethod : Controls how boundaries are treated for face-varying data (UVs and Vertex Colors).
  • Bi-linear (None): Renderman: InterpolateBoundaryNone
  • Smooth, (Edge Only): Renderman: InterpolateBoundaryEdgeOnly
  • Smooth, (Edges and Corners: Renderman: InterpolateBoundaryEdgeAndCorner
  • Smooth, (ZBrush and Maya "Smooth Internal Only"): Renderman: InterpolateBoundaryAlwaysSharp
- a_fvarBoundaryMethod = eAttr.create("fvarBoundaryMethod", "fvbm", 0, &stat); - MCHECKERR( stat, "cannot create MayaPolySmooth::fvarBoundaryMethod" ); - stat = eAttr.addField("Bi-linear (None)", k_BoundaryMethod_InterpolateBoundaryNone); - MCHECKERR( stat, "cannot MayaPolySmooth::fvarBoundaryMethod.addField(Bi-linear (None), k_BoundaryMethod_InterpolateBoundaryNone)" ); - stat = eAttr.addField("Smooth (Edge Only)", k_BoundaryMethod_InterpolateBoundaryEdgeOnly); - MCHECKERR( stat, "cannot MayaPolySmooth::fvarBoundaryMethod.addField(Smooth (Edge Only), k_BoundaryMethod_InterpolateBoundaryEdgeOnly)" ); - stat = eAttr.addField("Smooth (Edge and Corner)", k_BoundaryMethod_InterpolateBoundaryEdgeAndCorner); - MCHECKERR( stat, "cannot MayaPolySmooth::fvarBoundaryMethod.addField(Smooth (Edge and Corner), k_BoundaryMethod_InterpolateBoundaryEdgeAndCorner)" ); - stat = eAttr.addField("Smooth (Always Sharp)", k_BoundaryMethod_InterpolateBoundaryAlwaysSharp); - MCHECKERR( stat, "cannot MayaPolySmooth::fvarBoundaryMethod.addField(Smooth (Always Sharp), k_BoundaryMethod_InterpolateBoundaryAlwaysSharp)" ); - stat = eAttr.setDefault(k_BoundaryMethod_InterpolateBoundaryNone); - MCHECKERR( stat, "cannot MayaPolySmooth::fvarBoundaryMethod.setDefault(k_BoundaryMethod_InterpolateBoundaryNone)" ); - stat = eAttr.setReadable(true); - MCHECKERR( stat, "cannot MayaPolySmooth::fvarBoundaryMethod.setReadable()" ); - stat = eAttr.setWritable(true); - MCHECKERR( stat, "cannot MayaPolySmooth::fvarBoundaryMethod.setWritable()" ); - stat = addAttribute( a_fvarBoundaryMethod ); - MCHECKERR( stat, "cannot MayaPolySmooth::addAttribute(a_fvarBoundaryMethod)" ); - - // a_fvarPropagateCorners : - a_fvarPropagateCorners = nAttr.create("fvarPropagateCorners", "fvpc", MFnNumericData::kBoolean, 0.0, &stat); - MCHECKERR( stat, "cannot create MayaPolySmooth::fvarPropagateCorners" ); - stat = nAttr.setDefault(false); - MCHECKERR( stat, "cannot MayaPolySmooth::fvarPropagateCorners.setDefault(false)" ); - stat = nAttr.setReadable(true); - MCHECKERR( stat, "cannot MayaPolySmooth::fvarPropagateCorners.setReadable()" ); - stat = nAttr.setWritable(true); - MCHECKERR( stat, "cannot MayaPolySmooth::fvarPropagateCorners.setWritable()" ); - stat = addAttribute( a_fvarPropagateCorners ); - MCHECKERR( stat, "cannot MayaPolySmooth::addAttribute(a_fvarPropagateCorners)" ); - - // a_smoothTriangles : Apply a special subdivision rule be applied to all triangular faces that was empirically determined to make triangles subdivide more smoothly. - a_smoothTriangles = nAttr.create("smoothTriangles", "stri", MFnNumericData::kBoolean, 0.0, &stat); - MCHECKERR( stat, "cannot create MayaPolySmooth::smoothTriangles" ); - stat = nAttr.setDefault(true); - MCHECKERR( stat, "cannot MayaPolySmooth::smoothTriangles.setDefault(true)" ); - stat = nAttr.setReadable(true); - MCHECKERR( stat, "cannot MayaPolySmooth::smoothTriangles.setReadable()" ); - stat = nAttr.setWritable(true); - MCHECKERR( stat, "cannot MayaPolySmooth::smoothTriangles.setWritable()" ); - stat = addAttribute( a_smoothTriangles ); - MCHECKERR( stat, "cannot MayaPolySmooth::addAttribute(a_smoothTriangles)" ); - - // a_creaseMethod : Controls how boundary edges and vertices are interpolated.
  • Normal
  • Chaikin: Improves the appearance of multiedge creases with varying weight
- a_creaseMethod = eAttr.create("creaseMethod", "crm", 0, &stat); - MCHECKERR( stat, "cannot create MayaPolySmooth::creaseMethod" ); - stat = eAttr.addField("Normal", k_creaseMethod_normal); - MCHECKERR( stat, "cannot MayaPolySmooth::creaseMethod.addField(Normal, k_creaseMethod_normal)" ); - stat = eAttr.addField("Chaikin", k_creaseMethod_chaikin); - MCHECKERR( stat, "cannot MayaPolySmooth::creaseMethod.addField(Chaikin, k_creaseMethod_chaikin)" ); - stat = eAttr.setDefault(0); - MCHECKERR( stat, "cannot MayaPolySmooth::creaseMethod.setDefault(0)" ); - stat = eAttr.setReadable(true); - MCHECKERR( stat, "cannot MayaPolySmooth::creaseMethod.setReadable()" ); - stat = eAttr.setWritable(true); - MCHECKERR( stat, "cannot MayaPolySmooth::creaseMethod.setWritable()" ); - stat = addAttribute( a_creaseMethod ); - MCHECKERR( stat, "cannot MayaPolySmooth::addAttribute(a_creaseMethod)" ); - - // MAYA_NODE_BUILDER:END [ATTRIBUTE CREATION] ========== - - - // Set up a dependency between the input and the output. This will cause - // the output to be marked dirty when the input changes. The output will - // then be recomputed the next time the value of the output is requested. - // - // MAYA_NODE_BUILDER:BEG [ATTRIBUTE DEPENDS] ========== - stat = attributeAffects( a_creaseMethod, a_output ); - MCHECKERR( stat, "cannot have attribute creaseMethod affect output" ); - stat = attributeAffects( a_inputPolymesh, a_output ); - MCHECKERR( stat, "cannot have attribute inputPolymesh affect output" ); - stat = attributeAffects( a_subdivisionLevels, a_output ); - MCHECKERR( stat, "cannot have attribute subdivisionLevels affect output" ); - stat = attributeAffects( a_smoothTriangles, a_output ); - MCHECKERR( stat, "cannot have attribute smoothTriangles affect output" ); - stat = attributeAffects( a_fvarPropagateCorners, a_output ); - MCHECKERR( stat, "cannot have attribute fvarPropagateCorners affect output" ); - stat = attributeAffects( a_vertBoundaryMethod, a_output ); - MCHECKERR( stat, "cannot have attribute vertBoundaryMethod affect output" ); - stat = attributeAffects( a_fvarBoundaryMethod, a_output ); - MCHECKERR( stat, "cannot have attribute fvarBoundaryMethod affect output" ); - - stat = attributeAffects( a_creaseMethod, a_recommendedIsolation ); - MCHECKERR( stat, "cannot have attribute creaseMethod affect .si output" ); - stat = attributeAffects( a_inputPolymesh, a_recommendedIsolation ); - MCHECKERR( stat, "cannot have attribute inputPolymesh affect .si output" ); - stat = attributeAffects( a_subdivisionLevels, a_recommendedIsolation ); - MCHECKERR( stat, "cannot have attribute subdivisionLevels affect .si output" ); - stat = attributeAffects( a_smoothTriangles, a_recommendedIsolation ); - MCHECKERR( stat, "cannot have attribute smoothTriangles affect .si output" ); - stat = attributeAffects( a_fvarPropagateCorners, a_recommendedIsolation ); - MCHECKERR( stat, "cannot have attribute fvarPropagateCorners affect .si output" ); - stat = attributeAffects( a_vertBoundaryMethod, a_recommendedIsolation ); - MCHECKERR( stat, "cannot have attribute vertBoundaryMethod affect .si output" ); - stat = attributeAffects( a_fvarBoundaryMethod, a_recommendedIsolation ); - MCHECKERR( stat, "cannot have attribute fvarBoundaryMethod affect .si output" ); - // MAYA_NODE_BUILDER:END [ATTRIBUTE DEPENDS] ========== - - return MS::kSuccess; -} - - -// ========================================== -// Plugin -// ========================================== - -MStatus initializePlugin( MObject obj ) { - - MStatus status = MS::kSuccess; - MFnPlugin plugin( obj, "MayaPolySmooth", "1.0", "Any"); - - status = plugin.registerNode( - MayaPolySmooth::typeNameStr, - MayaPolySmooth::id, - MayaPolySmooth::creator, - MayaPolySmooth::initialize); - MCHECKERR(status, "registerNode"); - - // Source UI scripts - MString path = plugin.loadPath()+"/mayaPolySmooth.mel"; - if (!MGlobal::sourceFile(path)) { - path = "mayaPolySmooth.mel"; - if (!MGlobal::sourceFile(path)) { - MGlobal::displayWarning("Failed to source mayaPolySmooth.mel."); - } - } - - // RegisterUI - status = plugin.registerUI("mayaPolySmooth_addUI()", "mayaPolySmooth_removeUI()"); - MCHECKERR(status, "registerUI"); - - return status; -} - -MStatus uninitializePlugin( MObject obj) { - - MStatus returnStatus = MS::kSuccess; - MFnPlugin plugin( obj ); - - returnStatus = plugin.deregisterNode( MayaPolySmooth::id ); - MCHECKERR(returnStatus, "deregisterNode"); - - return returnStatus; -} diff --git a/examples/mayaPolySmooth/mayaPolySmooth.h b/examples/mayaPolySmooth/mayaPolySmooth.h deleted file mode 100644 index 4ac4ab63..00000000 --- a/examples/mayaPolySmooth/mayaPolySmooth.h +++ /dev/null @@ -1,64 +0,0 @@ -// -// 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 _MayaPolySmooth -#define _MayaPolySmooth - -#include -#include - - -class MayaPolySmooth : public MPxNode { - -public: - - MayaPolySmooth(); - - virtual ~MayaPolySmooth(); - - virtual MStatus compute( const MPlug& plug, MDataBlock& data ); - - static void * creator(); - - static MStatus initialize(); - -public: - - // 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_recommendedIsolation; // The recommended number of levels of isolation / subdivision based on topology - static MObject a_vertBoundaryMethod; // Controls how boundary edges and vertices are interpolated.
  • Smooth, Edges: Renderman: InterpolateBoundaryEdgeOnly
  • Smooth, Edges and Corners: Renderman: InterpolateBoundaryEdgeAndCorner
- static MObject a_fvarBoundaryMethod; // Controls how boundaries are treated for face-varying data (UVs and Vertex Colors).
  • Bi-linear (None): Renderman: InterpolateBoundaryNone
  • Smooth, (Edge Only): Renderman: InterpolateBoundaryEdgeOnly
  • Smooth, (Edges and Corners: Renderman: InterpolateBoundaryEdgeAndCorner
  • Smooth, (ZBrush and Maya "Smooth Internal Only"): Renderman: InterpolateBoundaryAlwaysSharp
- 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.
  • Normal
  • Chaikin: Improves the appearance of multiedge creases with varying weight
- // MAYA_NODE_BUILDER:END [ATTRIBUTE DECLARATION] ========== - - static const MTypeId id; - static const MString typeNameStr; -}; - -#endif // _MayaPolySmooth diff --git a/examples/mayaPolySmooth/mayaPolySmooth.mel b/examples/mayaPolySmooth/mayaPolySmooth.mel deleted file mode 100644 index 526eed21..00000000 --- a/examples/mayaPolySmooth/mayaPolySmooth.mel +++ /dev/null @@ -1,167 +0,0 @@ -// -// 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]; - } -} -