使用treex.domevents.js单击事件不起作用

时间:2015-05-30 19:14:09

标签: three.js

我现在谷歌搜索已经好几天了,仍然无法找到解决问题的方法。我只想让一个three.js对象可点击。使用threex.domevents.js它应该很容易,但似乎不适合我;-) 到目前为止我的代码:

    <!DOCTYPE html>
    <html>
    <head>

    <script src="scripts/three.min.js"></script>
    <script src="scripts/jquery.js"></script>
    <script src="scripts/ChromeFixes.js"></script>
    <script src="scripts/threex.domevents.js"></script>

    </head>
    <body>

    <script>
    var camera, scene, renderer, geometry, material, mesh;

    init();
    animate();

    function init() {

      h = $( window ).height();
      w = $( window ).width();


      scene = new THREE.Scene();

      camera = new THREE.PerspectiveCamera(50, w / h, 1, 10000);
      camera.position.z = 500;
      scene.add(camera);

      var shape = new THREE.SphereGeometry(20, 20, 20, 20);
      var cover = new THREE.MeshPhongMaterial();
      cover.emissive.setRGB(1, 0, 0);
      cover.specular.setRGB(0.9, 0.9, 0.9);
      var sphere = new THREE.Mesh(shape, cover);
      scene.add(sphere);



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

      document.body.appendChild(renderer.domElement);

    }

    function animate() {
      requestAnimationFrame(animate);
      render();
    }

    function render() {
      renderer.render(scene, camera);
    }

    var domEvent = new THREEx.DomEvent();

    sphere.on('click', function(object3d){ camera.position.z = 100 });


    </script>

    </body>
    </html>

1 个答案:

答案 0 :(得分:0)

您必须确保threex.domevents.js重写(最可能是r59)的three.js库与您在项目中包含的库相同。