Skip to main content
GameDev.net gamedev.net
🔒 Locked 🎮 Unity

[physx3.2.2 question]collision problem related to triangle mesh object

Started by Tom123 Jan 15, 2013 at 9:59 AM 3 replies 1.9k views
Original Post
Tom123
Tom123

hi guys. I'm a newbie and learning physx 3.2.2.

Now i meet a problem that I use PxTriangleMesh function to create a simple cube. We have also used PxSphereGeometry function and created a sphere. We create also a plane. The sphere can successfully drops down, touch the plane and stop, but the cube which created by triangle mesh directly fall down and over the plane. There may be something wrong with the collision detection part but I don't know why and how.

Here is the code that create the cube with triangle mesh:

// create triangle mesh
PxTransform transform(PxVec3(0.0f, 15.0f, 0.0f), PxQuat::createIdentity());
PxRigidDynamic *actor = gPhysicsSDK->createRigidDynamic(transform);
//actor->setRigidDynamicFlag(PxRigidDynamicFlag::eKINEMATIC,true);
if (!actor)
cerr<<"create actor failed!"<
PxTriangleMeshDesc meshDesc;
PxVec3 data[8]={
PxVec3(-1.0,-1.0,-1.0),
PxVec3(1.0,-1.0,-1.0),
PxVec3(-1.0,1.0,-1.0),
PxVec3(1.0,1.0,-1.0),
PxVec3(-1.0,-1.0,1.0),
PxVec3(1.0,-1.0,1.0),
PxVec3(-1.0,1.0,1.0),
PxVec3(1.0,1.0,1.0)
};
PxU32 indices[12*3] = {
1,2,3,
0,2,1,
5,7,6,
4,5,6,
5,4,1,
1,4,0,
1,3,5,
3,7,5,
3,2,7,
2,6,7,
2,0,6,
4,6,0
};
meshDesc.points.count = 8;
meshDesc.points.stride = sizeof(PxVec3);
meshDesc.points.data = data;
meshDesc.triangles.count = 12;
meshDesc.triangles.stride = 3 * sizeof(PxU32);
meshDesc.triangles.data = indices;
meshDesc.flags = PxMeshFlags(0);
PxToolkit::MemoryOutputStream writeBuffer;
PxCookingParams cookingP;
cookingP.suppressTriangleMeshRemapTable = true;
cookingP.buildTriangleAdjacencies = true;
cooking->setParams(cookingP);
bool status = cooking->cookTriangleMesh(meshDesc, writeBuffer);
if(!status)
cerr<<"fail cooking";
PxToolkit::MemoryInputData readBuffer(writeBuffer.getData(), writeBuffer.getSize());
PxTriangleMesh* triangleMesh = gPhysicsSDK->createTriangleMesh(readBuffer);
PxTriangleMeshGeometry geom(triangleMesh);
PxShape *aTriMeshShape = actor->createShape(geom, *mMaterial,PxTransform(PxVec3(0.0f, 0.0f, 0.0f), PxQuat::createIdentity()));
actor->setAngularDamping(0.0);
actor->setLinearVelocity(PxVec3(0,-1.0,0));
actor->setLinearVelocity(PxVec3(0,-1.0f,0), true);
actor->userData = (void*) 1;
actor->setRigidDynamicFlag(PxRigidDynamicFlag::eUSE_KINEMATIC_TARGET_FOR_SCENE_QUERIES,true);
actor->setActorFlag(PxActorFlag::eVISUALIZATION,true);
gScene->addActor(*actor);
Zaoshi Kaba
Zaoshi Kaba

How do you create your plane?

TriangleMesh <--> TriangleMesh collision is very complex therefore usually not implemented or not enabled by default.

For cube you should use PxBoxGeometry or something similar.

Tom123
Tom123
How do you create your plane?

TriangleMesh <--> TriangleMesh collision is very complex therefore usually not implemented or not enabled by default.

For cube you should use PxBoxGeometry or something similar.

here is code that create the plane:

//1) Create ground plane
PxReal d = 0.0f;
PxTransform pose = PxTransform(PxVec3(0.0f, 0.0f, 0.0f),PxQuat(PxHalfPi, PxVec3(0.0f, 0.0f, 1.0f)));
PxRigidStatic* plane = gPhysicsSDK->createRigidStatic(pose);
if (!plane)
cerr<<"create plane failed!"<
PxShape* shape = plane->createShape(PxPlaneGeometry(), *mMaterial);
if (!shape)
cerr<<"create shape failed!"<
gScene->addActor(*plane);
I want to be familiar with PxTriangleMeshGeometry function so I use it to create a cube
Hodgman
Hodgman

From the documentation (Shapes and Geometries -> Triangle Meshes):

"Shapes with triangle mesh geometries may only be created for static and kinematic actors"

You can't have a dynamic (moving) object that uses a triangle mesh for collisions, it's not supported.

Tom123
Tom123
From the documentation (Shapes and Geometries -> Triangle Meshes):

"Shapes with triangle mesh geometries may only be created for static and kinematic actors"

You can't have a dynamic (moving) object that uses a triangle mesh for collisions, it's not supported.

biggrin.png thank you!! I add " actor->setRigidDynamicFlag(PxRigidDynamicFlag::eKINEMATIC,true); " to change the triangle dynamic actor to kinematic actor, I use boxgeometry create a set of cubes and those are the dynamic actors. Then use them to hit kinematic actor--triangle mesh cube. The kinematic actor cube can intercept dynamic actor cubes, it seems that the collision detection happened, but now a new problem appeared, the kinematic actor cube can not fall down, it just hang on the air even though I have set the kinematic target and linear velocity. So what's the problem here?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.