void GenerateTriangleMeshFromDXMesh(ID3DXMesh* Mesh, NxActor* &PhysXActor, NxVec3 pos) { typedef struct { D3DXVECTOR3 VertexPos; D3DXVECTOR3 Normal; D3DXVECTOR2 TexCoord; } Mesh_FVF; //Used to copy indices typedef struct { int IBNumber[3]; } IndexBufferStruct; int NumVerticies = Mesh->GetNumVertices(); int NumTriangles = Mesh->GetNumFaces(); DWORD FVFSize = D3DXGetFVFVertexSize(Mesh->GetFVF()); //Create pointer for vertices NxVec3* verts = new NxVec3[NumVerticies]; char *DXMeshPtr; Mesh->LockVertexBuffer(D3DLOCK_READONLY, (void**)&DXMeshPtr); for(int i = 0; i < NumVerticies; i++) { Mesh_FVF *DXMeshFVF = (Mesh_FVF*)DXMeshPtr; verts[i] = NxVec3(DXMeshFVF->VertexPos.x, DXMeshFVF->VertexPos.y, DXMeshFVF->VertexPos.z); DXMeshPtr += FVFSize; } Mesh->UnlockVertexBuffer(); //Create pointer for indices IndexBufferStruct *tris = new IndexBufferStruct[NumTriangles]; IndexBufferStruct *DXMeshIBPtr; Mesh->LockIndexBuffer(D3DLOCK_READONLY, (void**)&DXMeshIBPtr); for(int NumInd = 0; NumInd < NumTriangles; NumInd++) { tris[NumInd].IBNumber[0] = DXMeshIBPtr[NumInd].IBNumber[0]; tris[NumInd].IBNumber[1] = DXMeshIBPtr[NumInd].IBNumber[1]; tris[NumInd].IBNumber[2] = DXMeshIBPtr[NumInd].IBNumber[2]; } Mesh->UnlockIndexBuffer(); // Build physical model NxTriangleMeshDesc TriMeshDesc; TriMeshDesc.numVertices = NumVerticies; TriMeshDesc.numTriangles = NumTriangles; TriMeshDesc.pointStrideBytes = sizeof(NxVec3); TriMeshDesc.triangleStrideBytes = 3*sizeof(int); TriMeshDesc.points = verts; TriMeshDesc.triangles = tris; TriMeshDesc.flags = 0; NxTriangleMeshShapeDesc ShapeDesc; bool status = NxCookTriangleMesh(TriMeshDesc, UserStream("c:\\tmp.bin", false)); ShapeDesc.meshData = gPhysicsSDK->createTriangleMesh(UserStream("c:\\tmp.bin", true)); NxBodyDesc BodyDesc; BodyDesc.angularDamping = 0.5f; NxActorDesc actorDesc; actorDesc.shapes.pushBack(&ShapeDesc); actorDesc.globalPose.t = pos; actorDesc.body = &BodyDesc; actorDesc.density = 10.0f; PhysXActor = gScene->createActor(actorDesc); }