3

我很确定我的 JavaScript 代码中有使用 Three.js OrbitControls 所需的一切。我有:

<script>"OrbitControls.js"></script>

并且:

var cameraControls;
cameraControls = new THREE.OrbitControls(camera, renderer.domElement);

它没有抱怨。但我的错误说...

未捕获的类型错误:无法在 public_html/OrbitControls.js:76 读取未定义的属性“LEFT”(21:20:28:855 | 错误,javascript)

它指的是 OrbitControls 文档,其中说:

this.mouseButtons = { ORBIT: THREE.MOUSE.LEFT, ZOOM: THREE.MOUSE.MIDDLE, PAN: THREE.MOUSE.RIGHT };

我不知道如何解决它,任何东西都会非常感激!

4

1 回答 1

2

就像@ryanpcmcquen 在他的评论中已经暗示你缺少THREE.MOUSE对象一样。您也应该加载three.js库以使其工作。

THREE.MOUSE对象在 three.js 库的核心中定义

THREE.MOUSE = { LEFT: 0, MIDDLE: 1, RIGHT: 2 };

更新

Make sure you have a build version of library loaded where the THREE.MOUSE object is defined in the code. I would suggest downloading it from the http://threejs.org/ website.

Both those files have the THREE.MOUSE object.


Note: Also think about the correct loading order of your libraries. You will have to include the three.js script before your OrbitControls.js script.

于 2016-05-11T07:30:08.267 回答