3D Text Library

Hello all, I’m relatively new to Processing but I’m loving working with it, so thanks in advance for the help!

In short I’m looking for a library that will allow me to create 3D text with depth (not just rotate 2D text in 3D space) in much the same way that Processing allow text to be drawn. I’ve been searching for a couple days and so far I found a Java library that is deprecated, and some libraries for extrusion, but nothing as simple as a text method with a depth parameter. Tbh some of the extrusion example are over my head since I’m still very new to programming.

I figured I’d pose it to the forum and see if any of you know something that might help. I’m on Mac OS btw.

Thanks!

1 Like

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

Can you please post a link the original source please?

Original as requested https://www.openprocessing.org/sketch/92050/#

2 Likes

@monkstone just getting to look through this now… thanks for the recommendation! This looks great. I know I came across this library initially, but for some reason I thought it wouldn’t be able to handle text this well.

Thanks!