-
-
-def DrawGCodeLayer(layer):
- 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], [0.0, 0.5, 0.5], [0.5, 0.0, 0.5]]
- moveColor = [0, 0, 1]
- retractColor = [1, 0, 0.5]
- supportColor = [0, 1, 1]
- extrudeColor = [1, 0, 0]
- innerWallColor = [0, 1, 0]
- skirtColor = [0, 0.5, 0.5]
- prevPathWasRetract = False
-
- glDisable(GL_CULL_FACE)
- for path in layer:
- if path.type == 'move':
- if prevPathWasRetract:
- c = retractColor
- else:
- c = moveColor
- 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
- if path.type == 'retract':
- c = [0, 1, 1]
- if path.type == 'extrude':
- drawLength = 0.0
- prevNormal = None
- for i in xrange(0, len(path.list) - 1):
- v0 = path.list[i]
- v1 = path.list[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)
- glColor3fv(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)
- glColor3fv(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:
- glBegin(GL_LINE_STRIP)
- glColor3fv(c)
- for v in path.list:
- glVertex3f(v.x, v.y, v.z)
- glEnd()
- if not path.type == 'move':
- prevPathWasRetract = False
- if path.type == 'retract' and path.list[0].almostEqual(path.list[-1]):
- prevPathWasRetract = True
- glEnable(GL_CULL_FACE)