mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-06 22:47:29 -06:00
Added line thickness to layer view
This commit is contained in:
parent
c12e6da3ac
commit
9904dad07b
5 changed files with 24 additions and 15 deletions
|
@ -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()
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue