2018-09-21 07:10:18 +00:00
|
|
|
#include <QGuiApplication>
|
|
|
|
#include <QElapsedTimer>
|
|
|
|
#include "posepreviewsgenerator.h"
|
|
|
|
#include "posemeshcreator.h"
|
2018-11-01 15:24:06 +00:00
|
|
|
#include "poserconstruct.h"
|
2019-06-10 14:01:06 +00:00
|
|
|
#include "posedocument.h"
|
2018-09-21 07:10:18 +00:00
|
|
|
|
2018-11-01 15:24:06 +00:00
|
|
|
PosePreviewsGenerator::PosePreviewsGenerator(RigType rigType,
|
|
|
|
const std::vector<RiggerBone> *rigBones,
|
2018-10-26 23:04:45 +00:00
|
|
|
const std::map<int, RiggerVertexWeights> *rigWeights,
|
2018-10-25 00:19:38 +00:00
|
|
|
const Outcome &outcome) :
|
2018-11-01 15:24:06 +00:00
|
|
|
m_rigType(rigType),
|
2018-09-21 07:10:18 +00:00
|
|
|
m_rigBones(*rigBones),
|
|
|
|
m_rigWeights(*rigWeights),
|
2018-10-25 00:19:38 +00:00
|
|
|
m_outcome(new Outcome(outcome))
|
2018-09-21 07:10:18 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
PosePreviewsGenerator::~PosePreviewsGenerator()
|
|
|
|
{
|
|
|
|
for (auto &item: m_previews) {
|
|
|
|
delete item.second;
|
|
|
|
}
|
2018-10-25 00:19:38 +00:00
|
|
|
delete m_outcome;
|
2018-09-21 07:10:18 +00:00
|
|
|
}
|
|
|
|
|
2018-11-09 03:20:48 +00:00
|
|
|
void PosePreviewsGenerator::addPose(std::pair<QUuid, int> idAndFrame, const std::map<QString, std::map<QString, QString>> &pose)
|
2018-09-21 07:10:18 +00:00
|
|
|
{
|
2018-11-09 03:20:48 +00:00
|
|
|
m_poses.push_back(std::make_pair(idAndFrame, pose));
|
2018-09-21 07:10:18 +00:00
|
|
|
}
|
|
|
|
|
2018-11-09 03:20:48 +00:00
|
|
|
const std::set<std::pair<QUuid, int>> &PosePreviewsGenerator::generatedPreviewPoseIdAndFrames()
|
2018-09-21 07:10:18 +00:00
|
|
|
{
|
2018-11-09 03:20:48 +00:00
|
|
|
return m_generatedPoseIdAndFrames;
|
2018-09-21 07:10:18 +00:00
|
|
|
}
|
|
|
|
|
2020-04-07 23:15:20 +00:00
|
|
|
Model *PosePreviewsGenerator::takePreview(std::pair<QUuid, int> idAndFrame)
|
2018-09-21 07:10:18 +00:00
|
|
|
{
|
2020-04-07 23:15:20 +00:00
|
|
|
Model *resultMesh = m_previews[idAndFrame];
|
2018-11-09 03:20:48 +00:00
|
|
|
m_previews[idAndFrame] = nullptr;
|
2018-09-21 07:10:18 +00:00
|
|
|
return resultMesh;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PosePreviewsGenerator::process()
|
|
|
|
{
|
|
|
|
QElapsedTimer countTimeConsumed;
|
|
|
|
countTimeConsumed.start();
|
|
|
|
|
2018-11-01 15:24:06 +00:00
|
|
|
Poser *poser = newPoser(m_rigType, m_rigBones);
|
2018-09-21 07:10:18 +00:00
|
|
|
for (const auto &pose: m_poses) {
|
2019-06-10 14:01:06 +00:00
|
|
|
PoseDocument poseDocument;
|
|
|
|
poseDocument.fromParameters(&m_rigBones, pose.second);
|
|
|
|
std::map<QString, std::map<QString, QString>> translatedParameters;
|
|
|
|
poseDocument.toParameters(translatedParameters);
|
|
|
|
poser->parameters() = translatedParameters;
|
2018-09-21 07:10:18 +00:00
|
|
|
poser->commit();
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
PoseMeshCreator *poseMeshCreator = new PoseMeshCreator(poser->resultNodes(), *m_outcome, m_rigWeights);
|
2018-09-21 07:10:18 +00:00
|
|
|
poseMeshCreator->createMesh();
|
|
|
|
m_previews[pose.first] = poseMeshCreator->takeResultMesh();
|
|
|
|
delete poseMeshCreator;
|
|
|
|
|
|
|
|
poser->reset();
|
|
|
|
|
2018-11-09 03:20:48 +00:00
|
|
|
m_generatedPoseIdAndFrames.insert(pose.first);
|
2018-09-21 07:10:18 +00:00
|
|
|
}
|
|
|
|
delete poser;
|
|
|
|
|
|
|
|
qDebug() << "The pose previews generation took" << countTimeConsumed.elapsed() << "milliseconds";
|
|
|
|
|
|
|
|
this->moveToThread(QGuiApplication::instance()->thread());
|
|
|
|
emit finished();
|
|
|
|
}
|