Auto-Rendering STL Files to PNG
Posted by Adam on Tuesday Dec 1, 2009For the past few months I’ve been messing around with django and writing a web-based inventory system thing for Hive76. One of my goals was to auto-generated nice renders of STL files people attach a-la Thingiverse. Sure, I could have just asked Zach, but where’s the fun in that? Since I don’t know a damn thing about 3D modeling or any of the tools used for this, it ended up taking me a lot longer than I expected. The result is this very short shell script, with all of the work being done by stl2pov and povray, with a little help from the Axes and Grid Macro to pretty things up a bit. Here is the povray template I’m using and here is the shell script:
#!/bin/bash
STL=$1
BASEFILE=`echo "$STL" | sed -e 's/\.stl//g'`
OUTFILE=${BASEFILE}.png
POVFILE=${BASEFILE}.pov
INCFILE=${BASEFILE}.inc
stl2pov -s "$STL" > "${INCFILE}"
MODELNAME=`grep "#declare" "${INCFILE}" | cut -d\ -f2`
cat pov_layout.tmpl | sed -e "s/{{INCLUDE_FILE}}/${INCFILE}/g" \
-e "s/{{MODELNAME}}/${MODELNAME}/g" > "${POVFILE}"
povray -s -i"${POVFILE}" +FN +W1600 +H1200 -o"${OUTFILE}" +Q9 +AM2 +A2
echo "OUTFILE: ${OUTFILE}"
That’s it!
I still haven’t made the script intelligent about camera positioning relative to model size, but since most of the models we design are intended to be printed on our MakerBot, the hard-coded values seem to work pretty well. Anyway, if you know about this stuff and see something I could do better, or you have any other cool ideas, I’m all ears.














