tencentcloud-webar 2.0.3-dev.1 → 2.0.3-dev.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build-esm/28.js +1 -1
- package/build-esm/avatar.worker.js +1 -1
- package/build-esm/hand3d.worker.js +1 -1
- package/build-esm/index.js +2 -2
- package/build-esm/sticker3d.js +1 -1
- package/build-esm/sticker3d.worker.js +1 -1
- package/build-umd/avatar.umd.js +174 -0
- package/build-umd/hand-3d.umd.js +17 -0
- package/build-umd/stickers-3d.umd.js +17 -0
- package/build-umd/webar-sdk.umd.js +6 -0
- package/miniprogram_dist/790.js +1 -0
- package/miniprogram_dist/core.js +1 -1
- package/miniprogram_dist/index.js +1 -0
- package/miniprogram_dist/lib-physics.js +1 -0
- package/miniprogram_dist/lib.js +1 -0
- package/miniprogram_dist/plugin-3d.js +1 -1
- package/miniprogram_dist/worker/tick.worker.js +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var self = wx;(self.webpackChunktencentcloud_webar=self.webpackChunktencentcloud_webar||[]).push([[541],{2415:(t,e,o)=>{o.r(e),o.d(e,{AABB:()=>h,ArrayCollisionMatrix:()=>v,BODY_SLEEP_STATES:()=>I,BODY_TYPES:()=>R,Body:()=>j,Box:()=>T,Broadphase:()=>Z,COLLISION_TYPES:()=>qi,ConeTwistConstraint:()=>ye,Constraint:()=>Wt,ContactEquation:()=>Zt,ContactMaterial:()=>Fe,ConvexPolyhedron:()=>E,Cylinder:()=>Oo,DistanceConstraint:()=>we,Equation:()=>kt,EventTarget:()=>f,FrictionEquation:()=>Pe,GSSolver:()=>gi,GridBroadphase:()=>ot,Heightfield:()=>Wo,HingeConstraint:()=>Ee,JacobianElement:()=>Vt,LockConstraint:()=>be,Mat3:()=>n,Material:()=>_e,NaiveBroadphase:()=>rt,Narrowphase:()=>Ni,ObjectCollisionMatrix:()=>i,Particle:()=>Io,Plane:()=>qo,PointToPointConstraint:()=>se,Pool:()=>Ri,Quaternion:()=>y,RAY_MODES:()=>at,Ray:()=>lt,RaycastResult:()=>st,RaycastVehicle:()=>Xe,RigidVehicle:()=>xo,RotationalEquation:()=>pe,RotationalMotorEquation:()=>Ae,SAPBroadphase:()=>Nt,SHAPE_TYPES:()=>g,SPHSystem:()=>Eo,Shape:()=>b,Solver:()=>mi,Sphere:()=>bo,SplitSolver:()=>Ei,Spring:()=>Oe,Transform:()=>x,Trimesh:()=>ii,Vec3:()=>s,Vec3Pool:()=>ji,WheelInfo:()=>Ue,World:()=>ar});var i=function(){function t(){this.matrix={}}return t.prototype.get=function(t,e){var o=t.id,i=e.id;if(i>o){var n=i;i=o,o=n}return"".concat(o,"-").concat(i)in this.matrix},t.prototype.set=function(t,e,o){var i=t.id,n=e.id;if(n>i){var r=n;n=i,i=r}o?this.matrix["".concat(i,"-").concat(n)]=!0:delete this.matrix["".concat(i,"-").concat(n)]},t.prototype.reset=function(){this.matrix={}},t.prototype.setNumObjects=function(t){},t}(),n=function(){function t(t){void 0===t&&(t=[0,0,0,0,0,0,0,0,0]),this.elements=t}return t.prototype.identity=function(){var 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},t.prototype.setZero=function(){var 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},t.prototype.setTrace=function(t){var e=this.elements;e[0]=t.x,e[4]=t.y,e[8]=t.z},t.prototype.getTrace=function(t){void 0===t&&(t=new s);var e=this.elements;return t.x=e[0],t.y=e[4],t.z=e[8],t},t.prototype.vmult=function(t,e){void 0===e&&(e=new s);var o=this.elements,i=t.x,n=t.y,r=t.z;return e.x=o[0]*i+o[1]*n+o[2]*r,e.y=o[3]*i+o[4]*n+o[5]*r,e.z=o[6]*i+o[7]*n+o[8]*r,e},t.prototype.smult=function(t){for(var e=0;e<this.elements.length;e++)this.elements[e]*=t},t.prototype.mmult=function(e,o){void 0===o&&(o=new t);var i=this.elements,n=e.elements,r=o.elements,s=i[0],a=i[1],l=i[2],c=i[3],u=i[4],h=i[5],p=i[6],d=i[7],v=i[8],f=n[0],y=n[1],m=n[2],w=n[3],g=n[4],b=n[5],x=n[6],A=n[7],B=n[8];return r[0]=s*f+a*w+l*x,r[1]=s*y+a*g+l*A,r[2]=s*m+a*b+l*B,r[3]=c*f+u*w+h*x,r[4]=c*y+u*g+h*A,r[5]=c*m+u*b+h*B,r[6]=p*f+d*w+v*x,r[7]=p*y+d*g+v*A,r[8]=p*m+d*b+v*B,o},t.prototype.scale=function(e,o){void 0===o&&(o=new t);for(var i=this.elements,n=o.elements,r=0;3!==r;r++)n[3*r+0]=e.x*i[3*r+0],n[3*r+1]=e.y*i[3*r+1],n[3*r+2]=e.z*i[3*r+2];return o},t.prototype.solve=function(t,e){void 0===e&&(e=new s);var o,i,n=[];for(o=0;o<12;o++)n.push(0);for(o=0;o<3;o++)for(i=0;i<3;i++)n[o+4*i]=this.elements[o+3*i];n[3]=t.x,n[7]=t.y,n[11]=t.z;var r,a,l=3,c=l;do{if(0===n[(o=c-l)+4*o])for(i=o+1;i<c;i++)if(0!==n[o+4*i]){r=4;do{n[(a=4-r)+4*o]+=n[a+4*i]}while(--r);break}if(0!==n[o+4*o])for(i=o+1;i<c;i++){var u=n[o+4*i]/n[o+4*o];r=4;do{n[(a=4-r)+4*i]=a<=o?0:n[a+4*i]-n[a+4*o]*u}while(--r)}}while(--l);if(e.z=n[11]/n[10],e.y=(n[7]-n[6]*e.z)/n[5],e.x=(n[3]-n[2]*e.z-n[1]*e.y)/n[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=[".concat(e.toString(),"], b=[").concat(t.toString(),"], A=[").concat(this.toString(),"]");return e},t.prototype.e=function(t,e,o){if(void 0===o)return this.elements[e+3*t];this.elements[e+3*t]=o},t.prototype.copy=function(t){for(var e=0;e<t.elements.length;e++)this.elements[e]=t.elements[e];return this},t.prototype.toString=function(){for(var t="",e=0;e<9;e++)t+=this.elements[e]+",";return t},t.prototype.reverse=function(e){void 0===e&&(e=new t);var o,i,n=r;for(o=0;o<3;o++)for(i=0;i<3;i++)n[o+6*i]=this.elements[o+3*i];n[3]=1,n[9]=0,n[15]=0,n[4]=0,n[10]=1,n[16]=0,n[5]=0,n[11]=0,n[17]=1;var s,a,l=3,c=l;do{if(0===n[(o=c-l)+6*o])for(i=o+1;i<c;i++)if(0!==n[o+6*i]){s=6;do{n[(a=6-s)+6*o]+=n[a+6*i]}while(--s);break}if(0!==n[o+6*o])for(i=o+1;i<c;i++){var u=n[o+6*i]/n[o+6*o];s=6;do{n[(a=6-s)+6*i]=a<=o?0:n[a+6*i]-n[a+6*o]*u}while(--s)}}while(--l);o=2;do{i=o-1;do{u=n[o+6*i]/n[o+6*o];s=6;do{n[(a=6-s)+6*i]=n[a+6*i]-n[a+6*o]*u}while(--s)}while(i--)}while(--o);o=2;do{u=1/n[o+6*o];s=6;do{n[(a=6-s)+6*o]=n[a+6*o]*u}while(--s)}while(o--);o=2;do{i=2;do{if(a=n[3+i+6*o],isNaN(a)||a===1/0)throw"Could not reverse! A=[".concat(this.toString(),"]");e.e(o,i,a)}while(i--)}while(o--);return e},t.prototype.setRotationFromQuaternion=function(t){var e=t.x,o=t.y,i=t.z,n=t.w,r=e+e,s=o+o,a=i+i,l=e*r,c=e*s,u=e*a,h=o*s,p=o*a,d=i*a,v=n*r,f=n*s,y=n*a,m=this.elements;return m[0]=1-(h+d),m[1]=c-y,m[2]=u+f,m[3]=c+y,m[4]=1-(l+d),m[5]=p-v,m[6]=u-f,m[7]=p+v,m[8]=1-(l+h),this},t.prototype.transpose=function(e){void 0===e&&(e=new t);var o,i=this.elements,n=e.elements;return n[0]=i[0],n[4]=i[4],n[8]=i[8],o=i[1],n[1]=i[3],n[3]=o,o=i[2],n[2]=i[6],n[6]=o,o=i[5],n[5]=i[7],n[7]=o,e},t}(),r=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],s=function(){function t(t,e,o){void 0===t&&(t=0),void 0===e&&(e=0),void 0===o&&(o=0),this.x=t,this.y=e,this.z=o}return t.prototype.cross=function(e,o){void 0===o&&(o=new t);var i=e.x,n=e.y,r=e.z,s=this.x,a=this.y,l=this.z;return o.x=a*r-l*n,o.y=l*i-s*r,o.z=s*n-a*i,o},t.prototype.set=function(t,e,o){return this.x=t,this.y=e,this.z=o,this},t.prototype.setZero=function(){this.x=this.y=this.z=0},t.prototype.vadd=function(e,o){if(!o)return new t(this.x+e.x,this.y+e.y,this.z+e.z);o.x=e.x+this.x,o.y=e.y+this.y,o.z=e.z+this.z},t.prototype.vsub=function(e,o){if(!o)return new t(this.x-e.x,this.y-e.y,this.z-e.z);o.x=this.x-e.x,o.y=this.y-e.y,o.z=this.z-e.z},t.prototype.crossmat=function(){return new n([0,-this.z,this.y,this.z,0,-this.x,-this.y,this.x,0])},t.prototype.normalize=function(){var t=this.x,e=this.y,o=this.z,i=Math.sqrt(t*t+e*e+o*o);if(i>0){var n=1/i;this.x*=n,this.y*=n,this.z*=n}else this.x=0,this.y=0,this.z=0;return i},t.prototype.unit=function(e){void 0===e&&(e=new t);var o=this.x,i=this.y,n=this.z,r=Math.sqrt(o*o+i*i+n*n);return r>0?(r=1/r,e.x=o*r,e.y=i*r,e.z=n*r):(e.x=1,e.y=0,e.z=0),e},t.prototype.length=function(){var t=this.x,e=this.y,o=this.z;return Math.sqrt(t*t+e*e+o*o)},t.prototype.lengthSquared=function(){return this.dot(this)},t.prototype.distanceTo=function(t){var e=this.x,o=this.y,i=this.z,n=t.x,r=t.y,s=t.z;return Math.sqrt((n-e)*(n-e)+(r-o)*(r-o)+(s-i)*(s-i))},t.prototype.distanceSquared=function(t){var e=this.x,o=this.y,i=this.z,n=t.x,r=t.y,s=t.z;return(n-e)*(n-e)+(r-o)*(r-o)+(s-i)*(s-i)},t.prototype.scale=function(e,o){void 0===o&&(o=new t);var i=this.x,n=this.y,r=this.z;return o.x=e*i,o.y=e*n,o.z=e*r,o},t.prototype.vmul=function(e,o){return void 0===o&&(o=new t),o.x=e.x*this.x,o.y=e.y*this.y,o.z=e.z*this.z,o},t.prototype.addScaledVector=function(e,o,i){return void 0===i&&(i=new t),i.x=this.x+e*o.x,i.y=this.y+e*o.y,i.z=this.z+e*o.z,i},t.prototype.dot=function(t){return this.x*t.x+this.y*t.y+this.z*t.z},t.prototype.isZero=function(){return 0===this.x&&0===this.y&&0===this.z},t.prototype.negate=function(e){return void 0===e&&(e=new t),e.x=-this.x,e.y=-this.y,e.z=-this.z,e},t.prototype.tangents=function(t,e){var o=this.length();if(o>0){var i=l,n=1/o;i.set(this.x*n,this.y*n,this.z*n);var r=c;Math.abs(i.x)<.9?(r.set(1,0,0),i.cross(r,t)):(r.set(0,1,0),i.cross(r,t)),i.cross(t,e)}else t.set(1,0,0),e.set(0,1,0)},t.prototype.toString=function(){return"".concat(this.x,",").concat(this.y,",").concat(this.z)},t.prototype.toArray=function(){return[this.x,this.y,this.z]},t.prototype.copy=function(t){return this.x=t.x,this.y=t.y,this.z=t.z,this},t.prototype.lerp=function(t,e,o){var i=this.x,n=this.y,r=this.z;o.x=i+(t.x-i)*e,o.y=n+(t.y-n)*e,o.z=r+(t.z-r)*e},t.prototype.almostEquals=function(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)},t.prototype.almostZero=function(t){return void 0===t&&(t=1e-6),!(Math.abs(this.x)>t||Math.abs(this.y)>t||Math.abs(this.z)>t)},t.prototype.isAntiparallelTo=function(t,e){return this.negate(u),u.almostEquals(t,e)},t.prototype.clone=function(){return new t(this.x,this.y,this.z)},t}();s.ZERO=new s(0,0,0),s.UNIT_X=new s(1,0,0),s.UNIT_Y=new s(0,1,0),s.UNIT_Z=new s(0,0,1);var a,l=new s,c=new s,u=new s,h=function(){function t(t){void 0===t&&(t={}),this.lowerBound=new s,this.upperBound=new s,t.lowerBound&&this.lowerBound.copy(t.lowerBound),t.upperBound&&this.upperBound.copy(t.upperBound)}return t.prototype.setFromPoints=function(t,e,o,i){var n=this.lowerBound,r=this.upperBound,s=o;n.copy(t[0]),s&&s.vmult(n,n),r.copy(n);for(var a=1;a<t.length;a++){var l=t[a];s&&(s.vmult(l,p),l=p),l.x>r.x&&(r.x=l.x),l.x<n.x&&(n.x=l.x),l.y>r.y&&(r.y=l.y),l.y<n.y&&(n.y=l.y),l.z>r.z&&(r.z=l.z),l.z<n.z&&(n.z=l.z)}return e&&(e.vadd(n,n),e.vadd(r,r)),i&&(n.x-=i,n.y-=i,n.z-=i,r.x+=i,r.y+=i,r.z+=i),this},t.prototype.copy=function(t){return this.lowerBound.copy(t.lowerBound),this.upperBound.copy(t.upperBound),this},t.prototype.clone=function(){return(new t).copy(this)},t.prototype.extend=function(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)},t.prototype.overlaps=function(t){var e=this.lowerBound,o=this.upperBound,i=t.lowerBound,n=t.upperBound,r=i.x<=o.x&&o.x<=n.x||e.x<=n.x&&n.x<=o.x,s=i.y<=o.y&&o.y<=n.y||e.y<=n.y&&n.y<=o.y,a=i.z<=o.z&&o.z<=n.z||e.z<=n.z&&n.z<=o.z;return r&&s&&a},t.prototype.volume=function(){var t=this.lowerBound,e=this.upperBound;return(e.x-t.x)*(e.y-t.y)*(e.z-t.z)},t.prototype.contains=function(t){var e=this.lowerBound,o=this.upperBound,i=t.lowerBound,n=t.upperBound;return e.x<=i.x&&o.x>=n.x&&e.y<=i.y&&o.y>=n.y&&e.z<=i.z&&o.z>=n.z},t.prototype.getCorners=function(t,e,o,i,n,r,s,a){var l=this.lowerBound,c=this.upperBound;t.copy(l),e.set(c.x,l.y,l.z),o.set(c.x,c.y,l.z),i.set(l.x,c.y,c.z),n.set(c.x,l.y,c.z),r.set(l.x,c.y,l.z),s.set(l.x,l.y,c.z),a.copy(c)},t.prototype.toLocalFrame=function(t,e){var o=d,i=o[0],n=o[1],r=o[2],s=o[3],a=o[4],l=o[5],c=o[6],u=o[7];this.getCorners(i,n,r,s,a,l,c,u);for(var h=0;8!==h;h++){var p=o[h];t.pointToLocal(p,p)}return e.setFromPoints(o)},t.prototype.toWorldFrame=function(t,e){var o=d,i=o[0],n=o[1],r=o[2],s=o[3],a=o[4],l=o[5],c=o[6],u=o[7];this.getCorners(i,n,r,s,a,l,c,u);for(var h=0;8!==h;h++){var p=o[h];t.pointToWorld(p,p)}return e.setFromPoints(o)},t.prototype.overlapsRay=function(t){var e=t.direction,o=t.from,i=1/e.x,n=1/e.y,r=1/e.z,s=(this.lowerBound.x-o.x)*i,a=(this.upperBound.x-o.x)*i,l=(this.lowerBound.y-o.y)*n,c=(this.upperBound.y-o.y)*n,u=(this.lowerBound.z-o.z)*r,h=(this.upperBound.z-o.z)*r,p=Math.max(Math.max(Math.min(s,a),Math.min(l,c)),Math.min(u,h)),d=Math.min(Math.min(Math.max(s,a),Math.max(l,c)),Math.max(u,h));return!(d<0)&&!(p>d)},t}(),p=new s,d=[new s,new s,new s,new s,new s,new s,new s,new s],v=function(){function t(){this.matrix=[]}return t.prototype.get=function(t,e){var o=t.index,i=e.index;if(i>o){var n=i;i=o,o=n}return this.matrix[(o*(o+1)>>1)+i-1]},t.prototype.set=function(t,e,o){var i=t.index,n=e.index;if(n>i){var r=n;n=i,i=r}this.matrix[(i*(i+1)>>1)+n-1]=o?1:0},t.prototype.reset=function(){for(var t=0,e=this.matrix.length;t!==e;t++)this.matrix[t]=0},t.prototype.setNumObjects=function(t){this.matrix.length=t*(t-1)>>1},t}(),f=function(){function t(){}return t.prototype.addEventListener=function(t,e){void 0===this._listeners&&(this._listeners={});var o=this._listeners;return void 0===o[t]&&(o[t]=[]),o[t].includes(e)||o[t].push(e),this},t.prototype.hasEventListener=function(t,e){if(void 0===this._listeners)return!1;var o=this._listeners;return!(void 0===o[t]||!o[t].includes(e))},t.prototype.hasAnyEventListener=function(t){return void 0!==this._listeners&&void 0!==this._listeners[t]},t.prototype.removeEventListener=function(t,e){if(void 0===this._listeners)return this;var o=this._listeners;if(void 0===o[t])return this;var i=o[t].indexOf(e);return-1!==i&&o[t].splice(i,1),this},t.prototype.dispatchEvent=function(t){if(void 0===this._listeners)return this;var e=this._listeners[t.type];if(void 0!==e){t.target=this;for(var o=0,i=e.length;o<i;o++)e[o].call(this,t)}return this},t}(),y=function(){function t(t,e,o,i){void 0===t&&(t=0),void 0===e&&(e=0),void 0===o&&(o=0),void 0===i&&(i=1),this.x=t,this.y=e,this.z=o,this.w=i}return t.prototype.set=function(t,e,o,i){return this.x=t,this.y=e,this.z=o,this.w=i,this},t.prototype.toString=function(){return"".concat(this.x,",").concat(this.y,",").concat(this.z,",").concat(this.w)},t.prototype.toArray=function(){return[this.x,this.y,this.z,this.w]},t.prototype.setFromAxisAngle=function(t,e){var o=Math.sin(.5*e);return this.x=t.x*o,this.y=t.y*o,this.z=t.z*o,this.w=Math.cos(.5*e),this},t.prototype.toAxisAngle=function(t){void 0===t&&(t=new s),this.normalize();var e=2*Math.acos(this.w),o=Math.sqrt(1-this.w*this.w);return o<.001?(t.x=this.x,t.y=this.y,t.z=this.z):(t.x=this.x/o,t.y=this.y/o,t.z=this.z/o),[t,e]},t.prototype.setFromVectors=function(t,e){if(t.isAntiparallelTo(e)){var o=m,i=w;t.tangents(o,i),this.setFromAxisAngle(o,Math.PI)}else{var n=t.cross(e);this.x=n.x,this.y=n.y,this.z=n.z,this.w=Math.sqrt(Math.pow(t.length(),2)*Math.pow(e.length(),2))+t.dot(e),this.normalize()}return this},t.prototype.mult=function(e,o){void 0===o&&(o=new t);var i=this.x,n=this.y,r=this.z,s=this.w,a=e.x,l=e.y,c=e.z,u=e.w;return o.x=i*u+s*a+n*c-r*l,o.y=n*u+s*l+r*a-i*c,o.z=r*u+s*c+i*l-n*a,o.w=s*u-i*a-n*l-r*c,o},t.prototype.inverse=function(e){void 0===e&&(e=new t);var o=this.x,i=this.y,n=this.z,r=this.w;this.conjugate(e);var s=1/(o*o+i*i+n*n+r*r);return e.x*=s,e.y*=s,e.z*=s,e.w*=s,e},t.prototype.conjugate=function(e){return void 0===e&&(e=new t),e.x=-this.x,e.y=-this.y,e.z=-this.z,e.w=this.w,e},t.prototype.normalize=function(){var 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},t.prototype.normalizeFast=function(){var 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},t.prototype.vmult=function(t,e){void 0===e&&(e=new s);var o=t.x,i=t.y,n=t.z,r=this.x,a=this.y,l=this.z,c=this.w,u=c*o+a*n-l*i,h=c*i+l*o-r*n,p=c*n+r*i-a*o,d=-r*o-a*i-l*n;return e.x=u*c+d*-r+h*-l-p*-a,e.y=h*c+d*-a+p*-r-u*-l,e.z=p*c+d*-l+u*-a-h*-r,e},t.prototype.copy=function(t){return this.x=t.x,this.y=t.y,this.z=t.z,this.w=t.w,this},t.prototype.toEuler=function(t,e){var o,i,n;void 0===e&&(e="YZX");var r=this.x,s=this.y,a=this.z,l=this.w;if("YZX"!==e)throw new Error("Euler order ".concat(e," not supported yet."));var c=r*s+a*l;if(c>.499&&(o=2*Math.atan2(r,l),i=Math.PI/2,n=0),c<-.499&&(o=-2*Math.atan2(r,l),i=-Math.PI/2,n=0),void 0===o){var u=r*r,h=s*s,p=a*a;o=Math.atan2(2*s*l-2*r*a,1-2*h-2*p),i=Math.asin(2*c),n=Math.atan2(2*r*l-2*s*a,1-2*u-2*p)}t.y=o,t.z=i,t.x=n},t.prototype.setFromEuler=function(t,e,o,i){void 0===i&&(i="XYZ");var n=Math.cos(t/2),r=Math.cos(e/2),s=Math.cos(o/2),a=Math.sin(t/2),l=Math.sin(e/2),c=Math.sin(o/2);return"XYZ"===i?(this.x=a*r*s+n*l*c,this.y=n*l*s-a*r*c,this.z=n*r*c+a*l*s,this.w=n*r*s-a*l*c):"YXZ"===i?(this.x=a*r*s+n*l*c,this.y=n*l*s-a*r*c,this.z=n*r*c-a*l*s,this.w=n*r*s+a*l*c):"ZXY"===i?(this.x=a*r*s-n*l*c,this.y=n*l*s+a*r*c,this.z=n*r*c+a*l*s,this.w=n*r*s-a*l*c):"ZYX"===i?(this.x=a*r*s-n*l*c,this.y=n*l*s+a*r*c,this.z=n*r*c-a*l*s,this.w=n*r*s+a*l*c):"YZX"===i?(this.x=a*r*s+n*l*c,this.y=n*l*s+a*r*c,this.z=n*r*c-a*l*s,this.w=n*r*s-a*l*c):"XZY"===i&&(this.x=a*r*s-n*l*c,this.y=n*l*s-a*r*c,this.z=n*r*c+a*l*s,this.w=n*r*s+a*l*c),this},t.prototype.clone=function(){return new t(this.x,this.y,this.z,this.w)},t.prototype.slerp=function(e,o,i){void 0===i&&(i=new t);var n,r,s,a,l,c=this.x,u=this.y,h=this.z,p=this.w,d=e.x,v=e.y,f=e.z,y=e.w;return(r=c*d+u*v+h*f+p*y)<0&&(r=-r,d=-d,v=-v,f=-f,y=-y),1-r>1e-6?(n=Math.acos(r),s=Math.sin(n),a=Math.sin((1-o)*n)/s,l=Math.sin(o*n)/s):(a=1-o,l=o),i.x=a*c+l*d,i.y=a*u+l*v,i.z=a*h+l*f,i.w=a*p+l*y,i},t.prototype.integrate=function(e,o,i,n){void 0===n&&(n=new t);var r=e.x*i.x,s=e.y*i.y,a=e.z*i.z,l=this.x,c=this.y,u=this.z,h=this.w,p=.5*o;return n.x+=p*(r*h+s*u-a*c),n.y+=p*(s*h+a*l-r*u),n.z+=p*(a*h+r*c-s*l),n.w+=p*(-r*l-s*c-a*u),n},t}(),m=new s,w=new s,g={SPHERE:1,PLANE:2,BOX:4,COMPOUND:8,CONVEXPOLYHEDRON:16,HEIGHTFIELD:32,PARTICLE:64,CYLINDER:128,TRIMESH:256},b=function(){function t(e){void 0===e&&(e={}),this.id=t.idCounter++,this.type=e.type||0,this.boundingSphereRadius=0,this.collisionResponse=!e.collisionResponse||e.collisionResponse,this.collisionFilterGroup=void 0!==e.collisionFilterGroup?e.collisionFilterGroup:1,this.collisionFilterMask=void 0!==e.collisionFilterMask?e.collisionFilterMask:-1,this.material=e.material?e.material:null,this.body=null}return t.prototype.updateBoundingSphereRadius=function(){throw"computeBoundingSphereRadius() not implemented for shape type ".concat(this.type)},t.prototype.volume=function(){throw"volume() not implemented for shape type ".concat(this.type)},t.prototype.calculateLocalInertia=function(t,e){throw"calculateLocalInertia() not implemented for shape type ".concat(this.type)},t.prototype.calculateWorldAABB=function(t,e,o,i){throw"calculateWorldAABB() not implemented for shape type ".concat(this.type)},t.idCounter=0,t.types=g,t}(),x=function(){function t(t){void 0===t&&(t={}),this.position=new s,this.quaternion=new y,t.position&&this.position.copy(t.position),t.quaternion&&this.quaternion.copy(t.quaternion)}return t.prototype.pointToLocal=function(e,o){return t.pointToLocalFrame(this.position,this.quaternion,e,o)},t.prototype.pointToWorld=function(e,o){return t.pointToWorldFrame(this.position,this.quaternion,e,o)},t.prototype.vectorToWorldFrame=function(t,e){return void 0===e&&(e=new s),this.quaternion.vmult(t,e),e},t.pointToLocalFrame=function(t,e,o,i){return void 0===i&&(i=new s),o.vsub(t,i),e.conjugate(A),A.vmult(i,i),i},t.pointToWorldFrame=function(t,e,o,i){return void 0===i&&(i=new s),e.vmult(o,i),i.vadd(t,i),i},t.vectorToWorldFrame=function(t,e,o){return void 0===o&&(o=new s),t.vmult(e,o),o},t.vectorToLocalFrame=function(t,e,o,i){return void 0===i&&(i=new s),e.w*=-1,e.vmult(o,i),e.w*=-1,i},t}(),A=new y,B=(a=function(t,e){return a=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])},a(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function o(){this.constructor=t}a(t,e),t.prototype=null===e?Object.create(e):(o.prototype=e.prototype,new o)}),E=function(t){function e(e){void 0===e&&(e={});var o=this,i=e.vertices,n=void 0===i?[]:i,r=e.faces,s=void 0===r?[]:r,a=e.normals,l=void 0===a?[]:a,c=e.axes,u=e.boundingSphereRadius;return(o=t.call(this,{type:b.types.CONVEXPOLYHEDRON})||this).vertices=n,o.faces=s,o.faceNormals=l,0===o.faceNormals.length&&o.computeNormals(),u?o.boundingSphereRadius=u:o.updateBoundingSphereRadius(),o.worldVertices=[],o.worldVerticesNeedsUpdate=!0,o.worldFaceNormals=[],o.worldFaceNormalsNeedsUpdate=!0,o.uniqueAxes=c?c.slice():null,o.uniqueEdges=[],o.computeEdges(),o}return B(e,t),e.prototype.computeEdges=function(){var t=this.faces,e=this.vertices,o=this.uniqueEdges;o.length=0;for(var i=new s,n=0;n!==t.length;n++)for(var r=t[n],a=r.length,l=0;l!==a;l++){var c=(l+1)%a;e[r[l]].vsub(e[r[c]],i),i.normalize();for(var u=!1,h=0;h!==o.length;h++)if(o[h].almostEquals(i)||o[h].almostEquals(i)){u=!0;break}u||o.push(i.clone())}},e.prototype.computeNormals=function(){this.faceNormals.length=this.faces.length;for(var t=0;t<this.faces.length;t++){for(var e=0;e<this.faces[t].length;e++)if(!this.vertices[this.faces[t][e]])throw new Error("Vertex ".concat(this.faces[t][e]," not found!"));var o=this.faceNormals[t]||new s;this.getFaceNormal(t,o),o.negate(o),this.faceNormals[t]=o;var i=this.vertices[this.faces[t][0]];if(o.dot(i)<0){console.error(".faceNormals[".concat(t,"] = Vec3(").concat(o.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(e=0;e<this.faces[t].length;e++)console.warn(".vertices[".concat(this.faces[t][e],"] = Vec3(").concat(this.vertices[this.faces[t][e]].toString(),")"))}}},e.prototype.getFaceNormal=function(t,o){var i=this.faces[t],n=this.vertices[i[0]],r=this.vertices[i[1]],s=this.vertices[i[2]];e.computeNormal(n,r,s,o)},e.computeNormal=function(t,e,o,i){var n=new s,r=new s;e.vsub(t,r),o.vsub(e,n),n.cross(r,i),i.isZero()||i.normalize()},e.prototype.clipAgainstHull=function(t,e,o,i,n,r,a,l,c){for(var u=new s,h=-1,p=-Number.MAX_VALUE,d=0;d<o.faces.length;d++){u.copy(o.faceNormals[d]),n.vmult(u,u);var v=u.dot(r);v>p&&(p=v,h=d)}for(var f=[],y=0;y<o.faces[h].length;y++){var m=o.vertices[o.faces[h][y]],w=new s;w.copy(m),n.vmult(w,w),i.vadd(w,w),f.push(w)}h>=0&&this.clipFaceAgainstHull(r,t,e,f,a,l,c)},e.prototype.findSeparatingAxis=function(t,e,o,i,n,r,a,l){var c=new s,u=new s,h=new s,p=new s,d=new s,v=new s,f=Number.MAX_VALUE,y=this;if(y.uniqueAxes)for(w=0;w!==y.uniqueAxes.length;w++){if(o.vmult(y.uniqueAxes[w],c),!1===(x=y.testSepAxis(c,t,e,o,i,n)))return!1;x<f&&(f=x,r.copy(c))}else for(var m=a?a.length:y.faces.length,w=0;w<m;w++){var g=a?a[w]:w;if(c.copy(y.faceNormals[g]),o.vmult(c,c),!1===(x=y.testSepAxis(c,t,e,o,i,n)))return!1;x<f&&(f=x,r.copy(c))}if(t.uniqueAxes)for(w=0;w!==t.uniqueAxes.length;w++){if(n.vmult(t.uniqueAxes[w],u),!1===(x=y.testSepAxis(u,t,e,o,i,n)))return!1;x<f&&(f=x,r.copy(u))}else for(var b=l?l.length:t.faces.length,w=0;w<b;w++){var x;g=l?l[w]:w;if(u.copy(t.faceNormals[g]),n.vmult(u,u),!1===(x=y.testSepAxis(u,t,e,o,i,n)))return!1;x<f&&(f=x,r.copy(u))}for(var A=0;A!==y.uniqueEdges.length;A++){o.vmult(y.uniqueEdges[A],p);for(var B=0;B!==t.uniqueEdges.length;B++)if(n.vmult(t.uniqueEdges[B],d),p.cross(d,v),!v.almostZero()){v.normalize();var E=y.testSepAxis(v,t,e,o,i,n);if(!1===E)return!1;E<f&&(f=E,r.copy(v))}}return i.vsub(e,h),h.dot(r)>0&&r.negate(r),!0},e.prototype.testSepAxis=function(t,o,i,n,r,s){e.project(this,t,i,n,S),e.project(o,t,r,s,C);var a=S[0],l=S[1],c=C[0],u=C[1];if(a<u||c<l)return!1;var h=a-u,p=c-l;return h<p?h:p},e.prototype.calculateLocalInertia=function(t,e){var o=new s,i=new s;this.computeLocalAABB(i,o);var n=o.x-i.x,r=o.y-i.y,a=o.z-i.z;e.x=1/12*t*(2*r*2*r+2*a*2*a),e.y=1/12*t*(2*n*2*n+2*a*2*a),e.z=1/12*t*(2*r*2*r+2*n*2*n)},e.prototype.getPlaneConstantOfFace=function(t){var e=this.faces[t],o=this.faceNormals[t],i=this.vertices[e[0]];return-o.dot(i)},e.prototype.clipFaceAgainstHull=function(t,e,o,i,n,r,a){for(var l=new s,c=new s,u=new s,h=new s,p=new s,d=new s,v=new s,f=new s,y=this,m=i,w=[],g=-1,b=Number.MAX_VALUE,x=0;x<y.faces.length;x++){l.copy(y.faceNormals[x]),o.vmult(l,l);var A=l.dot(t);A<b&&(b=A,g=x)}if(!(g<0)){var B=y.faces[g];B.connectedFaces=[];for(var E=0;E<y.faces.length;E++)for(var S=0;S<y.faces[E].length;S++)-1!==B.indexOf(y.faces[E][S])&&E!==g&&-1===B.connectedFaces.indexOf(E)&&B.connectedFaces.push(E);var C=B.length;for(E=0;E<C;E++){var z=y.vertices[B[E]],P=y.vertices[B[(E+1)%C]];z.vsub(P,c),u.copy(c),o.vmult(u,u),e.vadd(u,u),h.copy(this.faceNormals[g]),o.vmult(h,h),e.vadd(h,h),u.cross(h,p),p.negate(p),d.copy(z),o.vmult(d,d),e.vadd(d,d);var M=B.connectedFaces[E];v.copy(this.faceNormals[M]);var T=this.getPlaneConstantOfFace(M);f.copy(v),o.vmult(f,f);var F=T-f.dot(e);for(this.clipFaceAgainstPlane(m,w,f,F);m.length;)m.shift();for(;w.length;)m.push(w.shift())}v.copy(this.faceNormals[g]);var _=this.getPlaneConstantOfFace(g);f.copy(v),o.vmult(f,f);var O=_-f.dot(e);for(E=0;E<m.length;E++){var R=f.dot(m[E])+O;if(R<=n&&(console.log("clamped: depth=".concat(R," to minDist=").concat(n)),R=n),R<=r){var I=m[E];if(R<=1e-6){var j={point:I,normal:f,depth:R};a.push(j)}}}}},e.prototype.clipFaceAgainstPlane=function(t,e,o,i){var n,r,a=t.length;if(a<2)return e;var l=t[t.length-1],c=t[0];n=o.dot(l)+i;for(var u=0;u<a;u++){if(c=t[u],r=o.dot(c)+i,n<0)if(r<0){(h=new s).copy(c),e.push(h)}else{var h=new s;l.lerp(c,n/(n-r),h),e.push(h)}else if(r<0){h=new s;l.lerp(c,n/(n-r),h),e.push(h),e.push(c)}l=c,n=r}return e},e.prototype.computeWorldVertices=function(t,e){for(;this.worldVertices.length<this.vertices.length;)this.worldVertices.push(new s);for(var o=this.vertices,i=this.worldVertices,n=0;n!==this.vertices.length;n++)e.vmult(o[n],i[n]),t.vadd(i[n],i[n]);this.worldVerticesNeedsUpdate=!1},e.prototype.computeLocalAABB=function(t,e){var o=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(var i=0;i<this.vertices.length;i++){var n=o[i];n.x<t.x?t.x=n.x:n.x>e.x&&(e.x=n.x),n.y<t.y?t.y=n.y:n.y>e.y&&(e.y=n.y),n.z<t.z?t.z=n.z:n.z>e.z&&(e.z=n.z)}},e.prototype.computeWorldFaceNormals=function(t){for(var e=this.faceNormals.length;this.worldFaceNormals.length<e;)this.worldFaceNormals.push(new s);for(var o=this.faceNormals,i=this.worldFaceNormals,n=0;n!==e;n++)t.vmult(o[n],i[n]);this.worldFaceNormalsNeedsUpdate=!1},e.prototype.updateBoundingSphereRadius=function(){for(var t=0,e=this.vertices,o=0;o!==e.length;o++){var i=e[o].lengthSquared();i>t&&(t=i)}this.boundingSphereRadius=Math.sqrt(t)},e.prototype.calculateWorldAABB=function(t,e,o,i){for(var n,r,a,l,c,u,h=this.vertices,p=new s,d=0;d<h.length;d++){p.copy(h[d]),e.vmult(p,p),t.vadd(p,p);var v=p;(void 0===n||v.x<n)&&(n=v.x),(void 0===l||v.x>l)&&(l=v.x),(void 0===r||v.y<r)&&(r=v.y),(void 0===c||v.y>c)&&(c=v.y),(void 0===a||v.z<a)&&(a=v.z),(void 0===u||v.z>u)&&(u=v.z)}o.set(n,r,a),i.set(l,c,u)},e.prototype.volume=function(){return 4*Math.PI*this.boundingSphereRadius/3},e.prototype.getAveragePointLocal=function(t){void 0===t&&(t=new s);for(var e=this.vertices,o=0;o<e.length;o++)t.vadd(e[o],t);return t.scale(1/e.length,t),t},e.prototype.transformAllPoints=function(t,e){var o=this.vertices.length,i=this.vertices;if(e){for(var n=0;n<o;n++){var r=i[n];e.vmult(r,r)}for(n=0;n<this.faceNormals.length;n++){r=this.faceNormals[n];e.vmult(r,r)}}if(t)for(n=0;n<o;n++){(r=i[n]).vadd(t,r)}},e.prototype.pointIsInside=function(t){var e=this.vertices,o=this.faces,i=this.faceNormals,n=new s;this.getAveragePointLocal(n);for(var r=0;r<this.faces.length;r++){var a=i[r],l=e[o[r][0]],c=new s;t.vsub(l,c);var u=a.dot(c),h=new s;n.vsub(l,h);var p=a.dot(h);if(u<0&&p>0||u>0&&p<0)return!1}return-1},e.project=function(t,e,o,i,n){var r=t.vertices.length,s=z,a=0,l=0,c=P,u=t.vertices;c.setZero(),x.vectorToLocalFrame(o,i,e,s),x.pointToLocalFrame(o,i,c,c);var h=c.dot(s);l=a=u[0].dot(s);for(var p=1;p<r;p++){var d=u[p].dot(s);d>a&&(a=d),d<l&&(l=d)}if((l-=h)>(a-=h)){var v=l;l=a,a=v}n[0]=a,n[1]=l},e}(b),S=[],C=[],z=(new s,new s),P=new s,M=function(){var t=function(e,o){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])},t(e,o)};return function(e,o){if("function"!=typeof o&&null!==o)throw new TypeError("Class extends value "+String(o)+" is not a constructor or null");function i(){this.constructor=e}t(e,o),e.prototype=null===o?Object.create(o):(i.prototype=o.prototype,new i)}}(),T=function(t){function e(e){var o=t.call(this,{type:b.types.BOX})||this;return o.halfExtents=e,o.convexPolyhedronRepresentation=null,o.updateConvexPolyhedronRepresentation(),o.updateBoundingSphereRadius(),o}return M(e,t),e.prototype.updateConvexPolyhedronRepresentation=function(){var t=this.halfExtents.x,e=this.halfExtents.y,o=this.halfExtents.z,i=s,n=[new i(-t,-e,-o),new i(t,-e,-o),new i(t,e,-o),new i(-t,e,-o),new i(-t,-e,o),new i(t,-e,o),new i(t,e,o),new i(-t,e,o)],r=[new i(0,0,1),new i(0,1,0),new i(1,0,0)],a=new E({vertices:n,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:r});this.convexPolyhedronRepresentation=a,a.material=this.material},e.prototype.calculateLocalInertia=function(t,o){return void 0===o&&(o=new s),e.calculateInertia(this.halfExtents,t,o),o},e.calculateInertia=function(t,e,o){var i=t;o.x=1/12*e*(2*i.y*2*i.y+2*i.z*2*i.z),o.y=1/12*e*(2*i.x*2*i.x+2*i.z*2*i.z),o.z=1/12*e*(2*i.y*2*i.y+2*i.x*2*i.x)},e.prototype.getSideNormals=function(t,e){var o=t,i=this.halfExtents;if(o[0].set(i.x,0,0),o[1].set(0,i.y,0),o[2].set(0,0,i.z),o[3].set(-i.x,0,0),o[4].set(0,-i.y,0),o[5].set(0,0,-i.z),void 0!==e)for(var n=0;n!==o.length;n++)e.vmult(o[n],o[n]);return o},e.prototype.volume=function(){return 8*this.halfExtents.x*this.halfExtents.y*this.halfExtents.z},e.prototype.updateBoundingSphereRadius=function(){this.boundingSphereRadius=this.halfExtents.length()},e.prototype.forEachWorldCorner=function(t,e,o){for(var i=this.halfExtents,n=[[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]],r=0;r<n.length;r++)F.set(n[r][0],n[r][1],n[r][2]),e.vmult(F,F),t.vadd(F,F),o(F.x,F.y,F.z)},e.prototype.calculateWorldAABB=function(t,e,o,i){var n=this.halfExtents;_[0].set(n.x,n.y,n.z),_[1].set(-n.x,n.y,n.z),_[2].set(-n.x,-n.y,n.z),_[3].set(-n.x,-n.y,-n.z),_[4].set(n.x,-n.y,-n.z),_[5].set(n.x,n.y,-n.z),_[6].set(-n.x,n.y,-n.z),_[7].set(n.x,-n.y,n.z);var r=_[0];e.vmult(r,r),t.vadd(r,r),i.copy(r),o.copy(r);for(var s=1;s<8;s++){var a=_[s];e.vmult(a,a),t.vadd(a,a);var l=a.x,c=a.y,u=a.z;l>i.x&&(i.x=l),c>i.y&&(i.y=c),u>i.z&&(i.z=u),l<o.x&&(o.x=l),c<o.y&&(o.y=c),u<o.z&&(o.z=u)}},e}(b),F=new s,_=[new s,new s,new s,new s,new s,new s,new s,new s],O=function(){var t=function(e,o){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])},t(e,o)};return function(e,o){if("function"!=typeof o&&null!==o)throw new TypeError("Class extends value "+String(o)+" is not a constructor or null");function i(){this.constructor=e}t(e,o),e.prototype=null===o?Object.create(o):(i.prototype=o.prototype,new i)}}(),R={DYNAMIC:1,STATIC:2,KINEMATIC:4},I={AWAKE:0,SLEEPY:1,SLEEPING:2},j=function(t){function e(o){void 0===o&&(o={});var i=t.call(this)||this;i.id=e.idCounter++,i.index=-1,i.world=null,i.vlambda=new s,i.collisionFilterGroup="number"==typeof o.collisionFilterGroup?o.collisionFilterGroup:1,i.collisionFilterMask="number"==typeof o.collisionFilterMask?o.collisionFilterMask:-1,i.collisionResponse="boolean"!=typeof o.collisionResponse||o.collisionResponse,i.position=new s,i.previousPosition=new s,i.interpolatedPosition=new s,i.initPosition=new s,o.position&&(i.position.copy(o.position),i.previousPosition.copy(o.position),i.interpolatedPosition.copy(o.position),i.initPosition.copy(o.position)),i.velocity=new s,o.velocity&&i.velocity.copy(o.velocity),i.initVelocity=new s,i.force=new s;var r="number"==typeof o.mass?o.mass:0;return i.mass=r,i.invMass=r>0?1/r:0,i.material=o.material||null,i.linearDamping="number"==typeof o.linearDamping?o.linearDamping:.01,i.type=r<=0?e.STATIC:e.DYNAMIC,typeof o.type==typeof e.STATIC&&(i.type=o.type),i.allowSleep=void 0===o.allowSleep||o.allowSleep,i.sleepState=e.AWAKE,i.sleepSpeedLimit=void 0!==o.sleepSpeedLimit?o.sleepSpeedLimit:.1,i.sleepTimeLimit=void 0!==o.sleepTimeLimit?o.sleepTimeLimit:1,i.timeLastSleepy=0,i.wakeUpAfterNarrowphase=!1,i.torque=new s,i.quaternion=new y,i.initQuaternion=new y,i.previousQuaternion=new y,i.interpolatedQuaternion=new y,o.quaternion&&(i.quaternion.copy(o.quaternion),i.initQuaternion.copy(o.quaternion),i.previousQuaternion.copy(o.quaternion),i.interpolatedQuaternion.copy(o.quaternion)),i.angularVelocity=new s,o.angularVelocity&&i.angularVelocity.copy(o.angularVelocity),i.initAngularVelocity=new s,i.shapes=[],i.shapeOffsets=[],i.shapeOrientations=[],i.inertia=new s,i.invInertia=new s,i.invInertiaWorld=new n,i.invMassSolve=0,i.invInertiaSolve=new s,i.invInertiaWorldSolve=new n,i.fixedRotation=void 0!==o.fixedRotation&&o.fixedRotation,i.angularDamping=void 0!==o.angularDamping?o.angularDamping:.01,i.linearFactor=new s(1,1,1),o.linearFactor&&i.linearFactor.copy(o.linearFactor),i.angularFactor=new s(1,1,1),o.angularFactor&&i.angularFactor.copy(o.angularFactor),i.aabb=new h,i.aabbNeedsUpdate=!0,i.boundingRadius=0,i.wlambda=new s,i.isTrigger=Boolean(o.isTrigger),o.shape&&i.addShape(o.shape),i.updateMassProperties(),i}return O(e,t),e.prototype.wakeUp=function(){var t=this.sleepState;this.sleepState=e.AWAKE,this.wakeUpAfterNarrowphase=!1,t===e.SLEEPING&&this.dispatchEvent(e.wakeupEvent)},e.prototype.sleep=function(){this.sleepState=e.SLEEPING,this.velocity.set(0,0,0),this.angularVelocity.set(0,0,0),this.wakeUpAfterNarrowphase=!1},e.prototype.sleepTick=function(t){if(this.allowSleep){var o=this.sleepState,i=this.velocity.lengthSquared()+this.angularVelocity.lengthSquared(),n=Math.pow(this.sleepSpeedLimit,2);o===e.AWAKE&&i<n?(this.sleepState=e.SLEEPY,this.timeLastSleepy=t,this.dispatchEvent(e.sleepyEvent)):o===e.SLEEPY&&i>n?this.wakeUp():o===e.SLEEPY&&t-this.timeLastSleepy>this.sleepTimeLimit&&(this.sleep(),this.dispatchEvent(e.sleepEvent))}},e.prototype.updateSolveMassProperties=function(){this.sleepState===e.SLEEPING||this.type===e.KINEMATIC?(this.invMassSolve=0,this.invInertiaSolve.setZero(),this.invInertiaWorldSolve.setZero()):(this.invMassSolve=this.invMass,this.invInertiaSolve.copy(this.invInertia),this.invInertiaWorldSolve.copy(this.invInertiaWorld))},e.prototype.pointToLocalFrame=function(t,e){return void 0===e&&(e=new s),t.vsub(this.position,e),this.quaternion.conjugate().vmult(e,e),e},e.prototype.vectorToLocalFrame=function(t,e){return void 0===e&&(e=new s),this.quaternion.conjugate().vmult(t,e),e},e.prototype.pointToWorldFrame=function(t,e){return void 0===e&&(e=new s),this.quaternion.vmult(t,e),e.vadd(this.position,e),e},e.prototype.vectorToWorldFrame=function(t,e){return void 0===e&&(e=new s),this.quaternion.vmult(t,e),e},e.prototype.addShape=function(t,e,o){var i=new s,n=new y;return e&&i.copy(e),o&&n.copy(o),this.shapes.push(t),this.shapeOffsets.push(i),this.shapeOrientations.push(n),this.updateMassProperties(),this.updateBoundingRadius(),this.aabbNeedsUpdate=!0,t.body=this,this},e.prototype.removeShape=function(t){var 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)},e.prototype.updateBoundingRadius=function(){for(var t=this.shapes,e=this.shapeOffsets,o=t.length,i=0,n=0;n!==o;n++){var r=t[n];r.updateBoundingSphereRadius();var s=e[n].length(),a=r.boundingSphereRadius;s+a>i&&(i=s+a)}this.boundingRadius=i},e.prototype.updateAABB=function(){for(var t=this.shapes,e=this.shapeOffsets,o=this.shapeOrientations,i=t.length,n=q,r=N,s=this.quaternion,a=this.aabb,l=L,c=0;c!==i;c++){var u=t[c];s.vmult(e[c],n),n.vadd(this.position,n),s.mult(o[c],r),u.calculateWorldAABB(n,r,l.lowerBound,l.upperBound),0===c?a.copy(l):a.extend(l)}this.aabbNeedsUpdate=!1},e.prototype.updateInertiaWorld=function(t){var e=this.invInertia;if(e.x!==e.y||e.y!==e.z||t){var o=W,i=V;o.setRotationFromQuaternion(this.quaternion),o.transpose(i),o.scale(e,o),o.mmult(i,this.invInertiaWorld)}else;},e.prototype.applyForce=function(t,o){if(void 0===o&&(o=new s),this.type===e.DYNAMIC){this.sleepState===e.SLEEPING&&this.wakeUp();var i=k;o.cross(t,i),this.force.vadd(t,this.force),this.torque.vadd(i,this.torque)}},e.prototype.applyLocalForce=function(t,o){if(void 0===o&&(o=new s),this.type===e.DYNAMIC){var i=H,n=D;this.vectorToWorldFrame(t,i),this.vectorToWorldFrame(o,n),this.applyForce(i,n)}},e.prototype.applyTorque=function(t){this.type===e.DYNAMIC&&(this.sleepState===e.SLEEPING&&this.wakeUp(),this.torque.vadd(t,this.torque))},e.prototype.applyImpulse=function(t,o){if(void 0===o&&(o=new s),this.type===e.DYNAMIC){this.sleepState===e.SLEEPING&&this.wakeUp();var i=o,n=U;n.copy(t),n.scale(this.invMass,n),this.velocity.vadd(n,this.velocity);var r=G;i.cross(t,r),this.invInertiaWorld.vmult(r,r),this.angularVelocity.vadd(r,this.angularVelocity)}},e.prototype.applyLocalImpulse=function(t,o){if(void 0===o&&(o=new s),this.type===e.DYNAMIC){var i=Y,n=X;this.vectorToWorldFrame(t,i),this.vectorToWorldFrame(o,n),this.applyImpulse(i,n)}},e.prototype.updateMassProperties=function(){var t=K;this.invMass=this.mass>0?1/this.mass:0;var e=this.inertia,o=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),T.calculateInertia(t,this.mass,e),this.invInertia.set(e.x>0&&!o?1/e.x:0,e.y>0&&!o?1/e.y:0,e.z>0&&!o?1/e.z:0),this.updateInertiaWorld(!0)},e.prototype.getVelocityAtWorldPoint=function(t,e){var o=new s;return t.vsub(this.position,o),this.angularVelocity.cross(o,e),this.velocity.vadd(e,e),e},e.prototype.integrate=function(t,o,i){if(this.previousPosition.copy(this.position),this.previousQuaternion.copy(this.quaternion),(this.type===e.DYNAMIC||this.type===e.KINEMATIC)&&this.sleepState!==e.SLEEPING){var n=this.velocity,r=this.angularVelocity,s=this.position,a=this.force,l=this.torque,c=this.quaternion,u=this.invMass,h=this.invInertiaWorld,p=this.linearFactor,d=u*t;n.x+=a.x*d*p.x,n.y+=a.y*d*p.y,n.z+=a.z*d*p.z;var v=h.elements,f=this.angularFactor,y=l.x*f.x,m=l.y*f.y,w=l.z*f.z;r.x+=t*(v[0]*y+v[1]*m+v[2]*w),r.y+=t*(v[3]*y+v[4]*m+v[5]*w),r.z+=t*(v[6]*y+v[7]*m+v[8]*w),s.x+=n.x*t,s.y+=n.y*t,s.z+=n.z*t,c.integrate(this.angularVelocity,t,this.angularFactor,c),o&&(i?c.normalizeFast():c.normalize()),this.aabbNeedsUpdate=!0,this.updateInertiaWorld()}},e.idCounter=0,e.COLLIDE_EVENT_NAME="collide",e.DYNAMIC=R.DYNAMIC,e.STATIC=R.STATIC,e.KINEMATIC=R.KINEMATIC,e.AWAKE=I.AWAKE,e.SLEEPY=I.SLEEPY,e.SLEEPING=I.SLEEPING,e.wakeupEvent={type:"wakeup"},e.sleepyEvent={type:"sleepy"},e.sleepEvent={type:"sleep"},e}(f),q=new s,N=new y,L=new h,W=new n,V=new n,k=(new n,new s),H=new s,D=new s,U=new s,G=new s,Y=new s,X=new s,K=new s,Z=function(){function t(){this.world=null,this.useBoundingBoxes=!1,this.dirty=!0}return t.prototype.collisionPairs=function(t,e,o){throw new Error("collisionPairs not implemented for this BroadPhase class!")},t.prototype.needBroadphaseCollision=function(t,e){return 0!=(t.collisionFilterGroup&e.collisionFilterMask)&&0!=(e.collisionFilterGroup&t.collisionFilterMask)&&(0==(t.type&j.STATIC)&&t.sleepState!==j.SLEEPING||0==(e.type&j.STATIC)&&e.sleepState!==j.SLEEPING)},t.prototype.intersectionTest=function(t,e,o,i){this.useBoundingBoxes?this.doBoundingBoxBroadphase(t,e,o,i):this.doBoundingSphereBroadphase(t,e,o,i)},t.prototype.doBoundingSphereBroadphase=function(t,e,o,i){var n=Q;e.position.vsub(t.position,n);var r=Math.pow(t.boundingRadius+e.boundingRadius,2);n.lengthSquared()<r&&(o.push(t),i.push(e))},t.prototype.doBoundingBoxBroadphase=function(t,e,o,i){t.aabbNeedsUpdate&&t.updateAABB(),e.aabbNeedsUpdate&&e.updateAABB(),t.aabb.overlaps(e.aabb)&&(o.push(t),i.push(e))},t.prototype.makePairsUnique=function(t,e){for(var o=J,i=$,n=tt,r=t.length,s=0;s!==r;s++)i[s]=t[s],n[s]=e[s];t.length=0,e.length=0;for(s=0;s!==r;s++){var a=i[s].id,l=n[s].id;o[c=a<l?"".concat(a,",").concat(l):"".concat(l,",").concat(a)]=s,o.keys.push(c)}for(s=0;s!==o.keys.length;s++){var c=o.keys.pop(),u=o[c];t.push(i[u]),e.push(n[u]),delete o[c]}},t.prototype.setWorld=function(t){},t.boundingSphereCheck=function(t,e){var o=new s;t.position.vsub(e.position,o);var i=t.shapes[0],n=e.shapes[0];return Math.pow(i.boundingSphereRadius+n.boundingSphereRadius,2)>o.lengthSquared()},t.prototype.aabbQuery=function(t,e,o){return console.warn(".aabbQuery is not implemented in this Broadphase subclass."),[]},t}(),Q=new s,J=(new s,new y,new s,{keys:[]}),$=[],tt=[],et=(new s,function(){var t=function(e,o){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])},t(e,o)};return function(e,o){if("function"!=typeof o&&null!==o)throw new TypeError("Class extends value "+String(o)+" is not a constructor or null");function i(){this.constructor=e}t(e,o),e.prototype=null===o?Object.create(o):(i.prototype=o.prototype,new i)}}()),ot=function(t){function e(e,o,i,n,r){void 0===e&&(e=new s(100,100,100)),void 0===o&&(o=new s(-100,-100,-100)),void 0===i&&(i=10),void 0===n&&(n=10),void 0===r&&(r=10);var a=t.call(this)||this;a.nx=i,a.ny=n,a.nz=r,a.aabbMin=e,a.aabbMax=o;var l=a.nx*a.ny*a.nz;if(l<=0)throw"GridBroadphase: Each dimension's n must be >0";a.bins=[],a.binLengths=[],a.bins.length=l,a.binLengths.length=l;for(var c=0;c<l;c++)a.bins[c]=[],a.binLengths[c]=0;return a}return et(e,t),e.prototype.collisionPairs=function(t,e,o){for(var i=t.bodies.length,n=t.bodies,r=this.aabbMax,s=this.aabbMin,a=this.nx,l=this.ny,c=this.nz,u=l*c,h=c,p=r.x,d=r.y,v=r.z,f=s.x,y=s.y,m=s.z,w=a/(p-f),g=l/(d-y),x=c/(v-m),A=(p-f)/a,B=(d-y)/l,E=(v-m)/c,S=.5*Math.sqrt(A*A+B*B+E*E),C=b.types,z=C.SPHERE,P=C.PLANE,M=(C.BOX,C.COMPOUND,C.CONVEXPOLYHEDRON,this.bins),T=this.binLengths,F=this.bins.length,_=0;_!==F;_++)T[_]=0;var O=Math.ceil;function R(t,e,o,i,n,r,s){var p=(t-f)*w|0,d=(e-y)*g|0,v=(o-m)*x|0,b=O((i-f)*w),A=O((n-y)*g),B=O((r-m)*x);p<0?p=0:p>=a&&(p=a-1),d<0?d=0:d>=l&&(d=l-1),v<0?v=0:v>=c&&(v=c-1),b<0?b=0:b>=a&&(b=a-1),A<0?A=0:A>=l&&(A=l-1),B<0?B=0:B>=c&&(B=c-1),d*=h,v*=1,b*=u,A*=h,B*=1;for(var E=p*=u;E<=b;E+=u)for(var S=d;S<=A;S+=h)for(var C=v;C<=B;C+=1){var z=E+S+C;M[z][T[z]++]=s}}for(_=0;_!==i;_++){var I=(et=n[_]).shapes[0];switch(I.type){case z:var j=I,q=et.position.x,N=et.position.y,L=et.position.z,W=j.radius;R(q-W,N-W,L-W,q+W,N+W,L+W,et);break;case P:(j=I).worldNormalNeedsUpdate&&j.computeWorldNormal(et.quaternion);var V=j.worldNormal,k=f+.5*A-et.position.x,H=y+.5*B-et.position.y,D=m+.5*E-et.position.z,U=it;U.set(k,H,D);for(var G=0,Y=0;G!==a;G++,Y+=u,U.y=H,U.x+=A)for(var X=0,K=0;X!==l;X++,K+=h,U.z=D,U.y+=B)for(var Z=0,Q=0;Z!==c;Z++,Q+=1,U.z+=E)if(U.dot(V)<S){var J=Y+K+Q;M[J][T[J]++]=et}break;default:et.aabbNeedsUpdate&&et.updateAABB(),R(et.aabb.lowerBound.x,et.aabb.lowerBound.y,et.aabb.lowerBound.z,et.aabb.upperBound.x,et.aabb.upperBound.y,et.aabb.upperBound.z,et)}}for(_=0;_!==F;_++){var $=T[_];if($>1){var tt=M[_];for(G=0;G!==$;G++){var et=tt[G];for(X=0;X!==G;X++){var ot=tt[X];this.needBroadphaseCollision(et,ot)&&this.intersectionTest(et,ot,e,o)}}}}this.makePairsUnique(e,o)},e}(Z),it=new s,nt=(new s,function(){var t=function(e,o){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])},t(e,o)};return function(e,o){if("function"!=typeof o&&null!==o)throw new TypeError("Class extends value "+String(o)+" is not a constructor or null");function i(){this.constructor=e}t(e,o),e.prototype=null===o?Object.create(o):(i.prototype=o.prototype,new i)}}()),rt=function(t){function e(){return t.call(this)||this}return nt(e,t),e.prototype.collisionPairs=function(t,e,o){for(var i,n,r=t.bodies,s=r.length,a=0;a!==s;a++)for(var l=0;l!==a;l++)i=r[a],n=r[l],this.needBroadphaseCollision(i,n)&&this.intersectionTest(i,n,e,o)},e.prototype.aabbQuery=function(t,e,o){void 0===o&&(o=[]);for(var i=0;i<t.bodies.length;i++){var n=t.bodies[i];n.aabbNeedsUpdate&&n.updateAABB(),n.aabb.overlaps(e)&&o.push(n)}return o},e}(Z),st=function(){function t(){this.rayFromWorld=new s,this.rayToWorld=new s,this.hitNormalWorld=new s,this.hitPointWorld=new s,this.hasHit=!1,this.shape=null,this.body=null,this.hitFaceIndex=-1,this.distance=-1,this.shouldStop=!1}return t.prototype.reset=function(){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},t.prototype.abort=function(){this.shouldStop=!0},t.prototype.set=function(t,e,o,i,n,r,s){this.rayFromWorld.copy(t),this.rayToWorld.copy(e),this.hitNormalWorld.copy(o),this.hitPointWorld.copy(i),this.shape=n,this.body=r,this.distance=s},t}(),at={CLOSEST:1,ANY:2,ALL:4},lt=function(){function t(e,o){void 0===e&&(e=new s),void 0===o&&(o=new s),this.from=e.clone(),this.to=o.clone(),this.direction=new s,this.precision=1e-4,this.checkCollisionResponse=!0,this.skipBackfaces=!1,this.collisionFilterMask=-1,this.collisionFilterGroup=-1,this.mode=t.ANY,this.result=new st,this.hasHit=!1,this.callback=function(t){}}return Object.defineProperty(t.prototype,b.types.SPHERE,{get:function(){return this._intersectSphere},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,b.types.PLANE,{get:function(){return this._intersectPlane},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,b.types.BOX,{get:function(){return this._intersectBox},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,b.types.CYLINDER,{get:function(){return this._intersectConvex},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,b.types.CONVEXPOLYHEDRON,{get:function(){return this._intersectConvex},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,b.types.HEIGHTFIELD,{get:function(){return this._intersectHeightfield},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,b.types.TRIMESH,{get:function(){return this._intersectTrimesh},enumerable:!1,configurable:!0}),t.prototype.intersectWorld=function(e,o){return this.mode=o.mode||t.ANY,this.result=o.result||new st,this.skipBackfaces=!!o.skipBackfaces,this.collisionFilterMask=void 0!==o.collisionFilterMask?o.collisionFilterMask:-1,this.collisionFilterGroup=void 0!==o.collisionFilterGroup?o.collisionFilterGroup:-1,this.checkCollisionResponse=void 0===o.checkCollisionResponse||o.checkCollisionResponse,o.from&&this.from.copy(o.from),o.to&&this.to.copy(o.to),this.callback=o.callback||function(){},this.hasHit=!1,this.result.reset(),this.updateDirection(),this.getAABB(ct),ut.length=0,e.broadphase.aabbQuery(e,ct,ut),this.intersectBodies(ut),this.hasHit},t.prototype.intersectBody=function(t,e){e&&(this.result=e,this.updateDirection());var o=this.checkCollisionResponse;if((!o||t.collisionResponse)&&0!=(this.collisionFilterGroup&t.collisionFilterMask)&&0!=(t.collisionFilterGroup&this.collisionFilterMask))for(var i=dt,n=vt,r=0,s=t.shapes.length;r<s;r++){var a=t.shapes[r];if((!o||a.collisionResponse)&&(t.quaternion.mult(t.shapeOrientations[r],n),t.quaternion.vmult(t.shapeOffsets[r],i),i.vadd(t.position,i),this.intersectShape(a,n,i,t),this.result.shouldStop))break}},t.prototype.intersectBodies=function(t,e){e&&(this.result=e,this.updateDirection());for(var o=0,i=t.length;!this.result.shouldStop&&o<i;o++)this.intersectBody(t[o])},t.prototype.updateDirection=function(){this.to.vsub(this.from,this.direction),this.direction.normalize()},t.prototype.intersectShape=function(t,e,o,i){var n=function(t,e,o){o.vsub(t,It);var i=It.dot(e);return e.scale(i,jt),jt.vadd(t,jt),o.distanceTo(jt)}(this.from,this.direction,o);if(!(n>t.boundingSphereRadius)){var r=this[t.type];r&&r.call(this,t,e,o,i,t)}},t.prototype._intersectBox=function(t,e,o,i,n){return this._intersectConvex(t.convexPolyhedronRepresentation,e,o,i,n)},t.prototype._intersectPlane=function(t,e,o,i,n){var r=this.from,a=this.to,l=this.direction,c=new s(0,0,1);e.vmult(c,c);var u=new s;r.vsub(o,u);var h=u.dot(c);if(a.vsub(o,u),!(h*u.dot(c)>0||r.distanceTo(a)<h)){var p=c.dot(l);if(!(Math.abs(p)<this.precision)){var d=new s,v=new s,f=new s;r.vsub(o,d);var y=-c.dot(d)/p;l.scale(y,v),r.vadd(v,f),this.reportIntersection(c,f,n,i,-1)}}},t.prototype.getAABB=function(t){var e=t.lowerBound,o=t.upperBound,i=this.to,n=this.from;e.x=Math.min(i.x,n.x),e.y=Math.min(i.y,n.y),e.z=Math.min(i.z,n.z),o.x=Math.max(i.x,n.x),o.y=Math.max(i.y,n.y),o.z=Math.max(i.z,n.z)},t.prototype._intersectHeightfield=function(t,e,o,i,n){t.data,t.elementSize;var r=xt;r.from.copy(this.from),r.to.copy(this.to),x.pointToLocalFrame(o,e,r.from,r.from),x.pointToLocalFrame(o,e,r.to,r.to),r.updateDirection();var s,a,l,c,u=At;s=a=0,l=c=t.data.length-1;var p=new h;r.getAABB(p),t.getIndexOfPosition(p.lowerBound.x,p.lowerBound.y,u,!0),s=Math.max(s,u[0]),a=Math.max(a,u[1]),t.getIndexOfPosition(p.upperBound.x,p.upperBound.y,u,!0),l=Math.min(l,u[0]+1),c=Math.min(c,u[1]+1);for(var d=s;d<l;d++)for(var v=a;v<c;v++){if(this.result.shouldStop)return;if(t.getAabbAtIndex(d,v,p),p.overlapsRay(r)){if(t.getConvexTrianglePillar(d,v,!1),x.pointToWorldFrame(o,e,t.pillarOffset,bt),this._intersectConvex(t.pillarConvex,e,bt,i,n,gt),this.result.shouldStop)return;t.getConvexTrianglePillar(d,v,!0),x.pointToWorldFrame(o,e,t.pillarOffset,bt),this._intersectConvex(t.pillarConvex,e,bt,i,n,gt)}}},t.prototype._intersectSphere=function(t,e,o,i,n){var r=this.from,s=this.to,a=t.radius,l=Math.pow(s.x-r.x,2)+Math.pow(s.y-r.y,2)+Math.pow(s.z-r.z,2),c=2*((s.x-r.x)*(r.x-o.x)+(s.y-r.y)*(r.y-o.y)+(s.z-r.z)*(r.z-o.z)),u=Math.pow(r.x-o.x,2)+Math.pow(r.y-o.y,2)+Math.pow(r.z-o.z,2)-Math.pow(a,2),h=Math.pow(c,2)-4*l*u,p=Bt,d=Et;if(!(h<0))if(0===h)r.lerp(s,h,p),p.vsub(o,d),d.normalize(),this.reportIntersection(d,p,n,i,-1);else{var v=(-c-Math.sqrt(h))/(2*l),f=(-c+Math.sqrt(h))/(2*l);if(v>=0&&v<=1&&(r.lerp(s,v,p),p.vsub(o,d),d.normalize(),this.reportIntersection(d,p,n,i,-1)),this.result.shouldStop)return;f>=0&&f<=1&&(r.lerp(s,f,p),p.vsub(o,d),d.normalize(),this.reportIntersection(d,p,n,i,-1))}},t.prototype._intersectConvex=function(e,o,i,n,r,s){for(var a=St,l=Ct,c=s&&s.faceList||null,u=e.faces,h=e.vertices,p=e.faceNormals,d=this.direction,v=this.from,f=this.to,y=v.distanceTo(f),m=c?c.length:u.length,w=this.result,g=0;!w.shouldStop&&g<m;g++){var b=c?c[g]:g,x=u[b],A=p[b],B=o,E=i;l.copy(h[x[0]]),B.vmult(l,l),l.vadd(E,l),l.vsub(v,l),B.vmult(A,a);var S=d.dot(a);if(!(Math.abs(S)<this.precision)){var C=a.dot(l)/S;if(!(C<0)){d.scale(C,ft),ft.vadd(v,ft),yt.copy(h[x[0]]),B.vmult(yt,yt),E.vadd(yt,yt);for(var z=1;!w.shouldStop&&z<x.length-1;z++){mt.copy(h[x[z]]),wt.copy(h[x[z+1]]),B.vmult(mt,mt),B.vmult(wt,wt),E.vadd(mt,mt),E.vadd(wt,wt);var P=ft.distanceTo(v);!t.pointInTriangle(ft,yt,mt,wt)&&!t.pointInTriangle(ft,mt,yt,wt)||P>y||this.reportIntersection(a,ft,r,n,b)}}}}},t.prototype._intersectTrimesh=function(e,o,i,n,r,s){var a=zt,l=Ot,c=Rt,u=Ct,h=Pt,p=Mt,d=Tt,v=_t,f=Ft,y=e.indices,m=(e.vertices,this.from),w=this.to,g=this.direction;c.position.copy(i),c.quaternion.copy(o),x.vectorToLocalFrame(i,o,g,h),x.pointToLocalFrame(i,o,m,p),x.pointToLocalFrame(i,o,w,d),d.x*=e.scale.x,d.y*=e.scale.y,d.z*=e.scale.z,p.x*=e.scale.x,p.y*=e.scale.y,p.z*=e.scale.z,d.vsub(p,h),h.normalize();var b=p.distanceSquared(d);e.tree.rayQuery(this,c,l);for(var A=0,B=l.length;!this.result.shouldStop&&A!==B;A++){var E=l[A];e.getNormal(E,a),e.getVertex(y[3*E],yt),yt.vsub(p,u);var S=h.dot(a),C=a.dot(u)/S;if(!(C<0)){h.scale(C,ft),ft.vadd(p,ft),e.getVertex(y[3*E+1],mt),e.getVertex(y[3*E+2],wt);var z=ft.distanceSquared(p);!t.pointInTriangle(ft,mt,yt,wt)&&!t.pointInTriangle(ft,yt,mt,wt)||z>b||(x.vectorToWorldFrame(o,a,f),x.pointToWorldFrame(i,o,ft,v),this.reportIntersection(f,v,r,n,E))}}l.length=0},t.prototype.reportIntersection=function(e,o,i,n,r){var s=this.from,a=this.to,l=s.distanceTo(o),c=this.result;if(!(this.skipBackfaces&&e.dot(this.direction)>0))switch(c.hitFaceIndex=void 0!==r?r:-1,this.mode){case t.ALL:this.hasHit=!0,c.set(s,a,e,o,i,n,l),c.hasHit=!0,this.callback(c);break;case t.CLOSEST:(l<c.distance||!c.hasHit)&&(this.hasHit=!0,c.hasHit=!0,c.set(s,a,e,o,i,n,l));break;case t.ANY:this.hasHit=!0,c.hasHit=!0,c.set(s,a,e,o,i,n,l),c.shouldStop=!0}},t.pointInTriangle=function(t,e,o,i){i.vsub(e,It),o.vsub(e,ht),t.vsub(e,pt);var n,r,s=It.dot(It),a=It.dot(ht),l=It.dot(pt),c=ht.dot(ht),u=ht.dot(pt);return(n=c*l-a*u)>=0&&(r=s*u-a*l)>=0&&n+r<s*c-a*a},t.CLOSEST=at.CLOSEST,t.ANY=at.ANY,t.ALL=at.ALL,t}(),ct=new h,ut=[],ht=new s,pt=new s,dt=new s,vt=new y,ft=new s,yt=new s,mt=new s,wt=new s,gt=(new s,new st,{faceList:[0]}),bt=new s,xt=new lt,At=[],Bt=new s,Et=new s,St=new s,Ct=(new s,new s,new s),zt=new s,Pt=new s,Mt=new s,Tt=new s,Ft=new s,_t=new s,Ot=(new h,[]),Rt=new x,It=new s,jt=new s;var qt=function(){var t=function(e,o){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])},t(e,o)};return function(e,o){if("function"!=typeof o&&null!==o)throw new TypeError("Class extends value "+String(o)+" is not a constructor or null");function i(){this.constructor=e}t(e,o),e.prototype=null===o?Object.create(o):(i.prototype=o.prototype,new i)}}(),Nt=function(t){function e(e){var o=t.call(this)||this;o.axisList=[],o.world=null,o.axisIndex=0;var i=o.axisList;return o._addBodyHandler=function(t){i.push(t.body)},o._removeBodyHandler=function(t){var e=i.indexOf(t.body);-1!==e&&i.splice(e,1)},e&&o.setWorld(e),o}return qt(e,t),e.checkBounds=function(t,e,o){var i,n;0===o?(i=t.position.x,n=e.position.x):1===o?(i=t.position.y,n=e.position.y):2===o&&(i=t.position.z,n=e.position.z);var r=t.boundingRadius;return n-e.boundingRadius<i+r},e.insertionSortX=function(t){for(var e=1,o=t.length;e<o;e++){var i=t[e],n=void 0;for(n=e-1;n>=0&&!(t[n].aabb.lowerBound.x<=i.aabb.lowerBound.x);n--)t[n+1]=t[n];t[n+1]=i}return t},e.insertionSortY=function(t){for(var e=1,o=t.length;e<o;e++){var i=t[e],n=void 0;for(n=e-1;n>=0&&!(t[n].aabb.lowerBound.y<=i.aabb.lowerBound.y);n--)t[n+1]=t[n];t[n+1]=i}return t},e.insertionSortZ=function(t){for(var e=1,o=t.length;e<o;e++){var i=t[e],n=void 0;for(n=e-1;n>=0&&!(t[n].aabb.lowerBound.z<=i.aabb.lowerBound.z);n--)t[n+1]=t[n];t[n+1]=i}return t},e.prototype.setWorld=function(t){this.axisList.length=0;for(var 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},e.prototype.collisionPairs=function(t,o,i){var n,r,s=this.axisList,a=s.length,l=this.axisIndex;for(this.dirty&&(this.sortList(),this.dirty=!1),n=0;n!==a;n++){var c=s[n];for(r=n+1;r<a;r++){var u=s[r];if(this.needBroadphaseCollision(c,u)){if(!e.checkBounds(c,u,l))break;this.intersectionTest(c,u,o,i)}}}},e.prototype.sortList=function(){for(var t=this.axisList,o=this.axisIndex,i=t.length,n=0;n!==i;n++){var r=t[n];r.aabbNeedsUpdate&&r.updateAABB()}0===o?e.insertionSortX(t):1===o?e.insertionSortY(t):2===o&&e.insertionSortZ(t)},e.prototype.autoDetectAxis=function(){for(var t=0,e=0,o=0,i=0,n=0,r=0,s=this.axisList,a=s.length,l=1/a,c=0;c!==a;c++){var u=s[c],h=u.position.x;t+=h,e+=h*h;var p=u.position.y;o+=p,i+=p*p;var d=u.position.z;n+=d,r+=d*d}var v=e-t*t*l,f=i-o*o*l,y=r-n*n*l;this.axisIndex=v>f?v>y?0:2:f>y?1:2},e.prototype.aabbQuery=function(t,e,o){void 0===o&&(o=[]),this.dirty&&(this.sortList(),this.dirty=!1);var i=this.axisIndex,n="x";1===i&&(n="y"),2===i&&(n="z");for(var r=this.axisList,s=(e.lowerBound[n],e.upperBound[n],0);s<r.length;s++){var a=r[s];a.aabbNeedsUpdate&&a.updateAABB(),a.aabb.overlaps(e)&&o.push(a)}return o},e}(Z),Lt=function(){function t(){}return t.defaults=function(t,e){for(var o in void 0===t&&(t={}),e)o in t||(t[o]=e[o]);return t},t}(),Wt=function(){function t(e,o,i){void 0===i&&(i={}),i=Lt.defaults(i,{collideConnected:!0,wakeUpBodies:!0}),this.equations=[],this.bodyA=e,this.bodyB=o,this.id=t.idCounter++,this.collideConnected=i.collideConnected,i.wakeUpBodies&&(e&&e.wakeUp(),o&&o.wakeUp())}return t.prototype.update=function(){throw new Error("method update() not implmemented in this Constraint subclass!")},t.prototype.enable=function(){for(var t=this.equations,e=0;e<t.length;e++)t[e].enabled=!0},t.prototype.disable=function(){for(var t=this.equations,e=0;e<t.length;e++)t[e].enabled=!1},t.idCounter=0,t}(),Vt=function(){function t(){this.spatial=new s,this.rotational=new s}return t.prototype.multiplyElement=function(t){return t.spatial.dot(this.spatial)+t.rotational.dot(this.rotational)},t.prototype.multiplyVectors=function(t,e){return t.dot(this.spatial)+e.dot(this.rotational)},t}(),kt=function(){function t(e,o,i,n){void 0===i&&(i=-1e6),void 0===n&&(n=1e6),this.id=t.idCounter++,this.minForce=i,this.maxForce=n,this.bi=e,this.bj=o,this.a=0,this.b=0,this.eps=0,this.jacobianElementA=new Vt,this.jacobianElementB=new Vt,this.enabled=!0,this.multiplier=0,this.setSpookParams(1e7,4,1/60)}return t.prototype.setSpookParams=function(t,e,o){var i=e,n=t,r=o;this.a=4/(r*(1+4*i)),this.b=4*i/(1+4*i),this.eps=4/(r*r*n*(1+4*i))},t.prototype.computeB=function(t,e,o){var i=this.computeGW();return-this.computeGq()*t-i*e-this.computeGiMf()*o},t.prototype.computeGq=function(){var t=this.jacobianElementA,e=this.jacobianElementB,o=this.bi,i=this.bj,n=o.position,r=i.position;return t.spatial.dot(n)+e.spatial.dot(r)},t.prototype.computeGW=function(){var t=this.jacobianElementA,e=this.jacobianElementB,o=this.bi,i=this.bj,n=o.velocity,r=i.velocity,s=o.angularVelocity,a=i.angularVelocity;return t.multiplyVectors(n,s)+e.multiplyVectors(r,a)},t.prototype.computeGWlambda=function(){var t=this.jacobianElementA,e=this.jacobianElementB,o=this.bi,i=this.bj,n=o.vlambda,r=i.vlambda,s=o.wlambda,a=i.wlambda;return t.multiplyVectors(n,s)+e.multiplyVectors(r,a)},t.prototype.computeGiMf=function(){var t=this.jacobianElementA,e=this.jacobianElementB,o=this.bi,i=this.bj,n=o.force,r=o.torque,s=i.force,a=i.torque,l=o.invMassSolve,c=i.invMassSolve;return n.scale(l,Ht),s.scale(c,Dt),o.invInertiaWorldSolve.vmult(r,Ut),i.invInertiaWorldSolve.vmult(a,Gt),t.multiplyVectors(Ht,Ut)+e.multiplyVectors(Dt,Gt)},t.prototype.computeGiMGt=function(){var t=this.jacobianElementA,e=this.jacobianElementB,o=this.bi,i=this.bj,n=o.invMassSolve,r=i.invMassSolve,s=o.invInertiaWorldSolve,a=i.invInertiaWorldSolve,l=n+r;return s.vmult(t.rotational,Yt),l+=Yt.dot(t.rotational),a.vmult(e.rotational,Yt),l+=Yt.dot(e.rotational)},t.prototype.addToWlambda=function(t){var e=this.jacobianElementA,o=this.jacobianElementB,i=this.bi,n=this.bj,r=Xt;i.vlambda.addScaledVector(i.invMassSolve*t,e.spatial,i.vlambda),n.vlambda.addScaledVector(n.invMassSolve*t,o.spatial,n.vlambda),i.invInertiaWorldSolve.vmult(e.rotational,r),i.wlambda.addScaledVector(t,r,i.wlambda),n.invInertiaWorldSolve.vmult(o.rotational,r),n.wlambda.addScaledVector(t,r,n.wlambda)},t.prototype.computeC=function(){return this.computeGiMGt()+this.eps},t.idCounter=0,t}(),Ht=new s,Dt=new s,Ut=new s,Gt=new s,Yt=new s,Xt=new s,Kt=function(){var t=function(e,o){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])},t(e,o)};return function(e,o){if("function"!=typeof o&&null!==o)throw new TypeError("Class extends value "+String(o)+" is not a constructor or null");function i(){this.constructor=e}t(e,o),e.prototype=null===o?Object.create(o):(i.prototype=o.prototype,new i)}}(),Zt=function(t){function e(e,o,i){void 0===i&&(i=1e6);var n=t.call(this,e,o,0,i)||this;return n.restitution=0,n.ri=new s,n.rj=new s,n.ni=new s,n}return Kt(e,t),e.prototype.computeB=function(t){var e=this.a,o=this.b,i=this.bi,n=this.bj,r=this.ri,s=this.rj,a=Qt,l=Jt,c=i.velocity,u=i.angularVelocity,h=(i.force,i.torque,n.velocity),p=n.angularVelocity,d=(n.force,n.torque,$t),v=this.jacobianElementA,f=this.jacobianElementB,y=this.ni;r.cross(y,a),s.cross(y,l),y.negate(v.spatial),a.negate(v.rotational),f.spatial.copy(y),f.rotational.copy(l),d.copy(n.position),d.vadd(s,d),d.vsub(i.position,d),d.vsub(r,d);var m=y.dot(d),w=this.restitution+1;return-m*e-(w*h.dot(y)-w*c.dot(y)+p.dot(l)-u.dot(a))*o-t*this.computeGiMf()},e.prototype.getImpactVelocityAlongNormal=function(){var t=te,e=ee,o=oe,i=ie,n=ne;return this.bi.position.vadd(this.ri,o),this.bj.position.vadd(this.rj,i),this.bi.getVelocityAtWorldPoint(o,t),this.bj.getVelocityAtWorldPoint(i,e),t.vsub(e,n),this.ni.dot(n)},e}(kt),Qt=new s,Jt=new s,$t=new s,te=new s,ee=new s,oe=new s,ie=new s,ne=new s,re=function(){var t=function(e,o){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])},t(e,o)};return function(e,o){if("function"!=typeof o&&null!==o)throw new TypeError("Class extends value "+String(o)+" is not a constructor or null");function i(){this.constructor=e}t(e,o),e.prototype=null===o?Object.create(o):(i.prototype=o.prototype,new i)}}(),se=function(t){function e(e,o,i,n,r){void 0===o&&(o=new s),void 0===n&&(n=new s),void 0===r&&(r=1e6);var a=t.call(this,e,i)||this;a.pivotA=o.clone(),a.pivotB=n.clone();var l=a.equationX=new Zt(e,i),c=a.equationY=new Zt(e,i),u=a.equationZ=new Zt(e,i);return a.equations.push(l,c,u),l.minForce=c.minForce=u.minForce=-r,l.maxForce=c.maxForce=u.maxForce=r,l.ni.set(1,0,0),c.ni.set(0,1,0),u.ni.set(0,0,1),a}return re(e,t),e.prototype.update=function(){var t=this.bodyA,e=this.bodyB,o=this.equationX,i=this.equationY,n=this.equationZ;t.quaternion.vmult(this.pivotA,o.ri),e.quaternion.vmult(this.pivotB,o.rj),i.ri.copy(o.ri),i.rj.copy(o.rj),n.ri.copy(o.ri),n.rj.copy(o.rj)},e}(Wt),ae=function(){var t=function(e,o){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])},t(e,o)};return function(e,o){if("function"!=typeof o&&null!==o)throw new TypeError("Class extends value "+String(o)+" is not a constructor or null");function i(){this.constructor=e}t(e,o),e.prototype=null===o?Object.create(o):(i.prototype=o.prototype,new i)}}(),le=function(t){function e(e,o,i){void 0===i&&(i={});var n=this,r=void 0!==i.maxForce?i.maxForce:1e6;return(n=t.call(this,e,o,-r,r)||this).axisA=i.axisA?i.axisA.clone():new s(1,0,0),n.axisB=i.axisB?i.axisB.clone():new s(0,1,0),n.angle=void 0!==i.angle?i.angle:0,n}return ae(e,t),e.prototype.computeB=function(t){var e=this.a,o=this.b,i=this.axisA,n=this.axisB,r=ce,s=ue,a=this.jacobianElementA,l=this.jacobianElementB;return i.cross(n,r),n.cross(i,s),a.rotational.copy(s),l.rotational.copy(r),-(Math.cos(this.angle)-i.dot(n))*e-this.computeGW()*o-t*this.computeGiMf()},e}(kt),ce=new s,ue=new s,he=function(){var t=function(e,o){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])},t(e,o)};return function(e,o){if("function"!=typeof o&&null!==o)throw new TypeError("Class extends value "+String(o)+" is not a constructor or null");function i(){this.constructor=e}t(e,o),e.prototype=null===o?Object.create(o):(i.prototype=o.prototype,new i)}}(),pe=function(t){function e(e,o,i){void 0===i&&(i={});var n=this,r=void 0!==i.maxForce?i.maxForce:1e6;return(n=t.call(this,e,o,-r,r)||this).axisA=i.axisA?i.axisA.clone():new s(1,0,0),n.axisB=i.axisB?i.axisB.clone():new s(0,1,0),n.maxAngle=Math.PI/2,n}return he(e,t),e.prototype.computeB=function(t){var e=this.a,o=this.b,i=this.axisA,n=this.axisB,r=de,s=ve,a=this.jacobianElementA,l=this.jacobianElementB;return i.cross(n,r),n.cross(i,s),a.rotational.copy(s),l.rotational.copy(r),-(Math.cos(this.maxAngle)-i.dot(n))*e-this.computeGW()*o-t*this.computeGiMf()},e}(kt),de=new s,ve=new s,fe=function(){var t=function(e,o){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])},t(e,o)};return function(e,o){if("function"!=typeof o&&null!==o)throw new TypeError("Class extends value "+String(o)+" is not a constructor or null");function i(){this.constructor=e}t(e,o),e.prototype=null===o?Object.create(o):(i.prototype=o.prototype,new i)}}(),ye=function(t){function e(e,o,i){void 0===i&&(i={});var n=this,r=void 0!==i.maxForce?i.maxForce:1e6,a=i.pivotA?i.pivotA.clone():new s,l=i.pivotB?i.pivotB.clone():new s;(n=t.call(this,e,a,o,l,r)||this).axisA=i.axisA?i.axisA.clone():new s,n.axisB=i.axisB?i.axisB.clone():new s,n.collideConnected=!!i.collideConnected,n.angle=void 0!==i.angle?i.angle:0;var c=n.coneEquation=new le(e,o,i),u=n.twistEquation=new pe(e,o,i);return n.twistAngle=void 0!==i.twistAngle?i.twistAngle:0,c.maxForce=0,c.minForce=-r,u.maxForce=0,u.minForce=-r,n.equations.push(c,u),n}return fe(e,t),e.prototype.update=function(){var e=this.bodyA,o=this.bodyB,i=this.coneEquation,n=this.twistEquation;t.prototype.update.call(this),e.vectorToWorldFrame(this.axisA,i.axisA),o.vectorToWorldFrame(this.axisB,i.axisB),this.axisA.tangents(n.axisA,n.axisA),e.vectorToWorldFrame(n.axisA,n.axisA),this.axisB.tangents(n.axisB,n.axisB),o.vectorToWorldFrame(n.axisB,n.axisB),i.angle=this.angle,n.maxAngle=this.twistAngle},e}(se),me=(new s,new s,function(){var t=function(e,o){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])},t(e,o)};return function(e,o){if("function"!=typeof o&&null!==o)throw new TypeError("Class extends value "+String(o)+" is not a constructor or null");function i(){this.constructor=e}t(e,o),e.prototype=null===o?Object.create(o):(i.prototype=o.prototype,new i)}}()),we=function(t){function e(e,o,i,n){void 0===n&&(n=1e6);var r=t.call(this,e,o)||this;void 0===i&&(i=e.position.distanceTo(o.position)),r.distance=i;var s=r.distanceEquation=new Zt(e,o);return r.equations.push(s),s.minForce=-n,s.maxForce=n,r}return me(e,t),e.prototype.update=function(){var t=this.bodyA,e=this.bodyB,o=this.distanceEquation,i=.5*this.distance,n=o.ni;e.position.vsub(t.position,n),n.normalize(),n.scale(i,o.ri),n.scale(-i,o.rj)},e}(Wt),ge=function(){var t=function(e,o){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])},t(e,o)};return function(e,o){if("function"!=typeof o&&null!==o)throw new TypeError("Class extends value "+String(o)+" is not a constructor or null");function i(){this.constructor=e}t(e,o),e.prototype=null===o?Object.create(o):(i.prototype=o.prototype,new i)}}(),be=function(t){function e(e,o,i){void 0===i&&(i={});var n=this,r=void 0!==i.maxForce?i.maxForce:1e6,a=new s,l=new s,c=new s;e.position.vadd(o.position,c),c.scale(.5,c),o.pointToLocalFrame(c,l),e.pointToLocalFrame(c,a),(n=t.call(this,e,a,o,l,r)||this).xA=e.vectorToLocalFrame(s.UNIT_X),n.xB=o.vectorToLocalFrame(s.UNIT_X),n.yA=e.vectorToLocalFrame(s.UNIT_Y),n.yB=o.vectorToLocalFrame(s.UNIT_Y),n.zA=e.vectorToLocalFrame(s.UNIT_Z),n.zB=o.vectorToLocalFrame(s.UNIT_Z);var u=n.rotationalEquation1=new pe(e,o,i),h=n.rotationalEquation2=new pe(e,o,i),p=n.rotationalEquation3=new pe(e,o,i);return n.equations.push(u,h,p),n}return ge(e,t),e.prototype.update=function(){var e=this.bodyA,o=this.bodyB,i=(this.motorEquation,this.rotationalEquation1),n=this.rotationalEquation2,r=this.rotationalEquation3;t.prototype.update.call(this),e.vectorToWorldFrame(this.xA,i.axisA),o.vectorToWorldFrame(this.yB,i.axisB),e.vectorToWorldFrame(this.yA,n.axisA),o.vectorToWorldFrame(this.zB,n.axisB),e.vectorToWorldFrame(this.zA,r.axisA),o.vectorToWorldFrame(this.xB,r.axisB)},e}(se),xe=(new s,new s,function(){var t=function(e,o){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])},t(e,o)};return function(e,o){if("function"!=typeof o&&null!==o)throw new TypeError("Class extends value "+String(o)+" is not a constructor or null");function i(){this.constructor=e}t(e,o),e.prototype=null===o?Object.create(o):(i.prototype=o.prototype,new i)}}()),Ae=function(t){function e(e,o,i){void 0===i&&(i=1e6);var n=t.call(this,e,o,-i,i)||this;return n.axisA=new s,n.axisB=new s,n.targetVelocity=0,n}return xe(e,t),e.prototype.computeB=function(t){this.a;var e=this.b,o=(this.bi,this.bj,this.axisA),i=this.axisB,n=this.jacobianElementA,r=this.jacobianElementB;return n.rotational.copy(o),i.negate(r.rotational),-(this.computeGW()-this.targetVelocity)*e-t*this.computeGiMf()},e}(kt),Be=function(){var t=function(e,o){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])},t(e,o)};return function(e,o){if("function"!=typeof o&&null!==o)throw new TypeError("Class extends value "+String(o)+" is not a constructor or null");function i(){this.constructor=e}t(e,o),e.prototype=null===o?Object.create(o):(i.prototype=o.prototype,new i)}}(),Ee=function(t){function e(e,o,i){void 0===i&&(i={});var n=this,r=void 0!==i.maxForce?i.maxForce:1e6,a=i.pivotA?i.pivotA.clone():new s,l=i.pivotB?i.pivotB.clone():new s;((n=t.call(this,e,a,o,l,r)||this).axisA=i.axisA?i.axisA.clone():new s(1,0,0)).normalize(),(n.axisB=i.axisB?i.axisB.clone():new s(1,0,0)).normalize(),n.collideConnected=!!i.collideConnected;var c=n.rotationalEquation1=new pe(e,o,i),u=n.rotationalEquation2=new pe(e,o,i),h=n.motorEquation=new Ae(e,o,r);return h.enabled=!1,n.equations.push(c,u,h),n}return Be(e,t),e.prototype.enableMotor=function(){this.motorEquation.enabled=!0},e.prototype.disableMotor=function(){this.motorEquation.enabled=!1},e.prototype.setMotorSpeed=function(t){this.motorEquation.targetVelocity=t},e.prototype.setMotorMaxForce=function(t){this.motorEquation.maxForce=t,this.motorEquation.minForce=-t},e.prototype.update=function(){var e=this.bodyA,o=this.bodyB,i=this.motorEquation,n=this.rotationalEquation1,r=this.rotationalEquation2,s=Se,a=Ce,l=this.axisA,c=this.axisB;t.prototype.update.call(this),e.quaternion.vmult(l,s),o.quaternion.vmult(c,a),s.tangents(n.axisA,r.axisA),n.axisB.copy(a),r.axisB.copy(a),this.motorEquation.enabled&&(e.quaternion.vmult(this.axisA,i.axisA),o.quaternion.vmult(this.axisB,i.axisB))},e}(se),Se=new s,Ce=new s,ze=function(){var t=function(e,o){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])},t(e,o)};return function(e,o){if("function"!=typeof o&&null!==o)throw new TypeError("Class extends value "+String(o)+" is not a constructor or null");function i(){this.constructor=e}t(e,o),e.prototype=null===o?Object.create(o):(i.prototype=o.prototype,new i)}}(),Pe=function(t){function e(e,o,i){var n=t.call(this,e,o,-i,i)||this;return n.ri=new s,n.rj=new s,n.t=new s,n}return ze(e,t),e.prototype.computeB=function(t){this.a;var e=this.b,o=(this.bi,this.bj,this.ri),i=this.rj,n=Me,r=Te,s=this.t;o.cross(s,n),i.cross(s,r);var a=this.jacobianElementA,l=this.jacobianElementB;return s.negate(a.spatial),n.negate(a.rotational),l.spatial.copy(s),l.rotational.copy(r),-this.computeGW()*e-t*this.computeGiMf()},e}(kt),Me=new s,Te=new s,Fe=function(){function t(e,o,i){i=Lt.defaults(i,{friction:.3,restitution:.3,contactEquationStiffness:1e7,contactEquationRelaxation:3,frictionEquationStiffness:1e7,frictionEquationRelaxation:3}),this.id=t.idCounter++,this.materials=[e,o],this.friction=i.friction,this.restitution=i.restitution,this.contactEquationStiffness=i.contactEquationStiffness,this.contactEquationRelaxation=i.contactEquationRelaxation,this.frictionEquationStiffness=i.frictionEquationStiffness,this.frictionEquationRelaxation=i.frictionEquationRelaxation}return t.idCounter=0,t}(),_e=function(){function t(e){void 0===e&&(e={});var o="";"string"==typeof e&&(o=e,e={}),this.name=o,this.id=t.idCounter++,this.friction=void 0!==e.friction?e.friction:-1,this.restitution=void 0!==e.restitution?e.restitution:-1}return t.idCounter=0,t}(),Oe=function(){function t(t,e,o){void 0===o&&(o={}),this.restLength="number"==typeof o.restLength?o.restLength:1,this.stiffness=o.stiffness||100,this.damping=o.damping||1,this.bodyA=t,this.bodyB=e,this.localAnchorA=new s,this.localAnchorB=new s,o.localAnchorA&&this.localAnchorA.copy(o.localAnchorA),o.localAnchorB&&this.localAnchorB.copy(o.localAnchorB),o.worldAnchorA&&this.setWorldAnchorA(o.worldAnchorA),o.worldAnchorB&&this.setWorldAnchorB(o.worldAnchorB)}return t.prototype.setWorldAnchorA=function(t){this.bodyA.pointToLocalFrame(t,this.localAnchorA)},t.prototype.setWorldAnchorB=function(t){this.bodyB.pointToLocalFrame(t,this.localAnchorB)},t.prototype.getWorldAnchorA=function(t){this.bodyA.pointToWorldFrame(this.localAnchorA,t)},t.prototype.getWorldAnchorB=function(t){this.bodyB.pointToWorldFrame(this.localAnchorB,t)},t.prototype.applyForce=function(){var t=this.stiffness,e=this.damping,o=this.restLength,i=this.bodyA,n=this.bodyB,r=Re,s=Ie,a=je,l=qe,c=De,u=Ne,h=Le,p=We,d=Ve,v=ke,f=He;this.getWorldAnchorA(u),this.getWorldAnchorB(h),u.vsub(i.position,p),h.vsub(n.position,d),h.vsub(u,r);var y=r.length();s.copy(r),s.normalize(),n.velocity.vsub(i.velocity,a),n.angularVelocity.cross(d,c),a.vadd(c,a),i.angularVelocity.cross(p,c),a.vsub(c,a),s.scale(-t*(y-o)-e*a.dot(s),l),i.force.vsub(l,i.force),n.force.vadd(l,n.force),p.cross(l,v),d.cross(l,f),i.torque.vsub(v,i.torque),n.torque.vadd(f,n.torque)},t}(),Re=new s,Ie=new s,je=new s,qe=new s,Ne=new s,Le=new s,We=new s,Ve=new s,ke=new s,He=new s,De=new s,Ue=function(){function t(t){void 0===t&&(t={}),t=Lt.defaults(t,{chassisConnectionPointLocal:new s,chassisConnectionPointWorld:new s,directionLocal:new s,directionWorld:new s,axleLocal:new s,axleWorld:new s,suspensionRestLength:1,suspensionMaxLength:2,radius:1,suspensionStiffness:100,dampingCompression:10,dampingRelaxation:10,frictionSlip:10.5,forwardAcceleration:1,sideAcceleration:1,steering:0,rotation:0,deltaRotation:0,rollInfluence:.01,maxSuspensionForce:Number.MAX_VALUE,isFrontWheel:!0,clippedInvContactDotSuspension:1,suspensionRelativeVelocity:0,suspensionForce:0,slipInfo:0,skidInfo:0,suspensionLength:0,maxSuspensionTravel:1,useCustomSlidingRotationalSpeed:!1,customSlidingRotationalSpeed:-.1}),this.maxSuspensionTravel=t.maxSuspensionTravel,this.customSlidingRotationalSpeed=t.customSlidingRotationalSpeed,this.useCustomSlidingRotationalSpeed=t.useCustomSlidingRotationalSpeed,this.sliding=!1,this.chassisConnectionPointLocal=t.chassisConnectionPointLocal.clone(),this.chassisConnectionPointWorld=t.chassisConnectionPointWorld.clone(),this.directionLocal=t.directionLocal.clone(),this.directionWorld=t.directionWorld.clone(),this.axleLocal=t.axleLocal.clone(),this.axleWorld=t.axleWorld.clone(),this.suspensionRestLength=t.suspensionRestLength,this.suspensionMaxLength=t.suspensionMaxLength,this.radius=t.radius,this.suspensionStiffness=t.suspensionStiffness,this.dampingCompression=t.dampingCompression,this.dampingRelaxation=t.dampingRelaxation,this.frictionSlip=t.frictionSlip,this.forwardAcceleration=t.forwardAcceleration,this.sideAcceleration=t.sideAcceleration,this.steering=0,this.rotation=0,this.deltaRotation=0,this.rollInfluence=t.rollInfluence,this.maxSuspensionForce=t.maxSuspensionForce,this.engineForce=0,this.brake=0,this.isFrontWheel=t.isFrontWheel,this.clippedInvContactDotSuspension=1,this.suspensionRelativeVelocity=0,this.suspensionForce=0,this.slipInfo=0,this.skidInfo=0,this.suspensionLength=0,this.sideImpulse=0,this.forwardImpulse=0,this.raycastResult=new st,this.worldTransform=new x,this.isInContact=!1}return t.prototype.updateWheel=function(t){var e=this.raycastResult;if(this.isInContact){var o=e.hitNormalWorld.dot(e.directionWorld);e.hitPointWorld.vsub(t.position,Ye),t.getVelocityAtWorldPoint(Ye,Ge);var i=e.hitNormalWorld.dot(Ge);if(o>=-.1)this.suspensionRelativeVelocity=0,this.clippedInvContactDotSuspension=10;else{var n=-1/o;this.suspensionRelativeVelocity=i*n,this.clippedInvContactDotSuspension=n}}else e.suspensionLength=this.suspensionRestLength,this.suspensionRelativeVelocity=0,e.directionWorld.scale(-1,e.hitNormalWorld),this.clippedInvContactDotSuspension=1},t}(),Ge=new s,Ye=new s,Xe=function(){function t(t){this.chassisBody=t.chassisBody,this.wheelInfos=[],this.sliding=!1,this.world=null,this.indexRightAxis=void 0!==t.indexRightAxis?t.indexRightAxis:2,this.indexForwardAxis=void 0!==t.indexForwardAxis?t.indexForwardAxis:0,this.indexUpAxis=void 0!==t.indexUpAxis?t.indexUpAxis:1,this.constraints=[],this.preStepCallback=function(){},this.currentVehicleSpeedKmHour=0,this.numWheelsOnGround=0}return t.prototype.addWheel=function(t){void 0===t&&(t={});var e=new Ue(t),o=this.wheelInfos.length;return this.wheelInfos.push(e),o},t.prototype.setSteeringValue=function(t,e){this.wheelInfos[e].steering=t},t.prototype.applyEngineForce=function(t,e){this.wheelInfos[e].engineForce=t},t.prototype.setBrake=function(t,e){this.wheelInfos[e].brake=t},t.prototype.addToWorld=function(t){t.addBody(this.chassisBody);var e=this;this.preStepCallback=function(){e.updateVehicle(t.dt)},t.addEventListener("preStep",this.preStepCallback),this.world=t},t.prototype.getVehicleAxisWorld=function(t,e){e.set(0===t?1:0,1===t?1:0,2===t?1:0),this.chassisBody.vectorToWorldFrame(e,e)},t.prototype.updateVehicle=function(t){for(var e=this.wheelInfos,o=e.length,i=this.chassisBody,n=0;n<o;n++)this.updateWheelTransform(n);this.currentVehicleSpeedKmHour=3.6*i.velocity.length();var r=new s;this.getVehicleAxisWorld(this.indexForwardAxis,r),r.dot(i.velocity)<0&&(this.currentVehicleSpeedKmHour*=-1);for(n=0;n<o;n++)this.castRay(e[n]);this.updateSuspension(t);var a=new s,l=new s;for(n=0;n<o;n++){var c=(d=e[n]).suspensionForce;c>d.maxSuspensionForce&&(c=d.maxSuspensionForce),d.raycastResult.hitNormalWorld.scale(c*t,a),d.raycastResult.hitPointWorld.vsub(i.position,l),i.applyImpulse(a,l)}this.updateFriction(t);var u=new s,h=new s,p=new s;for(n=0;n<o;n++){var d=e[n];i.getVelocityAtWorldPoint(d.chassisConnectionPointWorld,p);var v=1;if(1===this.indexUpAxis)v=-1;if(d.isInContact){this.getVehicleAxisWorld(this.indexForwardAxis,h);var f=h.dot(d.raycastResult.hitNormalWorld);d.raycastResult.hitNormalWorld.scale(f,u),h.vsub(u,h);var y=h.dot(p);d.deltaRotation=v*y*t/d.radius}!d.sliding&&d.isInContact||0===d.engineForce||!d.useCustomSlidingRotationalSpeed||(d.deltaRotation=(d.engineForce>0?1:-1)*d.customSlidingRotationalSpeed*t),Math.abs(d.brake)>Math.abs(d.engineForce)&&(d.deltaRotation=0),d.rotation+=d.deltaRotation,d.deltaRotation*=.99}},t.prototype.updateSuspension=function(t){for(var e=this.chassisBody.mass,o=this.wheelInfos,i=o.length,n=0;n<i;n++){var r=o[n];if(r.isInContact){var s=void 0,a=r.suspensionRestLength-r.suspensionLength;s=r.suspensionStiffness*a*r.clippedInvContactDotSuspension;var l=r.suspensionRelativeVelocity;s-=(l<0?r.dampingCompression:r.dampingRelaxation)*l,r.suspensionForce=s*e,r.suspensionForce<0&&(r.suspensionForce=0)}else r.suspensionForce=0}},t.prototype.removeFromWorld=function(t){this.constraints;t.removeBody(this.chassisBody),t.removeEventListener("preStep",this.preStepCallback),this.world=null},t.prototype.castRay=function(t){var e=Je,o=$e;this.updateWheelTransformWorld(t);var i=this.chassisBody,n=-1,r=t.suspensionRestLength+t.radius;t.directionWorld.scale(r,e);var a=t.chassisConnectionPointWorld;a.vadd(e,o);var l=t.raycastResult;l.reset();var c=i.collisionResponse;i.collisionResponse=!1,this.world.rayTest(a,o,l),i.collisionResponse=c;var u=l.body;if(t.raycastResult.groundObject=0,u){n=l.distance,t.raycastResult.hitNormalWorld=l.hitNormalWorld,t.isInContact=!0;var h=l.distance;t.suspensionLength=h-t.radius;var p=t.suspensionRestLength-t.maxSuspensionTravel,d=t.suspensionRestLength+t.maxSuspensionTravel;t.suspensionLength<p&&(t.suspensionLength=p),t.suspensionLength>d&&(t.suspensionLength=d,t.raycastResult.reset());var v=t.raycastResult.hitNormalWorld.dot(t.directionWorld),f=new s;i.getVelocityAtWorldPoint(t.raycastResult.hitPointWorld,f);var y=t.raycastResult.hitNormalWorld.dot(f);if(v>=-.1)t.suspensionRelativeVelocity=0,t.clippedInvContactDotSuspension=10;else{var m=-1/v;t.suspensionRelativeVelocity=y*m,t.clippedInvContactDotSuspension=m}}else t.suspensionLength=t.suspensionRestLength+0*t.maxSuspensionTravel,t.suspensionRelativeVelocity=0,t.directionWorld.scale(-1,t.raycastResult.hitNormalWorld),t.clippedInvContactDotSuspension=1;return n},t.prototype.updateWheelTransformWorld=function(t){t.isInContact=!1;var e=this.chassisBody;e.pointToWorldFrame(t.chassisConnectionPointLocal,t.chassisConnectionPointWorld),e.vectorToWorldFrame(t.directionLocal,t.directionWorld),e.vectorToWorldFrame(t.axleLocal,t.axleWorld)},t.prototype.updateWheelTransform=function(t){var e=Ke,o=Ze,i=Qe,n=this.wheelInfos[t];this.updateWheelTransformWorld(n),n.directionLocal.scale(-1,e),o.copy(n.axleLocal),e.cross(o,i),i.normalize(),o.normalize();var r=n.steering,s=new y;s.setFromAxisAngle(e,r);var a=new y;a.setFromAxisAngle(o,n.rotation);var l=n.worldTransform.quaternion;this.chassisBody.quaternion.mult(s,l),l.mult(a,l),l.normalize();var c=n.worldTransform.position;c.copy(n.directionWorld),c.scale(n.suspensionLength,c),c.vadd(n.chassisConnectionPointWorld,c)},t.prototype.getWheelTransformWorld=function(t){return this.wheelInfos[t].worldTransform},t.prototype.updateFriction=function(t){var e=eo,o=this.wheelInfos,i=o.length,n=this.chassisBody,r=io,a=oo;this.numWheelsOnGround=0;for(var l=0;l<i;l++){(p=(x=o[l]).raycastResult.body)&&this.numWheelsOnGround++,x.sideImpulse=0,x.forwardImpulse=0,r[l]||(r[l]=new s),a[l]||(a[l]=new s)}for(l=0;l<i;l++){if(p=(x=o[l]).raycastResult.body){var c=a[l];this.getWheelTransformWorld(l).vectorToWorldFrame(to[this.indexRightAxis],c);var u=x.raycastResult.hitNormalWorld,h=c.dot(u);u.scale(h,e),c.vsub(e,c),c.normalize(),u.cross(c,r[l]),r[l].normalize(),x.sideImpulse=wo(n,x.raycastResult.hitPointWorld,p,x.raycastResult.hitPointWorld,c),x.sideImpulse*=no}}this.sliding=!1;for(l=0;l<i;l++){var p=(x=o[l]).raycastResult.body,d=0;if(x.slipInfo=1,p){var v=x.brake?x.brake:0;d=lo(n,p,x.raycastResult.hitPointWorld,r[l],v);var f=v/(d+=x.engineForce*t);x.slipInfo*=f}if(x.forwardImpulse=0,x.skidInfo=1,p){x.skidInfo=1;var y=x.suspensionForce*t*x.frictionSlip,m=y*y;x.forwardImpulse=d;var w=.5*x.forwardImpulse/x.forwardAcceleration,g=1*x.sideImpulse/x.sideAcceleration,b=w*w+g*g;if(x.sliding=!1,b>m){this.sliding=!0,x.sliding=!0;f=y/Math.sqrt(b);x.skidInfo*=f}}}if(this.sliding)for(l=0;l<i;l++){0!==(x=o[l]).sideImpulse&&x.skidInfo<1&&(x.forwardImpulse*=x.skidInfo,x.sideImpulse*=x.skidInfo)}for(l=0;l<i;l++){var x=o[l],A=new s;if(x.raycastResult.hitPointWorld.vsub(n.position,A),0!==x.forwardImpulse){var B=new s;r[l].scale(x.forwardImpulse,B),n.applyImpulse(B,A)}if(0!==x.sideImpulse){p=x.raycastResult.body;var E=new s;x.raycastResult.hitPointWorld.vsub(p.position,E);var S=new s;a[l].scale(x.sideImpulse,S),n.vectorToLocalFrame(A,A),A["xyz"[this.indexUpAxis]]*=x.rollInfluence,n.vectorToWorldFrame(A,A),n.applyImpulse(S,A),S.scale(-1,S),p.applyImpulse(S,E)}}},t}(),Ke=(new s,new s,new s,new s),Ze=new s,Qe=new s,Je=(new lt,new s,new s),$e=new s,to=[new s(1,0,0),new s(0,1,0),new s(0,0,1)],eo=new s,oo=[],io=[],no=1,ro=new s,so=new s,ao=new s;function lo(t,e,o,i,n){var r=0,s=o,a=ro,l=so,c=ao;t.getVelocityAtWorldPoint(s,a),e.getVelocityAtWorldPoint(s,l),a.vsub(l,c);return n<(r=-i.dot(c)*(1/(vo(t,o,i)+vo(e,o,i))))&&(r=n),r<-n&&(r=-n),r}var co=new s,uo=new s,ho=new s,po=new s;function vo(t,e,o){var i=co,n=uo,r=ho,s=po;return e.vsub(t.position,i),i.cross(o,n),t.invInertiaWorld.vmult(n,s),s.cross(i,r),t.invMass+o.dot(r)}var fo=new s,yo=new s,mo=new s;function wo(t,e,o,i,n){if(n.lengthSquared()>1.1)return 0;var r=fo,s=yo,a=mo;t.getVelocityAtWorldPoint(e,r),o.getVelocityAtWorldPoint(i,s),r.vsub(s,a);return-.2*n.dot(a)*(1/(t.invMass+o.invMass))}var go=function(){var t=function(e,o){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])},t(e,o)};return function(e,o){if("function"!=typeof o&&null!==o)throw new TypeError("Class extends value "+String(o)+" is not a constructor or null");function i(){this.constructor=e}t(e,o),e.prototype=null===o?Object.create(o):(i.prototype=o.prototype,new i)}}(),bo=function(t){function e(e){var o=t.call(this,{type:b.types.SPHERE})||this;if(o.radius=void 0!==e?e:1,o.radius<0)throw new Error("The sphere radius cannot be negative.");return o.updateBoundingSphereRadius(),o}return go(e,t),e.prototype.calculateLocalInertia=function(t,e){void 0===e&&(e=new s);var o=2*t*this.radius*this.radius/5;return e.x=o,e.y=o,e.z=o,e},e.prototype.volume=function(){return 4*Math.PI*Math.pow(this.radius,3)/3},e.prototype.updateBoundingSphereRadius=function(){this.boundingSphereRadius=this.radius},e.prototype.calculateWorldAABB=function(t,e,o,i){for(var n=this.radius,r=["x","y","z"],s=0;s<r.length;s++){var a=r[s];o[a]=t[a]-n,i[a]=t[a]+n}},e}(b),xo=function(){function t(t){void 0===t&&(t={}),this.wheelBodies=[],this.coordinateSystem=void 0!==t.coordinateSystem?t.coordinateSystem.clone():new s(1,2,3),t.chassisBody?this.chassisBody=t.chassisBody:this.chassisBody=new j({mass:1,shape:new T(new s(5,.5,2))}),this.constraints=[],this.wheelAxes=[],this.wheelForces=[]}return t.prototype.addWheel=function(t){var e;void 0===t&&(t={}),e=t.body?t.body:new j({mass:1,shape:new bo(1.2)}),this.wheelBodies.push(e),this.wheelForces.push(0);var o=void 0!==t.position?t.position.clone():new s,i=new s;this.chassisBody.pointToWorldFrame(o,i),e.position.set(i.x,i.y,i.z);var n=void 0!==t.axis?t.axis.clone():new s(0,0,1);this.wheelAxes.push(n);var r=new Ee(this.chassisBody,e,{pivotA:o,axisA:n,pivotB:s.ZERO,axisB:n,collideConnected:!1});return this.constraints.push(r),this.wheelBodies.length-1},t.prototype.setSteeringValue=function(t,e){var o=this.wheelAxes[e],i=Math.cos(t),n=Math.sin(t),r=o.x,s=o.z;this.constraints[e].axisA.set(-i*r+n*s,0,n*r+i*s)},t.prototype.setMotorSpeed=function(t,e){var o=this.constraints[e];o.enableMotor(),o.motorTargetVelocity=t},t.prototype.disableMotor=function(t){this.constraints[t].disableMotor()},t.prototype.setWheelForce=function(t,e){this.wheelForces[e]=t},t.prototype.applyWheelForce=function(t,e){var o=this.wheelAxes[e],i=this.wheelBodies[e],n=i.torque;o.scale(t,Ao),i.vectorToWorldFrame(Ao,Ao),n.vadd(Ao,n)},t.prototype.addToWorld=function(t){for(var e=this.constraints,o=this.wheelBodies.concat([this.chassisBody]),i=0;i<o.length;i++)t.addBody(o[i]);for(i=0;i<e.length;i++)t.addConstraint(e[i]);t.addEventListener("preStep",this._update.bind(this))},t.prototype._update=function(){for(var t=this.wheelForces,e=0;e<t.length;e++)this.applyWheelForce(t[e],e)},t.prototype.removeFromWorld=function(t){for(var e=this.constraints,o=this.wheelBodies.concat([this.chassisBody]),i=0;i<o.length;i++)t.removeBody(o[i]);for(i=0;i<e.length;i++)t.removeConstraint(e[i])},t.prototype.getWheelSpeed=function(t){var e=this.wheelAxes[t],o=this.wheelBodies[t].angularVelocity;return this.chassisBody.vectorToWorldFrame(e,Bo),o.dot(Bo)},t}(),Ao=new s,Bo=new s,Eo=function(){function t(){this.particles=[],this.density=1,this.smoothingRadius=1,this.speedOfSound=1,this.viscosity=.01,this.eps=1e-6,this.pressures=[],this.densities=[],this.neighbors=[]}return t.prototype.add=function(t){this.particles.push(t),this.neighbors.length<this.particles.length&&this.neighbors.push([])},t.prototype.remove=function(t){var e=this.particles.indexOf(t);-1!==e&&(this.particles.splice(e,1),this.neighbors.length>this.particles.length&&this.neighbors.pop())},t.prototype.getNeighbors=function(t,e){for(var o=this.particles.length,i=t.id,n=this.smoothingRadius*this.smoothingRadius,r=So,s=0;s!==o;s++){var a=this.particles[s];a.position.vsub(t.position,r),i!==a.id&&r.lengthSquared()<n&&e.push(a)}},t.prototype.update=function(){for(var t=this.particles.length,e=Co,o=this.speedOfSound,i=this.eps,n=0;n!==t;n++){var r=this.particles[n];(m=this.neighbors[n]).length=0,this.getNeighbors(r,m),m.push(this.particles[n]);for(var s=m.length,a=0,l=0;l!==s;l++){r.position.vsub(m[l].position,e);var c=e.length(),u=this.w(c);a+=m[l].mass*u}this.densities[n]=a,this.pressures[n]=o*o*(this.densities[n]-this.density)}var h=zo,p=Po,d=Mo,v=To,f=Fo;for(n=0;n!==t;n++){var y=this.particles[n];h.set(0,0,0),p.set(0,0,0);var m,w=void 0,g=void 0;for(s=(m=this.neighbors[n]).length,l=0;l!==s;l++){var b=m[l];y.position.vsub(b.position,v);var x=v.length();w=-b.mass*(this.pressures[n]/(this.densities[n]*this.densities[n]+i)+this.pressures[l]/(this.densities[l]*this.densities[l]+i)),this.gradw(v,d),d.scale(w,d),h.vadd(d,h),b.velocity.vsub(y.velocity,f),f.scale(1/(1e-4+this.densities[n]*this.densities[l])*this.viscosity*b.mass,f),g=this.nablaw(x),f.scale(g,f),p.vadd(f,p)}p.scale(y.mass,p),h.scale(y.mass,h),y.force.vadd(p,y.force),y.force.vadd(h,y.force)}},t.prototype.w=function(t){var e=this.smoothingRadius;return 315/(64*Math.PI*Math.pow(e,9))*Math.pow(e*e-t*t,3)},t.prototype.gradw=function(t,e){var o=t.length(),i=this.smoothingRadius;t.scale(945/(32*Math.PI*Math.pow(i,9))*Math.pow(i*i-o*o,2),e)},t.prototype.nablaw=function(t){var e=this.smoothingRadius;return 945/(32*Math.PI*Math.pow(e,9))*(e*e-t*t)*(7*t*t-3*e*e)},t}(),So=new s,Co=new s,zo=new s,Po=new s,Mo=new s,To=new s,Fo=new s,_o=function(){var t=function(e,o){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])},t(e,o)};return function(e,o){if("function"!=typeof o&&null!==o)throw new TypeError("Class extends value "+String(o)+" is not a constructor or null");function i(){this.constructor=e}t(e,o),e.prototype=null===o?Object.create(o):(i.prototype=o.prototype,new i)}}(),Oo=function(t){function e(e,o,i,n){void 0===e&&(e=1),void 0===o&&(o=1),void 0===i&&(i=1),void 0===n&&(n=8);var r=this;if(e<0)throw new Error("The cylinder radiusTop cannot be negative.");if(o<0)throw new Error("The cylinder radiusBottom cannot be negative.");var a=n,l=[],c=[],u=[],h=[],p=[],d=Math.cos,v=Math.sin;l.push(new s(-o*v(0),.5*-i,o*d(0))),h.push(0),l.push(new s(-e*v(0),.5*i,e*d(0))),p.push(1);for(var f=0;f<a;f++){var y=2*Math.PI/a*(f+1),m=2*Math.PI/a*(f+.5);f<a-1?(l.push(new s(-o*v(y),.5*-i,o*d(y))),h.push(2*f+2),l.push(new s(-e*v(y),.5*i,e*d(y))),p.push(2*f+3),u.push([2*f,2*f+1,2*f+3,2*f+2])):u.push([2*f,2*f+1,1,0]),(a%2==1||f<a/2)&&c.push(new s(-v(m),0,d(m)))}u.push(h),c.push(new s(0,1,0));var w=[];for(f=0;f<p.length;f++)w.push(p[p.length-f-1]);return u.push(w),(r=t.call(this,{vertices:l,faces:u,axes:c})||this).type=b.types.CYLINDER,r.radiusTop=e,r.radiusBottom=o,r.height=i,r.numSegments=n,r}return _o(e,t),e}(E),Ro=function(){var t=function(e,o){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])},t(e,o)};return function(e,o){if("function"!=typeof o&&null!==o)throw new TypeError("Class extends value "+String(o)+" is not a constructor or null");function i(){this.constructor=e}t(e,o),e.prototype=null===o?Object.create(o):(i.prototype=o.prototype,new i)}}(),Io=function(t){function e(){return t.call(this,{type:b.types.PARTICLE})||this}return Ro(e,t),e.prototype.calculateLocalInertia=function(t,e){return void 0===e&&(e=new s),e.set(0,0,0),e},e.prototype.volume=function(){return 0},e.prototype.updateBoundingSphereRadius=function(){this.boundingSphereRadius=0},e.prototype.calculateWorldAABB=function(t,e,o,i){o.copy(t),i.copy(t)},e}(b),jo=function(){var t=function(e,o){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])},t(e,o)};return function(e,o){if("function"!=typeof o&&null!==o)throw new TypeError("Class extends value "+String(o)+" is not a constructor or null");function i(){this.constructor=e}t(e,o),e.prototype=null===o?Object.create(o):(i.prototype=o.prototype,new i)}}(),qo=function(t){function e(){var e=t.call(this,{type:b.types.PLANE})||this;return e.worldNormal=new s,e.worldNormalNeedsUpdate=!0,e.boundingSphereRadius=Number.MAX_VALUE,e}return jo(e,t),e.prototype.computeWorldNormal=function(t){var e=this.worldNormal;e.set(0,0,1),t.vmult(e,e),this.worldNormalNeedsUpdate=!1},e.prototype.calculateLocalInertia=function(t,e){return void 0===e&&(e=new s),e},e.prototype.volume=function(){return Number.MAX_VALUE},e.prototype.calculateWorldAABB=function(t,e,o,i){No.set(0,0,1),e.vmult(No,No);var n=Number.MAX_VALUE;o.set(-n,-n,-n),i.set(n,n,n),1===No.x?i.x=t.x:-1===No.x&&(o.x=t.x),1===No.y?i.y=t.y:-1===No.y&&(o.y=t.y),1===No.z?i.z=t.z:-1===No.z&&(o.z=t.z)},e.prototype.updateBoundingSphereRadius=function(){this.boundingSphereRadius=Number.MAX_VALUE},e}(b),No=new s,Lo=function(){var t=function(e,o){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])},t(e,o)};return function(e,o){if("function"!=typeof o&&null!==o)throw new TypeError("Class extends value "+String(o)+" is not a constructor or null");function i(){this.constructor=e}t(e,o),e.prototype=null===o?Object.create(o):(i.prototype=o.prototype,new i)}}(),Wo=function(t){function e(e,o){void 0===o&&(o={});var i=this;return o=Lt.defaults(o,{maxValue:null,minValue:null,elementSize:1}),(i=t.call(this,{type:b.types.HEIGHTFIELD})||this).data=e,i.maxValue=o.maxValue,i.minValue=o.minValue,i.elementSize=o.elementSize,null===o.minValue&&i.updateMinValue(),null===o.maxValue&&i.updateMaxValue(),i.cacheEnabled=!0,i.pillarConvex=new E,i.pillarOffset=new s,i.updateBoundingSphereRadius(),i._cachedPillars={},i}return Lo(e,t),e.prototype.update=function(){this._cachedPillars={}},e.prototype.updateMinValue=function(){for(var t=this.data,e=t[0][0],o=0;o!==t.length;o++)for(var i=0;i!==t[o].length;i++){var n=t[o][i];n<e&&(e=n)}this.minValue=e},e.prototype.updateMaxValue=function(){for(var t=this.data,e=t[0][0],o=0;o!==t.length;o++)for(var i=0;i!==t[o].length;i++){var n=t[o][i];n>e&&(e=n)}this.maxValue=e},e.prototype.setHeightValueAtIndex=function(t,e,o){this.data[t][e]=o,this.clearCachedConvexTrianglePillar(t,e,!1),t>0&&(this.clearCachedConvexTrianglePillar(t-1,e,!0),this.clearCachedConvexTrianglePillar(t-1,e,!1)),e>0&&(this.clearCachedConvexTrianglePillar(t,e-1,!0),this.clearCachedConvexTrianglePillar(t,e-1,!1)),e>0&&t>0&&this.clearCachedConvexTrianglePillar(t-1,e-1,!0)},e.prototype.getRectMinMax=function(t,e,o,i,n){void 0===n&&(n=[]);for(var r=this.data,s=this.minValue,a=t;a<=o;a++)for(var l=e;l<=i;l++){var c=r[a][l];c>s&&(s=c)}n[0]=this.minValue,n[1]=s},e.prototype.getIndexOfPosition=function(t,e,o,i){var n=this.elementSize,r=this.data,s=Math.floor(t/n),a=Math.floor(e/n);return o[0]=s,o[1]=a,i&&(s<0&&(s=0),a<0&&(a=0),s>=r.length-1&&(s=r.length-1),a>=r[0].length-1&&(a=r[0].length-1)),!(s<0||a<0||s>=r.length-1||a>=r[0].length-1)},e.prototype.getTriangleAt=function(t,e,o,i,n,r){var s=Vo;this.getIndexOfPosition(t,e,s,o);var a=s[0],l=s[1],c=this.data;o&&(a=Math.min(c.length-2,Math.max(0,a)),l=Math.min(c[0].length-2,Math.max(0,l)));var u=this.elementSize,h=Math.pow(t/u-a,2)+Math.pow(e/u-l,2)>Math.pow(t/u-(a+1),2)+Math.pow(e/u-(l+1),2);return this.getTriangle(a,l,h,i,n,r),h},e.prototype.getNormalAt=function(t,e,o,i){var n=Go,r=Yo,s=Xo,a=Ko,l=Zo;this.getTriangleAt(t,e,o,n,r,s),r.vsub(n,a),s.vsub(n,l),a.cross(l,i),i.normalize()},e.prototype.getAabbAtIndex=function(t,e,o){var i=o.lowerBound,n=o.upperBound,r=this.data,s=this.elementSize;i.set(t*s,e*s,r[t][e]),n.set((t+1)*s,(e+1)*s,r[t+1][e+1])},e.prototype.getHeightAt=function(t,e,o){var i=this.data,n=Ho,r=Do,s=Uo,a=Vo;this.getIndexOfPosition(t,e,a,o);var l=a[0],c=a[1];o&&(l=Math.min(i.length-2,Math.max(0,l)),c=Math.min(i[0].length-2,Math.max(0,c)));var u=this.getTriangleAt(t,e,o,n,r,s);!function(t,e,o,i,n,r,s,a,l){l.x=((r-a)*(t-s)+(s-n)*(e-a))/((r-a)*(o-s)+(s-n)*(i-a)),l.y=((a-i)*(t-s)+(o-s)*(e-a))/((r-a)*(o-s)+(s-n)*(i-a)),l.z=1-l.x-l.y}(t,e,n.x,n.y,r.x,r.y,s.x,s.y,ko);var h=ko;return u?i[l+1][c+1]*h.x+i[l][c+1]*h.y+i[l+1][c]*h.z:i[l][c]*h.x+i[l+1][c]*h.y+i[l][c+1]*h.z},e.prototype.getCacheConvexTrianglePillarKey=function(t,e,o){return"".concat(t,"_").concat(e,"_").concat(o?1:0)},e.prototype.getCachedConvexTrianglePillar=function(t,e,o){return this._cachedPillars[this.getCacheConvexTrianglePillarKey(t,e,o)]},e.prototype.setCachedConvexTrianglePillar=function(t,e,o,i,n){this._cachedPillars[this.getCacheConvexTrianglePillarKey(t,e,o)]={convex:i,offset:n}},e.prototype.clearCachedConvexTrianglePillar=function(t,e,o){delete this._cachedPillars[this.getCacheConvexTrianglePillarKey(t,e,o)]},e.prototype.getTriangle=function(t,e,o,i,n,r){var s=this.data,a=this.elementSize;o?(i.set((t+1)*a,(e+1)*a,s[t+1][e+1]),n.set(t*a,(e+1)*a,s[t][e+1]),r.set((t+1)*a,e*a,s[t+1][e])):(i.set(t*a,e*a,s[t][e]),n.set((t+1)*a,e*a,s[t+1][e]),r.set(t*a,(e+1)*a,s[t][e+1]))},e.prototype.getConvexTrianglePillar=function(t,e,o){var i=this.pillarConvex,n=this.pillarOffset;if(this.cacheEnabled){var r=this.getCachedConvexTrianglePillar(t,e,o);if(r)return this.pillarConvex=r.convex,void(this.pillarOffset=r.offset);i=new E,n=new s,this.pillarConvex=i,this.pillarOffset=n}var a=this.data,l=this.elementSize,c=i.faces;i.vertices.length=6;for(var u=0;u<6;u++)i.vertices[u]||(i.vertices[u]=new s);c.length=5;for(u=0;u<5;u++)c[u]||(c[u]=[]);var h=i.vertices,p=(Math.min(a[t][e],a[t+1][e],a[t][e+1],a[t+1][e+1])-this.minValue)/2+this.minValue;o?(n.set((t+.75)*l,(e+.75)*l,p),h[0].set(.25*l,.25*l,a[t+1][e+1]-p),h[1].set(-.75*l,.25*l,a[t][e+1]-p),h[2].set(.25*l,-.75*l,a[t+1][e]-p),h[3].set(.25*l,.25*l,-Math.abs(p)-1),h[4].set(-.75*l,.25*l,-Math.abs(p)-1),h[5].set(.25*l,-.75*l,-Math.abs(p)-1),c[0][0]=0,c[0][1]=1,c[0][2]=2,c[1][0]=5,c[1][1]=4,c[1][2]=3,c[2][0]=2,c[2][1]=5,c[2][2]=3,c[2][3]=0,c[3][0]=3,c[3][1]=4,c[3][2]=1,c[3][3]=0,c[4][0]=1,c[4][1]=4,c[4][2]=5,c[4][3]=2):(n.set((t+.25)*l,(e+.25)*l,p),h[0].set(-.25*l,-.25*l,a[t][e]-p),h[1].set(.75*l,-.25*l,a[t+1][e]-p),h[2].set(-.25*l,.75*l,a[t][e+1]-p),h[3].set(-.25*l,-.25*l,-Math.abs(p)-1),h[4].set(.75*l,-.25*l,-Math.abs(p)-1),h[5].set(-.25*l,.75*l,-Math.abs(p)-1),c[0][0]=0,c[0][1]=1,c[0][2]=2,c[1][0]=5,c[1][1]=4,c[1][2]=3,c[2][0]=0,c[2][1]=2,c[2][2]=5,c[2][3]=3,c[3][0]=1,c[3][1]=0,c[3][2]=3,c[3][3]=4,c[4][0]=4,c[4][1]=5,c[4][2]=2,c[4][3]=1),i.computeNormals(),i.computeEdges(),i.updateBoundingSphereRadius(),this.setCachedConvexTrianglePillar(t,e,o,i,n)},e.prototype.calculateLocalInertia=function(t,e){return void 0===e&&(e=new s),e.set(0,0,0),e},e.prototype.volume=function(){return Number.MAX_VALUE},e.prototype.calculateWorldAABB=function(t,e,o,i){o.set(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE),i.set(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE)},e.prototype.updateBoundingSphereRadius=function(){var t=this.data,e=this.elementSize;this.boundingSphereRadius=new s(t.length*e,t[0].length*e,Math.max(Math.abs(this.maxValue),Math.abs(this.minValue))).length()},e.prototype.setHeightsFromImage=function(t,e){var o=e.x,i=e.z,n=e.y,r=document.createElement("canvas");r.width=t.width,r.height=t.height;var s=r.getContext("2d");s.drawImage(t,0,0);var a=s.getImageData(0,0,t.width,t.height),l=this.data;l.length=0,this.elementSize=Math.abs(o)/a.width;for(var c=0;c<a.height;c++){for(var u=[],h=0;h<a.width;h++){var p=(a.data[4*(c*a.height+h)]+a.data[4*(c*a.height+h)+1]+a.data[4*(c*a.height+h)+2])/4/255*i;o<0?u.push(p):u.unshift(p)}n<0?l.unshift(u):l.push(u)}this.updateMaxValue(),this.updateMinValue(),this.update()},e}(b),Vo=[],ko=new s,Ho=new s,Do=new s,Uo=new s,Go=new s,Yo=new s,Xo=new s,Ko=new s,Zo=new s;var Qo=function(){var t=function(e,o){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])},t(e,o)};return function(e,o){if("function"!=typeof o&&null!==o)throw new TypeError("Class extends value "+String(o)+" is not a constructor or null");function i(){this.constructor=e}t(e,o),e.prototype=null===o?Object.create(o):(i.prototype=o.prototype,new i)}}(),Jo=function(){function t(t){void 0===t&&(t={}),this.root=t.root||null,this.aabb=t.aabb?t.aabb.clone():new h,this.data=[],this.children=[]}return t.prototype.reset=function(){this.children.length=this.data.length=0},t.prototype.insert=function(t,e,o){void 0===o&&(o=0);var i=this.data;if(!this.aabb.contains(t))return!1;var n=this.children;if(o<(this.maxDepth||this.root.maxDepth)){var r=!1;n.length||(this.subdivide(),r=!0);for(var s=0;8!==s;s++)if(n[s].insert(t,e,o+1))return!0;r&&(n.length=0)}return i.push(e),!0},t.prototype.subdivide=function(){var e=this.aabb,o=e.lowerBound,i=e.upperBound,n=this.children;n.push(new t({aabb:new h({lowerBound:new s(0,0,0)})}),new t({aabb:new h({lowerBound:new s(1,0,0)})}),new t({aabb:new h({lowerBound:new s(1,1,0)})}),new t({aabb:new h({lowerBound:new s(1,1,1)})}),new t({aabb:new h({lowerBound:new s(0,1,1)})}),new t({aabb:new h({lowerBound:new s(0,0,1)})}),new t({aabb:new h({lowerBound:new s(1,0,1)})}),new t({aabb:new h({lowerBound:new s(0,1,0)})})),i.vsub(o,ti),ti.scale(.5,ti);for(var r=this.root||this,a=0;8!==a;a++){var l=n[a];l.root=r;var c=l.aabb.lowerBound;c.x*=ti.x,c.y*=ti.y,c.z*=ti.z,c.vadd(o,c),c.vadd(ti,l.aabb.upperBound)}},t.prototype.aabbQuery=function(t,e){this.data,this.children;for(var o=[this];o.length;){var i=o.pop();i.aabb.overlaps(t)&&Array.prototype.push.apply(e,i.data),Array.prototype.push.apply(o,i.children)}return e},t.prototype.rayQuery=function(t,e,o){return t.getAABB(ei),ei.toLocalFrame(e,ei),this.aabbQuery(ei,o),o},t.prototype.removeEmptyNodes=function(){for(var t=this.children.length-1;t>=0;t--)this.children[t].removeEmptyNodes(),this.children[t].children.length||this.children[t].data.length||this.children.splice(t,1)},t}(),$o=function(t){function e(e,o){void 0===o&&(o={});var i=t.call(this,{root:null,aabb:e})||this;return i.maxDepth=void 0!==o.maxDepth?o.maxDepth:8,i}return Qo(e,t),e}(Jo),ti=new s,ei=new h,oi=function(){var t=function(e,o){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])},t(e,o)};return function(e,o){if("function"!=typeof o&&null!==o)throw new TypeError("Class extends value "+String(o)+" is not a constructor or null");function i(){this.constructor=e}t(e,o),e.prototype=null===o?Object.create(o):(i.prototype=o.prototype,new i)}}(),ii=function(t){function e(e,o){var i=t.call(this,{type:b.types.TRIMESH})||this;return i.vertices=new Float32Array(e),i.indices=new Int16Array(o),i.normals=new Float32Array(o.length),i.aabb=new h,i.edges=null,i.scale=new s(1,1,1),i.tree=new $o,i.updateEdges(),i.updateNormals(),i.updateAABB(),i.updateBoundingSphereRadius(),i.updateTree(),i}return oi(e,t),e.prototype.updateTree=function(){var t=this.tree;t.reset(),t.aabb.copy(this.aabb);var e=this.scale;t.aabb.lowerBound.x*=1/e.x,t.aabb.lowerBound.y*=1/e.y,t.aabb.lowerBound.z*=1/e.z,t.aabb.upperBound.x*=1/e.x,t.aabb.upperBound.y*=1/e.y,t.aabb.upperBound.z*=1/e.z;for(var o=new h,i=new s,n=new s,r=new s,a=[i,n,r],l=0;l<this.indices.length/3;l++){var c=3*l;this._getUnscaledVertex(this.indices[c],i),this._getUnscaledVertex(this.indices[c+1],n),this._getUnscaledVertex(this.indices[c+2],r),o.setFromPoints(a),t.insert(o,l)}t.removeEmptyNodes()},e.prototype.getTrianglesInAABB=function(t,e){ri.copy(t);var o=this.scale,i=o.x,n=o.y,r=o.z,s=ri.lowerBound,a=ri.upperBound;return s.x/=i,s.y/=n,s.z/=r,a.x/=i,a.y/=n,a.z/=r,this.tree.aabbQuery(ri,e)},e.prototype.setScale=function(t){var e=this.scale.x===this.scale.y&&this.scale.y===this.scale.z,o=t.x===t.y&&t.y===t.z;e&&o||this.updateNormals(),this.scale.copy(t),this.updateAABB(),this.updateBoundingSphereRadius()},e.prototype.updateNormals=function(){for(var t=ni,o=this.normals,i=0;i<this.indices.length/3;i++){var n=3*i,r=this.indices[n],s=this.indices[n+1],a=this.indices[n+2];this.getVertex(r,ui),this.getVertex(s,hi),this.getVertex(a,pi),e.computeNormal(hi,ui,pi,t),o[n]=t.x,o[n+1]=t.y,o[n+2]=t.z}},e.prototype.updateEdges=function(){for(var t={},e=function(e,o){var i=e<o?"".concat(e,"_").concat(o):"".concat(o,"_").concat(e);t[i]=!0},o=0;o<this.indices.length/3;o++){var i=3*o,n=this.indices[i],r=this.indices[i+1],s=this.indices[i+2];e(n,r),e(r,s),e(s,n)}var a=Object.keys(t);this.edges=new Int16Array(2*a.length);for(o=0;o<a.length;o++){var l=a[o].split("_");this.edges[2*o]=parseInt(l[0],10),this.edges[2*o+1]=parseInt(l[1],10)}},e.prototype.getEdgeVertex=function(t,e,o){var i=this.edges[2*t+(e?1:0)];this.getVertex(i,o)},e.prototype.getEdgeVector=function(t,e){var o=si,i=ai;this.getEdgeVertex(t,0,o),this.getEdgeVertex(t,1,i),i.vsub(o,e)},e.computeNormal=function(t,e,o,i){e.vsub(t,ci),o.vsub(e,li),li.cross(ci,i),i.isZero()||i.normalize()},e.prototype.getVertex=function(t,e){var o=this.scale;return this._getUnscaledVertex(t,e),e.x*=o.x,e.y*=o.y,e.z*=o.z,e},e.prototype._getUnscaledVertex=function(t,e){var o=3*t,i=this.vertices;return e.set(i[o],i[o+1],i[o+2])},e.prototype.getWorldVertex=function(t,e,o,i){return this.getVertex(t,i),x.pointToWorldFrame(e,o,i,i),i},e.prototype.getTriangleVertices=function(t,e,o,i){var n=3*t;this.getVertex(this.indices[n],e),this.getVertex(this.indices[n+1],o),this.getVertex(this.indices[n+2],i)},e.prototype.getNormal=function(t,e){var o=3*t;return e.set(this.normals[o],this.normals[o+1],this.normals[o+2])},e.prototype.calculateLocalInertia=function(t,e){this.computeLocalAABB(di);var o=di.upperBound.x-di.lowerBound.x,i=di.upperBound.y-di.lowerBound.y,n=di.upperBound.z-di.lowerBound.z;return e.set(1/12*t*(2*i*2*i+2*n*2*n),1/12*t*(2*o*2*o+2*n*2*n),1/12*t*(2*i*2*i+2*o*2*o))},e.prototype.computeLocalAABB=function(t){var e=t.lowerBound,o=t.upperBound,i=this.vertices.length,n=(this.vertices,vi);this.getVertex(0,n),e.copy(n),o.copy(n);for(var r=0;r!==i;r++)this.getVertex(r,n),n.x<e.x?e.x=n.x:n.x>o.x&&(o.x=n.x),n.y<e.y?e.y=n.y:n.y>o.y&&(o.y=n.y),n.z<e.z?e.z=n.z:n.z>o.z&&(o.z=n.z)},e.prototype.updateAABB=function(){this.computeLocalAABB(this.aabb)},e.prototype.updateBoundingSphereRadius=function(){for(var t=0,e=this.vertices,o=new s,i=0,n=e.length/3;i!==n;i++){this.getVertex(i,o);var r=o.lengthSquared();r>t&&(t=r)}this.boundingSphereRadius=Math.sqrt(t)},e.prototype.calculateWorldAABB=function(t,e,o,i){var n=fi,r=yi;n.position=t,n.quaternion=e,this.aabb.toWorldFrame(n,r),o.copy(r.lowerBound),i.copy(r.upperBound)},e.prototype.volume=function(){return 4*Math.PI*this.boundingSphereRadius/3},e.createTorus=function(t,o,i,n,r){void 0===t&&(t=1),void 0===o&&(o=.5),void 0===i&&(i=8),void 0===n&&(n=6),void 0===r&&(r=2*Math.PI);for(var s=[],a=[],l=0;l<=i;l++)for(var c=0;c<=n;c++){var u=c/n*r,h=l/i*Math.PI*2,p=(t+o*Math.cos(h))*Math.cos(u),d=(t+o*Math.cos(h))*Math.sin(u),v=o*Math.sin(h);s.push(p,d,v)}for(l=1;l<=i;l++)for(c=1;c<=n;c++){var f=(n+1)*l+c-1,y=(n+1)*(l-1)+c-1,m=(n+1)*(l-1)+c,w=(n+1)*l+c;a.push(f,y,w),a.push(y,m,w)}return new e(s,a)},e}(b),ni=new s,ri=new h,si=new s,ai=new s,li=new s,ci=new s,ui=new s,hi=new s,pi=new s,di=new h,vi=new s,fi=new x,yi=new h,mi=function(){function t(){this.equations=[]}return t.prototype.solve=function(t,e){return 0},t.prototype.addEquation=function(t){!t.enabled||t.bi.isTrigger||t.bj.isTrigger||this.equations.push(t)},t.prototype.removeEquation=function(t){var e=this.equations,o=e.indexOf(t);-1!==o&&e.splice(o,1)},t.prototype.removeAllEquations=function(){this.equations.length=0},t}(),wi=function(){var t=function(e,o){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])},t(e,o)};return function(e,o){if("function"!=typeof o&&null!==o)throw new TypeError("Class extends value "+String(o)+" is not a constructor or null");function i(){this.constructor=e}t(e,o),e.prototype=null===o?Object.create(o):(i.prototype=o.prototype,new i)}}(),gi=function(t){function e(){var e=t.call(this)||this;return e.iterations=10,e.tolerance=1e-7,e}return wi(e,t),e.prototype.solve=function(t,e){var o,i,n,r,s,a=0,l=this.iterations,c=this.tolerance*this.tolerance,u=this.equations,h=u.length,p=e.bodies,d=p.length,v=t;if(0!==h)for(var f=0;f!==d;f++)p[f].updateSolveMassProperties();var y=xi,m=Ai,w=bi;y.length=h,m.length=h,w.length=h;for(f=0;f!==h;f++){var g=u[f];w[f]=0,m[f]=g.computeB(v),y[f]=1/g.computeC()}if(0!==h){for(f=0;f!==d;f++){var b=(B=p[f]).vlambda,x=B.wlambda;b.set(0,0,0),x.set(0,0,0)}for(a=0;a!==l;a++){r=0;for(var A=0;A!==h;A++){g=u[A];o=m[A],i=y[A],(s=w[A])+(n=i*(o-g.computeGWlambda()-g.eps*s))<g.minForce?n=g.minForce-s:s+n>g.maxForce&&(n=g.maxForce-s),w[A]+=n,r+=n>0?n:-n,g.addToWlambda(n)}if(r*r<c)break}for(f=0;f!==d;f++){var B,E=(B=p[f]).velocity,S=B.angularVelocity;B.vlambda.vmul(B.linearFactor,B.vlambda),E.vadd(B.vlambda,E),B.wlambda.vmul(B.angularFactor,B.wlambda),S.vadd(B.wlambda,S)}for(var C=u.length,z=1/v;C--;)u[C].multiplier=w[C]*z}return a},e}(mi),bi=[],xi=[],Ai=[],Bi=function(){var t=function(e,o){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])},t(e,o)};return function(e,o){if("function"!=typeof o&&null!==o)throw new TypeError("Class extends value "+String(o)+" is not a constructor or null");function i(){this.constructor=e}t(e,o),e.prototype=null===o?Object.create(o):(i.prototype=o.prototype,new i)}}(),Ei=function(t){function e(e){var o=t.call(this)||this;for(o.iterations=10,o.tolerance=1e-7,o.subsolver=e,o.nodes=[],o.nodePool=[];o.nodePool.length<128;)o.nodePool.push(o.createNode());return o}return Bi(e,t),e.prototype.createNode=function(){return{body:null,children:[],eqs:[],visited:!1}},e.prototype.solve=function(t,e){for(var o,i=Si,n=this.nodePool,r=e.bodies,s=this.equations,a=s.length,l=r.length,c=this.subsolver;n.length<l;)n.push(this.createNode());i.length=l;for(var u=0;u<l;u++)i[u]=n[u];for(u=0;u!==l;u++){var h=i[u];h.body=r[u],h.children.length=0,h.eqs.length=0,h.visited=!1}for(var p=0;p!==a;p++){var d=s[p],v=(u=r.indexOf(d.bi),r.indexOf(d.bj)),f=i[u],y=i[v];f.children.push(y),f.eqs.push(d),y.children.push(f),y.eqs.push(d)}var m=0,w=Ci;c.tolerance=this.tolerance,c.iterations=this.iterations;for(var g=zi;o=Mi(i);){w.length=0,g.bodies.length=0,Fi(o,_i,g.bodies,w);var b=w.length;w=w.sort(Oi);for(u=0;u!==b;u++)c.addEquation(w[u]);c.solve(t,g);c.removeAllEquations(),m++}return m},e}(mi),Si=[],Ci=[],zi={bodies:[]},Pi=j.STATIC;function Mi(t){for(var e=t.length,o=0;o!==e;o++){var i=t[o];if(!(i.visited||i.body.type&Pi))return i}return!1}var Ti=[];function Fi(t,e,o,i){for(Ti.push(t),t.visited=!0,e(t,o,i);Ti.length;)for(var n=Ti.pop(),r=void 0;r=Mi(n.children);)r.visited=!0,e(r,o,i),Ti.push(r)}function _i(t,e,o){e.push(t.body);for(var i=t.eqs.length,n=0;n!==i;n++){var r=t.eqs[n];o.includes(r)||o.push(r)}}function Oi(t,e){return e.id-t.id}var Ri=function(){function t(){this.objects=[],this.type=Object}return t.prototype.release=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];for(var o=t.length,i=0;i!==o;i++)this.objects.push(t[i]);return this},t.prototype.get=function(){return 0===this.objects.length?this.constructObject():this.objects.pop()},t.prototype.constructObject=function(){throw new Error("constructObject() not implemented in this Pool subclass yet!")},t.prototype.resize=function(t){for(var e=this.objects;e.length>t;)e.pop();for(;e.length<t;)e.push(this.constructObject());return this},t}(),Ii=function(){var t=function(e,o){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])},t(e,o)};return function(e,o){if("function"!=typeof o&&null!==o)throw new TypeError("Class extends value "+String(o)+" is not a constructor or null");function i(){this.constructor=e}t(e,o),e.prototype=null===o?Object.create(o):(i.prototype=o.prototype,new i)}}(),ji=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.type=s,e}return Ii(e,t),e.prototype.constructObject=function(){return new s},e}(Ri),qi={sphereSphere:b.types.SPHERE,spherePlane:b.types.SPHERE|b.types.PLANE,boxBox:b.types.BOX|b.types.BOX,sphereBox:b.types.SPHERE|b.types.BOX,planeBox:b.types.PLANE|b.types.BOX,convexConvex:b.types.CONVEXPOLYHEDRON,sphereConvex:b.types.SPHERE|b.types.CONVEXPOLYHEDRON,planeConvex:b.types.PLANE|b.types.CONVEXPOLYHEDRON,boxConvex:b.types.BOX|b.types.CONVEXPOLYHEDRON,sphereHeightfield:b.types.SPHERE|b.types.HEIGHTFIELD,boxHeightfield:b.types.BOX|b.types.HEIGHTFIELD,convexHeightfield:b.types.CONVEXPOLYHEDRON|b.types.HEIGHTFIELD,sphereParticle:b.types.PARTICLE|b.types.SPHERE,planeParticle:b.types.PLANE|b.types.PARTICLE,boxParticle:b.types.BOX|b.types.PARTICLE,convexParticle:b.types.PARTICLE|b.types.CONVEXPOLYHEDRON,cylinderCylinder:b.types.CYLINDER,sphereCylinder:b.types.SPHERE|b.types.CYLINDER,planeCylinder:b.types.PLANE|b.types.CYLINDER,boxCylinder:b.types.BOX|b.types.CYLINDER,convexCylinder:b.types.CONVEXPOLYHEDRON|b.types.CYLINDER,heightfieldCylinder:b.types.HEIGHTFIELD|b.types.CYLINDER,particleCylinder:b.types.PARTICLE|b.types.CYLINDER,sphereTrimesh:b.types.SPHERE|b.types.TRIMESH,planeTrimesh:b.types.PLANE|b.types.TRIMESH},Ni=function(){function t(t){this.contactPointPool=[],this.frictionEquationPool=[],this.result=[],this.frictionResult=[],this.v3pool=new ji,this.world=t,this.currentContactMaterial=t.defaultContactMaterial,this.enableFrictionReduction=!1}return Object.defineProperty(t.prototype,qi.sphereSphere,{get:function(){return this.sphereSphere},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,qi.spherePlane,{get:function(){return this.spherePlane},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,qi.boxBox,{get:function(){return this.boxBox},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,qi.sphereBox,{get:function(){return this.sphereBox},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,qi.planeBox,{get:function(){return this.planeBox},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,qi.convexConvex,{get:function(){return this.convexConvex},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,qi.sphereConvex,{get:function(){return this.sphereConvex},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,qi.planeConvex,{get:function(){return this.planeConvex},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,qi.boxConvex,{get:function(){return this.boxConvex},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,qi.sphereHeightfield,{get:function(){return this.sphereHeightfield},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,qi.boxHeightfield,{get:function(){return this.boxHeightfield},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,qi.convexHeightfield,{get:function(){return this.convexHeightfield},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,qi.sphereParticle,{get:function(){return this.sphereParticle},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,qi.planeParticle,{get:function(){return this.planeParticle},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,qi.boxParticle,{get:function(){return this.boxParticle},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,qi.convexParticle,{get:function(){return this.convexParticle},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,qi.cylinderCylinder,{get:function(){return this.convexConvex},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,qi.sphereCylinder,{get:function(){return this.sphereConvex},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,qi.planeCylinder,{get:function(){return this.planeConvex},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,qi.boxCylinder,{get:function(){return this.boxConvex},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,qi.convexCylinder,{get:function(){return this.convexConvex},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,qi.heightfieldCylinder,{get:function(){return this.heightfieldCylinder},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,qi.particleCylinder,{get:function(){return this.particleCylinder},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,qi.sphereTrimesh,{get:function(){return this.sphereTrimesh},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,qi.planeTrimesh,{get:function(){return this.planeTrimesh},enumerable:!1,configurable:!0}),t.prototype.createContactEquation=function(t,e,o,i,n,r){var s;this.contactPointPool.length?((s=this.contactPointPool.pop()).bi=t,s.bj=e):s=new Zt(t,e),s.enabled=t.collisionResponse&&e.collisionResponse&&o.collisionResponse&&i.collisionResponse;var a=this.currentContactMaterial;s.restitution=a.restitution,s.setSpookParams(a.contactEquationStiffness,a.contactEquationRelaxation,this.world.dt);var l=o.material||t.material,c=i.material||e.material;return l&&c&&l.restitution>=0&&c.restitution>=0&&(s.restitution=l.restitution*c.restitution),s.si=n||o,s.sj=r||i,s},t.prototype.createFrictionEquationsFromContact=function(t,e){var o=t.bi,i=t.bj,n=t.si,r=t.sj,s=this.world,a=this.currentContactMaterial,l=a.friction,c=n.material||o.material,u=r.material||i.material;if(c&&u&&c.friction>=0&&u.friction>=0&&(l=c.friction*u.friction),l>0){var h=l*(s.frictionGravity||s.gravity).length(),p=o.invMass+i.invMass;p>0&&(p=1/p);var d=this.frictionEquationPool,v=d.length?d.pop():new Pe(o,i,h*p),f=d.length?d.pop():new Pe(o,i,h*p);return v.bi=f.bi=o,v.bj=f.bj=i,v.minForce=f.minForce=-h*p,v.maxForce=f.maxForce=h*p,v.ri.copy(t.ri),v.rj.copy(t.rj),f.ri.copy(t.ri),f.rj.copy(t.rj),t.ni.tangents(v.t,f.t),v.setSpookParams(a.frictionEquationStiffness,a.frictionEquationRelaxation,s.dt),f.setSpookParams(a.frictionEquationStiffness,a.frictionEquationRelaxation,s.dt),v.enabled=f.enabled=t.enabled,e.push(v,f),!0}return!1},t.prototype.createFrictionFromAverage=function(t){var e=this.result[this.result.length-1];if(this.createFrictionEquationsFromContact(e,this.frictionResult)&&1!==t){var o=this.frictionResult[this.frictionResult.length-2],i=this.frictionResult[this.frictionResult.length-1];Li.setZero(),Wi.setZero(),Vi.setZero();for(var n=e.bi,r=(e.bj,0);r!==t;r++)(e=this.result[this.result.length-1-r]).bi!==n?(Li.vadd(e.ni,Li),Wi.vadd(e.ri,Wi),Vi.vadd(e.rj,Vi)):(Li.vsub(e.ni,Li),Wi.vadd(e.rj,Wi),Vi.vadd(e.ri,Vi));var s=1/t;Wi.scale(s,o.ri),Vi.scale(s,o.rj),i.ri.copy(o.ri),i.rj.copy(o.rj),Li.normalize(),Li.tangents(o.t,i.t)}},t.prototype.getContacts=function(t,e,o,i,n,r,s){this.contactPointPool=n,this.frictionEquationPool=s,this.result=i,this.frictionResult=r;for(var a=Di,l=Ui,c=ki,u=Hi,h=0,p=t.length;h!==p;h++){var d=t[h],v=e[h],f=null;d.material&&v.material&&(f=o.getContactMaterial(d.material,v.material)||null);for(var y=d.type&j.KINEMATIC&&v.type&j.STATIC||d.type&j.STATIC&&v.type&j.KINEMATIC||d.type&j.KINEMATIC&&v.type&j.KINEMATIC,m=0;m<d.shapes.length;m++){d.quaternion.mult(d.shapeOrientations[m],a),d.quaternion.vmult(d.shapeOffsets[m],c),c.vadd(d.position,c);for(var w=d.shapes[m],g=0;g<v.shapes.length;g++){v.quaternion.mult(v.shapeOrientations[g],l),v.quaternion.vmult(v.shapeOffsets[g],u),u.vadd(v.position,u);var b=v.shapes[g];if(w.collisionFilterMask&b.collisionFilterGroup&&b.collisionFilterMask&w.collisionFilterGroup&&!(c.distanceTo(u)>w.boundingSphereRadius+b.boundingSphereRadius)){var x=null;w.material&&b.material&&(x=o.getContactMaterial(w.material,b.material)||null),this.currentContactMaterial=x||f||o.defaultContactMaterial;var A=this[w.type|b.type];if(A){(w.type<b.type?A.call(this,w,b,c,u,a,l,d,v,w,b,y):A.call(this,b,w,u,c,l,a,v,d,w,b,y))&&y&&(o.shapeOverlapKeeper.set(w.id,b.id),o.bodyOverlapKeeper.set(d.id,v.id))}}}}}},t.prototype.sphereSphere=function(t,e,o,i,n,r,s,a,l,c,u){if(u)return o.distanceSquared(i)<Math.pow(t.radius+e.radius,2);var h=this.createContactEquation(s,a,t,e,l,c);i.vsub(o,h.ni),h.ni.normalize(),h.ri.copy(h.ni),h.rj.copy(h.ni),h.ri.scale(t.radius,h.ri),h.rj.scale(-e.radius,h.rj),h.ri.vadd(o,h.ri),h.ri.vsub(s.position,h.ri),h.rj.vadd(i,h.rj),h.rj.vsub(a.position,h.rj),this.result.push(h),this.createFrictionEquationsFromContact(h,this.frictionResult)},t.prototype.spherePlane=function(t,e,o,i,n,r,s,a,l,c,u){var h=this.createContactEquation(s,a,t,e,l,c);if(h.ni.set(0,0,1),r.vmult(h.ni,h.ni),h.ni.negate(h.ni),h.ni.normalize(),h.ni.scale(t.radius,h.ri),o.vsub(i,hn),h.ni.scale(h.ni.dot(hn),pn),hn.vsub(pn,h.rj),-hn.dot(h.ni)<=t.radius){if(u)return!0;var p=h.ri,d=h.rj;p.vadd(o,p),p.vsub(s.position,p),d.vadd(i,d),d.vsub(a.position,d),this.result.push(h),this.createFrictionEquationsFromContact(h,this.frictionResult)}},t.prototype.boxBox=function(t,e,o,i,n,r,s,a,l,c,u){return t.convexPolyhedronRepresentation.material=t.material,e.convexPolyhedronRepresentation.material=e.material,t.convexPolyhedronRepresentation.collisionResponse=t.collisionResponse,e.convexPolyhedronRepresentation.collisionResponse=e.collisionResponse,this.convexConvex(t.convexPolyhedronRepresentation,e.convexPolyhedronRepresentation,o,i,n,r,s,a,t,e,u)},t.prototype.sphereBox=function(t,e,o,i,n,r,s,a,l,c,u){var h=this.v3pool,p=xn;o.vsub(i,mn),e.getSideNormals(p,r);for(var d=t.radius,v=!1,f=Bn,y=En,m=Sn,w=null,g=0,b=0,x=0,A=null,B=0,E=p.length;B!==E&&!1===v;B++){var S=wn;S.copy(p[B]);var C=S.length();S.normalize();var z=mn.dot(S);if(z<C+d&&z>0){var P=gn,M=bn;P.copy(p[(B+1)%3]),M.copy(p[(B+2)%3]);var T=P.length(),F=M.length();P.normalize(),M.normalize();var _=mn.dot(P),O=mn.dot(M);if(_<T&&_>-T&&O<F&&O>-F){var R=Math.abs(z-C-d);if((null===A||R<A)&&(A=R,b=_,x=O,w=C,f.copy(S),y.copy(P),m.copy(M),g++,u))return!0}}}if(g){v=!0;var I=this.createContactEquation(s,a,t,e,l,c);f.scale(-d,I.ri),I.ni.copy(f),I.ni.negate(I.ni),f.scale(w,f),y.scale(b,y),f.vadd(y,f),m.scale(x,m),f.vadd(m,I.rj),I.ri.vadd(o,I.ri),I.ri.vsub(s.position,I.ri),I.rj.vadd(i,I.rj),I.rj.vsub(a.position,I.rj),this.result.push(I),this.createFrictionEquationsFromContact(I,this.frictionResult)}for(var j=h.get(),q=An,N=0;2!==N&&!v;N++)for(var L=0;2!==L&&!v;L++)for(var W=0;2!==W&&!v;W++)if(j.set(0,0,0),N?j.vadd(p[0],j):j.vsub(p[0],j),L?j.vadd(p[1],j):j.vsub(p[1],j),W?j.vadd(p[2],j):j.vsub(p[2],j),i.vadd(j,q),q.vsub(o,q),q.lengthSquared()<d*d){if(u)return!0;v=!0;var V=this.createContactEquation(s,a,t,e,l,c);V.ri.copy(q),V.ri.normalize(),V.ni.copy(V.ri),V.ri.scale(d,V.ri),V.rj.copy(j),V.ri.vadd(o,V.ri),V.ri.vsub(s.position,V.ri),V.rj.vadd(i,V.rj),V.rj.vsub(a.position,V.rj),this.result.push(V),this.createFrictionEquationsFromContact(V,this.frictionResult)}h.release(j),j=null;var k=h.get(),H=h.get(),D=h.get(),U=h.get(),G=h.get(),Y=p.length;for(N=0;N!==Y&&!v;N++)for(L=0;L!==Y&&!v;L++)if(N%3!=L%3){p[L].cross(p[N],k),k.normalize(),p[N].vadd(p[L],H),D.copy(o),D.vsub(H,D),D.vsub(i,D);var X=D.dot(k);k.scale(X,U);for(W=0;W===N%3||W===L%3;)W++;G.copy(o),G.vsub(U,G),G.vsub(H,G),G.vsub(i,G);var K=Math.abs(X),Z=G.length();if(K<p[W].length()&&Z<d){if(u)return!0;v=!0;var Q=this.createContactEquation(s,a,t,e,l,c);H.vadd(U,Q.rj),Q.rj.copy(Q.rj),G.negate(Q.ni),Q.ni.normalize(),Q.ri.copy(Q.rj),Q.ri.vadd(i,Q.ri),Q.ri.vsub(o,Q.ri),Q.ri.normalize(),Q.ri.scale(d,Q.ri),Q.ri.vadd(o,Q.ri),Q.ri.vsub(s.position,Q.ri),Q.rj.vadd(i,Q.rj),Q.rj.vsub(a.position,Q.rj),this.result.push(Q),this.createFrictionEquationsFromContact(Q,this.frictionResult)}}h.release(k,H,D,U,G)},t.prototype.planeBox=function(t,e,o,i,n,r,s,a,l,c,u){return e.convexPolyhedronRepresentation.material=e.material,e.convexPolyhedronRepresentation.collisionResponse=e.collisionResponse,e.convexPolyhedronRepresentation.id=e.id,this.planeConvex(t,e.convexPolyhedronRepresentation,o,i,n,r,s,a,t,e,u)},t.prototype.convexConvex=function(t,e,o,i,n,r,s,a,l,c,u,h,p){var d=Wn;if(!(o.distanceTo(i)>t.boundingSphereRadius+e.boundingSphereRadius)&&t.findSeparatingAxis(e,o,n,i,r,d,h,p)){var v=[],f=Vn;t.clipAgainstHull(o,n,e,i,r,d,-100,100,v);for(var y=0,m=0;m!==v.length;m++){if(u)return!0;var w=this.createContactEquation(s,a,t,e,l,c),g=w.ri,b=w.rj;d.negate(w.ni),v[m].normal.negate(f),f.scale(v[m].depth,f),v[m].point.vadd(f,g),b.copy(v[m].point),g.vsub(o,g),b.vsub(i,b),g.vadd(o,g),g.vsub(s.position,g),b.vadd(i,b),b.vsub(a.position,b),this.result.push(w),y++,this.enableFrictionReduction||this.createFrictionEquationsFromContact(w,this.frictionResult)}this.enableFrictionReduction&&y&&this.createFrictionFromAverage(y)}},t.prototype.sphereConvex=function(t,e,o,i,n,r,s,a,l,c,u){var h=this.v3pool;o.vsub(i,Cn);for(var p=e.faceNormals,d=e.faces,v=e.vertices,f=t.radius,y=!1,m=0;m!==v.length;m++){var w=v[m],g=Tn;r.vmult(w,g),i.vadd(g,g);var b=Mn;if(g.vsub(o,b),b.lengthSquared()<f*f)return!!u||(y=!0,(R=this.createContactEquation(s,a,t,e,l,c)).ri.copy(b),R.ri.normalize(),R.ni.copy(R.ri),R.ri.scale(f,R.ri),g.vsub(i,R.rj),R.ri.vadd(o,R.ri),R.ri.vsub(s.position,R.ri),R.rj.vadd(i,R.rj),R.rj.vsub(a.position,R.rj),this.result.push(R),void this.createFrictionEquationsFromContact(R,this.frictionResult))}m=0;for(var x=d.length;m!==x&&!1===y;m++){var A=p[m],B=d[m],E=Fn;r.vmult(A,E);var S=_n;r.vmult(v[B[0]],S),S.vadd(i,S);var C=On;E.scale(-f,C),o.vadd(C,C);var z=Rn;C.vsub(S,z);var P=z.dot(E),M=In;if(o.vsub(S,M),P<0&&M.dot(E)>0){for(var T=[],F=0,_=B.length;F!==_;F++){var O=h.get();r.vmult(v[B[F]],O),i.vadd(O,O),T.push(O)}if(yn(T,E,o)){if(u)return!0;y=!0;var R=this.createContactEquation(s,a,t,e,l,c);E.scale(-f,R.ri),E.negate(R.ni);var I=h.get();E.scale(-P,I);var j=h.get();E.scale(-f,j),o.vsub(i,R.rj),R.rj.vadd(j,R.rj),R.rj.vadd(I,R.rj),R.rj.vadd(i,R.rj),R.rj.vsub(a.position,R.rj),R.ri.vadd(o,R.ri),R.ri.vsub(s.position,R.ri),h.release(I),h.release(j),this.result.push(R),this.createFrictionEquationsFromContact(R,this.frictionResult);F=0;for(var q=T.length;F!==q;F++)h.release(T[F]);return}for(F=0;F!==B.length;F++){var N=h.get(),L=h.get();r.vmult(v[B[(F+1)%B.length]],N),r.vmult(v[B[(F+2)%B.length]],L),i.vadd(N,N),i.vadd(L,L);var W=zn;L.vsub(N,W);var V=Pn;W.unit(V);var k=h.get(),H=h.get();o.vsub(N,H);var D=H.dot(V);V.scale(D,k),k.vadd(N,k);var U=h.get();if(k.vsub(o,U),D>0&&D*D<W.lengthSquared()&&U.lengthSquared()<f*f){if(u)return!0;R=this.createContactEquation(s,a,t,e,l,c);k.vsub(i,R.rj),k.vsub(o,R.ni),R.ni.normalize(),R.ni.scale(f,R.ri),R.rj.vadd(i,R.rj),R.rj.vsub(a.position,R.rj),R.ri.vadd(o,R.ri),R.ri.vsub(s.position,R.ri),this.result.push(R),this.createFrictionEquationsFromContact(R,this.frictionResult);var G=0;for(q=T.length;G!==q;G++)h.release(T[G]);return h.release(N),h.release(L),h.release(k),h.release(U),void h.release(H)}h.release(N),h.release(L),h.release(k),h.release(U),h.release(H)}for(F=0,q=T.length;F!==q;F++)h.release(T[F])}}},t.prototype.planeConvex=function(t,e,o,i,n,r,s,a,l,c,u){var h=jn,p=qn;p.set(0,0,1),n.vmult(p,p);for(var d=0,v=Nn,f=0;f!==e.vertices.length;f++){if(h.copy(e.vertices[f]),r.vmult(h,h),i.vadd(h,h),h.vsub(o,v),p.dot(v)<=0){if(u)return!0;var y=this.createContactEquation(s,a,t,e,l,c),m=Ln;p.scale(p.dot(v),m),h.vsub(m,m),m.vsub(o,y.ri),y.ni.copy(p),h.vsub(i,y.rj),y.ri.vadd(o,y.ri),y.ri.vsub(s.position,y.ri),y.rj.vadd(i,y.rj),y.rj.vsub(a.position,y.rj),this.result.push(y),d++,this.enableFrictionReduction||this.createFrictionEquationsFromContact(y,this.frictionResult)}}this.enableFrictionReduction&&d&&this.createFrictionFromAverage(d)},t.prototype.boxConvex=function(t,e,o,i,n,r,s,a,l,c,u){return t.convexPolyhedronRepresentation.material=t.material,t.convexPolyhedronRepresentation.collisionResponse=t.collisionResponse,this.convexConvex(t.convexPolyhedronRepresentation,e,o,i,n,r,s,a,t,e,u)},t.prototype.sphereHeightfield=function(t,e,o,i,n,r,s,a,l,c,u){var h=e.data,p=t.radius,d=e.elementSize,v=er,f=tr;x.pointToLocalFrame(i,r,o,f);var y=Math.floor((f.x-p)/d)-1,m=Math.ceil((f.x+p)/d)+1,w=Math.floor((f.y-p)/d)-1,g=Math.ceil((f.y+p)/d)+1;if(!(m<0||g<0||y>h.length||w>h[0].length)){y<0&&(y=0),m<0&&(m=0),w<0&&(w=0),g<0&&(g=0),y>=h.length&&(y=h.length-1),m>=h.length&&(m=h.length-1),g>=h[0].length&&(g=h[0].length-1),w>=h[0].length&&(w=h[0].length-1);var b=[];e.getRectMinMax(y,w,m,g,b);var A=b[0],B=b[1];if(!(f.z-p>B||f.z+p<A))for(var E=this.result,S=y;S<m;S++)for(var C=w;C<g;C++){var z=E.length,P=!1;if(e.getConvexTrianglePillar(S,C,!1),x.pointToWorldFrame(i,r,e.pillarOffset,v),o.distanceTo(v)<e.pillarConvex.boundingSphereRadius+t.boundingSphereRadius&&(P=this.sphereConvex(t,e.pillarConvex,o,v,n,r,s,a,t,e,u)),u&&P)return!0;if(e.getConvexTrianglePillar(S,C,!0),x.pointToWorldFrame(i,r,e.pillarOffset,v),o.distanceTo(v)<e.pillarConvex.boundingSphereRadius+t.boundingSphereRadius&&(P=this.sphereConvex(t,e.pillarConvex,o,v,n,r,s,a,t,e,u)),u&&P)return!0;if(E.length-z>2)return}}},t.prototype.boxHeightfield=function(t,e,o,i,n,r,s,a,l,c,u){return t.convexPolyhedronRepresentation.material=t.material,t.convexPolyhedronRepresentation.collisionResponse=t.collisionResponse,this.convexHeightfield(t.convexPolyhedronRepresentation,e,o,i,n,r,s,a,t,e,u)},t.prototype.convexHeightfield=function(t,e,o,i,n,r,s,a,l,c,u){var h=e.data,p=e.elementSize,d=t.boundingSphereRadius,v=Jn,f=$n,y=Qn;x.pointToLocalFrame(i,r,o,y);var m=Math.floor((y.x-d)/p)-1,w=Math.ceil((y.x+d)/p)+1,g=Math.floor((y.y-d)/p)-1,b=Math.ceil((y.y+d)/p)+1;if(!(w<0||b<0||m>h.length||g>h[0].length)){m<0&&(m=0),w<0&&(w=0),g<0&&(g=0),b<0&&(b=0),m>=h.length&&(m=h.length-1),w>=h.length&&(w=h.length-1),b>=h[0].length&&(b=h[0].length-1),g>=h[0].length&&(g=h[0].length-1);var A=[];e.getRectMinMax(m,g,w,b,A);var B=A[0],E=A[1];if(!(y.z-d>E||y.z+d<B))for(var S=m;S<w;S++)for(var C=g;C<b;C++){var z=!1;if(e.getConvexTrianglePillar(S,C,!1),x.pointToWorldFrame(i,r,e.pillarOffset,v),o.distanceTo(v)<e.pillarConvex.boundingSphereRadius+t.boundingSphereRadius&&(z=this.convexConvex(t,e.pillarConvex,o,v,n,r,s,a,null,null,u,f,null)),u&&z)return!0;if(e.getConvexTrianglePillar(S,C,!0),x.pointToWorldFrame(i,r,e.pillarOffset,v),o.distanceTo(v)<e.pillarConvex.boundingSphereRadius+t.boundingSphereRadius&&(z=this.convexConvex(t,e.pillarConvex,o,v,n,r,s,a,null,null,u,f,null)),u&&z)return!0}}},t.prototype.sphereParticle=function(t,e,o,i,n,r,s,a,l,c,u){var h=Un;if(h.set(0,0,1),i.vsub(o,h),h.lengthSquared()<=t.radius*t.radius){if(u)return!0;var p=this.createContactEquation(a,s,e,t,l,c);h.normalize(),p.rj.copy(h),p.rj.scale(t.radius,p.rj),p.ni.copy(h),p.ni.negate(p.ni),p.ri.set(0,0,0),this.result.push(p),this.createFrictionEquationsFromContact(p,this.frictionResult)}},t.prototype.planeParticle=function(t,e,o,i,n,r,s,a,l,c,u){var h=kn;h.set(0,0,1),s.quaternion.vmult(h,h);var p=Hn;if(i.vsub(s.position,p),h.dot(p)<=0){if(u)return!0;var d=this.createContactEquation(a,s,e,t,l,c);d.ni.copy(h),d.ni.negate(d.ni),d.ri.set(0,0,0);var v=Dn;h.scale(h.dot(i),v),i.vsub(v,v),d.rj.copy(v),this.result.push(d),this.createFrictionEquationsFromContact(d,this.frictionResult)}},t.prototype.boxParticle=function(t,e,o,i,n,r,s,a,l,c,u){return t.convexPolyhedronRepresentation.material=t.material,t.convexPolyhedronRepresentation.collisionResponse=t.collisionResponse,this.convexParticle(t.convexPolyhedronRepresentation,e,o,i,n,r,s,a,t,e,u)},t.prototype.convexParticle=function(t,e,o,i,n,r,s,a,l,c,u){var h=-1,p=Xn,d=Zn,v=null,f=Yn;if(f.copy(i),f.vsub(o,f),n.conjugate(Gn),Gn.vmult(f,f),t.pointIsInside(f)){t.worldVerticesNeedsUpdate&&t.computeWorldVertices(o,n),t.worldFaceNormalsNeedsUpdate&&t.computeWorldFaceNormals(n);for(var y=0,m=t.faces.length;y!==m;y++){var w=[t.worldVertices[t.faces[y][0]]],g=t.worldFaceNormals[y];i.vsub(w[0],Kn);var b=-g.dot(Kn);if(null===v||Math.abs(b)<Math.abs(v)){if(u)return!0;v=b,h=y,p.copy(g)}}if(-1!==h){var x=this.createContactEquation(a,s,e,t,l,c);p.scale(v,d),d.vadd(i,d),d.vsub(o,d),x.rj.copy(d),p.negate(x.ni),x.ri.set(0,0,0);var A=x.ri,B=x.rj;A.vadd(i,A),A.vsub(a.position,A),B.vadd(o,B),B.vsub(s.position,B),this.result.push(x),this.createFrictionEquationsFromContact(x,this.frictionResult)}else console.warn("Point found inside convex, but did not find penetrating face!")}},t.prototype.heightfieldCylinder=function(t,e,o,i,n,r,s,a,l,c,u){return this.convexHeightfield(e,t,i,o,r,n,a,s,l,c,u)},t.prototype.particleCylinder=function(t,e,o,i,n,r,s,a,l,c,u){return this.convexParticle(e,t,i,o,r,n,a,s,l,c,u)},t.prototype.sphereTrimesh=function(t,e,o,i,n,r,s,a,l,c,u){var h=$i,p=tn,d=en,v=on,f=nn,y=rn,m=cn,w=Ji,g=Zi,b=un;x.pointToLocalFrame(i,r,o,f);var A=t.radius;m.lowerBound.set(f.x-A,f.y-A,f.z-A),m.upperBound.set(f.x+A,f.y+A,f.z+A),e.getTrianglesInAABB(m,b);for(var B=Qi,E=t.radius*t.radius,S=0;S<b.length;S++)for(var C=0;C<3;C++)if(e.getVertex(e.indices[3*b[S]+C],B),B.vsub(f,g),g.lengthSquared()<=E){if(w.copy(B),x.pointToWorldFrame(i,r,w,B),B.vsub(o,g),u)return!0;(M=this.createContactEquation(s,a,t,e,l,c)).ni.copy(g),M.ni.normalize(),M.ri.copy(M.ni),M.ri.scale(t.radius,M.ri),M.ri.vadd(o,M.ri),M.ri.vsub(s.position,M.ri),M.rj.copy(B),M.rj.vsub(a.position,M.rj),this.result.push(M),this.createFrictionEquationsFromContact(M,this.frictionResult)}for(S=0;S<b.length;S++)for(C=0;C<3;C++){e.getVertex(e.indices[3*b[S]+C],h),e.getVertex(e.indices[3*b[S]+(C+1)%3],p),p.vsub(h,d),f.vsub(p,y);var z=y.dot(d);f.vsub(h,y);var P=y.dot(d);if(P>0&&z<0)if(f.vsub(h,y),v.copy(d),v.normalize(),P=y.dot(v),v.scale(P,y),y.vadd(h,y),(I=y.distanceTo(f))<t.radius){if(u)return!0;var M=this.createContactEquation(s,a,t,e,l,c);y.vsub(f,M.ni),M.ni.normalize(),M.ni.scale(t.radius,M.ri),M.ri.vadd(o,M.ri),M.ri.vsub(s.position,M.ri),x.pointToWorldFrame(i,r,y,y),y.vsub(a.position,M.rj),x.vectorToWorldFrame(r,M.ni,M.ni),x.vectorToWorldFrame(r,M.ri,M.ri),this.result.push(M),this.createFrictionEquationsFromContact(M,this.frictionResult)}}for(var T=sn,F=an,_=ln,O=Ki,R=(S=0,b.length);S!==R;S++){e.getTriangleVertices(b[S],T,F,_),e.getNormal(b[S],O),f.vsub(T,y);var I=y.dot(O);if(O.scale(I,y),f.vsub(y,y),I=y.distanceTo(f),lt.pointInTriangle(y,T,F,_)&&I<t.radius){if(u)return!0;M=this.createContactEquation(s,a,t,e,l,c);y.vsub(f,M.ni),M.ni.normalize(),M.ni.scale(t.radius,M.ri),M.ri.vadd(o,M.ri),M.ri.vsub(s.position,M.ri),x.pointToWorldFrame(i,r,y,y),y.vsub(a.position,M.rj),x.vectorToWorldFrame(r,M.ni,M.ni),x.vectorToWorldFrame(r,M.ri,M.ri),this.result.push(M),this.createFrictionEquationsFromContact(M,this.frictionResult)}}b.length=0},t.prototype.planeTrimesh=function(t,e,o,i,n,r,a,l,c,u,h){var p=new s,d=Gi;d.set(0,0,1),n.vmult(d,d);for(var v=0;v<e.vertices.length/3;v++){e.getVertex(v,p);var f=new s;f.copy(p),x.pointToWorldFrame(i,r,f,p);var y=Yi;if(p.vsub(o,y),d.dot(y)<=0){if(h)return!0;var m=this.createContactEquation(a,l,t,e,c,u);m.ni.copy(d);var w=Xi;d.scale(y.dot(d),w),p.vsub(w,w),m.ri.copy(w),m.ri.vsub(a.position,m.ri),m.rj.copy(p),m.rj.vsub(l.position,m.rj),this.result.push(m),this.createFrictionEquationsFromContact(m,this.frictionResult)}}},t}(),Li=new s,Wi=new s,Vi=new s,ki=new s,Hi=new s,Di=new y,Ui=new y;var Gi=new s,Yi=new s,Xi=new s,Ki=new s,Zi=new s,Qi=(new s,new s),Ji=new s,$i=new s,tn=new s,en=new s,on=new s,nn=new s,rn=new s,sn=new s,an=new s,ln=new s,cn=new h,un=[],hn=new s,pn=new s,dn=new s,vn=new s,fn=new s;function yn(t,e,o){for(var i=null,n=t.length,r=0;r!==n;r++){var s=t[r],a=dn;t[(r+1)%n].vsub(s,a);var l=vn;a.cross(e,l);var c=fn;o.vsub(s,c);var u=l.dot(c);if(!(null===i||u>0&&!0===i||u<=0&&!1===i))return!1;null===i&&(i=u>0)}return!0}var mn=new s,wn=new s,gn=new s,bn=new s,xn=[new s,new s,new s,new s,new s,new s],An=new s,Bn=new s,En=new s,Sn=new s,Cn=new s,zn=new s,Pn=new s,Mn=new s,Tn=new s,Fn=new s,_n=new s,On=new s,Rn=new s,In=new s,jn=(new s,new s,new s),qn=new s,Nn=new s,Ln=new s,Wn=new s,Vn=new s,kn=new s,Hn=new s,Dn=new s,Un=new s,Gn=new y,Yn=new s,Xn=(new s,new s),Kn=new s,Zn=new s,Qn=new s,Jn=new s,$n=[0],tr=new s,er=new s,or=function(){function t(){this.current=[],this.previous=[]}return t.prototype.getKey=function(t,e){if(e<t){var o=e;e=t,t=o}return t<<16|e},t.prototype.set=function(t,e){for(var o=this.getKey(t,e),i=this.current,n=0;o>i[n];)n++;if(o!==i[n]){for(var r=i.length-1;r>=n;r--)i[r+1]=i[r];i[n]=o}},t.prototype.tick=function(){var t=this.current;this.current=this.previous,this.previous=t,this.current.length=0},t.prototype.getDiff=function(t,e){for(var o=this.current,i=this.previous,n=o.length,r=i.length,s=0,a=0;a<n;a++){for(var l=o[a];l>i[s];)s++;l===i[s]||ir(t,l)}s=0;for(a=0;a<r;a++){for(var c=i[a];c>o[s];)s++;o[s]===c||ir(e,c)}},t}();function ir(t,e){t.push((4294901760&e)>>16,65535&e)}var nr=function(t,e){return t<e?"".concat(t,"-").concat(e):"".concat(e,"-").concat(t)},rr=function(){function t(){this.data={keys:[]}}return t.prototype.get=function(t,e){var o=nr(t,e);return this.data[o]},t.prototype.set=function(t,e,o){var i=nr(t,e);this.get(t,e)||this.data.keys.push(i),this.data[i]=o},t.prototype.delete=function(t,e){var o=nr(t,e),i=this.data.keys.indexOf(o);-1!==i&&this.data.keys.splice(i,1),delete this.data[o]},t.prototype.reset=function(){for(var t=this.data,e=t.keys;e.length>0;){delete t[e.pop()]}},t}(),sr=function(){var t=function(e,o){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])},t(e,o)};return function(e,o){if("function"!=typeof o&&null!==o)throw new TypeError("Class extends value "+String(o)+" is not a constructor or null");function i(){this.constructor=e}t(e,o),e.prototype=null===o?Object.create(o):(i.prototype=o.prototype,new i)}}(),ar=function(t){function e(e){void 0===e&&(e={});var o=t.call(this)||this;return o.dt=-1,o.allowSleep=!!e.allowSleep,o.contacts=[],o.frictionEquations=[],o.quatNormalizeSkip=void 0!==e.quatNormalizeSkip?e.quatNormalizeSkip:0,o.quatNormalizeFast=void 0!==e.quatNormalizeFast&&e.quatNormalizeFast,o.time=0,o.stepnumber=0,o.default_dt=1/60,o.nextId=0,o.gravity=new s,e.gravity&&o.gravity.copy(e.gravity),e.frictionGravity&&(o.frictionGravity=new s,o.frictionGravity.copy(e.frictionGravity)),o.broadphase=void 0!==e.broadphase?e.broadphase:new rt,o.bodies=[],o.hasActiveBodies=!1,o.solver=void 0!==e.solver?e.solver:new gi,o.constraints=[],o.narrowphase=new Ni(o),o.collisionMatrix=new v,o.collisionMatrixPrevious=new v,o.bodyOverlapKeeper=new or,o.shapeOverlapKeeper=new or,o.contactmaterials=[],o.contactMaterialTable=new rr,o.defaultMaterial=new _e("default"),o.defaultContactMaterial=new Fe(o.defaultMaterial,o.defaultMaterial,{friction:.3,restitution:0}),o.doProfiling=!1,o.profile={solve:0,makeContactConstraints:0,broadphase:0,integrate:0,narrowphase:0},o.accumulator=0,o.subsystems=[],o.addBodyEvent={type:"addBody",body:null},o.removeBodyEvent={type:"removeBody",body:null},o.idToBodyMap={},o.broadphase.setWorld(o),o}return sr(e,t),e.prototype.getContactMaterial=function(t,e){return this.contactMaterialTable.get(t.id,e.id)},e.prototype.collisionMatrixTick=function(){var t=this.collisionMatrixPrevious;this.collisionMatrixPrevious=this.collisionMatrix,this.collisionMatrix=t,this.collisionMatrix.reset(),this.bodyOverlapKeeper.tick(),this.shapeOverlapKeeper.tick()},e.prototype.addConstraint=function(t){this.constraints.push(t)},e.prototype.removeConstraint=function(t){var e=this.constraints.indexOf(t);-1!==e&&this.constraints.splice(e,1)},e.prototype.rayTest=function(t,e,o){o instanceof st?this.raycastClosest(t,e,{skipBackfaces:!0},o):this.raycastAll(t,e,{skipBackfaces:!0},o)},e.prototype.raycastAll=function(t,e,o,i){return void 0===o&&(o={}),o.mode=lt.ALL,o.from=t,o.to=e,o.callback=i,lr.intersectWorld(this,o)},e.prototype.raycastAny=function(t,e,o,i){return void 0===o&&(o={}),o.mode=lt.ANY,o.from=t,o.to=e,o.result=i,lr.intersectWorld(this,o)},e.prototype.raycastClosest=function(t,e,o,i){return void 0===o&&(o={}),o.mode=lt.CLOSEST,o.from=t,o.to=e,o.result=i,lr.intersectWorld(this,o)},e.prototype.addBody=function(t){this.bodies.includes(t)||(t.index=this.bodies.length,this.bodies.push(t),t.world=this,t.initPosition.copy(t.position),t.initVelocity.copy(t.velocity),t.timeLastSleepy=this.time,t instanceof j&&(t.initAngularVelocity.copy(t.angularVelocity),t.initQuaternion.copy(t.quaternion)),this.collisionMatrix.setNumObjects(this.bodies.length),this.addBodyEvent.body=t,this.idToBodyMap[t.id]=t,this.dispatchEvent(this.addBodyEvent))},e.prototype.removeBody=function(t){t.world=null;var e=this.bodies.length-1,o=this.bodies,i=o.indexOf(t);if(-1!==i){o.splice(i,1);for(var n=0;n!==o.length;n++)o[n].index=n;this.collisionMatrix.setNumObjects(e),this.removeBodyEvent.body=t,delete this.idToBodyMap[t.id],this.dispatchEvent(this.removeBodyEvent)}},e.prototype.getBodyById=function(t){return this.idToBodyMap[t]},e.prototype.getShapeById=function(t){for(var e=this.bodies,o=0;o<e.length;o++)for(var i=e[o].shapes,n=0;n<i.length;n++){var r=i[n];if(r.id===t)return r}return null},e.prototype.addContactMaterial=function(t){this.contactmaterials.push(t),this.contactMaterialTable.set(t.materials[0].id,t.materials[1].id,t)},e.prototype.removeContactMaterial=function(t){var e=this.contactmaterials.indexOf(t);-1!==e&&(this.contactmaterials.splice(e,1),this.contactMaterialTable.delete(t.materials[0].id,t.materials[1].id))},e.prototype.fixedStep=function(t,e){void 0===t&&(t=1/60),void 0===e&&(e=10);var o=cr.now()/1e3;if(this.lastCallTime){var i=o-this.lastCallTime;this.step(t,i,e)}else this.step(t,void 0,e);this.lastCallTime=o},e.prototype.step=function(t,e,o){if(void 0===o&&(o=10),void 0===e)this.internalStep(t),this.time+=t;else{this.accumulator+=e;for(var i=cr.now(),n=0;this.accumulator>=t&&n<o&&(this.internalStep(t),this.accumulator-=t,n++,!(cr.now()-i>1e3*t)););this.accumulator=this.accumulator%t;for(var r=this.accumulator/t,s=0;s!==this.bodies.length;s++){var a=this.bodies[s];a.previousPosition.lerp(a.position,r,a.interpolatedPosition),a.previousQuaternion.slerp(a.quaternion,r,a.interpolatedQuaternion),a.previousQuaternion.normalize()}this.time+=e}},e.prototype.internalStep=function(t){this.dt=t;var e=this.contacts,o=yr,i=mr,n=this.bodies.length,r=this.bodies,s=this.solver,a=this.gravity,l=this.doProfiling,c=this.profile,u=j.DYNAMIC,h=-1/0,p=this.constraints,d=fr,v=(a.length(),a.x),f=a.y,y=a.z,m=0;for(l&&(h=cr.now()),m=0;m!==n;m++){if((M=r[m]).type===u){var w=M.force,g=M.mass;w.x+=g*v,w.y+=g*f,w.z+=g*y}}for(var b=0,x=this.subsystems.length;b!==x;b++)this.subsystems[b].update();l&&(h=cr.now()),o.length=0,i.length=0,this.broadphase.collisionPairs(this,o,i),l&&(c.broadphase=cr.now()-h);var A=p.length;for(m=0;m!==A;m++){if(!(O=p[m]).collideConnected)for(var B=o.length-1;B>=0;B-=1)(O.bodyA===o[B]&&O.bodyB===i[B]||O.bodyB===o[B]&&O.bodyA===i[B])&&(o.splice(B,1),i.splice(B,1))}this.collisionMatrixTick(),l&&(h=cr.now());var E=vr,S=e.length;for(m=0;m!==S;m++)E.push(e[m]);e.length=0;var C=this.frictionEquations.length;for(m=0;m!==C;m++)d.push(this.frictionEquations[m]);for(this.frictionEquations.length=0,this.narrowphase.getContacts(o,i,this,e,E,this.frictionEquations,d),l&&(c.narrowphase=cr.now()-h),l&&(h=cr.now()),m=0;m<this.frictionEquations.length;m++)s.addEquation(this.frictionEquations[m]);for(var z=e.length,P=0;P!==z;P++){var M=(O=e[P]).bi,T=O.bj,F=O.si,_=O.sj;(M.material&&T.material&&this.getContactMaterial(M.material,T.material)||this.defaultContactMaterial).friction;if(M.material&&T.material&&(M.material.friction>=0&&T.material.friction>=0&&M.material.friction*T.material.friction,M.material.restitution>=0&&T.material.restitution>=0&&(O.restitution=M.material.restitution*T.material.restitution)),s.addEquation(O),M.allowSleep&&M.type===j.DYNAMIC&&M.sleepState===j.SLEEPING&&T.sleepState===j.AWAKE&&T.type!==j.STATIC)T.velocity.lengthSquared()+T.angularVelocity.lengthSquared()>=2*Math.pow(T.sleepSpeedLimit,2)&&(M.wakeUpAfterNarrowphase=!0);if(T.allowSleep&&T.type===j.DYNAMIC&&T.sleepState===j.SLEEPING&&M.sleepState===j.AWAKE&&M.type!==j.STATIC)M.velocity.lengthSquared()+M.angularVelocity.lengthSquared()>=2*Math.pow(M.sleepSpeedLimit,2)&&(T.wakeUpAfterNarrowphase=!0);this.collisionMatrix.set(M,T,!0),this.collisionMatrixPrevious.get(M,T)||(dr.body=T,dr.contact=O,M.dispatchEvent(dr),dr.body=M,T.dispatchEvent(dr)),this.bodyOverlapKeeper.set(M.id,T.id),this.shapeOverlapKeeper.set(F.id,_.id)}for(this.emitContactEvents(),l&&(c.makeContactConstraints=cr.now()-h,h=cr.now()),m=0;m!==n;m++){(M=r[m]).wakeUpAfterNarrowphase&&(M.wakeUp(),M.wakeUpAfterNarrowphase=!1)}for(A=p.length,m=0;m!==A;m++){var O;(O=p[m]).update();B=0;for(var R=O.equations.length;B!==R;B++){var I=O.equations[B];s.addEquation(I)}}s.solve(t,this),l&&(c.solve=cr.now()-h),s.removeAllEquations();var q=Math.pow;for(m=0;m!==n;m++){if((M=r[m]).type&u){var N=q(1-M.linearDamping,t),L=M.velocity;L.scale(N,L);var W=M.angularVelocity;if(W){var V=q(1-M.angularDamping,t);W.scale(V,W)}}}this.dispatchEvent(pr),l&&(h=cr.now());var k=this.stepnumber%(this.quatNormalizeSkip+1)==0,H=this.quatNormalizeFast;for(m=0;m!==n;m++)r[m].integrate(t,k,H);this.clearForces(),this.broadphase.dirty=!0,l&&(c.integrate=cr.now()-h),this.stepnumber+=1,this.dispatchEvent(hr);var D=!0;if(this.allowSleep)for(D=!1,m=0;m!==n;m++){(M=r[m]).sleepTick(this.time),M.sleepState!==j.SLEEPING&&(D=!0)}this.hasActiveBodies=D},e.prototype.emitContactEvents=function(){var t=this.hasAnyEventListener("beginContact"),e=this.hasAnyEventListener("endContact");if((t||e)&&this.bodyOverlapKeeper.getDiff(wr,gr),t){for(var o=0,i=wr.length;o<i;o+=2)br.bodyA=this.getBodyById(wr[o]),br.bodyB=this.getBodyById(wr[o+1]),this.dispatchEvent(br);br.bodyA=br.bodyB=null}if(e){for(o=0,i=gr.length;o<i;o+=2)xr.bodyA=this.getBodyById(gr[o]),xr.bodyB=this.getBodyById(gr[o+1]),this.dispatchEvent(xr);xr.bodyA=xr.bodyB=null}wr.length=gr.length=0;var n=this.hasAnyEventListener("beginShapeContact"),r=this.hasAnyEventListener("endShapeContact");if((n||r)&&this.shapeOverlapKeeper.getDiff(wr,gr),n){for(o=0,i=wr.length;o<i;o+=2){var s=this.getShapeById(wr[o]),a=this.getShapeById(wr[o+1]);Ar.shapeA=s,Ar.shapeB=a,s&&(Ar.bodyA=s.body),a&&(Ar.bodyB=a.body),this.dispatchEvent(Ar)}Ar.bodyA=Ar.bodyB=Ar.shapeA=Ar.shapeB=null}if(r){for(o=0,i=gr.length;o<i;o+=2){s=this.getShapeById(gr[o]),a=this.getShapeById(gr[o+1]);Br.shapeA=s,Br.shapeB=a,s&&(Br.bodyA=s.body),a&&(Br.bodyB=a.body),this.dispatchEvent(Br)}Br.bodyA=Br.bodyB=Br.shapeA=Br.shapeB=null}},e.prototype.clearForces=function(){for(var t=this.bodies,e=t.length,o=0;o!==e;o++){var i=t[o];i.force,i.torque;i.force.set(0,0,0),i.torque.set(0,0,0)}},e}(f),lr=(new h,new lt),cr=globalThis.performance||{};if(!cr.now){var ur=Date.now();cr.timing&&cr.timing.navigationStart&&(ur=cr.timing.navigationStart),cr.now=function(){return Date.now()-ur}}new s;var hr={type:"postStep"},pr={type:"preStep"},dr={type:j.COLLIDE_EVENT_NAME,body:null,contact:null},vr=[],fr=[],yr=[],mr=[],wr=[],gr=[],br={type:"beginContact",bodyA:null,bodyB:null},xr={type:"endContact",bodyA:null,bodyB:null},Ar={type:"beginShapeContact",bodyA:null,bodyB:null,shapeA:null,shapeB:null},Br={type:"endShapeContact",bodyA:null,bodyB:null,shapeA:null,shapeB:null}}}]);
|