Vue JS,GLTF加载程序错误“当前未配置任何加载程序”

时间:2020-02-13 01:57:57

标签: javascript vue.js webpack three.js gltf

我正在尝试将gltf加载到vue项目中。这是我的代码

requests

我不断收到错误

import * as THREE from 'three'
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader';

let scene,camera,renderer;

function init(){

    scene = new THREE.Scene();
    scene.background = new THREE.Color(0xdddddd);

    camera = new THREE.PerspectiveCamera(40,window.innerWidth/window.innerHeight,1,5000);


    renderer = new THREE.WebGLRenderer();
    renderer.setSize(window.innerWidth,window.innerHeight);
    document.body.appendChild(renderer.domElement);


    let loader = new GLTFLoader();

    loader.load(require('../../assets/tshirt/gitF/tshirt.glb'),function(gltf){
        //some code here 
}

init();

我在这里做错了什么? PS:我是VUE和Three.js的新手。我已经尝试了没有框架的确切代码,并且可以正常工作。仅当代码在VUE中运行时,才会发生错误。

1 个答案:

答案 0 :(得分:0)

在装入调用中不需要require(),并且函数括号不能正确关闭:

init() {
    //...
    loader.load('../../assets/tshirt/gitF/tshirt.glb',function(gltf){
            //some code here 
    }
}