Trouble exporting 3D animation to SVG

This is awesome! I didn’t realize that Processing can do this! Ignore what I said before.

I ran through your script, which I managed to get working. I’ve changed a few things:

  1. A tiles value of 100 is too demanding for the computer I’m on right now, so I reduced this to 10.

  2. I’ve shuffled the nesting of your statements a bit – the final if statement isn’t nested within a for loop anymore.

  3. On my (Linux) computer, I have to add the settings() function (at the top of the sketch) to get 3D Processing working properly. I don’t think you need to do this, but just maybe this is part of the solution.

void settings() { 
  System.setProperty("jogl.disable.openglcore", "false");
  size(900, 900, P3D);
}

PImage img;
import processing.svg.*;
boolean record;

void setup() {
  //size(900, 900, P3D);
  img = loadImage("art.png");
  img.resize(900, 900);
}

void draw() {
  
  if (record) {
    beginRaw(SVG, "output.svg");
  }
  
  background(#f1f1f1);
  fill(0);
  noStroke();
  sphereDetail(3);
  float tiles = 10;
  float tileSize = width/tiles;
  push();
  translate(width/2,height/2);
  rotateY(radians(frameCount));
  
  for (int x = 0; x < tiles; x++) {
    
    for (int y = 0; y < tiles; y++) {
      color c = img.get(int(x*tileSize),int(y*tileSize));
      float b = map(brightness(c),0,255,1,0);
      float z = map(b,0,1,-150,150);
      push();
      translate(x*tileSize - width/2, y*tileSize - height/2, z);
      sphere(tileSize*b*0.4);
      pop();
    }
  }

  pop();
      
  if (record) {
    endRaw();
    record = false;
  }
}

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