3DScene's enable_picking variable moved to c++

This commit is contained in:
Enrico Turri 2018-05-22 09:02:42 +02:00
parent 59af3fb866
commit 451c58d58f
10 changed files with 101 additions and 13 deletions

View File

@ -35,7 +35,6 @@ use Slic3r::Geometry qw(PI);
# _camera_type: 'perspective' or 'ortho'
#==============================================================================================================================
__PACKAGE__->mk_accessors( qw(_quat init
enable_picking
enable_moving
use_plain_shader
on_viewport_changed
@ -504,7 +503,10 @@ sub mouse_event {
# Select volume in this 3D canvas.
# Don't deselect a volume if layer editing is enabled. We want the object to stay selected
# during the scene manipulation.
if ($self->enable_picking && ($volume_idx != -1 || ! $self->layer_editing_enabled)) {
#==============================================================================================================================
if (Slic3r::GUI::_3DScene::is_picking_enabled($self) && ($volume_idx != -1 || ! $self->layer_editing_enabled)) {
# if ($self->enable_picking && ($volume_idx != -1 || ! $self->layer_editing_enabled)) {
#==============================================================================================================================
$self->deselect_volumes;
$self->select_volume($volume_idx);
@ -658,7 +660,10 @@ sub mouse_event {
$self->_mouse_pos($pos);
# Only refresh if picking is enabled, in that case the objects may get highlighted if the mouse cursor
# hovers over.
if ($self->enable_picking) {
#==============================================================================================================================
if (Slic3r::GUI::_3DScene::is_picking_enabled($self)) {
# if ($self->enable_picking) {
#==============================================================================================================================
$self->Update;
$self->Refresh;
}
@ -1461,7 +1466,10 @@ sub Render {
# Head light
glLightfv_p(GL_LIGHT1, GL_POSITION, 1, 0, 1, 0);
if ($self->enable_picking && !$self->_mouse_dragging) {
#==============================================================================================================================
if (Slic3r::GUI::_3DScene::is_picking_enabled($self) && !$self->_mouse_dragging) {
# if ($self->enable_picking && !$self->_mouse_dragging) {
#==============================================================================================================================
if (my $pos = $self->_mouse_pos) {
# Render the object for picking.
# FIXME This cannot possibly work in a multi-sampled context as the color gets mangled by the anti-aliasing.
@ -1606,7 +1614,10 @@ sub Render {
# $self->draw_volumes;
#==============================================================================================================================
} elsif ($self->UseVBOs) {
if ($self->enable_picking) {
#==============================================================================================================================
if (Slic3r::GUI::_3DScene::is_picking_enabled($self)) {
# if ($self->enable_picking) {
#==============================================================================================================================
$self->mark_volumes_for_layer_height;
$self->volumes->set_print_box($self->bed_bounding_box->x_min, $self->bed_bounding_box->y_min, 0.0, $self->bed_bounding_box->x_max, $self->bed_bounding_box->y_max, $self->{config}->get('max_print_height'));
$self->volumes->update_outside_state($self->{config}, 0);
@ -1616,12 +1627,21 @@ sub Render {
$self->{plain_shader}->enable if $self->{plain_shader};
$self->volumes->render_VBOs;
$self->{plain_shader}->disable;
glEnable(GL_CULL_FACE) if ($self->enable_picking);
#==============================================================================================================================
glEnable(GL_CULL_FACE) if (Slic3r::GUI::_3DScene::is_picking_enabled($self));
# glEnable(GL_CULL_FACE) if ($self->enable_picking);
#==============================================================================================================================
} else {
# do not cull backfaces to show broken geometry, if any
glDisable(GL_CULL_FACE) if ($self->enable_picking);
#==============================================================================================================================
glDisable(GL_CULL_FACE) if (Slic3r::GUI::_3DScene::is_picking_enabled($self));
# glDisable(GL_CULL_FACE) if ($self->enable_picking);
#==============================================================================================================================
$self->volumes->render_legacy;
glEnable(GL_CULL_FACE) if ($self->enable_picking);
#==============================================================================================================================
glEnable(GL_CULL_FACE) if (Slic3r::GUI::_3DScene::is_picking_enabled($self));
# glEnable(GL_CULL_FACE) if ($self->enable_picking);
#==============================================================================================================================
}
#==============================================================================================================================

View File

@ -19,7 +19,10 @@ sub new {
my ($parent, $objects, $model, $print, $config) = @_;
my $self = $class->SUPER::new($parent);
$self->enable_picking(1);
#==============================================================================================================================
Slic3r::GUI::_3DScene::enable_picking($self, 1);
# $self->enable_picking(1);
#==============================================================================================================================
$self->enable_moving(1);
$self->select_by('object');
$self->drag_by('instance');

View File

@ -153,7 +153,10 @@ sub new {
my $canvas;
if ($Slic3r::GUI::have_OpenGL) {
$canvas = $self->{canvas} = Slic3r::GUI::3DScene->new($self);
$canvas->enable_picking(1);
#==============================================================================================================================
Slic3r::GUI::_3DScene::enable_picking($canvas, 1);
# $canvas->enable_picking(1);
#==============================================================================================================================
$canvas->select_by('volume');
$canvas->on_select(sub {

View File

@ -1898,6 +1898,11 @@ bool _3DScene::is_layers_editing_enabled(wxGLCanvas* canvas)
return s_canvas_mgr.is_layers_editing_enabled(canvas);
}
bool _3DScene::is_picking_enabled(wxGLCanvas* canvas)
{
return s_canvas_mgr.is_picking_enabled(canvas);
}
void _3DScene::enable_warning_texture(wxGLCanvas* canvas, bool enable)
{
s_canvas_mgr.enable_warning_texture(canvas, enable);
@ -1908,6 +1913,11 @@ void _3DScene::enable_legend_texture(wxGLCanvas* canvas, bool enable)
s_canvas_mgr.enable_legend_texture(canvas, enable);
}
void _3DScene::enable_picking(wxGLCanvas* canvas, bool enable)
{
s_canvas_mgr.enable_picking(canvas, enable);
}
void _3DScene::zoom_to_bed(wxGLCanvas* canvas)
{
s_canvas_mgr.zoom_to_bed(canvas);

View File

@ -589,9 +589,11 @@ public:
static void set_camera_target(wxGLCanvas* canvas, const Pointf3* target);
static bool is_layers_editing_enabled(wxGLCanvas* canvas);
static bool is_picking_enabled(wxGLCanvas* canvas);
static void enable_warning_texture(wxGLCanvas* canvas, bool enable);
static void enable_legend_texture(wxGLCanvas* canvas, bool enable);
static void enable_picking(wxGLCanvas* canvas, bool enable);
static void zoom_to_bed(wxGLCanvas* canvas);
static void zoom_to_volumes(wxGLCanvas* canvas);

View File

@ -421,6 +421,7 @@ GLCanvas3D::GLCanvas3D(wxGLCanvas* canvas, wxGLContext* context)
, m_apply_zoom_to_volumes_filter(false)
, m_warning_texture_enabled(false)
, m_legend_texture_enabled(false)
, m_picking_enabled(false)
{
}
@ -692,6 +693,11 @@ bool GLCanvas3D::is_layers_editing_enabled() const
return m_layers_editing.is_enabled();
}
bool GLCanvas3D::is_picking_enabled() const
{
return m_picking_enabled;
}
void GLCanvas3D::enable_warning_texture(bool enable)
{
m_warning_texture_enabled = enable;
@ -702,6 +708,11 @@ void GLCanvas3D::enable_legend_texture(bool enable)
m_legend_texture_enabled = enable;
}
void GLCanvas3D::enable_picking(bool enable)
{
m_picking_enabled = enable;
}
void GLCanvas3D::zoom_to_bed()
{
_zoom_to_bounding_box(bed_bounding_box());
@ -793,7 +804,10 @@ void GLCanvas3D::render_volumes(bool fake_colors) const
if (m_volumes == nullptr)
return;
::glEnable(GL_LIGHTING);
if (fake_colors)
::glDisable(GL_LIGHTING);
else
::glEnable(GL_LIGHTING);
// do not cull backfaces to show broken geometry, if any
::glDisable(GL_CULL_FACE);
@ -805,7 +819,7 @@ void GLCanvas3D::render_volumes(bool fake_colors) const
::glEnableClientState(GL_NORMAL_ARRAY);
unsigned int volume_id = 0;
for (const GLVolume* vol : m_volumes->volumes)
for (GLVolume* vol : m_volumes->volumes)
{
if (fake_colors)
{
@ -816,7 +830,10 @@ void GLCanvas3D::render_volumes(bool fake_colors) const
::glColor4f((float)r * INV_255, (float)g * INV_255, (float)b * INV_255, 1.0f);
}
else
{
vol->set_render_color();
::glColor4f(vol->render_color[0], vol->render_color[1], vol->render_color[2], vol->render_color[3]);
}
vol->render();
++volume_id;

View File

@ -156,6 +156,7 @@ private:
bool m_apply_zoom_to_volumes_filter;
bool m_warning_texture_enabled;
bool m_legend_texture_enabled;
bool m_picking_enabled;
PerlCallback m_on_viewport_changed_callback;
@ -217,9 +218,11 @@ public:
BoundingBoxf3 max_bounding_box() const;
bool is_layers_editing_enabled() const;
bool is_picking_enabled() const;
void enable_warning_texture(bool enable);
void enable_legend_texture(bool enable);
void enable_picking(bool enable);
void zoom_to_bed();
void zoom_to_volumes();

View File

@ -355,6 +355,12 @@ bool GLCanvas3DManager::is_layers_editing_enabled(wxGLCanvas* canvas) const
return (it != m_canvases.end()) ? it->second->is_layers_editing_enabled() : false;
}
bool GLCanvas3DManager::is_picking_enabled(wxGLCanvas* canvas) const
{
CanvasesMap::const_iterator it = _get_canvas(canvas);
return (it != m_canvases.end()) ? it->second->is_picking_enabled() : false;
}
void GLCanvas3DManager::enable_warning_texture(wxGLCanvas* canvas, bool enable)
{
CanvasesMap::iterator it = _get_canvas(canvas);
@ -369,6 +375,13 @@ void GLCanvas3DManager::enable_legend_texture(wxGLCanvas* canvas, bool enable)
it->second->enable_legend_texture(enable);
}
void GLCanvas3DManager::enable_picking(wxGLCanvas* canvas, bool enable)
{
CanvasesMap::iterator it = _get_canvas(canvas);
if (it != m_canvases.end())
it->second->enable_picking(enable);
}
void GLCanvas3DManager::zoom_to_bed(wxGLCanvas* canvas)
{
CanvasesMap::iterator it = _get_canvas(canvas);

View File

@ -99,9 +99,11 @@ public:
void set_camera_target(wxGLCanvas* canvas, const Pointf3* target);
bool is_layers_editing_enabled(wxGLCanvas* canvas) const;
bool is_picking_enabled(wxGLCanvas* canvas) const;
void enable_warning_texture(wxGLCanvas* canvas, bool enable);
void enable_legend_texture(wxGLCanvas* canvas, bool enable);
void enable_picking(wxGLCanvas* canvas, bool enable);
void zoom_to_bed(wxGLCanvas* canvas);
void zoom_to_volumes(wxGLCanvas* canvas);

View File

@ -411,6 +411,14 @@ set_camera_target(canvas, target)
CODE:
_3DScene::set_camera_target((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"), target);
bool
is_picking_enabled(canvas)
SV *canvas;
CODE:
RETVAL = _3DScene::is_picking_enabled((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"));
OUTPUT:
RETVAL
void
enable_warning_texture(canvas, enable)
SV *canvas;
@ -425,6 +433,13 @@ enable_legend_texture(canvas, enable)
CODE:
_3DScene::enable_legend_texture((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"), enable);
void
enable_picking(canvas, enable)
SV *canvas;
bool enable;
CODE:
_3DScene::enable_picking((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"), enable);
void
zoom_to_bed(canvas)
SV *canvas;