1 |
- !function t(e,o,i){function n(r,a){if(!o[r]){if(!e[r]){var c="function"==typeof require&&require;if(!a&&c)return c(r,!0);if(s)return s(r,!0);var h=new Error("Cannot find module '"+r+"'");throw h.code="MODULE_NOT_FOUND",h}var l=o[r]={exports:{}};e[r][0].call(l.exports,function(t){var o=e[r][1][t];return n(o||t)},l,l.exports,t,e,o,i)}return o[r].exports}for(var s="function"==typeof require&&require,r=0;r<i.length;r++)n(i[r]);return n}({1:[function(t,e,o){t("./src/controls").registerAll()},{"./src/controls":78}],2:[function(t,e,o){e.exports=Object.assign(function(){},{FACE_1:0,FACE_2:1,FACE_3:2,FACE_4:3,L_SHOULDER_1:4,R_SHOULDER_1:5,L_SHOULDER_2:6,R_SHOULDER_2:7,SELECT:8,START:9,DPAD_UP:12,DPAD_DOWN:13,DPAD_LEFT:14,DPAD_RIGHT:15,VENDOR:16})},{}],3:[function(t,e,o){e.exports=function(t,e,o){this.type=t,this.index=e,this.pressed=o.pressed,this.value=o.value}},{}],4:[function(t,e,o){!function(t){function e(t,e){return-1!==String(t).indexOf(e)}function o(t,e,o){u!==e&&l!==e&&h!==e||Object.keys(o).forEach(function(e){t[e]=o[e]})}function i(t){var e="keyCode"in t?t.keyCode:"which"in t?t.which:0,o=function(){if(w||"keyLocation"in t){var o=w?t.location:t.keyLocation;if(o&&e in y[o])return y[o][e]}return"keyIdentifier"in t&&t.keyIdentifier in d?d[t.keyIdentifier]:e in p?p[e]:null}();if(!o)return null;var i=function(){var e=v[o.code];return e?t.shiftKey&&"shiftKey"in e?e.shiftKey:e.key:o.code}();return{code:o.code,key:i,location:o.location,keyCap:o.keyCap}}var n="KeyboardEvent"in t;n||(t.KeyboardEvent=function(){throw TypeError("Illegal constructor")}),t.KeyboardEvent.DOM_KEY_LOCATION_STANDARD=0,t.KeyboardEvent.DOM_KEY_LOCATION_LEFT=1,t.KeyboardEvent.DOM_KEY_LOCATION_RIGHT=2,t.KeyboardEvent.DOM_KEY_LOCATION_NUMPAD=3;var s=window.KeyboardEvent.DOM_KEY_LOCATION_STANDARD,r=window.KeyboardEvent.DOM_KEY_LOCATION_LEFT,a=window.KeyboardEvent.DOM_KEY_LOCATION_RIGHT,c=window.KeyboardEvent.DOM_KEY_LOCATION_NUMPAD,h=e(navigator.platform,"Win")?"win":e(navigator.platform,"Mac")?"mac":e(navigator.platform,"CrOS")?"cros":e(navigator.platform,"Linux")?"linux":e(navigator.userAgent,"iPad")||e(navigator.platform,"iPod")||e(navigator.platform,"iPhone")?"ios":"",l=e(navigator.userAgent,"Chrome/")?"chrome":e(navigator.vendor,"Apple")?"safari":e(navigator.userAgent,"MSIE")?"ie":e(navigator.userAgent,"Gecko/")?"moz":e(navigator.userAgent,"Opera/")?"opera":"",u=l+"-"+h,p={3:{code:"Cancel"},6:{code:"Help"},8:{code:"Backspace"},9:{code:"Tab"},12:{code:"Clear"},13:{code:"Enter"},16:{code:"Shift"},17:{code:"Control"},18:{code:"Alt"},19:{code:"Pause"},20:{code:"CapsLock"},21:{code:"KanaMode"},22:{code:"HangulMode"},23:{code:"JunjaMode"},24:{code:"FinalMode"},25:{code:"KanjiMode"},27:{code:"Escape"},28:{code:"Convert"},29:{code:"NonConvert"},30:{code:"Accept"},31:{code:"ModeChange"},32:{code:"Space"},33:{code:"PageUp"},34:{code:"PageDown"},35:{code:"End"},36:{code:"Home"},37:{code:"ArrowLeft"},38:{code:"ArrowUp"},39:{code:"ArrowRight"},40:{code:"ArrowDown"},41:{code:"Select"},42:{code:"Print"},43:{code:"Execute"},44:{code:"PrintScreen"},45:{code:"Insert"},46:{code:"Delete"},47:{code:"Help"},48:{code:"Digit0",keyCap:"0"},49:{code:"Digit1",keyCap:"1"},50:{code:"Digit2",keyCap:"2"},51:{code:"Digit3",keyCap:"3"},52:{code:"Digit4",keyCap:"4"},53:{code:"Digit5",keyCap:"5"},54:{code:"Digit6",keyCap:"6"},55:{code:"Digit7",keyCap:"7"},56:{code:"Digit8",keyCap:"8"},57:{code:"Digit9",keyCap:"9"},65:{code:"KeyA",keyCap:"a"},66:{code:"KeyB",keyCap:"b"},67:{code:"KeyC",keyCap:"c"},68:{code:"KeyD",keyCap:"d"},69:{code:"KeyE",keyCap:"e"},70:{code:"KeyF",keyCap:"f"},71:{code:"KeyG",keyCap:"g"},72:{code:"KeyH",keyCap:"h"},73:{code:"KeyI",keyCap:"i"},74:{code:"KeyJ",keyCap:"j"},75:{code:"KeyK",keyCap:"k"},76:{code:"KeyL",keyCap:"l"},77:{code:"KeyM",keyCap:"m"},78:{code:"KeyN",keyCap:"n"},79:{code:"KeyO",keyCap:"o"},80:{code:"KeyP",keyCap:"p"},81:{code:"KeyQ",keyCap:"q"},82:{code:"KeyR",keyCap:"r"},83:{code:"KeyS",keyCap:"s"},84:{code:"KeyT",keyCap:"t"},85:{code:"KeyU",keyCap:"u"},86:{code:"KeyV",keyCap:"v"},87:{code:"KeyW",keyCap:"w"},88:{code:"KeyX",keyCap:"x"},89:{code:"KeyY",keyCap:"y"},90:{code:"KeyZ",keyCap:"z"},91:{code:"OSLeft",location:r},92:{code:"OSRight",location:a},93:{code:"ContextMenu"},95:{code:"Standby"},96:{code:"Numpad0",keyCap:"0",location:c},97:{code:"Numpad1",keyCap:"1",location:c},98:{code:"Numpad2",keyCap:"2",location:c},99:{code:"Numpad3",keyCap:"3",location:c},100:{code:"Numpad4",keyCap:"4",location:c},101:{code:"Numpad5",keyCap:"5",location:c},102:{code:"Numpad6",keyCap:"6",location:c},103:{code:"Numpad7",keyCap:"7",location:c},104:{code:"Numpad8",keyCap:"8",location:c},105:{code:"Numpad9",keyCap:"9",location:c},106:{code:"NumpadMultiply",keyCap:"*",location:c},107:{code:"NumpadAdd",keyCap:"+",location:c},108:{code:"NumpadComma",keyCap:",",location:c},109:{code:"NumpadSubtract",keyCap:"-",location:c},110:{code:"NumpadDecimal",keyCap:".",location:c},111:{code:"NumpadDivide",keyCap:"/",location:c},112:{code:"F1"},113:{code:"F2"},114:{code:"F3"},115:{code:"F4"},116:{code:"F5"},117:{code:"F6"},118:{code:"F7"},119:{code:"F8"},120:{code:"F9"},121:{code:"F10"},122:{code:"F11"},123:{code:"F12"},124:{code:"F13"},125:{code:"F14"},126:{code:"F15"},127:{code:"F16"},128:{code:"F17"},129:{code:"F18"},130:{code:"F19"},131:{code:"F20"},132:{code:"F21"},133:{code:"F22"},134:{code:"F23"},135:{code:"F24"},144:{code:"NumLock",location:c},145:{code:"ScrollLock"},160:{code:"ShiftLeft",location:r},161:{code:"ShiftRight",location:a},162:{code:"ControlLeft",location:r},163:{code:"ControlRight",location:a},164:{code:"AltLeft",location:r},165:{code:"AltRight",location:a},166:{code:"BrowserBack"},167:{code:"BrowserForward"},168:{code:"BrowserRefresh"},169:{code:"BrowserStop"},170:{code:"BrowserSearch"},171:{code:"BrowserFavorites"},172:{code:"BrowserHome"},173:{code:"VolumeMute"},174:{code:"VolumeDown"},175:{code:"VolumeUp"},176:{code:"MediaTrackNext"},177:{code:"MediaTrackPrevious"},178:{code:"MediaStop"},179:{code:"MediaPlayPause"},180:{code:"LaunchMail"},181:{code:"MediaSelect"},182:{code:"LaunchApp1"},183:{code:"LaunchApp2"},186:{code:"Semicolon",keyCap:";"},187:{code:"Equal",keyCap:"="},188:{code:"Comma",keyCap:","},189:{code:"Minus",keyCap:"-"},190:{code:"Period",keyCap:"."},191:{code:"Slash",keyCap:"/"},192:{code:"Backquote",keyCap:"`"},219:{code:"BracketLeft",keyCap:"["},220:{code:"Backslash",keyCap:"\\"},221:{code:"BracketRight",keyCap:"]"},222:{code:"Quote",keyCap:"'"},226:{code:"IntlBackslash",keyCap:"\\"},229:{code:"Process"},246:{code:"Attn"},247:{code:"CrSel"},248:{code:"ExSel"},249:{code:"EraseEof"},250:{code:"Play"},251:{code:"ZoomToggle"},254:{code:"Clear"}};o(p,"moz",{59:{code:"Semicolon",keyCap:";"},61:{code:"Equal",keyCap:"="},107:{code:"Equal",keyCap:"="},109:{code:"Minus",keyCap:"-"},187:{code:"NumpadAdd",keyCap:"+",location:c},189:{code:"NumpadSubtract",keyCap:"-",location:c}}),o(p,"moz-mac",{12:{code:"NumLock",location:c},173:{code:"Minus",keyCap:"-"}}),o(p,"moz-win",{173:{code:"Minus",keyCap:"-"}}),o(p,"chrome-mac",{93:{code:"OSRight",location:a}}),o(p,"safari",{3:{code:"Enter"},25:{code:"Tab"}}),o(p,"ios",{10:{code:"Enter",location:s}}),o(p,"safari-mac",{91:{code:"OSLeft",location:r},93:{code:"OSRight",location:a},229:{code:"KeyQ",keyCap:"Q"}});var d={};"cros"===h&&(d["U+00A0"]={code:"ShiftLeft",location:r},d["U+00A1"]={code:"ShiftRight",location:a},d["U+00A2"]={code:"ControlLeft",location:r},d["U+00A3"]={code:"ControlRight",location:a},d["U+00A4"]={code:"AltLeft",location:r},d["U+00A5"]={code:"AltRight",location:a}),"chrome-mac"===u&&(d["U+0010"]={code:"ContextMenu"}),"safari-mac"===u&&(d["U+0010"]={code:"ContextMenu"}),"ios"===h&&(d["U+0010"]={code:"Function"},d["U+001C"]={code:"ArrowLeft"},d["U+001D"]={code:"ArrowRight"},d["U+001E"]={code:"ArrowUp"},d["U+001F"]={code:"ArrowDown"},d["U+0001"]={code:"Home"},d["U+0004"]={code:"End"},d["U+000B"]={code:"PageUp"},d["U+000C"]={code:"PageDown"});var y=[];y[r]={16:{code:"ShiftLeft",location:r},17:{code:"ControlLeft",location:r},18:{code:"AltLeft",location:r}},y[a]={16:{code:"ShiftRight",location:a},17:{code:"ControlRight",location:a},18:{code:"AltRight",location:a}},y[c]={13:{code:"NumpadEnter",location:c}},o(y[c],"moz",{109:{code:"NumpadSubtract",location:c},107:{code:"NumpadAdd",location:c}}),o(y[r],"moz-mac",{224:{code:"OSLeft",location:r}}),o(y[a],"moz-mac",{224:{code:"OSRight",location:a}}),o(y[a],"moz-win",{91:{code:"OSRight",location:a}}),o(y[a],"mac",{93:{code:"OSRight",location:a}}),o(y[c],"chrome-mac",{12:{code:"NumLock",location:c}}),o(y[c],"safari-mac",{12:{code:"NumLock",location:c},187:{code:"NumpadAdd",location:c},189:{code:"NumpadSubtract",location:c},190:{code:"NumpadDecimal",location:c},191:{code:"NumpadDivide",location:c}});var v={ShiftLeft:{key:"Shift"},ShiftRight:{key:"Shift"},ControlLeft:{key:"Control"},ControlRight:{key:"Control"},AltLeft:{key:"Alt"},AltRight:{key:"Alt"},OSLeft:{key:"OS"},OSRight:{key:"OS"},NumpadEnter:{key:"Enter"},Space:{key:" "},Digit0:{key:"0",shiftKey:")"},Digit1:{key:"1",shiftKey:"!"},Digit2:{key:"2",shiftKey:"@"},Digit3:{key:"3",shiftKey:"#"},Digit4:{key:"4",shiftKey:"$"},Digit5:{key:"5",shiftKey:"%"},Digit6:{key:"6",shiftKey:"^"},Digit7:{key:"7",shiftKey:"&"},Digit8:{key:"8",shiftKey:"*"},Digit9:{key:"9",shiftKey:"("},KeyA:{key:"a",shiftKey:"A"},KeyB:{key:"b",shiftKey:"B"},KeyC:{key:"c",shiftKey:"C"},KeyD:{key:"d",shiftKey:"D"},KeyE:{key:"e",shiftKey:"E"},KeyF:{key:"f",shiftKey:"F"},KeyG:{key:"g",shiftKey:"G"},KeyH:{key:"h",shiftKey:"H"},KeyI:{key:"i",shiftKey:"I"},KeyJ:{key:"j",shiftKey:"J"},KeyK:{key:"k",shiftKey:"K"},KeyL:{key:"l",shiftKey:"L"},KeyM:{key:"m",shiftKey:"M"},KeyN:{key:"n",shiftKey:"N"},KeyO:{key:"o",shiftKey:"O"},KeyP:{key:"p",shiftKey:"P"},KeyQ:{key:"q",shiftKey:"Q"},KeyR:{key:"r",shiftKey:"R"},KeyS:{key:"s",shiftKey:"S"},KeyT:{key:"t",shiftKey:"T"},KeyU:{key:"u",shiftKey:"U"},KeyV:{key:"v",shiftKey:"V"},KeyW:{key:"w",shiftKey:"W"},KeyX:{key:"x",shiftKey:"X"},KeyY:{key:"y",shiftKey:"Y"},KeyZ:{key:"z",shiftKey:"Z"},Numpad0:{key:"0"},Numpad1:{key:"1"},Numpad2:{key:"2"},Numpad3:{key:"3"},Numpad4:{key:"4"},Numpad5:{key:"5"},Numpad6:{key:"6"},Numpad7:{key:"7"},Numpad8:{key:"8"},Numpad9:{key:"9"},NumpadMultiply:{key:"*"},NumpadAdd:{key:"+"},NumpadComma:{key:","},NumpadSubtract:{key:"-"},NumpadDecimal:{key:"."},NumpadDivide:{key:"/"},Semicolon:{key:";",shiftKey:":"},Equal:{key:"=",shiftKey:"+"},Comma:{key:",",shiftKey:"<"},Minus:{key:"-",shiftKey:"_"},Period:{key:".",shiftKey:">"},Slash:{key:"/",shiftKey:"?"},Backquote:{key:"`",shiftKey:"~"},BracketLeft:{key:"[",shiftKey:"{"},Backslash:{key:"\\",shiftKey:"|"},BracketRight:{key:"]",shiftKey:"}"},Quote:{key:"'",shiftKey:'"'},IntlBackslash:{key:"\\",shiftKey:"|"}};o(v,"mac",{OSLeft:{key:"Meta"},OSRight:{key:"Meta"}});var f={Esc:"Escape",Nonconvert:"NonConvert",Left:"ArrowLeft",Up:"ArrowUp",Right:"ArrowRight",Down:"ArrowDown",Del:"Delete",Menu:"ContextMenu",MediaNextTrack:"MediaTrackNext",MediaPreviousTrack:"MediaTrackPrevious",SelectMedia:"MediaSelect",HalfWidth:"Hankaku",FullWidth:"Zenkaku",RomanCharacters:"Romaji",Crsel:"CrSel",Exsel:"ExSel",Zoom:"ZoomToggle"},m=function(t,e){var o={};return Object.keys(t).forEach(function(i){var n=t[i];e in n&&(o[n[e]]=n)}),o}(p,"code");try{var w=n&&"location"in new KeyboardEvent("")}catch(t){}"KeyboardEvent"in t&&"defineProperty"in Object&&function(){function t(t,e,o){e in t||Object.defineProperty(t,e,o)}if(t(KeyboardEvent.prototype,"code",{get:function(){var t=i(this);return t?t.code:""}}),"key"in KeyboardEvent.prototype){var e=Object.getOwnPropertyDescriptor(KeyboardEvent.prototype,"key");Object.defineProperty(KeyboardEvent.prototype,"key",{get:function(){var t=e.get.call(this);return f.hasOwnProperty(t)?f[t]:t}})}t(KeyboardEvent.prototype,"key",{get:function(){var t=i(this);return t&&"key"in t?t.key:"Unidentified"}}),t(KeyboardEvent.prototype,"location",{get:function(){var t=i(this);return t&&"location"in t?t.location:s}}),t(KeyboardEvent.prototype,"locale",{get:function(){return""}})}(),"queryKeyCap"in t.KeyboardEvent||(t.KeyboardEvent.queryKeyCap=function(t,e){if(t=String(t),!m.hasOwnProperty(t))return"Undefined";if(e&&"en-us"!==String(e).toLowerCase())throw Error("Unsupported locale");var o=m[t];return o.keyCap||o.code||"Undefined"}),t.identifyKey=function(t){if(!("code"in t)){var e=i(t);t.code=e?e.code:"",t.key=e&&"key"in e?e.key:"Unidentified",t.location="location"in t?t.location:"keyLocation"in t?t.keyLocation:e&&"location"in e?e.location:s,t.locale=""}}}(window)},{}],5:[function(t,e,o){var i=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||i},{"./src/components/body/dynamic-body":8,"./src/components/body/static-body":9,"./src/components/constraint":10,"./src/components/math":11,"./src/system/physics":15,cannon:17}],6:[function(t,e,o){var i=t("cannon");i.shape2mesh=function(t){for(var e=new THREE.Object3D,o=0;o<t.shapes.length;o++){var n,s=t.shapes[o];switch(s.type){case i.Shape.types.SPHERE:var r=new THREE.SphereGeometry(s.radius,8,8);n=new THREE.Mesh(r,this.currentMaterial);break;case i.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 i.Shape.types.PLANE:g=new THREE.PlaneGeometry(10,10,4,4);n=new THREE.Object3D;var c=new THREE.Object3D,h=new THREE.Mesh(g,this.currentMaterial);h.scale.set(100,100,100),c.add(h),h.castShadow=!0,h.receiveShadow=!0,n.add(c);break;case i.Shape.types.BOX:var l=new THREE.BoxGeometry(2*s.halfExtents.x,2*s.halfExtents.y,2*s.halfExtents.z);n=new THREE.Mesh(l,this.currentMaterial);break;case i.Shape.types.CONVEXPOLYHEDRON:for(var u=new THREE.Geometry,p=0;p<s.vertices.length;p++){var d=s.vertices[p];u.vertices.push(new THREE.Vector3(d.x,d.y,d.z))}for(p=0;p<s.faces.length;p++)for(var y=s.faces[p],v=y[0],f=1;f<y.length-1;f++){var m=y[f],w=y[f+1];u.faces.push(new THREE.Face3(v,m,w))}u.computeBoundingSphere(),u.computeFaceNormals(),n=new THREE.Mesh(u,this.currentMaterial);break;case i.Shape.types.HEIGHTFIELD:for(var g=new THREE.Geometry,x=new i.Vec3,b=new i.Vec3,E=new i.Vec3,A=0;A<s.data.length-1;A++)for(var B=0;B<s.data[A].length-1;B++)for(var C=0;C<2;C++){s.getConvexTrianglePillar(A,B,0===C),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));p=g.vertices.length-3;g.faces.push(new THREE.Face3(p,p+1,p+2))}g.computeBoundingSphere(),g.computeFaceNormals(),n=new THREE.Mesh(g,this.currentMaterial);break;case i.Shape.types.TRIMESH:for(var g=new THREE.Geometry,x=new i.Vec3,b=new i.Vec3,E=new i.Vec3,p=0;p<s.indices.length/3;p++){s.getTriangleVertices(p,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(p=0;p<n.children.length;p++)if(n.children[p].castShadow=!0,n.children[p].receiveShadow=!0,n.children[p])for(f=0;f<n.children[p].length;f++)n.children[p].children[f].castShadow=!0,n.children[p].children[f].receiveShadow=!0;var S=t.shapeOffsets[o],R=t.shapeOrientations[o];n.position.set(S.x,S.y,S.z),n.quaternion.set(R.x,R.y,R.z,R.w),e.add(n)}return e},e.exports=i.shape2mesh},{cannon:17}],7:[function(t,e,o){var i=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,o=this.data,s=e.getAttribute("position");if(this.body=new i.Body({mass:o.mass||0,material:this.system.material,position:new i.Vec3(s.x,s.y,s.z),linearDamping:o.linearDamping,angularDamping:o.angularDamping}),this.el.object3D.updateMatrixWorld(!0),"none"!==o.shape){var r="auto"===o.shape?void 0:AFRAME.utils.extend({},this.data,{type:n.Type[o.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 o=e.offset,n=e.orientation,s=i.shape2mesh(t).children[0];this.wireframe=new THREE.LineSegments(new THREE.EdgesGeometry(s.geometry),new THREE.LineBasicMaterial({color:16711680})),o&&(this.wireframe.offset=o.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 o=this.el,i=o.parentEl,n=this.body;n&&(o.components.velocity&&n.velocity.copy(o.getAttribute("velocity")),i.isScene?(n.quaternion.copy(o.object3D.quaternion),n.position.copy(o.object3D.position)):(o.object3D.getWorldQuaternion(t),n.quaternion.copy(t),o.object3D.getWorldPosition(e),n.position.copy(e)),this.wireframe&&this.syncWireframe())}}(),syncFromPhysics:function(){var t=new THREE.Vector3,e=new THREE.Quaternion,o=new THREE.Quaternion;return function(){var i=this.el,n=i.parentEl,s=this.body;s&&(n.isScene?(i.setAttribute("quaternion",s.quaternion),i.setAttribute("position",s.position)):(e.copy(s.quaternion),n.object3D.getWorldQuaternion(o),e.multiply(o.inverse()),i.setAttribute("quaternion",{x:e.x,y:e.y,z:e.z,w:e.w}),t.copy(s.position),n.object3D.worldToLocal(t),i.setAttribute("position",{x:t.x,y:t.y,z:t.z})),this.wireframe&&this.syncWireframe())}}()}},{"../../../lib/CANNON-shape2mesh":6,cannon:17,"three-to-cannon":73}],8:[function(t,e,o){var i=t("./body");e.exports=AFRAME.utils.extend({},i,{dependencies:["quaternion","velocity"],schema:AFRAME.utils.extend({},i.schema,{mass:{default:5},linearDamping:{default:.01},angularDamping:{default:.01}}),step:function(){this.syncFromPhysics()}})},{"./body":7}],9:[function(t,e,o){var i=t("./body");e.exports=AFRAME.utils.extend({},i,{step:function(){this.syncToPhysics()}})},{"./body":7}],10:[function(t,e,o){var i=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,o=new i.Vec3(e.pivot.x,e.pivot.y,e.pivot.z),n=new i.Vec3(e.targetPivot.x,e.targetPivot.y,e.targetPivot.z),s=new i.Vec3(e.axis.x,e.axis.y,e.axis.z),r=new i.Vec3(e.targetAxis.x,e.targetAxis.y,e.targetAxis.z);switch(e.type){case"lock":t=new i.LockConstraint(this.el.body,e.target.body,{maxForce:e.maxForce});break;case"distance":t=new i.DistanceConstraint(this.el.body,e.target.body,e.distance,e.maxForce);break;case"hinge":t=new i.HingeConstraint(this.el.body,e.target.body,{pivotA:o,pivotB:n,axisA:s,axisB:r,maxForce:e.maxForce});break;case"coneTwist":t=new i.ConeTwistConstraint(this.el.body,e.target.body,{pivotA:o,pivotB:n,axisA:s,axisB:r,maxForce:e.maxForce});break;case"pointToPoint":t=new i.PointToPointConstraint(this.el.body,o,e.target.body,n,e.maxForce);break;default:throw new Error("[constraint] Unexpected type: "+e.type)}return t.collideConnected=e.collideConnected,t}}},{cannon:17}],11:[function(t,e,o){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":12,"./velocity":13}],12:[function(t,e,o){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)}}},{}],13:[function(t,e,o){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 o=this.el.sceneEl.systems.physics||{data:{maxInterval:1/60}},i=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*o.data.maxInterval),this.el.setAttribute("position",{x:n.x+i.x*e/1e3,y:n.y+i.y*e/1e3,z:n.z+i.z*e/1e3})}}}},{}],14:[function(t,e,o){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}}},{}],15:[function(t,e,o){var i=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 i.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 i.NaiveBroadphase,this.material=new i.Material({name:"defaultMaterial"}),this.contactMaterial=new i.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 o;for(o=0;o<this.children[this.Phase.SIMULATE].length;o++)this.children[this.Phase.SIMULATE][o].step(t,e);for(o=0;o<this.children[this.Phase.RENDER].length;o++)this.children[this.Phase.RENDER][o].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":14,cannon:17}],16:[function(t,e,o){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"}},{}],17:[function(t,e,o){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":16,"./collision/AABB":18,"./collision/ArrayCollisionMatrix":19,"./collision/Broadphase":20,"./collision/GridBroadphase":21,"./collision/NaiveBroadphase":22,"./collision/ObjectCollisionMatrix":23,"./collision/Ray":25,"./collision/RaycastResult":26,"./collision/SAPBroadphase":27,"./constraints/ConeTwistConstraint":28,"./constraints/Constraint":29,"./constraints/DistanceConstraint":30,"./constraints/HingeConstraint":31,"./constraints/LockConstraint":32,"./constraints/PointToPointConstraint":33,"./equations/ContactEquation":35,"./equations/Equation":36,"./equations/FrictionEquation":37,"./equations/RotationalEquation":38,"./equations/RotationalMotorEquation":39,"./material/ContactMaterial":40,"./material/Material":41,"./math/Mat3":43,"./math/Quaternion":44,"./math/Transform":45,"./math/Vec3":46,"./objects/Body":47,"./objects/RaycastVehicle":48,"./objects/RigidVehicle":49,"./objects/SPHSystem":50,"./objects/Spring":51,"./shapes/Box":53,"./shapes/ConvexPolyhedron":54,"./shapes/Cylinder":55,"./shapes/Heightfield":56,"./shapes/Particle":57,"./shapes/Plane":58,"./shapes/Shape":59,"./shapes/Sphere":60,"./shapes/Trimesh":61,"./solver/GSSolver":62,"./solver/Solver":63,"./solver/SplitSolver":64,"./utils/EventTarget":65,"./utils/Pool":67,"./utils/Vec3Pool":70,"./world/Narrowphase":71,"./world/World":72}],18:[function(t,e,o){function i(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=i;var s=new n;i.prototype.setFromPoints=function(t,e,o,i){var n=this.lowerBound,r=this.upperBound,a=o;n.copy(t[0]),a&&a.vmult(n,n),r.copy(n);for(var c=1;c<t.length;c++){var h=t[c];a&&(a.vmult(h,s),h=s),h.x>r.x&&(r.x=h.x),h.x<n.x&&(n.x=h.x),h.y>r.y&&(r.y=h.y),h.y<n.y&&(n.y=h.y),h.z>r.z&&(r.z=h.z),h.z<n.z&&(n.z=h.z)}return e&&(e.vadd(n,n),e.vadd(r,r)),i&&(n.x-=i,n.y-=i,n.z-=i,r.x+=i,r.y+=i,r.z+=i),this},i.prototype.copy=function(t){return this.lowerBound.copy(t.lowerBound),this.upperBound.copy(t.upperBound),this},i.prototype.clone=function(){return(new i).copy(this)},i.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)},i.prototype.overlaps=function(t){var e=this.lowerBound,o=this.upperBound,i=t.lowerBound,n=t.upperBound,s=i.x<=o.x&&o.x<=n.x||e.x<=n.x&&n.x<=o.x,r=i.y<=o.y&&o.y<=n.y||e.y<=n.y&&n.y<=o.y,a=i.z<=o.z&&o.z<=n.z||e.z<=n.z&&n.z<=o.z;return s&&r&&a},i.prototype.volume=function(){var t=this.lowerBound,e=this.upperBound;return(e.x-t.x)*(e.y-t.y)*(e.z-t.z)},i.prototype.contains=function(t){var e=this.lowerBound,o=this.upperBound,i=t.lowerBound,n=t.upperBound;return e.x<=i.x&&o.x>=n.x&&e.y<=i.y&&o.y>=n.y&&e.z<=i.z&&o.z>=n.z},i.prototype.getCorners=function(t,e,o,i,n,s,r,a){var c=this.lowerBound,h=this.upperBound;t.copy(c),e.set(h.x,c.y,c.z),o.set(h.x,h.y,c.z),i.set(c.x,h.y,h.z),n.set(h.x,c.y,c.z),s.set(c.x,h.y,c.z),r.set(c.x,c.y,h.z),a.copy(h)};var r=[new n,new n,new n,new n,new n,new n,new n,new n];i.prototype.toLocalFrame=function(t,e){var o=r,i=o[0],n=o[1],s=o[2],a=o[3],c=o[4],h=o[5],l=o[6],u=o[7];this.getCorners(i,n,s,a,c,h,l,u);for(var p=0;8!==p;p++){var d=o[p];t.pointToLocal(d,d)}return e.setFromPoints(o)},i.prototype.toWorldFrame=function(t,e){var o=r,i=o[0],n=o[1],s=o[2],a=o[3],c=o[4],h=o[5],l=o[6],u=o[7];this.getCorners(i,n,s,a,c,h,l,u);for(var p=0;8!==p;p++){var d=o[p];t.pointToWorld(d,d)}return e.setFromPoints(o)},i.prototype.overlapsRay=function(t){var e=1/t._direction.x,o=1/t._direction.y,i=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)*o,a=(this.upperBound.y-t.from.y)*o,c=(this.lowerBound.z-t.from.z)*i,h=(this.upperBound.z-t.from.z)*i,l=Math.max(Math.max(Math.min(n,s),Math.min(r,a)),Math.min(c,h)),u=Math.min(Math.min(Math.max(n,s),Math.max(r,a)),Math.max(c,h));return!(u<0)&&!(l>u)}},{"../math/Vec3":46,"../utils/Utils":69}],19:[function(t,e,o){function i(){this.matrix=[]}e.exports=i,i.prototype.get=function(t,e){if(t=t.index,(e=e.index)>t){var o=e;e=t,t=o}return this.matrix[(t*(t+1)>>1)+e-1]},i.prototype.set=function(t,e,o){if(t=t.index,(e=e.index)>t){var i=e;e=t,t=i}this.matrix[(t*(t+1)>>1)+e-1]=o?1:0},i.prototype.reset=function(){for(var t=0,e=this.matrix.length;t!==e;t++)this.matrix[t]=0},i.prototype.setNumObjects=function(t){this.matrix.length=t*(t-1)>>1}},{}],20:[function(t,e,o){function i(){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=i,i.prototype.collisionPairs=function(t,e,o){throw new Error("collisionPairs not implemented for this BroadPhase class!")},i.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)},i.prototype.intersectionTest=function(t,e,o,i){this.useBoundingBoxes?this.doBoundingBoxBroadphase(t,e,o,i):this.doBoundingSphereBroadphase(t,e,o,i)};var a=new s;new s,new r,new s;i.prototype.doBoundingSphereBroadphase=function(t,e,o,i){var n=a;e.position.vsub(t.position,n);var s=Math.pow(t.boundingRadius+e.boundingRadius,2);n.norm2()<s&&(o.push(t),i.push(e))},i.prototype.doBoundingBoxBroadphase=function(t,e,o,i){t.aabbNeedsUpdate&&t.computeAABB(),e.aabbNeedsUpdate&&e.computeAABB(),t.aabb.overlaps(e.aabb)&&(o.push(t),i.push(e))};var c={keys:[]},h=[],l=[];i.prototype.makePairsUnique=function(t,e){for(var o=c,i=h,n=l,s=t.length,r=0;r!==s;r++)i[r]=t[r],n[r]=e[r];t.length=0,e.length=0;for(r=0;r!==s;r++){var a=i[r].id,u=n[r].id;o[p=a<u?a+","+u:u+","+a]=r,o.keys.push(p)}for(r=0;r!==o.keys.length;r++){var p=o.keys.pop(),d=o[p];t.push(i[d]),e.push(n[d]),delete o[p]}},i.prototype.setWorld=function(t){};var u=new s;i.boundingSphereCheck=function(t,e){var o=u;return t.position.vsub(e.position,o),Math.pow(t.shape.boundingSphereRadius+e.shape.boundingSphereRadius,2)>o.norm2()},i.prototype.aabbQuery=function(t,e,o){return console.warn(".aabbQuery is not implemented in this Broadphase subclass."),[]}},{"../math/Quaternion":44,"../math/Vec3":46,"../objects/Body":47,"../shapes/Plane":58,"../shapes/Shape":59}],21:[function(t,e,o){function i(t,e,o,i,r){n.apply(this),this.nx=o||10,this.ny=i||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 c=0;c<a;c++)this.bins[c]=[],this.binLengths[c]=0}e.exports=i;var n=t("./Broadphase"),s=t("../math/Vec3"),r=t("../shapes/Shape");(i.prototype=new n).constructor=i;var a=new s;new s;i.prototype.collisionPairs=function(t,e,o){function i(t,e,o,i,n,s,r){var a=(t-g)*E|0,c=(e-x)*A|0,h=(o-b)*B|0,f=F((i-g)*E),m=F((n-x)*A),w=F((s-b)*B);a<0?a=0:a>=l&&(a=l-1),c<0?c=0:c>=u&&(c=u-1),h<0?h=0:h>=p&&(h=p-1),f<0?f=0:f>=l&&(f=l-1),m<0?m=0:m>=u&&(m=u-1),w<0?w=0:w>=p&&(w=p-1),c*=y,h*=v,f*=d,m*=y,w*=v;for(var C=a*=d;C<=f;C+=d)for(var S=c;S<=m;S+=y)for(var R=h;R<=w;R+=v){var M=C+S+R;P[M][q[M]++]=r}}for(var n=t.numObjects(),s=t.bodies,c=this.aabbMax,h=this.aabbMin,l=this.nx,u=this.ny,p=this.nz,d=u*p,y=p,v=1,f=c.x,m=c.y,w=c.z,g=h.x,x=h.y,b=h.z,E=l/(f-g),A=u/(m-x),B=p/(w-b),C=(f-g)/l,S=(m-x)/u,R=(w-b)/p,M=.5*Math.sqrt(C*C+S*S+R*R),T=r.types,z=T.SPHERE,k=T.PLANE,P=(T.BOX,T.COMPOUND,T.CONVEXPOLYHEDRON,this.bins),q=this.binLengths,L=this.bins.length,V=0;V!==L;V++)q[V]=0;for(var F=Math.ceil,h=Math.min,c=Math.max,V=0;V!==n;V++){var N=(ot=s[V]).shape;switch(N.type){case z:var I=ot.position.x,O=ot.position.y,j=ot.position.z,W=N.radius;i(I-W,O-W,j-W,I+W,O+W,j+W,ot);break;case k:N.worldNormalNeedsUpdate&&N.computeWorldNormal(ot.quaternion);var D=N.worldNormal,H=g+.5*C-ot.position.x,K=x+.5*S-ot.position.y,_=b+.5*R-ot.position.z,U=a;U.set(H,K,_);for(var G=0,X=0;G!==l;G++,X+=d,U.y=K,U.x+=C)for(var Y=0,Q=0;Y!==u;Y++,Q+=y,U.z=_,U.y+=S)for(var Z=0,J=0;Z!==p;Z++,J+=v,U.z+=R)if(U.dot(D)<M){var $=X+Q+J;P[$][q[$]++]=ot}break;default:ot.aabbNeedsUpdate&&ot.computeAABB(),i(ot.aabb.lowerBound.x,ot.aabb.lowerBound.y,ot.aabb.lowerBound.z,ot.aabb.upperBound.x,ot.aabb.upperBound.y,ot.aabb.upperBound.z,ot)}}for(V=0;V!==L;V++){var tt=q[V];if(tt>1)for(var et=P[V],G=0;G!==tt;G++)for(var ot=et[G],Y=0;Y!==G;Y++){var it=et[Y];this.needBroadphaseCollision(ot,it)&&this.intersectionTest(ot,it,e,o)}}this.makePairsUnique(e,o)}},{"../math/Vec3":46,"../shapes/Shape":59,"./Broadphase":20}],22:[function(t,e,o){function i(){n.apply(this)}e.exports=i;var n=t("./Broadphase"),s=t("./AABB");(i.prototype=new n).constructor=i,i.prototype.collisionPairs=function(t,e,o){var i,n,s,r,a=t.bodies,c=a.length;for(i=0;i!==c;i++)for(n=0;n!==i;n++)s=a[i],r=a[n],this.needBroadphaseCollision(s,r)&&this.intersectionTest(s,r,e,o)};new s;i.prototype.aabbQuery=function(t,e,o){o=o||[];for(var i=0;i<t.bodies.length;i++){var n=t.bodies[i];n.aabbNeedsUpdate&&n.computeAABB(),n.aabb.overlaps(e)&&o.push(n)}return o}},{"./AABB":18,"./Broadphase":20}],23:[function(t,e,o){function i(){this.matrix={}}e.exports=i,i.prototype.get=function(t,e){if(t=t.id,(e=e.id)>t){var o=e;e=t,t=o}return t+"-"+e in this.matrix},i.prototype.set=function(t,e,o){if(t=t.id,(e=e.id)>t){var i=e;e=t,t=i}o?this.matrix[t+"-"+e]=!0:delete this.matrix[t+"-"+e]},i.prototype.reset=function(){this.matrix={}},i.prototype.setNumObjects=function(t){}},{}],24:[function(t,e,o){function i(){this.current=[],this.previous=[]}function n(t,e){t.push((4294901760&e)>>16,65535&e)}e.exports=i,i.prototype.getKey=function(t,e){if(e<t){var o=e;e=t,t=o}return t<<16|e},i.prototype.set=function(t,e){for(var o=this.getKey(t,e),i=this.current,n=0;o>i[n];)n++;if(o!==i[n]){for(e=i.length-1;e>=n;e--)i[e+1]=i[e];i[n]=o}},i.prototype.tick=function(){var t=this.current;this.current=this.previous,this.previous=t,this.current.length=0},i.prototype.getDiff=function(t,e){for(var o=this.current,i=this.previous,s=o.length,r=i.length,a=0,c=0;c<s;c++){for(var h=o[c];h>i[a];)a++;h===i[a]||n(t,h)}a=0;for(c=0;c<r;c++){for(var l=i[c];l>o[a];)a++;o[a]===l||n(e,l)}}},{}],25:[function(t,e,o){function i(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=i.ANY,this.result=new c,this.hasHit=!1,this.callback=function(t){}}function n(t,e,o,i){i.vsub(e,N),o.vsub(e,d),t.vsub(e,y);var n,s,r=N.dot(N),a=N.dot(d),c=N.dot(y),h=d.dot(d),l=d.dot(y);return(n=h*c-a*l)>=0&&(s=r*l-a*c)>=0&&n+s<r*h-a*a}e.exports=i;var s=t("../math/Vec3"),r=t("../math/Quaternion"),a=t("../math/Transform"),c=(t("../shapes/ConvexPolyhedron"),t("../shapes/Box"),t("../collision/RaycastResult")),h=t("../shapes/Shape"),l=t("../collision/AABB");i.prototype.constructor=i,i.CLOSEST=1,i.ANY=2,i.ALL=4;var u=new l,p=[];i.prototype.intersectWorld=function(t,e){return this.mode=e.mode||i.ANY,this.result=e.result||new c,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(u),p.length=0,t.broadphase.aabbQuery(t,u,p),this.intersectBodies(p),this.hasHit};var d=new s,y=new s;i.pointInTriangle=n;var v=new s,f=new r;i.prototype.intersectBody=function(t,e){e&&(this.result=e,this._updateDirection());var o=this.checkCollisionResponse;if((!o||t.collisionResponse)&&0!=(this.collisionFilterGroup&t.collisionFilterMask)&&0!=(t.collisionFilterGroup&this.collisionFilterMask))for(var i=v,n=f,s=0,r=t.shapes.length;s<r;s++){var a=t.shapes[s];if((!o||a.collisionResponse)&&(t.quaternion.mult(t.shapeOrientations[s],n),t.quaternion.vmult(t.shapeOffsets[s],i),i.vadd(t.position,i),this.intersectShape(a,n,i,t),this.result._shouldStop))break}},i.prototype.intersectBodies=function(t,e){e&&(this.result=e,this._updateDirection());for(var o=0,i=t.length;!this.result._shouldStop&&o<i;o++)this.intersectBody(t[o])},i.prototype._updateDirection=function(){this.to.vsub(this.from,this._direction),this._direction.normalize()},i.prototype.intersectShape=function(t,e,o,i){if(!(function(t,e,o){o.vsub(t,N);var i=N.dot(e);return e.mult(i,I),I.vadd(t,I),o.distanceTo(I)}(this.from,this._direction,o)>t.boundingSphereRadius)){var n=this[t.type];n&&n.call(this,t,e,o,i,t)}};new s,new s;var m=new s,w=new s,g=new s,x=new s;new s,new c;i.prototype.intersectBox=function(t,e,o,i,n){return this.intersectConvex(t.convexPolyhedronRepresentation,e,o,i,n)},i.prototype[h.types.BOX]=i.prototype.intersectBox,i.prototype.intersectPlane=function(t,e,o,i,n){var r=this.from,a=this.to,c=this._direction,h=new s(0,0,1);e.vmult(h,h);var l=new s;r.vsub(o,l);var u=l.dot(h);a.vsub(o,l);if(!(u*l.dot(h)>0||r.distanceTo(a)<u)){var p=h.dot(c);if(!(Math.abs(p)<this.precision)){var d=new s,y=new s,v=new s;r.vsub(o,d);var f=-h.dot(d)/p;c.scale(f,y),r.vadd(y,v),this.reportIntersection(h,v,n,i,-1)}}},i.prototype[h.types.PLANE]=i.prototype.intersectPlane,i.prototype.getAABB=function(t){var e=this.to,o=this.from;t.lowerBound.x=Math.min(e.x,o.x),t.lowerBound.y=Math.min(e.y,o.y),t.lowerBound.z=Math.min(e.z,o.z),t.upperBound.x=Math.max(e.x,o.x),t.upperBound.y=Math.max(e.y,o.y),t.upperBound.z=Math.max(e.z,o.z)};var b={faceList:[0]},E=new s,A=new i,B=[];i.prototype.intersectHeightfield=function(t,e,o,i,n){t.data,t.elementSize;var s=A;s.from.copy(this.from),s.to.copy(this.to),a.pointToLocalFrame(o,e,s.from,s.from),a.pointToLocalFrame(o,e,s.to,s.to),s._updateDirection();var r,c,h,u,p=B;r=c=0,h=u=t.data.length-1;var d=new l;s.getAABB(d),t.getIndexOfPosition(d.lowerBound.x,d.lowerBound.y,p,!0),r=Math.max(r,p[0]),c=Math.max(c,p[1]),t.getIndexOfPosition(d.upperBound.x,d.upperBound.y,p,!0),h=Math.min(h,p[0]+1),u=Math.min(u,p[1]+1);for(var y=r;y<h;y++)for(var v=c;v<u;v++){if(this.result._shouldStop)return;if(t.getAabbAtIndex(y,v,d),d.overlapsRay(s)){if(t.getConvexTrianglePillar(y,v,!1),a.pointToWorldFrame(o,e,t.pillarOffset,E),this.intersectConvex(t.pillarConvex,e,E,i,n,b),this.result._shouldStop)return;t.getConvexTrianglePillar(y,v,!0),a.pointToWorldFrame(o,e,t.pillarOffset,E),this.intersectConvex(t.pillarConvex,e,E,i,n,b)}}},i.prototype[h.types.HEIGHTFIELD]=i.prototype.intersectHeightfield;var C=new s,S=new s;i.prototype.intersectSphere=function(t,e,o,i,n){var s=this.from,r=this.to,a=t.radius,c=Math.pow(r.x-s.x,2)+Math.pow(r.y-s.y,2)+Math.pow(r.z-s.z,2),h=2*((r.x-s.x)*(s.x-o.x)+(r.y-s.y)*(s.y-o.y)+(r.z-s.z)*(s.z-o.z)),l=Math.pow(s.x-o.x,2)+Math.pow(s.y-o.y,2)+Math.pow(s.z-o.z,2)-Math.pow(a,2),u=Math.pow(h,2)-4*c*l,p=C,d=S;if(!(u<0))if(0===u)s.lerp(r,u,p),p.vsub(o,d),d.normalize(),this.reportIntersection(d,p,n,i,-1);else{var y=(-h-Math.sqrt(u))/(2*c),v=(-h+Math.sqrt(u))/(2*c);if(y>=0&&y<=1&&(s.lerp(r,y,p),p.vsub(o,d),d.normalize(),this.reportIntersection(d,p,n,i,-1)),this.result._shouldStop)return;v>=0&&v<=1&&(s.lerp(r,v,p),p.vsub(o,d),d.normalize(),this.reportIntersection(d,p,n,i,-1))}},i.prototype[h.types.SPHERE]=i.prototype.intersectSphere;var R=new s,M=(new s,new s,new s);i.prototype.intersectConvex=function(t,e,o,i,s,r){for(var a=R,c=M,h=r&&r.faceList||null,l=t.faces,u=t.vertices,p=t.faceNormals,d=this._direction,y=this.from,v=this.to,f=y.distanceTo(v),b=h?h.length:l.length,E=this.result,A=0;!E._shouldStop&&A<b;A++){var B=h?h[A]:A,C=l[B],S=p[B],T=e,z=o;c.copy(u[C[0]]),T.vmult(c,c),c.vadd(z,c),c.vsub(y,c),T.vmult(S,a);var k=d.dot(a);if(!(Math.abs(k)<this.precision)){var P=a.dot(c)/k;if(!(P<0)){d.mult(P,m),m.vadd(y,m),w.copy(u[C[0]]),T.vmult(w,w),z.vadd(w,w);for(var q=1;!E._shouldStop&&q<C.length-1;q++){g.copy(u[C[q]]),x.copy(u[C[q+1]]),T.vmult(g,g),T.vmult(x,x),z.vadd(g,g),z.vadd(x,x);var L=m.distanceTo(y);!n(m,w,g,x)&&!n(m,g,w,x)||L>f||this.reportIntersection(a,m,s,i,B)}}}}},i.prototype[h.types.CONVEXPOLYHEDRON]=i.prototype.intersectConvex;var T=new s,z=new s,k=new s,P=new s,q=new s,L=new s,V=(new l,[]),F=new a;i.prototype.intersectTrimesh=function(t,e,o,i,s,r){var c=T,h=V,l=F,u=M,p=z,d=k,y=P,v=L,f=q,b=(r&&r.faceList,t.indices),E=(t.vertices,t.faceNormals,this.from),A=this.to,B=this._direction;l.position.copy(o),l.quaternion.copy(e),a.vectorToLocalFrame(o,e,B,p),a.pointToLocalFrame(o,e,E,d),a.pointToLocalFrame(o,e,A,y),y.x*=t.scale.x,y.y*=t.scale.y,y.z*=t.scale.z,d.x*=t.scale.x,d.y*=t.scale.y,d.z*=t.scale.z,y.vsub(d,p),p.normalize();var C=d.distanceSquared(y);t.tree.rayQuery(this,l,h);for(var S=0,R=h.length;!this.result._shouldStop&&S!==R;S++){var N=h[S];t.getNormal(N,c),t.getVertex(b[3*N],w),w.vsub(d,u);var I=p.dot(c),O=c.dot(u)/I;if(!(O<0)){p.scale(O,m),m.vadd(d,m),t.getVertex(b[3*N+1],g),t.getVertex(b[3*N+2],x);var j=m.distanceSquared(d);!n(m,g,w,x)&&!n(m,w,g,x)||j>C||(a.vectorToWorldFrame(e,c,f),a.pointToWorldFrame(o,e,m,v),this.reportIntersection(f,v,s,i,N))}}h.length=0},i.prototype[h.types.TRIMESH]=i.prototype.intersectTrimesh,i.prototype.reportIntersection=function(t,e,o,n,s){var r=this.from,a=this.to,c=r.distanceTo(e),h=this.result;if(!(this.skipBackfaces&&t.dot(this._direction)>0))switch(h.hitFaceIndex=void 0!==s?s:-1,this.mode){case i.ALL:this.hasHit=!0,h.set(r,a,t,e,o,n,c),h.hasHit=!0,this.callback(h);break;case i.CLOSEST:(c<h.distance||!h.hasHit)&&(this.hasHit=!0,h.hasHit=!0,h.set(r,a,t,e,o,n,c));break;case i.ANY:this.hasHit=!0,h.hasHit=!0,h.set(r,a,t,e,o,n,c),h._shouldStop=!0}};var N=new s,I=new s},{"../collision/AABB":18,"../collision/RaycastResult":26,"../math/Quaternion":44,"../math/Transform":45,"../math/Vec3":46,"../shapes/Box":53,"../shapes/ConvexPolyhedron":54,"../shapes/Shape":59}],26:[function(t,e,o){function i(){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=i,i.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},i.prototype.abort=function(){this._shouldStop=!0},i.prototype.set=function(t,e,o,i,n,s,r){this.rayFromWorld.copy(t),this.rayToWorld.copy(e),this.hitNormalWorld.copy(o),this.hitPointWorld.copy(i),this.shape=n,this.body=s,this.distance=r}},{"../math/Vec3":46}],27:[function(t,e,o){function i(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 o=e.indexOf(t.body);-1!==o&&e.splice(o,1)},t&&this.setWorld(t)}t("../shapes/Shape");var n=t("../collision/Broadphase");e.exports=i,(i.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},i.insertionSortX=function(t){for(var e=1,o=t.length;e<o;e++){for(var i=t[e],n=e-1;n>=0&&!(t[n].aabb.lowerBound.x<=i.aabb.lowerBound.x);n--)t[n+1]=t[n];t[n+1]=i}return t},i.insertionSortY=function(t){for(var e=1,o=t.length;e<o;e++){for(var i=t[e],n=e-1;n>=0&&!(t[n].aabb.lowerBound.y<=i.aabb.lowerBound.y);n--)t[n+1]=t[n];t[n+1]=i}return t},i.insertionSortZ=function(t){for(var e=1,o=t.length;e<o;e++){for(var i=t[e],n=e-1;n>=0&&!(t[n].aabb.lowerBound.z<=i.aabb.lowerBound.z);n--)t[n+1]=t[n];t[n+1]=i}return t},i.prototype.collisionPairs=function(t,e,o){var n,s,r=this.axisList,a=r.length,c=this.axisIndex;for(this.dirty&&(this.sortList(),this.dirty=!1),n=0;n!==a;n++){var h=r[n];for(s=n+1;s<a;s++){var l=r[s];if(this.needBroadphaseCollision(h,l)){if(!i.checkBounds(h,l,c))break;this.intersectionTest(h,l,e,o)}}}},i.prototype.sortList=function(){for(var t=this.axisList,e=this.axisIndex,o=t.length,n=0;n!==o;n++){var s=t[n];s.aabbNeedsUpdate&&s.computeAABB()}0===e?i.insertionSortX(t):1===e?i.insertionSortY(t):2===e&&i.insertionSortZ(t)},i.checkBounds=function(t,e,o){var i,n;0===o?(i=t.position.x,n=e.position.x):1===o?(i=t.position.y,n=e.position.y):2===o&&(i=t.position.z,n=e.position.z);var s=t.boundingRadius,r=e.boundingRadius;return n-r<i+s},i.prototype.autoDetectAxis=function(){for(var t=0,e=0,o=0,i=0,n=0,s=0,r=this.axisList,a=r.length,c=1/a,h=0;h!==a;h++){var l=r[h],u=l.position.x;t+=u,e+=u*u;var p=l.position.y;o+=p,i+=p*p;var d=l.position.z;n+=d,s+=d*d}var y=e-t*t*c,v=i-o*o*c,f=s-n*n*c;this.axisIndex=y>v?y>f?0:2:v>f?1:2},i.prototype.aabbQuery=function(t,e,o){o=o||[],this.dirty&&(this.sortList(),this.dirty=!1);var i=this.axisIndex,n="x";1===i&&(n="y"),2===i&&(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)&&o.push(a)}return o}},{"../collision/Broadphase":20,"../shapes/Shape":59}],28:[function(t,e,o){function i(t,e,o){var i=void 0!==(o=o||{}).maxForce?o.maxForce:1e6,c=o.pivotA?o.pivotA.clone():new a,h=o.pivotB?o.pivotB.clone():new a;this.axisA=o.axisA?o.axisA.clone():new a,this.axisB=o.axisB?o.axisB.clone():new a,n.call(this,t,c,e,h,i),this.collideConnected=!!o.collideConnected,this.angle=void 0!==o.angle?o.angle:0;var l=this.coneEquation=new s(t,e,o),u=this.twistEquation=new r(t,e,o);this.twistAngle=void 0!==o.twistAngle?o.twistAngle:0,l.maxForce=0,l.minForce=-i,u.maxForce=0,u.minForce=-i,this.equations.push(l,u)}e.exports=i;t("./Constraint");var n=t("./PointToPointConstraint"),s=t("../equations/ConeEquation"),r=t("../equations/RotationalEquation"),a=(t("../equations/ContactEquation"),t("../math/Vec3"));i.prototype=new n,i.constructor=i;new a,new a;i.prototype.update=function(){var t=this.bodyA,e=this.bodyB,o=this.coneEquation,i=this.twistEquation;n.prototype.update.call(this),t.vectorToWorldFrame(this.axisA,o.axisA),e.vectorToWorldFrame(this.axisB,o.axisB),this.axisA.tangents(i.axisA,i.axisA),t.vectorToWorldFrame(i.axisA,i.axisA),this.axisB.tangents(i.axisB,i.axisB),e.vectorToWorldFrame(i.axisB,i.axisB),o.angle=this.angle,i.maxAngle=this.twistAngle}},{"../equations/ConeEquation":34,"../equations/ContactEquation":35,"../equations/RotationalEquation":38,"../math/Vec3":46,"./Constraint":29,"./PointToPointConstraint":33}],29:[function(t,e,o){function i(t,e,o){o=n.defaults(o,{collideConnected:!0,wakeUpBodies:!0}),this.equations=[],this.bodyA=t,this.bodyB=e,this.id=i.idCounter++,this.collideConnected=o.collideConnected,o.wakeUpBodies&&(t&&t.wakeUp(),e&&e.wakeUp())}e.exports=i;var n=t("../utils/Utils");i.prototype.update=function(){throw new Error("method update() not implmemented in this Constraint subclass!")},i.prototype.enable=function(){for(var t=this.equations,e=0;e<t.length;e++)t[e].enabled=!0},i.prototype.disable=function(){for(var t=this.equations,e=0;e<t.length;e++)t[e].enabled=!1},i.idCounter=0},{"../utils/Utils":69}],30:[function(t,e,o){function i(t,e,o,i){n.call(this,t,e),void 0===o&&(o=t.position.distanceTo(e.position)),void 0===i&&(i=1e6),this.distance=o;var r=this.distanceEquation=new s(t,e);this.equations.push(r),r.minForce=-i,r.maxForce=i}e.exports=i;var n=t("./Constraint"),s=t("../equations/ContactEquation");(i.prototype=new n).update=function(){var t=this.bodyA,e=this.bodyB,o=this.distanceEquation,i=.5*this.distance,n=o.ni;e.position.vsub(t.position,n),n.normalize(),n.mult(i,o.ri),n.mult(-i,o.rj)}},{"../equations/ContactEquation":35,"./Constraint":29}],31:[function(t,e,o){function i(t,e,o){var i=void 0!==(o=o||{}).maxForce?o.maxForce:1e6,c=o.pivotA?o.pivotA.clone():new a,h=o.pivotB?o.pivotB.clone():new a;n.call(this,t,c,e,h,i);(this.axisA=o.axisA?o.axisA.clone():new a(1,0,0)).normalize();(this.axisB=o.axisB?o.axisB.clone():new a(1,0,0)).normalize();var l=this.rotationalEquation1=new s(t,e,o),u=this.rotationalEquation2=new s(t,e,o),p=this.motorEquation=new r(t,e,i);p.enabled=!1,this.equations.push(l,u,p)}e.exports=i;t("./Constraint");var n=t("./PointToPointConstraint"),s=t("../equations/RotationalEquation"),r=t("../equations/RotationalMotorEquation"),a=(t("../equations/ContactEquation"),t("../math/Vec3"));i.prototype=new n,i.constructor=i,i.prototype.enableMotor=function(){this.motorEquation.enabled=!0},i.prototype.disableMotor=function(){this.motorEquation.enabled=!1},i.prototype.setMotorSpeed=function(t){this.motorEquation.targetVelocity=t},i.prototype.setMotorMaxForce=function(t){this.motorEquation.maxForce=t,this.motorEquation.minForce=-t};var c=new a,h=new a;i.prototype.update=function(){var t=this.bodyA,e=this.bodyB,o=this.motorEquation,i=this.rotationalEquation1,s=this.rotationalEquation2,r=c,a=h,l=this.axisA,u=this.axisB;n.prototype.update.call(this),t.quaternion.vmult(l,r),e.quaternion.vmult(u,a),r.tangents(i.axisA,s.axisA),i.axisB.copy(a),s.axisB.copy(a),this.motorEquation.enabled&&(t.quaternion.vmult(this.axisA,o.axisA),e.quaternion.vmult(this.axisB,o.axisB))}},{"../equations/ContactEquation":35,"../equations/RotationalEquation":38,"../equations/RotationalMotorEquation":39,"../math/Vec3":46,"./Constraint":29,"./PointToPointConstraint":33}],32:[function(t,e,o){function i(t,e,o){var i=void 0!==(o=o||{}).maxForce?o.maxForce:1e6,a=new r,c=new r,h=new r;t.position.vadd(e.position,h),h.scale(.5,h),e.pointToLocalFrame(h,c),t.pointToLocalFrame(h,a),n.call(this,t,a,e,c,i),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 l=this.rotationalEquation1=new s(t,e,o),u=this.rotationalEquation2=new s(t,e,o),p=this.rotationalEquation3=new s(t,e,o);this.equations.push(l,u,p)}e.exports=i;t("./Constraint");var n=t("./PointToPointConstraint"),s=t("../equations/RotationalEquation"),r=(t("../equations/RotationalMotorEquation"),t("../equations/ContactEquation"),t("../math/Vec3"));i.prototype=new n,i.constructor=i;new r,new r;i.prototype.update=function(){var t=this.bodyA,e=this.bodyB,o=(this.motorEquation,this.rotationalEquation1),i=this.rotationalEquation2,s=this.rotationalEquation3;n.prototype.update.call(this),t.vectorToWorldFrame(this.xA,o.axisA),e.vectorToWorldFrame(this.yB,o.axisB),t.vectorToWorldFrame(this.yA,i.axisA),e.vectorToWorldFrame(this.zB,i.axisB),t.vectorToWorldFrame(this.zA,s.axisA),e.vectorToWorldFrame(this.xB,s.axisB)}},{"../equations/ContactEquation":35,"../equations/RotationalEquation":38,"../equations/RotationalMotorEquation":39,"../math/Vec3":46,"./Constraint":29,"./PointToPointConstraint":33}],33:[function(t,e,o){function i(t,e,o,i,a){n.call(this,t,o),a=void 0!==a?a:1e6,this.pivotA=e?e.clone():new r,this.pivotB=i?i.clone():new r;var c=this.equationX=new s(t,o),h=this.equationY=new s(t,o),l=this.equationZ=new s(t,o);this.equations.push(c,h,l),c.minForce=h.minForce=l.minForce=-a,c.maxForce=h.maxForce=l.maxForce=a,c.ni.set(1,0,0),h.ni.set(0,1,0),l.ni.set(0,0,1)}e.exports=i;var n=t("./Constraint"),s=t("../equations/ContactEquation"),r=t("../math/Vec3");(i.prototype=new n).update=function(){var t=this.bodyA,e=this.bodyB,o=this.equationX,i=this.equationY,n=this.equationZ;t.quaternion.vmult(this.pivotA,o.ri),e.quaternion.vmult(this.pivotB,o.rj),i.ri.copy(o.ri),i.rj.copy(o.rj),n.ri.copy(o.ri),n.rj.copy(o.rj)}},{"../equations/ContactEquation":35,"../math/Vec3":46,"./Constraint":29}],34:[function(t,e,o){function i(t,e,o){var i=void 0!==(o=o||{}).maxForce?o.maxForce:1e6;s.call(this,t,e,-i,i),this.axisA=o.axisA?o.axisA.clone():new n(1,0,0),this.axisB=o.axisB?o.axisB.clone():new n(0,1,0),this.angle=void 0!==o.angle?o.angle:0}e.exports=i;var n=t("../math/Vec3"),s=(t("../math/Mat3"),t("./Equation"));(i.prototype=new s).constructor=i;var r=new n,a=new n;i.prototype.computeB=function(t){var e=this.a,o=this.b,i=this.axisA,n=this.axisB,s=r,c=a,h=this.jacobianElementA,l=this.jacobianElementB;i.cross(n,s),n.cross(i,c),h.rotational.copy(c),l.rotational.copy(s);return-(Math.cos(this.angle)-i.dot(n))*e-this.computeGW()*o-t*this.computeGiMf()}},{"../math/Mat3":43,"../math/Vec3":46,"./Equation":36}],35:[function(t,e,o){function i(t,e,o){o=void 0!==o?o:1e6,n.call(this,t,e,0,o),this.restitution=0,this.ri=new s,this.rj=new s,this.ni=new s}e.exports=i;var n=t("./Equation"),s=t("../math/Vec3");t("../math/Mat3");(i.prototype=new n).constructor=i;var r=new s,a=new s,c=new s;i.prototype.computeB=function(t){var e=this.a,o=this.b,i=this.bi,n=this.bj,s=this.ri,h=this.rj,l=r,u=a,p=i.velocity,d=i.angularVelocity,y=(i.force,i.torque,n.velocity),v=n.angularVelocity,f=(n.force,n.torque,c),m=this.jacobianElementA,w=this.jacobianElementB,g=this.ni;s.cross(g,l),h.cross(g,u),g.negate(m.spatial),l.negate(m.rotational),w.spatial.copy(g),w.rotational.copy(u),f.copy(n.position),f.vadd(h,f),f.vsub(i.position,f),f.vsub(s,f);var x=g.dot(f),b=this.restitution+1;return-x*e-(b*y.dot(g)-b*p.dot(g)+v.dot(u)-d.dot(l))*o-t*this.computeGiMf()};var h=new s,l=new s,u=new s,p=new s,d=new s;i.prototype.getImpactVelocityAlongNormal=function(){var t=h,e=l,o=u,i=p,n=d;return this.bi.position.vadd(this.ri,o),this.bj.position.vadd(this.rj,i),this.bi.getVelocityAtWorldPoint(o,t),this.bj.getVelocityAtWorldPoint(i,e),t.vsub(e,n),this.ni.dot(n)}},{"../math/Mat3":43,"../math/Vec3":46,"./Equation":36}],36:[function(t,e,o){function i(t,e,o,s){this.id=i.id++,this.minForce=void 0===o?-1e6:o,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=i;var n=t("../math/JacobianElement"),s=t("../math/Vec3");i.prototype.constructor=i,i.id=0,i.prototype.setSpookParams=function(t,e,o){var i=e,n=t,s=o;this.a=4/(s*(1+4*i)),this.b=4*i/(1+4*i),this.eps=4/(s*s*n*(1+4*i))},i.prototype.computeB=function(t,e,o){var i=this.computeGW();return-this.computeGq()*t-i*e-this.computeGiMf()*o},i.prototype.computeGq=function(){var t=this.jacobianElementA,e=this.jacobianElementB,o=this.bi,i=this.bj,n=o.position,s=i.position;return t.spatial.dot(n)+e.spatial.dot(s)};new s;i.prototype.computeGW=function(){var t=this.jacobianElementA,e=this.jacobianElementB,o=this.bi,i=this.bj,n=o.velocity,s=i.velocity,r=o.angularVelocity,a=i.angularVelocity;return t.multiplyVectors(n,r)+e.multiplyVectors(s,a)},i.prototype.computeGWlambda=function(){var t=this.jacobianElementA,e=this.jacobianElementB,o=this.bi,i=this.bj,n=o.vlambda,s=i.vlambda,r=o.wlambda,a=i.wlambda;return t.multiplyVectors(n,r)+e.multiplyVectors(s,a)};var r=new s,a=new s,c=new s,h=new s;i.prototype.computeGiMf=function(){var t=this.jacobianElementA,e=this.jacobianElementB,o=this.bi,i=this.bj,n=o.force,s=o.torque,l=i.force,u=i.torque,p=o.invMassSolve,d=i.invMassSolve;return n.scale(p,r),l.scale(d,a),o.invInertiaWorldSolve.vmult(s,c),i.invInertiaWorldSolve.vmult(u,h),t.multiplyVectors(r,c)+e.multiplyVectors(a,h)};var l=new s;i.prototype.computeGiMGt=function(){var t=this.jacobianElementA,e=this.jacobianElementB,o=this.bi,i=this.bj,n=o.invMassSolve,s=i.invMassSolve,r=o.invInertiaWorldSolve,a=i.invInertiaWorldSolve,c=n+s;return r.vmult(t.rotational,l),c+=l.dot(t.rotational),a.vmult(e.rotational,l),c+=l.dot(e.rotational)};var u=new s;new s,new s,new s,new s,new s;i.prototype.addToWlambda=function(t){var e=this.jacobianElementA,o=this.jacobianElementB,i=this.bi,n=this.bj,s=u;i.vlambda.addScaledVector(i.invMassSolve*t,e.spatial,i.vlambda),n.vlambda.addScaledVector(n.invMassSolve*t,o.spatial,n.vlambda),i.invInertiaWorldSolve.vmult(e.rotational,s),i.wlambda.addScaledVector(t,s,i.wlambda),n.invInertiaWorldSolve.vmult(o.rotational,s),n.wlambda.addScaledVector(t,s,n.wlambda)},i.prototype.computeC=function(){return this.computeGiMGt()+this.eps}},{"../math/JacobianElement":42,"../math/Vec3":46}],37:[function(t,e,o){function i(t,e,o){n.call(this,t,e,-o,o),this.ri=new s,this.rj=new s,this.t=new s}e.exports=i;var n=t("./Equation"),s=t("../math/Vec3");t("../math/Mat3");(i.prototype=new n).constructor=i;var r=new s,a=new s;i.prototype.computeB=function(t){this.a;var e=this.b,o=(this.bi,this.bj,this.ri),i=this.rj,n=r,s=a,c=this.t;o.cross(c,n),i.cross(c,s);var h=this.jacobianElementA,l=this.jacobianElementB;c.negate(h.spatial),n.negate(h.rotational),l.spatial.copy(c),l.rotational.copy(s);return-this.computeGW()*e-t*this.computeGiMf()}},{"../math/Mat3":43,"../math/Vec3":46,"./Equation":36}],38:[function(t,e,o){function i(t,e,o){var i=void 0!==(o=o||{}).maxForce?o.maxForce:1e6;s.call(this,t,e,-i,i),this.axisA=o.axisA?o.axisA.clone():new n(1,0,0),this.axisB=o.axisB?o.axisB.clone():new n(0,1,0),this.maxAngle=Math.PI/2}e.exports=i;var n=t("../math/Vec3"),s=(t("../math/Mat3"),t("./Equation"));(i.prototype=new s).constructor=i;var r=new n,a=new n;i.prototype.computeB=function(t){var e=this.a,o=this.b,i=this.axisA,n=this.axisB,s=r,c=a,h=this.jacobianElementA,l=this.jacobianElementB;i.cross(n,s),n.cross(i,c),h.rotational.copy(c),l.rotational.copy(s);return-(Math.cos(this.maxAngle)-i.dot(n))*e-this.computeGW()*o-t*this.computeGiMf()}},{"../math/Mat3":43,"../math/Vec3":46,"./Equation":36}],39:[function(t,e,o){function i(t,e,o){o=void 0!==o?o:1e6,s.call(this,t,e,-o,o),this.axisA=new n,this.axisB=new n,this.targetVelocity=0}e.exports=i;var n=t("../math/Vec3"),s=(t("../math/Mat3"),t("./Equation"));(i.prototype=new s).constructor=i,i.prototype.computeB=function(t){this.a;var e=this.b,o=(this.bi,this.bj,this.axisA),i=this.axisB,n=this.jacobianElementA,s=this.jacobianElementB;n.rotational.copy(o),i.negate(s.rotational);return-(this.computeGW()-this.targetVelocity)*e-t*this.computeGiMf()}},{"../math/Mat3":43,"../math/Vec3":46,"./Equation":36}],40:[function(t,e,o){function i(t,e,o){o=n.defaults(o,{friction:.3,restitution:.3,contactEquationStiffness:1e7,contactEquationRelaxation:3,frictionEquationStiffness:1e7,frictionEquationRelaxation:3}),this.id=i.idCounter++,this.materials=[t,e],this.friction=o.friction,this.restitution=o.restitution,this.contactEquationStiffness=o.contactEquationStiffness,this.contactEquationRelaxation=o.contactEquationRelaxation,this.frictionEquationStiffness=o.frictionEquationStiffness,this.frictionEquationRelaxation=o.frictionEquationRelaxation}var n=t("../utils/Utils");e.exports=i,i.idCounter=0},{"../utils/Utils":69}],41:[function(t,e,o){function i(t){var e="";"string"==typeof(t=t||{})?(e=t,t={}):"object"==typeof t&&(e=""),this.name=e,this.id=i.idCounter++,this.friction=void 0!==t.friction?t.friction:-1,this.restitution=void 0!==t.restitution?t.restitution:-1}e.exports=i,i.idCounter=0},{}],42:[function(t,e,o){function i(){this.spatial=new n,this.rotational=new n}e.exports=i;var n=t("./Vec3");i.prototype.multiplyElement=function(t){return t.spatial.dot(this.spatial)+t.rotational.dot(this.rotational)},i.prototype.multiplyVectors=function(t,e){return t.dot(this.spatial)+e.dot(this.rotational)}},{"./Vec3":46}],43:[function(t,e,o){function i(t){this.elements=t||[0,0,0,0,0,0,0,0,0]}e.exports=i;var n=t("./Vec3");i.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},i.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},i.prototype.setTrace=function(t){var e=this.elements;e[0]=t.x,e[4]=t.y,e[8]=t.z},i.prototype.getTrace=function(t){var t=t||new n,e=this.elements;t.x=e[0],t.y=e[4],t.z=e[8]},i.prototype.vmult=function(t,e){e=e||new n;var o=this.elements,i=t.x,s=t.y,r=t.z;return e.x=o[0]*i+o[1]*s+o[2]*r,e.y=o[3]*i+o[4]*s+o[5]*r,e.z=o[6]*i+o[7]*s+o[8]*r,e},i.prototype.smult=function(t){for(var e=0;e<this.elements.length;e++)this.elements[e]*=t},i.prototype.mmult=function(t,e){for(var o=e||new i,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];o.elements[n+3*s]=r}return o},i.prototype.scale=function(t,e){e=e||new i;for(var o=this.elements,n=e.elements,s=0;3!==s;s++)n[3*s+0]=t.x*o[3*s+0],n[3*s+1]=t.y*o[3*s+1],n[3*s+2]=t.z*o[3*s+2];return e},i.prototype.solve=function(t,e){e=e||new n;for(var o=[],i=0;i<12;i++)o.push(0);var s;for(i=0;i<3;i++)for(s=0;s<3;s++)o[i+4*s]=this.elements[i+3*s];o[3]=t.x,o[7]=t.y,o[11]=t.z;var r,a,c=3,h=c;do{if(i=h-c,0===o[i+4*i])for(s=i+1;s<h;s++)if(0!==o[i+4*s]){r=4;do{o[(a=4-r)+4*i]+=o[a+4*s]}while(--r);break}if(0!==o[i+4*i])for(s=i+1;s<h;s++){var l=o[i+4*s]/o[i+4*i];r=4;do{o[(a=4-r)+4*s]=a<=i?0:o[a+4*s]-o[a+4*i]*l}while(--r)}}while(--c);if(e.z=o[11]/o[10],e.y=(o[7]-o[6]*e.z)/o[5],e.x=(o[3]-o[2]*e.z-o[1]*e.y)/o[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},i.prototype.e=function(t,e,o){if(void 0===o)return this.elements[e+3*t];this.elements[e+3*t]=o},i.prototype.copy=function(t){for(var e=0;e<t.elements.length;e++)this.elements[e]=t.elements[e];return this},i.prototype.toString=function(){for(var t="",e=0;e<9;e++)t+=this.elements[e]+",";return t},i.prototype.reverse=function(t){t=t||new i;for(var e=[],o=0;o<18;o++)e.push(0);var n;for(o=0;o<3;o++)for(n=0;n<3;n++)e[o+6*n]=this.elements[o+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,c=a;do{if(o=c-a,0===e[o+6*o])for(n=o+1;n<c;n++)if(0!==e[o+6*n]){s=6;do{e[(r=6-s)+6*o]+=e[r+6*n]}while(--s);break}if(0!==e[o+6*o])for(n=o+1;n<c;n++){h=e[o+6*n]/e[o+6*o];s=6;do{e[(r=6-s)+6*n]=r<=o?0:e[r+6*n]-e[r+6*o]*h}while(--s)}}while(--a);o=2;do{n=o-1;do{h=e[o+6*n]/e[o+6*o];s=6;do{e[(r=6-s)+6*n]=e[r+6*n]-e[r+6*o]*h}while(--s)}while(n--)}while(--o);o=2;do{var h=1/e[o+6*o];s=6;do{e[(r=6-s)+6*o]=e[r+6*o]*h}while(--s)}while(o--);o=2;do{n=2;do{if(r=e[3+n+6*o],isNaN(r)||r===1/0)throw"Could not reverse! A=["+this.toString()+"]";t.e(o,n,r)}while(n--)}while(o--);return t},i.prototype.setRotationFromQuaternion=function(t){var e=t.x,o=t.y,i=t.z,n=t.w,s=e+e,r=o+o,a=i+i,c=e*s,h=e*r,l=e*a,u=o*r,p=o*a,d=i*a,y=n*s,v=n*r,f=n*a,m=this.elements;return m[0]=1-(u+d),m[1]=h-f,m[2]=l+v,m[3]=h+f,m[4]=1-(c+d),m[5]=p-y,m[6]=l-v,m[7]=p+y,m[8]=1-(c+u),this},i.prototype.transpose=function(t){for(var e=(t=t||new i).elements,o=this.elements,n=0;3!==n;n++)for(var s=0;3!==s;s++)e[3*n+s]=o[3*s+n];return t}},{"./Vec3":46}],44:[function(t,e,o){function i(t,e,o,i){this.x=void 0!==t?t:0,this.y=void 0!==e?e:0,this.z=void 0!==o?o:0,this.w=void 0!==i?i:1}e.exports=i;var n=t("./Vec3");i.prototype.set=function(t,e,o,i){return this.x=t,this.y=e,this.z=o,this.w=i,this},i.prototype.toString=function(){return this.x+","+this.y+","+this.z+","+this.w},i.prototype.toArray=function(){return[this.x,this.y,this.z,this.w]},i.prototype.setFromAxisAngle=function(t,e){var o=Math.sin(.5*e);return this.x=t.x*o,this.y=t.y*o,this.z=t.z*o,this.w=Math.cos(.5*e),this},i.prototype.toAxisAngle=function(t){t=t||new n,this.normalize();var e=2*Math.acos(this.w),o=Math.sqrt(1-this.w*this.w);return o<.001?(t.x=this.x,t.y=this.y,t.z=this.z):(t.x=this.x/o,t.y=this.y/o,t.z=this.z/o),[t,e]};var s=new n,r=new n;i.prototype.setFromVectors=function(t,e){if(t.isAntiparallelTo(e)){var o=s,i=r;t.tangents(o,i),this.setFromAxisAngle(o,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;i.prototype.mult=function(t,e){e=e||new i;var o=this.x,n=this.y,s=this.z,r=this.w,a=t.x,c=t.y,h=t.z,l=t.w;return e.x=o*l+r*a+n*h-s*c,e.y=n*l+r*c+s*a-o*h,e.z=s*l+r*h+o*c-n*a,e.w=r*l-o*a-n*c-s*h,e},i.prototype.inverse=function(t){var e=this.x,o=this.y,n=this.z,s=this.w;t=t||new i,this.conjugate(t);var r=1/(e*e+o*o+n*n+s*s);return t.x*=r,t.y*=r,t.z*=r,t.w*=r,t},i.prototype.conjugate=function(t){return t=t||new i,t.x=-this.x,t.y=-this.y,t.z=-this.z,t.w=this.w,t},i.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},i.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},i.prototype.vmult=function(t,e){e=e||new n;var o=t.x,i=t.y,s=t.z,r=this.x,a=this.y,c=this.z,h=this.w,l=h*o+a*s-c*i,u=h*i+c*o-r*s,p=h*s+r*i-a*o,d=-r*o-a*i-c*s;return e.x=l*h+d*-r+u*-c-p*-a,e.y=u*h+d*-a+p*-r-l*-c,e.z=p*h+d*-c+l*-a-u*-r,e},i.prototype.copy=function(t){return this.x=t.x,this.y=t.y,this.z=t.z,this.w=t.w,this},i.prototype.toEuler=function(t,e){e=e||"YZX";var o,i,n,s=this.x,r=this.y,a=this.z,c=this.w;switch(e){case"YZX":var h=s*r+a*c;if(h>.499&&(o=2*Math.atan2(s,c),i=Math.PI/2,n=0),h<-.499&&(o=-2*Math.atan2(s,c),i=-Math.PI/2,n=0),isNaN(o)){var l=s*s,u=r*r,p=a*a;o=Math.atan2(2*r*c-2*s*a,1-2*u-2*p),i=Math.asin(2*h),n=Math.atan2(2*s*c-2*r*a,1-2*l-2*p)}break;default:throw new Error("Euler order "+e+" not supported yet.")}t.y=o,t.z=i,t.x=n},i.prototype.setFromEuler=function(t,e,o,i){i=i||"XYZ";var n=Math.cos(t/2),s=Math.cos(e/2),r=Math.cos(o/2),a=Math.sin(t/2),c=Math.sin(e/2),h=Math.sin(o/2);return"XYZ"===i?(this.x=a*s*r+n*c*h,this.y=n*c*r-a*s*h,this.z=n*s*h+a*c*r,this.w=n*s*r-a*c*h):"YXZ"===i?(this.x=a*s*r+n*c*h,this.y=n*c*r-a*s*h,this.z=n*s*h-a*c*r,this.w=n*s*r+a*c*h):"ZXY"===i?(this.x=a*s*r-n*c*h,this.y=n*c*r+a*s*h,this.z=n*s*h+a*c*r,this.w=n*s*r-a*c*h):"ZYX"===i?(this.x=a*s*r-n*c*h,this.y=n*c*r+a*s*h,this.z=n*s*h-a*c*r,this.w=n*s*r+a*c*h):"YZX"===i?(this.x=a*s*r+n*c*h,this.y=n*c*r+a*s*h,this.z=n*s*h-a*c*r,this.w=n*s*r-a*c*h):"XZY"===i&&(this.x=a*s*r-n*c*h,this.y=n*c*r-a*s*h,this.z=n*s*h+a*c*r,this.w=n*s*r+a*c*h),this},i.prototype.clone=function(){return new i(this.x,this.y,this.z,this.w)},i.prototype.slerp=function(t,e,o){o=o||new i;var n,s,r,a,c,h=this.x,l=this.y,u=this.z,p=this.w,d=t.x,y=t.y,v=t.z,f=t.w;return(s=h*d+l*y+u*v+p*f)<0&&(s=-s,d=-d,y=-y,v=-v,f=-f),1-s>1e-6?(n=Math.acos(s),r=Math.sin(n),a=Math.sin((1-e)*n)/r,c=Math.sin(e*n)/r):(a=1-e,c=e),o.x=a*h+c*d,o.y=a*l+c*y,o.z=a*u+c*v,o.w=a*p+c*f,o},i.prototype.integrate=function(t,e,o,n){n=n||new i;var s=t.x*o.x,r=t.y*o.y,a=t.z*o.z,c=this.x,h=this.y,l=this.z,u=this.w,p=.5*e;return n.x+=p*(s*u+r*l-a*h),n.y+=p*(r*u+a*c-s*l),n.z+=p*(a*u+s*h-r*c),n.w+=p*(-s*c-r*h-a*l),n}},{"./Vec3":46}],45:[function(t,e,o){function i(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=i;var r=new s;i.pointToLocalFrame=function(t,e,o,i){i=i||new n;return o.vsub(t,i),e.conjugate(r),r.vmult(i,i),i},i.prototype.pointToLocal=function(t,e){return i.pointToLocalFrame(this.position,this.quaternion,t,e)},i.pointToWorldFrame=function(t,e,o,i){i=i||new n;return e.vmult(o,i),i.vadd(t,i),i},i.prototype.pointToWorld=function(t,e){return i.pointToWorldFrame(this.position,this.quaternion,t,e)},i.prototype.vectorToWorldFrame=function(t,e){e=e||new n;return this.quaternion.vmult(t,e),e},i.vectorToWorldFrame=function(t,e,o){return t.vmult(e,o),o},i.vectorToLocalFrame=function(t,e,o,i){i=i||new n;return e.w*=-1,e.vmult(o,i),e.w*=-1,i}},{"./Quaternion":44,"./Vec3":46}],46:[function(t,e,o){function i(t,e,o){this.x=t||0,this.y=e||0,this.z=o||0}e.exports=i;var n=t("./Mat3");i.ZERO=new i(0,0,0),i.UNIT_X=new i(1,0,0),i.UNIT_Y=new i(0,1,0),i.UNIT_Z=new i(0,0,1),i.prototype.cross=function(t,e){var o=t.x,n=t.y,s=t.z,r=this.x,a=this.y,c=this.z;return e=e||new i,e.x=a*s-c*n,e.y=c*o-r*s,e.z=r*n-a*o,e},i.prototype.set=function(t,e,o){return this.x=t,this.y=e,this.z=o,this},i.prototype.setZero=function(){this.x=this.y=this.z=0},i.prototype.vadd=function(t,e){if(!e)return new i(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},i.prototype.vsub=function(t,e){if(!e)return new i(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},i.prototype.crossmat=function(){return new n([0,-this.z,this.y,this.z,0,-this.x,-this.y,this.x,0])},i.prototype.normalize=function(){var t=this.x,e=this.y,o=this.z,i=Math.sqrt(t*t+e*e+o*o);if(i>0){var n=1/i;this.x*=n,this.y*=n,this.z*=n}else this.x=0,this.y=0,this.z=0;return i},i.prototype.unit=function(t){t=t||new i;var e=this.x,o=this.y,n=this.z,s=Math.sqrt(e*e+o*o+n*n);return s>0?(s=1/s,t.x=e*s,t.y=o*s,t.z=n*s):(t.x=1,t.y=0,t.z=0),t},i.prototype.norm=function(){var t=this.x,e=this.y,o=this.z;return Math.sqrt(t*t+e*e+o*o)},i.prototype.length=i.prototype.norm,i.prototype.norm2=function(){return this.dot(this)},i.prototype.lengthSquared=i.prototype.norm2,i.prototype.distanceTo=function(t){var e=this.x,o=this.y,i=this.z,n=t.x,s=t.y,r=t.z;return Math.sqrt((n-e)*(n-e)+(s-o)*(s-o)+(r-i)*(r-i))},i.prototype.distanceSquared=function(t){var e=this.x,o=this.y,i=this.z,n=t.x,s=t.y,r=t.z;return(n-e)*(n-e)+(s-o)*(s-o)+(r-i)*(r-i)},i.prototype.mult=function(t,e){e=e||new i;var o=this.x,n=this.y,s=this.z;return e.x=t*o,e.y=t*n,e.z=t*s,e},i.prototype.vmul=function(t,e){return e=e||new i,e.x=t.x*this.x,e.y=t.y*this.y,e.z=t.z*this.z,e},i.prototype.scale=i.prototype.mult,i.prototype.addScaledVector=function(t,e,o){return o=o||new i,o.x=this.x+t*e.x,o.y=this.y+t*e.y,o.z=this.z+t*e.z,o},i.prototype.dot=function(t){return this.x*t.x+this.y*t.y+this.z*t.z},i.prototype.isZero=function(){return 0===this.x&&0===this.y&&0===this.z},i.prototype.negate=function(t){return t=t||new i,t.x=-this.x,t.y=-this.y,t.z=-this.z,t};var s=new i,r=new i;i.prototype.tangents=function(t,e){var o=this.norm();if(o>0){var i=s,n=1/o;i.set(this.x*n,this.y*n,this.z*n);var a=r;Math.abs(i.x)<.9?(a.set(1,0,0),i.cross(a,t)):(a.set(0,1,0),i.cross(a,t)),i.cross(t,e)}else t.set(1,0,0),e.set(0,1,0)},i.prototype.toString=function(){return this.x+","+this.y+","+this.z},i.prototype.toArray=function(){return[this.x,this.y,this.z]},i.prototype.copy=function(t){return this.x=t.x,this.y=t.y,this.z=t.z,this},i.prototype.lerp=function(t,e,o){var i=this.x,n=this.y,s=this.z;o.x=i+(t.x-i)*e,o.y=n+(t.y-n)*e,o.z=s+(t.z-s)*e},i.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)},i.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 i;i.prototype.isAntiparallelTo=function(t,e){return this.negate(a),a.almostEquals(t,e)},i.prototype.clone=function(){return new i(this.x,this.y,this.z)}},{"./Mat3":43}],47:[function(t,e,o){function i(t){t=t||{},n.apply(this),this.id=i.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?i.STATIC:i.DYNAMIC,typeof t.type==typeof i.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 c,this.aabbNeedsUpdate=!0,this.wlambda=new s,t.shape&&this.addShape(t.shape),this.updateMassProperties()}e.exports=i;var n=t("../utils/EventTarget"),s=(t("../shapes/Shape"),t("../math/Vec3")),r=t("../math/Mat3"),a=t("../math/Quaternion"),c=(t("../material/Material"),t("../collision/AABB")),h=t("../shapes/Box");(i.prototype=new n).constructor=i,i.COLLIDE_EVENT_NAME="collide",i.DYNAMIC=1,i.STATIC=2,i.KINEMATIC=4,i.AWAKE=0,i.SLEEPY=1,i.SLEEPING=2,i.idCounter=0,i.wakeupEvent={type:"wakeup"},i.prototype.wakeUp=function(){var t=this.sleepState;this.sleepState=0,this._wakeUpAfterNarrowphase=!1,t===i.SLEEPING&&this.dispatchEvent(i.wakeupEvent)},i.prototype.sleep=function(){this.sleepState=i.SLEEPING,this.velocity.set(0,0,0),this.angularVelocity.set(0,0,0),this._wakeUpAfterNarrowphase=!1},i.sleepyEvent={type:"sleepy"},i.sleepEvent={type:"sleep"},i.prototype.sleepTick=function(t){if(this.allowSleep){var e=this.sleepState,o=this.velocity.norm2()+this.angularVelocity.norm2(),n=Math.pow(this.sleepSpeedLimit,2);e===i.AWAKE&&o<n?(this.sleepState=i.SLEEPY,this.timeLastSleepy=t,this.dispatchEvent(i.sleepyEvent)):e===i.SLEEPY&&o>n?this.wakeUp():e===i.SLEEPY&&t-this.timeLastSleepy>this.sleepTimeLimit&&(this.sleep(),this.dispatchEvent(i.sleepEvent))}},i.prototype.updateSolveMassProperties=function(){this.sleepState===i.SLEEPING||this.type===i.KINEMATIC?(this.invMassSolve=0,this.invInertiaSolve.setZero(),this.invInertiaWorldSolve.setZero()):(this.invMassSolve=this.invMass,this.invInertiaSolve.copy(this.invInertia),this.invInertiaWorldSolve.copy(this.invInertiaWorld))},i.prototype.pointToLocalFrame=function(t,e){e=e||new s;return t.vsub(this.position,e),this.quaternion.conjugate().vmult(e,e),e},i.prototype.vectorToLocalFrame=function(t,e){e=e||new s;return this.quaternion.conjugate().vmult(t,e),e},i.prototype.pointToWorldFrame=function(t,e){e=e||new s;return this.quaternion.vmult(t,e),e.vadd(this.position,e),e},i.prototype.vectorToWorldFrame=function(t,e){e=e||new s;return this.quaternion.vmult(t,e),e};var l=new s,u=new a;i.prototype.addShape=function(t,e,o){var i=new s,n=new a;return e&&i.copy(e),o&&n.copy(o),this.shapes.push(t),this.shapeOffsets.push(i),this.shapeOrientations.push(n),this.updateMassProperties(),this.updateBoundingRadius(),this.aabbNeedsUpdate=!0,t.body=this,this},i.prototype.updateBoundingRadius=function(){for(var t=this.shapes,e=this.shapeOffsets,o=t.length,i=0,n=0;n!==o;n++){var s=t[n];s.updateBoundingSphereRadius();var r=e[n].norm(),a=s.boundingSphereRadius;r+a>i&&(i=r+a)}this.boundingRadius=i};var p=new c;i.prototype.computeAABB=function(){for(var t=this.shapes,e=this.shapeOffsets,o=this.shapeOrientations,i=t.length,n=l,s=u,r=this.quaternion,a=this.aabb,c=p,h=0;h!==i;h++){var d=t[h];r.vmult(e[h],n),n.vadd(this.position,n),o[h].mult(r,s),d.calculateWorldAABB(n,s,c.lowerBound,c.upperBound),0===h?a.copy(c):a.extend(c)}this.aabbNeedsUpdate=!1};var d=new r,y=new r;new r;i.prototype.updateInertiaWorld=function(t){var e=this.invInertia;if(e.x!==e.y||e.y!==e.z||t){var o=d,i=y;o.setRotationFromQuaternion(this.quaternion),o.transpose(i),o.scale(e,o),o.mmult(i,this.invInertiaWorld)}else;};new s;var v=new s;i.prototype.applyForce=function(t,e){if(this.type===i.DYNAMIC){var o=v;e.cross(t,o),this.force.vadd(t,this.force),this.torque.vadd(o,this.torque)}};var f=new s,m=new s;i.prototype.applyLocalForce=function(t,e){if(this.type===i.DYNAMIC){var o=f,n=m;this.vectorToWorldFrame(t,o),this.vectorToWorldFrame(e,n),this.applyForce(o,n)}};new s;var w=new s,g=new s;i.prototype.applyImpulse=function(t,e){if(this.type===i.DYNAMIC){var o=e,n=w;n.copy(t),n.mult(this.invMass,n),this.velocity.vadd(n,this.velocity);var s=g;o.cross(t,s),this.invInertiaWorld.vmult(s,s),this.angularVelocity.vadd(s,this.angularVelocity)}};var x=new s,b=new s;i.prototype.applyLocalImpulse=function(t,e){if(this.type===i.DYNAMIC){var o=x,n=b;this.vectorToWorldFrame(t,o),this.vectorToWorldFrame(e,n),this.applyImpulse(o,n)}};var E=new s;i.prototype.updateMassProperties=function(){var t=E;this.invMass=this.mass>0?1/this.mass:0;var e=this.inertia,o=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),h.calculateInertia(t,this.mass,e),this.invInertia.set(e.x>0&&!o?1/e.x:0,e.y>0&&!o?1/e.y:0,e.z>0&&!o?1/e.z:0),this.updateInertiaWorld(!0)},i.prototype.getVelocityAtWorldPoint=function(t,e){var o=new s;return t.vsub(this.position,o),this.angularVelocity.cross(o,e),this.velocity.vadd(e,e),e};new s,new s,new a,new a;i.prototype.integrate=function(t,e,o){if(this.previousPosition.copy(this.position),this.previousQuaternion.copy(this.quaternion),(this.type===i.DYNAMIC||this.type===i.KINEMATIC)&&this.sleepState!==i.SLEEPING){var n=this.velocity,s=this.angularVelocity,r=this.position,a=this.force,c=this.torque,h=this.quaternion,l=this.invMass,u=this.invInertiaWorld,p=this.linearFactor,d=l*t;n.x+=a.x*d*p.x,n.y+=a.y*d*p.y,n.z+=a.z*d*p.z;var y=u.elements,v=this.angularFactor,f=c.x*v.x,m=c.y*v.y,w=c.z*v.z;s.x+=t*(y[0]*f+y[1]*m+y[2]*w),s.y+=t*(y[3]*f+y[4]*m+y[5]*w),s.z+=t*(y[6]*f+y[7]*m+y[8]*w),r.x+=n.x*t,r.y+=n.y*t,r.z+=n.z*t,h.integrate(this.angularVelocity,t,this.angularFactor,h),e&&(o?h.normalizeFast():h.normalize()),this.aabbNeedsUpdate=!0,this.updateInertiaWorld()}}},{"../collision/AABB":18,"../material/Material":41,"../math/Mat3":43,"../math/Quaternion":44,"../math/Vec3":46,"../shapes/Box":53,"../shapes/Shape":59,"../utils/EventTarget":65}],48:[function(t,e,o){function i(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,o){var i=b,n=E,s=A,r=B;return e.vsub(t.position,i),i.cross(o,n),t.invInertiaWorld.vmult(n,r),r.cross(i,s),t.invMass+o.dot(s)}t("./Body");var s=t("../math/Vec3"),r=t("../math/Quaternion"),a=(t("../collision/RaycastResult"),t("../collision/Ray")),c=t("../objects/WheelInfo");e.exports=i;new s,new s,new s;var h=new s,l=new s,u=new s;new a;i.prototype.addWheel=function(t){var e=new c(t=t||{}),o=this.wheelInfos.length;return this.wheelInfos.push(e),o},i.prototype.setSteeringValue=function(t,e){this.wheelInfos[e].steering=t};new s;i.prototype.applyEngineForce=function(t,e){this.wheelInfos[e].engineForce=t},i.prototype.setBrake=function(t,e){this.wheelInfos[e].brake=t},i.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},i.prototype.getVehicleAxisWorld=function(t,e){e.set(0===t?1:0,1===t?1:0,2===t?1:0),this.chassisBody.vectorToWorldFrame(e,e)},i.prototype.updateVehicle=function(t){for(var e=this.wheelInfos,o=e.length,i=this.chassisBody,n=0;n<o;n++)this.updateWheelTransform(n);this.currentVehicleSpeedKmHour=3.6*i.velocity.norm();var r=new s;this.getVehicleAxisWorld(this.indexForwardAxis,r),r.dot(i.velocity)<0&&(this.currentVehicleSpeedKmHour*=-1);for(n=0;n<o;n++)this.castRay(e[n]);this.updateSuspension(t);for(var a=new s,c=new s,n=0;n<o;n++){var h=(d=e[n]).suspensionForce;h>d.maxSuspensionForce&&(h=d.maxSuspensionForce),d.raycastResult.hitNormalWorld.scale(h*t,a),d.raycastResult.hitPointWorld.vsub(i.position,c),i.applyImpulse(a,c)}this.updateFriction(t);var l=new s,u=new s,p=new s;for(n=0;n<o;n++){var d=e[n];i.getVelocityAtWorldPoint(d.chassisConnectionPointWorld,p);var y=1;switch(this.indexUpAxis){case 1:y=-1}if(d.isInContact){this.getVehicleAxisWorld(this.indexForwardAxis,u);var v=u.dot(d.raycastResult.hitNormalWorld);d.raycastResult.hitNormalWorld.scale(v,l),u.vsub(l,u);var f=u.dot(p);d.deltaRotation=y*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}},i.prototype.updateSuspension=function(t){for(var e=this.chassisBody.mass,o=this.wheelInfos,i=o.length,n=0;n<i;n++){var s=o[n];if(s.isInContact){var r,a=s.suspensionRestLength-s.suspensionLength;r=s.suspensionStiffness*a*s.clippedInvContactDotSuspension;var c=s.suspensionRelativeVelocity;r-=(c<0?s.dampingCompression:s.dampingRelaxation)*c,s.suspensionForce=r*e,s.suspensionForce<0&&(s.suspensionForce=0)}else s.suspensionForce=0}},i.prototype.removeFromWorld=function(t){this.constraints;t.remove(this.chassisBody),t.removeEventListener("preStep",this.preStepCallback),this.world=null};var p=new s,d=new s;i.prototype.castRay=function(t){var e=p,o=d;this.updateWheelTransformWorld(t);var i=this.chassisBody,n=-1,r=t.suspensionRestLength+t.radius;t.directionWorld.scale(r,e);var a=t.chassisConnectionPointWorld;a.vadd(e,o);var c=t.raycastResult;c.reset();var h=i.collisionResponse;i.collisionResponse=!1,this.world.rayTest(a,o,c),i.collisionResponse=h;var l=c.body;if(t.raycastResult.groundObject=0,l){n=c.distance,t.raycastResult.hitNormalWorld=c.hitNormalWorld,t.isInContact=!0;var u=c.distance;t.suspensionLength=u-t.radius;var y=t.suspensionRestLength-t.maxSuspensionTravel,v=t.suspensionRestLength+t.maxSuspensionTravel;t.suspensionLength<y&&(t.suspensionLength=y),t.suspensionLength>v&&(t.suspensionLength=v,t.raycastResult.reset());var f=t.raycastResult.hitNormalWorld.dot(t.directionWorld),m=new s;i.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},i.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)},i.prototype.updateWheelTransform=function(t){var e=h,o=l,i=u,n=this.wheelInfos[t];this.updateWheelTransformWorld(n),n.directionLocal.scale(-1,e),o.copy(n.axleLocal),e.cross(o,i),i.normalize(),o.normalize();var s=n.steering,a=new r;a.setFromAxisAngle(e,s);var c=new r;c.setFromAxisAngle(o,n.rotation);var p=n.worldTransform.quaternion;this.chassisBody.quaternion.mult(a,p),p.mult(c,p),p.normalize();var d=n.worldTransform.position;d.copy(n.directionWorld),d.scale(n.suspensionLength,d),d.vadd(n.chassisConnectionPointWorld,d)};var y=[new s(1,0,0),new s(0,1,0),new s(0,0,1)];i.prototype.getWheelTransformWorld=function(t){return this.wheelInfos[t].worldTransform};var v=new s,f=[],m=[];i.prototype.updateFriction=function(t){for(var e=v,o=this.wheelInfos,i=o.length,r=this.chassisBody,a=m,c=f,h=0;h<i;h++){(d=(P=o[h]).raycastResult.body)&&0,P.sideImpulse=0,P.forwardImpulse=0,a[h]||(a[h]=new s),c[h]||(c[h]=new s)}for(h=0;h<i;h++){if(d=(P=o[h]).raycastResult.body){var l=c[h];this.getWheelTransformWorld(h).vectorToWorldFrame(y[this.indexRightAxis],l);var u=P.raycastResult.hitNormalWorld,p=l.dot(u);u.scale(p,e),l.vsub(e,l),l.normalize(),u.cross(l,a[h]),a[h].normalize(),P.sideImpulse=function(t,e,o,i,n,s){if(n.norm2()>1.1)return 0;var r=C,a=S,c=R;return t.getVelocityAtWorldPoint(e,r),o.getVelocityAtWorldPoint(i,a),r.vsub(a,c),-.2*n.dot(c)*(1/(t.invMass+o.invMass))}(r,P.raycastResult.hitPointWorld,d,P.raycastResult.hitPointWorld,l),P.sideImpulse*=1}}this.sliding=!1;for(h=0;h<i;h++){var d=(P=o[h]).raycastResult.body,b=0;if(P.slipInfo=1,d){var E=P.brake?P.brake:0;b=function(t,e,o,i,s){var r=0,a=o,c=w,h=g,l=x;return t.getVelocityAtWorldPoint(a,c),e.getVelocityAtWorldPoint(a,h),c.vsub(h,l),r=-i.dot(l)*(1/(n(t,o,i)+n(e,o,i))),s<r&&(r=s),r<-s&&(r=-s),r}(r,d,P.raycastResult.hitPointWorld,a[h],E);k=E/(b+=P.engineForce*t);P.slipInfo*=k}if(P.forwardImpulse=0,P.skidInfo=1,d){P.skidInfo=1;var A=P.suspensionForce*t*P.frictionSlip,B=A*A;P.forwardImpulse=b;var M=.5*P.forwardImpulse,T=1*P.sideImpulse,z=M*M+T*T;if(P.sliding=!1,z>B){this.sliding=!0,P.sliding=!0;var k=A/Math.sqrt(z);P.skidInfo*=k}}}if(this.sliding)for(h=0;h<i;h++){0!==(P=o[h]).sideImpulse&&P.skidInfo<1&&(P.forwardImpulse*=P.skidInfo,P.sideImpulse*=P.skidInfo)}for(h=0;h<i;h++){var P=o[h],q=new s;if(P.raycastResult.hitPointWorld.vsub(r.position,q),0!==P.forwardImpulse){var L=new s;a[h].scale(P.forwardImpulse,L),r.applyImpulse(L,q)}if(0!==P.sideImpulse){var d=P.raycastResult.body,V=new s;P.raycastResult.hitPointWorld.vsub(d.position,V);var F=new s;c[h].scale(P.sideImpulse,F),r.vectorToLocalFrame(q,q),q["xyz"[this.indexUpAxis]]*=P.rollInfluence,r.vectorToWorldFrame(q,q),r.applyImpulse(F,q),F.scale(-1,F),d.applyImpulse(F,V)}}};var w=new s,g=new s,x=new s,b=new s,E=new s,A=new s,B=new s,C=new s,S=new s,R=new s},{"../collision/Ray":25,"../collision/RaycastResult":26,"../math/Quaternion":44,"../math/Vec3":46,"../objects/WheelInfo":52,"./Body":47}],49:[function(t,e,o){function i(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"),c=t("../constraints/HingeConstraint");e.exports=i,i.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 o=void 0!==t.position?t.position.clone():new a,i=new a;this.chassisBody.pointToWorldFrame(o,i),e.position.set(i.x,i.y,i.z);var r=void 0!==t.axis?t.axis.clone():new a(0,1,0);this.wheelAxes.push(r);var h=new c(this.chassisBody,e,{pivotA:o,axisA:r,pivotB:a.ZERO,axisB:r,collideConnected:!1});return this.constraints.push(h),this.wheelBodies.length-1},i.prototype.setSteeringValue=function(t,e){var o=this.wheelAxes[e],i=Math.cos(t),n=Math.sin(t),s=o.x,r=o.y;this.constraints[e].axisA.set(i*s-n*r,n*s+i*r,0)},i.prototype.setMotorSpeed=function(t,e){var o=this.constraints[e];o.enableMotor(),o.motorTargetVelocity=t},i.prototype.disableMotor=function(t){this.constraints[t].disableMotor()};var h=new a;i.prototype.setWheelForce=function(t,e){this.wheelForces[e]=t},i.prototype.applyWheelForce=function(t,e){var o=this.wheelAxes[e],i=this.wheelBodies[e],n=i.torque;o.scale(t,h),i.vectorToWorldFrame(h,h),n.vadd(h,n)},i.prototype.addToWorld=function(t){for(var e=this.constraints,o=this.wheelBodies.concat([this.chassisBody]),i=0;i<o.length;i++)t.addBody(o[i]);for(i=0;i<e.length;i++)t.addConstraint(e[i]);t.addEventListener("preStep",this._update.bind(this))},i.prototype._update=function(){for(var t=this.wheelForces,e=0;e<t.length;e++)this.applyWheelForce(t[e],e)},i.prototype.removeFromWorld=function(t){for(var e=this.constraints,o=this.wheelBodies.concat([this.chassisBody]),i=0;i<o.length;i++)t.remove(o[i]);for(i=0;i<e.length;i++)t.removeConstraint(e[i])};var l=new a;i.prototype.getWheelSpeed=function(t){var e=this.wheelAxes[t],o=this.wheelBodies[t].angularVelocity;return this.chassisBody.vectorToWorldFrame(e,l),o.dot(l)}},{"../constraints/HingeConstraint":31,"../math/Vec3":46,"../shapes/Box":53,"../shapes/Sphere":60,"./Body":47}],50:[function(t,e,o){function i(){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=i;t("../shapes/Shape");var n=t("../math/Vec3");t("../math/Quaternion"),t("../shapes/Particle"),t("../objects/Body"),t("../material/Material");i.prototype.add=function(t){this.particles.push(t),this.neighbors.length<this.particles.length&&this.neighbors.push([])},i.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;i.prototype.getNeighbors=function(t,e){for(var o=this.particles.length,i=t.id,n=this.smoothingRadius*this.smoothingRadius,r=s,a=0;a!==o;a++){var c=this.particles[a];c.position.vsub(t.position,r),i!==c.id&&r.norm2()<n&&e.push(c)}};var r=new n,a=new n,c=new n,h=new n,l=new n,u=new n;i.prototype.update=function(){for(var t=this.particles.length,e=r,o=this.speedOfSound,i=this.eps,n=0;n!==t;n++){var s=this.particles[n];(C=this.neighbors[n]).length=0,this.getNeighbors(s,C),C.push(this.particles[n]);for(var p=C.length,d=0,y=0;y!==p;y++){s.position.vsub(C[y].position,e);var v=e.norm(),f=this.w(v);d+=C[y].mass*f}this.densities[n]=d,this.pressures[n]=o*o*(this.densities[n]-this.density)}for(var m=a,w=c,g=h,x=l,b=u,n=0;n!==t;n++){var E=this.particles[n];m.set(0,0,0),w.set(0,0,0);for(var A,B,C=this.neighbors[n],p=C.length,y=0;y!==p;y++){var S=C[y];E.position.vsub(S.position,x);var R=x.norm();A=-S.mass*(this.pressures[n]/(this.densities[n]*this.densities[n]+i)+this.pressures[y]/(this.densities[y]*this.densities[y]+i)),this.gradw(x,g),g.mult(A,g),m.vadd(g,m),S.velocity.vsub(E.velocity,b),b.mult(1/(1e-4+this.densities[n]*this.densities[y])*this.viscosity*S.mass,b),B=this.nablaw(R),b.mult(B,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)}},i.prototype.w=function(t){var e=this.smoothingRadius;return 315/(64*Math.PI*Math.pow(e,9))*Math.pow(e*e-t*t,3)},i.prototype.gradw=function(t,e){var o=t.norm(),i=this.smoothingRadius;t.mult(945/(32*Math.PI*Math.pow(i,9))*Math.pow(i*i-o*o,2),e)},i.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":41,"../math/Quaternion":44,"../math/Vec3":46,"../objects/Body":47,"../shapes/Particle":57,"../shapes/Shape":59}],51:[function(t,e,o){function i(t,e,o){o=o||{},this.restLength="number"==typeof o.restLength?o.restLength:1,this.stiffness=o.stiffness||100,this.damping=o.damping||1,this.bodyA=t,this.bodyB=e,this.localAnchorA=new n,this.localAnchorB=new n,o.localAnchorA&&this.localAnchorA.copy(o.localAnchorA),o.localAnchorB&&this.localAnchorB.copy(o.localAnchorB),o.worldAnchorA&&this.setWorldAnchorA(o.worldAnchorA),o.worldAnchorB&&this.setWorldAnchorB(o.worldAnchorB)}var n=t("../math/Vec3");e.exports=i,i.prototype.setWorldAnchorA=function(t){this.bodyA.pointToLocalFrame(t,this.localAnchorA)},i.prototype.setWorldAnchorB=function(t){this.bodyB.pointToLocalFrame(t,this.localAnchorB)},i.prototype.getWorldAnchorA=function(t){this.bodyA.pointToWorldFrame(this.localAnchorA,t)},i.prototype.getWorldAnchorB=function(t){this.bodyB.pointToWorldFrame(this.localAnchorB,t)};var s=new n,r=new n,a=new n,c=new n,h=new n,l=new n,u=new n,p=new n,d=new n,y=new n,v=new n;i.prototype.applyForce=function(){var t=this.stiffness,e=this.damping,o=this.restLength,i=this.bodyA,n=this.bodyB,f=s,m=r,w=a,g=c,x=v,b=h,E=l,A=u,B=p,C=d,S=y;this.getWorldAnchorA(b),this.getWorldAnchorB(E),b.vsub(i.position,A),E.vsub(n.position,B),E.vsub(b,f);var R=f.norm();m.copy(f),m.normalize(),n.velocity.vsub(i.velocity,w),n.angularVelocity.cross(B,x),w.vadd(x,w),i.angularVelocity.cross(A,x),w.vsub(x,w),m.mult(-t*(R-o)-e*w.dot(m),g),i.force.vsub(g,i.force),n.force.vadd(g,n.force),A.cross(g,C),B.cross(g,S),i.torque.vsub(C,i.torque),n.torque.vadd(S,n.torque)}},{"../math/Vec3":46}],52:[function(t,e,o){function i(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=i;var c=new n,h=new n,c=new n;i.prototype.updateWheel=function(t){var e=this.raycastResult;if(this.isInContact){var o=e.hitNormalWorld.dot(e.directionWorld);e.hitPointWorld.vsub(t.position,h),t.getVelocityAtWorldPoint(h,c);var i=e.hitNormalWorld.dot(c);if(o>=-.1)this.suspensionRelativeVelocity=0,this.clippedInvContactDotSuspension=10;else{var n=-1/o;this.suspensionRelativeVelocity=i*n,this.clippedInvContactDotSuspension=n}}else e.suspensionLength=this.suspensionRestLength,this.suspensionRelativeVelocity=0,e.directionWorld.scale(-1,e.hitNormalWorld),this.clippedInvContactDotSuspension=1}},{"../collision/RaycastResult":26,"../math/Transform":45,"../math/Vec3":46,"../utils/Utils":69}],53:[function(t,e,o){function i(t){n.call(this),this.type=n.types.BOX,this.halfExtents=t,this.convexPolyhedronRepresentation=null,this.updateConvexPolyhedronRepresentation(),this.updateBoundingSphereRadius()}e.exports=i;var n=t("./Shape"),s=t("../math/Vec3"),r=t("./ConvexPolyhedron");(i.prototype=new n).constructor=i,i.prototype.updateConvexPolyhedronRepresentation=function(){var t=this.halfExtents.x,e=this.halfExtents.y,o=this.halfExtents.z,i=s,n=[new i(-t,-e,-o),new i(t,-e,-o),new i(t,e,-o),new i(-t,e,-o),new i(-t,-e,o),new i(t,-e,o),new i(t,e,o),new i(-t,e,o)],a=(new i(0,0,1),new i(0,1,0),new i(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},i.prototype.calculateLocalInertia=function(t,e){return e=e||new s,i.calculateInertia(this.halfExtents,t,e),e},i.calculateInertia=function(t,e,o){var i=t;o.x=1/12*e*(2*i.y*2*i.y+2*i.z*2*i.z),o.y=1/12*e*(2*i.x*2*i.x+2*i.z*2*i.z),o.z=1/12*e*(2*i.y*2*i.y+2*i.x*2*i.x)},i.prototype.getSideNormals=function(t,e){var o=t,i=this.halfExtents;if(o[0].set(i.x,0,0),o[1].set(0,i.y,0),o[2].set(0,0,i.z),o[3].set(-i.x,0,0),o[4].set(0,-i.y,0),o[5].set(0,0,-i.z),void 0!==e)for(var n=0;n!==o.length;n++)e.vmult(o[n],o[n]);return o},i.prototype.volume=function(){return 8*this.halfExtents.x*this.halfExtents.y*this.halfExtents.z},i.prototype.updateBoundingSphereRadius=function(){this.boundingSphereRadius=this.halfExtents.norm()};var a=new s;new s;i.prototype.forEachWorldCorner=function(t,e,o){for(var i=this.halfExtents,n=[[i.x,i.y,i.z],[-i.x,i.y,i.z],[-i.x,-i.y,i.z],[-i.x,-i.y,-i.z],[i.x,-i.y,-i.z],[i.x,i.y,-i.z],[-i.x,i.y,-i.z],[i.x,-i.y,i.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),o(a.x,a.y,a.z)};var c=[new s,new s,new s,new s,new s,new s,new s,new s];i.prototype.calculateWorldAABB=function(t,e,o,i){var n=this.halfExtents;c[0].set(n.x,n.y,n.z),c[1].set(-n.x,n.y,n.z),c[2].set(-n.x,-n.y,n.z),c[3].set(-n.x,-n.y,-n.z),c[4].set(n.x,-n.y,-n.z),c[5].set(n.x,n.y,-n.z),c[6].set(-n.x,n.y,-n.z),c[7].set(n.x,-n.y,n.z);r=c[0];e.vmult(r,r),t.vadd(r,r),i.copy(r),o.copy(r);for(var s=1;s<8;s++){var r=c[s];e.vmult(r,r),t.vadd(r,r);var a=r.x,h=r.y,l=r.z;a>i.x&&(i.x=a),h>i.y&&(i.y=h),l>i.z&&(i.z=l),a<o.x&&(o.x=a),h<o.y&&(o.y=h),l<o.z&&(o.z=l)}}},{"../math/Vec3":46,"./ConvexPolyhedron":54,"./Shape":59}],54:[function(t,e,o){function i(t,e,o){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=o?o.slice():null,this.computeEdges(),this.updateBoundingSphereRadius()}e.exports=i;var n=t("./Shape"),s=t("../math/Vec3"),r=(t("../math/Quaternion"),t("../math/Transform"));(i.prototype=new n).constructor=i;var a=new s;i.prototype.computeEdges=function(){var t=this.faces,e=this.vertices,o=(e.length,this.uniqueEdges);o.length=0;for(var i=a,n=0;n!==t.length;n++)for(var s=t[n],r=s.length,c=0;c!==r;c++){var h=(c+1)%r;e[s[c]].vsub(e[s[h]],i),i.normalize();for(var l=!1,u=0;u!==o.length;u++)if(o[u].almostEquals(i)||o[u].almostEquals(i)){l=!0;break}l||o.push(i.clone())}},i.prototype.computeNormals=function(){this.faceNormals.length=this.faces.length;for(var t=0;t<this.faces.length;t++){for(i=0;i<this.faces[t].length;i++)if(!this.vertices[this.faces[t][i]])throw new Error("Vertex "+this.faces[t][i]+" not found!");var e=this.faceNormals[t]||new s;this.getFaceNormal(t,e),e.negate(e),this.faceNormals[t]=e;var o=this.vertices[this.faces[t][0]];if(e.dot(o)<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 i=0;i<this.faces[t].length;i++)console.warn(".vertices["+this.faces[t][i]+"] = Vec3("+this.vertices[this.faces[t][i]].toString()+")")}}};var c=new s,h=new s;i.computeNormal=function(t,e,o,i){e.vsub(t,h),o.vsub(e,c),c.cross(h,i),i.isZero()||i.normalize()},i.prototype.getFaceNormal=function(t,e){var o=this.faces[t],n=this.vertices[o[0]],s=this.vertices[o[1]],r=this.vertices[o[2]];return i.computeNormal(n,s,r,e)};var l=new s;i.prototype.clipAgainstHull=function(t,e,o,i,n,r,a,c,h){for(var u=l,p=-1,d=-Number.MAX_VALUE,y=0;y<o.faces.length;y++){u.copy(o.faceNormals[y]),n.vmult(u,u);var v=u.dot(r);v>d&&(d=v,p=y)}for(var f=[],m=o.faces[p],w=m.length,g=0;g<w;g++){var x=o.vertices[m[g]],b=new s;b.copy(x),n.vmult(b,b),i.vadd(b,b),f.push(b)}p>=0&&this.clipFaceAgainstHull(r,t,e,f,a,c,h)};var u=new s,p=new s,d=new s,y=new s,v=new s,f=new s;i.prototype.findSeparatingAxis=function(t,e,o,i,n,s,r,a){var c=u,h=p,l=d,m=y,w=v,g=f,x=Number.MAX_VALUE,b=this;if(b.uniqueAxes)for(A=0;A!==b.uniqueAxes.length;A++){o.vmult(b.uniqueAxes[A],c);if(!1===(S=b.testSepAxis(c,t,e,o,i,n)))return!1;S<x&&(x=S,s.copy(c))}else for(var E=r?r.length:b.faces.length,A=0;A<E;A++){C=r?r[A]:A;c.copy(b.faceNormals[C]),o.vmult(c,c);if(!1===(S=b.testSepAxis(c,t,e,o,i,n)))return!1;S<x&&(x=S,s.copy(c))}if(t.uniqueAxes)for(A=0;A!==t.uniqueAxes.length;A++){n.vmult(t.uniqueAxes[A],h),0;S=b.testSepAxis(h,t,e,o,i,n);if(!1===S)return!1;S<x&&(x=S,s.copy(h))}else for(var B=a?a.length:t.faces.length,A=0;A<B;A++){var C=a?a[A]:A;h.copy(t.faceNormals[C]),n.vmult(h,h),0;var S;if(!1===(S=b.testSepAxis(h,t,e,o,i,n)))return!1;S<x&&(x=S,s.copy(h))}for(var R=0;R!==b.uniqueEdges.length;R++){o.vmult(b.uniqueEdges[R],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 T=b.testSepAxis(g,t,e,o,i,n);if(!1===T)return!1;T<x&&(x=T,s.copy(g))}}return i.vsub(e,l),l.dot(s)>0&&s.negate(s),!0};var m=[],w=[];i.prototype.testSepAxis=function(t,e,o,n,s,r){i.project(this,t,o,n,m),i.project(e,t,s,r,w);var a=m[0],c=m[1],h=w[0],l=w[1];if(a<l||h<c)return!1;var u=a-l,p=h-c;return u<p?u:p};var g=new s,x=new s;i.prototype.calculateLocalInertia=function(t,e){this.computeLocalAABB(g,x);var o=x.x-g.x,i=x.y-g.y,n=x.z-g.z;e.x=1/12*t*(2*i*2*i+2*n*2*n),e.y=1/12*t*(2*o*2*o+2*n*2*n),e.z=1/12*t*(2*i*2*i+2*o*2*o)},i.prototype.getPlaneConstantOfFace=function(t){var e=this.faces[t],o=this.faceNormals[t],i=this.vertices[e[0]];return-o.dot(i)};var b=new s,E=new s,A=new s,B=new s,C=new s,S=new s,R=new s,M=new s;i.prototype.clipFaceAgainstHull=function(t,e,o,i,n,s,r){for(var a=b,c=E,h=A,l=B,u=C,p=S,d=R,y=M,v=this,f=i,m=[],w=-1,g=Number.MAX_VALUE,x=0;x<v.faces.length;x++){a.copy(v.faceNormals[x]),o.vmult(a,a);var T=a.dot(t);T<g&&(g=T,w=x)}if(!(w<0)){var z=v.faces[w];z.connectedFaces=[];for(O=0;O<v.faces.length;O++)for(var k=0;k<v.faces[O].length;k++)-1!==z.indexOf(v.faces[O][k])&&O!==w&&-1===z.connectedFaces.indexOf(O)&&z.connectedFaces.push(O);f.length;for(var P=z.length,q=0;q<P;q++){var L=v.vertices[z[q]],V=v.vertices[z[(q+1)%P]];L.vsub(V,c),h.copy(c),o.vmult(h,h),e.vadd(h,h),l.copy(this.faceNormals[w]),o.vmult(l,l),e.vadd(l,l),h.cross(l,u),u.negate(u),p.copy(L),o.vmult(p,p),e.vadd(p,p);p.dot(u);var F=z.connectedFaces[q];d.copy(this.faceNormals[F]);N=this.getPlaneConstantOfFace(F);y.copy(d),o.vmult(y,y);I=N-y.dot(e);for(this.clipFaceAgainstPlane(f,m,y,I);f.length;)f.shift();for(;m.length;)f.push(m.shift())}d.copy(this.faceNormals[w]);var N=this.getPlaneConstantOfFace(w);y.copy(d),o.vmult(y,y);for(var I=N-y.dot(e),O=0;O<f.length;O++){var j=y.dot(f[O])+I;if(j<=n&&(console.log("clamped: depth="+j+" to minDist="+n),j=n),j<=s){var W=f[O];if(j<=0){var D={point:W,normal:y,depth:j};r.push(D)}}}}},i.prototype.clipFaceAgainstPlane=function(t,e,o,i){var n,r,a=t.length;if(a<2)return e;var c=t[t.length-1],h=t[0];n=o.dot(c)+i;for(var l=0;l<a;l++){if(h=t[l],r=o.dot(h)+i,n<0)if(r<0){(u=new s).copy(h),e.push(u)}else{u=new s;c.lerp(h,n/(n-r),u),e.push(u)}else if(r<0){var u=new s;c.lerp(h,n/(n-r),u),e.push(u),e.push(h)}c=h,n=r}return e},i.prototype.computeWorldVertices=function(t,e){for(var o=this.vertices.length;this.worldVertices.length<o;)this.worldVertices.push(new s);for(var i=this.vertices,n=this.worldVertices,r=0;r!==o;r++)e.vmult(i[r],n[r]),t.vadd(n[r],n[r]);this.worldVerticesNeedsUpdate=!1};new s;i.prototype.computeLocalAABB=function(t,e){var o=this.vertices.length,i=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<o;n++){var s=i[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)}},i.prototype.computeWorldFaceNormals=function(t){for(var e=this.faceNormals.length;this.worldFaceNormals.length<e;)this.worldFaceNormals.push(new s);for(var o=this.faceNormals,i=this.worldFaceNormals,n=0;n!==e;n++)t.vmult(o[n],i[n]);this.worldFaceNormalsNeedsUpdate=!1},i.prototype.updateBoundingSphereRadius=function(){for(var t=0,e=this.vertices,o=0,i=e.length;o!==i;o++){var n=e[o].norm2();n>t&&(t=n)}this.boundingSphereRadius=Math.sqrt(t)};var T=new s;i.prototype.calculateWorldAABB=function(t,e,o,i){for(var n,s,r,a,c,h,l=this.vertices.length,u=this.vertices,p=0;p<l;p++){T.copy(u[p]),e.vmult(T,T),t.vadd(T,T);var d=T;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>c||void 0===c)&&(c=d.y),d.z<r||void 0===r?r=d.z:(d.z>h||void 0===h)&&(h=d.z)}o.set(n,s,r),i.set(a,c,h)},i.prototype.volume=function(){return 4*Math.PI*this.boundingSphereRadius/3},i.prototype.getAveragePointLocal=function(t){t=t||new s;for(var e=this.vertices.length,o=this.vertices,i=0;i<e;i++)t.vadd(o[i],t);return t.mult(1/e,t),t},i.prototype.transformAllPoints=function(t,e){var o=this.vertices.length,i=this.vertices;if(e){for(n=0;n<o;n++){s=i[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<o;n++){var s;(s=i[n]).vadd(t,s)}};var z=new s,k=new s,P=new s;i.prototype.pointIsInside=function(t){var e=this.vertices.length,o=this.vertices,i=this.faces,n=this.faceNormals,s=this.faces.length,r=z;this.getAveragePointLocal(r);for(var a=0;a<s;a++){this.faces[a].length;var e=n[a],c=o[i[a][0]],h=k;t.vsub(c,h);var l=e.dot(h),u=P;r.vsub(c,u);var p=e.dot(u);if(l<0&&p>0||l>0&&p<0)return!1}return-1};new s;var q=new s,L=new s;i.project=function(t,e,o,i,n){var s=t.vertices.length,a=q,c=0,h=0,l=L,u=t.vertices;l.setZero(),r.vectorToLocalFrame(o,i,e,a),r.pointToLocalFrame(o,i,l,l);var p=l.dot(a);h=c=u[0].dot(a);for(var d=1;d<s;d++){var y=u[d].dot(a);y>c&&(c=y),y<h&&(h=y)}if(h-=p,c-=p,h>c){var v=h;h=c,c=v}n[0]=c,n[1]=h}},{"../math/Quaternion":44,"../math/Transform":45,"../math/Vec3":46,"./Shape":59}],55:[function(t,e,o){function i(t,e,o,i){var a=i,c=[],h=[],l=[],u=[],p=[],d=Math.cos,y=Math.sin;c.push(new s(e*d(0),e*y(0),.5*-o)),u.push(0),c.push(new s(t*d(0),t*y(0),.5*o)),p.push(1);for(w=0;w<a;w++){var v=2*Math.PI/a*(w+1),f=2*Math.PI/a*(w+.5);w<a-1?(c.push(new s(e*d(v),e*y(v),.5*-o)),u.push(2*w+2),c.push(new s(t*d(v),t*y(v),.5*o)),p.push(2*w+3),l.push([2*w+2,2*w+3,2*w+1,2*w])):l.push([0,1,2*w+1,2*w]),(a%2==1||w<a/2)&&h.push(new s(d(f),y(f),0))}l.push(p),h.push(new s(0,0,1));for(var m=[],w=0;w<u.length;w++)m.push(u[u.length-w-1]);l.push(m),this.type=n.types.CONVEXPOLYHEDRON,r.call(this,c,l,h)}e.exports=i;var n=t("./Shape"),s=t("../math/Vec3"),r=(t("../math/Quaternion"),t("./ConvexPolyhedron"));i.prototype=new r},{"../math/Quaternion":44,"../math/Vec3":46,"./ConvexPolyhedron":54,"./Shape":59}],56:[function(t,e,o){function i(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=i,(i.prototype=new n).update=function(){this._cachedPillars={}},i.prototype.updateMinValue=function(){for(var t=this.data,e=t[0][0],o=0;o!==t.length;o++)for(var i=0;i!==t[o].length;i++){var n=t[o][i];n<e&&(e=n)}this.minValue=e},i.prototype.updateMaxValue=function(){for(var t=this.data,e=t[0][0],o=0;o!==t.length;o++)for(var i=0;i!==t[o].length;i++){var n=t[o][i];n>e&&(e=n)}this.maxValue=e},i.prototype.setHeightValueAtIndex=function(t,e,o){this.data[t][e]=o,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)},i.prototype.getRectMinMax=function(t,e,o,i,n){n=n||[];for(var s=this.data,r=this.minValue,a=t;a<=o;a++)for(var c=e;c<=i;c++){var h=s[a][c];h>r&&(r=h)}n[0]=this.minValue,n[1]=r},i.prototype.getIndexOfPosition=function(t,e,o,i){var n=this.elementSize,s=this.data,r=Math.floor(t/n),a=Math.floor(e/n);return o[0]=r,o[1]=a,i&&(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 c=[],h=new r,l=new r,u=new r,p=new r;i.prototype.getTriangleAt=function(t,e,o,i,n,s){var r=c;this.getIndexOfPosition(t,e,r,o);var a=r[0],h=r[1],l=this.data;o&&(a=Math.min(l.length-2,Math.max(0,a)),h=Math.min(l[0].length-2,Math.max(0,h)));var u=this.elementSize,p=Math.pow(t/u-a,2)+Math.pow(e/u-h,2)>Math.pow(t/u-(a+1),2)+Math.pow(e/u-(h+1),2);return this.getTriangle(a,h,p,i,n,s),p};var d=new r,y=new r,v=new r,f=new r,m=new r;i.prototype.getNormalAt=function(t,e,o,i){var n=d,s=y,r=v,a=f,c=m;this.getTriangleAt(t,e,o,n,s,r),s.vsub(n,a),r.vsub(n,c),a.cross(c,i),i.normalize()},i.prototype.getAabbAtIndex=function(t,e,o){var i=this.data,n=this.elementSize;o.lowerBound.set(t*n,e*n,i[t][e]),o.upperBound.set((t+1)*n,(e+1)*n,i[t+1][e+1])},i.prototype.getHeightAt=function(t,e,o){var i=this.data,n=l,s=u,r=p,a=c;this.getIndexOfPosition(t,e,a,o);var d=a[0],y=a[1];o&&(d=Math.min(i.length-2,Math.max(0,d)),y=Math.min(i[0].length-2,Math.max(0,y)));var v=this.getTriangleAt(t,e,o,n,s,r);!function(t,e,o,i,n,s,r,a,c){c.x=((s-a)*(t-r)+(r-n)*(e-a))/((s-a)*(o-r)+(r-n)*(i-a)),c.y=((a-i)*(t-r)+(o-r)*(e-a))/((s-a)*(o-r)+(r-n)*(i-a)),c.z=1-c.x-c.y}(t,e,n.x,n.y,s.x,s.y,r.x,r.y,h);var f=h;return v?i[d+1][y+1]*f.x+i[d][y+1]*f.y+i[d+1][y]*f.z:i[d][y]*f.x+i[d+1][y]*f.y+i[d][y+1]*f.z},i.prototype.getCacheConvexTrianglePillarKey=function(t,e,o){return t+"_"+e+"_"+(o?1:0)},i.prototype.getCachedConvexTrianglePillar=function(t,e,o){return this._cachedPillars[this.getCacheConvexTrianglePillarKey(t,e,o)]},i.prototype.setCachedConvexTrianglePillar=function(t,e,o,i,n){this._cachedPillars[this.getCacheConvexTrianglePillarKey(t,e,o)]={convex:i,offset:n}},i.prototype.clearCachedConvexTrianglePillar=function(t,e,o){delete this._cachedPillars[this.getCacheConvexTrianglePillarKey(t,e,o)]},i.prototype.getTriangle=function(t,e,o,i,n,s){var r=this.data,a=this.elementSize;o?(i.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])):(i.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]))},i.prototype.getConvexTrianglePillar=function(t,e,o){var i=this.pillarConvex,n=this.pillarOffset;if(this.cacheEnabled){if(a=this.getCachedConvexTrianglePillar(t,e,o))return this.pillarConvex=a.convex,void(this.pillarOffset=a.offset);i=new s,n=new r,this.pillarConvex=i,this.pillarOffset=n}var a=this.data,c=this.elementSize,h=i.faces;i.vertices.length=6;for(l=0;l<6;l++)i.vertices[l]||(i.vertices[l]=new r);h.length=5;for(var l=0;l<5;l++)h[l]||(h[l]=[]);var u=i.vertices,p=(Math.min(a[t][e],a[t+1][e],a[t][e+1],a[t+1][e+1])-this.minValue)/2+this.minValue;o?(n.set((t+.75)*c,(e+.75)*c,p),u[0].set(.25*c,.25*c,a[t+1][e+1]-p),u[1].set(-.75*c,.25*c,a[t][e+1]-p),u[2].set(.25*c,-.75*c,a[t+1][e]-p),u[3].set(.25*c,.25*c,-p-1),u[4].set(-.75*c,.25*c,-p-1),u[5].set(.25*c,-.75*c,-p-1),h[0][0]=0,h[0][1]=1,h[0][2]=2,h[1][0]=5,h[1][1]=4,h[1][2]=3,h[2][0]=2,h[2][1]=5,h[2][2]=3,h[2][3]=0,h[3][0]=3,h[3][1]=4,h[3][2]=1,h[3][3]=0,h[4][0]=1,h[4][1]=4,h[4][2]=5,h[4][3]=2):(n.set((t+.25)*c,(e+.25)*c,p),u[0].set(-.25*c,-.25*c,a[t][e]-p),u[1].set(.75*c,-.25*c,a[t+1][e]-p),u[2].set(-.25*c,.75*c,a[t][e+1]-p),u[3].set(-.25*c,-.25*c,-p-1),u[4].set(.75*c,-.25*c,-p-1),u[5].set(-.25*c,.75*c,-p-1),h[0][0]=0,h[0][1]=1,h[0][2]=2,h[1][0]=5,h[1][1]=4,h[1][2]=3,h[2][0]=0,h[2][1]=2,h[2][2]=5,h[2][3]=3,h[3][0]=1,h[3][1]=0,h[3][2]=3,h[3][3]=4,h[4][0]=4,h[4][1]=5,h[4][2]=2,h[4][3]=1),i.computeNormals(),i.computeEdges(),i.updateBoundingSphereRadius(),this.setCachedConvexTrianglePillar(t,e,o,i,n)},i.prototype.calculateLocalInertia=function(t,e){return(e=e||new r).set(0,0,0),e},i.prototype.volume=function(){return Number.MAX_VALUE},i.prototype.calculateWorldAABB=function(t,e,o,i){o.set(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE),i.set(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE)},i.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()},i.prototype.setHeightsFromImage=function(t,e){var o=document.createElement("canvas");o.width=t.width,o.height=t.height;var i=o.getContext("2d");i.drawImage(t,0,0);var n=i.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=[],c=0;c<n.width;c++){var h=(n.data[4*(r*n.height+c)]+n.data[4*(r*n.height+c)+1]+n.data[4*(r*n.height+c)+2])/4/255*e.z;e.x<0?a.push(h):a.unshift(h)}e.y<0?s.unshift(a):s.push(a)}this.updateMaxValue(),this.updateMinValue(),this.update()}},{"../math/Vec3":46,"../utils/Utils":69,"./ConvexPolyhedron":54,"./Shape":59}],57:[function(t,e,o){function i(){n.call(this),this.type=n.types.PARTICLE}e.exports=i;var n=t("./Shape"),s=t("../math/Vec3");(i.prototype=new n).constructor=i,i.prototype.calculateLocalInertia=function(t,e){return(e=e||new s).set(0,0,0),e},i.prototype.volume=function(){return 0},i.prototype.updateBoundingSphereRadius=function(){this.boundingSphereRadius=0},i.prototype.calculateWorldAABB=function(t,e,o,i){o.copy(t),i.copy(t)}},{"../math/Vec3":46,"./Shape":59}],58:[function(t,e,o){function i(){n.call(this),this.type=n.types.PLANE,this.worldNormal=new s,this.worldNormalNeedsUpdate=!0,this.boundingSphereRadius=Number.MAX_VALUE}e.exports=i;var n=t("./Shape"),s=t("../math/Vec3");(i.prototype=new n).constructor=i,i.prototype.computeWorldNormal=function(t){var e=this.worldNormal;e.set(0,0,1),t.vmult(e,e),this.worldNormalNeedsUpdate=!1},i.prototype.calculateLocalInertia=function(t,e){return e=e||new s},i.prototype.volume=function(){return Number.MAX_VALUE};var r=new s;i.prototype.calculateWorldAABB=function(t,e,o,i){r.set(0,0,1),e.vmult(r,r);var n=Number.MAX_VALUE;o.set(-n,-n,-n),i.set(n,n,n),1===r.x&&(i.x=t.x),1===r.y&&(i.y=t.y),1===r.z&&(i.z=t.z),-1===r.x&&(o.x=t.x),-1===r.y&&(o.y=t.y),-1===r.z&&(o.z=t.z)},i.prototype.updateBoundingSphereRadius=function(){this.boundingSphereRadius=Number.MAX_VALUE}},{"../math/Vec3":46,"./Shape":59}],59:[function(t,e,o){function i(){this.id=i.idCounter++,this.type=0,this.boundingSphereRadius=0,this.collisionResponse=!0,this.material=null,this.body=null}e.exports=i;var i=t("./Shape");t("../math/Vec3"),t("../math/Quaternion"),t("../material/Material");i.prototype.constructor=i,i.prototype.updateBoundingSphereRadius=function(){throw"computeBoundingSphereRadius() not implemented for shape type "+this.type},i.prototype.volume=function(){throw"volume() not implemented for shape type "+this.type},i.prototype.calculateLocalInertia=function(t,e){throw"calculateLocalInertia() not implemented for shape type "+this.type},i.idCounter=0,i.types={SPHERE:1,PLANE:2,BOX:4,COMPOUND:8,CONVEXPOLYHEDRON:16,HEIGHTFIELD:32,PARTICLE:64,CYLINDER:128,TRIMESH:256}},{"../material/Material":41,"../math/Quaternion":44,"../math/Vec3":46,"./Shape":59}],60:[function(t,e,o){function i(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=i;var n=t("./Shape"),s=t("../math/Vec3");(i.prototype=new n).constructor=i,i.prototype.calculateLocalInertia=function(t,e){e=e||new s;var o=2*t*this.radius*this.radius/5;return e.x=o,e.y=o,e.z=o,e},i.prototype.volume=function(){return 4*Math.PI*this.radius/3},i.prototype.updateBoundingSphereRadius=function(){this.boundingSphereRadius=this.radius},i.prototype.calculateWorldAABB=function(t,e,o,i){for(var n=this.radius,s=["x","y","z"],r=0;r<s.length;r++){var a=s[r];o[a]=t[a]-n,i[a]=t[a]+n}}},{"../math/Vec3":46,"./Shape":59}],61:[function(t,e,o){function i(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 c,this.updateEdges(),this.updateNormals(),this.updateAABB(),this.updateBoundingSphereRadius(),this.updateTree()}e.exports=i;var n=t("./Shape"),s=t("../math/Vec3"),r=(t("../math/Quaternion"),t("../math/Transform")),a=t("../collision/AABB"),c=t("../utils/Octree");(i.prototype=new n).constructor=i;var h=new s;i.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 o=new a,i=new s,n=new s,r=new s,c=[i,n,r],h=0;h<this.indices.length/3;h++){var l=3*h;this._getUnscaledVertex(this.indices[l],i),this._getUnscaledVertex(this.indices[l+1],n),this._getUnscaledVertex(this.indices[l+2],r),o.setFromPoints(c),t.insert(o,h)}t.removeEmptyNodes()};var l=new a;i.prototype.getTrianglesInAABB=function(t,e){l.copy(t);var o=this.scale,i=o.x,n=o.y,s=o.z,r=l.lowerBound,a=l.upperBound;return r.x/=i,r.y/=n,r.z/=s,a.x/=i,a.y/=n,a.z/=s,this.tree.aabbQuery(l,e)},i.prototype.setScale=function(t){var e=this.scale.x===this.scale.y===this.scale.z,o=t.x===t.y===t.z;e&&o||this.updateNormals(),this.scale.copy(t),this.updateAABB(),this.updateBoundingSphereRadius()},i.prototype.updateNormals=function(){for(var t=h,e=this.normals,o=0;o<this.indices.length/3;o++){var n=3*o,s=this.indices[n],r=this.indices[n+1],a=this.indices[n+2];this.getVertex(s,v),this.getVertex(r,f),this.getVertex(a,m),i.computeNormal(f,v,m,t),e[n]=t.x,e[n+1]=t.y,e[n+2]=t.z}},i.prototype.updateEdges=function(){for(var t={},e=function(e,o){t[n<s?n+"_"+s:s+"_"+n]=!0},o=0;o<this.indices.length/3;o++){var i=3*o,n=this.indices[i],s=this.indices[i+1];this.indices[i+2];e(),e(),e()}var r=Object.keys(t);this.edges=new Int16Array(2*r.length);for(o=0;o<r.length;o++){var a=r[o].split("_");this.edges[2*o]=parseInt(a[0],10),this.edges[2*o+1]=parseInt(a[1],10)}},i.prototype.getEdgeVertex=function(t,e,o){var i=this.edges[2*t+(e?1:0)];this.getVertex(i,o)};var u=new s,p=new s;i.prototype.getEdgeVector=function(t,e){var o=u,i=p;this.getEdgeVertex(t,0,o),this.getEdgeVertex(t,1,i),i.vsub(o,e)};var d=new s,y=new s;i.computeNormal=function(t,e,o,i){e.vsub(t,y),o.vsub(e,d),d.cross(y,i),i.isZero()||i.normalize()};var v=new s,f=new s,m=new s;i.prototype.getVertex=function(t,e){var o=this.scale;return this._getUnscaledVertex(t,e),e.x*=o.x,e.y*=o.y,e.z*=o.z,e},i.prototype._getUnscaledVertex=function(t,e){var o=3*t,i=this.vertices;return e.set(i[o],i[o+1],i[o+2])},i.prototype.getWorldVertex=function(t,e,o,i){return this.getVertex(t,i),r.pointToWorldFrame(e,o,i,i),i},i.prototype.getTriangleVertices=function(t,e,o,i){var n=3*t;this.getVertex(this.indices[n],e),this.getVertex(this.indices[n+1],o),this.getVertex(this.indices[n+2],i)},i.prototype.getNormal=function(t,e){var o=3*t;return e.set(this.normals[o],this.normals[o+1],this.normals[o+2])};var w=new a;i.prototype.calculateLocalInertia=function(t,e){this.computeLocalAABB(w);var o=w.upperBound.x-w.lowerBound.x,i=w.upperBound.y-w.lowerBound.y,n=w.upperBound.z-w.lowerBound.z;return e.set(1/12*t*(2*i*2*i+2*n*2*n),1/12*t*(2*o*2*o+2*n*2*n),1/12*t*(2*i*2*i+2*o*2*o))};var g=new s;i.prototype.computeLocalAABB=function(t){var e=t.lowerBound,o=t.upperBound,i=this.vertices.length,n=(this.vertices,g);this.getVertex(0,n),e.copy(n),o.copy(n);for(var s=0;s!==i;s++)this.getVertex(s,n),n.x<e.x?e.x=n.x:n.x>o.x&&(o.x=n.x),n.y<e.y?e.y=n.y:n.y>o.y&&(o.y=n.y),n.z<e.z?e.z=n.z:n.z>o.z&&(o.z=n.z)},i.prototype.updateAABB=function(){this.computeLocalAABB(this.aabb)},i.prototype.updateBoundingSphereRadius=function(){for(var t=0,e=this.vertices,o=new s,i=0,n=e.length/3;i!==n;i++){this.getVertex(i,o);var r=o.norm2();r>t&&(t=r)}this.boundingSphereRadius=Math.sqrt(t)};new s;var x=new r,b=new a;i.prototype.calculateWorldAABB=function(t,e,o,i){var n=x,s=b;n.position=t,n.quaternion=e,this.aabb.toWorldFrame(n,s),o.copy(s.lowerBound),i.copy(s.upperBound)},i.prototype.volume=function(){return 4*Math.PI*this.boundingSphereRadius/3},i.createTorus=function(t,e,o,n,s){t=t||1,e=e||.5,o=o||8,n=n||6,s=s||2*Math.PI;for(var r=[],a=[],c=0;c<=o;c++)for(y=0;y<=n;y++){var h=y/n*s,l=c/o*Math.PI*2,u=(t+e*Math.cos(l))*Math.cos(h),p=(t+e*Math.cos(l))*Math.sin(h),d=e*Math.sin(l);r.push(u,p,d)}for(c=1;c<=o;c++)for(var y=1;y<=n;y++){var v=(n+1)*c+y-1,f=(n+1)*(c-1)+y-1,m=(n+1)*(c-1)+y,w=(n+1)*c+y;a.push(v,f,w),a.push(f,m,w)}return new i(r,a)}},{"../collision/AABB":18,"../math/Quaternion":44,"../math/Transform":45,"../math/Vec3":46,"../utils/Octree":66,"./Shape":59}],62:[function(t,e,o){function i(){n.call(this),this.iterations=10,this.tolerance=1e-7}e.exports=i;t("../math/Vec3"),t("../math/Quaternion");var n=t("./Solver"),s=[],r=[],a=[];(i.prototype=new n).solve=function(t,e){var o,i,n,c,h,l=0,u=this.iterations,p=this.tolerance*this.tolerance,d=this.equations,y=d.length,v=e.bodies,f=v.length,m=t;if(0!==y)for(C=0;C!==f;C++)v[C].updateSolveMassProperties();var w=r,g=a,x=s;w.length=y,g.length=y,x.length=y;for(C=0;C!==y;C++){B=d[C];x[C]=0,g[C]=B.computeB(m),w[C]=1/B.computeC()}if(0!==y){for(C=0;C!==f;C++){var b=(S=v[C]).vlambda,E=S.wlambda;b.set(0,0,0),E.set(0,0,0)}for(l=0;l!==u;l++){c=0;for(var A=0;A!==y;A++){var B=d[A];o=g[A],i=w[A],(h=x[A])+(n=i*(o-B.computeGWlambda()-B.eps*h))<B.minForce?n=B.minForce-h:h+n>B.maxForce&&(n=B.maxForce-h),x[A]+=n,c+=n>0?n:-n,B.addToWlambda(n)}if(c*c<p)break}for(var C=0;C!==f;C++){var S=v[C],R=S.velocity,M=S.angularVelocity;S.vlambda.vmul(S.linearFactor,S.vlambda),R.vadd(S.vlambda,R),S.wlambda.vmul(S.angularFactor,S.wlambda),M.vadd(S.wlambda,M)}for(var T=d.length,z=1/m;T--;)d[T].multiplier=x[T]*z}return l}},{"../math/Quaternion":44,"../math/Vec3":46,"./Solver":63}],63:[function(t,e,o){function i(){this.equations=[]}e.exports=i,i.prototype.solve=function(t,e){return 0},i.prototype.addEquation=function(t){t.enabled&&this.equations.push(t)},i.prototype.removeEquation=function(t){var e=this.equations,o=e.indexOf(t);-1!==o&&e.splice(o,1)},i.prototype.removeAllEquations=function(){this.equations.length=0}},{}],64:[function(t,e,o){function i(t){for(c.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,o=0;o!==e;o++){var i=t[o];if(!(i.visited||i.body.type&d))return i}return!1}function s(t,e,o,i){for(y.push(t),t.visited=!0,e(t,o,i);y.length;)for(var s,r=y.pop();s=n(r.children);)s.visited=!0,e(s,o,i),y.push(s)}function r(t,e,o){e.push(t.body);for(var i=t.eqs.length,n=0;n!==i;n++){var s=t.eqs[n];-1===o.indexOf(s)&&o.push(s)}}function a(t,e){return e.id-t.id}e.exports=i;t("../math/Vec3"),t("../math/Quaternion");var c=t("./Solver"),h=t("../objects/Body");i.prototype=new c;var l=[],u=[],p={bodies:[]},d=h.STATIC,y=[];i.prototype.createNode=function(){return{body:null,children:[],eqs:[],visited:!1}},i.prototype.solve=function(t,e){for(var o=l,i=this.nodePool,c=e.bodies,h=this.equations,d=h.length,y=c.length,v=this.subsolver;i.length<y;)i.push(this.createNode());o.length=y;for(g=0;g<y;g++)o[g]=i[g];for(g=0;g!==y;g++){var f=o[g];f.body=c[g],f.children.length=0,f.eqs.length=0,f.visited=!1}for(var m=0;m!==d;m++){var w=h[m],g=c.indexOf(w.bi),x=c.indexOf(w.bj),b=o[g],E=o[x];b.children.push(E),b.eqs.push(w),E.children.push(b),E.eqs.push(w)}var A,B=0,C=u;v.tolerance=this.tolerance,v.iterations=this.iterations;for(var S=p;A=n(o);){C.length=0,S.bodies.length=0,s(A,r,S.bodies,C);var R=C.length;C=C.sort(a);for(g=0;g!==R;g++)v.addEquation(C[g]);v.solve(t,S);v.removeAllEquations(),B++}return B}},{"../math/Quaternion":44,"../math/Vec3":46,"../objects/Body":47,"./Solver":63}],65:[function(t,e,o){var i=function(){};e.exports=i,i.prototype={constructor:i,addEventListener:function(t,e){void 0===this._listeners&&(this._listeners={});var o=this._listeners;return void 0===o[t]&&(o[t]=[]),-1===o[t].indexOf(e)&&o[t].push(e),this},hasEventListener:function(t,e){if(void 0===this._listeners)return!1;var o=this._listeners;return void 0!==o[t]&&-1!==o[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 o=this._listeners;if(void 0===o[t])return this;var i=o[t].indexOf(e);return-1!==i&&o[t].splice(i,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 o=0,i=e.length;o<i;o++)e[o].call(this,t)}return this}}},{}],66:[function(t,e,o){function i(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,i.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 i,i.prototype.reset=function(t,e){this.children.length=this.data.length=0},i.prototype.insert=function(t,e,o){var i=this.data;if(o=o||0,!this.aabb.contains(t))return!1;var n=this.children;if(o<(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,o+1))return!0;s&&(n.length=0)}return i.push(e),!0};var a=new r;i.prototype.subdivide=function(){var t=this.aabb,e=t.lowerBound,o=t.upperBound,n=this.children;n.push(new i({aabb:new s({lowerBound:new r(0,0,0)})}),new i({aabb:new s({lowerBound:new r(1,0,0)})}),new i({aabb:new s({lowerBound:new r(1,1,0)})}),new i({aabb:new s({lowerBound:new r(1,1,1)})}),new i({aabb:new s({lowerBound:new r(0,1,1)})}),new i({aabb:new s({lowerBound:new r(0,0,1)})}),new i({aabb:new s({lowerBound:new r(1,0,1)})}),new i({aabb:new s({lowerBound:new r(0,1,0)})})),o.vsub(e,a),a.scale(.5,a);for(var c=this.root||this,h=0;8!==h;h++){var l=n[h];l.root=c;var u=l.aabb.lowerBound;u.x*=a.x,u.y*=a.y,u.z*=a.z,u.vadd(e,u),u.vadd(a,l.aabb.upperBound)}},i.prototype.aabbQuery=function(t,e){this.data,this.children;for(var o=[this];o.length;){var i=o.pop();i.aabb.overlaps(t)&&Array.prototype.push.apply(e,i.data),Array.prototype.push.apply(o,i.children)}return e};var c=new s;i.prototype.rayQuery=function(t,e,o){return t.getAABB(c),c.toLocalFrame(e,c),this.aabbQuery(c,o),o},i.prototype.removeEmptyNodes=function(){for(var t=[this];t.length;){for(var e=t.pop(),o=e.children.length-1;o>=0;o--)e.children[o].data.length||e.children.splice(o,1);Array.prototype.push.apply(t,e.children)}}},{"../collision/AABB":18,"../math/Vec3":46}],67:[function(t,e,o){function i(){this.objects=[],this.type=Object}e.exports=i,i.prototype.release=function(){for(var t=arguments.length,e=0;e!==t;e++)this.objects.push(arguments[e]);return this},i.prototype.get=function(){return 0===this.objects.length?this.constructObject():this.objects.pop()},i.prototype.constructObject=function(){throw new Error("constructObject() not implemented in this Pool subclass yet!")},i.prototype.resize=function(t){for(var e=this.objects;e.length>t;)e.pop();for(;e.length<t;)e.push(this.constructObject());return this}},{}],68:[function(t,e,o){function i(){this.data={keys:[]}}e.exports=i,i.prototype.get=function(t,e){if(t>e){var o=e;e=t,t=o}return this.data[t+"-"+e]},i.prototype.set=function(t,e,o){if(t>e){var i=e;e=t,t=i}var n=t+"-"+e;this.get(t,e)||this.data.keys.push(n),this.data[n]=o},i.prototype.reset=function(){for(var t=this.data,e=t.keys;e.length>0;){delete t[e.pop()]}}},{}],69:[function(t,e,o){function i(){}e.exports=i,i.defaults=function(t,e){t=t||{};for(var o in e)o in t||(t[o]=e[o]);return t}},{}],70:[function(t,e,o){function i(){s.call(this),this.type=n}e.exports=i;var n=t("../math/Vec3"),s=t("./Pool");(i.prototype=new s).constructObject=function(){return new n}},{"../math/Vec3":46,"./Pool":67}],71:[function(t,e,o){function i(t){this.contactPointPool=[],this.frictionEquationPool=[],this.result=[],this.frictionResult=[],this.v3pool=new p,this.world=t,this.currentContactMaterial=null,this.enableFrictionReduction=!1}function n(t,e,o){for(var i=null,n=t.length,s=0;s!==n;s++){var r=t[s],a=D;t[(s+1)%n].vsub(r,a);var c=H;a.cross(e,c);var h=K;o.vsub(r,h);var l=c.dot(h);if(!(null===i||l>0&&!0===i||l<=0&&!1===i))return!1;null===i&&(i=l>0)}return!0}e.exports=i;var s=t("../collision/AABB"),r=t("../objects/Body"),a=t("../shapes/Shape"),c=t("../collision/Ray"),h=t("../math/Vec3"),l=t("../math/Transform"),u=(t("../shapes/ConvexPolyhedron"),t("../math/Quaternion")),p=(t("../solver/Solver"),t("../utils/Vec3Pool")),d=t("../equations/ContactEquation"),y=t("../equations/FrictionEquation");i.prototype.createContactEquation=function(t,e,o,i,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&&o.collisionResponse&&i.collisionResponse;var a=this.currentContactMaterial;r.restitution=a.restitution,r.setSpookParams(a.contactEquationStiffness,a.contactEquationRelaxation,this.world.dt);var c=o.material||t.material,h=i.material||e.material;return c&&h&&c.restitution>=0&&h.restitution>=0&&(r.restitution=c.restitution*h.restitution),r.si=n||o,r.sj=s||i,r},i.prototype.createFrictionEquationsFromContact=function(t,e){var o=t.bi,i=t.bj,n=t.si,s=t.sj,r=this.world,a=this.currentContactMaterial,c=a.friction,h=n.material||o.material,l=s.material||i.material;if(h&&l&&h.friction>=0&&l.friction>=0&&(c=h.friction*l.friction),c>0){var u=c*r.gravity.length(),p=o.invMass+i.invMass;p>0&&(p=1/p);var d=this.frictionEquationPool,v=d.length?d.pop():new y(o,i,u*p),f=d.length?d.pop():new y(o,i,u*p);return v.bi=f.bi=o,v.bj=f.bj=i,v.minForce=f.minForce=-u*p,v.maxForce=f.maxForce=u*p,v.ri.copy(t.ri),v.rj.copy(t.rj),f.ri.copy(t.ri),f.rj.copy(t.rj),t.ni.tangents(v.t,f.t),v.setSpookParams(a.frictionEquationStiffness,a.frictionEquationRelaxation,r.dt),f.setSpookParams(a.frictionEquationStiffness,a.frictionEquationRelaxation,r.dt),v.enabled=f.enabled=t.enabled,e.push(v,f),!0}return!1};var v=new h,f=new h,m=new h;i.prototype.createFrictionFromAverage=function(t){var e=this.result[this.result.length-1];if(this.createFrictionEquationsFromContact(e,this.frictionResult)&&1!==t){var o=this.frictionResult[this.frictionResult.length-2],i=this.frictionResult[this.frictionResult.length-1];v.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?(v.vadd(e.ni,v),f.vadd(e.ri,f),m.vadd(e.rj,m)):(v.vsub(e.ni,v),f.vadd(e.rj,f),m.vadd(e.ri,m));var r=1/t;f.scale(r,o.ri),m.scale(r,o.rj),i.ri.copy(o.ri),i.rj.copy(o.rj),v.normalize(),v.tangents(o.t,i.t)}};var w=new h,g=new h,x=new u,b=new u;i.prototype.getContacts=function(t,e,o,i,n,s,a){this.contactPointPool=n,this.frictionEquationPool=a,this.result=i,this.frictionResult=s;for(var c=x,h=b,l=w,u=g,p=0,d=t.length;p!==d;p++){var y=t[p],v=e[p],f=null;y.material&&v.material&&(f=o.getContactMaterial(y.material,v.material)||null);for(var m=y.type&r.KINEMATIC&&v.type&r.STATIC||y.type&r.STATIC&&v.type&r.KINEMATIC||y.type&r.KINEMATIC&&v.type&r.KINEMATIC,E=0;E<y.shapes.length;E++){y.quaternion.mult(y.shapeOrientations[E],c),y.quaternion.vmult(y.shapeOffsets[E],l),l.vadd(y.position,l);for(var A=y.shapes[E],B=0;B<v.shapes.length;B++){v.quaternion.mult(v.shapeOrientations[B],h),v.quaternion.vmult(v.shapeOffsets[B],u),u.vadd(v.position,u);var C=v.shapes[B];if(!(l.distanceTo(u)>A.boundingSphereRadius+C.boundingSphereRadius)){var S=null;A.material&&C.material&&(S=o.getContactMaterial(A.material,C.material)||null),this.currentContactMaterial=S||f||o.defaultContactMaterial;var R=this[A.type|C.type];if(R){(A.type<C.type?R.call(this,A,C,l,u,c,h,y,v,A,C,m):R.call(this,C,A,u,l,h,c,v,y,A,C,m))&&m&&(o.shapeOverlapKeeper.set(A.id,C.id),o.bodyOverlapKeeper.set(y.id,v.id))}}}}}};i.prototype[a.types.BOX|a.types.BOX]=i.prototype.boxBox=function(t,e,o,i,n,s,r,a,c,h,l){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,o,i,n,s,r,a,t,e,l)},i.prototype[a.types.BOX|a.types.CONVEXPOLYHEDRON]=i.prototype.boxConvex=function(t,e,o,i,n,s,r,a,c,h,l){return t.convexPolyhedronRepresentation.material=t.material,t.convexPolyhedronRepresentation.collisionResponse=t.collisionResponse,this.convexConvex(t.convexPolyhedronRepresentation,e,o,i,n,s,r,a,t,e,l)},i.prototype[a.types.BOX|a.types.PARTICLE]=i.prototype.boxParticle=function(t,e,o,i,n,s,r,a,c,h,l){return t.convexPolyhedronRepresentation.material=t.material,t.convexPolyhedronRepresentation.collisionResponse=t.collisionResponse,this.convexParticle(t.convexPolyhedronRepresentation,e,o,i,n,s,r,a,t,e,l)},i.prototype[a.types.SPHERE]=i.prototype.sphereSphere=function(t,e,o,i,n,s,r,a,c,h,l){if(l)return o.distanceSquared(i)<Math.pow(t.radius+e.radius,2);var u=this.createContactEquation(r,a,t,e,c,h);i.vsub(o,u.ni),u.ni.normalize(),u.ri.copy(u.ni),u.rj.copy(u.ni),u.ri.mult(t.radius,u.ri),u.rj.mult(-e.radius,u.rj),u.ri.vadd(o,u.ri),u.ri.vsub(r.position,u.ri),u.rj.vadd(i,u.rj),u.rj.vsub(a.position,u.rj),this.result.push(u),this.createFrictionEquationsFromContact(u,this.frictionResult)};var E=new h,A=new h,B=new h;i.prototype[a.types.PLANE|a.types.TRIMESH]=i.prototype.planeTrimesh=function(t,e,o,i,n,s,r,a,c,u,p){var d=new h,y=E;y.set(0,0,1),n.vmult(y,y);for(var v=0;v<e.vertices.length/3;v++){e.getVertex(v,d);var f=new h;f.copy(d),l.pointToWorldFrame(i,s,f,d);var m=A;d.vsub(o,m);if(y.dot(m)<=0){if(p)return!0;var w=this.createContactEquation(r,a,t,e,c,u);w.ni.copy(y);var g=B;y.scale(m.dot(y),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 C=new h,S=new h,R=(new h,new h),M=new h,T=new h,z=new h,k=new h,P=new h,q=new h,L=new h,V=new h,F=new h,N=new h,I=new s,O=[];i.prototype[a.types.SPHERE|a.types.TRIMESH]=i.prototype.sphereTrimesh=function(t,e,o,i,n,s,r,a,h,u,p){var d=T,y=z,v=k,f=P,m=q,w=L,g=I,x=M,b=S,E=O;l.pointToLocalFrame(i,s,o,m);var A=t.radius;g.lowerBound.set(m.x-A,m.y-A,m.z-A),g.upperBound.set(m.x+A,m.y+A,m.z+A),e.getTrianglesInAABB(g,E);for(var B=R,j=t.radius*t.radius,W=0;W<E.length;W++)for(D=0;D<3;D++)if(e.getVertex(e.indices[3*E[W]+D],B),B.vsub(m,b),b.norm2()<=j){if(x.copy(B),l.pointToWorldFrame(i,s,x,B),B.vsub(o,b),p)return!0;(Z=this.createContactEquation(r,a,t,e,h,u)).ni.copy(b),Z.ni.normalize(),Z.ri.copy(Z.ni),Z.ri.scale(t.radius,Z.ri),Z.ri.vadd(o,Z.ri),Z.ri.vsub(r.position,Z.ri),Z.rj.copy(B),Z.rj.vsub(a.position,Z.rj),this.result.push(Z),this.createFrictionEquationsFromContact(Z,this.frictionResult)}for(W=0;W<E.length;W++)for(var D=0;D<3;D++){e.getVertex(e.indices[3*E[W]+D],d),e.getVertex(e.indices[3*E[W]+(D+1)%3],y),y.vsub(d,v),m.vsub(y,w);var H=w.dot(v);m.vsub(d,w);var K=w.dot(v);if(K>0&&H<0){m.vsub(d,w),f.copy(v),f.normalize(),K=w.dot(f),f.scale(K,w),w.vadd(d,w);if((Q=w.distanceTo(m))<t.radius){if(p)return!0;Z=this.createContactEquation(r,a,t,e,h,u);w.vsub(m,Z.ni),Z.ni.normalize(),Z.ni.scale(t.radius,Z.ri),l.pointToWorldFrame(i,s,w,w),w.vsub(a.position,Z.rj),l.vectorToWorldFrame(s,Z.ni,Z.ni),l.vectorToWorldFrame(s,Z.ri,Z.ri),this.result.push(Z),this.createFrictionEquationsFromContact(Z,this.frictionResult)}}}for(var _=V,U=F,G=N,X=C,W=0,Y=E.length;W!==Y;W++){e.getTriangleVertices(E[W],_,U,G),e.getNormal(E[W],X),m.vsub(_,w);var Q=w.dot(X);if(X.scale(Q,w),m.vsub(w,w),Q=w.distanceTo(m),c.pointInTriangle(w,_,U,G)&&Q<t.radius){if(p)return!0;var Z=this.createContactEquation(r,a,t,e,h,u);w.vsub(m,Z.ni),Z.ni.normalize(),Z.ni.scale(t.radius,Z.ri),l.pointToWorldFrame(i,s,w,w),w.vsub(a.position,Z.rj),l.vectorToWorldFrame(s,Z.ni,Z.ni),l.vectorToWorldFrame(s,Z.ri,Z.ri),this.result.push(Z),this.createFrictionEquationsFromContact(Z,this.frictionResult)}}E.length=0};var j=new h,W=new h;i.prototype[a.types.SPHERE|a.types.PLANE]=i.prototype.spherePlane=function(t,e,o,i,n,s,r,a,c,h,l){var u=this.createContactEquation(r,a,t,e,c,h);if(u.ni.set(0,0,1),s.vmult(u.ni,u.ni),u.ni.negate(u.ni),u.ni.normalize(),u.ni.mult(t.radius,u.ri),o.vsub(i,j),u.ni.mult(u.ni.dot(j),W),j.vsub(W,u.rj),-j.dot(u.ni)<=t.radius){if(l)return!0;var p=u.ri,d=u.rj;p.vadd(o,p),p.vsub(r.position,p),d.vadd(i,d),d.vsub(a.position,d),this.result.push(u),this.createFrictionEquationsFromContact(u,this.frictionResult)}};var D=new h,H=new h,K=new h,_=new h,U=new h,G=new h,X=new h,Y=[new h,new h,new h,new h,new h,new h],Q=new h,Z=new h,J=new h,$=new h;i.prototype[a.types.SPHERE|a.types.BOX]=i.prototype.sphereBox=function(t,e,o,i,n,s,r,a,c,h,l){var u=this.v3pool,p=Y;o.vsub(i,_),e.getSideNormals(p,s);for(var d=t.radius,y=!1,v=Z,f=J,m=$,w=null,g=0,x=0,b=0,E=null,A=0,B=p.length;A!==B&&!1===y;A++){var C=U;C.copy(p[A]);var S=C.norm();C.normalize();var R=_.dot(C);if(R<S+d&&R>0){var M=G,T=X;M.copy(p[(A+1)%3]),T.copy(p[(A+2)%3]);var z=M.norm(),k=T.norm();M.normalize(),T.normalize();var P=_.dot(M),q=_.dot(T);if(P<z&&P>-z&&q<k&&q>-k){W=Math.abs(R-S-d);if((null===E||W<E)&&(E=W,x=P,b=q,w=S,v.copy(C),f.copy(M),m.copy(T),g++,l))return!0}}}if(g){y=!0;O=this.createContactEquation(r,a,t,e,c,h);v.mult(-d,O.ri),O.ni.copy(v),O.ni.negate(O.ni),v.mult(w,v),f.mult(x,f),v.vadd(f,v),m.mult(b,m),v.vadd(m,O.rj),O.ri.vadd(o,O.ri),O.ri.vsub(r.position,O.ri),O.rj.vadd(i,O.rj),O.rj.vsub(a.position,O.rj),this.result.push(O),this.createFrictionEquationsFromContact(O,this.frictionResult)}for(var L=u.get(),V=Q,F=0;2!==F&&!y;F++)for(H=0;2!==H&&!y;H++)for(tt=0;2!==tt&&!y;tt++)if(L.set(0,0,0),F?L.vadd(p[0],L):L.vsub(p[0],L),H?L.vadd(p[1],L):L.vsub(p[1],L),tt?L.vadd(p[2],L):L.vsub(p[2],L),i.vadd(L,V),V.vsub(o,V),V.norm2()<d*d){if(l)return!0;y=!0;(O=this.createContactEquation(r,a,t,e,c,h)).ri.copy(V),O.ri.normalize(),O.ni.copy(O.ri),O.ri.mult(d,O.ri),O.rj.copy(L),O.ri.vadd(o,O.ri),O.ri.vsub(r.position,O.ri),O.rj.vadd(i,O.rj),O.rj.vsub(a.position,O.rj),this.result.push(O),this.createFrictionEquationsFromContact(O,this.frictionResult)}u.release(L),L=null;for(var N=u.get(),I=u.get(),O=u.get(),j=u.get(),W=u.get(),D=p.length,F=0;F!==D&&!y;F++)for(var H=0;H!==D&&!y;H++)if(F%3!=H%3){p[H].cross(p[F],N),N.normalize(),p[F].vadd(p[H],I),O.copy(o),O.vsub(I,O),O.vsub(i,O);var K=O.dot(N);N.mult(K,j);for(var tt=0;tt===F%3||tt===H%3;)tt++;W.copy(o),W.vsub(j,W),W.vsub(I,W),W.vsub(i,W);var et=Math.abs(K),ot=W.norm();if(et<p[tt].norm()&&ot<d){if(l)return!0;y=!0;var it=this.createContactEquation(r,a,t,e,c,h);I.vadd(j,it.rj),it.rj.copy(it.rj),W.negate(it.ni),it.ni.normalize(),it.ri.copy(it.rj),it.ri.vadd(i,it.ri),it.ri.vsub(o,it.ri),it.ri.normalize(),it.ri.mult(d,it.ri),it.ri.vadd(o,it.ri),it.ri.vsub(r.position,it.ri),it.rj.vadd(i,it.rj),it.rj.vsub(a.position,it.rj),this.result.push(it),this.createFrictionEquationsFromContact(it,this.frictionResult)}}u.release(N,I,O,j,W)};var tt=new h,et=new h,ot=new h,it=new h,nt=new h,st=new h,rt=new h,at=new h,ct=new h,ht=new h;i.prototype[a.types.SPHERE|a.types.CONVEXPOLYHEDRON]=i.prototype.sphereConvex=function(t,e,o,i,s,r,a,c,h,l,u){var p=this.v3pool;o.vsub(i,tt);for(var d=e.faceNormals,y=e.faces,v=e.vertices,f=t.radius,m=0;m!==v.length;m++){var w=v[m],g=nt;r.vmult(w,g),i.vadd(g,g);var x=it;if(g.vsub(o,x),x.norm2()<f*f){if(u)return!0;b=!0;return(U=this.createContactEquation(a,c,t,e,h,l)).ri.copy(x),U.ri.normalize(),U.ni.copy(U.ri),U.ri.mult(f,U.ri),g.vsub(i,U.rj),U.ri.vadd(o,U.ri),U.ri.vsub(a.position,U.ri),U.rj.vadd(i,U.rj),U.rj.vsub(c.position,U.rj),this.result.push(U),void this.createFrictionEquationsFromContact(U,this.frictionResult)}}for(var b=!1,m=0,E=y.length;m!==E&&!1===b;m++){var A=d[m],B=y[m],C=st;r.vmult(A,C);var S=rt;r.vmult(v[B[0]],S),S.vadd(i,S);var R=at;C.mult(-f,R),o.vadd(R,R);var M=ct;R.vsub(S,M);var T=M.dot(C),z=ht;if(o.vsub(S,z),T<0&&z.dot(C)>0){for(var k=[],P=0,q=B.length;P!==q;P++){var L=p.get();r.vmult(v[B[P]],L),i.vadd(L,L),k.push(L)}if(n(k,C,o)){if(u)return!0;b=!0;U=this.createContactEquation(a,c,t,e,h,l);C.mult(-f,U.ri),C.negate(U.ni);var V=p.get();C.mult(-T,V);var F=p.get();C.mult(-f,F),o.vsub(i,U.rj),U.rj.vadd(F,U.rj),U.rj.vadd(V,U.rj),U.rj.vadd(i,U.rj),U.rj.vsub(c.position,U.rj),U.ri.vadd(o,U.ri),U.ri.vsub(a.position,U.ri),p.release(V),p.release(F),this.result.push(U),this.createFrictionEquationsFromContact(U,this.frictionResult);for(var P=0,N=k.length;P!==N;P++)p.release(k[P]);return}for(P=0;P!==B.length;P++){var I=p.get(),O=p.get();r.vmult(v[B[(P+1)%B.length]],I),r.vmult(v[B[(P+2)%B.length]],O),i.vadd(I,I),i.vadd(O,O);var j=et;O.vsub(I,j);var W=ot;j.unit(W);var D=p.get(),H=p.get();o.vsub(I,H);var K=H.dot(W);W.mult(K,D),D.vadd(I,D);var _=p.get();if(D.vsub(o,_),K>0&&K*K<j.norm2()&&_.norm2()<f*f){if(u)return!0;var U=this.createContactEquation(a,c,t,e,h,l);D.vsub(i,U.rj),D.vsub(o,U.ni),U.ni.normalize(),U.ni.mult(f,U.ri),U.rj.vadd(i,U.rj),U.rj.vsub(c.position,U.rj),U.ri.vadd(o,U.ri),U.ri.vsub(a.position,U.ri),this.result.push(U),this.createFrictionEquationsFromContact(U,this.frictionResult);for(var P=0,N=k.length;P!==N;P++)p.release(k[P]);return p.release(I),p.release(O),p.release(D),p.release(_),void p.release(H)}p.release(I),p.release(O),p.release(D),p.release(_),p.release(H)}for(var P=0,N=k.length;P!==N;P++)p.release(k[P])}}};new h,new h;i.prototype[a.types.PLANE|a.types.BOX]=i.prototype.planeBox=function(t,e,o,i,n,s,r,a,c,h,l){return e.convexPolyhedronRepresentation.material=e.material,e.convexPolyhedronRepresentation.collisionResponse=e.collisionResponse,e.convexPolyhedronRepresentation.id=e.id,this.planeConvex(t,e.convexPolyhedronRepresentation,o,i,n,s,r,a,t,e,l)};var lt=new h,ut=new h,pt=new h,dt=new h;i.prototype[a.types.PLANE|a.types.CONVEXPOLYHEDRON]=i.prototype.planeConvex=function(t,e,o,i,n,s,r,a,c,h,l){var u=lt,p=ut;p.set(0,0,1),n.vmult(p,p);for(var d=0,y=pt,v=0;v!==e.vertices.length;v++){u.copy(e.vertices[v]),s.vmult(u,u),i.vadd(u,u),u.vsub(o,y);if(p.dot(y)<=0){if(l)return!0;var f=this.createContactEquation(r,a,t,e,c,h),m=dt;p.mult(p.dot(y),m),u.vsub(m,m),m.vsub(o,f.ri),f.ni.copy(p),u.vsub(i,f.rj),f.ri.vadd(o,f.ri),f.ri.vsub(r.position,f.ri),f.rj.vadd(i,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 yt=new h,vt=new h;i.prototype[a.types.CONVEXPOLYHEDRON]=i.prototype.convexConvex=function(t,e,o,i,n,s,r,a,c,h,l,u,p){var d=yt;if(!(o.distanceTo(i)>t.boundingSphereRadius+e.boundingSphereRadius)&&t.findSeparatingAxis(e,o,n,i,s,d,u,p)){var y=[],v=vt;t.clipAgainstHull(o,n,e,i,s,d,-100,100,y);for(var f=0,m=0;m!==y.length;m++){if(l)return!0;var w=this.createContactEquation(r,a,t,e,c,h),g=w.ri,x=w.rj;d.negate(w.ni),y[m].normal.negate(v),v.mult(y[m].depth,v),y[m].point.vadd(v,g),x.copy(y[m].point),g.vsub(o,g),x.vsub(i,x),g.vadd(o,g),g.vsub(r.position,g),x.vadd(i,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 h,mt=new h,wt=new h;i.prototype[a.types.PLANE|a.types.PARTICLE]=i.prototype.planeParticle=function(t,e,o,i,n,s,r,a,c,h,l){var u=ft;u.set(0,0,1),r.quaternion.vmult(u,u);var p=mt;i.vsub(r.position,p);if(u.dot(p)<=0){if(l)return!0;var d=this.createContactEquation(a,r,e,t,c,h);d.ni.copy(u),d.ni.negate(d.ni),d.ri.set(0,0,0);var y=wt;u.mult(u.dot(i),y),i.vsub(y,y),d.rj.copy(y),this.result.push(d),this.createFrictionEquationsFromContact(d,this.frictionResult)}};var gt=new h;i.prototype[a.types.PARTICLE|a.types.SPHERE]=i.prototype.sphereParticle=function(t,e,o,i,n,s,r,a,c,h,l){var u=gt;u.set(0,0,1),i.vsub(o,u);if(u.norm2()<=t.radius*t.radius){if(l)return!0;var p=this.createContactEquation(a,r,e,t,c,h);u.normalize(),p.rj.copy(u),p.rj.mult(t.radius,p.rj),p.ni.copy(u),p.ni.negate(p.ni),p.ri.set(0,0,0),this.result.push(p),this.createFrictionEquationsFromContact(p,this.frictionResult)}};var xt=new u,bt=new h,Et=(new h,new h),At=new h,Bt=new h;i.prototype[a.types.PARTICLE|a.types.CONVEXPOLYHEDRON]=i.prototype.convexParticle=function(t,e,o,i,n,s,r,a,c,h,l){var u=-1,p=Et,d=Bt,y=null,v=bt;if(v.copy(i),v.vsub(o,v),n.conjugate(xt),xt.vmult(v,v),t.pointIsInside(v)){t.worldVerticesNeedsUpdate&&t.computeWorldVertices(o,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];i.vsub(w[0],At);var x=-g.dot(At);if(null===y||Math.abs(x)<Math.abs(y)){if(l)return!0;y=x,u=f,p.copy(g),0}}if(-1!==u){var b=this.createContactEquation(a,r,e,t,c,h);p.mult(y,d),d.vadd(i,d),d.vsub(o,d),b.rj.copy(d),p.negate(b.ni),b.ri.set(0,0,0);var E=b.ri,A=b.rj;E.vadd(i,E),E.vsub(a.position,E),A.vadd(o,A),A.vsub(r.position,A),this.result.push(b),this.createFrictionEquationsFromContact(b,this.frictionResult)}else console.warn("Point found inside convex, but did not find penetrating face!")}},i.prototype[a.types.BOX|a.types.HEIGHTFIELD]=i.prototype.boxHeightfield=function(t,e,o,i,n,s,r,a,c,h,l){return t.convexPolyhedronRepresentation.material=t.material,t.convexPolyhedronRepresentation.collisionResponse=t.collisionResponse,this.convexHeightfield(t.convexPolyhedronRepresentation,e,o,i,n,s,r,a,t,e,l)};var Ct=new h,St=new h,Rt=[0];i.prototype[a.types.CONVEXPOLYHEDRON|a.types.HEIGHTFIELD]=i.prototype.convexHeightfield=function(t,e,o,i,n,s,r,a,c,h,u){var p=e.data,d=e.elementSize,y=t.boundingSphereRadius,v=St,f=Rt,m=Ct;l.pointToLocalFrame(i,s,o,m);var w=Math.floor((m.x-y)/d)-1,g=Math.ceil((m.x+y)/d)+1,x=Math.floor((m.y-y)/d)-1,b=Math.ceil((m.y+y)/d)+1;if(!(g<0||b<0||w>p.length||x>p[0].length)){w<0&&(w=0),g<0&&(g=0),x<0&&(x=0),b<0&&(b=0),w>=p.length&&(w=p.length-1),g>=p.length&&(g=p.length-1),b>=p[0].length&&(b=p[0].length-1),x>=p[0].length&&(x=p[0].length-1);var E=[];e.getRectMinMax(w,x,g,b,E);var A=E[0],B=E[1];if(!(m.z-y>B||m.z+y<A))for(var C=w;C<g;C++)for(var S=x;S<b;S++){var R=!1;if(e.getConvexTrianglePillar(C,S,!1),l.pointToWorldFrame(i,s,e.pillarOffset,v),o.distanceTo(v)<e.pillarConvex.boundingSphereRadius+t.boundingSphereRadius&&(R=this.convexConvex(t,e.pillarConvex,o,v,n,s,r,a,null,null,u,f,null)),u&&R)return!0;if(e.getConvexTrianglePillar(C,S,!0),l.pointToWorldFrame(i,s,e.pillarOffset,v),o.distanceTo(v)<e.pillarConvex.boundingSphereRadius+t.boundingSphereRadius&&(R=this.convexConvex(t,e.pillarConvex,o,v,n,s,r,a,null,null,u,f,null)),u&&R)return!0}}};var Mt=new h,Tt=new h;i.prototype[a.types.SPHERE|a.types.HEIGHTFIELD]=i.prototype.sphereHeightfield=function(t,e,o,i,n,s,r,a,c,h,u){var p=e.data,d=t.radius,y=e.elementSize,v=Tt,f=Mt;l.pointToLocalFrame(i,s,o,f);var m=Math.floor((f.x-d)/y)-1,w=Math.ceil((f.x+d)/y)+1,g=Math.floor((f.y-d)/y)-1,x=Math.ceil((f.y+d)/y)+1;if(!(w<0||x<0||m>p.length||x>p[0].length)){m<0&&(m=0),w<0&&(w=0),g<0&&(g=0),x<0&&(x=0),m>=p.length&&(m=p.length-1),w>=p.length&&(w=p.length-1),x>=p[0].length&&(x=p[0].length-1),g>=p[0].length&&(g=p[0].length-1);var b=[];e.getRectMinMax(m,g,w,x,b);var E=b[0],A=b[1];if(!(f.z-d>A||f.z+d<E))for(var B=this.result,C=m;C<w;C++)for(var S=g;S<x;S++){var R=B.length,M=!1;if(e.getConvexTrianglePillar(C,S,!1),l.pointToWorldFrame(i,s,e.pillarOffset,v),o.distanceTo(v)<e.pillarConvex.boundingSphereRadius+t.boundingSphereRadius&&(M=this.sphereConvex(t,e.pillarConvex,o,v,n,s,r,a,t,e,u)),u&&M)return!0;if(e.getConvexTrianglePillar(C,S,!0),l.pointToWorldFrame(i,s,e.pillarOffset,v),o.distanceTo(v)<e.pillarConvex.boundingSphereRadius+t.boundingSphereRadius&&(M=this.sphereConvex(t,e.pillarConvex,o,v,n,s,r,a,t,e,u)),u&&M)return!0;if(B.length-R>2)return}}}},{"../collision/AABB":18,"../collision/Ray":25,"../equations/ContactEquation":35,"../equations/FrictionEquation":37,"../math/Quaternion":44,"../math/Transform":45,"../math/Vec3":46,"../objects/Body":47,"../shapes/ConvexPolyhedron":54,"../shapes/Shape":59,"../solver/Solver":63,"../utils/Vec3Pool":70}],72:[function(t,e,o){function i(t){t=t||{},c.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 h,this.collisionMatrixPrevious=new h,this.bodyOverlapKeeper=new l,this.shapeOverlapKeeper=new l,this.materials=[],this.contactmaterials=[],this.contactMaterialTable=new y,this.defaultMaterial=new u("default"),this.defaultContactMaterial=new p(this.defaultMaterial,this.defaultMaterial,{friction:.3,restitution:0}),this.doProfiling=!1,this.profile={solve:0,makeContactConstraints:0,broadphase:0,integrate:0,narrowphase:0},this.accumulator=0,this.subsystems=[],this.addBodyEvent={type:"addBody",body:null},this.removeBodyEvent={type:"removeBody",body:null},this.idToBodyMap={},this.broadphase.setWorld(this)}e.exports=i;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")),c=t("../utils/EventTarget"),h=t("../collision/ArrayCollisionMatrix"),l=t("../collision/OverlapKeeper"),u=t("../material/Material"),p=t("../material/ContactMaterial"),d=t("../objects/Body"),y=t("../utils/TupleDictionary"),v=t("../collision/RaycastResult"),f=t("../collision/AABB"),m=t("../collision/Ray"),w=t("../collision/NaiveBroadphase");i.prototype=new c;new f;var g=new m;if(i.prototype.getContactMaterial=function(t,e){return this.contactMaterialTable.get(t.id,e.id)},i.prototype.numObjects=function(){return this.bodies.length},i.prototype.collisionMatrixTick=function(){var t=this.collisionMatrixPrevious;this.collisionMatrixPrevious=this.collisionMatrix,this.collisionMatrix=t,this.collisionMatrix.reset(),this.bodyOverlapKeeper.tick(),this.shapeOverlapKeeper.tick()},i.prototype.add=i.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))},i.prototype.addConstraint=function(t){this.constraints.push(t)},i.prototype.removeConstraint=function(t){var e=this.constraints.indexOf(t);-1!==e&&this.constraints.splice(e,1)},i.prototype.rayTest=function(t,e,o){o instanceof v?this.raycastClosest(t,e,{skipBackfaces:!0},o):this.raycastAll(t,e,{skipBackfaces:!0},o)},i.prototype.raycastAll=function(t,e,o,i){return o.mode=m.ALL,o.from=t,o.to=e,o.callback=i,g.intersectWorld(this,o)},i.prototype.raycastAny=function(t,e,o,i){return o.mode=m.ANY,o.from=t,o.to=e,o.result=i,g.intersectWorld(this,o)},i.prototype.raycastClosest=function(t,e,o,i){return o.mode=m.CLOSEST,o.from=t,o.to=e,o.result=i,g.intersectWorld(this,o)},i.prototype.remove=function(t){t.world=null;var e=this.bodies.length-1,o=this.bodies,i=o.indexOf(t);if(-1!==i){o.splice(i,1);for(var n=0;n!==o.length;n++)o[n].index=n;this.collisionMatrix.setNumObjects(e),this.removeBodyEvent.body=t,delete this.idToBodyMap[t.id],this.dispatchEvent(this.removeBodyEvent)}},i.prototype.removeBody=i.prototype.remove,i.prototype.getBodyById=function(t){return this.idToBodyMap[t]},i.prototype.getShapeById=function(t){for(var e=this.bodies,o=0,i=e.length;o<i;o++)for(var n=e[o].shapes,s=0,r=n.length;s<r;s++){var a=n[s];if(a.id===t)return a}},i.prototype.addMaterial=function(t){this.materials.push(t)},i.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;i.prototype.step=function(t,e,o){if(o=o||10,0===(e=e||0))this.internalStep(t),this.time+=t;else{this.accumulator+=e;for(var i=0;this.accumulator>=t&&i<o;)this.internalStep(t),this.accumulator-=t,i++;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"},A={type:d.COLLIDE_EVENT_NAME,body:null,contact:null},B=[],C=[],S=[],R=[];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;i.prototype.internalStep=function(t){this.dt=t;var e,o=this.contacts,i=S,n=R,s=this.numObjects(),r=this.bodies,a=this.solver,c=this.gravity,h=this.doProfiling,l=this.profile,u=d.DYNAMIC,p=this.constraints,y=C,v=(c.norm(),c.x),f=c.y,m=c.z,w=0;for(h&&(e=performance.now()),w=0;w!==s;w++){if((L=r[w]).type===u){var g=L.force,x=L.mass;g.x+=x*v,g.y+=x*f,g.z+=x*m}}for(var w=0,M=this.subsystems.length;w!==M;w++)this.subsystems[w].update();h&&(e=performance.now()),i.length=0,n.length=0,this.broadphase.collisionPairs(this,i,n),h&&(l.broadphase=performance.now()-e);I=p.length;for(w=0;w!==I;w++){if(!(O=p[w]).collideConnected)for(j=i.length-1;j>=0;j-=1)(O.bodyA===i[j]&&O.bodyB===n[j]||O.bodyB===i[j]&&O.bodyA===n[j])&&(i.splice(j,1),n.splice(j,1))}this.collisionMatrixTick(),h&&(e=performance.now());var T=B,z=o.length;for(w=0;w!==z;w++)T.push(o[w]);o.length=0;var k=this.frictionEquations.length;for(w=0;w!==k;w++)y.push(this.frictionEquations[w]);this.frictionEquations.length=0,this.narrowphase.getContacts(i,n,this,o,T,this.frictionEquations,y),h&&(l.narrowphase=performance.now()-e),h&&(e=performance.now());for(w=0;w<this.frictionEquations.length;w++)a.addEquation(this.frictionEquations[w]);for(var P=o.length,q=0;q!==P;q++){var L=(O=o[q]).bi,V=O.bj,F=O.si,N=O.sj;(L.material&&V.material?this.getContactMaterial(L.material,V.material)||this.defaultContactMaterial:this.defaultContactMaterial).friction;if(L.material&&V.material&&(L.material.friction>=0&&V.material.friction>=0&&L.material.friction*V.material.friction,L.material.restitution>=0&&V.material.restitution>=0&&(O.restitution=L.material.restitution*V.material.restitution)),a.addEquation(O),L.allowSleep&&L.type===d.DYNAMIC&&L.sleepState===d.SLEEPING&&V.sleepState===d.AWAKE&&V.type!==d.STATIC){V.velocity.norm2()+V.angularVelocity.norm2()>=2*Math.pow(V.sleepSpeedLimit,2)&&(L._wakeUpAfterNarrowphase=!0)}if(V.allowSleep&&V.type===d.DYNAMIC&&V.sleepState===d.SLEEPING&&L.sleepState===d.AWAKE&&L.type!==d.STATIC){L.velocity.norm2()+L.angularVelocity.norm2()>=2*Math.pow(L.sleepSpeedLimit,2)&&(V._wakeUpAfterNarrowphase=!0)}this.collisionMatrix.set(L,V,!0),this.collisionMatrixPrevious.get(L,V)||(A.body=V,A.contact=O,L.dispatchEvent(A),A.body=L,V.dispatchEvent(A)),this.bodyOverlapKeeper.set(L.id,V.id),this.shapeOverlapKeeper.set(F.id,N.id)}for(this.emitContactEvents(),h&&(l.makeContactConstraints=performance.now()-e,e=performance.now()),w=0;w!==s;w++){(L=r[w])._wakeUpAfterNarrowphase&&(L.wakeUp(),L._wakeUpAfterNarrowphase=!1)}var I=p.length;for(w=0;w!==I;w++){var O=p[w];O.update();for(var j=0,W=O.equations.length;j!==W;j++){var D=O.equations[j];a.addEquation(D)}}a.solve(t,this),h&&(l.solve=performance.now()-e),a.removeAllEquations();var H=Math.pow;for(w=0;w!==s;w++){if((L=r[w]).type&u){var K=H(1-L.linearDamping,t),_=L.velocity;_.mult(K,_);var U=L.angularVelocity;if(U){var G=H(1-L.angularDamping,t);U.mult(G,U)}}}for(this.dispatchEvent(E),w=0;w!==s;w++){(L=r[w]).preStep&&L.preStep.call(L)}h&&(e=performance.now());var X=this.stepnumber%(this.quatNormalizeSkip+1)==0,Y=this.quatNormalizeFast;for(w=0;w!==s;w++)r[w].integrate(t,X,Y);for(this.clearForces(),this.broadphase.dirty=!0,h&&(l.integrate=performance.now()-e),this.time+=t,this.stepnumber+=1,this.dispatchEvent(b),w=0;w!==s;w++){var Q=(L=r[w]).postStep;Q&&Q.call(L)}if(this.allowSleep)for(w=0;w!==s;w++)r[w].sleepTick(this.time)},i.prototype.emitContactEvents=function(){var t=[],e=[],o={type:"beginContact",bodyA:null,bodyB:null},i={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 c=0,h=t.length;c<h;c+=2)o.bodyA=this.getBodyById(t[c]),o.bodyB=this.getBodyById(t[c+1]),this.dispatchEvent(o);o.bodyA=o.bodyB=null}if(a){for(var c=0,h=e.length;c<h;c+=2)i.bodyA=this.getBodyById(e[c]),i.bodyB=this.getBodyById(e[c+1]),this.dispatchEvent(i);i.bodyA=i.bodyB=null}t.length=e.length=0;var l=this.hasAnyEventListener("beginShapeContact"),u=this.hasAnyEventListener("endShapeContact");if((l||u)&&this.shapeOverlapKeeper.getDiff(t,e),l){for(var c=0,h=t.length;c<h;c+=2){var p=this.getShapeById(t[c]),d=this.getShapeById(t[c+1]);n.shapeA=p,n.shapeB=d,n.bodyA=p.body,n.bodyB=d.body,this.dispatchEvent(n)}n.bodyA=n.bodyB=n.shapeA=n.shapeB=null}if(u){for(var c=0,h=e.length;c<h;c+=2){var p=this.getShapeById(e[c]),d=this.getShapeById(e[c+1]);s.shapeA=p,s.shapeB=d,s.bodyA=p.body,s.bodyB=d.body,this.dispatchEvent(s)}s.bodyA=s.bodyB=s.shapeA=s.shapeB=null}}}(),i.prototype.clearForces=function(){for(var t=this.bodies,e=t.length,o=0;o!==e;o++){var i=t[o];i.force,i.torque;i.force.set(0,0,0),i.torque.set(0,0,0)}}},{"../collision/AABB":18,"../collision/ArrayCollisionMatrix":19,"../collision/NaiveBroadphase":22,"../collision/OverlapKeeper":24,"../collision/Ray":25,"../collision/RaycastResult":26,"../equations/ContactEquation":35,"../equations/FrictionEquation":37,"../material/ContactMaterial":40,"../material/Material":41,"../math/Quaternion":44,"../math/Vec3":46,"../objects/Body":47,"../shapes/Shape":59,"../solver/GSSolver":62,"../utils/EventTarget":65,"../utils/TupleDictionary":68,"./Narrowphase":71}],73:[function(t,e,o){function i(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,o,i,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(),(i=new THREE.Vector3).setFromMatrixPosition(t.matrixWorld),(o=n.translate(i.negate()).getCenter()).lengthSq()&&(e.offset=o),e):null}function s(t){var e,o,i=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===i.length)return null;if(1===i.length){var r=new THREE.Vector3,a=new THREE.Quaternion,c=new THREE.Vector3;return i[0].geometry.isBufferGeometry?i[0].geometry.attributes.position&&n.fromBufferGeometry(i[0].geometry):n=i[0].geometry.clone(),n.metadata=i[0].geometry.metadata,i[0].updateMatrixWorld(),i[0].matrixWorld.decompose(r,a,c),n.scale(c.x,c.y,c.z)}for(;o=i.pop();)o.updateMatrixWorld(),o.geometry.isBufferGeometry?(n.fromBufferGeometry(o.geometry),s.merge(n,o.matrixWorld)):s.merge(o.geometry,o.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"),c=t("./lib/THREE.quickhull"),h=Math.PI/2,l={BOX:"Box",CYLINDER:"Cylinder",SPHERE:"Sphere",HULL:"ConvexPolyhedron",MESH:"Trimesh"};e.exports=a.mesh2shape=function(t,e){var o;if((e=e||{}).type===l.BOX)return n(t);if(e.type===l.CYLINDER)return function(t,e){var o,i,n,s=new THREE.Box3,r=["x","y","z"],c=e.cylinderAxis||"y",l=r.splice(r.indexOf(c),1)&&r;return s.setFromObject(t),isFinite(s.min.lengthSq())?(i=s.max[c]-s.min[c],n=.5*Math.max(s.max[l[0]]-s.min[l[0]],s.max[l[1]]-s.min[l[1]]),o=new a.Cylinder(n,n,i,12),o._type=a.Shape.types.CYLINDER,o.radiusTop=n,o.radiusBottom=n,o.height=i,o.numSegments=12,o.orientation=new a.Quaternion,o.orientation.setFromEuler("y"===c?h:0,"z"===c?h:0,0,"XYZ").normalize(),o):null}(t,e);if(e.type===l.SPHERE)return function(t,e){if(e.sphereRadius)return new a.Sphere(e.sphereRadius);var o=s(t);return o?(o.computeBoundingSphere(),new a.Sphere(o.boundingSphere.radius)):null}(t,e);if(e.type===l.HULL)return function(t){var e,o,i,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=c(r),o=new Array(n.vertices.length),e=0;e<n.vertices.length;e++)o[e]=new a.Vec3(n.vertices[e].x,n.vertices[e].y,n.vertices[e].z);for(i=new Array(n.faces.length),e=0;e<n.faces.length;e++)i[e]=[n.faces[e].a,n.faces[e].b,n.faces[e].c];return new a.ConvexPolyhedron(o,i)}(t);if(e.type===l.MESH)return(o=s(t))?function(t){var e,o=r(t);return o.length?(e=Object.keys(o).map(Number),new a.Trimesh(o,e)):null}(o):null;if(e.type)throw new Error('[CANNON.mesh2shape] Invalid type "%s".',e.type);if(!(o=s(t)))return null;switch(o.metadata?o.metadata.type:o.type){case"BoxGeometry":case"BoxBufferGeometry":return i(o);case"CylinderGeometry":case"CylinderBufferGeometry":return function(t){var e,o=t.metadata?t.metadata.parameters:t.parameters;return e=new a.Cylinder(o.radiusTop,o.radiusBottom,o.height,o.radialSegments),e._type=a.Shape.types.CYLINDER,e.radiusTop=o.radiusTop,e.radiusBottom=o.radiusBottom,e.height=o.height,e.numSegments=o.radialSegments,e.orientation=new a.Quaternion,e.orientation.setFromEuler(THREE.Math.degToRad(-90),0,0,"XYZ").normalize(),e}(o);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))}(o);case"SphereGeometry":case"SphereBufferGeometry":return function(t){var e=t.metadata?t.metadata.parameters:t.parameters;return new a.Sphere(e.radius)}(o);case"TubeGeometry":case"Geometry":case"BufferGeometry":return n(t);default:return console.warn('Unrecognized geometry: "%s". Using bounding box as shape.',o.type),i(o)}},a.mesh2shape.Type=l},{"./lib/THREE.quickhull":74,cannon:17}],74:[function(t,e,o){e.exports=function(){function t(t){for(;B.length>0;)!function(t,i){var n,s=A.length,r=[t],a=i.indexOf(t.visiblePoints.pop());for(;s-- >0;)(n=A[s])!==t&&e(n,i).dot(g.subVectors(i[a],i[n[0]]))>0&&r.push(n);var c,h,l,u,p=s=r.length,d=1===s,y=[],v=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],y=[n[0],n[1],n[1],n[2],n[2],n[0]],B.indexOf(n)>-1&&B.splice(B.indexOf(n),1),n.visiblePoints&&(f=f.concat(n.visiblePoints)),A.splice(A.indexOf(n),1);else for(;s-- >0;){n=r[s],B.indexOf(n)>-1&&B.splice(B.indexOf(n),1),n.visiblePoints&&(f=f.concat(n.visiblePoints)),A.splice(A.indexOf(n),1);var m;for(cEdgeIndex=0;cEdgeIndex<3;){for(m=!1,p=r.length,l=n[cEdgeIndex],u=n[(cEdgeIndex+1)%3];p-- >0&&!m;)if(c=r[p],v=0,c!==n)for(;v<3&&!m;)h=v+1,m=c[v]===l&&c[h%3]===u||c[v]===u&&c[h%3]===l,v++;m&&!d||(y.push(l),y.push(u)),cEdgeIndex++}}s=0;var w,x=y.length/2;for(;s<x;)o(w=[y[2*s+1],a,y[2*s]],f,i),A.push(w),void 0!==w.visiblePoints&&B.push(w),s++}(B.shift(),t)}function e(t,e){if(void 0!==t.normal)return t.normal;var o=e[t[0]],i=e[t[1]],n=e[t[2]];return d.subVectors(i,o),y.subVectors(n,o),w.crossVectors(y,d),w.normalize(),t.normal=w.clone()}function o(t,o,i){var n=i[t[0]],s=[],r=e(t,i);o.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=o.length;for(1===a&&(s[o[0].x/3]=r.dot(f.subVectors(o[0],n)));a-- >0&&s[o[a].x/3]>0;);a+1<o.length&&s[o[a+1].x/3]>0&&(t.visiblePoints=o.splice(a+1))}var i,n,s,r,a,c,h,l,u,p,d,y,v,f,m,w,g,x,b,E,A=[],B=[],C=0,S=function(){var t=new THREE.Vector3,e=new THREE.Vector3,o=new THREE.Vector3;return function(i,n,s){return t.subVectors(s,i),e.subVectors(n,i),o.crossVectors(t,e),o.normalize()}}(),R=function(){var t=new THREE.Vector3,e=new THREE.Vector3,o=new THREE.Vector3;return function(i,n,s){t.subVectors(n,i),e.subVectors(s,i),o.subVectors(s,n);var r=e.dot(t);if(r<0)return e.dot(e);var a=t.dot(t);return r>=a?o.dot(o):e.dot(e)-r*r/a}}();return function(e){for(d=new THREE.Vector3,y=new THREE.Vector3,v=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,A=[],B=[],L=i=points.length,n=points.slice(0,6),C=0;L-- >0;)points[L].x<n[0].x&&(n[0]=points[L]),points[L].x>n[1].x&&(n[1]=points[L]),points[L].y<n[2].y&&(n[2]=points[L]),points[L].y<n[3].y&&(n[3]=points[L]),points[L].z<n[4].z&&(n[4]=points[L]),points[L].z<n[5].z&&(n[5]=points[L]);for(r=L=6;L-- >0;)for(r=L-1;r-- >0;)C<(s=n[L].distanceToSquared(n[r]))&&(C=s,a=n[L],c=n[r]);for(L=6,C=0;L-- >0;)s=R(a,c,n[L]),C<s&&(C=s,h=n[L]);for(u=S(a,c,h),p=u.dot(a),C=0,L=i;L-- >0;)s=Math.abs(points[L].dot(u)-p),C<s&&(C=s,l=points[L]);var M=points.indexOf(a),T=points.indexOf(c),z=points.indexOf(h),k=points.indexOf(l),P=[[z,T,M],[T,k,M],[z,k,T],[M,k,z]];x.subVectors(c,a).normalize(),b.subVectors(h,a).normalize(),E.subVectors(l,a).normalize();E.dot((new THREE.Vector3).crossVectors(b,x))<0&&(P[0].reverse(),P[1].reverse(),P[2].reverse(),P[3].reverse());var q=points.slice();q.splice(q.indexOf(a),1),q.splice(q.indexOf(c),1),q.splice(q.indexOf(h),1),q.splice(q.indexOf(l),1);for(var L=P.length;L-- >0;)o(P[L],q,points),void 0!==P[L].visiblePoints&&B.push(P[L]),A.push(P[L]);t(points);for(var V=A.length;V-- >0;)e.faces[V]=new THREE.Face3(A[V][2],A[V][1],A[V][0],A[V].normal);return e.normalsNeedUpdate=!0,e}}()},{}],75:[function(t,e,o){e.exports={schema:{enabled:{default:!0},mode:{default:"teleport",oneOf:["teleport","animate"]},animateSpeed:{default:3}},init:function(){this.active=!0,this.checkpoint=null,this.offset=new THREE.Vector3,this.position=new THREE.Vector3,this.targetPosition=new THREE.Vector3},play:function(){this.active=!0},pause:function(){this.active=!1},setCheckpoint:function(t){var e=this.el;this.active&&this.checkpoint!==t&&(this.checkpoint&&e.emit("navigation-end",{checkpoint:this.checkpoint}),this.checkpoint=t,this.sync(),this.position.distanceTo(this.targetPosition)<.1?this.checkpoint=null:(e.emit("navigation-start",{checkpoint:t}),"teleport"===this.data.mode&&(this.el.setAttribute("position",this.targetPosition),this.checkpoint=null,e.emit("navigation-end",{checkpoint:t}))))},isVelocityActive:function(){return!(!this.active||!this.checkpoint)},getVelocity:function(){if(this.active){var t=this.data,e=this.offset,o=this.position,i=this.targetPosition,n=this.checkpoint;return this.sync(),o.distanceTo(i)<.1?(this.checkpoint=null,this.el.emit("navigation-end",{checkpoint:n}),e.set(0,0,0)):(e.setLength(t.animateSpeed),e)}},sync:function(){var t=this.offset,e=this.position,o=this.targetPosition;e.copy(this.el.getAttribute("position")),o.copy(this.checkpoint.object3D.getWorldPosition()),o.add(this.checkpoint.components.checkpoint.getOffset()),t.copy(o).sub(e)}}},{}],76:[function(t,e,o){var i=t("../../lib/GamepadButton"),n=t("../../lib/GamepadButtonEvent");e.exports={GamepadButton:i,schema:{controller:{default:0,oneOf:[0,1,2,3]},enabled:{default:!0},debug:{default:!1}},init:function(){var t=this.el.sceneEl;this.prevTime=window.performance.now(),this.buttons={},t.addBehavior(this)},update:function(){this.tick()},tick:function(){this.updateButtonState()},remove:function(){},isVelocityActive:function(){if(!this.data.enabled||!this.isConnected())return!1;var t=this.getDpad(),e=this.getJoystick(0),o=t.x||e.x,i=t.y||e.y;return Math.abs(o)>.2||Math.abs(i)>.2},getVelocityDelta:function(){var t=this.getDpad(),e=this.getJoystick(0),o=t.x||e.x,i=t.y||e.y,n=new THREE.Vector3;return Math.abs(o)>.2&&(n.x+=o),Math.abs(i)>.2&&(n.z+=i),n},isRotationActive:function(){if(!this.data.enabled||!this.isConnected())return!1;var t=this.getJoystick(1);return Math.abs(t.x)>.2||Math.abs(t.y)>.2},getRotationDelta:function(){var t=this.getJoystick(1);return Math.abs(t.x)<=.2&&(t.x=0),Math.abs(t.y)<=.2&&(t.y=0),t},updateButtonState:function(){var t=this.getGamepad();if(this.data.enabled&&t)for(var e=0;e<t.buttons.length;e++)t.buttons[e].pressed&&!this.buttons[e]?this.emit(new n("gamepadbuttondown",e,t.buttons[e])):!t.buttons[e].pressed&&this.buttons[e]&&this.emit(new n("gamepadbuttonup",e,t.buttons[e])),this.buttons[e]=t.buttons[e].pressed;else Object.keys(this.buttons)&&(this.buttons={})},emit:function(t){this.el.emit(t.type,t),this.el.emit(t.type+":"+t.index,new n(t.type,t.index,t))},getGamepad:function(){var t=navigator.getGamepads&&navigator.getGamepads()[this.data.controller],e=this.el.sceneEl.components["proxy-controls"];return e&&e.isConnected()&&e.getGamepad(this.data.controller)||t},getButton:function(t){return this.getGamepad().buttons[t]},getAxis:function(t){return this.getGamepad().axes[t]},getJoystick:function(t){var e=this.getGamepad();switch(t){case 0:return new THREE.Vector2(e.axes[0],e.axes[1]);case 1:return new THREE.Vector2(e.axes[2],e.axes[3]);default:throw new Error('Unexpected joystick index "%d".',t)}},getDpad:function(){var t=this.getGamepad();return t.buttons[i.DPAD_RIGHT]?new THREE.Vector2((t.buttons[i.DPAD_RIGHT].pressed?1:0)+(t.buttons[i.DPAD_LEFT].pressed?-1:0),(t.buttons[i.DPAD_UP].pressed?-1:0)+(t.buttons[i.DPAD_DOWN].pressed?1:0)):new THREE.Vector2},isConnected:function(){var t=this.getGamepad();return!(!t||!t.connected)},getID:function(){return this.getGamepad().id}}},{"../../lib/GamepadButton":2,"../../lib/GamepadButtonEvent":3}],77:[function(t,e,o){function i(t){return 0===t.x&&0===t.y&&0===t.z}var n=THREE.Math.radToDeg,s=AFRAME.utils.device.isMobile();e.exports={schema:{enabled:{default:!0},standing:{default:!0}},init:function(){this.isPositionCalibrated=!1,this.dolly=new THREE.Object3D,this.hmdEuler=new THREE.Euler,this.previousHMDPosition=new THREE.Vector3,this.deltaHMDPosition=new THREE.Vector3,this.vrControls=new THREE.VRControls(this.dolly),this.rotation=new THREE.Vector3},update:function(){var t=this.data,e=this.vrControls;e.standing=t.standing,e.update()},tick:function(){this.vrControls.update()},remove:function(){this.vrControls.dispose()},isRotationActive:function(){var t=this.hmdEuler;return!(!this.data.enabled||!this.el.sceneEl.is("vr-mode")&&!s)&&(t.setFromQuaternion(this.dolly.quaternion,"YXZ"),!i(t))},getRotation:function(){var t=this.hmdEuler;return this.rotation.set(n(t.x),n(t.y),n(t.z))},isVelocityActive:function(){var t=this.deltaHMDPosition,e=this.previousHMDPosition,o=this.calculateHMDPosition();return this.isPositionCalibrated=this.isPositionCalibrated||!i(e),!(!this.data.enabled||!this.el.sceneEl.is("vr-mode")||s)&&(t.copy(o).sub(e),e.copy(o),this.isPositionCalibrated&&!i(t))},getPositionDelta:function(){return this.deltaHMDPosition},calculateHMDPosition:function(){var t=this.dolly,e=new THREE.Vector3;return t.updateMatrix(),e.setFromMatrixPosition(t.matrix),e}}},{}],78:[function(t,e,o){var i=t("aframe-physics-system");e.exports={"checkpoint-controls":t("./checkpoint-controls"),"gamepad-controls":t("./gamepad-controls"),"hmd-controls":t("./hmd-controls"),"keyboard-controls":t("./keyboard-controls"),"mouse-controls":t("./mouse-controls"),"touch-controls":t("./touch-controls"),"universal-controls":t("./universal-controls"),registerAll:function(t){this._registered||(t=t||window.AFRAME,i.registerAll(),t.components["checkpoint-controls"]||t.registerComponent("checkpoint-controls",this["checkpoint-controls"]),t.components["gamepad-controls"]||t.registerComponent("gamepad-controls",this["gamepad-controls"]),t.components["hmd-controls"]||t.registerComponent("hmd-controls",this["hmd-controls"]),t.components["keyboard-controls"]||t.registerComponent("keyboard-controls",this["keyboard-controls"]),t.components["mouse-controls"]||t.registerComponent("mouse-controls",this["mouse-controls"]),t.components["touch-controls"]||t.registerComponent("touch-controls",this["touch-controls"]),t.components["universal-controls"]||t.registerComponent("universal-controls",this["universal-controls"]),this._registered=!0)}}},{"./checkpoint-controls":75,"./gamepad-controls":76,"./hmd-controls":77,"./keyboard-controls":79,"./mouse-controls":80,"./touch-controls":81,"./universal-controls":82,"aframe-physics-system":5}],79:[function(t,e,o){t("../../lib/keyboard.polyfill");var i=window.KeyboardEvent;e.exports={schema:{enabled:{default:!0},debug:{default:!1}},init:function(){this.dVelocity=new THREE.Vector3,this.localKeys={},this.listeners={keydown:this.onKeyDown.bind(this),keyup:this.onKeyUp.bind(this),blur:this.onBlur.bind(this)},this.attachEventListeners()},isVelocityActive:function(){return this.data.enabled&&!!Object.keys(this.getKeys()).length},getVelocityDelta:function(){var t=this.data,e=this.getKeys();return this.dVelocity.set(0,0,0),t.enabled&&((e.KeyW||e.ArrowUp)&&(this.dVelocity.z-=1),(e.KeyA||e.ArrowLeft)&&(this.dVelocity.x-=1),(e.KeyS||e.ArrowDown)&&(this.dVelocity.z+=1),(e.KeyD||e.ArrowRight)&&(this.dVelocity.x+=1)),this.dVelocity.clone()},play:function(){this.attachEventListeners()},pause:function(){this.removeEventListeners()},remove:function(){this.pause()},attachEventListeners:function(){window.addEventListener("keydown",this.listeners.keydown,!1),window.addEventListener("keyup",this.listeners.keyup,!1),window.addEventListener("blur",this.listeners.blur,!1)},removeEventListeners:function(){window.removeEventListener("keydown",this.listeners.keydown),window.removeEventListener("keyup",this.listeners.keyup),window.removeEventListener("blur",this.listeners.blur)},onKeyDown:function(t){AFRAME.utils.shouldCaptureKeyEvent(t)&&(this.localKeys[t.code]=!0,this.emit(t))},onKeyUp:function(t){AFRAME.utils.shouldCaptureKeyEvent(t)&&(delete this.localKeys[t.code],this.emit(t))},onBlur:function(){for(var t in this.localKeys)this.localKeys.hasOwnProperty(t)&&delete this.localKeys[t]},emit:function(t){"__keyboard-controls-proxy"in t&&this.el.emit(t.type,t),this.el.emit(t.type+":"+t.code,new i(t.type,t)),this.data.debug&&console.log(t.type+":"+t.code)},isPressed:function(t){return t in this.getKeys()},getKeys:function(){return this.isProxied()?this.el.sceneEl.components["proxy-controls"].getKeyboard():this.localKeys},isProxied:function(){var t=this.el.sceneEl.components["proxy-controls"];return t&&t.isConnected()}}},{"../../lib/keyboard.polyfill":4}],80:[function(t,e,o){document.exitPointerLock=document.exitPointerLock||document.mozExitPointerLock,e.exports={schema:{enabled:{default:!0},pointerlockEnabled:{default:!0},sensitivity:{default:.04}},init:function(){this.mouseDown=!1,this.pointerLocked=!1,this.lookVector=new THREE.Vector2,this.bindMethods()},update:function(t){var e=this.data;t.pointerlockEnabled&&!e.pointerlockEnabled&&this.pointerLocked&&document.exitPointerLock()},play:function(){this.addEventListeners()},pause:function(){this.removeEventListeners(),this.lookVector.set(0,0)},remove:function(){this.pause()},bindMethods:function(){this.onMouseDown=this.onMouseDown.bind(this),this.onMouseMove=this.onMouseMove.bind(this),this.onMouseUp=this.onMouseUp.bind(this),this.onMouseUp=this.onMouseUp.bind(this),this.onPointerLockChange=this.onPointerLockChange.bind(this),this.onPointerLockChange=this.onPointerLockChange.bind(this),this.onPointerLockChange=this.onPointerLockChange.bind(this)},addEventListeners:function(){var t=this.el.sceneEl,e=t.canvas,o=this.data;e?(e.addEventListener("mousedown",this.onMouseDown,!1),e.addEventListener("mousemove",this.onMouseMove,!1),e.addEventListener("mouseup",this.onMouseUp,!1),e.addEventListener("mouseout",this.onMouseUp,!1),o.pointerlockEnabled&&(document.addEventListener("pointerlockchange",this.onPointerLockChange,!1),document.addEventListener("mozpointerlockchange",this.onPointerLockChange,!1),document.addEventListener("pointerlockerror",this.onPointerLockError,!1))):t.addEventListener("render-target-loaded",this.addEventListeners.bind(this))},removeEventListeners:function(){var t=this.el.sceneEl&&this.el.sceneEl.canvas;t&&(t.removeEventListener("mousedown",this.onMouseDown,!1),t.removeEventListener("mousemove",this.onMouseMove,!1),t.removeEventListener("mouseup",this.onMouseUp,!1),t.removeEventListener("mouseout",this.onMouseUp,!1)),document.removeEventListener("pointerlockchange",this.onPointerLockChange,!1),document.removeEventListener("mozpointerlockchange",this.onPointerLockChange,!1),document.removeEventListener("pointerlockerror",this.onPointerLockError,!1)},isRotationActive:function(){return this.data.enabled&&(this.mouseDown||this.pointerLocked)},getRotationDelta:function(){var t=this.lookVector.clone().multiplyScalar(this.data.sensitivity);return this.lookVector.set(0,0),t},onMouseMove:function(t){var e=this.previousMouseEvent;if(this.data.enabled&&(this.mouseDown||this.pointerLocked)){var o=t.movementX||t.mozMovementX||0,i=t.movementY||t.mozMovementY||0;this.pointerLocked||(o=t.screenX-e.screenX,i=t.screenY-e.screenY),this.lookVector.x+=o,this.lookVector.y+=i,this.previousMouseEvent=t}},onMouseDown:function(t){var e=this.el.sceneEl.canvas,o=(AFRAME.INSPECTOR||{}).opened;this.mouseDown=!0,this.previousMouseEvent=t,!this.data.pointerlockEnabled||this.pointerLocked||o||(e.requestPointerLock?e.requestPointerLock():e.mozRequestPointerLock&&e.mozRequestPointerLock())},onMouseUp:function(){this.mouseDown=!1},onPointerLockChange:function(){this.pointerLocked=!(!document.pointerLockElement&&!document.mozPointerLockElement)},onPointerLockError:function(){this.pointerLocked=!1}}},{}],81:[function(t,e,o){e.exports={schema:{enabled:{default:!0}},init:function(){this.dVelocity=new THREE.Vector3,this.bindMethods()},play:function(){this.addEventListeners()},pause:function(){this.removeEventListeners(),this.dVelocity.set(0,0,0)},remove:function(){this.pause()},addEventListeners:function(){var t=this.el.sceneEl,e=t.canvas;e?(e.addEventListener("touchstart",this.onTouchStart),e.addEventListener("touchend",this.onTouchEnd)):t.addEventListener("render-target-loaded",this.addEventListeners.bind(this))},removeEventListeners:function(){var t=this.el.sceneEl&&this.el.sceneEl.canvas;t&&(t.removeEventListener("touchstart",this.onTouchStart),t.removeEventListener("touchend",this.onTouchEnd))},isVelocityActive:function(){return this.data.enabled&&this.isMoving},getVelocityDelta:function(){return this.dVelocity.z=this.isMoving?-1:0,this.dVelocity.clone()},bindMethods:function(){this.onTouchStart=this.onTouchStart.bind(this),this.onTouchEnd=this.onTouchEnd.bind(this)},onTouchStart:function(t){this.isMoving=!0,t.preventDefault()},onTouchEnd:function(t){this.isMoving=!1,t.preventDefault()}}},{}],82:[function(t,e,o){var i=Math.PI/2;e.exports={dependencies:["velocity","rotation"],schema:{enabled:{default:!0},movementEnabled:{default:!0},movementControls:{default:["gamepad","keyboard","touch","hmd"]},rotationEnabled:{default:!0},rotationControls:{default:["hmd","gamepad","mouse"]},movementSpeed:{default:5},movementEasing:{default:15},movementEasingY:{default:0},movementAcceleration:{default:80},rotationSensitivity:{default:.05},fly:{default:!1}},init:function(){var t=this.el.getAttribute("rotation");this.el.hasAttribute("look-controls")&&this.data.rotationEnabled&&console.error("[universal-controls] The `universal-controls` component is a replacement for `look-controls`, and cannot be used in combination with it."),this.velocity=new THREE.Vector3,this.pitch=new THREE.Object3D,this.pitch.rotation.x=THREE.Math.degToRad(t.x),this.yaw=new THREE.Object3D,this.yaw.position.y=10,this.yaw.rotation.y=THREE.Math.degToRad(t.y),this.yaw.add(this.pitch),this.heading=new THREE.Euler(0,0,0,"YXZ"),this.el.sceneEl.hasLoaded?this.injectControls():this.el.sceneEl.addEventListener("loaded",this.injectControls.bind(this))},update:function(){this.el.sceneEl.hasLoaded&&this.injectControls()},injectControls:function(){var t,e,o=this.data;for(t=0;t<o.movementControls.length;t++)e=o.movementControls[t]+"-controls",this.el.components[e]||this.el.setAttribute(e,"");for(t=0;t<o.rotationControls.length;t++)e=o.rotationControls[t]+"-controls",this.el.components[e]||this.el.setAttribute(e,"")},tick:function(t,e){e&&(this.data.rotationEnabled&&this.updateRotation(e),this.data.movementEnabled&&e/1e3>.2?(this.velocity.set(0,0,0),this.el.setAttribute("velocity",this.velocity)):this.updateVelocity(e))},updateRotation:function(t){for(var e,o,n=this.data,s=0,r=n.rotationControls.length;s<r;s++)if((e=this.el.components[n.rotationControls[s]+"-controls"])&&e.isRotationActive()){if(e.getRotationDelta)(o=e.getRotationDelta(t)).multiplyScalar(n.rotationSensitivity),this.yaw.rotation.y-=o.x,this.pitch.rotation.x-=o.y,this.pitch.rotation.x=Math.max(-i,Math.min(i,this.pitch.rotation.x)),this.el.setAttribute("rotation",{x:THREE.Math.radToDeg(this.pitch.rotation.x),y:THREE.Math.radToDeg(this.yaw.rotation.y),z:0});else{if(!e.getRotation)throw new Error("Incompatible rotation controls: %s",n.rotationControls[s]);this.el.setAttribute("rotation",e.getRotation())}break}},updateVelocity:function(t){var e,o,i=this.velocity,n=this.data;if(n.movementEnabled)for(var s=0,r=n.movementControls.length;s<r;s++)if((e=this.el.components[n.movementControls[s]+"-controls"])&&e.isVelocityActive()){if(!e.getVelocityDelta){if(e.getVelocity)return void this.el.setAttribute("velocity",e.getVelocity());if(e.getPositionDelta)return i.copy(e.getPositionDelta(t).multiplyScalar(1e3/t)),void this.el.setAttribute("velocity",i);throw new Error("Incompatible movement controls: ",n.movementControls[s])}o=e.getVelocityDelta(t);break}if(i.copy(this.el.getAttribute("velocity")),i.x-=i.x*n.movementEasing*t/1e3,i.y-=i.y*n.movementEasingY*t/1e3,i.z-=i.z*n.movementEasing*t/1e3,o&&n.movementEnabled){o.length()>1?o.setLength(this.data.movementAcceleration*t/1e3):o.multiplyScalar(this.data.movementAcceleration*t/1e3);var a=this.el.getAttribute("rotation");a&&(this.heading.set(n.fly?THREE.Math.degToRad(a.x):0,THREE.Math.degToRad(a.y),0),o.applyEuler(this.heading)),i.add(o)}this.el.setAttribute("velocity",i)}}},{}]},{},[1]);
|