From f6ea8bd2062f93a40554272fa82921094ee1cea6 Mon Sep 17 00:00:00 2001 From: huxingyi Date: Wed, 18 Nov 2020 08:05:20 +0930 Subject: [PATCH] Save object in document only when locked for painting --- src/autosaver.cpp | 43 +++++++++++--------- src/documentsaver.cpp | 4 +- src/documentwindow.cpp | 92 ++++++++++++++++++++++-------------------- 3 files changed, 73 insertions(+), 66 deletions(-) diff --git a/src/autosaver.cpp b/src/autosaver.cpp index 4bc8f205..77599a14 100644 --- a/src/autosaver.cpp +++ b/src/autosaver.cpp @@ -84,9 +84,7 @@ void AutoSaver::check() Snapshot *snapshot = new Snapshot; m_document->toSnapshot(snapshot); - - Object *object = new Object(m_document->currentPostProcessedObject()); - + QByteArray *turnaroundPngByteArray = nullptr; if (!m_document->turnaround.isNull() && m_document->turnaroundPngByteArray.size() > 0) { turnaroundPngByteArray = new QByteArray(m_document->turnaroundPngByteArray); @@ -103,24 +101,29 @@ void AutoSaver::check() scriptVariables = new std::map>(variables); } - DocumentSaver::Textures *textures = new DocumentSaver::Textures; - if (nullptr != m_document->textureImage) { - textures->textureImage = new QImage(*m_document->textureImage); - } - if (nullptr != m_document->textureNormalImage) { - textures->textureNormalImage = new QImage(*m_document->textureNormalImage); - } - if (nullptr != m_document->textureMetalnessImage) { - textures->textureMetalnessImage = new QImage(*m_document->textureMetalnessImage); - } - if (nullptr != m_document->textureRoughnessImage) { - textures->textureRoughnessImage = new QImage(*m_document->textureRoughnessImage); - } - if (nullptr != m_document->textureAmbientOcclusionImage) { - textures->textureAmbientOcclusionImage = new QImage(*m_document->textureAmbientOcclusionImage); - } - textures->textureHasTransparencySettings = m_document->textureHasTransparencySettings; + Object *object = nullptr; + DocumentSaver::Textures *textures = nullptr; + if (m_document->objectLocked) { + object = new Object(m_document->currentPostProcessedObject()); + textures = new DocumentSaver::Textures; + if (nullptr != m_document->textureImage) { + textures->textureImage = new QImage(*m_document->textureImage); + } + if (nullptr != m_document->textureNormalImage) { + textures->textureNormalImage = new QImage(*m_document->textureNormalImage); + } + if (nullptr != m_document->textureMetalnessImage) { + textures->textureMetalnessImage = new QImage(*m_document->textureMetalnessImage); + } + if (nullptr != m_document->textureRoughnessImage) { + textures->textureRoughnessImage = new QImage(*m_document->textureRoughnessImage); + } + if (nullptr != m_document->textureAmbientOcclusionImage) { + textures->textureAmbientOcclusionImage = new QImage(*m_document->textureAmbientOcclusionImage); + } + textures->textureHasTransparencySettings = m_document->textureHasTransparencySettings; + } QThread *thread = new QThread; m_documentSaver = new DocumentSaver(&m_filename, snapshot, diff --git a/src/documentsaver.cpp b/src/documentsaver.cpp index bc518ca0..08212add 100644 --- a/src/documentsaver.cpp +++ b/src/documentsaver.cpp @@ -109,7 +109,7 @@ bool DocumentSaver::save(const QString *filename, ds3Writer.add("model.xml", "model", &modelXml); } - { + if (nullptr != object) { QByteArray objectXml; QXmlStreamWriter stream(&objectXml); saveObjectToXmlStream(object, &stream); @@ -117,7 +117,7 @@ bool DocumentSaver::save(const QString *filename, ds3Writer.add("object.xml", "object", &objectXml); } - if (nullptr != textures) { + if (nullptr != object && nullptr != textures) { if (nullptr != textures->textureImage && !textures->textureImage->isNull()) { if (nullptr == textures->textureImageByteArray) { textures->textureImageByteArray = new QByteArray; diff --git a/src/documentwindow.cpp b/src/documentwindow.cpp index 0fdb767a..9faf0ddb 100644 --- a/src/documentwindow.cpp +++ b/src/documentwindow.cpp @@ -1584,59 +1584,63 @@ void DocumentWindow::saveTo(const QString &saveAsFilename) QApplication::setOverrideCursor(Qt::WaitCursor); Snapshot snapshot; m_document->toSnapshot(&snapshot); + bool saveObject = m_document->objectLocked; DocumentSaver::Textures textures; - textures.textureImage = m_document->textureImage; - textures.textureImageByteArray = m_document->textureImageByteArray; - textures.textureNormalImage = m_document->textureNormalImage; - textures.textureNormalImageByteArray = m_document->textureNormalImageByteArray; - textures.textureMetalnessImage = m_document->textureMetalnessImage; - textures.textureMetalnessImageByteArray = m_document->textureMetalnessImageByteArray; - textures.textureRoughnessImage = m_document->textureRoughnessImage; - textures.textureRoughnessImageByteArray = m_document->textureRoughnessImageByteArray; - textures.textureAmbientOcclusionImage = m_document->textureAmbientOcclusionImage; - textures.textureAmbientOcclusionImageByteArray = m_document->textureAmbientOcclusionImageByteArray; - textures.textureHasTransparencySettings = m_document->textureHasTransparencySettings; + if (saveObject) { + textures.textureImage = m_document->textureImage; + textures.textureImageByteArray = m_document->textureImageByteArray; + textures.textureNormalImage = m_document->textureNormalImage; + textures.textureNormalImageByteArray = m_document->textureNormalImageByteArray; + textures.textureMetalnessImage = m_document->textureMetalnessImage; + textures.textureMetalnessImageByteArray = m_document->textureMetalnessImageByteArray; + textures.textureRoughnessImage = m_document->textureRoughnessImage; + textures.textureRoughnessImageByteArray = m_document->textureRoughnessImageByteArray; + textures.textureAmbientOcclusionImage = m_document->textureAmbientOcclusionImage; + textures.textureAmbientOcclusionImageByteArray = m_document->textureAmbientOcclusionImageByteArray; + textures.textureHasTransparencySettings = m_document->textureHasTransparencySettings; + } if (DocumentSaver::save(&filename, &snapshot, - &m_document->currentPostProcessedObject(), - &textures, + saveObject ? &m_document->currentPostProcessedObject() : nullptr, + saveObject ? &textures : nullptr, (!m_document->turnaround.isNull() && m_document->turnaroundPngByteArray.size() > 0) ? &m_document->turnaroundPngByteArray : nullptr, (!m_document->script().isEmpty()) ? &m_document->script() : nullptr, (!m_document->variables().empty()) ? &m_document->variables() : nullptr)) { setCurrentFilename(filename); } - textures.textureImage = nullptr; - textures.textureNormalImage = nullptr; - textures.textureMetalnessImage = nullptr; - textures.textureRoughnessImage = nullptr; - textures.textureAmbientOcclusionImage = nullptr; - - if (textures.textureImageByteArray != m_document->textureImageByteArray) - std::swap(textures.textureImageByteArray, m_document->textureImageByteArray); - else - textures.textureImageByteArray = nullptr; - - if (textures.textureNormalImageByteArray != m_document->textureNormalImageByteArray) - std::swap(textures.textureNormalImageByteArray, m_document->textureNormalImageByteArray); - else - textures.textureNormalImageByteArray = nullptr; - - if (textures.textureMetalnessImageByteArray != m_document->textureMetalnessImageByteArray) - std::swap(textures.textureMetalnessImageByteArray, m_document->textureMetalnessImageByteArray); - else - textures.textureMetalnessImageByteArray = nullptr; - - if (textures.textureRoughnessImageByteArray != m_document->textureRoughnessImageByteArray) - std::swap(textures.textureRoughnessImageByteArray, m_document->textureRoughnessImageByteArray); - else - textures.textureRoughnessImageByteArray = nullptr; - - if (textures.textureAmbientOcclusionImageByteArray != m_document->textureAmbientOcclusionImageByteArray) - std::swap(textures.textureAmbientOcclusionImageByteArray, m_document->textureAmbientOcclusionImageByteArray); - else - textures.textureAmbientOcclusionImageByteArray = nullptr; - + if (saveObject) { + textures.textureImage = nullptr; + textures.textureNormalImage = nullptr; + textures.textureMetalnessImage = nullptr; + textures.textureRoughnessImage = nullptr; + textures.textureAmbientOcclusionImage = nullptr; + + if (textures.textureImageByteArray != m_document->textureImageByteArray) + std::swap(textures.textureImageByteArray, m_document->textureImageByteArray); + else + textures.textureImageByteArray = nullptr; + + if (textures.textureNormalImageByteArray != m_document->textureNormalImageByteArray) + std::swap(textures.textureNormalImageByteArray, m_document->textureNormalImageByteArray); + else + textures.textureNormalImageByteArray = nullptr; + + if (textures.textureMetalnessImageByteArray != m_document->textureMetalnessImageByteArray) + std::swap(textures.textureMetalnessImageByteArray, m_document->textureMetalnessImageByteArray); + else + textures.textureMetalnessImageByteArray = nullptr; + + if (textures.textureRoughnessImageByteArray != m_document->textureRoughnessImageByteArray) + std::swap(textures.textureRoughnessImageByteArray, m_document->textureRoughnessImageByteArray); + else + textures.textureRoughnessImageByteArray = nullptr; + + if (textures.textureAmbientOcclusionImageByteArray != m_document->textureAmbientOcclusionImageByteArray) + std::swap(textures.textureAmbientOcclusionImageByteArray, m_document->textureAmbientOcclusionImageByteArray); + else + textures.textureAmbientOcclusionImageByteArray = nullptr; + } QApplication::restoreOverrideCursor(); }