javascript - Vue JS,GLTF 加载器错误 "currently no loaders are configured"

标签 javascript vue.js webpack three.js gltf

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

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();

我不断收到错误

./src/assets/tshirt/gitF/tshirt.glb 1:4
Module parse failed: Unexpected character '' (1:4)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
(Source code omitted for this binary file)

我在这里做错了什么? PS:我对 VUE 和 Three.js 都很陌生。我已经在没有框架的情况下尝试过这个确切的代码并且它有效。仅当代码在 VUE 中运行时才会出现该错误。

最佳答案

您在加载调用中不需要 require(),并且您的函数括号未正确关闭:

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

关于javascript - Vue JS,GLTF 加载器错误 "currently no loaders are configured",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60199419/

相关文章:

javascript - Sequelize — 如何获取关联模型?

javascript - 背景颜色到CSS中的透明背景图像

javascript - 如何将常规 javascript 文件集成到我的 vue.js 页面中?

javascript - Vue.js Avoriaz 单元测试在使用 vue-i18n 时产生翻译警告

网页包 4 : content hash filename?

reactjs - WebPack 禁用 HMR

javascript - 初始时只有一个字段的字段数组

javascript - 指数值的 JSON 解析为何以及如何在 Javascript 中给出数字?

json - 使用VueJs 在Axios 中,当responseType 为blob 时,如何读取http 错误?

node.js - Gulp + Webpack 还是只是 Webpack?