Finishing up compatibility mode

This commit is contained in:
Jack Ha 2017-01-02 14:56:31 +01:00
parent 93137fcc91
commit f0e0d65635
5 changed files with 91 additions and 15 deletions

View file

@ -49,7 +49,8 @@ class LayerDataBuilder(MeshBuilder):
self._layers[layer].setThickness(thickness) self._layers[layer].setThickness(thickness)
# material color map: [r, g, b, a] for each extruder row. # material color map: [r, g, b, a] for each extruder row.
def build(self, material_color_map): # line_type_brightness: compatibility layer view uses line type brightness of 0.5
def build(self, material_color_map, line_type_brightness = 1.0):
vertex_count = 0 vertex_count = 0
index_count = 0 index_count = 0
for layer, data in self._layers.items(): for layer, data in self._layers.items():
@ -70,6 +71,7 @@ class LayerDataBuilder(MeshBuilder):
self._element_counts[layer] = data.elementCount self._element_counts[layer] = data.elementCount
self.addVertices(vertices) self.addVertices(vertices)
colors[:, 0:3] *= line_type_brightness
self.addColors(colors) self.addColors(colors)
self.addIndices(indices.flatten()) self.addIndices(indices.flatten())

View file

@ -8,6 +8,7 @@ from UM.Scene.Iterator.DepthFirstIterator import DepthFirstIterator
from UM.Scene.SceneNode import SceneNode from UM.Scene.SceneNode import SceneNode
from UM.Application import Application from UM.Application import Application
from UM.Mesh.MeshData import MeshData from UM.Mesh.MeshData import MeshData
from UM.Preferences import Preferences
from UM.Message import Message from UM.Message import Message
from UM.i18n import i18nCatalog from UM.i18n import i18nCatalog
@ -105,7 +106,6 @@ class ProcessSlicedLayersJob(Job):
polygon = layer.getRepeatedMessage("path_segment", p) polygon = layer.getRepeatedMessage("path_segment", p)
extruder = polygon.extruder extruder = polygon.extruder
x = dir(polygon)
line_types = numpy.fromstring(polygon.line_type, dtype="u1") # Convert bytearray to numpy array line_types = numpy.fromstring(polygon.line_type, dtype="u1") # Convert bytearray to numpy array
line_types = line_types.reshape((-1,1)) line_types = line_types.reshape((-1,1))
@ -162,6 +162,7 @@ class ProcessSlicedLayersJob(Job):
# TODO: move to a better place. Code is similar to code in ExtrudersModel # TODO: move to a better place. Code is similar to code in ExtrudersModel
from cura.Settings.ExtruderManager import ExtruderManager from cura.Settings.ExtruderManager import ExtruderManager
import UM import UM
global_container_stack = UM.Application.getInstance().getGlobalContainerStack() global_container_stack = UM.Application.getInstance().getGlobalContainerStack()
manager = ExtruderManager.getInstance() manager = ExtruderManager.getInstance()
extruders = list(manager.getMachineExtruders(global_container_stack.getId())) extruders = list(manager.getMachineExtruders(global_container_stack.getId()))
@ -181,7 +182,11 @@ class ProcessSlicedLayersJob(Job):
color = colorCodeToRGBA(color_code) color = colorCodeToRGBA(color_code)
material_color_map[0, :] = color material_color_map[0, :] = color
layer_mesh = layer_data.build(material_color_map) if bool(Preferences.getInstance().getValue("view/compatibility_mode")):
line_type_brightness = 0.5
else:
line_type_brightness = 1.0
layer_mesh = layer_data.build(material_color_map, line_type_brightness)
if self._abort_requested: if self._abort_requested:
if self._progress: if self._progress:

View file

@ -146,7 +146,6 @@ Item
color: UM.Theme.getColor("tool_panel_background"); color: UM.Theme.getColor("tool_panel_background");
border.width: UM.Theme.getSize("default_lining").width border.width: UM.Theme.getSize("default_lining").width
border.color: UM.Theme.getColor("lining") border.color: UM.Theme.getColor("lining")
visible: !UM.LayerView.compatibilityMode
ListModel ListModel
{ {
@ -167,11 +166,20 @@ Item
anchors.top: slider_background.bottom anchors.top: slider_background.bottom
anchors.left: parent.left anchors.left: parent.left
model: layerViewTypes model: layerViewTypes
visible: !UM.LayerView.compatibilityMode
onActivated: { onActivated: {
UM.LayerView.setLayerViewType(layerViewTypes.get(index).type_id); UM.LayerView.setLayerViewType(layerViewTypes.get(index).type_id);
} }
} }
Label
{
anchors.top: slider_background.bottom
anchors.left: parent.left
text: catalog.i18nc("@label","Compatibility mode")
visible: UM.LayerView.compatibilityMode
}
ColumnLayout { ColumnLayout {
anchors.top: layer_type_combobox.bottom anchors.top: layer_type_combobox.bottom
anchors.topMargin: UM.Theme.getSize("default_margin").height anchors.topMargin: UM.Theme.getSize("default_margin").height
@ -182,6 +190,7 @@ Item
UM.LayerView.setExtruderOpacity(0, checked ? 1.0 : 0.0); UM.LayerView.setExtruderOpacity(0, checked ? 1.0 : 0.0);
} }
text: "Extruder 1" text: "Extruder 1"
visible: !UM.LayerView.compatibilityMode
} }
CheckBox { CheckBox {
checked: true checked: true
@ -189,6 +198,7 @@ Item
UM.LayerView.setExtruderOpacity(1, checked ? 1.0 : 0.0); UM.LayerView.setExtruderOpacity(1, checked ? 1.0 : 0.0);
} }
text: "Extruder 2" text: "Extruder 2"
visible: !UM.LayerView.compatibilityMode
} }
CheckBox { CheckBox {
onClicked: { onClicked: {

View file

@ -3,30 +3,88 @@ vertex =
uniform highp mat4 u_modelViewProjectionMatrix; uniform highp mat4 u_modelViewProjectionMatrix;
uniform lowp float u_active_extruder; uniform lowp float u_active_extruder;
uniform lowp float u_shade_factor; uniform lowp float u_shade_factor;
uniform highp int u_layer_view_type;
uniform highp int u_only_color_active_extruder;
attribute highp int a_extruder; attribute highp int a_extruder;
attribute highp int a_line_type;
attribute highp vec4 a_vertex; attribute highp vec4 a_vertex;
attribute lowp vec4 a_color; attribute lowp vec4 a_color;
attribute lowp vec4 a_material_color;
varying lowp vec4 v_color; varying lowp vec4 v_color;
varying float v_line_type;
void main() void main()
{ {
gl_Position = u_modelViewProjectionMatrix * a_vertex; 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;
v_color = (a_color.a == u_active_extruder) ? a_color * 1.5 : a_color * 1.5 * u_shade_factor; if ((u_only_color_active_extruder == 1) && (a_line_type != 8) && (a_line_type != 9)) {
v_color.a = 1.0; v_color = (a_extruder == u_active_extruder) ? v_color : vec4(0.4, 0.4, 0.4, v_color.a);
}
if ((u_only_color_active_extruder == 0) && (a_line_type != 8) && (a_line_type != 9)) {
v_color = (a_extruder == u_active_extruder) ? v_color : vec4(u_shade_factor * v_color.rgb, v_color.a);
}
v_line_type = a_line_type;
} }
fragment = fragment =
varying lowp vec4 v_color; varying lowp vec4 v_color;
varying float v_line_type;
uniform int u_show_travel_moves;
uniform int u_show_support;
uniform int u_show_adhesion;
uniform int u_show_skin;
uniform int u_show_infill;
void main() void main()
{ {
if ((u_show_travel_moves == 0) && (v_line_type >= 7.5) && (v_line_type <= 9.5)) { // actually, 8 and 9
// discard movements
discard;
}
// support: 4, 7, 10
if ((u_show_support == 0) && (
((v_line_type >= 3.5) && (v_line_type <= 4.5)) ||
((v_line_type >= 6.5) && (v_line_type <= 7.5)) ||
((v_line_type >= 9.5) && (v_line_type <= 10.5))
)) {
discard;
}
// skin: 1, 2, 3
if ((u_show_skin == 0) && (
(v_line_type >= 0.5) && (v_line_type <= 3.5)
)) {
discard;
}
// adhesion:
if ((u_show_adhesion == 0) && (v_line_type >= 4.5) && (v_line_type <= 5.5)) {
// discard movements
discard;
}
// infill:
if ((u_show_infill == 0) && (v_line_type >= 5.5) && (v_line_type <= 6.5)) {
// discard movements
discard;
}
gl_FragColor = v_color; gl_FragColor = v_color;
} }
[defaults] [defaults]
u_active_extruder = 0.0 u_active_extruder = 0.0
u_shade_factor = 0.60 u_shade_factor = 0.60
u_layer_view_type = 0
u_only_color_active_extruder = 1
u_extruder_opacity = [1.0, 1.0, 1.0, 1.0]
u_show_travel_moves = 0
u_show_support = 1
u_show_adhesion = 1
u_show_skin = 1
u_show_infill = 1
[bindings] [bindings]
u_modelViewProjectionMatrix = model_view_projection_matrix u_modelViewProjectionMatrix = model_view_projection_matrix
@ -35,3 +93,5 @@ u_modelViewProjectionMatrix = model_view_projection_matrix
a_vertex = vertex a_vertex = vertex
a_color = color a_color = color
a_extruder = extruder a_extruder = extruder
a_line_type = line_type
a_material_color = material_color

View file

@ -94,7 +94,6 @@ geometry =
out vec3 f_normal; out vec3 f_normal;
out vec3 f_vertex; out vec3 f_vertex;
out uint f_extruder; out uint f_extruder;
//out vec4 f_material_color;
void main() void main()
{ {
@ -325,7 +324,7 @@ fragment =
u_active_extruder = 0.0 u_active_extruder = 0.0
u_layer_view_type = 0 u_layer_view_type = 0
u_only_color_active_extruder = 1 u_only_color_active_extruder = 1
u_extruder_opacity = [1.0, 1.0] u_extruder_opacity = [1.0, 1.0, 1.0, 1.0]
u_specularColor = [0.4, 0.4, 0.4, 1.0] u_specularColor = [0.4, 0.4, 0.4, 1.0]
u_ambientColor = [0.3, 0.3, 0.3, 0.0] u_ambientColor = [0.3, 0.3, 0.3, 0.0]