-
Notifications
You must be signed in to change notification settings - Fork 0
/
bundle2.js
10 lines (10 loc) · 246 KB
/
bundle2.js
1
2
3
4
5
6
7
8
9
10
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
!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 c=new Error("Cannot find module '"+r+"'");throw c.code="MODULE_NOT_FOUND",c}var l=i[r]={exports:{}};e[r][0].call(l.exports,function(t){var i=e[r][1][t];return n(i?i:t)},l,l.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"),misc:t("./src/misc"),physics:t("aframe-physics-system"),primitives:t("./src/primitives"),shadows:t("./src/shadows"),registerAll:function(){this.controls.registerAll(),this.loaders.registerAll(),this.misc.registerAll(),this.physics.registerAll(),this.primitives.registerAll(),this.shadows.registerAll()}}},{"./src/controls":81,"./src/loaders":88,"./src/misc":95,"./src/primitives":103,"./src/shadows":104,"aframe-physics-system":8}],3:[function(t,e,i){!function(){function t(){}function i(){}function o(){this.skinIndices=[],this.skinWeights=[],this.matrices=[]}function n(){this.hierarchy=[]}function s(){this.geometries={}}function r(){this.node=null,this.name=null,this.id=null,this.vertices=[],this.indices=[],this.normals=[],this.uvs=[],this.bones=[]}function a(){this.uv=null,this.map=null,this.ref=null,this.node=null,this.index=null}function h(){this.normal=null,this.map=null,this.ref=null,this.node=null,this.index=null}function c(){this.indexBuffer=[]}function l(){this.version=null,this.id=null,this.internalId=null,this.times=null,this.values=null,this.attrFlag=null,this.attrData=null}function u(){this.id=null,this.attr=null,this.attrX=!1,this.attrY=!1,this.attrZ=!1,this.internalId=null,this.containerInternalId=null,this.containerBoneId=null,this.curveIdx=null,this.curves={}}function p(){this.curves={},this.length=0,this.fps=30,this.frames=0}function d(){this.textures={}}function y(){this.fileName="",this.name="",this.id=null,this.parentIds=[]}function v(){this.materials={},this.perGeoMap={}}function m(){this.fileName="",this.name="",this.id=null,this.parentIds=[]}function f(t,e,i){for(var o=[],n=0;n<e.length;++n)for(var s=0;s<i;++s)o.push(t[e[n]*i+s]);return o}function g(t,e,i,o){for(var n=[],s=0,r=0;r<e.length;++r){n[e[r]]=[];for(var a=0;a<o;++a)n[e[r]][a]=t[s+a];s+=o}for(var h=[],c=0;c<n.length;++c)if(void 0!==n[c])for(var l=0;l<o;++l)void 0!==n[c][l]&&h.push(n[c][l]);return h}function w(t,e,i){for(var o={},n=[],s=0,r=0;r<e.length;++r)if(!(e[r]in o)){o[e[r]]={};for(var a=0;a<i;++a)o[e[r]][a]=t[r*i+a];s=s<e[r]?e[r]:s}try{for(r=0;r<=s;r++)for(var h=0;h<i;h++)n.push(o[r][h])}catch(c){}return n}function b(t){return t/46186158e3}function x(t){return t*Math.PI/180}function E(t,e,i){var o=new THREE.Euler(t,e,i,"ZYX"),n=new THREE.Quaternion;return n.setFromEuler(o),n}function A(t){return t.split(",").map(function(t){return parseInt(t)})}function C(t){return t.split(",").map(function(t){return parseFloat(t)})}function B(t){return t.split(",").map(function(t){return x(parseFloat(t))})}function T(t){var e=C(t);return(new THREE.Matrix4).fromArray(e)}e.exports=THREE.FBXLoader=function(t){THREE.Loader.call(this),this.manager=void 0!==t?t:THREE.DefaultLoadingManager,this.textureLoader=null,this.textureBasePath=null},THREE.FBXLoader.prototype=Object.create(THREE.Loader.prototype),THREE.FBXLoader.prototype.constructor=THREE.FBXLoader,Object.assign(THREE.FBXLoader.prototype,{load:function(t,e,i,o){var n=this,s=new THREE.XHRLoader(n.manager);s.load(t,function(i){n.isFbxFormatASCII(i)?n.isFbxVersionSupported(i)?(n.textureBasePath=n.extractUrlBase(t),e(n.parse(i))):console.warn("FBXLoader: !!! FBX Version below 7 not supported !!!"):console.warn("FBXLoader: !!! FBX Binary format not supported !!!")},i,o)},setCrossOrigin:function(t){this.crossOrigin=t},isFbxFormatASCII:function(t){for(var e=["K","a","y","d","a","r","a","\\","F","B","X","\\","B","i","n","a","r","y","\\","\\"],i=0,o=function(e){var o=t[e-1];return t=t.slice(i+e),i++,o},n=0;n<e.length;++n){var s=o(1);if(s==e[n])return!1}return!0},isFbxVersionSupported:function(t){var e=/FBXVersion: (\d+)/,i=t.match(e);if(i){var o=parseInt(i[1]);return console.log("FBXLoader: FBX version "+o),o>=7e3}return!1},parse:function(t){var e=this;console.time("FBXLoader"),console.time("FBXLoader: TextParser");var r=(new i).parse(t);console.timeEnd("FBXLoader: TextParser"),console.time("FBXLoader: ObjectParser"),e.hierarchy=(new n).parseHierarchy(r),e.weights=(new o).parse(r,e.hierarchy),e.animations=(new p).parse(r,e.hierarchy),e.textures=(new d).parse(r,e.hierarchy),e.materials=(new v).parse(r,e.hierarchy),e.geometries=(new s).parse(r,e.hierarchy),console.timeEnd("FBXLoader: ObjectParser"),this.texture_cache={},this.material_cache={},this.geometry_cache={},console.time("FBXLoader: MeshParser");var a=this.parseMeshes(r);console.timeEnd("FBXLoader: MeshParser");for(var h=new THREE.Group,c=0;c<a.length;++c)void 0!==a[c]&&h.add(a[c]);return console.timeEnd("FBXLoader"),h},getTexture:function(t){return t.id in this.texture_cache||(null===this.textureLoader&&(this.textureLoader=new THREE.TextureLoader),this.texture_cache[t.id]=this.textureLoader.load(this.textureBasePath+"/"+t.fileName)),this.texture_cache[t.id]},getMaterial:function(t,e){if(!(t.id in this.material_cache)){var i;switch(t.type){case"phong":i=new THREE.MeshPhongMaterial;break;case"lambert":i=new THREE.MeshLambertMaterial;break;default:console.warn("No implementation given for material type "+t.type+" in FBXLoader.js. Defaulting to basic material"),i=new THREE.MeshBasicMaterial({color:3342591})}for(var o=e.searchConnectionChildren(t.id),n=0;n<o.length;++n){var s=e.searchConnectionType(o[n],t.id);switch(s){case' "AmbientColor':break;case' "DiffuseColor':t.parameters.map=this.getTexture(this.textures.textures[o[n]]);break;default:console.warn("Unknown texture application of type "+s+", skipping texture")}}i.setValues(t.parameters),this.material_cache[t.id]=i}return this.material_cache[t.id]},getGeometry:function(t){if(!(t.id in this.geometry_cache)){var e=new THREE.BufferGeometry;if(e.name=t.name,e.addAttribute("position",new THREE.BufferAttribute(new Float32Array(t.vertices),3)),void 0!==t.normals&&t.normals.length>0&&e.addAttribute("normal",new THREE.BufferAttribute(new Float32Array(t.normals),3)),void 0!==t.uvs&&t.uvs.length>0&&e.addAttribute("uv",new THREE.BufferAttribute(new Float32Array(t.uvs),2)),void 0!==t.indices&&t.indices.length>0&&(t.indices.length>65535?e.setIndex(new THREE.BufferAttribute(new Uint32Array(t.indices),1)):e.setIndex(new THREE.BufferAttribute(new Uint16Array(t.indices),1))),e.verticesNeedUpdate=!0,e.computeBoundingSphere(),e.computeBoundingBox(),t.materialIndices.length>1){e.groups=[];for(var i=0,o=-1;i<t.materialIndices.length;++i)t.materialIndices[i]!==o&&(e.groups.push({start:3*i,count:0,materialIndex:t.materialIndices[i]}),o=t.materialIndices[i]),e.groups[e.groups.length-1].count+=3}this.geometry_cache[t.id]=(new THREE.Geometry).fromBufferGeometry(e),this.geometry_cache[t.id].bones=t.bones,this.geometry_cache[t.id].skinIndices=this.weights.skinIndices,this.geometry_cache[t.id].skinWeights=this.weights.skinWeights}return this.geometry_cache[t.id]},parseMeshes:function(t){var e=t.Objects.subNodes.Model,i=[];for(var o in e)"Mesh"===e[o].attrType&&i.push(this.parseMesh(e[o],t));return i},parseMesh:function(t,e){for(var i,o,n,s=e.Objects.subNodes.Geometry,r=e.Objects.subNodes.Material,a=e.searchConnectionChildren(t.id),h=[],c=0;c<a.length;++c)a[c]in s?i=this.getGeometry(this.geometries.geometries[a[c]]):a[c]in r&&h.push(this.getMaterial(this.materials.materials[a[c]],e));if(o=h.length>1?new THREE.MultiMaterial(h):h[0],void 0!==i.bones&&void 0!==i.skinWeights){if(o instanceof THREE.MultiMaterial)for(var c=0;c<o.materials.length;++c)o.materials[c].skinning=!0;else o.skinning=!0;n=new THREE.SkinnedMesh(i,o)}else n=new THREE.Mesh(i,o);return void 0!==this.animations&&this.addAnimation(n,this.weights.matrices,this.animations),n},addAnimation:function(t,e,i){function o(t,e){if(void 0===t)return!1;var i;switch(e){case"S":if(!t.S)return!1;i=t.S;break;case"R":if(!t.R)return!1;i=t.R;break;case"T":if(!t.T)return!1;i=t.T}return void 0!==i.curves.x&&(void 0!==i.curves.y&&void 0!==i.curves.z)}function n(t,e){var i=s(t.curves.x,e),o=s(t.curves.y,e),n=s(t.curves.z,e);return i&&o&&n}function s(t,e){var i=t.values[e];return void 0!==i}function r(t,e){var s={};if(s.time=p/i.fps,s.pos=e.pos,s.rot=e.rotq,s.scl=e.scl,void 0===t)return s;try{if(o(t,"T")&&n(t.T,p)){var r=new THREE.Vector3(t.T.curves.x.values[p],t.T.curves.y.values[p],t.T.curves.z.values[p]);s.pos=[r.x,r.y,r.z]}if(o(t,"R")&&n(t.R,p)){var a=x(t.R.curves.x.values[p]),h=x(t.R.curves.y.values[p]),c=x(t.R.curves.z.values[p]),l=new THREE.Vector3(a,h,c),u=E(l.x,l.y,l.z);s.rot=[u.x,u.y,u.z,u.w]}if(o(t,"S")&&n(t.S,p)){var d=new THREE.Vector3(t.S.curves.x.values[p],t.S.curves.y.values[p],t.S.curves.z.values[p]);s.scl=[d.x,d.y,d.z]}}catch(y){console.log(e),console.log(y)}return s}for(var a in i.stacks){for(var h={name:i.stacks[a].name,fps:30,length:i.stacks[a].length,hierarchy:[]},c=0;c<t.geometry.bones.length;++c){var l=t.geometry.bones[c].name;l=l.replace(/.*:/,""),h.hierarchy.push({parent:t.geometry.bones[c].parent,name:l,keys:[]})}for(var u=t.geometry.bones,p=0;p<i.stacks[a].frames;p++)for(c=0;c<u.length;c++)for(var d=u[c],y=i.stacks[a].layers[0][c],v=0;v<h.hierarchy.length;v++)h.hierarchy[v].name===d.name&&h.hierarchy[v].keys.push(r(y,d));void 0===t.geometry.animations&&(t.geometry.animations=[]),t.geometry.animations.push(THREE.AnimationClip.parseAnimation(h,t.geometry.bones))}},loadFile:function(t,e,i,o,n){var s=new THREE.XHRLoader(this.manager);s.setResponseType(n);var r=s.load(t,e,i,o);return r},loadFileAsBuffer:function(t,e,i,o){this.loadFile(t,e,i,o,"arraybuffer")},loadFileAsText:function(t,e,i,o){this.loadFile(t,e,i,o,"text")}}),Object.assign(t.prototype,{add:function(t,e){this[t]=e},searchConnectionParent:function(t){if(void 0===this.__cache_search_connection_parent&&(this.__cache_search_connection_parent=[]),void 0!==this.__cache_search_connection_parent[t])return this.__cache_search_connection_parent[t];this.__cache_search_connection_parent[t]=[];for(var e=this.Connections.properties.connections,i=[],o=0;o<e.length;++o)if(e[o][0]==t){var n=0===e[o][1]?-1:e[o][1];i.push(n)}return i.length>0?(this.__cache_search_connection_parent[t]=this.__cache_search_connection_parent[t].concat(i),i):(this.__cache_search_connection_parent[t]=[-1],[-1])},searchConnectionChildren:function(t){if(void 0===this.__cache_search_connection_children&&(this.__cache_search_connection_children=[]),void 0!==this.__cache_search_connection_children[t])return this.__cache_search_connection_children[t];this.__cache_search_connection_children[t]=[];for(var e=this.Connections.properties.connections,i=[],o=0;o<e.length;++o)e[o][1]==t&&i.push(0===e[o][0]?-1:e[o][0]);return i.length>0?(this.__cache_search_connection_children[t]=this.__cache_search_connection_children[t].concat(i),i):(this.__cache_search_connection_children[t]=[],[])},searchConnectionType:function(t,e){var i=t+","+e;if(void 0===this.__cache_search_connection_type&&(this.__cache_search_connection_type={}),void 0!==this.__cache_search_connection_type[i])return this.__cache_search_connection_type[i];this.__cache_search_connection_type[i]="";for(var o=this.Connections.properties.connections,n=0;n<o.length;++n)if(o[n][0]==t&&o[n][1]==e)return this.__cache_search_connection_type[i]=o[n][2],o[n][2];return this.__cache_search_connection_type[t]=null,null}}),Object.assign(i.prototype,{getPrevNode:function(){return this.nodeStack[this.currentIndent-2]},getCurrentNode:function(){return this.nodeStack[this.currentIndent-1]},getCurrentProp:function(){return this.currentProp},pushStack:function(t){this.nodeStack.push(t),this.currentIndent+=1},popStack:function(){this.nodeStack.pop(),this.currentIndent-=1},setCurrentProp:function(t,e){this.currentProp=t,this.currentPropName=e},parse:function(e){this.currentIndent=0,this.allNodes=new t,this.nodeStack=[],this.currentProp=[],this.currentPropName="";var i=e.split("\n");for(var o in i){var n=i[o];if(!n.match(/^[\s\t]*;/)&&!n.match(/^[\s\t]*$/)){var s=new RegExp("^\\t{"+this.currentIndent+"}(\\w+):(.*){",""),r=n.match(s);if(r){var a=r[1].trim().replace(/^"/,"").replace(/"$/,""),h=r[2].split(",").map(function(t){return t.trim().replace(/^"/,"").replace(/"$/,"")});this.parseNodeBegin(n,a,h||null)}else{var c=new RegExp("^\\t{"+this.currentIndent+"}(\\w+):[\\s\\t\\r\\n](.*)"),r=n.match(c);if(r){var l=r[1].replace(/^"/,"").replace(/"$/,"").trim(),u=r[2].replace(/^"/,"").replace(/"$/,"").trim();this.parseNodeProperty(n,l,u)}else{var p=new RegExp("^\\t{"+(this.currentIndent-1)+"}}");n.match(p)?this.nodeEnd():n.match(/^[^\s\t}]/)&&this.parseNodePropertyContinued(n)}}}}return this.allNodes},parseNodeBegin:function(t,e,i){var o={name:e,properties:{},subNodes:{}},n=this.parseNodeAttr(i),s=this.getCurrentNode();if(0===this.currentIndent)this.allNodes.add(e,o);else if(e in s.subNodes){var r=s.subNodes[e];this.isFlattenNode(s.subNodes[e])&&(""===n.id?(s.subNodes[e]=[],s.subNodes[e].push(r)):(s.subNodes[e]={},s.subNodes[e][r.id]=r)),""===n.id?s.subNodes[e].push(o):s.subNodes[e][n.id]=o}else"number"==typeof n.id||n.id.match(/^\d+$/)?(s.subNodes[e]={},s.subNodes[e][n.id]=o):s.subNodes[e]=o;i&&(o.id=n.id,o.attrName=n.name,o.attrType=n.type),this.pushStack(o)},parseNodeAttr:function(t){var e=t[0];""!==t[0]&&(e=parseInt(t[0]),isNaN(e)&&(e=t[0]));var i,o;return t.length>1&&(i=t[1].replace(/^(\w+)::/,""),o=t[2]),{id:e,name:i||"",type:o||""}},parseNodeProperty:function(t,e,i){var o=this.getCurrentNode(),n=o.name;if(void 0!==n){var s=n.match(/Properties(\d)+/);if(s)return void this.parseNodeSpecialProperty(t,e,i)}if("C"==e){var r=i.split(",").slice(1),a=parseInt(r[0]),h=parseInt(r[1]),c=i.split(",").slice(3);e="connections",i=[a,h],i=i.concat(c),void 0===o.properties[e]&&(o.properties[e]=[])}if("Node"==e){var l=parseInt(i);o.properties.id=l,o.id=l}e in o.properties?Array.isArray(o.properties[e])?o.properties[e].push(i):o.properties[e]+=i:Array.isArray(o.properties[e])?o.properties[e].push(i):o.properties[e]=i,this.setCurrentProp(o.properties,e)},parseNodePropertyContinued:function(t){this.currentProp[this.currentPropName]+=t},parseNodeSpecialProperty:function(t,e,i){var o=i.split('",').map(function(t){return t.trim().replace(/^\"/,"").replace(/\s/,"_")}),n=o[0],s=o[1],r=o[2],a=o[3],h=o[4];switch(s){case"int":h=parseInt(h);break;case"double":h=parseFloat(h);break;case"ColorRGB":case"Vector3D":var c=h.split(",");h=new THREE.Vector3(c[0],c[1],c[2])}this.getPrevNode().properties[n]={type:s,type2:r,flag:a,value:h},this.setCurrentProp(this.getPrevNode().properties,n)},nodeEnd:function(){this.popStack()},isFlattenNode:function(t){return"subNodes"in t&&"properties"in t}}),o.prototype.parseCluster=function(t,e,i){var o=t.searchConnectionParent(e),n=A(i.subNodes.Indexes.properties.a),s=C(i.subNodes.Weights.properties.a),r=T(i.subNodes.Transform.properties.a),a=T(i.subNodes.TransformLink.properties.a);return{parent:o,id:parseInt(e),indices:n,weights:s,transform:r,transformlink:a,linkMode:i.properties.Mode}},o.prototype.parse=function(t,e){this.skinIndices=[],this.skinWeights=[],this.matrices=[];var i=t.Objects.subNodes.Deformer,o={};for(var n in i)if("Cluster"===i[n].attrType){if(!("Indexes"in i[n].subNodes))continue;var s=this.parseCluster(t,n,i[n]),r=t.searchConnectionChildren(s.id)[0];o[r]=s}for(var a=[],h=e.hierarchy,c=0;c<h.length;++c){var l=h[c].internalId;if(void 0!==o[l]){var u=o[l];this.matrices.push(u.transform);for(var p=0;p<u.indices.length;++p){void 0===a[u.indices[p]]&&(a[u.indices[p]]={},a[u.indices[p]].joint=[],a[u.indices[p]].weight=[]);var d=t.searchConnectionChildren(u.id);d.length>1&&console.warn("FBXLoader: node "+u.id+" have many weight kids: "+d),a[u.indices[p]].joint.push(e.getBoneIdfromInternalId(t,d[0])),a[u.indices[p]].weight.push(u.weights[p])}}else this.matrices.push(new THREE.Matrix4)}for(var y=0;y<a.length;y++)if(void 0!==a[y]){var v=new THREE.Vector4(a[y].joint[0]?a[y].joint[0]:0,a[y].joint[1]?a[y].joint[1]:0,a[y].joint[2]?a[y].joint[2]:0,a[y].joint[3]?a[y].joint[3]:0),m=new THREE.Vector4(a[y].weight[0]?a[y].weight[0]:0,a[y].weight[1]?a[y].weight[1]:0,a[y].weight[2]?a[y].weight[2]:0,a[y].weight[3]?a[y].weight[3]:0);this.skinIndices.push(v),this.skinWeights.push(m)}else this.skinIndices.push(new THREE.Vector4(0,0,0,0)),this.skinWeights.push(new THREE.Vector4(0,0,0,0));return this},n.prototype.parseHierarchy=function(t){var e=t.Objects,i=e.subNodes.Model,o=[];for(var n in i)void 0!==i[n].attrType&&o.push(i[n]);this.hierarchy=[];for(var s=0;s<o.length;++s){var r=o[s],a=t.searchConnectionParent(r.id)[0],h=[0,0,0],c=[0,0,0,1],l=[1,1,1];if("Lcl_Translation"in r.properties&&(h=C(r.properties.Lcl_Translation.value)),"Lcl_Rotation"in r.properties){c=B(r.properties.Lcl_Rotation.value);var u=new THREE.Quaternion;u.setFromEuler(new THREE.Euler(c[0],c[1],c[2],"ZYX")),c=[u.x,u.y,u.z,u.w]}"Lcl_Scaling"in r.properties&&(l=C(r.properties.Lcl_Scaling.value));var p=r.attrName;p=p.replace(/:/,""),p=p.replace(/_/,""),p=p.replace(/-/,""),this.hierarchy.push({parent:a,name:p,pos:h,rotq:c,scl:l,internalId:r.id})}return this.reindexParentId(),this.restoreBindPose(t),this},n.prototype.reindexParentId=function(){for(var t=0;t<this.hierarchy.length;t++)for(var e=0;e<this.hierarchy.length;++e)if(this.hierarchy[t].parent==this.hierarchy[e].internalId){this.hierarchy[t].parent=e;break}},n.prototype.restoreBindPose=function(t){var e=t.Objects.subNodes.Pose;if(void 0!==e){for(var i in e)if("BindPose"===e[i].attrType){e=e[i];break}for(var o=e.subNodes.PoseNode,n={},s={},r=0;r<o.length;++r){var a=T(o[r].subNodes.Matrix.properties.a),h=T(o[r].subNodes.Matrix.properties.a);n[o[r].id]=a,s[o[r].id]=h}for(var c=0;c<this.hierarchy.length;++c){var l=this.hierarchy[c],u=l.internalId;if(void 0!==s[u]){for(var p,d=new THREE.Vector3(0,0,0),y=new THREE.Quaternion,v=new THREE.Vector3(1,1,1),m=t.searchConnectionParent(u),f=0;f<m.length;++f)if(this.isBoneNode(m[f])){p=m[f];break}if(void 0!==p&&void 0!==n[p]){var g=new THREE.Matrix4;g.getInverse(s[p]),g.multiply(n[u]),n[u]=g}n[u].decompose(d,y,v),l.pos=[d.x,d.y,d.z],l.rotq=[y.x,y.y,y.z,y.w],l.scl=[v.x,v.y,v.z]}}}},n.prototype.searchRealId=function(t){for(var e=0;e<this.hierarchy.length;e++)if(t==this.hierarchy[e].internalId)return e;return-1},n.prototype.getByInternalId=function(t){for(var e=0;e<this.hierarchy.length;e++)if(t==this.hierarchy[e].internalId)return this.hierarchy[e];return null},n.prototype.isBoneNode=function(t){for(var e=0;e<this.hierarchy.length;++e)if(t===this.hierarchy[e].internalId)return!0;return!1},n.prototype.getBoneIdfromInternalId=function(t,e){if(void 0===t.__cache_get_boneid_from_internalid&&(t.__cache_get_boneid_from_internalid=[]),void 0!==t.__cache_get_boneid_from_internalid[e])return t.__cache_get_boneid_from_internalid[e];for(var i=0;i<this.hierarchy.length;++i)if(this.hierarchy[i].internalId==e)return t.__cache_get_boneid_from_internalid[e]=i,i;return-1},Object.assign(s.prototype,{parse:function(t,e){if(!("Geometry"in t.Objects.subNodes))return this;for(var i in t.Objects.subNodes.Geometry)"Mesh"===t.Objects.subNodes.Geometry[i].attrType&&(this.geometries[i]=(new r).parse(t.Objects.subNodes.Geometry[i]),this.geometries[i].addBones(e.hierarchy));return this}}),r.prototype.parse=function(t){if(this.node=t,this.name=t.attrName,this.id=t.id,this.vertices=this.getVertices(),void 0===this.vertices)return void console.log("FBXLoader: Geometry.parse(): pass"+this.node.id);if(this.indices=this.getPolygonVertexIndices(),this.uvs=(new a).parse(this.node,this),this.normals=(new h).parse(this.node,this),this.materialIndices=(new c).parse(this.node),this.getPolygonTopologyMax()>3){var e=this.convertPolyIndicesToTri(this.indices,this.materialIndices,this.getPolygonTopologyArray());this.indices=e.res,this.materialIndices=e.materialIndices,this.polyIndices=e.polyIndices}return this},r.prototype.getVertices=function(){if(this.node.__cache_vertices)return this.node.__cache_vertices;if(void 0===this.node.subNodes.Vertices)return console.warn("this.node: "+this.node.attrName+"("+this.node.id+") does not have Vertices"),this.node.__cache_vertices=void 0,null;var t=this.node.subNodes.Vertices.properties.a,e=t.split(",").map(function(t){return parseFloat(t)});return this.node.__cache_vertices=e,this.node.__cache_vertices},r.prototype.getPolygonVertexIndices=function(){if(this.node.__cache_indices&&this.node.__cache_poly_topology_max)return this.node.__cache_indices;if(void 0===this.node.subNodes)return console.error("this.node.subNodes undefined"),void console.log(this.node);if(void 0===this.node.subNodes.PolygonVertexIndex)return console.warn("this.node: "+this.node.attrName+"("+this.node.id+") does not have PolygonVertexIndex "),void(this.node.__cache_indices=void 0);for(var t=this.node.subNodes.PolygonVertexIndex.properties.a,e=t.split(","),i=1,o=null,n=[],s=0;s<e.length;++s){var r=parseInt(e[s]);r<0?(i>o&&(o=i),e[s]=r^-1,n.push(i),i=1):(e[s]=r,i++)}return null===o&&(console.warn("FBXLoader: topology N not found: "+this.node.attrName),console.warn(this.node),o=3),this.node.__cache_poly_topology_max=o,this.node.__cache_poly_topology_arr=n,this.node.__cache_indices=e,this.node.__cache_indices},r.prototype.getPolygonTopologyMax=function(){return this.node.__cache_indices&&this.node.__cache_poly_topology_max?this.node.__cache_poly_topology_max:(this.getPolygonVertexIndices(this.node),this.node.__cache_poly_topology_max)},r.prototype.getPolygonTopologyArray=function(){return this.node.__cache_indices&&this.node.__cache_poly_topology_max?this.node.__cache_poly_topology_arr:(this.getPolygonVertexIndices(this.node),this.node.__cache_poly_topology_arr)},r.prototype.convertPolyIndicesToTri=function(t,e,i){for(var o=[],n=0,s=0,r=0,a=[];n<t.length;){r=i[s];for(var h=0;h<=r-3;h++)o.push(t[n]),o.push(t[n+(r-2-h)]),o.push(t[n+(r-1-h)]),a.push(s);s++,n+=r}var c=[e[0]];if(e.length>1)for(var n=0;n<a.length;++n)c[n]=e[a[n]];return{res:o,materialIndices:c,polyIndices:a}},r.prototype.addBones=function(t){this.bones=t},a.prototype.getUV=function(t){return this.node&&this.uv&&this.map&&this.ref?this.uv:this._parseText(t)},a.prototype.getMap=function(t){return this.node&&this.uv&&this.map&&this.ref?this.map:(this._parseText(t),this.map)},a.prototype.getRef=function(t){return this.node&&this.uv&&this.map&&this.ref?this.ref:(this._parseText(t),this.ref)},a.prototype.getIndex=function(t){return this.node&&this.uv&&this.map&&this.ref?this.index:(this._parseText(t),this.index)},a.prototype.getNode=function(t){return null!==this.node?this.node:(this.node=t.subNodes.LayerElementUV,this.node)},a.prototype._parseText=function(t){var e=this.getNode(t)[0];if(void 0===e)return[];var i=0;for(var o in e)o.match(/^\d+$/)&&i++;i>0&&(console.warn("multi uv not supported"),e=e[o]);var n=e.subNodes.UVIndex.properties.a,s=e.subNodes.UV.properties.a,r=e.properties.MappingInformationType,a=e.properties.ReferenceInformationType;return this.uv=C(s),this.index=A(n),this.map=r,this.ref=a,this.uv},a.prototype.parse=function(t,e){if("LayerElementUV"in t.subNodes){this.uvNode=this.getNode(t),this.uv=this.getUV(t);var i=this.getMap(t),o=this.getRef(t),n=this.getIndex(t),s=e.getPolygonTopologyArray();switch(i){case"ByPolygonVertex":switch(o){case"Direct":this.uv=this.parseUV_ByPolygonVertex_Direct(this.uv,n,s,2);break;case"IndexToDirect":this.uv=this.parseUV_ByPolygonVertex_IndexToDirect(this.uv,n)}this.uv=w(this.uv,e.getPolygonVertexIndices(t),2);break;case"ByPolygon":switch(o){case"Direct":this.uv=this.parseUV_ByPolygon_Direct();break;case"IndexToDirect":this.uv=this.parseUV_ByPolygon_IndexToDirect()}}return this.uv}},a.prototype.parseUV_ByPolygonVertex_Direct=function(t,e,i,o){return g(t,e,i,o)},a.prototype.parseUV_ByPolygonVertex_IndexToDirect=function(t,e){return f(t,e,2)},a.prototype.parseUV_ByPolygon_Direct=function(t){return console.warn("not implemented"),t},a.prototype.parseUV_ByPolygon_IndexToDirect=function(t){return console.warn("not implemented"),t},a.prototype.parseUV_ByVertex_Direct=function(t){return console.warn("not implemented"),t},h.prototype.getNormal=function(t){return this.node&&this.normal&&this.map&&this.ref?this.normal:(this._parseText(t),this.normal)},h.prototype.getMap=function(t){return this.node&&this.normal&&this.map&&this.ref?this.map:(this._parseText(t),this.map)},h.prototype.getRef=function(t){return this.node&&this.normal&&this.map&&this.ref?this.ref:(this._parseText(t),this.ref)},h.prototype.getNode=function(t){return this.node?this.node:(this.node=t.subNodes.LayerElementNormal,this.node)},h.prototype._parseText=function(t){var e=this.getNode(t)[0];if(void 0===e)return void console.warn("node: "+t.attrName+"("+t.id+") does not have LayerElementNormal");var i=e.properties.MappingInformationType,o=e.properties.ReferenceInformationType,n=e.subNodes.Normals.properties.a;this.normal=C(n),this.map=i,this.ref=o},h.prototype.parse=function(t,e){var i=this.getNormal(t),o=this.getMap(t),n=this.getRef(t),s=e.getPolygonVertexIndices(t),r=e.getPolygonTopologyArray(t);switch(o){case"ByPolygonVertex":switch(n){case"Direct":i=this.parseNormal_ByPolygonVertex_Direct(i,s,r,3);break;case"IndexToDirect":i=this.parseNormal_ByPolygonVertex_IndexToDirect()}break;case"ByPolygon":switch(n){case"Direct":i=this.parseNormal_ByPolygon_Direct();break;case"IndexToDirect":i=this.parseNormal_ByPolygon_IndexToDirect()}}return i},h.prototype.parseNormal_ByPolygonVertex_Direct=function(t,e,i,o){return g(t,e,i,o)},h.prototype.parseNormal_ByPolygonVertex_IndexToDirect=function(t){return console.warn("not implemented"),t},h.prototype.parseNormal_ByPolygon_Direct=function(t){return console.warn("not implemented"),t},h.prototype.parseNormal_ByPolygon_IndexToDirect=function(t){return console.warn("not implemented"),t},h.prototype.parseNormal_ByVertex_Direct=function(t){return console.warn("not implemented"),t},Object.assign(c.prototype,{parse:function(t){if("LayerElementMaterial"in t.subNodes){var e=t.subNodes.LayerElementMaterial[0],i=e.properties.MappingInformationType,o=e.properties.ReferenceInformationType,n=A(e.subNodes.Materials.properties.a);switch(i){case"ByPolygon":switch(o){case"IndexToDirect":this.indexBuffer=this.parse_ByPolygon_IndexToDirect(n);break;default:this.indexBuffer=[0]}break;default:this.indexBuffer=[0]}return this.indexBuffer}},parse_ByPolygon_IndexToDirect:function(t){return t}}),l.prototype.fromNode=function(t){return this.id=t.id,this.internalId=t.id,this.times=t.subNodes.KeyTime.properties.a,this.values=t.subNodes.KeyValueFloat.properties.a,this.attrFlag=t.subNodes.KeyAttrFlags.properties.a,this.attrData=t.subNodes.KeyAttrDataFloat.properties.a,this.times=C(this.times),this.values=C(this.values),this.attrData=C(this.attrData),this.attrFlag=A(this.attrFlag),this.times=this.times.map(function(t){return b(t)}),this},l.prototype.getLength=function(){return this.times[this.times.length-1]},u.prototype.fromNode=function(t,e,i){if(this.id=e.id,this.attr=e.attrName,this.internalId=e.id,!this.attr.match(/S|R|T/))return null;for(var o in e.properties)o.match(/X/)&&(this.attrX=!0),o.match(/Y/)&&(this.attrY=!0),o.match(/Z/)&&(this.attrZ=!0);this.containerIndices=t.searchConnectionParent(this.id),this.curveIdx=t.searchConnectionChildren(this.id);for(var n=this.containerIndices.length-1;n>=0;--n){var s=i.searchRealId(this.containerIndices[n]);if(s>=0&&(this.containerBoneId=s,this.containerId=this.containerIndices[n]),s>=0)break}return this},u.prototype.setCurve=function(t){this.curves.push(t)},p.prototype.parse=function(t,e){function i(t){function e(t){t.x&&(A=t.x.getLength()>A?t.x.getLength():A,C=t.x.times[0]<C?t.x.times[0]:C),t.y&&(A=t.y.getLength()>A?t.y.getLength():A,C=t.y.times[0]<C?t.y.times[0]:C),t.z&&(A=t.z.getLength()>A?t.z.getLength():A,C=t.z.times[0]<C?t.z.times[0]:C)}t.R&&e(t.R.curves),t.S&&e(t.S.curves),t.T&&e(t.T.curves)}var o=t.Objects.subNodes.AnimationCurveNode,n=t.Objects.subNodes.AnimationCurve,s=t.Objects.subNodes.AnimationLayer,r=t.Objects.subNodes.AnimationStack,a=[];for(var h in o)if(h.match(/\d+/)){var c=(new u).fromNode(t,o[h],e);a.push(c)}for(var p={},d=0;d<a.length;++d)null!==a[d]&&(p[a[d].id]=a[d]);var y=[];for(h in n)if(h.match(/\d+/)){var v=(new l).fromNode(n[h]);y.push(v);var m=t.searchConnectionParent(v.id)[0],f=t.searchConnectionType(v.id,m);if(f.match(/X/))f="x";else if(f.match(/Y/))f="y";else{if(!f.match(/Z/))continue;f="z"}p[m].curves[f]=v}for(var g in p){var w=p[g].containerBoneId;void 0===this.curves[w]&&(this.curves[w]={T:null,R:null,S:null}),this.curves[w][p[g].attr]=p[g]}this.layers={};for(var h in s){for(var b=[],x=t.searchConnectionChildren(h),d=0;d<x.length;++d)p[x[d]]&&(void 0===b[p[x[d]].containerBoneId]&&(b[p[x[d]].containerBoneId]={T:null,R:null,S:null}),b[p[x[d]].containerBoneId][p[x[d]].attr]=p[x[d]]);this.layers[h]=b}this.stacks={};for(var h in r){for(var E=[],x=t.searchConnectionChildren(h),A=0,C=Number.MAX_VALUE,d=0;d<x.length;++d)if(x[d]in this.layers){E.push(this.layers[x[d]]);for(var B=0;B<this.layers[x[d]].length;++B){var b=this.layers[x[d]][B];b&&i(b)}}A>C&&(this.stacks[h]={name:r[h].attrName,layers:E,length:A-C,frames:30*(A-C)})}return this},d.prototype.add=function(t){void 0===this.textures&&(this.textures=[]),this.textures.push(t);for(var e=0;e<t.parentIds.length;++e)void 0===this.perGeoMap[t.parentIds[e]]&&(this.perGeoMap[t.parentIds[e]]=[]),this.perGeoMap[t.parentIds[e]].push(this.textures[this.textures.length-1])},d.prototype.parse=function(t){var e=t.Objects.subNodes.Texture;for(var i in e){var o=(new y).parse(e[i],t);this.textures[i]=o}return this},d.prototype.getById=function(t){return this.perGeoMap[t]},y.prototype.parse=function(t,e){return this.id=t.id,this.name=t.attrName,this.fileName=this.parseFileName(t.properties.FileName),this.parentIds=this.searchParents(this.id,e),this},y.prototype.parseFileName=function(t){if(void 0===t)return"";var e=t.split(/[\\\/]/);return e.length>0?e[e.length-1]:t},y.prototype.searchParents=function(t,e){var i=e.searchConnectionParent(t);return i},Object.assign(v.prototype,{parse:function(t){var e=t.Objects.subNodes.Material;for(var i in e){var o=(new m).parse(e[i],t);this.materials[i]=o}return this}}),Object.assign(m.prototype,{parse:function(t,e){return this.id=t.id,this.name=t.attrName,this.type=t.properties.ShadingModel,this.parameters=this.parseParameters(t.properties),this.parentIds=this.searchParents(this.id,e),this},parseParameters:function(t){var e={};return t.Diffuse&&(e.color=(new THREE.Color).fromArray([parseFloat(t.Diffuse.value.x),parseFloat(t.Diffuse.value.y),parseFloat(t.Diffuse.value.z)])),t.Specular&&(e.specular=(new THREE.Color).fromArray([parseFloat(t.Specular.value.x),parseFloat(t.Specular.value.y),parseFloat(t.Specular.value.z)])),t.Shininess&&(e.shininess=t.Shininess.value),t.Emissive&&(e.emissive=(new THREE.Color).fromArray([parseFloat(t.Emissive.value.x),parseFloat(t.Emissive.value.y),parseFloat(t.Emissive.value.z)])),t.EmissiveFactor&&(e.emissiveIntensity=t.EmissiveFactor.value),t.Reflectivity&&(e.reflectivity=t.Reflectivity.value),t.Opacity&&(e.opacity=t.Opacity.value),e.opacity<1&&(e.transparent=!0),e},searchParents:function(t,e){return e.searchConnectionParent(t)}})}()},{}],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},c=o.split("\n"),l=void 0,u=0;u<c.length;u++){var p=c[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!==l&&h.elements.push(l),l=Object(),l.name=a[0],l.count=parseInt(a[1]),l.properties=[];break;case"property":l.properties.push(e(a,this.propertyNameMapping));break;default:console.log("unhandled",r,a)}}return void 0!==l&&h.elements.push(l),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 c=0;c<r.length;c++){var l=r[c];if(l=l.trim(),""!==l){h>=o.elements[a].count&&(a++,h=0);var u=this.parseASCIIElement(o.elements[a].properties,l);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 c=n[0];r+=n[1];for(var l=0;l<c;l++)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 c=e[0];this.handleElement(i,o.elements[a].name,c)}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 m[i])return m[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=f[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,c=window.KeyboardEvent.DOM_KEY_LOCATION_RIGHT,l=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:c},93:{code:"ContextMenu"},95:{code:"Standby"},96:{code:"Numpad0",keyCap:"0",location:l},97:{code:"Numpad1",keyCap:"1",location:l},98:{code:"Numpad2",keyCap:"2",location:l},99:{code:"Numpad3",keyCap:"3",location:l},100:{code:"Numpad4",keyCap:"4",location:l},101:{code:"Numpad5",keyCap:"5",location:l},102:{code:"Numpad6",keyCap:"6",location:l},103:{code:"Numpad7",keyCap:"7",location:l},104:{code:"Numpad8",keyCap:"8",location:l},105:{code:"Numpad9",keyCap:"9",location:l},106:{code:"NumpadMultiply",keyCap:"*",location:l},107:{code:"NumpadAdd",keyCap:"+",location:l},108:{code:"NumpadComma",keyCap:",",location:l},109:{code:"NumpadSubtract",keyCap:"-",location:l},110:{code:"NumpadDecimal",keyCap:".",location:l},111:{code:"NumpadDivide",keyCap:"/",location:l},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:l},145:{code:"ScrollLock"},160:{code:"ShiftLeft",location:h},161:{code:"ShiftRight",location:c},162:{code:"ControlLeft",location:h},163:{code:"ControlRight",location:c},164:{code:"AltLeft",location:h},165:{code:"AltRight",location:c},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:l},189:{code:"NumpadSubtract",keyCap:"-",location:l}}),i(y,"moz-mac",{12:{code:"NumLock",location:l},173:{code:"Minus",keyCap:"-"}}),i(y,"moz-win",{173:{code:"Minus",keyCap:"-"}}),i(y,"chrome-mac",{93:{code:"OSRight",location:c}}),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:c},229:{code:"KeyQ",keyCap:"Q"}});var v={};"cros"===u&&(v["U+00A0"]={code:"ShiftLeft",location:h},v["U+00A1"]={code:"ShiftRight",location:c},v["U+00A2"]={code:"ControlLeft",location:h},v["U+00A3"]={code:"ControlRight",location:c},v["U+00A4"]={code:"AltLeft",location:h},v["U+00A5"]={code:"AltRight",location:c}),"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 m=[];m[h]={16:{code:"ShiftLeft",location:h},17:{code:"ControlLeft",location:h},18:{code:"AltLeft",location:h}},m[c]={16:{code:"ShiftRight",location:c},17:{code:"ControlRight",location:c},18:{code:"AltRight",location:c}},m[l]={13:{code:"NumpadEnter",location:l}},i(m[l],"moz",{109:{code:"NumpadSubtract",location:l},107:{code:"NumpadAdd",location:l}}),i(m[h],"moz-mac",{224:{code:"OSLeft",location:h}}),i(m[c],"moz-mac",{224:{code:"OSRight",location:c}}),i(m[c],"moz-win",{91:{code:"OSRight",location:c}}),i(m[c],"mac",{93:{code:"OSRight",location:c}}),i(m[l],"chrome-mac",{12:{code:"NumLock",location:l}}),i(m[l],"safari-mac",{12:{code:"NumLock",location:l},187:{code:"NumpadAdd",location:l},189:{code:"NumpadSubtract",location:l},190:{code:"NumpadDecimal",location:l},191:{code:"NumpadDivide",location:l}});var f={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(f,"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){var o=t("cannon"),n=t("./src/components/math");e.exports={"dynamic-body":t("./src/components/body/dynamic-body"),"static-body":t("./src/components/body/static-body"),constraint:t("./src/components/constraint"),system:t("./src/system/physics"),registerAll:function(t){this._registered||(t=t||window.AFRAME,n.registerAll(),t.systems.physics||t.registerSystem("physics",this.system),t.components["dynamic-body"]||t.registerComponent("dynamic-body",this["dynamic-body"]),t.components["static-body"]||t.registerComponent("static-body",this["static-body"]),t.components.constraint||t.registerComponent("constraint",this.constraint),this._registered=!0)}},window.CANNON=window.CANNON||o},{"./src/components/body/dynamic-body":11,"./src/components/body/static-body":12,"./src/components/constraint":13,"./src/components/math":14,"./src/system/physics":18,cannon:20}],9:[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 c=new THREE.Object3D,l=new THREE.Mesh(h,this.currentMaterial);l.scale.set(100,100,100),c.add(l),l.castShadow=!0,l.receiveShadow=!0,n.add(c);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],m=v[0],f=1;f<v.length-1;f++){var g=v[f],w=v[f+1];p.faces.push(new THREE.Face3(m,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 f=h.vertices.length-3;h.faces.push(new THREE.Face3(f,f+1,f+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 f=0;f<n.children[d].length;f++)n.children[d].children[f].castShadow=!0,n.children[d].children[f].receiveShadow=!0;var T=t.shapeOffsets[i],R=t.shapeOrientations[i];n.position.set(T.x,T.y,T.z),n.quaternion.set(R.x,R.y,R.z,R.w),e.add(n)}return e},e.exports=o.shape2mesh},{cannon:20}],10:[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.getAttribute("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.getAttribute("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.LineSegments(new THREE.EdgesGeometry(s.geometry),new THREE.LineBasicMaterial({color:16711680})),i&&(this.wireframe.offset=i.clone()),n&&(n.inverse(n),this.wireframe.orientation=new THREE.Quaternion(n.x,n.y,n.z,n.w)),this.syncWireframe()},syncWireframe:function(){var t,e=this.wireframe;this.wireframe&&(e.quaternion.copy(this.body.quaternion),e.orientation&&e.quaternion.multiply(e.orientation),e.position.copy(this.body.position),e.offset&&(t=e.offset.clone().applyQuaternion(e.quaternion),e.position.add(t)),e.updateMatrix())},syncToPhysics:function(){var t=new THREE.Quaternion,e=new THREE.Vector3;return function(){var i=this.el,o=i.parentEl,n=this.body;n&&(i.components.velocity&&n.velocity.copy(i.getAttribute("velocity")),o.isScene?(n.quaternion.copy(i.object3D.quaternion),n.position.copy(i.object3D.position)):(i.object3D.getWorldQuaternion(t),n.quaternion.copy(t),i.object3D.getWorldPosition(e),n.position.copy(e)),this.wireframe&&this.syncWireframe())}}(),syncFromPhysics:function(){var t=new THREE.Vector3,e=new THREE.Quaternion,i=new THREE.Quaternion;return function(){var o=this.el,n=o.parentEl,s=this.body;s&&(n.isScene?(o.setAttribute("quaternion",s.quaternion),o.setAttribute("position",s.position)):(e.copy(s.quaternion),n.object3D.getWorldQuaternion(i),e.multiply(i.inverse()),o.setAttribute("quaternion",{x:e.x,y:e.y,z:e.z,w:e.w}),t.copy(s.position),n.object3D.worldToLocal(t),o.setAttribute("position",{x:t.x,y:t.y,z:t.z})),this.wireframe&&this.syncWireframe())}}()}},{"../../../lib/CANNON-shape2mesh":9,cannon:20,"three-to-cannon":76}],11:[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":10}],12:[function(t,e,i){var o=t("./body");e.exports=AFRAME.utils.extend({},o,{step:function(){this.syncToPhysics()}})},{"./body":10}],13:[function(t,e,i){var o=t("cannon");e.exports={dependencies:["dynamic-body"],multiple:!0,schema:{type:{"default":"lock",oneOf:["coneTwist","distance","hinge","lock","pointToPoint"]},target:{type:"selector"},maxForce:{"default":1e6,min:0},collideConnected:{"default":!0},wakeUpBodies:{"default":!0},distance:{"default":0,min:0},pivot:{type:"vec3"},pivotTarget:{type:"vec3"},axis:{type:"vec3"},axisTarget:{type:"vec3"}},init:function(){this.system=this.el.sceneEl.systems.physics,this.constraint=null},remove:function(){this.constraint&&(this.system.world.removeConstraint(this.constraint),this.constraint=null)},update:function(){var t=this.el,e=this.data,i=AFRAME.utils.extend({},e.options);if(this.remove(),!t.body||!e.target.body)return void(t.body?e.target:t).addEventListener("body-loaded",this.update.bind(this,{}));switch(e.type){case"distance":this.constraint=new o.DistanceConstraint(t.body,e.target.body,i.distance||void 0,i.maxForce);break;case"lock":this.constraint=new o.LockConstraint(t.body,e.target.body,i);break;case"coneTwist":case"hinge":case"pointToPoint":throw new Error("[constraint] Unimplemented type.")}this.system.world.addConstraint(this.constraint)}}},{cannon:20}],14:[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":15,"./velocity":16}],15:[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)}}},{}],16:[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})}}}},{}],17:[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}}},{}],18:[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":17,cannon:20}],19:[function(t,e,i){e.exports={_args:[[{hosted:{directUrl:"https://raw.githubusercontent.com/donmccurdy/cannon.js/v0.6.2-dev1/package.json",gitUrl:"git://github.com/donmccurdy/cannon.js.git#v0.6.2-dev1",httpsUrl:"git+https://github.com/donmccurdy/cannon.js.git#v0.6.2-dev1",shortcut:"github:donmccurdy/cannon.js#v0.6.2-dev1",ssh:"[email protected]:donmccurdy/cannon.js.git#v0.6.2-dev1",sshUrl:"git+ssh://[email protected]/donmccurdy/cannon.js.git#v0.6.2-dev1",type:"github"},name:"cannon",raw:"cannon@github:donmccurdy/cannon.js#v0.6.2-dev1",rawSpec:"github:donmccurdy/cannon.js#v0.6.2-dev1",scope:null,spec:"github:donmccurdy/cannon.js#v0.6.2-dev1",type:"hosted"},"/Users/donmccurdy/Documents/Projects/aframe-extras/node_modules/aframe-physics-system"]],_from:"donmccurdy/cannon.js#v0.6.2-dev1",_id:"[email protected]",_inCache:!0,_installable:!0,_location:"/cannon",_phantomChildren:{},_requested:{hosted:{directUrl:"https://raw.githubusercontent.com/donmccurdy/cannon.js/v0.6.2-dev1/package.json",gitUrl:"git://github.com/donmccurdy/cannon.js.git#v0.6.2-dev1",httpsUrl:"git+https://github.com/donmccurdy/cannon.js.git#v0.6.2-dev1",shortcut:"github:donmccurdy/cannon.js#v0.6.2-dev1",ssh:"[email protected]:donmccurdy/cannon.js.git#v0.6.2-dev1",sshUrl:"git+ssh://[email protected]/donmccurdy/cannon.js.git#v0.6.2-dev1",type:"github"},name:"cannon",raw:"cannon@github:donmccurdy/cannon.js#v0.6.2-dev1",rawSpec:"github:donmccurdy/cannon.js#v0.6.2-dev1",scope:null,spec:"github:donmccurdy/cannon.js#v0.6.2-dev1",type:"hosted"},_requiredBy:["/aframe-physics-system"],_resolved:"git://github.com/donmccurdy/cannon.js.git#022e8ba53fa83abf0ad8a0e4fd08623123838a17",_shasum:"978d8979085b17fd0222913a2d349424b94a6e35",_shrinkwrap:null,_spec:"cannon@github:donmccurdy/cannon.js#v0.6.2-dev1",_where:"/Users/donmccurdy/Documents/Projects/aframe-extras/node_modules/aframe-physics-system",author:{email:"[email protected]",name:"Stefan Hedman",url:"http://steffe.se"},bugs:{url:"https://github.com/schteppe/cannon.js/issues"},dependencies:{},description:"A lightweight 3D physics engine written in JavaScript.",devDependencies:{browserify:"*",grunt:"~0.4.0","grunt-browserify":"^2.1.4","grunt-contrib-concat":"~0.1.3","grunt-contrib-jshint":"~0.1.1","grunt-contrib-nodeunit":"^0.4.1","grunt-contrib-uglify":"^0.5.1","grunt-contrib-yuidoc":"^0.5.2",jshint:"latest",nodeunit:"^0.9.0","uglify-js":"latest"},engines:{node:"*"},gitHead:"022e8ba53fa83abf0ad8a0e4fd08623123838a17",homepage:"https://github.com/schteppe/cannon.js",keywords:["cannon.js","cannon","physics","engine","3d"],licenses:[{type:"MIT"}],main:"./src/Cannon.js",name:"cannon",optionalDependencies:{},readme:'# cannon.js\n\n### Lightweight 3D physics for the web\nInspired by [three.js](https://github.com/mrdoob/three.js) and [ammo.js](https://github.com/kripken/ammo.js), and driven by the fact that the web lacks a physics engine, here comes cannon.js.\nThe rigid body physics engine includes simple collision detection, various body shapes, contacts, friction and constraints.\n\n[Demos](http://schteppe.github.com/cannon.js) - [Documentation](http://schteppe.github.com/cannon.js/docs) - [Rendering hints](https://github.com/schteppe/cannon.js/tree/master/examples) - [NPM package](https://npmjs.org/package/cannon) - [CDN](https://cdnjs.com/libraries/cannon.js)\n\n### Browser install\n\nJust include [cannon.js](https://github.com/schteppe/cannon.js/releases/download/v0.6.2/cannon.js) or [cannon.min.js](https://github.com/schteppe/cannon.js/releases/download/v0.6.2/cannon.min.js) in your html and you\'re done:\n\n```html\n<script src="cannon.min.js"></script>\n```\n\n### Node.js install\n\nInstall the cannon package via NPM:\n\n```bash\nnpm install --save cannon\n```\n\nAlternatively, point to the Github repo directly to get the very latest version:\n\n```bash\nnpm install --save schteppe/cannon.js\n```\n\n### Example\n\nThe sample code below creates a sphere on a plane, steps the simulation, and prints the sphere simulation to the console. Note that Cannon.js uses [SI units](http://en.wikipedia.org/wiki/International_System_of_Units) (metre, kilogram, second, etc.).\n\n```javascript\n// Setup our world\nvar world = new CANNON.World();\nworld.gravity.set(0, 0, -9.82); // m/s²\n\n// Create a sphere\nvar radius = 1; // m\nvar sphereBody = new CANNON.Body({\n mass: 5, // kg\n position: new CANNON.Vec3(0, 0, 10), // m\n shape: new CANNON.Sphere(radius)\n});\nworld.addBody(sphereBody);\n\n// Create a plane\nvar groundBody = new CANNON.Body({\n mass: 0 // mass == 0 makes the body static\n});\nvar groundShape = new CANNON.Plane();\ngroundBody.addShape(groundShape);\nworld.addBody(groundBody);\n\nvar fixedTimeStep = 1.0 / 60.0; // seconds\nvar maxSubSteps = 3;\n\n// Start the simulation loop\nvar lastTime;\n(function simloop(time){\n requestAnimationFrame(simloop);\n if(lastTime !== undefined){\n var dt = (time - lastTime) / 1000;\n world.step(fixedTimeStep, dt, maxSubSteps);\n }\n console.log("Sphere z position: " + sphereBody.position.z);\n lastTime = time;\n})();\n```\n\nIf you want to know how to use cannon.js with a rendering engine, for example Three.js, see the [Examples](examples).\n\n### Features\n* Rigid body dynamics\n* Discrete collision detection\n* Contacts, friction and restitution\n* Constraints\n * PointToPoint (a.k.a. ball/socket joint)\n * Distance\n * Hinge (with optional motor)\n * Lock\n * ConeTwist\n* Gauss-Seidel constraint solver and an island split algorithm\n* Collision filters\n* Body sleeping\n* Experimental SPH / fluid support\n* Various shapes and collision algorithms (see table below)\n\n| | [Sphere](http://schteppe.github.io/cannon.js/docs/classes/Sphere.html) | [Plane](http://schteppe.github.io/cannon.js/docs/classes/Plane.html) | [Box](http://schteppe.github.io/cannon.js/docs/classes/Box.html) | [Convex](http://schteppe.github.io/cannon.js/docs/classes/ConvexPolyhedron.html) | [Particle](http://schteppe.github.io/cannon.js/docs/classes/Particle.html) | [Heightfield](http://schteppe.github.io/cannon.js/docs/classes/Heightfield.html) | [Trimesh](http://schteppe.github.io/cannon.js/docs/classes/Trimesh.html) |\n| :-----------|:------:|:-----:|:---:|:------:|:--------:|:-----------:|:-------:|\n| Sphere | Yes | Yes | Yes | Yes | Yes | Yes | Yes |\n| Plane | - | - | Yes | Yes | Yes | - | Yes |\n| Box | - | - | Yes | Yes | Yes | Yes | (todo) |\n| Cylinder | - | - | Yes | Yes | Yes | Yes | (todo) |\n| Convex | - | - | - | Yes | Yes | Yes | (todo) |\n| Particle | - | - | - | - | - | (todo) | (todo) |\n| Heightfield | - | - | - | - | - | - | (todo) |\n| Trimesh | - | - | - | - | - | - | - |\n\n### Todo\nThe simpler todos are marked with ```@todo``` in the code. Github Issues can and should also be used for todos.\n\n### Help\nCreate an [issue](https://github.com/schteppe/cannon.js/issues) if you need help.\n',
readmeFilename:"README.markdown",repository:{type:"git",url:"git+https://github.com/schteppe/cannon.js.git"},version:"0.6.2"}},{}],20:[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":19,"./collision/AABB":21,"./collision/ArrayCollisionMatrix":22,"./collision/Broadphase":23,"./collision/GridBroadphase":24,"./collision/NaiveBroadphase":25,"./collision/ObjectCollisionMatrix":26,"./collision/Ray":28,"./collision/RaycastResult":29,"./collision/SAPBroadphase":30,"./constraints/ConeTwistConstraint":31,"./constraints/Constraint":32,"./constraints/DistanceConstraint":33,"./constraints/HingeConstraint":34,"./constraints/LockConstraint":35,"./constraints/PointToPointConstraint":36,"./equations/ContactEquation":38,"./equations/Equation":39,"./equations/FrictionEquation":40,"./equations/RotationalEquation":41,"./equations/RotationalMotorEquation":42,"./material/ContactMaterial":43,"./material/Material":44,"./math/Mat3":46,"./math/Quaternion":47,"./math/Transform":48,"./math/Vec3":49,"./objects/Body":50,"./objects/RaycastVehicle":51,"./objects/RigidVehicle":52,"./objects/SPHSystem":53,"./objects/Spring":54,"./shapes/Box":56,"./shapes/ConvexPolyhedron":57,"./shapes/Cylinder":58,"./shapes/Heightfield":59,"./shapes/Particle":60,"./shapes/Plane":61,"./shapes/Shape":62,"./shapes/Sphere":63,"./shapes/Trimesh":64,"./solver/GSSolver":65,"./solver/Solver":66,"./solver/SplitSolver":67,"./utils/EventTarget":68,"./utils/Pool":70,"./utils/Vec3Pool":73,"./world/Narrowphase":74,"./world/World":75}],21:[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 c=t[h];a&&(a.vmult(c,s),c=s),c.x>r.x&&(r.x=c.x),c.x<n.x&&(n.x=c.x),c.y>r.y&&(r.y=c.y),c.y<n.y&&(n.y=c.y),c.z>r.z&&(r.z=c.z),c.z<n.z&&(n.z=c.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,c=this.upperBound;t.copy(h),e.set(c.x,h.y,h.z),i.set(c.x,c.y,h.z),o.set(h.x,c.y,c.z),n.set(c.x,h.y,h.z),s.set(h.x,c.y,h.z),r.set(h.x,h.y,c.z),a.copy(c)};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],c=i[5],l=i[6],u=i[7];this.getCorners(o,n,s,a,h,c,l,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],c=i[5],l=i[6],u=i[7];this.getCorners(o,n,s,a,h,c,l,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,c=(this.upperBound.z-t.from.z)*o,l=Math.max(Math.max(Math.min(n,s),Math.min(r,a)),Math.min(h,c)),u=Math.min(Math.min(Math.max(n,s),Math.max(r,a)),Math.max(h,c));return!(u<0)&&!(l>u)}},{"../math/Vec3":49,"../utils/Utils":72}],22:[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}},{}],23:[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:[]},c=[],l=[];o.prototype.makePairsUnique=function(t,e){for(var i=h,o=c,n=l,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":47,"../math/Vec3":49,"../objects/Body":50,"../shapes/Plane":61,"../shapes/Shape":62}],24:[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,c=(i-x)*C|0,m=I((o-w)*E),f=I((n-b)*A),g=I((s-x)*C);a<0?a=0:a>=l&&(a=l-1),h<0?h=0:h>=u&&(h=u-1),c<0?c=0:c>=p&&(c=p-1),m<0?m=0:m>=l&&(m=l-1),f<0?f=0:f>=u&&(f=u-1),g<0?g=0:g>=p&&(g=p-1),a*=d,h*=y,c*=v,m*=d,f*=y,g*=v;for(var B=a;B<=m;B+=d)for(var T=h;T<=f;T+=y)for(var R=c;R<=g;R+=v){var S=B+T+R;N[S][L[S]++]=r}}for(var n=t.numObjects(),s=t.bodies,h=this.aabbMax,c=this.aabbMin,l=this.nx,u=this.ny,p=this.nz,d=u*p,y=p,v=1,m=h.x,f=h.y,g=h.z,w=c.x,b=c.y,x=c.z,E=l/(m-w),A=u/(f-b),C=p/(g-x),B=(m-w)/l,T=(f-b)/u,R=(g-x)/p,S=.5*Math.sqrt(B*B+T*T+R*R),M=r.types,k=M.SPHERE,P=M.PLANE,N=(M.BOX,M.COMPOUND,M.CONVEXPOLYHEDRON,this.bins),L=this.binLengths,_=this.bins.length,z=0;z!==_;z++)L[z]=0;for(var I=Math.ceil,c=Math.min,h=Math.max,z=0;z!==n;z++){var F=s[z],V=F.shape;switch(V.type){case k:var q=F.position.x,j=F.position.y,H=F.position.z,O=V.radius;o(q-O,j-O,H-O,q+O,j+O,H+O,F);break;case P:V.worldNormalNeedsUpdate&&V.computeWorldNormal(F.quaternion);var D=V.worldNormal,W=w+.5*B-F.position.x,K=b+.5*T-F.position.y,U=x+.5*R-F.position.z,G=a;G.set(W,K,U);for(var X=0,Y=0;X!==l;X++,Y+=d,G.y=K,G.x+=B)for(var Q=0,Z=0;Q!==u;Q++,Z+=y,G.z=U,G.y+=T)for(var J=0,$=0;J!==p;J++,$+=v,G.z+=R)if(G.dot(D)<S){var tt=Y+Z+$;N[tt][L[tt]++]=F}break;default:F.aabbNeedsUpdate&&F.computeAABB(),o(F.aabb.lowerBound.x,F.aabb.lowerBound.y,F.aabb.lowerBound.z,F.aabb.upperBound.x,F.aabb.upperBound.y,F.aabb.upperBound.z,F)}}for(var z=0;z!==_;z++){var et=L[z];if(et>1)for(var it=N[z],X=0;X!==et;X++)for(var F=it[X],Q=0;Q!==X;Q++){var ot=it[Q];this.needBroadphaseCollision(F,ot)&&this.intersectionTest(F,ot,e,i)}}this.makePairsUnique(e,i)}},{"../math/Vec3":49,"../shapes/Shape":62,"./Broadphase":23}],25:[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":21,"./Broadphase":23}],26:[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){}},{}],27:[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 c=!1,l=i[h];l>o[a];)a++;c=l===o[a],c||n(t,l)}a=0;for(var h=0;h<r;h++){for(var c=!1,u=o[h];u>i[a];)a++;c=i[a]===u,c||n(e,u)}}},{}],28:[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 c,this.hasHit=!1,this.callback=function(t){}}function n(t,e,i,o){o.vsub(e,V),i.vsub(e,y),t.vsub(e,v);var n,s,r=V.dot(V),a=V.dot(y),h=V.dot(v),c=y.dot(y),l=y.dot(v);return(n=c*h-a*l)>=0&&(s=r*l-a*h)>=0&&n+s<r*c-a*a}function s(t,e,i){i.vsub(t,V);var o=V.dot(e);e.mult(o,q),q.vadd(t,q);var n=i.distanceTo(q);return n}e.exports=o;var r=t("../math/Vec3"),a=t("../math/Quaternion"),h=t("../math/Transform"),c=(t("../shapes/ConvexPolyhedron"),t("../shapes/Box"),t("../collision/RaycastResult")),l=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 c,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 m=new r,f=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=m,n=f,s=0,r=t.shapes.length;s<r;s++){var a=t.shapes[s];if((!i||a.collisionResponse)&&(t.quaternion.mult(t.shapeOrientations[s],n),t.quaternion.vmult(t.shapeOffsets[s],o),o.vadd(t.position,o),this.intersectShape(a,n,o,t),this.result._shouldStop))break}},o.prototype.intersectBodies=function(t,e){e&&(this.result=e,this._updateDirection());for(var i=0,o=t.length;!this.result._shouldStop&&i<o;i++)this.intersectBody(t[i])},o.prototype._updateDirection=function(){this.to.vsub(this.from,this._direction),this._direction.normalize()},o.prototype.intersectShape=function(t,e,i,o){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 c;o.prototype.intersectBox=function(t,e,i,o,n){return this.intersectConvex(t.convexPolyhedronRepresentation,e,i,o,n)},o.prototype[l.types.BOX]=o.prototype.intersectBox,o.prototype.intersectPlane=function(t,e,i,o,n){var s=this.from,a=this.to,h=this._direction,c=new r(0,0,1);e.vmult(c,c);var l=new r;s.vsub(i,l);var u=l.dot(c);a.vsub(i,l);var p=l.dot(c);if(!(u*p>0||s.distanceTo(a)<u)){var d=c.dot(h);if(!(Math.abs(d)<this.precision)){var y=new r,v=new r,m=new r;s.vsub(i,y);var f=-c.dot(y)/d;h.scale(f,v),s.vadd(v,m),this.reportIntersection(c,m,n,o,-1)}}},o.prototype[l.types.PLANE]=o.prototype.intersectPlane,o.prototype.getAABB=function(t){var e=this.to,i=this.from;t.lowerBound.x=Math.min(e.x,i.x),t.lowerBound.y=Math.min(e.y,i.y),t.lowerBound.z=Math.min(e.z,i.z),t.upperBound.x=Math.max(e.x,i.x),t.upperBound.y=Math.max(e.y,i.y),t.upperBound.z=Math.max(e.z,i.z)};var 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,c,l,p=B;r=a=0,c=l=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),c=Math.min(c,p[0]+1),l=Math.min(l,p[1]+1);for(var y=r;y<c;y++)for(var v=a;v<l;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[l.types.HEIGHTFIELD]=o.prototype.intersectHeightfield;var T=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),c=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)),l=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(c,2)-4*h*l,p=T,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=(-c-Math.sqrt(u))/(2*h),v=(-c+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[l.types.SPHERE]=o.prototype.intersectSphere;var S=new r,M=(new r,new r,new r);o.prototype.intersectConvex=function(t,e,i,o,s,r){for(var a=S,h=M,c=r&&r.faceList||null,l=t.faces,u=t.vertices,p=t.faceNormals,d=this._direction,y=this.from,v=this.to,m=y.distanceTo(v),f=c?c.length:l.length,E=this.result,A=0;!E._shouldStop&&A<f;A++){var C=c?c[A]:A,B=l[C],T=p[C],R=e,k=i;h.copy(u[B[0]]),R.vmult(h,h),h.vadd(k,h),h.vsub(y,h),R.vmult(T,a);var P=d.dot(a);if(!(Math.abs(P)<this.precision)){var N=a.dot(h)/P;if(!(N<0)){d.mult(N,g),g.vadd(y,g),w.copy(u[B[0]]),R.vmult(w,w),k.vadd(w,w);for(var L=1;!E._shouldStop&&L<B.length-1;L++){b.copy(u[B[L]]),x.copy(u[B[L+1]]),R.vmult(b,b),R.vmult(x,x),k.vadd(b,b),k.vadd(x,x);var _=g.distanceTo(y);!n(g,w,b,x)&&!n(g,b,w,x)||_>m||this.reportIntersection(a,g,s,o,C)}}}}},o.prototype[l.types.CONVEXPOLYHEDRON]=o.prototype.intersectConvex;var k=new r,P=new r,N=new r,L=new r,_=new r,z=new r,I=(new u,[]),F=new h;o.prototype.intersectTrimesh=function(t,e,i,o,s,r){var a=k,c=I,l=F,u=M,p=P,d=N,y=L,v=z,m=_,f=(r&&r.faceList||null,t.indices),E=(t.vertices,t.faceNormals,this.from),A=this.to,C=this._direction;l.position.copy(i),l.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,l,c);for(var T=0,R=c.length;!this.result._shouldStop&&T!==R;T++){var S=c[T];t.getNormal(S,a),t.getVertex(f[3*S],w),w.vsub(d,u);var V=p.dot(a),q=a.dot(u)/V;if(!(q<0)){p.scale(q,g),g.vadd(d,g),t.getVertex(f[3*S+1],b),t.getVertex(f[3*S+2],x);var j=g.distanceSquared(d);!n(g,b,w,x)&&!n(g,w,b,x)||j>B||(h.vectorToWorldFrame(e,a,m),h.pointToWorldFrame(i,e,g,v),this.reportIntersection(m,v,s,o,S))}}c.length=0},o.prototype[l.types.TRIMESH]=o.prototype.intersectTrimesh,o.prototype.reportIntersection=function(t,e,i,n,s){var r=this.from,a=this.to,h=r.distanceTo(e),c=this.result;if(!(this.skipBackfaces&&t.dot(this._direction)>0))switch(c.hitFaceIndex="undefined"!=typeof s?s:-1,this.mode){case o.ALL:this.hasHit=!0,c.set(r,a,t,e,i,n,h),c.hasHit=!0,this.callback(c);break;case o.CLOSEST:(h<c.distance||!c.hasHit)&&(this.hasHit=!0,c.hasHit=!0,c.set(r,a,t,e,i,n,h));break;case o.ANY:this.hasHit=!0,c.hasHit=!0,c.set(r,a,t,e,i,n,h),c._shouldStop=!0}};var V=new r,q=new r},{"../collision/AABB":21,"../collision/RaycastResult":29,"../math/Quaternion":47,"../math/Transform":48,"../math/Vec3":49,"../shapes/Box":56,"../shapes/ConvexPolyhedron":57,"../shapes/Shape":62}],29:[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":49}],30:[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 c=r[n];for(s=n+1;s<a;s++){var l=r[s];if(this.needBroadphaseCollision(c,l)){if(!o.checkBounds(c,l,h))break;this.intersectionTest(c,l,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,c=0;c!==a;c++){var l=r[c],u=l.position.x;t+=u,e+=u*u;var p=l.position.y;i+=p,o+=p*p;var d=l.position.z;n+=d,s+=d*d}var y=e-t*t*h,v=o-i*i*h,m=s-n*n*h;y>v?y>m?this.axisIndex=0:this.axisIndex=2:v>m?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":23,"../shapes/Shape":62}],31:[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,c=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,c,o),this.collideConnected=!!i.collideConnected,this.angle="undefined"!=typeof i.angle?i.angle:0;var l=this.coneEquation=new s(t,e,i),u=this.twistEquation=new r(t,e,i);this.twistAngle="undefined"!=typeof i.twistAngle?i.twistAngle:0,l.maxForce=0,l.minForce=-o,u.maxForce=0,u.minForce=-o,this.equations.push(l,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":37,"../equations/ContactEquation":38,"../equations/RotationalEquation":41,"../math/Vec3":49,"./Constraint":32,"./PointToPointConstraint":36}],32:[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":72}],33:[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":38,"./Constraint":32}],34:[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,c=i.pivotB?i.pivotB.clone():new a;n.call(this,t,h,e,c,o);var l=this.axisA=i.axisA?i.axisA.clone():new a(1,0,0);l.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,c=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=c,l=this.axisA,u=this.axisB;n.prototype.update.call(this),t.quaternion.vmult(l,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":38,"../equations/RotationalEquation":41,"../equations/RotationalMotorEquation":42,"../math/Vec3":49,"./Constraint":32,"./PointToPointConstraint":36}],35:[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,c=new r;t.position.vadd(e.position,c),c.scale(.5,c),e.pointToLocalFrame(c,h),t.pointToLocalFrame(c,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 l=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(l,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":38,"../equations/RotationalEquation":41,"../equations/RotationalMotorEquation":42,"../math/Vec3":49,"./Constraint":32,"./PointToPointConstraint":36}],36:[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),c=this.equationY=new s(t,i),l=this.equationZ=new s(t,i);this.equations.push(h,c,l),h.minForce=c.minForce=l.minForce=-a,h.maxForce=c.maxForce=l.maxForce=a,h.ni.set(1,0,0),c.ni.set(0,1,0),l.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":38,"../math/Vec3":49,"./Constraint":32}],37:[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,c=this.jacobianElementA,l=this.jacobianElementB;o.cross(n,s),n.cross(o,h),c.rotational.copy(h),l.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":46,"../math/Vec3":49,"./Equation":39}],38:[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,c=this.rj,l=r,u=a,p=o.velocity,d=o.angularVelocity,y=(o.force,o.torque,n.velocity),v=n.angularVelocity,m=(n.force,n.torque,h),f=this.jacobianElementA,g=this.jacobianElementB,w=this.ni;s.cross(w,l),c.cross(w,u),w.negate(f.spatial),l.negate(f.rotational),g.spatial.copy(w),g.rotational.copy(u),m.copy(n.position),m.vadd(c,m),m.vsub(o.position,m),m.vsub(s,m);var b=w.dot(m),x=this.restitution+1,E=x*y.dot(w)-x*p.dot(w)+v.dot(u)-d.dot(l),A=this.computeGiMf(),C=-b*e-E*i-t*A;return C};var c=new s,l=new s,u=new s,p=new s,d=new s;
o.prototype.getImpactVelocityAlongNormal=function(){var t=c,e=l,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":46,"../math/Vec3":49,"./Equation":39}],39:[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,c=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,l=o.force,u=o.torque,p=i.invMassSolve,d=o.invMassSolve;return n.scale(p,r),l.scale(d,a),i.invInertiaWorldSolve.vmult(s,h),o.invInertiaWorldSolve.vmult(u,c),t.multiplyVectors(r,h)+e.multiplyVectors(a,c)};var l=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,l),h+=l.dot(t.rotational),a.vmult(e.rotational,l),h+=l.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":45,"../math/Vec3":49}],40:[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 c=this.jacobianElementA,l=this.jacobianElementB;h.negate(c.spatial),n.negate(c.rotational),l.spatial.copy(h),l.rotational.copy(s);var u=this.computeGW(),p=this.computeGiMf(),d=-u*e-t*p;return d}},{"../math/Mat3":46,"../math/Vec3":49,"./Equation":39}],41:[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,c=this.jacobianElementA,l=this.jacobianElementB;o.cross(n,s),n.cross(o,h),c.rotational.copy(h),l.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":46,"../math/Vec3":49,"./Equation":39}],42:[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":46,"../math/Vec3":49,"./Equation":39}],43:[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":72}],44:[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},{}],45:[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":49}],46:[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,c,l=3,u=l,p=4;do{if(r=u-l,0===s[r+o*r])for(a=r+1;a<u;a++)if(0!==s[r+o*a]){h=p;do c=p-h,s[c+o*r]+=s[c+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 c=p-h,s[c+o*a]=c<=r?0:s[c+o*a]-s[c+o*r]*d;while(--h)}}while(--l);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,c=3,l=c,u=i;do{if(s=l-c,0===n[s+i*s])for(r=s+1;r<l;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<l;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(--c);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,c=e*r,l=e*a,u=i*r,p=i*a,d=o*a,y=n*s,v=n*r,m=n*a,f=this.elements;return f[0]=1-(u+d),f[1]=c-m,f[2]=l+v,f[3]=c+m,f[4]=1-(h+d),f[5]=p-y,f[6]=l-v,f[7]=p+y,f[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":49}],47:[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,c=t.z,l=t.w;return e.x=i*l+r*a+n*c-s*h,e.y=n*l+r*h+s*a-i*c,e.z=s*l+r*c+i*h-n*a,e.w=r*l-i*a-n*h-s*c,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,c=this.w,l=c*i+a*s-h*o,u=c*o+h*i-r*s,p=c*s+r*o-a*i,d=-r*i-a*o-h*s;return e.x=l*c+d*-r+u*-h-p*-a,e.y=u*c+d*-a+p*-r-l*-h,e.z=p*c+d*-h+l*-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 c=s*r+a*h;if(c>.499&&(i=2*Math.atan2(s,h),o=Math.PI/2,n=0),c<-.499&&(i=-2*Math.atan2(s,h),o=-Math.PI/2,n=0),isNaN(i)){var l=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*c),n=Math.atan2(2*s*h-2*r*a,1-2*l-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),c=Math.sin(i/2);return"XYZ"===o?(this.x=a*s*r+n*h*c,this.y=n*h*r-a*s*c,this.z=n*s*c+a*h*r,this.w=n*s*r-a*h*c):"YXZ"===o?(this.x=a*s*r+n*h*c,this.y=n*h*r-a*s*c,this.z=n*s*c-a*h*r,this.w=n*s*r+a*h*c):"ZXY"===o?(this.x=a*s*r-n*h*c,this.y=n*h*r+a*s*c,this.z=n*s*c+a*h*r,this.w=n*s*r-a*h*c):"ZYX"===o?(this.x=a*s*r-n*h*c,this.y=n*h*r+a*s*c,this.z=n*s*c-a*h*r,this.w=n*s*r+a*h*c):"YZX"===o?(this.x=a*s*r+n*h*c,this.y=n*h*r+a*s*c,this.z=n*s*c-a*h*r,this.w=n*s*r-a*h*c):"XZY"===o&&(this.x=a*s*r-n*h*c,this.y=n*h*r-a*s*c,this.z=n*s*c+a*h*r,this.w=n*s*r+a*h*c),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,c=this.x,l=this.y,u=this.z,p=this.w,d=t.x,y=t.y,v=t.z,m=t.w;return s=c*d+l*y+u*v+p*m,s<0&&(s=-s,d=-d,y=-y,v=-v,m=-m),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*c+h*d,i.y=a*l+h*y,i.z=a*u+h*v,i.w=a*p+h*m,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,c=this.y,l=this.z,u=this.w,p=.5*e;return n.x+=p*(s*u+r*l-a*c),n.y+=p*(r*u+a*h-s*l),n.z+=p*(a*u+s*c-r*h),n.w+=p*(-s*h-r*c-a*l),n}},{"./Vec3":49}],48:[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":47,"./Vec3":49}],49:[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":46}],50:[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.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")),c=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 l=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=l,s=u,r=this.quaternion,a=this.aabb,h=p,c=0;c!==o;c++){var d=t[c];r.vmult(e[c],n),n.vadd(this.position,n),i[c].mult(r,s),d.calculateWorldAABB(n,s,h.lowerBound,h.upperBound),0===c?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 m=new s,f=new s;o.prototype.applyLocalForce=function(t,e){if(this.type===o.DYNAMIC){var i=m,n=f;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),c.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,c=this.quaternion,l=this.invMass,u=this.invInertiaWorld,p=this.linearFactor,d=l*t;n.x+=a.x*d*p.x,n.y+=a.y*d*p.y,n.z+=a.z*d*p.z;var y=u.elements,v=this.angularFactor,m=h.x*v.x,f=h.y*v.y,g=h.z*v.z;s.x+=t*(y[0]*m+y[1]*f+y[2]*g),s.y+=t*(y[3]*m+y[4]*f+y[5]*g),s.z+=t*(y[6]*m+y[7]*f+y[8]*g),r.x+=n.x*t,r.y+=n.y*t,r.z+=n.z*t,c.integrate(this.angularVelocity,t,this.angularFactor,c),e&&(i?c.normalizeFast():c.normalize()),this.aabbNeedsUpdate=!0,this.updateInertiaWorld()}}},{"../collision/AABB":21,"../material/Material":44,"../math/Mat3":46,"../math/Quaternion":47,"../math/Vec3":49,"../shapes/Box":56,"../shapes/Shape":62,"../utils/EventTarget":68}],51:[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,c=E,l=A;t.getVelocityAtWorldPoint(a,h),e.getVelocityAtWorldPoint(a,c),h.vsub(c,l);var u=o.dot(l),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=T,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=S,h=M,c=k;t.getVelocityAtWorldPoint(e,a),i.getVelocityAtWorldPoint(o,h),a.vsub(h,c);var l=n.dot(c),u=.2,p=1/(t.invMass+i.invMass),s=-u*l*p;return s}var a=(t("./Body"),t("../math/Vec3")),h=t("../math/Quaternion"),c=(t("../collision/RaycastResult"),t("../collision/Ray")),l=t("../objects/WheelInfo");e.exports=o;var u=(new a,new a,new a,new a),p=new a,d=new a;new c;o.prototype.addWheel=function(t){t=t||{};var e=new l(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 c=e[n],l=c.suspensionForce;l>c.maxSuspensionForce&&(l=c.maxSuspensionForce),c.raycastResult.hitNormalWorld.scale(l*t,r),c.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 c=e[n];o.getVelocityAtWorldPoint(c.chassisConnectionPointWorld,d);var y=1;switch(this.indexUpAxis){case 1:y=-1}if(c.isInContact){this.getVehicleAxisWorld(this.indexForwardAxis,p);var v=p.dot(c.raycastResult.hitNormalWorld);c.raycastResult.hitNormalWorld.scale(v,u),p.vsub(u,p);var m=p.dot(d);c.deltaRotation=y*m*t/c.radius}!c.sliding&&c.isInContact||0===c.engineForce||!c.useCustomSlidingRotationalSpeed||(c.deltaRotation=(c.engineForce>0?1:-1)*c.customSlidingRotationalSpeed*t),Math.abs(c.brake)>Math.abs(c.engineForce)&&(c.deltaRotation=0),c.rotation+=c.deltaRotation,c.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,c=r.suspensionLength,l=h-c;a=r.suspensionStiffness*l*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 c=o.collisionResponse;o.collisionResponse=!1,this.world.rayTest(r,i,h),o.collisionResponse=c;var l=h.body;if(t.raycastResult.groundObject=0,l){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 m=t.raycastResult.hitNormalWorld.dot(t.directionWorld),f=new a;o.getVelocityAtWorldPoint(t.raycastResult.hitPointWorld,f);var g=t.raycastResult.hitNormalWorld.dot(f);if(m>=-.1)t.suspensionRelativeVelocity=0,t.clippedInvContactDotSuspension=10;else{var w=-1/m;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 c=n.worldTransform.quaternion;this.chassisBody.quaternion.mult(r,c),c.mult(a,c),c.normalize();var l=n.worldTransform.position;l.copy(n.directionWorld),l.scale(n.suspensionLength,l),l.vadd(n.chassisConnectionPointWorld,l)};var m=[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 f=new a,g=[],w=[],b=1;o.prototype.updateFriction=function(t){for(var e=f,i=this.wheelInfos,o=i.length,s=this.chassisBody,h=w,c=g,l=0,u=0;u<o;u++){var p=i[u],d=p.raycastResult.body;d&&l++,p.sideImpulse=0,p.forwardImpulse=0,h[u]||(h[u]=new a),c[u]||(c[u]=new a)}for(var u=0;u<o;u++){var p=i[u],d=p.raycastResult.body;if(d){var y=c[u],v=this.getWheelTransformWorld(u);v.vectorToWorldFrame(m[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 T=0,R=p.brake?p.brake:T;B=n(s,d,p.raycastResult.hitPointWorld,h[u],R),B+=p.engineForce*t;var S=R/B;p.slipInfo*=S}if(p.forwardImpulse=0,p.skidInfo=1,d){p.skidInfo=1;var M=p.suspensionForce*t*p.frictionSlip,k=M,P=M*k;p.forwardImpulse=B;var N=p.forwardImpulse*C,L=p.sideImpulse*A,_=N*N+L*L;if(p.sliding=!1,_>P){this.sliding=!0,p.sliding=!0;var S=M/Math.sqrt(_);p.skidInfo*=S}}}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],z=new a;if(p.raycastResult.hitPointWorld.vsub(s.position,z),0!==p.forwardImpulse){var I=new a;h[u].scale(p.forwardImpulse,I),s.applyImpulse(I,z)}if(0!==p.sideImpulse){var d=p.raycastResult.body,F=new a;p.raycastResult.hitPointWorld.vsub(d.position,F);var V=new a;c[u].scale(p.sideImpulse,V),s.vectorToLocalFrame(z,z),z["xyz"[this.indexUpAxis]]*=p.rollInfluence,s.vectorToWorldFrame(z,z),s.applyImpulse(V,z),V.scale(-1,V),d.applyImpulse(V,F)}}};var x=new a,E=new a,A=new a,C=new a,B=new a,T=new a,R=new a,S=new a,M=new a,k=new a},{"../collision/Ray":28,"../collision/RaycastResult":29,"../math/Quaternion":47,"../math/Vec3":49,"../objects/WheelInfo":55,"./Body":50}],52:[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 c=new h(this.chassisBody,e,{pivotA:i,axisA:r,pivotB:a.ZERO,axisB:r,collideConnected:!1});return this.constraints.push(c),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 c=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,c),o.vectorToWorldFrame(c,c),n.vadd(c,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 l=new a;o.prototype.getWheelSpeed=function(t){var e=this.wheelAxes[t],i=this.wheelBodies[t],o=i.angularVelocity;return this.chassisBody.vectorToWorldFrame(e,l),o.dot(l)}},{"../constraints/HingeConstraint":34,"../math/Vec3":49,"../shapes/Box":56,"../shapes/Sphere":63,"./Body":50}],53:[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,c=new n,l=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 m=e.norm(),f=this.w(m);y+=p[v].mass*f}this.densities[n]=y,this.pressures[n]=i*i*(this.densities[n]-this.density)}for(var g=a,w=h,b=c,x=l,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 T=p[v];A.position.vsub(T.position,x);var R=x.norm();C=-T.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),T.velocity.vsub(A.velocity,E),E.mult(1/(1e-4+this.densities[n]*this.densities[v])*this.viscosity*T.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":44,"../math/Quaternion":47,"../math/Vec3":49,"../objects/Body":50,"../shapes/Particle":60,"../shapes/Shape":62}],54:[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,c=new n,l=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,m=s,f=r,g=a,w=h,b=v,x=c,E=l,A=u,C=p,B=d,T=y;this.getWorldAnchorA(x),this.getWorldAnchorB(E),x.vsub(o.position,A),E.vsub(n.position,C),E.vsub(x,m);var R=m.norm();f.copy(m),f.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),f.mult(-t*(R-i)-e*g.dot(f),w),o.force.vsub(w,o.force),n.force.vadd(w,n.force),A.cross(w,B),C.cross(w,T),o.torque.vsub(B,o.torque),n.torque.vadd(T,n.torque)}},{"../math/Vec3":49}],55:[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,c=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,c),t.getVelocityAtWorldPoint(c,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":29,"../math/Transform":48,"../math/Vec3":49,"../utils/Utils":72}],56:[function(t,e,i){function o(t){n.call(this),this.type=n.types.BOX,this.halfExtents=t,this.convexPolyhedronRepresentation=null,this.updateConvexPolyhedronRepresentation(),this.updateBoundingSphereRadius()}e.exports=o;var n=t("./Shape"),s=t("../math/Vec3"),r=t("./ConvexPolyhedron");o.prototype=new n,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,c=s.y,l=s.z;a>o.x&&(o.x=a),c>o.y&&(o.y=c),l>o.z&&(o.z=l),a<i.x&&(i.x=a),c<i.y&&(i.y=c),l<i.z&&(i.z=l)}}},{"../math/Vec3":49,"./ConvexPolyhedron":57,"./Shape":62}],57:[function(t,e,i){function o(t,e,i){n.call(this),this.type=n.types.CONVEXPOLYHEDRON,this.vertices=t||[],this.worldVertices=[],this.worldVerticesNeedsUpdate=!0,this.faces=e||[],this.faceNormals=[],this.computeNormals(),this.worldFaceNormalsNeedsUpdate=!0,this.worldFaceNormals=[],this.uniqueEdges=[],this.uniqueAxes=i?i.slice():null,this.computeEdges(),this.updateBoundingSphereRadius()}e.exports=o;var n=t("./Shape"),s=t("../math/Vec3"),r=(t("../math/Quaternion"),t("../math/Transform"));o.prototype=new n,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 c=(h+1)%r;e[s[h]].vsub(e[s[c]],o),o.normalize();for(var l=!1,u=0;u!==i.length;u++)if(i[u].almostEquals(o)||i[u].almostEquals(o)){l=!0;break}l||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,c=new s;o.computeNormal=function(t,e,i,o){e.vsub(t,c),i.vsub(e,h),h.cross(c,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 l=new s;o.prototype.clipAgainstHull=function(t,e,i,o,n,r,a,h,c){for(var u=l,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 m=[],f=i.faces[p],g=f.length,w=0;w<g;w++){var b=i.vertices[f[w]],x=new s;x.copy(b),n.vmult(x,x),o.vadd(x,x),m.push(x)}p>=0&&this.clipFaceAgainstHull(r,t,e,m,a,h,c)};var u=new s,p=new s,d=new s,y=new s,v=new s,m=new s;o.prototype.findSeparatingAxis=function(t,e,i,o,n,s,r,a){var h=u,c=p,l=d,f=y,g=v,w=m,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 T=r?r[A]:A;h.copy(x.faceNormals[T]),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],c),E++;var C=x.testSepAxis(c,t,e,i,o,n);if(C===!1)return!1;C<b&&(b=C,s.copy(c))}else for(var R=a?a.length:t.faces.length,A=0;A<R;A++){var T=a?a[A]:A;c.copy(t.faceNormals[T]),n.vmult(c,c),E++;var C=x.testSepAxis(c,t,e,i,o,n);if(C===!1)return!1;C<b&&(b=C,s.copy(c))}for(var S=0;S!==x.uniqueEdges.length;S++){i.vmult(x.uniqueEdges[S],f);for(var M=0;M!==t.uniqueEdges.length;M++)if(n.vmult(t.uniqueEdges[M],g),f.cross(g,w),!w.almostZero()){w.normalize();var k=x.testSepAxis(w,t,e,i,o,n);if(k===!1)return!1;k<b&&(b=k,s.copy(w))}}return o.vsub(e,l),l.dot(s)>0&&s.negate(s),!0};var f=[],g=[];o.prototype.testSepAxis=function(t,e,i,n,s,r){var a=this;o.project(a,t,i,n,f),o.project(e,t,s,r,g);var h=f[0],c=f[1],l=g[0],u=g[1];if(h<u||l<c)return!1;var p=h-u,d=l-c,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,T=new s,R=new s,S=new s;o.prototype.clipFaceAgainstHull=function(t,e,i,o,n,s,r){for(var a=x,h=E,c=A,l=C,u=B,p=T,d=R,y=S,v=this,m=[],f=o,g=m,w=-1,b=Number.MAX_VALUE,M=0;M<v.faces.length;M++){a.copy(v.faceNormals[M]),i.vmult(a,a);var k=a.dot(t);k<b&&(b=k,w=M)}if(!(w<0)){var P=v.faces[w];P.connectedFaces=[];for(var N=0;N<v.faces.length;N++)for(var L=0;L<v.faces[N].length;L++)P.indexOf(v.faces[N][L])!==-1&&N!==w&&P.connectedFaces.indexOf(N)===-1&&P.connectedFaces.push(N);for(var _=(f.length,P.length),z=0;z<_;z++){var I=v.vertices[P[z]],F=v.vertices[P[(z+1)%_]];I.vsub(F,h),c.copy(h),i.vmult(c,c),e.vadd(c,c),l.copy(this.faceNormals[w]),i.vmult(l,l),e.vadd(l,l),c.cross(l,u),u.negate(u),p.copy(I),i.vmult(p,p),e.vadd(p,p);var V,q=(-p.dot(u),P.connectedFaces[z]);d.copy(this.faceNormals[q]);var j=this.getPlaneConstantOfFace(q);y.copy(d),i.vmult(y,y);var V=j-y.dot(e);for(this.clipFaceAgainstPlane(f,g,y,V);f.length;)f.shift();for(;g.length;)f.push(g.shift())}d.copy(this.faceNormals[w]);var j=this.getPlaneConstantOfFace(w);y.copy(d),i.vmult(y,y);for(var V=j-y.dot(e),N=0;N<f.length;N++){var H=y.dot(f[N])+V;if(H<=n&&(console.log("clamped: depth="+H+" to minDist="+(n+"")),H=n),H<=s){var O=f[N];if(H<=0){var D={point:O,normal:y,depth:H};r.push(D)}}}}},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],c=t[0];n=i.dot(h)+o;for(var l=0;l<a;l++){if(c=t[l],r=i.dot(c)+o,n<0)if(r<0){var u=new s;u.copy(c),e.push(u)}else{var u=new s;h.lerp(c,n/(n-r),u),e.push(u)}else if(r<0){var u=new s;h.lerp(c,n/(n-r),u),e.push(u),e.push(c)}h=c,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 M=new s;o.prototype.calculateWorldAABB=function(t,e,i,o){for(var n,s,r,a,h,c,l=this.vertices.length,u=this.vertices,p=0;p<l;p++){M.copy(u[p]),e.vmult(M,M),t.vadd(M,M);var d=M;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>c||void 0===c)&&(c=d.z)}i.set(n,s,r),o.set(a,h,c)},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 k=new s,P=new s,N=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=k;this.getAveragePointLocal(a);for(var h=0;h<r;h++){var e=(this.faces[h].length,n[h]),c=i[o[h][0]],l=P;t.vsub(c,l);var u=e.dot(l),p=N;a.vsub(c,p);var d=e.dot(p);if(u<0&&d>0||u>0&&d<0)return!1}return s?1:-1};var L=(new s,new s),_=new s;o.project=function(t,e,i,o,n){var s=t.vertices.length,a=L,h=0,c=0,l=_,u=t.vertices;l.setZero(),r.vectorToLocalFrame(i,o,e,a),r.pointToLocalFrame(i,o,l,l);var p=l.dot(a);c=h=u[0].dot(a);for(var d=1;d<s;d++){var y=u[d].dot(a);y>h&&(h=y),y<c&&(c=y)}if(c-=p,h-=p,c>h){var v=c;c=h,h=v}n[0]=h,n[1]=c}},{"../math/Quaternion":47,"../math/Transform":48,"../math/Vec3":49,"./Shape":62}],58:[function(t,e,i){function o(t,e,i,o){var a=o,h=[],c=[],l=[],u=[],p=[],d=Math.cos,y=Math.sin;h.push(new s(e*d(0),e*y(0),.5*-i)),u.push(0),h.push(new s(t*d(0),t*y(0),.5*i)),p.push(1);for(var v=0;v<a;v++){var m=2*Math.PI/a*(v+1),f=2*Math.PI/a*(v+.5);v<a-1?(h.push(new s(e*d(m),e*y(m),.5*-i)),u.push(2*v+2),h.push(new s(t*d(m),t*y(m),.5*i)),p.push(2*v+3),l.push([2*v+2,2*v+3,2*v+1,2*v])):l.push([0,1,2*v+1,2*v]),(a%2===1||v<a/2)&&c.push(new s(d(f),y(f),0))}l.push(p),c.push(new s(0,0,1));for(var g=[],v=0;v<u.length;v++)g.push(u[u.length-v-1]);l.push(g),this.type=n.types.CONVEXPOLYHEDRON,r.call(this,h,l,c)}e.exports=o;var n=t("./Shape"),s=t("../math/Vec3"),r=(t("../math/Quaternion"),t("./ConvexPolyhedron"));o.prototype=new r},{"../math/Quaternion":47,"../math/Vec3":49,"./ConvexPolyhedron":57,"./Shape":62}],59:[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),this.pillarConvex=new r,this.pillarOffset=new a,this.type=s.types.HEIGHTFIELD,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 c=s[a][h];c>r&&(r=c)}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 c=[],l=new a,u=new a,p=new a,d=new a;o.prototype.getTriangleAt=function(t,e,i,o,n,s){var r=c;this.getIndexOfPosition(t,e,r,i);var a=r[0],h=r[1],l=this.data;i&&(a=Math.min(l.length-2,Math.max(0,a)),h=Math.min(l[0].length-2,Math.max(0,h)));var u=this.elementSize,p=Math.pow(t/u-a,2)+Math.pow(e/u-h,2),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,m=new a,f=new a,g=new a;o.prototype.getNormalAt=function(t,e,i,o){var n=y,s=v,r=m,a=f,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=c;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 m=this.getTriangleAt(t,e,i,s,r,a);n(t,e,s.x,s.y,r.x,r.y,a.x,a.y,l);var f=l;return m?o[y+1][v+1]*f.x+o[y][v+1]*f.y+o[y+1][v]*f.z:o[y][v]*f.x+o[y+1][v]*f.y+o[y][v+1]*f.z},o.prototype.getCacheConvexTrianglePillarKey=function(t,e,i){return t+"_"+e+"_"+(i?1:0)},o.prototype.getCachedConvexTrianglePillar=function(t,e,i){return this._cachedPillars[this.getCacheConvexTrianglePillarKey(t,e,i)]},o.prototype.setCachedConvexTrianglePillar=function(t,e,i,o,n){this._cachedPillars[this.getCacheConvexTrianglePillarKey(t,e,i)]={convex:o,offset:n}},o.prototype.clearCachedConvexTrianglePillar=function(t,e,i){delete this._cachedPillars[this.getCacheConvexTrianglePillarKey(t,e,i)]},o.prototype.getTriangle=function(t,e,i,o,n,s){var r=this.data,a=this.elementSize;i?(o.set((t+1)*a,(e+1)*a,r[t+1][e+1]),n.set(t*a,(e+1)*a,r[t][e+1]),s.set((t+1)*a,e*a,r[t+1][e])):(o.set(t*a,e*a,r[t][e]),n.set((t+1)*a,e*a,r[t+1][e]),s.set(t*a,(e+1)*a,r[t][e+1]))},o.prototype.getConvexTrianglePillar=function(t,e,i){var o=this.pillarConvex,n=this.pillarOffset;if(this.cacheEnabled){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,c=o.faces;o.vertices.length=6;for(var l=0;l<6;l++)o.vertices[l]||(o.vertices[l]=new a);c.length=5;for(var l=0;l<5;l++)c[l]||(c[l]=[]);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),c[0][0]=0,c[0][1]=1,c[0][2]=2,c[1][0]=5,c[1][1]=4,c[1][2]=3,c[2][0]=2,c[2][1]=5,c[2][2]=3,c[2][3]=0,c[3][0]=3,c[3][1]=4,c[3][2]=1,c[3][3]=0,c[4][0]=1,c[4][1]=4,c[4][2]=5,c[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),c[0][0]=0,c[0][1]=1,c[0][2]=2,c[1][0]=5,c[1][1]=4,c[1][2]=3,c[2][0]=0,c[2][1]=2,c[2][2]=5,c[2][3]=3,c[3][0]=1,c[3][1]=0,c[3][2]=3,c[3][3]=4,c[4][0]=4,c[4][1]=5,c[4][2]=2,c[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 c=n.data[4*(r*n.height+h)],l=n.data[4*(r*n.height+h)+1],u=n.data[4*(r*n.height+h)+2],p=(c+l+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":49,"../utils/Utils":72,"./ConvexPolyhedron":57,"./Shape":62}],60:[function(t,e,i){function o(){n.call(this),this.type=n.types.PARTICLE}e.exports=o;var n=t("./Shape"),s=t("../math/Vec3");o.prototype=new n,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":49,"./Shape":62}],61:[function(t,e,i){function o(){n.call(this),this.type=n.types.PLANE,this.worldNormal=new s,this.worldNormalNeedsUpdate=!0,this.boundingSphereRadius=Number.MAX_VALUE}e.exports=o;var n=t("./Shape"),s=t("../math/Vec3");o.prototype=new n,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":49,"./Shape":62}],62:[function(t,e,i){function o(){this.id=o.idCounter++,this.type=0,this.boundingSphereRadius=0,this.collisionResponse=!0,this.material=null,this.body=null}e.exports=o;var o=t("./Shape");t("../math/Vec3"),t("../math/Quaternion"),t("../material/Material");o.prototype.constructor=o,o.prototype.updateBoundingSphereRadius=function(){throw"computeBoundingSphereRadius() not implemented for shape type "+this.type},o.prototype.volume=function(){throw"volume() not implemented for shape type "+this.type},o.prototype.calculateLocalInertia=function(t,e){throw"calculateLocalInertia() not implemented for shape type "+this.type},o.idCounter=0,o.types={SPHERE:1,PLANE:2,BOX:4,COMPOUND:8,CONVEXPOLYHEDRON:16,HEIGHTFIELD:32,PARTICLE:64,CYLINDER:128,TRIMESH:256}},{"../material/Material":44,"../math/Quaternion":47,"../math/Vec3":49,"./Shape":62}],63:[function(t,e,i){function o(t){if(n.call(this),this.radius=void 0!==t?Number(t):1,this.type=n.types.SPHERE,this.radius<0)throw new Error("The sphere radius cannot be negative.");this.updateBoundingSphereRadius()}e.exports=o;var n=t("./Shape"),s=t("../math/Vec3");o.prototype=new n,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":49,"./Shape":62}],64:[function(t,e,i){function o(t,e){n.call(this),this.type=n.types.TRIMESH,this.vertices=new Float32Array(t),this.indices=new Int16Array(e),this.normals=new Float32Array(e.length),this.aabb=new a,this.edges=null,this.scale=new s(1,1,1),this.tree=new h,this.updateEdges(),this.updateNormals(),this.updateAABB(),this.updateBoundingSphereRadius(),this.updateTree()}e.exports=o;var n=t("./Shape"),s=t("../math/Vec3"),r=(t("../math/Quaternion"),t("../math/Transform")),a=t("../collision/AABB"),h=t("../utils/Octree");o.prototype=new n,o.prototype.constructor=o;var c=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],c=0;c<this.indices.length/3;c++){var l=3*c;this._getUnscaledVertex(this.indices[l],o),this._getUnscaledVertex(this.indices[l+1],n),this._getUnscaledVertex(this.indices[l+2],r),i.setFromPoints(h),t.insert(i,c)}t.removeEmptyNodes()};var l=new a;o.prototype.getTrianglesInAABB=function(t,e){l.copy(t);var i=this.scale,o=i.x,n=i.y,s=i.z,r=l.lowerBound,a=l.upperBound;return r.x/=o,r.y/=n,r.z/=s,a.x/=o,a.y/=n,a.z/=s,this.tree.aabbQuery(l,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=c,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,m),this.getVertex(a,f),o.computeNormal(m,v,f,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,m=new s,f=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 c=0;c<=n;c++){var l=c/n*s,u=h/i*Math.PI*2,p=(t+e*Math.cos(u))*Math.cos(l),d=(t+e*Math.cos(u))*Math.sin(l),y=e*Math.sin(u);r.push(p,d,y)}for(var h=1;h<=i;h++)for(var c=1;c<=n;c++){var v=(n+1)*h+c-1,m=(n+1)*(h-1)+c-1,f=(n+1)*(h-1)+c,g=(n+1)*h+c;a.push(v,m,g),a.push(m,f,g)}return new o(r,a)}},{"../collision/AABB":21,"../math/Quaternion":47,"../math/Transform":48,"../math/Vec3":49,"../utils/Octree":69,"./Shape":62}],65:[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,c,l,u=0,p=this.iterations,d=this.tolerance*this.tolerance,y=this.equations,v=y.length,m=e.bodies,f=m.length,g=t;if(0!==v)for(var w=0;w!==f;w++)m[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!==f;w++){var C=m[w],B=C.vlambda,T=C.wlambda;B.set(0,0,0),T.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],l=E[R],c=A.computeGWlambda(),n=o*(i-c-A.eps*l),l+n<A.minForce?n=A.minForce-l:l+n>A.maxForce&&(n=A.maxForce-l),E[R]+=n,h+=n>0?n:-n,A.addToWlambda(n)}if(h*h<d)break}for(var w=0;w!==f;w++){var C=m[w],S=C.velocity,M=C.angularVelocity;C.vlambda.vmul(C.linearFactor,C.vlambda),S.vadd(C.vlambda,S),C.wlambda.vmul(C.angularFactor,C.wlambda),M.vadd(C.wlambda,M)}for(var k=y.length,P=1/g;k--;)y[k].multiplier=E[k]*P}return u}},{"../math/Quaternion":47,"../math/Vec3":49,"./Solver":66}],66:[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}},{}],67:[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")),c=t("../objects/Body");o.prototype=new h;var l=[],u=[],p={bodies:[]},d=c.STATIC,y=[];o.prototype.createNode=function(){return{body:null,children:[],eqs:[],visited:!1}},o.prototype.solve=function(t,e){for(var i=l,o=this.nodePool,h=e.bodies,c=this.equations,d=c.length,y=h.length,v=this.subsolver;o.length<y;)o.push(this.createNode());i.length=y;for(var m=0;m<y;m++)i[m]=o[m];for(var m=0;m!==y;m++){var f=i[m];f.body=h[m],f.children.length=0,f.eqs.length=0,f.visited=!1}for(var g=0;g!==d;g++){var w=c[g],m=h.indexOf(w.bi),b=h.indexOf(w.bj),x=i[m],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 T=p;A=n(i);){B.length=0,T.bodies.length=0,s(A,r,T.bodies,B);var R=B.length;B=B.sort(a);for(var m=0;m!==R;m++)v.addEquation(B[m]);v.solve(t,T);v.removeAllEquations(),C++}return C}},{"../math/Quaternion":47,"../math/Vec3":49,"../objects/Body":50,"./Solver":66}],68:[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}}},{}],69:[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,c=0;8!==c;c++){var l=n[c];l.root=h;var u=l.aabb.lowerBound;u.x*=a.x,u.y*=a.y,u.z*=a.z,u.vadd(e,u),u.vadd(a,l.aabb.upperBound)}},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":21,"../math/Vec3":49}],70:[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}},{}],71:[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]}}},{}],72:[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}},{}],73:[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":49,"./Pool":70}],74:[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=O;t[(s+1)%n].vsub(r,a);var h=D;a.cross(e,h);var c=W;i.vsub(r,c);var l=h.dot(c);if(!(null===o||l>0&&o===!0||l<=0&&o===!1))return!1;null===o&&(o=l>0)}return!0}e.exports=o;var s=t("../collision/AABB"),r=t("../objects/Body"),a=t("../shapes/Shape"),h=t("../collision/Ray"),c=t("../math/Vec3"),l=t("../math/Transform"),u=(t("../shapes/ConvexPolyhedron"),t("../math/Quaternion")),p=(t("../solver/Solver"),t("../utils/Vec3Pool")),d=t("../equations/ContactEquation"),y=t("../equations/FrictionEquation");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,c=o.material||e.material;return h&&c&&h.restitution>=0&&c.restitution>=0&&(r.restitution=h.restitution*c.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,c=n.material||i.material,l=s.material||o.material;if(c&&l&&c.friction>=0&&l.friction>=0&&(h=c.friction*l.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),m=d.length?d.pop():new y(i,o,u*p);return v.bi=m.bi=i,v.bj=m.bj=o,v.minForce=m.minForce=-u*p,v.maxForce=m.maxForce=u*p,v.ri.copy(t.ri),v.rj.copy(t.rj),m.ri.copy(t.ri),m.rj.copy(t.rj),t.ni.tangents(v.t,m.t),v.setSpookParams(a.frictionEquationStiffness,a.frictionEquationRelaxation,r.dt),m.setSpookParams(a.frictionEquationStiffness,a.frictionEquationRelaxation,r.dt),v.enabled=m.enabled=t.enabled,e.push(v,m),!0}return!1};var v=new c,m=new c,f=new c;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(),m.setZero(),f.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),m.vadd(e.ri,m),f.vadd(e.rj,f)):(v.vsub(e.ni,v),m.vadd(e.rj,m),f.vadd(e.ri,f));var r=1/t;m.scale(r,i.ri),f.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 c,w=new c,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,c=x,l=g,u=w,p=0,d=t.length;p!==d;p++){var y=t[p],v=e[p],m=null;y.material&&v.material&&(m=i.getContactMaterial(y.material,v.material)||null);for(var f=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],l),l.vadd(y.position,l);for(var A=y.shapes[E],C=0;C<v.shapes.length;C++){v.quaternion.mult(v.shapeOrientations[C],c),v.quaternion.vmult(v.shapeOffsets[C],u),u.vadd(v.position,u);var B=v.shapes[C];if(!(l.distanceTo(u)>A.boundingSphereRadius+B.boundingSphereRadius)){var T=null;A.material&&B.material&&(T=i.getContactMaterial(A.material,B.material)||null),this.currentContactMaterial=T||m||i.defaultContactMaterial;var R=this[A.type|B.type];if(R){var S=!1;S=A.type<B.type?R.call(this,A,B,l,u,h,c,y,v,A,B,f):R.call(this,B,A,u,l,c,h,v,y,A,B,f),S&&f&&(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,c,l){return t.convexPolyhedronRepresentation.material=t.material,e.convexPolyhedronRepresentation.material=e.material,t.convexPolyhedronRepresentation.collisionResponse=t.collisionResponse,e.convexPolyhedronRepresentation.collisionResponse=e.collisionResponse,this.convexConvex(t.convexPolyhedronRepresentation,e.convexPolyhedronRepresentation,i,o,n,s,r,a,t,e,l)},o.prototype[a.types.BOX|a.types.CONVEXPOLYHEDRON]=o.prototype.boxConvex=function(t,e,i,o,n,s,r,a,h,c,l){return t.convexPolyhedronRepresentation.material=t.material,t.convexPolyhedronRepresentation.collisionResponse=t.collisionResponse,this.convexConvex(t.convexPolyhedronRepresentation,e,i,o,n,s,r,a,t,e,l)},o.prototype[a.types.BOX|a.types.PARTICLE]=o.prototype.boxParticle=function(t,e,i,o,n,s,r,a,h,c,l){return t.convexPolyhedronRepresentation.material=t.material,t.convexPolyhedronRepresentation.collisionResponse=t.collisionResponse,this.convexParticle(t.convexPolyhedronRepresentation,e,i,o,n,s,r,a,t,e,l)},o.prototype[a.types.SPHERE]=o.prototype.sphereSphere=function(t,e,i,o,n,s,r,a,h,c,l){if(l)return i.distanceSquared(o)<Math.pow(t.radius+e.radius,2);var u=this.createContactEquation(r,a,t,e,h,c);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 c,A=new c,C=new c;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 c,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 m=new c;m.copy(d),l.pointToWorldFrame(o,s,m,d);var f=A;d.vsub(i,f);var g=y.dot(f);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(f.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 c,T=new c,R=(new c,new c),S=new c,M=new c,k=new c,P=new c,N=new c,L=new c,_=new c,z=new c,I=new c,F=new c,V=new s,q=[];o.prototype[a.types.SPHERE|a.types.TRIMESH]=o.prototype.sphereTrimesh=function(t,e,i,o,n,s,r,a,c,u,p){var d=M,y=k,v=P,m=N,f=L,g=_,w=V,b=S,x=T,E=q;l.pointToLocalFrame(o,s,i,f);var A=t.radius;w.lowerBound.set(f.x-A,f.y-A,f.z-A),w.upperBound.set(f.x+A,f.y+A,f.z+A),e.getTrianglesInAABB(w,E);for(var C=R,j=t.radius*t.radius,H=0;H<E.length;H++)for(var O=0;O<3;O++)if(e.getVertex(e.indices[3*E[H]+O],C),C.vsub(f,x),x.norm2()<=j){if(b.copy(C),l.pointToWorldFrame(o,s,b,C),C.vsub(i,x),p)return!0;var D=this.createContactEquation(r,a,t,e,c,u);D.ni.copy(x),D.ni.normalize(),D.ri.copy(D.ni),D.ri.scale(t.radius,D.ri),D.ri.vadd(i,D.ri),D.ri.vsub(r.position,D.ri),D.rj.copy(C),D.rj.vsub(a.position,D.rj),this.result.push(D),this.createFrictionEquationsFromContact(D,this.frictionResult)}for(var H=0;H<E.length;H++)for(var O=0;O<3;O++){e.getVertex(e.indices[3*E[H]+O],d),e.getVertex(e.indices[3*E[H]+(O+1)%3],y),y.vsub(d,v),f.vsub(y,g);var W=g.dot(v);f.vsub(d,g);var K=g.dot(v);if(K>0&&W<0){f.vsub(d,g),m.copy(v),m.normalize(),K=g.dot(m),m.scale(K,g),g.vadd(d,g);var U=g.distanceTo(f);if(U<t.radius){if(p)return!0;var D=this.createContactEquation(r,a,t,e,c,u);g.vsub(f,D.ni),D.ni.normalize(),D.ni.scale(t.radius,D.ri),l.pointToWorldFrame(o,s,g,g),g.vsub(a.position,D.rj),l.vectorToWorldFrame(s,D.ni,D.ni),l.vectorToWorldFrame(s,D.ri,D.ri),this.result.push(D),this.createFrictionEquationsFromContact(D,this.frictionResult)}}}for(var G=z,X=I,Y=F,Q=B,H=0,Z=E.length;H!==Z;H++){e.getTriangleVertices(E[H],G,X,Y),e.getNormal(E[H],Q),f.vsub(G,g);var U=g.dot(Q);if(Q.scale(U,g),f.vsub(g,g),U=g.distanceTo(f),h.pointInTriangle(g,G,X,Y)&&U<t.radius){if(p)return!0;var D=this.createContactEquation(r,a,t,e,c,u);g.vsub(f,D.ni),D.ni.normalize(),D.ni.scale(t.radius,D.ri),l.pointToWorldFrame(o,s,g,g),g.vsub(a.position,D.rj),l.vectorToWorldFrame(s,D.ni,D.ni),l.vectorToWorldFrame(s,D.ri,D.ri),this.result.push(D),this.createFrictionEquationsFromContact(D,this.frictionResult)}}E.length=0};var j=new c,H=new c;o.prototype[a.types.SPHERE|a.types.PLANE]=o.prototype.spherePlane=function(t,e,i,o,n,s,r,a,h,c,l){var u=this.createContactEquation(r,a,t,e,h,c);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,j),u.ni.mult(u.ni.dot(j),H),j.vsub(H,u.rj),-j.dot(u.ni)<=t.radius){if(l)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 O=new c,D=new c,W=new c,K=new c,U=new c,G=new c,X=new c,Y=[new c,new c,new c,new c,new c,new c],Q=new c,Z=new c,J=new c,$=new c;o.prototype[a.types.SPHERE|a.types.BOX]=o.prototype.sphereBox=function(t,e,i,o,n,s,r,a,h,c,l){var u=this.v3pool,p=Y;i.vsub(o,K),e.getSideNormals(p,s);for(var d=t.radius,y=!1,v=Z,m=J,f=$,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 T=B.norm();B.normalize();var R=K.dot(B);if(R<T+d&&R>0){var S=G,M=X;S.copy(p[(A+1)%3]),M.copy(p[(A+2)%3]);var k=S.norm(),P=M.norm();S.normalize(),M.normalize();var N=K.dot(S),L=K.dot(M);if(N<k&&N>-k&&L<P&&L>-P){var _=Math.abs(R-T-d);if((null===E||_<E)&&(E=_,b=N,x=L,g=T,v.copy(B),m.copy(S),f.copy(M),w++,l))return!0}}}if(w){y=!0;var z=this.createContactEquation(r,a,t,e,h,c);v.mult(-d,z.ri),z.ni.copy(v),z.ni.negate(z.ni),v.mult(g,v),m.mult(b,m),v.vadd(m,v),f.mult(x,f),v.vadd(f,z.rj),z.ri.vadd(i,z.ri),z.ri.vsub(r.position,z.ri),z.rj.vadd(o,z.rj),z.rj.vsub(a.position,z.rj),this.result.push(z),this.createFrictionEquationsFromContact(z,this.frictionResult)}for(var I=u.get(),F=Q,V=0;2!==V&&!y;V++)for(var q=0;2!==q&&!y;q++)for(var j=0;2!==j&&!y;j++)if(I.set(0,0,0),V?I.vadd(p[0],I):I.vsub(p[0],I),q?I.vadd(p[1],I):I.vsub(p[1],I),j?I.vadd(p[2],I):I.vsub(p[2],I),o.vadd(I,F),F.vsub(i,F),F.norm2()<d*d){if(l)return!0;y=!0;var z=this.createContactEquation(r,a,t,e,h,c);z.ri.copy(F),z.ri.normalize(),z.ni.copy(z.ri),z.ri.mult(d,z.ri),z.rj.copy(I),z.ri.vadd(i,z.ri),z.ri.vsub(r.position,z.ri),z.rj.vadd(o,z.rj),z.rj.vsub(a.position,z.rj),this.result.push(z),this.createFrictionEquationsFromContact(z,this.frictionResult)}u.release(I),I=null;for(var H=u.get(),O=u.get(),z=u.get(),D=u.get(),_=u.get(),W=p.length,V=0;V!==W&&!y;V++)for(var q=0;q!==W&&!y;q++)if(V%3!==q%3){p[q].cross(p[V],H),H.normalize(),p[V].vadd(p[q],O),z.copy(i),z.vsub(O,z),z.vsub(o,z);var tt=z.dot(H);H.mult(tt,D);for(var j=0;j===V%3||j===q%3;)j++;_.copy(i),_.vsub(D,_),_.vsub(O,_),_.vsub(o,_);var et=Math.abs(tt),it=_.norm();if(et<p[j].norm()&&it<d){if(l)return!0;y=!0;var ot=this.createContactEquation(r,a,t,e,h,c);O.vadd(D,ot.rj),ot.rj.copy(ot.rj),_.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(H,O,z,D,_)};var tt=new c,et=new c,it=new c,ot=new c,nt=new c,st=new c,rt=new c,at=new c,ht=new c,ct=new c;o.prototype[a.types.SPHERE|a.types.CONVEXPOLYHEDRON]=o.prototype.sphereConvex=function(t,e,i,o,s,r,a,h,c,l,u){var p=this.v3pool;i.vsub(o,tt);for(var d=e.faceNormals,y=e.faces,v=e.vertices,m=t.radius,f=0;f!==v.length;f++){var g=v[f],w=nt;r.vmult(g,w),o.vadd(w,w);var b=ot;if(w.vsub(i,b),b.norm2()<m*m){if(u)return!0;E=!0;var x=this.createContactEquation(a,h,t,e,c,l);return x.ri.copy(b),x.ri.normalize(),x.ni.copy(x.ri),x.ri.mult(m,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,f=0,A=y.length;f!==A&&E===!1;f++){var C=d[f],B=y[f],T=st;r.vmult(C,T);var R=rt;r.vmult(v[B[0]],R),R.vadd(o,R);var S=at;T.mult(-m,S),i.vadd(S,S);var M=ht;S.vsub(R,M);var k=M.dot(T),P=ct;if(i.vsub(R,P),k<0&&P.dot(T)>0){for(var N=[],L=0,_=B.length;L!==_;L++){var z=p.get();r.vmult(v[B[L]],z),o.vadd(z,z),N.push(z)}if(n(N,T,i)){if(u)return!0;E=!0;var x=this.createContactEquation(a,h,t,e,c,l);T.mult(-m,x.ri),T.negate(x.ni);var I=p.get();T.mult(-k,I);var F=p.get();T.mult(-m,F),i.vsub(o,x.rj),x.rj.vadd(F,x.rj),x.rj.vadd(I,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(I),p.release(F),this.result.push(x),this.createFrictionEquationsFromContact(x,this.frictionResult);for(var L=0,V=N.length;L!==V;L++)p.release(N[L]);return}for(var L=0;L!==B.length;L++){var q=p.get(),j=p.get();r.vmult(v[B[(L+1)%B.length]],q),r.vmult(v[B[(L+2)%B.length]],j),o.vadd(q,q),o.vadd(j,j);var H=et;j.vsub(q,H);var O=it;H.unit(O);var D=p.get(),W=p.get();i.vsub(q,W);var K=W.dot(O);O.mult(K,D),D.vadd(q,D);var U=p.get();if(D.vsub(i,U),K>0&&K*K<H.norm2()&&U.norm2()<m*m){if(u)return!0;var x=this.createContactEquation(a,h,t,e,c,l);D.vsub(o,x.rj),D.vsub(i,x.ni),x.ni.normalize(),x.ni.mult(m,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 L=0,V=N.length;L!==V;L++)p.release(N[L]);return p.release(q),p.release(j),p.release(D),p.release(U),void p.release(W)}p.release(q),p.release(j),p.release(D),p.release(U),p.release(W)}for(var L=0,V=N.length;L!==V;L++)p.release(N[L])}}};new c,new c;o.prototype[a.types.PLANE|a.types.BOX]=o.prototype.planeBox=function(t,e,i,o,n,s,r,a,h,c,l){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,l)};var lt=new c,ut=new c,pt=new c,dt=new c;o.prototype[a.types.PLANE|a.types.CONVEXPOLYHEDRON]=o.prototype.planeConvex=function(t,e,i,o,n,s,r,a,h,c,l){var u=lt,p=ut;p.set(0,0,1),n.vmult(p,p);for(var d=0,y=pt,v=0;v!==e.vertices.length;v++){u.copy(e.vertices[v]),s.vmult(u,u),o.vadd(u,u),u.vsub(i,y);var m=p.dot(y);if(m<=0){if(l)return!0;var f=this.createContactEquation(r,a,t,e,h,c),g=dt;p.mult(p.dot(y),g),u.vsub(g,g),g.vsub(i,f.ri),f.ni.copy(p),u.vsub(o,f.rj),f.ri.vadd(i,f.ri),f.ri.vsub(r.position,f.ri),f.rj.vadd(o,f.rj),f.rj.vsub(a.position,f.rj),this.result.push(f),d++,this.enableFrictionReduction||this.createFrictionEquationsFromContact(f,this.frictionResult)}}this.enableFrictionReduction&&d&&this.createFrictionFromAverage(d)};var yt=new c,vt=new c;o.prototype[a.types.CONVEXPOLYHEDRON]=o.prototype.convexConvex=function(t,e,i,o,n,s,r,a,h,c,l,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 m=0,f=0;f!==y.length;f++){if(l)return!0;var g=this.createContactEquation(r,a,t,e,h,c),w=g.ri,b=g.rj;d.negate(g.ni),y[f].normal.negate(v),v.mult(y[f].depth,v),y[f].point.vadd(v,w),b.copy(y[f].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),m++,this.enableFrictionReduction||this.createFrictionEquationsFromContact(g,this.frictionResult)}this.enableFrictionReduction&&m&&this.createFrictionFromAverage(m)}};var mt=new c,ft=new c,gt=new c;o.prototype[a.types.PLANE|a.types.PARTICLE]=o.prototype.planeParticle=function(t,e,i,o,n,s,r,a,h,c,l){var u=mt;u.set(0,0,1),r.quaternion.vmult(u,u);var p=ft;o.vsub(r.position,p);var d=u.dot(p);if(d<=0){if(l)return!0;var y=this.createContactEquation(a,r,e,t,h,c);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 c;o.prototype[a.types.PARTICLE|a.types.SPHERE]=o.prototype.sphereParticle=function(t,e,i,o,n,s,r,a,h,c,l){var u=wt;u.set(0,0,1),o.vsub(i,u);var p=u.norm2();if(p<=t.radius*t.radius){if(l)return!0;var d=this.createContactEquation(a,r,e,t,h,c);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 c,Et=(new c,new c),At=new c,Ct=new c;o.prototype[a.types.PARTICLE|a.types.CONVEXPOLYHEDRON]=o.prototype.convexParticle=function(t,e,i,o,n,s,r,a,h,c,l){var u=-1,p=Et,d=Ct,y=null,v=0,m=xt;if(m.copy(o),m.vsub(i,m),n.conjugate(bt),bt.vmult(m,m),t.pointIsInside(m)){t.worldVerticesNeedsUpdate&&t.computeWorldVertices(i,n),t.worldFaceNormalsNeedsUpdate&&t.computeWorldFaceNormals(n);for(var f=0,g=t.faces.length;f!==g;f++){var w=[t.worldVertices[t.faces[f][0]]],b=t.worldFaceNormals[f];o.vsub(w[0],At);var x=-b.dot(At);if(null===y||Math.abs(x)<Math.abs(y)){if(l)return!0;y=x,u=f,p.copy(b),v++}}if(u!==-1){var E=this.createContactEquation(a,r,e,t,h,c);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,c,l){return t.convexPolyhedronRepresentation.material=t.material,t.convexPolyhedronRepresentation.collisionResponse=t.collisionResponse,this.convexHeightfield(t.convexPolyhedronRepresentation,e,i,o,n,s,r,a,t,e,l)};var Bt=new c,Tt=new c,Rt=[0];o.prototype[a.types.CONVEXPOLYHEDRON|a.types.HEIGHTFIELD]=o.prototype.convexHeightfield=function(t,e,i,o,n,s,r,a,h,c,u){var p=e.data,d=e.elementSize,y=t.boundingSphereRadius,v=Tt,m=Rt,f=Bt;l.pointToLocalFrame(o,s,i,f);var g=Math.floor((f.x-y)/d)-1,w=Math.ceil((f.x+y)/d)+1,b=Math.floor((f.y-y)/d)-1,x=Math.ceil((f.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(!(f.z-y>C||f.z+y<A))for(var B=g;B<w;B++)for(var T=b;T<x;T++){var R=!1;if(e.getConvexTrianglePillar(B,T,!1),l.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,m,null)),u&&R)return!0;if(e.getConvexTrianglePillar(B,T,!0),l.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,m,null)),u&&R)return!0}}};var St=new c,Mt=new c;o.prototype[a.types.SPHERE|a.types.HEIGHTFIELD]=o.prototype.sphereHeightfield=function(t,e,i,o,n,s,r,a,h,c,u){var p=e.data,d=t.radius,y=e.elementSize,v=Mt,m=St;l.pointToLocalFrame(o,s,i,m);var f=Math.floor((m.x-d)/y)-1,g=Math.ceil((m.x+d)/y)+1,w=Math.floor((m.y-d)/y)-1,b=Math.ceil((m.y+d)/y)+1;if(!(g<0||b<0||f>p.length||b>p[0].length)){f<0&&(f=0),g<0&&(g=0),w<0&&(w=0),b<0&&(b=0),f>=p.length&&(f=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(f,w,g,b,x);var E=x[0],A=x[1];if(!(m.z-d>A||m.z+d<E))for(var C=this.result,B=f;B<g;B++)for(var T=w;T<b;T++){var R=C.length,S=!1;if(e.getConvexTrianglePillar(B,T,!1),l.pointToWorldFrame(o,s,e.pillarOffset,v),i.distanceTo(v)<e.pillarConvex.boundingSphereRadius+t.boundingSphereRadius&&(S=this.sphereConvex(t,e.pillarConvex,i,v,n,s,r,a,t,e,u)),u&&S)return!0;if(e.getConvexTrianglePillar(B,T,!0),l.pointToWorldFrame(o,s,e.pillarOffset,v),i.distanceTo(v)<e.pillarConvex.boundingSphereRadius+t.boundingSphereRadius&&(S=this.sphereConvex(t,e.pillarConvex,i,v,n,s,r,a,t,e,u)),u&&S)return!0;var M=C.length-R;if(M>2)return}}}},{"../collision/AABB":21,"../collision/Ray":28,"../equations/ContactEquation":38,"../equations/FrictionEquation":40,"../math/Quaternion":47,"../math/Transform":48,"../math/Vec3":49,"../objects/Body":50,"../shapes/ConvexPolyhedron":57,"../shapes/Shape":62,"../solver/Solver":66,"../utils/Vec3Pool":73}],75:[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 c,this.collisionMatrixPrevious=new c,this.bodyOverlapKeeper=new l,this.shapeOverlapKeeper=new l,this.materials=[],this.contactmaterials=[],this.contactMaterialTable=new y,this.defaultMaterial=new u("default"),this.defaultContactMaterial=new p(this.defaultMaterial,this.defaultMaterial,{friction:.3,restitution:0}),this.doProfiling=!1,this.profile={solve:0,makeContactConstraints:0,broadphase:0,integrate:0,narrowphase:0},this.accumulator=0,this.subsystems=[],this.addBodyEvent={type:"addBody",body:null},this.removeBodyEvent={type:"removeBody",body:null},this.idToBodyMap={},this.broadphase.setWorld(this)}e.exports=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"),c=t("../collision/ArrayCollisionMatrix"),l=t("../collision/OverlapKeeper"),u=t("../material/Material"),p=t("../material/ContactMaterial"),d=t("../objects/Body"),y=t("../utils/TupleDictionary"),v=t("../collision/RaycastResult"),m=t("../collision/AABB"),f=t("../collision/Ray"),g=t("../collision/NaiveBroadphase");o.prototype=new h;var w=(new m,new f);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=f.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=f.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=f.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=[],T=[],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=T,n=R,s=this.numObjects(),r=this.bodies,a=this.solver,h=this.gravity,c=this.doProfiling,l=this.profile,u=d.DYNAMIC,p=this.constraints,y=B,v=(h.norm(),h.x),m=h.y,f=h.z,g=0;for(c&&(e=performance.now()),g=0;g!==s;g++){var w=r[g];if(w.type===u){var b=w.force,S=w.mass;b.x+=S*v,b.y+=S*m,b.z+=S*f}}for(var g=0,M=this.subsystems.length;g!==M;g++)this.subsystems[g].update();c&&(e=performance.now()),o.length=0,n.length=0,this.broadphase.collisionPairs(this,o,n),c&&(l.broadphase=performance.now()-e);var k=p.length;for(g=0;g!==k;g++){var P=p[g];if(!P.collideConnected)for(var N=o.length-1;N>=0;N-=1)(P.bodyA===o[N]&&P.bodyB===n[N]||P.bodyB===o[N]&&P.bodyA===n[N])&&(o.splice(N,1),n.splice(N,1))}this.collisionMatrixTick(),c&&(e=performance.now());var L=C,_=i.length;for(g=0;g!==_;g++)L.push(i[g]);i.length=0;var z=this.frictionEquations.length;for(g=0;g!==z;g++)y.push(this.frictionEquations[g]);this.frictionEquations.length=0,this.narrowphase.getContacts(o,n,this,i,L,this.frictionEquations,y),c&&(l.narrowphase=performance.now()-e),c&&(e=performance.now());for(var g=0;g<this.frictionEquations.length;g++)a.addEquation(this.frictionEquations[g]);for(var I=i.length,F=0;F!==I;F++){var V,P=i[F],w=P.bi,q=P.bj,j=P.si,H=P.sj;V=w.material&&q.material?this.getContactMaterial(w.material,q.material)||this.defaultContactMaterial:this.defaultContactMaterial;var O=V.friction;if(w.material&&q.material&&(w.material.friction>=0&&q.material.friction>=0&&(O=w.material.friction*q.material.friction),w.material.restitution>=0&&q.material.restitution>=0&&(P.restitution=w.material.restitution*q.material.restitution)),a.addEquation(P),w.allowSleep&&w.type===d.DYNAMIC&&w.sleepState===d.SLEEPING&&q.sleepState===d.AWAKE&&q.type!==d.STATIC){var D=q.velocity.norm2()+q.angularVelocity.norm2(),W=Math.pow(q.sleepSpeedLimit,2);D>=2*W&&(w._wakeUpAfterNarrowphase=!0)}if(q.allowSleep&&q.type===d.DYNAMIC&&q.sleepState===d.SLEEPING&&w.sleepState===d.AWAKE&&w.type!==d.STATIC){var K=w.velocity.norm2()+w.angularVelocity.norm2(),U=Math.pow(w.sleepSpeedLimit,2);K>=2*U&&(q._wakeUpAfterNarrowphase=!0)}this.collisionMatrix.set(w,q,!0),this.collisionMatrixPrevious.get(w,q)||(A.body=q,A.contact=P,w.dispatchEvent(A),A.body=w,q.dispatchEvent(A)),this.bodyOverlapKeeper.set(w.id,q.id),this.shapeOverlapKeeper.set(j.id,H.id)}for(this.emitContactEvents(),c&&(l.makeContactConstraints=performance.now()-e,e=performance.now()),g=0;g!==s;g++){var w=r[g];w._wakeUpAfterNarrowphase&&(w.wakeUp(),w._wakeUpAfterNarrowphase=!1)}var k=p.length;for(g=0;g!==k;g++){var P=p[g];P.update();for(var N=0,G=P.equations.length;N!==G;N++){var X=P.equations[N];a.addEquation(X)}}a.solve(t,this),c&&(l.solve=performance.now()-e),a.removeAllEquations();var Y=Math.pow;for(g=0;g!==s;g++){var w=r[g];if(w.type&u){var Q=Y(1-w.linearDamping,t),Z=w.velocity;Z.mult(Q,Z);var J=w.angularVelocity;if(J){var $=Y(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)}c&&(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,c&&(l.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,c=t.length;h<c;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,c=e.length;h<c;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 l=this.hasAnyEventListener("beginShapeContact"),u=this.hasAnyEventListener("endShapeContact");if((l||u)&&this.shapeOverlapKeeper.getDiff(t,e),l){for(var h=0,c=t.length;h<c;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,c=e.length;h<c;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":21,"../collision/ArrayCollisionMatrix":22,"../collision/NaiveBroadphase":25,"../collision/OverlapKeeper":27,"../collision/Ray":28,"../collision/RaycastResult":29,"../equations/ContactEquation":38,"../equations/FrictionEquation":40,"../material/ContactMaterial":43,"../material/Material":44,"../math/Quaternion":47,"../math/Vec3":49,"../objects/Body":50,"../shapes/Shape":62,"../solver/GSSolver":65,"../utils/EventTarget":68,"../utils/TupleDictionary":71,"./Narrowphase":74}],76:[function(t,e,i){function o(t){var e=y(t);if(!e.length)return null;t.computeBoundingBox();var i=t.boundingBox;return new m.Box(new m.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 m.Box(new m.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=f(r),i=new Array(n.vertices.length),e=0;e<n.vertices.length;e++)i[e]=new m.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 m.ConvexPolyhedron(i,o)}function r(t){var e,i=t.metadata?t.metadata.parameters:t.parameters;return e=new m.Cylinder(i.radiusTop,i.radiusBottom,i.height,i.radialSegments),e._type=m.Shape.types.CYLINDER,e.radiusTop=i.radiusTop,e.radiusBottom=i.radiusBottom,e.height=i.height,e.numSegments=i.radialSegments,e.orientation=new m.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 m.Cylinder(n,n,o,12),i._type=m.Shape.types.CYLINDER,i.radiusTop=n,i.radiusBottom=n,i.height=o,i.numSegments=12,i.orientation=new m.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 m.Box(new m.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 c(t){var e=t.metadata?t.metadata.parameters:t.parameters;return new m.Sphere(e.radius)}function l(t,e){if(e.sphereRadius)return new m.Sphere(e.sphereRadius);var i=d(t);return i?(i.computeBoundingSphere(),new m.Sphere(i.boundingSphere.radius)):null}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 m.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 m=t("cannon"),f=t("./lib/THREE.quickhull"),g=Math.PI/2,w={BOX:"Box",CYLINDER:"Cylinder",SPHERE:"Sphere",HULL:"ConvexPolyhedron"};e.exports=m.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 l(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 c(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)}},m.mesh2shape.Type=w},{"./lib/THREE.quickhull":77,cannon:20}],77:[function(t,e,i){e.exports=function(){function t(){v=new THREE.Vector3,m=new THREE.Vector3,f=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(;T.length>0;)n(T.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),m.subVectors(n,i),b.crossVectors(m,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 c,l,u,p,d=r=a.length,y=1===r,v=[],m=0,f=[];[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]],T.indexOf(s)>-1&&T.splice(T.indexOf(s),1),s.visiblePoints&&(f=f.concat(s.visiblePoints)),B.splice(B.indexOf(s),1);else for(;r-- >0;){s=a[r],T.indexOf(s)>-1&&T.splice(T.indexOf(s),1),s.visiblePoints&&(f=f.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(c=a[d],m=0,c!==s)for(;m<3&&!g;)l=m+1,g=c[m]===u&&c[l%3]===p||c[m]===p&&c[l%3]===u,m++;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,f,e),B.push(w),void 0!==w.visiblePoints&&T.push(w),r++}var s,r,a,h,c,l,u,p,d,y,v,m,f,g,w,b,x,E,A,C,B=[],T=[],R=0,S=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()}}(),M=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=[],T=[],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,c=r[x],l=r[h]);for(x=6,R=0;x-- >0;)a=M(c,l,r[x]),R<a&&(R=a,u=r[x]);for(d=S(c,l,u),y=d.dot(c),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(c),v=points.indexOf(l),m=points.indexOf(u),f=points.indexOf(p),g=[[m,v,n],[v,f,n],[m,f,v],[n,f,m]];E.subVectors(l,c).normalize(),A.subVectors(u,c).normalize(),C.subVectors(p,c).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(c),1),b.splice(b.indexOf(l),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&&T.push(g[x]),B.push(g[x]);e(points);for(var k=B.length;k-- >0;)i.faces[k]=new THREE.Face3(B[k][2],B[k][1],B[k][0],B[k].normal);return i.normalsNeedUpdate=!0,i}}()},{}],78:[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.getAttribute("position")),i.copy(this.checkpoint.object3D.getWorldPosition()),t.copy(i).sub(e)}}},{}],79:[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)},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}],80:[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.device.isMobile();e.exports={schema:{enabled:{"default":!0},standing:{"default":!0}},init:function(){this.isPositionCalibrated=!1,this.dolly=new THREE.Object3D,this.hmdEuler=new THREE.Euler,this.previousHMDPosition=new THREE.Vector3,this.deltaHMDPosition=new THREE.Vector3,this.vrControls=new THREE.VRControls(this.dolly),this.rotation=new THREE.Vector3},update:function(){var t=this.data,e=this.vrControls;e.standing=t.standing,e.update()},tick:function(){this.vrControls.update()},remove:function(){this.vrControls.dispose()},isRotationActive:function(){var t=this.hmdEuler;return!(!this.data.enabled||!this.el.sceneEl.is("vr-mode")&&!s)&&(t.setFromQuaternion(this.dolly.quaternion,"YXZ"),!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}}},{}],81:[function(t,e,i){var o=t("aframe-physics-system");e.exports={"checkpoint-controls":t("./checkpoint-controls"),"gamepad-controls":t("./gamepad-controls"),"hmd-controls":t("./hmd-controls"),"keyboard-controls":t("./keyboard-controls"),"mouse-controls":t("./mouse-controls"),"touch-controls":t("./touch-controls"),"universal-controls":t("./universal-controls"),registerAll:function(t){this._registered||(t=t||window.AFRAME,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)}}},{"./checkpoint-controls":78,"./gamepad-controls":79,"./hmd-controls":80,"./keyboard-controls":82,"./mouse-controls":83,"./touch-controls":84,"./universal-controls":85,"aframe-physics-system":8}],82:[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}],83:[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,i=(AFRAME.INSPECTOR||{}).opened;this.mouseDown=!0,this.previousMouseEvent=t,!this.data.pointerlockEnabled||this.pointerLocked||i||(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}}},{}],84:[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()}}},{}],85:[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(){var t=this.el.getAttribute("rotation");this.velocity=new THREE.Vector3,this.pitch=new THREE.Object3D,this.pitch.rotation.x=THREE.Math.degToRad(t.x),this.yaw=new THREE.Object3D,this.yaw.position.y=10,this.yaw.rotation.y=THREE.Math.degToRad(t.y),this.yaw.add(this.pitch),this.heading=new THREE.Euler(0,0,0,"YXZ"),this.el.sceneEl.hasLoaded?this.injectControls():this.el.sceneEl.addEventListener("loaded",this.injectControls.bind(this))},update:function(){this.el.sceneEl.hasLoaded&&this.injectControls()},injectControls:function(){var t,e,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.getAttribute("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)}}},{}],86:[function(t,e,i){var o="__auto__";e.exports={schema:{clip:{"default":o},duration:{"default":0}},init:function(){this.model=null,this.mixer=null,this.activeAction=null;var t=this.el.getObject3D("mesh");t?this.load(t):this.el.addEventListener("model-loaded",function(t){this.load(t.detail.model)}.bind(this))},load:function(t){this.model=t,this.mixer=new THREE.AnimationMixer(t),this.data.clip&&this.update({})},remove:function(){this.mixer&&this.mixer.stopAllAction()},update:function(t){if(t){var e=this.data;e.clip!==t.clip&&(this.activeAction&&this.activeAction.stop(),e.clip&&this.playClip(e.clip)),this.activeAction&&e.duration&&this.activeAction.setDuration(e.duration)}},playClip:function(t){if(this.mixer){var e,i=this.data,n=this.model,s=n.animations||(n.geometry||{}).animations||[];if(s.length){if(e=t===o?s[0]:THREE.AnimationClip.findByName(s,i.clip),!e)return void console.error('[animation-mixer] Clip "%s" not found.',i.clip);this.activeAction=this.mixer.clipAction(e,n),this.activeAction.play()}}},tick:function(t,e){this.mixer&&!isNaN(e)&&this.mixer.update(e/1e3)}}},{}],87:[function(t,e,i){THREE.FBXLoader=t("../../lib/FBXLoader"),e.exports={schema:{src:{type:"asset"},crossorigin:{"default":""}},init:function(){this.model=null},update:function(){var t,e=this.data;e.src&&(this.remove(),t=new THREE.FBXLoader,e.crossorigin&&t.setCrossOrigin(e.crossorigin),t.load(e.src,this.load.bind(this)))},load:function(t){this.model=t,this.el.setObject3D("mesh",t),this.el.emit("model-loaded",{format:"fbx",model:t})},remove:function(){this.model&&this.el.removeObject3D("mesh")}}},{"../../lib/FBXLoader":3}],88:[function(t,e,i){e.exports={"animation-mixer":t("./animation-mixer"),"fbx-model":t("./fbx-model"),"json-model":t("./json-model"),"object-model":t("./object-model"),"ply-model":t("./ply-model"),"three-model":t("./three-model"),registerAll:function(t){this._registered||(t=t||window.AFRAME,t.components["animation-mixer"]||t.registerComponent("animation-mixer",this["animation-mixer"]),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["fbx-model"]||t.registerComponent("fbx-model",this["fbx-model"]),t.components["json-model"]||t.registerComponent("json-model",this["json-model"]),t.components["object-model"]||t.registerComponent("object-model",this["object-model"]),t.components["three-model"]||t.registerComponent("three-model",this["three-model"]),this._registered=!0)}}},{"./animation-mixer":86,"./fbx-model":87,"./json-model":89,"./object-model":90,"./ply-model":91,"./three-model":92}],89:[function(t,e,i){e.exports={schema:{src:{type:"asset"},crossorigin:{"default":""}},init:function(){this.model=null},update:function(){var t,e=this.data;e.src&&(this.remove(),t=new THREE.JSONLoader,e.crossorigin&&(t.crossOrigin=e.crossorigin),t.load(e.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.el.setObject3D("mesh",t),this.el.emit("model-loaded",{format:"json",model:t})},remove:function(){this.model&&this.el.removeObject3D("mesh")}}},{}],90:[function(t,e,i){e.exports={schema:{src:{type:"asset"},crossorigin:{"default":""}},init:function(){this.model=null},update:function(){var t,e=this.data;e.src&&(this.remove(),t=new THREE.ObjectLoader,e.crossorigin&&t.setCrossOrigin(e.crossorigin),t.load(e.src,function(t){t.traverse(function(t){t instanceof THREE.SkinnedMesh&&t.material&&(t.material.skinning=!!(t.geometry&&t.geometry.bones||[]).length)}),this.load(t)}.bind(this)))},load:function(t){this.model=t,this.el.setObject3D("mesh",t),this.el.emit("model-loaded",{format:"json",model:t})},remove:function(){this.model&&this.el.removeObject3D("mesh")}}},{}],91:[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:"asset"}},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}],92:[function(t,e,i){var o="__auto__";e.exports={deprecated:!0,schema:{src:{type:"asset"},loader:{"default":"object",oneOf:["object","json"]},enableAnimation:{"default":!0},animation:{"default":o},animationDuration:{"default":0},crossorigin:{"default":""}},init:function(){this.model=null,this.mixer=null,console.warn("[three-model] Component is deprecated. Use json-model or object-model instead.")},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,i.crossorigin&&e.setCrossOrigin(i.crossorigin),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,i.crossorigin&&(e.crossOrigin=i.crossorigin),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)}}},{}],93:[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.removeEventListener("click",this.fire)},remove:function(){this.pause()},fire:function(){var t=this.el.sceneEl.querySelector("[checkpoint-controls]");if(!t)throw new Error("No `checkpoint-controls` component found.");t.components["checkpoint-controls"].setCheckpoint(this.el)}}},{}],94:[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))}}},{}],95:[function(t,e,i){var o=t("aframe-physics-system");e.exports={checkpoint:t("./checkpoint"),grab:t("./grab"),"jump-ability":t("./jump-ability"),"kinematic-body":t("./kinematic-body"),"sphere-collider":t("./sphere-collider"),"toggle-velocity":t("./toggle-velocity"),registerAll:function(t){this._registered||(t=t||window.AFRAME,o.registerAll(),t.components.checkpoint||t.registerComponent("checkpoint",this.checkpoint),t.components.grab||t.registerComponent("grab",this.grab),t.components["jump-ability"]||t.registerComponent("jump-ability",this["jump-ability"]),t.components["kinematic-body"]||t.registerComponent("kinematic-body",this["kinematic-body"]),t.components["sphere-collider"]||t.registerComponent("sphere-collider",this["sphere-collider"]),t.components["toggle-velocity"]||t.registerComponent("toggle-velocity",this["toggle-velocity"]),this._registered=!0)}}},{"./checkpoint":93,"./grab":94,"./jump-ability":96,"./kinematic-body":97,"./sphere-collider":98,"./toggle-velocity":99,"aframe-physics-system":8}],96:[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}}},{}],97:[function(t,e,i){var o=window.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.el.body=this.body,this.system.addBody(this.body)},remove:function(){this.system.removeBody(this.body),this.system.removeBehavior(this,this.system.Phase.SIMULATE),delete this.el.body},step:function(){var t=new THREE.Vector3,e=new THREE.Vector3,i=new THREE.Vector3,o=new THREE.Vector3;return function(s,r){if(r){var a,h,c=this.body,l=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")),c.velocity.copy(t),c.position.copy(this.el.getAttribute("position"));for(var d,y=0;d=this.system.world.contacts[y];y++){if(c.id===d.bi.id)d.ni.negate(i);else{if(c.id!==d.bj.id)continue;i.copy(d.ni)}u=c.velocity.dot(i)<-n,u&&i.y<=.5?t=t.projectOnPlane(i):i.y>.5&&(a=c.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=c.id===d.bi.id?d.bj:d.bi))}if(e.copy(t).normalize(),h&&e.y<.5?(l.enableSlopes?o.y<1-n&&o.copy(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.getAttribute("velocity");c.position.copy({x:c.position.x+v.x*r/1e3,y:c.position.y+v.y*r/1e3,z:c.position.z+v.z*r/1e3}),this.el.setAttribute("position",c.position)}c.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}}},{}],98:[function(t,e,i){e.exports={schema:{objects:{"default":""},state:{"default":"collided"},radius:{"default":.05},watch:{"default":!0}},init:function(){this.observer=null,this.els=[],this.collisions=[],this.handleHit=this.handleHit.bind(this)},remove:function(){this.pause()},play:function(){var t=this.el.sceneEl;this.data.watch&&(this.observer=new MutationObserver(this.update.bind(this,null)),this.observer.observe(t,{childList:!0,subtree:!0}))},pause:function(){this.observer&&(this.observer.disconnect(),this.observer=null)},update:function(){var t,e=this.data;t=e.objects?this.el.sceneEl.querySelectorAll(e.objects):this.el.sceneEl.children,this.els=Array.prototype.slice.call(t)},tick:function(){var t=new THREE.Vector3,e=new THREE.Vector3,i=new Map;return function(){function o(o){var n,r,h;o.isEntity&&(r=o.getObject3D("mesh"),r&&r.geometry&&(r.getWorldPosition(e),r.geometry.computeBoundingSphere(),n=r.geometry.boundingSphere.radius,h=t.distanceTo(e),h<n+s.radius&&(a.push(o),i.set(o,h))))}var n=this.el,s=this.data,r=n.getObject3D("mesh"),a=[];r&&(i.clear(),t.copy(n.object3D.getWorldPosition()),this.els.forEach(o),a.sort(function(t,e){return i.get(t)>i.get(e)?1:-1}).forEach(this.handleHit),0===a.length&&n.emit("hit",{el:null}),this.collisions.filter(function(t){return!i.has(t)}).forEach(function(t){t.removeState(s.state)}),this.collisions=a)}}(),handleHit:function(t){t.emit("hit"),t.addState(this.data.state),this.el.emit("hit",{el:t})}}},{}],99:[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))}}},{}],100:[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"}}},{}],101:[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":"#7AD2F7",type:"color"},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.setObject3D("mesh",this.mesh)},remove:function(){this.el.removeObject3D("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}}}},{}],102:[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")}}},{}],103:[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":100,"./a-ocean":101,"./a-tube":102}],104:[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":106,"./shadow-light":105}],105:[function(t,e,i){e.exports={schema:{angle:{"default":Math.PI/3},castShadow:{"default":!0},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},shadowCameraTop:{"default":10},shadowCameraRight:{"default":10},shadowCameraBottom:{"default":-10},shadowCameraLeft:{"default":-10},shadowDarkness:{"default":.5},shadowMapHeight:{"default":512},shadowMapWidth:{"default":512},type:{"default":"directional",oneOf:["ambient","directional","hemisphere","point","spot"]}},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.bias=e.shadowBias,t.shadow.darkness=e.shadowDarkness,t.shadow.mapSize.height=e.shadowMapHeight,t.shadow.mapSize.width=e.shadowMapWidth,t.shadow.camera.near=e.shadowCameraNear,t.shadow.camera.far=e.shadowCameraFar,t.shadow.camera instanceof THREE.OrthographicCamera?(t.shadow.camera.top=e.shadowCameraTop,t.shadow.camera.right=e.shadowCameraRight,t.shadow.camera.bottom=e.shadowCameraBottom,t.shadow.camera.left=e.shadowCameraLeft):t.shadow.camera.fov=e.shadowCameraFov,t):t}}},{}],106:[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(){}}},{}]},{},[1]);
},{}]},{},[1]);