MCPcopy Create free account
hub / github.com/Bloom-Engine/engine / getRayCollisionMesh

Function getRayCollisionMesh

src/math/index.ts:476–502  ·  view source on GitHub ↗
(ray: Ray, model: Model)

Source from the content-addressed store, hash-verified

474}
475
476export function getRayCollisionMesh(ray: Ray, model: Model): RayHit {
477 const noHit: RayHit = { hit: false, distance: 0, point: { x: 0, y: 0, z: 0 }, normal: { x: 0, y: 0, z: 0 } };
478 const data = _meshData.get(model.handle);
479 if (!data) return noHit;
480
481 let closest = noHit;
482 const verts = data.vertices;
483 const idxs = data.indices;
484
485 // Each vertex is 12 floats: x,y,z, nx,ny,nz, r,g,b,a, u,v
486 for (let i = 0; i < idxs.length; i += 3) {
487 const i0 = idxs[i] * 12;
488 const i1 = idxs[i + 1] * 12;
489 const i2 = idxs[i + 2] * 12;
490
491 const v0: Vec3 = { x: verts[i0], y: verts[i0 + 1], z: verts[i0 + 2] };
492 const v1: Vec3 = { x: verts[i1], y: verts[i1 + 1], z: verts[i1 + 2] };
493 const v2: Vec3 = { x: verts[i2], y: verts[i2 + 1], z: verts[i2 + 2] };
494
495 const hit = rayIntersectsTriangle(ray, v0, v1, v2);
496 if (hit.hit && (!closest.hit || hit.distance < closest.distance)) {
497 closest = hit;
498 }
499 }
500
501 return closest;
502}

Callers

nothing calls this directly

Calls 2

rayIntersectsTriangleFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected