Differential line growth: make it real

differential line growth

How to export the differential line growth sketch from Processing to Blender for digital fabrication.

After seeing how to implement the differential line growth algorithm with Processing, today we will find out how to export the beautiful shapes created in order to get a nice 3D model for fabrication.

As usual, you will find all the code on GitHub. Let’s look at the few changes that we did in our software.

 

Export from Processing

The idea is to export the line in dxf format, so that we can manipulate it and extrude it later on in a 3D software.

For this purpose we wrote, inside of our DifferentialLine class, a new method called exportDXF().

void exportDXF() {
  String export_name = day()+""+hour()+""+minute()+""+second();
  PGraphics pg = createGraphics(1280, 720, DXF, export_name+".dxf");
  pg.beginDraw();
  for (int i=0; i<nodes.size()-1; i++) {
    PVector p1 = nodes.get(i).position;
    PVector p2 = nodes.get(i+1).position;
    pg.line(p1.x, p1.y, p2.x, p2.y);
    if (i==nodes.size()-2) {
      pg.line(p2.x, p2.y, nodes.get(0).position.x, nodes.get(0).position.y);
    }
  }
  pg.endDraw();
  pg.endRaw();

  renderAsLine();
  exportPNG(export_name);
}

 

As you can see, it simply redraw the shape inside a PGraphics object that is then exported into dxf. Pretty simple (just remember to import processing.dxf.*;).

You can call this method inside of draw() but, in order to avoid the rendering time when this is not necessary, I wrote also another method called blindRun()blindRun() grows the shape inside of setup() (you only need to specify for how many iterations the algorithm has to run), so that the shape can later be exported directly from there.

void blindRun(int iterations) { // For exporting without rendering
  for (int i=0; i<iterations; i++) {
    float progress = (i / (float)iterations) * 100;
    if (progress%5 == 0) {
      println(progress + "%...");
    }
    run();
  }
  println("Done.\n\n");
}

 

This would be the simplest solution. Anyway if, like me, you will have problems importing the dxf inside Blender, you can  try another approach by exporting to obj instead of dxf thanks to the Nervous System’s library OBJExport. It works basically the same as DXF export:

import nervoussystem.obj.*;

//[...]
  
void exportOBJ() {
    String export_name = day()+""+hour()+""+minute()+""+second();
    OBJExport obj = (OBJExport) createGraphics(1280, 720, "nervoussystem.obj.OBJExport", export_name+".obj");
    obj.beginDraw();
    obj.beginShape();
    for (int i=0; i<nodes.size(); i++) {
      PVector p1 = nodes.get(i).position;
      obj.vertex(p1.x, p1.y);
    }
    obj.endShape();
    obj.endDraw();
    obj.dispose();

    renderAsLine();
    exportPNG(export_name);
}

 

Extrude in Blender

Once you have your dxf/obj file you can go to Blender and import it to the scene. If you see the file in the Outliner but not in the 3D View, it might be somewhere far away in the 3D space. Don’t worry and use this sequence of commands, after selecting the object in the Outliner: SHIFT + C to bring the 3D cursor to the origin of the axis; SHIFT + CTRL + ALT + C –> Origin to Geometry; SHIFT + S –> Selection to Cursor; Scale and rotate the shape if needed. Apply the transformations by pressing CTRL + A –> Rotation & Scale.

If your shape is not already filled, you can do it in Edit Mode by selecting all the edges and pressing F. Now press E in order to extrude as much as you want.

differential line growth

If you are already happy with the result you can export it to STL, however I would like to get a slightly smoother result. So let’s add a Smooth modifier! We will apply it only on the X and Y axis. Modify the Factor and increase the number of Repeat.

differential line growth

 

Now I’m happy! Save, export to STL and we are ready for fabrication. Done 😉

 

differential line growth

 

P.s. Following the already mentioned Entagma’s tutorial, I have found a way to get more interesting patterns for our line, and not only circular ones. The idea is to change the _maxForce parameter in the nodes according their position and a 2D Perlin noise field. You can get quite cool results 😉

void differentiate() {

  updateMaxForceByPosition();

  PVector[] separationForces = getSeparationForces();
  PVector[] cohesionForces = getEdgeCohesionForces();

  for (int i=0; i<nodes.size(); i++) {
    PVector separation = separationForces[i];
    PVector cohesion = cohesionForces[i];

    separation.mult(separationCohesionRation);

    nodes.get(i).applyForce(separation);
    nodes.get(i).applyForce(cohesion);
    nodes.get(i).update();
  }
}

void updateMaxForceByPosition() {
  if (!Float.isNaN(maxForceNoise)) {
    for (int i=0; i<nodes.size(); i++) {
      float new_max_force = noise(nodes.get(i).position.x/10, nodes.get(i).position.y/10) * maxForceNoise;
      nodes.get(i).maxForce = new_max_force;
    }
  }
}

differential line growth

3 comments

    1. Hi julien, if you mean differential line, just use 3D vectors instead of 2D ones, tweak the parameters and export in the same way using 3D vertices. If you want more details I could write a short article about it. Otherwise in 3D you could do differential mesh, which give much more spectacular results, but I haven’t experimented with it yet.

Leave a Reply