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。
麻省理工学院