Learn creative coding writing simple programs

152. Exporting 3D shapes as .obj files in Processing

This time we are taking the shape we created in episode 151 and exporting it as an .obj file. To achieve that we use the ObjExport Processing library. We also take a look at how to make code run only once even if it's inside the draw loop. That becomes useful to avoid exporting the .obj file over and over again. We only need the file once :)

Processing by default offers a limited set of 3D primitives: only spheres and cubes. Other shapes you have to load or build yourself out of triangles calling vertex(), which probably means knowing a lot of math. To make it easier to generate and manipulate complex 3D shapes there are several libraries, for instance Toxiclibs (http://toxiclibs.org/) and HE_Mesh (http://hemesh.wblut.com/). In this tutorial I also show where you can find examples for exporting .obj files using both HE_Mesh and Toxiclibs.

In the next episode we will import the .obj file into Blender and render an image with realistic lights and shadows!

Tags: obj, export, toxiclibs, hemesh

Code editor

You can make changes to the code below. Then

Questions and comments

Try to stay close to the topic of this episode. Use the Processing forums for help with unrelated Processing projects (or hire me for help ;-)

To indicate that a word in your comment is code, use the `backtick`. Example
Do `float` and `int` smell similar?
To highlight code blocks, surround it with ``` code-fences ``` like this:
``` void setup() { size(600, 600); } ```