• Create Account

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

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

4 replies to this topic

### #1Tom123  Members

125
Like
0Likes
Like

Posted 15 January 2013 - 03:59 AM

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!"<<endl;

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;
cooking->setParams(cookingP);

bool status = cooking->cookTriangleMesh(meshDesc, writeBuffer);

if(!status)
cerr<<"fail cooking";

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);

### #2Zaoshi Kaba  Members

7803
Like
0Likes
Like

Posted 15 January 2013 - 06:40 AM

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.

### #3Tom123  Members

125
Like
0Likes
Like

Posted 15 January 2013 - 11:28 PM

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!"<<endl;
PxShape* shape = plane->createShape(PxPlaneGeometry(), *mMaterial);

if (!shape)
cerr<<"create shape failed!"<<endl;

I want to be familiar with PxTriangleMeshGeometry function so I use it to create a cube

### #4Hodgman  Moderators

49429
Like
0Likes
Like

Posted 16 January 2013 - 12:01 AM

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.

### #5Tom123  Members

125
Like
0Likes
Like

Posted 16 January 2013 - 01:16 AM

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.

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?

Edited by Tom123, 16 January 2013 - 01:17 AM.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.