@animech-public/playcanvas
Version:
PlayCanvas WebGL game engine
2 lines (1 loc) • 747 B
JavaScript
import{Vec3 as t}from"../math/vec3.js";const s=new t,i=new t,n=new t,o=new t,r=new t,e=1e-6;class c{constructor(s=t.ZERO,i=t.ZERO,n=t.ZERO){this.v0=new t,this.v1=new t,this.v2=new t,this.set(s,i,n)}set(t,s,i){return this.v0.copy(t),this.v1.copy(s),this.v2.copy(i),this}intersectsRay(c,h){s.sub2(this.v1,this.v0),i.sub2(this.v2,this.v0),n.cross(c.direction,i);const v=s.dot(n);if(v>-e&&v<e)return!1;const u=1/v;o.sub2(c.origin,this.v0);const d=u*o.dot(n);if(d<0||d>1)return!1;r.cross(o,s);const w=u*c.direction.dot(r);if(w<0||d+w>1)return!1;const a=u*i.dot(r);return a>e&&(h instanceof t&&h.copy(c.direction).mulScalar(a).add(c.origin),!0)}toString(){return`[${this.v0.toString()}, ${this.v1.toString()}, ${this.v2.toString()}]`}}export{c as Tri};