I’ve found that more and more I am exporting images from OpenSCAD, and while in the past I was satisfied with just spinning the object to an angle and exporting a PNG file, I’m now doing more step-by-step things where I want consistency and don’t want things jumping around. Instead of carefully setting the view with the mouse and doing all the exports, I now set the viewing parameters directly in the file, because you can do that in OpenSCAD…
Time to go back to the OpenSCAD User Manual! While the Cheat Sheet is an excellent resource, I find myself hitting up the manual a lot more frequently lately. The Cheat Sheet will show you this of course:
$vpr viewport rotation angles in degrees
$vpt viewport translation
$vpd viewport camera distance
$vpf viewport camera field of view
And that’s what we need! So over to the manual section for $vpr,_$vpt,_$vpf_and_$vpd.
Pop open that Viewport-Control in the Window menu and look at that… it shows you values and you can change them…
(Note: You can also set the aspect ratio, and lock it. Sweet!)
But the real powerful bit is that you can just set those parameters in your code. When you preview your code it will set those values and you get the same viewing angle, rotation, distance and field of view each time. Brilliant!
You can see my commented out code for the bottom versus top view on line 37.
I love finding stuff like this and them implementing it into my code… It’s probably not some amazing killer feature, but it’s one more nicety that helps me keep things consistent and adds a bit more power to what I can do with OpenSCAD.