To create vectors from 3D data, use the beginRaw() and endRaw() commands. These commands will grab the shape data just before it is rendered to the screen. At this stage, your entire scene is nothing but a long list of lines and triangles. This means that a shape created with sphere() method will be made up of hundreds of triangles, rather than a single object.
When using beginRaw() and endRaw(), it’s possible to write to either a 2D or 3D renderer. For instance, beginRaw() with the PDF library will write the geometry as flattened triangles and lines.
As per the examples in the library reference you need to do all the drawing between beginRaw() and endRaw().
In your code you are drawing in setup() before beginRaw().
You have a function inside the draw() loop; this should be outside of draw() loop and called within the draw() loop.
You will need to also correct your opening and closing brackets in your code; there are a few errors for you to correct.
Here is a simple working example:
import processing.pdf.*;
boolean record;
int seed;
void setup()
{
size(400, 400, P3D);
noLoop();
}
//******************************************
void draw()
{
if (record)
{
beginRaw(PDF, "output.pdf");
}
randomSeed(seed);
// Do all your drawing here This could be a function call!
background(204);
stroke(0);
fill(0, 255, 0);
for(int i=0; i<200; i++)
{
push();
translate(random(width), random(height), -100);
circle(0, 0, 30);
pop();
}
if (record)
{
endRaw();
record = false;
}
}
//******************************************
// Hit 'r' to record a single frame
void keyPressed()
{
if (key == 'r')
{
record = true;
redraw();
}
if (key == 's')
{
seed = int(random(0, 2000));
redraw();
}
}
I generated a randomSeed() so I could capture what was generated in the current sketch window.
Hi @glv, I am still having issues with the PDF exporting P3D processing files… the PDF files have a white background instead of black, but I can see an off-white rendering of the image wireframe… how do I change this back to black?
Hi @glv, so I figured out an alternative way to go about putting the background back after converting my P3D Processing sketch to a PDF file. That alternative way is to add a background layer in Photoshop because the image turns into a vector image with a transparent background when you export your P3D file to a PDF. This way I can get the high resolution vector lines!