text: // Tue, 15 Jan 2019 15:51:47 GMT
  
  /*
   * Copyright (c) 2015 cannon.js Authors
   *
   * Permission is hereby granted, free of charge, to any person
   * obtaining a copy of this software and associated documentation
   * files (the "Software"), to deal in the Software without
   * restriction, including without limitation the rights to use, copy,
   * modify, merge, publish, distribute, sublicense, and/or sell copies
   * of the Software, and to permit persons to whom the Software is
   * furnished to do so, subject to the following conditions:
   *
   * The above copyright notice and this permission notice shall be
   * included in all copies or substantial portions of the Software.
   *
   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
   * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
   * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
   * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
   * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
   * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
   * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
   */
  
  !function(a){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=a();else if("function"==typeof define&&false)define([],a);else{var b;"undefined"!=typeof window?b=window:"undefined"!=typeof global?b=global:"undefined"!=typeof self&&(b=self),b.CANNON=a()}}(function(){return function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);throw new Error("Cannot find module '"+g+"'")}var j=c[g]={exports:{}};b[g][0].call(j.exports,function(a){var c=b[g][1][a];return e(c||a)},j,j.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(a,b,c){b.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:"./src/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(a,b,c){b.exports={version:a("../package.json").version,AABB:a("./collision/AABB"),ArrayCollisionMatrix:a("./collision/ArrayCollisionMatrix"),Body:a("./objects/Body"),Box:a("./shapes/Box"),Broadphase:a("./collision/Broadphase"),Constraint:a("./constraints/Constraint"),ContactEquation:a("./equations/ContactEquation"),Narrowphase:a("./world/Narrowphase"),ConeTwistConstraint:a("./constraints/ConeTwistConstraint"),ContactMaterial:a("./material/ContactMaterial"),ConvexPolyhedron:a("./shapes/ConvexPolyhedron"),Cylinder:a("./shapes/Cylinder"),DistanceConstraint:a("./constraints/DistanceConstraint"),Equation:a("./equations/Equation"),EventTarget:a("./utils/EventTarget"),FrictionEquation:a("./equations/FrictionEquation"),GSSolver:a("./solver/GSSolver"),GridBroadphase:a("./collision/GridBroadphase"),Heightfield:a("./shapes/Heightfield"),HingeConstraint:a("./constraints/HingeConstraint"),LockConstraint:a("./constraints/LockConstraint"),Mat3:a("./math/Mat3"),Material:a("./material/Material"),NaiveBroadphase:a("./collision/NaiveBroadphase"),ObjectCollisionMatrix:a("./collision/ObjectCollisionMatrix"),Pool:a("./utils/Pool"),Particle:a("./shapes/Particle"),Plane:a("./shapes/Plane"),PointToPointConstraint:a("./constraints/PointToPointConstraint"),Quaternion:a("./math/Quaternion"),Ray:a("./collision/Ray"),RaycastVehicle:a("./objects/RaycastVehicle"),RaycastResult:a("./collision/RaycastResult"),RigidVehicle:a("./objects/RigidVehicle"),RotationalEquation:a("./equations/RotationalEquation"),RotationalMotorEquation:a("./equations/RotationalMotorEquation"),SAPBroadphase:a("./collision/SAPBroadphase"),SPHSystem:a("./objects/SPHSystem"),Shape:a("./shapes/Shape"),Solver:a("./solver/Solver"),Sphere:a("./shapes/Sphere"),SplitSolver:a("./solver/SplitSolver"),Spring:a("./objects/Spring"),Transform:a("./math/Transform"),Trimesh:a("./shapes/Trimesh"),Vec3:a("./math/Vec3"),Vec3Pool:a("./utils/Vec3Pool"),World:a("./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":10,"./collision/RaycastResult":11,"./collision/SAPBroadphase":12,"./constraints/ConeTwistConstraint":13,"./constraints/Constraint":14,"./constraints/DistanceConstraint":15,"./constraints/HingeConstraint":16,"./constraints/LockConstraint":17,"./constraints/PointToPointConstraint":18,"./equations/ContactEquation":20,"./equations/Equation":21,"./equations/FrictionEquation":22,"./equations/RotationalEquation":23,"./equations/RotationalMotorEquation":24,"./material/ContactMaterial":25,"./material/Material":26,"./math/Mat3":28,"./math/Quaternion":29,"./math/Transform":30,"./math/Vec3":31,"./objects/Body":32,"./objects/RaycastVehicle":33,"./objects/RigidVehicle":34,"./objects/SPHSystem":35,"./objects/Spring":36,"./shapes/Box":38,"./shapes/ConvexPolyhedron":39,"./shapes/Cylinder":40,"./shapes/Heightfield":41,"./shapes/Particle":42,"./shapes/Plane":43,"./shapes/Shape":44,"./shapes/Sphere":45,"./shapes/Trimesh":46,"./solver/GSSolver":47,"./solver/Solver":48,"./solver/SplitSolver":49,"./utils/EventTarget":50,"./utils/Pool":52,"./utils/Vec3Pool":55,"./world/Narrowphase":56,"./world/World":57}],3:[function(a,b,c){function d(a){a=a||{},this.lowerBound=new e,a.lowerBound&&this.lowerBound.copy(a.lowerBound),this.upperBound=new e,a.upperBound&&this.upperBound.copy(a.upperBound)}var e=a("../math/Vec3");a("../utils/Utils");b.exports=d;var f=new e;d.prototype.setFromPoints=function(a,b,c,d){var e=this.lowerBound,g=this.upperBound,h=c;e.copy(a[0]),h&&h.vmult(e,e),g.copy(e);for(var i=1;i<a.length;i++){var j=a[i];h&&(h.vmult(j,f),j=f),j.x>g.x&&(g.x=j.x),j.x<e.x&&(e.x=j.x),j.y>g.y&&(g.y=j.y),j.y<e.y&&(e.y=j.y),j.z>g.z&&(g.z=j.z),j.z<e.z&&(e.z=j.z)}return b&&(b.vadd(e,e),b.vadd(g,g)),d&&(e.x-=d,e.y-=d,e.z-=d,g.x+=d,g.y+=d,g.z+=d),this},d.prototype.copy=function(a){return this.lowerBound.copy(a.lowerBound),this.upperBound.copy(a.upperBound),this},d.prototype.clone=function(){return(new d).copy(this)},d.prototype.extend=function(a){this.lowerBound.x=Math.min(this.lowerBound.x,a.lowerBound.x),this.upperBound.x=Math.max(this.upperBound.x,a.upperBound.x),this.lowerBound.y=Math.min(this.lowerBound.y,a.lowerBound.y),this.upperBound.y=Math.max(this.upperBound.y,a.upperBound.y),this.lowerBound.z=Math.min(this.lowerBound.z,a.lowerBound.z),this.upperBound.z=Math.max(this.upperBound.z,a.upperBound.z)},d.prototype.overlaps=function(a){var b=this.lowerBound,c=this.upperBound,d=a.lowerBound,e=a.upperBound,f=d.x<=c.x&&c.x<=e.x||b.x<=e.x&&e.x<=c.x,g=d.y<=c.y&&c.y<=e.y||b.y<=e.y&&e.y<=c.y,h=d.z<=c.z&&c.z<=e.z||b.z<=e.z&&e.z<=c.z;return f&&g&&h},d.prototype.volume=function(){var a=this.lowerBound,b=this.upperBound;return(b.x-a.x)*(b.y-a.y)*(b.z-a.z)},d.prototype.contains=function(a){var b=this.lowerBound,c=this.upperBound,d=a.lowerBound,e=a.upperBound;return b.x<=d.x&&c.x>=e.x&&b.y<=d.y&&c.y>=e.y&&b.z<=d.z&&c.z>=e.z},d.prototype.getCorners=function(a,b,c,d,e,f,g,h){var i=this.lowerBound,j=this.upperBound;a.copy(i),b.set(j.x,i.y,i.z),c.set(j.x,j.y,i.z),d.set(i.x,j.y,j.z),e.set(j.x,i.y,i.z),f.set(i.x,j.y,i.z),g.set(i.x,i.y,j.z),h.copy(j)};var g=[new e,new e,new e,new e,new e,new e,new e,new e];d.prototype.toLocalFrame=function(a,b){var c=g,d=c[0],e=c[1],f=c[2],h=c[3],i=c[4],j=c[5],k=c[6],l=c[7];this.getCorners(d,e,f,h,i,j,k,l);for(var m=0;8!==m;m++){var n=c[m];a.pointToLocal(n,n)}return b.setFromPoints(c)},d.prototype.toWorldFrame=function(a,b){var c=g,d=c[0],e=c[1],f=c[2],h=c[3],i=c[4],j=c[5],k=c[6],l=c[7];this.getCorners(d,e,f,h,i,j,k,l);for(var m=0;8!==m;m++){var n=c[m];a.pointToWorld(n,n)}return b.setFromPoints(c)},d.prototype.overlapsRay=function(a){var b=1/a._direction.x,c=1/a._direction.y,d=1/a._direction.z,e=(this.lowerBound.x-a.from.x)*b,f=(this.upperBound.x-a.from.x)*b,g=(this.lowerBound.y-a.from.y)*c,h=(this.upperBound.y-a.from.y)*c,i=(this.lowerBound.z-a.from.z)*d,j=(this.upperBound.z-a.from.z)*d,k=Math.max(Math.max(Math.min(e,f),Math.min(g,h)),Math.min(i,j)),l=Math.min(Math.min(Math.max(e,f),Math.max(g,h)),Math.max(i,j));return!(l<0)&&!(k>l)}},{"../math/Vec3":31,"../utils/Utils":54}],4:[function(a,b,c){function d(){this.matrix=[]}b.exports=d,d.prototype.get=function(a,b){if(a=a.index,(b=b.index)>a){var c=b;b=a,a=c}return this.matrix[(a*(a+1)>>1)+b-1]},d.prototype.set=function(a,b,c){if(a=a.index,(b=b.index)>a){var d=b;b=a,a=d}this.matrix[(a*(a+1)>>1)+b-1]=c?1:0},d.prototype.reset=function(){for(var a=0,b=this.matrix.length;a!==b;a++)this.matrix[a]=0},d.prototype.setNumObjects=function(a){this.matrix.length=a*(a-1)>>1}},{}],5:[function(a,b,c){function d(){this.world=null,this.useBoundingBoxes=!1,this.dirty=!0}var e=a("../objects/Body"),f=a("../math/Vec3"),g=a("../math/Quaternion");a("../shapes/Shape"),a("../shapes/Plane");b.exports=d,d.prototype.collisionPairs=function(a,b,c){throw new Error("collisionPairs not implemented for this BroadPhase class!")},d.prototype.needBroadphaseCollision=function(a,b){return 0!=(a.collisionFilterGroup&b.collisionFilterMask)&&0!=(b.collisionFilterGroup&a.collisionFilterMask)&&(0==(a.type&e.STATIC)&&a.sleepState!==e.SLEEPING||0==(b.type&e.STATIC)&&b.sleepState!==e.SLEEPING)},d.prototype.intersectionTest=function(a,b,c,d){this.useBoundingBoxes?this.doBoundingBoxBroadphase(a,b,c,d):this.doBoundingSphereBroadphase(a,b,c,d)};var h=new f;new f,new g,new f;d.prototype.doBoundingSphereBroadphase=function(a,b,c,d){var e=h;b.position.vsub(a.position,e);var f=Math.pow(a.boundingRadius+b.boundingRadius,2);e.norm2()<f&&(c.push(a),d.push(b))},d.prototype.doBoundingBoxBroadphase=function(a,b,c,d){a.aabbNeedsUpdate&&a.computeAABB(),b.aabbNeedsUpdate&&b.computeAABB(),a.aabb.overlaps(b.aabb)&&(c.push(a),d.push(b))};var i={keys:[]},j=[],k=[];d.prototype.makePairsUnique=function(a,b){for(var c=i,d=j,e=k,f=a.length,g=0;g!==f;g++)d[g]=a[g],e[g]=b[g];a.length=0,b.length=0;for(var g=0;g!==f;g++){var h=d[g].id,l=e[g].id,m=h<l?h+","+l:l+","+h;c[m]=g,c.keys.push(m)}for(var g=0;g!==c.keys.length;g++){var m=c.keys.pop(),n=c[m];a.push(d[n]),b.push(e[n]),delete c[m]}},d.prototype.setWorld=function(a){};var l=new f;d.boundingSphereCheck=function(a,b){var c=l;return a.position.vsub(b.position,c),Math.pow(a.shape.boundingSphereRadius+b.shape.boundingSphereRadius,2)>c.norm2()},d.prototype.aabbQuery=function(a,b,c){return console.warn(".aabbQuery is not implemented in this Broadphase subclass."),[]}},{"../math/Quaternion":29,"../math/Vec3":31,"../objects/Body":32,"../shapes/Plane":43,"../shapes/Shape":44}],6:[function(a,b,c){function d(a,b,c,d,g){e.apply(this),this.nx=c||10,this.ny=d||10,this.nz=g||10,this.aabbMin=a||new f(100,100,100),this.aabbMax=b||new f(-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 i=0;i<h;i++)this.bins[i]=[],this.binLengths[i]=0}b.exports=d;var e=a("./Broadphase"),f=a("../math/Vec3"),g=a("../shapes/Shape");d.prototype=new e,d.prototype.constructor=d;var h=new f;new f;d.prototype.collisionPairs=function(a,b,c){function d(a,b,c,d,e,f,g){var h=(a-t)*w|0,i=(b-u)*x|0,j=(c-v)*y|0,q=K((d-t)*w),r=K((e-u)*x),s=K((f-v)*y);h<0?h=0:h>=k&&(h=k-1),i<0?i=0:i>=l&&(i=l-1),j<0?j=0:j>=m&&(j=m-1),q<0?q=0:q>=k&&(q=k-1),r<0?r=0:r>=l&&(r=l-1),s<0?s=0:s>=m&&(s=m-1),h*=n,i*=o,j*=p,q*=n,r*=o,s*=p;for(var z=h;z<=q;z+=n)for(var A=i;A<=r;A+=o)for(var B=j;B<=s;B+=p){var C=z+A+B;G[C][H[C]++]=g}}for(var e=a.numObjects(),f=a.bodies,i=this.aabbMax,j=this.aabbMin,k=this.nx,l=this.ny,m=this.nz,n=l*m,o=m,p=1,q=i.x,r=i.y,s=i.z,t=j.x,u=j.y,v=j.z,w=k/(q-t),x=l/(r-u),y=m/(s-v),z=(q-t)/k,A=(r-u)/l,B=(s-v)/m,C=.5*Math.sqrt(z*z+A*A+B*B),D=g.types,E=D.SPHERE,F=D.PLANE,G=(D.BOX,D.COMPOUND,D.CONVEXPOLYHEDRON,this.bins),H=this.binLengths,I=this.bins.length,J=0;J!==I;J++)H[J]=0;for(var K=Math.ceil,j=Math.min,i=Math.max,J=0;J!==e;J++){var L=f[J],M=L.shape;switch(M.type){case E:var N=L.position.x,O=L.position.y,P=L.position.z,Q=M.radius;d(N-Q,O-Q,P-Q,N+Q,O+Q,P+Q,L);break;case F:M.worldNormalNeedsUpdate&&M.computeWorldNormal(L.quaternion);var R=M.worldNormal,S=t+.5*z-L.position.x,T=u+.5*A-L.position.y,U=v+.5*B-L.position.z,V=h;V.set(S,T,U);for(var W=0,X=0;W!==k;W++,X+=n,V.y=T,V.x+=z)for(var Y=0,Z=0;Y!==l;Y++,Z+=o,V.z=U,V.y+=A)for(var $=0,_=0;$!==m;$++,_+=p,V.z+=B)if(V.dot(R)<C){var aa=X+Z+_;G[aa][H[aa]++]=L}break;default:L.aabbNeedsUpdate&&L.computeAABB(),d(L.aabb.lowerBound.x,L.aabb.lowerBound.y,L.aabb.lowerBound.z,L.aabb.upperBound.x,L.aabb.upperBound.y,L.aabb.upperBound.z,L)}}for(var J=0;J!==I;J++){var ba=H[J];if(ba>1)for(var ca=G[J],W=0;W!==ba;W++)for(var L=ca[W],Y=0;Y!==W;Y++){var da=ca[Y];this.needBroadphaseCollision(L,da)&&this.intersectionTest(L,da,b,c)}}this.makePairsUnique(b,c)}},{"../math/Vec3":31,"../shapes/Shape":44,"./Broadphase":5}],7:[function(a,b,c){function d(){e.apply(this)}b.exports=d;var e=a("./Broadphase"),f=a("./AABB");d.prototype=new e,d.prototype.constructor=d,d.prototype.collisionPairs=function(a,b,c){var d,e,f,g,h=a.bodies,i=h.length;for(d=0;d!==i;d++)for(e=0;e!==d;e++)f=h[d],g=h[e],this.needBroadphaseCollision(f,g)&&this.intersectionTest(f,g,b,c)};new f;d.prototype.aabbQuery=function(a,b,c){c=c||[];for(var d=0;d<a.bodies.length;d++){var e=a.bodies[d];e.aabbNeedsUpdate&&e.computeAABB(),e.aabb.overlaps(b)&&c.push(e)}return c}},{"./AABB":3,"./Broadphase":5}],8:[function(a,b,c){function d(){this.matrix={}}b.exports=d,d.prototype.get=function(a,b){if(a=a.id,(b=b.id)>a){var c=b;b=a,a=c}return a+"-"+b in this.matrix},d.prototype.set=function(a,b,c){if(a=a.id,(b=b.id)>a){var d=b;b=a,a=d}c?this.matrix[a+"-"+b]=!0:delete this.matrix[a+"-"+b]},d.prototype.reset=function(){this.matrix={}},d.prototype.setNumObjects=function(a){}},{}],9:[function(a,b,c){function d(){this.current=[],this.previous=[]}function e(a,b){a.push((4294901760&b)>>16,65535&b)}b.exports=d,d.prototype.getKey=function(a,b){if(b<a){var c=b;b=a,a=c}return a<<16|b},d.prototype.set=function(a,b){for(var c=this.getKey(a,b),d=this.current,e=0;c>d[e];)e++;if(c!==d[e]){for(var b=d.length-1;b>=e;b--)d[b+1]=d[b];d[e]=c}},d.prototype.tick=function(){var a=this.current;this.current=this.previous,this.previous=a,this.current.length=0},d.prototype.getDiff=function(a,b){for(var c=this.current,d=this.previous,f=c.length,g=d.length,h=0,i=0;i<f;i++){for(var j=!1,k=c[i];k>d[h];)h++;j=k===d[h],j||e(a,k)}h=0;for(var i=0;i<g;i++){for(var j=!1,l=d[i];l>c[h];)h++;j=c[h]===l,j||e(b,l)}}},{}],10:[function(a,b,c){function d(a,b){this.from=a?a.clone():new g,this.to=b?b.clone():new g,this._direction=new g,this.precision=1e-4,this.checkCollisionResponse=!0,this.skipBackfaces=!1,this.collisionFilterMask=-1,this.collisionFilterGroup=-1,this.mode=d.ANY,this.result=new j,this.hasHit=!1,this.callback=function(a){}}function e(a,b,c,d){d.vsub(b,M),c.vsub(b,o),a.vsub(b,p);var e,f,g=M.dot(M),h=M.dot(o),i=M.dot(p),j=o.dot(o),k=o.dot(p);return(e=j*i-h*k)>=0&&(f=g*k-h*i)>=0&&e+f<g*j-h*h}function f(a,b,c){c.vsub(a,M);var d=M.dot(b);return b.mult(d,N),N.vadd(a,N),c.distanceTo(N)}b.exports=d;var g=a("../math/Vec3"),h=a("../math/Quaternion"),i=a("../math/Transform"),j=(a("../shapes/ConvexPolyhedron"),a("../shapes/Box"),a("../collision/RaycastResult")),k=a("../shapes/Shape"),l=a("../collision/AABB");d.prototype.constructor=d,d.CLOSEST=1,d.ANY=2,d.ALL=4;var m=new l,n=[];d.prototype.intersectWorld=function(a,b){this.mode=b.mode||d.ANY,this.result=b.result||new j,this.skipBackfaces=!!b.skipBackfaces,this.collisionFilterMask=void 0!==b.collisionFilterMask?b.collisionFilterMask:-1,this.collisionFilterGroup=void 0!==b.collisionFilterGroup?b.collisionFilterGroup:-1,b.from&&this.from.copy(b.from),b.to&&this.to.copy(b.to),this.callback=b.callback||function(){},this.hasHit=!1,this.result.reset(),this._updateDirection(),this.getAABB(m),n.length=0;var c=a;return b.bodies&&(c={bodies:b.bodies}),a.broadphase.aabbQuery(c,m,n),this.intersectBodies(n),this.hasHit};var o=new g,p=new g;d.pointInTriangle=e;var q=new g,r=new h;d.prototype.intersectBody=function(a,b){b&&(this.result=b,this._updateDirection());var c=this.checkCollisionResponse;if((!c||a.collisionResponse)&&0!=(this.collisionFilterGroup&a.collisionFilterMask)&&0!=(a.collisionFilterGroup&this.collisionFilterMask))for(var d=q,e=r,f=0,g=a.shapes.length;f<g;f++){var h=a.shapes[f];if((!c||h.collisionResponse)&&(a.quaternion.mult(a.shapeOrientations[f],e),a.quaternion.vmult(a.shapeOffsets[f],d),d.vadd(a.position,d),this.intersectShape(h,e,d,a),this.result._shouldStop))break}},d.prototype.intersectBodies=function(a,b){b&&(this.result=b,this._updateDirection());for(var c=0,d=a.length;!this.result._shouldStop&&c<d;c++)this.intersectBody(a[c])},d.prototype._updateDirection=function(){this.to.vsub(this.from,this._direction),this._direction.normalize()},d.prototype.intersectShape=function(a,b,c,d){if(!(f(this.from,this._direction,c)>a.boundingSphereRadius)){var e=this[a.type];e&&e.call(this,a,b,c,d,a)}};var s=(new g,new g,new g),t=new g,u=new g,v=new g;new g,new j;d.prototype.intersectBox=function(a,b,c,d,e){return this.intersectConvex(a.convexPolyhedronRepresentation,b,c,d,e)},d.prototype[k.types.BOX]=d.prototype.intersectBox,d.prototype.intersectPlane=function(a,b,c,d,e){var f=this.from,h=this.to,i=this._direction,j=new g(0,0,1);b.vmult(j,j);var k=new g;f.vsub(c,k);var l=k.dot(j);if(h.vsub(c,k),!(l*k.dot(j)>0||f.distanceTo(h)<l)){var m=j.dot(i);if(!(Math.abs(m)<this.precision)){var n=new g,o=new g,p=new g;f.vsub(c,n);var q=-j.dot(n)/m;i.scale(q,o),f.vadd(o,p),this.reportIntersection(j,p,e,d,-1)}}},d.prototype[k.types.PLANE]=d.prototype.intersectPlane,d.prototype.getAABB=function(a){var b=this.to,c=this.from;a.lowerBound.x=Math.min(b.x,c.x),a.lowerBound.y=Math.min(b.y,c.y),a.lowerBound.z=Math.min(b.z,c.z),a.upperBound.x=Math.max(b.x,c.x),a.upperBound.y=Math.max(b.y,c.y),a.upperBound.z=Math.max(b.z,c.z)};var w={faceList:[0]},x=new g,y=new d,z=[];d.prototype.intersectHeightfield=function(a,b,c,d,e){var f=(a.data,a.elementSize,y);f.from.copy(this.from),f.to.copy(this.to),i.pointToLocalFrame(c,b,f.from,f.from),i.pointToLocalFrame(c,b,f.to,f.to),f._updateDirection();var g,h,j,k,m=z;g=h=0,j=k=a.data.length-1;var n=new l;f.getAABB(n),a.getIndexOfPosition(n.lowerBound.x,n.lowerBound.y,m,!0),g=Math.max(g,m[0]),h=Math.max(h,m[1]),a.getIndexOfPosition(n.upperBound.x,n.upperBound.y,m,!0),j=Math.min(j,m[0]+1),k=Math.min(k,m[1]+1);for(var o=g;o<j;o++)for(var p=h;p<k;p++){if(this.result._shouldStop)return;if(a.getAabbAtIndex(o,p,n),n.overlapsRay(f)){if(a.getConvexTrianglePillar(o,p,!1),i.pointToWorldFrame(c,b,a.pillarOffset,x),this.intersectConvex(a.pillarConvex,b,x,d,e,w),this.result._shouldStop)return;a.getConvexTrianglePillar(o,p,!0),i.pointToWorldFrame(c,b,a.pillarOffset,x),this.intersectConvex(a.pillarConvex,b,x,d,e,w)}}},d.prototype[k.types.HEIGHTFIELD]=d.prototype.intersectHeightfield;var A=new g,B=new g;d.prototype.intersectSphere=function(a,b,c,d,e){var f=this.from,g=this.to,h=a.radius,i=Math.pow(g.x-f.x,2)+Math.pow(g.y-f.y,2)+Math.pow(g.z-f.z,2),j=2*((g.x-f.x)*(f.x-c.x)+(g.y-f.y)*(f.y-c.y)+(g.z-f.z)*(f.z-c.z)),k=Math.pow(f.x-c.x,2)+Math.pow(f.y-c.y,2)+Math.pow(f.z-c.z,2)-Math.pow(h,2),l=Math.pow(j,2)-4*i*k,m=A,n=B;if(!(l<0))if(0===l)f.lerp(g,l,m),m.vsub(c,n),n.normalize(),this.reportIntersection(n,m,e,d,-1);else{var o=(-j-Math.sqrt(l))/(2*i),p=(-j+Math.sqrt(l))/(2*i);if(o>=0&&o<=1&&(f.lerp(g,o,m),m.vsub(c,n),n.normalize(),this.reportIntersection(n,m,e,d,-1)),this.result._shouldStop)return;p>=0&&p<=1&&(f.lerp(g,p,m),m.vsub(c,n),n.normalize(),this.reportIntersection(n,m,e,d,-1))}},d.prototype[k.types.SPHERE]=d.prototype.intersectSphere;var C=new g,D=(new g,new g,new g);d.prototype.intersectConvex=function(a,b,c,d,f,g){for(var h=C,i=D,j=g&&g.faceList||null,k=a.faces,l=a.vertices,m=a.faceNormals,n=this._direction,o=this.from,p=this.to,q=o.distanceTo(p),r=j?j.length:k.length,w=this.result,x=0;!w._shouldStop&&x<r;x++){var y=j?j[x]:x,z=k[y],A=m[y],B=b,E=c;i.copy(l[z[0]]),B.vmult(i,i),i.vadd(E,i),i.vsub(o,i),B.vmult(A,h);var F=n.dot(h);if(!(Math.abs(F)<this.precision)){var G=h.dot(i)/F;if(!(G<0)){n.mult(G,s),s.vadd(o,s),t.copy(l[z[0]]),B.vmult(t,t),E.vadd(t,t);for(var H=1;!w._shouldStop&&H<z.length-1;H++){u.copy(l[z[H]]),v.copy(l[z[H+1]]),B.vmult(u,u),B.vmult(v,v),E.vadd(u,u),E.vadd(v,v);var I=s.distanceTo(o);!e(s,t,u,v)&&!e(s,u,t,v)||I>q||this.reportIntersection(h,s,f,d,y)}}}}},d.prototype[k.types.CONVEXPOLYHEDRON]=d.prototype.intersectConvex;var E=new g,F=new g,G=new g,H=new g,I=new g,J=new g,K=(new l,[]),L=new i;d.prototype.intersectTrimesh=function(a,b,c,d,f,g){var h=E,j=K,k=L,l=D,m=F,n=G,o=H,p=J,q=I,r=(g&&g.faceList,a.indices),w=(a.vertices,a.faceNormals,this.from),x=this.to,y=this._direction;k.position.copy(c),k.quaternion.copy(b),i.vectorToLocalFrame(c,b,y,m),i.pointToLocalFrame(c,b,w,n),i.pointToLocalFrame(c,b,x,o),o.x*=a.scale.x,o.y*=a.scale.y,o.z*=a.scale.z,n.x*=a.scale.x,n.y*=a.scale.y,n.z*=a.scale.z,o.vsub(n,m),m.normalize();var z=n.distanceSquared(o);a.tree.rayQuery(this,k,j);for(var A=0,B=j.length;!this.result._shouldStop&&A!==B;A++){var C=j[A];a.getNormal(C,h),a.getVertex(r[3*C],t),t.vsub(n,l);var M=m.dot(h),N=h.dot(l)/M;if(!(N<0)){m.scale(N,s),s.vadd(n,s),a.getVertex(r[3*C+1],u),a.getVertex(r[3*C+2],v);var O=s.distanceSquared(n);!e(s,u,t,v)&&!e(s,t,u,v)||O>z||(i.vectorToWorldFrame(b,h,q),i.pointToWorldFrame(c,b,s,p),this.reportIntersection(q,p,f,d,C))}}j.length=0},d.prototype[k.types.TRIMESH]=d.prototype.intersectTrimesh,d.prototype.reportIntersection=function(a,b,c,e,f){var g=this.from,h=this.to,i=g.distanceTo(b),j=this.result;if(!(this.skipBackfaces&&a.dot(this._direction)>0))switch(j.hitFaceIndex=void 0!==f?f:-1,this.mode){case d.ALL:this.hasHit=!0,j.set(g,h,a,b,c,e,i),j.hasHit=!0,this.callback(j);break;case d.CLOSEST:(i<j.distance||!j.hasHit)&&(this.hasHit=!0,j.hasHit=!0,j.set(g,h,a,b,c,e,i));break;case d.ANY:this.hasHit=!0,j.hasHit=!0,j.set(g,h,a,b,c,e,i),j._shouldStop=!0}};var M=new g,N=new g},{"../collision/AABB":3,"../collision/RaycastResult":11,"../math/Quaternion":29,"../math/Transform":30,"../math/Vec3":31,"../shapes/Box":38,"../shapes/ConvexPolyhedron":39,"../shapes/Shape":44}],11:[function(a,b,c){function d(){this.rayFromWorld=new e,this.rayToWorld=new e,this.hitNormalWorld=new e,this.hitPointWorld=new e,this.hasHit=!1,this.shape=null,this.body=null,this.hitFaceIndex=-1,this.distance=-1,this._shouldStop=!1}var e=a("../math/Vec3");b.exports=d,d.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},d.prototype.abort=function(){this._shouldStop=!0},d.prototype.set=function(a,b,c,d,e,f,g){this.rayFromWorld.copy(a),this.rayToWorld.copy(b),this.hitNormalWorld.copy(c),this.hitPointWorld.copy(d),this.shape=e,this.body=f,this.distance=g}},{"../math/Vec3":31}],12:[function(a,b,c){function d(a){e.apply(this),this.axisList=[],this.world=null,this.axisIndex=0;var b=this.axisList;this._addBodyHandler=function(a){b.push(a.body)},this._removeBodyHandler=function(a){var c=b.indexOf(a.body);-1!==c&&b.splice(c,1)},a&&this.setWorld(a)}var e=(a("../shapes/Shape"),a("../collision/Broadphase"));b.exports=d,d.prototype=new e,d.prototype.setWorld=function(a){this.axisList.length=0;for(var b=0;b<a.bodies.length;b++)this.axisList.push(a.bodies[b]);a.removeEventListener("addBody",this._addBodyHandler),a.removeEventListener("removeBody",this._removeBodyHandler),a.addEventListener("addBody",this._addBodyHandler),a.addEventListener("removeBody",this._removeBodyHandler),this.world=a,this.dirty=!0},d.insertionSortX=function(a){for(var b=1,c=a.length;b<c;b++){for(var d=a[b],e=b-1;e>=0&&!(a[e].aabb.lowerBound.x<=d.aabb.lowerBound.x);e--)a[e+1]=a[e];a[e+1]=d}return a},d.insertionSortY=function(a){for(var b=1,c=a.length;b<c;b++){for(var d=a[b],e=b-1;e>=0&&!(a[e].aabb.lowerBound.y<=d.aabb.lowerBound.y);e--)a[e+1]=a[e];a[e+1]=d}return a},d.insertionSortZ=function(a){for(var b=1,c=a.length;b<c;b++){for(var d=a[b],e=b-1;e>=0&&!(a[e].aabb.lowerBound.z<=d.aabb.lowerBound.z);e--)a[e+1]=a[e];a[e+1]=d}return a},d.prototype.collisionPairs=function(a,b,c){var e,f,g=this.axisList,h=g.length,i=this.axisIndex;for(this.dirty&&(this.sortList(),this.dirty=!1),e=0;e!==h;e++){var j=g[e];for(f=e+1;f<h;f++){var k=g[f];if(this.needBroadphaseCollision(j,k)){if(!d.checkBounds(j,k,i))break;this.intersectionTest(j,k,b,c)}}}},d.prototype.sortList=function(){for(var a=this.axisList,b=this.axisIndex,c=a.length,e=0;e!==c;e++){var f=a[e];f.aabbNeedsUpdate&&f.computeAABB()}0===b?d.insertionSortX(a):1===b?d.insertionSortY(a):2===b&&d.insertionSortZ(a)},d.checkBounds=function(a,b,c){var d,e;0===c?(d=a.position.x,e=b.position.x):1===c?(d=a.position.y,e=b.position.y):2===c&&(d=a.position.z,e=b.position.z);var f=a.boundingRadius,g=b.boundingRadius,h=d+f,i=e-g;return i<h},d.prototype.autoDetectAxis=function(){for(var a=0,b=0,c=0,d=0,e=0,f=0,g=this.axisList,h=g.length,i=1/h,j=0;j!==h;j++){var k=g[j],l=k.position.x;a+=l,b+=l*l;var m=k.position.y;c+=m,d+=m*m;var n=k.position.z;e+=n,f+=n*n}var o=b-a*a*i,p=d-c*c*i,q=f-e*e*i;this.axisIndex=o>p?o>q?0:2:p>q?1:2},d.prototype.aabbQuery=function(a,b,c){c=c||[],this.dirty&&(this.sortList(),this.dirty=!1);var d=this.axisIndex,e="x";1===d&&(e="y"),2===d&&(e="z");for(var f=this.axisList,g=(b.lowerBound[e],b.upperBound[e],0);g<f.length;g++){var h=f[g];h.aabbNeedsUpdate&&h.computeAABB(),h.aabb.overlaps(b)&&c.push(h)}return c}},{"../collision/Broadphase":5,"../shapes/Shape":44}],13:[function(a,b,c){function d(a,b,c){c=c||{};var d=void 0!==c.maxForce?c.maxForce:1e6,i=c.pivotA?c.pivotA.clone():new h,j=c.pivotB?c.pivotB.clone():new h;this.axisA=c.axisA?c.axisA.clone():new h,this.axisB=c.axisB?c.axisB.clone():new h,e.call(this,a,i,b,j,d),this.collideConnected=!!c.collideConnected,this.angle=void 0!==c.angle?c.angle:0;var k=this.coneEquation=new f(a,b,c),l=this.twistEquation=new g(a,b,c);this.twistAngle=void 0!==c.twistAngle?c.twistAngle:0,k.maxForce=0,k.minForce=-d,l.maxForce=0,l.minForce=-d,this.equations.push(k,l)}b.exports=d;var e=(a("./Constraint"),a("./PointToPointConstraint")),f=a("../equations/ConeEquation"),g=a("../equations/RotationalEquation"),h=(a("../equations/ContactEquation"),a("../math/Vec3"));d.prototype=new e,d.constructor=d;new h,new h;d.prototype.update=function(){var a=this.bodyA,b=this.bodyB,c=this.coneEquation,d=this.twistEquation;e.prototype.update.call(this),a.vectorToWorldFrame(this.axisA,c.axisA),b.vectorToWorldFrame(this.axisB,c.axisB),this.axisA.tangents(d.axisA,d.axisA),a.vectorToWorldFrame(d.axisA,d.axisA),this.axisB.tangents(d.axisB,d.axisB),b.vectorToWorldFrame(d.axisB,d.axisB),c.angle=this.angle,d.maxAngle=this.twistAngle}},{"../equations/ConeEquation":19,"../equations/ContactEquation":20,"../equations/RotationalEquation":23,"../math/Vec3":31,"./Constraint":14,"./PointToPointConstraint":18}],14:[function(a,b,c){function d(a,b,c){c=e.defaults(c,{collideConnected:!0,wakeUpBodies:!0}),this.equations=[],this.bodyA=a,this.bodyB=b,this.id=d.idCounter++,this.collideConnected=c.collideConnected,c.wakeUpBodies&&(a&&a.wakeUp(),b&&b.wakeUp())}b.exports=d;var e=a("../utils/Utils");d.prototype.update=function(){throw new Error("method update() not implmemented in this Constraint subclass!")},d.prototype.enable=function(){for(var a=this.equations,b=0;b<a.length;b++)a[b].enabled=!0},d.prototype.disable=function(){for(var a=this.equations,b=0;b<a.length;b++)a[b].enabled=!1},d.idCounter=0},{"../utils/Utils":54}],15:[function(a,b,c){function d(a,b,c,d){e.call(this,a,b),void 0===c&&(c=a.position.distanceTo(b.position)),void 0===d&&(d=1e6),this.distance=c;var g=this.distanceEquation=new f(a,b);this.equations.push(g),g.minForce=-d,g.maxForce=d}b.exports=d;var e=a("./Constraint"),f=a("../equations/ContactEquation");d.prototype=new e,d.prototype.update=function(){var a=this.bodyA,b=this.bodyB,c=this.distanceEquation,d=.5*this.distance,e=c.ni;b.position.vsub(a.position,e),e.normalize(),e.mult(d,c.ri),e.mult(-d,c.rj)}},{"../equations/ContactEquation":20,"./Constraint":14}],16:[function(a,b,c){function d(a,b,c){c=c||{};var d=void 0!==c.maxForce?c.maxForce:1e6,i=c.pivotA?c.pivotA.clone():new h,j=c.pivotB?c.pivotB.clone():new h;e.call(this,a,i,b,j,d),(this.axisA=c.axisA?c.axisA.clone():new h(1,0,0)).normalize(),(this.axisB=c.axisB?c.axisB.clone():new h(1,0,0)).normalize();var k=this.rotationalEquation1=new f(a,b,c),l=this.rotationalEquation2=new f(a,b,c),m=this.motorEquation=new g(a,b,d);m.enabled=!1,this.equations.push(k,l,m)}b.exports=d;var e=(a("./Constraint"),a("./PointToPointConstraint")),f=a("../equations/RotationalEquation"),g=a("../equations/RotationalMotorEquation"),h=(a("../equations/ContactEquation"),a("../math/Vec3"));d.prototype=new e,d.constructor=d,d.prototype.enableMotor=function(){this.motorEquation.enabled=!0},d.prototype.disableMotor=function(){this.motorEquation.enabled=!1},d.prototype.setMotorSpeed=function(a){this.motorEquation.targetVelocity=a},d.prototype.setMotorMaxForce=function(a){this.motorEquation.maxForce=a,this.motorEquation.minForce=-a};var i=new h,j=new h;d.prototype.update=function(){var a=this.bodyA,b=this.bodyB,c=this.motorEquation,d=this.rotationalEquation1,f=this.rotationalEquation2,g=i,h=j,k=this.axisA,l=this.axisB;e.prototype.update.call(this),a.quaternion.vmult(k,g),b.quaternion.vmult(l,h),g.tangents(d.axisA,f.axisA),d.axisB.copy(h),f.axisB.copy(h),this.motorEquation.enabled&&(a.quaternion.vmult(this.axisA,c.axisA),b.quaternion.vmult(this.axisB,c.axisB))}},{"../equations/ContactEquation":20,"../equations/RotationalEquation":23,"../equations/RotationalMotorEquation":24,"../math/Vec3":31,"./Constraint":14,"./PointToPointConstraint":18}],17:[function(a,b,c){function d(a,b,c){c=c||{};var d=void 0!==c.maxForce?c.maxForce:1e6,h=new g,i=new g,j=new g;a.position.vadd(b.position,j),j.scale(.5,j),b.pointToLocalFrame(j,i),a.pointToLocalFrame(j,h),e.call(this,a,h,b,i,d),this.xA=a.vectorToLocalFrame(g.UNIT_X),this.xB=b.vectorToLocalFrame(g.UNIT_X),this.yA=a.vectorToLocalFrame(g.UNIT_Y),this.yB=b.vectorToLocalFrame(g.UNIT_Y),this.zA=a.vectorToLocalFrame(g.UNIT_Z),this.zB=b.vectorToLocalFrame(g.UNIT_Z);var k=this.rotationalEquation1=new f(a,b,c),l=this.rotationalEquation2=new f(a,b,c),m=this.rotationalEquation3=new f(a,b,c);this.equations.push(k,l,m)}b.exports=d;var e=(a("./Constraint"),a("./PointToPointConstraint")),f=a("../equations/RotationalEquation"),g=(a("../equations/RotationalMotorEquation"),a("../equations/ContactEquation"),a("../math/Vec3"));d.prototype=new e,d.constructor=d;new g,new g;d.prototype.update=function(){var a=this.bodyA,b=this.bodyB,c=(this.motorEquation,this.rotationalEquation1),d=this.rotationalEquation2,f=this.rotationalEquation3;e.prototype.update.call(this),a.vectorToWorldFrame(this.xA,c.axisA),b.vectorToWorldFrame(this.yB,c.axisB),a.vectorToWorldFrame(this.yA,d.axisA),b.vectorToWorldFrame(this.zB,d.axisB),a.vectorToWorldFrame(this.zA,f.axisA),b.vectorToWorldFrame(this.xB,f.axisB)}},{"../equations/ContactEquation":20,"../equations/RotationalEquation":23,"../equations/RotationalMotorEquation":24,"../math/Vec3":31,"./Constraint":14,"./PointToPointConstraint":18}],18:[function(a,b,c){function d(a,b,c,d,h){e.call(this,a,c),h=void 0!==h?h:1e6,this.pivotA=b?b.clone():new g,this.pivotB=d?d.clone():new g;var i=this.equationX=new f(a,c),j=this.equationY=new f(a,c),k=this.equationZ=new f(a,c);this.equations.push(i,j,k),i.minForce=j.minForce=k.minForce=-h,i.maxForce=j.maxForce=k.maxForce=h,i.ni.set(1,0,0),j.ni.set(0,1,0),k.ni.set(0,0,1)}b.exports=d;var e=a("./Constraint"),f=a("../equations/ContactEquation"),g=a("../math/Vec3");d.prototype=new e,d.prototype.update=function(){var a=this.bodyA,b=this.bodyB,c=this.equationX,d=this.equationY,e=this.equationZ;a.quaternion.vmult(this.pivotA,c.ri),b.quaternion.vmult(this.pivotB,c.rj),d.ri.copy(c.ri),d.rj.copy(c.rj),e.ri.copy(c.ri),e.rj.copy(c.rj)}},{"../equations/ContactEquation":20,"../math/Vec3":31,"./Constraint":14}],19:[function(a,b,c){function d(a,b,c){c=c||{};var d=void 0!==c.maxForce?c.maxForce:1e6;f.call(this,a,b,-d,d),this.axisA=c.axisA?c.axisA.clone():new e(1,0,0),this.axisB=c.axisB?c.axisB.clone():new e(0,1,0),this.angle=void 0!==c.angle?c.angle:0}b.exports=d;var e=a("../math/Vec3"),f=(a("../math/Mat3"),a("./Equation"));d.prototype=new f,d.prototype.constructor=d;var g=new e,h=new e;d.prototype.computeB=function(a){var b=this.a,c=this.b,d=this.axisA,e=this.axisB,f=g,i=h,j=this.jacobianElementA,k=this.jacobianElementB;return d.cross(e,f),e.cross(d,i),j.rotational.copy(i),k.rotational.copy(f),-(Math.cos(this.angle)-d.dot(e))*b-this.computeGW()*c-a*this.computeGiMf()}},{"../math/Mat3":28,"../math/Vec3":31,"./Equation":21}],20:[function(a,b,c){function d(a,b,c){c=void 0!==c?c:1e6,e.call(this,a,b,0,c),this.restitution=0,this.ri=new f,this.rj=new f,this.ni=new f}b.exports=d;var e=a("./Equation"),f=a("../math/Vec3");a("../math/Mat3");d.prototype=new e,d.prototype.constructor=d;var g=new f,h=new f,i=new f;d.prototype.computeB=function(a){var b=this.a,c=this.b,d=this.bi,e=this.bj,f=this.ri,j=this.rj,k=g,l=h,m=d.velocity,n=d.angularVelocity,o=(d.force,d.torque,e.velocity),p=e.angularVelocity,q=(e.force,e.torque,i),r=this.jacobianElementA,s=this.jacobianElementB,t=this.ni;f.cross(t,k),j.cross(t,l),t.negate(r.spatial),k.negate(r.rotational),s.spatial.copy(t),s.rotational.copy(l),q.copy(e.position),q.vadd(j,q),q.vsub(d.position,q),q.vsub(f,q);var u=t.dot(q),v=this.restitution+1;return-u*b-(v*o.dot(t)-v*m.dot(t)+p.dot(l)-n.dot(k))*c-a*this.computeGiMf()};var j=new f,k=new f,l=new f,m=new f,n=new f;d.prototype.getImpactVelocityAlongNormal=function(){var a=j,b=k,c=l,d=m,e=n;return this.bi.position.vadd(this.ri,c),this.bj.position.vadd(this.rj,d),this.bi.getVelocityAtWorldPoint(c,a),this.bj.getVelocityAtWorldPoint(d,b),a.vsub(b,e),this.ni.dot(e)}},{"../math/Mat3":28,"../math/Vec3":31,"./Equation":21}],21:[function(a,b,c){function d(a,b,c,f){this.id=d.id++,this.minForce=void 0===c?-1e6:c,this.maxForce=void 0===f?1e6:f,this.bi=a,this.bj=b,this.a=0,this.b=0,this.eps=0,this.jacobianElementA=new e,this.jacobianElementB=new e,this.enabled=!0,this.multiplier=0,this.setSpookParams(1e7,4,1/60)}b.exports=d;var e=a("../math/JacobianElement"),f=a("../math/Vec3");d.prototype.constructor=d,d.id=0,d.prototype.setSpookParams=function(a,b,c){var d=b,e=a,f=c;this.a=4/(f*(1+4*d)),this.b=4*d/(1+4*d),this.eps=4/(f*f*e*(1+4*d))},d.prototype.computeB=function(a,b,c){var d=this.computeGW();return-this.computeGq()*a-d*b-this.computeGiMf()*c},d.prototype.computeGq=function(){var a=this.jacobianElementA,b=this.jacobianElementB,c=this.bi,d=this.bj,e=c.position,f=d.position;return a.spatial.dot(e)+b.spatial.dot(f)};new f;d.prototype.computeGW=function(){var a=this.jacobianElementA,b=this.jacobianElementB,c=this.bi,d=this.bj,e=c.velocity,f=d.velocity,g=c.angularVelocity,h=d.angularVelocity;return a.multiplyVectors(e,g)+b.multiplyVectors(f,h)},d.prototype.computeGWlambda=function(){var a=this.jacobianElementA,b=this.jacobianElementB,c=this.bi,d=this.bj,e=c.vlambda,f=d.vlambda,g=c.wlambda,h=d.wlambda;return a.multiplyVectors(e,g)+b.multiplyVectors(f,h)};var g=new f,h=new f,i=new f,j=new f;d.prototype.computeGiMf=function(){var a=this.jacobianElementA,b=this.jacobianElementB,c=this.bi,d=this.bj,e=c.force,f=c.torque,k=d.force,l=d.torque,m=c.invMassSolve,n=d.invMassSolve;return e.scale(m,g),k.scale(n,h),c.invInertiaWorldSolve.vmult(f,i),d.invInertiaWorldSolve.vmult(l,j),a.multiplyVectors(g,i)+b.multiplyVectors(h,j)};var k=new f;d.prototype.computeGiMGt=function(){var a=this.jacobianElementA,b=this.jacobianElementB,c=this.bi,d=this.bj,e=c.invMassSolve,f=d.invMassSolve,g=c.invInertiaWorldSolve,h=d.invInertiaWorldSolve,i=e+f;return g.vmult(a.rotational,k),i+=k.dot(a.rotational),h.vmult(b.rotational,k),i+=k.dot(b.rotational)};var l=new f;new f,new f,new f,new f,new f;d.prototype.addToWlambda=function(a){var b=this.jacobianElementA,c=this.jacobianElementB,d=this.bi,e=this.bj,f=l;d.vlambda.addScaledVector(d.invMassSolve*a,b.spatial,d.vlambda),e.vlambda.addScaledVector(e.invMassSolve*a,c.spatial,e.vlambda),d.invInertiaWorldSolve.vmult(b.rotational,f),d.wlambda.addScaledVector(a,f,d.wlambda),e.invInertiaWorldSolve.vmult(c.rotational,f),e.wlambda.addScaledVector(a,f,e.wlambda)},d.prototype.computeC=function(){return this.computeGiMGt()+this.eps}},{"../math/JacobianElement":27,"../math/Vec3":31}],22:[function(a,b,c){function d(a,b,c){e.call(this,a,b,-c,c),this.ri=new f,this.rj=new f,this.t=new f}b.exports=d;var e=a("./Equation"),f=a("../math/Vec3");a("../math/Mat3");d.prototype=new e,d.prototype.constructor=d;var g=new f,h=new f;d.prototype.computeB=function(a){var b=(this.a,this.b),c=(this.bi,this.bj,this.ri),d=this.rj,e=g,f=h,i=this.t;c.cross(i,e),d.cross(i,f);var j=this.jacobianElementA,k=this.jacobianElementB;return i.negate(j.spatial),e.negate(j.rotational),k.spatial.copy(i),k.rotational.copy(f),-this.computeGW()*b-a*this.computeGiMf()}},{"../math/Mat3":28,"../math/Vec3":31,"./Equation":21}],23:[function(a,b,c){function d(a,b,c){c=c||{};var d=void 0!==c.maxForce?c.maxForce:1e6;f.call(this,a,b,-d,d),this.axisA=c.axisA?c.axisA.clone():new e(1,0,0),this.axisB=c.axisB?c.axisB.clone():new e(0,1,0),this.maxAngle=Math.PI/2}b.exports=d;var e=a("../math/Vec3"),f=(a("../math/Mat3"),a("./Equation"));d.prototype=new f,d.prototype.constructor=d;var g=new e,h=new e;d.prototype.computeB=function(a){var b=this.a,c=this.b,d=this.axisA,e=this.axisB,f=g,i=h,j=this.jacobianElementA,k=this.jacobianElementB;return d.cross(e,f),e.cross(d,i),j.rotational.copy(i),k.rotational.copy(f),-(Math.cos(this.maxAngle)-d.dot(e))*b-this.computeGW()*c-a*this.computeGiMf()}},{"../math/Mat3":28,"../math/Vec3":31,"./Equation":21}],24:[function(a,b,c){function d(a,b,c){c=void 0!==c?c:1e6,f.call(this,a,b,-c,c),this.axisA=new e,this.axisB=new e,this.targetVelocity=0}b.exports=d;var e=a("../math/Vec3"),f=(a("../math/Mat3"),a("./Equation"));d.prototype=new f,d.prototype.constructor=d,d.prototype.computeB=function(a){var b=(this.a,this.b),c=(this.bi,this.bj,this.axisA),d=this.axisB,e=this.jacobianElementA,f=this.jacobianElementB;return e.rotational.copy(c),d.negate(f.rotational),-(this.computeGW()-this.targetVelocity)*b-a*this.computeGiMf()}},{"../math/Mat3":28,"../math/Vec3":31,"./Equation":21}],25:[function(a,b,c){function d(a,b,c){c=e.defaults(c,{friction:.3,restitution:.3,contactEquationStiffness:1e7,contactEquationRelaxation:3,frictionEquationStiffness:1e7,frictionEquationRelaxation:3}),this.id=d.idCounter++,this.materials=[a,b],this.friction=c.friction,this.restitution=c.restitution,this.contactEquationStiffness=c.contactEquationStiffness,this.contactEquationRelaxation=c.contactEquationRelaxation,this.frictionEquationStiffness=c.frictionEquationStiffness,this.frictionEquationRelaxation=c.frictionEquationRelaxation}var e=a("../utils/Utils");b.exports=d,d.idCounter=0},{"../utils/Utils":54}],26:[function(a,b,c){function d(a){var b="";a=a||{},"string"==typeof a?(b=a,a={}):"object"==typeof a&&(b=""),this.name=b,this.id=d.idCounter++,this.friction=void 0!==a.friction?a.friction:-1,this.restitution=void 0!==a.restitution?a.restitution:-1}b.exports=d,d.idCounter=0},{}],27:[function(a,b,c){function d(){this.spatial=new e,this.rotational=new e}b.exports=d;var e=a("./Vec3");d.prototype.multiplyElement=function(a){return a.spatial.dot(this.spatial)+a.rotational.dot(this.rotational)},d.prototype.multiplyVectors=function(a,b){return a.dot(this.spatial)+b.dot(this.rotational)}},{"./Vec3":31}],28:[function(a,b,c){function d(a){this.elements=a||[0,0,0,0,0,0,0,0,0]}b.exports=d;var e=a("./Vec3");d.prototype.identity=function(){var a=this.elements;a[0]=1,a[1]=0,a[2]=0,a[3]=0,a[4]=1,a[5]=0,a[6]=0,a[7]=0,a[8]=1},d.prototype.setZero=function(){var a=this.elements;a[0]=0,a[1]=0,a[2]=0,a[3]=0,a[4]=0,a[5]=0,a[6]=0,a[7]=0,a[8]=0},d.prototype.setTrace=function(a){var b=this.elements;b[0]=a.x,b[4]=a.y,b[8]=a.z},d.prototype.getTrace=function(a){var a=a||new e,b=this.elements;a.x=b[0],a.y=b[4],a.z=b[8]},d.prototype.vmult=function(a,b){b=b||new e;var c=this.elements,d=a.x,f=a.y,g=a.z;return b.x=c[0]*d+c[1]*f+c[2]*g,b.y=c[3]*d+c[4]*f+c[5]*g,b.z=c[6]*d+c[7]*f+c[8]*g,b},d.prototype.smult=function(a){for(var b=0;b<this.elements.length;b++)this.elements[b]*=a},d.prototype.mmult=function(a,b){for(var c=b||new d,e=0;e<3;e++)for(var f=0;f<3;f++){for(var g=0,h=0;h<3;h++)g+=a.elements[e+3*h]*this.elements[h+3*f];c.elements[e+3*f]=g}return c},d.prototype.scale=function(a,b){b=b||new d;for(var c=this.elements,e=b.elements,f=0;3!==f;f++)e[3*f+0]=a.x*c[3*f+0],e[3*f+1]=a.y*c[3*f+1],e[3*f+2]=a.z*c[3*f+2];return b},d.prototype.solve=function(a,b){b=b||new e;for(var c=3,d=4,f=[],g=0;g<c*d;g++)f.push(0);var g,h;for(g=0;g<3;g++)for(h=0;h<3;h++)f[g+d*h]=this.elements[g+3*h];f[3]=a.x,f[7]=a.y,f[11]=a.z;var i,j,k=3,l=k,m=4;do{if(g=l-k,0===f[g+d*g])for(h=g+1;h<l;h++)if(0!==f[g+d*h]){i=m;do{j=m-i,f[j+d*g]+=f[j+d*h]}while(--i);break}if(0!==f[g+d*g])for(h=g+1;h<l;h++){var n=f[g+d*h]/f[g+d*g];i=m;do{j=m-i,f[j+d*h]=j<=g?0:f[j+d*h]-f[j+d*g]*n}while(--i)}}while(--k);if(b.z=f[2*d+3]/f[2*d+2],b.y=(f[1*d+3]-f[1*d+2]*b.z)/f[1*d+1],b.x=(f[0*d+3]-f[0*d+2]*b.z-f[0*d+1]*b.y)/f[0*d+0],isNaN(b.x)||isNaN(b.y)||isNaN(b.z)||b.x===1/0||b.y===1/0||b.z===1/0)throw"Could not solve equation! Got x=["+b.toString()+"], b=["+a.toString()+"], A=["+this.toString()+"]";return b},d.prototype.e=function(a,b,c){if(void 0===c)return this.elements[b+3*a];this.elements[b+3*a]=c},d.prototype.copy=function(a){for(var b=0;b<a.elements.length;b++)this.elements[b]=a.elements[b];return this},d.prototype.toString=function(){for(var a="",b=",",c=0;c<9;c++)a+=this.elements[c]+b;return a},d.prototype.reverse=function(a){a=a||new d;for(var b=3,c=6,e=[],f=0;f<b*c;f++)e.push(0);var f,g;for(f=0;f<3;f++)for(g=0;g<3;g++)e[f+c*g]=this.elements[f+3*g];e[3]=1,e[9]=0,e[15]=0,e[4]=0,e[10]=1,e[16]=0,e[5]=0,e[11]=0,e[17]=1;var h,i,j=3,k=j,l=c;do{if(f=k-j,0===e[f+c*f])for(g=f+1;g<k;g++)if(0!==e[f+c*g]){h=l;do{i=l-h,e[i+c*f]+=e[i+c*g]}while(--h);break}if(0!==e[f+c*f])for(g=f+1;g<k;g++){var m=e[f+c*g]/e[f+c*f];h=l;do{i=l-h,e[i+c*g]=i<=f?0:e[i+c*g]-e[i+c*f]*m}while(--h)}}while(--j);f=2;do{g=f-1;do{var m=e[f+c*g]/e[f+c*f];h=c;do{i=c-h,e[i+c*g]=e[i+c*g]-e[i+c*f]*m}while(--h)}while(g--)}while(--f);f=2;do{var m=1/e[f+c*f];h=c;do{i=c-h,e[i+c*f]=e[i+c*f]*m}while(--h)}while(f--);f=2;do{g=2;do{if(i=e[b+g+c*f],isNaN(i)||i===1/0)throw"Could not reverse! A=["+this.toString()+"]";a.e(f,g,i)}while(g--)}while(f--);return a},d.prototype.setRotationFromQuaternion=function(a){var b=a.x,c=a.y,d=a.z,e=a.w,f=b+b,g=c+c,h=d+d,i=b*f,j=b*g,k=b*h,l=c*g,m=c*h,n=d*h,o=e*f,p=e*g,q=e*h,r=this.elements;return r[0]=1-(l+n),r[1]=j-q,r[2]=k+p,r[3]=j+q,r[4]=1-(i+n),r[5]=m-o,r[6]=k-p,r[7]=m+o,r[8]=1-(i+l),this},d.prototype.transpose=function(a){a=a||new d;for(var b=a.elements,c=this.elements,e=0;3!==e;e++)for(var f=0;3!==f;f++)b[3*e+f]=c[3*f+e];return a}},{"./Vec3":31}],29:[function(a,b,c){function d(a,b,c,d){this.x=void 0!==a?a:0,this.y=void 0!==b?b:0,this.z=void 0!==c?c:0,this.w=void 0!==d?d:1}b.exports=d;var e=a("./Vec3");d.prototype.set=function(a,b,c,d){return this.x=a,this.y=b,this.z=c,this.w=d,this},d.prototype.toString=function(){return this.x+","+this.y+","+this.z+","+this.w},d.prototype.toArray=function(){return[this.x,this.y,this.z,this.w]},d.prototype.setFromAxisAngle=function(a,b){var c=Math.sin(.5*b);return this.x=a.x*c,this.y=a.y*c,this.z=a.z*c,this.w=Math.cos(.5*b),this},d.prototype.toAxisAngle=function(a){a=a||new e,this.normalize();var b=2*Math.acos(this.w),c=Math.sqrt(1-this.w*this.w);return c<.001?(a.x=this.x,a.y=this.y,a.z=this.z):(a.x=this.x/c,a.y=this.y/c,a.z=this.z/c),[a,b]};var f=new e,g=new e;d.prototype.setFromVectors=function(a,b){if(a.isAntiparallelTo(b)){var c=f,d=g;a.tangents(c,d),this.setFromAxisAngle(c,Math.PI)}else{var e=a.cross(b);this.x=e.x,this.y=e.y,this.z=e.z,this.w=Math.sqrt(Math.pow(a.norm(),2)*Math.pow(b.norm(),2))+a.dot(b),this.normalize()}return this};new e,new e,new e;d.prototype.mult=function(a,b){b=b||new d;var c=this.x,e=this.y,f=this.z,g=this.w,h=a.x,i=a.y,j=a.z,k=a.w;return b.x=c*k+g*h+e*j-f*i,b.y=e*k+g*i+f*h-c*j,b.z=f*k+g*j+c*i-e*h,b.w=g*k-c*h-e*i-f*j,b},d.prototype.inverse=function(a){var b=this.x,c=this.y,e=this.z,f=this.w;a=a||new d,this.conjugate(a);var g=1/(b*b+c*c+e*e+f*f);return a.x*=g,a.y*=g,a.z*=g,a.w*=g,a},d.prototype.conjugate=function(a){return a=a||new d,a.x=-this.x,a.y=-this.y,a.z=-this.z,a.w=this.w,a},d.prototype.normalize=function(){var a=Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w);return 0===a?(this.x=0,this.y=0,this.z=0,this.w=0):(a=1/a,this.x*=a,this.y*=a,this.z*=a,this.w*=a),this},d.prototype.normalizeFast=function(){var a=(3-(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w))/2;return 0===a?(this.x=0,this.y=0,this.z=0,this.w=0):(this.x*=a,this.y*=a,this.z*=a,this.w*=a),this},d.prototype.vmult=function(a,b){b=b||new e;var c=a.x,d=a.y,f=a.z,g=this.x,h=this.y,i=this.z,j=this.w,k=j*c+h*f-i*d,l=j*d+i*c-g*f,m=j*f+g*d-h*c,n=-g*c-h*d-i*f;return b.x=k*j+n*-g+l*-i-m*-h,b.y=l*j+n*-h+m*-g-k*-i,b.z=m*j+n*-i+k*-h-l*-g,b},d.prototype.copy=function(a){return this.x=a.x,this.y=a.y,this.z=a.z,this.w=a.w,this},d.prototype.toEuler=function(a,b){b=b||"YZX";var c,d,e,f=this.x,g=this.y,h=this.z,i=this.w;switch(b){case"YZX":var j=f*g+h*i;if(j>.499&&(c=2*Math.atan2(f,i),d=Math.PI/2,e=0),j<-.499&&(c=-2*Math.atan2(f,i),d=-Math.PI/2,e=0),isNaN(c)){var k=f*f,l=g*g,m=h*h;c=Math.atan2(2*g*i-2*f*h,1-2*l-2*m),d=Math.asin(2*j),e=Math.atan2(2*f*i-2*g*h,1-2*k-2*m)}break;default:throw new Error("Euler order "+b+" not supported yet.")}a.y=c,a.z=d,a.x=e},d.prototype.setFromEuler=function(a,b,c,d){d=d||"XYZ";var e=Math.cos(a/2),f=Math.cos(b/2),g=Math.cos(c/2),h=Math.sin(a/2),i=Math.sin(b/2),j=Math.sin(c/2);return"XYZ"===d?(this.x=h*f*g+e*i*j,this.y=e*i*g-h*f*j,this.z=e*f*j+h*i*g,this.w=e*f*g-h*i*j):"YXZ"===d?(this.x=h*f*g+e*i*j,this.y=e*i*g-h*f*j,this.z=e*f*j-h*i*g,this.w=e*f*g+h*i*j):"ZXY"===d?(this.x=h*f*g-e*i*j,this.y=e*i*g+h*f*j,this.z=e*f*j+h*i*g,this.w=e*f*g-h*i*j):"ZYX"===d?(this.x=h*f*g-e*i*j,this.y=e*i*g+h*f*j,this.z=e*f*j-h*i*g,this.w=e*f*g+h*i*j):"YZX"===d?(this.x=h*f*g+e*i*j,this.y=e*i*g+h*f*j,this.z=e*f*j-h*i*g,this.w=e*f*g-h*i*j):"XZY"===d&&(this.x=h*f*g-e*i*j,this.y=e*i*g-h*f*j,this.z=e*f*j+h*i*g,this.w=e*f*g+h*i*j),this},d.prototype.clone=function(){return new d(this.x,this.y,this.z,this.w)},d.prototype.slerp=function(a,b,c){c=c||new d;var e,f,g,h,i,j=this.x,k=this.y,l=this.z,m=this.w,n=a.x,o=a.y,p=a.z,q=a.w;return f=j*n+k*o+l*p+m*q,f<0&&(f=-f,n=-n,o=-o,p=-p,q=-q),1-f>1e-6?(e=Math.acos(f),g=Math.sin(e),h=Math.sin((1-b)*e)/g,i=Math.sin(b*e)/g):(h=1-b,i=b),c.x=h*j+i*n,c.y=h*k+i*o,c.z=h*l+i*p,c.w=h*m+i*q,c},d.prototype.integrate=function(a,b,c,e){e=e||new d;var f=a.x*c.x,g=a.y*c.y,h=a.z*c.z,i=this.x,j=this.y,k=this.z,l=this.w,m=.5*b;return e.x+=m*(f*l+g*k-h*j),e.y+=m*(g*l+h*i-f*k),e.z+=m*(h*l+f*j-g*i),e.w+=m*(-f*i-g*j-h*k),e}},{"./Vec3":31}],30:[function(a,b,c){function d(a){a=a||{},this.position=new e,a.position&&this.position.copy(a.position),this.quaternion=new f,a.quaternion&&this.quaternion.copy(a.quaternion)}var e=a("./Vec3"),f=a("./Quaternion");b.exports=d;var g=new f;d.pointToLocalFrame=function(a,b,c,d){var d=d||new e;return c.vsub(a,d),b.conjugate(g),g.vmult(d,d),d},d.prototype.pointToLocal=function(a,b){return d.pointToLocalFrame(this.position,this.quaternion,a,b)},d.pointToWorldFrame=function(a,b,c,d){var d=d||new e;return b.vmult(c,d),d.vadd(a,d),d},d.prototype.pointToWorld=function(a,b){return d.pointToWorldFrame(this.position,this.quaternion,a,b)},d.prototype.vectorToWorldFrame=function(a,b){var b=b||new e;return this.quaternion.vmult(a,b),b},d.vectorToWorldFrame=function(a,b,c){return a.vmult(b,c),c},d.vectorToLocalFrame=function(a,b,c,d){var d=d||new e;return b.w*=-1,b.vmult(c,d),b.w*=-1,d}},{"./Quaternion":29,"./Vec3":31}],31:[function(a,b,c){function d(a,b,c){this.x=a||0,this.y=b||0,this.z=c||0}b.exports=d;var e=a("./Mat3");d.ZERO=new d(0,0,0),d.UNIT_X=new d(1,0,0),d.UNIT_Y=new d(0,1,0),d.UNIT_Z=new d(0,0,1),d.prototype.cross=function(a,b){var c=a.x,e=a.y,f=a.z,g=this.x,h=this.y,i=this.z;return b=b||new d,b.x=h*f-i*e,b.y=i*c-g*f,b.z=g*e-h*c,b},d.prototype.set=function(a,b,c){return this.x=a,this.y=b,this.z=c,this},d.prototype.setZero=function(){this.x=this.y=this.z=0},d.prototype.vadd=function(a,b){if(!b)return new d(this.x+a.x,this.y+a.y,this.z+a.z);b.x=a.x+this.x,b.y=a.y+this.y,b.z=a.z+this.z},d.prototype.vsub=function(a,b){if(!b)return new d(this.x-a.x,this.y-a.y,this.z-a.z);b.x=this.x-a.x,b.y=this.y-a.y,b.z=this.z-a.z},d.prototype.crossmat=function(){return new e([0,-this.z,this.y,this.z,0,-this.x,-this.y,this.x,0])},d.prototype.normalize=function(){var a=this.x,b=this.y,c=this.z,d=Math.sqrt(a*a+b*b+c*c);if(d>0){var e=1/d;this.x*=e,this.y*=e,this.z*=e}else this.x=0,this.y=0,this.z=0;return d},d.prototype.unit=function(a){a=a||new d;var b=this.x,c=this.y,e=this.z,f=Math.sqrt(b*b+c*c+e*e);return f>0?(f=1/f,a.x=b*f,a.y=c*f,a.z=e*f):(a.x=1,a.y=0,a.z=0),a},d.prototype.norm=function(){var a=this.x,b=this.y,c=this.z;return Math.sqrt(a*a+b*b+c*c)},d.prototype.length=d.prototype.norm,d.prototype.norm2=function(){return this.dot(this)},d.prototype.lengthSquared=d.prototype.norm2,d.prototype.distanceTo=function(a){var b=this.x,c=this.y,d=this.z,e=a.x,f=a.y,g=a.z;return Math.sqrt((e-b)*(e-b)+(f-c)*(f-c)+(g-d)*(g-d))},d.prototype.distanceSquared=function(a){var b=this.x,c=this.y,d=this.z,e=a.x,f=a.y,g=a.z;return(e-b)*(e-b)+(f-c)*(f-c)+(g-d)*(g-d)},d.prototype.mult=function(a,b){b=b||new d;var c=this.x,e=this.y,f=this.z;return b.x=a*c,b.y=a*e,b.z=a*f,b},d.prototype.vmul=function(a,b){return b=b||new d,b.x=a.x*this.x,b.y=a.y*this.y,b.z=a.z*this.z,b},d.prototype.scale=d.prototype.mult,d.prototype.addScaledVector=function(a,b,c){return c=c||new d,c.x=this.x+a*b.x,c.y=this.y+a*b.y,c.z=this.z+a*b.z,c},d.prototype.dot=function(a){return this.x*a.x+this.y*a.y+this.z*a.z},d.prototype.isZero=function(){return 0===this.x&&0===this.y&&0===this.z},d.prototype.negate=function(a){return a=a||new d,a.x=-this.x,a.y=-this.y,a.z=-this.z,a};var f=new d,g=new d;d.prototype.tangents=function(a,b){var c=this.norm();if(c>0){var d=f,e=1/c;d.set(this.x*e,this.y*e,this.z*e);var h=g;Math.abs(d.x)<.9?(h.set(1,0,0),d.cross(h,a)):(h.set(0,1,0),d.cross(h,a)),d.cross(a,b)}else a.set(1,0,0),b.set(0,1,0)},d.prototype.toString=function(){return this.x+","+this.y+","+this.z},d.prototype.toArray=function(){return[this.x,this.y,this.z]},d.prototype.copy=function(a){return this.x=a.x,this.y=a.y,this.z=a.z,this},d.prototype.lerp=function(a,b,c){var d=this.x,e=this.y,f=this.z;c.x=d+(a.x-d)*b,c.y=e+(a.y-e)*b,c.z=f+(a.z-f)*b},d.prototype.almostEquals=function(a,b){return void 0===b&&(b=1e-6),!(Math.abs(this.x-a.x)>b||Math.abs(this.y-a.y)>b||Math.abs(this.z-a.z)>b)},d.prototype.almostZero=function(a){return void 0===a&&(a=1e-6),!(Math.abs(this.x)>a||Math.abs(this.y)>a||Math.abs(this.z)>a)};var h=new d;d.prototype.isAntiparallelTo=function(a,b){return this.negate(h),h.almostEquals(a,b)},d.prototype.clone=function(){return new d(this.x,this.y,this.z)}},{"./Mat3":28}],32:[function(a,b,c){function d(a){a=a||{},e.apply(this),this.id=d.idCounter++,this.world=null,this.preStep=null,this.postStep=null,this.vlambda=new f,this.collisionFilterGroup="number"==typeof a.collisionFilterGroup?a.collisionFilterGroup:1,this.collisionFilterMask="number"==typeof a.collisionFilterMask?a.collisionFilterMask:-1,this.collisionResponse=!0,this.position=new f,this.previousPosition=new f,this.interpolatedPosition=new f,this.initPosition=new f,a.position&&(this.position.copy(a.position),this.previousPosition.copy(a.position),this.interpolatedPosition.copy(a.position),this.initPosition.copy(a.position)),this.velocity=new f,a.velocity&&this.velocity.copy(a.velocity),this.initVelocity=new f,this.force=new f;var b="number"==typeof a.mass?a.mass:0;this.mass=b,this.invMass=b>0?1/b:0,this.material=a.material||null,this.linearDamping="number"==typeof a.linearDamping?a.linearDamping:.01,this.type=b<=0?d.STATIC:d.DYNAMIC,typeof a.type==typeof d.STATIC&&(this.type=a.type),this.allowSleep=void 0===a.allowSleep||a.allowSleep,this.sleepState=0,this.sleepSpeedLimit=void 0!==a.sleepSpeedLimit?a.sleepSpeedLimit:.1,this.sleepTimeLimit=void 0!==a.sleepTimeLimit?a.sleepTimeLimit:1,this.timeLastSleepy=0,this._wakeUpAfterNarrowphase=!1,this.torque=new f,this.quaternion=new h,this.initQuaternion=new h,this.previousQuaternion=new h,this.interpolatedQuaternion=new h,a.quaternion&&(this.quaternion.copy(a.quaternion),this.initQuaternion.copy(a.quaternion),this.previousQuaternion.copy(a.quaternion),this.interpolatedQuaternion.copy(a.quaternion)),this.angularVelocity=new f,a.angularVelocity&&this.angularVelocity.copy(a.angularVelocity),this.initAngularVelocity=new f,this.shapes=[],this.shapeOffsets=[],this.shapeOrientations=[],this.inertia=new f,this.invInertia=new f,this.invInertiaWorld=new g,this.invMassSolve=0,this.invInertiaSolve=new f,this.invInertiaWorldSolve=new g,this.fixedRotation=void 0!==a.fixedRotation&&a.fixedRotation,this.angularDamping=void 0!==a.angularDamping?a.angularDamping:.01,this.linearFactor=new f(1,1,1),a.linearFactor&&this.linearFactor.copy(a.linearFactor),this.angularFactor=new f(1,1,1),a.angularFactor&&this.angularFactor.copy(a.angularFactor),this.aabb=new i,this.aabbNeedsUpdate=!0,this.boundingRadius=0,this.wlambda=new f,a.shape&&this.addShape(a.shape),this.updateMassProperties()}b.exports=d;var e=a("../utils/EventTarget"),f=(a("../shapes/Shape"),a("../math/Vec3")),g=a("../math/Mat3"),h=a("../math/Quaternion"),i=(a("../material/Material"),a("../collision/AABB")),j=a("../shapes/Box");d.prototype=new e,d.prototype.constructor=d,d.COLLIDE_EVENT_NAME="collide",d.DYNAMIC=1,d.STATIC=2,d.KINEMATIC=4,d.AWAKE=0,d.SLEEPY=1,d.SLEEPING=2,d.idCounter=0,d.wakeupEvent={type:"wakeup"},d.prototype.wakeUp=function(){var a=this.sleepState;this.sleepState=0,this._wakeUpAfterNarrowphase=!1,a===d.SLEEPING&&this.dispatchEvent(d.wakeupEvent)},d.prototype.sleep=function(){this.sleepState=d.SLEEPING,this.velocity.set(0,0,0),this.angularVelocity.set(0,0,0),this._wakeUpAfterNarrowphase=!1},d.sleepyEvent={type:"sleepy"},d.sleepEvent={type:"sleep"},d.prototype.sleepTick=function(a){if(this.allowSleep){var b=this.sleepState,c=this.velocity.norm2()+this.angularVelocity.norm2(),e=Math.pow(this.sleepSpeedLimit,2);b===d.AWAKE&&c<e?(this.sleepState=d.SLEEPY,this.timeLastSleepy=a,this.dispatchEvent(d.sleepyEvent)):b===d.SLEEPY&&c>e?this.wakeUp():b===d.SLEEPY&&a-this.timeLastSleepy>this.sleepTimeLimit&&(this.sleep(),this.dispatchEvent(d.sleepEvent))}},d.prototype.updateSolveMassProperties=function(){this.sleepState===d.SLEEPING||this.type===d.KINEMATIC?(this.invMassSolve=0,this.invInertiaSolve.setZero(),this.invInertiaWorldSolve.setZero()):(this.invMassSolve=this.invMass,this.invInertiaSolve.copy(this.invInertia),this.invInertiaWorldSolve.copy(this.invInertiaWorld))},d.prototype.pointToLocalFrame=function(a,b){var b=b||new f;return a.vsub(this.position,b),this.quaternion.conjugate().vmult(b,b),b},d.prototype.vectorToLocalFrame=function(a,b){var b=b||new f;return this.quaternion.conjugate().vmult(a,b),b},d.prototype.pointToWorldFrame=function(a,b){var b=b||new f;return this.quaternion.vmult(a,b),b.vadd(this.position,b),b},d.prototype.vectorToWorldFrame=function(a,b){var b=b||new f;return this.quaternion.vmult(a,b),b};var k=new f,l=new h;d.prototype.addShape=function(a,b,c){var d=new f,e=new h;return b&&d.copy(b),c&&e.copy(c),this.shapes.push(a),this.shapeOffsets.push(d),this.shapeOrientations.push(e),this.updateMassProperties(),this.updateBoundingRadius(),this.aabbNeedsUpdate=!0,a.body=this,this},d.prototype.updateBoundingRadius=function(){for(var a=this.shapes,b=this.shapeOffsets,c=a.length,d=0,e=0;e!==c;e++){var f=a[e];f.updateBoundingSphereRadius();var g=b[e].norm(),h=f.boundingSphereRadius;g+h>d&&(d=g+h)}this.boundingRadius=d};var m=new i;d.prototype.computeAABB=function(){for(var a=this.shapes,b=this.shapeOffsets,c=this.shapeOrientations,d=a.length,e=k,f=l,g=this.quaternion,h=this.aabb,i=m,j=0;j!==d;j++){var n=a[j];g.vmult(b[j],e),e.vadd(this.position,e),c[j].mult(g,f),n.calculateWorldAABB(e,f,i.lowerBound,i.upperBound),0===j?h.copy(i):h.extend(i)}this.aabbNeedsUpdate=!1};var n=new g,o=new g;new g;d.prototype.updateInertiaWorld=function(a){var b=this.invInertia;if(b.x!==b.y||b.y!==b.z||a){var c=n,d=o;c.setRotationFromQuaternion(this.quaternion),c.transpose(d),c.scale(b,c),c.mmult(d,this.invInertiaWorld)}else;};var p=(new f,new f);d.prototype.applyForce=function(a,b){if(this.type===d.DYNAMIC){var c=p;b.cross(a,c),this.force.vadd(a,this.force),this.torque.vadd(c,this.torque)}};var q=new f,r=new f;d.prototype.applyLocalForce=function(a,b){if(this.type===d.DYNAMIC){var c=q,e=r;this.vectorToWorldFrame(a,c),this.vectorToWorldFrame(b,e),this.applyForce(c,e)}};var s=(new f,new f),t=new f;d.prototype.applyImpulse=function(a,b){if(this.type===d.DYNAMIC){var c=b,e=s;e.copy(a),e.mult(this.invMass,e),this.velocity.vadd(e,this.velocity);var f=t;c.cross(a,f),this.invInertiaWorld.vmult(f,f),this.angularVelocity.vadd(f,this.angularVelocity)}};var u=new f,v=new f;d.prototype.applyLocalImpulse=function(a,b){if(this.type===d.DYNAMIC){var c=u,e=v;this.vectorToWorldFrame(a,c),this.vectorToWorldFrame(b,e),this.applyImpulse(c,e)}};var w=new f;d.prototype.updateMassProperties=function(){var a=w;this.invMass=this.mass>0?1/this.mass:0;var b=this.inertia,c=this.fixedRotation;this.computeAABB(),a.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),j.calculateInertia(a,this.mass,b),this.invInertia.set(b.x>0&&!c?1/b.x:0,b.y>0&&!c?1/b.y:0,b.z>0&&!c?1/b.z:0),this.updateInertiaWorld(!0)},d.prototype.getVelocityAtWorldPoint=function(a,b){var c=new f;return a.vsub(this.position,c),this.angularVelocity.cross(c,b),this.velocity.vadd(b,b),b};new f,new f,new h,new h;d.prototype.integrate=function(a,b,c){if(this.previousPosition.copy(this.position),this.previousQuaternion.copy(this.quaternion),(this.type===d.DYNAMIC||this.type===d.KINEMATIC)&&this.sleepState!==d.SLEEPING){var e=this.velocity,f=this.angularVelocity,g=this.position,h=this.force,i=this.torque,j=this.quaternion,k=this.invMass,l=this.invInertiaWorld,m=this.linearFactor,n=k*a;e.x+=h.x*n*m.x,e.y+=h.y*n*m.y,e.z+=h.z*n*m.z;var o=l.elements,p=this.angularFactor,q=i.x*p.x,r=i.y*p.y,s=i.z*p.z;f.x+=a*(o[0]*q+o[1]*r+o[2]*s),f.y+=a*(o[3]*q+o[4]*r+o[5]*s),f.z+=a*(o[6]*q+o[7]*r+o[8]*s),g.x+=e.x*a,g.y+=e.y*a,g.z+=e.z*a,j.integrate(this.angularVelocity,a,this.angularFactor,j),b&&(c?j.normalizeFast():j.normalize()),this.aabbNeedsUpdate=!0,this.updateInertiaWorld()}}},{"../collision/AABB":3,"../material/Material":26,"../math/Mat3":28,"../math/Quaternion":29,"../math/Vec3":31,"../shapes/Box":38,"../shapes/Shape":44,"../utils/EventTarget":50}],33:[function(a,b,c){function d(a){this.chassisBody=a.chassisBody,this.wheelInfos=[],this.sliding=!1,this.world=null,this.indexRightAxis=void 0!==a.indexRightAxis?a.indexRightAxis:1,this.indexForwardAxis=void 0!==a.indexForwardAxis?a.indexForwardAxis:0,this.indexUpAxis=void 0!==a.indexUpAxis?a.indexUpAxis:2}function e(a,b,c,d,e){var g=0,h=c,i=u,j=v,k=w;return a.getVelocityAtWorldPoint(h,i),b.getVelocityAtWorldPoint(h,j),i.vsub(j,k),g=-d.dot(k)*(1/(f(a,c,d)+f(b,c,d))),e<g&&(g=e),g<-e&&(g=-e),g}function f(a,b,c){var d=x,e=y,f=z,g=A;return b.vsub(a.position,d),d.cross(c,e),a.invInertiaWorld.vmult(e,g),g.cross(d,f),a.invMass+c.dot(f)}function g(a,b,c,d,e,f){if(e.norm2()>1.1)return 0;var g=B,h=C,i=D;return a.getVelocityAtWorldPoint(b,g),c.getVelocityAtWorldPoint(d,h),g.vsub(h,i),-.2*e.dot(i)*(1/(a.invMass+c.invMass))}var h=(a("./Body"),a("../math/Vec3")),i=a("../math/Quaternion"),j=(a("../collision/RaycastResult"),a("../collision/Ray")),k=a("../objects/WheelInfo");b.exports=d;var l=(new h,new h,new h,new h),m=new h,n=new h;new j;d.prototype.addWheel=function(a){a=a||{};var b=new k(a),c=this.wheelInfos.length;return this.wheelInfos.push(b),c},d.prototype.setSteeringValue=function(a,b){this.wheelInfos[b].steering=a};new h;d.prototype.applyEngineForce=function(a,b){this.wheelInfos[b].engineForce=a},d.prototype.setBrake=function(a,b){this.wheelInfos[b].brake=a},d.prototype.addToWorld=function(a){this.constraints;a.addBody(this.chassisBody);var b=this;this.preStepCallback=function(){b.updateVehicle(a.dt)},a.addEventListener("preStep",this.preStepCallback),this.world=a},d.prototype.getVehicleAxisWorld=function(a,b){b.set(0===a?1:0,1===a?1:0,2===a?1:0),this.chassisBody.vectorToWorldFrame(b,b)},d.prototype.updateVehicle=function(a){for(var b=this.wheelInfos,c=b.length,d=this.chassisBody,e=0;e<c;e++)this.updateWheelTransform(e);this.currentVehicleSpeedKmHour=3.6*d.velocity.norm();var f=new h;this.getVehicleAxisWorld(this.indexForwardAxis,f),f.dot(d.velocity)<0&&(this.currentVehicleSpeedKmHour*=-1);for(var e=0;e<c;e++)this.castRay(b[e]);this.updateSuspension(a);for(var g=new h,i=new h,e=0;e<c;e++){var j=b[e],k=j.suspensionForce;k>j.maxSuspensionForce&&(k=j.maxSuspensionForce),j.raycastResult.hitNormalWorld.scale(k*a,g),j.raycastResult.hitPointWorld.vsub(d.position,i),d.applyImpulse(g,i)}this.updateFriction(a);var l=new h,m=new h,n=new h;for(e=0;e<c;e++){var j=b[e];d.getVelocityAtWorldPoint(j.chassisConnectionPointWorld,n);var o=1;switch(this.indexUpAxis){case 1:o=-1}if(j.isInContact){this.getVehicleAxisWorld(this.indexForwardAxis,m);var p=m.dot(j.raycastResult.hitNormalWorld);j.raycastResult.hitNormalWorld.scale(p,l),m.vsub(l,m);var q=m.dot(n);j.deltaRotation=o*q*a/j.radius}!j.sliding&&j.isInContact||0===j.engineForce||!j.useCustomSlidingRotationalSpeed||(j.deltaRotation=(j.engineForce>0?1:-1)*j.customSlidingRotationalSpeed*a),Math.abs(j.brake)>Math.abs(j.engineForce)&&(j.deltaRotation=0),j.rotation+=j.deltaRotation,j.deltaRotation*=.99}},d.prototype.updateSuspension=function(a){for(var b=this.chassisBody,c=b.mass,d=this.wheelInfos,e=d.length,f=0;f<e;f++){var g=d[f];if(g.isInContact){var h,i=g.suspensionRestLength,j=g.suspensionLength,k=i-j;h=g.suspensionStiffness*k*g.clippedInvContactDotSuspension;var l,m=g.suspensionRelativeVelocity;l=m<0?g.dampingCompression:g.dampingRelaxation,h-=l*m,g.suspensionForce=h*c,g.suspensionForce<0&&(g.suspensionForce=0)}else g.suspensionForce=0}},d.prototype.removeFromWorld=function(a){this.constraints;a.remove(this.chassisBody),a.removeEventListener("preStep",this.preStepCallback),this.world=null};var o=new h,p=new h;d.prototype.castRay=function(a){var b=o,c=p;this.updateWheelTransformWorld(a);var d=this.chassisBody,e=-1,f=a.suspensionRestLength+a.radius;a.directionWorld.scale(f,b);var g=a.chassisConnectionPointWorld;g.vadd(b,c);var i=a.raycastResult;i.reset();var j=d.collisionResponse;d.collisionResponse=!1,this.world.rayTest(g,c,i),d.collisionResponse=j;var k=i.body;if(a.raycastResult.groundObject=0,k){e=i.distance,a.raycastResult.hitNormalWorld=i.hitNormalWorld,a.isInContact=!0;var l=i.distance;a.suspensionLength=l-a.radius;var m=a.suspensionRestLength-a.maxSuspensionTravel,n=a.suspensionRestLength+a.maxSuspensionTravel;a.suspensionLength<m&&(a.suspensionLength=m),a.suspensionLength>n&&(a.suspensionLength=n,a.raycastResult.reset());var q=a.raycastResult.hitNormalWorld.dot(a.directionWorld),r=new h;d.getVelocityAtWorldPoint(a.raycastResult.hitPointWorld,r);var s=a.raycastResult.hitNormalWorld.dot(r);if(q>=-.1)a.suspensionRelativeVelocity=0,a.clippedInvContactDotSuspension=10;else{var t=-1/q;a.suspensionRelativeVelocity=s*t,a.clippedInvContactDotSuspension=t}}else a.suspensionLength=a.suspensionRestLength+0*a.maxSuspensionTravel,a.suspensionRelativeVelocity=0,a.directionWorld.scale(-1,a.raycastResult.hitNormalWorld),a.clippedInvContactDotSuspension=1;return e},d.prototype.updateWheelTransformWorld=function(a){a.isInContact=!1;var b=this.chassisBody;b.pointToWorldFrame(a.chassisConnectionPointLocal,a.chassisConnectionPointWorld),b.vectorToWorldFrame(a.directionLocal,a.directionWorld),b.vectorToWorldFrame(a.axleLocal,a.axleWorld)},d.prototype.updateWheelTransform=function(a){var b=l,c=m,d=n,e=this.wheelInfos[a];this.updateWheelTransformWorld(e),e.directionLocal.scale(-1,b),c.copy(e.axleLocal),b.cross(c,d),d.normalize(),c.normalize();var f=e.steering,g=new i;g.setFromAxisAngle(b,f);var h=new i;h.setFromAxisAngle(c,e.rotation);var j=e.worldTransform.quaternion;this.chassisBody.quaternion.mult(g,j),j.mult(h,j),j.normalize();var k=e.worldTransform.position;k.copy(e.directionWorld),k.scale(e.suspensionLength,k),k.vadd(e.chassisConnectionPointWorld,k)};var q=[new h(1,0,0),new h(0,1,0),new h(0,0,1)];d.prototype.getWheelTransformWorld=function(a){return this.wheelInfos[a].worldTransform};var r=new h,s=[],t=[];d.prototype.updateFriction=function(a){for(var b=r,c=this.wheelInfos,d=c.length,f=this.chassisBody,i=t,j=s,k=0,l=0;l<d;l++){var m=c[l],n=m.raycastResult.body;n&&k++,m.sideImpulse=0,m.forwardImpulse=0,i[l]||(i[l]=new h),j[l]||(j[l]=new h)}for(var l=0;l<d;l++){var m=c[l],n=m.raycastResult.body;if(n){var o=j[l];this.getWheelTransformWorld(l).vectorToWorldFrame(q[this.indexRightAxis],o);var p=m.raycastResult.hitNormalWorld,u=o.dot(p);p.scale(u,b),o.vsub(b,o),o.normalize(),p.cross(o,i[l]),i[l].normalize(),m.sideImpulse=g(f,m.raycastResult.hitPointWorld,n,m.raycastResult.hitPointWorld,o),m.sideImpulse*=1}}var v=1,w=.5;this.sliding=!1;for(var l=0;l<d;l++){var m=c[l],n=m.raycastResult.body,x=0;if(m.slipInfo=1,n){var y=0,z=m.brake?m.brake:y;x=e(f,n,m.raycastResult.hitPointWorld,i[l],z),x+=m.engineForce*a;var A=z/x;m.slipInfo*=A}if(m.forwardImpulse=0,m.skidInfo=1,n){m.skidInfo=1;var B=m.suspensionForce*a*m.frictionSlip,C=B,D=B*C;m.forwardImpulse=x;var E=m.forwardImpulse*w,F=m.sideImpulse*v,G=E*E+F*F;if(m.sliding=!1,G>D){this.sliding=!0,m.sliding=!0;var A=B/Math.sqrt(G);m.skidInfo*=A}}}if(this.sliding)for(var l=0;l<d;l++){var m=c[l];0!==m.sideImpulse&&m.skidInfo<1&&(m.forwardImpulse*=m.skidInfo,m.sideImpulse*=m.skidInfo)}for(var l=0;l<d;l++){var m=c[l],H=new h;if(m.raycastResult.hitPointWorld.vsub(f.position,H),0!==m.forwardImpulse){var I=new h;i[l].scale(m.forwardImpulse,I),f.applyImpulse(I,H)}if(0!==m.sideImpulse){var n=m.raycastResult.body,J=new h;m.raycastResult.hitPointWorld.vsub(n.position,J);var K=new h;j[l].scale(m.sideImpulse,K),f.vectorToLocalFrame(H,H),H["xyz"[this.indexUpAxis]]*=m.rollInfluence,f.vectorToWorldFrame(H,H),f.applyImpulse(K,H),K.scale(-1,K),n.applyImpulse(K,J)}}};var u=new h,v=new h,w=new h,x=new h,y=new h,z=new h,A=new h,B=new h,C=new h,D=new h},{"../collision/Ray":10,"../collision/RaycastResult":11,"../math/Quaternion":29,"../math/Vec3":31,"../objects/WheelInfo":37,"./Body":32}],34:[function(a,b,c){function d(a){if(this.wheelBodies=[],this.coordinateSystem=void 0===a.coordinateSystem?new h(1,2,3):a.coordinateSystem.clone(),this.chassisBody=a.chassisBody,!this.chassisBody){var b=new g(new h(5,2,.5));this.chassisBody=new e(1,b)}this.constraints=[],this.wheelAxes=[],this.wheelForces=[]}var e=a("./Body"),f=a("../shapes/Sphere"),g=a("../shapes/Box"),h=a("../math/Vec3"),i=a("../constraints/HingeConstraint");b.exports=d,d.prototype.addWheel=function(a){a=a||{};var b=a.body;b||(b=new e(1,new f(1.2))),this.wheelBodies.push(b),this.wheelForces.push(0);var c=(new h,void 0!==a.position?a.position.clone():new h),d=new h;this.chassisBody.pointToWorldFrame(c,d),b.position.set(d.x,d.y,d.z);var g=void 0!==a.axis?a.axis.clone():new h(0,1,0);this.wheelAxes.push(g);var j=new i(this.chassisBody,b,{pivotA:c,axisA:g,pivotB:h.ZERO,axisB:g,collideConnected:!1});return this.constraints.push(j),this.wheelBodies.length-1},d.prototype.setSteeringValue=function(a,b){var c=this.wheelAxes[b],d=Math.cos(a),e=Math.sin(a),f=c.x,g=c.y;this.constraints[b].axisA.set(d*f-e*g,e*f+d*g,0)},d.prototype.setMotorSpeed=function(a,b){var c=this.constraints[b];c.enableMotor(),c.motorTargetVelocity=a},d.prototype.disableMotor=function(a){this.constraints[a].disableMotor()};var j=new h;d.prototype.setWheelForce=function(a,b){this.wheelForces[b]=a},d.prototype.applyWheelForce=function(a,b){var c=this.wheelAxes[b],d=this.wheelBodies[b],e=d.torque;c.scale(a,j),d.vectorToWorldFrame(j,j),e.vadd(j,e)},d.prototype.addToWorld=function(a){for(var b=this.constraints,c=this.wheelBodies.concat([this.chassisBody]),d=0;d<c.length;d++)a.addBody(c[d]);for(var d=0;d<b.length;d++)a.addConstraint(b[d]);a.addEventListener("preStep",this._update.bind(this))},d.prototype._update=function(){for(var a=this.wheelForces,b=0;b<a.length;b++)this.applyWheelForce(a[b],b)},d.prototype.removeFromWorld=function(a){for(var b=this.constraints,c=this.wheelBodies.concat([this.chassisBody]),d=0;d<c.length;d++)a.remove(c[d]);for(var d=0;d<b.length;d++)a.removeConstraint(b[d])};var k=new h;d.prototype.getWheelSpeed=function(a){var b=this.wheelAxes[a],c=this.wheelBodies[a],d=c.angularVelocity;return this.chassisBody.vectorToWorldFrame(b,k),d.dot(k)}},{"../constraints/HingeConstraint":16,"../math/Vec3":31,"../shapes/Box":38,"../shapes/Sphere":45,"./Body":32}],35:[function(a,b,c){function d(){this.particles=[],this.density=1,this.smoothingRadius=1,this.speedOfSound=1,this.viscosity=.01,this.eps=1e-6,this.pressures=[],this.densities=[],this.neighbors=[]}b.exports=d;var e=(a("../shapes/Shape"),a("../math/Vec3"));a("../math/Quaternion"),a("../shapes/Particle"),a("../objects/Body"),a("../material/Material");d.prototype.add=function(a){this.particles.push(a),this.neighbors.length<this.particles.length&&this.neighbors.push([])},d.prototype.remove=function(a){var b=this.particles.indexOf(a);-1!==b&&(this.particles.splice(b,1),this.neighbors.length>this.particles.length&&this.neighbors.pop())};var f=new e;d.prototype.getNeighbors=function(a,b){for(var c=this.particles.length,d=a.id,e=this.smoothingRadius*this.smoothingRadius,g=f,h=0;h!==c;h++){var i=this.particles[h];i.position.vsub(a.position,g),d!==i.id&&g.norm2()<e&&b.push(i)}};var g=new e,h=new e,i=new e,j=new e,k=new e,l=new e;d.prototype.update=function(){for(var a=this.particles.length,b=g,c=this.speedOfSound,d=this.eps,e=0;e!==a;e++){var f=this.particles[e],m=this.neighbors[e];m.length=0,this.getNeighbors(f,m),m.push(this.particles[e]);for(var n=m.length,o=0,p=0;p!==n;p++){f.position.vsub(m[p].position,b);var q=b.norm(),r=this.w(q);o+=m[p].mass*r}this.densities[e]=o,this.pressures[e]=c*c*(this.densities[e]-this.density)}for(var s=h,t=i,u=j,v=k,w=l,e=0;e!==a;e++){var x=this.particles[e];s.set(0,0,0),t.set(0,0,0);for(var y,z,m=this.neighbors[e],n=m.length,p=0;p!==n;p++){var A=m[p];x.position.vsub(A.position,v);var B=v.norm();y=-A.mass*(this.pressures[e]/(this.densities[e]*this.densities[e]+d)+this.pressures[p]/(this.densities[p]*this.densities[p]+d)),this.gradw(v,u),u.mult(y,u),s.vadd(u,s),A.velocity.vsub(x.velocity,w),w.mult(1/(1e-4+this.densities[e]*this.densities[p])*this.viscosity*A.mass,w),z=this.nablaw(B),w.mult(z,w),t.vadd(w,t)}t.mult(x.mass,t),s.mult(x.mass,s),x.force.vadd(t,x.force),x.force.vadd(s,x.force)}},d.prototype.w=function(a){var b=this.smoothingRadius;return 315/(64*Math.PI*Math.pow(b,9))*Math.pow(b*b-a*a,3)},d.prototype.gradw=function(a,b){var c=a.norm(),d=this.smoothingRadius;a.mult(945/(32*Math.PI*Math.pow(d,9))*Math.pow(d*d-c*c,2),b)},d.prototype.nablaw=function(a){var b=this.smoothingRadius;return 945/(32*Math.PI*Math.pow(b,9))*(b*b-a*a)*(7*a*a-3*b*b)}},{"../material/Material":26,"../math/Quaternion":29,"../math/Vec3":31,"../objects/Body":32,"../shapes/Particle":42,"../shapes/Shape":44}],36:[function(a,b,c){function d(a,b,c){c=c||{},this.restLength="number"==typeof c.restLength?c.restLength:1,this.stiffness=c.stiffness||100,this.damping=c.damping||1,this.bodyA=a,this.bodyB=b,this.localAnchorA=new e,this.localAnchorB=new e,c.localAnchorA&&this.localAnchorA.copy(c.localAnchorA),c.localAnchorB&&this.localAnchorB.copy(c.localAnchorB),c.worldAnchorA&&this.setWorldAnchorA(c.worldAnchorA),c.worldAnchorB&&this.setWorldAnchorB(c.worldAnchorB)}var e=a("../math/Vec3");b.exports=d,d.prototype.setWorldAnchorA=function(a){this.bodyA.pointToLocalFrame(a,this.localAnchorA)},d.prototype.setWorldAnchorB=function(a){this.bodyB.pointToLocalFrame(a,this.localAnchorB)},d.prototype.getWorldAnchorA=function(a){this.bodyA.pointToWorldFrame(this.localAnchorA,a)},d.prototype.getWorldAnchorB=function(a){this.bodyB.pointToWorldFrame(this.localAnchorB,a)};var f=new e,g=new e,h=new e,i=new e,j=new e,k=new e,l=new e,m=new e,n=new e,o=new e,p=new e;d.prototype.applyForce=function(){var a=this.stiffness,b=this.damping,c=this.restLength,d=this.bodyA,e=this.bodyB,q=f,r=g,s=h,t=i,u=p,v=j,w=k,x=l,y=m,z=n,A=o;this.getWorldAnchorA(v),this.getWorldAnchorB(w),v.vsub(d.position,x),w.vsub(e.position,y),w.vsub(v,q);var B=q.norm();r.copy(q),r.normalize(),e.velocity.vsub(d.velocity,s),e.angularVelocity.cross(y,u),s.vadd(u,s),d.angularVelocity.cross(x,u),s.vsub(u,s),r.mult(-a*(B-c)-b*s.dot(r),t),d.force.vsub(t,d.force),e.force.vadd(t,e.force),x.cross(t,z),y.cross(t,A),d.torque.vsub(z,d.torque),e.torque.vadd(A,e.torque)}},{"../math/Vec3":31}],37:[function(a,b,c){function d(a){a=h.defaults(a,{chassisConnectionPointLocal:new e,chassisConnectionPointWorld:new e,directionLocal:new e,directionWorld:new e,axleLocal:new e,axleWorld:new e,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=a.maxSuspensionTravel,this.customSlidingRotationalSpeed=a.customSlidingRotationalSpeed,this.useCustomSlidingRotationalSpeed=a.useCustomSlidingRotationalSpeed,this.sliding=!1,this.chassisConnectionPointLocal=a.chassisConnectionPointLocal.clone(),this.chassisConnectionPointWorld=a.chassisConnectionPointWorld.clone(),this.directionLocal=a.directionLocal.clone(),this.directionWorld=a.directionWorld.clone(),this.axleLocal=a.axleLocal.clone(),this.axleWorld=a.axleWorld.clone(),this.suspensionRestLength=a.suspensionRestLength,this.suspensionMaxLength=a.suspensionMaxLength,this.radius=a.radius,this.suspensionStiffness=a.suspensionStiffness,this.dampingCompression=a.dampingCompression,this.dampingRelaxation=a.dampingRelaxation,this.frictionSlip=a.frictionSlip,this.steering=0,this.rotation=0,this.deltaRotation=0,this.rollInfluence=a.rollInfluence,this.maxSuspensionForce=a.maxSuspensionForce,this.engineForce=0,this.brake=0,this.isFrontWheel=a.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 g,this.worldTransform=new f,this.isInContact=!1}var e=a("../math/Vec3"),f=a("../math/Transform"),g=a("../collision/RaycastResult"),h=a("../utils/Utils");b.exports=d;var i=new e,j=new e,i=new e;d.prototype.updateWheel=function(a){var b=this.raycastResult;if(this.isInContact){var c=b.hitNormalWorld.dot(b.directionWorld);b.hitPointWorld.vsub(a.position,j),a.getVelocityAtWorldPoint(j,i);var d=b.hitNormalWorld.dot(i);if(c>=-.1)this.suspensionRelativeVelocity=0,this.clippedInvContactDotSuspension=10;else{var e=-1/c;this.suspensionRelativeVelocity=d*e,this.clippedInvContactDotSuspension=e}}else b.suspensionLength=this.suspensionRestLength,this.suspensionRelativeVelocity=0,b.directionWorld.scale(-1,b.hitNormalWorld),this.clippedInvContactDotSuspension=1}},{"../collision/RaycastResult":11,"../math/Transform":30,"../math/Vec3":31,"../utils/Utils":54}],38:[function(a,b,c){function d(a){e.call(this,{type:e.types.BOX}),this.halfExtents=a,this.convexPolyhedronRepresentation=null,this.updateConvexPolyhedronRepresentation(),this.updateBoundingSphereRadius()}b.exports=d;var e=a("./Shape"),f=a("../math/Vec3"),g=a("./ConvexPolyhedron");d.prototype=new e,d.prototype.constructor=d,d.prototype.updateConvexPolyhedronRepresentation=function(){var a=this.halfExtents.x,b=this.halfExtents.y,c=this.halfExtents.z,d=f,e=[new d(-a,-b,-c),new d(a,-b,-c),new d(a,b,-c),new d(-a,b,-c),new d(-a,-b,c),new d(a,-b,c),new d(a,b,c),new d(-a,b,c)],h=[[3,2,1,0],[4,5,6,7],[5,4,0,1],[2,3,7,6],[0,4,7,3],[1,2,6,5]],i=(new d(0,0,1),new d(0,1,0),new d(1,0,0),new g(e,h));this.convexPolyhedronRepresentation=i,i.material=this.material},d.prototype.calculateLocalInertia=function(a,b){return b=b||new f,d.calculateInertia(this.halfExtents,a,b),b},d.calculateInertia=function(a,b,c){var d=a;c.x=1/12*b*(2*d.y*2*d.y+2*d.z*2*d.z),c.y=1/12*b*(2*d.x*2*d.x+2*d.z*2*d.z),c.z=1/12*b*(2*d.y*2*d.y+2*d.x*2*d.x)},d.prototype.getSideNormals=function(a,b){var c=a,d=this.halfExtents;if(c[0].set(d.x,0,0),c[1].set(0,d.y,0),c[2].set(0,0,d.z),c[3].set(-d.x,0,0),c[4].set(0,-d.y,0),c[5].set(0,0,-d.z),void 0!==b)for(var e=0;e!==c.length;e++)b.vmult(c[e],c[e]);return c},d.prototype.volume=function(){return 8*this.halfExtents.x*this.halfExtents.y*this.halfExtents.z},d.prototype.updateBoundingSphereRadius=function(){this.boundingSphereRadius=this.halfExtents.norm()};var h=new f;new f;d.prototype.forEachWorldCorner=function(a,b,c){for(var d=this.halfExtents,e=[[d.x,d.y,d.z],[-d.x,d.y,d.z],[-d.x,-d.y,d.z],[-d.x,-d.y,-d.z],[d.x,-d.y,-d.z],[d.x,d.y,-d.z],[-d.x,d.y,-d.z],[d.x,-d.y,d.z]],f=0;f<e.length;f++)h.set(e[f][0],e[f][1],e[f][2]),b.vmult(h,h),a.vadd(h,h),c(h.x,h.y,h.z)};var i=[new f,new f,new f,new f,new f,new f,new f,new f];d.prototype.calculateWorldAABB=function(a,b,c,d){var e=this.halfExtents;i[0].set(e.x,e.y,e.z),i[1].set(-e.x,e.y,e.z),i[2].set(-e.x,-e.y,e.z),i[3].set(-e.x,-e.y,-e.z),i[4].set(e.x,-e.y,-e.z),i[5].set(e.x,e.y,-e.z),i[6].set(-e.x,e.y,-e.z),i[7].set(e.x,-e.y,e.z);var f=i[0];b.vmult(f,f),a.vadd(f,f),d.copy(f),c.copy(f);for(var g=1;g<8;g++){var f=i[g];b.vmult(f,f),a.vadd(f,f);var h=f.x,j=f.y,k=f.z;h>d.x&&(d.x=h),j>d.y&&(d.y=j),k>d.z&&(d.z=k),h<c.x&&(c.x=h),j<c.y&&(c.y=j),k<c.z&&(c.z=k)}}},{"../math/Vec3":31,"./ConvexPolyhedron":39,"./Shape":44}],39:[function(a,b,c){function d(a,b,c){e.call(this,{type:e.types.CONVEXPOLYHEDRON}),this.vertices=a||[],this.worldVertices=[],this.worldVerticesNeedsUpdate=!0,this.faces=b||[],this.faceNormals=[],this.computeNormals(),this.worldFaceNormalsNeedsUpdate=!0,this.worldFaceNormals=[],this.uniqueEdges=[],this.uniqueAxes=c?c.slice():null,this.computeEdges(),this.updateBoundingSphereRadius()}b.exports=d;var e=a("./Shape"),f=a("../math/Vec3"),g=(a("../math/Quaternion"),a("../math/Transform"));d.prototype=new e,d.prototype.constructor=d;var h=new f;d.prototype.computeEdges=function(){var a=this.faces,b=this.vertices,c=(b.length,this.uniqueEdges);c.length=0;for(var d=h,e=0;e!==a.length;e++)for(var f=a[e],g=f.length,i=0;i!==g;i++){var j=(i+1)%g;b[f[i]].vsub(b[f[j]],d),d.normalize();for(var k=!1,l=0;l!==c.length;l++)if(c[l].almostEquals(d)||c[l].almostEquals(d)){k=!0;break}k||c.push(d.clone())}},d.prototype.computeNormals=function(){this.faceNormals.length=this.faces.length;for(var a=0;a<this.faces.length;a++){for(var b=0;b<this.faces[a].length;b++)if(!this.vertices[this.faces[a][b]])throw new Error("Vertex "+this.faces[a][b]+" not found!");var c=this.faceNormals[a]||new f;this.getFaceNormal(a,c),c.negate(c),this.faceNormals[a]=c;var d=this.vertices[this.faces[a][0]];if(c.dot(d)<0){console.error(".faceNormals["+a+"] = Vec3("+c.toString()+") looks like it points into the shape? The vertices follow. Make sure they are ordered CCW around the normal, using the right hand rule.");for(var b=0;b<this.faces[a].length;b++)console.warn(".vertices["+this.faces[a][b]+"] = Vec3("+this.vertices[this.faces[a][b]].toString()+")")}}};var i=new f,j=new f;d.computeNormal=function(a,b,c,d){b.vsub(a,j),c.vsub(b,i),i.cross(j,d),d.isZero()||d.normalize()},d.prototype.getFaceNormal=function(a,b){var c=this.faces[a],e=this.vertices[c[0]],f=this.vertices[c[1]],g=this.vertices[c[2]];return d.computeNormal(e,f,g,b)};var k=new f;d.prototype.clipAgainstHull=function(a,b,c,d,e,g,h,i,j){for(var l=k,m=-1,n=-Number.MAX_VALUE,o=0;o<c.faces.length;o++){l.copy(c.faceNormals[o]),e.vmult(l,l);var p=l.dot(g);p>n&&(n=p,m=o)}for(var q=[],r=c.faces[m],s=r.length,t=0;t<s;t++){var u=c.vertices[r[t]],v=new f;v.copy(u),e.vmult(v,v),d.vadd(v,v),q.push(v)}m>=0&&this.clipFaceAgainstHull(g,a,b,q,h,i,j)};var l=new f,m=new f,n=new f,o=new f,p=new f,q=new f;d.prototype.findSeparatingAxis=function(a,b,c,d,e,f,g,h){var i=l,j=m,k=n,r=o,s=p,t=q,u=Number.MAX_VALUE,v=this,w=0;if(v.uniqueAxes)for(var x=0;x!==v.uniqueAxes.length;x++){c.vmult(v.uniqueAxes[x],i);var y=v.testSepAxis(i,a,b,c,d,e);if(!1===y)return!1;y<u&&(u=y,f.copy(i))}else for(var z=g?g.length:v.faces.length,x=0;x<z;x++){var A=g?g[x]:x;i.copy(v.faceNormals[A]),c.vmult(i,i);var y=v.testSepAxis(i,a,b,c,d,e);if(!1===y)return!1;y<u&&(u=y,f.copy(i))}if(a.uniqueAxes)for(var x=0;x!==a.uniqueAxes.length;x++){e.vmult(a.uniqueAxes[x],j),w++;var y=v.testSepAxis(j,a,b,c,d,e);if(!1===y)return!1;y<u&&(u=y,f.copy(j))}else for(var B=h?h.length:a.faces.length,x=0;x<B;x++){var A=h?h[x]:x;j.copy(a.faceNormals[A]),e.vmult(j,j),w++;var y=v.testSepAxis(j,a,b,c,d,e);if(!1===y)return!1;y<u&&(u=y,f.copy(j))}for(var C=0;C!==v.uniqueEdges.length;C++){c.vmult(v.uniqueEdges[C],r);for(var D=0;D!==a.uniqueEdges.length;D++)if(e.vmult(a.uniqueEdges[D],s),r.cross(s,t),!t.almostZero()){t.normalize();var E=v.testSepAxis(t,a,b,c,d,e);if(!1===E)return!1;E<u&&(u=E,f.copy(t))}}return d.vsub(b,k),k.dot(f)>0&&f.negate(f),!0};var r=[],s=[];d.prototype.testSepAxis=function(a,b,c,e,f,g){var h=this;d.project(h,a,c,e,r),d.project(b,a,f,g,s);var i=r[0],j=r[1],k=s[0],l=s[1];if(i<l||k<j)return!1;var m=i-l,n=k-j;return m<n?m:n};var t=new f,u=new f;d.prototype.calculateLocalInertia=function(a,b){this.computeLocalAABB(t,u);var c=u.x-t.x,d=u.y-t.y,e=u.z-t.z;b.x=1/12*a*(2*d*2*d+2*e*2*e),b.y=1/12*a*(2*c*2*c+2*e*2*e),b.z=1/12*a*(2*d*2*d+2*c*2*c)},d.prototype.getPlaneConstantOfFace=function(a){var b=this.faces[a],c=this.faceNormals[a],d=this.vertices[b[0]];return-c.dot(d)};var v=new f,w=new f,x=new f,y=new f,z=new f,A=new f,B=new f,C=new f;d.prototype.clipFaceAgainstHull=function(a,b,c,d,e,f,g){for(var h=v,i=w,j=x,k=y,l=z,m=A,n=B,o=C,p=this,q=[],r=d,s=q,t=-1,u=Number.MAX_VALUE,D=0;D<p.faces.length;D++){h.copy(p.faceNormals[D]),c.vmult(h,h);var E=h.dot(a);E<u&&(u=E,t=D)}if(!(t<0)){var F=p.faces[t];F.connectedFaces=[];for(var G=0;G<p.faces.length;G++)for(var H=0;H<p.faces[G].length;H++)-1!==F.indexOf(p.faces[G][H])&&G!==t&&-1===F.connectedFaces.indexOf(G)&&F.connectedFaces.push(G);for(var I=(r.length,F.length),J=0;J<I;J++){var K=p.vertices[F[J]],L=p.vertices[F[(J+1)%I]];K.vsub(L,i),j.copy(i),c.vmult(j,j),b.vadd(j,j),k.copy(this.faceNormals[t]),c.vmult(k,k),b.vadd(k,k),j.cross(k,l),l.negate(l),m.copy(K),c.vmult(m,m),b.vadd(m,m);var M,N=(m.dot(l),F.connectedFaces[J]);n.copy(this.faceNormals[N]);var O=this.getPlaneConstantOfFace(N);o.copy(n),c.vmult(o,o);var M=O-o.dot(b);for(this.clipFaceAgainstPlane(r,s,o,M);r.length;)r.shift();for(;s.length;)r.push(s.shift())}n.copy(this.faceNormals[t]);var O=this.getPlaneConstantOfFace(t);o.copy(n),c.vmult(o,o);for(var M=O-o.dot(b),G=0;G<r.length;G++){var P=o.dot(r[G])+M;if(P<=e&&(console.log("clamped: depth="+P+" to minDist="+e),P=e),P<=f){var Q=r[G];if(P<=0){var R={point:Q,normal:o,depth:P};g.push(R)}}}}},d.prototype.clipFaceAgainstPlane=function(a,b,c,d){var e,g,h=a.length;if(h<2)return b;var i=a[a.length-1],j=a[0];e=c.dot(i)+d;for(var k=0;k<h;k++){if(j=a[k],g=c.dot(j)+d,e<0)if(g<0){var l=new f;l.copy(j),b.push(l)}else{var l=new f;i.lerp(j,e/(e-g),l),b.push(l)}else if(g<0){var l=new f;i.lerp(j,e/(e-g),l),b.push(l),b.push(j)}i=j,e=g}return b},d.prototype.computeWorldVertices=function(a,b){for(var c=this.vertices.length;this.worldVertices.length<c;)this.worldVertices.push(new f);for(var d=this.vertices,e=this.worldVertices,g=0;g!==c;g++)b.vmult(d[g],e[g]),a.vadd(e[g],e[g]);this.worldVerticesNeedsUpdate=!1};new f;d.prototype.computeLocalAABB=function(a,b){var c=this.vertices.length,d=this.vertices;a.set(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),b.set(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE);for(var e=0;e<c;e++){var f=d[e];f.x<a.x?a.x=f.x:f.x>b.x&&(b.x=f.x),f.y<a.y?a.y=f.y:f.y>b.y&&(b.y=f.y),f.z<a.z?a.z=f.z:f.z>b.z&&(b.z=f.z)}},d.prototype.computeWorldFaceNormals=function(a){for(var b=this.faceNormals.length;this.worldFaceNormals.length<b;)this.worldFaceNormals.push(new f);for(var c=this.faceNormals,d=this.worldFaceNormals,e=0;e!==b;e++)a.vmult(c[e],d[e]);this.worldFaceNormalsNeedsUpdate=!1},d.prototype.updateBoundingSphereRadius=function(){for(var a=0,b=this.vertices,c=0,d=b.length;c!==d;c++){var e=b[c].norm2();e>a&&(a=e)}this.boundingSphereRadius=Math.sqrt(a)};var D=new f;d.prototype.calculateWorldAABB=function(a,b,c,d){for(var e,f,g,h,i,j,k=this.vertices.length,l=this.vertices,m=0;m<k;m++){D.copy(l[m]),b.vmult(D,D),a.vadd(D,D);var n=D;n.x<e||void 0===e?e=n.x:(n.x>h||void 0===h)&&(h=n.x),n.y<f||void 0===f?f=n.y:(n.y>i||void 0===i)&&(i=n.y),n.z<g||void 0===g?g=n.z:(n.z>j||void 0===j)&&(j=n.z)}c.set(e,f,g),d.set(h,i,j)},d.prototype.volume=function(){return 4*Math.PI*this.boundingSphereRadius/3},d.prototype.getAveragePointLocal=function(a){a=a||new f;for(var b=this.vertices.length,c=this.vertices,d=0;d<b;d++)a.vadd(c[d],a);return a.mult(1/b,a),a},d.prototype.transformAllPoints=function(a,b){var c=this.vertices.length,d=this.vertices;if(b){for(var e=0;e<c;e++){var f=d[e];b.vmult(f,f)}for(var e=0;e<this.faceNormals.length;e++){var f=this.faceNormals[e];b.vmult(f,f)}}if(a)for(var e=0;e<c;e++){var f=d[e];f.vadd(a,f)}};var E=new f,F=new f,G=new f;d.prototype.pointIsInside=function(a){var b=this.vertices.length,c=this.vertices,d=this.faces,e=this.faceNormals,f=null,g=this.faces.length,h=E;this.getAveragePointLocal(h);for(var i=0;i<g;i++){var b=(this.faces[i].length,e[i]),j=c[d[i][0]],k=F;a.vsub(j,k);var l=b.dot(k),m=G;h.vsub(j,m);var n=b.dot(m);if(l<0&&n>0||l>0&&n<0)return!1}return f?1:-1};var H=(new f,new f),I=new f;d.project=function(a,b,c,d,e){var f=a.vertices.length,h=H,i=0,j=0,k=I,l=a.vertices;k.setZero(),g.vectorToLocalFrame(c,d,b,h),g.pointToLocalFrame(c,d,k,k);var m=k.dot(h);j=i=l[0].dot(h);for(var n=1;n<f;n++){var o=l[n].dot(h);o>i&&(i=o),o<j&&(j=o)}if(j-=m,i-=m,j>i){var p=j;j=i,i=p}e[0]=i,e[1]=j}},{"../math/Quaternion":29,"../math/Transform":30,"../math/Vec3":31,"./Shape":44}],40:[function(a,b,c){function d(a,b,c,d){var g=d,h=[],i=[],j=[],k=[],l=[],m=Math.cos,n=Math.sin;h.push(new e(b*m(0),b*n(0),.5*-c)),k.push(0),h.push(new e(a*m(0),a*n(0),.5*c)),l.push(1);for(var o=0;o<g;o++){var p=2*Math.PI/g*(o+1),q=2*Math.PI/g*(o+.5);o<g-1?(h.push(new e(b*m(p),b*n(p),.5*-c)),k.push(2*o+2),h.push(new e(a*m(p),a*n(p),.5*c)),l.push(2*o+3),j.push([2*o+2,2*o+3,2*o+1,2*o])):j.push([0,1,2*o+1,2*o]),(g%2==1||o<g/2)&&i.push(new e(m(q),n(q),0))}j.push(l),i.push(new e(0,0,1));for(var r=[],o=0;o<k.length;o++)r.push(k[k.length-o-1]);j.push(r),f.call(this,h,j,i)}b.exports=d;var e=(a("./Shape"),a("../math/Vec3")),f=(a("../math/Quaternion"),a("./ConvexPolyhedron"));d.prototype=new f},{"../math/Quaternion":29,"../math/Vec3":31,"./ConvexPolyhedron":39,"./Shape":44}],41:[function(a,b,c){function d(a,b){b=i.defaults(b,{maxValue:null,minValue:null,elementSize:1}),this.data=a,this.maxValue=b.maxValue,this.minValue=b.minValue,this.elementSize=b.elementSize,null===b.minValue&&this.updateMinValue(),null===b.maxValue&&this.updateMaxValue(),this.cacheEnabled=!0,f.call(this,{type:f.types.HEIGHTFIELD}),this.pillarConvex=new g,this.pillarOffset=new h,this.updateBoundingSphereRadius(),this._cachedPillars={}}function e(a,b,c,d,e,f,g,h,i){i.x=((f-h)*(a-g)+(g-e)*(b-h))/((f-h)*(c-g)+(g-e)*(d-h)),i.y=((h-d)*(a-g)+(c-g)*(b-h))/((f-h)*(c-g)+(g-e)*(d-h)),i.z=1-i.x-i.y}var f=a("./Shape"),g=a("./ConvexPolyhedron"),h=a("../math/Vec3"),i=a("../utils/Utils");b.exports=d,d.prototype=new f,d.prototype.update=function(){this._cachedPillars={}},d.prototype.updateMinValue=function(){for(var a=this.data,b=a[0][0],c=0;c!==a.length;c++)for(var d=0;d!==a[c].length;d++){var e=a[c][d];e<b&&(b=e)}this.minValue=b},d.prototype.updateMaxValue=function(){for(var a=this.data,b=a[0][0],c=0;c!==a.length;c++)for(var d=0;d!==a[c].length;d++){var e=a[c][d];e>b&&(b=e)}this.maxValue=b},d.prototype.setHeightValueAtIndex=function(a,b,c){this.data[a][b]=c,this.clearCachedConvexTrianglePillar(a,b,!1),a>0&&(this.clearCachedConvexTrianglePillar(a-1,b,!0),this.clearCachedConvexTrianglePillar(a-1,b,!1)),b>0&&(this.clearCachedConvexTrianglePillar(a,b-1,!0),this.clearCachedConvexTrianglePillar(a,b-1,!1)),b>0&&a>0&&this.clearCachedConvexTrianglePillar(a-1,b-1,!0)},d.prototype.getRectMinMax=function(a,b,c,d,e){e=e||[];for(var f=this.data,g=this.minValue,h=a;h<=c;h++)for(var i=b;i<=d;i++){var j=f[h][i];j>g&&(g=j)}e[0]=this.minValue,e[1]=g},d.prototype.getIndexOfPosition=function(a,b,c,d){var e=this.elementSize,f=this.data,g=Math.floor(a/e),h=Math.floor(b/e);return c[0]=g,c[1]=h,d&&(g<0&&(g=0),h<0&&(h=0),g>=f.length-1&&(g=f.length-1),h>=f[0].length-1&&(h=f[0].length-1)),!(g<0||h<0||g>=f.length-1||h>=f[0].length-1)};var j=[],k=new h,l=new h,m=new h,n=new h;d.prototype.getTriangleAt=function(a,b,c,d,e,f){var g=j;this.getIndexOfPosition(a,b,g,c);var h=g[0],i=g[1],k=this.data;c&&(h=Math.min(k.length-2,Math.max(0,h)),i=Math.min(k[0].length-2,Math.max(0,i)));var l=this.elementSize,m=Math.pow(a/l-h,2)+Math.pow(b/l-i,2),n=Math.pow(a/l-(h+1),2)+Math.pow(b/l-(i+1),2),o=m>n;return this.getTriangle(h,i,o,d,e,f),o};var o=new h,p=new h,q=new h,r=new h,s=new h;d.prototype.getNormalAt=function(a,b,c,d){var e=o,f=p,g=q,h=r,i=s;this.getTriangleAt(a,b,c,e,f,g),f.vsub(e,h),g.vsub(e,i),h.cross(i,d),d.normalize()},d.prototype.getAabbAtIndex=function(a,b,c){var d=this.data,e=this.elementSize;c.lowerBound.set(a*e,b*e,d[a][b]),c.upperBound.set((a+1)*e,(b+1)*e,d[a+1][b+1])},d.prototype.getHeightAt=function(a,b,c){var d=this.data,f=l,g=m,h=n,i=j;this.getIndexOfPosition(a,b,i,c);var o=i[0],p=i[1];c&&(o=Math.min(d.length-2,Math.max(0,o)),p=Math.min(d[0].length-2,Math.max(0,p)));var q=this.getTriangleAt(a,b,c,f,g,h);e(a,b,f.x,f.y,g.x,g.y,h.x,h.y,k);var r=k;return q?d[o+1][p+1]*r.x+d[o][p+1]*r.y+d[o+1][p]*r.z:d[o][p]*r.x+d[o+1][p]*r.y+d[o][p+1]*r.z},d.prototype.getCacheConvexTrianglePillarKey=function(a,b,c){return a+"_"+b+"_"+(c?1:0)},d.prototype.getCachedConvexTrianglePillar=function(a,b,c){return this._cachedPillars[this.getCacheConvexTrianglePillarKey(a,b,c)]},d.prototype.setCachedConvexTrianglePillar=function(a,b,c,d,e){this._cachedPillars[this.getCacheConvexTrianglePillarKey(a,b,c)]={convex:d,offset:e}},d.prototype.clearCachedConvexTrianglePillar=function(a,b,c){delete this._cachedPillars[this.getCacheConvexTrianglePillarKey(a,b,c)]},d.prototype.getTriangle=function(a,b,c,d,e,f){var g=this.data,h=this.elementSize;c?(d.set((a+1)*h,(b+1)*h,g[a+1][b+1]),e.set(a*h,(b+1)*h,g[a][b+1]),f.set((a+1)*h,b*h,g[a+1][b])):(d.set(a*h,b*h,g[a][b]),e.set((a+1)*h,b*h,g[a+1][b]),f.set(a*h,(b+1)*h,g[a][b+1]))},d.prototype.getConvexTrianglePillar=function(a,b,c){var d=this.pillarConvex,e=this.pillarOffset;if(this.cacheEnabled){var f=this.getCachedConvexTrianglePillar(a,b,c);if(f)return this.pillarConvex=f.convex,void(this.pillarOffset=f.offset);d=new g,e=new h,this.pillarConvex=d,this.pillarOffset=e}var f=this.data,i=this.elementSize,j=d.faces;d.vertices.length=6;for(var k=0;k<6;k++)d.vertices[k]||(d.vertices[k]=new h);j.length=5;for(var k=0;k<5;k++)j[k]||(j[k]=[]);var l=d.vertices,m=(Math.min(f[a][b],f[a+1][b],f[a][b+1],f[a+1][b+1])-this.minValue)/2+this.minValue;c?(e.set((a+.75)*i,(b+.75)*i,m),l[0].set(.25*i,.25*i,f[a+1][b+1]-m),l[1].set(-.75*i,.25*i,f[a][b+1]-m),l[2].set(.25*i,-.75*i,f[a+1][b]-m),l[3].set(.25*i,.25*i,-m-1),l[4].set(-.75*i,.25*i,-m-1),l[5].set(.25*i,-.75*i,-m-1),j[0][0]=0,j[0][1]=1,j[0][2]=2,j[1][0]=5,j[1][1]=4,j[1][2]=3,j[2][0]=2,j[2][1]=5,j[2][2]=3,j[2][3]=0,j[3][0]=3,j[3][1]=4,j[3][2]=1,j[3][3]=0,j[4][0]=1,j[4][1]=4,j[4][2]=5,j[4][3]=2):(e.set((a+.25)*i,(b+.25)*i,m),l[0].set(-.25*i,-.25*i,f[a][b]-m),l[1].set(.75*i,-.25*i,f[a+1][b]-m),l[2].set(-.25*i,.75*i,f[a][b+1]-m),l[3].set(-.25*i,-.25*i,-m-1),l[4].set(.75*i,-.25*i,-m-1),l[5].set(-.25*i,.75*i,-m-1),j[0][0]=0,j[0][1]=1,j[0][2]=2,j[1][0]=5,j[1][1]=4,j[1][2]=3,j[2][0]=0,j[2][1]=2,j[2][2]=5,j[2][3]=3,j[3][0]=1,j[3][1]=0,j[3][2]=3,j[3][3]=4,j[4][0]=4,j[4][1]=5,j[4][2]=2,j[4][3]=1),d.computeNormals(),d.computeEdges(),d.updateBoundingSphereRadius(),this.setCachedConvexTrianglePillar(a,b,c,d,e)},d.prototype.calculateLocalInertia=function(a,b){return b=b||new h,b.set(0,0,0),b},d.prototype.volume=function(){return Number.MAX_VALUE},d.prototype.calculateWorldAABB=function(a,b,c,d){c.set(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE),d.set(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE)},d.prototype.updateBoundingSphereRadius=function(){var a=this.data,b=this.elementSize;this.boundingSphereRadius=new h(a.length*b,a[0].length*b,Math.max(Math.abs(this.maxValue),Math.abs(this.minValue))).norm()},d.prototype.setHeightsFromImage=function(a,b){var c=document.createElement("canvas");c.width=a.width,c.height=a.height;var d=c.getContext("2d");d.drawImage(a,0,0);var e=d.getImageData(0,0,a.width,a.height),f=this.data;f.length=0,this.elementSize=Math.abs(b.x)/e.width;for(var g=0;g<e.height;g++){for(var h=[],i=0;i<e.width;i++){var j=e.data[4*(g*e.height+i)],k=e.data[4*(g*e.height+i)+1],l=e.data[4*(g*e.height+i)+2],m=(j+k+l)/4/255*b.z;b.x<0?h.push(m):h.unshift(m)}b.y<0?f.unshift(h):f.push(h)}this.updateMaxValue(),this.updateMinValue(),this.update()}},{"../math/Vec3":31,"../utils/Utils":54,"./ConvexPolyhedron":39,"./Shape":44}],42:[function(a,b,c){function d(){e.call(this,{type:e.types.PARTICLE})}b.exports=d;var e=a("./Shape"),f=a("../math/Vec3");d.prototype=new e,d.prototype.constructor=d,d.prototype.calculateLocalInertia=function(a,b){return b=b||new f,b.set(0,0,0),b},d.prototype.volume=function(){return 0},d.prototype.updateBoundingSphereRadius=function(){this.boundingSphereRadius=0},d.prototype.calculateWorldAABB=function(a,b,c,d){c.copy(a),d.copy(a)}},{"../math/Vec3":31,"./Shape":44}],43:[function(a,b,c){function d(){e.call(this,{type:e.types.PLANE}),this.worldNormal=new f,this.worldNormalNeedsUpdate=!0,this.boundingSphereRadius=Number.MAX_VALUE}b.exports=d;var e=a("./Shape"),f=a("../math/Vec3");d.prototype=new e,d.prototype.constructor=d,d.prototype.computeWorldNormal=function(a){var b=this.worldNormal;b.set(0,0,1),a.vmult(b,b),this.worldNormalNeedsUpdate=!1},d.prototype.calculateLocalInertia=function(a,b){return b=b||new f},d.prototype.volume=function(){return Number.MAX_VALUE};var g=new f;d.prototype.calculateWorldAABB=function(a,b,c,d){g.set(0,0,1),b.vmult(g,g);var e=Number.MAX_VALUE;c.set(-e,-e,-e),d.set(e,e,e),1===g.x&&(d.x=a.x),1===g.y&&(d.y=a.y),1===g.z&&(d.z=a.z),-1===g.x&&(c.x=a.x),-1===g.y&&(c.y=a.y),-1===g.z&&(c.z=a.z)},d.prototype.updateBoundingSphereRadius=function(){this.boundingSphereRadius=Number.MAX_VALUE}},{"../math/Vec3":31,"./Shape":44}],44:[function(a,b,c){function d(a){a=a||{},this.id=d.idCounter++,this.type=a.type||0,this.boundingSphereRadius=0,this.collisionResponse=!a.collisionResponse||a.collisionResponse,this.collisionFilterGroup=void 0!==a.collisionFilterGroup?a.collisionFilterGroup:1,this.collisionFilterMask=void 0!==a.collisionFilterMask?a.collisionFilterMask:-1,this.material=a.material?a.material:null,this.body=null}b.exports=d;var d=a("./Shape");a("../math/Vec3"),a("../math/Quaternion"),a("../material/Material");d.prototype.constructor=d,d.prototype.updateBoundingSphereRadius=function(){throw"computeBoundingSphereRadius() not implemented for shape type "+this.type},d.prototype.volume=function(){throw"volume() not implemented for shape type "+this.type},d.prototype.calculateLocalInertia=function(a,b){throw"calculateLocalInertia() not implemented for shape type "+this.type},d.idCounter=0,d.types={SPHERE:1,PLANE:2,BOX:4,COMPOUND:8,CONVEXPOLYHEDRON:16,HEIGHTFIELD:32,PARTICLE:64,CYLINDER:128,TRIMESH:256}},{"../material/Material":26,"../math/Quaternion":29,"../math/Vec3":31,"./Shape":44}],45:[function(a,b,c){function d(a){if(e.call(this,{type:e.types.SPHERE}),this.radius=void 0!==a?a:1,this.radius<0)throw new Error("The sphere radius cannot be negative.");this.updateBoundingSphereRadius()}b.exports=d;var e=a("./Shape"),f=a("../math/Vec3");d.prototype=new e,d.prototype.constructor=d,d.prototype.calculateLocalInertia=function(a,b){b=b||new f;var c=2*a*this.radius*this.radius/5;return b.x=c,b.y=c,b.z=c,b},d.prototype.volume=function(){return 4*Math.PI*this.radius/3},d.prototype.updateBoundingSphereRadius=function(){this.boundingSphereRadius=this.radius},d.prototype.calculateWorldAABB=function(a,b,c,d){for(var e=this.radius,f=["x","y","z"],g=0;g<f.length;g++){var h=f[g];c[h]=a[h]-e,d[h]=a[h]+e}}},{"../math/Vec3":31,"./Shape":44}],46:[function(a,b,c){function d(a,b){e.call(this,{type:e.types.TRIMESH}),this.vertices=new Float32Array(a),this.indices=new Int16Array(b),this.normals=new Float32Array(b.length),this.aabb=new h,this.edges=null,this.scale=new f(1,1,1),this.tree=new i,this.updateEdges(),this.updateNormals(),this.updateAABB(),this.updateBoundingSphereRadius(),this.updateTree()}b.exports=d;var e=a("./Shape"),f=a("../math/Vec3"),g=(a("../math/Quaternion"),a("../math/Transform")),h=a("../collision/AABB"),i=a("../utils/Octree");d.prototype=new e,d.prototype.constructor=d;var j=new f;d.prototype.updateTree=function(){var a=this.tree;a.reset(),a.aabb.copy(this.aabb);var b=this.scale;a.aabb.lowerBound.x*=1/b.x,a.aabb.lowerBound.y*=1/b.y,a.aabb.lowerBound.z*=1/b.z,a.aabb.upperBound.x*=1/b.x,a.aabb.upperBound.y*=1/b.y,a.aabb.upperBound.z*=1/b.z;for(var c=new h,d=new f,e=new f,g=new f,i=[d,e,g],j=0;j<this.indices.length/3;j++){var k=3*j;this._getUnscaledVertex(this.indices[k],d),this._getUnscaledVertex(this.indices[k+1],e),this._getUnscaledVertex(this.indices[k+2],g),c.setFromPoints(i),a.insert(c,j)}a.removeEmptyNodes()};var k=new h;d.prototype.getTrianglesInAABB=function(a,b){k.copy(a);var c=this.scale,d=c.x,e=c.y,f=c.z,g=k.lowerBound,h=k.upperBound;return g.x/=d,g.y/=e,g.z/=f,h.x/=d,h.y/=e,h.z/=f,this.tree.aabbQuery(k,b)},d.prototype.setScale=function(a){var b=this.scale.x===this.scale.y===this.scale.z,c=a.x===a.y===a.z;b&&c||this.updateNormals(),this.scale.copy(a),this.updateAABB(),this.updateBoundingSphereRadius()},d.prototype.updateNormals=function(){for(var a=j,b=this.normals,c=0;c<this.indices.length/3;c++){var e=3*c,f=this.indices[e],g=this.indices[e+1],h=this.indices[e+2];this.getVertex(f,p),this.getVertex(g,q),this.getVertex(h,r),d.computeNormal(q,p,r,a),b[e]=a.x,b[e+1]=a.y,b[e+2]=a.z}},d.prototype.updateEdges=function(){for(var a={},b=function(b,c){a[e<f?e+"_"+f:f+"_"+e]=!0},c=0;c<this.indices.length/3;c++){var d=3*c,e=this.indices[d],f=this.indices[d+1],g=this.indices[d+2];b(e,f),b(f,g),b(g,e)}var h=Object.keys(a);this.edges=new Int16Array(2*h.length);for(var c=0;c<h.length;c++){var i=h[c].split("_");this.edges[2*c]=parseInt(i[0],10),this.edges[2*c+1]=parseInt(i[1],10)}},d.prototype.getEdgeVertex=function(a,b,c){var d=this.edges[2*a+(b?1:0)];this.getVertex(d,c)};var l=new f,m=new f;d.prototype.getEdgeVector=function(a,b){var c=l,d=m;this.getEdgeVertex(a,0,c),this.getEdgeVertex(a,1,d),d.vsub(c,b)};var n=new f,o=new f;d.computeNormal=function(a,b,c,d){b.vsub(a,o),c.vsub(b,n),n.cross(o,d),d.isZero()||d.normalize()};var p=new f,q=new f,r=new f;d.prototype.getVertex=function(a,b){var c=this.scale;return this._getUnscaledVertex(a,b),b.x*=c.x,b.y*=c.y,b.z*=c.z,b},d.prototype._getUnscaledVertex=function(a,b){var c=3*a,d=this.vertices;return b.set(d[c],d[c+1],d[c+2])},d.prototype.getWorldVertex=function(a,b,c,d){return this.getVertex(a,d),g.pointToWorldFrame(b,c,d,d),d},d.prototype.getTriangleVertices=function(a,b,c,d){var e=3*a;this.getVertex(this.indices[e],b),this.getVertex(this.indices[e+1],c),this.getVertex(this.indices[e+2],d)},d.prototype.getNormal=function(a,b){var c=3*a;return b.set(this.normals[c],this.normals[c+1],this.normals[c+2])};var s=new h;d.prototype.calculateLocalInertia=function(a,b){this.computeLocalAABB(s);var c=s.upperBound.x-s.lowerBound.x,d=s.upperBound.y-s.lowerBound.y,e=s.upperBound.z-s.lowerBound.z;return b.set(1/12*a*(2*d*2*d+2*e*2*e),1/12*a*(2*c*2*c+2*e*2*e),1/12*a*(2*d*2*d+2*c*2*c))};var t=new f;d.prototype.computeLocalAABB=function(a){var b=a.lowerBound,c=a.upperBound,d=this.vertices.length,e=(this.vertices,t);this.getVertex(0,e),b.copy(e),c.copy(e);for(var f=0;f!==d;f++)this.getVertex(f,e),e.x<b.x?b.x=e.x:e.x>c.x&&(c.x=e.x),e.y<b.y?b.y=e.y:e.y>c.y&&(c.y=e.y),e.z<b.z?b.z=e.z:e.z>c.z&&(c.z=e.z)},d.prototype.updateAABB=function(){this.computeLocalAABB(this.aabb)},d.prototype.updateBoundingSphereRadius=function(){for(var a=0,b=this.vertices,c=new f,d=0,e=b.length/3;d!==e;d++){this.getVertex(d,c);var g=c.norm2();g>a&&(a=g)}this.boundingSphereRadius=Math.sqrt(a)};var u=(new f,new g),v=new h;d.prototype.calculateWorldAABB=function(a,b,c,d){var e=u,f=v;e.position=a,e.quaternion=b,this.aabb.toWorldFrame(e,f),c.copy(f.lowerBound),d.copy(f.upperBound)},d.prototype.volume=function(){return 4*Math.PI*this.boundingSphereRadius/3},d.createTorus=function(a,b,c,e,f){a=a||1,b=b||.5,c=c||8,e=e||6,f=f||2*Math.PI;for(var g=[],h=[],i=0;i<=c;i++)for(var j=0;j<=e;j++){var k=j/e*f,l=i/c*Math.PI*2,m=(a+b*Math.cos(l))*Math.cos(k),n=(a+b*Math.cos(l))*Math.sin(k),o=b*Math.sin(l);g.push(m,n,o)}for(var i=1;i<=c;i++)for(var j=1;j<=e;j++){var p=(e+1)*i+j-1,q=(e+1)*(i-1)+j-1,r=(e+1)*(i-1)+j,s=(e+1)*i+j;h.push(p,q,s),h.push(q,r,s)}return new d(g,h)}},{"../collision/AABB":3,"../math/Quaternion":29,"../math/Transform":30,"../math/Vec3":31,"../utils/Octree":51,"./Shape":44}],47:[function(a,b,c){function d(){e.call(this),this.iterations=10,this.tolerance=1e-7}b.exports=d;var e=(a("../math/Vec3"),a("../math/Quaternion"),a("./Solver"));d.prototype=new e;var f=[],g=[],h=[];d.prototype.solve=function(a,b){var c,d,e,i,j,k,l=0,m=this.iterations,n=this.tolerance*this.tolerance,o=this.equations,p=o.length,q=b.bodies,r=q.length,s=a;if(0!==p)for(var t=0;t!==r;t++)q[t].updateSolveMassProperties();var u=g,v=h,w=f;u.length=p,v.length=p,w.length=p;for(var t=0;t!==p;t++){var x=o[t];w[t]=0,v[t]=x.computeB(s),u[t]=1/x.computeC()}if(0!==p){for(var t=0;t!==r;t++){var y=q[t],z=y.vlambda,A=y.wlambda;z.set(0,0,0),A.set(0,0,0)}for(l=0;l!==m;l++){i=0;for(var B=0;B!==p;B++){var x=o[B];c=v[B],d=u[B],k=w[B],j=x.computeGWlambda(),e=d*(c-j-x.eps*k),k+e<x.minForce?e=x.minForce-k:k+e>x.maxForce&&(e=x.maxForce-k),w[B]+=e,i+=e>0?e:-e,x.addToWlambda(e)}if(i*i<n)break}for(var t=0;t!==r;t++){var y=q[t],C=y.velocity,D=y.angularVelocity;y.vlambda.vmul(y.linearFactor,y.vlambda),C.vadd(y.vlambda,C),y.wlambda.vmul(y.angularFactor,y.wlambda),D.vadd(y.wlambda,D)}for(var E=o.length,F=1/s;E--;)o[E].multiplier=w[E]*F}return l}},{"../math/Quaternion":29,"../math/Vec3":31,"./Solver":48}],48:[function(a,b,c){function d(){this.equations=[]}b.exports=d,d.prototype.solve=function(a,b){return 0},d.prototype.addEquation=function(a){a.enabled&&this.equations.push(a)},d.prototype.removeEquation=function(a){var b=this.equations,c=b.indexOf(a);-1!==c&&b.splice(c,1)},d.prototype.removeAllEquations=function(){this.equations.length=0}},{}],49:[function(a,b,c){function d(a){for(i.call(this),this.iterations=10,this.tolerance=1e-7,this.subsolver=a,this.nodes=[],this.nodePool=[];this.nodePool.length<128;)this.nodePool.push(this.createNode())}function e(a){for(var b=a.length,c=0;c!==b;c++){var d=a[c];if(!(d.visited||d.body.type&n))return d}return!1}function f(a,b,c,d){for(o.push(a),a.visited=!0,b(a,c,d);o.length;)for(var f,g=o.pop();f=e(g.children);)f.visited=!0,b(f,c,d),o.push(f)}function g(a,b,c){b.push(a.body);for(var d=a.eqs.length,e=0;e!==d;e++){var f=a.eqs[e];-1===c.indexOf(f)&&c.push(f)}}function h(a,b){return b.id-a.id}b.exports=d;var i=(a("../math/Vec3"),a("../math/Quaternion"),a("./Solver")),j=a("../objects/Body");d.prototype=new i;var k=[],l=[],m={bodies:[]},n=j.STATIC,o=[];d.prototype.createNode=function(){return{body:null,children:[],eqs:[],visited:!1}},d.prototype.solve=function(a,b){for(var c=k,d=this.nodePool,i=b.bodies,j=this.equations,n=j.length,o=i.length,p=this.subsolver;d.length<o;)d.push(this.createNode());c.length=o;for(var q=0;q<o;q++)c[q]=d[q];for(var q=0;q!==o;q++){var r=c[q];r.body=i[q],r.children.length=0,r.eqs.length=0,r.visited=!1}for(var s=0;s!==n;s++){var t=j[s],q=i.indexOf(t.bi),u=i.indexOf(t.bj),v=c[q],w=c[u];v.children.push(w),v.eqs.push(t),w.children.push(v),w.eqs.push(t)}var x,y=0,z=l;p.tolerance=this.tolerance,p.iterations=this.iterations;for(var A=m;x=e(c);){z.length=0,A.bodies.length=0,f(x,g,A.bodies,z);var B=z.length;z=z.sort(h);for(var q=0;q!==B;q++)p.addEquation(z[q]);p.solve(a,A);p.removeAllEquations(),y++}return y}},{"../math/Quaternion":29,"../math/Vec3":31,"../objects/Body":32,"./Solver":48}],50:[function(a,b,c){var d=function(){};b.exports=d,d.prototype={constructor:d,addEventListener:function(a,b){void 0===this._listeners&&(this._listeners={});var c=this._listeners;return void 0===c[a]&&(c[a]=[]),-1===c[a].indexOf(b)&&c[a].push(b),this},hasEventListener:function(a,b){if(void 0===this._listeners)return!1;var c=this._listeners;return void 0!==c[a]&&-1!==c[a].indexOf(b)},hasAnyEventListener:function(a){return void 0!==this._listeners&&void 0!==this._listeners[a]},removeEventListener:function(a,b){if(void 0===this._listeners)return this;var c=this._listeners;if(void 0===c[a])return this;var d=c[a].indexOf(b);return-1!==d&&c[a].splice(d,1),this},dispatchEvent:function(a){if(void 0===this._listeners)return this;var b=this._listeners,c=b[a.type];if(void 0!==c){a.target=this;for(var d=0,e=c.length;d<e;d++)c[d].call(this,a)}return this}}},{}],51:[function(a,b,c){function d(a){a=a||{},this.root=a.root||null,this.aabb=a.aabb?a.aabb.clone():new f,this.data=[],this.children=[]}function e(a,b){b=b||{},b.root=null,b.aabb=a,d.call(this,b),this.maxDepth=void 0!==b.maxDepth?b.maxDepth:8}var f=a("../collision/AABB"),g=a("../math/Vec3");b.exports=e,e.prototype=new d,d.prototype.reset=function(a,b){this.children.length=this.data.length=0},d.prototype.insert=function(a,b,c){var d=this.data;if(c=c||0,!this.aabb.contains(a))return!1;var e=this.children;if(c<(this.maxDepth||this.root.maxDepth)){var f=!1;e.length||(this.subdivide(),f=!0);for(var g=0;8!==g;g++)if(e[g].insert(a,b,c+1))return!0;f&&(e.length=0)}return d.push(b),!0};var h=new g;d.prototype.subdivide=function(){var a=this.aabb,b=a.lowerBound,c=a.upperBound,e=this.children;e.push(new d({aabb:new f({lowerBound:new g(0,0,0)})}),new d({aabb:new f({lowerBound:new g(1,0,0)})}),new d({aabb:new f({lowerBound:new g(1,1,0)})}),new d({aabb:new f({lowerBound:new g(1,1,1)})}),new d({aabb:new f({lowerBound:new g(0,1,1)})}),new d({aabb:new f({lowerBound:new g(0,0,1)})}),new d({aabb:new f({lowerBound:new g(1,0,1)})}),new d({aabb:new f({lowerBound:new g(0,1,0)})})),c.vsub(b,h),h.scale(.5,h);for(var i=this.root||this,j=0;8!==j;j++){var k=e[j];k.root=i;var l=k.aabb.lowerBound;l.x*=h.x,l.y*=h.y,l.z*=h.z,l.vadd(b,l),l.vadd(h,k.aabb.upperBound)}},d.prototype.aabbQuery=function(a,b){for(var c=(this.data,this.children,[this]);c.length;){var d=c.pop();d.aabb.overlaps(a)&&Array.prototype.push.apply(b,d.data),Array.prototype.push.apply(c,d.children)}return b};var i=new f;d.prototype.rayQuery=function(a,b,c){return a.getAABB(i),i.toLocalFrame(b,i),this.aabbQuery(i,c),c},d.prototype.removeEmptyNodes=function(){for(var a=[this];a.length;){for(var b=a.pop(),c=b.children.length-1;c>=0;c--)b.children[c].data.length||b.children.splice(c,1);Array.prototype.push.apply(a,b.children)}}},{"../collision/AABB":3,"../math/Vec3":31}],52:[function(a,b,c){function d(){this.objects=[],this.type=Object}b.exports=d,d.prototype.release=function(){for(var a=arguments.length,b=0;b!==a;b++)this.objects.push(arguments[b]);return this},d.prototype.get=function(){return 0===this.objects.length?this.constructObject():this.objects.pop()},d.prototype.constructObject=function(){throw new Error("constructObject() not implemented in this Pool subclass yet!")},d.prototype.resize=function(a){for(var b=this.objects;b.length>a;)b.pop();for(;b.length<a;)b.push(this.constructObject());return this}},{}],53:[function(a,b,c){function d(){this.data={keys:[]}}b.exports=d,d.prototype.get=function(a,b){if(a>b){var c=b;b=a,a=c}return this.data[a+"-"+b]},d.prototype.set=function(a,b,c){if(a>b){var d=b;b=a,a=d}var e=a+"-"+b;this.get(a,b)||this.data.keys.push(e),this.data[e]=c},d.prototype.reset=function(){for(var a=this.data,b=a.keys;b.length>0;){delete a[b.pop()]}}},{}],54:[function(a,b,c){function d(){}b.exports=d,d.defaults=function(a,b){a=a||{};for(var c in b)c in a||(a[c]=b[c]);return a}},{}],55:[function(a,b,c){function d(){f.call(this),this.type=e}b.exports=d;var e=a("../math/Vec3"),f=a("./Pool");d.prototype=new f,d.prototype.constructObject=function(){return new e}},{"../math/Vec3":31,"./Pool":52}],56:[function(a,b,c){function d(a){this.contactPointPool=[],this.frictionEquationPool=[],this.result=[],this.frictionResult=[],this.v3pool=new m,this.world=a,this.currentContactMaterial=null,this.enableFrictionReduction=!1}function e(a,b,c){for(var d=null,e=a.length,f=0;f!==e;f++){var g=a[f],h=Q;a[(f+1)%e].vsub(g,h);var i=R;h.cross(b,i);var j=S;c.vsub(g,j);var k=i.dot(j);if(!(null===d||k>0&&!0===d||k<=0&&!1===d))return!1;null===d&&(d=k>0)}return!0}b.exports=d;var f=a("../collision/AABB"),g=a("../objects/Body"),h=a("../shapes/Shape"),i=a("../collision/Ray"),j=a("../math/Vec3"),k=a("../math/Transform"),l=(a("../shapes/ConvexPolyhedron"),a("../math/Quaternion")),m=(a("../solver/Solver"),a("../utils/Vec3Pool")),n=a("../equations/ContactEquation"),o=a("../equations/FrictionEquation");d.prototype.createContactEquation=function(a,b,c,d,e,f){var g;this.contactPointPool.length?(g=this.contactPointPool.pop(),g.bi=a,g.bj=b):g=new n(a,b),g.enabled=a.collisionResponse&&b.collisionResponse&&c.collisionResponse&&d.collisionResponse;var h=this.currentContactMaterial;g.restitution=h.restitution,g.setSpookParams(h.contactEquationStiffness,h.contactEquationRelaxation,this.world.dt);var i=c.material||a.material,j=d.material||b.material;return i&&j&&i.restitution>=0&&j.restitution>=0&&(g.restitution=i.restitution*j.restitution),g.si=e||c,g.sj=f||d,g},d.prototype.createFrictionEquationsFromContact=function(a,b){var c=a.bi,d=a.bj,e=a.si,f=a.sj,g=this.world,h=this.currentContactMaterial,i=h.friction,j=e.material||c.material,k=f.material||d.material;if(j&&k&&j.friction>=0&&k.friction>=0&&(i=j.friction*k.friction),i>0){var l=i*g.gravity.length(),m=c.invMass+d.invMass;m>0&&(m=1/m);var n=this.frictionEquationPool,p=n.length?n.pop():new o(c,d,l*m),q=n.length?n.pop():new o(c,d,l*m);return p.bi=q.bi=c,p.bj=q.bj=d,p.minForce=q.minForce=-l*m,p.maxForce=q.maxForce=l*m,p.ri.copy(a.ri),p.rj.copy(a.rj),q.ri.copy(a.ri),q.rj.copy(a.rj),a.ni.tangents(p.t,q.t),p.setSpookParams(h.frictionEquationStiffness,h.frictionEquationRelaxation,g.dt),q.setSpookParams(h.frictionEquationStiffness,h.frictionEquationRelaxation,g.dt),p.enabled=q.enabled=a.enabled,b.push(p,q),!0}return!1};var p=new j,q=new j,r=new j;d.prototype.createFrictionFromAverage=function(a){var b=this.result[this.result.length-1];if(this.createFrictionEquationsFromContact(b,this.frictionResult)&&1!==a){var c=this.frictionResult[this.frictionResult.length-2],d=this.frictionResult[this.frictionResult.length-1];p.setZero(),q.setZero(),r.setZero();for(var e=b.bi,f=(b.bj,0);f!==a;f++)b=this.result[this.result.length-1-f],b.bodyA!==e?(p.vadd(b.ni,p),q.vadd(b.ri,q),r.vadd(b.rj,r)):(p.vsub(b.ni,p),q.vadd(b.rj,q),r.vadd(b.ri,r));var g=1/a;q.scale(g,c.ri),r.scale(g,c.rj),d.ri.copy(c.ri),d.rj.copy(c.rj),p.normalize(),p.tangents(c.t,d.t)}};var s=new j,t=new j,u=new l,v=new l;d.prototype.getContacts=function(a,b,c,d,e,f,h){this.contactPointPool=e,this.frictionEquationPool=h,this.result=d,this.frictionResult=f;for(var i=u,j=v,k=s,l=t,m=0,n=a.length;m!==n;m++){var o=a[m],p=b[m],q=null;o.material&&p.material&&(q=c.getContactMaterial(o.material,p.material)||null);for(var r=o.type&g.KINEMATIC&&p.type&g.STATIC||o.type&g.STATIC&&p.type&g.KINEMATIC||o.type&g.KINEMATIC&&p.type&g.KINEMATIC,w=0;w<o.shapes.length;w++){o.quaternion.mult(o.shapeOrientations[w],i),o.quaternion.vmult(o.shapeOffsets[w],k),k.vadd(o.position,k);for(var x=o.shapes[w],y=0;y<p.shapes.length;y++){p.quaternion.mult(p.shapeOrientations[y],j),p.quaternion.vmult(p.shapeOffsets[y],l),l.vadd(p.position,l);var z=p.shapes[y];if(x.collisionFilterMask&z.collisionFilterGroup&&z.collisionFilterMask&x.collisionFilterGroup&&!(k.distanceTo(l)>x.boundingSphereRadius+z.boundingSphereRadius)){var A=null;x.material&&z.material&&(A=c.getContactMaterial(x.material,z.material)||null),this.currentContactMaterial=A||q||c.defaultContactMaterial;var B=this[x.type|z.type];if(B){var C=!1;C=x.type<z.type?B.call(this,x,z,k,l,i,j,o,p,x,z,r):B.call(this,z,x,l,k,j,i,p,o,x,z,r),C&&r&&(c.shapeOverlapKeeper.set(x.id,z.id),c.bodyOverlapKeeper.set(o.id,p.id))}}}}}};d.prototype[h.types.BOX|h.types.BOX]=d.prototype.boxBox=function(a,b,c,d,e,f,g,h,i,j,k){return a.convexPolyhedronRepresentation.material=a.material,b.convexPolyhedronRepresentation.material=b.material,a.convexPolyhedronRepresentation.collisionResponse=a.collisionResponse,b.convexPolyhedronRepresentation.collisionResponse=b.collisionResponse,this.convexConvex(a.convexPolyhedronRepresentation,b.convexPolyhedronRepresentation,c,d,e,f,g,h,a,b,k)},d.prototype[h.types.BOX|h.types.CONVEXPOLYHEDRON]=d.prototype.boxConvex=function(a,b,c,d,e,f,g,h,i,j,k){return a.convexPolyhedronRepresentation.material=a.material,a.convexPolyhedronRepresentation.collisionResponse=a.collisionResponse,this.convexConvex(a.convexPolyhedronRepresentation,b,c,d,e,f,g,h,a,b,k)},d.prototype[h.types.BOX|h.types.PARTICLE]=d.prototype.boxParticle=function(a,b,c,d,e,f,g,h,i,j,k){return a.convexPolyhedronRepresentation.material=a.material,a.convexPolyhedronRepresentation.collisionResponse=a.collisionResponse,this.convexParticle(a.convexPolyhedronRepresentation,b,c,d,e,f,g,h,a,b,k)},d.prototype[h.types.SPHERE]=d.prototype.sphereSphere=function(a,b,c,d,e,f,g,h,i,j,k){if(k)return c.distanceSquared(d)<Math.pow(a.radius+b.radius,2);var l=this.createContactEquation(g,h,a,b,i,j);d.vsub(c,l.ni),l.ni.normalize(),l.ri.copy(l.ni),l.rj.copy(l.ni),l.ri.mult(a.radius,l.ri),l.rj.mult(-b.radius,l.rj),l.ri.vadd(c,l.ri),l.ri.vsub(g.position,l.ri),l.rj.vadd(d,l.rj),l.rj.vsub(h.position,l.rj),this.result.push(l),this.createFrictionEquationsFromContact(l,this.frictionResult)};var w=new j,x=new j,y=new j;d.prototype[h.types.PLANE|h.types.TRIMESH]=d.prototype.planeTrimesh=function(a,b,c,d,e,f,g,h,i,l,m){var n=new j,o=w;o.set(0,0,1),e.vmult(o,o);for(var p=0;p<b.vertices.length/3;p++){b.getVertex(p,n);var q=new j;q.copy(n),k.pointToWorldFrame(d,f,q,n);var r=x;n.vsub(c,r);if(o.dot(r)<=0){if(m)return!0;var s=this.createContactEquation(g,h,a,b,i,l);s.ni.copy(o);var t=y;o.scale(r.dot(o),t),n.vsub(t,t),s.ri.copy(t),s.ri.vsub(g.position,s.ri),s.rj.copy(n),s.rj.vsub(h.position,s.rj),this.result.push(s),this.createFrictionEquationsFromContact(s,this.frictionResult)}}};var z=new j,A=new j,B=(new j,new j),C=new j,D=new j,E=new j,F=new j,G=new j,H=new j,I=new j,J=new j,K=new j,L=new j,M=new f,N=[];d.prototype[h.types.SPHERE|h.types.TRIMESH]=d.prototype.sphereTrimesh=function(a,b,c,d,e,f,g,h,j,l,m){var n=D,o=E,p=F,q=G,r=H,s=I,t=M,u=C,v=A,w=N;k.pointToLocalFrame(d,f,c,r);var x=a.radius;t.lowerBound.set(r.x-x,r.y-x,r.z-x),t.upperBound.set(r.x+x,r.y+x,r.z+x),b.getTrianglesInAABB(t,w);for(var y=B,O=a.radius*a.radius,P=0;P<w.length;P++)for(var Q=0;Q<3;Q++)if(b.getVertex(b.indices[3*w[P]+Q],y),y.vsub(r,v),v.norm2()<=O){if(u.copy(y),k.pointToWorldFrame(d,f,u,y),y.vsub(c,v),m)return!0;var R=this.createContactEquation(g,h,a,b,j,l);R.ni.copy(v),R.ni.normalize(),R.ri.copy(R.ni),R.ri.scale(a.radius,R.ri),R.ri.vadd(c,R.ri),R.ri.vsub(g.position,R.ri),R.rj.copy(y),R.rj.vsub(h.position,R.rj),this.result.push(R),this.createFrictionEquationsFromContact(R,this.frictionResult)}for(var P=0;P<w.length;P++)for(var Q=0;Q<3;Q++){b.getVertex(b.indices[3*w[P]+Q],n),b.getVertex(b.indices[3*w[P]+(Q+1)%3],o),o.vsub(n,p),r.vsub(o,s);var S=s.dot(p);r.vsub(n,s);var T=s.dot(p);if(T>0&&S<0){r.vsub(n,s),q.copy(p),q.normalize(),T=s.dot(q),q.scale(T,s),s.vadd(n,s);var U=s.distanceTo(r);if(U<a.radius){if(m)return!0;var R=this.createContactEquation(g,h,a,b,j,l);s.vsub(r,R.ni),R.ni.normalize(),R.ni.scale(a.radius,R.ri),k.pointToWorldFrame(d,f,s,s),s.vsub(h.position,R.rj),k.vectorToWorldFrame(f,R.ni,R.ni),k.vectorToWorldFrame(f,R.ri,R.ri),this.result.push(R),this.createFrictionEquationsFromContact(R,this.frictionResult)}}}for(var V=J,W=K,X=L,Y=z,P=0,Z=w.length;P!==Z;P++){b.getTriangleVertices(w[P],V,W,X),b.getNormal(w[P],Y),r.vsub(V,s);var U=s.dot(Y);if(Y.scale(U,s),r.vsub(s,s),U=s.distanceTo(r),i.pointInTriangle(s,V,W,X)&&U<a.radius){if(m)return!0;var R=this.createContactEquation(g,h,a,b,j,l);s.vsub(r,R.ni),R.ni.normalize(),R.ni.scale(a.radius,R.ri),k.pointToWorldFrame(d,f,s,s),s.vsub(h.position,R.rj),k.vectorToWorldFrame(f,R.ni,R.ni),k.vectorToWorldFrame(f,R.ri,R.ri),this.result.push(R),this.createFrictionEquationsFromContact(R,this.frictionResult)}}w.length=0};var O=new j,P=new j;d.prototype[h.types.SPHERE|h.types.PLANE]=d.prototype.spherePlane=function(a,b,c,d,e,f,g,h,i,j,k){var l=this.createContactEquation(g,h,a,b,i,j);if(l.ni.set(0,0,1),f.vmult(l.ni,l.ni),l.ni.negate(l.ni),l.ni.normalize(),l.ni.mult(a.radius,l.ri),c.vsub(d,O),l.ni.mult(l.ni.dot(O),P),O.vsub(P,l.rj),-O.dot(l.ni)<=a.radius){if(k)return!0;var m=l.ri,n=l.rj;m.vadd(c,m),m.vsub(g.position,m),n.vadd(d,n),n.vsub(h.position,n),this.result.push(l),this.createFrictionEquationsFromContact(l,this.frictionResult)}};var Q=new j,R=new j,S=new j,T=new j,U=new j,V=new j,W=new j,X=[new j,new j,new j,new j,new j,new j],Y=new j,Z=new j,$=new j,_=new j;d.prototype[h.types.SPHERE|h.types.BOX]=d.prototype.sphereBox=function(a,b,c,d,e,f,g,h,i,j,k){var l=this.v3pool,m=X;c.vsub(d,T),b.getSideNormals(m,f);for(var n=a.radius,o=!1,p=Z,q=$,r=_,s=null,t=0,u=0,v=0,w=null,x=0,y=m.length;x!==y&&!1===o;x++){var z=U;z.copy(m[x]);var A=z.norm();z.normalize();var B=T.dot(z);if(B<A+n&&B>0){var C=V,D=W;C.copy(m[(x+1)%3]),D.copy(m[(x+2)%3]);var E=C.norm(),F=D.norm();C.normalize(),D.normalize();var G=T.dot(C),H=T.dot(D);if(G<E&&G>-E&&H<F&&H>-F){var I=Math.abs(B-A-n);if((null===w||I<w)&&(w=I,u=G,v=H,s=A,p.copy(z),q.copy(C),r.copy(D),t++,k))return!0}}}if(t){o=!0;var J=this.createContactEquation(g,h,a,b,i,j);p.mult(-n,J.ri),J.ni.copy(p),J.ni.negate(J.ni),p.mult(s,p),q.mult(u,q),p.vadd(q,p),r.mult(v,r),p.vadd(r,J.rj),J.ri.vadd(c,J.ri),J.ri.vsub(g.position,J.ri),J.rj.vadd(d,J.rj),J.rj.vsub(h.position,J.rj),this.result.push(J),this.createFrictionEquationsFromContact(J,this.frictionResult)}for(var K=l.get(),L=Y,M=0;2!==M&&!o;M++)for(var N=0;2!==N&&!o;N++)for(var O=0;2!==O&&!o;O++)if(K.set(0,0,0),M?K.vadd(m[0],K):K.vsub(m[0],K),N?K.vadd(m[1],K):K.vsub(m[1],K),O?K.vadd(m[2],K):K.vsub(m[2],K),d.vadd(K,L),L.vsub(c,L),L.norm2()<n*n){if(k)return!0;o=!0;var J=this.createContactEquation(g,h,a,b,i,j);J.ri.copy(L),J.ri.normalize(),J.ni.copy(J.ri),J.ri.mult(n,J.ri),J.rj.copy(K),J.ri.vadd(c,J.ri),J.ri.vsub(g.position,J.ri),J.rj.vadd(d,J.rj),J.rj.vsub(h.position,J.rj),this.result.push(J),this.createFrictionEquationsFromContact(J,this.frictionResult)}l.release(K),K=null;for(var P=l.get(),Q=l.get(),J=l.get(),R=l.get(),I=l.get(),S=m.length,M=0;M!==S&&!o;M++)for(var N=0;N!==S&&!o;N++)if(M%3!=N%3){m[N].cross(m[M],P),P.normalize(),m[M].vadd(m[N],Q),J.copy(c),J.vsub(Q,J),J.vsub(d,J);var aa=J.dot(P);P.mult(aa,R);for(var O=0;O===M%3||O===N%3;)O++;I.copy(c),I.vsub(R,I),I.vsub(Q,I),I.vsub(d,I);var ba=Math.abs(aa),ca=I.norm();if(ba<m[O].norm()&&ca<n){if(k)return!0;o=!0;var da=this.createContactEquation(g,h,a,b,i,j);Q.vadd(R,da.rj),da.rj.copy(da.rj),I.negate(da.ni),da.ni.normalize(),da.ri.copy(da.rj),da.ri.vadd(d,da.ri),da.ri.vsub(c,da.ri),da.ri.normalize(),da.ri.mult(n,da.ri),da.ri.vadd(c,da.ri),da.ri.vsub(g.position,da.ri),da.rj.vadd(d,da.rj),da.rj.vsub(h.position,da.rj),this.result.push(da),this.createFrictionEquationsFromContact(da,this.frictionResult)}}l.release(P,Q,J,R,I)};var aa=new j,ba=new j,ca=new j,da=new j,ea=new j,fa=new j,ga=new j,ha=new j,ia=new j,ja=new j;d.prototype[h.types.SPHERE|h.types.CONVEXPOLYHEDRON]=d.prototype.sphereConvex=function(a,b,c,d,f,g,h,i,j,k,l){var m=this.v3pool;c.vsub(d,aa);for(var n=b.faceNormals,o=b.faces,p=b.vertices,q=a.radius,r=0;r!==p.length;r++){var s=p[r],t=ea;g.vmult(s,t),d.vadd(t,t);var u=da;if(t.vsub(c,u),u.norm2()<q*q){if(l)return!0;w=!0;var v=this.createContactEquation(h,i,a,b,j,k);return v.ri.copy(u),v.ri.normalize(),v.ni.copy(v.ri),v.ri.mult(q,v.ri),t.vsub(d,v.rj),v.ri.vadd(c,v.ri),v.ri.vsub(h.position,v.ri),v.rj.vadd(d,v.rj),v.rj.vsub(i.position,v.rj),this.result.push(v),void this.createFrictionEquationsFromContact(v,this.frictionResult)}}for(var w=!1,r=0,x=o.length;r!==x&&!1===w;r++){var y=n[r],z=o[r],A=fa;g.vmult(y,A);var B=ga;g.vmult(p[z[0]],B),B.vadd(d,B);var C=ha;A.mult(-q,C),c.vadd(C,C);var D=ia;C.vsub(B,D);var E=D.dot(A),F=ja;if(c.vsub(B,F),E<0&&F.dot(A)>0){for(var G=[],H=0,I=z.length;H!==I;H++){var J=m.get();g.vmult(p[z[H]],J),d.vadd(J,J),G.push(J)}if(e(G,A,c)){if(l)return!0;w=!0;var v=this.createContactEquation(h,i,a,b,j,k);A.mult(-q,v.ri),A.negate(v.ni);var K=m.get();A.mult(-E,K);var L=m.get();A.mult(-q,L),c.vsub(d,v.rj),v.rj.vadd(L,v.rj),v.rj.vadd(K,v.rj),v.rj.vadd(d,v.rj),v.rj.vsub(i.position,v.rj),v.ri.vadd(c,v.ri),v.ri.vsub(h.position,v.ri),m.release(K),m.release(L),this.result.push(v),this.createFrictionEquationsFromContact(v,this.frictionResult);for(var H=0,M=G.length;H!==M;H++)m.release(G[H]);return}for(var H=0;H!==z.length;H++){var N=m.get(),O=m.get();g.vmult(p[z[(H+1)%z.length]],N),g.vmult(p[z[(H+2)%z.length]],O),d.vadd(N,N),d.vadd(O,O);var P=ba;O.vsub(N,P);var Q=ca;P.unit(Q);var R=m.get(),S=m.get();c.vsub(N,S);var T=S.dot(Q);Q.mult(T,R),R.vadd(N,R);var U=m.get();if(R.vsub(c,U),T>0&&T*T<P.norm2()&&U.norm2()<q*q){if(l)return!0;var v=this.createContactEquation(h,i,a,b,j,k);R.vsub(d,v.rj),R.vsub(c,v.ni),v.ni.normalize(),v.ni.mult(q,v.ri),v.rj.vadd(d,v.rj),v.rj.vsub(i.position,v.rj),v.ri.vadd(c,v.ri),v.ri.vsub(h.position,v.ri),this.result.push(v),this.createFrictionEquationsFromContact(v,this.frictionResult);for(var H=0,M=G.length;H!==M;H++)m.release(G[H]);return m.release(N),m.release(O),m.release(R),m.release(U),void m.release(S)}m.release(N),m.release(O),m.release(R),m.release(U),m.release(S)}for(var H=0,M=G.length;H!==M;H++)m.release(G[H])}}};new j,new j;d.prototype[h.types.PLANE|h.types.BOX]=d.prototype.planeBox=function(a,b,c,d,e,f,g,h,i,j,k){return b.convexPolyhedronRepresentation.material=b.material,b.convexPolyhedronRepresentation.collisionResponse=b.collisionResponse,b.convexPolyhedronRepresentation.id=b.id,this.planeConvex(a,b.convexPolyhedronRepresentation,c,d,e,f,g,h,a,b,k)};var ka=new j,la=new j,ma=new j,na=new j;d.prototype[h.types.PLANE|h.types.CONVEXPOLYHEDRON]=d.prototype.planeConvex=function(a,b,c,d,e,f,g,h,i,j,k){var l=ka,m=la;m.set(0,0,1),e.vmult(m,m);for(var n=0,o=ma,p=0;p!==b.vertices.length;p++){l.copy(b.vertices[p]),f.vmult(l,l),d.vadd(l,l),l.vsub(c,o);if(m.dot(o)<=0){if(k)return!0;var q=this.createContactEquation(g,h,a,b,i,j),r=na;m.mult(m.dot(o),r),l.vsub(r,r),r.vsub(c,q.ri),q.ni.copy(m),l.vsub(d,q.rj),q.ri.vadd(c,q.ri),q.ri.vsub(g.position,q.ri),q.rj.vadd(d,q.rj),q.rj.vsub(h.position,q.rj),this.result.push(q),n++,this.enableFrictionReduction||this.createFrictionEquationsFromContact(q,this.frictionResult)}}this.enableFrictionReduction&&n&&this.createFrictionFromAverage(n)};var oa=new j,pa=new j;d.prototype[h.types.CONVEXPOLYHEDRON]=d.prototype.convexConvex=function(a,b,c,d,e,f,g,h,i,j,k,l,m){var n=oa;if(!(c.distanceTo(d)>a.boundingSphereRadius+b.boundingSphereRadius)&&a.findSeparatingAxis(b,c,e,d,f,n,l,m)){var o=[],p=pa;a.clipAgainstHull(c,e,b,d,f,n,-100,100,o);for(var q=0,r=0;r!==o.length;r++){if(k)return!0;var s=this.createContactEquation(g,h,a,b,i,j),t=s.ri,u=s.rj;n.negate(s.ni),o[r].normal.negate(p),p.mult(o[r].depth,p),o[r].point.vadd(p,t),u.copy(o[r].point),t.vsub(c,t),u.vsub(d,u),t.vadd(c,t),t.vsub(g.position,t),u.vadd(d,u),u.vsub(h.position,u),this.result.push(s),q++,this.enableFrictionReduction||this.createFrictionEquationsFromContact(s,this.frictionResult)}this.enableFrictionReduction&&q&&this.createFrictionFromAverage(q)}};var qa=new j,ra=new j,sa=new j;d.prototype[h.types.PLANE|h.types.PARTICLE]=d.prototype.planeParticle=function(a,b,c,d,e,f,g,h,i,j,k){var l=qa;l.set(0,0,1),g.quaternion.vmult(l,l);var m=ra;if(d.vsub(g.position,m),l.dot(m)<=0){if(k)return!0;var n=this.createContactEquation(h,g,b,a,i,j);n.ni.copy(l),n.ni.negate(n.ni),n.ri.set(0,0,0);var o=sa;l.mult(l.dot(d),o),d.vsub(o,o),n.rj.copy(o),this.result.push(n),this.createFrictionEquationsFromContact(n,this.frictionResult)}};var ta=new j;d.prototype[h.types.PARTICLE|h.types.SPHERE]=d.prototype.sphereParticle=function(a,b,c,d,e,f,g,h,i,j,k){var l=ta;if(l.set(0,0,1),d.vsub(c,l),l.norm2()<=a.radius*a.radius){if(k)return!0;var m=this.createContactEquation(h,g,b,a,i,j);l.normalize(),m.rj.copy(l),m.rj.mult(a.radius,m.rj),m.ni.copy(l),m.ni.negate(m.ni),m.ri.set(0,0,0),this.result.push(m),this.createFrictionEquationsFromContact(m,this.frictionResult)}};var ua=new l,va=new j,wa=(new j,new j),xa=new j,ya=new j;d.prototype[h.types.PARTICLE|h.types.CONVEXPOLYHEDRON]=d.prototype.convexParticle=function(a,b,c,d,e,f,g,h,i,j,k){var l=-1,m=wa,n=ya,o=null,p=0,q=va;if(q.copy(d),q.vsub(c,q),e.conjugate(ua),ua.vmult(q,q),a.pointIsInside(q)){a.worldVerticesNeedsUpdate&&a.computeWorldVertices(c,e),a.worldFaceNormalsNeedsUpdate&&a.computeWorldFaceNormals(e);for(var r=0,s=a.faces.length;r!==s;r++){var t=[a.worldVertices[a.faces[r][0]]],u=a.worldFaceNormals[r];d.vsub(t[0],xa);var v=-u.dot(xa);if(null===o||Math.abs(v)<Math.abs(o)){if(k)return!0;o=v,l=r,m.copy(u),p++}}if(-1!==l){var w=this.createContactEquation(h,g,b,a,i,j);m.mult(o,n),n.vadd(d,n),n.vsub(c,n),w.rj.copy(n),m.negate(w.ni),w.ri.set(0,0,0);var x=w.ri,y=w.rj;x.vadd(d,x),x.vsub(h.position,x),y.vadd(c,y),y.vsub(g.position,y),this.result.push(w),this.createFrictionEquationsFromContact(w,this.frictionResult)}else console.warn("Point found inside convex, but did not find penetrating face!")}},d.prototype[h.types.BOX|h.types.HEIGHTFIELD]=d.prototype.boxHeightfield=function(a,b,c,d,e,f,g,h,i,j,k){return a.convexPolyhedronRepresentation.material=a.material,a.convexPolyhedronRepresentation.collisionResponse=a.collisionResponse,this.convexHeightfield(a.convexPolyhedronRepresentation,b,c,d,e,f,g,h,a,b,k)};var za=new j,Aa=new j,Ba=[0];d.prototype[h.types.CONVEXPOLYHEDRON|h.types.HEIGHTFIELD]=d.prototype.convexHeightfield=function(a,b,c,d,e,f,g,h,i,j,l){var m=b.data,n=b.elementSize,o=a.boundingSphereRadius,p=Aa,q=Ba,r=za;k.pointToLocalFrame(d,f,c,r);var s=Math.floor((r.x-o)/n)-1,t=Math.ceil((r.x+o)/n)+1,u=Math.floor((r.y-o)/n)-1,v=Math.ceil((r.y+o)/n)+1;if(!(t<0||v<0||s>m.length||u>m[0].length)){s<0&&(s=0),t<0&&(t=0),u<0&&(u=0),v<0&&(v=0),s>=m.length&&(s=m.length-1),t>=m.length&&(t=m.length-1),v>=m[0].length&&(v=m[0].length-1),u>=m[0].length&&(u=m[0].length-1);var w=[];b.getRectMinMax(s,u,t,v,w);var x=w[0],y=w[1];if(!(r.z-o>y||r.z+o<x))for(var z=s;z<t;z++)for(var A=u;A<v;A++){var B=!1;if(b.getConvexTrianglePillar(z,A,!1),k.pointToWorldFrame(d,f,b.pillarOffset,p),c.distanceTo(p)<b.pillarConvex.boundingSphereRadius+a.boundingSphereRadius&&(B=this.convexConvex(a,b.pillarConvex,c,p,e,f,g,h,null,null,l,q,null)),l&&B)return!0;if(b.getConvexTrianglePillar(z,A,!0),k.pointToWorldFrame(d,f,b.pillarOffset,p),c.distanceTo(p)<b.pillarConvex.boundingSphereRadius+a.boundingSphereRadius&&(B=this.convexConvex(a,b.pillarConvex,c,p,e,f,g,h,null,null,l,q,null)),l&&B)return!0}}};var Ca=new j,Da=new j;d.prototype[h.types.SPHERE|h.types.HEIGHTFIELD]=d.prototype.sphereHeightfield=function(a,b,c,d,e,f,g,h,i,j,l){var m=b.data,n=a.radius,o=b.elementSize,p=Da,q=Ca;k.pointToLocalFrame(d,f,c,q);var r=Math.floor((q.x-n)/o)-1,s=Math.ceil((q.x+n)/o)+1,t=Math.floor((q.y-n)/o)-1,u=Math.ceil((q.y+n)/o)+1;if(!(s<0||u<0||r>m.length||u>m[0].length)){r<0&&(r=0),s<0&&(s=0),t<0&&(t=0),u<0&&(u=0),r>=m.length&&(r=m.length-1),s>=m.length&&(s=m.length-1),u>=m[0].length&&(u=m[0].length-1),t>=m[0].length&&(t=m[0].length-1);var v=[];b.getRectMinMax(r,t,s,u,v);var w=v[0],x=v[1];if(!(q.z-n>x||q.z+n<w))for(var y=this.result,z=r;z<s;z++)for(var A=t;A<u;A++){var B=y.length,C=!1;if(b.getConvexTrianglePillar(z,A,!1),k.pointToWorldFrame(d,f,b.pillarOffset,p),c.distanceTo(p)<b.pillarConvex.boundingSphereRadius+a.boundingSphereRadius&&(C=this.sphereConvex(a,b.pillarConvex,c,p,e,f,g,h,a,b,l)),l&&C)return!0;if(b.getConvexTrianglePillar(z,A,!0),k.pointToWorldFrame(d,f,b.pillarOffset,p),c.distanceTo(p)<b.pillarConvex.boundingSphereRadius+a.boundingSphereRadius&&(C=this.sphereConvex(a,b.pillarConvex,c,p,e,f,g,h,a,b,l)),l&&C)return!0;var D=y.length-B;if(D>2)return}}}},{"../collision/AABB":3,"../collision/Ray":10,"../equations/ContactEquation":20,"../equations/FrictionEquation":22,"../math/Quaternion":29,"../math/Transform":30,"../math/Vec3":31,"../objects/Body":32,"../shapes/ConvexPolyhedron":39,"../shapes/Shape":44,"../solver/Solver":48,"../utils/Vec3Pool":55}],57:[function(a,b,c){function d(a){a=a||{},i.apply(this),this.dt=-1,this.allowSleep=!!a.allowSleep,this.contacts=[],this.frictionEquations=[],this.quatNormalizeSkip=void 0!==a.quatNormalizeSkip?a.quatNormalizeSkip:0,this.quatNormalizeFast=void 0!==a.quatNormalizeFast&&a.quatNormalizeFast,this.time=0,this.stepnumber=0,this.default_dt=1/60,this.nextId=0,this.gravity=new e,a.gravity&&this.gravity.copy(a.gravity),this.broadphase=void 0!==a.broadphase?a.broadphase:new s,this.bodies=[],this.solver=void 0!==a.solver?a.solver:new g,this.constraints=[],this.narrowphase=new h(this),this.collisionMatrix=new j,this.collisionMatrixPrevious=new j,this.bodyOverlapKeeper=new k,this.shapeOverlapKeeper=new k,this.materials=[],this.contactmaterials=[],this.contactMaterialTable=new o,this.defaultMaterial=new l("default"),this.defaultContactMaterial=new m(this.defaultMaterial,this.defaultMaterial,{friction:.3,restitution:0}),this.doProfiling=!1,this.profile={solve:0,makeContactConstraints:0,broadphase:0,integrate:0,narrowphase:0},this.accumulator=0,this.subsystems=[],this.addBodyEvent={type:"addBody",body:null},this.removeBodyEvent={type:"removeBody",body:null},this.idToBodyMap={},this.broadphase.setWorld(this)}b.exports=d;var e=(a("../shapes/Shape"),a("../math/Vec3")),f=a("../math/Quaternion"),g=a("../solver/GSSolver"),h=(a("../equations/ContactEquation"),a("../equations/FrictionEquation"),a("./Narrowphase")),i=a("../utils/EventTarget"),j=a("../collision/ArrayCollisionMatrix"),k=a("../collision/OverlapKeeper"),l=a("../material/Material"),m=a("../material/ContactMaterial"),n=a("../objects/Body"),o=a("../utils/TupleDictionary"),p=a("../collision/RaycastResult"),q=a("../collision/AABB"),r=a("../collision/Ray"),s=a("../collision/NaiveBroadphase");d.prototype=new i;var t=(new q,new r);if(d.prototype.getContactMaterial=function(a,b){return this.contactMaterialTable.get(a.id,b.id)},d.prototype.numObjects=function(){return this.bodies.length},d.prototype.collisionMatrixTick=function(){var a=this.collisionMatrixPrevious;this.collisionMatrixPrevious=this.collisionMatrix,this.collisionMatrix=a,this.collisionMatrix.reset(),this.bodyOverlapKeeper.tick(),this.shapeOverlapKeeper.tick()},d.prototype.add=d.prototype.addBody=function(a){-1===this.bodies.indexOf(a)&&(a.index=this.bodies.length,this.bodies.push(a),a.world=this,a.initPosition.copy(a.position),a.initVelocity.copy(a.velocity),a.timeLastSleepy=this.time,a instanceof n&&(a.initAngularVelocity.copy(a.angularVelocity),a.initQuaternion.copy(a.quaternion)),this.collisionMatrix.setNumObjects(this.bodies.length),this.addBodyEvent.body=a,this.idToBodyMap[a.id]=a,this.dispatchEvent(this.addBodyEvent))},d.prototype.addConstraint=function(a){this.constraints.push(a)},d.prototype.removeConstraint=function(a){var b=this.constraints.indexOf(a);-1!==b&&this.constraints.splice(b,1)},d.prototype.rayTest=function(a,b,c){c instanceof p?this.raycastClosest(a,b,{skipBackfaces:!0},c):this.raycastAll(a,b,{skipBackfaces:!0},c)},d.prototype.raycastAll=function(a,b,c,d){return c.mode=r.ALL,c.from=a,c.to=b,c.callback=d,t.intersectWorld(this,c)},d.prototype.raycastAny=function(a,b,c,d){return c.mode=r.ANY,c.from=a,c.to=b,c.result=d,t.intersectWorld(this,c)},d.prototype.raycastClosest=function(a,b,c,d){return c.mode=r.CLOSEST,c.from=a,c.to=b,c.result=d,t.intersectWorld(this,c)},d.prototype.remove=function(a){a.world=null;var b=this.bodies.length-1,c=this.bodies,d=c.indexOf(a);if(-1!==d){c.splice(d,1);for(var e=0;e!==c.length;e++)c[e].index=e;this.collisionMatrix.setNumObjects(b),this.removeBodyEvent.body=a,delete this.idToBodyMap[a.id],this.dispatchEvent(this.removeBodyEvent)}},d.prototype.removeBody=d.prototype.remove,d.prototype.getBodyById=function(a){return this.idToBodyMap[a]},d.prototype.getShapeById=function(a){for(var b=this.bodies,c=0,d=b.length;c<d;c++)for(var e=b[c].shapes,f=0,g=e.length;f<g;f++){var h=e[f];if(h.id===a)return h}},d.prototype.addMaterial=function(a){this.materials.push(a)},d.prototype.addContactMaterial=function(a){this.contactmaterials.push(a),this.contactMaterialTable.set(a.materials[0].id,a.materials[1].id,a)},"undefined"==typeof performance&&(performance={}),!performance.now){var u=Date.now();performance.timing&&performance.timing.navigationStart&&(u=performance.timing.navigationStart),performance.now=function(){return Date.now()-u}}new e;d.prototype.step=function(a,b,c){if(c=c||10,0===(b=b||0))this.internalStep(a),this.time+=a;else{this.accumulator+=b;for(var d=0;this.accumulator>=a&&d<c;)this.internalStep(a),this.accumulator-=a,d++;for(var e=this.accumulator%a/a,f=0;f!==this.bodies.length;f++){var g=this.bodies[f];g.previousPosition.lerp(g.position,e,g.interpolatedPosition),g.previousQuaternion.slerp(g.quaternion,e,g.interpolatedQuaternion),g.previousQuaternion.normalize()}this.time+=b}};var v={type:"postStep"},w={type:"preStep"},x={type:n.COLLIDE_EVENT_NAME,body:null,contact:null},y=[],z=[],A=[],B=[];new e,new e,new e,new e,new e,new e,new e,new e,new e,new f,new f,new f,new e;d.prototype.internalStep=function(a){this.dt=a;var b,c=this.contacts,d=A,e=B,f=this.numObjects(),g=this.bodies,h=this.solver,i=this.gravity,j=this.doProfiling,k=this.profile,l=n.DYNAMIC,m=this.constraints,o=z,p=(i.norm(),i.x),q=i.y,r=i.z,s=0;for(j&&(b=performance.now()),s=0;s!==f;s++){var t=g[s];if(t.type===l){var u=t.force,C=t.mass;u.x+=C*p,u.y+=C*q,u.z+=C*r}}for(var s=0,D=this.subsystems.length;s!==D;s++)this.subsystems[s].update();j&&(b=performance.now()),d.length=0,e.length=0,this.broadphase.collisionPairs(this,d,e),j&&(k.broadphase=performance.now()-b);var E=m.length;for(s=0;s!==E;s++){var F=m[s];if(!F.collideConnected)for(var G=d.length-1;G>=0;G-=1)(F.bodyA===d[G]&&F.bodyB===e[G]||F.bodyB===d[G]&&F.bodyA===e[G])&&(d.splice(G,1),e.splice(G,1))}this.collisionMatrixTick(),j&&(b=performance.now());var H=y,I=c.length;for(s=0;s!==I;s++)H.push(c[s]);c.length=0;var J=this.frictionEquations.length;for(s=0;s!==J;s++)o.push(this.frictionEquations[s]);this.frictionEquations.length=0,this.narrowphase.getContacts(d,e,this,c,H,this.frictionEquations,o),j&&(k.narrowphase=performance.now()-b),j&&(b=performance.now());for(var s=0;s<this.frictionEquations.length;s++)h.addEquation(this.frictionEquations[s]);for(var K=c.length,L=0;L!==K;L++){var M,F=c[L],t=F.bi,N=F.bj,O=F.si,P=F.sj;M=t.material&&N.material?this.getContactMaterial(t.material,N.material)||this.defaultContactMaterial:this.defaultContactMaterial;M.friction;if(t.material&&N.material&&(t.material.friction>=0&&N.material.friction>=0&&t.material.friction*N.material.friction,t.material.restitution>=0&&N.material.restitution>=0&&(F.restitution=t.material.restitution*N.material.restitution)),h.addEquation(F),t.allowSleep&&t.type===n.DYNAMIC&&t.sleepState===n.SLEEPING&&N.sleepState===n.AWAKE&&N.type!==n.STATIC){N.velocity.norm2()+N.angularVelocity.norm2()>=2*Math.pow(N.sleepSpeedLimit,2)&&(t._wakeUpAfterNarrowphase=!0)}if(N.allowSleep&&N.type===n.DYNAMIC&&N.sleepState===n.SLEEPING&&t.sleepState===n.AWAKE&&t.type!==n.STATIC){t.velocity.norm2()+t.angularVelocity.norm2()>=2*Math.pow(t.sleepSpeedLimit,2)&&(N._wakeUpAfterNarrowphase=!0)}this.collisionMatrix.set(t,N,!0),this.collisionMatrixPrevious.get(t,N)||(x.body=N,x.contact=F,t.dispatchEvent(x),x.body=t,N.dispatchEvent(x)),this.bodyOverlapKeeper.set(t.id,N.id),this.shapeOverlapKeeper.set(O.id,P.id)}for(this.emitContactEvents(),j&&(k.makeContactConstraints=performance.now()-b,b=performance.now()),s=0;s!==f;s++){var t=g[s];t._wakeUpAfterNarrowphase&&(t.wakeUp(),t._wakeUpAfterNarrowphase=!1)}var E=m.length;for(s=0;s!==E;s++){var F=m[s];F.update();for(var G=0,Q=F.equations.length;G!==Q;G++){var R=F.equations[G];h.addEquation(R)}}h.solve(a,this),j&&(k.solve=performance.now()-b),h.removeAllEquations();var S=Math.pow;for(s=0;s!==f;s++){var t=g[s];if(t.type&l){var T=S(1-t.linearDamping,a),U=t.velocity;U.mult(T,U);var V=t.angularVelocity;if(V){var W=S(1-t.angularDamping,a);V.mult(W,V)}}}for(this.dispatchEvent(w),s=0;s!==f;s++){var t=g[s];t.preStep&&t.preStep.call(t)}j&&(b=performance.now());var X=this.stepnumber,Y=X%(this.quatNormalizeSkip+1)==0,Z=this.quatNormalizeFast;for(s=0;s!==f;s++)g[s].integrate(a,Y,Z);for(this.clearForces(),this.broadphase.dirty=!0,j&&(k.integrate=performance.now()-b),this.time+=a,this.stepnumber+=1,this.dispatchEvent(v),s=0;s!==f;s++){var t=g[s],$=t.postStep;$&&$.call(t)}if(this.allowSleep)for(s=0;s!==f;s++)g[s].sleepTick(this.time)},d.prototype.emitContactEvents=function(){var a=[],b=[],c={type:"beginContact",bodyA:null,bodyB:null},d={type:"endContact",bodyA:null,bodyB:null},e={type:"beginShapeContact",bodyA:null,bodyB:null,shapeA:null,shapeB:null},f={type:"endShapeContact",bodyA:null,bodyB:null,shapeA:null,shapeB:null};return function(){var g=this.hasAnyEventListener("beginContact"),h=this.hasAnyEventListener("endContact");if((g||h)&&this.bodyOverlapKeeper.getDiff(a,b),g){for(var i=0,j=a.length;i<j;i+=2)c.bodyA=this.getBodyById(a[i]),c.bodyB=this.getBodyById(a[i+1]),this.dispatchEvent(c);c.bodyA=c.bodyB=null}if(h){for(var i=0,j=b.length;i<j;i+=2)d.bodyA=this.getBodyById(b[i]),d.bodyB=this.getBodyById(b[i+1]),this.dispatchEvent(d);d.bodyA=d.bodyB=null}a.length=b.length=0;var k=this.hasAnyEventListener("beginShapeContact"),l=this.hasAnyEventListener("endShapeContact");if((k||l)&&this.shapeOverlapKeeper.getDiff(a,b),k){for(var i=0,j=a.length;i<j;i+=2){var m=this.getShapeById(a[i]),n=this.getShapeById(a[i+1]);e.shapeA=m,e.shapeB=n,e.bodyA=m.body,e.bodyB=n.body,this.dispatchEvent(e)}e.bodyA=e.bodyB=e.shapeA=e.shapeB=null}if(l){for(var i=0,j=b.length;i<j;i+=2){var m=this.getShapeById(b[i]),n=this.getShapeById(b[i+1]);m&&n&&(f.shapeA=m,f.shapeB=n,f.bodyA=m.body,f.bodyB=n.body,this.dispatchEvent(f))}f.bodyA=f.bodyB=f.shapeA=f.shapeB=null}}}(),d.prototype.clearForces=function(){for(var a=this.bodies,b=a.length,c=0;c!==b;c++){var d=a[c];d.force,d.torque;d.force.set(0,0,0),d.torque.set(0,0,0)}}},{"../collision/AABB":3,"../collision/ArrayCollisionMatrix":4,"../collision/NaiveBroadphase":7,"../collision/OverlapKeeper":9,"../collision/Ray":10,"../collision/RaycastResult":11,"../equations/ContactEquation":20,"../equations/FrictionEquation":22,"../material/ContactMaterial":25,"../material/Material":26,"../math/Quaternion":29,"../math/Vec3":31,"../objects/Body":32,"../shapes/Shape":44,"../solver/GSSolver":47,"../utils/EventTarget":50,"../utils/TupleDictionary":53,"./Narrowphase":56}]},{},[2])(2)});