!function t(e,i,o){function n(r,a){if(!i[r]){if(!e[r]){var h="function"==typeof require&&require;if(!a&&h)return h(r,!0);if(s)return s(r,!0);var l=new Error("Cannot find module '"+r+"'");throw l.code="MODULE_NOT_FOUND",l}var c=i[r]={exports:{}};e[r][0].call(c.exports,function(t){var i=e[r][1][t];return n(i||t)},c,c.exports,t,e,i,o)}return i[r].exports}for(var s="function"==typeof require&&require,r=0;rr.x&&(r.x=l.x),l.xr.y&&(r.y=l.y),l.yr.z&&(r.z=l.z),l.z=n.x&&e.y<=o.y&&i.y>=n.y&&e.z<=o.z&&i.z>=n.z},o.prototype.getCorners=function(t,e,i,o,n,s,r,a){var h=this.lowerBound,l=this.upperBound;t.copy(h),e.set(l.x,h.y,h.z),i.set(l.x,l.y,h.z),o.set(h.x,l.y,l.z),n.set(l.x,h.y,h.z),s.set(h.x,l.y,h.z),r.set(h.x,h.y,l.z),a.copy(l)};var r=[new n,new n,new n,new n,new n,new n,new n,new n];o.prototype.toLocalFrame=function(t,e){var i=r,o=i[0],n=i[1],s=i[2],a=i[3],h=i[4],l=i[5],c=i[6],p=i[7];this.getCorners(o,n,s,a,h,l,c,p);for(var u=0;8!==u;u++){var d=i[u];t.pointToLocal(d,d)}return e.setFromPoints(i)},o.prototype.toWorldFrame=function(t,e){var i=r,o=i[0],n=i[1],s=i[2],a=i[3],h=i[4],l=i[5],c=i[6],p=i[7];this.getCorners(o,n,s,a,h,l,c,p);for(var u=0;8!==u;u++){var d=i[u];t.pointToWorld(d,d)}return e.setFromPoints(i)},o.prototype.overlapsRay=function(t){var e=1/t._direction.x,i=1/t._direction.y,o=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)*i,a=(this.upperBound.y-t.from.y)*i,h=(this.lowerBound.z-t.from.z)*o,l=(this.upperBound.z-t.from.z)*o,c=Math.max(Math.max(Math.min(n,s),Math.min(r,a)),Math.min(h,l)),p=Math.min(Math.min(Math.max(n,s),Math.max(r,a)),Math.max(h,l));return!(p<0)&&!(c>p)}},{"../math/Vec3":43,"../utils/Utils":66}],16:[function(t,e,i){function o(){this.matrix=[]}e.exports=o,o.prototype.get=function(t,e){if(t=t.index,(e=e.index)>t){var i=e;e=t,t=i}return this.matrix[(t*(t+1)>>1)+e-1]},o.prototype.set=function(t,e,i){if(t=t.index,(e=e.index)>t){var o=e;e=t,t=o}this.matrix[(t*(t+1)>>1)+e-1]=i?1:0},o.prototype.reset=function(){for(var t=0,e=this.matrix.length;t!==e;t++)this.matrix[t]=0},o.prototype.setNumObjects=function(t){this.matrix.length=t*(t-1)>>1}},{}],17:[function(t,e,i){function o(){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=o,o.prototype.collisionPairs=function(t,e,i){throw new Error("collisionPairs not implemented for this BroadPhase class!")},o.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)},o.prototype.intersectionTest=function(t,e,i,o){this.useBoundingBoxes?this.doBoundingBoxBroadphase(t,e,i,o):this.doBoundingSphereBroadphase(t,e,i,o)};var a=new s;new s,new r,new s;o.prototype.doBoundingSphereBroadphase=function(t,e,i,o){var n=a;e.position.vsub(t.position,n);var s=Math.pow(t.boundingRadius+e.boundingRadius,2);n.norm2()i.norm2()},o.prototype.aabbQuery=function(t,e,i){return console.warn(".aabbQuery is not implemented in this Broadphase subclass."),[]}},{"../math/Quaternion":41,"../math/Vec3":43,"../objects/Body":44,"../shapes/Plane":55,"../shapes/Shape":56}],18:[function(t,e,i){function o(t,e,i,o,r){n.apply(this),this.nx=i||10,this.ny=o||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 h=0;h=c&&(a=c-1),h<0?h=0:h>=p&&(h=p-1),l<0?l=0:l>=u&&(l=u-1),f<0?f=0:f>=c&&(f=c-1),m<0?m=0:m>=p&&(m=p-1),w<0?w=0:w>=u&&(w=u-1),h*=v,l*=y,f*=d,m*=v,w*=y;for(var S=a*=d;S<=f;S+=d)for(var R=h;R<=m;R+=v)for(var z=l;z<=w;z+=y){var M=S+R+z;V[M][F[M]++]=r}}for(var n=t.numObjects(),s=t.bodies,h=this.aabbMax,l=this.aabbMin,c=this.nx,p=this.ny,u=this.nz,d=p*u,v=u,y=1,f=h.x,m=h.y,w=h.z,g=l.x,x=l.y,b=l.z,E=c/(f-g),B=p/(m-x),A=u/(w-b),S=(f-g)/c,R=(m-x)/p,z=(w-b)/u,M=.5*Math.sqrt(S*S+R*R+z*z),C=r.types,T=C.SPHERE,q=C.PLANE,V=(C.BOX,C.COMPOUND,C.CONVEXPOLYHEDRON,this.bins),F=this.binLengths,P=this.bins.length,N=0;N!==P;N++)F[N]=0;for(var I=Math.ceil,l=Math.min,h=Math.max,N=0;N!==n;N++){var L=(it=s[N]).shape;switch(L.type){case T:var j=it.position.x,W=it.position.y,O=it.position.z,H=L.radius;o(j-H,W-H,O-H,j+H,W+H,O+H,it);break;case q:L.worldNormalNeedsUpdate&&L.computeWorldNormal(it.quaternion);var k=L.worldNormal,_=g+.5*S-it.position.x,D=x+.5*R-it.position.y,G=b+.5*z-it.position.z,U=a;U.set(_,D,G);for(var X=0,Q=0;X!==c;X++,Q+=d,U.y=D,U.x+=S)for(var Y=0,Z=0;Y!==p;Y++,Z+=v,U.z=G,U.y+=R)for(var K=0,J=0;K!==u;K++,J+=y,U.z+=z)if(U.dot(k)1)for(var et=V[N],X=0;X!==tt;X++)for(var it=et[X],Y=0;Y!==X;Y++){var ot=et[Y];this.needBroadphaseCollision(it,ot)&&this.intersectionTest(it,ot,e,i)}}this.makePairsUnique(e,i)}},{"../math/Vec3":43,"../shapes/Shape":56,"./Broadphase":17}],19:[function(t,e,i){function o(){n.apply(this)}e.exports=o;var n=t("./Broadphase"),s=t("./AABB");(o.prototype=new n).constructor=o,o.prototype.collisionPairs=function(t,e,i){var o,n,s,r,a=t.bodies,h=a.length;for(o=0;o!==h;o++)for(n=0;n!==o;n++)s=a[o],r=a[n],this.needBroadphaseCollision(s,r)&&this.intersectionTest(s,r,e,i)};new s;o.prototype.aabbQuery=function(t,e,i){i=i||[];for(var o=0;ot){var i=e;e=t,t=i}return t+"-"+e in this.matrix},o.prototype.set=function(t,e,i){if(t=t.id,(e=e.id)>t){var o=e;e=t,t=o}i?this.matrix[t+"-"+e]=!0:delete this.matrix[t+"-"+e]},o.prototype.reset=function(){this.matrix={}},o.prototype.setNumObjects=function(t){}},{}],21:[function(t,e,i){function o(){this.current=[],this.previous=[]}function n(t,e){t.push((4294901760&e)>>16,65535&e)}e.exports=o,o.prototype.getKey=function(t,e){if(eo[n];)n++;if(i!==o[n]){for(e=o.length-1;e>=n;e--)o[e+1]=o[e];o[n]=i}},o.prototype.tick=function(){var t=this.current;this.current=this.previous,this.previous=t,this.current.length=0},o.prototype.getDiff=function(t,e){for(var i=this.current,o=this.previous,s=i.length,r=o.length,a=0,h=0;ho[a];)a++;l===o[a]||n(t,l)}a=0;for(h=0;hi[a];)a++;i[a]===c||n(e,c)}}},{}],22:[function(t,e,i){function o(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=o.ANY,this.result=new h,this.hasHit=!1,this.callback=function(t){}}function n(t,e,i,o){o.vsub(e,L),i.vsub(e,d),t.vsub(e,v);var n,s,r=L.dot(L),a=L.dot(d),h=L.dot(v),l=d.dot(d),c=d.dot(v);return(n=l*h-a*c)>=0&&(s=r*c-a*h)>=0&&n+st.boundingSphereRadius)){var n=this[t.type];n&&n.call(this,t,e,i,o,t)}};new s,new s;var m=new s,w=new s,g=new s,x=new s;new s,new h;o.prototype.intersectBox=function(t,e,i,o,n){return this.intersectConvex(t.convexPolyhedronRepresentation,e,i,o,n)},o.prototype[l.types.BOX]=o.prototype.intersectBox,o.prototype.intersectPlane=function(t,e,i,o,n){var r=this.from,a=this.to,h=this._direction,l=new s(0,0,1);e.vmult(l,l);var c=new s;r.vsub(i,c);var p=c.dot(l);a.vsub(i,c);if(!(p*c.dot(l)>0||r.distanceTo(a)=0&&v<=1&&(s.lerp(r,v,u),u.vsub(i,d),d.normalize(),this.reportIntersection(d,u,n,o,-1)),this.result._shouldStop)return;y>=0&&y<=1&&(s.lerp(r,y,u),u.vsub(i,d),d.normalize(),this.reportIntersection(d,u,n,o,-1))}},o.prototype[l.types.SPHERE]=o.prototype.intersectSphere;var z=new s,M=(new s,new s,new s);o.prototype.intersectConvex=function(t,e,i,o,s,r){for(var a=z,h=M,l=r&&r.faceList||null,c=t.faces,p=t.vertices,u=t.faceNormals,d=this._direction,v=this.from,y=this.to,f=v.distanceTo(y),b=l?l.length:c.length,E=this.result,B=0;!E._shouldStop&&Bf||this.reportIntersection(a,m,s,o,A)}}}}},o.prototype[l.types.CONVEXPOLYHEDRON]=o.prototype.intersectConvex;var C=new s,T=new s,q=new s,V=new s,F=new s,P=new s,N=(new c,[]),I=new a;o.prototype.intersectTrimesh=function(t,e,i,o,s,r){var h=C,l=N,c=I,p=M,u=T,d=q,v=V,y=P,f=F,b=(r&&r.faceList,t.indices),E=(t.vertices,t.faceNormals,this.from),B=this.to,A=this._direction;c.position.copy(i),c.quaternion.copy(e),a.vectorToLocalFrame(i,e,A,u),a.pointToLocalFrame(i,e,E,d),a.pointToLocalFrame(i,e,B,v),v.x*=t.scale.x,v.y*=t.scale.y,v.z*=t.scale.z,d.x*=t.scale.x,d.y*=t.scale.y,d.z*=t.scale.z,v.vsub(d,u),u.normalize();var S=d.distanceSquared(v);t.tree.rayQuery(this,c,l);for(var R=0,z=l.length;!this.result._shouldStop&&R!==z;R++){var L=l[R];t.getNormal(L,h),t.getVertex(b[3*L],w),w.vsub(d,p);var j=u.dot(h),W=h.dot(p)/j;if(!(W<0)){u.scale(W,m),m.vadd(d,m),t.getVertex(b[3*L+1],g),t.getVertex(b[3*L+2],x);var O=m.distanceSquared(d);!n(m,g,w,x)&&!n(m,w,g,x)||O>S||(a.vectorToWorldFrame(e,h,f),a.pointToWorldFrame(i,e,m,y),this.reportIntersection(f,y,s,o,L))}}l.length=0},o.prototype[l.types.TRIMESH]=o.prototype.intersectTrimesh,o.prototype.reportIntersection=function(t,e,i,n,s){var r=this.from,a=this.to,h=r.distanceTo(e),l=this.result;if(!(this.skipBackfaces&&t.dot(this._direction)>0))switch(l.hitFaceIndex=void 0!==s?s:-1,this.mode){case o.ALL:this.hasHit=!0,l.set(r,a,t,e,i,n,h),l.hasHit=!0,this.callback(l);break;case o.CLOSEST:(h=0&&!(t[n].aabb.lowerBound.x<=o.aabb.lowerBound.x);n--)t[n+1]=t[n];t[n+1]=o}return t},o.insertionSortY=function(t){for(var e=1,i=t.length;e=0&&!(t[n].aabb.lowerBound.y<=o.aabb.lowerBound.y);n--)t[n+1]=t[n];t[n+1]=o}return t},o.insertionSortZ=function(t){for(var e=1,i=t.length;e=0&&!(t[n].aabb.lowerBound.z<=o.aabb.lowerBound.z);n--)t[n+1]=t[n];t[n+1]=o}return t},o.prototype.collisionPairs=function(t,e,i){var n,s,r=this.axisList,a=r.length,h=this.axisIndex;for(this.dirty&&(this.sortList(),this.dirty=!1),n=0;n!==a;n++){var l=r[n];for(s=n+1;sy?v>f?0:2:y>f?1:2},o.prototype.aabbQuery=function(t,e,i){i=i||[],this.dirty&&(this.sortList(),this.dirty=!1);var o=this.axisIndex,n="x";1===o&&(n="y"),2===o&&(n="z");for(var s=this.axisList,r=(e.lowerBound[n],e.upperBound[n],0);r.499&&(i=2*Math.atan2(s,h),o=Math.PI/2,n=0),l<-.499&&(i=-2*Math.atan2(s,h),o=-Math.PI/2,n=0),isNaN(i)){var c=s*s,p=r*r,u=a*a;i=Math.atan2(2*r*h-2*s*a,1-2*p-2*u),o=Math.asin(2*l),n=Math.atan2(2*s*h-2*r*a,1-2*c-2*u)}break;default:throw new Error("Euler order "+e+" not supported yet.")}t.y=i,t.z=o,t.x=n},o.prototype.setFromEuler=function(t,e,i,o){o=o||"XYZ";var n=Math.cos(t/2),s=Math.cos(e/2),r=Math.cos(i/2),a=Math.sin(t/2),h=Math.sin(e/2),l=Math.sin(i/2);return"XYZ"===o?(this.x=a*s*r+n*h*l,this.y=n*h*r-a*s*l,this.z=n*s*l+a*h*r,this.w=n*s*r-a*h*l):"YXZ"===o?(this.x=a*s*r+n*h*l,this.y=n*h*r-a*s*l,this.z=n*s*l-a*h*r,this.w=n*s*r+a*h*l):"ZXY"===o?(this.x=a*s*r-n*h*l,this.y=n*h*r+a*s*l,this.z=n*s*l+a*h*r,this.w=n*s*r-a*h*l):"ZYX"===o?(this.x=a*s*r-n*h*l,this.y=n*h*r+a*s*l,this.z=n*s*l-a*h*r,this.w=n*s*r+a*h*l):"YZX"===o?(this.x=a*s*r+n*h*l,this.y=n*h*r+a*s*l,this.z=n*s*l-a*h*r,this.w=n*s*r-a*h*l):"XZY"===o&&(this.x=a*s*r-n*h*l,this.y=n*h*r-a*s*l,this.z=n*s*l+a*h*r,this.w=n*s*r+a*h*l),this},o.prototype.clone=function(){return new o(this.x,this.y,this.z,this.w)},o.prototype.slerp=function(t,e,i){i=i||new o;var n,s,r,a,h,l=this.x,c=this.y,p=this.z,u=this.w,d=t.x,v=t.y,y=t.z,f=t.w;return(s=l*d+c*v+p*y+u*f)<0&&(s=-s,d=-d,v=-v,y=-y,f=-f),1-s>1e-6?(n=Math.acos(s),r=Math.sin(n),a=Math.sin((1-e)*n)/r,h=Math.sin(e*n)/r):(a=1-e,h=e),i.x=a*l+h*d,i.y=a*c+h*v,i.z=a*p+h*y,i.w=a*u+h*f,i},o.prototype.integrate=function(t,e,i,n){n=n||new o;var s=t.x*i.x,r=t.y*i.y,a=t.z*i.z,h=this.x,l=this.y,c=this.z,p=this.w,u=.5*e;return n.x+=u*(s*p+r*c-a*l),n.y+=u*(r*p+a*h-s*c),n.z+=u*(a*p+s*l-r*h),n.w+=u*(-s*h-r*l-a*c),n}},{"./Vec3":43}],42:[function(t,e,i){function o(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=o;var r=new s;o.pointToLocalFrame=function(t,e,i,o){o=o||new n;return i.vsub(t,o),e.conjugate(r),r.vmult(o,o),o},o.prototype.pointToLocal=function(t,e){return o.pointToLocalFrame(this.position,this.quaternion,t,e)},o.pointToWorldFrame=function(t,e,i,o){o=o||new n;return e.vmult(i,o),o.vadd(t,o),o},o.prototype.pointToWorld=function(t,e){return o.pointToWorldFrame(this.position,this.quaternion,t,e)},o.prototype.vectorToWorldFrame=function(t,e){e=e||new n;return this.quaternion.vmult(t,e),e},o.vectorToWorldFrame=function(t,e,i){return t.vmult(e,i),i},o.vectorToLocalFrame=function(t,e,i,o){o=o||new n;return e.w*=-1,e.vmult(i,o),e.w*=-1,o}},{"./Quaternion":41,"./Vec3":43}],43:[function(t,e,i){function o(t,e,i){this.x=t||0,this.y=e||0,this.z=i||0}e.exports=o;var n=t("./Mat3");o.ZERO=new o(0,0,0),o.UNIT_X=new o(1,0,0),o.UNIT_Y=new o(0,1,0),o.UNIT_Z=new o(0,0,1),o.prototype.cross=function(t,e){var i=t.x,n=t.y,s=t.z,r=this.x,a=this.y,h=this.z;return e=e||new o,e.x=a*s-h*n,e.y=h*i-r*s,e.z=r*n-a*i,e},o.prototype.set=function(t,e,i){return this.x=t,this.y=e,this.z=i,this},o.prototype.setZero=function(){this.x=this.y=this.z=0},o.prototype.vadd=function(t,e){if(!e)return new o(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},o.prototype.vsub=function(t,e){if(!e)return new o(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},o.prototype.crossmat=function(){return new n([0,-this.z,this.y,this.z,0,-this.x,-this.y,this.x,0])},o.prototype.normalize=function(){var t=this.x,e=this.y,i=this.z,o=Math.sqrt(t*t+e*e+i*i);if(o>0){var n=1/o;this.x*=n,this.y*=n,this.z*=n}else this.x=0,this.y=0,this.z=0;return o},o.prototype.unit=function(t){t=t||new o;var e=this.x,i=this.y,n=this.z,s=Math.sqrt(e*e+i*i+n*n);return s>0?(s=1/s,t.x=e*s,t.y=i*s,t.z=n*s):(t.x=1,t.y=0,t.z=0),t},o.prototype.norm=function(){var t=this.x,e=this.y,i=this.z;return Math.sqrt(t*t+e*e+i*i)},o.prototype.length=o.prototype.norm,o.prototype.norm2=function(){return this.dot(this)},o.prototype.lengthSquared=o.prototype.norm2,o.prototype.distanceTo=function(t){var e=this.x,i=this.y,o=this.z,n=t.x,s=t.y,r=t.z;return Math.sqrt((n-e)*(n-e)+(s-i)*(s-i)+(r-o)*(r-o))},o.prototype.distanceSquared=function(t){var e=this.x,i=this.y,o=this.z,n=t.x,s=t.y,r=t.z;return(n-e)*(n-e)+(s-i)*(s-i)+(r-o)*(r-o)},o.prototype.mult=function(t,e){e=e||new o;var i=this.x,n=this.y,s=this.z;return e.x=t*i,e.y=t*n,e.z=t*s,e},o.prototype.vmul=function(t,e){return e=e||new o,e.x=t.x*this.x,e.y=t.y*this.y,e.z=t.z*this.z,e},o.prototype.scale=o.prototype.mult,o.prototype.addScaledVector=function(t,e,i){return i=i||new o,i.x=this.x+t*e.x,i.y=this.y+t*e.y,i.z=this.z+t*e.z,i},o.prototype.dot=function(t){return this.x*t.x+this.y*t.y+this.z*t.z},o.prototype.isZero=function(){return 0===this.x&&0===this.y&&0===this.z},o.prototype.negate=function(t){return t=t||new o,t.x=-this.x,t.y=-this.y,t.z=-this.z,t};var s=new o,r=new o;o.prototype.tangents=function(t,e){var i=this.norm();if(i>0){var o=s,n=1/i;o.set(this.x*n,this.y*n,this.z*n);var a=r;Math.abs(o.x)<.9?(a.set(1,0,0),o.cross(a,t)):(a.set(0,1,0),o.cross(a,t)),o.cross(t,e)}else t.set(1,0,0),e.set(0,1,0)},o.prototype.toString=function(){return this.x+","+this.y+","+this.z},o.prototype.toArray=function(){return[this.x,this.y,this.z]},o.prototype.copy=function(t){return this.x=t.x,this.y=t.y,this.z=t.z,this},o.prototype.lerp=function(t,e,i){var o=this.x,n=this.y,s=this.z;i.x=o+(t.x-o)*e,i.y=n+(t.y-n)*e,i.z=s+(t.z-s)*e},o.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)},o.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 o;o.prototype.isAntiparallelTo=function(t,e){return this.negate(a),a.almostEquals(t,e)},o.prototype.clone=function(){return new o(this.x,this.y,this.z)}},{"./Mat3":40}],44:[function(t,e,i){function o(t){t=t||{},n.apply(this),this.id=o.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?o.STATIC:o.DYNAMIC,typeof t.type==typeof o.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 h,this.aabbNeedsUpdate=!0,this.wlambda=new s,t.shape&&this.addShape(t.shape),this.updateMassProperties()}e.exports=o;var n=t("../utils/EventTarget"),s=(t("../shapes/Shape"),t("../math/Vec3")),r=t("../math/Mat3"),a=t("../math/Quaternion"),h=(t("../material/Material"),t("../collision/AABB")),l=t("../shapes/Box");(o.prototype=new n).constructor=o,o.COLLIDE_EVENT_NAME="collide",o.DYNAMIC=1,o.STATIC=2,o.KINEMATIC=4,o.AWAKE=0,o.SLEEPY=1,o.SLEEPING=2,o.idCounter=0,o.wakeupEvent={type:"wakeup"},o.prototype.wakeUp=function(){var t=this.sleepState;this.sleepState=0,this._wakeUpAfterNarrowphase=!1,t===o.SLEEPING&&this.dispatchEvent(o.wakeupEvent)},o.prototype.sleep=function(){this.sleepState=o.SLEEPING,this.velocity.set(0,0,0),this.angularVelocity.set(0,0,0),this._wakeUpAfterNarrowphase=!1},o.sleepyEvent={type:"sleepy"},o.sleepEvent={type:"sleep"},o.prototype.sleepTick=function(t){if(this.allowSleep){var e=this.sleepState,i=this.velocity.norm2()+this.angularVelocity.norm2(),n=Math.pow(this.sleepSpeedLimit,2);e===o.AWAKE&&in?this.wakeUp():e===o.SLEEPY&&t-this.timeLastSleepy>this.sleepTimeLimit&&(this.sleep(),this.dispatchEvent(o.sleepEvent))}},o.prototype.updateSolveMassProperties=function(){this.sleepState===o.SLEEPING||this.type===o.KINEMATIC?(this.invMassSolve=0,this.invInertiaSolve.setZero(),this.invInertiaWorldSolve.setZero()):(this.invMassSolve=this.invMass,this.invInertiaSolve.copy(this.invInertia),this.invInertiaWorldSolve.copy(this.invInertiaWorld))},o.prototype.pointToLocalFrame=function(t,e){e=e||new s;return t.vsub(this.position,e),this.quaternion.conjugate().vmult(e,e),e},o.prototype.vectorToLocalFrame=function(t,e){e=e||new s;return this.quaternion.conjugate().vmult(t,e),e},o.prototype.pointToWorldFrame=function(t,e){e=e||new s;return this.quaternion.vmult(t,e),e.vadd(this.position,e),e},o.prototype.vectorToWorldFrame=function(t,e){e=e||new s;return this.quaternion.vmult(t,e),e};var c=new s,p=new a;o.prototype.addShape=function(t,e,i){var o=new s,n=new a;return e&&o.copy(e),i&&n.copy(i),this.shapes.push(t),this.shapeOffsets.push(o),this.shapeOrientations.push(n),this.updateMassProperties(),this.updateBoundingRadius(),this.aabbNeedsUpdate=!0,t.body=this,this},o.prototype.updateBoundingRadius=function(){for(var t=this.shapes,e=this.shapeOffsets,i=t.length,o=0,n=0;n!==i;n++){var s=t[n];s.updateBoundingSphereRadius();var r=e[n].norm(),a=s.boundingSphereRadius;r+a>o&&(o=r+a)}this.boundingRadius=o};var u=new h;o.prototype.computeAABB=function(){for(var t=this.shapes,e=this.shapeOffsets,i=this.shapeOrientations,o=t.length,n=c,s=p,r=this.quaternion,a=this.aabb,h=u,l=0;l!==o;l++){var d=t[l];r.vmult(e[l],n),n.vadd(this.position,n),i[l].mult(r,s),d.calculateWorldAABB(n,s,h.lowerBound,h.upperBound),0===l?a.copy(h):a.extend(h)}this.aabbNeedsUpdate=!1};var d=new r,v=new r;new r;o.prototype.updateInertiaWorld=function(t){var e=this.invInertia;if(e.x!==e.y||e.y!==e.z||t){var i=d,o=v;i.setRotationFromQuaternion(this.quaternion),i.transpose(o),i.scale(e,i),i.mmult(o,this.invInertiaWorld)}else;};new s;var y=new s;o.prototype.applyForce=function(t,e){if(this.type===o.DYNAMIC){var i=y;e.cross(t,i),this.force.vadd(t,this.force),this.torque.vadd(i,this.torque)}};var f=new s,m=new s;o.prototype.applyLocalForce=function(t,e){if(this.type===o.DYNAMIC){var i=f,n=m;this.vectorToWorldFrame(t,i),this.vectorToWorldFrame(e,n),this.applyForce(i,n)}};new s;var w=new s,g=new s;o.prototype.applyImpulse=function(t,e){if(this.type===o.DYNAMIC){var i=e,n=w;n.copy(t),n.mult(this.invMass,n),this.velocity.vadd(n,this.velocity);var s=g;i.cross(t,s),this.invInertiaWorld.vmult(s,s),this.angularVelocity.vadd(s,this.angularVelocity)}};var x=new s,b=new s;o.prototype.applyLocalImpulse=function(t,e){if(this.type===o.DYNAMIC){var i=x,n=b;this.vectorToWorldFrame(t,i),this.vectorToWorldFrame(e,n),this.applyImpulse(i,n)}};var E=new s;o.prototype.updateMassProperties=function(){var t=E;this.invMass=this.mass>0?1/this.mass:0;var e=this.inertia,i=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),l.calculateInertia(t,this.mass,e),this.invInertia.set(e.x>0&&!i?1/e.x:0,e.y>0&&!i?1/e.y:0,e.z>0&&!i?1/e.z:0),this.updateInertiaWorld(!0)},o.prototype.getVelocityAtWorldPoint=function(t,e){var i=new s;return t.vsub(this.position,i),this.angularVelocity.cross(i,e),this.velocity.vadd(e,e),e};new s,new s,new a,new a;o.prototype.integrate=function(t,e,i){if(this.previousPosition.copy(this.position),this.previousQuaternion.copy(this.quaternion),(this.type===o.DYNAMIC||this.type===o.KINEMATIC)&&this.sleepState!==o.SLEEPING){var n=this.velocity,s=this.angularVelocity,r=this.position,a=this.force,h=this.torque,l=this.quaternion,c=this.invMass,p=this.invInertiaWorld,u=this.linearFactor,d=c*t;n.x+=a.x*d*u.x,n.y+=a.y*d*u.y,n.z+=a.z*d*u.z;var v=p.elements,y=this.angularFactor,f=h.x*y.x,m=h.y*y.y,w=h.z*y.z;s.x+=t*(v[0]*f+v[1]*m+v[2]*w),s.y+=t*(v[3]*f+v[4]*m+v[5]*w),s.z+=t*(v[6]*f+v[7]*m+v[8]*w),r.x+=n.x*t,r.y+=n.y*t,r.z+=n.z*t,l.integrate(this.angularVelocity,t,this.angularFactor,l),e&&(i?l.normalizeFast():l.normalize()),this.aabbNeedsUpdate=!0,this.updateInertiaWorld()}}},{"../collision/AABB":15,"../material/Material":38,"../math/Mat3":40,"../math/Quaternion":41,"../math/Vec3":43,"../shapes/Box":50,"../shapes/Shape":56,"../utils/EventTarget":62}],45:[function(t,e,i){function o(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,i){var o=b,n=E,s=B,r=A;return e.vsub(t.position,o),o.cross(i,n),t.invInertiaWorld.vmult(n,r),r.cross(o,s),t.invMass+i.dot(s)}t("./Body");var s=t("../math/Vec3"),r=t("../math/Quaternion"),a=(t("../collision/RaycastResult"),t("../collision/Ray")),h=t("../objects/WheelInfo");e.exports=o;new s,new s,new s;var l=new s,c=new s,p=new s;new a;o.prototype.addWheel=function(t){var e=new h(t=t||{}),i=this.wheelInfos.length;return this.wheelInfos.push(e),i},o.prototype.setSteeringValue=function(t,e){this.wheelInfos[e].steering=t};new s;o.prototype.applyEngineForce=function(t,e){this.wheelInfos[e].engineForce=t},o.prototype.setBrake=function(t,e){this.wheelInfos[e].brake=t},o.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},o.prototype.getVehicleAxisWorld=function(t,e){e.set(0===t?1:0,1===t?1:0,2===t?1:0),this.chassisBody.vectorToWorldFrame(e,e)},o.prototype.updateVehicle=function(t){for(var e=this.wheelInfos,i=e.length,o=this.chassisBody,n=0;nd.maxSuspensionForce&&(l=d.maxSuspensionForce),d.raycastResult.hitNormalWorld.scale(l*t,a),d.raycastResult.hitPointWorld.vsub(o.position,h),o.applyImpulse(a,h)}this.updateFriction(t);var c=new s,p=new s,u=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}},o.prototype.updateSuspension=function(t){for(var e=this.chassisBody.mass,i=this.wheelInfos,o=i.length,n=0;ny&&(t.suspensionLength=y,t.raycastResult.reset());var f=t.raycastResult.hitNormalWorld.dot(t.directionWorld),m=new s;o.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},o.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)},o.prototype.updateWheelTransform=function(t){var e=l,i=c,o=p,n=this.wheelInfos[t];this.updateWheelTransformWorld(n),n.directionLocal.scale(-1,e),i.copy(n.axleLocal),e.cross(i,o),o.normalize(),i.normalize();var s=n.steering,a=new r;a.setFromAxisAngle(e,s);var h=new r;h.setFromAxisAngle(i,n.rotation);var u=n.worldTransform.quaternion;this.chassisBody.quaternion.mult(a,u),u.mult(h,u),u.normalize();var d=n.worldTransform.position;d.copy(n.directionWorld),d.scale(n.suspensionLength,d),d.vadd(n.chassisConnectionPointWorld,d)};var v=[new s(1,0,0),new s(0,1,0),new s(0,0,1)];o.prototype.getWheelTransformWorld=function(t){return this.wheelInfos[t].worldTransform};var y=new s,f=[],m=[];o.prototype.updateFriction=function(t){for(var e=y,i=this.wheelInfos,o=i.length,r=this.chassisBody,a=m,h=f,l=0;l1.1)return 0;var r=S,a=R,h=z;return t.getVelocityAtWorldPoint(e,r),i.getVelocityAtWorldPoint(o,a),r.vsub(a,h),-.2*n.dot(h)*(1/(t.invMass+i.invMass))}(r,V.raycastResult.hitPointWorld,d,V.raycastResult.hitPointWorld,c),V.sideImpulse*=1}}this.sliding=!1;for(l=0;lA){this.sliding=!0,V.sliding=!0;var q=B/Math.sqrt(T);V.skidInfo*=q}}}if(this.sliding)for(l=0;lthis.particles.length&&this.neighbors.pop())};var s=new n;o.prototype.getNeighbors=function(t,e){for(var i=this.particles.length,o=t.id,n=this.smoothingRadius*this.smoothingRadius,r=s,a=0;a!==i;a++){var h=this.particles[a];h.position.vsub(t.position,r),o!==h.id&&r.norm2()=-.1)this.suspensionRelativeVelocity=0,this.clippedInvContactDotSuspension=10;else{var n=-1/i;this.suspensionRelativeVelocity=o*n,this.clippedInvContactDotSuspension=n}}else e.suspensionLength=this.suspensionRestLength,this.suspensionRelativeVelocity=0,e.directionWorld.scale(-1,e.hitNormalWorld),this.clippedInvContactDotSuspension=1}},{"../collision/RaycastResult":23,"../math/Transform":42,"../math/Vec3":43,"../utils/Utils":66}],50:[function(t,e,i){function o(t){n.call(this),this.type=n.types.BOX,this.halfExtents=t,this.convexPolyhedronRepresentation=null,this.updateConvexPolyhedronRepresentation(),this.updateBoundingSphereRadius()}e.exports=o;var n=t("./Shape"),s=t("../math/Vec3"),r=t("./ConvexPolyhedron");(o.prototype=new n).constructor=o,o.prototype.updateConvexPolyhedronRepresentation=function(){var t=this.halfExtents.x,e=this.halfExtents.y,i=this.halfExtents.z,o=s,n=[new o(-t,-e,-i),new o(t,-e,-i),new o(t,e,-i),new o(-t,e,-i),new o(-t,-e,i),new o(t,-e,i),new o(t,e,i),new o(-t,e,i)],a=(new o(0,0,1),new o(0,1,0),new o(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},o.prototype.calculateLocalInertia=function(t,e){return e=e||new s,o.calculateInertia(this.halfExtents,t,e),e},o.calculateInertia=function(t,e,i){var o=t;i.x=1/12*e*(2*o.y*2*o.y+2*o.z*2*o.z),i.y=1/12*e*(2*o.x*2*o.x+2*o.z*2*o.z),i.z=1/12*e*(2*o.y*2*o.y+2*o.x*2*o.x)},o.prototype.getSideNormals=function(t,e){var i=t,o=this.halfExtents;if(i[0].set(o.x,0,0),i[1].set(0,o.y,0),i[2].set(0,0,o.z),i[3].set(-o.x,0,0),i[4].set(0,-o.y,0),i[5].set(0,0,-o.z),void 0!==e)for(var n=0;n!==i.length;n++)e.vmult(i[n],i[n]);return i},o.prototype.volume=function(){return 8*this.halfExtents.x*this.halfExtents.y*this.halfExtents.z},o.prototype.updateBoundingSphereRadius=function(){this.boundingSphereRadius=this.halfExtents.norm()};var a=new s;new s;o.prototype.forEachWorldCorner=function(t,e,i){for(var o=this.halfExtents,n=[[o.x,o.y,o.z],[-o.x,o.y,o.z],[-o.x,-o.y,o.z],[-o.x,-o.y,-o.z],[o.x,-o.y,-o.z],[o.x,o.y,-o.z],[-o.x,o.y,-o.z],[o.x,-o.y,o.z]],s=0;so.x&&(o.x=a),l>o.y&&(o.y=l),c>o.z&&(o.z=c),ad&&(d=y,u=v)}for(var f=[],m=i.faces[u],w=m.length,g=0;g=0&&this.clipFaceAgainstHull(r,t,e,f,a,h,l)};var p=new s,u=new s,d=new s,v=new s,y=new s,f=new s;o.prototype.findSeparatingAxis=function(t,e,i,o,n,s,r,a){var h=p,l=u,c=d,m=v,w=y,g=f,x=Number.MAX_VALUE,b=this;if(b.uniqueAxes)for(B=0;B!==b.uniqueAxes.length;B++){i.vmult(b.uniqueAxes[B],h);if(!1===(R=b.testSepAxis(h,t,e,i,o,n)))return!1;R0&&s.negate(s),!0};var m=[],w=[];o.prototype.testSepAxis=function(t,e,i,n,s,r){o.project(this,t,i,n,m),o.project(e,t,s,r,w);var a=m[0],h=m[1],l=w[0],c=w[1];if(ae&&(e=n)}this.maxValue=e},o.prototype.setHeightValueAtIndex=function(t,e,i){this.data[t][e]=i,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)},o.prototype.getRectMinMax=function(t,e,i,o,n){n=n||[];for(var s=this.data,r=this.minValue,a=t;a<=i;a++)for(var h=e;h<=o;h++){var l=s[a][h];l>r&&(r=l)}n[0]=this.minValue,n[1]=r},o.prototype.getIndexOfPosition=function(t,e,i,o){var n=this.elementSize,s=this.data,r=Math.floor(t/n),a=Math.floor(e/n);return i[0]=r,i[1]=a,o&&(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 h=[],l=new r,c=new r,p=new r,u=new r;o.prototype.getTriangleAt=function(t,e,i,o,n,s){var r=h;this.getIndexOfPosition(t,e,r,i);var a=r[0],l=r[1],c=this.data;i&&(a=Math.min(c.length-2,Math.max(0,a)),l=Math.min(c[0].length-2,Math.max(0,l)));var p=this.elementSize,u=Math.pow(t/p-a,2)+Math.pow(e/p-l,2)>Math.pow(t/p-(a+1),2)+Math.pow(e/p-(l+1),2);return this.getTriangle(a,l,u,o,n,s),u};var d=new r,v=new r,y=new r,f=new r,m=new r;o.prototype.getNormalAt=function(t,e,i,o){var n=d,s=v,r=y,a=f,h=m;this.getTriangleAt(t,e,i,n,s,r),s.vsub(n,a),r.vsub(n,h),a.cross(h,o),o.normalize()},o.prototype.getAabbAtIndex=function(t,e,i){var o=this.data,n=this.elementSize;i.lowerBound.set(t*n,e*n,o[t][e]),i.upperBound.set((t+1)*n,(e+1)*n,o[t+1][e+1])},o.prototype.getHeightAt=function(t,e,i){var o=this.data,n=c,s=p,r=u,a=h;this.getIndexOfPosition(t,e,a,i);var d=a[0],v=a[1];i&&(d=Math.min(o.length-2,Math.max(0,d)),v=Math.min(o[0].length-2,Math.max(0,v)));var y=this.getTriangleAt(t,e,i,n,s,r);!function(t,e,i,o,n,s,r,a,h){h.x=((s-a)*(t-r)+(r-n)*(e-a))/((s-a)*(i-r)+(r-n)*(o-a)),h.y=((a-o)*(t-r)+(i-r)*(e-a))/((s-a)*(i-r)+(r-n)*(o-a)),h.z=1-h.x-h.y}(t,e,n.x,n.y,s.x,s.y,r.x,r.y,l);var f=l;return y?o[d+1][v+1]*f.x+o[d][v+1]*f.y+o[d+1][v]*f.z:o[d][v]*f.x+o[d+1][v]*f.y+o[d][v+1]*f.z},o.prototype.getCacheConvexTrianglePillarKey=function(t,e,i){return t+"_"+e+"_"+(i?1:0)},o.prototype.getCachedConvexTrianglePillar=function(t,e,i){return this._cachedPillars[this.getCacheConvexTrianglePillarKey(t,e,i)]},o.prototype.setCachedConvexTrianglePillar=function(t,e,i,o,n){this._cachedPillars[this.getCacheConvexTrianglePillarKey(t,e,i)]={convex:o,offset:n}},o.prototype.clearCachedConvexTrianglePillar=function(t,e,i){delete this._cachedPillars[this.getCacheConvexTrianglePillarKey(t,e,i)]},o.prototype.getTriangle=function(t,e,i,o,n,s){var r=this.data,a=this.elementSize;i?(o.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])):(o.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]))},o.prototype.getConvexTrianglePillar=function(t,e,i){var o=this.pillarConvex,n=this.pillarOffset;if(this.cacheEnabled){if(a=this.getCachedConvexTrianglePillar(t,e,i))return this.pillarConvex=a.convex,void(this.pillarOffset=a.offset);o=new s,n=new r,this.pillarConvex=o,this.pillarOffset=n}var a=this.data,h=this.elementSize,l=o.faces;o.vertices.length=6;for(c=0;c<6;c++)o.vertices[c]||(o.vertices[c]=new r);l.length=5;for(var c=0;c<5;c++)l[c]||(l[c]=[]);var p=o.vertices,u=(Math.min(a[t][e],a[t+1][e],a[t][e+1],a[t+1][e+1])-this.minValue)/2+this.minValue;i?(n.set((t+.75)*h,(e+.75)*h,u),p[0].set(.25*h,.25*h,a[t+1][e+1]-u),p[1].set(-.75*h,.25*h,a[t][e+1]-u),p[2].set(.25*h,-.75*h,a[t+1][e]-u),p[3].set(.25*h,.25*h,-u-1),p[4].set(-.75*h,.25*h,-u-1),p[5].set(.25*h,-.75*h,-u-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):(n.set((t+.25)*h,(e+.25)*h,u),p[0].set(-.25*h,-.25*h,a[t][e]-u),p[1].set(.75*h,-.25*h,a[t+1][e]-u),p[2].set(-.25*h,.75*h,a[t][e+1]-u),p[3].set(-.25*h,-.25*h,-u-1),p[4].set(.75*h,-.25*h,-u-1),p[5].set(-.25*h,.75*h,-u-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),o.computeNormals(),o.computeEdges(),o.updateBoundingSphereRadius(),this.setCachedConvexTrianglePillar(t,e,i,o,n)},o.prototype.calculateLocalInertia=function(t,e){return(e=e||new r).set(0,0,0),e},o.prototype.volume=function(){return Number.MAX_VALUE},o.prototype.calculateWorldAABB=function(t,e,i,o){i.set(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE),o.set(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE)},o.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()},o.prototype.setHeightsFromImage=function(t,e){var i=document.createElement("canvas");i.width=t.width,i.height=t.height;var o=i.getContext("2d");o.drawImage(t,0,0);var n=o.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;ri.x&&(i.x=n.x),n.yi.y&&(i.y=n.y),n.zi.z&&(i.z=n.z)},o.prototype.updateAABB=function(){this.computeLocalAABB(this.aabb)},o.prototype.updateBoundingSphereRadius=function(){for(var t=0,e=this.vertices,i=new s,o=0,n=e.length/3;o!==n;o++){this.getVertex(o,i);var r=i.norm2();r>t&&(t=r)}this.boundingSphereRadius=Math.sqrt(t)};new s;var x=new r,b=new a;o.prototype.calculateWorldAABB=function(t,e,i,o){var n=x,s=b;n.position=t,n.quaternion=e,this.aabb.toWorldFrame(n,s),i.copy(s.lowerBound),o.copy(s.upperBound)},o.prototype.volume=function(){return 4*Math.PI*this.boundingSphereRadius/3},o.createTorus=function(t,e,i,n,s){t=t||1,e=e||.5,i=i||8,n=n||6,s=s||2*Math.PI;for(var r=[],a=[],h=0;h<=i;h++)for(v=0;v<=n;v++){var l=v/n*s,c=h/i*Math.PI*2,p=(t+e*Math.cos(c))*Math.cos(l),u=(t+e*Math.cos(c))*Math.sin(l),d=e*Math.sin(c);r.push(p,u,d)}for(h=1;h<=i;h++)for(var v=1;v<=n;v++){var y=(n+1)*h+v-1,f=(n+1)*(h-1)+v-1,m=(n+1)*(h-1)+v,w=(n+1)*h+v;a.push(y,f,w),a.push(f,m,w)}return new o(r,a)}},{"../collision/AABB":15,"../math/Quaternion":41,"../math/Transform":42,"../math/Vec3":43,"../utils/Octree":63,"./Shape":56}],59:[function(t,e,i){function o(){n.call(this),this.iterations=10,this.tolerance=1e-7}e.exports=o;t("../math/Vec3"),t("../math/Quaternion");var n=t("./Solver"),s=[],r=[],a=[];(o.prototype=new n).solve=function(t,e){var i,o,n,h,l,c=0,p=this.iterations,u=this.tolerance*this.tolerance,d=this.equations,v=d.length,y=e.bodies,f=y.length,m=t;if(0!==v)for(S=0;S!==f;S++)y[S].updateSolveMassProperties();var w=r,g=a,x=s;w.length=v,g.length=v,x.length=v;for(S=0;S!==v;S++){A=d[S];x[S]=0,g[S]=A.computeB(m),w[S]=1/A.computeC()}if(0!==v){for(S=0;S!==f;S++){var b=(R=y[S]).vlambda,E=R.wlambda;b.set(0,0,0),E.set(0,0,0)}for(c=0;c!==p;c++){h=0;for(var B=0;B!==v;B++){var A=d[B];i=g[B],o=w[B],(l=x[B])+(n=o*(i-A.computeGWlambda()-A.eps*l))A.maxForce&&(n=A.maxForce-l),x[B]+=n,h+=n>0?n:-n,A.addToWlambda(n)}if(h*h=0;i--)e.children[i].data.length||e.children.splice(i,1);Array.prototype.push.apply(t,e.children)}}},{"../collision/AABB":15,"../math/Vec3":43}],64:[function(t,e,i){function o(){this.objects=[],this.type=Object}e.exports=o,o.prototype.release=function(){for(var t=arguments.length,e=0;e!==t;e++)this.objects.push(arguments[e]);return this},o.prototype.get=function(){return 0===this.objects.length?this.constructObject():this.objects.pop()},o.prototype.constructObject=function(){throw new Error("constructObject() not implemented in this Pool subclass yet!")},o.prototype.resize=function(t){for(var e=this.objects;e.length>t;)e.pop();for(;e.lengthe){var i=e;e=t,t=i}return this.data[t+"-"+e]},o.prototype.set=function(t,e,i){if(t>e){var o=e;e=t,t=o}var n=t+"-"+e;this.get(t,e)||this.data.keys.push(n),this.data[n]=i},o.prototype.reset=function(){for(var t=this.data,e=t.keys;e.length>0;){delete t[e.pop()]}}},{}],66:[function(t,e,i){function o(){}e.exports=o,o.defaults=function(t,e){t=t||{};for(var i in e)i in t||(t[i]=e[i]);return t}},{}],67:[function(t,e,i){function o(){s.call(this),this.type=n}e.exports=o;var n=t("../math/Vec3"),s=t("./Pool");(o.prototype=new s).constructObject=function(){return new n}},{"../math/Vec3":43,"./Pool":64}],68:[function(t,e,i){function o(t){this.contactPointPool=[],this.frictionEquationPool=[],this.result=[],this.frictionResult=[],this.v3pool=new u,this.world=t,this.currentContactMaterial=null,this.enableFrictionReduction=!1}function n(t,e,i){for(var o=null,n=t.length,s=0;s!==n;s++){var r=t[s],a=k;t[(s+1)%n].vsub(r,a);var h=_;a.cross(e,h);var l=D;i.vsub(r,l);var c=h.dot(l);if(!(null===o||c>0&&!0===o||c<=0&&!1===o))return!1;null===o&&(o=c>0)}return!0}e.exports=o;var s=t("../collision/AABB"),r=t("../objects/Body"),a=t("../shapes/Shape"),h=t("../collision/Ray"),l=t("../math/Vec3"),c=t("../math/Transform"),p=(t("../shapes/ConvexPolyhedron"),t("../math/Quaternion")),u=(t("../solver/Solver"),t("../utils/Vec3Pool")),d=t("../equations/ContactEquation"),v=t("../equations/FrictionEquation");o.prototype.createContactEquation=function(t,e,i,o,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&&i.collisionResponse&&o.collisionResponse;var a=this.currentContactMaterial;r.restitution=a.restitution,r.setSpookParams(a.contactEquationStiffness,a.contactEquationRelaxation,this.world.dt);var h=i.material||t.material,l=o.material||e.material;return h&&l&&h.restitution>=0&&l.restitution>=0&&(r.restitution=h.restitution*l.restitution),r.si=n||i,r.sj=s||o,r},o.prototype.createFrictionEquationsFromContact=function(t,e){var i=t.bi,o=t.bj,n=t.si,s=t.sj,r=this.world,a=this.currentContactMaterial,h=a.friction,l=n.material||i.material,c=s.material||o.material;if(l&&c&&l.friction>=0&&c.friction>=0&&(h=l.friction*c.friction),h>0){var p=h*r.gravity.length(),u=i.invMass+o.invMass;u>0&&(u=1/u);var d=this.frictionEquationPool,y=d.length?d.pop():new v(i,o,p*u),f=d.length?d.pop():new v(i,o,p*u);return y.bi=f.bi=i,y.bj=f.bj=o,y.minForce=f.minForce=-p*u,y.maxForce=f.maxForce=p*u,y.ri.copy(t.ri),y.rj.copy(t.rj),f.ri.copy(t.ri),f.rj.copy(t.rj),t.ni.tangents(y.t,f.t),y.setSpookParams(a.frictionEquationStiffness,a.frictionEquationRelaxation,r.dt),f.setSpookParams(a.frictionEquationStiffness,a.frictionEquationRelaxation,r.dt),y.enabled=f.enabled=t.enabled,e.push(y,f),!0}return!1};var y=new l,f=new l,m=new l;o.prototype.createFrictionFromAverage=function(t){var e=this.result[this.result.length-1];if(this.createFrictionEquationsFromContact(e,this.frictionResult)&&1!==t){var i=this.frictionResult[this.frictionResult.length-2],o=this.frictionResult[this.frictionResult.length-1];y.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?(y.vadd(e.ni,y),f.vadd(e.ri,f),m.vadd(e.rj,m)):(y.vsub(e.ni,y),f.vadd(e.rj,f),m.vadd(e.ri,m));var r=1/t;f.scale(r,i.ri),m.scale(r,i.rj),o.ri.copy(i.ri),o.rj.copy(i.rj),y.normalize(),y.tangents(i.t,o.t)}};var w=new l,g=new l,x=new p,b=new p;o.prototype.getContacts=function(t,e,i,o,n,s,a){this.contactPointPool=n,this.frictionEquationPool=a,this.result=o,this.frictionResult=s;for(var h=x,l=b,c=w,p=g,u=0,d=t.length;u!==d;u++){var v=t[u],y=e[u],f=null;v.material&&y.material&&(f=i.getContactMaterial(v.material,y.material)||null);for(var m=v.type&r.KINEMATIC&&y.type&r.STATIC||v.type&r.STATIC&&y.type&r.KINEMATIC||v.type&r.KINEMATIC&&y.type&r.KINEMATIC,E=0;EB.boundingSphereRadius+S.boundingSphereRadius)){var R=null;B.material&&S.material&&(R=i.getContactMaterial(B.material,S.material)||null),this.currentContactMaterial=R||f||i.defaultContactMaterial;var z=this[B.type|S.type];if(z){(B.type0&&_<0){m.vsub(d,w),f.copy(y),f.normalize(),D=w.dot(f),f.scale(D,w),w.vadd(d,w);if((Z=w.distanceTo(m))0){var M=X,C=Q;M.copy(u[(B+1)%3]),C.copy(u[(B+2)%3]);var T=M.norm(),q=C.norm();M.normalize(),C.normalize();var V=G.dot(M),F=G.dot(C);if(V-T&&F-q){H=Math.abs(z-R-d);if((null===E||H0){for(var q=[],V=0,F=A.length;V!==F;V++){var P=u.get();r.vmult(y[A[V]],P),o.vadd(P,P),q.push(P)}if(n(q,S,i)){if(p)return!0;b=!0;U=this.createContactEquation(a,h,t,e,l,c);S.mult(-f,U.ri),S.negate(U.ni);var N=u.get();S.mult(-C,N);var I=u.get();S.mult(-f,I),i.vsub(o,U.rj),U.rj.vadd(I,U.rj),U.rj.vadd(N,U.rj),U.rj.vadd(o,U.rj),U.rj.vsub(h.position,U.rj),U.ri.vadd(i,U.ri),U.ri.vsub(a.position,U.ri),u.release(N),u.release(I),this.result.push(U),this.createFrictionEquationsFromContact(U,this.frictionResult);for(var V=0,L=q.length;V!==L;V++)u.release(q[V]);return}for(V=0;V!==A.length;V++){var j=u.get(),W=u.get();r.vmult(y[A[(V+1)%A.length]],j),r.vmult(y[A[(V+2)%A.length]],W),o.vadd(j,j),o.vadd(W,W);var O=et;W.vsub(j,O);var H=it;O.unit(H);var k=u.get(),_=u.get();i.vsub(j,_);var D=_.dot(H);H.mult(D,k),k.vadd(j,k);var G=u.get();if(k.vsub(i,G),D>0&&D*Dt.boundingSphereRadius+e.boundingSphereRadius)&&t.findSeparatingAxis(e,i,n,o,s,d,p,u)){var v=[],y=yt;t.clipAgainstHull(i,n,e,o,s,d,-100,100,v);for(var f=0,m=0;m!==v.length;m++){if(c)return!0;var w=this.createContactEquation(r,a,t,e,h,l),g=w.ri,x=w.rj;d.negate(w.ni),v[m].normal.negate(y),y.mult(v[m].depth,y),v[m].point.vadd(y,g),x.copy(v[m].point),g.vsub(i,g),x.vsub(o,x),g.vadd(i,g),g.vsub(r.position,g),x.vadd(o,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 l,mt=new l,wt=new l;o.prototype[a.types.PLANE|a.types.PARTICLE]=o.prototype.planeParticle=function(t,e,i,o,n,s,r,a,h,l,c){var p=ft;p.set(0,0,1),r.quaternion.vmult(p,p);var u=mt;o.vsub(r.position,u);if(p.dot(u)<=0){if(c)return!0;var d=this.createContactEquation(a,r,e,t,h,l);d.ni.copy(p),d.ni.negate(d.ni),d.ri.set(0,0,0);var v=wt;p.mult(p.dot(o),v),o.vsub(v,v),d.rj.copy(v),this.result.push(d),this.createFrictionEquationsFromContact(d,this.frictionResult)}};var gt=new l;o.prototype[a.types.PARTICLE|a.types.SPHERE]=o.prototype.sphereParticle=function(t,e,i,o,n,s,r,a,h,l,c){var p=gt;p.set(0,0,1),o.vsub(i,p);if(p.norm2()<=t.radius*t.radius){if(c)return!0;var u=this.createContactEquation(a,r,e,t,h,l);p.normalize(),u.rj.copy(p),u.rj.mult(t.radius,u.rj),u.ni.copy(p),u.ni.negate(u.ni),u.ri.set(0,0,0),this.result.push(u),this.createFrictionEquationsFromContact(u,this.frictionResult)}};var xt=new p,bt=new l,Et=(new l,new l),Bt=new l,At=new l;o.prototype[a.types.PARTICLE|a.types.CONVEXPOLYHEDRON]=o.prototype.convexParticle=function(t,e,i,o,n,s,r,a,h,l,c){var p=-1,u=Et,d=At,v=null,y=bt;if(y.copy(o),y.vsub(i,y),n.conjugate(xt),xt.vmult(y,y),t.pointIsInside(y)){t.worldVerticesNeedsUpdate&&t.computeWorldVertices(i,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];o.vsub(w[0],Bt);var x=-g.dot(Bt);if(null===v||Math.abs(x)u.length||x>u[0].length)){w<0&&(w=0),g<0&&(g=0),x<0&&(x=0),b<0&&(b=0),w>=u.length&&(w=u.length-1),g>=u.length&&(g=u.length-1),b>=u[0].length&&(b=u[0].length-1),x>=u[0].length&&(x=u[0].length-1);var E=[];e.getRectMinMax(w,x,g,b,E);var B=E[0],A=E[1];if(!(m.z-v>A||m.z+vu.length||x>u[0].length)){m<0&&(m=0),w<0&&(w=0),g<0&&(g=0),x<0&&(x=0),m>=u.length&&(m=u.length-1),w>=u.length&&(w=u.length-1),x>=u[0].length&&(x=u[0].length-1),g>=u[0].length&&(g=u[0].length-1);var b=[];e.getRectMinMax(m,g,w,x,b);var E=b[0],B=b[1];if(!(f.z-d>B||f.z+d2)return}}}},{"../collision/AABB":15,"../collision/Ray":22,"../equations/ContactEquation":32,"../equations/FrictionEquation":34,"../math/Quaternion":41,"../math/Transform":42,"../math/Vec3":43,"../objects/Body":44,"../shapes/ConvexPolyhedron":51,"../shapes/Shape":56,"../solver/Solver":60,"../utils/Vec3Pool":67}],69:[function(t,e,i){function o(t){t=t||{},h.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 l,this.collisionMatrixPrevious=new l,this.bodyOverlapKeeper=new c,this.shapeOverlapKeeper=new c,this.materials=[],this.contactmaterials=[],this.contactMaterialTable=new v,this.defaultMaterial=new p("default"),this.defaultContactMaterial=new u(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=o;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")),h=t("../utils/EventTarget"),l=t("../collision/ArrayCollisionMatrix"),c=t("../collision/OverlapKeeper"),p=t("../material/Material"),u=t("../material/ContactMaterial"),d=t("../objects/Body"),v=t("../utils/TupleDictionary"),y=t("../collision/RaycastResult"),f=t("../collision/AABB"),m=t("../collision/Ray"),w=t("../collision/NaiveBroadphase");o.prototype=new h;new f;var g=new m;if(o.prototype.getContactMaterial=function(t,e){return this.contactMaterialTable.get(t.id,e.id)},o.prototype.numObjects=function(){return this.bodies.length},o.prototype.collisionMatrixTick=function(){var t=this.collisionMatrixPrevious;this.collisionMatrixPrevious=this.collisionMatrix,this.collisionMatrix=t,this.collisionMatrix.reset(),this.bodyOverlapKeeper.tick(),this.shapeOverlapKeeper.tick()},o.prototype.add=o.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))},o.prototype.addConstraint=function(t){this.constraints.push(t)},o.prototype.removeConstraint=function(t){var e=this.constraints.indexOf(t);-1!==e&&this.constraints.splice(e,1)},o.prototype.rayTest=function(t,e,i){i instanceof y?this.raycastClosest(t,e,{skipBackfaces:!0},i):this.raycastAll(t,e,{skipBackfaces:!0},i)},o.prototype.raycastAll=function(t,e,i,o){return i.mode=m.ALL,i.from=t,i.to=e,i.callback=o,g.intersectWorld(this,i)},o.prototype.raycastAny=function(t,e,i,o){return i.mode=m.ANY,i.from=t,i.to=e,i.result=o,g.intersectWorld(this,i)},o.prototype.raycastClosest=function(t,e,i,o){return i.mode=m.CLOSEST,i.from=t,i.to=e,i.result=o,g.intersectWorld(this,i)},o.prototype.remove=function(t){t.world=null;var e=this.bodies.length-1,i=this.bodies,o=i.indexOf(t);if(-1!==o){i.splice(o,1);for(var n=0;n!==i.length;n++)i[n].index=n;this.collisionMatrix.setNumObjects(e),this.removeBodyEvent.body=t,delete this.idToBodyMap[t.id],this.dispatchEvent(this.removeBodyEvent)}},o.prototype.removeBody=o.prototype.remove,o.prototype.getBodyById=function(t){return this.idToBodyMap[t]},o.prototype.getShapeById=function(t){for(var e=this.bodies,i=0,o=e.length;i=t&&o=0;O-=1)(W.bodyA===o[O]&&W.bodyB===n[O]||W.bodyB===o[O]&&W.bodyA===n[O])&&(o.splice(O,1),n.splice(O,1))}this.collisionMatrixTick(),l&&(e=performance.now());var C=A,T=i.length;for(w=0;w!==T;w++)C.push(i[w]);i.length=0;var q=this.frictionEquations.length;for(w=0;w!==q;w++)v.push(this.frictionEquations[w]);this.frictionEquations.length=0,this.narrowphase.getContacts(o,n,this,i,C,this.frictionEquations,v),l&&(c.narrowphase=performance.now()-e),l&&(e=performance.now());for(w=0;w=0&&N.material.friction>=0&&P.material.friction*N.material.friction,P.material.restitution>=0&&N.material.restitution>=0&&(W.restitution=P.material.restitution*N.material.restitution)),a.addEquation(W),P.allowSleep&&P.type===d.DYNAMIC&&P.sleepState===d.SLEEPING&&N.sleepState===d.AWAKE&&N.type!==d.STATIC){N.velocity.norm2()+N.angularVelocity.norm2()>=2*Math.pow(N.sleepSpeedLimit,2)&&(P._wakeUpAfterNarrowphase=!0)}if(N.allowSleep&&N.type===d.DYNAMIC&&N.sleepState===d.SLEEPING&&P.sleepState===d.AWAKE&&P.type!==d.STATIC){P.velocity.norm2()+P.angularVelocity.norm2()>=2*Math.pow(P.sleepSpeedLimit,2)&&(N._wakeUpAfterNarrowphase=!0)}this.collisionMatrix.set(P,N,!0),this.collisionMatrixPrevious.get(P,N)||(B.body=N,B.contact=W,P.dispatchEvent(B),B.body=P,N.dispatchEvent(B)),this.bodyOverlapKeeper.set(P.id,N.id),this.shapeOverlapKeeper.set(I.id,L.id)}for(this.emitContactEvents(),l&&(c.makeContactConstraints=performance.now()-e,e=performance.now()),w=0;w!==s;w++){(P=r[w])._wakeUpAfterNarrowphase&&(P.wakeUp(),P._wakeUpAfterNarrowphase=!1)}var j=u.length;for(w=0;w!==j;w++){var W=u[w];W.update();for(var O=0,H=W.equations.length;O!==H;O++){var k=W.equations[O];a.addEquation(k)}}a.solve(t,this),l&&(c.solve=performance.now()-e),a.removeAllEquations();var _=Math.pow;for(w=0;w!==s;w++){if((P=r[w]).type&p){var D=_(1-P.linearDamping,t),G=P.velocity;G.mult(D,G);var U=P.angularVelocity;if(U){var X=_(1-P.angularDamping,t);U.mult(X,U)}}}for(this.dispatchEvent(E),w=0;w!==s;w++){(P=r[w]).preStep&&P.preStep.call(P)}l&&(e=performance.now());var Q=this.stepnumber%(this.quatNormalizeSkip+1)==0,Y=this.quatNormalizeFast;for(w=0;w!==s;w++)r[w].integrate(t,Q,Y);for(this.clearForces(),this.broadphase.dirty=!0,l&&(c.integrate=performance.now()-e),this.time+=t,this.stepnumber+=1,this.dispatchEvent(b),w=0;w!==s;w++){var Z=(P=r[w]).postStep;Z&&Z.call(P)}if(this.allowSleep)for(w=0;w!==s;w++)r[w].sleepTick(this.time)},o.prototype.emitContactEvents=function(){var t=[],e=[],i={type:"beginContact",bodyA:null,bodyB:null},o={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 h=0,l=t.length;h0;)!function(t,o){var n,s=B.length,r=[t],a=o.indexOf(t.visiblePoints.pop());for(;s-- >0;)(n=B[s])!==t&&e(n,o).dot(g.subVectors(o[a],o[n[0]]))>0&&r.push(n);var h,l,c,p,u=s=r.length,d=1===s,v=[],y=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],v=[n[0],n[1],n[1],n[2],n[2],n[0]],A.indexOf(n)>-1&&A.splice(A.indexOf(n),1),n.visiblePoints&&(f=f.concat(n.visiblePoints)),B.splice(B.indexOf(n),1);else for(;s-- >0;){n=r[s],A.indexOf(n)>-1&&A.splice(A.indexOf(n),1),n.visiblePoints&&(f=f.concat(n.visiblePoints)),B.splice(B.indexOf(n),1);var m;for(cEdgeIndex=0;cEdgeIndex<3;){for(m=!1,u=r.length,c=n[cEdgeIndex],p=n[(cEdgeIndex+1)%3];u-- >0&&!m;)if(h=r[u],y=0,h!==n)for(;y<3&&!m;)l=y+1,m=h[y]===c&&h[l%3]===p||h[y]===p&&h[l%3]===c,y++;m&&!d||(v.push(c),v.push(p)),cEdgeIndex++}}s=0;var w,x=v.length/2;for(;s0&&s[i[a].x/3]>0;);a+10&&(t.visiblePoints=i.splice(a+1))}var o,n,s,r,a,h,l,c,p,u,d,v,y,f,m,w,g,x,b,E,B=[],A=[],S=0,R=function(){var t=new THREE.Vector3,e=new THREE.Vector3,i=new THREE.Vector3;return function(o,n,s){return t.subVectors(s,o),e.subVectors(n,o),i.crossVectors(t,e),i.normalize()}}(),z=function(){var t=new THREE.Vector3,e=new THREE.Vector3,i=new THREE.Vector3;return function(o,n,s){t.subVectors(n,o),e.subVectors(s,o),i.subVectors(s,n);var r=e.dot(t);if(r<0)return e.dot(e);var a=t.dot(t);return r>=a?i.dot(i):e.dot(e)-r*r/a}}();return function(e){for(d=new THREE.Vector3,v=new THREE.Vector3,y=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,B=[],A=[],P=o=points.length,n=points.slice(0,6),S=0;P-- >0;)points[P].xn[1].x&&(n[1]=points[P]),points[P].y0;)for(r=P-1;r-- >0;)S<(s=n[P].distanceToSquared(n[r]))&&(S=s,a=n[P],h=n[r]);for(P=6,S=0;P-- >0;)s=z(a,h,n[P]),S0;)s=Math.abs(points[P].dot(p)-u),S0;)i(V[P],F,points),void 0!==V[P].visiblePoints&&A.push(V[P]),B.push(V[P]);t(points);for(var N=B.length;N-- >0;)e.faces[N]=new THREE.Face3(B[N][2],B[N][1],B[N][0],B[N].normal);return e.normalsNeedUpdate=!0,e}}()},{}],72:[function(t,e,i){e.exports={schema:{offset:{default:{x:0,y:0,z:0},type:"vec3"}},init:function(){this.active=!1,this.targetEl=null,this.fire=this.fire.bind(this),this.offset=new THREE.Vector3},update:function(){this.offset.copy(this.data.offset)},play:function(){this.el.addEventListener("click",this.fire)},pause:function(){this.el.removeEventListener("click",this.fire)},remove:function(){this.pause()},fire:function(){var t=this.el.sceneEl.querySelector("[checkpoint-controls]");if(!t)throw new Error("No `checkpoint-controls` component found.");t.components["checkpoint-controls"].setCheckpoint(this.el)},getOffset:function(){return this.offset.copy(this.data.offset)}}},{}],73:[function(t,e,i){e.exports={schema:{path:{default:""},extension:{default:"jpg"},format:{default:"RGBFormat"},enableBackground:{default:!1}},init:function(){var t=this.data;this.texture=(new THREE.CubeTextureLoader).load([t.path+"posx."+t.extension,t.path+"negx."+t.extension,t.path+"posy."+t.extension,t.path+"negy."+t.extension,t.path+"posz."+t.extension,t.path+"negz."+t.extension]),this.texture.format=THREE[t.format],t.enableBackground&&(this.el.sceneEl.object3D.background=this.texture),this.applyEnvMap(),this.el.addEventListener("object3dset",this.applyEnvMap.bind(this))},applyEnvMap:function(){var t=this.el.getObject3D("mesh"),e=this.texture;t&&t.traverse(function(t){t.material&&"envMap"in t.material&&(t.material.envMap=e,t.material.needsUpdate=!0)})}}},{}],74:[function(t,e,i){e.exports={init:function(){this.GRABBED_STATE="grabbed",this.grabbing=!1,this.hitEl=null,this.physics=this.el.sceneEl.systems.physics,this.constraint=null,this.onHit=this.onHit.bind(this),this.onGripOpen=this.onGripOpen.bind(this),this.onGripClose=this.onGripClose.bind(this)},play:function(){var t=this.el;t.addEventListener("hit",this.onHit),t.addEventListener("gripdown",this.onGripClose),t.addEventListener("gripup",this.onGripOpen),t.addEventListener("trackpaddown",this.onGripClose),t.addEventListener("trackpadup",this.onGripOpen),t.addEventListener("triggerdown",this.onGripClose),t.addEventListener("triggerup",this.onGripOpen)},pause:function(){var t=this.el;t.removeEventListener("hit",this.onHit),t.removeEventListener("gripdown",this.onGripClose),t.removeEventListener("gripup",this.onGripOpen),t.removeEventListener("trackpaddown",this.onGripClose),t.removeEventListener("trackpadup",this.onGripOpen),t.removeEventListener("triggerdown",this.onGripClose),t.removeEventListener("triggerup",this.onGripOpen)},onGripClose:function(t){this.grabbing=!0},onGripOpen:function(t){var e=this.hitEl;this.grabbing=!1,e&&(e.removeState(this.GRABBED_STATE),this.hitEl=void 0,this.physics.world.removeConstraint(this.constraint),this.constraint=null)},onHit:function(t){var e=t.detail.el;e&&!e.is(this.GRABBED_STATE)&&this.grabbing&&!this.hitEl&&(e.addState(this.GRABBED_STATE),this.hitEl=e,this.constraint=new CANNON.LockConstraint(this.el.body,e.body),this.physics.world.addConstraint(this.constraint))}}},{}],75:[function(t,e,i){var o=t("aframe-physics-system");e.exports={checkpoint:t("./checkpoint"),"cube-env-map":t("./cube-env-map"),grab:t("./grab"),"jump-ability":t("./jump-ability"),"kinematic-body":t("./kinematic-body"),"mesh-smooth":t("./mesh-smooth"),"sphere-collider":t("./sphere-collider"),"toggle-velocity":t("./toggle-velocity"),registerAll:function(t){this._registered||(t=t||window.AFRAME,o.registerAll(),t.components.checkpoint||t.registerComponent("checkpoint",this.checkpoint),t.components["cube-env-map"]||t.registerComponent("cube-env-map",this["cube-env-map"]),t.components.grab||t.registerComponent("grab",this.grab),t.components["jump-ability"]||t.registerComponent("jump-ability",this["jump-ability"]),t.components["kinematic-body"]||t.registerComponent("kinematic-body",this["kinematic-body"]),t.components["mesh-smooth"]||t.registerComponent("mesh-smooth",this["mesh-smooth"]),t.components["sphere-collider"]||t.registerComponent("sphere-collider",this["sphere-collider"]),t.components["toggle-velocity"]||t.registerComponent("toggle-velocity",this["toggle-velocity"]),this._registered=!0)}}},{"./checkpoint":72,"./cube-env-map":73,"./grab":74,"./jump-ability":76,"./kinematic-body":77,"./mesh-smooth":78,"./sphere-collider":79,"./toggle-velocity":80,"aframe-physics-system":2}],76:[function(t,e,i){e.exports={dependencies:["velocity"],schema:{on:{default:"keydown:Space gamepadbuttondown:0"},playerHeight:{default:1.764},maxJumps:{default:1},distance:{default:5},soundJump:{default:""},soundLand:{default:""},debug:{default:!1}},init:function(){this.velocity=0,this.numJumps=0;var t=this.beginJump.bind(this),e=this.data.on.split(" ");this.bindings={};for(var i=0;i.5&&(r=h.id===p.bi.id?Math.abs(p.rj.y+p.bj.position.y):Math.abs(p.ri.y+p.bi.position.y))>c&&(c=r,o.copy(i),a=h.id===p.bi.id?p.bj:p.bi)}if(e.copy(t).normalize(),a&&e.y<.5?(l.enableSlopes?o.y<1-1e-6&&o.copy(this.raycastToGround(a,o)):o.set(0,1,0),t=t.projectOnPlane(o)):t.add(this.system.world.gravity.scale(4*s/1e3)),a&&a.el&&a.el.components.velocity){var d=a.el.getAttribute("velocity");h.position.copy({x:h.position.x+d.x*s/1e3,y:h.position.y+d.y*s/1e3,z:h.position.z+d.z*s/1e3}),this.el.setAttribute("position",h.position)}h.velocity.copy(t),this.el.setAttribute("velocity",t)}}}(),raycastToGround:function(t,e){var i,n,s=this.body.position,r=this.body.position.clone();return r.y-=this.data.height,(i=new o.Ray(s,r))._updateDirection(),i.intersectBody(t),i.hasHit?(n=i.result.hitNormalWorld,Math.abs(n.y)>Math.abs(e.y)?n:e):e}}},{}],78:[function(t,e,i){e.exports={init:function(){this.el.addEventListener("model-loaded",function(t){t.detail.model.traverse(function(t){t.isMesh&&t.geometry.computeVertexNormals()})})}}},{}],79:[function(t,e,i){e.exports={schema:{objects:{default:""},state:{default:"collided"},radius:{default:.05},watch:{default:!0}},init:function(){this.observer=null,this.els=[],this.collisions=[],this.handleHit=this.handleHit.bind(this),this.handleHitEnd=this.handleHitEnd.bind(this)},remove:function(){this.pause()},play:function(){var t=this.el.sceneEl;this.data.watch&&(this.observer=new MutationObserver(this.update.bind(this,null)),this.observer.observe(t,{childList:!0,subtree:!0}))},pause:function(){this.observer&&(this.observer.disconnect(),this.observer=null)},update:function(){var t,e=this.data;t=e.objects?this.el.sceneEl.querySelectorAll(e.objects):this.el.sceneEl.children,this.els=Array.prototype.slice.call(t)},tick:function(){var t=new THREE.Vector3,e=new THREE.Vector3,i=(new THREE.Vector3,new THREE.Vector3),o=new Map;return function(){var n,s=this.el,r=this.data,a=[];s.getObject3D("mesh")&&(o.clear(),t.copy(s.object3D.getWorldPosition()),s.object3D.getWorldScale(i),n=r.radius*function(t){return Math.max.apply(null,t.toArray())}(i),this.els.forEach(function(i){var s,r,h,l,c,p;i.isEntity&&(r=i.getObject3D("mesh"))&&(p=(l=(new THREE.Box3).setFromObject(r)).getSize(),c=Math.max(p.x,p.y,p.z)/2,s=Math.sqrt(2*c*c),l.getCenter(e),s&&(h=t.distanceTo(e))o.get(e)?1:-1}).forEach(this.handleHit),0===a.length&&s.emit("hit",{el:null}),this.collisions.filter(function(t){return!o.has(t)}).forEach(this.handleHitEnd),this.collisions=a)}}(),handleHit:function(t){t.emit("hit"),t.addState(this.data.state),this.el.emit("hit",{el:t})},handleHitEnd:function(t){t.emit("hitend"),t.removeState(this.data.state),this.el.emit("hitend",{el:t})}}},{}],80:[function(t,e,i){e.exports={dependencies:["velocity"],schema:{axis:{default:"x",oneOf:["x","y","z"]},min:{default:0},max:{default:0},speed:{default:1}},init:function(){var t={x:0,y:0,z:0};t[this.data.axis]=this.data.speed,this.el.setAttribute("velocity",t),this.el.sceneEl.addBehavior&&this.el.sceneEl.addBehavior(this)},remove:function(){},update:function(){this.tick()},tick:function(){var t=this.data,e=this.el.getAttribute("velocity"),i=this.el.getAttribute("position");e[t.axis]>0&&i[t.axis]>t.max?(e[t.axis]=-t.speed,this.el.setAttribute("velocity",e)):e[t.axis]<0&&i[t.axis]