Add USE_SOFT_BODY_MULTI_BODY_DYNAMICS_WORLD option.

This commit is contained in:
yunfeibai
2016-10-18 17:38:43 -07:00
parent 3dc56d7e92
commit 7630bf62d5
3 changed files with 35 additions and 7 deletions

View File

@@ -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_DOUBLE_PRECISION "Use double precision" OFF)
OPTION(USE_GRAPHICAL_BENCHMARK "Use Graphical Benchmark" ON) OPTION(USE_GRAPHICAL_BENCHMARK "Use Graphical Benchmark" ON)
OPTION(BUILD_SHARED_LIBS "Use shared libraries" OFF) 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_MSVC_INCREMENTAL_LINKING "Use MSVC Incremental Linking" OFF)
OPTION(USE_CUSTOM_VECTOR_MATH "Use custom vectormath library" 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") SET( BULLET_DOUBLE_DEF "-DBT_USE_DOUBLE_PRECISION")
ENDIF (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) IF(USE_GRAPHICAL_BENCHMARK)
ADD_DEFINITIONS( -DUSE_GRAPHICAL_BENCHMARK) ADD_DEFINITIONS( -DUSE_GRAPHICAL_BENCHMARK)
ENDIF (USE_GRAPHICAL_BENCHMARK) ENDIF (USE_GRAPHICAL_BENCHMARK)

View File

@@ -25,11 +25,16 @@
#include "Bullet3Common/b3Logging.h" #include "Bullet3Common/b3Logging.h"
#include "../CommonInterfaces/CommonGUIHelperInterface.h" #include "../CommonInterfaces/CommonGUIHelperInterface.h"
#include "SharedMemoryCommands.h" #include "SharedMemoryCommands.h"
#ifdef USE_SOFT_BODY_MULTI_BODY_DYNAMICS_WORLD
#include "BulletSoftBody/btSoftBodyRigidBodyCollisionConfiguration.h" #include "BulletSoftBody/btSoftBodyRigidBodyCollisionConfiguration.h"
#include "BulletSoftBody/btSoftBodySolvers.h" #include "BulletSoftBody/btSoftBodySolvers.h"
#include "BulletSoftBody/btSoftBodyHelpers.h" #include "BulletSoftBody/btSoftBodyHelpers.h"
#include "BulletSoftBody/btSoftMultiBodyDynamicsWorld.h" #include "BulletSoftBody/btSoftMultiBodyDynamicsWorld.h"
#include "../SoftDemo/BunnyMesh.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! //@todo(erwincoumans) those globals are hacks for a VR demo, move this to Python/pybullet!
@@ -434,11 +439,17 @@ struct PhysicsServerCommandProcessorInternalData
btBroadphaseInterface* m_broadphase; btBroadphaseInterface* m_broadphase;
btCollisionDispatcher* m_dispatcher; btCollisionDispatcher* m_dispatcher;
btMultiBodyConstraintSolver* m_solver; btMultiBodyConstraintSolver* m_solver;
btSoftBodySolver* m_softbodySolver;
btDefaultCollisionConfiguration* m_collisionConfiguration; btDefaultCollisionConfiguration* m_collisionConfiguration;
#ifdef USE_SOFT_BODY_MULTI_BODY_DYNAMICS_WORLD
btSoftMultiBodyDynamicsWorld* m_dynamicsWorld; btSoftMultiBodyDynamicsWorld* m_dynamicsWorld;
SharedMemoryDebugDrawer* m_remoteDebugDrawer; btSoftBodySolver* m_softbodySolver;
btSoftBodyWorldInfo m_softBodyWorldInfo; btSoftBodyWorldInfo m_softBodyWorldInfo;
#else
btMultiBodyDynamicsWorld* m_dynamicsWorld;
#endif
SharedMemoryDebugDrawer* m_remoteDebugDrawer;
btAlignedObjectArray<b3ContactPointData> m_cachedContactPoints; btAlignedObjectArray<b3ContactPointData> m_cachedContactPoints;
@@ -615,9 +626,12 @@ PhysicsServerCommandProcessor::~PhysicsServerCommandProcessor()
void PhysicsServerCommandProcessor::createEmptyDynamicsWorld() void PhysicsServerCommandProcessor::createEmptyDynamicsWorld()
{ {
///collision configuration contains default setup for memory, collision setup ///collision configuration contains default setup for memory, collision setup
//m_data->m_collisionConfiguration = new btDefaultCollisionConfiguration();
//m_collisionConfiguration->setConvexConvexMultipointIterations(); //m_collisionConfiguration->setConvexConvexMultipointIterations();
#ifdef USE_SOFT_BODY_MULTI_BODY_DYNAMICS_WORLD
m_data->m_collisionConfiguration = new btSoftBodyRigidBodyCollisionConfiguration(); 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) ///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); m_data->m_dispatcher = new btCollisionDispatcher(m_data->m_collisionConfiguration);
@@ -625,7 +639,11 @@ void PhysicsServerCommandProcessor::createEmptyDynamicsWorld()
m_data->m_solver = new btMultiBodyConstraintSolver; 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); 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 //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); m_data->m_dynamicsWorld->getCollisionObjectArray().reserve(8192);
@@ -1609,6 +1627,7 @@ bool PhysicsServerCommandProcessor::processCommand(const struct SharedMemoryComm
} }
case CMD_LOAD_BUNNY: 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.air_density = (btScalar)1.2;
m_data->m_softBodyWorldInfo.water_density = 0; m_data->m_softBodyWorldInfo.water_density = 0;
m_data->m_softBodyWorldInfo.water_offset = 0; m_data->m_softBodyWorldInfo.water_offset = 0;
@@ -1633,7 +1652,7 @@ bool PhysicsServerCommandProcessor::processCommand(const struct SharedMemoryComm
psb->getCollisionShape()->setMargin(0.01); psb->getCollisionShape()->setMargin(0.01);
m_data->m_dynamicsWorld->addSoftBody(psb); m_data->m_dynamicsWorld->addSoftBody(psb);
#endif
break; break;
} }
case CMD_CREATE_SENSOR: case CMD_CREATE_SENSOR:
@@ -2979,7 +2998,7 @@ void PhysicsServerCommandProcessor::renderScene()
m_data->m_guiHelper->syncPhysicsToGraphics(m_data->m_dynamicsWorld); m_data->m_guiHelper->syncPhysicsToGraphics(m_data->m_dynamicsWorld);
m_data->m_guiHelper->render(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;i<m_data->m_dynamicsWorld->getSoftBodyArray().size();i++) for ( int i=0;i<m_data->m_dynamicsWorld->getSoftBodyArray().size();i++)
{ {
btSoftBody* psb=(btSoftBody*)m_data->m_dynamicsWorld->getSoftBodyArray()[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()); btSoftBodyHelpers::Draw(psb,m_data->m_dynamicsWorld->getDebugDrawer(),m_data->m_dynamicsWorld->getDrawFlags());
} }
} }
#endif
} }
void PhysicsServerCommandProcessor::physicsDebugDraw(int debugDrawFlags) void PhysicsServerCommandProcessor::physicsDebugDraw(int debugDrawFlags)

View File

@@ -13,8 +13,11 @@ ADD_DEFINITIONS(-DPHYSICS_LOOP_BACK -DPHYSICS_SERVER_DIRECT -DENABLE_GTEST -D_VA
LINK_LIBRARIES( 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) IF (NOT WIN32)
LINK_LIBRARIES( pthread ) LINK_LIBRARIES( pthread )