From c05cf2c4da1fd1cb4aff4591dc7826ab83664e2c Mon Sep 17 00:00:00 2001 From: ceade Date: Thu, 30 Apr 2020 22:57:17 +0200 Subject: [PATCH] Attempt to fix incorrectly inverted sub-parts There was bad behaviour if there were nested include files combined with a recursive invert flag, resulting in incorrect surface normals for sub-parts. For example try ldraw/parts/3020.dat before this commit. This is not the best way to solve the problem, but it may suffice for now. IMO the best way would be to "flip" the invert flag between states, rather than explcitely set it to 1 or 0. That way recursively setting invert would simply flip the flag. --- lib/LDraw/Parser.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/LDraw/Parser.pm b/lib/LDraw/Parser.pm index 735e5d1..602527b 100644 --- a/lib/LDraw/Parser.pm +++ b/lib/LDraw/Parser.pm @@ -128,7 +128,7 @@ sub handle_bfc_command { my $first = shift @items; if ( $first && $first eq 'INVERTNEXT' ) { - $self->invert( 1 ); + $self->invert(1); $self->DEBUG('handle_bfc_command(): inverted model'); } } @@ -197,7 +197,6 @@ sub parse_sub_file_reference { my $subparser = __PACKAGE__->new( { file => $subpart_filename, ldraw_path => $self->ldraw_path, - invert => $self->invert, debug => $self->debug, d_indent => $self->d_indent + 2, } ); @@ -210,6 +209,7 @@ sub parse_sub_file_reference { $vec->[1] = $new_vec[1]; $vec->[2] = $new_vec[2]; } + $triangle->[4] = [ $self->calc_surface_normal($triangle->[0], $triangle->[1], $triangle->[2]) ]; push @{ $self->{triangles} }, $triangle; } }