1

I'm trying to add OrbitControls in my three.js project, but when I try to call the constructor it gives an uncaught type error "THREE.OrbitControls is not a constructor". I have searched for a solution, but the only thing I can find is explicitly importing the file. But when I do, it still gives the error. This is my code:

    <script src="JS/three.js"></script>
    <scirpt src="JS/OrbitControls.js"></scirpt>
    <script src="JS/Models/ModelLoader.js"></script>

    <script>

        var scene = new THREE.Scene( );
        var camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 0.01, 10000 );

        var renderer = new THREE.WebGLRenderer( );
        renderer.setSize( window.innerWidth, window.innerHeight );

        document.body.appendChild( renderer.domElement );

        camera.position.z = 3;
        var controls = new THREE.OrbitControls(camera, renderer.domElement);//here is the problem

        var pointLight = new THREE.PointLight(0,2);
        pointLight.position.z = 2;
        scene.add(pointLight);

        // Game Logic
        var update = function( ){



        }

        // Draw Scene
        var render = function( ){

            renderer.render( scene, camera );

        }

        var testLoad = function(){

            var modelLoader = new ModelLoader();
            var obj = modelLoader.loadObj("/Res/Models/Characters/char1.obj", "/Res/Models/Characters/char1.mtl");
            scene.add(obj);

        }

        // Main Game Loop(update, render, repeat)
        var gameLoop = function( ){

            requestAnimationFrame( gameLoop );

            update( );
            render( );

        }

        gameLoop();

The ModelLoader is a custom class for loading obj files.

Anyone that knows what I've done wrong? Thanks in advance!

1 Answer 1

2

You have a typo:

<scirpt src="JS/OrbitControls.js"></scirpt>

should be

<script src="JS/OrbitControls.js"></script>
Sign up to request clarification or add additional context in comments.

4 Comments

lord i was staring at this for like 10 seconds. Yeah, you write scripts with javaSCRIPT.
Well........... I'm blind....... Thanks! (I will accept your answer in a few minutes)
@pailhead yeah I'm blind I guess
when i use <script src="JS/OrbitControls.js"></script>, i get "Cannot use import statement outside a module". dou you have any idea?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.