点上的Raycasting不起作用 - THREE.js

时间:2016-09-20 21:29:36

标签: javascript three.js raycasting

它看起来很基本,但不起作用。在这里我创建了Point:

var p_geo = new THREE.Geometry();
p_geo.vertices = [new THREE.Vec3(0.5, 0,5, 0)];


var p_mat = new THREE.PointsMaterial({size: 0.2 });
var points = new THREE.Points(p_geo, p_mat);
scene.add(points);

这是光线投射。

var raycaster = new THREE.Raycaster();
var mouse = new THREE.Vector2();

function onClick( event ) {

    mouse.x = ( event.clientX / renderer.domElement.clientWidth ) * 2 - 1;
    mouse.y = - ( event.clientY / renderer.domElement.clientHeight ) * 2 + 1;

    raycaster.setFromCamera( mouse, camera );


    var intersects = raycaster.intersectObject( points );

    for(var i = 0; i < intersects.length; i++){

        console.log(intersects[i]);
    }

    render();
}

window.addEventListener('click', onClick);

当我点击该点时,会发生任何事情。怎么了?

0 个答案:

没有答案