From f7cd1edf4af9f53b078357dd758b064d1e343bbb Mon Sep 17 00:00:00 2001 From: Xuchen Han Date: Sat, 10 Aug 2019 12:00:48 -0700 Subject: [PATCH] code clean up --- examples/DeformableDemo/DeformableRigid.cpp | 2 +- examples/DeformableDemo/GraspDeformable.cpp | 4 +- .../DeformableDemo/VolumetricDeformable.cpp | 3 +- src/BulletSoftBody/btCGProjection.h | 44 ------------------- src/BulletSoftBody/btDeformableBodySolver.cpp | 5 ++- src/BulletSoftBody/btDeformableBodySolver.h | 1 + 6 files changed, 9 insertions(+), 50 deletions(-) diff --git a/examples/DeformableDemo/DeformableRigid.cpp b/examples/DeformableDemo/DeformableRigid.cpp index 9268572ef..6cc3d7b4f 100644 --- a/examples/DeformableDemo/DeformableRigid.cpp +++ b/examples/DeformableDemo/DeformableRigid.cpp @@ -232,7 +232,7 @@ void DeformableRigid::initPhysics() psb->setDampingCoefficient(0.05); psb->m_cfg.kKHR = 1; // collision hardness with kinematic objects psb->m_cfg.kCHR = 1; // collision hardness with rigid body - psb->m_cfg.kDF = 0; + psb->m_cfg.kDF = 1; psb->m_cfg.collisions = btSoftBody::fCollision::SDF_RD; getDeformableDynamicsWorld()->addSoftBody(psb); getDeformableDynamicsWorld()->addForce(psb, new btDeformableMassSpringForce()); diff --git a/examples/DeformableDemo/GraspDeformable.cpp b/examples/DeformableDemo/GraspDeformable.cpp index 15348af26..6596c07d7 100644 --- a/examples/DeformableDemo/GraspDeformable.cpp +++ b/examples/DeformableDemo/GraspDeformable.cpp @@ -331,10 +331,10 @@ void GraspDeformable::initPhysics() psb->getCollisionShape()->setMargin(0.1); psb->setTotalMass(1); psb->setSpringStiffness(0); - psb->setDampingCoefficient(0.02); + psb->setDampingCoefficient(0.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 = 0; + psb->m_cfg.kDF = 2; psb->m_cfg.collisions = btSoftBody::fCollision::SDF_RD; getDeformableDynamicsWorld()->addSoftBody(psb); getDeformableDynamicsWorld()->addForce(psb, new btDeformableMassSpringForce()); diff --git a/examples/DeformableDemo/VolumetricDeformable.cpp b/examples/DeformableDemo/VolumetricDeformable.cpp index 74d9678a8..22755856b 100644 --- a/examples/DeformableDemo/VolumetricDeformable.cpp +++ b/examples/DeformableDemo/VolumetricDeformable.cpp @@ -234,7 +234,7 @@ void VolumetricDeformable::initPhysics() psb->getCollisionShape()->setMargin(0.25); // psb->generateBendingConstraints(2); psb->setTotalMass(1); - psb->setSpringStiffness(1); + psb->setSpringStiffness(0); psb->setDampingCoefficient(0.01); psb->m_cfg.kKHR = 1; // collision hardness with kinematic objects psb->m_cfg.kCHR = 1; // collision hardness with rigid body @@ -242,6 +242,7 @@ void VolumetricDeformable::initPhysics() psb->m_cfg.collisions = btSoftBody::fCollision::SDF_RD; getDeformableDynamicsWorld()->addForce(psb, new btDeformableMassSpringForce()); getDeformableDynamicsWorld()->addForce(psb, new btDeformableGravityForce(gravity)); + getDeformableDynamicsWorld()->addForce(psb, new btDeformableCorotatedForce(.5,.5)); } // add a few rigid bodies Ctor_RbUpStack(4); diff --git a/src/BulletSoftBody/btCGProjection.h b/src/BulletSoftBody/btCGProjection.h index ef902c70d..9dc416cdd 100644 --- a/src/BulletSoftBody/btCGProjection.h +++ b/src/BulletSoftBody/btCGProjection.h @@ -53,49 +53,6 @@ struct DeformableContactConstraint } }; -struct DeformableFrictionConstraint -{ - btAlignedObjectArray m_static; // whether the friction is static - btAlignedObjectArray m_impulse; // the impulse magnitude the node feels - btAlignedObjectArray m_dv; // the dv magnitude of the node - btAlignedObjectArray m_direction; // the direction of the friction for the node - - - btAlignedObjectArray m_static_prev; - btAlignedObjectArray m_impulse_prev; - btAlignedObjectArray m_dv_prev; - btAlignedObjectArray m_direction_prev; - - btAlignedObjectArray m_released; // whether the contact is released - - - // the total impulse the node applied to the rb in the tangential direction in the cg solve - btAlignedObjectArray m_accumulated_tangent_impulse; - - DeformableFrictionConstraint() - { - append(); - } - - void append() - { - m_static.push_back(false); - m_static_prev.push_back(false); - - m_direction_prev.push_back(btVector3(0,0,0)); - m_direction.push_back(btVector3(0,0,0)); - - m_impulse.push_back(0); - m_impulse_prev.push_back(0); - - m_dv.push_back(0); - m_dv_prev.push_back(0); - - m_accumulated_tangent_impulse.push_back(btVector3(0,0,0)); - m_released.push_back(false); - } -}; - class btCGProjection { public: @@ -104,7 +61,6 @@ public: typedef btAlignedObjectArray > TArrayStack; btAlignedObjectArray& m_softBodies; btDeformableRigidDynamicsWorld* m_world; -// const btAlignedObjectArray* m_nodes; const btScalar& m_dt; btCGProjection(btAlignedObjectArray& softBodies, const btScalar& dt) diff --git a/src/BulletSoftBody/btDeformableBodySolver.cpp b/src/BulletSoftBody/btDeformableBodySolver.cpp index be0262842..8361abfe5 100644 --- a/src/BulletSoftBody/btDeformableBodySolver.cpp +++ b/src/BulletSoftBody/btDeformableBodySolver.cpp @@ -19,6 +19,7 @@ btDeformableBodySolver::btDeformableBodySolver() : m_numNodes(0) , m_cg(10) +, m_contact_iterations(10) { m_objective = new btDeformableBackwardEulerObjective(m_softBodySet, m_backupVelocity); } @@ -46,7 +47,7 @@ void btDeformableBodySolver::solveConstraints(float solverdt) void btDeformableBodySolver::computeStep(TVStack& dv, const TVStack& residual) { - btScalar tolerance = std::numeric_limits::epsilon() * m_objective->computeNorm(residual); + btScalar tolerance = std::numeric_limits::epsilon() * 1024 * m_objective->computeNorm(residual); m_cg.solve(*m_objective, dv, residual, tolerance); } @@ -76,7 +77,7 @@ void btDeformableBodySolver::setConstraints() { BT_PROFILE("setConstraint"); m_objective->setConstraints(); - for (int i = 0; i < 10; ++i) + for (int i = 0; i < m_contact_iterations; ++i) { m_objective->projection.update(); m_objective->enforceConstraint(m_dv); diff --git a/src/BulletSoftBody/btDeformableBodySolver.h b/src/BulletSoftBody/btDeformableBodySolver.h index 94102afa9..206354f52 100644 --- a/src/BulletSoftBody/btDeformableBodySolver.h +++ b/src/BulletSoftBody/btDeformableBodySolver.h @@ -37,6 +37,7 @@ protected: btAlignedObjectArray m_backupVelocity; btScalar m_dt; + btScalar m_contact_iterations; btConjugateGradient m_cg;