[英]app.js:63 Uncaught ReferenceError: GLTFLoader is not defined
When i call this in three.js const loader = new GLTFLoader();当我在 three.js 中调用它时 const loader = new GLTFLoader(); get this error app.js:63 Uncaught ReferenceError: GLTFLoader is not defined.得到这个错误 app.js:63 Uncaught ReferenceError: GLTFLoader is not defined。 it is import in index.html.but got that error它是索引中的导入。html。但是得到了那个错误
<script src="./three.min.js"></script>
<script src="./OBJLoader.js"></script>
<script src="./GLTFLoader.js"></script>
<script src="./app.js"></script>
A code like const loader = new GLTFLoader();
像const loader = new GLTFLoader();
这样的代码only works if you import GLTFLoader
as an ES6 module via import
statement.仅当您通过import
语句将GLTFLoader
作为 ES6 模块导入时才有效。 When doing so, GLTFLoader
is no part of the THREE
namespace.这样做时, GLTFLoader
不是THREE
命名空间的一部分。
Since you are using three.min.js
, you are not using a module based workflow but global scripts.由于您使用的是three.min.js
,因此您使用的不是基于模块的工作流,而是全局脚本。 That means GLTFLoader
is only available under the THREE
namespace.这意味着GLTFLoader
仅在THREE
命名空间下可用。 So changing your code to the following should fix the issue:因此,将您的代码更改为以下内容应该可以解决问题:
const loader = new THREE.GLTFLoader();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.