2018-04-07 08:44:39 +00:00
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QThread>
|
|
|
|
#include <QGuiApplication>
|
2018-04-09 08:46:06 +00:00
|
|
|
#include <QClipboard>
|
|
|
|
#include <QMimeData>
|
|
|
|
#include <QApplication>
|
2018-04-12 12:27:21 +00:00
|
|
|
#include <QVector3D>
|
2018-10-25 06:27:59 +00:00
|
|
|
#include <functional>
|
2018-11-11 13:08:13 +00:00
|
|
|
#include <QBuffer>
|
2018-10-25 00:19:38 +00:00
|
|
|
#include "document.h"
|
|
|
|
#include "util.h"
|
|
|
|
#include "snapshotxml.h"
|
2018-10-09 02:19:12 +00:00
|
|
|
#include "materialpreviewsgenerator.h"
|
2018-10-23 14:57:47 +00:00
|
|
|
#include "motionsgenerator.h"
|
2018-10-25 00:19:38 +00:00
|
|
|
#include "skeletonside.h"
|
2018-04-07 08:44:39 +00:00
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
unsigned long Document::m_maxSnapshot = 1000;
|
2018-04-08 23:34:46 +00:00
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
Document::Document() :
|
2018-11-03 08:09:42 +00:00
|
|
|
SkeletonDocument(),
|
2018-04-15 12:11:51 +00:00
|
|
|
// public
|
2018-05-07 16:08:19 +00:00
|
|
|
textureGuideImage(nullptr),
|
|
|
|
textureImage(nullptr),
|
|
|
|
textureBorderImage(nullptr),
|
2018-05-10 09:16:22 +00:00
|
|
|
textureColorImage(nullptr),
|
2018-11-15 22:56:24 +00:00
|
|
|
textureNormalImage(nullptr),
|
|
|
|
textureMetalnessRoughnessAmbientOcclusionImage(nullptr),
|
2018-11-28 03:00:03 +00:00
|
|
|
textureMetalnessImage(nullptr),
|
|
|
|
textureRoughnessImage(nullptr),
|
|
|
|
textureAmbientOcclusionImage(nullptr),
|
2018-09-14 09:45:05 +00:00
|
|
|
rigType(RigType::None),
|
2018-10-05 15:54:12 +00:00
|
|
|
weldEnabled(true),
|
2018-04-15 12:11:51 +00:00
|
|
|
// private
|
2018-08-27 08:50:40 +00:00
|
|
|
m_isResultMeshObsolete(false),
|
2018-04-09 14:24:30 +00:00
|
|
|
m_meshGenerator(nullptr),
|
2018-04-15 12:11:51 +00:00
|
|
|
m_resultMesh(nullptr),
|
2019-01-07 13:03:42 +00:00
|
|
|
m_isMeshGenerationSucceed(true),
|
2018-04-30 11:31:09 +00:00
|
|
|
m_batchChangeRefCount(0),
|
2018-10-26 23:04:45 +00:00
|
|
|
m_currentOutcome(nullptr),
|
2018-08-27 08:50:40 +00:00
|
|
|
m_isTextureObsolete(false),
|
2018-05-07 16:08:19 +00:00
|
|
|
m_textureGenerator(nullptr),
|
2018-08-27 08:50:40 +00:00
|
|
|
m_isPostProcessResultObsolete(false),
|
2018-05-07 16:08:19 +00:00
|
|
|
m_postProcessor(nullptr),
|
2018-10-26 23:04:45 +00:00
|
|
|
m_postProcessedOutcome(new Outcome),
|
2018-05-11 05:27:29 +00:00
|
|
|
m_resultTextureMesh(nullptr),
|
|
|
|
m_textureImageUpdateVersion(0),
|
2018-09-03 07:05:05 +00:00
|
|
|
m_sharedContextWidget(nullptr),
|
2018-09-07 12:51:33 +00:00
|
|
|
m_allPositionRelatedLocksEnabled(true),
|
2019-06-01 13:12:53 +00:00
|
|
|
m_smoothNormal(!Preferences::instance().flatShading()),
|
2018-09-14 09:45:05 +00:00
|
|
|
m_rigGenerator(nullptr),
|
|
|
|
m_resultRigWeightMesh(nullptr),
|
|
|
|
m_resultRigBones(nullptr),
|
|
|
|
m_resultRigWeights(nullptr),
|
2018-09-18 03:17:35 +00:00
|
|
|
m_isRigObsolete(false),
|
2018-10-26 23:04:45 +00:00
|
|
|
m_riggedOutcome(new Outcome),
|
2018-10-02 04:59:30 +00:00
|
|
|
m_posePreviewsGenerator(nullptr),
|
2018-10-09 02:19:12 +00:00
|
|
|
m_currentRigSucceed(false),
|
2018-10-23 14:57:47 +00:00
|
|
|
m_materialPreviewsGenerator(nullptr),
|
|
|
|
m_motionsGenerator(nullptr)
|
2018-04-07 08:44:39 +00:00
|
|
|
{
|
2019-06-01 13:12:53 +00:00
|
|
|
connect(&Preferences::instance(), &Preferences::partColorChanged, this, &Document::applyPreferencePartColorChange);
|
|
|
|
connect(&Preferences::instance(), &Preferences::flatShadingChanged, this, &Document::applyPreferenceFlatShadingChange);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Document::applyPreferencePartColorChange()
|
|
|
|
{
|
2019-06-08 07:57:13 +00:00
|
|
|
regenerateMesh();
|
2019-06-01 13:12:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Document::applyPreferenceFlatShadingChange()
|
|
|
|
{
|
|
|
|
m_smoothNormal = !Preferences::instance().flatShading();
|
|
|
|
regenerateMesh();
|
2018-04-07 08:44:39 +00:00
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
Document::~Document()
|
2018-04-07 08:44:39 +00:00
|
|
|
{
|
|
|
|
delete m_resultMesh;
|
2018-10-26 23:04:45 +00:00
|
|
|
delete m_postProcessedOutcome;
|
2018-05-07 16:08:19 +00:00
|
|
|
delete textureGuideImage;
|
|
|
|
delete textureImage;
|
2018-11-15 22:56:24 +00:00
|
|
|
delete textureColorImage;
|
|
|
|
delete textureNormalImage;
|
|
|
|
delete textureMetalnessRoughnessAmbientOcclusionImage;
|
2018-11-28 03:00:03 +00:00
|
|
|
delete textureMetalnessImage;
|
|
|
|
delete textureRoughnessImage;
|
|
|
|
delete textureAmbientOcclusionImage;
|
2018-05-07 16:08:19 +00:00
|
|
|
delete textureBorderImage;
|
2018-05-10 09:16:22 +00:00
|
|
|
delete m_resultTextureMesh;
|
2018-09-14 09:45:05 +00:00
|
|
|
delete m_resultRigWeightMesh;
|
2018-04-07 08:44:39 +00:00
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::uiReady()
|
2018-04-07 08:44:39 +00:00
|
|
|
{
|
2018-04-10 07:59:20 +00:00
|
|
|
qDebug() << "uiReady";
|
2018-04-07 08:44:39 +00:00
|
|
|
emit editModeChanged();
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::Document::enableAllPositionRelatedLocks()
|
2018-09-03 07:05:05 +00:00
|
|
|
{
|
|
|
|
m_allPositionRelatedLocksEnabled = true;
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::Document::disableAllPositionRelatedLocks()
|
2018-09-03 07:05:05 +00:00
|
|
|
{
|
|
|
|
m_allPositionRelatedLocksEnabled = false;
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::breakEdge(QUuid edgeId)
|
2018-04-12 12:27:21 +00:00
|
|
|
{
|
2018-11-03 08:09:42 +00:00
|
|
|
const SkeletonEdge *edge = findEdge(edgeId);
|
2018-04-12 12:27:21 +00:00
|
|
|
if (nullptr == edge) {
|
|
|
|
qDebug() << "Find edge failed:" << edgeId;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (edge->nodeIds.size() != 2) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
QUuid firstNodeId = edge->nodeIds[0];
|
|
|
|
QUuid secondNodeId = edge->nodeIds[1];
|
2018-11-03 08:09:42 +00:00
|
|
|
const SkeletonNode *firstNode = findNode(firstNodeId);
|
2018-04-12 12:27:21 +00:00
|
|
|
if (nullptr == firstNode) {
|
|
|
|
qDebug() << "Find node failed:" << firstNodeId;
|
|
|
|
return;
|
|
|
|
}
|
2018-11-03 08:09:42 +00:00
|
|
|
const SkeletonNode *secondNode = findNode(secondNodeId);
|
2018-04-12 12:27:21 +00:00
|
|
|
if (nullptr == secondNode) {
|
|
|
|
qDebug() << "Find node failed:" << secondNodeId;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
QVector3D firstOrigin(firstNode->x, firstNode->y, firstNode->z);
|
|
|
|
QVector3D secondOrigin(secondNode->x, secondNode->y, secondNode->z);
|
|
|
|
QVector3D middleOrigin = (firstOrigin + secondOrigin) / 2;
|
|
|
|
float middleRadius = (firstNode->radius + secondNode->radius) / 2;
|
|
|
|
removeEdge(edgeId);
|
2019-03-20 11:04:37 +00:00
|
|
|
QUuid middleNodeId = createNode(QUuid::createUuid(), middleOrigin.x(), middleOrigin.y(), middleOrigin.z(), middleRadius, firstNodeId);
|
2018-04-12 12:27:21 +00:00
|
|
|
if (middleNodeId.isNull()) {
|
|
|
|
qDebug() << "Add middle node failed";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
addEdge(middleNodeId, secondNodeId);
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::removeEdge(QUuid edgeId)
|
2018-04-07 08:44:39 +00:00
|
|
|
{
|
2018-11-03 08:09:42 +00:00
|
|
|
const SkeletonEdge *edge = findEdge(edgeId);
|
2018-04-07 08:44:39 +00:00
|
|
|
if (nullptr == edge) {
|
|
|
|
qDebug() << "Find edge failed:" << edgeId;
|
|
|
|
return;
|
|
|
|
}
|
2018-04-08 23:34:46 +00:00
|
|
|
if (isPartReadonly(edge->partId))
|
2018-04-08 01:30:55 +00:00
|
|
|
return;
|
2018-11-03 08:09:42 +00:00
|
|
|
const SkeletonPart *oldPart = findPart(edge->partId);
|
2018-04-07 08:44:39 +00:00
|
|
|
if (nullptr == oldPart) {
|
|
|
|
qDebug() << "Find part failed:" << edge->partId;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
QString nextPartName = oldPart->name;
|
|
|
|
QUuid oldPartId = oldPart->id;
|
|
|
|
std::vector<std::vector<QUuid>> groups;
|
|
|
|
splitPartByEdge(&groups, edgeId);
|
2019-05-19 03:21:38 +00:00
|
|
|
std::vector<std::pair<QUuid, size_t>> newPartNodeNumMap;
|
2018-04-07 08:44:39 +00:00
|
|
|
for (auto groupIt = groups.begin(); groupIt != groups.end(); groupIt++) {
|
2018-09-18 06:22:29 +00:00
|
|
|
const auto newUuid = QUuid::createUuid();
|
2018-11-03 08:09:42 +00:00
|
|
|
SkeletonPart &part = partMap[newUuid];
|
2018-09-18 06:22:29 +00:00
|
|
|
part.id = newUuid;
|
2018-04-11 09:48:43 +00:00
|
|
|
part.copyAttributes(*oldPart);
|
2018-04-07 08:44:39 +00:00
|
|
|
part.name = nextPartName;
|
|
|
|
for (auto nodeIdIt = (*groupIt).begin(); nodeIdIt != (*groupIt).end(); nodeIdIt++) {
|
|
|
|
auto nodeIt = nodeMap.find(*nodeIdIt);
|
|
|
|
if (nodeIt == nodeMap.end()) {
|
|
|
|
qDebug() << "Find node failed:" << *nodeIdIt;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
nodeIt->second.partId = part.id;
|
|
|
|
part.nodeIds.push_back(nodeIt->first);
|
|
|
|
for (auto edgeIdIt = nodeIt->second.edgeIds.begin(); edgeIdIt != nodeIt->second.edgeIds.end(); edgeIdIt++) {
|
|
|
|
auto edgeIt = edgeMap.find(*edgeIdIt);
|
|
|
|
if (edgeIt == edgeMap.end()) {
|
|
|
|
qDebug() << "Find edge failed:" << *edgeIdIt;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
edgeIt->second.partId = part.id;
|
|
|
|
}
|
|
|
|
}
|
2018-08-27 08:50:40 +00:00
|
|
|
addPartToComponent(part.id, findComponentParentId(part.componentId));
|
2019-05-19 03:21:38 +00:00
|
|
|
newPartNodeNumMap.push_back({part.id, part.nodeIds.size()});
|
2018-04-07 08:44:39 +00:00
|
|
|
emit partAdded(part.id);
|
|
|
|
}
|
|
|
|
for (auto nodeIdIt = edge->nodeIds.begin(); nodeIdIt != edge->nodeIds.end(); nodeIdIt++) {
|
|
|
|
auto nodeIt = nodeMap.find(*nodeIdIt);
|
|
|
|
if (nodeIt == nodeMap.end()) {
|
|
|
|
qDebug() << "Find node failed:" << *nodeIdIt;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
nodeIt->second.edgeIds.erase(std::remove(nodeIt->second.edgeIds.begin(), nodeIt->second.edgeIds.end(), edgeId), nodeIt->second.edgeIds.end());
|
|
|
|
emit nodeOriginChanged(nodeIt->first);
|
|
|
|
}
|
|
|
|
edgeMap.erase(edgeId);
|
|
|
|
emit edgeRemoved(edgeId);
|
2018-08-27 08:50:40 +00:00
|
|
|
removePart(oldPartId);
|
2018-04-07 08:44:39 +00:00
|
|
|
|
2019-05-19 03:21:38 +00:00
|
|
|
if (!newPartNodeNumMap.empty()) {
|
|
|
|
std::sort(newPartNodeNumMap.begin(), newPartNodeNumMap.end(), [&](
|
|
|
|
const std::pair<QUuid, size_t> &first, const std::pair<QUuid, size_t> &second) {
|
|
|
|
return first.second > second.second;
|
|
|
|
});
|
|
|
|
updateLinkedPart(oldPartId, newPartNodeNumMap[0].first);
|
|
|
|
}
|
|
|
|
|
2018-04-07 08:44:39 +00:00
|
|
|
emit skeletonChanged();
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::removeNode(QUuid nodeId)
|
2018-04-07 08:44:39 +00:00
|
|
|
{
|
2018-11-03 08:09:42 +00:00
|
|
|
const SkeletonNode *node = findNode(nodeId);
|
2018-04-07 08:44:39 +00:00
|
|
|
if (nullptr == node) {
|
|
|
|
qDebug() << "Find node failed:" << nodeId;
|
|
|
|
return;
|
|
|
|
}
|
2018-04-08 23:34:46 +00:00
|
|
|
if (isPartReadonly(node->partId))
|
2018-04-08 01:30:55 +00:00
|
|
|
return;
|
2018-11-03 08:09:42 +00:00
|
|
|
const SkeletonPart *oldPart = findPart(node->partId);
|
2018-04-07 08:44:39 +00:00
|
|
|
if (nullptr == oldPart) {
|
|
|
|
qDebug() << "Find part failed:" << node->partId;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
QString nextPartName = oldPart->name;
|
|
|
|
QUuid oldPartId = oldPart->id;
|
|
|
|
std::vector<std::vector<QUuid>> groups;
|
|
|
|
splitPartByNode(&groups, nodeId);
|
2019-05-19 03:21:38 +00:00
|
|
|
std::vector<std::pair<QUuid, size_t>> newPartNodeNumMap;
|
2018-04-07 08:44:39 +00:00
|
|
|
for (auto groupIt = groups.begin(); groupIt != groups.end(); groupIt++) {
|
2018-09-18 06:22:29 +00:00
|
|
|
const auto newUuid = QUuid::createUuid();
|
2018-11-03 08:09:42 +00:00
|
|
|
SkeletonPart &part = partMap[newUuid];
|
2018-09-18 06:22:29 +00:00
|
|
|
part.id = newUuid;
|
2018-04-11 09:48:43 +00:00
|
|
|
part.copyAttributes(*oldPart);
|
2018-04-07 08:44:39 +00:00
|
|
|
part.name = nextPartName;
|
|
|
|
for (auto nodeIdIt = (*groupIt).begin(); nodeIdIt != (*groupIt).end(); nodeIdIt++) {
|
|
|
|
auto nodeIt = nodeMap.find(*nodeIdIt);
|
|
|
|
if (nodeIt == nodeMap.end()) {
|
|
|
|
qDebug() << "Find node failed:" << *nodeIdIt;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
nodeIt->second.partId = part.id;
|
|
|
|
part.nodeIds.push_back(nodeIt->first);
|
|
|
|
for (auto edgeIdIt = nodeIt->second.edgeIds.begin(); edgeIdIt != nodeIt->second.edgeIds.end(); edgeIdIt++) {
|
|
|
|
auto edgeIt = edgeMap.find(*edgeIdIt);
|
|
|
|
if (edgeIt == edgeMap.end()) {
|
|
|
|
qDebug() << "Find edge failed:" << *edgeIdIt;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
edgeIt->second.partId = part.id;
|
|
|
|
}
|
|
|
|
}
|
2018-08-27 08:50:40 +00:00
|
|
|
addPartToComponent(part.id, findComponentParentId(part.componentId));
|
2019-05-19 03:21:38 +00:00
|
|
|
newPartNodeNumMap.push_back({part.id, part.nodeIds.size()});
|
2018-04-07 08:44:39 +00:00
|
|
|
emit partAdded(part.id);
|
|
|
|
}
|
|
|
|
for (auto edgeIdIt = node->edgeIds.begin(); edgeIdIt != node->edgeIds.end(); edgeIdIt++) {
|
|
|
|
auto edgeIt = edgeMap.find(*edgeIdIt);
|
|
|
|
if (edgeIt == edgeMap.end()) {
|
|
|
|
qDebug() << "Find edge failed:" << *edgeIdIt;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
QUuid neighborId = edgeIt->second.neighborOf(nodeId);
|
|
|
|
auto nodeIt = nodeMap.find(neighborId);
|
|
|
|
if (nodeIt == nodeMap.end()) {
|
|
|
|
qDebug() << "Find node failed:" << neighborId;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
nodeIt->second.edgeIds.erase(std::remove(nodeIt->second.edgeIds.begin(), nodeIt->second.edgeIds.end(), *edgeIdIt), nodeIt->second.edgeIds.end());
|
|
|
|
edgeMap.erase(*edgeIdIt);
|
|
|
|
emit edgeRemoved(*edgeIdIt);
|
|
|
|
}
|
|
|
|
nodeMap.erase(nodeId);
|
|
|
|
emit nodeRemoved(nodeId);
|
2018-08-27 08:50:40 +00:00
|
|
|
removePart(oldPartId);
|
2018-04-07 08:44:39 +00:00
|
|
|
|
2019-05-19 03:21:38 +00:00
|
|
|
if (!newPartNodeNumMap.empty()) {
|
|
|
|
std::sort(newPartNodeNumMap.begin(), newPartNodeNumMap.end(), [&](
|
|
|
|
const std::pair<QUuid, size_t> &first, const std::pair<QUuid, size_t> &second) {
|
|
|
|
return first.second > second.second;
|
|
|
|
});
|
|
|
|
updateLinkedPart(oldPartId, newPartNodeNumMap[0].first);
|
|
|
|
}
|
|
|
|
|
2018-04-07 08:44:39 +00:00
|
|
|
emit skeletonChanged();
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::addNode(float x, float y, float z, float radius, QUuid fromNodeId)
|
2018-04-12 12:27:21 +00:00
|
|
|
{
|
2019-03-20 11:04:37 +00:00
|
|
|
createNode(QUuid::createUuid(), x, y, z, radius, fromNodeId);
|
2018-04-12 12:27:21 +00:00
|
|
|
}
|
|
|
|
|
2019-03-20 11:04:37 +00:00
|
|
|
void Document::addNodeWithId(QUuid nodeId, float x, float y, float z, float radius, QUuid fromNodeId)
|
|
|
|
{
|
|
|
|
createNode(nodeId, x, y, z, radius, fromNodeId);
|
|
|
|
}
|
|
|
|
|
|
|
|
QUuid Document::createNode(QUuid nodeId, float x, float y, float z, float radius, QUuid fromNodeId)
|
2018-04-07 08:44:39 +00:00
|
|
|
{
|
|
|
|
QUuid partId;
|
2018-11-03 08:09:42 +00:00
|
|
|
const SkeletonNode *fromNode = nullptr;
|
2018-04-07 08:44:39 +00:00
|
|
|
bool newPartAdded = false;
|
|
|
|
if (fromNodeId.isNull()) {
|
2018-09-18 06:22:29 +00:00
|
|
|
const auto newUuid = QUuid::createUuid();
|
2018-11-03 08:09:42 +00:00
|
|
|
SkeletonPart &part = partMap[newUuid];
|
2018-09-18 06:22:29 +00:00
|
|
|
part.id = newUuid;
|
2018-04-07 08:44:39 +00:00
|
|
|
partId = part.id;
|
|
|
|
emit partAdded(partId);
|
|
|
|
newPartAdded = true;
|
|
|
|
} else {
|
|
|
|
fromNode = findNode(fromNodeId);
|
|
|
|
if (nullptr == fromNode) {
|
|
|
|
qDebug() << "Find node failed:" << fromNodeId;
|
2018-04-12 12:27:21 +00:00
|
|
|
return QUuid();
|
2018-04-07 08:44:39 +00:00
|
|
|
}
|
|
|
|
partId = fromNode->partId;
|
2018-04-08 23:34:46 +00:00
|
|
|
if (isPartReadonly(partId))
|
2018-04-12 12:27:21 +00:00
|
|
|
return QUuid();
|
2018-09-23 02:41:47 +00:00
|
|
|
auto part = partMap.find(partId);
|
|
|
|
if (part != partMap.end())
|
|
|
|
part->second.dirty = true;
|
2018-04-07 08:44:39 +00:00
|
|
|
}
|
2019-03-20 11:04:37 +00:00
|
|
|
SkeletonNode node(nodeId);
|
2018-04-07 08:44:39 +00:00
|
|
|
node.partId = partId;
|
2018-04-23 00:10:01 +00:00
|
|
|
node.setRadius(radius);
|
2018-04-07 08:44:39 +00:00
|
|
|
node.x = x;
|
|
|
|
node.y = y;
|
|
|
|
node.z = z;
|
|
|
|
nodeMap[node.id] = node;
|
|
|
|
partMap[partId].nodeIds.push_back(node.id);
|
|
|
|
|
|
|
|
emit nodeAdded(node.id);
|
|
|
|
|
|
|
|
if (nullptr != fromNode) {
|
2018-11-03 08:09:42 +00:00
|
|
|
SkeletonEdge edge;
|
2018-04-07 08:44:39 +00:00
|
|
|
edge.partId = partId;
|
|
|
|
edge.nodeIds.push_back(fromNode->id);
|
|
|
|
edge.nodeIds.push_back(node.id);
|
|
|
|
edgeMap[edge.id] = edge;
|
|
|
|
|
|
|
|
nodeMap[node.id].edgeIds.push_back(edge.id);
|
|
|
|
nodeMap[fromNode->id].edgeIds.push_back(edge.id);
|
|
|
|
|
|
|
|
emit edgeAdded(edge.id);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (newPartAdded)
|
2018-08-27 08:50:40 +00:00
|
|
|
addPartToComponent(partId, m_currentCanvasComponentId);
|
2018-04-07 08:44:39 +00:00
|
|
|
|
|
|
|
emit skeletonChanged();
|
2018-04-12 12:27:21 +00:00
|
|
|
|
|
|
|
return node.id;
|
2018-04-07 08:44:39 +00:00
|
|
|
}
|
|
|
|
|
2019-06-19 12:57:38 +00:00
|
|
|
void Document::addPose(QUuid poseId, QString name, std::vector<std::pair<std::map<QString, QString>, std::map<QString, std::map<QString, QString>>>> frames, QUuid turnaroundImageId, float yTranslationScale)
|
2018-09-21 07:10:18 +00:00
|
|
|
{
|
2018-11-09 15:07:26 +00:00
|
|
|
QUuid newPoseId = poseId;
|
2018-09-21 07:10:18 +00:00
|
|
|
auto &pose = poseMap[newPoseId];
|
|
|
|
pose.id = newPoseId;
|
|
|
|
|
|
|
|
pose.name = name;
|
2018-11-09 03:20:48 +00:00
|
|
|
pose.frames = frames;
|
|
|
|
pose.turnaroundImageId = turnaroundImageId;
|
2019-06-19 12:57:38 +00:00
|
|
|
pose.yTranslationScale = yTranslationScale;
|
2018-09-21 07:10:18 +00:00
|
|
|
pose.dirty = true;
|
|
|
|
|
|
|
|
poseIdList.push_back(newPoseId);
|
|
|
|
|
2018-10-23 14:57:47 +00:00
|
|
|
emit posesChanged();
|
2018-09-21 07:10:18 +00:00
|
|
|
emit poseAdded(newPoseId);
|
|
|
|
emit poseListChanged();
|
|
|
|
emit optionsChanged();
|
|
|
|
}
|
|
|
|
|
2018-11-09 15:07:26 +00:00
|
|
|
void Document::addMotion(QUuid motionId, QString name, std::vector<MotionClip> clips)
|
2018-10-02 04:59:30 +00:00
|
|
|
{
|
2018-11-09 15:07:26 +00:00
|
|
|
QUuid newMotionId = motionId;
|
2018-10-02 04:59:30 +00:00
|
|
|
auto &motion = motionMap[newMotionId];
|
|
|
|
motion.id = newMotionId;
|
|
|
|
|
|
|
|
motion.name = name;
|
2018-10-23 14:57:47 +00:00
|
|
|
motion.clips = clips;
|
2018-10-02 04:59:30 +00:00
|
|
|
motion.dirty = true;
|
|
|
|
|
|
|
|
motionIdList.push_back(newMotionId);
|
|
|
|
|
2018-10-23 14:57:47 +00:00
|
|
|
emit motionsChanged();
|
2018-10-02 04:59:30 +00:00
|
|
|
emit motionAdded(newMotionId);
|
|
|
|
emit motionListChanged();
|
|
|
|
emit optionsChanged();
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::removeMotion(QUuid motionId)
|
2018-10-02 04:59:30 +00:00
|
|
|
{
|
|
|
|
auto findMotionResult = motionMap.find(motionId);
|
|
|
|
if (findMotionResult == motionMap.end()) {
|
|
|
|
qDebug() << "Remove a none exist motion:" << motionId;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
motionIdList.erase(std::remove(motionIdList.begin(), motionIdList.end(), motionId), motionIdList.end());
|
|
|
|
motionMap.erase(findMotionResult);
|
2018-10-23 14:57:47 +00:00
|
|
|
emit motionsChanged();
|
2018-10-02 04:59:30 +00:00
|
|
|
emit motionListChanged();
|
|
|
|
emit motionRemoved(motionId);
|
|
|
|
emit optionsChanged();
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::setMotionClips(QUuid motionId, std::vector<MotionClip> clips)
|
2018-10-02 04:59:30 +00:00
|
|
|
{
|
|
|
|
auto findMotionResult = motionMap.find(motionId);
|
|
|
|
if (findMotionResult == motionMap.end()) {
|
|
|
|
qDebug() << "Find motion failed:" << motionId;
|
|
|
|
return;
|
|
|
|
}
|
2018-10-23 14:57:47 +00:00
|
|
|
findMotionResult->second.clips = clips;
|
2018-10-02 04:59:30 +00:00
|
|
|
findMotionResult->second.dirty = true;
|
2018-10-23 14:57:47 +00:00
|
|
|
emit motionsChanged();
|
|
|
|
emit motionClipsChanged(motionId);
|
2018-10-02 04:59:30 +00:00
|
|
|
emit optionsChanged();
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::renameMotion(QUuid motionId, QString name)
|
2018-10-02 04:59:30 +00:00
|
|
|
{
|
|
|
|
auto findMotionResult = motionMap.find(motionId);
|
|
|
|
if (findMotionResult == motionMap.end()) {
|
|
|
|
qDebug() << "Find motion failed:" << motionId;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (findMotionResult->second.name == name)
|
|
|
|
return;
|
|
|
|
|
|
|
|
findMotionResult->second.name = name;
|
|
|
|
emit motionNameChanged(motionId);
|
|
|
|
emit optionsChanged();
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::removePose(QUuid poseId)
|
2018-09-21 07:10:18 +00:00
|
|
|
{
|
|
|
|
auto findPoseResult = poseMap.find(poseId);
|
|
|
|
if (findPoseResult == poseMap.end()) {
|
|
|
|
qDebug() << "Remove a none exist pose:" << poseId;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
poseIdList.erase(std::remove(poseIdList.begin(), poseIdList.end(), poseId), poseIdList.end());
|
|
|
|
poseMap.erase(findPoseResult);
|
2018-10-23 14:57:47 +00:00
|
|
|
emit posesChanged();
|
2018-09-21 07:10:18 +00:00
|
|
|
emit poseListChanged();
|
|
|
|
emit poseRemoved(poseId);
|
|
|
|
emit optionsChanged();
|
|
|
|
}
|
|
|
|
|
2018-11-09 03:20:48 +00:00
|
|
|
void Document::setPoseFrames(QUuid poseId, std::vector<std::pair<std::map<QString, QString>, std::map<QString, std::map<QString, QString>>>> frames)
|
2018-09-21 07:10:18 +00:00
|
|
|
{
|
|
|
|
auto findPoseResult = poseMap.find(poseId);
|
|
|
|
if (findPoseResult == poseMap.end()) {
|
|
|
|
qDebug() << "Find pose failed:" << poseId;
|
|
|
|
return;
|
|
|
|
}
|
2018-11-09 03:20:48 +00:00
|
|
|
findPoseResult->second.frames = frames;
|
2018-09-21 07:10:18 +00:00
|
|
|
findPoseResult->second.dirty = true;
|
2018-10-23 14:57:47 +00:00
|
|
|
emit posesChanged();
|
2018-11-09 03:20:48 +00:00
|
|
|
emit poseFramesChanged(poseId);
|
2018-09-21 07:10:18 +00:00
|
|
|
emit optionsChanged();
|
|
|
|
}
|
|
|
|
|
2018-11-09 03:20:48 +00:00
|
|
|
void Document::setPoseTurnaroundImageId(QUuid poseId, QUuid imageId)
|
2018-11-05 15:47:21 +00:00
|
|
|
{
|
|
|
|
auto findPoseResult = poseMap.find(poseId);
|
|
|
|
if (findPoseResult == poseMap.end()) {
|
|
|
|
qDebug() << "Find pose failed:" << poseId;
|
|
|
|
return;
|
|
|
|
}
|
2018-11-09 03:20:48 +00:00
|
|
|
if (findPoseResult->second.turnaroundImageId == imageId)
|
|
|
|
return;
|
|
|
|
findPoseResult->second.turnaroundImageId = imageId;
|
2018-11-05 15:47:21 +00:00
|
|
|
findPoseResult->second.dirty = true;
|
2018-11-09 03:20:48 +00:00
|
|
|
emit poseTurnaroundImageIdChanged(poseId);
|
2018-11-05 15:47:21 +00:00
|
|
|
emit optionsChanged();
|
|
|
|
}
|
|
|
|
|
2019-06-19 12:57:38 +00:00
|
|
|
void Document::setPoseYtranslationScale(QUuid poseId, float scale)
|
|
|
|
{
|
|
|
|
auto findPoseResult = poseMap.find(poseId);
|
|
|
|
if (findPoseResult == poseMap.end()) {
|
|
|
|
qDebug() << "Find pose failed:" << poseId;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
findPoseResult->second.yTranslationScale = scale;
|
|
|
|
findPoseResult->second.dirty = true;
|
|
|
|
emit poseYtranslationScaleChanged(poseId);
|
|
|
|
emit optionsChanged();
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::renamePose(QUuid poseId, QString name)
|
2018-09-21 07:10:18 +00:00
|
|
|
{
|
|
|
|
auto findPoseResult = poseMap.find(poseId);
|
|
|
|
if (findPoseResult == poseMap.end()) {
|
|
|
|
qDebug() << "Find pose failed:" << poseId;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (findPoseResult->second.name == name)
|
|
|
|
return;
|
|
|
|
|
|
|
|
findPoseResult->second.name = name;
|
|
|
|
emit poseNameChanged(poseId);
|
|
|
|
emit optionsChanged();
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
bool Document::originSettled() const
|
2018-04-15 12:11:51 +00:00
|
|
|
{
|
2018-08-27 08:50:40 +00:00
|
|
|
return !qFuzzyIsNull(originX) && !qFuzzyIsNull(originY) && !qFuzzyIsNull(originZ);
|
2018-04-15 12:11:51 +00:00
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::addEdge(QUuid fromNodeId, QUuid toNodeId)
|
2018-04-07 08:44:39 +00:00
|
|
|
{
|
2018-04-12 12:46:13 +00:00
|
|
|
if (findEdgeByNodes(fromNodeId, toNodeId)) {
|
|
|
|
qDebug() << "Add edge but edge already existed:" << fromNodeId << toNodeId;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-11-03 08:09:42 +00:00
|
|
|
const SkeletonNode *fromNode = nullptr;
|
|
|
|
const SkeletonNode *toNode = nullptr;
|
2018-04-07 08:44:39 +00:00
|
|
|
bool toPartRemoved = false;
|
|
|
|
|
|
|
|
fromNode = findNode(fromNodeId);
|
|
|
|
if (nullptr == fromNode) {
|
|
|
|
qDebug() << "Find node failed:" << fromNodeId;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-08 23:34:46 +00:00
|
|
|
if (isPartReadonly(fromNode->partId))
|
2018-04-08 01:30:55 +00:00
|
|
|
return;
|
|
|
|
|
2018-04-07 08:44:39 +00:00
|
|
|
toNode = findNode(toNodeId);
|
|
|
|
if (nullptr == toNode) {
|
|
|
|
qDebug() << "Find node failed:" << toNodeId;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-08 23:34:46 +00:00
|
|
|
if (isPartReadonly(toNode->partId))
|
2018-04-08 01:30:55 +00:00
|
|
|
return;
|
|
|
|
|
2018-04-07 08:44:39 +00:00
|
|
|
QUuid toPartId = toNode->partId;
|
|
|
|
|
|
|
|
auto fromPart = partMap.find(fromNode->partId);
|
|
|
|
if (fromPart == partMap.end()) {
|
|
|
|
qDebug() << "Find part failed:" << fromNode->partId;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-08-27 08:50:40 +00:00
|
|
|
fromPart->second.dirty = true;
|
|
|
|
|
2018-04-07 08:44:39 +00:00
|
|
|
if (fromNode->partId != toNode->partId) {
|
|
|
|
toPartRemoved = true;
|
|
|
|
std::vector<QUuid> toGroup;
|
|
|
|
std::set<QUuid> visitMap;
|
|
|
|
joinNodeAndNeiborsToGroup(&toGroup, toNodeId, &visitMap);
|
|
|
|
for (auto nodeIdIt = toGroup.begin(); nodeIdIt != toGroup.end(); nodeIdIt++) {
|
|
|
|
auto nodeIt = nodeMap.find(*nodeIdIt);
|
|
|
|
if (nodeIt == nodeMap.end()) {
|
|
|
|
qDebug() << "Find node failed:" << *nodeIdIt;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
nodeIt->second.partId = fromNode->partId;
|
|
|
|
fromPart->second.nodeIds.push_back(nodeIt->first);
|
|
|
|
for (auto edgeIdIt = nodeIt->second.edgeIds.begin(); edgeIdIt != nodeIt->second.edgeIds.end(); edgeIdIt++) {
|
|
|
|
auto edgeIt = edgeMap.find(*edgeIdIt);
|
|
|
|
if (edgeIt == edgeMap.end()) {
|
|
|
|
qDebug() << "Find edge failed:" << *edgeIdIt;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
edgeIt->second.partId = fromNode->partId;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-03 08:09:42 +00:00
|
|
|
SkeletonEdge edge;
|
2018-04-07 08:44:39 +00:00
|
|
|
edge.partId = fromNode->partId;
|
|
|
|
edge.nodeIds.push_back(fromNode->id);
|
|
|
|
edge.nodeIds.push_back(toNodeId);
|
|
|
|
edgeMap[edge.id] = edge;
|
|
|
|
|
|
|
|
nodeMap[toNodeId].edgeIds.push_back(edge.id);
|
|
|
|
nodeMap[fromNode->id].edgeIds.push_back(edge.id);
|
|
|
|
|
|
|
|
emit edgeAdded(edge.id);
|
|
|
|
|
|
|
|
if (toPartRemoved) {
|
2019-05-19 03:21:38 +00:00
|
|
|
updateLinkedPart(toPartId, fromNode->partId);
|
2018-08-27 08:50:40 +00:00
|
|
|
removePart(toPartId);
|
2018-04-07 08:44:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
emit skeletonChanged();
|
|
|
|
}
|
|
|
|
|
2019-05-19 03:21:38 +00:00
|
|
|
void Document::updateLinkedPart(QUuid oldPartId, QUuid newPartId)
|
|
|
|
{
|
|
|
|
for (auto &partIt: partMap) {
|
|
|
|
if (partIt.second.cutFaceLinkedId == oldPartId) {
|
|
|
|
partIt.second.dirty = true;
|
|
|
|
partIt.second.setCutFaceLinkedId(newPartId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
const Component *Document::findComponent(QUuid componentId) const
|
2018-08-27 08:50:40 +00:00
|
|
|
{
|
|
|
|
if (componentId.isNull())
|
|
|
|
return &rootComponent;
|
|
|
|
auto it = componentMap.find(componentId);
|
|
|
|
if (it == componentMap.end())
|
|
|
|
return nullptr;
|
|
|
|
return &it->second;
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
const Pose *Document::findPose(QUuid poseId) const
|
2018-09-21 07:10:18 +00:00
|
|
|
{
|
|
|
|
auto it = poseMap.find(poseId);
|
|
|
|
if (it == poseMap.end())
|
|
|
|
return nullptr;
|
|
|
|
return &it->second;
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
const Material *Document::findMaterial(QUuid materialId) const
|
2018-10-09 02:19:12 +00:00
|
|
|
{
|
|
|
|
auto it = materialMap.find(materialId);
|
|
|
|
if (it == materialMap.end())
|
|
|
|
return nullptr;
|
|
|
|
return &it->second;
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
const Motion *Document::findMotion(QUuid motionId) const
|
2018-10-02 04:59:30 +00:00
|
|
|
{
|
|
|
|
auto it = motionMap.find(motionId);
|
|
|
|
if (it == motionMap.end())
|
|
|
|
return nullptr;
|
|
|
|
return &it->second;
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::scaleNodeByAddRadius(QUuid nodeId, float amount)
|
2018-04-07 08:44:39 +00:00
|
|
|
{
|
|
|
|
auto it = nodeMap.find(nodeId);
|
|
|
|
if (it == nodeMap.end()) {
|
|
|
|
qDebug() << "Find node failed:" << nodeId;
|
|
|
|
return;
|
|
|
|
}
|
2018-04-08 23:34:46 +00:00
|
|
|
if (isPartReadonly(it->second.partId))
|
2018-04-08 01:30:55 +00:00
|
|
|
return;
|
2018-10-11 02:49:44 +00:00
|
|
|
if (radiusLocked)
|
|
|
|
return;
|
|
|
|
it->second.setRadius(it->second.radius + amount);
|
2018-08-27 08:50:40 +00:00
|
|
|
auto part = partMap.find(it->second.partId);
|
|
|
|
if (part != partMap.end())
|
|
|
|
part->second.dirty = true;
|
2018-04-07 08:44:39 +00:00
|
|
|
emit nodeRadiusChanged(nodeId);
|
|
|
|
emit skeletonChanged();
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
bool Document::isPartReadonly(QUuid partId) const
|
2018-04-08 01:30:55 +00:00
|
|
|
{
|
2018-11-03 08:09:42 +00:00
|
|
|
const SkeletonPart *part = findPart(partId);
|
2018-04-08 01:30:55 +00:00
|
|
|
if (nullptr == part) {
|
|
|
|
qDebug() << "Find part failed:" << partId;
|
|
|
|
return true;
|
|
|
|
}
|
2018-04-08 23:34:46 +00:00
|
|
|
return part->locked || !part->visible;
|
2018-04-08 01:30:55 +00:00
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::moveNodeBy(QUuid nodeId, float x, float y, float z)
|
2018-04-07 08:44:39 +00:00
|
|
|
{
|
|
|
|
auto it = nodeMap.find(nodeId);
|
|
|
|
if (it == nodeMap.end()) {
|
|
|
|
qDebug() << "Find node failed:" << nodeId;
|
|
|
|
return;
|
|
|
|
}
|
2018-09-03 07:05:05 +00:00
|
|
|
if (m_allPositionRelatedLocksEnabled && isPartReadonly(it->second.partId))
|
2018-04-08 01:30:55 +00:00
|
|
|
return;
|
2018-10-11 02:49:44 +00:00
|
|
|
bool changed = false;
|
|
|
|
if (!(m_allPositionRelatedLocksEnabled && xlocked)) {
|
2018-04-16 22:54:41 +00:00
|
|
|
it->second.x += x;
|
2018-10-11 02:49:44 +00:00
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
if (!(m_allPositionRelatedLocksEnabled && ylocked)) {
|
2018-04-16 22:54:41 +00:00
|
|
|
it->second.y += y;
|
2018-10-11 02:49:44 +00:00
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
if (!(m_allPositionRelatedLocksEnabled && zlocked)) {
|
2018-04-16 22:54:41 +00:00
|
|
|
it->second.z += z;
|
2018-10-11 02:49:44 +00:00
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
if (!changed)
|
|
|
|
return;
|
2018-08-27 08:50:40 +00:00
|
|
|
auto part = partMap.find(it->second.partId);
|
|
|
|
if (part != partMap.end())
|
|
|
|
part->second.dirty = true;
|
2018-04-07 08:44:39 +00:00
|
|
|
emit nodeOriginChanged(nodeId);
|
|
|
|
emit skeletonChanged();
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::moveOriginBy(float x, float y, float z)
|
2018-04-15 12:11:51 +00:00
|
|
|
{
|
2018-09-03 07:05:05 +00:00
|
|
|
if (!(m_allPositionRelatedLocksEnabled && xlocked))
|
2018-04-16 22:54:41 +00:00
|
|
|
originX += x;
|
2018-09-03 07:05:05 +00:00
|
|
|
if (!(m_allPositionRelatedLocksEnabled && ylocked))
|
2018-04-16 22:54:41 +00:00
|
|
|
originY += y;
|
2018-09-03 07:05:05 +00:00
|
|
|
if (!(m_allPositionRelatedLocksEnabled && zlocked))
|
2018-04-16 22:54:41 +00:00
|
|
|
originZ += z;
|
2018-09-02 02:24:39 +00:00
|
|
|
markAllDirty();
|
2018-04-15 12:11:51 +00:00
|
|
|
emit originChanged();
|
|
|
|
emit skeletonChanged();
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::setNodeOrigin(QUuid nodeId, float x, float y, float z)
|
2018-04-07 08:44:39 +00:00
|
|
|
{
|
|
|
|
auto it = nodeMap.find(nodeId);
|
|
|
|
if (it == nodeMap.end()) {
|
|
|
|
qDebug() << "Find node failed:" << nodeId;
|
|
|
|
return;
|
|
|
|
}
|
2018-09-03 07:05:05 +00:00
|
|
|
if ((m_allPositionRelatedLocksEnabled && isPartReadonly(it->second.partId)))
|
2018-04-08 01:30:55 +00:00
|
|
|
return;
|
2018-09-03 07:05:05 +00:00
|
|
|
if (!(m_allPositionRelatedLocksEnabled && xlocked))
|
2018-04-16 22:54:41 +00:00
|
|
|
it->second.x = x;
|
2018-09-03 07:05:05 +00:00
|
|
|
if (!(m_allPositionRelatedLocksEnabled && ylocked))
|
2018-04-16 22:54:41 +00:00
|
|
|
it->second.y = y;
|
2018-09-03 07:05:05 +00:00
|
|
|
if (!(m_allPositionRelatedLocksEnabled && zlocked))
|
2018-04-16 22:54:41 +00:00
|
|
|
it->second.z = z;
|
2018-08-27 08:50:40 +00:00
|
|
|
auto part = partMap.find(it->second.partId);
|
|
|
|
if (part != partMap.end())
|
|
|
|
part->second.dirty = true;
|
2018-04-07 08:44:39 +00:00
|
|
|
emit nodeOriginChanged(nodeId);
|
|
|
|
emit skeletonChanged();
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::setNodeRadius(QUuid nodeId, float radius)
|
2018-04-07 08:44:39 +00:00
|
|
|
{
|
|
|
|
auto it = nodeMap.find(nodeId);
|
|
|
|
if (it == nodeMap.end()) {
|
|
|
|
qDebug() << "Find node failed:" << nodeId;
|
|
|
|
return;
|
|
|
|
}
|
2018-04-08 23:34:46 +00:00
|
|
|
if (isPartReadonly(it->second.partId))
|
2018-04-08 01:30:55 +00:00
|
|
|
return;
|
2018-09-08 04:20:31 +00:00
|
|
|
if (!radiusLocked)
|
|
|
|
it->second.setRadius(radius);
|
2018-08-27 08:50:40 +00:00
|
|
|
auto part = partMap.find(it->second.partId);
|
|
|
|
if (part != partMap.end())
|
|
|
|
part->second.dirty = true;
|
2018-04-07 08:44:39 +00:00
|
|
|
emit nodeRadiusChanged(nodeId);
|
|
|
|
emit skeletonChanged();
|
2018-06-21 08:24:18 +00:00
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::switchNodeXZ(QUuid nodeId)
|
2018-06-21 08:24:18 +00:00
|
|
|
{
|
|
|
|
auto it = nodeMap.find(nodeId);
|
|
|
|
if (it == nodeMap.end()) {
|
|
|
|
qDebug() << "Find node failed:" << nodeId;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (isPartReadonly(it->second.partId))
|
|
|
|
return;
|
|
|
|
std::swap(it->second.x, it->second.z);
|
2018-08-27 08:50:40 +00:00
|
|
|
auto part = partMap.find(it->second.partId);
|
|
|
|
if (part != partMap.end())
|
|
|
|
part->second.dirty = true;
|
2018-06-21 08:24:18 +00:00
|
|
|
emit nodeOriginChanged(nodeId);
|
|
|
|
emit skeletonChanged();
|
2018-04-07 08:44:39 +00:00
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::setNodeBoneMark(QUuid nodeId, BoneMark mark)
|
2018-09-14 09:45:05 +00:00
|
|
|
{
|
|
|
|
auto it = nodeMap.find(nodeId);
|
|
|
|
if (it == nodeMap.end()) {
|
|
|
|
qDebug() << "Find node failed:" << nodeId;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (isPartReadonly(it->second.partId))
|
|
|
|
return;
|
|
|
|
if (it->second.boneMark == mark)
|
|
|
|
return;
|
|
|
|
it->second.boneMark = mark;
|
|
|
|
auto part = partMap.find(it->second.partId);
|
|
|
|
if (part != partMap.end())
|
|
|
|
part->second.dirty = true;
|
|
|
|
emit nodeBoneMarkChanged(nodeId);
|
|
|
|
emit skeletonChanged();
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::updateTurnaround(const QImage &image)
|
2018-04-07 08:44:39 +00:00
|
|
|
{
|
|
|
|
turnaround = image;
|
2018-11-11 13:08:13 +00:00
|
|
|
turnaroundPngByteArray.clear();
|
|
|
|
QBuffer pngBuffer(&turnaroundPngByteArray);
|
|
|
|
pngBuffer.open(QIODevice::WriteOnly);
|
|
|
|
turnaround.save(&pngBuffer, "PNG");
|
2018-04-07 08:44:39 +00:00
|
|
|
emit turnaroundChanged();
|
|
|
|
}
|
|
|
|
|
2018-11-03 08:09:42 +00:00
|
|
|
void Document::setEditMode(SkeletonDocumentEditMode mode)
|
2018-04-07 08:44:39 +00:00
|
|
|
{
|
|
|
|
if (editMode == mode)
|
|
|
|
return;
|
|
|
|
|
|
|
|
editMode = mode;
|
|
|
|
emit editModeChanged();
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::joinNodeAndNeiborsToGroup(std::vector<QUuid> *group, QUuid nodeId, std::set<QUuid> *visitMap, QUuid noUseEdgeId)
|
2018-04-07 08:44:39 +00:00
|
|
|
{
|
|
|
|
if (nodeId.isNull() || visitMap->find(nodeId) != visitMap->end())
|
|
|
|
return;
|
2018-11-03 08:09:42 +00:00
|
|
|
const SkeletonNode *node = findNode(nodeId);
|
2018-04-07 08:44:39 +00:00
|
|
|
if (nullptr == node) {
|
|
|
|
qDebug() << "Find node failed:" << nodeId;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
visitMap->insert(nodeId);
|
|
|
|
group->push_back(nodeId);
|
|
|
|
for (auto edgeIt = node->edgeIds.begin(); edgeIt != node->edgeIds.end(); edgeIt++) {
|
|
|
|
if (noUseEdgeId == *edgeIt)
|
|
|
|
continue;
|
2018-11-03 08:09:42 +00:00
|
|
|
const SkeletonEdge *edge = findEdge(*edgeIt);
|
2018-04-07 08:44:39 +00:00
|
|
|
if (nullptr == edge) {
|
|
|
|
qDebug() << "Find edge failed:" << *edgeIt;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
for (auto nodeIt = edge->nodeIds.begin(); nodeIt != edge->nodeIds.end(); nodeIt++) {
|
|
|
|
joinNodeAndNeiborsToGroup(group, *nodeIt, visitMap, noUseEdgeId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::splitPartByNode(std::vector<std::vector<QUuid>> *groups, QUuid nodeId)
|
2018-04-07 08:44:39 +00:00
|
|
|
{
|
2018-11-03 08:09:42 +00:00
|
|
|
const SkeletonNode *node = findNode(nodeId);
|
2018-04-07 08:44:39 +00:00
|
|
|
std::set<QUuid> visitMap;
|
|
|
|
for (auto edgeIt = node->edgeIds.begin(); edgeIt != node->edgeIds.end(); edgeIt++) {
|
|
|
|
std::vector<QUuid> group;
|
2018-11-03 08:09:42 +00:00
|
|
|
const SkeletonEdge *edge = findEdge(*edgeIt);
|
2018-04-07 08:44:39 +00:00
|
|
|
if (nullptr == edge) {
|
|
|
|
qDebug() << "Find edge failed:" << *edgeIt;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
joinNodeAndNeiborsToGroup(&group, edge->neighborOf(nodeId), &visitMap, *edgeIt);
|
|
|
|
if (!group.empty())
|
|
|
|
groups->push_back(group);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::splitPartByEdge(std::vector<std::vector<QUuid>> *groups, QUuid edgeId)
|
2018-04-07 08:44:39 +00:00
|
|
|
{
|
2018-11-03 08:09:42 +00:00
|
|
|
const SkeletonEdge *edge = findEdge(edgeId);
|
2018-04-07 08:44:39 +00:00
|
|
|
if (nullptr == edge) {
|
|
|
|
qDebug() << "Find edge failed:" << edgeId;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
std::set<QUuid> visitMap;
|
|
|
|
for (auto nodeIt = edge->nodeIds.begin(); nodeIt != edge->nodeIds.end(); nodeIt++) {
|
|
|
|
std::vector<QUuid> group;
|
|
|
|
joinNodeAndNeiborsToGroup(&group, *nodeIt, &visitMap, edgeId);
|
|
|
|
if (!group.empty())
|
|
|
|
groups->push_back(group);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::resetDirtyFlags()
|
2018-08-27 08:50:40 +00:00
|
|
|
{
|
|
|
|
for (auto &part: partMap) {
|
|
|
|
part.second.dirty = false;
|
|
|
|
}
|
|
|
|
for (auto &component: componentMap) {
|
|
|
|
component.second.dirty = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::markAllDirty()
|
2018-08-27 08:50:40 +00:00
|
|
|
{
|
|
|
|
for (auto &part: partMap) {
|
|
|
|
part.second.dirty = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::toSnapshot(Snapshot *snapshot, const std::set<QUuid> &limitNodeIds,
|
|
|
|
DocumentToSnapshotFor forWhat,
|
2018-10-09 02:19:12 +00:00
|
|
|
const std::set<QUuid> &limitPoseIds,
|
|
|
|
const std::set<QUuid> &limitMotionIds,
|
|
|
|
const std::set<QUuid> &limitMaterialIds) const
|
2018-04-07 08:44:39 +00:00
|
|
|
{
|
2018-10-25 00:19:38 +00:00
|
|
|
if (DocumentToSnapshotFor::Document == forWhat ||
|
|
|
|
DocumentToSnapshotFor::Nodes == forWhat) {
|
2018-09-21 07:10:18 +00:00
|
|
|
std::set<QUuid> limitPartIds;
|
|
|
|
std::set<QUuid> limitComponentIds;
|
|
|
|
for (const auto &nodeId: limitNodeIds) {
|
2018-11-03 08:09:42 +00:00
|
|
|
const SkeletonNode *node = findNode(nodeId);
|
2018-09-21 07:10:18 +00:00
|
|
|
if (!node)
|
|
|
|
continue;
|
2018-11-03 08:09:42 +00:00
|
|
|
const SkeletonPart *part = findPart(node->partId);
|
2018-09-21 07:10:18 +00:00
|
|
|
if (!part)
|
|
|
|
continue;
|
|
|
|
limitPartIds.insert(node->partId);
|
2018-10-25 00:19:38 +00:00
|
|
|
const Component *component = findComponent(part->componentId);
|
2018-09-21 07:10:18 +00:00
|
|
|
while (component) {
|
|
|
|
limitComponentIds.insert(component->id);
|
|
|
|
if (component->id.isNull())
|
|
|
|
break;
|
|
|
|
component = findComponent(component->parentId);
|
|
|
|
}
|
2018-08-27 08:50:40 +00:00
|
|
|
}
|
2018-09-21 07:10:18 +00:00
|
|
|
for (const auto &partIt : partMap) {
|
|
|
|
if (!limitPartIds.empty() && limitPartIds.find(partIt.first) == limitPartIds.end())
|
|
|
|
continue;
|
|
|
|
std::map<QString, QString> part;
|
|
|
|
part["id"] = partIt.second.id.toString();
|
|
|
|
part["visible"] = partIt.second.visible ? "true" : "false";
|
|
|
|
part["locked"] = partIt.second.locked ? "true" : "false";
|
|
|
|
part["subdived"] = partIt.second.subdived ? "true" : "false";
|
|
|
|
part["disabled"] = partIt.second.disabled ? "true" : "false";
|
|
|
|
part["xMirrored"] = partIt.second.xMirrored ? "true" : "false";
|
2019-05-20 13:38:01 +00:00
|
|
|
if (partIt.second.zMirrored)
|
|
|
|
part["zMirrored"] = partIt.second.zMirrored ? "true" : "false";
|
|
|
|
if (partIt.second.base != PartBase::XYZ)
|
|
|
|
part["base"] = PartBaseToString(partIt.second.base);
|
2018-09-21 07:10:18 +00:00
|
|
|
part["rounded"] = partIt.second.rounded ? "true" : "false";
|
2019-03-09 22:10:39 +00:00
|
|
|
part["chamfered"] = partIt.second.chamfered ? "true" : "false";
|
2019-05-19 03:21:38 +00:00
|
|
|
if (PartTarget::Model != partIt.second.target)
|
|
|
|
part["target"] = PartTargetToString(partIt.second.target);
|
2019-02-21 22:48:15 +00:00
|
|
|
if (partIt.second.cutRotationAdjusted())
|
|
|
|
part["cutRotation"] = QString::number(partIt.second.cutRotation);
|
2019-05-19 03:21:38 +00:00
|
|
|
if (partIt.second.cutFaceAdjusted()) {
|
|
|
|
if (CutFace::UserDefined == partIt.second.cutFace) {
|
|
|
|
if (!partIt.second.cutFaceLinkedId.isNull()) {
|
|
|
|
part["cutFace"] = partIt.second.cutFaceLinkedId.toString();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
part["cutFace"] = CutFaceToString(partIt.second.cutFace);
|
|
|
|
}
|
|
|
|
}
|
2018-09-21 07:10:18 +00:00
|
|
|
part["dirty"] = partIt.second.dirty ? "true" : "false";
|
2019-06-08 07:57:13 +00:00
|
|
|
if (partIt.second.hasColor)
|
2018-09-21 07:10:18 +00:00
|
|
|
part["color"] = partIt.second.color.name();
|
2019-05-25 23:24:24 +00:00
|
|
|
if (partIt.second.colorSolubilityAdjusted())
|
|
|
|
part["colorSolubility"] = QString::number(partIt.second.colorSolubility);
|
2018-09-21 07:10:18 +00:00
|
|
|
if (partIt.second.deformThicknessAdjusted())
|
|
|
|
part["deformThickness"] = QString::number(partIt.second.deformThickness);
|
|
|
|
if (partIt.second.deformWidthAdjusted())
|
|
|
|
part["deformWidth"] = QString::number(partIt.second.deformWidth);
|
|
|
|
if (!partIt.second.name.isEmpty())
|
|
|
|
part["name"] = partIt.second.name;
|
2018-10-09 02:19:12 +00:00
|
|
|
if (partIt.second.materialAdjusted())
|
|
|
|
part["materialId"] = partIt.second.materialId.toString();
|
2018-09-21 07:10:18 +00:00
|
|
|
snapshot->parts[part["id"]] = part;
|
|
|
|
}
|
|
|
|
for (const auto &nodeIt: nodeMap) {
|
|
|
|
if (!limitNodeIds.empty() && limitNodeIds.find(nodeIt.first) == limitNodeIds.end())
|
|
|
|
continue;
|
|
|
|
std::map<QString, QString> node;
|
|
|
|
node["id"] = nodeIt.second.id.toString();
|
|
|
|
node["radius"] = QString::number(nodeIt.second.radius);
|
|
|
|
node["x"] = QString::number(nodeIt.second.x);
|
|
|
|
node["y"] = QString::number(nodeIt.second.y);
|
|
|
|
node["z"] = QString::number(nodeIt.second.z);
|
|
|
|
node["partId"] = nodeIt.second.partId.toString();
|
2018-10-25 00:19:38 +00:00
|
|
|
if (nodeIt.second.boneMark != BoneMark::None)
|
|
|
|
node["boneMark"] = BoneMarkToString(nodeIt.second.boneMark);
|
2018-09-21 07:10:18 +00:00
|
|
|
if (!nodeIt.second.name.isEmpty())
|
|
|
|
node["name"] = nodeIt.second.name;
|
|
|
|
snapshot->nodes[node["id"]] = node;
|
|
|
|
}
|
|
|
|
for (const auto &edgeIt: edgeMap) {
|
|
|
|
if (edgeIt.second.nodeIds.size() != 2)
|
|
|
|
continue;
|
|
|
|
if (!limitNodeIds.empty() &&
|
|
|
|
(limitNodeIds.find(edgeIt.second.nodeIds[0]) == limitNodeIds.end() ||
|
|
|
|
limitNodeIds.find(edgeIt.second.nodeIds[1]) == limitNodeIds.end()))
|
|
|
|
continue;
|
|
|
|
std::map<QString, QString> edge;
|
|
|
|
edge["id"] = edgeIt.second.id.toString();
|
|
|
|
edge["from"] = edgeIt.second.nodeIds[0].toString();
|
|
|
|
edge["to"] = edgeIt.second.nodeIds[1].toString();
|
|
|
|
edge["partId"] = edgeIt.second.partId.toString();
|
|
|
|
if (!edgeIt.second.name.isEmpty())
|
|
|
|
edge["name"] = edgeIt.second.name;
|
|
|
|
snapshot->edges[edge["id"]] = edge;
|
2018-08-27 08:50:40 +00:00
|
|
|
}
|
2018-09-21 07:10:18 +00:00
|
|
|
for (const auto &componentIt: componentMap) {
|
|
|
|
if (!limitComponentIds.empty() && limitComponentIds.find(componentIt.first) == limitComponentIds.end())
|
|
|
|
continue;
|
|
|
|
std::map<QString, QString> component;
|
|
|
|
component["id"] = componentIt.second.id.toString();
|
|
|
|
if (!componentIt.second.name.isEmpty())
|
|
|
|
component["name"] = componentIt.second.name;
|
|
|
|
component["expanded"] = componentIt.second.expanded ? "true" : "false";
|
2018-11-14 13:21:45 +00:00
|
|
|
component["combineMode"] = CombineModeToString(componentIt.second.combineMode);
|
2018-09-21 07:10:18 +00:00
|
|
|
component["dirty"] = componentIt.second.dirty ? "true" : "false";
|
|
|
|
if (componentIt.second.smoothAllAdjusted())
|
|
|
|
component["smoothAll"] = QString::number(componentIt.second.smoothAll);
|
|
|
|
if (componentIt.second.smoothSeamAdjusted())
|
|
|
|
component["smoothSeam"] = QString::number(componentIt.second.smoothSeam);
|
|
|
|
QStringList childIdList;
|
|
|
|
for (const auto &childId: componentIt.second.childrenIds) {
|
|
|
|
childIdList.append(childId.toString());
|
|
|
|
}
|
|
|
|
QString children = childIdList.join(",");
|
|
|
|
if (!children.isEmpty())
|
|
|
|
component["children"] = children;
|
|
|
|
QString linkData = componentIt.second.linkData();
|
|
|
|
if (!linkData.isEmpty()) {
|
|
|
|
component["linkData"] = linkData;
|
|
|
|
component["linkDataType"] = componentIt.second.linkDataType();
|
|
|
|
}
|
|
|
|
if (!componentIt.second.name.isEmpty())
|
|
|
|
component["name"] = componentIt.second.name;
|
|
|
|
snapshot->components[component["id"]] = component;
|
2018-08-27 08:50:40 +00:00
|
|
|
}
|
2018-09-21 07:10:18 +00:00
|
|
|
if (limitComponentIds.empty() || limitComponentIds.find(QUuid()) != limitComponentIds.end()) {
|
|
|
|
QStringList childIdList;
|
|
|
|
for (const auto &childId: rootComponent.childrenIds) {
|
|
|
|
childIdList.append(childId.toString());
|
|
|
|
}
|
|
|
|
QString children = childIdList.join(",");
|
|
|
|
if (!children.isEmpty())
|
|
|
|
snapshot->rootComponent["children"] = children;
|
2018-08-27 08:50:40 +00:00
|
|
|
}
|
2018-04-07 08:44:39 +00:00
|
|
|
}
|
2018-10-25 00:19:38 +00:00
|
|
|
if (DocumentToSnapshotFor::Document == forWhat ||
|
|
|
|
DocumentToSnapshotFor::Materials == forWhat) {
|
2018-10-09 02:19:12 +00:00
|
|
|
for (const auto &materialId: materialIdList) {
|
|
|
|
if (!limitMaterialIds.empty() && limitMaterialIds.find(materialId) == limitMaterialIds.end())
|
|
|
|
continue;
|
|
|
|
auto findMaterialResult = materialMap.find(materialId);
|
|
|
|
if (findMaterialResult == materialMap.end()) {
|
|
|
|
qDebug() << "Find material failed:" << materialId;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
auto &materialIt = *findMaterialResult;
|
|
|
|
std::map<QString, QString> material;
|
|
|
|
material["id"] = materialIt.second.id.toString();
|
|
|
|
material["type"] = "MetalRoughness";
|
|
|
|
if (!materialIt.second.name.isEmpty())
|
|
|
|
material["name"] = materialIt.second.name;
|
|
|
|
std::vector<std::pair<std::map<QString, QString>, std::vector<std::map<QString, QString>>>> layers;
|
|
|
|
for (const auto &layer: materialIt.second.layers) {
|
|
|
|
std::vector<std::map<QString, QString>> maps;
|
|
|
|
for (const auto &mapItem: layer.maps) {
|
|
|
|
std::map<QString, QString> textureMap;
|
|
|
|
textureMap["for"] = TextureTypeToString(mapItem.forWhat);
|
|
|
|
textureMap["linkDataType"] = "imageId";
|
|
|
|
textureMap["linkData"] = mapItem.imageId.toString();
|
|
|
|
maps.push_back(textureMap);
|
|
|
|
}
|
|
|
|
std::map<QString, QString> layerAttributes;
|
|
|
|
layers.push_back({layerAttributes, maps});
|
|
|
|
}
|
|
|
|
snapshot->materials.push_back(std::make_pair(material, layers));
|
|
|
|
}
|
|
|
|
}
|
2018-10-25 00:19:38 +00:00
|
|
|
if (DocumentToSnapshotFor::Document == forWhat ||
|
|
|
|
DocumentToSnapshotFor::Poses == forWhat) {
|
2018-09-21 07:10:18 +00:00
|
|
|
for (const auto &poseId: poseIdList) {
|
|
|
|
if (!limitPoseIds.empty() && limitPoseIds.find(poseId) == limitPoseIds.end())
|
|
|
|
continue;
|
|
|
|
auto findPoseResult = poseMap.find(poseId);
|
|
|
|
if (findPoseResult == poseMap.end()) {
|
|
|
|
qDebug() << "Find pose failed:" << poseId;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
auto &poseIt = *findPoseResult;
|
2018-11-09 03:20:48 +00:00
|
|
|
std::map<QString, QString> pose;
|
2018-09-21 07:10:18 +00:00
|
|
|
pose["id"] = poseIt.second.id.toString();
|
|
|
|
if (!poseIt.second.name.isEmpty())
|
|
|
|
pose["name"] = poseIt.second.name;
|
2018-11-09 03:20:48 +00:00
|
|
|
if (!poseIt.second.turnaroundImageId.isNull())
|
|
|
|
pose["canvasImageId"] = poseIt.second.turnaroundImageId.toString();
|
2019-06-19 12:57:38 +00:00
|
|
|
if (poseIt.second.yTranslationScaleAdjusted())
|
|
|
|
pose["yTranslationScale"] = QString::number(poseIt.second.yTranslationScale);
|
2018-11-09 03:20:48 +00:00
|
|
|
snapshot->poses.push_back(std::make_pair(pose, poseIt.second.frames));
|
2018-09-21 07:10:18 +00:00
|
|
|
}
|
|
|
|
}
|
2018-10-25 00:19:38 +00:00
|
|
|
if (DocumentToSnapshotFor::Document == forWhat ||
|
|
|
|
DocumentToSnapshotFor::Motions == forWhat) {
|
2018-10-02 04:59:30 +00:00
|
|
|
for (const auto &motionId: motionIdList) {
|
|
|
|
if (!limitMotionIds.empty() && limitMotionIds.find(motionId) == limitMotionIds.end())
|
|
|
|
continue;
|
|
|
|
auto findMotionResult = motionMap.find(motionId);
|
|
|
|
if (findMotionResult == motionMap.end()) {
|
|
|
|
qDebug() << "Find motion failed:" << motionId;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
auto &motionIt = *findMotionResult;
|
|
|
|
std::map<QString, QString> motion;
|
|
|
|
motion["id"] = motionIt.second.id.toString();
|
|
|
|
if (!motionIt.second.name.isEmpty())
|
|
|
|
motion["name"] = motionIt.second.name;
|
2018-10-23 14:57:47 +00:00
|
|
|
std::vector<std::map<QString, QString>> clips;
|
|
|
|
for (const auto &clip: motionIt.second.clips) {
|
2018-10-02 04:59:30 +00:00
|
|
|
std::map<QString, QString> attributes;
|
2018-10-23 14:57:47 +00:00
|
|
|
attributes["duration"] = QString::number(clip.duration);
|
|
|
|
attributes["linkDataType"] = clip.linkDataType();
|
|
|
|
attributes["linkData"] = clip.linkData();
|
|
|
|
clips.push_back(attributes);
|
2018-10-02 04:59:30 +00:00
|
|
|
}
|
2018-10-23 14:57:47 +00:00
|
|
|
snapshot->motions.push_back(std::make_pair(motion, clips));
|
2018-10-02 04:59:30 +00:00
|
|
|
}
|
|
|
|
}
|
2018-10-25 00:19:38 +00:00
|
|
|
if (DocumentToSnapshotFor::Document == forWhat) {
|
2018-09-21 07:10:18 +00:00
|
|
|
std::map<QString, QString> canvas;
|
|
|
|
canvas["originX"] = QString::number(originX);
|
|
|
|
canvas["originY"] = QString::number(originY);
|
|
|
|
canvas["originZ"] = QString::number(originZ);
|
|
|
|
canvas["rigType"] = RigTypeToString(rigType);
|
|
|
|
snapshot->canvas = canvas;
|
|
|
|
}
|
2018-04-07 08:44:39 +00:00
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::addFromSnapshot(const Snapshot &snapshot, bool fromPaste)
|
2018-09-14 09:45:05 +00:00
|
|
|
{
|
|
|
|
bool isOriginChanged = false;
|
|
|
|
bool isRigTypeChanged = false;
|
|
|
|
if (!fromPaste) {
|
|
|
|
const auto &originXit = snapshot.canvas.find("originX");
|
|
|
|
const auto &originYit = snapshot.canvas.find("originY");
|
|
|
|
const auto &originZit = snapshot.canvas.find("originZ");
|
|
|
|
if (originXit != snapshot.canvas.end() &&
|
|
|
|
originYit != snapshot.canvas.end() &&
|
|
|
|
originZit != snapshot.canvas.end()) {
|
|
|
|
originX = originXit->second.toFloat();
|
|
|
|
originY = originYit->second.toFloat();
|
|
|
|
originZ = originZit->second.toFloat();
|
|
|
|
isOriginChanged = true;
|
|
|
|
}
|
|
|
|
const auto &rigTypeIt = snapshot.canvas.find("rigType");
|
|
|
|
if (rigTypeIt != snapshot.canvas.end()) {
|
|
|
|
rigType = RigTypeFromString(rigTypeIt->second.toUtf8().constData());
|
|
|
|
}
|
|
|
|
isRigTypeChanged = true;
|
2018-04-15 12:11:51 +00:00
|
|
|
}
|
|
|
|
|
2018-05-12 10:07:46 +00:00
|
|
|
std::set<QUuid> newAddedNodeIds;
|
|
|
|
std::set<QUuid> newAddedEdgeIds;
|
|
|
|
std::set<QUuid> newAddedPartIds;
|
2018-08-27 08:50:40 +00:00
|
|
|
std::set<QUuid> newAddedComponentIds;
|
|
|
|
|
|
|
|
std::set<QUuid> inversePartIds;
|
2018-05-12 10:07:46 +00:00
|
|
|
|
2018-04-09 08:46:06 +00:00
|
|
|
std::map<QUuid, QUuid> oldNewIdMap;
|
2018-10-09 02:19:12 +00:00
|
|
|
for (const auto &materialIt: snapshot.materials) {
|
|
|
|
const auto &materialAttributes = materialIt.first;
|
|
|
|
auto materialType = valueOfKeyInMapOrEmpty(materialAttributes, "type");
|
|
|
|
if ("MetalRoughness" != materialType) {
|
|
|
|
qDebug() << "Unsupported material type:" << materialType;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
QUuid newMaterialId = QUuid::createUuid();
|
|
|
|
auto &newMaterial = materialMap[newMaterialId];
|
|
|
|
newMaterial.id = newMaterialId;
|
|
|
|
newMaterial.name = valueOfKeyInMapOrEmpty(materialAttributes, "name");
|
|
|
|
oldNewIdMap[QUuid(valueOfKeyInMapOrEmpty(materialAttributes, "id"))] = newMaterialId;
|
|
|
|
for (const auto &layerIt: materialIt.second) {
|
2018-10-25 00:19:38 +00:00
|
|
|
MaterialLayer layer;
|
2018-10-09 02:19:12 +00:00
|
|
|
for (const auto &mapItem: layerIt.second) {
|
|
|
|
auto textureTypeString = valueOfKeyInMapOrEmpty(mapItem, "for");
|
|
|
|
auto textureType = TextureTypeFromString(textureTypeString.toUtf8().constData());
|
|
|
|
if (TextureType::None == textureType) {
|
|
|
|
qDebug() << "Unsupported texture type:" << textureTypeString;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
auto linkTypeString = valueOfKeyInMapOrEmpty(mapItem, "linkDataType");
|
|
|
|
if ("imageId" != linkTypeString) {
|
|
|
|
qDebug() << "Unsupported link data type:" << linkTypeString;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
auto imageId = QUuid(valueOfKeyInMapOrEmpty(mapItem, "linkData"));
|
2018-10-25 00:19:38 +00:00
|
|
|
MaterialMap materialMap;
|
2018-10-09 02:19:12 +00:00
|
|
|
materialMap.imageId = imageId;
|
|
|
|
materialMap.forWhat = textureType;
|
|
|
|
layer.maps.push_back(materialMap);
|
|
|
|
}
|
|
|
|
newMaterial.layers.push_back(layer);
|
|
|
|
}
|
|
|
|
materialIdList.push_back(newMaterialId);
|
|
|
|
emit materialAdded(newMaterialId);
|
|
|
|
}
|
2019-05-19 03:21:38 +00:00
|
|
|
std::map<QUuid, QUuid> cutFaceLinkedIdModifyMap;
|
2018-08-27 08:50:40 +00:00
|
|
|
for (const auto &partKv: snapshot.parts) {
|
2018-09-18 06:22:29 +00:00
|
|
|
const auto newUuid = QUuid::createUuid();
|
2018-11-03 08:09:42 +00:00
|
|
|
SkeletonPart &part = partMap[newUuid];
|
2018-09-18 06:22:29 +00:00
|
|
|
part.id = newUuid;
|
2018-04-09 08:46:06 +00:00
|
|
|
oldNewIdMap[QUuid(partKv.first)] = part.id;
|
|
|
|
part.name = valueOfKeyInMapOrEmpty(partKv.second, "name");
|
|
|
|
part.visible = isTrueValueString(valueOfKeyInMapOrEmpty(partKv.second, "visible"));
|
|
|
|
part.locked = isTrueValueString(valueOfKeyInMapOrEmpty(partKv.second, "locked"));
|
|
|
|
part.subdived = isTrueValueString(valueOfKeyInMapOrEmpty(partKv.second, "subdived"));
|
2018-04-11 09:19:27 +00:00
|
|
|
part.disabled = isTrueValueString(valueOfKeyInMapOrEmpty(partKv.second, "disabled"));
|
2018-04-15 12:11:51 +00:00
|
|
|
part.xMirrored = isTrueValueString(valueOfKeyInMapOrEmpty(partKv.second, "xMirrored"));
|
|
|
|
part.zMirrored = isTrueValueString(valueOfKeyInMapOrEmpty(partKv.second, "zMirrored"));
|
2019-05-20 13:38:01 +00:00
|
|
|
part.base = PartBaseFromString(valueOfKeyInMapOrEmpty(partKv.second, "base").toUtf8().constData());
|
2018-04-26 02:23:22 +00:00
|
|
|
part.rounded = isTrueValueString(valueOfKeyInMapOrEmpty(partKv.second, "rounded"));
|
2019-03-09 22:10:39 +00:00
|
|
|
part.chamfered = isTrueValueString(valueOfKeyInMapOrEmpty(partKv.second, "chamfered"));
|
2019-05-19 03:21:38 +00:00
|
|
|
part.target = PartTargetFromString(valueOfKeyInMapOrEmpty(partKv.second, "target").toUtf8().constData());
|
2019-02-21 22:48:15 +00:00
|
|
|
const auto &cutRotationIt = partKv.second.find("cutRotation");
|
|
|
|
if (cutRotationIt != partKv.second.end())
|
|
|
|
part.setCutRotation(cutRotationIt->second.toFloat());
|
2019-05-05 12:49:26 +00:00
|
|
|
const auto &cutFaceIt = partKv.second.find("cutFace");
|
2019-05-19 03:21:38 +00:00
|
|
|
if (cutFaceIt != partKv.second.end()) {
|
|
|
|
QUuid cutFaceLinkedId = QUuid(cutFaceIt->second);
|
|
|
|
if (cutFaceLinkedId.isNull()) {
|
|
|
|
part.setCutFace(CutFaceFromString(cutFaceIt->second.toUtf8().constData()));
|
|
|
|
} else {
|
|
|
|
part.setCutFaceLinkedId(cutFaceLinkedId);
|
|
|
|
cutFaceLinkedIdModifyMap.insert({part.id, cutFaceLinkedId});
|
|
|
|
}
|
|
|
|
}
|
2018-08-27 08:50:40 +00:00
|
|
|
if (isTrueValueString(valueOfKeyInMapOrEmpty(partKv.second, "inverse")))
|
|
|
|
inversePartIds.insert(part.id);
|
2018-04-26 02:23:22 +00:00
|
|
|
const auto &colorIt = partKv.second.find("color");
|
|
|
|
if (colorIt != partKv.second.end()) {
|
|
|
|
part.color = QColor(colorIt->second);
|
|
|
|
part.hasColor = true;
|
|
|
|
}
|
2019-05-25 23:24:24 +00:00
|
|
|
const auto &colorSolubilityIt = partKv.second.find("colorSolubility");
|
|
|
|
if (colorSolubilityIt != partKv.second.end())
|
|
|
|
part.colorSolubility = colorSolubilityIt->second.toFloat();
|
2018-04-17 16:14:31 +00:00
|
|
|
const auto &deformThicknessIt = partKv.second.find("deformThickness");
|
|
|
|
if (deformThicknessIt != partKv.second.end())
|
|
|
|
part.setDeformThickness(deformThicknessIt->second.toFloat());
|
|
|
|
const auto &deformWidthIt = partKv.second.find("deformWidth");
|
|
|
|
if (deformWidthIt != partKv.second.end())
|
|
|
|
part.setDeformWidth(deformWidthIt->second.toFloat());
|
2018-10-09 02:19:12 +00:00
|
|
|
const auto &materialIdIt = partKv.second.find("materialId");
|
|
|
|
if (materialIdIt != partKv.second.end())
|
|
|
|
part.materialId = oldNewIdMap[QUuid(materialIdIt->second)];
|
2018-05-12 10:07:46 +00:00
|
|
|
newAddedPartIds.insert(part.id);
|
2018-04-07 08:44:39 +00:00
|
|
|
}
|
2019-05-19 03:21:38 +00:00
|
|
|
for (const auto &it: cutFaceLinkedIdModifyMap) {
|
|
|
|
SkeletonPart &part = partMap[it.first];
|
|
|
|
auto findNewLinkedId = oldNewIdMap.find(it.second);
|
|
|
|
if (findNewLinkedId == oldNewIdMap.end())
|
|
|
|
part.setCutFaceLinkedId(QUuid());
|
|
|
|
else
|
|
|
|
part.setCutFaceLinkedId(findNewLinkedId->second);
|
|
|
|
}
|
2018-08-27 08:50:40 +00:00
|
|
|
for (const auto &nodeKv: snapshot.nodes) {
|
2018-04-09 08:46:06 +00:00
|
|
|
if (nodeKv.second.find("radius") == nodeKv.second.end() ||
|
|
|
|
nodeKv.second.find("x") == nodeKv.second.end() ||
|
|
|
|
nodeKv.second.find("y") == nodeKv.second.end() ||
|
|
|
|
nodeKv.second.find("z") == nodeKv.second.end() ||
|
|
|
|
nodeKv.second.find("partId") == nodeKv.second.end())
|
|
|
|
continue;
|
2019-06-25 11:37:17 +00:00
|
|
|
QUuid oldNodeId = QUuid(nodeKv.first);
|
|
|
|
SkeletonNode node(nodeMap.find(oldNodeId) == nodeMap.end() ? oldNodeId : QUuid::createUuid());
|
|
|
|
oldNewIdMap[oldNodeId] = node.id;
|
2018-04-07 08:44:39 +00:00
|
|
|
node.name = valueOfKeyInMapOrEmpty(nodeKv.second, "name");
|
|
|
|
node.radius = valueOfKeyInMapOrEmpty(nodeKv.second, "radius").toFloat();
|
|
|
|
node.x = valueOfKeyInMapOrEmpty(nodeKv.second, "x").toFloat();
|
|
|
|
node.y = valueOfKeyInMapOrEmpty(nodeKv.second, "y").toFloat();
|
|
|
|
node.z = valueOfKeyInMapOrEmpty(nodeKv.second, "z").toFloat();
|
2018-04-09 08:46:06 +00:00
|
|
|
node.partId = oldNewIdMap[QUuid(valueOfKeyInMapOrEmpty(nodeKv.second, "partId"))];
|
2018-10-25 00:19:38 +00:00
|
|
|
node.boneMark = BoneMarkFromString(valueOfKeyInMapOrEmpty(nodeKv.second, "boneMark").toUtf8().constData());
|
2018-04-07 08:44:39 +00:00
|
|
|
nodeMap[node.id] = node;
|
2018-05-12 10:07:46 +00:00
|
|
|
newAddedNodeIds.insert(node.id);
|
2018-04-07 08:44:39 +00:00
|
|
|
}
|
2018-08-27 08:50:40 +00:00
|
|
|
for (const auto &edgeKv: snapshot.edges) {
|
2018-04-09 08:46:06 +00:00
|
|
|
if (edgeKv.second.find("from") == edgeKv.second.end() ||
|
|
|
|
edgeKv.second.find("to") == edgeKv.second.end() ||
|
|
|
|
edgeKv.second.find("partId") == edgeKv.second.end())
|
|
|
|
continue;
|
2019-06-25 11:37:17 +00:00
|
|
|
QUuid oldEdgeId = QUuid(edgeKv.first);
|
|
|
|
SkeletonEdge edge(edgeMap.find(oldEdgeId) == edgeMap.end() ? oldEdgeId : QUuid::createUuid());
|
|
|
|
oldNewIdMap[oldEdgeId] = edge.id;
|
2018-04-07 08:44:39 +00:00
|
|
|
edge.name = valueOfKeyInMapOrEmpty(edgeKv.second, "name");
|
2018-04-09 08:46:06 +00:00
|
|
|
edge.partId = oldNewIdMap[QUuid(valueOfKeyInMapOrEmpty(edgeKv.second, "partId"))];
|
2018-04-07 08:44:39 +00:00
|
|
|
QString fromNodeId = valueOfKeyInMapOrEmpty(edgeKv.second, "from");
|
2018-04-08 23:42:59 +00:00
|
|
|
if (!fromNodeId.isEmpty()) {
|
2018-04-09 08:46:06 +00:00
|
|
|
QUuid fromId = oldNewIdMap[QUuid(fromNodeId)];
|
|
|
|
edge.nodeIds.push_back(fromId);
|
|
|
|
nodeMap[fromId].edgeIds.push_back(edge.id);
|
2018-04-08 23:42:59 +00:00
|
|
|
}
|
2018-04-07 08:44:39 +00:00
|
|
|
QString toNodeId = valueOfKeyInMapOrEmpty(edgeKv.second, "to");
|
2018-04-08 23:42:59 +00:00
|
|
|
if (!toNodeId.isEmpty()) {
|
2018-04-09 08:46:06 +00:00
|
|
|
QUuid toId = oldNewIdMap[QUuid(toNodeId)];
|
|
|
|
edge.nodeIds.push_back(toId);
|
|
|
|
nodeMap[toId].edgeIds.push_back(edge.id);
|
2018-04-08 23:42:59 +00:00
|
|
|
}
|
2018-04-07 08:44:39 +00:00
|
|
|
edgeMap[edge.id] = edge;
|
2018-05-12 10:07:46 +00:00
|
|
|
newAddedEdgeIds.insert(edge.id);
|
2018-04-07 08:44:39 +00:00
|
|
|
}
|
2018-04-09 05:22:25 +00:00
|
|
|
for (const auto &nodeIt: nodeMap) {
|
2018-05-12 10:07:46 +00:00
|
|
|
if (newAddedNodeIds.find(nodeIt.first) == newAddedNodeIds.end())
|
|
|
|
continue;
|
2018-04-09 05:22:25 +00:00
|
|
|
partMap[nodeIt.second.partId].nodeIds.push_back(nodeIt.first);
|
|
|
|
}
|
2018-08-27 08:50:40 +00:00
|
|
|
for (const auto &componentKv: snapshot.components) {
|
|
|
|
QString linkData = valueOfKeyInMapOrEmpty(componentKv.second, "linkData");
|
|
|
|
QString linkDataType = valueOfKeyInMapOrEmpty(componentKv.second, "linkDataType");
|
2018-10-25 00:19:38 +00:00
|
|
|
Component component(QUuid(), linkData, linkDataType);
|
2018-08-27 08:50:40 +00:00
|
|
|
oldNewIdMap[QUuid(componentKv.first)] = component.id;
|
|
|
|
component.name = valueOfKeyInMapOrEmpty(componentKv.second, "name");
|
|
|
|
component.expanded = isTrueValueString(valueOfKeyInMapOrEmpty(componentKv.second, "expanded"));
|
2018-11-14 13:21:45 +00:00
|
|
|
component.combineMode = CombineModeFromString(valueOfKeyInMapOrEmpty(componentKv.second, "combineMode").toUtf8().constData());
|
|
|
|
if (component.combineMode == CombineMode::Normal) {
|
|
|
|
if (isTrueValueString(valueOfKeyInMapOrEmpty(componentKv.second, "inverse")))
|
|
|
|
component.combineMode = CombineMode::Inversion;
|
|
|
|
}
|
2018-09-06 15:04:59 +00:00
|
|
|
const auto &smoothAllIt = componentKv.second.find("smoothAll");
|
|
|
|
if (smoothAllIt != componentKv.second.end())
|
|
|
|
component.setSmoothAll(smoothAllIt->second.toFloat());
|
|
|
|
const auto &smoothSeamIt = componentKv.second.find("smoothSeam");
|
|
|
|
if (smoothSeamIt != componentKv.second.end())
|
|
|
|
component.setSmoothSeam(smoothSeamIt->second.toFloat());
|
2018-09-21 07:10:18 +00:00
|
|
|
//qDebug() << "Add component:" << component.id << " old:" << componentKv.first << "name:" << component.name;
|
2018-08-27 08:50:40 +00:00
|
|
|
if ("partId" == linkDataType) {
|
|
|
|
QUuid partId = oldNewIdMap[QUuid(linkData)];
|
|
|
|
component.linkToPartId = partId;
|
2018-09-21 07:10:18 +00:00
|
|
|
//qDebug() << "Add part:" << partId << " from component:" << component.id;
|
2018-08-27 08:50:40 +00:00
|
|
|
partMap[partId].componentId = component.id;
|
|
|
|
if (inversePartIds.find(partId) != inversePartIds.end())
|
2018-11-14 13:21:45 +00:00
|
|
|
component.combineMode = CombineMode::Inversion;
|
2018-08-27 08:50:40 +00:00
|
|
|
}
|
|
|
|
componentMap[component.id] = component;
|
|
|
|
newAddedComponentIds.insert(component.id);
|
|
|
|
}
|
|
|
|
const auto &rootComponentChildren = snapshot.rootComponent.find("children");
|
|
|
|
if (rootComponentChildren != snapshot.rootComponent.end()) {
|
|
|
|
for (const auto &childId: rootComponentChildren->second.split(",")) {
|
|
|
|
if (childId.isEmpty())
|
|
|
|
continue;
|
|
|
|
QUuid componentId = oldNewIdMap[QUuid(childId)];
|
|
|
|
if (componentMap.find(componentId) == componentMap.end())
|
|
|
|
continue;
|
2018-09-21 07:10:18 +00:00
|
|
|
//qDebug() << "Add root component:" << componentId;
|
2018-08-27 08:50:40 +00:00
|
|
|
rootComponent.addChild(componentId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (const auto &componentKv: snapshot.components) {
|
|
|
|
QUuid componentId = oldNewIdMap[QUuid(componentKv.first)];
|
|
|
|
if (componentMap.find(componentId) == componentMap.end())
|
2018-05-12 10:07:46 +00:00
|
|
|
continue;
|
2018-08-27 08:50:40 +00:00
|
|
|
for (const auto &childId: valueOfKeyInMapOrEmpty(componentKv.second, "children").split(",")) {
|
|
|
|
if (childId.isEmpty())
|
|
|
|
continue;
|
|
|
|
QUuid childComponentId = oldNewIdMap[QUuid(childId)];
|
|
|
|
if (componentMap.find(childComponentId) == componentMap.end())
|
|
|
|
continue;
|
2018-09-21 07:10:18 +00:00
|
|
|
//qDebug() << "Add child component:" << childComponentId << "to" << componentId;
|
2018-08-27 08:50:40 +00:00
|
|
|
componentMap[componentId].addChild(childComponentId);
|
|
|
|
componentMap[childComponentId].parentId = componentId;
|
|
|
|
}
|
2018-04-07 08:44:39 +00:00
|
|
|
}
|
2018-09-21 07:10:18 +00:00
|
|
|
for (const auto &poseIt: snapshot.poses) {
|
|
|
|
QUuid newPoseId = QUuid::createUuid();
|
|
|
|
auto &newPose = poseMap[newPoseId];
|
|
|
|
newPose.id = newPoseId;
|
|
|
|
const auto &poseAttributes = poseIt.first;
|
|
|
|
newPose.name = valueOfKeyInMapOrEmpty(poseAttributes, "name");
|
2018-11-09 03:20:48 +00:00
|
|
|
auto findCanvasImageId = poseAttributes.find("canvasImageId");
|
|
|
|
if (findCanvasImageId != poseAttributes.end())
|
|
|
|
newPose.turnaroundImageId = QUuid(findCanvasImageId->second);
|
2019-06-19 12:57:38 +00:00
|
|
|
auto findYtranslationScale = poseAttributes.find("yTranslationScale");
|
|
|
|
if (findYtranslationScale != poseAttributes.end())
|
|
|
|
newPose.yTranslationScale = findYtranslationScale->second.toFloat();
|
2018-11-09 03:20:48 +00:00
|
|
|
newPose.frames = poseIt.second;
|
2018-09-21 07:10:18 +00:00
|
|
|
oldNewIdMap[QUuid(valueOfKeyInMapOrEmpty(poseAttributes, "id"))] = newPoseId;
|
|
|
|
poseIdList.push_back(newPoseId);
|
|
|
|
emit poseAdded(newPoseId);
|
|
|
|
}
|
2018-10-02 04:59:30 +00:00
|
|
|
for (const auto &motionIt: snapshot.motions) {
|
|
|
|
QUuid newMotionId = QUuid::createUuid();
|
|
|
|
auto &newMotion = motionMap[newMotionId];
|
|
|
|
newMotion.id = newMotionId;
|
2018-10-23 14:57:47 +00:00
|
|
|
const auto &motionAttributes = motionIt.first;
|
2018-10-02 04:59:30 +00:00
|
|
|
newMotion.name = valueOfKeyInMapOrEmpty(motionAttributes, "name");
|
2018-10-23 14:57:47 +00:00
|
|
|
for (const auto &attributes: motionIt.second) {
|
|
|
|
auto linkData = valueOfKeyInMapOrEmpty(attributes, "linkData");
|
|
|
|
QUuid testId = QUuid(linkData);
|
|
|
|
if (!testId.isNull()) {
|
|
|
|
auto findInOldNewIdMapResult = oldNewIdMap.find(testId);
|
|
|
|
if (findInOldNewIdMapResult != oldNewIdMap.end()) {
|
|
|
|
linkData = findInOldNewIdMapResult->second.toString();
|
|
|
|
}
|
2018-10-02 04:59:30 +00:00
|
|
|
}
|
2018-10-25 00:19:38 +00:00
|
|
|
MotionClip clip(linkData,
|
2018-10-23 14:57:47 +00:00
|
|
|
valueOfKeyInMapOrEmpty(attributes, "linkDataType"));
|
|
|
|
clip.duration = valueOfKeyInMapOrEmpty(attributes, "duration").toFloat();
|
|
|
|
newMotion.clips.push_back(clip);
|
2018-10-02 04:59:30 +00:00
|
|
|
}
|
|
|
|
oldNewIdMap[QUuid(valueOfKeyInMapOrEmpty(motionAttributes, "id"))] = newMotionId;
|
|
|
|
motionIdList.push_back(newMotionId);
|
|
|
|
emit motionAdded(newMotionId);
|
|
|
|
}
|
2018-04-07 08:44:39 +00:00
|
|
|
|
2018-05-12 10:07:46 +00:00
|
|
|
for (const auto &nodeIt: newAddedNodeIds) {
|
|
|
|
emit nodeAdded(nodeIt);
|
2018-04-07 08:44:39 +00:00
|
|
|
}
|
2018-05-12 10:07:46 +00:00
|
|
|
for (const auto &edgeIt: newAddedEdgeIds) {
|
|
|
|
emit edgeAdded(edgeIt);
|
2018-04-07 08:44:39 +00:00
|
|
|
}
|
2018-05-12 10:07:46 +00:00
|
|
|
for (const auto &partIt : newAddedPartIds) {
|
|
|
|
emit partAdded(partIt);
|
2018-04-07 08:44:39 +00:00
|
|
|
}
|
|
|
|
|
2018-08-27 08:50:40 +00:00
|
|
|
emit componentChildrenChanged(QUuid());
|
2018-09-14 09:45:05 +00:00
|
|
|
if (isOriginChanged)
|
|
|
|
emit originChanged();
|
|
|
|
if (isRigTypeChanged)
|
|
|
|
emit rigTypeChanged();
|
2018-04-08 23:34:46 +00:00
|
|
|
emit skeletonChanged();
|
2018-05-12 10:07:46 +00:00
|
|
|
|
|
|
|
for (const auto &partIt : newAddedPartIds) {
|
|
|
|
emit partVisibleStateChanged(partIt);
|
|
|
|
}
|
|
|
|
|
|
|
|
emit uncheckAll();
|
|
|
|
for (const auto &nodeIt: newAddedNodeIds) {
|
|
|
|
emit checkNode(nodeIt);
|
|
|
|
}
|
|
|
|
for (const auto &edgeIt: newAddedEdgeIds) {
|
|
|
|
emit checkEdge(edgeIt);
|
|
|
|
}
|
2018-09-21 07:10:18 +00:00
|
|
|
|
2018-10-09 02:19:12 +00:00
|
|
|
if (!snapshot.materials.empty())
|
|
|
|
emit materialListChanged();
|
2018-09-21 07:10:18 +00:00
|
|
|
if (!snapshot.poses.empty())
|
|
|
|
emit poseListChanged();
|
2018-10-02 04:59:30 +00:00
|
|
|
if (!snapshot.motions.empty())
|
|
|
|
emit motionListChanged();
|
2018-04-07 08:44:39 +00:00
|
|
|
}
|
|
|
|
|
2018-10-25 06:27:59 +00:00
|
|
|
void Document::silentReset()
|
2018-04-09 08:46:06 +00:00
|
|
|
{
|
2018-08-27 08:50:40 +00:00
|
|
|
originX = 0.0;
|
|
|
|
originY = 0.0;
|
|
|
|
originZ = 0.0;
|
2018-09-14 09:45:05 +00:00
|
|
|
rigType = RigType::None;
|
2018-04-09 08:46:06 +00:00
|
|
|
nodeMap.clear();
|
|
|
|
edgeMap.clear();
|
|
|
|
partMap.clear();
|
2018-08-27 08:50:40 +00:00
|
|
|
componentMap.clear();
|
2018-10-09 02:19:12 +00:00
|
|
|
materialMap.clear();
|
|
|
|
materialIdList.clear();
|
2018-09-21 07:10:18 +00:00
|
|
|
poseMap.clear();
|
|
|
|
poseIdList.clear();
|
2018-10-02 04:59:30 +00:00
|
|
|
motionMap.clear();
|
|
|
|
motionIdList.clear();
|
2018-10-25 00:19:38 +00:00
|
|
|
rootComponent = Component();
|
2018-10-21 23:56:56 +00:00
|
|
|
removeRigResults();
|
2018-10-25 06:27:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Document::reset()
|
|
|
|
{
|
|
|
|
silentReset();
|
2018-04-10 07:59:20 +00:00
|
|
|
emit cleanup();
|
|
|
|
emit skeletonChanged();
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::fromSnapshot(const Snapshot &snapshot)
|
2018-04-10 07:59:20 +00:00
|
|
|
{
|
|
|
|
reset();
|
2018-09-14 09:45:05 +00:00
|
|
|
addFromSnapshot(snapshot, false);
|
2018-05-12 10:07:46 +00:00
|
|
|
emit uncheckAll();
|
2018-04-09 08:46:06 +00:00
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
MeshLoader *Document::takeResultMesh()
|
2018-04-07 08:44:39 +00:00
|
|
|
{
|
2018-06-11 14:24:25 +00:00
|
|
|
if (nullptr == m_resultMesh)
|
|
|
|
return nullptr;
|
|
|
|
MeshLoader *resultMesh = new MeshLoader(*m_resultMesh);
|
2018-04-07 08:44:39 +00:00
|
|
|
return resultMesh;
|
|
|
|
}
|
|
|
|
|
2019-01-07 13:03:42 +00:00
|
|
|
bool Document::isMeshGenerationSucceed()
|
|
|
|
{
|
|
|
|
return m_isMeshGenerationSucceed;
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
MeshLoader *Document::takeResultTextureMesh()
|
2018-05-10 09:16:22 +00:00
|
|
|
{
|
2018-10-09 02:19:12 +00:00
|
|
|
if (nullptr == m_resultTextureMesh)
|
|
|
|
return nullptr;
|
|
|
|
MeshLoader *resultTextureMesh = new MeshLoader(*m_resultTextureMesh);
|
2018-05-10 09:16:22 +00:00
|
|
|
return resultTextureMesh;
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
MeshLoader *Document::takeResultRigWeightMesh()
|
2018-09-14 09:45:05 +00:00
|
|
|
{
|
|
|
|
if (nullptr == m_resultRigWeightMesh)
|
|
|
|
return nullptr;
|
|
|
|
MeshLoader *resultMesh = new MeshLoader(*m_resultRigWeightMesh);
|
|
|
|
return resultMesh;
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::meshReady()
|
2018-04-07 08:44:39 +00:00
|
|
|
{
|
2018-05-07 17:16:58 +00:00
|
|
|
MeshLoader *resultMesh = m_meshGenerator->takeResultMesh();
|
2018-10-26 23:04:45 +00:00
|
|
|
Outcome *outcome = m_meshGenerator->takeOutcome();
|
2019-01-07 13:03:42 +00:00
|
|
|
bool isSucceed = m_meshGenerator->isSucceed();
|
2018-04-07 08:44:39 +00:00
|
|
|
|
2018-09-18 06:22:29 +00:00
|
|
|
for (auto &partId: m_meshGenerator->generatedPreviewPartIds()) {
|
|
|
|
auto part = partMap.find(partId);
|
|
|
|
if (part != partMap.end()) {
|
|
|
|
MeshLoader *resultPartPreviewMesh = m_meshGenerator->takePartPreviewMesh(partId);
|
|
|
|
part->second.updatePreviewMesh(resultPartPreviewMesh);
|
|
|
|
emit partPreviewChanged(partId);
|
2018-04-07 08:44:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
delete m_resultMesh;
|
|
|
|
m_resultMesh = resultMesh;
|
|
|
|
|
2019-01-07 13:03:42 +00:00
|
|
|
m_isMeshGenerationSucceed = isSucceed;
|
|
|
|
|
2018-10-26 23:04:45 +00:00
|
|
|
delete m_currentOutcome;
|
|
|
|
m_currentOutcome = outcome;
|
2018-04-30 11:31:09 +00:00
|
|
|
|
2018-04-07 08:44:39 +00:00
|
|
|
if (nullptr == m_resultMesh) {
|
|
|
|
qDebug() << "Result mesh is null";
|
|
|
|
}
|
|
|
|
|
|
|
|
delete m_meshGenerator;
|
|
|
|
m_meshGenerator = nullptr;
|
|
|
|
|
2019-06-12 11:33:38 +00:00
|
|
|
qDebug() << "Mesh generation done";
|
2018-04-07 08:44:39 +00:00
|
|
|
|
2018-08-27 08:50:40 +00:00
|
|
|
m_isPostProcessResultObsolete = true;
|
2018-09-14 09:45:05 +00:00
|
|
|
m_isRigObsolete = true;
|
2018-06-15 05:34:41 +00:00
|
|
|
|
2018-04-07 08:44:39 +00:00
|
|
|
emit resultMeshChanged();
|
|
|
|
|
2018-08-27 08:50:40 +00:00
|
|
|
if (m_isResultMeshObsolete) {
|
2018-04-07 08:44:39 +00:00
|
|
|
generateMesh();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
bool Document::isPostProcessResultObsolete() const
|
2018-06-15 05:34:41 +00:00
|
|
|
{
|
2018-08-27 08:50:40 +00:00
|
|
|
return m_isPostProcessResultObsolete;
|
2018-06-15 05:34:41 +00:00
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::batchChangeBegin()
|
2018-04-09 14:24:30 +00:00
|
|
|
{
|
|
|
|
m_batchChangeRefCount++;
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::batchChangeEnd()
|
2018-04-09 14:24:30 +00:00
|
|
|
{
|
|
|
|
m_batchChangeRefCount--;
|
|
|
|
if (0 == m_batchChangeRefCount) {
|
2018-08-27 08:50:40 +00:00
|
|
|
if (m_isResultMeshObsolete) {
|
2018-04-09 14:24:30 +00:00
|
|
|
generateMesh();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::regenerateMesh()
|
2018-08-27 08:50:40 +00:00
|
|
|
{
|
|
|
|
markAllDirty();
|
|
|
|
generateMesh();
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::toggleSmoothNormal()
|
2018-09-07 12:51:33 +00:00
|
|
|
{
|
|
|
|
m_smoothNormal = !m_smoothNormal;
|
|
|
|
regenerateMesh();
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::enableWeld(bool enabled)
|
2018-09-22 10:31:02 +00:00
|
|
|
{
|
|
|
|
weldEnabled = enabled;
|
|
|
|
regenerateMesh();
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::generateMesh()
|
2018-04-07 08:44:39 +00:00
|
|
|
{
|
2018-04-09 14:24:30 +00:00
|
|
|
if (nullptr != m_meshGenerator || m_batchChangeRefCount > 0) {
|
2018-08-27 08:50:40 +00:00
|
|
|
m_isResultMeshObsolete = true;
|
2018-04-07 08:44:39 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-06-12 11:33:38 +00:00
|
|
|
qDebug() << "Mesh generating..";
|
2018-04-07 08:44:39 +00:00
|
|
|
|
2018-08-27 08:50:40 +00:00
|
|
|
settleOrigin();
|
|
|
|
|
|
|
|
m_isResultMeshObsolete = false;
|
2018-04-07 08:44:39 +00:00
|
|
|
|
|
|
|
QThread *thread = new QThread;
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
Snapshot *snapshot = new Snapshot;
|
2018-04-07 08:44:39 +00:00
|
|
|
toSnapshot(snapshot);
|
2018-08-27 08:50:40 +00:00
|
|
|
resetDirtyFlags();
|
2018-10-09 02:19:12 +00:00
|
|
|
m_meshGenerator = new MeshGenerator(snapshot);
|
2019-06-08 07:57:13 +00:00
|
|
|
m_meshGenerator->setDefaultPartColor(Preferences::instance().partColor());
|
2018-08-27 08:50:40 +00:00
|
|
|
m_meshGenerator->setGeneratedCacheContext(&m_generatedCacheContext);
|
2019-05-30 10:28:55 +00:00
|
|
|
if (!m_smoothNormal) {
|
|
|
|
m_meshGenerator->setSmoothShadingThresholdAngleDegrees(0);
|
|
|
|
}
|
2018-10-09 02:19:12 +00:00
|
|
|
m_meshGenerator->moveToThread(thread);
|
2018-04-07 08:44:39 +00:00
|
|
|
connect(thread, &QThread::started, m_meshGenerator, &MeshGenerator::process);
|
2018-10-25 00:19:38 +00:00
|
|
|
connect(m_meshGenerator, &MeshGenerator::finished, this, &Document::meshReady);
|
2018-04-07 08:44:39 +00:00
|
|
|
connect(m_meshGenerator, &MeshGenerator::finished, thread, &QThread::quit);
|
|
|
|
connect(thread, &QThread::finished, thread, &QThread::deleteLater);
|
2018-10-09 02:19:12 +00:00
|
|
|
emit meshGenerating();
|
2018-04-07 08:44:39 +00:00
|
|
|
thread->start();
|
|
|
|
}
|
2018-04-08 01:30:55 +00:00
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::generateTexture()
|
2018-05-07 16:08:19 +00:00
|
|
|
{
|
|
|
|
if (nullptr != m_textureGenerator) {
|
2018-08-27 08:50:40 +00:00
|
|
|
m_isTextureObsolete = true;
|
2018-05-07 16:08:19 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
qDebug() << "Texture guide generating..";
|
|
|
|
|
2018-08-27 08:50:40 +00:00
|
|
|
m_isTextureObsolete = false;
|
2018-05-07 16:08:19 +00:00
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
Snapshot *snapshot = new Snapshot;
|
2018-10-09 09:17:44 +00:00
|
|
|
toSnapshot(snapshot);
|
|
|
|
|
2018-05-07 16:08:19 +00:00
|
|
|
QThread *thread = new QThread;
|
2018-10-26 23:04:45 +00:00
|
|
|
m_textureGenerator = new TextureGenerator(*m_postProcessedOutcome, snapshot);
|
2018-05-07 16:08:19 +00:00
|
|
|
m_textureGenerator->moveToThread(thread);
|
|
|
|
connect(thread, &QThread::started, m_textureGenerator, &TextureGenerator::process);
|
2018-10-25 00:19:38 +00:00
|
|
|
connect(m_textureGenerator, &TextureGenerator::finished, this, &Document::textureReady);
|
2018-05-07 16:08:19 +00:00
|
|
|
connect(m_textureGenerator, &TextureGenerator::finished, thread, &QThread::quit);
|
|
|
|
connect(thread, &QThread::finished, thread, &QThread::deleteLater);
|
2018-10-09 02:19:12 +00:00
|
|
|
emit textureGenerating();
|
2018-05-07 16:08:19 +00:00
|
|
|
thread->start();
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::textureReady()
|
2018-05-07 16:08:19 +00:00
|
|
|
{
|
|
|
|
delete textureGuideImage;
|
|
|
|
textureGuideImage = m_textureGenerator->takeResultTextureGuideImage();
|
|
|
|
|
|
|
|
delete textureImage;
|
|
|
|
textureImage = m_textureGenerator->takeResultTextureImage();
|
|
|
|
|
|
|
|
delete textureBorderImage;
|
|
|
|
textureBorderImage = m_textureGenerator->takeResultTextureBorderImage();
|
|
|
|
|
2018-05-10 09:16:22 +00:00
|
|
|
delete textureColorImage;
|
|
|
|
textureColorImage = m_textureGenerator->takeResultTextureColorImage();
|
|
|
|
|
2018-11-15 22:56:24 +00:00
|
|
|
delete textureNormalImage;
|
|
|
|
textureNormalImage = m_textureGenerator->takeResultTextureNormalImage();
|
|
|
|
|
|
|
|
delete textureMetalnessRoughnessAmbientOcclusionImage;
|
|
|
|
textureMetalnessRoughnessAmbientOcclusionImage = m_textureGenerator->takeResultTextureMetalnessRoughnessAmbientOcclusionImage();
|
|
|
|
|
2018-11-28 03:00:03 +00:00
|
|
|
delete textureMetalnessImage;
|
|
|
|
textureMetalnessImage = m_textureGenerator->takeResultTextureMetalnessImage();
|
|
|
|
|
|
|
|
delete textureRoughnessImage;
|
|
|
|
textureRoughnessImage = m_textureGenerator->takeResultTextureRoughnessImage();
|
|
|
|
|
|
|
|
delete textureAmbientOcclusionImage;
|
|
|
|
textureAmbientOcclusionImage = m_textureGenerator->takeResultTextureAmbientOcclusionImage();
|
|
|
|
|
2018-05-10 09:16:22 +00:00
|
|
|
delete m_resultTextureMesh;
|
|
|
|
m_resultTextureMesh = m_textureGenerator->takeResultMesh();
|
|
|
|
|
2018-05-11 05:27:29 +00:00
|
|
|
m_textureImageUpdateVersion++;
|
|
|
|
|
2018-05-07 16:08:19 +00:00
|
|
|
delete m_textureGenerator;
|
|
|
|
m_textureGenerator = nullptr;
|
|
|
|
|
|
|
|
qDebug() << "Texture guide generation done";
|
|
|
|
|
|
|
|
emit resultTextureChanged();
|
|
|
|
|
2018-08-27 08:50:40 +00:00
|
|
|
if (m_isTextureObsolete) {
|
2018-05-07 16:08:19 +00:00
|
|
|
generateTexture();
|
|
|
|
} else {
|
|
|
|
checkExportReadyState();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::postProcess()
|
2018-04-30 11:31:09 +00:00
|
|
|
{
|
2018-05-07 16:08:19 +00:00
|
|
|
if (nullptr != m_postProcessor) {
|
2018-08-27 08:50:40 +00:00
|
|
|
m_isPostProcessResultObsolete = true;
|
2018-05-07 16:08:19 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-08-27 08:50:40 +00:00
|
|
|
m_isPostProcessResultObsolete = false;
|
2018-05-07 16:08:19 +00:00
|
|
|
|
2018-10-26 23:04:45 +00:00
|
|
|
if (!m_currentOutcome) {
|
2018-05-07 17:16:58 +00:00
|
|
|
qDebug() << "MeshLoader is null";
|
2018-05-07 16:08:19 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-09-14 09:45:05 +00:00
|
|
|
qDebug() << "Post processing..";
|
|
|
|
|
2018-05-07 16:08:19 +00:00
|
|
|
QThread *thread = new QThread;
|
2018-10-26 23:04:45 +00:00
|
|
|
m_postProcessor = new MeshResultPostProcessor(*m_currentOutcome);
|
2018-05-07 16:08:19 +00:00
|
|
|
m_postProcessor->moveToThread(thread);
|
|
|
|
connect(thread, &QThread::started, m_postProcessor, &MeshResultPostProcessor::process);
|
2018-10-25 00:19:38 +00:00
|
|
|
connect(m_postProcessor, &MeshResultPostProcessor::finished, this, &Document::postProcessedMeshResultReady);
|
2018-05-07 16:08:19 +00:00
|
|
|
connect(m_postProcessor, &MeshResultPostProcessor::finished, thread, &QThread::quit);
|
|
|
|
connect(thread, &QThread::finished, thread, &QThread::deleteLater);
|
2018-10-09 02:19:12 +00:00
|
|
|
emit postProcessing();
|
2018-05-07 16:08:19 +00:00
|
|
|
thread->start();
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::postProcessedMeshResultReady()
|
2018-05-07 16:08:19 +00:00
|
|
|
{
|
2018-10-26 23:04:45 +00:00
|
|
|
delete m_postProcessedOutcome;
|
|
|
|
m_postProcessedOutcome = m_postProcessor->takePostProcessedOutcome();
|
2018-05-07 16:08:19 +00:00
|
|
|
|
|
|
|
delete m_postProcessor;
|
|
|
|
m_postProcessor = nullptr;
|
|
|
|
|
|
|
|
qDebug() << "Post process done";
|
|
|
|
|
|
|
|
emit postProcessedResultChanged();
|
|
|
|
|
2018-08-27 08:50:40 +00:00
|
|
|
if (m_isPostProcessResultObsolete) {
|
2018-05-07 16:08:19 +00:00
|
|
|
postProcess();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-26 23:04:45 +00:00
|
|
|
const Outcome &Document::currentPostProcessedOutcome() const
|
2018-05-07 16:08:19 +00:00
|
|
|
{
|
2018-10-26 23:04:45 +00:00
|
|
|
return *m_postProcessedOutcome;
|
2018-04-30 11:31:09 +00:00
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::setPartLockState(QUuid partId, bool locked)
|
2018-04-08 01:30:55 +00:00
|
|
|
{
|
|
|
|
auto part = partMap.find(partId);
|
|
|
|
if (part == partMap.end()) {
|
|
|
|
qDebug() << "Part not found:" << partId;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (part->second.locked == locked)
|
|
|
|
return;
|
|
|
|
part->second.locked = locked;
|
|
|
|
emit partLockStateChanged(partId);
|
2018-08-27 08:50:40 +00:00
|
|
|
emit optionsChanged();
|
2018-04-08 01:30:55 +00:00
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::setPartVisibleState(QUuid partId, bool visible)
|
2018-04-08 01:30:55 +00:00
|
|
|
{
|
|
|
|
auto part = partMap.find(partId);
|
|
|
|
if (part == partMap.end()) {
|
|
|
|
qDebug() << "Part not found:" << partId;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (part->second.visible == visible)
|
|
|
|
return;
|
|
|
|
part->second.visible = visible;
|
|
|
|
emit partVisibleStateChanged(partId);
|
2018-08-27 08:50:40 +00:00
|
|
|
emit optionsChanged();
|
2018-04-08 01:30:55 +00:00
|
|
|
}
|
|
|
|
|
2018-11-14 13:21:45 +00:00
|
|
|
void Document::setComponentCombineMode(QUuid componentId, CombineMode combineMode)
|
2018-06-16 06:41:52 +00:00
|
|
|
{
|
2018-08-27 08:50:40 +00:00
|
|
|
auto component = componentMap.find(componentId);
|
|
|
|
if (component == componentMap.end()) {
|
|
|
|
qDebug() << "Component not found:" << componentId;
|
2018-06-16 06:41:52 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-11-14 13:21:45 +00:00
|
|
|
if (component->second.combineMode == combineMode)
|
2018-06-16 06:41:52 +00:00
|
|
|
return;
|
2018-11-14 13:21:45 +00:00
|
|
|
component->second.combineMode = combineMode;
|
2018-08-27 08:50:40 +00:00
|
|
|
component->second.dirty = true;
|
2018-11-14 13:21:45 +00:00
|
|
|
emit componentCombineModeChanged(componentId);
|
2018-06-16 06:41:52 +00:00
|
|
|
emit skeletonChanged();
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::setComponentSmoothAll(QUuid componentId, float toSmoothAll)
|
2018-09-06 15:04:59 +00:00
|
|
|
{
|
|
|
|
auto component = componentMap.find(componentId);
|
|
|
|
if (component == componentMap.end()) {
|
|
|
|
qDebug() << "Component not found:" << componentId;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
component->second.setSmoothAll(toSmoothAll);
|
|
|
|
component->second.dirty = true;
|
|
|
|
emit componentSmoothAllChanged(componentId);
|
|
|
|
emit skeletonChanged();
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::setComponentSmoothSeam(QUuid componentId, float toSmoothSeam)
|
2018-09-06 15:04:59 +00:00
|
|
|
{
|
|
|
|
auto component = componentMap.find(componentId);
|
|
|
|
if (component == componentMap.end()) {
|
|
|
|
qDebug() << "Component not found:" << componentId;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
component->second.setSmoothSeam(toSmoothSeam);
|
|
|
|
component->second.dirty = true;
|
|
|
|
emit componentSmoothSeamChanged(componentId);
|
|
|
|
emit skeletonChanged();
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::setPartSubdivState(QUuid partId, bool subdived)
|
2018-04-08 01:30:55 +00:00
|
|
|
{
|
|
|
|
auto part = partMap.find(partId);
|
|
|
|
if (part == partMap.end()) {
|
|
|
|
qDebug() << "Part not found:" << partId;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (part->second.subdived == subdived)
|
|
|
|
return;
|
|
|
|
part->second.subdived = subdived;
|
2018-08-27 08:50:40 +00:00
|
|
|
part->second.dirty = true;
|
2018-04-08 01:30:55 +00:00
|
|
|
emit partSubdivStateChanged(partId);
|
|
|
|
emit skeletonChanged();
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::setPartDisableState(QUuid partId, bool disabled)
|
2018-04-11 09:19:27 +00:00
|
|
|
{
|
|
|
|
auto part = partMap.find(partId);
|
|
|
|
if (part == partMap.end()) {
|
|
|
|
qDebug() << "Part not found:" << partId;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (part->second.disabled == disabled)
|
|
|
|
return;
|
|
|
|
part->second.disabled = disabled;
|
2018-08-27 08:50:40 +00:00
|
|
|
part->second.dirty = true;
|
2018-04-11 09:19:27 +00:00
|
|
|
emit partDisableStateChanged(partId);
|
|
|
|
emit skeletonChanged();
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
const Component *Document::findComponentParent(QUuid componentId) const
|
2018-06-16 06:41:52 +00:00
|
|
|
{
|
2018-08-27 08:50:40 +00:00
|
|
|
auto component = componentMap.find(componentId);
|
|
|
|
if (component == componentMap.end()) {
|
|
|
|
qDebug() << "Component not found:" << componentId;
|
|
|
|
return nullptr;
|
2018-06-16 06:41:52 +00:00
|
|
|
}
|
|
|
|
|
2018-08-27 08:50:40 +00:00
|
|
|
if (component->second.parentId.isNull())
|
|
|
|
return &rootComponent;
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
return (Component *)findComponent(component->second.parentId);
|
2018-08-27 08:50:40 +00:00
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
QUuid Document::findComponentParentId(QUuid componentId) const
|
2018-08-27 08:50:40 +00:00
|
|
|
{
|
|
|
|
auto component = componentMap.find(componentId);
|
|
|
|
if (component == componentMap.end()) {
|
|
|
|
qDebug() << "Component not found:" << componentId;
|
|
|
|
return QUuid();
|
2018-06-16 06:41:52 +00:00
|
|
|
}
|
|
|
|
|
2018-08-27 08:50:40 +00:00
|
|
|
return component->second.parentId;
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::moveComponentUp(QUuid componentId)
|
2018-08-27 08:50:40 +00:00
|
|
|
{
|
2018-10-25 00:19:38 +00:00
|
|
|
Component *parent = (Component *)findComponentParent(componentId);
|
2018-08-27 08:50:40 +00:00
|
|
|
if (nullptr == parent)
|
|
|
|
return;
|
|
|
|
|
|
|
|
QUuid parentId = findComponentParentId(componentId);
|
|
|
|
|
|
|
|
parent->moveChildUp(componentId);
|
|
|
|
parent->dirty = true;
|
|
|
|
emit componentChildrenChanged(parentId);
|
|
|
|
emit skeletonChanged();
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::moveComponentDown(QUuid componentId)
|
2018-08-27 08:50:40 +00:00
|
|
|
{
|
2018-10-25 00:19:38 +00:00
|
|
|
Component *parent = (Component *)findComponentParent(componentId);
|
2018-08-27 08:50:40 +00:00
|
|
|
if (nullptr == parent)
|
2018-06-16 06:41:52 +00:00
|
|
|
return;
|
2018-08-27 08:50:40 +00:00
|
|
|
|
|
|
|
QUuid parentId = findComponentParentId(componentId);
|
|
|
|
|
|
|
|
parent->moveChildDown(componentId);
|
|
|
|
parent->dirty = true;
|
|
|
|
emit componentChildrenChanged(parentId);
|
2018-06-16 06:41:52 +00:00
|
|
|
emit skeletonChanged();
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::moveComponentToTop(QUuid componentId)
|
2018-06-16 06:41:52 +00:00
|
|
|
{
|
2018-10-25 00:19:38 +00:00
|
|
|
Component *parent = (Component *)findComponentParent(componentId);
|
2018-08-27 08:50:40 +00:00
|
|
|
if (nullptr == parent)
|
|
|
|
return;
|
|
|
|
|
|
|
|
QUuid parentId = findComponentParentId(componentId);
|
|
|
|
|
|
|
|
parent->moveChildToTop(componentId);
|
|
|
|
parent->dirty = true;
|
|
|
|
emit componentChildrenChanged(parentId);
|
|
|
|
emit skeletonChanged();
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::moveComponentToBottom(QUuid componentId)
|
2018-08-27 08:50:40 +00:00
|
|
|
{
|
2018-10-25 00:19:38 +00:00
|
|
|
Component *parent = (Component *)findComponentParent(componentId);
|
2018-08-27 08:50:40 +00:00
|
|
|
if (nullptr == parent)
|
|
|
|
return;
|
|
|
|
|
|
|
|
QUuid parentId = findComponentParentId(componentId);
|
|
|
|
|
|
|
|
parent->moveChildToBottom(componentId);
|
|
|
|
parent->dirty = true;
|
|
|
|
emit componentChildrenChanged(parentId);
|
|
|
|
emit skeletonChanged();
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::renameComponent(QUuid componentId, QString name)
|
2018-08-27 08:50:40 +00:00
|
|
|
{
|
|
|
|
auto component = componentMap.find(componentId);
|
|
|
|
if (component == componentMap.end()) {
|
|
|
|
qDebug() << "Component not found:" << componentId;
|
2018-06-16 06:41:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-08-27 08:50:40 +00:00
|
|
|
if (component->second.name == name)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!name.trimmed().isEmpty())
|
|
|
|
component->second.name = name;
|
|
|
|
emit componentNameChanged(componentId);
|
|
|
|
emit optionsChanged();
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::setComponentExpandState(QUuid componentId, bool expanded)
|
2018-08-27 08:50:40 +00:00
|
|
|
{
|
|
|
|
auto component = componentMap.find(componentId);
|
|
|
|
if (component == componentMap.end()) {
|
|
|
|
qDebug() << "Component not found:" << componentId;
|
2018-06-16 06:41:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-08-27 08:50:40 +00:00
|
|
|
if (component->second.expanded == expanded)
|
2018-06-16 06:41:52 +00:00
|
|
|
return;
|
2018-08-27 08:50:40 +00:00
|
|
|
|
|
|
|
component->second.expanded = expanded;
|
|
|
|
emit componentExpandStateChanged(componentId);
|
|
|
|
emit optionsChanged();
|
2018-06-16 06:41:52 +00:00
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::createNewComponentAndMoveThisIn(QUuid componentId)
|
2018-08-27 08:50:40 +00:00
|
|
|
{
|
|
|
|
auto component = componentMap.find(componentId);
|
|
|
|
if (component == componentMap.end()) {
|
|
|
|
qDebug() << "Component not found:" << componentId;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
Component *oldParent = (Component *)findComponentParent(componentId);
|
2018-08-27 08:50:40 +00:00
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
Component newParent(QUuid::createUuid());
|
2018-08-27 08:50:40 +00:00
|
|
|
newParent.name = tr("Group") + " " + QString::number(componentMap.size() - partMap.size() + 1);
|
|
|
|
|
|
|
|
oldParent->replaceChild(componentId, newParent.id);
|
|
|
|
newParent.parentId = oldParent->id;
|
|
|
|
newParent.addChild(componentId);
|
|
|
|
componentMap[newParent.id] = newParent;
|
|
|
|
|
|
|
|
component->second.parentId = newParent.id;
|
|
|
|
|
|
|
|
emit componentChildrenChanged(oldParent->id);
|
|
|
|
emit componentAdded(newParent.id);
|
|
|
|
emit optionsChanged();
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::createNewChildComponent(QUuid parentComponentId)
|
2018-09-07 10:13:55 +00:00
|
|
|
{
|
2018-10-25 00:19:38 +00:00
|
|
|
Component *parentComponent = (Component *)findComponent(parentComponentId);
|
2018-09-07 10:13:55 +00:00
|
|
|
if (!parentComponent->linkToPartId.isNull()) {
|
|
|
|
parentComponentId = parentComponent->parentId;
|
2018-10-25 00:19:38 +00:00
|
|
|
parentComponent = (Component *)findComponent(parentComponentId);
|
2018-09-07 10:13:55 +00:00
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
Component newComponent(QUuid::createUuid());
|
2018-09-07 10:13:55 +00:00
|
|
|
newComponent.name = tr("Group") + " " + QString::number(componentMap.size() - partMap.size() + 1);
|
|
|
|
|
|
|
|
parentComponent->addChild(newComponent.id);
|
|
|
|
newComponent.parentId = parentComponentId;
|
|
|
|
|
|
|
|
componentMap[newComponent.id] = newComponent;
|
|
|
|
|
|
|
|
emit componentChildrenChanged(parentComponentId);
|
|
|
|
emit componentAdded(newComponent.id);
|
|
|
|
emit optionsChanged();
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::removePart(QUuid partId)
|
2018-06-16 06:41:52 +00:00
|
|
|
{
|
|
|
|
auto part = partMap.find(partId);
|
|
|
|
if (part == partMap.end()) {
|
|
|
|
qDebug() << "Part not found:" << partId;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-08-27 08:50:40 +00:00
|
|
|
if (!part->second.componentId.isNull()) {
|
|
|
|
removeComponent(part->second.componentId);
|
2018-06-16 06:41:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-08-27 08:50:40 +00:00
|
|
|
removePartDontCareComponent(partId);
|
2018-06-16 06:41:52 +00:00
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::removePartDontCareComponent(QUuid partId)
|
2018-06-16 06:41:52 +00:00
|
|
|
{
|
|
|
|
auto part = partMap.find(partId);
|
|
|
|
if (part == partMap.end()) {
|
|
|
|
qDebug() << "Part not found:" << partId;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-08-27 08:50:40 +00:00
|
|
|
std::vector<QUuid> removedNodeIds;
|
|
|
|
std::vector<QUuid> removedEdgeIds;
|
|
|
|
|
|
|
|
for (auto nodeIt = nodeMap.begin(); nodeIt != nodeMap.end();) {
|
|
|
|
if (nodeIt->second.partId != partId) {
|
|
|
|
nodeIt++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
removedNodeIds.push_back(nodeIt->second.id);
|
|
|
|
nodeIt = nodeMap.erase(nodeIt);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto edgeIt = edgeMap.begin(); edgeIt != edgeMap.end();) {
|
|
|
|
if (edgeIt->second.partId != partId) {
|
|
|
|
edgeIt++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
removedEdgeIds.push_back(edgeIt->second.id);
|
|
|
|
edgeIt = edgeMap.erase(edgeIt);
|
|
|
|
}
|
|
|
|
|
|
|
|
partMap.erase(part);
|
|
|
|
|
|
|
|
for (const auto &nodeId: removedNodeIds) {
|
|
|
|
emit nodeRemoved(nodeId);
|
|
|
|
}
|
|
|
|
for (const auto &edgeId: removedEdgeIds) {
|
|
|
|
emit edgeRemoved(edgeId);
|
|
|
|
}
|
|
|
|
emit partRemoved(partId);
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::addPartToComponent(QUuid partId, QUuid componentId)
|
2018-08-27 08:50:40 +00:00
|
|
|
{
|
2018-10-25 00:19:38 +00:00
|
|
|
Component child(QUuid::createUuid());
|
2018-08-27 08:50:40 +00:00
|
|
|
|
|
|
|
if (!componentId.isNull()) {
|
|
|
|
auto parentComponent = componentMap.find(componentId);
|
|
|
|
if (parentComponent == componentMap.end()) {
|
|
|
|
componentId = QUuid();
|
|
|
|
rootComponent.addChild(child.id);
|
|
|
|
} else {
|
|
|
|
parentComponent->second.addChild(child.id);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
rootComponent.addChild(child.id);
|
|
|
|
}
|
|
|
|
|
|
|
|
partMap[partId].componentId = child.id;
|
|
|
|
child.linkToPartId = partId;
|
|
|
|
child.parentId = componentId;
|
|
|
|
componentMap[child.id] = child;
|
|
|
|
|
|
|
|
emit componentChildrenChanged(componentId);
|
|
|
|
emit componentAdded(child.id);
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::removeComponent(QUuid componentId)
|
2018-08-27 08:50:40 +00:00
|
|
|
{
|
|
|
|
removeComponentRecursively(componentId);
|
|
|
|
emit skeletonChanged();
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::removeComponentRecursively(QUuid componentId)
|
2018-08-27 08:50:40 +00:00
|
|
|
{
|
|
|
|
auto component = componentMap.find(componentId);
|
|
|
|
if (component == componentMap.end()) {
|
|
|
|
qDebug() << "Component not found:" << componentId;
|
2018-06-16 06:41:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-08-27 08:50:40 +00:00
|
|
|
if (!component->second.linkToPartId.isNull()) {
|
|
|
|
removePartDontCareComponent(component->second.linkToPartId);
|
|
|
|
}
|
|
|
|
|
2018-08-31 01:40:53 +00:00
|
|
|
auto childrenIds = component->second.childrenIds;
|
|
|
|
for (const auto &childId: childrenIds) {
|
|
|
|
removeComponentRecursively(childId);
|
|
|
|
}
|
|
|
|
|
2018-08-27 08:50:40 +00:00
|
|
|
QUuid parentId = component->second.parentId;
|
|
|
|
if (!parentId.isNull()) {
|
|
|
|
auto parentComponent = componentMap.find(parentId);
|
|
|
|
if (parentComponent == componentMap.end()) {
|
|
|
|
qDebug() << "Component not found:" << parentId;
|
|
|
|
}
|
|
|
|
parentComponent->second.dirty = true;
|
|
|
|
parentComponent->second.removeChild(componentId);
|
|
|
|
} else {
|
|
|
|
rootComponent.removeChild(componentId);
|
|
|
|
}
|
|
|
|
|
|
|
|
componentMap.erase(component);
|
|
|
|
emit componentRemoved(componentId);
|
|
|
|
emit componentChildrenChanged(parentId);
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::setCurrentCanvasComponentId(QUuid componentId)
|
2018-08-27 08:50:40 +00:00
|
|
|
{
|
|
|
|
m_currentCanvasComponentId = componentId;
|
2018-10-25 00:19:38 +00:00
|
|
|
const Component *component = findComponent(m_currentCanvasComponentId);
|
2018-09-07 10:13:55 +00:00
|
|
|
if (nullptr == component) {
|
|
|
|
//qDebug() << "Current component switch to nullptr componentId:" << componentId;
|
|
|
|
m_currentCanvasComponentId = QUuid();
|
|
|
|
} else {
|
|
|
|
//qDebug() << "Current component switch to " << component->name << "componentId:" << componentId;
|
|
|
|
if (!component->linkToPartId.isNull()) {
|
|
|
|
m_currentCanvasComponentId = component->parentId;
|
|
|
|
component = findComponent(m_currentCanvasComponentId);
|
|
|
|
//if (nullptr != component) {
|
|
|
|
// qDebug() << "Then switch to " << component->name << "componentId:" << m_currentCanvasComponentId;
|
|
|
|
//}
|
|
|
|
}
|
|
|
|
}
|
2018-08-27 08:50:40 +00:00
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::addComponent(QUuid parentId)
|
2018-08-27 08:50:40 +00:00
|
|
|
{
|
2018-10-25 00:19:38 +00:00
|
|
|
Component component(QUuid::createUuid());
|
2018-08-27 08:50:40 +00:00
|
|
|
|
|
|
|
if (!parentId.isNull()) {
|
|
|
|
auto parentComponent = componentMap.find(parentId);
|
|
|
|
if (parentComponent == componentMap.end()) {
|
|
|
|
qDebug() << "Component not found:" << parentId;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
parentComponent->second.addChild(component.id);
|
|
|
|
} else {
|
|
|
|
rootComponent.addChild(component.id);
|
|
|
|
}
|
|
|
|
|
|
|
|
component.parentId = parentId;
|
|
|
|
componentMap[component.id] = component;
|
|
|
|
|
|
|
|
emit componentChildrenChanged(parentId);
|
|
|
|
emit componentAdded(component.id);
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
bool Document::isDescendantComponent(QUuid componentId, QUuid suspiciousId)
|
2018-08-27 08:50:40 +00:00
|
|
|
{
|
2018-10-25 00:19:38 +00:00
|
|
|
const Component *loopComponent = findComponentParent(suspiciousId);
|
2018-08-27 08:50:40 +00:00
|
|
|
while (nullptr != loopComponent) {
|
|
|
|
if (loopComponent->id == componentId)
|
|
|
|
return true;
|
|
|
|
loopComponent = findComponentParent(loopComponent->parentId);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::moveComponent(QUuid componentId, QUuid toParentId)
|
2018-08-27 08:50:40 +00:00
|
|
|
{
|
|
|
|
if (componentId == toParentId)
|
2018-06-16 06:41:52 +00:00
|
|
|
return;
|
2018-08-27 08:50:40 +00:00
|
|
|
|
|
|
|
auto component = componentMap.find(componentId);
|
|
|
|
if (component == componentMap.end()) {
|
|
|
|
qDebug() << "Component not found:" << componentId;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (component->second.parentId == toParentId)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (isDescendantComponent(componentId, toParentId))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (component->second.parentId.isNull()) {
|
|
|
|
rootComponent.removeChild(componentId);
|
|
|
|
emit componentChildrenChanged(rootComponent.id);
|
|
|
|
} else {
|
|
|
|
auto oldParent = componentMap.find(component->second.parentId);
|
|
|
|
if (oldParent != componentMap.end()) {
|
|
|
|
oldParent->second.dirty = true;
|
|
|
|
oldParent->second.removeChild(componentId);
|
|
|
|
emit componentChildrenChanged(oldParent->second.id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
component->second.parentId = toParentId;
|
|
|
|
|
|
|
|
if (toParentId.isNull()) {
|
|
|
|
rootComponent.addChild(componentId);
|
|
|
|
emit componentChildrenChanged(rootComponent.id);
|
|
|
|
} else {
|
|
|
|
auto newParent = componentMap.find(toParentId);
|
|
|
|
if (newParent != componentMap.end()) {
|
|
|
|
newParent->second.dirty = true;
|
|
|
|
newParent->second.addChild(componentId);
|
|
|
|
emit componentChildrenChanged(newParent->second.id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-16 06:41:52 +00:00
|
|
|
emit skeletonChanged();
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::settleOrigin()
|
2018-04-15 12:11:51 +00:00
|
|
|
{
|
|
|
|
if (originSettled())
|
|
|
|
return;
|
2018-10-25 00:19:38 +00:00
|
|
|
Snapshot snapshot;
|
2018-04-15 12:11:51 +00:00
|
|
|
toSnapshot(&snapshot);
|
|
|
|
QRectF mainProfile;
|
|
|
|
QRectF sideProfile;
|
|
|
|
snapshot.resolveBoundingBox(&mainProfile, &sideProfile);
|
|
|
|
originX = mainProfile.x() + mainProfile.width() / 2;
|
|
|
|
originY = mainProfile.y() + mainProfile.height() / 2;
|
|
|
|
originZ = sideProfile.x() + sideProfile.width() / 2;
|
2018-08-27 08:50:40 +00:00
|
|
|
markAllDirty();
|
2018-04-15 12:11:51 +00:00
|
|
|
emit originChanged();
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::setPartXmirrorState(QUuid partId, bool mirrored)
|
2018-04-15 12:11:51 +00:00
|
|
|
{
|
|
|
|
auto part = partMap.find(partId);
|
|
|
|
if (part == partMap.end()) {
|
|
|
|
qDebug() << "Part not found:" << partId;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (part->second.xMirrored == mirrored)
|
|
|
|
return;
|
|
|
|
part->second.xMirrored = mirrored;
|
2018-08-27 08:50:40 +00:00
|
|
|
part->second.dirty = true;
|
2018-04-15 12:11:51 +00:00
|
|
|
settleOrigin();
|
|
|
|
emit partXmirrorStateChanged(partId);
|
|
|
|
emit skeletonChanged();
|
|
|
|
}
|
|
|
|
|
2019-03-17 14:04:12 +00:00
|
|
|
//void Document::setPartZmirrorState(QUuid partId, bool mirrored)
|
|
|
|
//{
|
|
|
|
// auto part = partMap.find(partId);
|
|
|
|
// if (part == partMap.end()) {
|
|
|
|
// qDebug() << "Part not found:" << partId;
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
// if (part->second.zMirrored == mirrored)
|
|
|
|
// return;
|
|
|
|
// part->second.zMirrored = mirrored;
|
|
|
|
// part->second.dirty = true;
|
|
|
|
// settleOrigin();
|
|
|
|
// emit partZmirrorStateChanged(partId);
|
|
|
|
// emit skeletonChanged();
|
|
|
|
//}
|
2018-04-15 12:11:51 +00:00
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::setPartDeformThickness(QUuid partId, float thickness)
|
2018-04-17 13:13:32 +00:00
|
|
|
{
|
|
|
|
auto part = partMap.find(partId);
|
|
|
|
if (part == partMap.end()) {
|
|
|
|
qDebug() << "Part not found:" << partId;
|
|
|
|
return;
|
|
|
|
}
|
2018-04-17 16:14:31 +00:00
|
|
|
part->second.setDeformThickness(thickness);
|
2018-08-27 08:50:40 +00:00
|
|
|
part->second.dirty = true;
|
2018-04-17 16:14:31 +00:00
|
|
|
emit partDeformThicknessChanged(partId);
|
|
|
|
emit skeletonChanged();
|
|
|
|
}
|
|
|
|
|
2019-05-20 13:38:01 +00:00
|
|
|
void Document::setPartBase(QUuid partId, PartBase base)
|
|
|
|
{
|
|
|
|
auto part = partMap.find(partId);
|
|
|
|
if (part == partMap.end()) {
|
|
|
|
qDebug() << "Part not found:" << partId;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (part->second.base == base)
|
|
|
|
return;
|
|
|
|
part->second.base = base;
|
|
|
|
part->second.dirty = true;
|
|
|
|
emit partBaseChanged(partId);
|
|
|
|
emit skeletonChanged();
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::setPartDeformWidth(QUuid partId, float width)
|
2018-04-17 16:14:31 +00:00
|
|
|
{
|
|
|
|
auto part = partMap.find(partId);
|
|
|
|
if (part == partMap.end()) {
|
|
|
|
qDebug() << "Part not found:" << partId;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
part->second.setDeformWidth(width);
|
2018-08-27 08:50:40 +00:00
|
|
|
part->second.dirty = true;
|
2018-04-17 16:14:31 +00:00
|
|
|
emit partDeformWidthChanged(partId);
|
2018-04-17 13:13:32 +00:00
|
|
|
emit skeletonChanged();
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::setPartMaterialId(QUuid partId, QUuid materialId)
|
2018-10-04 12:51:01 +00:00
|
|
|
{
|
|
|
|
auto part = partMap.find(partId);
|
|
|
|
if (part == partMap.end()) {
|
|
|
|
qDebug() << "Part not found:" << partId;
|
|
|
|
return;
|
|
|
|
}
|
2018-10-09 02:19:12 +00:00
|
|
|
if (part->second.materialId == materialId)
|
2018-10-04 12:51:01 +00:00
|
|
|
return;
|
2018-10-09 02:19:12 +00:00
|
|
|
part->second.materialId = materialId;
|
2018-10-04 12:51:01 +00:00
|
|
|
part->second.dirty = true;
|
2018-10-09 02:19:12 +00:00
|
|
|
emit partMaterialIdChanged(partId);
|
2018-10-09 09:17:44 +00:00
|
|
|
emit textureChanged();
|
2018-10-04 12:51:01 +00:00
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::setPartRoundState(QUuid partId, bool rounded)
|
2018-04-26 02:23:22 +00:00
|
|
|
{
|
|
|
|
auto part = partMap.find(partId);
|
|
|
|
if (part == partMap.end()) {
|
|
|
|
qDebug() << "Part not found:" << partId;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (part->second.rounded == rounded)
|
|
|
|
return;
|
|
|
|
part->second.rounded = rounded;
|
2018-08-27 08:50:40 +00:00
|
|
|
part->second.dirty = true;
|
2018-04-26 02:23:22 +00:00
|
|
|
emit partRoundStateChanged(partId);
|
|
|
|
emit skeletonChanged();
|
|
|
|
}
|
|
|
|
|
2019-03-09 22:10:39 +00:00
|
|
|
void Document::setPartChamferState(QUuid partId, bool chamfered)
|
|
|
|
{
|
|
|
|
auto part = partMap.find(partId);
|
|
|
|
if (part == partMap.end()) {
|
|
|
|
qDebug() << "Part not found:" << partId;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (part->second.chamfered == chamfered)
|
|
|
|
return;
|
|
|
|
part->second.chamfered = chamfered;
|
|
|
|
part->second.dirty = true;
|
|
|
|
emit partChamferStateChanged(partId);
|
|
|
|
emit skeletonChanged();
|
|
|
|
}
|
|
|
|
|
2019-05-19 03:21:38 +00:00
|
|
|
void Document::setPartTarget(QUuid partId, PartTarget target)
|
|
|
|
{
|
|
|
|
auto part = partMap.find(partId);
|
|
|
|
if (part == partMap.end()) {
|
|
|
|
qDebug() << "Part not found:" << partId;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (part->second.target == target)
|
|
|
|
return;
|
|
|
|
part->second.target = target;
|
|
|
|
part->second.dirty = true;
|
|
|
|
emit partTargetChanged(partId);
|
|
|
|
emit skeletonChanged();
|
|
|
|
}
|
|
|
|
|
2019-05-25 23:24:24 +00:00
|
|
|
void Document::setPartColorSolubility(QUuid partId, float solubility)
|
|
|
|
{
|
|
|
|
auto part = partMap.find(partId);
|
|
|
|
if (part == partMap.end()) {
|
|
|
|
qDebug() << "Part not found:" << partId;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (qFuzzyCompare(part->second.colorSolubility, solubility))
|
|
|
|
return;
|
|
|
|
part->second.colorSolubility = solubility;
|
|
|
|
part->second.dirty = true;
|
|
|
|
emit partColorSolubilityChanged(partId);
|
|
|
|
emit skeletonChanged();
|
|
|
|
}
|
|
|
|
|
2019-02-21 22:48:15 +00:00
|
|
|
void Document::setPartCutRotation(QUuid partId, float cutRotation)
|
2018-08-31 04:54:32 +00:00
|
|
|
{
|
|
|
|
auto part = partMap.find(partId);
|
|
|
|
if (part == partMap.end()) {
|
|
|
|
qDebug() << "Part not found:" << partId;
|
|
|
|
return;
|
|
|
|
}
|
2019-02-24 13:42:23 +00:00
|
|
|
if (qFuzzyCompare(cutRotation, part->second.cutRotation))
|
|
|
|
return;
|
2019-02-21 22:48:15 +00:00
|
|
|
part->second.setCutRotation(cutRotation);
|
2018-08-31 04:54:32 +00:00
|
|
|
part->second.dirty = true;
|
2019-02-21 22:48:15 +00:00
|
|
|
emit partCutRotationChanged(partId);
|
2018-08-31 04:54:32 +00:00
|
|
|
emit skeletonChanged();
|
|
|
|
}
|
|
|
|
|
2019-05-05 12:49:26 +00:00
|
|
|
void Document::setPartCutFace(QUuid partId, CutFace cutFace)
|
2019-02-24 13:42:23 +00:00
|
|
|
{
|
|
|
|
auto part = partMap.find(partId);
|
|
|
|
if (part == partMap.end()) {
|
|
|
|
qDebug() << "Part not found:" << partId;
|
|
|
|
return;
|
|
|
|
}
|
2019-05-05 12:49:26 +00:00
|
|
|
if (part->second.cutFace == cutFace)
|
2019-02-24 13:42:23 +00:00
|
|
|
return;
|
2019-05-05 12:49:26 +00:00
|
|
|
part->second.setCutFace(cutFace);
|
2019-02-24 13:42:23 +00:00
|
|
|
part->second.dirty = true;
|
2019-05-19 03:21:38 +00:00
|
|
|
emit partCutFaceChanged(partId);
|
|
|
|
emit skeletonChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Document::setPartCutFaceLinkedId(QUuid partId, QUuid linkedId)
|
|
|
|
{
|
|
|
|
auto part = partMap.find(partId);
|
|
|
|
if (part == partMap.end()) {
|
|
|
|
qDebug() << "Part not found:" << partId;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (part->second.cutFace == CutFace::UserDefined &&
|
|
|
|
part->second.cutFaceLinkedId == linkedId)
|
|
|
|
return;
|
|
|
|
part->second.setCutFaceLinkedId(linkedId);
|
|
|
|
part->second.dirty = true;
|
2019-05-05 12:49:26 +00:00
|
|
|
emit partCutFaceChanged(partId);
|
2019-02-24 13:42:23 +00:00
|
|
|
emit skeletonChanged();
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::setPartColorState(QUuid partId, bool hasColor, QColor color)
|
2018-04-26 02:23:22 +00:00
|
|
|
{
|
|
|
|
auto part = partMap.find(partId);
|
|
|
|
if (part == partMap.end()) {
|
|
|
|
qDebug() << "Part not found:" << partId;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (part->second.hasColor == hasColor && part->second.color == color)
|
|
|
|
return;
|
|
|
|
part->second.hasColor = hasColor;
|
|
|
|
part->second.color = color;
|
2018-08-27 08:50:40 +00:00
|
|
|
part->second.dirty = true;
|
2018-04-26 02:23:22 +00:00
|
|
|
emit partColorStateChanged(partId);
|
|
|
|
emit skeletonChanged();
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::saveSnapshot()
|
2018-04-08 23:34:46 +00:00
|
|
|
{
|
2018-10-25 00:19:38 +00:00
|
|
|
HistoryItem item;
|
2018-04-08 23:34:46 +00:00
|
|
|
toSnapshot(&item.snapshot);
|
2018-10-25 06:27:59 +00:00
|
|
|
item.hash = item.snapshot.hash();
|
|
|
|
if (!m_undoItems.empty() && item.hash == m_undoItems[m_undoItems.size() - 1].hash) {
|
|
|
|
qDebug() << "Snapshot has the same hash:" << item.hash << "skipped";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (m_undoItems.size() + 1 > m_maxSnapshot)
|
|
|
|
m_undoItems.pop_front();
|
2018-04-08 23:34:46 +00:00
|
|
|
m_undoItems.push_back(item);
|
2018-10-25 06:27:59 +00:00
|
|
|
qDebug() << "Snapshot saved with hash:" << item.hash << " History count:" << m_undoItems.size();
|
2018-04-08 23:34:46 +00:00
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::undo()
|
2018-04-08 23:34:46 +00:00
|
|
|
{
|
2018-10-25 06:27:59 +00:00
|
|
|
if (!undoable())
|
2018-04-08 23:34:46 +00:00
|
|
|
return;
|
|
|
|
m_redoItems.push_back(m_undoItems.back());
|
|
|
|
m_undoItems.pop_back();
|
2018-10-25 06:27:59 +00:00
|
|
|
const auto &item = m_undoItems.back();
|
|
|
|
fromSnapshot(item.snapshot);
|
2018-04-08 23:34:46 +00:00
|
|
|
qDebug() << "Undo/Redo items:" << m_undoItems.size() << m_redoItems.size();
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::redo()
|
2018-04-08 23:34:46 +00:00
|
|
|
{
|
|
|
|
if (m_redoItems.empty())
|
|
|
|
return;
|
|
|
|
m_undoItems.push_back(m_redoItems.back());
|
2018-10-25 06:27:59 +00:00
|
|
|
const auto &item = m_redoItems.back();
|
|
|
|
fromSnapshot(item.snapshot);
|
2018-04-08 23:34:46 +00:00
|
|
|
m_redoItems.pop_back();
|
|
|
|
qDebug() << "Undo/Redo items:" << m_undoItems.size() << m_redoItems.size();
|
|
|
|
}
|
|
|
|
|
2018-10-25 06:27:59 +00:00
|
|
|
void Document::clearHistories()
|
|
|
|
{
|
|
|
|
m_undoItems.clear();
|
|
|
|
m_redoItems.clear();
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::paste()
|
2018-04-09 08:46:06 +00:00
|
|
|
{
|
|
|
|
const QClipboard *clipboard = QApplication::clipboard();
|
|
|
|
const QMimeData *mimeData = clipboard->mimeData();
|
|
|
|
if (mimeData->hasText()) {
|
|
|
|
QXmlStreamReader xmlStreamReader(mimeData->text());
|
2018-10-25 00:19:38 +00:00
|
|
|
Snapshot snapshot;
|
2018-04-09 08:46:06 +00:00
|
|
|
loadSkeletonFromXmlStream(&snapshot, xmlStreamReader);
|
2018-09-14 09:45:05 +00:00
|
|
|
addFromSnapshot(snapshot, true);
|
2018-04-09 08:46:06 +00:00
|
|
|
}
|
|
|
|
}
|
2018-04-09 14:24:30 +00:00
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
bool Document::hasPastableNodesInClipboard() const
|
2018-04-09 14:24:30 +00:00
|
|
|
{
|
|
|
|
const QClipboard *clipboard = QApplication::clipboard();
|
|
|
|
const QMimeData *mimeData = clipboard->mimeData();
|
|
|
|
if (mimeData->hasText()) {
|
2018-10-02 04:59:30 +00:00
|
|
|
if (-1 != mimeData->text().indexOf("<node "))
|
2018-09-21 07:10:18 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
bool Document::hasPastableMaterialsInClipboard() const
|
2018-10-09 02:19:12 +00:00
|
|
|
{
|
|
|
|
const QClipboard *clipboard = QApplication::clipboard();
|
|
|
|
const QMimeData *mimeData = clipboard->mimeData();
|
|
|
|
if (mimeData->hasText()) {
|
|
|
|
if (-1 != mimeData->text().indexOf("<material "))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
bool Document::hasPastablePosesInClipboard() const
|
2018-09-21 07:10:18 +00:00
|
|
|
{
|
|
|
|
const QClipboard *clipboard = QApplication::clipboard();
|
|
|
|
const QMimeData *mimeData = clipboard->mimeData();
|
|
|
|
if (mimeData->hasText()) {
|
2018-10-02 04:59:30 +00:00
|
|
|
if (-1 != mimeData->text().indexOf("<pose "))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
bool Document::hasPastableMotionsInClipboard() const
|
2018-10-02 04:59:30 +00:00
|
|
|
{
|
|
|
|
const QClipboard *clipboard = QApplication::clipboard();
|
|
|
|
const QMimeData *mimeData = clipboard->mimeData();
|
|
|
|
if (mimeData->hasText()) {
|
|
|
|
if (-1 != mimeData->text().indexOf("<motion "))
|
2018-04-09 14:24:30 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
bool Document::undoable() const
|
2018-04-09 15:10:23 +00:00
|
|
|
{
|
2018-10-25 06:27:59 +00:00
|
|
|
return m_undoItems.size() >= 2;
|
2018-04-09 15:10:23 +00:00
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
bool Document::redoable() const
|
2018-04-09 15:10:23 +00:00
|
|
|
{
|
|
|
|
return !m_redoItems.empty();
|
|
|
|
}
|
2018-04-13 00:19:31 +00:00
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
bool Document::isNodeEditable(QUuid nodeId) const
|
2018-04-13 00:19:31 +00:00
|
|
|
{
|
2018-11-03 08:09:42 +00:00
|
|
|
const SkeletonNode *node = findNode(nodeId);
|
2018-04-13 00:19:31 +00:00
|
|
|
if (!node) {
|
|
|
|
qDebug() << "Node id not found:" << nodeId;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return !isPartReadonly(node->partId);
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
bool Document::isEdgeEditable(QUuid edgeId) const
|
2018-04-13 00:19:31 +00:00
|
|
|
{
|
2018-11-03 08:09:42 +00:00
|
|
|
const SkeletonEdge *edge = findEdge(edgeId);
|
2018-04-13 00:19:31 +00:00
|
|
|
if (!edge) {
|
|
|
|
qDebug() << "Edge id not found:" << edgeId;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return !isPartReadonly(edge->partId);
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::setXlockState(bool locked)
|
2018-04-16 22:54:41 +00:00
|
|
|
{
|
|
|
|
if (xlocked == locked)
|
|
|
|
return;
|
|
|
|
xlocked = locked;
|
|
|
|
emit xlockStateChanged();
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::setYlockState(bool locked)
|
2018-04-16 22:54:41 +00:00
|
|
|
{
|
|
|
|
if (ylocked == locked)
|
|
|
|
return;
|
|
|
|
ylocked = locked;
|
|
|
|
emit ylockStateChanged();
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::setZlockState(bool locked)
|
2018-04-16 22:54:41 +00:00
|
|
|
{
|
|
|
|
if (zlocked == locked)
|
|
|
|
return;
|
|
|
|
zlocked = locked;
|
|
|
|
emit zlockStateChanged();
|
|
|
|
}
|
2018-05-07 16:08:19 +00:00
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::setRadiusLockState(bool locked)
|
2018-09-08 04:20:31 +00:00
|
|
|
{
|
|
|
|
if (radiusLocked == locked)
|
|
|
|
return;
|
|
|
|
radiusLocked = locked;
|
|
|
|
emit radiusLockStateChanged();
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
bool Document::isExportReady() const
|
2018-05-07 16:08:19 +00:00
|
|
|
{
|
2018-08-27 08:50:40 +00:00
|
|
|
if (m_isResultMeshObsolete ||
|
|
|
|
m_isTextureObsolete ||
|
|
|
|
m_isPostProcessResultObsolete ||
|
2018-09-14 09:45:05 +00:00
|
|
|
m_isRigObsolete ||
|
2018-05-07 16:08:19 +00:00
|
|
|
m_meshGenerator ||
|
|
|
|
m_textureGenerator ||
|
2018-09-14 09:45:05 +00:00
|
|
|
m_postProcessor ||
|
2018-10-23 14:57:47 +00:00
|
|
|
m_rigGenerator ||
|
|
|
|
m_motionsGenerator)
|
2018-05-07 16:08:19 +00:00
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::checkExportReadyState()
|
2018-05-07 16:08:19 +00:00
|
|
|
{
|
|
|
|
if (isExportReady())
|
|
|
|
emit exportReady();
|
|
|
|
}
|
2018-06-15 05:34:41 +00:00
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::setSharedContextWidget(QOpenGLWidget *sharedContextWidget)
|
2018-08-27 08:50:40 +00:00
|
|
|
{
|
|
|
|
m_sharedContextWidget = sharedContextWidget;
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::collectComponentDescendantParts(QUuid componentId, std::vector<QUuid> &partIds) const
|
2018-08-27 08:50:40 +00:00
|
|
|
{
|
2018-10-25 00:19:38 +00:00
|
|
|
const Component *component = findComponent(componentId);
|
2018-08-27 08:50:40 +00:00
|
|
|
if (nullptr == component)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!component->linkToPartId.isNull()) {
|
|
|
|
partIds.push_back(component->linkToPartId);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const auto &childId: component->childrenIds) {
|
|
|
|
collectComponentDescendantParts(childId, partIds);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::collectComponentDescendantComponents(QUuid componentId, std::vector<QUuid> &componentIds) const
|
2018-08-27 08:50:40 +00:00
|
|
|
{
|
2018-10-25 00:19:38 +00:00
|
|
|
const Component *component = findComponent(componentId);
|
2018-08-27 08:50:40 +00:00
|
|
|
if (nullptr == component)
|
|
|
|
return;
|
2018-09-07 10:13:55 +00:00
|
|
|
|
2018-08-27 08:50:40 +00:00
|
|
|
if (!component->linkToPartId.isNull()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const auto &childId: component->childrenIds) {
|
2018-09-07 10:13:55 +00:00
|
|
|
componentIds.push_back(childId);
|
2018-08-27 08:50:40 +00:00
|
|
|
collectComponentDescendantComponents(childId, componentIds);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::hideOtherComponents(QUuid componentId)
|
2018-08-27 08:50:40 +00:00
|
|
|
{
|
|
|
|
std::vector<QUuid> partIds;
|
|
|
|
collectComponentDescendantParts(componentId, partIds);
|
|
|
|
std::set<QUuid> partIdSet;
|
|
|
|
for (const auto &partId: partIds) {
|
|
|
|
partIdSet.insert(partId);
|
|
|
|
}
|
|
|
|
for (const auto &part: partMap) {
|
|
|
|
if (partIdSet.find(part.first) != partIdSet.end())
|
|
|
|
continue;
|
|
|
|
setPartVisibleState(part.first, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::lockOtherComponents(QUuid componentId)
|
2018-08-27 08:50:40 +00:00
|
|
|
{
|
|
|
|
std::vector<QUuid> partIds;
|
|
|
|
collectComponentDescendantParts(componentId, partIds);
|
|
|
|
std::set<QUuid> partIdSet;
|
|
|
|
for (const auto &partId: partIds) {
|
|
|
|
partIdSet.insert(partId);
|
|
|
|
}
|
|
|
|
for (const auto &part: partMap) {
|
|
|
|
if (partIdSet.find(part.first) != partIdSet.end())
|
|
|
|
continue;
|
|
|
|
setPartLockState(part.first, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::hideAllComponents()
|
2018-08-27 08:50:40 +00:00
|
|
|
{
|
|
|
|
for (const auto &part: partMap) {
|
|
|
|
setPartVisibleState(part.first, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::showAllComponents()
|
2018-08-27 08:50:40 +00:00
|
|
|
{
|
|
|
|
for (const auto &part: partMap) {
|
|
|
|
setPartVisibleState(part.first, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::collapseAllComponents()
|
2018-08-27 08:50:40 +00:00
|
|
|
{
|
|
|
|
for (const auto &component: componentMap) {
|
|
|
|
if (!component.second.linkToPartId.isNull())
|
|
|
|
continue;
|
|
|
|
setComponentExpandState(component.first, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::expandAllComponents()
|
2018-08-27 08:50:40 +00:00
|
|
|
{
|
|
|
|
for (const auto &component: componentMap) {
|
|
|
|
if (!component.second.linkToPartId.isNull())
|
|
|
|
continue;
|
|
|
|
setComponentExpandState(component.first, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::lockAllComponents()
|
2018-08-27 08:50:40 +00:00
|
|
|
{
|
|
|
|
for (const auto &part: partMap) {
|
|
|
|
setPartLockState(part.first, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::unlockAllComponents()
|
2018-08-27 08:50:40 +00:00
|
|
|
{
|
|
|
|
for (const auto &part: partMap) {
|
|
|
|
setPartLockState(part.first, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::hideDescendantComponents(QUuid componentId)
|
2018-08-27 08:50:40 +00:00
|
|
|
{
|
|
|
|
std::vector<QUuid> partIds;
|
|
|
|
collectComponentDescendantParts(componentId, partIds);
|
|
|
|
for (const auto &partId: partIds) {
|
|
|
|
setPartVisibleState(partId, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::showDescendantComponents(QUuid componentId)
|
2018-08-27 08:50:40 +00:00
|
|
|
{
|
|
|
|
std::vector<QUuid> partIds;
|
|
|
|
collectComponentDescendantParts(componentId, partIds);
|
|
|
|
for (const auto &partId: partIds) {
|
|
|
|
setPartVisibleState(partId, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::lockDescendantComponents(QUuid componentId)
|
2018-08-27 08:50:40 +00:00
|
|
|
{
|
|
|
|
std::vector<QUuid> partIds;
|
|
|
|
collectComponentDescendantParts(componentId, partIds);
|
|
|
|
for (const auto &partId: partIds) {
|
|
|
|
setPartLockState(partId, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::unlockDescendantComponents(QUuid componentId)
|
2018-08-27 08:50:40 +00:00
|
|
|
{
|
|
|
|
std::vector<QUuid> partIds;
|
|
|
|
collectComponentDescendantParts(componentId, partIds);
|
|
|
|
for (const auto &partId: partIds) {
|
|
|
|
setPartLockState(partId, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::generateRig()
|
2018-09-14 09:45:05 +00:00
|
|
|
{
|
|
|
|
if (nullptr != m_rigGenerator) {
|
|
|
|
m_isRigObsolete = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_isRigObsolete = false;
|
|
|
|
|
2018-10-26 23:04:45 +00:00
|
|
|
if (RigType::None == rigType || nullptr == m_currentOutcome) {
|
2018-09-14 09:45:05 +00:00
|
|
|
removeRigResults();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
qDebug() << "Rig generating..";
|
|
|
|
|
|
|
|
QThread *thread = new QThread;
|
2018-11-01 15:24:06 +00:00
|
|
|
m_rigGenerator = new RigGenerator(rigType, *m_postProcessedOutcome);
|
2018-09-14 09:45:05 +00:00
|
|
|
m_rigGenerator->moveToThread(thread);
|
|
|
|
connect(thread, &QThread::started, m_rigGenerator, &RigGenerator::process);
|
2018-10-25 00:19:38 +00:00
|
|
|
connect(m_rigGenerator, &RigGenerator::finished, this, &Document::rigReady);
|
2018-09-14 09:45:05 +00:00
|
|
|
connect(m_rigGenerator, &RigGenerator::finished, thread, &QThread::quit);
|
|
|
|
connect(thread, &QThread::finished, thread, &QThread::deleteLater);
|
|
|
|
thread->start();
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::rigReady()
|
2018-09-14 09:45:05 +00:00
|
|
|
{
|
2018-10-02 04:59:30 +00:00
|
|
|
m_currentRigSucceed = m_rigGenerator->isSucceed();
|
|
|
|
|
2018-09-14 09:45:05 +00:00
|
|
|
delete m_resultRigWeightMesh;
|
|
|
|
m_resultRigWeightMesh = m_rigGenerator->takeResultMesh();
|
|
|
|
|
|
|
|
delete m_resultRigBones;
|
|
|
|
m_resultRigBones = m_rigGenerator->takeResultBones();
|
|
|
|
|
|
|
|
delete m_resultRigWeights;
|
|
|
|
m_resultRigWeights = m_rigGenerator->takeResultWeights();
|
|
|
|
|
2018-11-06 16:26:19 +00:00
|
|
|
m_resultRigMessages = m_rigGenerator->messages();
|
2018-09-14 09:45:05 +00:00
|
|
|
|
2018-10-26 23:04:45 +00:00
|
|
|
delete m_riggedOutcome;
|
|
|
|
m_riggedOutcome = m_rigGenerator->takeOutcome();
|
|
|
|
if (nullptr == m_riggedOutcome)
|
|
|
|
m_riggedOutcome = new Outcome;
|
2018-09-18 03:17:35 +00:00
|
|
|
|
2018-09-14 09:45:05 +00:00
|
|
|
delete m_rigGenerator;
|
|
|
|
m_rigGenerator = nullptr;
|
|
|
|
|
|
|
|
qDebug() << "Rig generation done";
|
|
|
|
|
|
|
|
emit resultRigChanged();
|
|
|
|
|
|
|
|
if (m_isRigObsolete) {
|
|
|
|
generateRig();
|
|
|
|
} else {
|
|
|
|
checkExportReadyState();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-26 23:04:45 +00:00
|
|
|
const std::vector<RiggerBone> *Document::resultRigBones() const
|
2018-09-14 09:45:05 +00:00
|
|
|
{
|
|
|
|
return m_resultRigBones;
|
|
|
|
}
|
|
|
|
|
2018-10-26 23:04:45 +00:00
|
|
|
const std::map<int, RiggerVertexWeights> *Document::resultRigWeights() const
|
2018-09-14 09:45:05 +00:00
|
|
|
{
|
|
|
|
return m_resultRigWeights;
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::removeRigResults()
|
2018-09-14 09:45:05 +00:00
|
|
|
{
|
|
|
|
delete m_resultRigBones;
|
|
|
|
m_resultRigBones = nullptr;
|
|
|
|
|
|
|
|
delete m_resultRigWeights;
|
|
|
|
m_resultRigWeights = nullptr;
|
|
|
|
|
|
|
|
delete m_resultRigWeightMesh;
|
|
|
|
m_resultRigWeightMesh = nullptr;
|
|
|
|
|
2018-11-06 16:26:19 +00:00
|
|
|
m_resultRigMessages.clear();
|
2018-09-14 09:45:05 +00:00
|
|
|
|
2018-10-21 23:56:56 +00:00
|
|
|
m_currentRigSucceed = false;
|
|
|
|
|
2018-09-14 09:45:05 +00:00
|
|
|
emit resultRigChanged();
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::setRigType(RigType toRigType)
|
2018-09-14 09:45:05 +00:00
|
|
|
{
|
|
|
|
if (rigType == toRigType)
|
|
|
|
return;
|
|
|
|
|
|
|
|
rigType = toRigType;
|
|
|
|
|
|
|
|
m_isRigObsolete = true;
|
|
|
|
|
|
|
|
removeRigResults();
|
|
|
|
|
|
|
|
emit rigTypeChanged();
|
|
|
|
emit rigChanged();
|
|
|
|
}
|
|
|
|
|
2018-11-06 16:26:19 +00:00
|
|
|
const std::vector<std::pair<QtMsgType, QString>> &Document::resultRigMessages() const
|
2018-09-14 09:45:05 +00:00
|
|
|
{
|
2018-11-06 16:26:19 +00:00
|
|
|
return m_resultRigMessages;
|
2018-09-14 09:45:05 +00:00
|
|
|
}
|
2018-09-18 03:17:35 +00:00
|
|
|
|
2018-10-26 23:04:45 +00:00
|
|
|
const Outcome &Document::currentRiggedOutcome() const
|
2018-09-18 03:17:35 +00:00
|
|
|
{
|
2018-10-26 23:04:45 +00:00
|
|
|
return *m_riggedOutcome;
|
2018-09-18 03:17:35 +00:00
|
|
|
}
|
2018-09-21 07:10:18 +00:00
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
bool Document::currentRigSucceed() const
|
2018-10-02 04:59:30 +00:00
|
|
|
{
|
|
|
|
return m_currentRigSucceed;
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::generateMotions()
|
2018-10-23 14:57:47 +00:00
|
|
|
{
|
|
|
|
if (nullptr != m_motionsGenerator) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-26 23:04:45 +00:00
|
|
|
const std::vector<RiggerBone> *rigBones = resultRigBones();
|
|
|
|
const std::map<int, RiggerVertexWeights> *rigWeights = resultRigWeights();
|
2018-10-23 14:57:47 +00:00
|
|
|
|
|
|
|
if (nullptr == rigBones || nullptr == rigWeights) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-11-01 15:24:06 +00:00
|
|
|
m_motionsGenerator = new MotionsGenerator(rigType, rigBones, rigWeights, currentRiggedOutcome());
|
2018-10-23 14:57:47 +00:00
|
|
|
bool hasDirtyMotion = false;
|
|
|
|
for (const auto &pose: poseMap) {
|
2019-06-19 12:57:38 +00:00
|
|
|
m_motionsGenerator->addPoseToLibrary(pose.first, pose.second.frames, pose.second.yTranslationScale);
|
2018-10-23 14:57:47 +00:00
|
|
|
}
|
|
|
|
for (auto &motion: motionMap) {
|
|
|
|
if (motion.second.dirty) {
|
|
|
|
hasDirtyMotion = true;
|
|
|
|
motion.second.dirty = false;
|
|
|
|
m_motionsGenerator->addRequirement(motion.first);
|
|
|
|
}
|
|
|
|
m_motionsGenerator->addMotionToLibrary(motion.first, motion.second.clips);
|
|
|
|
}
|
|
|
|
if (!hasDirtyMotion) {
|
|
|
|
delete m_motionsGenerator;
|
|
|
|
m_motionsGenerator = nullptr;
|
|
|
|
checkExportReadyState();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
qDebug() << "Motions generating..";
|
|
|
|
|
|
|
|
QThread *thread = new QThread;
|
|
|
|
m_motionsGenerator->moveToThread(thread);
|
|
|
|
connect(thread, &QThread::started, m_motionsGenerator, &MotionsGenerator::process);
|
2018-10-25 00:19:38 +00:00
|
|
|
connect(m_motionsGenerator, &MotionsGenerator::finished, this, &Document::motionsReady);
|
2018-10-23 14:57:47 +00:00
|
|
|
connect(m_motionsGenerator, &MotionsGenerator::finished, thread, &QThread::quit);
|
|
|
|
connect(thread, &QThread::finished, thread, &QThread::deleteLater);
|
|
|
|
thread->start();
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::motionsReady()
|
2018-10-23 14:57:47 +00:00
|
|
|
{
|
|
|
|
for (auto &motionId: m_motionsGenerator->generatedMotionIds()) {
|
|
|
|
auto motion = motionMap.find(motionId);
|
|
|
|
if (motion != motionMap.end()) {
|
|
|
|
auto resultPreviewMeshs = m_motionsGenerator->takeResultPreviewMeshs(motionId);
|
|
|
|
motion->second.updatePreviewMeshs(resultPreviewMeshs);
|
|
|
|
motion->second.jointNodeTrees = m_motionsGenerator->takeResultJointNodeTrees(motionId);
|
|
|
|
emit motionPreviewChanged(motionId);
|
|
|
|
emit motionResultChanged(motionId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
delete m_motionsGenerator;
|
|
|
|
m_motionsGenerator = nullptr;
|
|
|
|
|
|
|
|
qDebug() << "Motions generation done";
|
|
|
|
|
|
|
|
generateMotions();
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::generatePosePreviews()
|
2018-09-21 07:10:18 +00:00
|
|
|
{
|
|
|
|
if (nullptr != m_posePreviewsGenerator) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-26 23:04:45 +00:00
|
|
|
const std::vector<RiggerBone> *rigBones = resultRigBones();
|
|
|
|
const std::map<int, RiggerVertexWeights> *rigWeights = resultRigWeights();
|
2018-09-21 07:10:18 +00:00
|
|
|
|
|
|
|
if (nullptr == rigBones || nullptr == rigWeights) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-11-01 15:24:06 +00:00
|
|
|
m_posePreviewsGenerator = new PosePreviewsGenerator(rigType, rigBones,
|
2018-10-26 23:04:45 +00:00
|
|
|
rigWeights, *m_riggedOutcome);
|
2018-09-21 07:10:18 +00:00
|
|
|
bool hasDirtyPose = false;
|
|
|
|
for (auto &poseIt: poseMap) {
|
|
|
|
if (!poseIt.second.dirty)
|
|
|
|
continue;
|
2018-11-09 03:20:48 +00:00
|
|
|
if (poseIt.second.frames.empty())
|
|
|
|
continue;
|
|
|
|
int middle = poseIt.second.frames.size() / 2;
|
|
|
|
if (middle >= (int)poseIt.second.frames.size())
|
|
|
|
middle = 0;
|
|
|
|
m_posePreviewsGenerator->addPose({poseIt.first, middle}, poseIt.second.frames[middle].second);
|
2018-09-21 07:10:18 +00:00
|
|
|
poseIt.second.dirty = false;
|
|
|
|
hasDirtyPose = true;
|
|
|
|
}
|
|
|
|
if (!hasDirtyPose) {
|
|
|
|
delete m_posePreviewsGenerator;
|
|
|
|
m_posePreviewsGenerator = nullptr;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
qDebug() << "Pose previews generating..";
|
|
|
|
|
2018-10-23 14:57:47 +00:00
|
|
|
QThread *thread = new QThread;
|
2018-09-21 07:10:18 +00:00
|
|
|
m_posePreviewsGenerator->moveToThread(thread);
|
|
|
|
connect(thread, &QThread::started, m_posePreviewsGenerator, &PosePreviewsGenerator::process);
|
2018-10-25 00:19:38 +00:00
|
|
|
connect(m_posePreviewsGenerator, &PosePreviewsGenerator::finished, this, &Document::posePreviewsReady);
|
2018-09-21 07:10:18 +00:00
|
|
|
connect(m_posePreviewsGenerator, &PosePreviewsGenerator::finished, thread, &QThread::quit);
|
|
|
|
connect(thread, &QThread::finished, thread, &QThread::deleteLater);
|
|
|
|
thread->start();
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::posePreviewsReady()
|
2018-09-21 07:10:18 +00:00
|
|
|
{
|
2018-11-09 03:20:48 +00:00
|
|
|
for (const auto &poseIdAndFrame: m_posePreviewsGenerator->generatedPreviewPoseIdAndFrames()) {
|
|
|
|
auto pose = poseMap.find(poseIdAndFrame.first);
|
2018-09-21 07:10:18 +00:00
|
|
|
if (pose != poseMap.end()) {
|
2018-11-09 03:20:48 +00:00
|
|
|
MeshLoader *resultPartPreviewMesh = m_posePreviewsGenerator->takePreview(poseIdAndFrame);
|
2018-09-21 07:10:18 +00:00
|
|
|
pose->second.updatePreviewMesh(resultPartPreviewMesh);
|
2018-11-09 03:20:48 +00:00
|
|
|
emit posePreviewChanged(poseIdAndFrame.first);
|
2018-09-21 07:10:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
delete m_posePreviewsGenerator;
|
|
|
|
m_posePreviewsGenerator = nullptr;
|
|
|
|
|
|
|
|
qDebug() << "Pose previews generation done";
|
|
|
|
|
|
|
|
generatePosePreviews();
|
|
|
|
}
|
2018-10-09 02:19:12 +00:00
|
|
|
|
2018-11-09 15:07:26 +00:00
|
|
|
void Document::addMaterial(QUuid materialId, QString name, std::vector<MaterialLayer> layers)
|
2018-10-09 02:19:12 +00:00
|
|
|
{
|
2018-11-09 15:07:26 +00:00
|
|
|
QUuid newMaterialId = materialId;
|
2018-10-09 02:19:12 +00:00
|
|
|
auto &material = materialMap[newMaterialId];
|
|
|
|
material.id = newMaterialId;
|
|
|
|
|
|
|
|
material.name = name;
|
|
|
|
material.layers = layers;
|
|
|
|
material.dirty = true;
|
|
|
|
|
|
|
|
materialIdList.push_back(newMaterialId);
|
|
|
|
|
|
|
|
emit materialAdded(newMaterialId);
|
|
|
|
emit materialListChanged();
|
|
|
|
emit optionsChanged();
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::removeMaterial(QUuid materialId)
|
2018-10-09 02:19:12 +00:00
|
|
|
{
|
|
|
|
auto findMaterialResult = materialMap.find(materialId);
|
|
|
|
if (findMaterialResult == materialMap.end()) {
|
|
|
|
qDebug() << "Remove a none exist material:" << materialId;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
materialIdList.erase(std::remove(materialIdList.begin(), materialIdList.end(), materialId), materialIdList.end());
|
|
|
|
materialMap.erase(findMaterialResult);
|
|
|
|
|
|
|
|
emit materialListChanged();
|
|
|
|
emit materialRemoved(materialId);
|
|
|
|
emit optionsChanged();
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::setMaterialLayers(QUuid materialId, std::vector<MaterialLayer> layers)
|
2018-10-09 02:19:12 +00:00
|
|
|
{
|
|
|
|
auto findMaterialResult = materialMap.find(materialId);
|
|
|
|
if (findMaterialResult == materialMap.end()) {
|
|
|
|
qDebug() << "Find material failed:" << materialId;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
findMaterialResult->second.layers = layers;
|
|
|
|
findMaterialResult->second.dirty = true;
|
|
|
|
emit materialLayersChanged(materialId);
|
2018-10-09 09:17:44 +00:00
|
|
|
emit textureChanged();
|
2018-10-09 02:19:12 +00:00
|
|
|
emit optionsChanged();
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::renameMaterial(QUuid materialId, QString name)
|
2018-10-09 02:19:12 +00:00
|
|
|
{
|
|
|
|
auto findMaterialResult = materialMap.find(materialId);
|
|
|
|
if (findMaterialResult == materialMap.end()) {
|
|
|
|
qDebug() << "Find material failed:" << materialId;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (findMaterialResult->second.name == name)
|
|
|
|
return;
|
|
|
|
|
|
|
|
findMaterialResult->second.name = name;
|
|
|
|
emit materialNameChanged(materialId);
|
|
|
|
emit optionsChanged();
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::generateMaterialPreviews()
|
2018-10-09 02:19:12 +00:00
|
|
|
{
|
|
|
|
if (nullptr != m_materialPreviewsGenerator) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QThread *thread = new QThread;
|
|
|
|
m_materialPreviewsGenerator = new MaterialPreviewsGenerator();
|
|
|
|
bool hasDirtyMaterial = false;
|
|
|
|
for (auto &materialIt: materialMap) {
|
|
|
|
if (!materialIt.second.dirty)
|
|
|
|
continue;
|
|
|
|
m_materialPreviewsGenerator->addMaterial(materialIt.first, materialIt.second.layers);
|
|
|
|
materialIt.second.dirty = false;
|
|
|
|
hasDirtyMaterial = true;
|
|
|
|
}
|
|
|
|
if (!hasDirtyMaterial) {
|
|
|
|
delete m_materialPreviewsGenerator;
|
|
|
|
m_materialPreviewsGenerator = nullptr;
|
|
|
|
delete thread;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
qDebug() << "Material previews generating..";
|
|
|
|
|
|
|
|
m_materialPreviewsGenerator->moveToThread(thread);
|
|
|
|
connect(thread, &QThread::started, m_materialPreviewsGenerator, &MaterialPreviewsGenerator::process);
|
2018-10-25 00:19:38 +00:00
|
|
|
connect(m_materialPreviewsGenerator, &MaterialPreviewsGenerator::finished, this, &Document::materialPreviewsReady);
|
2018-10-09 02:19:12 +00:00
|
|
|
connect(m_materialPreviewsGenerator, &MaterialPreviewsGenerator::finished, thread, &QThread::quit);
|
|
|
|
connect(thread, &QThread::finished, thread, &QThread::deleteLater);
|
|
|
|
thread->start();
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
void Document::materialPreviewsReady()
|
2018-10-09 02:19:12 +00:00
|
|
|
{
|
|
|
|
for (const auto &materialId: m_materialPreviewsGenerator->generatedPreviewMaterialIds()) {
|
|
|
|
auto material = materialMap.find(materialId);
|
|
|
|
if (material != materialMap.end()) {
|
|
|
|
MeshLoader *resultPartPreviewMesh = m_materialPreviewsGenerator->takePreview(materialId);
|
|
|
|
material->second.updatePreviewMesh(resultPartPreviewMesh);
|
|
|
|
emit materialPreviewChanged(materialId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
delete m_materialPreviewsGenerator;
|
|
|
|
m_materialPreviewsGenerator = nullptr;
|
|
|
|
|
|
|
|
qDebug() << "Material previews generation done";
|
|
|
|
|
|
|
|
generateMaterialPreviews();
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:19:38 +00:00
|
|
|
bool Document::isMeshGenerating() const
|
2018-10-09 13:01:04 +00:00
|
|
|
{
|
|
|
|
return nullptr != m_meshGenerator;
|
|
|
|
}
|
|
|
|
|
2018-11-03 08:09:42 +00:00
|
|
|
void Document::copyNodes(std::set<QUuid> nodeIdSet) const
|
|
|
|
{
|
|
|
|
Snapshot snapshot;
|
|
|
|
toSnapshot(&snapshot, nodeIdSet, DocumentToSnapshotFor::Nodes);
|
|
|
|
QString snapshotXml;
|
|
|
|
QXmlStreamWriter xmlStreamWriter(&snapshotXml);
|
|
|
|
saveSkeletonToXmlStream(&snapshot, &xmlStreamWriter);
|
|
|
|
QClipboard *clipboard = QApplication::clipboard();
|
|
|
|
clipboard->setText(snapshotXml);
|
2018-11-05 15:47:21 +00:00
|
|
|
}
|