【问题标题】:Attempted import error: 'OBJLoader' is not exported from 'three' (imported as 'THREE')尝试导入错误:“OBJLoader”未从“三”导出(导入为“三”)
【发布时间】:2021-03-08 02:48:21
【问题描述】:

当我尝试运行 OBJLoader 时,它给出了错误。尝试导入错误:“OBJLoader”未从“三”导出(导入为“三”)。

     import * as THREE from "three";
     import OBJLoader from "three-obj-loader";
     OBJLoader(THREE);

         const scene = new THREE.Scene();
            const camera = new THREE.PerspectiveCamera(
              75,
              window.innerWidth / window.innerHeight,
              0.1,
              1000
            );
        
            const renderer = new THREE.WebGLRenderer({ antialias: true });
            renderer.setSize(window.innerWidth, window.innerHeight);
            this.mount.appendChild(renderer.domElement);
        
           const loader = new OBJLoader();

            loader.load(
              "model/Room.obj",
              function (object) {
                scene.add(object);
              },
              function (xhr) {
                console.log((xhr.loaded / xhr.total) * 100 + "% loaded");
              },
              function (error) {
                console.log("An error happened");
              }
            );

【问题讨论】:

    标签: reactjs animation three.js


    【解决方案1】:

    请像这样导入OBJLoader

    import { OBJLoader } from 'three/examples/jsm/loaders/OBJLoader.js';
    

    three-obj-loader 的使用不是必需的。所有示例文件都作为模块在three npm 包中提供。

    【讨论】:

    • 当我运行它时没有给出输出并显示此错误 index.js:1 SyntaxError: Unexpected token ) at GLTFLoader.parse (GLTFLoader.parse) js:281) 在 Object.onLoad (GLTFLoader.js:174) 在 XMLHttpRequest. (three.module.js:36513)
    • 此错误表明您的服务器未正确提供 JS 文件。请用谷歌搜索这个,应该有多个关于这个问题的线程。
    • Infinity% 加载了 OBJLoader.js:716 THREE.OBJLoader: Unexpected line: "" parse @ OBJLoader.js:716 (anonymous) @ OBJLoader.js:455 (anonymous) @三.module.js:36513
    • 看起来同样的问题。加载器没有从服务器接收到正确的 OBJ 文件,而是一个 HTML 文档。
    • three.min.js:2 THREE.Object3D.add:对象不是 THREE.Object3D 的实例
    猜你喜欢
    • 2022-11-16
    • 2021-02-13
    • 2021-04-08
    • 1970-01-01
    • 2021-06-27
    • 2021-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多