1 |
- !function t(e,i,o){function n(r,a){if(!i[r]){if(!e[r]){var h="function"==typeof require&&require;if(!a&&h)return h(r,!0);if(s)return s(r,!0);var l=new Error("Cannot find module '"+r+"'");throw l.code="MODULE_NOT_FOUND",l}var c=i[r]={exports:{}};e[r][0].call(c.exports,function(t){var i=e[r][1][t];return n(i||t)},c,c.exports,t,e,i,o)}return i[r].exports}for(var s="function"==typeof require&&require,r=0;r<o.length;r++)n(o[r]);return n}({1:[function(t,e,i){t("./src/misc").registerAll()},{"./src/misc":75}],2:[function(t,e,i){var o=t("cannon"),n=t("./src/components/math");e.exports={"dynamic-body":t("./src/components/body/dynamic-body"),"static-body":t("./src/components/body/static-body"),constraint:t("./src/components/constraint"),system:t("./src/system/physics"),registerAll:function(t){this._registered||(t=t||window.AFRAME,n.registerAll(),t.systems.physics||t.registerSystem("physics",this.system),t.components["dynamic-body"]||t.registerComponent("dynamic-body",this["dynamic-body"]),t.components["static-body"]||t.registerComponent("static-body",this["static-body"]),t.components.constraint||t.registerComponent("constraint",this.constraint),this._registered=!0)}},window.CANNON=window.CANNON||o},{"./src/components/body/dynamic-body":5,"./src/components/body/static-body":6,"./src/components/constraint":7,"./src/components/math":8,"./src/system/physics":12,cannon:14}],3:[function(t,e,i){var o=t("cannon");o.shape2mesh=function(t){for(var e=new THREE.Object3D,i=0;i<t.shapes.length;i++){var n,s=t.shapes[i];switch(s.type){case o.Shape.types.SPHERE:var r=new THREE.SphereGeometry(s.radius,8,8);n=new THREE.Mesh(r,this.currentMaterial);break;case o.Shape.types.PARTICLE:n=new THREE.Mesh(this.particleGeo,this.particleMaterial);var a=this.settings;n.scale.set(a.particleSize,a.particleSize,a.particleSize);break;case o.Shape.types.PLANE:g=new THREE.PlaneGeometry(10,10,4,4);n=new THREE.Object3D;var h=new THREE.Object3D,l=new THREE.Mesh(g,this.currentMaterial);l.scale.set(100,100,100),h.add(l),l.castShadow=!0,l.receiveShadow=!0,n.add(h);break;case o.Shape.types.BOX:var c=new THREE.BoxGeometry(2*s.halfExtents.x,2*s.halfExtents.y,2*s.halfExtents.z);n=new THREE.Mesh(c,this.currentMaterial);break;case o.Shape.types.CONVEXPOLYHEDRON:for(var p=new THREE.Geometry,u=0;u<s.vertices.length;u++){var d=s.vertices[u];p.vertices.push(new THREE.Vector3(d.x,d.y,d.z))}for(u=0;u<s.faces.length;u++)for(var v=s.faces[u],y=v[0],f=1;f<v.length-1;f++){var m=v[f],w=v[f+1];p.faces.push(new THREE.Face3(y,m,w))}p.computeBoundingSphere(),p.computeFaceNormals(),n=new THREE.Mesh(p,this.currentMaterial);break;case o.Shape.types.HEIGHTFIELD:for(var g=new THREE.Geometry,x=new o.Vec3,b=new o.Vec3,E=new o.Vec3,B=0;B<s.data.length-1;B++)for(var A=0;A<s.data[B].length-1;A++)for(var S=0;S<2;S++){s.getConvexTrianglePillar(B,A,0===S),x.copy(s.pillarConvex.vertices[0]),b.copy(s.pillarConvex.vertices[1]),E.copy(s.pillarConvex.vertices[2]),x.vadd(s.pillarOffset,x),b.vadd(s.pillarOffset,b),E.vadd(s.pillarOffset,E),g.vertices.push(new THREE.Vector3(x.x,x.y,x.z),new THREE.Vector3(b.x,b.y,b.z),new THREE.Vector3(E.x,E.y,E.z));u=g.vertices.length-3;g.faces.push(new THREE.Face3(u,u+1,u+2))}g.computeBoundingSphere(),g.computeFaceNormals(),n=new THREE.Mesh(g,this.currentMaterial);break;case o.Shape.types.TRIMESH:for(var g=new THREE.Geometry,x=new o.Vec3,b=new o.Vec3,E=new o.Vec3,u=0;u<s.indices.length/3;u++){s.getTriangleVertices(u,x,b,E),g.vertices.push(new THREE.Vector3(x.x,x.y,x.z),new THREE.Vector3(b.x,b.y,b.z),new THREE.Vector3(E.x,E.y,E.z));f=g.vertices.length-3;g.faces.push(new THREE.Face3(f,f+1,f+2))}g.computeBoundingSphere(),g.computeFaceNormals(),n=new THREE.Mesh(g,this.currentMaterial);break;default:throw"Visual type not recognized: "+s.type}if(n.receiveShadow=!0,n.castShadow=!0,n.children)for(u=0;u<n.children.length;u++)if(n.children[u].castShadow=!0,n.children[u].receiveShadow=!0,n.children[u])for(f=0;f<n.children[u].length;f++)n.children[u].children[f].castShadow=!0,n.children[u].children[f].receiveShadow=!0;var R=t.shapeOffsets[i],z=t.shapeOrientations[i];n.position.set(R.x,R.y,R.z),n.quaternion.set(z.x,z.y,z.z,z.w),e.add(n)}return e},e.exports=o.shape2mesh},{cannon:14}],4:[function(t,e,i){var o=t("cannon"),n=t("three-to-cannon");t("../../../lib/CANNON-shape2mesh"),e.exports={schema:{shape:{default:"auto",oneOf:["auto","box","cylinder","sphere","hull","none"]},cylinderAxis:{default:"y",oneOf:["x","y","z"]},sphereRadius:{default:NaN}},init:function(){this.system=this.el.sceneEl.systems.physics,this.el.sceneEl.hasLoaded?this.initBody():this.el.sceneEl.addEventListener("loaded",this.initBody.bind(this))},initBody:function(){var t,e=this.el,i=this.data,s=e.getAttribute("position");if(this.body=new o.Body({mass:i.mass||0,material:this.system.material,position:new o.Vec3(s.x,s.y,s.z),linearDamping:i.linearDamping,angularDamping:i.angularDamping}),this.el.object3D.updateMatrixWorld(!0),"none"!==i.shape){var r="auto"===i.shape?void 0:AFRAME.utils.extend({},this.data,{type:n.Type[i.shape.toUpperCase()]});if(!(t=n(this.el.object3D,r)))return void this.el.addEventListener("model-loaded",this.initBody.bind(this));this.body.addShape(t,t.offset,t.orientation),this.system.debug&&this.createWireframe(this.body,t)}var a=e.getAttribute("rotation");this.body.quaternion.setFromEuler(THREE.Math.degToRad(a.x),THREE.Math.degToRad(a.y),THREE.Math.degToRad(a.z),"XYZ").normalize(),this.el.body=this.body,this.body.el=this.el,this.isLoaded=!0,this.isPlaying&&this._play(),this.el.emit("body-loaded",{body:this.el.body})},play:function(){this.isLoaded&&this._play()},_play:function(){this.system.addBehavior(this,this.system.Phase.SIMULATE),this.system.addBody(this.body),this.wireframe&&this.el.sceneEl.object3D.add(this.wireframe),this.syncToPhysics()},pause:function(){this.isLoaded&&(this.system.removeBehavior(this,this.system.Phase.SIMULATE),this.system.removeBody(this.body),this.wireframe&&this.el.sceneEl.object3D.remove(this.wireframe))},remove:function(){this.pause(),delete this.body.el,delete this.body,delete this.el.body,delete this.wireframe},createWireframe:function(t,e){var i=e.offset,n=e.orientation,s=o.shape2mesh(t).children[0];this.wireframe=new THREE.LineSegments(new THREE.EdgesGeometry(s.geometry),new THREE.LineBasicMaterial({color:16711680})),i&&(this.wireframe.offset=i.clone()),n&&(n.inverse(n),this.wireframe.orientation=new THREE.Quaternion(n.x,n.y,n.z,n.w)),this.syncWireframe()},syncWireframe:function(){var t,e=this.wireframe;this.wireframe&&(e.quaternion.copy(this.body.quaternion),e.orientation&&e.quaternion.multiply(e.orientation),e.position.copy(this.body.position),e.offset&&(t=e.offset.clone().applyQuaternion(e.quaternion),e.position.add(t)),e.updateMatrix())},syncToPhysics:function(){var t=new THREE.Quaternion,e=new THREE.Vector3;return function(){var i=this.el,o=i.parentEl,n=this.body;n&&(i.components.velocity&&n.velocity.copy(i.getAttribute("velocity")),o.isScene?(n.quaternion.copy(i.object3D.quaternion),n.position.copy(i.object3D.position)):(i.object3D.getWorldQuaternion(t),n.quaternion.copy(t),i.object3D.getWorldPosition(e),n.position.copy(e)),this.wireframe&&this.syncWireframe())}}(),syncFromPhysics:function(){var t=new THREE.Vector3,e=new THREE.Quaternion,i=new THREE.Quaternion;return function(){var o=this.el,n=o.parentEl,s=this.body;s&&(n.isScene?(o.setAttribute("quaternion",s.quaternion),o.setAttribute("position",s.position)):(e.copy(s.quaternion),n.object3D.getWorldQuaternion(i),e.multiply(i.inverse()),o.setAttribute("quaternion",{x:e.x,y:e.y,z:e.z,w:e.w}),t.copy(s.position),n.object3D.worldToLocal(t),o.setAttribute("position",{x:t.x,y:t.y,z:t.z})),this.wireframe&&this.syncWireframe())}}()}},{"../../../lib/CANNON-shape2mesh":3,cannon:14,"three-to-cannon":70}],5:[function(t,e,i){var o=t("./body");e.exports=AFRAME.utils.extend({},o,{dependencies:["quaternion","velocity"],schema:AFRAME.utils.extend({},o.schema,{mass:{default:5},linearDamping:{default:.01},angularDamping:{default:.01}}),step:function(){this.syncFromPhysics()}})},{"./body":4}],6:[function(t,e,i){var o=t("./body");e.exports=AFRAME.utils.extend({},o,{step:function(){this.syncToPhysics()}})},{"./body":4}],7:[function(t,e,i){var o=t("cannon");e.exports={dependencies:["dynamic-body"],multiple:!0,schema:{type:{default:"lock",oneOf:["coneTwist","distance","hinge","lock","pointToPoint"]},target:{type:"selector"},maxForce:{default:1e6,min:0},collideConnected:{default:!0},wakeUpBodies:{default:!0},distance:{default:0,min:0},pivot:{type:"vec3"},targetPivot:{type:"vec3"},axis:{type:"vec3",default:{x:0,y:0,z:1}},targetAxis:{type:"vec3",default:{x:0,y:0,z:1}}},init:function(){this.system=this.el.sceneEl.systems.physics,this.constraint=null},remove:function(){this.constraint&&(this.system.world.removeConstraint(this.constraint),this.constraint=null)},update:function(){var t=this.el,e=this.data;this.remove(),t.body&&e.target.body?(this.constraint=this.createConstraint(),this.system.world.addConstraint(this.constraint)):(t.body?e.target:t).addEventListener("body-loaded",this.update.bind(this,{}))},createConstraint:function(){var t,e=this.data,i=new o.Vec3(e.pivot.x,e.pivot.y,e.pivot.z),n=new o.Vec3(e.targetPivot.x,e.targetPivot.y,e.targetPivot.z),s=new o.Vec3(e.axis.x,e.axis.y,e.axis.z),r=new o.Vec3(e.targetAxis.x,e.targetAxis.y,e.targetAxis.z);switch(e.type){case"lock":t=new o.LockConstraint(this.el.body,e.target.body,{maxForce:e.maxForce});break;case"distance":t=new o.DistanceConstraint(this.el.body,e.target.body,e.distance,e.maxForce);break;case"hinge":t=new o.HingeConstraint(this.el.body,e.target.body,{pivotA:i,pivotB:n,axisA:s,axisB:r,maxForce:e.maxForce});break;case"coneTwist":t=new o.ConeTwistConstraint(this.el.body,e.target.body,{pivotA:i,pivotB:n,axisA:s,axisB:r,maxForce:e.maxForce});break;case"pointToPoint":t=new o.PointToPointConstraint(this.el.body,i,e.target.body,n,e.maxForce);break;default:throw new Error("[constraint] Unexpected type: "+e.type)}return t.collideConnected=e.collideConnected,t}}},{cannon:14}],8:[function(t,e,i){e.exports={velocity:t("./velocity"),quaternion:t("./quaternion"),registerAll:function(t){this._registered||((t=t||window.AFRAME).components.velocity||t.registerComponent("velocity",this.velocity),t.components.quaternion||t.registerComponent("quaternion",this.quaternion),this._registered=!0)}}},{"./quaternion":9,"./velocity":10}],9:[function(t,e,i){e.exports={schema:{type:"vec4"},play:function(){var t=this.el,e=t.object3D.quaternion;t.hasAttribute("rotation")&&(t.components.rotation.update(),t.setAttribute("quaternion",{x:e.x,y:e.y,z:e.z,w:e.w}),t.removeAttribute("rotation"),this.update())},update:function(){var t=this.data;this.el.object3D.quaternion.set(t.x,t.y,t.z,t.w)}}},{}],10:[function(t,e,i){e.exports={schema:{type:"vec3"},init:function(){this.system=this.el.sceneEl.systems.physics,this.system&&this.system.addBehavior(this,this.system.Phase.RENDER)},remove:function(){this.system&&this.system.removeBehavior(this,this.system.Phase.RENDER)},tick:function(t,e){e&&(this.system||this.step(t,e))},step:function(t,e){if(e){var i=this.el.sceneEl.systems.physics||{data:{maxInterval:1/60}},o=this.el.getAttribute("velocity")||{x:0,y:0,z:0},n=this.el.getAttribute("position")||{x:0,y:0,z:0};e=Math.min(e,1e3*i.data.maxInterval),this.el.setAttribute("position",{x:n.x+o.x*e/1e3,y:n.y+o.y*e/1e3,z:n.z+o.z*e/1e3})}}}},{}],11:[function(t,e,i){e.exports={GRAVITY:-9.8,MAX_INTERVAL:4/60,ITERATIONS:10,CONTACT_MATERIAL:{friction:.01,restitution:.3,contactEquationStiffness:1e8,contactEquationRelaxation:3,frictionEquationStiffness:1e8,frictionEquationRegularization:3}}},{}],12:[function(t,e,i){var o=t("cannon"),n=t("../constants"),s=n.GRAVITY,r=n.CONTACT_MATERIAL;e.exports={schema:{gravity:{default:s},iterations:{default:n.ITERATIONS},friction:{default:r.friction},restitution:{default:r.restitution},contactEquationStiffness:{default:r.contactEquationStiffness},contactEquationRelaxation:{default:r.contactEquationRelaxation},frictionEquationStiffness:{default:r.frictionEquationStiffness},frictionEquationRegularization:{default:r.frictionEquationRegularization},maxInterval:{default:4/60},debug:{default:!1}},Phase:{SIMULATE:"sim",RENDER:"render"},init:function(){var t=this.data;this.debug=t.debug,this.children={},this.children[this.Phase.SIMULATE]=[],this.children[this.Phase.RENDER]=[],this.listeners={},this.world=new o.World,this.world.quatNormalizeSkip=0,this.world.quatNormalizeFast=!1,this.world.solver.iterations=t.iterations,this.world.gravity.set(0,t.gravity,0),this.world.broadphase=new o.NaiveBroadphase,this.material=new o.Material({name:"defaultMaterial"}),this.contactMaterial=new o.ContactMaterial(this.material,this.material,{friction:t.friction,restitution:t.restitution,contactEquationStiffness:t.contactEquationStiffness,contactEquationRelaxation:t.contactEquationRelaxation,frictionEquationStiffness:t.frictionEquationStiffness,frictionEquationRegularization:t.frictionEquationRegularization}),this.world.addContactMaterial(this.contactMaterial)},tick:function(t,e){if(e){this.world.step(Math.min(e/1e3,this.data.maxInterval));var i;for(i=0;i<this.children[this.Phase.SIMULATE].length;i++)this.children[this.Phase.SIMULATE][i].step(t,e);for(i=0;i<this.children[this.Phase.RENDER].length;i++)this.children[this.Phase.RENDER][i].step(t,e)}},addBody:function(t){this.listeners[t.id]=function(e){t.el.emit("collide",e)},t.addEventListener("collide",this.listeners[t.id]),this.world.addBody(t)},removeBody:function(t){t.removeEventListener("collide",this.listeners[t.id]),delete this.listeners[t.id],this.world.removeBody(t)},addBehavior:function(t,e){this.children[e].push(t)},removeBehavior:function(t,e){this.children[e].splice(this.children[e].indexOf(t),1)},update:function(t){var e=this.data;e.debug!==t.debug&&console.warn("[physics] `debug` cannot be changed dynamically."),e.maxInterval,t.maxInterval,e.gravity!==t.gravity&&this.world.gravity.set(0,e.gravity,0),this.contactMaterial.friction=e.friction,this.contactMaterial.restitution=e.restitution,this.contactMaterial.contactEquationStiffness=e.contactEquationStiffness,this.contactMaterial.contactEquationRelaxation=e.contactEquationRelaxation,this.contactMaterial.frictionEquationStiffness=e.frictionEquationStiffness,this.contactMaterial.frictionEquationRegularization=e.frictionEquationRegularization}}},{"../constants":11,cannon:14}],13:[function(t,e,i){e.exports={_from:"github:donmccurdy/cannon.js#v0.6.2-dev1",_id:"cannon@0.6.2",_inBundle:!1,_integrity:"sha1-kuhwtr7Hd8jqU3mcndOx2tmf0RU=",_location:"/cannon",_phantomChildren:{},_requested:{type:"git",raw:"cannon@github:donmccurdy/cannon.js#v0.6.2-dev1",name:"cannon",escapedName:"cannon",rawSpec:"github:donmccurdy/cannon.js#v0.6.2-dev1",saveSpec:"github:donmccurdy/cannon.js#v0.6.2-dev1",fetchSpec:null,gitCommittish:"v0.6.2-dev1"},_requiredBy:["/aframe-physics-system"],_resolved:"github:donmccurdy/cannon.js#022e8ba53fa83abf0ad8a0e4fd08623123838a17",_spec:"cannon@github:donmccurdy/cannon.js#v0.6.2-dev1",_where:"/Users/donmccurdy/Documents/Projects/aframe-extras/node_modules/aframe-physics-system",author:{name:"Stefan Hedman",email:"schteppe@gmail.com",url:"http://steffe.se"},bugs:{url:"https://github.com/schteppe/cannon.js/issues"},bundleDependencies:!1,dependencies:{},deprecated:!1,description:"A lightweight 3D physics engine written in JavaScript.",devDependencies:{browserify:"*",grunt:"~0.4.0","grunt-browserify":"^2.1.4","grunt-contrib-concat":"~0.1.3","grunt-contrib-jshint":"~0.1.1","grunt-contrib-nodeunit":"^0.4.1","grunt-contrib-uglify":"^0.5.1","grunt-contrib-yuidoc":"^0.5.2",jshint:"latest",nodeunit:"^0.9.0","uglify-js":"latest"},engines:{node:"*"},homepage:"https://github.com/schteppe/cannon.js",keywords:["cannon.js","cannon","physics","engine","3d"],licenses:[{type:"MIT"}],main:"./src/Cannon.js",name:"cannon",repository:{type:"git",url:"git+https://github.com/schteppe/cannon.js.git"},version:"0.6.2"}},{}],14:[function(t,e,i){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")}},{"../package.json":13,"./collision/AABB":15,"./collision/ArrayCollisionMatrix":16,"./collision/Broadphase":17,"./collision/GridBroadphase":18,"./collision/NaiveBroadphase":19,"./collision/ObjectCollisionMatrix":20,"./collision/Ray":22,"./collision/RaycastResult":23,"./collision/SAPBroadphase":24,"./constraints/ConeTwistConstraint":25,"./constraints/Constraint":26,"./constraints/DistanceConstraint":27,"./constraints/HingeConstraint":28,"./constraints/LockConstraint":29,"./constraints/PointToPointConstraint":30,"./equations/ContactEquation":32,"./equations/Equation":33,"./equations/FrictionEquation":34,"./equations/RotationalEquation":35,"./equations/RotationalMotorEquation":36,"./material/ContactMaterial":37,"./material/Material":38,"./math/Mat3":40,"./math/Quaternion":41,"./math/Transform":42,"./math/Vec3":43,"./objects/Body":44,"./objects/RaycastVehicle":45,"./objects/RigidVehicle":46,"./objects/SPHSystem":47,"./objects/Spring":48,"./shapes/Box":50,"./shapes/ConvexPolyhedron":51,"./shapes/Cylinder":52,"./shapes/Heightfield":53,"./shapes/Particle":54,"./shapes/Plane":55,"./shapes/Shape":56,"./shapes/Sphere":57,"./shapes/Trimesh":58,"./solver/GSSolver":59,"./solver/Solver":60,"./solver/SplitSolver":61,"./utils/EventTarget":62,"./utils/Pool":64,"./utils/Vec3Pool":67,"./world/Narrowphase":68,"./world/World":69}],15:[function(t,e,i){function o(t){t=t||{},this.lowerBound=new n,t.lowerBound&&this.lowerBound.copy(t.lowerBound),this.upperBound=new n,t.upperBound&&this.upperBound.copy(t.upperBound)}var n=t("../math/Vec3");t("../utils/Utils");e.exports=o;var s=new n;o.prototype.setFromPoints=function(t,e,i,o){var n=this.lowerBound,r=this.upperBound,a=i;n.copy(t[0]),a&&a.vmult(n,n),r.copy(n);for(var h=1;h<t.length;h++){var l=t[h];a&&(a.vmult(l,s),l=s),l.x>r.x&&(r.x=l.x),l.x<n.x&&(n.x=l.x),l.y>r.y&&(r.y=l.y),l.y<n.y&&(n.y=l.y),l.z>r.z&&(r.z=l.z),l.z<n.z&&(n.z=l.z)}return e&&(e.vadd(n,n),e.vadd(r,r)),o&&(n.x-=o,n.y-=o,n.z-=o,r.x+=o,r.y+=o,r.z+=o),this},o.prototype.copy=function(t){return this.lowerBound.copy(t.lowerBound),this.upperBound.copy(t.upperBound),this},o.prototype.clone=function(){return(new o).copy(this)},o.prototype.extend=function(t){this.lowerBound.x=Math.min(this.lowerBound.x,t.lowerBound.x),this.upperBound.x=Math.max(this.upperBound.x,t.upperBound.x),this.lowerBound.y=Math.min(this.lowerBound.y,t.lowerBound.y),this.upperBound.y=Math.max(this.upperBound.y,t.upperBound.y),this.lowerBound.z=Math.min(this.lowerBound.z,t.lowerBound.z),this.upperBound.z=Math.max(this.upperBound.z,t.upperBound.z)},o.prototype.overlaps=function(t){var e=this.lowerBound,i=this.upperBound,o=t.lowerBound,n=t.upperBound,s=o.x<=i.x&&i.x<=n.x||e.x<=n.x&&n.x<=i.x,r=o.y<=i.y&&i.y<=n.y||e.y<=n.y&&n.y<=i.y,a=o.z<=i.z&&i.z<=n.z||e.z<=n.z&&n.z<=i.z;return s&&r&&a},o.prototype.volume=function(){var t=this.lowerBound,e=this.upperBound;return(e.x-t.x)*(e.y-t.y)*(e.z-t.z)},o.prototype.contains=function(t){var e=this.lowerBound,i=this.upperBound,o=t.lowerBound,n=t.upperBound;return e.x<=o.x&&i.x>=n.x&&e.y<=o.y&&i.y>=n.y&&e.z<=o.z&&i.z>=n.z},o.prototype.getCorners=function(t,e,i,o,n,s,r,a){var h=this.lowerBound,l=this.upperBound;t.copy(h),e.set(l.x,h.y,h.z),i.set(l.x,l.y,h.z),o.set(h.x,l.y,l.z),n.set(l.x,h.y,h.z),s.set(h.x,l.y,h.z),r.set(h.x,h.y,l.z),a.copy(l)};var r=[new n,new n,new n,new n,new n,new n,new n,new n];o.prototype.toLocalFrame=function(t,e){var i=r,o=i[0],n=i[1],s=i[2],a=i[3],h=i[4],l=i[5],c=i[6],p=i[7];this.getCorners(o,n,s,a,h,l,c,p);for(var u=0;8!==u;u++){var d=i[u];t.pointToLocal(d,d)}return e.setFromPoints(i)},o.prototype.toWorldFrame=function(t,e){var i=r,o=i[0],n=i[1],s=i[2],a=i[3],h=i[4],l=i[5],c=i[6],p=i[7];this.getCorners(o,n,s,a,h,l,c,p);for(var u=0;8!==u;u++){var d=i[u];t.pointToWorld(d,d)}return e.setFromPoints(i)},o.prototype.overlapsRay=function(t){var e=1/t._direction.x,i=1/t._direction.y,o=1/t._direction.z,n=(this.lowerBound.x-t.from.x)*e,s=(this.upperBound.x-t.from.x)*e,r=(this.lowerBound.y-t.from.y)*i,a=(this.upperBound.y-t.from.y)*i,h=(this.lowerBound.z-t.from.z)*o,l=(this.upperBound.z-t.from.z)*o,c=Math.max(Math.max(Math.min(n,s),Math.min(r,a)),Math.min(h,l)),p=Math.min(Math.min(Math.max(n,s),Math.max(r,a)),Math.max(h,l));return!(p<0)&&!(c>p)}},{"../math/Vec3":43,"../utils/Utils":66}],16:[function(t,e,i){function o(){this.matrix=[]}e.exports=o,o.prototype.get=function(t,e){if(t=t.index,(e=e.index)>t){var i=e;e=t,t=i}return this.matrix[(t*(t+1)>>1)+e-1]},o.prototype.set=function(t,e,i){if(t=t.index,(e=e.index)>t){var o=e;e=t,t=o}this.matrix[(t*(t+1)>>1)+e-1]=i?1:0},o.prototype.reset=function(){for(var t=0,e=this.matrix.length;t!==e;t++)this.matrix[t]=0},o.prototype.setNumObjects=function(t){this.matrix.length=t*(t-1)>>1}},{}],17:[function(t,e,i){function o(){this.world=null,this.useBoundingBoxes=!1,this.dirty=!0}var n=t("../objects/Body"),s=t("../math/Vec3"),r=t("../math/Quaternion");t("../shapes/Shape"),t("../shapes/Plane");e.exports=o,o.prototype.collisionPairs=function(t,e,i){throw new Error("collisionPairs not implemented for this BroadPhase class!")},o.prototype.needBroadphaseCollision=function(t,e){return 0!=(t.collisionFilterGroup&e.collisionFilterMask)&&0!=(e.collisionFilterGroup&t.collisionFilterMask)&&(0==(t.type&n.STATIC)&&t.sleepState!==n.SLEEPING||0==(e.type&n.STATIC)&&e.sleepState!==n.SLEEPING)},o.prototype.intersectionTest=function(t,e,i,o){this.useBoundingBoxes?this.doBoundingBoxBroadphase(t,e,i,o):this.doBoundingSphereBroadphase(t,e,i,o)};var a=new s;new s,new r,new s;o.prototype.doBoundingSphereBroadphase=function(t,e,i,o){var n=a;e.position.vsub(t.position,n);var s=Math.pow(t.boundingRadius+e.boundingRadius,2);n.norm2()<s&&(i.push(t),o.push(e))},o.prototype.doBoundingBoxBroadphase=function(t,e,i,o){t.aabbNeedsUpdate&&t.computeAABB(),e.aabbNeedsUpdate&&e.computeAABB(),t.aabb.overlaps(e.aabb)&&(i.push(t),o.push(e))};var h={keys:[]},l=[],c=[];o.prototype.makePairsUnique=function(t,e){for(var i=h,o=l,n=c,s=t.length,r=0;r!==s;r++)o[r]=t[r],n[r]=e[r];t.length=0,e.length=0;for(r=0;r!==s;r++){var a=o[r].id,p=n[r].id;i[u=a<p?a+","+p:p+","+a]=r,i.keys.push(u)}for(r=0;r!==i.keys.length;r++){var u=i.keys.pop(),d=i[u];t.push(o[d]),e.push(n[d]),delete i[u]}},o.prototype.setWorld=function(t){};var p=new s;o.boundingSphereCheck=function(t,e){var i=p;return t.position.vsub(e.position,i),Math.pow(t.shape.boundingSphereRadius+e.shape.boundingSphereRadius,2)>i.norm2()},o.prototype.aabbQuery=function(t,e,i){return console.warn(".aabbQuery is not implemented in this Broadphase subclass."),[]}},{"../math/Quaternion":41,"../math/Vec3":43,"../objects/Body":44,"../shapes/Plane":55,"../shapes/Shape":56}],18:[function(t,e,i){function o(t,e,i,o,r){n.apply(this),this.nx=i||10,this.ny=o||10,this.nz=r||10,this.aabbMin=t||new s(100,100,100),this.aabbMax=e||new s(-100,-100,-100);var a=this.nx*this.ny*this.nz;if(a<=0)throw"GridBroadphase: Each dimension's n must be >0";this.bins=[],this.binLengths=[],this.bins.length=a,this.binLengths.length=a;for(var h=0;h<a;h++)this.bins[h]=[],this.binLengths[h]=0}e.exports=o;var n=t("./Broadphase"),s=t("../math/Vec3"),r=t("../shapes/Shape");(o.prototype=new n).constructor=o;var a=new s;new s;o.prototype.collisionPairs=function(t,e,i){function o(t,e,i,o,n,s,r){var a=(t-g)*E|0,h=(e-x)*B|0,l=(i-b)*A|0,f=I((o-g)*E),m=I((n-x)*B),w=I((s-b)*A);a<0?a=0:a>=c&&(a=c-1),h<0?h=0:h>=p&&(h=p-1),l<0?l=0:l>=u&&(l=u-1),f<0?f=0:f>=c&&(f=c-1),m<0?m=0:m>=p&&(m=p-1),w<0?w=0:w>=u&&(w=u-1),h*=v,l*=y,f*=d,m*=v,w*=y;for(var S=a*=d;S<=f;S+=d)for(var R=h;R<=m;R+=v)for(var z=l;z<=w;z+=y){var M=S+R+z;V[M][F[M]++]=r}}for(var n=t.numObjects(),s=t.bodies,h=this.aabbMax,l=this.aabbMin,c=this.nx,p=this.ny,u=this.nz,d=p*u,v=u,y=1,f=h.x,m=h.y,w=h.z,g=l.x,x=l.y,b=l.z,E=c/(f-g),B=p/(m-x),A=u/(w-b),S=(f-g)/c,R=(m-x)/p,z=(w-b)/u,M=.5*Math.sqrt(S*S+R*R+z*z),C=r.types,T=C.SPHERE,q=C.PLANE,V=(C.BOX,C.COMPOUND,C.CONVEXPOLYHEDRON,this.bins),F=this.binLengths,P=this.bins.length,N=0;N!==P;N++)F[N]=0;for(var I=Math.ceil,l=Math.min,h=Math.max,N=0;N!==n;N++){var L=(it=s[N]).shape;switch(L.type){case T:var j=it.position.x,W=it.position.y,O=it.position.z,H=L.radius;o(j-H,W-H,O-H,j+H,W+H,O+H,it);break;case q:L.worldNormalNeedsUpdate&&L.computeWorldNormal(it.quaternion);var k=L.worldNormal,_=g+.5*S-it.position.x,D=x+.5*R-it.position.y,G=b+.5*z-it.position.z,U=a;U.set(_,D,G);for(var X=0,Q=0;X!==c;X++,Q+=d,U.y=D,U.x+=S)for(var Y=0,Z=0;Y!==p;Y++,Z+=v,U.z=G,U.y+=R)for(var K=0,J=0;K!==u;K++,J+=y,U.z+=z)if(U.dot(k)<M){var $=Q+Z+J;V[$][F[$]++]=it}break;default:it.aabbNeedsUpdate&&it.computeAABB(),o(it.aabb.lowerBound.x,it.aabb.lowerBound.y,it.aabb.lowerBound.z,it.aabb.upperBound.x,it.aabb.upperBound.y,it.aabb.upperBound.z,it)}}for(N=0;N!==P;N++){var tt=F[N];if(tt>1)for(var et=V[N],X=0;X!==tt;X++)for(var it=et[X],Y=0;Y!==X;Y++){var ot=et[Y];this.needBroadphaseCollision(it,ot)&&this.intersectionTest(it,ot,e,i)}}this.makePairsUnique(e,i)}},{"../math/Vec3":43,"../shapes/Shape":56,"./Broadphase":17}],19:[function(t,e,i){function o(){n.apply(this)}e.exports=o;var n=t("./Broadphase"),s=t("./AABB");(o.prototype=new n).constructor=o,o.prototype.collisionPairs=function(t,e,i){var o,n,s,r,a=t.bodies,h=a.length;for(o=0;o!==h;o++)for(n=0;n!==o;n++)s=a[o],r=a[n],this.needBroadphaseCollision(s,r)&&this.intersectionTest(s,r,e,i)};new s;o.prototype.aabbQuery=function(t,e,i){i=i||[];for(var o=0;o<t.bodies.length;o++){var n=t.bodies[o];n.aabbNeedsUpdate&&n.computeAABB(),n.aabb.overlaps(e)&&i.push(n)}return i}},{"./AABB":15,"./Broadphase":17}],20:[function(t,e,i){function o(){this.matrix={}}e.exports=o,o.prototype.get=function(t,e){if(t=t.id,(e=e.id)>t){var i=e;e=t,t=i}return t+"-"+e in this.matrix},o.prototype.set=function(t,e,i){if(t=t.id,(e=e.id)>t){var o=e;e=t,t=o}i?this.matrix[t+"-"+e]=!0:delete this.matrix[t+"-"+e]},o.prototype.reset=function(){this.matrix={}},o.prototype.setNumObjects=function(t){}},{}],21:[function(t,e,i){function o(){this.current=[],this.previous=[]}function n(t,e){t.push((4294901760&e)>>16,65535&e)}e.exports=o,o.prototype.getKey=function(t,e){if(e<t){var i=e;e=t,t=i}return t<<16|e},o.prototype.set=function(t,e){for(var i=this.getKey(t,e),o=this.current,n=0;i>o[n];)n++;if(i!==o[n]){for(e=o.length-1;e>=n;e--)o[e+1]=o[e];o[n]=i}},o.prototype.tick=function(){var t=this.current;this.current=this.previous,this.previous=t,this.current.length=0},o.prototype.getDiff=function(t,e){for(var i=this.current,o=this.previous,s=i.length,r=o.length,a=0,h=0;h<s;h++){for(var l=i[h];l>o[a];)a++;l===o[a]||n(t,l)}a=0;for(h=0;h<r;h++){for(var c=o[h];c>i[a];)a++;i[a]===c||n(e,c)}}},{}],22:[function(t,e,i){function o(t,e){this.from=t?t.clone():new s,this.to=e?e.clone():new s,this._direction=new s,this.precision=1e-4,this.checkCollisionResponse=!0,this.skipBackfaces=!1,this.collisionFilterMask=-1,this.collisionFilterGroup=-1,this.mode=o.ANY,this.result=new h,this.hasHit=!1,this.callback=function(t){}}function n(t,e,i,o){o.vsub(e,L),i.vsub(e,d),t.vsub(e,v);var n,s,r=L.dot(L),a=L.dot(d),h=L.dot(v),l=d.dot(d),c=d.dot(v);return(n=l*h-a*c)>=0&&(s=r*c-a*h)>=0&&n+s<r*l-a*a}e.exports=o;var s=t("../math/Vec3"),r=t("../math/Quaternion"),a=t("../math/Transform"),h=(t("../shapes/ConvexPolyhedron"),t("../shapes/Box"),t("../collision/RaycastResult")),l=t("../shapes/Shape"),c=t("../collision/AABB");o.prototype.constructor=o,o.CLOSEST=1,o.ANY=2,o.ALL=4;var p=new c,u=[];o.prototype.intersectWorld=function(t,e){return this.mode=e.mode||o.ANY,this.result=e.result||new h,this.skipBackfaces=!!e.skipBackfaces,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(p),u.length=0,t.broadphase.aabbQuery(t,p,u),this.intersectBodies(u),this.hasHit};var d=new s,v=new s;o.pointInTriangle=n;var y=new s,f=new r;o.prototype.intersectBody=function(t,e){e&&(this.result=e,this._updateDirection());var i=this.checkCollisionResponse;if((!i||t.collisionResponse)&&0!=(this.collisionFilterGroup&t.collisionFilterMask)&&0!=(t.collisionFilterGroup&this.collisionFilterMask))for(var o=y,n=f,s=0,r=t.shapes.length;s<r;s++){var a=t.shapes[s];if((!i||a.collisionResponse)&&(t.quaternion.mult(t.shapeOrientations[s],n),t.quaternion.vmult(t.shapeOffsets[s],o),o.vadd(t.position,o),this.intersectShape(a,n,o,t),this.result._shouldStop))break}},o.prototype.intersectBodies=function(t,e){e&&(this.result=e,this._updateDirection());for(var i=0,o=t.length;!this.result._shouldStop&&i<o;i++)this.intersectBody(t[i])},o.prototype._updateDirection=function(){this.to.vsub(this.from,this._direction),this._direction.normalize()},o.prototype.intersectShape=function(t,e,i,o){if(!(function(t,e,i){i.vsub(t,L);var o=L.dot(e);return e.mult(o,j),j.vadd(t,j),i.distanceTo(j)}(this.from,this._direction,i)>t.boundingSphereRadius)){var n=this[t.type];n&&n.call(this,t,e,i,o,t)}};new s,new s;var m=new s,w=new s,g=new s,x=new s;new s,new h;o.prototype.intersectBox=function(t,e,i,o,n){return this.intersectConvex(t.convexPolyhedronRepresentation,e,i,o,n)},o.prototype[l.types.BOX]=o.prototype.intersectBox,o.prototype.intersectPlane=function(t,e,i,o,n){var r=this.from,a=this.to,h=this._direction,l=new s(0,0,1);e.vmult(l,l);var c=new s;r.vsub(i,c);var p=c.dot(l);a.vsub(i,c);if(!(p*c.dot(l)>0||r.distanceTo(a)<p)){var u=l.dot(h);if(!(Math.abs(u)<this.precision)){var d=new s,v=new s,y=new s;r.vsub(i,d);var f=-l.dot(d)/u;h.scale(f,v),r.vadd(v,y),this.reportIntersection(l,y,n,o,-1)}}},o.prototype[l.types.PLANE]=o.prototype.intersectPlane,o.prototype.getAABB=function(t){var e=this.to,i=this.from;t.lowerBound.x=Math.min(e.x,i.x),t.lowerBound.y=Math.min(e.y,i.y),t.lowerBound.z=Math.min(e.z,i.z),t.upperBound.x=Math.max(e.x,i.x),t.upperBound.y=Math.max(e.y,i.y),t.upperBound.z=Math.max(e.z,i.z)};var b={faceList:[0]},E=new s,B=new o,A=[];o.prototype.intersectHeightfield=function(t,e,i,o,n){t.data,t.elementSize;var s=B;s.from.copy(this.from),s.to.copy(this.to),a.pointToLocalFrame(i,e,s.from,s.from),a.pointToLocalFrame(i,e,s.to,s.to),s._updateDirection();var r,h,l,p,u=A;r=h=0,l=p=t.data.length-1;var d=new c;s.getAABB(d),t.getIndexOfPosition(d.lowerBound.x,d.lowerBound.y,u,!0),r=Math.max(r,u[0]),h=Math.max(h,u[1]),t.getIndexOfPosition(d.upperBound.x,d.upperBound.y,u,!0),l=Math.min(l,u[0]+1),p=Math.min(p,u[1]+1);for(var v=r;v<l;v++)for(var y=h;y<p;y++){if(this.result._shouldStop)return;if(t.getAabbAtIndex(v,y,d),d.overlapsRay(s)){if(t.getConvexTrianglePillar(v,y,!1),a.pointToWorldFrame(i,e,t.pillarOffset,E),this.intersectConvex(t.pillarConvex,e,E,o,n,b),this.result._shouldStop)return;t.getConvexTrianglePillar(v,y,!0),a.pointToWorldFrame(i,e,t.pillarOffset,E),this.intersectConvex(t.pillarConvex,e,E,o,n,b)}}},o.prototype[l.types.HEIGHTFIELD]=o.prototype.intersectHeightfield;var S=new s,R=new s;o.prototype.intersectSphere=function(t,e,i,o,n){var s=this.from,r=this.to,a=t.radius,h=Math.pow(r.x-s.x,2)+Math.pow(r.y-s.y,2)+Math.pow(r.z-s.z,2),l=2*((r.x-s.x)*(s.x-i.x)+(r.y-s.y)*(s.y-i.y)+(r.z-s.z)*(s.z-i.z)),c=Math.pow(s.x-i.x,2)+Math.pow(s.y-i.y,2)+Math.pow(s.z-i.z,2)-Math.pow(a,2),p=Math.pow(l,2)-4*h*c,u=S,d=R;if(!(p<0))if(0===p)s.lerp(r,p,u),u.vsub(i,d),d.normalize(),this.reportIntersection(d,u,n,o,-1);else{var v=(-l-Math.sqrt(p))/(2*h),y=(-l+Math.sqrt(p))/(2*h);if(v>=0&&v<=1&&(s.lerp(r,v,u),u.vsub(i,d),d.normalize(),this.reportIntersection(d,u,n,o,-1)),this.result._shouldStop)return;y>=0&&y<=1&&(s.lerp(r,y,u),u.vsub(i,d),d.normalize(),this.reportIntersection(d,u,n,o,-1))}},o.prototype[l.types.SPHERE]=o.prototype.intersectSphere;var z=new s,M=(new s,new s,new s);o.prototype.intersectConvex=function(t,e,i,o,s,r){for(var a=z,h=M,l=r&&r.faceList||null,c=t.faces,p=t.vertices,u=t.faceNormals,d=this._direction,v=this.from,y=this.to,f=v.distanceTo(y),b=l?l.length:c.length,E=this.result,B=0;!E._shouldStop&&B<b;B++){var A=l?l[B]:B,S=c[A],R=u[A],C=e,T=i;h.copy(p[S[0]]),C.vmult(h,h),h.vadd(T,h),h.vsub(v,h),C.vmult(R,a);var q=d.dot(a);if(!(Math.abs(q)<this.precision)){var V=a.dot(h)/q;if(!(V<0)){d.mult(V,m),m.vadd(v,m),w.copy(p[S[0]]),C.vmult(w,w),T.vadd(w,w);for(var F=1;!E._shouldStop&&F<S.length-1;F++){g.copy(p[S[F]]),x.copy(p[S[F+1]]),C.vmult(g,g),C.vmult(x,x),T.vadd(g,g),T.vadd(x,x);var P=m.distanceTo(v);!n(m,w,g,x)&&!n(m,g,w,x)||P>f||this.reportIntersection(a,m,s,o,A)}}}}},o.prototype[l.types.CONVEXPOLYHEDRON]=o.prototype.intersectConvex;var C=new s,T=new s,q=new s,V=new s,F=new s,P=new s,N=(new c,[]),I=new a;o.prototype.intersectTrimesh=function(t,e,i,o,s,r){var h=C,l=N,c=I,p=M,u=T,d=q,v=V,y=P,f=F,b=(r&&r.faceList,t.indices),E=(t.vertices,t.faceNormals,this.from),B=this.to,A=this._direction;c.position.copy(i),c.quaternion.copy(e),a.vectorToLocalFrame(i,e,A,u),a.pointToLocalFrame(i,e,E,d),a.pointToLocalFrame(i,e,B,v),v.x*=t.scale.x,v.y*=t.scale.y,v.z*=t.scale.z,d.x*=t.scale.x,d.y*=t.scale.y,d.z*=t.scale.z,v.vsub(d,u),u.normalize();var S=d.distanceSquared(v);t.tree.rayQuery(this,c,l);for(var R=0,z=l.length;!this.result._shouldStop&&R!==z;R++){var L=l[R];t.getNormal(L,h),t.getVertex(b[3*L],w),w.vsub(d,p);var j=u.dot(h),W=h.dot(p)/j;if(!(W<0)){u.scale(W,m),m.vadd(d,m),t.getVertex(b[3*L+1],g),t.getVertex(b[3*L+2],x);var O=m.distanceSquared(d);!n(m,g,w,x)&&!n(m,w,g,x)||O>S||(a.vectorToWorldFrame(e,h,f),a.pointToWorldFrame(i,e,m,y),this.reportIntersection(f,y,s,o,L))}}l.length=0},o.prototype[l.types.TRIMESH]=o.prototype.intersectTrimesh,o.prototype.reportIntersection=function(t,e,i,n,s){var r=this.from,a=this.to,h=r.distanceTo(e),l=this.result;if(!(this.skipBackfaces&&t.dot(this._direction)>0))switch(l.hitFaceIndex=void 0!==s?s:-1,this.mode){case o.ALL:this.hasHit=!0,l.set(r,a,t,e,i,n,h),l.hasHit=!0,this.callback(l);break;case o.CLOSEST:(h<l.distance||!l.hasHit)&&(this.hasHit=!0,l.hasHit=!0,l.set(r,a,t,e,i,n,h));break;case o.ANY:this.hasHit=!0,l.hasHit=!0,l.set(r,a,t,e,i,n,h),l._shouldStop=!0}};var L=new s,j=new s},{"../collision/AABB":15,"../collision/RaycastResult":23,"../math/Quaternion":41,"../math/Transform":42,"../math/Vec3":43,"../shapes/Box":50,"../shapes/ConvexPolyhedron":51,"../shapes/Shape":56}],23:[function(t,e,i){function o(){this.rayFromWorld=new n,this.rayToWorld=new n,this.hitNormalWorld=new n,this.hitPointWorld=new n,this.hasHit=!1,this.shape=null,this.body=null,this.hitFaceIndex=-1,this.distance=-1,this._shouldStop=!1}var n=t("../math/Vec3");e.exports=o,o.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},o.prototype.abort=function(){this._shouldStop=!0},o.prototype.set=function(t,e,i,o,n,s,r){this.rayFromWorld.copy(t),this.rayToWorld.copy(e),this.hitNormalWorld.copy(i),this.hitPointWorld.copy(o),this.shape=n,this.body=s,this.distance=r}},{"../math/Vec3":43}],24:[function(t,e,i){function o(t){n.apply(this),this.axisList=[],this.world=null,this.axisIndex=0;var e=this.axisList;this._addBodyHandler=function(t){e.push(t.body)},this._removeBodyHandler=function(t){var i=e.indexOf(t.body);-1!==i&&e.splice(i,1)},t&&this.setWorld(t)}t("../shapes/Shape");var n=t("../collision/Broadphase");e.exports=o,(o.prototype=new n).setWorld=function(t){this.axisList.length=0;for(var e=0;e<t.bodies.length;e++)this.axisList.push(t.bodies[e]);t.removeEventListener("addBody",this._addBodyHandler),t.removeEventListener("removeBody",this._removeBodyHandler),t.addEventListener("addBody",this._addBodyHandler),t.addEventListener("removeBody",this._removeBodyHandler),this.world=t,this.dirty=!0},o.insertionSortX=function(t){for(var e=1,i=t.length;e<i;e++){for(var o=t[e],n=e-1;n>=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<i;e++){for(var o=t[e],n=e-1;n>=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<i;e++){for(var o=t[e],n=e-1;n>=0&&!(t[n].aabb.lowerBound.z<=o.aabb.lowerBound.z);n--)t[n+1]=t[n];t[n+1]=o}return t},o.prototype.collisionPairs=function(t,e,i){var n,s,r=this.axisList,a=r.length,h=this.axisIndex;for(this.dirty&&(this.sortList(),this.dirty=!1),n=0;n!==a;n++){var l=r[n];for(s=n+1;s<a;s++){var c=r[s];if(this.needBroadphaseCollision(l,c)){if(!o.checkBounds(l,c,h))break;this.intersectionTest(l,c,e,i)}}}},o.prototype.sortList=function(){for(var t=this.axisList,e=this.axisIndex,i=t.length,n=0;n!==i;n++){var s=t[n];s.aabbNeedsUpdate&&s.computeAABB()}0===e?o.insertionSortX(t):1===e?o.insertionSortY(t):2===e&&o.insertionSortZ(t)},o.checkBounds=function(t,e,i){var o,n;0===i?(o=t.position.x,n=e.position.x):1===i?(o=t.position.y,n=e.position.y):2===i&&(o=t.position.z,n=e.position.z);var s=t.boundingRadius,r=e.boundingRadius;return n-r<o+s},o.prototype.autoDetectAxis=function(){for(var t=0,e=0,i=0,o=0,n=0,s=0,r=this.axisList,a=r.length,h=1/a,l=0;l!==a;l++){var c=r[l],p=c.position.x;t+=p,e+=p*p;var u=c.position.y;i+=u,o+=u*u;var d=c.position.z;n+=d,s+=d*d}var v=e-t*t*h,y=o-i*i*h,f=s-n*n*h;this.axisIndex=v>y?v>f?0:2:y>f?1:2},o.prototype.aabbQuery=function(t,e,i){i=i||[],this.dirty&&(this.sortList(),this.dirty=!1);var o=this.axisIndex,n="x";1===o&&(n="y"),2===o&&(n="z");for(var s=this.axisList,r=(e.lowerBound[n],e.upperBound[n],0);r<s.length;r++){var a=s[r];a.aabbNeedsUpdate&&a.computeAABB(),a.aabb.overlaps(e)&&i.push(a)}return i}},{"../collision/Broadphase":17,"../shapes/Shape":56}],25:[function(t,e,i){function o(t,e,i){var o=void 0!==(i=i||{}).maxForce?i.maxForce:1e6,h=i.pivotA?i.pivotA.clone():new a,l=i.pivotB?i.pivotB.clone():new a;this.axisA=i.axisA?i.axisA.clone():new a,this.axisB=i.axisB?i.axisB.clone():new a,n.call(this,t,h,e,l,o),this.collideConnected=!!i.collideConnected,this.angle=void 0!==i.angle?i.angle:0;var c=this.coneEquation=new s(t,e,i),p=this.twistEquation=new r(t,e,i);this.twistAngle=void 0!==i.twistAngle?i.twistAngle:0,c.maxForce=0,c.minForce=-o,p.maxForce=0,p.minForce=-o,this.equations.push(c,p)}e.exports=o;t("./Constraint");var n=t("./PointToPointConstraint"),s=t("../equations/ConeEquation"),r=t("../equations/RotationalEquation"),a=(t("../equations/ContactEquation"),t("../math/Vec3"));o.prototype=new n,o.constructor=o;new a,new a;o.prototype.update=function(){var t=this.bodyA,e=this.bodyB,i=this.coneEquation,o=this.twistEquation;n.prototype.update.call(this),t.vectorToWorldFrame(this.axisA,i.axisA),e.vectorToWorldFrame(this.axisB,i.axisB),this.axisA.tangents(o.axisA,o.axisA),t.vectorToWorldFrame(o.axisA,o.axisA),this.axisB.tangents(o.axisB,o.axisB),e.vectorToWorldFrame(o.axisB,o.axisB),i.angle=this.angle,o.maxAngle=this.twistAngle}},{"../equations/ConeEquation":31,"../equations/ContactEquation":32,"../equations/RotationalEquation":35,"../math/Vec3":43,"./Constraint":26,"./PointToPointConstraint":30}],26:[function(t,e,i){function o(t,e,i){i=n.defaults(i,{collideConnected:!0,wakeUpBodies:!0}),this.equations=[],this.bodyA=t,this.bodyB=e,this.id=o.idCounter++,this.collideConnected=i.collideConnected,i.wakeUpBodies&&(t&&t.wakeUp(),e&&e.wakeUp())}e.exports=o;var n=t("../utils/Utils");o.prototype.update=function(){throw new Error("method update() not implmemented in this Constraint subclass!")},o.prototype.enable=function(){for(var t=this.equations,e=0;e<t.length;e++)t[e].enabled=!0},o.prototype.disable=function(){for(var t=this.equations,e=0;e<t.length;e++)t[e].enabled=!1},o.idCounter=0},{"../utils/Utils":66}],27:[function(t,e,i){function o(t,e,i,o){n.call(this,t,e),void 0===i&&(i=t.position.distanceTo(e.position)),void 0===o&&(o=1e6),this.distance=i;var r=this.distanceEquation=new s(t,e);this.equations.push(r),r.minForce=-o,r.maxForce=o}e.exports=o;var n=t("./Constraint"),s=t("../equations/ContactEquation");(o.prototype=new n).update=function(){var t=this.bodyA,e=this.bodyB,i=this.distanceEquation,o=.5*this.distance,n=i.ni;e.position.vsub(t.position,n),n.normalize(),n.mult(o,i.ri),n.mult(-o,i.rj)}},{"../equations/ContactEquation":32,"./Constraint":26}],28:[function(t,e,i){function o(t,e,i){var o=void 0!==(i=i||{}).maxForce?i.maxForce:1e6,h=i.pivotA?i.pivotA.clone():new a,l=i.pivotB?i.pivotB.clone():new a;n.call(this,t,h,e,l,o);(this.axisA=i.axisA?i.axisA.clone():new a(1,0,0)).normalize();(this.axisB=i.axisB?i.axisB.clone():new a(1,0,0)).normalize();var c=this.rotationalEquation1=new s(t,e,i),p=this.rotationalEquation2=new s(t,e,i),u=this.motorEquation=new r(t,e,o);u.enabled=!1,this.equations.push(c,p,u)}e.exports=o;t("./Constraint");var n=t("./PointToPointConstraint"),s=t("../equations/RotationalEquation"),r=t("../equations/RotationalMotorEquation"),a=(t("../equations/ContactEquation"),t("../math/Vec3"));o.prototype=new n,o.constructor=o,o.prototype.enableMotor=function(){this.motorEquation.enabled=!0},o.prototype.disableMotor=function(){this.motorEquation.enabled=!1},o.prototype.setMotorSpeed=function(t){this.motorEquation.targetVelocity=t},o.prototype.setMotorMaxForce=function(t){this.motorEquation.maxForce=t,this.motorEquation.minForce=-t};var h=new a,l=new a;o.prototype.update=function(){var t=this.bodyA,e=this.bodyB,i=this.motorEquation,o=this.rotationalEquation1,s=this.rotationalEquation2,r=h,a=l,c=this.axisA,p=this.axisB;n.prototype.update.call(this),t.quaternion.vmult(c,r),e.quaternion.vmult(p,a),r.tangents(o.axisA,s.axisA),o.axisB.copy(a),s.axisB.copy(a),this.motorEquation.enabled&&(t.quaternion.vmult(this.axisA,i.axisA),e.quaternion.vmult(this.axisB,i.axisB))}},{"../equations/ContactEquation":32,"../equations/RotationalEquation":35,"../equations/RotationalMotorEquation":36,"../math/Vec3":43,"./Constraint":26,"./PointToPointConstraint":30}],29:[function(t,e,i){function o(t,e,i){var o=void 0!==(i=i||{}).maxForce?i.maxForce:1e6,a=new r,h=new r,l=new r;t.position.vadd(e.position,l),l.scale(.5,l),e.pointToLocalFrame(l,h),t.pointToLocalFrame(l,a),n.call(this,t,a,e,h,o),this.xA=t.vectorToLocalFrame(r.UNIT_X),this.xB=e.vectorToLocalFrame(r.UNIT_X),this.yA=t.vectorToLocalFrame(r.UNIT_Y),this.yB=e.vectorToLocalFrame(r.UNIT_Y),this.zA=t.vectorToLocalFrame(r.UNIT_Z),this.zB=e.vectorToLocalFrame(r.UNIT_Z);var c=this.rotationalEquation1=new s(t,e,i),p=this.rotationalEquation2=new s(t,e,i),u=this.rotationalEquation3=new s(t,e,i);this.equations.push(c,p,u)}e.exports=o;t("./Constraint");var n=t("./PointToPointConstraint"),s=t("../equations/RotationalEquation"),r=(t("../equations/RotationalMotorEquation"),t("../equations/ContactEquation"),t("../math/Vec3"));o.prototype=new n,o.constructor=o;new r,new r;o.prototype.update=function(){var t=this.bodyA,e=this.bodyB,i=(this.motorEquation,this.rotationalEquation1),o=this.rotationalEquation2,s=this.rotationalEquation3;n.prototype.update.call(this),t.vectorToWorldFrame(this.xA,i.axisA),e.vectorToWorldFrame(this.yB,i.axisB),t.vectorToWorldFrame(this.yA,o.axisA),e.vectorToWorldFrame(this.zB,o.axisB),t.vectorToWorldFrame(this.zA,s.axisA),e.vectorToWorldFrame(this.xB,s.axisB)}},{"../equations/ContactEquation":32,"../equations/RotationalEquation":35,"../equations/RotationalMotorEquation":36,"../math/Vec3":43,"./Constraint":26,"./PointToPointConstraint":30}],30:[function(t,e,i){function o(t,e,i,o,a){n.call(this,t,i),a=void 0!==a?a:1e6,this.pivotA=e?e.clone():new r,this.pivotB=o?o.clone():new r;var h=this.equationX=new s(t,i),l=this.equationY=new s(t,i),c=this.equationZ=new s(t,i);this.equations.push(h,l,c),h.minForce=l.minForce=c.minForce=-a,h.maxForce=l.maxForce=c.maxForce=a,h.ni.set(1,0,0),l.ni.set(0,1,0),c.ni.set(0,0,1)}e.exports=o;var n=t("./Constraint"),s=t("../equations/ContactEquation"),r=t("../math/Vec3");(o.prototype=new n).update=function(){var t=this.bodyA,e=this.bodyB,i=this.equationX,o=this.equationY,n=this.equationZ;t.quaternion.vmult(this.pivotA,i.ri),e.quaternion.vmult(this.pivotB,i.rj),o.ri.copy(i.ri),o.rj.copy(i.rj),n.ri.copy(i.ri),n.rj.copy(i.rj)}},{"../equations/ContactEquation":32,"../math/Vec3":43,"./Constraint":26}],31:[function(t,e,i){function o(t,e,i){var o=void 0!==(i=i||{}).maxForce?i.maxForce:1e6;s.call(this,t,e,-o,o),this.axisA=i.axisA?i.axisA.clone():new n(1,0,0),this.axisB=i.axisB?i.axisB.clone():new n(0,1,0),this.angle=void 0!==i.angle?i.angle:0}e.exports=o;var n=t("../math/Vec3"),s=(t("../math/Mat3"),t("./Equation"));(o.prototype=new s).constructor=o;var r=new n,a=new n;o.prototype.computeB=function(t){var e=this.a,i=this.b,o=this.axisA,n=this.axisB,s=r,h=a,l=this.jacobianElementA,c=this.jacobianElementB;o.cross(n,s),n.cross(o,h),l.rotational.copy(h),c.rotational.copy(s);return-(Math.cos(this.angle)-o.dot(n))*e-this.computeGW()*i-t*this.computeGiMf()}},{"../math/Mat3":40,"../math/Vec3":43,"./Equation":33}],32:[function(t,e,i){function o(t,e,i){i=void 0!==i?i:1e6,n.call(this,t,e,0,i),this.restitution=0,this.ri=new s,this.rj=new s,this.ni=new s}e.exports=o;var n=t("./Equation"),s=t("../math/Vec3");t("../math/Mat3");(o.prototype=new n).constructor=o;var r=new s,a=new s,h=new s;o.prototype.computeB=function(t){var e=this.a,i=this.b,o=this.bi,n=this.bj,s=this.ri,l=this.rj,c=r,p=a,u=o.velocity,d=o.angularVelocity,v=(o.force,o.torque,n.velocity),y=n.angularVelocity,f=(n.force,n.torque,h),m=this.jacobianElementA,w=this.jacobianElementB,g=this.ni;s.cross(g,c),l.cross(g,p),g.negate(m.spatial),c.negate(m.rotational),w.spatial.copy(g),w.rotational.copy(p),f.copy(n.position),f.vadd(l,f),f.vsub(o.position,f),f.vsub(s,f);var x=g.dot(f),b=this.restitution+1;return-x*e-(b*v.dot(g)-b*u.dot(g)+y.dot(p)-d.dot(c))*i-t*this.computeGiMf()};var l=new s,c=new s,p=new s,u=new s,d=new s;o.prototype.getImpactVelocityAlongNormal=function(){var t=l,e=c,i=p,o=u,n=d;return this.bi.position.vadd(this.ri,i),this.bj.position.vadd(this.rj,o),this.bi.getVelocityAtWorldPoint(i,t),this.bj.getVelocityAtWorldPoint(o,e),t.vsub(e,n),this.ni.dot(n)}},{"../math/Mat3":40,"../math/Vec3":43,"./Equation":33}],33:[function(t,e,i){function o(t,e,i,s){this.id=o.id++,this.minForce=void 0===i?-1e6:i,this.maxForce=void 0===s?1e6:s,this.bi=t,this.bj=e,this.a=0,this.b=0,this.eps=0,this.jacobianElementA=new n,this.jacobianElementB=new n,this.enabled=!0,this.multiplier=0,this.setSpookParams(1e7,4,1/60)}e.exports=o;var n=t("../math/JacobianElement"),s=t("../math/Vec3");o.prototype.constructor=o,o.id=0,o.prototype.setSpookParams=function(t,e,i){var o=e,n=t,s=i;this.a=4/(s*(1+4*o)),this.b=4*o/(1+4*o),this.eps=4/(s*s*n*(1+4*o))},o.prototype.computeB=function(t,e,i){var o=this.computeGW();return-this.computeGq()*t-o*e-this.computeGiMf()*i},o.prototype.computeGq=function(){var t=this.jacobianElementA,e=this.jacobianElementB,i=this.bi,o=this.bj,n=i.position,s=o.position;return t.spatial.dot(n)+e.spatial.dot(s)};new s;o.prototype.computeGW=function(){var t=this.jacobianElementA,e=this.jacobianElementB,i=this.bi,o=this.bj,n=i.velocity,s=o.velocity,r=i.angularVelocity,a=o.angularVelocity;return t.multiplyVectors(n,r)+e.multiplyVectors(s,a)},o.prototype.computeGWlambda=function(){var t=this.jacobianElementA,e=this.jacobianElementB,i=this.bi,o=this.bj,n=i.vlambda,s=o.vlambda,r=i.wlambda,a=o.wlambda;return t.multiplyVectors(n,r)+e.multiplyVectors(s,a)};var r=new s,a=new s,h=new s,l=new s;o.prototype.computeGiMf=function(){var t=this.jacobianElementA,e=this.jacobianElementB,i=this.bi,o=this.bj,n=i.force,s=i.torque,c=o.force,p=o.torque,u=i.invMassSolve,d=o.invMassSolve;return n.scale(u,r),c.scale(d,a),i.invInertiaWorldSolve.vmult(s,h),o.invInertiaWorldSolve.vmult(p,l),t.multiplyVectors(r,h)+e.multiplyVectors(a,l)};var c=new s;o.prototype.computeGiMGt=function(){var t=this.jacobianElementA,e=this.jacobianElementB,i=this.bi,o=this.bj,n=i.invMassSolve,s=o.invMassSolve,r=i.invInertiaWorldSolve,a=o.invInertiaWorldSolve,h=n+s;return r.vmult(t.rotational,c),h+=c.dot(t.rotational),a.vmult(e.rotational,c),h+=c.dot(e.rotational)};var p=new s;new s,new s,new s,new s,new s;o.prototype.addToWlambda=function(t){var e=this.jacobianElementA,i=this.jacobianElementB,o=this.bi,n=this.bj,s=p;o.vlambda.addScaledVector(o.invMassSolve*t,e.spatial,o.vlambda),n.vlambda.addScaledVector(n.invMassSolve*t,i.spatial,n.vlambda),o.invInertiaWorldSolve.vmult(e.rotational,s),o.wlambda.addScaledVector(t,s,o.wlambda),n.invInertiaWorldSolve.vmult(i.rotational,s),n.wlambda.addScaledVector(t,s,n.wlambda)},o.prototype.computeC=function(){return this.computeGiMGt()+this.eps}},{"../math/JacobianElement":39,"../math/Vec3":43}],34:[function(t,e,i){function o(t,e,i){n.call(this,t,e,-i,i),this.ri=new s,this.rj=new s,this.t=new s}e.exports=o;var n=t("./Equation"),s=t("../math/Vec3");t("../math/Mat3");(o.prototype=new n).constructor=o;var r=new s,a=new s;o.prototype.computeB=function(t){this.a;var e=this.b,i=(this.bi,this.bj,this.ri),o=this.rj,n=r,s=a,h=this.t;i.cross(h,n),o.cross(h,s);var l=this.jacobianElementA,c=this.jacobianElementB;h.negate(l.spatial),n.negate(l.rotational),c.spatial.copy(h),c.rotational.copy(s);return-this.computeGW()*e-t*this.computeGiMf()}},{"../math/Mat3":40,"../math/Vec3":43,"./Equation":33}],35:[function(t,e,i){function o(t,e,i){var o=void 0!==(i=i||{}).maxForce?i.maxForce:1e6;s.call(this,t,e,-o,o),this.axisA=i.axisA?i.axisA.clone():new n(1,0,0),this.axisB=i.axisB?i.axisB.clone():new n(0,1,0),this.maxAngle=Math.PI/2}e.exports=o;var n=t("../math/Vec3"),s=(t("../math/Mat3"),t("./Equation"));(o.prototype=new s).constructor=o;var r=new n,a=new n;o.prototype.computeB=function(t){var e=this.a,i=this.b,o=this.axisA,n=this.axisB,s=r,h=a,l=this.jacobianElementA,c=this.jacobianElementB;o.cross(n,s),n.cross(o,h),l.rotational.copy(h),c.rotational.copy(s);return-(Math.cos(this.maxAngle)-o.dot(n))*e-this.computeGW()*i-t*this.computeGiMf()}},{"../math/Mat3":40,"../math/Vec3":43,"./Equation":33}],36:[function(t,e,i){function o(t,e,i){i=void 0!==i?i:1e6,s.call(this,t,e,-i,i),this.axisA=new n,this.axisB=new n,this.targetVelocity=0}e.exports=o;var n=t("../math/Vec3"),s=(t("../math/Mat3"),t("./Equation"));(o.prototype=new s).constructor=o,o.prototype.computeB=function(t){this.a;var e=this.b,i=(this.bi,this.bj,this.axisA),o=this.axisB,n=this.jacobianElementA,s=this.jacobianElementB;n.rotational.copy(i),o.negate(s.rotational);return-(this.computeGW()-this.targetVelocity)*e-t*this.computeGiMf()}},{"../math/Mat3":40,"../math/Vec3":43,"./Equation":33}],37:[function(t,e,i){function o(t,e,i){i=n.defaults(i,{friction:.3,restitution:.3,contactEquationStiffness:1e7,contactEquationRelaxation:3,frictionEquationStiffness:1e7,frictionEquationRelaxation:3}),this.id=o.idCounter++,this.materials=[t,e],this.friction=i.friction,this.restitution=i.restitution,this.contactEquationStiffness=i.contactEquationStiffness,this.contactEquationRelaxation=i.contactEquationRelaxation,this.frictionEquationStiffness=i.frictionEquationStiffness,this.frictionEquationRelaxation=i.frictionEquationRelaxation}var n=t("../utils/Utils");e.exports=o,o.idCounter=0},{"../utils/Utils":66}],38:[function(t,e,i){function o(t){var e="";"string"==typeof(t=t||{})?(e=t,t={}):"object"==typeof t&&(e=""),this.name=e,this.id=o.idCounter++,this.friction=void 0!==t.friction?t.friction:-1,this.restitution=void 0!==t.restitution?t.restitution:-1}e.exports=o,o.idCounter=0},{}],39:[function(t,e,i){function o(){this.spatial=new n,this.rotational=new n}e.exports=o;var n=t("./Vec3");o.prototype.multiplyElement=function(t){return t.spatial.dot(this.spatial)+t.rotational.dot(this.rotational)},o.prototype.multiplyVectors=function(t,e){return t.dot(this.spatial)+e.dot(this.rotational)}},{"./Vec3":43}],40:[function(t,e,i){function o(t){this.elements=t||[0,0,0,0,0,0,0,0,0]}e.exports=o;var n=t("./Vec3");o.prototype.identity=function(){var t=this.elements;t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=1,t[5]=0,t[6]=0,t[7]=0,t[8]=1},o.prototype.setZero=function(){var t=this.elements;t[0]=0,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=0,t[6]=0,t[7]=0,t[8]=0},o.prototype.setTrace=function(t){var e=this.elements;e[0]=t.x,e[4]=t.y,e[8]=t.z},o.prototype.getTrace=function(t){var t=t||new n,e=this.elements;t.x=e[0],t.y=e[4],t.z=e[8]},o.prototype.vmult=function(t,e){e=e||new n;var i=this.elements,o=t.x,s=t.y,r=t.z;return e.x=i[0]*o+i[1]*s+i[2]*r,e.y=i[3]*o+i[4]*s+i[5]*r,e.z=i[6]*o+i[7]*s+i[8]*r,e},o.prototype.smult=function(t){for(var e=0;e<this.elements.length;e++)this.elements[e]*=t},o.prototype.mmult=function(t,e){for(var i=e||new o,n=0;n<3;n++)for(var s=0;s<3;s++){for(var r=0,a=0;a<3;a++)r+=t.elements[n+3*a]*this.elements[a+3*s];i.elements[n+3*s]=r}return i},o.prototype.scale=function(t,e){e=e||new o;for(var i=this.elements,n=e.elements,s=0;3!==s;s++)n[3*s+0]=t.x*i[3*s+0],n[3*s+1]=t.y*i[3*s+1],n[3*s+2]=t.z*i[3*s+2];return e},o.prototype.solve=function(t,e){e=e||new n;for(var i=[],o=0;o<12;o++)i.push(0);var s;for(o=0;o<3;o++)for(s=0;s<3;s++)i[o+4*s]=this.elements[o+3*s];i[3]=t.x,i[7]=t.y,i[11]=t.z;var r,a,h=3,l=h;do{if(o=l-h,0===i[o+4*o])for(s=o+1;s<l;s++)if(0!==i[o+4*s]){r=4;do{i[(a=4-r)+4*o]+=i[a+4*s]}while(--r);break}if(0!==i[o+4*o])for(s=o+1;s<l;s++){var c=i[o+4*s]/i[o+4*o];r=4;do{i[(a=4-r)+4*s]=a<=o?0:i[a+4*s]-i[a+4*o]*c}while(--r)}}while(--h);if(e.z=i[11]/i[10],e.y=(i[7]-i[6]*e.z)/i[5],e.x=(i[3]-i[2]*e.z-i[1]*e.y)/i[0],isNaN(e.x)||isNaN(e.y)||isNaN(e.z)||e.x===1/0||e.y===1/0||e.z===1/0)throw"Could not solve equation! Got x=["+e.toString()+"], b=["+t.toString()+"], A=["+this.toString()+"]";return e},o.prototype.e=function(t,e,i){if(void 0===i)return this.elements[e+3*t];this.elements[e+3*t]=i},o.prototype.copy=function(t){for(var e=0;e<t.elements.length;e++)this.elements[e]=t.elements[e];return this},o.prototype.toString=function(){for(var t="",e=0;e<9;e++)t+=this.elements[e]+",";return t},o.prototype.reverse=function(t){t=t||new o;for(var e=[],i=0;i<18;i++)e.push(0);var n;for(i=0;i<3;i++)for(n=0;n<3;n++)e[i+6*n]=this.elements[i+3*n];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 s,r,a=3,h=a;do{if(i=h-a,0===e[i+6*i])for(n=i+1;n<h;n++)if(0!==e[i+6*n]){s=6;do{e[(r=6-s)+6*i]+=e[r+6*n]}while(--s);break}if(0!==e[i+6*i])for(n=i+1;n<h;n++){l=e[i+6*n]/e[i+6*i];s=6;do{e[(r=6-s)+6*n]=r<=i?0:e[r+6*n]-e[r+6*i]*l}while(--s)}}while(--a);i=2;do{n=i-1;do{l=e[i+6*n]/e[i+6*i];s=6;do{e[(r=6-s)+6*n]=e[r+6*n]-e[r+6*i]*l}while(--s)}while(n--)}while(--i);i=2;do{var l=1/e[i+6*i];s=6;do{e[(r=6-s)+6*i]=e[r+6*i]*l}while(--s)}while(i--);i=2;do{n=2;do{if(r=e[3+n+6*i],isNaN(r)||r===1/0)throw"Could not reverse! A=["+this.toString()+"]";t.e(i,n,r)}while(n--)}while(i--);return t},o.prototype.setRotationFromQuaternion=function(t){var e=t.x,i=t.y,o=t.z,n=t.w,s=e+e,r=i+i,a=o+o,h=e*s,l=e*r,c=e*a,p=i*r,u=i*a,d=o*a,v=n*s,y=n*r,f=n*a,m=this.elements;return m[0]=1-(p+d),m[1]=l-f,m[2]=c+y,m[3]=l+f,m[4]=1-(h+d),m[5]=u-v,m[6]=c-y,m[7]=u+v,m[8]=1-(h+p),this},o.prototype.transpose=function(t){for(var e=(t=t||new o).elements,i=this.elements,n=0;3!==n;n++)for(var s=0;3!==s;s++)e[3*n+s]=i[3*s+n];return t}},{"./Vec3":43}],41:[function(t,e,i){function o(t,e,i,o){this.x=void 0!==t?t:0,this.y=void 0!==e?e:0,this.z=void 0!==i?i:0,this.w=void 0!==o?o:1}e.exports=o;var n=t("./Vec3");o.prototype.set=function(t,e,i,o){return this.x=t,this.y=e,this.z=i,this.w=o,this},o.prototype.toString=function(){return this.x+","+this.y+","+this.z+","+this.w},o.prototype.toArray=function(){return[this.x,this.y,this.z,this.w]},o.prototype.setFromAxisAngle=function(t,e){var i=Math.sin(.5*e);return this.x=t.x*i,this.y=t.y*i,this.z=t.z*i,this.w=Math.cos(.5*e),this},o.prototype.toAxisAngle=function(t){t=t||new n,this.normalize();var e=2*Math.acos(this.w),i=Math.sqrt(1-this.w*this.w);return i<.001?(t.x=this.x,t.y=this.y,t.z=this.z):(t.x=this.x/i,t.y=this.y/i,t.z=this.z/i),[t,e]};var s=new n,r=new n;o.prototype.setFromVectors=function(t,e){if(t.isAntiparallelTo(e)){var i=s,o=r;t.tangents(i,o),this.setFromAxisAngle(i,Math.PI)}else{var n=t.cross(e);this.x=n.x,this.y=n.y,this.z=n.z,this.w=Math.sqrt(Math.pow(t.norm(),2)*Math.pow(e.norm(),2))+t.dot(e),this.normalize()}return this};new n,new n,new n;o.prototype.mult=function(t,e){e=e||new o;var i=this.x,n=this.y,s=this.z,r=this.w,a=t.x,h=t.y,l=t.z,c=t.w;return e.x=i*c+r*a+n*l-s*h,e.y=n*c+r*h+s*a-i*l,e.z=s*c+r*l+i*h-n*a,e.w=r*c-i*a-n*h-s*l,e},o.prototype.inverse=function(t){var e=this.x,i=this.y,n=this.z,s=this.w;t=t||new o,this.conjugate(t);var r=1/(e*e+i*i+n*n+s*s);return t.x*=r,t.y*=r,t.z*=r,t.w*=r,t},o.prototype.conjugate=function(t){return t=t||new o,t.x=-this.x,t.y=-this.y,t.z=-this.z,t.w=this.w,t},o.prototype.normalize=function(){var t=Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w);return 0===t?(this.x=0,this.y=0,this.z=0,this.w=0):(t=1/t,this.x*=t,this.y*=t,this.z*=t,this.w*=t),this},o.prototype.normalizeFast=function(){var t=(3-(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w))/2;return 0===t?(this.x=0,this.y=0,this.z=0,this.w=0):(this.x*=t,this.y*=t,this.z*=t,this.w*=t),this},o.prototype.vmult=function(t,e){e=e||new n;var i=t.x,o=t.y,s=t.z,r=this.x,a=this.y,h=this.z,l=this.w,c=l*i+a*s-h*o,p=l*o+h*i-r*s,u=l*s+r*o-a*i,d=-r*i-a*o-h*s;return e.x=c*l+d*-r+p*-h-u*-a,e.y=p*l+d*-a+u*-r-c*-h,e.z=u*l+d*-h+c*-a-p*-r,e},o.prototype.copy=function(t){return this.x=t.x,this.y=t.y,this.z=t.z,this.w=t.w,this},o.prototype.toEuler=function(t,e){e=e||"YZX";var i,o,n,s=this.x,r=this.y,a=this.z,h=this.w;switch(e){case"YZX":var l=s*r+a*h;if(l>.499&&(i=2*Math.atan2(s,h),o=Math.PI/2,n=0),l<-.499&&(i=-2*Math.atan2(s,h),o=-Math.PI/2,n=0),isNaN(i)){var c=s*s,p=r*r,u=a*a;i=Math.atan2(2*r*h-2*s*a,1-2*p-2*u),o=Math.asin(2*l),n=Math.atan2(2*s*h-2*r*a,1-2*c-2*u)}break;default:throw new Error("Euler order "+e+" not supported yet.")}t.y=i,t.z=o,t.x=n},o.prototype.setFromEuler=function(t,e,i,o){o=o||"XYZ";var n=Math.cos(t/2),s=Math.cos(e/2),r=Math.cos(i/2),a=Math.sin(t/2),h=Math.sin(e/2),l=Math.sin(i/2);return"XYZ"===o?(this.x=a*s*r+n*h*l,this.y=n*h*r-a*s*l,this.z=n*s*l+a*h*r,this.w=n*s*r-a*h*l):"YXZ"===o?(this.x=a*s*r+n*h*l,this.y=n*h*r-a*s*l,this.z=n*s*l-a*h*r,this.w=n*s*r+a*h*l):"ZXY"===o?(this.x=a*s*r-n*h*l,this.y=n*h*r+a*s*l,this.z=n*s*l+a*h*r,this.w=n*s*r-a*h*l):"ZYX"===o?(this.x=a*s*r-n*h*l,this.y=n*h*r+a*s*l,this.z=n*s*l-a*h*r,this.w=n*s*r+a*h*l):"YZX"===o?(this.x=a*s*r+n*h*l,this.y=n*h*r+a*s*l,this.z=n*s*l-a*h*r,this.w=n*s*r-a*h*l):"XZY"===o&&(this.x=a*s*r-n*h*l,this.y=n*h*r-a*s*l,this.z=n*s*l+a*h*r,this.w=n*s*r+a*h*l),this},o.prototype.clone=function(){return new o(this.x,this.y,this.z,this.w)},o.prototype.slerp=function(t,e,i){i=i||new o;var n,s,r,a,h,l=this.x,c=this.y,p=this.z,u=this.w,d=t.x,v=t.y,y=t.z,f=t.w;return(s=l*d+c*v+p*y+u*f)<0&&(s=-s,d=-d,v=-v,y=-y,f=-f),1-s>1e-6?(n=Math.acos(s),r=Math.sin(n),a=Math.sin((1-e)*n)/r,h=Math.sin(e*n)/r):(a=1-e,h=e),i.x=a*l+h*d,i.y=a*c+h*v,i.z=a*p+h*y,i.w=a*u+h*f,i},o.prototype.integrate=function(t,e,i,n){n=n||new o;var s=t.x*i.x,r=t.y*i.y,a=t.z*i.z,h=this.x,l=this.y,c=this.z,p=this.w,u=.5*e;return n.x+=u*(s*p+r*c-a*l),n.y+=u*(r*p+a*h-s*c),n.z+=u*(a*p+s*l-r*h),n.w+=u*(-s*h-r*l-a*c),n}},{"./Vec3":43}],42:[function(t,e,i){function o(t){t=t||{},this.position=new n,t.position&&this.position.copy(t.position),this.quaternion=new s,t.quaternion&&this.quaternion.copy(t.quaternion)}var n=t("./Vec3"),s=t("./Quaternion");e.exports=o;var r=new s;o.pointToLocalFrame=function(t,e,i,o){o=o||new n;return i.vsub(t,o),e.conjugate(r),r.vmult(o,o),o},o.prototype.pointToLocal=function(t,e){return o.pointToLocalFrame(this.position,this.quaternion,t,e)},o.pointToWorldFrame=function(t,e,i,o){o=o||new n;return e.vmult(i,o),o.vadd(t,o),o},o.prototype.pointToWorld=function(t,e){return o.pointToWorldFrame(this.position,this.quaternion,t,e)},o.prototype.vectorToWorldFrame=function(t,e){e=e||new n;return this.quaternion.vmult(t,e),e},o.vectorToWorldFrame=function(t,e,i){return t.vmult(e,i),i},o.vectorToLocalFrame=function(t,e,i,o){o=o||new n;return e.w*=-1,e.vmult(i,o),e.w*=-1,o}},{"./Quaternion":41,"./Vec3":43}],43:[function(t,e,i){function o(t,e,i){this.x=t||0,this.y=e||0,this.z=i||0}e.exports=o;var n=t("./Mat3");o.ZERO=new o(0,0,0),o.UNIT_X=new o(1,0,0),o.UNIT_Y=new o(0,1,0),o.UNIT_Z=new o(0,0,1),o.prototype.cross=function(t,e){var i=t.x,n=t.y,s=t.z,r=this.x,a=this.y,h=this.z;return e=e||new o,e.x=a*s-h*n,e.y=h*i-r*s,e.z=r*n-a*i,e},o.prototype.set=function(t,e,i){return this.x=t,this.y=e,this.z=i,this},o.prototype.setZero=function(){this.x=this.y=this.z=0},o.prototype.vadd=function(t,e){if(!e)return new o(this.x+t.x,this.y+t.y,this.z+t.z);e.x=t.x+this.x,e.y=t.y+this.y,e.z=t.z+this.z},o.prototype.vsub=function(t,e){if(!e)return new o(this.x-t.x,this.y-t.y,this.z-t.z);e.x=this.x-t.x,e.y=this.y-t.y,e.z=this.z-t.z},o.prototype.crossmat=function(){return new n([0,-this.z,this.y,this.z,0,-this.x,-this.y,this.x,0])},o.prototype.normalize=function(){var t=this.x,e=this.y,i=this.z,o=Math.sqrt(t*t+e*e+i*i);if(o>0){var n=1/o;this.x*=n,this.y*=n,this.z*=n}else this.x=0,this.y=0,this.z=0;return o},o.prototype.unit=function(t){t=t||new o;var e=this.x,i=this.y,n=this.z,s=Math.sqrt(e*e+i*i+n*n);return s>0?(s=1/s,t.x=e*s,t.y=i*s,t.z=n*s):(t.x=1,t.y=0,t.z=0),t},o.prototype.norm=function(){var t=this.x,e=this.y,i=this.z;return Math.sqrt(t*t+e*e+i*i)},o.prototype.length=o.prototype.norm,o.prototype.norm2=function(){return this.dot(this)},o.prototype.lengthSquared=o.prototype.norm2,o.prototype.distanceTo=function(t){var e=this.x,i=this.y,o=this.z,n=t.x,s=t.y,r=t.z;return Math.sqrt((n-e)*(n-e)+(s-i)*(s-i)+(r-o)*(r-o))},o.prototype.distanceSquared=function(t){var e=this.x,i=this.y,o=this.z,n=t.x,s=t.y,r=t.z;return(n-e)*(n-e)+(s-i)*(s-i)+(r-o)*(r-o)},o.prototype.mult=function(t,e){e=e||new o;var i=this.x,n=this.y,s=this.z;return e.x=t*i,e.y=t*n,e.z=t*s,e},o.prototype.vmul=function(t,e){return e=e||new o,e.x=t.x*this.x,e.y=t.y*this.y,e.z=t.z*this.z,e},o.prototype.scale=o.prototype.mult,o.prototype.addScaledVector=function(t,e,i){return i=i||new o,i.x=this.x+t*e.x,i.y=this.y+t*e.y,i.z=this.z+t*e.z,i},o.prototype.dot=function(t){return this.x*t.x+this.y*t.y+this.z*t.z},o.prototype.isZero=function(){return 0===this.x&&0===this.y&&0===this.z},o.prototype.negate=function(t){return t=t||new o,t.x=-this.x,t.y=-this.y,t.z=-this.z,t};var s=new o,r=new o;o.prototype.tangents=function(t,e){var i=this.norm();if(i>0){var o=s,n=1/i;o.set(this.x*n,this.y*n,this.z*n);var a=r;Math.abs(o.x)<.9?(a.set(1,0,0),o.cross(a,t)):(a.set(0,1,0),o.cross(a,t)),o.cross(t,e)}else t.set(1,0,0),e.set(0,1,0)},o.prototype.toString=function(){return this.x+","+this.y+","+this.z},o.prototype.toArray=function(){return[this.x,this.y,this.z]},o.prototype.copy=function(t){return this.x=t.x,this.y=t.y,this.z=t.z,this},o.prototype.lerp=function(t,e,i){var o=this.x,n=this.y,s=this.z;i.x=o+(t.x-o)*e,i.y=n+(t.y-n)*e,i.z=s+(t.z-s)*e},o.prototype.almostEquals=function(t,e){return void 0===e&&(e=1e-6),!(Math.abs(this.x-t.x)>e||Math.abs(this.y-t.y)>e||Math.abs(this.z-t.z)>e)},o.prototype.almostZero=function(t){return void 0===t&&(t=1e-6),!(Math.abs(this.x)>t||Math.abs(this.y)>t||Math.abs(this.z)>t)};var a=new o;o.prototype.isAntiparallelTo=function(t,e){return this.negate(a),a.almostEquals(t,e)},o.prototype.clone=function(){return new o(this.x,this.y,this.z)}},{"./Mat3":40}],44:[function(t,e,i){function o(t){t=t||{},n.apply(this),this.id=o.idCounter++,this.world=null,this.preStep=null,this.postStep=null,this.vlambda=new s,this.collisionFilterGroup="number"==typeof t.collisionFilterGroup?t.collisionFilterGroup:1,this.collisionFilterMask="number"==typeof t.collisionFilterMask?t.collisionFilterMask:1,this.collisionResponse=!0,this.position=new s,this.previousPosition=new s,this.interpolatedPosition=new s,this.initPosition=new s,t.position&&(this.position.copy(t.position),this.previousPosition.copy(t.position),this.interpolatedPosition.copy(t.position),this.initPosition.copy(t.position)),this.velocity=new s,t.velocity&&this.velocity.copy(t.velocity),this.initVelocity=new s,this.force=new s;var e="number"==typeof t.mass?t.mass:0;this.mass=e,this.invMass=e>0?1/e:0,this.material=t.material||null,this.linearDamping="number"==typeof t.linearDamping?t.linearDamping:.01,this.type=e<=0?o.STATIC:o.DYNAMIC,typeof t.type==typeof o.STATIC&&(this.type=t.type),this.allowSleep=void 0===t.allowSleep||t.allowSleep,this.sleepState=0,this.sleepSpeedLimit=void 0!==t.sleepSpeedLimit?t.sleepSpeedLimit:.1,this.sleepTimeLimit=void 0!==t.sleepTimeLimit?t.sleepTimeLimit:1,this.timeLastSleepy=0,this._wakeUpAfterNarrowphase=!1,this.torque=new s,this.quaternion=new a,this.initQuaternion=new a,this.previousQuaternion=new a,this.interpolatedQuaternion=new a,t.quaternion&&(this.quaternion.copy(t.quaternion),this.initQuaternion.copy(t.quaternion),this.previousQuaternion.copy(t.quaternion),this.interpolatedQuaternion.copy(t.quaternion)),this.angularVelocity=new s,t.angularVelocity&&this.angularVelocity.copy(t.angularVelocity),this.initAngularVelocity=new s,this.shapes=[],this.shapeOffsets=[],this.shapeOrientations=[],this.inertia=new s,this.invInertia=new s,this.invInertiaWorld=new r,this.invMassSolve=0,this.invInertiaSolve=new s,this.invInertiaWorldSolve=new r,this.fixedRotation=void 0!==t.fixedRotation&&t.fixedRotation,this.angularDamping=void 0!==t.angularDamping?t.angularDamping:.01,this.linearFactor=new s(1,1,1),t.linearFactor&&this.linearFactor.copy(t.linearFactor),this.angularFactor=new s(1,1,1),t.angularFactor&&this.angularFactor.copy(t.angularFactor),this.aabb=new h,this.aabbNeedsUpdate=!0,this.wlambda=new s,t.shape&&this.addShape(t.shape),this.updateMassProperties()}e.exports=o;var n=t("../utils/EventTarget"),s=(t("../shapes/Shape"),t("../math/Vec3")),r=t("../math/Mat3"),a=t("../math/Quaternion"),h=(t("../material/Material"),t("../collision/AABB")),l=t("../shapes/Box");(o.prototype=new n).constructor=o,o.COLLIDE_EVENT_NAME="collide",o.DYNAMIC=1,o.STATIC=2,o.KINEMATIC=4,o.AWAKE=0,o.SLEEPY=1,o.SLEEPING=2,o.idCounter=0,o.wakeupEvent={type:"wakeup"},o.prototype.wakeUp=function(){var t=this.sleepState;this.sleepState=0,this._wakeUpAfterNarrowphase=!1,t===o.SLEEPING&&this.dispatchEvent(o.wakeupEvent)},o.prototype.sleep=function(){this.sleepState=o.SLEEPING,this.velocity.set(0,0,0),this.angularVelocity.set(0,0,0),this._wakeUpAfterNarrowphase=!1},o.sleepyEvent={type:"sleepy"},o.sleepEvent={type:"sleep"},o.prototype.sleepTick=function(t){if(this.allowSleep){var e=this.sleepState,i=this.velocity.norm2()+this.angularVelocity.norm2(),n=Math.pow(this.sleepSpeedLimit,2);e===o.AWAKE&&i<n?(this.sleepState=o.SLEEPY,this.timeLastSleepy=t,this.dispatchEvent(o.sleepyEvent)):e===o.SLEEPY&&i>n?this.wakeUp():e===o.SLEEPY&&t-this.timeLastSleepy>this.sleepTimeLimit&&(this.sleep(),this.dispatchEvent(o.sleepEvent))}},o.prototype.updateSolveMassProperties=function(){this.sleepState===o.SLEEPING||this.type===o.KINEMATIC?(this.invMassSolve=0,this.invInertiaSolve.setZero(),this.invInertiaWorldSolve.setZero()):(this.invMassSolve=this.invMass,this.invInertiaSolve.copy(this.invInertia),this.invInertiaWorldSolve.copy(this.invInertiaWorld))},o.prototype.pointToLocalFrame=function(t,e){e=e||new s;return t.vsub(this.position,e),this.quaternion.conjugate().vmult(e,e),e},o.prototype.vectorToLocalFrame=function(t,e){e=e||new s;return this.quaternion.conjugate().vmult(t,e),e},o.prototype.pointToWorldFrame=function(t,e){e=e||new s;return this.quaternion.vmult(t,e),e.vadd(this.position,e),e},o.prototype.vectorToWorldFrame=function(t,e){e=e||new s;return this.quaternion.vmult(t,e),e};var c=new s,p=new a;o.prototype.addShape=function(t,e,i){var o=new s,n=new a;return e&&o.copy(e),i&&n.copy(i),this.shapes.push(t),this.shapeOffsets.push(o),this.shapeOrientations.push(n),this.updateMassProperties(),this.updateBoundingRadius(),this.aabbNeedsUpdate=!0,t.body=this,this},o.prototype.updateBoundingRadius=function(){for(var t=this.shapes,e=this.shapeOffsets,i=t.length,o=0,n=0;n!==i;n++){var s=t[n];s.updateBoundingSphereRadius();var r=e[n].norm(),a=s.boundingSphereRadius;r+a>o&&(o=r+a)}this.boundingRadius=o};var u=new h;o.prototype.computeAABB=function(){for(var t=this.shapes,e=this.shapeOffsets,i=this.shapeOrientations,o=t.length,n=c,s=p,r=this.quaternion,a=this.aabb,h=u,l=0;l!==o;l++){var d=t[l];r.vmult(e[l],n),n.vadd(this.position,n),i[l].mult(r,s),d.calculateWorldAABB(n,s,h.lowerBound,h.upperBound),0===l?a.copy(h):a.extend(h)}this.aabbNeedsUpdate=!1};var d=new r,v=new r;new r;o.prototype.updateInertiaWorld=function(t){var e=this.invInertia;if(e.x!==e.y||e.y!==e.z||t){var i=d,o=v;i.setRotationFromQuaternion(this.quaternion),i.transpose(o),i.scale(e,i),i.mmult(o,this.invInertiaWorld)}else;};new s;var y=new s;o.prototype.applyForce=function(t,e){if(this.type===o.DYNAMIC){var i=y;e.cross(t,i),this.force.vadd(t,this.force),this.torque.vadd(i,this.torque)}};var f=new s,m=new s;o.prototype.applyLocalForce=function(t,e){if(this.type===o.DYNAMIC){var i=f,n=m;this.vectorToWorldFrame(t,i),this.vectorToWorldFrame(e,n),this.applyForce(i,n)}};new s;var w=new s,g=new s;o.prototype.applyImpulse=function(t,e){if(this.type===o.DYNAMIC){var i=e,n=w;n.copy(t),n.mult(this.invMass,n),this.velocity.vadd(n,this.velocity);var s=g;i.cross(t,s),this.invInertiaWorld.vmult(s,s),this.angularVelocity.vadd(s,this.angularVelocity)}};var x=new s,b=new s;o.prototype.applyLocalImpulse=function(t,e){if(this.type===o.DYNAMIC){var i=x,n=b;this.vectorToWorldFrame(t,i),this.vectorToWorldFrame(e,n),this.applyImpulse(i,n)}};var E=new s;o.prototype.updateMassProperties=function(){var t=E;this.invMass=this.mass>0?1/this.mass:0;var e=this.inertia,i=this.fixedRotation;this.computeAABB(),t.set((this.aabb.upperBound.x-this.aabb.lowerBound.x)/2,(this.aabb.upperBound.y-this.aabb.lowerBound.y)/2,(this.aabb.upperBound.z-this.aabb.lowerBound.z)/2),l.calculateInertia(t,this.mass,e),this.invInertia.set(e.x>0&&!i?1/e.x:0,e.y>0&&!i?1/e.y:0,e.z>0&&!i?1/e.z:0),this.updateInertiaWorld(!0)},o.prototype.getVelocityAtWorldPoint=function(t,e){var i=new s;return t.vsub(this.position,i),this.angularVelocity.cross(i,e),this.velocity.vadd(e,e),e};new s,new s,new a,new a;o.prototype.integrate=function(t,e,i){if(this.previousPosition.copy(this.position),this.previousQuaternion.copy(this.quaternion),(this.type===o.DYNAMIC||this.type===o.KINEMATIC)&&this.sleepState!==o.SLEEPING){var n=this.velocity,s=this.angularVelocity,r=this.position,a=this.force,h=this.torque,l=this.quaternion,c=this.invMass,p=this.invInertiaWorld,u=this.linearFactor,d=c*t;n.x+=a.x*d*u.x,n.y+=a.y*d*u.y,n.z+=a.z*d*u.z;var v=p.elements,y=this.angularFactor,f=h.x*y.x,m=h.y*y.y,w=h.z*y.z;s.x+=t*(v[0]*f+v[1]*m+v[2]*w),s.y+=t*(v[3]*f+v[4]*m+v[5]*w),s.z+=t*(v[6]*f+v[7]*m+v[8]*w),r.x+=n.x*t,r.y+=n.y*t,r.z+=n.z*t,l.integrate(this.angularVelocity,t,this.angularFactor,l),e&&(i?l.normalizeFast():l.normalize()),this.aabbNeedsUpdate=!0,this.updateInertiaWorld()}}},{"../collision/AABB":15,"../material/Material":38,"../math/Mat3":40,"../math/Quaternion":41,"../math/Vec3":43,"../shapes/Box":50,"../shapes/Shape":56,"../utils/EventTarget":62}],45:[function(t,e,i){function o(t){this.chassisBody=t.chassisBody,this.wheelInfos=[],this.sliding=!1,this.world=null,this.indexRightAxis=void 0!==t.indexRightAxis?t.indexRightAxis:1,this.indexForwardAxis=void 0!==t.indexForwardAxis?t.indexForwardAxis:0,this.indexUpAxis=void 0!==t.indexUpAxis?t.indexUpAxis:2}function n(t,e,i){var o=b,n=E,s=B,r=A;return e.vsub(t.position,o),o.cross(i,n),t.invInertiaWorld.vmult(n,r),r.cross(o,s),t.invMass+i.dot(s)}t("./Body");var s=t("../math/Vec3"),r=t("../math/Quaternion"),a=(t("../collision/RaycastResult"),t("../collision/Ray")),h=t("../objects/WheelInfo");e.exports=o;new s,new s,new s;var l=new s,c=new s,p=new s;new a;o.prototype.addWheel=function(t){var e=new h(t=t||{}),i=this.wheelInfos.length;return this.wheelInfos.push(e),i},o.prototype.setSteeringValue=function(t,e){this.wheelInfos[e].steering=t};new s;o.prototype.applyEngineForce=function(t,e){this.wheelInfos[e].engineForce=t},o.prototype.setBrake=function(t,e){this.wheelInfos[e].brake=t},o.prototype.addToWorld=function(t){this.constraints;t.addBody(this.chassisBody);var e=this;this.preStepCallback=function(){e.updateVehicle(t.dt)},t.addEventListener("preStep",this.preStepCallback),this.world=t},o.prototype.getVehicleAxisWorld=function(t,e){e.set(0===t?1:0,1===t?1:0,2===t?1:0),this.chassisBody.vectorToWorldFrame(e,e)},o.prototype.updateVehicle=function(t){for(var e=this.wheelInfos,i=e.length,o=this.chassisBody,n=0;n<i;n++)this.updateWheelTransform(n);this.currentVehicleSpeedKmHour=3.6*o.velocity.norm();var r=new s;this.getVehicleAxisWorld(this.indexForwardAxis,r),r.dot(o.velocity)<0&&(this.currentVehicleSpeedKmHour*=-1);for(n=0;n<i;n++)this.castRay(e[n]);this.updateSuspension(t);for(var a=new s,h=new s,n=0;n<i;n++){var l=(d=e[n]).suspensionForce;l>d.maxSuspensionForce&&(l=d.maxSuspensionForce),d.raycastResult.hitNormalWorld.scale(l*t,a),d.raycastResult.hitPointWorld.vsub(o.position,h),o.applyImpulse(a,h)}this.updateFriction(t);var c=new s,p=new s,u=new s;for(n=0;n<i;n++){var d=e[n];o.getVelocityAtWorldPoint(d.chassisConnectionPointWorld,u);var v=1;switch(this.indexUpAxis){case 1:v=-1}if(d.isInContact){this.getVehicleAxisWorld(this.indexForwardAxis,p);var y=p.dot(d.raycastResult.hitNormalWorld);d.raycastResult.hitNormalWorld.scale(y,c),p.vsub(c,p);var f=p.dot(u);d.deltaRotation=v*f*t/d.radius}!d.sliding&&d.isInContact||0===d.engineForce||!d.useCustomSlidingRotationalSpeed||(d.deltaRotation=(d.engineForce>0?1:-1)*d.customSlidingRotationalSpeed*t),Math.abs(d.brake)>Math.abs(d.engineForce)&&(d.deltaRotation=0),d.rotation+=d.deltaRotation,d.deltaRotation*=.99}},o.prototype.updateSuspension=function(t){for(var e=this.chassisBody.mass,i=this.wheelInfos,o=i.length,n=0;n<o;n++){var s=i[n];if(s.isInContact){var r,a=s.suspensionRestLength-s.suspensionLength;r=s.suspensionStiffness*a*s.clippedInvContactDotSuspension;var h=s.suspensionRelativeVelocity;r-=(h<0?s.dampingCompression:s.dampingRelaxation)*h,s.suspensionForce=r*e,s.suspensionForce<0&&(s.suspensionForce=0)}else s.suspensionForce=0}},o.prototype.removeFromWorld=function(t){this.constraints;t.remove(this.chassisBody),t.removeEventListener("preStep",this.preStepCallback),this.world=null};var u=new s,d=new s;o.prototype.castRay=function(t){var e=u,i=d;this.updateWheelTransformWorld(t);var o=this.chassisBody,n=-1,r=t.suspensionRestLength+t.radius;t.directionWorld.scale(r,e);var a=t.chassisConnectionPointWorld;a.vadd(e,i);var h=t.raycastResult;h.reset();var l=o.collisionResponse;o.collisionResponse=!1,this.world.rayTest(a,i,h),o.collisionResponse=l;var c=h.body;if(t.raycastResult.groundObject=0,c){n=h.distance,t.raycastResult.hitNormalWorld=h.hitNormalWorld,t.isInContact=!0;var p=h.distance;t.suspensionLength=p-t.radius;var v=t.suspensionRestLength-t.maxSuspensionTravel,y=t.suspensionRestLength+t.maxSuspensionTravel;t.suspensionLength<v&&(t.suspensionLength=v),t.suspensionLength>y&&(t.suspensionLength=y,t.raycastResult.reset());var f=t.raycastResult.hitNormalWorld.dot(t.directionWorld),m=new s;o.getVelocityAtWorldPoint(t.raycastResult.hitPointWorld,m);var w=t.raycastResult.hitNormalWorld.dot(m);if(f>=-.1)t.suspensionRelativeVelocity=0,t.clippedInvContactDotSuspension=10;else{var g=-1/f;t.suspensionRelativeVelocity=w*g,t.clippedInvContactDotSuspension=g}}else t.suspensionLength=t.suspensionRestLength+0*t.maxSuspensionTravel,t.suspensionRelativeVelocity=0,t.directionWorld.scale(-1,t.raycastResult.hitNormalWorld),t.clippedInvContactDotSuspension=1;return n},o.prototype.updateWheelTransformWorld=function(t){t.isInContact=!1;var e=this.chassisBody;e.pointToWorldFrame(t.chassisConnectionPointLocal,t.chassisConnectionPointWorld),e.vectorToWorldFrame(t.directionLocal,t.directionWorld),e.vectorToWorldFrame(t.axleLocal,t.axleWorld)},o.prototype.updateWheelTransform=function(t){var e=l,i=c,o=p,n=this.wheelInfos[t];this.updateWheelTransformWorld(n),n.directionLocal.scale(-1,e),i.copy(n.axleLocal),e.cross(i,o),o.normalize(),i.normalize();var s=n.steering,a=new r;a.setFromAxisAngle(e,s);var h=new r;h.setFromAxisAngle(i,n.rotation);var u=n.worldTransform.quaternion;this.chassisBody.quaternion.mult(a,u),u.mult(h,u),u.normalize();var d=n.worldTransform.position;d.copy(n.directionWorld),d.scale(n.suspensionLength,d),d.vadd(n.chassisConnectionPointWorld,d)};var v=[new s(1,0,0),new s(0,1,0),new s(0,0,1)];o.prototype.getWheelTransformWorld=function(t){return this.wheelInfos[t].worldTransform};var y=new s,f=[],m=[];o.prototype.updateFriction=function(t){for(var e=y,i=this.wheelInfos,o=i.length,r=this.chassisBody,a=m,h=f,l=0;l<o;l++){(d=(V=i[l]).raycastResult.body)&&0,V.sideImpulse=0,V.forwardImpulse=0,a[l]||(a[l]=new s),h[l]||(h[l]=new s)}for(l=0;l<o;l++){if(d=(V=i[l]).raycastResult.body){var c=h[l];this.getWheelTransformWorld(l).vectorToWorldFrame(v[this.indexRightAxis],c);var p=V.raycastResult.hitNormalWorld,u=c.dot(p);p.scale(u,e),c.vsub(e,c),c.normalize(),p.cross(c,a[l]),a[l].normalize(),V.sideImpulse=function(t,e,i,o,n,s){if(n.norm2()>1.1)return 0;var r=S,a=R,h=z;return t.getVelocityAtWorldPoint(e,r),i.getVelocityAtWorldPoint(o,a),r.vsub(a,h),-.2*n.dot(h)*(1/(t.invMass+i.invMass))}(r,V.raycastResult.hitPointWorld,d,V.raycastResult.hitPointWorld,c),V.sideImpulse*=1}}this.sliding=!1;for(l=0;l<o;l++){var d=(V=i[l]).raycastResult.body,b=0;if(V.slipInfo=1,d){var E=V.brake?V.brake:0;b=function(t,e,i,o,s){var r=0,a=i,h=w,l=g,c=x;return t.getVelocityAtWorldPoint(a,h),e.getVelocityAtWorldPoint(a,l),h.vsub(l,c),r=-o.dot(c)*(1/(n(t,i,o)+n(e,i,o))),s<r&&(r=s),r<-s&&(r=-s),r}(r,d,V.raycastResult.hitPointWorld,a[l],E);q=E/(b+=V.engineForce*t);V.slipInfo*=q}if(V.forwardImpulse=0,V.skidInfo=1,d){V.skidInfo=1;var B=V.suspensionForce*t*V.frictionSlip,A=B*B;V.forwardImpulse=b;var M=.5*V.forwardImpulse,C=1*V.sideImpulse,T=M*M+C*C;if(V.sliding=!1,T>A){this.sliding=!0,V.sliding=!0;var q=B/Math.sqrt(T);V.skidInfo*=q}}}if(this.sliding)for(l=0;l<o;l++){0!==(V=i[l]).sideImpulse&&V.skidInfo<1&&(V.forwardImpulse*=V.skidInfo,V.sideImpulse*=V.skidInfo)}for(l=0;l<o;l++){var V=i[l],F=new s;if(V.raycastResult.hitPointWorld.vsub(r.position,F),0!==V.forwardImpulse){var P=new s;a[l].scale(V.forwardImpulse,P),r.applyImpulse(P,F)}if(0!==V.sideImpulse){var d=V.raycastResult.body,N=new s;V.raycastResult.hitPointWorld.vsub(d.position,N);var I=new s;h[l].scale(V.sideImpulse,I),r.vectorToLocalFrame(F,F),F["xyz"[this.indexUpAxis]]*=V.rollInfluence,r.vectorToWorldFrame(F,F),r.applyImpulse(I,F),I.scale(-1,I),d.applyImpulse(I,N)}}};var w=new s,g=new s,x=new s,b=new s,E=new s,B=new s,A=new s,S=new s,R=new s,z=new s},{"../collision/Ray":22,"../collision/RaycastResult":23,"../math/Quaternion":41,"../math/Vec3":43,"../objects/WheelInfo":49,"./Body":44}],46:[function(t,e,i){function o(t){if(this.wheelBodies=[],this.coordinateSystem=void 0===t.coordinateSystem?new a(1,2,3):t.coordinateSystem.clone(),this.chassisBody=t.chassisBody,!this.chassisBody){var e=new r(new a(5,2,.5));this.chassisBody=new n(1,e)}this.constraints=[],this.wheelAxes=[],this.wheelForces=[]}var n=t("./Body"),s=t("../shapes/Sphere"),r=t("../shapes/Box"),a=t("../math/Vec3"),h=t("../constraints/HingeConstraint");e.exports=o,o.prototype.addWheel=function(t){var e=(t=t||{}).body;e||(e=new n(1,new s(1.2))),this.wheelBodies.push(e),this.wheelForces.push(0);new a;var i=void 0!==t.position?t.position.clone():new a,o=new a;this.chassisBody.pointToWorldFrame(i,o),e.position.set(o.x,o.y,o.z);var r=void 0!==t.axis?t.axis.clone():new a(0,1,0);this.wheelAxes.push(r);var l=new h(this.chassisBody,e,{pivotA:i,axisA:r,pivotB:a.ZERO,axisB:r,collideConnected:!1});return this.constraints.push(l),this.wheelBodies.length-1},o.prototype.setSteeringValue=function(t,e){var i=this.wheelAxes[e],o=Math.cos(t),n=Math.sin(t),s=i.x,r=i.y;this.constraints[e].axisA.set(o*s-n*r,n*s+o*r,0)},o.prototype.setMotorSpeed=function(t,e){var i=this.constraints[e];i.enableMotor(),i.motorTargetVelocity=t},o.prototype.disableMotor=function(t){this.constraints[t].disableMotor()};var l=new a;o.prototype.setWheelForce=function(t,e){this.wheelForces[e]=t},o.prototype.applyWheelForce=function(t,e){var i=this.wheelAxes[e],o=this.wheelBodies[e],n=o.torque;i.scale(t,l),o.vectorToWorldFrame(l,l),n.vadd(l,n)},o.prototype.addToWorld=function(t){for(var e=this.constraints,i=this.wheelBodies.concat([this.chassisBody]),o=0;o<i.length;o++)t.addBody(i[o]);for(o=0;o<e.length;o++)t.addConstraint(e[o]);t.addEventListener("preStep",this._update.bind(this))},o.prototype._update=function(){for(var t=this.wheelForces,e=0;e<t.length;e++)this.applyWheelForce(t[e],e)},o.prototype.removeFromWorld=function(t){for(var e=this.constraints,i=this.wheelBodies.concat([this.chassisBody]),o=0;o<i.length;o++)t.remove(i[o]);for(o=0;o<e.length;o++)t.removeConstraint(e[o])};var c=new a;o.prototype.getWheelSpeed=function(t){var e=this.wheelAxes[t],i=this.wheelBodies[t].angularVelocity;return this.chassisBody.vectorToWorldFrame(e,c),i.dot(c)}},{"../constraints/HingeConstraint":28,"../math/Vec3":43,"../shapes/Box":50,"../shapes/Sphere":57,"./Body":44}],47:[function(t,e,i){function o(){this.particles=[],this.density=1,this.smoothingRadius=1,this.speedOfSound=1,this.viscosity=.01,this.eps=1e-6,this.pressures=[],this.densities=[],this.neighbors=[]}e.exports=o;t("../shapes/Shape");var n=t("../math/Vec3");t("../math/Quaternion"),t("../shapes/Particle"),t("../objects/Body"),t("../material/Material");o.prototype.add=function(t){this.particles.push(t),this.neighbors.length<this.particles.length&&this.neighbors.push([])},o.prototype.remove=function(t){var e=this.particles.indexOf(t);-1!==e&&(this.particles.splice(e,1),this.neighbors.length>this.particles.length&&this.neighbors.pop())};var s=new n;o.prototype.getNeighbors=function(t,e){for(var i=this.particles.length,o=t.id,n=this.smoothingRadius*this.smoothingRadius,r=s,a=0;a!==i;a++){var h=this.particles[a];h.position.vsub(t.position,r),o!==h.id&&r.norm2()<n&&e.push(h)}};var r=new n,a=new n,h=new n,l=new n,c=new n,p=new n;o.prototype.update=function(){for(var t=this.particles.length,e=r,i=this.speedOfSound,o=this.eps,n=0;n!==t;n++){var s=this.particles[n];(S=this.neighbors[n]).length=0,this.getNeighbors(s,S),S.push(this.particles[n]);for(var u=S.length,d=0,v=0;v!==u;v++){s.position.vsub(S[v].position,e);var y=e.norm(),f=this.w(y);d+=S[v].mass*f}this.densities[n]=d,this.pressures[n]=i*i*(this.densities[n]-this.density)}for(var m=a,w=h,g=l,x=c,b=p,n=0;n!==t;n++){var E=this.particles[n];m.set(0,0,0),w.set(0,0,0);for(var B,A,S=this.neighbors[n],u=S.length,v=0;v!==u;v++){var R=S[v];E.position.vsub(R.position,x);var z=x.norm();B=-R.mass*(this.pressures[n]/(this.densities[n]*this.densities[n]+o)+this.pressures[v]/(this.densities[v]*this.densities[v]+o)),this.gradw(x,g),g.mult(B,g),m.vadd(g,m),R.velocity.vsub(E.velocity,b),b.mult(1/(1e-4+this.densities[n]*this.densities[v])*this.viscosity*R.mass,b),A=this.nablaw(z),b.mult(A,b),w.vadd(b,w)}w.mult(E.mass,w),m.mult(E.mass,m),E.force.vadd(w,E.force),E.force.vadd(m,E.force)}},o.prototype.w=function(t){var e=this.smoothingRadius;return 315/(64*Math.PI*Math.pow(e,9))*Math.pow(e*e-t*t,3)},o.prototype.gradw=function(t,e){var i=t.norm(),o=this.smoothingRadius;t.mult(945/(32*Math.PI*Math.pow(o,9))*Math.pow(o*o-i*i,2),e)},o.prototype.nablaw=function(t){var e=this.smoothingRadius;return 945/(32*Math.PI*Math.pow(e,9))*(e*e-t*t)*(7*t*t-3*e*e)}},{"../material/Material":38,"../math/Quaternion":41,"../math/Vec3":43,"../objects/Body":44,"../shapes/Particle":54,"../shapes/Shape":56}],48:[function(t,e,i){function o(t,e,i){i=i||{},this.restLength="number"==typeof i.restLength?i.restLength:1,this.stiffness=i.stiffness||100,this.damping=i.damping||1,this.bodyA=t,this.bodyB=e,this.localAnchorA=new n,this.localAnchorB=new n,i.localAnchorA&&this.localAnchorA.copy(i.localAnchorA),i.localAnchorB&&this.localAnchorB.copy(i.localAnchorB),i.worldAnchorA&&this.setWorldAnchorA(i.worldAnchorA),i.worldAnchorB&&this.setWorldAnchorB(i.worldAnchorB)}var n=t("../math/Vec3");e.exports=o,o.prototype.setWorldAnchorA=function(t){this.bodyA.pointToLocalFrame(t,this.localAnchorA)},o.prototype.setWorldAnchorB=function(t){this.bodyB.pointToLocalFrame(t,this.localAnchorB)},o.prototype.getWorldAnchorA=function(t){this.bodyA.pointToWorldFrame(this.localAnchorA,t)},o.prototype.getWorldAnchorB=function(t){this.bodyB.pointToWorldFrame(this.localAnchorB,t)};var s=new n,r=new n,a=new n,h=new n,l=new n,c=new n,p=new n,u=new n,d=new n,v=new n,y=new n;o.prototype.applyForce=function(){var t=this.stiffness,e=this.damping,i=this.restLength,o=this.bodyA,n=this.bodyB,f=s,m=r,w=a,g=h,x=y,b=l,E=c,B=p,A=u,S=d,R=v;this.getWorldAnchorA(b),this.getWorldAnchorB(E),b.vsub(o.position,B),E.vsub(n.position,A),E.vsub(b,f);var z=f.norm();m.copy(f),m.normalize(),n.velocity.vsub(o.velocity,w),n.angularVelocity.cross(A,x),w.vadd(x,w),o.angularVelocity.cross(B,x),w.vsub(x,w),m.mult(-t*(z-i)-e*w.dot(m),g),o.force.vsub(g,o.force),n.force.vadd(g,n.force),B.cross(g,S),A.cross(g,R),o.torque.vsub(S,o.torque),n.torque.vadd(R,n.torque)}},{"../math/Vec3":43}],49:[function(t,e,i){function o(t){t=a.defaults(t,{chassisConnectionPointLocal:new n,chassisConnectionPointWorld:new n,directionLocal:new n,directionWorld:new n,axleLocal:new n,axleWorld:new n,suspensionRestLength:1,suspensionMaxLength:2,radius:1,suspensionStiffness:100,dampingCompression:10,dampingRelaxation:10,frictionSlip:1e4,steering:0,rotation:0,deltaRotation:0,rollInfluence:.01,maxSuspensionForce:Number.MAX_VALUE,isFrontWheel:!0,clippedInvContactDotSuspension:1,suspensionRelativeVelocity:0,suspensionForce:0,skidInfo:0,suspensionLength:0,maxSuspensionTravel:1,useCustomSlidingRotationalSpeed:!1,customSlidingRotationalSpeed:-.1}),this.maxSuspensionTravel=t.maxSuspensionTravel,this.customSlidingRotationalSpeed=t.customSlidingRotationalSpeed,this.useCustomSlidingRotationalSpeed=t.useCustomSlidingRotationalSpeed,this.sliding=!1,this.chassisConnectionPointLocal=t.chassisConnectionPointLocal.clone(),this.chassisConnectionPointWorld=t.chassisConnectionPointWorld.clone(),this.directionLocal=t.directionLocal.clone(),this.directionWorld=t.directionWorld.clone(),this.axleLocal=t.axleLocal.clone(),this.axleWorld=t.axleWorld.clone(),this.suspensionRestLength=t.suspensionRestLength,this.suspensionMaxLength=t.suspensionMaxLength,this.radius=t.radius,this.suspensionStiffness=t.suspensionStiffness,this.dampingCompression=t.dampingCompression,this.dampingRelaxation=t.dampingRelaxation,this.frictionSlip=t.frictionSlip,this.steering=0,this.rotation=0,this.deltaRotation=0,this.rollInfluence=t.rollInfluence,this.maxSuspensionForce=t.maxSuspensionForce,this.engineForce=0,this.brake=0,this.isFrontWheel=t.isFrontWheel,this.clippedInvContactDotSuspension=1,this.suspensionRelativeVelocity=0,this.suspensionForce=0,this.skidInfo=0,this.suspensionLength=0,this.sideImpulse=0,this.forwardImpulse=0,this.raycastResult=new r,this.worldTransform=new s,this.isInContact=!1}var n=t("../math/Vec3"),s=t("../math/Transform"),r=t("../collision/RaycastResult"),a=t("../utils/Utils");e.exports=o;var h=new n,l=new n,h=new n;o.prototype.updateWheel=function(t){var e=this.raycastResult;if(this.isInContact){var i=e.hitNormalWorld.dot(e.directionWorld);e.hitPointWorld.vsub(t.position,l),t.getVelocityAtWorldPoint(l,h);var o=e.hitNormalWorld.dot(h);if(i>=-.1)this.suspensionRelativeVelocity=0,this.clippedInvContactDotSuspension=10;else{var n=-1/i;this.suspensionRelativeVelocity=o*n,this.clippedInvContactDotSuspension=n}}else e.suspensionLength=this.suspensionRestLength,this.suspensionRelativeVelocity=0,e.directionWorld.scale(-1,e.hitNormalWorld),this.clippedInvContactDotSuspension=1}},{"../collision/RaycastResult":23,"../math/Transform":42,"../math/Vec3":43,"../utils/Utils":66}],50:[function(t,e,i){function o(t){n.call(this),this.type=n.types.BOX,this.halfExtents=t,this.convexPolyhedronRepresentation=null,this.updateConvexPolyhedronRepresentation(),this.updateBoundingSphereRadius()}e.exports=o;var n=t("./Shape"),s=t("../math/Vec3"),r=t("./ConvexPolyhedron");(o.prototype=new n).constructor=o,o.prototype.updateConvexPolyhedronRepresentation=function(){var t=this.halfExtents.x,e=this.halfExtents.y,i=this.halfExtents.z,o=s,n=[new o(-t,-e,-i),new o(t,-e,-i),new o(t,e,-i),new o(-t,e,-i),new o(-t,-e,i),new o(t,-e,i),new o(t,e,i),new o(-t,e,i)],a=(new o(0,0,1),new o(0,1,0),new o(1,0,0),new r(n,[[3,2,1,0],[4,5,6,7],[5,4,0,1],[2,3,7,6],[0,4,7,3],[1,2,6,5]]));this.convexPolyhedronRepresentation=a,a.material=this.material},o.prototype.calculateLocalInertia=function(t,e){return e=e||new s,o.calculateInertia(this.halfExtents,t,e),e},o.calculateInertia=function(t,e,i){var o=t;i.x=1/12*e*(2*o.y*2*o.y+2*o.z*2*o.z),i.y=1/12*e*(2*o.x*2*o.x+2*o.z*2*o.z),i.z=1/12*e*(2*o.y*2*o.y+2*o.x*2*o.x)},o.prototype.getSideNormals=function(t,e){var i=t,o=this.halfExtents;if(i[0].set(o.x,0,0),i[1].set(0,o.y,0),i[2].set(0,0,o.z),i[3].set(-o.x,0,0),i[4].set(0,-o.y,0),i[5].set(0,0,-o.z),void 0!==e)for(var n=0;n!==i.length;n++)e.vmult(i[n],i[n]);return i},o.prototype.volume=function(){return 8*this.halfExtents.x*this.halfExtents.y*this.halfExtents.z},o.prototype.updateBoundingSphereRadius=function(){this.boundingSphereRadius=this.halfExtents.norm()};var a=new s;new s;o.prototype.forEachWorldCorner=function(t,e,i){for(var o=this.halfExtents,n=[[o.x,o.y,o.z],[-o.x,o.y,o.z],[-o.x,-o.y,o.z],[-o.x,-o.y,-o.z],[o.x,-o.y,-o.z],[o.x,o.y,-o.z],[-o.x,o.y,-o.z],[o.x,-o.y,o.z]],s=0;s<n.length;s++)a.set(n[s][0],n[s][1],n[s][2]),e.vmult(a,a),t.vadd(a,a),i(a.x,a.y,a.z)};var h=[new s,new s,new s,new s,new s,new s,new s,new s];o.prototype.calculateWorldAABB=function(t,e,i,o){var n=this.halfExtents;h[0].set(n.x,n.y,n.z),h[1].set(-n.x,n.y,n.z),h[2].set(-n.x,-n.y,n.z),h[3].set(-n.x,-n.y,-n.z),h[4].set(n.x,-n.y,-n.z),h[5].set(n.x,n.y,-n.z),h[6].set(-n.x,n.y,-n.z),h[7].set(n.x,-n.y,n.z);r=h[0];e.vmult(r,r),t.vadd(r,r),o.copy(r),i.copy(r);for(var s=1;s<8;s++){var r=h[s];e.vmult(r,r),t.vadd(r,r);var a=r.x,l=r.y,c=r.z;a>o.x&&(o.x=a),l>o.y&&(o.y=l),c>o.z&&(o.z=c),a<i.x&&(i.x=a),l<i.y&&(i.y=l),c<i.z&&(i.z=c)}}},{"../math/Vec3":43,"./ConvexPolyhedron":51,"./Shape":56}],51:[function(t,e,i){function o(t,e,i){n.call(this),this.type=n.types.CONVEXPOLYHEDRON,this.vertices=t||[],this.worldVertices=[],this.worldVerticesNeedsUpdate=!0,this.faces=e||[],this.faceNormals=[],this.computeNormals(),this.worldFaceNormalsNeedsUpdate=!0,this.worldFaceNormals=[],this.uniqueEdges=[],this.uniqueAxes=i?i.slice():null,this.computeEdges(),this.updateBoundingSphereRadius()}e.exports=o;var n=t("./Shape"),s=t("../math/Vec3"),r=(t("../math/Quaternion"),t("../math/Transform"));(o.prototype=new n).constructor=o;var a=new s;o.prototype.computeEdges=function(){var t=this.faces,e=this.vertices,i=(e.length,this.uniqueEdges);i.length=0;for(var o=a,n=0;n!==t.length;n++)for(var s=t[n],r=s.length,h=0;h!==r;h++){var l=(h+1)%r;e[s[h]].vsub(e[s[l]],o),o.normalize();for(var c=!1,p=0;p!==i.length;p++)if(i[p].almostEquals(o)||i[p].almostEquals(o)){c=!0;break}c||i.push(o.clone())}},o.prototype.computeNormals=function(){this.faceNormals.length=this.faces.length;for(var t=0;t<this.faces.length;t++){for(o=0;o<this.faces[t].length;o++)if(!this.vertices[this.faces[t][o]])throw new Error("Vertex "+this.faces[t][o]+" not found!");var e=this.faceNormals[t]||new s;this.getFaceNormal(t,e),e.negate(e),this.faceNormals[t]=e;var i=this.vertices[this.faces[t][0]];if(e.dot(i)<0){console.error(".faceNormals["+t+"] = Vec3("+e.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 o=0;o<this.faces[t].length;o++)console.warn(".vertices["+this.faces[t][o]+"] = Vec3("+this.vertices[this.faces[t][o]].toString()+")")}}};var h=new s,l=new s;o.computeNormal=function(t,e,i,o){e.vsub(t,l),i.vsub(e,h),h.cross(l,o),o.isZero()||o.normalize()},o.prototype.getFaceNormal=function(t,e){var i=this.faces[t],n=this.vertices[i[0]],s=this.vertices[i[1]],r=this.vertices[i[2]];return o.computeNormal(n,s,r,e)};var c=new s;o.prototype.clipAgainstHull=function(t,e,i,o,n,r,a,h,l){for(var p=c,u=-1,d=-Number.MAX_VALUE,v=0;v<i.faces.length;v++){p.copy(i.faceNormals[v]),n.vmult(p,p);var y=p.dot(r);y>d&&(d=y,u=v)}for(var f=[],m=i.faces[u],w=m.length,g=0;g<w;g++){var x=i.vertices[m[g]],b=new s;b.copy(x),n.vmult(b,b),o.vadd(b,b),f.push(b)}u>=0&&this.clipFaceAgainstHull(r,t,e,f,a,h,l)};var p=new s,u=new s,d=new s,v=new s,y=new s,f=new s;o.prototype.findSeparatingAxis=function(t,e,i,o,n,s,r,a){var h=p,l=u,c=d,m=v,w=y,g=f,x=Number.MAX_VALUE,b=this;if(b.uniqueAxes)for(B=0;B!==b.uniqueAxes.length;B++){i.vmult(b.uniqueAxes[B],h);if(!1===(R=b.testSepAxis(h,t,e,i,o,n)))return!1;R<x&&(x=R,s.copy(h))}else for(var E=r?r.length:b.faces.length,B=0;B<E;B++){S=r?r[B]:B;h.copy(b.faceNormals[S]),i.vmult(h,h);if(!1===(R=b.testSepAxis(h,t,e,i,o,n)))return!1;R<x&&(x=R,s.copy(h))}if(t.uniqueAxes)for(B=0;B!==t.uniqueAxes.length;B++){n.vmult(t.uniqueAxes[B],l),0;R=b.testSepAxis(l,t,e,i,o,n);if(!1===R)return!1;R<x&&(x=R,s.copy(l))}else for(var A=a?a.length:t.faces.length,B=0;B<A;B++){var S=a?a[B]:B;l.copy(t.faceNormals[S]),n.vmult(l,l),0;var R;if(!1===(R=b.testSepAxis(l,t,e,i,o,n)))return!1;R<x&&(x=R,s.copy(l))}for(var z=0;z!==b.uniqueEdges.length;z++){i.vmult(b.uniqueEdges[z],m);for(var M=0;M!==t.uniqueEdges.length;M++)if(n.vmult(t.uniqueEdges[M],w),m.cross(w,g),!g.almostZero()){g.normalize();var C=b.testSepAxis(g,t,e,i,o,n);if(!1===C)return!1;C<x&&(x=C,s.copy(g))}}return o.vsub(e,c),c.dot(s)>0&&s.negate(s),!0};var m=[],w=[];o.prototype.testSepAxis=function(t,e,i,n,s,r){o.project(this,t,i,n,m),o.project(e,t,s,r,w);var a=m[0],h=m[1],l=w[0],c=w[1];if(a<c||l<h)return!1;var p=a-c,u=l-h;return p<u?p:u};var g=new s,x=new s;o.prototype.calculateLocalInertia=function(t,e){this.computeLocalAABB(g,x);var i=x.x-g.x,o=x.y-g.y,n=x.z-g.z;e.x=1/12*t*(2*o*2*o+2*n*2*n),e.y=1/12*t*(2*i*2*i+2*n*2*n),e.z=1/12*t*(2*o*2*o+2*i*2*i)},o.prototype.getPlaneConstantOfFace=function(t){var e=this.faces[t],i=this.faceNormals[t],o=this.vertices[e[0]];return-i.dot(o)};var b=new s,E=new s,B=new s,A=new s,S=new s,R=new s,z=new s,M=new s;o.prototype.clipFaceAgainstHull=function(t,e,i,o,n,s,r){for(var a=b,h=E,l=B,c=A,p=S,u=R,d=z,v=M,y=this,f=o,m=[],w=-1,g=Number.MAX_VALUE,x=0;x<y.faces.length;x++){a.copy(y.faceNormals[x]),i.vmult(a,a);var C=a.dot(t);C<g&&(g=C,w=x)}if(!(w<0)){var T=y.faces[w];T.connectedFaces=[];for(W=0;W<y.faces.length;W++)for(var q=0;q<y.faces[W].length;q++)-1!==T.indexOf(y.faces[W][q])&&W!==w&&-1===T.connectedFaces.indexOf(W)&&T.connectedFaces.push(W);f.length;for(var V=T.length,F=0;F<V;F++){var P=y.vertices[T[F]],N=y.vertices[T[(F+1)%V]];P.vsub(N,h),l.copy(h),i.vmult(l,l),e.vadd(l,l),c.copy(this.faceNormals[w]),i.vmult(c,c),e.vadd(c,c),l.cross(c,p),p.negate(p),u.copy(P),i.vmult(u,u),e.vadd(u,u);u.dot(p);var I=T.connectedFaces[F];d.copy(this.faceNormals[I]);L=this.getPlaneConstantOfFace(I);v.copy(d),i.vmult(v,v);j=L-v.dot(e);for(this.clipFaceAgainstPlane(f,m,v,j);f.length;)f.shift();for(;m.length;)f.push(m.shift())}d.copy(this.faceNormals[w]);var L=this.getPlaneConstantOfFace(w);v.copy(d),i.vmult(v,v);for(var j=L-v.dot(e),W=0;W<f.length;W++){var O=v.dot(f[W])+j;if(O<=n&&(console.log("clamped: depth="+O+" to minDist="+n),O=n),O<=s){var H=f[W];if(O<=0){var k={point:H,normal:v,depth:O};r.push(k)}}}}},o.prototype.clipFaceAgainstPlane=function(t,e,i,o){var n,r,a=t.length;if(a<2)return e;var h=t[t.length-1],l=t[0];n=i.dot(h)+o;for(var c=0;c<a;c++){if(l=t[c],r=i.dot(l)+o,n<0)if(r<0){(p=new s).copy(l),e.push(p)}else{p=new s;h.lerp(l,n/(n-r),p),e.push(p)}else if(r<0){var p=new s;h.lerp(l,n/(n-r),p),e.push(p),e.push(l)}h=l,n=r}return e},o.prototype.computeWorldVertices=function(t,e){for(var i=this.vertices.length;this.worldVertices.length<i;)this.worldVertices.push(new s);for(var o=this.vertices,n=this.worldVertices,r=0;r!==i;r++)e.vmult(o[r],n[r]),t.vadd(n[r],n[r]);this.worldVerticesNeedsUpdate=!1};new s;o.prototype.computeLocalAABB=function(t,e){var i=this.vertices.length,o=this.vertices;t.set(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),e.set(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE);for(var n=0;n<i;n++){var s=o[n];s.x<t.x?t.x=s.x:s.x>e.x&&(e.x=s.x),s.y<t.y?t.y=s.y:s.y>e.y&&(e.y=s.y),s.z<t.z?t.z=s.z:s.z>e.z&&(e.z=s.z)}},o.prototype.computeWorldFaceNormals=function(t){for(var e=this.faceNormals.length;this.worldFaceNormals.length<e;)this.worldFaceNormals.push(new s);for(var i=this.faceNormals,o=this.worldFaceNormals,n=0;n!==e;n++)t.vmult(i[n],o[n]);this.worldFaceNormalsNeedsUpdate=!1},o.prototype.updateBoundingSphereRadius=function(){for(var t=0,e=this.vertices,i=0,o=e.length;i!==o;i++){var n=e[i].norm2();n>t&&(t=n)}this.boundingSphereRadius=Math.sqrt(t)};var C=new s;o.prototype.calculateWorldAABB=function(t,e,i,o){for(var n,s,r,a,h,l,c=this.vertices.length,p=this.vertices,u=0;u<c;u++){C.copy(p[u]),e.vmult(C,C),t.vadd(C,C);var d=C;d.x<n||void 0===n?n=d.x:(d.x>a||void 0===a)&&(a=d.x),d.y<s||void 0===s?s=d.y:(d.y>h||void 0===h)&&(h=d.y),d.z<r||void 0===r?r=d.z:(d.z>l||void 0===l)&&(l=d.z)}i.set(n,s,r),o.set(a,h,l)},o.prototype.volume=function(){return 4*Math.PI*this.boundingSphereRadius/3},o.prototype.getAveragePointLocal=function(t){t=t||new s;for(var e=this.vertices.length,i=this.vertices,o=0;o<e;o++)t.vadd(i[o],t);return t.mult(1/e,t),t},o.prototype.transformAllPoints=function(t,e){var i=this.vertices.length,o=this.vertices;if(e){for(n=0;n<i;n++){s=o[n];e.vmult(s,s)}for(n=0;n<this.faceNormals.length;n++){s=this.faceNormals[n];e.vmult(s,s)}}if(t)for(var n=0;n<i;n++){var s;(s=o[n]).vadd(t,s)}};var T=new s,q=new s,V=new s;o.prototype.pointIsInside=function(t){var e=this.vertices.length,i=this.vertices,o=this.faces,n=this.faceNormals,s=this.faces.length,r=T;this.getAveragePointLocal(r);for(var a=0;a<s;a++){this.faces[a].length;var e=n[a],h=i[o[a][0]],l=q;t.vsub(h,l);var c=e.dot(l),p=V;r.vsub(h,p);var u=e.dot(p);if(c<0&&u>0||c>0&&u<0)return!1}return-1};new s;var F=new s,P=new s;o.project=function(t,e,i,o,n){var s=t.vertices.length,a=F,h=0,l=0,c=P,p=t.vertices;c.setZero(),r.vectorToLocalFrame(i,o,e,a),r.pointToLocalFrame(i,o,c,c);var u=c.dot(a);l=h=p[0].dot(a);for(var d=1;d<s;d++){var v=p[d].dot(a);v>h&&(h=v),v<l&&(l=v)}if(l-=u,h-=u,l>h){var y=l;l=h,h=y}n[0]=h,n[1]=l}},{"../math/Quaternion":41,"../math/Transform":42,"../math/Vec3":43,"./Shape":56}],52:[function(t,e,i){function o(t,e,i,o){var a=o,h=[],l=[],c=[],p=[],u=[],d=Math.cos,v=Math.sin;h.push(new s(e*d(0),e*v(0),.5*-i)),p.push(0),h.push(new s(t*d(0),t*v(0),.5*i)),u.push(1);for(w=0;w<a;w++){var y=2*Math.PI/a*(w+1),f=2*Math.PI/a*(w+.5);w<a-1?(h.push(new s(e*d(y),e*v(y),.5*-i)),p.push(2*w+2),h.push(new s(t*d(y),t*v(y),.5*i)),u.push(2*w+3),c.push([2*w+2,2*w+3,2*w+1,2*w])):c.push([0,1,2*w+1,2*w]),(a%2==1||w<a/2)&&l.push(new s(d(f),v(f),0))}c.push(u),l.push(new s(0,0,1));for(var m=[],w=0;w<p.length;w++)m.push(p[p.length-w-1]);c.push(m),this.type=n.types.CONVEXPOLYHEDRON,r.call(this,h,c,l)}e.exports=o;var n=t("./Shape"),s=t("../math/Vec3"),r=(t("../math/Quaternion"),t("./ConvexPolyhedron"));o.prototype=new r},{"../math/Quaternion":41,"../math/Vec3":43,"./ConvexPolyhedron":51,"./Shape":56}],53:[function(t,e,i){function o(t,e){e=a.defaults(e,{maxValue:null,minValue:null,elementSize:1}),this.data=t,this.maxValue=e.maxValue,this.minValue=e.minValue,this.elementSize=e.elementSize,null===e.minValue&&this.updateMinValue(),null===e.maxValue&&this.updateMaxValue(),this.cacheEnabled=!0,n.call(this),this.pillarConvex=new s,this.pillarOffset=new r,this.type=n.types.HEIGHTFIELD,this.updateBoundingSphereRadius(),this._cachedPillars={}}var n=t("./Shape"),s=t("./ConvexPolyhedron"),r=t("../math/Vec3"),a=t("../utils/Utils");e.exports=o,(o.prototype=new n).update=function(){this._cachedPillars={}},o.prototype.updateMinValue=function(){for(var t=this.data,e=t[0][0],i=0;i!==t.length;i++)for(var o=0;o!==t[i].length;o++){var n=t[i][o];n<e&&(e=n)}this.minValue=e},o.prototype.updateMaxValue=function(){for(var t=this.data,e=t[0][0],i=0;i!==t.length;i++)for(var o=0;o!==t[i].length;o++){var n=t[i][o];n>e&&(e=n)}this.maxValue=e},o.prototype.setHeightValueAtIndex=function(t,e,i){this.data[t][e]=i,this.clearCachedConvexTrianglePillar(t,e,!1),t>0&&(this.clearCachedConvexTrianglePillar(t-1,e,!0),this.clearCachedConvexTrianglePillar(t-1,e,!1)),e>0&&(this.clearCachedConvexTrianglePillar(t,e-1,!0),this.clearCachedConvexTrianglePillar(t,e-1,!1)),e>0&&t>0&&this.clearCachedConvexTrianglePillar(t-1,e-1,!0)},o.prototype.getRectMinMax=function(t,e,i,o,n){n=n||[];for(var s=this.data,r=this.minValue,a=t;a<=i;a++)for(var h=e;h<=o;h++){var l=s[a][h];l>r&&(r=l)}n[0]=this.minValue,n[1]=r},o.prototype.getIndexOfPosition=function(t,e,i,o){var n=this.elementSize,s=this.data,r=Math.floor(t/n),a=Math.floor(e/n);return i[0]=r,i[1]=a,o&&(r<0&&(r=0),a<0&&(a=0),r>=s.length-1&&(r=s.length-1),a>=s[0].length-1&&(a=s[0].length-1)),!(r<0||a<0||r>=s.length-1||a>=s[0].length-1)};var h=[],l=new r,c=new r,p=new r,u=new r;o.prototype.getTriangleAt=function(t,e,i,o,n,s){var r=h;this.getIndexOfPosition(t,e,r,i);var a=r[0],l=r[1],c=this.data;i&&(a=Math.min(c.length-2,Math.max(0,a)),l=Math.min(c[0].length-2,Math.max(0,l)));var p=this.elementSize,u=Math.pow(t/p-a,2)+Math.pow(e/p-l,2)>Math.pow(t/p-(a+1),2)+Math.pow(e/p-(l+1),2);return this.getTriangle(a,l,u,o,n,s),u};var d=new r,v=new r,y=new r,f=new r,m=new r;o.prototype.getNormalAt=function(t,e,i,o){var n=d,s=v,r=y,a=f,h=m;this.getTriangleAt(t,e,i,n,s,r),s.vsub(n,a),r.vsub(n,h),a.cross(h,o),o.normalize()},o.prototype.getAabbAtIndex=function(t,e,i){var o=this.data,n=this.elementSize;i.lowerBound.set(t*n,e*n,o[t][e]),i.upperBound.set((t+1)*n,(e+1)*n,o[t+1][e+1])},o.prototype.getHeightAt=function(t,e,i){var o=this.data,n=c,s=p,r=u,a=h;this.getIndexOfPosition(t,e,a,i);var d=a[0],v=a[1];i&&(d=Math.min(o.length-2,Math.max(0,d)),v=Math.min(o[0].length-2,Math.max(0,v)));var y=this.getTriangleAt(t,e,i,n,s,r);!function(t,e,i,o,n,s,r,a,h){h.x=((s-a)*(t-r)+(r-n)*(e-a))/((s-a)*(i-r)+(r-n)*(o-a)),h.y=((a-o)*(t-r)+(i-r)*(e-a))/((s-a)*(i-r)+(r-n)*(o-a)),h.z=1-h.x-h.y}(t,e,n.x,n.y,s.x,s.y,r.x,r.y,l);var f=l;return y?o[d+1][v+1]*f.x+o[d][v+1]*f.y+o[d+1][v]*f.z:o[d][v]*f.x+o[d+1][v]*f.y+o[d][v+1]*f.z},o.prototype.getCacheConvexTrianglePillarKey=function(t,e,i){return t+"_"+e+"_"+(i?1:0)},o.prototype.getCachedConvexTrianglePillar=function(t,e,i){return this._cachedPillars[this.getCacheConvexTrianglePillarKey(t,e,i)]},o.prototype.setCachedConvexTrianglePillar=function(t,e,i,o,n){this._cachedPillars[this.getCacheConvexTrianglePillarKey(t,e,i)]={convex:o,offset:n}},o.prototype.clearCachedConvexTrianglePillar=function(t,e,i){delete this._cachedPillars[this.getCacheConvexTrianglePillarKey(t,e,i)]},o.prototype.getTriangle=function(t,e,i,o,n,s){var r=this.data,a=this.elementSize;i?(o.set((t+1)*a,(e+1)*a,r[t+1][e+1]),n.set(t*a,(e+1)*a,r[t][e+1]),s.set((t+1)*a,e*a,r[t+1][e])):(o.set(t*a,e*a,r[t][e]),n.set((t+1)*a,e*a,r[t+1][e]),s.set(t*a,(e+1)*a,r[t][e+1]))},o.prototype.getConvexTrianglePillar=function(t,e,i){var o=this.pillarConvex,n=this.pillarOffset;if(this.cacheEnabled){if(a=this.getCachedConvexTrianglePillar(t,e,i))return this.pillarConvex=a.convex,void(this.pillarOffset=a.offset);o=new s,n=new r,this.pillarConvex=o,this.pillarOffset=n}var a=this.data,h=this.elementSize,l=o.faces;o.vertices.length=6;for(c=0;c<6;c++)o.vertices[c]||(o.vertices[c]=new r);l.length=5;for(var c=0;c<5;c++)l[c]||(l[c]=[]);var p=o.vertices,u=(Math.min(a[t][e],a[t+1][e],a[t][e+1],a[t+1][e+1])-this.minValue)/2+this.minValue;i?(n.set((t+.75)*h,(e+.75)*h,u),p[0].set(.25*h,.25*h,a[t+1][e+1]-u),p[1].set(-.75*h,.25*h,a[t][e+1]-u),p[2].set(.25*h,-.75*h,a[t+1][e]-u),p[3].set(.25*h,.25*h,-u-1),p[4].set(-.75*h,.25*h,-u-1),p[5].set(.25*h,-.75*h,-u-1),l[0][0]=0,l[0][1]=1,l[0][2]=2,l[1][0]=5,l[1][1]=4,l[1][2]=3,l[2][0]=2,l[2][1]=5,l[2][2]=3,l[2][3]=0,l[3][0]=3,l[3][1]=4,l[3][2]=1,l[3][3]=0,l[4][0]=1,l[4][1]=4,l[4][2]=5,l[4][3]=2):(n.set((t+.25)*h,(e+.25)*h,u),p[0].set(-.25*h,-.25*h,a[t][e]-u),p[1].set(.75*h,-.25*h,a[t+1][e]-u),p[2].set(-.25*h,.75*h,a[t][e+1]-u),p[3].set(-.25*h,-.25*h,-u-1),p[4].set(.75*h,-.25*h,-u-1),p[5].set(-.25*h,.75*h,-u-1),l[0][0]=0,l[0][1]=1,l[0][2]=2,l[1][0]=5,l[1][1]=4,l[1][2]=3,l[2][0]=0,l[2][1]=2,l[2][2]=5,l[2][3]=3,l[3][0]=1,l[3][1]=0,l[3][2]=3,l[3][3]=4,l[4][0]=4,l[4][1]=5,l[4][2]=2,l[4][3]=1),o.computeNormals(),o.computeEdges(),o.updateBoundingSphereRadius(),this.setCachedConvexTrianglePillar(t,e,i,o,n)},o.prototype.calculateLocalInertia=function(t,e){return(e=e||new r).set(0,0,0),e},o.prototype.volume=function(){return Number.MAX_VALUE},o.prototype.calculateWorldAABB=function(t,e,i,o){i.set(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE),o.set(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE)},o.prototype.updateBoundingSphereRadius=function(){var t=this.data,e=this.elementSize;this.boundingSphereRadius=new r(t.length*e,t[0].length*e,Math.max(Math.abs(this.maxValue),Math.abs(this.minValue))).norm()},o.prototype.setHeightsFromImage=function(t,e){var i=document.createElement("canvas");i.width=t.width,i.height=t.height;var o=i.getContext("2d");o.drawImage(t,0,0);var n=o.getImageData(0,0,t.width,t.height),s=this.data;s.length=0,this.elementSize=Math.abs(e.x)/n.width;for(var r=0;r<n.height;r++){for(var a=[],h=0;h<n.width;h++){var l=(n.data[4*(r*n.height+h)]+n.data[4*(r*n.height+h)+1]+n.data[4*(r*n.height+h)+2])/4/255*e.z;e.x<0?a.push(l):a.unshift(l)}e.y<0?s.unshift(a):s.push(a)}this.updateMaxValue(),this.updateMinValue(),this.update()}},{"../math/Vec3":43,"../utils/Utils":66,"./ConvexPolyhedron":51,"./Shape":56}],54:[function(t,e,i){function o(){n.call(this),this.type=n.types.PARTICLE}e.exports=o;var n=t("./Shape"),s=t("../math/Vec3");(o.prototype=new n).constructor=o,o.prototype.calculateLocalInertia=function(t,e){return(e=e||new s).set(0,0,0),e},o.prototype.volume=function(){return 0},o.prototype.updateBoundingSphereRadius=function(){this.boundingSphereRadius=0},o.prototype.calculateWorldAABB=function(t,e,i,o){i.copy(t),o.copy(t)}},{"../math/Vec3":43,"./Shape":56}],55:[function(t,e,i){function o(){n.call(this),this.type=n.types.PLANE,this.worldNormal=new s,this.worldNormalNeedsUpdate=!0,this.boundingSphereRadius=Number.MAX_VALUE}e.exports=o;var n=t("./Shape"),s=t("../math/Vec3");(o.prototype=new n).constructor=o,o.prototype.computeWorldNormal=function(t){var e=this.worldNormal;e.set(0,0,1),t.vmult(e,e),this.worldNormalNeedsUpdate=!1},o.prototype.calculateLocalInertia=function(t,e){return e=e||new s},o.prototype.volume=function(){return Number.MAX_VALUE};var r=new s;o.prototype.calculateWorldAABB=function(t,e,i,o){r.set(0,0,1),e.vmult(r,r);var n=Number.MAX_VALUE;i.set(-n,-n,-n),o.set(n,n,n),1===r.x&&(o.x=t.x),1===r.y&&(o.y=t.y),1===r.z&&(o.z=t.z),-1===r.x&&(i.x=t.x),-1===r.y&&(i.y=t.y),-1===r.z&&(i.z=t.z)},o.prototype.updateBoundingSphereRadius=function(){this.boundingSphereRadius=Number.MAX_VALUE}},{"../math/Vec3":43,"./Shape":56}],56:[function(t,e,i){function o(){this.id=o.idCounter++,this.type=0,this.boundingSphereRadius=0,this.collisionResponse=!0,this.material=null,this.body=null}e.exports=o;var o=t("./Shape");t("../math/Vec3"),t("../math/Quaternion"),t("../material/Material");o.prototype.constructor=o,o.prototype.updateBoundingSphereRadius=function(){throw"computeBoundingSphereRadius() not implemented for shape type "+this.type},o.prototype.volume=function(){throw"volume() not implemented for shape type "+this.type},o.prototype.calculateLocalInertia=function(t,e){throw"calculateLocalInertia() not implemented for shape type "+this.type},o.idCounter=0,o.types={SPHERE:1,PLANE:2,BOX:4,COMPOUND:8,CONVEXPOLYHEDRON:16,HEIGHTFIELD:32,PARTICLE:64,CYLINDER:128,TRIMESH:256}},{"../material/Material":38,"../math/Quaternion":41,"../math/Vec3":43,"./Shape":56}],57:[function(t,e,i){function o(t){if(n.call(this),this.radius=void 0!==t?Number(t):1,this.type=n.types.SPHERE,this.radius<0)throw new Error("The sphere radius cannot be negative.");this.updateBoundingSphereRadius()}e.exports=o;var n=t("./Shape"),s=t("../math/Vec3");(o.prototype=new n).constructor=o,o.prototype.calculateLocalInertia=function(t,e){e=e||new s;var i=2*t*this.radius*this.radius/5;return e.x=i,e.y=i,e.z=i,e},o.prototype.volume=function(){return 4*Math.PI*this.radius/3},o.prototype.updateBoundingSphereRadius=function(){this.boundingSphereRadius=this.radius},o.prototype.calculateWorldAABB=function(t,e,i,o){for(var n=this.radius,s=["x","y","z"],r=0;r<s.length;r++){var a=s[r];i[a]=t[a]-n,o[a]=t[a]+n}}},{"../math/Vec3":43,"./Shape":56}],58:[function(t,e,i){function o(t,e){n.call(this),this.type=n.types.TRIMESH,this.vertices=new Float32Array(t),this.indices=new Int16Array(e),this.normals=new Float32Array(e.length),this.aabb=new a,this.edges=null,this.scale=new s(1,1,1),this.tree=new h,this.updateEdges(),this.updateNormals(),this.updateAABB(),this.updateBoundingSphereRadius(),this.updateTree()}e.exports=o;var n=t("./Shape"),s=t("../math/Vec3"),r=(t("../math/Quaternion"),t("../math/Transform")),a=t("../collision/AABB"),h=t("../utils/Octree");(o.prototype=new n).constructor=o;var l=new s;o.prototype.updateTree=function(){var t=this.tree;t.reset(),t.aabb.copy(this.aabb);var e=this.scale;t.aabb.lowerBound.x*=1/e.x,t.aabb.lowerBound.y*=1/e.y,t.aabb.lowerBound.z*=1/e.z,t.aabb.upperBound.x*=1/e.x,t.aabb.upperBound.y*=1/e.y,t.aabb.upperBound.z*=1/e.z;for(var i=new a,o=new s,n=new s,r=new s,h=[o,n,r],l=0;l<this.indices.length/3;l++){var c=3*l;this._getUnscaledVertex(this.indices[c],o),this._getUnscaledVertex(this.indices[c+1],n),this._getUnscaledVertex(this.indices[c+2],r),i.setFromPoints(h),t.insert(i,l)}t.removeEmptyNodes()};var c=new a;o.prototype.getTrianglesInAABB=function(t,e){c.copy(t);var i=this.scale,o=i.x,n=i.y,s=i.z,r=c.lowerBound,a=c.upperBound;return r.x/=o,r.y/=n,r.z/=s,a.x/=o,a.y/=n,a.z/=s,this.tree.aabbQuery(c,e)},o.prototype.setScale=function(t){var e=this.scale.x===this.scale.y===this.scale.z,i=t.x===t.y===t.z;e&&i||this.updateNormals(),this.scale.copy(t),this.updateAABB(),this.updateBoundingSphereRadius()},o.prototype.updateNormals=function(){for(var t=l,e=this.normals,i=0;i<this.indices.length/3;i++){var n=3*i,s=this.indices[n],r=this.indices[n+1],a=this.indices[n+2];this.getVertex(s,y),this.getVertex(r,f),this.getVertex(a,m),o.computeNormal(f,y,m,t),e[n]=t.x,e[n+1]=t.y,e[n+2]=t.z}},o.prototype.updateEdges=function(){for(var t={},e=function(e,i){t[n<s?n+"_"+s:s+"_"+n]=!0},i=0;i<this.indices.length/3;i++){var o=3*i,n=this.indices[o],s=this.indices[o+1];this.indices[o+2];e(),e(),e()}var r=Object.keys(t);this.edges=new Int16Array(2*r.length);for(i=0;i<r.length;i++){var a=r[i].split("_");this.edges[2*i]=parseInt(a[0],10),this.edges[2*i+1]=parseInt(a[1],10)}},o.prototype.getEdgeVertex=function(t,e,i){var o=this.edges[2*t+(e?1:0)];this.getVertex(o,i)};var p=new s,u=new s;o.prototype.getEdgeVector=function(t,e){var i=p,o=u;this.getEdgeVertex(t,0,i),this.getEdgeVertex(t,1,o),o.vsub(i,e)};var d=new s,v=new s;o.computeNormal=function(t,e,i,o){e.vsub(t,v),i.vsub(e,d),d.cross(v,o),o.isZero()||o.normalize()};var y=new s,f=new s,m=new s;o.prototype.getVertex=function(t,e){var i=this.scale;return this._getUnscaledVertex(t,e),e.x*=i.x,e.y*=i.y,e.z*=i.z,e},o.prototype._getUnscaledVertex=function(t,e){var i=3*t,o=this.vertices;return e.set(o[i],o[i+1],o[i+2])},o.prototype.getWorldVertex=function(t,e,i,o){return this.getVertex(t,o),r.pointToWorldFrame(e,i,o,o),o},o.prototype.getTriangleVertices=function(t,e,i,o){var n=3*t;this.getVertex(this.indices[n],e),this.getVertex(this.indices[n+1],i),this.getVertex(this.indices[n+2],o)},o.prototype.getNormal=function(t,e){var i=3*t;return e.set(this.normals[i],this.normals[i+1],this.normals[i+2])};var w=new a;o.prototype.calculateLocalInertia=function(t,e){this.computeLocalAABB(w);var i=w.upperBound.x-w.lowerBound.x,o=w.upperBound.y-w.lowerBound.y,n=w.upperBound.z-w.lowerBound.z;return e.set(1/12*t*(2*o*2*o+2*n*2*n),1/12*t*(2*i*2*i+2*n*2*n),1/12*t*(2*o*2*o+2*i*2*i))};var g=new s;o.prototype.computeLocalAABB=function(t){var e=t.lowerBound,i=t.upperBound,o=this.vertices.length,n=(this.vertices,g);this.getVertex(0,n),e.copy(n),i.copy(n);for(var s=0;s!==o;s++)this.getVertex(s,n),n.x<e.x?e.x=n.x:n.x>i.x&&(i.x=n.x),n.y<e.y?e.y=n.y:n.y>i.y&&(i.y=n.y),n.z<e.z?e.z=n.z:n.z>i.z&&(i.z=n.z)},o.prototype.updateAABB=function(){this.computeLocalAABB(this.aabb)},o.prototype.updateBoundingSphereRadius=function(){for(var t=0,e=this.vertices,i=new s,o=0,n=e.length/3;o!==n;o++){this.getVertex(o,i);var r=i.norm2();r>t&&(t=r)}this.boundingSphereRadius=Math.sqrt(t)};new s;var x=new r,b=new a;o.prototype.calculateWorldAABB=function(t,e,i,o){var n=x,s=b;n.position=t,n.quaternion=e,this.aabb.toWorldFrame(n,s),i.copy(s.lowerBound),o.copy(s.upperBound)},o.prototype.volume=function(){return 4*Math.PI*this.boundingSphereRadius/3},o.createTorus=function(t,e,i,n,s){t=t||1,e=e||.5,i=i||8,n=n||6,s=s||2*Math.PI;for(var r=[],a=[],h=0;h<=i;h++)for(v=0;v<=n;v++){var l=v/n*s,c=h/i*Math.PI*2,p=(t+e*Math.cos(c))*Math.cos(l),u=(t+e*Math.cos(c))*Math.sin(l),d=e*Math.sin(c);r.push(p,u,d)}for(h=1;h<=i;h++)for(var v=1;v<=n;v++){var y=(n+1)*h+v-1,f=(n+1)*(h-1)+v-1,m=(n+1)*(h-1)+v,w=(n+1)*h+v;a.push(y,f,w),a.push(f,m,w)}return new o(r,a)}},{"../collision/AABB":15,"../math/Quaternion":41,"../math/Transform":42,"../math/Vec3":43,"../utils/Octree":63,"./Shape":56}],59:[function(t,e,i){function o(){n.call(this),this.iterations=10,this.tolerance=1e-7}e.exports=o;t("../math/Vec3"),t("../math/Quaternion");var n=t("./Solver"),s=[],r=[],a=[];(o.prototype=new n).solve=function(t,e){var i,o,n,h,l,c=0,p=this.iterations,u=this.tolerance*this.tolerance,d=this.equations,v=d.length,y=e.bodies,f=y.length,m=t;if(0!==v)for(S=0;S!==f;S++)y[S].updateSolveMassProperties();var w=r,g=a,x=s;w.length=v,g.length=v,x.length=v;for(S=0;S!==v;S++){A=d[S];x[S]=0,g[S]=A.computeB(m),w[S]=1/A.computeC()}if(0!==v){for(S=0;S!==f;S++){var b=(R=y[S]).vlambda,E=R.wlambda;b.set(0,0,0),E.set(0,0,0)}for(c=0;c!==p;c++){h=0;for(var B=0;B!==v;B++){var A=d[B];i=g[B],o=w[B],(l=x[B])+(n=o*(i-A.computeGWlambda()-A.eps*l))<A.minForce?n=A.minForce-l:l+n>A.maxForce&&(n=A.maxForce-l),x[B]+=n,h+=n>0?n:-n,A.addToWlambda(n)}if(h*h<u)break}for(var S=0;S!==f;S++){var R=y[S],z=R.velocity,M=R.angularVelocity;R.vlambda.vmul(R.linearFactor,R.vlambda),z.vadd(R.vlambda,z),R.wlambda.vmul(R.angularFactor,R.wlambda),M.vadd(R.wlambda,M)}for(var C=d.length,T=1/m;C--;)d[C].multiplier=x[C]*T}return c}},{"../math/Quaternion":41,"../math/Vec3":43,"./Solver":60}],60:[function(t,e,i){function o(){this.equations=[]}e.exports=o,o.prototype.solve=function(t,e){return 0},o.prototype.addEquation=function(t){t.enabled&&this.equations.push(t)},o.prototype.removeEquation=function(t){var e=this.equations,i=e.indexOf(t);-1!==i&&e.splice(i,1)},o.prototype.removeAllEquations=function(){this.equations.length=0}},{}],61:[function(t,e,i){function o(t){for(h.call(this),this.iterations=10,this.tolerance=1e-7,this.subsolver=t,this.nodes=[],this.nodePool=[];this.nodePool.length<128;)this.nodePool.push(this.createNode())}function n(t){for(var e=t.length,i=0;i!==e;i++){var o=t[i];if(!(o.visited||o.body.type&d))return o}return!1}function s(t,e,i,o){for(v.push(t),t.visited=!0,e(t,i,o);v.length;)for(var s,r=v.pop();s=n(r.children);)s.visited=!0,e(s,i,o),v.push(s)}function r(t,e,i){e.push(t.body);for(var o=t.eqs.length,n=0;n!==o;n++){var s=t.eqs[n];-1===i.indexOf(s)&&i.push(s)}}function a(t,e){return e.id-t.id}e.exports=o;t("../math/Vec3"),t("../math/Quaternion");var h=t("./Solver"),l=t("../objects/Body");o.prototype=new h;var c=[],p=[],u={bodies:[]},d=l.STATIC,v=[];o.prototype.createNode=function(){return{body:null,children:[],eqs:[],visited:!1}},o.prototype.solve=function(t,e){for(var i=c,o=this.nodePool,h=e.bodies,l=this.equations,d=l.length,v=h.length,y=this.subsolver;o.length<v;)o.push(this.createNode());i.length=v;for(g=0;g<v;g++)i[g]=o[g];for(g=0;g!==v;g++){var f=i[g];f.body=h[g],f.children.length=0,f.eqs.length=0,f.visited=!1}for(var m=0;m!==d;m++){var w=l[m],g=h.indexOf(w.bi),x=h.indexOf(w.bj),b=i[g],E=i[x];b.children.push(E),b.eqs.push(w),E.children.push(b),E.eqs.push(w)}var B,A=0,S=p;y.tolerance=this.tolerance,y.iterations=this.iterations;for(var R=u;B=n(i);){S.length=0,R.bodies.length=0,s(B,r,R.bodies,S);var z=S.length;S=S.sort(a);for(g=0;g!==z;g++)y.addEquation(S[g]);y.solve(t,R);y.removeAllEquations(),A++}return A}},{"../math/Quaternion":41,"../math/Vec3":43,"../objects/Body":44,"./Solver":60}],62:[function(t,e,i){var o=function(){};e.exports=o,o.prototype={constructor:o,addEventListener:function(t,e){void 0===this._listeners&&(this._listeners={});var i=this._listeners;return void 0===i[t]&&(i[t]=[]),-1===i[t].indexOf(e)&&i[t].push(e),this},hasEventListener:function(t,e){if(void 0===this._listeners)return!1;var i=this._listeners;return void 0!==i[t]&&-1!==i[t].indexOf(e)},hasAnyEventListener:function(t){if(void 0===this._listeners)return!1;return void 0!==this._listeners[t]},removeEventListener:function(t,e){if(void 0===this._listeners)return this;var i=this._listeners;if(void 0===i[t])return this;var o=i[t].indexOf(e);return-1!==o&&i[t].splice(o,1),this},dispatchEvent:function(t){if(void 0===this._listeners)return this;var e=this._listeners[t.type];if(void 0!==e){t.target=this;for(var i=0,o=e.length;i<o;i++)e[i].call(this,t)}return this}}},{}],63:[function(t,e,i){function o(t){t=t||{},this.root=t.root||null,this.aabb=t.aabb?t.aabb.clone():new s,this.data=[],this.children=[]}function n(t,e){(e=e||{}).root=null,e.aabb=t,o.call(this,e),this.maxDepth=void 0!==e.maxDepth?e.maxDepth:8}var s=t("../collision/AABB"),r=t("../math/Vec3");e.exports=n,n.prototype=new o,o.prototype.reset=function(t,e){this.children.length=this.data.length=0},o.prototype.insert=function(t,e,i){var o=this.data;if(i=i||0,!this.aabb.contains(t))return!1;var n=this.children;if(i<(this.maxDepth||this.root.maxDepth)){var s=!1;n.length||(this.subdivide(),s=!0);for(var r=0;8!==r;r++)if(n[r].insert(t,e,i+1))return!0;s&&(n.length=0)}return o.push(e),!0};var a=new r;o.prototype.subdivide=function(){var t=this.aabb,e=t.lowerBound,i=t.upperBound,n=this.children;n.push(new o({aabb:new s({lowerBound:new r(0,0,0)})}),new o({aabb:new s({lowerBound:new r(1,0,0)})}),new o({aabb:new s({lowerBound:new r(1,1,0)})}),new o({aabb:new s({lowerBound:new r(1,1,1)})}),new o({aabb:new s({lowerBound:new r(0,1,1)})}),new o({aabb:new s({lowerBound:new r(0,0,1)})}),new o({aabb:new s({lowerBound:new r(1,0,1)})}),new o({aabb:new s({lowerBound:new r(0,1,0)})})),i.vsub(e,a),a.scale(.5,a);for(var h=this.root||this,l=0;8!==l;l++){var c=n[l];c.root=h;var p=c.aabb.lowerBound;p.x*=a.x,p.y*=a.y,p.z*=a.z,p.vadd(e,p),p.vadd(a,c.aabb.upperBound)}},o.prototype.aabbQuery=function(t,e){this.data,this.children;for(var i=[this];i.length;){var o=i.pop();o.aabb.overlaps(t)&&Array.prototype.push.apply(e,o.data),Array.prototype.push.apply(i,o.children)}return e};var h=new s;o.prototype.rayQuery=function(t,e,i){return t.getAABB(h),h.toLocalFrame(e,h),this.aabbQuery(h,i),i},o.prototype.removeEmptyNodes=function(){for(var t=[this];t.length;){for(var e=t.pop(),i=e.children.length-1;i>=0;i--)e.children[i].data.length||e.children.splice(i,1);Array.prototype.push.apply(t,e.children)}}},{"../collision/AABB":15,"../math/Vec3":43}],64:[function(t,e,i){function o(){this.objects=[],this.type=Object}e.exports=o,o.prototype.release=function(){for(var t=arguments.length,e=0;e!==t;e++)this.objects.push(arguments[e]);return this},o.prototype.get=function(){return 0===this.objects.length?this.constructObject():this.objects.pop()},o.prototype.constructObject=function(){throw new Error("constructObject() not implemented in this Pool subclass yet!")},o.prototype.resize=function(t){for(var e=this.objects;e.length>t;)e.pop();for(;e.length<t;)e.push(this.constructObject());return this}},{}],65:[function(t,e,i){function o(){this.data={keys:[]}}e.exports=o,o.prototype.get=function(t,e){if(t>e){var i=e;e=t,t=i}return this.data[t+"-"+e]},o.prototype.set=function(t,e,i){if(t>e){var o=e;e=t,t=o}var n=t+"-"+e;this.get(t,e)||this.data.keys.push(n),this.data[n]=i},o.prototype.reset=function(){for(var t=this.data,e=t.keys;e.length>0;){delete t[e.pop()]}}},{}],66:[function(t,e,i){function o(){}e.exports=o,o.defaults=function(t,e){t=t||{};for(var i in e)i in t||(t[i]=e[i]);return t}},{}],67:[function(t,e,i){function o(){s.call(this),this.type=n}e.exports=o;var n=t("../math/Vec3"),s=t("./Pool");(o.prototype=new s).constructObject=function(){return new n}},{"../math/Vec3":43,"./Pool":64}],68:[function(t,e,i){function o(t){this.contactPointPool=[],this.frictionEquationPool=[],this.result=[],this.frictionResult=[],this.v3pool=new u,this.world=t,this.currentContactMaterial=null,this.enableFrictionReduction=!1}function n(t,e,i){for(var o=null,n=t.length,s=0;s!==n;s++){var r=t[s],a=k;t[(s+1)%n].vsub(r,a);var h=_;a.cross(e,h);var l=D;i.vsub(r,l);var c=h.dot(l);if(!(null===o||c>0&&!0===o||c<=0&&!1===o))return!1;null===o&&(o=c>0)}return!0}e.exports=o;var s=t("../collision/AABB"),r=t("../objects/Body"),a=t("../shapes/Shape"),h=t("../collision/Ray"),l=t("../math/Vec3"),c=t("../math/Transform"),p=(t("../shapes/ConvexPolyhedron"),t("../math/Quaternion")),u=(t("../solver/Solver"),t("../utils/Vec3Pool")),d=t("../equations/ContactEquation"),v=t("../equations/FrictionEquation");o.prototype.createContactEquation=function(t,e,i,o,n,s){var r;this.contactPointPool.length?((r=this.contactPointPool.pop()).bi=t,r.bj=e):r=new d(t,e),r.enabled=t.collisionResponse&&e.collisionResponse&&i.collisionResponse&&o.collisionResponse;var a=this.currentContactMaterial;r.restitution=a.restitution,r.setSpookParams(a.contactEquationStiffness,a.contactEquationRelaxation,this.world.dt);var h=i.material||t.material,l=o.material||e.material;return h&&l&&h.restitution>=0&&l.restitution>=0&&(r.restitution=h.restitution*l.restitution),r.si=n||i,r.sj=s||o,r},o.prototype.createFrictionEquationsFromContact=function(t,e){var i=t.bi,o=t.bj,n=t.si,s=t.sj,r=this.world,a=this.currentContactMaterial,h=a.friction,l=n.material||i.material,c=s.material||o.material;if(l&&c&&l.friction>=0&&c.friction>=0&&(h=l.friction*c.friction),h>0){var p=h*r.gravity.length(),u=i.invMass+o.invMass;u>0&&(u=1/u);var d=this.frictionEquationPool,y=d.length?d.pop():new v(i,o,p*u),f=d.length?d.pop():new v(i,o,p*u);return y.bi=f.bi=i,y.bj=f.bj=o,y.minForce=f.minForce=-p*u,y.maxForce=f.maxForce=p*u,y.ri.copy(t.ri),y.rj.copy(t.rj),f.ri.copy(t.ri),f.rj.copy(t.rj),t.ni.tangents(y.t,f.t),y.setSpookParams(a.frictionEquationStiffness,a.frictionEquationRelaxation,r.dt),f.setSpookParams(a.frictionEquationStiffness,a.frictionEquationRelaxation,r.dt),y.enabled=f.enabled=t.enabled,e.push(y,f),!0}return!1};var y=new l,f=new l,m=new l;o.prototype.createFrictionFromAverage=function(t){var e=this.result[this.result.length-1];if(this.createFrictionEquationsFromContact(e,this.frictionResult)&&1!==t){var i=this.frictionResult[this.frictionResult.length-2],o=this.frictionResult[this.frictionResult.length-1];y.setZero(),f.setZero(),m.setZero();for(var n=e.bi,s=(e.bj,0);s!==t;s++)(e=this.result[this.result.length-1-s]).bodyA!==n?(y.vadd(e.ni,y),f.vadd(e.ri,f),m.vadd(e.rj,m)):(y.vsub(e.ni,y),f.vadd(e.rj,f),m.vadd(e.ri,m));var r=1/t;f.scale(r,i.ri),m.scale(r,i.rj),o.ri.copy(i.ri),o.rj.copy(i.rj),y.normalize(),y.tangents(i.t,o.t)}};var w=new l,g=new l,x=new p,b=new p;o.prototype.getContacts=function(t,e,i,o,n,s,a){this.contactPointPool=n,this.frictionEquationPool=a,this.result=o,this.frictionResult=s;for(var h=x,l=b,c=w,p=g,u=0,d=t.length;u!==d;u++){var v=t[u],y=e[u],f=null;v.material&&y.material&&(f=i.getContactMaterial(v.material,y.material)||null);for(var m=v.type&r.KINEMATIC&&y.type&r.STATIC||v.type&r.STATIC&&y.type&r.KINEMATIC||v.type&r.KINEMATIC&&y.type&r.KINEMATIC,E=0;E<v.shapes.length;E++){v.quaternion.mult(v.shapeOrientations[E],h),v.quaternion.vmult(v.shapeOffsets[E],c),c.vadd(v.position,c);for(var B=v.shapes[E],A=0;A<y.shapes.length;A++){y.quaternion.mult(y.shapeOrientations[A],l),y.quaternion.vmult(y.shapeOffsets[A],p),p.vadd(y.position,p);var S=y.shapes[A];if(!(c.distanceTo(p)>B.boundingSphereRadius+S.boundingSphereRadius)){var R=null;B.material&&S.material&&(R=i.getContactMaterial(B.material,S.material)||null),this.currentContactMaterial=R||f||i.defaultContactMaterial;var z=this[B.type|S.type];if(z){(B.type<S.type?z.call(this,B,S,c,p,h,l,v,y,B,S,m):z.call(this,S,B,p,c,l,h,y,v,B,S,m))&&m&&(i.shapeOverlapKeeper.set(B.id,S.id),i.bodyOverlapKeeper.set(v.id,y.id))}}}}}};o.prototype[a.types.BOX|a.types.BOX]=o.prototype.boxBox=function(t,e,i,o,n,s,r,a,h,l,c){return t.convexPolyhedronRepresentation.material=t.material,e.convexPolyhedronRepresentation.material=e.material,t.convexPolyhedronRepresentation.collisionResponse=t.collisionResponse,e.convexPolyhedronRepresentation.collisionResponse=e.collisionResponse,this.convexConvex(t.convexPolyhedronRepresentation,e.convexPolyhedronRepresentation,i,o,n,s,r,a,t,e,c)},o.prototype[a.types.BOX|a.types.CONVEXPOLYHEDRON]=o.prototype.boxConvex=function(t,e,i,o,n,s,r,a,h,l,c){return t.convexPolyhedronRepresentation.material=t.material,t.convexPolyhedronRepresentation.collisionResponse=t.collisionResponse,this.convexConvex(t.convexPolyhedronRepresentation,e,i,o,n,s,r,a,t,e,c)},o.prototype[a.types.BOX|a.types.PARTICLE]=o.prototype.boxParticle=function(t,e,i,o,n,s,r,a,h,l,c){return t.convexPolyhedronRepresentation.material=t.material,t.convexPolyhedronRepresentation.collisionResponse=t.collisionResponse,this.convexParticle(t.convexPolyhedronRepresentation,e,i,o,n,s,r,a,t,e,c)},o.prototype[a.types.SPHERE]=o.prototype.sphereSphere=function(t,e,i,o,n,s,r,a,h,l,c){if(c)return i.distanceSquared(o)<Math.pow(t.radius+e.radius,2);var p=this.createContactEquation(r,a,t,e,h,l);o.vsub(i,p.ni),p.ni.normalize(),p.ri.copy(p.ni),p.rj.copy(p.ni),p.ri.mult(t.radius,p.ri),p.rj.mult(-e.radius,p.rj),p.ri.vadd(i,p.ri),p.ri.vsub(r.position,p.ri),p.rj.vadd(o,p.rj),p.rj.vsub(a.position,p.rj),this.result.push(p),this.createFrictionEquationsFromContact(p,this.frictionResult)};var E=new l,B=new l,A=new l;o.prototype[a.types.PLANE|a.types.TRIMESH]=o.prototype.planeTrimesh=function(t,e,i,o,n,s,r,a,h,p,u){var d=new l,v=E;v.set(0,0,1),n.vmult(v,v);for(var y=0;y<e.vertices.length/3;y++){e.getVertex(y,d);var f=new l;f.copy(d),c.pointToWorldFrame(o,s,f,d);var m=B;d.vsub(i,m);if(v.dot(m)<=0){if(u)return!0;var w=this.createContactEquation(r,a,t,e,h,p);w.ni.copy(v);var g=A;v.scale(m.dot(v),g),d.vsub(g,g),w.ri.copy(g),w.ri.vsub(r.position,w.ri),w.rj.copy(d),w.rj.vsub(a.position,w.rj),this.result.push(w),this.createFrictionEquationsFromContact(w,this.frictionResult)}}};var S=new l,R=new l,z=(new l,new l),M=new l,C=new l,T=new l,q=new l,V=new l,F=new l,P=new l,N=new l,I=new l,L=new l,j=new s,W=[];o.prototype[a.types.SPHERE|a.types.TRIMESH]=o.prototype.sphereTrimesh=function(t,e,i,o,n,s,r,a,l,p,u){var d=C,v=T,y=q,f=V,m=F,w=P,g=j,x=M,b=R,E=W;c.pointToLocalFrame(o,s,i,m);var B=t.radius;g.lowerBound.set(m.x-B,m.y-B,m.z-B),g.upperBound.set(m.x+B,m.y+B,m.z+B),e.getTrianglesInAABB(g,E);for(var A=z,O=t.radius*t.radius,H=0;H<E.length;H++)for(k=0;k<3;k++)if(e.getVertex(e.indices[3*E[H]+k],A),A.vsub(m,b),b.norm2()<=O){if(x.copy(A),c.pointToWorldFrame(o,s,x,A),A.vsub(i,b),u)return!0;(K=this.createContactEquation(r,a,t,e,l,p)).ni.copy(b),K.ni.normalize(),K.ri.copy(K.ni),K.ri.scale(t.radius,K.ri),K.ri.vadd(i,K.ri),K.ri.vsub(r.position,K.ri),K.rj.copy(A),K.rj.vsub(a.position,K.rj),this.result.push(K),this.createFrictionEquationsFromContact(K,this.frictionResult)}for(H=0;H<E.length;H++)for(var k=0;k<3;k++){e.getVertex(e.indices[3*E[H]+k],d),e.getVertex(e.indices[3*E[H]+(k+1)%3],v),v.vsub(d,y),m.vsub(v,w);var _=w.dot(y);m.vsub(d,w);var D=w.dot(y);if(D>0&&_<0){m.vsub(d,w),f.copy(y),f.normalize(),D=w.dot(f),f.scale(D,w),w.vadd(d,w);if((Z=w.distanceTo(m))<t.radius){if(u)return!0;K=this.createContactEquation(r,a,t,e,l,p);w.vsub(m,K.ni),K.ni.normalize(),K.ni.scale(t.radius,K.ri),c.pointToWorldFrame(o,s,w,w),w.vsub(a.position,K.rj),c.vectorToWorldFrame(s,K.ni,K.ni),c.vectorToWorldFrame(s,K.ri,K.ri),this.result.push(K),this.createFrictionEquationsFromContact(K,this.frictionResult)}}}for(var G=N,U=I,X=L,Q=S,H=0,Y=E.length;H!==Y;H++){e.getTriangleVertices(E[H],G,U,X),e.getNormal(E[H],Q),m.vsub(G,w);var Z=w.dot(Q);if(Q.scale(Z,w),m.vsub(w,w),Z=w.distanceTo(m),h.pointInTriangle(w,G,U,X)&&Z<t.radius){if(u)return!0;var K=this.createContactEquation(r,a,t,e,l,p);w.vsub(m,K.ni),K.ni.normalize(),K.ni.scale(t.radius,K.ri),c.pointToWorldFrame(o,s,w,w),w.vsub(a.position,K.rj),c.vectorToWorldFrame(s,K.ni,K.ni),c.vectorToWorldFrame(s,K.ri,K.ri),this.result.push(K),this.createFrictionEquationsFromContact(K,this.frictionResult)}}E.length=0};var O=new l,H=new l;o.prototype[a.types.SPHERE|a.types.PLANE]=o.prototype.spherePlane=function(t,e,i,o,n,s,r,a,h,l,c){var p=this.createContactEquation(r,a,t,e,h,l);if(p.ni.set(0,0,1),s.vmult(p.ni,p.ni),p.ni.negate(p.ni),p.ni.normalize(),p.ni.mult(t.radius,p.ri),i.vsub(o,O),p.ni.mult(p.ni.dot(O),H),O.vsub(H,p.rj),-O.dot(p.ni)<=t.radius){if(c)return!0;var u=p.ri,d=p.rj;u.vadd(i,u),u.vsub(r.position,u),d.vadd(o,d),d.vsub(a.position,d),this.result.push(p),this.createFrictionEquationsFromContact(p,this.frictionResult)}};var k=new l,_=new l,D=new l,G=new l,U=new l,X=new l,Q=new l,Y=[new l,new l,new l,new l,new l,new l],Z=new l,K=new l,J=new l,$=new l;o.prototype[a.types.SPHERE|a.types.BOX]=o.prototype.sphereBox=function(t,e,i,o,n,s,r,a,h,l,c){var p=this.v3pool,u=Y;i.vsub(o,G),e.getSideNormals(u,s);for(var d=t.radius,v=!1,y=K,f=J,m=$,w=null,g=0,x=0,b=0,E=null,B=0,A=u.length;B!==A&&!1===v;B++){var S=U;S.copy(u[B]);var R=S.norm();S.normalize();var z=G.dot(S);if(z<R+d&&z>0){var M=X,C=Q;M.copy(u[(B+1)%3]),C.copy(u[(B+2)%3]);var T=M.norm(),q=C.norm();M.normalize(),C.normalize();var V=G.dot(M),F=G.dot(C);if(V<T&&V>-T&&F<q&&F>-q){H=Math.abs(z-R-d);if((null===E||H<E)&&(E=H,x=V,b=F,w=R,y.copy(S),f.copy(M),m.copy(C),g++,c))return!0}}}if(g){v=!0;W=this.createContactEquation(r,a,t,e,h,l);y.mult(-d,W.ri),W.ni.copy(y),W.ni.negate(W.ni),y.mult(w,y),f.mult(x,f),y.vadd(f,y),m.mult(b,m),y.vadd(m,W.rj),W.ri.vadd(i,W.ri),W.ri.vsub(r.position,W.ri),W.rj.vadd(o,W.rj),W.rj.vsub(a.position,W.rj),this.result.push(W),this.createFrictionEquationsFromContact(W,this.frictionResult)}for(var P=p.get(),N=Z,I=0;2!==I&&!v;I++)for(_=0;2!==_&&!v;_++)for(tt=0;2!==tt&&!v;tt++)if(P.set(0,0,0),I?P.vadd(u[0],P):P.vsub(u[0],P),_?P.vadd(u[1],P):P.vsub(u[1],P),tt?P.vadd(u[2],P):P.vsub(u[2],P),o.vadd(P,N),N.vsub(i,N),N.norm2()<d*d){if(c)return!0;v=!0;(W=this.createContactEquation(r,a,t,e,h,l)).ri.copy(N),W.ri.normalize(),W.ni.copy(W.ri),W.ri.mult(d,W.ri),W.rj.copy(P),W.ri.vadd(i,W.ri),W.ri.vsub(r.position,W.ri),W.rj.vadd(o,W.rj),W.rj.vsub(a.position,W.rj),this.result.push(W),this.createFrictionEquationsFromContact(W,this.frictionResult)}p.release(P),P=null;for(var L=p.get(),j=p.get(),W=p.get(),O=p.get(),H=p.get(),k=u.length,I=0;I!==k&&!v;I++)for(var _=0;_!==k&&!v;_++)if(I%3!=_%3){u[_].cross(u[I],L),L.normalize(),u[I].vadd(u[_],j),W.copy(i),W.vsub(j,W),W.vsub(o,W);var D=W.dot(L);L.mult(D,O);for(var tt=0;tt===I%3||tt===_%3;)tt++;H.copy(i),H.vsub(O,H),H.vsub(j,H),H.vsub(o,H);var et=Math.abs(D),it=H.norm();if(et<u[tt].norm()&&it<d){if(c)return!0;v=!0;var ot=this.createContactEquation(r,a,t,e,h,l);j.vadd(O,ot.rj),ot.rj.copy(ot.rj),H.negate(ot.ni),ot.ni.normalize(),ot.ri.copy(ot.rj),ot.ri.vadd(o,ot.ri),ot.ri.vsub(i,ot.ri),ot.ri.normalize(),ot.ri.mult(d,ot.ri),ot.ri.vadd(i,ot.ri),ot.ri.vsub(r.position,ot.ri),ot.rj.vadd(o,ot.rj),ot.rj.vsub(a.position,ot.rj),this.result.push(ot),this.createFrictionEquationsFromContact(ot,this.frictionResult)}}p.release(L,j,W,O,H)};var tt=new l,et=new l,it=new l,ot=new l,nt=new l,st=new l,rt=new l,at=new l,ht=new l,lt=new l;o.prototype[a.types.SPHERE|a.types.CONVEXPOLYHEDRON]=o.prototype.sphereConvex=function(t,e,i,o,s,r,a,h,l,c,p){var u=this.v3pool;i.vsub(o,tt);for(var d=e.faceNormals,v=e.faces,y=e.vertices,f=t.radius,m=0;m!==y.length;m++){var w=y[m],g=nt;r.vmult(w,g),o.vadd(g,g);var x=ot;if(g.vsub(i,x),x.norm2()<f*f){if(p)return!0;b=!0;return(U=this.createContactEquation(a,h,t,e,l,c)).ri.copy(x),U.ri.normalize(),U.ni.copy(U.ri),U.ri.mult(f,U.ri),g.vsub(o,U.rj),U.ri.vadd(i,U.ri),U.ri.vsub(a.position,U.ri),U.rj.vadd(o,U.rj),U.rj.vsub(h.position,U.rj),this.result.push(U),void this.createFrictionEquationsFromContact(U,this.frictionResult)}}for(var b=!1,m=0,E=v.length;m!==E&&!1===b;m++){var B=d[m],A=v[m],S=st;r.vmult(B,S);var R=rt;r.vmult(y[A[0]],R),R.vadd(o,R);var z=at;S.mult(-f,z),i.vadd(z,z);var M=ht;z.vsub(R,M);var C=M.dot(S),T=lt;if(i.vsub(R,T),C<0&&T.dot(S)>0){for(var q=[],V=0,F=A.length;V!==F;V++){var P=u.get();r.vmult(y[A[V]],P),o.vadd(P,P),q.push(P)}if(n(q,S,i)){if(p)return!0;b=!0;U=this.createContactEquation(a,h,t,e,l,c);S.mult(-f,U.ri),S.negate(U.ni);var N=u.get();S.mult(-C,N);var I=u.get();S.mult(-f,I),i.vsub(o,U.rj),U.rj.vadd(I,U.rj),U.rj.vadd(N,U.rj),U.rj.vadd(o,U.rj),U.rj.vsub(h.position,U.rj),U.ri.vadd(i,U.ri),U.ri.vsub(a.position,U.ri),u.release(N),u.release(I),this.result.push(U),this.createFrictionEquationsFromContact(U,this.frictionResult);for(var V=0,L=q.length;V!==L;V++)u.release(q[V]);return}for(V=0;V!==A.length;V++){var j=u.get(),W=u.get();r.vmult(y[A[(V+1)%A.length]],j),r.vmult(y[A[(V+2)%A.length]],W),o.vadd(j,j),o.vadd(W,W);var O=et;W.vsub(j,O);var H=it;O.unit(H);var k=u.get(),_=u.get();i.vsub(j,_);var D=_.dot(H);H.mult(D,k),k.vadd(j,k);var G=u.get();if(k.vsub(i,G),D>0&&D*D<O.norm2()&&G.norm2()<f*f){if(p)return!0;var U=this.createContactEquation(a,h,t,e,l,c);k.vsub(o,U.rj),k.vsub(i,U.ni),U.ni.normalize(),U.ni.mult(f,U.ri),U.rj.vadd(o,U.rj),U.rj.vsub(h.position,U.rj),U.ri.vadd(i,U.ri),U.ri.vsub(a.position,U.ri),this.result.push(U),this.createFrictionEquationsFromContact(U,this.frictionResult);for(var V=0,L=q.length;V!==L;V++)u.release(q[V]);return u.release(j),u.release(W),u.release(k),u.release(G),void u.release(_)}u.release(j),u.release(W),u.release(k),u.release(G),u.release(_)}for(var V=0,L=q.length;V!==L;V++)u.release(q[V])}}};new l,new l;o.prototype[a.types.PLANE|a.types.BOX]=o.prototype.planeBox=function(t,e,i,o,n,s,r,a,h,l,c){return e.convexPolyhedronRepresentation.material=e.material,e.convexPolyhedronRepresentation.collisionResponse=e.collisionResponse,e.convexPolyhedronRepresentation.id=e.id,this.planeConvex(t,e.convexPolyhedronRepresentation,i,o,n,s,r,a,t,e,c)};var ct=new l,pt=new l,ut=new l,dt=new l;o.prototype[a.types.PLANE|a.types.CONVEXPOLYHEDRON]=o.prototype.planeConvex=function(t,e,i,o,n,s,r,a,h,l,c){var p=ct,u=pt;u.set(0,0,1),n.vmult(u,u);for(var d=0,v=ut,y=0;y!==e.vertices.length;y++){p.copy(e.vertices[y]),s.vmult(p,p),o.vadd(p,p),p.vsub(i,v);if(u.dot(v)<=0){if(c)return!0;var f=this.createContactEquation(r,a,t,e,h,l),m=dt;u.mult(u.dot(v),m),p.vsub(m,m),m.vsub(i,f.ri),f.ni.copy(u),p.vsub(o,f.rj),f.ri.vadd(i,f.ri),f.ri.vsub(r.position,f.ri),f.rj.vadd(o,f.rj),f.rj.vsub(a.position,f.rj),this.result.push(f),d++,this.enableFrictionReduction||this.createFrictionEquationsFromContact(f,this.frictionResult)}}this.enableFrictionReduction&&d&&this.createFrictionFromAverage(d)};var vt=new l,yt=new l;o.prototype[a.types.CONVEXPOLYHEDRON]=o.prototype.convexConvex=function(t,e,i,o,n,s,r,a,h,l,c,p,u){var d=vt;if(!(i.distanceTo(o)>t.boundingSphereRadius+e.boundingSphereRadius)&&t.findSeparatingAxis(e,i,n,o,s,d,p,u)){var v=[],y=yt;t.clipAgainstHull(i,n,e,o,s,d,-100,100,v);for(var f=0,m=0;m!==v.length;m++){if(c)return!0;var w=this.createContactEquation(r,a,t,e,h,l),g=w.ri,x=w.rj;d.negate(w.ni),v[m].normal.negate(y),y.mult(v[m].depth,y),v[m].point.vadd(y,g),x.copy(v[m].point),g.vsub(i,g),x.vsub(o,x),g.vadd(i,g),g.vsub(r.position,g),x.vadd(o,x),x.vsub(a.position,x),this.result.push(w),f++,this.enableFrictionReduction||this.createFrictionEquationsFromContact(w,this.frictionResult)}this.enableFrictionReduction&&f&&this.createFrictionFromAverage(f)}};var ft=new l,mt=new l,wt=new l;o.prototype[a.types.PLANE|a.types.PARTICLE]=o.prototype.planeParticle=function(t,e,i,o,n,s,r,a,h,l,c){var p=ft;p.set(0,0,1),r.quaternion.vmult(p,p);var u=mt;o.vsub(r.position,u);if(p.dot(u)<=0){if(c)return!0;var d=this.createContactEquation(a,r,e,t,h,l);d.ni.copy(p),d.ni.negate(d.ni),d.ri.set(0,0,0);var v=wt;p.mult(p.dot(o),v),o.vsub(v,v),d.rj.copy(v),this.result.push(d),this.createFrictionEquationsFromContact(d,this.frictionResult)}};var gt=new l;o.prototype[a.types.PARTICLE|a.types.SPHERE]=o.prototype.sphereParticle=function(t,e,i,o,n,s,r,a,h,l,c){var p=gt;p.set(0,0,1),o.vsub(i,p);if(p.norm2()<=t.radius*t.radius){if(c)return!0;var u=this.createContactEquation(a,r,e,t,h,l);p.normalize(),u.rj.copy(p),u.rj.mult(t.radius,u.rj),u.ni.copy(p),u.ni.negate(u.ni),u.ri.set(0,0,0),this.result.push(u),this.createFrictionEquationsFromContact(u,this.frictionResult)}};var xt=new p,bt=new l,Et=(new l,new l),Bt=new l,At=new l;o.prototype[a.types.PARTICLE|a.types.CONVEXPOLYHEDRON]=o.prototype.convexParticle=function(t,e,i,o,n,s,r,a,h,l,c){var p=-1,u=Et,d=At,v=null,y=bt;if(y.copy(o),y.vsub(i,y),n.conjugate(xt),xt.vmult(y,y),t.pointIsInside(y)){t.worldVerticesNeedsUpdate&&t.computeWorldVertices(i,n),t.worldFaceNormalsNeedsUpdate&&t.computeWorldFaceNormals(n);for(var f=0,m=t.faces.length;f!==m;f++){var w=[t.worldVertices[t.faces[f][0]]],g=t.worldFaceNormals[f];o.vsub(w[0],Bt);var x=-g.dot(Bt);if(null===v||Math.abs(x)<Math.abs(v)){if(c)return!0;v=x,p=f,u.copy(g),0}}if(-1!==p){var b=this.createContactEquation(a,r,e,t,h,l);u.mult(v,d),d.vadd(o,d),d.vsub(i,d),b.rj.copy(d),u.negate(b.ni),b.ri.set(0,0,0);var E=b.ri,B=b.rj;E.vadd(o,E),E.vsub(a.position,E),B.vadd(i,B),B.vsub(r.position,B),this.result.push(b),this.createFrictionEquationsFromContact(b,this.frictionResult)}else console.warn("Point found inside convex, but did not find penetrating face!")}},o.prototype[a.types.BOX|a.types.HEIGHTFIELD]=o.prototype.boxHeightfield=function(t,e,i,o,n,s,r,a,h,l,c){return t.convexPolyhedronRepresentation.material=t.material,t.convexPolyhedronRepresentation.collisionResponse=t.collisionResponse,this.convexHeightfield(t.convexPolyhedronRepresentation,e,i,o,n,s,r,a,t,e,c)};var St=new l,Rt=new l,zt=[0];o.prototype[a.types.CONVEXPOLYHEDRON|a.types.HEIGHTFIELD]=o.prototype.convexHeightfield=function(t,e,i,o,n,s,r,a,h,l,p){var u=e.data,d=e.elementSize,v=t.boundingSphereRadius,y=Rt,f=zt,m=St;c.pointToLocalFrame(o,s,i,m);var w=Math.floor((m.x-v)/d)-1,g=Math.ceil((m.x+v)/d)+1,x=Math.floor((m.y-v)/d)-1,b=Math.ceil((m.y+v)/d)+1;if(!(g<0||b<0||w>u.length||x>u[0].length)){w<0&&(w=0),g<0&&(g=0),x<0&&(x=0),b<0&&(b=0),w>=u.length&&(w=u.length-1),g>=u.length&&(g=u.length-1),b>=u[0].length&&(b=u[0].length-1),x>=u[0].length&&(x=u[0].length-1);var E=[];e.getRectMinMax(w,x,g,b,E);var B=E[0],A=E[1];if(!(m.z-v>A||m.z+v<B))for(var S=w;S<g;S++)for(var R=x;R<b;R++){var z=!1;if(e.getConvexTrianglePillar(S,R,!1),c.pointToWorldFrame(o,s,e.pillarOffset,y),i.distanceTo(y)<e.pillarConvex.boundingSphereRadius+t.boundingSphereRadius&&(z=this.convexConvex(t,e.pillarConvex,i,y,n,s,r,a,null,null,p,f,null)),p&&z)return!0;if(e.getConvexTrianglePillar(S,R,!0),c.pointToWorldFrame(o,s,e.pillarOffset,y),i.distanceTo(y)<e.pillarConvex.boundingSphereRadius+t.boundingSphereRadius&&(z=this.convexConvex(t,e.pillarConvex,i,y,n,s,r,a,null,null,p,f,null)),p&&z)return!0}}};var Mt=new l,Ct=new l;o.prototype[a.types.SPHERE|a.types.HEIGHTFIELD]=o.prototype.sphereHeightfield=function(t,e,i,o,n,s,r,a,h,l,p){var u=e.data,d=t.radius,v=e.elementSize,y=Ct,f=Mt;c.pointToLocalFrame(o,s,i,f);var m=Math.floor((f.x-d)/v)-1,w=Math.ceil((f.x+d)/v)+1,g=Math.floor((f.y-d)/v)-1,x=Math.ceil((f.y+d)/v)+1;if(!(w<0||x<0||m>u.length||x>u[0].length)){m<0&&(m=0),w<0&&(w=0),g<0&&(g=0),x<0&&(x=0),m>=u.length&&(m=u.length-1),w>=u.length&&(w=u.length-1),x>=u[0].length&&(x=u[0].length-1),g>=u[0].length&&(g=u[0].length-1);var b=[];e.getRectMinMax(m,g,w,x,b);var E=b[0],B=b[1];if(!(f.z-d>B||f.z+d<E))for(var A=this.result,S=m;S<w;S++)for(var R=g;R<x;R++){var z=A.length,M=!1;if(e.getConvexTrianglePillar(S,R,!1),c.pointToWorldFrame(o,s,e.pillarOffset,y),i.distanceTo(y)<e.pillarConvex.boundingSphereRadius+t.boundingSphereRadius&&(M=this.sphereConvex(t,e.pillarConvex,i,y,n,s,r,a,t,e,p)),p&&M)return!0;if(e.getConvexTrianglePillar(S,R,!0),c.pointToWorldFrame(o,s,e.pillarOffset,y),i.distanceTo(y)<e.pillarConvex.boundingSphereRadius+t.boundingSphereRadius&&(M=this.sphereConvex(t,e.pillarConvex,i,y,n,s,r,a,t,e,p)),p&&M)return!0;if(A.length-z>2)return}}}},{"../collision/AABB":15,"../collision/Ray":22,"../equations/ContactEquation":32,"../equations/FrictionEquation":34,"../math/Quaternion":41,"../math/Transform":42,"../math/Vec3":43,"../objects/Body":44,"../shapes/ConvexPolyhedron":51,"../shapes/Shape":56,"../solver/Solver":60,"../utils/Vec3Pool":67}],69:[function(t,e,i){function o(t){t=t||{},h.apply(this),this.dt=-1,this.allowSleep=!!t.allowSleep,this.contacts=[],this.frictionEquations=[],this.quatNormalizeSkip=void 0!==t.quatNormalizeSkip?t.quatNormalizeSkip:0,this.quatNormalizeFast=void 0!==t.quatNormalizeFast&&t.quatNormalizeFast,this.time=0,this.stepnumber=0,this.default_dt=1/60,this.nextId=0,this.gravity=new n,t.gravity&&this.gravity.copy(t.gravity),this.broadphase=void 0!==t.broadphase?t.broadphase:new w,this.bodies=[],this.solver=void 0!==t.solver?t.solver:new r,this.constraints=[],this.narrowphase=new a(this),this.collisionMatrix=new l,this.collisionMatrixPrevious=new l,this.bodyOverlapKeeper=new c,this.shapeOverlapKeeper=new c,this.materials=[],this.contactmaterials=[],this.contactMaterialTable=new v,this.defaultMaterial=new p("default"),this.defaultContactMaterial=new u(this.defaultMaterial,this.defaultMaterial,{friction:.3,restitution:0}),this.doProfiling=!1,this.profile={solve:0,makeContactConstraints:0,broadphase:0,integrate:0,narrowphase:0},this.accumulator=0,this.subsystems=[],this.addBodyEvent={type:"addBody",body:null},this.removeBodyEvent={type:"removeBody",body:null},this.idToBodyMap={},this.broadphase.setWorld(this)}e.exports=o;t("../shapes/Shape");var n=t("../math/Vec3"),s=t("../math/Quaternion"),r=t("../solver/GSSolver"),a=(t("../equations/ContactEquation"),t("../equations/FrictionEquation"),t("./Narrowphase")),h=t("../utils/EventTarget"),l=t("../collision/ArrayCollisionMatrix"),c=t("../collision/OverlapKeeper"),p=t("../material/Material"),u=t("../material/ContactMaterial"),d=t("../objects/Body"),v=t("../utils/TupleDictionary"),y=t("../collision/RaycastResult"),f=t("../collision/AABB"),m=t("../collision/Ray"),w=t("../collision/NaiveBroadphase");o.prototype=new h;new f;var g=new m;if(o.prototype.getContactMaterial=function(t,e){return this.contactMaterialTable.get(t.id,e.id)},o.prototype.numObjects=function(){return this.bodies.length},o.prototype.collisionMatrixTick=function(){var t=this.collisionMatrixPrevious;this.collisionMatrixPrevious=this.collisionMatrix,this.collisionMatrix=t,this.collisionMatrix.reset(),this.bodyOverlapKeeper.tick(),this.shapeOverlapKeeper.tick()},o.prototype.add=o.prototype.addBody=function(t){-1===this.bodies.indexOf(t)&&(t.index=this.bodies.length,this.bodies.push(t),t.world=this,t.initPosition.copy(t.position),t.initVelocity.copy(t.velocity),t.timeLastSleepy=this.time,t instanceof d&&(t.initAngularVelocity.copy(t.angularVelocity),t.initQuaternion.copy(t.quaternion)),this.collisionMatrix.setNumObjects(this.bodies.length),this.addBodyEvent.body=t,this.idToBodyMap[t.id]=t,this.dispatchEvent(this.addBodyEvent))},o.prototype.addConstraint=function(t){this.constraints.push(t)},o.prototype.removeConstraint=function(t){var e=this.constraints.indexOf(t);-1!==e&&this.constraints.splice(e,1)},o.prototype.rayTest=function(t,e,i){i instanceof y?this.raycastClosest(t,e,{skipBackfaces:!0},i):this.raycastAll(t,e,{skipBackfaces:!0},i)},o.prototype.raycastAll=function(t,e,i,o){return i.mode=m.ALL,i.from=t,i.to=e,i.callback=o,g.intersectWorld(this,i)},o.prototype.raycastAny=function(t,e,i,o){return i.mode=m.ANY,i.from=t,i.to=e,i.result=o,g.intersectWorld(this,i)},o.prototype.raycastClosest=function(t,e,i,o){return i.mode=m.CLOSEST,i.from=t,i.to=e,i.result=o,g.intersectWorld(this,i)},o.prototype.remove=function(t){t.world=null;var e=this.bodies.length-1,i=this.bodies,o=i.indexOf(t);if(-1!==o){i.splice(o,1);for(var n=0;n!==i.length;n++)i[n].index=n;this.collisionMatrix.setNumObjects(e),this.removeBodyEvent.body=t,delete this.idToBodyMap[t.id],this.dispatchEvent(this.removeBodyEvent)}},o.prototype.removeBody=o.prototype.remove,o.prototype.getBodyById=function(t){return this.idToBodyMap[t]},o.prototype.getShapeById=function(t){for(var e=this.bodies,i=0,o=e.length;i<o;i++)for(var n=e[i].shapes,s=0,r=n.length;s<r;s++){var a=n[s];if(a.id===t)return a}},o.prototype.addMaterial=function(t){this.materials.push(t)},o.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 x=Date.now();performance.timing&&performance.timing.navigationStart&&(x=performance.timing.navigationStart),performance.now=function(){return Date.now()-x}}new n;o.prototype.step=function(t,e,i){if(i=i||10,0===(e=e||0))this.internalStep(t),this.time+=t;else{this.accumulator+=e;for(var o=0;this.accumulator>=t&&o<i;)this.internalStep(t),this.accumulator-=t,o++;for(var n=this.accumulator%t/t,s=0;s!==this.bodies.length;s++){var r=this.bodies[s];r.previousPosition.lerp(r.position,n,r.interpolatedPosition),r.previousQuaternion.slerp(r.quaternion,n,r.interpolatedQuaternion),r.previousQuaternion.normalize()}this.time+=e}};var b={type:"postStep"},E={type:"preStep"},B={type:d.COLLIDE_EVENT_NAME,body:null,contact:null},A=[],S=[],R=[],z=[];new n,new n,new n,new n,new n,new n,new n,new n,new n,new s,new s,new s,new n;o.prototype.internalStep=function(t){this.dt=t;var e,i=this.contacts,o=R,n=z,s=this.numObjects(),r=this.bodies,a=this.solver,h=this.gravity,l=this.doProfiling,c=this.profile,p=d.DYNAMIC,u=this.constraints,v=S,y=(h.norm(),h.x),f=h.y,m=h.z,w=0;for(l&&(e=performance.now()),w=0;w!==s;w++){if((P=r[w]).type===p){var g=P.force,x=P.mass;g.x+=x*y,g.y+=x*f,g.z+=x*m}}for(var w=0,M=this.subsystems.length;w!==M;w++)this.subsystems[w].update();l&&(e=performance.now()),o.length=0,n.length=0,this.broadphase.collisionPairs(this,o,n),l&&(c.broadphase=performance.now()-e);j=u.length;for(w=0;w!==j;w++){if(!(W=u[w]).collideConnected)for(O=o.length-1;O>=0;O-=1)(W.bodyA===o[O]&&W.bodyB===n[O]||W.bodyB===o[O]&&W.bodyA===n[O])&&(o.splice(O,1),n.splice(O,1))}this.collisionMatrixTick(),l&&(e=performance.now());var C=A,T=i.length;for(w=0;w!==T;w++)C.push(i[w]);i.length=0;var q=this.frictionEquations.length;for(w=0;w!==q;w++)v.push(this.frictionEquations[w]);this.frictionEquations.length=0,this.narrowphase.getContacts(o,n,this,i,C,this.frictionEquations,v),l&&(c.narrowphase=performance.now()-e),l&&(e=performance.now());for(w=0;w<this.frictionEquations.length;w++)a.addEquation(this.frictionEquations[w]);for(var V=i.length,F=0;F!==V;F++){var P=(W=i[F]).bi,N=W.bj,I=W.si,L=W.sj;(P.material&&N.material?this.getContactMaterial(P.material,N.material)||this.defaultContactMaterial:this.defaultContactMaterial).friction;if(P.material&&N.material&&(P.material.friction>=0&&N.material.friction>=0&&P.material.friction*N.material.friction,P.material.restitution>=0&&N.material.restitution>=0&&(W.restitution=P.material.restitution*N.material.restitution)),a.addEquation(W),P.allowSleep&&P.type===d.DYNAMIC&&P.sleepState===d.SLEEPING&&N.sleepState===d.AWAKE&&N.type!==d.STATIC){N.velocity.norm2()+N.angularVelocity.norm2()>=2*Math.pow(N.sleepSpeedLimit,2)&&(P._wakeUpAfterNarrowphase=!0)}if(N.allowSleep&&N.type===d.DYNAMIC&&N.sleepState===d.SLEEPING&&P.sleepState===d.AWAKE&&P.type!==d.STATIC){P.velocity.norm2()+P.angularVelocity.norm2()>=2*Math.pow(P.sleepSpeedLimit,2)&&(N._wakeUpAfterNarrowphase=!0)}this.collisionMatrix.set(P,N,!0),this.collisionMatrixPrevious.get(P,N)||(B.body=N,B.contact=W,P.dispatchEvent(B),B.body=P,N.dispatchEvent(B)),this.bodyOverlapKeeper.set(P.id,N.id),this.shapeOverlapKeeper.set(I.id,L.id)}for(this.emitContactEvents(),l&&(c.makeContactConstraints=performance.now()-e,e=performance.now()),w=0;w!==s;w++){(P=r[w])._wakeUpAfterNarrowphase&&(P.wakeUp(),P._wakeUpAfterNarrowphase=!1)}var j=u.length;for(w=0;w!==j;w++){var W=u[w];W.update();for(var O=0,H=W.equations.length;O!==H;O++){var k=W.equations[O];a.addEquation(k)}}a.solve(t,this),l&&(c.solve=performance.now()-e),a.removeAllEquations();var _=Math.pow;for(w=0;w!==s;w++){if((P=r[w]).type&p){var D=_(1-P.linearDamping,t),G=P.velocity;G.mult(D,G);var U=P.angularVelocity;if(U){var X=_(1-P.angularDamping,t);U.mult(X,U)}}}for(this.dispatchEvent(E),w=0;w!==s;w++){(P=r[w]).preStep&&P.preStep.call(P)}l&&(e=performance.now());var Q=this.stepnumber%(this.quatNormalizeSkip+1)==0,Y=this.quatNormalizeFast;for(w=0;w!==s;w++)r[w].integrate(t,Q,Y);for(this.clearForces(),this.broadphase.dirty=!0,l&&(c.integrate=performance.now()-e),this.time+=t,this.stepnumber+=1,this.dispatchEvent(b),w=0;w!==s;w++){var Z=(P=r[w]).postStep;Z&&Z.call(P)}if(this.allowSleep)for(w=0;w!==s;w++)r[w].sleepTick(this.time)},o.prototype.emitContactEvents=function(){var t=[],e=[],i={type:"beginContact",bodyA:null,bodyB:null},o={type:"endContact",bodyA:null,bodyB:null},n={type:"beginShapeContact",bodyA:null,bodyB:null,shapeA:null,shapeB:null},s={type:"endShapeContact",bodyA:null,bodyB:null,shapeA:null,shapeB:null};return function(){var r=this.hasAnyEventListener("beginContact"),a=this.hasAnyEventListener("endContact");if((r||a)&&this.bodyOverlapKeeper.getDiff(t,e),r){for(var h=0,l=t.length;h<l;h+=2)i.bodyA=this.getBodyById(t[h]),i.bodyB=this.getBodyById(t[h+1]),this.dispatchEvent(i);i.bodyA=i.bodyB=null}if(a){for(var h=0,l=e.length;h<l;h+=2)o.bodyA=this.getBodyById(e[h]),o.bodyB=this.getBodyById(e[h+1]),this.dispatchEvent(o);o.bodyA=o.bodyB=null}t.length=e.length=0;var c=this.hasAnyEventListener("beginShapeContact"),p=this.hasAnyEventListener("endShapeContact");if((c||p)&&this.shapeOverlapKeeper.getDiff(t,e),c){for(var h=0,l=t.length;h<l;h+=2){var u=this.getShapeById(t[h]),d=this.getShapeById(t[h+1]);n.shapeA=u,n.shapeB=d,n.bodyA=u.body,n.bodyB=d.body,this.dispatchEvent(n)}n.bodyA=n.bodyB=n.shapeA=n.shapeB=null}if(p){for(var h=0,l=e.length;h<l;h+=2){var u=this.getShapeById(e[h]),d=this.getShapeById(e[h+1]);s.shapeA=u,s.shapeB=d,s.bodyA=u.body,s.bodyB=d.body,this.dispatchEvent(s)}s.bodyA=s.bodyB=s.shapeA=s.shapeB=null}}}(),o.prototype.clearForces=function(){for(var t=this.bodies,e=t.length,i=0;i!==e;i++){var o=t[i];o.force,o.torque;o.force.set(0,0,0),o.torque.set(0,0,0)}}},{"../collision/AABB":15,"../collision/ArrayCollisionMatrix":16,"../collision/NaiveBroadphase":19,"../collision/OverlapKeeper":21,"../collision/Ray":22,"../collision/RaycastResult":23,"../equations/ContactEquation":32,"../equations/FrictionEquation":34,"../material/ContactMaterial":37,"../material/Material":38,"../math/Quaternion":41,"../math/Vec3":43,"../objects/Body":44,"../shapes/Shape":56,"../solver/GSSolver":59,"../utils/EventTarget":62,"../utils/TupleDictionary":65,"./Narrowphase":68}],70:[function(t,e,i){function o(t){if(!r(t).length)return null;t.computeBoundingBox();var e=t.boundingBox;return new a.Box(new a.Vec3((e.max.x-e.min.x)/2,(e.max.y-e.min.y)/2,(e.max.z-e.min.z)/2))}function n(t){var e,i,o,n=new THREE.Box3;return n.setFromObject(t),isFinite(n.min.lengthSq())?(e=new a.Box(new a.Vec3((n.max.x-n.min.x)/2,(n.max.y-n.min.y)/2,(n.max.z-n.min.z)/2)),t.updateMatrixWorld(),(o=new THREE.Vector3).setFromMatrixPosition(t.matrixWorld),(i=n.translate(o.negate()).getCenter()).lengthSq()&&(e.offset=i),e):null}function s(t){var e,i,o=function(t){var e=[];return t.traverse(function(t){"Mesh"===t.type&&e.push(t)}),e}(t),n=new THREE.Geometry,s=new THREE.Geometry;if(0===o.length)return null;if(1===o.length){var r=new THREE.Vector3,a=new THREE.Quaternion,h=new THREE.Vector3;return o[0].geometry.isBufferGeometry?o[0].geometry.attributes.position&&n.fromBufferGeometry(o[0].geometry):n=o[0].geometry.clone(),n.metadata=o[0].geometry.metadata,o[0].updateMatrixWorld(),o[0].matrixWorld.decompose(r,a,h),n.scale(h.x,h.y,h.z)}for(;i=o.pop();)i.updateMatrixWorld(),i.geometry.isBufferGeometry?(n.fromBufferGeometry(i.geometry),s.merge(n,i.matrixWorld)):s.merge(i.geometry,i.matrixWorld);return(e=new THREE.Matrix4).scale(t.scale),s.applyMatrix(e),s}function r(t){return t.attributes||(t=(new THREE.BufferGeometry).fromGeometry(t)),(t.attributes.position||{}).array||[]}var a=t("cannon"),h=t("./lib/THREE.quickhull"),l=Math.PI/2,c={BOX:"Box",CYLINDER:"Cylinder",SPHERE:"Sphere",HULL:"ConvexPolyhedron",MESH:"Trimesh"};e.exports=a.mesh2shape=function(t,e){var i;if((e=e||{}).type===c.BOX)return n(t);if(e.type===c.CYLINDER)return function(t,e){var i,o,n,s=new THREE.Box3,r=["x","y","z"],h=e.cylinderAxis||"y",c=r.splice(r.indexOf(h),1)&&r;return s.setFromObject(t),isFinite(s.min.lengthSq())?(o=s.max[h]-s.min[h],n=.5*Math.max(s.max[c[0]]-s.min[c[0]],s.max[c[1]]-s.min[c[1]]),i=new a.Cylinder(n,n,o,12),i._type=a.Shape.types.CYLINDER,i.radiusTop=n,i.radiusBottom=n,i.height=o,i.numSegments=12,i.orientation=new a.Quaternion,i.orientation.setFromEuler("y"===h?l:0,"z"===h?l:0,0,"XYZ").normalize(),i):null}(t,e);if(e.type===c.SPHERE)return function(t,e){if(e.sphereRadius)return new a.Sphere(e.sphereRadius);var i=s(t);return i?(i.computeBoundingSphere(),new a.Sphere(i.boundingSphere.radius)):null}(t,e);if(e.type===c.HULL)return function(t){var e,i,o,n,r=s(t);if(!r||!r.vertices.length)return null;for(e=0;e<r.vertices.length;e++)r.vertices[e].x+=1e-4*(Math.random()-.5),r.vertices[e].y+=1e-4*(Math.random()-.5),r.vertices[e].z+=1e-4*(Math.random()-.5);for(n=h(r),i=new Array(n.vertices.length),e=0;e<n.vertices.length;e++)i[e]=new a.Vec3(n.vertices[e].x,n.vertices[e].y,n.vertices[e].z);for(o=new Array(n.faces.length),e=0;e<n.faces.length;e++)o[e]=[n.faces[e].a,n.faces[e].b,n.faces[e].c];return new a.ConvexPolyhedron(i,o)}(t);if(e.type===c.MESH)return(i=s(t))?function(t){var e,i=r(t);return i.length?(e=Object.keys(i).map(Number),new a.Trimesh(i,e)):null}(i):null;if(e.type)throw new Error('[CANNON.mesh2shape] Invalid type "%s".',e.type);if(!(i=s(t)))return null;switch(i.metadata?i.metadata.type:i.type){case"BoxGeometry":case"BoxBufferGeometry":return o(i);case"CylinderGeometry":case"CylinderBufferGeometry":return function(t){var e,i=t.metadata?t.metadata.parameters:t.parameters;return e=new a.Cylinder(i.radiusTop,i.radiusBottom,i.height,i.radialSegments),e._type=a.Shape.types.CYLINDER,e.radiusTop=i.radiusTop,e.radiusBottom=i.radiusBottom,e.height=i.height,e.numSegments=i.radialSegments,e.orientation=new a.Quaternion,e.orientation.setFromEuler(THREE.Math.degToRad(-90),0,0,"XYZ").normalize(),e}(i);case"PlaneGeometry":case"PlaneBufferGeometry":return function(t){t.computeBoundingBox();var e=t.boundingBox;return new a.Box(new a.Vec3((e.max.x-e.min.x)/2||.1,(e.max.y-e.min.y)/2||.1,(e.max.z-e.min.z)/2||.1))}(i);case"SphereGeometry":case"SphereBufferGeometry":return function(t){var e=t.metadata?t.metadata.parameters:t.parameters;return new a.Sphere(e.radius)}(i);case"TubeGeometry":case"Geometry":case"BufferGeometry":return n(t);default:return console.warn('Unrecognized geometry: "%s". Using bounding box as shape.',i.type),o(i)}},a.mesh2shape.Type=c},{"./lib/THREE.quickhull":71,cannon:14}],71:[function(t,e,i){e.exports=function(){function t(t){for(;A.length>0;)!function(t,o){var n,s=B.length,r=[t],a=o.indexOf(t.visiblePoints.pop());for(;s-- >0;)(n=B[s])!==t&&e(n,o).dot(g.subVectors(o[a],o[n[0]]))>0&&r.push(n);var h,l,c,p,u=s=r.length,d=1===s,v=[],y=0,f=[];r[0][0],r[0][1],r[0][1],r[0][2],r[0][2],r[0][0];if(1===r.length)n=r[0],v=[n[0],n[1],n[1],n[2],n[2],n[0]],A.indexOf(n)>-1&&A.splice(A.indexOf(n),1),n.visiblePoints&&(f=f.concat(n.visiblePoints)),B.splice(B.indexOf(n),1);else for(;s-- >0;){n=r[s],A.indexOf(n)>-1&&A.splice(A.indexOf(n),1),n.visiblePoints&&(f=f.concat(n.visiblePoints)),B.splice(B.indexOf(n),1);var m;for(cEdgeIndex=0;cEdgeIndex<3;){for(m=!1,u=r.length,c=n[cEdgeIndex],p=n[(cEdgeIndex+1)%3];u-- >0&&!m;)if(h=r[u],y=0,h!==n)for(;y<3&&!m;)l=y+1,m=h[y]===c&&h[l%3]===p||h[y]===p&&h[l%3]===c,y++;m&&!d||(v.push(c),v.push(p)),cEdgeIndex++}}s=0;var w,x=v.length/2;for(;s<x;)i(w=[v[2*s+1],a,v[2*s]],f,o),B.push(w),void 0!==w.visiblePoints&&A.push(w),s++}(A.shift(),t)}function e(t,e){if(void 0!==t.normal)return t.normal;var i=e[t[0]],o=e[t[1]],n=e[t[2]];return d.subVectors(o,i),v.subVectors(n,i),w.crossVectors(v,d),w.normalize(),t.normal=w.clone()}function i(t,i,o){var n=o[t[0]],s=[],r=e(t,o);i.sort(function(t,e){return s[t.x/3]=void 0!==s[t.x/3]?s[t.x/3]:r.dot(f.subVectors(t,n)),s[e.x/3]=void 0!==s[e.x/3]?s[e.x/3]:r.dot(m.subVectors(e,n)),s[t.x/3]-s[e.x/3]});var a=i.length;for(1===a&&(s[i[0].x/3]=r.dot(f.subVectors(i[0],n)));a-- >0&&s[i[a].x/3]>0;);a+1<i.length&&s[i[a+1].x/3]>0&&(t.visiblePoints=i.splice(a+1))}var o,n,s,r,a,h,l,c,p,u,d,v,y,f,m,w,g,x,b,E,B=[],A=[],S=0,R=function(){var t=new THREE.Vector3,e=new THREE.Vector3,i=new THREE.Vector3;return function(o,n,s){return t.subVectors(s,o),e.subVectors(n,o),i.crossVectors(t,e),i.normalize()}}(),z=function(){var t=new THREE.Vector3,e=new THREE.Vector3,i=new THREE.Vector3;return function(o,n,s){t.subVectors(n,o),e.subVectors(s,o),i.subVectors(s,n);var r=e.dot(t);if(r<0)return e.dot(e);var a=t.dot(t);return r>=a?i.dot(i):e.dot(e)-r*r/a}}();return function(e){for(d=new THREE.Vector3,v=new THREE.Vector3,y=new THREE.Vector3,f=new THREE.Vector3,m=new THREE.Vector3,w=new THREE.Vector3,g=new THREE.Vector3,x=new THREE.Vector3,b=new THREE.Vector3,E=new THREE.Vector3,points=e.vertices,B=[],A=[],P=o=points.length,n=points.slice(0,6),S=0;P-- >0;)points[P].x<n[0].x&&(n[0]=points[P]),points[P].x>n[1].x&&(n[1]=points[P]),points[P].y<n[2].y&&(n[2]=points[P]),points[P].y<n[3].y&&(n[3]=points[P]),points[P].z<n[4].z&&(n[4]=points[P]),points[P].z<n[5].z&&(n[5]=points[P]);for(r=P=6;P-- >0;)for(r=P-1;r-- >0;)S<(s=n[P].distanceToSquared(n[r]))&&(S=s,a=n[P],h=n[r]);for(P=6,S=0;P-- >0;)s=z(a,h,n[P]),S<s&&(S=s,l=n[P]);for(p=R(a,h,l),u=p.dot(a),S=0,P=o;P-- >0;)s=Math.abs(points[P].dot(p)-u),S<s&&(S=s,c=points[P]);var M=points.indexOf(a),C=points.indexOf(h),T=points.indexOf(l),q=points.indexOf(c),V=[[T,C,M],[C,q,M],[T,q,C],[M,q,T]];x.subVectors(h,a).normalize(),b.subVectors(l,a).normalize(),E.subVectors(c,a).normalize();E.dot((new THREE.Vector3).crossVectors(b,x))<0&&(V[0].reverse(),V[1].reverse(),V[2].reverse(),V[3].reverse());var F=points.slice();F.splice(F.indexOf(a),1),F.splice(F.indexOf(h),1),F.splice(F.indexOf(l),1),F.splice(F.indexOf(c),1);for(var P=V.length;P-- >0;)i(V[P],F,points),void 0!==V[P].visiblePoints&&A.push(V[P]),B.push(V[P]);t(points);for(var N=B.length;N-- >0;)e.faces[N]=new THREE.Face3(B[N][2],B[N][1],B[N][0],B[N].normal);return e.normalsNeedUpdate=!0,e}}()},{}],72:[function(t,e,i){e.exports={schema:{offset:{default:{x:0,y:0,z:0},type:"vec3"}},init:function(){this.active=!1,this.targetEl=null,this.fire=this.fire.bind(this),this.offset=new THREE.Vector3},update:function(){this.offset.copy(this.data.offset)},play:function(){this.el.addEventListener("click",this.fire)},pause:function(){this.el.removeEventListener("click",this.fire)},remove:function(){this.pause()},fire:function(){var t=this.el.sceneEl.querySelector("[checkpoint-controls]");if(!t)throw new Error("No `checkpoint-controls` component found.");t.components["checkpoint-controls"].setCheckpoint(this.el)},getOffset:function(){return this.offset.copy(this.data.offset)}}},{}],73:[function(t,e,i){e.exports={schema:{path:{default:""},extension:{default:"jpg"},format:{default:"RGBFormat"},enableBackground:{default:!1}},init:function(){var t=this.data;this.texture=(new THREE.CubeTextureLoader).load([t.path+"posx."+t.extension,t.path+"negx."+t.extension,t.path+"posy."+t.extension,t.path+"negy."+t.extension,t.path+"posz."+t.extension,t.path+"negz."+t.extension]),this.texture.format=THREE[t.format],t.enableBackground&&(this.el.sceneEl.object3D.background=this.texture),this.applyEnvMap(),this.el.addEventListener("object3dset",this.applyEnvMap.bind(this))},applyEnvMap:function(){var t=this.el.getObject3D("mesh"),e=this.texture;t&&t.traverse(function(t){t.material&&"envMap"in t.material&&(t.material.envMap=e,t.material.needsUpdate=!0)})}}},{}],74:[function(t,e,i){e.exports={init:function(){this.GRABBED_STATE="grabbed",this.grabbing=!1,this.hitEl=null,this.physics=this.el.sceneEl.systems.physics,this.constraint=null,this.onHit=this.onHit.bind(this),this.onGripOpen=this.onGripOpen.bind(this),this.onGripClose=this.onGripClose.bind(this)},play:function(){var t=this.el;t.addEventListener("hit",this.onHit),t.addEventListener("gripdown",this.onGripClose),t.addEventListener("gripup",this.onGripOpen),t.addEventListener("trackpaddown",this.onGripClose),t.addEventListener("trackpadup",this.onGripOpen),t.addEventListener("triggerdown",this.onGripClose),t.addEventListener("triggerup",this.onGripOpen)},pause:function(){var t=this.el;t.removeEventListener("hit",this.onHit),t.removeEventListener("gripdown",this.onGripClose),t.removeEventListener("gripup",this.onGripOpen),t.removeEventListener("trackpaddown",this.onGripClose),t.removeEventListener("trackpadup",this.onGripOpen),t.removeEventListener("triggerdown",this.onGripClose),t.removeEventListener("triggerup",this.onGripOpen)},onGripClose:function(t){this.grabbing=!0},onGripOpen:function(t){var e=this.hitEl;this.grabbing=!1,e&&(e.removeState(this.GRABBED_STATE),this.hitEl=void 0,this.physics.world.removeConstraint(this.constraint),this.constraint=null)},onHit:function(t){var e=t.detail.el;e&&!e.is(this.GRABBED_STATE)&&this.grabbing&&!this.hitEl&&(e.addState(this.GRABBED_STATE),this.hitEl=e,this.constraint=new CANNON.LockConstraint(this.el.body,e.body),this.physics.world.addConstraint(this.constraint))}}},{}],75:[function(t,e,i){var o=t("aframe-physics-system");e.exports={checkpoint:t("./checkpoint"),"cube-env-map":t("./cube-env-map"),grab:t("./grab"),"jump-ability":t("./jump-ability"),"kinematic-body":t("./kinematic-body"),"mesh-smooth":t("./mesh-smooth"),"sphere-collider":t("./sphere-collider"),"toggle-velocity":t("./toggle-velocity"),registerAll:function(t){this._registered||(t=t||window.AFRAME,o.registerAll(),t.components.checkpoint||t.registerComponent("checkpoint",this.checkpoint),t.components["cube-env-map"]||t.registerComponent("cube-env-map",this["cube-env-map"]),t.components.grab||t.registerComponent("grab",this.grab),t.components["jump-ability"]||t.registerComponent("jump-ability",this["jump-ability"]),t.components["kinematic-body"]||t.registerComponent("kinematic-body",this["kinematic-body"]),t.components["mesh-smooth"]||t.registerComponent("mesh-smooth",this["mesh-smooth"]),t.components["sphere-collider"]||t.registerComponent("sphere-collider",this["sphere-collider"]),t.components["toggle-velocity"]||t.registerComponent("toggle-velocity",this["toggle-velocity"]),this._registered=!0)}}},{"./checkpoint":72,"./cube-env-map":73,"./grab":74,"./jump-ability":76,"./kinematic-body":77,"./mesh-smooth":78,"./sphere-collider":79,"./toggle-velocity":80,"aframe-physics-system":2}],76:[function(t,e,i){e.exports={dependencies:["velocity"],schema:{on:{default:"keydown:Space gamepadbuttondown:0"},playerHeight:{default:1.764},maxJumps:{default:1},distance:{default:5},soundJump:{default:""},soundLand:{default:""},debug:{default:!1}},init:function(){this.velocity=0,this.numJumps=0;var t=this.beginJump.bind(this),e=this.data.on.split(" ");this.bindings={};for(var i=0;i<e.length;i++)this.bindings[e[i]]=t,this.el.addEventListener(e[i],t);this.bindings.collide=this.onCollide.bind(this),this.el.addEventListener("collide",this.bindings.collide)},remove:function(){for(var t in this.bindings)this.bindings.hasOwnProperty(t)&&(this.el.removeEventListener(t,this.bindings[t]),delete this.bindings[t]);this.el.removeEventListener("collide",this.bindings.collide),delete this.bindings.collide},beginJump:function(){if(this.numJumps<this.data.maxJumps){var t=this.data,e=Math.sqrt(-2*t.distance*-24.8),i=this.el.getAttribute("velocity");this.el.setAttribute("velocity",{x:i.x,y:e,z:i.z}),this.numJumps++}},onCollide:function(){this.numJumps=0}}},{}],77:[function(t,e,i){var o=window.CANNON;e.exports={dependencies:["velocity"],schema:{mass:{default:5},radius:{default:1.3},height:{default:1.764},linearDamping:{default:.05},enableSlopes:{default:!0}},init:function(){this.system=this.el.sceneEl.systems.physics,this.system.addBehavior(this,this.system.Phase.SIMULATE);var t=this.el,e=this.data,i=(new o.Vec3).copy(t.getAttribute("position"));this.body=new o.Body({material:this.system.material,position:i,mass:e.mass,linearDamping:e.linearDamping,fixedRotation:!0}),this.body.addShape(new o.Sphere(e.radius),new o.Vec3(0,e.radius-e.height,0)),this.body.el=this.el,this.el.body=this.body,this.system.addBody(this.body)},remove:function(){this.system.removeBody(this.body),this.system.removeBehavior(this,this.system.Phase.SIMULATE),delete this.el.body},step:function(){var t=new THREE.Vector3,e=new THREE.Vector3,i=new THREE.Vector3,o=new THREE.Vector3;return function(n,s){if(s){var r,a,h=this.body,l=this.data,c=-1/0;s=Math.min(s,1e3*this.system.data.maxInterval),o.set(0,0,0),t.copy(this.el.getAttribute("velocity")),h.velocity.copy(t),h.position.copy(this.el.getAttribute("position"));for(var p,u=0;p=this.system.world.contacts[u];u++)if(p.enabled){if(h.id===p.bi.id)p.ni.negate(i);else{if(h.id!==p.bj.id)continue;i.copy(p.ni)}h.velocity.dot(i)<-1e-6&&i.y<=.5?t=t.projectOnPlane(i):i.y>.5&&(r=h.id===p.bi.id?Math.abs(p.rj.y+p.bj.position.y):Math.abs(p.ri.y+p.bi.position.y))>c&&(c=r,o.copy(i),a=h.id===p.bi.id?p.bj:p.bi)}if(e.copy(t).normalize(),a&&e.y<.5?(l.enableSlopes?o.y<1-1e-6&&o.copy(this.raycastToGround(a,o)):o.set(0,1,0),t=t.projectOnPlane(o)):t.add(this.system.world.gravity.scale(4*s/1e3)),a&&a.el&&a.el.components.velocity){var d=a.el.getAttribute("velocity");h.position.copy({x:h.position.x+d.x*s/1e3,y:h.position.y+d.y*s/1e3,z:h.position.z+d.z*s/1e3}),this.el.setAttribute("position",h.position)}h.velocity.copy(t),this.el.setAttribute("velocity",t)}}}(),raycastToGround:function(t,e){var i,n,s=this.body.position,r=this.body.position.clone();return r.y-=this.data.height,(i=new o.Ray(s,r))._updateDirection(),i.intersectBody(t),i.hasHit?(n=i.result.hitNormalWorld,Math.abs(n.y)>Math.abs(e.y)?n:e):e}}},{}],78:[function(t,e,i){e.exports={init:function(){this.el.addEventListener("model-loaded",function(t){t.detail.model.traverse(function(t){t.isMesh&&t.geometry.computeVertexNormals()})})}}},{}],79:[function(t,e,i){e.exports={schema:{objects:{default:""},state:{default:"collided"},radius:{default:.05},watch:{default:!0}},init:function(){this.observer=null,this.els=[],this.collisions=[],this.handleHit=this.handleHit.bind(this),this.handleHitEnd=this.handleHitEnd.bind(this)},remove:function(){this.pause()},play:function(){var t=this.el.sceneEl;this.data.watch&&(this.observer=new MutationObserver(this.update.bind(this,null)),this.observer.observe(t,{childList:!0,subtree:!0}))},pause:function(){this.observer&&(this.observer.disconnect(),this.observer=null)},update:function(){var t,e=this.data;t=e.objects?this.el.sceneEl.querySelectorAll(e.objects):this.el.sceneEl.children,this.els=Array.prototype.slice.call(t)},tick:function(){var t=new THREE.Vector3,e=new THREE.Vector3,i=(new THREE.Vector3,new THREE.Vector3),o=new Map;return function(){var n,s=this.el,r=this.data,a=[];s.getObject3D("mesh")&&(o.clear(),t.copy(s.object3D.getWorldPosition()),s.object3D.getWorldScale(i),n=r.radius*function(t){return Math.max.apply(null,t.toArray())}(i),this.els.forEach(function(i){var s,r,h,l,c,p;i.isEntity&&(r=i.getObject3D("mesh"))&&(p=(l=(new THREE.Box3).setFromObject(r)).getSize(),c=Math.max(p.x,p.y,p.z)/2,s=Math.sqrt(2*c*c),l.getCenter(e),s&&(h=t.distanceTo(e))<s+n&&(a.push(i),o.set(i,h)))}),a.sort(function(t,e){return o.get(t)>o.get(e)?1:-1}).forEach(this.handleHit),0===a.length&&s.emit("hit",{el:null}),this.collisions.filter(function(t){return!o.has(t)}).forEach(this.handleHitEnd),this.collisions=a)}}(),handleHit:function(t){t.emit("hit"),t.addState(this.data.state),this.el.emit("hit",{el:t})},handleHitEnd:function(t){t.emit("hitend"),t.removeState(this.data.state),this.el.emit("hitend",{el:t})}}},{}],80:[function(t,e,i){e.exports={dependencies:["velocity"],schema:{axis:{default:"x",oneOf:["x","y","z"]},min:{default:0},max:{default:0},speed:{default:1}},init:function(){var t={x:0,y:0,z:0};t[this.data.axis]=this.data.speed,this.el.setAttribute("velocity",t),this.el.sceneEl.addBehavior&&this.el.sceneEl.addBehavior(this)},remove:function(){},update:function(){this.tick()},tick:function(){var t=this.data,e=this.el.getAttribute("velocity"),i=this.el.getAttribute("position");e[t.axis]>0&&i[t.axis]>t.max?(e[t.axis]=-t.speed,this.el.setAttribute("velocity",e)):e[t.axis]<0&&i[t.axis]<t.min&&(e[t.axis]=t.speed,this.el.setAttribute("velocity",e))}}},{}]},{},[1]);
|