!function t(e,o,i){function n(r,a){if(!o[r]){if(!e[r]){var c="function"==typeof require&&require;if(!a&&c)return c(r,!0);if(s)return s(r,!0);var h=new Error("Cannot find module '"+r+"'");throw h.code="MODULE_NOT_FOUND",h}var l=o[r]={exports:{}};e[r][0].call(l.exports,function(t){var o=e[r][1][t];return n(o||t)},l,l.exports,t,e,o,i)}return o[r].exports}for(var s="function"==typeof require&&require,r=0;r"},Slash:{key:"/",shiftKey:"?"},Backquote:{key:"`",shiftKey:"~"},BracketLeft:{key:"[",shiftKey:"{"},Backslash:{key:"\\",shiftKey:"|"},BracketRight:{key:"]",shiftKey:"}"},Quote:{key:"'",shiftKey:'"'},IntlBackslash:{key:"\\",shiftKey:"|"}};o(v,"mac",{OSLeft:{key:"Meta"},OSRight:{key:"Meta"}});var f={Esc:"Escape",Nonconvert:"NonConvert",Left:"ArrowLeft",Up:"ArrowUp",Right:"ArrowRight",Down:"ArrowDown",Del:"Delete",Menu:"ContextMenu",MediaNextTrack:"MediaTrackNext",MediaPreviousTrack:"MediaTrackPrevious",SelectMedia:"MediaSelect",HalfWidth:"Hankaku",FullWidth:"Zenkaku",RomanCharacters:"Romaji",Crsel:"CrSel",Exsel:"ExSel",Zoom:"ZoomToggle"},m=function(t,e){var o={};return Object.keys(t).forEach(function(i){var n=t[i];e in n&&(o[n[e]]=n)}),o}(p,"code");try{var w=n&&"location"in new KeyboardEvent("")}catch(t){}"KeyboardEvent"in t&&"defineProperty"in Object&&function(){function t(t,e,o){e in t||Object.defineProperty(t,e,o)}if(t(KeyboardEvent.prototype,"code",{get:function(){var t=i(this);return t?t.code:""}}),"key"in KeyboardEvent.prototype){var e=Object.getOwnPropertyDescriptor(KeyboardEvent.prototype,"key");Object.defineProperty(KeyboardEvent.prototype,"key",{get:function(){var t=e.get.call(this);return f.hasOwnProperty(t)?f[t]:t}})}t(KeyboardEvent.prototype,"key",{get:function(){var t=i(this);return t&&"key"in t?t.key:"Unidentified"}}),t(KeyboardEvent.prototype,"location",{get:function(){var t=i(this);return t&&"location"in t?t.location:s}}),t(KeyboardEvent.prototype,"locale",{get:function(){return""}})}(),"queryKeyCap"in t.KeyboardEvent||(t.KeyboardEvent.queryKeyCap=function(t,e){if(t=String(t),!m.hasOwnProperty(t))return"Undefined";if(e&&"en-us"!==String(e).toLowerCase())throw Error("Unsupported locale");var o=m[t];return o.keyCap||o.code||"Undefined"}),t.identifyKey=function(t){if(!("code"in t)){var e=i(t);t.code=e?e.code:"",t.key=e&&"key"in e?e.key:"Unidentified",t.location="location"in t?t.location:"keyLocation"in t?t.keyLocation:e&&"location"in e?e.location:s,t.locale=""}}}(window)},{}],5:[function(t,e,o){var i=t("cannon"),n=t("./src/components/math");e.exports={"dynamic-body":t("./src/components/body/dynamic-body"),"static-body":t("./src/components/body/static-body"),constraint:t("./src/components/constraint"),system:t("./src/system/physics"),registerAll:function(t){this._registered||(t=t||window.AFRAME,n.registerAll(),t.systems.physics||t.registerSystem("physics",this.system),t.components["dynamic-body"]||t.registerComponent("dynamic-body",this["dynamic-body"]),t.components["static-body"]||t.registerComponent("static-body",this["static-body"]),t.components.constraint||t.registerComponent("constraint",this.constraint),this._registered=!0)}},window.CANNON=window.CANNON||i},{"./src/components/body/dynamic-body":8,"./src/components/body/static-body":9,"./src/components/constraint":10,"./src/components/math":11,"./src/system/physics":15,cannon:17}],6:[function(t,e,o){var i=t("cannon");i.shape2mesh=function(t){for(var e=new THREE.Object3D,o=0;or.x&&(r.x=h.x),h.xr.y&&(r.y=h.y),h.yr.z&&(r.z=h.z),h.z=n.x&&e.y<=i.y&&o.y>=n.y&&e.z<=i.z&&o.z>=n.z},i.prototype.getCorners=function(t,e,o,i,n,s,r,a){var c=this.lowerBound,h=this.upperBound;t.copy(c),e.set(h.x,c.y,c.z),o.set(h.x,h.y,c.z),i.set(c.x,h.y,h.z),n.set(h.x,c.y,c.z),s.set(c.x,h.y,c.z),r.set(c.x,c.y,h.z),a.copy(h)};var r=[new n,new n,new n,new n,new n,new n,new n,new n];i.prototype.toLocalFrame=function(t,e){var o=r,i=o[0],n=o[1],s=o[2],a=o[3],c=o[4],h=o[5],l=o[6],u=o[7];this.getCorners(i,n,s,a,c,h,l,u);for(var p=0;8!==p;p++){var d=o[p];t.pointToLocal(d,d)}return e.setFromPoints(o)},i.prototype.toWorldFrame=function(t,e){var o=r,i=o[0],n=o[1],s=o[2],a=o[3],c=o[4],h=o[5],l=o[6],u=o[7];this.getCorners(i,n,s,a,c,h,l,u);for(var p=0;8!==p;p++){var d=o[p];t.pointToWorld(d,d)}return e.setFromPoints(o)},i.prototype.overlapsRay=function(t){var e=1/t._direction.x,o=1/t._direction.y,i=1/t._direction.z,n=(this.lowerBound.x-t.from.x)*e,s=(this.upperBound.x-t.from.x)*e,r=(this.lowerBound.y-t.from.y)*o,a=(this.upperBound.y-t.from.y)*o,c=(this.lowerBound.z-t.from.z)*i,h=(this.upperBound.z-t.from.z)*i,l=Math.max(Math.max(Math.min(n,s),Math.min(r,a)),Math.min(c,h)),u=Math.min(Math.min(Math.max(n,s),Math.max(r,a)),Math.max(c,h));return!(u<0)&&!(l>u)}},{"../math/Vec3":46,"../utils/Utils":69}],19:[function(t,e,o){function i(){this.matrix=[]}e.exports=i,i.prototype.get=function(t,e){if(t=t.index,(e=e.index)>t){var o=e;e=t,t=o}return this.matrix[(t*(t+1)>>1)+e-1]},i.prototype.set=function(t,e,o){if(t=t.index,(e=e.index)>t){var i=e;e=t,t=i}this.matrix[(t*(t+1)>>1)+e-1]=o?1:0},i.prototype.reset=function(){for(var t=0,e=this.matrix.length;t!==e;t++)this.matrix[t]=0},i.prototype.setNumObjects=function(t){this.matrix.length=t*(t-1)>>1}},{}],20:[function(t,e,o){function i(){this.world=null,this.useBoundingBoxes=!1,this.dirty=!0}var n=t("../objects/Body"),s=t("../math/Vec3"),r=t("../math/Quaternion");t("../shapes/Shape"),t("../shapes/Plane");e.exports=i,i.prototype.collisionPairs=function(t,e,o){throw new Error("collisionPairs not implemented for this BroadPhase class!")},i.prototype.needBroadphaseCollision=function(t,e){return 0!=(t.collisionFilterGroup&e.collisionFilterMask)&&0!=(e.collisionFilterGroup&t.collisionFilterMask)&&(0==(t.type&n.STATIC)&&t.sleepState!==n.SLEEPING||0==(e.type&n.STATIC)&&e.sleepState!==n.SLEEPING)},i.prototype.intersectionTest=function(t,e,o,i){this.useBoundingBoxes?this.doBoundingBoxBroadphase(t,e,o,i):this.doBoundingSphereBroadphase(t,e,o,i)};var a=new s;new s,new r,new s;i.prototype.doBoundingSphereBroadphase=function(t,e,o,i){var n=a;e.position.vsub(t.position,n);var s=Math.pow(t.boundingRadius+e.boundingRadius,2);n.norm2()o.norm2()},i.prototype.aabbQuery=function(t,e,o){return console.warn(".aabbQuery is not implemented in this Broadphase subclass."),[]}},{"../math/Quaternion":44,"../math/Vec3":46,"../objects/Body":47,"../shapes/Plane":58,"../shapes/Shape":59}],21:[function(t,e,o){function i(t,e,o,i,r){n.apply(this),this.nx=o||10,this.ny=i||10,this.nz=r||10,this.aabbMin=t||new s(100,100,100),this.aabbMax=e||new s(-100,-100,-100);var a=this.nx*this.ny*this.nz;if(a<=0)throw"GridBroadphase: Each dimension's n must be >0";this.bins=[],this.binLengths=[],this.bins.length=a,this.binLengths.length=a;for(var c=0;c=l&&(a=l-1),c<0?c=0:c>=u&&(c=u-1),h<0?h=0:h>=p&&(h=p-1),f<0?f=0:f>=l&&(f=l-1),m<0?m=0:m>=u&&(m=u-1),w<0?w=0:w>=p&&(w=p-1),c*=y,h*=v,f*=d,m*=y,w*=v;for(var C=a*=d;C<=f;C+=d)for(var S=c;S<=m;S+=y)for(var R=h;R<=w;R+=v){var M=C+S+R;P[M][q[M]++]=r}}for(var n=t.numObjects(),s=t.bodies,c=this.aabbMax,h=this.aabbMin,l=this.nx,u=this.ny,p=this.nz,d=u*p,y=p,v=1,f=c.x,m=c.y,w=c.z,g=h.x,x=h.y,b=h.z,E=l/(f-g),A=u/(m-x),B=p/(w-b),C=(f-g)/l,S=(m-x)/u,R=(w-b)/p,M=.5*Math.sqrt(C*C+S*S+R*R),T=r.types,z=T.SPHERE,k=T.PLANE,P=(T.BOX,T.COMPOUND,T.CONVEXPOLYHEDRON,this.bins),q=this.binLengths,L=this.bins.length,V=0;V!==L;V++)q[V]=0;for(var F=Math.ceil,h=Math.min,c=Math.max,V=0;V!==n;V++){var N=(ot=s[V]).shape;switch(N.type){case z:var I=ot.position.x,O=ot.position.y,j=ot.position.z,W=N.radius;i(I-W,O-W,j-W,I+W,O+W,j+W,ot);break;case k:N.worldNormalNeedsUpdate&&N.computeWorldNormal(ot.quaternion);var D=N.worldNormal,H=g+.5*C-ot.position.x,K=x+.5*S-ot.position.y,_=b+.5*R-ot.position.z,U=a;U.set(H,K,_);for(var G=0,X=0;G!==l;G++,X+=d,U.y=K,U.x+=C)for(var Y=0,Q=0;Y!==u;Y++,Q+=y,U.z=_,U.y+=S)for(var Z=0,J=0;Z!==p;Z++,J+=v,U.z+=R)if(U.dot(D)1)for(var et=P[V],G=0;G!==tt;G++)for(var ot=et[G],Y=0;Y!==G;Y++){var it=et[Y];this.needBroadphaseCollision(ot,it)&&this.intersectionTest(ot,it,e,o)}}this.makePairsUnique(e,o)}},{"../math/Vec3":46,"../shapes/Shape":59,"./Broadphase":20}],22:[function(t,e,o){function i(){n.apply(this)}e.exports=i;var n=t("./Broadphase"),s=t("./AABB");(i.prototype=new n).constructor=i,i.prototype.collisionPairs=function(t,e,o){var i,n,s,r,a=t.bodies,c=a.length;for(i=0;i!==c;i++)for(n=0;n!==i;n++)s=a[i],r=a[n],this.needBroadphaseCollision(s,r)&&this.intersectionTest(s,r,e,o)};new s;i.prototype.aabbQuery=function(t,e,o){o=o||[];for(var i=0;it){var o=e;e=t,t=o}return t+"-"+e in this.matrix},i.prototype.set=function(t,e,o){if(t=t.id,(e=e.id)>t){var i=e;e=t,t=i}o?this.matrix[t+"-"+e]=!0:delete this.matrix[t+"-"+e]},i.prototype.reset=function(){this.matrix={}},i.prototype.setNumObjects=function(t){}},{}],24:[function(t,e,o){function i(){this.current=[],this.previous=[]}function n(t,e){t.push((4294901760&e)>>16,65535&e)}e.exports=i,i.prototype.getKey=function(t,e){if(ei[n];)n++;if(o!==i[n]){for(e=i.length-1;e>=n;e--)i[e+1]=i[e];i[n]=o}},i.prototype.tick=function(){var t=this.current;this.current=this.previous,this.previous=t,this.current.length=0},i.prototype.getDiff=function(t,e){for(var o=this.current,i=this.previous,s=o.length,r=i.length,a=0,c=0;ci[a];)a++;h===i[a]||n(t,h)}a=0;for(c=0;co[a];)a++;o[a]===l||n(e,l)}}},{}],25:[function(t,e,o){function i(t,e){this.from=t?t.clone():new s,this.to=e?e.clone():new s,this._direction=new s,this.precision=1e-4,this.checkCollisionResponse=!0,this.skipBackfaces=!1,this.collisionFilterMask=-1,this.collisionFilterGroup=-1,this.mode=i.ANY,this.result=new c,this.hasHit=!1,this.callback=function(t){}}function n(t,e,o,i){i.vsub(e,N),o.vsub(e,d),t.vsub(e,y);var n,s,r=N.dot(N),a=N.dot(d),c=N.dot(y),h=d.dot(d),l=d.dot(y);return(n=h*c-a*l)>=0&&(s=r*l-a*c)>=0&&n+st.boundingSphereRadius)){var n=this[t.type];n&&n.call(this,t,e,o,i,t)}};new s,new s;var m=new s,w=new s,g=new s,x=new s;new s,new c;i.prototype.intersectBox=function(t,e,o,i,n){return this.intersectConvex(t.convexPolyhedronRepresentation,e,o,i,n)},i.prototype[h.types.BOX]=i.prototype.intersectBox,i.prototype.intersectPlane=function(t,e,o,i,n){var r=this.from,a=this.to,c=this._direction,h=new s(0,0,1);e.vmult(h,h);var l=new s;r.vsub(o,l);var u=l.dot(h);a.vsub(o,l);if(!(u*l.dot(h)>0||r.distanceTo(a)=0&&y<=1&&(s.lerp(r,y,p),p.vsub(o,d),d.normalize(),this.reportIntersection(d,p,n,i,-1)),this.result._shouldStop)return;v>=0&&v<=1&&(s.lerp(r,v,p),p.vsub(o,d),d.normalize(),this.reportIntersection(d,p,n,i,-1))}},i.prototype[h.types.SPHERE]=i.prototype.intersectSphere;var R=new s,M=(new s,new s,new s);i.prototype.intersectConvex=function(t,e,o,i,s,r){for(var a=R,c=M,h=r&&r.faceList||null,l=t.faces,u=t.vertices,p=t.faceNormals,d=this._direction,y=this.from,v=this.to,f=y.distanceTo(v),b=h?h.length:l.length,E=this.result,A=0;!E._shouldStop&&Af||this.reportIntersection(a,m,s,i,B)}}}}},i.prototype[h.types.CONVEXPOLYHEDRON]=i.prototype.intersectConvex;var T=new s,z=new s,k=new s,P=new s,q=new s,L=new s,V=(new l,[]),F=new a;i.prototype.intersectTrimesh=function(t,e,o,i,s,r){var c=T,h=V,l=F,u=M,p=z,d=k,y=P,v=L,f=q,b=(r&&r.faceList,t.indices),E=(t.vertices,t.faceNormals,this.from),A=this.to,B=this._direction;l.position.copy(o),l.quaternion.copy(e),a.vectorToLocalFrame(o,e,B,p),a.pointToLocalFrame(o,e,E,d),a.pointToLocalFrame(o,e,A,y),y.x*=t.scale.x,y.y*=t.scale.y,y.z*=t.scale.z,d.x*=t.scale.x,d.y*=t.scale.y,d.z*=t.scale.z,y.vsub(d,p),p.normalize();var C=d.distanceSquared(y);t.tree.rayQuery(this,l,h);for(var S=0,R=h.length;!this.result._shouldStop&&S!==R;S++){var N=h[S];t.getNormal(N,c),t.getVertex(b[3*N],w),w.vsub(d,u);var I=p.dot(c),O=c.dot(u)/I;if(!(O<0)){p.scale(O,m),m.vadd(d,m),t.getVertex(b[3*N+1],g),t.getVertex(b[3*N+2],x);var j=m.distanceSquared(d);!n(m,g,w,x)&&!n(m,w,g,x)||j>C||(a.vectorToWorldFrame(e,c,f),a.pointToWorldFrame(o,e,m,v),this.reportIntersection(f,v,s,i,N))}}h.length=0},i.prototype[h.types.TRIMESH]=i.prototype.intersectTrimesh,i.prototype.reportIntersection=function(t,e,o,n,s){var r=this.from,a=this.to,c=r.distanceTo(e),h=this.result;if(!(this.skipBackfaces&&t.dot(this._direction)>0))switch(h.hitFaceIndex=void 0!==s?s:-1,this.mode){case i.ALL:this.hasHit=!0,h.set(r,a,t,e,o,n,c),h.hasHit=!0,this.callback(h);break;case i.CLOSEST:(c=0&&!(t[n].aabb.lowerBound.x<=i.aabb.lowerBound.x);n--)t[n+1]=t[n];t[n+1]=i}return t},i.insertionSortY=function(t){for(var e=1,o=t.length;e=0&&!(t[n].aabb.lowerBound.y<=i.aabb.lowerBound.y);n--)t[n+1]=t[n];t[n+1]=i}return t},i.insertionSortZ=function(t){for(var e=1,o=t.length;e=0&&!(t[n].aabb.lowerBound.z<=i.aabb.lowerBound.z);n--)t[n+1]=t[n];t[n+1]=i}return t},i.prototype.collisionPairs=function(t,e,o){var n,s,r=this.axisList,a=r.length,c=this.axisIndex;for(this.dirty&&(this.sortList(),this.dirty=!1),n=0;n!==a;n++){var h=r[n];for(s=n+1;sv?y>f?0:2:v>f?1:2},i.prototype.aabbQuery=function(t,e,o){o=o||[],this.dirty&&(this.sortList(),this.dirty=!1);var i=this.axisIndex,n="x";1===i&&(n="y"),2===i&&(n="z");for(var s=this.axisList,r=(e.lowerBound[n],e.upperBound[n],0);r.499&&(o=2*Math.atan2(s,c),i=Math.PI/2,n=0),h<-.499&&(o=-2*Math.atan2(s,c),i=-Math.PI/2,n=0),isNaN(o)){var l=s*s,u=r*r,p=a*a;o=Math.atan2(2*r*c-2*s*a,1-2*u-2*p),i=Math.asin(2*h),n=Math.atan2(2*s*c-2*r*a,1-2*l-2*p)}break;default:throw new Error("Euler order "+e+" not supported yet.")}t.y=o,t.z=i,t.x=n},i.prototype.setFromEuler=function(t,e,o,i){i=i||"XYZ";var n=Math.cos(t/2),s=Math.cos(e/2),r=Math.cos(o/2),a=Math.sin(t/2),c=Math.sin(e/2),h=Math.sin(o/2);return"XYZ"===i?(this.x=a*s*r+n*c*h,this.y=n*c*r-a*s*h,this.z=n*s*h+a*c*r,this.w=n*s*r-a*c*h):"YXZ"===i?(this.x=a*s*r+n*c*h,this.y=n*c*r-a*s*h,this.z=n*s*h-a*c*r,this.w=n*s*r+a*c*h):"ZXY"===i?(this.x=a*s*r-n*c*h,this.y=n*c*r+a*s*h,this.z=n*s*h+a*c*r,this.w=n*s*r-a*c*h):"ZYX"===i?(this.x=a*s*r-n*c*h,this.y=n*c*r+a*s*h,this.z=n*s*h-a*c*r,this.w=n*s*r+a*c*h):"YZX"===i?(this.x=a*s*r+n*c*h,this.y=n*c*r+a*s*h,this.z=n*s*h-a*c*r,this.w=n*s*r-a*c*h):"XZY"===i&&(this.x=a*s*r-n*c*h,this.y=n*c*r-a*s*h,this.z=n*s*h+a*c*r,this.w=n*s*r+a*c*h),this},i.prototype.clone=function(){return new i(this.x,this.y,this.z,this.w)},i.prototype.slerp=function(t,e,o){o=o||new i;var n,s,r,a,c,h=this.x,l=this.y,u=this.z,p=this.w,d=t.x,y=t.y,v=t.z,f=t.w;return(s=h*d+l*y+u*v+p*f)<0&&(s=-s,d=-d,y=-y,v=-v,f=-f),1-s>1e-6?(n=Math.acos(s),r=Math.sin(n),a=Math.sin((1-e)*n)/r,c=Math.sin(e*n)/r):(a=1-e,c=e),o.x=a*h+c*d,o.y=a*l+c*y,o.z=a*u+c*v,o.w=a*p+c*f,o},i.prototype.integrate=function(t,e,o,n){n=n||new i;var s=t.x*o.x,r=t.y*o.y,a=t.z*o.z,c=this.x,h=this.y,l=this.z,u=this.w,p=.5*e;return n.x+=p*(s*u+r*l-a*h),n.y+=p*(r*u+a*c-s*l),n.z+=p*(a*u+s*h-r*c),n.w+=p*(-s*c-r*h-a*l),n}},{"./Vec3":46}],45:[function(t,e,o){function i(t){t=t||{},this.position=new n,t.position&&this.position.copy(t.position),this.quaternion=new s,t.quaternion&&this.quaternion.copy(t.quaternion)}var n=t("./Vec3"),s=t("./Quaternion");e.exports=i;var r=new s;i.pointToLocalFrame=function(t,e,o,i){i=i||new n;return o.vsub(t,i),e.conjugate(r),r.vmult(i,i),i},i.prototype.pointToLocal=function(t,e){return i.pointToLocalFrame(this.position,this.quaternion,t,e)},i.pointToWorldFrame=function(t,e,o,i){i=i||new n;return e.vmult(o,i),i.vadd(t,i),i},i.prototype.pointToWorld=function(t,e){return i.pointToWorldFrame(this.position,this.quaternion,t,e)},i.prototype.vectorToWorldFrame=function(t,e){e=e||new n;return this.quaternion.vmult(t,e),e},i.vectorToWorldFrame=function(t,e,o){return t.vmult(e,o),o},i.vectorToLocalFrame=function(t,e,o,i){i=i||new n;return e.w*=-1,e.vmult(o,i),e.w*=-1,i}},{"./Quaternion":44,"./Vec3":46}],46:[function(t,e,o){function i(t,e,o){this.x=t||0,this.y=e||0,this.z=o||0}e.exports=i;var n=t("./Mat3");i.ZERO=new i(0,0,0),i.UNIT_X=new i(1,0,0),i.UNIT_Y=new i(0,1,0),i.UNIT_Z=new i(0,0,1),i.prototype.cross=function(t,e){var o=t.x,n=t.y,s=t.z,r=this.x,a=this.y,c=this.z;return e=e||new i,e.x=a*s-c*n,e.y=c*o-r*s,e.z=r*n-a*o,e},i.prototype.set=function(t,e,o){return this.x=t,this.y=e,this.z=o,this},i.prototype.setZero=function(){this.x=this.y=this.z=0},i.prototype.vadd=function(t,e){if(!e)return new i(this.x+t.x,this.y+t.y,this.z+t.z);e.x=t.x+this.x,e.y=t.y+this.y,e.z=t.z+this.z},i.prototype.vsub=function(t,e){if(!e)return new i(this.x-t.x,this.y-t.y,this.z-t.z);e.x=this.x-t.x,e.y=this.y-t.y,e.z=this.z-t.z},i.prototype.crossmat=function(){return new n([0,-this.z,this.y,this.z,0,-this.x,-this.y,this.x,0])},i.prototype.normalize=function(){var t=this.x,e=this.y,o=this.z,i=Math.sqrt(t*t+e*e+o*o);if(i>0){var n=1/i;this.x*=n,this.y*=n,this.z*=n}else this.x=0,this.y=0,this.z=0;return i},i.prototype.unit=function(t){t=t||new i;var e=this.x,o=this.y,n=this.z,s=Math.sqrt(e*e+o*o+n*n);return s>0?(s=1/s,t.x=e*s,t.y=o*s,t.z=n*s):(t.x=1,t.y=0,t.z=0),t},i.prototype.norm=function(){var t=this.x,e=this.y,o=this.z;return Math.sqrt(t*t+e*e+o*o)},i.prototype.length=i.prototype.norm,i.prototype.norm2=function(){return this.dot(this)},i.prototype.lengthSquared=i.prototype.norm2,i.prototype.distanceTo=function(t){var e=this.x,o=this.y,i=this.z,n=t.x,s=t.y,r=t.z;return Math.sqrt((n-e)*(n-e)+(s-o)*(s-o)+(r-i)*(r-i))},i.prototype.distanceSquared=function(t){var e=this.x,o=this.y,i=this.z,n=t.x,s=t.y,r=t.z;return(n-e)*(n-e)+(s-o)*(s-o)+(r-i)*(r-i)},i.prototype.mult=function(t,e){e=e||new i;var o=this.x,n=this.y,s=this.z;return e.x=t*o,e.y=t*n,e.z=t*s,e},i.prototype.vmul=function(t,e){return e=e||new i,e.x=t.x*this.x,e.y=t.y*this.y,e.z=t.z*this.z,e},i.prototype.scale=i.prototype.mult,i.prototype.addScaledVector=function(t,e,o){return o=o||new i,o.x=this.x+t*e.x,o.y=this.y+t*e.y,o.z=this.z+t*e.z,o},i.prototype.dot=function(t){return this.x*t.x+this.y*t.y+this.z*t.z},i.prototype.isZero=function(){return 0===this.x&&0===this.y&&0===this.z},i.prototype.negate=function(t){return t=t||new i,t.x=-this.x,t.y=-this.y,t.z=-this.z,t};var s=new i,r=new i;i.prototype.tangents=function(t,e){var o=this.norm();if(o>0){var i=s,n=1/o;i.set(this.x*n,this.y*n,this.z*n);var a=r;Math.abs(i.x)<.9?(a.set(1,0,0),i.cross(a,t)):(a.set(0,1,0),i.cross(a,t)),i.cross(t,e)}else t.set(1,0,0),e.set(0,1,0)},i.prototype.toString=function(){return this.x+","+this.y+","+this.z},i.prototype.toArray=function(){return[this.x,this.y,this.z]},i.prototype.copy=function(t){return this.x=t.x,this.y=t.y,this.z=t.z,this},i.prototype.lerp=function(t,e,o){var i=this.x,n=this.y,s=this.z;o.x=i+(t.x-i)*e,o.y=n+(t.y-n)*e,o.z=s+(t.z-s)*e},i.prototype.almostEquals=function(t,e){return void 0===e&&(e=1e-6),!(Math.abs(this.x-t.x)>e||Math.abs(this.y-t.y)>e||Math.abs(this.z-t.z)>e)},i.prototype.almostZero=function(t){return void 0===t&&(t=1e-6),!(Math.abs(this.x)>t||Math.abs(this.y)>t||Math.abs(this.z)>t)};var a=new i;i.prototype.isAntiparallelTo=function(t,e){return this.negate(a),a.almostEquals(t,e)},i.prototype.clone=function(){return new i(this.x,this.y,this.z)}},{"./Mat3":43}],47:[function(t,e,o){function i(t){t=t||{},n.apply(this),this.id=i.idCounter++,this.world=null,this.preStep=null,this.postStep=null,this.vlambda=new s,this.collisionFilterGroup="number"==typeof t.collisionFilterGroup?t.collisionFilterGroup:1,this.collisionFilterMask="number"==typeof t.collisionFilterMask?t.collisionFilterMask:1,this.collisionResponse=!0,this.position=new s,this.previousPosition=new s,this.interpolatedPosition=new s,this.initPosition=new s,t.position&&(this.position.copy(t.position),this.previousPosition.copy(t.position),this.interpolatedPosition.copy(t.position),this.initPosition.copy(t.position)),this.velocity=new s,t.velocity&&this.velocity.copy(t.velocity),this.initVelocity=new s,this.force=new s;var e="number"==typeof t.mass?t.mass:0;this.mass=e,this.invMass=e>0?1/e:0,this.material=t.material||null,this.linearDamping="number"==typeof t.linearDamping?t.linearDamping:.01,this.type=e<=0?i.STATIC:i.DYNAMIC,typeof t.type==typeof i.STATIC&&(this.type=t.type),this.allowSleep=void 0===t.allowSleep||t.allowSleep,this.sleepState=0,this.sleepSpeedLimit=void 0!==t.sleepSpeedLimit?t.sleepSpeedLimit:.1,this.sleepTimeLimit=void 0!==t.sleepTimeLimit?t.sleepTimeLimit:1,this.timeLastSleepy=0,this._wakeUpAfterNarrowphase=!1,this.torque=new s,this.quaternion=new a,this.initQuaternion=new a,this.previousQuaternion=new a,this.interpolatedQuaternion=new a,t.quaternion&&(this.quaternion.copy(t.quaternion),this.initQuaternion.copy(t.quaternion),this.previousQuaternion.copy(t.quaternion),this.interpolatedQuaternion.copy(t.quaternion)),this.angularVelocity=new s,t.angularVelocity&&this.angularVelocity.copy(t.angularVelocity),this.initAngularVelocity=new s,this.shapes=[],this.shapeOffsets=[],this.shapeOrientations=[],this.inertia=new s,this.invInertia=new s,this.invInertiaWorld=new r,this.invMassSolve=0,this.invInertiaSolve=new s,this.invInertiaWorldSolve=new r,this.fixedRotation=void 0!==t.fixedRotation&&t.fixedRotation,this.angularDamping=void 0!==t.angularDamping?t.angularDamping:.01,this.linearFactor=new s(1,1,1),t.linearFactor&&this.linearFactor.copy(t.linearFactor),this.angularFactor=new s(1,1,1),t.angularFactor&&this.angularFactor.copy(t.angularFactor),this.aabb=new c,this.aabbNeedsUpdate=!0,this.wlambda=new s,t.shape&&this.addShape(t.shape),this.updateMassProperties()}e.exports=i;var n=t("../utils/EventTarget"),s=(t("../shapes/Shape"),t("../math/Vec3")),r=t("../math/Mat3"),a=t("../math/Quaternion"),c=(t("../material/Material"),t("../collision/AABB")),h=t("../shapes/Box");(i.prototype=new n).constructor=i,i.COLLIDE_EVENT_NAME="collide",i.DYNAMIC=1,i.STATIC=2,i.KINEMATIC=4,i.AWAKE=0,i.SLEEPY=1,i.SLEEPING=2,i.idCounter=0,i.wakeupEvent={type:"wakeup"},i.prototype.wakeUp=function(){var t=this.sleepState;this.sleepState=0,this._wakeUpAfterNarrowphase=!1,t===i.SLEEPING&&this.dispatchEvent(i.wakeupEvent)},i.prototype.sleep=function(){this.sleepState=i.SLEEPING,this.velocity.set(0,0,0),this.angularVelocity.set(0,0,0),this._wakeUpAfterNarrowphase=!1},i.sleepyEvent={type:"sleepy"},i.sleepEvent={type:"sleep"},i.prototype.sleepTick=function(t){if(this.allowSleep){var e=this.sleepState,o=this.velocity.norm2()+this.angularVelocity.norm2(),n=Math.pow(this.sleepSpeedLimit,2);e===i.AWAKE&&on?this.wakeUp():e===i.SLEEPY&&t-this.timeLastSleepy>this.sleepTimeLimit&&(this.sleep(),this.dispatchEvent(i.sleepEvent))}},i.prototype.updateSolveMassProperties=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))},i.prototype.pointToLocalFrame=function(t,e){e=e||new s;return t.vsub(this.position,e),this.quaternion.conjugate().vmult(e,e),e},i.prototype.vectorToLocalFrame=function(t,e){e=e||new s;return this.quaternion.conjugate().vmult(t,e),e},i.prototype.pointToWorldFrame=function(t,e){e=e||new s;return this.quaternion.vmult(t,e),e.vadd(this.position,e),e},i.prototype.vectorToWorldFrame=function(t,e){e=e||new s;return this.quaternion.vmult(t,e),e};var l=new s,u=new a;i.prototype.addShape=function(t,e,o){var i=new s,n=new a;return e&&i.copy(e),o&&n.copy(o),this.shapes.push(t),this.shapeOffsets.push(i),this.shapeOrientations.push(n),this.updateMassProperties(),this.updateBoundingRadius(),this.aabbNeedsUpdate=!0,t.body=this,this},i.prototype.updateBoundingRadius=function(){for(var t=this.shapes,e=this.shapeOffsets,o=t.length,i=0,n=0;n!==o;n++){var s=t[n];s.updateBoundingSphereRadius();var r=e[n].norm(),a=s.boundingSphereRadius;r+a>i&&(i=r+a)}this.boundingRadius=i};var p=new c;i.prototype.computeAABB=function(){for(var t=this.shapes,e=this.shapeOffsets,o=this.shapeOrientations,i=t.length,n=l,s=u,r=this.quaternion,a=this.aabb,c=p,h=0;h!==i;h++){var d=t[h];r.vmult(e[h],n),n.vadd(this.position,n),o[h].mult(r,s),d.calculateWorldAABB(n,s,c.lowerBound,c.upperBound),0===h?a.copy(c):a.extend(c)}this.aabbNeedsUpdate=!1};var d=new r,y=new r;new r;i.prototype.updateInertiaWorld=function(t){var e=this.invInertia;if(e.x!==e.y||e.y!==e.z||t){var o=d,i=y;o.setRotationFromQuaternion(this.quaternion),o.transpose(i),o.scale(e,o),o.mmult(i,this.invInertiaWorld)}else;};new s;var v=new s;i.prototype.applyForce=function(t,e){if(this.type===i.DYNAMIC){var o=v;e.cross(t,o),this.force.vadd(t,this.force),this.torque.vadd(o,this.torque)}};var f=new s,m=new s;i.prototype.applyLocalForce=function(t,e){if(this.type===i.DYNAMIC){var o=f,n=m;this.vectorToWorldFrame(t,o),this.vectorToWorldFrame(e,n),this.applyForce(o,n)}};new s;var w=new s,g=new s;i.prototype.applyImpulse=function(t,e){if(this.type===i.DYNAMIC){var o=e,n=w;n.copy(t),n.mult(this.invMass,n),this.velocity.vadd(n,this.velocity);var s=g;o.cross(t,s),this.invInertiaWorld.vmult(s,s),this.angularVelocity.vadd(s,this.angularVelocity)}};var x=new s,b=new s;i.prototype.applyLocalImpulse=function(t,e){if(this.type===i.DYNAMIC){var o=x,n=b;this.vectorToWorldFrame(t,o),this.vectorToWorldFrame(e,n),this.applyImpulse(o,n)}};var E=new s;i.prototype.updateMassProperties=function(){var t=E;this.invMass=this.mass>0?1/this.mass:0;var e=this.inertia,o=this.fixedRotation;this.computeAABB(),t.set((this.aabb.upperBound.x-this.aabb.lowerBound.x)/2,(this.aabb.upperBound.y-this.aabb.lowerBound.y)/2,(this.aabb.upperBound.z-this.aabb.lowerBound.z)/2),h.calculateInertia(t,this.mass,e),this.invInertia.set(e.x>0&&!o?1/e.x:0,e.y>0&&!o?1/e.y:0,e.z>0&&!o?1/e.z:0),this.updateInertiaWorld(!0)},i.prototype.getVelocityAtWorldPoint=function(t,e){var o=new s;return t.vsub(this.position,o),this.angularVelocity.cross(o,e),this.velocity.vadd(e,e),e};new s,new s,new a,new a;i.prototype.integrate=function(t,e,o){if(this.previousPosition.copy(this.position),this.previousQuaternion.copy(this.quaternion),(this.type===i.DYNAMIC||this.type===i.KINEMATIC)&&this.sleepState!==i.SLEEPING){var n=this.velocity,s=this.angularVelocity,r=this.position,a=this.force,c=this.torque,h=this.quaternion,l=this.invMass,u=this.invInertiaWorld,p=this.linearFactor,d=l*t;n.x+=a.x*d*p.x,n.y+=a.y*d*p.y,n.z+=a.z*d*p.z;var y=u.elements,v=this.angularFactor,f=c.x*v.x,m=c.y*v.y,w=c.z*v.z;s.x+=t*(y[0]*f+y[1]*m+y[2]*w),s.y+=t*(y[3]*f+y[4]*m+y[5]*w),s.z+=t*(y[6]*f+y[7]*m+y[8]*w),r.x+=n.x*t,r.y+=n.y*t,r.z+=n.z*t,h.integrate(this.angularVelocity,t,this.angularFactor,h),e&&(o?h.normalizeFast():h.normalize()),this.aabbNeedsUpdate=!0,this.updateInertiaWorld()}}},{"../collision/AABB":18,"../material/Material":41,"../math/Mat3":43,"../math/Quaternion":44,"../math/Vec3":46,"../shapes/Box":53,"../shapes/Shape":59,"../utils/EventTarget":65}],48:[function(t,e,o){function i(t){this.chassisBody=t.chassisBody,this.wheelInfos=[],this.sliding=!1,this.world=null,this.indexRightAxis=void 0!==t.indexRightAxis?t.indexRightAxis:1,this.indexForwardAxis=void 0!==t.indexForwardAxis?t.indexForwardAxis:0,this.indexUpAxis=void 0!==t.indexUpAxis?t.indexUpAxis:2}function n(t,e,o){var i=b,n=E,s=A,r=B;return e.vsub(t.position,i),i.cross(o,n),t.invInertiaWorld.vmult(n,r),r.cross(i,s),t.invMass+o.dot(s)}t("./Body");var s=t("../math/Vec3"),r=t("../math/Quaternion"),a=(t("../collision/RaycastResult"),t("../collision/Ray")),c=t("../objects/WheelInfo");e.exports=i;new s,new s,new s;var h=new s,l=new s,u=new s;new a;i.prototype.addWheel=function(t){var e=new c(t=t||{}),o=this.wheelInfos.length;return this.wheelInfos.push(e),o},i.prototype.setSteeringValue=function(t,e){this.wheelInfos[e].steering=t};new s;i.prototype.applyEngineForce=function(t,e){this.wheelInfos[e].engineForce=t},i.prototype.setBrake=function(t,e){this.wheelInfos[e].brake=t},i.prototype.addToWorld=function(t){this.constraints;t.addBody(this.chassisBody);var e=this;this.preStepCallback=function(){e.updateVehicle(t.dt)},t.addEventListener("preStep",this.preStepCallback),this.world=t},i.prototype.getVehicleAxisWorld=function(t,e){e.set(0===t?1:0,1===t?1:0,2===t?1:0),this.chassisBody.vectorToWorldFrame(e,e)},i.prototype.updateVehicle=function(t){for(var e=this.wheelInfos,o=e.length,i=this.chassisBody,n=0;nd.maxSuspensionForce&&(h=d.maxSuspensionForce),d.raycastResult.hitNormalWorld.scale(h*t,a),d.raycastResult.hitPointWorld.vsub(i.position,c),i.applyImpulse(a,c)}this.updateFriction(t);var l=new s,u=new s,p=new s;for(n=0;n0?1:-1)*d.customSlidingRotationalSpeed*t),Math.abs(d.brake)>Math.abs(d.engineForce)&&(d.deltaRotation=0),d.rotation+=d.deltaRotation,d.deltaRotation*=.99}},i.prototype.updateSuspension=function(t){for(var e=this.chassisBody.mass,o=this.wheelInfos,i=o.length,n=0;nv&&(t.suspensionLength=v,t.raycastResult.reset());var f=t.raycastResult.hitNormalWorld.dot(t.directionWorld),m=new s;i.getVelocityAtWorldPoint(t.raycastResult.hitPointWorld,m);var w=t.raycastResult.hitNormalWorld.dot(m);if(f>=-.1)t.suspensionRelativeVelocity=0,t.clippedInvContactDotSuspension=10;else{var g=-1/f;t.suspensionRelativeVelocity=w*g,t.clippedInvContactDotSuspension=g}}else t.suspensionLength=t.suspensionRestLength+0*t.maxSuspensionTravel,t.suspensionRelativeVelocity=0,t.directionWorld.scale(-1,t.raycastResult.hitNormalWorld),t.clippedInvContactDotSuspension=1;return n},i.prototype.updateWheelTransformWorld=function(t){t.isInContact=!1;var e=this.chassisBody;e.pointToWorldFrame(t.chassisConnectionPointLocal,t.chassisConnectionPointWorld),e.vectorToWorldFrame(t.directionLocal,t.directionWorld),e.vectorToWorldFrame(t.axleLocal,t.axleWorld)},i.prototype.updateWheelTransform=function(t){var e=h,o=l,i=u,n=this.wheelInfos[t];this.updateWheelTransformWorld(n),n.directionLocal.scale(-1,e),o.copy(n.axleLocal),e.cross(o,i),i.normalize(),o.normalize();var s=n.steering,a=new r;a.setFromAxisAngle(e,s);var c=new r;c.setFromAxisAngle(o,n.rotation);var p=n.worldTransform.quaternion;this.chassisBody.quaternion.mult(a,p),p.mult(c,p),p.normalize();var d=n.worldTransform.position;d.copy(n.directionWorld),d.scale(n.suspensionLength,d),d.vadd(n.chassisConnectionPointWorld,d)};var y=[new s(1,0,0),new s(0,1,0),new s(0,0,1)];i.prototype.getWheelTransformWorld=function(t){return this.wheelInfos[t].worldTransform};var v=new s,f=[],m=[];i.prototype.updateFriction=function(t){for(var e=v,o=this.wheelInfos,i=o.length,r=this.chassisBody,a=m,c=f,h=0;h1.1)return 0;var r=C,a=S,c=R;return t.getVelocityAtWorldPoint(e,r),o.getVelocityAtWorldPoint(i,a),r.vsub(a,c),-.2*n.dot(c)*(1/(t.invMass+o.invMass))}(r,P.raycastResult.hitPointWorld,d,P.raycastResult.hitPointWorld,l),P.sideImpulse*=1}}this.sliding=!1;for(h=0;hB){this.sliding=!0,P.sliding=!0;var k=A/Math.sqrt(z);P.skidInfo*=k}}}if(this.sliding)for(h=0;hthis.particles.length&&this.neighbors.pop())};var s=new n;i.prototype.getNeighbors=function(t,e){for(var o=this.particles.length,i=t.id,n=this.smoothingRadius*this.smoothingRadius,r=s,a=0;a!==o;a++){var c=this.particles[a];c.position.vsub(t.position,r),i!==c.id&&r.norm2()=-.1)this.suspensionRelativeVelocity=0,this.clippedInvContactDotSuspension=10;else{var n=-1/o;this.suspensionRelativeVelocity=i*n,this.clippedInvContactDotSuspension=n}}else e.suspensionLength=this.suspensionRestLength,this.suspensionRelativeVelocity=0,e.directionWorld.scale(-1,e.hitNormalWorld),this.clippedInvContactDotSuspension=1}},{"../collision/RaycastResult":26,"../math/Transform":45,"../math/Vec3":46,"../utils/Utils":69}],53:[function(t,e,o){function i(t){n.call(this),this.type=n.types.BOX,this.halfExtents=t,this.convexPolyhedronRepresentation=null,this.updateConvexPolyhedronRepresentation(),this.updateBoundingSphereRadius()}e.exports=i;var n=t("./Shape"),s=t("../math/Vec3"),r=t("./ConvexPolyhedron");(i.prototype=new n).constructor=i,i.prototype.updateConvexPolyhedronRepresentation=function(){var t=this.halfExtents.x,e=this.halfExtents.y,o=this.halfExtents.z,i=s,n=[new i(-t,-e,-o),new i(t,-e,-o),new i(t,e,-o),new i(-t,e,-o),new i(-t,-e,o),new i(t,-e,o),new i(t,e,o),new i(-t,e,o)],a=(new i(0,0,1),new i(0,1,0),new i(1,0,0),new r(n,[[3,2,1,0],[4,5,6,7],[5,4,0,1],[2,3,7,6],[0,4,7,3],[1,2,6,5]]));this.convexPolyhedronRepresentation=a,a.material=this.material},i.prototype.calculateLocalInertia=function(t,e){return e=e||new s,i.calculateInertia(this.halfExtents,t,e),e},i.calculateInertia=function(t,e,o){var i=t;o.x=1/12*e*(2*i.y*2*i.y+2*i.z*2*i.z),o.y=1/12*e*(2*i.x*2*i.x+2*i.z*2*i.z),o.z=1/12*e*(2*i.y*2*i.y+2*i.x*2*i.x)},i.prototype.getSideNormals=function(t,e){var o=t,i=this.halfExtents;if(o[0].set(i.x,0,0),o[1].set(0,i.y,0),o[2].set(0,0,i.z),o[3].set(-i.x,0,0),o[4].set(0,-i.y,0),o[5].set(0,0,-i.z),void 0!==e)for(var n=0;n!==o.length;n++)e.vmult(o[n],o[n]);return o},i.prototype.volume=function(){return 8*this.halfExtents.x*this.halfExtents.y*this.halfExtents.z},i.prototype.updateBoundingSphereRadius=function(){this.boundingSphereRadius=this.halfExtents.norm()};var a=new s;new s;i.prototype.forEachWorldCorner=function(t,e,o){for(var i=this.halfExtents,n=[[i.x,i.y,i.z],[-i.x,i.y,i.z],[-i.x,-i.y,i.z],[-i.x,-i.y,-i.z],[i.x,-i.y,-i.z],[i.x,i.y,-i.z],[-i.x,i.y,-i.z],[i.x,-i.y,i.z]],s=0;si.x&&(i.x=a),h>i.y&&(i.y=h),l>i.z&&(i.z=l),ad&&(d=v,p=y)}for(var f=[],m=o.faces[p],w=m.length,g=0;g=0&&this.clipFaceAgainstHull(r,t,e,f,a,c,h)};var u=new s,p=new s,d=new s,y=new s,v=new s,f=new s;i.prototype.findSeparatingAxis=function(t,e,o,i,n,s,r,a){var c=u,h=p,l=d,m=y,w=v,g=f,x=Number.MAX_VALUE,b=this;if(b.uniqueAxes)for(A=0;A!==b.uniqueAxes.length;A++){o.vmult(b.uniqueAxes[A],c);if(!1===(S=b.testSepAxis(c,t,e,o,i,n)))return!1;S0&&s.negate(s),!0};var m=[],w=[];i.prototype.testSepAxis=function(t,e,o,n,s,r){i.project(this,t,o,n,m),i.project(e,t,s,r,w);var a=m[0],c=m[1],h=w[0],l=w[1];if(ae&&(e=n)}this.maxValue=e},i.prototype.setHeightValueAtIndex=function(t,e,o){this.data[t][e]=o,this.clearCachedConvexTrianglePillar(t,e,!1),t>0&&(this.clearCachedConvexTrianglePillar(t-1,e,!0),this.clearCachedConvexTrianglePillar(t-1,e,!1)),e>0&&(this.clearCachedConvexTrianglePillar(t,e-1,!0),this.clearCachedConvexTrianglePillar(t,e-1,!1)),e>0&&t>0&&this.clearCachedConvexTrianglePillar(t-1,e-1,!0)},i.prototype.getRectMinMax=function(t,e,o,i,n){n=n||[];for(var s=this.data,r=this.minValue,a=t;a<=o;a++)for(var c=e;c<=i;c++){var h=s[a][c];h>r&&(r=h)}n[0]=this.minValue,n[1]=r},i.prototype.getIndexOfPosition=function(t,e,o,i){var n=this.elementSize,s=this.data,r=Math.floor(t/n),a=Math.floor(e/n);return o[0]=r,o[1]=a,i&&(r<0&&(r=0),a<0&&(a=0),r>=s.length-1&&(r=s.length-1),a>=s[0].length-1&&(a=s[0].length-1)),!(r<0||a<0||r>=s.length-1||a>=s[0].length-1)};var c=[],h=new r,l=new r,u=new r,p=new r;i.prototype.getTriangleAt=function(t,e,o,i,n,s){var r=c;this.getIndexOfPosition(t,e,r,o);var a=r[0],h=r[1],l=this.data;o&&(a=Math.min(l.length-2,Math.max(0,a)),h=Math.min(l[0].length-2,Math.max(0,h)));var u=this.elementSize,p=Math.pow(t/u-a,2)+Math.pow(e/u-h,2)>Math.pow(t/u-(a+1),2)+Math.pow(e/u-(h+1),2);return this.getTriangle(a,h,p,i,n,s),p};var d=new r,y=new r,v=new r,f=new r,m=new r;i.prototype.getNormalAt=function(t,e,o,i){var n=d,s=y,r=v,a=f,c=m;this.getTriangleAt(t,e,o,n,s,r),s.vsub(n,a),r.vsub(n,c),a.cross(c,i),i.normalize()},i.prototype.getAabbAtIndex=function(t,e,o){var i=this.data,n=this.elementSize;o.lowerBound.set(t*n,e*n,i[t][e]),o.upperBound.set((t+1)*n,(e+1)*n,i[t+1][e+1])},i.prototype.getHeightAt=function(t,e,o){var i=this.data,n=l,s=u,r=p,a=c;this.getIndexOfPosition(t,e,a,o);var d=a[0],y=a[1];o&&(d=Math.min(i.length-2,Math.max(0,d)),y=Math.min(i[0].length-2,Math.max(0,y)));var v=this.getTriangleAt(t,e,o,n,s,r);!function(t,e,o,i,n,s,r,a,c){c.x=((s-a)*(t-r)+(r-n)*(e-a))/((s-a)*(o-r)+(r-n)*(i-a)),c.y=((a-i)*(t-r)+(o-r)*(e-a))/((s-a)*(o-r)+(r-n)*(i-a)),c.z=1-c.x-c.y}(t,e,n.x,n.y,s.x,s.y,r.x,r.y,h);var f=h;return v?i[d+1][y+1]*f.x+i[d][y+1]*f.y+i[d+1][y]*f.z:i[d][y]*f.x+i[d+1][y]*f.y+i[d][y+1]*f.z},i.prototype.getCacheConvexTrianglePillarKey=function(t,e,o){return t+"_"+e+"_"+(o?1:0)},i.prototype.getCachedConvexTrianglePillar=function(t,e,o){return this._cachedPillars[this.getCacheConvexTrianglePillarKey(t,e,o)]},i.prototype.setCachedConvexTrianglePillar=function(t,e,o,i,n){this._cachedPillars[this.getCacheConvexTrianglePillarKey(t,e,o)]={convex:i,offset:n}},i.prototype.clearCachedConvexTrianglePillar=function(t,e,o){delete this._cachedPillars[this.getCacheConvexTrianglePillarKey(t,e,o)]},i.prototype.getTriangle=function(t,e,o,i,n,s){var r=this.data,a=this.elementSize;o?(i.set((t+1)*a,(e+1)*a,r[t+1][e+1]),n.set(t*a,(e+1)*a,r[t][e+1]),s.set((t+1)*a,e*a,r[t+1][e])):(i.set(t*a,e*a,r[t][e]),n.set((t+1)*a,e*a,r[t+1][e]),s.set(t*a,(e+1)*a,r[t][e+1]))},i.prototype.getConvexTrianglePillar=function(t,e,o){var i=this.pillarConvex,n=this.pillarOffset;if(this.cacheEnabled){if(a=this.getCachedConvexTrianglePillar(t,e,o))return this.pillarConvex=a.convex,void(this.pillarOffset=a.offset);i=new s,n=new r,this.pillarConvex=i,this.pillarOffset=n}var a=this.data,c=this.elementSize,h=i.faces;i.vertices.length=6;for(l=0;l<6;l++)i.vertices[l]||(i.vertices[l]=new r);h.length=5;for(var l=0;l<5;l++)h[l]||(h[l]=[]);var u=i.vertices,p=(Math.min(a[t][e],a[t+1][e],a[t][e+1],a[t+1][e+1])-this.minValue)/2+this.minValue;o?(n.set((t+.75)*c,(e+.75)*c,p),u[0].set(.25*c,.25*c,a[t+1][e+1]-p),u[1].set(-.75*c,.25*c,a[t][e+1]-p),u[2].set(.25*c,-.75*c,a[t+1][e]-p),u[3].set(.25*c,.25*c,-p-1),u[4].set(-.75*c,.25*c,-p-1),u[5].set(.25*c,-.75*c,-p-1),h[0][0]=0,h[0][1]=1,h[0][2]=2,h[1][0]=5,h[1][1]=4,h[1][2]=3,h[2][0]=2,h[2][1]=5,h[2][2]=3,h[2][3]=0,h[3][0]=3,h[3][1]=4,h[3][2]=1,h[3][3]=0,h[4][0]=1,h[4][1]=4,h[4][2]=5,h[4][3]=2):(n.set((t+.25)*c,(e+.25)*c,p),u[0].set(-.25*c,-.25*c,a[t][e]-p),u[1].set(.75*c,-.25*c,a[t+1][e]-p),u[2].set(-.25*c,.75*c,a[t][e+1]-p),u[3].set(-.25*c,-.25*c,-p-1),u[4].set(.75*c,-.25*c,-p-1),u[5].set(-.25*c,.75*c,-p-1),h[0][0]=0,h[0][1]=1,h[0][2]=2,h[1][0]=5,h[1][1]=4,h[1][2]=3,h[2][0]=0,h[2][1]=2,h[2][2]=5,h[2][3]=3,h[3][0]=1,h[3][1]=0,h[3][2]=3,h[3][3]=4,h[4][0]=4,h[4][1]=5,h[4][2]=2,h[4][3]=1),i.computeNormals(),i.computeEdges(),i.updateBoundingSphereRadius(),this.setCachedConvexTrianglePillar(t,e,o,i,n)},i.prototype.calculateLocalInertia=function(t,e){return(e=e||new r).set(0,0,0),e},i.prototype.volume=function(){return Number.MAX_VALUE},i.prototype.calculateWorldAABB=function(t,e,o,i){o.set(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE),i.set(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE)},i.prototype.updateBoundingSphereRadius=function(){var t=this.data,e=this.elementSize;this.boundingSphereRadius=new r(t.length*e,t[0].length*e,Math.max(Math.abs(this.maxValue),Math.abs(this.minValue))).norm()},i.prototype.setHeightsFromImage=function(t,e){var o=document.createElement("canvas");o.width=t.width,o.height=t.height;var i=o.getContext("2d");i.drawImage(t,0,0);var n=i.getImageData(0,0,t.width,t.height),s=this.data;s.length=0,this.elementSize=Math.abs(e.x)/n.width;for(var r=0;ro.x&&(o.x=n.x),n.yo.y&&(o.y=n.y),n.zo.z&&(o.z=n.z)},i.prototype.updateAABB=function(){this.computeLocalAABB(this.aabb)},i.prototype.updateBoundingSphereRadius=function(){for(var t=0,e=this.vertices,o=new s,i=0,n=e.length/3;i!==n;i++){this.getVertex(i,o);var r=o.norm2();r>t&&(t=r)}this.boundingSphereRadius=Math.sqrt(t)};new s;var x=new r,b=new a;i.prototype.calculateWorldAABB=function(t,e,o,i){var n=x,s=b;n.position=t,n.quaternion=e,this.aabb.toWorldFrame(n,s),o.copy(s.lowerBound),i.copy(s.upperBound)},i.prototype.volume=function(){return 4*Math.PI*this.boundingSphereRadius/3},i.createTorus=function(t,e,o,n,s){t=t||1,e=e||.5,o=o||8,n=n||6,s=s||2*Math.PI;for(var r=[],a=[],c=0;c<=o;c++)for(y=0;y<=n;y++){var h=y/n*s,l=c/o*Math.PI*2,u=(t+e*Math.cos(l))*Math.cos(h),p=(t+e*Math.cos(l))*Math.sin(h),d=e*Math.sin(l);r.push(u,p,d)}for(c=1;c<=o;c++)for(var y=1;y<=n;y++){var v=(n+1)*c+y-1,f=(n+1)*(c-1)+y-1,m=(n+1)*(c-1)+y,w=(n+1)*c+y;a.push(v,f,w),a.push(f,m,w)}return new i(r,a)}},{"../collision/AABB":18,"../math/Quaternion":44,"../math/Transform":45,"../math/Vec3":46,"../utils/Octree":66,"./Shape":59}],62:[function(t,e,o){function i(){n.call(this),this.iterations=10,this.tolerance=1e-7}e.exports=i;t("../math/Vec3"),t("../math/Quaternion");var n=t("./Solver"),s=[],r=[],a=[];(i.prototype=new n).solve=function(t,e){var o,i,n,c,h,l=0,u=this.iterations,p=this.tolerance*this.tolerance,d=this.equations,y=d.length,v=e.bodies,f=v.length,m=t;if(0!==y)for(C=0;C!==f;C++)v[C].updateSolveMassProperties();var w=r,g=a,x=s;w.length=y,g.length=y,x.length=y;for(C=0;C!==y;C++){B=d[C];x[C]=0,g[C]=B.computeB(m),w[C]=1/B.computeC()}if(0!==y){for(C=0;C!==f;C++){var b=(S=v[C]).vlambda,E=S.wlambda;b.set(0,0,0),E.set(0,0,0)}for(l=0;l!==u;l++){c=0;for(var A=0;A!==y;A++){var B=d[A];o=g[A],i=w[A],(h=x[A])+(n=i*(o-B.computeGWlambda()-B.eps*h))B.maxForce&&(n=B.maxForce-h),x[A]+=n,c+=n>0?n:-n,B.addToWlambda(n)}if(c*c=0;o--)e.children[o].data.length||e.children.splice(o,1);Array.prototype.push.apply(t,e.children)}}},{"../collision/AABB":18,"../math/Vec3":46}],67:[function(t,e,o){function i(){this.objects=[],this.type=Object}e.exports=i,i.prototype.release=function(){for(var t=arguments.length,e=0;e!==t;e++)this.objects.push(arguments[e]);return this},i.prototype.get=function(){return 0===this.objects.length?this.constructObject():this.objects.pop()},i.prototype.constructObject=function(){throw new Error("constructObject() not implemented in this Pool subclass yet!")},i.prototype.resize=function(t){for(var e=this.objects;e.length>t;)e.pop();for(;e.lengthe){var o=e;e=t,t=o}return this.data[t+"-"+e]},i.prototype.set=function(t,e,o){if(t>e){var i=e;e=t,t=i}var n=t+"-"+e;this.get(t,e)||this.data.keys.push(n),this.data[n]=o},i.prototype.reset=function(){for(var t=this.data,e=t.keys;e.length>0;){delete t[e.pop()]}}},{}],69:[function(t,e,o){function i(){}e.exports=i,i.defaults=function(t,e){t=t||{};for(var o in e)o in t||(t[o]=e[o]);return t}},{}],70:[function(t,e,o){function i(){s.call(this),this.type=n}e.exports=i;var n=t("../math/Vec3"),s=t("./Pool");(i.prototype=new s).constructObject=function(){return new n}},{"../math/Vec3":46,"./Pool":67}],71:[function(t,e,o){function i(t){this.contactPointPool=[],this.frictionEquationPool=[],this.result=[],this.frictionResult=[],this.v3pool=new p,this.world=t,this.currentContactMaterial=null,this.enableFrictionReduction=!1}function n(t,e,o){for(var i=null,n=t.length,s=0;s!==n;s++){var r=t[s],a=D;t[(s+1)%n].vsub(r,a);var c=H;a.cross(e,c);var h=K;o.vsub(r,h);var l=c.dot(h);if(!(null===i||l>0&&!0===i||l<=0&&!1===i))return!1;null===i&&(i=l>0)}return!0}e.exports=i;var s=t("../collision/AABB"),r=t("../objects/Body"),a=t("../shapes/Shape"),c=t("../collision/Ray"),h=t("../math/Vec3"),l=t("../math/Transform"),u=(t("../shapes/ConvexPolyhedron"),t("../math/Quaternion")),p=(t("../solver/Solver"),t("../utils/Vec3Pool")),d=t("../equations/ContactEquation"),y=t("../equations/FrictionEquation");i.prototype.createContactEquation=function(t,e,o,i,n,s){var r;this.contactPointPool.length?((r=this.contactPointPool.pop()).bi=t,r.bj=e):r=new d(t,e),r.enabled=t.collisionResponse&&e.collisionResponse&&o.collisionResponse&&i.collisionResponse;var a=this.currentContactMaterial;r.restitution=a.restitution,r.setSpookParams(a.contactEquationStiffness,a.contactEquationRelaxation,this.world.dt);var c=o.material||t.material,h=i.material||e.material;return c&&h&&c.restitution>=0&&h.restitution>=0&&(r.restitution=c.restitution*h.restitution),r.si=n||o,r.sj=s||i,r},i.prototype.createFrictionEquationsFromContact=function(t,e){var o=t.bi,i=t.bj,n=t.si,s=t.sj,r=this.world,a=this.currentContactMaterial,c=a.friction,h=n.material||o.material,l=s.material||i.material;if(h&&l&&h.friction>=0&&l.friction>=0&&(c=h.friction*l.friction),c>0){var u=c*r.gravity.length(),p=o.invMass+i.invMass;p>0&&(p=1/p);var d=this.frictionEquationPool,v=d.length?d.pop():new y(o,i,u*p),f=d.length?d.pop():new y(o,i,u*p);return v.bi=f.bi=o,v.bj=f.bj=i,v.minForce=f.minForce=-u*p,v.maxForce=f.maxForce=u*p,v.ri.copy(t.ri),v.rj.copy(t.rj),f.ri.copy(t.ri),f.rj.copy(t.rj),t.ni.tangents(v.t,f.t),v.setSpookParams(a.frictionEquationStiffness,a.frictionEquationRelaxation,r.dt),f.setSpookParams(a.frictionEquationStiffness,a.frictionEquationRelaxation,r.dt),v.enabled=f.enabled=t.enabled,e.push(v,f),!0}return!1};var v=new h,f=new h,m=new h;i.prototype.createFrictionFromAverage=function(t){var e=this.result[this.result.length-1];if(this.createFrictionEquationsFromContact(e,this.frictionResult)&&1!==t){var o=this.frictionResult[this.frictionResult.length-2],i=this.frictionResult[this.frictionResult.length-1];v.setZero(),f.setZero(),m.setZero();for(var n=e.bi,s=(e.bj,0);s!==t;s++)(e=this.result[this.result.length-1-s]).bodyA!==n?(v.vadd(e.ni,v),f.vadd(e.ri,f),m.vadd(e.rj,m)):(v.vsub(e.ni,v),f.vadd(e.rj,f),m.vadd(e.ri,m));var r=1/t;f.scale(r,o.ri),m.scale(r,o.rj),i.ri.copy(o.ri),i.rj.copy(o.rj),v.normalize(),v.tangents(o.t,i.t)}};var w=new h,g=new h,x=new u,b=new u;i.prototype.getContacts=function(t,e,o,i,n,s,a){this.contactPointPool=n,this.frictionEquationPool=a,this.result=i,this.frictionResult=s;for(var c=x,h=b,l=w,u=g,p=0,d=t.length;p!==d;p++){var y=t[p],v=e[p],f=null;y.material&&v.material&&(f=o.getContactMaterial(y.material,v.material)||null);for(var m=y.type&r.KINEMATIC&&v.type&r.STATIC||y.type&r.STATIC&&v.type&r.KINEMATIC||y.type&r.KINEMATIC&&v.type&r.KINEMATIC,E=0;EA.boundingSphereRadius+C.boundingSphereRadius)){var S=null;A.material&&C.material&&(S=o.getContactMaterial(A.material,C.material)||null),this.currentContactMaterial=S||f||o.defaultContactMaterial;var R=this[A.type|C.type];if(R){(A.type0&&H<0){m.vsub(d,w),f.copy(v),f.normalize(),K=w.dot(f),f.scale(K,w),w.vadd(d,w);if((Q=w.distanceTo(m))0){var M=G,T=X;M.copy(p[(A+1)%3]),T.copy(p[(A+2)%3]);var z=M.norm(),k=T.norm();M.normalize(),T.normalize();var P=_.dot(M),q=_.dot(T);if(P-z&&q-k){W=Math.abs(R-S-d);if((null===E||W0){for(var k=[],P=0,q=B.length;P!==q;P++){var L=p.get();r.vmult(v[B[P]],L),i.vadd(L,L),k.push(L)}if(n(k,C,o)){if(u)return!0;b=!0;U=this.createContactEquation(a,c,t,e,h,l);C.mult(-f,U.ri),C.negate(U.ni);var V=p.get();C.mult(-T,V);var F=p.get();C.mult(-f,F),o.vsub(i,U.rj),U.rj.vadd(F,U.rj),U.rj.vadd(V,U.rj),U.rj.vadd(i,U.rj),U.rj.vsub(c.position,U.rj),U.ri.vadd(o,U.ri),U.ri.vsub(a.position,U.ri),p.release(V),p.release(F),this.result.push(U),this.createFrictionEquationsFromContact(U,this.frictionResult);for(var P=0,N=k.length;P!==N;P++)p.release(k[P]);return}for(P=0;P!==B.length;P++){var I=p.get(),O=p.get();r.vmult(v[B[(P+1)%B.length]],I),r.vmult(v[B[(P+2)%B.length]],O),i.vadd(I,I),i.vadd(O,O);var j=et;O.vsub(I,j);var W=ot;j.unit(W);var D=p.get(),H=p.get();o.vsub(I,H);var K=H.dot(W);W.mult(K,D),D.vadd(I,D);var _=p.get();if(D.vsub(o,_),K>0&&K*Kt.boundingSphereRadius+e.boundingSphereRadius)&&t.findSeparatingAxis(e,o,n,i,s,d,u,p)){var y=[],v=vt;t.clipAgainstHull(o,n,e,i,s,d,-100,100,y);for(var f=0,m=0;m!==y.length;m++){if(l)return!0;var w=this.createContactEquation(r,a,t,e,c,h),g=w.ri,x=w.rj;d.negate(w.ni),y[m].normal.negate(v),v.mult(y[m].depth,v),y[m].point.vadd(v,g),x.copy(y[m].point),g.vsub(o,g),x.vsub(i,x),g.vadd(o,g),g.vsub(r.position,g),x.vadd(i,x),x.vsub(a.position,x),this.result.push(w),f++,this.enableFrictionReduction||this.createFrictionEquationsFromContact(w,this.frictionResult)}this.enableFrictionReduction&&f&&this.createFrictionFromAverage(f)}};var ft=new h,mt=new h,wt=new h;i.prototype[a.types.PLANE|a.types.PARTICLE]=i.prototype.planeParticle=function(t,e,o,i,n,s,r,a,c,h,l){var u=ft;u.set(0,0,1),r.quaternion.vmult(u,u);var p=mt;i.vsub(r.position,p);if(u.dot(p)<=0){if(l)return!0;var d=this.createContactEquation(a,r,e,t,c,h);d.ni.copy(u),d.ni.negate(d.ni),d.ri.set(0,0,0);var y=wt;u.mult(u.dot(i),y),i.vsub(y,y),d.rj.copy(y),this.result.push(d),this.createFrictionEquationsFromContact(d,this.frictionResult)}};var gt=new h;i.prototype[a.types.PARTICLE|a.types.SPHERE]=i.prototype.sphereParticle=function(t,e,o,i,n,s,r,a,c,h,l){var u=gt;u.set(0,0,1),i.vsub(o,u);if(u.norm2()<=t.radius*t.radius){if(l)return!0;var p=this.createContactEquation(a,r,e,t,c,h);u.normalize(),p.rj.copy(u),p.rj.mult(t.radius,p.rj),p.ni.copy(u),p.ni.negate(p.ni),p.ri.set(0,0,0),this.result.push(p),this.createFrictionEquationsFromContact(p,this.frictionResult)}};var xt=new u,bt=new h,Et=(new h,new h),At=new h,Bt=new h;i.prototype[a.types.PARTICLE|a.types.CONVEXPOLYHEDRON]=i.prototype.convexParticle=function(t,e,o,i,n,s,r,a,c,h,l){var u=-1,p=Et,d=Bt,y=null,v=bt;if(v.copy(i),v.vsub(o,v),n.conjugate(xt),xt.vmult(v,v),t.pointIsInside(v)){t.worldVerticesNeedsUpdate&&t.computeWorldVertices(o,n),t.worldFaceNormalsNeedsUpdate&&t.computeWorldFaceNormals(n);for(var f=0,m=t.faces.length;f!==m;f++){var w=[t.worldVertices[t.faces[f][0]]],g=t.worldFaceNormals[f];i.vsub(w[0],At);var x=-g.dot(At);if(null===y||Math.abs(x)p.length||x>p[0].length)){w<0&&(w=0),g<0&&(g=0),x<0&&(x=0),b<0&&(b=0),w>=p.length&&(w=p.length-1),g>=p.length&&(g=p.length-1),b>=p[0].length&&(b=p[0].length-1),x>=p[0].length&&(x=p[0].length-1);var E=[];e.getRectMinMax(w,x,g,b,E);var A=E[0],B=E[1];if(!(m.z-y>B||m.z+yp.length||x>p[0].length)){m<0&&(m=0),w<0&&(w=0),g<0&&(g=0),x<0&&(x=0),m>=p.length&&(m=p.length-1),w>=p.length&&(w=p.length-1),x>=p[0].length&&(x=p[0].length-1),g>=p[0].length&&(g=p[0].length-1);var b=[];e.getRectMinMax(m,g,w,x,b);var E=b[0],A=b[1];if(!(f.z-d>A||f.z+d2)return}}}},{"../collision/AABB":18,"../collision/Ray":25,"../equations/ContactEquation":35,"../equations/FrictionEquation":37,"../math/Quaternion":44,"../math/Transform":45,"../math/Vec3":46,"../objects/Body":47,"../shapes/ConvexPolyhedron":54,"../shapes/Shape":59,"../solver/Solver":63,"../utils/Vec3Pool":70}],72:[function(t,e,o){function i(t){t=t||{},c.apply(this),this.dt=-1,this.allowSleep=!!t.allowSleep,this.contacts=[],this.frictionEquations=[],this.quatNormalizeSkip=void 0!==t.quatNormalizeSkip?t.quatNormalizeSkip:0,this.quatNormalizeFast=void 0!==t.quatNormalizeFast&&t.quatNormalizeFast,this.time=0,this.stepnumber=0,this.default_dt=1/60,this.nextId=0,this.gravity=new n,t.gravity&&this.gravity.copy(t.gravity),this.broadphase=void 0!==t.broadphase?t.broadphase:new w,this.bodies=[],this.solver=void 0!==t.solver?t.solver:new r,this.constraints=[],this.narrowphase=new a(this),this.collisionMatrix=new h,this.collisionMatrixPrevious=new h,this.bodyOverlapKeeper=new l,this.shapeOverlapKeeper=new l,this.materials=[],this.contactmaterials=[],this.contactMaterialTable=new y,this.defaultMaterial=new u("default"),this.defaultContactMaterial=new p(this.defaultMaterial,this.defaultMaterial,{friction:.3,restitution:0}),this.doProfiling=!1,this.profile={solve:0,makeContactConstraints:0,broadphase:0,integrate:0,narrowphase:0},this.accumulator=0,this.subsystems=[],this.addBodyEvent={type:"addBody",body:null},this.removeBodyEvent={type:"removeBody",body:null},this.idToBodyMap={},this.broadphase.setWorld(this)}e.exports=i;t("../shapes/Shape");var n=t("../math/Vec3"),s=t("../math/Quaternion"),r=t("../solver/GSSolver"),a=(t("../equations/ContactEquation"),t("../equations/FrictionEquation"),t("./Narrowphase")),c=t("../utils/EventTarget"),h=t("../collision/ArrayCollisionMatrix"),l=t("../collision/OverlapKeeper"),u=t("../material/Material"),p=t("../material/ContactMaterial"),d=t("../objects/Body"),y=t("../utils/TupleDictionary"),v=t("../collision/RaycastResult"),f=t("../collision/AABB"),m=t("../collision/Ray"),w=t("../collision/NaiveBroadphase");i.prototype=new c;new f;var g=new m;if(i.prototype.getContactMaterial=function(t,e){return this.contactMaterialTable.get(t.id,e.id)},i.prototype.numObjects=function(){return this.bodies.length},i.prototype.collisionMatrixTick=function(){var t=this.collisionMatrixPrevious;this.collisionMatrixPrevious=this.collisionMatrix,this.collisionMatrix=t,this.collisionMatrix.reset(),this.bodyOverlapKeeper.tick(),this.shapeOverlapKeeper.tick()},i.prototype.add=i.prototype.addBody=function(t){-1===this.bodies.indexOf(t)&&(t.index=this.bodies.length,this.bodies.push(t),t.world=this,t.initPosition.copy(t.position),t.initVelocity.copy(t.velocity),t.timeLastSleepy=this.time,t instanceof d&&(t.initAngularVelocity.copy(t.angularVelocity),t.initQuaternion.copy(t.quaternion)),this.collisionMatrix.setNumObjects(this.bodies.length),this.addBodyEvent.body=t,this.idToBodyMap[t.id]=t,this.dispatchEvent(this.addBodyEvent))},i.prototype.addConstraint=function(t){this.constraints.push(t)},i.prototype.removeConstraint=function(t){var e=this.constraints.indexOf(t);-1!==e&&this.constraints.splice(e,1)},i.prototype.rayTest=function(t,e,o){o instanceof v?this.raycastClosest(t,e,{skipBackfaces:!0},o):this.raycastAll(t,e,{skipBackfaces:!0},o)},i.prototype.raycastAll=function(t,e,o,i){return o.mode=m.ALL,o.from=t,o.to=e,o.callback=i,g.intersectWorld(this,o)},i.prototype.raycastAny=function(t,e,o,i){return o.mode=m.ANY,o.from=t,o.to=e,o.result=i,g.intersectWorld(this,o)},i.prototype.raycastClosest=function(t,e,o,i){return o.mode=m.CLOSEST,o.from=t,o.to=e,o.result=i,g.intersectWorld(this,o)},i.prototype.remove=function(t){t.world=null;var e=this.bodies.length-1,o=this.bodies,i=o.indexOf(t);if(-1!==i){o.splice(i,1);for(var n=0;n!==o.length;n++)o[n].index=n;this.collisionMatrix.setNumObjects(e),this.removeBodyEvent.body=t,delete this.idToBodyMap[t.id],this.dispatchEvent(this.removeBodyEvent)}},i.prototype.removeBody=i.prototype.remove,i.prototype.getBodyById=function(t){return this.idToBodyMap[t]},i.prototype.getShapeById=function(t){for(var e=this.bodies,o=0,i=e.length;o=t&&i=0;j-=1)(O.bodyA===i[j]&&O.bodyB===n[j]||O.bodyB===i[j]&&O.bodyA===n[j])&&(i.splice(j,1),n.splice(j,1))}this.collisionMatrixTick(),h&&(e=performance.now());var T=B,z=o.length;for(w=0;w!==z;w++)T.push(o[w]);o.length=0;var k=this.frictionEquations.length;for(w=0;w!==k;w++)y.push(this.frictionEquations[w]);this.frictionEquations.length=0,this.narrowphase.getContacts(i,n,this,o,T,this.frictionEquations,y),h&&(l.narrowphase=performance.now()-e),h&&(e=performance.now());for(w=0;w=0&&V.material.friction>=0&&L.material.friction*V.material.friction,L.material.restitution>=0&&V.material.restitution>=0&&(O.restitution=L.material.restitution*V.material.restitution)),a.addEquation(O),L.allowSleep&&L.type===d.DYNAMIC&&L.sleepState===d.SLEEPING&&V.sleepState===d.AWAKE&&V.type!==d.STATIC){V.velocity.norm2()+V.angularVelocity.norm2()>=2*Math.pow(V.sleepSpeedLimit,2)&&(L._wakeUpAfterNarrowphase=!0)}if(V.allowSleep&&V.type===d.DYNAMIC&&V.sleepState===d.SLEEPING&&L.sleepState===d.AWAKE&&L.type!==d.STATIC){L.velocity.norm2()+L.angularVelocity.norm2()>=2*Math.pow(L.sleepSpeedLimit,2)&&(V._wakeUpAfterNarrowphase=!0)}this.collisionMatrix.set(L,V,!0),this.collisionMatrixPrevious.get(L,V)||(A.body=V,A.contact=O,L.dispatchEvent(A),A.body=L,V.dispatchEvent(A)),this.bodyOverlapKeeper.set(L.id,V.id),this.shapeOverlapKeeper.set(F.id,N.id)}for(this.emitContactEvents(),h&&(l.makeContactConstraints=performance.now()-e,e=performance.now()),w=0;w!==s;w++){(L=r[w])._wakeUpAfterNarrowphase&&(L.wakeUp(),L._wakeUpAfterNarrowphase=!1)}var I=p.length;for(w=0;w!==I;w++){var O=p[w];O.update();for(var j=0,W=O.equations.length;j!==W;j++){var D=O.equations[j];a.addEquation(D)}}a.solve(t,this),h&&(l.solve=performance.now()-e),a.removeAllEquations();var H=Math.pow;for(w=0;w!==s;w++){if((L=r[w]).type&u){var K=H(1-L.linearDamping,t),_=L.velocity;_.mult(K,_);var U=L.angularVelocity;if(U){var G=H(1-L.angularDamping,t);U.mult(G,U)}}}for(this.dispatchEvent(E),w=0;w!==s;w++){(L=r[w]).preStep&&L.preStep.call(L)}h&&(e=performance.now());var X=this.stepnumber%(this.quatNormalizeSkip+1)==0,Y=this.quatNormalizeFast;for(w=0;w!==s;w++)r[w].integrate(t,X,Y);for(this.clearForces(),this.broadphase.dirty=!0,h&&(l.integrate=performance.now()-e),this.time+=t,this.stepnumber+=1,this.dispatchEvent(b),w=0;w!==s;w++){var Q=(L=r[w]).postStep;Q&&Q.call(L)}if(this.allowSleep)for(w=0;w!==s;w++)r[w].sleepTick(this.time)},i.prototype.emitContactEvents=function(){var t=[],e=[],o={type:"beginContact",bodyA:null,bodyB:null},i={type:"endContact",bodyA:null,bodyB:null},n={type:"beginShapeContact",bodyA:null,bodyB:null,shapeA:null,shapeB:null},s={type:"endShapeContact",bodyA:null,bodyB:null,shapeA:null,shapeB:null};return function(){var r=this.hasAnyEventListener("beginContact"),a=this.hasAnyEventListener("endContact");if((r||a)&&this.bodyOverlapKeeper.getDiff(t,e),r){for(var c=0,h=t.length;c0;)!function(t,i){var n,s=A.length,r=[t],a=i.indexOf(t.visiblePoints.pop());for(;s-- >0;)(n=A[s])!==t&&e(n,i).dot(g.subVectors(i[a],i[n[0]]))>0&&r.push(n);var c,h,l,u,p=s=r.length,d=1===s,y=[],v=0,f=[];r[0][0],r[0][1],r[0][1],r[0][2],r[0][2],r[0][0];if(1===r.length)n=r[0],y=[n[0],n[1],n[1],n[2],n[2],n[0]],B.indexOf(n)>-1&&B.splice(B.indexOf(n),1),n.visiblePoints&&(f=f.concat(n.visiblePoints)),A.splice(A.indexOf(n),1);else for(;s-- >0;){n=r[s],B.indexOf(n)>-1&&B.splice(B.indexOf(n),1),n.visiblePoints&&(f=f.concat(n.visiblePoints)),A.splice(A.indexOf(n),1);var m;for(cEdgeIndex=0;cEdgeIndex<3;){for(m=!1,p=r.length,l=n[cEdgeIndex],u=n[(cEdgeIndex+1)%3];p-- >0&&!m;)if(c=r[p],v=0,c!==n)for(;v<3&&!m;)h=v+1,m=c[v]===l&&c[h%3]===u||c[v]===u&&c[h%3]===l,v++;m&&!d||(y.push(l),y.push(u)),cEdgeIndex++}}s=0;var w,x=y.length/2;for(;s0&&s[o[a].x/3]>0;);a+10&&(t.visiblePoints=o.splice(a+1))}var i,n,s,r,a,c,h,l,u,p,d,y,v,f,m,w,g,x,b,E,A=[],B=[],C=0,S=function(){var t=new THREE.Vector3,e=new THREE.Vector3,o=new THREE.Vector3;return function(i,n,s){return t.subVectors(s,i),e.subVectors(n,i),o.crossVectors(t,e),o.normalize()}}(),R=function(){var t=new THREE.Vector3,e=new THREE.Vector3,o=new THREE.Vector3;return function(i,n,s){t.subVectors(n,i),e.subVectors(s,i),o.subVectors(s,n);var r=e.dot(t);if(r<0)return e.dot(e);var a=t.dot(t);return r>=a?o.dot(o):e.dot(e)-r*r/a}}();return function(e){for(d=new THREE.Vector3,y=new THREE.Vector3,v=new THREE.Vector3,f=new THREE.Vector3,m=new THREE.Vector3,w=new THREE.Vector3,g=new THREE.Vector3,x=new THREE.Vector3,b=new THREE.Vector3,E=new THREE.Vector3,points=e.vertices,A=[],B=[],L=i=points.length,n=points.slice(0,6),C=0;L-- >0;)points[L].xn[1].x&&(n[1]=points[L]),points[L].y0;)for(r=L-1;r-- >0;)C<(s=n[L].distanceToSquared(n[r]))&&(C=s,a=n[L],c=n[r]);for(L=6,C=0;L-- >0;)s=R(a,c,n[L]),C0;)s=Math.abs(points[L].dot(u)-p),C0;)o(P[L],q,points),void 0!==P[L].visiblePoints&&B.push(P[L]),A.push(P[L]);t(points);for(var V=A.length;V-- >0;)e.faces[V]=new THREE.Face3(A[V][2],A[V][1],A[V][0],A[V].normal);return e.normalsNeedUpdate=!0,e}}()},{}],75:[function(t,e,o){e.exports={schema:{enabled:{default:!0},mode:{default:"teleport",oneOf:["teleport","animate"]},animateSpeed:{default:3}},init:function(){this.active=!0,this.checkpoint=null,this.offset=new THREE.Vector3,this.position=new THREE.Vector3,this.targetPosition=new THREE.Vector3},play:function(){this.active=!0},pause:function(){this.active=!1},setCheckpoint:function(t){var e=this.el;this.active&&this.checkpoint!==t&&(this.checkpoint&&e.emit("navigation-end",{checkpoint:this.checkpoint}),this.checkpoint=t,this.sync(),this.position.distanceTo(this.targetPosition)<.1?this.checkpoint=null:(e.emit("navigation-start",{checkpoint:t}),"teleport"===this.data.mode&&(this.el.setAttribute("position",this.targetPosition),this.checkpoint=null,e.emit("navigation-end",{checkpoint:t}))))},isVelocityActive:function(){return!(!this.active||!this.checkpoint)},getVelocity:function(){if(this.active){var t=this.data,e=this.offset,o=this.position,i=this.targetPosition,n=this.checkpoint;return this.sync(),o.distanceTo(i)<.1?(this.checkpoint=null,this.el.emit("navigation-end",{checkpoint:n}),e.set(0,0,0)):(e.setLength(t.animateSpeed),e)}},sync:function(){var t=this.offset,e=this.position,o=this.targetPosition;e.copy(this.el.getAttribute("position")),o.copy(this.checkpoint.object3D.getWorldPosition()),o.add(this.checkpoint.components.checkpoint.getOffset()),t.copy(o).sub(e)}}},{}],76:[function(t,e,o){var i=t("../../lib/GamepadButton"),n=t("../../lib/GamepadButtonEvent");e.exports={GamepadButton:i,schema:{controller:{default:0,oneOf:[0,1,2,3]},enabled:{default:!0},debug:{default:!1}},init:function(){var t=this.el.sceneEl;this.prevTime=window.performance.now(),this.buttons={},t.addBehavior(this)},update:function(){this.tick()},tick:function(){this.updateButtonState()},remove:function(){},isVelocityActive:function(){if(!this.data.enabled||!this.isConnected())return!1;var t=this.getDpad(),e=this.getJoystick(0),o=t.x||e.x,i=t.y||e.y;return Math.abs(o)>.2||Math.abs(i)>.2},getVelocityDelta:function(){var t=this.getDpad(),e=this.getJoystick(0),o=t.x||e.x,i=t.y||e.y,n=new THREE.Vector3;return Math.abs(o)>.2&&(n.x+=o),Math.abs(i)>.2&&(n.z+=i),n},isRotationActive:function(){if(!this.data.enabled||!this.isConnected())return!1;var t=this.getJoystick(1);return Math.abs(t.x)>.2||Math.abs(t.y)>.2},getRotationDelta:function(){var t=this.getJoystick(1);return Math.abs(t.x)<=.2&&(t.x=0),Math.abs(t.y)<=.2&&(t.y=0),t},updateButtonState:function(){var t=this.getGamepad();if(this.data.enabled&&t)for(var e=0;e.2?(this.velocity.set(0,0,0),this.el.setAttribute("velocity",this.velocity)):this.updateVelocity(e))},updateRotation:function(t){for(var e,o,n=this.data,s=0,r=n.rotationControls.length;s1?o.setLength(this.data.movementAcceleration*t/1e3):o.multiplyScalar(this.data.movementAcceleration*t/1e3);var a=this.el.getAttribute("rotation");a&&(this.heading.set(n.fly?THREE.Math.degToRad(a.x):0,THREE.Math.degToRad(a.y),0),o.applyEuler(this.heading)),i.add(o)}this.el.setAttribute("velocity",i)}}},{}]},{},[1]);