UNPKG

@realsee/dnalogel

Version:
15 lines (14 loc) 708 B
import * as t from "three"; function u(r, l, n, P = !0) { const s = new t.Plane().setFromNormalAndCoplanarPoint(l.direction.clone().normalize(), r), e = s.projectPoint(n.start, new t.Vector3()), i = s.projectPoint(n.end, new t.Vector3()), o = new t.Line3(e, i), c = o.closestPointToPoint(r, P, new t.Vector3()), d = c.distanceTo(i), p = c.distanceTo(e), T = o.distance(); if (d > p && d > T) { const a = -c.distanceTo(e) / o.distance(), m = n.start.clone().sub(n.end).normalize(); return n.start.sub(m.clone().multiplyScalar(a * n.distance())); } else { const a = c.distanceTo(e) / o.distance(); return new t.Vector3().lerpVectors(n.start, n.end, a); } } export { u as rayOnLine };