Sync viewport of 3D views. #2628
This commit is contained in:
parent
09c8563e71
commit
d44bf38906
2 changed files with 23 additions and 0 deletions
|
@ -16,6 +16,7 @@ __PACKAGE__->mk_accessors( qw(_quat _dirty init
|
|||
enable_cutting
|
||||
enable_picking
|
||||
enable_moving
|
||||
on_viewport_changed
|
||||
on_hover
|
||||
on_select
|
||||
on_double_click
|
||||
|
@ -108,6 +109,7 @@ sub new {
|
|||
-($pos->y - $size->y/2) * ($zoom) / $self->_zoom,
|
||||
0,
|
||||
) if 0;
|
||||
$self->on_viewport_changed->() if $self->on_viewport_changed;
|
||||
$self->_dirty(1);
|
||||
$self->Refresh;
|
||||
});
|
||||
|
@ -207,6 +209,7 @@ sub mouse_event {
|
|||
);
|
||||
$self->_quat(mulquats($self->_quat, \@quat));
|
||||
}
|
||||
$self->on_viewport_changed->() if $self->on_viewport_changed;
|
||||
$self->Refresh;
|
||||
}
|
||||
$self->_drag_start_pos($pos);
|
||||
|
@ -220,6 +223,7 @@ sub mouse_event {
|
|||
$self->_camera_target->translate(
|
||||
@{$orig->vector_to($cur_pos)->negative},
|
||||
);
|
||||
$self->on_viewport_changed->() if $self->on_viewport_changed;
|
||||
$self->Refresh;
|
||||
}
|
||||
$self->_drag_start_xy($pos);
|
||||
|
@ -256,6 +260,17 @@ sub reset_objects {
|
|||
$self->_dirty(1);
|
||||
}
|
||||
|
||||
sub set_viewport_from_scene {
|
||||
my ($self, $scene) = @_;
|
||||
|
||||
$self->_sphi($scene->_sphi);
|
||||
$self->_stheta($scene->_stheta);
|
||||
$self->_camera_target($scene->_camera_target);
|
||||
$self->_zoom($scene->_zoom);
|
||||
$self->_quat($scene->_quat);
|
||||
$self->_dirty(1);
|
||||
}
|
||||
|
||||
sub zoom_to_bounding_box {
|
||||
my ($self, $bb) = @_;
|
||||
|
||||
|
@ -267,6 +282,8 @@ sub zoom_to_bounding_box {
|
|||
|
||||
# center view around bounding box center
|
||||
$self->_camera_target($bb->center);
|
||||
|
||||
$self->on_viewport_changed->() if $self->on_viewport_changed;
|
||||
}
|
||||
|
||||
sub zoom_to_bed {
|
||||
|
|
|
@ -96,6 +96,9 @@ sub new {
|
|||
$self->{canvas3D}->set_on_double_click($on_double_click);
|
||||
$self->{canvas3D}->set_on_right_click(sub { $on_right_click->($self->{canvas3D}, @_); });
|
||||
$self->{canvas3D}->set_on_instances_moved($on_instances_moved);
|
||||
$self->{canvas3D}->on_viewport_changed(sub {
|
||||
$self->{preview3D}->canvas->set_viewport_from_scene($self->{canvas3D});
|
||||
});
|
||||
}
|
||||
|
||||
# Initialize 2D preview canvas
|
||||
|
@ -109,6 +112,9 @@ sub new {
|
|||
# Initialize 3D toolpaths preview
|
||||
if ($Slic3r::GUI::have_OpenGL) {
|
||||
$self->{preview3D} = Slic3r::GUI::Plater::3DPreview->new($self->{preview_notebook}, $self->{print});
|
||||
$self->{preview3D}->canvas->on_viewport_changed(sub {
|
||||
$self->{canvas3D}->set_viewport_from_scene($self->{preview3D}->canvas);
|
||||
});
|
||||
$self->{preview_notebook}->AddPage($self->{preview3D}, 'Preview');
|
||||
$self->{preview3D_page_idx} = $self->{preview_notebook}->GetPageCount-1;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue