Dale
Dale

Reputation: 1628

In Three.js when using the OrbitControls I get an Uncaught TypeError: THREE.OrbitControls is not a constructor when I try to instantiate it

When I go to create an instance of the OrbitControls I end up getting

Uncaught TypeError: THREE.OrbitControls is not a constructor.

enter image description here

My code is very simple however I'm obviously missing something.

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

The version of Three.js I'm using is the one straight off of threejs.org from the examples download directory. Any ideas to what I might be missing?

Thanks for your help.

Upvotes: 1

Views: 3984

Answers (1)

Ramil Kudashev
Ramil Kudashev

Reputation: 1175

THREE.OrbitControls modifies existing THREE global object. So at the time of OrbitControls script execution THREE.js lib should be loaded.

If you are adding scripts in raw HTML make sure that OrbitControls.js is below three.js.

If you are using some sort of bundler, make sure that global THREE variable is set. If you have THREE only as local variable try window.THREE = THREE || {}; before requiring OrbitControls (it looks messy though).

Upvotes: 2

Related Questions