diff --git a/src/documentsaver.cpp b/src/documentsaver.cpp index a530bacd..937218cd 100644 --- a/src/documentsaver.cpp +++ b/src/documentsaver.cpp @@ -40,6 +40,56 @@ void DocumentSaver::process() emit finished(); } +void DocumentSaver::collectUsedResourceIds(const Snapshot *snapshot, + std::set &imageIds, + std::set &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, Snapshot *snapshot, const QByteArray *turnaroundPngByteArray, @@ -72,45 +122,8 @@ bool DocumentSaver::save(const QString *filename, std::set imageIds; std::set 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); - } - } - + collectUsedResourceIds(snapshot, imageIds, fileIds); + for (const auto &imageId: imageIds) { const QByteArray *pngByteArray = ImageForever::getPngByteArray(imageId); if (nullptr == pngByteArray) diff --git a/src/documentsaver.h b/src/documentsaver.h index cf7041df..5ff7e040 100644 --- a/src/documentsaver.h +++ b/src/documentsaver.h @@ -4,6 +4,8 @@ #include #include #include +#include +#include #include "snapshot.h" class DocumentSaver : public QObject @@ -21,6 +23,9 @@ public: const QByteArray *turnaroundPngByteArray, const QString *script, const std::map> *variables); + static void collectUsedResourceIds(const Snapshot *snapshot, + std::set &imageIds, + std::set &fileIds); signals: void finished(); public slots: diff --git a/src/meshgenerator.cpp b/src/meshgenerator.cpp index 3200ee90..94ccdb77 100644 --- a/src/meshgenerator.cpp +++ b/src/meshgenerator.cpp @@ -1523,6 +1523,11 @@ void MeshGenerator::generate() 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 combinedVertices; std::vector> combinedFaces; if (nullptr != combinedMesh) { @@ -1543,13 +1548,9 @@ void MeshGenerator::generate() } 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); - m_outcome->nodeVertices = componentCache.outcomeNodeVertices; - m_outcome->vertices = combinedVertices; - m_outcome->triangles = combinedFaces; + m_outcome->vertices = combinedVertices; + m_outcome->triangles = combinedFaces; } // Recursively check uncombined components