From: Ian Jackson Date: Sun, 7 Jan 2018 19:59:16 +0000 (+0000) Subject: distort-stl: wip, does not work because admesh X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=61e7ac9902ebc101aa25b30ed1ed0e3ec5e3bdbd;p=reprap-play.git distort-stl: wip, does not work because admesh --- diff --git a/distort-stl b/distort-stl new file mode 100755 index 0000000..863c8d1 --- /dev/null +++ b/distort-stl @@ -0,0 +1,69 @@ +#!/usr/bin/perl -w +# +# usage: +# ./distort-stl OUTPUT DISTORTION [PARAMS...] ... +# +# DISTORTIONs: +# +# project-cylinder RADIUS +# projects the X-Z plane onto the cylinder of +# radius RADIUS with axis [0, 0, t] +# origin becomes [0, -RADIUS, 0] +# other planes of the input are projected onto smaller +# or larger cylinders accordingly +# probably a bad idea if +# object has any Y > RADIUS +# object has any |X| > tau / RADIUS +# technically, treats input as if it were +# polar-rectangular coords: +# Z' = Z; R' = Y + RADIUS; theta' = X / RADIUS +# and then converts back into cartesian + +use strict; +use autodie; + +sub shift_arg () { + die unless @ARGV; + scalar shift @ARGV; +} + +sub pointmap_distortion { + my ($x,$y,$z) = @_; + my $radius = shift_arg; + my $r = $y + $radius; + my $theta = $x / $radius; + return ($r * cos($theta), + $r * sin($theta), + $z); +} + +if (@ARGV && $ARGV[0] =~ m/^-/) { + die "no options supported\n"; +} + +my $admesh_pipe = '--write-ascii-stl 3<&0 4>&1 >/dev/null /dev/fd/4 /dev/fd/3'; + +open I, "admesh $admesh_pipe |"; +open O, "| admesh --normal-values $admesh_pipe"; + +our @saved_argv = @ARGV; + +while () { + if (s/^\s+vertex\s+//) { + my $lhs = $&; + s/\s+$//; + my @xyz = split /\s+/, $_; + while (@ARGV) { + my $op = shift_arg; + @xyz = &{ $::{"pointmap_$op"} }( @xyz ); + } + @xyz = map { sprintf "%.18g", $_ } @xyz; + $_ = "$lhs@xyz\n"; + } + print O; +} + +, if 0; # suppresses Name "main::I" used only once + +close I; +close O;