Commit 2ccce488 authored by Guillaume Seguin's avatar Guillaume Seguin

Factorize box sides creation

parent 79848771
...@@ -52,6 +52,11 @@ def numpy2vbo(nparray, target = GL_ARRAY_BUFFER, usage = GL_STATIC_DRAW, use_vbo ...@@ -52,6 +52,11 @@ def numpy2vbo(nparray, target = GL_ARRAY_BUFFER, usage = GL_STATIC_DRAW, use_vbo
def triangulate_rectangle(i1, i2, i3, i4): def triangulate_rectangle(i1, i2, i3, i4):
return [i1, i4, i3, i3, i2, i1] return [i1, i4, i3, i3, i2, i1]
def triangulate_box(i1, i2, i3, i4,
j1, j2, j3, j4):
return [i1, i2, j2, j2, j1, i1, i2, i3, j3, j3, j2, i2,
i3, i4, j4, j4, j3, i3, i4, i1, j1, j1, j4, i4]
class BoundingBox(object): class BoundingBox(object):
""" """
A rectangular box (cuboid) enclosing a 3D model, defined by lower and upper corners. A rectangular box (cuboid) enclosing a 3D model, defined by lower and upper corners.
...@@ -332,7 +337,7 @@ class GcodeModel(Model): ...@@ -332,7 +337,7 @@ class GcodeModel(Model):
new_vertices = [] new_vertices = []
if prev_is_extruding: if prev_is_extruding:
# Store previous vertices indices # Store previous vertices indices
first_prev = len(vertex_list) / 3 - 4 prev_id = len(vertex_list) / 3 - 4
# Average directions # Average directions
avg_move_x = delta_x + prev_move_x avg_move_x = delta_x + prev_move_x
avg_move_y = delta_y + prev_move_y avg_move_y = delta_y + prev_move_y
...@@ -356,14 +361,10 @@ class GcodeModel(Model): ...@@ -356,14 +361,10 @@ class GcodeModel(Model):
new_vertices.extend((p2x, p2y, prev_pos[2] + path_halfheight)) new_vertices.extend((p2x, p2y, prev_pos[2] + path_halfheight))
first = len(vertex_list) / 3 first = len(vertex_list) / 3
# Link to previous # Link to previous
new_indices += triangulate_rectangle(first_prev, first, new_indices += triangulate_box(prev_id, prev_id + 1,
first + 1, first_prev + 1) prev_id + 2, prev_id + 3,
new_indices += triangulate_rectangle(first_prev + 1, first + 1, first, first + 1,
first + 2, first_prev + 2) first + 2, first + 3)
new_indices += triangulate_rectangle(first_prev + 2, first + 2,
first + 3, first_prev + 3)
new_indices += triangulate_rectangle(first_prev + 3, first + 3,
first, first_prev)
else: else:
# Compute vertices normal to the current move and cap it # Compute vertices normal to the current move and cap it
p1x = prev_pos[0] - path_halfwidth * move_normal_x p1x = prev_pos[0] - path_halfwidth * move_normal_x
...@@ -391,14 +392,10 @@ class GcodeModel(Model): ...@@ -391,14 +392,10 @@ class GcodeModel(Model):
end_first = len(vertex_list) / 3 + len(new_vertices) / 3 - 4 end_first = len(vertex_list) / 3 + len(new_vertices) / 3 - 4
new_indices += triangulate_rectangle(end_first + 3, end_first + 2, new_indices += triangulate_rectangle(end_first + 3, end_first + 2,
end_first + 1, end_first) end_first + 1, end_first)
new_indices += triangulate_rectangle(first, end_first, new_indices += triangulate_box(first, first + 1,
end_first + 1, first + 1) first + 2, first + 3,
new_indices += triangulate_rectangle(first + 1, end_first + 1, end_first, end_first + 1,
end_first + 2, first + 2) end_first + 2, end_first + 3)
new_indices += triangulate_rectangle(first + 2, end_first + 2,
end_first + 3, first + 3)
new_indices += triangulate_rectangle(first + 3, end_first + 3,
end_first, first)
index_list += new_indices index_list += new_indices
vertex_list += new_vertices vertex_list += new_vertices
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment