diff --git a/lib/Slic3r/GUI/3DScene.pm b/lib/Slic3r/GUI/3DScene.pm index 319a15535..83cf5b45d 100644 --- a/lib/Slic3r/GUI/3DScene.pm +++ b/lib/Slic3r/GUI/3DScene.pm @@ -188,6 +188,7 @@ sub new { $self->volumes(Slic3r::GUI::_3DScene::GLVolume::Collection->new); #============================================================================================================================== Slic3r::GUI::_3DScene::set_volumes($self, $self->volumes); + Slic3r::GUI::_3DScene::reset_volumes($self); #============================================================================================================================== # 3D point in model space @@ -202,10 +203,7 @@ sub new { # $self->{layer_height_edit_last_object_id} = -1; # $self->{layer_height_edit_last_z} = 0.; # $self->{layer_height_edit_last_action} = 0; -#============================================================================================================================== - -#============================================================================================================================== - Slic3r::GUI::_3DScene::reset_volumes($self); +# # $self->reset_objects; #============================================================================================================================== @@ -215,8 +213,6 @@ sub new { }); #======================================================================================================================= # EVT_SIZE($self, sub { $self->_dirty(1) }); -#======================================================================================================================= -#============================================================================================================================== # EVT_IDLE($self, sub { # return unless $self->_dirty; # return if !$self->IsShownOnScreen; @@ -362,45 +358,33 @@ sub Destroy { # } # return -1; #} -#============================================================================================================================== - -# Returns an array with (left, top, right, bottom) of the variable layer thickness bar on the screen. -sub _variable_layer_thickness_bar_rect_screen { - my ($self) = @_; - my ($cw, $ch) = $self->GetSizeWH; - return ($cw - VARIABLE_LAYER_THICKNESS_BAR_WIDTH, 0, $cw, $ch - VARIABLE_LAYER_THICKNESS_RESET_BUTTON_HEIGHT); -} - -sub _variable_layer_thickness_bar_rect_viewport { - my ($self) = @_; - my ($cw, $ch) = $self->GetSizeWH; -#============================================================================================================================== - my $zoom = Slic3r::GUI::_3DScene::get_camera_zoom($self); - return ((0.5*$cw-VARIABLE_LAYER_THICKNESS_BAR_WIDTH)/$zoom, (-0.5*$ch+VARIABLE_LAYER_THICKNESS_RESET_BUTTON_HEIGHT)/$zoom, $cw/(2*$zoom), $ch/(2*$zoom)); +# +## Returns an array with (left, top, right, bottom) of the variable layer thickness bar on the screen. +#sub _variable_layer_thickness_bar_rect_screen { +# my ($self) = @_; +# my ($cw, $ch) = $self->GetSizeWH; +# return ($cw - VARIABLE_LAYER_THICKNESS_BAR_WIDTH, 0, $cw, $ch - VARIABLE_LAYER_THICKNESS_RESET_BUTTON_HEIGHT); +#} +# +#sub _variable_layer_thickness_bar_rect_viewport { +# my ($self) = @_; +# my ($cw, $ch) = $self->GetSizeWH; # return ((0.5*$cw-VARIABLE_LAYER_THICKNESS_BAR_WIDTH)/$self->_zoom, (-0.5*$ch+VARIABLE_LAYER_THICKNESS_RESET_BUTTON_HEIGHT)/$self->_zoom, $cw/(2*$self->_zoom), $ch/(2*$self->_zoom)); -#============================================================================================================================== -} - -#============================================================================================================================== +#} +# ## Returns an array with (left, top, right, bottom) of the variable layer thickness bar on the screen. #sub _variable_layer_thickness_reset_rect_screen { # my ($self) = @_; # my ($cw, $ch) = $self->GetSizeWH; # return ($cw - VARIABLE_LAYER_THICKNESS_BAR_WIDTH, $ch - VARIABLE_LAYER_THICKNESS_RESET_BUTTON_HEIGHT, $cw, $ch); #} -#============================================================================================================================== - -sub _variable_layer_thickness_reset_rect_viewport { - my ($self) = @_; - my ($cw, $ch) = $self->GetSizeWH; -#============================================================================================================================== - my $zoom = Slic3r::GUI::_3DScene::get_camera_zoom($self); - return ((0.5*$cw-VARIABLE_LAYER_THICKNESS_BAR_WIDTH)/$zoom, -$ch/(2*$zoom), $cw/(2*$zoom), (-0.5*$ch+VARIABLE_LAYER_THICKNESS_RESET_BUTTON_HEIGHT)/$zoom); +# +#sub _variable_layer_thickness_reset_rect_viewport { +# my ($self) = @_; +# my ($cw, $ch) = $self->GetSizeWH; # return ((0.5*$cw-VARIABLE_LAYER_THICKNESS_BAR_WIDTH)/$self->_zoom, -$ch/(2*$self->_zoom), $cw/(2*$self->_zoom), (-0.5*$ch+VARIABLE_LAYER_THICKNESS_RESET_BUTTON_HEIGHT)/$self->_zoom); -#============================================================================================================================== -} - -#============================================================================================================================== +#} +# #sub _variable_layer_thickness_bar_rect_mouse_inside { # my ($self, $mouse_evt) = @_; # my ($bar_left, $bar_top, $bar_right, $bar_bottom) = $self->_variable_layer_thickness_bar_rect_screen; @@ -1400,42 +1384,33 @@ sub Render { return unless my $context = $self->GetContext; $self->SetCurrent($context); $self->InitGL; - - glClearColor(1, 1, 1, 1); - glClearDepth(1); - glDepthFunc(GL_LESS); -#============================================================================================================================== -# glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); -#============================================================================================================================== - - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - - if (!TURNTABLE_MODE) { - # Shift the perspective camera. -#============================================================================================================================== - my $camera_pos = Slic3r::Pointf3->new(0,0,-Slic3r::GUI::_3DScene::get_camera_distance($self)); -# my $camera_pos = Slic3r::Pointf3->new(0,0,-$self->_camera_distance); -#============================================================================================================================== - glTranslatef(@$camera_pos); - } - - if (TURNTABLE_MODE) { - # Turntable mode is enabled by default. -#============================================================================================================================== - glRotatef(-Slic3r::GUI::_3DScene::get_camera_theta($self), 1, 0, 0); # pitch - glRotatef(Slic3r::GUI::_3DScene::get_camera_phi($self), 0, 0, 1); # yaw -# glRotatef(-$self->_stheta, 1, 0, 0); # pitch -# glRotatef($self->_sphi, 0, 0, 1); # yaw -#============================================================================================================================== - } else { - my @rotmat = quat_to_rotmatrix($self->quat); - glMultMatrixd_p(@rotmat[0..15]); - } - + #============================================================================================================================== Slic3r::GUI::_3DScene::render($self); +# glClearColor(1, 1, 1, 1); +# glClearDepth(1); +# glDepthFunc(GL_LESS); +# glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); +# +# glMatrixMode(GL_MODELVIEW); +# glLoadIdentity(); +# +# if (!TURNTABLE_MODE) { +# # Shift the perspective camera. +# my $camera_pos = Slic3r::Pointf3->new(0,0,-$self->_camera_distance); +# glTranslatef(@$camera_pos); +# } +# +# if (TURNTABLE_MODE) { +# # Turntable mode is enabled by default. +# glRotatef(-$self->_stheta, 1, 0, 0); # pitch +# glRotatef($self->_sphi, 0, 0, 1); # yaw +# } else { +# my @rotmat = quat_to_rotmatrix($self->quat); +# glMultMatrixd_p(@rotmat[0..15]); +# } +# # glTranslatef(@{ $self->_camera_target->negative }); # # # light from above diff --git a/xs/src/slic3r/GUI/GLCanvas3D.cpp b/xs/src/slic3r/GUI/GLCanvas3D.cpp index c9b31a94c..4e2355c89 100644 --- a/xs/src/slic3r/GUI/GLCanvas3D.cpp +++ b/xs/src/slic3r/GUI/GLCanvas3D.cpp @@ -15,7 +15,6 @@ #include #include -static const bool TURNTABLE_MODE = true; static const float GIMBALL_LOCK_THETA_MAX = 180.0f; static const float GROUND_Z = -0.02f; @@ -1082,10 +1081,12 @@ GLCanvas3D::~GLCanvas3D() bool GLCanvas3D::init(bool useVBOs, bool use_legacy_opengl) { - ::glClearColor(0.0f, 0.0f, 0.0f, 1.0f); - ::glEnable(GL_DEPTH_TEST); + ::glClearColor(1.0f, 1.0f, 1.0f, 1.0f); + ::glClearDepth(1.0f); - ::glDepthFunc(GL_LEQUAL); + ::glDepthFunc(GL_LESS); + + ::glEnable(GL_DEPTH_TEST); ::glEnable(GL_CULL_FACE); ::glEnable(GL_BLEND); ::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); @@ -1109,6 +1110,14 @@ bool GLCanvas3D::init(bool useVBOs, bool use_legacy_opengl) GLfloat diffuse[4] = { 0.2f, 0.2f, 0.2f, 1.0f }; ::glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse); + // light from above + GLfloat position1[4] = { -0.5f, -0.5f, 1.0f, 0.0f }; + ::glLightfv(GL_LIGHT0, GL_POSITION, position1); + GLfloat specular1[4] = { 0.2f, 0.2f, 0.2f, 1.0f }; + ::glLightfv(GL_LIGHT0, GL_SPECULAR, specular1); + GLfloat diffuse1[4] = { 0.5f, 0.5f, 0.5f, 1.0f }; + ::glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse1); + // Enables Smooth Color Shading; try GL_FLAT for (lack of) fun. ::glShadeModel(GL_SMOOTH); @@ -1574,21 +1583,7 @@ void GLCanvas3D::render(bool useVBOs) const if (m_canvas == nullptr) return; - Pointf3 neg_target = get_camera_target().negative(); - ::glTranslatef((GLfloat)neg_target.x, (GLfloat)neg_target.y, (GLfloat)neg_target.z); - - // light from above - GLfloat position0[4] = { -0.5f, -0.5f, 1.0f, 0.0f }; - ::glLightfv(GL_LIGHT0, GL_POSITION, position0); - GLfloat specular[4] = { 0.2f, 0.2f, 0.2f, 1.0f }; - ::glLightfv(GL_LIGHT0, GL_SPECULAR, specular); - GLfloat diffuse[4] = { 0.5f, 0.5f, 0.5f, 1.0f }; - ::glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse); - - // Head light - GLfloat position1[4] = { 1.0f, 0.0f, 1.0f, 0.0f }; - ::glLightfv(GL_LIGHT1, GL_POSITION, position1); - + _camera_tranform(); _picking_pass(); _render_background(); _render_bed(); @@ -1941,27 +1936,8 @@ float GLCanvas3D::_get_zoom_to_bounding_box_factor(const BoundingBoxf3& bbox) co // project the bbox vertices on a plane perpendicular to the camera forward axis // then calculates the vertices coordinate on this plane along the camera xy axes - // we need the view matrix, we let opengl calculate it(same as done in render sub) - ::glMatrixMode(GL_MODELVIEW); - ::glLoadIdentity(); - - if (TURNTABLE_MODE) - { - // Turntable mode is enabled by default. - ::glRotatef(-get_camera_theta(), 1.0f, 0.0f, 0.0f); // pitch - ::glRotatef(get_camera_phi(), 0.0f, 0.0f, 1.0f); // yaw - } - else - { - // Shift the perspective camera. - Pointf3 camera_pos(0.0, 0.0, -(coordf_t)get_camera_distance()); - ::glTranslatef((float)camera_pos.x, (float)camera_pos.y, (float)camera_pos.z); -// my @rotmat = quat_to_rotmatrix($self->quat); <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< TEMPORARY COMMENTED OUT -// glMultMatrixd_p(@rotmat[0..15]); <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< TEMPORARY COMMENTED OUT - } - - const Pointf3& target = get_camera_target(); - ::glTranslatef(-(float)target.x, -(float)target.y, -(float)target.z); + // we need the view matrix, we let opengl calculate it (same as done in render()) + _camera_tranform(); // get the view matrix back from opengl GLfloat matrix[16]; @@ -2055,6 +2031,18 @@ void GLCanvas3D::_refresh_if_shown_on_screen() } } +void GLCanvas3D::_camera_tranform() const +{ + ::glMatrixMode(GL_MODELVIEW); + ::glLoadIdentity(); + + ::glRotatef(-get_camera_theta(), 1.0f, 0.0f, 0.0f); // pitch + ::glRotatef(get_camera_phi(), 0.0f, 0.0f, 1.0f); // yaw + + Pointf3 neg_target = get_camera_target().negative(); + ::glTranslatef((GLfloat)neg_target.x, (GLfloat)neg_target.y, (GLfloat)neg_target.z); +} + void GLCanvas3D::_picking_pass() const { if (is_picking_enabled() && !is_mouse_dragging() && (m_volumes != nullptr)) diff --git a/xs/src/slic3r/GUI/GLCanvas3D.hpp b/xs/src/slic3r/GUI/GLCanvas3D.hpp index bbb5880f1..22f561cbd 100644 --- a/xs/src/slic3r/GUI/GLCanvas3D.hpp +++ b/xs/src/slic3r/GUI/GLCanvas3D.hpp @@ -482,6 +482,7 @@ private: void _mark_volumes_for_layer_height() const; void _refresh_if_shown_on_screen(); + void _camera_tranform() const; void _picking_pass() const; void _render_background() const; void _render_bed() const;