Skip to content

Commit

Permalink
First pass at bending constraints (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajweeks committed Nov 26, 2020
1 parent c6bef86 commit 3732498
Show file tree
Hide file tree
Showing 3 changed files with 2,595 additions and 14,400 deletions.
35 changes: 30 additions & 5 deletions FlexEngine/include/Scene/GameObject.hpp
Expand Up @@ -1033,30 +1033,45 @@ namespace flex
enum class Type
{
DISTANCE,
BENDING,

_NONE
};

Constraint(i32 index0, i32 index1, real stiffness, EqualityType equalityType, Type type) :
Constraint(real stiffness, EqualityType equalityType, Type type) :
stiffness(stiffness),
equalityType(equalityType),
type(type)
{
pointIndices[0] = index0;
pointIndices[1] = index1;
}

i32 pointIndices[2];
real stiffness;
EqualityType equalityType;
Type type;
};

struct DistanceConstraint : public Constraint
{
DistanceConstraint(i32 index0, i32 index1, real stiffness, real targetDistance);
DistanceConstraint(i32 pointIndex0, i32 pointIndex1, real stiffness, real targetDistance);

real targetDistance;
i32 pointIndices[2];
};

struct BendingConstraint : public Constraint
{
BendingConstraint(i32 pointIndex0, i32 pointIndex1, i32 pointIndex2, i32 pointIndex3, real stiffness, real targetPhi);

real targetPhi;
i32 pointIndices[4];
};

struct Triangle
{
Triangle();
Triangle(i32 pointIndex0, i32 pointIndex1, i32 pointIndex2);

i32 pointIndices[3];
};

class SoftBody : public GameObject
Expand Down Expand Up @@ -1084,9 +1099,13 @@ namespace flex
// Add new constraint between index0 & index1 if one doesn't already exist.
// Returns new constraint count
u32 AddUniqueDistanceConstraint(i32 index0, i32 index1, u32 atIndex, real stiffness);
u32 AddUniqueBendingConstraint(i32 index0, i32 index1, i32 index2, i32 index3, u32 atIndex, real stiffness);

void LoadFromMesh();

// Outside vert is vert not on shared edge
bool GetTriangleSharingEdge(const std::vector<u32>& indexData, i32 edgeIndex0, i32 edgeIndex1, const Triangle& originalTri, Triangle& outTri, i32& outOutsideVertIndex);

u32 m_SolverIterationCount;
bool m_bPaused = false;
bool m_bSingleStep = false;
Expand All @@ -1097,10 +1116,16 @@ namespace flex
ms m_UpdateDuration = 0.0f;
real m_Damping = 0.99f;
real m_Stiffness = 0.8f;
real m_BendingStiffness = 0.8f;

u32 m_DragPointIndex = 0;
std::vector<Point*> points;
// TODO: Split constraint types into separate containers
std::vector<Constraint*> constraints;
std::vector<Triangle*> triangles;

i32 m_ShownBendingIndex = 0;
i32 m_FirstBendingConstraintIndex = 0;

std::vector<glm::vec3> initialPositions;

Expand Down

0 comments on commit 3732498

Please sign in to comment.