From 484740f2ff3b8dab8e4bea00892c4d2229dda25b Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Wed, 16 Aug 2017 13:26:17 +0200 Subject: [PATCH 01/10] Remove grid pattern It'll be replaced by grid lines instead of grid surfaces. Contributes to issue CURA-4150. --- cura/BuildVolume.py | 3 +-- resources/shaders/grid.shader | 21 +++++---------------- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/cura/BuildVolume.py b/cura/BuildVolume.py index e37268e244..e613daa947 100755 --- a/cura/BuildVolume.py +++ b/cura/BuildVolume.py @@ -169,8 +169,7 @@ class BuildVolume(SceneNode): self._shader = OpenGL.getInstance().createShaderProgram(Resources.getPath(Resources.Shaders, "default.shader")) self._grid_shader = OpenGL.getInstance().createShaderProgram(Resources.getPath(Resources.Shaders, "grid.shader")) theme = Application.getInstance().getTheme() - self._grid_shader.setUniformValue("u_gridColor0", Color(*theme.getColor("buildplate").getRgb())) - self._grid_shader.setUniformValue("u_gridColor1", Color(*theme.getColor("buildplate_alt").getRgb())) + self._grid_shader.setUniformValue("u_buildplateColor", Color(*theme.getColor("buildplate").getRgb())) renderer.queueNode(self, mode = RenderBatch.RenderMode.Lines) renderer.queueNode(self, mesh = self._origin_mesh) diff --git a/resources/shaders/grid.shader b/resources/shaders/grid.shader index 74eed544fd..ece93cb51e 100644 --- a/resources/shaders/grid.shader +++ b/resources/shaders/grid.shader @@ -14,17 +14,12 @@ vertex = } fragment = - uniform lowp vec4 u_gridColor0; - uniform lowp vec4 u_gridColor1; - + uniform lowp vec4 u_buildplateColor; varying lowp vec2 v_uvs; void main() { - if (mod(floor(v_uvs.x / 10.0) - floor(v_uvs.y / 10.0), 2.0) < 1.0) - gl_FragColor = u_gridColor0; - else - gl_FragColor = u_gridColor1; + gl_FragColor = u_buildplateColor; } vertex41core = @@ -44,23 +39,17 @@ vertex41core = fragment41core = #version 410 - uniform lowp vec4 u_gridColor0; - uniform lowp vec4 u_gridColor1; - + uniform lowp vec4 u_buildplateColor; in lowp vec2 v_uvs; out vec4 frag_color; void main() { - if (mod(floor(v_uvs.x / 10.0) - floor(v_uvs.y / 10.0), 2.0) < 1.0) - frag_color = u_gridColor0; - else - frag_color = u_gridColor1; + gl_FragColor = u_buildplateColor; } [defaults] -u_gridColor0 = [0.96, 0.96, 0.96, 1.0] -u_gridColor1 = [0.8, 0.8, 0.8, 1.0] +u_buildplateColor = [0.96, 0.96, 0.96, 1.0] [bindings] u_modelViewProjectionMatrix = model_view_projection_matrix From 5e63c0df48d44e4b4bd23f7da29443ea47d77cf3 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Thu, 17 Aug 2017 09:56:11 +0200 Subject: [PATCH 02/10] Add major grid cells This draws a grid of 1x1cm. Contributes to issue CURA-4150. --- cura/BuildVolume.py | 21 +++++++++++++++++++-- resources/themes/cura/theme.json | 1 + 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/cura/BuildVolume.py b/cura/BuildVolume.py index e613daa947..2d1526aee5 100755 --- a/cura/BuildVolume.py +++ b/cura/BuildVolume.py @@ -56,6 +56,7 @@ class BuildVolume(SceneNode): self._origin_line_length = 20 self._origin_line_width = 0.5 + self._plate_mesh = None self._grid_mesh = None self._grid_shader = None @@ -173,7 +174,8 @@ class BuildVolume(SceneNode): renderer.queueNode(self, mode = RenderBatch.RenderMode.Lines) renderer.queueNode(self, mesh = self._origin_mesh) - renderer.queueNode(self, mesh = self._grid_mesh, shader = self._grid_shader, backface_cull = True) + renderer.queueNode(self, mesh = self._plate_mesh, shader = self._grid_shader, backface_cull = True) + renderer.queueNode(self, mesh = self._grid_mesh, mode = RenderBatch.RenderMode.Lines) if self._disallowed_area_mesh: renderer.queueNode(self, mesh = self._disallowed_area_mesh, shader = self._shader, transparent = True, backface_cull = True, sort = -9) @@ -246,6 +248,7 @@ class BuildVolume(SceneNode): self._z_axis_color = Color(*theme.getColor("z_axis").getRgb()) self._disallowed_area_color = Color(*theme.getColor("disallowed_area").getRgb()) self._error_area_color = Color(*theme.getColor("error_area").getRgb()) + self._grid_color = Color(*theme.getColor("buildplate_grid").getRgb()) min_w = -self._width / 2 max_w = self._width / 2 @@ -276,7 +279,7 @@ class BuildVolume(SceneNode): self.setMeshData(mb.build()) - # Build plate grid mesh + # Build plate surface. mb = MeshBuilder() mb.addQuad( Vector(min_w, min_h - z_fight_distance, min_d), @@ -288,6 +291,20 @@ class BuildVolume(SceneNode): for n in range(0, 6): v = mb.getVertex(n) mb.setVertexUVCoordinates(n, v[0], v[2]) + self._plate_mesh = mb.build() + + #Build plate grid mesh. + major_grid_size = 10 #In millimetres. + mb = MeshBuilder() + for x in range(0, int(math.ceil(max_w)), major_grid_size): + mb.addLine(Vector(x, min_h, min_d), Vector(x, min_h, max_d), color = self._grid_color) + for x in range(0, int(math.floor(min_w)), -major_grid_size): #Start from 0 in both cases, so you need to do this in two for loops. + mb.addLine(Vector(x, min_h, min_d), Vector(x, min_h, max_d), color = self._grid_color) + for y in range(0, int(math.ceil(max_d)), major_grid_size): + mb.addLine(Vector(min_w, min_h, y), Vector(max_w, min_h, y), color = self._grid_color) + for y in range(0, int(math.floor(min_d)), -major_grid_size): + mb.addLine(Vector(min_w, min_h, y), Vector(max_w, min_h, y), color = self._grid_color) + self._grid_mesh = mb.build() else: diff --git a/resources/themes/cura/theme.json b/resources/themes/cura/theme.json index d0919a8051..5a6179bb83 100644 --- a/resources/themes/cura/theme.json +++ b/resources/themes/cura/theme.json @@ -221,6 +221,7 @@ "volume_outline": [12, 169, 227, 255], "buildplate": [244, 244, 244, 255], "buildplate_alt": [204, 204, 204, 255], + "buildplate_grid": [129, 131, 134, 255], "convex_hull": [35, 35, 35, 127], "disallowed_area": [0, 0, 0, 40], From 6da5dda44fc1f77abc1051c6564a2ec31435942a Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Thu, 17 Aug 2017 10:21:48 +0200 Subject: [PATCH 03/10] Initialise _grid_color in __init__ All fields should always be defined throughout the lifetime of every object, according to code style. Contributes to issue CURA-4150. --- cura/BuildVolume.py | 1 + 1 file changed, 1 insertion(+) diff --git a/cura/BuildVolume.py b/cura/BuildVolume.py index 2d1526aee5..1089a0a806 100755 --- a/cura/BuildVolume.py +++ b/cura/BuildVolume.py @@ -44,6 +44,7 @@ class BuildVolume(SceneNode): self._z_axis_color = None self._disallowed_area_color = None self._error_area_color = None + self._grid_color = None self._width = 0 self._height = 0 From 38e907b3ae7d0b64278f63f9ce84f6a2bf10e9b2 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Thu, 17 Aug 2017 10:32:47 +0200 Subject: [PATCH 04/10] Add minor grid lines Makes it feel very professional and technical. Contributes to issue CURA-4150. --- cura/BuildVolume.py | 20 ++++++++++++++++++++ resources/themes/cura/theme.json | 1 + 2 files changed, 21 insertions(+) diff --git a/cura/BuildVolume.py b/cura/BuildVolume.py index 1089a0a806..f03ea91e36 100755 --- a/cura/BuildVolume.py +++ b/cura/BuildVolume.py @@ -45,6 +45,7 @@ class BuildVolume(SceneNode): self._disallowed_area_color = None self._error_area_color = None self._grid_color = None + self._grid_minor_color = None self._width = 0 self._height = 0 @@ -250,6 +251,7 @@ class BuildVolume(SceneNode): self._disallowed_area_color = Color(*theme.getColor("disallowed_area").getRgb()) self._error_area_color = Color(*theme.getColor("error_area").getRgb()) self._grid_color = Color(*theme.getColor("buildplate_grid").getRgb()) + self._grid_minor_color = Color(*theme.getColor("buildplate_grid_minor").getRgb()) min_w = -self._width / 2 max_w = self._width / 2 @@ -306,6 +308,24 @@ class BuildVolume(SceneNode): for y in range(0, int(math.floor(min_d)), -major_grid_size): mb.addLine(Vector(min_w, min_h, y), Vector(max_w, min_h, y), color = self._grid_color) + minor_grid_size = 1 + for x in range(0, int(math.ceil(max_w)), minor_grid_size): + if x % major_grid_size == 0: #Don't overlap with the major grid. + pass + mb.addLine(Vector(x, min_h, min_d), Vector(x, min_h, max_d), color = self._grid_minor_color) + for x in range(0, int(math.floor(min_w)), -minor_grid_size): + if x % major_grid_size == 0: + pass + mb.addLine(Vector(x, min_h, min_d), Vector(x, min_h, max_d), color = self._grid_minor_color) + for y in range(0, int(math.ceil(max_d)), minor_grid_size): + if y % major_grid_size == 0: + pass + mb.addLine(Vector(min_w, min_h, y), Vector(max_w, min_h, y), color = self._grid_minor_color) + for y in range(0, int(math.floor(min_d)), -minor_grid_size): + if y % major_grid_size == 0: + pass + mb.addLine(Vector(min_w, min_h, y), Vector(max_w, min_h, y), color = self._grid_minor_color) + self._grid_mesh = mb.build() else: diff --git a/resources/themes/cura/theme.json b/resources/themes/cura/theme.json index 5a6179bb83..7e5f6ae199 100644 --- a/resources/themes/cura/theme.json +++ b/resources/themes/cura/theme.json @@ -222,6 +222,7 @@ "buildplate": [244, 244, 244, 255], "buildplate_alt": [204, 204, 204, 255], "buildplate_grid": [129, 131, 134, 255], + "buildplate_grid_minor": [129, 131, 134, 31], "convex_hull": [35, 35, 35, 127], "disallowed_area": [0, 0, 0, 40], From bb3f8d085be5eb5a5ef889a4a2f70c509d2cda48 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Thu, 17 Aug 2017 10:35:00 +0200 Subject: [PATCH 05/10] Fix transparency of minor grid cells You need to turn it on manually, apparently. Contributes to issue CURA-4150. --- cura/BuildVolume.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cura/BuildVolume.py b/cura/BuildVolume.py index f03ea91e36..3c2819c40b 100755 --- a/cura/BuildVolume.py +++ b/cura/BuildVolume.py @@ -177,7 +177,7 @@ class BuildVolume(SceneNode): renderer.queueNode(self, mode = RenderBatch.RenderMode.Lines) renderer.queueNode(self, mesh = self._origin_mesh) renderer.queueNode(self, mesh = self._plate_mesh, shader = self._grid_shader, backface_cull = True) - renderer.queueNode(self, mesh = self._grid_mesh, mode = RenderBatch.RenderMode.Lines) + renderer.queueNode(self, mesh = self._grid_mesh, mode = RenderBatch.RenderMode.Lines, transparent = True) if self._disallowed_area_mesh: renderer.queueNode(self, mesh = self._disallowed_area_mesh, shader = self._shader, transparent = True, backface_cull = True, sort = -9) From 585b6ad8ebcf8933571f2fe6d4d5abe864df826f Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Thu, 17 Aug 2017 15:25:27 +0200 Subject: [PATCH 06/10] Remove superfluous grid shader The grid shader is now exactly equal to the colour shader, so let's just use the colour shader. Contributes to issue CURA-4150. --- cura/BuildVolume.py | 11 ++++--- resources/shaders/grid.shader | 59 ----------------------------------- 2 files changed, 6 insertions(+), 64 deletions(-) delete mode 100644 resources/shaders/grid.shader diff --git a/cura/BuildVolume.py b/cura/BuildVolume.py index 3c2819c40b..2076c59935 100755 --- a/cura/BuildVolume.py +++ b/cura/BuildVolume.py @@ -1,4 +1,4 @@ -# Copyright (c) 2016 Ultimaker B.V. +# Copyright (c) 2017 Ultimaker B.V. # Cura is released under the terms of the AGPLv3 or higher. from cura.Settings.ExtruderManager import ExtruderManager @@ -60,7 +60,7 @@ class BuildVolume(SceneNode): self._plate_mesh = None self._grid_mesh = None - self._grid_shader = None + self._plate_shader = None self._disallowed_areas = [] self._disallowed_area_mesh = None @@ -170,13 +170,13 @@ class BuildVolume(SceneNode): if not self._shader: self._shader = OpenGL.getInstance().createShaderProgram(Resources.getPath(Resources.Shaders, "default.shader")) - self._grid_shader = OpenGL.getInstance().createShaderProgram(Resources.getPath(Resources.Shaders, "grid.shader")) + self._plate_shader = OpenGL.getInstance().createShaderProgram(Resources.getPath(Resources.Shaders, "color.shader")) theme = Application.getInstance().getTheme() - self._grid_shader.setUniformValue("u_buildplateColor", Color(*theme.getColor("buildplate").getRgb())) + self._plate_shader.setUniformValue("u_color", Color(*theme.getColor("buildplate").getRgb())) renderer.queueNode(self, mode = RenderBatch.RenderMode.Lines) renderer.queueNode(self, mesh = self._origin_mesh) - renderer.queueNode(self, mesh = self._plate_mesh, shader = self._grid_shader, backface_cull = True) + renderer.queueNode(self, mesh = self._plate_mesh, shader = self._plate_shader, backface_cull = True) renderer.queueNode(self, mesh = self._grid_mesh, mode = RenderBatch.RenderMode.Lines, transparent = True) if self._disallowed_area_mesh: renderer.queueNode(self, mesh = self._disallowed_area_mesh, shader = self._shader, transparent = True, backface_cull = True, sort = -9) @@ -308,6 +308,7 @@ class BuildVolume(SceneNode): for y in range(0, int(math.floor(min_d)), -major_grid_size): mb.addLine(Vector(min_w, min_h, y), Vector(max_w, min_h, y), color = self._grid_color) + #More fine grained grid. minor_grid_size = 1 for x in range(0, int(math.ceil(max_w)), minor_grid_size): if x % major_grid_size == 0: #Don't overlap with the major grid. diff --git a/resources/shaders/grid.shader b/resources/shaders/grid.shader deleted file mode 100644 index ece93cb51e..0000000000 --- a/resources/shaders/grid.shader +++ /dev/null @@ -1,59 +0,0 @@ -[shaders] -vertex = - uniform highp mat4 u_modelViewProjectionMatrix; - - attribute highp vec4 a_vertex; - attribute lowp vec2 a_uvs; - - varying lowp vec2 v_uvs; - - void main() - { - gl_Position = u_modelViewProjectionMatrix * a_vertex; - v_uvs = a_uvs; - } - -fragment = - uniform lowp vec4 u_buildplateColor; - varying lowp vec2 v_uvs; - - void main() - { - gl_FragColor = u_buildplateColor; - } - -vertex41core = - #version 410 - uniform highp mat4 u_modelViewProjectionMatrix; - - in highp vec4 a_vertex; - in lowp vec2 a_uvs; - - out lowp vec2 v_uvs; - - void main() - { - gl_Position = u_modelViewProjectionMatrix * a_vertex; - v_uvs = a_uvs; - } - -fragment41core = - #version 410 - uniform lowp vec4 u_buildplateColor; - in lowp vec2 v_uvs; - out vec4 frag_color; - - void main() - { - gl_FragColor = u_buildplateColor; - } - -[defaults] -u_buildplateColor = [0.96, 0.96, 0.96, 1.0] - -[bindings] -u_modelViewProjectionMatrix = model_view_projection_matrix - -[attributes] -a_vertex = vertex -a_uvs = uv0 From e7c585469494e22671046fb57ffd52d8aa4262de Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Mon, 21 Aug 2017 09:24:31 +0200 Subject: [PATCH 07/10] Make grid size into global variables It doesn't need to be a preference, but it should be easy to modify in the code. Contributes to issue CURA-4150. --- cura/BuildVolume.py | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/cura/BuildVolume.py b/cura/BuildVolume.py index 2076c59935..1530346967 100755 --- a/cura/BuildVolume.py +++ b/cura/BuildVolume.py @@ -27,8 +27,9 @@ import math from typing import List -# Setting for clearance around the prime -PRIME_CLEARANCE = 6.5 +PRIME_CLEARANCE = 6.5 #Setting for clearance around the prime. +MAJOR_GRID_SIZE = 10 #Size of the grid cells. +MINOR_GRID_SIZE = 1 ## Build volume is a special kind of node that is responsible for rendering the printable area & disallowed areas. @@ -297,33 +298,31 @@ class BuildVolume(SceneNode): self._plate_mesh = mb.build() #Build plate grid mesh. - major_grid_size = 10 #In millimetres. mb = MeshBuilder() - for x in range(0, int(math.ceil(max_w)), major_grid_size): + for x in range(0, int(math.ceil(max_w)), MAJOR_GRID_SIZE): mb.addLine(Vector(x, min_h, min_d), Vector(x, min_h, max_d), color = self._grid_color) - for x in range(0, int(math.floor(min_w)), -major_grid_size): #Start from 0 in both cases, so you need to do this in two for loops. + for x in range(0, int(math.floor(min_w)), -MAJOR_GRID_SIZE): #Start from 0 in both cases, so you need to do this in two for loops. mb.addLine(Vector(x, min_h, min_d), Vector(x, min_h, max_d), color = self._grid_color) - for y in range(0, int(math.ceil(max_d)), major_grid_size): + for y in range(0, int(math.ceil(max_d)), MAJOR_GRID_SIZE): mb.addLine(Vector(min_w, min_h, y), Vector(max_w, min_h, y), color = self._grid_color) - for y in range(0, int(math.floor(min_d)), -major_grid_size): + for y in range(0, int(math.floor(min_d)), -MAJOR_GRID_SIZE): mb.addLine(Vector(min_w, min_h, y), Vector(max_w, min_h, y), color = self._grid_color) #More fine grained grid. - minor_grid_size = 1 - for x in range(0, int(math.ceil(max_w)), minor_grid_size): - if x % major_grid_size == 0: #Don't overlap with the major grid. + for x in range(0, int(math.ceil(max_w)), MINOR_GRID_SIZE): + if x % MAJOR_GRID_SIZE == 0: #Don't overlap with the major grid. pass mb.addLine(Vector(x, min_h, min_d), Vector(x, min_h, max_d), color = self._grid_minor_color) - for x in range(0, int(math.floor(min_w)), -minor_grid_size): - if x % major_grid_size == 0: + for x in range(0, int(math.floor(min_w)), -MINOR_GRID_SIZE): + if x % MAJOR_GRID_SIZE == 0: pass mb.addLine(Vector(x, min_h, min_d), Vector(x, min_h, max_d), color = self._grid_minor_color) - for y in range(0, int(math.ceil(max_d)), minor_grid_size): - if y % major_grid_size == 0: + for y in range(0, int(math.ceil(max_d)), MINOR_GRID_SIZE): + if y % MAJOR_GRID_SIZE == 0: pass mb.addLine(Vector(min_w, min_h, y), Vector(max_w, min_h, y), color = self._grid_minor_color) - for y in range(0, int(math.floor(min_d)), -minor_grid_size): - if y % major_grid_size == 0: + for y in range(0, int(math.floor(min_d)), -MINOR_GRID_SIZE): + if y % MAJOR_GRID_SIZE == 0: pass mb.addLine(Vector(min_w, min_h, y), Vector(max_w, min_h, y), color = self._grid_minor_color) From d8dd9c0d3af77cebf0c93433f59c95b33ecd50f4 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Mon, 21 Aug 2017 09:44:39 +0200 Subject: [PATCH 08/10] More efficient and elegant grid line creation Since the zero point is always in the centre, we can just re-use this loop to prevent code duplication and gain a minor speed increase. Contributes to issue CURA-4150. --- cura/BuildVolume.py | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/cura/BuildVolume.py b/cura/BuildVolume.py index 1530346967..6c18eb07ad 100755 --- a/cura/BuildVolume.py +++ b/cura/BuildVolume.py @@ -301,30 +301,23 @@ class BuildVolume(SceneNode): mb = MeshBuilder() for x in range(0, int(math.ceil(max_w)), MAJOR_GRID_SIZE): mb.addLine(Vector(x, min_h, min_d), Vector(x, min_h, max_d), color = self._grid_color) - for x in range(0, int(math.floor(min_w)), -MAJOR_GRID_SIZE): #Start from 0 in both cases, so you need to do this in two for loops. - mb.addLine(Vector(x, min_h, min_d), Vector(x, min_h, max_d), color = self._grid_color) + #Start from 0 in both cases, so you need to do this in two for loops. + mb.addLine(Vector(-x, min_h, min_d), Vector(-x, min_h, max_d), color = self._grid_color) for y in range(0, int(math.ceil(max_d)), MAJOR_GRID_SIZE): mb.addLine(Vector(min_w, min_h, y), Vector(max_w, min_h, y), color = self._grid_color) - for y in range(0, int(math.floor(min_d)), -MAJOR_GRID_SIZE): - mb.addLine(Vector(min_w, min_h, y), Vector(max_w, min_h, y), color = self._grid_color) + mb.addLine(Vector(min_w, min_h, -y), Vector(max_w, min_h, -y), color = self._grid_color) #More fine grained grid. for x in range(0, int(math.ceil(max_w)), MINOR_GRID_SIZE): if x % MAJOR_GRID_SIZE == 0: #Don't overlap with the major grid. pass mb.addLine(Vector(x, min_h, min_d), Vector(x, min_h, max_d), color = self._grid_minor_color) - for x in range(0, int(math.floor(min_w)), -MINOR_GRID_SIZE): - if x % MAJOR_GRID_SIZE == 0: - pass - mb.addLine(Vector(x, min_h, min_d), Vector(x, min_h, max_d), color = self._grid_minor_color) + mb.addLine(Vector(-x, min_h, min_d), Vector(-x, min_h, max_d), color = self._grid_minor_color) for y in range(0, int(math.ceil(max_d)), MINOR_GRID_SIZE): if y % MAJOR_GRID_SIZE == 0: pass mb.addLine(Vector(min_w, min_h, y), Vector(max_w, min_h, y), color = self._grid_minor_color) - for y in range(0, int(math.floor(min_d)), -MINOR_GRID_SIZE): - if y % MAJOR_GRID_SIZE == 0: - pass - mb.addLine(Vector(min_w, min_h, y), Vector(max_w, min_h, y), color = self._grid_minor_color) + mb.addLine(Vector(min_w, min_h, -y), Vector(max_w, min_h, -y), color = self._grid_minor_color) self._grid_mesh = mb.build() From 3b93a9d309e0eefb4501c164349f84f119f6b4c3 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Mon, 21 Aug 2017 10:21:25 +0200 Subject: [PATCH 09/10] Add grid lines for circular build plates Some trigonometry is involved to find the correct lengths for the lines. Contributes to issue CURA-4150. --- cura/BuildVolume.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/cura/BuildVolume.py b/cura/BuildVolume.py index 6c18eb07ad..8298d6de0c 100755 --- a/cura/BuildVolume.py +++ b/cura/BuildVolume.py @@ -334,7 +334,7 @@ class BuildVolume(SceneNode): mb.addArc(max_w, Vector.Unit_Y, center = (0, max_h, 0), color = self._volume_outline_color) self.setMeshData(mb.build().getTransformed(scale_matrix)) - # Build plate grid mesh + # Build plate surface. mb = MeshBuilder() mb.addVertex(0, min_h - z_fight_distance, 0) mb.addArc(max_w, Vector.Unit_Y, center = Vector(0, min_h - z_fight_distance, 0)) @@ -348,7 +348,26 @@ class BuildVolume(SceneNode): for n in range(0, mb.getVertexCount()): v = mb.getVertex(n) mb.setVertexUVCoordinates(n, v[0], v[2] * aspect) - self._grid_mesh = mb.build().getTransformed(scale_matrix) + self._plate_mesh = mb.build().getTransformed(scale_matrix) + + #Build plate grid mesh. + #We need to constrain the length of the lines to the build plate ellipsis. Time to get out the calculator! + mb = MeshBuilder() + for x in range(0, int(math.ceil(max_w)), MAJOR_GRID_SIZE): + #x / max_w is the fraction along the build plate we have progressed, counting from the centre. + #So x / max_w is sin(a), where a is the angle towards an endpoint of the grid line from the centre. + #So math.asin(x / max_w) is a. + #So math.cos(math.asin(x / max_w)) is half of the length of the grid line on a unit circle, which scales between 0 and 1. + length_factor = math.cos(math.asin(x / max_w)) + mb.addLine(Vector(x, min_h, min_d * length_factor), Vector(x, min_h, max_d * length_factor), color = self._grid_color) + #Start from 0 in both cases, so you need to do this in two for loops. + mb.addLine(Vector(-x, min_h, min_d * length_factor), Vector(-x, min_h, max_d * length_factor), color = self._grid_color) + for y in range(0, int(math.ceil(max_d)), MAJOR_GRID_SIZE): + length_factor = math.sin(math.acos(y / max_d)) + mb.addLine(Vector(min_w * length_factor, min_h, y), Vector(max_w * length_factor, min_h, y), color = self._grid_color) + mb.addLine(Vector(min_w * length_factor, min_h, -y), Vector(max_w * length_factor, min_h, -y), color = self._grid_color) + + self._grid_mesh = mb.build() # Indication of the machine origin if self._global_container_stack.getProperty("machine_center_is_zero", "value"): From 25c5c5a88836f30ceb71c1d333ba76f939aafe2e Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Mon, 21 Aug 2017 10:24:53 +0200 Subject: [PATCH 10/10] Add minor grid cells for circular build plates Same technique as the major grid cells. Contributes to issue CURA-4150. --- cura/BuildVolume.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/cura/BuildVolume.py b/cura/BuildVolume.py index 8298d6de0c..2757a37609 100755 --- a/cura/BuildVolume.py +++ b/cura/BuildVolume.py @@ -367,6 +367,20 @@ class BuildVolume(SceneNode): mb.addLine(Vector(min_w * length_factor, min_h, y), Vector(max_w * length_factor, min_h, y), color = self._grid_color) mb.addLine(Vector(min_w * length_factor, min_h, -y), Vector(max_w * length_factor, min_h, -y), color = self._grid_color) + #More fine grained grid. + for x in range(0, int(math.ceil(max_w)), MINOR_GRID_SIZE): + if x % MAJOR_GRID_SIZE == 0: #Don't overlap with the major grid. + pass + length_factor = math.cos(math.asin(x / max_w)) + mb.addLine(Vector(x, min_h, min_d * length_factor), Vector(x, min_h, max_d * length_factor), color = self._grid_minor_color) + mb.addLine(Vector(-x, min_h, min_d * length_factor), Vector(-x, min_h, max_d * length_factor), color = self._grid_minor_color) + for y in range(0, int(math.ceil(max_d)), MINOR_GRID_SIZE): + if y % MAJOR_GRID_SIZE == 0: + pass + length_factor = math.sin(math.acos(y / max_d)) + mb.addLine(Vector(min_w * length_factor, min_h, y), Vector(max_w * length_factor, min_h, y), color = self._grid_minor_color) + mb.addLine(Vector(min_w * length_factor, min_h, -y), Vector(max_w * length_factor, min_h, -y), color = self._grid_minor_color) + self._grid_mesh = mb.build() # Indication of the machine origin