From 3f3175e3147d5bec302cadb8b6c7ba622e5348db Mon Sep 17 00:00:00 2001 From: Erwin Coumans Date: Mon, 28 Oct 2019 10:07:22 -0700 Subject: [PATCH 1/3] disable Extras BulletRobotics by default in cmake --- Extras/BulletRobotics/CMakeLists.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Extras/BulletRobotics/CMakeLists.txt b/Extras/BulletRobotics/CMakeLists.txt index 2fa6c4935..38e96775d 100644 --- a/Extras/BulletRobotics/CMakeLists.txt +++ b/Extras/BulletRobotics/CMakeLists.txt @@ -290,7 +290,6 @@ IF (INSTALL_EXTRA_LIBS) SET_TARGET_PROPERTIES(BulletRobotics PROPERTIES FRAMEWORK true) SET_TARGET_PROPERTIES(BulletRobotics PROPERTIES PUBLIC_HEADER "PhysicsClientC_API.h" ) ENDIF (APPLE AND BUILD_SHARED_LIBS AND FRAMEWORK) -ENDIF (INSTALL_EXTRA_LIBS) IF(NOT MSVC) CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/bullet_robotics.pc.cmake @@ -301,4 +300,6 @@ IF(NOT MSVC) DESTINATION ${PKGCONFIG_INSTALL_PREFIX} ) -ENDIF(NOT MSVC) \ No newline at end of file +ENDIF(NOT MSVC) +ENDIF (INSTALL_EXTRA_LIBS) + From 136607151ee2ea916239c62db761d49dc8969050 Mon Sep 17 00:00:00 2001 From: Erwin Coumans Date: Mon, 28 Oct 2019 12:53:59 -0700 Subject: [PATCH 2/3] use mult instead of max to combine friction properties use 0.5 friction for ground for a demo, and also a larger grid size update description of deformable algorithm disable SVD for now, has some issue with some compilers --- examples/DeformableDemo/DeformableContact.cpp | 5 +++-- src/.DS_Store | Bin 6148 -> 6148 bytes .../btDeformableMultiBodyDynamicsWorld.cpp | 17 +++++++++++------ .../btDeformableNeoHookeanForce.h | 3 ++- src/BulletSoftBody/btSoftBodyInternals.h | 8 ++++---- 5 files changed, 20 insertions(+), 13 deletions(-) diff --git a/examples/DeformableDemo/DeformableContact.cpp b/examples/DeformableDemo/DeformableContact.cpp index 2432d3e27..8712d6de8 100644 --- a/examples/DeformableDemo/DeformableContact.cpp +++ b/examples/DeformableDemo/DeformableContact.cpp @@ -105,7 +105,8 @@ void DeformableContact::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); { @@ -182,7 +183,7 @@ void DeformableContact::initPhysics() 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 = 0; + psb2->m_cfg.kDF = 0.5; psb2->m_cfg.collisions = btSoftBody::fCollision::SDF_RD; psb2->m_cfg.collisions |= btSoftBody::fCollision::VF_DD; psb->translate(btVector3(3.5,0,0)); diff --git a/src/.DS_Store b/src/.DS_Store index ee616d543128a1988ca9f9dc9bb19e1f51a11544..26f6e2211eb869f996f693d2cd16705d092c3411 100644 GIT binary patch delta 707 zcmXYv&rcIU6vy9pmmj+;(kWsQby0&vP{2lwqJk+R3Zj8%fr5l)+Z|!!cDHu6E%DMA zh+f5Nki>a(_2`?J`21%}~Z)j9hZI?cJRU1pPmV(8L zlUdJl9Wldm!mmjd63cFJJncGDIbQK+)2^M*I3mfyX~RzEZNuZkwtd@rz(vC2D_*6W z7jDiQse(zyN_oL=aUZk_{ECl@gyr8?;TY8KO}m>zEZnlEb#F&!ci*XVgTslmo5^s; z6N{!#-!OzXndJ^Q?^NVSj{Bz>7k+%&Hd5S<-?JQZwon^5?id-qPyuhcrghii=1!#4 zwy%Bv0ZpIwIleMov`lY#&Jbztn3l6NTd;(cvN>xEqgPdSB0hcSu&y(OeNt-jXqPV~ z_AZb;$90X#%uv)S+<#KjSv@m@?CCR_#_E_*Ywo~#t)#OCHWAoEmwcPT_!0POm#!(Q z(i!Wf>Z(3K?Tkfhk`!vEeu~i;EfA+Htv)L`yuxd2VyiZogkZq&pauooe$z~sDNnY)IeD}(B*)5)N=Wg)XxWhe$Qz;7 PVa3l&l}tI&x-I_)AndO% delta 73 zcmZoMXfc=|#>B)qu~2NHo+2aD#(>?7lMO^zHuJOCGETn6Zn#;2gPmn!L-S^K4t@@x b!p(vl-m_tetras[j]; btMatrix3x3 P; firstPiola(psb->m_tetraScratches[j],P); - +#if USE_SVD btMatrix3x3 U, V; btVector3 sigma; singularValueDecomposition(P, U, sigma, V); @@ -194,6 +194,7 @@ public: Sigma[1][1] = sigma[1]; Sigma[2][2] = sigma[2]; P = U * Sigma * V.transpose(); +#endif // btVector3 force_on_node0 = P * (tetra.m_Dm_inverse.transpose()*grad_N_hat_1st_col); btMatrix3x3 force_on_node123 = P * tetra.m_Dm_inverse.transpose(); btVector3 force_on_node0 = force_on_node123 * grad_N_hat_1st_col; diff --git a/src/BulletSoftBody/btSoftBodyInternals.h b/src/BulletSoftBody/btSoftBodyInternals.h index 6e20b3222..93aa1d3c0 100644 --- a/src/BulletSoftBody/btSoftBodyInternals.h +++ b/src/BulletSoftBody/btSoftBodyInternals.h @@ -1288,7 +1288,7 @@ struct btSoftColliders c.m_node = node; c.m_face = face; c.m_weights = w; - c.m_friction = btMax(psb[0]->m_cfg.kDF, psb[1]->m_cfg.kDF); + c.m_friction = btMax (psb[0]->m_cfg.kDF, psb[1]->m_cfg.kDF); c.m_cfm[0] = ma / ms * psb[0]->m_cfg.kSHR; c.m_cfm[1] = mb / ms * psb[1]->m_cfg.kSHR; psb[0]->m_scontacts.push_back(c); @@ -1346,7 +1346,7 @@ struct btSoftColliders c.m_bary = w; // todo xuchenhan@: this is assuming mass of all vertices are the same. Need to modify if mass are different for distinct vertices c.m_weights = btScalar(2)/(btScalar(1) + w.length2()) * w; - c.m_friction = btMax(psb[0]->m_cfg.kDF, psb[1]->m_cfg.kDF); + c.m_friction = psb[0]->m_cfg.kDF * psb[1]->m_cfg.kDF; // the effective inverse mass of the face as in https://graphics.stanford.edu/papers/cloth-sig02/cloth.pdf c.m_imf = c.m_bary[0]*c.m_weights[0] * n[0]->m_im + c.m_bary[1]*c.m_weights[1] * n[1]->m_im + c.m_bary[2]*c.m_weights[2] * n[2]->m_im; c.m_c0 = btScalar(1)/(ma + c.m_imf); @@ -1408,7 +1408,7 @@ struct btSoftColliders c.m_bary = w; // todo xuchenhan@: this is assuming mass of all vertices are the same. Need to modify if mass are different for distinct vertices c.m_weights = btScalar(2)/(btScalar(1) + w.length2()) * w; - c.m_friction = btMax(psb[0]->m_cfg.kDF, psb[1]->m_cfg.kDF); + c.m_friction = psb[0]->m_cfg.kDF * psb[1]->m_cfg.kDF; // the effective inverse mass of the face as in https://graphics.stanford.edu/papers/cloth-sig02/cloth.pdf c.m_imf = c.m_bary[0]*c.m_weights[0] * n[0]->m_im + c.m_bary[1]*c.m_weights[1] * n[1]->m_im + c.m_bary[2]*c.m_weights[2] * n[2]->m_im; c.m_c0 = btScalar(1)/(ma + c.m_imf); @@ -1462,7 +1462,7 @@ struct btSoftColliders c.m_bary = w; // todo xuchenhan@: this is assuming mass of all vertices are the same. Need to modify if mass are different for distinct vertices c.m_weights = btScalar(2)/(btScalar(1) + w.length2()) * w; - c.m_friction = btMax(psb[0]->m_cfg.kDF, psb[1]->m_cfg.kDF); + c.m_friction = psb[0]->m_cfg.kDF * psb[1]->m_cfg.kDF; // the effective inverse mass of the face as in https://graphics.stanford.edu/papers/cloth-sig02/cloth.pdf c.m_imf = c.m_bary[0]*c.m_weights[0] * n[0]->m_im + c.m_bary[1]*c.m_weights[1] * n[1]->m_im + c.m_bary[2]*c.m_weights[2] * n[2]->m_im; c.m_c0 = btScalar(1)/(ma + c.m_imf); From 7bffbb23511977683f4334809524d38c84487d49 Mon Sep 17 00:00:00 2001 From: Erwin Coumans Date: Tue, 29 Oct 2019 18:28:30 -0700 Subject: [PATCH 3/3] add check against FLT_EPSILON/DBL_EPSILON for sqrt and division to avoid nan. add max_iterations count in svd as safety termination condition --- src/LinearMath/btImplicitQRSVD.h | 48 ++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 11 deletions(-) diff --git a/src/LinearMath/btImplicitQRSVD.h b/src/LinearMath/btImplicitQRSVD.h index cf96d4f72..54378b8a8 100644 --- a/src/LinearMath/btImplicitQRSVD.h +++ b/src/LinearMath/btImplicitQRSVD.h @@ -150,10 +150,14 @@ public: btScalar d = a * a + b * b; c = 1; s = 0; - if (d != 0) { - btScalar t = btScalar(1.0)/btSqrt(d); - c = a * t; - s = -b * t; + if (d > SIMD_EPSILON) { + btScalar sqrtd = btSqrt(d); + if (sqrtd>SIMD_EPSILON) + { + btScalar t = btScalar(1.0)/sqrtd; + c = a * t; + s = -b * t; + } } } @@ -167,7 +171,7 @@ public: btScalar d = a * a + b * b; c = 0; s = 1; - if (d != 0) { + if (d > SIMD_EPSILON) { btScalar t = btScalar(1.0)/btSqrt(d); s = a * t; c = b * t; @@ -432,10 +436,11 @@ inline void polarDecomposition(const btMatrix2x2& A, btScalar denominator = btSqrt(a*a+b*b); R.c = (btScalar)1; R.s = (btScalar)0; - if (denominator != 0) { + if (denominator > SIMD_EPSILON) { /* No need to use a tolerance here because x(0) and x(1) always have smaller magnitude then denominator, therefore overflow never happens. + In Bullet, we use a tolerance anyway. */ R.c = a / denominator; R.s = -b / denominator; @@ -485,7 +490,10 @@ inline void singularValueDecomposition( } else { btScalar tau = 0.5 * (x - z); - btScalar w = btSqrt(tau * tau + y * y); + btScalar val = tau * tau + y * y; + if (val > SIMD_EPSILON) + { + btScalar w = btSqrt(val); // w > y > 0 btScalar t; if (tau > 0) { @@ -508,6 +516,13 @@ inline void singularValueDecomposition( btScalar s2 = sine * sine; sigma(0,0) = c2 * x - csy + s2 * z; sigma(1,1) = s2 * x + csy + c2 * z; + } else + { + cosine = 1; + sine = 0; + sigma(0,0) = x; + sigma(1,1) = z; + } } // Sorting @@ -558,9 +573,15 @@ inline btScalar wilkinsonShift(const btScalar a1, const btScalar b1, const btSca { btScalar d = (btScalar)0.5 * (a1 - a2); btScalar bs = b1 * b1; - btScalar mu = a2 - copysign(bs / (btFabs(d) + btSqrt(d * d + bs)), d); + btScalar val = d * d + bs; + if (val>SIMD_EPSILON) + { + btScalar denom = btFabs(d) + btSqrt(val); + + btScalar mu = a2 - copySign(bs / (denom), d); // T mu = a2 - bs / ( d + sign_d*sqrt (d*d + bs)); return mu; + } } /** @@ -749,15 +770,20 @@ inline int singularValueDecomposition(const btMatrix3x3& A, btScalar beta_2 = B[1][2]; btScalar gamma_1 = alpha_1 * beta_1; btScalar gamma_2 = alpha_2 * beta_2; - tol *= btMax((btScalar)0.5 * btSqrt(alpha_1 * alpha_1 + alpha_2 * alpha_2 + alpha_3 * alpha_3 + beta_1 * beta_1 + beta_2 * beta_2), (btScalar)1); - + btScalar val = alpha_1 * alpha_1 + alpha_2 * alpha_2 + alpha_3 * alpha_3 + beta_1 * beta_1 + beta_2 * beta_2; + if (val > SIMD_EPSILON) + { + tol *= btMax((btScalar)0.5 * btSqrt(val), (btScalar)1); + } /** Do implicit shift QR until A^T A is block diagonal */ + int max_count = 100; while (btFabs(beta_2) > tol && btFabs(beta_1) > tol && btFabs(alpha_1) > tol && btFabs(alpha_2) > tol - && btFabs(alpha_3) > tol) { + && btFabs(alpha_3) > tol + && count < max_count) { mu = wilkinsonShift(alpha_2 * alpha_2 + beta_1 * beta_1, gamma_2, alpha_3 * alpha_3 + beta_2 * beta_2); r.compute(alpha_1 * alpha_1 - mu, gamma_1);