From e7cf32ab81dfd1f15ea9da5d300328a9f8b198b6 Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Fri, 31 May 2024 11:56:18 +0200 Subject: [PATCH] VGcode: removed quadratic copying when generating the initial preview --- src/slic3r/GUI/LibVGCode/LibVGCodeWrapper.cpp | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/src/slic3r/GUI/LibVGCode/LibVGCodeWrapper.cpp b/src/slic3r/GUI/LibVGCode/LibVGCodeWrapper.cpp index e3ceaee030..23af823103 100644 --- a/src/slic3r/GUI/LibVGCode/LibVGCodeWrapper.cpp +++ b/src/slic3r/GUI/LibVGCode/LibVGCodeWrapper.cpp @@ -714,16 +714,30 @@ GCodeInputData convert(const Slic3r::Print& print, const std::vector vert_indices(data.size(), 0); + for (size_t layer_id = 0; layer_id < layers.size(); ++layer_id) { + const float layer_z = layers[layer_id]; + for (size_t obj_idx = 0; obj_idx < data.size(); ++obj_idx) { + // d contains PathVertices for one object. Let's stuff everything below this layer_z into ret.vertices. + const size_t start_idx = vert_indices[obj_idx]; + size_t idx = start_idx; + while (idx < data[obj_idx].vertices.size() && data[obj_idx].vertices[idx].position[2] <= layer_z) + ++idx; + // We have found a vertex above current layer_z. Let's copy the vertices into the output + // and remember where to start when we process another layer. + ret.vertices.insert(ret.vertices.end(), + data[obj_idx].vertices.begin() + start_idx, + data[obj_idx].vertices.begin() + idx); + vert_indices[obj_idx] = idx; } - min_z = z; } + // collect tool colors ret.tools_colors.reserve(str_tool_colors.size()); for (const std::string& color : str_tool_colors) {