Browse Source

Revert "Merge branch 'feature_grid_lines'"

This reverts commit a0b7a2d165d4f973c69bf5fc7314726f19eeeb65, reversing
changes made to db640c6f3d7b32b4c387268e8ebeb0d4de1b461a.

# Conflicts:
#	cura/BuildVolume.py
fieldOfView 7 years ago
parent
commit
a4aa134f25
2 changed files with 82 additions and 75 deletions
  1. 12 75
      cura/BuildVolume.py
  2. 70 0
      resources/shaders/grid.shader

+ 12 - 75
cura/BuildVolume.py

@@ -1,4 +1,4 @@
-# Copyright (c) 2017 Ultimaker B.V.
+# Copyright (c) 2016 Ultimaker B.V.
 # Cura is released under the terms of the AGPLv3 or higher.
 # Cura is released under the terms of the AGPLv3 or higher.
 
 
 from cura.Settings.ExtruderManager import ExtruderManager
 from cura.Settings.ExtruderManager import ExtruderManager
@@ -27,9 +27,8 @@ import math
 
 
 from typing import List
 from typing import List
 
 
-PRIME_CLEARANCE = 6.5 #Setting for clearance around the prime.
-MAJOR_GRID_SIZE = 10 #Size of the grid cells.
-MINOR_GRID_SIZE = 1
+# Setting for clearance around the prime
+PRIME_CLEARANCE = 6.5
 
 
 
 
 ##  Build volume is a special kind of node that is responsible for rendering the printable area & disallowed areas.
 ##  Build volume is a special kind of node that is responsible for rendering the printable area & disallowed areas.
@@ -45,8 +44,6 @@ class BuildVolume(SceneNode):
         self._z_axis_color = None
         self._z_axis_color = None
         self._disallowed_area_color = None
         self._disallowed_area_color = None
         self._error_area_color = None
         self._error_area_color = None
-        self._grid_color = None
-        self._grid_minor_color = None
 
 
         self._width = 0
         self._width = 0
         self._height = 0
         self._height = 0
@@ -59,9 +56,8 @@ class BuildVolume(SceneNode):
         self._origin_line_length = 20
         self._origin_line_length = 20
         self._origin_line_width = 0.5
         self._origin_line_width = 0.5
 
 
-        self._plate_mesh = None
         self._grid_mesh = None
         self._grid_mesh = None
-        self._plate_shader = None
+        self._grid_shader = None
 
 
         self._disallowed_areas = []
         self._disallowed_areas = []
         self._disallowed_area_mesh = None
         self._disallowed_area_mesh = None
@@ -180,15 +176,15 @@ class BuildVolume(SceneNode):
 
 
         if not self._shader:
         if not self._shader:
             self._shader = OpenGL.getInstance().createShaderProgram(Resources.getPath(Resources.Shaders, "default.shader"))
             self._shader = OpenGL.getInstance().createShaderProgram(Resources.getPath(Resources.Shaders, "default.shader"))
-            self._plate_shader = OpenGL.getInstance().createShaderProgram(Resources.getPath(Resources.Shaders, "color.shader"))
+            self._grid_shader = OpenGL.getInstance().createShaderProgram(Resources.getPath(Resources.Shaders, "grid.shader"))
             theme = Application.getInstance().getTheme()
             theme = Application.getInstance().getTheme()
-            self._plate_shader.setUniformValue("u_color", Color(*theme.getColor("buildplate").getRgb()))
-            self._plate_shader.setUniformValue("u_z_bias", 0.000001)
+            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_z_bias", 0.000001)
 
 
         renderer.queueNode(self, mode = RenderBatch.RenderMode.Lines)
         renderer.queueNode(self, mode = RenderBatch.RenderMode.Lines)
         renderer.queueNode(self, mesh = self._origin_mesh)
         renderer.queueNode(self, mesh = self._origin_mesh)
-        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)
+        renderer.queueNode(self, mesh = self._grid_mesh, shader = self._grid_shader, backface_cull = True)
         if self._disallowed_area_mesh:
         if self._disallowed_area_mesh:
             renderer.queueNode(self, mesh = self._disallowed_area_mesh, shader = self._shader, transparent = True, backface_cull = True, sort = -9)
             renderer.queueNode(self, mesh = self._disallowed_area_mesh, shader = self._shader, transparent = True, backface_cull = True, sort = -9)
 
 
@@ -261,8 +257,6 @@ class BuildVolume(SceneNode):
             self._z_axis_color = Color(*theme.getColor("z_axis").getRgb())
             self._z_axis_color = Color(*theme.getColor("z_axis").getRgb())
             self._disallowed_area_color = Color(*theme.getColor("disallowed_area").getRgb())
             self._disallowed_area_color = Color(*theme.getColor("disallowed_area").getRgb())
             self._error_area_color = Color(*theme.getColor("error_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
         min_w = -self._width / 2
         max_w = self._width / 2
         max_w = self._width / 2
@@ -293,7 +287,7 @@ class BuildVolume(SceneNode):
 
 
             self.setMeshData(mb.build())
             self.setMeshData(mb.build())
 
 
-            # Build plate surface.
+            # Build plate grid mesh
             mb = MeshBuilder()
             mb = MeshBuilder()
             mb.addQuad(
             mb.addQuad(
                 Vector(min_w, min_h - z_fight_distance, min_d),
                 Vector(min_w, min_h - z_fight_distance, min_d),
@@ -305,30 +299,6 @@ class BuildVolume(SceneNode):
             for n in range(0, 6):
             for n in range(0, 6):
                 v = mb.getVertex(n)
                 v = mb.getVertex(n)
                 mb.setVertexUVCoordinates(n, v[0], v[2])
                 mb.setVertexUVCoordinates(n, v[0], v[2])
-            self._plate_mesh = mb.build()
-
-            #Build plate grid mesh.
-            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)
-                #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)
-                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)
-                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)
-                mb.addLine(Vector(min_w, min_h, -y), Vector(max_w, min_h, -y), color = self._grid_minor_color)
-
             self._grid_mesh = mb.build()
             self._grid_mesh = mb.build()
 
 
         else:
         else:
@@ -344,7 +314,7 @@ class BuildVolume(SceneNode):
             mb.addArc(max_w, Vector.Unit_Y, center = (0, max_h, 0),  color = self._volume_outline_color)
             mb.addArc(max_w, Vector.Unit_Y, center = (0, max_h, 0),  color = self._volume_outline_color)
             self.setMeshData(mb.build().getTransformed(scale_matrix))
             self.setMeshData(mb.build().getTransformed(scale_matrix))
 
 
-            # Build plate surface.
+            # Build plate grid mesh
             mb = MeshBuilder()
             mb = MeshBuilder()
             mb.addVertex(0, min_h - z_fight_distance, 0)
             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))
             mb.addArc(max_w, Vector.Unit_Y, center = Vector(0, min_h - z_fight_distance, 0))
@@ -358,40 +328,7 @@ class BuildVolume(SceneNode):
             for n in range(0, mb.getVertexCount()):
             for n in range(0, mb.getVertexCount()):
                 v = mb.getVertex(n)
                 v = mb.getVertex(n)
                 mb.setVertexUVCoordinates(n, v[0], v[2] * aspect)
                 mb.setVertexUVCoordinates(n, v[0], v[2] * aspect)
-            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)
-
-            #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()
+            self._grid_mesh = mb.build().getTransformed(scale_matrix)
 
 
         # Indication of the machine origin
         # Indication of the machine origin
         if self._global_container_stack.getProperty("machine_center_is_zero", "value"):
         if self._global_container_stack.getProperty("machine_center_is_zero", "value"):

+ 70 - 0
resources/shaders/grid.shader

@@ -0,0 +1,70 @@
+[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_gridColor0;
+    uniform lowp vec4 u_gridColor1;
+
+    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;
+    }
+
+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_gridColor0;
+    uniform lowp vec4 u_gridColor1;
+
+    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;
+    }
+
+[defaults]
+u_gridColor0 = [0.96, 0.96, 0.96, 1.0]
+u_gridColor1 = [0.8, 0.8, 0.8, 1.0]
+
+[bindings]
+u_modelViewProjectionMatrix = model_view_projection_matrix
+
+[attributes]
+a_vertex = vertex
+a_uvs = uv0