得到此错误" _this.dispatchEvent不是一个函数"使用trackballcontrols.js,但我不知道为什么

时间:2017-01-23 23:47:58

标签: three.js

以下是我的代码。我按照教程tutorial link进入了" T"关于如何使用trackball.js然而我仍然得到一个错误。这是stackoverflow上唯一一个接近我的问题,TrackballControls.js: this.domElement.addEventListener is not a function但是他的解决方案似乎不是我的解决方案。以下是错误screenshot的屏幕截图。

    <!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <style>
            body {
                background-color: #ffffff;
                margin: 0;
                overflow: hidden;
            }
        </style>
    </head>
    <body>
        <script src="http://cdnjs.cloudflare.com/ajax/libs/three.js/r57/three.min.js"></script>
        <script src="TrackballControls.js"></script>
        <script>

            var camera, controls, scene, renderer;

            init();
            animate();

            function init(){
                camera = new THREE.PerspectiveCamera( 45, window.innerWidth/ window.innerHeight, 1, 1000);
                camera.position.z = 500;

                controls = new THREE.TrackballControls( camera );
                controls.addEventListener('change', render );

                scene = new THREE.Scene();

                var geometry = new THREE.CubeGeometry(100,100,100);
                var material = new THREE.MeshNormalMaterial();
                var mesh = new THREE.Mesh(geometry,material);
                scene.add(mesh);

                renderer = new THREE.WebGLRenderer();
                renderer.setSize(window.innerWidth,window.innerHeight)
                document.body.appendChild(renderer.domElement);
            }

            function animate(){
                requestAnimationFrame( animate );
                controls.update();

            }

            function render(){

                renderer.render( scene, camera );
            }

        </script>
    </body>
</html>

0 个答案:

没有答案