From 730283a9e9dc06426b1927e60c1dca52ef2da571 Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Tue, 20 Aug 2019 09:51:25 +0200 Subject: [PATCH] Export to obj file only toolpaths visible in 3D scene --- src/slic3r/GUI/3DScene.cpp | 26 +++++++++++++++++--------- src/slic3r/GUI/3DScene.hpp | 2 +- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/slic3r/GUI/3DScene.cpp b/src/slic3r/GUI/3DScene.cpp index 6d9302ba6..d5fed6d42 100644 --- a/src/slic3r/GUI/3DScene.cpp +++ b/src/slic3r/GUI/3DScene.cpp @@ -872,7 +872,7 @@ void GLVolumeCollection::export_toolpaths_to_obj(const char* filename) const for (const GLVolume* volume : this->volumes) { - if (!volume->is_extrusion_path) + if (!volume->is_active || !volume->is_extrusion_path) continue; std::vector vertices_and_normals_interleaved; @@ -896,22 +896,30 @@ void GLVolumeCollection::export_toolpaths_to_obj(const char* filename) const triangle_indices = volume->indexed_vertex_array.triangle_indices; else if ((volume->indexed_vertex_array.triangle_indices_VBO_id != 0) && (volume->indexed_vertex_array.triangle_indices_size != 0)) { - triangle_indices = std::vector(volume->indexed_vertex_array.triangle_indices_size, 0); + size_t size = std::min(volume->indexed_vertex_array.triangle_indices_size, volume->tverts_range.second - volume->tverts_range.first); + if (size != 0) + { + triangle_indices = std::vector(size, 0); - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, volume->indexed_vertex_array.triangle_indices_VBO_id)); - glsafe(::glGetBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, triangle_indices.size() * sizeof(int), triangle_indices.data())); - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); + glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, volume->indexed_vertex_array.triangle_indices_VBO_id)); + glsafe(::glGetBufferSubData(GL_ELEMENT_ARRAY_BUFFER, volume->tverts_range.first * sizeof(int), size * sizeof(int), triangle_indices.data())); + glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); + } } if (!volume->indexed_vertex_array.quad_indices.empty()) quad_indices = volume->indexed_vertex_array.quad_indices; if ((volume->indexed_vertex_array.quad_indices_VBO_id != 0) && (volume->indexed_vertex_array.quad_indices_size != 0)) { - quad_indices = std::vector(volume->indexed_vertex_array.quad_indices_size, 0); + size_t size = std::min(volume->indexed_vertex_array.quad_indices_size, volume->qverts_range.second - volume->qverts_range.first); + if (size != 0) + { + quad_indices = std::vector(size, 0); - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, volume->indexed_vertex_array.quad_indices_VBO_id)); - glsafe(::glGetBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, quad_indices.size() * sizeof(int), quad_indices.data())); - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); + glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, volume->indexed_vertex_array.quad_indices_VBO_id)); + glsafe(::glGetBufferSubData(GL_ELEMENT_ARRAY_BUFFER, volume->qverts_range.first * sizeof(int), size * sizeof(int), quad_indices.data())); + glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); + } } if (triangle_indices.empty() && quad_indices.empty()) diff --git a/src/slic3r/GUI/3DScene.hpp b/src/slic3r/GUI/3DScene.hpp index 779194720..9c0e50cad 100644 --- a/src/slic3r/GUI/3DScene.hpp +++ b/src/slic3r/GUI/3DScene.hpp @@ -439,7 +439,7 @@ public: bool empty() const { return this->indexed_vertex_array.empty(); } - void set_range(coordf_t low, coordf_t high); + void set_range(double low, double high); void render() const; void render(int color_id, int detection_id, int worldmatrix_id) const;