UNPKG

lingo3d-vanilla

Version:

Lingo3D is a React/Vue 3d game development framework that ships with a complete visual editor

1 lines 125 kB
"use strict";(self.webpackChunklingo3d_vanilla=self.webpackChunklingo3d_vanilla||[]).push([[825],{6825:(t,e,s)=>{s.r(e),s.d(e,{AABB:()=>c,ArrayCollisionMatrix:()=>p,BODY_SLEEP_STATES:()=>T,BODY_TYPES:()=>R,Body:()=>I,Box:()=>C,Broadphase:()=>G,COLLISION_TYPES:()=>mi,ConeTwistConstraint:()=>de,Constraint:()=>Ot,ContactEquation:()=>$t,ContactMaterial:()=>be,ConvexPolyhedron:()=>B,Cylinder:()=>xs,DistanceConstraint:()=>ue,Equation:()=>_t,EventTarget:()=>y,FrictionEquation:()=>we,GSSolver:()=>ti,GridBroadphase:()=>Z,Heightfield:()=>Es,HingeConstraint:()=>ve,JacobianElement:()=>kt,LockConstraint:()=>pe,Mat3:()=>o,Material:()=>Be,NaiveBroadphase:()=>J,Narrowphase:()=>gi,ObjectCollisionMatrix:()=>i,Particle:()=>bs,Plane:()=>Bs,PointToPointConstraint:()=>oe,Pool:()=>yi,Quaternion:()=>v,RAY_MODES:()=>lt,Ray:()=>ht,RaycastResult:()=>tt,RaycastVehicle:()=>Ve,RigidVehicle:()=>hs,RotationalEquation:()=>le,RotationalMotorEquation:()=>ye,SAPBroadphase:()=>Vt,SHAPE_TYPES:()=>w,SPHSystem:()=>us,Shape:()=>f,Solver:()=>Js,Sphere:()=>ls,SplitSolver:()=>oi,Spring:()=>Ae,Transform:()=>x,Trimesh:()=>js,Vec3:()=>r,Vec3Pool:()=>vi,WheelInfo:()=>Ne,World:()=>jo});s(650),s(5488);class i{constructor(){this.matrix={}}get(t,e){let{id:s}=t,{id:i}=e;if(i>s){const t=i;i=s,s=t}return`${s}-${i}`in this.matrix}set(t,e,s){let{id:i}=t,{id:o}=e;if(o>i){const t=o;o=i,i=t}s?this.matrix[`${i}-${o}`]=!0:delete this.matrix[`${i}-${o}`]}reset(){this.matrix={}}setNumObjects(t){}}class o{constructor(t){void 0===t&&(t=[0,0,0,0,0,0,0,0,0]),this.elements=t}identity(){const t=this.elements;t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=1,t[5]=0,t[6]=0,t[7]=0,t[8]=1}setZero(){const t=this.elements;t[0]=0,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=0,t[6]=0,t[7]=0,t[8]=0}setTrace(t){const e=this.elements;e[0]=t.x,e[4]=t.y,e[8]=t.z}getTrace(t){void 0===t&&(t=new r);const e=this.elements;return t.x=e[0],t.y=e[4],t.z=e[8],t}vmult(t,e){void 0===e&&(e=new r);const s=this.elements,i=t.x,o=t.y,n=t.z;return e.x=s[0]*i+s[1]*o+s[2]*n,e.y=s[3]*i+s[4]*o+s[5]*n,e.z=s[6]*i+s[7]*o+s[8]*n,e}smult(t){for(let e=0;e<this.elements.length;e++)this.elements[e]*=t}mmult(t,e){void 0===e&&(e=new o);const s=this.elements,i=t.elements,n=e.elements,r=s[0],a=s[1],l=s[2],h=s[3],c=s[4],d=s[5],u=s[6],p=s[7],y=s[8],v=i[0],m=i[1],g=i[2],w=i[3],f=i[4],x=i[5],b=i[6],B=i[7],A=i[8];return n[0]=r*v+a*w+l*b,n[1]=r*m+a*f+l*B,n[2]=r*g+a*x+l*A,n[3]=h*v+c*w+d*b,n[4]=h*m+c*f+d*B,n[5]=h*g+c*x+d*A,n[6]=u*v+p*w+y*b,n[7]=u*m+p*f+y*B,n[8]=u*g+p*x+y*A,e}scale(t,e){void 0===e&&(e=new o);const s=this.elements,i=e.elements;for(let o=0;3!==o;o++)i[3*o+0]=t.x*s[3*o+0],i[3*o+1]=t.y*s[3*o+1],i[3*o+2]=t.z*s[3*o+2];return e}solve(t,e){void 0===e&&(e=new r);const s=[];let i,o;for(i=0;i<12;i++)s.push(0);for(i=0;i<3;i++)for(o=0;o<3;o++)s[i+4*o]=this.elements[i+3*o];s[3]=t.x,s[7]=t.y,s[11]=t.z;let n=3;const a=n;let l;let h;do{if(i=a-n,0===s[i+4*i])for(o=i+1;o<a;o++)if(0!==s[i+4*o]){l=4;do{h=4-l,s[h+4*i]+=s[h+4*o]}while(--l);break}if(0!==s[i+4*i])for(o=i+1;o<a;o++){const t=s[i+4*o]/s[i+4*i];l=4;do{h=4-l,s[h+4*o]=h<=i?0:s[h+4*o]-s[h+4*i]*t}while(--l)}}while(--n);if(e.z=s[11]/s[10],e.y=(s[7]-s[6]*e.z)/s[5],e.x=(s[3]-s[2]*e.z-s[1]*e.y)/s[0],isNaN(e.x)||isNaN(e.y)||isNaN(e.z)||e.x===1/0||e.y===1/0||e.z===1/0)throw`Could not solve equation! Got x=[${e.toString()}], b=[${t.toString()}], A=[${this.toString()}]`;return e}e(t,e,s){if(void 0===s)return this.elements[e+3*t];this.elements[e+3*t]=s}copy(t){for(let e=0;e<t.elements.length;e++)this.elements[e]=t.elements[e];return this}toString(){let t="";for(let e=0;e<9;e++)t+=this.elements[e]+",";return t}reverse(t){void 0===t&&(t=new o);const e=n;let s,i;for(s=0;s<3;s++)for(i=0;i<3;i++)e[s+6*i]=this.elements[s+3*i];e[3]=1,e[9]=0,e[15]=0,e[4]=0,e[10]=1,e[16]=0,e[5]=0,e[11]=0,e[17]=1;let r=3;const a=r;let l;let h;do{if(s=a-r,0===e[s+6*s])for(i=s+1;i<a;i++)if(0!==e[s+6*i]){l=6;do{h=6-l,e[h+6*s]+=e[h+6*i]}while(--l);break}if(0!==e[s+6*s])for(i=s+1;i<a;i++){const t=e[s+6*i]/e[s+6*s];l=6;do{h=6-l,e[h+6*i]=h<=s?0:e[h+6*i]-e[h+6*s]*t}while(--l)}}while(--r);s=2;do{i=s-1;do{const t=e[s+6*i]/e[s+6*s];l=6;do{h=6-l,e[h+6*i]=e[h+6*i]-e[h+6*s]*t}while(--l)}while(i--)}while(--s);s=2;do{const t=1/e[s+6*s];l=6;do{h=6-l,e[h+6*s]=e[h+6*s]*t}while(--l)}while(s--);s=2;do{i=2;do{if(h=e[3+i+6*s],isNaN(h)||h===1/0)throw`Could not reverse! A=[${this.toString()}]`;t.e(s,i,h)}while(i--)}while(s--);return t}setRotationFromQuaternion(t){const e=t.x,s=t.y,i=t.z,o=t.w,n=e+e,r=s+s,a=i+i,l=e*n,h=e*r,c=e*a,d=s*r,u=s*a,p=i*a,y=o*n,v=o*r,m=o*a,g=this.elements;return g[0]=1-(d+p),g[1]=h-m,g[2]=c+v,g[3]=h+m,g[4]=1-(l+p),g[5]=u-y,g[6]=c-v,g[7]=u+y,g[8]=1-(l+d),this}transpose(t){void 0===t&&(t=new o);const e=this.elements,s=t.elements;let i;return s[0]=e[0],s[4]=e[4],s[8]=e[8],i=e[1],s[1]=e[3],s[3]=i,i=e[2],s[2]=e[6],s[6]=i,i=e[5],s[5]=e[7],s[7]=i,t}}const n=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];class r{constructor(t,e,s){void 0===t&&(t=0),void 0===e&&(e=0),void 0===s&&(s=0),this.x=t,this.y=e,this.z=s}cross(t,e){void 0===e&&(e=new r);const s=t.x,i=t.y,o=t.z,n=this.x,a=this.y,l=this.z;return e.x=a*o-l*i,e.y=l*s-n*o,e.z=n*i-a*s,e}set(t,e,s){return this.x=t,this.y=e,this.z=s,this}setZero(){this.x=this.y=this.z=0}vadd(t,e){if(!e)return new r(this.x+t.x,this.y+t.y,this.z+t.z);e.x=t.x+this.x,e.y=t.y+this.y,e.z=t.z+this.z}vsub(t,e){if(!e)return new r(this.x-t.x,this.y-t.y,this.z-t.z);e.x=this.x-t.x,e.y=this.y-t.y,e.z=this.z-t.z}crossmat(){return new o([0,-this.z,this.y,this.z,0,-this.x,-this.y,this.x,0])}normalize(){const t=this.x,e=this.y,s=this.z,i=Math.sqrt(t*t+e*e+s*s);if(i>0){const t=1/i;this.x*=t,this.y*=t,this.z*=t}else this.x=0,this.y=0,this.z=0;return i}unit(t){void 0===t&&(t=new r);const e=this.x,s=this.y,i=this.z;let o=Math.sqrt(e*e+s*s+i*i);return o>0?(o=1/o,t.x=e*o,t.y=s*o,t.z=i*o):(t.x=1,t.y=0,t.z=0),t}length(){const t=this.x,e=this.y,s=this.z;return Math.sqrt(t*t+e*e+s*s)}lengthSquared(){return this.dot(this)}distanceTo(t){const e=this.x,s=this.y,i=this.z,o=t.x,n=t.y,r=t.z;return Math.sqrt((o-e)*(o-e)+(n-s)*(n-s)+(r-i)*(r-i))}distanceSquared(t){const e=this.x,s=this.y,i=this.z,o=t.x,n=t.y,r=t.z;return(o-e)*(o-e)+(n-s)*(n-s)+(r-i)*(r-i)}scale(t,e){void 0===e&&(e=new r);const s=this.x,i=this.y,o=this.z;return e.x=t*s,e.y=t*i,e.z=t*o,e}vmul(t,e){return void 0===e&&(e=new r),e.x=t.x*this.x,e.y=t.y*this.y,e.z=t.z*this.z,e}addScaledVector(t,e,s){return void 0===s&&(s=new r),s.x=this.x+t*e.x,s.y=this.y+t*e.y,s.z=this.z+t*e.z,s}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z}isZero(){return 0===this.x&&0===this.y&&0===this.z}negate(t){return void 0===t&&(t=new r),t.x=-this.x,t.y=-this.y,t.z=-this.z,t}tangents(t,e){const s=this.length();if(s>0){const i=a,o=1/s;i.set(this.x*o,this.y*o,this.z*o);const n=l;Math.abs(i.x)<.9?(n.set(1,0,0),i.cross(n,t)):(n.set(0,1,0),i.cross(n,t)),i.cross(t,e)}else t.set(1,0,0),e.set(0,1,0)}toString(){return`${this.x},${this.y},${this.z}`}toArray(){return[this.x,this.y,this.z]}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this}lerp(t,e,s){const i=this.x,o=this.y,n=this.z;s.x=i+(t.x-i)*e,s.y=o+(t.y-o)*e,s.z=n+(t.z-n)*e}almostEquals(t,e){return void 0===e&&(e=1e-6),!(Math.abs(this.x-t.x)>e||Math.abs(this.y-t.y)>e||Math.abs(this.z-t.z)>e)}almostZero(t){return void 0===t&&(t=1e-6),!(Math.abs(this.x)>t||Math.abs(this.y)>t||Math.abs(this.z)>t)}isAntiparallelTo(t,e){return this.negate(h),h.almostEquals(t,e)}clone(){return new r(this.x,this.y,this.z)}}r.ZERO=new r(0,0,0),r.UNIT_X=new r(1,0,0),r.UNIT_Y=new r(0,1,0),r.UNIT_Z=new r(0,0,1);const a=new r,l=new r,h=new r;class c{constructor(t){void 0===t&&(t={}),this.lowerBound=new r,this.upperBound=new r,t.lowerBound&&this.lowerBound.copy(t.lowerBound),t.upperBound&&this.upperBound.copy(t.upperBound)}setFromPoints(t,e,s,i){const o=this.lowerBound,n=this.upperBound,r=s;o.copy(t[0]),r&&r.vmult(o,o),n.copy(o);for(let a=1;a<t.length;a++){let e=t[a];r&&(r.vmult(e,d),e=d),e.x>n.x&&(n.x=e.x),e.x<o.x&&(o.x=e.x),e.y>n.y&&(n.y=e.y),e.y<o.y&&(o.y=e.y),e.z>n.z&&(n.z=e.z),e.z<o.z&&(o.z=e.z)}return e&&(e.vadd(o,o),e.vadd(n,n)),i&&(o.x-=i,o.y-=i,o.z-=i,n.x+=i,n.y+=i,n.z+=i),this}copy(t){return this.lowerBound.copy(t.lowerBound),this.upperBound.copy(t.upperBound),this}clone(){return(new c).copy(this)}extend(t){this.lowerBound.x=Math.min(this.lowerBound.x,t.lowerBound.x),this.upperBound.x=Math.max(this.upperBound.x,t.upperBound.x),this.lowerBound.y=Math.min(this.lowerBound.y,t.lowerBound.y),this.upperBound.y=Math.max(this.upperBound.y,t.upperBound.y),this.lowerBound.z=Math.min(this.lowerBound.z,t.lowerBound.z),this.upperBound.z=Math.max(this.upperBound.z,t.upperBound.z)}overlaps(t){const e=this.lowerBound,s=this.upperBound,i=t.lowerBound,o=t.upperBound,n=i.x<=s.x&&s.x<=o.x||e.x<=o.x&&o.x<=s.x,r=i.y<=s.y&&s.y<=o.y||e.y<=o.y&&o.y<=s.y,a=i.z<=s.z&&s.z<=o.z||e.z<=o.z&&o.z<=s.z;return n&&r&&a}volume(){const t=this.lowerBound,e=this.upperBound;return(e.x-t.x)*(e.y-t.y)*(e.z-t.z)}contains(t){const e=this.lowerBound,s=this.upperBound,i=t.lowerBound,o=t.upperBound;return e.x<=i.x&&s.x>=o.x&&e.y<=i.y&&s.y>=o.y&&e.z<=i.z&&s.z>=o.z}getCorners(t,e,s,i,o,n,r,a){const l=this.lowerBound,h=this.upperBound;t.copy(l),e.set(h.x,l.y,l.z),s.set(h.x,h.y,l.z),i.set(l.x,h.y,h.z),o.set(h.x,l.y,h.z),n.set(l.x,h.y,l.z),r.set(l.x,l.y,h.z),a.copy(h)}toLocalFrame(t,e){const s=u,i=s[0],o=s[1],n=s[2],r=s[3],a=s[4],l=s[5],h=s[6],c=s[7];this.getCorners(i,o,n,r,a,l,h,c);for(let d=0;8!==d;d++){const e=s[d];t.pointToLocal(e,e)}return e.setFromPoints(s)}toWorldFrame(t,e){const s=u,i=s[0],o=s[1],n=s[2],r=s[3],a=s[4],l=s[5],h=s[6],c=s[7];this.getCorners(i,o,n,r,a,l,h,c);for(let d=0;8!==d;d++){const e=s[d];t.pointToWorld(e,e)}return e.setFromPoints(s)}overlapsRay(t){const{direction:e,from:s}=t,i=1/e.x,o=1/e.y,n=1/e.z,r=(this.lowerBound.x-s.x)*i,a=(this.upperBound.x-s.x)*i,l=(this.lowerBound.y-s.y)*o,h=(this.upperBound.y-s.y)*o,c=(this.lowerBound.z-s.z)*n,d=(this.upperBound.z-s.z)*n,u=Math.max(Math.max(Math.min(r,a),Math.min(l,h)),Math.min(c,d)),p=Math.min(Math.min(Math.max(r,a),Math.max(l,h)),Math.max(c,d));return!(p<0)&&!(u>p)}}const d=new r,u=[new r,new r,new r,new r,new r,new r,new r,new r];class p{constructor(){this.matrix=[]}get(t,e){let{index:s}=t,{index:i}=e;if(i>s){const t=i;i=s,s=t}return this.matrix[(s*(s+1)>>1)+i-1]}set(t,e,s){let{index:i}=t,{index:o}=e;if(o>i){const t=o;o=i,i=t}this.matrix[(i*(i+1)>>1)+o-1]=s?1:0}reset(){for(let t=0,e=this.matrix.length;t!==e;t++)this.matrix[t]=0}setNumObjects(t){this.matrix.length=t*(t-1)>>1}}class y{addEventListener(t,e){void 0===this._listeners&&(this._listeners={});const s=this._listeners;return void 0===s[t]&&(s[t]=[]),s[t].includes(e)||s[t].push(e),this}hasEventListener(t,e){if(void 0===this._listeners)return!1;const s=this._listeners;return!(void 0===s[t]||!s[t].includes(e))}hasAnyEventListener(t){if(void 0===this._listeners)return!1;return void 0!==this._listeners[t]}removeEventListener(t,e){if(void 0===this._listeners)return this;const s=this._listeners;if(void 0===s[t])return this;const i=s[t].indexOf(e);return-1!==i&&s[t].splice(i,1),this}dispatchEvent(t){if(void 0===this._listeners)return this;const e=this._listeners[t.type];if(void 0!==e){t.target=this;for(let s=0,i=e.length;s<i;s++)e[s].call(this,t)}return this}}class v{constructor(t,e,s,i){void 0===t&&(t=0),void 0===e&&(e=0),void 0===s&&(s=0),void 0===i&&(i=1),this.x=t,this.y=e,this.z=s,this.w=i}set(t,e,s,i){return this.x=t,this.y=e,this.z=s,this.w=i,this}toString(){return`${this.x},${this.y},${this.z},${this.w}`}toArray(){return[this.x,this.y,this.z,this.w]}setFromAxisAngle(t,e){const s=Math.sin(.5*e);return this.x=t.x*s,this.y=t.y*s,this.z=t.z*s,this.w=Math.cos(.5*e),this}toAxisAngle(t){void 0===t&&(t=new r),this.normalize();const e=2*Math.acos(this.w),s=Math.sqrt(1-this.w*this.w);return s<.001?(t.x=this.x,t.y=this.y,t.z=this.z):(t.x=this.x/s,t.y=this.y/s,t.z=this.z/s),[t,e]}setFromVectors(t,e){if(t.isAntiparallelTo(e)){const e=m,s=g;t.tangents(e,s),this.setFromAxisAngle(e,Math.PI)}else{const s=t.cross(e);this.x=s.x,this.y=s.y,this.z=s.z,this.w=Math.sqrt(t.length()**2*e.length()**2)+t.dot(e),this.normalize()}return this}mult(t,e){void 0===e&&(e=new v);const s=this.x,i=this.y,o=this.z,n=this.w,r=t.x,a=t.y,l=t.z,h=t.w;return e.x=s*h+n*r+i*l-o*a,e.y=i*h+n*a+o*r-s*l,e.z=o*h+n*l+s*a-i*r,e.w=n*h-s*r-i*a-o*l,e}inverse(t){void 0===t&&(t=new v);const e=this.x,s=this.y,i=this.z,o=this.w;this.conjugate(t);const n=1/(e*e+s*s+i*i+o*o);return t.x*=n,t.y*=n,t.z*=n,t.w*=n,t}conjugate(t){return void 0===t&&(t=new v),t.x=-this.x,t.y=-this.y,t.z=-this.z,t.w=this.w,t}normalize(){let t=Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w);return 0===t?(this.x=0,this.y=0,this.z=0,this.w=0):(t=1/t,this.x*=t,this.y*=t,this.z*=t,this.w*=t),this}normalizeFast(){const t=(3-(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w))/2;return 0===t?(this.x=0,this.y=0,this.z=0,this.w=0):(this.x*=t,this.y*=t,this.z*=t,this.w*=t),this}vmult(t,e){void 0===e&&(e=new r);const s=t.x,i=t.y,o=t.z,n=this.x,a=this.y,l=this.z,h=this.w,c=h*s+a*o-l*i,d=h*i+l*s-n*o,u=h*o+n*i-a*s,p=-n*s-a*i-l*o;return e.x=c*h+p*-n+d*-l-u*-a,e.y=d*h+p*-a+u*-n-c*-l,e.z=u*h+p*-l+c*-a-d*-n,e}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this.w=t.w,this}toEuler(t,e){let s,i,o;void 0===e&&(e="YZX");const n=this.x,r=this.y,a=this.z,l=this.w;if("YZX"!==e)throw new Error(`Euler order ${e} not supported yet.`);{const t=n*r+a*l;if(t>.499&&(s=2*Math.atan2(n,l),i=Math.PI/2,o=0),t<-.499&&(s=-2*Math.atan2(n,l),i=-Math.PI/2,o=0),void 0===s){const e=n*n,h=r*r,c=a*a;s=Math.atan2(2*r*l-2*n*a,1-2*h-2*c),i=Math.asin(2*t),o=Math.atan2(2*n*l-2*r*a,1-2*e-2*c)}}t.y=s,t.z=i,t.x=o}setFromEuler(t,e,s,i){void 0===i&&(i="XYZ");const o=Math.cos(t/2),n=Math.cos(e/2),r=Math.cos(s/2),a=Math.sin(t/2),l=Math.sin(e/2),h=Math.sin(s/2);return"XYZ"===i?(this.x=a*n*r+o*l*h,this.y=o*l*r-a*n*h,this.z=o*n*h+a*l*r,this.w=o*n*r-a*l*h):"YXZ"===i?(this.x=a*n*r+o*l*h,this.y=o*l*r-a*n*h,this.z=o*n*h-a*l*r,this.w=o*n*r+a*l*h):"ZXY"===i?(this.x=a*n*r-o*l*h,this.y=o*l*r+a*n*h,this.z=o*n*h+a*l*r,this.w=o*n*r-a*l*h):"ZYX"===i?(this.x=a*n*r-o*l*h,this.y=o*l*r+a*n*h,this.z=o*n*h-a*l*r,this.w=o*n*r+a*l*h):"YZX"===i?(this.x=a*n*r+o*l*h,this.y=o*l*r+a*n*h,this.z=o*n*h-a*l*r,this.w=o*n*r-a*l*h):"XZY"===i&&(this.x=a*n*r-o*l*h,this.y=o*l*r-a*n*h,this.z=o*n*h+a*l*r,this.w=o*n*r+a*l*h),this}clone(){return new v(this.x,this.y,this.z,this.w)}slerp(t,e,s){void 0===s&&(s=new v);const i=this.x,o=this.y,n=this.z,r=this.w;let a,l,h,c,d,u=t.x,p=t.y,y=t.z,m=t.w;return l=i*u+o*p+n*y+r*m,l<0&&(l=-l,u=-u,p=-p,y=-y,m=-m),1-l>1e-6?(a=Math.acos(l),h=Math.sin(a),c=Math.sin((1-e)*a)/h,d=Math.sin(e*a)/h):(c=1-e,d=e),s.x=c*i+d*u,s.y=c*o+d*p,s.z=c*n+d*y,s.w=c*r+d*m,s}integrate(t,e,s,i){void 0===i&&(i=new v);const o=t.x*s.x,n=t.y*s.y,r=t.z*s.z,a=this.x,l=this.y,h=this.z,c=this.w,d=.5*e;return i.x+=d*(o*c+n*h-r*l),i.y+=d*(n*c+r*a-o*h),i.z+=d*(r*c+o*l-n*a),i.w+=d*(-o*a-n*l-r*h),i}}const m=new r,g=new r,w={SPHERE:1,PLANE:2,BOX:4,COMPOUND:8,CONVEXPOLYHEDRON:16,HEIGHTFIELD:32,PARTICLE:64,CYLINDER:128,TRIMESH:256};class f{constructor(t){void 0===t&&(t={}),this.id=f.idCounter++,this.type=t.type||0,this.boundingSphereRadius=0,this.collisionResponse=!t.collisionResponse||t.collisionResponse,this.collisionFilterGroup=void 0!==t.collisionFilterGroup?t.collisionFilterGroup:1,this.collisionFilterMask=void 0!==t.collisionFilterMask?t.collisionFilterMask:-1,this.material=t.material?t.material:null,this.body=null}updateBoundingSphereRadius(){throw`computeBoundingSphereRadius() not implemented for shape type ${this.type}`}volume(){throw`volume() not implemented for shape type ${this.type}`}calculateLocalInertia(t,e){throw`calculateLocalInertia() not implemented for shape type ${this.type}`}calculateWorldAABB(t,e,s,i){throw`calculateWorldAABB() not implemented for shape type ${this.type}`}}f.idCounter=0,f.types=w;class x{constructor(t){void 0===t&&(t={}),this.position=new r,this.quaternion=new v,t.position&&this.position.copy(t.position),t.quaternion&&this.quaternion.copy(t.quaternion)}pointToLocal(t,e){return x.pointToLocalFrame(this.position,this.quaternion,t,e)}pointToWorld(t,e){return x.pointToWorldFrame(this.position,this.quaternion,t,e)}vectorToWorldFrame(t,e){return void 0===e&&(e=new r),this.quaternion.vmult(t,e),e}static pointToLocalFrame(t,e,s,i){return void 0===i&&(i=new r),s.vsub(t,i),e.conjugate(b),b.vmult(i,i),i}static pointToWorldFrame(t,e,s,i){return void 0===i&&(i=new r),e.vmult(s,i),i.vadd(t,i),i}static vectorToWorldFrame(t,e,s){return void 0===s&&(s=new r),t.vmult(e,s),s}static vectorToLocalFrame(t,e,s,i){return void 0===i&&(i=new r),e.w*=-1,e.vmult(s,i),e.w*=-1,i}}const b=new v;class B extends f{constructor(t){void 0===t&&(t={});const{vertices:e=[],faces:s=[],normals:i=[],axes:o,boundingSphereRadius:n}=t;super({type:f.types.CONVEXPOLYHEDRON}),this.vertices=e,this.faces=s,this.faceNormals=i,0===this.faceNormals.length&&this.computeNormals(),n?this.boundingSphereRadius=n:this.updateBoundingSphereRadius(),this.worldVertices=[],this.worldVerticesNeedsUpdate=!0,this.worldFaceNormals=[],this.worldFaceNormalsNeedsUpdate=!0,this.uniqueAxes=o?o.slice():null,this.uniqueEdges=[],this.computeEdges()}computeEdges(){const t=this.faces,e=this.vertices,s=this.uniqueEdges;s.length=0;const i=new r;for(let o=0;o!==t.length;o++){const n=t[o],r=n.length;for(let t=0;t!==r;t++){const o=(t+1)%r;e[n[t]].vsub(e[n[o]],i),i.normalize();let a=!1;for(let t=0;t!==s.length;t++)if(s[t].almostEquals(i)||s[t].almostEquals(i)){a=!0;break}a||s.push(i.clone())}}}computeNormals(){this.faceNormals.length=this.faces.length;for(let t=0;t<this.faces.length;t++){for(let i=0;i<this.faces[t].length;i++)if(!this.vertices[this.faces[t][i]])throw new Error(`Vertex ${this.faces[t][i]} not found!`);const e=this.faceNormals[t]||new r;this.getFaceNormal(t,e),e.negate(e),this.faceNormals[t]=e;const s=this.vertices[this.faces[t][0]];if(e.dot(s)<0){console.error(`.faceNormals[${t}] = Vec3(${e.toString()}) looks like it points into the shape? The vertices follow. Make sure they are ordered CCW around the normal, using the right hand rule.`);for(let e=0;e<this.faces[t].length;e++)console.warn(`.vertices[${this.faces[t][e]}] = Vec3(${this.vertices[this.faces[t][e]].toString()})`)}}}getFaceNormal(t,e){const s=this.faces[t],i=this.vertices[s[0]],o=this.vertices[s[1]],n=this.vertices[s[2]];B.computeNormal(i,o,n,e)}static computeNormal(t,e,s,i){const o=new r,n=new r;e.vsub(t,n),s.vsub(e,o),o.cross(n,i),i.isZero()||i.normalize()}clipAgainstHull(t,e,s,i,o,n,a,l,h){const c=new r;let d=-1,u=-Number.MAX_VALUE;for(let r=0;r<s.faces.length;r++){c.copy(s.faceNormals[r]),o.vmult(c,c);const t=c.dot(n);t>u&&(u=t,d=r)}const p=[];for(let y=0;y<s.faces[d].length;y++){const t=s.vertices[s.faces[d][y]],e=new r;e.copy(t),o.vmult(e,e),i.vadd(e,e),p.push(e)}d>=0&&this.clipFaceAgainstHull(n,t,e,p,a,l,h)}findSeparatingAxis(t,e,s,i,o,n,a,l){const h=new r,c=new r,d=new r,u=new r,p=new r,y=new r;let v=Number.MAX_VALUE;const m=this;if(m.uniqueAxes)for(let r=0;r!==m.uniqueAxes.length;r++){s.vmult(m.uniqueAxes[r],h);const a=m.testSepAxis(h,t,e,s,i,o);if(!1===a)return!1;a<v&&(v=a,n.copy(h))}else{const r=a?a.length:m.faces.length;for(let l=0;l<r;l++){const r=a?a[l]:l;h.copy(m.faceNormals[r]),s.vmult(h,h);const c=m.testSepAxis(h,t,e,s,i,o);if(!1===c)return!1;c<v&&(v=c,n.copy(h))}}if(t.uniqueAxes)for(let r=0;r!==t.uniqueAxes.length;r++){o.vmult(t.uniqueAxes[r],c);const a=m.testSepAxis(c,t,e,s,i,o);if(!1===a)return!1;a<v&&(v=a,n.copy(c))}else{const r=l?l.length:t.faces.length;for(let a=0;a<r;a++){const r=l?l[a]:a;c.copy(t.faceNormals[r]),o.vmult(c,c);const h=m.testSepAxis(c,t,e,s,i,o);if(!1===h)return!1;h<v&&(v=h,n.copy(c))}}for(let r=0;r!==m.uniqueEdges.length;r++){s.vmult(m.uniqueEdges[r],u);for(let r=0;r!==t.uniqueEdges.length;r++)if(o.vmult(t.uniqueEdges[r],p),u.cross(p,y),!y.almostZero()){y.normalize();const r=m.testSepAxis(y,t,e,s,i,o);if(!1===r)return!1;r<v&&(v=r,n.copy(y))}}return i.vsub(e,d),d.dot(n)>0&&n.negate(n),!0}testSepAxis(t,e,s,i,o,n){B.project(this,t,s,i,A),B.project(e,t,o,n,E);const r=A[0],a=A[1],l=E[0],h=E[1];if(r<h||l<a)return!1;const c=r-h,d=l-a;return c<d?c:d}calculateLocalInertia(t,e){const s=new r,i=new r;this.computeLocalAABB(i,s);const o=s.x-i.x,n=s.y-i.y,a=s.z-i.z;e.x=1/12*t*(2*n*2*n+2*a*2*a),e.y=1/12*t*(2*o*2*o+2*a*2*a),e.z=1/12*t*(2*n*2*n+2*o*2*o)}getPlaneConstantOfFace(t){const e=this.faces[t],s=this.faceNormals[t],i=this.vertices[e[0]];return-s.dot(i)}clipFaceAgainstHull(t,e,s,i,o,n,a){const l=new r,h=new r,c=new r,d=new r,u=new r,p=new r,y=new r,v=new r,m=this,g=i,w=[];let f=-1,x=Number.MAX_VALUE;for(let r=0;r<m.faces.length;r++){l.copy(m.faceNormals[r]),s.vmult(l,l);const e=l.dot(t);e<x&&(x=e,f=r)}if(f<0)return;const b=m.faces[f];b.connectedFaces=[];for(let r=0;r<m.faces.length;r++)for(let t=0;t<m.faces[r].length;t++)-1!==b.indexOf(m.faces[r][t])&&r!==f&&-1===b.connectedFaces.indexOf(r)&&b.connectedFaces.push(r);const B=b.length;for(let r=0;r<B;r++){const t=m.vertices[b[r]],i=m.vertices[b[(r+1)%B]];t.vsub(i,h),c.copy(h),s.vmult(c,c),e.vadd(c,c),d.copy(this.faceNormals[f]),s.vmult(d,d),e.vadd(d,d),c.cross(d,u),u.negate(u),p.copy(t),s.vmult(p,p),e.vadd(p,p);const o=b.connectedFaces[r];y.copy(this.faceNormals[o]);const n=this.getPlaneConstantOfFace(o);v.copy(y),s.vmult(v,v);const a=n-v.dot(e);for(this.clipFaceAgainstPlane(g,w,v,a);g.length;)g.shift();for(;w.length;)g.push(w.shift())}y.copy(this.faceNormals[f]);const A=this.getPlaneConstantOfFace(f);v.copy(y),s.vmult(v,v);const E=A-v.dot(e);for(let r=0;r<g.length;r++){let t=v.dot(g[r])+E;if(t<=o&&(console.log(`clamped: depth=${t} to minDist=${o}`),t=o),t<=n){const e=g[r];if(t<=1e-6){const s={point:e,normal:v,depth:t};a.push(s)}}}}clipFaceAgainstPlane(t,e,s,i){let o,n;const a=t.length;if(a<2)return e;let l=t[t.length-1],h=t[0];o=s.dot(l)+i;for(let c=0;c<a;c++){if(h=t[c],n=s.dot(h)+i,o<0)if(n<0){const t=new r;t.copy(h),e.push(t)}else{const t=new r;l.lerp(h,o/(o-n),t),e.push(t)}else if(n<0){const t=new r;l.lerp(h,o/(o-n),t),e.push(t),e.push(h)}l=h,o=n}return e}computeWorldVertices(t,e){for(;this.worldVertices.length<this.vertices.length;)this.worldVertices.push(new r);const s=this.vertices,i=this.worldVertices;for(let o=0;o!==this.vertices.length;o++)e.vmult(s[o],i[o]),t.vadd(i[o],i[o]);this.worldVerticesNeedsUpdate=!1}computeLocalAABB(t,e){const s=this.vertices;t.set(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),e.set(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE);for(let i=0;i<this.vertices.length;i++){const o=s[i];o.x<t.x?t.x=o.x:o.x>e.x&&(e.x=o.x),o.y<t.y?t.y=o.y:o.y>e.y&&(e.y=o.y),o.z<t.z?t.z=o.z:o.z>e.z&&(e.z=o.z)}}computeWorldFaceNormals(t){const e=this.faceNormals.length;for(;this.worldFaceNormals.length<e;)this.worldFaceNormals.push(new r);const s=this.faceNormals,i=this.worldFaceNormals;for(let o=0;o!==e;o++)t.vmult(s[o],i[o]);this.worldFaceNormalsNeedsUpdate=!1}updateBoundingSphereRadius(){let t=0;const e=this.vertices;for(let s=0;s!==e.length;s++){const i=e[s].lengthSquared();i>t&&(t=i)}this.boundingSphereRadius=Math.sqrt(t)}calculateWorldAABB(t,e,s,i){const o=this.vertices;let n,a,l,h,c,d,u=new r;for(let r=0;r<o.length;r++){u.copy(o[r]),e.vmult(u,u),t.vadd(u,u);const s=u;(void 0===n||s.x<n)&&(n=s.x),(void 0===h||s.x>h)&&(h=s.x),(void 0===a||s.y<a)&&(a=s.y),(void 0===c||s.y>c)&&(c=s.y),(void 0===l||s.z<l)&&(l=s.z),(void 0===d||s.z>d)&&(d=s.z)}s.set(n,a,l),i.set(h,c,d)}volume(){return 4*Math.PI*this.boundingSphereRadius/3}getAveragePointLocal(t){void 0===t&&(t=new r);const e=this.vertices;for(let s=0;s<e.length;s++)t.vadd(e[s],t);return t.scale(1/e.length,t),t}transformAllPoints(t,e){const s=this.vertices.length,i=this.vertices;if(e){for(let t=0;t<s;t++){const s=i[t];e.vmult(s,s)}for(let t=0;t<this.faceNormals.length;t++){const s=this.faceNormals[t];e.vmult(s,s)}}if(t)for(let o=0;o<s;o++){const e=i[o];e.vadd(t,e)}}pointIsInside(t){const e=this.vertices,s=this.faces,i=this.faceNormals,o=new r;this.getAveragePointLocal(o);for(let n=0;n<this.faces.length;n++){let a=i[n];const l=e[s[n][0]],h=new r;t.vsub(l,h);const c=a.dot(h),d=new r;o.vsub(l,d);const u=a.dot(d);if(c<0&&u>0||c>0&&u<0)return!1}return-1}static project(t,e,s,i,o){const n=t.vertices.length,r=S;let a=0,l=0;const h=z,c=t.vertices;h.setZero(),x.vectorToLocalFrame(s,i,e,r),x.pointToLocalFrame(s,i,h,h);const d=h.dot(r);l=a=c[0].dot(r);for(let u=1;u<n;u++){const t=c[u].dot(r);t>a&&(a=t),t<l&&(l=t)}if(l-=d,a-=d,l>a){const t=l;l=a,a=t}o[0]=a,o[1]=l}}const A=[],E=[],S=(new r,new r),z=new r;class C extends f{constructor(t){super({type:f.types.BOX}),this.halfExtents=t,this.convexPolyhedronRepresentation=null,this.updateConvexPolyhedronRepresentation(),this.updateBoundingSphereRadius()}updateConvexPolyhedronRepresentation(){const t=this.halfExtents.x,e=this.halfExtents.y,s=this.halfExtents.z,i=r,o=[new i(-t,-e,-s),new i(t,-e,-s),new i(t,e,-s),new i(-t,e,-s),new i(-t,-e,s),new i(t,-e,s),new i(t,e,s),new i(-t,e,s)],n=[new i(0,0,1),new i(0,1,0),new i(1,0,0)],a=new B({vertices:o,faces:[[3,2,1,0],[4,5,6,7],[5,4,0,1],[2,3,7,6],[0,4,7,3],[1,2,6,5]],axes:n});this.convexPolyhedronRepresentation=a,a.material=this.material}calculateLocalInertia(t,e){return void 0===e&&(e=new r),C.calculateInertia(this.halfExtents,t,e),e}static calculateInertia(t,e,s){const i=t;s.x=1/12*e*(2*i.y*2*i.y+2*i.z*2*i.z),s.y=1/12*e*(2*i.x*2*i.x+2*i.z*2*i.z),s.z=1/12*e*(2*i.y*2*i.y+2*i.x*2*i.x)}getSideNormals(t,e){const s=t,i=this.halfExtents;if(s[0].set(i.x,0,0),s[1].set(0,i.y,0),s[2].set(0,0,i.z),s[3].set(-i.x,0,0),s[4].set(0,-i.y,0),s[5].set(0,0,-i.z),void 0!==e)for(let o=0;o!==s.length;o++)e.vmult(s[o],s[o]);return s}volume(){return 8*this.halfExtents.x*this.halfExtents.y*this.halfExtents.z}updateBoundingSphereRadius(){this.boundingSphereRadius=this.halfExtents.length()}forEachWorldCorner(t,e,s){const i=this.halfExtents,o=[[i.x,i.y,i.z],[-i.x,i.y,i.z],[-i.x,-i.y,i.z],[-i.x,-i.y,-i.z],[i.x,-i.y,-i.z],[i.x,i.y,-i.z],[-i.x,i.y,-i.z],[i.x,-i.y,i.z]];for(let n=0;n<o.length;n++)F.set(o[n][0],o[n][1],o[n][2]),e.vmult(F,F),t.vadd(F,F),s(F.x,F.y,F.z)}calculateWorldAABB(t,e,s,i){const o=this.halfExtents;M[0].set(o.x,o.y,o.z),M[1].set(-o.x,o.y,o.z),M[2].set(-o.x,-o.y,o.z),M[3].set(-o.x,-o.y,-o.z),M[4].set(o.x,-o.y,-o.z),M[5].set(o.x,o.y,-o.z),M[6].set(-o.x,o.y,-o.z),M[7].set(o.x,-o.y,o.z);const n=M[0];e.vmult(n,n),t.vadd(n,n),i.copy(n),s.copy(n);for(let r=1;r<8;r++){const o=M[r];e.vmult(o,o),t.vadd(o,o);const n=o.x,a=o.y,l=o.z;n>i.x&&(i.x=n),a>i.y&&(i.y=a),l>i.z&&(i.z=l),n<s.x&&(s.x=n),a<s.y&&(s.y=a),l<s.z&&(s.z=l)}}}const F=new r,M=[new r,new r,new r,new r,new r,new r,new r,new r],R={DYNAMIC:1,STATIC:2,KINEMATIC:4},T={AWAKE:0,SLEEPY:1,SLEEPING:2};class I extends y{constructor(t){void 0===t&&(t={}),super(),this.id=I.idCounter++,this.index=-1,this.world=null,this.vlambda=new r,this.collisionFilterGroup="number"==typeof t.collisionFilterGroup?t.collisionFilterGroup:1,this.collisionFilterMask="number"==typeof t.collisionFilterMask?t.collisionFilterMask:-1,this.collisionResponse="boolean"!=typeof t.collisionResponse||t.collisionResponse,this.position=new r,this.previousPosition=new r,this.interpolatedPosition=new r,this.initPosition=new r,t.position&&(this.position.copy(t.position),this.previousPosition.copy(t.position),this.interpolatedPosition.copy(t.position),this.initPosition.copy(t.position)),this.velocity=new r,t.velocity&&this.velocity.copy(t.velocity),this.initVelocity=new r,this.force=new r;const e="number"==typeof t.mass?t.mass:0;this.mass=e,this.invMass=e>0?1/e:0,this.material=t.material||null,this.linearDamping="number"==typeof t.linearDamping?t.linearDamping:.01,this.type=e<=0?I.STATIC:I.DYNAMIC,typeof t.type==typeof I.STATIC&&(this.type=t.type),this.allowSleep=void 0===t.allowSleep||t.allowSleep,this.sleepState=I.AWAKE,this.sleepSpeedLimit=void 0!==t.sleepSpeedLimit?t.sleepSpeedLimit:.1,this.sleepTimeLimit=void 0!==t.sleepTimeLimit?t.sleepTimeLimit:1,this.timeLastSleepy=0,this.wakeUpAfterNarrowphase=!1,this.torque=new r,this.quaternion=new v,this.initQuaternion=new v,this.previousQuaternion=new v,this.interpolatedQuaternion=new v,t.quaternion&&(this.quaternion.copy(t.quaternion),this.initQuaternion.copy(t.quaternion),this.previousQuaternion.copy(t.quaternion),this.interpolatedQuaternion.copy(t.quaternion)),this.angularVelocity=new r,t.angularVelocity&&this.angularVelocity.copy(t.angularVelocity),this.initAngularVelocity=new r,this.shapes=[],this.shapeOffsets=[],this.shapeOrientations=[],this.inertia=new r,this.invInertia=new r,this.invInertiaWorld=new o,this.invMassSolve=0,this.invInertiaSolve=new r,this.invInertiaWorldSolve=new o,this.fixedRotation=void 0!==t.fixedRotation&&t.fixedRotation,this.angularDamping=void 0!==t.angularDamping?t.angularDamping:.01,this.linearFactor=new r(1,1,1),t.linearFactor&&this.linearFactor.copy(t.linearFactor),this.angularFactor=new r(1,1,1),t.angularFactor&&this.angularFactor.copy(t.angularFactor),this.aabb=new c,this.aabbNeedsUpdate=!0,this.boundingRadius=0,this.wlambda=new r,this.isTrigger=Boolean(t.isTrigger),t.shape&&this.addShape(t.shape),this.updateMassProperties()}wakeUp(){const t=this.sleepState;this.sleepState=I.AWAKE,this.wakeUpAfterNarrowphase=!1,t===I.SLEEPING&&this.dispatchEvent(I.wakeupEvent)}sleep(){this.sleepState=I.SLEEPING,this.velocity.set(0,0,0),this.angularVelocity.set(0,0,0),this.wakeUpAfterNarrowphase=!1}sleepTick(t){if(this.allowSleep){const e=this.sleepState,s=this.velocity.lengthSquared()+this.angularVelocity.lengthSquared(),i=this.sleepSpeedLimit**2;e===I.AWAKE&&s<i?(this.sleepState=I.SLEEPY,this.timeLastSleepy=t,this.dispatchEvent(I.sleepyEvent)):e===I.SLEEPY&&s>i?this.wakeUp():e===I.SLEEPY&&t-this.timeLastSleepy>this.sleepTimeLimit&&(this.sleep(),this.dispatchEvent(I.sleepEvent))}}updateSolveMassProperties(){this.sleepState===I.SLEEPING||this.type===I.KINEMATIC?(this.invMassSolve=0,this.invInertiaSolve.setZero(),this.invInertiaWorldSolve.setZero()):(this.invMassSolve=this.invMass,this.invInertiaSolve.copy(this.invInertia),this.invInertiaWorldSolve.copy(this.invInertiaWorld))}pointToLocalFrame(t,e){return void 0===e&&(e=new r),t.vsub(this.position,e),this.quaternion.conjugate().vmult(e,e),e}vectorToLocalFrame(t,e){return void 0===e&&(e=new r),this.quaternion.conjugate().vmult(t,e),e}pointToWorldFrame(t,e){return void 0===e&&(e=new r),this.quaternion.vmult(t,e),e.vadd(this.position,e),e}vectorToWorldFrame(t,e){return void 0===e&&(e=new r),this.quaternion.vmult(t,e),e}addShape(t,e,s){const i=new r,o=new v;return e&&i.copy(e),s&&o.copy(s),this.shapes.push(t),this.shapeOffsets.push(i),this.shapeOrientations.push(o),this.updateMassProperties(),this.updateBoundingRadius(),this.aabbNeedsUpdate=!0,t.body=this,this}removeShape(t){const e=this.shapes.indexOf(t);return-1===e?(console.warn("Shape does not belong to the body"),this):(this.shapes.splice(e,1),this.shapeOffsets.splice(e,1),this.shapeOrientations.splice(e,1),this.updateMassProperties(),this.updateBoundingRadius(),this.aabbNeedsUpdate=!0,t.body=null,this)}updateBoundingRadius(){const t=this.shapes,e=this.shapeOffsets,s=t.length;let i=0;for(let o=0;o!==s;o++){const s=t[o];s.updateBoundingSphereRadius();const n=e[o].length(),r=s.boundingSphereRadius;n+r>i&&(i=n+r)}this.boundingRadius=i}updateAABB(){const t=this.shapes,e=this.shapeOffsets,s=this.shapeOrientations,i=t.length,o=P,n=q,r=this.quaternion,a=this.aabb,l=N;for(let h=0;h!==i;h++){const i=t[h];r.vmult(e[h],o),o.vadd(this.position,o),r.mult(s[h],n),i.calculateWorldAABB(o,n,l.lowerBound,l.upperBound),0===h?a.copy(l):a.extend(l)}this.aabbNeedsUpdate=!1}updateInertiaWorld(t){const e=this.invInertia;if(e.x!==e.y||e.y!==e.z||t){const t=L,s=W;t.setRotationFromQuaternion(this.quaternion),t.transpose(s),t.scale(e,t),t.mmult(s,this.invInertiaWorld)}else;}applyForce(t,e){if(void 0===e&&(e=new r),this.type!==I.DYNAMIC)return;this.sleepState===I.SLEEPING&&this.wakeUp();const s=V;e.cross(t,s),this.force.vadd(t,this.force),this.torque.vadd(s,this.torque)}applyLocalForce(t,e){if(void 0===e&&(e=new r),this.type!==I.DYNAMIC)return;const s=j,i=O;this.vectorToWorldFrame(t,s),this.vectorToWorldFrame(e,i),this.applyForce(s,i)}applyTorque(t){this.type===I.DYNAMIC&&(this.sleepState===I.SLEEPING&&this.wakeUp(),this.torque.vadd(t,this.torque))}applyImpulse(t,e){if(void 0===e&&(e=new r),this.type!==I.DYNAMIC)return;this.sleepState===I.SLEEPING&&this.wakeUp();const s=e,i=k;i.copy(t),i.scale(this.invMass,i),this.velocity.vadd(i,this.velocity);const o=_;s.cross(t,o),this.invInertiaWorld.vmult(o,o),this.angularVelocity.vadd(o,this.angularVelocity)}applyLocalImpulse(t,e){if(void 0===e&&(e=new r),this.type!==I.DYNAMIC)return;const s=H,i=D;this.vectorToWorldFrame(t,s),this.vectorToWorldFrame(e,i),this.applyImpulse(s,i)}updateMassProperties(){const t=U;this.invMass=this.mass>0?1/this.mass:0;const e=this.inertia,s=this.fixedRotation;this.updateAABB(),t.set((this.aabb.upperBound.x-this.aabb.lowerBound.x)/2,(this.aabb.upperBound.y-this.aabb.lowerBound.y)/2,(this.aabb.upperBound.z-this.aabb.lowerBound.z)/2),C.calculateInertia(t,this.mass,e),this.invInertia.set(e.x>0&&!s?1/e.x:0,e.y>0&&!s?1/e.y:0,e.z>0&&!s?1/e.z:0),this.updateInertiaWorld(!0)}getVelocityAtWorldPoint(t,e){const s=new r;return t.vsub(this.position,s),this.angularVelocity.cross(s,e),this.velocity.vadd(e,e),e}integrate(t,e,s){if(this.previousPosition.copy(this.position),this.previousQuaternion.copy(this.quaternion),this.type!==I.DYNAMIC&&this.type!==I.KINEMATIC||this.sleepState===I.SLEEPING)return;const i=this.velocity,o=this.angularVelocity,n=this.position,r=this.force,a=this.torque,l=this.quaternion,h=this.invMass,c=this.invInertiaWorld,d=this.linearFactor,u=h*t;i.x+=r.x*u*d.x,i.y+=r.y*u*d.y,i.z+=r.z*u*d.z;const p=c.elements,y=this.angularFactor,v=a.x*y.x,m=a.y*y.y,g=a.z*y.z;o.x+=t*(p[0]*v+p[1]*m+p[2]*g),o.y+=t*(p[3]*v+p[4]*m+p[5]*g),o.z+=t*(p[6]*v+p[7]*m+p[8]*g),n.x+=i.x*t,n.y+=i.y*t,n.z+=i.z*t,l.integrate(this.angularVelocity,t,this.angularFactor,l),e&&(s?l.normalizeFast():l.normalize()),this.aabbNeedsUpdate=!0,this.updateInertiaWorld()}}I.idCounter=0,I.COLLIDE_EVENT_NAME="collide",I.DYNAMIC=R.DYNAMIC,I.STATIC=R.STATIC,I.KINEMATIC=R.KINEMATIC,I.AWAKE=T.AWAKE,I.SLEEPY=T.SLEEPY,I.SLEEPING=T.SLEEPING,I.wakeupEvent={type:"wakeup"},I.sleepyEvent={type:"sleepy"},I.sleepEvent={type:"sleep"};const P=new r,q=new v,N=new c,L=new o,W=new o,V=(new o,new r),j=new r,O=new r,k=new r,_=new r,H=new r,D=new r,U=new r;class G{constructor(){this.world=null,this.useBoundingBoxes=!1,this.dirty=!0}collisionPairs(t,e,s){throw new Error("collisionPairs not implemented for this BroadPhase class!")}needBroadphaseCollision(t,e){return 0!=(t.collisionFilterGroup&e.collisionFilterMask)&&0!=(e.collisionFilterGroup&t.collisionFilterMask)&&(0==(t.type&I.STATIC)&&t.sleepState!==I.SLEEPING||0==(e.type&I.STATIC)&&e.sleepState!==I.SLEEPING)}intersectionTest(t,e,s,i){this.useBoundingBoxes?this.doBoundingBoxBroadphase(t,e,s,i):this.doBoundingSphereBroadphase(t,e,s,i)}doBoundingSphereBroadphase(t,e,s,i){const o=Y;e.position.vsub(t.position,o);const n=(t.boundingRadius+e.boundingRadius)**2;o.lengthSquared()<n&&(s.push(t),i.push(e))}doBoundingBoxBroadphase(t,e,s,i){t.aabbNeedsUpdate&&t.updateAABB(),e.aabbNeedsUpdate&&e.updateAABB(),t.aabb.overlaps(e.aabb)&&(s.push(t),i.push(e))}makePairsUnique(t,e){const s=X,i=$,o=K,n=t.length;for(let r=0;r!==n;r++)i[r]=t[r],o[r]=e[r];t.length=0,e.length=0;for(let r=0;r!==n;r++){const t=i[r].id,e=o[r].id,n=t<e?`${t},${e}`:`${e},${t}`;s[n]=r,s.keys.push(n)}for(let r=0;r!==s.keys.length;r++){const n=s.keys.pop(),r=s[n];t.push(i[r]),e.push(o[r]),delete s[n]}}setWorld(t){}static boundingSphereCheck(t,e){const s=new r;t.position.vsub(e.position,s);const i=t.shapes[0],o=e.shapes[0];return Math.pow(i.boundingSphereRadius+o.boundingSphereRadius,2)>s.lengthSquared()}aabbQuery(t,e,s){return console.warn(".aabbQuery is not implemented in this Broadphase subclass."),[]}}const Y=new r;new r,new v,new r;const X={keys:[]},$=[],K=[];new r;class Z extends G{constructor(t,e,s,i,o){void 0===t&&(t=new r(100,100,100)),void 0===e&&(e=new r(-100,-100,-100)),void 0===s&&(s=10),void 0===i&&(i=10),void 0===o&&(o=10),super(),this.nx=s,this.ny=i,this.nz=o,this.aabbMin=t,this.aabbMax=e;const n=this.nx*this.ny*this.nz;if(n<=0)throw"GridBroadphase: Each dimension's n must be >0";this.bins=[],this.binLengths=[],this.bins.length=n,this.binLengths.length=n;for(let r=0;r<n;r++)this.bins[r]=[],this.binLengths[r]=0}collisionPairs(t,e,s){const i=t.bodies.length,o=t.bodies,n=this.aabbMax,r=this.aabbMin,a=this.nx,l=this.ny,h=this.nz,c=l*h,d=h,u=n.x,p=n.y,y=n.z,v=r.x,m=r.y,g=r.z,w=a/(u-v),x=l/(p-m),b=h/(y-g),B=(u-v)/a,A=(p-m)/l,E=(y-g)/h,S=.5*Math.sqrt(B*B+A*A+E*E),z=f.types,C=z.SPHERE,F=z.PLANE;z.BOX,z.COMPOUND,z.CONVEXPOLYHEDRON;const M=this.bins,R=this.binLengths,T=this.bins.length;for(let f=0;f!==T;f++)R[f]=0;const I=Math.ceil;function P(t,e,s,i,o,n,r){let u=(t-v)*w|0,p=(e-m)*x|0,y=(s-g)*b|0,f=I((i-v)*w),B=I((o-m)*x),A=I((n-g)*b);u<0?u=0:u>=a&&(u=a-1),p<0?p=0:p>=l&&(p=l-1),y<0?y=0:y>=h&&(y=h-1),f<0?f=0:f>=a&&(f=a-1),B<0?B=0:B>=l&&(B=l-1),A<0?A=0:A>=h&&(A=h-1),u*=c,p*=d,y*=1,f*=c,B*=d,A*=1;for(let a=u;a<=f;a+=c)for(let t=p;t<=B;t+=d)for(let e=y;e<=A;e+=1){const s=a+t+e;M[s][R[s]++]=r}}for(let f=0;f!==i;f++){const t=o[f],e=t.shapes[0];switch(e.type){case C:{const s=e,i=t.position.x,o=t.position.y,n=t.position.z,r=s.radius;P(i-r,o-r,n-r,i+r,o+r,n+r,t);break}case F:{const s=e;s.worldNormalNeedsUpdate&&s.computeWorldNormal(t.quaternion);const i=s.worldNormal,o=v+.5*B-t.position.x,n=m+.5*A-t.position.y,r=g+.5*E-t.position.z,u=Q;u.set(o,n,r);for(let e=0,p=0;e!==a;e++,p+=c,u.y=n,u.x+=B)for(let s=0,o=0;s!==l;s++,o+=d,u.z=r,u.y+=A)for(let e=0,n=0;e!==h;e++,n+=1,u.z+=E)if(u.dot(i)<S){const e=p+o+n;M[e][R[e]++]=t}break}default:t.aabbNeedsUpdate&&t.updateAABB(),P(t.aabb.lowerBound.x,t.aabb.lowerBound.y,t.aabb.lowerBound.z,t.aabb.upperBound.x,t.aabb.upperBound.y,t.aabb.upperBound.z,t)}}for(let f=0;f!==T;f++){const t=R[f];if(t>1){const i=M[f];for(let o=0;o!==t;o++){const t=i[o];for(let n=0;n!==o;n++){const o=i[n];this.needBroadphaseCollision(t,o)&&this.intersectionTest(t,o,e,s)}}}}this.makePairsUnique(e,s)}}const Q=new r;new r;class J extends G{constructor(){super()}collisionPairs(t,e,s){const i=t.bodies,o=i.length;let n,r;for(let a=0;a!==o;a++)for(let t=0;t!==a;t++)n=i[a],r=i[t],this.needBroadphaseCollision(n,r)&&this.intersectionTest(n,r,e,s)}aabbQuery(t,e,s){void 0===s&&(s=[]);for(let i=0;i<t.bodies.length;i++){const o=t.bodies[i];o.aabbNeedsUpdate&&o.updateAABB(),o.aabb.overlaps(e)&&s.push(o)}return s}}class tt{constructor(){this.rayFromWorld=new r,this.rayToWorld=new r,this.hitNormalWorld=new r,this.hitPointWorld=new r,this.hasHit=!1,this.shape=null,this.body=null,this.hitFaceIndex=-1,this.distance=-1,this.shouldStop=!1}reset(){this.rayFromWorld.setZero(),this.rayToWorld.setZero(),this.hitNormalWorld.setZero(),this.hitPointWorld.setZero(),this.hasHit=!1,this.shape=null,this.body=null,this.hitFaceIndex=-1,this.distance=-1,this.shouldStop=!1}abort(){this.shouldStop=!0}set(t,e,s,i,o,n,r){this.rayFromWorld.copy(t),this.rayToWorld.copy(e),this.hitNormalWorld.copy(s),this.hitPointWorld.copy(i),this.shape=o,this.body=n,this.distance=r}}let et,st,it,ot,nt,rt,at;const lt={CLOSEST:1,ANY:2,ALL:4};et=f.types.SPHERE,st=f.types.PLANE,it=f.types.BOX,ot=f.types.CYLINDER,nt=f.types.CONVEXPOLYHEDRON,rt=f.types.HEIGHTFIELD,at=f.types.TRIMESH;class ht{get[et](){return this._intersectSphere}get[st](){return this._intersectPlane}get[it](){return this._intersectBox}get[ot](){return this._intersectConvex}get[nt](){return this._intersectConvex}get[rt](){return this._intersectHeightfield}get[at](){return this._intersectTrimesh}constructor(t,e){void 0===t&&(t=new r),void 0===e&&(e=new r),this.from=t.clone(),this.to=e.clone(),this.direction=new r,this.precision=1e-4,this.checkCollisionResponse=!0,this.skipBackfaces=!1,this.collisionFilterMask=-1,this.collisionFilterGroup=-1,this.mode=ht.ANY,this.result=new tt,this.hasHit=!1,this.callback=t=>{}}intersectWorld(t,e){return this.mode=e.mode||ht.ANY,this.result=e.result||new tt,this.skipBackfaces=!!e.skipBackfaces,this.collisionFilterMask=void 0!==e.collisionFilterMask?e.collisionFilterMask:-1,this.collisionFilterGroup=void 0!==e.collisionFilterGroup?e.collisionFilterGroup:-1,this.checkCollisionResponse=void 0===e.checkCollisionResponse||e.checkCollisionResponse,e.from&&this.from.copy(e.from),e.to&&this.to.copy(e.to),this.callback=e.callback||(()=>{}),this.hasHit=!1,this.result.reset(),this.updateDirection(),this.getAABB(ct),dt.length=0,t.broadphase.aabbQuery(t,ct,dt),this.intersectBodies(dt),this.hasHit}intersectBody(t,e){e&&(this.result=e,this.updateDirection());const s=this.checkCollisionResponse;if(s&&!t.collisionResponse)return;if(0==(this.collisionFilterGroup&t.collisionFilterMask)||0==(t.collisionFilterGroup&this.collisionFilterMask))return;const i=yt,o=vt;for(let n=0,r=t.shapes.length;n<r;n++){const e=t.shapes[n];if((!s||e.collisionResponse)&&(t.quaternion.mult(t.shapeOrientations[n],o),t.quaternion.vmult(t.shapeOffsets[n],i),i.vadd(t.position,i),this.intersectShape(e,o,i,t),this.result.shouldStop))break}}intersectBodies(t,e){e&&(this.result=e,this.updateDirection());for(let s=0,i=t.length;!this.result.shouldStop&&s<i;s++)this.intersectBody(t[s])}updateDirection(){this.to.vsub(this.from,this.direction),this.direction.normalize()}intersectShape(t,e,s,i){const o=function(t,e,s){s.vsub(t,Lt);const i=Lt.dot(e);e.scale(i,Wt),Wt.vadd(t,Wt);return s.distanceTo(Wt)}(this.from,this.direction,s);if(o>t.boundingSphereRadius)return;const n=this[t.type];n&&n.call(this,t,e,s,i,t)}_intersectBox(t,e,s,i,o){return this._intersectConvex(t.convexPolyhedronRepresentation,e,s,i,o)}_intersectPlane(t,e,s,i,o){const n=this.from,a=this.to,l=this.direction,h=new r(0,0,1);e.vmult(h,h);const c=new r;n.vsub(s,c);const d=c.dot(h);a.vsub(s,c);if(d*c.dot(h)>0)return;if(n.distanceTo(a)<d)return;const u=h.dot(l);if(Math.abs(u)<this.precision)return;const p=new r,y=new r,v=new r;n.vsub(s,p);const m=-h.dot(p)/u;l.scale(m,y),n.vadd(y,v),this.reportIntersection(h,v,o,i,-1)}getAABB(t){const{lowerBound:e,upperBound:s}=t,i=this.to,o=this.from;e.x=Math.min(i.x,o.x),e.y=Math.min(i.y,o.y),e.z=Math.min(i.z,o.z),s.x=Math.max(i.x,o.x),s.y=Math.max(i.y,o.y),s.z=Math.max(i.z,o.z)}_intersectHeightfield(t,e,s,i,o){t.data,t.elementSize;const n=Bt;n.from.copy(this.from),n.to.copy(this.to),x.pointToLocalFrame(s,e,n.from,n.from),x.pointToLocalFrame(s,e,n.to,n.to),n.updateDirection();const r=At;let a,l,h,d;a=l=0,h=d=t.data.length-1;const u=new c;n.getAABB(u),t.getIndexOfPosition(u.lowerBound.x,u.lowerBound.y,r,!0),a=Math.max(a,r[0]),l=Math.max(l,r[1]),t.getIndexOfPosition(u.upperBound.x,u.upperBound.y,r,!0),h=Math.min(h,r[0]+1),d=Math.min(d,r[1]+1);for(let c=a;c<h;c++)for(let r=l;r<d;r++){if(this.result.shouldStop)return;if(t.getAabbAtIndex(c,r,u),u.overlapsRay(n)){if(t.getConvexTrianglePillar(c,r,!1),x.pointToWorldFrame(s,e,t.pillarOffset,bt),this._intersectConvex(t.pillarConvex,e,bt,i,o,xt),this.result.shouldStop)return;t.getConvexTrianglePillar(c,r,!0),x.pointToWorldFrame(s,e,t.pillarOffset,bt),this._intersectConvex(t.pillarConvex,e,bt,i,o,xt)}}}_intersectSphere(t,e,s,i,o){const n=this.from,r=this.to,a=t.radius,l=(r.x-n.x)**2+(r.y-n.y)**2+(r.z-n.z)**2,h=2*((r.x-n.x)*(n.x-s.x)+(r.y-n.y)*(n.y-s.y)+(r.z-n.z)*(n.z-s.z)),c=h**2-4*l*((n.x-s.x)**2+(n.y-s.y)**2+(n.z-s.z)**2-a**2),d=Et,u=St;if(!(c<0))if(0===c)n.lerp(r,c,d),d.vsub(s,u),u.normalize(),this.reportIntersection(u,d,o,i,-1);else{const t=(-h-Math.sqrt(c))/(2*l),e=(-h+Math.sqrt(c))/(2*l);if(t>=0&&t<=1&&(n.lerp(r,t,d),d.vsub(s,u),u.normalize(),this.reportIntersection(u,d,o,i,-1)),this.result.shouldStop)return;e>=0&&e<=1&&(n.lerp(r,e,d),d.vsub(s,u),u.normalize(),this.reportIntersection(u,d,o,i,-1))}}_intersectConvex(t,e,s,i,o,n){const r=zt,a=Ct,l=n&&n.faceList||null,h=t.faces,c=t.vertices,d=t.faceNormals,u=this.direction,p=this.from,y=this.to,v=p.distanceTo(y),m=l?l.length:h.length,g=this.result;for(let w=0;!g.shouldStop&&w<m;w++){const t=l?l[w]:w,n=h[t],y=d[t],m=e,f=s;a.copy(c[n[0]]),m.vmult(a,a),a.vadd(f,a),a.vsub(p,a),m.vmult(y,r);const x=u.dot(r);if(Math.abs(x)<this.precision)continue;const b=r.dot(a)/x;if(!(b<0)){u.scale(b,mt),mt.vadd(p,mt),gt.copy(c[n[0]]),m.vmult(gt,gt),f.vadd(gt,gt);for(let e=1;!g.shouldStop&&e<n.length-1;e++){wt.copy(c[n[e]]),ft.copy(c[n[e+1]]),m.vmult(wt,wt),m.vmult(ft,ft),f.vadd(wt,wt),f.vadd(ft,ft);const s=mt.distanceTo(p);!ht.pointInTriangle(mt,gt,wt,ft)&&!ht.pointInTriangle(mt,wt,gt,ft)||s>v||this.reportIntersection(r,mt,o,i,t)}}}}_intersectTrimesh(t,e,s,i,o,n){const r=Ft,a=qt,l=Nt,h=Ct,c=Mt,d=Rt,u=Tt,p=Pt,y=It,v=t.indices;t.vertices;const m=this.from,g=this.to,w=this.direction;l.position.copy(s),l.quaternion.copy(e),x.vectorToLocalFrame(s,e,w,c),x.pointToLocalFrame(s,e,m,d),x.pointToLocalFrame(s,e,g,u),u.x*=t.scale.x,u.y*=t.scale.y,u.z*=t.scale.z,d.x*=t.scale.x,d.y*=t.scale.y,d.z*=t.scale.z,u.vsub(d,c),c.normalize();const f=d.distanceSquared(u);t.tree.rayQuery(this,l,a);for(let b=0,B=a.length;!this.result.shouldStop&&b!==B;b++){const n=a[b];t.getNormal(n,r),t.getVertex(v[3*n],gt),gt.vsub(d,h);const l=c.dot(r),u=r.dot(h)/l;if(u<0)continue;c.scale(u,mt),mt.vadd(d,mt),t.getVertex(v[3*n+1],wt),t.getVertex(v[3*n+2],ft);const m=mt.distanceSquared(d);!ht.pointInTriangle(mt,wt,gt,ft)&&!ht.pointInTriangle(mt,gt,wt,ft)||m>f||(x.vectorToWorldFrame(e,r,y),x.pointToWorldFrame(s,e,mt,p),this.reportIntersection(y,p,o,i,n))}a.length=0}reportIntersection(t,e,s,i,o){const n=this.from,r=this.to,a=n.distanceTo(e),l=this.result;if(!(this.skipBackfaces&&t.dot(this.direction)>0))switch(l.hitFaceIndex=void 0!==o?o:-1,this.mode){case ht.ALL:this.hasHit=!0,l.set(n,r,t,e,s,i,a),l.hasHit=!0,this.callback(l);break;case ht.CLOSEST:(a<l.distance||!l.hasHit)&&(this.hasHit=!0,l.hasHit=!0,l.set(n,r,t,e,s,i,a));break;case ht.ANY:this.hasHit=!0,l.hasHit=!0,l.set(n,r,t,e,s,i,a),l.shouldStop=!0}}static pointInTriangle(t,e,s,i){i.vsub(e,Lt),s.vsub(e,ut),t.vsub(e,pt);const o=Lt.dot(Lt),n=Lt.dot(ut),r=Lt.dot(pt),a=ut.dot(ut),l=ut.dot(pt);let h,c;return(h=a*r-n*l)>=0&&(c=o*l-n*r)>=0&&h+c<o*a-n*n}}ht.CLOSEST=lt.CLOSEST,ht.ANY=lt.ANY,ht.ALL=lt.ALL;const ct=new c,dt=[],ut=new r,pt=new r,yt=new r,vt=new v,mt=new r,gt=new r,wt=new r,ft=new r;new r,new tt;const xt={faceList:[0]},bt=new r,Bt=new ht,At=[],Et=new r,St=new r,zt=new r,Ct=(new r,new r,new r),Ft=new r,Mt=new r,Rt=new r,Tt=new r,It=new r,Pt=new r;new c;const qt=[],Nt=new x,Lt=new r,Wt=new r;class Vt extends G{static checkBounds(t,e,s){let i,o;0===s?(i=t.position.x,o=e.position.x):1===s?(i=t.position.y,o=e.position.y):2===s&&(i=t.position.z,o=e.position.z);const n=t.boundingRadius;return o-e.boundingRadius<i+n}static insertionSortX(t){for(let e=1,s=t.length;e<s;e++){const s=t[e];let i;for(i=e-1;i>=0&&!(t[i].aabb.lowerBound.x<=s.aabb.lowerBound.x);i--)t[i+1]=t[i];t[i+1]=s}return t}static insertionSortY(t){for(let e=1,s=t.length;e<s;e++){const s=t[e];let i;for(i=e-1;i>=0&&!(t[i].aabb.lowerBound.y<=s.aabb.lowerBound.y);i--)t[i+1]=t[i];t[i+1]=s}return t}static insertionSortZ(t){for(let e=1,s=t.length;e<s;e++){const s=t[e];let i;for(i=e-1;i>=0&&!(t[i].aabb.lowerBound.z<=s.aabb.lowerBound.z);i--)t[i+1]=t[i];t[i+1]=s}return t}constructor(t){super(),this.axisList=[],this.world=null,this.axisIndex=0;const e=this.axisList;this._addBodyHandler=t=>{e.push(t.body)},this._removeBodyHandler=t=>{const s=e.indexOf(t.body);-1!==s&&e.splice(s,1)},t&&this.setWorld(t)}setWorld(t){this.axisList.length=0;for(let e=0;e<t.bodies.length;e++)this.axisList.push(t.bodies[e]);t.removeEventListener("addBody",this._addBodyHandler),t.removeEventListener("removeBody",this._removeBodyHandler),t.addEventListener("addBody",this._addBodyHandler),t.addEventListener("removeBody",this._removeBodyHandler),this.world=t,this.dirty=!0}collisionPairs(t,e,s){const i=this.axisList,o=i.length,n=this.axisIndex;let r,a;for(this.dirty&&(this.sortList(),this.dirty=!1),r=0;r!==o;r++){const t=i[r];for(a=r+1;a<o;a++){const o=i[a];if(this.needBroadphaseCollision(t,o)){if(!Vt.checkBounds(t,o,n))break;this.intersectionTest(t,o,e,s)}}}}sortList(){const t=this.axisList,e=this.axisIndex,s=t.length;for(let i=0;i!==s;i++){const e=t[i];e.aabbNeedsUpdate&&e.updateAABB()}0===e?Vt.insertionSortX(t):1===e?Vt.insertionSortY(t):2===e&&Vt.insertionSortZ(t)}autoDetectAxis(){let t=0,e=0,s=0,i=0,o=0,n=0;const r=this.axisList,a=r.length,l=1/a;for(let u=0;u!==a;u++){const a=r[u],l=a.position.x;t+=l,e+=l*l;const h=a.position.y;s+=h,i+=h*h;const c=a.position.z;o+=c,n+=c*c}const h=e-t*t*l,c=i-s*s*l,d=n-o*o*l;this.axisIndex=h>c?h>d?0:2:c>d?1:2}aabbQuery(t,e,s){void 0===s&&(s=[]),this.dirty&&(this.sortList(),this.dirty=!1);const i=this.axisIndex;let o="x";1===i&&(o="y"),2===i&&(o="z");const n=this.axisList;e.lowerBound[o],e.upperBound[o];for(let r=0;r<n.length;r++){const t=n[r];t.aabbNeedsUpdate&&t.updateAABB(),t.aabb.overlaps(e)&&s.push(t)}return s}}class jt{static defaults(t,e){void 0===t&&(t={});for(let s in e)s in t||(t[s]=e[s]);return t}}class Ot{constructor(t,e,s){void 0===s&&(s={}),s=jt.defaults(s,{collideConnected:!0,wakeUpBodies:!0}),this.equations=[],this.bodyA=t,this.bodyB=e,this.id=Ot.idCounter++,this.collideConnected=s.collideConnected,s.wakeUpBodies&&(t&&t.wakeUp(),e&&e.wakeUp())}update(){throw new Error("method update() not implmemented in this Constraint subclass!")}enable(){const t=this.equations;for(let e=0;e<t.length;e++)t[e].enabled=!0}disable(){const t=this.equations;for(let e=0;e<t.length;e++)t[e].enabled=!1}}Ot.idCounter=0;class kt{constructor(){this.spatial=new r,this.rotational=new r}multiplyElement(t){return t.spatial.dot(this.spatial)+t.rotational.dot(this.rotational)}multiplyVectors(t,e){return t.dot(this.spatial)+e.dot(this.rotational)}}class _t{constructor(t,e,s,i){void 0===s&&(s=-1e6),void 0===i&&(i=1e6),this.id=_t.idCounter++,this.minForce=s,this.maxForce=i,this.bi=t,this.bj=e,this.a=0,this.b=0,this.eps=0,this.jacobianElementA=new kt,this.jacobianElementB=new kt,this.enabled=!0,this.multiplier=0,this.setSpookParams(1e7,4,1/60)}setSpookParams(t,e,s){const i=e,o=t,n=s;this.a=4/(n*(1+4*i)),this.b=4*i/(1+4*i),this.eps=4/(n*n*o*(1+4*i))}computeB(t,e,s){const i=this.computeGW();return-this.computeGq()*t-i*e-this.