Skip to content

Commit

Permalink
add use case; fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
ycw committed Sep 22, 2021
1 parent 4827317 commit 7c95818
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,9 @@ 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);
})();
Expand All @@ -41,44 +39,55 @@ import { Compiler, Font, TextMeshBuilder } from "babylon.font";
`Compiler`

```js
// construct a 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 :

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



---
`Font`

Load font from url

```js
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{}
- `.measure(text, fontSize)` : measure text; return a `Metrics`.

`Metrics`
`Metrics`

- `.advanceWidth`
- `.ascender`
- `.descender`



---
`TextMeshBuilder`

Construct a text mesh builder

```js
// construct a builder
new TextMeshBuilder(BABYLON, earcut);
// BABYLON: the 'babylonjs' lib
// earcut: the 'earcut' lib
```

- `.create(options, scene)` : create extruded mesh.
- `.create(options, scene)` : create extruded text mesh.

Ex.

Expand All @@ -91,11 +100,18 @@ builder.create({
eps, // decimation threshold, default is 0.001

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



# Thanks

[MaxGraey](https://github.com/MaxGraey) - Helps with AssemblyScript/WASM
Expand Down

0 comments on commit 7c95818

Please sign in to comment.