!function(t){var o;"undefined"!=typeof window?o=window:"undefined"!=typeof global?o=global:"undefined"!=typeof self&&(o=self),o.CANNON=t()}((function(){return function e(t,o,i){function s(r,a){if(!o[r]){if(!t[r]){var l="function"==typeof require&&require;if(!a&&l)return l(r,!0);if(n)return n(r,!0);throw new Error("Cannot find module '"+r+"'")}var h=o[r]={exports:{}};t[r][0].call(h.exports,(function(o){var i=t[r][1][o];return s(i||o)}),h,h.exports,e,t,o,i)}return o[r].exports}for(var n="function"==typeof require&&require,r=0;r (http://steffe.se)",keywords:["cannon.js","cannon","physics","engine","3d"],main:"./build/cannon.js",engines:{node:"*"},repository:{type:"git",url:"https://github.com/schteppe/cannon.js.git"},bugs:{url:"https://github.com/schteppe/cannon.js/issues"},licenses:[{type:"MIT"}],devDependencies:{jshint:"latest","uglify-js":"latest",nodeunit:"^0.9.0",grunt:"~0.4.0","grunt-contrib-jshint":"~0.1.1","grunt-contrib-nodeunit":"^0.4.1","grunt-contrib-concat":"~0.1.3","grunt-contrib-uglify":"^0.5.1","grunt-browserify":"^2.1.4","grunt-contrib-yuidoc":"^0.5.2",browserify:"*"},dependencies:{}}},{}],2:[function(t,o,i){o.exports={version:t("../package.json").version,AABB:t("./collision/AABB"),ArrayCollisionMatrix:t("./collision/ArrayCollisionMatrix"),Body:t("./objects/Body"),Box:t("./shapes/Box"),Broadphase:t("./collision/Broadphase"),Constraint:t("./constraints/Constraint"),ContactEquation:t("./equations/ContactEquation"),Narrowphase:t("./world/Narrowphase"),ConeTwistConstraint:t("./constraints/ConeTwistConstraint"),ContactMaterial:t("./material/ContactMaterial"),ConvexPolyhedron:t("./shapes/ConvexPolyhedron"),Cylinder:t("./shapes/Cylinder"),DistanceConstraint:t("./constraints/DistanceConstraint"),Equation:t("./equations/Equation"),EventTarget:t("./utils/EventTarget"),FrictionEquation:t("./equations/FrictionEquation"),GSSolver:t("./solver/GSSolver"),GridBroadphase:t("./collision/GridBroadphase"),Heightfield:t("./shapes/Heightfield"),HingeConstraint:t("./constraints/HingeConstraint"),LockConstraint:t("./constraints/LockConstraint"),Mat3:t("./math/Mat3"),Material:t("./material/Material"),NaiveBroadphase:t("./collision/NaiveBroadphase"),ObjectCollisionMatrix:t("./collision/ObjectCollisionMatrix"),Pool:t("./utils/Pool"),Particle:t("./shapes/Particle"),Plane:t("./shapes/Plane"),PointToPointConstraint:t("./constraints/PointToPointConstraint"),Quaternion:t("./math/Quaternion"),Ray:t("./collision/Ray"),RaycastVehicle:t("./objects/RaycastVehicle"),RaycastResult:t("./collision/RaycastResult"),RigidVehicle:t("./objects/RigidVehicle"),RotationalEquation:t("./equations/RotationalEquation"),RotationalMotorEquation:t("./equations/RotationalMotorEquation"),SAPBroadphase:t("./collision/SAPBroadphase"),SPHSystem:t("./objects/SPHSystem"),Shape:t("./shapes/Shape"),Solver:t("./solver/Solver"),Sphere:t("./shapes/Sphere"),SplitSolver:t("./solver/SplitSolver"),Spring:t("./objects/Spring"),Trimesh:t("./shapes/Trimesh"),Vec3:t("./math/Vec3"),Vec3Pool:t("./utils/Vec3Pool"),World:t("./world/World")}},{"../package.json":1,"./collision/AABB":3,"./collision/ArrayCollisionMatrix":4,"./collision/Broadphase":5,"./collision/GridBroadphase":6,"./collision/NaiveBroadphase":7,"./collision/ObjectCollisionMatrix":8,"./collision/Ray":9,"./collision/RaycastResult":10,"./collision/SAPBroadphase":11,"./constraints/ConeTwistConstraint":12,"./constraints/Constraint":13,"./constraints/DistanceConstraint":14,"./constraints/HingeConstraint":15,"./constraints/LockConstraint":16,"./constraints/PointToPointConstraint":17,"./equations/ContactEquation":19,"./equations/Equation":20,"./equations/FrictionEquation":21,"./equations/RotationalEquation":22,"./equations/RotationalMotorEquation":23,"./material/ContactMaterial":24,"./material/Material":25,"./math/Mat3":27,"./math/Quaternion":28,"./math/Vec3":30,"./objects/Body":31,"./objects/RaycastVehicle":32,"./objects/RigidVehicle":33,"./objects/SPHSystem":34,"./objects/Spring":35,"./shapes/Box":37,"./shapes/ConvexPolyhedron":38,"./shapes/Cylinder":39,"./shapes/Heightfield":40,"./shapes/Particle":41,"./shapes/Plane":42,"./shapes/Shape":43,"./shapes/Sphere":44,"./shapes/Trimesh":45,"./solver/GSSolver":46,"./solver/Solver":47,"./solver/SplitSolver":48,"./utils/EventTarget":49,"./utils/Pool":51,"./utils/Vec3Pool":54,"./world/Narrowphase":55,"./world/World":56}],3:[function(t,o,i){var n=t("../math/Vec3");t("../utils/Utils");function AABB(t){t=t||{},this.lowerBound=new n,t.lowerBound&&this.lowerBound.copy(t.lowerBound),this.upperBound=new n,t.upperBound&&this.upperBound.copy(t.upperBound)}o.exports=AABB;var r=new n;AABB.prototype.setFromPoints=function(t,o,i,n){var a=this.lowerBound,l=this.upperBound,h=i;a.copy(t[0]),h&&h.vmult(a,a),l.copy(a);for(var c=1;cl.x&&(l.x=p.x),p.xl.y&&(l.y=p.y),p.yl.z&&(l.z=p.z),p.zo&&(this.lowerBound.x=o);var i=t.upperBound.x;this.upperBound.xo&&(this.lowerBound.y=o);i=t.upperBound.y;this.upperBound.yo&&(this.lowerBound.z=o);i=t.upperBound.z;this.upperBound.z=r.x&&o.y<=n.y&&i.y>=r.y&&o.z<=n.z&&i.z>=r.z},AABB.prototype.getCorners=function(t,o,i,n,r,a,l,h){var c=this.lowerBound,p=this.upperBound;t.copy(c),o.set(p.x,c.y,c.z),i.set(p.x,p.y,c.z),n.set(c.x,p.y,p.z),r.set(p.x,c.y,c.z),a.set(c.x,p.y,c.z),l.set(c.x,c.y,p.z),h.copy(p)};var a=[new n,new n,new n,new n,new n,new n,new n,new n];AABB.prototype.toLocalFrame=function(t,o){var i=a,n=i[0],r=i[1],l=i[2],h=i[3],c=i[4],p=i[5],u=i[6],d=i[7];this.getCorners(n,r,l,h,c,p,u,d);for(var v=0;8!==v;v++){var y=i[v];t.pointToLocal(y,y)}return o.setFromPoints(i)},AABB.prototype.toWorldFrame=function(t,o){var i=a,n=i[0],r=i[1],l=i[2],h=i[3],c=i[4],p=i[5],u=i[6],d=i[7];this.getCorners(n,r,l,h,c,p,u,d);for(var v=0;8!==v;v++){var y=i[v];t.pointToWorld(y,y)}return o.setFromPoints(i)}},{"../math/Vec3":30,"../utils/Utils":53}],4:[function(t,o,i){function ArrayCollisionMatrix(){this.matrix=[]}o.exports=ArrayCollisionMatrix,ArrayCollisionMatrix.prototype.get=function(t,o){if(t=t.index,(o=o.index)>t){var i=o;o=t,t=i}return this.matrix[(t*(t+1)>>1)+o-1]},ArrayCollisionMatrix.prototype.set=function(t,o,i){if(t=t.index,(o=o.index)>t){var n=o;o=t,t=n}this.matrix[(t*(t+1)>>1)+o-1]=i?1:0},ArrayCollisionMatrix.prototype.reset=function(){for(var t=0,o=this.matrix.length;t!==o;t++)this.matrix[t]=0},ArrayCollisionMatrix.prototype.setNumObjects=function(t){this.matrix.length=t*(t-1)>>1}},{}],5:[function(t,o,i){var n=t("../objects/Body"),r=t("../math/Vec3"),a=t("../math/Quaternion");t("../shapes/Shape"),t("../shapes/Plane");function Broadphase(){this.world=null,this.useBoundingBoxes=!1,this.dirty=!0}o.exports=Broadphase,Broadphase.prototype.collisionPairs=function(t,o,i){throw new Error("collisionPairs not implemented for this BroadPhase class!")};n.STATIC,n.KINEMATIC;Broadphase.prototype.needBroadphaseCollision=function(t,o){return 0!=(t.collisionFilterGroup&o.collisionFilterMask)&&0!=(o.collisionFilterGroup&t.collisionFilterMask)&&(0==(t.type&n.STATIC)&&t.sleepState!==n.SLEEPING||0==(o.type&n.STATIC)&&o.sleepState!==n.SLEEPING)},Broadphase.prototype.intersectionTest=function(t,o,i,n){this.useBoundingBoxes?this.doBoundingBoxBroadphase(t,o,i,n):this.doBoundingSphereBroadphase(t,o,i,n)};var l=new r;new r,new a,new r;Broadphase.prototype.doBoundingSphereBroadphase=function(t,o,i,n){var r=l;o.position.vsub(t.position,r);var a=Math.pow(t.boundingRadius+o.boundingRadius,2);r.norm2()i.norm2()},Broadphase.prototype.aabbQuery=function(t,o,i){return console.warn(".aabbQuery is not implemented in this Broadphase subclass."),[]}},{"../math/Quaternion":28,"../math/Vec3":30,"../objects/Body":31,"../shapes/Plane":42,"../shapes/Shape":43}],6:[function(t,o,i){o.exports=GridBroadphase;var n=t("./Broadphase"),r=t("../math/Vec3"),a=t("../shapes/Shape");function GridBroadphase(t,o,i,a,l){n.apply(this),this.nx=i||10,this.ny=a||10,this.nz=l||10,this.aabbMin=t||new r(100,100,100),this.aabbMax=o||new r(-100,-100,-100);var h=this.nx*this.ny*this.nz;if(h<=0)throw"GridBroadphase: Each dimension's n must be >0";this.bins=[],this.binLengths=[],this.bins.length=h,this.binLengths.length=h;for(var c=0;c=p&&(h=p-1),c<0?c=0:c>=u&&(c=u-1),f<0?f=0:f>=d&&(f=d-1),m<0?m=0:m>=p&&(m=p-1),w<0?w=0:w>=u&&(w=u-1),C<0?C=0:C>=d&&(C=d-1),c*=y,f*=1,m*=v,w*=y,C*=1;for(var A=h*=v;A<=m;A+=v)for(var R=c;R<=w;R+=y)for(var P=f;P<=C;P+=1){var M=A+R+P;z[M][T[M]++]=l}}for(F=0;F!==n;F++){var W=(ot=r[F]).shape;switch(W.type){case q:var L=ot.position.x,j=ot.position.y,O=ot.position.z,H=W.radius;addBoxToBins(L-H,j-H,O-H,L+H,j+H,O+H,ot);break;case V:W.worldNormalNeedsUpdate&&W.computeWorldNormal(ot.quaternion);var k=W.worldNormal,_=x+.5*C-ot.position.x,U=g+.5*A-ot.position.y,D=b+.5*R-ot.position.z,Q=l;Q.set(_,U,D);for(var G=0,X=0;G!==p;G++,X+=v,Q.y=U,Q.x+=C)for(var Y=0,Z=0;Y!==u;Y++,Z+=y,Q.z=D,Q.y+=A)for(var K=0,J=0;K!==d;K++,J+=1,Q.z+=R)if(Q.dot(k)1){var et=z[F];for(G=0;G!==tt;G++){var ot=et[G];for(Y=0;Y!==G;Y++){var it=et[Y];this.needBroadphaseCollision(ot,it)&&this.intersectionTest(ot,it,o,i)}}}}this.makePairsUnique(o,i)}},{"../math/Vec3":30,"../shapes/Shape":43,"./Broadphase":5}],7:[function(t,o,i){o.exports=NaiveBroadphase;var n=t("./Broadphase"),r=t("./AABB");function NaiveBroadphase(){n.apply(this)}NaiveBroadphase.prototype=new n,NaiveBroadphase.prototype.constructor=NaiveBroadphase,NaiveBroadphase.prototype.collisionPairs=function(t,o,i){var n,r,a,l,h=t.bodies,c=h.length;for(n=0;n!==c;n++)for(r=0;r!==n;r++)a=h[n],l=h[r],this.needBroadphaseCollision(a,l)&&this.intersectionTest(a,l,o,i)};new r;NaiveBroadphase.prototype.aabbQuery=function(t,o,i){i=i||[];for(var n=0;nt){var i=o;o=t,t=i}return t+"-"+o in this.matrix},ObjectCollisionMatrix.prototype.set=function(t,o,i){if(t=t.id,(o=o.id)>t){var n=o;o=t,t=n}i?this.matrix[t+"-"+o]=!0:delete this.matrix[t+"-"+o]},ObjectCollisionMatrix.prototype.reset=function(){this.matrix={}},ObjectCollisionMatrix.prototype.setNumObjects=function(t){}},{}],9:[function(t,o,i){o.exports=Ray;var n=t("../math/Vec3"),r=t("../math/Quaternion"),a=t("../math/Transform"),l=(t("../shapes/ConvexPolyhedron"),t("../shapes/Box"),t("../collision/RaycastResult")),h=t("../shapes/Shape"),c=t("../collision/AABB");function Ray(t,o){this.from=t?t.clone():new n,this.to=o?o.clone():new n,this._direction=new n,this.precision=1e-4,this.checkCollisionResponse=!0,this.skipBackfaces=!1,this.collisionFilterMask=-1,this.collisionFilterGroup=-1,this.mode=Ray.ANY,this.result=new l,this.hasHit=!1,this.callback=function(t){}}Ray.prototype.constructor=Ray,Ray.CLOSEST=1,Ray.ANY=2,Ray.ALL=4;var p=new c,u=[];Ray.prototype.intersectWorld=function(t,o){return this.mode=o.mode||Ray.ANY,this.result=o.result||new l,this.skipBackfaces=!!o.skipBackfaces,this.collisionFilterMask=void 0!==o.collisionFilterMask?o.collisionFilterMask:-1,this.collisionFilterGroup=void 0!==o.collisionFilterGroup?o.collisionFilterGroup:-1,o.from&&this.from.copy(o.from),o.to&&this.to.copy(o.to),this.callback=o.callback||function(){},this.hasHit=!1,this.result.reset(),this._updateDirection(),this.getAABB(p),u.length=0,t.broadphase.aabbQuery(t,p,u),this.intersectBodies(u),this.hasHit};var d=new n,v=new n;function pointInTriangle(t,o,i,n){n.vsub(o,N),i.vsub(o,d),t.vsub(o,v);var r,a,l=N.dot(N),h=N.dot(d),c=N.dot(v),p=d.dot(d),u=d.dot(v);return(r=p*c-h*u)>=0&&(a=l*u-h*c)>=0&&r+at.boundingSphereRadius)){var r=this[t.type];r&&r.call(this,t,o,i,n)}};new n,new n;var m=new n,w=new n,x=new n,g=new n;new n,new l;Ray.prototype.intersectBox=function(t,o,i,n){return this.intersectConvex(t.convexPolyhedronRepresentation,o,i,n)},Ray.prototype[h.types.BOX]=Ray.prototype.intersectBox,Ray.prototype.intersectPlane=function(t,o,i,r){var a=this.from,l=this.to,h=this._direction,c=new n(0,0,1);o.vmult(c,c);var p=new n;a.vsub(i,p);var u=p.dot(c);if(l.vsub(i,p),!(u*p.dot(c)>0||a.distanceTo(l)d)&&(d=c[0]),(null===u||c[1]v)&&(v=c[1])),null!==p){var f=[];t.getRectMinMax(p,u,d,v,f);for(var m=p;m<=d;m++)for(var w=u;w<=v;w++){if(this.result._shouldStop)return;if(t.getConvexTrianglePillar(m,w,!1),a.pointToWorldFrame(i,o,t.pillarOffset,l),this.intersectConvex(t.pillarConvex,o,l,r,b),this.result._shouldStop)return;t.getConvexTrianglePillar(m,w,!0),a.pointToWorldFrame(i,o,t.pillarOffset,l),this.intersectConvex(t.pillarConvex,o,l,r,b)}}},Ray.prototype[h.types.HEIGHTFIELD]=Ray.prototype.intersectHeightfield;var B=new n,S=new n;Ray.prototype.intersectSphere=function(t,o,i,n){var r=this.from,a=this.to,l=t.radius,h=Math.pow(a.x-r.x,2)+Math.pow(a.y-r.y,2)+Math.pow(a.z-r.z,2),c=2*((a.x-r.x)*(r.x-i.x)+(a.y-r.y)*(r.y-i.y)+(a.z-r.z)*(r.z-i.z)),p=Math.pow(r.x-i.x,2)+Math.pow(r.y-i.y,2)+Math.pow(r.z-i.z,2)-Math.pow(l,2),u=Math.pow(c,2)-4*h*p,d=B,v=S;if(!(u<0))if(0===u)r.lerp(a,u,d),d.vsub(i,v),v.normalize(),this.reportIntersection(v,d,t,n,-1);else{var y=(-c-Math.sqrt(u))/(2*h),f=(-c+Math.sqrt(u))/(2*h);if(y>=0&&y<=1&&(r.lerp(a,y,d),d.vsub(i,v),v.normalize(),this.reportIntersection(v,d,t,n,-1)),this.result._shouldStop)return;f>=0&&f<=1&&(r.lerp(a,f,d),d.vsub(i,v),v.normalize(),this.reportIntersection(v,d,t,n,-1))}},Ray.prototype[h.types.SPHERE]=Ray.prototype.intersectSphere;var E=new n,C=(new n,new n,new n);Ray.prototype.intersectConvex=function(t,o,i,n,r){for(var a=E,l=C,h=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=h?h.length:c.length,B=this.result,S=0;!B._shouldStop&&Sf||this.reportIntersection(a,m,t,n,A)}}}}},Ray.prototype[h.types.CONVEXPOLYHEDRON]=Ray.prototype.intersectConvex;var A=new n,R=new n,P=new n,M=new n,q=new n,V=new n,z=(new c,[]),T=new a;Ray.prototype.intersectTrimesh=function(t,o,i,n,r){var l=A,h=z,c=T,p=C,u=R,d=P,v=M,y=V,f=q,b=(r&&r.faceList,t.indices),B=(t.vertices,t.faceNormals,this.from),S=this.to,E=this._direction;c.position.copy(i),c.quaternion.copy(o),a.vectorToLocalFrame(i,o,E,u),a.pointToLocalFrame(i,o,B,d),a.pointToLocalFrame(i,o,S,v);var N=d.distanceSquared(v);t.tree.rayQuery(this,c,h);for(var F=0,I=h.length;!this.result._shouldStop&&F!==I;F++){var W=h[F];t.getNormal(W,l),t.getVertex(b[3*W],w),w.vsub(d,p);var L=u.dot(l),j=l.dot(p)/L;if(!(j<0)){u.scale(j,m),m.vadd(d,m),t.getVertex(b[3*W+1],x),t.getVertex(b[3*W+2],g);var O=m.distanceSquared(d);!pointInTriangle(m,x,w,g)&&!pointInTriangle(m,w,x,g)||O>N||(a.vectorToWorldFrame(o,l,f),a.pointToWorldFrame(i,o,m,y),this.reportIntersection(f,y,t,n,W))}}h.length=0},Ray.prototype[h.types.TRIMESH]=Ray.prototype.intersectTrimesh,Ray.prototype.reportIntersection=function(t,o,i,n,r){var a=this.from,l=this.to,h=a.distanceTo(o),c=this.result;if(!(this.skipBackfaces&&t.dot(this._direction)>0))switch(c.hitFaceIndex=void 0!==r?r:-1,this.mode){case Ray.ALL:this.hasHit=!0,c.set(a,l,t,o,i,n,h),c.hasHit=!0,this.callback(c);break;case Ray.CLOSEST:(h=0&&!(t[r].aabb.lowerBound.x<=n.aabb.lowerBound.x);r--)t[r+1]=t[r];t[r+1]=n}return t},SAPBroadphase.insertionSortY=function(t){for(var o=1,i=t.length;o=0&&!(t[r].aabb.lowerBound.y<=n.aabb.lowerBound.y);r--)t[r+1]=t[r];t[r+1]=n}return t},SAPBroadphase.insertionSortZ=function(t){for(var o=1,i=t.length;o=0&&!(t[r].aabb.lowerBound.z<=n.aabb.lowerBound.z);r--)t[r+1]=t[r];t[r+1]=n}return t},SAPBroadphase.prototype.collisionPairs=function(t,o,i){var n,r,a=this.axisList,l=a.length,h=this.axisIndex;for(this.dirty&&(this.sortList(),this.dirty=!1),n=0;n!==l;n++){var c=a[n];for(r=n+1;rm?f>w?0:2:m>w?1:2},SAPBroadphase.prototype.aabbQuery=function(t,o,i){i=i||[],this.dirty&&(this.sortList(),this.dirty=!1);var n=this.axisIndex,r="x";1===n&&(r="y"),2===n&&(r="z");for(var a=this.axisList,l=(o.lowerBound[r],o.upperBound[r],0);l.499&&(i=2*Math.atan2(a,c),n=Math.PI/2,r=0),p<-.499&&(i=-2*Math.atan2(a,c),n=-Math.PI/2,r=0),isNaN(i)){var u=a*a,d=l*l,v=h*h;i=Math.atan2(2*l*c-2*a*h,1-2*d-2*v),n=Math.asin(2*p),r=Math.atan2(2*a*c-2*l*h,1-2*u-2*v)}break;default:throw new Error("Euler order "+o+" not supported yet.")}t.y=i,t.z=n,t.x=r},Quaternion.prototype.setFromEuler=function(t,o,i,n){n=n||"XYZ";var r=Math.cos(t/2),a=Math.cos(o/2),l=Math.cos(i/2),h=Math.sin(t/2),c=Math.sin(o/2),p=Math.sin(i/2);return"XYZ"===n?(this.x=h*a*l+r*c*p,this.y=r*c*l-h*a*p,this.z=r*a*p+h*c*l,this.w=r*a*l-h*c*p):"YXZ"===n?(this.x=h*a*l+r*c*p,this.y=r*c*l-h*a*p,this.z=r*a*p-h*c*l,this.w=r*a*l+h*c*p):"ZXY"===n?(this.x=h*a*l-r*c*p,this.y=r*c*l+h*a*p,this.z=r*a*p+h*c*l,this.w=r*a*l-h*c*p):"ZYX"===n?(this.x=h*a*l-r*c*p,this.y=r*c*l+h*a*p,this.z=r*a*p-h*c*l,this.w=r*a*l+h*c*p):"YZX"===n?(this.x=h*a*l+r*c*p,this.y=r*c*l+h*a*p,this.z=r*a*p-h*c*l,this.w=r*a*l-h*c*p):"XZY"===n&&(this.x=h*a*l-r*c*p,this.y=r*c*l-h*a*p,this.z=r*a*p+h*c*l,this.w=r*a*l+h*c*p),this},Quaternion.prototype.clone=function(){return new Quaternion(this.x,this.y,this.z,this.w)}},{"./Vec3":30}],29:[function(t,o,i){var n=t("./Vec3"),r=t("./Quaternion");function Transform(t){t=t||{},this.position=new n,t.position&&this.position.copy(t.position),this.quaternion=new r,t.quaternion&&this.quaternion.copy(t.quaternion)}o.exports=Transform;var a=new r;Transform.pointToLocalFrame=function(t,o,i,r){r=r||new n;return i.vsub(t,r),o.conjugate(a),a.vmult(r,r),r},Transform.prototype.pointToLocal=function(t,o){return Transform.pointToLocalFrame(this.position,this.quaternion,t,o)},Transform.pointToWorldFrame=function(t,o,i,r){r=r||new n;return o.vmult(i,r),r.vadd(t,r),r},Transform.prototype.pointToWorld=function(t,o){return Transform.pointToWorldFrame(this.position,this.quaternion,t,o)},Transform.prototype.vectorToWorldFrame=function(t,o){o=o||new n;return this.quaternion.vmult(t,o),o},Transform.vectorToWorldFrame=function(t,o,i){return t.vmult(o,i),i},Transform.vectorToLocalFrame=function(t,o,i,r){r=r||new n;return o.w*=-1,o.vmult(i,r),o.w*=-1,r}},{"./Quaternion":28,"./Vec3":30}],30:[function(t,o,i){o.exports=Vec3;var n=t("./Mat3");function Vec3(t,o,i){this.x=t||0,this.y=o||0,this.z=i||0}Vec3.ZERO=new Vec3(0,0,0),Vec3.UNIT_X=new Vec3(1,0,0),Vec3.UNIT_Y=new Vec3(0,1,0),Vec3.UNIT_Z=new Vec3(0,0,1),Vec3.prototype.cross=function(t,o){var i=t.x,n=t.y,r=t.z,a=this.x,l=this.y,h=this.z;return(o=o||new Vec3).x=l*r-h*n,o.y=h*i-a*r,o.z=a*n-l*i,o},Vec3.prototype.set=function(t,o,i){return this.x=t,this.y=o,this.z=i,this},Vec3.prototype.setZero=function(){this.x=this.y=this.z=0},Vec3.prototype.vadd=function(t,o){if(!o)return new Vec3(this.x+t.x,this.y+t.y,this.z+t.z);o.x=t.x+this.x,o.y=t.y+this.y,o.z=t.z+this.z},Vec3.prototype.vsub=function(t,o){if(!o)return new Vec3(this.x-t.x,this.y-t.y,this.z-t.z);o.x=this.x-t.x,o.y=this.y-t.y,o.z=this.z-t.z},Vec3.prototype.crossmat=function(){return new n([0,-this.z,this.y,this.z,0,-this.x,-this.y,this.x,0])},Vec3.prototype.normalize=function(){var t=this.x,o=this.y,i=this.z,n=Math.sqrt(t*t+o*o+i*i);if(n>0){var r=1/n;this.x*=r,this.y*=r,this.z*=r}else this.x=0,this.y=0,this.z=0;return n},Vec3.prototype.unit=function(t){t=t||new Vec3;var o=this.x,i=this.y,n=this.z,r=Math.sqrt(o*o+i*i+n*n);return r>0?(r=1/r,t.x=o*r,t.y=i*r,t.z=n*r):(t.x=1,t.y=0,t.z=0),t},Vec3.prototype.norm=function(){var t=this.x,o=this.y,i=this.z;return Math.sqrt(t*t+o*o+i*i)},Vec3.prototype.length=Vec3.prototype.norm,Vec3.prototype.norm2=function(){return this.dot(this)},Vec3.prototype.lengthSquared=Vec3.prototype.norm2,Vec3.prototype.distanceTo=function(t){var o=this.x,i=this.y,n=this.z,r=t.x,a=t.y,l=t.z;return Math.sqrt((r-o)*(r-o)+(a-i)*(a-i)+(l-n)*(l-n))},Vec3.prototype.distanceSquared=function(t){var o=this.x,i=this.y,n=this.z,r=t.x,a=t.y,l=t.z;return(r-o)*(r-o)+(a-i)*(a-i)+(l-n)*(l-n)},Vec3.prototype.mult=function(t,o){o=o||new Vec3;var i=this.x,n=this.y,r=this.z;return o.x=t*i,o.y=t*n,o.z=t*r,o},Vec3.prototype.scale=Vec3.prototype.mult,Vec3.prototype.dot=function(t){return this.x*t.x+this.y*t.y+this.z*t.z},Vec3.prototype.isZero=function(){return 0===this.x&&0===this.y&&0===this.z},Vec3.prototype.negate=function(t){return(t=t||new Vec3).x=-this.x,t.y=-this.y,t.z=-this.z,t};var r=new Vec3,a=new Vec3;Vec3.prototype.tangents=function(t,o){var i=this.norm();if(i>0){var n=r,l=1/i;n.set(this.x*l,this.y*l,this.z*l);var h=a;Math.abs(n.x)<.9?(h.set(1,0,0),n.cross(h,t)):(h.set(0,1,0),n.cross(h,t)),n.cross(t,o)}else t.set(1,0,0),o.set(0,1,0)},Vec3.prototype.toString=function(){return this.x+","+this.y+","+this.z},Vec3.prototype.toArray=function(){return[this.x,this.y,this.z]},Vec3.prototype.copy=function(t){return this.x=t.x,this.y=t.y,this.z=t.z,this},Vec3.prototype.lerp=function(t,o,i){var n=this.x,r=this.y,a=this.z;i.x=n+(t.x-n)*o,i.y=r+(t.y-r)*o,i.z=a+(t.z-a)*o},Vec3.prototype.almostEquals=function(t,o){return void 0===o&&(o=1e-6),!(Math.abs(this.x-t.x)>o||Math.abs(this.y-t.y)>o||Math.abs(this.z-t.z)>o)},Vec3.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 l=new Vec3;Vec3.prototype.isAntiparallelTo=function(t,o){return this.negate(l),l.almostEquals(t,o)},Vec3.prototype.clone=function(){return new Vec3(this.x,this.y,this.z)}},{"./Mat3":27}],31:[function(t,o,i){o.exports=Body;var n=t("../utils/EventTarget"),r=(t("../shapes/Shape"),t("../math/Vec3")),a=t("../math/Mat3"),l=t("../math/Quaternion"),h=(t("../material/Material"),t("../collision/AABB")),c=t("../shapes/Box");function Body(t){t=t||{},n.apply(this),this.id=Body.idCounter++,this.layaID,this.isTrigger=!1,this.world=null,this.preStep=null,this.postStep=null,this.vlambda=new r,this.collisionFilterGroup="number"==typeof t.collisionFilterGroup?t.collisionFilterGroup:1,this.collisionFilterMask="number"==typeof t.collisionFilterMask?t.collisionFilterMask:1,this.collisionResponse=!0,this.position=new r,t.position&&this.position.copy(t.position),this.previousPosition=new r,this.initPosition=new r,this.velocity=new r,t.velocity&&this.velocity.copy(t.velocity),this.initVelocity=new r,this.force=new r;var o="number"==typeof t.mass?t.mass:0;this.mass=o,this.invMass=o>0?1/o:0,this.material=t.material||null,this.linearDamping="number"==typeof t.linearDamping?t.linearDamping:.01,this.type=o<=0?Body.STATIC:Body.DYNAMIC,typeof t.type==typeof Body.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 r,this.quaternion=new l,t.quaternion&&this.quaternion.copy(t.quaternion),this.initQuaternion=new l,this.angularVelocity=new r,t.angularVelocity&&this.angularVelocity.copy(t.angularVelocity),this.initAngularVelocity=new r,this.interpolatedPosition=new r,this.interpolatedQuaternion=new l,this.shapes=[],this.shapeOffsets=[],this.shapeOrientations=[],this.inertia=new r,this.invInertia=new r,this.invInertiaWorld=new a,this.invMassSolve=0,this.invInertiaSolve=new r,this.invInertiaWorldSolve=new a,this.fixedRotation=void 0!==t.fixedRotation&&t.fixedRotation,this.angularDamping=void 0!==t.angularDamping?t.angularDamping:.01,this.aabb=new h,this.aabbNeedsUpdate=!0,this.wlambda=new r,t.shape&&this.addShape(t.shape),this.updateMassProperties()}Body.prototype=new n,Body.prototype.constructor=Body,Body.DYNAMIC=1,Body.STATIC=2,Body.KINEMATIC=4,Body.AWAKE=0,Body.SLEEPY=1,Body.SLEEPING=2,Body.idCounter=0,Body.prototype.wakeUp=function(){var t=this.sleepState;this.sleepState=0,t===Body.SLEEPING&&this.dispatchEvent({type:"wakeup"})},Body.prototype.sleep=function(){this.sleepState=Body.SLEEPING,this.velocity.set(0,0,0),this.angularVelocity.set(0,0,0)},Body.sleepyEvent={type:"sleepy"},Body.sleepEvent={type:"sleep"},Body.prototype.sleepTick=function(t){if(this.allowSleep){var o=this.sleepState,i=this.velocity.norm2()+this.angularVelocity.norm2(),n=Math.pow(this.sleepSpeedLimit,2);o===Body.AWAKE&&in?this.wakeUp():o===Body.SLEEPY&&t-this.timeLastSleepy>this.sleepTimeLimit&&(this.sleep(),this.dispatchEvent(Body.sleepEvent))}},Body.prototype.updateSolveMassProperties=function(){this.sleepState===Body.SLEEPING||this.type===Body.KINEMATIC?(this.invMassSolve=0,this.invInertiaSolve.setZero(),this.invInertiaWorldSolve.setZero()):(this.invMassSolve=this.invMass,this.invInertiaSolve.copy(this.invInertia),this.invInertiaWorldSolve.copy(this.invInertiaWorld))},Body.prototype.pointToLocalFrame=function(t,o){o=o||new r;return t.vsub(this.position,o),this.quaternion.conjugate().vmult(o,o),o},Body.prototype.vectorToLocalFrame=function(t,o){o=o||new r;return this.quaternion.conjugate().vmult(t,o),o},Body.prototype.pointToWorldFrame=function(t,o){o=o||new r;return this.quaternion.vmult(t,o),o.vadd(this.position,o),o},Body.prototype.vectorToWorldFrame=function(t,o){o=o||new r;return this.quaternion.vmult(t,o),o};var p=new r,u=new l;Body.prototype.addShape=function(t,o,i){var n=new r,a=new l;return o&&n.copy(o),i&&a.copy(i),this.shapes.push(t),this.shapeOffsets.push(n),this.shapeOrientations.push(a),this.updateMassProperties(),this.updateBoundingRadius(),this.aabbNeedsUpdate=!0,this},Body.prototype.updateBoundingRadius=function(){for(var t=this.shapes,o=this.shapeOffsets,i=t.length,n=0,r=0;r!==i;r++){var a=t[r];a.updateBoundingSphereRadius();var l=o[r].norm(),h=a.boundingSphereRadius;l+h>n&&(n=l+h)}this.boundingRadius=n};var d=new h;Body.prototype.computeAABB=function(){for(var t=this.shapes,o=this.shapeOffsets,i=this.shapeOrientations,n=t.length,r=p,a=u,l=this.quaternion,h=this.aabb,c=d,v=0;v!==n;v++){var y=t[v];i[v].mult(l,a),a.vmult(o[v],r),r.vadd(this.position,r),y.calculateWorldAABB(r,a,c.lowerBound,c.upperBound),0===v?h.copy(c):h.extend(c)}this.aabbNeedsUpdate=!1};var v=new a,y=new a;new a;Body.prototype.updateInertiaWorld=function(t){var o=this.invInertia;if(o.x!==o.y||o.y!==o.z||t){var i=v,n=y;i.setRotationFromQuaternion(this.quaternion),i.transpose(n),i.scale(o,i),i.mmult(n,this.invInertiaWorld)}else;};var f=new r,m=new r;Body.prototype.applyForce=function(t,o){if(this.type===Body.DYNAMIC){var i=f;o.vsub(this.position,i);var n=m;i.cross(t,n),this.force.vadd(t,this.force),this.torque.vadd(n,this.torque)}};var w=new r,x=new r;Body.prototype.applyLocalForce=function(t,o){if(this.type===Body.DYNAMIC){var i=w,n=x;this.vectorToWorldFrame(t,i),this.pointToWorldFrame(o,n),this.applyForce(i,n)}};var g=new r,b=new r,B=new r;Body.prototype.applyImpulse=function(t,o){if(this.type===Body.DYNAMIC){var i=g;o.vsub(this.position,i);var n=b;n.copy(t),n.mult(this.invMass,n),this.velocity.vadd(n,this.velocity);var r=B;i.cross(t,r),this.invInertiaWorld.vmult(r,r),this.angularVelocity.vadd(r,this.angularVelocity)}};var S=new r,E=new r;Body.prototype.applyLocalImpulse=function(t,o){if(this.type===Body.DYNAMIC){var i=S,n=E;this.vectorToWorldFrame(t,i),this.pointToWorldFrame(o,n),this.applyImpulse(i,n)}};var C=new r;Body.prototype.updateMassProperties=function(){var t=C;this.invMass=this.mass>0?1/this.mass:0;var o=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),c.calculateInertia(t,this.mass,o),this.invInertia.set(o.x>0&&!i?1/o.x:0,o.y>0&&!i?1/o.y:0,o.z>0&&!i?1/o.z:0),this.updateInertiaWorld(!0)},Body.prototype.getVelocityAtWorldPoint=function(t,o){var i=new r;return t.vsub(this.position,i),this.angularVelocity.cross(i,o),this.velocity.vadd(o,o),o}},{"../collision/AABB":3,"../material/Material":25,"../math/Mat3":27,"../math/Quaternion":28,"../math/Vec3":30,"../shapes/Box":37,"../shapes/Shape":43,"../utils/EventTarget":49}],32:[function(t,o,i){t("./Body");var n=t("../math/Vec3"),r=t("../math/Quaternion"),a=(t("../collision/RaycastResult"),t("../collision/Ray")),l=t("../objects/WheelInfo");function RaycastVehicle(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}o.exports=RaycastVehicle;new n,new n,new n;var h=new n,c=new n,p=new n;new a;RaycastVehicle.prototype.addWheel=function(t){var o=new l(t=t||{}),i=this.wheelInfos.length;return this.wheelInfos.push(o),i},RaycastVehicle.prototype.setSteeringValue=function(t,o){this.wheelInfos[o].steering=t};new n;RaycastVehicle.prototype.applyEngineForce=function(t,o){this.wheelInfos[o].engineForce=t},RaycastVehicle.prototype.setBrake=function(t,o){this.wheelInfos[o].brake=t},RaycastVehicle.prototype.addToWorld=function(t){this.constraints;t.add(this.chassisBody);var o=this;this.preStepCallback=function(){o.updateVehicle(t.dt)},t.addEventListener("preStep",this.preStepCallback),this.world=t},RaycastVehicle.prototype.getVehicleAxisWorld=function(t,o){o.set(0===t?1:0,1===t?1:0,2===t?1:0),this.chassisBody.vectorToWorldFrame(o,o)},RaycastVehicle.prototype.updateVehicle=function(t){for(var o=this.wheelInfos,i=o.length,r=this.chassisBody,a=0;ay.maxSuspensionForce&&(p=y.maxSuspensionForce),y.raycastResult.hitNormalWorld.scale(p*t,h),y.raycastResult.hitPointWorld.vsub(r.position,c),r.applyImpulse(h,y.raycastResult.hitPointWorld)}this.updateFriction(t);var u=new n,d=new n,v=new n;for(a=0;a0?1:-1)*y.customSlidingRotationalSpeed*t),Math.abs(y.brake)>Math.abs(y.engineForce)&&(y.deltaRotation=0),y.rotation+=y.deltaRotation,y.deltaRotation*=.99}},RaycastVehicle.prototype.updateSuspension=function(t){for(var o=this.chassisBody.mass,i=this.wheelInfos,n=i.length,r=0;rm&&(t.suspensionLength=m,t.raycastResult.reset());var w=t.raycastResult.hitNormalWorld.dot(t.directionWorld),x=new n;r.getVelocityAtWorldPoint(t.raycastResult.hitPointWorld,x);var g=t.raycastResult.hitNormalWorld.dot(x);if(w>=-.1)t.suspensionRelativeVelocity=0,t.clippedInvContactDotSuspension=10;else{var b=-1/w;t.suspensionRelativeVelocity=g*b,t.clippedInvContactDotSuspension=b}}else t.suspensionLength=t.suspensionRestLength+0*t.maxSuspensionTravel,t.suspensionRelativeVelocity=0,t.directionWorld.scale(-1,t.raycastResult.hitNormalWorld),t.clippedInvContactDotSuspension=1;return a},RaycastVehicle.prototype.updateWheelTransformWorld=function(t){t.isInContact=!1;var o=this.chassisBody;o.pointToWorldFrame(t.chassisConnectionPointLocal,t.chassisConnectionPointWorld),o.vectorToWorldFrame(t.directionLocal,t.directionWorld),o.vectorToWorldFrame(t.axleLocal,t.axleWorld)},RaycastVehicle.prototype.updateWheelTransform=function(t){var o=h,i=c,n=p,a=this.wheelInfos[t];this.updateWheelTransformWorld(a),a.directionLocal.scale(-1,o),i.copy(a.axleLocal),o.cross(i,n),n.normalize(),i.normalize();var l=a.steering,u=new r;u.setFromAxisAngle(o,l);var d=new r;d.setFromAxisAngle(i,a.rotation);var v=a.worldTransform.quaternion;this.chassisBody.quaternion.mult(u,v),v.mult(d,v),v.normalize();var y=a.worldTransform.position;y.copy(a.directionWorld),y.scale(a.suspensionLength,y),y.vadd(a.chassisConnectionPointWorld,y)};var v=[new n(1,0,0),new n(0,1,0),new n(0,0,1)];RaycastVehicle.prototype.getWheelTransformWorld=function(t){return this.wheelInfos[t].worldTransform};var y=new n,f=[],m=[];RaycastVehicle.prototype.updateFriction=function(t){for(var o=y,i=this.wheelInfos,r=i.length,a=this.chassisBody,l=m,h=f,c=0;cS){this.sliding=!0,R.sliding=!0;b=B/Math.sqrt(A);R.skidInfo*=b}}}if(this.sliding)for(c=0;c1.1)return 0;var l=C,h=A,c=R;t.getVelocityAtWorldPoint(o,l),i.getVelocityAtWorldPoint(n,h),l.vsub(h,c);return-.2*r.dot(c)*(1/(t.invMass+i.invMass))}},{"../collision/Ray":9,"../collision/RaycastResult":10,"../math/Quaternion":28,"../math/Vec3":30,"../objects/WheelInfo":36,"./Body":31}],33:[function(t,o,i){var n=t("./Body"),r=t("../shapes/Sphere"),a=t("../shapes/Box"),l=t("../math/Vec3"),h=t("../constraints/HingeConstraint");function RigidVehicle(t){if(this.wheelBodies=[],this.coordinateSystem=void 0===t.coordinateSystem?new l(1,2,3):t.coordinateSystem.clone(),this.chassisBody=t.chassisBody,!this.chassisBody){var o=new a(new l(5,2,.5));this.chassisBody=new n(1,o)}this.constraints=[],this.wheelAxes=[],this.wheelForces=[]}o.exports=RigidVehicle,RigidVehicle.prototype.addWheel=function(t){var o=(t=t||{}).body;o||(o=new n(1,new r(1.2))),this.wheelBodies.push(o),this.wheelForces.push(0);new l;var i=void 0!==t.position?t.position.clone():new l,a=new l;this.chassisBody.pointToWorldFrame(i,a),o.position.set(a.x,a.y,a.z);var c=void 0!==t.axis?t.axis.clone():new l(0,1,0);this.wheelAxes.push(c);var p=new h(this.chassisBody,o,{pivotA:i,axisA:c,pivotB:l.ZERO,axisB:c,collideConnected:!1});return this.constraints.push(p),this.wheelBodies.length-1},RigidVehicle.prototype.setSteeringValue=function(t,o){var i=this.wheelAxes[o],n=Math.cos(t),r=Math.sin(t),a=i.x,l=i.y;this.constraints[o].axisA.set(n*a-r*l,r*a+n*l,0)},RigidVehicle.prototype.setMotorSpeed=function(t,o){var i=this.constraints[o];i.enableMotor(),i.motorTargetVelocity=t},RigidVehicle.prototype.disableMotor=function(t){this.constraints[t].disableMotor()};var c=new l;RigidVehicle.prototype.setWheelForce=function(t,o){this.wheelForces[o]=t},RigidVehicle.prototype.applyWheelForce=function(t,o){var i=this.wheelAxes[o],n=this.wheelBodies[o],r=n.torque;i.scale(t,c),n.vectorToWorldFrame(c,c),r.vadd(c,r)},RigidVehicle.prototype.addToWorld=function(t){for(var o=this.constraints,i=this.wheelBodies.concat([this.chassisBody]),n=0;nthis.particles.length&&this.neighbors.pop())};var r=new n;SPHSystem.prototype.getNeighbors=function(t,o){for(var i=this.particles.length,n=t.id,a=this.smoothingRadius*this.smoothingRadius,l=r,h=0;h!==i;h++){var c=this.particles[h];c.position.vsub(t.position,l),n!==c.id&&l.norm2()=-.1)this.suspensionRelativeVelocity=0,this.clippedInvContactDotSuspension=10;else{var r=-1/i;this.suspensionRelativeVelocity=n*r,this.clippedInvContactDotSuspension=r}}else o.suspensionLength=this.suspensionRestLength,this.suspensionRelativeVelocity=0,o.directionWorld.scale(-1,o.hitNormalWorld),this.clippedInvContactDotSuspension=1}},{"../collision/RaycastResult":10,"../math/Transform":29,"../math/Vec3":30,"../utils/Utils":53}],37:[function(t,o,i){o.exports=Box;var n=t("./Shape"),r=t("../math/Vec3"),a=t("./ConvexPolyhedron");function Box(t){n.call(this),this.type=n.types.BOX,this.halfExtents=t,this.convexPolyhedronRepresentation=null,this.updateConvexPolyhedronRepresentation(),this.updateBoundingSphereRadius()}Box.prototype=new n,Box.prototype.constructor=Box,Box.prototype.updateConvexPolyhedronRepresentation=function(){var t=this.halfExtents.x,o=this.halfExtents.y,i=this.halfExtents.z,n=r,l=[new n(-t,-o,-i),new n(t,-o,-i),new n(t,o,-i),new n(-t,o,-i),new n(-t,-o,i),new n(t,-o,i),new n(t,o,i),new n(-t,o,i)],h=(new n(0,0,1),new n(0,1,0),new n(1,0,0),new a(l,[[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=h,h.material=this.material},Box.prototype.calculateLocalInertia=function(t,o){return o=o||new r,Box.calculateInertia(this.halfExtents,t,o),o},Box.calculateInertia=function(t,o,i){var n=t;i.x=1/12*o*(2*n.y*2*n.y+2*n.z*2*n.z),i.y=1/12*o*(2*n.x*2*n.x+2*n.z*2*n.z),i.z=1/12*o*(2*n.y*2*n.y+2*n.x*2*n.x)},Box.prototype.getSideNormals=function(t,o){var i=t,n=this.halfExtents;if(i[0].set(n.x,0,0),i[1].set(0,n.y,0),i[2].set(0,0,n.z),i[3].set(-n.x,0,0),i[4].set(0,-n.y,0),i[5].set(0,0,-n.z),void 0!==o)for(var r=0;r!==i.length;r++)o.vmult(i[r],i[r]);return i},Box.prototype.volume=function(){return 8*this.halfExtents.x*this.halfExtents.y*this.halfExtents.z},Box.prototype.updateBoundingSphereRadius=function(){this.boundingSphereRadius=this.halfExtents.norm()};var l=new r;new r;Box.prototype.forEachWorldCorner=function(t,o,i){for(var n=this.halfExtents,r=[[n.x,n.y,n.z],[-n.x,n.y,n.z],[-n.x,-n.y,n.z],[-n.x,-n.y,-n.z],[n.x,-n.y,-n.z],[n.x,n.y,-n.z],[-n.x,n.y,-n.z],[n.x,-n.y,n.z]],a=0;an.x&&(n.x=c),p>n.y&&(n.y=p),u>n.z&&(n.z=u),cy&&(y=m,v=f)}for(var w=[],x=i.faces[v],g=x.length,b=0;b=0&&this.clipFaceAgainstHull(l,t,o,w,h,c,u)};var u=new r,d=new r,v=new r,y=new r,f=new r,m=new r;ConvexPolyhedron.prototype.findSeparatingAxis=function(t,o,i,n,r,a,l,h){var c=u,p=d,w=v,x=y,g=f,b=m,B=Number.MAX_VALUE;if(this.uniqueAxes)for(E=0;E!==this.uniqueAxes.length;E++){if(i.vmult(this.uniqueAxes[E],c),!1===(R=this.testSepAxis(c,t,o,i,n,r)))return!1;R0&&a.negate(a),!0};var w=[],x=[];ConvexPolyhedron.prototype.testSepAxis=function(t,o,i,n,r,a){ConvexPolyhedron.project(this,t,i,n,w),ConvexPolyhedron.project(o,t,r,a,x);var l=w[0],h=w[1],c=x[0],p=x[1];if(lo&&(o=r)}this.maxValue=o},Heightfield.prototype.setHeightValueAtIndex=function(t,o,i){this.data[t][o]=i,this.clearCachedConvexTrianglePillar(t,o,!1),t>0&&(this.clearCachedConvexTrianglePillar(t-1,o,!0),this.clearCachedConvexTrianglePillar(t-1,o,!1)),o>0&&(this.clearCachedConvexTrianglePillar(t,o-1,!0),this.clearCachedConvexTrianglePillar(t,o-1,!1)),o>0&&t>0&&this.clearCachedConvexTrianglePillar(t-1,o-1,!0)},Heightfield.prototype.getRectMinMax=function(t,o,i,n,r){r=r||[];for(var a=this.data,l=this.minValue,h=t;h<=i;h++)for(var c=o;c<=n;c++){var p=a[h][c];p>l&&(l=p)}r[0]=this.minValue,r[1]=l},Heightfield.prototype.getIndexOfPosition=function(t,o,i,n){var r=this.elementSize,a=this.data,l=Math.floor(t/r),h=Math.floor(o/r);return i[0]=l,i[1]=h,n&&(l<0&&(l=0),h<0&&(h=0),l>=a.length-1&&(l=a.length-1),h>=a[0].length-1&&(h=a[0].length-1)),!(l<0||h<0||l>=a.length-1||h>=a[0].length-1)},Heightfield.prototype.getHeightAt=function(t,o,i){var n=[];this.getIndexOfPosition(t,o,n,i);var r=[];return this.getRectMinMax(n[0],n[1]+1,n[0],n[1]+1,r),(r[0]+r[1])/2},Heightfield.prototype.getCacheConvexTrianglePillarKey=function(t,o,i){return t+"_"+o+"_"+(i?1:0)},Heightfield.prototype.getCachedConvexTrianglePillar=function(t,o,i){return this._cachedPillars[this.getCacheConvexTrianglePillarKey(t,o,i)]},Heightfield.prototype.setCachedConvexTrianglePillar=function(t,o,i,n,r){this._cachedPillars[this.getCacheConvexTrianglePillarKey(t,o,i)]={convex:n,offset:r}},Heightfield.prototype.clearCachedConvexTrianglePillar=function(t,o,i){delete this._cachedPillars[this.getCacheConvexTrianglePillarKey(t,o,i)]},Heightfield.prototype.getConvexTrianglePillar=function(t,o,i){var n=this.pillarConvex,l=this.pillarOffset;if(this.cacheEnabled){if(h=this.getCachedConvexTrianglePillar(t,o,i))return this.pillarConvex=h.convex,void(this.pillarOffset=h.offset);n=new r,l=new a,this.pillarConvex=n,this.pillarOffset=l}var h=this.data,c=this.elementSize,p=n.faces;n.vertices.length=6;for(var u=0;u<6;u++)n.vertices[u]||(n.vertices[u]=new a);p.length=5;for(u=0;u<5;u++)p[u]||(p[u]=[]);var d=n.vertices,v=(Math.min(h[t][o],h[t+1][o],h[t][o+1],h[t+1][o+1])-this.minValue)/2+this.minValue;i?(l.set((t+.75)*c,(o+.75)*c,v),d[0].set(.25*c,.25*c,h[t+1][o+1]-v),d[1].set(-.75*c,.25*c,h[t][o+1]-v),d[2].set(.25*c,-.75*c,h[t+1][o]-v),d[3].set(.25*c,.25*c,-v-1),d[4].set(-.75*c,.25*c,-v-1),d[5].set(.25*c,-.75*c,-v-1),p[0][0]=0,p[0][1]=1,p[0][2]=2,p[1][0]=5,p[1][1]=4,p[1][2]=3,p[2][0]=2,p[2][1]=5,p[2][2]=3,p[2][3]=0,p[3][0]=3,p[3][1]=4,p[3][2]=1,p[3][3]=0,p[4][0]=1,p[4][1]=4,p[4][2]=5,p[4][3]=2):(l.set((t+.25)*c,(o+.25)*c,v),d[0].set(-.25*c,-.25*c,h[t][o]-v),d[1].set(.75*c,-.25*c,h[t+1][o]-v),d[2].set(-.25*c,.75*c,h[t][o+1]-v),d[3].set(-.25*c,-.25*c,-v-1),d[4].set(.75*c,-.25*c,-v-1),d[5].set(-.25*c,.75*c,-v-1),p[0][0]=0,p[0][1]=1,p[0][2]=2,p[1][0]=5,p[1][1]=4,p[1][2]=3,p[2][0]=0,p[2][1]=2,p[2][2]=5,p[2][3]=3,p[3][0]=1,p[3][1]=0,p[3][2]=3,p[3][3]=4,p[4][0]=4,p[4][1]=5,p[4][2]=2,p[4][3]=1),n.computeNormals(),n.computeEdges(),n.updateBoundingSphereRadius(),this.setCachedConvexTrianglePillar(t,o,i,n,l)},Heightfield.prototype.calculateLocalInertia=function(t,o){return(o=o||new a).set(0,0,0),o},Heightfield.prototype.volume=function(){return Number.MAX_VALUE},Heightfield.prototype.calculateWorldAABB=function(t,o,i,n){i.set(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE),n.set(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE)},Heightfield.prototype.updateBoundingSphereRadius=function(){var t=this.data,o=this.elementSize;this.boundingSphereRadius=new a(t.length*o,t[0].length*o,Math.max(Math.abs(this.maxValue),Math.abs(this.minValue))).norm()}},{"../math/Vec3":30,"../utils/Utils":53,"./ConvexPolyhedron":38,"./Shape":43}],41:[function(t,o,i){o.exports=Particle;var n=t("./Shape"),r=t("../math/Vec3");function Particle(){n.call(this),this.type=n.types.PARTICLE}Particle.prototype=new n,Particle.prototype.constructor=Particle,Particle.prototype.calculateLocalInertia=function(t,o){return(o=o||new r).set(0,0,0),o},Particle.prototype.volume=function(){return 0},Particle.prototype.updateBoundingSphereRadius=function(){this.boundingSphereRadius=0},Particle.prototype.calculateWorldAABB=function(t,o,i,n){i.copy(t),n.copy(t)}},{"../math/Vec3":30,"./Shape":43}],42:[function(t,o,i){o.exports=Plane;var n=t("./Shape"),r=t("../math/Vec3");function Plane(){n.call(this),this.type=n.types.PLANE,this.worldNormal=new r,this.worldNormalNeedsUpdate=!0,this.boundingSphereRadius=Number.MAX_VALUE}Plane.prototype=new n,Plane.prototype.constructor=Plane,Plane.prototype.computeWorldNormal=function(t){var o=this.worldNormal;o.set(0,0,1),t.vmult(o,o),this.worldNormalNeedsUpdate=!1},Plane.prototype.calculateLocalInertia=function(t,o){return o=o||new r},Plane.prototype.volume=function(){return Number.MAX_VALUE};var a=new r;Plane.prototype.calculateWorldAABB=function(t,o,i,n){a.set(0,0,1),o.vmult(a,a);var r=Number.MAX_VALUE;i.set(-r,-r,-r),n.set(r,r,r),1===a.x&&(n.x=t.x),1===a.y&&(n.y=t.y),1===a.z&&(n.z=t.z),-1===a.x&&(i.x=t.x),-1===a.y&&(i.y=t.y),-1===a.z&&(i.z=t.z)},Plane.prototype.updateBoundingSphereRadius=function(){this.boundingSphereRadius=Number.MAX_VALUE}},{"../math/Vec3":30,"./Shape":43}],43:[function(t,o,i){o.exports=n;var n=t("./Shape");t("../math/Vec3"),t("../math/Quaternion"),t("../material/Material");function n(){this.id=n.idCounter++,this.type=0,this.boundingSphereRadius=0,this.collisionResponse=!0,this.material=null}n.prototype.constructor=n,n.prototype.updateBoundingSphereRadius=function(){throw"computeBoundingSphereRadius() not implemented for shape type "+this.type},n.prototype.volume=function(){throw"volume() not implemented for shape type "+this.type},n.prototype.calculateLocalInertia=function(t,o){throw"calculateLocalInertia() not implemented for shape type "+this.type},n.idCounter=0,n.types={SPHERE:1,PLANE:2,BOX:4,COMPOUND:8,CONVEXPOLYHEDRON:16,HEIGHTFIELD:32,PARTICLE:64,CYLINDER:128,TRIMESH:256}},{"../material/Material":25,"../math/Quaternion":28,"../math/Vec3":30,"./Shape":43}],44:[function(t,o,i){o.exports=Sphere;var n=t("./Shape"),r=t("../math/Vec3");function Sphere(t){if(n.call(this),this.radius=void 0!==t?Number(t):1,this.type=n.types.SPHERE,this.radius<0)throw new Error("The sphere radius cannot be negative.");this.updateBoundingSphereRadius()}Sphere.prototype=new n,Sphere.prototype.constructor=Sphere,Sphere.prototype.calculateLocalInertia=function(t,o){o=o||new r;var i=2*t*this.radius*this.radius/5;return o.x=i,o.y=i,o.z=i,o},Sphere.prototype.volume=function(){return 4*Math.PI*this.radius/3},Sphere.prototype.updateBoundingSphereRadius=function(){this.boundingSphereRadius=this.radius},Sphere.prototype.calculateWorldAABB=function(t,o,i,n){for(var r=this.radius,a=["x","y","z"],l=0;li.x&&(i.x=r.x),r.yi.y&&(i.y=r.y),r.zi.z&&(i.z=r.z)},Trimesh.prototype.updateAABB=function(){this.computeLocalAABB(this.aabb)},Trimesh.prototype.updateBoundingSphereRadius=function(){for(var t=0,o=this.vertices,i=new r,n=0,a=o.length/3;n!==a;n++){this.getVertex(n,i);var l=i.norm2();l>t&&(t=l)}this.boundingSphereRadius=Math.sqrt(t)};new r;var b=new a,B=new l;Trimesh.prototype.calculateWorldAABB=function(t,o,i,n){var r=b,a=B;r.position=t,r.quaternion=o,this.aabb.toWorldFrame(r,a),i.copy(a.lowerBound),n.copy(a.upperBound)},Trimesh.prototype.volume=function(){return 4*Math.PI*this.boundingSphereRadius/3},Trimesh.createTorus=function(t,o,i,n,r){t=t||1,o=o||.5,i=i||8,n=n||6,r=r||2*Math.PI;for(var a=[],l=[],h=0;h<=i;h++)for(var c=0;c<=n;c++){var p=c/n*r,u=h/i*Math.PI*2,d=(t+o*Math.cos(u))*Math.cos(p),v=(t+o*Math.cos(u))*Math.sin(p),y=o*Math.sin(u);a.push(d,v,y)}for(h=1;h<=i;h++)for(c=1;c<=n;c++){var f=(n+1)*h+c-1,m=(n+1)*(h-1)+c-1,w=(n+1)*(h-1)+c,x=(n+1)*h+c;l.push(f,m,x),l.push(m,w,x)}return new Trimesh(a,l)}},{"../collision/AABB":3,"../math/Quaternion":28,"../math/Transform":29,"../math/Vec3":30,"../utils/Octree":50,"./Shape":43}],46:[function(t,o,i){o.exports=GSSolver;t("../math/Vec3"),t("../math/Quaternion");var n=t("./Solver");function GSSolver(){n.call(this),this.iterations=10,this.tolerance=1e-7}GSSolver.prototype=new n;var r=[],a=[],l=[];GSSolver.prototype.solve=function(t,o){var i,n,h,c,p,u=0,d=this.iterations,v=this.tolerance*this.tolerance,y=this.equations,f=y.length,m=o.bodies,w=m.length,x=t;if(0!==f)for(var g=0;g!==w;g++)m[g].updateSolveMassProperties();var b=a,B=l,S=r;b.length=f,B.length=f,S.length=f;for(g=0;g!==f;g++){var E=y[g];S[g]=0,B[g]=E.computeB(x),b[g]=1/E.computeC()}if(0!==f){for(g=0;g!==w;g++){var C=(P=m[g]).vlambda,A=P.wlambda;C.set(0,0,0),A&&A.set(0,0,0)}for(u=0;u!==d;u++){c=0;for(var R=0;R!==f;R++){E=y[R];i=B[R],n=b[R],(p=S[R])+(h=n*(i-E.computeGWlambda()-E.eps*p))E.maxForce&&(h=E.maxForce-p),S[R]+=h,c+=h>0?h:-h,E.addToWlambda(h)}if(c*c=0;i--)o.children[i].data.length||o.children.splice(i,1);Array.prototype.push.apply(t,o.children)}}},{"../collision/AABB":3,"../math/Vec3":30}],51:[function(t,o,i){function Pool(){this.objects=[],this.type=Object}o.exports=Pool,Pool.prototype.release=function(){for(var t=arguments.length,o=0;o!==t;o++)this.objects.push(arguments[o])},Pool.prototype.get=function(){return 0===this.objects.length?this.constructObject():this.objects.pop()},Pool.prototype.constructObject=function(){throw new Error("constructObject() not implemented in this Pool subclass yet!")}},{}],52:[function(t,o,i){function TupleDictionary(){this.data={keys:[]}}o.exports=TupleDictionary,TupleDictionary.prototype.get=function(t,o){if(t>o){var i=o;o=t,t=i}return this.data[t+"-"+o]},TupleDictionary.prototype.set=function(t,o,i){if(t>o){var n=o;o=t,t=n}var r=t+"-"+o;this.get(t,o)||this.data.keys.push(r),this.data[r]=i},TupleDictionary.prototype.reset=function(){for(var t=this.data,o=t.keys;o.length>0;){delete t[o.pop()]}}},{}],53:[function(t,o,i){function Utils(){}o.exports=Utils,Utils.defaults=function(t,o){for(var i in t=t||{},o)i in t||(t[i]=o[i]);return t}},{}],54:[function(t,o,i){o.exports=Vec3Pool;var n=t("../math/Vec3"),r=t("./Pool");function Vec3Pool(){r.call(this),this.type=n}Vec3Pool.prototype=new r,Vec3Pool.prototype.constructObject=function(){return new n}},{"../math/Vec3":30,"./Pool":51}],55:[function(t,o,i){o.exports=Narrowphase;var n=t("../collision/AABB"),r=t("../shapes/Shape"),a=t("../collision/Ray"),l=t("../math/Vec3"),h=t("../math/Transform"),c=(t("../shapes/ConvexPolyhedron"),t("../math/Quaternion")),p=(t("../solver/Solver"),t("../utils/Vec3Pool")),u=t("../equations/ContactEquation"),d=t("../equations/FrictionEquation");function Narrowphase(t){this.contactPointPool=[],this.frictionEquationPool=[],this.result=[],this.frictionResult=[],this.v3pool=new p,this.world=t,this.currentContactMaterial=null,this.enableFrictionReduction=!1}Narrowphase.prototype.createContactEquation=function(t,o,i,n,r,a){var l;this.contactPointPool.length?((l=this.contactPointPool.pop()).bi=t,l.bj=o):l=new u(t,o),l.enabled=t.collisionResponse&&o.collisionResponse&&i.collisionResponse&&n.collisionResponse;var h=this.currentContactMaterial;l.restitution=h.restitution,l.setSpookParams(h.contactEquationStiffness,h.contactEquationRelaxation,this.world.dt);var c=i.material||t.material,p=n.material||o.material;return c&&p&&c.restitution>=0&&p.restitution>=0&&(l.restitution=c.restitution*p.restitution),l.si=r||i,l.sj=a||n,l},Narrowphase.prototype.createFrictionEquationsFromContact=function(t,o){var i=t.bi,n=t.bj,r=t.si,a=t.sj,l=this.world,h=this.currentContactMaterial,c=h.friction,p=r.material||i.material,u=a.material||n.material;if(p&&u&&p.friction>=0&&u.friction>=0&&(c=p.friction*u.friction),c>0){var v=c*l.gravity.length(),y=i.invMass+n.invMass;y>0&&(y=1/y);var f=this.frictionEquationPool,m=f.length?f.pop():new d(i,n,v*y),w=f.length?f.pop():new d(i,n,v*y);return m.bi=w.bi=i,m.bj=w.bj=n,m.minForce=w.minForce=-v*y,m.maxForce=w.maxForce=v*y,m.ri.copy(t.ri),m.rj.copy(t.rj),w.ri.copy(t.ri),w.rj.copy(t.rj),t.ni.tangents(m.t,w.t),m.setSpookParams(h.frictionEquationStiffness,h.frictionEquationRelaxation,l.dt),w.setSpookParams(h.frictionEquationStiffness,h.frictionEquationRelaxation,l.dt),m.enabled=w.enabled=t.enabled,o.push(m,w),!0}return!1};var v=new l,y=new l,f=new l;Narrowphase.prototype.createFrictionFromAverage=function(t){var o=this.result[this.result.length-1];if(this.createFrictionEquationsFromContact(o,this.frictionResult)&&1!==t){var i=this.frictionResult[this.frictionResult.length-2],n=this.frictionResult[this.frictionResult.length-1];v.setZero(),y.setZero(),f.setZero();for(var r=o.bi,a=(o.bj,0);a!==t;a++)(o=this.result[this.result.length-1-a]).bodyA!==r?(v.vadd(o.ni,v),y.vadd(o.ri,y),f.vadd(o.rj,f)):(v.vsub(o.ni,v),y.vadd(o.rj,y),f.vadd(o.ri,f));var l=1/t;y.scale(l,i.ri),f.scale(l,i.rj),n.ri.copy(i.ri),n.rj.copy(i.rj),v.normalize(),v.tangents(i.t,n.t)}};var m=new l,w=new l,x=new c,g=new c;Narrowphase.prototype.getContacts=function(t,o,i,n,r,a,l){this.contactPointPool=r,this.frictionEquationPool=l,this.result=n,this.frictionResult=a;for(var h=x,c=g,p=m,u=w,d=0,v=t.length;d!==v;d++){var y=t[d],f=o[d],b=!1;y.material&&f.material&&(b=!0);for(var B=0;BS.boundingSphereRadius+C.boundingSphereRadius)){S.material&&C.material&&(i.getContactMaterial(S.material,C.material)||null),b?(this.currentContactMaterial=i.defaultContactMaterial2,this.currentContactMaterial.materials[0]=y.material,this.currentContactMaterial.materials[1]=f.material,this.currentContactMaterial.friction=y.material.friction+f.material.friction,this.currentContactMaterial.restitution=y.material.restitution*f.material.restitution):this.currentContactMaterial=i.defaultContactMaterial2,this.currentContactMaterial=i.defaultContactMaterial2;var A=this[S.type|C.type];A&&(S.type0&&k<0)if(f.vsub(u,m),y.copy(v),y.normalize(),_=m.dot(y),y.scale(_,m),m.vadd(u,m),(Z=m.distanceTo(f))0&&!0===n||u<=0&&!1===n))return!1;null===n&&(n=u>0)}return!0}var U=new l,D=new l,Q=new l,G=new l,X=[new l,new l,new l,new l,new l,new l],Y=new l,Z=new l,K=new l,J=new l;Narrowphase.prototype[r.types.SPHERE|r.types.BOX]=Narrowphase.prototype.sphereBox=function(t,o,i,n,r,a,l,h){var c=this.v3pool,p=X;i.vsub(n,U),o.getSideNormals(p,a);for(var u=t.radius,d=!1,v=Z,y=K,f=J,m=null,w=0,x=0,g=0,b=null,B=0,S=p.length;B!==S&&!1===d;B++){var E=D;E.copy(p[B]);var C=E.norm();E.normalize();var A=U.dot(E);if(A0){var R=Q,P=G;R.copy(p[(B+1)%3]),P.copy(p[(B+2)%3]);var M=R.norm(),q=P.norm();R.normalize(),P.normalize();var V=U.dot(R),z=U.dot(P);if(V-M&&z-q){var T=Math.abs(A-C-u);(null===b||T0){for(var M=[],q=0,V=B.length;q!==V;q++){var z=c.get();a.vmult(d[B[q]],z),n.vadd(z,z),M.push(z)}if(pointInPolygon(M,S,i)){x=!0;var T=this.createContactEquation(l,h,t,o);S.mult(-v,T.ri),S.negate(T.ni);var N=c.get();S.mult(-R,N);var F=c.get();S.mult(-v,F),i.vsub(n,T.rj),T.rj.vadd(F,T.rj),T.rj.vadd(N,T.rj),T.rj.vadd(n,T.rj),T.rj.vsub(h.position,T.rj),T.ri.vadd(i,T.ri),T.ri.vsub(l.position,T.ri),c.release(N),c.release(F),this.result.push(T),this.createFrictionEquationsFromContact(T,this.frictionResult);q=0;for(var I=M.length;q!==I;q++)c.release(M[q]);return}for(q=0;q!==B.length;q++){var W=c.get(),L=c.get();a.vmult(d[B[(q+1)%B.length]],W),a.vmult(d[B[(q+2)%B.length]],L),n.vadd(W,W),n.vadd(L,L);var j=tt;L.vsub(W,j);var O=et;j.unit(O);var H=c.get(),k=c.get();i.vsub(W,k);var _=k.dot(O);O.mult(_,H),H.vadd(W,H);var U=c.get();if(H.vsub(i,U),_>0&&_*_t.boundingSphereRadius+o.boundingSphereRadius)&&t.findSeparatingAxis(o,i,r,n,a,v,u,d)){var y=[],f=vt;t.clipAgainstHull(i,r,o,n,a,v,-100,100,y);for(var m=0,w=0;w!==y.length;w++){var x=this.createContactEquation(l,h,t,o,c,p),g=x.ri,b=x.rj;v.negate(x.ni),y[w].normal.negate(f),f.mult(y[w].depth,f),y[w].point.vadd(f,g),b.copy(y[w].point),g.vsub(i,g),b.vsub(n,b),g.vadd(i,g),g.vsub(l.position,g),b.vadd(n,b),b.vsub(h.position,b),this.result.push(x),m++,this.enableFrictionReduction||this.createFrictionEquationsFromContact(x,this.frictionResult)}this.enableFrictionReduction&&m&&this.createFrictionFromAverage(m)}};var yt=new l,ft=new l,mt=new l;Narrowphase.prototype[r.types.PLANE|r.types.PARTICLE]=Narrowphase.prototype.planeParticle=function(t,o,i,n,r,a,l,h){var c=yt;c.set(0,0,1),l.quaternion.vmult(c,c);var p=ft;if(n.vsub(l.position,p),c.dot(p)<=0){var u=this.createContactEquation(h,l,o,t);u.ni.copy(c),u.ni.negate(u.ni),u.ri.set(0,0,0);var d=mt;c.mult(c.dot(n),d),n.vsub(d,d),u.rj.copy(d),this.result.push(u),this.createFrictionEquationsFromContact(u,this.frictionResult)}};var wt=new l;Narrowphase.prototype[r.types.PARTICLE|r.types.SPHERE]=Narrowphase.prototype.sphereParticle=function(t,o,i,n,r,a,l,h){var c=wt;if(c.set(0,0,1),n.vsub(i,c),c.norm2()<=t.radius*t.radius){var p=this.createContactEquation(h,l,o,t);c.normalize(),p.rj.copy(c),p.rj.mult(t.radius,p.rj),p.ni.copy(c),p.ni.negate(p.ni),p.ri.set(0,0,0),this.result.push(p),this.createFrictionEquationsFromContact(p,this.frictionResult)}};var xt=new c,gt=new l,bt=(new l,new l),Bt=new l,St=new l;Narrowphase.prototype[r.types.PARTICLE|r.types.CONVEXPOLYHEDRON]=Narrowphase.prototype.convexParticle=function(t,o,i,n,r,a,l,h){var c=-1,p=bt,u=St,d=null,v=gt;if(v.copy(n),v.vsub(i,v),r.conjugate(xt),xt.vmult(v,v),t.pointIsInside(v)){t.worldVerticesNeedsUpdate&&t.computeWorldVertices(i,r),t.worldFaceNormalsNeedsUpdate&&t.computeWorldFaceNormals(r);for(var y=0,f=t.faces.length;y!==f;y++){var m=[t.worldVertices[t.faces[y][0]]],w=t.worldFaceNormals[y];n.vsub(m[0],Bt);var x=-w.dot(Bt);(null===d||Math.abs(x)p.length||x>p[0].length)){m<0&&(m=0),w<0&&(w=0),x<0&&(x=0),g<0&&(g=0),m>=p.length&&(m=p.length-1),w>=p.length&&(w=p.length-1),g>=p[0].length&&(g=p[0].length-1),x>=p[0].length&&(x=p[0].length-1);var b=[];o.getRectMinMax(m,x,w,g,b);var B=b[0],S=b[1];if(!(f.z-d>S||f.z+dp.length||x>p[0].length)){f<0&&(f=0),m<0&&(m=0),w<0&&(w=0),x<0&&(x=0),f>=p.length&&(f=p.length-1),m>=p.length&&(m=p.length-1),x>=p[0].length&&(x=p[0].length-1),w>=p[0].length&&(w=p[0].length-1);var g=[];o.getRectMinMax(f,w,m,x,g);var b=g[0],B=g[1];if(!(y.z-u>B||y.z+u2)return}}}},{"../collision/AABB":3,"../collision/Ray":9,"../equations/ContactEquation":19,"../equations/FrictionEquation":21,"../math/Quaternion":28,"../math/Transform":29,"../math/Vec3":30,"../shapes/ConvexPolyhedron":38,"../shapes/Shape":43,"../solver/Solver":47,"../utils/Vec3Pool":54}],56:[function(t,o,i){o.exports=World;var n=t("../shapes/Shape"),r=t("../math/Vec3"),a=t("../math/Quaternion"),l=t("../solver/GSSolver"),h=(t("../utils/Vec3Pool"),t("../equations/ContactEquation"),t("../equations/FrictionEquation"),t("./Narrowphase")),c=t("../utils/EventTarget"),p=t("../collision/ArrayCollisionMatrix"),u=t("../material/Material"),d=t("../material/ContactMaterial"),v=t("../objects/Body"),y=t("../utils/TupleDictionary"),f=t("../collision/RaycastResult"),m=t("../collision/AABB"),w=t("../collision/Ray"),x=t("../collision/NaiveBroadphase");function World(){c.apply(this),this.dt=-1,this.allowSleep=!1,this.contacts=[],this.allContacts=[],this.frictionEquations=[],this.quatNormalizeSkip=0,this.quatNormalizeFast=!1,this.time=0,this.stepnumber=0,this.default_dt=1/60,this.nextId=0,this.gravity=new r,this.broadphase=new x,this.bodies=[],this.callBackBody=[],this.solver=new l,this.constraints=[],this.narrowphase=new h(this),this.collisionMatrix=new p,this.collisionMatrixPrevious=new p,this.materials=[],this.contactmaterials=[],this.contactMaterialTable=new y,this.defaultMaterial=new u("default"),this.defaultContactMaterial=new d(this.defaultMaterial,this.defaultMaterial,{friction:.3,restitution:0}),this.defaultContactMaterial2=new d(this.defaultMaterial,this.defaultMaterial,{friction:.3,restitution:0}),this.doProfiling=!1,this.profile={solve:0,makeContactConstraints:0,broadphase:0,integrate:0,narrowphase:0},this.subsystems=[],this.addBodyEvent={type:"addBody",body:null},this.removeBodyEvent={type:"removeBody",body:null}}World.prototype=new c;new m;var g=new w;if(World.prototype.getContactMaterial=function(t,o){return this.contactMaterialTable.get(t.id,o.id)},World.prototype.numObjects=function(){return this.bodies.length},World.prototype.collisionMatrixTick=function(){var t=this.collisionMatrixPrevious;this.collisionMatrixPrevious=this.collisionMatrix,this.collisionMatrix=t,this.collisionMatrix.reset()},World.prototype.add=World.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 v&&(t.initAngularVelocity.copy(t.angularVelocity),t.initQuaternion.copy(t.quaternion)),this.collisionMatrix.setNumObjects(this.bodies.length),this.addBodyEvent.body=t,this.dispatchEvent(this.addBodyEvent))},World.prototype.addConstraint=function(t){this.constraints.push(t)},World.prototype.removeConstraint=function(t){var o=this.constraints.indexOf(t);-1!==o&&this.constraints.splice(o,1)},World.prototype.rayTest=function(t,o,i){i instanceof f?this.raycastClosest(t,o,{skipBackfaces:!0},i):this.raycastAll(t,o,{skipBackfaces:!0},i)},World.prototype.raycastAll=function(t,o,i,n){return i.mode=w.ALL,i.from=t,i.to=o,i.callback=n,g.intersectWorld(this,i)},World.prototype.raycastAny=function(t,o,i,n){return i.mode=w.ANY,i.from=t,i.to=o,i.result=n,g.intersectWorld(this,i)},World.prototype.raycastClosest=function(t,o,i,n){return i.mode=w.CLOSEST,i.from=t,i.to=o,i.result=n,g.intersectWorld(this,i)},World.prototype.remove=function(t){t.world=null;var o=this.bodies.length-1,i=this.bodies,n=i.indexOf(t);if(-1!==n){i.splice(n,1);for(var r=0;r!==i.length;r++)i[r].index=r;this.collisionMatrix.setNumObjects(o),this.removeBodyEvent.body=t,this.dispatchEvent(this.removeBodyEvent)}},World.prototype.removeBody=World.prototype.remove,World.prototype.addMaterial=function(t){this.materials.push(t)},World.prototype.addContactMaterial=function(t){this.contactmaterials.push(t),this.contactMaterialTable.set(t.materials[0].id,t.materials[1].id,t)},"undefined"==typeof performance&&(performance={}),!performance.now){var b=Date.now();performance.timing&&performance.timing.navigationStart&&(b=performance.timing.navigationStart),performance.now=function(){return Date.now()-b}}var B=new r;World.prototype.step=function(t,o,i){if(i=i||10,0===(o=o||0))this.internalStep(t),this.time+=t;else{var n=Math.floor((this.time+o)/t)-Math.floor(this.time/t);n=Math.min(n,i);for(var r=performance.now(),a=0;a!==n&&(this.internalStep(t),!(performance.now()-r>1e3*t));a++);this.time+=o;for(var l=this.time%t/t,h=B,c=this.bodies,p=0;p!==c.length;p++){var u=c[p];u.type!==v.STATIC&&u.sleepState!==v.SLEEPING?(u.position.vsub(u.previousPosition,h),h.scale(l,h),u.position.vadd(h,u.interpolatedPosition)):(u.interpolatedPosition.copy(u.position),u.interpolatedQuaternion.copy(u.quaternion))}}};var S={type:"postStep"},E={type:"preStep"},C={type:"collide",body:null,contact:null},A=[],R=[],P=[],M=[],q=(new r,new r,new r,new r,new r,new r,new r,new r,new r,new a,new a),V=new a,z=new r;World.prototype.internalStep=function(t){this.dt=t;var o,i=this.contacts,r=this.allContacts,a=P,l=M,h=this.numObjects(),c=this.bodies,p=this.solver,u=this.gravity,d=this.doProfiling,y=this.profile,f=v.DYNAMIC,m=this.constraints,w=R,x=(u.norm(),u.x),g=u.y,b=u.z,B=0;for(d&&(o=performance.now()),B=0;B!==h;B++){if((Q=c[B]).type&f){var T=Q.force,N=Q.mass;T.x+=N*x,T.y+=N*g,T.z+=N*b}}B=0;for(var F=this.subsystems.length;B!==F;B++)this.subsystems[B].update();d&&(o=performance.now()),a.length=0,l.length=0,this.broadphase.collisionPairs(this,a,l),d&&(y.broadphase=performance.now()-o);var I=m.length;for(B=0;B!==I;B++){if(!(X=m[B]).collideConnected)for(var W=a.length-1;W>=0;W-=1)(X.bodyA===a[W]&&X.bodyB===l[W]||X.bodyB===a[W]&&X.bodyA===l[W])&&(a.splice(W,1),l.splice(W,1))}this.collisionMatrixTick(),d&&(o=performance.now());var L=A,j=r.length;for(B=0;B!==j;B++)L.push(r[B]);i.length=0,r.length=0;var O=this.frictionEquations.length;for(B=0;B!==O;B++)w.push(this.frictionEquations[B]);this.frictionEquations.length=0,this.narrowphase.getContacts(a,l,this,r,L,this.frictionEquations,w);for(var H=r.length,k=0;k!=H;k++){var _=r[k];_.bi.isTrigger||_.bj.isTrigger||i.push(_)}d&&(y.narrowphase=performance.now()-o),d&&(o=performance.now());for(B=0;B=0&&G.material.friction>=0&&Q.material.friction*G.material.friction,Q.material.restitution>=0&&G.material.restitution>=0&&(X.restitution=Q.material.restitution*G.material.restitution)),p.addEquation(X),Q.allowSleep&&Q.type===v.DYNAMIC&&Q.sleepState===v.SLEEPING&&G.sleepState===v.AWAKE&&G.type!==v.STATIC)G.velocity.norm2()+G.angularVelocity.norm2()>=2*Math.pow(G.sleepSpeedLimit,2)&&(Q._wakeUpAfterNarrowphase=!0);if(G.allowSleep&&G.type===v.DYNAMIC&&G.sleepState===v.SLEEPING&&Q.sleepState===v.AWAKE&&Q.type!==v.STATIC)Q.velocity.norm2()+Q.angularVelocity.norm2()>=2*Math.pow(Q.sleepSpeedLimit,2)&&(G._wakeUpAfterNarrowphase=!0);this.collisionMatrix.set(Q,G,!0),this.collisionMatrixPrevious.get(Q,G)||(C.body=G,C.contact=X,Q.dispatchEvent(C),C.body=Q,G.dispatchEvent(C))}for(d&&(y.makeContactConstraints=performance.now()-o,o=performance.now()),B=0;B!==h;B++){(Q=c[B])._wakeUpAfterNarrowphase&&(Q.wakeUp(),Q._wakeUpAfterNarrowphase=!1)}I=m.length;for(B=0;B!==I;B++){var X;(X=m[B]).update();W=0;for(var Y=X.equations.length;W!==Y;W++){var Z=X.equations[W];p.addEquation(Z)}}p.solve(t,this),d&&(y.solve=performance.now()-o),p.removeAllEquations();var K=Math.pow;for(B=0;B!==h;B++){if((Q=c[B]).type&f){var J=K(1-Q.linearDamping,t),$=Q.velocity;$.mult(J,$);var tt=Q.angularVelocity;if(tt){var et=K(1-Q.angularDamping,t);tt.mult(et,tt)}}}for(this.dispatchEvent(E),B=0;B!==h;B++){(Q=c[B]).preStep&&Q.preStep.call(Q)}d&&(o=performance.now());var ot=q,it=V,nt=this.stepnumber,rt=v.DYNAMIC|v.KINEMATIC,st=nt%(this.quatNormalizeSkip+1)==0,at=this.quatNormalizeFast,lt=.5*t;n.types.PLANE,n.types.CONVEXPOLYHEDRON;for(this.callBackBody.length=0,B=0;B!==h;B++){var ht=c[B],ct=ht.force,pt=ht.torque;if(ht.type&rt&&ht.sleepState!==v.SLEEPING){var ut=ht.velocity,dt=ht.angularVelocity,vt=ht.position,yt=ht.quaternion,ft=ht.invMass,mt=ht.invInertiaWorld;ut.x+=ct.x*ft*t,ut.y+=ct.y*ft*t,ut.z+=ct.z*ft*t,ht.angularVelocity&&(mt.vmult(pt,z),z.mult(t,z),z.vadd(dt,dt)),vt.x+=ut.x*t,vt.y+=ut.y*t,vt.z+=ut.z*t,ht.angularVelocity&&(ot.set(dt.x,dt.y,dt.z,0),ot.mult(yt,it),yt.x+=lt*it.x,yt.y+=lt*it.y,yt.z+=lt*it.z,yt.w+=lt*it.w,st&&(at?yt.normalizeFast():yt.normalize())),this.callBackBody.push(ht),ht.aabb&&(ht.aabbNeedsUpdate=!0),ht.updateInertiaWorld&&ht.updateInertiaWorld()}}for(this.clearForces(),this.broadphase.dirty=!0,d&&(y.integrate=performance.now()-o),this.time+=t,this.stepnumber+=1,this.dispatchEvent(S),B=0;B!==h;B++){var wt=(Q=c[B]).postStep;wt&&wt.call(Q)}if(this.allowSleep)for(B=0;B!==h;B++)c[B].sleepTick(this.time)},World.prototype.clearForces=function(){for(var t=this.bodies,o=t.length,i=0;i!==o;i++){var n=t[i];n.force,n.torque;n.force.set(0,0,0),n.torque.set(0,0,0)}}},{"../collision/AABB":3,"../collision/ArrayCollisionMatrix":4,"../collision/NaiveBroadphase":7,"../collision/Ray":9,"../collision/RaycastResult":10,"../equations/ContactEquation":19,"../equations/FrictionEquation":21,"../material/ContactMaterial":24,"../material/Material":25,"../math/Quaternion":28,"../math/Vec3":30,"../objects/Body":31,"../shapes/Shape":43,"../solver/GSSolver":46,"../utils/EventTarget":49,"../utils/TupleDictionary":52,"../utils/Vec3Pool":54,"./Narrowphase":55}]},{},[2])(2)}));