(function t(e,i,o){function n(s,a){if(!i[s]){if(!e[s]){var l="function"==typeof require&&require;if(!a&&l)return l(s,!0);if(r)return r(s,!0);var h=new Error("Cannot find module '"+s+"'");throw h.code="MODULE_NOT_FOUND",h}var c=i[s]={exports:{}};e[s][0].call(c.exports,function(t){return n(e[s][1][t]||t)},c,c.exports,t,e,i,o)}return i[s].exports}for(var r="function"==typeof require&&require,s=0;s=0&&(u(this.shapes,e),this.body.removeShape(t.shape),t.setIndex(-1))},o.syncSceneToPhysics=function(t){void 0===t&&(t=!1);var e=this.node,i=(0,s.worldDirty)(e);if(t||i){if(this.body.aabbNeedsUpdate=!0,e.getWorldPosition(d),e.getWorldRotation(y),p.copy(this.body.position,d),c.copy(this.body.quaternion,y),e._localMatDirty&h){for(var o=e.__wscale,n=0;n0){var r=f.pop();p.copy(r.contactA,n.ri),p.copy(r.contactB,n.rj),p.copy(r.normal,n.ni),v.contacts.push(r)}else{var l={contactA:p.copy(new p,n.ri),contactB:p.copy(new p,n.rj),normal:p.copy(new p,n.ni)};v.contacts.push(l)}}for(o=0;o=0&&(0==this.shapes.length&&null==this.wrappedBody||0==this.shapes.length&&null!=this.wrappedBody&&!this.wrappedBody.rigidBody.enabledInHierarchy||0==this.shapes.length&&null!=this.wrappedBody&&!this.wrappedBody.isEnabled)&&(this.body.sleep(),this.index=-1,this.wrappedWorld.removeSharedBody(this))}},{key:"reference",set:function(t){t?this.ref++:this.ref--,0==this.ref&&this.destroy()}}])&&l(e.prototype,i),t}();i.CannonSharedBody=m,m.sharedBodiesMap=new Map},{"../../../../../external/cannon/cannon":24,"../framework/physics-enum":19,"../framework/util":23,"./cannon-util":3}],3:[function(t,e,i){"use strict";i.__esModule=!0,i.groupIndexToBitMask=r,i.toCannonRaycastOptions=function(t,e){t.checkCollisionResponse=!e.queryTrigger,r(e.groupIndex,t),t.skipBackFaces=!1},i.fillRaycastResult=function(t,e){t._assign(n.copy(new n,e.hitPointWorld),e.distance,(0,o.getWrap)(e.shape).collider)},i.commitShapeUpdates=function(t){t.aabbNeedsUpdate=!0,t.updateMassProperties(),t.updateBoundingRadius()},i.deprecatedEventMap=void 0;var o=t("../framework/util"),n=cc.Vec3;function r(t,e){var i=1<=0&&(p(this.bodies,e),this._world.remove(t.body))},e=t,(i=[{key:"world",get:function(){return this._world}},{key:"defaultMaterial",set:function(t){this._world.defaultMaterial.friction=t.friction,this._world.defaultMaterial.restitution=t.restitution,null!=s.CannonShape.idToMaterial[t._uuid]&&(s.CannonShape.idToMaterial[t._uuid]=this._world.defaultMaterial)}},{key:"allowSleep",set:function(t){this._world.allowSleep=t}},{key:"gravity",set:function(t){c.copy(this._world.gravity,t)}}])&&h(e.prototype,i),t}();i.CannonWorld=u;var d=new n.default.Vec3,y=new n.default.Vec3;function f(t,e){c.copy(d,t.o),t.computeHit(y,e)}var v={checkCollisionResponse:!1,collisionFilterGroup:-1,collisionFilterMask:-1,skipBackFaces:!1}},{"../../../../../external/cannon/cannon":24,"../framework/util":23,"./cannon-shared-body":2,"./cannon-util":3,"./shapes/cannon-shape":7}],5:[function(t){"use strict";var e=t("../framework/physics-selector"),i=t("./cannon-rigid-body"),o=t("./cannon-world"),n=t("./shapes/cannon-box-shape"),r=t("./shapes/cannon-sphere-shape");(0,e.instantiate)(n.CannonBoxShape,r.CannonSphereShape,i.CannonRigidBody,o.CannonWorld)},{"../framework/physics-selector":22,"./cannon-rigid-body":1,"./cannon-world":4,"./shapes/cannon-box-shape":6,"./shapes/cannon-sphere-shape":8}],6:[function(t,e,i){"use strict";i.__esModule=!0,i.CannonBoxShape=void 0;var o,n=(o=t("../../../../../../external/cannon/cannon"))&&o.__esModule?o:{default:o},r=t("../cannon-util"),s=t("./cannon-shape");function a(t,e){for(var i=0;i=0&&this._body.updateHasTrigger()}},{key:"center",set:function(t){this._setCenter(t),this._index>=0&&(0,s.commitShapeUpdates)(this._body)}},{key:"_body",get:function(){return this._sharedBody.body}}])&&a(e.prototype,i),t}();i.CannonShape=p,p.idToMaterial={}},{"../../../../../../external/cannon/cannon":24,"../../framework/util":23,"../cannon-util":3}],8:[function(t,e,i){"use strict";i.__esModule=!0,i.CannonSphereShape=void 0;var o,n=(o=t("../../../../../../external/cannon/cannon"))&&o.__esModule?o:{default:o},r=t("../cannon-util"),s=t("./cannon-shape");function a(t,e){for(var i=0;ithis._lastTime?(e-this._lastTime)/1e3:0,this._lastTime=e}else this._deltaTime=t;if(cc.director.emit(cc.Director.EVENT_BEFORE_PHYSICS),this._useFixedTime)this.physicsWorld.step(this._fixedTime);else if(this.useAccumulator){var i=0;for(this._accumulator+=this._deltaTime;ithis._fixedTime;)this.physicsWorld.step(this._fixedTime),this._accumulator-=this._fixedTime,i++}else this.physicsWorld.step(this._fixedTime,this._deltaTime,this._maxSubStep);cc.director.emit(cc.Director.EVENT_AFTER_PHYSICS)}},o.raycast=function(t,e,i,o){if(void 0===e&&(e=0),void 0===i&&(i=1/0),void 0===o&&(o=!0),this.raycastResultPool.reset(),this.raycastResults.length=0,"string"==typeof e){var n=cc.game.groupList.indexOf(e);-1==n&&(n=0),this.raycastOptions.groupIndex=n}else this.raycastOptions.groupIndex=e;return this.raycastOptions.maxDistance=i,this.raycastOptions.queryTrigger=o,this.physicsWorld.raycast(t,this.raycastOptions,this.raycastResultPool,this.raycastResults)?this.raycastResults:null},o.raycastClosest=function(t,e,i,o){if(void 0===e&&(e=0),void 0===i&&(i=1/0),void 0===o&&(o=!0),"string"==typeof e){var n=cc.game.groupList.indexOf(e);-1==n&&(n=0),this.raycastOptions.groupIndex=n}else this.raycastOptions.groupIndex=e;return this.raycastOptions.maxDistance=i,this.raycastOptions.queryTrigger=o,this.physicsWorld.raycastClosest(t,this.raycastOptions,this.raycastClosestResult)?this.raycastClosestResult:null},o._updateMaterial=function(){this.physicsWorld.defaultMaterial=this._material},e=t,(i=[{key:"enabled",get:function(){return this._enabled},set:function(t){this._enabled=t}},{key:"allowSleep",get:function(){return this._allowSleep},set:function(t){this._allowSleep=t,this.physicsWorld.allowSleep=this._allowSleep}},{key:"maxSubStep",get:function(){return this._maxSubStep},set:function(t){this._maxSubStep=t}},{key:"deltaTime",get:function(){return this._fixedTime},set:function(t){this._fixedTime=t}},{key:"useFixedTime",get:function(){return this._useFixedTime},set:function(t){this._useFixedTime=t}},{key:"gravity",get:function(){return this._gravity},set:function(t){this._gravity.set(t),this.physicsWorld.gravity=t}},{key:"defaultMaterial",get:function(){return this._material}}])&&f(e.prototype,i),t}()).prototype,"_enabled",[g],{configurable:!0,enumerable:!0,writable:!0,initializer:function(){return!1}}),s=v(n.prototype,"_allowSleep",[g],{configurable:!0,enumerable:!0,writable:!0,initializer:function(){return!0}}),a=v(n.prototype,"_gravity",[g],{configurable:!0,enumerable:!0,writable:!0,initializer:function(){return new cc.Vec3(0,-10,0)}}),l=v(n.prototype,"_maxSubStep",[g],{configurable:!0,enumerable:!0,writable:!0,initializer:function(){return 1}}),h=v(n.prototype,"_fixedTime",[g],{configurable:!0,enumerable:!0,writable:!0,initializer:function(){return 1/60}}),c=v(n.prototype,"_useFixedTime",[g],{configurable:!0,enumerable:!0,writable:!0,initializer:function(){return!0}}),o=n))||o;i.Physics3DManager=b},{"./assets/physics-material":11,"./instance":18,"./physics-ray-result":21}],21:[function(t,e,i){"use strict";function o(t,e){for(var i=0;i (http://steffe.se), JayceLai",keywords:["cannon.js","cocos","creator","physics","engine","3d"],scripts:{build:"grunt && npm run preprocess && grunt addLicense && grunt addDate",preprocess:"node node_modules/uglify-js/bin/uglifyjs build/cannon.js -o build/cannon.min.js -c -m"},main:"./build/cannon.min.js",engines:{node:"*"},repository:{type:"git",url:"https://github.com/cocos-creator/cannon.js.git"},bugs:{url:"https://github.com/cocos-creator/cannon.js/issues"},licenses:[{type:"MIT"}],devDependencies:{jshint:"latest","uglify-js":"latest",nodeunit:"^0.9.0",grunt:"~0.4.0","grunt-contrib-jshint":"~0.1.1","grunt-contrib-nodeunit":"^0.4.1","grunt-contrib-concat":"~0.1.3","grunt-contrib-uglify":"^0.5.1","grunt-browserify":"^2.1.4","grunt-contrib-yuidoc":"^0.5.2",browserify:"*"},dependencies:{}}},{}],2:[function(t,e){e.exports={version:t("../package.json").version,AABB:t("./collision/AABB"),ArrayCollisionMatrix:t("./collision/ArrayCollisionMatrix"),Body:t("./objects/Body"),Box:t("./shapes/Box"),Broadphase:t("./collision/Broadphase"),Constraint:t("./constraints/Constraint"),ContactEquation:t("./equations/ContactEquation"),Narrowphase:t("./world/Narrowphase"),ConeTwistConstraint:t("./constraints/ConeTwistConstraint"),ContactMaterial:t("./material/ContactMaterial"),ConvexPolyhedron:t("./shapes/ConvexPolyhedron"),Cylinder:t("./shapes/Cylinder"),DistanceConstraint:t("./constraints/DistanceConstraint"),Equation:t("./equations/Equation"),EventTarget:t("./utils/EventTarget"),FrictionEquation:t("./equations/FrictionEquation"),GSSolver:t("./solver/GSSolver"),GridBroadphase:t("./collision/GridBroadphase"),Heightfield:t("./shapes/Heightfield"),HingeConstraint:t("./constraints/HingeConstraint"),LockConstraint:t("./constraints/LockConstraint"),Mat3:t("./math/Mat3"),Material:t("./material/Material"),NaiveBroadphase:t("./collision/NaiveBroadphase"),ObjectCollisionMatrix:t("./collision/ObjectCollisionMatrix"),Pool:t("./utils/Pool"),Particle:t("./shapes/Particle"),Plane:t("./shapes/Plane"),PointToPointConstraint:t("./constraints/PointToPointConstraint"),Quaternion:t("./math/Quaternion"),Ray:t("./collision/Ray"),RaycastVehicle:t("./objects/RaycastVehicle"),RaycastResult:t("./collision/RaycastResult"),RigidVehicle:t("./objects/RigidVehicle"),RotationalEquation:t("./equations/RotationalEquation"),RotationalMotorEquation:t("./equations/RotationalMotorEquation"),SAPBroadphase:t("./collision/SAPBroadphase"),SPHSystem:t("./objects/SPHSystem"),Shape:t("./shapes/Shape"),Solver:t("./solver/Solver"),Sphere:t("./shapes/Sphere"),SplitSolver:t("./solver/SplitSolver"),Spring:t("./objects/Spring"),Transform:t("./math/Transform"),Trimesh:t("./shapes/Trimesh"),Vec3:t("./math/Vec3"),Vec3Pool:t("./utils/Vec3Pool"),World:t("./world/World"),Octree:t("./utils/Octree"),CMath:t("./math/CMath")}},{"../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/CMath":27,"./math/Mat3":29,"./math/Quaternion":30,"./math/Transform":31,"./math/Vec3":32,"./objects/Body":33,"./objects/RaycastVehicle":34,"./objects/RigidVehicle":35,"./objects/SPHSystem":36,"./objects/Spring":37,"./shapes/Box":39,"./shapes/ConvexPolyhedron":40,"./shapes/Cylinder":41,"./shapes/Heightfield":42,"./shapes/Particle":43,"./shapes/Plane":44,"./shapes/Shape":45,"./shapes/Sphere":46,"./shapes/Trimesh":47,"./solver/GSSolver":48,"./solver/Solver":49,"./solver/SplitSolver":50,"./utils/EventTarget":51,"./utils/Octree":52,"./utils/Pool":53,"./utils/Vec3Pool":56,"./world/Narrowphase":57,"./world/World":58}],3:[function(t,e){var i=t("../math/Vec3");function o(t){t=t||{},this.lowerBound=new i,t.lowerBound&&this.lowerBound.copy(t.lowerBound),this.upperBound=new i,t.upperBound&&this.upperBound.copy(t.upperBound)}t("../utils/Utils"),e.exports=o;var n=new i;o.prototype.setFromPoints=function(t,e,i,o){var r=this.lowerBound,s=this.upperBound,a=i;r.copy(t[0]),a&&a.vmult(r,r),s.copy(r);for(var l=1;ls.x&&(s.x=h.x),h.xs.y&&(s.y=h.y),h.ys.z&&(s.z=h.z),h.z=n.x&&e.y<=o.y&&i.y>=n.y&&e.z<=o.z&&i.z>=n.z},o.prototype.getCorners=function(t,e,i,o,n,r,s,a){var l=this.lowerBound,h=this.upperBound;t.copy(l),e.set(h.x,l.y,l.z),i.set(h.x,h.y,l.z),o.set(l.x,h.y,h.z),n.set(h.x,l.y,h.z),r.set(l.x,h.y,l.z),s.set(l.x,l.y,h.z),a.copy(h)};var r=[new i,new i,new i,new i,new i,new i,new i,new i];o.prototype.toLocalFrame=function(t,e){var i=r,o=i[0],n=i[1],s=i[2],a=i[3],l=i[4],h=i[5],c=i[6],p=i[7];this.getCorners(o,n,s,a,l,h,c,p);for(var u=0;8!==u;u++){var d=i[u];t.pointToLocal(d,d)}return e.setFromPoints(i)},o.prototype.toWorldFrame=function(t,e){var i=r,o=i[0],n=i[1],s=i[2],a=i[3],l=i[4],h=i[5],c=i[6],p=i[7];this.getCorners(o,n,s,a,l,h,c,p);for(var u=0;8!==u;u++){var d=i[u];t.pointToWorld(d,d)}return e.setFromPoints(i)},o.prototype.overlapsRay=function(t){var e=1/t._direction.x,i=1/t._direction.y,o=1/t._direction.z,n=(this.lowerBound.x-t.from.x)*e,r=(this.upperBound.x-t.from.x)*e,s=(this.lowerBound.y-t.from.y)*i,a=(this.upperBound.y-t.from.y)*i,l=(this.lowerBound.z-t.from.z)*o,h=(this.upperBound.z-t.from.z)*o,c=Math.max(Math.max(Math.min(n,r),Math.min(s,a)),Math.min(l,h)),p=Math.min(Math.min(Math.max(n,r),Math.max(s,a)),Math.max(l,h));return!(p<0||c>p)}},{"../math/Vec3":32,"../utils/Utils":55}],4:[function(t,e){function i(){this.matrix=[]}e.exports=i,i.prototype.get=function(t,e){if(t=t.index,(e=e.index)>t){var i=e;e=t,t=i}return this.matrix[(t*(t+1)>>1)+e-1]},i.prototype.set=function(t,e,i){if(t=t.index,(e=e.index)>t){var o=e;e=t,t=o}this.matrix[(t*(t+1)>>1)+e-1]=i?1:0},i.prototype.reset=function(){for(var t=0,e=this.matrix.length;t!==e;t++)this.matrix[t]=0},i.prototype.setNumObjects=function(t){this.matrix.length=t*(t-1)>>1}},{}],5:[function(t,e){var i=t("../objects/Body"),o=t("../math/Vec3"),n=t("../math/Quaternion");function r(){this.world=null,this.useBoundingBoxes=!1,this.dirty=!0}t("../shapes/Shape"),t("../shapes/Plane"),e.exports=r,r.prototype.collisionPairs=function(){throw new Error("collisionPairs not implemented for this BroadPhase class!")},r.prototype.needBroadphaseCollision=function(t,e){return 0!=(t.collisionFilterGroup&e.collisionFilterMask)&&0!=(e.collisionFilterGroup&t.collisionFilterMask)&&(!(!t.hasTrigger&&!e.hasTrigger)||0==(t.type&i.STATIC)&&t.sleepState!==i.SLEEPING||0==(e.type&i.STATIC)&&e.sleepState!==i.SLEEPING)},r.prototype.intersectionTest=function(t,e,i,o){this.useBoundingBoxes?this.doBoundingBoxBroadphase(t,e,i,o):this.doBoundingSphereBroadphase(t,e,i,o)};var s=new o;new o,new n,new o,r.prototype.doBoundingSphereBroadphase=function(t,e,i,o){var n=s;e.position.vsub(t.position,n);var r=Math.pow(t.boundingRadius+e.boundingRadius,2);n.norm2()i.norm2()},r.prototype.aabbQuery=function(){return console.warn(".aabbQuery is not implemented in this Broadphase subclass."),[]}},{"../math/Quaternion":30,"../math/Vec3":32,"../objects/Body":33,"../shapes/Plane":44,"../shapes/Shape":45}],6:[function(t,e){e.exports=r;var i=t("./Broadphase"),o=t("../math/Vec3"),n=t("../shapes/Shape");function r(t,e,n,r,s){i.apply(this),this.nx=n||10,this.ny=r||10,this.nz=s||10,this.aabbMin=t||new o(100,100,100),this.aabbMax=e||new o(-100,-100,-100);var a=this.nx*this.ny*this.nz;if(a<=0)throw"GridBroadphase: Each dimension's n must be >0";this.bins=[],this.binLengths=[],this.bins.length=a,this.binLengths.length=a;for(var l=0;l=h&&(a=h-1),l<0?l=0:l>=c&&(l=c-1),f<0?f=0:f>=p&&(f=p-1),v<0?v=0:v>=h&&(v=h-1),m<0?m=0:m>=c&&(m=c-1),S<0?S=0:S>=p&&(S=p-1),l*=d,f*=y,v*=u,m*=d,S*=y;for(var E=a*=u;E<=v;E+=u)for(var M=l;M<=m;M+=d)for(var C=f;C<=S;C+=y){var A=E+M+C;R[A][T[A]++]=s}}for(l=Math.min,a=Math.max,q=0;q!==o;q++){var V=(it=r[q]).shape;switch(V.type){case z:var j=it.position.x,k=it.position.y,N=it.position.z,L=V.radius;I(j-L,k-L,N-L,j+L,k+L,N+L,it);break;case F:V.worldNormalNeedsUpdate&&V.computeWorldNormal(it.quaternion);var W=V.worldNormal,D=g+.5*S-it.position.x,U=b+.5*E-it.position.y,G=w+.5*M-it.position.z,H=s;H.set(D,U,G);for(var K=0,Q=0;K!==h;K++,Q+=u,H.y=U,H.x+=S)for(var X=0,Y=0;X!==c;X++,Y+=d,H.z=G,H.y+=E)for(var Z=0,J=0;Z!==p;Z++,J+=y,H.z+=M)if(H.dot(W)1){var et=R[q];for(K=0;K!==tt;K++){var it=et[K];for(X=0;X!==K;X++){var ot=et[X];this.needBroadphaseCollision(it,ot)&&this.intersectionTest(it,ot,e,i)}}}}this.makePairsUnique(e,i)}},{"../math/Vec3":32,"../shapes/Shape":45,"./Broadphase":5}],7:[function(t,e){e.exports=n;var i=t("./Broadphase"),o=t("./AABB");function n(){i.apply(this)}n.prototype=new i,n.prototype.constructor=n,n.prototype.collisionPairs=function(t,e,i){var o,n,r,s,a=t.bodies,l=a.length;for(o=0;o!==l;o++)for(n=0;n!==o;n++)r=a[o],s=a[n],this.needBroadphaseCollision(r,s)&&this.intersectionTest(r,s,e,i)},new o,n.prototype.aabbQuery=function(t,e,i){i=i||[];for(var o=0;ot){var i=e;e=t,t=i}return t+"-"+e in this.matrix},i.prototype.set=function(t,e,i){if(t=t.id,(e=e.id)>t){var o=e;e=t,t=o}i?this.matrix[t+"-"+e]=!0:delete this.matrix[t+"-"+e]},i.prototype.reset=function(){this.matrix={}},i.prototype.setNumObjects=function(){}},{}],9:[function(t,e){function i(){this.current=[],this.previous=[]}function o(t,e){t.push((4294901760&e)>>16,65535&e)}e.exports=i,i.prototype.getKey=function(t,e){if(eo[n];)n++;if(i!==o[n]){for(e=o.length-1;e>=n;e--)o[e+1]=o[e];o[n]=i}},i.prototype.tick=function(){var t=this.current;this.current=this.previous,this.previous=t,this.current.length=0},i.prototype.getDiff=function(t,e){for(var i=this.current,n=this.previous,r=i.length,s=n.length,a=0,l=0;ln[a];)a++;h===n[a]||o(t,h)}for(a=0,l=0;li[a];)a++;i[a]===c||o(e,c)}}},{}],10:[function(t,e){e.exports=l;var i=t("../math/Vec3"),o=t("../math/Quaternion"),n=t("../math/Transform"),r=(t("../shapes/ConvexPolyhedron"),t("../shapes/Box"),t("../collision/RaycastResult")),s=t("../shapes/Shape"),a=t("../collision/AABB");function l(t,e){this.from=t?t.clone():new i,this.to=e?e.clone():new i,this._direction=new i,this.precision=1e-4,this.checkCollisionResponse=!0,this.skipBackfaces=!1,this.collisionFilterMask=-1,this.collisionFilterGroup=-1,this.mode=l.ANY,this.result=new r,this.hasHit=!1,this.callback=function(){}}l.prototype.constructor=l,l.CLOSEST=1,l.ANY=2,l.ALL=4;var h=new a,c=[];l.prototype.intersectWorld=function(t,e){return this.mode=e.mode||l.ANY,this.result=e.result||new r,this.skipBackfaces=!!e.skipBackfaces,this.checkCollisionResponse=!!e.checkCollisionResponse,this.collisionFilterMask=void 0!==e.collisionFilterMask?e.collisionFilterMask:-1,this.collisionFilterGroup=void 0!==e.collisionFilterGroup?e.collisionFilterGroup:-1,e.from&&this.from.copy(e.from),e.to&&this.to.copy(e.to),this.callback=e.callback||function(){},this.hasHit=!1,this.result.reset(),this._updateDirection(),this.getAABB(h),c.length=0,t.broadphase.aabbQuery(t,h,c),this.intersectBodies(c),this.hasHit};var p=new i,u=new i;function d(t,e,i,o){o.vsub(e,I),i.vsub(e,p),t.vsub(e,u);var n,r,s=I.dot(I),a=I.dot(p),l=I.dot(u),h=p.dot(p),c=p.dot(u);return(n=h*l-a*c)>=0&&(r=s*c-a*l)>=0&&n+rt.boundingSphereRadius)){var n=this[t.type];n&&n.call(this,t,e,i,o,t)}},new i,new i;var v=new i,m=new i,g=new i,b=new i;new i,new r,l.prototype.intersectBox=function(t,e,i,o,n){return this.intersectConvex(t.convexPolyhedronRepresentation,e,i,o,n)},l.prototype[s.types.BOX]=l.prototype.intersectBox,l.prototype.intersectPlane=function(t,e,o,n,r){var s=this.from,a=this.to,l=this._direction,h=new i(0,0,1);e.vmult(h,h);var c=new i;s.vsub(o,c);var p=c.dot(h);if(a.vsub(o,c),!(p*c.dot(h)>0||s.distanceTo(a)=0&&y<=1&&(r.lerp(s,y,u),u.vsub(i,d),d.normalize(),this.reportIntersection(d,u,n,o,-1)),this.result._shouldStop)return;f>=0&&f<=1&&(r.lerp(s,f,u),u.vsub(i,d),d.normalize(),this.reportIntersection(d,u,n,o,-1))}},l.prototype[s.types.SPHERE]=l.prototype.intersectSphere;var M=new i,C=(new i,new i,new i);l.prototype.intersectConvex=function(t,e,i,o,n,r){for(var s=M,a=C,l=r&&r.faceList||null,h=t.faces,c=t.vertices,p=t.faceNormals,u=this._direction,y=this.from,f=this.to,w=y.distanceTo(f),x=l?l.length:h.length,_=this.result,B=0;!_._shouldStop&&Bw||this.reportIntersection(s,v,n,o,S)}}}}},l.prototype[s.types.CONVEXPOLYHEDRON]=l.prototype.intersectConvex;var A=new i,z=new i,F=new i,R=new i,T=new i,P=new i,q=(new a,[]),O=new n;l.prototype.intersectTrimesh=function(t,e,i,o,r,s){var a=A,l=q,h=O,c=C,p=z,u=F,y=R,f=P,w=T,x=(s&&s.faceList,t.indices),_=(t.vertices,t.faceNormals,this.from),B=this.to,S=this._direction;h.position.copy(i),h.quaternion.copy(e),n.vectorToLocalFrame(i,e,S,p),n.pointToLocalFrame(i,e,_,u),n.pointToLocalFrame(i,e,B,y),y.x*=t.scale.x,y.y*=t.scale.y,y.z*=t.scale.z,u.x*=t.scale.x,u.y*=t.scale.y,u.z*=t.scale.z,y.vsub(u,p),p.normalize();var E=u.distanceSquared(y);t.tree.rayQuery(this,h,l);for(var M=0,I=l.length;!this.result._shouldStop&&M!==I;M++){var V=l[M];t.getNormal(V,a),t.getVertex(x[3*V],m),m.vsub(u,c);var j=p.dot(a),k=a.dot(c)/j;if(!(k<0)){p.scale(k,v),v.vadd(u,v),t.getVertex(x[3*V+1],g),t.getVertex(x[3*V+2],b);var N=v.distanceSquared(u);!d(v,g,m,b)&&!d(v,m,g,b)||N>E||(n.vectorToWorldFrame(e,a,w),n.pointToWorldFrame(i,e,v,f),this.reportIntersection(w,f,r,o,V))}}l.length=0},l.prototype[s.types.TRIMESH]=l.prototype.intersectTrimesh,l.prototype.reportIntersection=function(t,e,i,o,n){var r=this.from,s=this.to,a=r.distanceTo(e),h=this.result;if(!(this.skipBackfaces&&t.dot(this._direction)>0))switch(h.hitFaceIndex=void 0!==n?n:-1,this.mode){case l.ALL:this.hasHit=!0,h.set(r,s,t,e,i,o,a),h.hasHit=!0,this.callback(h);break;case l.CLOSEST:(a=0&&!(t[n].aabb.lowerBound.x<=o.aabb.lowerBound.x);n--)t[n+1]=t[n];t[n+1]=o}return t},o.insertionSortY=function(t){for(var e=1,i=t.length;e=0&&!(t[n].aabb.lowerBound.y<=o.aabb.lowerBound.y);n--)t[n+1]=t[n];t[n+1]=o}return t},o.insertionSortZ=function(t){for(var e=1,i=t.length;e=0&&!(t[n].aabb.lowerBound.z<=o.aabb.lowerBound.z);n--)t[n+1]=t[n];t[n+1]=o}return t},o.prototype.collisionPairs=function(t,e,i){var n,r,s=this.axisList,a=s.length,l=this.axisIndex;for(this.dirty&&(this.sortList(),this.dirty=!1),n=0;n!==a;n++){var h=s[n];for(r=n+1;rf?y>v?0:2:f>v?1:2},o.prototype.aabbQuery=function(t,e,i){i=i||[],this.dirty&&(this.sortList(),this.dirty=!1);var o=this.axisIndex,n="x";1===o&&(n="y"),2===o&&(n="z");for(var r=this.axisList,s=(e.lowerBound[n],e.upperBound[n],0);s.499&&(i=2*o.atan2(s,h),n=Math.PI/2,r=0),c<-.499&&(i=-2*o.atan2(s,h),n=-Math.PI/2,r=0),isNaN(i)){var p=s*s,u=a*a,d=l*l;i=o.atan2(2*a*h-2*s*l,1-2*u-2*d),n=Math.asin(2*c),r=o.atan2(2*s*h-2*a*l,1-2*p-2*d)}break;default:throw new Error("Euler order "+e+" not supported yet.")}t.y=i,t.z=n,t.x=r},n.prototype.setFromEuler=function(t,e,i,n){n=n||"XYZ";var r=o.cos(t/2),s=o.cos(e/2),a=o.cos(i/2),l=o.sin(t/2),h=o.sin(e/2),c=o.sin(i/2);return"XYZ"===n?(this.x=l*s*a+r*h*c,this.y=r*h*a-l*s*c,this.z=r*s*c+l*h*a,this.w=r*s*a-l*h*c):"YXZ"===n?(this.x=l*s*a+r*h*c,this.y=r*h*a-l*s*c,this.z=r*s*c-l*h*a,this.w=r*s*a+l*h*c):"ZXY"===n?(this.x=l*s*a-r*h*c,this.y=r*h*a+l*s*c,this.z=r*s*c+l*h*a,this.w=r*s*a-l*h*c):"ZYX"===n?(this.x=l*s*a-r*h*c,this.y=r*h*a+l*s*c,this.z=r*s*c-l*h*a,this.w=r*s*a+l*h*c):"YZX"===n?(this.x=l*s*a+r*h*c,this.y=r*h*a+l*s*c,this.z=r*s*c-l*h*a,this.w=r*s*a-l*h*c):"XZY"===n&&(this.x=l*s*a-r*h*c,this.y=r*h*a-l*s*c,this.z=r*s*c+l*h*a,this.w=r*s*a+l*h*c),this},n.prototype.clone=function(){return new n(this.x,this.y,this.z,this.w)},n.prototype.slerp=function(t,e,i){i=i||new n;var r,s,a,l,h,c=this.x,p=this.y,u=this.z,d=this.w,y=t.x,f=t.y,v=t.z,m=t.w;return(s=c*y+p*f+u*v+d*m)<0&&(s=-s,y=-y,f=-f,v=-v,m=-m),1-s>1e-6?(r=Math.acos(s),a=o.sin(r),l=o.sin((1-e)*r)/a,h=o.sin(e*r)/a):(l=1-e,h=e),i.x=l*c+h*y,i.y=l*p+h*f,i.z=l*u+h*v,i.w=l*d+h*m,i},n.prototype.integrate=function(t,e,i,o){o=o||new n;var r=t.x*i.x,s=t.y*i.y,a=t.z*i.z,l=this.x,h=this.y,c=this.z,p=this.w,u=.5*e;return o.x+=u*(r*p+s*c-a*h),o.y+=u*(s*p+a*l-r*c),o.z+=u*(a*p+r*h-s*l),o.w+=u*(-r*l-s*h-a*c),o}},{"./CMath":27,"./Vec3":32}],31:[function(t,e){var i=t("./Vec3"),o=t("./Quaternion");function n(t){t=t||{},this.position=new i,t.position&&this.position.copy(t.position),this.quaternion=new o,t.quaternion&&this.quaternion.copy(t.quaternion)}e.exports=n;var r=new o;n.pointToLocalFrame=function(t,e,o,n){return n=n||new i,o.vsub(t,n),e.conjugate(r),r.vmult(n,n),n},n.prototype.pointToLocal=function(t,e){return n.pointToLocalFrame(this.position,this.quaternion,t,e)},n.pointToWorldFrame=function(t,e,o,n){return n=n||new i,e.vmult(o,n),n.vadd(t,n),n},n.prototype.pointToWorld=function(t,e){return n.pointToWorldFrame(this.position,this.quaternion,t,e)},n.prototype.vectorToWorldFrame=function(t,e){return e=e||new i,this.quaternion.vmult(t,e),e},n.vectorToWorldFrame=function(t,e,i){return t.vmult(e,i),i},n.vectorToLocalFrame=function(t,e,o,n){return n=n||new i,e.w*=-1,e.vmult(o,n),e.w*=-1,n}},{"./Quaternion":30,"./Vec3":32}],32:[function(t,e){e.exports=o;var i=t("./Mat3");function o(t,e,i){this.x=t||0,this.y=e||0,this.z=i||0}o.ZERO=new o(0,0,0),o.UNIT_X=new o(1,0,0),o.UNIT_Y=new o(0,1,0),o.UNIT_Z=new o(0,0,1),o.prototype.cross=function(t,e){var i=t.x,n=t.y,r=t.z,s=this.x,a=this.y,l=this.z;return(e=e||new o).x=a*r-l*n,e.y=l*i-s*r,e.z=s*n-a*i,e},o.prototype.set=function(t,e,i){return this.x=t,this.y=e,this.z=i,this},o.prototype.setZero=function(){this.x=this.y=this.z=0},o.prototype.vadd=function(t,e){if(!e)return new o(this.x+t.x,this.y+t.y,this.z+t.z);e.x=t.x+this.x,e.y=t.y+this.y,e.z=t.z+this.z},o.prototype.vsub=function(t,e){if(!e)return new o(this.x-t.x,this.y-t.y,this.z-t.z);e.x=this.x-t.x,e.y=this.y-t.y,e.z=this.z-t.z},o.prototype.crossmat=function(){return new i([0,-this.z,this.y,this.z,0,-this.x,-this.y,this.x,0])},o.prototype.normalize=function(){var t=this.x,e=this.y,i=this.z,o=Math.sqrt(t*t+e*e+i*i);if(o>0){var n=1/o;this.x*=n,this.y*=n,this.z*=n}else this.x=0,this.y=0,this.z=0;return o},o.prototype.unit=function(t){t=t||new o;var e=this.x,i=this.y,n=this.z,r=Math.sqrt(e*e+i*i+n*n);return r>0?(r=1/r,t.x=e*r,t.y=i*r,t.z=n*r):(t.x=1,t.y=0,t.z=0),t},o.prototype.norm=function(){var t=this.x,e=this.y,i=this.z;return Math.sqrt(t*t+e*e+i*i)},o.prototype.length=o.prototype.norm,o.prototype.norm2=function(){return this.dot(this)},o.prototype.lengthSquared=o.prototype.norm2,o.prototype.distanceTo=function(t){var e=this.x,i=this.y,o=this.z,n=t.x,r=t.y,s=t.z;return Math.sqrt((n-e)*(n-e)+(r-i)*(r-i)+(s-o)*(s-o))},o.prototype.distanceSquared=function(t){var e=this.x,i=this.y,o=this.z,n=t.x,r=t.y,s=t.z;return(n-e)*(n-e)+(r-i)*(r-i)+(s-o)*(s-o)},o.prototype.mult=function(t,e){e=e||new o;var i=this.x,n=this.y,r=this.z;return e.x=t*i,e.y=t*n,e.z=t*r,e},o.prototype.vmul=function(t,e){return(e=e||new o).x=t.x*this.x,e.y=t.y*this.y,e.z=t.z*this.z,e},o.prototype.scale=o.prototype.mult,o.prototype.addScaledVector=function(t,e,i){return(i=i||new o).x=this.x+t*e.x,i.y=this.y+t*e.y,i.z=this.z+t*e.z,i},o.prototype.dot=function(t){return this.x*t.x+this.y*t.y+this.z*t.z},o.prototype.isZero=function(){return 0===this.x&&0===this.y&&0===this.z},o.prototype.negate=function(t){return(t=t||new o).x=-this.x,t.y=-this.y,t.z=-this.z,t};var n=new o,r=new o;o.prototype.tangents=function(t,e){var i=this.norm();if(i>0){var o=n,s=1/i;o.set(this.x*s,this.y*s,this.z*s);var a=r;Math.abs(o.x)<.9?(a.set(1,0,0),o.cross(a,t)):(a.set(0,1,0),o.cross(a,t)),o.cross(t,e)}else t.set(1,0,0),e.set(0,1,0)},o.prototype.toString=function(){return this.x+","+this.y+","+this.z},o.prototype.toArray=function(){return[this.x,this.y,this.z]},o.prototype.copy=function(t){return this.x=t.x,this.y=t.y,this.z=t.z,this},o.prototype.lerp=function(t,e,i){var o=this.x,n=this.y,r=this.z;i.x=o+(t.x-o)*e,i.y=n+(t.y-n)*e,i.z=r+(t.z-r)*e},o.prototype.almostEquals=function(t,e){return void 0===e&&(e=1e-6),!(Math.abs(this.x-t.x)>e||Math.abs(this.y-t.y)>e||Math.abs(this.z-t.z)>e)},o.prototype.almostZero=function(t){return void 0===t&&(t=1e-6),!(Math.abs(this.x)>t||Math.abs(this.y)>t||Math.abs(this.z)>t)};var s=new o;o.prototype.isAntiparallelTo=function(t,e){return this.negate(s),s.almostEquals(t,e)},o.prototype.clone=function(){return new o(this.x,this.y,this.z)}},{"./Mat3":29}],33:[function(t,e){e.exports=h;var i=t("../utils/EventTarget"),o=(t("../shapes/Shape"),t("../math/Vec3")),n=t("../math/Mat3"),r=t("../math/Quaternion"),s=(t("../material/Material"),t("../collision/AABB")),a=t("../shapes/Box"),l=t("../world/World");function h(t){t=t||{},i.apply(this),this.id=h.idCounter++,this.world=null,this.preStep=null,this.postStep=null,this.vlambda=new o,this.collisionFilterGroup="number"==typeof t.collisionFilterGroup?t.collisionFilterGroup:1,this.collisionFilterMask="number"==typeof t.collisionFilterMask?t.collisionFilterMask:-1,this.collisionResponse=!0,this.position=new o,this.previousPosition=new o,this.interpolatedPosition=new o,this.initPosition=new o,t.position&&(this.position.copy(t.position),this.previousPosition.copy(t.position),this.interpolatedPosition.copy(t.position),this.initPosition.copy(t.position)),this.velocity=new o,t.velocity&&this.velocity.copy(t.velocity),this.initVelocity=new o,this.force=new o;var e="number"==typeof t.mass?t.mass:0;this.mass=e,this.invMass=e>0?1/e:0,this.material=t.material||null,this.linearDamping="number"==typeof t.linearDamping?t.linearDamping:.01,this.type=e<=0?h.STATIC:h.DYNAMIC,typeof t.type==typeof h.STATIC&&(this.type=t.type),this.allowSleep=void 0===t.allowSleep||t.allowSleep,this.sleepState=0,this.sleepSpeedLimit=void 0!==t.sleepSpeedLimit?t.sleepSpeedLimit:.1,this.sleepTimeLimit=void 0!==t.sleepTimeLimit?t.sleepTimeLimit:1,this.timeLastSleepy=0,this._wakeUpAfterNarrowphase=!1,this.torque=new o,this.quaternion=new r,this.initQuaternion=new r,this.previousQuaternion=new r,this.interpolatedQuaternion=new r,t.quaternion&&(this.quaternion.copy(t.quaternion),this.initQuaternion.copy(t.quaternion),this.previousQuaternion.copy(t.quaternion),this.interpolatedQuaternion.copy(t.quaternion)),this.angularVelocity=new o,t.angularVelocity&&this.angularVelocity.copy(t.angularVelocity),this.initAngularVelocity=new o,this.shapes=[],this.shapeOffsets=[],this.shapeOrientations=[],this.inertia=new o,this.invInertia=new o,this.invInertiaWorld=new n,this.invMassSolve=0,this.invInertiaSolve=new o,this.invInertiaWorldSolve=new n,this.fixedRotation=void 0!==t.fixedRotation&&t.fixedRotation,this.useGravity=!0,this.angularDamping=void 0!==t.angularDamping?t.angularDamping:.01,this.linearFactor=new o(1,1,1),t.linearFactor&&this.linearFactor.copy(t.linearFactor),this.angularFactor=new o(1,1,1),t.angularFactor&&this.angularFactor.copy(t.angularFactor),this.aabb=new s,this.aabbNeedsUpdate=!0,this.boundingRadius=0,this.wlambda=new o,t.shape&&this.addShape(t.shape),this.hasTrigger=!0,this.updateMassProperties()}h.prototype=new i,h.prototype.constructor=h,h.COLLIDE_EVENT_NAME="collide",h.DYNAMIC=1,h.STATIC=2,h.KINEMATIC=4,h.AWAKE=0,h.SLEEPY=1,h.SLEEPING=2,h.idCounter=0,h.wakeupEvent={type:"wakeup"},h.prototype.wakeUp=function(){l.SLEEPING=!1;var t=this.sleepState;this.sleepState=0,this._wakeUpAfterNarrowphase=!1,t===h.SLEEPING&&this.dispatchEvent(h.wakeupEvent)},h.prototype.sleep=function(){this.sleepState=h.SLEEPING,this.velocity.set(0,0,0),this.angularVelocity.set(0,0,0),this._wakeUpAfterNarrowphase=!1},h.sleepyEvent={type:"sleepy"},h.sleepEvent={type:"sleep"},h.prototype.sleepTick=function(t){if(this.allowSleep){var e=this.sleepState,i=this.velocity.norm2()+this.angularVelocity.norm2(),o=Math.pow(this.sleepSpeedLimit,2);e===h.AWAKE&&io?this.wakeUp():e===h.SLEEPY&&t-this.timeLastSleepy>this.sleepTimeLimit&&(this.sleep(),this.dispatchEvent(h.sleepEvent))}},h.prototype.updateSolveMassProperties=function(){this.sleepState===h.SLEEPING||this.type===h.KINEMATIC?(this.invMassSolve=0,this.invInertiaSolve.setZero(),this.invInertiaWorldSolve.setZero()):(this.invMassSolve=this.invMass,this.invInertiaSolve.copy(this.invInertia),this.invInertiaWorldSolve.copy(this.invInertiaWorld))},h.prototype.pointToLocalFrame=function(t,e){return e=e||new o,t.vsub(this.position,e),this.quaternion.conjugate().vmult(e,e),e},h.prototype.vectorToLocalFrame=function(t,e){return e=e||new o,this.quaternion.conjugate().vmult(t,e),e},h.prototype.pointToWorldFrame=function(t,e){return e=e||new o,this.quaternion.vmult(t,e),e.vadd(this.position,e),e},h.prototype.vectorToWorldFrame=function(t,e){return e=e||new o,this.quaternion.vmult(t,e),e};var c=new o,p=new r;h.prototype.addShape=function(t,e,i){var n=new o,s=new r;return e&&n.copy(e),i&&s.copy(i),this.shapes.push(t),this.shapeOffsets.push(n),this.shapeOrientations.push(s),this.aabbNeedsUpdate=!0,this.updateMassProperties(),this.updateBoundingRadius(),this.updateHasTrigger(),l.idToShapeMap[t.id]=t,t.body=this,this},h.prototype.removeShape=function(t){var e=this.shapes.indexOf(t);-1!==e&&(this.shapes.splice(e,1),this.shapeOffsets.splice(e,1),this.shapeOrientations.splice(e,1),this.aabbNeedsUpdate=!0,this.updateMassProperties(),this.updateBoundingRadius(),this.updateHasTrigger())},h.prototype.updateBoundingRadius=function(){for(var t=this.shapes,e=this.shapeOffsets,i=t.length,o=0,n=0;n!==i;n++){var r=t[n];r.updateBoundingSphereRadius();var s=e[n].norm(),a=r.boundingSphereRadius;s+a>o&&(o=s+a)}this.boundingRadius=o};var u=new s;h.prototype.computeAABB=function(){for(var t=this.shapes,e=this.shapeOffsets,i=this.shapeOrientations,o=t.length,n=c,r=p,s=this.quaternion,a=this.aabb,l=u,h=0;h!==o;h++){var d=t[h];s.vmult(e[h],n),n.vadd(this.position,n),i[h].mult(s,r),d.calculateWorldAABB(n,r,l.lowerBound,l.upperBound),0===h?a.copy(l):a.extend(l)}this.aabbNeedsUpdate=!1};var d=new n,y=new n;new n,h.prototype.updateInertiaWorld=function(t){var e=this.invInertia;if(e.x!==e.y||e.y!==e.z||t){var i=d,o=y;i.setRotationFromQuaternion(this.quaternion),i.transpose(o),i.scale(e,i),i.mmult(o,this.invInertiaWorld)}},new o;var f=new o;h.prototype.applyForce=function(t,e){if(this.type===h.DYNAMIC){var i=f;e.cross(t,i),this.force.vadd(t,this.force),this.torque.vadd(i,this.torque)}};var v=new o,m=new o;h.prototype.applyLocalForce=function(t,e){if(this.type===h.DYNAMIC){var i=v,o=m;this.vectorToWorldFrame(t,i),this.vectorToWorldFrame(e,o),this.applyForce(i,o)}},new o;var g=new o,b=new o;h.prototype.applyImpulse=function(t,e){if(this.type===h.DYNAMIC){var i=e,o=g;o.copy(t),o.mult(this.invMass,o),this.velocity.vadd(o,this.velocity);var n=b;i.cross(t,n),this.invInertiaWorld.vmult(n,n),this.angularVelocity.vadd(n,this.angularVelocity)}};var w=new o,x=new o;h.prototype.applyLocalImpulse=function(t,e){if(this.type===h.DYNAMIC){var i=w,o=x;this.vectorToWorldFrame(t,i),this.vectorToWorldFrame(e,o),this.applyImpulse(i,o)}};var _=new o;h.prototype.updateMassProperties=function(){var t=_;this.invMass=this.mass>0?1/this.mass:0;var e=this.inertia,i=this.fixedRotation;this.computeAABB(),t.set((this.aabb.upperBound.x-this.aabb.lowerBound.x)/2,(this.aabb.upperBound.y-this.aabb.lowerBound.y)/2,(this.aabb.upperBound.z-this.aabb.lowerBound.z)/2),a.calculateInertia(t,this.mass,e),this.invInertia.set(e.x>0&&!i?1/e.x:0,e.y>0&&!i?1/e.y:0,e.z>0&&!i?1/e.z:0),this.updateInertiaWorld(!0)},h.prototype.getVelocityAtWorldPoint=function(t,e){var i=new o;return t.vsub(this.position,i),this.angularVelocity.cross(i,e),this.velocity.vadd(e,e),e},new o,new o,new r,new r,h.prototype.integrate=function(t,e,i){if(this.previousPosition.copy(this.position),this.previousQuaternion.copy(this.quaternion),(this.type===h.DYNAMIC||this.type===h.KINEMATIC)&&this.sleepState!==h.SLEEPING){var o=this.velocity,n=this.angularVelocity,r=this.position,s=this.force,a=this.torque,l=this.quaternion,c=this.invMass,p=this.invInertiaWorld,u=this.linearFactor,d=c*t;o.x+=s.x*d*u.x,o.y+=s.y*d*u.y,o.z+=s.z*d*u.z;var y=p.elements,f=this.angularFactor,v=a.x*f.x,m=a.y*f.y,g=a.z*f.z;n.x+=t*(y[0]*v+y[1]*m+y[2]*g),n.y+=t*(y[3]*v+y[4]*m+y[5]*g),n.z+=t*(y[6]*v+y[7]*m+y[8]*g),r.x+=o.x*t,r.y+=o.y*t,r.z+=o.z*t,l.integrate(this.angularVelocity,t,this.angularFactor,l),e&&(i?l.normalizeFast():l.normalize()),this.aabbNeedsUpdate=!0,this.updateInertiaWorld()}},h.prototype.isSleeping=function(){return this.sleepState===h.SLEEPING},h.prototype.isSleepy=function(){return this.sleepState===h.SLEEPY},h.prototype.isAwake=function(){return this.sleepState===h.AWAKE},h.prototype.updateHasTrigger=function(){for(var t=this.shapes.length;t--&&(this.hasTrigger=!this.shapes[t].collisionResponse,!this.hasTrigger););}},{"../collision/AABB":3,"../material/Material":26,"../math/Mat3":29,"../math/Quaternion":30,"../math/Vec3":32,"../shapes/Box":39,"../shapes/Shape":45,"../utils/EventTarget":51,"../world/World":58}],34:[function(t,e){t("./Body");var i=t("../math/Vec3"),o=t("../math/Quaternion"),n=(t("../collision/RaycastResult"),t("../collision/Ray")),r=t("../objects/WheelInfo");function s(t){this.chassisBody=t.chassisBody,this.wheelInfos=[],this.sliding=!1,this.world=null,this.indexRightAxis=void 0!==t.indexRightAxis?t.indexRightAxis:1,this.indexForwardAxis=void 0!==t.indexForwardAxis?t.indexForwardAxis:0,this.indexUpAxis=void 0!==t.indexUpAxis?t.indexUpAxis:2}e.exports=s,new i,new i,new i;var a=new i,l=new i,h=new i;new n,s.prototype.addWheel=function(t){var e=new r(t=t||{}),i=this.wheelInfos.length;return this.wheelInfos.push(e),i},s.prototype.setSteeringValue=function(t,e){this.wheelInfos[e].steering=t},new i,s.prototype.applyEngineForce=function(t,e){this.wheelInfos[e].engineForce=t},s.prototype.setBrake=function(t,e){this.wheelInfos[e].brake=t},s.prototype.addToWorld=function(t){this.constraints,t.addBody(this.chassisBody);var e=this;this.preStepCallback=function(){e.updateVehicle(t.dt)},t.addEventListener("preStep",this.preStepCallback),this.world=t},s.prototype.getVehicleAxisWorld=function(t,e){e.set(0===t?1:0,1===t?1:0,2===t?1:0),this.chassisBody.vectorToWorldFrame(e,e)},s.prototype.updateVehicle=function(t){for(var e=this.wheelInfos,o=e.length,n=this.chassisBody,r=0;rd.maxSuspensionForce&&(h=d.maxSuspensionForce),d.raycastResult.hitNormalWorld.scale(h*t,a),d.raycastResult.hitPointWorld.vsub(n.position,l),n.applyImpulse(a,l)}this.updateFriction(t);var c=new i,p=new i,u=new i;for(r=0;r0?1:-1)*d.customSlidingRotationalSpeed*t),Math.abs(d.brake)>Math.abs(d.engineForce)&&(d.deltaRotation=0),d.rotation+=d.deltaRotation,d.deltaRotation*=.99}},s.prototype.updateSuspension=function(){for(var t=this.chassisBody.mass,e=this.wheelInfos,i=e.length,o=0;of&&(t.suspensionLength=f,t.raycastResult.reset());var v=t.raycastResult.hitNormalWorld.dot(t.directionWorld),m=new i;n.getVelocityAtWorldPoint(t.raycastResult.hitPointWorld,m);var g=t.raycastResult.hitNormalWorld.dot(m);if(v>=-.1)t.suspensionRelativeVelocity=0,t.clippedInvContactDotSuspension=10;else{var b=-1/v;t.suspensionRelativeVelocity=g*b,t.clippedInvContactDotSuspension=b}}else t.suspensionLength=t.suspensionRestLength+0*t.maxSuspensionTravel,t.suspensionRelativeVelocity=0,t.directionWorld.scale(-1,t.raycastResult.hitNormalWorld),t.clippedInvContactDotSuspension=1;return r},s.prototype.updateWheelTransformWorld=function(t){t.isInContact=!1;var e=this.chassisBody;e.pointToWorldFrame(t.chassisConnectionPointLocal,t.chassisConnectionPointWorld),e.vectorToWorldFrame(t.directionLocal,t.directionWorld),e.vectorToWorldFrame(t.axleLocal,t.axleWorld)},s.prototype.updateWheelTransform=function(t){var e=a,i=l,n=h,r=this.wheelInfos[t];this.updateWheelTransformWorld(r),r.directionLocal.scale(-1,e),i.copy(r.axleLocal),e.cross(i,n),n.normalize(),i.normalize();var s=r.steering,c=new o;c.setFromAxisAngle(e,s);var p=new o;p.setFromAxisAngle(i,r.rotation);var u=r.worldTransform.quaternion;this.chassisBody.quaternion.mult(c,u),u.mult(p,u),u.normalize();var d=r.worldTransform.position;d.copy(r.directionWorld),d.scale(r.suspensionLength,d),d.vadd(r.chassisConnectionPointWorld,d)};var u=[new i(1,0,0),new i(0,1,0),new i(0,0,1)];s.prototype.getWheelTransformWorld=function(t){return this.wheelInfos[t].worldTransform};var d=new i,y=[],f=[];s.prototype.updateFriction=function(t){for(var e=d,o=this.wheelInfos,n=o.length,r=this.chassisBody,s=f,a=y,l=0;l_&&(this.sliding=!0,M.sliding=!0,w=x/Math.sqrt(E),M.skidInfo*=w)}}if(this.sliding)for(l=0;l1.1)return 0;var r=E,s=M,a=C;return t.getVelocityAtWorldPoint(e,r),i.getVelocityAtWorldPoint(o,s),r.vsub(s,a),-.2*n.dot(a)*(1/(t.invMass+i.invMass))}},{"../collision/Ray":10,"../collision/RaycastResult":11,"../math/Quaternion":30,"../math/Vec3":32,"../objects/WheelInfo":38,"./Body":33}],35:[function(t,e){var i=t("./Body"),o=t("../shapes/Sphere"),n=t("../shapes/Box"),r=t("../math/Vec3"),s=t("../constraints/HingeConstraint"),a=t("../math/CMath");function l(t){if(this.wheelBodies=[],this.coordinateSystem=void 0===t.coordinateSystem?new r(1,2,3):t.coordinateSystem.clone(),this.chassisBody=t.chassisBody,!this.chassisBody){var e=new n(new r(5,2,.5));this.chassisBody=new i(1,e)}this.constraints=[],this.wheelAxes=[],this.wheelForces=[]}e.exports=l,l.prototype.addWheel=function(t){var e=(t=t||{}).body;e||(e=new i(1,new o(1.2))),this.wheelBodies.push(e),this.wheelForces.push(0),new r;var n=void 0!==t.position?t.position.clone():new r,a=new r;this.chassisBody.pointToWorldFrame(n,a),e.position.set(a.x,a.y,a.z);var l=void 0!==t.axis?t.axis.clone():new r(0,1,0);this.wheelAxes.push(l);var h=new s(this.chassisBody,e,{pivotA:n,axisA:l,pivotB:r.ZERO,axisB:l,collideConnected:!1});return this.constraints.push(h),this.wheelBodies.length-1},l.prototype.setSteeringValue=function(t,e){var i=this.wheelAxes[e],o=a.cos(t),n=a.sin(t),r=i.x,s=i.y;this.constraints[e].axisA.set(o*r-n*s,n*r+o*s,0)},l.prototype.setMotorSpeed=function(t,e){var i=this.constraints[e];i.enableMotor(),i.motorTargetVelocity=t},l.prototype.disableMotor=function(t){this.constraints[t].disableMotor()};var h=new r;l.prototype.setWheelForce=function(t,e){this.wheelForces[e]=t},l.prototype.applyWheelForce=function(t,e){var i=this.wheelAxes[e],o=this.wheelBodies[e],n=o.torque;i.scale(t,h),o.vectorToWorldFrame(h,h),n.vadd(h,n)},l.prototype.addToWorld=function(t){for(var e=this.constraints,i=this.wheelBodies.concat([this.chassisBody]),o=0;othis.particles.length&&this.neighbors.pop())};var n=new i;o.prototype.getNeighbors=function(t,e){for(var i=this.particles.length,o=t.id,r=this.smoothingRadius*this.smoothingRadius,s=n,a=0;a!==i;a++){var l=this.particles[a];l.position.vsub(t.position,s),o!==l.id&&s.norm2()=-.1)this.suspensionRelativeVelocity=0,this.clippedInvContactDotSuspension=10;else{var n=-1/i;this.suspensionRelativeVelocity=o*n,this.clippedInvContactDotSuspension=n}}else e.suspensionLength=this.suspensionRestLength,this.suspensionRelativeVelocity=0,e.directionWorld.scale(-1,e.hitNormalWorld),this.clippedInvContactDotSuspension=1}},{"../collision/RaycastResult":11,"../math/Transform":31,"../math/Vec3":32,"../utils/Utils":55}],39:[function(t,e){e.exports=r;var i=t("./Shape"),o=t("../math/Vec3"),n=t("./ConvexPolyhedron");function r(t){i.call(this,{type:i.types.BOX}),this.halfExtents=t,this.convexPolyhedronRepresentation=null,this.updateConvexPolyhedronRepresentation(),this.updateBoundingSphereRadius()}r.prototype=new i,r.prototype.constructor=r,r.prototype.updateConvexPolyhedronRepresentation=function(){var t=this.halfExtents.x,e=this.halfExtents.y,i=this.halfExtents.z,r=o,s=[new r(-t,-e,-i),new r(t,-e,-i),new r(t,e,-i),new r(-t,e,-i),new r(-t,-e,i),new r(t,-e,i),new r(t,e,i),new r(-t,e,i)],a=(new r(0,0,1),new r(0,1,0),new r(1,0,0),new n(s,[[3,2,1,0],[4,5,6,7],[5,4,0,1],[2,3,7,6],[0,4,7,3],[1,2,6,5]]));this.convexPolyhedronRepresentation=a,a.material=this.material},r.prototype.calculateLocalInertia=function(t,e){return e=e||new o,r.calculateInertia(this.halfExtents,t,e),e},r.calculateInertia=function(t,e,i){var o=t;o.isZero()?(i.x=2/12*e,i.y=2/12*e,i.z=2/12*e):(i.x=1/12*e*(4*o.y*o.y+4*o.z*o.z),i.y=1/12*e*(4*o.x*o.x+4*o.z*o.z),i.z=1/12*e*(4*o.y*o.y+4*o.x*o.x))},r.prototype.getSideNormals=function(t,e){var i=t,o=this.halfExtents;if(i[0].set(o.x,0,0),i[1].set(0,o.y,0),i[2].set(0,0,o.z),i[3].set(-o.x,0,0),i[4].set(0,-o.y,0),i[5].set(0,0,-o.z),void 0!==e)for(var n=0;n!==i.length;n++)e.vmult(i[n],i[n]);return i},r.prototype.volume=function(){return 8*this.halfExtents.x*this.halfExtents.y*this.halfExtents.z},r.prototype.updateBoundingSphereRadius=function(){this.boundingSphereRadius=this.halfExtents.norm()};var s=new o;new o,r.prototype.forEachWorldCorner=function(t,e,i){for(var o=this.halfExtents,n=[[o.x,o.y,o.z],[-o.x,o.y,o.z],[-o.x,-o.y,o.z],[-o.x,-o.y,-o.z],[o.x,-o.y,-o.z],[o.x,o.y,-o.z],[-o.x,o.y,-o.z],[o.x,-o.y,o.z]],r=0;ro.x&&(o.x=l),h>o.y&&(o.y=h),c>o.z&&(o.z=c),ld&&(d=f,u=y)}for(var v=[],m=i.faces[u],g=m.length,b=0;b=0&&this.clipFaceAgainstHull(s,t,e,v,a,l,c)};var c=new o,p=new o,u=new o,d=new o,y=new o,f=new o;r.prototype.findSeparatingAxis=function(t,e,i,o,n,r,s,a){var l=c,h=p,v=u,m=d,g=y,b=f,w=Number.MAX_VALUE;if(this.uniqueAxes)for(_=0;_!==this.uniqueAxes.length;_++){if(i.vmult(this.uniqueAxes[_],l),!1===(E=this.testSepAxis(l,t,e,i,o,n)))return!1;E0&&r.negate(r),!0};var v=[],m=[];r.prototype.testSepAxis=function(t,e,i,o,n,s){r.project(this,t,i,o,v),r.project(e,t,n,s,m);var a=v[0],l=v[1],h=m[0],c=m[1];if(ae.x&&(e.x=r.x),r.ye.y&&(e.y=r.y),r.ze.z&&(e.z=r.z)}},r.prototype.computeWorldFaceNormals=function(t){for(var e=this.faceNormals.length;this.worldFaceNormals.lengtht&&(t=n)}this.boundingSphereRadius=Math.sqrt(t)};var A=new o;r.prototype.calculateWorldAABB=function(t,e,i,o){for(var n,r,s,a,l,h,c=this.vertices.length,p=this.vertices,u=0;ua||void 0===a)&&(a=d.x),(d.yl||void 0===l)&&(l=d.y),(d.zh||void 0===h)&&(h=d.z)}i.set(n,r,s),o.set(a,l,h)},r.prototype.volume=function(){return 4*Math.PI*this.boundingSphereRadius/3},r.prototype.getAveragePointLocal=function(t){t=t||new o;for(var e=this.vertices.length,i=this.vertices,n=0;n0||c>0&&u<0)return!1}return-1},new o;var T=new o,P=new o;r.project=function(t,e,i,o,r){var s=t.vertices.length,a=T,l=0,h=0,c=P,p=t.vertices;c.setZero(),n.vectorToLocalFrame(i,o,e,a),n.pointToLocalFrame(i,o,c,c);var u=c.dot(a);h=l=p[0].dot(a);for(var d=1;dl&&(l=y),y(l-=u)){var f=h;h=l,l=f}r[0]=l,r[1]=h}},{"../math/Quaternion":30,"../math/Transform":31,"../math/Vec3":32,"./Shape":45}],41:[function(t,e){e.exports=r,t("./Shape");var i=t("../math/Vec3"),o=(t("../math/Quaternion"),t("./ConvexPolyhedron")),n=t("../math/CMath");function r(t,e,r,s,a){if(a){for(var l=s,h=n.cos,c=n.sin,p=r/2,u=[],d=[],y=[0],f=[1],v=[],m=2*Math.PI/l,g=0;ge&&(e=n)}this.maxValue=e},s.prototype.setHeightValueAtIndex=function(t,e,i){this.data[t][e]=i,this.clearCachedConvexTrianglePillar(t,e,!1),t>0&&(this.clearCachedConvexTrianglePillar(t-1,e,!0),this.clearCachedConvexTrianglePillar(t-1,e,!1)),e>0&&(this.clearCachedConvexTrianglePillar(t,e-1,!0),this.clearCachedConvexTrianglePillar(t,e-1,!1)),e>0&&t>0&&this.clearCachedConvexTrianglePillar(t-1,e-1,!0)},s.prototype.getRectMinMax=function(t,e,i,o,n){n=n||[];for(var r=this.data,s=this.minValue,a=t;a<=i;a++)for(var l=e;l<=o;l++){var h=r[a][l];h>s&&(s=h)}n[0]=this.minValue,n[1]=s},s.prototype.getIndexOfPosition=function(t,e,i,o){var n=this.elementSize,r=this.data,s=Math.floor(t/n),a=Math.floor(e/n);return i[0]=s,i[1]=a,o&&(s<0&&(s=0),a<0&&(a=0),s>=r.length-1&&(s=r.length-1),a>=r[0].length-1&&(a=r[0].length-1)),!(s<0||a<0||s>=r.length-1||a>=r[0].length-1)};var a=[],l=new n,h=new n,c=new n,p=new n;s.prototype.getTriangleAt=function(t,e,i,o,n,r){var s=a;this.getIndexOfPosition(t,e,s,i);var l=s[0],h=s[1],c=this.data;i&&(l=Math.min(c.length-2,Math.max(0,l)),h=Math.min(c[0].length-2,Math.max(0,h)));var p=this.elementSize,u=Math.pow(t/p-l,2)+Math.pow(e/p-h,2)>Math.pow(t/p-(l+1),2)+Math.pow(e/p-(h+1),2);return this.getTriangle(l,h,u,o,n,r),u};var u=new n,d=new n,y=new n,f=new n,v=new n;function m(t,e,i,o,n,r,s,a,l){l.x=((r-a)*(t-s)+(s-n)*(e-a))/((r-a)*(i-s)+(s-n)*(o-a)),l.y=((a-o)*(t-s)+(i-s)*(e-a))/((r-a)*(i-s)+(s-n)*(o-a)),l.z=1-l.x-l.y}s.prototype.getNormalAt=function(t,e,i,o){var n=u,r=d,s=y,a=f,l=v;this.getTriangleAt(t,e,i,n,r,s),r.vsub(n,a),s.vsub(n,l),a.cross(l,o),o.normalize()},s.prototype.getAabbAtIndex=function(t,e,i){var o=this.data,n=this.elementSize;i.lowerBound.set(t*n,e*n,o[t][e]),i.upperBound.set((t+1)*n,(e+1)*n,o[t+1][e+1])},s.prototype.getHeightAt=function(t,e,i){var o=this.data,n=h,r=c,s=p,u=a;this.getIndexOfPosition(t,e,u,i);var d=u[0],y=u[1];i&&(d=Math.min(o.length-2,Math.max(0,d)),y=Math.min(o[0].length-2,Math.max(0,y)));var f=this.getTriangleAt(t,e,i,n,r,s);m(t,e,n.x,n.y,r.x,r.y,s.x,s.y,l);var v=l;return f?o[d+1][y+1]*v.x+o[d][y+1]*v.y+o[d+1][y]*v.z:o[d][y]*v.x+o[d+1][y]*v.y+o[d][y+1]*v.z},s.prototype.getCacheConvexTrianglePillarKey=function(t,e,i){return t+"_"+e+"_"+(i?1:0)},s.prototype.getCachedConvexTrianglePillar=function(t,e,i){return this._cachedPillars[this.getCacheConvexTrianglePillarKey(t,e,i)]},s.prototype.setCachedConvexTrianglePillar=function(t,e,i,o,n){this._cachedPillars[this.getCacheConvexTrianglePillarKey(t,e,i)]={convex:o,offset:n}},s.prototype.clearCachedConvexTrianglePillar=function(t,e,i){delete this._cachedPillars[this.getCacheConvexTrianglePillarKey(t,e,i)]},s.prototype.getTriangle=function(t,e,i,o,n,r){var s=this.data,a=this.elementSize;i?(o.set((t+1)*a,(e+1)*a,s[t+1][e+1]),n.set(t*a,(e+1)*a,s[t][e+1]),r.set((t+1)*a,e*a,s[t+1][e])):(o.set(t*a,e*a,s[t][e]),n.set((t+1)*a,e*a,s[t+1][e]),r.set(t*a,(e+1)*a,s[t][e+1]))},s.prototype.getConvexTrianglePillar=function(t,e,i){var r=this.pillarConvex,s=this.pillarOffset;if(this.cacheEnabled){if(a=this.getCachedConvexTrianglePillar(t,e,i))return this.pillarConvex=a.convex,void(this.pillarOffset=a.offset);r=new o,s=new n,this.pillarConvex=r,this.pillarOffset=s}var a=this.data,l=this.elementSize,h=r.faces;r.vertices.length=6;for(var c=0;c<6;c++)r.vertices[c]||(r.vertices[c]=new n);for(h.length=5,c=0;c<5;c++)h[c]||(h[c]=[]);var p=r.vertices,u=(Math.min(a[t][e],a[t+1][e],a[t][e+1],a[t+1][e+1])-this.minValue)/2+this.minValue;i?(s.set((t+.75)*l,(e+.75)*l,u),p[0].set(.25*l,.25*l,a[t+1][e+1]-u),p[1].set(-.75*l,.25*l,a[t][e+1]-u),p[2].set(.25*l,-.75*l,a[t+1][e]-u),p[3].set(.25*l,.25*l,-u-1),p[4].set(-.75*l,.25*l,-u-1),p[5].set(.25*l,-.75*l,-u-1),h[0][0]=0,h[0][1]=1,h[0][2]=2,h[1][0]=5,h[1][1]=4,h[1][2]=3,h[2][0]=2,h[2][1]=5,h[2][2]=3,h[2][3]=0,h[3][0]=3,h[3][1]=4,h[3][2]=1,h[3][3]=0,h[4][0]=1,h[4][1]=4,h[4][2]=5,h[4][3]=2):(s.set((t+.25)*l,(e+.25)*l,u),p[0].set(-.25*l,-.25*l,a[t][e]-u),p[1].set(.75*l,-.25*l,a[t+1][e]-u),p[2].set(-.25*l,.75*l,a[t][e+1]-u),p[3].set(-.25*l,-.25*l,-u-1),p[4].set(.75*l,-.25*l,-u-1),p[5].set(-.25*l,.75*l,-u-1),h[0][0]=0,h[0][1]=1,h[0][2]=2,h[1][0]=5,h[1][1]=4,h[1][2]=3,h[2][0]=0,h[2][1]=2,h[2][2]=5,h[2][3]=3,h[3][0]=1,h[3][1]=0,h[3][2]=3,h[3][3]=4,h[4][0]=4,h[4][1]=5,h[4][2]=2,h[4][3]=1),r.computeNormals(),r.computeEdges(),r.updateBoundingSphereRadius(),this.setCachedConvexTrianglePillar(t,e,i,r,s)},s.prototype.calculateLocalInertia=function(t,e){return(e=e||new n).set(0,0,0),e},s.prototype.volume=function(){return Number.MAX_VALUE},s.prototype.calculateWorldAABB=function(t,e,i,o){i.set(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE),o.set(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE)},s.prototype.updateBoundingSphereRadius=function(){var t=this.data,e=this.elementSize;this.boundingSphereRadius=new n(t.length*e,t[0].length*e,Math.max(Math.abs(this.maxValue),Math.abs(this.minValue))).norm()},s.prototype.setHeightsFromImage=function(t,e){var i=document.createElement("canvas");i.width=t.width,i.height=t.height;var o=i.getContext("2d");o.drawImage(t,0,0);var n=o.getImageData(0,0,t.width,t.height),r=this.data;r.length=0,this.elementSize=Math.abs(e.x)/n.width;for(var s=0;si.x&&(i.x=n.x),n.yi.y&&(i.y=n.y),n.zi.z&&(i.z=n.z)},l.prototype.updateAABB=function(){this.computeLocalAABB(this.aabb)},l.prototype.updateBoundingSphereRadius=function(){for(var t=0,e=this.vertices,i=new o,n=0,r=e.length/3;n!==r;n++){this.getVertex(n,i);var s=i.norm2();s>t&&(t=s)}this.boundingSphereRadius=Math.sqrt(t)},new o;var w=new n,x=new r;l.prototype.calculateWorldAABB=function(t,e,i,o){var n=w,r=x;n.position=t,n.quaternion=e,this.aabb.toWorldFrame(n,r),i.copy(r.lowerBound),o.copy(r.upperBound)},l.prototype.volume=function(){return 4*Math.PI*this.boundingSphereRadius/3},l.createTorus=function(t,e,i,o,n){t=t||1,e=e||.5,i=i||8,o=o||6,n=n||2*Math.PI;for(var r=[],s=[],h=0;h<=i;h++)for(var c=0;c<=o;c++){var p=c/o*n,u=h/i*Math.PI*2,d=(t+e*a.cos(u))*a.cos(p),y=(t+e*a.cos(u))*a.sin(p),f=e*a.sin(u);r.push(d,y,f)}for(h=1;h<=i;h++)for(c=1;c<=o;c++){var v=(o+1)*h+c-1,m=(o+1)*(h-1)+c-1,g=(o+1)*(h-1)+c,b=(o+1)*h+c;s.push(v,m,b),s.push(m,g,b)}return new l(r,s)}},{"../collision/AABB":3,"../math/CMath":27,"../math/Quaternion":30,"../math/Transform":31,"../math/Vec3":32,"../utils/Octree":52,"./Shape":45}],48:[function(t,e){e.exports=o,t("../math/Vec3"),t("../math/Quaternion");var i=t("./Solver");function o(){i.call(this),this.iterations=10,this.tolerance=1e-7}o.prototype=new i;var n=[],r=[],s=[];o.prototype.solve=function(t,e){var i,o,a,l,h,c=0,p=this.iterations,u=this.tolerance*this.tolerance,d=this.equations,y=d.length,f=e.bodies,v=f.length,m=t;if(0!==y)for(var g=0;g!==v;g++)f[g].updateSolveMassProperties();var b=r,w=s,x=n;for(b.length=y,w.length=y,x.length=y,g=0;g!==y;g++){var _=d[g];x[g]=0,w[g]=_.computeB(m),b[g]=1/_.computeC()}if(0!==y){for(g=0;g!==v;g++){var B=(M=f[g]).vlambda,S=M.wlambda;B.set(0,0,0),S.set(0,0,0)}for(c=0;c!==p;c++){l=0;for(var E=0;E!==y;E++)_=d[E],i=w[E],o=b[E],(h=x[E])+(a=o*(i-_.computeGWlambda()-_.eps*h))<_.minForce?a=_.minForce-h:h+a>_.maxForce&&(a=_.maxForce-h),x[E]+=a,l+=a>0?a:-a,_.addToWlambda(a);if(l*l=0;t--)this.children[t].removeEmptyNodes(),this.children[t].children.length||this.children[t].data.length||this.children.splice(t,1)}},{"../collision/AABB":3,"../math/Vec3":32}],53:[function(t,e){function i(){this.objects=[],this.type=Object}e.exports=i,i.prototype.release=function(){for(var t=arguments.length,e=0;e!==t;e++)this.objects.push(arguments[e]);return this},i.prototype.get=function(){return 0===this.objects.length?this.constructObject():this.objects.pop()},i.prototype.constructObject=function(){throw new Error("constructObject() not implemented in this Pool subclass yet!")},i.prototype.resize=function(t){for(var e=this.objects;e.length>t;)e.pop();for(;e.lengthe){var i=e;e=t,t=i}return this.data[t+"-"+e]},i.prototype.set=function(t,e,i){if(t>e){var o=e;e=t,t=o}var n=t+"-"+e;return this.get(t,e)||this.data.keys.push(n),this.data[n]=i,this.data[n]},i.prototype.del=function(t,e){if(t>e){var i=e;e=t,t=i}var o=t+"-"+e,n=this.data.keys.indexOf(o);return n>=0&&(this.data.keys.splice(n,1),delete this.data[o],!0)},i.prototype.reset=function(){this.data={keys:[]}},i.prototype.getLength=function(){return this.data.keys.length},i.prototype.getKeyByIndex=function(t){return this.data.keys[t]},i.prototype.getDataByKey=function(t){return this.data[t]}},{}],55:[function(t,e){function i(){}e.exports=i,i.defaults=function(t,e){for(var i in t=t||{},e)i in t||(t[i]=e[i]);return t}},{}],56:[function(t,e){e.exports=n;var i=t("../math/Vec3"),o=t("./Pool");function n(){o.call(this),this.type=i}n.prototype=new o,n.prototype.constructObject=function(){return new i}},{"../math/Vec3":32,"./Pool":53}],57:[function(t,e){e.exports=u;var i=t("../collision/AABB"),o=t("../objects/Body"),n=t("../shapes/Shape"),r=t("../collision/Ray"),s=t("../math/Vec3"),a=t("../math/Transform"),l=(t("../shapes/ConvexPolyhedron"),t("../math/Quaternion")),h=(t("../solver/Solver"),t("../utils/Vec3Pool")),c=t("../equations/ContactEquation"),p=t("../equations/FrictionEquation");function u(t){this.contactPointPool=[],this.frictionEquationPool=[],this.result=[],this.frictionResult=[],this.v3pool=new h,this.world=t,this.currentContactMaterial=null,this.enableFrictionReduction=!1}u.prototype.createContactEquation=function(t,e,i,o,n,r){var s;this.contactPointPool.length?((s=this.contactPointPool.pop()).bi=t,s.bj=e):s=new c(t,e),s.enabled=t.collisionResponse&&e.collisionResponse&&i.collisionResponse&&o.collisionResponse;var a=this.currentContactMaterial;s.restitution=a.restitution,s.setSpookParams(a.contactEquationStiffness,a.contactEquationRelaxation,this.world.dt);var l=i.material||t.material,h=o.material||e.material;return l&&h&&l.restitution>=0&&h.restitution>=0&&(s.restitution=l.restitution*h.restitution),s.si=n||i,s.sj=r||o,s},u.prototype.createFrictionEquationsFromContact=function(t,e){var i=t.bi,o=t.bj,n=t.si,r=t.sj,s=this.world,a=this.currentContactMaterial,l=a.friction,h=n.material||i.material,c=r.material||o.material;if(h&&c&&h.friction>=0&&c.friction>=0&&(l=h.friction*c.friction),l>0){var u=l*s.gravity.length(),d=i.invMass+o.invMass;d>0&&(d=1/d);var y=this.frictionEquationPool,f=y.length?y.pop():new p(i,o,u*d),v=y.length?y.pop():new p(i,o,u*d);return f.bi=v.bi=i,f.bj=v.bj=o,f.minForce=v.minForce=-u*d,f.maxForce=v.maxForce=u*d,f.ri.copy(t.ri),f.rj.copy(t.rj),v.ri.copy(t.ri),v.rj.copy(t.rj),t.ni.tangents(f.t,v.t),f.setSpookParams(a.frictionEquationStiffness,a.frictionEquationRelaxation,s.dt),v.setSpookParams(a.frictionEquationStiffness,a.frictionEquationRelaxation,s.dt),f.enabled=v.enabled=t.enabled,e.push(f,v),!0}return!1};var d=new s,y=new s,f=new s;u.prototype.createFrictionFromAverage=function(t){var e=this.result[this.result.length-1];if(this.createFrictionEquationsFromContact(e,this.frictionResult)&&1!==t){var i=this.frictionResult[this.frictionResult.length-2],o=this.frictionResult[this.frictionResult.length-1];d.setZero(),y.setZero(),f.setZero();for(var n=e.bi,r=(e.bj,0);r!==t;r++)(e=this.result[this.result.length-1-r]).bodyA!==n?(d.vadd(e.ni,d),y.vadd(e.ri,y),f.vadd(e.rj,f)):(d.vsub(e.ni,d),y.vadd(e.rj,y),f.vadd(e.ri,f));var s=1/t;y.scale(s,i.ri),f.scale(s,i.rj),o.ri.copy(i.ri),o.rj.copy(i.rj),d.normalize(),d.tangents(i.t,o.t)}};var v=new s,m=new s,g=new l,b=new l;u.prototype.getContacts=function(t,e,i,n,r,s,a){this.contactPointPool=r,this.frictionEquationPool=a,this.result=n,this.frictionResult=s;for(var l=g,h=b,c=v,p=m,u=0,d=t.length;u!==d;u++){var y=t[u],f=e[u],w=null;y.material&&f.material&&(w=i.getContactMaterial(y.material,f.material)||null);for(var x=0==y.collisionResponse||0==f.collisionResponse||y.type&o.KINEMATIC&&f.type&o.STATIC||y.type&o.STATIC&&f.type&o.KINEMATIC||y.type&o.KINEMATIC&&f.type&o.KINEMATIC,_=0;_B.boundingSphereRadius+E.boundingSphereRadius)){x|=0==B.collisionResponse||0==E.collisionResponse;var M=null;B.material&&E.material&&(M=i.getContactMaterial(B.material,E.material)||null),this.currentContactMaterial=M||w||i.defaultContactMaterial;var C=this[B.type|E.type];if(C&&(B.type0&&D<0&&(m.vsub(d,g),v.copy(f),v.normalize(),U=g.dot(v),v.scale(U,g),g.vadd(d,g),(Z=g.distanceTo(m))0&&!0===o||c<=0&&!1===o))return!1;null===o&&(o=c>0)}return!0}var K=new s,Q=new s,X=new s,Y=new s,Z=[new s,new s,new s,new s,new s,new s],J=new s,$=new s,tt=new s,et=new s;u.prototype[n.types.SPHERE|n.types.BOX]=u.prototype.sphereBox=function(t,e,i,o,n,r,s,a,l,h,c){var p=this.v3pool,u=Z;i.vsub(o,K),e.getSideNormals(u,r);for(var d=t.radius,y=!1,f=$,v=tt,m=et,g=null,b=0,w=0,x=0,_=null,B=0,S=u.length;B!==S&&!1===y;B++){var E=Q;E.copy(u[B]);var M=E.norm();E.normalize();var C=K.dot(E);if(C0){var A=X,z=Y;A.copy(u[(B+1)%3]),z.copy(u[(B+2)%3]);var F=A.norm(),R=z.norm();A.normalize(),z.normalize();var T=K.dot(A),P=K.dot(z);if(T-F&&P-R){var q=Math.abs(C-M-d);if((null===_||q<_)&&(_=q,w=T,x=P,g=M,f.copy(E),v.copy(A),m.copy(z),b++,c))return!0}}}if(b){y=!0;var O=this.createContactEquation(s,a,t,e,l,h);f.mult(-d,O.ri),O.ni.copy(f),O.ni.negate(O.ni),f.mult(g,f),v.mult(w,v),f.vadd(v,f),m.mult(x,m),f.vadd(m,O.rj),O.ri.vadd(i,O.ri),O.ri.vsub(s.position,O.ri),O.rj.vadd(o,O.rj),O.rj.vsub(a.position,O.rj),this.result.push(O),this.createFrictionEquationsFromContact(O,this.frictionResult)}for(var I=p.get(),V=J,j=0;2!==j&&!y;j++)for(var k=0;2!==k&&!y;k++)for(var N=0;2!==N&&!y;N++)if(I.set(0,0,0),j?I.vadd(u[0],I):I.vsub(u[0],I),k?I.vadd(u[1],I):I.vsub(u[1],I),N?I.vadd(u[2],I):I.vsub(u[2],I),o.vadd(I,V),V.vsub(i,V),V.norm2()0){for(var F=[],R=0,T=B.length;R!==T;R++){var P=p.get();r.vmult(y[B[R]],P),o.vadd(P,P),F.push(P)}if(H(F,S,i)){if(c)return!0;w=!0;var q=this.createContactEquation(s,a,t,e,l,h);S.mult(-f,q.ri),S.negate(q.ni);var O=p.get();S.mult(-A,O);var I=p.get();S.mult(-f,I),i.vsub(o,q.rj),q.rj.vadd(I,q.rj),q.rj.vadd(O,q.rj),q.rj.vadd(o,q.rj),q.rj.vsub(a.position,q.rj),q.ri.vadd(i,q.ri),q.ri.vsub(s.position,q.ri),p.release(O),p.release(I),this.result.push(q),this.createFrictionEquationsFromContact(q,this.frictionResult),R=0;for(var V=F.length;R!==V;R++)p.release(F[R]);return}for(R=0;R!==B.length;R++){var j=p.get(),k=p.get();r.vmult(y[B[(R+1)%B.length]],j),r.vmult(y[B[(R+2)%B.length]],k),o.vadd(j,j),o.vadd(k,k);var N=ot;k.vsub(j,N);var L=nt;N.unit(L);var W=p.get(),D=p.get();i.vsub(j,D);var U=D.dot(L);L.mult(U,W),W.vadd(j,W);var G=p.get();if(W.vsub(i,G),U>0&&U*Ut.boundingSphereRadius+e.boundingSphereRadius)&&t.findSeparatingAxis(e,i,n,o,r,d,p,u)){var y=[],f=mt;t.clipAgainstHull(i,n,e,o,r,d,-100,100,y);for(var v=0,m=0;m!==y.length;m++){if(c)return!0;var g=this.createContactEquation(s,a,t,e,l,h),b=g.ri,w=g.rj;d.negate(g.ni),y[m].normal.negate(f),f.mult(y[m].depth,f),y[m].point.vadd(f,b),w.copy(y[m].point),b.vsub(i,b),w.vsub(o,w),b.vadd(i,b),b.vsub(s.position,b),w.vadd(o,w),w.vsub(a.position,w),this.result.push(g),v++,this.enableFrictionReduction||this.createFrictionEquationsFromContact(g,this.frictionResult)}this.enableFrictionReduction&&v&&this.createFrictionFromAverage(v)}};var gt=new s,bt=new s,wt=new s;u.prototype[n.types.PLANE|n.types.PARTICLE]=u.prototype.planeParticle=function(t,e,i,o,n,r,s,a,l,h,c){var p=gt;p.set(0,0,1),s.quaternion.vmult(p,p);var u=bt;if(o.vsub(s.position,u),p.dot(u)<=0){if(c)return!0;var d=this.createContactEquation(a,s,e,t,l,h);d.ni.copy(p),d.ni.negate(d.ni),d.ri.set(0,0,0);var y=wt;p.mult(p.dot(o),y),o.vsub(y,y),d.rj.copy(y),this.result.push(d),this.createFrictionEquationsFromContact(d,this.frictionResult)}};var xt=new s;u.prototype[n.types.PARTICLE|n.types.SPHERE]=u.prototype.sphereParticle=function(t,e,i,o,n,r,s,a,l,h,c){var p=xt;if(p.set(0,0,1),o.vsub(i,p),p.norm2()<=t.radius*t.radius){if(c)return!0;var u=this.createContactEquation(a,s,e,t,l,h);p.normalize(),u.rj.copy(p),u.rj.mult(t.radius,u.rj),u.ni.copy(p),u.ni.negate(u.ni),u.ri.set(0,0,0),this.result.push(u),this.createFrictionEquationsFromContact(u,this.frictionResult)}};var _t=new l,Bt=new s,St=(new s,new s),Et=new s,Mt=new s;u.prototype[n.types.PARTICLE|n.types.CONVEXPOLYHEDRON]=u.prototype.convexParticle=function(t,e,i,o,n,r,s,a,l,h,c){var p=-1,u=St,d=Mt,y=null,f=Bt;if(f.copy(o),f.vsub(i,f),n.conjugate(_t),_t.vmult(f,f),t.pointIsInside(f)){t.worldVerticesNeedsUpdate&&t.computeWorldVertices(i,n),t.worldFaceNormalsNeedsUpdate&&t.computeWorldFaceNormals(n);for(var v=0,m=t.faces.length;v!==m;v++){var g=[t.worldVertices[t.faces[v][0]]],b=t.worldFaceNormals[v];o.vsub(g[0],Et);var w=-b.dot(Et);if(null===y||Math.abs(w)u.length||w>u[0].length)){g<0&&(g=0),b<0&&(b=0),w<0&&(w=0),x<0&&(x=0),g>=u.length&&(g=u.length-1),b>=u.length&&(b=u.length-1),x>=u[0].length&&(x=u[0].length-1),w>=u[0].length&&(w=u[0].length-1);var _=[];e.getRectMinMax(g,w,b,x,_);var B=_[0],S=_[1];if(!(m.z-y>S||m.z+yu.length||b>u[0].length)){m<0&&(m=0),g<0&&(g=0),b<0&&(b=0),w<0&&(w=0),m>=u.length&&(m=u.length-1),g>=u.length&&(g=u.length-1),w>=u[0].length&&(w=u[0].length-1),b>=u[0].length&&(b=u[0].length-1);var x=[];e.getRectMinMax(m,b,g,w,x);var _=x[0],B=x[1];if(!(v.z-d>B||v.z+d<_))for(var S=this.result,E=m;E2)return}}}},{"../collision/AABB":3,"../collision/Ray":10,"../equations/ContactEquation":20,"../equations/FrictionEquation":22,"../math/Quaternion":30,"../math/Transform":31,"../math/Vec3":32,"../objects/Body":33,"../shapes/ConvexPolyhedron":40,"../shapes/Shape":45,"../solver/Solver":49,"../utils/Vec3Pool":56}],58:[function(t,e){e.exports=g,t("../shapes/Shape");var i=t("../math/Vec3"),o=t("../math/Quaternion"),n=t("../solver/GSSolver"),r=(t("../equations/ContactEquation"),t("../equations/FrictionEquation"),t("./Narrowphase")),s=t("../utils/EventTarget"),a=t("../collision/ArrayCollisionMatrix"),l=t("../collision/ObjectCollisionMatrix"),h=t("../collision/OverlapKeeper"),c=t("../material/Material"),p=t("../material/ContactMaterial"),u=t("../objects/Body"),d=t("../utils/TupleDictionary"),y=t("../collision/RaycastResult"),f=t("../collision/AABB"),v=t("../collision/Ray"),m=t("../collision/NaiveBroadphase");function g(t){t=t||{},s.apply(this),this.dt=-1,this.allowSleep=!!t.allowSleep,this.contacts=[],this.frictionEquations=[],this.quatNormalizeSkip=void 0!==t.quatNormalizeSkip?t.quatNormalizeSkip:0,this.quatNormalizeFast=void 0!==t.quatNormalizeFast&&t.quatNormalizeFast,this.time=0,this.timeFixed=0,this.stepnumber=0,this.default_dt=1/60,this.nextId=0,this.gravity=new i,t.gravity&&this.gravity.copy(t.gravity),this.broadphase=void 0!==t.broadphase?t.broadphase:new m,this.bodies=[],this.solver=void 0!==t.solver?t.solver:new n,this.constraints=[],this.narrowphase=new r(this),this.collisionMatrix=new a,this.collisionMatrixPrevious=new a,this.bodyOverlapKeeper=new h,this.shapeOverlapKeeper=new h,this.materials=[],this.contactmaterials=[],this.contactMaterialTable=new d,this.defaultMaterial=new c("default"),this.defaultContactMaterial=new p(this.defaultMaterial,this.defaultMaterial,{friction:.3,restitution:0}),this.doProfiling=!1,this.profile={solve:0,makeContactConstraints:0,broadphase:0,integrate:0,narrowphase:0},this.accumulator=0,this.subsystems=[],this.addBodyEvent={type:"addBody",body:null},this.removeBodyEvent={type:"removeBody",body:null},this.idToBodyMap={},this.broadphase.setWorld(this),this.substeps=0,this.cm=new l,this.tm=new l,this.triggerDic=new d,this.oldTriggerDic=new d,this.contactsDic=new d,this.oldContactsDic=new d}g.idToBodyMap={},g.idToShapeMap={},g.prototype=new s,new f;var b=new v;if(g.prototype.getContactMaterial=function(t,e){return this.contactMaterialTable.get(t.id,e.id)},g.prototype.numObjects=function(){return this.bodies.length},g.prototype.collisionMatrixTick=function(){var t=this.collisionMatrixPrevious;this.collisionMatrixPrevious=this.collisionMatrix,this.collisionMatrix=t,this.collisionMatrix.reset(),this.bodyOverlapKeeper.tick(),this.shapeOverlapKeeper.tick()},g.prototype.add=g.prototype.addBody=function(t){g.SLEEPING=!1,-1===this.bodies.indexOf(t)&&(t.index=this.bodies.length,this.bodies.push(t),t.world=this,t.initPosition.copy(t.position),t.initVelocity.copy(t.velocity),t.timeLastSleepy=this.time,t instanceof u&&(t.initAngularVelocity.copy(t.angularVelocity),t.initQuaternion.copy(t.quaternion)),this.collisionMatrix.setNumObjects(this.bodies.length),this.addBodyEvent.body=t,this.cm.setNumObjects(this.bodies.length),g.idToBodyMap[t.id]=t,this.dispatchEvent(this.addBodyEvent))},g.prototype.addConstraint=function(t){g.SLEEPING=!1,this.constraints.push(t)},g.prototype.removeConstraint=function(t){g.SLEEPING=!1;var e=this.constraints.indexOf(t);-1!==e&&this.constraints.splice(e,1)},g.prototype.rayTest=function(t,e,i){i instanceof y?this.raycastClosest(t,e,{skipBackfaces:!0},i):this.raycastAll(t,e,{skipBackfaces:!0},i)},g.prototype.raycastAll=function(t,e,i,o){return i.mode=v.ALL,i.from=t,i.to=e,i.callback=o,b.intersectWorld(this,i)},g.prototype.raycastAny=function(t,e,i,o){return i.mode=v.ANY,i.from=t,i.to=e,i.result=o,b.intersectWorld(this,i)},g.prototype.raycastClosest=function(t,e,i,o){return i.mode=v.CLOSEST,i.from=t,i.to=e,i.result=o,b.intersectWorld(this,i)},g.prototype.remove=function(t){g.SLEEPING=!1,t.world=null;var e=this.bodies.length-1,i=this.bodies,o=i.indexOf(t);if(-1!==o){i.splice(o,1);for(var n=0;n!==i.length;n++)i[n].index=n;this.collisionMatrix.setNumObjects(e),this.removeBodyEvent.body=t,delete g.idToBodyMap[t.id],this.cm.setNumObjects(e),this.dispatchEvent(this.removeBodyEvent)}},g.prototype.removeBody=g.prototype.remove,g.prototype.getBodyById=function(t){return g.idToBodyMap[t]},g.prototype.getShapeById=function(t){return g.idToShapeMap[t]},g.prototype.addMaterial=function(t){this.materials.push(t)},g.prototype.addContactMaterial=function(t){this.contactmaterials.push(t),this.contactMaterialTable.set(t.materials[0].id,t.materials[1].id,t)},"undefined"==typeof performance&&(performance={}),!performance.now){var w=Date.now();performance.timing&&performance.timing.navigationStart&&(w=performance.timing.navigationStart),performance.now=function(){return Date.now()-w}}new i,g.prototype.step=function(t,e,i){if(i=i||10,0===(e=e||0))this.internalStep(t),this.time+=t,this.substeps=1;else{for(this.accumulator+=e,this.substeps=0;this.accumulator>=t&&this.substeps=0;S-=1)(L.bodyA===o[S]&&L.bodyB===n[S]||L.bodyB===o[S]&&L.bodyA===n[S])&&(o.splice(S,1),n.splice(S,1));this.collisionMatrixTick(),h&&(e=performance.now());var E=F,M=i.length;for(b=0;b!==M;b++)E.push(i[b]);i.length=0;var q=this.frictionEquations.length;for(b=0;b!==q;b++)y.push(this.frictionEquations[b]);if(this.frictionEquations.length=0,this.narrowphase.getContacts(o,n,this,i,E,this.frictionEquations,y),0!=i.length||!g.SLEEPING){for(h&&(c.narrowphase=performance.now()-e),h&&(e=performance.now()),b=0;b=0&&N.material.restitution>=0&&(L.restitution=k.material.restitution*N.material.restitution):V.material&&j.material&&V.material.restitution>=0&&j.material.restitution>=0&&(L.restitution=V.material.restitution*j.material.restitution),a.addEquation(L),V.allowSleep&&V.type===u.DYNAMIC&&V.sleepState===u.SLEEPING&&j.sleepState===u.AWAKE&&j.type!==u.STATIC&&j.velocity.norm2()+j.angularVelocity.norm2()>=2*Math.pow(j.sleepSpeedLimit,2)&&(V._wakeUpAfterNarrowphase=!0),j.allowSleep&&j.type===u.DYNAMIC&&j.sleepState===u.SLEEPING&&V.sleepState===u.AWAKE&&V.type!==u.STATIC&&V.velocity.norm2()+V.angularVelocity.norm2()>=2*Math.pow(V.sleepSpeedLimit,2)&&(j._wakeUpAfterNarrowphase=!0),this.collisionMatrix.set(V,j,!0),this.collisionMatrixPrevious.get(V,j)||(z.body=j,z.contact=L,V.dispatchEvent(z),z.body=V,j.dispatchEvent(z)),this.bodyOverlapKeeper.set(V.id,j.id),this.shapeOverlapKeeper.set(k.id,N.id)}for(this.emitContactEvents(),h&&(c.makeContactConstraints=performance.now()-e,e=performance.now()),b=0;b!==r;b++)(V=s[b])._wakeUpAfterNarrowphase&&(V.wakeUp(),V._wakeUpAfterNarrowphase=!1);for(B=d.length,b=0;b!==B;b++){var L;(L=d[b]).update(),S=0;for(var W=L.equations.length;S!==W;S++){var D=L.equations[S];a.addEquation(D)}}a.solve(t,this),h&&(c.solve=performance.now()-e),a.removeAllEquations();var U=Math.pow;for(b=0;b!==r;b++)if((V=s[b]).type&p){var G=U(1-V.linearDamping,t),H=V.velocity;H.mult(G,H);var K=V.angularVelocity;if(K){var Q=U(1-V.angularDamping,t);K.mult(Q,K)}}for(this.dispatchEvent(A),b=0;b!==r;b++)(V=s[b]).preStep&&V.preStep.call(V);h&&(e=performance.now());var X=this.stepnumber%(this.quatNormalizeSkip+1)==0,Y=this.quatNormalizeFast;for(b=0;b!==r;b++)s[b].integrate(t,X,Y);for(this.clearForces(),this.broadphase.dirty=!0,h&&(c.integrate=performance.now()-e),this.time+=t,this.timeFixed+=t,this.stepnumber+=1,this.dispatchEvent(C),b=0;b!==r;b++){var Z=(V=s[b]).postStep;Z&&Z.call(V)}if(this.allowSleep){for(b=0;b!==r;b++)s[b].sleepTick(this.time);for(g.SLEEPING=!0,b=0;b!==r;b++)if((V=s[b]).type!=u.STATIC&&!V.isSleeping()){g.SLEEPING=!1;break}}else g.SLEEPING=!1}},g.prototype.emitContactEvents=(x=[],_=[],B={type:"beginContact",bodyA:null,bodyB:null},S={type:"endContact",bodyA:null,bodyB:null},E={type:"beginShapeContact",bodyA:null,bodyB:null,shapeA:null,shapeB:null},M={type:"endShapeContact",bodyA:null,bodyB:null,shapeA:null,shapeB:null},function(){var t=this.hasAnyEventListener("beginContact"),e=this.hasAnyEventListener("endContact");if((t||e)&&this.bodyOverlapKeeper.getDiff(x,_),t){for(var i=0,o=x.length;i0;)i--,t=this.oldTriggerDic.getKeyByIndex(i),null==this.triggerDic.getDataByKey(t)&&null!=(e=this.oldTriggerDic.getDataByKey(t))&&(o=e.si,n=e.sj,this.tm.set(o,n,!1),this.oldTriggerDic.del(o.id,n.id)&&i--,q.event="onTriggerExit",q.selfShape=o,q.otherShape=n,q.selfBody=o.body,q.otherBody=n.body,o.dispatchEvent(q),q.selfShape=n,q.otherShape=o,q.selfBody=n.body,q.otherBody=o.body,n.dispatchEvent(q));this.triggerDic.reset()}},g.prototype.emitCollisionEvents=function(){if(0!=this.substeps){for(var t,e,i=this.contacts,o=this.contacts.length;o--;){var n=(c=i[o]).si,r=c.sj,s=this.contactsDic.get(n.id,r.id);null==s&&(s=this.contactsDic.set(n.id,r.id,[])),s.push(c)}for(o=this.contactsDic.getLength();o--;)if(t=this.contactsDic.getKeyByIndex(o),null!=(e=this.contactsDic.getDataByKey(t))){n=e[0].si,r=e[0].sj;var a=n.body,l=r.body;this.cm.get(a,l)?O.event="onCollisionStay":(this.cm.set(a,l,!0),O.event="onCollisionEnter"),O.bi=a,O.contact=e[0],O.contacts=e,O.body=l,O.selfShape=n,O.otherShape=r,a.dispatchEvent(O),O.body=a,O.selfShape=r,O.otherShape=n,l.dispatchEvent(O)}var h=I;for(o=h.length;o--;){var c;n=(c=h[o]).si,r=c.sj,null==this.oldContactsDic.get(n.id,r.id)&&this.oldContactsDic.set(n.id,r.id,c)}for(o=this.oldContactsDic.getLength();o--;)t=this.oldContactsDic.getKeyByIndex(o),null==this.contactsDic.getDataByKey(t)&&(n=(e=this.oldContactsDic.getDataByKey(t)).si,r=e.sj,a=n.body,l=r.body,this.cm.get(a,l)&&(a.isSleeping()&&l.isSleeping()||(this.cm.set(a,l,!1),O.bi=a,O.contact=e,O.event="onCollisionExit",O.body=l,O.selfShape=n,O.otherShape=r,O.contacts.length=0,O.contacts.push(e),a.dispatchEvent(O),O.body=a,O.selfShape=r,O.otherShape=n,l.dispatchEvent(O))));this.contactsDic.reset(),this.oldContactsDic.reset(),F=I,I=this.contacts.slice(),this.contacts.length=0}}},{"../collision/AABB":3,"../collision/ArrayCollisionMatrix":4,"../collision/NaiveBroadphase":7,"../collision/ObjectCollisionMatrix":8,"../collision/OverlapKeeper":9,"../collision/Ray":10,"../collision/RaycastResult":11,"../equations/ContactEquation":20,"../equations/FrictionEquation":22,"../material/ContactMaterial":25,"../material/Material":26,"../math/Quaternion":30,"../math/Vec3":32,"../objects/Body":33,"../shapes/Shape":45,"../solver/GSSolver":48,"../utils/EventTarget":51,"../utils/TupleDictionary":54,"./Narrowphase":57}]},{},[2])(2)})}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}]},{},[10,9]);