Hi, I'm trying to convert a mesh from an assimp object to a physx convex mesh. The code I have done works fine when the model being read in is a single mesh, but if i want to bring a model that contains multiple meshes the physx mesh is joined together. This isn't an issue with the assimp since my project is rendering the assimp meshes completely fine. How can I fix this?
// Create the mesh
static physx::PxConvexMesh* CreateConvexMesh(const physx::PxVec3* verts, const physx::PxU32 numVerts, physx::PxPhysics* physics, physx::PxCooking* cooking)
{
// Create descriptor for convex mesh
physx::PxConvexMeshDesc convexDesc;
convexDesc.points.count = numVerts;
convexDesc.points.stride = sizeof(physx::PxVec3);
convexDesc.points.data = verts;
convexDesc.flags = physx::PxConvexFlag::eCOMPUTE_CONVEX;
physx::PxConvexMesh* convexMesh = NULL;
physx::PxDefaultMemoryOutputStream buf;
if (cooking->cookConvexMesh(convexDesc, buf))
{
physx::PxDefaultMemoryInputData id(buf.getData(), buf.getSize());
convexMesh = physics->createConvexMesh(id);
}
return convexMesh;
}
// Creates the object out of the assimp mesh
physx::PxConvexMesh* class::MakeObject(int index, Entity* entity)
{
physx::PxU32 vertexCount;
std::vector<physx::PxVec3> vertices;
if (entity != nullptr)
{
if (mesh)
{
vertexCount = mesh->GetNumberOfVertices(index);
std::vector<CVector3> meshVertices = mesh->GetVertices();
// Copy from cvector array to PxVec3 array
for (int i = 0; i < vertexCount; i++)
{
vertices.push_back(physx::PxVec3(trackVertices[i].x, trackVertices[i].y, trackVertices[i].z));
}
physx::PxVec3* v = vertices.data();
return CreateConvexMesh(v, vertexCount, m_PhysicsSystem->GetPhysics(), m_PhysicsSystem->GetCooking());
}
}
return nullptr;
}