Export as DXF

edited December 2017 in Library Questions

Hi, I have some code that I would like to get some DXF exports from. However, every time I press record I get the following message:

RawDXF can only be used with beginRaw(), because it only supports lines and triangles

I'm really not sure what the issue is. The code contains spheres, however, I have used the same code for exporting the DXF on other codes with spheres in the past and had no problem. The code for exporting the DXF is on lines 1-3, 41-43, 88-99.

I've been scratching my head as to why this isn't working and thought I'd ask for some help. Is there anything that needs changing? Or is there a different way of exporting that I could use?

Any help would be much appreciated!

Thanks,

Michael

import processing.dxf.*;
int number = 0;
boolean record; //set boolean for recording the dxf file

import toxi.geom.*;

import peasy.*;
import peasy.org.apache.commons.math.*;
import peasy.org.apache.commons.math.geometry.*;
PeasyCam cam; //use PeasyCam

Branch tree1;
Branch tree2;
Branch tree3;
ArrayList<Node> nodes;


void setup() {

  cam = new PeasyCam (this, width/2);
  cam.setMinimumDistance(20);
  cam.setDistance(200);
  cam.setMaximumDistance(10000);
  size(1000, 700, P3D);

 nodes = new ArrayList<Node>();

  stroke(255, 50);
  tree1 = new Branch(new Vec3D(0, -1, 0), 6, 25+random(15));
  tree1.start = new Vec3D(0, 37.5, 0);

   tree2 = new Branch(new Vec3D(0, -1, 0), 6, 25+random(15));
  tree2.start = new Vec3D(75, 37.5, 0);

   tree3 = new Branch(new Vec3D(0, -1, 0), 6, 25+random(15));
  tree3.start = new Vec3D(-75, 37.5, 0);
}

void draw() {

  if (record) { //if the boolean record is true
    beginRaw(DXF, "output_" + nf(number, 2) +".dxf"); //export a dxf file
  }

  background(0);

  tree1.update();
  tree1.draw();
   tree2.update();
  tree2.draw();
  tree3.update();
  tree3.draw();

  pushMatrix();

  translate(0, 0, 0); //translate at 0,0,0 (the three coordinates being x,y & z)
  noFill(); //set the box to have no fill
  stroke(255); //set the stroke to light grey
  box(75); //draw the box at size 500
  translate(75, 0, 0); //translate at 0,0,0 (the three coordinates being x,y & z)
   box(75); //draw the box at size 500
   translate(-150, 0, 0); //translate at 0,0,0 (the three coordinates being x,y & z)
   box(75); //draw the box at size 500
   popMatrix();


if (keyPressed == true) {
     if(key == CODED){
   if(keyCode == DOWN){


 for (int t = 0; t<nodes.size(); t++) {
    nodes.get(t).draw();
  }
   for (int i = 0; i<nodes.size()-1; i++) {
    for (int c = i+1; c<nodes.size(); c++) {

      float d = sq(nodes.get(c).loc.x - nodes.get(i).loc.x) + sq(nodes.get(c).loc.y - nodes.get(i).loc.y) + sq(nodes.get(c).loc.z - nodes.get(i).loc.z);

      if ( d < pow(45, 2)  ) {
        stroke(255, map(d, 0, pow(100, 2), 100, 0));
        line(nodes.get(c).loc.x, nodes.get(c).loc.y, nodes.get(c).loc.z, nodes.get(i).loc.x, nodes.get(i).loc.y, nodes.get(i).loc.z);
      }
    }
  }
   }}}

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

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

class Branch {
  float spltLength;
  int numChildren = 6;
  float maxAngle = PI/2.5;
  float energy;
boolean grow = false;

  Vec3D start;
  Vec3D end;
  Vec3D direction;
  Branch[] children;

  Branch( Vec3D direction, float energy, float spltLength) {
    this.direction = direction;
    this.energy = energy*spltLength/4.8;
    this.spltLength = spltLength;


  }

  void update() {


    // grow
    float factor = 1 + energy/(5*sq(direction.magnitude()));
    direction = direction.scale(factor);
    end = start.add(direction);

    // if splitLength is reached, create children and update them
    if (direction.magnitude() >= spltLength) {
      energy = 0;   


      nodes.add(new Node(new PVector(end.x, end.y, end.z)));



       //create child-branches if they don't exist
 if (keyPressed == true) {
     if(key == CODED){
   if(keyCode == UP){
      if (children == null) {


        createChildren();
      }    

      for (int i =0; i<children.length; i++) {

        children[i].start = end;
        children[i].update();

      }}
     }}
    }
      }

  void createChildren() {
    children = new Branch[numChildren];
    for (int i = 0; i<numChildren; i++) {


      // this is not so elegant, there may be slick solution for it
      Vec3D axis = new Vec3D();
      boolean isPerpendicular = false;
      // find a perpendicular vector
      while (!isPerpendicular) {
        axis = Vec3D.randomVector() ;
        if (direction.dot(axis)!=0) {
          isPerpendicular = true;
        }
      }
      axis.cross(direction);
      //rotate vector
      Vec3D dir = direction.copy().rotateAroundAxis(axis, random(-maxAngle, maxAngle));
      dir.normalize();
      // calculate energy
      float en = map(abs(dir.angleBetween(direction, true)), 0, maxAngle, energy, 0);
      children[i] = new Branch(dir, this.spltLength/4.8, this.spltLength/1.2);

    }
  }

  void draw() {

       pushMatrix();

      translate(end.x, end.y, end.z);
     sphere(1);
       popMatrix();
    line(start.x, start.y, start.z, end.x, end.y, end.z);
    if (children == null) {
      point(end.x, end.y, end.z);

    }
    else {
      for (int i = 0; i<children.length; i++) {
        children[i].draw();
      }
    }
  }

}

class Node {

  PVector loc; 
  float radius;

  Node(PVector loc_ ) {

    loc = loc_;
    this.radius = 1;
  }

  void draw() {


stroke(30,60,10);
    fill(30,60,10);

    pushMatrix();
    translate(loc.x, loc.y, loc.z);
    sphere(radius);

    popMatrix();
  }
}
Tagged:

Answers

Sign In or Register to comment.