UNPKG

@animech-public/playcanvas

Version:
2 lines (1 loc) 1.22 kB
import{Mat4 as r}from"../math/mat4.js";import{Vec3 as t}from"../math/vec3.js";import{BoundingBox as o}from"./bounding-box.js";import{BoundingSphere as n}from"./bounding-sphere.js";import{Ray as s}from"./ray.js";const i=new s,e=new t,a=new n,m=new r;class f{constructor(n=new r,s=new t(.5,.5,.5)){this.halfExtents=void 0,this._modelTransform=void 0,this._worldTransform=void 0,this._aabb=void 0,this.halfExtents=s,this._modelTransform=n.clone().invert(),this._worldTransform=n.clone(),this._aabb=new o(new t,this.halfExtents)}set worldTransform(r){this._worldTransform.copy(r),this._modelTransform.copy(r).invert()}get worldTransform(){return this._worldTransform}intersectsRay(r,t){if(this._modelTransform.transformPoint(r.origin,i.origin),this._modelTransform.transformVector(r.direction,i.direction),t){const r=this._aabb._intersectsRay(i,t);return m.copy(this._modelTransform).invert().transformPoint(t,t),r}return this._aabb._fastIntersectsRay(i)}containsPoint(r){return this._modelTransform.transformPoint(r,e),this._aabb.containsPoint(e)}intersectsBoundingSphere(r){return this._modelTransform.transformPoint(r.center,a.center),a.radius=r.radius,!!this._aabb.intersectsBoundingSphere(a)}}export{f as OrientedBox};