Save to SVG with edges visible

Hi,
I’m trying to save a 3D canvas from Processing to SVG.

I found great the use of beginRaw and endRaw. But I don’t understand how to save into the SVG just the edges that are visible.

What I would like is to export to SVG just the edges that are visible (this is what I see in the processing sketch):

But the output to svg is quite different. In fact if I use hint(ENABLE_DEPTH_SORT); just the outlines of the 3d objects are shown (last image).

While if I don’t use that line every edge is shown (middle image).

Here is the code:

import processing.svg.*;


boolean record;

void setup() {
  size(500, 500, P3D);
  //hint(ENABLE_DEPTH_SORT);
}

void draw() {
  if (record) {
    beginRaw(SVG, "output.svg");
  }
  background(204);
  translate(width/2, height/2, -200);
  rotateZ(0.2);
  rotateY(mouseX/500.0);
  stroke(0);
  strokeWeight(4);
  box(200);
  translate(-100,0,0);
  box(100);

  if (record) {
    endRaw();
    record = false;
    exit();
  }
}
void keyPressed() {
  if (key == 'r') {
    record = true;
    
  }
}

I’ve tried different combinations of commands to input into the hint function call without much success (I looked for the available hint parameters into the PConstants file). Any help appreciated!

-a- what you see on canvas is what you get by the default

fill(255);

if you set

noFill();

you see that what a export to SVG uses.

if you want save what you see could use

save("data/output.png");

yes, i also tested little about the hint switches
but not get better results
( i play win7 / processing 3.5.3 )


test-code
import processing.svg.*;

String outfile, outfile0 = "data/output"; 
boolean record;

void setup() {
  size(500, 500, P3D);
  //  hint(ENABLE_DEPTH_SORT);
  //  hint(DISABLE_DEPTH_SORT);   // default
  //  hint(DISABLE_DEPTH_TEST);
  //  hint(ENABLE_DEPTH_TEST);    // default
  //  hint(DISABLE_DEPTH_MASK);
  //  hint(ENABLE_DEPTH_MASK);    // default
}

void draw() {
  if (record) {
    outfile = outfile0 + str(frameCount);
    beginRaw(SVG, outfile+".svg");
  }
  background(204);
  translate(width/2, height/2, -200);
  rotateZ(PI*mouseY/500.0);
  rotateY(PI*mouseX/500.0);
  stroke(0);
  strokeWeight(4);
  //  fill(255);
  //  noFill();
  //  fill(0,0,200);
  box(200);
  translate(-100, 0, 0);
  //  fill(0,200,0);
  box(100);

  if (record) {
    println("save to "+outfile+ " (.svg and .png)");
    endRaw();
    record = false;
    save(outfile+".png");
    //exit();
  }
}

void keyPressed() {
  if (key == 'r') record = true;
}

@kll thanks, but what I need is export to a vector file, so the functions to save to bitmap are quite useless to me.

There must be a way to intercept the vector drawing after the DEPTH passes in the graphic pipeline.

1 Like