All Projects → ycw → Babylon.Font

ycw / Babylon.Font

Licence: MIT License
Generate text mesh for BabylonJS using WASM, written in AssemblyScript.

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Babylon.Font

Lucet
Lucet, the Sandboxing WebAssembly Compiler.
Stars: ✭ 4,006 (+18109.09%)
Mutual labels:  webassembly, assemblyscript
Lunatic
Lunatic is an Erlang-inspired runtime for WebAssembly
Stars: ✭ 2,074 (+9327.27%)
Mutual labels:  webassembly, assemblyscript
Assemblyscript
A TypeScript-like language for WebAssembly.
Stars: ✭ 13,152 (+59681.82%)
Mutual labels:  webassembly, assemblyscript
fontfacegen-webpack-plugin
A plugin for webpack that allows you to convert .ttf and .otf files into various other font formats such as .eot, .ttf, .svg, .woff and .woff2 using the existing NPM package fontfacegen.
Stars: ✭ 20 (-9.09%)
Mutual labels:  font
rana-kufi
Rana Kufi (كوفي رنا) is a Fatimid Kufic typeface
Stars: ✭ 25 (+13.64%)
Mutual labels:  font
go-wasm-examples
Some small examples of using Go and WebAssembly
Stars: ✭ 22 (+0%)
Mutual labels:  webassembly
holyc
An easy to use C++ to WASM compiler (Highly-experimental)
Stars: ✭ 33 (+50%)
Mutual labels:  webassembly
svg-fixer
Converts SVG Strokes To Fill.
Stars: ✭ 59 (+168.18%)
Mutual labels:  font
rustexp
A Rust regular expression editor and tester that runs entirely within the browser!
Stars: ✭ 59 (+168.18%)
Mutual labels:  webassembly
kotlin-gradle-templates
Quick start kotlin gradle DSL
Stars: ✭ 50 (+127.27%)
Mutual labels:  webassembly
pygame-text-input
a small module that enables you to input text with your keyboard using pygame
Stars: ✭ 114 (+418.18%)
Mutual labels:  font
fontless
🚀🔒 Host your own Google Fonts.
Stars: ✭ 63 (+186.36%)
Mutual labels:  font
ricardo-forth
Forth dialect implemented in C, Javascript, WebAssembly and compiled from C to asm.js and WebAssembly.
Stars: ✭ 26 (+18.18%)
Mutual labels:  webassembly
hoard-of-bitfonts
turns out I like bitmap fonts
Stars: ✭ 811 (+3586.36%)
Mutual labels:  font
krustlet-wasmcloud-provider
Kubernetes Rust Kubelet provider for wasmCloud
Stars: ✭ 15 (-31.82%)
Mutual labels:  webassembly
warpy
WebAssembly interpreter in RPython
Stars: ✭ 54 (+145.45%)
Mutual labels:  webassembly
awesome-swiftwasm
A community-driven curated list of SwiftWasm projects and content
Stars: ✭ 117 (+431.82%)
Mutual labels:  webassembly
SdfFontDesigner
Offline font tuning/bitmap generation via shaders
Stars: ✭ 56 (+154.55%)
Mutual labels:  font
rapid-arrows-font
OTF comic font
Stars: ✭ 30 (+36.36%)
Mutual labels:  font
libOpenDRIVE
Small, lightweight C++ library for handling OpenDRIVE files
Stars: ✭ 104 (+372.73%)
Mutual labels:  webassembly

About

Generate text mesh for babylonjs using WASM, written in AssemblyScript.

Example

Installation

With cdn

https://cdn.jsdelivr.net/gh/ycw/babylon.font@{VERSION}/build/babylon.font.js

or npm

npm i ycw/babylon.font
npm i ycw/babylon.font#{VERSION_TAG}

Usage

import * as BABYLON from "babylonjs"
import * as opentype from "opentype.js"
import earcut from "earcut"
import { Compiler, Font, TextMeshBuilder } from "babylon.font";

(async function() {
  const compiler = await Compiler.Build();
  const font = await Font.Install("a.ttf", compiler, opentype);
  const builder = new TextMeshBuilder(BABYLON, earcut);
  const scene = ..;
  const mesh = builder.create({ font, text: "foo" }, scene);
})();

Docs

Compiler

// (1) auto-probe .wasm url
await Compiler.Build();

// (2) specify .wasm url
await Compiler.Build(wasmUrl);

The signature(2) is useful when using bundler / dev server :

// ex. obtain static asset url for ViteJS/Vite
import wasmUrl from "babylon.font/build/optimized.wasm?url";
const compiler = await Compiler.Build(wasmUrl);

Font

await Font.Install(fontUrl, compiler, opentype);
// fontUrl:  font(.otf/.ttf) url
// compiler: a Compiler instance
// opentype: the 'opentype.js' lib
  • .measure(text, fontSize) : measure text; return a Metrics.

Metrics

  • .advanceWidth
  • .ascender
  • .descender

TextMeshBuilder

Construct a text mesh builder

new TextMeshBuilder(BABYLON, earcut);
// BABYLON: the 'babylonjs' lib
// earcut: the 'earcut' lib
  • .create(options, scene) : create extruded text mesh.

Ex.

builder.create({
  font, // Font instance
  text, // text
  size, // font size; default is 100
  ppc, // points per curve, [0, 255], default is 2
  eps, // decimation threshold, default is 0.001

  // plus `BABYLON.MeshBuilder.CreatePolygon` options
  depth,
  sideOrientation,
  faceColors,
  faceUV,
  backUVs,
  frontUVs,
  updatable,
}, scene);

Thanks

MaxGraey - Helps with AssemblyScript/WASM optimizations

OpentypeJS - Read and write OpenType fonts using JavaScript.

Earcut - The fastest and smallest JavaScript polygon triangulation library for your WebGL apps

BabylonJS - A powerful, beautiful, simple, and open game and rendering engine packed into a friendly JavaScript framework.

AssemblyScript - Compiles a strict subset of TypeScript (basically JavaScript with types) to WebAssembly using Binaryen.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].