UNPKG

aframe-physics-system

Version:

Physics system for A-Frame VR, built on Cannon.js

1 lines 293 kB
!function(){return function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){return o(e[i][1][r]||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}}()({1:[function(require,module,exports){var CANNON=require("cannon-es");require("./src/components/math"),require("./src/components/body/ammo-body"),require("./src/components/body/body"),require("./src/components/body/dynamic-body"),require("./src/components/body/static-body"),require("./src/components/shape/shape"),require("./src/components/shape/ammo-shape"),require("./src/components/ammo-constraint"),require("./src/components/constraint"),require("./src/components/spring"),require("./src/system"),module.exports={registerAll:function(){console.warn("registerAll() is deprecated. Components are automatically registered.")}},window.CANNON=window.CANNON||CANNON},{"./src/components/ammo-constraint":8,"./src/components/body/ammo-body":9,"./src/components/body/body":10,"./src/components/body/dynamic-body":11,"./src/components/body/static-body":12,"./src/components/constraint":13,"./src/components/math":14,"./src/components/shape/ammo-shape":16,"./src/components/shape/shape":17,"./src/components/spring":18,"./src/system":28,"cannon-es":4}],2:[function(require,module,exports){var CANNON=require("cannon-es");CANNON.shape2mesh=function(body){for(var obj=new THREE.Object3D,l=0;l<body.shapes.length;l++){var mesh,shape=body.shapes[l];switch(shape.type){case CANNON.Shape.types.SPHERE:var sphere_geometry=new THREE.SphereGeometry(shape.radius,8,8);mesh=new THREE.Mesh(sphere_geometry,this.currentMaterial);break;case CANNON.Shape.types.PARTICLE:mesh=new THREE.Mesh(this.particleGeo,this.particleMaterial);var s=this.settings;mesh.scale.set(s.particleSize,s.particleSize,s.particleSize);break;case CANNON.Shape.types.PLANE:var geometry=new THREE.PlaneGeometry(10,10,4,4);mesh=new THREE.Object3D;var submesh=new THREE.Object3D,ground=new THREE.Mesh(geometry,this.currentMaterial);ground.scale.set(100,100,100),submesh.add(ground),ground.castShadow=!0,ground.receiveShadow=!0,mesh.add(submesh);break;case CANNON.Shape.types.BOX:var box_geometry=new THREE.BoxGeometry(2*shape.halfExtents.x,2*shape.halfExtents.y,2*shape.halfExtents.z);mesh=new THREE.Mesh(box_geometry,this.currentMaterial);break;case CANNON.Shape.types.CONVEXPOLYHEDRON:for(var geo=new THREE.Geometry,i=0;i<shape.vertices.length;i++){var v=shape.vertices[i];geo.vertices.push(new THREE.Vector3(v.x,v.y,v.z))}for(i=0;i<shape.faces.length;i++)for(var face=shape.faces[i],a=face[0],j=1;j<face.length-1;j++){var b=face[j],c=face[j+1];geo.faces.push(new THREE.Face3(a,b,c))}geo.computeBoundingSphere(),geo.computeFaceNormals(),mesh=new THREE.Mesh(geo,this.currentMaterial);break;case CANNON.Shape.types.HEIGHTFIELD:geometry=new THREE.Geometry;for(var v0=new CANNON.Vec3,v1=new CANNON.Vec3,v2=new CANNON.Vec3,xi=0;xi<shape.data.length-1;xi++)for(var yi=0;yi<shape.data[xi].length-1;yi++)for(var k=0;k<2;k++){shape.getConvexTrianglePillar(xi,yi,0===k),v0.copy(shape.pillarConvex.vertices[0]),v1.copy(shape.pillarConvex.vertices[1]),v2.copy(shape.pillarConvex.vertices[2]),v0.vadd(shape.pillarOffset,v0),v1.vadd(shape.pillarOffset,v1),v2.vadd(shape.pillarOffset,v2),geometry.vertices.push(new THREE.Vector3(v0.x,v0.y,v0.z),new THREE.Vector3(v1.x,v1.y,v1.z),new THREE.Vector3(v2.x,v2.y,v2.z));i=geometry.vertices.length-3;geometry.faces.push(new THREE.Face3(i,i+1,i+2))}geometry.computeBoundingSphere(),geometry.computeFaceNormals(),mesh=new THREE.Mesh(geometry,this.currentMaterial);break;case CANNON.Shape.types.TRIMESH:for(geometry=new THREE.Geometry,v0=new CANNON.Vec3,v1=new CANNON.Vec3,v2=new CANNON.Vec3,i=0;i<shape.indices.length/3;i++){shape.getTriangleVertices(i,v0,v1,v2),geometry.vertices.push(new THREE.Vector3(v0.x,v0.y,v0.z),new THREE.Vector3(v1.x,v1.y,v1.z),new THREE.Vector3(v2.x,v2.y,v2.z));j=geometry.vertices.length-3;geometry.faces.push(new THREE.Face3(j,j+1,j+2))}geometry.computeBoundingSphere(),geometry.computeFaceNormals(),mesh=new THREE.Mesh(geometry,this.currentMaterial);break;default:throw"Visual type not recognized: "+shape.type}if(mesh.receiveShadow=!0,mesh.castShadow=!0,mesh.children)for(i=0;i<mesh.children.length;i++)if(mesh.children[i].castShadow=!0,mesh.children[i].receiveShadow=!0,mesh.children[i])for(j=0;j<mesh.children[i].length;j++)mesh.children[i].children[j].castShadow=!0,mesh.children[i].children[j].receiveShadow=!0;var o=body.shapeOffsets[l],q=body.shapeOrientations[l];mesh.position.set(o.x,o.y,o.z),mesh.quaternion.set(q.x,q.y,q.z,q.w),obj.add(mesh)}return obj},module.exports=CANNON.shape2mesh},{"cannon-es":4}],3:[function(require,module,exports){THREE.AmmoDebugConstants={NoDebug:0,DrawWireframe:1,DrawAabb:2,DrawFeaturesText:4,DrawContactPoints:8,NoDeactivation:16,NoHelpText:32,DrawText:64,ProfileTimings:128,EnableSatComparison:256,DisableBulletLCP:512,EnableCCD:1024,DrawConstraints:2048,DrawConstraintLimits:4096,FastWireframe:8192,DrawNormals:16384,DrawOnTop:32768,MAX_DEBUG_DRAW_MODE:4294967295},THREE.AmmoDebugDrawer=function(scene,world,options){this.scene=scene,this.world=world,options=options||{},this.debugDrawMode=options.debugDrawMode||THREE.AmmoDebugConstants.DrawWireframe;var drawOnTop=this.debugDrawMode&THREE.AmmoDebugConstants.DrawOnTop||!1,maxBufferSize=options.maxBufferSize||1e6;this.geometry=new THREE.BufferGeometry;var vertices=new Float32Array(3*maxBufferSize),colors=new Float32Array(3*maxBufferSize);this.geometry.setAttribute("position",new THREE.BufferAttribute(vertices,3).setUsage(THREE.DynamicDrawUsage)),this.geometry.setAttribute("color",new THREE.BufferAttribute(colors,3).setUsage(THREE.DynamicDrawUsage)),this.index=0;var material=new THREE.LineBasicMaterial({vertexColors:!0,depthTest:!drawOnTop});this.mesh=new THREE.LineSegments(this.geometry,material),drawOnTop&&(this.mesh.renderOrder=999),this.mesh.frustumCulled=!1,this.enabled=!1,this.debugDrawer=new Ammo.DebugDrawer,this.debugDrawer.drawLine=this.drawLine.bind(this),this.debugDrawer.drawContactPoint=this.drawContactPoint.bind(this),this.debugDrawer.reportErrorWarning=this.reportErrorWarning.bind(this),this.debugDrawer.draw3dText=this.draw3dText.bind(this),this.debugDrawer.setDebugMode=this.setDebugMode.bind(this),this.debugDrawer.getDebugMode=this.getDebugMode.bind(this),this.debugDrawer.enable=this.enable.bind(this),this.debugDrawer.disable=this.disable.bind(this),this.debugDrawer.update=this.update.bind(this),this.world.setDebugDrawer(this.debugDrawer)},THREE.AmmoDebugDrawer.prototype=function(){return this.debugDrawer},THREE.AmmoDebugDrawer.prototype.enable=function(){this.enabled=!0,this.scene.add(this.mesh)},THREE.AmmoDebugDrawer.prototype.disable=function(){this.enabled=!1,this.scene.remove(this.mesh)},THREE.AmmoDebugDrawer.prototype.update=function(){this.enabled&&(0!=this.index&&(this.geometry.attributes.position.needsUpdate=!0,this.geometry.attributes.color.needsUpdate=!0),this.index=0,this.world.debugDrawWorld(),this.geometry.setDrawRange(0,this.index))},THREE.AmmoDebugDrawer.prototype.drawLine=function(from,to,color){const heap=Ammo.HEAPF32,r=heap[(color+0)/4],g=heap[(color+4)/4],b=heap[(color+8)/4],fromX=heap[(from+0)/4],fromY=heap[(from+4)/4],fromZ=heap[(from+8)/4];this.geometry.attributes.position.setXYZ(this.index,fromX,fromY,fromZ),this.geometry.attributes.color.setXYZ(this.index++,r,g,b);const toX=heap[(to+0)/4],toY=heap[(to+4)/4],toZ=heap[(to+8)/4];this.geometry.attributes.position.setXYZ(this.index,toX,toY,toZ),this.geometry.attributes.color.setXYZ(this.index++,r,g,b)},THREE.AmmoDebugDrawer.prototype.drawContactPoint=function(pointOnB,normalOnB,distance,lifeTime,color){const heap=Ammo.HEAPF32,r=heap[(color+0)/4],g=heap[(color+4)/4],b=heap[(color+8)/4],x=heap[(pointOnB+0)/4],y=heap[(pointOnB+4)/4],z=heap[(pointOnB+8)/4];this.geometry.attributes.position.setXYZ(this.index,x,y,z),this.geometry.attributes.color.setXYZ(this.index++,r,g,b);const dx=heap[(normalOnB+0)/4]*distance,dy=heap[(normalOnB+4)/4]*distance,dz=heap[(normalOnB+8)/4]*distance;this.geometry.attributes.position.setXYZ(this.index,x+dx,y+dy,z+dz),this.geometry.attributes.color.setXYZ(this.index++,r,g,b)},THREE.AmmoDebugDrawer.prototype.reportErrorWarning=function(warningString){Ammo.hasOwnProperty("Pointer_stringify")?console.warn(Ammo.Pointer_stringify(warningString)):this.warnedOnce||(this.warnedOnce=!0,console.warn("Cannot print warningString, please rebuild Ammo.js using 'debug' flag"))},THREE.AmmoDebugDrawer.prototype.draw3dText=function(location,textString){console.warn("TODO: draw3dText")},THREE.AmmoDebugDrawer.prototype.setDebugMode=function(debugMode){this.debugDrawMode=debugMode},THREE.AmmoDebugDrawer.prototype.getDebugMode=function(){return this.debugDrawMode}},{}],4:[function(require,module,exports){"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var ObjectCollisionMatrix=function(){function ObjectCollisionMatrix(){this.matrix={}}var _proto=ObjectCollisionMatrix.prototype;return _proto.get=function(bi,bj){var i=bi.id,j=bj.id;if(j>i){var temp=j;j=i,i=temp}return i+"-"+j in this.matrix},_proto.set=function(bi,bj,value){var i=bi.id,j=bj.id;if(j>i){var temp=j;j=i,i=temp}value?this.matrix[i+"-"+j]=!0:delete this.matrix[i+"-"+j]},_proto.reset=function(){this.matrix={}},_proto.setNumObjects=function(n){},ObjectCollisionMatrix}(),Mat3=function(){function Mat3(elements){void 0===elements&&(elements=[0,0,0,0,0,0,0,0,0]),this.elements=elements}var _proto=Mat3.prototype;return _proto.identity=function(){var e=this.elements;e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=1,e[5]=0,e[6]=0,e[7]=0,e[8]=1},_proto.setZero=function(){var e=this.elements;e[0]=0,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=0,e[6]=0,e[7]=0,e[8]=0},_proto.setTrace=function(vector){var e=this.elements;e[0]=vector.x,e[4]=vector.y,e[8]=vector.z},_proto.getTrace=function(target){void 0===target&&(target=new Vec3);var e=this.elements;target.x=e[0],target.y=e[4],target.z=e[8]},_proto.vmult=function(v,target){void 0===target&&(target=new Vec3);var e=this.elements,x=v.x,y=v.y,z=v.z;return target.x=e[0]*x+e[1]*y+e[2]*z,target.y=e[3]*x+e[4]*y+e[5]*z,target.z=e[6]*x+e[7]*y+e[8]*z,target},_proto.smult=function(s){for(var i=0;i<this.elements.length;i++)this.elements[i]*=s},_proto.mmult=function(matrix,target){void 0===target&&(target=new Mat3);for(var elements=matrix.elements,i=0;i<3;i++)for(var j=0;j<3;j++){for(var sum=0,k=0;k<3;k++)sum+=elements[i+3*k]*this.elements[k+3*j];target.elements[i+3*j]=sum}return target},_proto.scale=function(vector,target){void 0===target&&(target=new Mat3);for(var e=this.elements,t=target.elements,i=0;3!==i;i++)t[3*i+0]=vector.x*e[3*i+0],t[3*i+1]=vector.y*e[3*i+1],t[3*i+2]=vector.z*e[3*i+2];return target},_proto.solve=function(b,target){void 0===target&&(target=new Vec3);var i,j,eqns=[];for(i=0;i<12;i++)eqns.push(0);for(i=0;i<3;i++)for(j=0;j<3;j++)eqns[i+4*j]=this.elements[i+3*j];eqns[3]=b.x,eqns[7]=b.y,eqns[11]=b.z;var np,p,n=3,k=n;do{if(0===eqns[(i=k-n)+4*i])for(j=i+1;j<k;j++)if(0!==eqns[i+4*j]){np=4;do{eqns[(p=4-np)+4*i]+=eqns[p+4*j]}while(--np);break}if(0!==eqns[i+4*i])for(j=i+1;j<k;j++){var multiplier=eqns[i+4*j]/eqns[i+4*i];np=4;do{eqns[(p=4-np)+4*j]=p<=i?0:eqns[p+4*j]-eqns[p+4*i]*multiplier}while(--np)}}while(--n);if(target.z=eqns[11]/eqns[10],target.y=(eqns[7]-eqns[6]*target.z)/eqns[5],target.x=(eqns[3]-eqns[2]*target.z-eqns[1]*target.y)/eqns[0],isNaN(target.x)||isNaN(target.y)||isNaN(target.z)||target.x===1/0||target.y===1/0||target.z===1/0)throw"Could not solve equation! Got x=["+target.toString()+"], b=["+b.toString()+"], A=["+this.toString()+"]";return target},_proto.e=function(row,column,value){if(void 0===value)return this.elements[column+3*row];this.elements[column+3*row]=value},_proto.copy=function(matrix){for(var i=0;i<matrix.elements.length;i++)this.elements[i]=matrix.elements[i];return this},_proto.toString=function(){for(var r="",i=0;i<9;i++)r+=this.elements[i]+",";return r},_proto.reverse=function(target){void 0===target&&(target=new Mat3);var i,j,eqns=[];for(i=0;i<18;i++)eqns.push(0);for(i=0;i<3;i++)for(j=0;j<3;j++)eqns[i+6*j]=this.elements[i+3*j];eqns[3]=1,eqns[9]=0,eqns[15]=0,eqns[4]=0,eqns[10]=1,eqns[16]=0,eqns[5]=0,eqns[11]=0,eqns[17]=1;var np,p,n=3,k=n;do{if(0===eqns[(i=k-n)+6*i])for(j=i+1;j<k;j++)if(0!==eqns[i+6*j]){np=6;do{eqns[(p=6-np)+6*i]+=eqns[p+6*j]}while(--np);break}if(0!==eqns[i+6*i])for(j=i+1;j<k;j++){var multiplier=eqns[i+6*j]/eqns[i+6*i];np=6;do{eqns[(p=6-np)+6*j]=p<=i?0:eqns[p+6*j]-eqns[p+6*i]*multiplier}while(--np)}}while(--n);i=2;do{j=i-1;do{var _multiplier=eqns[i+6*j]/eqns[i+6*i];np=6;do{eqns[(p=6-np)+6*j]=eqns[p+6*j]-eqns[p+6*i]*_multiplier}while(--np)}while(j--)}while(--i);i=2;do{var _multiplier2=1/eqns[i+6*i];np=6;do{eqns[(p=6-np)+6*i]=eqns[p+6*i]*_multiplier2}while(--np)}while(i--);i=2;do{j=2;do{if(p=eqns[3+j+6*i],isNaN(p)||p===1/0)throw"Could not reverse! A=["+this.toString()+"]";target.e(i,j,p)}while(j--)}while(i--);return target},_proto.setRotationFromQuaternion=function(q){var x=q.x,y=q.y,z=q.z,w=q.w,x2=x+x,y2=y+y,z2=z+z,xx=x*x2,xy=x*y2,xz=x*z2,yy=y*y2,yz=y*z2,zz=z*z2,wx=w*x2,wy=w*y2,wz=w*z2,e=this.elements;return e[0]=1-(yy+zz),e[1]=xy-wz,e[2]=xz+wy,e[3]=xy+wz,e[4]=1-(xx+zz),e[5]=yz-wx,e[6]=xz-wy,e[7]=yz+wx,e[8]=1-(xx+yy),this},_proto.transpose=function(target){void 0===target&&(target=new Mat3);for(var Mt=target.elements,M=this.elements,i=0;3!==i;i++)for(var j=0;3!==j;j++)Mt[3*i+j]=M[3*j+i];return target},Mat3}(),Vec3=function(){function Vec3(x,y,z){void 0===x&&(x=0),void 0===y&&(y=0),void 0===z&&(z=0),this.x=x,this.y=y,this.z=z}var _proto=Vec3.prototype;return _proto.cross=function(vector,target){void 0===target&&(target=new Vec3);var vx=vector.x,vy=vector.y,vz=vector.z,x=this.x,y=this.y,z=this.z;return target.x=y*vz-z*vy,target.y=z*vx-x*vz,target.z=x*vy-y*vx,target},_proto.set=function(x,y,z){return this.x=x,this.y=y,this.z=z,this},_proto.setZero=function(){this.x=this.y=this.z=0},_proto.vadd=function(vector,target){if(!target)return new Vec3(this.x+vector.x,this.y+vector.y,this.z+vector.z);target.x=vector.x+this.x,target.y=vector.y+this.y,target.z=vector.z+this.z},_proto.vsub=function(vector,target){if(!target)return new Vec3(this.x-vector.x,this.y-vector.y,this.z-vector.z);target.x=this.x-vector.x,target.y=this.y-vector.y,target.z=this.z-vector.z},_proto.crossmat=function(){return new Mat3([0,-this.z,this.y,this.z,0,-this.x,-this.y,this.x,0])},_proto.normalize=function(){var x=this.x,y=this.y,z=this.z,n=Math.sqrt(x*x+y*y+z*z);if(n>0){var invN=1/n;this.x*=invN,this.y*=invN,this.z*=invN}else this.x=0,this.y=0,this.z=0;return n},_proto.unit=function(target){void 0===target&&(target=new Vec3);var x=this.x,y=this.y,z=this.z,ninv=Math.sqrt(x*x+y*y+z*z);return ninv>0?(ninv=1/ninv,target.x=x*ninv,target.y=y*ninv,target.z=z*ninv):(target.x=1,target.y=0,target.z=0),target},_proto.length=function(){var x=this.x,y=this.y,z=this.z;return Math.sqrt(x*x+y*y+z*z)},_proto.lengthSquared=function(){return this.dot(this)},_proto.distanceTo=function(p){var x=this.x,y=this.y,z=this.z,px=p.x,py=p.y,pz=p.z;return Math.sqrt((px-x)*(px-x)+(py-y)*(py-y)+(pz-z)*(pz-z))},_proto.distanceSquared=function(p){var x=this.x,y=this.y,z=this.z,px=p.x,py=p.y,pz=p.z;return(px-x)*(px-x)+(py-y)*(py-y)+(pz-z)*(pz-z)},_proto.scale=function(scalar,target){void 0===target&&(target=new Vec3);var x=this.x,y=this.y,z=this.z;return target.x=scalar*x,target.y=scalar*y,target.z=scalar*z,target},_proto.vmul=function(vector,target){return void 0===target&&(target=new Vec3),target.x=vector.x*this.x,target.y=vector.y*this.y,target.z=vector.z*this.z,target},_proto.addScaledVector=function(scalar,vector,target){return void 0===target&&(target=new Vec3),target.x=this.x+scalar*vector.x,target.y=this.y+scalar*vector.y,target.z=this.z+scalar*vector.z,target},_proto.dot=function(vector){return this.x*vector.x+this.y*vector.y+this.z*vector.z},_proto.isZero=function(){return 0===this.x&&0===this.y&&0===this.z},_proto.negate=function(target){return void 0===target&&(target=new Vec3),target.x=-this.x,target.y=-this.y,target.z=-this.z,target},_proto.tangents=function(t1,t2){var norm=this.length();if(norm>0){var n=Vec3_tangents_n,inorm=1/norm;n.set(this.x*inorm,this.y*inorm,this.z*inorm);var randVec=Vec3_tangents_randVec;Math.abs(n.x)<.9?(randVec.set(1,0,0),n.cross(randVec,t1)):(randVec.set(0,1,0),n.cross(randVec,t1)),n.cross(t1,t2)}else t1.set(1,0,0),t2.set(0,1,0)},_proto.toString=function(){return this.x+","+this.y+","+this.z},_proto.toArray=function(){return[this.x,this.y,this.z]},_proto.copy=function(vector){return this.x=vector.x,this.y=vector.y,this.z=vector.z,this},_proto.lerp=function(vector,t,target){var x=this.x,y=this.y,z=this.z;target.x=x+(vector.x-x)*t,target.y=y+(vector.y-y)*t,target.z=z+(vector.z-z)*t},_proto.almostEquals=function(vector,precision){return void 0===precision&&(precision=1e-6),!(Math.abs(this.x-vector.x)>precision||Math.abs(this.y-vector.y)>precision||Math.abs(this.z-vector.z)>precision)},_proto.almostZero=function(precision){return void 0===precision&&(precision=1e-6),!(Math.abs(this.x)>precision||Math.abs(this.y)>precision||Math.abs(this.z)>precision)},_proto.isAntiparallelTo=function(vector,precision){return this.negate(antip_neg),antip_neg.almostEquals(vector,precision)},_proto.clone=function(){return new Vec3(this.x,this.y,this.z)},Vec3}();Vec3.ZERO=new Vec3(0,0,0),Vec3.UNIT_X=new Vec3(1,0,0),Vec3.UNIT_Y=new Vec3(0,1,0),Vec3.UNIT_Z=new Vec3(0,0,1);var Vec3_tangents_n=new Vec3,Vec3_tangents_randVec=new Vec3,antip_neg=new Vec3,AABB=function(){function AABB(options){void 0===options&&(options={}),this.lowerBound=new Vec3,this.upperBound=new Vec3,options.lowerBound&&this.lowerBound.copy(options.lowerBound),options.upperBound&&this.upperBound.copy(options.upperBound)}var _proto=AABB.prototype;return _proto.setFromPoints=function(points,position,quaternion,skinSize){var l=this.lowerBound,u=this.upperBound,q=quaternion;l.copy(points[0]),q&&q.vmult(l,l),u.copy(l);for(var i=1;i<points.length;i++){var p=points[i];q&&(q.vmult(p,tmp),p=tmp),p.x>u.x&&(u.x=p.x),p.x<l.x&&(l.x=p.x),p.y>u.y&&(u.y=p.y),p.y<l.y&&(l.y=p.y),p.z>u.z&&(u.z=p.z),p.z<l.z&&(l.z=p.z)}return position&&(position.vadd(l,l),position.vadd(u,u)),skinSize&&(l.x-=skinSize,l.y-=skinSize,l.z-=skinSize,u.x+=skinSize,u.y+=skinSize,u.z+=skinSize),this},_proto.copy=function(aabb){return this.lowerBound.copy(aabb.lowerBound),this.upperBound.copy(aabb.upperBound),this},_proto.clone=function(){return(new AABB).copy(this)},_proto.extend=function(aabb){this.lowerBound.x=Math.min(this.lowerBound.x,aabb.lowerBound.x),this.upperBound.x=Math.max(this.upperBound.x,aabb.upperBound.x),this.lowerBound.y=Math.min(this.lowerBound.y,aabb.lowerBound.y),this.upperBound.y=Math.max(this.upperBound.y,aabb.upperBound.y),this.lowerBound.z=Math.min(this.lowerBound.z,aabb.lowerBound.z),this.upperBound.z=Math.max(this.upperBound.z,aabb.upperBound.z)},_proto.overlaps=function(aabb){var l1=this.lowerBound,u1=this.upperBound,l2=aabb.lowerBound,u2=aabb.upperBound,overlapsX=l2.x<=u1.x&&u1.x<=u2.x||l1.x<=u2.x&&u2.x<=u1.x,overlapsY=l2.y<=u1.y&&u1.y<=u2.y||l1.y<=u2.y&&u2.y<=u1.y,overlapsZ=l2.z<=u1.z&&u1.z<=u2.z||l1.z<=u2.z&&u2.z<=u1.z;return overlapsX&&overlapsY&&overlapsZ},_proto.volume=function(){var l=this.lowerBound,u=this.upperBound;return(u.x-l.x)*(u.y-l.y)*(u.z-l.z)},_proto.contains=function(aabb){var l1=this.lowerBound,u1=this.upperBound,l2=aabb.lowerBound,u2=aabb.upperBound;return l1.x<=l2.x&&u1.x>=u2.x&&l1.y<=l2.y&&u1.y>=u2.y&&l1.z<=l2.z&&u1.z>=u2.z},_proto.getCorners=function(a,b,c,d,e,f,g,h){var l=this.lowerBound,u=this.upperBound;a.copy(l),b.set(u.x,l.y,l.z),c.set(u.x,u.y,l.z),d.set(l.x,u.y,u.z),e.set(u.x,l.y,u.z),f.set(l.x,u.y,l.z),g.set(l.x,l.y,u.z),h.copy(u)},_proto.toLocalFrame=function(frame,target){var corners=transformIntoFrame_corners,a=corners[0],b=corners[1],c=corners[2],d=corners[3],e=corners[4],f=corners[5],g=corners[6],h=corners[7];this.getCorners(a,b,c,d,e,f,g,h);for(var i=0;8!==i;i++){var corner=corners[i];frame.pointToLocal(corner,corner)}return target.setFromPoints(corners)},_proto.toWorldFrame=function(frame,target){var corners=transformIntoFrame_corners,a=corners[0],b=corners[1],c=corners[2],d=corners[3],e=corners[4],f=corners[5],g=corners[6],h=corners[7];this.getCorners(a,b,c,d,e,f,g,h);for(var i=0;8!==i;i++){var corner=corners[i];frame.pointToWorld(corner,corner)}return target.setFromPoints(corners)},_proto.overlapsRay=function(ray){var direction=ray.direction,from=ray.from,dirFracX=1/direction.x,dirFracY=1/direction.y,dirFracZ=1/direction.z,t1=(this.lowerBound.x-from.x)*dirFracX,t2=(this.upperBound.x-from.x)*dirFracX,t3=(this.lowerBound.y-from.y)*dirFracY,t4=(this.upperBound.y-from.y)*dirFracY,t5=(this.lowerBound.z-from.z)*dirFracZ,t6=(this.upperBound.z-from.z)*dirFracZ,tmin=Math.max(Math.max(Math.min(t1,t2),Math.min(t3,t4)),Math.min(t5,t6)),tmax=Math.min(Math.min(Math.max(t1,t2),Math.max(t3,t4)),Math.max(t5,t6));return!(tmax<0)&&!(tmin>tmax)},AABB}(),tmp=new Vec3,transformIntoFrame_corners=[new Vec3,new Vec3,new Vec3,new Vec3,new Vec3,new Vec3,new Vec3,new Vec3],ArrayCollisionMatrix=function(){function ArrayCollisionMatrix(){this.matrix=[]}var _proto=ArrayCollisionMatrix.prototype;return _proto.get=function(bi,bj){var i=bi.index,j=bj.index;if(j>i){var temp=j;j=i,i=temp}return this.matrix[(i*(i+1)>>1)+j-1]},_proto.set=function(bi,bj,value){var i=bi.index,j=bj.index;if(j>i){var temp=j;j=i,i=temp}this.matrix[(i*(i+1)>>1)+j-1]=value?1:0},_proto.reset=function(){for(var i=0,l=this.matrix.length;i!==l;i++)this.matrix[i]=0},_proto.setNumObjects=function(n){this.matrix.length=n*(n-1)>>1},ArrayCollisionMatrix}();function _inheritsLoose(subClass,superClass){subClass.prototype=Object.create(superClass.prototype),subClass.prototype.constructor=subClass,subClass.__proto__=superClass}function _assertThisInitialized(self){if(void 0===self)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return self}var EventTarget=function(){function EventTarget(){}var _proto=EventTarget.prototype;return _proto.addEventListener=function(type,listener){void 0===this._listeners&&(this._listeners={});var listeners=this._listeners;return void 0===listeners[type]&&(listeners[type]=[]),listeners[type].includes(listener)||listeners[type].push(listener),this},_proto.hasEventListener=function(type,listener){if(void 0===this._listeners)return!1;var listeners=this._listeners;return!(void 0===listeners[type]||!listeners[type].includes(listener))},_proto.hasAnyEventListener=function(type){return void 0!==this._listeners&&void 0!==this._listeners[type]},_proto.removeEventListener=function(type,listener){if(void 0===this._listeners)return this;var listeners=this._listeners;if(void 0===listeners[type])return this;var index=listeners[type].indexOf(listener);return-1!==index&&listeners[type].splice(index,1),this},_proto.dispatchEvent=function(event){if(void 0===this._listeners)return this;var listenerArray=this._listeners[event.type];if(void 0!==listenerArray){event.target=this;for(var i=0,l=listenerArray.length;i<l;i++)listenerArray[i].call(this,event)}return this},EventTarget}(),Quaternion=function(){function Quaternion(x,y,z,w){void 0===x&&(x=0),void 0===y&&(y=0),void 0===z&&(z=0),void 0===w&&(w=1),this.x=x,this.y=y,this.z=z,this.w=w}var _proto=Quaternion.prototype;return _proto.set=function(x,y,z,w){return this.x=x,this.y=y,this.z=z,this.w=w,this},_proto.toString=function(){return this.x+","+this.y+","+this.z+","+this.w},_proto.toArray=function(){return[this.x,this.y,this.z,this.w]},_proto.setFromAxisAngle=function(vector,angle){var s=Math.sin(.5*angle);return this.x=vector.x*s,this.y=vector.y*s,this.z=vector.z*s,this.w=Math.cos(.5*angle),this},_proto.toAxisAngle=function(targetAxis){void 0===targetAxis&&(targetAxis=new Vec3),this.normalize();var angle=2*Math.acos(this.w),s=Math.sqrt(1-this.w*this.w);return s<.001?(targetAxis.x=this.x,targetAxis.y=this.y,targetAxis.z=this.z):(targetAxis.x=this.x/s,targetAxis.y=this.y/s,targetAxis.z=this.z/s),[targetAxis,angle]},_proto.setFromVectors=function(u,v){if(u.isAntiparallelTo(v)){var t1=sfv_t1,t2=sfv_t2;u.tangents(t1,t2),this.setFromAxisAngle(t1,Math.PI)}else{var a=u.cross(v);this.x=a.x,this.y=a.y,this.z=a.z,this.w=Math.sqrt(Math.pow(u.length(),2)*Math.pow(v.length(),2))+u.dot(v),this.normalize()}return this},_proto.mult=function(quat,target){void 0===target&&(target=new Quaternion);var ax=this.x,ay=this.y,az=this.z,aw=this.w,bx=quat.x,by=quat.y,bz=quat.z,bw=quat.w;return target.x=ax*bw+aw*bx+ay*bz-az*by,target.y=ay*bw+aw*by+az*bx-ax*bz,target.z=az*bw+aw*bz+ax*by-ay*bx,target.w=aw*bw-ax*bx-ay*by-az*bz,target},_proto.inverse=function(target){void 0===target&&(target=new Quaternion);var x=this.x,y=this.y,z=this.z,w=this.w;this.conjugate(target);var inorm2=1/(x*x+y*y+z*z+w*w);return target.x*=inorm2,target.y*=inorm2,target.z*=inorm2,target.w*=inorm2,target},_proto.conjugate=function(target){return void 0===target&&(target=new Quaternion),target.x=-this.x,target.y=-this.y,target.z=-this.z,target.w=this.w,target},_proto.normalize=function(){var l=Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w);return 0===l?(this.x=0,this.y=0,this.z=0,this.w=0):(l=1/l,this.x*=l,this.y*=l,this.z*=l,this.w*=l),this},_proto.normalizeFast=function(){var f=(3-(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w))/2;return 0===f?(this.x=0,this.y=0,this.z=0,this.w=0):(this.x*=f,this.y*=f,this.z*=f,this.w*=f),this},_proto.vmult=function(v,target){void 0===target&&(target=new Vec3);var x=v.x,y=v.y,z=v.z,qx=this.x,qy=this.y,qz=this.z,qw=this.w,ix=qw*x+qy*z-qz*y,iy=qw*y+qz*x-qx*z,iz=qw*z+qx*y-qy*x,iw=-qx*x-qy*y-qz*z;return target.x=ix*qw+iw*-qx+iy*-qz-iz*-qy,target.y=iy*qw+iw*-qy+iz*-qx-ix*-qz,target.z=iz*qw+iw*-qz+ix*-qy-iy*-qx,target},_proto.copy=function(quat){return this.x=quat.x,this.y=quat.y,this.z=quat.z,this.w=quat.w,this},_proto.toEuler=function(target,order){var heading,attitude,bank;void 0===order&&(order="YZX");var x=this.x,y=this.y,z=this.z,w=this.w;switch(order){case"YZX":var test=x*y+z*w;if(test>.499&&(heading=2*Math.atan2(x,w),attitude=Math.PI/2,bank=0),test<-.499&&(heading=-2*Math.atan2(x,w),attitude=-Math.PI/2,bank=0),void 0===heading){var sqx=x*x,sqy=y*y,sqz=z*z;heading=Math.atan2(2*y*w-2*x*z,1-2*sqy-2*sqz),attitude=Math.asin(2*test),bank=Math.atan2(2*x*w-2*y*z,1-2*sqx-2*sqz)}break;default:throw new Error("Euler order "+order+" not supported yet.")}target.y=heading,target.z=attitude,target.x=bank},_proto.setFromEuler=function(x,y,z,order){void 0===order&&(order="XYZ");var c1=Math.cos(x/2),c2=Math.cos(y/2),c3=Math.cos(z/2),s1=Math.sin(x/2),s2=Math.sin(y/2),s3=Math.sin(z/2);return"XYZ"===order?(this.x=s1*c2*c3+c1*s2*s3,this.y=c1*s2*c3-s1*c2*s3,this.z=c1*c2*s3+s1*s2*c3,this.w=c1*c2*c3-s1*s2*s3):"YXZ"===order?(this.x=s1*c2*c3+c1*s2*s3,this.y=c1*s2*c3-s1*c2*s3,this.z=c1*c2*s3-s1*s2*c3,this.w=c1*c2*c3+s1*s2*s3):"ZXY"===order?(this.x=s1*c2*c3-c1*s2*s3,this.y=c1*s2*c3+s1*c2*s3,this.z=c1*c2*s3+s1*s2*c3,this.w=c1*c2*c3-s1*s2*s3):"ZYX"===order?(this.x=s1*c2*c3-c1*s2*s3,this.y=c1*s2*c3+s1*c2*s3,this.z=c1*c2*s3-s1*s2*c3,this.w=c1*c2*c3+s1*s2*s3):"YZX"===order?(this.x=s1*c2*c3+c1*s2*s3,this.y=c1*s2*c3+s1*c2*s3,this.z=c1*c2*s3-s1*s2*c3,this.w=c1*c2*c3-s1*s2*s3):"XZY"===order&&(this.x=s1*c2*c3-c1*s2*s3,this.y=c1*s2*c3-s1*c2*s3,this.z=c1*c2*s3+s1*s2*c3,this.w=c1*c2*c3+s1*s2*s3),this},_proto.clone=function(){return new Quaternion(this.x,this.y,this.z,this.w)},_proto.slerp=function(toQuat,t,target){void 0===target&&(target=new Quaternion);var omega,cosom,sinom,scale0,scale1,ax=this.x,ay=this.y,az=this.z,aw=this.w,bx=toQuat.x,by=toQuat.y,bz=toQuat.z,bw=toQuat.w;return(cosom=ax*bx+ay*by+az*bz+aw*bw)<0&&(cosom=-cosom,bx=-bx,by=-by,bz=-bz,bw=-bw),1-cosom>1e-6?(omega=Math.acos(cosom),sinom=Math.sin(omega),scale0=Math.sin((1-t)*omega)/sinom,scale1=Math.sin(t*omega)/sinom):(scale0=1-t,scale1=t),target.x=scale0*ax+scale1*bx,target.y=scale0*ay+scale1*by,target.z=scale0*az+scale1*bz,target.w=scale0*aw+scale1*bw,target},_proto.integrate=function(angularVelocity,dt,angularFactor,target){void 0===target&&(target=new Quaternion);var ax=angularVelocity.x*angularFactor.x,ay=angularVelocity.y*angularFactor.y,az=angularVelocity.z*angularFactor.z,bx=this.x,by=this.y,bz=this.z,bw=this.w,half_dt=.5*dt;return target.x+=half_dt*(ax*bw+ay*bz-az*by),target.y+=half_dt*(ay*bw+az*bx-ax*bz),target.z+=half_dt*(az*bw+ax*by-ay*bx),target.w+=half_dt*(-ax*bx-ay*by-az*bz),target},Quaternion}(),sfv_t1=new Vec3,sfv_t2=new Vec3,SHAPE_TYPES={SPHERE:1,PLANE:2,BOX:4,COMPOUND:8,CONVEXPOLYHEDRON:16,HEIGHTFIELD:32,PARTICLE:64,CYLINDER:128,TRIMESH:256},Shape=function(){function Shape(options){void 0===options&&(options={}),this.id=Shape.idCounter++,this.type=options.type||0,this.boundingSphereRadius=0,this.collisionResponse=!options.collisionResponse||options.collisionResponse,this.collisionFilterGroup=void 0!==options.collisionFilterGroup?options.collisionFilterGroup:1,this.collisionFilterMask=void 0!==options.collisionFilterMask?options.collisionFilterMask:-1,this.material=options.material?options.material:null,this.body=null}var _proto=Shape.prototype;return _proto.updateBoundingSphereRadius=function(){throw"computeBoundingSphereRadius() not implemented for shape type "+this.type},_proto.volume=function(){throw"volume() not implemented for shape type "+this.type},_proto.calculateLocalInertia=function(mass,target){throw"calculateLocalInertia() not implemented for shape type "+this.type},_proto.calculateWorldAABB=function(pos,quat,min,max){throw"calculateWorldAABB() not implemented for shape type "+this.type},Shape}();Shape.idCounter=0,Shape.types=SHAPE_TYPES;var Transform=function(){function Transform(options){void 0===options&&(options={}),this.position=new Vec3,this.quaternion=new Quaternion,options.position&&this.position.copy(options.position),options.quaternion&&this.quaternion.copy(options.quaternion)}var _proto=Transform.prototype;return _proto.pointToLocal=function(worldPoint,result){return Transform.pointToLocalFrame(this.position,this.quaternion,worldPoint,result)},_proto.pointToWorld=function(localPoint,result){return Transform.pointToWorldFrame(this.position,this.quaternion,localPoint,result)},_proto.vectorToWorldFrame=function(localVector,result){return void 0===result&&(result=new Vec3),this.quaternion.vmult(localVector,result),result},Transform.pointToLocalFrame=function(position,quaternion,worldPoint,result){return void 0===result&&(result=new Vec3),worldPoint.vsub(position,result),quaternion.conjugate(tmpQuat),tmpQuat.vmult(result,result),result},Transform.pointToWorldFrame=function(position,quaternion,localPoint,result){return void 0===result&&(result=new Vec3),quaternion.vmult(localPoint,result),result.vadd(position,result),result},Transform.vectorToWorldFrame=function(quaternion,localVector,result){return void 0===result&&(result=new Vec3),quaternion.vmult(localVector,result),result},Transform.vectorToLocalFrame=function(position,quaternion,worldVector,result){return void 0===result&&(result=new Vec3),quaternion.w*=-1,quaternion.vmult(worldVector,result),quaternion.w*=-1,result},Transform}(),tmpQuat=new Quaternion,ConvexPolyhedron=function(_Shape){function ConvexPolyhedron(props){var _this;void 0===props&&(props={});var _props=props,_props$vertices=_props.vertices,vertices=void 0===_props$vertices?[]:_props$vertices,_props$faces=_props.faces,faces=void 0===_props$faces?[]:_props$faces,_props$normals=_props.normals,normals=void 0===_props$normals?[]:_props$normals,axes=_props.axes,boundingSphereRadius=_props.boundingSphereRadius;return(_this=_Shape.call(this,{type:Shape.types.CONVEXPOLYHEDRON})||this).vertices=vertices,_this.faces=faces,_this.faceNormals=normals,0===_this.faceNormals.length&&_this.computeNormals(),boundingSphereRadius?_this.boundingSphereRadius=boundingSphereRadius:_this.updateBoundingSphereRadius(),_this.worldVertices=[],_this.worldVerticesNeedsUpdate=!0,_this.worldFaceNormals=[],_this.worldFaceNormalsNeedsUpdate=!0,_this.uniqueAxes=axes?axes.slice():null,_this.uniqueEdges=[],_this.computeEdges(),_this}_inheritsLoose(ConvexPolyhedron,_Shape);var _proto=ConvexPolyhedron.prototype;return _proto.computeEdges=function(){var faces=this.faces,vertices=this.vertices,edges=this.uniqueEdges;edges.length=0;for(var edge=new Vec3,i=0;i!==faces.length;i++)for(var face=faces[i],numVertices=face.length,j=0;j!==numVertices;j++){var k=(j+1)%numVertices;vertices[face[j]].vsub(vertices[face[k]],edge),edge.normalize();for(var found=!1,p=0;p!==edges.length;p++)if(edges[p].almostEquals(edge)||edges[p].almostEquals(edge)){found=!0;break}found||edges.push(edge.clone())}},_proto.computeNormals=function(){this.faceNormals.length=this.faces.length;for(var i=0;i<this.faces.length;i++){for(var j=0;j<this.faces[i].length;j++)if(!this.vertices[this.faces[i][j]])throw new Error("Vertex "+this.faces[i][j]+" not found!");var n=this.faceNormals[i]||new Vec3;this.getFaceNormal(i,n),n.negate(n),this.faceNormals[i]=n;var vertex=this.vertices[this.faces[i][0]];if(n.dot(vertex)<0){console.error(".faceNormals["+i+"] = Vec3("+n.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 _j=0;_j<this.faces[i].length;_j++)console.warn(".vertices["+this.faces[i][_j]+"] = Vec3("+this.vertices[this.faces[i][_j]].toString()+")")}}},_proto.getFaceNormal=function(i,target){var f=this.faces[i],va=this.vertices[f[0]],vb=this.vertices[f[1]],vc=this.vertices[f[2]];ConvexPolyhedron.computeNormal(va,vb,vc,target)},_proto.clipAgainstHull=function(posA,quatA,hullB,posB,quatB,separatingNormal,minDist,maxDist,result){for(var WorldNormal=new Vec3,closestFaceB=-1,dmax=-Number.MAX_VALUE,face=0;face<hullB.faces.length;face++){WorldNormal.copy(hullB.faceNormals[face]),quatB.vmult(WorldNormal,WorldNormal);var d=WorldNormal.dot(separatingNormal);d>dmax&&(dmax=d,closestFaceB=face)}for(var worldVertsB1=[],i=0;i<hullB.faces[closestFaceB].length;i++){var b=hullB.vertices[hullB.faces[closestFaceB][i]],worldb=new Vec3;worldb.copy(b),quatB.vmult(worldb,worldb),posB.vadd(worldb,worldb),worldVertsB1.push(worldb)}closestFaceB>=0&&this.clipFaceAgainstHull(separatingNormal,posA,quatA,worldVertsB1,minDist,maxDist,result)},_proto.findSeparatingAxis=function(hullB,posA,quatA,posB,quatB,target,faceListA,faceListB){var faceANormalWS3=new Vec3,Worldnormal1=new Vec3,deltaC=new Vec3,worldEdge0=new Vec3,worldEdge1=new Vec3,Cross=new Vec3,dmin=Number.MAX_VALUE;if(this.uniqueAxes)for(var _i=0;_i!==this.uniqueAxes.length;_i++){quatA.vmult(this.uniqueAxes[_i],faceANormalWS3);var _d=this.testSepAxis(faceANormalWS3,hullB,posA,quatA,posB,quatB);if(!1===_d)return!1;_d<dmin&&(dmin=_d,target.copy(faceANormalWS3))}else for(var numFacesA=faceListA?faceListA.length:this.faces.length,i=0;i<numFacesA;i++){var fi=faceListA?faceListA[i]:i;faceANormalWS3.copy(this.faceNormals[fi]),quatA.vmult(faceANormalWS3,faceANormalWS3);var d=this.testSepAxis(faceANormalWS3,hullB,posA,quatA,posB,quatB);if(!1===d)return!1;d<dmin&&(dmin=d,target.copy(faceANormalWS3))}if(hullB.uniqueAxes)for(var _i3=0;_i3!==hullB.uniqueAxes.length;_i3++){quatB.vmult(hullB.uniqueAxes[_i3],Worldnormal1);var _d3=this.testSepAxis(Worldnormal1,hullB,posA,quatA,posB,quatB);if(!1===_d3)return!1;_d3<dmin&&(dmin=_d3,target.copy(Worldnormal1))}else for(var numFacesB=faceListB?faceListB.length:hullB.faces.length,_i2=0;_i2<numFacesB;_i2++){var _fi=faceListB?faceListB[_i2]:_i2;Worldnormal1.copy(hullB.faceNormals[_fi]),quatB.vmult(Worldnormal1,Worldnormal1);var _d2=this.testSepAxis(Worldnormal1,hullB,posA,quatA,posB,quatB);if(!1===_d2)return!1;_d2<dmin&&(dmin=_d2,target.copy(Worldnormal1))}for(var e0=0;e0!==this.uniqueEdges.length;e0++){quatA.vmult(this.uniqueEdges[e0],worldEdge0);for(var e1=0;e1!==hullB.uniqueEdges.length;e1++)if(quatB.vmult(hullB.uniqueEdges[e1],worldEdge1),worldEdge0.cross(worldEdge1,Cross),!Cross.almostZero()){Cross.normalize();var dist=this.testSepAxis(Cross,hullB,posA,quatA,posB,quatB);if(!1===dist)return!1;dist<dmin&&(dmin=dist,target.copy(Cross))}}return posB.vsub(posA,deltaC),deltaC.dot(target)>0&&target.negate(target),!0},_proto.testSepAxis=function(axis,hullB,posA,quatA,posB,quatB){ConvexPolyhedron.project(this,axis,posA,quatA,maxminA),ConvexPolyhedron.project(hullB,axis,posB,quatB,maxminB);var maxA=maxminA[0],minA=maxminA[1],maxB=maxminB[0],minB=maxminB[1];if(maxA<minB||maxB<minA)return!1;var d0=maxA-minB,d1=maxB-minA;return d0<d1?d0:d1},_proto.calculateLocalInertia=function(mass,target){var aabbmax=new Vec3,aabbmin=new Vec3;this.computeLocalAABB(aabbmin,aabbmax);var x=aabbmax.x-aabbmin.x,y=aabbmax.y-aabbmin.y,z=aabbmax.z-aabbmin.z;target.x=1/12*mass*(2*y*2*y+2*z*2*z),target.y=1/12*mass*(2*x*2*x+2*z*2*z),target.z=1/12*mass*(2*y*2*y+2*x*2*x)},_proto.getPlaneConstantOfFace=function(face_i){var f=this.faces[face_i],n=this.faceNormals[face_i],v=this.vertices[f[0]];return-n.dot(v)},_proto.clipFaceAgainstHull=function(separatingNormal,posA,quatA,worldVertsB1,minDist,maxDist,result){for(var faceANormalWS=new Vec3,edge0=new Vec3,WorldEdge0=new Vec3,worldPlaneAnormal1=new Vec3,planeNormalWS1=new Vec3,worldA1=new Vec3,localPlaneNormal=new Vec3,planeNormalWS=new Vec3,pVtxIn=worldVertsB1,pVtxOut=[],closestFaceA=-1,dmin=Number.MAX_VALUE,face=0;face<this.faces.length;face++){faceANormalWS.copy(this.faceNormals[face]),quatA.vmult(faceANormalWS,faceANormalWS);var d=faceANormalWS.dot(separatingNormal);d<dmin&&(dmin=d,closestFaceA=face)}if(!(closestFaceA<0)){var polyA=this.faces[closestFaceA];polyA.connectedFaces=[];for(var i=0;i<this.faces.length;i++)for(var j=0;j<this.faces[i].length;j++)-1!==polyA.indexOf(this.faces[i][j])&&i!==closestFaceA&&-1===polyA.connectedFaces.indexOf(i)&&polyA.connectedFaces.push(i);for(var numVerticesA=polyA.length,_i4=0;_i4<numVerticesA;_i4++){var a=this.vertices[polyA[_i4]],b=this.vertices[polyA[(_i4+1)%numVerticesA]];a.vsub(b,edge0),WorldEdge0.copy(edge0),quatA.vmult(WorldEdge0,WorldEdge0),posA.vadd(WorldEdge0,WorldEdge0),worldPlaneAnormal1.copy(this.faceNormals[closestFaceA]),quatA.vmult(worldPlaneAnormal1,worldPlaneAnormal1),posA.vadd(worldPlaneAnormal1,worldPlaneAnormal1),WorldEdge0.cross(worldPlaneAnormal1,planeNormalWS1),planeNormalWS1.negate(planeNormalWS1),worldA1.copy(a),quatA.vmult(worldA1,worldA1),posA.vadd(worldA1,worldA1);var otherFace=polyA.connectedFaces[_i4];localPlaneNormal.copy(this.faceNormals[otherFace]);var _localPlaneEq=this.getPlaneConstantOfFace(otherFace);planeNormalWS.copy(localPlaneNormal),quatA.vmult(planeNormalWS,planeNormalWS);var _planeEqWS=_localPlaneEq-planeNormalWS.dot(posA);for(this.clipFaceAgainstPlane(pVtxIn,pVtxOut,planeNormalWS,_planeEqWS);pVtxIn.length;)pVtxIn.shift();for(;pVtxOut.length;)pVtxIn.push(pVtxOut.shift())}localPlaneNormal.copy(this.faceNormals[closestFaceA]);var localPlaneEq=this.getPlaneConstantOfFace(closestFaceA);planeNormalWS.copy(localPlaneNormal),quatA.vmult(planeNormalWS,planeNormalWS);for(var planeEqWS=localPlaneEq-planeNormalWS.dot(posA),_i5=0;_i5<pVtxIn.length;_i5++){var depth=planeNormalWS.dot(pVtxIn[_i5])+planeEqWS;if(depth<=minDist&&(console.log("clamped: depth="+depth+" to minDist="+minDist),depth=minDist),depth<=maxDist){var point=pVtxIn[_i5];if(depth<=1e-6){var p={point:point,normal:planeNormalWS,depth:depth};result.push(p)}}}}},_proto.clipFaceAgainstPlane=function(inVertices,outVertices,planeNormal,planeConstant){var n_dot_first,n_dot_last,numVerts=inVertices.length;if(numVerts<2)return outVertices;var firstVertex=inVertices[inVertices.length-1],lastVertex=inVertices[0];n_dot_first=planeNormal.dot(firstVertex)+planeConstant;for(var vi=0;vi<numVerts;vi++){if(lastVertex=inVertices[vi],n_dot_last=planeNormal.dot(lastVertex)+planeConstant,n_dot_first<0)if(n_dot_last<0){var newv=new Vec3;newv.copy(lastVertex),outVertices.push(newv)}else{var _newv=new Vec3;firstVertex.lerp(lastVertex,n_dot_first/(n_dot_first-n_dot_last),_newv),outVertices.push(_newv)}else if(n_dot_last<0){var _newv2=new Vec3;firstVertex.lerp(lastVertex,n_dot_first/(n_dot_first-n_dot_last),_newv2),outVertices.push(_newv2),outVertices.push(lastVertex)}firstVertex=lastVertex,n_dot_first=n_dot_last}return outVertices},_proto.computeWorldVertices=function(position,quat){for(;this.worldVertices.length<this.vertices.length;)this.worldVertices.push(new Vec3);for(var verts=this.vertices,worldVerts=this.worldVertices,i=0;i!==this.vertices.length;i++)quat.vmult(verts[i],worldVerts[i]),position.vadd(worldVerts[i],worldVerts[i]);this.worldVerticesNeedsUpdate=!1},_proto.computeLocalAABB=function(aabbmin,aabbmax){var vertices=this.vertices;aabbmin.set(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),aabbmax.set(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE);for(var i=0;i<this.vertices.length;i++){var v=vertices[i];v.x<aabbmin.x?aabbmin.x=v.x:v.x>aabbmax.x&&(aabbmax.x=v.x),v.y<aabbmin.y?aabbmin.y=v.y:v.y>aabbmax.y&&(aabbmax.y=v.y),v.z<aabbmin.z?aabbmin.z=v.z:v.z>aabbmax.z&&(aabbmax.z=v.z)}},_proto.computeWorldFaceNormals=function(quat){for(var N=this.faceNormals.length;this.worldFaceNormals.length<N;)this.worldFaceNormals.push(new Vec3);for(var normals=this.faceNormals,worldNormals=this.worldFaceNormals,i=0;i!==N;i++)quat.vmult(normals[i],worldNormals[i]);this.worldFaceNormalsNeedsUpdate=!1},_proto.updateBoundingSphereRadius=function(){for(var max2=0,verts=this.vertices,i=0;i!==verts.length;i++){var norm2=verts[i].lengthSquared();norm2>max2&&(max2=norm2)}this.boundingSphereRadius=Math.sqrt(max2)},_proto.calculateWorldAABB=function(pos,quat,min,max){for(var minx,miny,minz,maxx,maxy,maxz,verts=this.vertices,tempWorldVertex=new Vec3,i=0;i<verts.length;i++){tempWorldVertex.copy(verts[i]),quat.vmult(tempWorldVertex,tempWorldVertex),pos.vadd(tempWorldVertex,tempWorldVertex);var v=tempWorldVertex;(void 0===minx||v.x<minx)&&(minx=v.x),(void 0===maxx||v.x>maxx)&&(maxx=v.x),(void 0===miny||v.y<miny)&&(miny=v.y),(void 0===maxy||v.y>maxy)&&(maxy=v.y),(void 0===minz||v.z<minz)&&(minz=v.z),(void 0===maxz||v.z>maxz)&&(maxz=v.z)}min.set(minx,miny,minz),max.set(maxx,maxy,maxz)},_proto.volume=function(){return 4*Math.PI*this.boundingSphereRadius/3},_proto.getAveragePointLocal=function(target){void 0===target&&(target=new Vec3);for(var verts=this.vertices,i=0;i<verts.length;i++)target.vadd(verts[i],target);return target.scale(1/verts.length,target),target},_proto.transformAllPoints=function(offset,quat){var n=this.vertices.length,verts=this.vertices;if(quat){for(var i=0;i<n;i++){var v=verts[i];quat.vmult(v,v)}for(var _i6=0;_i6<this.faceNormals.length;_i6++){var _v=this.faceNormals[_i6];quat.vmult(_v,_v)}}if(offset)for(var _i7=0;_i7<n;_i7++){var _v2=verts[_i7];_v2.vadd(offset,_v2)}},_proto.pointIsInside=function(p){var verts=this.vertices,faces=this.faces,normals=this.faceNormals,pointInside=new Vec3;this.getAveragePointLocal(pointInside);for(var i=0;i<this.faces.length;i++){var n=normals[i],v=verts[faces[i][0]],vToP=new Vec3;p.vsub(v,vToP);var r1=n.dot(vToP),vToPointInside=new Vec3;pointInside.vsub(v,vToPointInside);var r2=n.dot(vToPointInside);if(r1<0&&r2>0||r1>0&&r2<0)return!1}return-1},ConvexPolyhedron}(Shape);ConvexPolyhedron.computeNormal=function(va,vb,vc,target){var cb=new Vec3,ab=new Vec3;vb.vsub(va,ab),vc.vsub(vb,cb),cb.cross(ab,target),target.isZero()||target.normalize()};var maxminA=[],maxminB=[];ConvexPolyhedron.project=function(shape,axis,pos,quat,result){var n=shape.vertices.length,localAxis=new Vec3,max=0,min=0,localOrigin=new Vec3,vs=shape.vertices;localOrigin.setZero(),Transform.vectorToLocalFrame(pos,quat,axis,localAxis),Transform.pointToLocalFrame(pos,quat,localOrigin,localOrigin);var add=localOrigin.dot(localAxis);min=max=vs[0].dot(localAxis);for(var i=1;i<n;i++){var val=vs[i].dot(localAxis);val>max&&(max=val),val<min&&(min=val)}if((min-=add)>(max-=add)){var temp=min;min=max,max=temp}result[0]=max,result[1]=min};var Box=function(_Shape){function Box(halfExtents){var _this;return(_this=_Shape.call(this,{type:Shape.types.BOX})||this).halfExtents=halfExtents,_this.convexPolyhedronRepresentation=null,_this.updateConvexPolyhedronRepresentation(),_this.updateBoundingSphereRadius(),_this}_inheritsLoose(Box,_Shape);var _proto=Box.prototype;return _proto.updateConvexPolyhedronRepresentation=function(){var sx=this.halfExtents.x,sy=this.halfExtents.y,sz=this.halfExtents.z,V=Vec3,vertices=[new V(-sx,-sy,-sz),new V(sx,-sy,-sz),new V(sx,sy,-sz),new V(-sx,sy,-sz),new V(-sx,-sy,sz),new V(sx,-sy,sz),new V(sx,sy,sz),new V(-sx,sy,sz)],axes=[new V(0,0,1),new V(0,1,0),new V(1,0,0)],h=new ConvexPolyhedron({vertices:vertices,faces:[[3,2,1,0],[4,5,6,7],[5,4,0,1],[2,3,7,6],[0,4,7,3],[1,2,6,5]],axes:axes});this.convexPolyhedronRepresentation=h,h.material=this.material},_proto.calculateLocalInertia=function(mass,target){return void 0===target&&(target=new Vec3),Box.calculateInertia(this.halfExtents,mass,target),target},_proto.getSideNormals=function(sixTargetVectors,quat){var sides=sixTargetVectors,ex=this.halfExtents;if(sides[0].set(ex.x,0,0),sides[1].set(0,ex.y,0),sides[2].set(0,0,ex.z),sides[3].set(-ex.x,0,0),sides[4].set(0,-ex.y,0),sides[5].set(0,0,-ex.z),void 0!==quat)for(var i=0;i!==sides.length;i++)quat.vmult(sides[i],sides[i]);return sides},_proto.volume=function(){return 8*this.halfExtents.x*this.halfExtents.y*this.halfExtents.z},_proto.updateBoundingSphereRadius=function(){this.boundingSphereRadius=this.halfExtents.length()},_proto.forEachWorldCorner=function(pos,quat,callback){for(var e=this.halfExtents,corners=[[e.x,e.y,e.z],[-e.x,e.y,e.z],[-e.x,-e.y,e.z],[-e.x,-e.y,-e.z],[e.x,-e.y,-e.z],[e.x,e.y,-e.z],[-e.x,e.y,-e.z],[e.x,-e.y,e.z]],i=0;i<corners.length;i++)worldCornerTempPos.set(corners[i][0],corners[i][1],corners[i][2]),quat.vmult(worldCornerTempPos,worldCornerTempPos),pos.vadd(worldCornerTempPos,worldCornerTempPos),callback(worldCornerTempPos.x,worldCornerTempPos.y,worldCornerTempPos.z)},_proto.calculateWorldAABB=function(pos,quat,min,max){var e=this.halfExtents;worldCornersTemp[0].set(e.x,e.y,e.z),worldCornersTemp[1].set(-e.x,e.y,e.z),worldCornersTemp[2].set(-e.x,-e.y,e.z),worldCornersTemp[3].set(-e.x,-e.y,-e.z),worldCornersTemp[4].set(e.x,-e.y,-e.z),worldCornersTemp[5].set(e.x,e.y,-e.z),worldCornersTemp[6].set(-e.x,e.y,-e.z),worldCornersTemp[7].set(e.x,-e.y,e.z);var wc=worldCornersTemp[0];quat.vmult(wc,wc),pos.vadd(wc,wc),max.copy(wc),min.copy(wc);for(var i=1;i<8;i++){var _wc=worldCornersTemp[i];quat.vmult(_wc,_wc),pos.vadd(_wc,_wc);var _x=_wc.x,_y=_wc.y,_z=_wc.z;_x>max.x&&(max.x=_x),_y>max.y&&(max.y=_y),_z>max.z&&(max.z=_z),_x<min.x&&(min.x=_x),_y<min.y&&(min.y=_y),_z<min.z&&(min.z=_z)}},Box}(Shape);Box.calculateInertia=function(halfExtents,mass,target){var e=halfExtents;target.x=1/12*mass*(2*e.y*2*e.y+2*e.z*2*e.z),target.y=1/12*mass*(2*e.x*2*e.x+2*e.z*2*e.z),target.z=1/12*mass*(2*e.y*2*e.y+2*e.x*2*e.x)};var worldCornerTempPos=new Vec3,worldCornersTemp=[new Vec3,new Vec3,new Vec3,new Vec3,new Vec3,new Vec3,new Vec3,new Vec3],BODY_SLEEP_STATES={AWAKE:0,SLEEPY:1,SLEEPING:2},Body=function(_EventTarget){function Body(options){var _this;void 0===options&&(options={}),(_this=_EventTarget.call(this)||this).id=Body.idCounter++,_this.index=-1,_this.world=null,_this.preStep=null,_this.postStep=null,_this.vlambda=new Vec3,_this.collisionFilterGroup="number"==typeof options.collisionFilterGroup?options.collisionFilterGroup:1,_this.collisionFilterMask="number"==typeof options.collisionFilterMask?options.collisionFilterMask:-1,_this.collisionResponse="boolean"!=typeof options.collisionResponse||options.collisionResponse,_this.position=new Vec3,_this.previousPosition=new Vec3,_this.interpolatedPosition=new Vec3,_this.initPosition=new Vec3,options.position&&(_this.position.copy(options.position),_this.previousPosition.copy(options.position),_this.interpolatedPosition.copy(options.position),_this.initPosition.copy(options.position)),_this.velocity=new Vec3,options.velocity&&_this.velocity.copy(options.velocity),_this.initVelocity=new Vec3,_this.force=new Vec3;var mass="number"==typeof options.mass?options.mass:0;return _this.mass=mass,_this.invMass=mass>0?1/mass:0,_this.material=options.material||null,_this.linearDamping="number"==typeof options.linearDamping?options.linearDamping:.01,_this.type=mass<=0?Body.STATIC:Body.DYNAMIC,typeof options.type==typeof Body.STATIC&&(_this.type=options.type),_this.allowSleep=void 0===options.allowSleep||options.allowSleep,_this.sleepState=0,_this.sleepSpeedLimit=void 0!==options.sleepSpeedLimit?options.sleepSpeedLimit:.1,_this.sleepTimeLimit=void 0!==options.sleepTimeLimit?options.sleepTimeLimit:1,_this.timeLastSleepy=0,_this.wakeUpAfterNarrowphase=!1,_this.torque=new Vec3,_this.quaternion=new Quaternion,_this.initQuaternion=new Quaternion,_this.previousQuaternion=new Quaternion,_this.interpolatedQuaternion=new Quaternion,options.quaternion&&(_this.quaternion.copy(options.quaternion),_this.initQuaternion.copy(options.quaternion),_this.previousQuaternion.copy(options.quaternion),_this.interpolatedQuaternion.copy(options.quaternion)),_this.angularVelocity=new Vec3,options.angularVelocity&&_this.angularVelocity.copy(options.angularVelocity),_this.initAngularVelocity=new Vec3,_this.shapes=[],_this.shapeOffsets=[],_this.shapeOrientations=[],_this.inertia=new Vec3,_this.invInertia=new Vec3,_this.invInertiaWorld=new Mat3,_this.invMassSolve=0,_this.invInertiaSolve=new Vec3,_this.invInertiaWorldSolve=new Mat3,_this.fixedRotation=void 0!==options.fixedRotation&&options.fixedRotation,_this.angularDamping=void 0!==options.angularDamping?options.angularDamping:.01,_this.linearFactor=new Vec3(1,1,1),options.linearFactor&&_this.linearFactor.copy(options.linearFactor),_this.angularFactor=new Vec3(1,1,1),options.angularFactor&&_this.angularFactor.copy(options.angularFactor),_this.aabb=new AABB,_this.aabbNeedsUpdate=!0,_this.boundingRadius=0,_this.wlambda=new Vec3,options.shape&&_this.addShape(options.shape),_this.updateMassPro