关于three.js: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,因为你加载不到动态资源

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理