diff --git a/examples/Importers/ImportMJCFDemo/BulletMJCFImporter.cpp b/examples/Importers/ImportMJCFDemo/BulletMJCFImporter.cpp index 07cb2696d..484391388 100644 --- a/examples/Importers/ImportMJCFDemo/BulletMJCFImporter.cpp +++ b/examples/Importers/ImportMJCFDemo/BulletMJCFImporter.cpp @@ -187,6 +187,7 @@ struct BulletMJCFImporterInternalData //those collision shapes are deleted by caller (todo: make sure this happens!) btAlignedObjectArray m_allocatedCollisionShapes; + mutable btAlignedObjectArray m_allocatedMeshInterfaces; BulletMJCFImporterInternalData() :m_activeModel(-1), @@ -1855,6 +1856,8 @@ class btCompoundShape* BulletMJCFImporter::convertLinkCollisionShapes( int linkI { btTriangleMesh* meshInterface = new btTriangleMesh(); + m_data->m_allocatedMeshInterfaces.push_back(meshInterface); + for (int i=0;im_numIndices/3;i++) { float* v0 = glmesh->m_vertices->at(glmesh->m_indices->at(i*3)).xyzw; @@ -1926,6 +1929,15 @@ class btCollisionShape* BulletMJCFImporter::getAllocatedCollisionShape(int index return m_data->m_allocatedCollisionShapes[index]; } +int BulletMJCFImporter::getNumAllocatedMeshInterfaces() const +{ + return m_data->m_allocatedMeshInterfaces.size(); +} + +btStridingMeshInterface* BulletMJCFImporter::getAllocatedMeshInterface(int index) +{ + return m_data->m_allocatedMeshInterfaces[index]; +} int BulletMJCFImporter::getNumModels() const { diff --git a/examples/Importers/ImportMJCFDemo/BulletMJCFImporter.h b/examples/Importers/ImportMJCFDemo/BulletMJCFImporter.h index 306d311ca..05e5dc2fe 100644 --- a/examples/Importers/ImportMJCFDemo/BulletMJCFImporter.h +++ b/examples/Importers/ImportMJCFDemo/BulletMJCFImporter.h @@ -78,6 +78,9 @@ public: virtual int getNumModels() const; virtual void activateModel(int modelIndex); + virtual int getNumAllocatedMeshInterfaces() const; + virtual btStridingMeshInterface* getAllocatedMeshInterface(int index); + }; diff --git a/examples/Importers/ImportURDFDemo/BulletUrdfImporter.cpp b/examples/Importers/ImportURDFDemo/BulletUrdfImporter.cpp index 6f6d1f752..a80317119 100644 --- a/examples/Importers/ImportURDFDemo/BulletUrdfImporter.cpp +++ b/examples/Importers/ImportURDFDemo/BulletUrdfImporter.cpp @@ -54,6 +54,7 @@ ATTRIBUTE_ALIGNED16(struct) BulletURDFInternalData int m_bodyId; btHashMap m_linkColors; btAlignedObjectArray m_allocatedCollisionShapes; + mutable btAlignedObjectArray m_allocatedMeshInterfaces; LinkVisualShapesConverter* m_customVisualShapesConverter; @@ -572,7 +573,7 @@ bool findExistingMeshFile( } } -btCollisionShape* convertURDFToCollisionShape(const UrdfCollision* collision, const char* urdfPathPrefix) +btCollisionShape* BulletURDFImporter::convertURDFToCollisionShape(const UrdfCollision* collision, const char* urdfPathPrefix) const { BT_PROFILE("convertURDFToCollisionShape"); @@ -775,6 +776,7 @@ upAxisMat.setIdentity(); { BT_PROFILE("convert trimesh"); btTriangleMesh* meshInterface = new btTriangleMesh(); + m_data->m_allocatedMeshInterfaces.push_back(meshInterface); { BT_PROFILE("convert vertices"); @@ -1229,6 +1231,19 @@ btCollisionShape* BulletURDFImporter::getAllocatedCollisionShape(int index) return m_data->m_allocatedCollisionShapes[index]; } +int BulletURDFImporter::getNumAllocatedMeshInterfaces() const +{ + return m_data->m_allocatedMeshInterfaces.size(); +} + + +btStridingMeshInterface* BulletURDFImporter::getAllocatedMeshInterface(int index) +{ + return m_data->m_allocatedMeshInterfaces[index]; +} + + + class btCompoundShape* BulletURDFImporter::convertLinkCollisionShapes(int linkIndex, const char* pathPrefix, const btTransform& localInertiaFrame) const { diff --git a/examples/Importers/ImportURDFDemo/BulletUrdfImporter.h b/examples/Importers/ImportURDFDemo/BulletUrdfImporter.h index c8fbf6204..5e0892fdd 100644 --- a/examples/Importers/ImportURDFDemo/BulletUrdfImporter.h +++ b/examples/Importers/ImportURDFDemo/BulletUrdfImporter.h @@ -62,6 +62,8 @@ public: virtual void convertLinkVisualShapes2(int linkIndex, int urdfIndex, const char* pathPrefix, const btTransform& inertialFrame, class btCollisionObject* colObj, int bodyUniqueId) const; + class btCollisionShape* convertURDFToCollisionShape(const struct UrdfCollision* collision, const char* urdfPathPrefix) const; + ///todo(erwincoumans) refactor this convertLinkCollisionShapes/memory allocation virtual class btCompoundShape* convertLinkCollisionShapes(int linkIndex, const char* pathPrefix, const btTransform& localInertiaFrame) const; @@ -69,7 +71,9 @@ public: virtual int getNumAllocatedCollisionShapes() const; virtual class btCollisionShape* getAllocatedCollisionShape(int index); - + virtual int getNumAllocatedMeshInterfaces() const; + virtual class btStridingMeshInterface* getAllocatedMeshInterface(int index); + }; diff --git a/examples/Importers/ImportURDFDemo/URDFImporterInterface.h b/examples/Importers/ImportURDFDemo/URDFImporterInterface.h index d6853e3b6..e1a98d0c2 100644 --- a/examples/Importers/ImportURDFDemo/URDFImporterInterface.h +++ b/examples/Importers/ImportURDFDemo/URDFImporterInterface.h @@ -80,6 +80,8 @@ public: virtual class btCollisionShape* getAllocatedCollisionShape(int /*index*/ ) {return 0;} virtual int getNumModels() const {return 0;} virtual void activateModel(int /*modelIndex*/) { } + virtual int getNumAllocatedMeshInterfaces() const { return 0;} + virtual class btStridingMeshInterface* getAllocatedMeshInterface(int index) {return 0;} }; diff --git a/examples/SharedMemory/PhysicsServerCommandProcessor.cpp b/examples/SharedMemory/PhysicsServerCommandProcessor.cpp index 9975312da..06a599339 100644 --- a/examples/SharedMemory/PhysicsServerCommandProcessor.cpp +++ b/examples/SharedMemory/PhysicsServerCommandProcessor.cpp @@ -1191,6 +1191,7 @@ struct PhysicsServerCommandProcessorInternalData btAlignedObjectArray m_strings; btAlignedObjectArray m_collisionShapes; + btAlignedObjectArray m_meshInterfaces; MyOverlapFilterCallback* m_broadphaseCollisionFilterCallback; btHashedOverlappingPairCache* m_pairCache; @@ -2027,6 +2028,11 @@ void PhysicsServerCommandProcessor::deleteDynamicsWorld() btCollisionShape* shape = m_data->m_collisionShapes[j]; delete shape; } + for (int j=0;jm_meshInterfaces.size();j++) + { + delete m_data->m_meshInterfaces[j]; + } + m_data->m_meshInterfaces.clear(); m_data->m_collisionShapes.clear(); delete m_data->m_dynamicsWorld; @@ -2232,7 +2238,12 @@ bool PhysicsServerCommandProcessor::processImportedObjects(const char* fileName, } } - + + for (int i=0;im_meshInterfaces.push_back(u2b.getAllocatedMeshInterface(i)); + } + for (int i=0;im_data->m_meshInterfaces.push_back(meshInterface); { BT_PROFILE("convert vertices"); @@ -3801,6 +3812,7 @@ bool PhysicsServerCommandProcessor::processCommand(const struct SharedMemoryComm { BT_PROFILE("create btBvhTriangleMeshShape"); btBvhTriangleMeshShape* trimesh = new btBvhTriangleMeshShape(meshInterface,true,true); + m_data->m_collisionShapes.push_back(trimesh); //trimesh->setLocalScaling(collision->m_geometry.m_meshScale); shape = trimesh; if (compound) @@ -3808,6 +3820,7 @@ bool PhysicsServerCommandProcessor::processCommand(const struct SharedMemoryComm compound->addChildShape(childTransform,shape); } } + delete glmesh; } else {