-
-def DrawGCodeLayer(layer, drawQuick = True):
- filamentRadius = profile.getProfileSettingFloat('filament_diameter') / 2
- filamentArea = math.pi * filamentRadius * filamentRadius
- lineWidth = profile.getProfileSettingFloat('nozzle_size') / 2 / 10
-
- fillCycle = 0
- fillColorCycle = [[0.5, 0.5, 0.0, 1], [0.0, 0.5, 0.5, 1], [0.5, 0.0, 0.5, 1]]
- moveColor = [0, 0, 1, 0.5]
- retractColor = [1, 0, 0.5, 0.5]
- supportColor = [0, 1, 1, 1]
- extrudeColor = [[1, 0, 0, 1], [0, 1, 1, 1], [1, 1, 0, 1], [1, 0, 1, 1]]
- innerWallColor = [0, 1, 0, 1]
- skirtColor = [0, 0.5, 0.5, 1]
- prevPathWasRetract = False
-
- glDisable(GL_CULL_FACE)
- for path in layer:
- if path.type == 'move':
- if prevPathWasRetract:
- c = retractColor
- else:
- c = moveColor
- if drawQuick:
- continue
- zOffset = 0.01
- if path.type == 'extrude':
- if path.pathType == 'FILL':
- c = fillColorCycle[fillCycle]
- fillCycle = (fillCycle + 1) % len(fillColorCycle)
- elif path.pathType == 'WALL-INNER':
- c = innerWallColor
- zOffset = 0.02
- elif path.pathType == 'SUPPORT':
- c = supportColor
- elif path.pathType == 'SKIRT':
- c = skirtColor
- else:
- c = extrudeColor[path.extruder]
- if path.type == 'retract':
- c = retractColor
- if path.type == 'extrude' and not drawQuick:
- drawLength = 0.0
- prevNormal = None
- for i in xrange(0, len(path.points) - 1):
- v0 = path.points[i]
- v1 = path.points[i + 1]
-
- # Calculate line width from ePerDistance (needs layer thickness and filament diameter)
- dist = (v0 - v1).vsize()
- if dist > 0 and path.layerThickness > 0:
- extrusionMMperDist = (v1.e - v0.e) / dist
- lineWidth = extrusionMMperDist * filamentArea / path.layerThickness / 2 * v1.extrudeAmountMultiply
-
- drawLength += (v0 - v1).vsize()
- normal = (v0 - v1).cross(util3d.Vector3(0, 0, 1))
- normal.normalize()
-
- vv2 = v0 + normal * lineWidth
- vv3 = v1 + normal * lineWidth
- vv0 = v0 - normal * lineWidth
- vv1 = v1 - normal * lineWidth
-
- glBegin(GL_QUADS)
- glColor4fv(c)
- glVertex3f(vv0.x, vv0.y, vv0.z - zOffset)
- glVertex3f(vv1.x, vv1.y, vv1.z - zOffset)
- glVertex3f(vv3.x, vv3.y, vv3.z - zOffset)
- glVertex3f(vv2.x, vv2.y, vv2.z - zOffset)
- glEnd()
- if prevNormal is not None:
- n = (normal + prevNormal)
- n.normalize()
- vv4 = v0 + n * lineWidth
- vv5 = v0 - n * lineWidth
- glBegin(GL_QUADS)
- glColor4fv(c)
- glVertex3f(vv2.x, vv2.y, vv2.z - zOffset)
- glVertex3f(vv4.x, vv4.y, vv4.z - zOffset)
- glVertex3f(prevVv3.x, prevVv3.y, prevVv3.z - zOffset)
- glVertex3f(v0.x, v0.y, v0.z - zOffset)
-
- glVertex3f(vv0.x, vv0.y, vv0.z - zOffset)
- glVertex3f(vv5.x, vv5.y, vv5.z - zOffset)
- glVertex3f(prevVv1.x, prevVv1.y, prevVv1.z - zOffset)
- glVertex3f(v0.x, v0.y, v0.z - zOffset)
- glEnd()
-
- prevNormal = normal
- prevVv1 = vv1
- prevVv3 = vv3
- else:
- glColor4fv(c)
- glBegin(GL_TRIANGLES)
- for v in path.points:
- glVertex3f(v[0], v[1], v[2])
- glEnd()
-
- if not path.type == 'move':
- prevPathWasRetract = False
- #if path.type == 'retract' and path.points[0].almostEqual(path.points[-1]):
- # prevPathWasRetract = True
- glEnable(GL_CULL_FACE)