diff --git a/examples/ReducedDeformableDemo/BasicTest.cpp b/examples/ReducedDeformableDemo/BasicTest.cpp index fcdad9930..d6b3b21cb 100644 --- a/examples/ReducedDeformableDemo/BasicTest.cpp +++ b/examples/ReducedDeformableDemo/BasicTest.cpp @@ -210,12 +210,7 @@ void BasicTest::initPhysics() // create volumetric reduced deformable body { - std::string filepath("../../../examples/SoftDemo/beam/"); - std::string filename = filepath + "mesh.vtk"; - btReducedSoftBody* rsb = btReducedSoftBodyHelpers::createFromVtkFile(getDeformableDynamicsWorld()->getWorldInfo(), filename.c_str()); - - rsb->setReducedModes(start_mode, num_modes, rsb->m_nodes.size()); - btReducedSoftBodyHelpers::readReducedDeformableInfoFromFiles(rsb, filepath.c_str()); + btReducedSoftBody* rsb = btReducedSoftBodyHelpers::createReducedBeam(getDeformableDynamicsWorld()->getWorldInfo(), start_mode, num_modes); getDeformableDynamicsWorld()->addSoftBody(rsb); rsb->getCollisionShape()->setMargin(0.1); @@ -246,10 +241,6 @@ void BasicTest::initPhysics() // rsb->setVelocity(btVector3(0, -COLLIDING_VELOCITY, 0)); // rsb->setRigidVelocity(btVector3(0, 1, 0)); // rsb->setRigidAngularVelocity(btVector3(1, 0, 0)); - - // btDeformableGravityForce* gravity_force = new btDeformableGravityForce(gravity); - // getDeformableDynamicsWorld()->addForce(rsb, gravity_force); - // m_forces.push_back(gravity_force); } getDeformableDynamicsWorld()->setImplicit(false); getDeformableDynamicsWorld()->setLineSearch(false); diff --git a/examples/ReducedDeformableDemo/FreeFall.cpp b/examples/ReducedDeformableDemo/FreeFall.cpp index ee6ae089a..54c810ae7 100644 --- a/examples/ReducedDeformableDemo/FreeFall.cpp +++ b/examples/ReducedDeformableDemo/FreeFall.cpp @@ -145,32 +145,19 @@ void FreeFall::initPhysics() // create volumetric reduced deformable body { - std::string filepath("../../../examples/SoftDemo/beam/"); - std::string filename = filepath + "mesh.vtk"; - btReducedSoftBody* rsb = btReducedSoftBodyHelpers::createFromVtkFile(getDeformableDynamicsWorld()->getWorldInfo(), filename.c_str()); - - rsb->setReducedModes(start_mode, num_modes, rsb->m_nodes.size()); - btReducedSoftBodyHelpers::readReducedDeformableInfoFromFiles(rsb, filepath.c_str()); + btReducedSoftBody* rsb = btReducedSoftBodyHelpers::createReducedBeam(getDeformableDynamicsWorld()->getWorldInfo(), start_mode, num_modes); getDeformableDynamicsWorld()->addSoftBody(rsb); rsb->getCollisionShape()->setMargin(0.01); btTransform init_transform; init_transform.setIdentity(); - // init_transform.setOrigin(btVector3(0, 2.5, 0)); init_transform.setOrigin(btVector3(0, 10, 0)); - // init_transform.setRotation(btQuaternion(0, SIMD_PI / 2.0, SIMD_PI / 2.0)); - // init_transform.setRotation(btQuaternion(btVector3(1, 0, 0), SIMD_PI / 6.0)); init_transform.setRotation(btQuaternion(btVector3(1, 0, 0), SIMD_PI / 2.0)); rsb->transform(init_transform); - // rsb->setTotalMass(0.5); rsb->setStiffnessScale(50); rsb->setDamping(damping_alpha, damping_beta); - // rsb->setFriction(200); - - // no fixed nodes - // rsb->setFixedNodes(0); rsb->m_cfg.kKHR = 1; // collision hardness with kinematic objects rsb->m_cfg.kCHR = 1; // collision hardness with rigid body @@ -183,10 +170,6 @@ void FreeFall::initPhysics() // rsb->setVelocity(btVector3(0, -COLLIDING_VELOCITY, 0)); // rsb->setRigidVelocity(btVector3(0, 0, 1)); // rsb->setRigidAngularVelocity(btVector3(1, 0, 0)); - - // btDeformableGravityForce* gravity_force = new btDeformableGravityForce(gravity); - // getDeformableDynamicsWorld()->addForce(rsb, gravity_force); - // m_forces.push_back(gravity_force); } // create a static rigid box as the ground { diff --git a/examples/ReducedDeformableDemo/FrictionSlope.cpp b/examples/ReducedDeformableDemo/FrictionSlope.cpp index 4bae378fc..81de87b94 100644 --- a/examples/ReducedDeformableDemo/FrictionSlope.cpp +++ b/examples/ReducedDeformableDemo/FrictionSlope.cpp @@ -188,12 +188,7 @@ void FrictionSlope::initPhysics() // create volumetric reduced deformable body { - std::string filepath("../../../examples/SoftDemo/beam/"); - std::string filename = filepath + "mesh.vtk"; - btReducedSoftBody* rsb = btReducedSoftBodyHelpers::createFromVtkFile(getDeformableDynamicsWorld()->getWorldInfo(), filename.c_str()); - - rsb->setReducedModes(start_mode, num_modes, rsb->m_nodes.size()); - btReducedSoftBodyHelpers::readReducedDeformableInfoFromFiles(rsb, filepath.c_str()); + btReducedSoftBody* rsb = btReducedSoftBodyHelpers::createReducedBeam(getDeformableDynamicsWorld()->getWorldInfo(), start_mode, num_modes); getDeformableDynamicsWorld()->addSoftBody(rsb); rsb->getCollisionShape()->setMargin(0.1); diff --git a/examples/ReducedDeformableDemo/ModeVisualizer.cpp b/examples/ReducedDeformableDemo/ModeVisualizer.cpp index 18ff2aa3c..b854ddd8b 100644 --- a/examples/ReducedDeformableDemo/ModeVisualizer.cpp +++ b/examples/ReducedDeformableDemo/ModeVisualizer.cpp @@ -119,12 +119,7 @@ void ModeVisualizer::initPhysics() // create volumetric soft body { - std::string filepath("../../../examples/SoftDemo/beam/"); - std::string filename = filepath + "mesh.vtk"; - btReducedSoftBody* rsb = btReducedSoftBodyHelpers::createFromVtkFile(getDeformableDynamicsWorld()->getWorldInfo(), filename.c_str()); - - rsb->setReducedModes(start_mode, num_modes, rsb->m_nodes.size()); - btReducedSoftBodyHelpers::readReducedDeformableInfoFromFiles(rsb, filepath.c_str()); + btReducedSoftBody* rsb = btReducedSoftBodyHelpers::createReducedBeam(getDeformableDynamicsWorld()->getWorldInfo(), start_mode, num_modes); getDeformableDynamicsWorld()->addSoftBody(rsb); rsb->getCollisionShape()->setMargin(0.1); diff --git a/examples/ReducedDeformableDemo/ReducedCollide.cpp b/examples/ReducedDeformableDemo/ReducedCollide.cpp index da8629c67..d053be92b 100644 --- a/examples/ReducedDeformableDemo/ReducedCollide.cpp +++ b/examples/ReducedDeformableDemo/ReducedCollide.cpp @@ -30,7 +30,7 @@ // static btScalar E = 50; // static btScalar nu = 0.3; static btScalar damping_alpha = 0.0; -static btScalar damping_beta = 0.0; +static btScalar damping_beta = 0.0001; static btScalar COLLIDING_VELOCITY = 4; static int start_mode = 6; static int num_modes = 20; @@ -56,10 +56,10 @@ public: void resetCamera() { - float dist = 15; - float pitch = -10; + float dist = 5; + float pitch = -5; float yaw = 90; - float targetPos[3] = {0, 3, 0}; + float targetPos[3] = {0, 0, 0}; m_guiHelper->resetCamera(dist, yaw, pitch, targetPos[0], targetPos[1], targetPos[2]); } @@ -86,28 +86,13 @@ public: { CommonDeformableBodyBase::renderScene(); btDeformableMultiBodyDynamicsWorld* deformableWorld = getDeformableDynamicsWorld(); - // int flag = 0; for (int i = 0; i < deformableWorld->getSoftBodyArray().size(); i++) { btReducedSoftBody* rsb = static_cast(deformableWorld->getSoftBodyArray()[i]); { btSoftBodyHelpers::DrawFrame(rsb, deformableWorld->getDebugDrawer()); - // btSoftBodyHelpers::Draw(rsb, deformableWorld->getDebugDrawer(), flag); btSoftBodyHelpers::Draw(rsb, deformableWorld->getDebugDrawer(), deformableWorld->getDrawFlags()); - - for (int p = 0; p < rsb->m_fixedNodes.size(); ++p) - { - deformableWorld->getDebugDrawer()->drawSphere(rsb->m_nodes[rsb->m_fixedNodes[p]].m_x, 0.2, btVector3(1, 0, 0)); - } - for (int p = 0; p < rsb->m_nodeRigidContacts.size(); ++p) - { - deformableWorld->getDebugDrawer()->drawSphere(rsb->m_nodes[rsb->m_contactNodesList[p]].m_x, 0.2, btVector3(0, 1, 0)); - } - - deformableWorld->getDebugDrawer()->drawSphere(btVector3(0, 0, 0), 0.1, btVector3(1, 1, 1)); - deformableWorld->getDebugDrawer()->drawSphere(btVector3(0, 5, 0), 0.1, btVector3(1, 1, 1)); - deformableWorld->getDebugDrawer()->drawSphere(btVector3(0, 10, 0), 0.1, btVector3(1, 1, 1)); } } } @@ -138,12 +123,7 @@ void ReducedCollide::initPhysics() // create volumetric reduced deformable body { - std::string filepath("../../../examples/SoftDemo/cube/"); - std::string filename = filepath + "mesh.vtk"; - btReducedSoftBody* rsb = btReducedSoftBodyHelpers::createFromVtkFile(getDeformableDynamicsWorld()->getWorldInfo(), filename.c_str()); - - rsb->setReducedModes(start_mode, num_modes, rsb->m_nodes.size()); - btReducedSoftBodyHelpers::readReducedDeformableInfoFromFiles(rsb, filepath.c_str()); + btReducedSoftBody* rsb = btReducedSoftBodyHelpers::createReducedCube(getDeformableDynamicsWorld()->getWorldInfo(), start_mode, num_modes); getDeformableDynamicsWorld()->addSoftBody(rsb); rsb->getCollisionShape()->setMargin(0.01); @@ -153,7 +133,7 @@ void ReducedCollide::initPhysics() init_transform.setOrigin(btVector3(0, 2, 0)); rsb->transform(init_transform); - rsb->setStiffnessScale(50); + rsb->setStiffnessScale(25); rsb->setDamping(damping_alpha, damping_beta); rsb->m_cfg.kKHR = 1; // collision hardness with kinematic objects @@ -166,19 +146,15 @@ void ReducedCollide::initPhysics() rsb->setRigidVelocity(btVector3(0, -COLLIDING_VELOCITY, 0)); // rsb->setRigidAngularVelocity(btVector3(1, 0, 0)); - - // btDeformableGravityForce* gravity_force = new btDeformableGravityForce(gravity); - // getDeformableDynamicsWorld()->addForce(rsb, gravity_force); - // m_forces.push_back(gravity_force); } getDeformableDynamicsWorld()->setImplicit(false); getDeformableDynamicsWorld()->setLineSearch(false); - getDeformableDynamicsWorld()->setUseProjection(true); - getDeformableDynamicsWorld()->getSolverInfo().m_deformable_erp = 0.3; + getDeformableDynamicsWorld()->setUseProjection(false); + getDeformableDynamicsWorld()->getSolverInfo().m_deformable_erp = 0.2; getDeformableDynamicsWorld()->getSolverInfo().m_deformable_maxErrorReduction = btScalar(200); getDeformableDynamicsWorld()->getSolverInfo().m_leastSquaresResidualThreshold = 1e-3; - getDeformableDynamicsWorld()->getSolverInfo().m_splitImpulse = true; + getDeformableDynamicsWorld()->getSolverInfo().m_splitImpulse = false; getDeformableDynamicsWorld()->getSolverInfo().m_numIterations = 100; // add a few rigid bodies Ctor_RbUpStack(); diff --git a/examples/ReducedDeformableDemo/ReducedGrasp.cpp b/examples/ReducedDeformableDemo/ReducedGrasp.cpp index 39780f835..50b34a6dc 100644 --- a/examples/ReducedDeformableDemo/ReducedGrasp.cpp +++ b/examples/ReducedDeformableDemo/ReducedGrasp.cpp @@ -274,12 +274,7 @@ void ReducedGrasp::initPhysics() // create volumetric reduced deformable body { - std::string filepath("../../../examples/SoftDemo/beam/"); - std::string filename = filepath + "mesh.vtk"; - btReducedSoftBody* rsb = btReducedSoftBodyHelpers::createFromVtkFile(getDeformableDynamicsWorld()->getWorldInfo(), filename.c_str()); - - rsb->setReducedModes(start_mode, num_modes, rsb->m_nodes.size()); - btReducedSoftBodyHelpers::readReducedDeformableInfoFromFiles(rsb, filepath.c_str()); + btReducedSoftBody* rsb = btReducedSoftBodyHelpers::createReducedBeam(getDeformableDynamicsWorld()->getWorldInfo(), start_mode, num_modes); getDeformableDynamicsWorld()->addSoftBody(rsb); rsb->getCollisionShape()->setMargin(0.015); @@ -304,10 +299,6 @@ void ReducedGrasp::initPhysics() // rsb->setRigidVelocity(btVector3(0, -COLLIDING_VELOCITY, 0)); // rsb->setRigidAngularVelocity(btVector3(1, 0, 0)); - - // btDeformableGravityForce* gravity_force = new btDeformableGravityForce(gravity); - // getDeformableDynamicsWorld()->addForce(rsb, gravity_force); - // m_forces.push_back(gravity_force); } getDeformableDynamicsWorld()->setImplicit(false); diff --git a/examples/ReducedDeformableDemo/ReducedMotorGrasp.cpp b/examples/ReducedDeformableDemo/ReducedMotorGrasp.cpp index f7597d6a9..1621a2127 100644 --- a/examples/ReducedDeformableDemo/ReducedMotorGrasp.cpp +++ b/examples/ReducedDeformableDemo/ReducedMotorGrasp.cpp @@ -304,12 +304,7 @@ void ReducedMotorGrasp::initPhysics() // create volumetric reduced deformable body { - std::string filepath("../../../examples/SoftDemo/beam/"); - std::string filename = filepath + "mesh.vtk"; - btReducedSoftBody* rsb = btReducedSoftBodyHelpers::createFromVtkFile(getDeformableDynamicsWorld()->getWorldInfo(), filename.c_str()); - - rsb->setReducedModes(start_mode, num_modes, rsb->m_nodes.size()); - btReducedSoftBodyHelpers::readReducedDeformableInfoFromFiles(rsb, filepath.c_str()); + btReducedSoftBody* rsb = btReducedSoftBodyHelpers::createReducedBeam(getDeformableDynamicsWorld()->getWorldInfo(), start_mode, num_modes); getDeformableDynamicsWorld()->addSoftBody(rsb); rsb->getCollisionShape()->setMargin(0.1); diff --git a/src/BulletSoftBody/BulletReducedSoftBody/btReducedSoftBodyHelpers.cpp b/src/BulletSoftBody/BulletReducedSoftBody/btReducedSoftBodyHelpers.cpp index 6652de989..9d2ba9510 100644 --- a/src/BulletSoftBody/BulletReducedSoftBody/btReducedSoftBodyHelpers.cpp +++ b/src/BulletSoftBody/BulletReducedSoftBody/btReducedSoftBodyHelpers.cpp @@ -4,6 +4,32 @@ #include #include +btReducedSoftBody* btReducedSoftBodyHelpers::createReducedBeam(btSoftBodyWorldInfo& worldInfo, const int start_mode, const int num_modes) +{ + std::string filepath("../../../examples/SoftDemo/beam/"); + std::string filename = filepath + "mesh.vtk"; + btReducedSoftBody* rsb = btReducedSoftBodyHelpers::createFromVtkFile(worldInfo, filename.c_str()); + + rsb->setReducedModes(start_mode, num_modes, rsb->m_nodes.size()); + btVector3 half_extents(0.5, 0.25, 2); + btReducedSoftBodyHelpers::readReducedDeformableInfoFromFiles(rsb, filepath.c_str(), half_extents); + + return rsb; +} + +btReducedSoftBody* btReducedSoftBodyHelpers::createReducedCube(btSoftBodyWorldInfo& worldInfo, const int start_mode, const int num_modes) +{ + std::string filepath("../../../examples/SoftDemo/cube/"); + std::string filename = filepath + "mesh.vtk"; + btReducedSoftBody* rsb = btReducedSoftBodyHelpers::createFromVtkFile(worldInfo, filename.c_str()); + + rsb->setReducedModes(start_mode, num_modes, rsb->m_nodes.size()); + btVector3 half_extents(0.5, 0.5, 0.5); + btReducedSoftBodyHelpers::readReducedDeformableInfoFromFiles(rsb, filepath.c_str(), half_extents); + + return rsb; +} + btReducedSoftBody* btReducedSoftBodyHelpers::createFromVtkFile(btSoftBodyWorldInfo& worldInfo, const char* vtk_file) { std::ifstream fs; @@ -112,7 +138,7 @@ btReducedSoftBody* btReducedSoftBodyHelpers::createFromVtkFile(btSoftBodyWorldIn return rsb; } -void btReducedSoftBodyHelpers::readReducedDeformableInfoFromFiles(btReducedSoftBody* rsb, const char* file_path) +void btReducedSoftBodyHelpers::readReducedDeformableInfoFromFiles(btReducedSoftBody* rsb, const char* file_path, const btVector3& half_extents) { // read in eigenmodes, stiffness and mass matrices std::string eigenvalues_file = std::string(file_path) + "eigenvalues.bin"; @@ -135,7 +161,8 @@ void btReducedSoftBodyHelpers::readReducedDeformableInfoFromFiles(btReducedSoftB // calculate the inertia tensor in the local frame btVector3 inertia(0, 0, 0); - calculateLocalInertia(inertia, rsb->getTotalMass(), btVector3(0.5, 0.25, 2), btVector3(0, 0, 0)); + calculateLocalInertia(inertia, rsb->getTotalMass(), half_extents, btVector3(0, 0, 0)); + // calculateLocalInertia(inertia, rsb->getTotalMass(), btVector3(0.5, 0.25, 2), btVector3(0, 0, 0)); // calculateLocalInertia(inertia, rsb->getTotalMass(), btVector3(0.5, 0.5, 0.5), btVector3(0, 0, 0)); rsb->setInertiaProps(inertia); diff --git a/src/BulletSoftBody/BulletReducedSoftBody/btReducedSoftBodyHelpers.h b/src/BulletSoftBody/BulletReducedSoftBody/btReducedSoftBodyHelpers.h index 38519e205..eab51809a 100644 --- a/src/BulletSoftBody/BulletReducedSoftBody/btReducedSoftBodyHelpers.h +++ b/src/BulletSoftBody/BulletReducedSoftBody/btReducedSoftBodyHelpers.h @@ -5,10 +5,15 @@ struct btReducedSoftBodyHelpers { + // create a beam + static btReducedSoftBody* createReducedBeam(btSoftBodyWorldInfo& worldInfo, const int start_mode, const int num_modes); + // create a cube + static btReducedSoftBody* createReducedCube(btSoftBodyWorldInfo& worldInfo, const int start_mode, const int num_modes); + // read in geometry info from Vtk file static btReducedSoftBody* createFromVtkFile(btSoftBodyWorldInfo& worldInfo, const char* vtk_file); // read in all reduced files - static void readReducedDeformableInfoFromFiles(btReducedSoftBody* rsb, const char* file_path); + static void readReducedDeformableInfoFromFiles(btReducedSoftBody* rsb, const char* file_path, const btVector3& half_extents); // read in a binary vector static void readBinary(btReducedSoftBody::tDenseArray& vec, const unsigned int n_start, const unsigned int n_modes, const unsigned int n_full, const char* file); // read in a binary matrix