Three.js - TypeError: _eye.subVectors is not a function

I am trying to render from the following tutorial ( https://aerotwist.com/tutorials/creating-particles-with-three-js/ ) a set of particles in 3D (with randomly generated positions).

I modified the script to rotate the mouse and scale the wheels: I followed this example: http://threejs.org/examples/#misc_controls_trackball

Here's my script:

<html>
    <head>
        <meta charset="utf-8" />
        <title>Sample Three.js</title>
        <style>
            #container {
                background: #000;
                width: 700px;
                height: 500px;
            }
        </style>
    </head>
    <body>

        <div id="container">


        </div>

    </body>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
  <script src="js/three.min.js"></script> 
  <script src="js/Three.js"></script> 
  <script src="js/controls/TrackballControls.js"></script>
    <script src="js/Detector.js"></script>
    <script src="js/libs/stats.min.js"></script>

    <script type="text/javascript">

    if ( ! Detector.webgl ) Detector.addGetWebGLMessage();

    var container, stats;

    var camera, controls, scene, renderer;

    var cross;

    init();
    animate();

  function init() {

  // set the scene size
    var WIDTH = 700,
        HEIGHT = 500;

    // set some camera attributes
    var VIEW_ANGLE = 45,
        ASPECT = WIDTH / HEIGHT,
        NEAR = 0.1,
        FAR = 10000;

    // get the DOM element to attach to
    // - assume we've got jQuery to hand
    var $container = $('#container');

    // create a WebGL renderer, camera
    // and a scene
    var renderer = new THREE.WebGLRenderer();
    var camera = new THREE.Camera(  VIEW_ANGLE,
                                    ASPECT,
                                    NEAR,
                                    FAR  );
    var scene = new THREE.Scene();

    // the camera starts at 0,0,0 so pull it back
    camera.position.z = 300;

  controls = new THREE.TrackballControls( camera );

  // Add controls +
  controls.rotateSpeed = 1.0;
  controls.zoomSpeed = 1.2;
  controls.panSpeed = 0.8;

  controls.noZoom = false;
  controls.noPan = false;

  controls.staticMoving = true;
  controls.dynamicDampingFactor = 0.3;

  controls.keys = [ 65, 83, 68 ];
  controls.addEventListener( 'change', render );

    // start the renderer - set the clear colour
    // to a full black
    renderer.setClearColor(new THREE.Color(0, 1));
    renderer.setSize(WIDTH, HEIGHT);

    // attach the render-supplied DOM element
    $container.append(renderer.domElement);

    // create the particle variables
    var particleCount = 1800,
        particles = new THREE.Geometry(),
        pMaterial = new THREE.ParticleBasicMaterial({
            color: 0xFFFFFF,
            size: 20,
            map: THREE.ImageUtils.loadTexture(
                "images/particle.png"
            ),
            blending: THREE.AdditiveBlending,
            transparent: true
        });

    // now create the individual particles
    for(var p = 0; p < particleCount; p++) {

        // create a particle with random
        // position values, -250 -> 250
        var pX = Math.random() * 500 - 250,
            pY = Math.random() * 500 - 250,
            pZ = Math.random() * 500 - 250,
            particle = new THREE.Vertex(
                new THREE.Vector3(pX, pY, pZ)
            );

        // add it to the geometry
        particles.vertices.push(particle);

    }

    // create the particle system
    var particleSystem = new THREE.ParticleSystem(
        particles,
        pMaterial);

    particleSystem.sortParticles = true;

    // add it to the scene
    scene.addChild(particleSystem);


    // add Stats +
    stats = new Stats();
    stats.domElement.style.position = 'absolute';
    stats.domElement.style.top = '0px';
    stats.domElement.style.zIndex = 100;
    container.appendChild( stats.domElement );

    window.addEventListener( 'resize', onWindowResize, false );

    render();

  }

function onWindowResize() {

    camera.aspect = window.innerWidth / window.innerHeight;
    camera.updateProjectionMatrix();

    renderer.setSize( window.innerWidth, window.innerHeight );

    controls.handleResize();

    render();

}

function animate() {

    requestAnimationFrame( animate );
    controls.update();
}

function render() {

        // flag to the particle system that we've
        // changed its vertices. This is the
        // dirty little secret.
        particleSystem.geometry.__dirtyVertices = true;

        renderer.render(scene, camera);
      stats.update();
}
    </script>
</html>

      

But the following error appears when loading the page:

TypeError: _eye.subVectors is not a function TrackballControls.js:296

      

I've downloaded mrdoob-three.js-r71-5-gd6384d2.zip for three.js.

Is there a conflict between Three.js and three.js?

Can anyone give me a hint about this error?

thank

UPDATE 1:

Ok, I modified this source a bit (view-source: http://threejs.org/examples/misc_controls_trackball.html ) to include my own texture and add correctly Vector3

for each particle like this:

  // create the particle variables
  var particleCount = 1800,
      particles = new THREE.Geometry(),
    pMaterial = new THREE.ParticleBasicMaterial({
      color: 0xFFFFFF,
      size: 20,
      map: THREE.ImageUtils.loadTexture(
        "images/particle.png"
      ),
      blending: THREE.AdditiveBlending,
      transparent: true
    });

  // now create the individual particles
  for(var p = 0; p < particleCount; p++) {

    // create a particle with random
    // position values, -250 -> 250
    var pX = Math.random() * 500 - 250,
      pY = Math.random() * 500 - 250,
      pZ = Math.random() * 500 - 250,

      particle = new THREE.Vector3();
      particle.x = pX;
      particle.y = pY;
      particle.z = pZ;

      // add Vector3 to the geometry
      particles.vertices.push(particle);
  }

      

So the whole source is:

<html lang="en">
    <head>
        <title>three.js webgl - trackball controls</title>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
        <style>

        body {
             color: #000;
             font-family:Monospace;
             font-size:13px;
             text-align:center;
             font-weight: bold;

             background-color: #000;
margin: 0px;
overflow: hidden;
        }

#info {
color:#000;
position: absolute;
top: 0px; width: 100%;
padding: 5px;

}
            a {
                color: red;
            }
        </style>
    </head>

    <body>
        <div id="container"></div>
        <div id="info"> 
            <a href="http://threejs.org" target="_blank">three.js</a> - trackball controls example</br>
            MOVE mouse &amp; press LEFT/A: rotate, MIDDLE/S: zoom, RIGHT/D: pan
        </div>

        <script src="js/three.min.js"></script>

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

        <script src="js/Detector.js"></script>
        <script src="js/libs/stats.min.js"></script>

        <script>


            if ( ! Detector.webgl ) Detector.addGetWebGLMessage();

            var container, stats;

            var camera, controls, scene, renderer;

            var cross;

            init();
            animate();

            function init() {

                camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 1, 1000 );
                camera.position.z = 500;

                controls = new THREE.TrackballControls( camera );

                controls.rotateSpeed = 1.0;
                controls.zoomSpeed = 1.2;
                controls.panSpeed = 0.8;

                controls.noZoom = false;
                controls.noPan = false;

                controls.staticMoving = true;
                controls.dynamicDampingFactor = 0.3;

                controls.keys = [ 65, 83, 68 ];

                controls.addEventListener( 'change', render );

                // world

                scene = new THREE.Scene();
                scene.fog = new THREE.FogExp2( 0xcccccc, 0.002 );

    // create the particle variables
    var particleCount = 1800,
        particles = new THREE.Geometry(),
        pMaterial = new THREE.ParticleBasicMaterial({
            color: 0xFFFFFF,
            size: 20,
            map: THREE.ImageUtils.loadTexture(
                "images/particle.png"
            ),
            blending: THREE.AdditiveBlending,
            transparent: true
        });

    // now create the individual particles
    for(var p = 0; p < particleCount; p++) {

        // create a particle with random
        // position values, -250 -> 250
        var pX = Math.random() * 500 - 250,
            pY = Math.random() * 500 - 250,
            pZ = Math.random() * 500 - 250,

            particle = new THREE.Vector3();
          particle.x = pX;
          particle.y = pY;
          particle.z = pZ;

          // add Vector3 to the geometry
          particles.vertices.push(particle);
    }

                // lights

                light = new THREE.DirectionalLight( 0xffffff );
                light.position.set( 1, 1, 1 );
                scene.add( light );

                light = new THREE.DirectionalLight( 0x002288 );
                light.position.set( -1, -1, -1 );
                scene.add( light );

                light = new THREE.AmbientLight( 0x222222 );
                scene.add( light );


                // renderer

                renderer = new THREE.WebGLRenderer( { antialias: false } );
                renderer.setClearColor( scene.fog.color );
                renderer.setPixelRatio( window.devicePixelRatio );
                renderer.setSize( window.innerWidth, window.innerHeight );

                container = document.getElementById( 'container' );
                container.appendChild( renderer.domElement );

                stats = new Stats();
                stats.domElement.style.position = 'absolute';
                stats.domElement.style.top = '0px';
                stats.domElement.style.zIndex = 100;
                container.appendChild( stats.domElement );

                //

                window.addEventListener( 'resize', onWindowResize, false );
                //

                render();

            }

            function onWindowResize() {

                camera.aspect = window.innerWidth / window.innerHeight;
                camera.updateProjectionMatrix();

                renderer.setSize( window.innerWidth, window.innerHeight );

                controls.handleResize();

                render();

            }

            function animate() {

                requestAnimationFrame( animate );
                controls.update();

            }

            function render() {

                renderer.render( scene, camera );
                stats.update();

            }


        </script>

    </body>
</html>

      

Now nothing is displayed, but nothing is displayed ...

Can anyone check this source?

thank

+3


source to share





All Articles