mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-08-14 14:35:56 +08:00
Merge branch 'master' of https://github.com/Ultimaker/Cura
This commit is contained in:
commit
9564b4753e
@ -27,9 +27,8 @@ import math
|
|||||||
|
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
PRIME_CLEARANCE = 6.5 #Setting for clearance around the prime.
|
# Setting for clearance around the prime
|
||||||
MAJOR_GRID_SIZE = 10 #Size of the grid cells.
|
PRIME_CLEARANCE = 6.5
|
||||||
MINOR_GRID_SIZE = 1
|
|
||||||
|
|
||||||
|
|
||||||
## 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._grid_shader.setUniformValue("u_plateColor", Color(*theme.getColor("buildplate").getRgb()))
|
||||||
self._plate_shader.setUniformValue("u_z_bias", 0.000001)
|
self._grid_shader.setUniformValue("u_gridColor0", Color(*theme.getColor("buildplate_grid").getRgb()))
|
||||||
|
self._grid_shader.setUniformValue("u_gridColor1", Color(*theme.getColor("buildplate_grid_minor").getRgb()))
|
||||||
|
|
||||||
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, shader = self._grid_shader, backface_cull = True)
|
||||||
renderer.queueNode(self, mesh = self._grid_mesh, mode = RenderBatch.RenderMode.Lines, transparent = 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)
|
self._grid_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
|
# 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"):
|
||||||
|
@ -181,7 +181,7 @@ Rectangle
|
|||||||
color: (control.checked || control.pressed) ? UM.Theme.getColor("action_button_active_text") :
|
color: (control.checked || control.pressed) ? UM.Theme.getColor("action_button_active_text") :
|
||||||
control.hovered ? UM.Theme.getColor("action_button_hovered_text") :
|
control.hovered ? UM.Theme.getColor("action_button_hovered_text") :
|
||||||
UM.Theme.getColor("action_button_text")
|
UM.Theme.getColor("action_button_text")
|
||||||
font: (control.checked || control.pressed) ? UM.Theme.getFont("default_little_big") : UM.Theme.getFont("default")
|
font: UM.Theme.getFont("default")
|
||||||
text: control.text;
|
text: control.text;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -153,7 +153,7 @@ Column
|
|||||||
control.hovered ? UM.Theme.getColor("action_button_hovered_text") :
|
control.hovered ? UM.Theme.getColor("action_button_hovered_text") :
|
||||||
UM.Theme.getColor("action_button_text")
|
UM.Theme.getColor("action_button_text")
|
||||||
|
|
||||||
font: control.checked ? UM.Theme.getFont("default_bold") : UM.Theme.getFont("default")
|
font: UM.Theme.getFont("large_nonbold")
|
||||||
text: catalog.i18nc("@label", "Extruder")
|
text: catalog.i18nc("@label", "Extruder")
|
||||||
visible: width < (control.width - extruderIconItem.width - UM.Theme.getSize("default_margin").width)
|
visible: width < (control.width - extruderIconItem.width - UM.Theme.getSize("default_margin").width)
|
||||||
elide: Text.ElideRight
|
elide: Text.ElideRight
|
||||||
|
91
resources/shaders/grid.shader
Normal file
91
resources/shaders/grid.shader
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
[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_plateColor;
|
||||||
|
uniform lowp vec4 u_gridColor0;
|
||||||
|
uniform lowp vec4 u_gridColor1;
|
||||||
|
|
||||||
|
varying lowp vec2 v_uvs;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
vec2 coord = v_uvs.xy;
|
||||||
|
|
||||||
|
// Compute anti-aliased world-space minor grid lines
|
||||||
|
vec2 minorGrid = abs(fract(coord - 0.5) - 0.5) / fwidth(coord);
|
||||||
|
float minorLine = min(minorGrid.x, minorGrid.y);
|
||||||
|
|
||||||
|
vec4 minorGridColor = mix(u_plateColor, u_gridColor1, 1.0 - min(minorLine, 1.0));
|
||||||
|
|
||||||
|
// Compute anti-aliased world-space major grid lines
|
||||||
|
vec2 majorGrid = abs(fract(coord / 10 - 0.5) - 0.5) / fwidth(coord / 10);
|
||||||
|
float majorLine = min(majorGrid.x, majorGrid.y);
|
||||||
|
|
||||||
|
frag_color = mix(minorGridColor, u_gridColor0, 1.0 - min(majorLine, 1.0));
|
||||||
|
}
|
||||||
|
|
||||||
|
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_plateColor;
|
||||||
|
uniform lowp vec4 u_gridColor0;
|
||||||
|
uniform lowp vec4 u_gridColor1;
|
||||||
|
|
||||||
|
in lowp vec2 v_uvs;
|
||||||
|
out vec4 frag_color;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
vec2 coord = v_uvs.xy;
|
||||||
|
|
||||||
|
// Compute anti-aliased world-space minor grid lines
|
||||||
|
vec2 minorGrid = abs(fract(coord - 0.5) - 0.5) / fwidth(coord);
|
||||||
|
float minorLine = min(minorGrid.x, minorGrid.y);
|
||||||
|
|
||||||
|
vec4 minorGridColor = mix(u_plateColor, u_gridColor1, 1.0 - min(minorLine, 1.0));
|
||||||
|
|
||||||
|
// Compute anti-aliased world-space major grid lines
|
||||||
|
vec2 majorGrid = abs(fract(coord / 10 - 0.5) - 0.5) / fwidth(coord / 10);
|
||||||
|
float majorLine = min(majorGrid.x, majorGrid.y);
|
||||||
|
|
||||||
|
frag_color = mix(minorGridColor, u_gridColor0, 1.0 - min(majorLine, 1.0));
|
||||||
|
}
|
||||||
|
|
||||||
|
[defaults]
|
||||||
|
u_plateColor = [1.0, 1.0, 1.0, 1.0]
|
||||||
|
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
|
@ -248,9 +248,8 @@
|
|||||||
"viewport_background": [245, 245, 245, 255],
|
"viewport_background": [245, 245, 245, 255],
|
||||||
"volume_outline": [12, 169, 227, 255],
|
"volume_outline": [12, 169, 227, 255],
|
||||||
"buildplate": [244, 244, 244, 255],
|
"buildplate": [244, 244, 244, 255],
|
||||||
"buildplate_alt": [204, 204, 204, 255],
|
|
||||||
"buildplate_grid": [129, 131, 134, 255],
|
"buildplate_grid": [129, 131, 134, 255],
|
||||||
"buildplate_grid_minor": [129, 131, 134, 31],
|
"buildplate_grid_minor": [230, 230, 231, 255],
|
||||||
|
|
||||||
"convex_hull": [35, 35, 35, 127],
|
"convex_hull": [35, 35, 35, 127],
|
||||||
"disallowed_area": [0, 0, 0, 40],
|
"disallowed_area": [0, 0, 0, 40],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user