three.js加载模型时报错:THREE.GLTFLoader: No DRACOLoader instance provided.

143 阅读1分钟

原因:模型是被压缩过的,需要用到DRACOLoader。

解决: 1.找到draco文件夹:node_modules/three/examples/jsm/libs/draco。

2.将文件夹复制到public文件夹下。

3.代码

import { DRACOLoader } from 'three/addons/loaders/DRACOLoader.js';

const dracoLoader = new DRACOLoader();

dracoLoader.setDecoderPath( './draco/' );

dracoLoader.setDecoderConfig({ type: 'js' })

const loader = new GLTFLoader();

loader.setDRACOLoader( dracoLoader );

loader.load( '/gltf_file/1F.glb', function ( gltf ) {

scene.add( gltf.scene );

})