From 7ce09d1cd6104484184674d24db160690ffdcae2 Mon Sep 17 00:00:00 2001 From: Jeremy HU Date: Sun, 30 Oct 2022 19:08:03 +1100 Subject: [PATCH] Fix part cache --- application/sources/document.cc | 15 ++++++++------- application/sources/document.h | 4 ++-- application/sources/document_window.cc | 4 ++-- application/sources/uv_map_generator.cc | 2 +- dust3d/mesh/mesh_generator.cc | 14 +++----------- dust3d/mesh/mesh_generator.h | 24 ++++++++++++++++++++++++ 6 files changed, 40 insertions(+), 23 deletions(-) diff --git a/application/sources/document.cc b/application/sources/document.cc index 5913b697..2e8b1306 100644 --- a/application/sources/document.cc +++ b/application/sources/document.cc @@ -37,7 +37,6 @@ Document::~Document() { delete (dust3d::MeshGenerator::GeneratedCacheContext*)m_generatedCacheContext; delete m_resultMesh; - delete m_postProcessedObject; delete textureImage; delete textureImageByteArray; delete textureNormalImage; @@ -2148,7 +2147,7 @@ void Document::generateTexture() m_isTextureObsolete = false; - auto object = std::make_unique(*m_postProcessedObject); + auto object = std::make_unique(*m_uvMappedObject); auto snapshot = std::make_unique(); toSnapshot(snapshot.get()); @@ -2174,7 +2173,10 @@ void Document::textureReady() delete m_resultTextureMesh; m_resultTextureMesh = m_textureGenerator->takeResultMesh().release(); - m_postProcessedObject->alphaEnabled = m_textureGenerator->hasTransparencySettings(); + auto object = m_textureGenerator->takeObject(); + if (nullptr != object) + m_uvMappedObject = std::move(object); + //m_uvMappedObject->alphaEnabled = m_textureGenerator->hasTransparencySettings(); m_textureImageUpdateVersion++; @@ -2221,8 +2223,7 @@ void Document::postProcess() void Document::postProcessedMeshResultReady() { - delete m_postProcessedObject; - m_postProcessedObject = m_postProcessor->takePostProcessedObject(); + m_uvMappedObject.reset(m_postProcessor->takePostProcessedObject()); delete m_postProcessor; m_postProcessor = nullptr; @@ -2236,9 +2237,9 @@ void Document::postProcessedMeshResultReady() } } -const dust3d::Object& Document::currentPostProcessedObject() const +const dust3d::Object& Document::currentUvMappedObject() const { - return *m_postProcessedObject; + return *m_uvMappedObject; } void Document::setComponentCombineMode(dust3d::Uuid componentId, dust3d::CombineMode combineMode) diff --git a/application/sources/document.h b/application/sources/document.h index 8a890491..296a1022 100644 --- a/application/sources/document.h +++ b/application/sources/document.h @@ -689,7 +689,7 @@ public: void updateTextureMetalnessImage(QImage* image); void updateTextureRoughnessImage(QImage* image); void updateTextureAmbientOcclusionImage(QImage* image); - const dust3d::Object& currentPostProcessedObject() const; + const dust3d::Object& currentUvMappedObject() const; bool isExportReady() const; bool isPostProcessResultObsolete() const; bool isMeshGenerating() const; @@ -876,7 +876,7 @@ private: UvMapGenerator* m_textureGenerator = nullptr; bool m_isPostProcessResultObsolete = false; MeshResultPostProcessor* m_postProcessor = nullptr; - dust3d::Object* m_postProcessedObject = new dust3d::Object; + std::unique_ptr m_uvMappedObject = std::make_unique(); ModelMesh* m_resultTextureMesh = nullptr; unsigned long long m_textureImageUpdateVersion = 0; bool m_smoothNormal = false; diff --git a/application/sources/document_window.cc b/application/sources/document_window.cc index b0eee73c..b126d3ee 100644 --- a/application/sources/document_window.cc +++ b/application/sources/document_window.cc @@ -1030,7 +1030,7 @@ void DocumentWindow::exportFbxToFilename(const QString& filename) return; } QApplication::setOverrideCursor(Qt::WaitCursor); - dust3d::Object skeletonResult = m_document->currentPostProcessedObject(); + dust3d::Object skeletonResult = m_document->currentUvMappedObject(); FbxFileWriter fbxFileWriter(skeletonResult, filename, m_document->textureImage, @@ -1060,7 +1060,7 @@ void DocumentWindow::exportGlbToFilename(const QString& filename) return; } QApplication::setOverrideCursor(Qt::WaitCursor); - dust3d::Object skeletonResult = m_document->currentPostProcessedObject(); + dust3d::Object skeletonResult = m_document->currentUvMappedObject(); QImage* textureMetalnessRoughnessAmbientOcclusionImage = UvMapGenerator::combineMetalnessRoughnessAmbientOcclusionImages(m_document->textureMetalnessImage, m_document->textureRoughnessImage, m_document->textureAmbientOcclusionImage); diff --git a/application/sources/uv_map_generator.cc b/application/sources/uv_map_generator.cc index f2c511c0..ba28a91a 100644 --- a/application/sources/uv_map_generator.cc +++ b/application/sources/uv_map_generator.cc @@ -4,7 +4,7 @@ #include #include -size_t UvMapGenerator::m_textureSize = 1024; +size_t UvMapGenerator::m_textureSize = 4096; UvMapGenerator::UvMapGenerator(std::unique_ptr object, std::unique_ptr snapshot) : m_object(std::move(object)) diff --git a/dust3d/mesh/mesh_generator.cc b/dust3d/mesh/mesh_generator.cc index a806cde9..2c9ce2ee 100644 --- a/dust3d/mesh/mesh_generator.cc +++ b/dust3d/mesh/mesh_generator.cc @@ -649,11 +649,8 @@ std::unique_ptr MeshGenerator::combinePartMesh(const std::st return nullptr; auto& partCache = m_cacheContext->parts[partIdString]; - partCache.objectNodes.clear(); - partCache.objectEdges.clear(); - partCache.objectNodeVertices.clear(); - partCache.vertices.clear(); - partCache.faces.clear(); + partCache.reset(); + partCache.color = partColor; partCache.metalness = metalness; partCache.roughness = roughness; @@ -829,12 +826,7 @@ std::unique_ptr MeshGenerator::combineComponentMesh(const st } } - componentCache.sharedQuadEdges.clear(); - componentCache.noneSeamVertices.clear(); - componentCache.objectNodes.clear(); - componentCache.objectEdges.clear(); - componentCache.objectNodeVertices.clear(); - componentCache.mesh.reset(); + componentCache.reset(); std::string linkDataType = String::valueOrEmpty(*component, "linkDataType"); if ("partId" == linkDataType) { diff --git a/dust3d/mesh/mesh_generator.h b/dust3d/mesh/mesh_generator.h index 50d42970..6395fcbd 100644 --- a/dust3d/mesh/mesh_generator.h +++ b/dust3d/mesh/mesh_generator.h @@ -53,6 +53,20 @@ public: float roughness = 1.0; bool isSuccessful = false; bool joined = true; + void reset() + { + vertices.clear(); + faces.clear(); + triangleUvs.clear(); + objectNodes.clear(); + objectEdges.clear(); + objectNodeVertices.clear(); + color = Color(1.0, 1.0, 1.0); + metalness = 0.0; + roughness = 1.0; + isSuccessful = false; + joined = true; + } }; struct GeneratedComponent { @@ -63,6 +77,16 @@ public: std::vector objectNodes; std::vector, std::pair>> objectEdges; std::vector>> objectNodeVertices; + void reset() + { + mesh.reset(); + sharedQuadEdges.clear(); + partTriangleUvs.clear(); + noneSeamVertices.clear(); + objectNodes.clear(); + objectEdges.clear(); + objectNodeVertices.clear(); + } }; struct GeneratedCacheContext {