feat(@typegpu/geometry): Raycast against a mesh on the CPU

未关闭
#3,455 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
48/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
活跃
技术栈
computer-graphics, typescript

调研方向

Start with the mesh endpoint from #2997 and inspect IndexedGeometry's vertexAt(i), indexAt(i), and topology APIs. The issue proposes meshes.raycast(geometry, origin, direction) for triangle-list meshes, returning the nearest hit with barycentric data and available vertex attributes. Done means callers can raycast indexed and non-indexed geometry synchronously in local space; the back-face and all-hit questions still need decisions.

由索引模型根据 Issue 内容生成。

描述

Use case: world-space UIs (https://github.com/software-mansion/typegpu-kit/issues/15). A UI is rendered to a texture on a plane, and pointer events need the hit UV. Picking on the GPU is async and has no UVs, so this needs a sync CPU raycast against the mesh.

It builds on the mesh endpoint from #2997, which already gives everything needed: vertexAt(i), indexAt(i) on IndexedGeometry, and the topology.

Proposal:

const hit = meshes.raycast(geometry, origin, direction);
// { distance, triangle, barycentric, position, normal, uv } | undefined
  • Works for triangle-list geometry, indexed or not.
  • Returns the nearest hit along the ray, or undefined.
  • triangle and barycentric let you interpolate any attribute of a custom vertex schema. position, normal and uv are filled when the schema has them (the default Vertex does).
  • The ray is in the geometry's local space. Moving it by the inverse of an instance's placement stays with the caller (or a helper in the kit).

Open questions:

  • Hit back faces too, or only front faces by default? A UI plane wants both.
  • One hit, or an option for all hits sorted by distance?
  • No acceleration structure at first: a linear pass over the triangles is fine for UI planes and small meshes. A BVH can come later if someone raycasts big meshes every frame.
主要语言
TypeScript
星标
3.4k
派生
151
平均合并
3 天 8 小时
30 天内合并 PR
55

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

software-mansion/TypeGPU 的其他 Issue

查看 software-mansion/TypeGPU 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。