I noticed the deform function doesn't call when you edit the deformer membership of a custom deformer in Maya 2018 but it does in 2016. Is there something new that has to be done?
I adjusted the code so that it works with the newer versions of Maya. Removing points from the deformer membership in this plugin works as expected in 2016 but not in 2018.
# ------------------------------------------------------------------------------------------- #
import maya.OpenMayaMPx as OpenMayaMPx
import maya.OpenMaya as OpenMaya
import maya.cmds as cmds
if OpenMaya.MGlobal.apiVersion() < 201600:
envelope = OpenMayaMPx.cvar.MPxDeformerNode_envelope
inputGeom = OpenMayaMPx.cvar.MPxDeformerNode_inputGeom
outputGeom = OpenMayaMPx.cvar.MPxDeformerNode_outputGeom
else:
inputGeom = OpenMayaMPx.cvar.MPxGeometryFilter_inputGeom
envelope = OpenMayaMPx.cvar.MPxGeometryFilter_envelope
outputGeom = OpenMayaMPx.cvar.MPxGeometryFilter_outputGeom
class BlendNode(OpenMayaMPx.MPxDeformerNode):
kPluginNodeId = OpenMaya.MTypeId(0x00000002)
aBlendMesh = OpenMaya.MObject()
aBlendWeight = OpenMaya.MObject()
def __init__(self):
OpenMayaMPx.MPxDeformerNode.__init__(self)
def deform(self, data, itGeo, localToWorldMatrix, mIndex):
env = data.inputValue(envelope).asFloat()
blendWeight = data.inputValue(BlendNode.aBlendWeight).asFloat()
blendWeight *= env
oBlendMesh = data.inputValue(BlendNode.aBlendMesh).asMesh()
if oBlendMesh.isNull():
return
fnBlendMesh = OpenMaya.MFnMesh(oBlendMesh)
blendPoints = OpenMaya.MPointArray()
fnBlendMesh.getPoints(blendPoints)
while not itGeo.isDone():
pt = itGeo.position()
w = self.weightValue(data, mIndex, itGeo.index())
pt = pt + (blendPoints[itGeo.index()] - pt) * blendWeight * w
itGeo.setPosition(pt)
itGeo.next()
def creator():
return OpenMayaMPx.asMPxPtr(BlendNode())
def initialize():
tAttr = OpenMaya.MFnTypedAttribute()
nAttr = OpenMaya.MFnNumericAttribute()
BlendNode.aBlendMesh = tAttr.create('blendMesh', 'bm', OpenMaya.MFnData.kMesh)
BlendNode.addAttribute( BlendNode.aBlendMesh )
BlendNode.attributeAffects(BlendNode.aBlendMesh, outputGeom)
BlendNode.aBlendWeight = nAttr.create('blendWeight', 'bw', OpenMaya.MFnNumericData.kFloat)
nAttr.setKeyable(True)
BlendNode.addAttribute(BlendNode.aBlendWeight)
BlendNode.attributeAffects(BlendNode.aBlendWeight, outputGeom)
# Make deformer weights paintable
cmds.makePaintable('blendNode', 'weights', attrType='multiFloat', shapeMode='deformer')
def initializePlugin(obj):
plugin = OpenMayaMPx.MFnPlugin(obj, 'Chad Vernon', '1.0', 'Any')
try:
plugin.registerNode('blendNode', BlendNode.kPluginNodeId, creator, initialize, OpenMayaMPx.MPxNode.kDeformerNode)
except:
raise RuntimeError, 'Failed to register node'
def uninitializePlugin(obj):
plugin = OpenMayaMPx.MFnPlugin(obj)
try:
plugin.deregisterNode(BlendNode.kPluginNodeId)
except:
raise RuntimeError, 'Failed to deregister node'
# ------------------------------------------------------------------------------------------- #