Animating with the c++ API, viewport stops refreshing...

Animating with the c++ API, viewport stops refreshing...

Anonymous
Not applicable
948 Views
2 Replies
Message 1 of 3

Animating with the c++ API, viewport stops refreshing...

Anonymous
Not applicable

I am trying to wrap my head around moving an object using the API.

 

I create a joint, using:

 

MFnIkJoint* rootJoint = new MFnIkJoint();
MObject rootTransform = rootJoint->create(MObject::kNullObj, &status);

Then I launch a thread that moves this joint:

 

 

MStatus stat = MThreadAsync::init();
	if (MStatus::kSuccess != stat) {
		MString str = MString("Error creating MThreadAsync");
		MGlobal::displayError(str);
	}
	else
	{
		MThreadAsync::createTask(ApplyData, this, NULL, NULL);
	}

 

 

 

Where the thread function contains:

 

 

MVector currentPos;

while(dataExit == false) { currentPos.x += 0.0001; MStatus status = rootJoint->setTranslation(currentPos, MSpace::kTransform); }

 

I run this function, and it works great. the joint is created in the viewport, and starts moving. Then, after a few seconds, it stops. When i stop the thread, the translation value does not match where the joint is in the viewport.

 

It is as if the thread keeps assigning data, but the viewport stops updating. Do I need to add a `refreshviewport` of some kind here?

 

Thank you.

 

 

 

0 Likes
949 Views
2 Replies
Replies (2)
Message 2 of 3

cheng_xi_li
Autodesk Support
Autodesk Support

Hi,

 

Most Maya classes are not thread safe. You can check this document for more details.

 

http://help.autodesk.com/view/MAYAUL/2018/ENU/?guid=__files_GUID_2BEF58D3_6162_4235_A6CE_3D8B0742A0A...

 

I am not sure how you are updating the data and what is your goal here.  Could you give me more details? If you are trying to use it for animating objects in viewport directly in a different thread, it probably isn't a good idea. You could try to use executeCommandOnIdle to keep animation going by executing commands when Maya is in idle.

 

BTW:  For you original question, dgDirty command could enforce dirty propagate and ogs -reset could enforce viewport to reevaluate and redraw.

 

Yours,

Li

0 Likes
Message 3 of 3

negow
Advocate
Advocate

I've got a similar issue, albeit without threading.

 

ragdollviewportglitch.gif

Some notes.

 

1. The `pCube1.translate` is connected to `outputTranslate` of a custom shape node, `rRigid1`, which is a MPxLocatorNode

1. The wireframe is the MPxDrawOverride of `rRigid1`

1. The `rRigid1` wireframe draws correctly, `pCube1` does not

1. Values are correct, as seen in the channel box

1. Changes to any value on the custom shape causes the Maya-native polyCube to snap into place.

 

With this thread, I found that calling `ogs -reset` also resolves the issue.

 

What can I do in my MPxLocator or MPxDrawOverride subclasses to avoid having to call `ogs -reset`? Or, worst case, is there an API/C++ equivalent?

 

Thanks!

 

Edit: I might add, I've experimented with `MFnAttribute.setAffectsWorldSpace` and `.setAffectsAppearance` on just about every attribute involved without any noticeable change in behavior. I've also tested on 3 GPUs (integrated and discrete) on 2 separate machines.

 

Edit 2: Also tested with DirectX 11 viewport, and can confirm it *does work* as expected in the Legacy viewport. And that this is mostly tested with Maya 2020.2 on Windows.

0 Likes