Store material parameters inside elements

This commit is contained in:
Irlan
2019-07-07 10:00:00 -03:00
parent b73b760515
commit 2982bc2bd3
3 changed files with 28 additions and 25 deletions

View File

@ -43,6 +43,13 @@ struct b3SoftBodyRayCastSingleOutput
// Soft body tetrahedron element
struct b3SoftBodyElement
{
float32 E;
float32 nu;
float32 c_yield;
float32 c_creep;
float32 c_max;
b3Mat33 K[16]; // 12 x 12
b3Mat33 invE;
b3Quat q;
@ -60,6 +67,7 @@ struct b3SoftBodyTriangle
// Soft body definition
// This requires defining a soft body mesh which is typically bound to a render mesh
// and some uniform material parameters.
struct b3SoftBodyDef
{
b3SoftBodyDef()
@ -130,6 +138,9 @@ public:
// Return the node associated with the given vertex.
b3SoftBodyNode* GetVertexNode(u32 i);
// Return the element associated with the given tetrahedron.
b3SoftBodyElement* GetTetrahedronElement(u32 i);
// Return the kinetic (or dynamic) energy in this system.
float32 GetEnergy() const;
@ -162,21 +173,6 @@ private:
// Soft body density
float32 m_density;
// Material Young's modulus
float32 m_E;
// Material poisson ratio
float32 m_nu;
// Material yield
float32 m_c_yield;
// Material creep rate
float32 m_c_creep;
// Material maximum plastic strain
float32 m_c_max;
// Soft body nodes
b3SoftBodyNode* m_nodes;

View File

@ -450,11 +450,6 @@ b3SoftBody::b3SoftBody(const b3SoftBodyDef& def)
m_mesh = def.mesh;
m_density = def.density;
m_E = def.E;
m_nu = def.nu;
m_c_yield = def.c_yield;
m_c_creep = def.c_creep;
m_c_max = def.c_max;
m_gravity.SetZero();
m_world = nullptr;
m_contactManager.m_body = this;
@ -495,6 +490,12 @@ b3SoftBody::b3SoftBody(const b3SoftBodyDef& def)
{
b3SoftBodyMeshTetrahedron* mt = m->tetrahedrons + ei;
b3SoftBodyElement* e = m_elements + ei;
e->E = def.E;
e->nu = def.nu;
e->c_yield = def.c_yield;
e->c_creep = def.c_creep;
e->c_max = def.c_max;
u32 v1 = mt->v1;
u32 v2 = mt->v2;
@ -520,7 +521,7 @@ b3SoftBody::b3SoftBody(const b3SoftBodyDef& def)
// 6 x 6
float32 D[36];
b3ComputeD(D, m_E, m_nu);
b3ComputeD(D, e->E, e->nu);
// 6 x 12
float32* B = e->B;
@ -658,6 +659,12 @@ b3SoftBodyNode* b3SoftBody::GetVertexNode(u32 i)
return m_nodes + i;
}
b3SoftBodyElement* b3SoftBody::GetTetrahedronElement(u32 i)
{
B3_ASSERT(i < m_mesh->tetrahedronCount);
return m_elements + i;
}
float32 b3SoftBody::GetEnergy() const
{
float32 E = 0.0f;

View File

@ -345,9 +345,9 @@ void b3SoftBodyForceSolver::Solve(float32 dt, const b3Vec3& gravity)
}
float32 len_epsilon_elastic = b3Length(epsilon_elastic, 6);
if (len_epsilon_elastic > m_body->m_c_yield)
if (len_epsilon_elastic > e->c_yield)
{
float32 amount = h * b3Min(m_body->m_c_creep, inv_h);
float32 amount = h * b3Min(e->c_creep, inv_h);
for (u32 i = 0; i < 6; ++i)
{
epsilon_plastic[i] += amount * epsilon_elastic[i];
@ -355,9 +355,9 @@ void b3SoftBodyForceSolver::Solve(float32 dt, const b3Vec3& gravity)
}
float32 len_epsilon_plastic = b3Length(epsilon_plastic, 6);
if (len_epsilon_plastic > m_body->m_c_max)
if (len_epsilon_plastic > e->c_max)
{
float32 scale = m_body->m_c_max / len_epsilon_plastic;
float32 scale = e->c_max / len_epsilon_plastic;
for (u32 i = 0; i < 6; ++i)
{
epsilon_plastic[i] *= scale;