2012-10-05 13:07:20 +00:00
|
|
|
import math, time, os
|
2012-05-07 11:24:26 +00:00
|
|
|
|
2012-10-05 13:07:20 +00:00
|
|
|
from util import meshLoader
|
2012-05-07 11:24:26 +00:00
|
|
|
from util import util3d
|
|
|
|
from util import profile
|
2012-04-05 20:35:52 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
import OpenGL
|
|
|
|
OpenGL.ERROR_CHECKING = False
|
|
|
|
from OpenGL.GLU import *
|
|
|
|
from OpenGL.GL import *
|
|
|
|
hasOpenGLlibs = True
|
|
|
|
except:
|
|
|
|
print "Failed to find PyOpenGL: http://pyopengl.sourceforge.net/"
|
|
|
|
hasOpenGLlibs = False
|
|
|
|
|
|
|
|
def InitGL(window, view3D, zoom):
|
|
|
|
# set viewing projection
|
|
|
|
glMatrixMode(GL_MODELVIEW)
|
|
|
|
glLoadIdentity()
|
|
|
|
size = window.GetSize()
|
|
|
|
glViewport(0,0, size.GetWidth(), size.GetHeight())
|
|
|
|
|
2012-11-06 07:52:16 +00:00
|
|
|
glLightfv(GL_LIGHT0, GL_POSITION, [0.2, 0.2, 1.0, 0.0])
|
2012-05-03 18:09:46 +00:00
|
|
|
glLightfv(GL_LIGHT1, GL_POSITION, [1.0, 1.0, 1.0, 0.0])
|
2012-04-05 20:35:52 +00:00
|
|
|
|
2012-09-03 10:06:05 +00:00
|
|
|
glEnable(GL_RESCALE_NORMAL)
|
2012-04-05 20:35:52 +00:00
|
|
|
glEnable(GL_LIGHTING)
|
|
|
|
glEnable(GL_LIGHT0)
|
|
|
|
glEnable(GL_DEPTH_TEST)
|
|
|
|
glEnable(GL_CULL_FACE)
|
|
|
|
glDisable(GL_BLEND)
|
|
|
|
|
2012-09-01 12:53:17 +00:00
|
|
|
glClearColor(1.0, 1.0, 1.0, 1.0)
|
2012-04-05 20:35:52 +00:00
|
|
|
glClearStencil(0)
|
|
|
|
glClearDepth(1.0)
|
|
|
|
|
|
|
|
glMatrixMode(GL_PROJECTION)
|
|
|
|
glLoadIdentity()
|
|
|
|
aspect = float(size.GetWidth()) / float(size.GetHeight())
|
|
|
|
if view3D:
|
2012-04-17 11:29:16 +00:00
|
|
|
gluPerspective(45.0, aspect, 1.0, 1000.0)
|
2012-04-05 20:35:52 +00:00
|
|
|
else:
|
2012-11-08 07:38:37 +00:00
|
|
|
glOrtho(-aspect * (zoom), aspect * (zoom), -1.0 * (zoom), 1.0 * (zoom), -1000.0, 1000.0)
|
2012-04-05 20:35:52 +00:00
|
|
|
|
|
|
|
glMatrixMode(GL_MODELVIEW)
|
|
|
|
glLoadIdentity()
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)
|
|
|
|
|
2012-10-05 13:07:20 +00:00
|
|
|
platformMesh = None
|
|
|
|
|
2012-04-05 20:35:52 +00:00
|
|
|
def DrawMachine(machineSize):
|
2012-10-05 13:07:20 +00:00
|
|
|
if profile.getPreference('machine_type') == 'ultimaker':
|
|
|
|
glPushMatrix()
|
|
|
|
glEnable(GL_LIGHTING)
|
2012-11-06 07:52:16 +00:00
|
|
|
glTranslate(100,200,-5)
|
2012-10-05 13:07:20 +00:00
|
|
|
glLightfv(GL_LIGHT0, GL_DIFFUSE, [0.8,0.8,0.8])
|
2012-10-05 20:26:40 +00:00
|
|
|
glLightfv(GL_LIGHT0, GL_AMBIENT, [0.5,0.5,0.5])
|
|
|
|
glEnable(GL_BLEND)
|
|
|
|
glBlendFunc(GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR)
|
2012-10-05 13:07:20 +00:00
|
|
|
|
|
|
|
global platformMesh
|
|
|
|
if platformMesh == None:
|
|
|
|
platformMesh = meshLoader.loadMesh(os.path.normpath(os.path.join(os.path.split(__file__)[0], "../images", 'ultimaker_platform.stl')))
|
2012-11-06 07:52:16 +00:00
|
|
|
platformMesh.setRotateMirror(0, False, False, False, False, False)
|
2012-10-05 13:07:20 +00:00
|
|
|
|
|
|
|
DrawMesh(platformMesh)
|
|
|
|
glPopMatrix()
|
|
|
|
|
2012-09-01 12:55:48 +00:00
|
|
|
glDisable(GL_LIGHTING)
|
2012-08-30 13:01:05 +00:00
|
|
|
if False:
|
|
|
|
glColor3f(0.7,0.7,0.7)
|
|
|
|
glLineWidth(2)
|
|
|
|
glBegin(GL_LINES)
|
|
|
|
for i in xrange(0, int(machineSize.x), 10):
|
|
|
|
glVertex3f(i, 0, 0)
|
|
|
|
glVertex3f(i, machineSize.y, 0)
|
|
|
|
for i in xrange(0, int(machineSize.y), 10):
|
|
|
|
glVertex3f(0, i, 0)
|
|
|
|
glVertex3f(machineSize.x, i, 0)
|
|
|
|
glEnd()
|
2012-09-02 12:25:38 +00:00
|
|
|
|
|
|
|
glEnable(GL_LINE_SMOOTH)
|
|
|
|
glEnable(GL_BLEND)
|
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
|
|
|
|
glHint(GL_LINE_SMOOTH_HINT, GL_DONT_CARE);
|
|
|
|
|
|
|
|
glColor3f(0.0,0.0,0.0)
|
|
|
|
glLineWidth(4)
|
|
|
|
glBegin(GL_LINE_LOOP)
|
|
|
|
glVertex3f(0, 0, 0)
|
|
|
|
glVertex3f(machineSize.x, 0, 0)
|
|
|
|
glVertex3f(machineSize.x, machineSize.y, 0)
|
|
|
|
glVertex3f(0, machineSize.y, 0)
|
|
|
|
glEnd()
|
|
|
|
|
|
|
|
glLineWidth(2)
|
|
|
|
glBegin(GL_LINE_LOOP)
|
|
|
|
glVertex3f(0, 0, machineSize.z)
|
|
|
|
glVertex3f(machineSize.x, 0, machineSize.z)
|
|
|
|
glVertex3f(machineSize.x, machineSize.y, machineSize.z)
|
|
|
|
glVertex3f(0, machineSize.y, machineSize.z)
|
|
|
|
glEnd()
|
|
|
|
glBegin(GL_LINES)
|
|
|
|
glVertex3f(0, 0, 0)
|
|
|
|
glVertex3f(0, 0, machineSize.z)
|
|
|
|
glVertex3f(machineSize.x, 0, 0)
|
|
|
|
glVertex3f(machineSize.x, 0, machineSize.z)
|
|
|
|
glVertex3f(machineSize.x, machineSize.y, 0)
|
|
|
|
glVertex3f(machineSize.x, machineSize.y, machineSize.z)
|
|
|
|
glVertex3f(0, machineSize.y, 0)
|
|
|
|
glVertex3f(0, machineSize.y, machineSize.z)
|
|
|
|
glEnd()
|
2012-08-30 13:01:05 +00:00
|
|
|
else:
|
|
|
|
glDisable(GL_CULL_FACE)
|
|
|
|
glEnable(GL_BLEND)
|
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
|
2012-09-01 12:53:17 +00:00
|
|
|
glColor4ub(5,171,231,127)
|
2012-08-30 13:01:05 +00:00
|
|
|
glBegin(GL_QUADS)
|
|
|
|
for x in xrange(0, int(machineSize.x), 20):
|
|
|
|
for y in xrange(0, int(machineSize.y), 20):
|
|
|
|
glVertex3f(x, y, -0.01)
|
|
|
|
glVertex3f(min(x+10, machineSize.x), y, -0.01)
|
|
|
|
glVertex3f(min(x+10, machineSize.x), min(y+10, machineSize.y), -0.01)
|
|
|
|
glVertex3f(x, min(y+10, machineSize.y), -0.01)
|
|
|
|
for x in xrange(10, int(machineSize.x), 20):
|
|
|
|
for y in xrange(10, int(machineSize.y), 20):
|
|
|
|
glVertex3f(x, y, -0.01)
|
|
|
|
glVertex3f(min(x+10, machineSize.x), y, -0.01)
|
|
|
|
glVertex3f(min(x+10, machineSize.x), min(y+10, machineSize.y), -0.01)
|
|
|
|
glVertex3f(x, min(y+10, machineSize.y), -0.01)
|
|
|
|
glEnd()
|
2012-11-06 07:52:16 +00:00
|
|
|
glColor4ub(5*8/10,171*8/10,231*8/10,128)
|
2012-09-01 12:53:17 +00:00
|
|
|
glBegin(GL_QUADS)
|
|
|
|
for x in xrange(10, int(machineSize.x), 20):
|
|
|
|
for y in xrange(0, int(machineSize.y), 20):
|
|
|
|
glVertex3f(x, y, -0.01)
|
|
|
|
glVertex3f(min(x+10, machineSize.x), y, -0.01)
|
|
|
|
glVertex3f(min(x+10, machineSize.x), min(y+10, machineSize.y), -0.01)
|
|
|
|
glVertex3f(x, min(y+10, machineSize.y), -0.01)
|
|
|
|
for x in xrange(0, int(machineSize.x), 20):
|
|
|
|
for y in xrange(10, int(machineSize.y), 20):
|
|
|
|
glVertex3f(x, y, -0.01)
|
|
|
|
glVertex3f(min(x+10, machineSize.x), y, -0.01)
|
|
|
|
glVertex3f(min(x+10, machineSize.x), min(y+10, machineSize.y), -0.01)
|
|
|
|
glVertex3f(x, min(y+10, machineSize.y), -0.01)
|
|
|
|
glEnd()
|
2012-08-30 13:01:05 +00:00
|
|
|
glEnable(GL_CULL_FACE)
|
2012-09-01 12:53:17 +00:00
|
|
|
|
2012-11-06 07:52:16 +00:00
|
|
|
glColor4ub(5,171,231,64)
|
2012-09-02 12:25:38 +00:00
|
|
|
glBegin(GL_QUADS)
|
|
|
|
glVertex3f(0, 0, machineSize.z)
|
|
|
|
glVertex3f(0, machineSize.y, machineSize.z)
|
|
|
|
glVertex3f(machineSize.x, machineSize.y, machineSize.z)
|
|
|
|
glVertex3f(machineSize.x, 0, machineSize.z)
|
|
|
|
glEnd()
|
|
|
|
|
2012-11-06 07:52:16 +00:00
|
|
|
glColor4ub(5,171,231,96)
|
2012-09-02 12:25:38 +00:00
|
|
|
glBegin(GL_QUADS)
|
|
|
|
glVertex3f(0, 0, 0)
|
|
|
|
glVertex3f(0, 0, machineSize.z)
|
|
|
|
glVertex3f(machineSize.x, 0, machineSize.z)
|
|
|
|
glVertex3f(machineSize.x, 0, 0)
|
|
|
|
|
|
|
|
glVertex3f(0, machineSize.y, machineSize.z)
|
|
|
|
glVertex3f(0, machineSize.y, 0)
|
|
|
|
glVertex3f(machineSize.x, machineSize.y, 0)
|
|
|
|
glVertex3f(machineSize.x, machineSize.y, machineSize.z)
|
|
|
|
glEnd()
|
2012-04-05 20:35:52 +00:00
|
|
|
|
2012-11-06 07:52:16 +00:00
|
|
|
glColor4ub(5,171,231,128)
|
2012-09-02 12:25:38 +00:00
|
|
|
glBegin(GL_QUADS)
|
|
|
|
glVertex3f(0, 0, machineSize.z)
|
|
|
|
glVertex3f(0, 0, 0)
|
|
|
|
glVertex3f(0, machineSize.y, 0)
|
|
|
|
glVertex3f(0, machineSize.y, machineSize.z)
|
|
|
|
|
2012-10-19 07:55:48 +00:00
|
|
|
glVertex3f(machineSize.x, 0, 0)
|
|
|
|
glVertex3f(machineSize.x, 0, machineSize.z)
|
2012-09-02 12:25:38 +00:00
|
|
|
glVertex3f(machineSize.x, machineSize.y, machineSize.z)
|
|
|
|
glVertex3f(machineSize.x, machineSize.y, 0)
|
|
|
|
glEnd()
|
|
|
|
|
|
|
|
glDisable(GL_BLEND)
|
|
|
|
|
2012-04-22 11:11:21 +00:00
|
|
|
glPushMatrix()
|
2012-09-06 14:54:27 +00:00
|
|
|
glTranslate(5,5,2)
|
2012-04-22 11:11:21 +00:00
|
|
|
glLineWidth(2)
|
|
|
|
glColor3f(0.5,0,0)
|
|
|
|
glBegin(GL_LINES)
|
|
|
|
glVertex3f(0,0,0)
|
|
|
|
glVertex3f(20,0,0)
|
|
|
|
glEnd()
|
|
|
|
glColor3f(0,0.5,0)
|
|
|
|
glBegin(GL_LINES)
|
|
|
|
glVertex3f(0,0,0)
|
|
|
|
glVertex3f(0,20,0)
|
|
|
|
glEnd()
|
|
|
|
glColor3f(0,0,0.5)
|
|
|
|
glBegin(GL_LINES)
|
|
|
|
glVertex3f(0,0,0)
|
|
|
|
glVertex3f(0,0,20)
|
|
|
|
glEnd()
|
|
|
|
|
|
|
|
glDisable(GL_DEPTH_TEST)
|
|
|
|
#X
|
|
|
|
glColor3f(1,0,0)
|
|
|
|
glPushMatrix()
|
|
|
|
glTranslate(23,0,0)
|
|
|
|
noZ = ResetMatrixRotationAndScale()
|
|
|
|
glBegin(GL_LINES)
|
|
|
|
glVertex3f(-0.8,1,0)
|
|
|
|
glVertex3f(0.8,-1,0)
|
|
|
|
glVertex3f(0.8,1,0)
|
|
|
|
glVertex3f(-0.8,-1,0)
|
|
|
|
glEnd()
|
|
|
|
glPopMatrix()
|
|
|
|
|
|
|
|
#Y
|
|
|
|
glColor3f(0,1,0)
|
|
|
|
glPushMatrix()
|
|
|
|
glTranslate(0,23,0)
|
|
|
|
ResetMatrixRotationAndScale()
|
|
|
|
glBegin(GL_LINES)
|
|
|
|
glVertex3f(-0.8, 1,0)
|
|
|
|
glVertex3f( 0.0, 0,0)
|
|
|
|
glVertex3f( 0.8, 1,0)
|
|
|
|
glVertex3f(-0.8,-1,0)
|
|
|
|
glEnd()
|
|
|
|
glPopMatrix()
|
|
|
|
|
|
|
|
#Z
|
|
|
|
if not noZ:
|
|
|
|
glColor3f(0,0,1)
|
|
|
|
glPushMatrix()
|
|
|
|
glTranslate(0,0,23)
|
|
|
|
ResetMatrixRotationAndScale()
|
|
|
|
glBegin(GL_LINES)
|
|
|
|
glVertex3f(-0.8, 1,0)
|
|
|
|
glVertex3f( 0.8, 1,0)
|
|
|
|
glVertex3f( 0.8, 1,0)
|
|
|
|
glVertex3f(-0.8,-1,0)
|
|
|
|
glVertex3f(-0.8,-1,0)
|
|
|
|
glVertex3f( 0.8,-1,0)
|
|
|
|
glEnd()
|
|
|
|
glPopMatrix()
|
|
|
|
|
|
|
|
glPopMatrix()
|
|
|
|
glEnable(GL_DEPTH_TEST)
|
|
|
|
|
|
|
|
def ResetMatrixRotationAndScale():
|
|
|
|
matrix = glGetFloatv(GL_MODELVIEW_MATRIX)
|
|
|
|
noZ = False
|
2012-04-25 14:30:51 +00:00
|
|
|
if matrix[3][2] > 0:
|
|
|
|
return False
|
2012-04-22 11:11:21 +00:00
|
|
|
scale2D = matrix[0][0]
|
|
|
|
matrix[0][0] = 1.0
|
|
|
|
matrix[1][0] = 0.0
|
|
|
|
matrix[2][0] = 0.0
|
|
|
|
matrix[0][1] = 0.0
|
|
|
|
matrix[1][1] = 1.0
|
|
|
|
matrix[2][1] = 0.0
|
|
|
|
matrix[0][2] = 0.0
|
|
|
|
matrix[1][2] = 0.0
|
|
|
|
matrix[2][2] = 1.0
|
|
|
|
|
|
|
|
if matrix[3][2] != 0.0:
|
2012-06-01 09:29:21 +00:00
|
|
|
matrix[3][0] = matrix[3][0] / (-matrix[3][2] / 100)
|
|
|
|
matrix[3][1] = matrix[3][1] / (-matrix[3][2] / 100)
|
2012-04-22 11:11:21 +00:00
|
|
|
matrix[3][2] = -100
|
|
|
|
else:
|
|
|
|
matrix[0][0] = scale2D
|
|
|
|
matrix[1][1] = scale2D
|
|
|
|
matrix[2][2] = scale2D
|
|
|
|
matrix[3][2] = -100
|
|
|
|
noZ = True
|
|
|
|
|
|
|
|
glLoadMatrixf(matrix)
|
|
|
|
return noZ
|
|
|
|
|
2012-04-17 17:12:40 +00:00
|
|
|
def DrawBox(vMin, vMax):
|
|
|
|
glBegin(GL_LINE_LOOP)
|
2012-07-26 14:30:43 +00:00
|
|
|
glVertex3f(vMin[0], vMin[1], vMin[2])
|
|
|
|
glVertex3f(vMax[0], vMin[1], vMin[2])
|
|
|
|
glVertex3f(vMax[0], vMax[1], vMin[2])
|
|
|
|
glVertex3f(vMin[0], vMax[1], vMin[2])
|
2012-04-17 17:12:40 +00:00
|
|
|
glEnd()
|
|
|
|
|
|
|
|
glBegin(GL_LINE_LOOP)
|
2012-07-26 14:30:43 +00:00
|
|
|
glVertex3f(vMin[0], vMin[1], vMax[2])
|
|
|
|
glVertex3f(vMax[0], vMin[1], vMax[2])
|
|
|
|
glVertex3f(vMax[0], vMax[1], vMax[2])
|
|
|
|
glVertex3f(vMin[0], vMax[1], vMax[2])
|
2012-04-17 17:12:40 +00:00
|
|
|
glEnd()
|
|
|
|
glBegin(GL_LINES)
|
2012-07-26 14:30:43 +00:00
|
|
|
glVertex3f(vMin[0], vMin[1], vMin[2])
|
|
|
|
glVertex3f(vMin[0], vMin[1], vMax[2])
|
|
|
|
glVertex3f(vMax[0], vMin[1], vMin[2])
|
|
|
|
glVertex3f(vMax[0], vMin[1], vMax[2])
|
|
|
|
glVertex3f(vMax[0], vMax[1], vMin[2])
|
|
|
|
glVertex3f(vMax[0], vMax[1], vMax[2])
|
|
|
|
glVertex3f(vMin[0], vMax[1], vMin[2])
|
|
|
|
glVertex3f(vMin[0], vMax[1], vMax[2])
|
2012-04-17 17:12:40 +00:00
|
|
|
glEnd()
|
|
|
|
|
2012-07-31 14:39:31 +00:00
|
|
|
def DrawMeshOutline(mesh):
|
|
|
|
glEnable(GL_CULL_FACE)
|
|
|
|
glEnableClientState(GL_VERTEX_ARRAY);
|
|
|
|
glVertexPointer(3, GL_FLOAT, 0, mesh.vertexes)
|
2012-07-31 15:29:58 +00:00
|
|
|
|
2012-07-31 14:39:31 +00:00
|
|
|
glCullFace(GL_FRONT)
|
|
|
|
glLineWidth(3)
|
|
|
|
glPolygonMode(GL_BACK, GL_LINE)
|
|
|
|
glDrawArrays(GL_TRIANGLES, 0, mesh.vertexCount)
|
|
|
|
glPolygonMode(GL_BACK, GL_FILL)
|
|
|
|
glCullFace(GL_BACK)
|
|
|
|
|
|
|
|
glDisableClientState(GL_VERTEX_ARRAY)
|
|
|
|
|
|
|
|
def DrawMesh(mesh):
|
2012-05-03 18:09:46 +00:00
|
|
|
glEnable(GL_CULL_FACE)
|
2012-07-30 09:02:49 +00:00
|
|
|
glEnableClientState(GL_VERTEX_ARRAY);
|
|
|
|
glEnableClientState(GL_NORMAL_ARRAY);
|
|
|
|
glVertexPointer(3, GL_FLOAT, 0, mesh.vertexes)
|
|
|
|
glNormalPointer(GL_FLOAT, 0, mesh.normal)
|
2012-10-04 10:04:04 +00:00
|
|
|
|
|
|
|
#Odd, drawing in batchs is a LOT faster then drawing it all at once.
|
|
|
|
batchSize = 999 #Warning, batchSize needs to be dividable by 3
|
|
|
|
extraStartPos = int(mesh.vertexCount / batchSize) * batchSize
|
|
|
|
extraCount = mesh.vertexCount - extraStartPos
|
2012-07-30 09:02:49 +00:00
|
|
|
|
|
|
|
glCullFace(GL_BACK)
|
2012-10-04 10:04:04 +00:00
|
|
|
for i in xrange(0, int(mesh.vertexCount / batchSize)):
|
|
|
|
glDrawArrays(GL_TRIANGLES, i*batchSize, batchSize)
|
|
|
|
glDrawArrays(GL_TRIANGLES, extraStartPos, extraCount)
|
2012-07-30 09:02:49 +00:00
|
|
|
|
|
|
|
glCullFace(GL_FRONT)
|
|
|
|
glNormalPointer(GL_FLOAT, 0, mesh.invNormal)
|
2012-10-04 10:04:04 +00:00
|
|
|
for i in xrange(0, int(mesh.vertexCount / batchSize)):
|
|
|
|
glDrawArrays(GL_TRIANGLES, i*batchSize, batchSize)
|
|
|
|
extraStartPos = int(mesh.vertexCount / batchSize) * batchSize
|
|
|
|
extraCount = mesh.vertexCount - extraStartPos
|
|
|
|
glDrawArrays(GL_TRIANGLES, extraStartPos, extraCount)
|
2012-07-31 14:12:02 +00:00
|
|
|
glCullFace(GL_BACK)
|
2012-07-30 09:02:49 +00:00
|
|
|
|
|
|
|
glDisableClientState(GL_VERTEX_ARRAY)
|
|
|
|
glDisableClientState(GL_NORMAL_ARRAY);
|
2012-05-07 11:24:26 +00:00
|
|
|
|
|
|
|
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]]
|
2012-06-01 10:02:50 +00:00
|
|
|
moveColor = [0,0,1]
|
2012-06-20 00:34:59 +00:00
|
|
|
retractColor = [1,0,0.5]
|
2012-06-01 10:02:50 +00:00
|
|
|
supportColor = [0,1,1]
|
|
|
|
extrudeColor = [1,0,0]
|
|
|
|
innerWallColor = [0,1,0]
|
|
|
|
skirtColor = [0,0.5,0.5]
|
|
|
|
prevPathWasRetract = False
|
2012-05-07 11:24:26 +00:00
|
|
|
|
|
|
|
glDisable(GL_CULL_FACE)
|
|
|
|
for path in layer:
|
|
|
|
if path.type == 'move':
|
2012-06-01 10:02:50 +00:00
|
|
|
if prevPathWasRetract:
|
|
|
|
c = retractColor
|
|
|
|
else:
|
|
|
|
c = moveColor
|
2012-10-01 12:36:47 +00:00
|
|
|
zOffset = 0.01
|
2012-05-07 11:24:26 +00:00
|
|
|
if path.type == 'extrude':
|
|
|
|
if path.pathType == 'FILL':
|
2012-06-01 10:02:50 +00:00
|
|
|
c = fillColorCycle[fillCycle]
|
2012-05-07 11:24:26 +00:00
|
|
|
fillCycle = (fillCycle + 1) % len(fillColorCycle)
|
|
|
|
elif path.pathType == 'WALL-INNER':
|
2012-06-01 10:02:50 +00:00
|
|
|
c = innerWallColor
|
2012-10-01 12:36:47 +00:00
|
|
|
zOffset = 0.02
|
2012-05-07 11:24:26 +00:00
|
|
|
elif path.pathType == 'SUPPORT':
|
2012-06-01 10:02:50 +00:00
|
|
|
c = supportColor
|
2012-05-07 11:24:26 +00:00
|
|
|
elif path.pathType == 'SKIRT':
|
2012-06-01 10:02:50 +00:00
|
|
|
c = skirtColor
|
2012-05-07 11:24:26 +00:00
|
|
|
else:
|
2012-06-01 10:02:50 +00:00
|
|
|
c = extrudeColor
|
2012-05-07 11:24:26 +00:00
|
|
|
if path.type == 'retract':
|
2012-06-01 10:02:50 +00:00
|
|
|
c = [0,1,1]
|
2012-05-07 11:24:26 +00:00
|
|
|
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
|
2012-11-06 07:52:16 +00:00
|
|
|
lineWidth = extrusionMMperDist * filamentArea / path.layerThickness / 2 * v1.extrudeAmountMultiply
|
2012-05-07 11:24:26 +00:00
|
|
|
|
|
|
|
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)
|
2012-06-01 10:02:50 +00:00
|
|
|
glColor3fv(c)
|
2012-10-01 12:36:47 +00:00
|
|
|
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)
|
2012-05-07 11:24:26 +00:00
|
|
|
glEnd()
|
|
|
|
if prevNormal != None:
|
|
|
|
n = (normal + prevNormal)
|
|
|
|
n.normalize()
|
|
|
|
vv4 = v0 + n * lineWidth
|
|
|
|
vv5 = v0 - n * lineWidth
|
|
|
|
glBegin(GL_QUADS)
|
2012-06-01 10:02:50 +00:00
|
|
|
glColor3fv(c)
|
2012-10-01 12:36:47 +00:00
|
|
|
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)
|
2012-05-07 11:24:26 +00:00
|
|
|
|
2012-10-01 12:36:47 +00:00
|
|
|
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)
|
2012-05-07 11:24:26 +00:00
|
|
|
glEnd()
|
|
|
|
|
|
|
|
prevNormal = normal
|
|
|
|
prevVv1 = vv1
|
|
|
|
prevVv3 = vv3
|
|
|
|
else:
|
|
|
|
glBegin(GL_LINE_STRIP)
|
2012-06-01 10:02:50 +00:00
|
|
|
glColor3fv(c)
|
2012-05-07 11:24:26 +00:00
|
|
|
for v in path.list:
|
|
|
|
glVertex3f(v.x, v.y, v.z)
|
|
|
|
glEnd()
|
2012-06-20 00:34:59 +00:00
|
|
|
if not path.type == 'move':
|
|
|
|
prevPathWasRetract = False
|
2012-06-01 11:27:19 +00:00
|
|
|
if path.type == 'retract' and path.list[0].almostEqual(path.list[-1]):
|
2012-06-01 10:02:50 +00:00
|
|
|
prevPathWasRetract = True
|
2012-05-07 11:24:26 +00:00
|
|
|
glEnable(GL_CULL_FACE)
|