mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-20 13:17:51 -06:00
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.
This commit is contained in:
parent
89a4ab0fe2
commit
7e1927434a
1 changed files with 12 additions and 14 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue