3DScene.pm 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. # Implements pure perl packages
  2. #
  3. # Slic3r::GUI::3DScene::Base;
  4. # Slic3r::GUI::3DScene;
  5. #
  6. # Slic3r::GUI::Plater::3D derives from Slic3r::GUI::3DScene,
  7. # Slic3r::GUI::Plater::3DPreview,
  8. # Slic3r::GUI::Plater::ObjectCutDialog and Slic3r::GUI::Plater::ObjectPartsPanel
  9. # own $self->{canvas} of the Slic3r::GUI::3DScene type.
  10. #
  11. # Therefore the 3DScene supports renderng of STLs, extrusions and cutting planes,
  12. # and camera manipulation.
  13. package Slic3r::GUI::3DScene::Base;
  14. use strict;
  15. use warnings;
  16. use Wx qw(wxTheApp :timer :bitmap :icon :dialog);
  17. # must load OpenGL *before* Wx::GLCanvas
  18. use OpenGL qw(:glconstants :glfunctions :glufunctions :gluconstants);
  19. use base qw(Wx::GLCanvas Class::Accessor);
  20. use Wx::GLCanvas qw(:all);
  21. sub new {
  22. my ($class, $parent) = @_;
  23. # We can only enable multi sample anti aliasing wih wxWidgets 3.0.3 and with a hacked Wx::GLCanvas,
  24. # which exports some new WX_GL_XXX constants, namely WX_GL_SAMPLE_BUFFERS and WX_GL_SAMPLES.
  25. my $can_multisample =
  26. ! wxTheApp->{app_config}->get('use_legacy_opengl') &&
  27. Wx::wxVERSION >= 3.000003 &&
  28. defined Wx::GLCanvas->can('WX_GL_SAMPLE_BUFFERS') &&
  29. defined Wx::GLCanvas->can('WX_GL_SAMPLES');
  30. my $attrib = [WX_GL_RGBA, WX_GL_DOUBLEBUFFER, WX_GL_DEPTH_SIZE, 24];
  31. if ($can_multisample) {
  32. # Request a window with multi sampled anti aliasing. This is a new feature in Wx 3.0.3 (backported from 3.1.0).
  33. # Use eval to avoid compilation, if the subs WX_GL_SAMPLE_BUFFERS and WX_GL_SAMPLES are missing.
  34. eval 'push(@$attrib, (WX_GL_SAMPLE_BUFFERS, 1, WX_GL_SAMPLES, 4));';
  35. }
  36. # wxWidgets expect the attrib list to be ended by zero.
  37. push(@$attrib, 0);
  38. # we request a depth buffer explicitely because it looks like it's not created by
  39. # default on Linux, causing transparency issues
  40. my $self = $class->SUPER::new($parent, -1, Wx::wxDefaultPosition, Wx::wxDefaultSize, 0, "", $attrib);
  41. Slic3r::GUI::_3DScene::add_canvas($self);
  42. Slic3r::GUI::_3DScene::allow_multisample($self, $can_multisample);
  43. return $self;
  44. }
  45. sub Destroy {
  46. my ($self) = @_;
  47. Slic3r::GUI::_3DScene::remove_canvas($self);
  48. return $self->SUPER::Destroy;
  49. }
  50. # The 3D canvas to display objects and tool paths.
  51. package Slic3r::GUI::3DScene;
  52. use base qw(Slic3r::GUI::3DScene::Base);
  53. sub new {
  54. my $class = shift;
  55. my $self = $class->SUPER::new(@_);
  56. return $self;
  57. }
  58. 1;