mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-05-09 18:29:01 +08:00
Merge branch 'feature_grid_lines'
CURA-4150
This commit is contained in:
commit
a0b7a2d165
@ -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
|
||||
@ -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.
|
||||
@ -44,6 +45,8 @@ class BuildVolume(SceneNode):
|
||||
self._z_axis_color = None
|
||||
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
|
||||
@ -56,8 +59,9 @@ 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
|
||||
self._plate_shader = None
|
||||
|
||||
self._disallowed_areas = []
|
||||
self._disallowed_area_mesh = None
|
||||
@ -167,14 +171,14 @@ 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_gridColor0", Color(*theme.getColor("buildplate").getRgb()))
|
||||
self._grid_shader.setUniformValue("u_gridColor1", Color(*theme.getColor("buildplate_alt").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._grid_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)
|
||||
|
||||
@ -247,6 +251,8 @@ 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())
|
||||
self._grid_minor_color = Color(*theme.getColor("buildplate_grid_minor").getRgb())
|
||||
|
||||
min_w = -self._width / 2
|
||||
max_w = self._width / 2
|
||||
@ -277,7 +283,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),
|
||||
@ -289,6 +295,30 @@ 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.
|
||||
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()
|
||||
|
||||
else:
|
||||
@ -304,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))
|
||||
@ -318,7 +348,40 @@ 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)
|
||||
|
||||
#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
|
||||
if self._global_container_stack.getProperty("machine_center_is_zero", "value"):
|
||||
|
@ -1,70 +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_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
|
@ -221,6 +221,8 @@
|
||||
"volume_outline": [12, 169, 227, 255],
|
||||
"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],
|
||||
|
Loading…
x
Reference in New Issue
Block a user