Exporting 3D files
You've already learned that you can save your work as an image or a PDF file. If you want to generate 3D objects in Processing, and render them in a 3D application such as Cinema 4D or in a CAD program, you'll need to save that 3D data. We'll take a look at how you can use the DXF library that comes with Processing to save your generated 3D models.
How to do it...
We'll need to import the DXF and OpenGL libraries first. Go to the Sketch | Import Library menu, and choose these libraries from there. You'll also need to declare a boolean variable named saveDXF
. We'll use this variable in the same way as we used the savePDF
variable in the recipe on saving PDF files.
import processing.opengl.*; import processing.dxf.*; boolean saveDXF = false; void setup() { size( 640, 480, OPENGL ); smooth(); }
In the draw()
function, we'll use the beginRaw()
and endRaw()
functions to record the 3D data we need to save. You need to draw all 3D objects between these functions.
void draw...