PxConvexMesh* createConvexMesh( const std::vector<PxVec3>& verts, PxConvexFlags flags ) { PxConvexMeshDesc convexDesc; convexDesc.points.count = verts.size(); convexDesc.points.stride = sizeof(PxVec3); convexDesc.points.data = &(verts[0]); convexDesc.flags = flags; MemoryOutputStream writeBuffer; if ( !SDK_COOK->cookConvexMesh(convexDesc, writeBuffer) ) return NULL; MemoryInputData readBuffer( writeBuffer.getData(), writeBuffer.getSize() ); return SDK_OBJ->createConvexMesh( readBuffer ); }
PxConvexMesh* PxToolkit::createConvexMesh(PxPhysics& physics, PxCooking& cooking, const PxVec3* verts, PxU32 vertCount, PxConvexFlags flags) { PxConvexMeshDesc convexDesc; convexDesc.points.count = vertCount; convexDesc.points.stride = sizeof(PxVec3); convexDesc.points.data = verts; convexDesc.flags = flags; MemoryOutputStream buf; if(!cooking.cookConvexMesh(convexDesc, buf)) return NULL; PxToolkit::MemoryInputData input(buf.getData(), buf.getSize()); return physics.createConvexMesh(input); }
PxTriangleMesh* createTriangleMesh( const std::vector<PxVec3>& verts, const std::vector<PxU32>& indices ) { PxTriangleMeshDesc meshDesc; meshDesc.points.count = verts.size(); meshDesc.points.stride = sizeof(PxVec3); meshDesc.points.data = &(verts[0]); meshDesc.triangles.count = indices.size() / 3; meshDesc.triangles.stride = 3 * sizeof(PxU32); meshDesc.triangles.data = &(indices[0]); MemoryOutputStream writeBuffer; if ( !SDK_COOK->cookTriangleMesh(meshDesc, writeBuffer) ) return NULL; MemoryInputData readBuffer( writeBuffer.getData(), writeBuffer.getSize() ); return SDK_OBJ->createTriangleMesh( readBuffer ); }
PxClothFabric* createClothFabric( const std::vector<PxVec3>& verts, const std::vector<PxU32>& indices, const osg::Vec3& gravity ) { PxClothMeshDesc meshDesc; meshDesc.points.count = verts.size(); meshDesc.points.stride = sizeof(PxVec3); meshDesc.points.data = &(verts[0]); meshDesc.triangles.count = indices.size() / 3; meshDesc.triangles.stride = 3 * sizeof(PxU32); meshDesc.triangles.data = &(indices[0]); PxVec3 g( gravity[0], gravity[1], gravity[2] ); #if USE_PHYSX_33 return PxClothFabricCreate( *SDK_OBJ, meshDesc, g ); #else MemoryOutputStream writeBuffer; if ( !SDK_COOK->cookClothFabric(meshDesc, g, writeBuffer) ) return NULL; MemoryInputData readData( writeBuffer.getData(), writeBuffer.getSize() ); return SDK_OBJ->createClothFabric(readData); #endif }
PxConvexMesh* createConvexMesh( osg::Node& node, PxConvexFlags flags ) { GeometryDataCollector collector; node.accept( collector ); std::vector<PxVec3> verts; for ( unsigned int i=0; i<collector.vertices.size(); ++i ) { const osg::Vec3& v = collector.vertices[i]; verts.push_back( PxVec3(v[0], v[1], v[2]) ); } std::vector<PxU32> indices; for ( unsigned int i=0; i<collector.faces.size(); ++i ) { const GeometryDataCollector::GeometryFace& f = collector.faces[i]; indices.push_back( f.indices[0] ); indices.push_back( f.indices[1] ); indices.push_back( f.indices[2] ); } if ( !verts.size() || !indices.size() ) return NULL; PxConvexMeshDesc convexDesc; convexDesc.points.count = verts.size(); convexDesc.points.stride = sizeof(PxVec3); convexDesc.points.data = &(verts[0]); convexDesc.triangles.count = indices.size() / 3; convexDesc.triangles.stride = 3 * sizeof(PxU32); convexDesc.triangles.data = &(indices[0]); convexDesc.flags = flags; MemoryOutputStream writeBuffer; if ( !SDK_COOK->cookConvexMesh(convexDesc, writeBuffer) ) return NULL; MemoryInputData readBuffer( writeBuffer.getData(), writeBuffer.getSize() ); return SDK_OBJ->createConvexMesh( readBuffer ); }