-
Notifications
You must be signed in to change notification settings - Fork 6
/
aframe-extras.js
7 lines (7 loc) · 204 KB
/
aframe-extras.js
1
2
3
4
5
6
7
!function t(e,i,o){function n(r,a){if(!i[r]){if(!e[r]){var h="function"==typeof require&&require;if(!a&&h)return h(r,!0);if(s)return s(r,!0);var l=new Error("Cannot find module '"+r+"'");throw l.code="MODULE_NOT_FOUND",l}var c=i[r]={exports:{}};e[r][0].call(c.exports,function(t){var i=e[r][1][t];return n(i?i:t)},c,c.exports,t,e,i,o)}return i[r].exports}for(var s="function"==typeof require&&require,r=0;r<o.length;r++)n(o[r]);return n}({1:[function(t,e,i){t("./").registerAll()},{"./":2}],2:[function(t,e,i){e.exports={controls:t("./src/controls"),loaders:t("./src/loaders"),math:t("./src/math"),misc:t("./src/misc"),physics:t("./src/physics"),primitives:t("./src/primitives"),shadows:t("./src/shadows"),registerAll:function(){this.controls.registerAll(),this.loaders.registerAll(),this.math.registerAll(),this.misc.registerAll(),this.physics.registerAll(),this.primitives.registerAll(),this.shadows.registerAll()}}},{"./src/controls":13,"./src/loaders":18,"./src/math":21,"./src/misc":26,"./src/physics":33,"./src/primitives":40,"./src/shadows":41}],3:[function(t,e,i){var o=t("cannon");o.shape2mesh=function(t){for(var e=new THREE.Object3D,i=0;i<t.shapes.length;i++){var n,s=t.shapes[i];switch(s.type){case o.Shape.types.SPHERE:var r=new THREE.SphereGeometry(s.radius,8,8);n=new THREE.Mesh(r,this.currentMaterial);break;case o.Shape.types.PARTICLE:n=new THREE.Mesh(this.particleGeo,this.particleMaterial);var a=this.settings;n.scale.set(a.particleSize,a.particleSize,a.particleSize);break;case o.Shape.types.PLANE:var h=new THREE.PlaneGeometry(10,10,4,4);n=new THREE.Object3D;var l=new THREE.Object3D,c=new THREE.Mesh(h,this.currentMaterial);c.scale.set(100,100,100),l.add(c),c.castShadow=!0,c.receiveShadow=!0,n.add(l);break;case o.Shape.types.BOX:var u=new THREE.BoxGeometry(2*s.halfExtents.x,2*s.halfExtents.y,2*s.halfExtents.z);n=new THREE.Mesh(u,this.currentMaterial);break;case o.Shape.types.CONVEXPOLYHEDRON:for(var p=new THREE.Geometry,d=0;d<s.vertices.length;d++){var y=s.vertices[d];p.vertices.push(new THREE.Vector3(y.x,y.y,y.z))}for(var d=0;d<s.faces.length;d++)for(var v=s.faces[d],f=v[0],m=1;m<v.length-1;m++){var g=v[m],w=v[m+1];p.faces.push(new THREE.Face3(f,g,w))}p.computeBoundingSphere(),p.computeFaceNormals(),n=new THREE.Mesh(p,this.currentMaterial);break;case o.Shape.types.HEIGHTFIELD:for(var h=new THREE.Geometry,b=new o.Vec3,x=new o.Vec3,E=new o.Vec3,A=0;A<s.data.length-1;A++)for(var C=0;C<s.data[A].length-1;C++)for(var B=0;B<2;B++){s.getConvexTrianglePillar(A,C,0===B),b.copy(s.pillarConvex.vertices[0]),x.copy(s.pillarConvex.vertices[1]),E.copy(s.pillarConvex.vertices[2]),b.vadd(s.pillarOffset,b),x.vadd(s.pillarOffset,x),E.vadd(s.pillarOffset,E),h.vertices.push(new THREE.Vector3(b.x,b.y,b.z),new THREE.Vector3(x.x,x.y,x.z),new THREE.Vector3(E.x,E.y,E.z));var d=h.vertices.length-3;h.faces.push(new THREE.Face3(d,d+1,d+2))}h.computeBoundingSphere(),h.computeFaceNormals(),n=new THREE.Mesh(h,this.currentMaterial);break;case o.Shape.types.TRIMESH:for(var h=new THREE.Geometry,b=new o.Vec3,x=new o.Vec3,E=new o.Vec3,d=0;d<s.indices.length/3;d++){s.getTriangleVertices(d,b,x,E),h.vertices.push(new THREE.Vector3(b.x,b.y,b.z),new THREE.Vector3(x.x,x.y,x.z),new THREE.Vector3(E.x,E.y,E.z));var m=h.vertices.length-3;h.faces.push(new THREE.Face3(m,m+1,m+2))}h.computeBoundingSphere(),h.computeFaceNormals(),n=new THREE.Mesh(h,this.currentMaterial);break;default:throw"Visual type not recognized: "+s.type}if(n.receiveShadow=!0,n.castShadow=!0,n.children)for(var d=0;d<n.children.length;d++)if(n.children[d].castShadow=!0,n.children[d].receiveShadow=!0,n.children[d])for(var m=0;m<n.children[d].length;m++)n.children[d].children[m].castShadow=!0,n.children[d].children[m].receiveShadow=!0;var S=t.shapeOffsets[i],R=t.shapeOrientations[i];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=o.shape2mesh},{cannon:45}],4:[function(t,e,i){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})},{}],5:[function(t,e,i){function o(t,e,i){this.type=t,this.index=e,this.pressed=i.pressed,this.value=i.value}e.exports=o},{}],6:[function(t,e,i){e.exports=THREE.PLYLoader=function(t){this.manager=void 0!==t?t:THREE.DefaultLoadingManager,this.propertyNameMapping={}},THREE.PLYLoader.prototype={constructor:THREE.PLYLoader,load:function(t,e,i,o){var n=this,s=new THREE.XHRLoader(this.manager);s.setResponseType("arraybuffer"),s.load(t,function(t){e(n.parse(t))},i,o)},setPropertyNameMapping:function(t){this.propertyNameMapping=t},bin2str:function(t){for(var e=new Uint8Array(t),i="",o=0;o<t.byteLength;o++)i+=String.fromCharCode(e[o]);return i},isASCII:function(t){var e=this.parseHeader(this.bin2str(t));return"ascii"===e.format},parse:function(t){return t instanceof ArrayBuffer?this.isASCII(t)?this.parseASCII(this.bin2str(t)):this.parseBinary(t):this.parseASCII(t)},parseHeader:function(t){function e(t,e){var i={type:t[0]};return"list"===i.type?(i.name=t[3],i.countType=t[1],i.itemType=t[2]):i.name=t[1],i.name in e&&(i.name=e[i.name]),i}var i=/ply([\s\S]*)end_header\s/,o="",n=0,s=i.exec(t);null!==s&&(o=s[1],n=s[0].length);for(var r,a,h={comments:[],elements:[],headerLength:n},l=o.split("\n"),c=void 0,u=0;u<l.length;u++){var p=l[u];if(p=p.trim(),""!==p)switch(a=p.split(/\s+/),r=a.shift(),p=a.join(" "),r){case"format":h.format=a[0],h.version=a[1];break;case"comment":h.comments.push(p);break;case"element":void 0!==c&&h.elements.push(c),c=Object(),c.name=a[0],c.count=parseInt(a[1]),c.properties=[];break;case"property":c.properties.push(e(a,this.propertyNameMapping));break;default:console.log("unhandled",r,a)}}return void 0!==c&&h.elements.push(c),h},parseASCIINumber:function(t,e){switch(e){case"char":case"uchar":case"short":case"ushort":case"int":case"uint":case"int8":case"uint8":case"int16":case"uint16":case"int32":case"uint32":return parseInt(t);case"float":case"double":case"float32":case"float64":return parseFloat(t)}},parseASCIIElement:function(t,e){for(var i=e.split(/\s+/),o=Object(),n=0;n<t.length;n++)if("list"===t[n].type){for(var s=[],r=this.parseASCIINumber(i.shift(),t[n].countType),a=0;a<r;a++)s.push(this.parseASCIINumber(i.shift(),t[n].itemType));o[t[n].name]=s}else o[t[n].name]=this.parseASCIINumber(i.shift(),t[n].type);return o},parseASCII:function(t){var e,i=new THREE.Geometry,o=this.parseHeader(t),n=/end_header\s([\s\S]*)$/,s="";null!==(e=n.exec(t))&&(s=e[1]);var r=s.split("\n"),a=0,h=0;i.useColor=!1;for(var l=0;l<r.length;l++){var c=r[l];if(c=c.trim(),""!==c){h>=o.elements[a].count&&(a++,h=0);var u=this.parseASCIIElement(o.elements[a].properties,c);this.handleElement(i,o.elements[a].name,u),h++}}return this.postProcess(i)},postProcess:function(t){if(t.useColor){for(var e=0;e<t.faces.length;e++)t.faces[e].vertexColors=[t.colors[t.faces[e].a],t.colors[t.faces[e].b],t.colors[t.faces[e].c]];t.elementsNeedUpdate=!0}return t.computeBoundingSphere(),t},handleElement:function(t,e,i){if("vertex"===e){if(t.vertices.push(new THREE.Vector3(i.x,i.y,i.z)),"red"in i&&"green"in i&&"blue"in i){t.useColor=!0;var o=new THREE.Color;o.setRGB(i.red/255,i.green/255,i.blue/255),t.colors.push(o)}}else if("face"===e){var n=i.vertex_indices||i.vertex_index;3===n.length?t.faces.push(new THREE.Face3(n[0],n[1],n[2])):4===n.length&&t.faces.push(new THREE.Face3(n[0],n[1],n[3]),new THREE.Face3(n[1],n[2],n[3]))}},binaryRead:function(t,e,i,o){switch(i){case"int8":case"char":return[t.getInt8(e),1];case"uint8":case"uchar":return[t.getUint8(e),1];case"int16":case"short":return[t.getInt16(e,o),2];case"uint16":case"ushort":return[t.getUint16(e,o),2];case"int32":case"int":return[t.getInt32(e,o),4];case"uint32":case"uint":return[t.getUint32(e,o),4];case"float32":case"float":return[t.getFloat32(e,o),4];case"float64":case"double":return[t.getFloat64(e,o),8]}},binaryReadElement:function(t,e,i,o){for(var n,s=Object(),r=0,a=0;a<i.length;a++)if("list"===i[a].type){var h=[];n=this.binaryRead(t,e+r,i[a].countType,o);var l=n[0];r+=n[1];for(var c=0;c<l;c++)n=this.binaryRead(t,e+r,i[a].itemType,o),h.push(n[0]),r+=n[1];s[i[a].name]=h}else n=this.binaryRead(t,e+r,i[a].type,o),s[i[a].name]=n[0],r+=n[1];return[s,r]},parseBinary:function(t){for(var e,i=new THREE.Geometry,o=this.parseHeader(this.bin2str(t)),n="binary_little_endian"===o.format,s=new DataView(t,o.headerLength),r=0,a=0;a<o.elements.length;a++)for(var h=0;h<o.elements[a].count;h++){e=this.binaryReadElement(s,r,o.elements[a].properties,n),r+=e[1];var l=e[0];this.handleElement(i,o.elements[a].name,l)}return this.postProcess(i)}}},{}],7:[function(t,e,i){!function(t){function e(t,e){return String(t).indexOf(e)!==-1}function i(t,e,i){d!==e&&p!==e&&u!==e||Object.keys(i).forEach(function(e){t[e]=i[e]})}function o(t,e){var i={};return Object.keys(t).forEach(function(o){var n=t[o];e in n&&(i[n[e]]=n)}),i}function n(t){var e="keyCode"in t?t.keyCode:"which"in t?t.which:0,i=function(){if(b||"keyLocation"in t){var i=b?t.location:t.keyLocation;if(i&&e in f[i])return f[i][e]}return"keyIdentifier"in t&&t.keyIdentifier in v?v[t.keyIdentifier]:e in y?y[e]:null}();if(!i)return null;var o=function(){var e=m[i.code];return e?t.shiftKey&&"shiftKey"in e?e.shiftKey:e.key:i.code}();return{code:i.code,key:o,location:i.location,keyCap:i.keyCap}}function s(t,e){if(t=String(t),!w.hasOwnProperty(t))return"Undefined";if(e&&"en-us"!==String(e).toLowerCase())throw Error("Unsupported locale");var i=w[t];return i.keyCap||i.code||"Undefined"}var r="KeyboardEvent"in t;r||(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 a=window.KeyboardEvent.DOM_KEY_LOCATION_STANDARD,h=window.KeyboardEvent.DOM_KEY_LOCATION_LEFT,l=window.KeyboardEvent.DOM_KEY_LOCATION_RIGHT,c=window.KeyboardEvent.DOM_KEY_LOCATION_NUMPAD,u=function(){return 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":""}(),p=function(){return 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":""}(),d=p+"-"+u,y={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:h},92:{code:"OSRight",location:l},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:h},161:{code:"ShiftRight",location:l},162:{code:"ControlLeft",location:h},163:{code:"ControlRight",location:l},164:{code:"AltLeft",location:h},165:{code:"AltRight",location:l},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"}};i(y,"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}}),i(y,"moz-mac",{12:{code:"NumLock",location:c},173:{code:"Minus",keyCap:"-"}}),i(y,"moz-win",{173:{code:"Minus",keyCap:"-"}}),i(y,"chrome-mac",{93:{code:"OSRight",location:l}}),i(y,"safari",{3:{code:"Enter"},25:{code:"Tab"}}),i(y,"ios",{10:{code:"Enter",location:a}}),i(y,"safari-mac",{91:{code:"OSLeft",location:h},93:{code:"OSRight",location:l},229:{code:"KeyQ",keyCap:"Q"}});var v={};"cros"===u&&(v["U+00A0"]={code:"ShiftLeft",location:h},v["U+00A1"]={code:"ShiftRight",location:l},v["U+00A2"]={code:"ControlLeft",location:h},v["U+00A3"]={code:"ControlRight",location:l},v["U+00A4"]={code:"AltLeft",location:h},v["U+00A5"]={code:"AltRight",location:l}),"chrome-mac"===d&&(v["U+0010"]={code:"ContextMenu"}),"safari-mac"===d&&(v["U+0010"]={code:"ContextMenu"}),"ios"===u&&(v["U+0010"]={code:"Function"},v["U+001C"]={code:"ArrowLeft"},v["U+001D"]={code:"ArrowRight"},v["U+001E"]={code:"ArrowUp"},v["U+001F"]={code:"ArrowDown"},v["U+0001"]={code:"Home"},v["U+0004"]={code:"End"},v["U+000B"]={code:"PageUp"},v["U+000C"]={code:"PageDown"});var f=[];f[h]={16:{code:"ShiftLeft",location:h},17:{code:"ControlLeft",location:h},18:{code:"AltLeft",location:h}},f[l]={16:{code:"ShiftRight",location:l},17:{code:"ControlRight",location:l},18:{code:"AltRight",location:l}},f[c]={13:{code:"NumpadEnter",location:c}},i(f[c],"moz",{109:{code:"NumpadSubtract",location:c},107:{code:"NumpadAdd",location:c}}),i(f[h],"moz-mac",{224:{code:"OSLeft",location:h}}),i(f[l],"moz-mac",{224:{code:"OSRight",location:l}}),i(f[l],"moz-win",{91:{code:"OSRight",location:l}}),i(f[l],"mac",{93:{code:"OSRight",location:l}}),i(f[c],"chrome-mac",{12:{code:"NumLock",location:c}}),i(f[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 m={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:"|"}};i(m,"mac",{OSLeft:{key:"Meta"},OSRight:{key:"Meta"}});var g={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"},w=o(y,"code");try{var b=r&&"location"in new KeyboardEvent("")}catch(x){}"KeyboardEvent"in t&&"defineProperty"in Object&&!function(){function t(t,e,i){e in t||Object.defineProperty(t,e,i)}if(t(KeyboardEvent.prototype,"code",{get:function(){var t=n(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 g.hasOwnProperty(t)?g[t]:t}})}t(KeyboardEvent.prototype,"key",{get:function(){var t=n(this);return t&&"key"in t?t.key:"Unidentified"}}),t(KeyboardEvent.prototype,"location",{get:function(){var t=n(this);return t&&"location"in t?t.location:a}}),t(KeyboardEvent.prototype,"locale",{get:function(){return""}})}(),"queryKeyCap"in t.KeyboardEvent||(t.KeyboardEvent.queryKeyCap=s),t.identifyKey=function(t){if(!("code"in t)){var e=n(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:a,t.locale=""}}}(window)},{}],8:[function(t,e,i){function o(t){var e=y(t);if(!e.length)return null;t.computeBoundingBox();var i=t.boundingBox;return new f.Box(new f.Vec3((i.max.x-i.min.x)/2,(i.max.y-i.min.y)/2,(i.max.z-i.min.z)/2))}function n(t){var e,i,o,n,s=new THREE.BoundingBoxHelper(t);return s.update(),e=s.box,isFinite(e.min.lengthSq())?(i=new f.Box(new f.Vec3((e.max.x-e.min.x)/2,(e.max.y-e.min.y)/2,(e.max.z-e.min.z)/2)),t.updateMatrixWorld(),n=new THREE.Vector3,n.setFromMatrixPosition(t.matrixWorld),o=s.position.sub(n),o.lengthSq()&&(i.offset=o),i):null}function s(t){var e,i,o,n,s=1e-4,r=d(t);if(!r||!r.vertices.length)return null;for(e=0;e<r.vertices.length;e++)r.vertices[e].x+=(Math.random()-.5)*s,r.vertices[e].y+=(Math.random()-.5)*s,r.vertices[e].z+=(Math.random()-.5)*s;for(n=m(r),i=new Array(n.vertices.length),e=0;e<n.vertices.length;e++)i[e]=new f.Vec3(n.vertices[e].x,n.vertices[e].y,n.vertices[e].z);for(o=new Array(n.faces.length),e=0;e<n.faces.length;e++)o[e]=[n.faces[e].a,n.faces[e].b,n.faces[e].c];return new f.ConvexPolyhedron(i,o)}function r(t){var e,i=t.metadata?t.metadata.parameters:t.parameters;return e=new f.Cylinder(i.radiusTop,i.radiusBottom,i.height,i.radialSegments),e.orientation=new f.Quaternion,e.orientation.setFromEuler(THREE.Math.degToRad(-90),0,0,"XYZ").normalize(),e}function a(t,e){var i,o,n,s=d(t),r=["x","y","z"],a=e.cylinderAxis||"y",h=r.splice(r.indexOf(a),1)&&r;return s.computeBoundingBox(),s.computeBoundingSphere(),o=s.boundingBox.max[a]-s.boundingBox.min[a],n=.5*Math.max(s.boundingBox.max[h[0]]-s.boundingBox.min[h[0]],s.boundingBox.max[h[1]]-s.boundingBox.min[h[1]]),i=new f.Cylinder(n,n,o,12),i.orientation=new f.Quaternion,i.orientation.setFromEuler("y"===a?g:0,"z"===a?g:0,0,"XYZ").normalize(),i}function h(t){t.computeBoundingBox();var e=t.boundingBox;return new f.Box(new f.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))}function l(t){var e=t.metadata?t.metadata.parameters:t.parameters;return new f.Sphere(e.radius)}function c(t,e){var i=d(t);return i.computeBoundingSphere(),new f.Sphere(e.sphereRadius||i.boundingSphere.radius)}function u(t){var e=new THREE.BufferGeometry;return e.fromGeometry(t),p(e)}function p(t){var e,i=y(t);return i.length?(e=Object.keys(i).map(Number),new f.Trimesh(i,e)):null}function d(t){var e,i,o=v(t),n=new THREE.Geometry,s=new THREE.Geometry;if(0===o.length)return null;if(1===o.length){var r=new THREE.Vector3,a=new THREE.Quaternion,h=new THREE.Vector3;return n=o[0].geometry.clone(),n.metadata=o[0].geometry.metadata,o[0].updateMatrixWorld(),o[0].matrixWorld.decompose(r,a,h),n.scale(h.x,h.y,h.z)}for(;i=o.pop();)i.updateMatrixWorld(),i.geometry instanceof THREE.BufferGeometry?(n.fromBufferGeometry(i.geometry),s.merge(n,i.matrixWorld)):s.merge(i.geometry,i.matrixWorld);return e=new THREE.Matrix4,e.scale(t.scale),s.applyMatrix(e),s}function y(t){return t.attributes||(t=(new THREE.BufferGeometry).fromGeometry(t)),t.attributes.position.array}function v(t){var e=[];return t.traverse(function(t){"Mesh"===t.type&&e.push(t)}),e}var f=t("cannon"),m=t("./lib/THREE.quickhull"),g=Math.PI/2,w={BOX:"Box",CYLINDER:"Cylinder",SPHERE:"Sphere",HULL:"ConvexPolyhedron"};e.exports=f.mesh2shape=function(t,e){if(e=e||{},e.type===w.BOX)return n(t);if(e.type===w.CYLINDER)return a(t,e);if(e.type===w.SPHERE)return c(t,e);if(e.type===w.HULL)return s(t);if(e.type)throw new Error('[CANNON.mesh2shape] Invalid type "%s".',e.type);var i=d(t);if(!i)return null;var y=i.metadata?i.metadata.type:i.type;switch(y){case"BoxGeometry":case"BoxBufferGeometry":return o(i);case"CylinderGeometry":case"CylinderBufferGeometry":return r(i);case"PlaneGeometry":case"PlaneBufferGeometry":return h(i);case"SphereGeometry":case"SphereBufferGeometry":return l(i);case"TubeGeometry":return u(i);case"Geometry":case"BufferGeometry":return p(i);default:return console.warn('Unrecognized geometry: "%s". Using bounding box as shape.',i.type),o(i)}},f.mesh2shape.Type=w},{"./lib/THREE.quickhull":9,cannon:45}],9:[function(t,e,i){e.exports=function(){function t(){v=new THREE.Vector3,f=new THREE.Vector3,m=new THREE.Vector3,g=new THREE.Vector3,w=new THREE.Vector3,b=new THREE.Vector3,x=new THREE.Vector3,E=new THREE.Vector3,A=new THREE.Vector3,C=new THREE.Vector3}function e(t){for(;S.length>0;)n(S.shift(),t)}function i(t,e){if(void 0!==t.normal)return t.normal;var i=e[t[0]],o=e[t[1]],n=e[t[2]];return v.subVectors(o,i),f.subVectors(n,i),b.crossVectors(f,v),b.normalize(),t.normal=b.clone()}function o(t,e,o){var n=o[t[0]],s=[],r=i(t,o);e.sort(function(t,e){return s[t.x/3]=void 0!==s[t.x/3]?s[t.x/3]:r.dot(g.subVectors(t,n)),s[e.x/3]=void 0!==s[e.x/3]?s[e.x/3]:r.dot(w.subVectors(e,n)),s[t.x/3]-s[e.x/3]});var a=e.length;for(1===a&&(s[e[0].x/3]=r.dot(g.subVectors(e[0],n)));a-- >0&&s[e[a].x/3]>0;);a+1<e.length&&s[e[a+1].x/3]>0&&(t.visiblePoints=e.splice(a+1))}function n(t,e){for(var n,s,r=B.length,a=[t],h=e.indexOf(t.visiblePoints.pop());r-- >0;)s=B[r],s!==t&&(n=i(s,e).dot(x.subVectors(e[h],e[s[0]])),n>0&&a.push(s));var l,c,u,p,d=r=a.length,y=1===r,v=[],f=0,m=[];[a[0][0],a[0][1],a[0][1],a[0][2],a[0][2],a[0][0]];if(1===a.length)s=a[0],v=[s[0],s[1],s[1],s[2],s[2],s[0]],S.indexOf(s)>-1&&S.splice(S.indexOf(s),1),s.visiblePoints&&(m=m.concat(s.visiblePoints)),B.splice(B.indexOf(s),1);else for(;r-- >0;){s=a[r],S.indexOf(s)>-1&&S.splice(S.indexOf(s),1),s.visiblePoints&&(m=m.concat(s.visiblePoints)),B.splice(B.indexOf(s),1);var g;for(cEdgeIndex=0;cEdgeIndex<3;){for(g=!1,d=a.length,u=s[cEdgeIndex],p=s[(cEdgeIndex+1)%3];d-- >0&&!g;)if(l=a[d],f=0,l!==s)for(;f<3&&!g;)c=f+1,g=l[f]===u&&l[c%3]===p||l[f]===p&&l[c%3]===u,f++;g&&!y||(v.push(u),v.push(p)),cEdgeIndex++}}r=0;for(var w,b=v.length/2;r<b;)w=[v[2*r+1],h,v[2*r]],o(w,m,e),B.push(w),void 0!==w.visiblePoints&&S.push(w),r++}var s,r,a,h,l,c,u,p,d,y,v,f,m,g,w,b,x,E,A,C,B=[],S=[],R=0,M=function(){var t=new THREE.Vector3,e=new THREE.Vector3,i=new THREE.Vector3;return function(o,n,s){return t.subVectors(s,o),e.subVectors(n,o),i.crossVectors(t,e),i.normalize()}}(),T=function(){var t=new THREE.Vector3,e=new THREE.Vector3,i=new THREE.Vector3;return function(o,n,s){t.subVectors(n,o),e.subVectors(s,o),i.subVectors(s,n);var r=e.dot(t);if(r<0)return e.dot(e);var a=t.dot(t);return r>=a?i.dot(i):e.dot(e)-r*r/a}}();return function(i){for(t(),points=i.vertices,B=[],S=[],x=s=points.length,r=points.slice(0,6),R=0;x-- >0;)points[x].x<r[0].x&&(r[0]=points[x]),points[x].x>r[1].x&&(r[1]=points[x]),points[x].y<r[2].y&&(r[2]=points[x]),points[x].y<r[3].y&&(r[3]=points[x]),points[x].z<r[4].z&&(r[4]=points[x]),points[x].z<r[5].z&&(r[5]=points[x]);for(h=x=6;x-- >0;)for(h=x-1;h-- >0;)R<(a=r[x].distanceToSquared(r[h]))&&(R=a,l=r[x],c=r[h]);for(x=6,R=0;x-- >0;)a=T(l,c,r[x]),R<a&&(R=a,u=r[x]);for(d=M(l,c,u),y=d.dot(l),R=0,x=s;x-- >0;)a=Math.abs(points[x].dot(d)-y),R<a&&(R=a,p=points[x]);var n=points.indexOf(l),v=points.indexOf(c),f=points.indexOf(u),m=points.indexOf(p),g=[[f,v,n],[v,m,n],[f,m,v],[n,m,f]];E.subVectors(c,l).normalize(),A.subVectors(u,l).normalize(),C.subVectors(p,l).normalize();var w=C.dot((new THREE.Vector3).crossVectors(A,E));w<0&&(g[0].reverse(),g[1].reverse(),g[2].reverse(),g[3].reverse());var b=points.slice();b.splice(b.indexOf(l),1),b.splice(b.indexOf(c),1),b.splice(b.indexOf(u),1),b.splice(b.indexOf(p),1);for(var x=g.length;x-- >0;)o(g[x],b,points),void 0!==g[x].visiblePoints&&S.push(g[x]),B.push(g[x]);e(points);for(var z=B.length;z-- >0;)i.faces[z]=new THREE.Face3(B[z][2],B[z][1],B[z][0],B[z].normal);return i.normalsNeedUpdate=!0,i}}()},{}],10:[function(t,e,i){var o=.1;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){this.active&&(this.checkpoint=t,"teleport"===this.data.mode&&(this.sync(),this.el.setAttribute("position",this.targetPosition)))},isVelocityActive:function(){return!(!this.active||!this.checkpoint)},getVelocity:function(){if(this.active){var t=this.data,e=this.offset,i=this.position,n=this.targetPosition;return this.sync(),i.distanceTo(n)<o?(this.checkpoint=null,e.set(0,0,0)):(e.setLength(t.animateSpeed),e)}},sync:function(){var t=this.offset,e=this.position,i=this.targetPosition;e.copy(this.el.getComputedAttribute("position")),i.copy(this.checkpoint.getComputedAttribute("position")),i.y=e.y,t.copy(i).sub(e)}}},{}],11:[function(t,e,i){var o=t("../../lib/GamepadButton"),n=t("../../lib/GamepadButtonEvent"),s=.2;e.exports={GamepadButton:o,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),this.getGamepad()||console.warn("Gamepad #%d not found. Connect controller and press any button to continue.",this.data.controller)},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),i=t.x||e.x,o=t.y||e.y;return Math.abs(i)>s||Math.abs(o)>s},getVelocityDelta:function(){var t=this.getDpad(),e=this.getJoystick(0),i=t.x||e.x,o=t.y||e.y,n=new THREE.Vector3;return Math.abs(i)>s&&(n.x+=i),Math.abs(o)>s&&(n.z+=o),n},isRotationActive:function(){if(!this.data.enabled||!this.isConnected())return!1;var t=this.getJoystick(1);return Math.abs(t.x)>s||Math.abs(t.y)>s},getRotationDelta:function(){var t=this.getJoystick(1);return Math.abs(t.x)<=s&&(t.x=0),Math.abs(t.y)<=s&&(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"],i=e&&e.isConnected()&&e.getGamepad(this.data.controller);return i||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[o.DPAD_RIGHT]?new THREE.Vector2((t.buttons[o.DPAD_RIGHT].pressed?1:0)+(t.buttons[o.DPAD_LEFT].pressed?-1:0),(t.buttons[o.DPAD_UP].pressed?-1:0)+(t.buttons[o.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":4,"../../lib/GamepadButtonEvent":5}],12:[function(t,e,i){function o(t){return 0===t.x&&0===t.y&&0===t.z}var n=THREE.Math.radToDeg,s=AFRAME.utils.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"),!o(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,i=this.calculateHMDPosition();return this.isPositionCalibrated=this.isPositionCalibrated||!o(e),!(!this.data.enabled||!this.el.sceneEl.is("vr-mode")||s)&&(t.copy(i).sub(e),e.copy(i),this.isPositionCalibrated&&!o(t))},getPositionDelta:function(){return this.deltaHMDPosition},calculateHMDPosition:function(){var t=this.dolly,e=new THREE.Vector3;return t.updateMatrix(),e.setFromMatrixPosition(t.matrix),e}}},{}],13:[function(t,e,i){var o=t("../math");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,o.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)}}},{"../math":21,"./checkpoint-controls":10,"./gamepad-controls":11,"./hmd-controls":12,"./keyboard-controls":14,"./mouse-controls":15,"./touch-controls":16,"./universal-controls":17}],14:[function(t,e,i){t("../../lib/keyboard.polyfill");var o="__keyboard-controls-proxy",n=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){this.localKeys[t.code]=!0,this.emit(t)},onKeyUp:function(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){o in t&&this.el.emit(t.type,t),this.el.emit(t.type+":"+t.code,new n(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":7}],15:[function(t,e,i){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()},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,i=this.data;return 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),void(i.pointerlockEnabled&&(document.addEventListener("pointerlockchange",this.onPointerLockChange,!1),document.addEventListener("mozpointerlockchange",this.onPointerLockChange,!1),document.addEventListener("pointerlockerror",this.onPointerLockError,!1)))):void 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 i=t.movementX||t.mozMovementX||0,o=t.movementY||t.mozMovementY||0;this.pointerLocked||(i=t.screenX-e.screenX,o=t.screenY-e.screenY),this.lookVector.x+=i,this.lookVector.y+=o,this.previousMouseEvent=t}},onMouseDown:function(t){var e=this.el.sceneEl.canvas;this.mouseDown=!0,this.previousMouseEvent=t,this.data.pointerlockEnabled&&!this.pointerLocked&&(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}}},{}],16:[function(t,e,i){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;return e?(e.addEventListener("touchstart",this.onTouchStart),void e.addEventListener("touchend",this.onTouchEnd)):void 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()}}},{}],17:[function(t,e,i){var o="-controls",n=.2,s=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},movementAcceleration:{"default":80},rotationSensitivity:{"default":.05},fly:{"default":!1}},init:function(){this.velocity=new THREE.Vector3,this.pitch=new THREE.Object3D,this.yaw=new THREE.Object3D,this.yaw.position.y=10,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,i=this.data;for(t=0;t<i.movementControls.length;t++)e=i.movementControls[t]+o,this.el.components[e]||this.el.setAttribute(e,"");for(t=0;t<i.rotationControls.length;t++)e=i.rotationControls[t]+o,this.el.components[e]||this.el.setAttribute(e,"")},tick:function(t,e){e&&(this.data.rotationEnabled&&this.updateRotation(e),this.data.movementEnabled&&e/1e3>n?(this.velocity.set(0,0,0),this.el.setAttribute("velocity",this.velocity)):this.updateVelocity(e))},updateRotation:function(t){for(var e,i,n=this.data,r=0,a=n.rotationControls.length;r<a;r++)if(e=this.el.components[n.rotationControls[r]+o],e&&e.isRotationActive()){if(e.getRotationDelta)i=e.getRotationDelta(t),i.multiplyScalar(n.rotationSensitivity),this.yaw.rotation.y-=i.x,this.pitch.rotation.x-=i.y,this.pitch.rotation.x=Math.max(-s,Math.min(s,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[r]);this.el.setAttribute("rotation",e.getRotation())}break}},updateVelocity:function(t){var e,i,n=this.velocity,s=this.data;if(s.movementEnabled)for(var r=0,a=s.movementControls.length;r<a;r++)if(e=this.el.components[s.movementControls[r]+o],e&&e.isVelocityActive()){if(!e.getVelocityDelta){if(e.getVelocity)return void this.el.setAttribute("velocity",e.getVelocity());if(e.getPositionDelta)return n.copy(e.getPositionDelta(t).multiplyScalar(1e3/t)),void this.el.setAttribute("velocity",n);throw new Error("Incompatible movement controls: ",s.movementControls[r])}i=e.getVelocityDelta(t);break}if(n.copy(this.el.getComputedAttribute("velocity")),n.x-=n.x*s.movementEasing*t/1e3,n.z-=n.z*s.movementEasing*t/1e3,i&&s.movementEnabled){i.length()>1?i.setLength(this.data.movementAcceleration*t/1e3):i.multiplyScalar(this.data.movementAcceleration*t/1e3);var h=this.el.getAttribute("rotation");h&&(this.heading.set(s.fly?THREE.Math.degToRad(h.x):0,THREE.Math.degToRad(h.y),0),i.applyEuler(this.heading)),n.add(i)}this.el.setAttribute("velocity",n)}}},{}],18:[function(t,e,i){e.exports={"ply-model":t("./ply-model"),"three-model":t("./three-model"),registerAll:function(t){this._registered||(t=t||window.AFRAME,t.systems["ply-model"]||t.registerSystem("ply-model",this["ply-model"].System),t.components["ply-model"]||t.registerComponent("ply-model",this["ply-model"].Component),t.components["three-model"]||t.registerComponent("three-model",this["three-model"]),this._registered=!0)}}},{"./ply-model":19,"./three-model":20}],19:[function(t,e,i){function o(t){return new THREE.Mesh(t,new THREE.MeshPhongMaterial({color:16777215,shading:THREE.FlatShading,vertexColors:THREE.VertexColors,shininess:0}))}THREE.PLYLoader=t("../../lib/PLYLoader"),e.exports.System={init:function(){this.cache={}},getOrLoadGeometry:function(t,e){var i=this.cache,o=i[t];return!e&&o?o:(i[t]=new Promise(function(e){var i=new THREE.PLYLoader;i.load(t,function(t){e(t)})}),i[t])}},e.exports.Component={schema:{skipCache:{type:"boolean","default":!1},src:{type:"src"}},init:function(){this.model=null},update:function(){var t=this.data,e=this.el;return t.src?void this.system.getOrLoadGeometry(t.src,t.skipCache).then(function(t){var i=o(t);e.setObject3D("mesh",i),e.emit("model-loaded",{format:"ply",model:i})}):void console.warn("[%s] `src` property is required.",this.name)},remove:function(){this.model&&this.el.removeObject3D("mesh")}}},{"../../lib/PLYLoader":6}],20:[function(t,e,i){var o="__auto__";e.exports={schema:{src:{type:"src"},loader:{"default":"object",oneOf:["object","json"]},enableAnimation:{"default":!0},animation:{"default":o},animationDuration:{"default":0}},init:function(){this.model=null,this.mixer=null},update:function(t){t=t||{};var e,i=this.data;if(!i.src)return void this.remove();if(Object.keys(t).length){var o=this.model&&this.model.activeAction;if(i.animation!==t.animation)return o&&o.stop(),void this.playAnimation();o&&i.enableAnimation!==o.isRunning()&&(i.enableAnimation?this.playAnimation():o.stop()),o&&i.animationDuration&&o.setDuration(i.animationDuration)}else if(this.remove(),"object"===i.loader)e=new THREE.ObjectLoader,e.load(i.src,function(t){t.traverse(function(e){e instanceof THREE.SkinnedMesh&&(t=e)}),t.material&&(t.material.skinning=!!(t.geometry&&t.geometry.bones||[]).length),this.load(t)}.bind(this));else{if("json"!==i.loader)throw new Error('[three-model] Invalid mode "%s".',i.mode);e=new THREE.JSONLoader,e.load(i.src,function(t,e){e.forEach(function(e){e.vertexColors=(t.faces[0]||{}).color?THREE.FaceColors:THREE.NoColors,e.skinning=!!(t.bones||[]).length,e.morphTargets=!!(t.morphTargets||[]).length,e.morphNormals=!!(t.morphNormals||[]).length});var i=(t.bones||[]).length?new THREE.SkinnedMesh(t,new THREE.MultiMaterial(e)):new THREE.Mesh(t,new THREE.MultiMaterial(e));this.load(i)}.bind(this))}},load:function(t){this.model=t,this.mixer=new THREE.AnimationMixer(this.model),this.el.setObject3D("mesh",t),this.el.emit("model-loaded",{format:"three",model:t}),this.data.enableAnimation&&this.playAnimation()},playAnimation:function(){var t,e=this.data,i=this.model.animations||this.model.geometry.animations||[];if(e.enableAnimation&&e.animation&&i.length){if(t=e.animation===o?i[0]:THREE.AnimationClip.findByName(i,e.animation),!t)return void console.error('[three-model] Animation "%s" not found.',e.animation);this.model.activeAction=this.mixer.clipAction(t,this.model),e.animationDuration&&this.model.activeAction.setDuration(e.animationDuration),this.model.activeAction.play()}},remove:function(){this.mixer&&this.mixer.stopAllAction(),this.model&&this.el.removeObject3D("mesh")},tick:function(t,e){this.mixer&&!isNaN(e)&&this.mixer.update(e/1e3)}}},{}],21:[function(t,e,i){e.exports={velocity:t("./velocity"),quaternion:t("./quaternion"),registerAll:function(t){this._registered||(t=t||window.AFRAME,t.components.velocity||t.registerComponent("velocity",this.velocity),t.components.quaternion||t.registerComponent("quaternion",this.quaternion),this._registered=!0)}}},{"./quaternion":22,"./velocity":23}],22:[function(t,e,i){e.exports={schema:{type:"vec4"},play:function(){var t=this.el,e=t.object3D.quaternion;t.hasAttribute("rotation")&&(t.components.rotation.update(),t.setAttribute("quaternion",{x:e.x,y:e.y,z:e.z,w:e.w}),t.removeAttribute("rotation"),this.update())},update:function(){var t=this.data;this.el.object3D.quaternion.set(t.x,t.y,t.z,t.w)}}},{}],23:[function(t,e,i){e.exports={schema:{type:"vec3"},init:function(){this.system=this.el.sceneEl.systems.physics,this.system&&this.system.addBehavior(this,this.system.Phase.RENDER)},remove:function(){this.system&&this.system.removeBehavior(this,this.system.Phase.RENDER)},tick:function(t,e){e&&(this.system||this.step(t,e))},step:function(t,e){if(e){var i=this.el.sceneEl.systems.physics||{data:{maxInterval:1/60}},o=this.el.getAttribute("velocity")||{x:0,y:0,z:0},n=this.el.getAttribute("position")||{x:0,y:0,z:0};e=Math.min(e,1e3*i.data.maxInterval),this.el.setAttribute("position",{x:n.x+o.x*e/1e3,y:n.y+o.y*e/1e3,z:n.z+o.z*e/1e3})}}}},{}],24:[function(t,e,i){e.exports={schema:{defaultRotation:{type:"vec3"},enableDefaultRotation:{"default":!1}},init:function(){this.active=!1,this.targetEl=null,this.fire=this.fire.bind(this)},play:function(){this.el.addEventListener("click",this.fire)},pause:function(){this.el.addEventListener("click",this.fire)},remove:function(){this.pause()},fire:function(){var t=this.el.sceneEl.querySelector("[checkpoint-controls]");if(!t)throw new Error("No `checkpoint-controls` component found.");t.components["checkpoint-controls"].setCheckpoint(this.el)}}},{}],25:[function(t,e,i){e.exports={init:function(){this.GRABBED_STATE="grabbed",this.grabbing=!1,this.hitEl=null,this.physics=this.el.sceneEl.systems.physics,this.constraint=null,this.onHit=this.onHit.bind(this),this.onGripOpen=this.onGripOpen.bind(this),this.onGripClose=this.onGripClose.bind(this)},play:function(){var t=this.el;t.addEventListener("hit",this.onHit),t.addEventListener("gripdown",this.onGripClose),t.addEventListener("gripup",this.onGripOpen),t.addEventListener("trackpaddown",this.onGripClose),t.addEventListener("trackpadup",this.onGripOpen),t.addEventListener("triggerdown",this.onGripClose),t.addEventListener("triggerup",this.onGripOpen)},pause:function(){var t=this.el;t.removeEventListener("hit",this.onHit),t.removeEventListener("gripdown",this.onGripClose),t.removeEventListener("gripup",this.onGripOpen),t.removeEventListener("trackpaddown",this.onGripClose),t.removeEventListener("trackpadup",this.onGripOpen),t.removeEventListener("triggerdown",this.onGripClose),t.removeEventListener("triggerup",this.onGripOpen)},onGripClose:function(t){this.grabbing=!0},onGripOpen:function(t){var e=this.hitEl;this.grabbing=!1,e&&(e.removeState(this.GRABBED_STATE),this.hitEl=void 0,this.physics.world.removeConstraint(this.constraint),this.constraint=null)},onHit:function(t){var e=t.detail.el;e&&!e.is(this.GRABBED_STATE)&&this.grabbing&&!this.hitEl&&(e.addState(this.GRABBED_STATE),this.hitEl=e,this.constraint=new CANNON.LockConstraint(this.el.body,e.body),this.physics.world.addConstraint(this.constraint))}}},{}],26:[function(t,e,i){var o=t("../math"),n=t("../physics");e.exports={checkpoint:t("./checkpoint"),grab:t("./grab"),"jump-ability":t("./jump-ability"),"sphere-collider":t("./sphere-collider"),"toggle-velocity":t("./toggle-velocity"),registerAll:function(t){this._registered||(t=t||window.AFRAME,o.registerAll(),n.registerAll(),t.components.checkpoint||t.registerComponent("checkpoint",this.checkpoint),t.components.grab||t.registerComponent("grab",this.grab),t.components["jump-ability"]||t.registerComponent("jump-ability",this["jump-ability"]),t.components["sphere-collider"]||t.registerComponent("sphere-collider",this["sphere-collider"]),t.components["toggle-velocity"]||t.registerComponent("toggle-velocity",this["toggle-velocity"]),this._registered=!0)}}},{"../math":21,"../physics":33,"./checkpoint":24,"./grab":25,"./jump-ability":27,"./sphere-collider":28,"./toggle-velocity":29}],27:[function(t,e,i){var o=-9.8,n=-15;e.exports={dependencies:["velocity"],schema:{on:{"default":"keydown:Space gamepadbuttondown:0"},playerHeight:{"default":1.764},maxJumps:{"default":1},distance:{"default":5},soundJump:{"default":""},soundLand:{"default":""},debug:{"default":!1}},init:function(){this.velocity=0,this.numJumps=0;var t=this.beginJump.bind(this),e=this.data.on.split(" ");this.bindings={};for(var i=0;i<e.length;i++)this.bindings[e[i]]=t,this.el.addEventListener(e[i],t);this.bindings.collide=this.onCollide.bind(this),this.el.addEventListener("collide",this.bindings.collide)},remove:function(){for(var t in this.bindings)this.bindings.hasOwnProperty(t)&&(this.el.removeEventListener(t,this.bindings[t]),delete this.bindings[t]);this.el.removeEventListener("collide",this.bindings.collide),delete this.bindings.collide},beginJump:function(){if(this.numJumps<this.data.maxJumps){var t=this.data,e=Math.sqrt(-2*t.distance*(o+n)),i=this.el.getAttribute("velocity");this.el.setAttribute("velocity",{x:i.x,y:e,z:i.z}),this.numJumps++}},onCollide:function(){this.numJumps=0}}},{}],28:[function(t,e,i){e.exports={schema:{objects:{"default":""},state:{"default":"collided"},radius:{"default":.05}},init:function(){this.els=[],this.collisions=[]},update:function(){var t,e=this.data;t=e.objects?this.el.sceneEl.querySelectorAll(e.objects):this.el.sceneEl.children,this.els=Array.prototype.slice.call(t)},tick:function(){var t=new THREE.Vector3,e=new THREE.Vector3;return function(){function i(i){var o,n=i.getObject3D("mesh");n&&(n.getWorldPosition(e),n.geometry.computeBoundingSphere(),o=n.geometry.boundingSphere.radius,t.distanceTo(e)<o+s.radius&&a.push(i))}function o(t){t.emit("hit"),t.addState(s.state),n.emit("hit",{el:t})}var n=this.el,s=this.data,r=n.getObject3D("mesh"),a=[];r&&(t.copy(n.getComputedAttribute("position")),this.els.forEach(i),a.forEach(o),0===a.length&&n.emit("hit",{el:null}),this.collisions.filter(function(t){return a.indexOf(t)===-1}).forEach(function(t){t.removeState(s.state)}),this.collisions=a)}}()}},{}],29:[function(t,e,i){e.exports={dependencies:["velocity"],schema:{axis:{"default":"x",oneOf:["x","y","z"]},min:{"default":0},max:{"default":0},speed:{"default":1}},init:function(){var t={x:0,y:0,z:0};t[this.data.axis]=this.data.speed,this.el.setAttribute("velocity",t),this.el.sceneEl.addBehavior&&this.el.sceneEl.addBehavior(this)},remove:function(){},update:function(){this.tick()},tick:function(){var t=this.data,e=this.el.getAttribute("velocity"),i=this.el.getAttribute("position");e[t.axis]>0&&i[t.axis]>t.max?(e[t.axis]=-t.speed,this.el.setAttribute("velocity",e)):e[t.axis]<0&&i[t.axis]<t.min&&(e[t.axis]=t.speed,this.el.setAttribute("velocity",e))}}},{}],30:[function(t,e,i){var o=t("cannon"),n=t("three-to-cannon");t("../../lib/CANNON-shape2mesh"),e.exports={schema:{shape:{"default":"auto",oneOf:["auto","box","cylinder","sphere","hull"]},cylinderAxis:{"default":"y",oneOf:["x","y","z"]},sphereRadius:{"default":NaN}},init:function(){this.system=this.el.sceneEl.systems.physics,this.el.sceneEl.hasLoaded?this.initBody():this.el.sceneEl.addEventListener("loaded",this.initBody.bind(this))},initBody:function(){var t,e=this.el,i=this.data,s=e.getComputedAttribute("position"),r="auto"===i.shape?void 0:AFRAME.utils.extend({},this.data,{type:n.Type[i.shape.toUpperCase()]});if(this.el.object3D.updateMatrixWorld(!0),t=n(this.el.object3D,r),!t)return void this.el.addEventListener("model-loaded",this.initBody.bind(this));this.body=new o.Body({mass:i.mass||0,material:this.system.material,position:new o.Vec3(s.x,s.y,s.z),linearDamping:i.linearDamping,angularDamping:i.angularDamping}),this.body.addShape(t,t.offset,t.orientation);var a=e.getComputedAttribute("rotation");this.body.quaternion.setFromEuler(THREE.Math.degToRad(a.x),THREE.Math.degToRad(a.y),THREE.Math.degToRad(a.z),"XYZ").normalize(),this.system.debug&&this.createWireframe(this.body,t),this.el.body=this.body,this.body.el=this.el,this.isLoaded=!0,this.isPlaying&&this._play(),this.el.emit("body-loaded",{body:this.el.body})},play:function(){this.isLoaded&&this._play()},_play:function(){this.system.addBehavior(this,this.system.Phase.SIMULATE),this.system.addBody(this.body),this.wireframe&&this.el.sceneEl.object3D.add(this.wireframe),this.syncToPhysics()},pause:function(){this.isLoaded&&(this.system.removeBehavior(this,this.system.Phase.SIMULATE),this.system.removeBody(this.body),this.wireframe&&this.el.sceneEl.object3D.remove(this.wireframe))},remove:function(){this.pause(),delete this.body.el,delete this.body,delete this.el.body,delete this.wireframe},createWireframe:function(t,e){var i=e.offset,n=e.orientation,s=o.shape2mesh(t).children[0];this.wireframe=new THREE.EdgesHelper(s,16711680),i&&(this.wireframe.offset=i.clone()),n&&(n.inverse(n),this.wireframe.orientation=new THREE.Quaternion(n.x,n.y,n.z,n.w)),this.syncWireframe()},syncWireframe:function(){var t,e=this.wireframe;this.wireframe&&(e.quaternion.copy(this.body.quaternion),e.orientation&&e.quaternion.multiply(e.orientation),e.position.copy(this.body.position),e.offset&&(t=e.offset.clone().applyQuaternion(e.quaternion),e.position.add(t)),e.updateMatrix())},syncToPhysics:function(){var t=new THREE.Quaternion,e=new THREE.Vector3;return function(){var i=this.el,o=i.parentEl,n=this.body;n&&(i.components.velocity&&n.velocity.copy(i.getComputedAttribute("velocity")),o.isScene?(n.quaternion.copy(i.object3D.quaternion),n.position.copy(i.object3D.position)):(i.object3D.getWorldQuaternion(t),n.quaternion.copy(t),i.object3D.getWorldPosition(e),n.position.copy(e)),this.wireframe&&this.syncWireframe())}}(),syncFromPhysics:function(){var t=new THREE.Vector3,e=new THREE.Quaternion,i=new THREE.Quaternion;return function(){var o=this.el,n=o.parentEl,s=this.body;s&&(n.isScene?(o.setAttribute("quaternion",s.quaternion),o.setAttribute("position",s.position)):(e.copy(s.quaternion),n.object3D.getWorldQuaternion(i),e.multiply(i.inverse()),o.setAttribute("quaternion",{x:e.x,y:e.y,z:e.z,w:e.w}),t.copy(s.position),n.object3D.worldToLocal(t),o.setAttribute("position",{x:t.x,y:t.y,z:t.z})),this.wireframe&&this.syncWireframe())}}()}},{"../../lib/CANNON-shape2mesh":3,cannon:45,"three-to-cannon":8}],31:[function(t,e,i){e.exports={GRAVITY:-9.8,MAX_INTERVAL:4/60,ITERATIONS:10,CONTACT_MATERIAL:{friction:.01,restitution:.3,contactEquationStiffness:1e8,contactEquationRelaxation:3,frictionEquationStiffness:1e8,frictionEquationRegularization:3}}},{}],32:[function(t,e,i){var o=t("./body");e.exports=AFRAME.utils.extend({},o,{dependencies:["quaternion","velocity"],schema:AFRAME.utils.extend({},o.schema,{mass:{"default":5},linearDamping:{"default":.01},angularDamping:{"default":.01}}),step:function(){this.syncFromPhysics()}})},{"./body":30}],33:[function(t,e,i){var o=t("cannon"),n=t("../math");e.exports={"dynamic-body":t("./dynamic-body"),"kinematic-body":t("./kinematic-body"),"static-body":t("./static-body"),system:t("./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["kinematic-body"]||t.registerComponent("kinematic-body",this["kinematic-body"]),t.components["static-body"]||t.registerComponent("static-body",this["static-body"]),this._registered=!0)}},window.CANNON=window.CANNON||o},{"../math":21,"./dynamic-body":32,"./kinematic-body":34,"./static-body":35,"./system/physics":36,cannon:45}],34:[function(t,e,i){var o=t("cannon"),n=1e-6;e.exports={dependencies:["velocity"],schema:{mass:{"default":5},radius:{"default":1.3},height:{"default":1.764},linearDamping:{"default":.05},enableSlopes:{"default":!0}},init:function(){this.system=this.el.sceneEl.systems.physics,this.system.addBehavior(this,this.system.Phase.SIMULATE);var t=this.el,e=this.data,i=(new o.Vec3).copy(t.getAttribute("position"));this.body=new o.Body({material:this.system.material,position:i,mass:e.mass,linearDamping:e.linearDamping,fixedRotation:!0}),this.body.addShape(new o.Sphere(e.radius),new o.Vec3(0,e.radius-e.height,0)),this.body.el=this.el,this.system.addBody(this.body)},remove:function(){this.system.removeBody(this.body),this.system.removeBehavior(this,this.system.Phase.SIMULATE)},step:function(){var t=new THREE.Vector3,e=new THREE.Vector3,i=new THREE.Vector3,o=new THREE.Vector3;return function(s,r){if(r){var a,h,l=this.body,c=this.data,u=!1,p=-(1/0);r=Math.min(r,1e3*this.system.data.maxInterval),o.set(0,0,0),t.copy(this.el.getAttribute("velocity")),l.velocity.copy(t),l.position.copy(this.el.getAttribute("position"));for(var d,y=0;d=this.system.world.contacts[y];y++){if(l.id===d.bi.id)d.ni.negate(i);else{if(l.id!==d.bj.id)continue;i.copy(d.ni)}u=l.velocity.dot(i)<-n,u&&i.y<=.5?t=t.projectOnPlane(i):i.y>.5&&(a=l.id===d.bi.id?Math.abs(d.rj.y+d.bj.position.y):Math.abs(d.ri.y+d.bi.position.y),a>p&&(p=a,o.copy(i),h=l.id===d.bi.id?d.bj:d.bi))}if(e.copy(t).normalize(),h&&e.y<.5?(c.enableSlopes?o.y<1-n&&(o=this.raycastToGround(h,o)):o.set(0,1,0),t=t.projectOnPlane(o)):t.add(this.system.world.gravity.scale(4*r/1e3)),h&&h.el&&h.el.components.velocity){var v=h.el.getComputedAttribute("velocity");l.position.copy({x:l.position.x+v.x*r/1e3,y:l.position.y+v.y*r/1e3,z:l.position.z+v.z*r/1e3}),this.el.setAttribute("position",l.position)}l.velocity.copy(t),this.el.setAttribute("velocity",t)}}}(),raycastToGround:function(t,e){var i,n,s=this.body.position,r=this.body.position.clone();return r.y-=this.data.height,i=new o.Ray(s,r),i._updateDirection(),i.intersectBody(t),i.hasHit?(n=i.result.hitNormalWorld,Math.abs(n.y)>Math.abs(e.y)?n:e):e}}},{cannon:45}],35:[function(t,e,i){var o=t("./body");e.exports=AFRAME.utils.extend({},o,{step:function(){this.syncToPhysics()}})},{"./body":30}],36:[function(t,e,i){var o=t("cannon"),n=t("../constants"),s=n.GRAVITY,r=n.CONTACT_MATERIAL;e.exports={schema:{gravity:{"default":s},iterations:{"default":n.ITERATIONS},friction:{"default":r.friction},restitution:{"default":r.restitution},contactEquationStiffness:{"default":r.contactEquationStiffness},contactEquationRelaxation:{"default":r.contactEquationRelaxation},frictionEquationStiffness:{"default":r.frictionEquationStiffness},frictionEquationRegularization:{"default":r.frictionEquationRegularization},maxInterval:{"default":4/60},debug:{"default":!1}},Phase:{SIMULATE:"sim",RENDER:"render"},init:function(){var t=this.data;this.debug=t.debug,this.children={},this.children[this.Phase.SIMULATE]=[],this.children[this.Phase.RENDER]=[],this.listeners={},this.world=new o.World,this.world.quatNormalizeSkip=0,this.world.quatNormalizeFast=!1,this.world.solver.iterations=t.iterations,this.world.gravity.set(0,t.gravity,0),this.world.broadphase=new o.NaiveBroadphase,this.material=new o.Material({name:"defaultMaterial"}),this.contactMaterial=new o.ContactMaterial(this.material,this.material,{friction:t.friction,restitution:t.restitution,contactEquationStiffness:t.contactEquationStiffness,contactEquationRelaxation:t.contactEquationRelaxation,frictionEquationStiffness:t.frictionEquationStiffness,frictionEquationRegularization:t.frictionEquationRegularization}),this.world.addContactMaterial(this.contactMaterial)},tick:function(t,e){if(e){this.world.step(Math.min(e/1e3,this.data.maxInterval));var i;for(i=0;i<this.children[this.Phase.SIMULATE].length;i++)this.children[this.Phase.SIMULATE][i].step(t,e);for(i=0;i<this.children[this.Phase.RENDER].length;i++)this.children[this.Phase.RENDER][i].step(t,e)}},addBody:function(t){this.listeners[t.id]=function(e){t.el.emit("collide",e)},t.addEventListener("collide",this.listeners[t.id]),this.world.addBody(t)},removeBody:function(t){t.removeEventListener("collide",this.listeners[t.id]),delete this.listeners[t.id],this.world.removeBody(t)},addBehavior:function(t,e){this.children[e].push(t)},removeBehavior:function(t,e){this.children[e].splice(this.children[e].indexOf(t),1)},update:function(t){var e=this.data;e.debug!==t.debug&&console.warn("[physics] `debug` cannot be changed dynamically."),e.maxInterval!==t.maxInterval,e.gravity!==t.gravity&&this.world.gravity.set(0,e.gravity,0),this.contactMaterial.friction=e.friction,this.contactMaterial.restitution=e.restitution,this.contactMaterial.contactEquationStiffness=e.contactEquationStiffness,this.contactMaterial.contactEquationRelaxation=e.contactEquationRelaxation,this.contactMaterial.frictionEquationStiffness=e.frictionEquationStiffness,this.contactMaterial.frictionEquationRegularization=e.frictionEquationRegularization}}},{"../constants":31,cannon:45}],37:[function(t,e,i){e.exports={defaultComponents:{geometry:{primitive:"plane",width:75,height:75},rotation:{x:-90,y:0,z:0},material:{src:"url(https://cdn.rawgit.com/donmccurdy/aframe-extras/v1.16.3/assets/grid.png)",repeat:"75 75"}},mappings:{width:"geometry.width",height:"geometry.height",src:"material.src"
}}},{}],38:[function(t,e,i){e.exports.Primitive={defaultComponents:{ocean:{},rotation:{x:-90,y:0,z:0}},mappings:{width:"ocean.width",depth:"ocean.depth",density:"ocean.density",color:"ocean.color",opacity:"ocean.opacity"}},e.exports.Component={schema:{width:{"default":10,min:0},depth:{"default":10,min:0},density:{"default":10},amplitude:{"default":.1},amplitudeVariance:{"default":.3},speed:{"default":1},speedVariance:{"default":2},color:{"default":8049399},opacity:{"default":.8}},play:function(){var t=this.el,e=this.data,i=t.components.material,o=new THREE.PlaneGeometry(e.width,e.depth,e.density,e.density);o.mergeVertices(),this.waves=[];for(var n,s=0,r=o.vertices.length;s<r;s++)n=o.vertices[s],this.waves.push({z:n.z,ang:Math.random()*Math.PI*2,amp:e.amplitude+Math.random()*e.amplitudeVariance,speed:(e.speed+Math.random()*e.speedVariance)/1e3});i||(i={},i.material=new THREE.MeshPhongMaterial({color:e.color,transparent:e.opacity<1,opacity:e.opacity,shading:THREE.FlatShading})),this.mesh=new THREE.Mesh(o,i.material),t.object3D.add(this.mesh)},remove:function(){this.el.object3D.remove(this.mesh)},tick:function(t,e){if(e){for(var i,o,n=this.mesh.geometry.vertices,s=0;i=n[s];s++)o=this.waves[s],i.z=o.z+Math.sin(o.ang)*o.amp,o.ang+=o.speed*e;this.mesh.geometry.verticesNeedUpdate=!0}}}},{}],39:[function(t,e,i){e.exports.Primitive={defaultComponents:{tube:{}},mappings:{path:"tube.path",segments:"tube.segments",radius:"tube.radius",radialSegments:"tube.radialSegments",closed:"tube.closed"}},e.exports.Component={schema:{path:{"default":[]},segments:{"default":64},radius:{"default":1},radialSegments:{"default":8},closed:{"default":!1}},init:function(){var t=this.el,e=this.data,i=t.components.material;if(!e.path.length)return void console.error("[a-tube] `path` property expected but not found.");var o=new THREE.CatmullRomCurve3(e.path.map(function(t){return t=t.split(" "),new THREE.Vector3(Number(t[0]),Number(t[1]),Number(t[2]))})),n=new THREE.TubeGeometry(o,e.segments,e.radius,e.radialSegments,e.closed);i||(i={},i.material=new THREE.MeshPhongMaterial),this.mesh=new THREE.Mesh(n,i.material),this.el.setObject3D("mesh",this.mesh)},remove:function(){this.mesh&&this.el.removeObject3D("mesh")}}},{}],40:[function(t,e,i){e.exports={"a-grid":t("./a-grid"),"a-ocean":t("./a-ocean"),"a-tube":t("./a-tube"),registerAll:function(t){this._registered||(t=t||window.AFRAME,t.registerPrimitive("a-grid",this["a-grid"]),t.registerComponent("ocean",this["a-ocean"].Component),t.registerPrimitive("a-ocean",this["a-ocean"].Primitive),t.registerComponent("tube",this["a-tube"].Component),t.registerPrimitive("a-tube",this["a-tube"].Primitive),this._registered=!0)}}},{"./a-grid":37,"./a-ocean":38,"./a-tube":39}],41:[function(t,e,i){e.exports={shadow:t("./shadow"),"shadow-light":t("./shadow-light"),registerAll:function(t){this._registered||(t=t||window.AFRAME,t.components.shadow||t.registerComponent("shadow",this.shadow),t.components["shadow-light"]||t.registerComponent("shadow-light",this["shadow-light"]),this._registered=!0)}}},{"./shadow":43,"./shadow-light":42}],42:[function(t,e,i){e.exports={schema:{angle:{"default":Math.PI/3},castShadow:{"default":!1},color:{"default":"#FFF"},groundColor:{"default":"#FFF"},decay:{"default":1},distance:{"default":0},exponent:{"default":10},intensity:{"default":1},shadowBias:{"default":0},shadowCameraFar:{"default":5e3},shadowCameraFov:{"default":50},shadowCameraNear:{"default":.5},shadowDarkness:{"default":.5},shadowMapHeight:{"default":512},shadowMapWidth:{"default":512},type:{"default":"directional"}},init:function(){var t=this.el;this.light=this.getLight(),t.object3D.add(this.light),t.sceneEl.systems.light.registerLight(t),t.sceneEl.hasLoaded||t.sceneEl.addEventListener("loaded",this.play.bind(this))},update:function(t){t=t||{},Object.keys(t).length&&(this.el.object3D.remove(this.light),this.light=this.getLight(),this.el.object3D.add(this.light))},play:function(){var t=this.el,e=t.sceneEl.renderer;e&&!e.shadowMap.enabled&&(e.shadowMap.enabled=!0)},getLight:function(){var t=this.data,e=new THREE.Color(t.color).getHex(),i=t.intensity,o=t.type;switch(o&&(o=o.toLowerCase()),o){case"ambient":return new THREE.AmbientLight(e);case"directional":return this.setShadow(new THREE.DirectionalLight(e,i));case"hemisphere":return new THREE.HemisphereLight(e,t.groundColor,i);case"point":return this.setShadow(new THREE.PointLight(e,i,t.distance,t.decay));case"spot":return this.setShadow(new THREE.SpotLight(e,i,t.distance,t.angle,t.exponent,t.decay));default:return new THREE.AmbientLight(e)}},setShadow:function(t){var e=this.data;return e.castShadow?(t.castShadow=e.castShadow,t.shadow.camera.near=e.shadowCameraNear,t.shadow.camera.far=e.shadowCameraFar,t.shadow.camera.fov=e.shadowCameraFov,t.shadow.darkness=e.shadowDarkness,t.shadow.mapSize.height=e.shadowMapHeight,t.shadow.mapSize.width=e.shadowMapWidth,t):t}}},{}],43:[function(t,e,i){e.exports={schema:{cast:{"default":!1},receive:{"default":!1}},init:function(){this.el.addEventListener("model-loaded",this.update.bind(this))},update:function(){var t=this.data;this.el.object3D.traverse(function(e){e instanceof THREE.Mesh&&(e.castShadow=t.cast,e.receiveShadow=t.receive)})},remove:function(){}}},{}],44:[function(t,e,i){e.exports={name:"cannon",version:"0.6.2",description:"A lightweight 3D physics engine written in JavaScript.",homepage:"https://github.com/schteppe/cannon.js",author:"Stefan Hedman <[email protected]> (http:https://steffe.se)",keywords:["cannon.js","cannon","physics","engine","3d"],main:"./src/Cannon.js",engines:{node:"*"},repository:{type:"git",url:"https://github.com/schteppe/cannon.js.git"},bugs:{url:"https://github.com/schteppe/cannon.js/issues"},licenses:[{type:"MIT"}],devDependencies:{jshint:"latest","uglify-js":"latest",nodeunit:"^0.9.0",grunt:"~0.4.0","grunt-contrib-jshint":"~0.1.1","grunt-contrib-nodeunit":"^0.4.1","grunt-contrib-concat":"~0.1.3","grunt-contrib-uglify":"^0.5.1","grunt-browserify":"^2.1.4","grunt-contrib-yuidoc":"^0.5.2",browserify:"*"},dependencies:{}}},{}],45:[function(t,e,i){e.exports={version:t("../package.json").version,AABB:t("./collision/AABB"),ArrayCollisionMatrix:t("./collision/ArrayCollisionMatrix"),Body:t("./objects/Body"),Box:t("./shapes/Box"),Broadphase:t("./collision/Broadphase"),Constraint:t("./constraints/Constraint"),ContactEquation:t("./equations/ContactEquation"),Narrowphase:t("./world/Narrowphase"),ConeTwistConstraint:t("./constraints/ConeTwistConstraint"),ContactMaterial:t("./material/ContactMaterial"),ConvexPolyhedron:t("./shapes/ConvexPolyhedron"),Cylinder:t("./shapes/Cylinder"),DistanceConstraint:t("./constraints/DistanceConstraint"),Equation:t("./equations/Equation"),EventTarget:t("./utils/EventTarget"),FrictionEquation:t("./equations/FrictionEquation"),GSSolver:t("./solver/GSSolver"),GridBroadphase:t("./collision/GridBroadphase"),Heightfield:t("./shapes/Heightfield"),HingeConstraint:t("./constraints/HingeConstraint"),LockConstraint:t("./constraints/LockConstraint"),Mat3:t("./math/Mat3"),Material:t("./material/Material"),NaiveBroadphase:t("./collision/NaiveBroadphase"),ObjectCollisionMatrix:t("./collision/ObjectCollisionMatrix"),Pool:t("./utils/Pool"),Particle:t("./shapes/Particle"),Plane:t("./shapes/Plane"),PointToPointConstraint:t("./constraints/PointToPointConstraint"),Quaternion:t("./math/Quaternion"),Ray:t("./collision/Ray"),RaycastVehicle:t("./objects/RaycastVehicle"),RaycastResult:t("./collision/RaycastResult"),RigidVehicle:t("./objects/RigidVehicle"),RotationalEquation:t("./equations/RotationalEquation"),RotationalMotorEquation:t("./equations/RotationalMotorEquation"),SAPBroadphase:t("./collision/SAPBroadphase"),SPHSystem:t("./objects/SPHSystem"),Shape:t("./shapes/Shape"),Solver:t("./solver/Solver"),Sphere:t("./shapes/Sphere"),SplitSolver:t("./solver/SplitSolver"),Spring:t("./objects/Spring"),Transform:t("./math/Transform"),Trimesh:t("./shapes/Trimesh"),Vec3:t("./math/Vec3"),Vec3Pool:t("./utils/Vec3Pool"),World:t("./world/World")}},{"../package.json":44,"./collision/AABB":46,"./collision/ArrayCollisionMatrix":47,"./collision/Broadphase":48,"./collision/GridBroadphase":49,"./collision/NaiveBroadphase":50,"./collision/ObjectCollisionMatrix":51,"./collision/Ray":53,"./collision/RaycastResult":54,"./collision/SAPBroadphase":55,"./constraints/ConeTwistConstraint":56,"./constraints/Constraint":57,"./constraints/DistanceConstraint":58,"./constraints/HingeConstraint":59,"./constraints/LockConstraint":60,"./constraints/PointToPointConstraint":61,"./equations/ContactEquation":63,"./equations/Equation":64,"./equations/FrictionEquation":65,"./equations/RotationalEquation":66,"./equations/RotationalMotorEquation":67,"./material/ContactMaterial":68,"./material/Material":69,"./math/Mat3":71,"./math/Quaternion":72,"./math/Transform":73,"./math/Vec3":74,"./objects/Body":75,"./objects/RaycastVehicle":76,"./objects/RigidVehicle":77,"./objects/SPHSystem":78,"./objects/Spring":79,"./shapes/Box":81,"./shapes/ConvexPolyhedron":82,"./shapes/Cylinder":83,"./shapes/Heightfield":84,"./shapes/Particle":85,"./shapes/Plane":86,"./shapes/Shape":87,"./shapes/Sphere":88,"./shapes/Trimesh":89,"./solver/GSSolver":90,"./solver/Solver":91,"./solver/SplitSolver":92,"./utils/EventTarget":93,"./utils/Pool":95,"./utils/Vec3Pool":98,"./world/Narrowphase":99,"./world/World":100}],46:[function(t,e,i){function o(t){t=t||{},this.lowerBound=new n,t.lowerBound&&this.lowerBound.copy(t.lowerBound),this.upperBound=new n,t.upperBound&&this.upperBound.copy(t.upperBound)}var n=t("../math/Vec3");t("../utils/Utils");e.exports=o;var s=new n;o.prototype.setFromPoints=function(t,e,i,o){var n=this.lowerBound,r=this.upperBound,a=i;n.copy(t[0]),a&&a.vmult(n,n),r.copy(n);for(var h=1;h<t.length;h++){var l=t[h];a&&(a.vmult(l,s),l=s),l.x>r.x&&(r.x=l.x),l.x<n.x&&(n.x=l.x),l.y>r.y&&(r.y=l.y),l.y<n.y&&(n.y=l.y),l.z>r.z&&(r.z=l.z),l.z<n.z&&(n.z=l.z)}return e&&(e.vadd(n,n),e.vadd(r,r)),o&&(n.x-=o,n.y-=o,n.z-=o,r.x+=o,r.y+=o,r.z+=o),this},o.prototype.copy=function(t){return this.lowerBound.copy(t.lowerBound),this.upperBound.copy(t.upperBound),this},o.prototype.clone=function(){return(new o).copy(this)},o.prototype.extend=function(t){this.lowerBound.x=Math.min(this.lowerBound.x,t.lowerBound.x),this.upperBound.x=Math.max(this.upperBound.x,t.upperBound.x),this.lowerBound.y=Math.min(this.lowerBound.y,t.lowerBound.y),this.upperBound.y=Math.max(this.upperBound.y,t.upperBound.y),this.lowerBound.z=Math.min(this.lowerBound.z,t.lowerBound.z),this.upperBound.z=Math.max(this.upperBound.z,t.upperBound.z)},o.prototype.overlaps=function(t){var e=this.lowerBound,i=this.upperBound,o=t.lowerBound,n=t.upperBound,s=o.x<=i.x&&i.x<=n.x||e.x<=n.x&&n.x<=i.x,r=o.y<=i.y&&i.y<=n.y||e.y<=n.y&&n.y<=i.y,a=o.z<=i.z&&i.z<=n.z||e.z<=n.z&&n.z<=i.z;return s&&r&&a},o.prototype.volume=function(){var t=this.lowerBound,e=this.upperBound;return(e.x-t.x)*(e.y-t.y)*(e.z-t.z)},o.prototype.contains=function(t){var e=this.lowerBound,i=this.upperBound,o=t.lowerBound,n=t.upperBound;return e.x<=o.x&&i.x>=n.x&&e.y<=o.y&&i.y>=n.y&&e.z<=o.z&&i.z>=n.z},o.prototype.getCorners=function(t,e,i,o,n,s,r,a){var h=this.lowerBound,l=this.upperBound;t.copy(h),e.set(l.x,h.y,h.z),i.set(l.x,l.y,h.z),o.set(h.x,l.y,l.z),n.set(l.x,h.y,h.z),s.set(h.x,l.y,h.z),r.set(h.x,h.y,l.z),a.copy(l)};var r=[new n,new n,new n,new n,new n,new n,new n,new n];o.prototype.toLocalFrame=function(t,e){var i=r,o=i[0],n=i[1],s=i[2],a=i[3],h=i[4],l=i[5],c=i[6],u=i[7];this.getCorners(o,n,s,a,h,l,c,u);for(var p=0;8!==p;p++){var d=i[p];t.pointToLocal(d,d)}return e.setFromPoints(i)},o.prototype.toWorldFrame=function(t,e){var i=r,o=i[0],n=i[1],s=i[2],a=i[3],h=i[4],l=i[5],c=i[6],u=i[7];this.getCorners(o,n,s,a,h,l,c,u);for(var p=0;8!==p;p++){var d=i[p];t.pointToWorld(d,d)}return e.setFromPoints(i)},o.prototype.overlapsRay=function(t){var e=1/t._direction.x,i=1/t._direction.y,o=1/t._direction.z,n=(this.lowerBound.x-t.from.x)*e,s=(this.upperBound.x-t.from.x)*e,r=(this.lowerBound.y-t.from.y)*i,a=(this.upperBound.y-t.from.y)*i,h=(this.lowerBound.z-t.from.z)*o,l=(this.upperBound.z-t.from.z)*o,c=Math.max(Math.max(Math.min(n,s),Math.min(r,a)),Math.min(h,l)),u=Math.min(Math.min(Math.max(n,s),Math.max(r,a)),Math.max(h,l));return!(u<0)&&!(c>u)}},{"../math/Vec3":74,"../utils/Utils":97}],47:[function(t,e,i){function o(){this.matrix=[]}e.exports=o,o.prototype.get=function(t,e){if(t=t.index,e=e.index,e>t){var i=e;e=t,t=i}return this.matrix[(t*(t+1)>>1)+e-1]},o.prototype.set=function(t,e,i){if(t=t.index,e=e.index,e>t){var o=e;e=t,t=o}this.matrix[(t*(t+1)>>1)+e-1]=i?1:0},o.prototype.reset=function(){for(var t=0,e=this.matrix.length;t!==e;t++)this.matrix[t]=0},o.prototype.setNumObjects=function(t){this.matrix.length=t*(t-1)>>1}},{}],48:[function(t,e,i){function o(){this.world=null,this.useBoundingBoxes=!1,this.dirty=!0}var n=t("../objects/Body"),s=t("../math/Vec3"),r=t("../math/Quaternion");t("../shapes/Shape"),t("../shapes/Plane");e.exports=o,o.prototype.collisionPairs=function(t,e,i){throw new Error("collisionPairs not implemented for this BroadPhase class!")},o.prototype.needBroadphaseCollision=function(t,e){return 0!==(t.collisionFilterGroup&e.collisionFilterMask)&&0!==(e.collisionFilterGroup&t.collisionFilterMask)&&(0===(t.type&n.STATIC)&&t.sleepState!==n.SLEEPING||0===(e.type&n.STATIC)&&e.sleepState!==n.SLEEPING)},o.prototype.intersectionTest=function(t,e,i,o){this.useBoundingBoxes?this.doBoundingBoxBroadphase(t,e,i,o):this.doBoundingSphereBroadphase(t,e,i,o)};var a=new s;new s,new r,new s;o.prototype.doBoundingSphereBroadphase=function(t,e,i,o){var n=a;e.position.vsub(t.position,n);var s=Math.pow(t.boundingRadius+e.boundingRadius,2),r=n.norm2();r<s&&(i.push(t),o.push(e))},o.prototype.doBoundingBoxBroadphase=function(t,e,i,o){t.aabbNeedsUpdate&&t.computeAABB(),e.aabbNeedsUpdate&&e.computeAABB(),t.aabb.overlaps(e.aabb)&&(i.push(t),o.push(e))};var h={keys:[]},l=[],c=[];o.prototype.makePairsUnique=function(t,e){for(var i=h,o=l,n=c,s=t.length,r=0;r!==s;r++)o[r]=t[r],n[r]=e[r];t.length=0,e.length=0;for(var r=0;r!==s;r++){var a=o[r].id,u=n[r].id,p=a<u?a+","+u:u+","+a;i[p]=r,i.keys.push(p)}for(var r=0;r!==i.keys.length;r++){var p=i.keys.pop(),d=i[p];t.push(o[d]),e.push(n[d]),delete i[p]}},o.prototype.setWorld=function(t){};var u=new s;o.boundingSphereCheck=function(t,e){var i=u;return t.position.vsub(e.position,i),Math.pow(t.shape.boundingSphereRadius+e.shape.boundingSphereRadius,2)>i.norm2()},o.prototype.aabbQuery=function(t,e,i){return console.warn(".aabbQuery is not implemented in this Broadphase subclass."),[]}},{"../math/Quaternion":72,"../math/Vec3":74,"../objects/Body":75,"../shapes/Plane":86,"../shapes/Shape":87}],49:[function(t,e,i){function o(t,e,i,o,r){n.apply(this),this.nx=i||10,this.ny=o||10,this.nz=r||10,this.aabbMin=t||new s(100,100,100),this.aabbMax=e||new s((-100),(-100),(-100));var a=this.nx*this.ny*this.nz;if(a<=0)throw"GridBroadphase: Each dimension's n must be >0";this.bins=[],this.binLengths=[],this.bins.length=a,this.binLengths.length=a;for(var h=0;h<a;h++)this.bins[h]=[],this.binLengths[h]=0}e.exports=o;var n=t("./Broadphase"),s=t("../math/Vec3"),r=t("../shapes/Shape");o.prototype=new n,o.prototype.constructor=o;var a=new s;new s;o.prototype.collisionPairs=function(t,e,i){function o(t,e,i,o,n,s,r){var a=(t-w)*E|0,h=(e-b)*A|0,l=(i-x)*C|0,f=V((o-w)*E),m=V((n-b)*A),g=V((s-x)*C);a<0?a=0:a>=c&&(a=c-1),h<0?h=0:h>=u&&(h=u-1),l<0?l=0:l>=p&&(l=p-1),f<0?f=0:f>=c&&(f=c-1),m<0?m=0:m>=u&&(m=u-1),g<0?g=0:g>=p&&(g=p-1),a*=d,h*=y,l*=v,f*=d,m*=y,g*=v;for(var B=a;B<=f;B+=d)for(var S=h;S<=m;S+=y)for(var R=l;R<=g;R+=v){var M=B+S+R;L[M][P[M]++]=r}}for(var n=t.numObjects(),s=t.bodies,h=this.aabbMax,l=this.aabbMin,c=this.nx,u=this.ny,p=this.nz,d=u*p,y=p,v=1,f=h.x,m=h.y,g=h.z,w=l.x,b=l.y,x=l.z,E=c/(f-w),A=u/(m-b),C=p/(g-x),B=(f-w)/c,S=(m-b)/u,R=(g-x)/p,M=.5*Math.sqrt(B*B+S*S+R*R),T=r.types,z=T.SPHERE,k=T.PLANE,L=(T.BOX,T.COMPOUND,T.CONVEXPOLYHEDRON,this.bins),P=this.binLengths,q=this.bins.length,F=0;F!==q;F++)P[F]=0;for(var V=Math.ceil,l=Math.min,h=Math.max,F=0;F!==n;F++){var N=s[F],I=N.shape;switch(I.type){case z:var H=N.position.x,O=N.position.y,j=N.position.z,D=I.radius;o(H-D,O-D,j-D,H+D,O+D,j+D,N);break;case k:I.worldNormalNeedsUpdate&&I.computeWorldNormal(N.quaternion);var W=I.worldNormal,K=w+.5*B-N.position.x,_=b+.5*S-N.position.y,U=x+.5*R-N.position.z,G=a;G.set(K,_,U);for(var Y=0,X=0;Y!==c;Y++,X+=d,G.y=_,G.x+=B)for(var Q=0,Z=0;Q!==u;Q++,Z+=y,G.z=U,G.y+=S)for(var J=0,$=0;J!==p;J++,$+=v,G.z+=R)if(G.dot(W)<M){var tt=X+Z+$;L[tt][P[tt]++]=N}break;default:N.aabbNeedsUpdate&&N.computeAABB(),o(N.aabb.lowerBound.x,N.aabb.lowerBound.y,N.aabb.lowerBound.z,N.aabb.upperBound.x,N.aabb.upperBound.y,N.aabb.upperBound.z,N)}}for(var F=0;F!==q;F++){var et=P[F];if(et>1)for(var it=L[F],Y=0;Y!==et;Y++)for(var N=it[Y],Q=0;Q!==Y;Q++){var ot=it[Q];this.needBroadphaseCollision(N,ot)&&this.intersectionTest(N,ot,e,i)}}this.makePairsUnique(e,i)}},{"../math/Vec3":74,"../shapes/Shape":87,"./Broadphase":48}],50:[function(t,e,i){function o(){n.apply(this)}e.exports=o;var n=t("./Broadphase"),s=t("./AABB");o.prototype=new n,o.prototype.constructor=o,o.prototype.collisionPairs=function(t,e,i){var o,n,s,r,a=t.bodies,h=a.length;for(o=0;o!==h;o++)for(n=0;n!==o;n++)s=a[o],r=a[n],this.needBroadphaseCollision(s,r)&&this.intersectionTest(s,r,e,i)};new s;o.prototype.aabbQuery=function(t,e,i){i=i||[];for(var o=0;o<t.bodies.length;o++){var n=t.bodies[o];n.aabbNeedsUpdate&&n.computeAABB(),n.aabb.overlaps(e)&&i.push(n)}return i}},{"./AABB":46,"./Broadphase":48}],51:[function(t,e,i){function o(){this.matrix={}}e.exports=o,o.prototype.get=function(t,e){if(t=t.id,e=e.id,e>t){var i=e;e=t,t=i}return t+"-"+e in this.matrix},o.prototype.set=function(t,e,i){if(t=t.id,e=e.id,e>t){var o=e;e=t,t=o}i?this.matrix[t+"-"+e]=!0:delete this.matrix[t+"-"+e]},o.prototype.reset=function(){this.matrix={}},o.prototype.setNumObjects=function(t){}},{}],52:[function(t,e,i){function o(){this.current=[],this.previous=[]}function n(t,e){t.push((4294901760&e)>>16,65535&e)}e.exports=o,o.prototype.getKey=function(t,e){if(e<t){var i=e;e=t,t=i}return t<<16|e},o.prototype.set=function(t,e){for(var i=this.getKey(t,e),o=this.current,n=0;i>o[n];)n++;if(i!==o[n]){for(var e=o.length-1;e>=n;e--)o[e+1]=o[e];o[n]=i}},o.prototype.tick=function(){var t=this.current;this.current=this.previous,this.previous=t,this.current.length=0},o.prototype.getDiff=function(t,e){for(var i=this.current,o=this.previous,s=i.length,r=o.length,a=0,h=0;h<s;h++){for(var l=!1,c=i[h];c>o[a];)a++;l=c===o[a],l||n(t,c)}a=0;for(var h=0;h<r;h++){for(var l=!1,u=o[h];u>i[a];)a++;l=i[a]===u,l||n(e,u)}}},{}],53:[function(t,e,i){function o(t,e){this.from=t?t.clone():new r,this.to=e?e.clone():new r,this._direction=new r,this.precision=1e-4,this.checkCollisionResponse=!0,this.skipBackfaces=!1,this.collisionFilterMask=-1,this.collisionFilterGroup=-1,this.mode=o.ANY,this.result=new l,this.hasHit=!1,this.callback=function(t){}}function n(t,e,i,o){o.vsub(e,I),i.vsub(e,y),t.vsub(e,v);var n,s,r=I.dot(I),a=I.dot(y),h=I.dot(v),l=y.dot(y),c=y.dot(v);return(n=l*h-a*c)>=0&&(s=r*c-a*h)>=0&&n+s<r*l-a*a}function s(t,e,i){i.vsub(t,I);var o=I.dot(e);e.mult(o,H),H.vadd(t,H);var n=i.distanceTo(H);return n}e.exports=o;var r=t("../math/Vec3"),a=t("../math/Quaternion"),h=t("../math/Transform"),l=(t("../shapes/ConvexPolyhedron"),t("../shapes/Box"),t("../collision/RaycastResult")),c=t("../shapes/Shape"),u=t("../collision/AABB");o.prototype.constructor=o,o.CLOSEST=1,o.ANY=2,o.ALL=4;var p=new u,d=[];o.prototype.intersectWorld=function(t,e){return this.mode=e.mode||o.ANY,this.result=e.result||new l,this.skipBackfaces=!!e.skipBackfaces,this.collisionFilterMask="undefined"!=typeof e.collisionFilterMask?e.collisionFilterMask:-1,this.collisionFilterGroup="undefined"!=typeof e.collisionFilterGroup?e.collisionFilterGroup:-1,e.from&&this.from.copy(e.from),e.to&&this.to.copy(e.to),this.callback=e.callback||function(){},this.hasHit=!1,this.result.reset(),this._updateDirection(),this.getAABB(p),d.length=0,t.broadphase.aabbQuery(t,p,d),this.intersectBodies(d),this.hasHit};var y=new r,v=new r;o.pointInTriangle=n;var f=new r,m=new a;o.prototype.intersectBody=function(t,e){e&&(this.result=e,this._updateDirection());var i=this.checkCollisionResponse;if((!i||t.collisionResponse)&&0!==(this.collisionFilterGroup&t.collisionFilterMask)&&0!==(t.collisionFilterGroup&this.collisionFilterMask))for(var o=f,n=m,s=0,r=t.shapes.length;s<r;s++){var a=t.shapes[s];if((!i||a.collisionResponse)&&(t.quaternion.mult(t.shapeOrientations[s],n),t.quaternion.vmult(t.shapeOffsets[s],o),o.vadd(t.position,o),this.intersectShape(a,n,o,t),this.result._shouldStop))break}},o.prototype.intersectBodies=function(t,e){e&&(this.result=e,this._updateDirection());for(var i=0,o=t.length;!this.result._shouldStop&&i<o;i++)this.intersectBody(t[i])},o.prototype._updateDirection=function(){this.to.vsub(this.from,this._direction),this._direction.normalize()},o.prototype.intersectShape=function(t,e,i,o){var n=this.from,r=s(n,this._direction,i);if(!(r>t.boundingSphereRadius)){var a=this[t.type];a&&a.call(this,t,e,i,o,t)}};var g=(new r,new r,new r),w=new r,b=new r,x=new r;new r,new l;o.prototype.intersectBox=function(t,e,i,o,n){return this.intersectConvex(t.convexPolyhedronRepresentation,e,i,o,n)},o.prototype[c.types.BOX]=o.prototype.intersectBox,o.prototype.intersectPlane=function(t,e,i,o,n){var s=this.from,a=this.to,h=this._direction,l=new r(0,0,1);e.vmult(l,l);var c=new r;s.vsub(i,c);var u=c.dot(l);a.vsub(i,c);var p=c.dot(l);if(!(u*p>0||s.distanceTo(a)<u)){var d=l.dot(h);if(!(Math.abs(d)<this.precision)){var y=new r,v=new r,f=new r;s.vsub(i,y);var m=-l.dot(y)/d;h.scale(m,v),s.vadd(v,f),this.reportIntersection(l,f,n,o,-1)}}},o.prototype[c.types.PLANE]=o.prototype.intersectPlane,o.prototype.getAABB=function(t){var e=this.to,i=this.from;t.lowerBound.x=Math.min(e.x,i.x),t.lowerBound.y=Math.min(e.y,i.y),t.lowerBound.z=Math.min(e.z,i.z),t.upperBound.x=Math.max(e.x,i.x),t.upperBound.y=Math.max(e.y,i.y),t.upperBound.z=Math.max(e.z,i.z)};var E={faceList:[0]},A=new r,C=new o,B=[];o.prototype.intersectHeightfield=function(t,e,i,o,n){var s=(t.data,t.elementSize,C);s.from.copy(this.from),s.to.copy(this.to),h.pointToLocalFrame(i,e,s.from,s.from),h.pointToLocalFrame(i,e,s.to,s.to),s._updateDirection();var r,a,l,c,p=B;r=a=0,l=c=t.data.length-1;var d=new u;s.getAABB(d),t.getIndexOfPosition(d.lowerBound.x,d.lowerBound.y,p,!0),r=Math.max(r,p[0]),a=Math.max(a,p[1]),t.getIndexOfPosition(d.upperBound.x,d.upperBound.y,p,!0),l=Math.min(l,p[0]+1),c=Math.min(c,p[1]+1);for(var y=r;y<l;y++)for(var v=a;v<c;v++){if(this.result._shouldStop)return;if(t.getAabbAtIndex(y,v,d),d.overlapsRay(s)){if(t.getConvexTrianglePillar(y,v,!1),h.pointToWorldFrame(i,e,t.pillarOffset,A),this.intersectConvex(t.pillarConvex,e,A,o,n,E),this.result._shouldStop)return;t.getConvexTrianglePillar(y,v,!0),h.pointToWorldFrame(i,e,t.pillarOffset,A),this.intersectConvex(t.pillarConvex,e,A,o,n,E)}}},o.prototype[c.types.HEIGHTFIELD]=o.prototype.intersectHeightfield;var S=new r,R=new r;o.prototype.intersectSphere=function(t,e,i,o,n){var s=this.from,r=this.to,a=t.radius,h=Math.pow(r.x-s.x,2)+Math.pow(r.y-s.y,2)+Math.pow(r.z-s.z,2),l=2*((r.x-s.x)*(s.x-i.x)+(r.y-s.y)*(s.y-i.y)+(r.z-s.z)*(s.z-i.z)),c=Math.pow(s.x-i.x,2)+Math.pow(s.y-i.y,2)+Math.pow(s.z-i.z,2)-Math.pow(a,2),u=Math.pow(l,2)-4*h*c,p=S,d=R;if(!(u<0))if(0===u)s.lerp(r,u,p),p.vsub(i,d),d.normalize(),this.reportIntersection(d,p,n,o,-1);else{var y=(-l-Math.sqrt(u))/(2*h),v=(-l+Math.sqrt(u))/(2*h);if(y>=0&&y<=1&&(s.lerp(r,y,p),p.vsub(i,d),d.normalize(),this.reportIntersection(d,p,n,o,-1)),this.result._shouldStop)return;v>=0&&v<=1&&(s.lerp(r,v,p),p.vsub(i,d),d.normalize(),this.reportIntersection(d,p,n,o,-1))}},o.prototype[c.types.SPHERE]=o.prototype.intersectSphere;var M=new r,T=(new r,new r,new r);o.prototype.intersectConvex=function(t,e,i,o,s,r){for(var a=M,h=T,l=r&&r.faceList||null,c=t.faces,u=t.vertices,p=t.faceNormals,d=this._direction,y=this.from,v=this.to,f=y.distanceTo(v),m=l?l.length:c.length,E=this.result,A=0;!E._shouldStop&&A<m;A++){var C=l?l[A]:A,B=c[C],S=p[C],R=e,z=i;h.copy(u[B[0]]),R.vmult(h,h),h.vadd(z,h),h.vsub(y,h),R.vmult(S,a);var k=d.dot(a);if(!(Math.abs(k)<this.precision)){var L=a.dot(h)/k;if(!(L<0)){d.mult(L,g),g.vadd(y,g),w.copy(u[B[0]]),R.vmult(w,w),z.vadd(w,w);for(var P=1;!E._shouldStop&&P<B.length-1;P++){b.copy(u[B[P]]),x.copy(u[B[P+1]]),R.vmult(b,b),R.vmult(x,x),z.vadd(b,b),z.vadd(x,x);var q=g.distanceTo(y);!n(g,w,b,x)&&!n(g,b,w,x)||q>f||this.reportIntersection(a,g,s,o,C)}}}}},o.prototype[c.types.CONVEXPOLYHEDRON]=o.prototype.intersectConvex;var z=new r,k=new r,L=new r,P=new r,q=new r,F=new r,V=(new u,[]),N=new h;o.prototype.intersectTrimesh=function(t,e,i,o,s,r){var a=z,l=V,c=N,u=T,p=k,d=L,y=P,v=F,f=q,m=(r&&r.faceList||null,t.indices),E=(t.vertices,t.faceNormals,this.from),A=this.to,C=this._direction;c.position.copy(i),c.quaternion.copy(e),h.vectorToLocalFrame(i,e,C,p),h.pointToLocalFrame(i,e,E,d),h.pointToLocalFrame(i,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 B=d.distanceSquared(y);t.tree.rayQuery(this,c,l);for(var S=0,R=l.length;!this.result._shouldStop&&S!==R;S++){var M=l[S];t.getNormal(M,a),t.getVertex(m[3*M],w),w.vsub(d,u);var I=p.dot(a),H=a.dot(u)/I;if(!(H<0)){p.scale(H,g),g.vadd(d,g),t.getVertex(m[3*M+1],b),t.getVertex(m[3*M+2],x);var O=g.distanceSquared(d);!n(g,b,w,x)&&!n(g,w,b,x)||O>B||(h.vectorToWorldFrame(e,a,f),h.pointToWorldFrame(i,e,g,v),this.reportIntersection(f,v,s,o,M))}}l.length=0},o.prototype[c.types.TRIMESH]=o.prototype.intersectTrimesh,o.prototype.reportIntersection=function(t,e,i,n,s){var r=this.from,a=this.to,h=r.distanceTo(e),l=this.result;if(!(this.skipBackfaces&&t.dot(this._direction)>0))switch(l.hitFaceIndex="undefined"!=typeof s?s:-1,this.mode){case o.ALL:this.hasHit=!0,l.set(r,a,t,e,i,n,h),l.hasHit=!0,this.callback(l);break;case o.CLOSEST:(h<l.distance||!l.hasHit)&&(this.hasHit=!0,l.hasHit=!0,l.set(r,a,t,e,i,n,h));break;case o.ANY:this.hasHit=!0,l.hasHit=!0,l.set(r,a,t,e,i,n,h),l._shouldStop=!0}};var I=new r,H=new r},{"../collision/AABB":46,"../collision/RaycastResult":54,"../math/Quaternion":72,"../math/Transform":73,"../math/Vec3":74,"../shapes/Box":81,"../shapes/ConvexPolyhedron":82,"../shapes/Shape":87}],54:[function(t,e,i){function o(){this.rayFromWorld=new n,this.rayToWorld=new n,this.hitNormalWorld=new n,this.hitPointWorld=new n,this.hasHit=!1,this.shape=null,this.body=null,this.hitFaceIndex=-1,this.distance=-1,this._shouldStop=!1}var n=t("../math/Vec3");e.exports=o,o.prototype.reset=function(){this.rayFromWorld.setZero(),this.rayToWorld.setZero(),this.hitNormalWorld.setZero(),this.hitPointWorld.setZero(),this.hasHit=!1,this.shape=null,this.body=null,this.hitFaceIndex=-1,this.distance=-1,this._shouldStop=!1},o.prototype.abort=function(){this._shouldStop=!0},o.prototype.set=function(t,e,i,o,n,s,r){this.rayFromWorld.copy(t),this.rayToWorld.copy(e),this.hitNormalWorld.copy(i),this.hitPointWorld.copy(o),this.shape=n,this.body=s,this.distance=r}},{"../math/Vec3":74}],55:[function(t,e,i){function o(t){n.apply(this),this.axisList=[],this.world=null,this.axisIndex=0;var e=this.axisList;this._addBodyHandler=function(t){e.push(t.body)},this._removeBodyHandler=function(t){var i=e.indexOf(t.body);i!==-1&&e.splice(i,1)},t&&this.setWorld(t)}var n=(t("../shapes/Shape"),t("../collision/Broadphase"));e.exports=o,o.prototype=new n,o.prototype.setWorld=function(t){this.axisList.length=0;for(var e=0;e<t.bodies.length;e++)this.axisList.push(t.bodies[e]);t.removeEventListener("addBody",this._addBodyHandler),t.removeEventListener("removeBody",this._removeBodyHandler),t.addEventListener("addBody",this._addBodyHandler),t.addEventListener("removeBody",this._removeBodyHandler),this.world=t,this.dirty=!0},o.insertionSortX=function(t){for(var e=1,i=t.length;e<i;e++){for(var o=t[e],n=e-1;n>=0&&!(t[n].aabb.lowerBound.x<=o.aabb.lowerBound.x);n--)t[n+1]=t[n];t[n+1]=o}return t},o.insertionSortY=function(t){for(var e=1,i=t.length;e<i;e++){for(var o=t[e],n=e-1;n>=0&&!(t[n].aabb.lowerBound.y<=o.aabb.lowerBound.y);n--)t[n+1]=t[n];t[n+1]=o}return t},o.insertionSortZ=function(t){for(var e=1,i=t.length;e<i;e++){for(var o=t[e],n=e-1;n>=0&&!(t[n].aabb.lowerBound.z<=o.aabb.lowerBound.z);n--)t[n+1]=t[n];t[n+1]=o}return t},o.prototype.collisionPairs=function(t,e,i){var n,s,r=this.axisList,a=r.length,h=this.axisIndex;for(this.dirty&&(this.sortList(),this.dirty=!1),n=0;n!==a;n++){var l=r[n];for(s=n+1;s<a;s++){var c=r[s];if(this.needBroadphaseCollision(l,c)){if(!o.checkBounds(l,c,h))break;this.intersectionTest(l,c,e,i)}}}},o.prototype.sortList=function(){for(var t=this.axisList,e=this.axisIndex,i=t.length,n=0;n!==i;n++){var s=t[n];s.aabbNeedsUpdate&&s.computeAABB()}0===e?o.insertionSortX(t):1===e?o.insertionSortY(t):2===e&&o.insertionSortZ(t)},o.checkBounds=function(t,e,i){var o,n;0===i?(o=t.position.x,n=e.position.x):1===i?(o=t.position.y,n=e.position.y):2===i&&(o=t.position.z,n=e.position.z);var s=t.boundingRadius,r=e.boundingRadius,a=o+s,h=n-r;return h<a},o.prototype.autoDetectAxis=function(){for(var t=0,e=0,i=0,o=0,n=0,s=0,r=this.axisList,a=r.length,h=1/a,l=0;l!==a;l++){var c=r[l],u=c.position.x;t+=u,e+=u*u;var p=c.position.y;i+=p,o+=p*p;var d=c.position.z;n+=d,s+=d*d}var y=e-t*t*h,v=o-i*i*h,f=s-n*n*h;y>v?y>f?this.axisIndex=0:this.axisIndex=2:v>f?this.axisIndex=1:this.axisIndex=2},o.prototype.aabbQuery=function(t,e,i){i=i||[],this.dirty&&(this.sortList(),this.dirty=!1);var o=this.axisIndex,n="x";1===o&&(n="y"),2===o&&(n="z");for(var s=this.axisList,r=(e.lowerBound[n],e.upperBound[n],0);r<s.length;r++){var a=s[r];a.aabbNeedsUpdate&&a.computeAABB(),a.aabb.overlaps(e)&&i.push(a)}return i}},{"../collision/Broadphase":48,"../shapes/Shape":87}],56:[function(t,e,i){function o(t,e,i){i=i||{};var o="undefined"!=typeof i.maxForce?i.maxForce:1e6,h=i.pivotA?i.pivotA.clone():new a,l=i.pivotB?i.pivotB.clone():new a;this.axisA=i.axisA?i.axisA.clone():new a,this.axisB=i.axisB?i.axisB.clone():new a,n.call(this,t,h,e,l,o),this.collideConnected=!!i.collideConnected,this.angle="undefined"!=typeof i.angle?i.angle:0;var c=this.coneEquation=new s(t,e,i),u=this.twistEquation=new r(t,e,i);this.twistAngle="undefined"!=typeof i.twistAngle?i.twistAngle:0,c.maxForce=0,c.minForce=-o,u.maxForce=0,u.minForce=-o,this.equations.push(c,u)}e.exports=o;var n=(t("./Constraint"),t("./PointToPointConstraint")),s=t("../equations/ConeEquation"),r=t("../equations/RotationalEquation"),a=(t("../equations/ContactEquation"),t("../math/Vec3"));o.prototype=new n,o.constructor=o;new a,new a;o.prototype.update=function(){var t=this.bodyA,e=this.bodyB,i=this.coneEquation,o=this.twistEquation;n.prototype.update.call(this),t.vectorToWorldFrame(this.axisA,i.axisA),e.vectorToWorldFrame(this.axisB,i.axisB),this.axisA.tangents(o.axisA,o.axisA),t.vectorToWorldFrame(o.axisA,o.axisA),this.axisB.tangents(o.axisB,o.axisB),e.vectorToWorldFrame(o.axisB,o.axisB),i.angle=this.angle,o.maxAngle=this.twistAngle}},{"../equations/ConeEquation":62,"../equations/ContactEquation":63,"../equations/RotationalEquation":66,"../math/Vec3":74,"./Constraint":57,"./PointToPointConstraint":61}],57:[function(t,e,i){function o(t,e,i){i=n.defaults(i,{collideConnected:!0,wakeUpBodies:!0}),this.equations=[],this.bodyA=t,this.bodyB=e,this.id=o.idCounter++,this.collideConnected=i.collideConnected,i.wakeUpBodies&&(t&&t.wakeUp(),e&&e.wakeUp())}e.exports=o;var n=t("../utils/Utils");o.prototype.update=function(){throw new Error("method update() not implmemented in this Constraint subclass!")},o.prototype.enable=function(){for(var t=this.equations,e=0;e<t.length;e++)t[e].enabled=!0},o.prototype.disable=function(){for(var t=this.equations,e=0;e<t.length;e++)t[e].enabled=!1},o.idCounter=0},{"../utils/Utils":97}],58:[function(t,e,i){function o(t,e,i,o){n.call(this,t,e),"undefined"==typeof i&&(i=t.position.distanceTo(e.position)),"undefined"==typeof o&&(o=1e6),this.distance=i;var r=this.distanceEquation=new s(t,e);this.equations.push(r),r.minForce=-o,r.maxForce=o}e.exports=o;var n=t("./Constraint"),s=t("../equations/ContactEquation");
o.prototype=new n,o.prototype.update=function(){var t=this.bodyA,e=this.bodyB,i=this.distanceEquation,o=.5*this.distance,n=i.ni;e.position.vsub(t.position,n),n.normalize(),n.mult(o,i.ri),n.mult(-o,i.rj)}},{"../equations/ContactEquation":63,"./Constraint":57}],59:[function(t,e,i){function o(t,e,i){i=i||{};var o="undefined"!=typeof i.maxForce?i.maxForce:1e6,h=i.pivotA?i.pivotA.clone():new a,l=i.pivotB?i.pivotB.clone():new a;n.call(this,t,h,e,l,o);var c=this.axisA=i.axisA?i.axisA.clone():new a(1,0,0);c.normalize();var u=this.axisB=i.axisB?i.axisB.clone():new a(1,0,0);u.normalize();var p=this.rotationalEquation1=new s(t,e,i),d=this.rotationalEquation2=new s(t,e,i),y=this.motorEquation=new r(t,e,o);y.enabled=!1,this.equations.push(p,d,y)}e.exports=o;var n=(t("./Constraint"),t("./PointToPointConstraint")),s=t("../equations/RotationalEquation"),r=t("../equations/RotationalMotorEquation"),a=(t("../equations/ContactEquation"),t("../math/Vec3"));o.prototype=new n,o.constructor=o,o.prototype.enableMotor=function(){this.motorEquation.enabled=!0},o.prototype.disableMotor=function(){this.motorEquation.enabled=!1},o.prototype.setMotorSpeed=function(t){this.motorEquation.targetVelocity=t},o.prototype.setMotorMaxForce=function(t){this.motorEquation.maxForce=t,this.motorEquation.minForce=-t};var h=new a,l=new a;o.prototype.update=function(){var t=this.bodyA,e=this.bodyB,i=this.motorEquation,o=this.rotationalEquation1,s=this.rotationalEquation2,r=h,a=l,c=this.axisA,u=this.axisB;n.prototype.update.call(this),t.quaternion.vmult(c,r),e.quaternion.vmult(u,a),r.tangents(o.axisA,s.axisA),o.axisB.copy(a),s.axisB.copy(a),this.motorEquation.enabled&&(t.quaternion.vmult(this.axisA,i.axisA),e.quaternion.vmult(this.axisB,i.axisB))}},{"../equations/ContactEquation":63,"../equations/RotationalEquation":66,"../equations/RotationalMotorEquation":67,"../math/Vec3":74,"./Constraint":57,"./PointToPointConstraint":61}],60:[function(t,e,i){function o(t,e,i){i=i||{};var o="undefined"!=typeof i.maxForce?i.maxForce:1e6,a=new r,h=new r,l=new r;t.position.vadd(e.position,l),l.scale(.5,l),e.pointToLocalFrame(l,h),t.pointToLocalFrame(l,a),n.call(this,t,a,e,h,o),this.xA=t.vectorToLocalFrame(r.UNIT_X),this.xB=e.vectorToLocalFrame(r.UNIT_X),this.yA=t.vectorToLocalFrame(r.UNIT_Y),this.yB=e.vectorToLocalFrame(r.UNIT_Y),this.zA=t.vectorToLocalFrame(r.UNIT_Z),this.zB=e.vectorToLocalFrame(r.UNIT_Z);var c=this.rotationalEquation1=new s(t,e,i),u=this.rotationalEquation2=new s(t,e,i),p=this.rotationalEquation3=new s(t,e,i);this.equations.push(c,u,p)}e.exports=o;var n=(t("./Constraint"),t("./PointToPointConstraint")),s=t("../equations/RotationalEquation"),r=(t("../equations/RotationalMotorEquation"),t("../equations/ContactEquation"),t("../math/Vec3"));o.prototype=new n,o.constructor=o;new r,new r;o.prototype.update=function(){var t=this.bodyA,e=this.bodyB,i=(this.motorEquation,this.rotationalEquation1),o=this.rotationalEquation2,s=this.rotationalEquation3;n.prototype.update.call(this),t.vectorToWorldFrame(this.xA,i.axisA),e.vectorToWorldFrame(this.yB,i.axisB),t.vectorToWorldFrame(this.yA,o.axisA),e.vectorToWorldFrame(this.zB,o.axisB),t.vectorToWorldFrame(this.zA,s.axisA),e.vectorToWorldFrame(this.xB,s.axisB)}},{"../equations/ContactEquation":63,"../equations/RotationalEquation":66,"../equations/RotationalMotorEquation":67,"../math/Vec3":74,"./Constraint":57,"./PointToPointConstraint":61}],61:[function(t,e,i){function o(t,e,i,o,a){n.call(this,t,i),a="undefined"!=typeof a?a:1e6,this.pivotA=e?e.clone():new r,this.pivotB=o?o.clone():new r;var h=this.equationX=new s(t,i),l=this.equationY=new s(t,i),c=this.equationZ=new s(t,i);this.equations.push(h,l,c),h.minForce=l.minForce=c.minForce=-a,h.maxForce=l.maxForce=c.maxForce=a,h.ni.set(1,0,0),l.ni.set(0,1,0),c.ni.set(0,0,1)}e.exports=o;var n=t("./Constraint"),s=t("../equations/ContactEquation"),r=t("../math/Vec3");o.prototype=new n,o.prototype.update=function(){var t=this.bodyA,e=this.bodyB,i=this.equationX,o=this.equationY,n=this.equationZ;t.quaternion.vmult(this.pivotA,i.ri),e.quaternion.vmult(this.pivotB,i.rj),o.ri.copy(i.ri),o.rj.copy(i.rj),n.ri.copy(i.ri),n.rj.copy(i.rj)}},{"../equations/ContactEquation":63,"../math/Vec3":74,"./Constraint":57}],62:[function(t,e,i){function o(t,e,i){i=i||{};var o="undefined"!=typeof i.maxForce?i.maxForce:1e6;s.call(this,t,e,-o,o),this.axisA=i.axisA?i.axisA.clone():new n(1,0,0),this.axisB=i.axisB?i.axisB.clone():new n(0,1,0),this.angle="undefined"!=typeof i.angle?i.angle:0}e.exports=o;var n=t("../math/Vec3"),s=(t("../math/Mat3"),t("./Equation"));o.prototype=new s,o.prototype.constructor=o;var r=new n,a=new n;o.prototype.computeB=function(t){var e=this.a,i=this.b,o=this.axisA,n=this.axisB,s=r,h=a,l=this.jacobianElementA,c=this.jacobianElementB;o.cross(n,s),n.cross(o,h),l.rotational.copy(h),c.rotational.copy(s);var u=Math.cos(this.angle)-o.dot(n),p=this.computeGW(),d=this.computeGiMf(),y=-u*e-p*i-t*d;return y}},{"../math/Mat3":71,"../math/Vec3":74,"./Equation":64}],63:[function(t,e,i){function o(t,e,i){i="undefined"!=typeof i?i:1e6,n.call(this,t,e,0,i),this.restitution=0,this.ri=new s,this.rj=new s,this.ni=new s}e.exports=o;var n=t("./Equation"),s=t("../math/Vec3");t("../math/Mat3");o.prototype=new n,o.prototype.constructor=o;var r=new s,a=new s,h=new s;o.prototype.computeB=function(t){var e=this.a,i=this.b,o=this.bi,n=this.bj,s=this.ri,l=this.rj,c=r,u=a,p=o.velocity,d=o.angularVelocity,y=(o.force,o.torque,n.velocity),v=n.angularVelocity,f=(n.force,n.torque,h),m=this.jacobianElementA,g=this.jacobianElementB,w=this.ni;s.cross(w,c),l.cross(w,u),w.negate(m.spatial),c.negate(m.rotational),g.spatial.copy(w),g.rotational.copy(u),f.copy(n.position),f.vadd(l,f),f.vsub(o.position,f),f.vsub(s,f);var b=w.dot(f),x=this.restitution+1,E=x*y.dot(w)-x*p.dot(w)+v.dot(u)-d.dot(c),A=this.computeGiMf(),C=-b*e-E*i-t*A;return C};var l=new s,c=new s,u=new s,p=new s,d=new s;o.prototype.getImpactVelocityAlongNormal=function(){var t=l,e=c,i=u,o=p,n=d;return this.bi.position.vadd(this.ri,i),this.bj.position.vadd(this.rj,o),this.bi.getVelocityAtWorldPoint(i,t),this.bj.getVelocityAtWorldPoint(o,e),t.vsub(e,n),this.ni.dot(n)}},{"../math/Mat3":71,"../math/Vec3":74,"./Equation":64}],64:[function(t,e,i){function o(t,e,i,s){this.id=o.id++,this.minForce="undefined"==typeof i?-1e6:i,this.maxForce="undefined"==typeof s?1e6:s,this.bi=t,this.bj=e,this.a=0,this.b=0,this.eps=0,this.jacobianElementA=new n,this.jacobianElementB=new n,this.enabled=!0,this.multiplier=0,this.setSpookParams(1e7,4,1/60)}e.exports=o;var n=t("../math/JacobianElement"),s=t("../math/Vec3");o.prototype.constructor=o,o.id=0,o.prototype.setSpookParams=function(t,e,i){var o=e,n=t,s=i;this.a=4/(s*(1+4*o)),this.b=4*o/(1+4*o),this.eps=4/(s*s*n*(1+4*o))},o.prototype.computeB=function(t,e,i){var o=this.computeGW(),n=this.computeGq(),s=this.computeGiMf();return-n*t-o*e-s*i},o.prototype.computeGq=function(){var t=this.jacobianElementA,e=this.jacobianElementB,i=this.bi,o=this.bj,n=i.position,s=o.position;return t.spatial.dot(n)+e.spatial.dot(s)};new s;o.prototype.computeGW=function(){var t=this.jacobianElementA,e=this.jacobianElementB,i=this.bi,o=this.bj,n=i.velocity,s=o.velocity,r=i.angularVelocity,a=o.angularVelocity;return t.multiplyVectors(n,r)+e.multiplyVectors(s,a)},o.prototype.computeGWlambda=function(){var t=this.jacobianElementA,e=this.jacobianElementB,i=this.bi,o=this.bj,n=i.vlambda,s=o.vlambda,r=i.wlambda,a=o.wlambda;return t.multiplyVectors(n,r)+e.multiplyVectors(s,a)};var r=new s,a=new s,h=new s,l=new s;o.prototype.computeGiMf=function(){var t=this.jacobianElementA,e=this.jacobianElementB,i=this.bi,o=this.bj,n=i.force,s=i.torque,c=o.force,u=o.torque,p=i.invMassSolve,d=o.invMassSolve;return n.scale(p,r),c.scale(d,a),i.invInertiaWorldSolve.vmult(s,h),o.invInertiaWorldSolve.vmult(u,l),t.multiplyVectors(r,h)+e.multiplyVectors(a,l)};var c=new s;o.prototype.computeGiMGt=function(){var t=this.jacobianElementA,e=this.jacobianElementB,i=this.bi,o=this.bj,n=i.invMassSolve,s=o.invMassSolve,r=i.invInertiaWorldSolve,a=o.invInertiaWorldSolve,h=n+s;return r.vmult(t.rotational,c),h+=c.dot(t.rotational),a.vmult(e.rotational,c),h+=c.dot(e.rotational)};var u=new s;new s,new s,new s,new s,new s;o.prototype.addToWlambda=function(t){var e=this.jacobianElementA,i=this.jacobianElementB,o=this.bi,n=this.bj,s=u;o.vlambda.addScaledVector(o.invMassSolve*t,e.spatial,o.vlambda),n.vlambda.addScaledVector(n.invMassSolve*t,i.spatial,n.vlambda),o.invInertiaWorldSolve.vmult(e.rotational,s),o.wlambda.addScaledVector(t,s,o.wlambda),n.invInertiaWorldSolve.vmult(i.rotational,s),n.wlambda.addScaledVector(t,s,n.wlambda)},o.prototype.computeC=function(){return this.computeGiMGt()+this.eps}},{"../math/JacobianElement":70,"../math/Vec3":74}],65:[function(t,e,i){function o(t,e,i){n.call(this,t,e,-i,i),this.ri=new s,this.rj=new s,this.t=new s}e.exports=o;var n=t("./Equation"),s=t("../math/Vec3");t("../math/Mat3");o.prototype=new n,o.prototype.constructor=o;var r=new s,a=new s;o.prototype.computeB=function(t){var e=(this.a,this.b),i=(this.bi,this.bj,this.ri),o=this.rj,n=r,s=a,h=this.t;i.cross(h,n),o.cross(h,s);var l=this.jacobianElementA,c=this.jacobianElementB;h.negate(l.spatial),n.negate(l.rotational),c.spatial.copy(h),c.rotational.copy(s);var u=this.computeGW(),p=this.computeGiMf(),d=-u*e-t*p;return d}},{"../math/Mat3":71,"../math/Vec3":74,"./Equation":64}],66:[function(t,e,i){function o(t,e,i){i=i||{};var o="undefined"!=typeof i.maxForce?i.maxForce:1e6;s.call(this,t,e,-o,o),this.axisA=i.axisA?i.axisA.clone():new n(1,0,0),this.axisB=i.axisB?i.axisB.clone():new n(0,1,0),this.maxAngle=Math.PI/2}e.exports=o;var n=t("../math/Vec3"),s=(t("../math/Mat3"),t("./Equation"));o.prototype=new s,o.prototype.constructor=o;var r=new n,a=new n;o.prototype.computeB=function(t){var e=this.a,i=this.b,o=this.axisA,n=this.axisB,s=r,h=a,l=this.jacobianElementA,c=this.jacobianElementB;o.cross(n,s),n.cross(o,h),l.rotational.copy(h),c.rotational.copy(s);var u=Math.cos(this.maxAngle)-o.dot(n),p=this.computeGW(),d=this.computeGiMf(),y=-u*e-p*i-t*d;return y}},{"../math/Mat3":71,"../math/Vec3":74,"./Equation":64}],67:[function(t,e,i){function o(t,e,i){i="undefined"!=typeof i?i:1e6,s.call(this,t,e,-i,i),this.axisA=new n,this.axisB=new n,this.targetVelocity=0}e.exports=o;var n=t("../math/Vec3"),s=(t("../math/Mat3"),t("./Equation"));o.prototype=new s,o.prototype.constructor=o,o.prototype.computeB=function(t){var e=(this.a,this.b),i=(this.bi,this.bj,this.axisA),o=this.axisB,n=this.jacobianElementA,s=this.jacobianElementB;n.rotational.copy(i),o.negate(s.rotational);var r=this.computeGW()-this.targetVelocity,a=this.computeGiMf(),h=-r*e-t*a;return h}},{"../math/Mat3":71,"../math/Vec3":74,"./Equation":64}],68:[function(t,e,i){function o(t,e,i){i=n.defaults(i,{friction:.3,restitution:.3,contactEquationStiffness:1e7,contactEquationRelaxation:3,frictionEquationStiffness:1e7,frictionEquationRelaxation:3}),this.id=o.idCounter++,this.materials=[t,e],this.friction=i.friction,this.restitution=i.restitution,this.contactEquationStiffness=i.contactEquationStiffness,this.contactEquationRelaxation=i.contactEquationRelaxation,this.frictionEquationStiffness=i.frictionEquationStiffness,this.frictionEquationRelaxation=i.frictionEquationRelaxation}var n=t("../utils/Utils");e.exports=o,o.idCounter=0},{"../utils/Utils":97}],69:[function(t,e,i){function o(t){var e="";t=t||{},"string"==typeof t?(e=t,t={}):"object"==typeof t&&(e=""),this.name=e,this.id=o.idCounter++,this.friction="undefined"!=typeof t.friction?t.friction:-1,this.restitution="undefined"!=typeof t.restitution?t.restitution:-1}e.exports=o,o.idCounter=0},{}],70:[function(t,e,i){function o(){this.spatial=new n,this.rotational=new n}e.exports=o;var n=t("./Vec3");o.prototype.multiplyElement=function(t){return t.spatial.dot(this.spatial)+t.rotational.dot(this.rotational)},o.prototype.multiplyVectors=function(t,e){return t.dot(this.spatial)+e.dot(this.rotational)}},{"./Vec3":74}],71:[function(t,e,i){function o(t){t?this.elements=t:this.elements=[0,0,0,0,0,0,0,0,0]}e.exports=o;var n=t("./Vec3");o.prototype.identity=function(){var t=this.elements;t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=1,t[5]=0,t[6]=0,t[7]=0,t[8]=1},o.prototype.setZero=function(){var t=this.elements;t[0]=0,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=0,t[6]=0,t[7]=0,t[8]=0},o.prototype.setTrace=function(t){var e=this.elements;e[0]=t.x,e[4]=t.y,e[8]=t.z},o.prototype.getTrace=function(t){var t=t||new n,e=this.elements;t.x=e[0],t.y=e[4],t.z=e[8]},o.prototype.vmult=function(t,e){e=e||new n;var i=this.elements,o=t.x,s=t.y,r=t.z;return e.x=i[0]*o+i[1]*s+i[2]*r,e.y=i[3]*o+i[4]*s+i[5]*r,e.z=i[6]*o+i[7]*s+i[8]*r,e},o.prototype.smult=function(t){for(var e=0;e<this.elements.length;e++)this.elements[e]*=t},o.prototype.mmult=function(t,e){for(var i=e||new o,n=0;n<3;n++)for(var s=0;s<3;s++){for(var r=0,a=0;a<3;a++)r+=t.elements[n+3*a]*this.elements[a+3*s];i.elements[n+3*s]=r}return i},o.prototype.scale=function(t,e){e=e||new o;for(var i=this.elements,n=e.elements,s=0;3!==s;s++)n[3*s+0]=t.x*i[3*s+0],n[3*s+1]=t.y*i[3*s+1],n[3*s+2]=t.z*i[3*s+2];return e},o.prototype.solve=function(t,e){e=e||new n;for(var i=3,o=4,s=[],r=0;r<i*o;r++)s.push(0);var r,a;for(r=0;r<3;r++)for(a=0;a<3;a++)s[r+o*a]=this.elements[r+3*a];s[3]=t.x,s[7]=t.y,s[11]=t.z;var h,l,c=3,u=c,p=4;do{if(r=u-c,0===s[r+o*r])for(a=r+1;a<u;a++)if(0!==s[r+o*a]){h=p;do l=p-h,s[l+o*r]+=s[l+o*a];while(--h);break}if(0!==s[r+o*r])for(a=r+1;a<u;a++){var d=s[r+o*a]/s[r+o*r];h=p;do l=p-h,s[l+o*a]=l<=r?0:s[l+o*a]-s[l+o*r]*d;while(--h)}}while(--c);if(e.z=s[2*o+3]/s[2*o+2],e.y=(s[1*o+3]-s[1*o+2]*e.z)/s[1*o+1],e.x=(s[0*o+3]-s[0*o+2]*e.z-s[0*o+1]*e.y)/s[0*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},o.prototype.e=function(t,e,i){return void 0===i?this.elements[e+3*t]:void(this.elements[e+3*t]=i)},o.prototype.copy=function(t){for(var e=0;e<t.elements.length;e++)this.elements[e]=t.elements[e];return this},o.prototype.toString=function(){for(var t="",e=",",i=0;i<9;i++)t+=this.elements[i]+e;return t},o.prototype.reverse=function(t){t=t||new o;for(var e=3,i=6,n=[],s=0;s<e*i;s++)n.push(0);var s,r;for(s=0;s<3;s++)for(r=0;r<3;r++)n[s+i*r]=this.elements[s+3*r];n[3]=1,n[9]=0,n[15]=0,n[4]=0,n[10]=1,n[16]=0,n[5]=0,n[11]=0,n[17]=1;var a,h,l=3,c=l,u=i;do{if(s=c-l,0===n[s+i*s])for(r=s+1;r<c;r++)if(0!==n[s+i*r]){a=u;do h=u-a,n[h+i*s]+=n[h+i*r];while(--a);break}if(0!==n[s+i*s])for(r=s+1;r<c;r++){var p=n[s+i*r]/n[s+i*s];a=u;do h=u-a,n[h+i*r]=h<=s?0:n[h+i*r]-n[h+i*s]*p;while(--a)}}while(--l);s=2;do{r=s-1;do{var p=n[s+i*r]/n[s+i*s];a=i;do h=i-a,n[h+i*r]=n[h+i*r]-n[h+i*s]*p;while(--a)}while(r--)}while(--s);s=2;do{var p=1/n[s+i*s];a=i;do h=i-a,n[h+i*s]=n[h+i*s]*p;while(--a)}while(s--);s=2;do{r=2;do{if(h=n[e+r+i*s],isNaN(h)||h===1/0)throw"Could not reverse! A=["+this.toString()+"]";t.e(s,r,h)}while(r--)}while(s--);return t},o.prototype.setRotationFromQuaternion=function(t){var e=t.x,i=t.y,o=t.z,n=t.w,s=e+e,r=i+i,a=o+o,h=e*s,l=e*r,c=e*a,u=i*r,p=i*a,d=o*a,y=n*s,v=n*r,f=n*a,m=this.elements;return m[0]=1-(u+d),m[1]=l-f,m[2]=c+v,m[3]=l+f,m[4]=1-(h+d),m[5]=p-y,m[6]=c-v,m[7]=p+y,m[8]=1-(h+u),this},o.prototype.transpose=function(t){t=t||new o;for(var e=t.elements,i=this.elements,n=0;3!==n;n++)for(var s=0;3!==s;s++)e[3*n+s]=i[3*s+n];return t}},{"./Vec3":74}],72:[function(t,e,i){function o(t,e,i,o){this.x=void 0!==t?t:0,this.y=void 0!==e?e:0,this.z=void 0!==i?i:0,this.w=void 0!==o?o:1}e.exports=o;var n=t("./Vec3");o.prototype.set=function(t,e,i,o){return this.x=t,this.y=e,this.z=i,this.w=o,this},o.prototype.toString=function(){return this.x+","+this.y+","+this.z+","+this.w},o.prototype.toArray=function(){return[this.x,this.y,this.z,this.w]},o.prototype.setFromAxisAngle=function(t,e){var i=Math.sin(.5*e);return this.x=t.x*i,this.y=t.y*i,this.z=t.z*i,this.w=Math.cos(.5*e),this},o.prototype.toAxisAngle=function(t){t=t||new n,this.normalize();var e=2*Math.acos(this.w),i=Math.sqrt(1-this.w*this.w);return i<.001?(t.x=this.x,t.y=this.y,t.z=this.z):(t.x=this.x/i,t.y=this.y/i,t.z=this.z/i),[t,e]};var s=new n,r=new n;o.prototype.setFromVectors=function(t,e){if(t.isAntiparallelTo(e)){var i=s,o=r;t.tangents(i,o),this.setFromAxisAngle(i,Math.PI)}else{var n=t.cross(e);this.x=n.x,this.y=n.y,this.z=n.z,this.w=Math.sqrt(Math.pow(t.norm(),2)*Math.pow(e.norm(),2))+t.dot(e),this.normalize()}return this};new n,new n,new n;o.prototype.mult=function(t,e){e=e||new o;var i=this.x,n=this.y,s=this.z,r=this.w,a=t.x,h=t.y,l=t.z,c=t.w;return e.x=i*c+r*a+n*l-s*h,e.y=n*c+r*h+s*a-i*l,e.z=s*c+r*l+i*h-n*a,e.w=r*c-i*a-n*h-s*l,e},o.prototype.inverse=function(t){var e=this.x,i=this.y,n=this.z,s=this.w;t=t||new o,this.conjugate(t);var r=1/(e*e+i*i+n*n+s*s);return t.x*=r,t.y*=r,t.z*=r,t.w*=r,t},o.prototype.conjugate=function(t){return t=t||new o,t.x=-this.x,t.y=-this.y,t.z=-this.z,t.w=this.w,t},o.prototype.normalize=function(){var t=Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w);return 0===t?(this.x=0,this.y=0,this.z=0,this.w=0):(t=1/t,this.x*=t,this.y*=t,this.z*=t,this.w*=t),this},o.prototype.normalizeFast=function(){var t=(3-(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w))/2;return 0===t?(this.x=0,this.y=0,this.z=0,this.w=0):(this.x*=t,this.y*=t,this.z*=t,this.w*=t),this},o.prototype.vmult=function(t,e){e=e||new n;var i=t.x,o=t.y,s=t.z,r=this.x,a=this.y,h=this.z,l=this.w,c=l*i+a*s-h*o,u=l*o+h*i-r*s,p=l*s+r*o-a*i,d=-r*i-a*o-h*s;return e.x=c*l+d*-r+u*-h-p*-a,e.y=u*l+d*-a+p*-r-c*-h,e.z=p*l+d*-h+c*-a-u*-r,e},o.prototype.copy=function(t){return this.x=t.x,this.y=t.y,this.z=t.z,this.w=t.w,this},o.prototype.toEuler=function(t,e){e=e||"YZX";var i,o,n,s=this.x,r=this.y,a=this.z,h=this.w;switch(e){case"YZX":var l=s*r+a*h;if(l>.499&&(i=2*Math.atan2(s,h),o=Math.PI/2,n=0),l<-.499&&(i=-2*Math.atan2(s,h),o=-Math.PI/2,n=0),isNaN(i)){var c=s*s,u=r*r,p=a*a;i=Math.atan2(2*r*h-2*s*a,1-2*u-2*p),o=Math.asin(2*l),n=Math.atan2(2*s*h-2*r*a,1-2*c-2*p)}break;default:throw new Error("Euler order "+e+" not supported yet.")}t.y=i,t.z=o,t.x=n},o.prototype.setFromEuler=function(t,e,i,o){o=o||"XYZ";var n=Math.cos(t/2),s=Math.cos(e/2),r=Math.cos(i/2),a=Math.sin(t/2),h=Math.sin(e/2),l=Math.sin(i/2);return"XYZ"===o?(this.x=a*s*r+n*h*l,this.y=n*h*r-a*s*l,this.z=n*s*l+a*h*r,this.w=n*s*r-a*h*l):"YXZ"===o?(this.x=a*s*r+n*h*l,this.y=n*h*r-a*s*l,this.z=n*s*l-a*h*r,this.w=n*s*r+a*h*l):"ZXY"===o?(this.x=a*s*r-n*h*l,this.y=n*h*r+a*s*l,this.z=n*s*l+a*h*r,this.w=n*s*r-a*h*l):"ZYX"===o?(this.x=a*s*r-n*h*l,this.y=n*h*r+a*s*l,this.z=n*s*l-a*h*r,this.w=n*s*r+a*h*l):"YZX"===o?(this.x=a*s*r+n*h*l,this.y=n*h*r+a*s*l,this.z=n*s*l-a*h*r,this.w=n*s*r-a*h*l):"XZY"===o&&(this.x=a*s*r-n*h*l,this.y=n*h*r-a*s*l,this.z=n*s*l+a*h*r,this.w=n*s*r+a*h*l),this},o.prototype.clone=function(){return new o(this.x,this.y,this.z,this.w)},o.prototype.slerp=function(t,e,i){i=i||new o;var n,s,r,a,h,l=this.x,c=this.y,u=this.z,p=this.w,d=t.x,y=t.y,v=t.z,f=t.w;return s=l*d+c*y+u*v+p*f,s<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,h=Math.sin(e*n)/r):(a=1-e,h=e),i.x=a*l+h*d,i.y=a*c+h*y,i.z=a*u+h*v,i.w=a*p+h*f,i},o.prototype.integrate=function(t,e,i,n){n=n||new o;var s=t.x*i.x,r=t.y*i.y,a=t.z*i.z,h=this.x,l=this.y,c=this.z,u=this.w,p=.5*e;return n.x+=p*(s*u+r*c-a*l),n.y+=p*(r*u+a*h-s*c),n.z+=p*(a*u+s*l-r*h),n.w+=p*(-s*h-r*l-a*c),n}},{"./Vec3":74}],73:[function(t,e,i){function o(t){t=t||{},this.position=new n,t.position&&this.position.copy(t.position),this.quaternion=new s,t.quaternion&&this.quaternion.copy(t.quaternion)}var n=t("./Vec3"),s=t("./Quaternion");e.exports=o;var r=new s;o.pointToLocalFrame=function(t,e,i,o){var o=o||new n;return i.vsub(t,o),e.conjugate(r),r.vmult(o,o),o},o.prototype.pointToLocal=function(t,e){return o.pointToLocalFrame(this.position,this.quaternion,t,e)},o.pointToWorldFrame=function(t,e,i,o){var o=o||new n;return e.vmult(i,o),o.vadd(t,o),o},o.prototype.pointToWorld=function(t,e){return o.pointToWorldFrame(this.position,this.quaternion,t,e)},o.prototype.vectorToWorldFrame=function(t,e){var e=e||new n;return this.quaternion.vmult(t,e),e},o.vectorToWorldFrame=function(t,e,i){return t.vmult(e,i),i},o.vectorToLocalFrame=function(t,e,i,o){var o=o||new n;return e.w*=-1,e.vmult(i,o),e.w*=-1,o}},{"./Quaternion":72,"./Vec3":74}],74:[function(t,e,i){function o(t,e,i){this.x=t||0,this.y=e||0,this.z=i||0}e.exports=o;var n=t("./Mat3");o.ZERO=new o(0,0,0),o.UNIT_X=new o(1,0,0),o.UNIT_Y=new o(0,1,0),o.UNIT_Z=new o(0,0,1),o.prototype.cross=function(t,e){var i=t.x,n=t.y,s=t.z,r=this.x,a=this.y,h=this.z;return e=e||new o,e.x=a*s-h*n,e.y=h*i-r*s,e.z=r*n-a*i,e},o.prototype.set=function(t,e,i){return this.x=t,this.y=e,this.z=i,this},o.prototype.setZero=function(){this.x=this.y=this.z=0},o.prototype.vadd=function(t,e){return e?(e.x=t.x+this.x,e.y=t.y+this.y,e.z=t.z+this.z,void 0):new o(this.x+t.x,this.y+t.y,this.z+t.z)},o.prototype.vsub=function(t,e){return e?(e.x=this.x-t.x,e.y=this.y-t.y,e.z=this.z-t.z,void 0):new o(this.x-t.x,this.y-t.y,this.z-t.z)},o.prototype.crossmat=function(){return new n([0,-this.z,this.y,this.z,0,-this.x,-this.y,this.x,0])},o.prototype.normalize=function(){var t=this.x,e=this.y,i=this.z,o=Math.sqrt(t*t+e*e+i*i);if(o>0){var n=1/o;this.x*=n,this.y*=n,this.z*=n}else this.x=0,this.y=0,this.z=0;return o},o.prototype.unit=function(t){t=t||new o;var e=this.x,i=this.y,n=this.z,s=Math.sqrt(e*e+i*i+n*n);return s>0?(s=1/s,t.x=e*s,t.y=i*s,t.z=n*s):(t.x=1,t.y=0,t.z=0),t},o.prototype.norm=function(){var t=this.x,e=this.y,i=this.z;return Math.sqrt(t*t+e*e+i*i)},o.prototype.length=o.prototype.norm,o.prototype.norm2=function(){return this.dot(this)},o.prototype.lengthSquared=o.prototype.norm2,o.prototype.distanceTo=function(t){var e=this.x,i=this.y,o=this.z,n=t.x,s=t.y,r=t.z;return Math.sqrt((n-e)*(n-e)+(s-i)*(s-i)+(r-o)*(r-o))},o.prototype.distanceSquared=function(t){var e=this.x,i=this.y,o=this.z,n=t.x,s=t.y,r=t.z;return(n-e)*(n-e)+(s-i)*(s-i)+(r-o)*(r-o)},o.prototype.mult=function(t,e){e=e||new o;var i=this.x,n=this.y,s=this.z;return e.x=t*i,e.y=t*n,e.z=t*s,e},o.prototype.vmul=function(t,e){return e=e||new o,e.x=t.x*this.x,e.y=t.y*this.y,e.z=t.z*this.z,e},o.prototype.scale=o.prototype.mult,o.prototype.addScaledVector=function(t,e,i){return i=i||new o,i.x=this.x+t*e.x,i.y=this.y+t*e.y,i.z=this.z+t*e.z,i},o.prototype.dot=function(t){return this.x*t.x+this.y*t.y+this.z*t.z},o.prototype.isZero=function(){return 0===this.x&&0===this.y&&0===this.z},o.prototype.negate=function(t){return t=t||new o,t.x=-this.x,t.y=-this.y,t.z=-this.z,t};var s=new o,r=new o;o.prototype.tangents=function(t,e){var i=this.norm();if(i>0){var o=s,n=1/i;o.set(this.x*n,this.y*n,this.z*n);var a=r;Math.abs(o.x)<.9?(a.set(1,0,0),o.cross(a,t)):(a.set(0,1,0),o.cross(a,t)),o.cross(t,e)}else t.set(1,0,0),e.set(0,1,0)},o.prototype.toString=function(){return this.x+","+this.y+","+this.z},o.prototype.toArray=function(){return[this.x,this.y,this.z]},o.prototype.copy=function(t){return this.x=t.x,this.y=t.y,this.z=t.z,this},o.prototype.lerp=function(t,e,i){var o=this.x,n=this.y,s=this.z;i.x=o+(t.x-o)*e,i.y=n+(t.y-n)*e,i.z=s+(t.z-s)*e},o.prototype.almostEquals=function(t,e){return void 0===e&&(e=1e-6),!(Math.abs(this.x-t.x)>e||Math.abs(this.y-t.y)>e||Math.abs(this.z-t.z)>e)},o.prototype.almostZero=function(t){return void 0===t&&(t=1e-6),!(Math.abs(this.x)>t||Math.abs(this.y)>t||Math.abs(this.z)>t)};var a=new o;o.prototype.isAntiparallelTo=function(t,e){return this.negate(a),a.almostEquals(t,e)},o.prototype.clone=function(){return new o(this.x,this.y,this.z)}},{"./Mat3":71}],75:[function(t,e,i){function o(t){t=t||{},n.apply(this),this.id=o.idCounter++,this.world=null,this.preStep=null,this.postStep=null,this.vlambda=new s,this.collisionFilterGroup="number"==typeof t.collisionFilterGroup?t.collisionFilterGroup:1,this.collisionFilterMask="number"==typeof t.collisionFilterMask?t.collisionFilterMask:-1,this.collisionResponse=!0,this.position=new s,this.previousPosition=new s,this.interpolatedPosition=new s,this.initPosition=new s,t.position&&(this.position.copy(t.position),this.previousPosition.copy(t.position),this.interpolatedPosition.copy(t.position),this.initPosition.copy(t.position)),this.velocity=new s,t.velocity&&this.velocity.copy(t.velocity),this.initVelocity=new s,this.force=new s;var e="number"==typeof t.mass?t.mass:0;this.mass=e,this.invMass=e>0?1/e:0,this.material=t.material||null,this.linearDamping="number"==typeof t.linearDamping?t.linearDamping:.01,this.type=e<=0?o.STATIC:o.DYNAMIC,typeof t.type==typeof o.STATIC&&(this.type=t.type),this.allowSleep="undefined"==typeof t.allowSleep||t.allowSleep,this.sleepState=0,this.sleepSpeedLimit="undefined"!=typeof t.sleepSpeedLimit?t.sleepSpeedLimit:.1,this.sleepTimeLimit="undefined"!=typeof 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="undefined"!=typeof t.fixedRotation&&t.fixedRotation,this.angularDamping="undefined"!=typeof t.angularDamping?t.angularDamping:.01,this.linearFactor=new s(1,1,1),t.linearFactor&&this.linearFactor.copy(t.linearFactor),this.angularFactor=new s(1,1,1),t.angularFactor&&this.angularFactor.copy(t.angularFactor),this.aabb=new h,this.aabbNeedsUpdate=!0,this.boundingRadius=0,this.wlambda=new s,t.shape&&this.addShape(t.shape),this.updateMassProperties()}e.exports=o;var n=t("../utils/EventTarget"),s=(t("../shapes/Shape"),t("../math/Vec3")),r=t("../math/Mat3"),a=t("../math/Quaternion"),h=(t("../material/Material"),t("../collision/AABB")),l=t("../shapes/Box");o.prototype=new n,o.prototype.constructor=o,o.COLLIDE_EVENT_NAME="collide",o.DYNAMIC=1,o.STATIC=2,o.KINEMATIC=4,o.AWAKE=0,o.SLEEPY=1,o.SLEEPING=2,o.idCounter=0,o.wakeupEvent={type:"wakeup"},o.prototype.wakeUp=function(){var t=this.sleepState;this.sleepState=0,this._wakeUpAfterNarrowphase=!1,t===o.SLEEPING&&this.dispatchEvent(o.wakeupEvent)},o.prototype.sleep=function(){this.sleepState=o.SLEEPING,this.velocity.set(0,0,0),this.angularVelocity.set(0,0,0),this._wakeUpAfterNarrowphase=!1},o.sleepyEvent={type:"sleepy"},o.sleepEvent={type:"sleep"},o.prototype.sleepTick=function(t){if(this.allowSleep){var e=this.sleepState,i=this.velocity.norm2()+this.angularVelocity.norm2(),n=Math.pow(this.sleepSpeedLimit,2);e===o.AWAKE&&i<n?(this.sleepState=o.SLEEPY,this.timeLastSleepy=t,this.dispatchEvent(o.sleepyEvent)):e===o.SLEEPY&&i>n?this.wakeUp():e===o.SLEEPY&&t-this.timeLastSleepy>this.sleepTimeLimit&&(this.sleep(),this.dispatchEvent(o.sleepEvent))}},o.prototype.updateSolveMassProperties=function(){this.sleepState===o.SLEEPING||this.type===o.KINEMATIC?(this.invMassSolve=0,this.invInertiaSolve.setZero(),this.invInertiaWorldSolve.setZero()):(this.invMassSolve=this.invMass,this.invInertiaSolve.copy(this.invInertia),this.invInertiaWorldSolve.copy(this.invInertiaWorld))},o.prototype.pointToLocalFrame=function(t,e){var e=e||new s;return t.vsub(this.position,e),this.quaternion.conjugate().vmult(e,e),e},o.prototype.vectorToLocalFrame=function(t,e){var e=e||new s;return this.quaternion.conjugate().vmult(t,e),e},o.prototype.pointToWorldFrame=function(t,e){var e=e||new s;return this.quaternion.vmult(t,e),e.vadd(this.position,e),e},o.prototype.vectorToWorldFrame=function(t,e){var e=e||new s;return this.quaternion.vmult(t,e),e};var c=new s,u=new a;o.prototype.addShape=function(t,e,i){var o=new s,n=new a;return e&&o.copy(e),i&&n.copy(i),this.shapes.push(t),this.shapeOffsets.push(o),this.shapeOrientations.push(n),this.updateMassProperties(),this.updateBoundingRadius(),this.aabbNeedsUpdate=!0,t.body=this,this},o.prototype.updateBoundingRadius=function(){for(var t=this.shapes,e=this.shapeOffsets,i=t.length,o=0,n=0;n!==i;n++){var s=t[n];s.updateBoundingSphereRadius();var r=e[n].norm(),a=s.boundingSphereRadius;r+a>o&&(o=r+a)}this.boundingRadius=o};var p=new h;o.prototype.computeAABB=function(){for(var t=this.shapes,e=this.shapeOffsets,i=this.shapeOrientations,o=t.length,n=c,s=u,r=this.quaternion,a=this.aabb,h=p,l=0;l!==o;l++){var d=t[l];r.vmult(e[l],n),n.vadd(this.position,n),i[l].mult(r,s),d.calculateWorldAABB(n,s,h.lowerBound,h.upperBound),0===l?a.copy(h):a.extend(h)}this.aabbNeedsUpdate=!1};var d=new r,y=new r;new r;o.prototype.updateInertiaWorld=function(t){var e=this.invInertia;if(e.x!==e.y||e.y!==e.z||t){var i=d,o=y;i.setRotationFromQuaternion(this.quaternion),i.transpose(o),i.scale(e,i),i.mmult(o,this.invInertiaWorld)}else;};var v=(new s,new s);o.prototype.applyForce=function(t,e){if(this.type===o.DYNAMIC){var i=v;e.cross(t,i),this.force.vadd(t,this.force),this.torque.vadd(i,this.torque)}};var f=new s,m=new s;o.prototype.applyLocalForce=function(t,e){if(this.type===o.DYNAMIC){var i=f,n=m;this.vectorToWorldFrame(t,i),this.vectorToWorldFrame(e,n),this.applyForce(i,n)}};var g=(new s,new s),w=new s;o.prototype.applyImpulse=function(t,e){if(this.type===o.DYNAMIC){var i=e,n=g;n.copy(t),n.mult(this.invMass,n),this.velocity.vadd(n,this.velocity);var s=w;i.cross(t,s),this.invInertiaWorld.vmult(s,s),this.angularVelocity.vadd(s,this.angularVelocity)}};var b=new s,x=new s;o.prototype.applyLocalImpulse=function(t,e){if(this.type===o.DYNAMIC){var i=b,n=x;this.vectorToWorldFrame(t,i),this.vectorToWorldFrame(e,n),this.applyImpulse(i,n)}};var E=new s;o.prototype.updateMassProperties=function(){var t=E;this.invMass=this.mass>0?1/this.mass:0;var e=this.inertia,i=this.fixedRotation;this.computeAABB(),t.set((this.aabb.upperBound.x-this.aabb.lowerBound.x)/2,(this.aabb.upperBound.y-this.aabb.lowerBound.y)/2,(this.aabb.upperBound.z-this.aabb.lowerBound.z)/2),l.calculateInertia(t,this.mass,e),this.invInertia.set(e.x>0&&!i?1/e.x:0,e.y>0&&!i?1/e.y:0,e.z>0&&!i?1/e.z:0),this.updateInertiaWorld(!0)},o.prototype.getVelocityAtWorldPoint=function(t,e){var i=new s;return t.vsub(this.position,i),this.angularVelocity.cross(i,e),this.velocity.vadd(e,e),e};new s,new s,new a,new a;o.prototype.integrate=function(t,e,i){if(this.previousPosition.copy(this.position),this.previousQuaternion.copy(this.quaternion),(this.type===o.DYNAMIC||this.type===o.KINEMATIC)&&this.sleepState!==o.SLEEPING){var n=this.velocity,s=this.angularVelocity,r=this.position,a=this.force,h=this.torque,l=this.quaternion,c=this.invMass,u=this.invInertiaWorld,p=this.linearFactor,d=c*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=h.x*v.x,m=h.y*v.y,g=h.z*v.z;s.x+=t*(y[0]*f+y[1]*m+y[2]*g),s.y+=t*(y[3]*f+y[4]*m+y[5]*g),s.z+=t*(y[6]*f+y[7]*m+y[8]*g),r.x+=n.x*t,r.y+=n.y*t,r.z+=n.z*t,l.integrate(this.angularVelocity,t,this.angularFactor,l),e&&(i?l.normalizeFast():l.normalize()),this.aabbNeedsUpdate=!0,this.updateInertiaWorld()}}},{"../collision/AABB":46,"../material/Material":69,"../math/Mat3":71,"../math/Quaternion":72,"../math/Vec3":74,"../shapes/Box":81,"../shapes/Shape":87,"../utils/EventTarget":93}],76:[function(t,e,i){function o(t){this.chassisBody=t.chassisBody,this.wheelInfos=[],this.sliding=!1,this.world=null,this.indexRightAxis="undefined"!=typeof t.indexRightAxis?t.indexRightAxis:1,this.indexForwardAxis="undefined"!=typeof t.indexForwardAxis?t.indexForwardAxis:0,this.indexUpAxis="undefined"!=typeof t.indexUpAxis?t.indexUpAxis:2}function n(t,e,i,o,n){var r=0,a=i,h=x,l=E,c=A;t.getVelocityAtWorldPoint(a,h),e.getVelocityAtWorldPoint(a,l),h.vsub(l,c);var u=o.dot(c),p=s(t,i,o),d=s(e,i,o),y=1,v=y/(p+d);return r=-u*v,n<r&&(r=n),r<-n&&(r=-n),r}function s(t,e,i){var o=C,n=B,s=S,r=R;return e.vsub(t.position,o),o.cross(i,n),
t.invInertiaWorld.vmult(n,r),r.cross(o,s),t.invMass+i.dot(s)}function r(t,e,i,o,n,s){var r=n.norm2();if(r>1.1)return 0;var a=M,h=T,l=z;t.getVelocityAtWorldPoint(e,a),i.getVelocityAtWorldPoint(o,h),a.vsub(h,l);var c=n.dot(l),u=.2,p=1/(t.invMass+i.invMass),s=-u*c*p;return s}var a=(t("./Body"),t("../math/Vec3")),h=t("../math/Quaternion"),l=(t("../collision/RaycastResult"),t("../collision/Ray")),c=t("../objects/WheelInfo");e.exports=o;var u=(new a,new a,new a,new a),p=new a,d=new a;new l;o.prototype.addWheel=function(t){t=t||{};var e=new c(t),i=this.wheelInfos.length;return this.wheelInfos.push(e),i},o.prototype.setSteeringValue=function(t,e){var i=this.wheelInfos[e];i.steering=t};new a;o.prototype.applyEngineForce=function(t,e){this.wheelInfos[e].engineForce=t},o.prototype.setBrake=function(t,e){this.wheelInfos[e].brake=t},o.prototype.addToWorld=function(t){this.constraints;t.addBody(this.chassisBody);var e=this;this.preStepCallback=function(){e.updateVehicle(t.dt)},t.addEventListener("preStep",this.preStepCallback),this.world=t},o.prototype.getVehicleAxisWorld=function(t,e){e.set(0===t?1:0,1===t?1:0,2===t?1:0),this.chassisBody.vectorToWorldFrame(e,e)},o.prototype.updateVehicle=function(t){for(var e=this.wheelInfos,i=e.length,o=this.chassisBody,n=0;n<i;n++)this.updateWheelTransform(n);this.currentVehicleSpeedKmHour=3.6*o.velocity.norm();var s=new a;this.getVehicleAxisWorld(this.indexForwardAxis,s),s.dot(o.velocity)<0&&(this.currentVehicleSpeedKmHour*=-1);for(var n=0;n<i;n++)this.castRay(e[n]);this.updateSuspension(t);for(var r=new a,h=new a,n=0;n<i;n++){var l=e[n],c=l.suspensionForce;c>l.maxSuspensionForce&&(c=l.maxSuspensionForce),l.raycastResult.hitNormalWorld.scale(c*t,r),l.raycastResult.hitPointWorld.vsub(o.position,h),o.applyImpulse(r,h)}this.updateFriction(t);var u=new a,p=new a,d=new a;for(n=0;n<i;n++){var l=e[n];o.getVelocityAtWorldPoint(l.chassisConnectionPointWorld,d);var y=1;switch(this.indexUpAxis){case 1:y=-1}if(l.isInContact){this.getVehicleAxisWorld(this.indexForwardAxis,p);var v=p.dot(l.raycastResult.hitNormalWorld);l.raycastResult.hitNormalWorld.scale(v,u),p.vsub(u,p);var f=p.dot(d);l.deltaRotation=y*f*t/l.radius}!l.sliding&&l.isInContact||0===l.engineForce||!l.useCustomSlidingRotationalSpeed||(l.deltaRotation=(l.engineForce>0?1:-1)*l.customSlidingRotationalSpeed*t),Math.abs(l.brake)>Math.abs(l.engineForce)&&(l.deltaRotation=0),l.rotation+=l.deltaRotation,l.deltaRotation*=.99}},o.prototype.updateSuspension=function(t){for(var e=this.chassisBody,i=e.mass,o=this.wheelInfos,n=o.length,s=0;s<n;s++){var r=o[s];if(r.isInContact){var a,h=r.suspensionRestLength,l=r.suspensionLength,c=h-l;a=r.suspensionStiffness*c*r.clippedInvContactDotSuspension;var u,p=r.suspensionRelativeVelocity;u=p<0?r.dampingCompression:r.dampingRelaxation,a-=u*p,r.suspensionForce=a*i,r.suspensionForce<0&&(r.suspensionForce=0)}else r.suspensionForce=0}},o.prototype.removeFromWorld=function(t){this.constraints;t.remove(this.chassisBody),t.removeEventListener("preStep",this.preStepCallback),this.world=null};var y=new a,v=new a;o.prototype.castRay=function(t){var e=y,i=v;this.updateWheelTransformWorld(t);var o=this.chassisBody,n=-1,s=t.suspensionRestLength+t.radius;t.directionWorld.scale(s,e);var r=t.chassisConnectionPointWorld;r.vadd(e,i);var h=t.raycastResult;h.reset();var l=o.collisionResponse;o.collisionResponse=!1,this.world.rayTest(r,i,h),o.collisionResponse=l;var c=h.body;if(t.raycastResult.groundObject=0,c){n=h.distance,t.raycastResult.hitNormalWorld=h.hitNormalWorld,t.isInContact=!0;var u=h.distance;t.suspensionLength=u-t.radius;var p=t.suspensionRestLength-t.maxSuspensionTravel,d=t.suspensionRestLength+t.maxSuspensionTravel;t.suspensionLength<p&&(t.suspensionLength=p),t.suspensionLength>d&&(t.suspensionLength=d,t.raycastResult.reset());var f=t.raycastResult.hitNormalWorld.dot(t.directionWorld),m=new a;o.getVelocityAtWorldPoint(t.raycastResult.hitPointWorld,m);var g=t.raycastResult.hitNormalWorld.dot(m);if(f>=-.1)t.suspensionRelativeVelocity=0,t.clippedInvContactDotSuspension=10;else{var w=-1/f;t.suspensionRelativeVelocity=g*w,t.clippedInvContactDotSuspension=w}}else t.suspensionLength=t.suspensionRestLength+0*t.maxSuspensionTravel,t.suspensionRelativeVelocity=0,t.directionWorld.scale(-1,t.raycastResult.hitNormalWorld),t.clippedInvContactDotSuspension=1;return n},o.prototype.updateWheelTransformWorld=function(t){t.isInContact=!1;var e=this.chassisBody;e.pointToWorldFrame(t.chassisConnectionPointLocal,t.chassisConnectionPointWorld),e.vectorToWorldFrame(t.directionLocal,t.directionWorld),e.vectorToWorldFrame(t.axleLocal,t.axleWorld)},o.prototype.updateWheelTransform=function(t){var e=u,i=p,o=d,n=this.wheelInfos[t];this.updateWheelTransformWorld(n),n.directionLocal.scale(-1,e),i.copy(n.axleLocal),e.cross(i,o),o.normalize(),i.normalize();var s=n.steering,r=new h;r.setFromAxisAngle(e,s);var a=new h;a.setFromAxisAngle(i,n.rotation);var l=n.worldTransform.quaternion;this.chassisBody.quaternion.mult(r,l),l.mult(a,l),l.normalize();var c=n.worldTransform.position;c.copy(n.directionWorld),c.scale(n.suspensionLength,c),c.vadd(n.chassisConnectionPointWorld,c)};var f=[new a(1,0,0),new a(0,1,0),new a(0,0,1)];o.prototype.getWheelTransformWorld=function(t){return this.wheelInfos[t].worldTransform};var m=new a,g=[],w=[],b=1;o.prototype.updateFriction=function(t){for(var e=m,i=this.wheelInfos,o=i.length,s=this.chassisBody,h=w,l=g,c=0,u=0;u<o;u++){var p=i[u],d=p.raycastResult.body;d&&c++,p.sideImpulse=0,p.forwardImpulse=0,h[u]||(h[u]=new a),l[u]||(l[u]=new a)}for(var u=0;u<o;u++){var p=i[u],d=p.raycastResult.body;if(d){var y=l[u],v=this.getWheelTransformWorld(u);v.vectorToWorldFrame(f[this.indexRightAxis],y);var x=p.raycastResult.hitNormalWorld,E=y.dot(x);x.scale(E,e),y.vsub(e,y),y.normalize(),x.cross(y,h[u]),h[u].normalize(),p.sideImpulse=r(s,p.raycastResult.hitPointWorld,d,p.raycastResult.hitPointWorld,y),p.sideImpulse*=b}}var A=1,C=.5;this.sliding=!1;for(var u=0;u<o;u++){var p=i[u],d=p.raycastResult.body,B=0;if(p.slipInfo=1,d){var S=0,R=p.brake?p.brake:S;B=n(s,d,p.raycastResult.hitPointWorld,h[u],R),B+=p.engineForce*t;var M=R/B;p.slipInfo*=M}if(p.forwardImpulse=0,p.skidInfo=1,d){p.skidInfo=1;var T=p.suspensionForce*t*p.frictionSlip,z=T,k=T*z;p.forwardImpulse=B;var L=p.forwardImpulse*C,P=p.sideImpulse*A,q=L*L+P*P;if(p.sliding=!1,q>k){this.sliding=!0,p.sliding=!0;var M=T/Math.sqrt(q);p.skidInfo*=M}}}if(this.sliding)for(var u=0;u<o;u++){var p=i[u];0!==p.sideImpulse&&p.skidInfo<1&&(p.forwardImpulse*=p.skidInfo,p.sideImpulse*=p.skidInfo)}for(var u=0;u<o;u++){var p=i[u],F=new a;if(p.raycastResult.hitPointWorld.vsub(s.position,F),0!==p.forwardImpulse){var V=new a;h[u].scale(p.forwardImpulse,V),s.applyImpulse(V,F)}if(0!==p.sideImpulse){var d=p.raycastResult.body,N=new a;p.raycastResult.hitPointWorld.vsub(d.position,N);var I=new a;l[u].scale(p.sideImpulse,I),s.vectorToLocalFrame(F,F),F["xyz"[this.indexUpAxis]]*=p.rollInfluence,s.vectorToWorldFrame(F,F),s.applyImpulse(I,F),I.scale(-1,I),d.applyImpulse(I,N)}}};var x=new a,E=new a,A=new a,C=new a,B=new a,S=new a,R=new a,M=new a,T=new a,z=new a},{"../collision/Ray":53,"../collision/RaycastResult":54,"../math/Quaternion":72,"../math/Vec3":74,"../objects/WheelInfo":80,"./Body":75}],77:[function(t,e,i){function o(t){if(this.wheelBodies=[],this.coordinateSystem="undefined"==typeof t.coordinateSystem?new a(1,2,3):t.coordinateSystem.clone(),this.chassisBody=t.chassisBody,!this.chassisBody){var e=new r(new a(5,2,.5));this.chassisBody=new n(1,e)}this.constraints=[],this.wheelAxes=[],this.wheelForces=[]}var n=t("./Body"),s=t("../shapes/Sphere"),r=t("../shapes/Box"),a=t("../math/Vec3"),h=t("../constraints/HingeConstraint");e.exports=o,o.prototype.addWheel=function(t){t=t||{};var e=t.body;e||(e=new n(1,new s(1.2))),this.wheelBodies.push(e),this.wheelForces.push(0);var i=(new a,"undefined"!=typeof t.position?t.position.clone():new a),o=new a;this.chassisBody.pointToWorldFrame(i,o),e.position.set(o.x,o.y,o.z);var r="undefined"!=typeof t.axis?t.axis.clone():new a(0,1,0);this.wheelAxes.push(r);var l=new h(this.chassisBody,e,{pivotA:i,axisA:r,pivotB:a.ZERO,axisB:r,collideConnected:!1});return this.constraints.push(l),this.wheelBodies.length-1},o.prototype.setSteeringValue=function(t,e){var i=this.wheelAxes[e],o=Math.cos(t),n=Math.sin(t),s=i.x,r=i.y;this.constraints[e].axisA.set(o*s-n*r,n*s+o*r,0)},o.prototype.setMotorSpeed=function(t,e){var i=this.constraints[e];i.enableMotor(),i.motorTargetVelocity=t},o.prototype.disableMotor=function(t){var e=this.constraints[t];e.disableMotor()};var l=new a;o.prototype.setWheelForce=function(t,e){this.wheelForces[e]=t},o.prototype.applyWheelForce=function(t,e){var i=this.wheelAxes[e],o=this.wheelBodies[e],n=o.torque;i.scale(t,l),o.vectorToWorldFrame(l,l),n.vadd(l,n)},o.prototype.addToWorld=function(t){for(var e=this.constraints,i=this.wheelBodies.concat([this.chassisBody]),o=0;o<i.length;o++)t.addBody(i[o]);for(var o=0;o<e.length;o++)t.addConstraint(e[o]);t.addEventListener("preStep",this._update.bind(this))},o.prototype._update=function(){for(var t=this.wheelForces,e=0;e<t.length;e++)this.applyWheelForce(t[e],e)},o.prototype.removeFromWorld=function(t){for(var e=this.constraints,i=this.wheelBodies.concat([this.chassisBody]),o=0;o<i.length;o++)t.remove(i[o]);for(var o=0;o<e.length;o++)t.removeConstraint(e[o])};var c=new a;o.prototype.getWheelSpeed=function(t){var e=this.wheelAxes[t],i=this.wheelBodies[t],o=i.angularVelocity;return this.chassisBody.vectorToWorldFrame(e,c),o.dot(c)}},{"../constraints/HingeConstraint":59,"../math/Vec3":74,"../shapes/Box":81,"../shapes/Sphere":88,"./Body":75}],78:[function(t,e,i){function o(){this.particles=[],this.density=1,this.smoothingRadius=1,this.speedOfSound=1,this.viscosity=.01,this.eps=1e-6,this.pressures=[],this.densities=[],this.neighbors=[]}e.exports=o;var n=(t("../shapes/Shape"),t("../math/Vec3"));t("../math/Quaternion"),t("../shapes/Particle"),t("../objects/Body"),t("../material/Material");o.prototype.add=function(t){this.particles.push(t),this.neighbors.length<this.particles.length&&this.neighbors.push([])},o.prototype.remove=function(t){var e=this.particles.indexOf(t);e!==-1&&(this.particles.splice(e,1),this.neighbors.length>this.particles.length&&this.neighbors.pop())};var s=new n;o.prototype.getNeighbors=function(t,e){for(var i=this.particles.length,o=t.id,n=this.smoothingRadius*this.smoothingRadius,r=s,a=0;a!==i;a++){var h=this.particles[a];h.position.vsub(t.position,r),o!==h.id&&r.norm2()<n&&e.push(h)}};var r=new n,a=new n,h=new n,l=new n,c=new n,u=new n;o.prototype.update=function(){for(var t=this.particles.length,e=r,i=this.speedOfSound,o=this.eps,n=0;n!==t;n++){var s=this.particles[n],p=this.neighbors[n];p.length=0,this.getNeighbors(s,p),p.push(this.particles[n]);for(var d=p.length,y=0,v=0;v!==d;v++){s.position.vsub(p[v].position,e);var f=e.norm(),m=this.w(f);y+=p[v].mass*m}this.densities[n]=y,this.pressures[n]=i*i*(this.densities[n]-this.density)}for(var g=a,w=h,b=l,x=c,E=u,n=0;n!==t;n++){var A=this.particles[n];g.set(0,0,0),w.set(0,0,0);for(var C,B,p=this.neighbors[n],d=p.length,v=0;v!==d;v++){var S=p[v];A.position.vsub(S.position,x);var R=x.norm();C=-S.mass*(this.pressures[n]/(this.densities[n]*this.densities[n]+o)+this.pressures[v]/(this.densities[v]*this.densities[v]+o)),this.gradw(x,b),b.mult(C,b),g.vadd(b,g),S.velocity.vsub(A.velocity,E),E.mult(1/(1e-4+this.densities[n]*this.densities[v])*this.viscosity*S.mass,E),B=this.nablaw(R),E.mult(B,E),w.vadd(E,w)}w.mult(A.mass,w),g.mult(A.mass,g),A.force.vadd(w,A.force),A.force.vadd(g,A.force)}},o.prototype.w=function(t){var e=this.smoothingRadius;return 315/(64*Math.PI*Math.pow(e,9))*Math.pow(e*e-t*t,3)},o.prototype.gradw=function(t,e){var i=t.norm(),o=this.smoothingRadius;t.mult(945/(32*Math.PI*Math.pow(o,9))*Math.pow(o*o-i*i,2),e)},o.prototype.nablaw=function(t){var e=this.smoothingRadius,i=945/(32*Math.PI*Math.pow(e,9))*(e*e-t*t)*(7*t*t-3*e*e);return i}},{"../material/Material":69,"../math/Quaternion":72,"../math/Vec3":74,"../objects/Body":75,"../shapes/Particle":85,"../shapes/Shape":87}],79:[function(t,e,i){function o(t,e,i){i=i||{},this.restLength="number"==typeof i.restLength?i.restLength:1,this.stiffness=i.stiffness||100,this.damping=i.damping||1,this.bodyA=t,this.bodyB=e,this.localAnchorA=new n,this.localAnchorB=new n,i.localAnchorA&&this.localAnchorA.copy(i.localAnchorA),i.localAnchorB&&this.localAnchorB.copy(i.localAnchorB),i.worldAnchorA&&this.setWorldAnchorA(i.worldAnchorA),i.worldAnchorB&&this.setWorldAnchorB(i.worldAnchorB)}var n=t("../math/Vec3");e.exports=o,o.prototype.setWorldAnchorA=function(t){this.bodyA.pointToLocalFrame(t,this.localAnchorA)},o.prototype.setWorldAnchorB=function(t){this.bodyB.pointToLocalFrame(t,this.localAnchorB)},o.prototype.getWorldAnchorA=function(t){this.bodyA.pointToWorldFrame(this.localAnchorA,t)},o.prototype.getWorldAnchorB=function(t){this.bodyB.pointToWorldFrame(this.localAnchorB,t)};var s=new n,r=new n,a=new n,h=new n,l=new n,c=new n,u=new n,p=new n,d=new n,y=new n,v=new n;o.prototype.applyForce=function(){var t=this.stiffness,e=this.damping,i=this.restLength,o=this.bodyA,n=this.bodyB,f=s,m=r,g=a,w=h,b=v,x=l,E=c,A=u,C=p,B=d,S=y;this.getWorldAnchorA(x),this.getWorldAnchorB(E),x.vsub(o.position,A),E.vsub(n.position,C),E.vsub(x,f);var R=f.norm();m.copy(f),m.normalize(),n.velocity.vsub(o.velocity,g),n.angularVelocity.cross(C,b),g.vadd(b,g),o.angularVelocity.cross(A,b),g.vsub(b,g),m.mult(-t*(R-i)-e*g.dot(m),w),o.force.vsub(w,o.force),n.force.vadd(w,n.force),A.cross(w,B),C.cross(w,S),o.torque.vsub(B,o.torque),n.torque.vadd(S,n.torque)}},{"../math/Vec3":74}],80:[function(t,e,i){function o(t){t=a.defaults(t,{chassisConnectionPointLocal:new n,chassisConnectionPointWorld:new n,directionLocal:new n,directionWorld:new n,axleLocal:new n,axleWorld:new n,suspensionRestLength:1,suspensionMaxLength:2,radius:1,suspensionStiffness:100,dampingCompression:10,dampingRelaxation:10,frictionSlip:1e4,steering:0,rotation:0,deltaRotation:0,rollInfluence:.01,maxSuspensionForce:Number.MAX_VALUE,isFrontWheel:!0,clippedInvContactDotSuspension:1,suspensionRelativeVelocity:0,suspensionForce:0,skidInfo:0,suspensionLength:0,maxSuspensionTravel:1,useCustomSlidingRotationalSpeed:!1,customSlidingRotationalSpeed:-.1}),this.maxSuspensionTravel=t.maxSuspensionTravel,this.customSlidingRotationalSpeed=t.customSlidingRotationalSpeed,this.useCustomSlidingRotationalSpeed=t.useCustomSlidingRotationalSpeed,this.sliding=!1,this.chassisConnectionPointLocal=t.chassisConnectionPointLocal.clone(),this.chassisConnectionPointWorld=t.chassisConnectionPointWorld.clone(),this.directionLocal=t.directionLocal.clone(),this.directionWorld=t.directionWorld.clone(),this.axleLocal=t.axleLocal.clone(),this.axleWorld=t.axleWorld.clone(),this.suspensionRestLength=t.suspensionRestLength,this.suspensionMaxLength=t.suspensionMaxLength,this.radius=t.radius,this.suspensionStiffness=t.suspensionStiffness,this.dampingCompression=t.dampingCompression,this.dampingRelaxation=t.dampingRelaxation,this.frictionSlip=t.frictionSlip,this.steering=0,this.rotation=0,this.deltaRotation=0,this.rollInfluence=t.rollInfluence,this.maxSuspensionForce=t.maxSuspensionForce,this.engineForce=0,this.brake=0,this.isFrontWheel=t.isFrontWheel,this.clippedInvContactDotSuspension=1,this.suspensionRelativeVelocity=0,this.suspensionForce=0,this.skidInfo=0,this.suspensionLength=0,this.sideImpulse=0,this.forwardImpulse=0,this.raycastResult=new r,this.worldTransform=new s,this.isInContact=!1}var n=t("../math/Vec3"),s=t("../math/Transform"),r=t("../collision/RaycastResult"),a=t("../utils/Utils");e.exports=o;var h=new n,l=new n,h=new n;o.prototype.updateWheel=function(t){var e=this.raycastResult;if(this.isInContact){var i=e.hitNormalWorld.dot(e.directionWorld);e.hitPointWorld.vsub(t.position,l),t.getVelocityAtWorldPoint(l,h);var o=e.hitNormalWorld.dot(h);if(i>=-.1)this.suspensionRelativeVelocity=0,this.clippedInvContactDotSuspension=10;else{var n=-1/i;this.suspensionRelativeVelocity=o*n,this.clippedInvContactDotSuspension=n}}else e.suspensionLength=this.suspensionRestLength,this.suspensionRelativeVelocity=0,e.directionWorld.scale(-1,e.hitNormalWorld),this.clippedInvContactDotSuspension=1}},{"../collision/RaycastResult":54,"../math/Transform":73,"../math/Vec3":74,"../utils/Utils":97}],81:[function(t,e,i){function o(t){n.call(this,{type:n.types.BOX}),this.halfExtents=t,this.convexPolyhedronRepresentation=null,this.updateConvexPolyhedronRepresentation(),this.updateBoundingSphereRadius()}e.exports=o;var n=t("./Shape"),s=t("../math/Vec3"),r=t("./ConvexPolyhedron");o.prototype=new n,o.prototype.constructor=o,o.prototype.updateConvexPolyhedronRepresentation=function(){var t=this.halfExtents.x,e=this.halfExtents.y,i=this.halfExtents.z,o=s,n=[new o((-t),(-e),(-i)),new o(t,(-e),(-i)),new o(t,e,(-i)),new o((-t),e,(-i)),new o((-t),(-e),i),new o(t,(-e),i),new o(t,e,i),new o((-t),e,i)],a=[[3,2,1,0],[4,5,6,7],[5,4,0,1],[2,3,7,6],[0,4,7,3],[1,2,6,5]],h=([new o(0,0,1),new o(0,1,0),new o(1,0,0)],new r(n,a));this.convexPolyhedronRepresentation=h,h.material=this.material},o.prototype.calculateLocalInertia=function(t,e){return e=e||new s,o.calculateInertia(this.halfExtents,t,e),e},o.calculateInertia=function(t,e,i){var o=t;i.x=1/12*e*(2*o.y*2*o.y+2*o.z*2*o.z),i.y=1/12*e*(2*o.x*2*o.x+2*o.z*2*o.z),i.z=1/12*e*(2*o.y*2*o.y+2*o.x*2*o.x)},o.prototype.getSideNormals=function(t,e){var i=t,o=this.halfExtents;if(i[0].set(o.x,0,0),i[1].set(0,o.y,0),i[2].set(0,0,o.z),i[3].set(-o.x,0,0),i[4].set(0,-o.y,0),i[5].set(0,0,-o.z),void 0!==e)for(var n=0;n!==i.length;n++)e.vmult(i[n],i[n]);return i},o.prototype.volume=function(){return 8*this.halfExtents.x*this.halfExtents.y*this.halfExtents.z},o.prototype.updateBoundingSphereRadius=function(){this.boundingSphereRadius=this.halfExtents.norm()};var a=new s;new s;o.prototype.forEachWorldCorner=function(t,e,i){for(var o=this.halfExtents,n=[[o.x,o.y,o.z],[-o.x,o.y,o.z],[-o.x,-o.y,o.z],[-o.x,-o.y,-o.z],[o.x,-o.y,-o.z],[o.x,o.y,-o.z],[-o.x,o.y,-o.z],[o.x,-o.y,o.z]],s=0;s<n.length;s++)a.set(n[s][0],n[s][1],n[s][2]),e.vmult(a,a),t.vadd(a,a),i(a.x,a.y,a.z)};var h=[new s,new s,new s,new s,new s,new s,new s,new s];o.prototype.calculateWorldAABB=function(t,e,i,o){var n=this.halfExtents;h[0].set(n.x,n.y,n.z),h[1].set(-n.x,n.y,n.z),h[2].set(-n.x,-n.y,n.z),h[3].set(-n.x,-n.y,-n.z),h[4].set(n.x,-n.y,-n.z),h[5].set(n.x,n.y,-n.z),h[6].set(-n.x,n.y,-n.z),h[7].set(n.x,-n.y,n.z);var s=h[0];e.vmult(s,s),t.vadd(s,s),o.copy(s),i.copy(s);for(var r=1;r<8;r++){var s=h[r];e.vmult(s,s),t.vadd(s,s);var a=s.x,l=s.y,c=s.z;a>o.x&&(o.x=a),l>o.y&&(o.y=l),c>o.z&&(o.z=c),a<i.x&&(i.x=a),l<i.y&&(i.y=l),c<i.z&&(i.z=c)}}},{"../math/Vec3":74,"./ConvexPolyhedron":82,"./Shape":87}],82:[function(t,e,i){function o(t,e,i){n.call(this,{type:n.types.CONVEXPOLYHEDRON}),this.vertices=t||[],this.worldVertices=[],this.worldVerticesNeedsUpdate=!0,this.faces=e||[],this.faceNormals=[],this.computeNormals(),this.worldFaceNormalsNeedsUpdate=!0,this.worldFaceNormals=[],this.uniqueEdges=[],this.uniqueAxes=i?i.slice():null,this.computeEdges(),this.updateBoundingSphereRadius()}e.exports=o;var n=t("./Shape"),s=t("../math/Vec3"),r=(t("../math/Quaternion"),t("../math/Transform"));o.prototype=new n,o.prototype.constructor=o;var a=new s;o.prototype.computeEdges=function(){var t=this.faces,e=this.vertices,i=(e.length,this.uniqueEdges);i.length=0;for(var o=a,n=0;n!==t.length;n++)for(var s=t[n],r=s.length,h=0;h!==r;h++){var l=(h+1)%r;e[s[h]].vsub(e[s[l]],o),o.normalize();for(var c=!1,u=0;u!==i.length;u++)if(i[u].almostEquals(o)||i[u].almostEquals(o)){c=!0;break}c||i.push(o.clone())}},o.prototype.computeNormals=function(){this.faceNormals.length=this.faces.length;for(var t=0;t<this.faces.length;t++){for(var e=0;e<this.faces[t].length;e++)if(!this.vertices[this.faces[t][e]])throw new Error("Vertex "+this.faces[t][e]+" not found!");var i=this.faceNormals[t]||new s;this.getFaceNormal(t,i),i.negate(i),this.faceNormals[t]=i;var o=this.vertices[this.faces[t][0]];if(i.dot(o)<0){console.error(".faceNormals["+t+"] = Vec3("+i.toString()+") looks like it points into the shape? The vertices follow. Make sure they are ordered CCW around the normal, using the right hand rule.");for(var e=0;e<this.faces[t].length;e++)console.warn(".vertices["+this.faces[t][e]+"] = Vec3("+this.vertices[this.faces[t][e]].toString()+")")}}};var h=new s,l=new s;o.computeNormal=function(t,e,i,o){e.vsub(t,l),i.vsub(e,h),h.cross(l,o),o.isZero()||o.normalize()},o.prototype.getFaceNormal=function(t,e){var i=this.faces[t],n=this.vertices[i[0]],s=this.vertices[i[1]],r=this.vertices[i[2]];return o.computeNormal(n,s,r,e)};var c=new s;o.prototype.clipAgainstHull=function(t,e,i,o,n,r,a,h,l){for(var u=c,p=-1,d=-Number.MAX_VALUE,y=0;y<i.faces.length;y++){u.copy(i.faceNormals[y]),n.vmult(u,u);var v=u.dot(r);v>d&&(d=v,p=y)}for(var f=[],m=i.faces[p],g=m.length,w=0;w<g;w++){var b=i.vertices[m[w]],x=new s;x.copy(b),n.vmult(x,x),o.vadd(x,x),f.push(x)}p>=0&&this.clipFaceAgainstHull(r,t,e,f,a,h,l)};var u=new s,p=new s,d=new s,y=new s,v=new s,f=new s;o.prototype.findSeparatingAxis=function(t,e,i,o,n,s,r,a){var h=u,l=p,c=d,m=y,g=v,w=f,b=Number.MAX_VALUE,x=this,E=0;if(x.uniqueAxes)for(var A=0;A!==x.uniqueAxes.length;A++){i.vmult(x.uniqueAxes[A],h);var C=x.testSepAxis(h,t,e,i,o,n);if(C===!1)return!1;C<b&&(b=C,s.copy(h))}else for(var B=r?r.length:x.faces.length,A=0;A<B;A++){var S=r?r[A]:A;h.copy(x.faceNormals[S]),i.vmult(h,h);var C=x.testSepAxis(h,t,e,i,o,n);if(C===!1)return!1;C<b&&(b=C,s.copy(h))}if(t.uniqueAxes)for(var A=0;A!==t.uniqueAxes.length;A++){n.vmult(t.uniqueAxes[A],l),E++;var C=x.testSepAxis(l,t,e,i,o,n);if(C===!1)return!1;C<b&&(b=C,s.copy(l))}else for(var R=a?a.length:t.faces.length,A=0;A<R;A++){var S=a?a[A]:A;l.copy(t.faceNormals[S]),n.vmult(l,l),E++;var C=x.testSepAxis(l,t,e,i,o,n);if(C===!1)return!1;C<b&&(b=C,s.copy(l))}for(var M=0;M!==x.uniqueEdges.length;M++){i.vmult(x.uniqueEdges[M],m);for(var T=0;T!==t.uniqueEdges.length;T++)if(n.vmult(t.uniqueEdges[T],g),m.cross(g,w),!w.almostZero()){w.normalize();var z=x.testSepAxis(w,t,e,i,o,n);if(z===!1)return!1;z<b&&(b=z,s.copy(w))}}return o.vsub(e,c),c.dot(s)>0&&s.negate(s),!0};var m=[],g=[];o.prototype.testSepAxis=function(t,e,i,n,s,r){var a=this;o.project(a,t,i,n,m),o.project(e,t,s,r,g);var h=m[0],l=m[1],c=g[0],u=g[1];if(h<u||c<l)return!1;var p=h-u,d=c-l,y=p<d?p:d;return y};var w=new s,b=new s;o.prototype.calculateLocalInertia=function(t,e){this.computeLocalAABB(w,b);var i=b.x-w.x,o=b.y-w.y,n=b.z-w.z;e.x=1/12*t*(2*o*2*o+2*n*2*n),e.y=1/12*t*(2*i*2*i+2*n*2*n),e.z=1/12*t*(2*o*2*o+2*i*2*i)},o.prototype.getPlaneConstantOfFace=function(t){var e=this.faces[t],i=this.faceNormals[t],o=this.vertices[e[0]],n=-i.dot(o);return n};var x=new s,E=new s,A=new s,C=new s,B=new s,S=new s,R=new s,M=new s;o.prototype.clipFaceAgainstHull=function(t,e,i,o,n,s,r){for(var a=x,h=E,l=A,c=C,u=B,p=S,d=R,y=M,v=this,f=[],m=o,g=f,w=-1,b=Number.MAX_VALUE,T=0;T<v.faces.length;T++){a.copy(v.faceNormals[T]),i.vmult(a,a);var z=a.dot(t);z<b&&(b=z,w=T)}if(!(w<0)){var k=v.faces[w];k.connectedFaces=[];for(var L=0;L<v.faces.length;L++)for(var P=0;P<v.faces[L].length;P++)k.indexOf(v.faces[L][P])!==-1&&L!==w&&k.connectedFaces.indexOf(L)===-1&&k.connectedFaces.push(L);for(var q=(m.length,k.length),F=0;F<q;F++){var V=v.vertices[k[F]],N=v.vertices[k[(F+1)%q]];V.vsub(N,h),l.copy(h),i.vmult(l,l),e.vadd(l,l),c.copy(this.faceNormals[w]),i.vmult(c,c),e.vadd(c,c),l.cross(c,u),u.negate(u),p.copy(V),i.vmult(p,p),e.vadd(p,p);var I,H=(-p.dot(u),k.connectedFaces[F]);d.copy(this.faceNormals[H]);var O=this.getPlaneConstantOfFace(H);y.copy(d),i.vmult(y,y);var I=O-y.dot(e);for(this.clipFaceAgainstPlane(m,g,y,I);m.length;)m.shift();for(;g.length;)m.push(g.shift())}d.copy(this.faceNormals[w]);var O=this.getPlaneConstantOfFace(w);y.copy(d),i.vmult(y,y);for(var I=O-y.dot(e),L=0;L<m.length;L++){var j=y.dot(m[L])+I;if(j<=n&&(console.log("clamped: depth="+j+" to minDist="+(n+"")),j=n),j<=s){var D=m[L];if(j<=0){var W={point:D,normal:y,depth:j};r.push(W)}}}}},o.prototype.clipFaceAgainstPlane=function(t,e,i,o){var n,r,a=t.length;if(a<2)return e;var h=t[t.length-1],l=t[0];n=i.dot(h)+o;for(var c=0;c<a;c++){if(l=t[c],r=i.dot(l)+o,n<0)if(r<0){var u=new s;u.copy(l),e.push(u)}else{var u=new s;h.lerp(l,n/(n-r),u),e.push(u)}else if(r<0){var u=new s;h.lerp(l,n/(n-r),u),e.push(u),e.push(l)}h=l,n=r}return e},o.prototype.computeWorldVertices=function(t,e){for(var i=this.vertices.length;this.worldVertices.length<i;)this.worldVertices.push(new s);for(var o=this.vertices,n=this.worldVertices,r=0;r!==i;r++)e.vmult(o[r],n[r]),t.vadd(n[r],n[r]);this.worldVerticesNeedsUpdate=!1};new s;o.prototype.computeLocalAABB=function(t,e){var i=this.vertices.length,o=this.vertices;t.set(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),e.set(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE);for(var n=0;n<i;n++){var s=o[n];s.x<t.x?t.x=s.x:s.x>e.x&&(e.x=s.x),s.y<t.y?t.y=s.y:s.y>e.y&&(e.y=s.y),s.z<t.z?t.z=s.z:s.z>e.z&&(e.z=s.z)}},o.prototype.computeWorldFaceNormals=function(t){for(var e=this.faceNormals.length;this.worldFaceNormals.length<e;)this.worldFaceNormals.push(new s);for(var i=this.faceNormals,o=this.worldFaceNormals,n=0;n!==e;n++)t.vmult(i[n],o[n]);this.worldFaceNormalsNeedsUpdate=!1},o.prototype.updateBoundingSphereRadius=function(){for(var t=0,e=this.vertices,i=0,o=e.length;i!==o;i++){var n=e[i].norm2();n>t&&(t=n)}this.boundingSphereRadius=Math.sqrt(t)};var T=new s;o.prototype.calculateWorldAABB=function(t,e,i,o){for(var n,s,r,a,h,l,c=this.vertices.length,u=this.vertices,p=0;p<c;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>h||void 0===h)&&(h=d.y),d.z<r||void 0===r?r=d.z:(d.z>l||void 0===l)&&(l=d.z)}i.set(n,s,r),o.set(a,h,l)},o.prototype.volume=function(){return 4*Math.PI*this.boundingSphereRadius/3},o.prototype.getAveragePointLocal=function(t){t=t||new s;for(var e=this.vertices.length,i=this.vertices,o=0;o<e;o++)t.vadd(i[o],t);return t.mult(1/e,t),t},o.prototype.transformAllPoints=function(t,e){var i=this.vertices.length,o=this.vertices;if(e){for(var n=0;n<i;n++){var s=o[n];e.vmult(s,s)}for(var n=0;n<this.faceNormals.length;n++){var s=this.faceNormals[n];e.vmult(s,s)}}if(t)for(var n=0;n<i;n++){var s=o[n];s.vadd(t,s)}};var z=new s,k=new s,L=new s;o.prototype.pointIsInside=function(t){var e=this.vertices.length,i=this.vertices,o=this.faces,n=this.faceNormals,s=null,r=this.faces.length,a=z;this.getAveragePointLocal(a);for(var h=0;h<r;h++){var e=(this.faces[h].length,n[h]),l=i[o[h][0]],c=k;t.vsub(l,c);var u=e.dot(c),p=L;a.vsub(l,p);var d=e.dot(p);if(u<0&&d>0||u>0&&d<0)return!1}return s?1:-1};var P=(new s,new s),q=new s;o.project=function(t,e,i,o,n){var s=t.vertices.length,a=P,h=0,l=0,c=q,u=t.vertices;c.setZero(),r.vectorToLocalFrame(i,o,e,a),r.pointToLocalFrame(i,o,c,c);var p=c.dot(a);l=h=u[0].dot(a);for(var d=1;d<s;d++){var y=u[d].dot(a);y>h&&(h=y),y<l&&(l=y)}if(l-=p,h-=p,l>h){var v=l;l=h,h=v}n[0]=h,n[1]=l}},{"../math/Quaternion":72,"../math/Transform":73,"../math/Vec3":74,"./Shape":87}],83:[function(t,e,i){function o(t,e,i,o){var r=o,a=[],h=[],l=[],c=[],u=[],p=Math.cos,d=Math.sin;a.push(new n(e*p(0),e*d(0),.5*-i)),c.push(0),a.push(new n(t*p(0),t*d(0),.5*i)),u.push(1);for(var y=0;y<r;y++){var v=2*Math.PI/r*(y+1),f=2*Math.PI/r*(y+.5);y<r-1?(a.push(new n(e*p(v),e*d(v),.5*-i)),c.push(2*y+2),a.push(new n(t*p(v),t*d(v),.5*i)),u.push(2*y+3),l.push([2*y+2,2*y+3,2*y+1,2*y])):l.push([0,1,2*y+1,2*y]),(r%2===1||y<r/2)&&h.push(new n(p(f),d(f),0))}l.push(u),h.push(new n(0,0,1));for(var m=[],y=0;y<c.length;y++)m.push(c[c.length-y-1]);l.push(m),s.call(this,a,l,h)}e.exports=o;var n=(t("./Shape"),t("../math/Vec3")),s=(t("../math/Quaternion"),t("./ConvexPolyhedron"));o.prototype=new s},{"../math/Quaternion":72,"../math/Vec3":74,"./ConvexPolyhedron":82,"./Shape":87}],84:[function(t,e,i){function o(t,e){e=h.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,s.call(this,{type:s.types.HEIGHTFIELD}),this.pillarConvex=new r,this.pillarOffset=new a,this.updateBoundingSphereRadius(),this._cachedPillars={}}function n(t,e,i,o,n,s,r,a,h){h.x=((s-a)*(t-r)+(r-n)*(e-a))/((s-a)*(i-r)+(r-n)*(o-a)),h.y=((a-o)*(t-r)+(i-r)*(e-a))/((s-a)*(i-r)+(r-n)*(o-a)),h.z=1-h.x-h.y}var s=t("./Shape"),r=t("./ConvexPolyhedron"),a=t("../math/Vec3"),h=t("../utils/Utils");e.exports=o,o.prototype=new s,o.prototype.update=function(){this._cachedPillars={}},o.prototype.updateMinValue=function(){for(var t=this.data,e=t[0][0],i=0;i!==t.length;i++)for(var o=0;o!==t[i].length;o++){var n=t[i][o];n<e&&(e=n)}this.minValue=e},o.prototype.updateMaxValue=function(){for(var t=this.data,e=t[0][0],i=0;i!==t.length;i++)for(var o=0;o!==t[i].length;o++){var n=t[i][o];n>e&&(e=n)}this.maxValue=e},o.prototype.setHeightValueAtIndex=function(t,e,i){var o=this.data;o[t][e]=i,this.clearCachedConvexTrianglePillar(t,e,!1),t>0&&(this.clearCachedConvexTrianglePillar(t-1,e,!0),this.clearCachedConvexTrianglePillar(t-1,e,!1)),e>0&&(this.clearCachedConvexTrianglePillar(t,e-1,!0),this.clearCachedConvexTrianglePillar(t,e-1,!1)),e>0&&t>0&&this.clearCachedConvexTrianglePillar(t-1,e-1,!0)},o.prototype.getRectMinMax=function(t,e,i,o,n){n=n||[];for(var s=this.data,r=this.minValue,a=t;a<=i;a++)for(var h=e;h<=o;h++){var l=s[a][h];l>r&&(r=l)}n[0]=this.minValue,n[1]=r},o.prototype.getIndexOfPosition=function(t,e,i,o){var n=this.elementSize,s=this.data,r=Math.floor(t/n),a=Math.floor(e/n);return i[0]=r,i[1]=a,o&&(r<0&&(r=0),a<0&&(a=0),r>=s.length-1&&(r=s.length-1),a>=s[0].length-1&&(a=s[0].length-1)),!(r<0||a<0||r>=s.length-1||a>=s[0].length-1)};var l=[],c=new a,u=new a,p=new a,d=new a;o.prototype.getTriangleAt=function(t,e,i,o,n,s){var r=l;this.getIndexOfPosition(t,e,r,i);var a=r[0],h=r[1],c=this.data;i&&(a=Math.min(c.length-2,Math.max(0,a)),h=Math.min(c[0].length-2,Math.max(0,h)));var u=this.elementSize,p=Math.pow(t/u-a,2)+Math.pow(e/u-h,2),d=Math.pow(t/u-(a+1),2)+Math.pow(e/u-(h+1),2),y=p>d;return this.getTriangle(a,h,y,o,n,s),y};var y=new a,v=new a,f=new a,m=new a,g=new a;o.prototype.getNormalAt=function(t,e,i,o){var n=y,s=v,r=f,a=m,h=g;this.getTriangleAt(t,e,i,n,s,r),s.vsub(n,a),r.vsub(n,h),a.cross(h,o),o.normalize()},o.prototype.getAabbAtIndex=function(t,e,i){var o=this.data,n=this.elementSize;i.lowerBound.set(t*n,e*n,o[t][e]),i.upperBound.set((t+1)*n,(e+1)*n,o[t+1][e+1])},o.prototype.getHeightAt=function(t,e,i){var o=this.data,s=u,r=p,a=d,h=l;this.getIndexOfPosition(t,e,h,i);var y=h[0],v=h[1];i&&(y=Math.min(o.length-2,Math.max(0,y)),v=Math.min(o[0].length-2,Math.max(0,v)));var f=this.getTriangleAt(t,e,i,s,r,a);n(t,e,s.x,s.y,r.x,r.y,a.x,a.y,c);var m=c;return f?o[y+1][v+1]*m.x+o[y][v+1]*m.y+o[y+1][v]*m.z:o[y][v]*m.x+o[y+1][v]*m.y+o[y][v+1]*m.z},o.prototype.getCacheConvexTrianglePillarKey=function(t,e,i){return t+"_"+e+"_"+(i?1:0)},o.prototype.getCachedConvexTrianglePillar=function(t,e,i){return this._cachedPillars[this.getCacheConvexTrianglePillarKey(t,e,i)]},o.prototype.setCachedConvexTrianglePillar=function(t,e,i,o,n){this._cachedPillars[this.getCacheConvexTrianglePillarKey(t,e,i)]={convex:o,offset:n}},o.prototype.clearCachedConvexTrianglePillar=function(t,e,i){delete this._cachedPillars[this.getCacheConvexTrianglePillarKey(t,e,i)]},o.prototype.getTriangle=function(t,e,i,o,n,s){var r=this.data,a=this.elementSize;i?(o.set((t+1)*a,(e+1)*a,r[t+1][e+1]),n.set(t*a,(e+1)*a,r[t][e+1]),s.set((t+1)*a,e*a,r[t+1][e])):(o.set(t*a,e*a,r[t][e]),n.set((t+1)*a,e*a,r[t+1][e]),s.set(t*a,(e+1)*a,r[t][e+1]))},o.prototype.getConvexTrianglePillar=function(t,e,i){var o=this.pillarConvex,n=this.pillarOffset;if(this.cacheEnabled){var s=this.getCachedConvexTrianglePillar(t,e,i);if(s)return this.pillarConvex=s.convex,void(this.pillarOffset=s.offset);o=new r,n=new a,this.pillarConvex=o,this.pillarOffset=n}var s=this.data,h=this.elementSize,l=o.faces;o.vertices.length=6;for(var c=0;c<6;c++)o.vertices[c]||(o.vertices[c]=new a);
l.length=5;for(var c=0;c<5;c++)l[c]||(l[c]=[]);var u=o.vertices,p=(Math.min(s[t][e],s[t+1][e],s[t][e+1],s[t+1][e+1])-this.minValue)/2+this.minValue;i?(n.set((t+.75)*h,(e+.75)*h,p),u[0].set(.25*h,.25*h,s[t+1][e+1]-p),u[1].set(-.75*h,.25*h,s[t][e+1]-p),u[2].set(.25*h,-.75*h,s[t+1][e]-p),u[3].set(.25*h,.25*h,-p-1),u[4].set(-.75*h,.25*h,-p-1),u[5].set(.25*h,-.75*h,-p-1),l[0][0]=0,l[0][1]=1,l[0][2]=2,l[1][0]=5,l[1][1]=4,l[1][2]=3,l[2][0]=2,l[2][1]=5,l[2][2]=3,l[2][3]=0,l[3][0]=3,l[3][1]=4,l[3][2]=1,l[3][3]=0,l[4][0]=1,l[4][1]=4,l[4][2]=5,l[4][3]=2):(n.set((t+.25)*h,(e+.25)*h,p),u[0].set(-.25*h,-.25*h,s[t][e]-p),u[1].set(.75*h,-.25*h,s[t+1][e]-p),u[2].set(-.25*h,.75*h,s[t][e+1]-p),u[3].set(-.25*h,-.25*h,-p-1),u[4].set(.75*h,-.25*h,-p-1),u[5].set(-.25*h,.75*h,-p-1),l[0][0]=0,l[0][1]=1,l[0][2]=2,l[1][0]=5,l[1][1]=4,l[1][2]=3,l[2][0]=0,l[2][1]=2,l[2][2]=5,l[2][3]=3,l[3][0]=1,l[3][1]=0,l[3][2]=3,l[3][3]=4,l[4][0]=4,l[4][1]=5,l[4][2]=2,l[4][3]=1),o.computeNormals(),o.computeEdges(),o.updateBoundingSphereRadius(),this.setCachedConvexTrianglePillar(t,e,i,o,n)},o.prototype.calculateLocalInertia=function(t,e){return e=e||new a,e.set(0,0,0),e},o.prototype.volume=function(){return Number.MAX_VALUE},o.prototype.calculateWorldAABB=function(t,e,i,o){i.set(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE),o.set(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE)},o.prototype.updateBoundingSphereRadius=function(){var t=this.data,e=this.elementSize;this.boundingSphereRadius=new a(t.length*e,t[0].length*e,Math.max(Math.abs(this.maxValue),Math.abs(this.minValue))).norm()},o.prototype.setHeightsFromImage=function(t,e){var i=document.createElement("canvas");i.width=t.width,i.height=t.height;var o=i.getContext("2d");o.drawImage(t,0,0);var n=o.getImageData(0,0,t.width,t.height),s=this.data;s.length=0,this.elementSize=Math.abs(e.x)/n.width;for(var r=0;r<n.height;r++){for(var a=[],h=0;h<n.width;h++){var l=n.data[4*(r*n.height+h)],c=n.data[4*(r*n.height+h)+1],u=n.data[4*(r*n.height+h)+2],p=(l+c+u)/4/255*e.z;e.x<0?a.push(p):a.unshift(p)}e.y<0?s.unshift(a):s.push(a)}this.updateMaxValue(),this.updateMinValue(),this.update()}},{"../math/Vec3":74,"../utils/Utils":97,"./ConvexPolyhedron":82,"./Shape":87}],85:[function(t,e,i){function o(){n.call(this,{type:n.types.PARTICLE})}e.exports=o;var n=t("./Shape"),s=t("../math/Vec3");o.prototype=new n,o.prototype.constructor=o,o.prototype.calculateLocalInertia=function(t,e){return e=e||new s,e.set(0,0,0),e},o.prototype.volume=function(){return 0},o.prototype.updateBoundingSphereRadius=function(){this.boundingSphereRadius=0},o.prototype.calculateWorldAABB=function(t,e,i,o){i.copy(t),o.copy(t)}},{"../math/Vec3":74,"./Shape":87}],86:[function(t,e,i){function o(){n.call(this,{type:n.types.PLANE}),this.worldNormal=new s,this.worldNormalNeedsUpdate=!0,this.boundingSphereRadius=Number.MAX_VALUE}e.exports=o;var n=t("./Shape"),s=t("../math/Vec3");o.prototype=new n,o.prototype.constructor=o,o.prototype.computeWorldNormal=function(t){var e=this.worldNormal;e.set(0,0,1),t.vmult(e,e),this.worldNormalNeedsUpdate=!1},o.prototype.calculateLocalInertia=function(t,e){return e=e||new s},o.prototype.volume=function(){return Number.MAX_VALUE};var r=new s;o.prototype.calculateWorldAABB=function(t,e,i,o){r.set(0,0,1),e.vmult(r,r);var n=Number.MAX_VALUE;i.set(-n,-n,-n),o.set(n,n,n),1===r.x&&(o.x=t.x),1===r.y&&(o.y=t.y),1===r.z&&(o.z=t.z),r.x===-1&&(i.x=t.x),r.y===-1&&(i.y=t.y),r.z===-1&&(i.z=t.z)},o.prototype.updateBoundingSphereRadius=function(){this.boundingSphereRadius=Number.MAX_VALUE}},{"../math/Vec3":74,"./Shape":87}],87:[function(t,e,i){function o(t){t=t||{},this.id=o.idCounter++,this.type=t.type||0,this.boundingSphereRadius=0,this.collisionResponse=!t.collisionResponse||t.collisionResponse,this.collisionFilterGroup=void 0!==t.collisionFilterGroup?t.collisionFilterGroup:1,this.collisionFilterMask=void 0!==t.collisionFilterMask?t.collisionFilterMask:-1,this.material=t.material?t.material:null,this.body=null}e.exports=o;var o=t("./Shape");t("../math/Vec3"),t("../math/Quaternion"),t("../material/Material");o.prototype.constructor=o,o.prototype.updateBoundingSphereRadius=function(){throw"computeBoundingSphereRadius() not implemented for shape type "+this.type},o.prototype.volume=function(){throw"volume() not implemented for shape type "+this.type},o.prototype.calculateLocalInertia=function(t,e){throw"calculateLocalInertia() not implemented for shape type "+this.type},o.idCounter=0,o.types={SPHERE:1,PLANE:2,BOX:4,COMPOUND:8,CONVEXPOLYHEDRON:16,HEIGHTFIELD:32,PARTICLE:64,CYLINDER:128,TRIMESH:256}},{"../material/Material":69,"../math/Quaternion":72,"../math/Vec3":74,"./Shape":87}],88:[function(t,e,i){function o(t){if(n.call(this,{type:n.types.SPHERE}),this.radius=void 0!==t?t:1,this.radius<0)throw new Error("The sphere radius cannot be negative.");this.updateBoundingSphereRadius()}e.exports=o;var n=t("./Shape"),s=t("../math/Vec3");o.prototype=new n,o.prototype.constructor=o,o.prototype.calculateLocalInertia=function(t,e){e=e||new s;var i=2*t*this.radius*this.radius/5;return e.x=i,e.y=i,e.z=i,e},o.prototype.volume=function(){return 4*Math.PI*this.radius/3},o.prototype.updateBoundingSphereRadius=function(){this.boundingSphereRadius=this.radius},o.prototype.calculateWorldAABB=function(t,e,i,o){for(var n=this.radius,s=["x","y","z"],r=0;r<s.length;r++){var a=s[r];i[a]=t[a]-n,o[a]=t[a]+n}}},{"../math/Vec3":74,"./Shape":87}],89:[function(t,e,i){function o(t,e){n.call(this,{type:n.types.TRIMESH}),this.vertices=new Float32Array(t),this.indices=new Int16Array(e),this.normals=new Float32Array(e.length),this.aabb=new a,this.edges=null,this.scale=new s(1,1,1),this.tree=new h,this.updateEdges(),this.updateNormals(),this.updateAABB(),this.updateBoundingSphereRadius(),this.updateTree()}e.exports=o;var n=t("./Shape"),s=t("../math/Vec3"),r=(t("../math/Quaternion"),t("../math/Transform")),a=t("../collision/AABB"),h=t("../utils/Octree");o.prototype=new n,o.prototype.constructor=o;var l=new s;o.prototype.updateTree=function(){var t=this.tree;t.reset(),t.aabb.copy(this.aabb);var e=this.scale;t.aabb.lowerBound.x*=1/e.x,t.aabb.lowerBound.y*=1/e.y,t.aabb.lowerBound.z*=1/e.z,t.aabb.upperBound.x*=1/e.x,t.aabb.upperBound.y*=1/e.y,t.aabb.upperBound.z*=1/e.z;for(var i=new a,o=new s,n=new s,r=new s,h=[o,n,r],l=0;l<this.indices.length/3;l++){var c=3*l;this._getUnscaledVertex(this.indices[c],o),this._getUnscaledVertex(this.indices[c+1],n),this._getUnscaledVertex(this.indices[c+2],r),i.setFromPoints(h),t.insert(i,l)}t.removeEmptyNodes()};var c=new a;o.prototype.getTrianglesInAABB=function(t,e){c.copy(t);var i=this.scale,o=i.x,n=i.y,s=i.z,r=c.lowerBound,a=c.upperBound;return r.x/=o,r.y/=n,r.z/=s,a.x/=o,a.y/=n,a.z/=s,this.tree.aabbQuery(c,e)},o.prototype.setScale=function(t){var e=this.scale.x===this.scale.y===this.scale.z,i=t.x===t.y===t.z;e&&i||this.updateNormals(),this.scale.copy(t),this.updateAABB(),this.updateBoundingSphereRadius()},o.prototype.updateNormals=function(){for(var t=l,e=this.normals,i=0;i<this.indices.length/3;i++){var n=3*i,s=this.indices[n],r=this.indices[n+1],a=this.indices[n+2];this.getVertex(s,v),this.getVertex(r,f),this.getVertex(a,m),o.computeNormal(f,v,m,t),e[n]=t.x,e[n+1]=t.y,e[n+2]=t.z}},o.prototype.updateEdges=function(){for(var t={},e=function(e,i){var o=n<s?n+"_"+s:s+"_"+n;t[o]=!0},i=0;i<this.indices.length/3;i++){var o=3*i,n=this.indices[o],s=this.indices[o+1],r=this.indices[o+2];e(n,s),e(s,r),e(r,n)}var a=Object.keys(t);this.edges=new Int16Array(2*a.length);for(var i=0;i<a.length;i++){var h=a[i].split("_");this.edges[2*i]=parseInt(h[0],10),this.edges[2*i+1]=parseInt(h[1],10)}},o.prototype.getEdgeVertex=function(t,e,i){var o=this.edges[2*t+(e?1:0)];this.getVertex(o,i)};var u=new s,p=new s;o.prototype.getEdgeVector=function(t,e){var i=u,o=p;this.getEdgeVertex(t,0,i),this.getEdgeVertex(t,1,o),o.vsub(i,e)};var d=new s,y=new s;o.computeNormal=function(t,e,i,o){e.vsub(t,y),i.vsub(e,d),d.cross(y,o),o.isZero()||o.normalize()};var v=new s,f=new s,m=new s;o.prototype.getVertex=function(t,e){var i=this.scale;return this._getUnscaledVertex(t,e),e.x*=i.x,e.y*=i.y,e.z*=i.z,e},o.prototype._getUnscaledVertex=function(t,e){var i=3*t,o=this.vertices;return e.set(o[i],o[i+1],o[i+2])},o.prototype.getWorldVertex=function(t,e,i,o){return this.getVertex(t,o),r.pointToWorldFrame(e,i,o,o),o},o.prototype.getTriangleVertices=function(t,e,i,o){var n=3*t;this.getVertex(this.indices[n],e),this.getVertex(this.indices[n+1],i),this.getVertex(this.indices[n+2],o)},o.prototype.getNormal=function(t,e){var i=3*t;return e.set(this.normals[i],this.normals[i+1],this.normals[i+2])};var g=new a;o.prototype.calculateLocalInertia=function(t,e){this.computeLocalAABB(g);var i=g.upperBound.x-g.lowerBound.x,o=g.upperBound.y-g.lowerBound.y,n=g.upperBound.z-g.lowerBound.z;return e.set(1/12*t*(2*o*2*o+2*n*2*n),1/12*t*(2*i*2*i+2*n*2*n),1/12*t*(2*o*2*o+2*i*2*i))};var w=new s;o.prototype.computeLocalAABB=function(t){var e=t.lowerBound,i=t.upperBound,o=this.vertices.length,n=(this.vertices,w);this.getVertex(0,n),e.copy(n),i.copy(n);for(var s=0;s!==o;s++)this.getVertex(s,n),n.x<e.x?e.x=n.x:n.x>i.x&&(i.x=n.x),n.y<e.y?e.y=n.y:n.y>i.y&&(i.y=n.y),n.z<e.z?e.z=n.z:n.z>i.z&&(i.z=n.z)},o.prototype.updateAABB=function(){this.computeLocalAABB(this.aabb)},o.prototype.updateBoundingSphereRadius=function(){for(var t=0,e=this.vertices,i=new s,o=0,n=e.length/3;o!==n;o++){this.getVertex(o,i);var r=i.norm2();r>t&&(t=r)}this.boundingSphereRadius=Math.sqrt(t)};var b=(new s,new r),x=new a;o.prototype.calculateWorldAABB=function(t,e,i,o){var n=b,s=x;n.position=t,n.quaternion=e,this.aabb.toWorldFrame(n,s),i.copy(s.lowerBound),o.copy(s.upperBound)},o.prototype.volume=function(){return 4*Math.PI*this.boundingSphereRadius/3},o.createTorus=function(t,e,i,n,s){t=t||1,e=e||.5,i=i||8,n=n||6,s=s||2*Math.PI;for(var r=[],a=[],h=0;h<=i;h++)for(var l=0;l<=n;l++){var c=l/n*s,u=h/i*Math.PI*2,p=(t+e*Math.cos(u))*Math.cos(c),d=(t+e*Math.cos(u))*Math.sin(c),y=e*Math.sin(u);r.push(p,d,y)}for(var h=1;h<=i;h++)for(var l=1;l<=n;l++){var v=(n+1)*h+l-1,f=(n+1)*(h-1)+l-1,m=(n+1)*(h-1)+l,g=(n+1)*h+l;a.push(v,f,g),a.push(f,m,g)}return new o(r,a)}},{"../collision/AABB":46,"../math/Quaternion":72,"../math/Transform":73,"../math/Vec3":74,"../utils/Octree":94,"./Shape":87}],90:[function(t,e,i){function o(){n.call(this),this.iterations=10,this.tolerance=1e-7}e.exports=o;var n=(t("../math/Vec3"),t("../math/Quaternion"),t("./Solver"));o.prototype=new n;var s=[],r=[],a=[];o.prototype.solve=function(t,e){var i,o,n,h,l,c,u=0,p=this.iterations,d=this.tolerance*this.tolerance,y=this.equations,v=y.length,f=e.bodies,m=f.length,g=t;if(0!==v)for(var w=0;w!==m;w++)f[w].updateSolveMassProperties();var b=r,x=a,E=s;b.length=v,x.length=v,E.length=v;for(var w=0;w!==v;w++){var A=y[w];E[w]=0,x[w]=A.computeB(g),b[w]=1/A.computeC()}if(0!==v){for(var w=0;w!==m;w++){var C=f[w],B=C.vlambda,S=C.wlambda;B.set(0,0,0),S.set(0,0,0)}for(u=0;u!==p;u++){h=0;for(var R=0;R!==v;R++){var A=y[R];i=x[R],o=b[R],c=E[R],l=A.computeGWlambda(),n=o*(i-l-A.eps*c),c+n<A.minForce?n=A.minForce-c:c+n>A.maxForce&&(n=A.maxForce-c),E[R]+=n,h+=n>0?n:-n,A.addToWlambda(n)}if(h*h<d)break}for(var w=0;w!==m;w++){var C=f[w],M=C.velocity,T=C.angularVelocity;C.vlambda.vmul(C.linearFactor,C.vlambda),M.vadd(C.vlambda,M),C.wlambda.vmul(C.angularFactor,C.wlambda),T.vadd(C.wlambda,T)}for(var z=y.length,k=1/g;z--;)y[z].multiplier=E[z]*k}return u}},{"../math/Quaternion":72,"../math/Vec3":74,"./Solver":91}],91:[function(t,e,i){function o(){this.equations=[]}e.exports=o,o.prototype.solve=function(t,e){return 0},o.prototype.addEquation=function(t){t.enabled&&this.equations.push(t)},o.prototype.removeEquation=function(t){var e=this.equations,i=e.indexOf(t);i!==-1&&e.splice(i,1)},o.prototype.removeAllEquations=function(){this.equations.length=0}},{}],92:[function(t,e,i){function o(t){for(h.call(this),this.iterations=10,this.tolerance=1e-7,this.subsolver=t,this.nodes=[],this.nodePool=[];this.nodePool.length<128;)this.nodePool.push(this.createNode())}function n(t){for(var e=t.length,i=0;i!==e;i++){var o=t[i];if(!(o.visited||o.body.type&d))return o}return!1}function s(t,e,i,o){for(y.push(t),t.visited=!0,e(t,i,o);y.length;)for(var s,r=y.pop();s=n(r.children);)s.visited=!0,e(s,i,o),y.push(s)}function r(t,e,i){e.push(t.body);for(var o=t.eqs.length,n=0;n!==o;n++){var s=t.eqs[n];i.indexOf(s)===-1&&i.push(s)}}function a(t,e){return e.id-t.id}e.exports=o;var h=(t("../math/Vec3"),t("../math/Quaternion"),t("./Solver")),l=t("../objects/Body");o.prototype=new h;var c=[],u=[],p={bodies:[]},d=l.STATIC,y=[];o.prototype.createNode=function(){return{body:null,children:[],eqs:[],visited:!1}},o.prototype.solve=function(t,e){for(var i=c,o=this.nodePool,h=e.bodies,l=this.equations,d=l.length,y=h.length,v=this.subsolver;o.length<y;)o.push(this.createNode());i.length=y;for(var f=0;f<y;f++)i[f]=o[f];for(var f=0;f!==y;f++){var m=i[f];m.body=h[f],m.children.length=0,m.eqs.length=0,m.visited=!1}for(var g=0;g!==d;g++){var w=l[g],f=h.indexOf(w.bi),b=h.indexOf(w.bj),x=i[f],E=i[b];x.children.push(E),x.eqs.push(w),E.children.push(x),E.eqs.push(w)}var A,C=0,B=u;v.tolerance=this.tolerance,v.iterations=this.iterations;for(var S=p;A=n(i);){B.length=0,S.bodies.length=0,s(A,r,S.bodies,B);var R=B.length;B=B.sort(a);for(var f=0;f!==R;f++)v.addEquation(B[f]);v.solve(t,S);v.removeAllEquations(),C++}return C}},{"../math/Quaternion":72,"../math/Vec3":74,"../objects/Body":75,"./Solver":91}],93:[function(t,e,i){var o=function(){};e.exports=o,o.prototype={constructor:o,addEventListener:function(t,e){void 0===this._listeners&&(this._listeners={});var i=this._listeners;return void 0===i[t]&&(i[t]=[]),i[t].indexOf(e)===-1&&i[t].push(e),this},hasEventListener:function(t,e){if(void 0===this._listeners)return!1;var i=this._listeners;return void 0!==i[t]&&i[t].indexOf(e)!==-1},hasAnyEventListener:function(t){if(void 0===this._listeners)return!1;var e=this._listeners;return void 0!==e[t]},removeEventListener:function(t,e){if(void 0===this._listeners)return this;var i=this._listeners;if(void 0===i[t])return this;var o=i[t].indexOf(e);return o!==-1&&i[t].splice(o,1),this},dispatchEvent:function(t){if(void 0===this._listeners)return this;var e=this._listeners,i=e[t.type];if(void 0!==i){t.target=this;for(var o=0,n=i.length;o<n;o++)i[o].call(this,t)}return this}}},{}],94:[function(t,e,i){function o(t){t=t||{},this.root=t.root||null,this.aabb=t.aabb?t.aabb.clone():new s,this.data=[],this.children=[]}function n(t,e){e=e||{},e.root=null,e.aabb=t,o.call(this,e),this.maxDepth="undefined"!=typeof e.maxDepth?e.maxDepth:8}var s=t("../collision/AABB"),r=t("../math/Vec3");e.exports=n,n.prototype=new o,o.prototype.reset=function(t,e){this.children.length=this.data.length=0},o.prototype.insert=function(t,e,i){var o=this.data;if(i=i||0,!this.aabb.contains(t))return!1;var n=this.children;if(i<(this.maxDepth||this.root.maxDepth)){var s=!1;n.length||(this.subdivide(),s=!0);for(var r=0;8!==r;r++)if(n[r].insert(t,e,i+1))return!0;s&&(n.length=0)}return o.push(e),!0};var a=new r;o.prototype.subdivide=function(){var t=this.aabb,e=t.lowerBound,i=t.upperBound,n=this.children;n.push(new o({aabb:new s({lowerBound:new r(0,0,0)})}),new o({aabb:new s({lowerBound:new r(1,0,0)})}),new o({aabb:new s({lowerBound:new r(1,1,0)})}),new o({aabb:new s({lowerBound:new r(1,1,1)})}),new o({aabb:new s({lowerBound:new r(0,1,1)})}),new o({aabb:new s({lowerBound:new r(0,0,1)})}),new o({aabb:new s({lowerBound:new r(1,0,1)})}),new o({aabb:new s({lowerBound:new r(0,1,0)})})),i.vsub(e,a),a.scale(.5,a);for(var h=this.root||this,l=0;8!==l;l++){var c=n[l];c.root=h;var u=c.aabb.lowerBound;u.x*=a.x,u.y*=a.y,u.z*=a.z,u.vadd(e,u),u.vadd(a,c.aabb.upperBound)}},o.prototype.aabbQuery=function(t,e){for(var i=(this.data,this.children,[this]);i.length;){var o=i.pop();o.aabb.overlaps(t)&&Array.prototype.push.apply(e,o.data),Array.prototype.push.apply(i,o.children)}return e};var h=new s;o.prototype.rayQuery=function(t,e,i){return t.getAABB(h),h.toLocalFrame(e,h),this.aabbQuery(h,i),i},o.prototype.removeEmptyNodes=function(){for(var t=[this];t.length;){for(var e=t.pop(),i=e.children.length-1;i>=0;i--)e.children[i].data.length||e.children.splice(i,1);Array.prototype.push.apply(t,e.children)}}},{"../collision/AABB":46,"../math/Vec3":74}],95:[function(t,e,i){function o(){this.objects=[],this.type=Object}e.exports=o,o.prototype.release=function(){for(var t=arguments.length,e=0;e!==t;e++)this.objects.push(arguments[e]);return this},o.prototype.get=function(){return 0===this.objects.length?this.constructObject():this.objects.pop()},o.prototype.constructObject=function(){throw new Error("constructObject() not implemented in this Pool subclass yet!")},o.prototype.resize=function(t){for(var e=this.objects;e.length>t;)e.pop();for(;e.length<t;)e.push(this.constructObject());return this}},{}],96:[function(t,e,i){function o(){this.data={keys:[]}}e.exports=o,o.prototype.get=function(t,e){if(t>e){var i=e;e=t,t=i}return this.data[t+"-"+e]},o.prototype.set=function(t,e,i){if(t>e){var o=e;e=t,t=o}var n=t+"-"+e;this.get(t,e)||this.data.keys.push(n),this.data[n]=i},o.prototype.reset=function(){for(var t=this.data,e=t.keys;e.length>0;){var i=e.pop();delete t[i]}}},{}],97:[function(t,e,i){function o(){}e.exports=o,o.defaults=function(t,e){t=t||{};for(var i in e)i in t||(t[i]=e[i]);return t}},{}],98:[function(t,e,i){function o(){s.call(this),this.type=n}e.exports=o;var n=t("../math/Vec3"),s=t("./Pool");o.prototype=new s,o.prototype.constructObject=function(){return new n}},{"../math/Vec3":74,"./Pool":95}],99:[function(t,e,i){function o(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,i){for(var o=null,n=t.length,s=0;s!==n;s++){var r=t[s],a=D;t[(s+1)%n].vsub(r,a);var h=W;a.cross(e,h);var l=K;i.vsub(r,l);var c=h.dot(l);if(!(null===o||c>0&&o===!0||c<=0&&o===!1))return!1;null===o&&(o=c>0)}return!0}e.exports=o;var s=t("../collision/AABB"),r=t("../objects/Body"),a=t("../shapes/Shape"),h=t("../collision/Ray"),l=t("../math/Vec3"),c=t("../math/Transform"),u=(t("../shapes/ConvexPolyhedron"),t("../math/Quaternion")),p=(t("../solver/Solver"),t("../utils/Vec3Pool")),d=t("../equations/ContactEquation"),y=t("../equations/FrictionEquation");o.prototype.createContactEquation=function(t,e,i,o,n,s){var r;this.contactPointPool.length?(r=this.contactPointPool.pop(),r.bi=t,r.bj=e):r=new d(t,e),r.enabled=t.collisionResponse&&e.collisionResponse&&i.collisionResponse&&o.collisionResponse;var a=this.currentContactMaterial;r.restitution=a.restitution,r.setSpookParams(a.contactEquationStiffness,a.contactEquationRelaxation,this.world.dt);var h=i.material||t.material,l=o.material||e.material;return h&&l&&h.restitution>=0&&l.restitution>=0&&(r.restitution=h.restitution*l.restitution),r.si=n||i,r.sj=s||o,r},o.prototype.createFrictionEquationsFromContact=function(t,e){var i=t.bi,o=t.bj,n=t.si,s=t.sj,r=this.world,a=this.currentContactMaterial,h=a.friction,l=n.material||i.material,c=s.material||o.material;if(l&&c&&l.friction>=0&&c.friction>=0&&(h=l.friction*c.friction),h>0){var u=h*r.gravity.length(),p=i.invMass+o.invMass;p>0&&(p=1/p);var d=this.frictionEquationPool,v=d.length?d.pop():new y(i,o,u*p),f=d.length?d.pop():new y(i,o,u*p);return v.bi=f.bi=i,v.bj=f.bj=o,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 l,f=new l,m=new l;o.prototype.createFrictionFromAverage=function(t){var e=this.result[this.result.length-1];if(this.createFrictionEquationsFromContact(e,this.frictionResult)&&1!==t){var i=this.frictionResult[this.frictionResult.length-2],o=this.frictionResult[this.frictionResult.length-1];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],e.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,i.ri),m.scale(r,i.rj),o.ri.copy(i.ri),o.rj.copy(i.rj),v.normalize(),v.tangents(i.t,o.t)}};var g=new l,w=new l,b=new u,x=new u;o.prototype.getContacts=function(t,e,i,o,n,s,a){this.contactPointPool=n,this.frictionEquationPool=a,this.result=o,this.frictionResult=s;for(var h=b,l=x,c=g,u=w,p=0,d=t.length;p!==d;p++){var y=t[p],v=e[p],f=null;y.material&&v.material&&(f=i.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],h),y.quaternion.vmult(y.shapeOffsets[E],c),c.vadd(y.position,c);for(var A=y.shapes[E],C=0;C<v.shapes.length;C++){v.quaternion.mult(v.shapeOrientations[C],l),v.quaternion.vmult(v.shapeOffsets[C],u),u.vadd(v.position,u);var B=v.shapes[C];if(A.collisionFilterMask&B.collisionFilterGroup&&B.collisionFilterMask&A.collisionFilterGroup&&!(c.distanceTo(u)>A.boundingSphereRadius+B.boundingSphereRadius)){var S=null;A.material&&B.material&&(S=i.getContactMaterial(A.material,B.material)||null),this.currentContactMaterial=S||f||i.defaultContactMaterial;var R=this[A.type|B.type];if(R){var M=!1;M=A.type<B.type?R.call(this,A,B,c,u,h,l,y,v,A,B,m):R.call(this,B,A,u,c,l,h,v,y,A,B,m),M&&m&&(i.shapeOverlapKeeper.set(A.id,B.id),i.bodyOverlapKeeper.set(y.id,v.id))}}}}}};o.prototype[a.types.BOX|a.types.BOX]=o.prototype.boxBox=function(t,e,i,o,n,s,r,a,h,l,c){return t.convexPolyhedronRepresentation.material=t.material,e.convexPolyhedronRepresentation.material=e.material,t.convexPolyhedronRepresentation.collisionResponse=t.collisionResponse,e.convexPolyhedronRepresentation.collisionResponse=e.collisionResponse,this.convexConvex(t.convexPolyhedronRepresentation,e.convexPolyhedronRepresentation,i,o,n,s,r,a,t,e,c)},o.prototype[a.types.BOX|a.types.CONVEXPOLYHEDRON]=o.prototype.boxConvex=function(t,e,i,o,n,s,r,a,h,l,c){return t.convexPolyhedronRepresentation.material=t.material,t.convexPolyhedronRepresentation.collisionResponse=t.collisionResponse,this.convexConvex(t.convexPolyhedronRepresentation,e,i,o,n,s,r,a,t,e,c)},o.prototype[a.types.BOX|a.types.PARTICLE]=o.prototype.boxParticle=function(t,e,i,o,n,s,r,a,h,l,c){return t.convexPolyhedronRepresentation.material=t.material,t.convexPolyhedronRepresentation.collisionResponse=t.collisionResponse,this.convexParticle(t.convexPolyhedronRepresentation,e,i,o,n,s,r,a,t,e,c)},o.prototype[a.types.SPHERE]=o.prototype.sphereSphere=function(t,e,i,o,n,s,r,a,h,l,c){if(c)return i.distanceSquared(o)<Math.pow(t.radius+e.radius,2);var u=this.createContactEquation(r,a,t,e,h,l);o.vsub(i,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(i,u.ri),u.ri.vsub(r.position,u.ri),u.rj.vadd(o,u.rj),u.rj.vsub(a.position,u.rj),this.result.push(u),this.createFrictionEquationsFromContact(u,this.frictionResult)};var E=new l,A=new l,C=new l;o.prototype[a.types.PLANE|a.types.TRIMESH]=o.prototype.planeTrimesh=function(t,e,i,o,n,s,r,a,h,u,p){var d=new l,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 l;f.copy(d),c.pointToWorldFrame(o,s,f,d);var m=A;d.vsub(i,m);var g=y.dot(m);if(g<=0){if(p)return!0;var w=this.createContactEquation(r,a,t,e,h,u);w.ni.copy(y);var b=C;y.scale(m.dot(y),b),d.vsub(b,b),w.ri.copy(b),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 B=new l,S=new l,R=(new l,new l),M=new l,T=new l,z=new l,k=new l,L=new l,P=new l,q=new l,F=new l,V=new l,N=new l,I=new s,H=[];o.prototype[a.types.SPHERE|a.types.TRIMESH]=o.prototype.sphereTrimesh=function(t,e,i,o,n,s,r,a,l,u,p){var d=T,y=z,v=k,f=L,m=P,g=q,w=I,b=M,x=S,E=H;c.pointToLocalFrame(o,s,i,m);var A=t.radius;w.lowerBound.set(m.x-A,m.y-A,m.z-A),w.upperBound.set(m.x+A,m.y+A,m.z+A),e.getTrianglesInAABB(w,E);for(var C=R,O=t.radius*t.radius,j=0;j<E.length;j++)for(var D=0;D<3;D++)if(e.getVertex(e.indices[3*E[j]+D],C),C.vsub(m,x),x.norm2()<=O){if(b.copy(C),c.pointToWorldFrame(o,s,b,C),C.vsub(i,x),p)return!0;var W=this.createContactEquation(r,a,t,e,l,u);W.ni.copy(x),W.ni.normalize(),W.ri.copy(W.ni),W.ri.scale(t.radius,W.ri),W.ri.vadd(i,W.ri),W.ri.vsub(r.position,W.ri),W.rj.copy(C),W.rj.vsub(a.position,W.rj),this.result.push(W),this.createFrictionEquationsFromContact(W,this.frictionResult)}for(var j=0;j<E.length;j++)for(var D=0;D<3;D++){e.getVertex(e.indices[3*E[j]+D],d),e.getVertex(e.indices[3*E[j]+(D+1)%3],y),y.vsub(d,v),m.vsub(y,g);var K=g.dot(v);m.vsub(d,g);var _=g.dot(v);if(_>0&&K<0){m.vsub(d,g),f.copy(v),f.normalize(),_=g.dot(f),f.scale(_,g),g.vadd(d,g);var U=g.distanceTo(m);if(U<t.radius){if(p)return!0;var W=this.createContactEquation(r,a,t,e,l,u);g.vsub(m,W.ni),W.ni.normalize(),W.ni.scale(t.radius,W.ri),c.pointToWorldFrame(o,s,g,g),g.vsub(a.position,W.rj),c.vectorToWorldFrame(s,W.ni,W.ni),c.vectorToWorldFrame(s,W.ri,W.ri),this.result.push(W),this.createFrictionEquationsFromContact(W,this.frictionResult)}}}for(var G=F,Y=V,X=N,Q=B,j=0,Z=E.length;j!==Z;j++){e.getTriangleVertices(E[j],G,Y,X),e.getNormal(E[j],Q),m.vsub(G,g);var U=g.dot(Q);if(Q.scale(U,g),m.vsub(g,g),U=g.distanceTo(m),h.pointInTriangle(g,G,Y,X)&&U<t.radius){if(p)return!0;var W=this.createContactEquation(r,a,t,e,l,u);g.vsub(m,W.ni),W.ni.normalize(),W.ni.scale(t.radius,W.ri),c.pointToWorldFrame(o,s,g,g),g.vsub(a.position,W.rj),c.vectorToWorldFrame(s,W.ni,W.ni),c.vectorToWorldFrame(s,W.ri,W.ri),this.result.push(W),this.createFrictionEquationsFromContact(W,this.frictionResult)}}E.length=0};var O=new l,j=new l;o.prototype[a.types.SPHERE|a.types.PLANE]=o.prototype.spherePlane=function(t,e,i,o,n,s,r,a,h,l,c){var u=this.createContactEquation(r,a,t,e,h,l);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),i.vsub(o,O),u.ni.mult(u.ni.dot(O),j),O.vsub(j,u.rj),-O.dot(u.ni)<=t.radius){if(c)return!0;var p=u.ri,d=u.rj;p.vadd(i,p),p.vsub(r.position,p),d.vadd(o,d),d.vsub(a.position,d),this.result.push(u),this.createFrictionEquationsFromContact(u,this.frictionResult)}};var D=new l,W=new l,K=new l,_=new l,U=new l,G=new l,Y=new l,X=[new l,new l,new l,new l,new l,new l],Q=new l,Z=new l,J=new l,$=new l;o.prototype[a.types.SPHERE|a.types.BOX]=o.prototype.sphereBox=function(t,e,i,o,n,s,r,a,h,l,c){var u=this.v3pool,p=X;i.vsub(o,_),e.getSideNormals(p,s);for(var d=t.radius,y=!1,v=Z,f=J,m=$,g=null,w=0,b=0,x=0,E=null,A=0,C=p.length;A!==C&&y===!1;A++){var B=U;B.copy(p[A]);var S=B.norm();B.normalize();var R=_.dot(B);if(R<S+d&&R>0){var M=G,T=Y;M.copy(p[(A+1)%3]),T.copy(p[(A+2)%3]);var z=M.norm(),k=T.norm();M.normalize(),T.normalize();var L=_.dot(M),P=_.dot(T);if(L<z&&L>-z&&P<k&&P>-k){var q=Math.abs(R-S-d);if((null===E||q<E)&&(E=q,b=L,x=P,g=S,v.copy(B),f.copy(M),m.copy(T),w++,c))return!0}}}if(w){y=!0;var F=this.createContactEquation(r,a,t,e,h,l);v.mult(-d,F.ri),F.ni.copy(v),F.ni.negate(F.ni),v.mult(g,v),f.mult(b,f),v.vadd(f,v),m.mult(x,m),v.vadd(m,F.rj),F.ri.vadd(i,F.ri),F.ri.vsub(r.position,F.ri),F.rj.vadd(o,F.rj),F.rj.vsub(a.position,F.rj),this.result.push(F),this.createFrictionEquationsFromContact(F,this.frictionResult)}for(var V=u.get(),N=Q,I=0;2!==I&&!y;I++)for(var H=0;2!==H&&!y;H++)for(var O=0;2!==O&&!y;O++)if(V.set(0,0,0),I?V.vadd(p[0],V):V.vsub(p[0],V),H?V.vadd(p[1],V):V.vsub(p[1],V),O?V.vadd(p[2],V):V.vsub(p[2],V),o.vadd(V,N),N.vsub(i,N),N.norm2()<d*d){if(c)return!0;y=!0;var F=this.createContactEquation(r,a,t,e,h,l);F.ri.copy(N),F.ri.normalize(),F.ni.copy(F.ri),F.ri.mult(d,F.ri),F.rj.copy(V),F.ri.vadd(i,F.ri),F.ri.vsub(r.position,F.ri),F.rj.vadd(o,F.rj),F.rj.vsub(a.position,F.rj),this.result.push(F),this.createFrictionEquationsFromContact(F,this.frictionResult)}u.release(V),V=null;for(var j=u.get(),D=u.get(),F=u.get(),W=u.get(),q=u.get(),K=p.length,I=0;I!==K&&!y;I++)for(var H=0;H!==K&&!y;H++)if(I%3!==H%3){p[H].cross(p[I],j),j.normalize(),p[I].vadd(p[H],D),F.copy(i),F.vsub(D,F),F.vsub(o,F);var tt=F.dot(j);j.mult(tt,W);for(var O=0;O===I%3||O===H%3;)O++;q.copy(i),q.vsub(W,q),q.vsub(D,q),q.vsub(o,q);var et=Math.abs(tt),it=q.norm();if(et<p[O].norm()&&it<d){if(c)return!0;y=!0;var ot=this.createContactEquation(r,a,t,e,h,l);D.vadd(W,ot.rj),ot.rj.copy(ot.rj),q.negate(ot.ni),ot.ni.normalize(),ot.ri.copy(ot.rj),ot.ri.vadd(o,ot.ri),ot.ri.vsub(i,ot.ri),ot.ri.normalize(),ot.ri.mult(d,ot.ri),ot.ri.vadd(i,ot.ri),ot.ri.vsub(r.position,ot.ri),ot.rj.vadd(o,ot.rj),ot.rj.vsub(a.position,ot.rj),this.result.push(ot),this.createFrictionEquationsFromContact(ot,this.frictionResult)}}u.release(j,D,F,W,q)};var tt=new l,et=new l,it=new l,ot=new l,nt=new l,st=new l,rt=new l,at=new l,ht=new l,lt=new l;o.prototype[a.types.SPHERE|a.types.CONVEXPOLYHEDRON]=o.prototype.sphereConvex=function(t,e,i,o,s,r,a,h,l,c,u){var p=this.v3pool;i.vsub(o,tt);for(var d=e.faceNormals,y=e.faces,v=e.vertices,f=t.radius,m=0;m!==v.length;m++){var g=v[m],w=nt;r.vmult(g,w),o.vadd(w,w);var b=ot;if(w.vsub(i,b),b.norm2()<f*f){if(u)return!0;E=!0;var x=this.createContactEquation(a,h,t,e,l,c);return x.ri.copy(b),x.ri.normalize(),x.ni.copy(x.ri),x.ri.mult(f,x.ri),w.vsub(o,x.rj),x.ri.vadd(i,x.ri),x.ri.vsub(a.position,x.ri),x.rj.vadd(o,x.rj),x.rj.vsub(h.position,x.rj),this.result.push(x),void this.createFrictionEquationsFromContact(x,this.frictionResult)}}for(var E=!1,m=0,A=y.length;m!==A&&E===!1;m++){var C=d[m],B=y[m],S=st;r.vmult(C,S);var R=rt;r.vmult(v[B[0]],R),R.vadd(o,R);var M=at;S.mult(-f,M),i.vadd(M,M);var T=ht;M.vsub(R,T);var z=T.dot(S),k=lt;if(i.vsub(R,k),z<0&&k.dot(S)>0){for(var L=[],P=0,q=B.length;P!==q;P++){var F=p.get();r.vmult(v[B[P]],F),o.vadd(F,F),L.push(F)}if(n(L,S,i)){if(u)return!0;E=!0;var x=this.createContactEquation(a,h,t,e,l,c);S.mult(-f,x.ri),S.negate(x.ni);var V=p.get();S.mult(-z,V);var N=p.get();S.mult(-f,N),i.vsub(o,x.rj),x.rj.vadd(N,x.rj),x.rj.vadd(V,x.rj),x.rj.vadd(o,x.rj),x.rj.vsub(h.position,x.rj),x.ri.vadd(i,x.ri),x.ri.vsub(a.position,x.ri),p.release(V),p.release(N),this.result.push(x),this.createFrictionEquationsFromContact(x,this.frictionResult);for(var P=0,I=L.length;P!==I;P++)p.release(L[P]);return}for(var P=0;P!==B.length;P++){var H=p.get(),O=p.get();r.vmult(v[B[(P+1)%B.length]],H),r.vmult(v[B[(P+2)%B.length]],O),o.vadd(H,H),o.vadd(O,O);var j=et;O.vsub(H,j);var D=it;j.unit(D);var W=p.get(),K=p.get();i.vsub(H,K);var _=K.dot(D);D.mult(_,W),W.vadd(H,W);var U=p.get();if(W.vsub(i,U),_>0&&_*_<j.norm2()&&U.norm2()<f*f){if(u)return!0;var x=this.createContactEquation(a,h,t,e,l,c);W.vsub(o,x.rj),W.vsub(i,x.ni),x.ni.normalize(),x.ni.mult(f,x.ri),x.rj.vadd(o,x.rj),x.rj.vsub(h.position,x.rj),x.ri.vadd(i,x.ri),x.ri.vsub(a.position,x.ri),this.result.push(x),this.createFrictionEquationsFromContact(x,this.frictionResult);for(var P=0,I=L.length;P!==I;P++)p.release(L[P]);return p.release(H),p.release(O),p.release(W),p.release(U),void p.release(K)}p.release(H),p.release(O),p.release(W),p.release(U),p.release(K)}for(var P=0,I=L.length;P!==I;P++)p.release(L[P])}}};new l,new l;o.prototype[a.types.PLANE|a.types.BOX]=o.prototype.planeBox=function(t,e,i,o,n,s,r,a,h,l,c){return e.convexPolyhedronRepresentation.material=e.material,e.convexPolyhedronRepresentation.collisionResponse=e.collisionResponse,e.convexPolyhedronRepresentation.id=e.id,this.planeConvex(t,e.convexPolyhedronRepresentation,i,o,n,s,r,a,t,e,c)};var ct=new l,ut=new l,pt=new l,dt=new l;o.prototype[a.types.PLANE|a.types.CONVEXPOLYHEDRON]=o.prototype.planeConvex=function(t,e,i,o,n,s,r,a,h,l,c){var u=ct,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),o.vadd(u,u),u.vsub(i,y);var f=p.dot(y);if(f<=0){if(c)return!0;var m=this.createContactEquation(r,a,t,e,h,l),g=dt;p.mult(p.dot(y),g),u.vsub(g,g),g.vsub(i,m.ri),m.ni.copy(p),u.vsub(o,m.rj),m.ri.vadd(i,m.ri),m.ri.vsub(r.position,m.ri),
m.rj.vadd(o,m.rj),m.rj.vsub(a.position,m.rj),this.result.push(m),d++,this.enableFrictionReduction||this.createFrictionEquationsFromContact(m,this.frictionResult)}}this.enableFrictionReduction&&d&&this.createFrictionFromAverage(d)};var yt=new l,vt=new l;o.prototype[a.types.CONVEXPOLYHEDRON]=o.prototype.convexConvex=function(t,e,i,o,n,s,r,a,h,l,c,u,p){var d=yt;if(!(i.distanceTo(o)>t.boundingSphereRadius+e.boundingSphereRadius)&&t.findSeparatingAxis(e,i,n,o,s,d,u,p)){var y=[],v=vt;t.clipAgainstHull(i,n,e,o,s,d,-100,100,y);for(var f=0,m=0;m!==y.length;m++){if(c)return!0;var g=this.createContactEquation(r,a,t,e,h,l),w=g.ri,b=g.rj;d.negate(g.ni),y[m].normal.negate(v),v.mult(y[m].depth,v),y[m].point.vadd(v,w),b.copy(y[m].point),w.vsub(i,w),b.vsub(o,b),w.vadd(i,w),w.vsub(r.position,w),b.vadd(o,b),b.vsub(a.position,b),this.result.push(g),f++,this.enableFrictionReduction||this.createFrictionEquationsFromContact(g,this.frictionResult)}this.enableFrictionReduction&&f&&this.createFrictionFromAverage(f)}};var ft=new l,mt=new l,gt=new l;o.prototype[a.types.PLANE|a.types.PARTICLE]=o.prototype.planeParticle=function(t,e,i,o,n,s,r,a,h,l,c){var u=ft;u.set(0,0,1),r.quaternion.vmult(u,u);var p=mt;o.vsub(r.position,p);var d=u.dot(p);if(d<=0){if(c)return!0;var y=this.createContactEquation(a,r,e,t,h,l);y.ni.copy(u),y.ni.negate(y.ni),y.ri.set(0,0,0);var v=gt;u.mult(u.dot(o),v),o.vsub(v,v),y.rj.copy(v),this.result.push(y),this.createFrictionEquationsFromContact(y,this.frictionResult)}};var wt=new l;o.prototype[a.types.PARTICLE|a.types.SPHERE]=o.prototype.sphereParticle=function(t,e,i,o,n,s,r,a,h,l,c){var u=wt;u.set(0,0,1),o.vsub(i,u);var p=u.norm2();if(p<=t.radius*t.radius){if(c)return!0;var d=this.createContactEquation(a,r,e,t,h,l);u.normalize(),d.rj.copy(u),d.rj.mult(t.radius,d.rj),d.ni.copy(u),d.ni.negate(d.ni),d.ri.set(0,0,0),this.result.push(d),this.createFrictionEquationsFromContact(d,this.frictionResult)}};var bt=new u,xt=new l,Et=(new l,new l),At=new l,Ct=new l;o.prototype[a.types.PARTICLE|a.types.CONVEXPOLYHEDRON]=o.prototype.convexParticle=function(t,e,i,o,n,s,r,a,h,l,c){var u=-1,p=Et,d=Ct,y=null,v=0,f=xt;if(f.copy(o),f.vsub(i,f),n.conjugate(bt),bt.vmult(f,f),t.pointIsInside(f)){t.worldVerticesNeedsUpdate&&t.computeWorldVertices(i,n),t.worldFaceNormalsNeedsUpdate&&t.computeWorldFaceNormals(n);for(var m=0,g=t.faces.length;m!==g;m++){var w=[t.worldVertices[t.faces[m][0]]],b=t.worldFaceNormals[m];o.vsub(w[0],At);var x=-b.dot(At);if(null===y||Math.abs(x)<Math.abs(y)){if(c)return!0;y=x,u=m,p.copy(b),v++}}if(u!==-1){var E=this.createContactEquation(a,r,e,t,h,l);p.mult(y,d),d.vadd(o,d),d.vsub(i,d),E.rj.copy(d),p.negate(E.ni),E.ri.set(0,0,0);var A=E.ri,C=E.rj;A.vadd(o,A),A.vsub(a.position,A),C.vadd(i,C),C.vsub(r.position,C),this.result.push(E),this.createFrictionEquationsFromContact(E,this.frictionResult)}else console.warn("Point found inside convex, but did not find penetrating face!")}},o.prototype[a.types.BOX|a.types.HEIGHTFIELD]=o.prototype.boxHeightfield=function(t,e,i,o,n,s,r,a,h,l,c){return t.convexPolyhedronRepresentation.material=t.material,t.convexPolyhedronRepresentation.collisionResponse=t.collisionResponse,this.convexHeightfield(t.convexPolyhedronRepresentation,e,i,o,n,s,r,a,t,e,c)};var Bt=new l,St=new l,Rt=[0];o.prototype[a.types.CONVEXPOLYHEDRON|a.types.HEIGHTFIELD]=o.prototype.convexHeightfield=function(t,e,i,o,n,s,r,a,h,l,u){var p=e.data,d=e.elementSize,y=t.boundingSphereRadius,v=St,f=Rt,m=Bt;c.pointToLocalFrame(o,s,i,m);var g=Math.floor((m.x-y)/d)-1,w=Math.ceil((m.x+y)/d)+1,b=Math.floor((m.y-y)/d)-1,x=Math.ceil((m.y+y)/d)+1;if(!(w<0||x<0||g>p.length||b>p[0].length)){g<0&&(g=0),w<0&&(w=0),b<0&&(b=0),x<0&&(x=0),g>=p.length&&(g=p.length-1),w>=p.length&&(w=p.length-1),x>=p[0].length&&(x=p[0].length-1),b>=p[0].length&&(b=p[0].length-1);var E=[];e.getRectMinMax(g,b,w,x,E);var A=E[0],C=E[1];if(!(m.z-y>C||m.z+y<A))for(var B=g;B<w;B++)for(var S=b;S<x;S++){var R=!1;if(e.getConvexTrianglePillar(B,S,!1),c.pointToWorldFrame(o,s,e.pillarOffset,v),i.distanceTo(v)<e.pillarConvex.boundingSphereRadius+t.boundingSphereRadius&&(R=this.convexConvex(t,e.pillarConvex,i,v,n,s,r,a,null,null,u,f,null)),u&&R)return!0;if(e.getConvexTrianglePillar(B,S,!0),c.pointToWorldFrame(o,s,e.pillarOffset,v),i.distanceTo(v)<e.pillarConvex.boundingSphereRadius+t.boundingSphereRadius&&(R=this.convexConvex(t,e.pillarConvex,i,v,n,s,r,a,null,null,u,f,null)),u&&R)return!0}}};var Mt=new l,Tt=new l;o.prototype[a.types.SPHERE|a.types.HEIGHTFIELD]=o.prototype.sphereHeightfield=function(t,e,i,o,n,s,r,a,h,l,u){var p=e.data,d=t.radius,y=e.elementSize,v=Tt,f=Mt;c.pointToLocalFrame(o,s,i,f);var m=Math.floor((f.x-d)/y)-1,g=Math.ceil((f.x+d)/y)+1,w=Math.floor((f.y-d)/y)-1,b=Math.ceil((f.y+d)/y)+1;if(!(g<0||b<0||m>p.length||b>p[0].length)){m<0&&(m=0),g<0&&(g=0),w<0&&(w=0),b<0&&(b=0),m>=p.length&&(m=p.length-1),g>=p.length&&(g=p.length-1),b>=p[0].length&&(b=p[0].length-1),w>=p[0].length&&(w=p[0].length-1);var x=[];e.getRectMinMax(m,w,g,b,x);var E=x[0],A=x[1];if(!(f.z-d>A||f.z+d<E))for(var C=this.result,B=m;B<g;B++)for(var S=w;S<b;S++){var R=C.length,M=!1;if(e.getConvexTrianglePillar(B,S,!1),c.pointToWorldFrame(o,s,e.pillarOffset,v),i.distanceTo(v)<e.pillarConvex.boundingSphereRadius+t.boundingSphereRadius&&(M=this.sphereConvex(t,e.pillarConvex,i,v,n,s,r,a,t,e,u)),u&&M)return!0;if(e.getConvexTrianglePillar(B,S,!0),c.pointToWorldFrame(o,s,e.pillarOffset,v),i.distanceTo(v)<e.pillarConvex.boundingSphereRadius+t.boundingSphereRadius&&(M=this.sphereConvex(t,e.pillarConvex,i,v,n,s,r,a,t,e,u)),u&&M)return!0;var T=C.length-R;if(T>2)return}}}},{"../collision/AABB":46,"../collision/Ray":53,"../equations/ContactEquation":63,"../equations/FrictionEquation":65,"../math/Quaternion":72,"../math/Transform":73,"../math/Vec3":74,"../objects/Body":75,"../shapes/ConvexPolyhedron":82,"../shapes/Shape":87,"../solver/Solver":91,"../utils/Vec3Pool":98}],100:[function(t,e,i){function o(t){t=t||{},h.apply(this),this.dt=-1,this.allowSleep=!!t.allowSleep,this.contacts=[],this.frictionEquations=[],this.quatNormalizeSkip=void 0!==t.quatNormalizeSkip?t.quatNormalizeSkip:0,this.quatNormalizeFast=void 0!==t.quatNormalizeFast&&t.quatNormalizeFast,this.time=0,this.stepnumber=0,this.default_dt=1/60,this.nextId=0,this.gravity=new n,t.gravity&&this.gravity.copy(t.gravity),this.broadphase=void 0!==t.broadphase?t.broadphase:new g,this.bodies=[],this.solver=void 0!==t.solver?t.solver:new r,this.constraints=[],this.narrowphase=new a(this),this.collisionMatrix=new l,this.collisionMatrixPrevious=new l,this.bodyOverlapKeeper=new c,this.shapeOverlapKeeper=new c,this.materials=[],this.contactmaterials=[],this.contactMaterialTable=new 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=o;var n=(t("../shapes/Shape"),t("../math/Vec3")),s=t("../math/Quaternion"),r=t("../solver/GSSolver"),a=(t("../equations/ContactEquation"),t("../equations/FrictionEquation"),t("./Narrowphase")),h=t("../utils/EventTarget"),l=t("../collision/ArrayCollisionMatrix"),c=t("../collision/OverlapKeeper"),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"),g=t("../collision/NaiveBroadphase");o.prototype=new h;var w=(new f,new m);if(o.prototype.getContactMaterial=function(t,e){return this.contactMaterialTable.get(t.id,e.id)},o.prototype.numObjects=function(){return this.bodies.length},o.prototype.collisionMatrixTick=function(){var t=this.collisionMatrixPrevious;this.collisionMatrixPrevious=this.collisionMatrix,this.collisionMatrix=t,this.collisionMatrix.reset(),this.bodyOverlapKeeper.tick(),this.shapeOverlapKeeper.tick()},o.prototype.add=o.prototype.addBody=function(t){this.bodies.indexOf(t)===-1&&(t.index=this.bodies.length,this.bodies.push(t),t.world=this,t.initPosition.copy(t.position),t.initVelocity.copy(t.velocity),t.timeLastSleepy=this.time,t instanceof d&&(t.initAngularVelocity.copy(t.angularVelocity),t.initQuaternion.copy(t.quaternion)),this.collisionMatrix.setNumObjects(this.bodies.length),this.addBodyEvent.body=t,this.idToBodyMap[t.id]=t,this.dispatchEvent(this.addBodyEvent))},o.prototype.addConstraint=function(t){this.constraints.push(t)},o.prototype.removeConstraint=function(t){var e=this.constraints.indexOf(t);e!==-1&&this.constraints.splice(e,1)},o.prototype.rayTest=function(t,e,i){i instanceof v?this.raycastClosest(t,e,{skipBackfaces:!0},i):this.raycastAll(t,e,{skipBackfaces:!0},i)},o.prototype.raycastAll=function(t,e,i,o){return i.mode=m.ALL,i.from=t,i.to=e,i.callback=o,w.intersectWorld(this,i)},o.prototype.raycastAny=function(t,e,i,o){return i.mode=m.ANY,i.from=t,i.to=e,i.result=o,w.intersectWorld(this,i)},o.prototype.raycastClosest=function(t,e,i,o){return i.mode=m.CLOSEST,i.from=t,i.to=e,i.result=o,w.intersectWorld(this,i)},o.prototype.remove=function(t){t.world=null;var e=this.bodies.length-1,i=this.bodies,o=i.indexOf(t);if(o!==-1){i.splice(o,1);for(var n=0;n!==i.length;n++)i[n].index=n;this.collisionMatrix.setNumObjects(e),this.removeBodyEvent.body=t,delete this.idToBodyMap[t.id],this.dispatchEvent(this.removeBodyEvent)}},o.prototype.removeBody=o.prototype.remove,o.prototype.getBodyById=function(t){return this.idToBodyMap[t]},o.prototype.getShapeById=function(t){for(var e=this.bodies,i=0,o=e.length;i<o;i++)for(var n=e[i].shapes,s=0,r=n.length;s<r;s++){var a=n[s];if(a.id===t)return a}},o.prototype.addMaterial=function(t){this.materials.push(t)},o.prototype.addContactMaterial=function(t){this.contactmaterials.push(t),this.contactMaterialTable.set(t.materials[0].id,t.materials[1].id,t)},"undefined"==typeof performance&&(performance={}),!performance.now){var b=Date.now();performance.timing&&performance.timing.navigationStart&&(b=performance.timing.navigationStart),performance.now=function(){return Date.now()-b}}new n;o.prototype.step=function(t,e,i){if(i=i||10,e=e||0,0===e)this.internalStep(t),this.time+=t;else{this.accumulator+=e;for(var o=0;this.accumulator>=t&&o<i;)this.internalStep(t),this.accumulator-=t,o++;for(var n=this.accumulator%t/t,s=0;s!==this.bodies.length;s++){var r=this.bodies[s];r.previousPosition.lerp(r.position,n,r.interpolatedPosition),r.previousQuaternion.slerp(r.quaternion,n,r.interpolatedQuaternion),r.previousQuaternion.normalize()}this.time+=e}};var x={type:"postStep"},E={type:"preStep"},A={type:d.COLLIDE_EVENT_NAME,body:null,contact:null},C=[],B=[],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;o.prototype.internalStep=function(t){this.dt=t;var e,i=this.contacts,o=S,n=R,s=this.numObjects(),r=this.bodies,a=this.solver,h=this.gravity,l=this.doProfiling,c=this.profile,u=d.DYNAMIC,p=this.constraints,y=B,v=(h.norm(),h.x),f=h.y,m=h.z,g=0;for(l&&(e=performance.now()),g=0;g!==s;g++){var w=r[g];if(w.type===u){var b=w.force,M=w.mass;b.x+=M*v,b.y+=M*f,b.z+=M*m}}for(var g=0,T=this.subsystems.length;g!==T;g++)this.subsystems[g].update();l&&(e=performance.now()),o.length=0,n.length=0,this.broadphase.collisionPairs(this,o,n),l&&(c.broadphase=performance.now()-e);var z=p.length;for(g=0;g!==z;g++){var k=p[g];if(!k.collideConnected)for(var L=o.length-1;L>=0;L-=1)(k.bodyA===o[L]&&k.bodyB===n[L]||k.bodyB===o[L]&&k.bodyA===n[L])&&(o.splice(L,1),n.splice(L,1))}this.collisionMatrixTick(),l&&(e=performance.now());var P=C,q=i.length;for(g=0;g!==q;g++)P.push(i[g]);i.length=0;var F=this.frictionEquations.length;for(g=0;g!==F;g++)y.push(this.frictionEquations[g]);this.frictionEquations.length=0,this.narrowphase.getContacts(o,n,this,i,P,this.frictionEquations,y),l&&(c.narrowphase=performance.now()-e),l&&(e=performance.now());for(var g=0;g<this.frictionEquations.length;g++)a.addEquation(this.frictionEquations[g]);for(var V=i.length,N=0;N!==V;N++){var I,k=i[N],w=k.bi,H=k.bj,O=k.si,j=k.sj;I=w.material&&H.material?this.getContactMaterial(w.material,H.material)||this.defaultContactMaterial:this.defaultContactMaterial;var D=I.friction;if(w.material&&H.material&&(w.material.friction>=0&&H.material.friction>=0&&(D=w.material.friction*H.material.friction),w.material.restitution>=0&&H.material.restitution>=0&&(k.restitution=w.material.restitution*H.material.restitution)),a.addEquation(k),w.allowSleep&&w.type===d.DYNAMIC&&w.sleepState===d.SLEEPING&&H.sleepState===d.AWAKE&&H.type!==d.STATIC){var W=H.velocity.norm2()+H.angularVelocity.norm2(),K=Math.pow(H.sleepSpeedLimit,2);W>=2*K&&(w._wakeUpAfterNarrowphase=!0)}if(H.allowSleep&&H.type===d.DYNAMIC&&H.sleepState===d.SLEEPING&&w.sleepState===d.AWAKE&&w.type!==d.STATIC){var _=w.velocity.norm2()+w.angularVelocity.norm2(),U=Math.pow(w.sleepSpeedLimit,2);_>=2*U&&(H._wakeUpAfterNarrowphase=!0)}this.collisionMatrix.set(w,H,!0),this.collisionMatrixPrevious.get(w,H)||(A.body=H,A.contact=k,w.dispatchEvent(A),A.body=w,H.dispatchEvent(A)),this.bodyOverlapKeeper.set(w.id,H.id),this.shapeOverlapKeeper.set(O.id,j.id)}for(this.emitContactEvents(),l&&(c.makeContactConstraints=performance.now()-e,e=performance.now()),g=0;g!==s;g++){var w=r[g];w._wakeUpAfterNarrowphase&&(w.wakeUp(),w._wakeUpAfterNarrowphase=!1)}var z=p.length;for(g=0;g!==z;g++){var k=p[g];k.update();for(var L=0,G=k.equations.length;L!==G;L++){var Y=k.equations[L];a.addEquation(Y)}}a.solve(t,this),l&&(c.solve=performance.now()-e),a.removeAllEquations();var X=Math.pow;for(g=0;g!==s;g++){var w=r[g];if(w.type&u){var Q=X(1-w.linearDamping,t),Z=w.velocity;Z.mult(Q,Z);var J=w.angularVelocity;if(J){var $=X(1-w.angularDamping,t);J.mult($,J)}}}for(this.dispatchEvent(E),g=0;g!==s;g++){var w=r[g];w.preStep&&w.preStep.call(w)}l&&(e=performance.now());var tt=this.stepnumber,et=tt%(this.quatNormalizeSkip+1)===0,it=this.quatNormalizeFast;for(g=0;g!==s;g++)r[g].integrate(t,et,it);for(this.clearForces(),this.broadphase.dirty=!0,l&&(c.integrate=performance.now()-e),this.time+=t,this.stepnumber+=1,this.dispatchEvent(x),g=0;g!==s;g++){var w=r[g],ot=w.postStep;ot&&ot.call(w)}if(this.allowSleep)for(g=0;g!==s;g++)r[g].sleepTick(this.time)},o.prototype.emitContactEvents=function(){var t=[],e=[],i={type:"beginContact",bodyA:null,bodyB:null},o={type:"endContact",bodyA:null,bodyB:null},n={type:"beginShapeContact",bodyA:null,bodyB:null,shapeA:null,shapeB:null},s={type:"endShapeContact",bodyA:null,bodyB:null,shapeA:null,shapeB:null};return function(){var r=this.hasAnyEventListener("beginContact"),a=this.hasAnyEventListener("endContact");if((r||a)&&this.bodyOverlapKeeper.getDiff(t,e),r){for(var h=0,l=t.length;h<l;h+=2)i.bodyA=this.getBodyById(t[h]),i.bodyB=this.getBodyById(t[h+1]),this.dispatchEvent(i);i.bodyA=i.bodyB=null}if(a){for(var h=0,l=e.length;h<l;h+=2)o.bodyA=this.getBodyById(e[h]),o.bodyB=this.getBodyById(e[h+1]),this.dispatchEvent(o);o.bodyA=o.bodyB=null}t.length=e.length=0;var c=this.hasAnyEventListener("beginShapeContact"),u=this.hasAnyEventListener("endShapeContact");if((c||u)&&this.shapeOverlapKeeper.getDiff(t,e),c){for(var h=0,l=t.length;h<l;h+=2){var p=this.getShapeById(t[h]),d=this.getShapeById(t[h+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 h=0,l=e.length;h<l;h+=2){var p=this.getShapeById(e[h]),d=this.getShapeById(e[h+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}}}(),o.prototype.clearForces=function(){for(var t=this.bodies,e=t.length,i=0;i!==e;i++){var o=t[i];o.force,o.torque;o.force.set(0,0,0),o.torque.set(0,0,0)}}},{"../collision/AABB":46,"../collision/ArrayCollisionMatrix":47,"../collision/NaiveBroadphase":50,"../collision/OverlapKeeper":52,"../collision/Ray":53,"../collision/RaycastResult":54,"../equations/ContactEquation":63,"../equations/FrictionEquation":65,"../material/ContactMaterial":68,"../material/Material":69,"../math/Quaternion":72,"../math/Vec3":74,"../objects/Body":75,"../shapes/Shape":87,"../solver/GSSolver":90,"../utils/EventTarget":93,"../utils/TupleDictionary":96,"./Narrowphase":99}]},{},[1]);