三。FontLoader() 在 Three JS 中不起作用



我是Three JS的新手,我想创建一个3D文本。我遵循了教程的大部分内容来创建它,但即使我遵循了所有步骤或复制/通过了教程的代码,我也会出现错误。这是我的组件:

import * as THREE from "three";
import bumped from "../Bumped.json";
const Text = () => {
const font = new THREE.FontLoader().parse(bumped);
const textOptions = {
font,
size: 5,
height: 1,
};
return (
<mesh>
<textGeometry attach="geometry" args={["three.js", textOptions]} />
<meshStandardMaterial attach="material" />
</mesh>
);
};
export default Text;

我的错误://THREE.FontLoader已移至/examples/jsm/loaders/FontLoader.js

//未捕获的类型错误:(中间值(。解析不是函数

当然,这个组件将位于主页面的Canvas元素中。我的控制台错误:我的控制台错误

该错误意味着FontLoaderr133以来不再是核心库的一部分。您需要额外导入才能在应用程序中使用此加载程序。试试:

import { FontLoader } from 'three/examples/jsm/loaders/FontLoader.js';

请注意,现在使用的FontLoader没有THREE名称空间。

最新更新