Three.js装载机

时间:2016-08-27 13:24:50

标签: javascript web three.js loader

我从threejs.org获得了包文件three.js-dev,我试图这样使用:

<script type="text/javascript" src="./build/three.js"></script>

<script type="text/javascript" src="./src/loaders/JSONLoader.js"></script>

<script src="./examples/js/controls/TrackballControls.js"></script>
<script src="./examples/js/Detector.js"></script>

但是我在控制台出错:

  

JSONLoader.js:1 Uncaught SyntaxError: Unexpected token import

源标签页上的其他错误。

  

Uncaught SyntaxError: Unexpected token import

我想,'javascript import'有问题吗?

所以我搜索了它,found this at the MDN我将'./Loader'替换为"./Loader",但错误仍然存​​在。

是否有人对此问题有惊人的智慧?救命啊!

1 个答案:

答案 0 :(得分:1)

您正在引用JSONLoader的来源。这是使用模块模式(这是import令牌的用途)在ES6中编写的,它被捆绑到您已经引用的build/three.js中。问题出现了,因为无法在浏览器中使用模块(.yet)。

简单地说,您不需要引用/src/loaders/JSONLoader.js,默认情况下包含JSONLoader。

见这里: http://threejs.org/docs/index.html?q=json#Reference/Loaders/JSONLoader