diff options
author | Tomi Korpipaa <tomi.korpipaa@qt.io> | 2018-05-29 09:39:31 +0300 |
---|---|---|
committer | Andy Nichols <andy.nichols@qt.io> | 2018-05-29 08:24:43 +0000 |
commit | 5f625401ebe432648208edc58fc8f862659284c4 (patch) | |
tree | e93d924c19c2dd76dcb601e2471a69d9abd9558f | |
parent | 1ffc64911a8add299a49426be5711f43959602b0 (diff) |
Clean up old mesh revisions from old presentations
Task-number: QT3DS-1790
Change-Id: I988a3f09ee4a9daaa4ce3dd08e2ae56850964cb0
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
-rw-r--r-- | src/Authoring/Client/Code/Core/Doc/Doc.cpp | 41 | ||||
-rw-r--r-- | src/Authoring/Client/Code/Core/Doc/Doc.h | 2 | ||||
-rw-r--r-- | src/Authoring/Client/Code/Core/Doc/DocumentEditor.cpp | 51 | ||||
-rw-r--r-- | src/Authoring/Client/Code/Core/Doc/IComposerSerializer.cpp | 46 | ||||
-rw-r--r-- | src/Authoring/Client/Code/Core/Doc/IDocumentEditor.h | 2 |
5 files changed, 83 insertions, 59 deletions
diff --git a/src/Authoring/Client/Code/Core/Doc/Doc.cpp b/src/Authoring/Client/Code/Core/Doc/Doc.cpp index bf9b3f27..96c54f4c 100644 --- a/src/Authoring/Client/Code/Core/Doc/Doc.cpp +++ b/src/Authoring/Client/Code/Core/Doc/Doc.cpp @@ -83,10 +83,12 @@ #include "EASTL/sort.h" #include "foundation/Qt3DSLogging.h" #include "Studio/Application/StudioApp.h" +#include "Dialogs.h" #include <QtCore/qfileinfo.h> #include <QtWidgets/qaction.h> #include <QtWidgets/qwidget.h> +#include <QtCore/qtimer.h> using std::ref; using std::shared_ptr; @@ -94,7 +96,7 @@ using std::shared_ptr; //============================================================================== // Constants //============================================================================== -const long STUDIO_FILE_VERSION = 3; +const long STUDIO_FILE_VERSION = 4; const long STUDIO_LAST_SUPPORTED_FILE_VERSION = 1; IMPLEMENT_OBJECT_COUNTER(CDoc) @@ -2111,7 +2113,7 @@ void CDoc::LoadPresentationFile(CBufferedInputStream *inInputStream) // Let any interested parties know that a presentation is going to be loaded m_Core->GetDispatch()->FireOnLoadingPresentation(); - LoadStudioData(inInputStream); + int uipVersion = LoadStudioData(inInputStream); // We have a new presentation and a new active time context (scene) OnNewPresentation(); @@ -2121,6 +2123,18 @@ void CDoc::LoadPresentationFile(CBufferedInputStream *inInputStream) m_StudioSystem->GetClientDataModelBridge()->GetComponentSlide(m_SceneInstance, 1); m_StudioSystem->GetFullSystem()->GetSignalSender()->SendActiveSlide(theMasterSlide, 1, theChildSlide); + + if (uipVersion == 3) { + m_SceneEditor->CleanUpMeshes(); + QTimer::singleShot(0, [](){ + g_StudioApp.OnSave(); + g_StudioApp.GetDialogs()->DisplayMessageBox( + tr("Old Presentation Version"), + tr("Presentation was in old format and had unoptimized meshes.\n" + "They were optimized, and presentation version was updated."), + Qt3DSMessageBox::ICON_INFO, false); + }); + } } //============================================================================== @@ -2129,11 +2143,12 @@ void CDoc::LoadPresentationFile(CBufferedInputStream *inInputStream) * Loads Studio object data from a presentation file archive. * @param inArchive CArchive from which to load the data objects. */ -void CDoc::LoadStudioData(CBufferedInputStream *inInputStream) +int CDoc::LoadStudioData(CBufferedInputStream *inInputStream) { using namespace std; using namespace qt3dsdm; using namespace Q3DStudio; + qt3ds::QT3DSI32 theVersion = 0; QT3DS_PROFILE(LoadStudioData); bool theModifiedFlag = false; @@ -2143,7 +2158,6 @@ void CDoc::LoadStudioData(CBufferedInputStream *inInputStream) // This cuts down on a lot of redraw calls. CDispatchDataModelNotificationScope __dispatchScope(*GetCore()->GetDispatch()); - qt3ds::QT3DSI32 theVersion = 0; { std::shared_ptr<IDOMReader> theReaderPtr = CreateDOMReader(*inInputStream, theVersion); @@ -2171,27 +2185,16 @@ void CDoc::LoadStudioData(CBufferedInputStream *inInputStream) // Setup the Presentation and Scene // Asset Graph has only one root and that's the scene m_SceneInstance = m_AssetGraph->GetRoot(0); - m_ActiveSlide = - m_StudioSystem->GetClientDataModelBridge()->GetComponentSlide(m_SceneInstance, 1); - // Update from version 1 to current version here - if (theVersion == 1) { - // Ensure the scene editor even exists. - GetDocumentReader(); - if (m_SceneGraph && m_SceneGraph->GetTextRenderer()) { - m_SceneGraph->GetTextRenderer()->ClearProjectFontDirectories(); - m_SceneGraph->GetTextRenderer()->AddProjectFontDirectory( - GetDocumentDirectory().GetCharStar()); - m_SceneEditor->ReplaceTextFontNameWithTextFileStem( - *m_SceneGraph->GetTextRenderer()); - theModifiedFlag = true; - } - } + m_ActiveSlide = m_StudioSystem->GetClientDataModelBridge()->GetComponentSlide( + m_SceneInstance, 1); } catch (...) { CleanupData(); throw; // pass the error along to the caller, so the appropriate error message can be // feedback } SetModifiedFlag(theModifiedFlag); + + return theVersion; } //============================================================================== diff --git a/src/Authoring/Client/Code/Core/Doc/Doc.h b/src/Authoring/Client/Code/Core/Doc/Doc.h index 4d1b6738..8d6225d3 100644 --- a/src/Authoring/Client/Code/Core/Doc/Doc.h +++ b/src/Authoring/Client/Code/Core/Doc/Doc.h @@ -419,7 +419,7 @@ protected: void CleanupData(); void ResetData(); - void LoadStudioData(CBufferedInputStream *inInputStream); + int LoadStudioData(CBufferedInputStream *inInputStream); void ResetDataCore(); void SetupDataCoreSignals(); diff --git a/src/Authoring/Client/Code/Core/Doc/DocumentEditor.cpp b/src/Authoring/Client/Code/Core/Doc/DocumentEditor.cpp index b7703bb4..f60ebd0b 100644 --- a/src/Authoring/Client/Code/Core/Doc/DocumentEditor.cpp +++ b/src/Authoring/Client/Code/Core/Doc/DocumentEditor.cpp @@ -85,6 +85,7 @@ #include <QtCore/qdir.h> #include <unordered_set> #include "Runtime/Include/q3dsqmlbehavior.h" +#include "Qt3DSFileToolsSeekableMeshBufIOStream.h" namespace { @@ -3638,6 +3639,56 @@ public: theDispatch.FireOnProgressEnd(); } + void CleanUpMeshes() override + { + CDispatch &theDispatch(*m_Doc.GetCore()->GetDispatch()); + theDispatch.FireOnProgressBegin( + Q3DStudio::CString::fromQString(QObject::tr("Old UIP version")), + Q3DStudio::CString::fromQString(QObject::tr("Cleaning up meshes"))); + ScopedBoolean __ignoredDirs(m_IgnoreDirChange); + try { + vector<CFilePath> importFileList; + m_SourcePathInstanceMap.clear(); + GetSourcePathToInstanceMap(m_SourcePathInstanceMap, false); + for (TCharPtrToSlideInstanceMap::iterator theIter = m_SourcePathInstanceMap.begin(), + end = m_SourcePathInstanceMap.end(); + theIter != end; ++theIter) { + CFilePath theSource(theIter->first); + if (theSource.GetExtension().Compare(L"mesh", CString::ENDOFSTRING, false)) { + CFilePath theFullPath = m_Doc.GetResolvedPathToDoc(theSource); + + if (!theFullPath.Exists() || !theFullPath.isFile()) + continue; + + Mesh *theMesh = Mesh::LoadMulti( + theFullPath.toCString().GetCharStar(), + Mesh::GetHighestMultiVersion( + theFullPath.toCString().GetCharStar())); + + if (!theMesh) + continue; + + // Import file still has revisions, so we need to use SaveMulti for saving + // the mesh file with correct revision number. + // Once import file revisioning has been removed (QT3DS-1815), this can be + // replaced with theMesh->Save(theFullPath.toCString().GetCharStar()); + // It also requires ripping the revisions out from the *.import files + Qt3DSFileToolsSeekableMeshBufIOStream output( + SFile::Wrap(SFile::OpenForWrite(theFullPath, FileWriteFlags()), + theFullPath)); + if (!output.IsOpen()) + QT3DS_ALWAYS_ASSERT_MESSAGE(theFullPath.toCString().GetCharStar()); + MallocAllocator allocator; + theMesh->SaveMulti(allocator, output); + + delete theMesh; + } + } + } catch (...) { + } + theDispatch.FireOnProgressEnd(); + } + void ExternalizePath(TInstanceHandle path) override { CFilePath thePathsDirectory( diff --git a/src/Authoring/Client/Code/Core/Doc/IComposerSerializer.cpp b/src/Authoring/Client/Code/Core/Doc/IComposerSerializer.cpp index c78fe7ea..257f88e1 100644 --- a/src/Authoring/Client/Code/Core/Doc/IComposerSerializer.cpp +++ b/src/Authoring/Client/Code/Core/Doc/IComposerSerializer.cpp @@ -1480,16 +1480,11 @@ struct SComposerSerializerImpl : public IComposerSerializer TPropertyHandleValuePairList &outProperties) { bool hasNoLifetime = - m_DataCore.IsInstanceOrDerivedFrom(inInstance, m_ObjectDefinitions.m_Image.m_Instance) + m_DataCore.IsInstanceOrDerivedFrom(inInstance, + m_ObjectDefinitions.m_Image.m_Instance) || m_DataCore.IsInstanceOrDerivedFrom(inInstance, m_ObjectDefinitions.m_Material.m_Instance); - bool checkConversionToV3LayerFormat = false; - if (m_UIPVersion.hasValue() && *m_UIPVersion < 3 - && m_DataCore.IsInstanceOrDerivedFrom(inInstance, - m_ObjectDefinitions.m_Layer.m_Instance)) - checkConversionToV3LayerFormat = true; - for (eastl::pair<TCharPtr, TCharPtr> theAtt = inReader.GetFirstAttribute(); !IsTrivial(theAtt.first); theAtt = inReader.GetNextAttribute()) { Option<pair<Qt3DSDMPropertyHandle, SValue>> theValue = @@ -1497,38 +1492,11 @@ struct SComposerSerializerImpl : public IComposerSerializer bool ignoreProperty = theValue.hasValue() == false || (hasNoLifetime && (theValue->first == m_ObjectDefinitions.m_Asset.m_StartTime.m_Property - || theValue->first == m_ObjectDefinitions.m_Asset.m_EndTime.m_Property)); - if (ignoreProperty) { - bool keepProperty = true; - if (checkConversionToV3LayerFormat) { - if (AreEqual(theAtt.first, L"location") || AreEqual(theAtt.first, L"size")) { - keepProperty = false; - SValue theValueUnion = ParseValue(DataModelDataType::Float2, theAtt.second); - SFloat2 theValue(theValueUnion.getData<SFloat2>()); - SValue theFirstValue(theValue.m_Floats[0]); - SValue theSecondValue(theValue.m_Floats[1]); - if (AreEqual(theAtt.first, L"location")) { - Qt3DSDMPropertyHandle theLeft, theTop; - theLeft = - m_DataCore.GetAggregateInstancePropertyByName(inInstance, L"left"); - theTop = - m_DataCore.GetAggregateInstancePropertyByName(inInstance, L"top"); - outProperties.push_back(std::make_pair(theLeft, theFirstValue)); - outProperties.push_back(std::make_pair(theTop, theSecondValue)); - } else { - Qt3DSDMPropertyHandle theWidth, theHeight; - theWidth = - m_DataCore.GetAggregateInstancePropertyByName(inInstance, L"width"); - theHeight = m_DataCore.GetAggregateInstancePropertyByName(inInstance, - L"height"); - outProperties.push_back(std::make_pair(theWidth, theFirstValue)); - outProperties.push_back(std::make_pair(theHeight, theSecondValue)); - } - } - } - if (keepProperty) - outExtraAttributes.push_back(std::make_pair(theAtt.first, theAtt.second)); - } else + || theValue->first + == m_ObjectDefinitions.m_Asset.m_EndTime.m_Property)); + if (ignoreProperty) + outExtraAttributes.push_back(std::make_pair(theAtt.first, theAtt.second)); + else outProperties.push_back(std::make_pair(theValue->first, theValue->second)); } } diff --git a/src/Authoring/Client/Code/Core/Doc/IDocumentEditor.h b/src/Authoring/Client/Code/Core/Doc/IDocumentEditor.h index c1bf158f..684c917a 100644 --- a/src/Authoring/Client/Code/Core/Doc/IDocumentEditor.h +++ b/src/Authoring/Client/Code/Core/Doc/IDocumentEditor.h @@ -399,6 +399,8 @@ public: // Absolute path to the file. virtual void RefreshImport(const CFilePath &inOldFile, const CFilePath &inNewFile) = 0; + virtual void CleanUpMeshes() = 0; + virtual void ReplaceTextFontNameWithTextFileStem(qt3ds::render::ITextRenderer &inRenderer) = 0; virtual void ExternalizePath(TInstanceHandle path) = 0; |