3D object positioning

This commit is contained in:
Alessandro Ranellucci 2014-12-16 01:12:37 +01:00
parent a82f95e903
commit fcfb3b98bc
16 changed files with 217 additions and 91 deletions

View file

@ -16,11 +16,13 @@ sub new {
my $self = $class->SUPER::new($parent);
$self->enable_picking(1);
$self->enable_moving(1);
$self->{objects} = $objects;
$self->{model} = $model;
$self->{config} = $config;
$self->{on_select_object} = sub {};
$self->{on_instance_moved} = sub {};
$self->on_select(sub {
my ($volume_idx) = @_;
@ -40,6 +42,21 @@ sub new {
my $obj_idx = $self->{_volumes_inv}{$volume_idx};
$self->volumes->[$_]->hover(1) for @{$self->{_volumes}{$obj_idx}};
});
$self->on_move(sub {
my ($volume_idx) = @_;
my $volume = $self->volumes->[$volume_idx];
my $obj_idx = $self->{_volumes_inv}{$volume_idx};
my $model_object = $self->{model}->get_object($obj_idx);
$model_object
->instances->[$volume->instance_idx]
->offset
->translate($volume->origin->x, $volume->origin->y); #))
$model_object->invalidate_bounding_box;
$self->{on_instance_moved}->($obj_idx, $volume->instance_idx)
if $self->{on_instance_moved};
});
return $self;
}
@ -61,12 +78,7 @@ sub set_on_right_click {
sub set_on_instance_moved {
my ($self, $cb) = @_;
$self->on_instance_moved(sub {
my ($volume_idx, $instance_idx) = @_;
my $obj_idx = $self->{_volumes_inv}{$volume_idx};
return $cb->($obj_idx, $instance_idx);
});
$self->{on_instance_moved} = $cb;
}
sub update {
@ -75,10 +87,8 @@ sub update {
$self->{_volumes} = {}; # obj_idx => [ volume_idx, volume_idx ]
$self->{_volumes_inv} = {}; # volume_idx => obj_idx
$self->reset_objects;
return if $self->{model}->objects_count == 0;
$self->set_bounding_box($self->{model}->bounding_box);
$self->set_bed_shape($self->{config}->bed_shape);
$self->update_bed_size;
foreach my $obj_idx (0..$#{$self->{model}->objects}) {
my $model_object = $self->{model}->get_object($obj_idx);
@ -94,4 +104,9 @@ sub update {
}
}
sub update_bed_size {
my ($self) = @_;
$self->set_bed_shape($self->{config}->bed_shape);
}
1;