Raycasting 不提供任何交集 [英] Raycasting doesn't give any intersections

查看:43
本文介绍了Raycasting 不提供任何交集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用光线投射来获得球体和光线之间的交点,两者都位于场景的中心.这是一个非常简单的场景,但我无法让它发挥作用.

I'm trying to to use raycasting to get the intersection between a sphere and a ray, both located at the center of the scene. It's a pretty simple scenario but I'm not being able to make it work.

相关代码:

// renderer, camera, etc...

var material = new THREE.MeshStandardMaterial();
material.opacity = 0.25;
material.transparent = true;
sphere = new THREE.Mesh(new THREE.SphereGeometry(100, 32, 32), material);
scene.add(sphere);

var start = new THREE.Vector3(0, 0, 0);
var direction = new THREE.Vector3(-84, 102, 97);
var ray = new THREE.Raycaster(start, direction.normalize());
scene.updateMatrixWorld();
var rayIntersects = ray.intersectObjects([sphere], true);

console.log(rayIntersects); // empty array

推荐答案

如果您想在对象和从对象内部投射的光线之间获得交集,那么作为一个选项,您应该使用双面材质.

In case, when you want to get intersection between an object and a ray, casted from inside of the object, then, as an option, you should use a double-sided material.

像这样:

var material = new THREE.MeshStandardMaterial({ side: THREE.DoubleSide });

THREE.Raycaster() 的文档,在关于 .intersectObject ( object, recursive ) 方法的解释部分的最后,说:

The documentation for THREE.Raycaster(), at the end of the part of explanation about the .intersectObject ( object, recursive ) method, says:

请注意,对于网格,面必须指向光线的原点才能被检测到;穿过面部背面的光线的交叉点将不会被检测到.要对对象的两个面进行光线投射,您需要将材质的 side 属性设置为 THREE.DoubleSide.

这篇关于Raycasting 不提供任何交集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆