From be7383cc035977d2fc5eee7ac4cf1a1cd47ea324 Mon Sep 17 00:00:00 2001 From: Xuchen Han Date: Thu, 19 Sep 2019 17:09:52 -0700 Subject: [PATCH] update examples to test different time stepping schemes (namely explicit, implicit and implicit with line search)/ --- examples/DeformableDemo/DeformableContact.cpp | 13 ++++--- .../DeformableDemo/DeformableMultibody.cpp | 36 +++++++++---------- examples/DeformableDemo/DeformableRigid.cpp | 2 ++ examples/DeformableDemo/Pinch.cpp | 1 + .../DeformableDemo/VolumetricDeformable.cpp | 1 + src/BulletSoftBody/btDeformableBodySolver.cpp | 2 +- 6 files changed, 29 insertions(+), 26 deletions(-) diff --git a/examples/DeformableDemo/DeformableContact.cpp b/examples/DeformableDemo/DeformableContact.cpp index 68ffd26c0..e80cda1b1 100644 --- a/examples/DeformableDemo/DeformableContact.cpp +++ b/examples/DeformableDemo/DeformableContact.cpp @@ -26,6 +26,7 @@ #include "../Utils/b3ResourcePath.h" ///The DeformableContact shows the contact between deformable objects + class DeformableContact : public CommonRigidBodyBase { btAlignedObjectArray m_forces; @@ -149,12 +150,12 @@ void DeformableContact::initPhysics() 20,20, 1 + 2 + 4 + 8, true); - psb->getCollisionShape()->setMargin(0.05); + psb->getCollisionShape()->setMargin(0.1); psb->generateBendingConstraints(2); psb->setTotalMass(1); psb->m_cfg.kKHR = 1; // collision hardness with kinematic objects psb->m_cfg.kCHR = 1; // collision hardness with rigid body - psb->m_cfg.kDF = 1; + psb->m_cfg.kDF = 0; psb->m_cfg.collisions = btSoftBody::fCollision::SDF_RD; psb->m_cfg.collisions |= btSoftBody::fCollision::VF_DD; getDeformableDynamicsWorld()->addSoftBody(psb); @@ -176,15 +177,15 @@ void DeformableContact::initPhysics() btVector3(+s, h, +s), 10,10, 0, true); - psb2->getCollisionShape()->setMargin(0.05); + psb2->getCollisionShape()->setMargin(0.1); psb2->generateBendingConstraints(2); psb2->setTotalMass(1); psb2->m_cfg.kKHR = 1; // collision hardness with kinematic objects psb2->m_cfg.kCHR = 1; // collision hardness with rigid body - psb2->m_cfg.kDF = 1; + psb2->m_cfg.kDF = .1; psb2->m_cfg.collisions = btSoftBody::fCollision::SDF_RD; psb2->m_cfg.collisions |= btSoftBody::fCollision::VF_DD; - psb->translate(btVector3(3,0,0)); + psb->translate(btVector3(3.5,0,0)); getDeformableDynamicsWorld()->addSoftBody(psb2); btDeformableMassSpringForce* mass_spring2 = new btDeformableMassSpringForce(10,1, true); @@ -195,6 +196,8 @@ void DeformableContact::initPhysics() getDeformableDynamicsWorld()->addForce(psb2, gravity_force2); m_forces.push_back(gravity_force2); } + getDeformableDynamicsWorld()->setImplicit(true); + getDeformableDynamicsWorld()->setLineSearch(false); m_guiHelper->autogenerateGraphicsObjects(m_dynamicsWorld); } diff --git a/examples/DeformableDemo/DeformableMultibody.cpp b/examples/DeformableDemo/DeformableMultibody.cpp index a4b03f430..d7f254960 100644 --- a/examples/DeformableDemo/DeformableMultibody.cpp +++ b/examples/DeformableDemo/DeformableMultibody.cpp @@ -221,7 +221,7 @@ void DeformableMultibody::initPhysics() getDeformableDynamicsWorld()->addForce(psb, gravity_force); m_forces.push_back(gravity_force); } - + getDeformableDynamicsWorld()->setImplicit(false); m_guiHelper->autogenerateGraphicsObjects(m_dynamicsWorld); } @@ -346,26 +346,23 @@ void DeformableMultibody::addColliders_testMultiDof(btMultiBody* pMultiBody, btM local_origin[0] = pMultiBody->getBasePos(); { - // float pos[4]={local_origin[0].x(),local_origin[0].y(),local_origin[0].z(),1}; + btScalar quat[4] = {-world_to_local[0].x(), -world_to_local[0].y(), -world_to_local[0].z(), world_to_local[0].w()}; - if (1) - { - btCollisionShape* box = new btBoxShape(baseHalfExtents); - btMultiBodyLinkCollider* col = new btMultiBodyLinkCollider(pMultiBody, -1); - col->setCollisionShape(box); - - btTransform tr; - tr.setIdentity(); - tr.setOrigin(local_origin[0]); - tr.setRotation(btQuaternion(quat[0], quat[1], quat[2], quat[3])); - col->setWorldTransform(tr); - - pWorld->addCollisionObject(col, 2, 1 + 2); - - col->setFriction(friction); - pMultiBody->setBaseCollider(col); - } + btCollisionShape* box = new btBoxShape(baseHalfExtents); + btMultiBodyLinkCollider* col = new btMultiBodyLinkCollider(pMultiBody, -1); + col->setCollisionShape(box); + + btTransform tr; + tr.setIdentity(); + tr.setOrigin(local_origin[0]); + tr.setRotation(btQuaternion(quat[0], quat[1], quat[2], quat[3])); + col->setWorldTransform(tr); + + pWorld->addCollisionObject(col, 2, 1 + 2); + + col->setFriction(friction); + pMultiBody->setBaseCollider(col); } for (int i = 0; i < pMultiBody->getNumLinks(); ++i) @@ -378,7 +375,6 @@ void DeformableMultibody::addColliders_testMultiDof(btMultiBody* pMultiBody, btM for (int i = 0; i < pMultiBody->getNumLinks(); ++i) { btVector3 posr = local_origin[i + 1]; - // float pos[4]={posr.x(),posr.y(),posr.z(),1}; btScalar quat[4] = {-world_to_local[i + 1].x(), -world_to_local[i + 1].y(), -world_to_local[i + 1].z(), world_to_local[i + 1].w()}; diff --git a/examples/DeformableDemo/DeformableRigid.cpp b/examples/DeformableDemo/DeformableRigid.cpp index 920cd79a6..1bd437a49 100644 --- a/examples/DeformableDemo/DeformableRigid.cpp +++ b/examples/DeformableDemo/DeformableRigid.cpp @@ -231,6 +231,8 @@ void DeformableRigid::initPhysics() // add a few rigid bodies Ctor_RbUpStack(1); } + getDeformableDynamicsWorld()->setImplicit(true); + getDeformableDynamicsWorld()->setLineSearch(false); m_guiHelper->autogenerateGraphicsObjects(m_dynamicsWorld); } diff --git a/examples/DeformableDemo/Pinch.cpp b/examples/DeformableDemo/Pinch.cpp index 0887453f5..7c966cc4d 100644 --- a/examples/DeformableDemo/Pinch.cpp +++ b/examples/DeformableDemo/Pinch.cpp @@ -329,6 +329,7 @@ void Pinch::initPhysics() // add a grippers createGrip(); } + getDeformableDynamicsWorld()->setImplicit(false); m_guiHelper->autogenerateGraphicsObjects(m_dynamicsWorld); } diff --git a/examples/DeformableDemo/VolumetricDeformable.cpp b/examples/DeformableDemo/VolumetricDeformable.cpp index 3f663562f..0c4de59b1 100644 --- a/examples/DeformableDemo/VolumetricDeformable.cpp +++ b/examples/DeformableDemo/VolumetricDeformable.cpp @@ -196,6 +196,7 @@ void VolumetricDeformable::initPhysics() //add the ground to the dynamics world m_dynamicsWorld->addRigidBody(body); } + getDeformableDynamicsWorld()->setLineSearch(false); createStaticBox(btVector3(1, 5, 5), btVector3(-5,0,0)); createStaticBox(btVector3(1, 5, 5), btVector3(5,0,0)); diff --git a/src/BulletSoftBody/btDeformableBodySolver.cpp b/src/BulletSoftBody/btDeformableBodySolver.cpp index a9de66454..0bec738dd 100644 --- a/src/BulletSoftBody/btDeformableBodySolver.cpp +++ b/src/BulletSoftBody/btDeformableBodySolver.cpp @@ -24,7 +24,7 @@ btDeformableBodySolver::btDeformableBodySolver() , m_cg(20) , m_maxNewtonIterations(3) , m_newtonTolerance(1e-4) -, m_lineSearch(false) +, m_lineSearch(true) { m_objective = new btDeformableBackwardEulerObjective(m_softBodies, m_backupVelocity); }