UNPKG

@animech-public/playcanvas

Version:
2 lines (1 loc) 3.02 kB
var t;class s{constructor(t=0,s=0,h=0){this.x=void 0,this.y=void 0,this.z=void 0,3===t.length?(this.x=t[0],this.y=t[1],this.z=t[2]):(this.x=t,this.y=s,this.z=h)}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this}add2(t,s){return this.x=t.x+s.x,this.y=t.y+s.y,this.z=t.z+s.z,this}addScalar(t){return this.x+=t,this.y+=t,this.z+=t,this}addScaled(t,s){return this.x+=t.x*s,this.y+=t.y*s,this.z+=t.z*s,this}clone(){return new(0,this.constructor)(this.x,this.y,this.z)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this}cross(t,s){const h=t.x,i=t.y,r=t.z,e=s.x,z=s.y,x=s.z;return this.x=i*x-z*r,this.y=r*e-x*h,this.z=h*z-e*i,this}distance(t){const s=this.x-t.x,h=this.y-t.y,i=this.z-t.z;return Math.sqrt(s*s+h*h+i*i)}div(t){return this.x/=t.x,this.y/=t.y,this.z/=t.z,this}div2(t,s){return this.x=t.x/s.x,this.y=t.y/s.y,this.z=t.z/s.z,this}divScalar(t){return this.x/=t,this.y/=t,this.z/=t,this}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z}equals(t){return this.x===t.x&&this.y===t.y&&this.z===t.z}equalsApprox(t,s=1e-6){return Math.abs(this.x-t.x)<s&&Math.abs(this.y-t.y)<s&&Math.abs(this.z-t.z)<s}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}lerp(t,s,h){return this.x=t.x+h*(s.x-t.x),this.y=t.y+h*(s.y-t.y),this.z=t.z+h*(s.z-t.z),this}mul(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this}mul2(t,s){return this.x=t.x*s.x,this.y=t.y*s.y,this.z=t.z*s.z,this}mulScalar(t){return this.x*=t,this.y*=t,this.z*=t,this}normalize(t=this){const s=t.x*t.x+t.y*t.y+t.z*t.z;if(s>0){const h=1/Math.sqrt(s);this.x=t.x*h,this.y=t.y*h,this.z=t.z*h}return this}floor(t=this){return this.x=Math.floor(t.x),this.y=Math.floor(t.y),this.z=Math.floor(t.z),this}ceil(t=this){return this.x=Math.ceil(t.x),this.y=Math.ceil(t.y),this.z=Math.ceil(t.z),this}round(t=this){return this.x=Math.round(t.x),this.y=Math.round(t.y),this.z=Math.round(t.z),this}min(t){return t.x<this.x&&(this.x=t.x),t.y<this.y&&(this.y=t.y),t.z<this.z&&(this.z=t.z),this}max(t){return t.x>this.x&&(this.x=t.x),t.y>this.y&&(this.y=t.y),t.z>this.z&&(this.z=t.z),this}project(t){const s=(this.x*t.x+this.y*t.y+this.z*t.z)/(t.x*t.x+t.y*t.y+t.z*t.z);return this.x=t.x*s,this.y=t.y*s,this.z=t.z*s,this}set(t,s,h){return this.x=t,this.y=s,this.z=h,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this}sub2(t,s){return this.x=t.x-s.x,this.y=t.y-s.y,this.z=t.z-s.z,this}subScalar(t){return this.x-=t,this.y-=t,this.z-=t,this}fromArray(t,s=0){var h,i,r;return this.x=null!=(h=t[s])?h:this.x,this.y=null!=(i=t[s+1])?i:this.y,this.z=null!=(r=t[s+2])?r:this.z,this}toString(){return`[${this.x}, ${this.y}, ${this.z}]`}toArray(t=[],s=0){return t[s]=this.x,t[s+1]=this.y,t[s+2]=this.z,t}}t=s,s.ZERO=Object.freeze(new t(0,0,0)),s.ONE=Object.freeze(new t(1,1,1)),s.UP=Object.freeze(new t(0,1,0)),s.DOWN=Object.freeze(new t(0,-1,0)),s.RIGHT=Object.freeze(new t(1,0,0)),s.LEFT=Object.freeze(new t(-1,0,0)),s.FORWARD=Object.freeze(new t(0,0,-1)),s.BACK=Object.freeze(new t(0,0,1));export{s as Vec3};