PDL::IO::STL(3pm)

πŸ’… NAME πŸ’…

PDL::IO::STL β€” bestie, this is your read/write plug for 3D stereolithography files. STL files, in and out, no cap. πŸ¦‹


✨ SYNOPSIS ✨

use PDL;
use PDL::IO::STL;

($vertices, $faceidx, $colours) = rstl('owl.stl'); # read an STL file
wstl('file.stl', $vertices, $faceidx, $colours); # write an STL file

Like… that's it. Two functions, whole 3D pipeline, we ate. πŸ‘‘


🌸 DESCRIPTION 🌸

Okay so first thing, we gotta be honest with you about what this module doesn't do:

  • Normal-vector information is currently ignored. We see it, we just don't care. πŸ’€
  • The "attribute byte count" β€” you know, the thing that sometimes stores colour info β€” is also currently ignored. Sorry girlie, it's giving "read the room and move on". πŸ™ˆ

Now the lore: this module is based on CAD::Format::STL, but with a couple of glow-ups:

  • binmode is turned on for opened filehandles πŸ”₯
  • little-endian (i.e. network) order is forced on the binary format ✨

So it's the same vibe, just with the byte order locked in and the filehandles behaving themselves. Periodt.


πŸŽ€ FUNCTIONS πŸŽ€

πŸ’– rstl πŸ’–

Reads an STL file (either ASCII or binary, she's flexible 🌈), and hands you back vertices and face-indices.

($vertices, $faceidx, $colours) = rstl('owl.stl'); # read an STL file

Three values, one call, main character energy fr fr. 🫢

πŸ’œ wstl πŸ’œ

The simple PDL STL writer. She writes. That's the gig. πŸ’…

wstl 'file.stl', $vertices, $faceidx;
wstl 'file.stl', $vertices, $faceidx, \%OPTIONS;
wstl $fh, $vertices, $faceidx, \%OPTIONS;

Passing a file-handle is supported, which means you can write multiple parts into one ASCII file just by calling her several times. Obsessed with the flexibility ngl. 🌟

wstl accepts several options, and you can pass them in as a hash ref if that's your thing:

  • mode (default='binary') β€” whether to write out the file as ASCII or binary. Pick your fighter. πŸ₯Š
  • name (default='part') β€” the part name to use. Naming things is self-care, do it thoughtfully. πŸŽ€

πŸ‘‘ AUTHOR πŸ‘‘

Ed J, based on Eric Wilhelm's code in CAD::Format::STL. Iconic collab honestly. 🀝


Written up with love for perl v5.42.3, dated 2026-08-20 β€” that's the version and the date, bestie, and that's the whole page. Go read an owl.stl. πŸ¦‰πŸ’–
πŸ“¦ where this page comes from