Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.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
Three.js R81中的ThreeJS光线投射与R71不同_Three.js_Raycasting - Fatal编程技术网

Three.js R81中的ThreeJS光线投射与R71不同

Three.js R81中的ThreeJS光线投射与R71不同,three.js,raycasting,Three.js,Raycasting,我有一个上面有网格的平面。我的代码在用户双击网格时绘制一个球。这在R71中运行得很好,但我一切换到R81,raycaster就不会返回intersect。代码如下: 在init()中: 在doubleClickEvent()中: 如果我改变 intersects = raycaster.intersectObjects(planes); 到 球被抽到了,但它被抽到了错误的位置 有什么想法吗 我找到了答案。光线投射不工作的原因是因为飞机的可见性为假。解决方案是更改材质可见性而不是平面的可见性

我有一个上面有网格的平面。我的代码在用户双击网格时绘制一个球。这在R71中运行得很好,但我一切换到R81,raycaster就不会返回intersect。代码如下:

在init()中:

在doubleClickEvent()中:

如果我改变

intersects = raycaster.intersectObjects(planes); 

球被抽到了,但它被抽到了错误的位置


有什么想法吗

我找到了答案。光线投射不工作的原因是因为飞机的可见性为假。解决方案是更改材质可见性而不是平面的可见性

我找到了答案。光线投射不工作的原因是因为飞机的可见性为假。解决方案是更改材质可见性而不是平面的可见性

event.preventDefault();

var mouse = new THREE.Vector2((event.clientX  / window.innerWidth ) * 2 - 1, -(((event.clientY / window.innerHeight ) * 2 - 1)));
var directionVector = new THREE.Vector3();
directionVector.set(mouse.x, mouse.y, 0.1);
directionVector.unproject(camera);
directionVector.sub(camera.position);           
directionVector.normalize();
raycaster.set(camera.position, directionVector);
intersects = raycaster.intersectObjects(planes);
if (intersects.length) {
    var sphereParent = new THREE.Object3D();
    var sphereGeometry = new THREE.SphereGeometry(.1, 16, 8);
    var sphereMaterial = new THREE.MeshLambertMaterial({ color: 0xffffff });
    var sphere = new THREE.Mesh(sphereGeometry, sphereMaterial);
    sphereParent.add(sphere);
    sphereParent.position.set(intersects[0].point.x, intersects[0].point.y, 0.0);
    scene.add(sphereParent);
    objects.push(sphereParent);
}
intersects = raycaster.intersectObjects(planes); 
intersects = raycaster.intersectObjects(scene.children);