Class: FontBuilder

FontBuilder converts text into geometry -- surfaces and curves generated from font characters. All methods are static, so you call them directly on the class without instantiation.

When to use

  • Adding text to 3D models -- place labels, part numbers, or branding on solid faces.
  • Creating signage -- generate extrudable letter outlines for signs or displays.
  • Engraving and embossing -- produce curve and surface geometry that can be used with boolean operations to cut or raise text on solids.

Quick start

import { FontBuilder, Plane } from '@beegraphy/opencascade';

// Load a font from a URL
const font = { url: '/fonts/Roboto-Regular.ttf', setParsedFont: (f) => { font.parsed = f; } };
await FontBuilder.load(font);

// Generate text geometry on a plane
const { surfaces, curves } = FontBuilder.text(
  Plane.XY,   // the plane to place text on
  'Hello',    // the text string
  12,          // font size
  font         // the loaded font object
);

// surfaces: array of Surface shapes for each character
// curves: array of Curve outlines for each character

Key methods

MethodDescription
text(plane, text, size, font)Generate surface and curve shapes from text on a given plane
load(font)Asynchronously load and parse a font from a URL

Static Method: text

Creates a surface and curve shapes representing the rendered text.

Parameters

  • plane (IPlane): The plane on which the text will be placed.
  • text (any): The text to be rendered.
  • size (number): The size of the text.
  • fontWrapper (IFont): The font to be used for rendering the text.

Returns

An object containing the surface and curve shapes of the rendered text.

Example

const plane = /* specify a plane */;
const text = /* specify a text */;
const size = 0.5;
const fontWrapper = /* specify a fontWrapper */;
FontBuilder.text(plane, text, size, fontWrapper);

Static Method: load

Asynchronously loads a font from the provided URL and parses it.

Parameters

  • font (IFont): The font object containing the URL and a method to set the parsed font.

Returns

Promise - void A promise that resolves when the font is loaded and parsed.

Example

const font = /* specify a font */;
FontBuilder.load(font);