2021-11-18 14:58:01 +00:00
|
|
|
#include "skeleton_ik_mover.h"
|
|
|
|
#include "ccd_ik_resolver.h"
|
2022-10-18 09:35:04 +00:00
|
|
|
#include <QGuiApplication>
|
2018-05-24 01:44:40 +00:00
|
|
|
|
2020-12-19 08:12:50 +00:00
|
|
|
SkeletonIkMover::SkeletonIkMover()
|
2018-05-24 01:44:40 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SkeletonIkMover::~SkeletonIkMover()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-10-18 09:35:04 +00:00
|
|
|
void SkeletonIkMover::setTarget(const QVector3D& target)
|
2018-05-24 01:44:40 +00:00
|
|
|
{
|
|
|
|
m_target = target;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SkeletonIkMover::setUpdateVersion(unsigned long long version)
|
|
|
|
{
|
|
|
|
m_updateVersion = version;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned long long SkeletonIkMover::getUpdateVersion()
|
|
|
|
{
|
|
|
|
return m_updateVersion;
|
|
|
|
}
|
|
|
|
|
2021-11-18 14:58:01 +00:00
|
|
|
void SkeletonIkMover::addNode(dust3d::Uuid id, QVector3D position)
|
2018-05-24 01:44:40 +00:00
|
|
|
{
|
|
|
|
SkeletonIkNode ikNode;
|
|
|
|
ikNode.id = id;
|
|
|
|
ikNode.position = ikNode.newPosition = position;
|
|
|
|
m_ikNodes.push_back(ikNode);
|
|
|
|
}
|
|
|
|
|
2022-10-18 09:35:04 +00:00
|
|
|
const std::vector<SkeletonIkNode>& SkeletonIkMover::ikNodes()
|
2018-05-24 01:44:40 +00:00
|
|
|
{
|
|
|
|
return m_ikNodes;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SkeletonIkMover::process()
|
|
|
|
{
|
|
|
|
resolve();
|
2022-10-18 09:35:04 +00:00
|
|
|
|
2018-05-24 01:44:40 +00:00
|
|
|
emit finished();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SkeletonIkMover::resolve()
|
|
|
|
{
|
2020-11-09 10:46:06 +00:00
|
|
|
CcdIkSolver solver;
|
2018-05-24 01:44:40 +00:00
|
|
|
for (auto i = 0u; i < m_ikNodes.size(); i++) {
|
|
|
|
solver.addNodeInOrder(m_ikNodes[i].position);
|
|
|
|
}
|
|
|
|
solver.solveTo(m_target);
|
|
|
|
for (auto i = 0u; i < m_ikNodes.size(); i++) {
|
|
|
|
m_ikNodes[i].newPosition = solver.getNodeSolvedPosition(i);
|
|
|
|
}
|
|
|
|
}
|