Skip to content

Instantly share code, notes, and snippets.

@utilForever
Created August 19, 2019 07:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save utilForever/173434f57fd49a5ab8c7f268599b8052 to your computer and use it in GitHub Desktop.
Save utilForever/173434f57fd49a5ab8c7f268599b8052 to your computer and use it in GitHub Desktop.
Create PxShape using PxTriangleMesh
physx::PxVec3* pPxVerts = new physx::PxVec3[list.vertexCount];
for (int i = 0; i < list.vertexCount; i++)
{
ConvertPosToPhysX(list.pVerts[i], pPxVerts[i]);
}
physx::PxU32* pPxIndices = new physx::PxU32[list.triangleCount * 3];
for (int i = 0; i < list.triangleCount * 3; ++i)
{
pPxIndices[i] = list.indices[i];
}
physx::PxTriangleMeshDesc meshDesc;
meshDesc.points.count = list.vertexCount;
meshDesc.points.stride = sizeof(physx::PxVec3);
meshDesc.points.data = pPxVerts;
meshDesc.triangles.count = list.triangleCount;
meshDesc.triangles.stride = 3 * sizeof(physx::PxU32);
meshDesc.triangles.data = pPxIndices;
physx::PxDefaultMemoryOutputStream writeBuffer;
bool status = System::g_pxCooking->cookTriangleMesh(meshDesc, writeBuffer);
if (!status)
{
delete[] pPxVerts;
return;
}
physx::PxDefaultMemoryInputData readBuffer(writeBuffer.getData(), writeBuffer.getSize());
physx::PxTriangleMesh* triangleMesh = static_cast<physx::PxTriangleMesh*>(System::g_pxPhysics->createTriangleMesh(readBuffer));
if (!triangleMesh)
{
delete[] pPxVerts;
return;
}
physx::PxMeshScale scale(physx::PxVec3(1.0f, 1.0f, -1.0f), physx::PxQuat(physx::PxIdentity));
physx::PxShape* shape = System::g_pxPhysics->createShape(physx::PxTriangleMeshGeometry(triangleMesh, scale), *System::g_pxMaterial, true);
shape->setContactOffset(0.002f);
shape->setRestOffset(0.002f);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment