1
0
mirror of https://github.com/kristov/ldraw2stl.git synced 2025-05-15 14:20:11 -07:00
ldraw2stl/bin/dat2stl
ceade 9a0073a0c5 Hopefully better support for Windows users
I was concatenating paths together using the unix slash `/`. This change used
`File::Spec::catpath` instead, however I haven't been able to test it on Windows, and
there may be other path issues. Also note: without debugging on the user doesn't see when
files are not found (eg: due to path issues), so it silently creates an empty STL file.
2025-03-19 23:41:12 +01:00

78 lines
1.7 KiB
Perl
Executable File

#!/usr/bin/perl
use strict;
use warnings;
use FindBin;
use lib "$FindBin::Bin/../lib";
use LDraw::Parser;
use Getopt::Long;
my $opts = {};
GetOptions(
$opts,
'help',
'scale=s',
'ldrawdir=s',
'file=s',
'debug',
'nomodel',
);
if (!keys %{$opts}) {
print_usage();
exit 0;
}
if ($opts->{help}) {
print_usage();
exit 0;
}
if (!$opts->{file}) {
print "ERROR: --file is required! (try --help)\n";
exit 1;
}
sub print_usage {
print <<END;
Usage: $0 --file <input file> [--scale=<N> --ldrawdir=/usr/share/ldraw]
Takes an ldraw part .dat file as input and converts it into an STL file.
--file <string>
The full path to the input .dat part file. Regardless of where this file
is, sub-parts of the file will be searched in --ldrawdir.
--scale <int>
Also scale the STL by N. This is separate from the LDU scaling that is
used to convert internally from LDU (LDraw Unit) to mm (STL).
--ldrawdir <string>
The location of the ldraw parts library package. Note: it is expected
that this contains the directories "p", "parts" and "models". The Debian
non-free package "ldraw-parts" installs to /usr/share/ldraw and that is
the default value for this tool.
--debug
Print debugging messages to STDERR
--nomodel
Do not print the stl output. I am using this to run the script over all
parts to try to detect issues.
END
}
my $parser = LDraw::Parser->new( {
file => $opts->{file},
$opts->{scale} ? ( scale => $opts->{scale} ) : (),
$opts->{ldrawdir} ? ( ldraw_path => $opts->{ldrawdir} ) : (),
$opts->{debug} ? ( debug => 1 ) : (),
} );
$parser->parse;
if ($opts->{nomodel}) {
exit 0;
}
print $parser->to_stl;