PhysX 3.2 : Strange pose of convex hulls for 4-wheeled vehicle

In an empty scene, I create a rigid body and a vehicle using the same mesh (same instance).
The convex hulls poses are correct for the rigid body, but completely wrong for the vehicle chassis.

Here is the code for creating shapes for rigid body :

bool N3DEPhysicsRigidActor::setGeometry(PCHMesh& mesh,const PxMeshScale& scale)
{
	pchMesh=&mesh;

	PxFilterData collisionFilterData;
	collisionFilterData.word0=static_cast<PxU32>(ShapeFilterGroup::OtherObjectShape);

	PxConvexMeshGeometry geom;
	geom.scale=scale;

	for (size_t i=0;i<mesh.convexMeshes.size();i++)
	{
		PxMaterial * material=mesh.convexMeshes[i].first;
		geom.convexMesh=mesh.convexMeshes[i].second;

		PxShape * shape=actor->createShape(geom,*material);
		if (shape==nullptr) return false;

		shape->userData=material->userData;
		shape->setSimulationFilterData(collisionFilterData);
	}

	return true;
}

and here is the code for vehicle :

//actor :
	PxRigidDynamic * actor=physics->physics->createRigidDynamic(PxTransform::createIdentity());

	PxConvexMeshGeometry geom;
	PxShape * shape=nullptr;
	PxMaterial * material=nullptr;

	//add chassis shapes :
	for (size_t i=0;i<chassisMesh.convexMeshes.size();i++)
	{
		geom.convexMesh=chassisMesh.convexMeshes[i].second;
		material=chassisMesh.convexMeshes[i].first;
		
		shape=actor->createShape(geom,*material);
		if (shape==nullptr)	return false;

		shape->setSimulationFilterData(physics->chassisCollisionFilterData);
		shape->userData=material->userData;
	}

I’m sure the cooking code works because every rigid body’s shapes are perfectly fine. The bug occurs only with vehicle.
Any help would be really appreciated, thank you.

Could you provide a bit more detail about how the pose appears incorrect? Is it the case, for example, that it is rotate 90 degrees about the up vector? Or is it the case that the chassis could be correct but that the wheels appear to be in the wrong place? A screenshot would really help diagnose the problem.

Thanks,

Gordon

Thank you for the fast reply.
For vehicles, the convex meshes are correctly oriented but wrongly positioned. All is ok when I use the same geometry data for rigid bodies.
I’ve attached the PVD file. Just remove the .doc extension, thank you.
debug.pxd2.doc (523 KB)

I think I know what is causing this.

The vehicle update function PxVehicleUpdates poses all the collision shapes of the vehicle that represent wheels. The idea here is to pose each wheel’s shape with the rotation around the rolling axis, the suspension travel and the steer and camber angles. There is a function PxVehicleWheelsSimData::setWheelShapeMapping that maps each wheel to a specific shape on the vehicle’s rigid body. I suspect that this is incorrectly set up.

From your pvd it looks like your vehicle has no collision shapes for wheels. There’s no problem wtih that provided you set the vehicle up so that it won’t attempt to pose wheel shapes. The default is that wheel i is mapped to shape i. This is documented in the doxy comments for PxVehicleWheelsSimData::setWheelShapeMapping.

I recommend that for each wheel you call myVehicle.mWheelsSimData.setWheelShapeMapping(i, -1). This will stop the vehicle update function from attempting to pose the wheels. You only need to do this once as part of your vehicle initialisation code. If you later decide to add collision shapes for the wheels you will need to reset the mapping.

Thanks,

Gordon


Thank you Gordon.
I think I understand what’s going on : the first 4 convex meshes must define the 4 wheels, and must be, in local pose, positioned at origin. The other convex hulls defined the chassis’s shape.

//actor :
	PxRigidDynamic * actor=physics->physics->createRigidDynamic(PxTransform::createIdentity());

	PxConvexMeshGeometry geom;
	PxShape * shape=nullptr;
	PxMaterial * material=nullptr;

	//add wheel shapes:
	for (size_t i=0;i<4;i++)
	{
		geom.convexMesh=wheelMeshes[i]->convexMeshes[0].second;
		material=wheelMeshes[i]->convexMeshes[0].first;
		shape=actor->createShape(geom,*material);
		if (shape==nullptr)	return false;

		shape->setSimulationFilterData(physics->wheelCollisionFilterData);
		shape->userData=material->userData;
	}

	//add chassis shapes :
	for (size_t i=0;i<chassisMesh.convexMeshes.size();i++)
	{
		geom.convexMesh=chassisMesh.convexMeshes[i].second;
		material=chassisMesh.convexMeshes[i].first;
		
		shape=actor->createShape(geom,*material);
		if (shape==nullptr)	return false;

		shape->setSimulationFilterData(physics->chassisCollisionFilterData);
		shape->userData=material->userData;
	}

With these assumptions, I get correct results :
debug.pxd2.doc (561 KB)

Glad that fixed your problem.

Thanks,

Gordon