mtuttle
I've discovered that Chad Vernon's tutorial on getting the MObject to a deformer node's input geometry and then initializing a MFnMesh to get it's normals is really slow. So I tried just calling MFnGeometryFilter(thisMObject()) instead and that sped things up significantly but it still slows down the deformer noticeably. Is there any other way to get a normal of a poly object in a deformer node that would be faster than either method?
Reply 0 0
pshipkov
I am a bit unclear how do you use mfngeometryfilter normal ?
Reply 0 0
mtuttle
mtuttle wrote:
I'm using mfngeometryfilter to get the input geometry object. So instead of:

 
MStatus SomeDeformer::deform( MDataBlock& data, MItGeometry& itGeo, const MMatrix &localToWorldMatrix, unsigned int geomIndex )
{
    MStatus status;
    MArrayDataHandle hInput = data.outputArrayValue( input, &status );
    CHECK_MSTATUS_AND_RETURN_IT( status )
    status = hInput.jumpToElement( geomIndex );
    CHECK_MSTATUS_AND_RETURN_IT( status )
    MObject oInputGeom = hInput.outputValue().child( inputGeom ).asMesh();
    MFnMesh fnInputMesh( oInputGeom );
}


I have this:

 
MStatus SomeDeformer::deform( MDataBlock& data, MItGeometry& itGeo, const MMatrix &localToWorldMatrix, unsigned int geomIndex )
{
    MStatus status;
    MFnGeometryFilter filter(thisMObject());
    MObject oInputGeom = filter.inputShapeAtIndex(geomIndex,&status);
    CHECK_MSTATUS_AND_RETURN_IT( status )
    MObject oInputGeom = hInput.outputValue().child( inputGeom ).asMesh();
    MFnMesh fnInputMesh( oInputGeom );
}


That works a lot faster than the previous code, but I feel it can be faster still...
 
 
Reply 0 0
pshipkov
Oh, i see now. You are accessing the inputs through that.

I actually never use the deform method and do everything in ::compute.

        // get the input corresponding to the currently evaluated output
        MObject oThisNode = thisMObject();
        unsigned int nIndex = plug.logicalIndex();
        MPlug plugInGeo(oThisNode, input);
        plugInGeo.selectAncestorLogicalIndex(nIndex, input);
        MDataHandle hInput = data.inputValue(plugInGeo);

        // create a copy of the input geometry and "send" it to the output
        MDataHandle hInGeo = hInput.child(inputGeom);
        MDataHandle hOutGeo = data.outputValue(plug);
        hOutGeo.copy(hInGeo);

        // get the inGroupId (if needed)
        MDataHandle hGroupId = hInput.child(groupId);
        int nGroupId = hGroupId.asLong();

        MObject oOutGeo = hOutGeo.data();

From here on proceed as usual.



You got me interested. Can you post some test results from the two snippets of code you have ?
Some FPS, etc.

Another way to potentially speed things up is to use MFnMesh::getRawNormals.
Reply 0 0
mtuttle
Test results? As in a playblast, or the refresh rate during interaction within the scene?
Reply 0 0
mtuttle
Oh, and it seems that MFnGeometryFilter::inputShapeAtIndex returns the dag object for the geometry itself, not the geometry data directly. So one would have to initiate the MFnDagNode subclass for whichever geometry it is, then get its output geometry plug, and convert that to a mdatahandle using asMDataHandle() in order to be able to use that inputShape to set a ouputShape's plug data via a MItGeometry routine. So if you have a deformer intended for any sort of geometry (Mesh, NURBS, Subdiv, etc), the MFnGeometryFilter::inputShapeAtIndex method may be a bit tedious, and I don't notice any particular speed-ups from doing so, it appears to be about the same, though accessing normal data from a MFnMesh instance is faster due since neither it or MFnGeometryFilter are being declared during the iteration.
Reply 0 0
pshipkov
So you are saying it is not actually faster using MFnGeometryFilter ?
Not sure what to make of your last message :)
about the test:
this method - ## FPS
that method - ## FPS
will be enough
Reply 0 0
mtuttle
I meant that either method might have been too slow because I was calling them per each step in the iteration rather than from outside of it...I decided though that using the normal wasn't necessary but I can test either method to see how fast each one accesses geometry data...
Reply 0 0
pshipkov
Ah, got it.
Don't worry about testing.
Reply 0 0
Reply