Skip to content

Commit

Permalink
Remove unnecessary activate attribute from node. Remove code that get…
Browse files Browse the repository at this point in the history
…s input geometry.
  • Loading branch information
chadmv committed Jun 16, 2016
1 parent 08cb040 commit 8b26555
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 44 deletions.
56 changes: 13 additions & 43 deletions plug-ins/cvshapeinverter_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class cvShapeInverter(OpenMayaMPx.MPxDeformerNode):
aMatrix = OpenMaya.MObject()
aCorrectiveGeo = OpenMaya.MObject()
aDeformedPoints = OpenMaya.MObject()
aActivate = OpenMaya.MObject()

def __init__(self):
OpenMayaMPx.MPxDeformerNode.__init__(self)
Expand All @@ -19,39 +18,31 @@ def __init__(self):
self.__deformedPoints = OpenMaya.MPointArray()

def deform(self, data, itGeo, localToWorldMatrix, geomIndex):
run = data.inputValue(cvShapeInverter.aActivate).asBool()
if not run:
# Get the corrective mesh
oMesh = data.inputValue(cvShapeInverter.aCorrectiveGeo).asMesh()
if oMesh.isNull():
# Not connected yet
return
fnMesh = OpenMaya.MFnMesh(oMesh)
correctivePoints = OpenMaya.MPointArray()
fnMesh.getPoints(correctivePoints)

# Read the matrices
if not self.__initialized:
if API_VERSION < 201600:
inputAttribute = OpenMayaMPx.cvar.MPxDeformerNode_input
inputGeom = OpenMayaMPx.cvar.MPxDeformerNode_inputGeom
else:
inputAttribute = OpenMayaMPx.cvar.MPxGeometryFilter_input
inputGeom = OpenMayaMPx.cvar.MPxGeometryFilter_inputGeom
hInput = data.outputArrayValue(inputAttribute)
hInput.jumpToElement(geomIndex)
oInputGeom = hInput.outputValue().child(inputGeom).asMesh()
fnInputMesh = OpenMaya.MFnMesh(oInputGeom)
numVertices = fnInputMesh.numVertices()

hMatrix = data.inputArrayValue(cvShapeInverter.aMatrix)
for i in range(numVertices):
self.jumpToElement(hMatrix, i)
matrixCount = hMatrix.elementCount()
if matrixCount == 0:
# No data yet
return
for i in range(matrixCount):
hMatrix.jumpToArrayElement(i)
self.__matrices.append(hMatrix.inputValue().asMatrix())

oDeformedPoints = data.inputValue(cvShapeInverter.aDeformedPoints).data()
fnData = OpenMaya.MFnPointArrayData(oDeformedPoints)
fnData.copyTo(self.__deformedPoints)
self.__initialized = True

# Get the corrective mesh
oMesh = data.inputValue(cvShapeInverter.aCorrectiveGeo).asMesh()
fnMesh = OpenMaya.MFnMesh(oMesh)
correctivePoints = OpenMaya.MPointArray()
fnMesh.getPoints(correctivePoints)

# Perform the inversion calculation
while not itGeo.isDone():
Expand All @@ -70,21 +61,6 @@ def deform(self, data, itGeo, localToWorldMatrix, geomIndex):
itGeo.next()


def jumpToElement(self, hArray, index):
"""@brief Jumps an array handle to a logical index and uses the builder if necessary.
@param[in/out] hArray MArrayDataHandle to jump.
@param[in] index Logical index.
"""
try:
hArray.jumpToElement(index)
except:
builder = hArray.builder()
builder.addElement(index)
hArray.set(builder)
hArray.jumpToElement(index)


def creator():
return OpenMayaMPx.asMPxPtr(cvShapeInverter())

Expand All @@ -99,11 +75,6 @@ def initialize():
else:
outputGeom = OpenMayaMPx.cvar.MPxGeometryFilter_outputGeom

cvShapeInverter.aActivate = nAttr.create('activate', 'activate',
OpenMaya.MFnNumericData.kBoolean)
cvShapeInverter.addAttribute(cvShapeInverter.aActivate)
cvShapeInverter.attributeAffects(cvShapeInverter.aActivate, outputGeom)

cvShapeInverter.aCorrectiveGeo = tAttr.create('correctiveMesh', 'cm', OpenMaya.MFnData.kMesh)
cvShapeInverter.addAttribute(cvShapeInverter.aCorrectiveGeo)
cvShapeInverter.attributeAffects(cvShapeInverter.aCorrectiveGeo, outputGeom)
Expand All @@ -114,7 +85,6 @@ def initialize():

cvShapeInverter.aMatrix = mAttr.create('inversionMatrix', 'im')
mAttr.setArray(True)
mAttr.setUsesArrayDataBuilder(True)
cvShapeInverter.addAttribute(cvShapeInverter.aMatrix)


Expand Down
1 change: 0 additions & 1 deletion scripts/cvshapeinverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ def invert(base=None, corrective=None, name=None):
plug_deformed_points.setMObject(point_data_mobj)

cmds.connectAttr('%s.outMesh' % get_shape(corrective), '%s.correctiveMesh' % deformer)
cmds.setAttr('%s.activate' % deformer, True)

cmds.undoInfo(closeChunk=True)
return inverted_shapes
Expand Down

0 comments on commit 8b26555

Please sign in to comment.