mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-06 22:47:29 -06:00
layers3d.shader now detects and draws 'starts' as boxes
Also adds a "show starts" option to the SimulationViewMenuComponent and corresponding logic SimulationPass.py adds a prev_line_types attribute to the shader, which the shader uses to compare with its line_type to detect starts.
This commit is contained in:
parent
2d1128f088
commit
757d7eee50
4 changed files with 58 additions and 1 deletions
|
@ -18,6 +18,7 @@ from cura.Settings.ExtruderManager import ExtruderManager
|
|||
|
||||
|
||||
import os.path
|
||||
import numpy
|
||||
|
||||
## RenderPass used to display g-code paths.
|
||||
from .NozzleNode import NozzleNode
|
||||
|
@ -71,6 +72,7 @@ class SimulationPass(RenderPass):
|
|||
self._layer_shader.setUniformValue("u_show_helpers", self._layer_view.getShowHelpers())
|
||||
self._layer_shader.setUniformValue("u_show_skin", self._layer_view.getShowSkin())
|
||||
self._layer_shader.setUniformValue("u_show_infill", self._layer_view.getShowInfill())
|
||||
self._layer_shader.setUniformValue("u_show_starts", self._layer_view.getShowStarts())
|
||||
else:
|
||||
#defaults
|
||||
self._layer_shader.setUniformValue("u_max_feedrate", 1)
|
||||
|
@ -83,6 +85,7 @@ class SimulationPass(RenderPass):
|
|||
self._layer_shader.setUniformValue("u_show_helpers", 1)
|
||||
self._layer_shader.setUniformValue("u_show_skin", 1)
|
||||
self._layer_shader.setUniformValue("u_show_infill", 1)
|
||||
self._layer_shader.setUniformValue("u_show_starts", 1)
|
||||
|
||||
if not self._tool_handle_shader:
|
||||
self._tool_handle_shader = OpenGL.getInstance().createShaderProgram(Resources.getPath(Resources.Shaders, "toolhandle.shader"))
|
||||
|
@ -161,6 +164,12 @@ class SimulationPass(RenderPass):
|
|||
self._current_shader = self._layer_shader
|
||||
self._switching_layers = True
|
||||
|
||||
# The first line does not have a previous line: add a zero in front
|
||||
prev_line_types = numpy.concatenate([numpy.asarray([0], dtype=numpy.float32), layer_data._attributes["line_types"]["value"]])
|
||||
# Remove the last element
|
||||
prev_line_types = prev_line_types[0:layer_data._attributes["line_types"]["value"].size]
|
||||
layer_data._attributes["prev_line_types"] = {'opengl_type': 'float', 'value': prev_line_types, 'opengl_name': 'a_prev_line_type'}
|
||||
|
||||
layers_batch = RenderBatch(self._current_shader, type = RenderBatch.RenderType.Solid, mode = RenderBatch.RenderMode.Lines, range = (start, end), backface_cull = True)
|
||||
layers_batch.addItem(node.getWorldTransformation(), layer_data)
|
||||
layers_batch.render(self._scene.getActiveCamera())
|
||||
|
|
|
@ -111,6 +111,7 @@ class SimulationView(CuraView):
|
|||
Application.getInstance().getPreferences().addPreference("layerview/show_helpers", True)
|
||||
Application.getInstance().getPreferences().addPreference("layerview/show_skin", True)
|
||||
Application.getInstance().getPreferences().addPreference("layerview/show_infill", True)
|
||||
Application.getInstance().getPreferences().addPreference("layerview/show_starts", True)
|
||||
|
||||
self._updateWithPreferences()
|
||||
|
||||
|
@ -146,6 +147,7 @@ class SimulationView(CuraView):
|
|||
self._show_helpers = True
|
||||
self._show_skin = True
|
||||
self._show_infill = True
|
||||
self._show_starts = True
|
||||
self.resetLayerData()
|
||||
|
||||
def getActivity(self) -> bool:
|
||||
|
@ -355,6 +357,13 @@ class SimulationView(CuraView):
|
|||
def getShowInfill(self) -> bool:
|
||||
return self._show_infill
|
||||
|
||||
def setShowStarts(self, show: bool) -> None:
|
||||
self._show_starts = show
|
||||
self.currentLayerNumChanged.emit()
|
||||
|
||||
def getShowStarts(self) -> bool:
|
||||
return self._show_starts
|
||||
|
||||
def getCompatibilityMode(self) -> bool:
|
||||
return self._compatibility_mode
|
||||
|
||||
|
@ -638,6 +647,7 @@ class SimulationView(CuraView):
|
|||
self.setShowHelpers(bool(Application.getInstance().getPreferences().getValue("layerview/show_helpers")))
|
||||
self.setShowSkin(bool(Application.getInstance().getPreferences().getValue("layerview/show_skin")))
|
||||
self.setShowInfill(bool(Application.getInstance().getPreferences().getValue("layerview/show_infill")))
|
||||
self.setShowStarts(bool(Application.getInstance().getPreferences().getValue("layerview/show_starts")))
|
||||
|
||||
self._startUpdateTopLayers()
|
||||
self.preferencesChanged.emit()
|
||||
|
@ -653,6 +663,7 @@ class SimulationView(CuraView):
|
|||
"layerview/show_helpers",
|
||||
"layerview/show_skin",
|
||||
"layerview/show_infill",
|
||||
"layerview/show_starts",
|
||||
}:
|
||||
return
|
||||
|
||||
|
|
|
@ -82,6 +82,7 @@ Cura.ExpandableComponent
|
|||
property bool show_helpers: UM.Preferences.getValue("layerview/show_helpers")
|
||||
property bool show_skin: UM.Preferences.getValue("layerview/show_skin")
|
||||
property bool show_infill: UM.Preferences.getValue("layerview/show_infill")
|
||||
property bool show_starts: UM.Preferences.getValue("layerview/show_starts")
|
||||
|
||||
// If we are in compatibility mode, we only show the "line type"
|
||||
property bool show_legend: UM.SimulationView.compatibilityMode ? true : UM.Preferences.getValue("layerview/layer_view_type") == 1
|
||||
|
@ -250,6 +251,12 @@ Cura.ExpandableComponent
|
|||
preference: "layerview/show_infill",
|
||||
colorId: "layerview_infill"
|
||||
});
|
||||
typesLegendModel.append({
|
||||
label: catalog.i18nc("@label", "Starts"),
|
||||
initialValue: viewSettings.show_starts,
|
||||
preference: "layerview/show_starts",
|
||||
colorId: "layerview_starts"
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ vertex41core =
|
|||
in highp vec4 a_normal;
|
||||
in highp vec2 a_line_dim; // line width and thickness
|
||||
in highp float a_extruder;
|
||||
in highp float a_prev_line_type;
|
||||
in highp float a_line_type;
|
||||
in highp float a_feedrate;
|
||||
in highp float a_thickness;
|
||||
|
@ -32,6 +33,7 @@ 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 lowp vec4 f_color;
|
||||
|
@ -92,6 +94,7 @@ vertex41core =
|
|||
v_normal = (u_normalMatrix * normalize(a_normal)).xyz;
|
||||
v_line_dim = a_line_dim;
|
||||
v_extruder = int(a_extruder);
|
||||
v_prev_line_type = a_prev_line_type;
|
||||
v_line_type = a_line_type;
|
||||
v_extruder_opacity = u_extruder_opacity;
|
||||
|
||||
|
@ -112,9 +115,10 @@ geometry41core =
|
|||
uniform int u_show_helpers;
|
||||
uniform int u_show_skin;
|
||||
uniform int u_show_infill;
|
||||
uniform int u_show_starts;
|
||||
|
||||
layout(lines) in;
|
||||
layout(triangle_strip, max_vertices = 26) out;
|
||||
layout(triangle_strip, max_vertices = 40) out;
|
||||
|
||||
in vec4 v_color[];
|
||||
in vec3 v_vertex[];
|
||||
|
@ -122,6 +126,7 @@ geometry41core =
|
|||
in vec2 v_line_dim[];
|
||||
in int v_extruder[];
|
||||
in mat4 v_extruder_opacity[];
|
||||
in float v_prev_line_type[];
|
||||
in float v_line_type[];
|
||||
|
||||
out vec4 f_color;
|
||||
|
@ -268,6 +273,29 @@ geometry41core =
|
|||
|
||||
EndPrimitive();
|
||||
}
|
||||
|
||||
|
||||
if ((u_show_starts == 1) && (v_prev_line_type[0] != 1) && (v_line_type[0] == 1)) {
|
||||
float w = v_line_dim[0].x / 2;
|
||||
float h = v_line_dim[0].y / 2;
|
||||
|
||||
myEmitVertex(v_vertex[0] + vec3( w, h, w), vec4(1.0, 1.0, 1.0, 1.0), normalize(vec3( 1.0, 1.0, 1.0)), viewProjectionMatrix * (gl_in[0].gl_Position + vec4( w, h, w, 0.0))); // Front-top-left
|
||||
myEmitVertex(v_vertex[0] + vec3(-w, h, w), vec4(1.0, 1.0, 1.0, 1.0), normalize(vec3(-1.0, 1.0, 1.0)), viewProjectionMatrix * (gl_in[0].gl_Position + vec4(-w, h, w, 0.0))); // Front-top-right
|
||||
myEmitVertex(v_vertex[0] + vec3( w, -h, w), vec4(1.0, 1.0, 1.0, 1.0), normalize(vec3( 1.0, -1.0, 1.0)), viewProjectionMatrix * (gl_in[0].gl_Position + vec4( w, -h, w, 0.0))); // Front-bottom-left
|
||||
myEmitVertex(v_vertex[0] + vec3(-w, -h, w), vec4(1.0, 1.0, 1.0, 1.0), normalize(vec3(-1.0, -1.0, 1.0)), viewProjectionMatrix * (gl_in[0].gl_Position + vec4(-w, -h, w, 0.0))); // Front-bottom-right
|
||||
myEmitVertex(v_vertex[0] + vec3(-w, -h, -w), vec4(1.0, 1.0, 1.0, 1.0), normalize(vec3(-1.0, -1.0, -1.0)), viewProjectionMatrix * (gl_in[0].gl_Position + vec4(-w, -h, -w, 0.0))); // Back-bottom-right
|
||||
myEmitVertex(v_vertex[0] + vec3(-w, h, w), vec4(1.0, 1.0, 1.0, 1.0), normalize(vec3(-1.0, 1.0, 1.0)), viewProjectionMatrix * (gl_in[0].gl_Position + vec4(-w, h, w, 0.0))); // Front-top-right
|
||||
myEmitVertex(v_vertex[0] + vec3(-w, h, -w), vec4(1.0, 1.0, 1.0, 1.0), normalize(vec3(-1.0, 1.0, -1.0)), viewProjectionMatrix * (gl_in[0].gl_Position + vec4(-w, h, -w, 0.0))); // Back-top-right
|
||||
myEmitVertex(v_vertex[0] + vec3( w, h, w), vec4(1.0, 1.0, 1.0, 1.0), normalize(vec3( 1.0, 1.0, 1.0)), viewProjectionMatrix * (gl_in[0].gl_Position + vec4( w, h, w, 0.0))); // Front-top-left
|
||||
myEmitVertex(v_vertex[0] + vec3( w, h, -w), vec4(1.0, 1.0, 1.0, 1.0), normalize(vec3( 1.0, 1.0, -1.0)), viewProjectionMatrix * (gl_in[0].gl_Position + vec4( w, h, -w, 0.0))); // Back-top-left
|
||||
myEmitVertex(v_vertex[0] + vec3( w, -h, w), vec4(1.0, 1.0, 1.0, 1.0), normalize(vec3( 1.0, -1.0, 1.0)), viewProjectionMatrix * (gl_in[0].gl_Position + vec4( w, -h, w, 0.0))); // Front-bottom-left
|
||||
myEmitVertex(v_vertex[0] + vec3( w, -h, -w), vec4(1.0, 1.0, 1.0, 1.0), normalize(vec3( 1.0, -1.0, -1.0)), viewProjectionMatrix * (gl_in[0].gl_Position + vec4( w, -h, -w, 0.0))); // Back-bottom-left
|
||||
myEmitVertex(v_vertex[0] + vec3(-w, -h, -w), vec4(1.0, 1.0, 1.0, 1.0), normalize(vec3(-1.0, -1.0, -1.0)), viewProjectionMatrix * (gl_in[0].gl_Position + vec4(-w, -h, -w, 0.0))); // Back-bottom-right
|
||||
myEmitVertex(v_vertex[0] + vec3( w, h, -w), vec4(1.0, 1.0, 1.0, 1.0), normalize(vec3( 1.0, 1.0, -1.0)), viewProjectionMatrix * (gl_in[0].gl_Position + vec4( w, h, -w, 0.0))); // Back-top-left
|
||||
myEmitVertex(v_vertex[0] + vec3(-w, h, -w), vec4(1.0, 1.0, 1.0, 1.0), normalize(vec3(-1.0, 1.0, -1.0)), viewProjectionMatrix * (gl_in[0].gl_Position + vec4(-w, h, -w, 0.0))); // Back-top-right
|
||||
|
||||
EndPrimitive();
|
||||
}
|
||||
}
|
||||
|
||||
fragment41core =
|
||||
|
@ -316,6 +344,7 @@ u_show_travel_moves = 0
|
|||
u_show_helpers = 1
|
||||
u_show_skin = 1
|
||||
u_show_infill = 1
|
||||
u_show_starts = 1
|
||||
|
||||
u_min_feedrate = 0
|
||||
u_max_feedrate = 1
|
||||
|
@ -337,6 +366,7 @@ a_normal = normal
|
|||
a_line_dim = line_dim
|
||||
a_extruder = extruder
|
||||
a_material_color = material_color
|
||||
a_prev_line_type = prev_line_type
|
||||
a_line_type = line_type
|
||||
a_feedrate = feedrate
|
||||
a_thickness = thickness
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue