1
0
mirror of https://github.com/kristov/ldraw2stl.git synced 2025-05-15 22:30:10 -07:00

Add --debug flag for adding debug messages

Trying to track down a normals problem with studs on 3020.dat model.
This commit is contained in:
Chris Eade 2020-04-30 14:22:59 +02:00
parent b76f67e092
commit e3f34ac87b
2 changed files with 33 additions and 1 deletions

View File

@ -14,6 +14,7 @@ GetOptions(
'scale=s',
'ldrawdir=s',
'file=s',
'debug',
);
if ( $opts->{help} ) {
@ -46,6 +47,9 @@ Takes an ldraw part .dat file as input and converts it into an STL file.
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
END
}
@ -53,6 +57,7 @@ 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;

View File

@ -37,10 +37,34 @@ has invert => (
documentation => 'Invert this part',
);
has debug => (
is => 'rw',
isa => 'Bool',
default => 0,
documentation => 'Print debugging messages to stderr',
);
has d_indent => (
is => 'ro',
isa => 'Int',
default => 0,
documentation => 'Indentation for debug messages (for subfiles)',
);
use constant X => 0;
use constant Y => 1;
use constant Z => 2;
sub DEBUG {
my ( $self, $message, @args) = @_;
return if !$self->debug;
my $indent = " " x $self->d_indent;
if ( @args ) {
$message = sprintf($message, @args);
}
print STDERR sprintf("%s%s\n", $indent, $message);
}
sub parse {
my ( $self ) = @_;
return $self->parse_file( $self->file );
@ -95,7 +119,6 @@ sub parse_line {
sub parse_comment_or_meta {
my ( $self, $rest ) = @_;
my @items = split( /\s+/, $rest );
my $first = shift @items;
@ -111,6 +134,7 @@ sub handle_bfc_command {
if ( $first && $first eq 'INVERTNEXT' ) {
$self->invert( 1 );
$self->DEBUG('handle_bfc_command(): inverted model');
}
}
@ -174,10 +198,13 @@ sub parse_sub_file_reference {
return;
}
$self->DEBUG('parse_sub_file_reference(): parsing subfile "%s" with inverted: %d', $subpart_filename, $self->invert);
my $subparser = __PACKAGE__->new( {
file => $subpart_filename,
ldraw_path => $self->ldraw_path,
invert => $self->invert,
debug => $self->debug,
d_indent => $self->d_indent + 2,
} );
$subparser->parse;