加载obj过程请参考如下两篇
【threejs基础:使用OBJLoader】加载obj模型
【threejs基础:使用MTLLoader】加载材质OBj模型
1 加载gltf模型
效果如下:
第一步:引入GLTFLoader
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader'
第二步:加载模型
加载模型部分代码很简单;创建加载器、设置gltf文件路径、开始加载文件、添加到scene;代码如下
const loader = new GLTFLoader()
loader.setPath('./statics/models/gltf/');
loader.load('mount.gltf', function (gltf) {
gltf.scene.traverse(function (child) {
if (child.isMesh) {}
});
scene.add(gltf.scene);
})
gltf模型可以自行在网络下载