From e9ce612c3bacb64d46293494696c73b3c42b7a40 Mon Sep 17 00:00:00 2001 From: "zhou.xu" Date: Mon, 30 Sep 2024 12:09:13 +0800 Subject: [PATCH] ENH:GLIndexedVertexArray use shared_ptr jira: none Change-Id: I6029bd918a070039181b4faf9547db1784ba79d5 --- src/slic3r/GUI/3DScene.cpp | 15 ++++++++------- src/slic3r/GUI/3DScene.hpp | 4 ++-- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/slic3r/GUI/3DScene.cpp b/src/slic3r/GUI/3DScene.cpp index 67bec1687..d6ccd5510 100644 --- a/src/slic3r/GUI/3DScene.cpp +++ b/src/slic3r/GUI/3DScene.cpp @@ -623,13 +623,12 @@ std::array color_from_model_volume(const ModelVolume& model_volume) return color; } -bool GLVolume::simplify_mesh(const TriangleMesh &mesh, GLIndexedVertexArray &va, LOD_LEVEL lod) const -{ +bool GLVolume::simplify_mesh(const TriangleMesh &mesh, std::shared_ptr va, LOD_LEVEL lod) const { return simplify_mesh(mesh.its,va,lod); } #define SUPER_LARGE_FACES 500000 #define LARGE_FACES 100000 -bool GLVolume::simplify_mesh(const indexed_triangle_set &_its, GLIndexedVertexArray &va, LOD_LEVEL lod) const +bool GLVolume::simplify_mesh(const indexed_triangle_set &_its, std::shared_ptr va, LOD_LEVEL lod) const { if (_its.indices.size() == 0 || _its.vertices.size() == 0) { return false; } auto its = std::make_unique(_its); @@ -653,7 +652,7 @@ bool GLVolume::simplify_mesh(const indexed_triangle_set &_its, GLIndexedVertexAr //std::mutex m_state_mutex; std::thread m_worker = std::thread( - [&va](std::unique_ptr its, std::unique_ptr state) { + [va,this](std::unique_ptr its, std::unique_ptr state) { // Checks that the UI thread did not request cancellation, throws if so. std::function throw_on_cancel = []() { }; @@ -695,7 +694,9 @@ bool GLVolume::simplify_mesh(const indexed_triangle_set &_its, GLIndexedVertexAr Vec3f origin_max = origin_mesh.stats().max + Vec3f(eps, eps, eps); if (origin_min.x() < mesh.stats().min.x() && origin_min.y() < mesh.stats().min.y() && origin_min.z() < mesh.stats().min.z()&& origin_max.x() > mesh.stats().max.x() && origin_max.y() > mesh.stats().max.y() && origin_max.z() > mesh.stats().max.z()) { - va.load_mesh(mesh); + if (va && va.use_count() >= 2) { + va->load_mesh(mesh); + } } else { state->status = State::cancelling; @@ -1315,13 +1316,13 @@ int GLVolumeCollection::load_object_volume( v.indexed_vertex_array_middle = std::make_shared(); } - v.simplify_mesh(mesh, *v.indexed_vertex_array_middle, LOD_LEVEL::MIDDLE); // include finalize_geometry + v.simplify_mesh(mesh, v.indexed_vertex_array_middle, LOD_LEVEL::MIDDLE); // include finalize_geometry if (v.indexed_vertex_array_small == nullptr) { v.indexed_vertex_array_small = std::make_shared(); } - v.simplify_mesh(mesh, *v.indexed_vertex_array_small, LOD_LEVEL::SMALL); + v.simplify_mesh(mesh, v.indexed_vertex_array_small, LOD_LEVEL::SMALL); } v.indexed_vertex_array->load_mesh(mesh); diff --git a/src/slic3r/GUI/3DScene.hpp b/src/slic3r/GUI/3DScene.hpp index 293615ace..50244fba5 100644 --- a/src/slic3r/GUI/3DScene.hpp +++ b/src/slic3r/GUI/3DScene.hpp @@ -304,8 +304,8 @@ public: virtual ~GLVolume() = default; // BBS - bool simplify_mesh(const TriangleMesh &mesh, GLIndexedVertexArray &va, LOD_LEVEL lod) const; - bool simplify_mesh(const indexed_triangle_set &_its, GLIndexedVertexArray &va, LOD_LEVEL lod) const; + bool simplify_mesh(const TriangleMesh &mesh, std::shared_ptr va, LOD_LEVEL lod) const; + bool simplify_mesh(const indexed_triangle_set &_its, std::shared_ptr va, LOD_LEVEL lod) const; protected: Geometry::Transformation m_instance_transformation;