From 7630bf62d56efe6119d834ab006da8253426c68f Mon Sep 17 00:00:00 2001 From: yunfeibai Date: Tue, 18 Oct 2016 17:38:43 -0700 Subject: [PATCH] Add USE_SOFT_BODY_MULTI_BODY_DYNAMICS_WORLD option. --- CMakeLists.txt | 5 +++ .../PhysicsServerCommandProcessor.cpp | 32 +++++++++++++++---- test/SharedMemory/CMakeLists.txt | 5 ++- 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 41a4ba98d..acc474da3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,6 +27,7 @@ SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_DEBUG") OPTION(USE_DOUBLE_PRECISION "Use double precision" OFF) OPTION(USE_GRAPHICAL_BENCHMARK "Use Graphical Benchmark" ON) OPTION(BUILD_SHARED_LIBS "Use shared libraries" OFF) +OPTION(USE_SOFT_BODY_MULTI_BODY_DYNAMICS_WORLD "Use btSoftMultiBodyDynamicsWorld" OFF) OPTION(USE_MSVC_INCREMENTAL_LINKING "Use MSVC Incremental Linking" OFF) OPTION(USE_CUSTOM_VECTOR_MATH "Use custom vectormath library" OFF) @@ -146,6 +147,10 @@ ADD_DEFINITIONS( -DBT_USE_DOUBLE_PRECISION) SET( BULLET_DOUBLE_DEF "-DBT_USE_DOUBLE_PRECISION") ENDIF (USE_DOUBLE_PRECISION) +IF (USE_SOFT_BODY_MULTI_BODY_DYNAMICS_WORLD) +ADD_DEFINITIONS(-DUSE_SOFT_BODY_MULTI_BODY_DYNAMICS_WORLD) +ENDIF (USE_SOFT_BODY_MULTI_BODY_DYNAMICS_WORLD) + IF(USE_GRAPHICAL_BENCHMARK) ADD_DEFINITIONS( -DUSE_GRAPHICAL_BENCHMARK) ENDIF (USE_GRAPHICAL_BENCHMARK) diff --git a/examples/SharedMemory/PhysicsServerCommandProcessor.cpp b/examples/SharedMemory/PhysicsServerCommandProcessor.cpp index a46613c59..4c86279ac 100644 --- a/examples/SharedMemory/PhysicsServerCommandProcessor.cpp +++ b/examples/SharedMemory/PhysicsServerCommandProcessor.cpp @@ -25,11 +25,16 @@ #include "Bullet3Common/b3Logging.h" #include "../CommonInterfaces/CommonGUIHelperInterface.h" #include "SharedMemoryCommands.h" + +#ifdef USE_SOFT_BODY_MULTI_BODY_DYNAMICS_WORLD #include "BulletSoftBody/btSoftBodyRigidBodyCollisionConfiguration.h" #include "BulletSoftBody/btSoftBodySolvers.h" #include "BulletSoftBody/btSoftBodyHelpers.h" #include "BulletSoftBody/btSoftMultiBodyDynamicsWorld.h" #include "../SoftDemo/BunnyMesh.h" +#else +#include "BulletDynamics/Featherstone/btMultiBodyDynamicsWorld.h" +#endif //@todo(erwincoumans) those globals are hacks for a VR demo, move this to Python/pybullet! @@ -434,12 +439,18 @@ struct PhysicsServerCommandProcessorInternalData btBroadphaseInterface* m_broadphase; btCollisionDispatcher* m_dispatcher; btMultiBodyConstraintSolver* m_solver; - btSoftBodySolver* m_softbodySolver; btDefaultCollisionConfiguration* m_collisionConfiguration; + +#ifdef USE_SOFT_BODY_MULTI_BODY_DYNAMICS_WORLD btSoftMultiBodyDynamicsWorld* m_dynamicsWorld; - SharedMemoryDebugDrawer* m_remoteDebugDrawer; + btSoftBodySolver* m_softbodySolver; btSoftBodyWorldInfo m_softBodyWorldInfo; - +#else + btMultiBodyDynamicsWorld* m_dynamicsWorld; +#endif + + SharedMemoryDebugDrawer* m_remoteDebugDrawer; + btAlignedObjectArray m_cachedContactPoints; btAlignedObjectArray m_sdfRecentLoadedBodies; @@ -615,9 +626,12 @@ PhysicsServerCommandProcessor::~PhysicsServerCommandProcessor() void PhysicsServerCommandProcessor::createEmptyDynamicsWorld() { ///collision configuration contains default setup for memory, collision setup - //m_data->m_collisionConfiguration = new btDefaultCollisionConfiguration(); //m_collisionConfiguration->setConvexConvexMultipointIterations(); +#ifdef USE_SOFT_BODY_MULTI_BODY_DYNAMICS_WORLD m_data->m_collisionConfiguration = new btSoftBodyRigidBodyCollisionConfiguration(); +#else + m_data->m_collisionConfiguration = new btDefaultCollisionConfiguration(); +#endif ///use the default collision dispatcher. For parallel processing you can use a diffent dispatcher (see Extras/BulletMultiThreaded) m_data->m_dispatcher = new btCollisionDispatcher(m_data->m_collisionConfiguration); @@ -625,7 +639,11 @@ void PhysicsServerCommandProcessor::createEmptyDynamicsWorld() m_data->m_solver = new btMultiBodyConstraintSolver; +#ifdef USE_SOFT_BODY_MULTI_BODY_DYNAMICS_WORLD m_data->m_dynamicsWorld = new btSoftMultiBodyDynamicsWorld(m_data->m_dispatcher, m_data->m_broadphase, m_data->m_solver, m_data->m_collisionConfiguration); +#else + m_data->m_dynamicsWorld = new btMultiBodyDynamicsWorld(m_data->m_dispatcher, m_data->m_broadphase, m_data->m_solver, m_data->m_collisionConfiguration); +#endif //Workaround: in a VR application, where we avoid synchronizaing between GFX/Physics threads, we don't want to resize this array, so pre-allocate it m_data->m_dynamicsWorld->getCollisionObjectArray().reserve(8192); @@ -1609,6 +1627,7 @@ bool PhysicsServerCommandProcessor::processCommand(const struct SharedMemoryComm } case CMD_LOAD_BUNNY: { +#ifdef USE_SOFT_BODY_MULTI_BODY_DYNAMICS_WORLD m_data->m_softBodyWorldInfo.air_density = (btScalar)1.2; m_data->m_softBodyWorldInfo.water_density = 0; m_data->m_softBodyWorldInfo.water_offset = 0; @@ -1633,7 +1652,7 @@ bool PhysicsServerCommandProcessor::processCommand(const struct SharedMemoryComm psb->getCollisionShape()->setMargin(0.01); m_data->m_dynamicsWorld->addSoftBody(psb); - +#endif break; } case CMD_CREATE_SENSOR: @@ -2979,7 +2998,7 @@ void PhysicsServerCommandProcessor::renderScene() m_data->m_guiHelper->syncPhysicsToGraphics(m_data->m_dynamicsWorld); m_data->m_guiHelper->render(m_data->m_dynamicsWorld); } - +#ifdef USE_SOFT_BODY_MULTI_BODY_DYNAMICS_WORLD for ( int i=0;im_dynamicsWorld->getSoftBodyArray().size();i++) { btSoftBody* psb=(btSoftBody*)m_data->m_dynamicsWorld->getSoftBodyArray()[i]; @@ -2989,6 +3008,7 @@ void PhysicsServerCommandProcessor::renderScene() btSoftBodyHelpers::Draw(psb,m_data->m_dynamicsWorld->getDebugDrawer(),m_data->m_dynamicsWorld->getDrawFlags()); } } +#endif } void PhysicsServerCommandProcessor::physicsDebugDraw(int debugDrawFlags) diff --git a/test/SharedMemory/CMakeLists.txt b/test/SharedMemory/CMakeLists.txt index 491e54186..8ece789cc 100644 --- a/test/SharedMemory/CMakeLists.txt +++ b/test/SharedMemory/CMakeLists.txt @@ -13,8 +13,11 @@ ADD_DEFINITIONS(-DPHYSICS_LOOP_BACK -DPHYSICS_SERVER_DIRECT -DENABLE_GTEST -D_VA LINK_LIBRARIES( - BulletInverseDynamicsUtils BulletInverseDynamics BulletFileLoader BulletWorldImporter Bullet3Common BulletDynamics BulletCollision LinearMath gtest BussIK BulletSoftBody + BulletInverseDynamicsUtils BulletInverseDynamics BulletFileLoader BulletWorldImporter Bullet3Common BulletDynamics BulletCollision LinearMath gtest BussIK ) +IF (USE_SOFT_BODY_MULTI_BODY_DYNAMICS_WORLD) + LINK_LIBRARIES(BulletSoftBody) +ENDIF() IF (NOT WIN32) LINK_LIBRARIES( pthread )