mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-07 06:57:28 -06:00
Layer shader now uses own attribute for line dimensions instead of misusing uvs.
This commit is contained in:
parent
8d2b3654a4
commit
0f2fb86cd9
6 changed files with 22 additions and 40 deletions
|
@ -53,11 +53,8 @@ class Layer:
|
||||||
result_vertex_offset = vertex_offset
|
result_vertex_offset = vertex_offset
|
||||||
result_index_offset = index_offset
|
result_index_offset = index_offset
|
||||||
self._element_count = 0
|
self._element_count = 0
|
||||||
thickness = self._thickness / 1000 # micrometer to millimeter
|
|
||||||
for polygon in self._polygons:
|
for polygon in self._polygons:
|
||||||
polygon.build(result_vertex_offset, result_index_offset, vertices, colors, line_dimensions, indices, thickness)
|
polygon.build(result_vertex_offset, result_index_offset, vertices, colors, line_dimensions, 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_vertex_offset += polygon.lineMeshVertexCount()
|
||||||
result_index_offset += polygon.lineMeshElementCount()
|
result_index_offset += polygon.lineMeshElementCount()
|
||||||
self._element_count += polygon.elementCount
|
self._element_count += polygon.elementCount
|
||||||
|
|
|
@ -6,9 +6,9 @@ from UM.Mesh.MeshData import MeshData
|
||||||
# Immutable, use LayerDataBuilder to create one of these.
|
# Immutable, use LayerDataBuilder to create one of these.
|
||||||
class LayerData(MeshData):
|
class LayerData(MeshData):
|
||||||
def __init__(self, vertices = None, normals = None, indices = None, colors = None, uvs = None, file_name = None,
|
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,
|
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._layers = layers
|
||||||
self._element_counts = element_counts
|
self._element_counts = element_counts
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,6 @@ class LayerDataBuilder(MeshBuilder):
|
||||||
index_count += data.lineMeshElementCount()
|
index_count += data.lineMeshElementCount()
|
||||||
|
|
||||||
vertices = numpy.empty((vertex_count, 3), numpy.float32)
|
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)
|
line_dimensions = numpy.empty((vertex_count, 2), numpy.float32)
|
||||||
colors = numpy.empty((vertex_count, 4), numpy.float32)
|
colors = numpy.empty((vertex_count, 4), numpy.float32)
|
||||||
indices = numpy.empty((index_count, 2), numpy.int32)
|
indices = numpy.empty((index_count, 2), numpy.int32)
|
||||||
|
@ -70,10 +69,15 @@ class LayerDataBuilder(MeshBuilder):
|
||||||
self.addVertices(vertices)
|
self.addVertices(vertices)
|
||||||
self.addColors(colors)
|
self.addColors(colors)
|
||||||
self.addIndices(indices.flatten())
|
self.addIndices(indices.flatten())
|
||||||
self._uvs = line_dimensions
|
# self._uvs = line_dimensions
|
||||||
#self._normals = normals
|
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(),
|
return LayerData(vertices=self.getVertices(), normals=self.getNormals(), indices=self.getIndices(),
|
||||||
colors=self.getColors(), uvs=self.getUVCoordinates(), file_name=self.getFileName(),
|
colors=self.getColors(), uvs=self.getUVCoordinates(), file_name=self.getFileName(),
|
||||||
center_position=self.getCenterPosition(), layers=self._layers,
|
center_position=self.getCenterPosition(), layers=self._layers,
|
||||||
element_counts=self._element_counts)
|
element_counts=self._element_counts, attributes=attributes)
|
||||||
|
|
|
@ -67,7 +67,7 @@ class LayerPolygon:
|
||||||
|
|
||||||
## build
|
## build
|
||||||
# line_thicknesses: array with type as index and thickness as value
|
# 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 ):
|
if (self._build_cache_line_mesh_mask is None) or (self._build_cache_needed_points is None ):
|
||||||
self.buildCache()
|
self.buildCache()
|
||||||
|
|
||||||
|
@ -85,6 +85,7 @@ class LayerPolygon:
|
||||||
|
|
||||||
# Points are picked based on the index list to get the vertices needed.
|
# Points are picked based on the index list to get the vertices needed.
|
||||||
vertices[self._vertex_begin:self._vertex_end, :] = self._data[index_list, :]
|
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.
|
# 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)
|
colors[self._vertex_begin:self._vertex_end, :] *= numpy.array([[0.5, 0.5, 0.5, 1.0]], numpy.float32)
|
||||||
|
|
|
@ -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
|
# 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()
|
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._abort_requested:
|
||||||
if self._progress:
|
if self._progress:
|
||||||
|
|
|
@ -10,13 +10,14 @@ vertex =
|
||||||
attribute highp vec4 a_vertex;
|
attribute highp vec4 a_vertex;
|
||||||
attribute lowp vec4 a_color;
|
attribute lowp vec4 a_color;
|
||||||
attribute highp vec4 a_normal;
|
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 lowp vec4 v_color;
|
||||||
|
|
||||||
varying highp vec3 v_vertex;
|
varying highp vec3 v_vertex;
|
||||||
varying highp vec3 v_normal;
|
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 lowp vec4 f_color;
|
||||||
varying highp vec3 f_vertex;
|
varying highp vec3 f_vertex;
|
||||||
|
@ -25,7 +26,7 @@ vertex =
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec4 v1_vertex = a_vertex;
|
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;
|
vec4 world_space_vert = u_modelMatrix * v1_vertex;
|
||||||
// gl_Position = u_viewProjectionMatrix * world_space_vert;
|
// gl_Position = u_viewProjectionMatrix * world_space_vert;
|
||||||
gl_Position = world_space_vert;
|
gl_Position = world_space_vert;
|
||||||
|
@ -36,7 +37,7 @@ vertex =
|
||||||
|
|
||||||
v_vertex = world_space_vert.xyz;
|
v_vertex = world_space_vert.xyz;
|
||||||
v_normal = (u_normalMatrix * normalize(a_normal)).xyz;
|
v_normal = (u_normalMatrix * normalize(a_normal)).xyz;
|
||||||
v_uvs = a_uvs;
|
v_line_dim = a_line_dim;
|
||||||
|
|
||||||
// for testing without geometry shader
|
// for testing without geometry shader
|
||||||
f_color = v_color;
|
f_color = v_color;
|
||||||
|
@ -47,9 +48,7 @@ vertex =
|
||||||
geometry =
|
geometry =
|
||||||
#version 410
|
#version 410
|
||||||
|
|
||||||
//uniform highp mat4 u_modelMatrix;
|
|
||||||
uniform highp mat4 u_viewProjectionMatrix;
|
uniform highp mat4 u_viewProjectionMatrix;
|
||||||
//uniform highp mat4 u_modelViewProjectionMatrix;
|
|
||||||
|
|
||||||
layout(lines) in;
|
layout(lines) in;
|
||||||
layout(triangle_strip, max_vertices = 26) out;
|
layout(triangle_strip, max_vertices = 26) out;
|
||||||
|
@ -57,7 +56,7 @@ geometry =
|
||||||
in vec4 v_color[];
|
in vec4 v_color[];
|
||||||
in vec3 v_vertex[];
|
in vec3 v_vertex[];
|
||||||
in vec3 v_normal[];
|
in vec3 v_normal[];
|
||||||
in vec2 v_uvs[];
|
in vec2 v_line_dim[];
|
||||||
|
|
||||||
out vec4 f_color;
|
out vec4 f_color;
|
||||||
out vec3 f_normal;
|
out vec3 f_normal;
|
||||||
|
@ -65,10 +64,6 @@ geometry =
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
//int i;
|
|
||||||
//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
|
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
|
vec4 g_vertex_offset_horz; // vec4 to match gl_in[x].gl_Position
|
||||||
|
@ -77,8 +72,8 @@ geometry =
|
||||||
vec3 g_vertex_normal_horz_head;
|
vec3 g_vertex_normal_horz_head;
|
||||||
vec4 g_vertex_offset_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_x = v_line_dim[0].x / 2 + 0.01; // radius, and make it nicely overlapping
|
||||||
float size_y = v_uvs[0].y / 2 + 0.01;
|
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_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_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_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_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);
|
g_vertex_offset_vert = vec4(g_vertex_normal_vert * size_y, 0.0);
|
||||||
|
|
||||||
f_vertex = v_vertex[0];
|
f_vertex = v_vertex[0];
|
||||||
|
@ -243,10 +237,6 @@ geometry =
|
||||||
EmitVertex();
|
EmitVertex();
|
||||||
|
|
||||||
EndPrimitive();
|
EndPrimitive();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fragment =
|
fragment =
|
||||||
|
@ -327,4 +317,4 @@ u_lightPosition = light_0_position
|
||||||
a_vertex = vertex
|
a_vertex = vertex
|
||||||
a_color = color
|
a_color = color
|
||||||
a_normal = normal
|
a_normal = normal
|
||||||
a_uvs = uv0
|
a_line_dim = line_dim
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue