博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
three.js 创建文字的几种方法
阅读量:7005 次
发布时间:2019-06-27

本文共 2090 字,大约阅读时间需要 6 分钟。

three.js 创建文字的几种方法

1. DOM + CSS

传统网页html实现

2. 将文字绘制到画布中,并将其用作Texture(纹理)

将文字保存为图片格式,再将其当作一张蒙皮材质,贴到某个物体上

3. 在你所喜欢的3D软件里创建模型,并导出给three.js

建模实现,成本高,效果好

4. three.js自带的文字几何体

  1. 构造器
var loader = new THREE.FontLoader();loader.load( 'fonts/helvetiker_regular.typeface.json', function ( font ) {    var geometry = new THREE.TextGeometry( 'Hello three.js!', {        font: font,        size: 80,        height: 5,        curveSegments: 12,        bevelEnabled: true,        bevelThickness: 10,        bevelSize: 8,        bevelSegments: 5    } );} );

TextGeometry(text : String, parameters : Object)

text — 将要显示的文本。
parameters — 包含有下列参数的对象:

font — THREE.Font的实例。

size — Float。字体大小,默认值为100。

height — Float。挤出文本的厚度。默认值为50。
curveSegments — Integer。(表示文本的)曲线上点的数量。默认值为12。
bevelEnabled — Boolean。是否开启斜角,默认为false。
bevelThickness — Float。文本上斜角的深度,默认值为20。
bevelSize — Float。斜角与原始文本轮廓之间的延伸距离。默认值为8。
bevelSegments — Integer。斜角的分段数。默认值为3。

  1. 可用的字体

文本几何体使用 typeface.json所生成的字体。 一些已有的字体可以在/examples/fonts中找到,且必须在页面中引入。

字体 字重 风格 文件路径
helvetiker normal normal /examples/fonts/helvetiker_regular.typeface.json
helvetiker bold normal /examples/fonts/helvetiker_bold.typeface.json
optimer normal normal /examples/fonts/optimer_regular.typeface.json
optimer bold normal /examples/fonts/optimer_bold.typeface.json
gentilis normal normal /examples/fonts/gentilis_regular.typeface.json
gentilis bold normal /examples/fonts/gentilis_bold.typeface.json
droid sans normal normal /examples/fonts/droid/droid_sans_regular.typeface.json
droid sans bold normal /examples/fonts/droid/droid_sans_bold.typeface.json
droid serif normal normal /examples/fonts/droid/droid_serif_regular.typeface.json
droid serif bold normal /examples/fonts/droid/droid_serif_bold.typeface.json

5. 位图字体

BMFonts (位图字体) 可以将字形批处理为单个BufferGeometry。BMFont的渲染支持自动换行、字母间距、字句调整、signed distance fields with standard derivatives、multi-channel signed distance fields、多纹理字体等特性。 详情请参阅three-bmfont-text。

现有库存的字体在项目中同样可用,就像A-Frame Fonts一样, 或者你也可以从任何TTF字体中创建你自己的字体,优化时,只需要包含项目中所需的字符即可。

这是一些有用的工具:

msdf-bmfont-web (web-based)

msdf-bmfont-xml (commandline)
hiero (desktop app)

转载地址:http://naytl.baihongyu.com/

你可能感兴趣的文章
ASP 未结束的字符串常量
查看>>
五个项目管理学习笔记.沟通技巧II
查看>>
jquery的$.extend和$.fn.extend作用及区别
查看>>
JAVA--继承
查看>>
.NET完全手动搭建三层B/S架构
查看>>
线程安全的单例模式
查看>>
软件项目量化管理(CMMI高成熟度)实践经验谈——之项目管理过程策划篇
查看>>
iOS开发--线程通信
查看>>
写入位置时发生訪问冲突
查看>>
webpack window 处理图片和其他静态文件
查看>>
在windows上搭建C语言开发环境——借助eclipse和MinGW
查看>>
利用javascript跨域访问cookie之广告推广
查看>>
[Machine Learning] Active Learning
查看>>
后台服务器端技术点(前沿了解)
查看>>
The Frog's Games(二分)
查看>>
Android 文件访问权限的四种模式
查看>>
安卓Android科大讯飞语音识别代码使用详解
查看>>
eclipse出现错误:he type java.util.Map$Entry cannot be resolved. It is indirectly referenced
查看>>
Android AbsListView Abs前缀
查看>>
Redis应用场景一
查看>>