Add hang effect for cloth simulation
parent
44cd33d799
commit
8ffef700c4
|
@ -754,7 +754,7 @@ Tips:
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<source>Stiffness</source>
|
<source>Stiffness</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation>硬度</translation>
|
||||||
</message>
|
</message>
|
||||||
</context>
|
</context>
|
||||||
<context>
|
<context>
|
||||||
|
|
|
@ -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,
|
ClothSimulator::ClothSimulator(const std::vector<QVector3D> &vertices,
|
||||||
|
@ -131,6 +144,7 @@ ClothSimulator::~ClothSimulator()
|
||||||
delete m_rootNode;
|
delete m_rootNode;
|
||||||
delete m_deformationNode;
|
delete m_deformationNode;
|
||||||
delete m_meshCollisionNode;
|
delete m_meshCollisionNode;
|
||||||
|
delete m_fixNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClothSimulator::setStiffness(float stiffness)
|
void ClothSimulator::setStiffness(float stiffness)
|
||||||
|
@ -243,5 +257,10 @@ void ClothSimulator::create()
|
||||||
m_meshCollisionNode = new CgMeshCollisionNode(m_massSpringSystem, m_clothPointBuffer.data(),
|
m_meshCollisionNode = new CgMeshCollisionNode(m_massSpringSystem, m_clothPointBuffer.data(),
|
||||||
m_collisionVertices,
|
m_collisionVertices,
|
||||||
m_collisionTriangles);
|
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);
|
m_rootNode->addChild(m_meshCollisionNode);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ class MassSpringSolver;
|
||||||
class CgRootNode;
|
class CgRootNode;
|
||||||
class CgSpringDeformationNode;
|
class CgSpringDeformationNode;
|
||||||
class CgMeshCollisionNode;
|
class CgMeshCollisionNode;
|
||||||
|
class CgPointFixNode;
|
||||||
|
|
||||||
class ClothSimulator : public QObject
|
class ClothSimulator : public QObject
|
||||||
{
|
{
|
||||||
|
@ -37,6 +38,7 @@ private:
|
||||||
CgRootNode *m_rootNode = nullptr;
|
CgRootNode *m_rootNode = nullptr;
|
||||||
CgSpringDeformationNode *m_deformationNode = nullptr;
|
CgSpringDeformationNode *m_deformationNode = nullptr;
|
||||||
CgMeshCollisionNode *m_meshCollisionNode = nullptr;
|
CgMeshCollisionNode *m_meshCollisionNode = nullptr;
|
||||||
|
CgPointFixNode *m_fixNode = nullptr;
|
||||||
void convertMeshToCloth();
|
void convertMeshToCloth();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue