From 96ca3b14170c7e3e8b1b13215a9e27ab32893f5e Mon Sep 17 00:00:00 2001 From: Remco Burema Date: Sun, 25 Jul 2021 22:26:59 +0200 Subject: [PATCH 01/15] Handle render-range in shader. Instead of re-uploading the mesh each time the range changes, handle the range in the shaders with the new draw-range parameters. This does however, mean the range has to be in vertices, not in elements. This necessitates some changes to the simulation-view, and some added bits deeper in the base code. Mainly, since each time the type of a line changes, there is an extra vertex, there needs to be a type-change count available to get from 'paths' to range indices. --- cura/Layer.py | 10 +++++++++- cura/LayerDataBuilder.py | 7 +++++++ cura/LayerPolygon.py | 12 ++++++++++++ plugins/SimulationView/SimulationPass.py | 11 +++++++---- plugins/SimulationView/layers3d.shader | 18 ++++++++++++++++-- plugins/SimulationView/layers3d_shadow.shader | 16 +++++++++++++++- 6 files changed, 66 insertions(+), 8 deletions(-) diff --git a/cura/Layer.py b/cura/Layer.py index af42488e2a..52c4583f54 100644 --- a/cura/Layer.py +++ b/cura/Layer.py @@ -43,14 +43,22 @@ class Layer: result = 0 for polygon in self._polygons: result += polygon.lineMeshVertexCount() - return result def lineMeshElementCount(self) -> int: result = 0 for polygon in self._polygons: result += polygon.lineMeshElementCount() + return result + def lineMeshCumulativeTypeChangeCount(self, path: int) -> int: + result = 0 + for polygon in self._polygons: + num_counts = len(polygon.cumulativeTypeChangeCounts) + if path < num_counts: + return result + polygon.cumulativeTypeChangeCounts[path] + path -= num_counts + result += polygon.cumulativeTypeChangeCounts[num_counts - 1] return result def build(self, vertex_offset, index_offset, vertices, colors, line_dimensions, feedrates, extruders, line_types, indices): diff --git a/cura/LayerDataBuilder.py b/cura/LayerDataBuilder.py index d8801c9e7b..6760098667 100755 --- a/cura/LayerDataBuilder.py +++ b/cura/LayerDataBuilder.py @@ -63,6 +63,7 @@ class LayerDataBuilder(MeshBuilder): feedrates = numpy.empty((vertex_count), numpy.float32) extruders = numpy.empty((vertex_count), numpy.float32) line_types = numpy.empty((vertex_count), numpy.float32) + vertex_indices = numpy.arange(0, vertex_count, 1, dtype=numpy.float32) vertex_offset = 0 index_offset = 0 @@ -109,6 +110,12 @@ class LayerDataBuilder(MeshBuilder): "value": feedrates, "opengl_name": "a_feedrate", "opengl_type": "float" + }, + # Can't use glDrawElements to index (due to oversight in (Py)Qt), can't use gl_PrimitiveID (due to legacy support): + "vertex_indices": { + "value": vertex_indices, + "opengl_name": "a_vertex_index", + "opengl_type": "float" } } diff --git a/cura/LayerPolygon.py b/cura/LayerPolygon.py index 6e518e984a..f975f9919e 100644 --- a/cura/LayerPolygon.py +++ b/cura/LayerPolygon.py @@ -55,6 +55,14 @@ class LayerPolygon: self._jump_mask = self.__jump_map[self._types] self._jump_count = numpy.sum(self._jump_mask) + self._cumulative_type_change_counts = numpy.zeros(len(self._types)) + last_type = self.types[0] + current_type_count = 0 + for i in range(0, len(self._cumulative_type_change_counts)): + if last_type != self.types[i]: + current_type_count += 1 + last_type = self.types[i] + self._cumulative_type_change_counts[i] = current_type_count self._mesh_line_count = len(self._types) - self._jump_count self._vertex_count = self._mesh_line_count + numpy.sum(self._types[1:] == self._types[:-1]) @@ -208,6 +216,10 @@ class LayerPolygon: def jumpCount(self): return self._jump_count + @property + def cumulativeTypeChangeCounts(self): + return self._cumulative_type_change_counts + def getNormals(self) -> numpy.ndarray: """Calculate normals for the entire polygon using numpy. diff --git a/plugins/SimulationView/SimulationPass.py b/plugins/SimulationView/SimulationPass.py index 506bc5a01d..740eeca47c 100644 --- a/plugins/SimulationView/SimulationPass.py +++ b/plugins/SimulationView/SimulationPass.py @@ -138,6 +138,7 @@ class SimulationPass(RenderPass): if self._layer_view._current_layer_num > -1 and ((not self._layer_view._only_show_top_layers) or (not self._layer_view.getCompatibilityMode())): start = 0 end = 0 + current_polygon_offset = 0 element_counts = layer_data.getElementCounts() for layer in sorted(element_counts.keys()): # In the current layer, we show just the indicated paths @@ -151,18 +152,20 @@ class SimulationPass(RenderPass): if index >= polygon.data.size // 3 - offset: index -= polygon.data.size // 3 - offset offset = 1 # This is to avoid the first point when there is more than one polygon, since has the same value as the last point in the previous polygon + current_polygon_offset += 1 continue # The head position is calculated and translated head_position = Vector(polygon.data[index+offset][0], polygon.data[index+offset][1], polygon.data[index+offset][2]) + node.getWorldPosition() break break - if self._layer_view._minimum_layer_num > layer: - start += element_counts[layer] - end += element_counts[layer] + end += layer_data.getLayer(layer).lineMeshVertexCount() + if layer < self._layer_view._minimum_layer_num: + start = end # Calculate the range of paths in the last layer + type_change_count = layer_data.getLayer(self._layer_view._current_layer_num).lineMeshCumulativeTypeChangeCount(max(self._layer_view._current_path_num - 1, 0)) current_layer_start = end - current_layer_end = end + self._layer_view._current_path_num * 2 # Because each point is used twice + current_layer_end = current_layer_start + self._layer_view._current_path_num + current_polygon_offset + type_change_count # This uses glDrawRangeElements internally to only draw a certain range of lines. # All the layers but the current selected layer are rendered first diff --git a/plugins/SimulationView/layers3d.shader b/plugins/SimulationView/layers3d.shader index a0c93e146a..8428c02a56 100644 --- a/plugins/SimulationView/layers3d.shader +++ b/plugins/SimulationView/layers3d.shader @@ -25,6 +25,7 @@ vertex41core = in highp float a_extruder; in highp float a_prev_line_type; in highp float a_line_type; + in highp float a_vertex_index; in highp float a_feedrate; in highp float a_thickness; @@ -35,8 +36,9 @@ vertex41core = out lowp vec2 v_line_dim; out highp int v_extruder; out highp mat4 v_extruder_opacity; - out float v_prev_line_type; - out float v_line_type; + out highp float v_prev_line_type; + out highp float v_line_type; + out highp float v_index; out lowp vec4 f_color; out highp vec3 f_vertex; @@ -114,6 +116,7 @@ vertex41core = v_extruder = int(a_extruder); v_prev_line_type = a_prev_line_type; v_line_type = a_line_type; + v_index = a_vertex_index; v_extruder_opacity = u_extruder_opacity; // for testing without geometry shader @@ -137,6 +140,8 @@ geometry41core = uniform int u_show_infill; uniform int u_show_starts; + uniform highp vec2 u_drawRange; + layout(lines) in; layout(triangle_strip, max_vertices = 40) out; @@ -148,6 +153,7 @@ geometry41core = in mat4 v_extruder_opacity[]; in float v_prev_line_type[]; in float v_line_type[]; + in float v_index[]; out vec4 f_color; out vec3 f_normal; @@ -177,6 +183,10 @@ geometry41core = float size_x; float size_y; + if (u_drawRange[0] >= 0 && u_drawRange[1] >= 0 && (v_index[0] < u_drawRange[0] || v_index[0] >= u_drawRange[1])) + { + return; + } if ((v_extruder_opacity[0][int(mod(v_extruder[0], 4))][v_extruder[0] / 4] == 0.0) && (v_line_type[0] != 8) && (v_line_type[0] != 9)) { return; } @@ -374,12 +384,15 @@ u_max_feedrate = 1 u_min_thickness = 0 u_max_thickness = 1 +u_drawRange = [-1, -1] + [bindings] u_modelMatrix = model_matrix u_viewMatrix = view_matrix u_projectionMatrix = projection_matrix u_normalMatrix = normal_matrix u_lightPosition = light_0_position +u_drawRange = draw_range [attributes] a_vertex = vertex @@ -392,3 +405,4 @@ a_prev_line_type = prev_line_type a_line_type = line_type a_feedrate = feedrate a_thickness = thickness +a_vertex_index = vertex_index diff --git a/plugins/SimulationView/layers3d_shadow.shader b/plugins/SimulationView/layers3d_shadow.shader index 88268938c9..92ea43ad64 100644 --- a/plugins/SimulationView/layers3d_shadow.shader +++ b/plugins/SimulationView/layers3d_shadow.shader @@ -18,6 +18,7 @@ vertex41core = in highp vec2 a_line_dim; // line width and thickness in highp float a_extruder; in highp float a_line_type; + in highp float a_vertex_index; out lowp vec4 v_color; @@ -26,7 +27,8 @@ vertex41core = out lowp vec2 v_line_dim; out highp int v_extruder; out highp mat4 v_extruder_opacity; - out float v_line_type; + out highp float v_line_type; + out highp float v_index; out lowp vec4 f_color; out highp vec3 f_vertex; @@ -47,6 +49,7 @@ vertex41core = v_line_dim = a_line_dim; v_extruder = int(a_extruder); v_line_type = a_line_type; + v_index = a_vertex_index; v_extruder_opacity = u_extruder_opacity; // for testing without geometry shader @@ -67,6 +70,8 @@ geometry41core = uniform int u_show_skin; uniform int u_show_infill; + uniform highp vec2 u_drawRange; + layout(lines) in; layout(triangle_strip, max_vertices = 26) out; @@ -77,6 +82,7 @@ geometry41core = in int v_extruder[]; in mat4 v_extruder_opacity[]; in float v_line_type[]; + in float v_index[]; out vec4 f_color; out vec3 f_normal; @@ -106,6 +112,10 @@ geometry41core = float size_x; float size_y; + if (u_drawRange[0] >= 0 && u_drawRange[1] >= 0 && (v_index[0] < u_drawRange[0] || v_index[0] >= u_drawRange[1])) + { + return; + } if ((v_extruder_opacity[0][int(mod(v_extruder[0], 4))][v_extruder[0] / 4] == 0.0) && (v_line_type[0] != 8) && (v_line_type[0] != 9)) { return; } @@ -268,12 +278,15 @@ u_show_helpers = 1 u_show_skin = 1 u_show_infill = 1 +u_drawRange = [-1, -1] + [bindings] u_modelMatrix = model_matrix u_viewMatrix = view_matrix u_projectionMatrix = projection_matrix u_normalMatrix = normal_matrix u_lightPosition = light_0_position +u_drawRange = draw_range [attributes] a_vertex = vertex @@ -284,3 +297,4 @@ a_line_dim = line_dim a_extruder = extruder a_material_color = material_color a_line_type = line_type +a_vertex_index = vertex_index From e119c4694416f562305d93d42f0306e5a70ab31c Mon Sep 17 00:00:00 2001 From: Remco Burema Date: Mon, 9 Aug 2021 13:15:44 +0200 Subject: [PATCH 02/15] Fetch count from simple property instead of recalculation. Polygons don't change when in layer-view. There's already an analogous elementCount property anyway, so a vertexCount property can't do much harm. Just keep in mind that when the polygons are altered, it should be either done via build, or the lineMeshXXXCount methods should be used instead. --- cura/Layer.py | 7 +++++++ cura/LayerPolygon.py | 4 ++++ plugins/SimulationView/SimulationPass.py | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/cura/Layer.py b/cura/Layer.py index 52c4583f54..11c6a7f908 100644 --- a/cura/Layer.py +++ b/cura/Layer.py @@ -15,6 +15,7 @@ class Layer: self._height = 0.0 self._thickness = 0.0 self._polygons = [] # type: List[LayerPolygon] + self._vertex_count = 0 self._element_count = 0 @property @@ -29,6 +30,10 @@ class Layer: def polygons(self) -> List[LayerPolygon]: return self._polygons + @property + def vertexCount(self): + return self._vertex_count + @property def elementCount(self): return self._element_count @@ -64,11 +69,13 @@ class Layer: def build(self, vertex_offset, index_offset, vertices, colors, line_dimensions, feedrates, extruders, line_types, indices): result_vertex_offset = vertex_offset result_index_offset = index_offset + self._vertex_count = 0 self._element_count = 0 for polygon in self._polygons: polygon.build(result_vertex_offset, result_index_offset, vertices, colors, line_dimensions, feedrates, extruders, line_types, indices) result_vertex_offset += polygon.lineMeshVertexCount() result_index_offset += polygon.lineMeshElementCount() + self._vertex_count += polygon.vertexCount self._element_count += polygon.elementCount return result_vertex_offset, result_index_offset diff --git a/cura/LayerPolygon.py b/cura/LayerPolygon.py index cf4bb47a86..610366d5fc 100644 --- a/cura/LayerPolygon.py +++ b/cura/LayerPolygon.py @@ -187,6 +187,10 @@ class LayerPolygon: def data(self): return self._data + @property + def vertexCount(self): + return self._vertex_end - self._vertex_begin + @property def elementCount(self): return (self._index_end - self._index_begin) * 2 # The range of vertices multiplied by 2 since each vertex is used twice diff --git a/plugins/SimulationView/SimulationPass.py b/plugins/SimulationView/SimulationPass.py index 3f5f12a702..b17b38be38 100644 --- a/plugins/SimulationView/SimulationPass.py +++ b/plugins/SimulationView/SimulationPass.py @@ -162,7 +162,7 @@ class SimulationPass(RenderPass): head_position = Vector(polygon.data[index+offset][0], polygon.data[index+offset][1], polygon.data[index+offset][2]) + node.getWorldPosition() break break - end += layer_data.getLayer(layer).lineMeshVertexCount() + end += layer_data.getLayer(layer).vertexCount if layer < self._layer_view._minimum_layer_num: start = end From acde6ae489b0861c695f118d016975b9f6b5bdcf Mon Sep 17 00:00:00 2001 From: Remco Burema <41987080+rburema@users.noreply.github.com> Date: Sun, 31 Oct 2021 21:21:24 +0100 Subject: [PATCH 03/15] Apply suggestions from code review Co-authored-by: Ghostkeeper --- cura/LayerDataBuilder.py | 2 +- cura/LayerPolygon.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cura/LayerDataBuilder.py b/cura/LayerDataBuilder.py index 6760098667..39eced5ac6 100755 --- a/cura/LayerDataBuilder.py +++ b/cura/LayerDataBuilder.py @@ -63,7 +63,7 @@ class LayerDataBuilder(MeshBuilder): feedrates = numpy.empty((vertex_count), numpy.float32) extruders = numpy.empty((vertex_count), numpy.float32) line_types = numpy.empty((vertex_count), numpy.float32) - vertex_indices = numpy.arange(0, vertex_count, 1, dtype=numpy.float32) + vertex_indices = numpy.arange(0, vertex_count, 1, dtype = numpy.float32) vertex_offset = 0 index_offset = 0 diff --git a/cura/LayerPolygon.py b/cura/LayerPolygon.py index ddb3a86289..fe85be4a94 100644 --- a/cura/LayerPolygon.py +++ b/cura/LayerPolygon.py @@ -61,7 +61,7 @@ class LayerPolygon: for i in range(0, len(self._cumulative_type_change_counts)): if last_type != self.types[i]: current_type_count += 1 - last_type = self.types[i] + last_type = self.types[i] self._cumulative_type_change_counts[i] = current_type_count self._mesh_line_count = len(self._types) - self._jump_count self._vertex_count = self._mesh_line_count + numpy.sum(self._types[1:] == self._types[:-1]) From 4f20dc4c5dd1d076c1f91bbb224c37a6a34403f9 Mon Sep 17 00:00:00 2001 From: Remco Burema Date: Sun, 7 Nov 2021 22:26:34 +0100 Subject: [PATCH 04/15] Add documentation. --- cura/Layer.py | 6 ++++++ cura/LayerPolygon.py | 9 ++++++++- plugins/SimulationView/SimulationPass.py | 7 ++++++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/cura/Layer.py b/cura/Layer.py index 11c6a7f908..87aad3c949 100644 --- a/cura/Layer.py +++ b/cura/Layer.py @@ -57,6 +57,12 @@ class Layer: return result def lineMeshCumulativeTypeChangeCount(self, path: int) -> int: + """ The number of line-type changes in this layer up until #path. + See also LayerPolygon::cumulativeTypeChangeCounts. + + :param path: The path-index up until which the cumulative changes are counted. + :return: The cumulative number of line-type changes up until this path. + """ result = 0 for polygon in self._polygons: num_counts = len(polygon.cumulativeTypeChangeCounts) diff --git a/cura/LayerPolygon.py b/cura/LayerPolygon.py index fe85be4a94..5eb8c96ec5 100644 --- a/cura/LayerPolygon.py +++ b/cura/LayerPolygon.py @@ -55,7 +55,7 @@ class LayerPolygon: self._jump_mask = self.__jump_map[self._types] self._jump_count = numpy.sum(self._jump_mask) - self._cumulative_type_change_counts = numpy.zeros(len(self._types)) + self._cumulative_type_change_counts = numpy.zeros(len(self._types)) # See the comment on the 'cumulativeTypeChangeCounts' property below. last_type = self.types[0] current_type_count = 0 for i in range(0, len(self._cumulative_type_change_counts)): @@ -221,6 +221,13 @@ class LayerPolygon: @property def cumulativeTypeChangeCounts(self): + """ This polygon class stores with a vertex the type of the line to the next vertex. However, in other contexts, + other ways of representing this might be more suited to the task (for example, when a vertex can possibly only + have _one_ type, it's unavoidable to duplicate vertices when the type is changed). In such situations it's might + be useful to know how many times the type has changed, in order to keep the various vertex-indices aligned. + + :return: The total times the line-type changes from one type to another within this LayerPolygon. + """ return self._cumulative_type_change_counts def getNormals(self) -> numpy.ndarray: diff --git a/plugins/SimulationView/SimulationPass.py b/plugins/SimulationView/SimulationPass.py index b17b38be38..86cf643e08 100644 --- a/plugins/SimulationView/SimulationPass.py +++ b/plugins/SimulationView/SimulationPass.py @@ -166,7 +166,12 @@ class SimulationPass(RenderPass): if layer < self._layer_view._minimum_layer_num: start = end - # Calculate the range of paths in the last layer + # Calculate the range of paths in the last layer. -- The type-change count is needed to keep the + # vertex-indices aligned between the two different ways we represent polygons here. + # Since there is one type per line, that could give a vertex two different types, if it's a vertex + # where a type-chage occurs. However, the shader expects vertices to have only one type. In order to + # fix this, those vertices are duplicated. This introduces a discrepancy that we have to take into + # account, which is done by the type-change-count. type_change_count = layer_data.getLayer(self._layer_view._current_layer_num).lineMeshCumulativeTypeChangeCount(max(self._layer_view._current_path_num - 1, 0)) current_layer_start = end current_layer_end = current_layer_start + self._layer_view._current_path_num + current_polygon_offset + type_change_count From f48617746555c2a9e5a08a9392bd2b39eeeb6926 Mon Sep 17 00:00:00 2001 From: Remco Burema Date: Mon, 8 Nov 2021 21:36:06 +0100 Subject: [PATCH 05/15] Remove dead (shader) code. These shader (files) are now only used for compatability mode. The 'modern' code is found in the '...3d.shader' versions of these files. --- plugins/SimulationView/layers.shader | 71 -------------------- plugins/SimulationView/layers_shadow.shader | 72 --------------------- 2 files changed, 143 deletions(-) diff --git a/plugins/SimulationView/layers.shader b/plugins/SimulationView/layers.shader index e6210c2b65..d9115de158 100644 --- a/plugins/SimulationView/layers.shader +++ b/plugins/SimulationView/layers.shader @@ -77,77 +77,6 @@ fragment = gl_FragColor = v_color; } -vertex41core = - #version 410 - uniform highp mat4 u_modelMatrix; - uniform highp mat4 u_viewMatrix; - uniform highp mat4 u_projectionMatrix; - - uniform lowp float u_active_extruder; - uniform lowp float u_shade_factor; - uniform highp int u_layer_view_type; - - in highp float a_extruder; - in highp float a_line_type; - in highp vec4 a_vertex; - in lowp vec4 a_color; - in lowp vec4 a_material_color; - - out lowp vec4 v_color; - out float v_line_type; - - void main() - { - gl_Position = u_projectionMatrix * u_viewMatrix * u_modelMatrix * a_vertex; - v_color = a_color; - if ((a_line_type != 8) && (a_line_type != 9)) { - v_color = (a_extruder == u_active_extruder) ? v_color : vec4(u_shade_factor * v_color.rgb, v_color.a); - } - - v_line_type = a_line_type; - } - -fragment41core = - #version 410 - in lowp vec4 v_color; - in float v_line_type; - out vec4 frag_color; - - uniform int u_show_travel_moves; - uniform int u_show_helpers; - uniform int u_show_skin; - uniform int u_show_infill; - - void main() - { - if ((u_show_travel_moves == 0) && (v_line_type >= 7.5) && (v_line_type <= 9.5)) { // actually, 8 and 9 - // discard movements - discard; - } - // helpers: 4, 5, 7, 10 - if ((u_show_helpers == 0) && ( - ((v_line_type >= 3.5) && (v_line_type <= 4.5)) || - ((v_line_type >= 6.5) && (v_line_type <= 7.5)) || - ((v_line_type >= 9.5) && (v_line_type <= 10.5)) || - ((v_line_type >= 4.5) && (v_line_type <= 5.5)) - )) { - discard; - } - // skin: 1, 2, 3 - if ((u_show_skin == 0) && ( - (v_line_type >= 0.5) && (v_line_type <= 3.5) - )) { - discard; - } - // infill: - if ((u_show_infill == 0) && (v_line_type >= 5.5) && (v_line_type <= 6.5)) { - // discard movements - discard; - } - - frag_color = v_color; - } - [defaults] u_active_extruder = 0.0 u_shade_factor = 0.60 diff --git a/plugins/SimulationView/layers_shadow.shader b/plugins/SimulationView/layers_shadow.shader index 4bc2de3d0b..737b66e6f6 100644 --- a/plugins/SimulationView/layers_shadow.shader +++ b/plugins/SimulationView/layers_shadow.shader @@ -81,78 +81,6 @@ fragment = gl_FragColor = v_color; } -vertex41core = - #version 410 - uniform highp mat4 u_modelMatrix; - uniform highp mat4 u_viewMatrix; - uniform highp mat4 u_projectionMatrix; - - uniform lowp float u_active_extruder; - uniform lowp float u_shade_factor; - uniform highp int u_layer_view_type; - - in highp float a_extruder; - in highp float a_line_type; - in highp vec4 a_vertex; - in lowp vec4 a_color; - in lowp vec4 a_material_color; - - out lowp vec4 v_color; - out float v_line_type; - - void main() - { - gl_Position = u_projectionMatrix * u_viewMatrix * u_modelMatrix * a_vertex; - v_color = vec4(0.4, 0.4, 0.4, 0.9); // default color for not current layer - // if ((a_line_type != 8) && (a_line_type != 9)) { - // v_color = (a_extruder == u_active_extruder) ? v_color : vec4(u_shade_factor * v_color.rgb, v_color.a); - // } - - v_line_type = a_line_type; - } - -fragment41core = - #version 410 - in lowp vec4 v_color; - in float v_line_type; - out vec4 frag_color; - - uniform int u_show_travel_moves; - uniform int u_show_helpers; - uniform int u_show_skin; - uniform int u_show_infill; - - void main() - { - if ((u_show_travel_moves == 0) && (v_line_type >= 7.5) && (v_line_type <= 9.5)) { // actually, 8 and 9 - // discard movements - discard; - } - // helpers: 4, 5, 7, 10, 11 - if ((u_show_helpers == 0) && ( - ((v_line_type >= 3.5) && (v_line_type <= 4.5)) || - ((v_line_type >= 6.5) && (v_line_type <= 7.5)) || - ((v_line_type >= 9.5) && (v_line_type <= 10.5)) || - ((v_line_type >= 4.5) && (v_line_type <= 5.5)) || - ((v_line_type >= 10.5) && (v_line_type <= 11.5)) - )) { - discard; - } - // skin: 1, 2, 3 - if ((u_show_skin == 0) && ( - (v_line_type >= 0.5) && (v_line_type <= 3.5) - )) { - discard; - } - // infill: - if ((u_show_infill == 0) && (v_line_type >= 5.5) && (v_line_type <= 6.5)) { - // discard movements - discard; - } - - frag_color = v_color; - } - [defaults] u_active_extruder = 0.0 u_shade_factor = 0.60 From 51c5572f0f32d77599b4e20da0e1ce764c763135 Mon Sep 17 00:00:00 2001 From: Remco Burema Date: Mon, 8 Nov 2021 21:39:12 +0100 Subject: [PATCH 06/15] Add draw-range behaviour to legacy-mode shaders. --- plugins/SimulationView/layers.shader | 14 ++++++++++++++ plugins/SimulationView/layers_shadow.shader | 14 ++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/plugins/SimulationView/layers.shader b/plugins/SimulationView/layers.shader index d9115de158..036d8841b6 100644 --- a/plugins/SimulationView/layers.shader +++ b/plugins/SimulationView/layers.shader @@ -13,9 +13,11 @@ vertex = attribute highp vec4 a_vertex; attribute lowp vec4 a_color; attribute lowp vec4 a_material_color; + attribute highp float a_vertex_index; varying lowp vec4 v_color; varying float v_line_type; + varying highp float v_vertex_index; void main() { @@ -28,6 +30,7 @@ vertex = } v_line_type = a_line_type; + v_vertex_index = a_vertex_index; } fragment = @@ -40,14 +43,21 @@ fragment = #endif // GL_ES varying lowp vec4 v_color; varying float v_line_type; + varying highp float v_vertex_index; uniform int u_show_travel_moves; uniform int u_show_helpers; uniform int u_show_skin; uniform int u_show_infill; + uniform highp vec2 u_drawRange; + void main() { + if (u_drawRange.x >= 0 && u_drawRange.y >= 0 && (v_vertex_index < u_drawRange.x || v_vertex_index > u_drawRange.y)) + { + discard; + } if ((u_show_travel_moves == 0) && (v_line_type >= 7.5) && (v_line_type <= 9.5)) { // actually, 8 and 9 // discard movements discard; @@ -88,10 +98,13 @@ u_show_helpers = 1 u_show_skin = 1 u_show_infill = 1 +u_drawRange = [-1, -1] + [bindings] u_modelMatrix = model_matrix u_viewMatrix = view_matrix u_projectionMatrix = projection_matrix +u_drawRange = draw_range [attributes] a_vertex = vertex @@ -99,3 +112,4 @@ a_color = color a_extruder = extruder a_line_type = line_type a_material_color = material_color +a_vertex_index = vertex_index diff --git a/plugins/SimulationView/layers_shadow.shader b/plugins/SimulationView/layers_shadow.shader index 737b66e6f6..0be982e219 100644 --- a/plugins/SimulationView/layers_shadow.shader +++ b/plugins/SimulationView/layers_shadow.shader @@ -13,9 +13,11 @@ vertex = attribute highp vec4 a_vertex; attribute lowp vec4 a_color; attribute lowp vec4 a_material_color; + attribute highp float a_vertex_index; varying lowp vec4 v_color; varying float v_line_type; + varying highp float v_vertex_index; void main() { @@ -28,6 +30,7 @@ vertex = // } v_line_type = a_line_type; + v_vertex_index = a_vertex_index; } fragment = @@ -40,14 +43,21 @@ fragment = #endif // GL_ES varying lowp vec4 v_color; varying float v_line_type; + varying highp float v_vertex_index; uniform int u_show_travel_moves; uniform int u_show_helpers; uniform int u_show_skin; uniform int u_show_infill; + uniform highp vec2 u_drawRange; + void main() { + if (u_drawRange.x >= 0 && u_drawRange.y >= 0 && (v_vertex_index < u_drawRange.x || v_vertex_index > u_drawRange.y)) + { + discard; + } if ((u_show_travel_moves == 0) && (v_line_type >= 7.5) && (v_line_type <= 9.5)) { // actually, 8 and 9 // discard movements @@ -92,10 +102,13 @@ u_show_helpers = 1 u_show_skin = 1 u_show_infill = 1 +u_drawRange = [-1, -1] + [bindings] u_modelMatrix = model_matrix u_viewMatrix = view_matrix u_projectionMatrix = projection_matrix +u_drawRange = draw_range [attributes] a_vertex = vertex @@ -103,3 +116,4 @@ a_color = color a_extruder = extruder a_line_type = line_type a_material_color = material_color +a_vertex_index = vertex_index From 447c4e73687bad9fd22e24939a7c883abfdccd1a Mon Sep 17 00:00:00 2001 From: Rijk van Manen Date: Wed, 3 Nov 2021 16:46:46 +0100 Subject: [PATCH 07/15] optimized skin orientation for cross pattern The skin orientation is optimized for the cross (3d) pattern to reduce the bridge distance. For more information see PP-55. --- resources/definitions/ultimaker.def.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/resources/definitions/ultimaker.def.json b/resources/definitions/ultimaker.def.json index 47a60fe51c..2a22a93124 100644 --- a/resources/definitions/ultimaker.def.json +++ b/resources/definitions/ultimaker.def.json @@ -40,6 +40,9 @@ { "value": false, "enabled": false + }, + "skin_angles": { + "value": "[] if infill_pattern not in ['cross', 'cross_3d'] else [20, 110]" } } } From d12d756b1de9cab9f4b18cc255b31202c14a328d Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Sat, 13 Nov 2021 16:42:06 +0100 Subject: [PATCH 08/15] Move machine_height to the other machine dimension settings It's quite logical that the 3 dimensions of the printer are next to each other... Found during work on a plug-in. --- resources/definitions/fdmprinter.def.json | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/resources/definitions/fdmprinter.def.json b/resources/definitions/fdmprinter.def.json index e630aa92c5..d14601f613 100644 --- a/resources/definitions/fdmprinter.def.json +++ b/resources/definitions/fdmprinter.def.json @@ -159,6 +159,16 @@ "settable_per_extruder": false, "settable_per_meshgroup": false }, + "machine_height": + { + "label": "Machine Height", + "description": "The height (Z-direction) of the printable area.", + "default_value": 100, + "type": "float", + "settable_per_mesh": false, + "settable_per_extruder": false, + "settable_per_meshgroup": false + }, "machine_shape": { "label": "Build Plate Shape", @@ -189,16 +199,6 @@ "settable_per_extruder": false, "settable_per_meshgroup": false }, - "machine_height": - { - "label": "Machine Height", - "description": "The height (Z-direction) of the printable area.", - "default_value": 100, - "type": "float", - "settable_per_mesh": false, - "settable_per_extruder": false, - "settable_per_meshgroup": false - }, "machine_heated_bed": { "label": "Has Heated Build Plate", From c9feace0fbe02beb2089ec0af7be35127d7420f7 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Mon, 15 Nov 2021 10:59:58 +0100 Subject: [PATCH 09/15] Change user-visible name of Maximum Feedrate to Maximum Speed E Maximum Feedrate was correct, but compared to the names of the X/Y/Z maximum speeds, this is considered to be more consistent. Fixes #10767. --- resources/definitions/fdmprinter.def.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/definitions/fdmprinter.def.json b/resources/definitions/fdmprinter.def.json index d14601f613..c4051d806f 100644 --- a/resources/definitions/fdmprinter.def.json +++ b/resources/definitions/fdmprinter.def.json @@ -571,7 +571,7 @@ }, "machine_max_feedrate_e": { - "label": "Maximum Feedrate", + "label": "Maximum Speed E", "description": "The maximum speed of the filament.", "unit": "mm/s", "type": "float", From dc28370178b1cf3e6729712af358039ebec51104 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Mon, 15 Nov 2021 15:19:57 +0100 Subject: [PATCH 10/15] Remove implicit casts and comparisons of int to float We can't change this index to an integer, because varying variables can't be integer, even though this variable will only really be tested on vertex level. Not sure if varying was the right choice, but I don't want to change that. This prevents a crash, probably only occurring on certain GPUs. Contributes to issue CURA-8657. --- plugins/SimulationView/layers.shader | 4 ++-- plugins/SimulationView/layers3d.shader | 4 ++-- plugins/SimulationView/layers3d_shadow.shader | 4 ++-- plugins/SimulationView/layers_shadow.shader | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/plugins/SimulationView/layers.shader b/plugins/SimulationView/layers.shader index 036d8841b6..97e0180307 100644 --- a/plugins/SimulationView/layers.shader +++ b/plugins/SimulationView/layers.shader @@ -54,7 +54,7 @@ fragment = void main() { - if (u_drawRange.x >= 0 && u_drawRange.y >= 0 && (v_vertex_index < u_drawRange.x || v_vertex_index > u_drawRange.y)) + if (u_drawRange.x >= 0.0 && u_drawRange.y >= 0.0 && (v_vertex_index < u_drawRange.x || v_vertex_index > u_drawRange.y)) { discard; } @@ -98,7 +98,7 @@ u_show_helpers = 1 u_show_skin = 1 u_show_infill = 1 -u_drawRange = [-1, -1] +u_drawRange = [-1.0, -1.0] [bindings] u_modelMatrix = model_matrix diff --git a/plugins/SimulationView/layers3d.shader b/plugins/SimulationView/layers3d.shader index 4bd54d6d35..dc5aee2d1c 100644 --- a/plugins/SimulationView/layers3d.shader +++ b/plugins/SimulationView/layers3d.shader @@ -237,7 +237,7 @@ geometry41core = float size_x; float size_y; - if (u_drawRange[0] >= 0 && u_drawRange[1] >= 0 && (v_index[0] < u_drawRange[0] || v_index[0] >= u_drawRange[1])) + if (u_drawRange[0] >= 0.0 && u_drawRange[1] >= 0.0 && (v_index[0] < u_drawRange[0] || v_index[0] >= u_drawRange[1])) { return; } @@ -437,7 +437,7 @@ u_max_feedrate = 1 u_min_thickness = 0 u_max_thickness = 1 -u_drawRange = [-1, -1] +u_drawRange = [-1.0, -1.0] [bindings] u_modelMatrix = model_matrix diff --git a/plugins/SimulationView/layers3d_shadow.shader b/plugins/SimulationView/layers3d_shadow.shader index 92ea43ad64..81ae84ae05 100644 --- a/plugins/SimulationView/layers3d_shadow.shader +++ b/plugins/SimulationView/layers3d_shadow.shader @@ -112,7 +112,7 @@ geometry41core = float size_x; float size_y; - if (u_drawRange[0] >= 0 && u_drawRange[1] >= 0 && (v_index[0] < u_drawRange[0] || v_index[0] >= u_drawRange[1])) + if (u_drawRange[0] >= 0.0 && u_drawRange[1] >= 0.0 && (v_index[0] < u_drawRange[0] || v_index[0] >= u_drawRange[1])) { return; } @@ -278,7 +278,7 @@ u_show_helpers = 1 u_show_skin = 1 u_show_infill = 1 -u_drawRange = [-1, -1] +u_drawRange = [-1.0, -1.0] [bindings] u_modelMatrix = model_matrix diff --git a/plugins/SimulationView/layers_shadow.shader b/plugins/SimulationView/layers_shadow.shader index 0be982e219..403fd2bd8e 100644 --- a/plugins/SimulationView/layers_shadow.shader +++ b/plugins/SimulationView/layers_shadow.shader @@ -54,7 +54,7 @@ fragment = void main() { - if (u_drawRange.x >= 0 && u_drawRange.y >= 0 && (v_vertex_index < u_drawRange.x || v_vertex_index > u_drawRange.y)) + if (u_drawRange.x >= 0.0 && u_drawRange.y >= 0.0 && (v_vertex_index < u_drawRange.x || v_vertex_index > u_drawRange.y)) { discard; } @@ -102,7 +102,7 @@ u_show_helpers = 1 u_show_skin = 1 u_show_infill = 1 -u_drawRange = [-1, -1] +u_drawRange = [-1.0, -1.0] [bindings] u_modelMatrix = model_matrix From 322d48cdd787d47c13d9c7ee019bff0114f722a1 Mon Sep 17 00:00:00 2001 From: Jelle Spijker Date: Mon, 15 Nov 2021 16:54:47 +0100 Subject: [PATCH 11/15] Fixed speed flow equalization width factor --- resources/definitions/ultimaker.def.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/definitions/ultimaker.def.json b/resources/definitions/ultimaker.def.json index 3dc3555266..766a83f8ed 100644 --- a/resources/definitions/ultimaker.def.json +++ b/resources/definitions/ultimaker.def.json @@ -54,7 +54,7 @@ "value": true }, "speed_equalize_flow_width_factor": { - "value": "1.1" + "value": "110.0" }, "meshfix_maximum_extrusion_area_deviation": { "value": "50000" From c2ed0a918124f628abd13157a0e869c39585de93 Mon Sep 17 00:00:00 2001 From: Remco Burema Date: Tue, 16 Nov 2021 12:33:29 +0100 Subject: [PATCH 12/15] Workaround for if layer is None somehow. --- plugins/SimulationView/SimulationPass.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/SimulationView/SimulationPass.py b/plugins/SimulationView/SimulationPass.py index 86cf643e08..495feb6fd3 100644 --- a/plugins/SimulationView/SimulationPass.py +++ b/plugins/SimulationView/SimulationPass.py @@ -172,7 +172,8 @@ class SimulationPass(RenderPass): # where a type-chage occurs. However, the shader expects vertices to have only one type. In order to # fix this, those vertices are duplicated. This introduces a discrepancy that we have to take into # account, which is done by the type-change-count. - type_change_count = layer_data.getLayer(self._layer_view._current_layer_num).lineMeshCumulativeTypeChangeCount(max(self._layer_view._current_path_num - 1, 0)) + layer = layer_data.getLayer(self._layer_view._current_layer_num) + type_change_count = 0 if layer is None else layer.lineMeshCumulativeTypeChangeCount(max(self._layer_view._current_path_num - 1, 0)) current_layer_start = end current_layer_end = current_layer_start + self._layer_view._current_path_num + current_polygon_offset + type_change_count From 291d047facd6a6e2f88d4d7c83fa7e4373b4763f Mon Sep 17 00:00:00 2001 From: Remco Burema Date: Wed, 17 Nov 2021 14:31:57 +0100 Subject: [PATCH 13/15] Revert "fixed top bottom pattern zigzag in profiles" This reverts commit 3abbcc99c07b3b434a95183968e2b2e1cf7664ab. --- resources/definitions/atmat_signal_pro_base.def.json | 4 ++-- resources/definitions/cubicon_common.def.json | 6 +++--- resources/definitions/fdmprinter.def.json | 4 ++-- resources/definitions/maker_starter.def.json | 2 +- resources/definitions/trimaker_cosmosII.def.json | 2 +- resources/definitions/trimaker_nebula.def.json | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/resources/definitions/atmat_signal_pro_base.def.json b/resources/definitions/atmat_signal_pro_base.def.json index 65da7b7596..0d1c5a75c2 100644 --- a/resources/definitions/atmat_signal_pro_base.def.json +++ b/resources/definitions/atmat_signal_pro_base.def.json @@ -294,7 +294,7 @@ "support_xy_distance_overhang": { "value": "wall_line_width_0" }, "support_angle": { "value": "60" }, "support_bottom_distance": { "value": "support_z_distance / 2" }, - "support_pattern": { "default_value": "'zigzag'" }, + "support_pattern": { "default_value": "zigzag" }, "support_top_distance": { "value": "support_z_distance" }, "support_use_towers": { "value": "True" }, "support_z_distance": { "value": "layer_height" }, @@ -308,4 +308,4 @@ "support_brim_enable": { "value": "True" }, "prime_tower_enable": { "value": "True" } } -} +} \ No newline at end of file diff --git a/resources/definitions/cubicon_common.def.json b/resources/definitions/cubicon_common.def.json index 3bff01bf9b..f700df7ae6 100644 --- a/resources/definitions/cubicon_common.def.json +++ b/resources/definitions/cubicon_common.def.json @@ -45,8 +45,8 @@ "wall_thickness": { "value": "1.2" }, "cool_min_layer_time_fan_speed_max": { "default_value": 15 }, "cool_min_layer_time": { "default_value": 15 }, - "support_interface_pattern": { "default_value": "'zigzag'" }, - "support_pattern": { "default_value": "'zigzag'" }, + "support_interface_pattern": { "default_value": "zigzag" }, + "support_pattern": { "default_value": "zigzag" }, "retraction_amount": { "default_value": 1.5 } } -} +} \ No newline at end of file diff --git a/resources/definitions/fdmprinter.def.json b/resources/definitions/fdmprinter.def.json index d7669f4b3a..8719908c12 100644 --- a/resources/definitions/fdmprinter.def.json +++ b/resources/definitions/fdmprinter.def.json @@ -1647,7 +1647,7 @@ "concentric": "Concentric", "zigzag": "Zig Zag" }, - "default_value": "'zigzag'", + "default_value": "zigzag", "enabled": "ironing_enabled", "limit_to_extruder": "top_bottom_extruder_nr", "settable_per_mesh": true @@ -4477,7 +4477,7 @@ "cross": "Cross", "gyroid": "Gyroid" }, - "default_value": "'zigzag'", + "default_value": "zigzag", "enabled": "support_enable or support_meshes_present", "limit_to_extruder": "support_infill_extruder_nr", "settable_per_mesh": false, diff --git a/resources/definitions/maker_starter.def.json b/resources/definitions/maker_starter.def.json index 471de6ff0c..d847bd4fe5 100644 --- a/resources/definitions/maker_starter.def.json +++ b/resources/definitions/maker_starter.def.json @@ -78,7 +78,7 @@ "default_value": 0.2 }, "support_pattern": { - "default_value": "'zigzag'" + "default_value": "ZigZag" }, "support_infill_rate": { "value": "15 if support_enable and support_structure == 'normal' else 0 if support_enable and support_structure == 'tree' else 15" diff --git a/resources/definitions/trimaker_cosmosII.def.json b/resources/definitions/trimaker_cosmosII.def.json index 1102b9f65a..45072df1b1 100644 --- a/resources/definitions/trimaker_cosmosII.def.json +++ b/resources/definitions/trimaker_cosmosII.def.json @@ -182,7 +182,7 @@ "support_enable": {"default_value": true}, "support_type": {"default_value": "everywhere"}, "support_angle": {"default_value": 50}, - "support_pattern": {"default_value": "'zigzag'"}, + "support_pattern": {"default_value": "zigzag"}, "support_z_distance": {"default_value": 0.17}, "support_xy_distance": {"default_value": 0.7}, "adhesion_type": {"default_value": "skirt"}, diff --git a/resources/definitions/trimaker_nebula.def.json b/resources/definitions/trimaker_nebula.def.json index 5a9c93b837..46e57f96e5 100644 --- a/resources/definitions/trimaker_nebula.def.json +++ b/resources/definitions/trimaker_nebula.def.json @@ -182,7 +182,7 @@ "support_enable": {"default_value": true}, "support_type": {"default_value": "everywhere"}, "support_angle": {"default_value": 50}, - "support_pattern": {"default_value": "'zigzag'"}, + "support_pattern": {"default_value": "zigzag"}, "support_z_distance": {"default_value": 0.17}, "support_xy_distance": {"default_value": 0.7}, "adhesion_type": {"default_value": "skirt"}, From 71c6df8829fbf566ab2fd6d67eb1b37a55256670 Mon Sep 17 00:00:00 2001 From: Remco Burema Date: Wed, 17 Nov 2021 14:35:16 +0100 Subject: [PATCH 14/15] Fix capitalization in what (should) refer(s) to a key-value. CURA-8701 --- resources/definitions/maker_starter.def.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/definitions/maker_starter.def.json b/resources/definitions/maker_starter.def.json index d847bd4fe5..ea849b7039 100644 --- a/resources/definitions/maker_starter.def.json +++ b/resources/definitions/maker_starter.def.json @@ -78,7 +78,7 @@ "default_value": 0.2 }, "support_pattern": { - "default_value": "ZigZag" + "default_value": "zigzag" }, "support_infill_rate": { "value": "15 if support_enable and support_structure == 'normal' else 0 if support_enable and support_structure == 'tree' else 15" From 52d639f980ced4a97dc82663f10ad60cb5bf0689 Mon Sep 17 00:00:00 2001 From: Jelle Spijker Date: Wed, 17 Nov 2021 19:49:47 +0100 Subject: [PATCH 15/15] fixed missing , in json --- resources/definitions/ultimaker.def.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/definitions/ultimaker.def.json b/resources/definitions/ultimaker.def.json index 33ef546dab..9e0182a966 100644 --- a/resources/definitions/ultimaker.def.json +++ b/resources/definitions/ultimaker.def.json @@ -43,7 +43,7 @@ }, "skin_angles": { "value": "[] if infill_pattern not in ['cross', 'cross_3d'] else [20, 110]" - } + }, "line_width": { "value": "machine_nozzle_size" },