From 61dcaf88116b7ec300fb4b00d0748cb206afff10 Mon Sep 17 00:00:00 2001 From: Jack Ha Date: Tue, 20 Dec 2016 11:45:05 +0100 Subject: [PATCH 01/54] wip --- cura/CuraApplication.py | 4 + .../ProcessSlicedLayersJob.py | 6 + plugins/LayerView/layers.shader | 114 +++++++++++++++++- resources/shaders/overhang.shader | 53 ++++++-- 4 files changed, 164 insertions(+), 13 deletions(-) diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index 2ab7837352..17342edd7c 100644 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -415,6 +415,8 @@ class CuraApplication(QtApplication): controller = self.getController() controller.setActiveView("SolidView") + # controller.setActiveView("LayerView") + controller.setCameraTool("CameraTool") controller.setSelectionTool("SelectionTool") @@ -455,6 +457,8 @@ class CuraApplication(QtApplication): self._qml_import_paths.append(Resources.getPath(self.ResourceTypes.QmlFiles)) self.initializeEngine() + # self.callLater(controller.setActiveView, "LayerView") + if self._engine.rootObjects: self.closeSplash() diff --git a/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py b/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py index c4e9554b2c..d4d2ccf15e 100644 --- a/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py +++ b/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py @@ -85,6 +85,7 @@ class ProcessSlicedLayersJob(Job): min_layer_number = layer.id current_layer = 0 + all_normals = [] for layer in self._layers: abs_layer_number = layer.id + abs(min_layer_number) @@ -126,6 +127,9 @@ class ProcessSlicedLayersJob(Job): this_poly = LayerPolygon.LayerPolygon(layer_data, extruder, line_types, new_points, line_widths) this_poly.buildCache() + + normals = this_poly.getNormals() + all_normals.append(normals) this_layer.polygons.append(this_poly) @@ -143,7 +147,9 @@ class ProcessSlicedLayersJob(Job): if self._progress: self._progress.setProgress(progress) + # layer_data.calculateNormals() # We are done processing all the layers we got from the engine, now create a mesh out of the data + layer_data._normals = numpy.concatenate(all_normals) layer_mesh = layer_data.build() if self._abort_requested: diff --git a/plugins/LayerView/layers.shader b/plugins/LayerView/layers.shader index 0e1f767e23..c48c56f1e7 100644 --- a/plugins/LayerView/layers.shader +++ b/plugins/LayerView/layers.shader @@ -1,35 +1,141 @@ [shaders] vertex = + uniform highp mat4 u_modelMatrix; + uniform highp mat4 u_viewProjectionMatrix; uniform highp mat4 u_modelViewProjectionMatrix; uniform lowp float u_active_extruder; uniform lowp float u_shade_factor; + uniform highp mat4 u_normalMatrix; attribute highp vec4 a_vertex; attribute lowp vec4 a_color; + attribute highp vec4 a_normal; + varying lowp vec4 v_color; + + varying highp vec3 v_vertex; + varying highp vec3 v_normal; + void main() { - gl_Position = u_modelViewProjectionMatrix * a_vertex; + vec4 world_space_vert = u_modelMatrix * a_vertex; + gl_Position = u_viewProjectionMatrix * world_space_vert; + // 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; + + v_vertex = world_space_vert.xyz; + v_normal = (u_normalMatrix * normalize(a_normal)).xyz; } -fragment = - varying lowp vec4 v_color; +geometry = + #version 410 + + layout(lines) in; + layout(triangle_strip, max_vertices = 6) out; + + in vec4 v_color[]; + in vec3 v_vertex[]; + in vec3 v_normal[]; + + out vec4 f_color; + out vec3 f_normal; + out vec3 f_vertex; void main() { - gl_FragColor = v_color; + int i; + vec4 delta; + vec3 g_normal; + vec3 g_offset; + + delta = vec4(gl_in[1].gl_Position.xy, 0.0, 0.0) - vec4(gl_in[0].gl_Position.xy, 0.0, 0.0); + g_normal = normalize(vec3(delta.y, -delta.x, delta.z)); + //g_offset = vec3(3.5, 3.5, 0.0); //5.0 * g_normal; // vec3(3.5, 3.5, 0.0); + g_offset = normalize(vec3(g_normal.x, g_normal.y, 0)); //5.0 * g_normal; // vec3(3.5, 3.5, 0.0); + f_vertex = v_vertex[0]; + + f_normal = v_normal[0]; + f_color = v_color[0]; + gl_Position = gl_in[0].gl_Position + g_offset; + EmitVertex(); + + f_normal = -v_normal[0]; + f_color = v_color[0]; + gl_Position = gl_in[0].gl_Position - g_offset; + EmitVertex(); + + f_normal = v_normal[0]; + f_color = v_color[1]; + gl_Position = gl_in[1].gl_Position + g_offset; + EmitVertex(); + + EndPrimitive(); + + + f_vertex = v_vertex[1]; + + f_normal = -v_normal[0]; + f_color = v_color[0]; + gl_Position = gl_in[0].gl_Position - g_offset; + EmitVertex(); + + f_normal = v_normal[0]; + f_color = v_color[1]; + gl_Position = gl_in[1].gl_Position + g_offset; + EmitVertex(); + + f_normal = -v_normal[0]; + f_color = v_color[1]; + gl_Position = gl_in[1].gl_Position - g_offset; + EmitVertex(); + + EndPrimitive(); + + } + +fragment = + varying lowp vec4 f_color; + varying lowp vec3 f_normal; + varying lowp vec3 f_vertex; + + uniform mediump vec4 u_diffuseColor; + //uniform highp vec3 u_lightPosition; + + void main() + { + mediump vec4 finalColor = vec4(0.0); + + finalColor += f_color; + + highp vec3 normal = normalize(f_normal); + highp vec3 lightDir = normalize(vec3(0.0, 100.0, -50.0) - f_vertex); + + // Diffuse Component + highp float NdotL = clamp(abs(dot(normal, lightDir)), 0.0, 1.0); + finalColor += (NdotL * u_diffuseColor); + + finalColor.a = 1.0; + gl_FragColor = finalColor; + + //gl_FragColor = f_color; + //gl_FragColor = vec4(f_normal, 1.0); } [defaults] u_active_extruder = 0.0 u_shade_factor = 0.60 +u_diffuseColor = [1.0, 0.79, 0.14, 1.0] +# u_lightPosition = light_0_position [bindings] u_modelViewProjectionMatrix = model_view_projection_matrix +u_modelMatrix = model_matrix +u_viewProjectionMatrix = view_projection_matrix +u_normalMatrix = normal_matrix [attributes] a_vertex = vertex a_color = color +a_normal = normal \ No newline at end of file diff --git a/resources/shaders/overhang.shader b/resources/shaders/overhang.shader index 99cbdf913d..0e8592f675 100644 --- a/resources/shaders/overhang.shader +++ b/resources/shaders/overhang.shader @@ -20,6 +20,40 @@ vertex = v_normal = (u_normalMatrix * normalize(a_normal)).xyz; } +geometry = + #version 410 + + layout(triangles) in; + layout(triangle_strip, max_vertices = 6) out; + + in vec3 v_normal[]; + in vec3 v_vertex[]; + + out vec3 f_normal; + out vec3 f_vertex; + + void main() + { + int i; + for(i = 0; i < 3; i++) + { + f_normal = v_normal[i]; + f_vertex = v_vertex[i]; + gl_Position = gl_in[i].gl_Position + vec4(-50, 0.0, 0.0, 0.0); + EmitVertex(); + } + EndPrimitive(); + + for(i = 0; i < 3; i++) + { + f_normal = v_normal[i]; + f_vertex = v_vertex[i]; + gl_Position = gl_in[i].gl_Position + vec4(50, 0.0, 0.0, 0.0); + EmitVertex(); + } + EndPrimitive(); + } + fragment = uniform mediump vec4 u_ambientColor; uniform mediump vec4 u_diffuseColor; @@ -31,27 +65,28 @@ fragment = uniform lowp float u_overhangAngle; uniform lowp vec4 u_overhangColor; - varying highp vec3 v_vertex; - varying highp vec3 v_normal; + varying highp vec3 f_vertex; + varying highp vec3 f_normal; void main() { + mediump vec4 finalColor = vec4(0.0); - /* Ambient Component */ + // Ambient Component finalColor += u_ambientColor; - highp vec3 normal = normalize(v_normal); - highp vec3 lightDir = normalize(u_lightPosition - v_vertex); + highp vec3 normal = normalize(f_normal); + highp vec3 lightDir = normalize(u_lightPosition - f_vertex); - /* Diffuse Component */ + // Diffuse Component highp float NdotL = clamp(abs(dot(normal, lightDir)), 0.0, 1.0); finalColor += (NdotL * u_diffuseColor); - /* Specular Component */ - /* TODO: We should not do specularity for fragments facing away from the light.*/ + // Specular Component + // TODO: We should not do specularity for fragments facing away from the light. highp vec3 reflectedLight = reflect(-lightDir, normal); - highp vec3 viewVector = normalize(u_viewPosition - v_vertex); + highp vec3 viewVector = normalize(u_viewPosition - f_vertex); highp float NdotR = clamp(dot(viewVector, reflectedLight), 0.0, 1.0); finalColor += pow(NdotR, u_shininess) * u_specularColor; From 57cec4ec59ae4558560db0ff970a2365dda10853 Mon Sep 17 00:00:00 2001 From: Jack Ha Date: Tue, 20 Dec 2016 14:00:34 +0100 Subject: [PATCH 02/54] wip --- plugins/LayerView/layers.shader | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/plugins/LayerView/layers.shader b/plugins/LayerView/layers.shader index c48c56f1e7..19f5c39e20 100644 --- a/plugins/LayerView/layers.shader +++ b/plugins/LayerView/layers.shader @@ -51,22 +51,31 @@ geometry = vec3 g_offset; delta = vec4(gl_in[1].gl_Position.xy, 0.0, 0.0) - vec4(gl_in[0].gl_Position.xy, 0.0, 0.0); - g_normal = normalize(vec3(delta.y, -delta.x, delta.z)); - //g_offset = vec3(3.5, 3.5, 0.0); //5.0 * g_normal; // vec3(3.5, 3.5, 0.0); - g_offset = normalize(vec3(g_normal.x, g_normal.y, 0)); //5.0 * g_normal; // vec3(3.5, 3.5, 0.0); - f_vertex = v_vertex[0]; + if (length(delta) > 0.1) { + g_normal = normalize(vec3(delta.y, -delta.x, delta.z)); + g_offset = vec3(g_normal.xy, 0); //5.0 * g_normal; // vec3(3.5, 3.5, 0.0); + } else { + g_normal = vec3(delta.y, -delta.x, delta.z); + g_offset = vec3(0.0, 0.0, 0.0); + } + //g_offset = vec3(3.5, 3.5, 0.0); //5.0 * g_normal; // vec3(3.5, 3.5, 0.0); + //g_normal = normalize(vec3(delta.y, -delta.x, delta.z)); + + f_vertex = v_vertex[0]; f_normal = v_normal[0]; f_color = v_color[0]; gl_Position = gl_in[0].gl_Position + g_offset; EmitVertex(); + f_vertex = v_vertex[0]; f_normal = -v_normal[0]; f_color = v_color[0]; gl_Position = gl_in[0].gl_Position - g_offset; EmitVertex(); - f_normal = v_normal[0]; + f_vertex = v_vertex[1]; + f_normal = v_normal[1]; f_color = v_color[1]; gl_Position = gl_in[1].gl_Position + g_offset; EmitVertex(); @@ -74,18 +83,19 @@ geometry = EndPrimitive(); - f_vertex = v_vertex[1]; - + f_vertex = v_vertex[0]; f_normal = -v_normal[0]; f_color = v_color[0]; gl_Position = gl_in[0].gl_Position - g_offset; EmitVertex(); + f_vertex = v_vertex[1]; f_normal = v_normal[0]; f_color = v_color[1]; gl_Position = gl_in[1].gl_Position + g_offset; EmitVertex(); + f_vertex = v_vertex[1]; f_normal = -v_normal[0]; f_color = v_color[1]; gl_Position = gl_in[1].gl_Position - g_offset; @@ -101,7 +111,7 @@ fragment = varying lowp vec3 f_vertex; uniform mediump vec4 u_diffuseColor; - //uniform highp vec3 u_lightPosition; + uniform highp vec3 u_lightPosition; void main() { @@ -110,10 +120,10 @@ fragment = finalColor += f_color; highp vec3 normal = normalize(f_normal); - highp vec3 lightDir = normalize(vec3(0.0, 100.0, -50.0) - f_vertex); + highp vec3 lightDir = normalize(u_lightPosition - f_vertex); // Diffuse Component - highp float NdotL = clamp(abs(dot(normal, lightDir)), 0.0, 1.0); + highp float NdotL = clamp(dot(normal, lightDir), 0.0, 1.0); finalColor += (NdotL * u_diffuseColor); finalColor.a = 1.0; @@ -127,13 +137,13 @@ fragment = u_active_extruder = 0.0 u_shade_factor = 0.60 u_diffuseColor = [1.0, 0.79, 0.14, 1.0] -# u_lightPosition = light_0_position [bindings] u_modelViewProjectionMatrix = model_view_projection_matrix u_modelMatrix = model_matrix u_viewProjectionMatrix = view_projection_matrix u_normalMatrix = normal_matrix +u_lightPosition = light_0_position [attributes] a_vertex = vertex From 3d9bccb7c788b4c20d4a676b8ddd75003ff93ed2 Mon Sep 17 00:00:00 2001 From: Jack Ha Date: Tue, 20 Dec 2016 16:32:34 +0100 Subject: [PATCH 03/54] big tryout --- .../ProcessSlicedLayersJob.py | 20 +++- plugins/LayerView/layers.shader | 91 +++++++++++++++---- 2 files changed, 90 insertions(+), 21 deletions(-) diff --git a/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py b/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py index d4d2ccf15e..64a55266e4 100644 --- a/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py +++ b/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py @@ -130,6 +130,8 @@ class ProcessSlicedLayersJob(Job): normals = this_poly.getNormals() all_normals.append(normals) + # insert last element twice - fake converting line normals to vertex normals + #all_normals.append(normals[-1:]) this_layer.polygons.append(this_poly) @@ -149,8 +151,24 @@ class ProcessSlicedLayersJob(Job): # layer_data.calculateNormals() # We are done processing all the layers we got from the engine, now create a mesh out of the data - layer_data._normals = numpy.concatenate(all_normals) + # layer_data._normals = numpy.concatenate(all_normals) layer_mesh = layer_data.build() + # normals = [] + # # quick and dirty normals calculation for 2d lines + # for line_idx in range(len(layer_mesh._indices) // 2 - 1): + # idx0 = layer_mesh._indices[line_idx] + # idx1 = layer_mesh._indices[line_idx + 1] + # x0 = layer_mesh._vertices[idx0][0] + # y0 = layer_mesh._vertices[idx0][2] + # x1 = layer_mesh._vertices[idx1][0] + # y1 = layer_mesh._vertices[idx1][2] + # dx = x1 - x0; + # dy = y1 - y0; + # normals.append([dy, 0, -dx]) + # normals.append([dy, 0, -dx]) + # layer_mesh._normals = numpy.array(normals) + #from UM.Mesh.MeshData import calculateNormalsFromIndexedVertices + #layer_mesh._normals = calculateNormalsFromIndexedVertices(layer_mesh._vertices, layer_mesh._indices, layer_mesh._face_count) if self._abort_requested: if self._progress: diff --git a/plugins/LayerView/layers.shader b/plugins/LayerView/layers.shader index 19f5c39e20..7bed3df795 100644 --- a/plugins/LayerView/layers.shader +++ b/plugins/LayerView/layers.shader @@ -16,6 +16,8 @@ vertex = varying highp vec3 v_vertex; varying highp vec3 v_normal; + varying highp vec3 v_orig_vertex; + void main() { vec4 world_space_vert = u_modelMatrix * a_vertex; @@ -27,6 +29,8 @@ vertex = v_vertex = world_space_vert.xyz; v_normal = (u_normalMatrix * normalize(a_normal)).xyz; + + v_orig_vertex = a_vertex.xyz; } geometry = @@ -38,6 +42,7 @@ geometry = in vec4 v_color[]; in vec3 v_vertex[]; in vec3 v_normal[]; + in vec3 v_orig_vertex[]; out vec4 f_color; out vec3 f_normal; @@ -50,6 +55,12 @@ geometry = vec3 g_normal; vec3 g_offset; + vec3 g_vertex_delta; + vec3 g_vertex_normal; + + float size = 3; + + /* delta = vec4(gl_in[1].gl_Position.xy, 0.0, 0.0) - vec4(gl_in[0].gl_Position.xy, 0.0, 0.0); if (length(delta) > 0.1) { @@ -59,49 +70,71 @@ geometry = g_normal = vec3(delta.y, -delta.x, delta.z); g_offset = vec3(0.0, 0.0, 0.0); } - //g_offset = vec3(3.5, 3.5, 0.0); //5.0 * g_normal; // vec3(3.5, 3.5, 0.0); + g_offset = vec3(3.5, 3.5, 0.0); //5.0 * g_normal; // vec3(3.5, 3.5, 0.0); + */ //g_normal = normalize(vec3(delta.y, -delta.x, delta.z)); - f_vertex = v_vertex[0]; - f_normal = v_normal[0]; - f_color = v_color[0]; - gl_Position = gl_in[0].gl_Position + g_offset; - EmitVertex(); + g_vertex_delta = v_orig_vertex[1] - v_orig_vertex[0]; + g_vertex_normal = vec3(g_vertex_delta.z, 0.0, -g_vertex_delta.x); + if (length(g_vertex_normal) < 0.1) { + g_vertex_normal = vec3(1.0, 0.0, 0.0); + } else { + g_vertex_normal = normalize(g_vertex_normal); + } f_vertex = v_vertex[0]; - f_normal = -v_normal[0]; f_color = v_color[0]; - gl_Position = gl_in[0].gl_Position - g_offset; + + f_normal = g_vertex_normal; + gl_Position = gl_in[0].gl_Position + vec4(0.0, size, 0.0, 0.0); EmitVertex(); - f_vertex = v_vertex[1]; - f_normal = v_normal[1]; - f_color = v_color[1]; - gl_Position = gl_in[1].gl_Position + g_offset; + f_normal = g_vertex_normal; + gl_Position = gl_in[1].gl_Position + vec4(0.0, size, 0.0, 0.0); + EmitVertex(); + + f_normal = vec3(0.0); + gl_Position = gl_in[0].gl_Position + vec4(-size, 0.0, 0.0, 0.0); + EmitVertex(); + + //f_vertex = v_vertex[1]; + //f_color = v_color[1]; + + + f_normal = vec3(0.0); + gl_Position = gl_in[1].gl_Position + vec4(size, 0.0, 0.0, 0.0); + EmitVertex(); + + f_normal = -g_vertex_normal; + gl_Position = gl_in[0].gl_Position + vec4(0, -size, 0.0, 0.0); + EmitVertex(); + + f_normal = -g_vertex_normal; + gl_Position = gl_in[1].gl_Position + vec4(0.0, -size, 0.0, 0.0); EmitVertex(); EndPrimitive(); - + /* f_vertex = v_vertex[0]; - f_normal = -v_normal[0]; + f_normal = -g_vertex_normal; f_color = v_color[0]; gl_Position = gl_in[0].gl_Position - g_offset; EmitVertex(); f_vertex = v_vertex[1]; - f_normal = v_normal[0]; + f_normal = g_vertex_normal; f_color = v_color[1]; gl_Position = gl_in[1].gl_Position + g_offset; EmitVertex(); f_vertex = v_vertex[1]; - f_normal = -v_normal[0]; + f_normal = -g_vertex_normal; f_color = v_color[1]; gl_Position = gl_in[1].gl_Position - g_offset; EmitVertex(); + */ - EndPrimitive(); } @@ -110,21 +143,38 @@ fragment = varying lowp vec3 f_normal; varying lowp vec3 f_vertex; + uniform mediump vec4 u_ambientColor; uniform mediump vec4 u_diffuseColor; uniform highp vec3 u_lightPosition; + void Impostor(in float sphereRadius, in vec3 cameraSpherePos, in vec2 mapping, out vec3 cameraPos, out vec3 cameraNormal) + { + float lensqr = dot(mapping, mapping); + if(lensqr > 1.0) + discard; + + cameraNormal = vec3(mapping, sqrt(1.0 - lensqr)); + cameraPos = (cameraNormal * sphereRadius) + cameraSpherePos; + } + void main() { + vec3 cameraPos; + vec3 cameraNormal; + + Impostor(0.2, vec3(0.0, 0.0, 0.0), vec2(0.1, 0.0), cameraPos, cameraNormal); + mediump vec4 finalColor = vec4(0.0); - finalColor += f_color; + finalColor += u_ambientColor; - highp vec3 normal = normalize(f_normal); + //highp vec3 normal = normalize(f_normal); + highp vec3 normal = normalize(cameraNormal); highp vec3 lightDir = normalize(u_lightPosition - f_vertex); // Diffuse Component highp float NdotL = clamp(dot(normal, lightDir), 0.0, 1.0); - finalColor += (NdotL * u_diffuseColor); + finalColor += (NdotL * f_color); finalColor.a = 1.0; gl_FragColor = finalColor; @@ -136,6 +186,7 @@ fragment = [defaults] u_active_extruder = 0.0 u_shade_factor = 0.60 +u_ambientColor = [0.3, 0.3, 0.3, 0.3] u_diffuseColor = [1.0, 0.79, 0.14, 1.0] [bindings] From 9e6c070ac64cd55981c998d48a9f75106e76580f Mon Sep 17 00:00:00 2001 From: Jack Ha Date: Wed, 21 Dec 2016 09:21:05 +0100 Subject: [PATCH 04/54] tryout --- plugins/LayerView/layers.shader | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/plugins/LayerView/layers.shader b/plugins/LayerView/layers.shader index 7bed3df795..24346e5c65 100644 --- a/plugins/LayerView/layers.shader +++ b/plugins/LayerView/layers.shader @@ -85,15 +85,15 @@ geometry = f_vertex = v_vertex[0]; f_color = v_color[0]; - f_normal = g_vertex_normal; + f_normal = g_vertex_normal + vec3(0.0, 0.0, 0.5); gl_Position = gl_in[0].gl_Position + vec4(0.0, size, 0.0, 0.0); EmitVertex(); - f_normal = g_vertex_normal; + f_normal = g_vertex_normal + vec3(0.0, 0.0, 0.5); gl_Position = gl_in[1].gl_Position + vec4(0.0, size, 0.0, 0.0); EmitVertex(); - f_normal = vec3(0.0); + f_normal = vec3(0.0, 0.0, 0.5); gl_Position = gl_in[0].gl_Position + vec4(-size, 0.0, 0.0, 0.0); EmitVertex(); @@ -101,15 +101,15 @@ geometry = //f_color = v_color[1]; - f_normal = vec3(0.0); + f_normal = vec3(0.0, 0.0, 0.5); gl_Position = gl_in[1].gl_Position + vec4(size, 0.0, 0.0, 0.0); EmitVertex(); - f_normal = -g_vertex_normal; + f_normal = -g_vertex_normal + vec3(0.0, 0.0, 0.5); gl_Position = gl_in[0].gl_Position + vec4(0, -size, 0.0, 0.0); EmitVertex(); - f_normal = -g_vertex_normal; + f_normal = -g_vertex_normal + vec3(0.0, 0.0, 0.5); gl_Position = gl_in[1].gl_Position + vec4(0.0, -size, 0.0, 0.0); EmitVertex(); @@ -162,14 +162,14 @@ fragment = vec3 cameraPos; vec3 cameraNormal; - Impostor(0.2, vec3(0.0, 0.0, 0.0), vec2(0.1, 0.0), cameraPos, cameraNormal); + //Impostor(0.2, vec3(0.0, 0.0, 0.0), vec2(0.1, 0.1), cameraPos, cameraNormal); mediump vec4 finalColor = vec4(0.0); finalColor += u_ambientColor; - //highp vec3 normal = normalize(f_normal); - highp vec3 normal = normalize(cameraNormal); + highp vec3 normal = normalize(f_normal); + //highp vec3 normal = normalize(cameraNormal); highp vec3 lightDir = normalize(u_lightPosition - f_vertex); // Diffuse Component From 0adb1a4c1c16ca6550a8450b1c516e79f5f7b53c Mon Sep 17 00:00:00 2001 From: Jack Ha Date: Wed, 21 Dec 2016 14:37:02 +0100 Subject: [PATCH 05/54] Finally got normals in --- cura/Layer.py | 4 +- cura/LayerDataBuilder.py | 4 +- .../ProcessSlicedLayersJob.py | 7 +- plugins/LayerView/LayerView.py | 6 +- plugins/LayerView/layers.shader | 206 ++++++++++++------ 5 files changed, 155 insertions(+), 72 deletions(-) diff --git a/cura/Layer.py b/cura/Layer.py index 4e38a6eba9..bc9f66e881 100644 --- a/cura/Layer.py +++ b/cura/Layer.py @@ -49,12 +49,14 @@ class Layer: return result - def build(self, vertex_offset, index_offset, vertices, colors, indices): + def build(self, vertex_offset, index_offset, vertices, colors, indices, normals): result_vertex_offset = vertex_offset result_index_offset = index_offset self._element_count = 0 for polygon in self._polygons: polygon.build(result_vertex_offset, result_index_offset, vertices, colors, indices) + polygon_normals = polygon.getNormals() # [numpy.where(numpy.logical_not(polygon.jumpMask))] + normals[result_vertex_offset:result_vertex_offset+polygon.lineMeshVertexCount()] = polygon_normals[:polygon.lineMeshVertexCount()] result_vertex_offset += polygon.lineMeshVertexCount() result_index_offset += polygon.lineMeshElementCount() self._element_count += polygon.elementCount diff --git a/cura/LayerDataBuilder.py b/cura/LayerDataBuilder.py index 2215ed5f27..f2ad6b55fa 100644 --- a/cura/LayerDataBuilder.py +++ b/cura/LayerDataBuilder.py @@ -56,18 +56,20 @@ class LayerDataBuilder(MeshBuilder): index_count += data.lineMeshElementCount() vertices = numpy.empty((vertex_count, 3), numpy.float32) + normals = numpy.empty((vertex_count, 3), numpy.float32) colors = numpy.empty((vertex_count, 4), numpy.float32) indices = numpy.empty((index_count, 2), numpy.int32) vertex_offset = 0 index_offset = 0 for layer, data in self._layers.items(): - ( vertex_offset, index_offset ) = data.build( vertex_offset, index_offset, vertices, colors, indices) + ( vertex_offset, index_offset ) = data.build( vertex_offset, index_offset, vertices, colors, indices, normals) self._element_counts[layer] = data.elementCount self.addVertices(vertices) self.addColors(colors) self.addIndices(indices.flatten()) + self._normals = normals return LayerData(vertices=self.getVertices(), normals=self.getNormals(), indices=self.getIndices(), colors=self.getColors(), uvs=self.getUVCoordinates(), file_name=self.getFileName(), diff --git a/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py b/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py index 64a55266e4..d7863f07cb 100644 --- a/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py +++ b/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py @@ -129,9 +129,10 @@ class ProcessSlicedLayersJob(Job): this_poly.buildCache() normals = this_poly.getNormals() - all_normals.append(normals) + # normals = this_poly.getNormals()[numpy.where(numpy.logical_not(this_poly.jumpMask))] + # all_normals.append(normals) # insert last element twice - fake converting line normals to vertex normals - #all_normals.append(normals[-1:]) + # all_normals.append(normals[-1:]) this_layer.polygons.append(this_poly) @@ -155,7 +156,7 @@ class ProcessSlicedLayersJob(Job): layer_mesh = layer_data.build() # normals = [] # # quick and dirty normals calculation for 2d lines - # for line_idx in range(len(layer_mesh._indices) // 2 - 1): + # for line_idx in range(len(layer_mesh._indices) // 2): # idx0 = layer_mesh._indices[line_idx] # idx1 = layer_mesh._indices[line_idx + 1] # x0 = layer_mesh._vertices[idx0][0] diff --git a/plugins/LayerView/LayerView.py b/plugins/LayerView/LayerView.py index 50c13194f7..cf2fbbc1d3 100644 --- a/plugins/LayerView/LayerView.py +++ b/plugins/LayerView/LayerView.py @@ -236,9 +236,9 @@ class LayerView(View): self.setBusy(True) - self._top_layers_job = _CreateTopLayersJob(self._controller.getScene(), self._current_layer_num, self._solid_layers) - self._top_layers_job.finished.connect(self._updateCurrentLayerMesh) - self._top_layers_job.start() + #self._top_layers_job = _CreateTopLayersJob(self._controller.getScene(), self._current_layer_num, self._solid_layers) + #self._top_layers_job.finished.connect(self._updateCurrentLayerMesh) + #self._top_layers_job.start() def _updateCurrentLayerMesh(self, job): self.setBusy(False) diff --git a/plugins/LayerView/layers.shader b/plugins/LayerView/layers.shader index 24346e5c65..88eb54cc36 100644 --- a/plugins/LayerView/layers.shader +++ b/plugins/LayerView/layers.shader @@ -1,8 +1,8 @@ [shaders] vertex = uniform highp mat4 u_modelMatrix; - uniform highp mat4 u_viewProjectionMatrix; - uniform highp mat4 u_modelViewProjectionMatrix; + //uniform highp mat4 u_viewProjectionMatrix; + //uniform highp mat4 u_modelViewProjectionMatrix; uniform lowp float u_active_extruder; uniform lowp float u_shade_factor; uniform highp mat4 u_normalMatrix; @@ -16,12 +16,17 @@ vertex = varying highp vec3 v_vertex; varying highp vec3 v_normal; - varying highp vec3 v_orig_vertex; + varying highp vec4 v_orig_vertex; + + varying lowp vec4 f_color; + varying highp vec3 f_vertex; + varying highp vec3 f_normal; void main() { vec4 world_space_vert = u_modelMatrix * a_vertex; - gl_Position = u_viewProjectionMatrix * world_space_vert; + // gl_Position = u_viewProjectionMatrix * world_space_vert; + gl_Position = world_space_vert; // 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; @@ -30,14 +35,26 @@ vertex = v_vertex = world_space_vert.xyz; v_normal = (u_normalMatrix * normalize(a_normal)).xyz; - v_orig_vertex = a_vertex.xyz; + v_orig_vertex = a_vertex; + + // for testing without geometry shader + f_color = v_color; + f_vertex = v_vertex; + f_normal = v_normal; } geometry = #version 410 + //uniform highp mat4 u_modelMatrix; + uniform highp mat4 u_viewProjectionMatrix; + //uniform highp mat4 u_modelViewProjectionMatrix; + layout(lines) in; - layout(triangle_strip, max_vertices = 6) out; + layout(triangle_strip, max_vertices = 4) out; + /*layout(std140) uniform Matrices { + mat4 u_modelViewProjectionMatrix; + };*/ in vec4 v_color[]; in vec3 v_vertex[]; @@ -48,6 +65,73 @@ geometry = out vec3 f_normal; out vec3 f_vertex; + void main() + { + //int i; + //vec3 g_normal; + //vec3 g_offset; + + //vec4 g_vertex_delta; + vec3 g_vertex_normal_horz; // horizontal and vertical in respect to layers + vec3 g_vertex_normal_vert; + vec3 g_vertex_offset_horz; + vec3 g_vertex_offset_vert; + + float size = 0.5; + + //g_vertex_delta = gl_in[1].gl_Position - gl_in[0].gl_Position; + g_vertex_normal_horz = normalize(v_normal[0]); //vec3(g_vertex_delta.z, g_vertex_delta.y, -g_vertex_delta.x); + g_vertex_offset_horz = vec3(0.5, 0.0, 0.0); //size * g_vertex_normal_horz; //size * g_vertex_normal_horz; + g_vertex_normal_vert = vec3(0.0, 1.0, 0.0); + g_vertex_offset_vert = vec3(0.0, 0.5, 0.0); //size * g_vertex_normal_vert; + + f_vertex = v_vertex[0]; + f_normal = g_vertex_normal_horz; + f_color = vec4(g_vertex_normal_horz, 1.0); //v_color[0]; + gl_Position = u_viewProjectionMatrix * (gl_in[0].gl_Position + g_vertex_offset_horz); + EmitVertex(); + + f_vertex = v_vertex[1]; + //f_color = v_color[1]; + f_normal = g_vertex_normal_horz; + gl_Position = u_viewProjectionMatrix * (gl_in[1].gl_Position + g_vertex_offset_horz); + EmitVertex(); + + f_vertex = v_vertex[0]; + //f_color = v_color[0]; + f_normal = g_vertex_normal_vert; + gl_Position = u_viewProjectionMatrix * (gl_in[0].gl_Position + g_vertex_offset_vert); + EmitVertex(); + + f_vertex = v_vertex[1]; + //f_color = v_color[1]; + f_normal = g_vertex_normal_vert; + gl_Position = u_viewProjectionMatrix * (gl_in[1].gl_Position + g_vertex_offset_vert); + EmitVertex(); + + EndPrimitive(); + } + + +poep = + #version 410 + + uniform highp mat4 u_modelMatrix; + uniform highp mat4 u_viewProjectionMatrix; + uniform highp mat4 u_modelViewProjectionMatrix; + + layout(lines) in; + layout(triangle_strip, max_vertices = 3) out; + + in vec4 v_color[]; + in vec3 v_vertex[]; + in vec3 v_normal[]; + in vec4 v_orig_vertex[]; + + out vec4 f_color; + out vec3 f_normal; + out vec3 f_vertex; + void main() { int i; @@ -55,85 +139,78 @@ geometry = vec3 g_normal; vec3 g_offset; - vec3 g_vertex_delta; - vec3 g_vertex_normal; + vec4 g_vertex_delta; + vec4 g_vertex_normal_horz; // horizontal and vertical in respect to layers + vec3 g_vertex_normal_vert; + vec3 g_vertex_offset_horz; + vec3 g_vertex_offset_vert; float size = 3; - /* - delta = vec4(gl_in[1].gl_Position.xy, 0.0, 0.0) - vec4(gl_in[0].gl_Position.xy, 0.0, 0.0); - - if (length(delta) > 0.1) { - g_normal = normalize(vec3(delta.y, -delta.x, delta.z)); - g_offset = vec3(g_normal.xy, 0); //5.0 * g_normal; // vec3(3.5, 3.5, 0.0); - } else { - g_normal = vec3(delta.y, -delta.x, delta.z); - g_offset = vec3(0.0, 0.0, 0.0); - } - g_offset = vec3(3.5, 3.5, 0.0); //5.0 * g_normal; // vec3(3.5, 3.5, 0.0); - */ - //g_normal = normalize(vec3(delta.y, -delta.x, delta.z)); - g_vertex_delta = v_orig_vertex[1] - v_orig_vertex[0]; - g_vertex_normal = vec3(g_vertex_delta.z, 0.0, -g_vertex_delta.x); - if (length(g_vertex_normal) < 0.1) { - g_vertex_normal = vec3(1.0, 0.0, 0.0); + g_vertex_normal_horz = vec4(g_vertex_delta.z, 0.0, -g_vertex_delta.x, g_vertex_delta.w); + if (length(g_vertex_normal_horz) < 0.1) { + g_vertex_normal_horz = vec4(1.0, 0.0, 0.0, 0.0); + g_vertex_offset_horz = vec3(0.0, 0.0, 0.0); + g_vertex_offset_vert = vec3(0.0, 0.0, 0.0); } else { - g_vertex_normal = normalize(g_vertex_normal); + g_vertex_normal_horz = normalize(g_vertex_normal_horz); + g_vertex_offset_horz = (u_viewProjectionMatrix * u_modelMatrix * size * g_vertex_normal_horz).xyz; + g_vertex_normal_vert = vec3(0.0, 0.0, 1.0); + g_vertex_offset_vert = (u_viewProjectionMatrix * u_modelMatrix * size * g_vertex_normal_vert).xyz; } f_vertex = v_vertex[0]; f_color = v_color[0]; - - f_normal = g_vertex_normal + vec3(0.0, 0.0, 0.5); - gl_Position = gl_in[0].gl_Position + vec4(0.0, size, 0.0, 0.0); + f_normal = g_vertex_normal_horz; + gl_Position = gl_in[0].gl_Position + g_vertex_offset_horz; EmitVertex(); - f_normal = g_vertex_normal + vec3(0.0, 0.0, 0.5); - gl_Position = gl_in[1].gl_Position + vec4(0.0, size, 0.0, 0.0); + f_vertex = v_vertex[1]; + f_color = v_color[1]; + f_normal = g_vertex_normal_horz; + gl_Position = gl_in[1].gl_Position + g_vertex_offset_horz; EmitVertex(); - f_normal = vec3(0.0, 0.0, 0.5); - gl_Position = gl_in[0].gl_Position + vec4(-size, 0.0, 0.0, 0.0); + f_vertex = v_vertex[0]; + f_color = v_color[0]; + f_normal = g_vertex_offset_vert; + gl_Position = gl_in[0].gl_Position + g_vertex_offset_vert; EmitVertex(); - //f_vertex = v_vertex[1]; - //f_color = v_color[1]; - - - f_normal = vec3(0.0, 0.0, 0.5); - gl_Position = gl_in[1].gl_Position + vec4(size, 0.0, 0.0, 0.0); + f_vertex = v_vertex[1]; + f_color = v_color[1]; + f_normal = g_vertex_offset_vert; + gl_Position = gl_in[1].gl_Position + g_vertex_offset_vert; EmitVertex(); - f_normal = -g_vertex_normal + vec3(0.0, 0.0, 0.5); - gl_Position = gl_in[0].gl_Position + vec4(0, -size, 0.0, 0.0); + f_vertex = v_vertex[0]; + f_color = v_color[0]; + f_normal = -g_vertex_normal_horz; + gl_Position = gl_in[0].gl_Position - g_vertex_offset_horz; EmitVertex(); - f_normal = -g_vertex_normal + vec3(0.0, 0.0, 0.5); - gl_Position = gl_in[1].gl_Position + vec4(0.0, -size, 0.0, 0.0); + f_vertex = v_vertex[1]; + f_color = v_color[1]; + f_normal = -g_vertex_normal_horz; + gl_Position = gl_in[1].gl_Position - g_vertex_offset_horz; EmitVertex(); + f_vertex = v_vertex[0]; + f_color = v_color[0]; + f_normal = -g_vertex_offset_vert; + gl_Position = gl_in[0].gl_Position - g_vertex_offset_vert; + EmitVertex(); + + f_vertex = v_vertex[1]; + f_color = v_color[1]; + f_normal = -g_vertex_offset_vert; + gl_Position = gl_in[1].gl_Position - g_vertex_offset_vert; + EmitVertex(); + + EndPrimitive(); - /* - f_vertex = v_vertex[0]; - f_normal = -g_vertex_normal; - f_color = v_color[0]; - gl_Position = gl_in[0].gl_Position - g_offset; - EmitVertex(); - - f_vertex = v_vertex[1]; - f_normal = g_vertex_normal; - f_color = v_color[1]; - gl_Position = gl_in[1].gl_Position + g_offset; - EmitVertex(); - - f_vertex = v_vertex[1]; - f_normal = -g_vertex_normal; - f_color = v_color[1]; - gl_Position = gl_in[1].gl_Position - g_offset; - EmitVertex(); - */ } @@ -166,7 +243,8 @@ fragment = mediump vec4 finalColor = vec4(0.0); - finalColor += u_ambientColor; + //finalColor += u_ambientColor; + finalColor = f_color; highp vec3 normal = normalize(f_normal); //highp vec3 normal = normalize(cameraNormal); @@ -174,7 +252,7 @@ fragment = // Diffuse Component highp float NdotL = clamp(dot(normal, lightDir), 0.0, 1.0); - finalColor += (NdotL * f_color); + //finalColor += (NdotL * f_color); finalColor.a = 1.0; gl_FragColor = finalColor; From 47e204038fbef3041eac9f325cc00dbca8ab49dd Mon Sep 17 00:00:00 2001 From: Jack Ha Date: Wed, 21 Dec 2016 15:44:01 +0100 Subject: [PATCH 06/54] Got cylinders --- plugins/LayerView/layers.shader | 66 ++++++++++++++++++++++++++------- 1 file changed, 52 insertions(+), 14 deletions(-) diff --git a/plugins/LayerView/layers.shader b/plugins/LayerView/layers.shader index 88eb54cc36..270d2daa50 100644 --- a/plugins/LayerView/layers.shader +++ b/plugins/LayerView/layers.shader @@ -51,7 +51,7 @@ geometry = //uniform highp mat4 u_modelViewProjectionMatrix; layout(lines) in; - layout(triangle_strip, max_vertices = 4) out; + layout(triangle_strip, max_vertices = 8) out; /*layout(std140) uniform Matrices { mat4 u_modelViewProjectionMatrix; };*/ @@ -73,42 +73,67 @@ geometry = //vec4 g_vertex_delta; vec3 g_vertex_normal_horz; // horizontal and vertical in respect to layers + vec4 g_vertex_offset_horz; // vec4 to match gl_in[x].gl_Position vec3 g_vertex_normal_vert; - vec3 g_vertex_offset_horz; - vec3 g_vertex_offset_vert; + vec4 g_vertex_offset_vert; - float size = 0.5; + const float size = 0.5; //g_vertex_delta = gl_in[1].gl_Position - gl_in[0].gl_Position; g_vertex_normal_horz = normalize(v_normal[0]); //vec3(g_vertex_delta.z, g_vertex_delta.y, -g_vertex_delta.x); - g_vertex_offset_horz = vec3(0.5, 0.0, 0.0); //size * g_vertex_normal_horz; //size * g_vertex_normal_horz; + g_vertex_offset_horz = vec4(g_vertex_normal_horz * size, 0.0); //size * g_vertex_normal_horz; g_vertex_normal_vert = vec3(0.0, 1.0, 0.0); - g_vertex_offset_vert = vec3(0.0, 0.5, 0.0); //size * g_vertex_normal_vert; + //g_vertex_offset_vert = vec3(g_vertex_normal_vert.x * 0.5f, g_vertex_normal_vert.y * 0.5f, g_vertex_normal_vert.z * 0.5f); //size * g_vertex_normal_vert; + g_vertex_offset_vert = vec4(g_vertex_normal_vert * size, 0.0); f_vertex = v_vertex[0]; f_normal = g_vertex_normal_horz; - f_color = vec4(g_vertex_normal_horz, 1.0); //v_color[0]; + f_color = v_color[0]; gl_Position = u_viewProjectionMatrix * (gl_in[0].gl_Position + g_vertex_offset_horz); EmitVertex(); f_vertex = v_vertex[1]; - //f_color = v_color[1]; + f_color = v_color[1]; f_normal = g_vertex_normal_horz; gl_Position = u_viewProjectionMatrix * (gl_in[1].gl_Position + g_vertex_offset_horz); EmitVertex(); f_vertex = v_vertex[0]; - //f_color = v_color[0]; + f_color = v_color[0]; f_normal = g_vertex_normal_vert; gl_Position = u_viewProjectionMatrix * (gl_in[0].gl_Position + g_vertex_offset_vert); EmitVertex(); f_vertex = v_vertex[1]; - //f_color = v_color[1]; + f_color = v_color[1]; f_normal = g_vertex_normal_vert; gl_Position = u_viewProjectionMatrix * (gl_in[1].gl_Position + g_vertex_offset_vert); EmitVertex(); + f_vertex = v_vertex[0]; + f_normal = -g_vertex_normal_horz; + f_color = v_color[0]; + gl_Position = u_viewProjectionMatrix * (gl_in[0].gl_Position - g_vertex_offset_horz); + EmitVertex(); + + f_vertex = v_vertex[1]; + f_color = v_color[1]; + f_normal = -g_vertex_normal_horz; + gl_Position = u_viewProjectionMatrix * (gl_in[1].gl_Position - g_vertex_offset_horz); + EmitVertex(); + + f_vertex = v_vertex[0]; + f_color = v_color[0]; + f_normal = -g_vertex_normal_vert; + gl_Position = u_viewProjectionMatrix * (gl_in[0].gl_Position - g_vertex_offset_vert); + EmitVertex(); + + f_vertex = v_vertex[1]; + f_color = v_color[1]; + f_normal = -g_vertex_normal_vert; + gl_Position = u_viewProjectionMatrix * (gl_in[1].gl_Position - g_vertex_offset_vert); + EmitVertex(); + EndPrimitive(); } @@ -222,6 +247,9 @@ fragment = uniform mediump vec4 u_ambientColor; uniform mediump vec4 u_diffuseColor; + //uniform mediump vec4 u_specularColor; + //uniform mediump float u_shininess; + uniform highp vec3 u_lightPosition; void Impostor(in float sphereRadius, in vec3 cameraSpherePos, in vec2 mapping, out vec3 cameraPos, out vec3 cameraNormal) @@ -241,18 +269,26 @@ fragment = //Impostor(0.2, vec3(0.0, 0.0, 0.0), vec2(0.1, 0.1), cameraPos, cameraNormal); + //gl_FrontFacing = .. + mediump vec4 finalColor = vec4(0.0); - //finalColor += u_ambientColor; - finalColor = f_color; + finalColor += u_ambientColor; + //finalColor = f_color; highp vec3 normal = normalize(f_normal); - //highp vec3 normal = normalize(cameraNormal); highp vec3 lightDir = normalize(u_lightPosition - f_vertex); // Diffuse Component highp float NdotL = clamp(dot(normal, lightDir), 0.0, 1.0); - //finalColor += (NdotL * f_color); + finalColor += (NdotL * f_color); + + // Specular Component + // TODO: We should not do specularity for fragments facing away from the light. + /*highp vec3 reflectedLight = reflect(-lightDir, normal); + highp vec3 viewVector = normalize(u_viewPosition - f_vertex); + highp float NdotR = clamp(dot(viewVector, reflectedLight), 0.0, 1.0); + finalColor += pow(NdotR, u_shininess) * u_specularColor;*/ finalColor.a = 1.0; gl_FragColor = finalColor; @@ -264,8 +300,10 @@ fragment = [defaults] u_active_extruder = 0.0 u_shade_factor = 0.60 +u_specularColor = [0.4, 0.4, 0.4, 1.0] u_ambientColor = [0.3, 0.3, 0.3, 0.3] u_diffuseColor = [1.0, 0.79, 0.14, 1.0] +u_shininess = 20.0 [bindings] u_modelViewProjectionMatrix = model_view_projection_matrix From c6d56b60f69c7021b9f4aebfb4a0e97ce931ca33 Mon Sep 17 00:00:00 2001 From: Jack Ha Date: Thu, 22 Dec 2016 09:44:00 +0100 Subject: [PATCH 07/54] Working quite nicely --- cura/LayerDataBuilder.py | 1 + .../ProcessSlicedLayersJob.py | 25 --- plugins/LayerView/LayerPass.py | 4 +- plugins/LayerView/LayerView.py | 6 +- plugins/LayerView/layers.shader | 206 +++++++++--------- 5 files changed, 108 insertions(+), 134 deletions(-) diff --git a/cura/LayerDataBuilder.py b/cura/LayerDataBuilder.py index f2ad6b55fa..1bd26d1ddc 100644 --- a/cura/LayerDataBuilder.py +++ b/cura/LayerDataBuilder.py @@ -57,6 +57,7 @@ class LayerDataBuilder(MeshBuilder): vertices = numpy.empty((vertex_count, 3), numpy.float32) normals = numpy.empty((vertex_count, 3), numpy.float32) + # line_widths = numpy.empty((vertex_count, 3), numpy.float32) # strictly taken you need 1 less colors = numpy.empty((vertex_count, 4), numpy.float32) indices = numpy.empty((index_count, 2), numpy.int32) diff --git a/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py b/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py index d7863f07cb..6a64cfd5d6 100644 --- a/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py +++ b/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py @@ -85,7 +85,6 @@ class ProcessSlicedLayersJob(Job): min_layer_number = layer.id current_layer = 0 - all_normals = [] for layer in self._layers: abs_layer_number = layer.id + abs(min_layer_number) @@ -128,12 +127,6 @@ class ProcessSlicedLayersJob(Job): this_poly = LayerPolygon.LayerPolygon(layer_data, extruder, line_types, new_points, line_widths) this_poly.buildCache() - normals = this_poly.getNormals() - # normals = this_poly.getNormals()[numpy.where(numpy.logical_not(this_poly.jumpMask))] - # all_normals.append(normals) - # insert last element twice - fake converting line normals to vertex normals - # all_normals.append(normals[-1:]) - this_layer.polygons.append(this_poly) Job.yieldThread() @@ -150,26 +143,8 @@ class ProcessSlicedLayersJob(Job): if self._progress: self._progress.setProgress(progress) - # layer_data.calculateNormals() # We are done processing all the layers we got from the engine, now create a mesh out of the data - # layer_data._normals = numpy.concatenate(all_normals) layer_mesh = layer_data.build() - # normals = [] - # # quick and dirty normals calculation for 2d lines - # for line_idx in range(len(layer_mesh._indices) // 2): - # idx0 = layer_mesh._indices[line_idx] - # idx1 = layer_mesh._indices[line_idx + 1] - # x0 = layer_mesh._vertices[idx0][0] - # y0 = layer_mesh._vertices[idx0][2] - # x1 = layer_mesh._vertices[idx1][0] - # y1 = layer_mesh._vertices[idx1][2] - # dx = x1 - x0; - # dy = y1 - y0; - # normals.append([dy, 0, -dx]) - # normals.append([dy, 0, -dx]) - # layer_mesh._normals = numpy.array(normals) - #from UM.Mesh.MeshData import calculateNormalsFromIndexedVertices - #layer_mesh._normals = calculateNormalsFromIndexedVertices(layer_mesh._vertices, layer_mesh._indices, layer_mesh._face_count) if self._abort_requested: if self._progress: diff --git a/plugins/LayerView/LayerPass.py b/plugins/LayerView/LayerPass.py index 8ff2eb16ec..378f7278c4 100644 --- a/plugins/LayerView/LayerPass.py +++ b/plugins/LayerView/LayerPass.py @@ -54,12 +54,12 @@ class LayerPass(RenderPass): continue # Render all layers below a certain number as line mesh instead of vertices. - if self._layerview._current_layer_num - self._layerview._solid_layers > -1 and not self._layerview._only_show_top_layers: + if self._layerview._current_layer_num > -1 and not self._layerview._only_show_top_layers: start = 0 end = 0 element_counts = layer_data.getElementCounts() for layer, counts in element_counts.items(): - if layer + self._layerview._solid_layers > self._layerview._current_layer_num: + if layer > self._layerview._current_layer_num: break end += counts diff --git a/plugins/LayerView/LayerView.py b/plugins/LayerView/LayerView.py index cf2fbbc1d3..50c13194f7 100644 --- a/plugins/LayerView/LayerView.py +++ b/plugins/LayerView/LayerView.py @@ -236,9 +236,9 @@ class LayerView(View): self.setBusy(True) - #self._top_layers_job = _CreateTopLayersJob(self._controller.getScene(), self._current_layer_num, self._solid_layers) - #self._top_layers_job.finished.connect(self._updateCurrentLayerMesh) - #self._top_layers_job.start() + self._top_layers_job = _CreateTopLayersJob(self._controller.getScene(), self._current_layer_num, self._solid_layers) + self._top_layers_job.finished.connect(self._updateCurrentLayerMesh) + self._top_layers_job.start() def _updateCurrentLayerMesh(self, job): self.setBusy(False) diff --git a/plugins/LayerView/layers.shader b/plugins/LayerView/layers.shader index 270d2daa50..0e8791ef6a 100644 --- a/plugins/LayerView/layers.shader +++ b/plugins/LayerView/layers.shader @@ -16,8 +16,6 @@ vertex = varying highp vec3 v_vertex; varying highp vec3 v_normal; - varying highp vec4 v_orig_vertex; - varying lowp vec4 f_color; varying highp vec3 f_vertex; varying highp vec3 f_normal; @@ -29,14 +27,12 @@ vertex = gl_Position = world_space_vert; // 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_color.a == u_active_extruder) ? a_color : vec4(0.4, 0.4, 0.4, 1.0); //a_color * u_shade_factor; v_color.a = 1.0; v_vertex = world_space_vert.xyz; v_normal = (u_normalMatrix * normalize(a_normal)).xyz; - v_orig_vertex = a_vertex; - // for testing without geometry shader f_color = v_color; f_vertex = v_vertex; @@ -51,7 +47,7 @@ geometry = //uniform highp mat4 u_modelViewProjectionMatrix; layout(lines) in; - layout(triangle_strip, max_vertices = 8) out; + layout(triangle_strip, max_vertices = 28) out; /*layout(std140) uniform Matrices { mat4 u_modelViewProjectionMatrix; };*/ @@ -59,7 +55,6 @@ geometry = in vec4 v_color[]; in vec3 v_vertex[]; in vec3 v_normal[]; - in vec3 v_orig_vertex[]; out vec4 f_color; out vec3 f_normal; @@ -71,20 +66,28 @@ geometry = //vec3 g_normal; //vec3 g_offset; - //vec4 g_vertex_delta; + vec4 g_vertex_delta; vec3 g_vertex_normal_horz; // horizontal and vertical in respect to layers vec4 g_vertex_offset_horz; // vec4 to match gl_in[x].gl_Position vec3 g_vertex_normal_vert; vec4 g_vertex_offset_vert; + vec3 g_vertex_normal_horz_head; + vec4 g_vertex_offset_horz_head; - const float size = 0.5; + const float size_x = 0.2; + const float size_y = 0.1; - //g_vertex_delta = gl_in[1].gl_Position - gl_in[0].gl_Position; - g_vertex_normal_horz = normalize(v_normal[0]); //vec3(g_vertex_delta.z, g_vertex_delta.y, -g_vertex_delta.x); - g_vertex_offset_horz = vec4(g_vertex_normal_horz * size, 0.0); //size * g_vertex_normal_horz; + //g_vertex_normal_horz = normalize(v_normal[0]); //vec3(g_vertex_delta.z, g_vertex_delta.y, -g_vertex_delta.x); + g_vertex_delta = gl_in[1].gl_Position - gl_in[0].gl_Position; + g_vertex_normal_horz_head = normalize(vec3(-g_vertex_delta.x, -g_vertex_delta.y, -g_vertex_delta.z)); + g_vertex_offset_horz_head = vec4(g_vertex_normal_horz_head * size_x, 0.0); + + g_vertex_normal_horz = normalize(vec3(g_vertex_delta.z, g_vertex_delta.y, -g_vertex_delta.x)); + + g_vertex_offset_horz = vec4(g_vertex_normal_horz * size_x, 0.0); //size * g_vertex_normal_horz; g_vertex_normal_vert = vec3(0.0, 1.0, 0.0); //g_vertex_offset_vert = vec3(g_vertex_normal_vert.x * 0.5f, g_vertex_normal_vert.y * 0.5f, g_vertex_normal_vert.z * 0.5f); //size * g_vertex_normal_vert; - g_vertex_offset_vert = vec4(g_vertex_normal_vert * size, 0.0); + g_vertex_offset_vert = vec4(g_vertex_normal_vert * size_y, 0.0); f_vertex = v_vertex[0]; f_normal = g_vertex_normal_horz; @@ -134,108 +137,101 @@ geometry = gl_Position = u_viewProjectionMatrix * (gl_in[1].gl_Position - g_vertex_offset_vert); EmitVertex(); - EndPrimitive(); - } - - -poep = - #version 410 - - uniform highp mat4 u_modelMatrix; - uniform highp mat4 u_viewProjectionMatrix; - uniform highp mat4 u_modelViewProjectionMatrix; - - layout(lines) in; - layout(triangle_strip, max_vertices = 3) out; - - in vec4 v_color[]; - in vec3 v_vertex[]; - in vec3 v_normal[]; - in vec4 v_orig_vertex[]; - - out vec4 f_color; - out vec3 f_normal; - out vec3 f_vertex; - - void main() - { - int i; - vec4 delta; - vec3 g_normal; - vec3 g_offset; - - vec4 g_vertex_delta; - vec4 g_vertex_normal_horz; // horizontal and vertical in respect to layers - vec3 g_vertex_normal_vert; - vec3 g_vertex_offset_horz; - vec3 g_vertex_offset_vert; - - float size = 3; - - g_vertex_delta = v_orig_vertex[1] - v_orig_vertex[0]; - g_vertex_normal_horz = vec4(g_vertex_delta.z, 0.0, -g_vertex_delta.x, g_vertex_delta.w); - if (length(g_vertex_normal_horz) < 0.1) { - g_vertex_normal_horz = vec4(1.0, 0.0, 0.0, 0.0); - g_vertex_offset_horz = vec3(0.0, 0.0, 0.0); - g_vertex_offset_vert = vec3(0.0, 0.0, 0.0); - } else { - g_vertex_normal_horz = normalize(g_vertex_normal_horz); - g_vertex_offset_horz = (u_viewProjectionMatrix * u_modelMatrix * size * g_vertex_normal_horz).xyz; - g_vertex_normal_vert = vec3(0.0, 0.0, 1.0); - g_vertex_offset_vert = (u_viewProjectionMatrix * u_modelMatrix * size * g_vertex_normal_vert).xyz; - } - f_vertex = v_vertex[0]; - f_color = v_color[0]; f_normal = g_vertex_normal_horz; - gl_Position = gl_in[0].gl_Position + g_vertex_offset_horz; + f_color = v_color[0]; + gl_Position = u_viewProjectionMatrix * (gl_in[0].gl_Position + g_vertex_offset_horz); EmitVertex(); f_vertex = v_vertex[1]; f_color = v_color[1]; f_normal = g_vertex_normal_horz; - gl_Position = gl_in[1].gl_Position + g_vertex_offset_horz; + gl_Position = u_viewProjectionMatrix * (gl_in[1].gl_Position + g_vertex_offset_horz); EmitVertex(); - f_vertex = v_vertex[0]; - f_color = v_color[0]; - f_normal = g_vertex_offset_vert; - gl_Position = gl_in[0].gl_Position + g_vertex_offset_vert; - EmitVertex(); - - f_vertex = v_vertex[1]; - f_color = v_color[1]; - f_normal = g_vertex_offset_vert; - gl_Position = gl_in[1].gl_Position + g_vertex_offset_vert; - EmitVertex(); - - f_vertex = v_vertex[0]; - f_color = v_color[0]; - f_normal = -g_vertex_normal_horz; - gl_Position = gl_in[0].gl_Position - g_vertex_offset_horz; - EmitVertex(); - - f_vertex = v_vertex[1]; - f_color = v_color[1]; - f_normal = -g_vertex_normal_horz; - gl_Position = gl_in[1].gl_Position - g_vertex_offset_horz; - EmitVertex(); - - f_vertex = v_vertex[0]; - f_color = v_color[0]; - f_normal = -g_vertex_offset_vert; - gl_Position = gl_in[0].gl_Position - g_vertex_offset_vert; - EmitVertex(); - - f_vertex = v_vertex[1]; - f_color = v_color[1]; - f_normal = -g_vertex_offset_vert; - gl_Position = gl_in[1].gl_Position - g_vertex_offset_vert; - EmitVertex(); - - EndPrimitive(); + // left side + f_vertex = v_vertex[0]; + f_color = v_color[0]; + + f_normal = g_vertex_normal_horz; + gl_Position = u_viewProjectionMatrix * (gl_in[0].gl_Position + g_vertex_offset_horz); + EmitVertex(); + + f_normal = g_vertex_normal_vert; + gl_Position = u_viewProjectionMatrix * (gl_in[0].gl_Position + g_vertex_offset_vert); + EmitVertex(); + + f_normal = g_vertex_normal_horz_head; + gl_Position = u_viewProjectionMatrix * (gl_in[0].gl_Position + g_vertex_offset_horz_head); + EmitVertex(); + + f_normal = -g_vertex_normal_horz; + gl_Position = u_viewProjectionMatrix * (gl_in[0].gl_Position - g_vertex_offset_horz); + EmitVertex(); + + EndPrimitive(); + + f_normal = -g_vertex_normal_horz; + gl_Position = u_viewProjectionMatrix * (gl_in[0].gl_Position - g_vertex_offset_horz); + EmitVertex(); + + f_normal = -g_vertex_normal_vert; + gl_Position = u_viewProjectionMatrix * (gl_in[0].gl_Position - g_vertex_offset_vert); + EmitVertex(); + + f_normal = g_vertex_normal_horz_head; + gl_Position = u_viewProjectionMatrix * (gl_in[0].gl_Position + g_vertex_offset_horz_head); + EmitVertex(); + + f_normal = g_vertex_normal_horz; + gl_Position = u_viewProjectionMatrix * (gl_in[0].gl_Position + g_vertex_offset_horz); + EmitVertex(); + + EndPrimitive(); + + // right side + f_vertex = v_vertex[1]; + f_color = v_color[1]; + + f_normal = g_vertex_normal_horz; + gl_Position = u_viewProjectionMatrix * (gl_in[1].gl_Position + g_vertex_offset_horz); + EmitVertex(); + + f_normal = g_vertex_normal_vert; + gl_Position = u_viewProjectionMatrix * (gl_in[1].gl_Position + g_vertex_offset_vert); + EmitVertex(); + + f_normal = -g_vertex_normal_horz_head; + gl_Position = u_viewProjectionMatrix * (gl_in[1].gl_Position - g_vertex_offset_horz_head); + EmitVertex(); + + f_normal = -g_vertex_normal_horz; + gl_Position = u_viewProjectionMatrix * (gl_in[1].gl_Position - g_vertex_offset_horz); + EmitVertex(); + + EndPrimitive(); + + f_normal = -g_vertex_normal_horz; + gl_Position = u_viewProjectionMatrix * (gl_in[1].gl_Position - g_vertex_offset_horz); + EmitVertex(); + + f_normal = -g_vertex_normal_vert; + gl_Position = u_viewProjectionMatrix * (gl_in[1].gl_Position - g_vertex_offset_vert); + EmitVertex(); + + f_normal = -g_vertex_normal_horz_head; + gl_Position = u_viewProjectionMatrix * (gl_in[1].gl_Position - g_vertex_offset_horz_head); + EmitVertex(); + + f_normal = g_vertex_normal_horz; + gl_Position = u_viewProjectionMatrix * (gl_in[1].gl_Position + g_vertex_offset_horz); + EmitVertex(); + + EndPrimitive(); + + } @@ -271,6 +267,8 @@ fragment = //gl_FrontFacing = .. + //if ((f_normal).z < 0) {discard; } + mediump vec4 finalColor = vec4(0.0); finalColor += u_ambientColor; From 2b37bde6302142ed24bfc32881e78cd59a61c38b Mon Sep 17 00:00:00 2001 From: Jack Ha Date: Thu, 22 Dec 2016 10:46:19 +0100 Subject: [PATCH 08/54] Now with infill --- cura/LayerPolygon.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cura/LayerPolygon.py b/cura/LayerPolygon.py index cb00bd0c60..f37e6a2f5e 100644 --- a/cura/LayerPolygon.py +++ b/cura/LayerPolygon.py @@ -49,7 +49,8 @@ class LayerPolygon: def buildCache(self): # For the line mesh we do not draw Infill or Jumps. Therefore those lines are filtered out. - self._build_cache_line_mesh_mask = numpy.logical_not(numpy.logical_or(self._jump_mask, self._types == LayerPolygon.InfillType )) + # self._build_cache_line_mesh_mask = numpy.logical_not(numpy.logical_or(self._jump_mask, self._types == LayerPolygon.InfillType )) + self._build_cache_line_mesh_mask = numpy.logical_not(self._jump_mask) mesh_line_count = numpy.sum(self._build_cache_line_mesh_mask) self._index_begin = 0 self._index_end = mesh_line_count From c12e6da3ac5224ae72111ae21a1e648f321c5e2d Mon Sep 17 00:00:00 2001 From: Jack Ha Date: Thu, 22 Dec 2016 14:41:50 +0100 Subject: [PATCH 09/54] Started setting layer height and line width in layer view --- cura/Layer.py | 6 ++-- cura/LayerDataBuilder.py | 6 ++-- cura/LayerPolygon.py | 2 +- .../ProcessSlicedLayersJob.py | 10 +++++++ plugins/LayerView/layers.shader | 28 +++++++++++++------ 5 files changed, 37 insertions(+), 15 deletions(-) diff --git a/cura/Layer.py b/cura/Layer.py index bc9f66e881..794d282a47 100644 --- a/cura/Layer.py +++ b/cura/Layer.py @@ -49,14 +49,14 @@ class Layer: return result - def build(self, vertex_offset, index_offset, vertices, colors, indices, normals): + def build(self, vertex_offset, index_offset, vertices, colors, indices): result_vertex_offset = vertex_offset result_index_offset = index_offset self._element_count = 0 for polygon in self._polygons: polygon.build(result_vertex_offset, result_index_offset, vertices, colors, indices) - polygon_normals = polygon.getNormals() # [numpy.where(numpy.logical_not(polygon.jumpMask))] - normals[result_vertex_offset:result_vertex_offset+polygon.lineMeshVertexCount()] = polygon_normals[:polygon.lineMeshVertexCount()] + #polygon_normals = polygon.getNormals() # [numpy.where(numpy.logical_not(polygon.jumpMask))] + #normals[result_vertex_offset:result_vertex_offset+polygon.lineMeshVertexCount()] = polygon_normals[:polygon.lineMeshVertexCount()] result_vertex_offset += polygon.lineMeshVertexCount() result_index_offset += polygon.lineMeshElementCount() self._element_count += polygon.elementCount diff --git a/cura/LayerDataBuilder.py b/cura/LayerDataBuilder.py index 1bd26d1ddc..e32e60efd3 100644 --- a/cura/LayerDataBuilder.py +++ b/cura/LayerDataBuilder.py @@ -56,7 +56,7 @@ class LayerDataBuilder(MeshBuilder): index_count += data.lineMeshElementCount() vertices = numpy.empty((vertex_count, 3), numpy.float32) - normals = numpy.empty((vertex_count, 3), numpy.float32) + # normals = numpy.empty((vertex_count, 3), numpy.float32) # line_widths = numpy.empty((vertex_count, 3), numpy.float32) # strictly taken you need 1 less colors = numpy.empty((vertex_count, 4), numpy.float32) indices = numpy.empty((index_count, 2), numpy.int32) @@ -64,13 +64,13 @@ class LayerDataBuilder(MeshBuilder): vertex_offset = 0 index_offset = 0 for layer, data in self._layers.items(): - ( vertex_offset, index_offset ) = data.build( vertex_offset, index_offset, vertices, colors, indices, normals) + ( vertex_offset, index_offset ) = data.build( vertex_offset, index_offset, vertices, colors, indices) self._element_counts[layer] = data.elementCount self.addVertices(vertices) self.addColors(colors) self.addIndices(indices.flatten()) - self._normals = normals + #self._normals = normals return LayerData(vertices=self.getVertices(), normals=self.getNormals(), indices=self.getIndices(), colors=self.getColors(), uvs=self.getUVCoordinates(), file_name=self.getFileName(), diff --git a/cura/LayerPolygon.py b/cura/LayerPolygon.py index f37e6a2f5e..27b9a9c11d 100644 --- a/cura/LayerPolygon.py +++ b/cura/LayerPolygon.py @@ -60,7 +60,7 @@ class LayerPolygon: self._build_cache_needed_points[1:, 0][:, numpy.newaxis] = self._types[1:] != self._types[:-1] # Mark points as unneeded if they are of types we don't want in the line mesh according to the calculated mask numpy.logical_and(self._build_cache_needed_points, self._build_cache_line_mesh_mask, self._build_cache_needed_points ) - + self._vertex_begin = 0 self._vertex_end = numpy.sum( self._build_cache_needed_points ) diff --git a/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py b/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py index 6a64cfd5d6..7a2fa6072f 100644 --- a/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py +++ b/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py @@ -145,6 +145,16 @@ class ProcessSlicedLayersJob(Job): # We are done processing all the layers we got from the engine, now create a mesh out of the data layer_mesh = layer_data.build() + # Hack for adding line widths and heights: misuse u, v coordinates. + uvs = numpy.zeros([layer_mesh.getVertexCount(), 2], dtype=numpy.float32) + uvs[:, 0] = 0.175 + uvs[:, 1] = 0.125 + + from UM.Math import NumPyUtil + layer_mesh._uvs = NumPyUtil.immutableNDArray(uvs) + # mesh._uvs = numpy.zeros([layer_mesh.getVertexCount(), 2]) + # mesh._uvs[:, 0] = 1.0 # width + # mesh._uvs[:, 1] = 0.1 # height if self._abort_requested: if self._progress: diff --git a/plugins/LayerView/layers.shader b/plugins/LayerView/layers.shader index 0e8791ef6a..f6a96f1eeb 100644 --- a/plugins/LayerView/layers.shader +++ b/plugins/LayerView/layers.shader @@ -10,11 +10,13 @@ vertex = attribute highp vec4 a_vertex; attribute lowp vec4 a_color; attribute highp vec4 a_normal; + attribute highp vec2 a_uvs; // misused here for width and height varying lowp vec4 v_color; varying highp vec3 v_vertex; varying highp vec3 v_normal; + varying lowp vec2 v_uvs; varying lowp vec4 f_color; varying highp vec3 f_vertex; @@ -32,6 +34,7 @@ vertex = v_vertex = world_space_vert.xyz; v_normal = (u_normalMatrix * normalize(a_normal)).xyz; + v_uvs = a_uvs; // for testing without geometry shader f_color = v_color; @@ -47,14 +50,12 @@ geometry = //uniform highp mat4 u_modelViewProjectionMatrix; layout(lines) in; - layout(triangle_strip, max_vertices = 28) out; - /*layout(std140) uniform Matrices { - mat4 u_modelViewProjectionMatrix; - };*/ + layout(triangle_strip, max_vertices = 26) out; in vec4 v_color[]; in vec3 v_vertex[]; in vec3 v_normal[]; + in vec2 v_uvs[]; out vec4 f_color; out vec3 f_normal; @@ -74,8 +75,8 @@ geometry = vec3 g_vertex_normal_horz_head; vec4 g_vertex_offset_horz_head; - const float size_x = 0.2; - const float size_y = 0.1; + float size_x = v_uvs[0].x; + float size_y = v_uvs[0].y; //g_vertex_normal_horz = normalize(v_normal[0]); //vec3(g_vertex_delta.z, g_vertex_delta.y, -g_vertex_delta.x); g_vertex_delta = gl_in[1].gl_Position - gl_in[0].gl_Position; @@ -90,25 +91,29 @@ geometry = g_vertex_offset_vert = vec4(g_vertex_normal_vert * size_y, 0.0); f_vertex = v_vertex[0]; - f_normal = g_vertex_normal_horz; f_color = v_color[0]; + //f_color = vec4(v_uvs[0], 0.0, 1.0); + f_normal = g_vertex_normal_horz; gl_Position = u_viewProjectionMatrix * (gl_in[0].gl_Position + g_vertex_offset_horz); EmitVertex(); f_vertex = v_vertex[1]; f_color = v_color[1]; + //f_color = vec4(v_uvs[0], 0.0, 1.0); f_normal = g_vertex_normal_horz; gl_Position = u_viewProjectionMatrix * (gl_in[1].gl_Position + g_vertex_offset_horz); EmitVertex(); f_vertex = v_vertex[0]; f_color = v_color[0]; + //f_color = vec4(v_uvs[0], 0.0, 1.0); f_normal = g_vertex_normal_vert; gl_Position = u_viewProjectionMatrix * (gl_in[0].gl_Position + g_vertex_offset_vert); EmitVertex(); f_vertex = v_vertex[1]; f_color = v_color[1]; + //f_color = vec4(v_uvs[0], 0.0, 1.0); f_normal = g_vertex_normal_vert; gl_Position = u_viewProjectionMatrix * (gl_in[1].gl_Position + g_vertex_offset_vert); EmitVertex(); @@ -116,23 +121,27 @@ geometry = f_vertex = v_vertex[0]; f_normal = -g_vertex_normal_horz; f_color = v_color[0]; + //f_color = vec4(v_uvs[0], 0.0, 1.0); gl_Position = u_viewProjectionMatrix * (gl_in[0].gl_Position - g_vertex_offset_horz); EmitVertex(); f_vertex = v_vertex[1]; f_color = v_color[1]; + //f_color = vec4(v_uvs[0], 0.0, 1.0); f_normal = -g_vertex_normal_horz; gl_Position = u_viewProjectionMatrix * (gl_in[1].gl_Position - g_vertex_offset_horz); EmitVertex(); f_vertex = v_vertex[0]; f_color = v_color[0]; + //f_color = vec4(v_uvs[0], 0.0, 1.0); f_normal = -g_vertex_normal_vert; gl_Position = u_viewProjectionMatrix * (gl_in[0].gl_Position - g_vertex_offset_vert); EmitVertex(); f_vertex = v_vertex[1]; f_color = v_color[1]; + //f_color = vec4(v_uvs[0], 0.0, 1.0); f_normal = -g_vertex_normal_vert; gl_Position = u_viewProjectionMatrix * (gl_in[1].gl_Position - g_vertex_offset_vert); EmitVertex(); @@ -140,11 +149,13 @@ geometry = f_vertex = v_vertex[0]; f_normal = g_vertex_normal_horz; f_color = v_color[0]; + //f_color = vec4(v_uvs[0], 0.0, 1.0); gl_Position = u_viewProjectionMatrix * (gl_in[0].gl_Position + g_vertex_offset_horz); EmitVertex(); f_vertex = v_vertex[1]; f_color = v_color[1]; + //f_color = vec4(v_uvs[0], 0.0, 1.0); f_normal = g_vertex_normal_horz; gl_Position = u_viewProjectionMatrix * (gl_in[1].gl_Position + g_vertex_offset_horz); EmitVertex(); @@ -313,4 +324,5 @@ u_lightPosition = light_0_position [attributes] a_vertex = vertex a_color = color -a_normal = normal \ No newline at end of file +a_normal = normal +a_uvs = uv0 From 9904dad07b17aacdc7175d82f98a1ac161609ba4 Mon Sep 17 00:00:00 2001 From: Jack Ha Date: Wed, 28 Dec 2016 11:30:59 +0100 Subject: [PATCH 10/54] Added line thickness to layer view --- cura/Layer.py | 5 +++-- cura/LayerDataBuilder.py | 5 +++-- cura/LayerPolygon.py | 11 ++++++++--- plugins/CuraEngineBackend/ProcessSlicedLayersJob.py | 10 +++++----- plugins/LayerView/layers.shader | 8 +++++--- 5 files changed, 24 insertions(+), 15 deletions(-) diff --git a/cura/Layer.py b/cura/Layer.py index 794d282a47..9fc744e9de 100644 --- a/cura/Layer.py +++ b/cura/Layer.py @@ -49,12 +49,13 @@ class Layer: return result - def build(self, vertex_offset, index_offset, vertices, colors, indices): + def build(self, vertex_offset, index_offset, vertices, colors, line_dimensions, indices): result_vertex_offset = vertex_offset result_index_offset = index_offset self._element_count = 0 + thickness = self._thickness / 1000 # micrometer to millimeter for polygon in self._polygons: - polygon.build(result_vertex_offset, result_index_offset, vertices, colors, indices) + polygon.build(result_vertex_offset, result_index_offset, vertices, colors, line_dimensions, indices, thickness) #polygon_normals = polygon.getNormals() # [numpy.where(numpy.logical_not(polygon.jumpMask))] #normals[result_vertex_offset:result_vertex_offset+polygon.lineMeshVertexCount()] = polygon_normals[:polygon.lineMeshVertexCount()] result_vertex_offset += polygon.lineMeshVertexCount() diff --git a/cura/LayerDataBuilder.py b/cura/LayerDataBuilder.py index e32e60efd3..7ff8a3737a 100644 --- a/cura/LayerDataBuilder.py +++ b/cura/LayerDataBuilder.py @@ -57,19 +57,20 @@ class LayerDataBuilder(MeshBuilder): vertices = numpy.empty((vertex_count, 3), numpy.float32) # normals = numpy.empty((vertex_count, 3), numpy.float32) - # line_widths = numpy.empty((vertex_count, 3), numpy.float32) # strictly taken you need 1 less + line_dimensions = numpy.empty((vertex_count, 2), numpy.float32) colors = numpy.empty((vertex_count, 4), numpy.float32) indices = numpy.empty((index_count, 2), numpy.int32) vertex_offset = 0 index_offset = 0 for layer, data in self._layers.items(): - ( vertex_offset, index_offset ) = data.build( vertex_offset, index_offset, vertices, colors, indices) + ( vertex_offset, index_offset ) = data.build( vertex_offset, index_offset, vertices, colors, line_dimensions, indices) self._element_counts[layer] = data.elementCount self.addVertices(vertices) self.addColors(colors) self.addIndices(indices.flatten()) + self._uvs = line_dimensions #self._normals = normals return LayerData(vertices=self.getVertices(), normals=self.getNormals(), indices=self.getIndices(), diff --git a/cura/LayerPolygon.py b/cura/LayerPolygon.py index 27b9a9c11d..628fd78350 100644 --- a/cura/LayerPolygon.py +++ b/cura/LayerPolygon.py @@ -64,8 +64,9 @@ class LayerPolygon: self._vertex_begin = 0 self._vertex_end = numpy.sum( self._build_cache_needed_points ) - - def build(self, vertex_offset, index_offset, vertices, colors, indices): + ## build + # line_thicknesses: array with type as index and thickness as value + def build(self, vertex_offset, index_offset, vertices, colors, line_dimensions, indices, thickness): if (self._build_cache_line_mesh_mask is None) or (self._build_cache_needed_points is None ): self.buildCache() @@ -84,9 +85,13 @@ class LayerPolygon: # Points are picked based on the index list to get the vertices needed. vertices[self._vertex_begin:self._vertex_end, :] = self._data[index_list, :] # Create an array with colors for each vertex and remove the color data for the points that has been thrown away. - colors[self._vertex_begin:self._vertex_end, :] = numpy.tile(self._colors, (1, 2)).reshape((-1, 4))[needed_points_list.ravel()] + colors[self._vertex_begin:self._vertex_end, :] = numpy.tile(self._colors, (1, 2)).reshape((-1, 4))[needed_points_list.ravel()] colors[self._vertex_begin:self._vertex_end, :] *= numpy.array([[0.5, 0.5, 0.5, 1.0]], numpy.float32) + # Create an array with line widths for each vertex. + line_dimensions[self._vertex_begin:self._vertex_end, :] = numpy.tile(self._line_widths, (1, 2)).reshape((-1, 1))[needed_points_list.ravel()] + line_dimensions[self._vertex_begin:self._vertex_end, 1] = thickness + # The relative values of begin and end indices have already been set in buildCache, so we only need to offset them to the parents offset. self._index_begin += index_offset self._index_end += index_offset diff --git a/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py b/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py index 7a2fa6072f..f8b80e9da0 100644 --- a/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py +++ b/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py @@ -146,12 +146,12 @@ class ProcessSlicedLayersJob(Job): # We are done processing all the layers we got from the engine, now create a mesh out of the data layer_mesh = layer_data.build() # Hack for adding line widths and heights: misuse u, v coordinates. - uvs = numpy.zeros([layer_mesh.getVertexCount(), 2], dtype=numpy.float32) - uvs[:, 0] = 0.175 - uvs[:, 1] = 0.125 + #uvs = numpy.zeros([layer_mesh.getVertexCount(), 2], dtype=numpy.float32) + #uvs[:, 0] = 0.175 + #uvs[:, 1] = 0.125 - from UM.Math import NumPyUtil - layer_mesh._uvs = NumPyUtil.immutableNDArray(uvs) + #from UM.Math import NumPyUtil + #layer_mesh._uvs = NumPyUtil.immutableNDArray(uvs) # mesh._uvs = numpy.zeros([layer_mesh.getVertexCount(), 2]) # mesh._uvs[:, 0] = 1.0 # width # mesh._uvs[:, 1] = 0.1 # height diff --git a/plugins/LayerView/layers.shader b/plugins/LayerView/layers.shader index f6a96f1eeb..0cff84d233 100644 --- a/plugins/LayerView/layers.shader +++ b/plugins/LayerView/layers.shader @@ -24,7 +24,9 @@ vertex = void main() { - vec4 world_space_vert = u_modelMatrix * a_vertex; + vec4 v1_vertex = a_vertex; + v1_vertex.y -= a_uvs.y / 2; // half layer down + vec4 world_space_vert = u_modelMatrix * v1_vertex; // gl_Position = u_viewProjectionMatrix * world_space_vert; gl_Position = world_space_vert; // gl_Position = u_modelViewProjectionMatrix * a_vertex; @@ -75,8 +77,8 @@ geometry = vec3 g_vertex_normal_horz_head; vec4 g_vertex_offset_horz_head; - float size_x = v_uvs[0].x; - float size_y = v_uvs[0].y; + float size_x = v_uvs[0].x / 2 + 0.01; // radius, and make it nicely overlapping + float size_y = v_uvs[0].y / 2 + 0.01; //g_vertex_normal_horz = normalize(v_normal[0]); //vec3(g_vertex_delta.z, g_vertex_delta.y, -g_vertex_delta.x); g_vertex_delta = gl_in[1].gl_Position - gl_in[0].gl_Position; From 8d2b3654a4ff8d107b97fb2297cc27bd05315ed5 Mon Sep 17 00:00:00 2001 From: Jack Ha Date: Wed, 28 Dec 2016 13:15:42 +0100 Subject: [PATCH 11/54] Layer thickness now as array --- cura/LayerPolygon.py | 9 +++++---- plugins/CuraEngineBackend/ProcessSlicedLayersJob.py | 10 +++++++--- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/cura/LayerPolygon.py b/cura/LayerPolygon.py index 628fd78350..858fa11c77 100644 --- a/cura/LayerPolygon.py +++ b/cura/LayerPolygon.py @@ -18,13 +18,14 @@ class LayerPolygon: __jump_map = numpy.logical_or(numpy.logical_or(numpy.arange(11) == NoneType, numpy.arange(11) == MoveCombingType), numpy.arange(11) == MoveRetractionType) - def __init__(self, mesh, extruder, line_types, data, line_widths): + def __init__(self, mesh, extruder, line_types, data, line_widths, line_thicknesses): self._mesh = mesh self._extruder = extruder self._types = line_types self._data = data self._line_widths = line_widths - + self._line_thicknesses = line_thicknesses + self._vertex_begin = 0 self._vertex_end = 0 self._index_begin = 0 @@ -89,8 +90,8 @@ class LayerPolygon: colors[self._vertex_begin:self._vertex_end, :] *= numpy.array([[0.5, 0.5, 0.5, 1.0]], numpy.float32) # Create an array with line widths for each vertex. - line_dimensions[self._vertex_begin:self._vertex_end, :] = numpy.tile(self._line_widths, (1, 2)).reshape((-1, 1))[needed_points_list.ravel()] - line_dimensions[self._vertex_begin:self._vertex_end, 1] = thickness + line_dimensions[self._vertex_begin:self._vertex_end, 0] = numpy.tile(self._line_widths, (1, 2)).reshape((-1, 1))[needed_points_list.ravel()][:, 0] + line_dimensions[self._vertex_begin:self._vertex_end, 1] = numpy.tile(self._line_thicknesses, (1, 2)).reshape((-1, 1))[needed_points_list.ravel()][:, 0] # The relative values of begin and end indices have already been set in buildCache, so we only need to offset them to the parents offset. self._index_begin += index_offset diff --git a/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py b/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py index f8b80e9da0..7b814d99b4 100644 --- a/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py +++ b/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py @@ -92,7 +92,6 @@ class ProcessSlicedLayersJob(Job): layer_data.addLayer(abs_layer_number) this_layer = layer_data.getLayer(abs_layer_number) layer_data.setLayerHeight(abs_layer_number, layer.height) - layer_data.setLayerThickness(abs_layer_number, layer.thickness) for p in range(layer.repeatedMessageCount("path_segment")): polygon = layer.getRepeatedMessage("path_segment", p) @@ -110,7 +109,12 @@ class ProcessSlicedLayersJob(Job): line_widths = numpy.fromstring(polygon.line_width, dtype="f4") # Convert bytearray to numpy array line_widths = line_widths.reshape((-1,1)) # We get a linear list of pairs that make up the points, so make numpy interpret them correctly. - + + # In the future, line_thicknesses should be given by CuraEngine as well. + # Currently the infill layer thickness also translates to line width + line_thicknesses = numpy.zeros(line_widths.shape, dtype="f4") + line_thicknesses[:] = layer.thickness / 1000 # from micrometer to millimeter + # Create a new 3D-array, copy the 2D points over and insert the right height. # This uses manual array creation + copy rather than numpy.insert since this is # faster. @@ -124,7 +128,7 @@ class ProcessSlicedLayersJob(Job): new_points[:, 1] = points[:, 2] new_points[:, 2] = -points[:, 1] - this_poly = LayerPolygon.LayerPolygon(layer_data, extruder, line_types, new_points, line_widths) + this_poly = LayerPolygon.LayerPolygon(layer_data, extruder, line_types, new_points, line_widths, line_thicknesses) this_poly.buildCache() this_layer.polygons.append(this_poly) From 0f2fb86cd9872843eb73d86cbb5e001c75ad93dd Mon Sep 17 00:00:00 2001 From: Jack Ha Date: Wed, 28 Dec 2016 15:20:14 +0100 Subject: [PATCH 12/54] Layer shader now uses own attribute for line dimensions instead of misusing uvs. --- cura/Layer.py | 5 +--- cura/LayerData.py | 4 +-- cura/LayerDataBuilder.py | 12 +++++--- cura/LayerPolygon.py | 3 +- .../ProcessSlicedLayersJob.py | 10 ------- plugins/LayerView/layers.shader | 28 ++++++------------- 6 files changed, 22 insertions(+), 40 deletions(-) diff --git a/cura/Layer.py b/cura/Layer.py index 9fc744e9de..3103d1772e 100644 --- a/cura/Layer.py +++ b/cura/Layer.py @@ -53,11 +53,8 @@ class Layer: result_vertex_offset = vertex_offset result_index_offset = index_offset self._element_count = 0 - thickness = self._thickness / 1000 # micrometer to millimeter for polygon in self._polygons: - polygon.build(result_vertex_offset, result_index_offset, vertices, colors, line_dimensions, indices, thickness) - #polygon_normals = polygon.getNormals() # [numpy.where(numpy.logical_not(polygon.jumpMask))] - #normals[result_vertex_offset:result_vertex_offset+polygon.lineMeshVertexCount()] = polygon_normals[:polygon.lineMeshVertexCount()] + polygon.build(result_vertex_offset, result_index_offset, vertices, colors, line_dimensions, indices) result_vertex_offset += polygon.lineMeshVertexCount() result_index_offset += polygon.lineMeshElementCount() self._element_count += polygon.elementCount diff --git a/cura/LayerData.py b/cura/LayerData.py index ad5326373e..3fe550c297 100644 --- a/cura/LayerData.py +++ b/cura/LayerData.py @@ -6,9 +6,9 @@ from UM.Mesh.MeshData import MeshData # Immutable, use LayerDataBuilder to create one of these. class LayerData(MeshData): def __init__(self, vertices = None, normals = None, indices = None, colors = None, uvs = None, file_name = None, - center_position = None, layers=None, element_counts=None): + center_position = None, layers=None, element_counts=None, attributes=None): super().__init__(vertices=vertices, normals=normals, indices=indices, colors=colors, uvs=uvs, - file_name=file_name, center_position=center_position) + file_name=file_name, center_position=center_position, attributes=attributes) self._layers = layers self._element_counts = element_counts diff --git a/cura/LayerDataBuilder.py b/cura/LayerDataBuilder.py index 7ff8a3737a..41c7790102 100644 --- a/cura/LayerDataBuilder.py +++ b/cura/LayerDataBuilder.py @@ -56,7 +56,6 @@ class LayerDataBuilder(MeshBuilder): index_count += data.lineMeshElementCount() vertices = numpy.empty((vertex_count, 3), numpy.float32) - # normals = numpy.empty((vertex_count, 3), numpy.float32) line_dimensions = numpy.empty((vertex_count, 2), numpy.float32) colors = numpy.empty((vertex_count, 4), numpy.float32) indices = numpy.empty((index_count, 2), numpy.int32) @@ -70,10 +69,15 @@ class LayerDataBuilder(MeshBuilder): self.addVertices(vertices) self.addColors(colors) self.addIndices(indices.flatten()) - self._uvs = line_dimensions - #self._normals = normals + # self._uvs = line_dimensions + attributes = { + "line_dimensions": { + "value": line_dimensions, + "opengl_name": "a_line_dim", + "opengl_type": "vector2f"} + } return LayerData(vertices=self.getVertices(), normals=self.getNormals(), indices=self.getIndices(), colors=self.getColors(), uvs=self.getUVCoordinates(), file_name=self.getFileName(), center_position=self.getCenterPosition(), layers=self._layers, - element_counts=self._element_counts) + element_counts=self._element_counts, attributes=attributes) diff --git a/cura/LayerPolygon.py b/cura/LayerPolygon.py index 858fa11c77..439146e6e2 100644 --- a/cura/LayerPolygon.py +++ b/cura/LayerPolygon.py @@ -67,7 +67,7 @@ class LayerPolygon: ## build # line_thicknesses: array with type as index and thickness as value - def build(self, vertex_offset, index_offset, vertices, colors, line_dimensions, indices, thickness): + def build(self, vertex_offset, index_offset, vertices, colors, line_dimensions, indices): if (self._build_cache_line_mesh_mask is None) or (self._build_cache_needed_points is None ): self.buildCache() @@ -85,6 +85,7 @@ class LayerPolygon: # Points are picked based on the index list to get the vertices needed. vertices[self._vertex_begin:self._vertex_end, :] = self._data[index_list, :] + # Create an array with colors for each vertex and remove the color data for the points that has been thrown away. colors[self._vertex_begin:self._vertex_end, :] = numpy.tile(self._colors, (1, 2)).reshape((-1, 4))[needed_points_list.ravel()] colors[self._vertex_begin:self._vertex_end, :] *= numpy.array([[0.5, 0.5, 0.5, 1.0]], numpy.float32) diff --git a/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py b/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py index 7b814d99b4..be148e41f6 100644 --- a/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py +++ b/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py @@ -149,16 +149,6 @@ class ProcessSlicedLayersJob(Job): # We are done processing all the layers we got from the engine, now create a mesh out of the data layer_mesh = layer_data.build() - # Hack for adding line widths and heights: misuse u, v coordinates. - #uvs = numpy.zeros([layer_mesh.getVertexCount(), 2], dtype=numpy.float32) - #uvs[:, 0] = 0.175 - #uvs[:, 1] = 0.125 - - #from UM.Math import NumPyUtil - #layer_mesh._uvs = NumPyUtil.immutableNDArray(uvs) - # mesh._uvs = numpy.zeros([layer_mesh.getVertexCount(), 2]) - # mesh._uvs[:, 0] = 1.0 # width - # mesh._uvs[:, 1] = 0.1 # height if self._abort_requested: if self._progress: diff --git a/plugins/LayerView/layers.shader b/plugins/LayerView/layers.shader index 0cff84d233..cb34360226 100644 --- a/plugins/LayerView/layers.shader +++ b/plugins/LayerView/layers.shader @@ -10,13 +10,14 @@ vertex = attribute highp vec4 a_vertex; attribute lowp vec4 a_color; attribute highp vec4 a_normal; - attribute highp vec2 a_uvs; // misused here for width and height + attribute highp vec2 a_line_dim; // line width and thickness varying lowp vec4 v_color; varying highp vec3 v_vertex; varying highp vec3 v_normal; - varying lowp vec2 v_uvs; + //varying lowp vec2 v_uvs; + varying lowp vec2 v_line_dim; varying lowp vec4 f_color; varying highp vec3 f_vertex; @@ -25,7 +26,7 @@ vertex = void main() { vec4 v1_vertex = a_vertex; - v1_vertex.y -= a_uvs.y / 2; // half layer down + v1_vertex.y -= a_line_dim.y / 2; // half layer down vec4 world_space_vert = u_modelMatrix * v1_vertex; // gl_Position = u_viewProjectionMatrix * world_space_vert; gl_Position = world_space_vert; @@ -36,7 +37,7 @@ vertex = v_vertex = world_space_vert.xyz; v_normal = (u_normalMatrix * normalize(a_normal)).xyz; - v_uvs = a_uvs; + v_line_dim = a_line_dim; // for testing without geometry shader f_color = v_color; @@ -47,9 +48,7 @@ vertex = geometry = #version 410 - //uniform highp mat4 u_modelMatrix; uniform highp mat4 u_viewProjectionMatrix; - //uniform highp mat4 u_modelViewProjectionMatrix; layout(lines) in; layout(triangle_strip, max_vertices = 26) out; @@ -57,7 +56,7 @@ geometry = in vec4 v_color[]; in vec3 v_vertex[]; in vec3 v_normal[]; - in vec2 v_uvs[]; + in vec2 v_line_dim[]; out vec4 f_color; out vec3 f_normal; @@ -65,10 +64,6 @@ geometry = void main() { - //int i; - //vec3 g_normal; - //vec3 g_offset; - vec4 g_vertex_delta; vec3 g_vertex_normal_horz; // horizontal and vertical in respect to layers vec4 g_vertex_offset_horz; // vec4 to match gl_in[x].gl_Position @@ -77,8 +72,8 @@ geometry = vec3 g_vertex_normal_horz_head; vec4 g_vertex_offset_horz_head; - float size_x = v_uvs[0].x / 2 + 0.01; // radius, and make it nicely overlapping - float size_y = v_uvs[0].y / 2 + 0.01; + float size_x = v_line_dim[0].x / 2 + 0.01; // radius, and make it nicely overlapping + float size_y = v_line_dim[0].y / 2 + 0.01; //g_vertex_normal_horz = normalize(v_normal[0]); //vec3(g_vertex_delta.z, g_vertex_delta.y, -g_vertex_delta.x); g_vertex_delta = gl_in[1].gl_Position - gl_in[0].gl_Position; @@ -89,7 +84,6 @@ geometry = g_vertex_offset_horz = vec4(g_vertex_normal_horz * size_x, 0.0); //size * g_vertex_normal_horz; g_vertex_normal_vert = vec3(0.0, 1.0, 0.0); - //g_vertex_offset_vert = vec3(g_vertex_normal_vert.x * 0.5f, g_vertex_normal_vert.y * 0.5f, g_vertex_normal_vert.z * 0.5f); //size * g_vertex_normal_vert; g_vertex_offset_vert = vec4(g_vertex_normal_vert * size_y, 0.0); f_vertex = v_vertex[0]; @@ -243,10 +237,6 @@ geometry = EmitVertex(); EndPrimitive(); - - - - } fragment = @@ -327,4 +317,4 @@ u_lightPosition = light_0_position a_vertex = vertex a_color = color a_normal = normal -a_uvs = uv0 +a_line_dim = line_dim From 1217281727d9496a7c31b1f36872eec88e91bbdd Mon Sep 17 00:00:00 2001 From: Jack Ha Date: Thu, 29 Dec 2016 16:49:00 +0100 Subject: [PATCH 13/54] Busy with layer_view options --- cura/Layer.py | 4 +- cura/LayerDataBuilder.py | 27 ++++-- cura/LayerPolygon.py | 6 +- .../ProcessSlicedLayersJob.py | 34 +++++++- plugins/LayerView/LayerPass.py | 4 + plugins/LayerView/LayerView.qml | 72 +++++++++++++++ plugins/LayerView/layers.shader | 87 +++++++++++-------- 7 files changed, 187 insertions(+), 47 deletions(-) diff --git a/cura/Layer.py b/cura/Layer.py index 3103d1772e..8d35e9c6b2 100644 --- a/cura/Layer.py +++ b/cura/Layer.py @@ -49,12 +49,12 @@ class Layer: return result - def build(self, vertex_offset, index_offset, vertices, colors, line_dimensions, indices): + def build(self, vertex_offset, index_offset, vertices, colors, line_dimensions, extruders, indices): result_vertex_offset = vertex_offset result_index_offset = index_offset self._element_count = 0 for polygon in self._polygons: - polygon.build(result_vertex_offset, result_index_offset, vertices, colors, line_dimensions, indices) + polygon.build(result_vertex_offset, result_index_offset, vertices, colors, line_dimensions, extruders, indices) result_vertex_offset += polygon.lineMeshVertexCount() result_index_offset += polygon.lineMeshElementCount() self._element_count += polygon.elementCount diff --git a/cura/LayerDataBuilder.py b/cura/LayerDataBuilder.py index 41c7790102..2b46a604b7 100644 --- a/cura/LayerDataBuilder.py +++ b/cura/LayerDataBuilder.py @@ -48,7 +48,8 @@ class LayerDataBuilder(MeshBuilder): self._layers[layer].setThickness(thickness) - def build(self): + # material color map: [r, g, b, a] for each extruder row. + def build(self, material_color_map): vertex_count = 0 index_count = 0 for layer, data in self._layers.items(): @@ -59,23 +60,39 @@ class LayerDataBuilder(MeshBuilder): line_dimensions = numpy.empty((vertex_count, 2), numpy.float32) colors = numpy.empty((vertex_count, 4), numpy.float32) indices = numpy.empty((index_count, 2), numpy.int32) + extruders = numpy.empty((vertex_count), numpy.float32) vertex_offset = 0 index_offset = 0 for layer, data in self._layers.items(): - ( vertex_offset, index_offset ) = data.build( vertex_offset, index_offset, vertices, colors, line_dimensions, indices) + ( vertex_offset, index_offset ) = data.build( vertex_offset, index_offset, vertices, colors, line_dimensions, extruders, indices) self._element_counts[layer] = data.elementCount self.addVertices(vertices) self.addColors(colors) self.addIndices(indices.flatten()) - # self._uvs = line_dimensions + + material_colors = numpy.zeros((line_dimensions.shape[0], 4), dtype=numpy.float32) + for extruder_nr in range(material_color_map.shape[0]): + material_colors[extruders == extruder_nr] = material_color_map[extruder_nr] + attributes = { "line_dimensions": { "value": line_dimensions, "opengl_name": "a_line_dim", - "opengl_type": "vector2f"} - } + "opengl_type": "vector2f" + }, + "extruders": { + "value": extruders, + "opengl_name": "a_extruder", + "opengl_type": "float" + }, + "colors": { + "value": material_colors, + "opengl_name": "a_material_color", + "opengl_type": "vector4f" + }, + } return LayerData(vertices=self.getVertices(), normals=self.getNormals(), indices=self.getIndices(), colors=self.getColors(), uvs=self.getUVCoordinates(), file_name=self.getFileName(), diff --git a/cura/LayerPolygon.py b/cura/LayerPolygon.py index 439146e6e2..bb37d641bb 100644 --- a/cura/LayerPolygon.py +++ b/cura/LayerPolygon.py @@ -38,7 +38,7 @@ class LayerPolygon: # Buffering the colors shouldn't be necessary as it is not # re-used and can save alot of memory usage. - 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 # * [1, 1, 1, self._extruder] # The alpha component is used to store the extruder nr 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 @@ -67,7 +67,7 @@ class LayerPolygon: ## build # line_thicknesses: array with type as index and thickness as value - def build(self, vertex_offset, index_offset, vertices, colors, line_dimensions, indices): + def build(self, vertex_offset, index_offset, vertices, colors, line_dimensions, extruders, indices): if (self._build_cache_line_mesh_mask is None) or (self._build_cache_needed_points is None ): self.buildCache() @@ -94,6 +94,8 @@ class LayerPolygon: line_dimensions[self._vertex_begin:self._vertex_end, 0] = numpy.tile(self._line_widths, (1, 2)).reshape((-1, 1))[needed_points_list.ravel()][:, 0] line_dimensions[self._vertex_begin:self._vertex_end, 1] = numpy.tile(self._line_thicknesses, (1, 2)).reshape((-1, 1))[needed_points_list.ravel()][:, 0] + extruders[self._vertex_begin:self._vertex_end] = float(self._extruder) + # The relative values of begin and end indices have already been set in buildCache, so we only need to offset them to the parents offset. self._index_begin += index_offset self._index_end += index_offset diff --git a/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py b/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py index be148e41f6..d7be0f1a52 100644 --- a/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py +++ b/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py @@ -24,6 +24,14 @@ from time import time catalog = i18nCatalog("cura") +def colorCodeToRGBA(color_code): + return [ + int(color_code[1:3], 16) / 255, + int(color_code[3:5], 16) / 255, + int(color_code[5:7], 16) / 255, + 1.0] + + class ProcessSlicedLayersJob(Job): def __init__(self, layers): super().__init__() @@ -148,7 +156,31 @@ class ProcessSlicedLayersJob(Job): self._progress.setProgress(progress) # We are done processing all the layers we got from the engine, now create a mesh out of the data - layer_mesh = layer_data.build() + + # Find out colors per extruder + # TODO: move to a better place. Code is similar to code in ExtrudersModel + from cura.Settings.ExtruderManager import ExtruderManager + import UM + global_container_stack = UM.Application.getInstance().getGlobalContainerStack() + manager = ExtruderManager.getInstance() + extruders = list(manager.getMachineExtruders(global_container_stack.getId())) + if extruders: + material_color_map = numpy.zeros((len(extruders), 4), dtype=numpy.float32) + for extruder in extruders: + material = extruder.findContainer({"type": "material"}) + position = int(extruder.getMetaDataEntry("position", default="0")) # Get the position + color_code = material.getMetaDataEntry("color_code") + color = colorCodeToRGBA(color_code) + material_color_map[position, :] = color + else: + # Single extruder via global stack. + material_color_map = numpy.zeros((1, 4), dtype=numpy.float32) + material = global_container_stack.findContainer({"type": "material"}) + color_code = material.getMetaDataEntry("color_code") + color = colorCodeToRGBA(color_code) + material_color_map[0, :] = color + + layer_mesh = layer_data.build(material_color_map) if self._abort_requested: if self._progress: diff --git a/plugins/LayerView/LayerPass.py b/plugins/LayerView/LayerPass.py index 378f7278c4..dda35624ec 100644 --- a/plugins/LayerView/LayerPass.py +++ b/plugins/LayerView/LayerPass.py @@ -37,6 +37,10 @@ class LayerPass(RenderPass): self._layer_shader = OpenGL.getInstance().createShaderProgram(os.path.join(PluginRegistry.getInstance().getPluginPath("LayerView"), "layers.shader")) # Use extruder 0 if the extruder manager reports extruder index -1 (for single extrusion printers) self._layer_shader.setUniformValue("u_active_extruder", float(max(0, self._extruder_manager.activeExtruderIndex))) + self._layer_shader.setUniformValue("u_layer_view_type", 0) + self._layer_shader.setUniformValue("u_only_color_active_extruder", 1) + self._layer_shader.setUniformValue("u_extruder_opacity", [1, 1, 1, 1]) + if not self._tool_handle_shader: self._tool_handle_shader = OpenGL.getInstance().createShaderProgram(Resources.getPath(Resources.Shaders, "toolhandle.shader")) diff --git a/plugins/LayerView/LayerView.qml b/plugins/LayerView/LayerView.qml index fef0c52c12..68c51e5752 100644 --- a/plugins/LayerView/LayerView.qml +++ b/plugins/LayerView/LayerView.qml @@ -95,6 +95,7 @@ Item } Rectangle { + id: slider_background anchors.left: parent.left anchors.verticalCenter: parent.verticalCenter z: slider.z - 1 @@ -113,4 +114,75 @@ Item } } } + + Rectangle { + anchors.left: parent.left + anchors.verticalCenter: parent.verticalCenter + anchors.top: slider_background.bottom + width: UM.Theme.getSize("slider_layerview_background").width * 3 + height: slider.height + UM.Theme.getSize("default_margin").height * 2 + color: UM.Theme.getColor("tool_panel_background"); + border.width: UM.Theme.getSize("default_lining").width + border.color: UM.Theme.getColor("lining") + + ListModel + { + id: layerViewTypes + ListElement { + text: "Line type" + type_id: 0 // these ids match the switching in the shader + } + ListElement { + text: "Material color" + type_id: 1 + } + ListElement { + text: "Printing speed" + type_id: 2 + } + } + + ComboBox + { + id: layer_type_combobox + anchors.top: slider_background.bottom + model: layerViewTypes + onActivated: { + CuraApplication.log("Combobox" + String(index)); + CuraApplication.log(layerViewTypes.get(index).type_id); + } + } + + ColumnLayout { + anchors.top: layer_type_combobox.bottom + CheckBox { + checked: true + onClicked: { + CuraApplication.log("First"); + } + text: "Extruder 1" + } + CheckBox { + checked: true + onClicked: { + CuraApplication.log("First"); + } + text: "Extruder 2" + } + CheckBox { + onClicked: { + CuraApplication.log("First"); + } + text: "Travel moves" + } + CheckBox { + checked: true + onClicked: { + CuraApplication.log("First"); + } + text: "Only color active extruder" + } + } + + } } diff --git a/plugins/LayerView/layers.shader b/plugins/LayerView/layers.shader index cb34360226..869230e87d 100644 --- a/plugins/LayerView/layers.shader +++ b/plugins/LayerView/layers.shader @@ -4,24 +4,33 @@ vertex = //uniform highp mat4 u_viewProjectionMatrix; //uniform highp mat4 u_modelViewProjectionMatrix; uniform lowp float u_active_extruder; + uniform lowp int u_layer_view_type; + uniform lowp int u_only_color_active_extruder; + uniform lowp vec4 u_extruder_opacity; // currently only for max 4 extruders, others always visible + uniform lowp float u_shade_factor; uniform highp mat4 u_normalMatrix; attribute highp vec4 a_vertex; attribute lowp vec4 a_color; + attribute lowp vec4 a_material_color; attribute highp vec4 a_normal; attribute highp vec2 a_line_dim; // line width and thickness + attribute highp int a_extruder; varying lowp vec4 v_color; + //varying lowp vec4 v_material_color; varying highp vec3 v_vertex; varying highp vec3 v_normal; //varying lowp vec2 v_uvs; varying lowp vec2 v_line_dim; + varying highp int v_extruder; varying lowp vec4 f_color; varying highp vec3 f_vertex; varying highp vec3 f_normal; + varying highp int f_extruder; void main() { @@ -32,17 +41,38 @@ vertex = gl_Position = world_space_vert; // 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 : vec4(0.4, 0.4, 0.4, 1.0); //a_color * u_shade_factor; - v_color.a = 1.0; + + switch (u_layer_view_type) { + case 0: // "Line type" + v_color = a_color; + break; + case 1: // "Material color" + v_color = a_material_color; + break; + case 2: // "Speed" + v_color = a_color; + break; + } + if (u_only_color_active_extruder == 1) { + v_color = (a_extruder == u_active_extruder) ? v_color : vec4(0.4, 0.4, 0.4, 1.0); + } else { + v_color = (a_extruder == u_active_extruder) ? v_color : v_color * u_shade_factor; + } + if (a_extruder < 4) { + v_color.a *= u_extruder_opacity[a_extruder]; // make it (in)visible + } v_vertex = world_space_vert.xyz; v_normal = (u_normalMatrix * normalize(a_normal)).xyz; v_line_dim = a_line_dim; + v_extruder = a_extruder; + //v_material_color = a_material_color; // for testing without geometry shader f_color = v_color; f_vertex = v_vertex; f_normal = v_normal; + f_extruder = v_extruder; } geometry = @@ -57,10 +87,14 @@ geometry = in vec3 v_vertex[]; in vec3 v_normal[]; in vec2 v_line_dim[]; + in int v_extruder[]; + //in vec4 v_material_color[]; out vec4 f_color; out vec3 f_normal; out vec3 f_vertex; + out uint f_extruder; + //out vec4 f_material_color; void main() { @@ -75,6 +109,9 @@ geometry = float size_x = v_line_dim[0].x / 2 + 0.01; // radius, and make it nicely overlapping float size_y = v_line_dim[0].y / 2 + 0.01; + f_extruder = v_extruder[0]; + //f_material_color = v_material_color[0]; + //g_vertex_normal_horz = normalize(v_normal[0]); //vec3(g_vertex_delta.z, g_vertex_delta.y, -g_vertex_delta.x); g_vertex_delta = gl_in[1].gl_Position - gl_in[0].gl_Position; g_vertex_normal_horz_head = normalize(vec3(-g_vertex_delta.x, -g_vertex_delta.y, -g_vertex_delta.z)); @@ -241,41 +278,19 @@ geometry = fragment = varying lowp vec4 f_color; + //varying lowp vec4 f_material_color; varying lowp vec3 f_normal; varying lowp vec3 f_vertex; + //flat varying lowp uint f_extruder; uniform mediump vec4 u_ambientColor; - uniform mediump vec4 u_diffuseColor; - //uniform mediump vec4 u_specularColor; - //uniform mediump float u_shininess; - uniform highp vec3 u_lightPosition; - void Impostor(in float sphereRadius, in vec3 cameraSpherePos, in vec2 mapping, out vec3 cameraPos, out vec3 cameraNormal) - { - float lensqr = dot(mapping, mapping); - if(lensqr > 1.0) - discard; - - cameraNormal = vec3(mapping, sqrt(1.0 - lensqr)); - cameraPos = (cameraNormal * sphereRadius) + cameraSpherePos; - } - void main() { - vec3 cameraPos; - vec3 cameraNormal; - - //Impostor(0.2, vec3(0.0, 0.0, 0.0), vec2(0.1, 0.1), cameraPos, cameraNormal); - - //gl_FrontFacing = .. - - //if ((f_normal).z < 0) {discard; } - mediump vec4 finalColor = vec4(0.0); finalColor += u_ambientColor; - //finalColor = f_color; highp vec3 normal = normalize(f_normal); highp vec3 lightDir = normalize(u_lightPosition - f_vertex); @@ -283,23 +298,19 @@ fragment = // Diffuse Component highp float NdotL = clamp(dot(normal, lightDir), 0.0, 1.0); finalColor += (NdotL * f_color); + //finalColor += (NdotL * f_material_color); + //finalColor.a = 1.0; - // Specular Component - // TODO: We should not do specularity for fragments facing away from the light. - /*highp vec3 reflectedLight = reflect(-lightDir, normal); - highp vec3 viewVector = normalize(u_viewPosition - f_vertex); - highp float NdotR = clamp(dot(viewVector, reflectedLight), 0.0, 1.0); - finalColor += pow(NdotR, u_shininess) * u_specularColor;*/ - - finalColor.a = 1.0; gl_FragColor = finalColor; - - //gl_FragColor = f_color; - //gl_FragColor = vec4(f_normal, 1.0); } + [defaults] u_active_extruder = 0.0 +u_layer_view_type = 0 +u_only_color_active_extruder = 1 +u_extruder_opacity = [1.0, 1.0] + u_shade_factor = 0.60 u_specularColor = [0.4, 0.4, 0.4, 1.0] u_ambientColor = [0.3, 0.3, 0.3, 0.3] @@ -318,3 +329,5 @@ a_vertex = vertex a_color = color a_normal = normal a_line_dim = line_dim +a_extruder = extruders +a_material_color = material_color From fc4c60b0dcfe8198831915ebf2d1de2dda653dfb Mon Sep 17 00:00:00 2001 From: Jack Ha Date: Fri, 30 Dec 2016 14:31:53 +0100 Subject: [PATCH 14/54] Added layer view options --- cura/Layer.py | 4 +- cura/LayerDataBuilder.py | 12 +++++- cura/LayerPolygon.py | 11 ++++-- plugins/LayerView/LayerPass.py | 28 +++++++++----- plugins/LayerView/LayerView.py | 34 +++++++++++++++++ plugins/LayerView/LayerView.qml | 18 +++++---- plugins/LayerView/LayerViewProxy.py | 25 ++++++++++++ plugins/LayerView/layers.shader | 59 ++++++++++++++++------------- resources/shaders/overhang.shader | 42 ++------------------ 9 files changed, 143 insertions(+), 90 deletions(-) diff --git a/cura/Layer.py b/cura/Layer.py index 8d35e9c6b2..869b84ed90 100644 --- a/cura/Layer.py +++ b/cura/Layer.py @@ -49,12 +49,12 @@ class Layer: return result - def build(self, vertex_offset, index_offset, vertices, colors, line_dimensions, extruders, indices): + def build(self, vertex_offset, index_offset, vertices, colors, line_dimensions, extruders, line_types, indices): result_vertex_offset = vertex_offset result_index_offset = index_offset self._element_count = 0 for polygon in self._polygons: - polygon.build(result_vertex_offset, result_index_offset, vertices, colors, line_dimensions, extruders, indices) + polygon.build(result_vertex_offset, result_index_offset, vertices, colors, line_dimensions, extruders, line_types, indices) result_vertex_offset += polygon.lineMeshVertexCount() result_index_offset += polygon.lineMeshElementCount() self._element_count += polygon.elementCount diff --git a/cura/LayerDataBuilder.py b/cura/LayerDataBuilder.py index 2b46a604b7..6750b60d53 100644 --- a/cura/LayerDataBuilder.py +++ b/cura/LayerDataBuilder.py @@ -60,12 +60,13 @@ class LayerDataBuilder(MeshBuilder): line_dimensions = numpy.empty((vertex_count, 2), numpy.float32) colors = numpy.empty((vertex_count, 4), numpy.float32) indices = numpy.empty((index_count, 2), numpy.int32) - extruders = numpy.empty((vertex_count), numpy.float32) + extruders = numpy.empty((vertex_count), numpy.int32) + line_types = numpy.empty((vertex_count), numpy.int32) vertex_offset = 0 index_offset = 0 for layer, data in self._layers.items(): - ( vertex_offset, index_offset ) = data.build( vertex_offset, index_offset, vertices, colors, line_dimensions, extruders, indices) + ( vertex_offset, index_offset ) = data.build( vertex_offset, index_offset, vertices, colors, line_dimensions, extruders, line_types, indices) self._element_counts[layer] = data.elementCount self.addVertices(vertices) @@ -75,6 +76,8 @@ class LayerDataBuilder(MeshBuilder): material_colors = numpy.zeros((line_dimensions.shape[0], 4), dtype=numpy.float32) for extruder_nr in range(material_color_map.shape[0]): material_colors[extruders == extruder_nr] = material_color_map[extruder_nr] + material_colors[line_types == LayerPolygon.MoveCombingType] = [0.0, 0.0, 0.8, 1.0] + material_colors[line_types == LayerPolygon.MoveRetractionType] = [0.0, 0.0, 0.8, 1.0] attributes = { "line_dimensions": { @@ -92,6 +95,11 @@ class LayerDataBuilder(MeshBuilder): "opengl_name": "a_material_color", "opengl_type": "vector4f" }, + "line_types": { + "value": line_types, + "opengl_name": "a_line_type", + "opengl_type": "float" + } } return LayerData(vertices=self.getVertices(), normals=self.getNormals(), indices=self.getIndices(), diff --git a/cura/LayerPolygon.py b/cura/LayerPolygon.py index bb37d641bb..f7acc62286 100644 --- a/cura/LayerPolygon.py +++ b/cura/LayerPolygon.py @@ -51,7 +51,7 @@ class LayerPolygon: def buildCache(self): # For the line mesh we do not draw Infill or Jumps. Therefore those lines are filtered out. # self._build_cache_line_mesh_mask = numpy.logical_not(numpy.logical_or(self._jump_mask, self._types == LayerPolygon.InfillType )) - self._build_cache_line_mesh_mask = numpy.logical_not(self._jump_mask) + self._build_cache_line_mesh_mask = numpy.ones(self._jump_mask.shape, dtype=bool) # numpy.logical_not(self._jump_mask) mesh_line_count = numpy.sum(self._build_cache_line_mesh_mask) self._index_begin = 0 self._index_end = mesh_line_count @@ -60,14 +60,14 @@ class LayerPolygon: # Only if the type of line segment changes do we need to add an extra vertex to change colors self._build_cache_needed_points[1:, 0][:, numpy.newaxis] = self._types[1:] != self._types[:-1] # Mark points as unneeded if they are of types we don't want in the line mesh according to the calculated mask - numpy.logical_and(self._build_cache_needed_points, self._build_cache_line_mesh_mask, self._build_cache_needed_points ) + numpy.logical_and(self._build_cache_needed_points, self._build_cache_line_mesh_mask ) self._vertex_begin = 0 self._vertex_end = numpy.sum( self._build_cache_needed_points ) ## build # line_thicknesses: array with type as index and thickness as value - def build(self, vertex_offset, index_offset, vertices, colors, line_dimensions, extruders, indices): + def build(self, vertex_offset, index_offset, vertices, colors, line_dimensions, extruders, line_types, indices): if (self._build_cache_line_mesh_mask is None) or (self._build_cache_needed_points is None ): self.buildCache() @@ -94,7 +94,10 @@ class LayerPolygon: line_dimensions[self._vertex_begin:self._vertex_end, 0] = numpy.tile(self._line_widths, (1, 2)).reshape((-1, 1))[needed_points_list.ravel()][:, 0] line_dimensions[self._vertex_begin:self._vertex_end, 1] = numpy.tile(self._line_thicknesses, (1, 2)).reshape((-1, 1))[needed_points_list.ravel()][:, 0] - extruders[self._vertex_begin:self._vertex_end] = float(self._extruder) + extruders[self._vertex_begin:self._vertex_end] = self._extruder + + # Convert type per vertex to type per line + line_types[self._vertex_begin:self._vertex_end] = numpy.tile(self._types, (1, 2)).reshape((-1, 1))[needed_points_list.ravel()][:, 0] # The relative values of begin and end indices have already been set in buildCache, so we only need to offset them to the parents offset. self._index_begin += index_offset diff --git a/plugins/LayerView/LayerPass.py b/plugins/LayerView/LayerPass.py index dda35624ec..545abd04f2 100644 --- a/plugins/LayerView/LayerPass.py +++ b/plugins/LayerView/LayerPass.py @@ -30,16 +30,24 @@ class LayerPass(RenderPass): self._layer_view = None def setLayerView(self, layerview): - self._layerview = layerview + self._layer_view = layerview def render(self): if not self._layer_shader: self._layer_shader = OpenGL.getInstance().createShaderProgram(os.path.join(PluginRegistry.getInstance().getPluginPath("LayerView"), "layers.shader")) # Use extruder 0 if the extruder manager reports extruder index -1 (for single extrusion printers) self._layer_shader.setUniformValue("u_active_extruder", float(max(0, self._extruder_manager.activeExtruderIndex))) - self._layer_shader.setUniformValue("u_layer_view_type", 0) - self._layer_shader.setUniformValue("u_only_color_active_extruder", 1) - self._layer_shader.setUniformValue("u_extruder_opacity", [1, 1, 1, 1]) + if self._layer_view: + self._layer_shader.setUniformValue("u_layer_view_type", self._layer_view.getLayerViewType()) + self._layer_shader.setUniformValue("u_only_color_active_extruder", (1 if self._layer_view.getOnlyColorActiveExtruder() else 0)) + self._layer_shader.setUniformValue("u_extruder_opacity", self._layer_view.getExtruderOpacities()) + self._layer_shader.setUniformValue("u_show_travel_moves", self._layer_view.getShowTravelMoves()) + else: + #defaults + self._layer_shader.setUniformValue("u_layer_view_type", 1) + self._layer_shader.setUniformValue("u_only_color_active_extruder", 1) + self._layer_shader.setUniformValue("u_extruder_opacity", [1, 1, 1, 1]) + self._layer_shader.setUniformValue("u_show_travel_moves", 0) if not self._tool_handle_shader: self._tool_handle_shader = OpenGL.getInstance().createShaderProgram(Resources.getPath(Resources.Shaders, "toolhandle.shader")) @@ -58,12 +66,12 @@ class LayerPass(RenderPass): continue # Render all layers below a certain number as line mesh instead of vertices. - if self._layerview._current_layer_num > -1 and not self._layerview._only_show_top_layers: + if self._layer_view._current_layer_num > -1 and not self._layer_view._only_show_top_layers: start = 0 end = 0 element_counts = layer_data.getElementCounts() for layer, counts in element_counts.items(): - if layer > self._layerview._current_layer_num: + if layer > self._layer_view._current_layer_num: break end += counts @@ -75,11 +83,11 @@ class LayerPass(RenderPass): # Create a new batch that is not range-limited batch = RenderBatch(self._layer_shader, type = RenderBatch.RenderType.Solid) - if self._layerview._current_layer_mesh: - batch.addItem(node.getWorldTransformation(), self._layerview._current_layer_mesh) + if self._layer_view._current_layer_mesh: + batch.addItem(node.getWorldTransformation(), self._layer_view._current_layer_mesh) - if self._layerview._current_layer_jumps: - batch.addItem(node.getWorldTransformation(), self._layerview._current_layer_jumps) + if self._layer_view._current_layer_jumps: + batch.addItem(node.getWorldTransformation(), self._layer_view._current_layer_jumps) if len(batch.items) > 0: batch.render(self._scene.getActiveCamera()) diff --git a/plugins/LayerView/LayerView.py b/plugins/LayerView/LayerView.py index 50c13194f7..16dced8a6e 100644 --- a/plugins/LayerView/LayerView.py +++ b/plugins/LayerView/LayerView.py @@ -60,8 +60,14 @@ class LayerView(View): self._proxy = LayerViewProxy.LayerViewProxy() self._controller.getScene().getRoot().childrenChanged.connect(self._onSceneChanged) + self._layer_view_type = 0 # 0 is material color, 1 is color by linetype, 2 is speed + self._only_color_active_extruder = True + self._extruder_opacity = [1.0, 1.0, 1.0, 1.0] + self._show_travel_moves = 0 + Preferences.getInstance().addPreference("view/top_layer_count", 5) Preferences.getInstance().addPreference("view/only_show_top_layers", False) + Preferences.getInstance().preferenceChanged.connect(self._onPreferencesChanged) self._solid_layers = int(Preferences.getInstance().getValue("view/top_layer_count")) @@ -134,6 +140,34 @@ class LayerView(View): self.currentLayerNumChanged.emit() + def setLayerViewType(self, layer_view_type): + self._layer_view_type = layer_view_type + self.currentLayerNumChanged.emit() + + def getLayerViewType(self): + return self._layer_view_type + + def setOnlyColorActiveExtruder(self, only_color_active_extruder): + self._only_color_active_extruder = only_color_active_extruder + self.currentLayerNumChanged.emit() + + def getOnlyColorActiveExtruder(self): + return self._only_color_active_extruder + + def setExtruderOpacity(self, extruder_nr, opacity): + self._extruder_opacity[extruder_nr] = opacity + self.currentLayerNumChanged.emit() + + def getExtruderOpacities(self): + return self._extruder_opacity + + def setShowTravelMoves(self, show): + self._show_travel_moves = show + self.currentLayerNumChanged.emit() + + def getShowTravelMoves(self): + return self._show_travel_moves + def calculateMaxLayers(self): scene = self.getController().getScene() self._activity = True diff --git a/plugins/LayerView/LayerView.qml b/plugins/LayerView/LayerView.qml index 68c51e5752..500e0d12c1 100644 --- a/plugins/LayerView/LayerView.qml +++ b/plugins/LayerView/LayerView.qml @@ -129,12 +129,12 @@ Item { id: layerViewTypes ListElement { - text: "Line type" - type_id: 0 // these ids match the switching in the shader + text: "Material color" + type_id: 0 } ListElement { - text: "Material color" - type_id: 1 + text: "Line type" + type_id: 1 // these ids match the switching in the shader } ListElement { text: "Printing speed" @@ -150,6 +150,7 @@ Item onActivated: { CuraApplication.log("Combobox" + String(index)); CuraApplication.log(layerViewTypes.get(index).type_id); + UM.LayerView.setLayerViewType(layerViewTypes.get(index).type_id); } } @@ -158,27 +159,28 @@ Item CheckBox { checked: true onClicked: { - CuraApplication.log("First"); + UM.LayerView.setExtruderOpacity(0, checked ? 1.0 : 0.0); } text: "Extruder 1" } CheckBox { checked: true onClicked: { - CuraApplication.log("First"); + UM.LayerView.setExtruderOpacity(1, checked ? 1.0 : 0.0); } text: "Extruder 2" } CheckBox { onClicked: { - CuraApplication.log("First"); + UM.LayerView.setShowTravelMoves(checked ? 1 : 0); } text: "Travel moves" } CheckBox { checked: true onClicked: { - CuraApplication.log("First"); + CuraApplication.log("First" + checked); + UM.LayerView.setOnlyColorActiveExtruder(checked); } text: "Only color active extruder" } diff --git a/plugins/LayerView/LayerViewProxy.py b/plugins/LayerView/LayerViewProxy.py index e9319ef6e1..5555f7358a 100644 --- a/plugins/LayerView/LayerViewProxy.py +++ b/plugins/LayerView/LayerViewProxy.py @@ -50,6 +50,31 @@ class LayerViewProxy(QObject): if type(active_view) == LayerView.LayerView.LayerView: active_view.setLayer(layer_num) + @pyqtSlot(int) + def setLayerViewType(self, layer_view_type): + active_view = self._controller.getActiveView() + if type(active_view) == LayerView.LayerView.LayerView: + active_view.setLayerViewType(layer_view_type) + + @pyqtSlot(bool) + def setOnlyColorActiveExtruder(self, only_color_active_extruder): + active_view = self._controller.getActiveView() + if type(active_view) == LayerView.LayerView.LayerView: + active_view.setOnlyColorActiveExtruder(only_color_active_extruder) + + # Opacity 0..1 + @pyqtSlot(int, float) + def setExtruderOpacity(self, extruder_nr, opacity): + active_view = self._controller.getActiveView() + if type(active_view) == LayerView.LayerView.LayerView: + active_view.setExtruderOpacity(extruder_nr, opacity) + + @pyqtSlot(bool) + def setShowTravelMoves(self, show): + active_view = self._controller.getActiveView() + if type(active_view) == LayerView.LayerView.LayerView: + active_view.setShowTravelMoves(show) + def _layerActivityChanged(self): self.activityChanged.emit() diff --git a/plugins/LayerView/layers.shader b/plugins/LayerView/layers.shader index 869230e87d..c086aa3575 100644 --- a/plugins/LayerView/layers.shader +++ b/plugins/LayerView/layers.shader @@ -17,6 +17,7 @@ vertex = attribute highp vec4 a_normal; attribute highp vec2 a_line_dim; // line width and thickness attribute highp int a_extruder; + attribute highp int a_line_type; varying lowp vec4 v_color; //varying lowp vec4 v_material_color; @@ -26,6 +27,7 @@ vertex = //varying lowp vec2 v_uvs; varying lowp vec2 v_line_dim; varying highp int v_extruder; + varying int v_line_type; varying lowp vec4 f_color; varying highp vec3 f_vertex; @@ -44,19 +46,19 @@ vertex = switch (u_layer_view_type) { case 0: // "Line type" - v_color = a_color; + v_color = a_material_color; break; case 1: // "Material color" - v_color = a_material_color; + v_color = a_color; break; case 2: // "Speed" v_color = a_color; break; } if (u_only_color_active_extruder == 1) { - v_color = (a_extruder == u_active_extruder) ? v_color : vec4(0.4, 0.4, 0.4, 1.0); + v_color = (a_extruder == u_active_extruder) ? v_color : vec4(0.4, 0.4, 0.4, v_color.a); } else { - v_color = (a_extruder == u_active_extruder) ? v_color : v_color * u_shade_factor; + v_color = (a_extruder == u_active_extruder) ? v_color : vec4((v_color * u_shade_factor).rgb, v_color.a); } if (a_extruder < 4) { v_color.a *= u_extruder_opacity[a_extruder]; // make it (in)visible @@ -66,19 +68,20 @@ vertex = v_normal = (u_normalMatrix * normalize(a_normal)).xyz; v_line_dim = a_line_dim; v_extruder = a_extruder; - //v_material_color = a_material_color; + v_line_type = a_line_type; // for testing without geometry shader - f_color = v_color; + /*f_color = v_color; f_vertex = v_vertex; f_normal = v_normal; - f_extruder = v_extruder; + f_extruder = v_extruder; */ } geometry = #version 410 uniform highp mat4 u_viewProjectionMatrix; + uniform int u_show_travel_moves; layout(lines) in; layout(triangle_strip, max_vertices = 26) out; @@ -88,7 +91,7 @@ geometry = in vec3 v_normal[]; in vec2 v_line_dim[]; in int v_extruder[]; - //in vec4 v_material_color[]; + in int v_line_type[]; out vec4 f_color; out vec3 f_normal; @@ -106,13 +109,24 @@ geometry = vec3 g_vertex_normal_horz_head; vec4 g_vertex_offset_horz_head; - float size_x = v_line_dim[0].x / 2 + 0.01; // radius, and make it nicely overlapping - float size_y = v_line_dim[0].y / 2 + 0.01; + float size_x; + float size_y; + + // See LayerPolygon; 8 is MoveCombingType, 9 is RetractionType + if (((v_line_type[0] == 8) || (v_line_type[0] == 9)) && (u_show_travel_moves == 0)) { + return; + } + if ((v_line_type[0] == 8) || (v_line_type[0] == 9)) { + // fixed size for movements + size_x = 0.1; + size_y = 0.1; + } else { + size_x = v_line_dim[0].x / 2 + 0.01; // radius, and make it nicely overlapping + size_y = v_line_dim[0].y / 2 + 0.01; + } f_extruder = v_extruder[0]; - //f_material_color = v_material_color[0]; - //g_vertex_normal_horz = normalize(v_normal[0]); //vec3(g_vertex_delta.z, g_vertex_delta.y, -g_vertex_delta.x); g_vertex_delta = gl_in[1].gl_Position - gl_in[0].gl_Position; g_vertex_normal_horz_head = normalize(vec3(-g_vertex_delta.x, -g_vertex_delta.y, -g_vertex_delta.z)); g_vertex_offset_horz_head = vec4(g_vertex_normal_horz_head * size_x, 0.0); @@ -125,28 +139,24 @@ geometry = f_vertex = v_vertex[0]; f_color = v_color[0]; - //f_color = vec4(v_uvs[0], 0.0, 1.0); f_normal = g_vertex_normal_horz; gl_Position = u_viewProjectionMatrix * (gl_in[0].gl_Position + g_vertex_offset_horz); EmitVertex(); f_vertex = v_vertex[1]; f_color = v_color[1]; - //f_color = vec4(v_uvs[0], 0.0, 1.0); f_normal = g_vertex_normal_horz; gl_Position = u_viewProjectionMatrix * (gl_in[1].gl_Position + g_vertex_offset_horz); EmitVertex(); f_vertex = v_vertex[0]; f_color = v_color[0]; - //f_color = vec4(v_uvs[0], 0.0, 1.0); f_normal = g_vertex_normal_vert; gl_Position = u_viewProjectionMatrix * (gl_in[0].gl_Position + g_vertex_offset_vert); EmitVertex(); f_vertex = v_vertex[1]; f_color = v_color[1]; - //f_color = vec4(v_uvs[0], 0.0, 1.0); f_normal = g_vertex_normal_vert; gl_Position = u_viewProjectionMatrix * (gl_in[1].gl_Position + g_vertex_offset_vert); EmitVertex(); @@ -154,27 +164,23 @@ geometry = f_vertex = v_vertex[0]; f_normal = -g_vertex_normal_horz; f_color = v_color[0]; - //f_color = vec4(v_uvs[0], 0.0, 1.0); gl_Position = u_viewProjectionMatrix * (gl_in[0].gl_Position - g_vertex_offset_horz); EmitVertex(); f_vertex = v_vertex[1]; f_color = v_color[1]; - //f_color = vec4(v_uvs[0], 0.0, 1.0); f_normal = -g_vertex_normal_horz; gl_Position = u_viewProjectionMatrix * (gl_in[1].gl_Position - g_vertex_offset_horz); EmitVertex(); f_vertex = v_vertex[0]; f_color = v_color[0]; - //f_color = vec4(v_uvs[0], 0.0, 1.0); f_normal = -g_vertex_normal_vert; gl_Position = u_viewProjectionMatrix * (gl_in[0].gl_Position - g_vertex_offset_vert); EmitVertex(); f_vertex = v_vertex[1]; f_color = v_color[1]; - //f_color = vec4(v_uvs[0], 0.0, 1.0); f_normal = -g_vertex_normal_vert; gl_Position = u_viewProjectionMatrix * (gl_in[1].gl_Position - g_vertex_offset_vert); EmitVertex(); @@ -182,13 +188,11 @@ geometry = f_vertex = v_vertex[0]; f_normal = g_vertex_normal_horz; f_color = v_color[0]; - //f_color = vec4(v_uvs[0], 0.0, 1.0); gl_Position = u_viewProjectionMatrix * (gl_in[0].gl_Position + g_vertex_offset_horz); EmitVertex(); f_vertex = v_vertex[1]; f_color = v_color[1]; - //f_color = vec4(v_uvs[0], 0.0, 1.0); f_normal = g_vertex_normal_horz; gl_Position = u_viewProjectionMatrix * (gl_in[1].gl_Position + g_vertex_offset_horz); EmitVertex(); @@ -289,8 +293,9 @@ fragment = void main() { mediump vec4 finalColor = vec4(0.0); + float alpha = f_color.a; - finalColor += u_ambientColor; + finalColor.rgb += f_color.rgb * 0.3; highp vec3 normal = normalize(f_normal); highp vec3 lightDir = normalize(u_lightPosition - f_vertex); @@ -298,8 +303,7 @@ fragment = // Diffuse Component highp float NdotL = clamp(dot(normal, lightDir), 0.0, 1.0); finalColor += (NdotL * f_color); - //finalColor += (NdotL * f_material_color); - //finalColor.a = 1.0; + finalColor.a = alpha; // Do not change alpha in any way gl_FragColor = finalColor; } @@ -313,10 +317,12 @@ u_extruder_opacity = [1.0, 1.0] u_shade_factor = 0.60 u_specularColor = [0.4, 0.4, 0.4, 1.0] -u_ambientColor = [0.3, 0.3, 0.3, 0.3] +u_ambientColor = [0.3, 0.3, 0.3, 0.0] u_diffuseColor = [1.0, 0.79, 0.14, 1.0] u_shininess = 20.0 +u_show_travel_moves = 0 + [bindings] u_modelViewProjectionMatrix = model_view_projection_matrix u_modelMatrix = model_matrix @@ -331,3 +337,4 @@ a_normal = normal a_line_dim = line_dim a_extruder = extruders a_material_color = material_color +a_line_type = line_type diff --git a/resources/shaders/overhang.shader b/resources/shaders/overhang.shader index 0e8592f675..4e5999a693 100644 --- a/resources/shaders/overhang.shader +++ b/resources/shaders/overhang.shader @@ -8,50 +8,16 @@ vertex = attribute highp vec4 a_normal; attribute highp vec2 a_uvs; - varying highp vec3 v_vertex; - varying highp vec3 v_normal; + varying highp vec3 f_vertex; + varying highp vec3 f_normal; void main() { vec4 world_space_vert = u_modelMatrix * a_vertex; gl_Position = u_viewProjectionMatrix * world_space_vert; - v_vertex = world_space_vert.xyz; - v_normal = (u_normalMatrix * normalize(a_normal)).xyz; - } - -geometry = - #version 410 - - layout(triangles) in; - layout(triangle_strip, max_vertices = 6) out; - - in vec3 v_normal[]; - in vec3 v_vertex[]; - - out vec3 f_normal; - out vec3 f_vertex; - - void main() - { - int i; - for(i = 0; i < 3; i++) - { - f_normal = v_normal[i]; - f_vertex = v_vertex[i]; - gl_Position = gl_in[i].gl_Position + vec4(-50, 0.0, 0.0, 0.0); - EmitVertex(); - } - EndPrimitive(); - - for(i = 0; i < 3; i++) - { - f_normal = v_normal[i]; - f_vertex = v_vertex[i]; - gl_Position = gl_in[i].gl_Position + vec4(50, 0.0, 0.0, 0.0); - EmitVertex(); - } - EndPrimitive(); + f_vertex = world_space_vert.xyz; + f_normal = (u_normalMatrix * normalize(a_normal)).xyz; } fragment = From 6271774528688a5fb0af46a39eefd4586a238136 Mon Sep 17 00:00:00 2001 From: Jack Ha Date: Fri, 30 Dec 2016 15:32:06 +0100 Subject: [PATCH 15/54] Added all kinds of options to layer view --- cura/LayerDataBuilder.py | 4 +- cura/LayerPolygon.py | 1 - .../ProcessSlicedLayersJob.py | 1 + plugins/LayerView/LayerPass.py | 8 ++++ plugins/LayerView/LayerView.py | 32 ++++++++++++++++ plugins/LayerView/LayerView.qml | 38 +++++++++++++++---- plugins/LayerView/LayerViewProxy.py | 26 ++++++++++++- plugins/LayerView/layers.shader | 34 ++++++++++++----- 8 files changed, 122 insertions(+), 22 deletions(-) diff --git a/cura/LayerDataBuilder.py b/cura/LayerDataBuilder.py index 6750b60d53..72dac319cd 100644 --- a/cura/LayerDataBuilder.py +++ b/cura/LayerDataBuilder.py @@ -76,8 +76,8 @@ class LayerDataBuilder(MeshBuilder): material_colors = numpy.zeros((line_dimensions.shape[0], 4), dtype=numpy.float32) for extruder_nr in range(material_color_map.shape[0]): material_colors[extruders == extruder_nr] = material_color_map[extruder_nr] - material_colors[line_types == LayerPolygon.MoveCombingType] = [0.0, 0.0, 0.8, 1.0] - material_colors[line_types == LayerPolygon.MoveRetractionType] = [0.0, 0.0, 0.8, 1.0] + material_colors[line_types == LayerPolygon.MoveCombingType] = colors[line_types == LayerPolygon.MoveCombingType] + material_colors[line_types == LayerPolygon.MoveRetractionType] = colors[line_types == LayerPolygon.MoveRetractionType] attributes = { "line_dimensions": { diff --git a/cura/LayerPolygon.py b/cura/LayerPolygon.py index f7acc62286..4509ba7d26 100644 --- a/cura/LayerPolygon.py +++ b/cura/LayerPolygon.py @@ -88,7 +88,6 @@ class LayerPolygon: # Create an array with colors for each vertex and remove the color data for the points that has been thrown away. colors[self._vertex_begin:self._vertex_end, :] = numpy.tile(self._colors, (1, 2)).reshape((-1, 4))[needed_points_list.ravel()] - colors[self._vertex_begin:self._vertex_end, :] *= numpy.array([[0.5, 0.5, 0.5, 1.0]], numpy.float32) # Create an array with line widths for each vertex. line_dimensions[self._vertex_begin:self._vertex_end, 0] = numpy.tile(self._line_widths, (1, 2)).reshape((-1, 1))[needed_points_list.ravel()][:, 0] diff --git a/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py b/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py index d7be0f1a52..70398ff867 100644 --- a/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py +++ b/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py @@ -105,6 +105,7 @@ class ProcessSlicedLayersJob(Job): polygon = layer.getRepeatedMessage("path_segment", p) extruder = polygon.extruder + x = dir(polygon) line_types = numpy.fromstring(polygon.line_type, dtype="u1") # Convert bytearray to numpy array line_types = line_types.reshape((-1,1)) diff --git a/plugins/LayerView/LayerPass.py b/plugins/LayerView/LayerPass.py index 545abd04f2..2ff4b14ec6 100644 --- a/plugins/LayerView/LayerPass.py +++ b/plugins/LayerView/LayerPass.py @@ -42,12 +42,20 @@ class LayerPass(RenderPass): self._layer_shader.setUniformValue("u_only_color_active_extruder", (1 if self._layer_view.getOnlyColorActiveExtruder() else 0)) self._layer_shader.setUniformValue("u_extruder_opacity", self._layer_view.getExtruderOpacities()) self._layer_shader.setUniformValue("u_show_travel_moves", self._layer_view.getShowTravelMoves()) + self._layer_shader.setUniformValue("u_show_support", self._layer_view.getShowSupport()) + self._layer_shader.setUniformValue("u_show_adhesion", self._layer_view.getShowAdhesion()) + self._layer_shader.setUniformValue("u_show_skin", self._layer_view.getShowSkin()) + self._layer_shader.setUniformValue("u_show_infill", self._layer_view.getShowInfill()) else: #defaults self._layer_shader.setUniformValue("u_layer_view_type", 1) self._layer_shader.setUniformValue("u_only_color_active_extruder", 1) self._layer_shader.setUniformValue("u_extruder_opacity", [1, 1, 1, 1]) self._layer_shader.setUniformValue("u_show_travel_moves", 0) + self._layer_shader.setUniformValue("u_show_support", 1) + self._layer_shader.setUniformValue("u_show_adhesion", 1) + self._layer_shader.setUniformValue("u_show_skin", 1) + self._layer_shader.setUniformValue("u_show_infill", 1) if not self._tool_handle_shader: self._tool_handle_shader = OpenGL.getInstance().createShaderProgram(Resources.getPath(Resources.Shaders, "toolhandle.shader")) diff --git a/plugins/LayerView/LayerView.py b/plugins/LayerView/LayerView.py index 16dced8a6e..a1e48ee3a6 100644 --- a/plugins/LayerView/LayerView.py +++ b/plugins/LayerView/LayerView.py @@ -64,6 +64,10 @@ class LayerView(View): self._only_color_active_extruder = True self._extruder_opacity = [1.0, 1.0, 1.0, 1.0] self._show_travel_moves = 0 + self._show_support = 1 + self._show_adhesion = 1 + self._show_skin = 1 + self._show_infill = 1 Preferences.getInstance().addPreference("view/top_layer_count", 5) Preferences.getInstance().addPreference("view/only_show_top_layers", False) @@ -168,6 +172,34 @@ class LayerView(View): def getShowTravelMoves(self): return self._show_travel_moves + def setShowSupport(self, show): + self._show_support = show + self.currentLayerNumChanged.emit() + + def getShowSupport(self): + return self._show_support + + def setShowAdhesion(self, show): + self._show_adhesion = show + self.currentLayerNumChanged.emit() + + def getShowAdhesion(self): + return self._show_adhesion + + def setShowSkin(self, show): + self._show_skin = show + self.currentLayerNumChanged.emit() + + def getShowSkin(self): + return self._show_skin + + def setShowInfill(self, show): + self._show_infill = show + self.currentLayerNumChanged.emit() + + def getShowInfill(self): + return self._show_infill + def calculateMaxLayers(self): scene = self.getController().getScene() self._activity = True diff --git a/plugins/LayerView/LayerView.qml b/plugins/LayerView/LayerView.qml index 500e0d12c1..ad02aade19 100644 --- a/plugins/LayerView/LayerView.qml +++ b/plugins/LayerView/LayerView.qml @@ -136,20 +136,15 @@ Item text: "Line type" type_id: 1 // these ids match the switching in the shader } - ListElement { - text: "Printing speed" - type_id: 2 - } } ComboBox { id: layer_type_combobox anchors.top: slider_background.bottom + anchors.left: parent.left model: layerViewTypes onActivated: { - CuraApplication.log("Combobox" + String(index)); - CuraApplication.log(layerViewTypes.get(index).type_id); UM.LayerView.setLayerViewType(layerViewTypes.get(index).type_id); } } @@ -174,12 +169,39 @@ Item onClicked: { UM.LayerView.setShowTravelMoves(checked ? 1 : 0); } - text: "Travel moves" + text: "Show travel moves" + } + CheckBox { + checked: true + onClicked: { + UM.LayerView.setShowSupport(checked ? 1 : 0); + } + text: "Show support" + } + CheckBox { + checked: true + onClicked: { + UM.LayerView.setShowAdhesion(checked ? 1 : 0); + } + text: "Show adhesion" + } + CheckBox { + checked: true + onClicked: { + UM.LayerView.setShowSkin(checked ? 1 : 0); + } + text: "Show skin" + } + CheckBox { + checked: true + onClicked: { + UM.LayerView.setShowInfill(checked ? 1 : 0); + } + text: "Show infill" } CheckBox { checked: true onClicked: { - CuraApplication.log("First" + checked); UM.LayerView.setOnlyColorActiveExtruder(checked); } text: "Only color active extruder" diff --git a/plugins/LayerView/LayerViewProxy.py b/plugins/LayerView/LayerViewProxy.py index 5555f7358a..c7a0d4a918 100644 --- a/plugins/LayerView/LayerViewProxy.py +++ b/plugins/LayerView/LayerViewProxy.py @@ -69,12 +69,36 @@ class LayerViewProxy(QObject): if type(active_view) == LayerView.LayerView.LayerView: active_view.setExtruderOpacity(extruder_nr, opacity) - @pyqtSlot(bool) + @pyqtSlot(int) def setShowTravelMoves(self, show): active_view = self._controller.getActiveView() if type(active_view) == LayerView.LayerView.LayerView: active_view.setShowTravelMoves(show) + @pyqtSlot(int) + def setShowSupport(self, show): + active_view = self._controller.getActiveView() + if type(active_view) == LayerView.LayerView.LayerView: + active_view.setShowSupport(show) + + @pyqtSlot(int) + def setShowAdhesion(self, show): + active_view = self._controller.getActiveView() + if type(active_view) == LayerView.LayerView.LayerView: + active_view.setShowAdhesion(show) + + @pyqtSlot(int) + def setShowSkin(self, show): + active_view = self._controller.getActiveView() + if type(active_view) == LayerView.LayerView.LayerView: + active_view.setShowSkin(show) + + @pyqtSlot(int) + def setShowInfill(self, show): + active_view = self._controller.getActiveView() + if type(active_view) == LayerView.LayerView.LayerView: + active_view.setShowInfill(show) + def _layerActivityChanged(self): self.activityChanged.emit() diff --git a/plugins/LayerView/layers.shader b/plugins/LayerView/layers.shader index c086aa3575..a667ecc370 100644 --- a/plugins/LayerView/layers.shader +++ b/plugins/LayerView/layers.shader @@ -8,7 +8,6 @@ vertex = uniform lowp int u_only_color_active_extruder; uniform lowp vec4 u_extruder_opacity; // currently only for max 4 extruders, others always visible - uniform lowp float u_shade_factor; uniform highp mat4 u_normalMatrix; attribute highp vec4 a_vertex; @@ -45,20 +44,15 @@ vertex = // shade the color depending on the extruder index stored in the alpha component of the color switch (u_layer_view_type) { - case 0: // "Line type" + case 0: // "Material color" v_color = a_material_color; break; - case 1: // "Material color" - v_color = a_color; - break; - case 2: // "Speed" + case 1: // "Line type" v_color = a_color; break; } if (u_only_color_active_extruder == 1) { v_color = (a_extruder == u_active_extruder) ? v_color : vec4(0.4, 0.4, 0.4, v_color.a); - } else { - v_color = (a_extruder == u_active_extruder) ? v_color : vec4((v_color * u_shade_factor).rgb, v_color.a); } if (a_extruder < 4) { v_color.a *= u_extruder_opacity[a_extruder]; // make it (in)visible @@ -82,6 +76,10 @@ geometry = uniform highp mat4 u_viewProjectionMatrix; 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; layout(lines) in; layout(triangle_strip, max_vertices = 26) out; @@ -113,9 +111,22 @@ geometry = float size_y; // See LayerPolygon; 8 is MoveCombingType, 9 is RetractionType - if (((v_line_type[0] == 8) || (v_line_type[0] == 9)) && (u_show_travel_moves == 0)) { + if ((u_show_travel_moves == 0) && ((v_line_type[0] == 8) || (v_line_type[0] == 9))) { return; } + if ((u_show_support == 0) && ((v_line_type[0] == 4) || (v_line_type[0] == 7) || (v_line_type[0] == 10))) { + return; + } + if ((u_show_adhesion == 0) && (v_line_type[0] == 5)) { + return; + } + if ((u_show_skin == 0) && ((v_line_type[0] == 1) || (v_line_type[0] == 2) || (v_line_type[0] == 3))) { + return; + } + if ((u_show_infill == 0) && (v_line_type[0] == 6)) { + return; + } + if ((v_line_type[0] == 8) || (v_line_type[0] == 9)) { // fixed size for movements size_x = 0.1; @@ -315,13 +326,16 @@ u_layer_view_type = 0 u_only_color_active_extruder = 1 u_extruder_opacity = [1.0, 1.0] -u_shade_factor = 0.60 u_specularColor = [0.4, 0.4, 0.4, 1.0] u_ambientColor = [0.3, 0.3, 0.3, 0.0] u_diffuseColor = [1.0, 0.79, 0.14, 1.0] u_shininess = 20.0 u_show_travel_moves = 0 +u_show_support = 1 +u_show_adhesion = 1 +u_show_skin = 1 +u_show_infill = 1 [bindings] u_modelViewProjectionMatrix = model_view_projection_matrix From e3d77de6df0a30df96965210922ea00fa4c0bbd6 Mon Sep 17 00:00:00 2001 From: Jack Ha Date: Fri, 30 Dec 2016 15:43:32 +0100 Subject: [PATCH 16/54] Working quite well --- plugins/LayerView/layers.shader | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/plugins/LayerView/layers.shader b/plugins/LayerView/layers.shader index a667ecc370..96ef72e7fd 100644 --- a/plugins/LayerView/layers.shader +++ b/plugins/LayerView/layers.shader @@ -26,6 +26,7 @@ vertex = //varying lowp vec2 v_uvs; varying lowp vec2 v_line_dim; varying highp int v_extruder; + varying highp vec4 v_extruder_opacity; varying int v_line_type; varying lowp vec4 f_color; @@ -51,18 +52,19 @@ vertex = v_color = a_color; break; } - if (u_only_color_active_extruder == 1) { + if ((u_only_color_active_extruder == 1) && (a_line_type != 8) && (a_line_type != 9)) { v_color = (a_extruder == u_active_extruder) ? v_color : vec4(0.4, 0.4, 0.4, v_color.a); } - if (a_extruder < 4) { + /*if (a_extruder < 4) { v_color.a *= u_extruder_opacity[a_extruder]; // make it (in)visible - } + }*/ v_vertex = world_space_vert.xyz; v_normal = (u_normalMatrix * normalize(a_normal)).xyz; v_line_dim = a_line_dim; v_extruder = a_extruder; v_line_type = a_line_type; + v_extruder_opacity = u_extruder_opacity; // for testing without geometry shader /*f_color = v_color; @@ -89,6 +91,7 @@ geometry = in vec3 v_normal[]; in vec2 v_line_dim[]; in int v_extruder[]; + in vec4 v_extruder_opacity[]; in int v_line_type[]; out vec4 f_color; @@ -110,6 +113,9 @@ geometry = float size_x; float size_y; + if ((v_extruder_opacity[0][v_extruder[0]] == 0.0) && (v_line_type[0] != 8) && (v_line_type[0] != 9)) { + return; + } // See LayerPolygon; 8 is MoveCombingType, 9 is RetractionType if ((u_show_travel_moves == 0) && ((v_line_type[0] == 8) || (v_line_type[0] == 9))) { return; From 73a8859b0e46fc69a77e9e8535b03c2edc68fa81 Mon Sep 17 00:00:00 2001 From: Jack Ha Date: Mon, 2 Jan 2017 09:20:27 +0100 Subject: [PATCH 17/54] WIP second slider LayerView --- plugins/LayerView/LayerPass.py | 2 ++ plugins/LayerView/LayerView.py | 16 ++++++++++++++++ plugins/LayerView/LayerView.qml | 22 +++++++++++++++++++++- plugins/LayerView/LayerViewProxy.py | 12 ++++++++++++ 4 files changed, 51 insertions(+), 1 deletion(-) diff --git a/plugins/LayerView/LayerPass.py b/plugins/LayerView/LayerPass.py index 2ff4b14ec6..2fce95b18b 100644 --- a/plugins/LayerView/LayerPass.py +++ b/plugins/LayerView/LayerPass.py @@ -81,6 +81,8 @@ class LayerPass(RenderPass): for layer, counts in element_counts.items(): if layer > self._layer_view._current_layer_num: break + if self._layer_view._minimum_layer_num > layer: + start += counts end += counts # This uses glDrawRangeElements internally to only draw a certain range of lines. diff --git a/plugins/LayerView/LayerView.py b/plugins/LayerView/LayerView.py index a1e48ee3a6..d39fb38d58 100644 --- a/plugins/LayerView/LayerView.py +++ b/plugins/LayerView/LayerView.py @@ -41,6 +41,7 @@ class LayerView(View): self._max_layers = 0 self._current_layer_num = 0 + self._minimum_layer_num = 0 self._current_layer_mesh = None self._current_layer_jumps = None self._top_layers_job = None @@ -94,6 +95,9 @@ class LayerView(View): def getCurrentLayer(self): return self._current_layer_num + def getMinimumLayer(self): + return self._minimum_layer_num + def _onSceneChanged(self, node): self.calculateMaxLayers() @@ -144,6 +148,18 @@ class LayerView(View): self.currentLayerNumChanged.emit() + def setMinimumLayer(self, value): + if self._minimum_layer_num != value: + self._minimum_layer_num = value + if self._minimum_layer_num < 0: + self._minimum_layer_num = 0 + if self._minimum_layer_num > self._current_layer_num: + self._minimum_layer_num = self._current_layer_num + + self._startUpdateTopLayers() + + self.currentLayerNumChanged.emit() + def setLayerViewType(self, layer_view_type): self._layer_view_type = layer_view_type self.currentLayerNumChanged.emit() diff --git a/plugins/LayerView/LayerView.qml b/plugins/LayerView/LayerView.qml index ad02aade19..dd0b311c6d 100644 --- a/plugins/LayerView/LayerView.qml +++ b/plugins/LayerView/LayerView.qml @@ -13,13 +13,33 @@ Item width: UM.Theme.getSize("button").width height: UM.Theme.getSize("slider_layerview_size").height + Slider + { + id: slider2 + width: UM.Theme.getSize("slider_layerview_size").width + height: UM.Theme.getSize("slider_layerview_size").height + anchors.left: parent.left + anchors.leftMargin: UM.Theme.getSize("slider_layerview_margin").width * 0.2 + orientation: Qt.Vertical + minimumValue: 0; + maximumValue: UM.LayerView.numLayers; + stepSize: 1 + + property real pixelsPerStep: ((height - UM.Theme.getSize("slider_handle").height) / (maximumValue - minimumValue)) * stepSize; + + value: UM.LayerView.minimumLayer + onValueChanged: UM.LayerView.setMinimumLayer(value) + + style: UM.Theme.styles.slider; + } + Slider { id: slider width: UM.Theme.getSize("slider_layerview_size").width height: UM.Theme.getSize("slider_layerview_size").height anchors.left: parent.left - anchors.leftMargin: UM.Theme.getSize("slider_layerview_margin").width/2 + anchors.leftMargin: UM.Theme.getSize("slider_layerview_margin").width * 0.8 orientation: Qt.Vertical minimumValue: 0; maximumValue: UM.LayerView.numLayers; diff --git a/plugins/LayerView/LayerViewProxy.py b/plugins/LayerView/LayerViewProxy.py index c7a0d4a918..28acdce4a5 100644 --- a/plugins/LayerView/LayerViewProxy.py +++ b/plugins/LayerView/LayerViewProxy.py @@ -35,6 +35,12 @@ class LayerViewProxy(QObject): if type(active_view) == LayerView.LayerView.LayerView: return active_view.getCurrentLayer() + @pyqtProperty(int, notify = currentLayerChanged) + def minimumLayer(self): + active_view = self._controller.getActiveView() + if type(active_view) == LayerView.LayerView.LayerView: + return active_view.getMinimumLayer() + busyChanged = pyqtSignal() @pyqtProperty(bool, notify = busyChanged) def busy(self): @@ -50,6 +56,12 @@ class LayerViewProxy(QObject): if type(active_view) == LayerView.LayerView.LayerView: active_view.setLayer(layer_num) + @pyqtSlot(int) + def setMinimumLayer(self, layer_num): + active_view = self._controller.getActiveView() + if type(active_view) == LayerView.LayerView.LayerView: + active_view.setMinimumLayer(layer_num) + @pyqtSlot(int) def setLayerViewType(self, layer_view_type): active_view = self._controller.getActiveView() From 93137fcc91ced8b08fab66ce41a95d44568e9cf7 Mon Sep 17 00:00:00 2001 From: Jack Ha Date: Mon, 2 Jan 2017 12:56:18 +0100 Subject: [PATCH 18/54] Added compatibility mode - old layer view is now also available --- cura/CuraApplication.py | 3 - plugins/LayerView/LayerPass.py | 8 +- plugins/LayerView/LayerView.py | 11 +- plugins/LayerView/LayerView.qml | 5 + plugins/LayerView/LayerViewProxy.py | 10 +- plugins/LayerView/layers.shader | 353 +-------------------- plugins/LayerView/layers3d.shader | 355 ++++++++++++++++++++++ resources/qml/Preferences/GeneralPage.qml | 19 +- 8 files changed, 418 insertions(+), 346 deletions(-) create mode 100644 plugins/LayerView/layers3d.shader diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index 17342edd7c..3f4e0963d1 100644 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -415,7 +415,6 @@ class CuraApplication(QtApplication): controller = self.getController() controller.setActiveView("SolidView") - # controller.setActiveView("LayerView") controller.setCameraTool("CameraTool") controller.setSelectionTool("SelectionTool") @@ -457,8 +456,6 @@ class CuraApplication(QtApplication): self._qml_import_paths.append(Resources.getPath(self.ResourceTypes.QmlFiles)) self.initializeEngine() - # self.callLater(controller.setActiveView, "LayerView") - if self._engine.rootObjects: self.closeSplash() diff --git a/plugins/LayerView/LayerPass.py b/plugins/LayerView/LayerPass.py index 2fce95b18b..6d0c49e0f9 100644 --- a/plugins/LayerView/LayerPass.py +++ b/plugins/LayerView/LayerPass.py @@ -28,13 +28,19 @@ class LayerPass(RenderPass): self._extruder_manager = ExtruderManager.getInstance() self._layer_view = None + self._compatibility_mode = None def setLayerView(self, layerview): self._layer_view = layerview + self._compatibility_mode = layerview.getCompatibilityMode() def render(self): if not self._layer_shader: - self._layer_shader = OpenGL.getInstance().createShaderProgram(os.path.join(PluginRegistry.getInstance().getPluginPath("LayerView"), "layers.shader")) + if self._compatibility_mode: + shader_filename = "layers.shader" + else: + shader_filename = "layers3d.shader" + self._layer_shader = OpenGL.getInstance().createShaderProgram(os.path.join(PluginRegistry.getInstance().getPluginPath("LayerView"), shader_filename)) # Use extruder 0 if the extruder manager reports extruder index -1 (for single extrusion printers) self._layer_shader.setUniformValue("u_active_extruder", float(max(0, self._extruder_manager.activeExtruderIndex))) if self._layer_view: diff --git a/plugins/LayerView/LayerView.py b/plugins/LayerView/LayerView.py index d39fb38d58..4e5d7da23e 100644 --- a/plugins/LayerView/LayerView.py +++ b/plugins/LayerView/LayerView.py @@ -72,11 +72,13 @@ class LayerView(View): Preferences.getInstance().addPreference("view/top_layer_count", 5) Preferences.getInstance().addPreference("view/only_show_top_layers", False) + Preferences.getInstance().addPreference("view/compatibility_mode", True) # Default True for now, needs testing of different computers Preferences.getInstance().preferenceChanged.connect(self._onPreferencesChanged) self._solid_layers = int(Preferences.getInstance().getValue("view/top_layer_count")) self._only_show_top_layers = bool(Preferences.getInstance().getValue("view/only_show_top_layers")) + self._compatibility_mode = bool(Preferences.getInstance().getValue("view/compatibility_mode")) self._wireprint_warning_message = Message(catalog.i18nc("@info:status", "Cura does not accurately display layers when Wire Printing is enabled")) @@ -216,6 +218,9 @@ class LayerView(View): def getShowInfill(self): return self._show_infill + def getCompatibilityMode(self): + return self._compatibility_mode + def calculateMaxLayers(self): scene = self.getController().getScene() self._activity = True @@ -312,6 +317,9 @@ class LayerView(View): self._wireprint_warning_message.hide() def _startUpdateTopLayers(self): + if not self._compatibility_mode: + return + if self._top_layers_job: self._top_layers_job.finished.disconnect(self._updateCurrentLayerMesh) self._top_layers_job.cancel() @@ -335,11 +343,12 @@ class LayerView(View): self._top_layers_job = None def _onPreferencesChanged(self, preference): - if preference != "view/top_layer_count" and preference != "view/only_show_top_layers": + if preference not in {"view/top_layer_count", "view/only_show_top_layers", "view/compatibility_mode"}: return self._solid_layers = int(Preferences.getInstance().getValue("view/top_layer_count")) self._only_show_top_layers = bool(Preferences.getInstance().getValue("view/only_show_top_layers")) + self._compatibility_mode = bool(Preferences.getInstance().getValue("view/compatibility_mode")) self._startUpdateTopLayers() diff --git a/plugins/LayerView/LayerView.qml b/plugins/LayerView/LayerView.qml index dd0b311c6d..9306b4f5f5 100644 --- a/plugins/LayerView/LayerView.qml +++ b/plugins/LayerView/LayerView.qml @@ -139,11 +139,14 @@ Item anchors.left: parent.left anchors.verticalCenter: parent.verticalCenter anchors.top: slider_background.bottom + anchors.topMargin: UM.Theme.getSize("default_margin").height + //anchors.leftMargin: UM.Theme.getSize("default_margin").width width: UM.Theme.getSize("slider_layerview_background").width * 3 height: slider.height + UM.Theme.getSize("default_margin").height * 2 color: UM.Theme.getColor("tool_panel_background"); border.width: UM.Theme.getSize("default_lining").width border.color: UM.Theme.getColor("lining") + visible: !UM.LayerView.compatibilityMode ListModel { @@ -171,6 +174,8 @@ Item ColumnLayout { anchors.top: layer_type_combobox.bottom + anchors.topMargin: UM.Theme.getSize("default_margin").height + CheckBox { checked: true onClicked: { diff --git a/plugins/LayerView/LayerViewProxy.py b/plugins/LayerView/LayerViewProxy.py index 28acdce4a5..8b9a9b7d38 100644 --- a/plugins/LayerView/LayerViewProxy.py +++ b/plugins/LayerView/LayerViewProxy.py @@ -49,7 +49,15 @@ class LayerViewProxy(QObject): return active_view.isBusy() return False - + + @pyqtProperty(bool) + def compatibilityMode(self): + active_view = self._controller.getActiveView() + if type(active_view) == LayerView.LayerView.LayerView: + return active_view.getCompatibilityMode() + + return False + @pyqtSlot(int) def setCurrentLayer(self, layer_num): active_view = self._controller.getActiveView() diff --git a/plugins/LayerView/layers.shader b/plugins/LayerView/layers.shader index 96ef72e7fd..f360e57121 100644 --- a/plugins/LayerView/layers.shader +++ b/plugins/LayerView/layers.shader @@ -1,360 +1,37 @@ [shaders] vertex = - uniform highp mat4 u_modelMatrix; - //uniform highp mat4 u_viewProjectionMatrix; - //uniform highp mat4 u_modelViewProjectionMatrix; + uniform highp mat4 u_modelViewProjectionMatrix; uniform lowp float u_active_extruder; - uniform lowp int u_layer_view_type; - uniform lowp int u_only_color_active_extruder; - uniform lowp vec4 u_extruder_opacity; // currently only for max 4 extruders, others always visible - - uniform highp mat4 u_normalMatrix; + uniform lowp float u_shade_factor; + attribute highp int a_extruder; attribute highp vec4 a_vertex; attribute lowp vec4 a_color; - attribute lowp vec4 a_material_color; - attribute highp vec4 a_normal; - attribute highp vec2 a_line_dim; // line width and thickness - attribute highp int a_extruder; - attribute highp int a_line_type; - varying lowp vec4 v_color; - //varying lowp vec4 v_material_color; - - varying highp vec3 v_vertex; - varying highp vec3 v_normal; - //varying lowp vec2 v_uvs; - varying lowp vec2 v_line_dim; - varying highp int v_extruder; - varying highp vec4 v_extruder_opacity; - varying int v_line_type; - - varying lowp vec4 f_color; - varying highp vec3 f_vertex; - varying highp vec3 f_normal; - varying highp int f_extruder; - - void main() - { - vec4 v1_vertex = a_vertex; - v1_vertex.y -= a_line_dim.y / 2; // half layer down - vec4 world_space_vert = u_modelMatrix * v1_vertex; - // gl_Position = u_viewProjectionMatrix * world_space_vert; - gl_Position = world_space_vert; - // gl_Position = u_modelViewProjectionMatrix * a_vertex; - // shade the color depending on the extruder index stored in the alpha component of the color - - switch (u_layer_view_type) { - case 0: // "Material color" - v_color = a_material_color; - break; - case 1: // "Line type" - v_color = a_color; - break; + 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 * 1.5 : a_color * 1.5 * u_shade_factor; + v_color.a = 1.0; } - if ((u_only_color_active_extruder == 1) && (a_line_type != 8) && (a_line_type != 9)) { - v_color = (a_extruder == u_active_extruder) ? v_color : vec4(0.4, 0.4, 0.4, v_color.a); - } - /*if (a_extruder < 4) { - v_color.a *= u_extruder_opacity[a_extruder]; // make it (in)visible - }*/ - - v_vertex = world_space_vert.xyz; - v_normal = (u_normalMatrix * normalize(a_normal)).xyz; - v_line_dim = a_line_dim; - v_extruder = a_extruder; - v_line_type = a_line_type; - v_extruder_opacity = u_extruder_opacity; - - // for testing without geometry shader - /*f_color = v_color; - f_vertex = v_vertex; - f_normal = v_normal; - f_extruder = v_extruder; */ - } - -geometry = - #version 410 - - uniform highp mat4 u_viewProjectionMatrix; - 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; - - layout(lines) in; - layout(triangle_strip, max_vertices = 26) out; - - in vec4 v_color[]; - in vec3 v_vertex[]; - in vec3 v_normal[]; - in vec2 v_line_dim[]; - in int v_extruder[]; - in vec4 v_extruder_opacity[]; - in int v_line_type[]; - - out vec4 f_color; - out vec3 f_normal; - out vec3 f_vertex; - out uint f_extruder; - //out vec4 f_material_color; - - void main() - { - vec4 g_vertex_delta; - vec3 g_vertex_normal_horz; // horizontal and vertical in respect to layers - vec4 g_vertex_offset_horz; // vec4 to match gl_in[x].gl_Position - vec3 g_vertex_normal_vert; - vec4 g_vertex_offset_vert; - vec3 g_vertex_normal_horz_head; - vec4 g_vertex_offset_horz_head; - - float size_x; - float size_y; - - if ((v_extruder_opacity[0][v_extruder[0]] == 0.0) && (v_line_type[0] != 8) && (v_line_type[0] != 9)) { - return; - } - // See LayerPolygon; 8 is MoveCombingType, 9 is RetractionType - if ((u_show_travel_moves == 0) && ((v_line_type[0] == 8) || (v_line_type[0] == 9))) { - return; - } - if ((u_show_support == 0) && ((v_line_type[0] == 4) || (v_line_type[0] == 7) || (v_line_type[0] == 10))) { - return; - } - if ((u_show_adhesion == 0) && (v_line_type[0] == 5)) { - return; - } - if ((u_show_skin == 0) && ((v_line_type[0] == 1) || (v_line_type[0] == 2) || (v_line_type[0] == 3))) { - return; - } - if ((u_show_infill == 0) && (v_line_type[0] == 6)) { - return; - } - - if ((v_line_type[0] == 8) || (v_line_type[0] == 9)) { - // fixed size for movements - size_x = 0.1; - size_y = 0.1; - } else { - size_x = v_line_dim[0].x / 2 + 0.01; // radius, and make it nicely overlapping - size_y = v_line_dim[0].y / 2 + 0.01; - } - - f_extruder = v_extruder[0]; - - g_vertex_delta = gl_in[1].gl_Position - gl_in[0].gl_Position; - g_vertex_normal_horz_head = normalize(vec3(-g_vertex_delta.x, -g_vertex_delta.y, -g_vertex_delta.z)); - g_vertex_offset_horz_head = vec4(g_vertex_normal_horz_head * size_x, 0.0); - - g_vertex_normal_horz = normalize(vec3(g_vertex_delta.z, g_vertex_delta.y, -g_vertex_delta.x)); - - g_vertex_offset_horz = vec4(g_vertex_normal_horz * size_x, 0.0); //size * g_vertex_normal_horz; - g_vertex_normal_vert = vec3(0.0, 1.0, 0.0); - g_vertex_offset_vert = vec4(g_vertex_normal_vert * size_y, 0.0); - - f_vertex = v_vertex[0]; - f_color = v_color[0]; - f_normal = g_vertex_normal_horz; - gl_Position = u_viewProjectionMatrix * (gl_in[0].gl_Position + g_vertex_offset_horz); - EmitVertex(); - - f_vertex = v_vertex[1]; - f_color = v_color[1]; - f_normal = g_vertex_normal_horz; - gl_Position = u_viewProjectionMatrix * (gl_in[1].gl_Position + g_vertex_offset_horz); - EmitVertex(); - - f_vertex = v_vertex[0]; - f_color = v_color[0]; - f_normal = g_vertex_normal_vert; - gl_Position = u_viewProjectionMatrix * (gl_in[0].gl_Position + g_vertex_offset_vert); - EmitVertex(); - - f_vertex = v_vertex[1]; - f_color = v_color[1]; - f_normal = g_vertex_normal_vert; - gl_Position = u_viewProjectionMatrix * (gl_in[1].gl_Position + g_vertex_offset_vert); - EmitVertex(); - - f_vertex = v_vertex[0]; - f_normal = -g_vertex_normal_horz; - f_color = v_color[0]; - gl_Position = u_viewProjectionMatrix * (gl_in[0].gl_Position - g_vertex_offset_horz); - EmitVertex(); - - f_vertex = v_vertex[1]; - f_color = v_color[1]; - f_normal = -g_vertex_normal_horz; - gl_Position = u_viewProjectionMatrix * (gl_in[1].gl_Position - g_vertex_offset_horz); - EmitVertex(); - - f_vertex = v_vertex[0]; - f_color = v_color[0]; - f_normal = -g_vertex_normal_vert; - gl_Position = u_viewProjectionMatrix * (gl_in[0].gl_Position - g_vertex_offset_vert); - EmitVertex(); - - f_vertex = v_vertex[1]; - f_color = v_color[1]; - f_normal = -g_vertex_normal_vert; - gl_Position = u_viewProjectionMatrix * (gl_in[1].gl_Position - g_vertex_offset_vert); - EmitVertex(); - - f_vertex = v_vertex[0]; - f_normal = g_vertex_normal_horz; - f_color = v_color[0]; - gl_Position = u_viewProjectionMatrix * (gl_in[0].gl_Position + g_vertex_offset_horz); - EmitVertex(); - - f_vertex = v_vertex[1]; - f_color = v_color[1]; - f_normal = g_vertex_normal_horz; - gl_Position = u_viewProjectionMatrix * (gl_in[1].gl_Position + g_vertex_offset_horz); - EmitVertex(); - - EndPrimitive(); - - // left side - f_vertex = v_vertex[0]; - f_color = v_color[0]; - - f_normal = g_vertex_normal_horz; - gl_Position = u_viewProjectionMatrix * (gl_in[0].gl_Position + g_vertex_offset_horz); - EmitVertex(); - - f_normal = g_vertex_normal_vert; - gl_Position = u_viewProjectionMatrix * (gl_in[0].gl_Position + g_vertex_offset_vert); - EmitVertex(); - - f_normal = g_vertex_normal_horz_head; - gl_Position = u_viewProjectionMatrix * (gl_in[0].gl_Position + g_vertex_offset_horz_head); - EmitVertex(); - - f_normal = -g_vertex_normal_horz; - gl_Position = u_viewProjectionMatrix * (gl_in[0].gl_Position - g_vertex_offset_horz); - EmitVertex(); - - EndPrimitive(); - - f_normal = -g_vertex_normal_horz; - gl_Position = u_viewProjectionMatrix * (gl_in[0].gl_Position - g_vertex_offset_horz); - EmitVertex(); - - f_normal = -g_vertex_normal_vert; - gl_Position = u_viewProjectionMatrix * (gl_in[0].gl_Position - g_vertex_offset_vert); - EmitVertex(); - - f_normal = g_vertex_normal_horz_head; - gl_Position = u_viewProjectionMatrix * (gl_in[0].gl_Position + g_vertex_offset_horz_head); - EmitVertex(); - - f_normal = g_vertex_normal_horz; - gl_Position = u_viewProjectionMatrix * (gl_in[0].gl_Position + g_vertex_offset_horz); - EmitVertex(); - - EndPrimitive(); - - // right side - f_vertex = v_vertex[1]; - f_color = v_color[1]; - - f_normal = g_vertex_normal_horz; - gl_Position = u_viewProjectionMatrix * (gl_in[1].gl_Position + g_vertex_offset_horz); - EmitVertex(); - - f_normal = g_vertex_normal_vert; - gl_Position = u_viewProjectionMatrix * (gl_in[1].gl_Position + g_vertex_offset_vert); - EmitVertex(); - - f_normal = -g_vertex_normal_horz_head; - gl_Position = u_viewProjectionMatrix * (gl_in[1].gl_Position - g_vertex_offset_horz_head); - EmitVertex(); - - f_normal = -g_vertex_normal_horz; - gl_Position = u_viewProjectionMatrix * (gl_in[1].gl_Position - g_vertex_offset_horz); - EmitVertex(); - - EndPrimitive(); - - f_normal = -g_vertex_normal_horz; - gl_Position = u_viewProjectionMatrix * (gl_in[1].gl_Position - g_vertex_offset_horz); - EmitVertex(); - - f_normal = -g_vertex_normal_vert; - gl_Position = u_viewProjectionMatrix * (gl_in[1].gl_Position - g_vertex_offset_vert); - EmitVertex(); - - f_normal = -g_vertex_normal_horz_head; - gl_Position = u_viewProjectionMatrix * (gl_in[1].gl_Position - g_vertex_offset_horz_head); - EmitVertex(); - - f_normal = g_vertex_normal_horz; - gl_Position = u_viewProjectionMatrix * (gl_in[1].gl_Position + g_vertex_offset_horz); - EmitVertex(); - - EndPrimitive(); - } fragment = - varying lowp vec4 f_color; - //varying lowp vec4 f_material_color; - varying lowp vec3 f_normal; - varying lowp vec3 f_vertex; - //flat varying lowp uint f_extruder; - - uniform mediump vec4 u_ambientColor; - uniform highp vec3 u_lightPosition; + varying lowp vec4 v_color; void main() - { - mediump vec4 finalColor = vec4(0.0); - float alpha = f_color.a; - - finalColor.rgb += f_color.rgb * 0.3; - - highp vec3 normal = normalize(f_normal); - highp vec3 lightDir = normalize(u_lightPosition - f_vertex); - - // Diffuse Component - highp float NdotL = clamp(dot(normal, lightDir), 0.0, 1.0); - finalColor += (NdotL * f_color); - finalColor.a = alpha; // Do not change alpha in any way - - gl_FragColor = finalColor; - } - + { + gl_FragColor = v_color; + } [defaults] u_active_extruder = 0.0 -u_layer_view_type = 0 -u_only_color_active_extruder = 1 -u_extruder_opacity = [1.0, 1.0] - -u_specularColor = [0.4, 0.4, 0.4, 1.0] -u_ambientColor = [0.3, 0.3, 0.3, 0.0] -u_diffuseColor = [1.0, 0.79, 0.14, 1.0] -u_shininess = 20.0 - -u_show_travel_moves = 0 -u_show_support = 1 -u_show_adhesion = 1 -u_show_skin = 1 -u_show_infill = 1 +u_shade_factor = 0.60 [bindings] u_modelViewProjectionMatrix = model_view_projection_matrix -u_modelMatrix = model_matrix -u_viewProjectionMatrix = view_projection_matrix -u_normalMatrix = normal_matrix -u_lightPosition = light_0_position [attributes] a_vertex = vertex a_color = color -a_normal = normal -a_line_dim = line_dim -a_extruder = extruders -a_material_color = material_color -a_line_type = line_type +a_extruder = extruder diff --git a/plugins/LayerView/layers3d.shader b/plugins/LayerView/layers3d.shader new file mode 100644 index 0000000000..76813915b8 --- /dev/null +++ b/plugins/LayerView/layers3d.shader @@ -0,0 +1,355 @@ +[shaders] +vertex = + #version 410 + uniform highp mat4 u_modelMatrix; + uniform highp mat4 u_viewProjectionMatrix; + //uniform highp mat4 u_modelViewProjectionMatrix; + uniform lowp float u_active_extruder; + uniform lowp int u_layer_view_type; + uniform lowp int u_only_color_active_extruder; + uniform lowp vec4 u_extruder_opacity; // currently only for max 4 extruders, others always visible + + uniform highp mat4 u_normalMatrix; + + attribute highp vec4 a_vertex; + attribute lowp vec4 a_color; + attribute lowp vec4 a_material_color; + attribute highp vec4 a_normal; + attribute highp vec2 a_line_dim; // line width and thickness + attribute highp int a_extruder; + attribute highp int a_line_type; + + varying lowp vec4 v_color; + //varying lowp vec4 v_material_color; + + varying highp vec3 v_vertex; + varying highp vec3 v_normal; + //varying lowp vec2 v_uvs; + varying lowp vec2 v_line_dim; + varying highp int v_extruder; + varying highp vec4 v_extruder_opacity; + varying int v_line_type; + + varying lowp vec4 f_color; + varying highp vec3 f_vertex; + varying highp vec3 f_normal; + varying highp int f_extruder; + + void main() + { + vec4 v1_vertex = a_vertex; + v1_vertex.y -= a_line_dim.y / 2; // half layer down + + vec4 world_space_vert = u_modelMatrix * v1_vertex; + gl_Position = world_space_vert; + // shade the color depending on the extruder index stored in the alpha component of the color + + switch (u_layer_view_type) { + case 0: // "Material color" + v_color = a_material_color; + break; + case 1: // "Line type" + v_color = a_color; + break; + } + if ((u_only_color_active_extruder == 1) && (a_line_type != 8) && (a_line_type != 9)) { + v_color = (a_extruder == u_active_extruder) ? v_color : vec4(0.4, 0.4, 0.4, v_color.a); + } + + v_vertex = world_space_vert.xyz; + v_normal = (u_normalMatrix * normalize(a_normal)).xyz; + v_line_dim = a_line_dim; + v_extruder = a_extruder; + v_line_type = a_line_type; + v_extruder_opacity = u_extruder_opacity; + + // for testing and backwards compatibility without geometry shader + /*f_color = v_color; + f_vertex = v_vertex; + f_normal = v_normal;*/ + } + +geometry = + #version 410 + + uniform highp mat4 u_viewProjectionMatrix; + 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; + + layout(lines) in; + layout(triangle_strip, max_vertices = 26) out; + + in vec4 v_color[]; + in vec3 v_vertex[]; + in vec3 v_normal[]; + in vec2 v_line_dim[]; + in int v_extruder[]; + in vec4 v_extruder_opacity[]; + in int v_line_type[]; + + out vec4 f_color; + out vec3 f_normal; + out vec3 f_vertex; + out uint f_extruder; + //out vec4 f_material_color; + + void main() + { + vec4 g_vertex_delta; + vec3 g_vertex_normal_horz; // horizontal and vertical in respect to layers + vec4 g_vertex_offset_horz; // vec4 to match gl_in[x].gl_Position + vec3 g_vertex_normal_vert; + vec4 g_vertex_offset_vert; + vec3 g_vertex_normal_horz_head; + vec4 g_vertex_offset_horz_head; + + float size_x; + float size_y; + + if ((v_extruder_opacity[0][v_extruder[0]] == 0.0) && (v_line_type[0] != 8) && (v_line_type[0] != 9)) { + return; + } + // See LayerPolygon; 8 is MoveCombingType, 9 is RetractionType + if ((u_show_travel_moves == 0) && ((v_line_type[0] == 8) || (v_line_type[0] == 9))) { + return; + } + if ((u_show_support == 0) && ((v_line_type[0] == 4) || (v_line_type[0] == 7) || (v_line_type[0] == 10))) { + return; + } + if ((u_show_adhesion == 0) && (v_line_type[0] == 5)) { + return; + } + if ((u_show_skin == 0) && ((v_line_type[0] == 1) || (v_line_type[0] == 2) || (v_line_type[0] == 3))) { + return; + } + if ((u_show_infill == 0) && (v_line_type[0] == 6)) { + return; + } + + if ((v_line_type[0] == 8) || (v_line_type[0] == 9)) { + // fixed size for movements + size_x = 0.1; + size_y = 0.1; + } else { + size_x = v_line_dim[0].x / 2 + 0.01; // radius, and make it nicely overlapping + size_y = v_line_dim[0].y / 2 + 0.01; + } + + f_extruder = v_extruder[0]; + + g_vertex_delta = gl_in[1].gl_Position - gl_in[0].gl_Position; + g_vertex_normal_horz_head = normalize(vec3(-g_vertex_delta.x, -g_vertex_delta.y, -g_vertex_delta.z)); + g_vertex_offset_horz_head = vec4(g_vertex_normal_horz_head * size_x, 0.0); + + g_vertex_normal_horz = normalize(vec3(g_vertex_delta.z, g_vertex_delta.y, -g_vertex_delta.x)); + + g_vertex_offset_horz = vec4(g_vertex_normal_horz * size_x, 0.0); //size * g_vertex_normal_horz; + g_vertex_normal_vert = vec3(0.0, 1.0, 0.0); + g_vertex_offset_vert = vec4(g_vertex_normal_vert * size_y, 0.0); + + f_vertex = v_vertex[0]; + f_color = v_color[0]; + f_normal = g_vertex_normal_horz; + gl_Position = u_viewProjectionMatrix * (gl_in[0].gl_Position + g_vertex_offset_horz); + EmitVertex(); + + f_vertex = v_vertex[1]; + f_color = v_color[1]; + f_normal = g_vertex_normal_horz; + gl_Position = u_viewProjectionMatrix * (gl_in[1].gl_Position + g_vertex_offset_horz); + EmitVertex(); + + f_vertex = v_vertex[0]; + f_color = v_color[0]; + f_normal = g_vertex_normal_vert; + gl_Position = u_viewProjectionMatrix * (gl_in[0].gl_Position + g_vertex_offset_vert); + EmitVertex(); + + f_vertex = v_vertex[1]; + f_color = v_color[1]; + f_normal = g_vertex_normal_vert; + gl_Position = u_viewProjectionMatrix * (gl_in[1].gl_Position + g_vertex_offset_vert); + EmitVertex(); + + f_vertex = v_vertex[0]; + f_normal = -g_vertex_normal_horz; + f_color = v_color[0]; + gl_Position = u_viewProjectionMatrix * (gl_in[0].gl_Position - g_vertex_offset_horz); + EmitVertex(); + + f_vertex = v_vertex[1]; + f_color = v_color[1]; + f_normal = -g_vertex_normal_horz; + gl_Position = u_viewProjectionMatrix * (gl_in[1].gl_Position - g_vertex_offset_horz); + EmitVertex(); + + f_vertex = v_vertex[0]; + f_color = v_color[0]; + f_normal = -g_vertex_normal_vert; + gl_Position = u_viewProjectionMatrix * (gl_in[0].gl_Position - g_vertex_offset_vert); + EmitVertex(); + + f_vertex = v_vertex[1]; + f_color = v_color[1]; + f_normal = -g_vertex_normal_vert; + gl_Position = u_viewProjectionMatrix * (gl_in[1].gl_Position - g_vertex_offset_vert); + EmitVertex(); + + f_vertex = v_vertex[0]; + f_normal = g_vertex_normal_horz; + f_color = v_color[0]; + gl_Position = u_viewProjectionMatrix * (gl_in[0].gl_Position + g_vertex_offset_horz); + EmitVertex(); + + f_vertex = v_vertex[1]; + f_color = v_color[1]; + f_normal = g_vertex_normal_horz; + gl_Position = u_viewProjectionMatrix * (gl_in[1].gl_Position + g_vertex_offset_horz); + EmitVertex(); + + EndPrimitive(); + + // left side + f_vertex = v_vertex[0]; + f_color = v_color[0]; + + f_normal = g_vertex_normal_horz; + gl_Position = u_viewProjectionMatrix * (gl_in[0].gl_Position + g_vertex_offset_horz); + EmitVertex(); + + f_normal = g_vertex_normal_vert; + gl_Position = u_viewProjectionMatrix * (gl_in[0].gl_Position + g_vertex_offset_vert); + EmitVertex(); + + f_normal = g_vertex_normal_horz_head; + gl_Position = u_viewProjectionMatrix * (gl_in[0].gl_Position + g_vertex_offset_horz_head); + EmitVertex(); + + f_normal = -g_vertex_normal_horz; + gl_Position = u_viewProjectionMatrix * (gl_in[0].gl_Position - g_vertex_offset_horz); + EmitVertex(); + + EndPrimitive(); + + f_normal = -g_vertex_normal_horz; + gl_Position = u_viewProjectionMatrix * (gl_in[0].gl_Position - g_vertex_offset_horz); + EmitVertex(); + + f_normal = -g_vertex_normal_vert; + gl_Position = u_viewProjectionMatrix * (gl_in[0].gl_Position - g_vertex_offset_vert); + EmitVertex(); + + f_normal = g_vertex_normal_horz_head; + gl_Position = u_viewProjectionMatrix * (gl_in[0].gl_Position + g_vertex_offset_horz_head); + EmitVertex(); + + f_normal = g_vertex_normal_horz; + gl_Position = u_viewProjectionMatrix * (gl_in[0].gl_Position + g_vertex_offset_horz); + EmitVertex(); + + EndPrimitive(); + + // right side + f_vertex = v_vertex[1]; + f_color = v_color[1]; + + f_normal = g_vertex_normal_horz; + gl_Position = u_viewProjectionMatrix * (gl_in[1].gl_Position + g_vertex_offset_horz); + EmitVertex(); + + f_normal = g_vertex_normal_vert; + gl_Position = u_viewProjectionMatrix * (gl_in[1].gl_Position + g_vertex_offset_vert); + EmitVertex(); + + f_normal = -g_vertex_normal_horz_head; + gl_Position = u_viewProjectionMatrix * (gl_in[1].gl_Position - g_vertex_offset_horz_head); + EmitVertex(); + + f_normal = -g_vertex_normal_horz; + gl_Position = u_viewProjectionMatrix * (gl_in[1].gl_Position - g_vertex_offset_horz); + EmitVertex(); + + EndPrimitive(); + + f_normal = -g_vertex_normal_horz; + gl_Position = u_viewProjectionMatrix * (gl_in[1].gl_Position - g_vertex_offset_horz); + EmitVertex(); + + f_normal = -g_vertex_normal_vert; + gl_Position = u_viewProjectionMatrix * (gl_in[1].gl_Position - g_vertex_offset_vert); + EmitVertex(); + + f_normal = -g_vertex_normal_horz_head; + gl_Position = u_viewProjectionMatrix * (gl_in[1].gl_Position - g_vertex_offset_horz_head); + EmitVertex(); + + f_normal = g_vertex_normal_horz; + gl_Position = u_viewProjectionMatrix * (gl_in[1].gl_Position + g_vertex_offset_horz); + EmitVertex(); + + EndPrimitive(); + } + +fragment = + #version 410 + varying lowp vec4 f_color; + varying lowp vec3 f_normal; + varying lowp vec3 f_vertex; + + uniform mediump vec4 u_ambientColor; + uniform highp vec3 u_lightPosition; + + void main() + { + mediump vec4 finalColor = vec4(0.0); + float alpha = f_color.a; + + finalColor.rgb += f_color.rgb * 0.3; + + highp vec3 normal = normalize(f_normal); + highp vec3 lightDir = normalize(u_lightPosition - f_vertex); + + // Diffuse Component + highp float NdotL = clamp(dot(normal, lightDir), 0.0, 1.0); + finalColor += (NdotL * f_color); + finalColor.a = alpha; // Do not change alpha in any way + + gl_FragColor = finalColor; + } + + +[defaults] +u_active_extruder = 0.0 +u_layer_view_type = 0 +u_only_color_active_extruder = 1 +u_extruder_opacity = [1.0, 1.0] + +u_specularColor = [0.4, 0.4, 0.4, 1.0] +u_ambientColor = [0.3, 0.3, 0.3, 0.0] +u_diffuseColor = [1.0, 0.79, 0.14, 1.0] +u_shininess = 20.0 + +u_show_travel_moves = 0 +u_show_support = 1 +u_show_adhesion = 1 +u_show_skin = 1 +u_show_infill = 1 + +[bindings] +u_modelViewProjectionMatrix = model_view_projection_matrix +u_modelMatrix = model_matrix +u_viewProjectionMatrix = view_projection_matrix +u_normalMatrix = normal_matrix +u_lightPosition = light_0_position + +[attributes] +a_vertex = vertex +a_color = color +a_normal = normal +a_line_dim = line_dim +a_extruder = extruder +a_material_color = material_color +a_line_type = line_type diff --git a/resources/qml/Preferences/GeneralPage.qml b/resources/qml/Preferences/GeneralPage.qml index eab5dbe938..bf6e1aa0f0 100644 --- a/resources/qml/Preferences/GeneralPage.qml +++ b/resources/qml/Preferences/GeneralPage.qml @@ -212,6 +212,20 @@ UM.PreferencesPage } } + UM.TooltipArea { + width: childrenRect.width + height: childrenRect.height + text: catalog.i18nc("@info:tooltip", "Compatibility mode in layerview?") + + CheckBox + { + id: topLayerViewCompatibilityCheckbox + text: catalog.i18nc("@option:check", "Layer view compatibility mode (for OpenGL <= 4.0, restart required)") + checked: boolCheck(UM.Preferences.getValue("view/compatibility_mode")) + onCheckedChanged: UM.Preferences.setValue("view/compatibility_mode", checked) + } + } + UM.TooltipArea { width: childrenRect.width; height: childrenRect.height; @@ -220,7 +234,7 @@ UM.PreferencesPage CheckBox { id: topLayerCountCheckbox - text: catalog.i18nc("@action:button","Display five top layers in layer view"); + text: catalog.i18nc("@action:button","Display five top layers in layer view (only for compatibility mode)"); checked: UM.Preferences.getValue("view/top_layer_count") == 5 onClicked: { @@ -235,6 +249,7 @@ UM.PreferencesPage } } } + UM.TooltipArea { width: childrenRect.width height: childrenRect.height @@ -243,7 +258,7 @@ UM.PreferencesPage CheckBox { id: topLayersOnlyCheckbox - text: catalog.i18nc("@option:check", "Only display top layer(s) in layer view") + text: catalog.i18nc("@option:check", "Only display top layer(s) in layer view (only for compatibility mode)") checked: boolCheck(UM.Preferences.getValue("view/only_show_top_layers")) onCheckedChanged: UM.Preferences.setValue("view/only_show_top_layers", checked) } From f0e0d65635fbf0f2170631ce04a475757122fc0f Mon Sep 17 00:00:00 2001 From: Jack Ha Date: Mon, 2 Jan 2017 14:56:31 +0100 Subject: [PATCH 19/54] Finishing up compatibility mode --- cura/LayerDataBuilder.py | 4 +- .../ProcessSlicedLayersJob.py | 9 ++- plugins/LayerView/LayerView.qml | 12 ++- plugins/LayerView/layers.shader | 78 ++++++++++++++++--- plugins/LayerView/layers3d.shader | 3 +- 5 files changed, 91 insertions(+), 15 deletions(-) diff --git a/cura/LayerDataBuilder.py b/cura/LayerDataBuilder.py index 72dac319cd..dcc3991833 100644 --- a/cura/LayerDataBuilder.py +++ b/cura/LayerDataBuilder.py @@ -49,7 +49,8 @@ class LayerDataBuilder(MeshBuilder): self._layers[layer].setThickness(thickness) # 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 index_count = 0 for layer, data in self._layers.items(): @@ -70,6 +71,7 @@ class LayerDataBuilder(MeshBuilder): self._element_counts[layer] = data.elementCount self.addVertices(vertices) + colors[:, 0:3] *= line_type_brightness self.addColors(colors) self.addIndices(indices.flatten()) diff --git a/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py b/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py index 70398ff867..028c51b3ed 100644 --- a/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py +++ b/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py @@ -8,6 +8,7 @@ from UM.Scene.Iterator.DepthFirstIterator import DepthFirstIterator from UM.Scene.SceneNode import SceneNode from UM.Application import Application from UM.Mesh.MeshData import MeshData +from UM.Preferences import Preferences from UM.Message import Message from UM.i18n import i18nCatalog @@ -105,7 +106,6 @@ class ProcessSlicedLayersJob(Job): polygon = layer.getRepeatedMessage("path_segment", p) extruder = polygon.extruder - x = dir(polygon) line_types = numpy.fromstring(polygon.line_type, dtype="u1") # Convert bytearray to numpy array 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 from cura.Settings.ExtruderManager import ExtruderManager import UM + global_container_stack = UM.Application.getInstance().getGlobalContainerStack() manager = ExtruderManager.getInstance() extruders = list(manager.getMachineExtruders(global_container_stack.getId())) @@ -181,7 +182,11 @@ class ProcessSlicedLayersJob(Job): color = colorCodeToRGBA(color_code) 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._progress: diff --git a/plugins/LayerView/LayerView.qml b/plugins/LayerView/LayerView.qml index 9306b4f5f5..73c34520d6 100644 --- a/plugins/LayerView/LayerView.qml +++ b/plugins/LayerView/LayerView.qml @@ -146,7 +146,6 @@ Item color: UM.Theme.getColor("tool_panel_background"); border.width: UM.Theme.getSize("default_lining").width border.color: UM.Theme.getColor("lining") - visible: !UM.LayerView.compatibilityMode ListModel { @@ -167,11 +166,20 @@ Item anchors.top: slider_background.bottom anchors.left: parent.left model: layerViewTypes + visible: !UM.LayerView.compatibilityMode onActivated: { 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 { anchors.top: layer_type_combobox.bottom anchors.topMargin: UM.Theme.getSize("default_margin").height @@ -182,6 +190,7 @@ Item UM.LayerView.setExtruderOpacity(0, checked ? 1.0 : 0.0); } text: "Extruder 1" + visible: !UM.LayerView.compatibilityMode } CheckBox { checked: true @@ -189,6 +198,7 @@ Item UM.LayerView.setExtruderOpacity(1, checked ? 1.0 : 0.0); } text: "Extruder 2" + visible: !UM.LayerView.compatibilityMode } CheckBox { onClicked: { diff --git a/plugins/LayerView/layers.shader b/plugins/LayerView/layers.shader index f360e57121..b58d11da0c 100644 --- a/plugins/LayerView/layers.shader +++ b/plugins/LayerView/layers.shader @@ -3,30 +3,88 @@ vertex = uniform highp mat4 u_modelViewProjectionMatrix; uniform lowp float u_active_extruder; 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_line_type; attribute highp vec4 a_vertex; attribute lowp vec4 a_color; + attribute lowp vec4 a_material_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 * 1.5 : a_color * 1.5 * u_shade_factor; - v_color.a = 1.0; + varying float v_line_type; + + void main() + { + gl_Position = u_modelViewProjectionMatrix * a_vertex; + v_color = a_color; + if ((u_only_color_active_extruder == 1) && (a_line_type != 8) && (a_line_type != 9)) { + 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 = 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() - { - gl_FragColor = v_color; - } + { + 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; + } [defaults] u_active_extruder = 0.0 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] u_modelViewProjectionMatrix = model_view_projection_matrix @@ -35,3 +93,5 @@ u_modelViewProjectionMatrix = model_view_projection_matrix a_vertex = vertex a_color = color a_extruder = extruder +a_line_type = line_type +a_material_color = material_color diff --git a/plugins/LayerView/layers3d.shader b/plugins/LayerView/layers3d.shader index 76813915b8..03a4015b3c 100644 --- a/plugins/LayerView/layers3d.shader +++ b/plugins/LayerView/layers3d.shader @@ -94,7 +94,6 @@ geometry = out vec3 f_normal; out vec3 f_vertex; out uint f_extruder; - //out vec4 f_material_color; void main() { @@ -325,7 +324,7 @@ fragment = u_active_extruder = 0.0 u_layer_view_type = 0 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_ambientColor = [0.3, 0.3, 0.3, 0.0] From 55dd08eff81cd5e20b5f07c9590dc6679f326d67 Mon Sep 17 00:00:00 2001 From: Jack Ha Date: Tue, 3 Jan 2017 09:18:26 +0100 Subject: [PATCH 20/54] Somewhat better layout, added legend --- .../ProcessSlicedLayersJob.py | 8 +-- plugins/LayerView/LayerView.qml | 57 +++++++++++++++++++ plugins/LayerView/LayerViewProxy.py | 7 +++ 3 files changed, 67 insertions(+), 5 deletions(-) diff --git a/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py b/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py index 028c51b3ed..49c306ea77 100644 --- a/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py +++ b/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py @@ -16,6 +16,7 @@ from UM.Logger import Logger from UM.Math.Vector import Vector +from cura.Settings.ExtruderManager import ExtruderManager from cura import LayerDataBuilder from cura import LayerDataDecorator from cura import LayerPolygon @@ -159,11 +160,7 @@ class ProcessSlicedLayersJob(Job): # We are done processing all the layers we got from the engine, now create a mesh out of the data # Find out colors per extruder - # TODO: move to a better place. Code is similar to code in ExtrudersModel - from cura.Settings.ExtruderManager import ExtruderManager - import UM - - global_container_stack = UM.Application.getInstance().getGlobalContainerStack() + global_container_stack = Application.getInstance().getGlobalContainerStack() manager = ExtruderManager.getInstance() extruders = list(manager.getMachineExtruders(global_container_stack.getId())) if extruders: @@ -182,6 +179,7 @@ class ProcessSlicedLayersJob(Job): color = colorCodeToRGBA(color_code) material_color_map[0, :] = color + # We have to scale the colors for compatibility mode if bool(Preferences.getInstance().getValue("view/compatibility_mode")): line_type_brightness = 0.5 else: diff --git a/plugins/LayerView/LayerView.qml b/plugins/LayerView/LayerView.qml index 73c34520d6..0e9a2cd7c9 100644 --- a/plugins/LayerView/LayerView.qml +++ b/plugins/LayerView/LayerView.qml @@ -181,8 +181,10 @@ Item } ColumnLayout { + id: view_settings anchors.top: layer_type_combobox.bottom anchors.topMargin: UM.Theme.getSize("default_margin").height + x: UM.Theme.getSize("default_margin").width CheckBox { checked: true @@ -243,5 +245,60 @@ Item } } + // legend + ListView { + + visible: (UM.LayerView.getLayerViewType() == 1) // line type + anchors.top: view_settings.bottom + anchors.topMargin: UM.Theme.getSize("default_margin").height + //width: parent.width + //height: childrenRect.height + + delegate: Row + { + Rectangle + { + id: rect + + x: UM.Theme.getSize("default_margin").width + y: index * UM.Theme.getSize("section_icon").height + + //width: UM.Theme.getSize("section_icon").width + //height: 0.5 * UM.Theme.getSize("section_icon").height + width: UM.Theme.getSize("setting_control").height / 2 + height: UM.Theme.getSize("setting_control").height / 2 + //Behavior on height { NumberAnimation { duration: 50; } } + + border.width: UM.Theme.getSize("default_lining").width; + border.color: UM.Theme.getColor("slider_groove_border"); + + color: model.color; + } + + Label + { + anchors.left: rect.right + anchors.verticalCenter: rect.verticalCenter + anchors.leftMargin: UM.Theme.getSize("default_margin").width + text: model.label + } + } + model: ListModel + { + id: legendModel + } + Component.onCompleted: + { + // see LayerPolygon + legendModel.append({ label:catalog.i18nc("@label", "Inset0"), color: "#ff0000" }); + legendModel.append({ label:catalog.i18nc("@label", "InsetX"), color: "#00ff00" }); + legendModel.append({ label:catalog.i18nc("@label", "Skin"), color: "#ffff00" }); + legendModel.append({ label:catalog.i18nc("@label", "Support, Skirt, SupportInfill"), color: "#00ffff" }); + legendModel.append({ label:catalog.i18nc("@label", "Infill"), color: "#ffbf00" }); + legendModel.append({ label:catalog.i18nc("@label", "MoveCombing"), color: "#0000ff" }); + legendModel.append({ label:catalog.i18nc("@label", "MoveRetraction"), color: "#8080ff" }); + legendModel.append({ label:catalog.i18nc("@label", "SupportInterface"), color: "#3fbfff" }); + } + } } } diff --git a/plugins/LayerView/LayerViewProxy.py b/plugins/LayerView/LayerViewProxy.py index 8b9a9b7d38..4cf1668ca3 100644 --- a/plugins/LayerView/LayerViewProxy.py +++ b/plugins/LayerView/LayerViewProxy.py @@ -76,6 +76,13 @@ class LayerViewProxy(QObject): if type(active_view) == LayerView.LayerView.LayerView: active_view.setLayerViewType(layer_view_type) + @pyqtProperty(bool) + def getLayerViewType(self): + active_view = self._controller.getActiveView() + if type(active_view) == LayerView.LayerView.LayerView: + return active_view.getLayerViewType() + return 0 + @pyqtSlot(bool) def setOnlyColorActiveExtruder(self, only_color_active_extruder): active_view = self._controller.getActiveView() From e57de296e70d66d978f867dcd79289fb04ff7910 Mon Sep 17 00:00:00 2001 From: Jack Ha Date: Tue, 3 Jan 2017 10:14:34 +0100 Subject: [PATCH 21/54] Readded accidently removed stuff --- cura/LayerPolygon.py | 2 +- plugins/CuraEngineBackend/ProcessSlicedLayersJob.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cura/LayerPolygon.py b/cura/LayerPolygon.py index 4509ba7d26..959ac9ad84 100644 --- a/cura/LayerPolygon.py +++ b/cura/LayerPolygon.py @@ -60,7 +60,7 @@ class LayerPolygon: # Only if the type of line segment changes do we need to add an extra vertex to change colors self._build_cache_needed_points[1:, 0][:, numpy.newaxis] = self._types[1:] != self._types[:-1] # Mark points as unneeded if they are of types we don't want in the line mesh according to the calculated mask - numpy.logical_and(self._build_cache_needed_points, self._build_cache_line_mesh_mask ) + numpy.logical_and(self._build_cache_needed_points, self._build_cache_line_mesh_mask, self._build_cache_needed_points ) self._vertex_begin = 0 self._vertex_end = numpy.sum( self._build_cache_needed_points ) diff --git a/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py b/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py index 49c306ea77..a00ab69d67 100644 --- a/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py +++ b/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py @@ -131,7 +131,7 @@ class ProcessSlicedLayersJob(Job): new_points = numpy.empty((len(points), 3), numpy.float32) if polygon.point_type == 0: # Point2D new_points[:, 0] = points[:, 0] - new_points[:, 1] = layer.height / 1000 # layer height value is in backend representation + new_points[:, 1] = layer.height / 1000 # layer height value is in backend representation new_points[:, 2] = -points[:, 1] else: # Point3D new_points[:, 0] = points[:, 0] From cd8eaf77599f9e3cb12113771f6669ff7d44eea9 Mon Sep 17 00:00:00 2001 From: Jack Ha Date: Tue, 3 Jan 2017 15:58:35 +0100 Subject: [PATCH 22/54] minimum layer slider now works --- plugins/LayerView/LayerPass.py | 2 +- plugins/LayerView/LayerView.py | 2 -- plugins/LayerView/LayerView.qml | 16 +++++++++++++--- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/plugins/LayerView/LayerPass.py b/plugins/LayerView/LayerPass.py index 6d0c49e0f9..dba6f10930 100644 --- a/plugins/LayerView/LayerPass.py +++ b/plugins/LayerView/LayerPass.py @@ -80,7 +80,7 @@ class LayerPass(RenderPass): continue # Render all layers below a certain number as line mesh instead of vertices. - if self._layer_view._current_layer_num > -1 and not self._layer_view._only_show_top_layers: + if self._layer_view._current_layer_num > -1 and ((not self._layer_view._only_show_top_layers) or (not self._layer_view.getCompatibilityMode())): start = 0 end = 0 element_counts = layer_data.getElementCounts() diff --git a/plugins/LayerView/LayerView.py b/plugins/LayerView/LayerView.py index 4e5d7da23e..d7bcb03f93 100644 --- a/plugins/LayerView/LayerView.py +++ b/plugins/LayerView/LayerView.py @@ -155,8 +155,6 @@ class LayerView(View): self._minimum_layer_num = value if self._minimum_layer_num < 0: self._minimum_layer_num = 0 - if self._minimum_layer_num > self._current_layer_num: - self._minimum_layer_num = self._current_layer_num self._startUpdateTopLayers() diff --git a/plugins/LayerView/LayerView.qml b/plugins/LayerView/LayerView.qml index 0e9a2cd7c9..de6327e066 100644 --- a/plugins/LayerView/LayerView.qml +++ b/plugins/LayerView/LayerView.qml @@ -22,13 +22,18 @@ Item anchors.leftMargin: UM.Theme.getSize("slider_layerview_margin").width * 0.2 orientation: Qt.Vertical minimumValue: 0; - maximumValue: UM.LayerView.numLayers; + maximumValue: UM.LayerView.numLayers-1; stepSize: 1 property real pixelsPerStep: ((height - UM.Theme.getSize("slider_handle").height) / (maximumValue - minimumValue)) * stepSize; value: UM.LayerView.minimumLayer - onValueChanged: UM.LayerView.setMinimumLayer(value) + onValueChanged: { + UM.LayerView.setMinimumLayer(value) + if (value > UM.LayerView.currentLayer) { + UM.LayerView.setCurrentLayer(value); + } + } style: UM.Theme.styles.slider; } @@ -48,7 +53,12 @@ Item property real pixelsPerStep: ((height - UM.Theme.getSize("slider_handle").height) / (maximumValue - minimumValue)) * stepSize; value: UM.LayerView.currentLayer - onValueChanged: UM.LayerView.setCurrentLayer(value) + onValueChanged: { + UM.LayerView.setCurrentLayer(value); + if (value < UM.LayerView.minimumLayer) { + UM.LayerView.setMinimumLayer(value); + } + } style: UM.Theme.styles.slider; From f80a04cbc3101db38b9d6346b47709d4aa6a1c10 Mon Sep 17 00:00:00 2001 From: Jack Ha Date: Tue, 24 Jan 2017 16:31:57 +0100 Subject: [PATCH 23/54] Auto detect compatibility mode for layer view. --- plugins/LayerView/LayerView.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/plugins/LayerView/LayerView.py b/plugins/LayerView/LayerView.py index 6aa85c3e3c..21854fb295 100644 --- a/plugins/LayerView/LayerView.py +++ b/plugins/LayerView/LayerView.py @@ -13,15 +13,13 @@ from UM.Mesh.MeshBuilder import MeshBuilder from UM.Job import Job from UM.Preferences import Preferences from UM.Logger import Logger -from UM.Scene.SceneNode import SceneNode -from UM.View.RenderBatch import RenderBatch from UM.View.GL.OpenGL import OpenGL from UM.Message import Message from UM.Application import Application from cura.ConvexHullNode import ConvexHullNode -from PyQt5.QtCore import Qt, QTimer +from PyQt5.QtCore import Qt from PyQt5.QtWidgets import QApplication from . import LayerViewProxy @@ -78,7 +76,10 @@ class LayerView(View): self._solid_layers = int(Preferences.getInstance().getValue("view/top_layer_count")) self._only_show_top_layers = bool(Preferences.getInstance().getValue("view/only_show_top_layers")) - self._compatibility_mode = bool(Preferences.getInstance().getValue("view/compatibility_mode")) + self._compatibility_mode = True # for safety + #self._compatibility_mode = bool(Preferences.getInstance().getValue("view/compatibility_mode")) + #self._compatibility_mode = not self.getRenderer().getSupportsGeometryShader() + #Logger.log("d", "OpenGL Compatibility mode: %s" % self._compatibility_mode) self._wireprint_warning_message = Message(catalog.i18nc("@info:status", "Cura does not accurately display layers when Wire Printing is enabled")) @@ -90,6 +91,7 @@ class LayerView(View): # Currently the RenderPass constructor requires a size > 0 # This should be fixed in RenderPass's constructor. self._layer_pass = LayerPass.LayerPass(1, 1) + self._compatibility_mode = not self.getRenderer().getSupportsGeometryShader() self._layer_pass.setLayerView(self) self.getRenderer().addRenderPass(self._layer_pass) return self._layer_pass @@ -346,7 +348,7 @@ class LayerView(View): self._solid_layers = int(Preferences.getInstance().getValue("view/top_layer_count")) self._only_show_top_layers = bool(Preferences.getInstance().getValue("view/only_show_top_layers")) - self._compatibility_mode = bool(Preferences.getInstance().getValue("view/compatibility_mode")) + # self._compatibility_mode = bool(Preferences.getInstance().getValue("view/compatibility_mode")) self._startUpdateTopLayers() From e21a6ed62a0e6018c717c5ce0e331c9496d5a85b Mon Sep 17 00:00:00 2001 From: Jack Ha Date: Tue, 24 Jan 2017 16:52:47 +0100 Subject: [PATCH 24/54] Cleanup --- plugins/LayerView/LayerView.py | 4 ---- resources/qml/Preferences/GeneralPage.qml | 18 ++---------------- 2 files changed, 2 insertions(+), 20 deletions(-) diff --git a/plugins/LayerView/LayerView.py b/plugins/LayerView/LayerView.py index 21854fb295..0d38e89026 100644 --- a/plugins/LayerView/LayerView.py +++ b/plugins/LayerView/LayerView.py @@ -77,9 +77,6 @@ class LayerView(View): self._solid_layers = int(Preferences.getInstance().getValue("view/top_layer_count")) self._only_show_top_layers = bool(Preferences.getInstance().getValue("view/only_show_top_layers")) self._compatibility_mode = True # for safety - #self._compatibility_mode = bool(Preferences.getInstance().getValue("view/compatibility_mode")) - #self._compatibility_mode = not self.getRenderer().getSupportsGeometryShader() - #Logger.log("d", "OpenGL Compatibility mode: %s" % self._compatibility_mode) self._wireprint_warning_message = Message(catalog.i18nc("@info:status", "Cura does not accurately display layers when Wire Printing is enabled")) @@ -348,7 +345,6 @@ class LayerView(View): self._solid_layers = int(Preferences.getInstance().getValue("view/top_layer_count")) self._only_show_top_layers = bool(Preferences.getInstance().getValue("view/only_show_top_layers")) - # self._compatibility_mode = bool(Preferences.getInstance().getValue("view/compatibility_mode")) self._startUpdateTopLayers() diff --git a/resources/qml/Preferences/GeneralPage.qml b/resources/qml/Preferences/GeneralPage.qml index db0b372fd9..57a35943d9 100644 --- a/resources/qml/Preferences/GeneralPage.qml +++ b/resources/qml/Preferences/GeneralPage.qml @@ -213,20 +213,6 @@ UM.PreferencesPage } } - UM.TooltipArea { - width: childrenRect.width - height: childrenRect.height - text: catalog.i18nc("@info:tooltip", "Compatibility mode in layerview?") - - CheckBox - { - id: topLayerViewCompatibilityCheckbox - text: catalog.i18nc("@option:check", "Layer view compatibility mode (for OpenGL <= 4.0, restart required)") - checked: boolCheck(UM.Preferences.getValue("view/compatibility_mode")) - onCheckedChanged: UM.Preferences.setValue("view/compatibility_mode", checked) - } - } - UM.TooltipArea { width: childrenRect.width; height: childrenRect.height; @@ -235,7 +221,7 @@ UM.PreferencesPage CheckBox { id: topLayerCountCheckbox - text: catalog.i18nc("@action:button","Display five top layers in layer view (only for compatibility mode)"); + text: catalog.i18nc("@action:button","Display five top layers in layer view compatibility mode"); checked: UM.Preferences.getValue("view/top_layer_count") == 5 onClicked: { @@ -259,7 +245,7 @@ UM.PreferencesPage CheckBox { id: topLayersOnlyCheckbox - text: catalog.i18nc("@option:check", "Only display top layer(s) in layer view (only for compatibility mode)") + text: catalog.i18nc("@option:check", "Only display top layer(s) in layer view compatibility mode") checked: boolCheck(UM.Preferences.getValue("view/only_show_top_layers")) onCheckedChanged: UM.Preferences.setValue("view/only_show_top_layers", checked) } From 6625938a2b7d0590e099d398acad2c4fa3b29ec6 Mon Sep 17 00:00:00 2001 From: Jack Ha Date: Wed, 25 Jan 2017 09:24:40 +0100 Subject: [PATCH 25/54] Cleanup __color_map in LayerPolygon --- cura/LayerPolygon.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cura/LayerPolygon.py b/cura/LayerPolygon.py index 959ac9ad84..c1ec3a6978 100644 --- a/cura/LayerPolygon.py +++ b/cura/LayerPolygon.py @@ -38,7 +38,6 @@ class LayerPolygon: # Buffering the colors shouldn't be necessary as it is not # re-used and can save alot of memory usage. - self._color_map = self.__color_map # * [1, 1, 1, self._extruder] # The alpha component is used to store the extruder nr 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 @@ -185,7 +184,7 @@ class LayerPolygon: return normals # Should be generated in better way, not hardcoded. - __color_map = numpy.array([ + _color_map = numpy.array([ [1.0, 1.0, 1.0, 1.0], # NoneType [1.0, 0.0, 0.0, 1.0], # Inset0Type [0.0, 1.0, 0.0, 1.0], # InsetXType From 5fff1f665763904f8b9ccaf4138555391396a333 Mon Sep 17 00:00:00 2001 From: Jack Ha Date: Wed, 25 Jan 2017 09:27:22 +0100 Subject: [PATCH 26/54] Cleanup --- cura/LayerPolygon.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cura/LayerPolygon.py b/cura/LayerPolygon.py index c1ec3a6978..287caa69f9 100644 --- a/cura/LayerPolygon.py +++ b/cura/LayerPolygon.py @@ -49,8 +49,7 @@ class LayerPolygon: def buildCache(self): # For the line mesh we do not draw Infill or Jumps. Therefore those lines are filtered out. - # self._build_cache_line_mesh_mask = numpy.logical_not(numpy.logical_or(self._jump_mask, self._types == LayerPolygon.InfillType )) - self._build_cache_line_mesh_mask = numpy.ones(self._jump_mask.shape, dtype=bool) # numpy.logical_not(self._jump_mask) + self._build_cache_line_mesh_mask = numpy.ones(self._jump_mask.shape, dtype=bool) mesh_line_count = numpy.sum(self._build_cache_line_mesh_mask) self._index_begin = 0 self._index_end = mesh_line_count From a52cb2fa636c2af1f70fedfd3a3af2cbdfb74180 Mon Sep 17 00:00:00 2001 From: Jack Ha Date: Wed, 25 Jan 2017 09:48:36 +0100 Subject: [PATCH 27/54] Compatibility mode scale line type colors --- cura/LayerPolygon.py | 4 ++-- plugins/CuraEngineBackend/ProcessSlicedLayersJob.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cura/LayerPolygon.py b/cura/LayerPolygon.py index 287caa69f9..34bb38249a 100644 --- a/cura/LayerPolygon.py +++ b/cura/LayerPolygon.py @@ -18,6 +18,8 @@ class LayerPolygon: __jump_map = numpy.logical_or(numpy.logical_or(numpy.arange(11) == NoneType, numpy.arange(11) == MoveCombingType), numpy.arange(11) == MoveRetractionType) + ## LayerPolygon + # line_thicknesses: array with type as index and thickness as value def __init__(self, mesh, extruder, line_types, data, line_widths, line_thicknesses): self._mesh = mesh self._extruder = extruder @@ -63,8 +65,6 @@ class LayerPolygon: self._vertex_begin = 0 self._vertex_end = numpy.sum( self._build_cache_needed_points ) - ## build - # line_thicknesses: array with type as index and thickness as value def build(self, vertex_offset, index_offset, vertices, colors, line_dimensions, extruders, line_types, indices): if (self._build_cache_line_mesh_mask is None) or (self._build_cache_needed_points is None ): self.buildCache() diff --git a/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py b/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py index a00ab69d67..1dbcbdb3b7 100644 --- a/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py +++ b/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py @@ -180,10 +180,10 @@ class ProcessSlicedLayersJob(Job): material_color_map[0, :] = color # We have to scale the colors for compatibility mode - if bool(Preferences.getInstance().getValue("view/compatibility_mode")): - line_type_brightness = 0.5 - else: + if Application.getInstance().getRenderer().getSupportsGeometryShader(): line_type_brightness = 1.0 + else: + line_type_brightness = 0.5 # for compatibility mode layer_mesh = layer_data.build(material_color_map, line_type_brightness) if self._abort_requested: From 5f6ed488d1693f8f422364d2537b46b38fcdf258 Mon Sep 17 00:00:00 2001 From: Jack Ha Date: Mon, 30 Jan 2017 11:39:59 +0100 Subject: [PATCH 28/54] Layerview removed Color Only Selected Extruder, cleanup 3d shader. CURA-3273 --- plugins/LayerView/LayerPass.py | 2 -- plugins/LayerView/LayerView.py | 8 -------- plugins/LayerView/LayerView.qml | 7 ------- plugins/LayerView/LayerViewProxy.py | 6 ------ plugins/LayerView/layers3d.shader | 8 -------- 5 files changed, 31 deletions(-) diff --git a/plugins/LayerView/LayerPass.py b/plugins/LayerView/LayerPass.py index f01e4b56c2..7ae024181d 100644 --- a/plugins/LayerView/LayerPass.py +++ b/plugins/LayerView/LayerPass.py @@ -45,7 +45,6 @@ class LayerPass(RenderPass): self._layer_shader.setUniformValue("u_active_extruder", float(max(0, self._extruder_manager.activeExtruderIndex))) if self._layer_view: self._layer_shader.setUniformValue("u_layer_view_type", self._layer_view.getLayerViewType()) - self._layer_shader.setUniformValue("u_only_color_active_extruder", (1 if self._layer_view.getOnlyColorActiveExtruder() else 0)) self._layer_shader.setUniformValue("u_extruder_opacity", self._layer_view.getExtruderOpacities()) self._layer_shader.setUniformValue("u_show_travel_moves", self._layer_view.getShowTravelMoves()) self._layer_shader.setUniformValue("u_show_support", self._layer_view.getShowSupport()) @@ -55,7 +54,6 @@ class LayerPass(RenderPass): else: #defaults self._layer_shader.setUniformValue("u_layer_view_type", 1) - self._layer_shader.setUniformValue("u_only_color_active_extruder", 1) self._layer_shader.setUniformValue("u_extruder_opacity", [1, 1, 1, 1]) self._layer_shader.setUniformValue("u_show_travel_moves", 0) self._layer_shader.setUniformValue("u_show_support", 1) diff --git a/plugins/LayerView/LayerView.py b/plugins/LayerView/LayerView.py index 15a79c4412..8f8d9dbd0a 100644 --- a/plugins/LayerView/LayerView.py +++ b/plugins/LayerView/LayerView.py @@ -60,7 +60,6 @@ class LayerView(View): self._controller.getScene().getRoot().childrenChanged.connect(self._onSceneChanged) self._layer_view_type = 0 # 0 is material color, 1 is color by linetype, 2 is speed - self._only_color_active_extruder = True self._extruder_opacity = [1.0, 1.0, 1.0, 1.0] self._show_travel_moves = 0 self._show_support = 1 @@ -167,13 +166,6 @@ class LayerView(View): def getLayerViewType(self): return self._layer_view_type - def setOnlyColorActiveExtruder(self, only_color_active_extruder): - self._only_color_active_extruder = only_color_active_extruder - self.currentLayerNumChanged.emit() - - def getOnlyColorActiveExtruder(self): - return self._only_color_active_extruder - def setExtruderOpacity(self, extruder_nr, opacity): self._extruder_opacity[extruder_nr] = opacity self.currentLayerNumChanged.emit() diff --git a/plugins/LayerView/LayerView.qml b/plugins/LayerView/LayerView.qml index d7ea4282d2..aeb163855e 100644 --- a/plugins/LayerView/LayerView.qml +++ b/plugins/LayerView/LayerView.qml @@ -247,13 +247,6 @@ Item } text: "Show infill" } - CheckBox { - checked: true - onClicked: { - UM.LayerView.setOnlyColorActiveExtruder(checked); - } - text: "Only color active extruder" - } } } } diff --git a/plugins/LayerView/LayerViewProxy.py b/plugins/LayerView/LayerViewProxy.py index ac87ca904d..3de360306a 100644 --- a/plugins/LayerView/LayerViewProxy.py +++ b/plugins/LayerView/LayerViewProxy.py @@ -84,12 +84,6 @@ class LayerViewProxy(QObject): return active_view.getLayerViewType() return 0 - @pyqtSlot(bool) - def setOnlyColorActiveExtruder(self, only_color_active_extruder): - active_view = self._controller.getActiveView() - if type(active_view) == LayerView.LayerView.LayerView: - active_view.setOnlyColorActiveExtruder(only_color_active_extruder) - # Opacity 0..1 @pyqtSlot(int, float) def setExtruderOpacity(self, extruder_nr, opacity): diff --git a/plugins/LayerView/layers3d.shader b/plugins/LayerView/layers3d.shader index 03a4015b3c..943e9bd64e 100644 --- a/plugins/LayerView/layers3d.shader +++ b/plugins/LayerView/layers3d.shader @@ -3,10 +3,8 @@ vertex = #version 410 uniform highp mat4 u_modelMatrix; uniform highp mat4 u_viewProjectionMatrix; - //uniform highp mat4 u_modelViewProjectionMatrix; uniform lowp float u_active_extruder; uniform lowp int u_layer_view_type; - uniform lowp int u_only_color_active_extruder; uniform lowp vec4 u_extruder_opacity; // currently only for max 4 extruders, others always visible uniform highp mat4 u_normalMatrix; @@ -20,11 +18,9 @@ vertex = attribute highp int a_line_type; varying lowp vec4 v_color; - //varying lowp vec4 v_material_color; varying highp vec3 v_vertex; varying highp vec3 v_normal; - //varying lowp vec2 v_uvs; varying lowp vec2 v_line_dim; varying highp int v_extruder; varying highp vec4 v_extruder_opacity; @@ -52,9 +48,6 @@ vertex = v_color = a_color; break; } - if ((u_only_color_active_extruder == 1) && (a_line_type != 8) && (a_line_type != 9)) { - v_color = (a_extruder == u_active_extruder) ? v_color : vec4(0.4, 0.4, 0.4, v_color.a); - } v_vertex = world_space_vert.xyz; v_normal = (u_normalMatrix * normalize(a_normal)).xyz; @@ -323,7 +316,6 @@ fragment = [defaults] u_active_extruder = 0.0 u_layer_view_type = 0 -u_only_color_active_extruder = 1 u_extruder_opacity = [1.0, 1.0, 1.0, 1.0] u_specularColor = [0.4, 0.4, 0.4, 1.0] From 5a2aa8846b7c0afcdbb4e18314ed2e5cdcc63b40 Mon Sep 17 00:00:00 2001 From: Jack Ha Date: Mon, 30 Jan 2017 13:29:35 +0100 Subject: [PATCH 29/54] Added extruder count detection to layer view. CURA-3273 --- cura/Settings/ExtruderManager.py | 1 + plugins/LayerView/LayerView.py | 25 ++++++++++++++++++------- plugins/LayerView/LayerView.qml | 24 ++++++++++++++++++++++-- plugins/LayerView/LayerViewProxy.py | 14 +++++++++++++- 4 files changed, 54 insertions(+), 10 deletions(-) diff --git a/cura/Settings/ExtruderManager.py b/cura/Settings/ExtruderManager.py index 81579f74d0..4e59df9597 100644 --- a/cura/Settings/ExtruderManager.py +++ b/cura/Settings/ExtruderManager.py @@ -50,6 +50,7 @@ class ExtruderManager(QObject): except KeyError: # Extruder index could be -1 if the global tab is selected, or the entry doesn't exist if the machine definition is wrong. return None + ## Return extruder count according to extruder trains. @pyqtProperty(int, notify = extrudersChanged) def extruderCount(self): if not UM.Application.getInstance().getGlobalContainerStack(): diff --git a/plugins/LayerView/LayerView.py b/plugins/LayerView/LayerView.py index 8f8d9dbd0a..922966854d 100644 --- a/plugins/LayerView/LayerView.py +++ b/plugins/LayerView/LayerView.py @@ -18,6 +18,7 @@ from UM.Message import Message from UM.Application import Application from cura.ConvexHullNode import ConvexHullNode +from cura.Settings.ExtruderManager import ExtruderManager from PyQt5.QtCore import Qt from PyQt5.QtWidgets import QApplication @@ -59,13 +60,7 @@ class LayerView(View): self._proxy = LayerViewProxy.LayerViewProxy() self._controller.getScene().getRoot().childrenChanged.connect(self._onSceneChanged) - self._layer_view_type = 0 # 0 is material color, 1 is color by linetype, 2 is speed - self._extruder_opacity = [1.0, 1.0, 1.0, 1.0] - self._show_travel_moves = 0 - self._show_support = 1 - self._show_adhesion = 1 - self._show_skin = 1 - self._show_infill = 1 + self._resetSettings() self._legend_items = None Preferences.getInstance().addPreference("view/top_layer_count", 5) @@ -80,6 +75,16 @@ class LayerView(View): self._wireprint_warning_message = Message(catalog.i18nc("@info:status", "Cura does not accurately display layers when Wire Printing is enabled")) + def _resetSettings(self): + self._layer_view_type = 0 # 0 is material color, 1 is color by linetype, 2 is speed + self._extruder_count = 0 + self._extruder_opacity = [1.0, 1.0, 1.0, 1.0] + self._show_travel_moves = 0 + self._show_support = 1 + self._show_adhesion = 1 + self._show_skin = 1 + self._show_infill = 1 + def getActivity(self): return self._activity @@ -211,6 +216,9 @@ class LayerView(View): def getCompatibilityMode(self): return self._compatibility_mode + def getExtruderCount(self): + return self._extruder_count + def calculateMaxLayers(self): scene = self.getController().getScene() self._activity = True @@ -242,6 +250,7 @@ class LayerView(View): maxLayersChanged = Signal() currentLayerNumChanged = Signal() + globalStackChanged = Signal() ## Hackish way to ensure the proxy is already created, which ensures that the layerview.qml is already created # as this caused some issues. @@ -302,7 +311,9 @@ class LayerView(View): self._global_container_stack = Application.getInstance().getGlobalContainerStack() if self._global_container_stack: self._global_container_stack.propertyChanged.connect(self._onPropertyChanged) + self._extruder_count = self._global_container_stack.getProperty("machine_extruder_count", "value") self._onPropertyChanged("wireframe_enabled", "value") + self.globalStackChanged.emit() else: self._wireprint_warning_message.hide() diff --git a/plugins/LayerView/LayerView.qml b/plugins/LayerView/LayerView.qml index aeb163855e..b60f158e3b 100644 --- a/plugins/LayerView/LayerView.qml +++ b/plugins/LayerView/LayerView.qml @@ -203,7 +203,7 @@ Item UM.LayerView.setExtruderOpacity(0, checked ? 1.0 : 0.0); } text: "Extruder 1" - visible: !UM.LayerView.compatibilityMode + visible: !UM.LayerView.compatibilityMode && (UM.LayerView.getExtruderCount >= 1) } CheckBox { checked: true @@ -211,7 +211,27 @@ Item UM.LayerView.setExtruderOpacity(1, checked ? 1.0 : 0.0); } text: "Extruder 2" - visible: !UM.LayerView.compatibilityMode + visible: !UM.LayerView.compatibilityMode && (UM.LayerView.getExtruderCount >= 2) + } + CheckBox { + checked: true + onClicked: { + UM.LayerView.setExtruderOpacity(2, checked ? 1.0 : 0.0); + } + text: "Extruder 3" + visible: !UM.LayerView.compatibilityMode && (UM.LayerView.getExtruderCount >= 3) + } + CheckBox { + checked: true + onClicked: { + UM.LayerView.setExtruderOpacity(3, checked ? 1.0 : 0.0); + } + text: "Extruder 4" + visible: !UM.LayerView.compatibilityMode && (UM.LayerView.getExtruderCount >= 4) + } + Label { + text: "Other extruders always visible" + visible: !UM.LayerView.compatibilityMode && (UM.LayerView.getExtruderCount >= 5) } CheckBox { onClicked: { diff --git a/plugins/LayerView/LayerViewProxy.py b/plugins/LayerView/LayerViewProxy.py index 3de360306a..7eb4cc65da 100644 --- a/plugins/LayerView/LayerViewProxy.py +++ b/plugins/LayerView/LayerViewProxy.py @@ -16,6 +16,7 @@ class LayerViewProxy(QObject): currentLayerChanged = pyqtSignal() maxLayersChanged = pyqtSignal() activityChanged = pyqtSignal() + globalStackChanged = pyqtSignal() @pyqtProperty(bool, notify = activityChanged) def getLayerActivity(self): @@ -121,6 +122,13 @@ class LayerViewProxy(QObject): if type(active_view) == LayerView.LayerView.LayerView: active_view.setShowInfill(show) + @pyqtProperty(int, notify = globalStackChanged) + def getExtruderCount(self): + active_view = self._controller.getActiveView() + if type(active_view) == LayerView.LayerView.LayerView: + return active_view.getExtruderCount() + return 0 + def _layerActivityChanged(self): self.activityChanged.emit() @@ -133,10 +141,14 @@ class LayerViewProxy(QObject): def _onBusyChanged(self): self.busyChanged.emit() - + + def _onGlobalStackChanged(self): + self.globalStackChanged.emit() + def _onActiveViewChanged(self): active_view = self._controller.getActiveView() if type(active_view) == LayerView.LayerView.LayerView: active_view.currentLayerNumChanged.connect(self._onLayerChanged) active_view.maxLayersChanged.connect(self._onMaxLayersChanged) active_view.busyChanged.connect(self._onBusyChanged) + active_view.globalStackChanged.connect(self._onGlobalStackChanged) From aa923321f80aafa6ed473746f73f2d9e98fd7121 Mon Sep 17 00:00:00 2001 From: Jack Ha Date: Tue, 31 Jan 2017 09:19:18 +0100 Subject: [PATCH 30/54] Fix compatibility mode layout. CURA-3273 --- plugins/LayerView/LayerView.qml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/LayerView/LayerView.qml b/plugins/LayerView/LayerView.qml index b60f158e3b..9c877769bc 100644 --- a/plugins/LayerView/LayerView.qml +++ b/plugins/LayerView/LayerView.qml @@ -173,7 +173,7 @@ Item ComboBox { - id: layer_type_combobox + id: layerTypeCombobox anchors.top: slider_background.bottom anchors.left: parent.left model: layerViewTypes @@ -185,6 +185,7 @@ Item Label { + id: compatibilityModeLabel anchors.top: slider_background.bottom anchors.left: parent.left text: catalog.i18nc("@label","Compatibility mode") @@ -193,7 +194,7 @@ Item ColumnLayout { id: view_settings - anchors.top: layer_type_combobox.bottom + anchors.top: UM.LayerView.compatibilityMode ? compatibilityModeLabel.bottom : layerTypeCombobox.bottom anchors.topMargin: UM.Theme.getSize("default_margin").height x: UM.Theme.getSize("default_margin").width From e31a6950614e5fa8a031fb8a68c037fb685581a9 Mon Sep 17 00:00:00 2001 From: Jack Ha Date: Tue, 31 Jan 2017 17:05:00 +0100 Subject: [PATCH 31/54] WIP OpenGL 4.1 core profile. CURA-3273 --- resources/shaders/grid.shader | 31 ++++++++++ resources/shaders/overhang.shader | 67 ++++++++++++++++++++ resources/shaders/striped.shader | 68 +++++++++++++++++++++ resources/shaders/transparent_object.shader | 53 ++++++++++++++++ 4 files changed, 219 insertions(+) diff --git a/resources/shaders/grid.shader b/resources/shaders/grid.shader index c05b9ba15c..74eed544fd 100644 --- a/resources/shaders/grid.shader +++ b/resources/shaders/grid.shader @@ -27,6 +27,37 @@ fragment = 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] diff --git a/resources/shaders/overhang.shader b/resources/shaders/overhang.shader index 4e5999a693..b9cf53f8b7 100644 --- a/resources/shaders/overhang.shader +++ b/resources/shaders/overhang.shader @@ -62,6 +62,73 @@ fragment = gl_FragColor.a = 1.0; } +vertex41core = + #version 410 + uniform highp mat4 u_modelMatrix; + uniform highp mat4 u_viewProjectionMatrix; + uniform highp mat4 u_normalMatrix; + + in highp vec4 a_vertex; + in highp vec4 a_normal; + in highp vec2 a_uvs; + + out highp vec3 f_vertex; + out highp vec3 f_normal; + + void main() + { + vec4 world_space_vert = u_modelMatrix * a_vertex; + gl_Position = u_viewProjectionMatrix * world_space_vert; + + f_vertex = world_space_vert.xyz; + f_normal = (u_normalMatrix * normalize(a_normal)).xyz; + } + +fragment41core = + #version 410 + uniform mediump vec4 u_ambientColor; + uniform mediump vec4 u_diffuseColor; + uniform mediump vec4 u_specularColor; + uniform highp vec3 u_lightPosition; + uniform mediump float u_shininess; + uniform highp vec3 u_viewPosition; + + uniform lowp float u_overhangAngle; + uniform lowp vec4 u_overhangColor; + + in highp vec3 f_vertex; + in highp vec3 f_normal; + + out vec4 frag_color; + + void main() + { + + mediump vec4 finalColor = vec4(0.0); + + // Ambient Component + finalColor += u_ambientColor; + + highp vec3 normal = normalize(f_normal); + highp vec3 lightDir = normalize(u_lightPosition - f_vertex); + + // Diffuse Component + highp float NdotL = clamp(abs(dot(normal, lightDir)), 0.0, 1.0); + finalColor += (NdotL * u_diffuseColor); + + // Specular Component + // TODO: We should not do specularity for fragments facing away from the light. + highp vec3 reflectedLight = reflect(-lightDir, normal); + highp vec3 viewVector = normalize(u_viewPosition - f_vertex); + highp float NdotR = clamp(dot(viewVector, reflectedLight), 0.0, 1.0); + finalColor += pow(NdotR, u_shininess) * u_specularColor; + + finalColor = (-normal.y > u_overhangAngle) ? u_overhangColor : finalColor; + + frag_color = finalColor; + frag_color.a = 1.0; + } + [defaults] u_ambientColor = [0.3, 0.3, 0.3, 1.0] u_diffuseColor = [1.0, 0.79, 0.14, 1.0] diff --git a/resources/shaders/striped.shader b/resources/shaders/striped.shader index 0114f0b2cb..ce7d14e39e 100644 --- a/resources/shaders/striped.shader +++ b/resources/shaders/striped.shader @@ -63,6 +63,74 @@ fragment = gl_FragColor.a = 1.0; } +vertex41core = + #version 410 + uniform highp mat4 u_modelMatrix; + uniform highp mat4 u_viewProjectionMatrix; + uniform highp mat4 u_normalMatrix; + + in highp vec4 a_vertex; + in highp vec4 a_normal; + in highp vec2 a_uvs; + + out highp vec3 v_position; + out highp vec3 v_vertex; + out highp vec3 v_normal; + + void main() + { + vec4 world_space_vert = u_modelMatrix * a_vertex; + gl_Position = u_viewProjectionMatrix * world_space_vert; + + v_position = gl_Position.xyz; + v_vertex = world_space_vert.xyz; + v_normal = (u_normalMatrix * normalize(a_normal)).xyz; + } + +fragment41core = + #version 410 + uniform mediump vec4 u_ambientColor; + uniform mediump vec4 u_diffuseColor1; + uniform mediump vec4 u_diffuseColor2; + uniform mediump vec4 u_specularColor; + uniform highp vec3 u_lightPosition; + uniform mediump float u_shininess; + uniform highp vec3 u_viewPosition; + + uniform mediump float u_width; + + in highp vec3 v_position; + in highp vec3 v_vertex; + in highp vec3 v_normal; + + out vec4 frag_color; + + void main() + { + mediump vec4 finalColor = vec4(0.0); + mediump vec4 diffuseColor = (mod((-v_position.x + v_position.y), u_width) < (u_width / 2.)) ? u_diffuseColor1 : u_diffuseColor2; + + /* Ambient Component */ + finalColor += u_ambientColor; + + highp vec3 normal = normalize(v_normal); + highp vec3 lightDir = normalize(u_lightPosition - v_vertex); + + /* Diffuse Component */ + highp float NdotL = clamp(abs(dot(normal, lightDir)), 0.0, 1.0); + finalColor += (NdotL * diffuseColor); + + /* Specular Component */ + /* TODO: We should not do specularity for fragments facing away from the light.*/ + highp vec3 reflectedLight = reflect(-lightDir, normal); + highp vec3 viewVector = normalize(u_viewPosition - v_vertex); + highp float NdotR = clamp(dot(viewVector, reflectedLight), 0.0, 1.0); + finalColor += pow(NdotR, u_shininess) * u_specularColor; + + frag_color = finalColor; + frag_color.a = 1.0; + } + [defaults] u_ambientColor = [0.3, 0.3, 0.3, 1.0] u_diffuseColor1 = [1.0, 0.5, 0.5, 1.0] diff --git a/resources/shaders/transparent_object.shader b/resources/shaders/transparent_object.shader index cd27a40769..faa43bb46c 100644 --- a/resources/shaders/transparent_object.shader +++ b/resources/shaders/transparent_object.shader @@ -48,6 +48,59 @@ fragment = gl_FragColor.a = u_opacity; } +vertex41core = + #version 410 + uniform highp mat4 u_modelMatrix; + uniform highp mat4 u_viewProjectionMatrix; + uniform highp mat4 u_normalMatrix; + + in highp vec4 a_vertex; + in highp vec4 a_normal; + in highp vec2 a_uvs; + + out highp vec3 v_vertex; + out highp vec3 v_normal; + + void main() + { + vec4 world_space_vert = u_modelMatrix * a_vertex; + gl_Position = u_viewProjectionMatrix * world_space_vert; + + v_vertex = world_space_vert.xyz; + v_normal = (u_normalMatrix * normalize(a_normal)).xyz; + } + +fragment41core = + #version 410 + uniform mediump vec4 u_ambientColor; + uniform mediump vec4 u_diffuseColor; + uniform highp vec3 u_lightPosition; + + uniform mediump float u_opacity; + + in highp vec3 v_vertex; + in highp vec3 v_normal; + + out vec4 frag_color; + + void main() + { + mediump vec4 finalColor = vec4(0.0); + + /* Ambient Component */ + finalColor += u_ambientColor; + + highp vec3 normal = normalize(v_normal); + highp vec3 lightDir = normalize(u_lightPosition - v_vertex); + + /* Diffuse Component */ + highp float NdotL = clamp(abs(dot(normal, lightDir)), 0.0, 1.0); + finalColor += (NdotL * u_diffuseColor); + + frag_color = finalColor; + frag_color.a = u_opacity; + } + [defaults] u_ambientColor = [0.1, 0.1, 0.1, 1.0] u_diffuseColor = [0.4, 0.4, 0.4, 1.0] From 4bb8e1b0252b5d9bf1974d3a55366292ad1ecf61 Mon Sep 17 00:00:00 2001 From: Jack Ha Date: Wed, 1 Feb 2017 16:10:52 +0100 Subject: [PATCH 32/54] Converted layers3d.shader to 41core spec. Contributes to CURA-3273 --- plugins/LayerView/layers3d.shader | 52 ++++++++++++++++--------------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/plugins/LayerView/layers3d.shader b/plugins/LayerView/layers3d.shader index 943e9bd64e..c066c7cc6f 100644 --- a/plugins/LayerView/layers3d.shader +++ b/plugins/LayerView/layers3d.shader @@ -1,5 +1,5 @@ [shaders] -vertex = +vertex41core = #version 410 uniform highp mat4 u_modelMatrix; uniform highp mat4 u_viewProjectionMatrix; @@ -9,27 +9,27 @@ vertex = uniform highp mat4 u_normalMatrix; - attribute highp vec4 a_vertex; - attribute lowp vec4 a_color; - attribute lowp vec4 a_material_color; - attribute highp vec4 a_normal; - attribute highp vec2 a_line_dim; // line width and thickness - attribute highp int a_extruder; - attribute highp int a_line_type; + in highp vec4 a_vertex; + in lowp vec4 a_color; + in lowp vec4 a_material_color; + in highp vec4 a_normal; + in highp vec2 a_line_dim; // line width and thickness + in highp int a_extruder; + in highp int a_line_type; - varying lowp vec4 v_color; + out lowp vec4 v_color; - varying highp vec3 v_vertex; - varying highp vec3 v_normal; - varying lowp vec2 v_line_dim; - varying highp int v_extruder; - varying highp vec4 v_extruder_opacity; - varying int v_line_type; + out highp vec3 v_vertex; + out highp vec3 v_normal; + out lowp vec2 v_line_dim; + out highp int v_extruder; + out highp vec4 v_extruder_opacity; + out int v_line_type; - varying lowp vec4 f_color; - varying highp vec3 f_vertex; - varying highp vec3 f_normal; - varying highp int f_extruder; + out lowp vec4 f_color; + out highp vec3 f_vertex; + out highp vec3 f_normal; + out highp int f_extruder; void main() { @@ -62,7 +62,7 @@ vertex = f_normal = v_normal;*/ } -geometry = +geometry41core = #version 410 uniform highp mat4 u_viewProjectionMatrix; @@ -285,11 +285,13 @@ geometry = EndPrimitive(); } -fragment = +fragment41core = #version 410 - varying lowp vec4 f_color; - varying lowp vec3 f_normal; - varying lowp vec3 f_vertex; + in lowp vec4 f_color; + in lowp vec3 f_normal; + in lowp vec3 f_vertex; + + out vec4 frag_color; uniform mediump vec4 u_ambientColor; uniform highp vec3 u_lightPosition; @@ -309,7 +311,7 @@ fragment = finalColor += (NdotL * f_color); finalColor.a = alpha; // Do not change alpha in any way - gl_FragColor = finalColor; + frag_color = finalColor; } From 4659d8616eacf3d78b76903d0080f476a45ec13f Mon Sep 17 00:00:00 2001 From: Jack Ha Date: Wed, 1 Feb 2017 16:29:21 +0100 Subject: [PATCH 33/54] Fixed some opengl 4.1 core vertex and fragment shaders, layerview anchor. CURA-3273 --- plugins/LayerView/LayerView.qml | 4 +- plugins/LayerView/layerview_composite.shader | 68 ++++++++++++++++++++ plugins/XRayView/xray.shader | 22 +++++++ 3 files changed, 92 insertions(+), 2 deletions(-) diff --git a/plugins/LayerView/LayerView.qml b/plugins/LayerView/LayerView.qml index 9c877769bc..ee109b7f04 100644 --- a/plugins/LayerView/LayerView.qml +++ b/plugins/LayerView/LayerView.qml @@ -174,7 +174,7 @@ Item ComboBox { id: layerTypeCombobox - anchors.top: slider_background.bottom + anchors.top: parent.top anchors.left: parent.left model: layerViewTypes visible: !UM.LayerView.compatibilityMode @@ -186,7 +186,7 @@ Item Label { id: compatibilityModeLabel - anchors.top: slider_background.bottom + anchors.top: parent.top anchors.left: parent.left text: catalog.i18nc("@label","Compatibility mode") visible: UM.LayerView.compatibilityMode diff --git a/plugins/LayerView/layerview_composite.shader b/plugins/LayerView/layerview_composite.shader index 61d61bb901..f203650ce6 100644 --- a/plugins/LayerView/layerview_composite.shader +++ b/plugins/LayerView/layerview_composite.shader @@ -63,6 +63,74 @@ fragment = } } +vertex41core = + #version 410 + uniform highp mat4 u_modelViewProjectionMatrix; + in highp vec4 a_vertex; + in highp vec2 a_uvs; + + out highp vec2 v_uvs; + + void main() + { + gl_Position = u_modelViewProjectionMatrix * a_vertex; + v_uvs = a_uvs; + } + +fragment41core = + #version 410 + uniform sampler2D u_layer0; + uniform sampler2D u_layer1; + uniform sampler2D u_layer2; + + uniform vec2 u_offset[9]; + + uniform vec4 u_background_color; + uniform float u_outline_strength; + uniform vec4 u_outline_color; + + in vec2 v_uvs; + + float kernel[9]; + + const vec3 x_axis = vec3(1.0, 0.0, 0.0); + const vec3 y_axis = vec3(0.0, 1.0, 0.0); + const vec3 z_axis = vec3(0.0, 0.0, 1.0); + + out vec4 frag_color; + + void main() + { + kernel[0] = 0.0; kernel[1] = 1.0; kernel[2] = 0.0; + kernel[3] = 1.0; kernel[4] = -4.0; kernel[5] = 1.0; + kernel[6] = 0.0; kernel[7] = 1.0; kernel[8] = 0.0; + + vec4 result = u_background_color; + + vec4 main_layer = texture(u_layer0, v_uvs); + vec4 selection_layer = texture(u_layer1, v_uvs); + vec4 layerview_layer = texture(u_layer2, v_uvs); + + result = main_layer * main_layer.a + result * (1.0 - main_layer.a); + result = layerview_layer * layerview_layer.a + result * (1.0 - layerview_layer.a); + + vec4 sum = vec4(0.0); + for (int i = 0; i < 9; i++) + { + vec4 color = vec4(texture(u_layer1, v_uvs.xy + u_offset[i]).a); + sum += color * (kernel[i] / u_outline_strength); + } + + if((selection_layer.rgb == x_axis || selection_layer.rgb == y_axis || selection_layer.rgb == z_axis)) + { + frag_color = result; + } + else + { + frag_color = mix(result, u_outline_color, abs(sum.a)); + } + } + [defaults] u_layer0 = 0 u_layer1 = 1 diff --git a/plugins/XRayView/xray.shader b/plugins/XRayView/xray.shader index b42b3e056a..41b00154ea 100644 --- a/plugins/XRayView/xray.shader +++ b/plugins/XRayView/xray.shader @@ -17,6 +17,28 @@ fragment = gl_FragColor = u_color; } +vertex41core = + #version 410 + uniform highp mat4 u_modelViewProjectionMatrix; + + in highp vec4 a_vertex; + + void main() + { + gl_Position = u_modelViewProjectionMatrix * a_vertex; + } + +fragment41core = + #version 410 + uniform lowp vec4 u_color; + + out vec4 frag_color; + + void main() + { + frag_color = u_color; + } + [defaults] u_color = [0.02, 0.02, 0.02, 1.0] From 0889722350ac9bfe981e93dbb22efe6dcd451280 Mon Sep 17 00:00:00 2001 From: Jack Ha Date: Thu, 2 Feb 2017 17:08:20 +0100 Subject: [PATCH 34/54] Finishing up opengl 4.1 core profile things, it all works. CURA-3273 --- plugins/LayerView/LayerPass.py | 1 + plugins/LayerView/layers.shader | 88 +++++++++++++++++++++++--- plugins/LayerView/layers3d.shader | 13 ++-- plugins/XRayView/xray_composite.shader | 71 +++++++++++++++++++++ 4 files changed, 157 insertions(+), 16 deletions(-) diff --git a/plugins/LayerView/LayerPass.py b/plugins/LayerView/LayerPass.py index 7ae024181d..9ba245489a 100644 --- a/plugins/LayerView/LayerPass.py +++ b/plugins/LayerView/LayerPass.py @@ -14,6 +14,7 @@ from UM.View.GL.OpenGL import OpenGL from cura.Settings.ExtruderManager import ExtruderManager + import os.path ## RenderPass used to display g-code paths. diff --git a/plugins/LayerView/layers.shader b/plugins/LayerView/layers.shader index b58d11da0c..0999e07e8c 100644 --- a/plugins/LayerView/layers.shader +++ b/plugins/LayerView/layers.shader @@ -4,7 +4,6 @@ vertex = uniform lowp float u_active_extruder; 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_line_type; @@ -19,10 +18,7 @@ vertex = { gl_Position = u_modelViewProjectionMatrix * a_vertex; v_color = a_color; - if ((u_only_color_active_extruder == 1) && (a_line_type != 8) && (a_line_type != 9)) { - 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)) { + if ((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); } @@ -30,8 +26,10 @@ vertex = } fragment = - varying lowp vec4 v_color; - varying float v_line_type; + in lowp vec4 v_color; + in float v_line_type; + + out vec4 frag_color; uniform int u_show_travel_moves; uniform int u_show_support; @@ -70,14 +68,86 @@ fragment = discard; } - gl_FragColor = v_color; + frag_color = v_color; + } + +vertex41core = + #version 410 + uniform highp mat4 u_modelViewProjectionMatrix; + uniform lowp float u_active_extruder; + uniform lowp float u_shade_factor; + uniform highp int u_layer_view_type; + + in highp int a_extruder; + in highp int a_line_type; + in highp vec4 a_vertex; + in lowp vec4 a_color; + in lowp vec4 a_material_color; + + out lowp vec4 v_color; + out float v_line_type; + + void main() + { + gl_Position = u_modelViewProjectionMatrix * a_vertex; + v_color = a_color; + if ((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; + } + +fragment41core = + #version 410 + in lowp vec4 v_color; + in float v_line_type; + out vec4 frag_color; + + 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() + { + 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; + } + + frag_color = v_color; } [defaults] u_active_extruder = 0.0 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 diff --git a/plugins/LayerView/layers3d.shader b/plugins/LayerView/layers3d.shader index c066c7cc6f..a1e412debb 100644 --- a/plugins/LayerView/layers3d.shader +++ b/plugins/LayerView/layers3d.shader @@ -1,6 +1,8 @@ [shaders] vertex41core = #version 410 + uniform highp mat4 u_modelViewProjectionMatrix; + uniform highp mat4 u_modelMatrix; uniform highp mat4 u_viewProjectionMatrix; uniform lowp float u_active_extruder; @@ -29,7 +31,6 @@ vertex41core = out lowp vec4 f_color; out highp vec3 f_vertex; out highp vec3 f_normal; - out highp int f_extruder; void main() { @@ -37,6 +38,7 @@ vertex41core = v1_vertex.y -= a_line_dim.y / 2; // half layer down vec4 world_space_vert = u_modelMatrix * v1_vertex; + //gl_Position = u_modelViewProjectionMatrix * a_vertex; //world_space_vert; gl_Position = world_space_vert; // shade the color depending on the extruder index stored in the alpha component of the color @@ -56,10 +58,10 @@ vertex41core = v_line_type = a_line_type; v_extruder_opacity = u_extruder_opacity; - // for testing and backwards compatibility without geometry shader - /*f_color = v_color; + // for testing without geometry shader + f_color = v_color; f_vertex = v_vertex; - f_normal = v_normal;*/ + f_normal = v_normal; } geometry41core = @@ -86,7 +88,6 @@ geometry41core = out vec4 f_color; out vec3 f_normal; out vec3 f_vertex; - out uint f_extruder; void main() { @@ -130,8 +131,6 @@ geometry41core = size_y = v_line_dim[0].y / 2 + 0.01; } - f_extruder = v_extruder[0]; - g_vertex_delta = gl_in[1].gl_Position - gl_in[0].gl_Position; g_vertex_normal_horz_head = normalize(vec3(-g_vertex_delta.x, -g_vertex_delta.y, -g_vertex_delta.z)); g_vertex_offset_horz_head = vec4(g_vertex_normal_horz_head * size_x, 0.0); diff --git a/plugins/XRayView/xray_composite.shader b/plugins/XRayView/xray_composite.shader index e7a38950bf..82dca52cf9 100644 --- a/plugins/XRayView/xray_composite.shader +++ b/plugins/XRayView/xray_composite.shader @@ -67,6 +67,77 @@ fragment = } } +vertex41core = + #version 410 + uniform highp mat4 u_modelViewProjectionMatrix; + in highp vec4 a_vertex; + in highp vec2 a_uvs; + + out highp vec2 v_uvs; + + void main() + { + gl_Position = u_modelViewProjectionMatrix * a_vertex; + v_uvs = a_uvs; + } + +fragment41core = + #version 410 + uniform sampler2D u_layer0; + uniform sampler2D u_layer1; + uniform sampler2D u_layer2; + + uniform vec2 u_offset[9]; + + uniform float u_outline_strength; + uniform vec4 u_outline_color; + uniform vec4 u_error_color; + uniform vec4 u_background_color; + + const vec3 x_axis = vec3(1.0, 0.0, 0.0); + const vec3 y_axis = vec3(0.0, 1.0, 0.0); + const vec3 z_axis = vec3(0.0, 0.0, 1.0); + + in vec2 v_uvs; + out vec4 frag_color; + + float kernel[9]; + + void main() + { + kernel[0] = 0.0; kernel[1] = 1.0; kernel[2] = 0.0; + kernel[3] = 1.0; kernel[4] = -4.0; kernel[5] = 1.0; + kernel[6] = 0.0; kernel[7] = 1.0; kernel[8] = 0.0; + + vec4 result = u_background_color; + vec4 layer0 = texture(u_layer0, v_uvs); + + result = layer0 * layer0.a + result * (1.0 - layer0.a); + + float intersection_count = (texture(u_layer2, v_uvs).r * 255.0) / 5.0; + if(mod(intersection_count, 2.0) == 1.0) + { + result = u_error_color; + } + + vec4 sum = vec4(0.0); + for (int i = 0; i < 9; i++) + { + vec4 color = vec4(texture(u_layer1, v_uvs.xy + u_offset[i]).a); + sum += color * (kernel[i] / u_outline_strength); + } + + vec4 layer1 = texture(u_layer1, v_uvs); + if((layer1.rgb == x_axis || layer1.rgb == y_axis || layer1.rgb == z_axis)) + { + frag_color = result; + } + else + { + frag_color = mix(result, vec4(abs(sum.a)) * u_outline_color, abs(sum.a)); + } + } + [defaults] u_layer0 = 0 u_layer1 = 1 From 7c964045dbb5ae799119661de04cbbf8eac7a456 Mon Sep 17 00:00:00 2001 From: Jack Ha Date: Mon, 6 Feb 2017 13:16:47 +0100 Subject: [PATCH 35/54] Removed unused line in shader. CURA-3273 --- plugins/LayerView/layers3d.shader | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/LayerView/layers3d.shader b/plugins/LayerView/layers3d.shader index a1e412debb..c7c7628a92 100644 --- a/plugins/LayerView/layers3d.shader +++ b/plugins/LayerView/layers3d.shader @@ -38,7 +38,6 @@ vertex41core = v1_vertex.y -= a_line_dim.y / 2; // half layer down vec4 world_space_vert = u_modelMatrix * v1_vertex; - //gl_Position = u_modelViewProjectionMatrix * a_vertex; //world_space_vert; gl_Position = world_space_vert; // shade the color depending on the extruder index stored in the alpha component of the color From 1d778649154112cb138f9c20aba41b869c7fb3dd Mon Sep 17 00:00:00 2001 From: Jack Ha Date: Tue, 7 Feb 2017 09:36:21 +0100 Subject: [PATCH 36/54] Added force layer view compatibility mode. CURA-3273 --- cura/CuraApplication.py | 1 + plugins/LayerView/LayerView.py | 3 +-- resources/qml/Preferences/GeneralPage.qml | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index e6e1d08afb..720f5b8fb7 100644 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -223,6 +223,7 @@ class CuraApplication(QtApplication): Preferences.getInstance().addPreference("mesh/scale_tiny_meshes", True) Preferences.getInstance().addPreference("cura/dialog_on_project_save", True) Preferences.getInstance().addPreference("cura/asked_dialog_on_project_save", False) + Preferences.getInstance().addPreference("view/force_layer_view_compatibility_mode", False) Preferences.getInstance().addPreference("cura/currency", "€") Preferences.getInstance().addPreference("cura/material_settings", "{}") diff --git a/plugins/LayerView/LayerView.py b/plugins/LayerView/LayerView.py index 922966854d..a5e07513a7 100644 --- a/plugins/LayerView/LayerView.py +++ b/plugins/LayerView/LayerView.py @@ -65,7 +65,6 @@ class LayerView(View): Preferences.getInstance().addPreference("view/top_layer_count", 5) Preferences.getInstance().addPreference("view/only_show_top_layers", False) - Preferences.getInstance().addPreference("view/compatibility_mode", True) # Default True for now, needs testing of different computers Preferences.getInstance().preferenceChanged.connect(self._onPreferencesChanged) @@ -93,7 +92,7 @@ class LayerView(View): # Currently the RenderPass constructor requires a size > 0 # This should be fixed in RenderPass's constructor. self._layer_pass = LayerPass.LayerPass(1, 1) - self._compatibility_mode = not self.getRenderer().getSupportsGeometryShader() + self._compatibility_mode = not self.getRenderer().getSupportsGeometryShader() or bool(Preferences.getInstance().getValue("view/force_layer_view_compatibility_mode")) self._layer_pass.setLayerView(self) self.getRenderer().addRenderPass(self._layer_pass) return self._layer_pass diff --git a/resources/qml/Preferences/GeneralPage.qml b/resources/qml/Preferences/GeneralPage.qml index ee300989a4..9b6f32f114 100644 --- a/resources/qml/Preferences/GeneralPage.qml +++ b/resources/qml/Preferences/GeneralPage.qml @@ -265,6 +265,20 @@ UM.PreferencesPage } } + UM.TooltipArea { + width: childrenRect.width + height: childrenRect.height + text: catalog.i18nc("@info:tooltip", "Should layer be forced into compatibility mode?") + + CheckBox + { + id: forceLayerViewCompatibilityModeCheckbox + text: catalog.i18nc("@option:check", "Force layer view compatibility mode (restart required)") + checked: boolCheck(UM.Preferences.getValue("view/force_layer_view_compatibility_mode")) + onCheckedChanged: UM.Preferences.setValue("view/force_layer_view_compatibility_mode", checked) + } + } + Item { //: Spacer From 4b02a425d8a8fc11423cbb2cafc0ed3e19e22309 Mon Sep 17 00:00:00 2001 From: Jack Ha Date: Tue, 7 Feb 2017 11:55:51 +0100 Subject: [PATCH 37/54] Let Layer View compatibility mode depend on OpenGL version we asked for (may be different than actual). CURA-3273 --- plugins/LayerView/LayerView.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/LayerView/LayerView.py b/plugins/LayerView/LayerView.py index a5e07513a7..468fc01ec3 100644 --- a/plugins/LayerView/LayerView.py +++ b/plugins/LayerView/LayerView.py @@ -16,6 +16,7 @@ from UM.Logger import Logger from UM.View.GL.OpenGL import OpenGL from UM.Message import Message from UM.Application import Application +from UM.View.GL.OpenGLContext import OpenGLContext from cura.ConvexHullNode import ConvexHullNode from cura.Settings.ExtruderManager import ExtruderManager @@ -92,7 +93,7 @@ class LayerView(View): # Currently the RenderPass constructor requires a size > 0 # This should be fixed in RenderPass's constructor. self._layer_pass = LayerPass.LayerPass(1, 1) - self._compatibility_mode = not self.getRenderer().getSupportsGeometryShader() or bool(Preferences.getInstance().getValue("view/force_layer_view_compatibility_mode")) + self._compatibility_mode = OpenGLContext.isLegacyOpenGL() or bool(Preferences.getInstance().getValue("view/force_layer_view_compatibility_mode")) self._layer_pass.setLayerView(self) self.getRenderer().addRenderPass(self._layer_pass) return self._layer_pass From ed1fea2d3eb44e3ad7d52d6168ad3eb105697844 Mon Sep 17 00:00:00 2001 From: Jack Ha Date: Tue, 7 Feb 2017 13:20:26 +0100 Subject: [PATCH 38/54] Fix colors of compatibility mode. CURA-3273 --- plugins/CuraEngineBackend/ProcessSlicedLayersJob.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py b/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py index 1dbcbdb3b7..21227e7a8b 100644 --- a/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py +++ b/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py @@ -9,6 +9,7 @@ from UM.Scene.SceneNode import SceneNode from UM.Application import Application from UM.Mesh.MeshData import MeshData from UM.Preferences import Preferences +from UM.View.GL.OpenGLContext import OpenGLContext from UM.Message import Message from UM.i18n import i18nCatalog @@ -180,10 +181,10 @@ class ProcessSlicedLayersJob(Job): material_color_map[0, :] = color # We have to scale the colors for compatibility mode - if Application.getInstance().getRenderer().getSupportsGeometryShader(): - line_type_brightness = 1.0 - else: + if OpenGLContext.isLegacyOpenGL() or bool(Preferences.getInstance().getValue("view/force_layer_view_compatibility_mode")): line_type_brightness = 0.5 # for compatibility mode + else: + line_type_brightness = 1.0 layer_mesh = layer_data.build(material_color_map, line_type_brightness) if self._abort_requested: From 4057996e2395b6c1736bb9781d09a5a866585dc0 Mon Sep 17 00:00:00 2001 From: Jack Ha Date: Tue, 7 Feb 2017 14:28:22 +0100 Subject: [PATCH 39/54] Made layers.shader compatibility shader compatible. CURA-3273 --- plugins/LayerView/layers.shader | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/plugins/LayerView/layers.shader b/plugins/LayerView/layers.shader index 0999e07e8c..88717e8774 100644 --- a/plugins/LayerView/layers.shader +++ b/plugins/LayerView/layers.shader @@ -26,10 +26,8 @@ vertex = } fragment = - in lowp vec4 v_color; - in float v_line_type; - - out vec4 frag_color; + varying lowp vec4 v_color; + varying float v_line_type; uniform int u_show_travel_moves; uniform int u_show_support; @@ -68,7 +66,7 @@ fragment = discard; } - frag_color = v_color; + gl_FragColor = u_color; } vertex41core = From 74bef2ff951ef2a29fb4db72f1eed2667f58e234 Mon Sep 17 00:00:00 2001 From: Arjen Hiemstra Date: Tue, 7 Feb 2017 17:34:02 +0100 Subject: [PATCH 40/54] Fix OpenGL 2.0 fallback shader for Layer View --- plugins/LayerView/layers.shader | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/LayerView/layers.shader b/plugins/LayerView/layers.shader index 88717e8774..81d5c94dff 100644 --- a/plugins/LayerView/layers.shader +++ b/plugins/LayerView/layers.shader @@ -5,8 +5,8 @@ vertex = uniform lowp float u_shade_factor; uniform highp int u_layer_view_type; - attribute highp int a_extruder; - attribute highp int a_line_type; + attribute highp float a_extruder; + attribute highp float a_line_type; attribute highp vec4 a_vertex; attribute lowp vec4 a_color; attribute lowp vec4 a_material_color; @@ -18,7 +18,7 @@ vertex = { gl_Position = u_modelViewProjectionMatrix * a_vertex; v_color = a_color; - if ((a_line_type != 8) && (a_line_type != 9)) { + if ((a_line_type != 8.0) && (a_line_type != 9.0)) { v_color = (a_extruder == u_active_extruder) ? v_color : vec4(u_shade_factor * v_color.rgb, v_color.a); } @@ -66,7 +66,7 @@ fragment = discard; } - gl_FragColor = u_color; + gl_FragColor = v_color; } vertex41core = From 1d6ef4bc3cdcf42714e61b1eb69836a348de4c33 Mon Sep 17 00:00:00 2001 From: Jack Ha Date: Wed, 8 Feb 2017 10:40:17 +0100 Subject: [PATCH 41/54] Default color if no material color is available. CURA-3273 --- plugins/CuraEngineBackend/ProcessSlicedLayersJob.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py b/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py index 21227e7a8b..7648307de5 100644 --- a/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py +++ b/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py @@ -177,6 +177,8 @@ class ProcessSlicedLayersJob(Job): material_color_map = numpy.zeros((1, 4), dtype=numpy.float32) material = global_container_stack.findContainer({"type": "material"}) color_code = material.getMetaDataEntry("color_code") + if color_code is None: # not all stacks have a material color + color_code = "#e0e000" color = colorCodeToRGBA(color_code) material_color_map[0, :] = color From 6c19bc1c16c15329539c9275581c80842f516cb1 Mon Sep 17 00:00:00 2001 From: Jack Ha Date: Wed, 8 Feb 2017 11:08:59 +0100 Subject: [PATCH 42/54] Only show legend in color: line_type --- plugins/LayerView/LayerView.py | 15 +++++++++++++-- plugins/LayerView/LayerView.qml | 11 +++++++++-- plugins/LayerView/LayerViewProxy.py | 12 ++++++++++++ 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/plugins/LayerView/LayerView.py b/plugins/LayerView/LayerView.py index 468fc01ec3..6217ebdad2 100644 --- a/plugins/LayerView/LayerView.py +++ b/plugins/LayerView/LayerView.py @@ -36,6 +36,10 @@ import os.path ## View used to display g-code paths. class LayerView(View): + # Must match LayerView.qml + LAYER_VIEW_TYPE_MATERIAL_TYPE = 0 + LAYER_VIEW_TYPE_LINE_TYPE = 1 + def __init__(self): super().__init__() @@ -260,6 +264,12 @@ class LayerView(View): def endRendering(self): pass + def enableLegend(self): + Application.getInstance().setViewLegendItems(self._getLegendItems()) + + def disableLegend(self): + Application.getInstance().setViewLegendItems([]) + def event(self, event): modifiers = QApplication.keyboardModifiers() ctrl_is_active = modifiers == Qt.ControlModifier @@ -292,7 +302,8 @@ class LayerView(View): self._old_composite_shader = self._composite_pass.getCompositeShader() self._composite_pass.setCompositeShader(self._layerview_composite_shader) - Application.getInstance().setViewLegendItems(self._getLegendItems()) + if self.getLayerViewType() == self.LAYER_VIEW_TYPE_LINE_TYPE: + self.enableLegend() elif event.type == Event.ViewDeactivateEvent: self._wireprint_warning_message.hide() @@ -303,7 +314,7 @@ class LayerView(View): self._composite_pass.setLayerBindings(self._old_layer_bindings) self._composite_pass.setCompositeShader(self._old_composite_shader) - Application.getInstance().setViewLegendItems([]) + self.disableLegend() def _onGlobalStackChanged(self): if self._global_container_stack: diff --git a/plugins/LayerView/LayerView.qml b/plugins/LayerView/LayerView.qml index ee109b7f04..c2b2fb3559 100644 --- a/plugins/LayerView/LayerView.qml +++ b/plugins/LayerView/LayerView.qml @@ -158,7 +158,7 @@ Item border.width: UM.Theme.getSize("default_lining").width border.color: UM.Theme.getColor("lining") - ListModel + ListModel // matches LayerView.py { id: layerViewTypes ListElement { @@ -179,7 +179,14 @@ Item model: layerViewTypes visible: !UM.LayerView.compatibilityMode onActivated: { - UM.LayerView.setLayerViewType(layerViewTypes.get(index).type_id); + var type_id = layerViewTypes.get(index).type_id; + UM.LayerView.setLayerViewType(type_id); + if (type_id == 1) { + // Line type + UM.LayerView.enableLegend(); + } else { + UM.LayerView.disableLegend(); + } } } diff --git a/plugins/LayerView/LayerViewProxy.py b/plugins/LayerView/LayerViewProxy.py index 7eb4cc65da..d386b53d01 100644 --- a/plugins/LayerView/LayerViewProxy.py +++ b/plugins/LayerView/LayerViewProxy.py @@ -129,6 +129,18 @@ class LayerViewProxy(QObject): return active_view.getExtruderCount() return 0 + @pyqtSlot() + def enableLegend(self): + active_view = self._controller.getActiveView() + if type(active_view) == LayerView.LayerView.LayerView: + active_view.enableLegend() + + @pyqtSlot() + def disableLegend(self): + active_view = self._controller.getActiveView() + if type(active_view) == LayerView.LayerView.LayerView: + active_view.disableLegend() + def _layerActivityChanged(self): self.activityChanged.emit() From 50ba236e660ac7df92e3070585de59a6d25374b0 Mon Sep 17 00:00:00 2001 From: Jack Ha Date: Wed, 8 Feb 2017 11:24:41 +0100 Subject: [PATCH 43/54] Removed unused option in LayerPolygon, added comments --- cura/LayerDataBuilder.py | 9 +++++++-- cura/LayerPolygon.py | 11 +++++++---- plugins/CuraEngineBackend/ProcessSlicedLayersJob.py | 2 +- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/cura/LayerDataBuilder.py b/cura/LayerDataBuilder.py index dcc3991833..1de2302f77 100644 --- a/cura/LayerDataBuilder.py +++ b/cura/LayerDataBuilder.py @@ -48,8 +48,10 @@ class LayerDataBuilder(MeshBuilder): self._layers[layer].setThickness(thickness) - # material color map: [r, g, b, a] for each extruder row. - # line_type_brightness: compatibility layer view uses line type brightness of 0.5 + ## Return the layer data as LayerData. + # + # \param material_color_map: [r, g, b, a] for each extruder row. + # \param 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 index_count = 0 @@ -75,9 +77,12 @@ class LayerDataBuilder(MeshBuilder): self.addColors(colors) self.addIndices(indices.flatten()) + # Note: we're using numpy indexing here. + # See also: https://docs.scipy.org/doc/numpy/reference/arrays.indexing.html material_colors = numpy.zeros((line_dimensions.shape[0], 4), dtype=numpy.float32) for extruder_nr in range(material_color_map.shape[0]): material_colors[extruders == extruder_nr] = material_color_map[extruder_nr] + # Set material_colors with indices where line_types (also numpy array) == MoveCombingType material_colors[line_types == LayerPolygon.MoveCombingType] = colors[line_types == LayerPolygon.MoveCombingType] material_colors[line_types == LayerPolygon.MoveRetractionType] = colors[line_types == LayerPolygon.MoveRetractionType] diff --git a/cura/LayerPolygon.py b/cura/LayerPolygon.py index 90bc123548..577de9e40b 100644 --- a/cura/LayerPolygon.py +++ b/cura/LayerPolygon.py @@ -19,10 +19,13 @@ class LayerPolygon: __jump_map = numpy.logical_or(numpy.logical_or(numpy.arange(11) == NoneType, numpy.arange(11) == MoveCombingType), numpy.arange(11) == MoveRetractionType) - ## LayerPolygon - # line_thicknesses: array with type as index and thickness as value - def __init__(self, mesh, extruder, line_types, data, line_widths, line_thicknesses): - self._mesh = mesh + ## LayerPolygon, used in ProcessSlicedLayersJob + # \param extruder + # \param line_types array with line_types + # \param data new_points + # \param line_widths array with line widths + # \param line_thicknesses: array with type as index and thickness as value + def __init__(self, extruder, line_types, data, line_widths, line_thicknesses): self._extruder = extruder self._types = line_types self._data = data diff --git a/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py b/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py index 7648307de5..0f46cc96bf 100644 --- a/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py +++ b/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py @@ -139,7 +139,7 @@ class ProcessSlicedLayersJob(Job): new_points[:, 1] = points[:, 2] new_points[:, 2] = -points[:, 1] - this_poly = LayerPolygon.LayerPolygon(layer_data, extruder, line_types, new_points, line_widths, line_thicknesses) + this_poly = LayerPolygon.LayerPolygon(extruder, line_types, new_points, line_widths, line_thicknesses) this_poly.buildCache() this_layer.polygons.append(this_poly) From 47ab49795f732886d223f61f32a04d3239185458 Mon Sep 17 00:00:00 2001 From: Jack Ha Date: Wed, 8 Feb 2017 11:48:00 +0100 Subject: [PATCH 44/54] Added comments, changed small layout and id thing. CURA-3273 --- cura/LayerPolygon.py | 15 +++++++++++++-- .../CuraEngineBackend/ProcessSlicedLayersJob.py | 3 +++ plugins/LayerView/LayerView.py | 8 ++++++++ plugins/LayerView/LayerView.qml | 6 +++--- 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/cura/LayerPolygon.py b/cura/LayerPolygon.py index 577de9e40b..242bb25d56 100644 --- a/cura/LayerPolygon.py +++ b/cura/LayerPolygon.py @@ -69,9 +69,20 @@ class LayerPolygon: self._vertex_begin = 0 self._vertex_end = numpy.sum( self._build_cache_needed_points ) - + + ## Set all the arrays provided by the function caller, representing the LayerPolygon + # The arrays are either by vertex or by indices. + # + # \param vertex_offset : determines where to start and end filling the arrays + # \param index_offset : determines where to start and end filling the arrays + # \param vertices : vertex numpy array to be filled + # \param colors : vertex numpy array to be filled + # \param line_dimensions : vertex numpy array to be filled + # \param extruders : vertex numpy array to be filled + # \param line_types : vertex numpy array to be filled + # \param indices : index numpy array to be filled def build(self, vertex_offset, index_offset, vertices, colors, line_dimensions, extruders, line_types, indices): - if (self._build_cache_line_mesh_mask is None) or (self._build_cache_needed_points is None ): + if self._build_cache_line_mesh_mask is None or self._build_cache_needed_points is None: self.buildCache() line_mesh_mask = self._build_cache_line_mesh_mask diff --git a/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py b/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py index 0f46cc96bf..0d706f59b8 100644 --- a/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py +++ b/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py @@ -27,6 +27,9 @@ from time import time catalog = i18nCatalog("cura") +## Return a 4-tuple with floats 0-1 representing the html color code +# +# \param color_code html color code, i.e. "#FF0000" -> red def colorCodeToRGBA(color_code): return [ int(color_code[1:3], 16) / 255, diff --git a/plugins/LayerView/LayerView.py b/plugins/LayerView/LayerView.py index 6217ebdad2..c75c2eac0c 100644 --- a/plugins/LayerView/LayerView.py +++ b/plugins/LayerView/LayerView.py @@ -168,13 +168,21 @@ class LayerView(View): self.currentLayerNumChanged.emit() + ## Set the layer view type + # + # \param layer_view_type integer as in LayerView.qml and this class def setLayerViewType(self, layer_view_type): self._layer_view_type = layer_view_type self.currentLayerNumChanged.emit() + ## Return the layer view type, integer as in LayerView.qml and this class def getLayerViewType(self): return self._layer_view_type + ## Set the extruder opacity + # + # \param extruder_nr 0..3 + # \param opacity 0.0 .. 1.0 def setExtruderOpacity(self, extruder_nr, opacity): self._extruder_opacity[extruder_nr] = opacity self.currentLayerNumChanged.emit() diff --git a/plugins/LayerView/LayerView.qml b/plugins/LayerView/LayerView.qml index c2b2fb3559..ac85d6ccb2 100644 --- a/plugins/LayerView/LayerView.qml +++ b/plugins/LayerView/LayerView.qml @@ -15,7 +15,7 @@ Item Slider { - id: slider2 + id: sliderMinimumLayer width: UM.Theme.getSize("slider_layerview_size").width height: UM.Theme.getSize("slider_layerview_size").height anchors.left: parent.left @@ -151,7 +151,6 @@ Item anchors.verticalCenter: parent.verticalCenter anchors.top: slider_background.bottom anchors.topMargin: UM.Theme.getSize("default_margin").height - //anchors.leftMargin: UM.Theme.getSize("default_margin").width width: UM.Theme.getSize("slider_layerview_background").width * 3 height: slider.height + UM.Theme.getSize("default_margin").height * 2 color: UM.Theme.getColor("tool_panel_background"); @@ -203,7 +202,8 @@ Item id: view_settings anchors.top: UM.LayerView.compatibilityMode ? compatibilityModeLabel.bottom : layerTypeCombobox.bottom anchors.topMargin: UM.Theme.getSize("default_margin").height - x: UM.Theme.getSize("default_margin").width + anchors.left: parent.left + anchors.leftMargin: UM.Theme.getSize("default_margin").width CheckBox { checked: true From cc950732b63fa3d34a7f4b040fcb7162b72be236 Mon Sep 17 00:00:00 2001 From: Jack Ha Date: Wed, 8 Feb 2017 11:57:59 +0100 Subject: [PATCH 45/54] Added comment. CURA-3273 --- plugins/LayerView/layers.shader | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/LayerView/layers.shader b/plugins/LayerView/layers.shader index 81d5c94dff..1b1c62e21f 100644 --- a/plugins/LayerView/layers.shader +++ b/plugins/LayerView/layers.shader @@ -17,6 +17,7 @@ vertex = void main() { gl_Position = u_modelViewProjectionMatrix * a_vertex; + // shade the color depending on the extruder index v_color = a_color; if ((a_line_type != 8.0) && (a_line_type != 9.0)) { v_color = (a_extruder == u_active_extruder) ? v_color : vec4(u_shade_factor * v_color.rgb, v_color.a); From 8e80593232140b62bf3b21890122834205f8b064 Mon Sep 17 00:00:00 2001 From: Jack Ha Date: Wed, 8 Feb 2017 13:03:48 +0100 Subject: [PATCH 46/54] Added comment. CURA-3273 --- plugins/LayerView/layers.shader | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/LayerView/layers.shader b/plugins/LayerView/layers.shader index 1b1c62e21f..cc25134216 100644 --- a/plugins/LayerView/layers.shader +++ b/plugins/LayerView/layers.shader @@ -19,6 +19,7 @@ vertex = gl_Position = u_modelViewProjectionMatrix * a_vertex; // shade the color depending on the extruder index v_color = a_color; + // 8 and 9 are travel moves if ((a_line_type != 8.0) && (a_line_type != 9.0)) { v_color = (a_extruder == u_active_extruder) ? v_color : vec4(u_shade_factor * v_color.rgb, v_color.a); } From 0d444298bcffef2f19e1771ee950908f9dea059d Mon Sep 17 00:00:00 2001 From: Jack Ha Date: Wed, 8 Feb 2017 13:29:24 +0100 Subject: [PATCH 47/54] Added myEmitVertex function in layers3d.shader. CURA-3273 --- plugins/LayerView/layers3d.shader | 160 +++++++----------------------- 1 file changed, 35 insertions(+), 125 deletions(-) diff --git a/plugins/LayerView/layers3d.shader b/plugins/LayerView/layers3d.shader index c7c7628a92..16572356db 100644 --- a/plugins/LayerView/layers3d.shader +++ b/plugins/LayerView/layers3d.shader @@ -88,6 +88,15 @@ geometry41core = out vec3 f_normal; out vec3 f_vertex; + // Set the set of variables and EmitVertex + void myEmitVertex(vec3 vertex, vec4 color, vec3 normal, vec4 pos) { + f_vertex = vertex; + f_color = color; + f_normal = normal; + gl_Position = pos; + EmitVertex(); + } + void main() { vec4 g_vertex_delta; @@ -140,145 +149,46 @@ geometry41core = g_vertex_normal_vert = vec3(0.0, 1.0, 0.0); g_vertex_offset_vert = vec4(g_vertex_normal_vert * size_y, 0.0); - f_vertex = v_vertex[0]; - f_color = v_color[0]; - f_normal = g_vertex_normal_horz; - gl_Position = u_viewProjectionMatrix * (gl_in[0].gl_Position + g_vertex_offset_horz); - EmitVertex(); - - f_vertex = v_vertex[1]; - f_color = v_color[1]; - f_normal = g_vertex_normal_horz; - gl_Position = u_viewProjectionMatrix * (gl_in[1].gl_Position + g_vertex_offset_horz); - EmitVertex(); - - f_vertex = v_vertex[0]; - f_color = v_color[0]; - f_normal = g_vertex_normal_vert; - gl_Position = u_viewProjectionMatrix * (gl_in[0].gl_Position + g_vertex_offset_vert); - EmitVertex(); - - f_vertex = v_vertex[1]; - f_color = v_color[1]; - f_normal = g_vertex_normal_vert; - gl_Position = u_viewProjectionMatrix * (gl_in[1].gl_Position + g_vertex_offset_vert); - EmitVertex(); - - f_vertex = v_vertex[0]; - f_normal = -g_vertex_normal_horz; - f_color = v_color[0]; - gl_Position = u_viewProjectionMatrix * (gl_in[0].gl_Position - g_vertex_offset_horz); - EmitVertex(); - - f_vertex = v_vertex[1]; - f_color = v_color[1]; - f_normal = -g_vertex_normal_horz; - gl_Position = u_viewProjectionMatrix * (gl_in[1].gl_Position - g_vertex_offset_horz); - EmitVertex(); - - f_vertex = v_vertex[0]; - f_color = v_color[0]; - f_normal = -g_vertex_normal_vert; - gl_Position = u_viewProjectionMatrix * (gl_in[0].gl_Position - g_vertex_offset_vert); - EmitVertex(); - - f_vertex = v_vertex[1]; - f_color = v_color[1]; - f_normal = -g_vertex_normal_vert; - gl_Position = u_viewProjectionMatrix * (gl_in[1].gl_Position - g_vertex_offset_vert); - EmitVertex(); - - f_vertex = v_vertex[0]; - f_normal = g_vertex_normal_horz; - f_color = v_color[0]; - gl_Position = u_viewProjectionMatrix * (gl_in[0].gl_Position + g_vertex_offset_horz); - EmitVertex(); - - f_vertex = v_vertex[1]; - f_color = v_color[1]; - f_normal = g_vertex_normal_horz; - gl_Position = u_viewProjectionMatrix * (gl_in[1].gl_Position + g_vertex_offset_horz); - EmitVertex(); + myEmitVertex(v_vertex[0], v_color[0], g_vertex_normal_horz, u_viewProjectionMatrix * (gl_in[0].gl_Position + g_vertex_offset_horz)); + myEmitVertex(v_vertex[1], v_color[1], g_vertex_normal_horz, u_viewProjectionMatrix * (gl_in[1].gl_Position + g_vertex_offset_horz)); + myEmitVertex(v_vertex[0], v_color[0], g_vertex_normal_vert, u_viewProjectionMatrix * (gl_in[0].gl_Position + g_vertex_offset_vert)); + myEmitVertex(v_vertex[1], v_color[1], g_vertex_normal_vert, u_viewProjectionMatrix * (gl_in[1].gl_Position + g_vertex_offset_vert)); + myEmitVertex(v_vertex[0], v_color[0], -g_vertex_normal_horz, u_viewProjectionMatrix * (gl_in[0].gl_Position - g_vertex_offset_horz)); + myEmitVertex(v_vertex[1], v_color[1], -g_vertex_normal_horz, u_viewProjectionMatrix * (gl_in[1].gl_Position - g_vertex_offset_horz)); + myEmitVertex(v_vertex[0], v_color[0], -g_vertex_normal_vert, u_viewProjectionMatrix * (gl_in[0].gl_Position - g_vertex_offset_vert)); + myEmitVertex(v_vertex[1], v_color[1], -g_vertex_normal_vert, u_viewProjectionMatrix * (gl_in[1].gl_Position - g_vertex_offset_vert)); + myEmitVertex(v_vertex[0], v_color[0], g_vertex_normal_horz, u_viewProjectionMatrix * (gl_in[0].gl_Position + g_vertex_offset_horz)); + myEmitVertex(v_vertex[1], v_color[1], g_vertex_normal_horz, u_viewProjectionMatrix * (gl_in[1].gl_Position + g_vertex_offset_horz)); EndPrimitive(); // left side - f_vertex = v_vertex[0]; - f_color = v_color[0]; - - f_normal = g_vertex_normal_horz; - gl_Position = u_viewProjectionMatrix * (gl_in[0].gl_Position + g_vertex_offset_horz); - EmitVertex(); - - f_normal = g_vertex_normal_vert; - gl_Position = u_viewProjectionMatrix * (gl_in[0].gl_Position + g_vertex_offset_vert); - EmitVertex(); - - f_normal = g_vertex_normal_horz_head; - gl_Position = u_viewProjectionMatrix * (gl_in[0].gl_Position + g_vertex_offset_horz_head); - EmitVertex(); - - f_normal = -g_vertex_normal_horz; - gl_Position = u_viewProjectionMatrix * (gl_in[0].gl_Position - g_vertex_offset_horz); - EmitVertex(); + myEmitVertex(v_vertex[0], v_color[0], g_vertex_normal_horz, u_viewProjectionMatrix * (gl_in[0].gl_Position + g_vertex_offset_horz)); + myEmitVertex(v_vertex[0], v_color[0], g_vertex_normal_vert, u_viewProjectionMatrix * (gl_in[0].gl_Position + g_vertex_offset_horz)); + myEmitVertex(v_vertex[0], v_color[0], g_vertex_normal_horz_head, u_viewProjectionMatrix * (gl_in[0].gl_Position + g_vertex_offset_horz_head)); + myEmitVertex(v_vertex[0], v_color[0], -g_vertex_normal_horz, u_viewProjectionMatrix * (gl_in[0].gl_Position - g_vertex_offset_horz)); EndPrimitive(); - f_normal = -g_vertex_normal_horz; - gl_Position = u_viewProjectionMatrix * (gl_in[0].gl_Position - g_vertex_offset_horz); - EmitVertex(); - - f_normal = -g_vertex_normal_vert; - gl_Position = u_viewProjectionMatrix * (gl_in[0].gl_Position - g_vertex_offset_vert); - EmitVertex(); - - f_normal = g_vertex_normal_horz_head; - gl_Position = u_viewProjectionMatrix * (gl_in[0].gl_Position + g_vertex_offset_horz_head); - EmitVertex(); - - f_normal = g_vertex_normal_horz; - gl_Position = u_viewProjectionMatrix * (gl_in[0].gl_Position + g_vertex_offset_horz); - EmitVertex(); + myEmitVertex(v_vertex[0], v_color[0], -g_vertex_normal_horz, u_viewProjectionMatrix * (gl_in[0].gl_Position - g_vertex_offset_horz)); + myEmitVertex(v_vertex[0], v_color[0], -g_vertex_normal_vert, u_viewProjectionMatrix * (gl_in[0].gl_Position - g_vertex_offset_vert)); + myEmitVertex(v_vertex[0], v_color[0], g_vertex_normal_horz_head, u_viewProjectionMatrix * (gl_in[0].gl_Position + g_vertex_offset_horz_head)); + myEmitVertex(v_vertex[0], v_color[0], g_vertex_normal_horz, u_viewProjectionMatrix * (gl_in[0].gl_Position + g_vertex_offset_horz)); EndPrimitive(); // right side - f_vertex = v_vertex[1]; - f_color = v_color[1]; - - f_normal = g_vertex_normal_horz; - gl_Position = u_viewProjectionMatrix * (gl_in[1].gl_Position + g_vertex_offset_horz); - EmitVertex(); - - f_normal = g_vertex_normal_vert; - gl_Position = u_viewProjectionMatrix * (gl_in[1].gl_Position + g_vertex_offset_vert); - EmitVertex(); - - f_normal = -g_vertex_normal_horz_head; - gl_Position = u_viewProjectionMatrix * (gl_in[1].gl_Position - g_vertex_offset_horz_head); - EmitVertex(); - - f_normal = -g_vertex_normal_horz; - gl_Position = u_viewProjectionMatrix * (gl_in[1].gl_Position - g_vertex_offset_horz); - EmitVertex(); + myEmitVertex(v_vertex[1], v_color[1], g_vertex_normal_horz, u_viewProjectionMatrix * (gl_in[1].gl_Position + g_vertex_offset_horz)); + myEmitVertex(v_vertex[1], v_color[1], g_vertex_normal_vert, u_viewProjectionMatrix * (gl_in[1].gl_Position + g_vertex_offset_vert)); + myEmitVertex(v_vertex[1], v_color[1], -g_vertex_normal_horz_head, u_viewProjectionMatrix * (gl_in[1].gl_Position - g_vertex_offset_horz_head)); + myEmitVertex(v_vertex[1], v_color[1], -g_vertex_normal_horz, u_viewProjectionMatrix * (gl_in[1].gl_Position - g_vertex_offset_horz)); EndPrimitive(); - f_normal = -g_vertex_normal_horz; - gl_Position = u_viewProjectionMatrix * (gl_in[1].gl_Position - g_vertex_offset_horz); - EmitVertex(); - - f_normal = -g_vertex_normal_vert; - gl_Position = u_viewProjectionMatrix * (gl_in[1].gl_Position - g_vertex_offset_vert); - EmitVertex(); - - f_normal = -g_vertex_normal_horz_head; - gl_Position = u_viewProjectionMatrix * (gl_in[1].gl_Position - g_vertex_offset_horz_head); - EmitVertex(); - - f_normal = g_vertex_normal_horz; - gl_Position = u_viewProjectionMatrix * (gl_in[1].gl_Position + g_vertex_offset_horz); - EmitVertex(); + myEmitVertex(v_vertex[1], v_color[1], -g_vertex_normal_horz, u_viewProjectionMatrix * (gl_in[1].gl_Position - g_vertex_offset_horz)); + myEmitVertex(v_vertex[1], v_color[1], -g_vertex_normal_vert, u_viewProjectionMatrix * (gl_in[1].gl_Position - g_vertex_offset_vert)); + myEmitVertex(v_vertex[1], v_color[1], -g_vertex_normal_horz_head, u_viewProjectionMatrix * (gl_in[1].gl_Position - g_vertex_offset_horz_head)); + myEmitVertex(v_vertex[1], v_color[1], g_vertex_normal_horz, u_viewProjectionMatrix * (gl_in[1].gl_Position - g_vertex_offset_horz)); EndPrimitive(); } From 811f40d294b2ef5afba56b20591976d1ff3da9bf Mon Sep 17 00:00:00 2001 From: Jack Ha Date: Wed, 8 Feb 2017 13:34:54 +0100 Subject: [PATCH 48/54] Renamed lightDir to light_dir. CURA-3273 --- plugins/LayerView/layers3d.shader | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/LayerView/layers3d.shader b/plugins/LayerView/layers3d.shader index 16572356db..c63bdac7d9 100644 --- a/plugins/LayerView/layers3d.shader +++ b/plugins/LayerView/layers3d.shader @@ -212,10 +212,10 @@ fragment41core = finalColor.rgb += f_color.rgb * 0.3; highp vec3 normal = normalize(f_normal); - highp vec3 lightDir = normalize(u_lightPosition - f_vertex); + highp vec3 light_dir = normalize(u_lightPosition - f_vertex); // Diffuse Component - highp float NdotL = clamp(dot(normal, lightDir), 0.0, 1.0); + highp float NdotL = clamp(dot(normal, light_dir), 0.0, 1.0); finalColor += (NdotL * f_color); finalColor.a = alpha; // Do not change alpha in any way From 81e575da31dee0f1ab77a88c743929fd3a56a86b Mon Sep 17 00:00:00 2001 From: Jack Ha Date: Wed, 8 Feb 2017 13:39:19 +0100 Subject: [PATCH 49/54] Added comment. CURA-3273 --- plugins/LayerView/layerview_composite.shader | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/LayerView/layerview_composite.shader b/plugins/LayerView/layerview_composite.shader index f203650ce6..dcc02acc84 100644 --- a/plugins/LayerView/layerview_composite.shader +++ b/plugins/LayerView/layerview_composite.shader @@ -33,6 +33,7 @@ fragment = void main() { + // blur kernel kernel[0] = 0.0; kernel[1] = 1.0; kernel[2] = 0.0; kernel[3] = 1.0; kernel[4] = -4.0; kernel[5] = 1.0; kernel[6] = 0.0; kernel[7] = 1.0; kernel[8] = 0.0; @@ -101,6 +102,7 @@ fragment41core = void main() { + // blur kernel kernel[0] = 0.0; kernel[1] = 1.0; kernel[2] = 0.0; kernel[3] = 1.0; kernel[4] = -4.0; kernel[5] = 1.0; kernel[6] = 0.0; kernel[7] = 1.0; kernel[8] = 0.0; From 30af908e2919f83bf04a21bca625a9d9b0ddcba6 Mon Sep 17 00:00:00 2001 From: Jack Ha Date: Thu, 9 Feb 2017 15:27:53 +0100 Subject: [PATCH 50/54] Fixed GCodeReader. CURA-3273 --- plugins/GCodeReader/GCodeReader.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/plugins/GCodeReader/GCodeReader.py b/plugins/GCodeReader/GCodeReader.py index 34ea91a727..290b66343e 100644 --- a/plugins/GCodeReader/GCodeReader.py +++ b/plugins/GCodeReader/GCodeReader.py @@ -99,8 +99,11 @@ class GCodeReader(MeshReader): count = len(path) line_types = numpy.empty((count - 1, 1), numpy.int32) line_widths = numpy.empty((count - 1, 1), numpy.float32) + line_thicknesses = numpy.empty((count - 1, 1), numpy.float32) # TODO: need to calculate actual line width based on E values line_widths[:, 0] = 0.4 + # TODO: need to calculate actual line heights + line_thicknesses[:, 0] = 0.2 points = numpy.empty((count, 3), numpy.float32) i = 0 for point in path: @@ -113,7 +116,7 @@ class GCodeReader(MeshReader): line_widths[i - 1] = 0.2 i += 1 - this_poly = LayerPolygon(self._layer_data_builder, self._extruder, line_types, points, line_widths) + this_poly = LayerPolygon(self._extruder, line_types, points, line_widths, line_thicknesses) this_poly.buildCache() this_layer.polygons.append(this_poly) @@ -276,7 +279,10 @@ class GCodeReader(MeshReader): self._layer += 1 current_path.clear() - layer_mesh = self._layer_data_builder.build() + material_color_map = numpy.zeros((10, 4), dtype = numpy.float32) + material_color_map[0, :] = [0.0, 0.7, 0.9, 1.0] + material_color_map[1, :] = [0.7, 0.9, 0.0, 1.0] + layer_mesh = self._layer_data_builder.build(material_color_map) decorator = LayerDataDecorator.LayerDataDecorator() decorator.setLayerData(layer_mesh) scene_node.addDecorator(decorator) From 7000717f6e2f5a6cd1c061d59bdffae3baaf152e Mon Sep 17 00:00:00 2001 From: Jack Ha Date: Mon, 13 Feb 2017 09:58:33 +0100 Subject: [PATCH 51/54] Fixed warning non-NOTIFYable properties, added signals for propertiesChanged. CURA-3273 --- plugins/LayerView/LayerView.py | 6 +++++- plugins/LayerView/LayerViewProxy.py | 7 ++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/plugins/LayerView/LayerView.py b/plugins/LayerView/LayerView.py index c75c2eac0c..77c17a0aea 100644 --- a/plugins/LayerView/LayerView.py +++ b/plugins/LayerView/LayerView.py @@ -263,6 +263,7 @@ class LayerView(View): maxLayersChanged = Signal() currentLayerNumChanged = Signal() globalStackChanged = Signal() + preferencesChanged = Signal() ## Hackish way to ensure the proxy is already created, which ensures that the layerview.qml is already created # as this caused some issues. @@ -370,13 +371,16 @@ class LayerView(View): self._top_layers_job = None def _onPreferencesChanged(self, preference): - if preference not in {"view/top_layer_count", "view/only_show_top_layers", "view/compatibility_mode"}: + if preference not in {"view/top_layer_count", "view/only_show_top_layers", "view/force_layer_view_compatibility_mode"}: return self._solid_layers = int(Preferences.getInstance().getValue("view/top_layer_count")) self._only_show_top_layers = bool(Preferences.getInstance().getValue("view/only_show_top_layers")) + self._compatibility_mode = OpenGLContext.isLegacyOpenGL() or bool( + Preferences.getInstance().getValue("view/force_layer_view_compatibility_mode")) self._startUpdateTopLayers() + self.preferencesChanged.emit() def _getLegendItems(self): if self._legend_items is None: diff --git a/plugins/LayerView/LayerViewProxy.py b/plugins/LayerView/LayerViewProxy.py index d386b53d01..b3a1cca87d 100644 --- a/plugins/LayerView/LayerViewProxy.py +++ b/plugins/LayerView/LayerViewProxy.py @@ -17,6 +17,7 @@ class LayerViewProxy(QObject): maxLayersChanged = pyqtSignal() activityChanged = pyqtSignal() globalStackChanged = pyqtSignal() + preferencesChanged = pyqtSignal() @pyqtProperty(bool, notify = activityChanged) def getLayerActivity(self): @@ -52,7 +53,7 @@ class LayerViewProxy(QObject): return False - @pyqtProperty(bool) + @pyqtProperty(bool, notify = preferencesChanged) def compatibilityMode(self): active_view = self._controller.getActiveView() if type(active_view) == LayerView.LayerView.LayerView: @@ -157,6 +158,9 @@ class LayerViewProxy(QObject): def _onGlobalStackChanged(self): self.globalStackChanged.emit() + def _onPreferencesChanged(self): + self.preferencesChanged.emit() + def _onActiveViewChanged(self): active_view = self._controller.getActiveView() if type(active_view) == LayerView.LayerView.LayerView: @@ -164,3 +168,4 @@ class LayerViewProxy(QObject): active_view.maxLayersChanged.connect(self._onMaxLayersChanged) active_view.busyChanged.connect(self._onBusyChanged) active_view.globalStackChanged.connect(self._onGlobalStackChanged) + active_view.preferencesChanged.connect(self._onPreferencesChanged) From 106cb6ded9cd4e4fff9c2c19283105ef8cc1ff59 Mon Sep 17 00:00:00 2001 From: Jack Ha Date: Mon, 13 Feb 2017 12:47:04 +0100 Subject: [PATCH 52/54] Fixed compatibility mode. CURA-3273 --- cura/LayerDataBuilder.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cura/LayerDataBuilder.py b/cura/LayerDataBuilder.py index 1de2302f77..428ad4a210 100644 --- a/cura/LayerDataBuilder.py +++ b/cura/LayerDataBuilder.py @@ -63,8 +63,8 @@ class LayerDataBuilder(MeshBuilder): line_dimensions = numpy.empty((vertex_count, 2), numpy.float32) colors = numpy.empty((vertex_count, 4), numpy.float32) indices = numpy.empty((index_count, 2), numpy.int32) - extruders = numpy.empty((vertex_count), numpy.int32) - line_types = numpy.empty((vertex_count), numpy.int32) + extruders = numpy.empty((vertex_count), numpy.float32) + line_types = numpy.empty((vertex_count), numpy.float32) vertex_offset = 0 index_offset = 0 From 488b952815f9ffe7be861e8e051dc89ead5efaf7 Mon Sep 17 00:00:00 2001 From: Jack Ha Date: Mon, 13 Feb 2017 13:21:30 +0100 Subject: [PATCH 53/54] Fix 4.1 shader for line types. CURA-3273 --- plugins/LayerView/layers.shader | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/LayerView/layers.shader b/plugins/LayerView/layers.shader index cc25134216..840c3f25ba 100644 --- a/plugins/LayerView/layers.shader +++ b/plugins/LayerView/layers.shader @@ -78,8 +78,8 @@ vertex41core = uniform lowp float u_shade_factor; uniform highp int u_layer_view_type; - in highp int a_extruder; - in highp int a_line_type; + in highp float a_extruder; + in highp float a_line_type; in highp vec4 a_vertex; in lowp vec4 a_color; in lowp vec4 a_material_color; From 9e973732f56678506a9ba9730ce59a52a51d18cb Mon Sep 17 00:00:00 2001 From: Jack Ha Date: Wed, 15 Feb 2017 10:50:21 +0100 Subject: [PATCH 54/54] Fixed remember coloring type in Layer View. CURA-3273 --- plugins/LayerView/LayerView.qml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugins/LayerView/LayerView.qml b/plugins/LayerView/LayerView.qml index ac85d6ccb2..7713b796a9 100644 --- a/plugins/LayerView/LayerView.qml +++ b/plugins/LayerView/LayerView.qml @@ -187,6 +187,9 @@ Item UM.LayerView.disableLegend(); } } + onModelChanged: { + currentIndex = UM.LayerView.getLayerViewType(); + } } Label