typescript - Raycast 没有击中原始几何网格
问题描述
我正在尝试使用射线将鼠标悬停在对象上,但只有从 3D 资产文件加载的网格被它击中。从原始几何体创建的任何网格都像CylinderGeometry
或被BoxGeometry
忽略。
我要命中的对象是CameraPole
,它是一个扩展THREE.Group
并包含pole
网格的类。
export default class CameraPole extends Group {
public pole: Mesh;
constructor() {
super();
this.name = 'CameraPole';
this.pole = new Mesh(
new CylinderGeometry(.25, .25, 5, 32),
new MeshPhongMaterial({color: 0xffffff})
);
this.position.x = -34;
this.position.y = 5;
this.position.z = 17.8;
this.add(this.pole);
}
}
这只是一个示例,但我的场景中还有其他原始对象,并且它们都没有被光线投射检测到。
我构建并将其添加到场景中:
const cameraPole = new CameraPole();
scene.add(cameraPole);
但是当我尝试用光线投射命中来检测它时,我只命中了从 3D 资产文件加载的对象。返回的数组从不包含从原始几何生成的任何对象。
document.addEventListener('mousemove', (e) => {
const mouse = {
x: (e.clientX / window.innerWidth) * 2 - 1,
y: (e.clientY / window.innerHeight) * 2 - 1
};
const ray = new Raycaster();
ray.setFromCamera(mouse, camera);
console.log(ray.intersectObjects(scene.children, true)); // Only returning complex meshes, not geometric objects created dynamically.
});
我也尝试过专门寻找相机杆,但我仍然一无所获:
ray.intersectObject(cameraPole, true);
编辑:如果相关,相机是OrthographicCamera
.
编辑2:所以我发现如果我不改变它的位置CameraPole
就可以了。当位置更新时,光线投射不再检测到它。关于如何解决这个问题的任何消息?
解决方案
推荐阅读
- wordpress - 如何使用 wp-cron 一次性创建执行功能
- python - 运行 asyncio 循环和 tkinter gui
- javascript - 如何在点击时替换 8 张图片的部分 src?
- c# - RSocketClient 打印一些奇怪的消息
- r - R按因子水平对各列求和
- android - 启动 Xamarin.forms 应用程序时出错:尝试绘制太大(165514752 字节)位图
- python - 将变量名称作为原始字符串输入到python中的请求中
- php - 无法在 PHP 中接收从 Android 客户端发送的 JSON 数组
- flutter - 发布模式下的 Flutter Web View 空白屏幕
- android - 为什么我的图像出现在 Android Studio 设计视图中,但在手机中运行时却没有?