@@ -175,15 +175,20 @@ sub cdummies { $_[1]->dummy(1,$_[2]->getdim(1)); }
175175package # hide from PAUSE
176176 PDL::Graphics::TriD::Triangles;
177177use base qw/ PDL::Graphics::TriD::GObject/ ;
178- use fields qw/ Faceidx Normals/ ;
178+ use fields qw/ Faceidx Normals TexColors TexCoord / ;
179179use PDL::Graphics::OpenGLQ;
180180sub new {
181181 my $options = ref ($_ [-1]) eq ' HASH' ? pop : {};
182182 my ($type ,$points ,$faceidx ,$colors ) = @_ ;
183183 my $this = $type -> SUPER::new($points ,$colors ,$options );
184184 $faceidx = $this -> {Faceidx } = $faceidx -> ulong; # (3,nfaces) indices
185- PDL::barf " Triangles error: broadcast dimensions forbidden for '$_ ' [@{[$this ->{$_ }->dims]}]" for grep $this -> {$_ }-> ndims != 2, qw( Points Colors Faceidx) ;
186- PDL::barf " Triangles error: dimension mismatch between Points [@{[$this ->{Points}->dims]}] and Colors [@{[$this ->{Colors}->dims]}]" if $this -> {Points }-> ndims != $this -> {Colors }-> ndims or $this -> {Points }-> dim(1) != $this -> {Colors }-> dim(1);
185+ if (ref $this -> {Colors } eq ' REF' ) {
186+ @$this {qw( TexColors TexCoord) } = @${ $this -> {Colors } };
187+ $this -> {Colors } = undef ;
188+ }
189+ PDL::barf " Triangles error: broadcast dimensions forbidden for '$_ ' [@{[$this ->{$_ }->dims]}]" for grep defined $this -> {$_ } && $this -> {$_ }-> ndims != 2, qw( Points Colors Faceidx TexCoord) ;
190+ my ($colour_cmp ) = grep defined , @$this {qw( Colors TexCoord) };
191+ PDL::barf " Triangles error: dimension mismatch between Points [@{[$this ->{Points}->dims]}] and Colors/TexCoord [@{[$colour_cmp ->dims]}]" if $this -> {Points }-> ndims != $colour_cmp -> ndims or $this -> {Points }-> dim(1) != $colour_cmp -> dim(1);
187192 $options = $this -> {Options };
188193 my ($idxflat , $idx0 , @idxdims ) = ($faceidx -> flat, $faceidx -> dims);
189194 if ($options -> {Shading } or $options -> {ShowNormals }) {
@@ -264,7 +269,10 @@ sub new {
264269 my @colordims = $colors -> dims;
265270 PDL::barf " Lattice: colours must be 3,x,y: got (@colordims )" if @colordims != 3 or $colordims [0] != 3;
266271 PDL::barf " Lattice: colours' x,y must equal points: got colour=(@colordims ) points=($x ,$y )" if $colordims [1] != $x or $colordims [2] != $y ;
267- $this -> add_object(PDL::Graphics::TriD::Triangles-> new($points -> clump(1..2), $faceidx , $colors -> clump(1..$colors -> ndims-1), \%less ));
272+ my $tc = PDL-> zeroes(PDL::float, 2, @colordims [1,2]);
273+ $tc -> slice(' (0)' ) .= $tc -> slice(' (0)' )-> xlinvals(0,1); # should be inplace but PDL bugfix not yet released XXX
274+ $tc -> slice(' (1)' ) .= $tc -> slice(' (1)' )-> ylinvals(0,1);
275+ $this -> add_object(PDL::Graphics::TriD::Triangles-> new($points -> clump(1..2), $faceidx , \[$colors , $tc -> clump(1..2)], \%less ));
268276 }
269277 if ($shading == 0 or $options -> {Lines }) {
270278 my $lcolors = $shading ? $this -> cdummies(PDL::float(0,0,0),$points ) : $colors ;
0 commit comments