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

@ -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<QString, std::map<QString, QString>>(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,

View File

@ -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;

View File

@ -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();
}