Skip to content

Commit 95f4ccc

Browse files
committed
trigrid3d $colours is now per-vertex
1 parent f43c1db commit 95f4ccc

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

Changes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
- build improvements
22
- drop use of GLU functions
33
- rationalise/unify ::Objects classes
4+
- trigrid3d $colours is now per-vertex
45

56
2.102 2025-04-11
67
- fix scrolling out with mousewheel/double-touch-scroll in GLUT

lib/PDL/Graphics/TriD.pm

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,17 +369,27 @@ contexts and options
369369
370370
=head2 lattice3d
371371
372+
=for usage
373+
374+
trigrid3d $vertices, $faceidx, [$colours], [{OPTIONS}]
375+
372376
=for ref
373377
374378
alias for mesh3d
375379
376380
=head2 trigrid3d
377381
378-
Show a triangular mesh, giving C<$vertices> and C<$faceidx> which is
382+
=for ref
383+
384+
Show a triangular mesh.
385+
386+
C<$faceidx> is
379387
a series of triplets of indices into the vertices, each describing
380388
one triangle. The order of points matters for the shading - the normal
381389
vector points towards the clockface if the points go clockwise.
382390
391+
C<$colours> is per vertex.
392+
383393
Options: C<Smooth> (on by default), C<Lines> (off by default),
384394
C<ShowNormals> (off by default, useful for debugging).
385395

lib/PDL/Graphics/TriD/Objects.pm

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,16 +148,14 @@ sub new {
148148
if(!defined $options and ref $colors eq "HASH") {
149149
$options = $colors;undef $colors; }
150150
$points = PDL::Graphics::TriD::realcoords($type->r_type,$points);
151-
my $faces = $points->dice_axis(1,$faceidx->flat)->splitdim(1,3);
152-
# faces is 3D pdl slices of points, giving cart coords of face verts
153151
if(!defined $colors) { $colors = PDL->pdl(PDL::float(),0.8,0.8,0.8);
154-
$colors = $type->cdummies($colors,$faces);
152+
$colors = $type->cdummies($colors,$points);
155153
$options->{ UseDefcols } = 1; } # for VRML efficiency
156154
else { $colors = PDL::Graphics::TriD::realcoords("COLOR",$colors); }
157155
my $this = bless { Points => $points, Faceidx => $faceidx,
158156
Colors => $colors, Options => $options},$type;
159157
$this->check_options;
160-
$this->{Normals} = $this->smoothn($faces) if $this->{Options}{Smooth};
158+
$this->{Normals} = $this->smoothn($points->dice_axis(1,$faceidx->flat)->splitdim(1,3)) if $this->{Options}{Smooth};
161159
$this;
162160
}
163161
sub get_valid_options { +{
@@ -168,10 +166,11 @@ sub get_valid_options { +{
168166
ShowNormals => 0,
169167
Lighting => 1,
170168
}}
171-
sub cdummies { # called with (type,colors,faces)
172-
return $_[1]->dummy(1,$_[2]->getdim(2))->dummy(1,$_[2]->getdim(1)); }
169+
sub cdummies { # called with (type,colors,points)
170+
return $_[1]->dummy(1,$_[2]->getdim(1))->dummy(1,3); }
173171
sub smoothn { my ($this, $faces) = @_;
174172
my ($points, $faceidx) = @$this{qw(Points Faceidx)};
173+
# faces is 3D pdl slices of points, giving cart coords of face verts
175174
my @p = $faces->mv(1,-1)->dog;
176175
my $fn = ($p[1]-$p[0])->crossp($p[2]-$p[1])->norm; # flat faces, >= 3 points
177176
$this->{FaceNormals} = $fn if $this->{Options}{ShowNormals};

0 commit comments

Comments
 (0)