The frameCache Node is pretty good if you want to get a translation or 
rotation from a previous frame but you can only use it on a single 
attribute so if you if you need it to do it on translation and rotation 
together you would need six frameCache nodes.  It's a pretty easy node to 
use, just plug your driver attribute into the frameCache stream attribute 
and use the varyTime attribute for your offset (it can be positive or 
negative). Plug the varying attribute into the driven attribute and hey 
presto!

On Sunday, 30 April 2017 19:50:34 UTC+1, David DeJuan wrote:
>
> Hi,
> I'm trying to do a Node, where the input is a mesh and get the translation 
> matrix of it in the previous frame. But I don't get it.
> I have tried using the MPlug getValue setting the MDGContext one frame 
> before, but it doesn't work. 
> This is the code, it is in C++
>
> MStatus node::compute(const MPlug& plug, MDataBlock& data){
>
> if (plug == dirX) {
> MDataHandle dirXHandle = data.outputValue(dirX);
> MDataHandle dirXHandleOld = data.outputValue(dirXOld);
> MTime time = MAnimControl::currentTime();
>
> MDGContext timeContextOld(time - 1);
>
> MObject inputMeshObj = inputMeshHandle.asMesh();
> MFnMesh meshFn(inputMeshObj);
>
> MDagPath dagPath;
> dagPath = meshFn.dagPath();
> MFnDagNode transFn(dagPath);
>
> MPlug matrixPlugArray = transFn.findPlug("worldMatrix");
> matrixPlugArray.evaluateNumElements();
> MPlug matrixPlug = matrixPlugArray.elementByPhysicalIndex(0);
>
> MObject matrixO;
> matrixPlug.getValue(matrixO, timeContextOld);
> MFnMatrixData fnMat(matrixO);
> MVector res = fnMat.transformation().getTranslation(MSpace::kWor ld);
>
> // Set the output data.
> dirXHandle.setFloat(0.0);
> dirXHandleOld.setFloat(res.x);
> }else {
> return MS::kUnknownParameter;
> }
>
> return MS::kSuccess;
> }
>
>
> I am wondering also how the cacheFrame node works.
> Can anyone help me?
> Thanks
>

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/844e364d-1dad-4597-ad16-0cccba31174c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to