Bringing a Geomerative Library 3D Text Sketch Up to Date

There was a question in the forum about creating 3D text in processing, I found this sketch on Open Processing it needed some hacking to get it to work. But I wasn’t happy with the sketch because I hate indexing arrays. Here is my improved version:-

import geomerative.RCommand;
import geomerative.RFont;
import geomerative.RG;
import geomerative.RMesh;
import geomerative.RPoint;
import geomerative.RShape;
import geomerative.RStrip;

RFont f;
RShape grp;
RExtrudedMesh em;

void settings() {
  size(600, 400, P3D);
  smooth();
}

void setup() {
  RG.init(this);
  grp = RG.getText("Depth!", "FreeSans.ttf", 50, CENTER);
  RG.setPolygonizer(RCommand.UNIFORMLENGTH);
  RG.setPolygonizerLength(1);
  em = new RExtrudedMesh(grp);
}

void draw()
{
  background(100);
  lights();
  translate(width / 2, height / 2, 200);
  rotateY(millis()/2000.0);
  fill(255, 100, 0);
  noStroke();
  em.draw();
}



class RExtrudedMesh
{
  float depth = 10;
  RPoint[][] points_array;
  RMesh m;
  RExtrudedMesh(RShape grp, float d)
  {
    depth = d;
    m = grp.toMesh();
    points_array = grp.getPointsInPaths();
  }

  RExtrudedMesh(RShape grp)
  {
    m = grp.toMesh();
    points_array = grp.getPointsInPaths();
  }
  void draw()
  {
    for (RStrip strip : m.strips) {
      beginShape(PConstants.TRIANGLE_STRIP);
      for (RPoint point : strip.vertices){
        vertex(point.x, point.y, depth);
      }
      endShape(PConstants.CLOSE);
    }
    for (RStrip strip : m.strips) {
      beginShape(PConstants.TRIANGLE_STRIP);
      for (RPoint point : strip.vertices){
        vertex(point.x, point.y, -depth);
      }
      endShape(PConstants.CLOSE);
    }
    for (RPoint[] points : points_array) {
      beginShape(PConstants.QUAD_STRIP);
      for (RPoint point : points){
        vertex(point.x, point.y, depth);
        vertex(point.x, point.y, -depth);
      }
      endShape(PConstants.CLOSE);
    }
  }
}

solid_text

4 Likes