Hi so i have wrote a python script to convert an wavefront OBJ file from blender into PxVec3 vertex array and a PxU32 triangle array, which is then used to create the triangle mesh.
However the issue that I’m experiencing is that this works perfectly sometimes, and other time not so much - with the same mesh. E.g. I start my PhysX program, and create 10 of the same objects and some of them look like this:
https://i.stack.imgur.com/3mxES.png
but then 2 or 3 will look like this despite being loaded with the same data
https://i.stack.imgur.com/FIaRg.png
both are being passed the vertex and triangles array however they result in vastly different outputs. Below is the code i am using to cook the mesh
class CustomObject : public StaticActor
{
public:
ModelLoader* modelLoader;
std::vector<PxVec3>objectVerts;
std::vector<PxU32>objectTrigs;
CustomObject(const PxTransform& pose = PxTransform(PxIdentity), string vert = "", string trig = "") :
StaticActor(pose)
{
//creates new model loader to load vertex and triangle data
modelLoader = new ModelLoader();
objectVerts = modelLoader->LoadVertexFile(vert); //returns PxVec3 and stores in vector
objectTrigs = modelLoader->LoadTrianglesFile(trig); //returns PxU32 and stores in vector
PxTriangleMeshDesc mesh_desc;
mesh_desc.points.count = (PxU32)objectVerts.size();
mesh_desc.points.stride = sizeof(PxVec3);
mesh_desc.points.data = &objectVerts.front();
mesh_desc.triangles.count = (PxU32)objectTrigs.size();
mesh_desc.triangles.stride = 3 * sizeof(PxU32);
mesh_desc.triangles.data = &objectTrigs.front();
PxDefaultMemoryOutputStream stream;
if (!GetCooking()->cookTriangleMesh(mesh_desc, stream))
throw new Exception("TriangleMesh::CookMesh, cooking failed.");
PxDefaultMemoryInputData input(stream.getData(), stream.getSize());
PxTriangleMeshGeometry meshGeometry = GetPhysics()->createTriangleMesh(input);
CreateShape(meshGeometry);
}
~CustomObject()
{
std::cout << "Custom Object Deleted" << std::endl;
delete modelLoader;
}
};
EDIT: I’ve updated my code to make sure that CustomObject always has a copy of the vertex and triangle data, however the problem still persists