From 270028363bb6b4148a9277508c398b14957f370c Mon Sep 17 00:00:00 2001 From: Xuchen Han Date: Thu, 24 Oct 2019 15:03:23 -0700 Subject: [PATCH 1/2] Fix some performance issues caused by unneccessarily small sdf grid size. --- examples/DeformableDemo/DeformableMultibody.cpp | 2 ++ examples/DeformableDemo/DeformableRigid.cpp | 2 ++ examples/DeformableDemo/PinchFriction.cpp | 15 ++++++++------- examples/DeformableDemo/VolumetricDeformable.cpp | 4 +++- .../btMultiBodyInplaceSolverIslandCallback.h | 8 +++++++- 5 files changed, 22 insertions(+), 9 deletions(-) diff --git a/examples/DeformableDemo/DeformableMultibody.cpp b/examples/DeformableDemo/DeformableMultibody.cpp index 7b9137cc9..40db119b9 100644 --- a/examples/DeformableDemo/DeformableMultibody.cpp +++ b/examples/DeformableDemo/DeformableMultibody.cpp @@ -113,6 +113,8 @@ void DeformableMultibody::initPhysics() btVector3 gravity = btVector3(0, -10, 0); m_dynamicsWorld->setGravity(gravity); getDeformableDynamicsWorld()->getWorldInfo().m_gravity = gravity; + getDeformableDynamicsWorld()->getWorldInfo().m_sparsesdf.setDefaultVoxelsz(0.25); + getDeformableDynamicsWorld()->getWorldInfo().m_sparsesdf.Reset(); m_guiHelper->createPhysicsDebugDrawer(m_dynamicsWorld); { diff --git a/examples/DeformableDemo/DeformableRigid.cpp b/examples/DeformableDemo/DeformableRigid.cpp index 748f1f4c8..9a3ca9403 100644 --- a/examples/DeformableDemo/DeformableRigid.cpp +++ b/examples/DeformableDemo/DeformableRigid.cpp @@ -154,6 +154,8 @@ void DeformableRigid::initPhysics() btVector3 gravity = btVector3(0, -10, 0); m_dynamicsWorld->setGravity(gravity); getDeformableDynamicsWorld()->getWorldInfo().m_gravity = gravity; + getDeformableDynamicsWorld()->getWorldInfo().m_sparsesdf.setDefaultVoxelsz(0.25); + getDeformableDynamicsWorld()->getWorldInfo().m_sparsesdf.Reset(); // getDeformableDynamicsWorld()->before_solver_callbacks.push_back(dynamics); m_guiHelper->createPhysicsDebugDrawer(m_dynamicsWorld); diff --git a/examples/DeformableDemo/PinchFriction.cpp b/examples/DeformableDemo/PinchFriction.cpp index 1cbc7e43d..bf0d57d0b 100644 --- a/examples/DeformableDemo/PinchFriction.cpp +++ b/examples/DeformableDemo/PinchFriction.cpp @@ -112,9 +112,9 @@ void dynamics2(btScalar time, btDeformableMultiBodyDynamicsWorld* world) if (rbs.size()<2) return; btRigidBody* rb0 = rbs[0]; - btScalar pressTime = 0.9; - btScalar liftTime = 10; - btScalar shiftTime = 3.5; + btScalar pressTime = 0.45; + btScalar liftTime = 5; + btScalar shiftTime = 1.75; btScalar holdTime = 4.5*1000; btScalar dropTime = 5.3*1000; btTransform rbTransform; @@ -124,9 +124,9 @@ void dynamics2(btScalar time, btDeformableMultiBodyDynamicsWorld* world) btVector3 initialTranslationLeft = btVector3(0.5,3,4); btVector3 initialTranslationRight = btVector3(0.5,3,-4); - btVector3 PinchFrictionVelocityLeft = btVector3(0,0,-1); - btVector3 PinchFrictionVelocityRight = btVector3(0,0,1); - btVector3 liftVelocity = btVector3(0,1,0); + btVector3 PinchFrictionVelocityLeft = btVector3(0,0,-2); + btVector3 PinchFrictionVelocityRight = btVector3(0,0,2); + btVector3 liftVelocity = btVector3(0,2,0); btVector3 shiftVelocity = btVector3(0,0,0); btVector3 holdVelocity = btVector3(0,0,0); btVector3 openVelocityLeft = btVector3(0,0,4); @@ -230,7 +230,8 @@ void PinchFriction::initPhysics() btVector3 gravity = btVector3(0, -10, 0); m_dynamicsWorld->setGravity(gravity); getDeformableDynamicsWorld()->getWorldInfo().m_gravity = gravity; - + getDeformableDynamicsWorld()->getWorldInfo().m_sparsesdf.setDefaultVoxelsz(0.25); + getDeformableDynamicsWorld()->getWorldInfo().m_sparsesdf.Reset(); getDeformableDynamicsWorld()->setSolverCallback(dynamics2); m_guiHelper->createPhysicsDebugDrawer(m_dynamicsWorld); diff --git a/examples/DeformableDemo/VolumetricDeformable.cpp b/examples/DeformableDemo/VolumetricDeformable.cpp index d3a37d5bf..7eaf9aa37 100644 --- a/examples/DeformableDemo/VolumetricDeformable.cpp +++ b/examples/DeformableDemo/VolumetricDeformable.cpp @@ -169,6 +169,8 @@ void VolumetricDeformable::initPhysics() btVector3 gravity = btVector3(0, -100, 0); m_dynamicsWorld->setGravity(gravity); getDeformableDynamicsWorld()->getWorldInfo().m_gravity = gravity; + getDeformableDynamicsWorld()->getWorldInfo().m_sparsesdf.setDefaultVoxelsz(0.25); + getDeformableDynamicsWorld()->getWorldInfo().m_sparsesdf.Reset(); m_guiHelper->createPhysicsDebugDrawer(m_dynamicsWorld); { @@ -223,7 +225,7 @@ void VolumetricDeformable::initPhysics() getDeformableDynamicsWorld()->addForce(psb, gravity_force); m_forces.push_back(gravity_force); - btDeformableNeoHookeanForce* neohookean = new btDeformableNeoHookeanForce(30,100,0.02); + btDeformableNeoHookeanForce* neohookean = new btDeformableNeoHookeanForce(30,100,0.05); getDeformableDynamicsWorld()->addForce(psb, neohookean); m_forces.push_back(neohookean); diff --git a/src/BulletDynamics/Featherstone/btMultiBodyInplaceSolverIslandCallback.h b/src/BulletDynamics/Featherstone/btMultiBodyInplaceSolverIslandCallback.h index 458e62a78..593f68d9a 100644 --- a/src/BulletDynamics/Featherstone/btMultiBodyInplaceSolverIslandCallback.h +++ b/src/BulletDynamics/Featherstone/btMultiBodyInplaceSolverIslandCallback.h @@ -188,7 +188,13 @@ struct MultiBodyInplaceSolverIslandCallback : public btSimulationIslandManager:: //} else { for (i = 0; i < numBodies; i++) - m_bodies.push_back(bodies[i]); + { + bool isSoftBodyType = (bodies[i]->getInternalType() & btCollisionObject::CO_SOFT_BODY); + if (!isSoftBodyType) + { + m_bodies.push_back(bodies[i]); + } + } for (i = 0; i < numManifolds; i++) m_manifolds.push_back(manifolds[i]); for (i = 0; i < numCurConstraints; i++) From 23dbea16f3158bd1382f89407c207dc327d2dccf Mon Sep 17 00:00:00 2001 From: Xuchen Han Date: Thu, 24 Oct 2019 15:28:21 -0700 Subject: [PATCH 2/2] initialize m_useSelfCollision --- examples/DeformableDemo/ClothFriction.cpp | 2 ++ examples/DeformableDemo/DeformableSelfCollision.cpp | 1 + src/BulletSoftBody/btSoftBody.cpp | 1 + 3 files changed, 4 insertions(+) diff --git a/examples/DeformableDemo/ClothFriction.cpp b/examples/DeformableDemo/ClothFriction.cpp index ef9c8da47..e62dab0d2 100644 --- a/examples/DeformableDemo/ClothFriction.cpp +++ b/examples/DeformableDemo/ClothFriction.cpp @@ -104,6 +104,8 @@ void ClothFriction::initPhysics() btVector3 gravity = btVector3(0, -10, 0); m_dynamicsWorld->setGravity(gravity); getDeformableDynamicsWorld()->getWorldInfo().m_gravity = gravity; + getDeformableDynamicsWorld()->getWorldInfo().m_sparsesdf.setDefaultVoxelsz(0.25); + getDeformableDynamicsWorld()->getWorldInfo().m_sparsesdf.Reset(); m_guiHelper->createPhysicsDebugDrawer(m_dynamicsWorld); diff --git a/examples/DeformableDemo/DeformableSelfCollision.cpp b/examples/DeformableDemo/DeformableSelfCollision.cpp index cb4f405c2..6b1d92611 100644 --- a/examples/DeformableDemo/DeformableSelfCollision.cpp +++ b/examples/DeformableDemo/DeformableSelfCollision.cpp @@ -166,6 +166,7 @@ void DeformableSelfCollision::initPhysics() psb->m_cfg.collisions = btSoftBody::fCollision::SDF_RD; psb->m_cfg.collisions |= btSoftBody::fCollision::VF_DD; getDeformableDynamicsWorld()->addSoftBody(psb); + psb->setSelfCollision(true); btDeformableMassSpringForce* mass_spring = new btDeformableMassSpringForce(10,0.2, true); getDeformableDynamicsWorld()->addForce(psb, mass_spring); diff --git a/src/BulletSoftBody/btSoftBody.cpp b/src/BulletSoftBody/btSoftBody.cpp index c46f7a3b8..e4e8c0c41 100644 --- a/src/BulletSoftBody/btSoftBody.cpp +++ b/src/BulletSoftBody/btSoftBody.cpp @@ -119,6 +119,7 @@ void btSoftBody::initDefaults() m_dampingCoefficient = 1; m_sleepingThreshold = 0.1; m_useFaceContact = false; + m_useSelfCollision = false; m_collisionFlags = 0; }