I’ve taken up 3d printing as a hobby, and so in short order had hundreds of little files sitting around of various works in progress. STLs, 3mf’s, gcode files, and scad files to name a few. I found someone’s github project to thumbnail STL files, and discovered how gnome’s plug-able thumbnailers work.
How cool, I thought. I found someone else’s thumbnailer example for gcode and that worked a treat too. And then I got greedy. Why should I ever have a vanilla icon again if I can make thumbnails. THUMBNAIL EVERYTHING. that hammer is golden after all…
When I couldn’t find one for 3mf, I remembered that 3mf files are just a zipfile, and contain a preview image already. I wrote my first ever thumnailer from scratch, that’s just a oneline script to use unzip to pull out that preview image.
Then I took on scad files and here is where I ran into a snag.
STLs are a self contained mesh (array of tangential triangles in 3 dimensional space.)
gcode is machine instructions for where to squirt out plastic and how fast
3mf’s are assemblies of STL files on a 2 dimensional plate, with some instructions for custom printting
SCAD files however, are scripts that can generate STL files. Most of the time they have default values sufficient to immediately render something when you open them. And I found a command line to do just that.
more or less:
/usr/bin/openscad --imgsize=%s,%s -o %o %i
But here’s the snag. Unlike STLs, gcode, and 3MF, because scad files are ‘programs’ they often ‘include’ other scad files, or standard libraries. And when the thumbnailer executes it’s in some sort of chroot jail. the included files aren’t available to it in the jail, and so the renders, frustratingly fail.
Is there a way to disable this chroot for one specific thumbnailer? or do I need to expand on my thumbnailer script to have it, itself parse out what includes are needed, and copy then into the jail or something else?
I assume this is a problem thats been seen before. For instance, some types of word processor documents can embed images by URL or filepath, so your .doc file doesn’t become rediculously large for example.
What’s the right way to write a thumbnailer for a file type with external dependencies?