MFnMesh outputGeom from deformer?

415 views
Skip to first unread message

mePt

unread,
Nov 20, 2008, 9:36:47 PM11/20/08
to python_inside_maya
hey all,

so i'm still VERY much a noob with python (so even the smallest
pointers help! ;p but i've decided to make my new deformer a python
plugin (as i'm tired of compiling for different OSs and different Maya
versions) and am having some "issues" getting the data i need so help
is appreciated up front.

i'm looking to take my deformer node, and then find the output mesh
and create a MFnMesh for it so i can manipulate some details of the
surface, and i'm having a heck of a time trying to get that data....

any tips or pointers?! thanx in advance,

br...@meljunky.com

unread,
Nov 20, 2008, 10:10:48 PM11/20/08
to python_in...@googlegroups.com
I dealt with the very same issue recently creating a custom deformer.

This is what I used to get the mesh into a MFnMesh:

def deform(self,dataBlock,geomIter,matrix,multiIndex):
        inputH  = OpenMaya.MArrayDataHandle( dataBlock.inputArrayValue(self.input) )
        inputH.jumpToElement(multiIndex)
        inputGeomH = OpenMaya.MDataHandle( inputH.inputValue().child(self.inputGeom) )
        inputObject = OpenMaya.MObject(inputGeomH.data() )
        meshFn = OpenMaya.MFnMesh( inputObject )

Hope that helps,
-Brian
www.meljunky.com

mePt

unread,
Nov 20, 2008, 11:04:56 PM11/20/08
to python_inside_maya
perfect! this did the trick!

thanx brian!

i was trying too hard to get something with using
OpenMayaMPx.cvar.MPxDeformerNode_outputGeom i think! ;)

Chad Vernon

unread,
Nov 21, 2008, 12:31:52 AM11/21/08
to python_in...@googlegroups.com
You actually shouldn't get the mesh object this way as it will cause an extra evaluation of the upstream dependency graph nodes.  If you need the mesh object, you should override the compute method instead.  If you look in the documentation for MPxDeformerNode, it gives an example of how to do it.
--
www.chadvernon.com

br...@meljunky.com

unread,
Nov 21, 2008, 1:43:27 AM11/21/08
to python_in...@googlegroups.com
Would you not lose access to geomIter? For evaluating over the membership.

I created a plug-in to displace the mesh based off a 2D texture and a membership. Suppose not looping through vertices that will stay at their default locations is worth the extra computations.


-brian

Chad Vernon

unread,
Nov 21, 2008, 2:20:24 AM11/21/08
to python_in...@googlegroups.com
You can still create the geometry iterator.  From the docs:

MStatus
exampleDeformer::compute(const MPlug& plug, MDataBlock& dataBlock)
{
MStatus status = MS::kUnknownParameter;
if (plug.attribute() == outputGeom) {
// get the input corresponding to this output
//
unsigned int index = plug.logicalIndex();
MObject thisNode = this->thisMObject();
MPlug inPlug(thisNode,input);
inPlug.selectAncestorLogicalIndex(index,input);
MDataHandle hInput = dataBlock.inputValue(inPlug);

// get the input geometry and input groupId
//
MDataHandle hGeom = hInput.child(inputGeom);
MDataHandle hGroup = hInput.child(groupId);
unsigned int groupId = hGroup.asLong();
MDataHandle hOutput = dataBlock.outputValue(plug);
hOutput.copy(hGeom);

// do the deformation
//
MItGeometry iter(hOutput,groupId,false);
for ( ; !iter.isDone(); iter.next()) {
MPoint pt = iter.position();

//
// insert deformation code here
//

iter.setPosition(pt);
}
status = MS::kSuccess;
}
return status;
}

You'll see your same code as before but since it's in the compute method, it hasn't been called yet.  Calling it in the deform method is actually the second time it gets called, which is why you get the extra evaluation.
--
www.chadvernon.com

mePt

unread,
Nov 21, 2008, 12:17:05 PM11/21/08
to python_inside_maya
haven't gotten into working on it yet, but something along the lines
of is running (granted i'm not doing anything with it yet either,
so....):

-----------------------------------------------------------------------------------------

# compute
def compute ( self, plug, dataBlock ):
if plug == OpenMayaMPx.cvar.MPxDeformerNode_outputGeom:
self.doCalculation( plug, dataBlock )
else:
return OpenMaya.kUnknownParameter


#==================================================
# doCalculation
def doCalculation( self, plug, dataBlock ):
thisNode = self.thisMObject()

envelope = OpenMayaMPx.cvar.MPxDeformerNode_envelope
envelopeHandle = dataBlock.inputValue( envelope )
fEnvelope = envelopeHandle.asFloat()

index = plug.logicalIndex()
inPlug = OpenMaya.MPlug( thisNode,
OpenMayaMPx.cvar.MPxDeformerNode_input )
inPlug.selectAncestorLogicalIndex( index,
OpenMayaMPx.cvar.MPxDeformerNode_input )
hInput = dataBlock.inputValue( inPlug )

hGeom = hInput.child( OpenMayaMPx.cvar.MPxDeformerNode_input )
hGroup = hInput.child( OpenMayaMPx.cvar.MPxDeformerNode_groupId )
groupId = hGroup.asLong()
hOutput = dataBlock.outputValue( plug )
# and just because...
hOutput.copy( hGeom )

mePt

unread,
Nov 21, 2008, 12:34:46 PM11/21/08
to python_inside_maya
with that, i can get the input meshFn easily, but am having trouble
getting the output and creating a MFnMesh out of that.



Reply all
Reply to author
Forward
0 new messages