-1

So I am trying to cook a mesh into a PxTriangleMesh. Here is my code (actually copy-pasted from the documentation):

PxTriangleMeshDesc meshDesc;
meshDesc.points.count = vertices->size();
meshDesc.points.stride = sizeof(PxVec3);
meshDesc.points.data = vertices;

meshDesc.triangles.count = vertices->size() / 3;
meshDesc.triangles.stride = 3 * sizeof(unsigned int);
meshDesc.triangles.data = indices;

assert(meshDesc.isValid());

PxDefaultMemoryOutputStream writeBuffer;
PxTriangleMeshCookingResult::Enum result;
bool status = my_cooking->cookTriangleMesh(meshDesc, writeBuffer, &result);
if (!status)
    return NULL;

PxDefaultMemoryInputData readBuffer(writeBuffer.getData(), writeBuffer.getSize());
return p.createTriangleMesh(readBuffer);

The assert does not fail but

my_cooking->cookTriangleMesh(..)

returns the status 'false'. I would guess there's something wrong with my indices but the documentation gives very little information about what they expect me to fill in there. I am using this little OBJ-loader: https://github.com/Bly7/OBJ-Loader. Loading a simple cube returns 36 vertices and 36 indices, just like it should do.

When loading the obj, I just do this:

indices = my_loader.LoadedIndices;

I can confirm that this works perfectly fine for vertices, uvs and normals. 'indices' is defined like this:

std::vector<unsigned int> indices
  1. Is PhysX expecting me to fill other data into triangles.data?
  2. If not, why is cookTriangleMesh() not returning true?
uCantHim
  • 121
  • 1
  • 7

1 Answers1

1

I think I had the similar problem in the past. I think that the problem is with what meshDesc.triangles.data expects to receive. Either use the array and not std::vector or just change this:

meshDesc.triangles.data = indices;

to this:

meshDesc.triangles.data = &indices[0];

My code is working with this solution, please update if this solves your issue.

Josse
  • 59
  • 1
  • 4