Creating a 3D text mesh
In this section, we’ll have a quick look at how you can create 3D text. First, we’ll look at how to render text using the fonts provided by Three.js, and how you can use your own fonts for this. Then, we’ll show a quick example of using an external library called Troika (https://github.com/protectwise/troika) that makes it really easy to create labels and 2D text elements and add them to your scene.
Rendering text
Rendering text in Three.js is very easy. All you have to do is define the font you want to use and use the same extrude properties we saw when we discussed THREE.ExtrudeGeometry
. The following screenshot shows a text-geometry.html
example of how to render text in Three.js:
Figure 6.14 – Rendering text in Three.js
The code required to create this 3D text is as follows:
import { FontLoader } from 'three/examples/jsm/ loaders/FontLoader' import { TextGeometry } from...