Add hang effect for cloth simulation

master
Jeremy Hu 2020-01-09 23:52:33 +09:30
parent 44cd33d799
commit 8ffef700c4
3 changed files with 23 additions and 2 deletions

View File

@ -754,7 +754,7 @@ Tips:
</message>
<message>
<source>Stiffness</source>
<translation type="unfinished"></translation>
<translation></translation>
</message>
</context>
<context>

View File

@ -111,6 +111,19 @@ public:
}
}
}
void fixPoints(CgPointFixNode *fixNode) {
for (unsigned int i = 0; i < system->n_points; i++) {
auto offset = 3 * i;
Point point(vbuff[offset + 0],
vbuff[offset + 1],
vbuff[offset + 2]);
if (nullptr != m_insideTester &&
(*m_insideTester)(point) != CGAL::ON_UNBOUNDED_SIDE) {
fixNode->fixPoint(i);
}
}
}
};
ClothSimulator::ClothSimulator(const std::vector<QVector3D> &vertices,
@ -131,6 +144,7 @@ ClothSimulator::~ClothSimulator()
delete m_rootNode;
delete m_deformationNode;
delete m_meshCollisionNode;
delete m_fixNode;
}
void ClothSimulator::setStiffness(float stiffness)
@ -243,5 +257,10 @@ void ClothSimulator::create()
m_meshCollisionNode = new CgMeshCollisionNode(m_massSpringSystem, m_clothPointBuffer.data(),
m_collisionVertices,
m_collisionTriangles);
m_fixNode = new CgPointFixNode(m_massSpringSystem, m_clothPointBuffer.data());
m_meshCollisionNode->fixPoints(m_fixNode);
m_deformationNode->addChild(m_fixNode);
m_rootNode->addChild(m_meshCollisionNode);
}

View File

@ -9,6 +9,7 @@ class MassSpringSolver;
class CgRootNode;
class CgSpringDeformationNode;
class CgMeshCollisionNode;
class CgPointFixNode;
class ClothSimulator : public QObject
{
@ -37,6 +38,7 @@ private:
CgRootNode *m_rootNode = nullptr;
CgSpringDeformationNode *m_deformationNode = nullptr;
CgMeshCollisionNode *m_meshCollisionNode = nullptr;
CgPointFixNode *m_fixNode = nullptr;
void convertMeshToCloth();
};