How do I set up a ragdoll using c++ code?

Would anyone be so kind as to link me to example code? I currently have a PxBoxGeometry covering my character at the moment and I also have an articulation with several links (inside the box) with eSimulation disabled. I believe the general idea is to disable my animation, disable the box simulation and then enable the link simulation. Am I along the right track? I am surprised there is no example code or snippets from nvidia.

Hi there,

I don’t know if it’s common or not, but we rather rely on the PxRigidBodyFlag::eKINEMATIC mode of the rigid body to switch from an animated character to the ragdoll.

Here is our process.

At first, we initialize the rigid bodies, shapes and constraints according to our character’s shape, and with the eKINEMATIC set to true.

We apply the animation transforms each frame thanks to the setGlobalPose method (you may also do it with the setKinematicTarget method):

for (int rigidBodyIndex = 0; rigidBodyIndex < physicsEntityTypeData._nbRigidBodies; ++rigidBodyIndex)
{
	/*
	...
	code to extract the tmp_PxTransform value from my current animation
	...
	*/
	_rigidDynamicBodies[rigidBodyIndex]->setGlobalPose(tmp_PxTransform);
}

Then at one time, we switch to ragdoll mode by changing the eKINEMATIC mode of all rigid bodies:

for (int rigidBodyIndex = 0; rigidBodyIndex < physicsEntityTypeData._nbRigidBodies; ++rigidBodyIndex)
{
	rigidBodiesLinearVelocities[rigidBodyIndex]->setRigidBodyFlag(PxRigidBodyFlag::eKINEMATIC, false);
	rigidBodiesLinearVelocities[rigidBodyIndex]->wakeUp();

	//set current velocity to keep inertia
	dynamicRigidBody->setLinearVelocity(_rigidBodiesLinearVelocities[rigidBodyIndex]);
	dynamicRigidBody->setAngularVelocity(_rigidBodiesAngularVelocities[rigidBodyIndex]);
}

Once the character is in ragdoll mode, we extract the transforms from the rigid bodies for the visualization and skinning system:

for (int rigidBodyIndex = 0; rigidBodyIndex < physicsEntityTypeData._nbRigidBodies; ++rigidBodyIndex)
{
	tmp_PxTransform = _rigidDynamicBodies[rigidBodyIndex]->getGlobalPose();
	/*
	...
	code to put the tmp_PxTransform value to our anim/skinning/visu system
	...
	*/
}

I hope it helps.

Thanks!