Three Font Outliner Save

Constructing shapes from glyphs at runtime for three.js.

Project README

About

Constructing shapes from glyphs at runtime for three.js.

Examples

Installation

Via npm: ( npm i ycw/three-font-outliner#v2.0.0 )

import { FontOutliner } from "three-font-outliner"

Via cdn:

import { FontOutliner } from "https://cdn.jsdelivr.net/gh/ycw/[email protected]/dist/lib.esm.js"

Usage

// Ex. Show text "Shapes" using font "aqua.ttf".
const outliner = await FontOutliner.fromUrl(THREE, "./aqua.ttf");
const { shapes } = outliner.outline("Shapes");
scene.add(new THREE.Mesh(
    new THREE.ShapeBufferGeometry(shapes, 16).center(),
    new THREE.MeshBasicMaterial({ color: "blue", side: THREE.DoubleSide })
));

Live result: Shapes

Docs

Make a font outliner:

// Method 1: Load from `Arraybuffer` holding the font file.
const outliner = new FontOutliner(THREE, arrayBuffer);

// Method 2: Load from url. (async)
const outliner = await FontOutliner.fromUrl(THREE, fontUrl);

Then, outline glyph:

const result = outliner.outline("hello");

result.shapes; // Array of `THREE.Shape`
result.h; // Line height
result.w; // Advance width
result.yMin; // Bottom (usually a negative value)
result.yMax; // Top

.outline() accepts optional options:

const result = outliner.outline("hello", {
  size: 100, // Font size. Default 100,
  isLTR: true, // Is left-to-right writing mode? Default true.
  isCCW: false, // Is solid shape using CCW winding? Default false.
});

Check if certain glyph exists by unicode code point:

const codePoint = 65;
outliner.hasGlyph(codePoint); // return true / false

Credits

License

MIT

Open Source Agenda is not affiliated with "Three Font Outliner" Project. README Source: ycw/three-font-outliner
Stars
63
Open Issues
0
Last Commit
3 years ago
License
MIT

Open Source Agenda Badge

Open Source Agenda Rating