Commit 6ece0b1f authored by Guillaume Seguin's avatar Guillaume Seguin

Add optional antialiasing to 3D gcode viewer

parent 41f3721f
...@@ -49,9 +49,11 @@ def set_model_colors(model, root): ...@@ -49,9 +49,11 @@ def set_model_colors(model, root):
class GcodeViewPanel(wxGLPanel): class GcodeViewPanel(wxGLPanel):
def __init__(self, parent, id = wx.ID_ANY, def __init__(self, parent, id = wx.ID_ANY,
build_dimensions = None, realparent = None): build_dimensions = None, realparent = None,
antialias_samples = 0):
super(GcodeViewPanel, self).__init__(parent, id, wx.DefaultPosition, super(GcodeViewPanel, self).__init__(parent, id, wx.DefaultPosition,
wx.DefaultSize, 0) wx.DefaultSize, 0,
antialias_samples = antialias_samples)
self.canvas.Bind(wx.EVT_MOUSE_EVENTS, self.move) self.canvas.Bind(wx.EVT_MOUSE_EVENTS, self.move)
self.canvas.Bind(wx.EVT_LEFT_DCLICK, self.double) self.canvas.Bind(wx.EVT_LEFT_DCLICK, self.double)
self.canvas.Bind(wx.EVT_KEY_DOWN, self.keypress) self.canvas.Bind(wx.EVT_KEY_DOWN, self.keypress)
...@@ -282,10 +284,11 @@ class GcodeViewLoader(object): ...@@ -282,10 +284,11 @@ class GcodeViewLoader(object):
class GcodeViewMainWrapper(GcodeViewLoader): class GcodeViewMainWrapper(GcodeViewLoader):
def __init__(self, parent, build_dimensions, root, circular): def __init__(self, parent, build_dimensions, root, circular, antialias_samples):
self.root = root self.root = root
self.glpanel = GcodeViewPanel(parent, realparent = self, self.glpanel = GcodeViewPanel(parent, realparent = self,
build_dimensions = build_dimensions) build_dimensions = build_dimensions,
antialias_samples = antialias_samples)
self.glpanel.SetMinSize((150, 150)) self.glpanel.SetMinSize((150, 150))
if self.root and hasattr(self.root, "gcview_color_background"): if self.root and hasattr(self.root, "gcview_color_background"):
self.glpanel.color_background = self.root.gcview_color_background self.glpanel.color_background = self.root.gcview_color_background
...@@ -331,7 +334,8 @@ class GcodeViewFrame(GvizBaseFrame, GcodeViewLoader): ...@@ -331,7 +334,8 @@ class GcodeViewFrame(GvizBaseFrame, GcodeViewLoader):
def __init__(self, parent, ID, title, build_dimensions, objects = None, def __init__(self, parent, ID, title, build_dimensions, objects = None,
pos = wx.DefaultPosition, size = wx.DefaultSize, pos = wx.DefaultPosition, size = wx.DefaultSize,
style = wx.DEFAULT_FRAME_STYLE, root = None, circular = False): style = wx.DEFAULT_FRAME_STYLE, root = None, circular = False,
antialias_samples = 0):
GvizBaseFrame.__init__(self, parent, ID, title, GvizBaseFrame.__init__(self, parent, ID, title,
pos, size, style) pos, size, style)
self.root = root self.root = root
...@@ -355,7 +359,8 @@ class GcodeViewFrame(GvizBaseFrame, GcodeViewLoader): ...@@ -355,7 +359,8 @@ class GcodeViewFrame(GvizBaseFrame, GcodeViewLoader):
self.toolbar.Realize() self.toolbar.Realize()
self.glpanel = GcodeViewPanel(panel, self.glpanel = GcodeViewPanel(panel,
build_dimensions = build_dimensions, build_dimensions = build_dimensions,
realparent = self) realparent = self,
antialias_samples = antialias_samples)
vbox.Add(self.glpanel, 1, flag = wx.EXPAND) vbox.Add(self.glpanel, 1, flag = wx.EXPAND)
self.Bind(wx.EVT_TOOL, lambda x: self.glpanel.zoom_to_center(1.2), id = 1) self.Bind(wx.EVT_TOOL, lambda x: self.glpanel.zoom_to_center(1.2), id = 1)
......
...@@ -35,7 +35,8 @@ class wxGLPanel(wx.Panel): ...@@ -35,7 +35,8 @@ class wxGLPanel(wx.Panel):
color_background = (0.98, 0.98, 0.78, 1) color_background = (0.98, 0.98, 0.78, 1)
def __init__(self, parent, id, pos = wx.DefaultPosition, def __init__(self, parent, id, pos = wx.DefaultPosition,
size = wx.DefaultSize, style = 0): size = wx.DefaultSize, style = 0,
antialias_samples = 0):
# Forcing a no full repaint to stop flickering # Forcing a no full repaint to stop flickering
style = style | wx.NO_FULL_REPAINT_ON_RESIZE style = style | wx.NO_FULL_REPAINT_ON_RESIZE
super(wxGLPanel, self).__init__(parent, id, pos, size, style) super(wxGLPanel, self).__init__(parent, id, pos, size, style)
...@@ -46,6 +47,10 @@ class wxGLPanel(wx.Panel): ...@@ -46,6 +47,10 @@ class wxGLPanel(wx.Panel):
glcanvas.WX_GL_DOUBLEBUFFER, # Double Buffered glcanvas.WX_GL_DOUBLEBUFFER, # Double Buffered
glcanvas.WX_GL_DEPTH_SIZE, 24) # 24 bit glcanvas.WX_GL_DEPTH_SIZE, 24) # 24 bit
if antialias_samples > 0:
attribList += (glcanvas.WX_GL_SAMPLE_BUFFERS, 1,
glcanvas.WX_GL_SAMPLES, antialias_samples)
self.width = None self.width = None
self.height = None self.height = None
......
...@@ -49,7 +49,7 @@ class VizPane(wx.BoxSizer): ...@@ -49,7 +49,7 @@ class VizPane(wx.BoxSizer):
if root.settings.mainviz == "3D": if root.settings.mainviz == "3D":
try: try:
import printrun.gcview import printrun.gcview
root.gviz = printrun.gcview.GcodeViewMainWrapper(parentpanel, root.build_dimensions_list, root = root, circular = root.settings.circular_bed) root.gviz = printrun.gcview.GcodeViewMainWrapper(parentpanel, root.build_dimensions_list, root = root, circular = root.settings.circular_bed, antialias_samples = int(root.settings.antialias3dsamples))
root.gviz.clickcb = root.show_viz_window root.gviz.clickcb = root.show_viz_window
except: except:
use2dview = True use2dview = True
...@@ -72,7 +72,7 @@ class VizPane(wx.BoxSizer): ...@@ -72,7 +72,7 @@ class VizPane(wx.BoxSizer):
objects = None objects = None
if isinstance(root.gviz, printrun.gcview.GcodeViewMainWrapper): if isinstance(root.gviz, printrun.gcview.GcodeViewMainWrapper):
objects = root.gviz.objects objects = root.gviz.objects
root.gwindow = printrun.gcview.GcodeViewFrame(None, wx.ID_ANY, 'Gcode view, shift to move view, mousewheel to set layer', size = (600, 600), build_dimensions = root.build_dimensions_list, objects = objects, root = root, circular = root.settings.circular_bed) root.gwindow = printrun.gcview.GcodeViewFrame(None, wx.ID_ANY, 'Gcode view, shift to move view, mousewheel to set layer', size = (600, 600), build_dimensions = root.build_dimensions_list, objects = objects, root = root, circular = root.settings.circular_bed, antialias_samples = int(root.settings.antialias3dsamples))
except: except:
use3dview = False use3dview = False
print "3D view mode requested, but we failed to initialize it." print "3D view mode requested, but we failed to initialize it."
......
...@@ -798,7 +798,8 @@ Printrun. If not, see <http://www.gnu.org/licenses/>.""" ...@@ -798,7 +798,8 @@ Printrun. If not, see <http://www.gnu.org/licenses/>."""
self.settings._add(BooleanSetting("slic3rupdate", False, _("Update Slic3r default presets"), _("When selecting a profile in Slic3r integration menu, also save it as the default Slic3r preset"), "UI")) self.settings._add(BooleanSetting("slic3rupdate", False, _("Update Slic3r default presets"), _("When selecting a profile in Slic3r integration menu, also save it as the default Slic3r preset"), "UI"))
self.settings._add(ComboSetting("mainviz", "2D", ["2D", "3D", "None"], _("Main visualization"), _("Select visualization for main window."), "UI"), self.reload_ui) self.settings._add(ComboSetting("mainviz", "2D", ["2D", "3D", "None"], _("Main visualization"), _("Select visualization for main window."), "UI"), self.reload_ui)
self.settings._add(BooleanSetting("viz3d", False, _("Use 3D in GCode viewer window"), _("Use 3D mode instead of 2D layered mode in the visualization window"), "UI"), self.reload_ui) self.settings._add(BooleanSetting("viz3d", False, _("Use 3D in GCode viewer window"), _("Use 3D mode instead of 2D layered mode in the visualization window"), "UI"), self.reload_ui)
self.settings._add(BooleanSetting("light3d", True, _("Use a lighter 3D visualization"), _("Use a lighter visualization with simple lines instead of extruded paths for 3D viewer"), "UI")) self.settings._add(BooleanSetting("light3d", True, _("Use a lighter 3D visualization"), _("Use a lighter visualization with simple lines instead of extruded paths for 3D viewer"), "UI"), self.reload_ui)
self.settings._add(ComboSetting("antialias3dsamples", "0", ["0", "2", "4", "8"], _("Number of anti-aliasing samples"), _("Amount of anti-aliasing samples used in the 3D viewer"), "UI"), self.reload_ui)
self.settings._add(BooleanSetting("trackcurrentlayer3d", False, _("Track current layer in main 3D view"), _("Track the currently printing layer in the main 3D visualization"), "UI")) self.settings._add(BooleanSetting("trackcurrentlayer3d", False, _("Track current layer in main 3D view"), _("Track the currently printing layer in the main 3D visualization"), "UI"))
self.settings._add(BooleanSetting("tempgraph", True, _("Display temperature graph"), _("Display time-lapse temperature graph"), "UI"), self.reload_ui) self.settings._add(BooleanSetting("tempgraph", True, _("Display temperature graph"), _("Display time-lapse temperature graph"), "UI"), self.reload_ui)
self.settings._add(BooleanSetting("tempgauges", False, _("Display temperature gauges"), _("Display graphical gauges for temperatures visualization"), "UI"), self.reload_ui) self.settings._add(BooleanSetting("tempgauges", False, _("Display temperature gauges"), _("Display graphical gauges for temperatures visualization"), "UI"), self.reload_ui)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment