Better handling of degenerate convex hull cases.

Contributes to CURA-1504
This commit is contained in:
Simon Edwards 2016-05-26 14:39:22 +02:00
parent 7e3dd3d443
commit 5f638f6e69
2 changed files with 42 additions and 38 deletions

View file

@ -130,8 +130,8 @@ class ConvexHullDecorator(SceneNodeDecorator):
return rounded_hull
else:
if not self._node.getMeshData():
return None
rounded_hull = None
if self._node.getMeshData():
mesh = self._node.getMeshData()
world_transform = self._node.getWorldTransformation()
@ -145,6 +145,7 @@ class ConvexHullDecorator(SceneNodeDecorator):
# TODO; We need a better check for this as this gives poor results for meshes with long edges.
vertex_data = vertex_data[vertex_data[:,1] >= 0]
if len(vertex_data) >= 4:
# Round the vertex data to 1/10th of a mm, then remove all duplicate vertices
# This is done to greatly speed up further convex hull calculations as the convex hull
# becomes much less complex when dealing with highly detailed models.
@ -164,6 +165,7 @@ class ConvexHullDecorator(SceneNodeDecorator):
hull = Polygon(vertex_data)
if len(vertex_data) >= 4:
# First, calculate the normal convex hull around the points
convex_hull = hull.getConvexHull()

View file

@ -39,6 +39,7 @@ class ConvexHullNode(SceneNode):
self._convex_hull_head_mesh = None
self._hull = hull
if self._hull:
hull_mesh = self.createHullMesh(self._hull.getPoints())
if hull_mesh:
self.setMeshData(hull_mesh)
@ -76,6 +77,7 @@ class ConvexHullNode(SceneNode):
self._shader.setUniformValue("u_color", self._color)
if self.getParent():
if self.getMeshData():
renderer.queueNode(self, transparent = True, shader = self._shader, backface_cull = True, sort = -8)
if self._convex_hull_head_mesh:
renderer.queueNode(self, shader = self._shader, transparent = True, mesh = self._convex_hull_head_mesh, backface_cull = True, sort = -8)