使用到 FontLoader跟 TextGeometry
引包
import {TextGeometry} from "three/examples/jsm/geometries/TextGeometry";
import {FontLoader} from "three/examples/jsm/loaders/FontLoader";
使用
const fontLoader = new FontLoader();
fontLoader.load('/static/ziti.json', function (font) {const textMaterial = new THREE.MeshBasicMaterial({color: '#00ff00'});const textGeometry = new TextGeometry('贴图文字', {font: font,size: 80,height: 0.2,curveSegments: 12,bevelEnabled: true,bevelThickness: 0.1,bevelSize: 0.1,bevelOffset: 0,bevelSegments: 5});
})
const mesh123 = new THREE.Mesh(textGeometry, textMaterial);
mesh123.position.x = position.x
mesh123.position.y = position.y
mesh123.position.z = position.z
scene.add(mesh123);
辅助网格(方便定位文字在哪里)
var gridHelper = new THREE.GridHelper(4000, 20, '#00ff00', '#0000ff');
gridHelper.position.set(0, 20, -.1)
gridHelper.visible = true
scene.add(gridHelper);