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;