2012-11-21 19:41:14 +00:00
|
|
|
package Slic3r::Test;
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
2012-12-21 12:25:03 +00:00
|
|
|
require Exporter;
|
|
|
|
our @ISA = qw(Exporter);
|
|
|
|
our @EXPORT_OK = qw(_eq);
|
|
|
|
|
2012-11-21 19:41:14 +00:00
|
|
|
use IO::Scalar;
|
2012-12-30 15:27:20 +00:00
|
|
|
use List::Util qw(first);
|
|
|
|
use Slic3r::Geometry qw(epsilon X Y Z);
|
2012-11-21 19:41:14 +00:00
|
|
|
|
2012-12-09 17:33:25 +00:00
|
|
|
my %cuboids = (
|
|
|
|
'20mm_cube' => [20,20,20],
|
|
|
|
'2x20x10' => [2, 20,10],
|
|
|
|
);
|
|
|
|
|
2013-02-23 16:40:38 +00:00
|
|
|
sub model {
|
2013-06-15 10:10:57 +00:00
|
|
|
my ($model_name, %params) = @_;
|
2012-11-21 19:41:14 +00:00
|
|
|
|
2013-02-23 16:40:38 +00:00
|
|
|
my ($vertices, $facets);
|
|
|
|
if ($cuboids{$model_name}) {
|
|
|
|
my ($x, $y, $z) = @{ $cuboids{$model_name} };
|
|
|
|
$vertices = [
|
|
|
|
[$x,$y,0], [$x,0,0], [0,0,0], [0,$y,0], [$x,$y,$z], [0,$y,$z], [0,0,$z], [$x,0,$z],
|
|
|
|
];
|
|
|
|
$facets = [
|
|
|
|
[0,1,2], [0,2,3], [4,5,6], [4,6,7], [0,4,7], [0,7,1], [1,7,6], [1,6,2], [2,6,5], [2,5,3], [4,0,3], [4,3,5],
|
|
|
|
],
|
2013-06-22 22:05:08 +00:00
|
|
|
} elsif ($model_name eq 'cube_with_hole') {
|
|
|
|
$vertices = [
|
|
|
|
[0,0,0],[0,0,10],[0,20,0],[0,20,10],[20,0,0],[20,0,10],[5,5,0],[15,5,0],[5,15,0],[20,20,0],[15,15,0],[20,20,10],[5,5,10],[5,15,10],[15,5,10],[15,15,10]
|
|
|
|
];
|
|
|
|
$facets = [
|
|
|
|
[0,1,2],[2,1,3],[1,0,4],[5,1,4],[6,7,4],[8,2,9],[0,2,8],[10,8,9],[0,8,6],[0,6,4],[4,7,9],[7,10,9],[2,3,9],[9,3,11],[12,1,5],[13,3,12],[14,12,5],[3,1,12],[11,3,13],[11,15,5],[11,13,15],[15,14,5],[5,4,9],[11,5,9],[8,13,12],[6,8,12],[10,15,13],[8,10,13],[15,10,14],[14,10,7],[14,7,12],[12,7,6]
|
|
|
|
],
|
2013-06-08 18:01:26 +00:00
|
|
|
} elsif ($model_name eq 'V') {
|
|
|
|
$vertices = [
|
|
|
|
[-14,0,20],[-14,15,20],[0,0,0],[0,15,0],[-4,0,20],[-4,15,20],[5,0,7.14286],[10,0,0],[24,0,20],[14,0,20],[10,15,0],[5,15,7.14286],[14,15,20],[24,15,20]
|
|
|
|
];
|
|
|
|
$facets = [
|
|
|
|
[0,1,2],[2,1,3],[1,0,4],[5,1,4],[4,0,2],[6,4,2],[7,6,2],[8,9,7],[9,6,7],[2,3,7],[7,3,10],[1,5,3],[3,5,11],[11,12,13],[11,13,3],[3,13,10],[5,4,6],[11,5,6],[6,9,11],[11,9,12],[12,9,8],[13,12,8],[8,7,10],[13,8,10]
|
|
|
|
],
|
2013-06-22 13:22:58 +00:00
|
|
|
} elsif ($model_name eq 'L') {
|
|
|
|
$vertices = [
|
|
|
|
[0,10,0],[0,10,10],[0,20,0],[0,20,10],[10,10,0],[10,10,10],[20,20,0],[20,0,0],[10,0,0],[20,20,10],[10,0,10],[20,0,10]
|
|
|
|
];
|
|
|
|
$facets = [
|
|
|
|
[0,1,2],[2,1,3],[4,5,1],[0,4,1],[0,2,4],[4,2,6],[4,6,7],[4,7,8],[2,3,6],[6,3,9],[3,1,5],[9,3,5],[10,11,5],[11,9,5],[5,4,10],[10,4,8],[10,8,7],[11,10,7],[11,7,6],[9,11,6]
|
|
|
|
],
|
2013-06-21 12:52:35 +00:00
|
|
|
} elsif ($model_name eq 'overhang') {
|
|
|
|
$vertices = [
|
|
|
|
[1364.68505859375,614.398010253906,20.002498626709],[1389.68505859375,614.398010253906,20.002498626709],[1377.18505859375,589.398986816406,20.002498626709],[1389.68505859375,589.398986816406,20.002498626709],[1389.68505859375,564.398986816406,20.0014991760254],[1364.68505859375,589.398986816406,20.002498626709],[1364.68505859375,564.398986816406,20.0014991760254],[1360.93505859375,589.398986816406,17.0014991760254],[1360.93505859375,585.64697265625,17.0014991760254],[1357.18505859375,564.398986816406,17.0014991760254],[1364.68505859375,589.398986816406,17.0014991760254],[1364.68505859375,571.899963378906,17.0014991760254],[1364.68505859375,564.398986816406,17.0014991760254],[1348.43603515625,564.398986816406,17.0014991760254],[1352.80908203125,589.398986816406,17.0014991760254],[1357.18408203125,589.398986816406,17.0014991760254],[1357.18310546875,614.398010253906,17.0014991760254],[1364.68505859375,606.89599609375,17.0014991760254],[1364.68505859375,614.398010253906,17.0014991760254],[1352.18603515625,564.398986816406,20.0014991760254],[1363.65405273438,589.398986816406,23.3004989624023],[1359.46704101562,589.398986816406,23.3004989624023],[1358.37109375,564.398986816406,23.3004989624023],[1385.56103515625,564.398986816406,23.3004989624023],[1373.06311035156,589.398986816406,23.3004989624023],[1368.80810546875,564.398986816406,23.3004989624023],[1387.623046875,589.398986816406,23.3004989624023],[1387.623046875,585.276000976562,23.3004989624023],[1389.68505859375,589.398986816406,23.3004989624023],[1389.68505859375,572.64599609375,23.3004989624023],[1389.68505859375,564.398986816406,23.3004989624023],[1367.77709960938,589.398986816406,23.3004989624023],[1366.7470703125,564.398986816406,23.3004989624023],[1354.31201171875,589.398986816406,23.3004989624023],[1352.18603515625,564.398986816406,23.3004989624023],[1389.68505859375,614.398010253906,23.3004989624023],[1377.31701660156,614.398010253906,23.3004989624023],[1381.43908691406,589.398986816406,23.3004989624023],[1368.80700683594,614.398010253906,23.3004989624023],[1368.80810546875,589.398986816406,23.3004989624023],[1356.43908691406,614.398010253906,23.3004989624023],[1357.40502929688,589.398986816406,23.3004989624023],[1360.56201171875,614.398010253906,23.3004989624023],[1348.705078125,614.398010253906,23.3004989624023],[1350.44506835938,589.398986816406,23.3004989624023],[1389.68505859375,606.153015136719,23.3004989624023],[1347.35205078125,589.398986816406,23.3004989624023],[1346.56005859375,589.398986816406,23.3004989624023],[1346.56005859375,594.159912109375,17.0014991760254],[1346.56005859375,589.398986816406,17.0014991760254],[1346.56005859375,605.250427246094,23.3004989624023],[1346.56005859375,614.398010253906,23.3004989624023],[1346.56005859375,614.398010253906,20.8258285522461],[1346.56005859375,614.398010253906,17.0014991760254],[1346.56005859375,564.398986816406,19.10133934021],[1346.56005859375,567.548583984375,23.3004989624023],[1346.56005859375,564.398986816406,17.0020332336426],[1346.56005859375,564.398986816406,23.0018501281738],[1346.56005859375,564.398986816406,23.3004989624023],[1346.56005859375,575.118957519531,17.0014991760254],[1346.56005859375,574.754028320312,23.3004989624023]
|
|
|
|
];
|
|
|
|
$facets = [
|
|
|
|
[0,1,2],[2,3,4],[2,5,0],[4,6,2],[2,6,5],[2,1,3],[7,8,9],[10,9,8],[11,9,10],[12,9,11],[9,13,14],[7,15,16],[10,17,0],[10,0,5],[12,11,6],[18,16,0],[6,19,13],[6,13,9],[9,12,6],[17,18,0],[11,10,5],[11,5,6],[14,16,15],[17,7,18],[16,18,7],[14,15,9],[7,9,15],[7,17,8],[10,8,17],[20,21,22],[23,24,25],[26,23,27],[28,27,23],[29,28,23],[30,29,23],[25,31,32],[22,33,34],[35,36,37],[24,38,39],[21,40,41],[38,42,20],[33,43,44],[6,4,23],[6,23,25],[36,35,1],[1,0,38],[1,38,36],[29,30,4],[25,32,6],[40,42,0],[35,45,1],[4,3,28],[4,28,29],[3,1,45],[3,45,28],[22,34,19],[19,6,32],[19,32,22],[42,38,0],[30,23,4],[0,16,43],[0,43,40],[24,37,36],[38,24,36],[24,23,37],[37,23,26],[22,32,20],[20,32,31],[33,41,40],[43,33,40],[45,35,26],[37,26,35],[33,44,34],[44,43,46],[20,42,21],[40,21,42],[31,39,38],[20,31,38],[33,22,41],[21,41,22],[31,25,39],[24,39,25],[26,27,45],[28,45,27],[47,48,49],[47,50,48],[51,48,50],[52,48,51],[53,48,52],[54,55,56],[57,55,54],[58,55,57],[49,59,47],[60,56,55],[59,56,60],[60,47,59],[48,53,16],[56,13,19],[54,56,19],[56,59,13],[59,49,14],[59,14,13],[49,48,16],[49,16,14],[44,46,60],[44,60,55],[51,50,43],[19,34,58],[19,58,57],[53,52,16],[43,16,52],[43,52,51],[57,54,19],[47,60,46],[55,58,34],[55,34,44],[50,47,46],[50,46,43]
|
|
|
|
],
|
2012-11-21 19:41:14 +00:00
|
|
|
}
|
|
|
|
|
2013-07-03 13:42:01 +00:00
|
|
|
my $mesh = Slic3r::TriangleMesh->new(
|
|
|
|
vertices => $vertices,
|
|
|
|
facets => $facets,
|
|
|
|
);
|
|
|
|
$mesh->scale($params{scale}) if $params{scale};
|
|
|
|
|
2013-02-23 16:40:38 +00:00
|
|
|
my $model = Slic3r::Model->new;
|
2013-07-03 13:42:01 +00:00
|
|
|
my $object = $model->add_object(vertices => $mesh->vertices);
|
|
|
|
$object->add_volume(facets => $mesh->facets);
|
2013-06-15 10:10:57 +00:00
|
|
|
$object->add_instance(
|
|
|
|
offset => [0,0],
|
2013-06-15 15:17:48 +00:00
|
|
|
rotation => $params{rotation} // 0,
|
2013-06-15 10:10:57 +00:00
|
|
|
);
|
2013-02-23 16:40:38 +00:00
|
|
|
return $model;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub init_print {
|
|
|
|
my ($model_name, %params) = @_;
|
|
|
|
|
2012-11-21 19:41:14 +00:00
|
|
|
my $config = Slic3r::Config->new_from_defaults;
|
|
|
|
$config->apply($params{config}) if $params{config};
|
2012-12-21 14:14:44 +00:00
|
|
|
$config->set('gcode_comments', 1) if $ENV{SLIC3R_TESTS_GCODE};
|
2012-11-21 19:41:14 +00:00
|
|
|
|
|
|
|
my $print = Slic3r::Print->new(config => $config);
|
2013-05-30 18:06:05 +00:00
|
|
|
|
|
|
|
$model_name = [$model_name] if ref($model_name) ne 'ARRAY';
|
2013-06-15 10:10:57 +00:00
|
|
|
$print->add_model(model($_, %params)) for @$model_name;
|
2012-11-21 19:41:14 +00:00
|
|
|
$print->validate;
|
|
|
|
|
|
|
|
return $print;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub gcode {
|
|
|
|
my ($print) = @_;
|
|
|
|
|
|
|
|
my $fh = IO::Scalar->new(\my $gcode);
|
|
|
|
$print->export_gcode(output_fh => $fh, quiet => 1);
|
|
|
|
$fh->close;
|
|
|
|
|
|
|
|
return $gcode;
|
|
|
|
}
|
|
|
|
|
2012-12-21 12:25:03 +00:00
|
|
|
sub _eq {
|
2012-11-21 19:41:14 +00:00
|
|
|
my ($a, $b) = @_;
|
|
|
|
return abs($a - $b) < epsilon;
|
|
|
|
}
|
|
|
|
|
2012-12-30 15:27:20 +00:00
|
|
|
sub add_facet {
|
|
|
|
my ($facet, $vertices, $facets) = @_;
|
|
|
|
|
|
|
|
push @$facets, [];
|
|
|
|
for my $i (0..2) {
|
|
|
|
my $v = first { $vertices->[$_][X] == $facet->[$i][X] && $vertices->[$_][Y] == $facet->[$i][Y] && $vertices->[$_][Z] == $facet->[$i][Z] } 0..$#$vertices;
|
|
|
|
if (!defined $v) {
|
|
|
|
push @$vertices, [ @{$facet->[$i]}[X,Y,Z] ];
|
|
|
|
$v = $#$vertices;
|
|
|
|
}
|
|
|
|
$facets->[-1][$i] = $v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-21 19:41:14 +00:00
|
|
|
1;
|