I was digging through some bit-rotted PDL::Graphics::TriD stuff to finish/fix it, and looked at PDL::Graphics::TriD::Logo. It was intended to be used with the non-functional-right-now PDL VRML support, in particular VRML's IndexedFaceSet feature. It had 3D point coordinates, then triplets of indexes into those to describe triangles.
Gripped - nay, seized - by a desire to see what the logo looked like, I needed to turn that into something the current TriD code can show me. I knew line3d could take a set of 4-point tuples to draw triangles if the 4th point was the same as the 1st. But how to turn points+indexes into that?
I often say that in PDL, the "right" solution to problems involves slices and dimension-mangling. This was no exception!
Coda: the logo is just "PDL" in a serif font, given "depth" as if in a stick of rock.use PDL::Graphics::TriD; use PDL::Graphics::TriD::Logo; $p = $PDL::Graphics::TriD::Logo::POINTS; # dims: xyz, i $i = $PDL::Graphics::TriD::Logo::FACES; # dims: i1to3, ntriangles # 1: duplicate 0-th index onto end of each vector completing triangle $i = $i->append($i->slice('0')); # change to i1to3to1 # 2: flatten indices, slice points with those, restore 4-tuples shape $tri = $p->slice(':',$i->clump(-1))->splitdim(1,$i->dim(0)); line3d($tri); # visualise
I'm intending to update the VRML support to:
- generalise that plus the OpenGL support of each specific thing (lines, points, etc) to go via an intermediate description to make this easy;
- work at all;
- switch it to use X3D;
- use that to generate updated 3d demos for the PDL website.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: IndexedFaceSet to 3D lines in two lines of PDL
by etj (Deacon) on Apr 17, 2022 at 22:23 UTC |
Back to
Cool Uses for Perl