Save object in document only when locked for painting

master
huxingyi 2020-11-18 08:05:20 +09:30
parent 484f6aaaba
commit f6ea8bd206
3 changed files with 73 additions and 66 deletions

View File

@ -85,8 +85,6 @@ void AutoSaver::check()
Snapshot *snapshot = new Snapshot; Snapshot *snapshot = new Snapshot;
m_document->toSnapshot(snapshot); m_document->toSnapshot(snapshot);
Object *object = new Object(m_document->currentPostProcessedObject());
QByteArray *turnaroundPngByteArray = nullptr; QByteArray *turnaroundPngByteArray = nullptr;
if (!m_document->turnaround.isNull() && m_document->turnaroundPngByteArray.size() > 0) { if (!m_document->turnaround.isNull() && m_document->turnaroundPngByteArray.size() > 0) {
turnaroundPngByteArray = new QByteArray(m_document->turnaroundPngByteArray); turnaroundPngByteArray = new QByteArray(m_document->turnaroundPngByteArray);
@ -103,7 +101,12 @@ void AutoSaver::check()
scriptVariables = new std::map<QString, std::map<QString, QString>>(variables); scriptVariables = new std::map<QString, std::map<QString, QString>>(variables);
} }
DocumentSaver::Textures *textures = new DocumentSaver::Textures; 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) { if (nullptr != m_document->textureImage) {
textures->textureImage = new QImage(*m_document->textureImage); textures->textureImage = new QImage(*m_document->textureImage);
} }
@ -120,7 +123,7 @@ void AutoSaver::check()
textures->textureAmbientOcclusionImage = new QImage(*m_document->textureAmbientOcclusionImage); textures->textureAmbientOcclusionImage = new QImage(*m_document->textureAmbientOcclusionImage);
} }
textures->textureHasTransparencySettings = m_document->textureHasTransparencySettings; textures->textureHasTransparencySettings = m_document->textureHasTransparencySettings;
}
QThread *thread = new QThread; QThread *thread = new QThread;
m_documentSaver = new DocumentSaver(&m_filename, m_documentSaver = new DocumentSaver(&m_filename,
snapshot, snapshot,

View File

@ -109,7 +109,7 @@ bool DocumentSaver::save(const QString *filename,
ds3Writer.add("model.xml", "model", &modelXml); ds3Writer.add("model.xml", "model", &modelXml);
} }
{ if (nullptr != object) {
QByteArray objectXml; QByteArray objectXml;
QXmlStreamWriter stream(&objectXml); QXmlStreamWriter stream(&objectXml);
saveObjectToXmlStream(object, &stream); saveObjectToXmlStream(object, &stream);
@ -117,7 +117,7 @@ bool DocumentSaver::save(const QString *filename,
ds3Writer.add("object.xml", "object", &objectXml); ds3Writer.add("object.xml", "object", &objectXml);
} }
if (nullptr != textures) { if (nullptr != object && nullptr != textures) {
if (nullptr != textures->textureImage && !textures->textureImage->isNull()) { if (nullptr != textures->textureImage && !textures->textureImage->isNull()) {
if (nullptr == textures->textureImageByteArray) { if (nullptr == textures->textureImageByteArray) {
textures->textureImageByteArray = new QByteArray; textures->textureImageByteArray = new QByteArray;

View File

@ -1584,7 +1584,9 @@ void DocumentWindow::saveTo(const QString &saveAsFilename)
QApplication::setOverrideCursor(Qt::WaitCursor); QApplication::setOverrideCursor(Qt::WaitCursor);
Snapshot snapshot; Snapshot snapshot;
m_document->toSnapshot(&snapshot); m_document->toSnapshot(&snapshot);
bool saveObject = m_document->objectLocked;
DocumentSaver::Textures textures; DocumentSaver::Textures textures;
if (saveObject) {
textures.textureImage = m_document->textureImage; textures.textureImage = m_document->textureImage;
textures.textureImageByteArray = m_document->textureImageByteArray; textures.textureImageByteArray = m_document->textureImageByteArray;
textures.textureNormalImage = m_document->textureNormalImage; textures.textureNormalImage = m_document->textureNormalImage;
@ -1596,16 +1598,18 @@ void DocumentWindow::saveTo(const QString &saveAsFilename)
textures.textureAmbientOcclusionImage = m_document->textureAmbientOcclusionImage; textures.textureAmbientOcclusionImage = m_document->textureAmbientOcclusionImage;
textures.textureAmbientOcclusionImageByteArray = m_document->textureAmbientOcclusionImageByteArray; textures.textureAmbientOcclusionImageByteArray = m_document->textureAmbientOcclusionImageByteArray;
textures.textureHasTransparencySettings = m_document->textureHasTransparencySettings; textures.textureHasTransparencySettings = m_document->textureHasTransparencySettings;
}
if (DocumentSaver::save(&filename, if (DocumentSaver::save(&filename,
&snapshot, &snapshot,
&m_document->currentPostProcessedObject(), saveObject ? &m_document->currentPostProcessedObject() : nullptr,
&textures, saveObject ? &textures : nullptr,
(!m_document->turnaround.isNull() && m_document->turnaroundPngByteArray.size() > 0) ? (!m_document->turnaround.isNull() && m_document->turnaroundPngByteArray.size() > 0) ?
&m_document->turnaroundPngByteArray : nullptr, &m_document->turnaroundPngByteArray : nullptr,
(!m_document->script().isEmpty()) ? &m_document->script() : nullptr, (!m_document->script().isEmpty()) ? &m_document->script() : nullptr,
(!m_document->variables().empty()) ? &m_document->variables() : nullptr)) { (!m_document->variables().empty()) ? &m_document->variables() : nullptr)) {
setCurrentFilename(filename); setCurrentFilename(filename);
} }
if (saveObject) {
textures.textureImage = nullptr; textures.textureImage = nullptr;
textures.textureNormalImage = nullptr; textures.textureNormalImage = nullptr;
textures.textureMetalnessImage = nullptr; textures.textureMetalnessImage = nullptr;
@ -1636,7 +1640,7 @@ void DocumentWindow::saveTo(const QString &saveAsFilename)
std::swap(textures.textureAmbientOcclusionImageByteArray, m_document->textureAmbientOcclusionImageByteArray); std::swap(textures.textureAmbientOcclusionImageByteArray, m_document->textureAmbientOcclusionImageByteArray);
else else
textures.textureAmbientOcclusionImageByteArray = nullptr; textures.textureAmbientOcclusionImageByteArray = nullptr;
}
QApplication::restoreOverrideCursor(); QApplication::restoreOverrideCursor();
} }