How to get nice thumbnails for stl files in GNOME file explorer
TLDR:
Follow F3D's docs and install it somwhere the sandboxing system has access to (e.g. /usr/local)
I was looking for a way to display a nice preview of stl files and while it wasn't really complicated in the end it was not really obvious either. So I hope I can help you spare some time and also maybe learn something new along the way.
Nautilus doesn't generate thumbnails by itself, but uses thumbnailers - little scripts that tells it which command to execute to get a thumbnail preview. They are usually located in /usr/share/thumbnailers. See for example avif.thumbnailer:
[Thumbnailer Entry]
TryExec=/usr/bin/gdk-pixbuf-thumbnailer
Exec=/usr/bin/gdk-pixbuf-thumbnailer -s %s %u %o
MimeType=image/avif;
As you can see, the structure is pretty simple. TryExec tests if the program required for the generation if present, Exec is the command itself and MimeType ensures that correct thumbnailer will be selected for the file type.
GNOME has a mime type databases, that links them with files based on their extension.
Usually updating all of this is taken care of during installation of a program that is used to work with the desired file types. I however was not lucky in this case as the bambu studio flatpak did nothing for me in this regard. So I started looking for a program that would do just that. I found F3D - which is fast and minimalist 3D viewer that looked very promising. Even though I didn't plan to use it for actually opening the files it has incredibly helpful documentation! I first tried to install it via the recommended distro package, which still didn't show any stl thumbnails. However the desktop integration section of the documentation turned out to be incredibly helpful. All you have to do is follow the portable installation guide, but pay close attention to this inconspicuous section:
If you use the portable archive, make sure to extract it somewhere the sandboxing system has access to, eg: Nautilus uses bwrap and gives it access to /usr but not to /opt.
For me, installing the portable archive into ~/.local/share didn't work out exactly because of this. I installed it into /usr/local and after deleting the thumbnail cache folder (~/.cache/thumbnails/) the thumbnails finally appeared! I proceeded to tweak their visuals (documented here), which in my case is located in /usr/local/share/f3d/configs/thumbnail.d/. To get a nice blue color, change the 05_all.json as follows:
[
{
"options": {
"anti-aliasing": true,
"anti-aliasing-mode": "ssaa",
"camera-direction": "-1,-0.5,-1",
"color": "0.2,0.4,0.8",
"hdri-ambient": true,
"max-size": 100,
"metallic": 0.1,
"no-background": true,
"roughness": 0.3,
"tone-mapping": true,
"translucency-support": true,
"verbose": "quiet"
}
}
]