better support of initial rotation.

This commit is contained in:
jingyuc 2021-09-10 13:34:34 -04:00
parent e62c42f54c
commit 9d1aafc51c
5 changed files with 38 additions and 36 deletions

View File

@ -134,13 +134,13 @@ public:
void stepSimulation(float deltaTime)
{
// TODO: remove this. very hacky way of adding initial deformation
// btReducedSoftBody* rsb = static_cast<btReducedSoftBody*>(static_cast<btDeformableMultiBodyDynamicsWorld*>(m_dynamicsWorld)->getSoftBodyArray()[0]);
// if (first_step /* && !rsb->m_bUpdateRtCst*/)
// {
// getDeformedShape(rsb, 0, 1);
// first_step = false;
// // rsb->mapToReducedDofs();
// }
btReducedSoftBody* rsb = static_cast<btReducedSoftBody*>(static_cast<btDeformableMultiBodyDynamicsWorld*>(m_dynamicsWorld)->getSoftBodyArray()[0]);
if (first_step /* && !rsb->m_bUpdateRtCst*/)
{
getDeformedShape(rsb, 0, 1);
first_step = false;
// rsb->mapToReducedDofs();
}
float internalTimeStep = 1. / 60.f;
// float internalTimeStep = 1e-3;
@ -211,7 +211,7 @@ void BasicTest::initPhysics()
// create volumetric reduced deformable body
{
std::string filepath("../../../examples/SoftDemo/");
std::string filepath("../../../examples/SoftDemo/beam/");
std::string filename = filepath + "mesh.vtk";
btReducedSoftBody* rsb = btReducedSoftBodyHelpers::createFromVtkFile(getDeformableDynamicsWorld()->getWorldInfo(), filename.c_str());
@ -247,7 +247,7 @@ void BasicTest::initPhysics()
// rsb->setVelocity(btVector3(0, -COLLIDING_VELOCITY, 0));
// rsb->setRigidVelocity(btVector3(0, 1, 0));
// rsb->setRigidAngularVelocity(btVector3(1, 0, 0));
rsb->setRigidAngularVelocity(btVector3(1, 0, 0));
// btDeformableGravityForce* gravity_force = new btDeformableGravityForce(gravity);
// getDeformableDynamicsWorld()->addForce(rsb, gravity_force);

View File

@ -33,7 +33,7 @@ static btScalar damping_alpha = 0.0;
static btScalar damping_beta = 0.0;
static btScalar COLLIDING_VELOCITY = 0;
static int start_mode = 6;
static int num_modes = 1;
static int num_modes = 10;
class FreeFall : public CommonDeformableBodyBase
{
@ -153,17 +153,19 @@ void FreeFall::initPhysics()
btReducedSoftBodyHelpers::readReducedDeformableInfoFromFiles(rsb, filepath.c_str());
getDeformableDynamicsWorld()->addSoftBody(rsb);
rsb->getCollisionShape()->setMargin(0.1);
rsb->getCollisionShape()->setMargin(0.01);
btTransform init_transform;
init_transform.setIdentity();
init_transform.setOrigin(btVector3(0, 10, 0));
init_transform.setRotation(btQuaternion(btVector3(0, 1, 0), SIMD_PI / 2.0));
// init_transform.setRotation(btQuaternion(0, SIMD_PI / 2.0, SIMD_PI / 2.0));
// init_transform.setRotation(btQuaternion(btVector3(0, 0, 1), SIMD_PI / 6.0));
// init_transform.setRotation(btQuaternion(btVector3(0, 1, 0), SIMD_PI / 2.0));
// init_transform.setRotation(btQuaternion(SIMD_PI / 2.0, 0, 0));
rsb->transform(init_transform);
// rsb->setTotalMass(0.5);
rsb->setStiffnessScale(200);
rsb->setStiffnessScale(50);
rsb->setDamping(damping_alpha, damping_beta);
// rsb->setFriction(200);

View File

@ -33,7 +33,7 @@ static btScalar damping_alpha = 0.0;
static btScalar damping_beta = 0.0;
static btScalar COLLIDING_VELOCITY = 4;
static int start_mode = 6;
static int num_modes = 1;
static int num_modes = 20;
class ReducedCollide : public CommonDeformableBodyBase
{
@ -65,8 +65,8 @@ public:
void Ctor_RbUpStack()
{
float mass = 8;
btCollisionShape* shape = new btBoxShape(btVector3(1, 1, 1));
float mass = 55;
btCollisionShape* shape = new btBoxShape(btVector3(0.5, 0.5, 0.5));
btTransform startTransform;
startTransform.setIdentity();
startTransform.setOrigin(btVector3(0,-2,0));
@ -138,7 +138,7 @@ void ReducedCollide::initPhysics()
// create volumetric reduced deformable body
{
std::string filepath("../../../examples/SoftDemo/beam/");
std::string filepath("../../../examples/SoftDemo/cube/");
std::string filename = filepath + "mesh.vtk";
btReducedSoftBody* rsb = btReducedSoftBodyHelpers::createFromVtkFile(getDeformableDynamicsWorld()->getWorldInfo(), filename.c_str());
@ -146,14 +146,14 @@ void ReducedCollide::initPhysics()
btReducedSoftBodyHelpers::readReducedDeformableInfoFromFiles(rsb, filepath.c_str());
getDeformableDynamicsWorld()->addSoftBody(rsb);
rsb->getCollisionShape()->setMargin(0.1);
rsb->getCollisionShape()->setMargin(0.01);
btTransform init_transform;
init_transform.setIdentity();
init_transform.setOrigin(btVector3(0, 2, 0));
rsb->transform(init_transform);
rsb->setStiffnessScale(10);
rsb->setStiffnessScale(50);
rsb->setDamping(damping_alpha, damping_beta);
rsb->m_cfg.kKHR = 1; // collision hardness with kinematic objects

View File

@ -85,14 +85,14 @@ btScalar btReducedDeformableRigidContactConstraint::solveConstraint(const btCont
{
btVector3 Va = getVa();
// btVector3 deltaVa = Va - m_bufferVelocityA;
if (!m_collideStatic)
{
// if (!m_collideStatic)
// {
std::cout << "moving collision!!!\n";
std::cout << "relPosA: " << m_relPosA[0] << "\t" << m_relPosA[1] << "\t" << m_relPosA[2] << "\n";
// std::cout << "moving rigid linear_vel: " << m_solverBody->m_originalBody->getLinearVelocity()[0] << '\t'
// << m_solverBody->m_originalBody->getLinearVelocity()[1] << '\t'
// << m_solverBody->m_originalBody->getLinearVelocity()[2] << '\n';
}
// }
btVector3 deltaVa = getDeltaVa();
btVector3 deltaVb = getDeltaVb();
@ -115,11 +115,11 @@ btScalar btReducedDeformableRigidContactConstraint::solveConstraint(const btCont
// get the normal impulse to be applied
btScalar deltaImpulse = m_rhs - deltaV_rel_normal / m_normalImpulseFactor;
if (!m_collideStatic)
{
// if (!m_collideStatic)
// {
std::cout << "m_rhs: " << m_rhs << '\t' << "m_appliedNormalImpulse: " << m_appliedNormalImpulse << "\n";
std::cout << "m_normalImpulseFactor: " << m_normalImpulseFactor << '\n';
}
// }
{
// cumulative impulse that has been applied

View File

@ -199,7 +199,7 @@ void btReducedSoftBody::updateExternalForceProjectMatrix(bool initialized)
{
btMatrix3x3 r_star = Cross(m_localMomentArm[i]);
btVector3 s_ri(m_modes[r][3 * i], m_modes[r][3 * i + 1], m_modes[r][3 * i + 2]);
btVector3 prod_i = r_star.scaled(m_invInertiaLocal) * r_star * s_ri;
btVector3 prod_i = r_star * m_invInertiaTensorWorld * r_star * s_ri;
for (int k = 0; k < 3; ++k)
m_projCq[r][3 * i + k] = m_nodalMass[i] * prod_i[k];
@ -338,7 +338,8 @@ const btVector3 btReducedSoftBody::internalComputeNodeDeltaVelocity(const btTran
void btReducedSoftBody::proceedToTransform(btScalar dt, bool end_of_time_step)
{
btTransformUtil::integrateTransform(m_rigidTransformWorld, m_linearVelocity, m_angularVelocity, dt, m_interpolationWorldTransform);
m_interpolateInvInertiaTensorWorld = m_interpolationWorldTransform.getBasis().scaled(m_invInertiaLocal) * m_interpolationWorldTransform.getBasis().transpose();
updateInertiaTensor();
// m_interpolateInvInertiaTensorWorld = m_interpolationWorldTransform.getBasis().scaled(m_invInertiaLocal) * m_interpolationWorldTransform.getBasis().transpose();
m_rigidTransformWorld = m_interpolationWorldTransform;
m_invInertiaTensorWorld = m_interpolateInvInertiaTensorWorld;
}
@ -347,21 +348,20 @@ void btReducedSoftBody::transform(const btTransform& trs)
{
// translate mesh
btSoftBody::transform(trs);
updateRestNodalPositions();
// update modes
updateModesByRotation(trs.getBasis());
// update inertia tensor
updateInitialInertiaTensor(trs.getBasis());
updateInertiaTensor();
m_interpolateInvInertiaTensorWorld = m_invInertiaTensorWorld;
// update rigid frame (No need to update the rotation. Nodes have already been updated.)
m_rigidTransformWorld.setOrigin(trs.getOrigin());
m_interpolationWorldTransform = m_rigidTransformWorld;
m_initialOrigin = m_rigidTransformWorld.getOrigin();
updateLocalMomentArm();
// update inertia tensor
updateInitialInertiaTensor(trs.getBasis());
// updateInitialInertiaTensorFromNodes();
updateInertiaTensor();
// update modes
updateModesByRotation(trs.getBasis());
internalInitialization();
}
void btReducedSoftBody::updateRestNodalPositions()