2018-10-26 23:04:45 +00:00
|
|
|
#ifndef DUST3D_RIGGER_H
|
|
|
|
#define DUST3D_RIGGER_H
|
2018-09-14 09:45:05 +00:00
|
|
|
#include <QtGlobal>
|
|
|
|
#include <QVector3D>
|
|
|
|
#include <QObject>
|
|
|
|
#include <QColor>
|
2018-09-18 03:17:35 +00:00
|
|
|
#include <QDebug>
|
2018-11-01 15:24:06 +00:00
|
|
|
#include <QVector2D>
|
2020-02-09 11:12:14 +00:00
|
|
|
#include <set>
|
2018-10-25 00:19:38 +00:00
|
|
|
#include "bonemark.h"
|
2018-09-14 09:45:05 +00:00
|
|
|
#include "rigtype.h"
|
2018-10-25 00:19:38 +00:00
|
|
|
#include "skeletonside.h"
|
2018-09-14 09:45:05 +00:00
|
|
|
|
2020-02-09 11:12:14 +00:00
|
|
|
namespace Rigger
|
2018-09-14 09:45:05 +00:00
|
|
|
{
|
2020-02-09 11:12:14 +00:00
|
|
|
const QString rootBoneName = "Body";
|
2018-09-14 09:45:05 +00:00
|
|
|
};
|
|
|
|
|
2018-10-26 23:04:45 +00:00
|
|
|
class RiggerBone
|
2018-09-14 09:45:05 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
QString name;
|
2018-11-01 15:24:06 +00:00
|
|
|
int index = -1;
|
2020-02-09 11:12:14 +00:00
|
|
|
int parent = -1;
|
2018-09-14 09:45:05 +00:00
|
|
|
QVector3D headPosition;
|
|
|
|
QVector3D tailPosition;
|
2019-09-21 14:30:27 +00:00
|
|
|
float headRadius = 0.0;
|
|
|
|
float tailRadius = 0.0;
|
2018-09-14 09:45:05 +00:00
|
|
|
QColor color;
|
|
|
|
std::vector<int> children;
|
|
|
|
};
|
|
|
|
|
2018-10-26 23:04:45 +00:00
|
|
|
class RiggerVertexWeights
|
2018-09-14 09:45:05 +00:00
|
|
|
{
|
|
|
|
public:
|
2018-11-17 23:02:12 +00:00
|
|
|
int boneIndices[4] = {0, 0, 0, 0};
|
2018-09-14 09:45:05 +00:00
|
|
|
float boneWeights[4] = {0, 0, 0, 0};
|
2020-02-09 11:12:14 +00:00
|
|
|
void addBone(int boneIndex, float weight)
|
2018-09-14 09:45:05 +00:00
|
|
|
{
|
2020-02-09 11:12:14 +00:00
|
|
|
for (auto &it: m_boneRawWeights) {
|
|
|
|
if (it.first == boneIndex) {
|
|
|
|
it.second += weight;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_boneRawWeights.push_back(std::make_pair(boneIndex, weight));
|
2018-09-14 09:45:05 +00:00
|
|
|
}
|
|
|
|
void finalizeWeights()
|
|
|
|
{
|
|
|
|
std::sort(m_boneRawWeights.begin(), m_boneRawWeights.end(),
|
|
|
|
[](const std::pair<int, float> &a, const std::pair<int, float> &b) {
|
|
|
|
return a.second > b.second;
|
|
|
|
});
|
2020-02-09 11:12:14 +00:00
|
|
|
float totalWeight = 0;
|
2018-09-14 09:45:05 +00:00
|
|
|
for (size_t i = 0; i < m_boneRawWeights.size() && i < 4; i++) {
|
|
|
|
const auto &item = m_boneRawWeights[i];
|
2020-02-09 11:12:14 +00:00
|
|
|
totalWeight += item.second;
|
2018-09-14 09:45:05 +00:00
|
|
|
}
|
2020-02-09 11:12:14 +00:00
|
|
|
if (totalWeight > 0) {
|
2018-09-14 09:45:05 +00:00
|
|
|
for (size_t i = 0; i < m_boneRawWeights.size() && i < 4; i++) {
|
|
|
|
const auto &item = m_boneRawWeights[i];
|
2018-11-17 23:02:12 +00:00
|
|
|
boneIndices[i] = item.first;
|
2020-02-09 11:12:14 +00:00
|
|
|
boneWeights[i] = item.second / totalWeight;
|
2018-09-14 09:45:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
std::vector<std::pair<int, float>> m_boneRawWeights;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|