Babylon.Font
v4.0.0
使用assemblyscript編寫的WASM生成Babylonjs的文本網格。
例子
與CDN
https://cdn.jsdelivr.net/gh/ycw/babylon.font@ {version }/build/babylon.font.js
或NPM
npm i ycw/babylon.font
npm i ycw/babylon.font#{VERSION_TAG}
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 ) ;
} ) ( ) ;Compiler
// (1) auto-probe .wasm url
await Compiler . Build ( ) ;
// (2) specify .wasm url
await Compiler . Build ( wasmUrl ) ;使用Bundler / Dev Server時,簽名(2)很有用:
// 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)返回Metrics 。 Metrics
.advanceWidth.ascender.descender TextMeshBuilder
構建文本網狀建築商
new TextMeshBuilder ( BABYLON , earcut ) ;
// BABYLON: the 'babylonjs' lib
// earcut: the 'earcut' lib.create(options, scene) :創建擠出的文本網格。Mesh 。null如果沒有創建網格,例如文本都是所有空格。undefined返回 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 ) ;前任。倒退
var mesh = builder . create ( opt1 , scene )
if ( mesh === undefined ) mesh = builder . create ( opt2 , scene ) MAXGRAEY-幫助彙編/WASM優化
OPENTYPEJS-使用JavaScript讀取和編寫OpenType字體。
耳塞 - 您的WebGL應用程序最快,最小,最小的JavaScript多邊形三角庫庫
Babylonjs-一個強大,美麗,簡單且開放的遊戲和渲染引擎裝在一個友好的JavaScript框架中。
彙編 - 使用Binaryen編譯一個嚴格的打字稿(基本上是JavaScript的類型JavaScript),以WebAssembly。
麻省理工學院