diff options
author | Jack Ha <j.ha@ultimaker.com> | 2016-07-25 17:45:38 +0300 |
---|---|---|
committer | Jack Ha <j.ha@ultimaker.com> | 2016-07-25 17:45:38 +0300 |
commit | d77f6e86e4f31b18d0c5e0415ded41435c2a566a (patch) | |
tree | 8dde099dd9d18fbfef09529059098772d2ee6bc2 /cura/ConvexHullNode.py | |
parent | 2d34e2b28ef9a1e83011edcd6bcc6a556bafb08b (diff) |
Added an extruded convex hull as a raft instead of a grey plane.
- New shader transparent_object.shader
- Raft thickness is calculated in BuildVolume and used in
ConvexHullDecorator, notified by a Signal.
- Removed old grey plane from BuildVolume.
- Vertex data below build plane is no longer discarded (caused convex
hulls that are too small).
- Uses new functions in MeshBuilder (update Uranium as well).
CURA-1707
Diffstat (limited to 'cura/ConvexHullNode.py')
-rw-r--r-- | cura/ConvexHullNode.py | 49 |
1 files changed, 21 insertions, 28 deletions
diff --git a/cura/ConvexHullNode.py b/cura/ConvexHullNode.py index be571d111e..53bee40a8e 100644 --- a/cura/ConvexHullNode.py +++ b/cura/ConvexHullNode.py @@ -4,16 +4,16 @@ 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.MeshBuilder import MeshBuilder # To create a mesh to display the convex hull with. from UM.View.GL.OpenGL import OpenGL class ConvexHullNode(SceneNode): - ## Convex hull node is a special type of scene node that is used to display a 2D area, to indicate the + ## Convex hull node is a special type of scene node that is used to display an area, to indicate the # location an object uses on the buildplate. This area (or area's in case of one at a time printing) is - # then displayed as a transparent shadow. - def __init__(self, node, hull, parent = None): + # then displayed as a transparent shadow. If the adhesion type is set to raft, the area is extruded + # to represent the raft as well. + def __init__(self, node, hull, thickness, parent = None): super().__init__(parent) self.setCalculateBoundingBox(False) @@ -23,7 +23,7 @@ class ConvexHullNode(SceneNode): self._original_parent = parent # Color of the drawn convex hull - self._color = Color(35, 35, 35, 128) + self._color = Color(35, 35, 35, 192) # The y-coordinate of the convex hull mesh. Must not be 0, to prevent z-fighting. self._mesh_height = 0.1 @@ -34,11 +34,17 @@ class ConvexHullNode(SceneNode): self._onNodeDecoratorsChanged(self._node) self._convex_hull_head_mesh = None - self._hull = hull + self._hull = hull + self._thickness = thickness if self._hull: - hull_mesh = self.createHullMesh(self._hull.getPoints()) - if hull_mesh: + hull_mesh_builder = MeshBuilder() + + if hull_mesh_builder.addConvexPolygonExtrusion( + self._hull.getPoints()[::-1], # bottom layer is reversed + self._mesh_height-thickness, self._mesh_height, color=self._color): + + hull_mesh = hull_mesh_builder.build() self.setMeshData(hull_mesh) convex_hull_head = self._node.callDecoration("getConvexHullHead") if convex_hull_head: @@ -47,31 +53,17 @@ class ConvexHullNode(SceneNode): def getHull(self): return self._hull - ## Actually create the mesh from the hullpoints - # /param hull_points list of xy values - # /return meshData - def createHullMesh(self, hull_points): - # Input checking. - if len(hull_points) < 3: - return None - - mesh_builder = MeshBuilder() - 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. - - return mesh_builder.build() + def getThickness(self): + return self._thickness def getWatchedNode(self): return self._node def render(self, renderer): if not self._shader: - self._shader = OpenGL.getInstance().createShaderProgram(Resources.getPath(Resources.Shaders, "default.shader")) - self._shader.setUniformValue("u_color", self._color) + self._shader = OpenGL.getInstance().createShaderProgram(Resources.getPath(Resources.Shaders, "transparent_object.shader")) + self._shader.setUniformValue("u_diffuseColor", self._color) + self._shader.setUniformValue("u_opacity", 0.6) if self.getParent(): if self.getMeshData(): @@ -85,4 +77,5 @@ class ConvexHullNode(SceneNode): self._color = Color(35, 35, 35, 0.5) if not node: - return
\ No newline at end of file + return + |