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