0

我是三个.js 菜鸟。我正在玩这个示例 http://threejs.org/examples/css3d_periodictable.html

我想知道单击特定元素的时间,查看了几个示例并添加了下面的代码 在函数内设置断点,即使我在元素内单击,intersects.length 也始终为 0。请帮忙!我错过了什么?提前致谢

    function onDocumentMouseDown( event ) {

        event.preventDefault();
        controls.enabled = true;

        mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1;
        mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1;
        var vector = new THREE.Vector3( mouse.x, mouse.y, 0.5 );
        //var vector = new THREE.Vector3( ( event.clientX / window.innerWidth ) * 2 - 1, - ( event.clientY / window.innerHeight ) * 2 + 1, 0.5 );
        projector.unprojectVector( vector, camera );

        var raycaster = new THREE.Raycaster( camera.position, vector.sub( camera.position ).normalize() );

        var intersects = raycaster.intersectObjects( objects,true );

        if ( intersects.length > 0 ) {

            intersects[ 0 ].object.material.color.setHex( Math.random() * 0xffffff );

            var particle = new THREE.Particle( particleMaterial );
            particle.position = intersects[ 0 ].point;
            particle.scale.x = particle.scale.y = 8;
            scene.add( particle );

        }

    }
4

1 回答 1

0

Raycaster 不适用于 css3Drenderer。只需使用元素 onclick 事件

于 2013-04-27T18:20:38.567 回答