cannon.min.js 133 KB

1
  1. !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<i.length;r++)s(i[r]);return s}({1:[function(t,o,i){o.exports={name:"cannon",version:"0.6.2",description:"A lightweight 3D physics engine written in JavaScript.",homepage:"https://github.com/schteppe/cannon.js",author:"Stefan Hedman <schteppe@gmail.com> (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;c<t.length;c++){var p=t[c];h&&(h.vmult(p,r),p=r),p.x>l.x&&(l.x=p.x),p.x<a.x&&(a.x=p.x),p.y>l.y&&(l.y=p.y),p.y<a.y&&(a.y=p.y),p.z>l.z&&(l.z=p.z),p.z<a.z&&(a.z=p.z)}return o&&(o.vadd(a,a),o.vadd(l,l)),n&&(a.x-=n,a.y-=n,a.z-=n,l.x+=n,l.y+=n,l.z+=n),this},AABB.prototype.copy=function(t){return this.lowerBound.copy(t.lowerBound),this.upperBound.copy(t.upperBound),this},AABB.prototype.clone=function(){return(new AABB).copy(this)},AABB.prototype.extend=function(t){var o=t.lowerBound.x;this.lowerBound.x>o&&(this.lowerBound.x=o);var i=t.upperBound.x;this.upperBound.x<i&&(this.upperBound.x=i);o=t.lowerBound.y;this.lowerBound.y>o&&(this.lowerBound.y=o);i=t.upperBound.y;this.upperBound.y<i&&(this.upperBound.y=i);o=t.lowerBound.z;this.lowerBound.z>o&&(this.lowerBound.z=o);i=t.upperBound.z;this.upperBound.z<i&&(this.upperBound.z=i)},AABB.prototype.overlaps=function(t){var o=this.lowerBound,i=this.upperBound,n=t.lowerBound,r=t.upperBound;return(n.x<=i.x&&i.x<=r.x||o.x<=r.x&&r.x<=i.x)&&(n.y<=i.y&&i.y<=r.y||o.y<=r.y&&r.y<=i.y)&&(n.z<=i.z&&i.z<=r.z||o.z<=r.z&&r.z<=i.z)},AABB.prototype.contains=function(t){var o=this.lowerBound,i=this.upperBound,n=t.lowerBound,r=t.upperBound;return o.x<=n.x&&i.x>=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()<a&&(i.push(t),n.push(o))},Broadphase.prototype.doBoundingBoxBroadphase=function(t,o,i,n){t.aabbNeedsUpdate&&t.computeAABB(),o.aabbNeedsUpdate&&o.computeAABB(),t.aabb.overlaps(o.aabb)&&(i.push(t),n.push(o))};var h={keys:[]},c=[],p=[];Broadphase.prototype.makePairsUnique=function(t,o){for(var i=h,n=c,r=p,a=t.length,l=0;l!==a;l++)n[l]=t[l],r[l]=o[l];t.length=0,o.length=0;for(l=0;l!==a;l++){var u=n[l].id,d=r[l].id;i[v=u<d?u+","+d:d+","+u]=l,i.keys.push(v)}for(l=0;l!==i.keys.length;l++){var v=i.keys.pop(),y=i[v];t.push(n[y]),o.push(r[y]),delete i[v]}},Broadphase.prototype.setWorld=function(t){};var u=new r;Broadphase.boundingSphereCheck=function(t,o){var i=u;return t.position.vsub(o.position,i),Math.pow(t.shape.boundingSphereRadius+o.shape.boundingSphereRadius,2)>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<h;c++)this.bins[c]=[],this.binLengths[c]=0}GridBroadphase.prototype=new n,GridBroadphase.prototype.constructor=GridBroadphase;var l=new r;new r;GridBroadphase.prototype.collisionPairs=function(t,o,i){for(var n=t.numObjects(),r=t.bodies,h=this.aabbMax,c=this.aabbMin,p=this.nx,u=this.ny,d=this.nz,v=u*d,y=d,f=h.x,m=h.y,w=h.z,x=c.x,g=c.y,b=c.z,B=p/(f-x),S=u/(m-g),E=d/(w-b),C=(f-x)/p,A=(m-g)/u,R=(w-b)/d,P=.5*Math.sqrt(C*C+A*A+R*R),M=a.types,q=M.SPHERE,V=M.PLANE,z=(M.BOX,M.COMPOUND,M.CONVEXPOLYHEDRON,this.bins),T=this.binLengths,N=this.bins.length,F=0;F!==N;F++)T[F]=0;var I=Math.ceil;c=Math.min,h=Math.max;function addBoxToBins(t,o,i,n,r,a,l){var h=(t-x)*B|0,c=(o-g)*S|0,f=(i-b)*E|0,m=I((n-x)*B),w=I((r-g)*S),C=I((a-b)*E);h<0?h=0:h>=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)<P){var $=X+Z+J;z[$][T[$]++]=ot}break;default:ot.aabbNeedsUpdate&&ot.computeAABB(),addBoxToBins(ot.aabb.lowerBound.x,ot.aabb.lowerBound.y,ot.aabb.lowerBound.z,ot.aabb.upperBound.x,ot.aabb.upperBound.y,ot.aabb.upperBound.z,ot)}}for(F=0;F!==N;F++){var tt=T[F];if(tt>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;n<t.bodies.length;n++){var r=t.bodies[n];r.aabbNeedsUpdate&&r.computeAABB(),r.aabb.overlaps(o)&&i.push(r)}return i}},{"./AABB":3,"./Broadphase":5}],8:[function(t,o,i){function ObjectCollisionMatrix(){this.matrix={}}o.exports=ObjectCollisionMatrix,ObjectCollisionMatrix.prototype.get=function(t,o){if(t=t.id,(o=o.id)>t){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+a<l*p-h*h}Ray.pointInTriangle=pointInTriangle;var y=new n,f=new r;Ray.prototype.intersectBody=function(t,o){o&&(this.result=o,this._updateDirection());var i=this.checkCollisionResponse;if((!i||t.collisionResponse)&&0!=(this.collisionFilterGroup&t.collisionFilterMask)&&0!=(t.collisionFilterGroup&this.collisionFilterMask))for(var n=y,r=f,a=0,l=t.shapes.length;a<l;a++){var h=t.shapes[a];if((!i||h.collisionResponse)&&(t.quaternion.mult(t.shapeOrientations[a],r),t.quaternion.vmult(t.shapeOffsets[a],n),n.vadd(t.position,n),this.intersectShape(h,r,n,t),this.result._shouldStop))break}},Ray.prototype.intersectBodies=function(t,o){o&&(this.result=o,this._updateDirection());for(var i=0,n=t.length;!this.result._shouldStop&&i<n;i++)this.intersectBody(t[i])},Ray.prototype._updateDirection=function(){this.to.vsub(this.from,this._direction),this._direction.normalize()},Ray.prototype.intersectShape=function(t,o,i,n){if(!(function(t,o,i){i.vsub(t,N);var n=N.dot(o);return o.mult(n,F),F.vadd(t,F),i.distanceTo(F)}(this.from,this._direction,i)>t.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)<u)){var d=c.dot(h);if(!(Math.abs(d)<this.precision)){var v=new n,y=new n,f=new n;a.vsub(i,v);var m=-c.dot(v)/d;h.scale(m,y),a.vadd(y,f),this.reportIntersection(c,f,t,r,-1)}}},Ray.prototype[h.types.PLANE]=Ray.prototype.intersectPlane,Ray.prototype.getAABB=function(t){var o=this.to,i=this.from;t.lowerBound.x=Math.min(o.x,i.x),t.lowerBound.y=Math.min(o.y,i.y),t.lowerBound.z=Math.min(o.z,i.z),t.upperBound.x=Math.max(o.x,i.x),t.upperBound.y=Math.max(o.y,i.y),t.upperBound.z=Math.max(o.z,i.z)};var b={faceList:[0]};Ray.prototype.intersectHeightfield=function(t,o,i,r){t.data,t.elementSize;var l=new n,h=new Ray(this.from,this.to);a.pointToLocalFrame(i,o,h.from,h.from),a.pointToLocalFrame(i,o,h.to,h.to);var c=[],p=null,u=null,d=null,v=null,y=t.getIndexOfPosition(h.from.x,h.from.y,c,!1);if(y&&(p=c[0],u=c[1],d=c[0],v=c[1]),(y=t.getIndexOfPosition(h.to.x,h.to.y,c,!1))&&((null===p||c[0]<p)&&(p=c[0]),(null===d||c[0]>d)&&(d=c[0]),(null===u||c[1]<u)&&(u=c[1]),(null===v||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&&S<b;S++){var A=h?h[S]:S,R=c[A],P=u[A],M=o,q=i;l.copy(p[R[0]]),M.vmult(l,l),l.vadd(q,l),l.vsub(v,l),M.vmult(P,a);var V=d.dot(a);if(!(Math.abs(V)<this.precision)){var z=a.dot(l)/V;if(!(z<0)){d.mult(z,m),m.vadd(v,m),w.copy(p[R[0]]),M.vmult(w,w),q.vadd(w,w);for(var T=1;!B._shouldStop&&T<R.length-1;T++){x.copy(p[R[T]]),g.copy(p[R[T+1]]),M.vmult(x,x),M.vmult(g,g),q.vadd(x,x),q.vadd(g,g);var N=m.distanceTo(v);!pointInTriangle(m,w,x,g)&&!pointInTriangle(m,x,w,g)||N>f||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<c.distance||!c.hasHit)&&(this.hasHit=!0,c.hasHit=!0,c.set(a,l,t,o,i,n,h));break;case Ray.ANY:this.hasHit=!0,c.hasHit=!0,c.set(a,l,t,o,i,n,h),c._shouldStop=!0}};var N=new n,F=new n},{"../collision/AABB":3,"../collision/RaycastResult":10,"../math/Quaternion":28,"../math/Transform":29,"../math/Vec3":30,"../shapes/Box":37,"../shapes/ConvexPolyhedron":38,"../shapes/Shape":43}],10:[function(t,o,i){var n=t("../math/Vec3");function RaycastResult(){this.rayFromWorld=new n,this.rayToWorld=new n,this.hitNormalWorld=new n,this.hitPointWorld=new n,this.hasHit=!1,this.shape=null,this.body=null,this.hitFaceIndex=-1,this.distance=-1,this._shouldStop=!1}o.exports=RaycastResult,RaycastResult.prototype.reset=function(){this.rayFromWorld.setZero(),this.rayToWorld.setZero(),this.hitNormalWorld.setZero(),this.hitPointWorld.setZero(),this.hasHit=!1,this.shape=null,this.body=null,this.hitFaceIndex=-1,this.distance=-1,this._shouldStop=!1},RaycastResult.prototype.abort=function(){this._shouldStop=!0},RaycastResult.prototype.set=function(t,o,i,n,r,a,l){this.rayFromWorld.copy(t),this.rayToWorld.copy(o),this.hitNormalWorld.copy(i),this.hitPointWorld.copy(n),this.shape=r,this.body=a,this.distance=l}},{"../math/Vec3":30}],11:[function(t,o,i){t("../shapes/Shape");var n=t("../collision/Broadphase");function SAPBroadphase(t){n.apply(this),this.axisList=[],this.world=null,this.axisIndex=0;var o=this.axisList;this._addBodyHandler=function(t){o.push(t.body)},this._removeBodyHandler=function(t){var i=o.indexOf(t.body);-1!==i&&o.splice(i,1)},t&&this.setWorld(t)}o.exports=SAPBroadphase,SAPBroadphase.prototype=new n,SAPBroadphase.prototype.setWorld=function(t){this.axisList.length=0;for(var o=0;o<t.bodies.length;o++)this.axisList.push(t.bodies[o]);t.removeEventListener("addBody",this._addBodyHandler),t.removeEventListener("removeBody",this._removeBodyHandler),t.addEventListener("addBody",this._addBodyHandler),t.addEventListener("removeBody",this._removeBodyHandler),this.world=t,this.dirty=!0},SAPBroadphase.insertionSortX=function(t){for(var o=1,i=t.length;o<i;o++){for(var n=t[o],r=o-1;r>=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<i;o++){for(var n=t[o],r=o-1;r>=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<i;o++){for(var n=t[o],r=o-1;r>=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;r<l;r++){var p=a[r];if(this.needBroadphaseCollision(c,p)){if(!SAPBroadphase.checkBounds(c,p,h))break;this.intersectionTest(c,p,o,i)}}}},SAPBroadphase.prototype.sortList=function(){for(var t=this.axisList,o=this.axisIndex,i=t.length,n=0;n!==i;n++){var r=t[n];r.aabbNeedsUpdate&&r.computeAABB()}0===o?SAPBroadphase.insertionSortX(t):1===o?SAPBroadphase.insertionSortY(t):2===o&&SAPBroadphase.insertionSortZ(t)},SAPBroadphase.checkBounds=function(t,o,i){var n,r;0===i?(n=t.position.x,r=o.position.x):1===i?(n=t.position.y,r=o.position.y):2===i&&(n=t.position.z,r=o.position.z);var a=t.boundingRadius,l=o.boundingRadius;return r-l<n+a},SAPBroadphase.prototype.autoDetectAxis=function(){for(var t=0,o=0,i=0,n=0,r=0,a=0,l=this.axisList,h=l.length,c=1/h,p=0;p!==h;p++){var u=l[p],d=u.position.x;t+=d,o+=d*d;var v=u.position.y;i+=v,n+=v*v;var y=u.position.z;r+=y,a+=y*y}var f=o-t*t*c,m=n-i*i*c,w=a-r*r*c;this.axisIndex=f>m?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<a.length;l++){var h=a[l];h.aabbNeedsUpdate&&h.computeAABB(),h.aabb.overlaps(o)&&i.push(h)}return i}},{"../collision/Broadphase":5,"../shapes/Shape":43}],12:[function(t,o,i){o.exports=ConeTwistConstraint;t("./Constraint");var n=t("./PointToPointConstraint"),r=t("../equations/ConeEquation"),a=t("../equations/RotationalEquation"),l=(t("../equations/ContactEquation"),t("../math/Vec3"));function ConeTwistConstraint(t,o,i){var h=void 0!==(i=i||{}).maxForce?i.maxForce:1e6,c=i.pivotA?i.pivotA.clone():new l,p=i.pivotB?i.pivotB.clone():new l;this.axisA=i.axisA?i.axisA.clone():new l,this.axisB=i.axisB?i.axisB.clone():new l,n.call(this,t,c,o,p,h),this.collideConnected=!!i.collideConnected,this.angle=void 0!==i.angle?i.angle:0;var u=this.coneEquation=new r(t,o,i),d=this.twistEquation=new a(t,o,i);this.twistAngle=void 0!==i.twistAngle?i.twistAngle:0,u.maxForce=0,u.minForce=-h,d.maxForce=0,d.minForce=-h,this.equations.push(u,d)}ConeTwistConstraint.prototype=new n,ConeTwistConstraint.constructor=ConeTwistConstraint;new l,new l;ConeTwistConstraint.prototype.update=function(){var t=this.bodyA,o=this.bodyB,i=this.coneEquation,r=this.twistEquation;n.prototype.update.call(this),t.vectorToWorldFrame(this.axisA,i.axisA),o.vectorToWorldFrame(this.axisB,i.axisB),this.axisA.tangents(r.axisA,r.axisA),t.vectorToWorldFrame(r.axisA,r.axisA),this.axisB.tangents(r.axisB,r.axisB),o.vectorToWorldFrame(r.axisB,r.axisB),i.angle=this.angle,r.maxAngle=this.twistAngle}},{"../equations/ConeEquation":18,"../equations/ContactEquation":19,"../equations/RotationalEquation":22,"../math/Vec3":30,"./Constraint":13,"./PointToPointConstraint":17}],13:[function(t,o,i){o.exports=Constraint;var n=t("../utils/Utils");function Constraint(t,o,i){i=n.defaults(i,{collideConnected:!0,wakeUpBodies:!0}),this.equations=[],this.bodyA=t,this.bodyB=o,this.id=Constraint.idCounter++,this.collideConnected=i.collideConnected,i.wakeUpBodies&&(t&&t.wakeUp(),o&&o.wakeUp())}Constraint.prototype.update=function(){throw new Error("method update() not implmemented in this Constraint subclass!")},Constraint.prototype.enable=function(){for(var t=this.equations,o=0;o<t.length;o++)t[o].enabled=!0},Constraint.prototype.disable=function(){for(var t=this.equations,o=0;o<t.length;o++)t[o].enabled=!1},Constraint.idCounter=0},{"../utils/Utils":53}],14:[function(t,o,i){o.exports=DistanceConstraint;var n=t("./Constraint"),r=t("../equations/ContactEquation");function DistanceConstraint(t,o,i,a){n.call(this,t,o),void 0===i&&(i=t.position.distanceTo(o.position)),void 0===a&&(a=1e6),this.distance=i;var l=this.distanceEquation=new r(t,o);this.equations.push(l),l.minForce=-a,l.maxForce=a}DistanceConstraint.prototype=new n,DistanceConstraint.prototype.update=function(){var t=this.bodyA,o=this.bodyB,i=this.distanceEquation,n=.5*this.distance,r=i.ni;o.position.vsub(t.position,r),r.normalize(),r.mult(n,i.ri),r.mult(-n,i.rj)}},{"../equations/ContactEquation":19,"./Constraint":13}],15:[function(t,o,i){o.exports=HingeConstraint;t("./Constraint");var n=t("./PointToPointConstraint"),r=t("../equations/RotationalEquation"),a=t("../equations/RotationalMotorEquation"),l=(t("../equations/ContactEquation"),t("../math/Vec3"));function HingeConstraint(t,o,i){var h=void 0!==(i=i||{}).maxForce?i.maxForce:1e6,c=i.pivotA?i.pivotA.clone():new l,p=i.pivotB?i.pivotB.clone():new l;n.call(this,t,c,o,p,h),(this.axisA=i.axisA?i.axisA.clone():new l(1,0,0)).normalize(),(this.axisB=i.axisB?i.axisB.clone():new l(1,0,0)).normalize();var u=this.rotationalEquation1=new r(t,o,i),d=this.rotationalEquation2=new r(t,o,i),v=this.motorEquation=new a(t,o,h);v.enabled=!1,this.equations.push(u,d,v)}HingeConstraint.prototype=new n,HingeConstraint.constructor=HingeConstraint,HingeConstraint.prototype.enableMotor=function(){this.motorEquation.enabled=!0},HingeConstraint.prototype.disableMotor=function(){this.motorEquation.enabled=!1},HingeConstraint.prototype.setMotorSpeed=function(t){this.motorEquation.targetVelocity=t},HingeConstraint.prototype.setMotorMaxForce=function(t){this.motorEquation.maxForce=t,this.motorEquation.minForce=-t};var h=new l,c=new l;HingeConstraint.prototype.update=function(){var t=this.bodyA,o=this.bodyB,i=this.motorEquation,r=this.rotationalEquation1,a=this.rotationalEquation2,l=h,p=c,u=this.axisA,d=this.axisB;n.prototype.update.call(this),t.quaternion.vmult(u,l),o.quaternion.vmult(d,p),l.tangents(r.axisA,a.axisA),r.axisB.copy(p),a.axisB.copy(p),this.motorEquation.enabled&&(t.quaternion.vmult(this.axisA,i.axisA),o.quaternion.vmult(this.axisB,i.axisB))}},{"../equations/ContactEquation":19,"../equations/RotationalEquation":22,"../equations/RotationalMotorEquation":23,"../math/Vec3":30,"./Constraint":13,"./PointToPointConstraint":17}],16:[function(t,o,i){o.exports=LockConstraint;t("./Constraint");var n=t("./PointToPointConstraint"),r=t("../equations/RotationalEquation"),a=(t("../equations/RotationalMotorEquation"),t("../equations/ContactEquation"),t("../math/Vec3"));function LockConstraint(t,o,i){var l=void 0!==(i=i||{}).maxForce?i.maxForce:1e6,h=new a,c=new a,p=new a;t.position.vadd(o.position,p),p.scale(.5,p),o.pointToLocalFrame(p,c),t.pointToLocalFrame(p,h),n.call(this,t,h,o,c,l);var u=this.rotationalEquation1=new r(t,o,i),d=this.rotationalEquation2=new r(t,o,i),v=this.rotationalEquation3=new r(t,o,i);this.equations.push(u,d,v)}LockConstraint.prototype=new n,LockConstraint.constructor=LockConstraint;new a,new a;LockConstraint.prototype.update=function(){var t=this.bodyA,o=this.bodyB,i=(this.motorEquation,this.rotationalEquation1),r=this.rotationalEquation2,l=this.rotationalEquation3;n.prototype.update.call(this),t.vectorToWorldFrame(a.UNIT_X,i.axisA),o.vectorToWorldFrame(a.UNIT_Y,i.axisB),t.vectorToWorldFrame(a.UNIT_Y,r.axisA),o.vectorToWorldFrame(a.UNIT_Z,r.axisB),t.vectorToWorldFrame(a.UNIT_Z,l.axisA),o.vectorToWorldFrame(a.UNIT_X,l.axisB)}},{"../equations/ContactEquation":19,"../equations/RotationalEquation":22,"../equations/RotationalMotorEquation":23,"../math/Vec3":30,"./Constraint":13,"./PointToPointConstraint":17}],17:[function(t,o,i){o.exports=PointToPointConstraint;var n=t("./Constraint"),r=t("../equations/ContactEquation"),a=t("../math/Vec3");function PointToPointConstraint(t,o,i,l,h){n.call(this,t,i),h=void 0!==h?h:1e6,this.pivotA=o?o.clone():new a,this.pivotB=l?l.clone():new a;var c=this.equationX=new r(t,i),p=this.equationY=new r(t,i),u=this.equationZ=new r(t,i);this.equations.push(c,p,u),c.minForce=p.minForce=u.minForce=-h,c.maxForce=p.maxForce=u.maxForce=h,c.ni.set(1,0,0),p.ni.set(0,1,0),u.ni.set(0,0,1)}PointToPointConstraint.prototype=new n,PointToPointConstraint.prototype.update=function(){var t=this.bodyA,o=this.bodyB,i=this.equationX,n=this.equationY,r=this.equationZ;t.quaternion.vmult(this.pivotA,i.ri),o.quaternion.vmult(this.pivotB,i.rj),n.ri.copy(i.ri),n.rj.copy(i.rj),r.ri.copy(i.ri),r.rj.copy(i.rj)}},{"../equations/ContactEquation":19,"../math/Vec3":30,"./Constraint":13}],18:[function(t,o,i){o.exports=ConeEquation;var n=t("../math/Vec3"),r=(t("../math/Mat3"),t("./Equation"));function ConeEquation(t,o,i){var a=void 0!==(i=i||{}).maxForce?i.maxForce:1e6;r.call(this,t,o,-a,a),this.axisA=i.axisA?i.axisA.clone():new n(1,0,0),this.axisB=i.axisB?i.axisB.clone():new n(0,1,0),this.angle=void 0!==i.angle?i.angle:0}ConeEquation.prototype=new r,ConeEquation.prototype.constructor=ConeEquation;var a=new n,l=new n;ConeEquation.prototype.computeB=function(t){var o=this.a,i=this.b,n=this.axisA,r=this.axisB,h=a,c=l,p=this.jacobianElementA,u=this.jacobianElementB;return n.cross(r,h),r.cross(n,c),p.rotational.copy(c),u.rotational.copy(h),-(Math.cos(this.angle)-n.dot(r))*o-this.computeGW()*i-t*this.computeGiMf()}},{"../math/Mat3":27,"../math/Vec3":30,"./Equation":20}],19:[function(t,o,i){o.exports=ContactEquation;var n=t("./Equation"),r=t("../math/Vec3");t("../math/Mat3");function ContactEquation(t,o,i){i=void 0!==i?i:1e6,n.call(this,t,o,0,i),this.restitution=0,this.ri=new r,this.rj=new r,this.ni=new r}ContactEquation.prototype=new n,ContactEquation.prototype.constructor=ContactEquation;var a=new r,l=new r,h=new r;ContactEquation.prototype.computeB=function(t){var o=this.a,i=this.b,n=this.bi,r=this.bj,c=this.ri,p=this.rj,u=a,d=l,v=n.velocity,y=n.angularVelocity,f=(n.force,n.torque,r.velocity),m=r.angularVelocity,w=(r.force,r.torque,h),x=this.jacobianElementA,g=this.jacobianElementB,b=this.ni;c.cross(b,u),p.cross(b,d),b.negate(x.spatial),u.negate(x.rotational),g.spatial.copy(b),g.rotational.copy(d),w.copy(r.position),w.vadd(p,w),w.vsub(n.position,w),w.vsub(c,w);var B=b.dot(w),S=this.restitution+1;return-B*o-(S*f.dot(b)-S*v.dot(b)+m.dot(d)-y.dot(u))*i-t*this.computeGiMf()};var c=new r,p=new r,u=new r,d=new r,v=new r;ContactEquation.prototype.getImpactVelocityAlongNormal=function(){var t=c,o=p,i=u,n=d,r=v;return this.bi.position.vadd(this.ri,i),this.bj.position.vadd(this.rj,n),this.bi.getVelocityAtWorldPoint(i,t),this.bj.getVelocityAtWorldPoint(n,o),t.vsub(o,r),this.ni.dot(r)}},{"../math/Mat3":27,"../math/Vec3":30,"./Equation":20}],20:[function(t,o,i){o.exports=Equation;var n=t("../math/JacobianElement"),r=t("../math/Vec3");function Equation(t,o,i,r){this.id=Equation.id++,this.minForce=void 0===i?-1e6:i,this.maxForce=void 0===r?1e6:r,this.bi=t,this.bj=o,this.a=0,this.b=0,this.eps=0,this.jacobianElementA=new n,this.jacobianElementB=new n,this.enabled=!0,this.setSpookParams(1e7,4,1/60)}Equation.prototype.constructor=Equation,Equation.id=0,Equation.prototype.setSpookParams=function(t,o,i){var n=o,r=t,a=i;this.a=4/(a*(1+4*n)),this.b=4*n/(1+4*n),this.eps=4/(a*a*r*(1+4*n))},Equation.prototype.computeB=function(t,o,i){var n=this.computeGW();return-this.computeGq()*t-n*o-this.computeGiMf()*i},Equation.prototype.computeGq=function(){var t=this.jacobianElementA,o=this.jacobianElementB,i=this.bi,n=this.bj,r=i.position,a=n.position;return t.spatial.dot(r)+o.spatial.dot(a)};var a=new r;Equation.prototype.computeGW=function(){var t=this.jacobianElementA,o=this.jacobianElementB,i=this.bi,n=this.bj,r=i.velocity,l=n.velocity,h=i.angularVelocity||a,c=n.angularVelocity||a;return t.multiplyVectors(r,h)+o.multiplyVectors(l,c)},Equation.prototype.computeGWlambda=function(){var t=this.jacobianElementA,o=this.jacobianElementB,i=this.bi,n=this.bj,r=i.vlambda,l=n.vlambda,h=i.wlambda||a,c=n.wlambda||a;return t.multiplyVectors(r,h)+o.multiplyVectors(l,c)};var l=new r,h=new r,c=new r,p=new r;Equation.prototype.computeGiMf=function(){var t=this.jacobianElementA,o=this.jacobianElementB,i=this.bi,n=this.bj,r=i.force,a=i.torque,u=n.force,d=n.torque,v=i.invMassSolve,y=n.invMassSolve;return i.invInertiaWorldSolve?i.invInertiaWorldSolve.vmult(a,c):c.set(0,0,0),n.invInertiaWorldSolve?n.invInertiaWorldSolve.vmult(d,p):p.set(0,0,0),r.mult(v,l),u.mult(y,h),t.multiplyVectors(l,c)+o.multiplyVectors(h,p)};var u=new r;Equation.prototype.computeGiMGt=function(){var t=this.jacobianElementA,o=this.jacobianElementB,i=this.bi,n=this.bj,r=i.invMassSolve,a=n.invMassSolve,l=i.invInertiaWorldSolve,h=n.invInertiaWorldSolve,c=r+a;return l&&(l.vmult(t.rotational,u),c+=u.dot(t.rotational)),h&&(h.vmult(o.rotational,u),c+=u.dot(o.rotational)),c};var d=new r;new r,new r,new r,new r,new r;Equation.prototype.addToWlambda=function(t){var o=this.jacobianElementA,i=this.jacobianElementB,n=this.bi,r=this.bj,a=d;o.spatial.mult(n.invMassSolve*t,a),n.vlambda.vadd(a,n.vlambda),i.spatial.mult(r.invMassSolve*t,a),r.vlambda.vadd(a,r.vlambda),n.invInertiaWorldSolve&&(n.invInertiaWorldSolve.vmult(o.rotational,a),a.mult(t,a),n.wlambda.vadd(a,n.wlambda)),r.invInertiaWorldSolve&&(r.invInertiaWorldSolve.vmult(i.rotational,a),a.mult(t,a),r.wlambda.vadd(a,r.wlambda))},Equation.prototype.computeC=function(){return this.computeGiMGt()+this.eps}},{"../math/JacobianElement":26,"../math/Vec3":30}],21:[function(t,o,i){o.exports=FrictionEquation;var n=t("./Equation"),r=t("../math/Vec3");t("../math/Mat3");function FrictionEquation(t,o,i){n.call(this,t,o,-i,i),this.ri=new r,this.rj=new r,this.t=new r}FrictionEquation.prototype=new n,FrictionEquation.prototype.constructor=FrictionEquation;var a=new r,l=new r;FrictionEquation.prototype.computeB=function(t){this.a;var o=this.b,i=(this.bi,this.bj,this.ri),n=this.rj,r=a,h=l,c=this.t;i.cross(c,r),n.cross(c,h);var p=this.jacobianElementA,u=this.jacobianElementB;return c.negate(p.spatial),r.negate(p.rotational),u.spatial.copy(c),u.rotational.copy(h),-this.computeGW()*o-t*this.computeGiMf()}},{"../math/Mat3":27,"../math/Vec3":30,"./Equation":20}],22:[function(t,o,i){o.exports=RotationalEquation;var n=t("../math/Vec3"),r=(t("../math/Mat3"),t("./Equation"));function RotationalEquation(t,o,i){var a=void 0!==(i=i||{}).maxForce?i.maxForce:1e6;r.call(this,t,o,-a,a),this.axisA=i.axisA?i.axisA.clone():new n(1,0,0),this.axisB=i.axisB?i.axisB.clone():new n(0,1,0),this.maxAngle=Math.PI/2}RotationalEquation.prototype=new r,RotationalEquation.prototype.constructor=RotationalEquation;var a=new n,l=new n;RotationalEquation.prototype.computeB=function(t){var o=this.a,i=this.b,n=this.axisA,r=this.axisB,h=a,c=l,p=this.jacobianElementA,u=this.jacobianElementB;return n.cross(r,h),r.cross(n,c),p.rotational.copy(c),u.rotational.copy(h),-(Math.cos(this.maxAngle)-n.dot(r))*o-this.computeGW()*i-t*this.computeGiMf()}},{"../math/Mat3":27,"../math/Vec3":30,"./Equation":20}],23:[function(t,o,i){o.exports=RotationalMotorEquation;var n=t("../math/Vec3"),r=(t("../math/Mat3"),t("./Equation"));function RotationalMotorEquation(t,o,i){i=void 0!==i?i:1e6,r.call(this,t,o,-i,i),this.axisA=new n,this.axisB=new n,this.targetVelocity=0}RotationalMotorEquation.prototype=new r,RotationalMotorEquation.prototype.constructor=RotationalMotorEquation,RotationalMotorEquation.prototype.computeB=function(t){this.a;var o=this.b,i=(this.bi,this.bj,this.axisA),n=this.axisB,r=this.jacobianElementA,a=this.jacobianElementB;return r.rotational.copy(i),n.negate(a.rotational),-(this.computeGW()-this.targetVelocity)*o-t*this.computeGiMf()}},{"../math/Mat3":27,"../math/Vec3":30,"./Equation":20}],24:[function(t,o,i){var n=t("../utils/Utils");function ContactMaterial(t,o,i){i=n.defaults(i,{friction:.3,restitution:.3,contactEquationStiffness:1e7,contactEquationRelaxation:3,frictionEquationStiffness:1e7,frictionEquationRelaxation:3}),this.id=ContactMaterial.idCounter++,this.materials=[t,o],this.friction=i.friction,this.restitution=i.restitution,this.contactEquationStiffness=i.contactEquationStiffness,this.contactEquationRelaxation=i.contactEquationRelaxation,this.frictionEquationStiffness=i.frictionEquationStiffness,this.frictionEquationRelaxation=i.frictionEquationRelaxation}o.exports=ContactMaterial,ContactMaterial.idCounter=0},{"../utils/Utils":53}],25:[function(t,o,i){function Material(t){var o="";"string"==typeof(t=t||{})?(o=t,t={}):"object"==typeof t&&(o=""),this.name=o,this.id=Material.idCounter++,this.friction=void 0!==t.friction?t.friction:-1,this.restitution=void 0!==t.restitution?t.restitution:-1}o.exports=Material,Material.idCounter=0},{}],26:[function(t,o,i){o.exports=JacobianElement;var n=t("./Vec3");function JacobianElement(){this.spatial=new n,this.rotational=new n}JacobianElement.prototype.multiplyElement=function(t){return t.spatial.dot(this.spatial)+t.rotational.dot(this.rotational)},JacobianElement.prototype.multiplyVectors=function(t,o){return t.dot(this.spatial)+o.dot(this.rotational)}},{"./Vec3":30}],27:[function(t,o,i){o.exports=Mat3;var n=t("./Vec3");function Mat3(t){this.elements=t||[0,0,0,0,0,0,0,0,0]}Mat3.prototype.identity=function(){var t=this.elements;t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=1,t[5]=0,t[6]=0,t[7]=0,t[8]=1},Mat3.prototype.setZero=function(){var t=this.elements;t[0]=0,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=0,t[6]=0,t[7]=0,t[8]=0},Mat3.prototype.setTrace=function(t){var o=this.elements;o[0]=t.x,o[4]=t.y,o[8]=t.z},Mat3.prototype.getTrace=function(t){t=t||new n;var o=this.elements;t.x=o[0],t.y=o[4],t.z=o[8]},Mat3.prototype.vmult=function(t,o){o=o||new n;var i=this.elements,r=t.x,a=t.y,l=t.z;return o.x=i[0]*r+i[1]*a+i[2]*l,o.y=i[3]*r+i[4]*a+i[5]*l,o.z=i[6]*r+i[7]*a+i[8]*l,o},Mat3.prototype.smult=function(t){for(var o=0;o<this.elements.length;o++)this.elements[o]*=t},Mat3.prototype.mmult=function(t,o){for(var i=o||new Mat3,n=0;n<3;n++)for(var r=0;r<3;r++){for(var a=0,l=0;l<3;l++)a+=t.elements[n+3*l]*this.elements[l+3*r];i.elements[n+3*r]=a}return i},Mat3.prototype.scale=function(t,o){o=o||new Mat3;for(var i=this.elements,n=o.elements,r=0;3!==r;r++)n[3*r+0]=t.x*i[3*r+0],n[3*r+1]=t.y*i[3*r+1],n[3*r+2]=t.z*i[3*r+2];return o},Mat3.prototype.solve=function(t,o){o=o||new n;for(var i,r=[],a=0;a<12;a++)r.push(0);for(a=0;a<3;a++)for(i=0;i<3;i++)r[a+4*i]=this.elements[a+3*i];r[3]=t.x,r[7]=t.y,r[11]=t.z;var l,h,c=3,p=c;do{if(0===r[(a=p-c)+4*a])for(i=a+1;i<p;i++)if(0!==r[a+4*i]){l=4;do{r[(h=4-l)+4*a]+=r[h+4*i]}while(--l);break}if(0!==r[a+4*a])for(i=a+1;i<p;i++){var u=r[a+4*i]/r[a+4*a];l=4;do{r[(h=4-l)+4*i]=h<=a?0:r[h+4*i]-r[h+4*a]*u}while(--l)}}while(--c);if(o.z=r[11]/r[10],o.y=(r[7]-r[6]*o.z)/r[5],o.x=(r[3]-r[2]*o.z-r[1]*o.y)/r[0],isNaN(o.x)||isNaN(o.y)||isNaN(o.z)||o.x===1/0||o.y===1/0||o.z===1/0)throw"Could not solve equation! Got x=["+o.toString()+"], b=["+t.toString()+"], A=["+this.toString()+"]";return o},Mat3.prototype.e=function(t,o,i){if(void 0===i)return this.elements[o+3*t];this.elements[o+3*t]=i},Mat3.prototype.copy=function(t){for(var o=0;o<t.elements.length;o++)this.elements[o]=t.elements[o];return this},Mat3.prototype.toString=function(){for(var t="",o=0;o<9;o++)t+=this.elements[o]+",";return t},Mat3.prototype.reverse=function(t){t=t||new Mat3;for(var o,i=[],n=0;n<18;n++)i.push(0);for(n=0;n<3;n++)for(o=0;o<3;o++)i[n+6*o]=this.elements[n+3*o];i[3]=1,i[9]=0,i[15]=0,i[4]=0,i[10]=1,i[16]=0,i[5]=0,i[11]=0,i[17]=1;var r,a,l=3,h=l;do{if(0===i[(n=h-l)+6*n])for(o=n+1;o<h;o++)if(0!==i[n+6*o]){r=6;do{i[(a=6-r)+6*n]+=i[a+6*o]}while(--r);break}if(0!==i[n+6*n])for(o=n+1;o<h;o++){var c=i[n+6*o]/i[n+6*n];r=6;do{i[(a=6-r)+6*o]=a<=n?0:i[a+6*o]-i[a+6*n]*c}while(--r)}}while(--l);n=2;do{o=n-1;do{c=i[n+6*o]/i[n+6*n];r=6;do{i[(a=6-r)+6*o]=i[a+6*o]-i[a+6*n]*c}while(--r)}while(o--)}while(--n);n=2;do{c=1/i[n+6*n];r=6;do{i[(a=6-r)+6*n]=i[a+6*n]*c}while(--r)}while(n--);n=2;do{o=2;do{if(a=i[3+o+6*n],isNaN(a)||a===1/0)throw"Could not reverse! A=["+this.toString()+"]";t.e(n,o,a)}while(o--)}while(n--);return t},Mat3.prototype.setRotationFromQuaternion=function(t){var o=t.x,i=t.y,n=t.z,r=t.w,a=o+o,l=i+i,h=n+n,c=o*a,p=o*l,u=o*h,d=i*l,v=i*h,y=n*h,f=r*a,m=r*l,w=r*h,x=this.elements;return x[0]=1-(d+y),x[1]=p-w,x[2]=u+m,x[3]=p+w,x[4]=1-(c+y),x[5]=v-f,x[6]=u-m,x[7]=v+f,x[8]=1-(c+d),this},Mat3.prototype.transpose=function(t){for(var o=(t=t||new Mat3).elements,i=this.elements,n=0;3!==n;n++)for(var r=0;3!==r;r++)o[3*n+r]=i[3*r+n];return t}},{"./Vec3":30}],28:[function(t,o,i){o.exports=Quaternion;var n=t("./Vec3");function Quaternion(t,o,i,n){this.x=void 0!==t?t:0,this.y=void 0!==o?o:0,this.z=void 0!==i?i:0,this.w=void 0!==n?n:1}Quaternion.prototype.set=function(t,o,i,n){this.x=t,this.y=o,this.z=i,this.w=n},Quaternion.prototype.toString=function(){return this.x+","+this.y+","+this.z+","+this.w},Quaternion.prototype.toArray=function(){return[this.x,this.y,this.z,this.w]},Quaternion.prototype.setFromAxisAngle=function(t,o){var i=Math.sin(.5*o);this.x=t.x*i,this.y=t.y*i,this.z=t.z*i,this.w=Math.cos(.5*o)},Quaternion.prototype.toAxisAngle=function(t){t=t||new n,this.normalize();var o=2*Math.acos(this.w),i=Math.sqrt(1-this.w*this.w);return i<.001?(t.x=this.x,t.y=this.y,t.z=this.z):(t.x=this.x/i,t.y=this.y/i,t.z=this.z/i),[t,o]};var r=new n,a=new n;Quaternion.prototype.setFromVectors=function(t,o){if(t.isAntiparallelTo(o)){var i=r,n=a;t.tangents(i,n),this.setFromAxisAngle(i,Math.PI)}else{var l=t.cross(o);this.x=l.x,this.y=l.y,this.z=l.z,this.w=Math.sqrt(Math.pow(t.norm(),2)*Math.pow(o.norm(),2))+t.dot(o),this.normalize()}};var l=new n,h=new n,c=new n;Quaternion.prototype.mult=function(t,o){o=o||new Quaternion;var i=this.w,n=l,r=h,a=c;return n.set(this.x,this.y,this.z),r.set(t.x,t.y,t.z),o.w=i*t.w-n.dot(r),n.cross(r,a),o.x=i*r.x+t.w*n.x+a.x,o.y=i*r.y+t.w*n.y+a.y,o.z=i*r.z+t.w*n.z+a.z,o},Quaternion.prototype.inverse=function(t){var o=this.x,i=this.y,n=this.z,r=this.w;t=t||new Quaternion,this.conjugate(t);var a=1/(o*o+i*i+n*n+r*r);return t.x*=a,t.y*=a,t.z*=a,t.w*=a,t},Quaternion.prototype.conjugate=function(t){return(t=t||new Quaternion).x=-this.x,t.y=-this.y,t.z=-this.z,t.w=this.w,t},Quaternion.prototype.normalize=function(){var t=Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w);0===t?(this.x=0,this.y=0,this.z=0,this.w=0):(t=1/t,this.x*=t,this.y*=t,this.z*=t,this.w*=t)},Quaternion.prototype.normalizeFast=function(){var t=(3-(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w))/2;0===t?(this.x=0,this.y=0,this.z=0,this.w=0):(this.x*=t,this.y*=t,this.z*=t,this.w*=t)},Quaternion.prototype.vmult=function(t,o){o=o||new n;var i=t.x,r=t.y,a=t.z,l=this.x,h=this.y,c=this.z,p=this.w,u=p*i+h*a-c*r,d=p*r+c*i-l*a,v=p*a+l*r-h*i,y=-l*i-h*r-c*a;return o.x=u*p+y*-l+d*-c-v*-h,o.y=d*p+y*-h+v*-l-u*-c,o.z=v*p+y*-c+u*-h-d*-l,o},Quaternion.prototype.copy=function(t){return this.x=t.x,this.y=t.y,this.z=t.z,this.w=t.w,this},Quaternion.prototype.toEuler=function(t,o){var i,n,r;o=o||"YZX";var a=this.x,l=this.y,h=this.z,c=this.w;switch(o){case"YZX":var p=a*l+h*c;if(p>.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&&i<n?(this.sleepState=Body.SLEEPY,this.timeLastSleepy=t,this.dispatchEvent(Body.sleepyEvent)):o===Body.SLEEPY&&i>n?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;a<i;a++)this.updateWheelTransform(a);this.currentVehicleSpeedKmHour=3.6*r.velocity.norm();var l=new n;this.getVehicleAxisWorld(this.indexForwardAxis,l),l.dot(r.velocity)<0&&(this.currentVehicleSpeedKmHour*=-1);for(a=0;a<i;a++)this.castRay(o[a]);this.updateSuspension(t);var h=new n,c=new n;for(a=0;a<i;a++){var p=(y=o[a]).suspensionForce;p>y.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;a<i;a++){var y=o[a];r.getVelocityAtWorldPoint(y.chassisConnectionPointWorld,v);var f=1;switch(this.indexUpAxis){case 1:f=-1}if(y.isInContact){this.getVehicleAxisWorld(this.indexForwardAxis,d);var m=d.dot(y.raycastResult.hitNormalWorld);y.raycastResult.hitNormalWorld.scale(m,u),d.vsub(u,d);var w=d.dot(v);y.deltaRotation=f*w*t/y.radius}!y.sliding&&y.isInContact||0===y.engineForce||!y.useCustomSlidingRotationalSpeed||(y.deltaRotation=(y.engineForce>0?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;r<n;r++){var a=i[r];if(a.isInContact){var l,h=a.suspensionRestLength-a.suspensionLength;l=a.suspensionStiffness*h*a.clippedInvContactDotSuspension;var c=a.suspensionRelativeVelocity;l-=(c<0?a.dampingCompression:a.dampingRelaxation)*c,a.suspensionForce=l*o,a.suspensionForce<0&&(a.suspensionForce=0)}else a.suspensionForce=0}},RaycastVehicle.prototype.removeFromWorld=function(t){this.constraints;t.remove(this.chassisBody),t.removeEventListener("preStep",this.preStepCallback),this.world=null};var u=new n,d=new n;RaycastVehicle.prototype.castRay=function(t){var o=u,i=d;this.updateWheelTransformWorld(t);var r=this.chassisBody,a=-1,l=t.suspensionRestLength+t.radius;t.directionWorld.scale(l,o);var h=t.chassisConnectionPointWorld;h.vadd(o,i);var c=t.raycastResult;c.reset();var p=r.collisionResponse;r.collisionResponse=!1,this.world.rayTest(h,i,c),r.collisionResponse=p;var v=c.body;if(t.raycastResult.groundObject=0,v){a=c.distance,t.raycastResult.hitNormalWorld=c.hitNormalWorld,t.isInContact=!0;var y=c.distance;t.suspensionLength=y-t.radius;var f=t.suspensionRestLength-t.maxSuspensionTravel,m=t.suspensionRestLength+t.maxSuspensionTravel;t.suspensionLength<f&&(t.suspensionLength=f),t.suspensionLength>m&&(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;c<r;c++){(w=(R=i[c]).raycastResult.body)&&0,R.sideImpulse=0,R.forwardImpulse=0,l[c]||(l[c]=new n),h[c]||(h[c]=new n)}for(c=0;c<r;c++){if(w=(R=i[c]).raycastResult.body){var p=h[c];this.getWheelTransformWorld(c).vectorToWorldFrame(v[this.indexRightAxis],p);var u=R.raycastResult.hitNormalWorld,d=p.dot(u);u.scale(d,o),p.vsub(o,p),p.normalize(),u.cross(p,l[c]),l[c].normalize(),R.sideImpulse=resolveSingleBilateral(a,R.raycastResult.hitPointWorld,w,R.raycastResult.hitPointWorld,p),R.sideImpulse*=1}}this.sliding=!1;for(c=0;c<r;c++){var w=(R=i[c]).raycastResult.body,x=0;if(R.slipInfo=1,w){var g=R.brake?R.brake:0;x=calcRollingFriction(a,w,R.raycastResult.hitPointWorld,l[c],g);var b=g/(x+=R.engineForce*t);R.slipInfo*=b}if(R.forwardImpulse=0,R.skidInfo=1,w){R.skidInfo=1;var B=R.suspensionForce*t*R.frictionSlip,S=B*B;R.forwardImpulse=x;var E=.5*R.forwardImpulse,C=1*R.sideImpulse,A=E*E+C*C;if(R.sliding=!1,A>S){this.sliding=!0,R.sliding=!0;b=B/Math.sqrt(A);R.skidInfo*=b}}}if(this.sliding)for(c=0;c<r;c++){0!==(R=i[c]).sideImpulse&&R.skidInfo<1&&(R.forwardImpulse*=R.skidInfo,R.sideImpulse*=R.skidInfo)}for(c=0;c<r;c++){var R=i[c],P=new n;if(P.copy(R.raycastResult.hitPointWorld),0!==R.forwardImpulse){var M=new n;l[c].scale(R.forwardImpulse,M),a.applyImpulse(M,P)}if(0!==R.sideImpulse){w=R.raycastResult.body;var q=new n;q.copy(R.raycastResult.hitPointWorld);var V=new n;h[c].scale(R.sideImpulse,V),a.pointToLocalFrame(P,P),P["xyz"[this.indexUpAxis]]*=R.rollInfluence,a.pointToWorldFrame(P,P),a.applyImpulse(V,P),V.scale(-1,V),w.applyImpulse(V,q)}}};var w=new n,x=new n,g=new n;function calcRollingFriction(t,o,i,n,r){var a=0,l=i,h=w,c=x,p=g;t.getVelocityAtWorldPoint(l,h),o.getVelocityAtWorldPoint(l,c),h.vsub(c,p);return r<(a=-n.dot(p)*(1/(computeImpulseDenominator(t,i,n)+computeImpulseDenominator(o,i,n))))&&(a=r),a<-r&&(a=-r),a}var b=new n,B=new n,S=new n,E=new n;function computeImpulseDenominator(t,o,i){var n=b,r=B,a=S,l=E;return o.vsub(t.position,n),n.cross(i,r),t.invInertiaWorld.vmult(r,l),l.cross(n,a),t.invMass+i.dot(a)}var C=new n,A=new n,R=new n;function resolveSingleBilateral(t,o,i,n,r,a){if(r.norm2()>1.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;n<i.length;n++)t.add(i[n]);for(n=0;n<o.length;n++)t.addConstraint(o[n]);t.addEventListener("preStep",this._update.bind(this))},RigidVehicle.prototype._update=function(){for(var t=this.wheelForces,o=0;o<t.length;o++)this.applyWheelForce(t[o],o)},RigidVehicle.prototype.removeFromWorld=function(t){for(var o=this.constraints,i=this.wheelBodies.concat([this.chassisBody]),n=0;n<i.length;n++)t.remove(i[n]);for(n=0;n<o.length;n++)t.removeConstraint(o[n])};var p=new l;RigidVehicle.prototype.getWheelSpeed=function(t){var o=this.wheelAxes[t],i=this.wheelBodies[t].angularVelocity;return this.chassisBody.vectorToWorldFrame(o,p),i.dot(p)}},{"../constraints/HingeConstraint":15,"../math/Vec3":30,"../shapes/Box":37,"../shapes/Sphere":44,"./Body":31}],34:[function(t,o,i){o.exports=SPHSystem;t("../shapes/Shape");var n=t("../math/Vec3");t("../math/Quaternion"),t("../shapes/Particle"),t("../objects/Body"),t("../material/Material");function SPHSystem(){this.particles=[],this.density=1,this.smoothingRadius=1,this.speedOfSound=1,this.viscosity=.01,this.eps=1e-6,this.pressures=[],this.densities=[],this.neighbors=[]}SPHSystem.prototype.add=function(t){this.particles.push(t),this.neighbors.length<this.particles.length&&this.neighbors.push([])},SPHSystem.prototype.remove=function(t){var o=this.particles.indexOf(t);-1!==o&&(this.particles.splice(o,1),this.neighbors.length>this.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()<a&&o.push(c)}};var a=new n,l=new n,h=new n,c=new n,p=new n,u=new n;SPHSystem.prototype.update=function(){for(var t=this.particles.length,o=a,i=this.speedOfSound,n=this.eps,r=0;r!==t;r++){var d=this.particles[r];(R=this.neighbors[r]).length=0,this.getNeighbors(d,R),R.push(this.particles[r]);for(var v=R.length,y=0,f=0;f!==v;f++){d.position.vsub(R[f].position,o);var m=o.norm(),w=this.w(m);y+=R[f].mass*w}this.densities[r]=y,this.pressures[r]=i*i*(this.densities[r]-this.density)}var x=l,g=h,b=c,B=p,S=u;for(r=0;r!==t;r++){var E,C,A=this.particles[r];x.set(0,0,0),g.set(0,0,0);var R;for(v=(R=this.neighbors[r]).length,f=0;f!==v;f++){var P=R[f];A.position.vsub(P.position,B);var M=B.norm();E=-P.mass*(this.pressures[r]/(this.densities[r]*this.densities[r]+n)+this.pressures[f]/(this.densities[f]*this.densities[f]+n)),this.gradw(B,b),b.mult(E,b),x.vadd(b,x),P.velocity.vsub(A.velocity,S),S.mult(1/(1e-4+this.densities[r]*this.densities[f])*this.viscosity*P.mass,S),C=this.nablaw(M),S.mult(C,S),g.vadd(S,g)}g.mult(A.mass,g),x.mult(A.mass,x),A.force.vadd(g,A.force),A.force.vadd(x,A.force)}},SPHSystem.prototype.w=function(t){var o=this.smoothingRadius;return 315/(64*Math.PI*Math.pow(o,9))*Math.pow(o*o-t*t,3)},SPHSystem.prototype.gradw=function(t,o){var i=t.norm(),n=this.smoothingRadius;t.mult(945/(32*Math.PI*Math.pow(n,9))*Math.pow(n*n-i*i,2),o)},SPHSystem.prototype.nablaw=function(t){var o=this.smoothingRadius;return 945/(32*Math.PI*Math.pow(o,9))*(o*o-t*t)*(7*t*t-3*o*o)}},{"../material/Material":25,"../math/Quaternion":28,"../math/Vec3":30,"../objects/Body":31,"../shapes/Particle":41,"../shapes/Shape":43}],35:[function(t,o,i){var n=t("../math/Vec3");function Spring(t,o,i){i=i||{},this.restLength="number"==typeof i.restLength?i.restLength:1,this.stiffness=i.stiffness||100,this.damping=i.damping||1,this.bodyA=t,this.bodyB=o,this.localAnchorA=new n,this.localAnchorB=new n,i.localAnchorA&&this.localAnchorA.copy(i.localAnchorA),i.localAnchorB&&this.localAnchorB.copy(i.localAnchorB),i.worldAnchorA&&this.setWorldAnchorA(i.worldAnchorA),i.worldAnchorB&&this.setWorldAnchorB(i.worldAnchorB)}o.exports=Spring,Spring.prototype.setWorldAnchorA=function(t){this.bodyA.pointToLocalFrame(t,this.localAnchorA)},Spring.prototype.setWorldAnchorB=function(t){this.bodyB.pointToLocalFrame(t,this.localAnchorB)},Spring.prototype.getWorldAnchorA=function(t){this.bodyA.pointToWorldFrame(this.localAnchorA,t)},Spring.prototype.getWorldAnchorB=function(t){this.bodyB.pointToWorldFrame(this.localAnchorB,t)};var r=new n,a=new n,l=new n,h=new n,c=new n,p=new n,u=new n,d=new n,v=new n,y=new n,f=new n;Spring.prototype.applyForce=function(){var t=this.stiffness,o=this.damping,i=this.restLength,n=this.bodyA,m=this.bodyB,w=r,x=a,g=l,b=h,B=f,S=c,E=p,C=u,A=d,R=v,P=y;this.getWorldAnchorA(S),this.getWorldAnchorB(E),S.vsub(n.position,C),E.vsub(m.position,A),E.vsub(S,w);var M=w.norm();x.copy(w),x.normalize(),m.velocity.vsub(n.velocity,g),m.angularVelocity.cross(A,B),g.vadd(B,g),n.angularVelocity.cross(C,B),g.vsub(B,g),x.mult(-t*(M-i)-o*g.dot(x),b),n.force.vsub(b,n.force),m.force.vadd(b,m.force),C.cross(b,R),A.cross(b,P),n.torque.vsub(R,n.torque),m.torque.vadd(P,m.torque)}},{"../math/Vec3":30}],36:[function(t,o,i){var n=t("../math/Vec3"),r=t("../math/Transform"),a=t("../collision/RaycastResult"),l=t("../utils/Utils");function WheelInfo(t){t=l.defaults(t,{chassisConnectionPointLocal:new n,chassisConnectionPointWorld:new n,directionLocal:new n,directionWorld:new n,axleLocal:new n,axleWorld:new n,suspensionRestLength:1,suspensionMaxLength:2,radius:1,suspensionStiffness:100,dampingCompression:10,dampingRelaxation:10,frictionSlip:1e4,steering:0,rotation:0,deltaRotation:0,rollInfluence:.01,maxSuspensionForce:Number.MAX_VALUE,isFrontWheel:!0,clippedInvContactDotSuspension:1,suspensionRelativeVelocity:0,suspensionForce:0,skidInfo:0,suspensionLength:0,maxSuspensionTravel:1,useCustomSlidingRotationalSpeed:!1,customSlidingRotationalSpeed:-.1}),this.maxSuspensionTravel=t.maxSuspensionTravel,this.customSlidingRotationalSpeed=t.customSlidingRotationalSpeed,this.useCustomSlidingRotationalSpeed=t.useCustomSlidingRotationalSpeed,this.sliding=!1,this.chassisConnectionPointLocal=t.chassisConnectionPointLocal.clone(),this.chassisConnectionPointWorld=t.chassisConnectionPointWorld.clone(),this.directionLocal=t.directionLocal.clone(),this.directionWorld=t.directionWorld.clone(),this.axleLocal=t.axleLocal.clone(),this.axleWorld=t.axleWorld.clone(),this.suspensionRestLength=t.suspensionRestLength,this.suspensionMaxLength=t.suspensionMaxLength,this.radius=t.radius,this.suspensionStiffness=t.suspensionStiffness,this.dampingCompression=t.dampingCompression,this.dampingRelaxation=t.dampingRelaxation,this.frictionSlip=t.frictionSlip,this.steering=0,this.rotation=0,this.deltaRotation=0,this.rollInfluence=t.rollInfluence,this.maxSuspensionForce=t.maxSuspensionForce,this.engineForce=0,this.brake=0,this.isFrontWheel=t.isFrontWheel,this.clippedInvContactDotSuspension=1,this.suspensionRelativeVelocity=0,this.suspensionForce=0,this.skidInfo=0,this.suspensionLength=0,this.sideImpulse=0,this.forwardImpulse=0,this.raycastResult=new a,this.worldTransform=new r,this.isInContact=!1}o.exports=WheelInfo;var h=new n,c=new n;h=new n;WheelInfo.prototype.updateWheel=function(t){var o=this.raycastResult;if(this.isInContact){var i=o.hitNormalWorld.dot(o.directionWorld);o.hitPointWorld.vsub(t.position,c),t.getVelocityAtWorldPoint(c,h);var n=o.hitNormalWorld.dot(h);if(i>=-.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;a<r.length;a++)l.set(r[a][0],r[a][1],r[a][2]),o.vmult(l,l),t.vadd(l,l),i(l.x,l.y,l.z)};var h=[new r,new r,new r,new r,new r,new r,new r,new r];Box.prototype.calculateWorldAABB=function(t,o,i,n){var r=this.halfExtents;h[0].set(r.x,r.y,r.z),h[1].set(-r.x,r.y,r.z),h[2].set(-r.x,-r.y,r.z),h[3].set(-r.x,-r.y,-r.z),h[4].set(r.x,-r.y,-r.z),h[5].set(r.x,r.y,-r.z),h[6].set(-r.x,r.y,-r.z),h[7].set(r.x,-r.y,r.z);var a=h[0];o.vmult(a,a),t.vadd(a,a),n.copy(a),i.copy(a);for(var l=1;l<8;l++){a=h[l];o.vmult(a,a),t.vadd(a,a);var c=a.x,p=a.y,u=a.z;c>n.x&&(n.x=c),p>n.y&&(n.y=p),u>n.z&&(n.z=u),c<i.x&&(i.x=c),p<i.y&&(i.y=p),u<i.z&&(i.z=u)}}},{"../math/Vec3":30,"./ConvexPolyhedron":38,"./Shape":43}],38:[function(t,o,i){o.exports=ConvexPolyhedron;var n=t("./Shape"),r=t("../math/Vec3"),a=(t("../math/Quaternion"),t("../math/Transform"));function ConvexPolyhedron(t,o,i){n.call(this),this.type=n.types.CONVEXPOLYHEDRON,this.vertices=t||[],this.worldVertices=[],this.worldVerticesNeedsUpdate=!0,this.faces=o||[],this.faceNormals=[],this.computeNormals(),this.worldFaceNormalsNeedsUpdate=!0,this.worldFaceNormals=[],this.uniqueEdges=[],this.uniqueAxes=i?i.slice():null,this.computeEdges(),this.updateBoundingSphereRadius()}ConvexPolyhedron.prototype=new n,ConvexPolyhedron.prototype.constructor=ConvexPolyhedron;var l=new r;ConvexPolyhedron.prototype.computeEdges=function(){var t=this.faces,o=this.vertices,i=(o.length,this.uniqueEdges);i.length=0;for(var n=l,r=0;r!==t.length;r++)for(var a=t[r],h=a.length,c=0;c!==h;c++){var p=(c+1)%h;o[a[c]].vsub(o[a[p]],n),n.normalize();for(var u=!1,d=0;d!==i.length;d++)if(i[d].almostEquals(n)||i[d].almostEquals(n)){u=!0;break}u||i.push(n.clone())}},ConvexPolyhedron.prototype.computeNormals=function(){this.faceNormals.length=this.faces.length;for(var t=0;t<this.faces.length;t++){for(var o=0;o<this.faces[t].length;o++)if(!this.vertices[this.faces[t][o]])throw new Error("Vertex "+this.faces[t][o]+" not found!");var i=this.faceNormals[t]||new r;this.getFaceNormal(t,i),i.negate(i),this.faceNormals[t]=i;var n=this.vertices[this.faces[t][0]];if(i.dot(n)<0){console.error(".faceNormals["+t+"] = Vec3("+i.toString()+") looks like it points into the shape? The vertices follow. Make sure they are ordered CCW around the normal, using the right hand rule.");for(o=0;o<this.faces[t].length;o++)console.warn(".vertices["+this.faces[t][o]+"] = Vec3("+this.vertices[this.faces[t][o]].toString()+")")}}};var h=new r,c=new r;ConvexPolyhedron.computeNormal=function(t,o,i,n){o.vsub(t,c),i.vsub(o,h),h.cross(c,n),n.isZero()||n.normalize()},ConvexPolyhedron.prototype.getFaceNormal=function(t,o){var i=this.faces[t],n=this.vertices[i[0]],r=this.vertices[i[1]],a=this.vertices[i[2]];return ConvexPolyhedron.computeNormal(n,r,a,o)};var p=new r;ConvexPolyhedron.prototype.clipAgainstHull=function(t,o,i,n,a,l,h,c,u){for(var d=p,v=-1,y=-Number.MAX_VALUE,f=0;f<i.faces.length;f++){d.copy(i.faceNormals[f]),a.vmult(d,d);var m=d.dot(l);m>y&&(y=m,v=f)}for(var w=[],x=i.faces[v],g=x.length,b=0;b<g;b++){var B=i.vertices[x[b]],S=new r;S.copy(B),a.vmult(S,S),n.vadd(S,S),w.push(S)}v>=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;R<B&&(B=R,a.copy(c))}else for(var S=l?l.length:this.faces.length,E=0;E<S;E++){var C=l?l[E]:E;if(c.copy(this.faceNormals[C]),i.vmult(c,c),!1===(R=this.testSepAxis(c,t,o,i,n,r)))return!1;R<B&&(B=R,a.copy(c))}if(t.uniqueAxes)for(E=0;E!==t.uniqueAxes.length;E++){if(r.vmult(t.uniqueAxes[E],p),!1===(R=this.testSepAxis(p,t,o,i,n,r)))return!1;R<B&&(B=R,a.copy(p))}else for(var A=h?h.length:t.faces.length,E=0;E<A;E++){var R;C=h?h[E]:E;if(p.copy(t.faceNormals[C]),r.vmult(p,p),!1===(R=this.testSepAxis(p,t,o,i,n,r)))return!1;R<B&&(B=R,a.copy(p))}for(var P=0;P!==this.uniqueEdges.length;P++){i.vmult(this.uniqueEdges[P],x);for(var M=0;M!==t.uniqueEdges.length;M++)if(r.vmult(t.uniqueEdges[M],g),x.cross(g,b),!b.almostZero()){b.normalize();var q=this.testSepAxis(b,t,o,i,n,r);if(!1===q)return!1;q<B&&(B=q,a.copy(b))}}return n.vsub(o,w),w.dot(a)>0&&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(l<p||c<h)return!1;var u=l-p,d=c-h;return u<d?u:d};var g=new r,b=new r;ConvexPolyhedron.prototype.calculateLocalInertia=function(t,o){this.computeLocalAABB(g,b);var i=b.x-g.x,n=b.y-g.y,r=b.z-g.z;o.x=1/12*t*(2*n*2*n+2*r*2*r),o.y=1/12*t*(2*i*2*i+2*r*2*r),o.z=1/12*t*(2*n*2*n+2*i*2*i)},ConvexPolyhedron.prototype.getPlaneConstantOfFace=function(t){var o=this.faces[t],i=this.faceNormals[t],n=this.vertices[o[0]];return-i.dot(n)};var B=new r,S=new r,E=new r,C=new r,A=new r,R=new r,P=new r,M=new r;ConvexPolyhedron.prototype.clipFaceAgainstHull=function(t,o,i,n,r,a,l){for(var h=B,c=S,p=E,u=C,d=A,v=R,y=P,f=M,m=n,w=[],x=-1,g=Number.MAX_VALUE,b=0;b<this.faces.length;b++){h.copy(this.faceNormals[b]),i.vmult(h,h);var q=h.dot(t);q<g&&(g=q,x=b)}if(!(x<0)){var V=this.faces[x];V.connectedFaces=[];for(var z=0;z<this.faces.length;z++)for(var T=0;T<this.faces[z].length;T++)-1!==V.indexOf(this.faces[z][T])&&z!==x&&-1===V.connectedFaces.indexOf(z)&&V.connectedFaces.push(z);m.length;for(var N=V.length,F=0;F<N;F++){var I=this.vertices[V[F]],W=this.vertices[V[(F+1)%N]];I.vsub(W,c),p.copy(c),i.vmult(p,p),o.vadd(p,p),u.copy(this.faceNormals[x]),i.vmult(u,u),o.vadd(u,u),p.cross(u,d),d.negate(d),v.copy(I),i.vmult(v,v),o.vadd(v,v);v.dot(d);var L=V.connectedFaces[F];y.copy(this.faceNormals[L]);var j=this.getPlaneConstantOfFace(L);f.copy(y),i.vmult(f,f);var O=j-f.dot(o);for(this.clipFaceAgainstPlane(m,w,f,O);m.length;)m.shift();for(;w.length;)m.push(w.shift())}y.copy(this.faceNormals[x]);j=this.getPlaneConstantOfFace(x);f.copy(y),i.vmult(f,f);for(O=j-f.dot(o),z=0;z<m.length;z++){var H=f.dot(m[z])+O;if(H<=r&&(console.log("clamped: depth="+H+" to minDist="+r),H=r),H<=a){var k=m[z];if(H<=0){var _={point:k,normal:f,depth:H};l.push(_)}}}}},ConvexPolyhedron.prototype.clipFaceAgainstPlane=function(t,o,i,n){var a,l,h=t.length;if(h<2)return o;var c=t[t.length-1],p=t[0];a=i.dot(c)+n;for(var u=0;u<h;u++){if(p=t[u],l=i.dot(p)+n,a<0)if(l<0){(d=new r).copy(p),o.push(d)}else{var d=new r;c.lerp(p,a/(a-l),d),o.push(d)}else if(l<0){d=new r;c.lerp(p,a/(a-l),d),o.push(d),o.push(p)}c=p,a=l}return o},ConvexPolyhedron.prototype.computeWorldVertices=function(t,o){for(var i=this.vertices.length;this.worldVertices.length<i;)this.worldVertices.push(new r);for(var n=this.vertices,a=this.worldVertices,l=0;l!==i;l++)o.vmult(n[l],a[l]),t.vadd(a[l],a[l]);this.worldVerticesNeedsUpdate=!1};new r;ConvexPolyhedron.prototype.computeLocalAABB=function(t,o){var i=this.vertices.length,n=this.vertices;t.set(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),o.set(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE);for(var r=0;r<i;r++){var a=n[r];a.x<t.x?t.x=a.x:a.x>o.x&&(o.x=a.x),a.y<t.y?t.y=a.y:a.y>o.y&&(o.y=a.y),a.z<t.z?t.z=a.z:a.z>o.z&&(o.z=a.z)}},ConvexPolyhedron.prototype.computeWorldFaceNormals=function(t){for(var o=this.faceNormals.length;this.worldFaceNormals.length<o;)this.worldFaceNormals.push(new r);for(var i=this.faceNormals,n=this.worldFaceNormals,a=0;a!==o;a++)t.vmult(i[a],n[a]);this.worldFaceNormalsNeedsUpdate=!1},ConvexPolyhedron.prototype.updateBoundingSphereRadius=function(){for(var t=0,o=this.vertices,i=0,n=o.length;i!==n;i++){var r=o[i].norm2();r>t&&(t=r)}this.boundingSphereRadius=Math.sqrt(t)};var q=new r;ConvexPolyhedron.prototype.calculateWorldAABB=function(t,o,i,n){for(var r,a,l,h,c,p,u=this.vertices.length,d=this.vertices,v=0;v<u;v++){q.copy(d[v]),o.vmult(q,q),t.vadd(q,q);var y=q;y.x<r||void 0===r?r=y.x:(y.x>h||void 0===h)&&(h=y.x),y.y<a||void 0===a?a=y.y:(y.y>c||void 0===c)&&(c=y.y),y.z<l||void 0===l?l=y.z:(y.z>p||void 0===p)&&(p=y.z)}i.set(r,a,l),n.set(h,c,p)},ConvexPolyhedron.prototype.volume=function(){return 4*Math.PI*this.boundingSphereRadius/3},ConvexPolyhedron.prototype.getAveragePointLocal=function(t){t=t||new r;for(var o=this.vertices.length,i=this.vertices,n=0;n<o;n++)t.vadd(i[n],t);return t.mult(1/o,t),t},ConvexPolyhedron.prototype.transformAllPoints=function(t,o){var i=this.vertices.length,n=this.vertices;if(o){for(var r=0;r<i;r++){var a=n[r];o.vmult(a,a)}for(r=0;r<this.faceNormals.length;r++){a=this.faceNormals[r];o.vmult(a,a)}}if(t)for(r=0;r<i;r++){(a=n[r]).vadd(t,a)}};var V=new r,z=new r,T=new r;ConvexPolyhedron.prototype.pointIsInside=function(t){var o=this.vertices.length,i=this.vertices,n=this.faces,r=this.faceNormals,a=this.faces.length,l=V;this.getAveragePointLocal(l);for(var h=0;h<a;h++){this.faces[h].length,o=r[h];var c=i[n[h][0]],p=z;t.vsub(c,p);var u=o.dot(p),d=T;l.vsub(c,d);var v=o.dot(d);if(u<0&&v>0||u>0&&v<0)return!1}return-1};new r;var N=new r,F=new r;ConvexPolyhedron.project=function(t,o,i,n,r){var l=t.vertices.length,h=N,c=0,p=0,u=F,d=t.vertices;u.setZero(),a.vectorToLocalFrame(i,n,o,h),a.pointToLocalFrame(i,n,u,u);var v=u.dot(h);p=c=d[0].dot(h);for(var y=1;y<l;y++){var f=d[y].dot(h);f>c&&(c=f),f<p&&(p=f)}if((p-=v)>(c-=v)){var m=p;p=c,c=m}r[0]=c,r[1]=p}},{"../math/Quaternion":28,"../math/Transform":29,"../math/Vec3":30,"./Shape":43}],39:[function(t,o,i){o.exports=Cylinder;var n=t("./Shape"),r=t("../math/Vec3"),a=(t("../math/Quaternion"),t("./ConvexPolyhedron"));function Cylinder(t,o,i,l){var h=l,c=[],p=[],u=[],d=[],v=[],y=Math.cos,f=Math.sin;c.push(new r(o*y(0),o*f(0),.5*-i)),d.push(0),c.push(new r(t*y(0),t*f(0),.5*i)),v.push(1);for(var m=0;m<h;m++){var w=2*Math.PI/h*(m+1),x=2*Math.PI/h*(m+.5);m<h-1?(c.push(new r(o*y(w),o*f(w),.5*-i)),d.push(2*m+2),c.push(new r(t*y(w),t*f(w),.5*i)),v.push(2*m+3),u.push([2*m+2,2*m+3,2*m+1,2*m])):u.push([0,1,2*m+1,2*m]),(h%2==1||m<h/2)&&p.push(new r(y(x),f(x),0))}u.push(v),p.push(new r(0,0,1));var g=[];for(m=0;m<d.length;m++)g.push(d[d.length-m-1]);u.push(g),this.type=n.types.CONVEXPOLYHEDRON,a.call(this,c,u,p)}Cylinder.prototype=new a},{"../math/Quaternion":28,"../math/Vec3":30,"./ConvexPolyhedron":38,"./Shape":43}],40:[function(t,o,i){var n=t("./Shape"),r=t("./ConvexPolyhedron"),a=t("../math/Vec3"),l=t("../utils/Utils");function Heightfield(t,o){o=l.defaults(o,{maxValue:null,minValue:null,elementSize:1}),this.data=t,this.maxValue=o.maxValue,this.minValue=o.minValue,this.elementSize=o.elementSize,null===o.minValue&&this.updateMinValue(),null===o.maxValue&&this.updateMaxValue(),this.cacheEnabled=!0,n.call(this),this.pillarConvex=new r,this.pillarOffset=new a,this.type=n.types.HEIGHTFIELD,this.updateBoundingSphereRadius(),this._cachedPillars={}}o.exports=Heightfield,Heightfield.prototype=new n,Heightfield.prototype.update=function(){this._cachedPillars={}},Heightfield.prototype.updateMinValue=function(){for(var t=this.data,o=t[0][0],i=0;i!==t.length;i++)for(var n=0;n!==t[i].length;n++){var r=t[i][n];r<o&&(o=r)}this.minValue=o},Heightfield.prototype.updateMaxValue=function(){for(var t=this.data,o=t[0][0],i=0;i!==t.length;i++)for(var n=0;n!==t[i].length;n++){var r=t[i][n];r>o&&(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;l<a.length;l++){var h=a[l];i[h]=t[h]-r,n[h]=t[h]+r}}},{"../math/Vec3":30,"./Shape":43}],45:[function(t,o,i){o.exports=Trimesh;var n=t("./Shape"),r=t("../math/Vec3"),a=(t("../math/Quaternion"),t("../math/Transform")),l=t("../collision/AABB"),h=t("../utils/Octree");function Trimesh(t,o){n.call(this),this.type=n.types.TRIMESH,this.vertices=new Float32Array(t),this.indices=new Int16Array(o),this.normals=new Float32Array(o.length),this.aabb=new l,this.edges=null,this.scale=new r(1,1,1),this.tree=new h,this.updateEdges(),this.updateNormals(),this.updateAABB(),this.updateBoundingSphereRadius(),this.updateTree()}Trimesh.prototype=new n,Trimesh.prototype.constructor=Trimesh;var c=new r;Trimesh.prototype.updateTree=function(){var t=this.tree;t.reset(),t.aabb.copy(this.aabb);var o=this.scale;t.aabb.lowerBound.x*=1/o.x,t.aabb.lowerBound.y*=1/o.y,t.aabb.lowerBound.z*=1/o.z,t.aabb.upperBound.x*=1/o.x,t.aabb.upperBound.y*=1/o.y,t.aabb.upperBound.z*=1/o.z;for(var i=new l,n=new r,a=new r,h=new r,c=[n,a,h],p=0;p<this.indices.length/3;p++){var u=3*p;this._getUnscaledVertex(this.indices[u],n),this._getUnscaledVertex(this.indices[u+1],a),this._getUnscaledVertex(this.indices[u+2],h),i.setFromPoints(c),t.insert(i,p)}t.removeEmptyNodes()};var p=new l;Trimesh.prototype.getTrianglesInAABB=function(t,o){p.copy(t);var i=this.scale,n=i.x,r=i.y,a=i.z,l=p.lowerBound,h=p.upperBound;return l.x/=n,l.y/=r,l.z/=a,h.x/=n,h.y/=r,h.z/=a,this.tree.aabbQuery(p,o)},Trimesh.prototype.setScale=function(t){var o=this.scale.x===this.scale.y===this.scale.z,i=t.x===t.y===t.z;o&&i||this.updateNormals(),this.scale.copy(t),this.updateAABB(),this.updateBoundingSphereRadius()},Trimesh.prototype.updateNormals=function(){for(var t=c,o=this.normals,i=0;i<this.indices.length/3;i++){var n=3*i,r=this.indices[n],a=this.indices[n+1],l=this.indices[n+2];this.getVertex(r,f),this.getVertex(a,m),this.getVertex(l,w),Trimesh.computeNormal(m,f,w,t),o[n]=t.x,o[n+1]=t.y,o[n+2]=t.z}},Trimesh.prototype.updateEdges=function(){for(var t={},add=function(o,i){t[n<r?n+"_"+r:r+"_"+n]=!0},o=0;o<this.indices.length/3;o++){var i=3*o,n=this.indices[i],r=this.indices[i+1];this.indices[i+2];add(),add(),add()}var a=Object.keys(t);this.edges=new Int16Array(2*a.length);for(o=0;o<a.length;o++){var l=a[o].split("_");this.edges[2*o]=parseInt(l[0],10),this.edges[2*o+1]=parseInt(l[1],10)}},Trimesh.prototype.getEdgeVertex=function(t,o,i){var n=this.edges[2*t+(o?1:0)];this.getVertex(n,i)};var u=new r,d=new r;Trimesh.prototype.getEdgeVector=function(t,o){var i=u,n=d;this.getEdgeVertex(t,0,i),this.getEdgeVertex(t,1,n),n.vsub(i,o)};var v=new r,y=new r;Trimesh.computeNormal=function(t,o,i,n){o.vsub(t,y),i.vsub(o,v),v.cross(y,n),n.isZero()||n.normalize()};var f=new r,m=new r,w=new r;Trimesh.prototype.getVertex=function(t,o){var i=this.scale;return this._getUnscaledVertex(t,o),o.x*=i.x,o.y*=i.y,o.z*=i.z,o},Trimesh.prototype._getUnscaledVertex=function(t,o){var i=3*t,n=this.vertices;return o.set(n[i],n[i+1],n[i+2])},Trimesh.prototype.getWorldVertex=function(t,o,i,n){return this.getVertex(t,n),a.pointToWorldFrame(o,i,n,n),n},Trimesh.prototype.getTriangleVertices=function(t,o,i,n){var r=3*t;this.getVertex(this.indices[r],o),this.getVertex(this.indices[r+1],i),this.getVertex(this.indices[r+2],n)},Trimesh.prototype.getNormal=function(t,o){var i=3*t;return o.set(this.normals[i],this.normals[i+1],this.normals[i+2])};var x=new l;Trimesh.prototype.calculateLocalInertia=function(t,o){this.computeLocalAABB(x);var i=x.upperBound.x-x.lowerBound.x,n=x.upperBound.y-x.lowerBound.y,r=x.upperBound.z-x.lowerBound.z;return o.set(1/12*t*(2*n*2*n+2*r*2*r),1/12*t*(2*i*2*i+2*r*2*r),1/12*t*(2*n*2*n+2*i*2*i))};var g=new r;Trimesh.prototype.computeLocalAABB=function(t){var o=t.lowerBound,i=t.upperBound,n=this.vertices.length,r=(this.vertices,g);this.getVertex(0,r),o.copy(r),i.copy(r);for(var a=0;a!==n;a++)this.getVertex(a,r),r.x<o.x?o.x=r.x:r.x>i.x&&(i.x=r.x),r.y<o.y?o.y=r.y:r.y>i.y&&(i.y=r.y),r.z<o.z?o.z=r.z:r.z>i.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.minForce?h=E.minForce-p:p+h>E.maxForce&&(h=E.maxForce-p),S[R]+=h,c+=h>0?h:-h,E.addToWlambda(h)}if(c*c<v)break}for(g=0;g!==w;g++){var P,M=(P=m[g]).velocity,q=P.angularVelocity;M.vadd(P.vlambda,M),q&&q.vadd(P.wlambda,q)}}return u}},{"../math/Quaternion":28,"../math/Vec3":30,"./Solver":47}],47:[function(t,o,i){function Solver(){this.equations=[]}o.exports=Solver,Solver.prototype.solve=function(t,o){return 0},Solver.prototype.addEquation=function(t){t.enabled&&this.equations.push(t)},Solver.prototype.removeEquation=function(t){var o=this.equations,i=o.indexOf(t);-1!==i&&o.splice(i,1)},Solver.prototype.removeAllEquations=function(){this.equations.length=0}},{}],48:[function(t,o,i){o.exports=SplitSolver;t("../math/Vec3"),t("../math/Quaternion");var n=t("./Solver"),r=t("../objects/Body");function SplitSolver(t){for(n.call(this),this.iterations=10,this.tolerance=1e-7,this.subsolver=t,this.nodes=[],this.nodePool=[];this.nodePool.length<128;)this.nodePool.push(this.createNode())}SplitSolver.prototype=new n;var a=[],l=[],h={bodies:[]},c=r.STATIC;function getUnvisitedNode(t){for(var o=t.length,i=0;i!==o;i++){var n=t[i];if(!(n.visited||n.body.type&c))return n}return!1}var p=[];function bfs(t,o,i,n){for(p.push(t),t.visited=!0,o(t,i,n);p.length;)for(var r,a=p.pop();r=getUnvisitedNode(a.children);)r.visited=!0,o(r,i,n),p.push(r)}function visitFunc(t,o,i){o.push(t.body);for(var n=t.eqs.length,r=0;r!==n;r++){var a=t.eqs[r];-1===i.indexOf(a)&&i.push(a)}}function sortById(t,o){return o.id-t.id}SplitSolver.prototype.createNode=function(){return{body:null,children:[],eqs:[],visited:!1}},SplitSolver.prototype.solve=function(t,o){for(var i=a,n=this.nodePool,r=o.bodies,c=this.equations,p=c.length,u=r.length,d=this.subsolver;n.length<u;)n.push(this.createNode());i.length=u;for(var v=0;v<u;v++)i[v]=n[v];for(v=0;v!==u;v++){var y=i[v];y.body=r[v],y.children.length=0,y.eqs.length=0,y.visited=!1}for(var f=0;f!==p;f++){var m=c[f],w=(v=r.indexOf(m.bi),r.indexOf(m.bj)),x=i[v],g=i[w];x.children.push(g),x.eqs.push(m),g.children.push(x),g.eqs.push(m)}var b,B=0,S=l;d.tolerance=this.tolerance,d.iterations=this.iterations;for(var E=h;b=getUnvisitedNode(i);){S.length=0,E.bodies.length=0,bfs(b,visitFunc,E.bodies,S);var C=S.length;S=S.sort(sortById);for(v=0;v!==C;v++)d.addEquation(S[v]);d.solve(t,E);d.removeAllEquations(),B++}return B}},{"../math/Quaternion":28,"../math/Vec3":30,"../objects/Body":31,"./Solver":47}],49:[function(t,o,i){var EventTarget=function(){};o.exports=EventTarget,EventTarget.prototype={constructor:EventTarget,addEventListener:function(t,o){void 0===this._listeners&&(this._listeners={});var i=this._listeners;return void 0===i[t]&&(i[t]=[]),-1===i[t].indexOf(o)&&i[t].push(o),this},hasEventListener:function(t,o){if(void 0===this._listeners)return!1;var i=this._listeners;return void 0!==i[t]&&-1!==i[t].indexOf(o)},removeEventListener:function(t,o){if(void 0===this._listeners)return this;var i=this._listeners;if(void 0===i[t])return this;var n=i[t].indexOf(o);return-1!==n&&i[t].splice(n,1),this},dispatchEvent:function(t){if(void 0===this._listeners)return this;var o=this._listeners[t.type];if(void 0!==o){t.target=this;for(var i=0,n=o.length;i<n;i++)o[i].call(this,t)}return this}}},{}],50:[function(t,o,i){var n=t("../collision/AABB"),r=t("../math/Vec3");function OctreeNode(t){t=t||{},this.root=t.root||null,this.aabb=t.aabb?t.aabb.clone():new n,this.data=[],this.children=[]}function Octree(t,o){(o=o||{}).root=null,o.aabb=t,OctreeNode.call(this,o),this.maxDepth=void 0!==o.maxDepth?o.maxDepth:8}o.exports=Octree,Octree.prototype=new OctreeNode,OctreeNode.prototype.reset=function(t,o){this.children.length=this.data.length=0},OctreeNode.prototype.insert=function(t,o,i){var n=this.data;if(i=i||0,!this.aabb.contains(t))return!1;var r=this.children;if(i<(this.maxDepth||this.root.maxDepth)){var a=!1;r.length||(this.subdivide(),a=!0);for(var l=0;8!==l;l++)if(r[l].insert(t,o,i+1))return!0;a&&(r.length=0)}return n.push(o),!0};var a=new r;OctreeNode.prototype.subdivide=function(){var t=this.aabb,o=t.lowerBound,i=t.upperBound,l=this.children;l.push(new OctreeNode({aabb:new n({lowerBound:new r(0,0,0)})}),new OctreeNode({aabb:new n({lowerBound:new r(1,0,0)})}),new OctreeNode({aabb:new n({lowerBound:new r(1,1,0)})}),new OctreeNode({aabb:new n({lowerBound:new r(1,1,1)})}),new OctreeNode({aabb:new n({lowerBound:new r(0,1,1)})}),new OctreeNode({aabb:new n({lowerBound:new r(0,0,1)})}),new OctreeNode({aabb:new n({lowerBound:new r(1,0,1)})}),new OctreeNode({aabb:new n({lowerBound:new r(0,1,0)})})),i.vsub(o,a),a.scale(.5,a);for(var h=this.root||this,c=0;8!==c;c++){var p=l[c];p.root=h;var u=p.aabb.lowerBound;u.x*=a.x,u.y*=a.y,u.z*=a.z,u.vadd(o,u),u.vadd(a,p.aabb.upperBound)}},OctreeNode.prototype.aabbQuery=function(t,o){this.data,this.children;for(var i=[this];i.length;){var n=i.pop();n.aabb.overlaps(t)&&Array.prototype.push.apply(o,n.data),Array.prototype.push.apply(i,n.children)}return o};var l=new n;OctreeNode.prototype.rayQuery=function(t,o,i){return t.getAABB(l),l.toLocalFrame(o,l),this.aabbQuery(l,i),i},OctreeNode.prototype.removeEmptyNodes=function(){for(var t=[this];t.length;){for(var o=t.pop(),i=o.children.length-1;i>=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;B<y.shapes.length;B++){y.quaternion.mult(y.shapeOrientations[B],h),y.quaternion.vmult(y.shapeOffsets[B],p),p.vadd(y.position,p);for(var S=y.shapes[B],E=0;E<f.shapes.length;E++){f.quaternion.mult(f.shapeOrientations[E],c),f.quaternion.vmult(f.shapeOffsets[E],u),u.vadd(f.position,u);var C=f.shapes[E];if(!(p.distanceTo(u)>S.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.type<C.type?A.call(this,S,C,p,u,h,c,y,f,S,C):A.call(this,C,S,u,p,c,h,f,y,S,C))}}}}};Narrowphase.prototype[r.types.BOX|r.types.BOX]=Narrowphase.prototype.boxBox=function(t,o,i,n,r,a,l,h){t.convexPolyhedronRepresentation.material=t.material,o.convexPolyhedronRepresentation.material=o.material,t.convexPolyhedronRepresentation.collisionResponse=t.collisionResponse,o.convexPolyhedronRepresentation.collisionResponse=o.collisionResponse,this.convexConvex(t.convexPolyhedronRepresentation,o.convexPolyhedronRepresentation,i,n,r,a,l,h,t,o)},Narrowphase.prototype[r.types.BOX|r.types.CONVEXPOLYHEDRON]=Narrowphase.prototype.boxConvex=function(t,o,i,n,r,a,l,h){t.convexPolyhedronRepresentation.material=t.material,t.convexPolyhedronRepresentation.collisionResponse=t.collisionResponse,this.convexConvex(t.convexPolyhedronRepresentation,o,i,n,r,a,l,h,t,o)},Narrowphase.prototype[r.types.BOX|r.types.PARTICLE]=Narrowphase.prototype.boxParticle=function(t,o,i,n,r,a,l,h){t.convexPolyhedronRepresentation.material=t.material,t.convexPolyhedronRepresentation.collisionResponse=t.collisionResponse,this.convexParticle(t.convexPolyhedronRepresentation,o,i,n,r,a,l,h,t,o)},Narrowphase.prototype[r.types.SPHERE]=Narrowphase.prototype.sphereSphere=function(t,o,i,n,r,a,l,h){var c=this.createContactEquation(l,h,t,o);n.vsub(i,c.ni),c.ni.normalize(),c.ri.copy(c.ni),c.rj.copy(c.ni),c.ri.mult(t.radius,c.ri),c.rj.mult(-o.radius,c.rj),c.ri.vadd(i,c.ri),c.ri.vsub(l.position,c.ri),c.rj.vadd(n,c.rj),c.rj.vsub(h.position,c.rj),this.result.push(c),this.createFrictionEquationsFromContact(c,this.frictionResult)};var b=new l,B=new l,S=new l;Narrowphase.prototype[r.types.PLANE|r.types.TRIMESH]=Narrowphase.prototype.planeTrimesh=function(t,o,i,n,r,a,c,p){var u=new l,d=b;d.set(0,0,1),r.vmult(d,d);for(var v=0;v<o.vertices.length/3;v++){o.getVertex(v,u);var y=new l;y.copy(u),h.pointToWorldFrame(n,a,y,u);var f=B;if(u.vsub(i,f),d.dot(f)<=0){var m=this.createContactEquation(c,p,t,o);m.ni.copy(d);var w=S;d.scale(f.dot(d),w),u.vsub(w,w),m.ri.copy(w),m.ri.vsub(c.position,m.ri),m.rj.copy(u),m.rj.vsub(p.position,m.rj),this.result.push(m),this.createFrictionEquationsFromContact(m,this.frictionResult)}}};var E=new l,C=new l,A=(new l,new l),R=new l,P=new l,M=new l,q=new l,V=new l,z=new l,T=new l,N=new l,F=new l,I=new l,W=new n,L=[];Narrowphase.prototype[r.types.SPHERE|r.types.TRIMESH]=Narrowphase.prototype.sphereTrimesh=function(t,o,i,n,r,l,c,p){var u=P,d=M,v=q,y=V,f=z,m=T,w=W,x=R,g=C,b=L;h.pointToLocalFrame(n,l,i,f);var B=t.radius;w.lowerBound.set(f.x-B,f.y-B,f.z-B),w.upperBound.set(f.x+B,f.y+B,f.z+B),o.getTrianglesInAABB(w,b);for(var S=A,j=t.radius*t.radius,O=0;O<b.length;O++)for(var H=0;H<3;H++){if(o.getVertex(o.indices[3*b[O]+H],S),S.vsub(f,g),g.norm2()<=j)x.copy(S),h.pointToWorldFrame(n,l,x,S),S.vsub(i,g),(U=this.createContactEquation(c,p,t,o)).ni.copy(g),U.ni.normalize(),U.ri.copy(U.ni),U.ri.scale(t.radius,U.ri),U.ri.vadd(i,U.ri),U.ri.vsub(c.position,U.ri),U.rj.copy(S),U.rj.vsub(p.position,U.rj),this.result.push(U),this.createFrictionEquationsFromContact(U,this.frictionResult)}for(O=0;O<b.length;O++)for(H=0;H<3;H++){o.getVertex(o.indices[3*b[O]+H],u),o.getVertex(o.indices[3*b[O]+(H+1)%3],d),d.vsub(u,v),f.vsub(d,m);var k=m.dot(v);f.vsub(u,m);var _=m.dot(v);if(_>0&&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))<t.radius){var U=this.createContactEquation(c,p,t,o);m.vsub(f,U.ni),U.ni.normalize(),U.ni.scale(t.radius,U.ri),h.pointToWorldFrame(n,l,m,m),m.vsub(p.position,U.rj),h.vectorToWorldFrame(l,U.ni,U.ni),h.vectorToWorldFrame(l,U.ri,U.ri),this.result.push(U),this.createFrictionEquationsFromContact(U,this.frictionResult)}}for(var D=N,Q=F,G=I,X=E,Y=(O=0,b.length);O!==Y;O++){o.getTriangleVertices(b[O],D,Q,G),o.getNormal(b[O],X),f.vsub(D,m);var Z=m.dot(X);if(X.scale(Z,m),f.vsub(m,m),Z=m.distanceTo(f),a.pointInTriangle(m,D,Q,G)&&Z<t.radius){U=this.createContactEquation(c,p,t,o);m.vsub(f,U.ni),U.ni.normalize(),U.ni.scale(t.radius,U.ri),h.pointToWorldFrame(n,l,m,m),m.vsub(p.position,U.rj),h.vectorToWorldFrame(l,U.ni,U.ni),h.vectorToWorldFrame(l,U.ri,U.ri),this.result.push(U),this.createFrictionEquationsFromContact(U,this.frictionResult)}}b.length=0};var j=new l,O=new l;Narrowphase.prototype[r.types.SPHERE|r.types.PLANE]=Narrowphase.prototype.spherePlane=function(t,o,i,n,r,a,l,h){var c=this.createContactEquation(l,h,t,o);if(c.ni.set(0,0,1),a.vmult(c.ni,c.ni),c.ni.negate(c.ni),c.ni.normalize(),c.ni.mult(t.radius,c.ri),i.vsub(n,j),c.ni.mult(c.ni.dot(j),O),j.vsub(O,c.rj),-j.dot(c.ni)<=t.radius){var p=c.ri,u=c.rj;p.vadd(i,p),p.vsub(l.position,p),u.vadd(n,u),u.vsub(h.position,u),this.result.push(c),this.createFrictionEquationsFromContact(c,this.frictionResult)}};var H=new l,k=new l,_=new l;function pointInPolygon(t,o,i){for(var n=null,r=t.length,a=0;a!==r;a++){var l=t[a],h=H;t[(a+1)%r].vsub(l,h);var c=k;h.cross(o,c);var p=_;i.vsub(l,p);var u=c.dot(p);if(!(null===n||u>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(A<C+u&&A>0){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&&V>-M&&z<q&&z>-q){var T=Math.abs(A-C-u);(null===b||T<b)&&(b=T,x=V,g=z,m=C,v.copy(E),y.copy(R),f.copy(P),w++)}}}if(w){d=!0;var N=this.createContactEquation(l,h,t,o);v.mult(-u,N.ri),N.ni.copy(v),N.ni.negate(N.ni),v.mult(m,v),y.mult(x,y),v.vadd(y,v),f.mult(g,f),v.vadd(f,N.rj),N.ri.vadd(i,N.ri),N.ri.vsub(l.position,N.ri),N.rj.vadd(n,N.rj),N.rj.vsub(h.position,N.rj),this.result.push(N),this.createFrictionEquationsFromContact(N,this.frictionResult)}for(var F=c.get(),I=Y,W=0;2!==W&&!d;W++)for(var L=0;2!==L&&!d;L++)for(var j=0;2!==j&&!d;j++){if(F.set(0,0,0),W?F.vadd(p[0],F):F.vsub(p[0],F),L?F.vadd(p[1],F):F.vsub(p[1],F),j?F.vadd(p[2],F):F.vsub(p[2],F),n.vadd(F,I),I.vsub(i,I),I.norm2()<u*u)d=!0,(N=this.createContactEquation(l,h,t,o)).ri.copy(I),N.ri.normalize(),N.ni.copy(N.ri),N.ri.mult(u,N.ri),N.rj.copy(F),N.ri.vadd(i,N.ri),N.ri.vsub(l.position,N.ri),N.rj.vadd(n,N.rj),N.rj.vsub(h.position,N.rj),this.result.push(N),this.createFrictionEquationsFromContact(N,this.frictionResult)}c.release(F),F=null;var O=c.get(),H=c.get(),k=(N=c.get(),c.get()),_=(T=c.get(),p.length);for(W=0;W!==_&&!d;W++)for(L=0;L!==_&&!d;L++)if(W%3!=L%3){p[L].cross(p[W],O),O.normalize(),p[W].vadd(p[L],H),N.copy(i),N.vsub(H,N),N.vsub(n,N);var $=N.dot(O);O.mult($,k);for(j=0;j===W%3||j===L%3;)j++;T.copy(i),T.vsub(k,T),T.vsub(H,T),T.vsub(n,T);var tt=Math.abs($),et=T.norm();if(tt<p[j].norm()&&et<u){d=!0;var ot=this.createContactEquation(l,h,t,o);H.vadd(k,ot.rj),ot.rj.copy(ot.rj),T.negate(ot.ni),ot.ni.normalize(),ot.ri.copy(ot.rj),ot.ri.vadd(n,ot.ri),ot.ri.vsub(i,ot.ri),ot.ri.normalize(),ot.ri.mult(u,ot.ri),ot.ri.vadd(i,ot.ri),ot.ri.vsub(l.position,ot.ri),ot.rj.vadd(n,ot.rj),ot.rj.vsub(h.position,ot.rj),this.result.push(ot),this.createFrictionEquationsFromContact(ot,this.frictionResult)}}c.release(O,H,N,k,T)};var $=new l,tt=new l,et=new l,ot=new l,it=new l,nt=new l,rt=new l,st=new l,at=new l,lt=new l;Narrowphase.prototype[r.types.SPHERE|r.types.CONVEXPOLYHEDRON]=Narrowphase.prototype.sphereConvex=function(t,o,i,n,r,a,l,h){var c=this.v3pool;i.vsub(n,$);for(var p=o.faceNormals,u=o.faces,d=o.vertices,v=t.radius,y=0;y!==d.length;y++){var f=d[y],m=it;a.vmult(f,m),n.vadd(m,m);var w=ot;if(m.vsub(i,w),w.norm2()<v*v)return x=!0,(T=this.createContactEquation(l,h,t,o)).ri.copy(w),T.ri.normalize(),T.ni.copy(T.ri),T.ri.mult(v,T.ri),m.vsub(n,T.rj),T.ri.vadd(i,T.ri),T.ri.vsub(l.position,T.ri),T.rj.vadd(n,T.rj),T.rj.vsub(h.position,T.rj),this.result.push(T),void this.createFrictionEquationsFromContact(T,this.frictionResult)}for(var x=!1,g=(y=0,u.length);y!==g&&!1===x;y++){var b=p[y],B=u[y],S=nt;a.vmult(b,S);var E=rt;a.vmult(d[B[0]],E),E.vadd(n,E);var C=st;S.mult(-v,C),i.vadd(C,C);var A=at;C.vsub(E,A);var R=A.dot(S),P=lt;if(i.vsub(E,P),R<0&&P.dot(S)>0){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&&_*_<j.norm2()&&U.norm2()<v*v){T=this.createContactEquation(l,h,t,o);H.vsub(n,T.rj),H.vsub(i,T.ni),T.ni.normalize(),T.ni.mult(v,T.ri),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),this.result.push(T),this.createFrictionEquationsFromContact(T,this.frictionResult);for(q=0,I=M.length;q!==I;q++)c.release(M[q]);return c.release(W),c.release(L),c.release(H),c.release(U),void c.release(k)}c.release(W),c.release(L),c.release(H),c.release(U),c.release(k)}for(q=0,I=M.length;q!==I;q++)c.release(M[q])}}};new l,new l;Narrowphase.prototype[r.types.PLANE|r.types.BOX]=Narrowphase.prototype.planeBox=function(t,o,i,n,r,a,l,h){o.convexPolyhedronRepresentation.material=o.material,o.convexPolyhedronRepresentation.collisionResponse=o.collisionResponse,this.planeConvex(t,o.convexPolyhedronRepresentation,i,n,r,a,l,h)};var ht=new l,ct=new l,pt=new l,ut=new l;Narrowphase.prototype[r.types.PLANE|r.types.CONVEXPOLYHEDRON]=Narrowphase.prototype.planeConvex=function(t,o,i,n,r,a,l,h){var c=ht,p=ct;p.set(0,0,1),r.vmult(p,p);for(var u=0,d=pt,v=0;v!==o.vertices.length;v++){if(c.copy(o.vertices[v]),a.vmult(c,c),n.vadd(c,c),c.vsub(i,d),p.dot(d)<=0){var y=this.createContactEquation(l,h,t,o),f=ut;p.mult(p.dot(d),f),c.vsub(f,f),f.vsub(i,y.ri),y.ni.copy(p),c.vsub(n,y.rj),y.ri.vadd(i,y.ri),y.ri.vsub(l.position,y.ri),y.rj.vadd(n,y.rj),y.rj.vsub(h.position,y.rj),this.result.push(y),u++,this.enableFrictionReduction||this.createFrictionEquationsFromContact(y,this.frictionResult)}}this.enableFrictionReduction&&u&&this.createFrictionFromAverage(u)};var dt=new l,vt=new l;Narrowphase.prototype[r.types.CONVEXPOLYHEDRON]=Narrowphase.prototype.convexConvex=function(t,o,i,n,r,a,l,h,c,p,u,d){var v=dt;if(!(i.distanceTo(n)>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)<Math.abs(d))&&(d=x,c=y,p.copy(w))}if(-1!==c){var g=this.createContactEquation(h,l,o,t);p.mult(d,u),u.vadd(n,u),u.vsub(i,u),g.rj.copy(u),p.negate(g.ni),g.ri.set(0,0,0);var b=g.ri,B=g.rj;b.vadd(n,b),b.vsub(h.position,b),B.vadd(i,B),B.vsub(l.position,B),this.result.push(g),this.createFrictionEquationsFromContact(g,this.frictionResult)}else console.warn("Point found inside convex, but did not find penetrating face!")}},Narrowphase.prototype[r.types.BOX|r.types.HEIGHTFIELD]=Narrowphase.prototype.boxHeightfield=function(t,o,i,n,r,a,l,h){t.convexPolyhedronRepresentation.material=t.material,t.convexPolyhedronRepresentation.collisionResponse=t.collisionResponse,this.convexHeightfield(t.convexPolyhedronRepresentation,o,i,n,r,a,l,h)};var Et=new l,Ct=new l,At=[0];Narrowphase.prototype[r.types.CONVEXPOLYHEDRON|r.types.HEIGHTFIELD]=Narrowphase.prototype.convexHeightfield=function(t,o,i,n,r,a,l,c){var p=o.data,u=o.elementSize,d=t.boundingSphereRadius,v=Ct,y=At,f=Et;h.pointToLocalFrame(n,a,i,f);var m=Math.floor((f.x-d)/u)-1,w=Math.ceil((f.x+d)/u)+1,x=Math.floor((f.y-d)/u)-1,g=Math.ceil((f.y+d)/u)+1;if(!(w<0||g<0||m>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+d<B))for(var E=m;E<w;E++)for(var C=x;C<g;C++)o.getConvexTrianglePillar(E,C,!1),h.pointToWorldFrame(n,a,o.pillarOffset,v),i.distanceTo(v)<o.pillarConvex.boundingSphereRadius+t.boundingSphereRadius&&this.convexConvex(t,o.pillarConvex,i,v,r,a,l,c,null,null,y,null),o.getConvexTrianglePillar(E,C,!0),h.pointToWorldFrame(n,a,o.pillarOffset,v),i.distanceTo(v)<o.pillarConvex.boundingSphereRadius+t.boundingSphereRadius&&this.convexConvex(t,o.pillarConvex,i,v,r,a,l,c,null,null,y,null)}};var Rt=new l,Pt=new l;Narrowphase.prototype[r.types.SPHERE|r.types.HEIGHTFIELD]=Narrowphase.prototype.sphereHeightfield=function(t,o,i,n,r,a,l,c){var p=o.data,u=t.radius,d=o.elementSize,v=Pt,y=Rt;h.pointToLocalFrame(n,a,i,y);var f=Math.floor((y.x-u)/d)-1,m=Math.ceil((y.x+u)/d)+1,w=Math.floor((y.y-u)/d)-1,x=Math.ceil((y.y+u)/d)+1;if(!(m<0||x<0||f>p.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+u<b))for(var S=this.result,E=f;E<m;E++)for(var C=w;C<x;C++){var A=S.length;if(o.getConvexTrianglePillar(E,C,!1),h.pointToWorldFrame(n,a,o.pillarOffset,v),i.distanceTo(v)<o.pillarConvex.boundingSphereRadius+t.boundingSphereRadius&&this.sphereConvex(t,o.pillarConvex,i,v,r,a,l,c),o.getConvexTrianglePillar(E,C,!0),h.pointToWorldFrame(n,a,o.pillarOffset,v),i.distanceTo(v)<o.pillarConvex.boundingSphereRadius+t.boundingSphereRadius&&this.sphereConvex(t,o.pillarConvex,i,v,r,a,l,c),S.length-A>2)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<this.frictionEquations.length;B++)p.addEquation(this.frictionEquations[B]);for(var U=i.length,D=0;D!==U;D++){var Q=(X=i[D]).bi,G=X.bj;X.si,X.sj,(Q.material&&G.material&&this.getContactMaterial(Q.material,G.material)||this.defaultContactMaterial).friction;if(Q.material&&G.material&&(Q.material.friction>=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)}));