vue使用threejs加载glb或者gltf模型,以及踩坑
文章目录
需要在组件内引入下列的东西
import * as THREE from 'three'
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls'
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader'创建scene
this.scene = new THREE.Scene()然后引入模型
const loader = new GLTFLoader()
loader.load(
'/glb/aaa.glb',
gltf => {
this.scene.add(gltf.scene)
},
undefined,
undefined
)文件路径
提示:千万别写public/glb/aaa.glb
不然会报这个错unexpected token < in json at position 0,因为你加载不到静态资源
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论