From 59ab2fd29031c4d5930a44d7275347074a8746fb Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 7 Jan 2018 22:24:37 +0000 Subject: [PATCH] distort-stl: new approach, wip fixes --- distort-stl | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/distort-stl b/distort-stl index eb3a7a1..1b512f8 100755 --- a/distort-stl +++ b/distort-stl @@ -25,8 +25,11 @@ use strict; use autodie; -use File::Temp; use List::Util; +use POSIX; +use File::Temp (); + +sub TAU () { M_PI * 2; } our $fa = 10; @@ -38,19 +41,19 @@ sub shift_arg () { } sub subdivide_triangle ($$) { - my ($it, $fn) = @_; + my ($t, $fn) = @_; my @mids; foreach my $ix (0..2) { my $jx = ($ix+1) % 3; my @midp; foreach my $ci (0..2) { - push @midp, 0.5 * ($it->[$ix][$ci] + $it->[$jx][$ci]); + push @midp, 0.5 * ($t->[$ix][$ci] + $t->[$jx][$ci]); } push @mids, @midp; } foreach my $ix (0..2) { my $kx = ($ix+2) % 3; - $fn->([ $it->[$ix], $mids[$ix], $it->[$kx] ]); + $fn->([ $t->[$ix], $mids[$ix], $t->[$kx] ]); } $fn->(\@mids); } @@ -61,22 +64,22 @@ our $project_cylinder_radius; our $project_cylinder_max_d_theta; sub project_cylinder_tri { - my ($it) = @_; + my ($t) = @_; - my $radius = project_cylinder_radius; + my $radius = $project_cylinder_radius; - my @thetas = map { $_->[0] / $radius } @$it; + my @thetas = map { $_->[0] / $radius } @$t; foreach my $ix (0..2) { if (abs($thetas[$ix] - $thetas[($ix+1)%3]) > $project_cylinder_max_d_theta) { - subdivide_triangle $it, \&project_cylinder_tri; + subdivide_triangle $t, \&project_cylinder_tri; return; } } my @ot; - foreach my $p (@it) { + foreach my $p ($t) { my ($x,$y,$z) = @$p; my $r = $radius - $y; my $theta = $x / $radius; @@ -115,19 +118,21 @@ open I, "admesh $admesh_stdout $itmp |"; my $triangle; while () { - if (m/^\s+outer\s+loop/) { + s/^\s*//; + if (m/^outer\s+loop/) { die if $triangle; $triangle = []; - } elsif (s/^\s+vertex\s+//) { + } elsif (s/^vertex\s+//) { my $lhs = $&; s/\s+$//; my @xyz = split /\s+/, $_; die unless $triangle; - push @$triangle, \@xya; - } elsif (m/^\s+endloop/) { + push @$triangle, \@xyz; + } elsif (m/^endloop/) { die unless @$triangle == 3; push @triangles, $triangle; - } elsif (m/^\s+(?:solid|facet\s+normal|endfacet|endsolid)\s/) { + undef $triangle; + } elsif (m/^(?:solid|facet\s+normal|endfacet|endsolid)\s/) { } else { die "$_ ?"; } -- 2.30.2