3D Text Library

What you want is the geomerative library by Ricard Marxer.
solid_text

This is sketch I took from open processing, and hacked to get it to work:-

import geomerative.*;

RFont f;
RShape grp;
RExtrudedMesh em;

void setup() {
  size(600, 400, P3D);

  // VERY IMPORTANT: Allways initialize the library in the setup
  RG.init(this);

  //  Load the font file we want to use (the file must be in the data folder in the sketch floder), with the size 60 and the alignment CENTER
  grp = RG.getText("Depth!", "FreeSans.ttf", 50, CENTER);
  
  // Set the polygonizer detail (lower = more details)
  RG.setPolygonizer(RG.UNIFORMLENGTH);
  RG.setPolygonizerLength(1);
  
  // Geomerative's flat mesh
  //RMesh m = grp.toMesh();
  
  // Create an extruded mesh
  em = new RExtrudedMesh(grp, 20);

  // Enable smoothing
  smooth();
}

void draw()
{
  background(100);

  lights();

  translate(width/2, height/2, 200);
  rotateY(millis()/2000.0);

  fill(255, 100, 0);
  noStroke();
  
  // Draw mesh
  em.draw();
}

class RExtrudedMesh
{
  float depth = 10;
  RPoint[][] points;
  RMesh m;
  
  RExtrudedMesh(RShape grp, float d)
  {
    depth = d;
    m = grp.toMesh();
    points = grp.getPointsInPaths();
  }
  
  void draw()
  {
    // Draw front
  for (int i=0; i<m.countStrips(); i++) {
    beginShape(TRIANGLE_STRIP);
    for (int j=0;j<m.strips[i].vertices.length;j++) {
      vertex(m.strips[i].vertices[j].x, m.strips[i].vertices[j].y, 0);
    }
    endShape(CLOSE);
  }

  // Draw back
  for (int i=0; i<m.countStrips(); i++) {
    beginShape(TRIANGLE_STRIP);
    for (int j=0;j<m.strips[i].vertices.length;j++) {
      vertex(m.strips[i].vertices[j].x, m.strips[i].vertices[j].y, -depth);
    }
    endShape(CLOSE);
  }
  
  // Draw side (from outline points)
  for (int i=0; i<points.length; i++) {
    beginShape(TRIANGLE_STRIP);
    for (int j=0; j<points[i].length-1; j++)
    {
      vertex(points[i][j].x, points[i][j].y, 0);
      vertex(points[i][j].x, points[i][j].y, -depth);
      vertex(points[i][j+1].x, points[i][j+1].y, -depth);
      vertex(points[i][j].x, points[i][j].y, 0);
      vertex(points[i][j+1].x, points[i][j+1].y, 0);
    }
    vertex(points[i][0].x, points[i][0].y, 0);
    endShape(CLOSE);
  }
  }
}

You need to supply “FreeSans.ttf” in the data folder for your sketch!

1 Like