![]() I stumbled on this fish shape when playing with the equations for the Oloid. ![]() The mode is very handy for creating video clips and as I’ve just discovered also for making animated GIFs. There are at least 3 uses that I make of it: for capturing an animation, for exploring parameters and to refresh the view when programming. Thanks for reading! In part 2 I’ll cover some more OpenSCAD tricks with similar command line scripting techniques to easily export a design for laser cutting.I’m a fan of the animation mode in OpenSCAD. You should check it out if you haven’t already: Automated KiCad, OpenSCAD rendering using Travis CI. In a past blog post, I discussed how I run this script using Travis CI to automatically re-render the 3d animation every time I make a change to the source code. The full script implementation can be found in the following files: The last step is to put all those frames together as an animated gif, which is fairly straightforward using ImageMagick:Ĭonvert 'frame_*.png' -set delay 1x15 animation.gif On my machine, rendering with a 4-thread Pool reduced the rendering time from 6 minutes 41 seconds down to just under 3 minutes! # Consume results as they occur so any task exceptions are rethrown asapĪs a minor aside, it’s not really necessary to use separate threads, since each task is already launching a separate subprocess, but a threadpool provides a convenient abstraction for bounded parallel execution. Pool = Pool() # By default, Pool uses one thread per available CPUįor _ in pool.imap_unordered(render_frame, range(num_frames)): Since each OpenSCAD process uses up to a single core, we can choose a pool size to match the number of cores available. Using a threadpool ( in Python) we can enqueue each of the OpenSCAD frame-rendering tasks to be run in parallel across a specified number of workers. With a desired 50 frames per revolution * 3 rendering options, that’s 150 total invocations of OpenSCAD! As far as I can tell there’s no easy way around this, but we can still speed it up by using multiple cores. Unfortunately, by invoking openscad once per frame, the 3D model’s geometry needs to be recompiled for every camera angle rendered, which takes a nontrivial amount of time. Three different views of the model by changing the render_enclosure and render_flaps variables. I use this so that over the course of three animated revolutions you can see all the different parts of the design. Then from a script, I can invoke OpenSCAD using arguments like -D render_enclosure=0 -D render_flaps=false which override the variable definitions in the file. Render_enclosure = 1 // 2=opaque color 1=translucent 0=invisible At the top of splitflap.scad, I defined a few variables that control the visibility/opacity of the enclosure and flaps (this was also useful while designing the model): In addition to a simple rotation, I wanted to showcase different parts of the model in the animation. (This uses a simple Python wrapper to invoke OpenSCAD’s command line interface) This makes it easy to write a script that exports snapshots from 360 degrees:Īngle = start_angle + (i * 360 / num_frames) ![]() To fully automate this, I used OpenSCAD’s command-line interface which lets you specify options like -imgsize=width,height and -camera=translatex,y,z,rotx,y,z,dist to control the exported image. This works well, but still requires some manual export steps from the GUI. To make a spinning animation, you can just wrap your model in a rotate transformation proportional to $t. He used OpenSCAD’s built-in animation feature, which lets you parameterize your model using a special animation time variable, $t. I was inspired by Bryan Duxbury’s blog post on creating an animated gif from an OpenSCAD model. The final product: a 360° animation that cycles through three views of the model. Plus, a single static image doesn’t fully convey the 3D model, so I wanted something more dynamic. The image that’s exported is basically a snapshot of the current preview window, so the image dimensions and camera angle would be different each time. It’s possible to capture an image manually (File→Export→Export as Image), but that’s an extra thing to remember to do after every change and it’s also not very consistent. OpenSCAD Rendering Tricks, Part 3: Web viewerĮarly when designing the split flap 3D model using OpenSCAD I wanted to include a visualization in the project’s README so others could see what it looked like. OpenSCAD Rendering Tricks, Part 2: Laser Cutting
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |