Exporting 3d points

edited January 2014 in Library Questions

I’m new to processing and I have a question about exporting points. I wrote a code which produces multiple points in a 3 dimensional space. When generating and exporting points in a 2 dimensional flat the PDF-library works fine, but when exporting 3 dimensions using the DXF, I get an error saying it only supports lines and triangles. The OBJ library also doesn’t work. How can I export 3 dimensional points?

Tagged:

Answers

  • One way to export the points is to simply write out the coordinates into a file. The exported coordinates can then be used in other programs like cinema or blender. the obj file format is pretty simple, see wikipedia for reference.

    here a simple sketch that generates some points and writes them to an obj on mouse click.

    ArrayList<PVector> points = new ArrayList<PVector>();
    int numPoints = 300;
    boolean save = false;
    void setup(){
      size(200,200,OPENGL);
      generate();
    }
    
    void draw(){
      background(0);
      stroke(255);
      fill(255);
      for(PVector v:points){
        point(v.x,v.y,v.z);
      }
      if(save){
        save = false;
        writeOBJ();
      }
    }
    
    void writeOBJ(){
      try{
        PrintWriter writer = new PrintWriter(sketchPath("points.obj"), "UTF-8");
        for(PVector v:points){
          writer.printf("v %f %f %f\n",v.x,v.y,v.z);
        }
        writer.close();
        println("saved");
      }catch(Exception e){
        println(e);
      }
    }
    
    void generate(){
      points.clear();
      for(int i = 0;i<numPoints;i++){
        float x = randomGaussian()*width;
        float y = random(width);
        float z = (float) Math.random()*width/2;
        points.add(new PVector(x,y,z));
      }
    }
    
    void mouseClicked(){
      save = true;
    }
    
Sign In or Register to comment.