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

This topic is 2163 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

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

Share on other sites

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.

Share on other sites
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

Share on other sites

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.

Share on other sites
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

1. 1
2. 2
Rutin
19
3. 3
khawk
18
4. 4
5. 5

• 9
• 12
• 16
• 26
• 10
• Forum Statistics

• Total Topics
633769
• Total Posts
3013759
×