Created
August 31, 2015 08:25
-
-
Save SEVEZ/c519393ac2ea0f829d52 to your computer and use it in GitHub Desktop.
Simple flatten deformer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
import maya.cmds as cmds | |
if not cmds.pluginInfo( 'ehm_flattenDeformer2.py', l=1, q=1 ): | |
if cmds.loadPlugin( 'ehm_flattenDeformer2.py') == None: | |
cmds.warning('Failed to load plugin.') | |
# Apply the deformer | |
cmds.deformer( name="Flatten_Deform", type='ehm_flattenDeformer2' ) | |
''' | |
import maya.OpenMaya as om | |
import maya.OpenMayaMPx as mpx | |
import sys | |
pluginName = 'ehm_flattenDeformer2' | |
pluginId = om.MTypeId( 0x0011E183 ) | |
class ehm_flattenDeformer2( mpx.MPxDeformerNode ): | |
def __init__( self ): | |
mpx.MPxDeformerNode.__init__( self ) | |
def deform( self, block, geoItr, matrix, index ): | |
# 0. get deformer input | |
input = mpx.cvar.MPxDeformerNode_input | |
# 1. Attach a handle to input Array Attribute. | |
inputHandle_array = block.outputArrayValue( input ) | |
# 2. Jump to particular element | |
inputHandle_array.jumpToElement( index ) | |
# 3. get value of current element | |
inputValue_element = inputHandle_array.outputValue() | |
# 4. Reach to the child - inputGeom | |
inputGeom = mpx.cvar.MPxDeformerNode_inputGeom | |
inMeshHandle = inputValue_element.child( inputGeom ) | |
# 5. get Mesh | |
inMesh = inMeshHandle.asMesh() | |
# envelope | |
envelope = mpx.cvar.MPxDeformerNode_envelope | |
envelopeHandle = block.inputValue( envelope ) | |
envelopeValue = envelopeHandle.asFloat() | |
inmeshVertexItr = om.MItMeshVertex( inMesh ) | |
while not inmeshVertexItr.isDone(): | |
pPosition = inmeshVertexItr.position() | |
pPosition.y = 0.0 | |
inmeshVertexItr.setPosition( pPosition ) | |
inmeshVertexItr.next() | |
def nodeCreator(): | |
return mpx.asMPxPtr( ehm_flattenDeformer2() ) | |
def nodeInitializer(): | |
pass | |
def initializePlugin( mObj ): | |
plugin = mpx.MFnPlugin( mObj, 'Ehsan HM', '1.0', 'any' ) | |
try: | |
plugin.registerNode( pluginName, pluginId, nodeCreator, nodeInitializer, mpx.MPxNode.kDeformerNode ) | |
except: | |
sys.stderr.write( 'Load plugin failed: %s' % pluginName ) | |
def uninitializePlugin( mObj ): | |
plugin = mpx.MFnPlugin( mObj ) | |
try: | |
plugin.deregisterNode( pluginId ) | |
except: | |
sys.stderr.write( 'Unload plugin failed: %s' % pluginName ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment