Small refactor. Allow cloth particle to collide with multiple shapes. This is a more general solution.

This commit is contained in:
Irlan
2019-06-23 10:52:41 -03:00
parent 39b27c86d2
commit 13eab5d00d
19 changed files with 426 additions and 247 deletions

View File

@ -26,16 +26,14 @@
#include <bounce/cloth/cloth_contact_manager.h>
class b3World;
class b3Shape;
class b3Particle;
class b3ClothTriangle;
class b3Force;
struct b3ParticleBodyContact;
struct b3ParticleDef;
class b3Particle;
struct b3ForceDef;
class b3Force;
class b3ClothTriangle;
struct b3ClothMesh;
@ -44,8 +42,6 @@ class b3RayCastListener;
struct b3RayCastInput;
struct b3RayCastOutput;
struct b3ClothAABBProxy;
struct b3ClothRayCastSingleOutput
{
u32 triangle;
@ -161,9 +157,6 @@ private:
// Compute mass of each particle.
void ComputeMass();
// Update particle-body contacts
void UpdateParticleBodyContacts();
// Solve
void Solve(float32 dt, const b3Vec3& gravity, u32 velocityIterations, u32 positionIterations);

View File

@ -0,0 +1,38 @@
/*
* 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_COLLISION_H
#define B3_CLOTH_COLLISION_H
#include <bounce/common/math/vec3.h>
// Cloth primitive type
enum b3ClothAABBProxyType
{
e_particleProxy,
e_triangleProxy
};
// Cloth primitive broadphase proxy
struct b3ClothAABBProxy
{
b3ClothAABBProxyType type;
void* owner;
};
#endif

View File

@ -19,7 +19,8 @@
#ifndef B3_CLOTH_CONTACT_MANAGER_H
#define B3_CLOTH_CONTACT_MANAGER_H
#include <bounce/cloth/cloth_contact.h>
#include <bounce/cloth/cloth_particle_body_contact.h>
#include <bounce/cloth/cloth_particle_triangle_contact.h>
#include <bounce/collision/broad_phase.h>
#include <bounce/common/memory/block_pool.h>
#include <bounce/common/template/list.h>
@ -32,21 +33,31 @@ class b3ClothContactManager
public:
b3ClothContactManager();
// The broad-phase callback.
void AddPair(void* data1, void* data2);
void FindNewContacts();
void AddPair(void* data1, void* data2);
void FindNewClothContacts();
void AddPSPair(b3Particle* p1, b3Shape* s2);
void FindNewBodyContacts();
void UpdateContacts();
void UpdateClothContacts();
void UpdateBodyContacts();
b3ParticleTriangleContact* CreateParticleTriangleContact();
void Destroy(b3ParticleTriangleContact* c);
b3ParticleBodyContact* CreateParticleBodyContact();
void Destroy(b3ParticleBodyContact* c);
b3BlockPool m_particleTriangleContactBlocks;
b3BlockPool m_particleBodyContactBlocks;
b3Cloth* m_cloth;
b3BroadPhase m_broadPhase;
b3List2<b3ParticleTriangleContact> m_particleTriangleContactList;
b3List2<b3ParticleBodyContact> m_particleBodyContactList;
};
#endif

View File

@ -27,7 +27,7 @@ class b3StackAllocator;
class b3Particle;
class b3Body;
struct b3ParticleBodyContact;
class b3ParticleBodyContact;
class b3ParticleTriangleContact;
struct b3ClothSolverBodyContactVelocityConstraint

View File

@ -0,0 +1,76 @@
/*
* 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_PARTICLE_BODY_CONTACT_H
#define B3_CLOTH_PARTICLE_BODY_CONTACT_H
#include <bounce/common/template/list.h>
#include <bounce/common/math/vec2.h>
#include <bounce/common/math/vec3.h>
#include <bounce/common/math/transform.h>
class b3Particle;
class b3Shape;
// A contact between a particle and a body
class b3ParticleBodyContact
{
public:
private:
friend class b3List2<b3ParticleBodyContact>;
friend class b3Cloth;
friend class b3Particle;
friend class b3ClothContactManager;
friend class b3ClothSolver;
friend class b3ClothContactSolver;
friend struct b3ParticleBodyContactWorldPoint;
b3ParticleBodyContact() { }
~b3ParticleBodyContact() { }
void Update();
b3Particle* m_p1;
b3Shape* m_s2;
bool m_active;
// Contact constraint
b3Vec3 m_normal1;
b3Vec3 m_localPoint1;
b3Vec3 m_localPoint2;
float32 m_normalImpulse;
// Friction constraint
b3Vec3 m_tangent1, m_tangent2;
b3Vec2 m_tangentImpulse;
b3ParticleBodyContact* m_prev;
b3ParticleBodyContact* m_next;
};
struct b3ParticleBodyContactWorldPoint
{
void Initialize(const b3ParticleBodyContact* c, float32 rA, const b3Transform& xfA, float32 rB, const b3Transform& xfB);
b3Vec3 point;
b3Vec3 normal;
float32 separation;
};
#endif

View File

@ -16,8 +16,8 @@
* 3. This notice may not be removed or altered from any source distribution.
*/
#ifndef B3_CLOTH_CONTACT_H
#define B3_CLOTH_CONTACT_H
#ifndef B3_CLOTH_PARTICLE_TRIANGLE_CONTACT_H
#define B3_CLOTH_PARTICLE_TRIANGLE_CONTACT_H
#include <bounce/common/template/list.h>
@ -29,11 +29,11 @@ class b3ParticleTriangleContact
{
public:
private:
friend class b3List2<b3ParticleTriangleContact>;
friend class b3Cloth;
friend class b3Particle;
friend class b3ClothTriangle;
friend class b3ClothContactManager;
friend class b3List2<b3ParticleTriangleContact>;
friend class b3ClothContactSolver;
b3ParticleTriangleContact() { }

View File

@ -26,7 +26,7 @@ class b3StackAllocator;
class b3Particle;
class b3Force;
struct b3ParticleBodyContact;
class b3ParticleBodyContact;
class b3ParticleTriangleContact;
struct b3ClothSolverDef

View File

@ -19,7 +19,7 @@
#ifndef B3_CLOTH_TRIANGLE_H
#define B3_CLOTH_TRIANGLE_H
#include <bounce/cloth/particle.h>
#include <bounce/cloth/cloth_collision.h>
// A cloth triangle
class b3ClothTriangle

View File

@ -19,14 +19,10 @@
#ifndef B3_PARTICLE_H
#define B3_PARTICLE_H
#include <bounce/cloth/force.h>
#include <bounce/common/math/transform.h>
#include <bounce/common/math/vec2.h>
#include <bounce/cloth/cloth_collision.h>
#include <bounce/common/template/list.h>
class b3Shape;
class b3Cloth;
class b3Particle;
// Static particle: Can be moved manually.
// Kinematic particle: Non-zero velocity, can be moved by the solver.
@ -38,7 +34,7 @@ enum b3ParticleType
e_dynamicParticle
};
//
// Particle definition
struct b3ParticleDef
{
b3ParticleDef()
@ -63,48 +59,6 @@ struct b3ParticleDef
void* userData;
};
// A contact between a particle and a solid
struct b3ParticleBodyContact
{
b3Particle* p1;
b3Shape* s2;
// Contact constraint
b3Vec3 normal1;
b3Vec3 localPoint1;
b3Vec3 localPoint2;
float32 normalImpulse;
// Friction constraint
b3Vec3 t1, t2;
b3Vec2 tangentImpulse;
bool active;
};
struct b3ParticleBodyContactWorldPoint
{
void Initialize(const b3ParticleBodyContact* c, float32 rA, const b3Transform& xfA, float32 rB, const b3Transform& xfB);
b3Vec3 point;
b3Vec3 normal;
float32 separation;
};
// Cloth primitive type
enum b3ClothAABBProxyType
{
e_particleProxy,
e_triangleProxy
};
// Cloth primitive broadphase proxy
struct b3ClothAABBProxy
{
b3ClothAABBProxyType type;
void* owner;
};
// A cloth particle.
class b3Particle
{
@ -162,6 +116,7 @@ private:
friend class b3ClothSolver;
friend class b3ClothForceSolver;
friend class b3ClothContactManager;
friend class b3ParticleBodyContact;
friend class b3ParticleTriangleContact;
friend class b3ClothContactSolver;
friend class b3Force;
@ -223,9 +178,6 @@ private:
// Parent cloth
b3Cloth* m_cloth;
// Contact
b3ParticleBodyContact m_bodyContact;
// AABB Proxy
b3ClothAABBProxy m_aabbProxy;

View File

@ -140,6 +140,9 @@ public:
// Set the user data associated with this shape.
void SetUserData(void* data);
// Get broadphase AABB
const b3AABB3& GetAABB() const;
// Dump this shape to the log file.
void Dump(u32 bodyIndex) const;