Added per triangle stretching force and damping. This gives more realistics results. Also updated the tests.
Saying goodbye to mass-spring system!
This commit is contained in:
@ -68,6 +68,7 @@
|
||||
#include <bounce/cloth/cloth.h>
|
||||
#include <bounce/cloth/particle.h>
|
||||
#include <bounce/cloth/cloth_triangle.h>
|
||||
#include <bounce/cloth/strech_force.h>
|
||||
#include <bounce/cloth/spring_force.h>
|
||||
|
||||
#include <bounce/cloth/garment/sewing_pattern.h>
|
||||
|
@ -57,7 +57,8 @@ struct b3ClothDef
|
||||
{
|
||||
mesh = nullptr;
|
||||
density = 0.0f;
|
||||
structural = 0.0f;
|
||||
streching = 0.0f;
|
||||
sewing = 0.0f;
|
||||
bending = 0.0f;
|
||||
damping = 0.0f;
|
||||
thickness = 0.0f;
|
||||
@ -70,12 +71,15 @@ struct b3ClothDef
|
||||
// Cloth density in kg/m^2
|
||||
float32 density;
|
||||
|
||||
// Structural stiffness
|
||||
float32 structural;
|
||||
// Streching stiffness
|
||||
float32 streching;
|
||||
|
||||
// Bending stiffness
|
||||
float32 bending;
|
||||
|
||||
// Sewing stiffness
|
||||
float32 sewing;
|
||||
|
||||
// Damping stiffness
|
||||
float32 damping;
|
||||
|
||||
@ -152,6 +156,8 @@ public:
|
||||
private:
|
||||
friend class b3Particle;
|
||||
friend class b3ClothTriangle;
|
||||
friend class b3StrechForce;
|
||||
friend class b3SpringForce;
|
||||
friend class b3ClothContactManager;
|
||||
|
||||
// Compute mass of each particle.
|
||||
|
@ -42,6 +42,7 @@ public:
|
||||
private:
|
||||
friend class b3Cloth;
|
||||
friend class b3Particle;
|
||||
friend class b3StrechForce;
|
||||
friend class b3ClothContactManager;
|
||||
friend class b3ParticleTriangleContact;
|
||||
friend class b3ClothSolver;
|
||||
@ -70,6 +71,14 @@ private:
|
||||
|
||||
// Broadphase ID
|
||||
u32 m_broadPhaseId;
|
||||
|
||||
// Alpha
|
||||
float32 m_alpha;
|
||||
|
||||
// Strech matrix
|
||||
float32 m_du1, m_dv1;
|
||||
float32 m_du2, m_dv2;
|
||||
float32 m_inv_det;
|
||||
};
|
||||
|
||||
inline u32 b3ClothTriangle::GetTriangle() const
|
||||
|
@ -29,6 +29,7 @@ class b3Particle;
|
||||
// Force types
|
||||
enum b3ForceType
|
||||
{
|
||||
e_strechForce,
|
||||
e_springForce,
|
||||
};
|
||||
|
||||
|
@ -120,6 +120,7 @@ private:
|
||||
friend class b3ParticleTriangleContact;
|
||||
friend class b3ClothContactSolver;
|
||||
friend class b3Force;
|
||||
friend class b3StrechForce;
|
||||
friend class b3SpringForce;
|
||||
|
||||
b3Particle(const b3ParticleDef& def, b3Cloth* cloth);
|
||||
|
126
include/bounce/cloth/strech_force.h
Normal file
126
include/bounce/cloth/strech_force.h
Normal file
@ -0,0 +1,126 @@
|
||||
/*
|
||||
* Copyright (c) 2016-2019 Irlan Robson https://irlanrobson.github.io
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef B3_STRECH_FORCE_H
|
||||
#define B3_STRECH_FORCE_H
|
||||
|
||||
#include <bounce/cloth/force.h>
|
||||
|
||||
class b3ClothTriangle;
|
||||
|
||||
struct b3StrechForceDef : public b3ForceDef
|
||||
{
|
||||
b3StrechForceDef()
|
||||
{
|
||||
type = e_strechForce;
|
||||
}
|
||||
|
||||
// Triangle
|
||||
b3ClothTriangle* triangle;
|
||||
|
||||
// Streching stiffness
|
||||
float32 streching;
|
||||
|
||||
// Damping stiffness
|
||||
float32 damping;
|
||||
|
||||
// Desired strechiness in u direction
|
||||
float32 bu;
|
||||
|
||||
// Desired strechiness in v direction
|
||||
float32 bv;
|
||||
};
|
||||
|
||||
// Strech force acting on a cloth triangle.
|
||||
class b3StrechForce : public b3Force
|
||||
{
|
||||
public:
|
||||
bool HasParticle(const b3Particle* particle) const;
|
||||
|
||||
b3ClothTriangle* GetTriangle() const;
|
||||
|
||||
float32 GetStrechingStiffness() const;
|
||||
|
||||
float32 GetDampingStiffness() const;
|
||||
|
||||
b3Vec3 GetActionForce1() const;
|
||||
|
||||
b3Vec3 GetActionForce2() const;
|
||||
|
||||
b3Vec3 GetActionForce3() const;
|
||||
private:
|
||||
friend class b3Force;
|
||||
friend class b3Cloth;
|
||||
|
||||
b3StrechForce(const b3StrechForceDef* def);
|
||||
~b3StrechForce();
|
||||
|
||||
void Apply(const b3ClothForceSolverData* data);
|
||||
|
||||
// Solver shared
|
||||
|
||||
// Triangle
|
||||
b3ClothTriangle* m_triangle;
|
||||
|
||||
// Streching stiffness
|
||||
float32 m_ks;
|
||||
|
||||
// Damping stiffness
|
||||
float32 m_kd;
|
||||
|
||||
// bu
|
||||
float32 m_bu;
|
||||
|
||||
// bv
|
||||
float32 m_bv;
|
||||
|
||||
// Action forces
|
||||
b3Vec3 m_f1, m_f2, m_f3;
|
||||
};
|
||||
|
||||
inline b3ClothTriangle* b3StrechForce::GetTriangle() const
|
||||
{
|
||||
return m_triangle;
|
||||
}
|
||||
|
||||
inline float32 b3StrechForce::GetStrechingStiffness() const
|
||||
{
|
||||
return m_ks;
|
||||
}
|
||||
|
||||
inline float32 b3StrechForce::GetDampingStiffness() const
|
||||
{
|
||||
return m_kd;
|
||||
}
|
||||
|
||||
inline b3Vec3 b3StrechForce::GetActionForce1() const
|
||||
{
|
||||
return m_f1;
|
||||
}
|
||||
|
||||
inline b3Vec3 b3StrechForce::GetActionForce2() const
|
||||
{
|
||||
return m_f2;
|
||||
}
|
||||
|
||||
inline b3Vec3 b3StrechForce::GetActionForce3() const
|
||||
{
|
||||
return m_f3;
|
||||
}
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user