functionGameLib(){}if("undefined"==typeofGameLib.D3&&(GameLib.D3=function(){}),"undefined"==typeofQ){if("undefined"==typeofrequire)throwconsole.warn("You need the Q promise library for the GameLib.D3"),newError("You need the Q promise library for the GameLib.D3");varQ=require("q")}GameLib.D3.BoneWeight=function(e,i){this.boneIndex=e,this.weight=i},GameLib.D3.Bone=function(e,i,t,n,s,o,a,r,h,c){this.id=e,this.name=t,this.boneId=i,"undefined"==typeofn&&(n=[]),this.childBoneIds=n,"undefined"==typeofs&&(s=null),this.parentBoneId=s,"undefined"==typeofo&&(o=newGameLib.D3.Vector4),this.quaternion=o,"undefined"==typeofa&&(a=newGameLib.D3.Vector3(0,0,0)),this.position=a,"undefined"==typeofr&&(r=newGameLib.D3.Vector3(0,0,0)),this.rotation=r,"undefined"==typeofh&&(h=newGameLib.D3.Vector3(1,1,1)),this.scale=h,"undefined"==typeofc&&(c=newGameLib.D3.Vector3(0,1,0)),this.up=c},GameLib.D3.Broadphase=function(e,i,t,n,s){this.id=e,"undefined"==typeofi&&(i="broadphase-"+t),this.name=i,"undefined"==typeoft&&(t=GameLib.D3.Broadphase.BROADPHASE_TYPE_NAIVE),this.broadphaseType=t,"undefined"==typeofn&&(n=null),this.engine=n,this.instance=null,s&&this.createInstance()},GameLib.D3.Broadphase.prototype.createInstance=function(){if(!(this.engineinstanceofGameLib.D3.Engine))throwconsole.warn("No Engine"),newError("No Engine");this.engine.isNotCannonThrow();vare=null;if(this.broadphaseType==GameLib.D3.Broadphase.BROADPHASE_TYPE_NAIVE)e=newthis.engine.instance.NaiveBroadphase;elseif(this.broadphaseType==GameLib.D3.Broadphase.BROADPHASE_TYPE_GRID)e=newthis.engine.instance.GridBroadphase;else{if(this.broadphaseType!=GameLib.D3.Broadphase.BROADPHASE_TYPE_SAP)throwconsole.warn("Unsupported broadphase type: "+this.broadphaseType),newError("Unsupported broadphase type: "+this.broadphaseType);e=newthis.engine.instance.SAPBroardphase}returnthis.instance=e,e},GameLib.D3.Broadphase.BROADPHASE_TYPE_NAIVE=1,GameLib.D3.Broadphase.BROADPHASE_TYPE_GRID=2,GameLib.D3.Broadphase.BROADPHASE_TYPE_SAP=3,GameLib.D3.Color=function(e,i,t,n){this.r=e,this.g=i,this.b=t,this.a=n},GameLib.D3.Engine=function(e,i){this.engineType=e,this.instance=i},GameLib.D3.Engine.prototype.isCannon=function(){returnthis.engineType==GameLib.D3.Engine.ENGINE_TYPE_CANNON},GameLib.D3.Engine.prototype.isNotCannonThrow=function(){if(this.engineType!=GameLib.D3.Engine.ENGINE_TYPE_CANNON)throwconsole.warn("Only CANNON supported for this function"),newError("Only CANNON supported for this function")},GameLib.D3.Engine.prototype.isAmmo=function(){returnthis.engineType==GameLib.D3.Engine.ENGINE_TYPE_AMMO},GameLib.D3.Engine.prototype.isGoblin=function(){returnthis.engineType==GameLib.D3.Engine.ENGINE_TYPE_GOBLIN},GameLib.D3.Engine.ENGINE_TYPE_CANNON=1,GameLib.D3.Engine.ENGINE_TYPE_AMMO=2,GameLib.D3.Engine.ENGINE_TYPE_GOBLIN=3,GameLib.D3.Entity=function(e,i){this.meshId=e,"undefined"==typeofi&&(i=[]),this.componentIds=i},GameLib.D3.FlyControls=function(e,i,t){this.flySpeed=100,this.canvas=t,this.THREE=i,this.yaw=0,this.pitch=0,this.canRotate=!1,this.moveForward=!1,this.moveBackward=!1,this.moveLeft=!1,this.moveRight=!1,this.moveUp=!1,this.moveDown=!1,this.mouseUpCallback=this.onMouseUp.bind(this),this.mouseDownCallback=this.onMouseDown.bind(this),this.mouseMoveCallback=this.onMouseMove.bind(this),this.mouseWheelCallback=this.onMouseWheel.bind(this),this.keyDownCallback=this.onKeyDown.bind(this),this.keyUpCallback=this.onKeyUp.bind(this),this.camera=e,this.canvas.addEventListener("keydown",this.keyDownCallback,!1),this.canvas.addEventListener("keyup",this.keyUpCallback,!1),this.canvas.addEventListener("mousedown",this.mouseDownCallback,!1),this.canvas.addEventListener("mouseup",this.mouseUpCallback,!1),this.canvas.addEventListener("mousewheel",this.mouseWheelCallback,!1),this.havePointerLock="pointerLockElement"indocument||"mozPointerLockElement"indocument||"webkitPointerLockElement"indocument,this.element=document.body,this.havePointerLock&&(this.element.requestPointerLock=this.element.requestPointerLock||this.element.mozRequestPointerLock||this.element.webkitReque
useCustomSlidingRotationalSpeed:this.useCustomSlidingRotationalSpeed,customSlidingRotationalSpeed:this.customSlidingRotationalSpeed})},GameLib.D3.RigidBodyVehicle=function(e,i,t){this.componentId=GameLib.D3.Tools.RandomId(),this.engine=e,this.engine.isNotCannonThrow(),this.chassisBody=i,"undefined"==typeoft&&(t=[]),this.wheels=t,this.instance=this.createInstance()},GameLib.D3.RigidBodyVehicle.prototype.getWheelInfo=function(){returnthis.instance.wheelBodies},GameLib.D3.RigidBodyVehicle.prototype.createInstance=function(){returnnewthis.engine.instance.RigidVehicle({chassisBody:this.chassisBody.instance})},GameLib.D3.RigidBodyVehicle.prototype.addWheel=function(e){this.wheels.push(e),this.instance.addWheel({body:e.body.instance,position:newthis.engine.instance.Vec3(e.position.x,e.position.y,e.position.z),axis:newthis.engine.instance.Vec3(e.axis.x,e.axis.y,e.axis.z),direction:newthis.engine.instance.Vec3(e.direction.x,e.direction.y,e.direction.z)})},GameLib.D3.RigidBody=function(e,i,t,n,s,o,a,r,h,c,l,p,d,m,u,f){this.componentId=GameLib.D3.Tools.RandomId(),this.position=n||newGameLib.D3.Vector3,this.velocity=o||newGameLib.D3.Vector3,this.angularVelocity=a||newGameLib.D3.Vector3,this.quaternion=s||newGameLib.D3.Vector4(0,0,0,1),this.mass="undefined"==typeofi?0:i,this.friction="undefined"==typeoft?5:t,this.linearDamping="undefined"==typeofr?.01:r,this.angularDamping="undefined"==typeofh?.01:h,this.allowSleep="undefined"==typeofc||c,this.sleepSpeedLimit="undefined"==typeofl?.1:l,this.sleepTimeLimit="undefined"==typeofp?1:p,this.collisionFilterGroup="undefined"==typeofd?1:d,this.collisionFilterMask="undefined"==typeofm?1:m,this.fixedRotation="undefined"!=typeofu&&u,this.shape="undefined"==typeoff?null:f,this.engine=e,this.engine.isNotCannonThrow(),this.instance=this.createInstance()},GameLib.D3.RigidBody.prototype.createInstance=function(){vare=newthis.engine.instance.Body({mass:mass,friction:this.friction,position:newthis.engine.instance.Vec3(this.position.x,this.position.y,this.position.z),velocity:newthis.engine.instance.Vec3(this.velocity.x,this.velocity.y,this.velocity.z),quaternion:newthis.engine.instance.Quaternion(this.quaternion.x,this.quaternion.y,this.quaternion.z,this.quaternion.w),angularVelocity:newthis.engine.instance.Vec3(this.angularVelocity.x,this.angularVelocity.y,this.angularVelocity.z),linearDamping:this.linearDamping,angularDamping:this.angularDamping,allowSleep:this.allowSleep,sleepSpeedLimit:this.sleepSpeedLimit,sleepTimeLimit:this.sleepTimeLimit,collisionFilterGroup:this.collisionFilterGroup,collisionFilterMask:this.collisionFilterMask,fixedRotation:this.fixedRotation,shape:this.shape.instance});returnthis.instance=e,e},GameLib.D3.RigidBody.prototype.addShape=function(e,i,t){i||(i=newGameLib.D3.Vector3(0,0,0)),t||(t=newGameLib.D3.Vector4(0,0,0,1)),this.instance.addShape(e.instance,newthis.engine.instance.Vec3(i.x,i.y,i.z),newthis.engine.instance.Quaternion(t.x,t.y,t.z,t.w))},GameLib.D3.RigidWheel=function(e,i,t,n){this.componentId=GameLib.D3.Tools.RandomId(),this.body=e,this.position=i,this.axis=t,this.direction=n},GameLib.D3.Scene=function(e,i,t,n,s,o,a,r,h,c,l,p){this.id=e,this.sceneId=GameLib.D3.Tools.RandomId(),this.path=i,this.name=t,""==this.name.trim()&&(this.name="unnamed"),"undefined"==typeofn&&(n=[]),this.meshes=n,"undefined"==typeofs&&(s=newGameLib.D3.Vector4),this.quaternion=s,"undefined"==typeofo&&(o=newGameLib.D3.Vector3(0,0,0)),this.position=o,"undefined"==typeofa&&(a=newGameLib.D3.Vector3(0,0,0)),this.rotation=a,"undefined"==typeofr&&(r=newGameLib.D3.Vector3(1,1,1)),this.scale=r,"undefined"==typeofh&&(h=null),this.parentSceneId=h,"undefined"==typeofc&&(c=[]),this.lights=c,"undefined"==typeofl&&(l=[]),this.worlds=l,"undefined"==typeofp&&(p=[]),this.entities=p},GameLib.D3.Scene.LoadSceneFromApi=function(e,i,t,n,s,o){if("undefined"==typeofXMLHttpRequest)returnconsole.warn("implement server side loading from API here"),i(null,newError("not implemented"));vara=newXMLHttpRequest;a.open("GET",o+"/scene/load"+e.path+"/"+e.name),a.onreadystatecha