aframe-extras.min.js 285 KB

1
  1. !function t(e,i,o){function n(r,a){if(!i[r]){if(!e[r]){var l="function"==typeof require&&require;if(!a&&l)return l(r,!0);if(s)return s(r,!0);var h=new Error("Cannot find module '"+r+"'");throw h.code="MODULE_NOT_FOUND",h}var c=i[r]={exports:{}};e[r][0].call(c.exports,function(t){var i=e[r][1][t];return n(i||t)},c,c.exports,t,e,i,o)}return i[r].exports}for(var s="function"==typeof require&&require,r=0;r<o.length;r++)n(o[r]);return n}({1:[function(t,e,i){t("./").registerAll()},{"./":2}],2:[function(t,e,i){e.exports={controls:t("./src/controls"),loaders:t("./src/loaders"),misc:t("./src/misc"),pathfinding:t("./src/pathfinding"),physics:t("aframe-physics-system"),primitives:t("./src/primitives"),registerAll:function(){this.controls.registerAll(),this.loaders.registerAll(),this.misc.registerAll(),this.pathfinding.registerAll(),this.physics.registerAll(),this.primitives.registerAll()}}},{"./src/controls":89,"./src/loaders":97,"./src/misc":104,"./src/pathfinding":110,"./src/primitives":118,"aframe-physics-system":11}],3:[function(t,e,i){!function(){function t(t){var e=new Map;if("Video"in t.Objects.subNodes){var i=t.Objects.subNodes.Video;for(var o in i){if("Content"in i[o].properties){var n=function(t){var e,i=t.properties.Content,o=t.properties.RelativeFilename||t.properties.Filename,n=o.slice(o.lastIndexOf(".")+1).toLowerCase();switch(n){case"bmp":e="image/bmp";break;case"jpg":e="image/jpeg";break;case"png":e="image/png";break;case"tif":e="image/tiff";break;default:return void console.warn("FBXLoader: No support image type "+n)}if("string"==typeof i)return"data:"+e+";base64,"+i;var s=new Uint8Array(i);return window.URL.createObjectURL(new Blob([s],{type:e}))}(i[o]);e.set(parseInt(o),n)}}}return e}function i(t,e,i,o){var n=new Map;if("Texture"in t.Objects.subNodes){var s=t.Objects.subNodes.Texture;for(var r in s){var a=function(t,e,i,o){var n,s=t.id,r=t.name,a=t.properties.FileName,l=t.properties.RelativeFilename,h=o.get(s).children;if(void 0!==h&&h.length>0&&i.has(h[0].ID))n=i.get(h[0].ID);else if(void 0!==l&&"/"!==l[0]&&null===l.match(/^[a-zA-Z]:/))n=l;else{var c=a.split(/[\\\/]/);n=c.length>0?c[c.length-1]:a}var u=e.path;0!==n.indexOf("blob:")&&0!==n.indexOf("data:")||e.setPath(void 0);var p=e.load(n);p.name=r,p.FBX_ID=s;var d=t.properties.WrapModeU,f=t.properties.WrapModeV,v=void 0!==d?d.value:0,m=void 0!==f?f.value:0;return p.wrapS=0===v?THREE.RepeatWrapping:THREE.ClampToEdgeWrapping,p.wrapT=0===m?THREE.RepeatWrapping:THREE.ClampToEdgeWrapping,e.setPath(u),p}(s[r],e,i,o);n.set(parseInt(r),a)}}return n}function o(t,e,i){var o=new Map;if("Material"in t.Objects.subNodes){var n=t.Objects.subNodes.Material;for(var s in n){var r=function(t,e,i){var o=t.id,n=t.attrName,s=t.properties.ShadingModel;"object"==typeof s&&(s=s.value);if(!i.has(o))return null;var r,a=i.get(o).children,l=function(t,e,i){var o={};t.Diffuse&&(o.color=C(t.Diffuse));t.Specular&&(o.specular=C(t.Specular));t.Shininess&&(o.shininess=t.Shininess.value);t.Emissive&&(o.emissive=C(t.Emissive));t.EmissiveFactor&&(o.emissiveIntensity=t.EmissiveFactor.value);t.Opacity&&(o.opacity=t.Opacity.value);o.opacity<1&&(o.transparent=!0);for(var n=0,s=i.length;n<s;++n){var r=i[n],a=r.relationship;switch(a){case"DiffuseColor":case' "DiffuseColor':o.map=e.get(r.ID);break;case"Bump":case' "Bump':o.bumpMap=e.get(r.ID);break;case"NormalMap":case' "NormalMap':o.normalMap=e.get(r.ID);break;case"AmbientColor":case"EmissiveColor":case' "AmbientColor':case' "EmissiveColor':default:console.warn("THREE.FBXLoader: Unknown texture application of type %s, skipping texture.",a)}}return o}(t.properties,e,a);switch(s.toLowerCase()){case"phong":r=new THREE.MeshPhongMaterial;break;case"lambert":r=new THREE.MeshLambertMaterial;break;default:console.warn("THREE.FBXLoader: No implementation given for material type %s in FBXLoader.js. Defaulting to standard material.",s),r=new THREE.MeshStandardMaterial({color:3342591})}return r.setValues(l),r.name=n,r}(n[s],e,i);null!==r&&o.set(parseInt(s),r)}}return o}function n(t,e){var i={};if("Deformer"in t.Objects.subNodes){var o=t.Objects.subNodes.Deformer;for(var n in o){if("Skin"===o[n].attrType){var s=function(t,e){for(var i={},o=t.children,n=0,s=o.length;n<s;++n){var r=o[n],a=e[r.ID],l={FBX_ID:r.ID,index:n,indices:[],weights:[],transform:A(a.subNodes.Transform.properties.a),transformLink:A(a.subNodes.TransformLink.properties.a),linkMode:a.properties.Mode};"Indexes"in a.subNodes&&(l.indices=T(a.subNodes.Indexes.properties.a),l.weights=E(a.subNodes.Weights.properties.a)),i[r.ID]=l}return{map:i,bones:[]}}(e.get(parseInt(n)),o);s.FBX_ID=parseInt(n),i[n]=s}}}return i}function s(t,e,i){var o=new Map;if("Geometry"in t.Objects.subNodes){var n=t.Objects.subNodes.Geometry;for(var s in n){var a=e.get(parseInt(s)),l=function(t,e,i){switch(t.attrType){case"Mesh":return function(t,e,i){for(var o=0;o<e.children.length;++o){var n=i[e.children[o].ID];if(void 0!==n)break}return function(t,e){var i=new v,o=t.subNodes,n=E(o.Vertices.properties.a),s=T(o.PolygonVertexIndex.properties.a);if(o.LayerElementNormal)var a=function(t){var e=t.properties.MappingInformationType,i=t.properties.ReferenceInformationType,o=E(t.subNodes.Normals.properties.a),n=[];"IndexToDirect"===i&&("NormalIndex"in t.subNodes?n=T(t.subNodes.NormalIndex.properties.a):"NormalsIndex"in t.subNodes&&(n=T(t.subNodes.NormalsIndex.properties.a)));return{dataSize:3,buffer:o,indices:n,mappingType:e,referenceType:i}}(o.LayerElementNormal[0]);if(o.LayerElementUV)var l=function(t){var e=t.properties.MappingInformationType,i=t.properties.ReferenceInformationType,o=E(t.subNodes.UV.properties.a),n=[];"IndexToDirect"===i&&(n=T(t.subNodes.UVIndex.properties.a));return{dataSize:2,buffer:o,indices:n,mappingType:e,referenceType:i}}(o.LayerElementUV[0]);if(o.LayerElementColor)var h=function(t){var e=t.properties.MappingInformationType,i=t.properties.ReferenceInformationType,o=E(t.subNodes.Colors.properties.a),n=[];"IndexToDirect"===i&&(n=E(t.subNodes.ColorIndex.properties.a));return{dataSize:4,buffer:o,indices:n,mappingType:e,referenceType:i}}(o.LayerElementColor[0]);if(o.LayerElementMaterial)var c=function(t){var e=t.properties.MappingInformationType,i=t.properties.ReferenceInformationType;if("NoMappingInformation"===e)return{dataSize:1,buffer:[0],indices:[0],mappingType:"AllSame",referenceType:i};for(var o=T(t.subNodes.Materials.properties.a),n=[],s=0,r=o.length;s<r;++s)n.push(s);return{dataSize:1,buffer:o,indices:n,mappingType:e,referenceType:i}}(o.LayerElementMaterial[0]);var u={};if(e){var d=e.map;for(var m in d)for(var y=d[m],g=y.indices,w=0;w<g.length;w++){var b=g[w],x=y.weights[w];void 0===u[b]&&(u[b]=[]),u[b].push({id:y.index,weight:x})}}for(var S=[],C=0,A=!1,R=0;R<s.length;R++){var M=s[R],B=!1;M<0&&(M^=-1,s[R]=M,B=!0);var z=new p,k=[],L=[];if(z.position.fromArray(n,3*M),e){if(void 0!==u[M])for(var P=u[M],w=0,I=P.length;w<I;w++)L.push(P[w].weight),k.push(P[w].id);if(L.length>4){A||(console.warn("THREE.FBXLoader: Vertex has more than 4 skinning weights assigned to vertex. Deleting additional weights."),A=!0);var N=[0,0,0,0],_=[0,0,0,0];L.forEach(function(t,e){var i=t,o=k[e];_.forEach(function(t,e,n){if(i>t){n[e]=i,i=t;var s=N[e];N[e]=o,o=s}})}),k=N,L=_}for(W=L.length;W<4;++W)L[W]=0,k[W]=0;z.skinWeights.fromArray(L),z.skinIndices.fromArray(k)}if(a&&z.normal.fromArray(r(R,C,M,a)),l&&z.uv.fromArray(r(R,C,M,l)),h&&z.color.fromArray(r(R,C,M,h)),S.push(z),B){var F=new f;if(F.genTrianglesFromVertices(S),void 0!==c){var V=r(R,C,M,c);F.materialIndex=V[0]}else F.materialIndex=0;i.faces.push(F),S=[],C++,B=!1}}var q=i.flattenToBuffers(),D=new THREE.BufferGeometry;D.name=t.name,D.addAttribute("position",new THREE.Float32BufferAttribute(q.vertexBuffer,3)),q.normalBuffer.length>0&&D.addAttribute("normal",new THREE.Float32BufferAttribute(q.normalBuffer,3));q.uvBuffer.length>0&&D.addAttribute("uv",new THREE.Float32BufferAttribute(q.uvBuffer,2));o.LayerElementColor&&D.addAttribute("color",new THREE.Float32BufferAttribute(q.colorBuffer,3));e&&(D.addAttribute("skinIndex",new THREE.Float32BufferAttribute(q.skinIndexBuffer,4)),D.addAttribute("skinWeight",new THREE.Float32BufferAttribute(q.skinWeightBuffer,4)),D.FBX_Deformer=e);for(var O=q.materialIndexBuffer,H=O[0],j=0,W=0;W<O.length;++W)O[W]!==H&&(D.addGroup(j,W-j,H),H=O[W],j=W);return D}(t,n)}(t,e,i);case"NurbsCurve":return function(t){if(void 0===THREE.NURBSCurve)return console.error("THREE.FBXLoader: The loader relies on THREE.NURBSCurve for any nurbs present in the model. Nurbs will show up as empty geometry."),new THREE.BufferGeometry;var e=parseInt(t.properties.Order);if(isNaN(e))return console.error("THREE.FBXLoader: Invalid Order %s given for geometry ID: %s",t.properties.Order,t.id),new THREE.BufferGeometry;for(var i=e-1,o=E(t.subNodes.KnotVector.properties.a),n=[],s=E(t.subNodes.Points.properties.a),r=0,a=s.length;r<a;r+=4)n.push((new THREE.Vector4).fromArray(s,r));var l,h;if("Closed"===t.properties.Form)n.push(n[0]);else if("Periodic"===t.properties.Form){l=i,h=o.length-1-l;for(r=0;r<i;++r)n.push(n[r])}for(var c=new THREE.NURBSCurve(i,o,n,l,h).getPoints(7*n.length),u=new Float32Array(3*c.length),r=0,a=c.length;r<a;++r)c[r].toArray(u,3*r);var p=new THREE.BufferGeometry;return p.addAttribute("position",new THREE.BufferAttribute(u,3)),p}(t)}}(n[s],a,i);o.set(parseInt(s),l)}}return o}function r(t,e,i,o){return P[o.mappingType][o.referenceType](t,e,i,o)}function a(t,e,i,o,n){var s=new THREE.Group,r=t.Objects.subNodes.Model,a=[],h=new Map;for(var p in r){for(var d=parseInt(p),f=r[p],v=e.get(d),m=null,y=0;y<v.parents.length;++y)for(var g in i){if(it=(tt=($=i[g]).map)[v.parents[y].ID]){var w=m;m=new THREE.Bone,$.bones[it.index]=m,null!==w&&m.add(w)}}if(!m)switch(f.attrType){case"Mesh":for(var b=null,C=null,R=[],z=0,k=v.children.length;z<k;++z){q=v.children[z];o.has(q.ID)&&(b=o.get(q.ID)),n.has(q.ID)&&R.push(n.get(q.ID))}if(R.length>1?C=R:R.length>0?C=R[0]:(C=new THREE.MeshStandardMaterial({color:3342591}),R.push(C)),"color"in b.attributes)for(var L=0,P=R.length;L<P;++L)R[L].vertexColors=THREE.VertexColors;if(b.FBX_Deformer){for(var _=0,V=R.length;_<V;++_)R[_].skinning=!0;m=new THREE.SkinnedMesh(b,C)}else m=new THREE.Mesh(b,C);break;case"NurbsCurve":for(var b=null,z=0,k=v.children.length;z<k;++z){var q=v.children[z];o.has(q.ID)&&(b=o.get(q.ID))}C=new THREE.LineBasicMaterial({color:3342591,linewidth:5}),m=new THREE.Line(b,C);break;default:m=new THREE.Object3D}m.name=f.attrName.replace(/:/,"").replace(/_/,"").replace(/-/,""),m.FBX_ID=d,a.push(m),h.set(d,m)}for(var D=0,O=a.length;D<O;++D){if("Lcl_Translation"in(f=r[(m=a[D]).FBX_ID]).properties&&m.position.fromArray(E(f.properties.Lcl_Translation.value)),"Lcl_Rotation"in f.properties){var H=E(f.properties.Lcl_Rotation.value).map(M);H.push("ZYX"),m.rotation.fromArray(H)}if("Lcl_Scaling"in f.properties&&m.scale.fromArray(E(f.properties.Lcl_Scaling.value)),"PreRotation"in f.properties){var j=(new THREE.Euler).setFromVector3(S(f.properties.PreRotation).multiplyScalar(F),"ZYX");j=(new THREE.Quaternion).setFromEuler(j);var W=(new THREE.Quaternion).setFromEuler(m.rotation);j.multiply(W),m.rotation.setFromQuaternion(j,"ZYX")}for(var v=e.get(m.FBX_ID),U=0;U<v.parents.length;U++){var G=B(a,function(t){return t.FBX_ID===v.parents[U].ID});if(G>-1){a[G].add(m);break}}null===m.parent&&s.add(m)}s.updateMatrixWorld(!0);var K=t.Objects.subNodes.Pose;for(var p in K)if("BindPose"===K[p].attrType){K=K[p];break}if(K)for(var X=K.subNodes.PoseNode,Y=new Map,Q=0,Z=X.length;Q<Z;++Q){var J=A((f=X[Q]).subNodes.Matrix.properties.a);Y.set(parseInt(f.id),J)}for(var g in i){var $=i[g],tt=$.map;for(var et in tt){var it=tt[et],ot=it.index,nt=$.bones[ot];if(!Y.has(nt.FBX_ID))break;var st=Y.get(nt.FBX_ID);nt.matrixWorld.copy(st)}$.skeleton=new THREE.Skeleton($.bones);for(var rt=(v=e.get($.FBX_ID)).parents,at=0,lt=rt.length;at<lt;++at){var ht=rt[at];if(o.has(ht.ID))for(var ct=ht.ID,ut=e.get(ct),y=0;y<ut.parents.length;++y)if(h.has(ut.parents[y].ID)){(m=h.get(ut.parents[y].ID)).bind($.skeleton,m.matrixWorld);break}}}s.updateMatrixWorld(!0),s.skeleton={bones:a};return function(t,e){void 0===t.animations&&(t.animations=[]);var i=e.stacks;for(var o in i){for(var n=i[o],s={name:n.name,fps:30,length:n.length,hierarchy:[]},r=t.skeleton.bones,a=0,l=r.length;a<l;++a){var h=(f=r[a]).name.replace(/.*:/,""),p=B(r,function(t){return f.parent===t});s.hierarchy.push({parent:p,name:h,keys:[]})}for(var d=0;d<=n.frames;d++)for(var a=0,l=r.length;a<l;++a)for(var f=r[a],v=a,m=n.layers[0][v],y=0,g=s.hierarchy.length;y<g;++y){var w=s.hierarchy[y];w.name===f.name&&w.keys.push(function(t,e,i,o){var n={time:o/t.fps,pos:i.position.toArray(),rot:i.quaternion.toArray(),scl:i.scale.toArray()};if(void 0===e)return n;try{if(c(e,"T")&&u(e.T,o)&&(n.pos=[e.T.curves.x.values[o],e.T.curves.y.values[o],e.T.curves.z.values[o]]),c(e,"R")&&u(e.R,o)){var s=e.R.curves.x.values[o],r=e.R.curves.y.values[o],a=e.R.curves.z.values[o];N.setFromEuler(I.set(s,r,a,"ZYX")),n.rot=N.toArray()}c(e,"S")&&u(e.S,o)&&(n.scl=[e.S.curves.x.values[o],e.S.curves.y.values[o],e.S.curves.z.values[o]])}catch(t){console.log("THREE.FBXLoader: ",i),console.log("THREE.FBXLoader: ",t)}return n}(e,m,f,d))}t.animations.push(THREE.AnimationClip.parseAnimation(s,r))}}(s,function(t,e,i){var o=t.Objects.subNodes.AnimationCurveNode,n=t.Objects.subNodes.AnimationCurve,s=t.Objects.subNodes.AnimationLayer,r=t.Objects.subNodes.AnimationStack,a={curves:new Map,layers:{},stacks:{},length:0,fps:30,frames:0},h=[];for(var c in o)if(c.match(/\d+/)){var u=function(t,e,i,o){var n=t.Objects.subNodes.Model,s={id:e.id,attr:e.attrName,internalID:e.id,attrX:!1,attrY:!1,attrZ:!1,containerBoneID:-1,containerID:-1,curves:{x:null,y:null,z:null},preRotations:null};if(!s.attr.match(/S|R|T/))return null;for(var r in e.properties)r.match(/X/)&&(s.attrX=!0),r.match(/Y/)&&(s.attrY=!0),r.match(/Z/)&&(s.attrZ=!0);for(var a=i.get(s.id).parents,l=a.length-1;l>=0;--l){var h=B(o.skeleton.bones,function(t){return t.FBX_ID===a[l].ID});if(h>-1){s.containerBoneID=h,s.containerID=a[l].ID;var c=n[s.containerID.toString()];"PreRotation"in c.properties&&(s.preRotations=S(c.properties.PreRotation).multiplyScalar(Math.PI/180));break}}return s}(t,o[c],e,i);h.push(u)}for(var p=new Map,d=0;d<h.length;++d)null!==h[d]&&p.set(h[d].id,h[d]);var f=[];for(c in n)if(c.match(/\d+/)){var v=function(t){return{version:null,id:t.id,internalID:t.id,times:E(t.subNodes.KeyTime.properties.a).map(x),values:E(t.subNodes.KeyValueFloat.properties.a),attrFlag:T(t.subNodes.KeyAttrFlags.properties.a),attrData:E(t.subNodes.KeyAttrDataFloat.properties.a)}}(n[c]);if(!e.has(v.id))continue;f.push(v);var m=e.get(v.id).parents[0],y=m.ID,g=m.relationship,w="";if(g.match(/X/))w="x";else if(g.match(/Y/))w="y";else{if(!g.match(/Z/))continue;w="z"}p.get(y).curves[w]=v}p.forEach(function(t){var e=t.containerBoneID;if(a.curves.has(e)||a.curves.set(e,{T:null,R:null,S:null}),a.curves.get(e)[t.attr]=t,"R"===t.attr){var i=t.curves;if(null===i.x&&(i.x={version:null,times:[0],values:[0]}),null===i.y&&(i.y={version:null,times:[0],values:[0]}),null===i.z&&(i.z={version:null,times:[0],values:[0]}),i.x.values=i.x.values.map(M),i.y.values=i.y.values.map(M),i.z.values=i.z.values.map(M),null!==t.preRotations){var o=(new THREE.Euler).setFromVector3(t.preRotations,"ZYX");o=(new THREE.Quaternion).setFromEuler(o);for(var n=new THREE.Euler,s=new THREE.Quaternion,r=0;r<i.x.times.length;++r)n.set(i.x.values[r],i.y.values[r],i.z.values[r],"ZYX"),s.setFromEuler(n).premultiply(o),n.setFromQuaternion(s,"ZYX"),i.x.values[r]=n.x,i.y.values[r]=n.y,i.z.values[r]=n.z}}});for(var c in s){for(var b=[],C=e.get(parseInt(c)).children,A=0;A<C.length;A++)if(p.has(C[A].ID)){var R=p.get(C[A].ID),z=R.containerBoneID;void 0===b[z]&&(b[z]={T:null,R:null,S:null}),b[z][R.attr]=R}a.layers[c]=b}for(var c in r){for(var k=[],C=e.get(parseInt(c)).children,L={max:0,min:Number.MAX_VALUE},A=0;A<C.length;++A){var P=a.layers[C[A].ID];if(void 0!==P){k.push(P);for(var I=0,N=P.length;I<N;++I){(b=P[I])&&function(t,e){t.R&&l(t.R.curves,e);t.S&&l(t.S.curves,e);t.T&&l(t.T.curves,e)}(b,L)}}}L.max>L.min&&(a.stacks[c]={name:r[c].attrName,layers:k,length:L.max-L.min,frames:30*(L.max-L.min)})}return a}(t,e,s)),s}function l(t,e){t.x&&h(t.x,e),t.y&&h(t.y,e),t.z&&h(t.z,e)}function h(t,e){e.max=t.times[t.times.length-1]>e.max?t.times[t.times.length-1]:e.max,e.min=t.times[0]<e.min?t.times[0]:e.min}function c(t,e){if(void 0===t)return!1;var i=t[e];return!!i&&_.every(function(t){return null!==i.curves[t]})}function u(t,e){return _.every(function(i){return function(t,e){return void 0!==t.values[e]}(t.curves[i],e)})}function p(){this.position=new THREE.Vector3,this.normal=new THREE.Vector3,this.uv=new THREE.Vector2,this.color=new THREE.Vector3,this.skinIndices=new THREE.Vector4(0,0,0,0),this.skinWeights=new THREE.Vector4(0,0,0,0)}function d(){this.vertices=[]}function f(){this.triangles=[],this.materialIndex=0}function v(){this.faces=[],this.skeleton=null}function m(){}function y(){}function g(t,e){this.dv=new DataView(t),this.offset=0,this.littleEndian=void 0===e||e}function w(){}function b(t){var e=t.match(/FBXVersion: (\d+)/);if(e){return parseInt(e[1])}throw new Error("THREE.FBXLoader: Cannot find the version number for the file given.")}function x(t){return t/46186158e3}function E(t){for(var e=t.split(","),i=0,o=e.length;i<o;i++)e[i]=parseFloat(e[i]);return e}function T(t){for(var e=t.split(","),i=0,o=e.length;i<o;i++)e[i]=parseInt(e[i]);return e}function S(t){return(new THREE.Vector3).fromArray(t.value)}function C(t){return(new THREE.Color).fromArray(t.value)}function A(t){return(new THREE.Matrix4).fromArray(E(t))}function R(t,e,i){void 0===e&&(e=0),void 0===i&&(i=t.byteLength);var o=new Uint8Array(t,e,i);if(void 0!==window.TextDecoder)return(new TextDecoder).decode(o);for(var n="",s=0,r=o.length;s<r;s++)n+=String.fromCharCode(o[s]);return n}function M(t){return t*F}function B(t,e){for(var i=0,o=t.length;i<o;i++)if(e(t[i]))return i;return-1}function z(t,e){for(var i=0,o=t.length,n=e.length;i<n;i++,o++)t[o]=e[i]}function k(t,e,i,o){for(var n=i,s=0;n<o;n++,s++)t[s]=e[n];return t}e.exports=THREE.FBXLoader=function(t){this.manager=void 0!==t?t:THREE.DefaultLoadingManager},Object.assign(THREE.FBXLoader.prototype,{load:function(t,e,i,o){var n=this,s=THREE.Loader.prototype.extractUrlBase(t),r=new THREE.FileLoader(this.manager);r.setResponseType("arraybuffer"),r.load(t,function(i){try{var r=n.parse(i,s);e(r)}catch(e){window.setTimeout(function(){o&&o(e),n.manager.itemError(t)},0)}},i,o)},parse:function(e,r){var l;if(function(t){var e="Kaydara FBX Binary \0";return t.byteLength>=e.length&&e===R(t,0,e.length)}(e))l=(new y).parse(e);else{var h=R(e);if(!function(t){function e(e){var i=t[e-1];return t=t.slice(o+e),o++,i}for(var i=["K","a","y","d","a","r","a","\\","F","B","X","\\","B","i","n","a","r","y","\\","\\"],o=0,n=0;n<i.length;++n)if(e(1)===i[n])return!1;return!0}(h))throw new Error("THREE.FBXLoader: Unknown format.");if(b(h)<7e3)throw new Error("THREE.FBXLoader: FBX version not supported, FileVersion: "+b(h));l=(new m).parse(h)}var c=function(t){var e=new Map;if("Connections"in t)for(var i=t.Connections.properties.connections,o=0,n=i.length;o<n;++o){var s=i[o];e.has(s[0])||e.set(s[0],{parents:[],children:[]});var r={ID:s[1],relationship:s[2]};e.get(s[0]).parents.push(r),e.has(s[1])||e.set(s[1],{parents:[],children:[]});var a={ID:s[0],relationship:s[2]};e.get(s[1]).children.push(a)}return e}(l),u=t(l),p=o(l,i(l,new THREE.TextureLoader(this.manager).setPath(r),u,c),c),d=n(l,c);return a(l,c,d,s(l,c,d),p)}});var L=[],P={ByPolygonVertex:{Direct:function(t,e,i,o){var n=t*o.dataSize,s=t*o.dataSize+o.dataSize;return k(L,o.buffer,n,s)},IndexToDirect:function(t,e,i,o){var n=o.indices[t],s=n*o.dataSize,r=n*o.dataSize+o.dataSize;return k(L,o.buffer,s,r)}},ByPolygon:{Direct:function(t,e,i,o){var n=e*o.dataSize,s=e*o.dataSize+o.dataSize;return k(L,o.buffer,n,s)},IndexToDirect:function(t,e,i,o){var n=o.indices[e],s=n*o.dataSize,r=n*o.dataSize+o.dataSize;return k(L,o.buffer,s,r)}},ByVertice:{Direct:function(t,e,i,o){var n=i*o.dataSize,s=i*o.dataSize+o.dataSize;return k(L,o.buffer,n,s)}},AllSame:{IndexToDirect:function(t,e,i,o){var n=o.indices[0]*o.dataSize,s=o.indices[0]*o.dataSize+o.dataSize;return k(L,o.buffer,n,s)}}},I=new THREE.Euler,N=new THREE.Quaternion,_=["x","y","z"];Object.assign(p.prototype,{copy:function(t){var e=t||new p;return e.position.copy(this.position),e.normal.copy(this.normal),e.uv.copy(this.uv),e.skinIndices.copy(this.skinIndices),e.skinWeights.copy(this.skinWeights),e},flattenToBuffers:function(t,e,i,o,n,s){this.position.toArray(t,t.length),this.normal.toArray(e,e.length),this.uv.toArray(i,i.length),this.color.toArray(o,o.length),this.skinIndices.toArray(n,n.length),this.skinWeights.toArray(s,s.length)}}),Object.assign(d.prototype,{copy:function(t){for(var e=t||new d,i=0;i<this.vertices.length;++i)this.vertices[i].copy(e.vertices[i]);return e},flattenToBuffers:function(t,e,i,o,n,s){for(var r=this.vertices,a=0,l=r.length;a<l;++a)r[a].flattenToBuffers(t,e,i,o,n,s)}}),Object.assign(f.prototype,{copy:function(t){for(var e=t||new f,i=0;i<this.triangles.length;++i)this.triangles[i].copy(e.triangles[i]);return e.materialIndex=this.materialIndex,e},genTrianglesFromVertices:function(t){for(var e=2;e<t.length;++e){var i=new d;i.vertices[0]=t[0],i.vertices[1]=t[e-1],i.vertices[2]=t[e],this.triangles.push(i)}},flattenToBuffers:function(t,e,i,o,n,s,r){for(var a=this.triangles,l=this.materialIndex,h=0,c=a.length;h<c;++h)a[h].flattenToBuffers(t,e,i,o,n,s),z(r,[l,l,l])}}),Object.assign(v.prototype,{flattenToBuffers:function(){for(var t=[],e=[],i=[],o=[],n=[],s=[],r=[],a=this.faces,l=0,h=a.length;l<h;++l)a[l].flattenToBuffers(t,e,i,o,n,s,r);return{vertexBuffer:t,normalBuffer:e,uvBuffer:i,colorBuffer:o,skinIndexBuffer:n,skinWeightBuffer:s,materialIndexBuffer:r}}}),Object.assign(m.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(t){this.currentIndent=0,this.allNodes=new w,this.nodeStack=[],this.currentProp=[],this.currentPropName="";for(var e=t.split("\n"),i=0,o=e.length;i<o;i++){if(!(h=e[i]).match(/^[\s\t]*;/)&&!h.match(/^[\s\t]*$/)){var n=new RegExp("^\\t{"+this.currentIndent+"}(\\w+):(.*){",""),s=h.match(n);if(s){for(var r=s[1].trim().replace(/^"/,"").replace(/"$/,""),a=s[2].split(","),l=0,h=a.length;l<h;l++)a[l]=a[l].trim().replace(/^"/,"").replace(/"$/,"");this.parseNodeBegin(h,r,a||null)}else{var c=new RegExp("^\\t{"+this.currentIndent+"}(\\w+):[\\s\\t\\r\\n](.*)");if(s=h.match(c)){var u=s[1].replace(/^"/,"").replace(/"$/,"").trim(),p=s[2].replace(/^"/,"").replace(/"$/,"").trim();"Content"===u&&","===p&&(p=e[++i].replace(/"/g,"").trim()),this.parseNodeProperty(h,u,p)}else{var d=new RegExp("^\\t{"+(this.currentIndent-1)+"}}");h.match(d)?this.nodeEnd():h.match(/^[^\s\t}]/)&&this.parseNodePropertyContinued(h)}}}}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){if(n.match(/Properties(\d)+/))return void this.parseNodeSpecialProperty(t,e,i)}if("C"===e){var s=i.split(",").slice(1),r=parseInt(s[0]),a=parseInt(s[1]),l=i.split(",").slice(3);e="connections",z(i=[r,a],l),void 0===o.properties[e]&&(o.properties[e]=[])}if("Node"===e){var h=parseInt(i);o.properties.id=h,o.id=h}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){for(var o=i.split('",'),n=0,s=o.length;n<s;n++)o[n]=o[n].trim().replace(/^\"/,"").replace(/\s/,"_");var r=o[0],a=o[1],l=o[2],h=o[3],c=o[4];switch(a){case"int":c=parseInt(c);break;case"double":c=parseFloat(c);break;case"ColorRGB":case"Vector3D":c=E(c)}this.getPrevNode().properties[r]={type:a,type2:l,flag:h,value:c},this.setCurrentProp(this.getPrevNode().properties,r)},nodeEnd:function(){this.popStack()},isFlattenNode:function(t){return"subNodes"in t&&"properties"in t}}),Object.assign(y.prototype,{parse:function(t){var e=new g(t);e.skip(23);var i=e.getUint32();console.log("THREE.FBXLoader: FBX binary version: "+i);for(var o=new w;!this.endOfContent(e);){var n=this.parseNode(e,i);null!==n&&o.add(n.name,n)}return o},endOfContent:function(t){return t.size()%16==0?(t.getOffset()+160+16&-16)>=t.size():t.getOffset()+160+16>=t.size()},parseNode:function(t,e){var i=e>=7500?t.getUint64():t.getUint32(),o=e>=7500?t.getUint64():t.getUint32(),n=(e>=7500?t.getUint64():t.getUint32(),t.getUint8()),s=t.getString(n);if(0===i)return null;for(var r=[],a=0;a<o;a++)r.push(this.parseProperty(t));var l=r.length>0?r[0]:"",h=r.length>1?r[1]:"",c=r.length>2?r[2]:"",u={},p={},d=!1;for(1===o&&t.getOffset()===i&&(d=!0);i>t.getOffset();){var f=this.parseNode(t,e);if(null!==f)if(!0!==f.singleProperty)if("Connections"!==s||"C"!==f.name)if(f.name.match(/^Properties\d+$/))for(var v=Object.keys(f.properties),a=0,m=v.length;a<m;a++){var y=v[a];p[y]=f.properties[y]}else if(s.match(/^Properties\d+$/)&&"P"===f.name){var g,w=f.propertyList[0],b=f.propertyList[1],x=f.propertyList[2],E=f.propertyList[3];0===w.indexOf("Lcl ")&&(w=w.replace("Lcl ","Lcl_")),0===b.indexOf("Lcl ")&&(b=b.replace("Lcl ","Lcl_")),g="ColorRGB"===b||"Vector"===b||"Vector3D"===b||0===b.indexOf("Lcl_")?[f.propertyList[4],f.propertyList[5],f.propertyList[6]]:f.propertyList[4],0===b.indexOf("Lcl_")&&(g=g.toString()),p[w]={type:b,type2:x,flag:E,value:g}}else void 0===u[f.name]?"number"==typeof f.id?(u[f.name]={},u[f.name][f.id]=f):u[f.name]=f:""===f.id?(Array.isArray(u[f.name])||(u[f.name]=[u[f.name]]),u[f.name].push(f)):void 0===u[f.name][f.id]?u[f.name][f.id]=f:(Array.isArray(u[f.name][f.id])||(u[f.name][f.id]=[u[f.name][f.id]]),u[f.name][f.id].push(f));else{for(var T=[],a=1,m=f.propertyList.length;a<m;a++)T[a-1]=f.propertyList[a];void 0===p.connections&&(p.connections=[]),p.connections.push(T)}else{var S=f.propertyList[0];Array.isArray(S)?(f.properties[f.name]=f.propertyList[0],u[f.name]=f,f.properties.a=S.toString()):p[f.name]=S}}return{singleProperty:d,id:l,attrName:h,attrType:c,name:s,properties:p,propertyList:r,subNodes:u}},parseProperty:function(t){var e=t.getChar();switch(e){case"F":return t.getFloat32();case"D":return t.getFloat64();case"L":return t.getInt64();case"I":return t.getInt32();case"Y":return t.getInt16();case"C":return t.getBoolean();case"f":case"d":case"l":case"i":case"b":var i=t.getUint32(),o=t.getUint32(),n=t.getUint32();if(0===o)switch(e){case"f":return t.getFloat32Array(i);case"d":return t.getFloat64Array(i);case"l":return t.getInt64Array(i);case"i":return t.getInt32Array(i);case"b":return t.getBooleanArray(i)}if(void 0===window.Zlib)throw new Error("THREE.FBXLoader: External library Inflate.min.js required, obtain or import from https://github.com/imaya/zlib.js");var s=new g(new Zlib.Inflate(new Uint8Array(t.getArrayBuffer(n))).decompress().buffer);switch(e){case"f":return s.getFloat32Array(i);case"d":return s.getFloat64Array(i);case"l":return s.getInt64Array(i);case"i":return s.getInt32Array(i);case"b":return s.getBooleanArray(i)}case"S":r=t.getUint32();return t.getString(r);case"R":var r=t.getUint32();return t.getArrayBuffer(r);default:throw new Error("THREE.FBXLoader: Unknown property type "+e)}}}),Object.assign(g.prototype,{getOffset:function(){return this.offset},size:function(){return this.dv.buffer.byteLength},skip:function(t){this.offset+=t},getBoolean:function(){return 1==(1&this.getUint8())},getBooleanArray:function(t){for(var e=[],i=0;i<t;i++)e.push(this.getBoolean());return e},getInt8:function(){var t=this.dv.getInt8(this.offset);return this.offset+=1,t},getInt8Array:function(t){for(var e=[],i=0;i<t;i++)e.push(this.getInt8());return e},getUint8:function(){var t=this.dv.getUint8(this.offset);return this.offset+=1,t},getUint8Array:function(t){for(var e=[],i=0;i<t;i++)e.push(this.getUint8());return e},getInt16:function(){var t=this.dv.getInt16(this.offset,this.littleEndian);return this.offset+=2,t},getInt16Array:function(t){for(var e=[],i=0;i<t;i++)e.push(this.getInt16());return e},getUint16:function(){var t=this.dv.getUint16(this.offset,this.littleEndian);return this.offset+=2,t},getUint16Array:function(t){for(var e=[],i=0;i<t;i++)e.push(this.getUint16());return e},getInt32:function(){var t=this.dv.getInt32(this.offset,this.littleEndian);return this.offset+=4,t},getInt32Array:function(t){for(var e=[],i=0;i<t;i++)e.push(this.getInt32());return e},getUint32:function(){var t=this.dv.getUint32(this.offset,this.littleEndian);return this.offset+=4,t},getUint32Array:function(t){for(var e=[],i=0;i<t;i++)e.push(this.getUint32());return e},getInt64:function(){var t,e;return this.littleEndian?(t=this.getUint32(),e=this.getUint32()):(e=this.getUint32(),t=this.getUint32()),2147483648&e?(e=4294967295&~e,4294967295===(t=4294967295&~t)&&(e=e+1&4294967295),t=t+1&4294967295,-(4294967296*e+t)):4294967296*e+t},getInt64Array:function(t){for(var e=[],i=0;i<t;i++)e.push(this.getInt64());return e},getUint64:function(){var t,e;return this.littleEndian?(t=this.getUint32(),e=this.getUint32()):(e=this.getUint32(),t=this.getUint32()),4294967296*e+t},getUint64Array:function(t){for(var e=[],i=0;i<t;i++)e.push(this.getUint64());return e},getFloat32:function(){var t=this.dv.getFloat32(this.offset,this.littleEndian);return this.offset+=4,t},getFloat32Array:function(t){for(var e=[],i=0;i<t;i++)e.push(this.getFloat32());return e},getFloat64:function(){var t=this.dv.getFloat64(this.offset,this.littleEndian);return this.offset+=8,t},getFloat64Array:function(t){for(var e=[],i=0;i<t;i++)e.push(this.getFloat64());return e},getArrayBuffer:function(t){var e=this.dv.buffer.slice(this.offset,this.offset+t);return this.offset+=t,e},getChar:function(){return String.fromCharCode(this.getUint8())},getString:function(t){for(var e="";t>0;){var i=this.getUint8();if(t--,0===i)break;e+=String.fromCharCode(i)}return this.skip(t),e}}),Object.assign(w.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?(z(this.__cache_search_connection_parent[t],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?(z(this.__cache_search_connection_children[t],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}});var F=Math.PI/180}()},{}],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){e.exports=function(t,e,i){this.type=t,this.index=e,this.pressed=i.pressed,this.value=i.value}},{}],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){return"ascii"===this.parseHeader(this.bin2str(t)).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="",o=0,n=/ply([\s\S]*)end_header\s/.exec(t);null!==n&&(i=n[1],o=n[0].length);for(var s,r,a={comments:[],elements:[],headerLength:o},l=i.split("\n"),h=void 0,c=0;c<l.length;c++){var u=l[c];if(""!==(u=u.trim()))switch(r=u.split(/\s+/),s=r.shift(),u=r.join(" "),s){case"format":a.format=r[0],a.version=r[1];break;case"comment":a.comments.push(u);break;case"element":void 0!==h&&a.elements.push(h),(h=Object()).name=r[0],h.count=parseInt(r[1]),h.properties=[];break;case"property":h.properties.push(e(r,this.propertyNameMapping));break;default:console.log("unhandled",s,r)}}return void 0!==h&&a.elements.push(h),a},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="";null!==(e=/end_header\s([\s\S]*)$/.exec(t))&&(n=e[1]);var s=n.split("\n"),r=0,a=0;i.useColor=!1;for(var l=0;l<s.length;l++){var h=s[l];if(""!==(h=h.trim())){a>=o.elements[r].count&&(r++,a=0);var c=this.parseASCIIElement(o.elements[r].properties,h);this.handleElement(i,o.elements[r].name,c),a++}}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 l=[],h=(n=this.binaryRead(t,e+r,i[a].countType,o))[0];r+=n[1];for(var c=0;c<h;c++)n=this.binaryRead(t,e+r,i[a].itemType,o),l.push(n[0]),r+=n[1];s[i[a].name]=l}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 l=0;l<o.elements[a].count;l++){r+=(e=this.binaryReadElement(s,r,o.elements[a].properties,n))[1];var h=e[0];this.handleElement(i,o.elements[a].name,h)}return this.postProcess(i)}}},{}],7:[function(t,e,i){e.exports={size:5,cellSize:10,extrudeSettings:{amount:1,bevelEnabled:!0,bevelSegments:1,steps:1,bevelSize:.5,bevelThickness:.5},autogenerated:!0,cells:[{q:-1,r:0,s:1,h:1,walkable:!0,userData:{}},{q:0,r:-1,s:1,h:1,walkable:!0,userData:{}},{q:0,r:0,s:0,h:1,walkable:!0,userData:{}},{q:1,r:-1,s:0,h:1,walkable:!0,userData:{}},{q:-1,r:1,s:0,h:0,walkable:!0,userData:{}},{q:0,r:1,s:-1,h:0,walkable:!0,userData:{}},{q:1,r:0,s:-1,h:0,walkable:!0,userData:{}}]}},{}],8:[function(t,e,i){function o(t){const e=document.getElementById(t),i=e.parentNode;try{i&&i.removeChild(e)}catch(t){}}function n(t,e,i){return new i(function(i,n){const s=e.timeout||5e3,r="script_"+Date.now()+"_"+Math.ceil(1e5*Math.random()),a=function(t,e){var i=document.createElement("script");return i.type="text/javascript",i.async=!0,i.id=e,i.src=t,i}(t,r),l=setTimeout(function(){n(new Error("Script request to "+t+" timed out")),o(r)},s),h=function(t){clearTimeout(t)};a.addEventListener("load",function(t){i({ok:!0}),h(l),o(r)}),a.addEventListener("error",function(e){n(new Error("Script request to "+t+" failed "+e)),h(l),o(r)}),function(t){const e=document.getElementsByTagName("script")[0];e.parentNode.insertBefore(t,e)}(a)})}e.exports=function(t){return t=t||{},function(e,i){return i=i||{},n(e,i,t.Promise||Promise)}}},{}],9:[function(t,e,i){var o=e.exports={VERSION:"0.1.1",PI:Math.PI,TAU:2*Math.PI,DEG_TO_RAD:.0174532925,RAD_TO_DEG:57.2957795,SQRT3:Math.sqrt(3),TILE:"tile",ENT:"entity",STR:"structure",HEX:"hex",SQR:"square",ABS:"abstract"};o.Board=function(t,e){if(!t)throw new Error("You must pass in a grid system for the board to use.");this.tiles=[],this.tileGroup=null,this.group=new THREE.Object3D,this.grid=null,this.overlay=null,this.finder=new o.AStarFinder(e),o.Loader.init(),this.setGrid(t)},o.Board.prototype={setEntityOnTile:function(t,e){var i=this.grid.cellToPixel(e.cell);t.position.copy(i),t.position.y+=t.heightOffset||0,t.tile&&(t.tile.entity=null),t.tile=e,e.entity=t},addTile:function(t){-1===this.tiles.indexOf(t)&&(this.tiles.push(t),this.snapTileToGrid(t),t.position.y=0,this.tileGroup.add(t.mesh),this.grid.add(t.cell),t.cell.tile=t)},removeTile:function(t){if(t){var e=this.tiles.indexOf(t);this.grid.remove(t.cell),-1!==e&&this.tiles.splice(e,1),t.dispose()}},removeAllTiles:function(){if(this.tileGroup)for(var t=this.tileGroup.children,e=0;e<t.length;e++)this.tileGroup.remove(t[e])},getTileAtCell:function(t){var e=this.grid.cellToHash(t);return t.tile||(void 0!==this.grid.cells[e]?this.grid.cells[e].tile:null)},snapToGrid:function(t){var e=this.grid.pixelToCell(t);t.copy(this.grid.cellToPixel(e))},snapTileToGrid:function(t){if(t.cell)t.position.copy(this.grid.cellToPixel(t.cell));else{var e=this.grid.pixelToCell(t.position);t.position.copy(this.grid.cellToPixel(e))}return t},getRandomTile:function(){var t=o.Tools.randomInt(0,this.tiles.length-1);return this.tiles[t]},findPath:function(t,e,i){return this.finder.findPath(t.cell,e.cell,i,this.grid)},setGrid:function(t){this.group.remove(this.tileGroup),this.grid&&t!==this.grid&&(this.removeAllTiles(),this.tiles.forEach(function(t){this.grid.remove(t.cell),t.dispose()}),this.grid.dispose()),this.grid=t,this.tiles=[],this.tileGroup=new THREE.Object3D,this.group.add(this.tileGroup)},generateOverlay:function(t){var e=new THREE.LineBasicMaterial({color:0,opacity:.3});this.overlay&&this.group.remove(this.overlay),this.overlay=new THREE.Object3D,this.grid.generateOverlay(t,this.overlay,e),this.group.add(this.overlay)},generateTilemap:function(t){this.reset();var e=this.grid.generateTiles(t);this.tiles=e,this.tileGroup=new THREE.Object3D;for(var i=0;i<e.length;i++)this.tileGroup.add(e[i].mesh);this.group.add(this.tileGroup)},reset:function(){this.removeAllTiles(),this.tileGroup&&this.group.remove(this.tileGroup)}},o.Board.prototype.constructor=o.Board,o.Cell=function(t,e,i,n){this.q=t||0,this.r=e||0,this.s=i||0,this.h=n||1,this.tile=null,this.userData={},this.walkable=!0,this._calcCost=0,this._priority=0,this._visited=!1,this._parent=null,this.uniqueID=o.LinkedList.generateID()},o.Cell.prototype={set:function(t,e,i){return this.q=t,this.r=e,this.s=i,this},copy:function(t){return this.q=t.q,this.r=t.r,this.s=t.s,this.h=t.h,this.tile=t.tile||null,this.userData=t.userData||{},this.walkable=t.walkable,this},add:function(t){return this.q+=t.q,this.r+=t.r,this.s+=t.s,this},equals:function(t){return this.q===t.q&&this.r===t.r&&this.s===t.s}},o.Cell.prototype.constructor=o.Cell,o.HexGrid=function(t){t=t||{},this.type=o.HEX,this.size=5,this.cellSize=void 0===t.cellSize?10:t.cellSize,this.cells={},this.numCells=0,this.extrudeSettings=null,this.autogenerated=!1;var e,i=[];for(e=0;6>e;e++)i.push(this._createVertex(e));for(this.cellShape=new THREE.Shape,this.cellShape.moveTo(i[0].x,i[0].y),e=1;6>e;e++)this.cellShape.lineTo(i[e].x,i[e].y);this.cellShape.lineTo(i[0].x,i[0].y),this.cellShape.autoClose=!0,this.cellGeo=new THREE.Geometry,this.cellGeo.vertices=i,this.cellGeo.verticesNeedUpdate=!0,this.cellShapeGeo=new THREE.ShapeGeometry(this.cellShape),this._cellWidth=2*this.cellSize,this._cellLength=.5*o.SQRT3*this._cellWidth,this._hashDelimeter=".",this._directions=[new o.Cell(1,-1,0),new o.Cell(1,0,-1),new o.Cell(0,1,-1),new o.Cell(-1,1,0),new o.Cell(-1,0,1),new o.Cell(0,-1,1)],this._diagonals=[new o.Cell(2,-1,-1),new o.Cell(1,1,-2),new o.Cell(-1,2,-1),new o.Cell(-2,1,1),new o.Cell(-1,-1,2),new o.Cell(1,-2,1)],this._list=[],this._vec3=new THREE.Vector3,this._cel=new o.Cell,this._conversionVec=new THREE.Vector3,this._geoCache=[],this._matCache=[]},o.HexGrid.TWO_THIRDS=2/3,o.HexGrid.prototype={cellToPixel:function(t){return this._vec3.x=t.q*this._cellWidth*.75,this._vec3.y=t.h,this._vec3.z=-(t.s-t.r)*this._cellLength*.5,this._vec3},pixelToCell:function(t){var e=t.x*(o.HexGrid.TWO_THIRDS/this.cellSize),i=(-t.x/3+o.SQRT3/3*t.z)/this.cellSize;return this._cel.set(e,i,-e-i),this._cubeRound(this._cel)},getCellAt:function(t){var e=t.x*(o.HexGrid.TWO_THIRDS/this.cellSize),i=(-t.x/3+o.SQRT3/3*t.z)/this.cellSize;return this._cel.set(e,i,-e-i),this._cubeRound(this._cel),this.cells[this.cellToHash(this._cel)]},getNeighbors:function(t,e,i){var o,n,s=this._directions.length;for(this._list.length=0,o=0;s>o;o++)this._cel.copy(t),this._cel.add(this._directions[o]),!(n=this.cells[this.cellToHash(this._cel)])||i&&!i(t,n)||this._list.push(n);if(e)for(o=0;s>o;o++)this._cel.copy(t),this._cel.add(this._diagonals[o]),!(n=this.cells[this.cellToHash(this._cel)])||i&&!i(t,n)||this._list.push(n);return this._list},getRandomCell:function(){var t,e=0,i=o.Tools.randomInt(0,this.numCells);for(t in this.cells){if(e===i)return this.cells[t];e++}return this.cells[t]},cellToHash:function(t){return t.q+this._hashDelimeter+t.r+this._hashDelimeter+t.s},distance:function(t,e){var i=Math.max(Math.abs(t.q-e.q),Math.abs(t.r-e.r),Math.abs(t.s-e.s));return i+=e.h-t.h},clearPath:function(){var t,e;for(t in this.cells)e=this.cells[t],e._calcCost=0,e._priority=0,e._parent=null,e._visited=!1},traverse:function(t){var e;for(e in this.cells)t(this.cells[e])},generateTile:function(t,e,i){var n=Math.abs(t.h);1>n&&(n=1);var s=this._geoCache[n];s||(this.extrudeSettings.amount=n,s=new THREE.ExtrudeGeometry(this.cellShape,this.extrudeSettings),this._geoCache[n]=s);var r=new o.Tile({size:this.cellSize,scale:e,cell:t,geometry:s,material:i});return t.tile=r,r},generateTiles:function(t){t=t||{};var e=[],i={tileScale:.95,cellSize:this.cellSize,material:null,extrudeSettings:{amount:1,bevelEnabled:!0,bevelSegments:1,steps:1,bevelSize:.5,bevelThickness:.5}};i=o.Tools.merge(i,t),this.cellSize=i.cellSize,this._cellWidth=2*this.cellSize,this._cellLength=.5*o.SQRT3*this._cellWidth,this.autogenerated=!0,this.extrudeSettings=i.extrudeSettings;var n,s,r;for(n in this.cells)r=this.cells[n],(s=this.generateTile(r,i.tileScale,i.material)).position.copy(this.cellToPixel(r)),s.position.y=0,e.push(s);return e},generateTilePoly:function(t){t||(t=new THREE.MeshBasicMaterial({color:2405631}));var e=new THREE.Mesh(this.cellShapeGeo,t);return this._vec3.set(1,0,0),e.rotateOnAxis(this._vec3,o.PI/2),e},generate:function(t){t=t||{},this.size=void 0===t.size?this.size:t.size;var e,i,n,s;for(e=-this.size;e<this.size+1;e++)for(i=-this.size;i<this.size+1;i++)n=-e-i,Math.abs(e)<=this.size&&Math.abs(i)<=this.size&&Math.abs(n)<=this.size&&(s=new o.Cell(e,i,n),this.add(s))},generateOverlay:function(t,e,i){var n,s,r,a=this.cellShape.createPointsGeometry();for(n=-t;t+1>n;n++)for(s=-t;t+1>s;s++)if(r=-n-s,Math.abs(n)<=t&&Math.abs(s)<=t&&Math.abs(r)<=t){this._cel.set(n,s,r);var l=new THREE.Line(a,i);l.position.copy(this.cellToPixel(this._cel)),l.rotation.x=90*o.DEG_TO_RAD,e.add(l)}},add:function(t){var e=this.cellToHash(t);if(!this.cells[e])return this.cells[e]=t,this.numCells++,t},remove:function(t){var e=this.cellToHash(t);this.cells[e]&&(delete this.cells[e],this.numCells--)},dispose:function(){this.cells=null,this.numCells=0,this.cellShape=null,this.cellGeo.dispose(),this.cellGeo=null,this.cellShapeGeo.dispose(),this.cellShapeGeo=null,this._list=null,this._vec3=null,this._conversionVec=null,this._geoCache=null,this._matCache=null},load:function(t,e,i){var n=this;o.Tools.getJSON({url:t,callback:function(t){n.fromJSON(t),e.call(i||null,t)},cache:!1,scope:n})},fromJSON:function(t){var e,i,n=t.cells;for(this.cells={},this.numCells=0,this.size=t.size,this.cellSize=t.cellSize,this._cellWidth=2*this.cellSize,this._cellLength=.5*o.SQRT3*this._cellWidth,this.extrudeSettings=t.extrudeSettings,this.autogenerated=t.autogenerated,e=0;e<n.length;e++)(i=new o.Cell).copy(n[e]),this.add(i)},toJSON:function(){var t,e,i={size:this.size,cellSize:this.cellSize,extrudeSettings:this.extrudeSettings,autogenerated:this.autogenerated},o=[];for(e in this.cells)t=this.cells[e],o.push({q:t.q,r:t.r,s:t.s,h:t.h,walkable:t.walkable,userData:t.userData});return i.cells=o,i},_createVertex:function(t){var e=o.TAU/6*t;return new THREE.Vector3(this.cellSize*Math.cos(e),this.cellSize*Math.sin(e),0)},_cubeRound:function(t){var e=Math.round(t.q),i=Math.round(t.r),o=Math.round(t.s),n=Math.abs(e-t.q),s=Math.abs(i-t.r),r=Math.abs(o-t.s);return n>s&&n>r?e=-i-o:s>r?i=-e-o:o=-e-i,this._cel.set(e,i,o)}},o.HexGrid.prototype.constructor=o.HexGrid,o.SqrGrid=function(t){t=t||{},this.type=o.SQR,this.size=5,this.cellSize=void 0===t.cellSize?10:t.cellSize,this.cells={},this.numCells=0,this.extrudeSettings=null,this.autogenerated=!1;var e=[];e.push(new THREE.Vector3),e.push(new THREE.Vector3(-this.cellSize,this.cellSize)),e.push(new THREE.Vector3(this.cellSize,this.cellSize)),e.push(new THREE.Vector3(this.cellSize,-this.cellSize)),this.cellShape=new THREE.Shape,this.cellShape.moveTo(-this.cellSize,-this.cellSize),this.cellShape.lineTo(-this.cellSize,this.cellSize),this.cellShape.lineTo(this.cellSize,this.cellSize),this.cellShape.lineTo(this.cellSize,-this.cellSize),this.cellShape.lineTo(-this.cellSize,-this.cellSize),this.cellGeo=new THREE.Geometry,this.cellGeo.vertices=e,this.cellGeo.verticesNeedUpdate=!0,this.cellShapeGeo=new THREE.ShapeGeometry(this.cellShape),this._fullCellSize=2*this.cellSize,this._hashDelimeter=".",this._directions=[new o.Cell(1,0,0),new o.Cell(0,-1,0),new o.Cell(-1,0,0),new o.Cell(0,1,0)],this._diagonals=[new o.Cell(-1,-1,0),new o.Cell(-1,1,0),new o.Cell(1,1,0),new o.Cell(1,-1,0)],this._list=[],this._vec3=new THREE.Vector3,this._cel=new o.Cell,this._conversionVec=new THREE.Vector3,this._geoCache=[],this._matCache=[]},o.SqrGrid.prototype={cellToPixel:function(t){return this._vec3.x=t.q*this._fullCellSize,this._vec3.y=t.h,this._vec3.z=t.r*this._fullCellSize,this._vec3},pixelToCell:function(t){var e=Math.round(t.x/this._fullCellSize),i=Math.round(t.z/this._fullCellSize);return this._cel.set(e,i,0)},getCellAt:function(t){var e=Math.round(t.x/this._fullCellSize),i=Math.round(t.z/this._fullCellSize);return this._cel.set(e,i),this.cells[this.cellToHash(this._cel)]},getNeighbors:function(t,e,i){var o,n,s=this._directions.length;for(this._list.length=0,o=0;s>o;o++)this._cel.copy(t),this._cel.add(this._directions[o]),!(n=this.cells[this.cellToHash(this._cel)])||i&&!i(t,n)||this._list.push(n);if(e)for(o=0;s>o;o++)this._cel.copy(t),this._cel.add(this._diagonals[o]),!(n=this.cells[this.cellToHash(this._cel)])||i&&!i(t,n)||this._list.push(n);return this._list},getRandomCell:function(){var t,e=0,i=o.Tools.randomInt(0,this.numCells);for(t in this.cells){if(e===i)return this.cells[t];e++}return this.cells[t]},cellToHash:function(t){return t.q+this._hashDelimeter+t.r},distance:function(t,e){var i=Math.max(Math.abs(t.q-e.q),Math.abs(t.r-e.r));return i+=e.h-t.h},clearPath:function(){var t,e;for(t in this.cells)e=this.cells[t],e._calcCost=0,e._priority=0,e._parent=null,e._visited=!1},traverse:function(t){var e;for(e in this.cells)t(this.cells[e])},generateTile:function(t,e,i){var n=Math.abs(t.h);1>n&&(n=1);var s=this._geoCache[n];s||(this.extrudeSettings.amount=n,s=new THREE.ExtrudeGeometry(this.cellShape,this.extrudeSettings),this._geoCache[n]=s);var r=new o.Tile({size:this.cellSize,scale:e,cell:t,geometry:s,material:i});return t.tile=r,r},generateTiles:function(t){t=t||{};var e=[],i={tileScale:.95,cellSize:this.cellSize,material:null,extrudeSettings:{amount:1,bevelEnabled:!0,bevelSegments:1,steps:1,bevelSize:.5,bevelThickness:.5}};i=o.Tools.merge(i,t),this.cellSize=i.cellSize,this._fullCellSize=2*this.cellSize,this.autogenerated=!0,this.extrudeSettings=i.extrudeSettings;var n,s,r;for(n in this.cells)r=this.cells[n],(s=this.generateTile(r,i.tileScale,i.material)).position.copy(this.cellToPixel(r)),s.position.y=0,e.push(s);return e},generateTilePoly:function(t){t||(t=new THREE.MeshBasicMaterial({color:2405631}));var e=new THREE.Mesh(this.cellShapeGeo,t);return this._vec3.set(1,0,0),e.rotateOnAxis(this._vec3,o.PI/2),e},generate:function(t){t=t||{},this.size=void 0===t.size?this.size:t.size;var e,i,n,s=Math.ceil(this.size/2);for(e=-s;s>e;e++)for(i=-s;s>i;i++)n=new o.Cell(e,i+1),this.add(n)},generateOverlay:function(t,e,i){var n,s,r=Math.ceil(t/2);for(n=-r;r>n;n++)for(s=-r;r>s;s++){this._cel.set(n,s);var a=new THREE.Line(this.cellGeo,i);a.position.copy(this.cellToPixel(this._cel)),a.rotation.x=90*o.DEG_TO_RAD,e.add(a)}},add:function(t){var e=this.cellToHash(t);if(!this.cells[e])return this.cells[e]=t,this.numCells++,t},remove:function(t){var e=this.cellToHash(t);this.cells[e]&&(delete this.cells[e],this.numCells--)},dispose:function(){this.cells=null,this.numCells=0,this.cellShape=null,this.cellGeo.dispose(),this.cellGeo=null,this.cellShapeGeo.dispose(),this.cellShapeGeo=null,this._list=null,this._vec3=null,this._conversionVec=null,this._geoCache=null,this._matCache=null},load:function(t,e,i){o.Tools.getJSON({url:t,callback:function(t){this.fromJSON(t),e.call(i||null,t)},cache:!1,scope:this})},fromJSON:function(t){var e,i,n=t.cells;for(this.cells={},this.numCells=0,this.size=t.size,this.cellSize=t.cellSize,this._fullCellSize=2*this.cellSize,this.extrudeSettings=t.extrudeSettings,this.autogenerated=t.autogenerated,e=0;e<n.length;e++)(i=new o.Cell).copy(n[e]),this.add(i)},toJSON:function(){var t,e,i={size:this.size,cellSize:this.cellSize,extrudeSettings:this.extrudeSettings,autogenerated:this.autogenerated},o=[];for(e in this.cells)t=this.cells[e],o.push({q:t.q,r:t.r,s:t.s,h:t.h,walkable:t.walkable,userData:t.userData});return i.cells=o,i}},o.SqrGrid.prototype.constructor=o.SqrGrid,o.Tile=function(t){t=t||{};var e={cell:null,geometry:null,material:null};if(!(e=o.Tools.merge(e,t)).cell||!e.geometry)throw new Error("Missing vg.Tile configuration");this.cell=e.cell,this.cell.tile&&this.cell.tile!==this&&this.cell.tile.dispose(),this.cell.tile=this,this.uniqueID=o.Tools.generateID(),this.geometry=e.geometry,this.material=e.material,this.material||(this.material=new THREE.MeshPhongMaterial({color:o.Tools.randomizeRGB("30, 30, 30",13)})),this.objectType=o.TILE,this.entity=null,this.userData={},this.selected=!1,this.highlight="0x0084cc",this.mesh=new THREE.Mesh(this.geometry,this.material),this.mesh.userData.structure=this,this.position=this.mesh.position,this.rotation=this.mesh.rotation,this.rotation.x=-90*o.DEG_TO_RAD,this.mesh.scale.set(e.scale,e.scale,1),this.material.emissive?this._emissive=this.material.emissive.getHex():this._emissive=null},o.Tile.prototype={select:function(){return this.material.emissive&&this.material.emissive.setHex(this.highlight),this.selected=!0,this},deselect:function(){return null!==this._emissive&&this.material.emissive&&this.material.emissive.setHex(this._emissive),this.selected=!1,this},toggle:function(){return this.selected?this.deselect():this.select(),this},dispose:function(){this.cell&&this.cell.tile&&(this.cell.tile=null),this.cell=null,this.position=null,this.rotation=null,this.mesh.parent&&this.mesh.parent.remove(this.mesh),this.mesh.userData.structure=null,this.mesh=null,this.material=null,this.userData=null,this.entity=null,this.geometry=null,this._emissive=null}},o.Tile.prototype.constructor=o.Tile,function(){var t=function(){this.first=null,this.last=null,this.length=0,this.objToNodeMap={},this.uniqueID=Date.now()+""+Math.floor(1e3*Math.random()),this.sortArray=[]};t.generateID=function(){return Math.random().toString(36).slice(2)+Date.now()},(t.prototype={getNode:function(t){return this.objToNodeMap[t.uniqueID]},addNode:function(e){var i=new function(){this.obj=null,this.next=null,this.prev=null,this.free=!0};if(!e.uniqueID)try{e.uniqueID=t.generateID()}catch(t){return console.error("[LinkedList.addNode] obj passed is immutable: cannot attach necessary identifier"),null}return i.obj=e,i.free=!1,this.objToNodeMap[e.uniqueID]=i,i},swapObjects:function(t,e){this.objToNodeMap[t.obj.uniqueID]=null,this.objToNodeMap[e.uniqueID]=t,t.obj=e},add:function(t){var e=this.objToNodeMap[t.uniqueID];if(e){if(!1===e.free)return;e.obj=t,e.free=!1,e.next=null,e.prev=null}else e=this.addNode(t);if(this.first){if(!this.last)throw new Error("[LinkedList.add] No last in the list -- that shouldn't happen here");this.last.next=e,e.prev=this.last,this.last=e,e.next=null}else this.first=e,this.last=e,e.next=null,e.prev=null;this.length++,this.showDebug&&this.dump("after add")},has:function(t){return!!this.objToNodeMap[t.uniqueID]},moveUp:function(t){this.dump("before move up");var e=this.getNode(t);if(!e)throw"Oops, trying to move an object that isn't in the list";if(e.prev){var i=e.prev,o=i.prev;e==this.last&&(this.last=i);var n=e.next;o&&(o.next=e),e.next=i,e.prev=i.prev,i.next=n,i.prev=e,this.first==i&&(this.first=e)}},moveDown:function(t){var e=this.getNode(t);if(!e)throw"Oops, trying to move an object that isn't in the list";if(e.next){var i=e.next;this.moveUp(i.obj),this.last==i&&(this.last=e)}},sort:function(t){var e,i,o=this.sortArray,n=this.first;for(o.length=0;n;)o.push(n.obj),n=n.next;for(this.clear(),o.sort(t),i=o.length,e=0;i>e;e++)this.add(o[e])},remove:function(t){var e=this.getNode(t);return!(!e||e.free)&&(e.prev&&(e.prev.next=e.next),e.next&&(e.next.prev=e.prev),e.prev||(this.first=e.next),e.next||(this.last=e.prev),e.free=!0,e.prev=null,e.next=null,this.length--,!0)},shift:function(){var t=this.first;return 0===this.length?null:(t.prev&&(t.prev.next=t.next),t.next&&(t.next.prev=t.prev),this.first=t.next,t.next||(this.last=null),t.free=!0,t.prev=null,t.next=null,this.length--,t.obj)},pop:function(){var t=this.last;return 0===this.length?null:(t.prev&&(t.prev.next=t.next),t.next&&(t.next.prev=t.prev),this.last=t.prev,t.prev||(this.first=null),t.free=!0,t.prev=null,t.next=null,this.length--,t.obj)},concat:function(t){for(var e=t.first;e;)this.add(e.obj),e=e.next},clear:function(){for(var t=this.first;t;)t.free=!0,t=t.next;this.first=null,this.length=0},dispose:function(){for(var t=this.first;t;)t.obj=null,t=t.next;this.first=null,this.objToNodeMap=null},dump:function(t){console.log("===================="+t+"=====================");for(var e=this.first;e;)console.log("{"+e.obj.toString()+"} previous="+(e.prev?e.prev.obj:"NULL")),e=e.next();console.log("==================================="),console.log("Last: {"+(this.last?this.last.obj:"NULL")+"} First: {"+(this.first?this.first.obj:"NULL")+"}")}}).constructor=t,o.LinkedList=t}(),function(){var t=function(t,e,i,o,n){this._listener=e,this.isOnce=i,this.context=o,this.signal=t,this._priority=n||0};(t.prototype={active:!0,params:null,execute:function(t){var e,i;return this.active&&this._listener&&(i=this.params?this.params.concat(t):t,e=this._listener.apply(this.context,i),this.isOnce&&this.detach()),e},detach:function(){return this.isBound()?this.signal.remove(this._listener,this.context):null},isBound:function(){return!!this.signal&&!!this._listener},_destroy:function(){delete this.signal,delete this._listener,delete this.context},toString:function(){return"[SignalBinding isOnce:"+this.isOnce+", isBound:"+this.isBound()+", active:"+this.active+"]"}}).constructor=t;var e=function(){this._bindings=[],this._prevParams=null;var t=this;this.dispatch=function(){e.prototype.dispatch.apply(t,arguments)}};e.prototype={memorize:!1,_shouldPropagate:!0,active:!0,validateListener:function(t,e){if("function"!=typeof t)throw new Error("Signal: listener is a required param of {fn}() and should be a Function.".replace("{fn}",e))},_registerListener:function(e,i,o,n){var s,r=this._indexOfListener(e,o);if(-1!==r){if((s=this._bindings[r]).isOnce!==i)throw new Error("You cannot add"+(i?"":"Once")+"() then add"+(i?"Once":"")+"() the same listener without removing the relationship first.")}else s=new t(this,e,i,o,n),this._addBinding(s);return this.memorize&&this._prevParams&&s.execute(this._prevParams),s},_addBinding:function(t){var e=this._bindings.length;do{e--}while(this._bindings[e]&&t._priority<=this._bindings[e]._priority);this._bindings.splice(e+1,0,t)},_indexOfListener:function(t,e){for(var i,o=this._bindings.length;o--;)if((i=this._bindings[o])._listener===t&&i.context===e)return o;return-1},has:function(t,e){return-1!==this._indexOfListener(t,e)},add:function(t,e,i){return this.validateListener(t,"add"),this._registerListener(t,!1,e,i)},addOnce:function(t,e,i){return this.validateListener(t,"addOnce"),this._registerListener(t,!0,e,i)},remove:function(t,e){this.validateListener(t,"remove");var i=this._indexOfListener(t,e);return-1!==i&&(this._bindings[i]._destroy(),this._bindings.splice(i,1)),t},removeAll:function(t){void 0===t&&(t=null);for(var e=this._bindings.length;e--;)t?this._bindings[e].context===t&&(this._bindings[e]._destroy(),this._bindings.splice(e,1)):this._bindings[e]._destroy();t||(this._bindings.length=0)},getNumListeners:function(){return this._bindings.length},halt:function(){this._shouldPropagate=!1},dispatch:function(){if(this.active){var t,e=Array.prototype.slice.call(arguments),i=this._bindings.length;if(this.memorize&&(this._prevParams=e),i){t=this._bindings.slice(),this._shouldPropagate=!0;do{i--}while(t[i]&&this._shouldPropagate&&!1!==t[i].execute(e))}}},forget:function(){this._prevParams=null},dispose:function(){this.removeAll(),delete this._bindings,delete this._prevParams},toString:function(){return"[Signal active:"+this.active+" numListeners:"+this.getNumListeners()+"]"}},e.prototype.constructor=e,o.Signal=e}(),o.AStarFinder=function(t){t=t||{};var e={allowDiagonal:!1,heuristicFilter:null};e=o.Tools.merge(e,t),this.allowDiagonal=e.allowDiagonal,this.heuristicFilter=e.heuristicFilter,this.list=new o.LinkedList},o.AStarFinder.prototype={findPath:function(t,e,i,n){var s,r,a,l,h,c;for(i=i||this.heuristicFilter,n.clearPath(),this.list.clear(),this.list.add(t);this.list.length>0;){if(this.list.sort(this.compare),s=this.list.shift(),s._visited=!0,s===e)return o.PathUtil.backtrace(e);for(h=0,c=(a=n.getNeighbors(s,this.allowDiagonal,i)).length;c>h;h++)if((l=a[h]).walkable&&(r=s._calcCost+n.distance(s,l),!l._visited||r<l._calcCost)){if(l._visited=!0,l._parent=s,l._calcCost=r,l._priority=r+n.distance(e,l),l===e)return o.PathUtil.backtrace(e);this.list.add(l)}}return null},compare:function(t,e){return t._priority-e._priority}},o.AStarFinder.prototype.constructor=o.AStarFinder,o.PathUtil={backtrace:function(t){for(var e=[t];t._parent;)t=t._parent,e.push(t);return e.reverse()},biBacktrace:function(t,e){var i=this.backtrace(t),o=this.backtrace(e);return i.concat(o.reverse())},pathLength:function(t){var e,i,o,n,s,r=0;for(e=1;e<t.length;++e)i=t[e-1],o=t[e],n=i[0]-o[0],s=i[1]-o[1],r+=Math.sqrt(n*n+s*s);return r},interpolate:function(t,e,i,o){var n,s,r,a,l,h,c=Math.abs,u=[];for(r=c(i-t),a=c(o-e),n=i>t?1:-1,s=o>e?1:-1,l=r-a;t!==i||e!==o;)u.push([t,e]),(h=2*l)>-a&&(l-=a,t+=n),r>h&&(l+=r,e+=s);return u},expandPath:function(t){var e,i,o,n,s,r,a=[],l=t.length;if(2>l)return a;for(s=0;l-1>s;++s)for(e=t[s],i=t[s+1],o=this.interpolate(e[0],e[1],i[0],i[1]),n=o.length,r=0;n-1>r;++r)a.push(o[r]);return a.push(t[l-1]),a},smoothenPath:function(t,e){var i,o,n,s,r,a,l,h,c,u,p,d,f=e.length,v=e[0][0],m=e[0][1],y=e[f-1][0],g=e[f-1][1];for(r=[[i=v,o=m]],l=2;f>l;++l){for(n=(c=e[l])[0],s=c[1],u=this.interpolate(i,o,n,s),d=!1,h=1;h<u.length;++h)if(p=u[h],!t.isWalkableAt(p[0],p[1])){d=!0;break}d&&(a=e[l-1],r.push(a),i=a[0],o=a[1])}return r.push([y,g]),r},compressPath:function(t){if(t.length<3)return t;var e,i,o,n,s,r,a=[],l=t[0][0],h=t[0][1],c=t[1][0],u=t[1][1],p=c-l,d=u-h;for(p/=s=Math.sqrt(p*p+d*d),d/=s,a.push([l,h]),r=2;r<t.length;r++)e=c,i=u,o=p,n=d,c=t[r][0],u=t[r][1],p=c-e,d=u-i,s=Math.sqrt(p*p+d*d),p/=s,d/=s,(p!==o||d!==n)&&a.push([e,i]);return a.push([c,u]),a}},o.Loader={manager:null,imageLoader:null,crossOrigin:!1,init:function(t){this.crossOrigin=t||!1,this.manager=new THREE.LoadingManager(function(){},function(){},function(){console.warn("Error loading images")}),this.imageLoader=new THREE.ImageLoader(this.manager),this.imageLoader.crossOrigin=t},loadTexture:function(t,e,i,o){var n=new THREE.Texture(null,e);return this.imageLoader.load(t,function(t){n.image=t,n.needsUpdate=!0,i&&i(n)},null,function(t){o&&o(t)}),n.sourceFile=t,n}},o.MouseCaster=function(t,e,i){this.down=!1,this.rightDown=!1,this.pickedObject=null,this.selectedObject=null,this.allHits=null,this.active=!0,this.shift=!1,this.ctrl=!1,this.wheel=0,this.position=new THREE.Vector3,this.screenPosition=new THREE.Vector2,this.signal=new o.Signal,this.group=t,this._camera=e,this._raycaster=new THREE.Raycaster,this._preventDefault=!1,(i=i||document).addEventListener("mousemove",this._onDocumentMouseMove.bind(this),!1),i.addEventListener("mousedown",this._onDocumentMouseDown.bind(this),!1),i.addEventListener("mouseup",this._onDocumentMouseUp.bind(this),!1),i.addEventListener("mousewheel",this._onMouseWheel.bind(this),!1),i.addEventListener("DOMMouseScroll",this._onMouseWheel.bind(this),!1)},o.MouseCaster.OVER="over",o.MouseCaster.OUT="out",o.MouseCaster.DOWN="down",o.MouseCaster.UP="up",o.MouseCaster.CLICK="click",o.MouseCaster.WHEEL="wheel",o.MouseCaster.prototype={update:function(){if(this.active){this._raycaster.setFromCamera(this.screenPosition,this._camera);var t,e,i=this._raycaster.intersectObject(this.group,!0);i.length>0?(t=i[0],e=t.object.userData.structure,this.pickedObject!=e&&(this.pickedObject&&this.signal.dispatch(o.MouseCaster.OUT,this.pickedObject),this.pickedObject=e,this.selectedObject=null,this.signal.dispatch(o.MouseCaster.OVER,this.pickedObject)),this.position.copy(t.point),this.screenPosition.z=t.distance):(this.pickedObject&&this.signal.dispatch(o.MouseCaster.OUT,this.pickedObject),this.pickedObject=null,this.selectedObject=null),this.allHits=i}},preventDefault:function(){this._preventDefault=!0},_onDocumentMouseDown:function(t){return(t=t||window.event).preventDefault(),this._preventDefault?(this._preventDefault=!1,!1):(this.pickedObject&&(this.selectedObject=this.pickedObject),this.shift=t.shiftKey,this.ctrl=t.ctrlKey,this.down=1===t.which,this.rightDown=3===t.which,void this.signal.dispatch(o.MouseCaster.DOWN,this.pickedObject))},_onDocumentMouseUp:function(t){return t.preventDefault(),this._preventDefault?(this._preventDefault=!1,!1):(this.shift=t.shiftKey,this.ctrl=t.ctrlKey,this.signal.dispatch(o.MouseCaster.UP,this.pickedObject),this.selectedObject&&this.pickedObject&&this.selectedObject.uniqueID===this.pickedObject.uniqueID&&this.signal.dispatch(o.MouseCaster.CLICK,this.pickedObject),this.down=1!==t.which&&this.down,void(this.rightDown=3!==t.which&&this.rightDown))},_onDocumentMouseMove:function(t){t.preventDefault(),this.screenPosition.x=t.clientX/window.innerWidth*2-1,this.screenPosition.y=-t.clientY/window.innerHeight*2+1},_onMouseWheel:function(t){if(this.active){t.preventDefault(),t.stopPropagation();var e=0;void 0!==t.wheelDelta?e=t.wheelDelta:void 0!==t.detail&&(e=-t.detail),e>0?this.wheel++:this.wheel--,this.signal.dispatch(o.MouseCaster.WHEEL,this.wheel)}}},o.MouseCaster.prototype.constructor=o.MouseCaster,o.Scene=function(t,e){var i={element:document.body,alpha:!0,antialias:!0,clearColor:"#fff",sortObjects:!1,fog:null,light:new THREE.DirectionalLight(16777215),lightPosition:null,cameraType:"PerspectiveCamera",cameraPosition:null,orthoZoom:4},n={minDistance:100,maxDistance:1e3,zoomSpeed:2,noZoom:!1};if(i=o.Tools.merge(i,t),"boolean"!=typeof e&&(n=o.Tools.merge(n,e)),this.renderer=new THREE.WebGLRenderer({alpha:i.alpha,antialias:i.antialias}),this.renderer.setClearColor(i.clearColor,0),this.renderer.sortObjects=i.sortObjects,this.width=window.innerWidth,this.height=window.innerHeight,this.orthoZoom=i.orthoZoom,this.container=new THREE.Scene,this.container.fog=i.fog,this.container.add(new THREE.AmbientLight(14540253)),i.lightPosition||i.light.position.set(-1,1,-1).normalize(),this.container.add(i.light),"OrthographicCamera"===i.cameraType){var s=window.innerWidth/this.orthoZoom,r=window.innerHeight/this.orthoZoom;this.camera=new THREE.OrthographicCamera(s/-2,s/2,r/2,r/-2,1,5e3)}else this.camera=new THREE.PerspectiveCamera(50,this.width/this.height,1,5e3);this.contolled=!!e,this.contolled&&(this.controls=new THREE.OrbitControls(this.camera,this.renderer.domElement),this.controls.minDistance=n.minDistance,this.controls.maxDistance=n.maxDistance,this.controls.zoomSpeed=n.zoomSpeed,this.controls.noZoom=n.noZoom),i.cameraPosition&&this.camera.position.copy(i.cameraPosition),window.addEventListener("resize",function(){if(this.width=window.innerWidth,this.height=window.innerHeight,"OrthographicCamera"===this.camera.type){var t=this.width/this.orthoZoom,e=this.height/this.orthoZoom;this.camera.left=t/-2,this.camera.right=t/2,this.camera.top=e/2,this.camera.bottom=e/-2}else this.camera.aspect=this.width/this.height;this.camera.updateProjectionMatrix(),this.renderer.setSize(this.width,this.height)}.bind(this),!1),this.attachTo(i.element)},o.Scene.prototype={attachTo:function(t){t.style.width=this.width+"px",t.style.height=this.height+"px",this.renderer.setPixelRatio(window.devicePixelRatio),this.renderer.setSize(this.width,this.height),t.appendChild(this.renderer.domElement)},add:function(t){this.container.add(t)},remove:function(t){this.container.remove(t)},render:function(){this.contolled&&this.controls.update(),this.renderer.render(this.container,this.camera)},updateOrthoZoom:function(){if(this.orthoZoom<=0)this.orthoZoom=0;else{var t=this.width/this.orthoZoom,e=this.height/this.orthoZoom;this.camera.left=t/-2,this.camera.right=t/2,this.camera.top=e/2,this.camera.bottom=e/-2,this.camera.updateProjectionMatrix()}},focusOn:function(t){this.camera.lookAt(t.position)}},o.Scene.prototype.constructor=o.Scene,o.SelectionManager=function(t){this.mouse=t,this.onSelect=new o.Signal,this.onDeselect=new o.Signal,this.selected=null,this.toggleSelection=!1,this.mouse.signal.add(this.onMouse,this)},o.SelectionManager.prototype={select:function(t,e){t&&(e=e||!0,this.selected!==t&&this.clearSelection(e),t.selected?this.toggleSelection&&(e&&this.onDeselect.dispatch(t),t.deselect()):t.select(),this.selected=t,e&&this.onSelect.dispatch(t))},clearSelection:function(t){t=t||!0,this.selected&&(t&&this.onDeselect.dispatch(this.selected),this.selected.deselect()),this.selected=null},onMouse:function(t,e){switch(t){case o.MouseCaster.DOWN:e||this.clearSelection();break;case o.MouseCaster.CLICK:this.select(e)}}},o.SelectionManager.prototype.constructor=o.SelectionManager,o.Tools={clamp:function(t,e,i){return Math.max(e,Math.min(i,t))},sign:function(t){return t&&t/Math.abs(t)},random:function(t,e){return 1===arguments.length?Math.random()*t-.5*t:Math.random()*(e-t)+t},randomInt:function(t,e){return 1===arguments.length?Math.random()*t-.5*t|0:Math.random()*(e-t+1)+t|0},normalize:function(t,e,i){return(t-e)/(i-e)},getShortRotation:function(t){return(t%=this.TAU)>this.PI?t-=this.TAU:t<-this.PI&&(t+=this.TAU),t},generateID:function(){return Math.random().toString(36).slice(2)+Date.now()},isPlainObject:function(t){if("object"!=typeof t||t.nodeType||t===t.window)return!1;try{if(t.constructor&&!Object.prototype.hasOwnProperty.call(t.constructor.prototype,"isPrototypeOf"))return!1}catch(t){return!1}return!0},merge:function(t,e){var i=this,o=Array.isArray(e),n=o&&[]||{};return o?(t=t||[],n=n.concat(t),e.forEach(function(e,o){void 0===n[o]?n[o]=e:i.isPlainObject(e)?n[o]=i.merge(t[o],e):-1===t.indexOf(e)&&n.push(e)}),n):(t&&i.isPlainObject(t)&&Object.keys(t).forEach(function(e){n[e]=t[e]}),Object.keys(e).forEach(function(o){e[o]&&i.isPlainObject(e[o])&&t[o]?n[o]=i.merge(t[o],e[o]):n[o]=e[o]}),n)},now:function(){return window.nwf?window.nwf.system.Performance.elapsedTime:window.performance.now()},empty:function(t){for(;t.lastChild;)t.removeChild(t.lastChild)},radixSort:function(t,e,i,o){if(e=e||0,i=i||t.length,o=o||31,!(e>=i-1||0>o)){for(var n=e,s=i,r=1<<o;s>n;)if(t[n]&r){--s;var a=t[n];t[n]=t[s],t[s]=a}else++n;this.radixSort(t,e,s,o-1),this.radixSort(t,s,i,o-1)}},randomizeRGB:function(t,e){var i,o,n=t.split(","),s="rgb(";for(e=this.randomInt(e),i=0;3>i;i++)0>(o=parseInt(n[i])+e)?o=0:o>255&&(o=255),s+=o+",";return s=s.substring(0,s.length-1),s+=")"},getJSON:function(t){var e=new XMLHttpRequest,i=void 0!==t.cache&&t.cache?t.url:t.url+"?t="+Math.floor(1e4*Math.random())+Date.now();e.onreadystatechange=function(){if(200!==this.status)0!==this.status&&console.warn("[Tools.getJSON] Error: "+this.status+" ("+this.statusText+") :: "+t.url);else{var e=null;try{e=JSON.parse(this.responseText)}catch(t){return}t.callback.call(t.scope||null,e)}},e.open("GET",i,!0),e.setRequestHeader("Accept","application/json"),e.setRequestHeader("Content-Type","application/json"),e.send("")}}},{}],10:[function(t,e,i){!function(t){function e(t,e){return-1!==String(t).indexOf(e)}function i(t,e,i){u!==e&&c!==e&&h!==e||Object.keys(i).forEach(function(e){t[e]=i[e]})}function o(t){var e="keyCode"in t?t.keyCode:"which"in t?t.which:0,i=function(){if(g||"keyLocation"in t){var i=g?t.location:t.keyLocation;if(i&&e in f[i])return f[i][e]}return"keyIdentifier"in t&&t.keyIdentifier in d?d[t.keyIdentifier]:e in p?p[e]:null}();if(!i)return null;var o=function(){var e=v[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}}var n="KeyboardEvent"in t;n||(t.KeyboardEvent=function(){throw TypeError("Illegal constructor")}),t.KeyboardEvent.DOM_KEY_LOCATION_STANDARD=0,t.KeyboardEvent.DOM_KEY_LOCATION_LEFT=1,t.KeyboardEvent.DOM_KEY_LOCATION_RIGHT=2,t.KeyboardEvent.DOM_KEY_LOCATION_NUMPAD=3;var s=window.KeyboardEvent.DOM_KEY_LOCATION_STANDARD,r=window.KeyboardEvent.DOM_KEY_LOCATION_LEFT,a=window.KeyboardEvent.DOM_KEY_LOCATION_RIGHT,l=window.KeyboardEvent.DOM_KEY_LOCATION_NUMPAD,h=e(navigator.platform,"Win")?"win":e(navigator.platform,"Mac")?"mac":e(navigator.platform,"CrOS")?"cros":e(navigator.platform,"Linux")?"linux":e(navigator.userAgent,"iPad")||e(navigator.platform,"iPod")||e(navigator.platform,"iPhone")?"ios":"",c=e(navigator.userAgent,"Chrome/")?"chrome":e(navigator.vendor,"Apple")?"safari":e(navigator.userAgent,"MSIE")?"ie":e(navigator.userAgent,"Gecko/")?"moz":e(navigator.userAgent,"Opera/")?"opera":"",u=c+"-"+h,p={3:{code:"Cancel"},6:{code:"Help"},8:{code:"Backspace"},9:{code:"Tab"},12:{code:"Clear"},13:{code:"Enter"},16:{code:"Shift"},17:{code:"Control"},18:{code:"Alt"},19:{code:"Pause"},20:{code:"CapsLock"},21:{code:"KanaMode"},22:{code:"HangulMode"},23:{code:"JunjaMode"},24:{code:"FinalMode"},25:{code:"KanjiMode"},27:{code:"Escape"},28:{code:"Convert"},29:{code:"NonConvert"},30:{code:"Accept"},31:{code:"ModeChange"},32:{code:"Space"},33:{code:"PageUp"},34:{code:"PageDown"},35:{code:"End"},36:{code:"Home"},37:{code:"ArrowLeft"},38:{code:"ArrowUp"},39:{code:"ArrowRight"},40:{code:"ArrowDown"},41:{code:"Select"},42:{code:"Print"},43:{code:"Execute"},44:{code:"PrintScreen"},45:{code:"Insert"},46:{code:"Delete"},47:{code:"Help"},48:{code:"Digit0",keyCap:"0"},49:{code:"Digit1",keyCap:"1"},50:{code:"Digit2",keyCap:"2"},51:{code:"Digit3",keyCap:"3"},52:{code:"Digit4",keyCap:"4"},53:{code:"Digit5",keyCap:"5"},54:{code:"Digit6",keyCap:"6"},55:{code:"Digit7",keyCap:"7"},56:{code:"Digit8",keyCap:"8"},57:{code:"Digit9",keyCap:"9"},65:{code:"KeyA",keyCap:"a"},66:{code:"KeyB",keyCap:"b"},67:{code:"KeyC",keyCap:"c"},68:{code:"KeyD",keyCap:"d"},69:{code:"KeyE",keyCap:"e"},70:{code:"KeyF",keyCap:"f"},71:{code:"KeyG",keyCap:"g"},72:{code:"KeyH",keyCap:"h"},73:{code:"KeyI",keyCap:"i"},74:{code:"KeyJ",keyCap:"j"},75:{code:"KeyK",keyCap:"k"},76:{code:"KeyL",keyCap:"l"},77:{code:"KeyM",keyCap:"m"},78:{code:"KeyN",keyCap:"n"},79:{code:"KeyO",keyCap:"o"},80:{code:"KeyP",keyCap:"p"},81:{code:"KeyQ",keyCap:"q"},82:{code:"KeyR",keyCap:"r"},83:{code:"KeyS",keyCap:"s"},84:{code:"KeyT",keyCap:"t"},85:{code:"KeyU",keyCap:"u"},86:{code:"KeyV",keyCap:"v"},87:{code:"KeyW",keyCap:"w"},88:{code:"KeyX",keyCap:"x"},89:{code:"KeyY",keyCap:"y"},90:{code:"KeyZ",keyCap:"z"},91:{code:"OSLeft",location:r},92:{code:"OSRight",location:a},93:{code:"ContextMenu"},95:{code:"Standby"},96:{code:"Numpad0",keyCap:"0",location: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:r},161:{code:"ShiftRight",location:a},162:{code:"ControlLeft",location:r},163:{code:"ControlRight",location:a},164:{code:"AltLeft",location:r},165:{code:"AltRight",location:a},166:{code:"BrowserBack"},167:{code:"BrowserForward"},168:{code:"BrowserRefresh"},169:{code:"BrowserStop"},170:{code:"BrowserSearch"},171:{code:"BrowserFavorites"},172:{code:"BrowserHome"},173:{code:"VolumeMute"},174:{code:"VolumeDown"},175:{code:"VolumeUp"},176:{code:"MediaTrackNext"},177:{code:"MediaTrackPrevious"},178:{code:"MediaStop"},179:{code:"MediaPlayPause"},180:{code:"LaunchMail"},181:{code:"MediaSelect"},182:{code:"LaunchApp1"},183:{code:"LaunchApp2"},186:{code:"Semicolon",keyCap:";"},187:{code:"Equal",keyCap:"="},188:{code:"Comma",keyCap:","},189:{code:"Minus",keyCap:"-"},190:{code:"Period",keyCap:"."},191:{code:"Slash",keyCap:"/"},192:{code:"Backquote",keyCap:"`"},219:{code:"BracketLeft",keyCap:"["},220:{code:"Backslash",keyCap:"\\"},221:{code:"BracketRight",keyCap:"]"},222:{code:"Quote",keyCap:"'"},226:{code:"IntlBackslash",keyCap:"\\"},229:{code:"Process"},246:{code:"Attn"},247:{code:"CrSel"},248:{code:"ExSel"},249:{code:"EraseEof"},250:{code:"Play"},251:{code:"ZoomToggle"},254:{code:"Clear"}};i(p,"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(p,"moz-mac",{12:{code:"NumLock",location:l},173:{code:"Minus",keyCap:"-"}}),i(p,"moz-win",{173:{code:"Minus",keyCap:"-"}}),i(p,"chrome-mac",{93:{code:"OSRight",location:a}}),i(p,"safari",{3:{code:"Enter"},25:{code:"Tab"}}),i(p,"ios",{10:{code:"Enter",location:s}}),i(p,"safari-mac",{91:{code:"OSLeft",location:r},93:{code:"OSRight",location:a},229:{code:"KeyQ",keyCap:"Q"}});var d={};"cros"===h&&(d["U+00A0"]={code:"ShiftLeft",location:r},d["U+00A1"]={code:"ShiftRight",location:a},d["U+00A2"]={code:"ControlLeft",location:r},d["U+00A3"]={code:"ControlRight",location:a},d["U+00A4"]={code:"AltLeft",location:r},d["U+00A5"]={code:"AltRight",location:a}),"chrome-mac"===u&&(d["U+0010"]={code:"ContextMenu"}),"safari-mac"===u&&(d["U+0010"]={code:"ContextMenu"}),"ios"===h&&(d["U+0010"]={code:"Function"},d["U+001C"]={code:"ArrowLeft"},d["U+001D"]={code:"ArrowRight"},d["U+001E"]={code:"ArrowUp"},d["U+001F"]={code:"ArrowDown"},d["U+0001"]={code:"Home"},d["U+0004"]={code:"End"},d["U+000B"]={code:"PageUp"},d["U+000C"]={code:"PageDown"});var f=[];f[r]={16:{code:"ShiftLeft",location:r},17:{code:"ControlLeft",location:r},18:{code:"AltLeft",location:r}},f[a]={16:{code:"ShiftRight",location:a},17:{code:"ControlRight",location:a},18:{code:"AltRight",location:a}},f[l]={13:{code:"NumpadEnter",location:l}},i(f[l],"moz",{109:{code:"NumpadSubtract",location:l},107:{code:"NumpadAdd",location:l}}),i(f[r],"moz-mac",{224:{code:"OSLeft",location:r}}),i(f[a],"moz-mac",{224:{code:"OSRight",location:a}}),i(f[a],"moz-win",{91:{code:"OSRight",location:a}}),i(f[a],"mac",{93:{code:"OSRight",location:a}}),i(f[l],"chrome-mac",{12:{code:"NumLock",location:l}}),i(f[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 v={ShiftLeft:{key:"Shift"},ShiftRight:{key:"Shift"},ControlLeft:{key:"Control"},ControlRight:{key:"Control"},AltLeft:{key:"Alt"},AltRight:{key:"Alt"},OSLeft:{key:"OS"},OSRight:{key:"OS"},NumpadEnter:{key:"Enter"},Space:{key:" "},Digit0:{key:"0",shiftKey:")"},Digit1:{key:"1",shiftKey:"!"},Digit2:{key:"2",shiftKey:"@"},Digit3:{key:"3",shiftKey:"#"},Digit4:{key:"4",shiftKey:"$"},Digit5:{key:"5",shiftKey:"%"},Digit6:{key:"6",shiftKey:"^"},Digit7:{key:"7",shiftKey:"&"},Digit8:{key:"8",shiftKey:"*"},Digit9:{key:"9",shiftKey:"("},KeyA:{key:"a",shiftKey:"A"},KeyB:{key:"b",shiftKey:"B"},KeyC:{key:"c",shiftKey:"C"},KeyD:{key:"d",shiftKey:"D"},KeyE:{key:"e",shiftKey:"E"},KeyF:{key:"f",shiftKey:"F"},KeyG:{key:"g",shiftKey:"G"},KeyH:{key:"h",shiftKey:"H"},KeyI:{key:"i",shiftKey:"I"},KeyJ:{key:"j",shiftKey:"J"},KeyK:{key:"k",shiftKey:"K"},KeyL:{key:"l",shiftKey:"L"},KeyM:{key:"m",shiftKey:"M"},KeyN:{key:"n",shiftKey:"N"},KeyO:{key:"o",shiftKey:"O"},KeyP:{key:"p",shiftKey:"P"},KeyQ:{key:"q",shiftKey:"Q"},KeyR:{key:"r",shiftKey:"R"},KeyS:{key:"s",shiftKey:"S"},KeyT:{key:"t",shiftKey:"T"},KeyU:{key:"u",shiftKey:"U"},KeyV:{key:"v",shiftKey:"V"},KeyW:{key:"w",shiftKey:"W"},KeyX:{key:"x",shiftKey:"X"},KeyY:{key:"y",shiftKey:"Y"},KeyZ:{key:"z",shiftKey:"Z"},Numpad0:{key:"0"},Numpad1:{key:"1"},Numpad2:{key:"2"},Numpad3:{key:"3"},Numpad4:{key:"4"},Numpad5:{key:"5"},Numpad6:{key:"6"},Numpad7:{key:"7"},Numpad8:{key:"8"},Numpad9:{key:"9"},NumpadMultiply:{key:"*"},NumpadAdd:{key:"+"},NumpadComma:{key:","},NumpadSubtract:{key:"-"},NumpadDecimal:{key:"."},NumpadDivide:{key:"/"},Semicolon:{key:";",shiftKey:":"},Equal:{key:"=",shiftKey:"+"},Comma:{key:",",shiftKey:"<"},Minus:{key:"-",shiftKey:"_"},Period:{key:".",shiftKey:">"},Slash:{key:"/",shiftKey:"?"},Backquote:{key:"`",shiftKey:"~"},BracketLeft:{key:"[",shiftKey:"{"},Backslash:{key:"\\",shiftKey:"|"},BracketRight:{key:"]",shiftKey:"}"},Quote:{key:"'",shiftKey:'"'},IntlBackslash:{key:"\\",shiftKey:"|"}};i(v,"mac",{OSLeft:{key:"Meta"},OSRight:{key:"Meta"}});var m={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"},y=function(t,e){var i={};return Object.keys(t).forEach(function(o){var n=t[o];e in n&&(i[n[e]]=n)}),i}(p,"code");try{var g=n&&"location"in new KeyboardEvent("")}catch(t){}"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=o(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 m.hasOwnProperty(t)?m[t]:t}})}t(KeyboardEvent.prototype,"key",{get:function(){var t=o(this);return t&&"key"in t?t.key:"Unidentified"}}),t(KeyboardEvent.prototype,"location",{get:function(){var t=o(this);return t&&"location"in t?t.location:s}}),t(KeyboardEvent.prototype,"locale",{get:function(){return""}})}(),"queryKeyCap"in t.KeyboardEvent||(t.KeyboardEvent.queryKeyCap=function(t,e){if(t=String(t),!y.hasOwnProperty(t))return"Undefined";if(e&&"en-us"!==String(e).toLowerCase())throw Error("Unsupported locale");var i=y[t];return i.keyCap||i.code||"Undefined"}),t.identifyKey=function(t){if(!("code"in t)){var e=o(t);t.code=e?e.code:"",t.key=e&&"key"in e?e.key:"Unidentified",t.location="location"in t?t.location:"keyLocation"in t?t.keyLocation:e&&"location"in e?e.location:s,t.locale=""}}}(window)},{}],11:[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":14,"./src/components/body/static-body":15,"./src/components/constraint":16,"./src/components/math":17,"./src/system/physics":21,cannon:23}],12:[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:w=new THREE.PlaneGeometry(10,10,4,4);n=new THREE.Object3D;var l=new THREE.Object3D,h=new THREE.Mesh(w,this.currentMaterial);h.scale.set(100,100,100),l.add(h),h.castShadow=!0,h.receiveShadow=!0,n.add(l);break;case o.Shape.types.BOX:var c=new THREE.BoxGeometry(2*s.halfExtents.x,2*s.halfExtents.y,2*s.halfExtents.z);n=new THREE.Mesh(c,this.currentMaterial);break;case o.Shape.types.CONVEXPOLYHEDRON:for(var u=new THREE.Geometry,p=0;p<s.vertices.length;p++){var d=s.vertices[p];u.vertices.push(new THREE.Vector3(d.x,d.y,d.z))}for(p=0;p<s.faces.length;p++)for(var f=s.faces[p],v=f[0],m=1;m<f.length-1;m++){var y=f[m],g=f[m+1];u.faces.push(new THREE.Face3(v,y,g))}u.computeBoundingSphere(),u.computeFaceNormals(),n=new THREE.Mesh(u,this.currentMaterial);break;case o.Shape.types.HEIGHTFIELD:for(var w=new THREE.Geometry,b=new o.Vec3,x=new o.Vec3,E=new o.Vec3,T=0;T<s.data.length-1;T++)for(var S=0;S<s.data[T].length-1;S++)for(var C=0;C<2;C++){s.getConvexTrianglePillar(T,S,0===C),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),w.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));p=w.vertices.length-3;w.faces.push(new THREE.Face3(p,p+1,p+2))}w.computeBoundingSphere(),w.computeFaceNormals(),n=new THREE.Mesh(w,this.currentMaterial);break;case o.Shape.types.TRIMESH:for(var w=new THREE.Geometry,b=new o.Vec3,x=new o.Vec3,E=new o.Vec3,p=0;p<s.indices.length/3;p++){s.getTriangleVertices(p,b,x,E),w.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));m=w.vertices.length-3;w.faces.push(new THREE.Face3(m,m+1,m+2))}w.computeBoundingSphere(),w.computeFaceNormals(),n=new THREE.Mesh(w,this.currentMaterial);break;default:throw"Visual type not recognized: "+s.type}if(n.receiveShadow=!0,n.castShadow=!0,n.children)for(p=0;p<n.children.length;p++)if(n.children[p].castShadow=!0,n.children[p].receiveShadow=!0,n.children[p])for(m=0;m<n.children[p].length;m++)n.children[p].children[m].castShadow=!0,n.children[p].children[m].receiveShadow=!0;var A=t.shapeOffsets[i],R=t.shapeOrientations[i];n.position.set(A.x,A.y,A.z),n.quaternion.set(R.x,R.y,R.z,R.w),e.add(n)}return e},e.exports=o.shape2mesh},{cannon:23}],13:[function(t,e,i){var o=t("cannon"),n=t("three-to-cannon");t("../../../lib/CANNON-shape2mesh"),e.exports={schema:{shape:{default:"auto",oneOf:["auto","box","cylinder","sphere","hull","none"]},cylinderAxis:{default:"y",oneOf:["x","y","z"]},sphereRadius:{default:NaN}},init:function(){this.system=this.el.sceneEl.systems.physics,this.el.sceneEl.hasLoaded?this.initBody():this.el.sceneEl.addEventListener("loaded",this.initBody.bind(this))},initBody:function(){var t,e=this.el,i=this.data,s=e.getAttribute("position");if(this.body=new o.Body({mass:i.mass||0,material:this.system.material,position:new o.Vec3(s.x,s.y,s.z),linearDamping:i.linearDamping,angularDamping:i.angularDamping}),this.el.object3D.updateMatrixWorld(!0),"none"!==i.shape){var r="auto"===i.shape?void 0:AFRAME.utils.extend({},this.data,{type:n.Type[i.shape.toUpperCase()]});if(!(t=n(this.el.object3D,r)))return void this.el.addEventListener("model-loaded",this.initBody.bind(this));this.body.addShape(t,t.offset,t.orientation),this.system.debug&&this.createWireframe(this.body,t)}var a=e.getAttribute("rotation");this.body.quaternion.setFromEuler(THREE.Math.degToRad(a.x),THREE.Math.degToRad(a.y),THREE.Math.degToRad(a.z),"XYZ").normalize(),this.el.body=this.body,this.body.el=this.el,this.isLoaded=!0,this.isPlaying&&this._play(),this.el.emit("body-loaded",{body:this.el.body})},play:function(){this.isLoaded&&this._play()},_play:function(){this.system.addBehavior(this,this.system.Phase.SIMULATE),this.system.addBody(this.body),this.wireframe&&this.el.sceneEl.object3D.add(this.wireframe),this.syncToPhysics()},pause:function(){this.isLoaded&&(this.system.removeBehavior(this,this.system.Phase.SIMULATE),this.system.removeBody(this.body),this.wireframe&&this.el.sceneEl.object3D.remove(this.wireframe))},remove:function(){this.pause(),delete this.body.el,delete this.body,delete this.el.body,delete this.wireframe},createWireframe:function(t,e){var i=e.offset,n=e.orientation,s=o.shape2mesh(t).children[0];this.wireframe=new THREE.LineSegments(new THREE.EdgesGeometry(s.geometry),new THREE.LineBasicMaterial({color:16711680})),i&&(this.wireframe.offset=i.clone()),n&&(n.inverse(n),this.wireframe.orientation=new THREE.Quaternion(n.x,n.y,n.z,n.w)),this.syncWireframe()},syncWireframe:function(){var t,e=this.wireframe;this.wireframe&&(e.quaternion.copy(this.body.quaternion),e.orientation&&e.quaternion.multiply(e.orientation),e.position.copy(this.body.position),e.offset&&(t=e.offset.clone().applyQuaternion(e.quaternion),e.position.add(t)),e.updateMatrix())},syncToPhysics:function(){var t=new THREE.Quaternion,e=new THREE.Vector3;return function(){var i=this.el,o=i.parentEl,n=this.body;n&&(i.components.velocity&&n.velocity.copy(i.getAttribute("velocity")),o.isScene?(n.quaternion.copy(i.object3D.quaternion),n.position.copy(i.object3D.position)):(i.object3D.getWorldQuaternion(t),n.quaternion.copy(t),i.object3D.getWorldPosition(e),n.position.copy(e)),this.wireframe&&this.syncWireframe())}}(),syncFromPhysics:function(){var t=new THREE.Vector3,e=new THREE.Quaternion,i=new THREE.Quaternion;return function(){var o=this.el,n=o.parentEl,s=this.body;s&&(n.isScene?(o.setAttribute("quaternion",s.quaternion),o.setAttribute("position",s.position)):(e.copy(s.quaternion),n.object3D.getWorldQuaternion(i),e.multiply(i.inverse()),o.setAttribute("quaternion",{x:e.x,y:e.y,z:e.z,w:e.w}),t.copy(s.position),n.object3D.worldToLocal(t),o.setAttribute("position",{x:t.x,y:t.y,z:t.z})),this.wireframe&&this.syncWireframe())}}()}},{"../../../lib/CANNON-shape2mesh":12,cannon:23,"three-to-cannon":84}],14:[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":13}],15:[function(t,e,i){var o=t("./body");e.exports=AFRAME.utils.extend({},o,{step:function(){this.syncToPhysics()}})},{"./body":13}],16:[function(t,e,i){var o=t("cannon");e.exports={dependencies:["dynamic-body"],multiple:!0,schema:{type:{default:"lock",oneOf:["coneTwist","distance","hinge","lock","pointToPoint"]},target:{type:"selector"},maxForce:{default:1e6,min:0},collideConnected:{default:!0},wakeUpBodies:{default:!0},distance:{default:0,min:0},pivot:{type:"vec3"},targetPivot:{type:"vec3"},axis:{type:"vec3",default:{x:0,y:0,z:1}},targetAxis:{type:"vec3",default:{x:0,y:0,z:1}}},init:function(){this.system=this.el.sceneEl.systems.physics,this.constraint=null},remove:function(){this.constraint&&(this.system.world.removeConstraint(this.constraint),this.constraint=null)},update:function(){var t=this.el,e=this.data;this.remove(),t.body&&e.target.body?(this.constraint=this.createConstraint(),this.system.world.addConstraint(this.constraint)):(t.body?e.target:t).addEventListener("body-loaded",this.update.bind(this,{}))},createConstraint:function(){var t,e=this.data,i=new o.Vec3(e.pivot.x,e.pivot.y,e.pivot.z),n=new o.Vec3(e.targetPivot.x,e.targetPivot.y,e.targetPivot.z),s=new o.Vec3(e.axis.x,e.axis.y,e.axis.z),r=new o.Vec3(e.targetAxis.x,e.targetAxis.y,e.targetAxis.z);switch(e.type){case"lock":t=new o.LockConstraint(this.el.body,e.target.body,{maxForce:e.maxForce});break;case"distance":t=new o.DistanceConstraint(this.el.body,e.target.body,e.distance,e.maxForce);break;case"hinge":t=new o.HingeConstraint(this.el.body,e.target.body,{pivotA:i,pivotB:n,axisA:s,axisB:r,maxForce:e.maxForce});break;case"coneTwist":t=new o.ConeTwistConstraint(this.el.body,e.target.body,{pivotA:i,pivotB:n,axisA:s,axisB:r,maxForce:e.maxForce});break;case"pointToPoint":t=new o.PointToPointConstraint(this.el.body,i,e.target.body,n,e.maxForce);break;default:throw new Error("[constraint] Unexpected type: "+e.type)}return t.collideConnected=e.collideConnected,t}}},{cannon:23}],17:[function(t,e,i){e.exports={velocity:t("./velocity"),quaternion:t("./quaternion"),registerAll:function(t){this._registered||((t=t||window.AFRAME).components.velocity||t.registerComponent("velocity",this.velocity),t.components.quaternion||t.registerComponent("quaternion",this.quaternion),this._registered=!0)}}},{"./quaternion":18,"./velocity":19}],18:[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)}}},{}],19:[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})}}}},{}],20:[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}}},{}],21:[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":20,cannon:23}],22:[function(t,e,i){e.exports={_from:"github:donmccurdy/cannon.js#v0.6.2-dev1",_id:"cannon@0.6.2",_inBundle:!1,_integrity:"sha1-kuhwtr7Hd8jqU3mcndOx2tmf0RU=",_location:"/cannon",_phantomChildren:{},_requested:{type:"git",raw:"cannon@github:donmccurdy/cannon.js#v0.6.2-dev1",name:"cannon",escapedName:"cannon",rawSpec:"github:donmccurdy/cannon.js#v0.6.2-dev1",saveSpec:"github:donmccurdy/cannon.js#v0.6.2-dev1",fetchSpec:null,gitCommittish:"v0.6.2-dev1"},_requiredBy:["/aframe-physics-system"],_resolved:"github:donmccurdy/cannon.js#022e8ba53fa83abf0ad8a0e4fd08623123838a17",_spec:"cannon@github:donmccurdy/cannon.js#v0.6.2-dev1",_where:"/Users/donmccurdy/Documents/Projects/aframe-extras/node_modules/aframe-physics-system",author:{name:"Stefan Hedman",email:"schteppe@gmail.com",url:"http://steffe.se"},bugs:{url:"https://github.com/schteppe/cannon.js/issues"},bundleDependencies:!1,dependencies:{},deprecated:!1,description:"A lightweight 3D physics engine written in JavaScript.",devDependencies:{browserify:"*",grunt:"~0.4.0","grunt-browserify":"^2.1.4","grunt-contrib-concat":"~0.1.3","grunt-contrib-jshint":"~0.1.1","grunt-contrib-nodeunit":"^0.4.1","grunt-contrib-uglify":"^0.5.1","grunt-contrib-yuidoc":"^0.5.2",jshint:"latest",nodeunit:"^0.9.0","uglify-js":"latest"},engines:{node:"*"},homepage:"https://github.com/schteppe/cannon.js",keywords:["cannon.js","cannon","physics","engine","3d"],licenses:[{type:"MIT"}],main:"./src/Cannon.js",name:"cannon",repository:{type:"git",url:"git+https://github.com/schteppe/cannon.js.git"},version:"0.6.2"}},{}],23:[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":22,"./collision/AABB":24,"./collision/ArrayCollisionMatrix":25,"./collision/Broadphase":26,"./collision/GridBroadphase":27,"./collision/NaiveBroadphase":28,"./collision/ObjectCollisionMatrix":29,"./collision/Ray":31,"./collision/RaycastResult":32,"./collision/SAPBroadphase":33,"./constraints/ConeTwistConstraint":34,"./constraints/Constraint":35,"./constraints/DistanceConstraint":36,"./constraints/HingeConstraint":37,"./constraints/LockConstraint":38,"./constraints/PointToPointConstraint":39,"./equations/ContactEquation":41,"./equations/Equation":42,"./equations/FrictionEquation":43,"./equations/RotationalEquation":44,"./equations/RotationalMotorEquation":45,"./material/ContactMaterial":46,"./material/Material":47,"./math/Mat3":49,"./math/Quaternion":50,"./math/Transform":51,"./math/Vec3":52,"./objects/Body":53,"./objects/RaycastVehicle":54,"./objects/RigidVehicle":55,"./objects/SPHSystem":56,"./objects/Spring":57,"./shapes/Box":59,"./shapes/ConvexPolyhedron":60,"./shapes/Cylinder":61,"./shapes/Heightfield":62,"./shapes/Particle":63,"./shapes/Plane":64,"./shapes/Shape":65,"./shapes/Sphere":66,"./shapes/Trimesh":67,"./solver/GSSolver":68,"./solver/Solver":69,"./solver/SplitSolver":70,"./utils/EventTarget":71,"./utils/Pool":73,"./utils/Vec3Pool":76,"./world/Narrowphase":77,"./world/World":78}],24:[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 l=1;l<t.length;l++){var h=t[l];a&&(a.vmult(h,s),h=s),h.x>r.x&&(r.x=h.x),h.x<n.x&&(n.x=h.x),h.y>r.y&&(r.y=h.y),h.y<n.y&&(n.y=h.y),h.z>r.z&&(r.z=h.z),h.z<n.z&&(n.z=h.z)}return e&&(e.vadd(n,n),e.vadd(r,r)),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 l=this.lowerBound,h=this.upperBound;t.copy(l),e.set(h.x,l.y,l.z),i.set(h.x,h.y,l.z),o.set(l.x,h.y,h.z),n.set(h.x,l.y,l.z),s.set(l.x,h.y,l.z),r.set(l.x,l.y,h.z),a.copy(h)};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],l=i[4],h=i[5],c=i[6],u=i[7];this.getCorners(o,n,s,a,l,h,c,u);for(var p=0;8!==p;p++){var d=i[p];t.pointToLocal(d,d)}return e.setFromPoints(i)},o.prototype.toWorldFrame=function(t,e){var i=r,o=i[0],n=i[1],s=i[2],a=i[3],l=i[4],h=i[5],c=i[6],u=i[7];this.getCorners(o,n,s,a,l,h,c,u);for(var p=0;8!==p;p++){var d=i[p];t.pointToWorld(d,d)}return e.setFromPoints(i)},o.prototype.overlapsRay=function(t){var e=1/t._direction.x,i=1/t._direction.y,o=1/t._direction.z,n=(this.lowerBound.x-t.from.x)*e,s=(this.upperBound.x-t.from.x)*e,r=(this.lowerBound.y-t.from.y)*i,a=(this.upperBound.y-t.from.y)*i,l=(this.lowerBound.z-t.from.z)*o,h=(this.upperBound.z-t.from.z)*o,c=Math.max(Math.max(Math.min(n,s),Math.min(r,a)),Math.min(l,h)),u=Math.min(Math.min(Math.max(n,s),Math.max(r,a)),Math.max(l,h));return!(u<0)&&!(c>u)}},{"../math/Vec3":52,"../utils/Utils":75}],25:[function(t,e,i){function o(){this.matrix=[]}e.exports=o,o.prototype.get=function(t,e){if(t=t.index,(e=e.index)>t){var i=e;e=t,t=i}return this.matrix[(t*(t+1)>>1)+e-1]},o.prototype.set=function(t,e,i){if(t=t.index,(e=e.index)>t){var o=e;e=t,t=o}this.matrix[(t*(t+1)>>1)+e-1]=i?1:0},o.prototype.reset=function(){for(var t=0,e=this.matrix.length;t!==e;t++)this.matrix[t]=0},o.prototype.setNumObjects=function(t){this.matrix.length=t*(t-1)>>1}},{}],26:[function(t,e,i){function o(){this.world=null,this.useBoundingBoxes=!1,this.dirty=!0}var n=t("../objects/Body"),s=t("../math/Vec3"),r=t("../math/Quaternion");t("../shapes/Shape"),t("../shapes/Plane");e.exports=o,o.prototype.collisionPairs=function(t,e,i){throw new Error("collisionPairs not implemented for this BroadPhase class!")},o.prototype.needBroadphaseCollision=function(t,e){return 0!=(t.collisionFilterGroup&e.collisionFilterMask)&&0!=(e.collisionFilterGroup&t.collisionFilterMask)&&(0==(t.type&n.STATIC)&&t.sleepState!==n.SLEEPING||0==(e.type&n.STATIC)&&e.sleepState!==n.SLEEPING)},o.prototype.intersectionTest=function(t,e,i,o){this.useBoundingBoxes?this.doBoundingBoxBroadphase(t,e,i,o):this.doBoundingSphereBroadphase(t,e,i,o)};var a=new s;new s,new r,new s;o.prototype.doBoundingSphereBroadphase=function(t,e,i,o){var n=a;e.position.vsub(t.position,n);var s=Math.pow(t.boundingRadius+e.boundingRadius,2);n.norm2()<s&&(i.push(t),o.push(e))},o.prototype.doBoundingBoxBroadphase=function(t,e,i,o){t.aabbNeedsUpdate&&t.computeAABB(),e.aabbNeedsUpdate&&e.computeAABB(),t.aabb.overlaps(e.aabb)&&(i.push(t),o.push(e))};var l={keys:[]},h=[],c=[];o.prototype.makePairsUnique=function(t,e){for(var i=l,o=h,n=c,s=t.length,r=0;r!==s;r++)o[r]=t[r],n[r]=e[r];t.length=0,e.length=0;for(r=0;r!==s;r++){var a=o[r].id,u=n[r].id;i[p=a<u?a+","+u:u+","+a]=r,i.keys.push(p)}for(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":50,"../math/Vec3":52,"../objects/Body":53,"../shapes/Plane":64,"../shapes/Shape":65}],27:[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 l=0;l<a;l++)this.bins[l]=[],this.binLengths[l]=0}e.exports=o;var n=t("./Broadphase"),s=t("../math/Vec3"),r=t("../shapes/Shape");(o.prototype=new n).constructor=o;var a=new s;new s;o.prototype.collisionPairs=function(t,e,i){function o(t,e,i,o,n,s,r){var a=(t-w)*E|0,l=(e-b)*T|0,h=(i-x)*S|0,m=_((o-w)*E),y=_((n-b)*T),g=_((s-x)*S);a<0?a=0:a>=c&&(a=c-1),l<0?l=0:l>=u&&(l=u-1),h<0?h=0:h>=p&&(h=p-1),m<0?m=0:m>=c&&(m=c-1),y<0?y=0:y>=u&&(y=u-1),g<0?g=0:g>=p&&(g=p-1),l*=f,h*=v,m*=d,y*=f,g*=v;for(var C=a*=d;C<=m;C+=d)for(var A=l;A<=y;A+=f)for(var R=h;R<=g;R+=v){var M=C+A+R;L[M][P[M]++]=r}}for(var n=t.numObjects(),s=t.bodies,l=this.aabbMax,h=this.aabbMin,c=this.nx,u=this.ny,p=this.nz,d=u*p,f=p,v=1,m=l.x,y=l.y,g=l.z,w=h.x,b=h.y,x=h.z,E=c/(m-w),T=u/(y-b),S=p/(g-x),C=(m-w)/c,A=(y-b)/u,R=(g-x)/p,M=.5*Math.sqrt(C*C+A*A+R*R),B=r.types,z=B.SPHERE,k=B.PLANE,L=(B.BOX,B.COMPOUND,B.CONVEXPOLYHEDRON,this.bins),P=this.binLengths,I=this.bins.length,N=0;N!==I;N++)P[N]=0;for(var _=Math.ceil,h=Math.min,l=Math.max,N=0;N!==n;N++){var F=(it=s[N]).shape;switch(F.type){case z:var V=it.position.x,q=it.position.y,D=it.position.z,O=F.radius;o(V-O,q-O,D-O,V+O,q+O,D+O,it);break;case k:F.worldNormalNeedsUpdate&&F.computeWorldNormal(it.quaternion);var H=F.worldNormal,j=w+.5*C-it.position.x,W=b+.5*A-it.position.y,U=x+.5*R-it.position.z,G=a;G.set(j,W,U);for(var K=0,X=0;K!==c;K++,X+=d,G.y=W,G.x+=C)for(var Y=0,Q=0;Y!==u;Y++,Q+=f,G.z=U,G.y+=A)for(var Z=0,J=0;Z!==p;Z++,J+=v,G.z+=R)if(G.dot(H)<M){var $=X+Q+J;L[$][P[$]++]=it}break;default:it.aabbNeedsUpdate&&it.computeAABB(),o(it.aabb.lowerBound.x,it.aabb.lowerBound.y,it.aabb.lowerBound.z,it.aabb.upperBound.x,it.aabb.upperBound.y,it.aabb.upperBound.z,it)}}for(N=0;N!==I;N++){var tt=P[N];if(tt>1)for(var et=L[N],K=0;K!==tt;K++)for(var it=et[K],Y=0;Y!==K;Y++){var ot=et[Y];this.needBroadphaseCollision(it,ot)&&this.intersectionTest(it,ot,e,i)}}this.makePairsUnique(e,i)}},{"../math/Vec3":52,"../shapes/Shape":65,"./Broadphase":26}],28:[function(t,e,i){function o(){n.apply(this)}e.exports=o;var n=t("./Broadphase"),s=t("./AABB");(o.prototype=new n).constructor=o,o.prototype.collisionPairs=function(t,e,i){var o,n,s,r,a=t.bodies,l=a.length;for(o=0;o!==l;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":24,"./Broadphase":26}],29:[function(t,e,i){function o(){this.matrix={}}e.exports=o,o.prototype.get=function(t,e){if(t=t.id,(e=e.id)>t){var i=e;e=t,t=i}return t+"-"+e in this.matrix},o.prototype.set=function(t,e,i){if(t=t.id,(e=e.id)>t){var o=e;e=t,t=o}i?this.matrix[t+"-"+e]=!0:delete this.matrix[t+"-"+e]},o.prototype.reset=function(){this.matrix={}},o.prototype.setNumObjects=function(t){}},{}],30:[function(t,e,i){function o(){this.current=[],this.previous=[]}function n(t,e){t.push((4294901760&e)>>16,65535&e)}e.exports=o,o.prototype.getKey=function(t,e){if(e<t){var i=e;e=t,t=i}return t<<16|e},o.prototype.set=function(t,e){for(var i=this.getKey(t,e),o=this.current,n=0;i>o[n];)n++;if(i!==o[n]){for(e=o.length-1;e>=n;e--)o[e+1]=o[e];o[n]=i}},o.prototype.tick=function(){var t=this.current;this.current=this.previous,this.previous=t,this.current.length=0},o.prototype.getDiff=function(t,e){for(var i=this.current,o=this.previous,s=i.length,r=o.length,a=0,l=0;l<s;l++){for(var h=i[l];h>o[a];)a++;h===o[a]||n(t,h)}a=0;for(l=0;l<r;l++){for(var c=o[l];c>i[a];)a++;i[a]===c||n(e,c)}}},{}],31:[function(t,e,i){function o(t,e){this.from=t?t.clone():new s,this.to=e?e.clone():new s,this._direction=new s,this.precision=1e-4,this.checkCollisionResponse=!0,this.skipBackfaces=!1,this.collisionFilterMask=-1,this.collisionFilterGroup=-1,this.mode=o.ANY,this.result=new l,this.hasHit=!1,this.callback=function(t){}}function n(t,e,i,o){o.vsub(e,F),i.vsub(e,d),t.vsub(e,f);var n,s,r=F.dot(F),a=F.dot(d),l=F.dot(f),h=d.dot(d),c=d.dot(f);return(n=h*l-a*c)>=0&&(s=r*c-a*l)>=0&&n+s<r*h-a*a}e.exports=o;var s=t("../math/Vec3"),r=t("../math/Quaternion"),a=t("../math/Transform"),l=(t("../shapes/ConvexPolyhedron"),t("../shapes/Box"),t("../collision/RaycastResult")),h=t("../shapes/Shape"),c=t("../collision/AABB");o.prototype.constructor=o,o.CLOSEST=1,o.ANY=2,o.ALL=4;var u=new c,p=[];o.prototype.intersectWorld=function(t,e){return this.mode=e.mode||o.ANY,this.result=e.result||new l,this.skipBackfaces=!!e.skipBackfaces,this.collisionFilterMask=void 0!==e.collisionFilterMask?e.collisionFilterMask:-1,this.collisionFilterGroup=void 0!==e.collisionFilterGroup?e.collisionFilterGroup:-1,e.from&&this.from.copy(e.from),e.to&&this.to.copy(e.to),this.callback=e.callback||function(){},this.hasHit=!1,this.result.reset(),this._updateDirection(),this.getAABB(u),p.length=0,t.broadphase.aabbQuery(t,u,p),this.intersectBodies(p),this.hasHit};var d=new s,f=new s;o.pointInTriangle=n;var v=new s,m=new r;o.prototype.intersectBody=function(t,e){e&&(this.result=e,this._updateDirection());var i=this.checkCollisionResponse;if((!i||t.collisionResponse)&&0!=(this.collisionFilterGroup&t.collisionFilterMask)&&0!=(t.collisionFilterGroup&this.collisionFilterMask))for(var o=v,n=m,s=0,r=t.shapes.length;s<r;s++){var a=t.shapes[s];if((!i||a.collisionResponse)&&(t.quaternion.mult(t.shapeOrientations[s],n),t.quaternion.vmult(t.shapeOffsets[s],o),o.vadd(t.position,o),this.intersectShape(a,n,o,t),this.result._shouldStop))break}},o.prototype.intersectBodies=function(t,e){e&&(this.result=e,this._updateDirection());for(var i=0,o=t.length;!this.result._shouldStop&&i<o;i++)this.intersectBody(t[i])},o.prototype._updateDirection=function(){this.to.vsub(this.from,this._direction),this._direction.normalize()},o.prototype.intersectShape=function(t,e,i,o){if(!(function(t,e,i){i.vsub(t,F);var o=F.dot(e);return e.mult(o,V),V.vadd(t,V),i.distanceTo(V)}(this.from,this._direction,i)>t.boundingSphereRadius)){var n=this[t.type];n&&n.call(this,t,e,i,o,t)}};new s,new s;var y=new s,g=new s,w=new s,b=new s;new s,new l;o.prototype.intersectBox=function(t,e,i,o,n){return this.intersectConvex(t.convexPolyhedronRepresentation,e,i,o,n)},o.prototype[h.types.BOX]=o.prototype.intersectBox,o.prototype.intersectPlane=function(t,e,i,o,n){var r=this.from,a=this.to,l=this._direction,h=new s(0,0,1);e.vmult(h,h);var c=new s;r.vsub(i,c);var u=c.dot(h);a.vsub(i,c);if(!(u*c.dot(h)>0||r.distanceTo(a)<u)){var p=h.dot(l);if(!(Math.abs(p)<this.precision)){var d=new s,f=new s,v=new s;r.vsub(i,d);var m=-h.dot(d)/p;l.scale(m,f),r.vadd(f,v),this.reportIntersection(h,v,n,o,-1)}}},o.prototype[h.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 x={faceList:[0]},E=new s,T=new o,S=[];o.prototype.intersectHeightfield=function(t,e,i,o,n){t.data,t.elementSize;var s=T;s.from.copy(this.from),s.to.copy(this.to),a.pointToLocalFrame(i,e,s.from,s.from),a.pointToLocalFrame(i,e,s.to,s.to),s._updateDirection();var r,l,h,u,p=S;r=l=0,h=u=t.data.length-1;var d=new c;s.getAABB(d),t.getIndexOfPosition(d.lowerBound.x,d.lowerBound.y,p,!0),r=Math.max(r,p[0]),l=Math.max(l,p[1]),t.getIndexOfPosition(d.upperBound.x,d.upperBound.y,p,!0),h=Math.min(h,p[0]+1),u=Math.min(u,p[1]+1);for(var f=r;f<h;f++)for(var v=l;v<u;v++){if(this.result._shouldStop)return;if(t.getAabbAtIndex(f,v,d),d.overlapsRay(s)){if(t.getConvexTrianglePillar(f,v,!1),a.pointToWorldFrame(i,e,t.pillarOffset,E),this.intersectConvex(t.pillarConvex,e,E,o,n,x),this.result._shouldStop)return;t.getConvexTrianglePillar(f,v,!0),a.pointToWorldFrame(i,e,t.pillarOffset,E),this.intersectConvex(t.pillarConvex,e,E,o,n,x)}}},o.prototype[h.types.HEIGHTFIELD]=o.prototype.intersectHeightfield;var C=new s,A=new s;o.prototype.intersectSphere=function(t,e,i,o,n){var s=this.from,r=this.to,a=t.radius,l=Math.pow(r.x-s.x,2)+Math.pow(r.y-s.y,2)+Math.pow(r.z-s.z,2),h=2*((r.x-s.x)*(s.x-i.x)+(r.y-s.y)*(s.y-i.y)+(r.z-s.z)*(s.z-i.z)),c=Math.pow(s.x-i.x,2)+Math.pow(s.y-i.y,2)+Math.pow(s.z-i.z,2)-Math.pow(a,2),u=Math.pow(h,2)-4*l*c,p=C,d=A;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 f=(-h-Math.sqrt(u))/(2*l),v=(-h+Math.sqrt(u))/(2*l);if(f>=0&&f<=1&&(s.lerp(r,f,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[h.types.SPHERE]=o.prototype.intersectSphere;var R=new s,M=(new s,new s,new s);o.prototype.intersectConvex=function(t,e,i,o,s,r){for(var a=R,l=M,h=r&&r.faceList||null,c=t.faces,u=t.vertices,p=t.faceNormals,d=this._direction,f=this.from,v=this.to,m=f.distanceTo(v),x=h?h.length:c.length,E=this.result,T=0;!E._shouldStop&&T<x;T++){var S=h?h[T]:T,C=c[S],A=p[S],B=e,z=i;l.copy(u[C[0]]),B.vmult(l,l),l.vadd(z,l),l.vsub(f,l),B.vmult(A,a);var k=d.dot(a);if(!(Math.abs(k)<this.precision)){var L=a.dot(l)/k;if(!(L<0)){d.mult(L,y),y.vadd(f,y),g.copy(u[C[0]]),B.vmult(g,g),z.vadd(g,g);for(var P=1;!E._shouldStop&&P<C.length-1;P++){w.copy(u[C[P]]),b.copy(u[C[P+1]]),B.vmult(w,w),B.vmult(b,b),z.vadd(w,w),z.vadd(b,b);var I=y.distanceTo(f);!n(y,g,w,b)&&!n(y,w,g,b)||I>m||this.reportIntersection(a,y,s,o,S)}}}}},o.prototype[h.types.CONVEXPOLYHEDRON]=o.prototype.intersectConvex;var B=new s,z=new s,k=new s,L=new s,P=new s,I=new s,N=(new c,[]),_=new a;o.prototype.intersectTrimesh=function(t,e,i,o,s,r){var l=B,h=N,c=_,u=M,p=z,d=k,f=L,v=I,m=P,x=(r&&r.faceList,t.indices),E=(t.vertices,t.faceNormals,this.from),T=this.to,S=this._direction;c.position.copy(i),c.quaternion.copy(e),a.vectorToLocalFrame(i,e,S,p),a.pointToLocalFrame(i,e,E,d),a.pointToLocalFrame(i,e,T,f),f.x*=t.scale.x,f.y*=t.scale.y,f.z*=t.scale.z,d.x*=t.scale.x,d.y*=t.scale.y,d.z*=t.scale.z,f.vsub(d,p),p.normalize();var C=d.distanceSquared(f);t.tree.rayQuery(this,c,h);for(var A=0,R=h.length;!this.result._shouldStop&&A!==R;A++){var F=h[A];t.getNormal(F,l),t.getVertex(x[3*F],g),g.vsub(d,u);var V=p.dot(l),q=l.dot(u)/V;if(!(q<0)){p.scale(q,y),y.vadd(d,y),t.getVertex(x[3*F+1],w),t.getVertex(x[3*F+2],b);var D=y.distanceSquared(d);!n(y,w,g,b)&&!n(y,g,w,b)||D>C||(a.vectorToWorldFrame(e,l,m),a.pointToWorldFrame(i,e,y,v),this.reportIntersection(m,v,s,o,F))}}h.length=0},o.prototype[h.types.TRIMESH]=o.prototype.intersectTrimesh,o.prototype.reportIntersection=function(t,e,i,n,s){var r=this.from,a=this.to,l=r.distanceTo(e),h=this.result;if(!(this.skipBackfaces&&t.dot(this._direction)>0))switch(h.hitFaceIndex=void 0!==s?s:-1,this.mode){case o.ALL:this.hasHit=!0,h.set(r,a,t,e,i,n,l),h.hasHit=!0,this.callback(h);break;case o.CLOSEST:(l<h.distance||!h.hasHit)&&(this.hasHit=!0,h.hasHit=!0,h.set(r,a,t,e,i,n,l));break;case o.ANY:this.hasHit=!0,h.hasHit=!0,h.set(r,a,t,e,i,n,l),h._shouldStop=!0}};var F=new s,V=new s},{"../collision/AABB":24,"../collision/RaycastResult":32,"../math/Quaternion":50,"../math/Transform":51,"../math/Vec3":52,"../shapes/Box":59,"../shapes/ConvexPolyhedron":60,"../shapes/Shape":65}],32:[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":52}],33:[function(t,e,i){function o(t){n.apply(this),this.axisList=[],this.world=null,this.axisIndex=0;var e=this.axisList;this._addBodyHandler=function(t){e.push(t.body)},this._removeBodyHandler=function(t){var i=e.indexOf(t.body);-1!==i&&e.splice(i,1)},t&&this.setWorld(t)}t("../shapes/Shape");var n=t("../collision/Broadphase");e.exports=o,(o.prototype=new n).setWorld=function(t){this.axisList.length=0;for(var e=0;e<t.bodies.length;e++)this.axisList.push(t.bodies[e]);t.removeEventListener("addBody",this._addBodyHandler),t.removeEventListener("removeBody",this._removeBodyHandler),t.addEventListener("addBody",this._addBodyHandler),t.addEventListener("removeBody",this._removeBodyHandler),this.world=t,this.dirty=!0},o.insertionSortX=function(t){for(var e=1,i=t.length;e<i;e++){for(var o=t[e],n=e-1;n>=0&&!(t[n].aabb.lowerBound.x<=o.aabb.lowerBound.x);n--)t[n+1]=t[n];t[n+1]=o}return t},o.insertionSortY=function(t){for(var e=1,i=t.length;e<i;e++){for(var o=t[e],n=e-1;n>=0&&!(t[n].aabb.lowerBound.y<=o.aabb.lowerBound.y);n--)t[n+1]=t[n];t[n+1]=o}return t},o.insertionSortZ=function(t){for(var e=1,i=t.length;e<i;e++){for(var o=t[e],n=e-1;n>=0&&!(t[n].aabb.lowerBound.z<=o.aabb.lowerBound.z);n--)t[n+1]=t[n];t[n+1]=o}return t},o.prototype.collisionPairs=function(t,e,i){var n,s,r=this.axisList,a=r.length,l=this.axisIndex;for(this.dirty&&(this.sortList(),this.dirty=!1),n=0;n!==a;n++){var h=r[n];for(s=n+1;s<a;s++){var c=r[s];if(this.needBroadphaseCollision(h,c)){if(!o.checkBounds(h,c,l))break;this.intersectionTest(h,c,e,i)}}}},o.prototype.sortList=function(){for(var t=this.axisList,e=this.axisIndex,i=t.length,n=0;n!==i;n++){var s=t[n];s.aabbNeedsUpdate&&s.computeAABB()}0===e?o.insertionSortX(t):1===e?o.insertionSortY(t):2===e&&o.insertionSortZ(t)},o.checkBounds=function(t,e,i){var o,n;0===i?(o=t.position.x,n=e.position.x):1===i?(o=t.position.y,n=e.position.y):2===i&&(o=t.position.z,n=e.position.z);var s=t.boundingRadius,r=e.boundingRadius;return n-r<o+s},o.prototype.autoDetectAxis=function(){for(var t=0,e=0,i=0,o=0,n=0,s=0,r=this.axisList,a=r.length,l=1/a,h=0;h!==a;h++){var c=r[h],u=c.position.x;t+=u,e+=u*u;var p=c.position.y;i+=p,o+=p*p;var d=c.position.z;n+=d,s+=d*d}var f=e-t*t*l,v=o-i*i*l,m=s-n*n*l;this.axisIndex=f>v?f>m?0:2:v>m?1:2},o.prototype.aabbQuery=function(t,e,i){i=i||[],this.dirty&&(this.sortList(),this.dirty=!1);var o=this.axisIndex,n="x";1===o&&(n="y"),2===o&&(n="z");for(var s=this.axisList,r=(e.lowerBound[n],e.upperBound[n],0);r<s.length;r++){var a=s[r];a.aabbNeedsUpdate&&a.computeAABB(),a.aabb.overlaps(e)&&i.push(a)}return i}},{"../collision/Broadphase":26,"../shapes/Shape":65}],34:[function(t,e,i){function o(t,e,i){var o=void 0!==(i=i||{}).maxForce?i.maxForce:1e6,l=i.pivotA?i.pivotA.clone():new a,h=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,l,e,h,o),this.collideConnected=!!i.collideConnected,this.angle=void 0!==i.angle?i.angle:0;var c=this.coneEquation=new s(t,e,i),u=this.twistEquation=new r(t,e,i);this.twistAngle=void 0!==i.twistAngle?i.twistAngle:0,c.maxForce=0,c.minForce=-o,u.maxForce=0,u.minForce=-o,this.equations.push(c,u)}e.exports=o;t("./Constraint");var n=t("./PointToPointConstraint"),s=t("../equations/ConeEquation"),r=t("../equations/RotationalEquation"),a=(t("../equations/ContactEquation"),t("../math/Vec3"));o.prototype=new n,o.constructor=o;new a,new a;o.prototype.update=function(){var t=this.bodyA,e=this.bodyB,i=this.coneEquation,o=this.twistEquation;n.prototype.update.call(this),t.vectorToWorldFrame(this.axisA,i.axisA),e.vectorToWorldFrame(this.axisB,i.axisB),this.axisA.tangents(o.axisA,o.axisA),t.vectorToWorldFrame(o.axisA,o.axisA),this.axisB.tangents(o.axisB,o.axisB),e.vectorToWorldFrame(o.axisB,o.axisB),i.angle=this.angle,o.maxAngle=this.twistAngle}},{"../equations/ConeEquation":40,"../equations/ContactEquation":41,"../equations/RotationalEquation":44,"../math/Vec3":52,"./Constraint":35,"./PointToPointConstraint":39}],35:[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":75}],36:[function(t,e,i){function o(t,e,i,o){n.call(this,t,e),void 0===i&&(i=t.position.distanceTo(e.position)),void 0===o&&(o=1e6),this.distance=i;var r=this.distanceEquation=new s(t,e);this.equations.push(r),r.minForce=-o,r.maxForce=o}e.exports=o;var n=t("./Constraint"),s=t("../equations/ContactEquation");(o.prototype=new n).update=function(){var t=this.bodyA,e=this.bodyB,i=this.distanceEquation,o=.5*this.distance,n=i.ni;e.position.vsub(t.position,n),n.normalize(),n.mult(o,i.ri),n.mult(-o,i.rj)}},{"../equations/ContactEquation":41,"./Constraint":35}],37:[function(t,e,i){function o(t,e,i){var o=void 0!==(i=i||{}).maxForce?i.maxForce:1e6,l=i.pivotA?i.pivotA.clone():new a,h=i.pivotB?i.pivotB.clone():new a;n.call(this,t,l,e,h,o);(this.axisA=i.axisA?i.axisA.clone():new a(1,0,0)).normalize();(this.axisB=i.axisB?i.axisB.clone():new a(1,0,0)).normalize();var c=this.rotationalEquation1=new s(t,e,i),u=this.rotationalEquation2=new s(t,e,i),p=this.motorEquation=new r(t,e,o);p.enabled=!1,this.equations.push(c,u,p)}e.exports=o;t("./Constraint");var n=t("./PointToPointConstraint"),s=t("../equations/RotationalEquation"),r=t("../equations/RotationalMotorEquation"),a=(t("../equations/ContactEquation"),t("../math/Vec3"));o.prototype=new n,o.constructor=o,o.prototype.enableMotor=function(){this.motorEquation.enabled=!0},o.prototype.disableMotor=function(){this.motorEquation.enabled=!1},o.prototype.setMotorSpeed=function(t){this.motorEquation.targetVelocity=t},o.prototype.setMotorMaxForce=function(t){this.motorEquation.maxForce=t,this.motorEquation.minForce=-t};var l=new a,h=new a;o.prototype.update=function(){var t=this.bodyA,e=this.bodyB,i=this.motorEquation,o=this.rotationalEquation1,s=this.rotationalEquation2,r=l,a=h,c=this.axisA,u=this.axisB;n.prototype.update.call(this),t.quaternion.vmult(c,r),e.quaternion.vmult(u,a),r.tangents(o.axisA,s.axisA),o.axisB.copy(a),s.axisB.copy(a),this.motorEquation.enabled&&(t.quaternion.vmult(this.axisA,i.axisA),e.quaternion.vmult(this.axisB,i.axisB))}},{"../equations/ContactEquation":41,"../equations/RotationalEquation":44,"../equations/RotationalMotorEquation":45,"../math/Vec3":52,"./Constraint":35,"./PointToPointConstraint":39}],38:[function(t,e,i){function o(t,e,i){var o=void 0!==(i=i||{}).maxForce?i.maxForce:1e6,a=new r,l=new r,h=new r;t.position.vadd(e.position,h),h.scale(.5,h),e.pointToLocalFrame(h,l),t.pointToLocalFrame(h,a),n.call(this,t,a,e,l,o),this.xA=t.vectorToLocalFrame(r.UNIT_X),this.xB=e.vectorToLocalFrame(r.UNIT_X),this.yA=t.vectorToLocalFrame(r.UNIT_Y),this.yB=e.vectorToLocalFrame(r.UNIT_Y),this.zA=t.vectorToLocalFrame(r.UNIT_Z),this.zB=e.vectorToLocalFrame(r.UNIT_Z);var c=this.rotationalEquation1=new s(t,e,i),u=this.rotationalEquation2=new s(t,e,i),p=this.rotationalEquation3=new s(t,e,i);this.equations.push(c,u,p)}e.exports=o;t("./Constraint");var n=t("./PointToPointConstraint"),s=t("../equations/RotationalEquation"),r=(t("../equations/RotationalMotorEquation"),t("../equations/ContactEquation"),t("../math/Vec3"));o.prototype=new n,o.constructor=o;new r,new r;o.prototype.update=function(){var t=this.bodyA,e=this.bodyB,i=(this.motorEquation,this.rotationalEquation1),o=this.rotationalEquation2,s=this.rotationalEquation3;n.prototype.update.call(this),t.vectorToWorldFrame(this.xA,i.axisA),e.vectorToWorldFrame(this.yB,i.axisB),t.vectorToWorldFrame(this.yA,o.axisA),e.vectorToWorldFrame(this.zB,o.axisB),t.vectorToWorldFrame(this.zA,s.axisA),e.vectorToWorldFrame(this.xB,s.axisB)}},{"../equations/ContactEquation":41,"../equations/RotationalEquation":44,"../equations/RotationalMotorEquation":45,"../math/Vec3":52,"./Constraint":35,"./PointToPointConstraint":39}],39:[function(t,e,i){function o(t,e,i,o,a){n.call(this,t,i),a=void 0!==a?a:1e6,this.pivotA=e?e.clone():new r,this.pivotB=o?o.clone():new r;var l=this.equationX=new s(t,i),h=this.equationY=new s(t,i),c=this.equationZ=new s(t,i);this.equations.push(l,h,c),l.minForce=h.minForce=c.minForce=-a,l.maxForce=h.maxForce=c.maxForce=a,l.ni.set(1,0,0),h.ni.set(0,1,0),c.ni.set(0,0,1)}e.exports=o;var n=t("./Constraint"),s=t("../equations/ContactEquation"),r=t("../math/Vec3");(o.prototype=new n).update=function(){var t=this.bodyA,e=this.bodyB,i=this.equationX,o=this.equationY,n=this.equationZ;t.quaternion.vmult(this.pivotA,i.ri),e.quaternion.vmult(this.pivotB,i.rj),o.ri.copy(i.ri),o.rj.copy(i.rj),n.ri.copy(i.ri),n.rj.copy(i.rj)}},{"../equations/ContactEquation":41,"../math/Vec3":52,"./Constraint":35}],40:[function(t,e,i){function o(t,e,i){var o=void 0!==(i=i||{}).maxForce?i.maxForce:1e6;s.call(this,t,e,-o,o),this.axisA=i.axisA?i.axisA.clone():new n(1,0,0),this.axisB=i.axisB?i.axisB.clone():new n(0,1,0),this.angle=void 0!==i.angle?i.angle:0}e.exports=o;var n=t("../math/Vec3"),s=(t("../math/Mat3"),t("./Equation"));(o.prototype=new s).constructor=o;var r=new n,a=new n;o.prototype.computeB=function(t){var e=this.a,i=this.b,o=this.axisA,n=this.axisB,s=r,l=a,h=this.jacobianElementA,c=this.jacobianElementB;o.cross(n,s),n.cross(o,l),h.rotational.copy(l),c.rotational.copy(s);return-(Math.cos(this.angle)-o.dot(n))*e-this.computeGW()*i-t*this.computeGiMf()}},{"../math/Mat3":49,"../math/Vec3":52,"./Equation":42}],41:[function(t,e,i){function o(t,e,i){i=void 0!==i?i:1e6,n.call(this,t,e,0,i),this.restitution=0,this.ri=new s,this.rj=new s,this.ni=new s}e.exports=o;var n=t("./Equation"),s=t("../math/Vec3");t("../math/Mat3");(o.prototype=new n).constructor=o;var r=new s,a=new s,l=new s;o.prototype.computeB=function(t){var e=this.a,i=this.b,o=this.bi,n=this.bj,s=this.ri,h=this.rj,c=r,u=a,p=o.velocity,d=o.angularVelocity,f=(o.force,o.torque,n.velocity),v=n.angularVelocity,m=(n.force,n.torque,l),y=this.jacobianElementA,g=this.jacobianElementB,w=this.ni;s.cross(w,c),h.cross(w,u),w.negate(y.spatial),c.negate(y.rotational),g.spatial.copy(w),g.rotational.copy(u),m.copy(n.position),m.vadd(h,m),m.vsub(o.position,m),m.vsub(s,m);var b=w.dot(m),x=this.restitution+1;return-b*e-(x*f.dot(w)-x*p.dot(w)+v.dot(u)-d.dot(c))*i-t*this.computeGiMf()};var h=new s,c=new s,u=new s,p=new s,d=new s;o.prototype.getImpactVelocityAlongNormal=function(){var t=h,e=c,i=u,o=p,n=d;return this.bi.position.vadd(this.ri,i),this.bj.position.vadd(this.rj,o),this.bi.getVelocityAtWorldPoint(i,t),this.bj.getVelocityAtWorldPoint(o,e),t.vsub(e,n),this.ni.dot(n)}},{"../math/Mat3":49,"../math/Vec3":52,"./Equation":42}],42:[function(t,e,i){function o(t,e,i,s){this.id=o.id++,this.minForce=void 0===i?-1e6:i,this.maxForce=void 0===s?1e6:s,this.bi=t,this.bj=e,this.a=0,this.b=0,this.eps=0,this.jacobianElementA=new n,this.jacobianElementB=new n,this.enabled=!0,this.multiplier=0,this.setSpookParams(1e7,4,1/60)}e.exports=o;var n=t("../math/JacobianElement"),s=t("../math/Vec3");o.prototype.constructor=o,o.id=0,o.prototype.setSpookParams=function(t,e,i){var o=e,n=t,s=i;this.a=4/(s*(1+4*o)),this.b=4*o/(1+4*o),this.eps=4/(s*s*n*(1+4*o))},o.prototype.computeB=function(t,e,i){var o=this.computeGW();return-this.computeGq()*t-o*e-this.computeGiMf()*i},o.prototype.computeGq=function(){var t=this.jacobianElementA,e=this.jacobianElementB,i=this.bi,o=this.bj,n=i.position,s=o.position;return t.spatial.dot(n)+e.spatial.dot(s)};new s;o.prototype.computeGW=function(){var t=this.jacobianElementA,e=this.jacobianElementB,i=this.bi,o=this.bj,n=i.velocity,s=o.velocity,r=i.angularVelocity,a=o.angularVelocity;return t.multiplyVectors(n,r)+e.multiplyVectors(s,a)},o.prototype.computeGWlambda=function(){var t=this.jacobianElementA,e=this.jacobianElementB,i=this.bi,o=this.bj,n=i.vlambda,s=o.vlambda,r=i.wlambda,a=o.wlambda;return t.multiplyVectors(n,r)+e.multiplyVectors(s,a)};var r=new s,a=new s,l=new s,h=new s;o.prototype.computeGiMf=function(){var t=this.jacobianElementA,e=this.jacobianElementB,i=this.bi,o=this.bj,n=i.force,s=i.torque,c=o.force,u=o.torque,p=i.invMassSolve,d=o.invMassSolve;return n.scale(p,r),c.scale(d,a),i.invInertiaWorldSolve.vmult(s,l),o.invInertiaWorldSolve.vmult(u,h),t.multiplyVectors(r,l)+e.multiplyVectors(a,h)};var c=new s;o.prototype.computeGiMGt=function(){var t=this.jacobianElementA,e=this.jacobianElementB,i=this.bi,o=this.bj,n=i.invMassSolve,s=o.invMassSolve,r=i.invInertiaWorldSolve,a=o.invInertiaWorldSolve,l=n+s;return r.vmult(t.rotational,c),l+=c.dot(t.rotational),a.vmult(e.rotational,c),l+=c.dot(e.rotational)};var u=new s;new s,new s,new s,new s,new s;o.prototype.addToWlambda=function(t){var e=this.jacobianElementA,i=this.jacobianElementB,o=this.bi,n=this.bj,s=u;o.vlambda.addScaledVector(o.invMassSolve*t,e.spatial,o.vlambda),n.vlambda.addScaledVector(n.invMassSolve*t,i.spatial,n.vlambda),o.invInertiaWorldSolve.vmult(e.rotational,s),o.wlambda.addScaledVector(t,s,o.wlambda),n.invInertiaWorldSolve.vmult(i.rotational,s),n.wlambda.addScaledVector(t,s,n.wlambda)},o.prototype.computeC=function(){return this.computeGiMGt()+this.eps}},{"../math/JacobianElement":48,"../math/Vec3":52}],43:[function(t,e,i){function o(t,e,i){n.call(this,t,e,-i,i),this.ri=new s,this.rj=new s,this.t=new s}e.exports=o;var n=t("./Equation"),s=t("../math/Vec3");t("../math/Mat3");(o.prototype=new n).constructor=o;var r=new s,a=new s;o.prototype.computeB=function(t){this.a;var e=this.b,i=(this.bi,this.bj,this.ri),o=this.rj,n=r,s=a,l=this.t;i.cross(l,n),o.cross(l,s);var h=this.jacobianElementA,c=this.jacobianElementB;l.negate(h.spatial),n.negate(h.rotational),c.spatial.copy(l),c.rotational.copy(s);return-this.computeGW()*e-t*this.computeGiMf()}},{"../math/Mat3":49,"../math/Vec3":52,"./Equation":42}],44:[function(t,e,i){function o(t,e,i){var o=void 0!==(i=i||{}).maxForce?i.maxForce:1e6;s.call(this,t,e,-o,o),this.axisA=i.axisA?i.axisA.clone():new n(1,0,0),this.axisB=i.axisB?i.axisB.clone():new n(0,1,0),this.maxAngle=Math.PI/2}e.exports=o;var n=t("../math/Vec3"),s=(t("../math/Mat3"),t("./Equation"));(o.prototype=new s).constructor=o;var r=new n,a=new n;o.prototype.computeB=function(t){var e=this.a,i=this.b,o=this.axisA,n=this.axisB,s=r,l=a,h=this.jacobianElementA,c=this.jacobianElementB;o.cross(n,s),n.cross(o,l),h.rotational.copy(l),c.rotational.copy(s);return-(Math.cos(this.maxAngle)-o.dot(n))*e-this.computeGW()*i-t*this.computeGiMf()}},{"../math/Mat3":49,"../math/Vec3":52,"./Equation":42}],45:[function(t,e,i){function o(t,e,i){i=void 0!==i?i:1e6,s.call(this,t,e,-i,i),this.axisA=new n,this.axisB=new n,this.targetVelocity=0}e.exports=o;var n=t("../math/Vec3"),s=(t("../math/Mat3"),t("./Equation"));(o.prototype=new s).constructor=o,o.prototype.computeB=function(t){this.a;var e=this.b,i=(this.bi,this.bj,this.axisA),o=this.axisB,n=this.jacobianElementA,s=this.jacobianElementB;n.rotational.copy(i),o.negate(s.rotational);return-(this.computeGW()-this.targetVelocity)*e-t*this.computeGiMf()}},{"../math/Mat3":49,"../math/Vec3":52,"./Equation":42}],46:[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":75}],47:[function(t,e,i){function o(t){var e="";"string"==typeof(t=t||{})?(e=t,t={}):"object"==typeof t&&(e=""),this.name=e,this.id=o.idCounter++,this.friction=void 0!==t.friction?t.friction:-1,this.restitution=void 0!==t.restitution?t.restitution:-1}e.exports=o,o.idCounter=0},{}],48:[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":52}],49:[function(t,e,i){function o(t){this.elements=t||[0,0,0,0,0,0,0,0,0]}e.exports=o;var n=t("./Vec3");o.prototype.identity=function(){var t=this.elements;t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=1,t[5]=0,t[6]=0,t[7]=0,t[8]=1},o.prototype.setZero=function(){var t=this.elements;t[0]=0,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=0,t[6]=0,t[7]=0,t[8]=0},o.prototype.setTrace=function(t){var e=this.elements;e[0]=t.x,e[4]=t.y,e[8]=t.z},o.prototype.getTrace=function(t){var t=t||new n,e=this.elements;t.x=e[0],t.y=e[4],t.z=e[8]},o.prototype.vmult=function(t,e){e=e||new n;var i=this.elements,o=t.x,s=t.y,r=t.z;return e.x=i[0]*o+i[1]*s+i[2]*r,e.y=i[3]*o+i[4]*s+i[5]*r,e.z=i[6]*o+i[7]*s+i[8]*r,e},o.prototype.smult=function(t){for(var e=0;e<this.elements.length;e++)this.elements[e]*=t},o.prototype.mmult=function(t,e){for(var i=e||new o,n=0;n<3;n++)for(var s=0;s<3;s++){for(var r=0,a=0;a<3;a++)r+=t.elements[n+3*a]*this.elements[a+3*s];i.elements[n+3*s]=r}return i},o.prototype.scale=function(t,e){e=e||new o;for(var i=this.elements,n=e.elements,s=0;3!==s;s++)n[3*s+0]=t.x*i[3*s+0],n[3*s+1]=t.y*i[3*s+1],n[3*s+2]=t.z*i[3*s+2];return e},o.prototype.solve=function(t,e){e=e||new n;for(var i=[],o=0;o<12;o++)i.push(0);var s;for(o=0;o<3;o++)for(s=0;s<3;s++)i[o+4*s]=this.elements[o+3*s];i[3]=t.x,i[7]=t.y,i[11]=t.z;var r,a,l=3,h=l;do{if(o=h-l,0===i[o+4*o])for(s=o+1;s<h;s++)if(0!==i[o+4*s]){r=4;do{i[(a=4-r)+4*o]+=i[a+4*s]}while(--r);break}if(0!==i[o+4*o])for(s=o+1;s<h;s++){var c=i[o+4*s]/i[o+4*o];r=4;do{i[(a=4-r)+4*s]=a<=o?0:i[a+4*s]-i[a+4*o]*c}while(--r)}}while(--l);if(e.z=i[11]/i[10],e.y=(i[7]-i[6]*e.z)/i[5],e.x=(i[3]-i[2]*e.z-i[1]*e.y)/i[0],isNaN(e.x)||isNaN(e.y)||isNaN(e.z)||e.x===1/0||e.y===1/0||e.z===1/0)throw"Could not solve equation! Got x=["+e.toString()+"], b=["+t.toString()+"], A=["+this.toString()+"]";return e},o.prototype.e=function(t,e,i){if(void 0===i)return this.elements[e+3*t];this.elements[e+3*t]=i},o.prototype.copy=function(t){for(var e=0;e<t.elements.length;e++)this.elements[e]=t.elements[e];return this},o.prototype.toString=function(){for(var t="",e=0;e<9;e++)t+=this.elements[e]+",";return t},o.prototype.reverse=function(t){t=t||new o;for(var e=[],i=0;i<18;i++)e.push(0);var n;for(i=0;i<3;i++)for(n=0;n<3;n++)e[i+6*n]=this.elements[i+3*n];e[3]=1,e[9]=0,e[15]=0,e[4]=0,e[10]=1,e[16]=0,e[5]=0,e[11]=0,e[17]=1;var s,r,a=3,l=a;do{if(i=l-a,0===e[i+6*i])for(n=i+1;n<l;n++)if(0!==e[i+6*n]){s=6;do{e[(r=6-s)+6*i]+=e[r+6*n]}while(--s);break}if(0!==e[i+6*i])for(n=i+1;n<l;n++){h=e[i+6*n]/e[i+6*i];s=6;do{e[(r=6-s)+6*n]=r<=i?0:e[r+6*n]-e[r+6*i]*h}while(--s)}}while(--a);i=2;do{n=i-1;do{h=e[i+6*n]/e[i+6*i];s=6;do{e[(r=6-s)+6*n]=e[r+6*n]-e[r+6*i]*h}while(--s)}while(n--)}while(--i);i=2;do{var h=1/e[i+6*i];s=6;do{e[(r=6-s)+6*i]=e[r+6*i]*h}while(--s)}while(i--);i=2;do{n=2;do{if(r=e[3+n+6*i],isNaN(r)||r===1/0)throw"Could not reverse! A=["+this.toString()+"]";t.e(i,n,r)}while(n--)}while(i--);return t},o.prototype.setRotationFromQuaternion=function(t){var e=t.x,i=t.y,o=t.z,n=t.w,s=e+e,r=i+i,a=o+o,l=e*s,h=e*r,c=e*a,u=i*r,p=i*a,d=o*a,f=n*s,v=n*r,m=n*a,y=this.elements;return y[0]=1-(u+d),y[1]=h-m,y[2]=c+v,y[3]=h+m,y[4]=1-(l+d),y[5]=p-f,y[6]=c-v,y[7]=p+f,y[8]=1-(l+u),this},o.prototype.transpose=function(t){for(var e=(t=t||new o).elements,i=this.elements,n=0;3!==n;n++)for(var s=0;3!==s;s++)e[3*n+s]=i[3*s+n];return t}},{"./Vec3":52}],50:[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,l=t.y,h=t.z,c=t.w;return e.x=i*c+r*a+n*h-s*l,e.y=n*c+r*l+s*a-i*h,e.z=s*c+r*h+i*l-n*a,e.w=r*c-i*a-n*l-s*h,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,l=this.z,h=this.w,c=h*i+a*s-l*o,u=h*o+l*i-r*s,p=h*s+r*o-a*i,d=-r*i-a*o-l*s;return e.x=c*h+d*-r+u*-l-p*-a,e.y=u*h+d*-a+p*-r-c*-l,e.z=p*h+d*-l+c*-a-u*-r,e},o.prototype.copy=function(t){return this.x=t.x,this.y=t.y,this.z=t.z,this.w=t.w,this},o.prototype.toEuler=function(t,e){e=e||"YZX";var i,o,n,s=this.x,r=this.y,a=this.z,l=this.w;switch(e){case"YZX":var h=s*r+a*l;if(h>.499&&(i=2*Math.atan2(s,l),o=Math.PI/2,n=0),h<-.499&&(i=-2*Math.atan2(s,l),o=-Math.PI/2,n=0),isNaN(i)){var c=s*s,u=r*r,p=a*a;i=Math.atan2(2*r*l-2*s*a,1-2*u-2*p),o=Math.asin(2*h),n=Math.atan2(2*s*l-2*r*a,1-2*c-2*p)}break;default:throw new Error("Euler order "+e+" not supported yet.")}t.y=i,t.z=o,t.x=n},o.prototype.setFromEuler=function(t,e,i,o){o=o||"XYZ";var n=Math.cos(t/2),s=Math.cos(e/2),r=Math.cos(i/2),a=Math.sin(t/2),l=Math.sin(e/2),h=Math.sin(i/2);return"XYZ"===o?(this.x=a*s*r+n*l*h,this.y=n*l*r-a*s*h,this.z=n*s*h+a*l*r,this.w=n*s*r-a*l*h):"YXZ"===o?(this.x=a*s*r+n*l*h,this.y=n*l*r-a*s*h,this.z=n*s*h-a*l*r,this.w=n*s*r+a*l*h):"ZXY"===o?(this.x=a*s*r-n*l*h,this.y=n*l*r+a*s*h,this.z=n*s*h+a*l*r,this.w=n*s*r-a*l*h):"ZYX"===o?(this.x=a*s*r-n*l*h,this.y=n*l*r+a*s*h,this.z=n*s*h-a*l*r,this.w=n*s*r+a*l*h):"YZX"===o?(this.x=a*s*r+n*l*h,this.y=n*l*r+a*s*h,this.z=n*s*h-a*l*r,this.w=n*s*r-a*l*h):"XZY"===o&&(this.x=a*s*r-n*l*h,this.y=n*l*r-a*s*h,this.z=n*s*h+a*l*r,this.w=n*s*r+a*l*h),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,l,h=this.x,c=this.y,u=this.z,p=this.w,d=t.x,f=t.y,v=t.z,m=t.w;return(s=h*d+c*f+u*v+p*m)<0&&(s=-s,d=-d,f=-f,v=-v,m=-m),1-s>1e-6?(n=Math.acos(s),r=Math.sin(n),a=Math.sin((1-e)*n)/r,l=Math.sin(e*n)/r):(a=1-e,l=e),i.x=a*h+l*d,i.y=a*c+l*f,i.z=a*u+l*v,i.w=a*p+l*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,l=this.x,h=this.y,c=this.z,u=this.w,p=.5*e;return n.x+=p*(s*u+r*c-a*h),n.y+=p*(r*u+a*l-s*c),n.z+=p*(a*u+s*h-r*l),n.w+=p*(-s*l-r*h-a*c),n}},{"./Vec3":52}],51:[function(t,e,i){function o(t){t=t||{},this.position=new n,t.position&&this.position.copy(t.position),this.quaternion=new s,t.quaternion&&this.quaternion.copy(t.quaternion)}var n=t("./Vec3"),s=t("./Quaternion");e.exports=o;var r=new s;o.pointToLocalFrame=function(t,e,i,o){o=o||new n;return i.vsub(t,o),e.conjugate(r),r.vmult(o,o),o},o.prototype.pointToLocal=function(t,e){return o.pointToLocalFrame(this.position,this.quaternion,t,e)},o.pointToWorldFrame=function(t,e,i,o){o=o||new n;return e.vmult(i,o),o.vadd(t,o),o},o.prototype.pointToWorld=function(t,e){return o.pointToWorldFrame(this.position,this.quaternion,t,e)},o.prototype.vectorToWorldFrame=function(t,e){e=e||new n;return this.quaternion.vmult(t,e),e},o.vectorToWorldFrame=function(t,e,i){return t.vmult(e,i),i},o.vectorToLocalFrame=function(t,e,i,o){o=o||new n;return e.w*=-1,e.vmult(i,o),e.w*=-1,o}},{"./Quaternion":50,"./Vec3":52}],52:[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,l=this.z;return e=e||new o,e.x=a*s-l*n,e.y=l*i-r*s,e.z=r*n-a*i,e},o.prototype.set=function(t,e,i){return this.x=t,this.y=e,this.z=i,this},o.prototype.setZero=function(){this.x=this.y=this.z=0},o.prototype.vadd=function(t,e){if(!e)return new o(this.x+t.x,this.y+t.y,this.z+t.z);e.x=t.x+this.x,e.y=t.y+this.y,e.z=t.z+this.z},o.prototype.vsub=function(t,e){if(!e)return new o(this.x-t.x,this.y-t.y,this.z-t.z);e.x=this.x-t.x,e.y=this.y-t.y,e.z=this.z-t.z},o.prototype.crossmat=function(){return new n([0,-this.z,this.y,this.z,0,-this.x,-this.y,this.x,0])},o.prototype.normalize=function(){var t=this.x,e=this.y,i=this.z,o=Math.sqrt(t*t+e*e+i*i);if(o>0){var n=1/o;this.x*=n,this.y*=n,this.z*=n}else this.x=0,this.y=0,this.z=0;return o},o.prototype.unit=function(t){t=t||new o;var e=this.x,i=this.y,n=this.z,s=Math.sqrt(e*e+i*i+n*n);return s>0?(s=1/s,t.x=e*s,t.y=i*s,t.z=n*s):(t.x=1,t.y=0,t.z=0),t},o.prototype.norm=function(){var t=this.x,e=this.y,i=this.z;return Math.sqrt(t*t+e*e+i*i)},o.prototype.length=o.prototype.norm,o.prototype.norm2=function(){return this.dot(this)},o.prototype.lengthSquared=o.prototype.norm2,o.prototype.distanceTo=function(t){var e=this.x,i=this.y,o=this.z,n=t.x,s=t.y,r=t.z;return Math.sqrt((n-e)*(n-e)+(s-i)*(s-i)+(r-o)*(r-o))},o.prototype.distanceSquared=function(t){var e=this.x,i=this.y,o=this.z,n=t.x,s=t.y,r=t.z;return(n-e)*(n-e)+(s-i)*(s-i)+(r-o)*(r-o)},o.prototype.mult=function(t,e){e=e||new o;var i=this.x,n=this.y,s=this.z;return e.x=t*i,e.y=t*n,e.z=t*s,e},o.prototype.vmul=function(t,e){return e=e||new o,e.x=t.x*this.x,e.y=t.y*this.y,e.z=t.z*this.z,e},o.prototype.scale=o.prototype.mult,o.prototype.addScaledVector=function(t,e,i){return i=i||new o,i.x=this.x+t*e.x,i.y=this.y+t*e.y,i.z=this.z+t*e.z,i},o.prototype.dot=function(t){return this.x*t.x+this.y*t.y+this.z*t.z},o.prototype.isZero=function(){return 0===this.x&&0===this.y&&0===this.z},o.prototype.negate=function(t){return t=t||new o,t.x=-this.x,t.y=-this.y,t.z=-this.z,t};var s=new o,r=new o;o.prototype.tangents=function(t,e){var i=this.norm();if(i>0){var o=s,n=1/i;o.set(this.x*n,this.y*n,this.z*n);var a=r;Math.abs(o.x)<.9?(a.set(1,0,0),o.cross(a,t)):(a.set(0,1,0),o.cross(a,t)),o.cross(t,e)}else t.set(1,0,0),e.set(0,1,0)},o.prototype.toString=function(){return this.x+","+this.y+","+this.z},o.prototype.toArray=function(){return[this.x,this.y,this.z]},o.prototype.copy=function(t){return this.x=t.x,this.y=t.y,this.z=t.z,this},o.prototype.lerp=function(t,e,i){var o=this.x,n=this.y,s=this.z;i.x=o+(t.x-o)*e,i.y=n+(t.y-n)*e,i.z=s+(t.z-s)*e},o.prototype.almostEquals=function(t,e){return void 0===e&&(e=1e-6),!(Math.abs(this.x-t.x)>e||Math.abs(this.y-t.y)>e||Math.abs(this.z-t.z)>e)},o.prototype.almostZero=function(t){return void 0===t&&(t=1e-6),!(Math.abs(this.x)>t||Math.abs(this.y)>t||Math.abs(this.z)>t)};var a=new o;o.prototype.isAntiparallelTo=function(t,e){return this.negate(a),a.almostEquals(t,e)},o.prototype.clone=function(){return new o(this.x,this.y,this.z)}},{"./Mat3":49}],53:[function(t,e,i){function o(t){t=t||{},n.apply(this),this.id=o.idCounter++,this.world=null,this.preStep=null,this.postStep=null,this.vlambda=new s,this.collisionFilterGroup="number"==typeof t.collisionFilterGroup?t.collisionFilterGroup:1,this.collisionFilterMask="number"==typeof t.collisionFilterMask?t.collisionFilterMask:1,this.collisionResponse=!0,this.position=new s,this.previousPosition=new s,this.interpolatedPosition=new s,this.initPosition=new s,t.position&&(this.position.copy(t.position),this.previousPosition.copy(t.position),this.interpolatedPosition.copy(t.position),this.initPosition.copy(t.position)),this.velocity=new s,t.velocity&&this.velocity.copy(t.velocity),this.initVelocity=new s,this.force=new s;var e="number"==typeof t.mass?t.mass:0;this.mass=e,this.invMass=e>0?1/e:0,this.material=t.material||null,this.linearDamping="number"==typeof t.linearDamping?t.linearDamping:.01,this.type=e<=0?o.STATIC:o.DYNAMIC,typeof t.type==typeof o.STATIC&&(this.type=t.type),this.allowSleep=void 0===t.allowSleep||t.allowSleep,this.sleepState=0,this.sleepSpeedLimit=void 0!==t.sleepSpeedLimit?t.sleepSpeedLimit:.1,this.sleepTimeLimit=void 0!==t.sleepTimeLimit?t.sleepTimeLimit:1,this.timeLastSleepy=0,this._wakeUpAfterNarrowphase=!1,this.torque=new s,this.quaternion=new a,this.initQuaternion=new a,this.previousQuaternion=new a,this.interpolatedQuaternion=new a,t.quaternion&&(this.quaternion.copy(t.quaternion),this.initQuaternion.copy(t.quaternion),this.previousQuaternion.copy(t.quaternion),this.interpolatedQuaternion.copy(t.quaternion)),this.angularVelocity=new s,t.angularVelocity&&this.angularVelocity.copy(t.angularVelocity),this.initAngularVelocity=new s,this.shapes=[],this.shapeOffsets=[],this.shapeOrientations=[],this.inertia=new s,this.invInertia=new s,this.invInertiaWorld=new r,this.invMassSolve=0,this.invInertiaSolve=new s,this.invInertiaWorldSolve=new r,this.fixedRotation=void 0!==t.fixedRotation&&t.fixedRotation,this.angularDamping=void 0!==t.angularDamping?t.angularDamping:.01,this.linearFactor=new s(1,1,1),t.linearFactor&&this.linearFactor.copy(t.linearFactor),this.angularFactor=new s(1,1,1),t.angularFactor&&this.angularFactor.copy(t.angularFactor),this.aabb=new l,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"),l=(t("../material/Material"),t("../collision/AABB")),h=t("../shapes/Box");(o.prototype=new n).constructor=o,o.COLLIDE_EVENT_NAME="collide",o.DYNAMIC=1,o.STATIC=2,o.KINEMATIC=4,o.AWAKE=0,o.SLEEPY=1,o.SLEEPING=2,o.idCounter=0,o.wakeupEvent={type:"wakeup"},o.prototype.wakeUp=function(){var t=this.sleepState;this.sleepState=0,this._wakeUpAfterNarrowphase=!1,t===o.SLEEPING&&this.dispatchEvent(o.wakeupEvent)},o.prototype.sleep=function(){this.sleepState=o.SLEEPING,this.velocity.set(0,0,0),this.angularVelocity.set(0,0,0),this._wakeUpAfterNarrowphase=!1},o.sleepyEvent={type:"sleepy"},o.sleepEvent={type:"sleep"},o.prototype.sleepTick=function(t){if(this.allowSleep){var e=this.sleepState,i=this.velocity.norm2()+this.angularVelocity.norm2(),n=Math.pow(this.sleepSpeedLimit,2);e===o.AWAKE&&i<n?(this.sleepState=o.SLEEPY,this.timeLastSleepy=t,this.dispatchEvent(o.sleepyEvent)):e===o.SLEEPY&&i>n?this.wakeUp():e===o.SLEEPY&&t-this.timeLastSleepy>this.sleepTimeLimit&&(this.sleep(),this.dispatchEvent(o.sleepEvent))}},o.prototype.updateSolveMassProperties=function(){this.sleepState===o.SLEEPING||this.type===o.KINEMATIC?(this.invMassSolve=0,this.invInertiaSolve.setZero(),this.invInertiaWorldSolve.setZero()):(this.invMassSolve=this.invMass,this.invInertiaSolve.copy(this.invInertia),this.invInertiaWorldSolve.copy(this.invInertiaWorld))},o.prototype.pointToLocalFrame=function(t,e){e=e||new s;return t.vsub(this.position,e),this.quaternion.conjugate().vmult(e,e),e},o.prototype.vectorToLocalFrame=function(t,e){e=e||new s;return this.quaternion.conjugate().vmult(t,e),e},o.prototype.pointToWorldFrame=function(t,e){e=e||new s;return this.quaternion.vmult(t,e),e.vadd(this.position,e),e},o.prototype.vectorToWorldFrame=function(t,e){e=e||new s;return this.quaternion.vmult(t,e),e};var c=new s,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 l;o.prototype.computeAABB=function(){for(var t=this.shapes,e=this.shapeOffsets,i=this.shapeOrientations,o=t.length,n=c,s=u,r=this.quaternion,a=this.aabb,l=p,h=0;h!==o;h++){var d=t[h];r.vmult(e[h],n),n.vadd(this.position,n),i[h].mult(r,s),d.calculateWorldAABB(n,s,l.lowerBound,l.upperBound),0===h?a.copy(l):a.extend(l)}this.aabbNeedsUpdate=!1};var d=new r,f=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=f;i.setRotationFromQuaternion(this.quaternion),i.transpose(o),i.scale(e,i),i.mmult(o,this.invInertiaWorld)}else;};new s;var v=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,y=new s;o.prototype.applyLocalForce=function(t,e){if(this.type===o.DYNAMIC){var i=m,n=y;this.vectorToWorldFrame(t,i),this.vectorToWorldFrame(e,n),this.applyForce(i,n)}};new s;var g=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),h.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,l=this.torque,h=this.quaternion,c=this.invMass,u=this.invInertiaWorld,p=this.linearFactor,d=c*t;n.x+=a.x*d*p.x,n.y+=a.y*d*p.y,n.z+=a.z*d*p.z;var f=u.elements,v=this.angularFactor,m=l.x*v.x,y=l.y*v.y,g=l.z*v.z;s.x+=t*(f[0]*m+f[1]*y+f[2]*g),s.y+=t*(f[3]*m+f[4]*y+f[5]*g),s.z+=t*(f[6]*m+f[7]*y+f[8]*g),r.x+=n.x*t,r.y+=n.y*t,r.z+=n.z*t,h.integrate(this.angularVelocity,t,this.angularFactor,h),e&&(i?h.normalizeFast():h.normalize()),this.aabbNeedsUpdate=!0,this.updateInertiaWorld()}}},{"../collision/AABB":24,"../material/Material":47,"../math/Mat3":49,"../math/Quaternion":50,"../math/Vec3":52,"../shapes/Box":59,"../shapes/Shape":65,"../utils/EventTarget":71}],54:[function(t,e,i){function o(t){this.chassisBody=t.chassisBody,this.wheelInfos=[],this.sliding=!1,this.world=null,this.indexRightAxis=void 0!==t.indexRightAxis?t.indexRightAxis:1,this.indexForwardAxis=void 0!==t.indexForwardAxis?t.indexForwardAxis:0,this.indexUpAxis=void 0!==t.indexUpAxis?t.indexUpAxis:2}function n(t,e,i){var o=x,n=E,s=T,r=S;return e.vsub(t.position,o),o.cross(i,n),t.invInertiaWorld.vmult(n,r),r.cross(o,s),t.invMass+i.dot(s)}t("./Body");var s=t("../math/Vec3"),r=t("../math/Quaternion"),a=(t("../collision/RaycastResult"),t("../collision/Ray")),l=t("../objects/WheelInfo");e.exports=o;new s,new s,new s;var h=new s,c=new s,u=new s;new a;o.prototype.addWheel=function(t){var e=new l(t=t||{}),i=this.wheelInfos.length;return this.wheelInfos.push(e),i},o.prototype.setSteeringValue=function(t,e){this.wheelInfos[e].steering=t};new s;o.prototype.applyEngineForce=function(t,e){this.wheelInfos[e].engineForce=t},o.prototype.setBrake=function(t,e){this.wheelInfos[e].brake=t},o.prototype.addToWorld=function(t){this.constraints;t.addBody(this.chassisBody);var e=this;this.preStepCallback=function(){e.updateVehicle(t.dt)},t.addEventListener("preStep",this.preStepCallback),this.world=t},o.prototype.getVehicleAxisWorld=function(t,e){e.set(0===t?1:0,1===t?1:0,2===t?1:0),this.chassisBody.vectorToWorldFrame(e,e)},o.prototype.updateVehicle=function(t){for(var e=this.wheelInfos,i=e.length,o=this.chassisBody,n=0;n<i;n++)this.updateWheelTransform(n);this.currentVehicleSpeedKmHour=3.6*o.velocity.norm();var r=new s;this.getVehicleAxisWorld(this.indexForwardAxis,r),r.dot(o.velocity)<0&&(this.currentVehicleSpeedKmHour*=-1);for(n=0;n<i;n++)this.castRay(e[n]);this.updateSuspension(t);for(var a=new s,l=new s,n=0;n<i;n++){var h=(d=e[n]).suspensionForce;h>d.maxSuspensionForce&&(h=d.maxSuspensionForce),d.raycastResult.hitNormalWorld.scale(h*t,a),d.raycastResult.hitPointWorld.vsub(o.position,l),o.applyImpulse(a,l)}this.updateFriction(t);var c=new s,u=new s,p=new s;for(n=0;n<i;n++){var d=e[n];o.getVelocityAtWorldPoint(d.chassisConnectionPointWorld,p);var f=1;switch(this.indexUpAxis){case 1:f=-1}if(d.isInContact){this.getVehicleAxisWorld(this.indexForwardAxis,u);var v=u.dot(d.raycastResult.hitNormalWorld);d.raycastResult.hitNormalWorld.scale(v,c),u.vsub(c,u);var m=u.dot(p);d.deltaRotation=f*m*t/d.radius}!d.sliding&&d.isInContact||0===d.engineForce||!d.useCustomSlidingRotationalSpeed||(d.deltaRotation=(d.engineForce>0?1:-1)*d.customSlidingRotationalSpeed*t),Math.abs(d.brake)>Math.abs(d.engineForce)&&(d.deltaRotation=0),d.rotation+=d.deltaRotation,d.deltaRotation*=.99}},o.prototype.updateSuspension=function(t){for(var e=this.chassisBody.mass,i=this.wheelInfos,o=i.length,n=0;n<o;n++){var s=i[n];if(s.isInContact){var r,a=s.suspensionRestLength-s.suspensionLength;r=s.suspensionStiffness*a*s.clippedInvContactDotSuspension;var l=s.suspensionRelativeVelocity;r-=(l<0?s.dampingCompression:s.dampingRelaxation)*l,s.suspensionForce=r*e,s.suspensionForce<0&&(s.suspensionForce=0)}else s.suspensionForce=0}},o.prototype.removeFromWorld=function(t){this.constraints;t.remove(this.chassisBody),t.removeEventListener("preStep",this.preStepCallback),this.world=null};var p=new s,d=new s;o.prototype.castRay=function(t){var e=p,i=d;this.updateWheelTransformWorld(t);var o=this.chassisBody,n=-1,r=t.suspensionRestLength+t.radius;t.directionWorld.scale(r,e);var a=t.chassisConnectionPointWorld;a.vadd(e,i);var l=t.raycastResult;l.reset();var h=o.collisionResponse;o.collisionResponse=!1,this.world.rayTest(a,i,l),o.collisionResponse=h;var c=l.body;if(t.raycastResult.groundObject=0,c){n=l.distance,t.raycastResult.hitNormalWorld=l.hitNormalWorld,t.isInContact=!0;var u=l.distance;t.suspensionLength=u-t.radius;var f=t.suspensionRestLength-t.maxSuspensionTravel,v=t.suspensionRestLength+t.maxSuspensionTravel;t.suspensionLength<f&&(t.suspensionLength=f),t.suspensionLength>v&&(t.suspensionLength=v,t.raycastResult.reset());var m=t.raycastResult.hitNormalWorld.dot(t.directionWorld),y=new s;o.getVelocityAtWorldPoint(t.raycastResult.hitPointWorld,y);var g=t.raycastResult.hitNormalWorld.dot(y);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=h,i=c,o=u,n=this.wheelInfos[t];this.updateWheelTransformWorld(n),n.directionLocal.scale(-1,e),i.copy(n.axleLocal),e.cross(i,o),o.normalize(),i.normalize();var s=n.steering,a=new r;a.setFromAxisAngle(e,s);var l=new r;l.setFromAxisAngle(i,n.rotation);var p=n.worldTransform.quaternion;this.chassisBody.quaternion.mult(a,p),p.mult(l,p),p.normalize();var d=n.worldTransform.position;d.copy(n.directionWorld),d.scale(n.suspensionLength,d),d.vadd(n.chassisConnectionPointWorld,d)};var f=[new s(1,0,0),new s(0,1,0),new s(0,0,1)];o.prototype.getWheelTransformWorld=function(t){return this.wheelInfos[t].worldTransform};var v=new s,m=[],y=[];o.prototype.updateFriction=function(t){for(var e=v,i=this.wheelInfos,o=i.length,r=this.chassisBody,a=y,l=m,h=0;h<o;h++){(d=(L=i[h]).raycastResult.body)&&0,L.sideImpulse=0,L.forwardImpulse=0,a[h]||(a[h]=new s),l[h]||(l[h]=new s)}for(h=0;h<o;h++){if(d=(L=i[h]).raycastResult.body){var c=l[h];this.getWheelTransformWorld(h).vectorToWorldFrame(f[this.indexRightAxis],c);var u=L.raycastResult.hitNormalWorld,p=c.dot(u);u.scale(p,e),c.vsub(e,c),c.normalize(),u.cross(c,a[h]),a[h].normalize(),L.sideImpulse=function(t,e,i,o,n,s){if(n.norm2()>1.1)return 0;var r=C,a=A,l=R;return t.getVelocityAtWorldPoint(e,r),i.getVelocityAtWorldPoint(o,a),r.vsub(a,l),-.2*n.dot(l)*(1/(t.invMass+i.invMass))}(r,L.raycastResult.hitPointWorld,d,L.raycastResult.hitPointWorld,c),L.sideImpulse*=1}}this.sliding=!1;for(h=0;h<o;h++){var d=(L=i[h]).raycastResult.body,x=0;if(L.slipInfo=1,d){var E=L.brake?L.brake:0;x=function(t,e,i,o,s){var r=0,a=i,l=g,h=w,c=b;return t.getVelocityAtWorldPoint(a,l),e.getVelocityAtWorldPoint(a,h),l.vsub(h,c),r=-o.dot(c)*(1/(n(t,i,o)+n(e,i,o))),s<r&&(r=s),r<-s&&(r=-s),r}(r,d,L.raycastResult.hitPointWorld,a[h],E);k=E/(x+=L.engineForce*t);L.slipInfo*=k}if(L.forwardImpulse=0,L.skidInfo=1,d){L.skidInfo=1;var T=L.suspensionForce*t*L.frictionSlip,S=T*T;L.forwardImpulse=x;var M=.5*L.forwardImpulse,B=1*L.sideImpulse,z=M*M+B*B;if(L.sliding=!1,z>S){this.sliding=!0,L.sliding=!0;var k=T/Math.sqrt(z);L.skidInfo*=k}}}if(this.sliding)for(h=0;h<o;h++){0!==(L=i[h]).sideImpulse&&L.skidInfo<1&&(L.forwardImpulse*=L.skidInfo,L.sideImpulse*=L.skidInfo)}for(h=0;h<o;h++){var L=i[h],P=new s;if(L.raycastResult.hitPointWorld.vsub(r.position,P),0!==L.forwardImpulse){var I=new s;a[h].scale(L.forwardImpulse,I),r.applyImpulse(I,P)}if(0!==L.sideImpulse){var d=L.raycastResult.body,N=new s;L.raycastResult.hitPointWorld.vsub(d.position,N);var _=new s;l[h].scale(L.sideImpulse,_),r.vectorToLocalFrame(P,P),P["xyz"[this.indexUpAxis]]*=L.rollInfluence,r.vectorToWorldFrame(P,P),r.applyImpulse(_,P),_.scale(-1,_),d.applyImpulse(_,N)}}};var g=new s,w=new s,b=new s,x=new s,E=new s,T=new s,S=new s,C=new s,A=new s,R=new s},{"../collision/Ray":31,"../collision/RaycastResult":32,"../math/Quaternion":50,"../math/Vec3":52,"../objects/WheelInfo":58,"./Body":53}],55:[function(t,e,i){function o(t){if(this.wheelBodies=[],this.coordinateSystem=void 0===t.coordinateSystem?new a(1,2,3):t.coordinateSystem.clone(),this.chassisBody=t.chassisBody,!this.chassisBody){var e=new r(new a(5,2,.5));this.chassisBody=new n(1,e)}this.constraints=[],this.wheelAxes=[],this.wheelForces=[]}var n=t("./Body"),s=t("../shapes/Sphere"),r=t("../shapes/Box"),a=t("../math/Vec3"),l=t("../constraints/HingeConstraint");e.exports=o,o.prototype.addWheel=function(t){var e=(t=t||{}).body;e||(e=new n(1,new s(1.2))),this.wheelBodies.push(e),this.wheelForces.push(0);new a;var i=void 0!==t.position?t.position.clone():new a,o=new a;this.chassisBody.pointToWorldFrame(i,o),e.position.set(o.x,o.y,o.z);var r=void 0!==t.axis?t.axis.clone():new a(0,1,0);this.wheelAxes.push(r);var h=new l(this.chassisBody,e,{pivotA:i,axisA:r,pivotB:a.ZERO,axisB:r,collideConnected:!1});return this.constraints.push(h),this.wheelBodies.length-1},o.prototype.setSteeringValue=function(t,e){var i=this.wheelAxes[e],o=Math.cos(t),n=Math.sin(t),s=i.x,r=i.y;this.constraints[e].axisA.set(o*s-n*r,n*s+o*r,0)},o.prototype.setMotorSpeed=function(t,e){var i=this.constraints[e];i.enableMotor(),i.motorTargetVelocity=t},o.prototype.disableMotor=function(t){this.constraints[t].disableMotor()};var h=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,h),o.vectorToWorldFrame(h,h),n.vadd(h,n)},o.prototype.addToWorld=function(t){for(var e=this.constraints,i=this.wheelBodies.concat([this.chassisBody]),o=0;o<i.length;o++)t.addBody(i[o]);for(o=0;o<e.length;o++)t.addConstraint(e[o]);t.addEventListener("preStep",this._update.bind(this))},o.prototype._update=function(){for(var t=this.wheelForces,e=0;e<t.length;e++)this.applyWheelForce(t[e],e)},o.prototype.removeFromWorld=function(t){for(var e=this.constraints,i=this.wheelBodies.concat([this.chassisBody]),o=0;o<i.length;o++)t.remove(i[o]);for(o=0;o<e.length;o++)t.removeConstraint(e[o])};var c=new a;o.prototype.getWheelSpeed=function(t){var e=this.wheelAxes[t],i=this.wheelBodies[t].angularVelocity;return this.chassisBody.vectorToWorldFrame(e,c),i.dot(c)}},{"../constraints/HingeConstraint":37,"../math/Vec3":52,"../shapes/Box":59,"../shapes/Sphere":66,"./Body":53}],56:[function(t,e,i){function o(){this.particles=[],this.density=1,this.smoothingRadius=1,this.speedOfSound=1,this.viscosity=.01,this.eps=1e-6,this.pressures=[],this.densities=[],this.neighbors=[]}e.exports=o;t("../shapes/Shape");var n=t("../math/Vec3");t("../math/Quaternion"),t("../shapes/Particle"),t("../objects/Body"),t("../material/Material");o.prototype.add=function(t){this.particles.push(t),this.neighbors.length<this.particles.length&&this.neighbors.push([])},o.prototype.remove=function(t){var e=this.particles.indexOf(t);-1!==e&&(this.particles.splice(e,1),this.neighbors.length>this.particles.length&&this.neighbors.pop())};var s=new n;o.prototype.getNeighbors=function(t,e){for(var i=this.particles.length,o=t.id,n=this.smoothingRadius*this.smoothingRadius,r=s,a=0;a!==i;a++){var l=this.particles[a];l.position.vsub(t.position,r),o!==l.id&&r.norm2()<n&&e.push(l)}};var r=new n,a=new n,l=new n,h=new n,c=new n,u=new n;o.prototype.update=function(){for(var t=this.particles.length,e=r,i=this.speedOfSound,o=this.eps,n=0;n!==t;n++){var s=this.particles[n];(C=this.neighbors[n]).length=0,this.getNeighbors(s,C),C.push(this.particles[n]);for(var p=C.length,d=0,f=0;f!==p;f++){s.position.vsub(C[f].position,e);var v=e.norm(),m=this.w(v);d+=C[f].mass*m}this.densities[n]=d,this.pressures[n]=i*i*(this.densities[n]-this.density)}for(var y=a,g=l,w=h,b=c,x=u,n=0;n!==t;n++){var E=this.particles[n];y.set(0,0,0),g.set(0,0,0);for(var T,S,C=this.neighbors[n],p=C.length,f=0;f!==p;f++){var A=C[f];E.position.vsub(A.position,b);var R=b.norm();T=-A.mass*(this.pressures[n]/(this.densities[n]*this.densities[n]+o)+this.pressures[f]/(this.densities[f]*this.densities[f]+o)),this.gradw(b,w),w.mult(T,w),y.vadd(w,y),A.velocity.vsub(E.velocity,x),x.mult(1/(1e-4+this.densities[n]*this.densities[f])*this.viscosity*A.mass,x),S=this.nablaw(R),x.mult(S,x),g.vadd(x,g)}g.mult(E.mass,g),y.mult(E.mass,y),E.force.vadd(g,E.force),E.force.vadd(y,E.force)}},o.prototype.w=function(t){var e=this.smoothingRadius;return 315/(64*Math.PI*Math.pow(e,9))*Math.pow(e*e-t*t,3)},o.prototype.gradw=function(t,e){var i=t.norm(),o=this.smoothingRadius;t.mult(945/(32*Math.PI*Math.pow(o,9))*Math.pow(o*o-i*i,2),e)},o.prototype.nablaw=function(t){var e=this.smoothingRadius;return 945/(32*Math.PI*Math.pow(e,9))*(e*e-t*t)*(7*t*t-3*e*e)}},{"../material/Material":47,"../math/Quaternion":50,"../math/Vec3":52,"../objects/Body":53,"../shapes/Particle":63,"../shapes/Shape":65}],57:[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,l=new n,h=new n,c=new n,u=new n,p=new n,d=new n,f=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,y=r,g=a,w=l,b=v,x=h,E=c,T=u,S=p,C=d,A=f;this.getWorldAnchorA(x),this.getWorldAnchorB(E),x.vsub(o.position,T),E.vsub(n.position,S),E.vsub(x,m);var R=m.norm();y.copy(m),y.normalize(),n.velocity.vsub(o.velocity,g),n.angularVelocity.cross(S,b),g.vadd(b,g),o.angularVelocity.cross(T,b),g.vsub(b,g),y.mult(-t*(R-i)-e*g.dot(y),w),o.force.vsub(w,o.force),n.force.vadd(w,n.force),T.cross(w,C),S.cross(w,A),o.torque.vsub(C,o.torque),n.torque.vadd(A,n.torque)}},{"../math/Vec3":52}],58:[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 l=new n,h=new n,l=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,h),t.getVelocityAtWorldPoint(h,l);var o=e.hitNormalWorld.dot(l);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":32,"../math/Transform":51,"../math/Vec3":52,"../utils/Utils":75}],59:[function(t,e,i){function o(t){n.call(this),this.type=n.types.BOX,this.halfExtents=t,this.convexPolyhedronRepresentation=null,this.updateConvexPolyhedronRepresentation(),this.updateBoundingSphereRadius()}e.exports=o;var n=t("./Shape"),s=t("../math/Vec3"),r=t("./ConvexPolyhedron");(o.prototype=new n).constructor=o,o.prototype.updateConvexPolyhedronRepresentation=function(){var t=this.halfExtents.x,e=this.halfExtents.y,i=this.halfExtents.z,o=s,n=[new o(-t,-e,-i),new o(t,-e,-i),new o(t,e,-i),new o(-t,e,-i),new o(-t,-e,i),new o(t,-e,i),new o(t,e,i),new o(-t,e,i)],a=(new o(0,0,1),new o(0,1,0),new o(1,0,0),new r(n,[[3,2,1,0],[4,5,6,7],[5,4,0,1],[2,3,7,6],[0,4,7,3],[1,2,6,5]]));this.convexPolyhedronRepresentation=a,a.material=this.material},o.prototype.calculateLocalInertia=function(t,e){return e=e||new s,o.calculateInertia(this.halfExtents,t,e),e},o.calculateInertia=function(t,e,i){var o=t;i.x=1/12*e*(2*o.y*2*o.y+2*o.z*2*o.z),i.y=1/12*e*(2*o.x*2*o.x+2*o.z*2*o.z),i.z=1/12*e*(2*o.y*2*o.y+2*o.x*2*o.x)},o.prototype.getSideNormals=function(t,e){var i=t,o=this.halfExtents;if(i[0].set(o.x,0,0),i[1].set(0,o.y,0),i[2].set(0,0,o.z),i[3].set(-o.x,0,0),i[4].set(0,-o.y,0),i[5].set(0,0,-o.z),void 0!==e)for(var n=0;n!==i.length;n++)e.vmult(i[n],i[n]);return i},o.prototype.volume=function(){return 8*this.halfExtents.x*this.halfExtents.y*this.halfExtents.z},o.prototype.updateBoundingSphereRadius=function(){this.boundingSphereRadius=this.halfExtents.norm()};var a=new s;new s;o.prototype.forEachWorldCorner=function(t,e,i){for(var o=this.halfExtents,n=[[o.x,o.y,o.z],[-o.x,o.y,o.z],[-o.x,-o.y,o.z],[-o.x,-o.y,-o.z],[o.x,-o.y,-o.z],[o.x,o.y,-o.z],[-o.x,o.y,-o.z],[o.x,-o.y,o.z]],s=0;s<n.length;s++)a.set(n[s][0],n[s][1],n[s][2]),e.vmult(a,a),t.vadd(a,a),i(a.x,a.y,a.z)};var l=[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;l[0].set(n.x,n.y,n.z),l[1].set(-n.x,n.y,n.z),l[2].set(-n.x,-n.y,n.z),l[3].set(-n.x,-n.y,-n.z),l[4].set(n.x,-n.y,-n.z),l[5].set(n.x,n.y,-n.z),l[6].set(-n.x,n.y,-n.z),l[7].set(n.x,-n.y,n.z);r=l[0];e.vmult(r,r),t.vadd(r,r),o.copy(r),i.copy(r);for(var s=1;s<8;s++){var r=l[s];e.vmult(r,r),t.vadd(r,r);var a=r.x,h=r.y,c=r.z;a>o.x&&(o.x=a),h>o.y&&(o.y=h),c>o.z&&(o.z=c),a<i.x&&(i.x=a),h<i.y&&(i.y=h),c<i.z&&(i.z=c)}}},{"../math/Vec3":52,"./ConvexPolyhedron":60,"./Shape":65}],60:[function(t,e,i){function o(t,e,i){n.call(this),this.type=n.types.CONVEXPOLYHEDRON,this.vertices=t||[],this.worldVertices=[],this.worldVerticesNeedsUpdate=!0,this.faces=e||[],this.faceNormals=[],this.computeNormals(),this.worldFaceNormalsNeedsUpdate=!0,this.worldFaceNormals=[],this.uniqueEdges=[],this.uniqueAxes=i?i.slice():null,this.computeEdges(),this.updateBoundingSphereRadius()}e.exports=o;var n=t("./Shape"),s=t("../math/Vec3"),r=(t("../math/Quaternion"),t("../math/Transform"));(o.prototype=new n).constructor=o;var a=new s;o.prototype.computeEdges=function(){var t=this.faces,e=this.vertices,i=(e.length,this.uniqueEdges);i.length=0;for(var o=a,n=0;n!==t.length;n++)for(var s=t[n],r=s.length,l=0;l!==r;l++){var h=(l+1)%r;e[s[l]].vsub(e[s[h]],o),o.normalize();for(var c=!1,u=0;u!==i.length;u++)if(i[u].almostEquals(o)||i[u].almostEquals(o)){c=!0;break}c||i.push(o.clone())}},o.prototype.computeNormals=function(){this.faceNormals.length=this.faces.length;for(var t=0;t<this.faces.length;t++){for(o=0;o<this.faces[t].length;o++)if(!this.vertices[this.faces[t][o]])throw new Error("Vertex "+this.faces[t][o]+" not found!");var e=this.faceNormals[t]||new s;this.getFaceNormal(t,e),e.negate(e),this.faceNormals[t]=e;var i=this.vertices[this.faces[t][0]];if(e.dot(i)<0){console.error(".faceNormals["+t+"] = Vec3("+e.toString()+") looks like it points into the shape? The vertices follow. Make sure they are ordered CCW around the normal, using the right hand rule.");for(var o=0;o<this.faces[t].length;o++)console.warn(".vertices["+this.faces[t][o]+"] = Vec3("+this.vertices[this.faces[t][o]].toString()+")")}}};var l=new s,h=new s;o.computeNormal=function(t,e,i,o){e.vsub(t,h),i.vsub(e,l),l.cross(h,o),o.isZero()||o.normalize()},o.prototype.getFaceNormal=function(t,e){var i=this.faces[t],n=this.vertices[i[0]],s=this.vertices[i[1]],r=this.vertices[i[2]];return o.computeNormal(n,s,r,e)};var c=new s;o.prototype.clipAgainstHull=function(t,e,i,o,n,r,a,l,h){for(var u=c,p=-1,d=-Number.MAX_VALUE,f=0;f<i.faces.length;f++){u.copy(i.faceNormals[f]),n.vmult(u,u);var v=u.dot(r);v>d&&(d=v,p=f)}for(var m=[],y=i.faces[p],g=y.length,w=0;w<g;w++){var b=i.vertices[y[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,l,h)};var u=new s,p=new s,d=new s,f=new s,v=new s,m=new s;o.prototype.findSeparatingAxis=function(t,e,i,o,n,s,r,a){var l=u,h=p,c=d,y=f,g=v,w=m,b=Number.MAX_VALUE,x=this;if(x.uniqueAxes)for(T=0;T!==x.uniqueAxes.length;T++){i.vmult(x.uniqueAxes[T],l);if(!1===(A=x.testSepAxis(l,t,e,i,o,n)))return!1;A<b&&(b=A,s.copy(l))}else for(var E=r?r.length:x.faces.length,T=0;T<E;T++){C=r?r[T]:T;l.copy(x.faceNormals[C]),i.vmult(l,l);if(!1===(A=x.testSepAxis(l,t,e,i,o,n)))return!1;A<b&&(b=A,s.copy(l))}if(t.uniqueAxes)for(T=0;T!==t.uniqueAxes.length;T++){n.vmult(t.uniqueAxes[T],h),0;A=x.testSepAxis(h,t,e,i,o,n);if(!1===A)return!1;A<b&&(b=A,s.copy(h))}else for(var S=a?a.length:t.faces.length,T=0;T<S;T++){var C=a?a[T]:T;h.copy(t.faceNormals[C]),n.vmult(h,h),0;var A;if(!1===(A=x.testSepAxis(h,t,e,i,o,n)))return!1;A<b&&(b=A,s.copy(h))}for(var R=0;R!==x.uniqueEdges.length;R++){i.vmult(x.uniqueEdges[R],y);for(var M=0;M!==t.uniqueEdges.length;M++)if(n.vmult(t.uniqueEdges[M],g),y.cross(g,w),!w.almostZero()){w.normalize();var B=x.testSepAxis(w,t,e,i,o,n);if(!1===B)return!1;B<b&&(b=B,s.copy(w))}}return o.vsub(e,c),c.dot(s)>0&&s.negate(s),!0};var y=[],g=[];o.prototype.testSepAxis=function(t,e,i,n,s,r){o.project(this,t,i,n,y),o.project(e,t,s,r,g);var a=y[0],l=y[1],h=g[0],c=g[1];if(a<c||h<l)return!1;var u=a-c,p=h-l;return u<p?u:p};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]];return-i.dot(o)};var x=new s,E=new s,T=new s,S=new s,C=new s,A=new s,R=new s,M=new s;o.prototype.clipFaceAgainstHull=function(t,e,i,o,n,s,r){for(var a=x,l=E,h=T,c=S,u=C,p=A,d=R,f=M,v=this,m=o,y=[],g=-1,w=Number.MAX_VALUE,b=0;b<v.faces.length;b++){a.copy(v.faceNormals[b]),i.vmult(a,a);var B=a.dot(t);B<w&&(w=B,g=b)}if(!(g<0)){var z=v.faces[g];z.connectedFaces=[];for(q=0;q<v.faces.length;q++)for(var k=0;k<v.faces[q].length;k++)-1!==z.indexOf(v.faces[q][k])&&q!==g&&-1===z.connectedFaces.indexOf(q)&&z.connectedFaces.push(q);m.length;for(var L=z.length,P=0;P<L;P++){var I=v.vertices[z[P]],N=v.vertices[z[(P+1)%L]];I.vsub(N,l),h.copy(l),i.vmult(h,h),e.vadd(h,h),c.copy(this.faceNormals[g]),i.vmult(c,c),e.vadd(c,c),h.cross(c,u),u.negate(u),p.copy(I),i.vmult(p,p),e.vadd(p,p);p.dot(u);var _=z.connectedFaces[P];d.copy(this.faceNormals[_]);F=this.getPlaneConstantOfFace(_);f.copy(d),i.vmult(f,f);V=F-f.dot(e);for(this.clipFaceAgainstPlane(m,y,f,V);m.length;)m.shift();for(;y.length;)m.push(y.shift())}d.copy(this.faceNormals[g]);var F=this.getPlaneConstantOfFace(g);f.copy(d),i.vmult(f,f);for(var V=F-f.dot(e),q=0;q<m.length;q++){var D=f.dot(m[q])+V;if(D<=n&&(console.log("clamped: depth="+D+" to minDist="+n),D=n),D<=s){var O=m[q];if(D<=0){var H={point:O,normal:f,depth:D};r.push(H)}}}}},o.prototype.clipFaceAgainstPlane=function(t,e,i,o){var n,r,a=t.length;if(a<2)return e;var l=t[t.length-1],h=t[0];n=i.dot(l)+o;for(var c=0;c<a;c++){if(h=t[c],r=i.dot(h)+o,n<0)if(r<0){(u=new s).copy(h),e.push(u)}else{u=new s;l.lerp(h,n/(n-r),u),e.push(u)}else if(r<0){var u=new s;l.lerp(h,n/(n-r),u),e.push(u),e.push(h)}l=h,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 B=new s;o.prototype.calculateWorldAABB=function(t,e,i,o){for(var n,s,r,a,l,h,c=this.vertices.length,u=this.vertices,p=0;p<c;p++){B.copy(u[p]),e.vmult(B,B),t.vadd(B,B);var d=B;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>l||void 0===l)&&(l=d.y),d.z<r||void 0===r?r=d.z:(d.z>h||void 0===h)&&(h=d.z)}i.set(n,s,r),o.set(a,l,h)},o.prototype.volume=function(){return 4*Math.PI*this.boundingSphereRadius/3},o.prototype.getAveragePointLocal=function(t){t=t||new s;for(var e=this.vertices.length,i=this.vertices,o=0;o<e;o++)t.vadd(i[o],t);return t.mult(1/e,t),t},o.prototype.transformAllPoints=function(t,e){var i=this.vertices.length,o=this.vertices;if(e){for(n=0;n<i;n++){s=o[n];e.vmult(s,s)}for(n=0;n<this.faceNormals.length;n++){s=this.faceNormals[n];e.vmult(s,s)}}if(t)for(var n=0;n<i;n++){var s;(s=o[n]).vadd(t,s)}};var z=new s,k=new s,L=new s;o.prototype.pointIsInside=function(t){var e=this.vertices.length,i=this.vertices,o=this.faces,n=this.faceNormals,s=this.faces.length,r=z;this.getAveragePointLocal(r);for(var a=0;a<s;a++){this.faces[a].length;var e=n[a],l=i[o[a][0]],h=k;t.vsub(l,h);var c=e.dot(h),u=L;r.vsub(l,u);var p=e.dot(u);if(c<0&&p>0||c>0&&p<0)return!1}return-1};new s;var P=new s,I=new s;o.project=function(t,e,i,o,n){var s=t.vertices.length,a=P,l=0,h=0,c=I,u=t.vertices;c.setZero(),r.vectorToLocalFrame(i,o,e,a),r.pointToLocalFrame(i,o,c,c);var p=c.dot(a);h=l=u[0].dot(a);for(var d=1;d<s;d++){var f=u[d].dot(a);f>l&&(l=f),f<h&&(h=f)}if(h-=p,l-=p,h>l){var v=h;h=l,l=v}n[0]=l,n[1]=h}},{"../math/Quaternion":50,"../math/Transform":51,"../math/Vec3":52,"./Shape":65}],61:[function(t,e,i){function o(t,e,i,o){var a=o,l=[],h=[],c=[],u=[],p=[],d=Math.cos,f=Math.sin;l.push(new s(e*d(0),e*f(0),.5*-i)),u.push(0),l.push(new s(t*d(0),t*f(0),.5*i)),p.push(1);for(g=0;g<a;g++){var v=2*Math.PI/a*(g+1),m=2*Math.PI/a*(g+.5);g<a-1?(l.push(new s(e*d(v),e*f(v),.5*-i)),u.push(2*g+2),l.push(new s(t*d(v),t*f(v),.5*i)),p.push(2*g+3),c.push([2*g+2,2*g+3,2*g+1,2*g])):c.push([0,1,2*g+1,2*g]),(a%2==1||g<a/2)&&h.push(new s(d(m),f(m),0))}c.push(p),h.push(new s(0,0,1));for(var y=[],g=0;g<u.length;g++)y.push(u[u.length-g-1]);c.push(y),this.type=n.types.CONVEXPOLYHEDRON,r.call(this,l,c,h)}e.exports=o;var n=t("./Shape"),s=t("../math/Vec3"),r=(t("../math/Quaternion"),t("./ConvexPolyhedron"));o.prototype=new r},{"../math/Quaternion":50,"../math/Vec3":52,"./ConvexPolyhedron":60,"./Shape":65}],62:[function(t,e,i){function o(t,e){e=a.defaults(e,{maxValue:null,minValue:null,elementSize:1}),this.data=t,this.maxValue=e.maxValue,this.minValue=e.minValue,this.elementSize=e.elementSize,null===e.minValue&&this.updateMinValue(),null===e.maxValue&&this.updateMaxValue(),this.cacheEnabled=!0,n.call(this),this.pillarConvex=new s,this.pillarOffset=new r,this.type=n.types.HEIGHTFIELD,this.updateBoundingSphereRadius(),this._cachedPillars={}}var n=t("./Shape"),s=t("./ConvexPolyhedron"),r=t("../math/Vec3"),a=t("../utils/Utils");e.exports=o,(o.prototype=new n).update=function(){this._cachedPillars={}},o.prototype.updateMinValue=function(){for(var t=this.data,e=t[0][0],i=0;i!==t.length;i++)for(var o=0;o!==t[i].length;o++){var n=t[i][o];n<e&&(e=n)}this.minValue=e},o.prototype.updateMaxValue=function(){for(var t=this.data,e=t[0][0],i=0;i!==t.length;i++)for(var o=0;o!==t[i].length;o++){var n=t[i][o];n>e&&(e=n)}this.maxValue=e},o.prototype.setHeightValueAtIndex=function(t,e,i){this.data[t][e]=i,this.clearCachedConvexTrianglePillar(t,e,!1),t>0&&(this.clearCachedConvexTrianglePillar(t-1,e,!0),this.clearCachedConvexTrianglePillar(t-1,e,!1)),e>0&&(this.clearCachedConvexTrianglePillar(t,e-1,!0),this.clearCachedConvexTrianglePillar(t,e-1,!1)),e>0&&t>0&&this.clearCachedConvexTrianglePillar(t-1,e-1,!0)},o.prototype.getRectMinMax=function(t,e,i,o,n){n=n||[];for(var s=this.data,r=this.minValue,a=t;a<=i;a++)for(var l=e;l<=o;l++){var h=s[a][l];h>r&&(r=h)}n[0]=this.minValue,n[1]=r},o.prototype.getIndexOfPosition=function(t,e,i,o){var n=this.elementSize,s=this.data,r=Math.floor(t/n),a=Math.floor(e/n);return i[0]=r,i[1]=a,o&&(r<0&&(r=0),a<0&&(a=0),r>=s.length-1&&(r=s.length-1),a>=s[0].length-1&&(a=s[0].length-1)),!(r<0||a<0||r>=s.length-1||a>=s[0].length-1)};var l=[],h=new r,c=new r,u=new r,p=new r;o.prototype.getTriangleAt=function(t,e,i,o,n,s){var r=l;this.getIndexOfPosition(t,e,r,i);var a=r[0],h=r[1],c=this.data;i&&(a=Math.min(c.length-2,Math.max(0,a)),h=Math.min(c[0].length-2,Math.max(0,h)));var u=this.elementSize,p=Math.pow(t/u-a,2)+Math.pow(e/u-h,2)>Math.pow(t/u-(a+1),2)+Math.pow(e/u-(h+1),2);return this.getTriangle(a,h,p,o,n,s),p};var d=new r,f=new r,v=new r,m=new r,y=new r;o.prototype.getNormalAt=function(t,e,i,o){var n=d,s=f,r=v,a=m,l=y;this.getTriangleAt(t,e,i,n,s,r),s.vsub(n,a),r.vsub(n,l),a.cross(l,o),o.normalize()},o.prototype.getAabbAtIndex=function(t,e,i){var o=this.data,n=this.elementSize;i.lowerBound.set(t*n,e*n,o[t][e]),i.upperBound.set((t+1)*n,(e+1)*n,o[t+1][e+1])},o.prototype.getHeightAt=function(t,e,i){var o=this.data,n=c,s=u,r=p,a=l;this.getIndexOfPosition(t,e,a,i);var d=a[0],f=a[1];i&&(d=Math.min(o.length-2,Math.max(0,d)),f=Math.min(o[0].length-2,Math.max(0,f)));var v=this.getTriangleAt(t,e,i,n,s,r);!function(t,e,i,o,n,s,r,a,l){l.x=((s-a)*(t-r)+(r-n)*(e-a))/((s-a)*(i-r)+(r-n)*(o-a)),l.y=((a-o)*(t-r)+(i-r)*(e-a))/((s-a)*(i-r)+(r-n)*(o-a)),l.z=1-l.x-l.y}(t,e,n.x,n.y,s.x,s.y,r.x,r.y,h);var m=h;return v?o[d+1][f+1]*m.x+o[d][f+1]*m.y+o[d+1][f]*m.z:o[d][f]*m.x+o[d+1][f]*m.y+o[d][f+1]*m.z},o.prototype.getCacheConvexTrianglePillarKey=function(t,e,i){return t+"_"+e+"_"+(i?1:0)},o.prototype.getCachedConvexTrianglePillar=function(t,e,i){return this._cachedPillars[this.getCacheConvexTrianglePillarKey(t,e,i)]},o.prototype.setCachedConvexTrianglePillar=function(t,e,i,o,n){this._cachedPillars[this.getCacheConvexTrianglePillarKey(t,e,i)]={convex:o,offset:n}},o.prototype.clearCachedConvexTrianglePillar=function(t,e,i){delete this._cachedPillars[this.getCacheConvexTrianglePillarKey(t,e,i)]},o.prototype.getTriangle=function(t,e,i,o,n,s){var r=this.data,a=this.elementSize;i?(o.set((t+1)*a,(e+1)*a,r[t+1][e+1]),n.set(t*a,(e+1)*a,r[t][e+1]),s.set((t+1)*a,e*a,r[t+1][e])):(o.set(t*a,e*a,r[t][e]),n.set((t+1)*a,e*a,r[t+1][e]),s.set(t*a,(e+1)*a,r[t][e+1]))},o.prototype.getConvexTrianglePillar=function(t,e,i){var o=this.pillarConvex,n=this.pillarOffset;if(this.cacheEnabled){if(a=this.getCachedConvexTrianglePillar(t,e,i))return this.pillarConvex=a.convex,void(this.pillarOffset=a.offset);o=new s,n=new r,this.pillarConvex=o,this.pillarOffset=n}var a=this.data,l=this.elementSize,h=o.faces;o.vertices.length=6;for(c=0;c<6;c++)o.vertices[c]||(o.vertices[c]=new r);h.length=5;for(var c=0;c<5;c++)h[c]||(h[c]=[]);var u=o.vertices,p=(Math.min(a[t][e],a[t+1][e],a[t][e+1],a[t+1][e+1])-this.minValue)/2+this.minValue;i?(n.set((t+.75)*l,(e+.75)*l,p),u[0].set(.25*l,.25*l,a[t+1][e+1]-p),u[1].set(-.75*l,.25*l,a[t][e+1]-p),u[2].set(.25*l,-.75*l,a[t+1][e]-p),u[3].set(.25*l,.25*l,-p-1),u[4].set(-.75*l,.25*l,-p-1),u[5].set(.25*l,-.75*l,-p-1),h[0][0]=0,h[0][1]=1,h[0][2]=2,h[1][0]=5,h[1][1]=4,h[1][2]=3,h[2][0]=2,h[2][1]=5,h[2][2]=3,h[2][3]=0,h[3][0]=3,h[3][1]=4,h[3][2]=1,h[3][3]=0,h[4][0]=1,h[4][1]=4,h[4][2]=5,h[4][3]=2):(n.set((t+.25)*l,(e+.25)*l,p),u[0].set(-.25*l,-.25*l,a[t][e]-p),u[1].set(.75*l,-.25*l,a[t+1][e]-p),u[2].set(-.25*l,.75*l,a[t][e+1]-p),u[3].set(-.25*l,-.25*l,-p-1),u[4].set(.75*l,-.25*l,-p-1),u[5].set(-.25*l,.75*l,-p-1),h[0][0]=0,h[0][1]=1,h[0][2]=2,h[1][0]=5,h[1][1]=4,h[1][2]=3,h[2][0]=0,h[2][1]=2,h[2][2]=5,h[2][3]=3,h[3][0]=1,h[3][1]=0,h[3][2]=3,h[3][3]=4,h[4][0]=4,h[4][1]=5,h[4][2]=2,h[4][3]=1),o.computeNormals(),o.computeEdges(),o.updateBoundingSphereRadius(),this.setCachedConvexTrianglePillar(t,e,i,o,n)},o.prototype.calculateLocalInertia=function(t,e){return(e=e||new r).set(0,0,0),e},o.prototype.volume=function(){return Number.MAX_VALUE},o.prototype.calculateWorldAABB=function(t,e,i,o){i.set(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE),o.set(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE)},o.prototype.updateBoundingSphereRadius=function(){var t=this.data,e=this.elementSize;this.boundingSphereRadius=new r(t.length*e,t[0].length*e,Math.max(Math.abs(this.maxValue),Math.abs(this.minValue))).norm()},o.prototype.setHeightsFromImage=function(t,e){var i=document.createElement("canvas");i.width=t.width,i.height=t.height;var o=i.getContext("2d");o.drawImage(t,0,0);var n=o.getImageData(0,0,t.width,t.height),s=this.data;s.length=0,this.elementSize=Math.abs(e.x)/n.width;for(var r=0;r<n.height;r++){for(var a=[],l=0;l<n.width;l++){var h=(n.data[4*(r*n.height+l)]+n.data[4*(r*n.height+l)+1]+n.data[4*(r*n.height+l)+2])/4/255*e.z;e.x<0?a.push(h):a.unshift(h)}e.y<0?s.unshift(a):s.push(a)}this.updateMaxValue(),this.updateMinValue(),this.update()}},{"../math/Vec3":52,"../utils/Utils":75,"./ConvexPolyhedron":60,"./Shape":65}],63:[function(t,e,i){function o(){n.call(this),this.type=n.types.PARTICLE}e.exports=o;var n=t("./Shape"),s=t("../math/Vec3");(o.prototype=new n).constructor=o,o.prototype.calculateLocalInertia=function(t,e){return(e=e||new s).set(0,0,0),e},o.prototype.volume=function(){return 0},o.prototype.updateBoundingSphereRadius=function(){this.boundingSphereRadius=0},o.prototype.calculateWorldAABB=function(t,e,i,o){i.copy(t),o.copy(t)}},{"../math/Vec3":52,"./Shape":65}],64:[function(t,e,i){function o(){n.call(this),this.type=n.types.PLANE,this.worldNormal=new s,this.worldNormalNeedsUpdate=!0,this.boundingSphereRadius=Number.MAX_VALUE}e.exports=o;var n=t("./Shape"),s=t("../math/Vec3");(o.prototype=new n).constructor=o,o.prototype.computeWorldNormal=function(t){var e=this.worldNormal;e.set(0,0,1),t.vmult(e,e),this.worldNormalNeedsUpdate=!1},o.prototype.calculateLocalInertia=function(t,e){return e=e||new s},o.prototype.volume=function(){return Number.MAX_VALUE};var r=new s;o.prototype.calculateWorldAABB=function(t,e,i,o){r.set(0,0,1),e.vmult(r,r);var n=Number.MAX_VALUE;i.set(-n,-n,-n),o.set(n,n,n),1===r.x&&(o.x=t.x),1===r.y&&(o.y=t.y),1===r.z&&(o.z=t.z),-1===r.x&&(i.x=t.x),-1===r.y&&(i.y=t.y),-1===r.z&&(i.z=t.z)},o.prototype.updateBoundingSphereRadius=function(){this.boundingSphereRadius=Number.MAX_VALUE}},{"../math/Vec3":52,"./Shape":65}],65:[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":47,"../math/Quaternion":50,"../math/Vec3":52,"./Shape":65}],66:[function(t,e,i){function o(t){if(n.call(this),this.radius=void 0!==t?Number(t):1,this.type=n.types.SPHERE,this.radius<0)throw new Error("The sphere radius cannot be negative.");this.updateBoundingSphereRadius()}e.exports=o;var n=t("./Shape"),s=t("../math/Vec3");(o.prototype=new n).constructor=o,o.prototype.calculateLocalInertia=function(t,e){e=e||new s;var i=2*t*this.radius*this.radius/5;return e.x=i,e.y=i,e.z=i,e},o.prototype.volume=function(){return 4*Math.PI*this.radius/3},o.prototype.updateBoundingSphereRadius=function(){this.boundingSphereRadius=this.radius},o.prototype.calculateWorldAABB=function(t,e,i,o){for(var n=this.radius,s=["x","y","z"],r=0;r<s.length;r++){var a=s[r];i[a]=t[a]-n,o[a]=t[a]+n}}},{"../math/Vec3":52,"./Shape":65}],67:[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 l,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"),l=t("../utils/Octree");(o.prototype=new n).constructor=o;var h=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,l=[o,n,r],h=0;h<this.indices.length/3;h++){var c=3*h;this._getUnscaledVertex(this.indices[c],o),this._getUnscaledVertex(this.indices[c+1],n),this._getUnscaledVertex(this.indices[c+2],r),i.setFromPoints(l),t.insert(i,h)}t.removeEmptyNodes()};var c=new a;o.prototype.getTrianglesInAABB=function(t,e){c.copy(t);var i=this.scale,o=i.x,n=i.y,s=i.z,r=c.lowerBound,a=c.upperBound;return r.x/=o,r.y/=n,r.z/=s,a.x/=o,a.y/=n,a.z/=s,this.tree.aabbQuery(c,e)},o.prototype.setScale=function(t){var e=this.scale.x===this.scale.y===this.scale.z,i=t.x===t.y===t.z;e&&i||this.updateNormals(),this.scale.copy(t),this.updateAABB(),this.updateBoundingSphereRadius()},o.prototype.updateNormals=function(){for(var t=h,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,y),o.computeNormal(m,v,y,t),e[n]=t.x,e[n+1]=t.y,e[n+2]=t.z}},o.prototype.updateEdges=function(){for(var t={},e=function(e,i){t[n<s?n+"_"+s:s+"_"+n]=!0},i=0;i<this.indices.length/3;i++){var o=3*i,n=this.indices[o],s=this.indices[o+1];this.indices[o+2];e(),e(),e()}var r=Object.keys(t);this.edges=new Int16Array(2*r.length);for(i=0;i<r.length;i++){var a=r[i].split("_");this.edges[2*i]=parseInt(a[0],10),this.edges[2*i+1]=parseInt(a[1],10)}},o.prototype.getEdgeVertex=function(t,e,i){var o=this.edges[2*t+(e?1:0)];this.getVertex(o,i)};var 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,f=new s;o.computeNormal=function(t,e,i,o){e.vsub(t,f),i.vsub(e,d),d.cross(f,o),o.isZero()||o.normalize()};var v=new s,m=new s,y=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)};new s;var b=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=[],l=0;l<=i;l++)for(f=0;f<=n;f++){var h=f/n*s,c=l/i*Math.PI*2,u=(t+e*Math.cos(c))*Math.cos(h),p=(t+e*Math.cos(c))*Math.sin(h),d=e*Math.sin(c);r.push(u,p,d)}for(l=1;l<=i;l++)for(var f=1;f<=n;f++){var v=(n+1)*l+f-1,m=(n+1)*(l-1)+f-1,y=(n+1)*(l-1)+f,g=(n+1)*l+f;a.push(v,m,g),a.push(m,y,g)}return new o(r,a)}},{"../collision/AABB":24,"../math/Quaternion":50,"../math/Transform":51,"../math/Vec3":52,"../utils/Octree":72,"./Shape":65}],68:[function(t,e,i){function o(){n.call(this),this.iterations=10,this.tolerance=1e-7}e.exports=o;t("../math/Vec3"),t("../math/Quaternion");var n=t("./Solver"),s=[],r=[],a=[];(o.prototype=new n).solve=function(t,e){var i,o,n,l,h,c=0,u=this.iterations,p=this.tolerance*this.tolerance,d=this.equations,f=d.length,v=e.bodies,m=v.length,y=t;if(0!==f)for(C=0;C!==m;C++)v[C].updateSolveMassProperties();var g=r,w=a,b=s;g.length=f,w.length=f,b.length=f;for(C=0;C!==f;C++){S=d[C];b[C]=0,w[C]=S.computeB(y),g[C]=1/S.computeC()}if(0!==f){for(C=0;C!==m;C++){var x=(A=v[C]).vlambda,E=A.wlambda;x.set(0,0,0),E.set(0,0,0)}for(c=0;c!==u;c++){l=0;for(var T=0;T!==f;T++){var S=d[T];i=w[T],o=g[T],(h=b[T])+(n=o*(i-S.computeGWlambda()-S.eps*h))<S.minForce?n=S.minForce-h:h+n>S.maxForce&&(n=S.maxForce-h),b[T]+=n,l+=n>0?n:-n,S.addToWlambda(n)}if(l*l<p)break}for(var C=0;C!==m;C++){var A=v[C],R=A.velocity,M=A.angularVelocity;A.vlambda.vmul(A.linearFactor,A.vlambda),R.vadd(A.vlambda,R),A.wlambda.vmul(A.angularFactor,A.wlambda),M.vadd(A.wlambda,M)}for(var B=d.length,z=1/y;B--;)d[B].multiplier=b[B]*z}return c}},{"../math/Quaternion":50,"../math/Vec3":52,"./Solver":69}],69:[function(t,e,i){function o(){this.equations=[]}e.exports=o,o.prototype.solve=function(t,e){return 0},o.prototype.addEquation=function(t){t.enabled&&this.equations.push(t)},o.prototype.removeEquation=function(t){var e=this.equations,i=e.indexOf(t);-1!==i&&e.splice(i,1)},o.prototype.removeAllEquations=function(){this.equations.length=0}},{}],70:[function(t,e,i){function o(t){for(l.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(f.push(t),t.visited=!0,e(t,i,o);f.length;)for(var s,r=f.pop();s=n(r.children);)s.visited=!0,e(s,i,o),f.push(s)}function r(t,e,i){e.push(t.body);for(var o=t.eqs.length,n=0;n!==o;n++){var s=t.eqs[n];-1===i.indexOf(s)&&i.push(s)}}function a(t,e){return e.id-t.id}e.exports=o;t("../math/Vec3"),t("../math/Quaternion");var l=t("./Solver"),h=t("../objects/Body");o.prototype=new l;var c=[],u=[],p={bodies:[]},d=h.STATIC,f=[];o.prototype.createNode=function(){return{body:null,children:[],eqs:[],visited:!1}},o.prototype.solve=function(t,e){for(var i=c,o=this.nodePool,l=e.bodies,h=this.equations,d=h.length,f=l.length,v=this.subsolver;o.length<f;)o.push(this.createNode());i.length=f;for(w=0;w<f;w++)i[w]=o[w];for(w=0;w!==f;w++){var m=i[w];m.body=l[w],m.children.length=0,m.eqs.length=0,m.visited=!1}for(var y=0;y!==d;y++){var g=h[y],w=l.indexOf(g.bi),b=l.indexOf(g.bj),x=i[w],E=i[b];x.children.push(E),x.eqs.push(g),E.children.push(x),E.eqs.push(g)}var T,S=0,C=u;v.tolerance=this.tolerance,v.iterations=this.iterations;for(var A=p;T=n(i);){C.length=0,A.bodies.length=0,s(T,r,A.bodies,C);var R=C.length;C=C.sort(a);for(w=0;w!==R;w++)v.addEquation(C[w]);v.solve(t,A);v.removeAllEquations(),S++}return S}},{"../math/Quaternion":50,"../math/Vec3":52,"../objects/Body":53,"./Solver":69}],71:[function(t,e,i){var o=function(){};e.exports=o,o.prototype={constructor:o,addEventListener:function(t,e){void 0===this._listeners&&(this._listeners={});var i=this._listeners;return void 0===i[t]&&(i[t]=[]),-1===i[t].indexOf(e)&&i[t].push(e),this},hasEventListener:function(t,e){if(void 0===this._listeners)return!1;var i=this._listeners;return void 0!==i[t]&&-1!==i[t].indexOf(e)},hasAnyEventListener:function(t){if(void 0===this._listeners)return!1;return void 0!==this._listeners[t]},removeEventListener:function(t,e){if(void 0===this._listeners)return this;var i=this._listeners;if(void 0===i[t])return this;var o=i[t].indexOf(e);return-1!==o&&i[t].splice(o,1),this},dispatchEvent:function(t){if(void 0===this._listeners)return this;var e=this._listeners[t.type];if(void 0!==e){t.target=this;for(var i=0,o=e.length;i<o;i++)e[i].call(this,t)}return this}}},{}],72:[function(t,e,i){function o(t){t=t||{},this.root=t.root||null,this.aabb=t.aabb?t.aabb.clone():new s,this.data=[],this.children=[]}function n(t,e){(e=e||{}).root=null,e.aabb=t,o.call(this,e),this.maxDepth=void 0!==e.maxDepth?e.maxDepth:8}var s=t("../collision/AABB"),r=t("../math/Vec3");e.exports=n,n.prototype=new o,o.prototype.reset=function(t,e){this.children.length=this.data.length=0},o.prototype.insert=function(t,e,i){var o=this.data;if(i=i||0,!this.aabb.contains(t))return!1;var n=this.children;if(i<(this.maxDepth||this.root.maxDepth)){var s=!1;n.length||(this.subdivide(),s=!0);for(var r=0;8!==r;r++)if(n[r].insert(t,e,i+1))return!0;s&&(n.length=0)}return o.push(e),!0};var a=new r;o.prototype.subdivide=function(){var t=this.aabb,e=t.lowerBound,i=t.upperBound,n=this.children;n.push(new o({aabb:new s({lowerBound:new r(0,0,0)})}),new o({aabb:new s({lowerBound:new r(1,0,0)})}),new o({aabb:new s({lowerBound:new r(1,1,0)})}),new o({aabb:new s({lowerBound:new r(1,1,1)})}),new o({aabb:new s({lowerBound:new r(0,1,1)})}),new o({aabb:new s({lowerBound:new r(0,0,1)})}),new o({aabb:new s({lowerBound:new r(1,0,1)})}),new o({aabb:new s({lowerBound:new r(0,1,0)})})),i.vsub(e,a),a.scale(.5,a);for(var l=this.root||this,h=0;8!==h;h++){var c=n[h];c.root=l;var u=c.aabb.lowerBound;u.x*=a.x,u.y*=a.y,u.z*=a.z,u.vadd(e,u),u.vadd(a,c.aabb.upperBound)}},o.prototype.aabbQuery=function(t,e){this.data,this.children;for(var i=[this];i.length;){var o=i.pop();o.aabb.overlaps(t)&&Array.prototype.push.apply(e,o.data),Array.prototype.push.apply(i,o.children)}return e};var l=new s;o.prototype.rayQuery=function(t,e,i){return t.getAABB(l),l.toLocalFrame(e,l),this.aabbQuery(l,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":24,"../math/Vec3":52}],73:[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}},{}],74:[function(t,e,i){function o(){this.data={keys:[]}}e.exports=o,o.prototype.get=function(t,e){if(t>e){var i=e;e=t,t=i}return this.data[t+"-"+e]},o.prototype.set=function(t,e,i){if(t>e){var o=e;e=t,t=o}var n=t+"-"+e;this.get(t,e)||this.data.keys.push(n),this.data[n]=i},o.prototype.reset=function(){for(var t=this.data,e=t.keys;e.length>0;){delete t[e.pop()]}}},{}],75:[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}},{}],76:[function(t,e,i){function o(){s.call(this),this.type=n}e.exports=o;var n=t("../math/Vec3"),s=t("./Pool");(o.prototype=new s).constructObject=function(){return new n}},{"../math/Vec3":52,"./Pool":73}],77:[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=H;t[(s+1)%n].vsub(r,a);var l=j;a.cross(e,l);var h=W;i.vsub(r,h);var c=l.dot(h);if(!(null===o||c>0&&!0===o||c<=0&&!1===o))return!1;null===o&&(o=c>0)}return!0}e.exports=o;var s=t("../collision/AABB"),r=t("../objects/Body"),a=t("../shapes/Shape"),l=t("../collision/Ray"),h=t("../math/Vec3"),c=t("../math/Transform"),u=(t("../shapes/ConvexPolyhedron"),t("../math/Quaternion")),p=(t("../solver/Solver"),t("../utils/Vec3Pool")),d=t("../equations/ContactEquation"),f=t("../equations/FrictionEquation");o.prototype.createContactEquation=function(t,e,i,o,n,s){var r;this.contactPointPool.length?((r=this.contactPointPool.pop()).bi=t,r.bj=e):r=new d(t,e),r.enabled=t.collisionResponse&&e.collisionResponse&&i.collisionResponse&&o.collisionResponse;var a=this.currentContactMaterial;r.restitution=a.restitution,r.setSpookParams(a.contactEquationStiffness,a.contactEquationRelaxation,this.world.dt);var l=i.material||t.material,h=o.material||e.material;return l&&h&&l.restitution>=0&&h.restitution>=0&&(r.restitution=l.restitution*h.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,l=a.friction,h=n.material||i.material,c=s.material||o.material;if(h&&c&&h.friction>=0&&c.friction>=0&&(l=h.friction*c.friction),l>0){var u=l*r.gravity.length(),p=i.invMass+o.invMass;p>0&&(p=1/p);var d=this.frictionEquationPool,v=d.length?d.pop():new f(i,o,u*p),m=d.length?d.pop():new f(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 h,m=new h,y=new h;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(),y.setZero();for(var n=e.bi,s=(e.bj,0);s!==t;s++)(e=this.result[this.result.length-1-s]).bodyA!==n?(v.vadd(e.ni,v),m.vadd(e.ri,m),y.vadd(e.rj,y)):(v.vsub(e.ni,v),m.vadd(e.rj,m),y.vadd(e.ri,y));var r=1/t;m.scale(r,i.ri),y.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 h,w=new h,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 l=b,h=x,c=g,u=w,p=0,d=t.length;p!==d;p++){var f=t[p],v=e[p],m=null;f.material&&v.material&&(m=i.getContactMaterial(f.material,v.material)||null);for(var y=f.type&r.KINEMATIC&&v.type&r.STATIC||f.type&r.STATIC&&v.type&r.KINEMATIC||f.type&r.KINEMATIC&&v.type&r.KINEMATIC,E=0;E<f.shapes.length;E++){f.quaternion.mult(f.shapeOrientations[E],l),f.quaternion.vmult(f.shapeOffsets[E],c),c.vadd(f.position,c);for(var T=f.shapes[E],S=0;S<v.shapes.length;S++){v.quaternion.mult(v.shapeOrientations[S],h),v.quaternion.vmult(v.shapeOffsets[S],u),u.vadd(v.position,u);var C=v.shapes[S];if(!(c.distanceTo(u)>T.boundingSphereRadius+C.boundingSphereRadius)){var A=null;T.material&&C.material&&(A=i.getContactMaterial(T.material,C.material)||null),this.currentContactMaterial=A||m||i.defaultContactMaterial;var R=this[T.type|C.type];if(R){(T.type<C.type?R.call(this,T,C,c,u,l,h,f,v,T,C,y):R.call(this,C,T,u,c,h,l,v,f,T,C,y))&&y&&(i.shapeOverlapKeeper.set(T.id,C.id),i.bodyOverlapKeeper.set(f.id,v.id))}}}}}};o.prototype[a.types.BOX|a.types.BOX]=o.prototype.boxBox=function(t,e,i,o,n,s,r,a,l,h,c){return t.convexPolyhedronRepresentation.material=t.material,e.convexPolyhedronRepresentation.material=e.material,t.convexPolyhedronRepresentation.collisionResponse=t.collisionResponse,e.convexPolyhedronRepresentation.collisionResponse=e.collisionResponse,this.convexConvex(t.convexPolyhedronRepresentation,e.convexPolyhedronRepresentation,i,o,n,s,r,a,t,e,c)},o.prototype[a.types.BOX|a.types.CONVEXPOLYHEDRON]=o.prototype.boxConvex=function(t,e,i,o,n,s,r,a,l,h,c){return t.convexPolyhedronRepresentation.material=t.material,t.convexPolyhedronRepresentation.collisionResponse=t.collisionResponse,this.convexConvex(t.convexPolyhedronRepresentation,e,i,o,n,s,r,a,t,e,c)},o.prototype[a.types.BOX|a.types.PARTICLE]=o.prototype.boxParticle=function(t,e,i,o,n,s,r,a,l,h,c){return t.convexPolyhedronRepresentation.material=t.material,t.convexPolyhedronRepresentation.collisionResponse=t.collisionResponse,this.convexParticle(t.convexPolyhedronRepresentation,e,i,o,n,s,r,a,t,e,c)},o.prototype[a.types.SPHERE]=o.prototype.sphereSphere=function(t,e,i,o,n,s,r,a,l,h,c){if(c)return i.distanceSquared(o)<Math.pow(t.radius+e.radius,2);var u=this.createContactEquation(r,a,t,e,l,h);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 h,T=new h,S=new h;o.prototype[a.types.PLANE|a.types.TRIMESH]=o.prototype.planeTrimesh=function(t,e,i,o,n,s,r,a,l,u,p){var d=new h,f=E;f.set(0,0,1),n.vmult(f,f);for(var v=0;v<e.vertices.length/3;v++){e.getVertex(v,d);var m=new h;m.copy(d),c.pointToWorldFrame(o,s,m,d);var y=T;d.vsub(i,y);if(f.dot(y)<=0){if(p)return!0;var g=this.createContactEquation(r,a,t,e,l,u);g.ni.copy(f);var w=S;f.scale(y.dot(f),w),d.vsub(w,w),g.ri.copy(w),g.ri.vsub(r.position,g.ri),g.rj.copy(d),g.rj.vsub(a.position,g.rj),this.result.push(g),this.createFrictionEquationsFromContact(g,this.frictionResult)}}};var C=new h,A=new h,R=(new h,new h),M=new h,B=new h,z=new h,k=new h,L=new h,P=new h,I=new h,N=new h,_=new h,F=new h,V=new s,q=[];o.prototype[a.types.SPHERE|a.types.TRIMESH]=o.prototype.sphereTrimesh=function(t,e,i,o,n,s,r,a,h,u,p){var d=B,f=z,v=k,m=L,y=P,g=I,w=V,b=M,x=A,E=q;c.pointToLocalFrame(o,s,i,y);var T=t.radius;w.lowerBound.set(y.x-T,y.y-T,y.z-T),w.upperBound.set(y.x+T,y.y+T,y.z+T),e.getTrianglesInAABB(w,E);for(var S=R,D=t.radius*t.radius,O=0;O<E.length;O++)for(H=0;H<3;H++)if(e.getVertex(e.indices[3*E[O]+H],S),S.vsub(y,x),x.norm2()<=D){if(b.copy(S),c.pointToWorldFrame(o,s,b,S),S.vsub(i,x),p)return!0;(Z=this.createContactEquation(r,a,t,e,h,u)).ni.copy(x),Z.ni.normalize(),Z.ri.copy(Z.ni),Z.ri.scale(t.radius,Z.ri),Z.ri.vadd(i,Z.ri),Z.ri.vsub(r.position,Z.ri),Z.rj.copy(S),Z.rj.vsub(a.position,Z.rj),this.result.push(Z),this.createFrictionEquationsFromContact(Z,this.frictionResult)}for(O=0;O<E.length;O++)for(var H=0;H<3;H++){e.getVertex(e.indices[3*E[O]+H],d),e.getVertex(e.indices[3*E[O]+(H+1)%3],f),f.vsub(d,v),y.vsub(f,g);var j=g.dot(v);y.vsub(d,g);var W=g.dot(v);if(W>0&&j<0){y.vsub(d,g),m.copy(v),m.normalize(),W=g.dot(m),m.scale(W,g),g.vadd(d,g);if((Q=g.distanceTo(y))<t.radius){if(p)return!0;Z=this.createContactEquation(r,a,t,e,h,u);g.vsub(y,Z.ni),Z.ni.normalize(),Z.ni.scale(t.radius,Z.ri),c.pointToWorldFrame(o,s,g,g),g.vsub(a.position,Z.rj),c.vectorToWorldFrame(s,Z.ni,Z.ni),c.vectorToWorldFrame(s,Z.ri,Z.ri),this.result.push(Z),this.createFrictionEquationsFromContact(Z,this.frictionResult)}}}for(var U=N,G=_,K=F,X=C,O=0,Y=E.length;O!==Y;O++){e.getTriangleVertices(E[O],U,G,K),e.getNormal(E[O],X),y.vsub(U,g);var Q=g.dot(X);if(X.scale(Q,g),y.vsub(g,g),Q=g.distanceTo(y),l.pointInTriangle(g,U,G,K)&&Q<t.radius){if(p)return!0;var Z=this.createContactEquation(r,a,t,e,h,u);g.vsub(y,Z.ni),Z.ni.normalize(),Z.ni.scale(t.radius,Z.ri),c.pointToWorldFrame(o,s,g,g),g.vsub(a.position,Z.rj),c.vectorToWorldFrame(s,Z.ni,Z.ni),c.vectorToWorldFrame(s,Z.ri,Z.ri),this.result.push(Z),this.createFrictionEquationsFromContact(Z,this.frictionResult)}}E.length=0};var D=new h,O=new h;o.prototype[a.types.SPHERE|a.types.PLANE]=o.prototype.spherePlane=function(t,e,i,o,n,s,r,a,l,h,c){var u=this.createContactEquation(r,a,t,e,l,h);if(u.ni.set(0,0,1),s.vmult(u.ni,u.ni),u.ni.negate(u.ni),u.ni.normalize(),u.ni.mult(t.radius,u.ri),i.vsub(o,D),u.ni.mult(u.ni.dot(D),O),D.vsub(O,u.rj),-D.dot(u.ni)<=t.radius){if(c)return!0;var p=u.ri,d=u.rj;p.vadd(i,p),p.vsub(r.position,p),d.vadd(o,d),d.vsub(a.position,d),this.result.push(u),this.createFrictionEquationsFromContact(u,this.frictionResult)}};var H=new h,j=new h,W=new h,U=new h,G=new h,K=new h,X=new h,Y=[new h,new h,new h,new h,new h,new h],Q=new h,Z=new h,J=new h,$=new h;o.prototype[a.types.SPHERE|a.types.BOX]=o.prototype.sphereBox=function(t,e,i,o,n,s,r,a,l,h,c){var u=this.v3pool,p=Y;i.vsub(o,U),e.getSideNormals(p,s);for(var d=t.radius,f=!1,v=Z,m=J,y=$,g=null,w=0,b=0,x=0,E=null,T=0,S=p.length;T!==S&&!1===f;T++){var C=G;C.copy(p[T]);var A=C.norm();C.normalize();var R=U.dot(C);if(R<A+d&&R>0){var M=K,B=X;M.copy(p[(T+1)%3]),B.copy(p[(T+2)%3]);var z=M.norm(),k=B.norm();M.normalize(),B.normalize();var L=U.dot(M),P=U.dot(B);if(L<z&&L>-z&&P<k&&P>-k){O=Math.abs(R-A-d);if((null===E||O<E)&&(E=O,b=L,x=P,g=A,v.copy(C),m.copy(M),y.copy(B),w++,c))return!0}}}if(w){f=!0;q=this.createContactEquation(r,a,t,e,l,h);v.mult(-d,q.ri),q.ni.copy(v),q.ni.negate(q.ni),v.mult(g,v),m.mult(b,m),v.vadd(m,v),y.mult(x,y),v.vadd(y,q.rj),q.ri.vadd(i,q.ri),q.ri.vsub(r.position,q.ri),q.rj.vadd(o,q.rj),q.rj.vsub(a.position,q.rj),this.result.push(q),this.createFrictionEquationsFromContact(q,this.frictionResult)}for(var I=u.get(),N=Q,_=0;2!==_&&!f;_++)for(j=0;2!==j&&!f;j++)for(tt=0;2!==tt&&!f;tt++)if(I.set(0,0,0),_?I.vadd(p[0],I):I.vsub(p[0],I),j?I.vadd(p[1],I):I.vsub(p[1],I),tt?I.vadd(p[2],I):I.vsub(p[2],I),o.vadd(I,N),N.vsub(i,N),N.norm2()<d*d){if(c)return!0;f=!0;(q=this.createContactEquation(r,a,t,e,l,h)).ri.copy(N),q.ri.normalize(),q.ni.copy(q.ri),q.ri.mult(d,q.ri),q.rj.copy(I),q.ri.vadd(i,q.ri),q.ri.vsub(r.position,q.ri),q.rj.vadd(o,q.rj),q.rj.vsub(a.position,q.rj),this.result.push(q),this.createFrictionEquationsFromContact(q,this.frictionResult)}u.release(I),I=null;for(var F=u.get(),V=u.get(),q=u.get(),D=u.get(),O=u.get(),H=p.length,_=0;_!==H&&!f;_++)for(var j=0;j!==H&&!f;j++)if(_%3!=j%3){p[j].cross(p[_],F),F.normalize(),p[_].vadd(p[j],V),q.copy(i),q.vsub(V,q),q.vsub(o,q);var W=q.dot(F);F.mult(W,D);for(var tt=0;tt===_%3||tt===j%3;)tt++;O.copy(i),O.vsub(D,O),O.vsub(V,O),O.vsub(o,O);var et=Math.abs(W),it=O.norm();if(et<p[tt].norm()&&it<d){if(c)return!0;f=!0;var ot=this.createContactEquation(r,a,t,e,l,h);V.vadd(D,ot.rj),ot.rj.copy(ot.rj),O.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(F,V,q,D,O)};var tt=new h,et=new h,it=new h,ot=new h,nt=new h,st=new h,rt=new h,at=new h,lt=new h,ht=new h;o.prototype[a.types.SPHERE|a.types.CONVEXPOLYHEDRON]=o.prototype.sphereConvex=function(t,e,i,o,s,r,a,l,h,c,u){var p=this.v3pool;i.vsub(o,tt);for(var d=e.faceNormals,f=e.faces,v=e.vertices,m=t.radius,y=0;y!==v.length;y++){var g=v[y],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;x=!0;return(G=this.createContactEquation(a,l,t,e,h,c)).ri.copy(b),G.ri.normalize(),G.ni.copy(G.ri),G.ri.mult(m,G.ri),w.vsub(o,G.rj),G.ri.vadd(i,G.ri),G.ri.vsub(a.position,G.ri),G.rj.vadd(o,G.rj),G.rj.vsub(l.position,G.rj),this.result.push(G),void this.createFrictionEquationsFromContact(G,this.frictionResult)}}for(var x=!1,y=0,E=f.length;y!==E&&!1===x;y++){var T=d[y],S=f[y],C=st;r.vmult(T,C);var A=rt;r.vmult(v[S[0]],A),A.vadd(o,A);var R=at;C.mult(-m,R),i.vadd(R,R);var M=lt;R.vsub(A,M);var B=M.dot(C),z=ht;if(i.vsub(A,z),B<0&&z.dot(C)>0){for(var k=[],L=0,P=S.length;L!==P;L++){var I=p.get();r.vmult(v[S[L]],I),o.vadd(I,I),k.push(I)}if(n(k,C,i)){if(u)return!0;x=!0;G=this.createContactEquation(a,l,t,e,h,c);C.mult(-m,G.ri),C.negate(G.ni);var N=p.get();C.mult(-B,N);var _=p.get();C.mult(-m,_),i.vsub(o,G.rj),G.rj.vadd(_,G.rj),G.rj.vadd(N,G.rj),G.rj.vadd(o,G.rj),G.rj.vsub(l.position,G.rj),G.ri.vadd(i,G.ri),G.ri.vsub(a.position,G.ri),p.release(N),p.release(_),this.result.push(G),this.createFrictionEquationsFromContact(G,this.frictionResult);for(var L=0,F=k.length;L!==F;L++)p.release(k[L]);return}for(L=0;L!==S.length;L++){var V=p.get(),q=p.get();r.vmult(v[S[(L+1)%S.length]],V),r.vmult(v[S[(L+2)%S.length]],q),o.vadd(V,V),o.vadd(q,q);var D=et;q.vsub(V,D);var O=it;D.unit(O);var H=p.get(),j=p.get();i.vsub(V,j);var W=j.dot(O);O.mult(W,H),H.vadd(V,H);var U=p.get();if(H.vsub(i,U),W>0&&W*W<D.norm2()&&U.norm2()<m*m){if(u)return!0;var G=this.createContactEquation(a,l,t,e,h,c);H.vsub(o,G.rj),H.vsub(i,G.ni),G.ni.normalize(),G.ni.mult(m,G.ri),G.rj.vadd(o,G.rj),G.rj.vsub(l.position,G.rj),G.ri.vadd(i,G.ri),G.ri.vsub(a.position,G.ri),this.result.push(G),this.createFrictionEquationsFromContact(G,this.frictionResult);for(var L=0,F=k.length;L!==F;L++)p.release(k[L]);return p.release(V),p.release(q),p.release(H),p.release(U),void p.release(j)}p.release(V),p.release(q),p.release(H),p.release(U),p.release(j)}for(var L=0,F=k.length;L!==F;L++)p.release(k[L])}}};new h,new h;o.prototype[a.types.PLANE|a.types.BOX]=o.prototype.planeBox=function(t,e,i,o,n,s,r,a,l,h,c){return e.convexPolyhedronRepresentation.material=e.material,e.convexPolyhedronRepresentation.collisionResponse=e.collisionResponse,e.convexPolyhedronRepresentation.id=e.id,this.planeConvex(t,e.convexPolyhedronRepresentation,i,o,n,s,r,a,t,e,c)};var ct=new h,ut=new h,pt=new h,dt=new h;o.prototype[a.types.PLANE|a.types.CONVEXPOLYHEDRON]=o.prototype.planeConvex=function(t,e,i,o,n,s,r,a,l,h,c){var u=ct,p=ut;p.set(0,0,1),n.vmult(p,p);for(var d=0,f=pt,v=0;v!==e.vertices.length;v++){u.copy(e.vertices[v]),s.vmult(u,u),o.vadd(u,u),u.vsub(i,f);if(p.dot(f)<=0){if(c)return!0;var m=this.createContactEquation(r,a,t,e,l,h),y=dt;p.mult(p.dot(f),y),u.vsub(y,y),y.vsub(i,m.ri),m.ni.copy(p),u.vsub(o,m.rj),m.ri.vadd(i,m.ri),m.ri.vsub(r.position,m.ri),m.rj.vadd(o,m.rj),m.rj.vsub(a.position,m.rj),this.result.push(m),d++,this.enableFrictionReduction||this.createFrictionEquationsFromContact(m,this.frictionResult)}}this.enableFrictionReduction&&d&&this.createFrictionFromAverage(d)};var ft=new h,vt=new h;o.prototype[a.types.CONVEXPOLYHEDRON]=o.prototype.convexConvex=function(t,e,i,o,n,s,r,a,l,h,c,u,p){var d=ft;if(!(i.distanceTo(o)>t.boundingSphereRadius+e.boundingSphereRadius)&&t.findSeparatingAxis(e,i,n,o,s,d,u,p)){var f=[],v=vt;t.clipAgainstHull(i,n,e,o,s,d,-100,100,f);for(var m=0,y=0;y!==f.length;y++){if(c)return!0;var g=this.createContactEquation(r,a,t,e,l,h),w=g.ri,b=g.rj;d.negate(g.ni),f[y].normal.negate(v),v.mult(f[y].depth,v),f[y].point.vadd(v,w),b.copy(f[y].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 h,yt=new h,gt=new h;o.prototype[a.types.PLANE|a.types.PARTICLE]=o.prototype.planeParticle=function(t,e,i,o,n,s,r,a,l,h,c){var u=mt;u.set(0,0,1),r.quaternion.vmult(u,u);var p=yt;o.vsub(r.position,p);if(u.dot(p)<=0){if(c)return!0;var d=this.createContactEquation(a,r,e,t,l,h);d.ni.copy(u),d.ni.negate(d.ni),d.ri.set(0,0,0);var f=gt;u.mult(u.dot(o),f),o.vsub(f,f),d.rj.copy(f),this.result.push(d),this.createFrictionEquationsFromContact(d,this.frictionResult)}};var wt=new h;o.prototype[a.types.PARTICLE|a.types.SPHERE]=o.prototype.sphereParticle=function(t,e,i,o,n,s,r,a,l,h,c){var u=wt;u.set(0,0,1),o.vsub(i,u);if(u.norm2()<=t.radius*t.radius){if(c)return!0;var p=this.createContactEquation(a,r,e,t,l,h);u.normalize(),p.rj.copy(u),p.rj.mult(t.radius,p.rj),p.ni.copy(u),p.ni.negate(p.ni),p.ri.set(0,0,0),this.result.push(p),this.createFrictionEquationsFromContact(p,this.frictionResult)}};var bt=new u,xt=new h,Et=(new h,new h),Tt=new h,St=new h;o.prototype[a.types.PARTICLE|a.types.CONVEXPOLYHEDRON]=o.prototype.convexParticle=function(t,e,i,o,n,s,r,a,l,h,c){var u=-1,p=Et,d=St,f=null,v=xt;if(v.copy(o),v.vsub(i,v),n.conjugate(bt),bt.vmult(v,v),t.pointIsInside(v)){t.worldVerticesNeedsUpdate&&t.computeWorldVertices(i,n),t.worldFaceNormalsNeedsUpdate&&t.computeWorldFaceNormals(n);for(var m=0,y=t.faces.length;m!==y;m++){var g=[t.worldVertices[t.faces[m][0]]],w=t.worldFaceNormals[m];o.vsub(g[0],Tt);var b=-w.dot(Tt);if(null===f||Math.abs(b)<Math.abs(f)){if(c)return!0;f=b,u=m,p.copy(w),0}}if(-1!==u){var x=this.createContactEquation(a,r,e,t,l,h);p.mult(f,d),d.vadd(o,d),d.vsub(i,d),x.rj.copy(d),p.negate(x.ni),x.ri.set(0,0,0);var E=x.ri,T=x.rj;E.vadd(o,E),E.vsub(a.position,E),T.vadd(i,T),T.vsub(r.position,T),this.result.push(x),this.createFrictionEquationsFromContact(x,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,l,h,c){return t.convexPolyhedronRepresentation.material=t.material,t.convexPolyhedronRepresentation.collisionResponse=t.collisionResponse,this.convexHeightfield(t.convexPolyhedronRepresentation,e,i,o,n,s,r,a,t,e,c)};var Ct=new h,At=new h,Rt=[0];o.prototype[a.types.CONVEXPOLYHEDRON|a.types.HEIGHTFIELD]=o.prototype.convexHeightfield=function(t,e,i,o,n,s,r,a,l,h,u){var p=e.data,d=e.elementSize,f=t.boundingSphereRadius,v=At,m=Rt,y=Ct;c.pointToLocalFrame(o,s,i,y);var g=Math.floor((y.x-f)/d)-1,w=Math.ceil((y.x+f)/d)+1,b=Math.floor((y.y-f)/d)-1,x=Math.ceil((y.y+f)/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 T=E[0],S=E[1];if(!(y.z-f>S||y.z+f<T))for(var C=g;C<w;C++)for(var A=b;A<x;A++){var R=!1;if(e.getConvexTrianglePillar(C,A,!1),c.pointToWorldFrame(o,s,e.pillarOffset,v),i.distanceTo(v)<e.pillarConvex.boundingSphereRadius+t.boundingSphereRadius&&(R=this.convexConvex(t,e.pillarConvex,i,v,n,s,r,a,null,null,u,m,null)),u&&R)return!0;if(e.getConvexTrianglePillar(C,A,!0),c.pointToWorldFrame(o,s,e.pillarOffset,v),i.distanceTo(v)<e.pillarConvex.boundingSphereRadius+t.boundingSphereRadius&&(R=this.convexConvex(t,e.pillarConvex,i,v,n,s,r,a,null,null,u,m,null)),u&&R)return!0}}};var Mt=new h,Bt=new h;o.prototype[a.types.SPHERE|a.types.HEIGHTFIELD]=o.prototype.sphereHeightfield=function(t,e,i,o,n,s,r,a,l,h,u){var p=e.data,d=t.radius,f=e.elementSize,v=Bt,m=Mt;c.pointToLocalFrame(o,s,i,m);var y=Math.floor((m.x-d)/f)-1,g=Math.ceil((m.x+d)/f)+1,w=Math.floor((m.y-d)/f)-1,b=Math.ceil((m.y+d)/f)+1;if(!(g<0||b<0||y>p.length||b>p[0].length)){y<0&&(y=0),g<0&&(g=0),w<0&&(w=0),b<0&&(b=0),y>=p.length&&(y=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(y,w,g,b,x);var E=x[0],T=x[1];if(!(m.z-d>T||m.z+d<E))for(var S=this.result,C=y;C<g;C++)for(var A=w;A<b;A++){var R=S.length,M=!1;if(e.getConvexTrianglePillar(C,A,!1),c.pointToWorldFrame(o,s,e.pillarOffset,v),i.distanceTo(v)<e.pillarConvex.boundingSphereRadius+t.boundingSphereRadius&&(M=this.sphereConvex(t,e.pillarConvex,i,v,n,s,r,a,t,e,u)),u&&M)return!0;if(e.getConvexTrianglePillar(C,A,!0),c.pointToWorldFrame(o,s,e.pillarOffset,v),i.distanceTo(v)<e.pillarConvex.boundingSphereRadius+t.boundingSphereRadius&&(M=this.sphereConvex(t,e.pillarConvex,i,v,n,s,r,a,t,e,u)),u&&M)return!0;if(S.length-R>2)return}}}},{"../collision/AABB":24,"../collision/Ray":31,"../equations/ContactEquation":41,"../equations/FrictionEquation":43,"../math/Quaternion":50,"../math/Transform":51,"../math/Vec3":52,"../objects/Body":53,"../shapes/ConvexPolyhedron":60,"../shapes/Shape":65,"../solver/Solver":69,"../utils/Vec3Pool":76}],78:[function(t,e,i){function o(t){t=t||{},l.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 h,this.collisionMatrixPrevious=new h,this.bodyOverlapKeeper=new c,this.shapeOverlapKeeper=new c,this.materials=[],this.contactmaterials=[],this.contactMaterialTable=new f,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;t("../shapes/Shape");var n=t("../math/Vec3"),s=t("../math/Quaternion"),r=t("../solver/GSSolver"),a=(t("../equations/ContactEquation"),t("../equations/FrictionEquation"),t("./Narrowphase")),l=t("../utils/EventTarget"),h=t("../collision/ArrayCollisionMatrix"),c=t("../collision/OverlapKeeper"),u=t("../material/Material"),p=t("../material/ContactMaterial"),d=t("../objects/Body"),f=t("../utils/TupleDictionary"),v=t("../collision/RaycastResult"),m=t("../collision/AABB"),y=t("../collision/Ray"),g=t("../collision/NaiveBroadphase");o.prototype=new l;new m;var w=new y;if(o.prototype.getContactMaterial=function(t,e){return this.contactMaterialTable.get(t.id,e.id)},o.prototype.numObjects=function(){return this.bodies.length},o.prototype.collisionMatrixTick=function(){var t=this.collisionMatrixPrevious;this.collisionMatrixPrevious=this.collisionMatrix,this.collisionMatrix=t,this.collisionMatrix.reset(),this.bodyOverlapKeeper.tick(),this.shapeOverlapKeeper.tick()},o.prototype.add=o.prototype.addBody=function(t){-1===this.bodies.indexOf(t)&&(t.index=this.bodies.length,this.bodies.push(t),t.world=this,t.initPosition.copy(t.position),t.initVelocity.copy(t.velocity),t.timeLastSleepy=this.time,t instanceof d&&(t.initAngularVelocity.copy(t.angularVelocity),t.initQuaternion.copy(t.quaternion)),this.collisionMatrix.setNumObjects(this.bodies.length),this.addBodyEvent.body=t,this.idToBodyMap[t.id]=t,this.dispatchEvent(this.addBodyEvent))},o.prototype.addConstraint=function(t){this.constraints.push(t)},o.prototype.removeConstraint=function(t){var e=this.constraints.indexOf(t);-1!==e&&this.constraints.splice(e,1)},o.prototype.rayTest=function(t,e,i){i instanceof 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=y.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=y.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=y.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(-1!==o){i.splice(o,1);for(var n=0;n!==i.length;n++)i[n].index=n;this.collisionMatrix.setNumObjects(e),this.removeBodyEvent.body=t,delete this.idToBodyMap[t.id],this.dispatchEvent(this.removeBodyEvent)}},o.prototype.removeBody=o.prototype.remove,o.prototype.getBodyById=function(t){return this.idToBodyMap[t]},o.prototype.getShapeById=function(t){for(var e=this.bodies,i=0,o=e.length;i<o;i++)for(var n=e[i].shapes,s=0,r=n.length;s<r;s++){var a=n[s];if(a.id===t)return a}},o.prototype.addMaterial=function(t){this.materials.push(t)},o.prototype.addContactMaterial=function(t){this.contactmaterials.push(t),this.contactMaterialTable.set(t.materials[0].id,t.materials[1].id,t)},"undefined"==typeof performance&&(performance={}),!performance.now){var 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,0===(e=e||0))this.internalStep(t),this.time+=t;else{this.accumulator+=e;for(var o=0;this.accumulator>=t&&o<i;)this.internalStep(t),this.accumulator-=t,o++;for(var n=this.accumulator%t/t,s=0;s!==this.bodies.length;s++){var r=this.bodies[s];r.previousPosition.lerp(r.position,n,r.interpolatedPosition),r.previousQuaternion.slerp(r.quaternion,n,r.interpolatedQuaternion),r.previousQuaternion.normalize()}this.time+=e}};var x={type:"postStep"},E={type:"preStep"},T={type:d.COLLIDE_EVENT_NAME,body:null,contact:null},S=[],C=[],A=[],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=A,n=R,s=this.numObjects(),r=this.bodies,a=this.solver,l=this.gravity,h=this.doProfiling,c=this.profile,u=d.DYNAMIC,p=this.constraints,f=C,v=(l.norm(),l.x),m=l.y,y=l.z,g=0;for(h&&(e=performance.now()),g=0;g!==s;g++){if((I=r[g]).type===u){var w=I.force,b=I.mass;w.x+=b*v,w.y+=b*m,w.z+=b*y}}for(var g=0,M=this.subsystems.length;g!==M;g++)this.subsystems[g].update();h&&(e=performance.now()),o.length=0,n.length=0,this.broadphase.collisionPairs(this,o,n),h&&(c.broadphase=performance.now()-e);V=p.length;for(g=0;g!==V;g++){if(!(q=p[g]).collideConnected)for(D=o.length-1;D>=0;D-=1)(q.bodyA===o[D]&&q.bodyB===n[D]||q.bodyB===o[D]&&q.bodyA===n[D])&&(o.splice(D,1),n.splice(D,1))}this.collisionMatrixTick(),h&&(e=performance.now());var B=S,z=i.length;for(g=0;g!==z;g++)B.push(i[g]);i.length=0;var k=this.frictionEquations.length;for(g=0;g!==k;g++)f.push(this.frictionEquations[g]);this.frictionEquations.length=0,this.narrowphase.getContacts(o,n,this,i,B,this.frictionEquations,f),h&&(c.narrowphase=performance.now()-e),h&&(e=performance.now());for(g=0;g<this.frictionEquations.length;g++)a.addEquation(this.frictionEquations[g]);for(var L=i.length,P=0;P!==L;P++){var I=(q=i[P]).bi,N=q.bj,_=q.si,F=q.sj;(I.material&&N.material?this.getContactMaterial(I.material,N.material)||this.defaultContactMaterial:this.defaultContactMaterial).friction;if(I.material&&N.material&&(I.material.friction>=0&&N.material.friction>=0&&I.material.friction*N.material.friction,I.material.restitution>=0&&N.material.restitution>=0&&(q.restitution=I.material.restitution*N.material.restitution)),a.addEquation(q),I.allowSleep&&I.type===d.DYNAMIC&&I.sleepState===d.SLEEPING&&N.sleepState===d.AWAKE&&N.type!==d.STATIC){N.velocity.norm2()+N.angularVelocity.norm2()>=2*Math.pow(N.sleepSpeedLimit,2)&&(I._wakeUpAfterNarrowphase=!0)}if(N.allowSleep&&N.type===d.DYNAMIC&&N.sleepState===d.SLEEPING&&I.sleepState===d.AWAKE&&I.type!==d.STATIC){I.velocity.norm2()+I.angularVelocity.norm2()>=2*Math.pow(I.sleepSpeedLimit,2)&&(N._wakeUpAfterNarrowphase=!0)}this.collisionMatrix.set(I,N,!0),this.collisionMatrixPrevious.get(I,N)||(T.body=N,T.contact=q,I.dispatchEvent(T),T.body=I,N.dispatchEvent(T)),this.bodyOverlapKeeper.set(I.id,N.id),this.shapeOverlapKeeper.set(_.id,F.id)}for(this.emitContactEvents(),h&&(c.makeContactConstraints=performance.now()-e,e=performance.now()),g=0;g!==s;g++){(I=r[g])._wakeUpAfterNarrowphase&&(I.wakeUp(),I._wakeUpAfterNarrowphase=!1)}var V=p.length;for(g=0;g!==V;g++){var q=p[g];q.update();for(var D=0,O=q.equations.length;D!==O;D++){var H=q.equations[D];a.addEquation(H)}}a.solve(t,this),h&&(c.solve=performance.now()-e),a.removeAllEquations();var j=Math.pow;for(g=0;g!==s;g++){if((I=r[g]).type&u){var W=j(1-I.linearDamping,t),U=I.velocity;U.mult(W,U);var G=I.angularVelocity;if(G){var K=j(1-I.angularDamping,t);G.mult(K,G)}}}for(this.dispatchEvent(E),g=0;g!==s;g++){(I=r[g]).preStep&&I.preStep.call(I)}h&&(e=performance.now());var X=this.stepnumber%(this.quatNormalizeSkip+1)==0,Y=this.quatNormalizeFast;for(g=0;g!==s;g++)r[g].integrate(t,X,Y);for(this.clearForces(),this.broadphase.dirty=!0,h&&(c.integrate=performance.now()-e),this.time+=t,this.stepnumber+=1,this.dispatchEvent(x),g=0;g!==s;g++){var Q=(I=r[g]).postStep;Q&&Q.call(I)}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 l=0,h=t.length;l<h;l+=2)i.bodyA=this.getBodyById(t[l]),i.bodyB=this.getBodyById(t[l+1]),this.dispatchEvent(i);i.bodyA=i.bodyB=null}if(a){for(var l=0,h=e.length;l<h;l+=2)o.bodyA=this.getBodyById(e[l]),o.bodyB=this.getBodyById(e[l+1]),this.dispatchEvent(o);o.bodyA=o.bodyB=null}t.length=e.length=0;var c=this.hasAnyEventListener("beginShapeContact"),u=this.hasAnyEventListener("endShapeContact");if((c||u)&&this.shapeOverlapKeeper.getDiff(t,e),c){for(var l=0,h=t.length;l<h;l+=2){var p=this.getShapeById(t[l]),d=this.getShapeById(t[l+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 l=0,h=e.length;l<h;l+=2){var p=this.getShapeById(e[l]),d=this.getShapeById(e[l+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":24,"../collision/ArrayCollisionMatrix":25,"../collision/NaiveBroadphase":28,"../collision/OverlapKeeper":30,"../collision/Ray":31,"../collision/RaycastResult":32,"../equations/ContactEquation":41,"../equations/FrictionEquation":43,"../material/ContactMaterial":46,"../material/Material":47,"../math/Quaternion":50,"../math/Vec3":52,"../objects/Body":53,"../shapes/Shape":65,"../solver/GSSolver":68,"../utils/EventTarget":71,"../utils/TupleDictionary":74,"./Narrowphase":77}],79:[function(t,e,i){const o=t("./BinaryHeap"),n=t("./utils.js");class s{static init(t){for(let e=0;e<t.length;e++){const i=t[e];i.f=0,i.g=0,i.h=0,i.cost=1,i.visited=!1,i.closed=!1,i.parent=null}}static cleanUp(t){for(let e=0;e<t.length;e++){const i=t[e];delete i.f,delete i.g,delete i.h,delete i.cost,delete i.visited,delete i.closed,delete i.parent}}static heap(){return new o(function(t){return t.f})}static search(t,e,i){this.init(t);const o=this.heap();for(o.push(e);o.size()>0;){const e=o.pop();if(e===i){let t=e;const i=[];for(;t.parent;)i.push(t),t=t.parent;return this.cleanUp(i),i.reverse()}e.closed=!0;const n=this.neighbours(t,e);for(let t=0,s=n.length;t<s;t++){const s=n[t];if(s.closed)continue;const r=e.g+s.cost,a=s.visited;if(!a||r<s.g){if(s.visited=!0,s.parent=e,!s.centroid||!i.centroid)throw new Error("Unexpected state");s.h=s.h||this.heuristic(s.centroid,i.centroid),s.g=r,s.f=s.g+s.h,a?o.rescoreElement(s):o.push(s)}}}return[]}static heuristic(t,e){return n.distanceToSquared(t,e)}static neighbours(t,e){const i=[];for(let o=0;o<e.neighbours.length;o++)i.push(t[e.neighbours[o]]);return i}}e.exports=s},{"./BinaryHeap":80,"./utils.js":83}],80:[function(t,e,i){class o{constructor(t){this.content=[],this.scoreFunction=t}push(t){this.content.push(t),this.sinkDown(this.content.length-1)}pop(){const t=this.content[0],e=this.content.pop();return this.content.length>0&&(this.content[0]=e,this.bubbleUp(0)),t}remove(t){const e=this.content.indexOf(t),i=this.content.pop();e!==this.content.length-1&&(this.content[e]=i,this.scoreFunction(i)<this.scoreFunction(t)?this.sinkDown(e):this.bubbleUp(e))}size(){return this.content.length}rescoreElement(t){this.sinkDown(this.content.indexOf(t))}sinkDown(t){const e=this.content[t];for(;t>0;){const i=(t+1>>1)-1,o=this.content[i];if(!(this.scoreFunction(e)<this.scoreFunction(o)))break;this.content[i]=e,this.content[t]=o,t=i}}bubbleUp(t){const e=this.content.length,i=this.content[t],o=this.scoreFunction(i);for(;;){const n=t+1<<1,s=n-1;let r,a=null;if(s<e){const t=this.content[s];(r=this.scoreFunction(t))<o&&(a=s)}if(n<e){const t=this.content[n];this.scoreFunction(t)<(null===a?o:r)&&(a=n)}if(null===a)break;this.content[t]=this.content[a],this.content[a]=i,t=a}}}e.exports=o},{}],81:[function(t,e,i){const o=t("./utils");class n{constructor(){this.portals=[]}push(t,e){void 0===e&&(e=t),this.portals.push({left:t,right:e})}stringPull(){const t=this.portals,e=[];let i,n,s,r=0,a=0,l=0;i=t[0].left,n=t[0].left,s=t[0].right,e.push(i);for(let h=1;h<t.length;h++){const c=t[h].left,u=t[h].right;if(o.triarea2(i,s,u)<=0){if(!(o.vequal(i,s)||o.triarea2(i,n,u)>0)){e.push(n),n=i=n,s=i,a=r=a,l=r,h=r;continue}s=u,l=h}if(o.triarea2(i,n,c)>=0){if(!(o.vequal(i,n)||o.triarea2(i,s,c)<0)){e.push(s),n=i=s,s=i,a=r=l,l=r,h=r;continue}n=c,a=h}}return 0!==e.length&&o.vequal(e[e.length-1],t[t.length-1].left)||e.push(t[t.length-1].left),this.path=e,e}}e.exports=n},{"./utils":83}],82:[function(t,e,i){const o=t("./utils"),n=t("./AStar"),s=t("./Channel");var r=1,a=function(t){console.log("Vertices:",t.vertices.length,"polygons:",t.faces.length);var e=[],i=t.vertices,n=t.faceVertexUvs;t.faces.forEach(t=>{e.push({id:r++,vertexIds:[t.a,t.b,t.c],centroid:t.centroid,normal:t.normal,neighbours:[]})});var s={polygons:e,vertices:i,faceVertexUvs:n};return e.forEach(t=>{!function(t,e){t.neighbours=[];for(var i=0,n=e.polygons.length;i<n;i++)t===e.polygons[i]||t.centroid.distanceToSquared(e.polygons[i].centroid)>1e4||o.array_intersect(t.vertexIds,e.polygons[i].vertexIds).length>=2&&t.neighbours.push(e.polygons[i])}(t,s)}),s},l=function(t){var e={};t.vertices.forEach(t=>{t.x=o.roundNumber(t.x,2),t.y=o.roundNumber(t.y,2),t.z=o.roundNumber(t.z,2)}),e.vertices=t.vertices;var i=function(t){var e=[],i=0,o=function(t){t.neighbours.forEach(e=>{void 0===e.group&&(e.group=t.group,o(e))})};return t.polygons.forEach(t=>{void 0===t.group&&(t.group=i++,o(t)),e[t.group]||(e[t.group]=[]),e[t.group].push(t)}),console.log("Groups built: ",e.length),e}(t);e.groups=[];var n=function(t,e){for(var i=0;i<t.length;i++)if(e===t[i])return i};return i.forEach(t=>{var i=[];t.forEach(e=>{var s=[];e.neighbours.forEach(e=>{s.push(n(t,e))});var r=[];e.neighbours.forEach(t=>{r.push(function(t,e){var i=t.vertexIds,o=e.vertexIds,n=[];return i.forEach(t=>{o.includes(t)&&n.push(t)}),n.length<2?[]:(n.includes(i[0])&&n.includes(i[i.length-1])&&i.push(i.shift()),n.includes(o[0])&&n.includes(o[o.length-1])&&o.push(o.shift()),n=[],i.forEach(t=>{o.includes(t)&&n.push(t)}),n)}(e,t))}),e.centroid.x=o.roundNumber(e.centroid.x,2),e.centroid.y=o.roundNumber(e.centroid.y,2),e.centroid.z=o.roundNumber(e.centroid.z,2),i.push({id:n(t,e),neighbours:s,vertexIds:e.vertexIds,centroid:e.centroid,portals:r})}),e.groups.push(i)}),e},h={};e.exports={buildNodes:function(t){var e=function(t){return o.computeCentroids(t),t.mergeVertices(),a(t)}(t);return l(e)},setZoneData:function(t,e){h[t]=e},getGroup:function(t,e){if(!h[t])return null;var i=null,n=Math.pow(50,2);return h[t].groups.forEach((t,s)=>{t.forEach(t=>{var r=o.distanceToSquared(t.centroid,e);r<n&&(i=s,n=r)})}),i},getRandomNode:function(t,e,i,n){if(!h[t])return new THREE.Vector3;i=i||null,n=n||0;var s=[];return h[t].groups[e].forEach(t=>{i&&n?o.distanceToSquared(i,t.centroid)<n*n&&s.push(t.centroid):s.push(t.centroid)}),o.sample(s)||new THREE.Vector3},getClosestNode:function(t,e,i,n=!1){const s=h[e].groups[i],r=h[e].vertices;let a=null,l=1/0;return s.forEach(e=>{const i=o.distanceToSquared(e.centroid,t);i<l&&(!n||o.isVectorInPolygon(t,e,r))&&(a=e,l=i)}),a},findPath:function(t,e,i,o){const r=h[i].groups[o],a=h[i].vertices,l=this.getClosestNode(t,i,o),c=this.getClosestNode(e,i,o,!0);if(!l||!c)return null;const u=n.search(r,l,c),p=function(t,e){for(var i=0;i<t.neighbours.length;i++)if(t.neighbours[i]===e.id)return t.portals[i]},d=new s;d.push(t);for(let t=0;t<u.length;t++){const e=u[t],i=u[t+1];if(i){const t=p(e,i);d.push(a[t[0]],a[t[1]])}}d.push(e),d.stringPull();const f=d.path.map(t=>new THREE.Vector3(t.x,t.y,t.z));return f.shift(),f}}},{"./AStar":79,"./Channel":81,"./utils":83}],83:[function(t,e,i){class o{static computeCentroids(t){var e,i,o;for(e=0,i=t.faces.length;e<i;e++)(o=t.faces[e]).centroid=new THREE.Vector3(0,0,0),o.centroid.add(t.vertices[o.a]),o.centroid.add(t.vertices[o.b]),o.centroid.add(t.vertices[o.c]),o.centroid.divideScalar(3)}static roundNumber(t,e){var i=Number(t+"").toFixed(parseInt(e));return parseFloat(i)}static sample(t){return t[Math.floor(Math.random()*t.length)]}static mergeVertexIds(t,e){var i=[];if(t.forEach(t=>{e.indexOf(t)>=0&&i.push(t)}),i.length<2)return[];i.includes(t[0])&&i.includes(t[t.length-1])&&t.push(t.shift()),i.includes(e[0])&&i.includes(e[e.length-1])&&e.push(e.shift()),i=[],t.forEach(t=>{e.includes(t)&&i.push(t)});for(var o=i[1],n=i[0],s=t.slice();s[0]!==o;)s.push(s.shift());for(var r=0,a=e.slice();a[0]!==n;)if(a.push(a.shift()),r++>10)throw new Error("Unexpected state");return a.shift(),a.pop(),s=s.concat(a)}static setPolygonCentroid(t,e){var i=new THREE.Vector3,o=e.vertices;t.vertexIds.forEach(t=>{i.add(o[t])}),i.divideScalar(t.vertexIds.length),t.centroid.copy(i)}static cleanPolygon(t,e){for(var i=[],o=e.vertices,n=0;n<t.vertexIds.length;n++){var s,r,a,l,h=o[t.vertexIds[n]];0===n?(s=t.vertexIds[1],r=t.vertexIds[t.vertexIds.length-1]):n===t.vertexIds.length-1?(s=t.vertexIds[0],r=t.vertexIds[t.vertexIds.length-2]):(s=t.vertexIds[n+1],r=t.vertexIds[n-1]),a=o[s],l=o[r];var c=a.clone().sub(h),u=l.clone().sub(h),p=c.angleTo(u);if(p>Math.PI-.01&&p<Math.PI+.01){var d=[];t.neighbours.forEach(e=>{e.vertexIds.includes(t.vertexIds[n])||d.push(e)}),t.neighbours=d}else i.push(t.vertexIds[n])}t.vertexIds=i,setPolygonCentroid(t,e)}static isConvex(t,e){var i=e.vertices;if(t.vertexIds.length<3)return!1;for(var o=!0,n=[],s=0;s<t.vertexIds.length;s++){var r,a,l=i[t.vertexIds[s]];0===s?(r=i[t.vertexIds[1]],a=i[t.vertexIds[t.vertexIds.length-1]]):s===t.vertexIds.length-1?(r=i[t.vertexIds[0]],a=i[t.vertexIds[t.vertexIds.length-2]]):(r=i[t.vertexIds[s+1]],a=i[t.vertexIds[s-1]]);var h=r.clone().sub(l),c=a.clone().sub(l),u=h.angleTo(c);if(u,u===Math.PI||0===u)return!1;var p=h.cross(c).y;n.push(p)}return n.forEach(t=>{0===t&&(o=!1)}),n[0]>0?n.forEach(t=>{t<0&&(o=!1)}):n.forEach(t=>{t>0&&(o=!1)}),o}static distanceToSquared(t,e){var i=t.x-e.x,o=t.y-e.y,n=t.z-e.z;return i*i+o*o+n*n}static isPointInPoly(t,e){for(var i=!1,o=-1,n=t.length,s=n-1;++o<n;s=o)(t[o].z<=e.z&&e.z<t[s].z||t[s].z<=e.z&&e.z<t[o].z)&&e.x<(t[s].x-t[o].x)*(e.z-t[o].z)/(t[s].z-t[o].z)+t[o].x&&(i=!i);return i}static isVectorInPolygon(t,e,i){var o=1e5,n=-1e5,s=[];return e.vertexIds.forEach(t=>{o=Math.min(i[t].y,o),n=Math.max(i[t].y,n),s.push(i[t])}),!!(t.y<n+.5&&t.y>o-.5&&this.isPointInPoly(s,t))}static triarea2(t,e,i){var o=e.x-t.x,n=e.z-t.z;return(i.x-t.x)*n-o*(i.z-t.z)}static vequal(t,e){return this.distanceToSquared(t,e)<1e-5}static array_intersect(){let t,e,i,o,n,s,r=[],a={};for(s=arguments.length-1,i=arguments[0].length,e=0,t=0;t<=s;t++)(o=arguments[t].length)<i&&(e=t,i=o);for(t=0;t<=s;t++){n=arguments[o=t===e?0:t||e].length;for(var l=0;l<n;l++){var h=arguments[o][l];a[h]===t-1?t===s?(r.push(h),a[h]=0):a[h]=t:0===t&&(a[h]=0)}}return r}}e.exports=o},{}],84:[function(t,e,i){function o(t){if(!r(t).length)return null;t.computeBoundingBox();var e=t.boundingBox;return new a.Box(new a.Vec3((e.max.x-e.min.x)/2,(e.max.y-e.min.y)/2,(e.max.z-e.min.z)/2))}function n(t){var e,i,o,n=new THREE.Box3;return n.setFromObject(t),isFinite(n.min.lengthSq())?(e=new a.Box(new a.Vec3((n.max.x-n.min.x)/2,(n.max.y-n.min.y)/2,(n.max.z-n.min.z)/2)),t.updateMatrixWorld(),(o=new THREE.Vector3).setFromMatrixPosition(t.matrixWorld),(i=n.translate(o.negate()).getCenter()).lengthSq()&&(e.offset=i),e):null}function s(t){var e,i,o=function(t){var e=[];return t.traverse(function(t){"Mesh"===t.type&&e.push(t)}),e}(t),n=new THREE.Geometry,s=new THREE.Geometry;if(0===o.length)return null;if(1===o.length){var r=new THREE.Vector3,a=new THREE.Quaternion,l=new THREE.Vector3;return o[0].geometry.isBufferGeometry?o[0].geometry.attributes.position&&n.fromBufferGeometry(o[0].geometry):n=o[0].geometry.clone(),n.metadata=o[0].geometry.metadata,o[0].updateMatrixWorld(),o[0].matrixWorld.decompose(r,a,l),n.scale(l.x,l.y,l.z)}for(;i=o.pop();)i.updateMatrixWorld(),i.geometry.isBufferGeometry?(n.fromBufferGeometry(i.geometry),s.merge(n,i.matrixWorld)):s.merge(i.geometry,i.matrixWorld);return(e=new THREE.Matrix4).scale(t.scale),s.applyMatrix(e),s}function r(t){return t.attributes||(t=(new THREE.BufferGeometry).fromGeometry(t)),(t.attributes.position||{}).array||[]}var a=t("cannon"),l=t("./lib/THREE.quickhull"),h=Math.PI/2,c={BOX:"Box",CYLINDER:"Cylinder",SPHERE:"Sphere",HULL:"ConvexPolyhedron",MESH:"Trimesh"};e.exports=a.mesh2shape=function(t,e){var i;if((e=e||{}).type===c.BOX)return n(t);if(e.type===c.CYLINDER)return function(t,e){var i,o,n,s=new THREE.Box3,r=["x","y","z"],l=e.cylinderAxis||"y",c=r.splice(r.indexOf(l),1)&&r;return s.setFromObject(t),isFinite(s.min.lengthSq())?(o=s.max[l]-s.min[l],n=.5*Math.max(s.max[c[0]]-s.min[c[0]],s.max[c[1]]-s.min[c[1]]),i=new a.Cylinder(n,n,o,12),i._type=a.Shape.types.CYLINDER,i.radiusTop=n,i.radiusBottom=n,i.height=o,i.numSegments=12,i.orientation=new a.Quaternion,i.orientation.setFromEuler("y"===l?h:0,"z"===l?h:0,0,"XYZ").normalize(),i):null}(t,e);if(e.type===c.SPHERE)return function(t,e){if(e.sphereRadius)return new a.Sphere(e.sphereRadius);var i=s(t);return i?(i.computeBoundingSphere(),new a.Sphere(i.boundingSphere.radius)):null}(t,e);if(e.type===c.HULL)return function(t){var e,i,o,n,r=s(t);if(!r||!r.vertices.length)return null;for(e=0;e<r.vertices.length;e++)r.vertices[e].x+=1e-4*(Math.random()-.5),r.vertices[e].y+=1e-4*(Math.random()-.5),r.vertices[e].z+=1e-4*(Math.random()-.5);for(n=l(r),i=new Array(n.vertices.length),e=0;e<n.vertices.length;e++)i[e]=new a.Vec3(n.vertices[e].x,n.vertices[e].y,n.vertices[e].z);for(o=new Array(n.faces.length),e=0;e<n.faces.length;e++)o[e]=[n.faces[e].a,n.faces[e].b,n.faces[e].c];return new a.ConvexPolyhedron(i,o)}(t);if(e.type===c.MESH)return(i=s(t))?function(t){var e,i=r(t);return i.length?(e=Object.keys(i).map(Number),new a.Trimesh(i,e)):null}(i):null;if(e.type)throw new Error('[CANNON.mesh2shape] Invalid type "%s".',e.type);if(!(i=s(t)))return null;switch(i.metadata?i.metadata.type:i.type){case"BoxGeometry":case"BoxBufferGeometry":return o(i);case"CylinderGeometry":case"CylinderBufferGeometry":return function(t){var e,i=t.metadata?t.metadata.parameters:t.parameters;return e=new a.Cylinder(i.radiusTop,i.radiusBottom,i.height,i.radialSegments),e._type=a.Shape.types.CYLINDER,e.radiusTop=i.radiusTop,e.radiusBottom=i.radiusBottom,e.height=i.height,e.numSegments=i.radialSegments,e.orientation=new a.Quaternion,e.orientation.setFromEuler(THREE.Math.degToRad(-90),0,0,"XYZ").normalize(),e}(i);case"PlaneGeometry":case"PlaneBufferGeometry":return function(t){t.computeBoundingBox();var e=t.boundingBox;return new a.Box(new a.Vec3((e.max.x-e.min.x)/2||.1,(e.max.y-e.min.y)/2||.1,(e.max.z-e.min.z)/2||.1))}(i);case"SphereGeometry":case"SphereBufferGeometry":return function(t){var e=t.metadata?t.metadata.parameters:t.parameters;return new a.Sphere(e.radius)}(i);case"TubeGeometry":case"Geometry":case"BufferGeometry":return n(t);default:return console.warn('Unrecognized geometry: "%s". Using bounding box as shape.',i.type),o(i)}},a.mesh2shape.Type=c},{"./lib/THREE.quickhull":85,cannon:23}],85:[function(t,e,i){e.exports=function(){function t(t){for(;S.length>0;)!function(t,o){var n,s=T.length,r=[t],a=o.indexOf(t.visiblePoints.pop());for(;s-- >0;)(n=T[s])!==t&&e(n,o).dot(w.subVectors(o[a],o[n[0]]))>0&&r.push(n);var l,h,c,u,p=s=r.length,d=1===s,f=[],v=0,m=[];r[0][0],r[0][1],r[0][1],r[0][2],r[0][2],r[0][0];if(1===r.length)n=r[0],f=[n[0],n[1],n[1],n[2],n[2],n[0]],S.indexOf(n)>-1&&S.splice(S.indexOf(n),1),n.visiblePoints&&(m=m.concat(n.visiblePoints)),T.splice(T.indexOf(n),1);else for(;s-- >0;){n=r[s],S.indexOf(n)>-1&&S.splice(S.indexOf(n),1),n.visiblePoints&&(m=m.concat(n.visiblePoints)),T.splice(T.indexOf(n),1);var y;for(cEdgeIndex=0;cEdgeIndex<3;){for(y=!1,p=r.length,c=n[cEdgeIndex],u=n[(cEdgeIndex+1)%3];p-- >0&&!y;)if(l=r[p],v=0,l!==n)for(;v<3&&!y;)h=v+1,y=l[v]===c&&l[h%3]===u||l[v]===u&&l[h%3]===c,v++;y&&!d||(f.push(c),f.push(u)),cEdgeIndex++}}s=0;var g,b=f.length/2;for(;s<b;)i(g=[f[2*s+1],a,f[2*s]],m,o),T.push(g),void 0!==g.visiblePoints&&S.push(g),s++}(S.shift(),t)}function e(t,e){if(void 0!==t.normal)return t.normal;var i=e[t[0]],o=e[t[1]],n=e[t[2]];return d.subVectors(o,i),f.subVectors(n,i),g.crossVectors(f,d),g.normalize(),t.normal=g.clone()}function i(t,i,o){var n=o[t[0]],s=[],r=e(t,o);i.sort(function(t,e){return s[t.x/3]=void 0!==s[t.x/3]?s[t.x/3]:r.dot(m.subVectors(t,n)),s[e.x/3]=void 0!==s[e.x/3]?s[e.x/3]:r.dot(y.subVectors(e,n)),s[t.x/3]-s[e.x/3]});var a=i.length;for(1===a&&(s[i[0].x/3]=r.dot(m.subVectors(i[0],n)));a-- >0&&s[i[a].x/3]>0;);a+1<i.length&&s[i[a+1].x/3]>0&&(t.visiblePoints=i.splice(a+1))}var o,n,s,r,a,l,h,c,u,p,d,f,v,m,y,g,w,b,x,E,T=[],S=[],C=0,A=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()}}(),R=function(){var t=new THREE.Vector3,e=new THREE.Vector3,i=new THREE.Vector3;return function(o,n,s){t.subVectors(n,o),e.subVectors(s,o),i.subVectors(s,n);var r=e.dot(t);if(r<0)return e.dot(e);var a=t.dot(t);return r>=a?i.dot(i):e.dot(e)-r*r/a}}();return function(e){for(d=new THREE.Vector3,f=new THREE.Vector3,v=new THREE.Vector3,m=new THREE.Vector3,y=new THREE.Vector3,g=new THREE.Vector3,w=new THREE.Vector3,b=new THREE.Vector3,x=new THREE.Vector3,E=new THREE.Vector3,points=e.vertices,T=[],S=[],I=o=points.length,n=points.slice(0,6),C=0;I-- >0;)points[I].x<n[0].x&&(n[0]=points[I]),points[I].x>n[1].x&&(n[1]=points[I]),points[I].y<n[2].y&&(n[2]=points[I]),points[I].y<n[3].y&&(n[3]=points[I]),points[I].z<n[4].z&&(n[4]=points[I]),points[I].z<n[5].z&&(n[5]=points[I]);for(r=I=6;I-- >0;)for(r=I-1;r-- >0;)C<(s=n[I].distanceToSquared(n[r]))&&(C=s,a=n[I],l=n[r]);for(I=6,C=0;I-- >0;)s=R(a,l,n[I]),C<s&&(C=s,h=n[I]);for(u=A(a,l,h),p=u.dot(a),C=0,I=o;I-- >0;)s=Math.abs(points[I].dot(u)-p),C<s&&(C=s,c=points[I]);var M=points.indexOf(a),B=points.indexOf(l),z=points.indexOf(h),k=points.indexOf(c),L=[[z,B,M],[B,k,M],[z,k,B],[M,k,z]];b.subVectors(l,a).normalize(),x.subVectors(h,a).normalize(),E.subVectors(c,a).normalize();E.dot((new THREE.Vector3).crossVectors(x,b))<0&&(L[0].reverse(),L[1].reverse(),L[2].reverse(),L[3].reverse());var P=points.slice();P.splice(P.indexOf(a),1),P.splice(P.indexOf(l),1),P.splice(P.indexOf(h),1),P.splice(P.indexOf(c),1);for(var I=L.length;I-- >0;)i(L[I],P,points),void 0!==L[I].visiblePoints&&S.push(L[I]),T.push(L[I]);t(points);for(var N=T.length;N-- >0;)e.faces[N]=new THREE.Face3(T[N][2],T[N][1],T[N][0],T[N].normal);return e.normalsNeedUpdate=!0,e}}()},{}],86:[function(t,e,i){e.exports={schema:{enabled:{default:!0},mode:{default:"teleport",oneOf:["teleport","animate"]},animateSpeed:{default:3}},init:function(){this.active=!0,this.checkpoint=null,this.offset=new THREE.Vector3,this.position=new THREE.Vector3,this.targetPosition=new THREE.Vector3},play:function(){this.active=!0},pause:function(){this.active=!1},setCheckpoint:function(t){var e=this.el;this.active&&this.checkpoint!==t&&(this.checkpoint&&e.emit("navigation-end",{checkpoint:this.checkpoint}),this.checkpoint=t,this.sync(),this.position.distanceTo(this.targetPosition)<.1?this.checkpoint=null:(e.emit("navigation-start",{checkpoint:t}),"teleport"===this.data.mode&&(this.el.setAttribute("position",this.targetPosition),this.checkpoint=null,e.emit("navigation-end",{checkpoint:t}))))},isVelocityActive:function(){return!(!this.active||!this.checkpoint)},getVelocity:function(){if(this.active){var t=this.data,e=this.offset,i=this.position,o=this.targetPosition,n=this.checkpoint;return this.sync(),i.distanceTo(o)<.1?(this.checkpoint=null,this.el.emit("navigation-end",{checkpoint:n}),e.set(0,0,0)):(e.setLength(t.animateSpeed),e)}},sync:function(){var t=this.offset,e=this.position,i=this.targetPosition;e.copy(this.el.getAttribute("position")),i.copy(this.checkpoint.object3D.getWorldPosition()),i.add(this.checkpoint.components.checkpoint.getOffset()),t.copy(i).sub(e)}}},{}],87:[function(t,e,i){var o=t("../../lib/GamepadButton"),n=t("../../lib/GamepadButtonEvent");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)>.2||Math.abs(o)>.2},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)>.2&&(n.x+=i),Math.abs(o)>.2&&(n.z+=o),n},isRotationActive:function(){if(!this.data.enabled||!this.isConnected())return!1;var t=this.getJoystick(1);return Math.abs(t.x)>.2||Math.abs(t.y)>.2},getRotationDelta:function(){var t=this.getJoystick(1);return Math.abs(t.x)<=.2&&(t.x=0),Math.abs(t.y)<=.2&&(t.y=0),t},updateButtonState:function(){var t=this.getGamepad();if(this.data.enabled&&t)for(var e=0;e<t.buttons.length;e++)t.buttons[e].pressed&&!this.buttons[e]?this.emit(new n("gamepadbuttondown",e,t.buttons[e])):!t.buttons[e].pressed&&this.buttons[e]&&this.emit(new n("gamepadbuttonup",e,t.buttons[e])),this.buttons[e]=t.buttons[e].pressed;else Object.keys(this.buttons)&&(this.buttons={})},emit:function(t){this.el.emit(t.type,t),this.el.emit(t.type+":"+t.index,new n(t.type,t.index,t))},getGamepad:function(){var t=navigator.getGamepads&&navigator.getGamepads()[this.data.controller],e=this.el.sceneEl.components["proxy-controls"];return e&&e.isConnected()&&e.getGamepad(this.data.controller)||t},getButton:function(t){return this.getGamepad().buttons[t]},getAxis:function(t){return this.getGamepad().axes[t]},getJoystick:function(t){var e=this.getGamepad();switch(t){case 0:return new THREE.Vector2(e.axes[0],e.axes[1]);case 1:return new THREE.Vector2(e.axes[2],e.axes[3]);default:throw new Error('Unexpected joystick index "%d".',t)}},getDpad:function(){var t=this.getGamepad();return t.buttons[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}],88:[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}}},{}],89:[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":86,"./gamepad-controls":87,"./hmd-controls":88,"./keyboard-controls":90,"./mouse-controls":91,"./touch-controls":92,"./universal-controls":93,"aframe-physics-system":11}],90:[function(t,e,i){t("../../lib/keyboard.polyfill");var o=window.KeyboardEvent;e.exports={schema:{enabled:{default:!0},debug:{default:!1}},init:function(){this.dVelocity=new THREE.Vector3,this.localKeys={},this.listeners={keydown:this.onKeyDown.bind(this),keyup:this.onKeyUp.bind(this),blur:this.onBlur.bind(this)},this.attachEventListeners()},isVelocityActive:function(){return this.data.enabled&&!!Object.keys(this.getKeys()).length},getVelocityDelta:function(){var t=this.data,e=this.getKeys();return this.dVelocity.set(0,0,0),t.enabled&&((e.KeyW||e.ArrowUp)&&(this.dVelocity.z-=1),(e.KeyA||e.ArrowLeft)&&(this.dVelocity.x-=1),(e.KeyS||e.ArrowDown)&&(this.dVelocity.z+=1),(e.KeyD||e.ArrowRight)&&(this.dVelocity.x+=1)),this.dVelocity.clone()},play:function(){this.attachEventListeners()},pause:function(){this.removeEventListeners()},remove:function(){this.pause()},attachEventListeners:function(){window.addEventListener("keydown",this.listeners.keydown,!1),window.addEventListener("keyup",this.listeners.keyup,!1),window.addEventListener("blur",this.listeners.blur,!1)},removeEventListeners:function(){window.removeEventListener("keydown",this.listeners.keydown),window.removeEventListener("keyup",this.listeners.keyup),window.removeEventListener("blur",this.listeners.blur)},onKeyDown:function(t){AFRAME.utils.shouldCaptureKeyEvent(t)&&(this.localKeys[t.code]=!0,this.emit(t))},onKeyUp:function(t){AFRAME.utils.shouldCaptureKeyEvent(t)&&(delete this.localKeys[t.code],this.emit(t))},onBlur:function(){for(var t in this.localKeys)this.localKeys.hasOwnProperty(t)&&delete this.localKeys[t]},emit:function(t){"__keyboard-controls-proxy"in t&&this.el.emit(t.type,t),this.el.emit(t.type+":"+t.code,new o(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":10}],91:[function(t,e,i){document.exitPointerLock=document.exitPointerLock||document.mozExitPointerLock,e.exports={schema:{enabled:{default:!0},pointerlockEnabled:{default:!0},sensitivity:{default:.04}},init:function(){this.mouseDown=!1,this.pointerLocked=!1,this.lookVector=new THREE.Vector2,this.bindMethods()},update:function(t){var e=this.data;t.pointerlockEnabled&&!e.pointerlockEnabled&&this.pointerLocked&&document.exitPointerLock()},play:function(){this.addEventListeners()},pause:function(){this.removeEventListeners(),this.lookVector.set(0,0)},remove:function(){this.pause()},bindMethods:function(){this.onMouseDown=this.onMouseDown.bind(this),this.onMouseMove=this.onMouseMove.bind(this),this.onMouseUp=this.onMouseUp.bind(this),this.onMouseUp=this.onMouseUp.bind(this),this.onPointerLockChange=this.onPointerLockChange.bind(this),this.onPointerLockChange=this.onPointerLockChange.bind(this),this.onPointerLockChange=this.onPointerLockChange.bind(this)},addEventListeners:function(){var t=this.el.sceneEl,e=t.canvas,i=this.data;e?(e.addEventListener("mousedown",this.onMouseDown,!1),e.addEventListener("mousemove",this.onMouseMove,!1),e.addEventListener("mouseup",this.onMouseUp,!1),e.addEventListener("mouseout",this.onMouseUp,!1),i.pointerlockEnabled&&(document.addEventListener("pointerlockchange",this.onPointerLockChange,!1),document.addEventListener("mozpointerlockchange",this.onPointerLockChange,!1),document.addEventListener("pointerlockerror",this.onPointerLockError,!1))):t.addEventListener("render-target-loaded",this.addEventListeners.bind(this))},removeEventListeners:function(){var t=this.el.sceneEl&&this.el.sceneEl.canvas;t&&(t.removeEventListener("mousedown",this.onMouseDown,!1),t.removeEventListener("mousemove",this.onMouseMove,!1),t.removeEventListener("mouseup",this.onMouseUp,!1),t.removeEventListener("mouseout",this.onMouseUp,!1)),document.removeEventListener("pointerlockchange",this.onPointerLockChange,!1),document.removeEventListener("mozpointerlockchange",this.onPointerLockChange,!1),document.removeEventListener("pointerlockerror",this.onPointerLockError,!1)},isRotationActive:function(){return this.data.enabled&&(this.mouseDown||this.pointerLocked)},getRotationDelta:function(){var t=this.lookVector.clone().multiplyScalar(this.data.sensitivity);return this.lookVector.set(0,0),t},onMouseMove:function(t){var e=this.previousMouseEvent;if(this.data.enabled&&(this.mouseDown||this.pointerLocked)){var 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}}},{}],92:[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;e?(e.addEventListener("touchstart",this.onTouchStart),e.addEventListener("touchend",this.onTouchEnd)):t.addEventListener("render-target-loaded",this.addEventListeners.bind(this))},removeEventListeners:function(){var t=this.el.sceneEl&&this.el.sceneEl.canvas;t&&(t.removeEventListener("touchstart",this.onTouchStart),t.removeEventListener("touchend",this.onTouchEnd))},isVelocityActive:function(){return this.data.enabled&&this.isMoving},getVelocityDelta:function(){return this.dVelocity.z=this.isMoving?-1:0,this.dVelocity.clone()},bindMethods:function(){this.onTouchStart=this.onTouchStart.bind(this),this.onTouchEnd=this.onTouchEnd.bind(this)},onTouchStart:function(t){this.isMoving=!0,t.preventDefault()},onTouchEnd:function(t){this.isMoving=!1,t.preventDefault()}}},{}],93:[function(t,e,i){var o=Math.PI/2;e.exports={dependencies:["velocity","rotation"],schema:{enabled:{default:!0},movementEnabled:{default:!0},movementControls:{default:["gamepad","keyboard","touch","hmd"]},rotationEnabled:{default:!0},rotationControls:{default:["hmd","gamepad","mouse"]},movementSpeed:{default:5},movementEasing:{default:15},movementEasingY:{default:0},movementAcceleration:{default:80},rotationSensitivity:{default:.05},fly:{default:!1}},init:function(){var t=this.el.getAttribute("rotation");this.el.hasAttribute("look-controls")&&this.data.rotationEnabled&&console.error("[universal-controls] The `universal-controls` component is a replacement for `look-controls`, and cannot be used in combination with it."),this.velocity=new THREE.Vector3,this.pitch=new THREE.Object3D,this.pitch.rotation.x=THREE.Math.degToRad(t.x),this.yaw=new THREE.Object3D,this.yaw.position.y=10,this.yaw.rotation.y=THREE.Math.degToRad(t.y),this.yaw.add(this.pitch),this.heading=new THREE.Euler(0,0,0,"YXZ"),this.el.sceneEl.hasLoaded?this.injectControls():this.el.sceneEl.addEventListener("loaded",this.injectControls.bind(this))},update:function(){this.el.sceneEl.hasLoaded&&this.injectControls()},injectControls:function(){var t,e,i=this.data;for(t=0;t<i.movementControls.length;t++)e=i.movementControls[t]+"-controls",this.el.components[e]||this.el.setAttribute(e,"");for(t=0;t<i.rotationControls.length;t++)e=i.rotationControls[t]+"-controls",this.el.components[e]||this.el.setAttribute(e,"")},tick:function(t,e){e&&(this.data.rotationEnabled&&this.updateRotation(e),this.data.movementEnabled&&e/1e3>.2?(this.velocity.set(0,0,0),this.el.setAttribute("velocity",this.velocity)):this.updateVelocity(e))},updateRotation:function(t){for(var e,i,n=this.data,s=0,r=n.rotationControls.length;s<r;s++)if((e=this.el.components[n.rotationControls[s]+"-controls"])&&e.isRotationActive()){if(e.getRotationDelta)(i=e.getRotationDelta(t)).multiplyScalar(n.rotationSensitivity),this.yaw.rotation.y-=i.x,this.pitch.rotation.x-=i.y,this.pitch.rotation.x=Math.max(-o,Math.min(o,this.pitch.rotation.x)),this.el.setAttribute("rotation",{x:THREE.Math.radToDeg(this.pitch.rotation.x),y:THREE.Math.radToDeg(this.yaw.rotation.y),z:0});else{if(!e.getRotation)throw new Error("Incompatible rotation controls: %s",n.rotationControls[s]);this.el.setAttribute("rotation",e.getRotation())}break}},updateVelocity:function(t){var e,i,o=this.velocity,n=this.data;if(n.movementEnabled)for(var s=0,r=n.movementControls.length;s<r;s++)if((e=this.el.components[n.movementControls[s]+"-controls"])&&e.isVelocityActive()){if(!e.getVelocityDelta){if(e.getVelocity)return void this.el.setAttribute("velocity",e.getVelocity());if(e.getPositionDelta)return o.copy(e.getPositionDelta(t).multiplyScalar(1e3/t)),void this.el.setAttribute("velocity",o);throw new Error("Incompatible movement controls: ",n.movementControls[s])}i=e.getVelocityDelta(t);break}if(o.copy(this.el.getAttribute("velocity")),o.x-=o.x*n.movementEasing*t/1e3,o.y-=o.y*n.movementEasingY*t/1e3,o.z-=o.z*n.movementEasing*t/1e3,i&&n.movementEnabled){i.length()>1?i.setLength(this.data.movementAcceleration*t/1e3):i.multiplyScalar(this.data.movementAcceleration*t/1e3);var a=this.el.getAttribute("rotation");a&&(this.heading.set(n.fly?THREE.Math.degToRad(a.x):0,THREE.Math.degToRad(a.y),0),i.applyEuler(this.heading)),o.add(i)}this.el.setAttribute("velocity",o)}}},{}],94:[function(t,e,i){function o(t){return t.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&")}var n={once:THREE.LoopOnce,repeat:THREE.LoopRepeat,pingpong:THREE.LoopPingPong};e.exports={schema:{clip:{default:"*"},duration:{default:0},crossFadeDuration:{default:0},loop:{default:"repeat",oneOf:Object.keys(n)},repetitions:{default:1/0,min:0}},init:function(){this.model=null,this.mixer=null,this.activeActions=[];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){var e=this.el;this.model=t,this.mixer=new THREE.AnimationMixer(t),this.mixer.addEventListener("loop",function(t){e.emit("animation-loop",{action:t.action,loopDelta:t.loopDelta})}.bind(this)),this.mixer.addEventListener("finished",function(t){e.emit("animation-finished",{action:t.action,direction:t.direction})}.bind(this)),this.data.clip&&this.update({})},remove:function(){this.mixer&&this.mixer.stopAllAction()},update:function(t){t&&(this.stopAction(),this.data.clip&&this.playAction())},stopAction:function(){for(var t=this.data,e=0;e<this.activeActions.length;e++)t.crossFadeDuration?this.activeActions[e].fadeOut(t.crossFadeDuration):this.activeActions[e].stop();this.activeActions.length=0},playAction:function(){if(this.mixer){var t=this.model,e=this.data,i=t.animations||(t.geometry||{}).animations||[];if(i.length)for(var s,r=function(t){return new RegExp("^"+t.split(/\*+/).map(o).join(".*")+"$")}(e.clip),a=0;s=i[a];a++)if(s.name.match(r)){var l=this.mixer.clipAction(s,t);l.enabled=!0,e.duration&&l.setDuration(e.duration),l.setLoop(n[e.loop],e.repetitions).fadeIn(e.crossFadeDuration).play(),this.activeActions.push(l)}}},tick:function(t,e){this.mixer&&!isNaN(e)&&this.mixer.update(e/1e3)}}},{}],95:[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}],96:[function(t,e,i){var o=t("../../lib/fetch-script")();e.exports={schema:{type:"model"},init:function(){this.model=null,this.loader=null,this.loaderPromise=n().then(function(){this.loader=new THREE.GLTFLoader,this.loader.setCrossOrigin("Anonymous")}.bind(this))},update:function(){var t=this,e=this.el,i=this.data;i&&(this.remove(),this.loaderPromise.then(function(){this.loader.load(i,function(i){t.model=i.scene,t.model.animations=i.animations,e.setObject3D("mesh",t.model),e.emit("model-loaded",{format:"gltf",model:t.model})})}.bind(this)))},remove:function(){this.model&&this.el.removeObject3D("mesh")}};var n=function(){var t;return function(){return t=t||o("https://rawgit.com/mrdoob/three.js/r86/examples/js/loaders/GLTFLoader.js")}}()},{"../../lib/fetch-script":8}],97:[function(t,e,i){e.exports={"animation-mixer":t("./animation-mixer"),"fbx-model":t("./fbx-model"),"gltf-model-legacy":t("./gltf-model-legacy"),"json-model":t("./json-model"),"object-model":t("./object-model"),"ply-model":t("./ply-model"),registerAll:function(t){this._registered||((t=t||window.AFRAME).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["gltf-model-legacy"]||t.registerComponent("gltf-model-legacy",this["gltf-model-legacy"]),t.components["json-model"]||t.registerComponent("json-model",this["json-model"]),t.components["object-model"]||t.registerComponent("object-model",this["object-model"]),this._registered=!0)}}},{"./animation-mixer":94,"./fbx-model":95,"./gltf-model-legacy":96,"./json-model":98,"./object-model":99,"./ply-model":100}],98:[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")}}},{}],99:[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")}}},{}],100:[function(t,e,i){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){(new THREE.PLYLoader).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;t.src?this.system.getOrLoadGeometry(t.src,t.skipCache).then(function(t){var i=function(t){return new THREE.Mesh(t,new THREE.MeshPhongMaterial({color:16777215,shading:THREE.FlatShading,vertexColors:THREE.VertexColors,shininess:0}))}(t);e.setObject3D("mesh",i),e.emit("model-loaded",{format:"ply",model:i})}):console.warn("[%s] `src` property is required.",this.name)},remove:function(){this.model&&this.el.removeObject3D("mesh")}}},{"../../lib/PLYLoader":6}],101:[function(t,e,i){e.exports={schema:{offset:{default:{x:0,y:0,z:0},type:"vec3"}},init:function(){this.active=!1,this.targetEl=null,this.fire=this.fire.bind(this),this.offset=new THREE.Vector3},update:function(){this.offset.copy(this.data.offset)},play:function(){this.el.addEventListener("click",this.fire)},pause:function(){this.el.removeEventListener("click",this.fire)},remove:function(){this.pause()},fire:function(){var t=this.el.sceneEl.querySelector("[checkpoint-controls]");if(!t)throw new Error("No `checkpoint-controls` component found.");t.components["checkpoint-controls"].setCheckpoint(this.el)},getOffset:function(){return this.offset.copy(this.data.offset)}}},{}],102:[function(t,e,i){e.exports={schema:{path:{default:""},extension:{default:"jpg"},format:{default:"RGBFormat"},enableBackground:{default:!1}},init:function(){var t=this.data;this.texture=(new THREE.CubeTextureLoader).load([t.path+"posx."+t.extension,t.path+"negx."+t.extension,t.path+"posy."+t.extension,t.path+"negy."+t.extension,t.path+"posz."+t.extension,t.path+"negz."+t.extension]),this.texture.format=THREE[t.format],t.enableBackground&&(this.el.sceneEl.object3D.background=this.texture),this.applyEnvMap(),this.el.addEventListener("object3dset",this.applyEnvMap.bind(this))},applyEnvMap:function(){var t=this.el.getObject3D("mesh"),e=this.texture;t&&t.traverse(function(t){t.material&&"envMap"in t.material&&(t.material.envMap=e,t.material.needsUpdate=!0)})}}},{}],103:[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))}}},{}],104:[function(t,e,i){var o=t("aframe-physics-system");e.exports={checkpoint:t("./checkpoint"),"cube-env-map":t("./cube-env-map"),grab:t("./grab"),"jump-ability":t("./jump-ability"),"kinematic-body":t("./kinematic-body"),"mesh-smooth":t("./mesh-smooth"),"sphere-collider":t("./sphere-collider"),"toggle-velocity":t("./toggle-velocity"),registerAll:function(t){this._registered||(t=t||window.AFRAME,o.registerAll(),t.components.checkpoint||t.registerComponent("checkpoint",this.checkpoint),t.components["cube-env-map"]||t.registerComponent("cube-env-map",this["cube-env-map"]),t.components.grab||t.registerComponent("grab",this.grab),t.components["jump-ability"]||t.registerComponent("jump-ability",this["jump-ability"]),t.components["kinematic-body"]||t.registerComponent("kinematic-body",this["kinematic-body"]),t.components["mesh-smooth"]||t.registerComponent("mesh-smooth",this["mesh-smooth"]),t.components["sphere-collider"]||t.registerComponent("sphere-collider",this["sphere-collider"]),t.components["toggle-velocity"]||t.registerComponent("toggle-velocity",this["toggle-velocity"]),this._registered=!0)}}},{"./checkpoint":101,"./cube-env-map":102,"./grab":103,"./jump-ability":105,"./kinematic-body":106,"./mesh-smooth":107,"./sphere-collider":108,"./toggle-velocity":109,"aframe-physics-system":11}],105:[function(t,e,i){e.exports={dependencies:["velocity"],schema:{on:{default:"keydown:Space gamepadbuttondown:0"},playerHeight:{default:1.764},maxJumps:{default:1},distance:{default:5},soundJump:{default:""},soundLand:{default:""},debug:{default:!1}},init:function(){this.velocity=0,this.numJumps=0;var t=this.beginJump.bind(this),e=this.data.on.split(" ");this.bindings={};for(var i=0;i<e.length;i++)this.bindings[e[i]]=t,this.el.addEventListener(e[i],t);this.bindings.collide=this.onCollide.bind(this),this.el.addEventListener("collide",this.bindings.collide)},remove:function(){for(var t in this.bindings)this.bindings.hasOwnProperty(t)&&(this.el.removeEventListener(t,this.bindings[t]),delete this.bindings[t]);this.el.removeEventListener("collide",this.bindings.collide),delete this.bindings.collide},beginJump:function(){if(this.numJumps<this.data.maxJumps){var t=this.data,e=Math.sqrt(-2*t.distance*-24.8),i=this.el.getAttribute("velocity");this.el.setAttribute("velocity",{x:i.x,y:e,z:i.z}),this.numJumps++}},onCollide:function(){this.numJumps=0}}},{}],106:[function(t,e,i){var o=window.CANNON;e.exports={dependencies:["velocity"],schema:{mass:{default:5},radius:{default:1.3},height:{default:1.764},linearDamping:{default:.05},enableSlopes:{default:!0}},init:function(){this.system=this.el.sceneEl.systems.physics,this.system.addBehavior(this,this.system.Phase.SIMULATE);var t=this.el,e=this.data,i=(new o.Vec3).copy(t.getAttribute("position"));this.body=new o.Body({material:this.system.material,position:i,mass:e.mass,linearDamping:e.linearDamping,fixedRotation:!0}),this.body.addShape(new o.Sphere(e.radius),new o.Vec3(0,e.radius-e.height,0)),this.body.el=this.el,this.el.body=this.body,this.system.addBody(this.body)},remove:function(){this.system.removeBody(this.body),this.system.removeBehavior(this,this.system.Phase.SIMULATE),delete this.el.body},step:function(){var t=new THREE.Vector3,e=new THREE.Vector3,i=new THREE.Vector3,o=new THREE.Vector3;return function(n,s){if(s){var r,a,l=this.body,h=this.data,c=-1/0;s=Math.min(s,1e3*this.system.data.maxInterval),o.set(0,0,0),t.copy(this.el.getAttribute("velocity")),l.velocity.copy(t),l.position.copy(this.el.getAttribute("position"));for(var u,p=0;u=this.system.world.contacts[p];p++)if(u.enabled){if(l.id===u.bi.id)u.ni.negate(i);else{if(l.id!==u.bj.id)continue;i.copy(u.ni)}l.velocity.dot(i)<-1e-6&&i.y<=.5?t=t.projectOnPlane(i):i.y>.5&&(r=l.id===u.bi.id?Math.abs(u.rj.y+u.bj.position.y):Math.abs(u.ri.y+u.bi.position.y))>c&&(c=r,o.copy(i),a=l.id===u.bi.id?u.bj:u.bi)}if(e.copy(t).normalize(),a&&e.y<.5?(h.enableSlopes?o.y<1-1e-6&&o.copy(this.raycastToGround(a,o)):o.set(0,1,0),t=t.projectOnPlane(o)):t.add(this.system.world.gravity.scale(4*s/1e3)),a&&a.el&&a.el.components.velocity){var d=a.el.getAttribute("velocity");l.position.copy({x:l.position.x+d.x*s/1e3,y:l.position.y+d.y*s/1e3,z:l.position.z+d.z*s/1e3}),this.el.setAttribute("position",l.position)}l.velocity.copy(t),this.el.setAttribute("velocity",t)}}}(),raycastToGround:function(t,e){var i,n,s=this.body.position,r=this.body.position.clone();return r.y-=this.data.height,(i=new o.Ray(s,r))._updateDirection(),i.intersectBody(t),i.hasHit?(n=i.result.hitNormalWorld,Math.abs(n.y)>Math.abs(e.y)?n:e):e}}},{}],107:[function(t,e,i){e.exports={init:function(){this.el.addEventListener("model-loaded",function(t){t.detail.model.traverse(function(t){t.isMesh&&t.geometry.computeVertexNormals()})})}}},{}],108:[function(t,e,i){e.exports={schema:{objects:{default:""},state:{default:"collided"},radius:{default:.05},watch:{default:!0}},init:function(){this.observer=null,this.els=[],this.collisions=[],this.handleHit=this.handleHit.bind(this),this.handleHitEnd=this.handleHitEnd.bind(this)},remove:function(){this.pause()},play:function(){var t=this.el.sceneEl;this.data.watch&&(this.observer=new MutationObserver(this.update.bind(this,null)),this.observer.observe(t,{childList:!0,subtree:!0}))},pause:function(){this.observer&&(this.observer.disconnect(),this.observer=null)},update:function(){var t,e=this.data;t=e.objects?this.el.sceneEl.querySelectorAll(e.objects):this.el.sceneEl.children,this.els=Array.prototype.slice.call(t)},tick:function(){var t=new THREE.Vector3,e=new THREE.Vector3,i=(new THREE.Vector3,new THREE.Vector3),o=new Map;return function(){var n,s=this.el,r=this.data,a=[];s.getObject3D("mesh")&&(o.clear(),t.copy(s.object3D.getWorldPosition()),s.object3D.getWorldScale(i),n=r.radius*function(t){return Math.max.apply(null,t.toArray())}(i),this.els.forEach(function(i){var s,r,l,h,c,u;i.isEntity&&(r=i.getObject3D("mesh"))&&(u=(h=(new THREE.Box3).setFromObject(r)).getSize(),c=Math.max(u.x,u.y,u.z)/2,s=Math.sqrt(2*c*c),h.getCenter(e),s&&(l=t.distanceTo(e))<s+n&&(a.push(i),o.set(i,l)))}),a.sort(function(t,e){return o.get(t)>o.get(e)?1:-1}).forEach(this.handleHit),0===a.length&&s.emit("hit",{el:null}),this.collisions.filter(function(t){return!o.has(t)}).forEach(this.handleHitEnd),this.collisions=a)}}(),handleHit:function(t){t.emit("hit"),t.addState(this.data.state),this.el.emit("hit",{el:t})},handleHitEnd:function(t){t.emit("hitend"),t.removeState(this.data.state),this.el.emit("hitend",{el:t})}}},{}],109:[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))}}},{}],110:[function(t,e,i){e.exports={"nav-mesh":t("./nav-mesh"),"nav-controller":t("./nav-controller"),system:t("./system"),registerAll:function(t){this._registered||((t=t||window.AFRAME).components["nav-mesh"]||t.registerComponent("nav-mesh",this["nav-mesh"]),t.components["nav-controller"]||t.registerComponent("nav-controller",this["nav-controller"]),t.systems.nav||t.registerSystem("nav",this.system),this._registered=!0)}}},{"./nav-controller":111,"./nav-mesh":112,"./system":113}],111:[function(t,e,i){e.exports={schema:{destination:{type:"vec3"},active:{default:!1},speed:{default:2}},init:function(){this.system=this.el.sceneEl.systems.nav,this.system.addController(this),this.path=[],this.raycaster=new THREE.Raycaster},remove:function(){this.system.removeController(this)},update:function(){this.path.length=0},tick:function(){var t=new THREE.Vector3,e=new THREE.Vector3,i=new THREE.Vector3;return function(o,n){var s=this.el,r=this.data,a=this.raycaster,l=r.speed*n/1e3;if(r.active){if(this.path.length||(this.path=this.system.getPath(this.el.object3D,t.copy(r.destination)),this.path=this.path||[],s.emit("nav-start")),!this.path.length)return console.warn("[nav] Unable to find path to %o.",r.destination),this.el.setAttribute("nav-controller",{active:!1}),void s.emit("nav-end");var h=s.object3D.position,c=this.path[0];e.subVectors(c,h);var u;if(e.length()<l){if(this.path.shift(),!this.path.length)return this.el.setAttribute("nav-controller",{active:!1}),void s.emit("nav-end");u=this.path[0]}else i.copy(e.setLength(l)).add(h),u=c;u.y=h.y,s.object3D.lookAt(u),a.ray.origin.copy(i),a.ray.origin.y+=1.5,a.ray.direction.y=-1;var p=a.intersectObject(this.system.getNavMesh());p.length?(e.subVectors(p[0].point,h),h.add(e.setLength(l))):h.copy(i)}}}()}},{}],112:[function(t,e,i){e.exports={init:function(){this.system=this.el.sceneEl.systems.nav,this.loadNavMesh(),this.el.addEventListener("model-loaded",this.loadNavMesh.bind(this))},loadNavMesh:function(){var t=this.el.getObject3D("mesh");if(t){var e;t.traverse(function(t){t.isMesh&&(e=t)}),e&&this.system.setNavMesh(e)}}}},{}],113:[function(t,e,i){var o=t("three-pathfinding");e.exports={init:function(){this.navMesh=null,this.nodes=null,this.controllers=new Set},setNavMesh:function(t){var e=t.geometry.isBufferGeometry?(new THREE.Geometry).fromBufferGeometry(t.geometry):t.geometry;this.navMesh=new THREE.Mesh(e),this.nodes=o.buildNodes(this.navMesh.geometry),o.setZoneData("level",this.nodes)},getNavMesh:function(){return this.navMesh},addController:function(t){this.controllers.add(t)},removeController:function(t){this.controllers.remove(t)},getPath:function(t,e){var i=t.el.object3D.position,n=o.getGroup("level",i);return o.findPath(i,e,"level",n)}}},{"three-pathfinding":82}],114:[function(t,e,i){var o=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"}};e.exports.registerAll=function(){var t=!1;return function(e){t||((e=e||window.AFRAME).registerPrimitive("a-grid",o),t=!0)}}()},{}],115:[function(t,e,i){var o=t("../../lib/hex-grid.min.js"),n=t("../../lib/default-hex-grid.json"),s=e.exports.Primitive={defaultComponents:{hexgrid:{}},mappings:{src:"hexgrid.src"}},r=e.exports.Component={dependencies:["material"],schema:{src:{type:"asset"}},init:function(){var t=this.data;t.src?fetch(t.src).then(function(t){t.json()}).then(function(t){this.addMesh(t)}):this.addMesh(n)},addMesh:function(t){var e=new o.HexGrid;e.fromJSON(t);var i=new o.Board(e);i.generateTilemap(),this.el.setObject3D("mesh",i.group),this.addMaterial()},addMaterial:function(){var t=(this.el.components.material||{}).material;t&&this.el.object3D.traverse(function(e){e.isMesh&&(e.material=t)})},remove:function(){this.el.removeObject3D("mesh")}};e.exports.registerAll=function(){var t=!1;return function(e){t||((e=e||window.AFRAME).registerComponent("hexgrid",r),e.registerPrimitive("a-hexgrid",s),t=!0)}}()},{"../../lib/default-hex-grid.json":7,"../../lib/hex-grid.min.js":9}],116:[function(t,e,i){var o=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"}},n=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={}).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}}};e.exports.registerAll=function(){var t=!1;return function(e){t||((e=e||window.AFRAME).registerComponent("ocean",n),e.registerPrimitive("a-ocean",o),t=!0)}}()},{}],117:[function(t,e,i){var o=e.exports.Primitive={defaultComponents:{tube:{}},mappings:{path:"tube.path",segments:"tube.segments",radius:"tube.radius",radialSegments:"tube.radialSegments",closed:"tube.closed"}},n=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){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={}).material=new THREE.MeshPhongMaterial),this.mesh=new THREE.Mesh(n,i.material),this.el.setObject3D("mesh",this.mesh)}else console.error("[a-tube] `path` property expected but not found.")},remove:function(){this.mesh&&this.el.removeObject3D("mesh")}};e.exports.registerAll=function(){var t=!1;return function(e){t||((e=e||window.AFRAME).registerComponent("tube",n),e.registerPrimitive("a-tube",o),t=!0)}}()},{}],118:[function(t,e,i){e.exports={"a-grid":t("./a-grid"),"a-hexgrid":t("./a-hexgrid"),"a-ocean":t("./a-ocean"),"a-tube":t("./a-tube"),registerAll:function(t){this._registered||(t=t||window.AFRAME,this["a-grid"].registerAll(t),this["a-hexgrid"].registerAll(t),this["a-ocean"].registerAll(t),this["a-tube"].registerAll(t),this._registered=!0)}}},{"./a-grid":114,"./a-hexgrid":115,"./a-ocean":116,"./a-tube":117}]},{},[1]);