Fix part cache

master
Jeremy HU 2022-10-30 19:08:03 +11:00
parent c87c4482c1
commit 7ce09d1cd6
6 changed files with 40 additions and 23 deletions

View File

@ -37,7 +37,6 @@ Document::~Document()
{ {
delete (dust3d::MeshGenerator::GeneratedCacheContext*)m_generatedCacheContext; delete (dust3d::MeshGenerator::GeneratedCacheContext*)m_generatedCacheContext;
delete m_resultMesh; delete m_resultMesh;
delete m_postProcessedObject;
delete textureImage; delete textureImage;
delete textureImageByteArray; delete textureImageByteArray;
delete textureNormalImage; delete textureNormalImage;
@ -2148,7 +2147,7 @@ void Document::generateTexture()
m_isTextureObsolete = false; m_isTextureObsolete = false;
auto object = std::make_unique<dust3d::Object>(*m_postProcessedObject); auto object = std::make_unique<dust3d::Object>(*m_uvMappedObject);
auto snapshot = std::make_unique<dust3d::Snapshot>(); auto snapshot = std::make_unique<dust3d::Snapshot>();
toSnapshot(snapshot.get()); toSnapshot(snapshot.get());
@ -2174,7 +2173,10 @@ void Document::textureReady()
delete m_resultTextureMesh; delete m_resultTextureMesh;
m_resultTextureMesh = m_textureGenerator->takeResultMesh().release(); 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++; m_textureImageUpdateVersion++;
@ -2221,8 +2223,7 @@ void Document::postProcess()
void Document::postProcessedMeshResultReady() void Document::postProcessedMeshResultReady()
{ {
delete m_postProcessedObject; m_uvMappedObject.reset(m_postProcessor->takePostProcessedObject());
m_postProcessedObject = m_postProcessor->takePostProcessedObject();
delete m_postProcessor; delete m_postProcessor;
m_postProcessor = nullptr; 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) void Document::setComponentCombineMode(dust3d::Uuid componentId, dust3d::CombineMode combineMode)

View File

@ -689,7 +689,7 @@ public:
void updateTextureMetalnessImage(QImage* image); void updateTextureMetalnessImage(QImage* image);
void updateTextureRoughnessImage(QImage* image); void updateTextureRoughnessImage(QImage* image);
void updateTextureAmbientOcclusionImage(QImage* image); void updateTextureAmbientOcclusionImage(QImage* image);
const dust3d::Object& currentPostProcessedObject() const; const dust3d::Object& currentUvMappedObject() const;
bool isExportReady() const; bool isExportReady() const;
bool isPostProcessResultObsolete() const; bool isPostProcessResultObsolete() const;
bool isMeshGenerating() const; bool isMeshGenerating() const;
@ -876,7 +876,7 @@ private:
UvMapGenerator* m_textureGenerator = nullptr; UvMapGenerator* m_textureGenerator = nullptr;
bool m_isPostProcessResultObsolete = false; bool m_isPostProcessResultObsolete = false;
MeshResultPostProcessor* m_postProcessor = nullptr; MeshResultPostProcessor* m_postProcessor = nullptr;
dust3d::Object* m_postProcessedObject = new dust3d::Object; std::unique_ptr<dust3d::Object> m_uvMappedObject = std::make_unique<dust3d::Object>();
ModelMesh* m_resultTextureMesh = nullptr; ModelMesh* m_resultTextureMesh = nullptr;
unsigned long long m_textureImageUpdateVersion = 0; unsigned long long m_textureImageUpdateVersion = 0;
bool m_smoothNormal = false; bool m_smoothNormal = false;

View File

@ -1030,7 +1030,7 @@ void DocumentWindow::exportFbxToFilename(const QString& filename)
return; return;
} }
QApplication::setOverrideCursor(Qt::WaitCursor); QApplication::setOverrideCursor(Qt::WaitCursor);
dust3d::Object skeletonResult = m_document->currentPostProcessedObject(); dust3d::Object skeletonResult = m_document->currentUvMappedObject();
FbxFileWriter fbxFileWriter(skeletonResult, FbxFileWriter fbxFileWriter(skeletonResult,
filename, filename,
m_document->textureImage, m_document->textureImage,
@ -1060,7 +1060,7 @@ void DocumentWindow::exportGlbToFilename(const QString& filename)
return; return;
} }
QApplication::setOverrideCursor(Qt::WaitCursor); QApplication::setOverrideCursor(Qt::WaitCursor);
dust3d::Object skeletonResult = m_document->currentPostProcessedObject(); dust3d::Object skeletonResult = m_document->currentUvMappedObject();
QImage* textureMetalnessRoughnessAmbientOcclusionImage = UvMapGenerator::combineMetalnessRoughnessAmbientOcclusionImages(m_document->textureMetalnessImage, QImage* textureMetalnessRoughnessAmbientOcclusionImage = UvMapGenerator::combineMetalnessRoughnessAmbientOcclusionImages(m_document->textureMetalnessImage,
m_document->textureRoughnessImage, m_document->textureRoughnessImage,
m_document->textureAmbientOcclusionImage); m_document->textureAmbientOcclusionImage);

View File

@ -4,7 +4,7 @@
#include <QPainter> #include <QPainter>
#include <dust3d/uv/uv_map_packer.h> #include <dust3d/uv/uv_map_packer.h>
size_t UvMapGenerator::m_textureSize = 1024; size_t UvMapGenerator::m_textureSize = 4096;
UvMapGenerator::UvMapGenerator(std::unique_ptr<dust3d::Object> object, std::unique_ptr<dust3d::Snapshot> snapshot) UvMapGenerator::UvMapGenerator(std::unique_ptr<dust3d::Object> object, std::unique_ptr<dust3d::Snapshot> snapshot)
: m_object(std::move(object)) : m_object(std::move(object))

View File

@ -649,11 +649,8 @@ std::unique_ptr<MeshCombiner::Mesh> MeshGenerator::combinePartMesh(const std::st
return nullptr; return nullptr;
auto& partCache = m_cacheContext->parts[partIdString]; auto& partCache = m_cacheContext->parts[partIdString];
partCache.objectNodes.clear(); partCache.reset();
partCache.objectEdges.clear();
partCache.objectNodeVertices.clear();
partCache.vertices.clear();
partCache.faces.clear();
partCache.color = partColor; partCache.color = partColor;
partCache.metalness = metalness; partCache.metalness = metalness;
partCache.roughness = roughness; partCache.roughness = roughness;
@ -829,12 +826,7 @@ std::unique_ptr<MeshCombiner::Mesh> MeshGenerator::combineComponentMesh(const st
} }
} }
componentCache.sharedQuadEdges.clear(); componentCache.reset();
componentCache.noneSeamVertices.clear();
componentCache.objectNodes.clear();
componentCache.objectEdges.clear();
componentCache.objectNodeVertices.clear();
componentCache.mesh.reset();
std::string linkDataType = String::valueOrEmpty(*component, "linkDataType"); std::string linkDataType = String::valueOrEmpty(*component, "linkDataType");
if ("partId" == linkDataType) { if ("partId" == linkDataType) {

View File

@ -53,6 +53,20 @@ public:
float roughness = 1.0; float roughness = 1.0;
bool isSuccessful = false; bool isSuccessful = false;
bool joined = true; 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 { struct GeneratedComponent {
@ -63,6 +77,16 @@ public:
std::vector<ObjectNode> objectNodes; std::vector<ObjectNode> objectNodes;
std::vector<std::pair<std::pair<Uuid, Uuid>, std::pair<Uuid, Uuid>>> objectEdges; std::vector<std::pair<std::pair<Uuid, Uuid>, std::pair<Uuid, Uuid>>> objectEdges;
std::vector<std::pair<Vector3, std::pair<Uuid, Uuid>>> objectNodeVertices; std::vector<std::pair<Vector3, std::pair<Uuid, Uuid>>> objectNodeVertices;
void reset()
{
mesh.reset();
sharedQuadEdges.clear();
partTriangleUvs.clear();
noneSeamVertices.clear();
objectNodes.clear();
objectEdges.clear();
objectNodeVertices.clear();
}
}; };
struct GeneratedCacheContext { struct GeneratedCacheContext {