mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-24 07:03:59 -06:00
Some cleanup for the plater code
This commit is contained in:
parent
def013ba91
commit
962a51cc80
3 changed files with 43 additions and 30 deletions
|
@ -119,6 +119,7 @@ sub arrange_objects {
|
|||
$object->add_instance(
|
||||
offset => $_,
|
||||
rotation => $instance->rotation,
|
||||
scaling_factor => $instance->scaling_factor,
|
||||
) for move_points($instance->offset, @positions);
|
||||
}
|
||||
}
|
||||
|
@ -213,6 +214,7 @@ sub mesh {
|
|||
my $mesh = $object->mesh->clone;
|
||||
if ($instance) {
|
||||
$mesh->rotate($instance->rotation);
|
||||
$mesh->scale($instance->scaling_factor);
|
||||
$mesh->align_to_origin;
|
||||
$mesh->move(@{$instance->offset});
|
||||
}
|
||||
|
@ -259,6 +261,7 @@ sub split_meshes {
|
|||
$new_object->add_instance(
|
||||
offset => [ $_->offset->[X] + $extents[X][MIN], $_->offset->[Y] + $extents[Y][MIN] ],
|
||||
rotation => $_->rotation,
|
||||
scaling_factor => $_->scaling_factor,
|
||||
) for @{ $object->instances // [] };
|
||||
}
|
||||
}
|
||||
|
@ -274,7 +277,7 @@ package Slic3r::Model::Object;
|
|||
use Moo;
|
||||
|
||||
use List::Util qw(first);
|
||||
use Slic3r::Geometry qw(X Y Z MIN move_points move_points_3D);
|
||||
use Slic3r::Geometry qw(X Y Z MIN MAX move_points move_points_3D);
|
||||
use Storable qw(dclone);
|
||||
|
||||
has 'input_file' => (is => 'rw');
|
||||
|
@ -338,13 +341,27 @@ sub extents {
|
|||
return Slic3r::Geometry::bounding_box_3D($self->used_vertices);
|
||||
}
|
||||
|
||||
sub center {
|
||||
my $self = shift;
|
||||
|
||||
my @extents = $self->extents;
|
||||
return [ map +($extents[$_][MAX] + $extents[$_][MIN])/2, X,Y,Z ];
|
||||
}
|
||||
|
||||
sub bounding_box {
|
||||
my $self = shift;
|
||||
return Slic3r::Geometry::BoundingBox->new(extents => [ $self->extents ]);
|
||||
}
|
||||
|
||||
sub align_to_origin {
|
||||
my $self = shift;
|
||||
|
||||
# calculate the displacements needed to
|
||||
# have lowest value for each axis at coordinate 0
|
||||
my @extents = $self->extents;
|
||||
$self->move(map -$extents[$_][MIN], X,Y,Z);
|
||||
my @shift = map -$extents[$_][MIN], X,Y,Z;
|
||||
$self->move(@shift);
|
||||
return @shift;
|
||||
}
|
||||
|
||||
sub move {
|
||||
|
@ -410,6 +427,7 @@ use Moo;
|
|||
|
||||
has 'object' => (is => 'ro', weak_ref => 1, required => 1);
|
||||
has 'rotation' => (is => 'rw', default => sub { 0 }); # around mesh center point
|
||||
has 'scaling_factor' => (is => 'rw', default => sub { 1 });
|
||||
has 'offset' => (is => 'rw'); # must be Slic3r::Point object
|
||||
|
||||
1;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue