Fix deformMap of imported document not saved

- Save resources used by imported document
- Fix UV not generated if the final result is empty, even though there
  are uncombined or errored components
master
huxingyi 2020-04-12 11:35:39 +09:30
parent 610bc978a8
commit 0da8a23124
3 changed files with 64 additions and 45 deletions

View File

@ -40,6 +40,56 @@ void DocumentSaver::process()
emit finished(); emit finished();
} }
void DocumentSaver::collectUsedResourceIds(const Snapshot *snapshot,
std::set<QUuid> &imageIds,
std::set<QUuid> &fileIds)
{
for (const auto &material: snapshot->materials) {
for (auto &layer: material.second) {
for (auto &mapItem: layer.second) {
auto findImageIdString = mapItem.find("linkData");
if (findImageIdString == mapItem.end())
continue;
QUuid imageId = QUuid(findImageIdString->second);
imageIds.insert(imageId);
}
}
}
for (const auto &part: snapshot->parts) {
auto findImageIdString = part.second.find("deformMapImageId");
if (findImageIdString == part.second.end())
continue;
QUuid imageId = QUuid(findImageIdString->second);
imageIds.insert(imageId);
}
for (const auto &part: snapshot->parts) {
auto fillMeshLinkedIdString = part.second.find("fillMesh");
if (fillMeshLinkedIdString == part.second.end())
continue;
QUuid fileId = QUuid(fillMeshLinkedIdString->second);
if (fileId.isNull())
continue;
fileIds.insert(fileId);
const QByteArray *byteArray = FileForever::getContent(fileId);
if (nullptr == byteArray)
continue;
QXmlStreamReader stream(*byteArray);
Snapshot fileSnapshot;
loadSkeletonFromXmlStream(&fileSnapshot, stream, SNAPSHOT_ITEM_CANVAS | SNAPSHOT_ITEM_COMPONENT);
collectUsedResourceIds(&fileSnapshot, imageIds, fileIds);
}
for (auto &pose: snapshot->poses) {
auto findCanvasImageId = pose.first.find("canvasImageId");
if (findCanvasImageId != pose.first.end()) {
QUuid imageId = QUuid(findCanvasImageId->second);
imageIds.insert(imageId);
}
}
}
bool DocumentSaver::save(const QString *filename, bool DocumentSaver::save(const QString *filename,
Snapshot *snapshot, Snapshot *snapshot,
const QByteArray *turnaroundPngByteArray, const QByteArray *turnaroundPngByteArray,
@ -72,44 +122,7 @@ bool DocumentSaver::save(const QString *filename,
std::set<QUuid> imageIds; std::set<QUuid> imageIds;
std::set<QUuid> fileIds; std::set<QUuid> fileIds;
collectUsedResourceIds(snapshot, imageIds, fileIds);
for (const auto &material: snapshot->materials) {
for (auto &layer: material.second) {
for (auto &mapItem: layer.second) {
auto findImageIdString = mapItem.find("linkData");
if (findImageIdString == mapItem.end())
continue;
QUuid imageId = QUuid(findImageIdString->second);
imageIds.insert(imageId);
}
}
}
for (const auto &part: snapshot->parts) {
auto findImageIdString = part.second.find("deformMapImageId");
if (findImageIdString == part.second.end())
continue;
QUuid imageId = QUuid(findImageIdString->second);
imageIds.insert(imageId);
}
for (const auto &part: snapshot->parts) {
auto fillMeshLinkedIdString = part.second.find("fillMesh");
if (fillMeshLinkedIdString == part.second.end())
continue;
QUuid fileId = QUuid(fillMeshLinkedIdString->second);
if (fileId.isNull())
continue;
fileIds.insert(fileId);
}
for (auto &pose: snapshot->poses) {
auto findCanvasImageId = pose.first.find("canvasImageId");
if (findCanvasImageId != pose.first.end()) {
QUuid imageId = QUuid(findCanvasImageId->second);
imageIds.insert(imageId);
}
}
for (const auto &imageId: imageIds) { for (const auto &imageId: imageIds) {
const QByteArray *pngByteArray = ImageForever::getPngByteArray(imageId); const QByteArray *pngByteArray = ImageForever::getPngByteArray(imageId);

View File

@ -4,6 +4,8 @@
#include <QObject> #include <QObject>
#include <QByteArray> #include <QByteArray>
#include <map> #include <map>
#include <set>
#include <QUuid>
#include "snapshot.h" #include "snapshot.h"
class DocumentSaver : public QObject class DocumentSaver : public QObject
@ -21,6 +23,9 @@ public:
const QByteArray *turnaroundPngByteArray, const QByteArray *turnaroundPngByteArray,
const QString *script, const QString *script,
const std::map<QString, std::map<QString, QString>> *variables); const std::map<QString, std::map<QString, QString>> *variables);
static void collectUsedResourceIds(const Snapshot *snapshot,
std::set<QUuid> &imageIds,
std::set<QUuid> &fileIds);
signals: signals:
void finished(); void finished();
public slots: public slots:

View File

@ -1523,6 +1523,11 @@ void MeshGenerator::generate()
const auto &componentCache = m_cacheContext->components[QUuid().toString()]; const auto &componentCache = m_cacheContext->components[QUuid().toString()];
m_outcome->nodes = componentCache.outcomeNodes;
m_outcome->edges = componentCache.outcomeEdges;
m_outcome->paintMaps = componentCache.outcomePaintMaps;
m_outcome->nodeVertices = componentCache.outcomeNodeVertices;
std::vector<QVector3D> combinedVertices; std::vector<QVector3D> combinedVertices;
std::vector<std::vector<size_t>> combinedFaces; std::vector<std::vector<size_t>> combinedFaces;
if (nullptr != combinedMesh) { if (nullptr != combinedMesh) {
@ -1543,13 +1548,9 @@ void MeshGenerator::generate()
} while (affectedNum > 0); } while (affectedNum > 0);
} }
} }
m_outcome->nodes = componentCache.outcomeNodes;
m_outcome->edges = componentCache.outcomeEdges;
m_outcome->paintMaps = componentCache.outcomePaintMaps;
recoverQuads(combinedVertices, combinedFaces, componentCache.sharedQuadEdges, m_outcome->triangleAndQuads); recoverQuads(combinedVertices, combinedFaces, componentCache.sharedQuadEdges, m_outcome->triangleAndQuads);
m_outcome->nodeVertices = componentCache.outcomeNodeVertices; m_outcome->vertices = combinedVertices;
m_outcome->vertices = combinedVertices; m_outcome->triangles = combinedFaces;
m_outcome->triangles = combinedFaces;
} }
// Recursively check uncombined components // Recursively check uncombined components