raycaster.intersectObjects始终返回0

时间:2016-07-07 09:19:38

标签: three.js

下面是我正在尝试的代码,raycaster.intersectObjects返回0总是我在这里缺少什么?我也试过raycaster.intersectObjects(objects);

geometry.vertices.push(顶点);

objects.push(几何);

var particleTexture = THREE.ImageUtils.loadTexture('images / test.jpg');                 var materials = new THREE.PointsMaterial({                     图:particleTexture,                     大小:150                     });

document.addEventListener('click',onDocumentMouseClick,false);

function onDocumentMouseClick(event){

event.preventDefault();

var vector = new THREE.Vector3();
var raycaster = new THREE.Raycaster();


vector.set( ( event.clientX / window.innerWidth ) * 2 - 1, - ( event.clientY / window.innerHeight ) * 2 + 1, 0.5 ); // z = 0.5 important!

vector.unproject( camera );

raycaster.set( camera.position, vector.sub( camera.position ).normalize() );

var intersects = raycaster.intersectObjects( scene.children, true );

}

粒子=新的THREE.Points(几何,材料);

scene.add(颗粒);

1 个答案:

答案 0 :(得分:0)

您可以从Array开始交叉,scene.childern是Object

尝试对另一个对象进行另一个数组引用。

    function onDocumentMouseMove( event ) {  
            event.preventDefault();
            mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1;
            mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1;
    }

    function onDocumentMouseUp( event ) {
     event.preventDefault();
     if(event.which == 1)  { /// LMB
                           var raycaster = new THREE.Raycaster();
                            raycaster.setFromCamera( mouse, camera ); 
                           raycaster.params.Points.threshold = 100000;   

                    var intersects = raycaster.intersectObjects( intersects_obj, false ); 
       console.log(intersects_m);
     }
    } 

    var mouse = new THREE.Vector2();
    var intersects_obj = [];


    canvas.addEventListener( 'mousemove', onDocumentMouseMove, false );   
    canvas.addEventListener( 'mouseup', onDocumentMouseUp, false );

//var paticles = .... your code;

    intersects_obj.push(paticles);