diff --git a/examples/DeformableDemo/DeformableSelfCollision.cpp b/examples/DeformableDemo/DeformableSelfCollision.cpp index 7d3db4965..699289b1c 100644 --- a/examples/DeformableDemo/DeformableSelfCollision.cpp +++ b/examples/DeformableDemo/DeformableSelfCollision.cpp @@ -50,8 +50,8 @@ public: void stepSimulation(float deltaTime) { - float internalTimeStep = 1. / 480.f; - m_dynamicsWorld->stepSimulation(deltaTime, 8, internalTimeStep); + float internalTimeStep = 1. / 240.f; + m_dynamicsWorld->stepSimulation(deltaTime, 4, internalTimeStep); } void addCloth(btVector3 origin); @@ -114,12 +114,13 @@ void DeformableSelfCollision::initPhysics() btDefaultMotionState* myMotionState = new btDefaultMotionState(groundTransform); btRigidBody::btRigidBodyConstructionInfo rbInfo(mass, myMotionState, groundShape, localInertia); btRigidBody* body = new btRigidBody(rbInfo); - body->setFriction(40); + body->setFriction(4); //add the ground to the dynamics world m_dynamicsWorld->addRigidBody(body); } - addCloth(btVector3(0, -0.4, 0)); + addCloth(btVector3(0, -0.1, 0)); + addCloth(btVector3(0, 1, 0)); getDeformableDynamicsWorld()->setImplicit(false); getDeformableDynamicsWorld()->setLineSearch(false); m_guiHelper->autogenerateGraphicsObjects(m_dynamicsWorld); @@ -134,29 +135,29 @@ void DeformableSelfCollision::addCloth(btVector3 origin) btVector3(+s, h, -2*s), btVector3(-s, h, +2*s), btVector3(+s, h, +2*s), - 20,40, + 15,30, // 4,4, 0, true, 0.0); - psb->getCollisionShape()->setMargin(0.0075); - psb->generateBendingConstraints(3); + psb->getCollisionShape()->setMargin(0.02); + psb->generateBendingConstraints(2); psb->setTotalMass(.5); 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.1; - psb->rotate(btQuaternion(0, SIMD_PI / 2, 0)); + psb->rotate(btQuaternion(0, SIMD_PI / 4, 0)); btTransform clothTransform; clothTransform.setIdentity(); - clothTransform.setOrigin(btVector3(0,0.2,0)); + clothTransform.setOrigin(btVector3(0,0.2,0)+origin); psb->transform(clothTransform); 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(1.5,0.1, true); - psb->setSpringStiffness(1); + btDeformableMassSpringForce* mass_spring = new btDeformableMassSpringForce(2,0.1, true); + psb->setSpringStiffness(2); getDeformableDynamicsWorld()->addForce(psb, mass_spring); m_forces.push_back(mass_spring); btVector3 gravity = btVector3(0, -9.8, 0); diff --git a/src/BulletSoftBody/btDeformableMultiBodyDynamicsWorld.cpp b/src/BulletSoftBody/btDeformableMultiBodyDynamicsWorld.cpp index f6a49a934..93d52272b 100644 --- a/src/BulletSoftBody/btDeformableMultiBodyDynamicsWorld.cpp +++ b/src/BulletSoftBody/btDeformableMultiBodyDynamicsWorld.cpp @@ -63,7 +63,7 @@ m_deformableBodySolver(deformableBodySolver), m_solverCallback(0) m_implicit = false; m_lineSearch = false; m_selfCollision = true; - m_ccdIterations = 3; + m_ccdIterations = 5; m_solverDeformableBodyIslandCallback = new DeformableBodyInplaceSolverIslandCallback(constraintSolver, dispatcher); } diff --git a/src/BulletSoftBody/btSoftBody.cpp b/src/BulletSoftBody/btSoftBody.cpp index 5014300aa..fa779a490 100644 --- a/src/BulletSoftBody/btSoftBody.cpp +++ b/src/BulletSoftBody/btSoftBody.cpp @@ -4139,7 +4139,7 @@ void btSoftBody::defaultCollisionHandler(btSoftBody* psb) if (psb->useSelfCollision()) { btSoftColliders::CollideFF_DD docollide; - docollide.mrg = getCollisionShape()->getMargin()*2.0; + docollide.mrg = getCollisionShape()->getMargin(); docollide.psb[0] = this; docollide.psb[1] = psb; if (this->m_tetras.size() > 0) @@ -4196,7 +4196,7 @@ void btSoftBody::geometricCollisionHandler(btSoftBody* psb) if (psb->useSelfCollision()) { btSoftColliders::CollideCCD docollide; - docollide.mrg = 1e-6; + docollide.mrg = SAFE_EPSILON; docollide.psb[0] = this; docollide.psb[1] = psb; docollide.dt = psb->m_sst.sdt; diff --git a/src/BulletSoftBody/btSoftBody.h b/src/BulletSoftBody/btSoftBody.h index 770794430..b1d78b7b7 100644 --- a/src/BulletSoftBody/btSoftBody.h +++ b/src/BulletSoftBody/btSoftBody.h @@ -1173,7 +1173,7 @@ public: static psolver_t getSolver(ePSolver::_ solver); static vsolver_t getSolver(eVSolver::_ solver); void geometricCollisionHandler(btSoftBody* psb); -#define SAFE_EPSILON SIMD_EPSILON*10.0 +#define SAFE_EPSILON SIMD_EPSILON*100.0 void updateNode(btDbvtNode* node, bool use_velocity, bool margin) { if (node->isleaf()) @@ -1307,7 +1307,7 @@ public: bool face_constrained = false, node_constrained = node->m_constrained; for (int i = 0; i < 3; ++i) face_constrained |= face->m_n[i]->m_constrained; - btScalar I_tilde = 2.0*I /(1.0+w.length2()); + btScalar I_tilde = .5 *I /(1.0+w.length2()); // double the impulse if node or face is constrained. if (face_constrained || node_constrained) @@ -1331,7 +1331,7 @@ public: btScalar vt_new = btMax(btScalar(1) - mu * delta_vn / (vt_norm + SIMD_EPSILON), btScalar(0))*vt_norm; I = 0.5 * mass * (vt_norm-vt_new); vt.safeNormalize(); - I_tilde = 2.0*I /(1.0+w.length2()); + I_tilde = .5 *I /(1.0+w.length2()); // double the impulse if node or face is constrained. if (face_constrained || node_constrained) I_tilde *= 2.0;