mesh.raycast

Where a ray first meets the mesh, with the face it hits.

GeometricSince 0.3.0

Usage

TypeScript
mesh.raycast(ray: Ray): MeshHit | null

Parameters

  • rayRay

    Origin and direction; the direction need not have unit length. Required. In model.

Returns

The hit (t in units of the ray direction’s length, point, face normal, face as a prim set), or null for a miss, a zero direction or a non-finite origin.

Guarantees

  • hit.point equals Ray.pointAt(ray, hit.t)
  • hit.face names a face of this mesh
  • The same result on every machine.

Example

TypeScript
const hit = Mesh.box().value.raycast(Ray.of(Point3.of(0, 0, 5), Vector3.of(0, 0, -1)))
hit.t // → 4.5

See also