Skip to content

Commit 4b2a2b4

Browse files
committed
Trigrid ShowNormals check have normals to show
1 parent 2d492b6 commit 4b2a2b4

File tree

1 file changed

+14
-8
lines changed
  • lib/PDL/Graphics/TriD

1 file changed

+14
-8
lines changed

lib/PDL/Graphics/TriD/GL.pm

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -261,14 +261,20 @@ sub PDL::Graphics::TriD::Trigrid::gdraw {
261261
PDL::gl_triangles_n_mat(map $_->mv(1,-1)->dog, $faces, $colours);
262262
}
263263
if ($this->{Options}{ShowNormals}) {
264-
my $arrows = $points->append($points + $this->{Normals}*0.1)->splitdim(0,3);
265-
glDisable(GL_LIGHTING);
266-
glColor3d(1,1,1);
267-
PDL::Graphics::OpenGLQ::gl_arrows($arrows, 0, 1, 0.5, 0.02);
268-
my $facecentres = $faces->transpose->avgover;
269-
my $facearrows = $facecentres->append($facecentres + $this->{FaceNormals}*0.1)->splitdim(0,3);
270-
glColor3d(0.5,0.5,0.5);
271-
PDL::Graphics::OpenGLQ::gl_arrows($facearrows, 0, 1, 0.5, 0.02);
264+
die "No normals to show!" if !grep defined $this->{$_}, qw(FaceNormals Normals);
265+
if (defined $this->{Normals}) {
266+
my $arrows = $points->append($points + $this->{Normals}*0.1)->splitdim(0,3);
267+
glDisable(GL_LIGHTING);
268+
glColor3d(1,1,1);
269+
PDL::Graphics::OpenGLQ::gl_arrows($arrows, 0, 1, 0.5, 0.02);
270+
}
271+
if (defined $this->{FaceNormals}) {
272+
my $facecentres = $faces->transpose->avgover;
273+
my $facearrows = $facecentres->append($facecentres + $this->{FaceNormals}*0.1)->splitdim(0,3);
274+
glDisable(GL_LIGHTING);
275+
glColor3d(0.5,0.5,0.5);
276+
PDL::Graphics::OpenGLQ::gl_arrows($facearrows, 0, 1, 0.5, 0.02);
277+
}
272278
}
273279
if ($this->{Options}{Lines}) {
274280
glColor3f(0,0,0);

0 commit comments

Comments
 (0)