codecamp

three.js FontLoader

一个用于加载JSON格式的字体的类。返回font, 返回值是表示字体的Shape类型的数组。 其内部使用FileLoader来加载文件。

你可以使用facetype.js来在线转换字体。

代码示例

const loader = new FontLoader();
const font = loader.load(
	// 资源URL
	'fonts/helvetiker_bold.typeface.json',

	// onLoad回调
	function ( font ) {
		// do something with the font
		console.log( font );
	},

	// onProgress回调
	function ( xhr ) {
		console.log( (xhr.loaded / xhr.total * 100) + '% loaded' );
	},

	// onError回调
	function ( err ) {
		console.log( 'An error happened' );
	}
);

例子

geometry / text / shapes
geometry / text

构造函数

FontLoader( manager : LoadingManager )

manager — 加载器所使用的loadingManager。默认值为THREE.DefaultLoadingManager.

创建一个新的FontLoader.

属性

共有属性请参见其基类Loader。

方法

共有方法请参见其基类Loader。

.load ( url : String, onLoad : Function, onProgress : Function, onError : Function ) : undefined

url — 文件的URL或者路径,也可以为 Data URI。
onLoad — 将在加载完成时调用。参数是将要被加载的font。
onProgress — 将在加载过程中调用。参数是包含total和loaded字节的XMLHttpRequest实例。如果server没有设置header的Content-Length,则total值为0。
onError — 将在加载错误时调用。

开始加载url,并将加载的font传递给onLoad。

.parse ( json : Object ) : Font

json — 用于解析的JSON>格式的对象。

解析一个JSON>格式的对象,并返回一个font。

examples/jsm/loaders/FontLoader.js


three.js DRACOLoader
three.js GLTFLoader
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

参考

核心 / BufferAttributes

渲染器 / WebXR

开发者参考

WebGL渲染器

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }