Support cloth self friction, thickness. Small refactor
This commit is contained in:
@ -29,6 +29,8 @@ class b3World;
|
||||
class b3Shape;
|
||||
|
||||
class b3Particle;
|
||||
class b3ClothTriangle;
|
||||
|
||||
class b3Force;
|
||||
struct b3ParticleBodyContact;
|
||||
|
||||
@ -62,6 +64,8 @@ struct b3ClothDef
|
||||
structural = 0.0f;
|
||||
bending = 0.0f;
|
||||
damping = 0.0f;
|
||||
thickness = 0.0f;
|
||||
friction = 0.2f;
|
||||
}
|
||||
|
||||
// Cloth mesh
|
||||
@ -78,6 +82,12 @@ struct b3ClothDef
|
||||
|
||||
// Damping stiffness
|
||||
float32 damping;
|
||||
|
||||
// Cloth thickness
|
||||
float32 thickness;
|
||||
|
||||
// Cloth coefficient of friction
|
||||
float32 friction;
|
||||
};
|
||||
|
||||
// A cloth represents a deformable surface as a collection of particles.
|
||||
@ -126,6 +136,9 @@ public:
|
||||
// Return the particle associated with the given vertex.
|
||||
b3Particle* GetVertexParticle(u32 i);
|
||||
|
||||
// Return the cloth triangle given the triangle index.
|
||||
b3ClothTriangle* GetTriangle(u32 i);
|
||||
|
||||
// Return the list of particles in this cloth.
|
||||
const b3List2<b3Particle>& GetParticleList() const;
|
||||
|
||||
@ -142,6 +155,7 @@ public:
|
||||
void Draw() const;
|
||||
private:
|
||||
friend class b3Particle;
|
||||
friend class b3ClothTriangle;
|
||||
friend class b3ClothContactManager;
|
||||
|
||||
// Compute mass of each particle.
|
||||
@ -153,12 +167,6 @@ private:
|
||||
// Solve
|
||||
void Solve(float32 dt, const b3Vec3& gravity, u32 velocityIterations, u32 positionIterations);
|
||||
|
||||
// Synchronize triangle AABB.
|
||||
void SynchronizeTriangle(u32 triangleIndex);
|
||||
|
||||
// Time-step
|
||||
float32 m_dt;
|
||||
|
||||
// Stack allocator
|
||||
b3StackAllocator m_stackAllocator;
|
||||
|
||||
@ -174,8 +182,8 @@ private:
|
||||
// Vertex particles
|
||||
b3Particle** m_vertexParticles;
|
||||
|
||||
// Triangle proxies
|
||||
b3ClothAABBProxy* m_triangleProxies;
|
||||
// Triangles
|
||||
b3ClothTriangle* m_triangles;
|
||||
|
||||
// Cloth density
|
||||
float32 m_density;
|
||||
|
@ -22,8 +22,7 @@
|
||||
#include <bounce/common/template/list.h>
|
||||
|
||||
class b3Particle;
|
||||
struct b3ClothMeshTriangle;
|
||||
struct b3ClothAABBProxy;
|
||||
class b3ClothTriangle;
|
||||
|
||||
// Contact between particle and a triangle
|
||||
class b3ParticleTriangleContact
|
||||
@ -32,6 +31,7 @@ public:
|
||||
private:
|
||||
friend class b3Cloth;
|
||||
friend class b3Particle;
|
||||
friend class b3ClothTriangle;
|
||||
friend class b3ClothContactManager;
|
||||
friend class b3List2<b3ParticleTriangleContact>;
|
||||
friend class b3ClothContactSolver;
|
||||
@ -45,16 +45,17 @@ private:
|
||||
b3Particle* m_p1;
|
||||
|
||||
// Triangle
|
||||
b3ClothMeshTriangle* m_triangle;
|
||||
b3ClothAABBProxy* m_triangleProxy;
|
||||
b3ClothTriangle* m_t2;
|
||||
b3Particle* m_p2;
|
||||
b3Particle* m_p3;
|
||||
b3Particle* m_p4;
|
||||
|
||||
float32 m_normalImpulse;
|
||||
|
||||
float32 m_w2, m_w3, m_w4;
|
||||
|
||||
float32 m_normalImpulse;
|
||||
float32 m_tangentImpulse1;
|
||||
float32 m_tangentImpulse2;
|
||||
|
||||
bool m_active;
|
||||
|
||||
b3ParticleTriangleContact* m_prev;
|
||||
|
@ -96,9 +96,17 @@ struct b3ClothSolverTriangleContactVelocityConstraint
|
||||
float32 wB, wC, wD;
|
||||
|
||||
b3Vec3 normal;
|
||||
|
||||
float32 normalMass;
|
||||
float32 normalImpulse;
|
||||
|
||||
float32 friction;
|
||||
|
||||
b3Vec3 tangent1;
|
||||
b3Vec3 tangent2;
|
||||
float32 tangentMass1;
|
||||
float32 tangentMass2;
|
||||
float32 tangentImpulse1;
|
||||
float32 tangentImpulse2;
|
||||
};
|
||||
|
||||
struct b3ClothSolverTriangleContactPositionConstraint
|
||||
|
98
include/bounce/cloth/cloth_triangle.h
Normal file
98
include/bounce/cloth/cloth_triangle.h
Normal file
@ -0,0 +1,98 @@
|
||||
/*
|
||||
* 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_CLOTH_TRIANGLE_H
|
||||
#define B3_CLOTH_TRIANGLE_H
|
||||
|
||||
#include <bounce/cloth/particle.h>
|
||||
|
||||
// A cloth triangle
|
||||
class b3ClothTriangle
|
||||
{
|
||||
public:
|
||||
// Return the triangle index.
|
||||
u32 GetTriangle() const;
|
||||
|
||||
// Set the triangle radius.
|
||||
void SetRadius(float32 radius);
|
||||
|
||||
// Return the triangle radius.
|
||||
float32 GetRadius() const;
|
||||
|
||||
// Set the triangle coefficient of friction.
|
||||
void SetFriction(float32 friction);
|
||||
|
||||
// Return the triangle coefficient of friction.
|
||||
float32 GetFriction() const;
|
||||
private:
|
||||
friend class b3Cloth;
|
||||
friend class b3Particle;
|
||||
friend class b3ClothContactManager;
|
||||
friend class b3ParticleTriangleContact;
|
||||
friend class b3ClothSolver;
|
||||
friend class b3ClothContactSolver;
|
||||
|
||||
b3ClothTriangle() { }
|
||||
~b3ClothTriangle() { }
|
||||
|
||||
// Synchronize AABB
|
||||
void Synchronize(const b3Vec3& displacement);
|
||||
|
||||
// Cloth
|
||||
b3Cloth* m_cloth;
|
||||
|
||||
// Triangle index
|
||||
u32 m_triangle;
|
||||
|
||||
// Radius
|
||||
float32 m_radius;
|
||||
|
||||
// Coefficient of friction
|
||||
float32 m_friction;
|
||||
|
||||
// AABB Proxy
|
||||
b3ClothAABBProxy m_aabbProxy;
|
||||
};
|
||||
|
||||
inline u32 b3ClothTriangle::GetTriangle() const
|
||||
{
|
||||
return m_triangle;
|
||||
}
|
||||
|
||||
inline void b3ClothTriangle::SetRadius(float32 radius)
|
||||
{
|
||||
m_radius = radius;
|
||||
Synchronize(b3Vec3_zero);
|
||||
}
|
||||
|
||||
inline float32 b3ClothTriangle::GetRadius() const
|
||||
{
|
||||
return m_radius;
|
||||
}
|
||||
|
||||
inline void b3ClothTriangle::SetFriction(float32 friction)
|
||||
{
|
||||
m_friction = friction;
|
||||
}
|
||||
|
||||
inline float32 b3ClothTriangle::GetFriction() const
|
||||
{
|
||||
return m_friction;
|
||||
}
|
||||
|
||||
#endif
|
@ -103,7 +103,6 @@ struct b3ClothAABBProxy
|
||||
{
|
||||
b3ClothAABBProxyType type;
|
||||
void* data;
|
||||
u32 index;
|
||||
u32 broadPhaseId;
|
||||
};
|
||||
|
||||
@ -160,6 +159,7 @@ public:
|
||||
private:
|
||||
friend class b3List2<b3Particle>;
|
||||
friend class b3Cloth;
|
||||
friend class b3ClothTriangle;
|
||||
friend class b3ClothSolver;
|
||||
friend class b3ClothContactManager;
|
||||
friend class b3ParticleTriangleContact;
|
||||
@ -171,7 +171,7 @@ private:
|
||||
~b3Particle();
|
||||
|
||||
// Synchronize particle AABB
|
||||
void Synchronize();
|
||||
void Synchronize(const b3Vec3& displacement);
|
||||
|
||||
// Synchronize triangles AABB
|
||||
void SynchronizeTriangles();
|
||||
@ -246,10 +246,12 @@ inline u32 b3Particle::GetVertex() const
|
||||
|
||||
inline void b3Particle::SetPosition(const b3Vec3& position)
|
||||
{
|
||||
b3Vec3 displacement = position - m_position;
|
||||
|
||||
m_position = position;
|
||||
m_translation.SetZero();
|
||||
|
||||
Synchronize();
|
||||
Synchronize(displacement);
|
||||
SynchronizeTriangles();
|
||||
}
|
||||
|
||||
@ -281,7 +283,7 @@ inline void b3Particle::SetRadius(float32 radius)
|
||||
{
|
||||
m_radius = radius;
|
||||
|
||||
Synchronize();
|
||||
Synchronize(b3Vec3_zero);
|
||||
}
|
||||
|
||||
inline float32 b3Particle::GetRadius() const
|
||||
|
Reference in New Issue
Block a user