Added few missing options

Added transparent mode to 3D preview
master
Daid 2012-02-21 00:54:04 +01:00
parent 68944bb221
commit 1414737787
2 changed files with 52 additions and 22 deletions

View File

@ -65,6 +65,7 @@ class mainWindow(wx.Frame):
self.AddSetting(configPanel, "Speed (mm/s)", self.plugins['dimension'].preferencesDict['Extruder_Retraction_Speed_mm/s'])
self.AddSetting(configPanel, "Distance (mm)", self.plugins['dimension'].preferencesDict['Retraction_Distance_millimeters'])
self.AddSetting(configPanel, "Extra length on start (mm)", self.plugins['dimension'].preferencesDict['Restart_Extra_Distance_millimeters'])
self.AddSetting(configPanel, "Minimal travel (mm)", self.plugins['dimension'].preferencesDict['Minimum_Travel_for_Retraction_millimeters'])
configPanel = wx.Panel(nb);
nb.AddPage(configPanel, "Machine")
@ -82,6 +83,8 @@ class mainWindow(wx.Frame):
self.AddTitle(configPanel, "Speed")
self.AddSetting(configPanel, "Print speed (mm/s)", self.plugins['speed'].preferencesDict['Feed_Rate_mm/s'])
self.AddSetting(configPanel, "Travel speed (mm/s)", self.plugins['speed'].preferencesDict['Travel_Feed_Rate_mm/s'])
self.AddSetting(configPanel, "Max Z speed (mm/z)", self.plugins['speed'].preferencesDict['Maximum_Z_Feed_Rate_mm/s'])
self.AddSetting(configPanel, "Bottom Layer Speed Ratio", self.plugins['speed'].preferencesDict['Object_First_Layer_Feed_Rate_Infill_Multiplier_ratio'])
self.AddTitle(configPanel, "Filament")
self.AddSetting(configPanel, "Diameter (mm)", self.plugins['dimension'].preferencesDict['Filament_Diameter_mm'])
@ -136,6 +139,7 @@ class mainWindow(wx.Frame):
self.controlList.append(ctrl)
sizer.Add(ctrl, (sizer.GetRows(),2), flag=wx.ALIGN_BOTTOM|wx.EXPAND)
sizer.SetRows(sizer.GetRows()+1)
return ctrl
def OnSaveProfile(self, e):
dlg=wx.FileDialog(self, "Select profile file to save", style=wx.FD_SAVE)

View File

@ -28,8 +28,11 @@ class myGLCanvas(GLCanvas):
self.yaw = 30
self.pitch = 60
self.zoom = 150
self.renderTransparent = False
self.machineSize = Vector3(210, 210, 200)
self.machineCenter = Vector3(100, 100, 0)
configButton = wx.Button(self, -1, '', (3,3), (10,10))
self.Bind(wx.EVT_BUTTON, self.OnConfigClick, configButton)
def loadFile(self, filename):
self.filename = filename
@ -43,7 +46,11 @@ class myGLCanvas(GLCanvas):
self.triangleMesh = fabmetheus_interpret.getCarving(self.filename)
self.moveModel()
self.Refresh()
def OnConfigClick(self, e):
self.renderTransparent = not self.renderTransparent
self.Refresh()
def moveModel(self):
if self.triangleMesh == None:
return
@ -97,27 +104,6 @@ class myGLCanvas(GLCanvas):
glTranslate(-self.machineCenter.x, -self.machineCenter.y, 0)
if self.triangleMesh != None:
if self.modelDisplayList == None:
self.modelDisplayList = glGenLists(1);
if self.modelDirty:
self.modelDirty = False
glNewList(self.modelDisplayList, GL_COMPILE)
glBegin(GL_TRIANGLES)
for face in self.triangleMesh.faces:
v1 = self.triangleMesh.vertexes[face.vertexIndexes[0]]
v2 = self.triangleMesh.vertexes[face.vertexIndexes[1]]
v3 = self.triangleMesh.vertexes[face.vertexIndexes[2]]
normal = (v2 - v1).cross(v3 - v1)
normal.normalize()
glNormal3f(normal.x, normal.y, normal.z)
glVertex3f(v1.x, v1.y, v1.z)
glVertex3f(v2.x, v2.y, v2.z)
glVertex3f(v3.x, v3.y, v3.z)
glEnd()
glEndList()
glCallList(self.modelDisplayList)
glLineWidth(4)
glDisable(GL_LIGHTING)
glBegin(GL_LINE_LOOP)
@ -152,6 +138,44 @@ class myGLCanvas(GLCanvas):
glVertex3f(0, self.machineSize.y, 0)
glVertex3f(0, self.machineSize.y, self.machineSize.z)
glEnd()
if self.triangleMesh != None:
if self.modelDisplayList == None:
self.modelDisplayList = glGenLists(1);
if self.modelDirty:
self.modelDirty = False
glNewList(self.modelDisplayList, GL_COMPILE)
glBegin(GL_TRIANGLES)
for face in self.triangleMesh.faces:
v1 = self.triangleMesh.vertexes[face.vertexIndexes[0]]
v2 = self.triangleMesh.vertexes[face.vertexIndexes[1]]
v3 = self.triangleMesh.vertexes[face.vertexIndexes[2]]
normal = (v2 - v1).cross(v3 - v1)
normal.normalize()
glNormal3f(normal.x, normal.y, normal.z)
glVertex3f(v1.x, v1.y, v1.z)
glVertex3f(v2.x, v2.y, v2.z)
glVertex3f(v3.x, v3.y, v3.z)
glEnd()
glEndList()
if self.renderTransparent:
#If we want transparent, then first render a solid black model to remove the printer size lines.
glDisable(GL_BLEND)
glDisable(GL_LIGHTING)
glColor3f(0,0,0)
glCallList(self.modelDisplayList)
glColor3f(1,1,1)
#After the black model is rendered, render the model again but now with lighting and no depth testing.
glDisable(GL_DEPTH_TEST)
glEnable(GL_LIGHTING)
glEnable(GL_BLEND)
glBlendFunc(GL_ONE, GL_ONE)
glEnable(GL_LIGHTING)
glCallList(self.modelDisplayList)
else:
glEnable(GL_LIGHTING)
glCallList(self.modelDisplayList)
self.SwapBuffers()
return
@ -168,6 +192,8 @@ class myGLCanvas(GLCanvas):
glEnable(GL_LIGHTING)
glEnable(GL_LIGHT0)
glEnable(GL_DEPTH_TEST)
glDisable(GL_BLEND)
glClearColor(0.0, 0.0, 0.0, 1.0)
glClearDepth(1.0)