Hi all,
I’m trying to write a smooth deformer in Maya using Python API. I need to find the adjacent vertices’ positions for each vertex. I found that MItMeshVertex.getConnectedVertices() does exactly what I need but I can’t create a MItMeshVertex cause it needs an MObject as input and I don’t know how to find the MObject of the current inputGeom.
This is how far I went by now:
##############################################################################
import maya.OpenMaya as om
import maya.OpenMayaMPx as mpx
import sys
pluginName = ‘flattenDeformer’
pluginId = om.MTypeId( 0x0011E183 )
class flattenDeformer( 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.inputArrayValue( input )
# 2. Jump to particular element
inputHandle_array.jumpToElement( index )
# 3. get value of current element
inputValue_element = inputHandle_array.inputValue()
# 4. Reach to the child - inputGeom
inputGeom = mpx.cvar.MPxDeformerNode_inputGeom
inMeshHandle = inputValue_element.child( inputGeom )
# 5. get Mesh
inMesh = inMeshHandle.asMesh()
# ----------------------------------where I have problem--------------------------------------
# vertexMeshItr = om.MItMeshVertex( inMesh )
envelope = mpx.cvar.MPxDeformerNode_envelope
envelopeHandle = block.inputValue( envelope )
envelopeValue = envelopeHandle.asFloat()
while not vertexMeshItr.isDone():
#connectedVerts = vertexMeshItr.getConnectedVertices( )
position = vertexMeshItr.position( )
position.y = position.y - (position.y * envelopeValue);
vertexMeshItr.setPosition( position )
vertexMeshItr.next()
return om.MStatus.kSuccess
def nodeCreator():
return mpx.asMPxPtr( flattenDeformer() )
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 )
##############################################################################
Any help is appreciated.
Ehsan