Maya 2019 Cached Playback c++ api?

Maya 2019 Cached Playback c++ api?

Sebastian_Wiendl
Enthusiast Enthusiast
1,491 Views
4 Replies
Message 1 of 5

Maya 2019 Cached Playback c++ api?

Sebastian_Wiendl
Enthusiast
Enthusiast

Hi all,

 

I have seen several videos about the new Cached Playback option in Maya 2019 and read about it in the release notes / announcements.

 

Is there any c++ api to interact with this; more specifically:

 

  1. Can I query the state, i.e. which frames are cached, which aren't; is cached playback enabled, etc.
  2. Is there a callback so that I can get a callback whenever the cache gets invalidated, preferably also letting me know which attribute has caused the invalidation and what frame is the oldest valid frame.

I guess, in general, what c++ api is available to interact/query anything and everything about the new Cached Playback feature?

 

I'm really excited about this.

 

Thanks for your help.

 

Cheers,

Sebastian

0 Likes
1,492 Views
4 Replies
Replies (4)
Message 2 of 5

Sebastian_Wiendl
Enthusiast
Enthusiast

I am trying to make the most of Maya 2019 and would really appreciate any help on this.

 

Cheers,

Sebastian

0 Likes
Message 3 of 5

yupeng.zhang58CFR
Explorer
Explorer

Hi, sebastian,

 

Thanks for trying out the new technology!

 

This is Yupeng from the Maya team.

 Here is a link to the powerful 'cacheEvaluator' MEL/Python command, which encapsulated most API for Cached Playback :

https://help.autodesk.com/view/MAYAUL/2019/ENU/?guid=__CommandsPython_cacheEvaluator_html

You can also call these command from C++ code with `MGlobal` class.

In term of advanced C++ API, the team is actively working on it 🙂

 

Here are some stats about your question:

  1. Can I query the state, i.e. which frames are cached, which aren't; is cached playback enabled, etc.
    1. Use the python command `maya.cmds.evaluator( name='cache', q=True, info=True )`, this will print out the cached frames. You may need to do some parsing yourself. 
  2. Is there a callback so that I can get a callback whenever the cache gets invalidated, preferably also letting me know which attribute has caused the invalidation and what frame is the oldest valid frame.
    1. Sadly, there is no API for this in Maya 2019 (Right now).
    2. For some workaround, I will recommend you to encapsulate your custom data as Maya Attributes: it will get properly compute-on-demand, proper parallelism, and can be computed in the background. We may be able to share more examples or guidance-code if you would like to share some requirements/scenario with us 🙂
Message 4 of 5

Sebastian_Wiendl
Enthusiast
Enthusiast

Hi Yupeng,

 

First of all, thank you very much for getting back to me.

 

Let me give you a more specific scenario:

I am writing a plugin that takes animated meshes as input and internally saves some states for the mesh.
If the mesh or the mesh animation changes, I need to basically flush all invalid states and recalculate them.

 

Now, as an example, if you look at a rigged and skinned character, whenever I move a bone or change an animation keyframe, the Maya evaluation cache resets to the last valid state and starts refreshing.

I would like to be able to get that information, i.e. some callback saying that the mesh (animation) has changed and that the lowest valid frame is e.g. 20.
I am using an attribute that triggers compute and also tried putting an attribute changed callback on the source mesh object, but I am getting a lot of callback triggers while I am moving a bone.
I really only want one callback/notification when I am done editing (for example only when the mouse is released if you move the bone with the Move Tool) that tells me the new smallest valid frame.

 

Do you have any suggestions for this?

 

Cheers,
Sebastian

0 Likes
Message 5 of 5

yupeng.zhang58CFR
Explorer
Explorer

Thanks for the information 🙂

 

I am not really sure I have grabbed all the details, but here is some suggestion I can make:

 

1. A lot of attribute-changed callbacks when moving the bone.

Try to set a keyframe or two on the bone. If there are no keyframes attached to the bone, Maya will think the bone as a 'uniform' or 'static' object, which makes dragging/rotating slow and may trigger a lot of attribute-changed callback.

 

2. Compute your node's states with Cached Playback

Because Cached Playback may happen in the background (it can even happen in concurrently with Foreground rendering), we really recommend the plugin-nodes to use and respect Maya's "Dependency-Node" framework.

This means, if you have some states that may change with time (depend on inputMesh), you should store it in the node's Maya attribute.

Once you set this attribute to depend on input-mesh, the node/attribute will be invalidated just like Maya's builtin things. And they can be computed in the background 🙂

 

Some pseudo code like:

class MyNode : MPxSurfaceShape {
	static MObject myMeshStatesAttr; // The attribute captured your mesh states
	MStatus compute( const MPlug& plug, MDataBlock& data )
	{
		if (plug.name() == "myMeshStatesAttr")
		{
			auto iMesh = data.inputValue(inputMesh);
			// ..
			// Compute your states based on inputMesh
		}
	}

	MStatus setDependentsDirty(const MPlug& plug, MPlugArray& plugArray)
	{
		// Important to override this method
		// Otherwise Maya may not cache 'myMeshStatesAttr'
		// Even if you set it with MFnAttribute::dependOn()
		if (plug.name() == "inputMesh")
		{
			MObject thisNode = thisMObject();
			MPlug oPlug(thisNode, myMeshStatesAttr);
			plugArray.append(oPlug);
		}
	}
}

Well, I agree that to store data as Maya attribute is a pain >_<

0 Likes