Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/407.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Three.js光线投射始终返回空数组_Javascript_Three.js_Raycasting - Fatal编程技术网

Javascript Three.js光线投射始终返回空数组

Javascript Three.js光线投射始终返回空数组,javascript,three.js,raycasting,Javascript,Three.js,Raycasting,我的场景中有很多对象,但是intersects变量总是返回一个空数组,你知道吗 var mouse = new THREE.Vector2((event.clientX / window.innerWidth) * 2 - 1, -( event.clientY / window.innerHeight ) * 2 + 1); var raycaster = new THREE.Raycaster(); //new THREE.Raycaster(camera.position, mouse);

我的场景中有很多对象,但是intersects变量总是返回一个空数组,你知道吗

var mouse = new THREE.Vector2((event.clientX / window.innerWidth) * 2 - 1, -( event.clientY / window.innerHeight ) * 2 + 1);
var raycaster = new THREE.Raycaster(); //new THREE.Raycaster(camera.position, mouse);
raycaster.setFromCamera(mouse, camera); 
var intersects = raycaster.intersectObjects(scene.children, true);

此代码是否在渲染函数中执行?您的
mouse
变量是否有有效的坐标?mouse有有效的坐标(-X和y上的1到1),但该函数不在渲染函数下,是否应该?它应该在
onMouseMove
onMouseDown中?让它在onMouseMove中工作,然后您可以添加onMouseDown。