C++ API - Getting subframe mesh vertices


#1

I’m writing a mesh deformer plugin that gets info about the mesh from past frames to perform some calculations. In the past, to get past mesh info, I did the following

MStatus MyClass::deform(MDataBlock& dataBlock, MItGeometry& itGeo, 
        const MMatrix& localToWorldMatrix, unsigned int index)
{

    MFnPointArrayData fnPoints;


    //... other init code


    MPlug meshPlug = nodeFn.findPlug(MString("inputMesh"));

    // gets the mesh connection from the previous frame
    MPlug meshPositionPlug = meshPlug.elementByLogicalIndex(0);

    MObject objOldMesh;

    meshPositionPlug.getValue(objOldMesh);

    fnPoints.setObject(objOldMesh);
    MPointArray oldMeshPositionVertices = fnPoints.array();  // previous frame's vertices


    // ... calculations


    return MS::kSuccess;
}

If I needed more than one frame I’d run for-loops over logical indices and repeat the process. Since creating this however, I’ve found that the needs of my plugin can’t just get past frames but also frames in the future as well as subframes (between integer frames). Since my current code relies on elementByLogicalIndex() to get past frame info and that only takes unsigned integers, and the 0th index refers to the previous frame, I can’t get subframe information. I haven’t tried getting future frame info yet but I don’t think that’s possible either.

How do I query mesh vertex positions in an array for past/future/sub-frames? Is my current method inflexible and, if so, how else could I do this?


#2

first of all, does not look from your code like a previous frame to me. You’re just getting pre-deformed values of current frame.

getting a mesh values from any point in time other than “current” would mean potentially re-evaluating a whole scene: character mesh deformation depend on joint poisitions which depend on controls,etc.

you could look into MDGContext and MPxNode::forceCache to get values “from the time in the past”, but I would wonder if that’s safe inside a Compute() method of a deformer. Not to mention future performance issues.

I would say that anything that references “time in the past” needs some kind of caching approach for Maya. Either remember N previous calculations deformer did (won’t be able to control), evaluate scene every .5 frame and cache in-memory/on-disk for future access, etc.


#3

The plug has very limited use (used on alembic caches) so I don’t have to be as aware about joint position/controls etc. Theoretically, one could apply deformations before/afterwards but the intended use is to keep close to if not to the very end of a deformation chain or on cached data. I’d be fine to do a caching solution too if there were no other way to do it, I just don’t want to resort to it if there was an easier way. In the meantime, I’ll be sure to message back if I find a solution that’s stable/doesn’t require it and after I’ve looked into the info you sent me