Original Post
I'm trying to find a good way of creating collision detection for triangle meshes. My major problem is that pmaps aren't a very good option (support for it may soon be dropped) and there are no tutorials on using NxTriangleMeshShape (no idea why). I did try using the InitBunny function in the documentation (re-adapted) but what it produces is a very, very bouncy object that doesn't want to stay still (even if I apply a massive force to it, just ignores it): Right now my major worry with it is that I don't know what it wants when it asks for bunnyDesc.triangles, I tried using verts but it produced an error, so I commented it out. Therse no help anywhere about it which is really frustrating.
NxActor* PhysX::InitBunny(const NxVec3& pos, float* vertices, const NxReal density, NxTriangleMeshDesc& cmd, int numVertices, int numFaces)
{
NxActorDesc actorDesc;
NxBodyDesc bodyDesc;
NxTriangleMesh *triangleMesh;
NxVec3* verts = new NxVec3[numVertices];
int ii = -1;
for(int i = 0; i < numVertices; i++)
{
++ii;
verts.x = vertices[ii]/2;
verts.y = vertices[++ii]/2;
verts.z = vertices[++ii]/2;
}
std::ofstream c(L"nxvec3.txt");
ii = -1;
for(int i = 0; i < numVertices; i++)
{
++ii;
c<<vertices[ii]/2<<", "<<vertices[++ii]/2<<", "<<vertices[++ii]/2<<"\n";
}
NxTriangleMeshDesc bunnyDesc;
bunnyDesc.numVertices = numVertices;
bunnyDesc.numTriangles = numFaces;
bunnyDesc.pointStrideBytes = sizeof(NxVec3);
bunnyDesc.triangleStrideBytes = 3*sizeof(NxU32);
bunnyDesc.points = verts;
//bunnyDesc.triangles = verts;
bunnyDesc.flags = 0;
gCooking->NxCookTriangleMesh(bunnyDesc, UserStream("c:\\cooked.bin", false));
NxTriangleMeshShapeDesc bunnyShapeDesc;
bunnyShapeDesc.localPose.t = NxVec3(0, 0, 0);
NxInitCooking();
// Cooking from memory
MemoryWriteBuffer buf;
bool status = NxCookTriangleMesh(bunnyDesc, buf);
triangleMesh = gPhysicsSDK->createTriangleMesh(MemoryReadBuffer(buf.data)); //<-- hello
bunnyShapeDesc.meshData= triangleMesh;
NxActor* newActor = gScene->createActor(actorDesc);
if (bunnyShapeDesc.meshData)
{
NxActorDesc actorDesc;
actorDesc.shapes.pushBack(&bunnyShapeDesc);
if (density)
{
actorDesc.body= &bodyDesc;
actorDesc.density= density;
}
else
{
actorDesc.body = NULL;
}
actorDesc.globalPose.t = pos;
NxActor* actor = gScene->createActor(actorDesc);
// Attach drawable mesh to mesh shape's user data
NxShape*const* shapes = actor->getShapes();
shapes[0]->isTriangleMesh()->getTriangleMesh().saveToDesc(cmd);
shapes[0]->userData = (void*)&cmd;
return actor;
// gPhysicsSDK->releaseConvexMesh(*convexShapeDesc.meshData);
}
return NULL;
}