三维文字在许多场景中很常见,而THREE.js也为我们封装了TextGeometry
类来更好(容易)地生成三维文字。
先来看看官网的介绍:
TextGeometry
A class for generating text as a single geometry. It is constructed by providing a string of text, and a hash of parameters consisting of a loaded Font and settings for the geometry’s parent ExtrudeGeometry.
可以看到,THREE.js通过把文字设成Geometry
类来创建三维文字,而查看源码可知,它是通过ExtrudeGeometry
类来实现的。
ExtrudeBufferGeometry.call( this, shapes, parameters );
TextBufferGeometry.prototype = Object.create( ExtrudeBufferGeometry.prototype );
构造函数
TextGeometry(text : String, parameters : Object)
参数说明:
text
— The text that needs to be shown. (要显示的字符串)parameters
— Object that can contains the following parameters.font
— an instance of THREE.Font.(字体格式)size
— Float. Size of the text. Default is 100.(字体大小)height
— Float. Thickness to extrude text. Default is 50.(字体的深度)curveSegments
— Integer. Number of points on the curves. Default is 12.(曲线控制点数)bevelEnabled
— Boolean. Turn on bevel. Default is False.(斜角)</