Export A 3D Object From Processing To Blender

** TL;DR

This sketch code exports a 3D object from Processing that you can import into Blender

(You'll need the [[https://n-e-r-v-o-u-s.com/tools/obj/][OBJExport library]] installed to run the process)

** Importing Into Blender

The example above exports a file called `cubes.obj`. The steps to import it into Blender are:

1. Open a new project in Blender 2. Click "File" in the main menu bar 3. Click "Import" 4. Select "Wavefront (.obj)" 5. Navigate to the "cubes.obj" file 6. Click "Import OBJ" 7. Zoom way out to find the object

When I import the object it's pretty huge and way off center. Hence the last step to zoom way out. The center point of the object is the world origin. So, another option is to scale down and eventually you'll see it there.

If you figure out a way to keep it centered, let me know.

In the mean time, have fun using the apps together.



- These are notes from my setup using Processing 4.0.1 and Blender 3.2.0 on macOS 12.2.1. Give it a shot if you have something different and see what happens

- Credit to [[https://funprogramming.org/][funprogramming.org]] for the videos that got me started. [[https://funprogramming.org/151-Convert-an-image-into-a-3D-grid-of-boxes.html][Their example]] uses an image for the primary source to make the cubes. It's very cool but adds extra steps. I switched to the random cubes in an effort to simplify, but you should totally go check theirs out too for the image. I use a modified approach of it for [[https://art.alanwsmith.com/projects/1/][some of my pieces]]

- [[https://github.com/nervoussystem/OBJExport][OBJExport]] hasn't been updated in a decade, but it's working great for me

- You have to save the sketch file before running the sketch code so Processing knows where it is to output the file in the same directory. (You could also use a full path)

- Two other Processing 3D libraries to investigate are "HE_Mesh", and "toxiclibscore". Probably there are other libraries as well, but those two were mentioned on [[https://funprogramming.org][funprogramming.org]]

- The `beginRecord()` and `endRecord()` are in the `setup()` function because that only runs one time as opposed to the `draw()` function which runs continously. If you put it in `draw()` you have to setup something to trigger the capture. See the example on [[https://n-e-r-v-o-u-s.com/tools/obj/][the home page]])

- Only a single object is imported in to Blender. You'll have to split things out if you want to work with them individually. You can do that by switching to Edit Mode, using `l` to select a single cube, pressing `p` to bring up the `Separate` menu, then clicking `Selection`


- [[https://funprogramming.org/152-Exporting-3D-shapes-as-obj-files-in-Processing.html][Exporting 3D shapes as .obj files in Processing - fun programming]] - [[https://n-e-r-v-o-u-s.com/tools/obj/][OBJExport from NERVOUS SYSTEM, INC.]] - [[https://github.com/nervoussystem/OBJExport][OBJExport on GitHub]]