diff options
author | Ghostkeeper <ghost_keeper+github@hotmail.com> | 2016-01-21 15:55:11 +0300 |
---|---|---|
committer | Ghostkeeper <ghost_keeper+github@hotmail.com> | 2016-01-21 15:55:11 +0300 |
commit | 7e1927434aa8fe2e642c7ae3e956b766c9467103 (patch) | |
tree | fb7bda674506febba326ec7c749a8398a92fd1d9 /cura/ConvexHullNode.py | |
parent | 89a4ab0fe277cd738ddf21cfc0270d3f41ed3848 (diff) |
Use MeshBuilder to make convex hull mesh
The convex hull mesh was made without adding colours to the vertices. This was probably causing the convex hull to appear red on some machines, if red is the default vertex colour. Using meshbuilder makes code maintenance easier and allows us to easily set the colour of the vertices. Hopefully this fixes the issue with the red convex hulls.
Contributes to issue CURA-625.
Diffstat (limited to 'cura/ConvexHullNode.py')
-rw-r--r-- | cura/ConvexHullNode.py | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/cura/ConvexHullNode.py b/cura/ConvexHullNode.py index 9932a19cfa..b9cf925eef 100644 --- a/cura/ConvexHullNode.py +++ b/cura/ConvexHullNode.py @@ -5,7 +5,7 @@ from UM.Scene.SceneNode import SceneNode from UM.Resources import Resources from UM.Math.Color import Color from UM.Math.Vector import Vector -from UM.Mesh.MeshData import MeshData +from UM.Mesh.MeshBuilder import MeshBuilder #To create a mesh to display the convex hull with. from UM.View.GL.OpenGL import OpenGL @@ -25,6 +25,7 @@ class ConvexHullNode(SceneNode): self._inherit_scale = False self._color = Color(35, 35, 35, 128) + self._mesh_height = 0.1 #The y-coordinate of the convex hull mesh. Must not be 0, to prevent z-fighting. self._node = node self._node.transformationChanged.connect(self._onNodePositionChanged) @@ -43,22 +44,19 @@ class ConvexHullNode(SceneNode): self._convex_hull_head_mesh = self.createHullMesh(convex_hull_head.getPoints()) def createHullMesh(self, hull_points): - mesh = MeshData() - if len(hull_points) > 3: - center = (hull_points.min(0) + hull_points.max(0)) / 2.0 - mesh.addVertex(center[0], -0.1, center[1]) - else: + #Input checking. + if len(hull_points) < 3: return None - for point in hull_points: - mesh.addVertex(point[0], -0.1, point[1]) - indices = [] - for i in range(len(hull_points) - 1): - indices.append([0, i + 1, i + 2]) - indices.append([0, mesh.getVertexCount() - 1, 1]) + mesh_builder = MeshBuilder() #Create a mesh using the mesh builder. + point_first = Vector(hull_points[0][0], self._mesh_height, hull_points[0][1]) + point_previous = Vector(hull_points[1][0], self._mesh_height, hull_points[1][1]) + for point in hull_points[2:]: #Add the faces in the order of a triangle fan. + point_new = Vector(point[0], self._mesh_height, point[1]) + mesh_builder.addFace(point_first, point_previous, point_new, color = self._color) + point_previous = point_new #Prepare point_previous for the next triangle. - mesh.addIndices(numpy.array(indices, numpy.int32)) - return mesh + return mesh_builder.getData() def getWatchedNode(self): return self._node |