stl2png Nautilus Thumbnailer
Recently I've found myself working with STL files a lot more since I bought a 3d printer (more on that in a separate post!) (.obj is technically the better format, but STL is still widely used). I'm a visual sort of person, and with this in mind I like to have previews of things in my file manager. When I found no good STL thumbnailers for Nautilus (the default file manager on Ubuntu), I set out to write my own.
In my research, I discovered that OpenSCAD can be used to generate a PNG image from an STL file if one writes a small .scad
file wrapper (ref), and wanted to blog about it here.
First, a screenshot of it in action:
(Above: stl2png in action as a nautilus thumbnailer. STL credit: Entitled Goose from the Untitled Goose Game)
You can find installation instructions here:
https://github.com/sbrl/nautilus-thumbnailer-stl/#nautilus-thumbnailer-stl
The original inspiration for this twofold:
- All the existing stl thumbnailers I found GitHub didn't work for me
- This Stack Exchange answer: https://3dprinting.stackexchange.com/a/6047/30537
From there, wrapping it in a shell script and turning it into a nautilus thumbnailer was not too challenging. To do that, I followed this guide, ehich was very helpful (though the update-mime-database
bit was wrong - the filepath there needs to have the /packages
suffix removed).
I did encounter a few issues though. Firstly finding the name for a suitable fallback icon was not easy - I resorted to browsing the contents of /usr/share/icons/gnome/256x256/mimetypes/
in my file manager, as this spec was not helpful because STL model files don't fit neatly into any of the categories there.
The other major issue was that the script worked fine when I called it manually, but failed when I tried to use it via the nautilus thumbnailing engine. It turned out that OpenSCAD couldn't open an OpenGL context, so as a quick hack I wrapped the openscad
call in xvfb-run
(from X Virtual FrameBuffer; sudo apt install xvfb
)).
With those issues sorted, it worked flawlessly. I also added optional oxipng
(or optipng
as an optional fallback) support for optimising the generated PNG image - this I found in casual testing saved between 70% and 90% on file sizes.
Found this interesting or helpful? Comment below! It really helps motivate me.