mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-20 13:17:51 -06:00
Shade layerview elements printed with non-active extruder(s)
CURA-2025
This commit is contained in:
parent
90dedc354c
commit
9300489796
3 changed files with 60 additions and 32 deletions
|
@ -37,8 +37,8 @@ class LayerPolygon:
|
||||||
|
|
||||||
# Buffering the colors shouldn't be necessary as it is not
|
# Buffering the colors shouldn't be necessary as it is not
|
||||||
# re-used and can save alot of memory usage.
|
# re-used and can save alot of memory usage.
|
||||||
self._colors = self.__color_map[self._types]
|
self._color_map = self.__color_map * [1, 1, 1, self._extruder] # The alpha component is used to store the extruder nr
|
||||||
self._color_map = self.__color_map
|
self._colors = self._color_map[self._types]
|
||||||
|
|
||||||
# When type is used as index returns true if type == LayerPolygon.InfillType or type == LayerPolygon.SkinType or type == LayerPolygon.SupportInfillType
|
# When type is used as index returns true if type == LayerPolygon.InfillType or type == LayerPolygon.SkinType or type == LayerPolygon.SupportInfillType
|
||||||
# Should be generated in better way, not hardcoded.
|
# Should be generated in better way, not hardcoded.
|
||||||
|
@ -172,31 +172,17 @@ class LayerPolygon:
|
||||||
|
|
||||||
return normals
|
return normals
|
||||||
|
|
||||||
__color_mapping = {
|
|
||||||
NoneType: Color(1.0, 1.0, 1.0, 1.0),
|
|
||||||
Inset0Type: Color(1.0, 0.0, 0.0, 1.0),
|
|
||||||
InsetXType: Color(0.0, 1.0, 0.0, 1.0),
|
|
||||||
SkinType: Color(1.0, 1.0, 0.0, 1.0),
|
|
||||||
SupportType: Color(0.0, 1.0, 1.0, 1.0),
|
|
||||||
SkirtType: Color(0.0, 1.0, 1.0, 1.0),
|
|
||||||
InfillType: Color(1.0, 0.75, 0.0, 1.0),
|
|
||||||
SupportInfillType: Color(0.0, 1.0, 1.0, 1.0),
|
|
||||||
MoveCombingType: Color(0.0, 0.0, 1.0, 1.0),
|
|
||||||
MoveRetractionType: Color(0.5, 0.5, 1.0, 1.0),
|
|
||||||
SupportInterfaceType: Color(0.25, 0.75, 1.0, 1.0),
|
|
||||||
}
|
|
||||||
|
|
||||||
# Should be generated in better way, not hardcoded.
|
# Should be generated in better way, not hardcoded.
|
||||||
__color_map = numpy.array([
|
__color_map = numpy.array([
|
||||||
[1.0, 1.0, 1.0, 1.0],
|
[1.0, 1.0, 1.0, 1.0], # NoneType
|
||||||
[1.0, 0.0, 0.0, 1.0],
|
[1.0, 0.0, 0.0, 1.0], # Inset0Type
|
||||||
[0.0, 1.0, 0.0, 1.0],
|
[0.0, 1.0, 0.0, 1.0], # InsetXType
|
||||||
[1.0, 1.0, 0.0, 1.0],
|
[1.0, 1.0, 0.0, 1.0], # SkinType
|
||||||
[0.0, 1.0, 1.0, 1.0],
|
[0.0, 1.0, 1.0, 1.0], # SupportType
|
||||||
[0.0, 1.0, 1.0, 1.0],
|
[0.0, 1.0, 1.0, 1.0], # SkirtType
|
||||||
[1.0, 0.75, 0.0, 1.0],
|
[1.0, 0.75, 0.0, 1.0], # InfillType
|
||||||
[0.0, 1.0, 1.0, 1.0],
|
[0.0, 1.0, 1.0, 1.0], # SupportInfillType
|
||||||
[0.0, 0.0, 1.0, 1.0],
|
[0.0, 0.0, 1.0, 1.0], # MoveCombingType
|
||||||
[0.5, 0.5, 1.0, 1.0],
|
[0.5, 0.5, 1.0, 1.0], # MoveRetractionType
|
||||||
[0.25, 0.75, 1.0, 1.0]
|
[0.25, 0.75, 1.0, 1.0] # SupportInterfaceType
|
||||||
])
|
])
|
|
@ -6,20 +6,26 @@ from UM.Resources import Resources
|
||||||
from UM.Scene.SceneNode import SceneNode
|
from UM.Scene.SceneNode import SceneNode
|
||||||
from UM.Scene.ToolHandle import ToolHandle
|
from UM.Scene.ToolHandle import ToolHandle
|
||||||
from UM.Application import Application
|
from UM.Application import Application
|
||||||
|
from UM.PluginRegistry import PluginRegistry
|
||||||
|
|
||||||
from UM.View.RenderPass import RenderPass
|
from UM.View.RenderPass import RenderPass
|
||||||
from UM.View.RenderBatch import RenderBatch
|
from UM.View.RenderBatch import RenderBatch
|
||||||
from UM.View.GL.OpenGL import OpenGL
|
from UM.View.GL.OpenGL import OpenGL
|
||||||
|
|
||||||
|
from cura.Settings.ExtruderManager import ExtruderManager
|
||||||
|
|
||||||
|
import os.path
|
||||||
|
|
||||||
## RenderPass used to display g-code paths.
|
## RenderPass used to display g-code paths.
|
||||||
class LayerPass(RenderPass):
|
class LayerPass(RenderPass):
|
||||||
def __init__(self, width, height):
|
def __init__(self, width, height):
|
||||||
super().__init__("layerview", width, height)
|
super().__init__("layerview", width, height)
|
||||||
|
|
||||||
self._shader = None
|
self._layer_shader = None
|
||||||
self._tool_handle_shader = None
|
self._tool_handle_shader = None
|
||||||
self._gl = OpenGL.getInstance().getBindingsObject()
|
self._gl = OpenGL.getInstance().getBindingsObject()
|
||||||
self._scene = Application.getInstance().getController().getScene()
|
self._scene = Application.getInstance().getController().getScene()
|
||||||
|
self._extruder_manager = ExtruderManager.getInstance()
|
||||||
|
|
||||||
self._layer_view = None
|
self._layer_view = None
|
||||||
|
|
||||||
|
@ -27,8 +33,9 @@ class LayerPass(RenderPass):
|
||||||
self._layerview = layerview
|
self._layerview = layerview
|
||||||
|
|
||||||
def render(self):
|
def render(self):
|
||||||
if not self._shader:
|
if not self._layer_shader:
|
||||||
self._shader = OpenGL.getInstance().createShaderProgram(Resources.getPath(Resources.Shaders, "default.shader"))
|
self._layer_shader = OpenGL.getInstance().createShaderProgram(os.path.join(PluginRegistry.getInstance().getPluginPath("LayerView"), "layers.shader"))
|
||||||
|
self._layer_shader.setUniformValue("u_active_extruder", float(self._extruder_manager.activeExtruderIndex))
|
||||||
if not self._tool_handle_shader:
|
if not self._tool_handle_shader:
|
||||||
self._tool_handle_shader = OpenGL.getInstance().createShaderProgram(Resources.getPath(Resources.Shaders, "toolhandle.shader"))
|
self._tool_handle_shader = OpenGL.getInstance().createShaderProgram(Resources.getPath(Resources.Shaders, "toolhandle.shader"))
|
||||||
|
|
||||||
|
@ -56,12 +63,12 @@ class LayerPass(RenderPass):
|
||||||
end += counts
|
end += counts
|
||||||
|
|
||||||
# This uses glDrawRangeElements internally to only draw a certain range of lines.
|
# This uses glDrawRangeElements internally to only draw a certain range of lines.
|
||||||
batch = RenderBatch(self._shader, type = RenderBatch.RenderType.Solid, mode = RenderBatch.RenderMode.Lines, range = (start, end))
|
batch = RenderBatch(self._layer_shader, type = RenderBatch.RenderType.Solid, mode = RenderBatch.RenderMode.Lines, range = (start, end))
|
||||||
batch.addItem(node.getWorldTransformation(), layer_data)
|
batch.addItem(node.getWorldTransformation(), layer_data)
|
||||||
batch.render(self._scene.getActiveCamera())
|
batch.render(self._scene.getActiveCamera())
|
||||||
|
|
||||||
# Create a new batch that is not range-limited
|
# Create a new batch that is not range-limited
|
||||||
batch = RenderBatch(self._shader, type = RenderBatch.RenderType.Solid)
|
batch = RenderBatch(self._layer_shader, type = RenderBatch.RenderType.Solid)
|
||||||
|
|
||||||
if self._layerview._current_layer_mesh:
|
if self._layerview._current_layer_mesh:
|
||||||
batch.addItem(node.getWorldTransformation(), self._layerview._current_layer_mesh)
|
batch.addItem(node.getWorldTransformation(), self._layerview._current_layer_mesh)
|
||||||
|
|
35
plugins/LayerView/layers.shader
Normal file
35
plugins/LayerView/layers.shader
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
[shaders]
|
||||||
|
vertex =
|
||||||
|
uniform highp mat4 u_modelViewProjectionMatrix;
|
||||||
|
uniform lowp float u_active_extruder;
|
||||||
|
uniform lowp float u_shade_factor;
|
||||||
|
|
||||||
|
attribute highp vec4 a_vertex;
|
||||||
|
attribute lowp vec4 a_color;
|
||||||
|
varying lowp vec4 v_color;
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
gl_Position = u_modelViewProjectionMatrix * a_vertex;
|
||||||
|
// shade the color depending on the extruder index stored in the alpha component of the color
|
||||||
|
v_color = (a_color.a == u_active_extruder) ? a_color : a_color * u_shade_factor;
|
||||||
|
v_color.a = 1.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
fragment =
|
||||||
|
varying lowp vec4 v_color;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
gl_FragColor = v_color;
|
||||||
|
}
|
||||||
|
|
||||||
|
[defaults]
|
||||||
|
u_active_extruder = 0.0
|
||||||
|
u_shade_factor = 0.75
|
||||||
|
|
||||||
|
[bindings]
|
||||||
|
u_modelViewProjectionMatrix = model_view_projection_matrix
|
||||||
|
|
||||||
|
[attributes]
|
||||||
|
a_vertex = vertex
|
||||||
|
a_color = color
|
Loading…
Add table
Add a link
Reference in a new issue