Skip to content

Documentation / @ripl/3d / rayIntersectTriangleBuffer

Function: rayIntersectTriangleBuffer() ​

rayIntersectTriangleBuffer(ray, vertices, offsetA, offsetB, offsetC): number

Defined in: 3d/src/math/ray.ts:117

Intersects a ray with a triangle read straight out of a packed vertex buffer.

The same Möller–Trumbore solve as rayIntersectTriangle, written against three flat offsets and scalars. That version allocates five vectors per triangle, which a pointer move over a mesh of a few thousand triangles turns into tens of thousands of short-lived objects; this one allocates nothing, at the cost of reporting only the distance.

Parameters ​

ParameterTypeDescription
rayRayThe ray to cast.
verticesFloat64ArrayWorld-space vertex components, three floats per vertex.
offsetAnumberIndex into vertices of the triangle's first vertex.
offsetBnumberIndex into vertices of the triangle's second vertex.
offsetCnumberIndex into vertices of the triangle's third vertex.

Returns ​

number

The distance along the ray, or -1 when the ray misses, is parallel, or would hit behind its origin.