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.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.webkitRequestPointerLock,document.exitPointerLock=document.exitPointerLock||document.mozExitPointerLock||doc
w.push(_)}varN=newGameLib.D3.Scene(a._id||a.id,a.path,a.name,a.meshes,newGameLib.D3.Vector4(a.quaternion.x,a.quaternion.y,a.quaternion.z,a.quaternion.w),newGameLib.D3.Vector3(a.position.x,a.position.y,a.position.z),newGameLib.D3.Vector3(a.rotation.x,a.rotation.y,a.rotation.z),newGameLib.D3.Vector3(a.scale.x,a.scale.y,a.scale.z),a.parentSceneId,w,r);GameLib.D3.Scene.loadScene(N,i,!1,t,n,s)}}}(a),a.send()},GameLib.D3.Scene.loadScene=function(e,i,t,n,s,o){console.log("loading scene "+e.name),n.isNotThreeThrow();for(vara=[],r=0;r<e.meshes.length;r++){varh=e.meshes[r];console.log("loading mesh "+h.name);for(varc=newn.instance.Geometry,l=h.vertices,p=h.faces,m=h.faceVertexUvs,d=h.materials,u=0;u<l.length;u++)c.vertices.push(newn.instance.Vector3(l[u].position.x,l[u].position.y,l[u].position.z));for(vary=0;y<p.length;y++){varf=newn.instance.Face3(p[y].v0,p[y].v1,p[y].v2,newn.instance.Vector3(p[y].normal.x,p[y].normal.y,p[y].normal.z),newn.instance.Color(p[y].color.r,p[y].color.g,p[y].color.b),p[y].materialIndex);f.vertexColors=[newn.instance.Color(p[y].vertexColors[0].r,p[y].vertexColors[0].g,p[y].vertexColors[0].b),newn.instance.Color(p[y].vertexColors[1].r,p[y].vertexColors[1].g,p[y].vertexColors[1].b),newn.instance.Color(p[y].vertexColors[2].r,p[y].vertexColors[2].g,p[y].vertexColors[2].b)],f.normal=newn.instance.Vector3(p[y].normal.x,p[y].normal.y,p[y].normal.z),f.vertexNormals=[newn.instance.Vector3(p[y].vertexNormals[0].x,p[y].vertexNormals[0].y,p[y].vertexNormals[0].z),newn.instance.Vector3(p[y].vertexNormals[1].x,p[y].vertexNormals[1].y,p[y].vertexNormals[1].z),newn.instance.Vector3(p[y].vertexNormals[2].x,p[y].vertexNormals[2].y,p[y].vertexNormals[2].z)],c.faces.push(f)}c.faceVertexUvs=[];for(varb=0;b<m.length;b++){varL=m[b];c.faceVertexUvs[b]=[];for(varv=0;v<L.length;v++)c.faceVertexUvs[b][v]=[],c.faceVertexUvs[b][v].push(newn.instance.Vector2(L[v][0].x,L[v][0].y),newn.instance.Vector2(L[v][1].x,L[v][1].y),newn.instance.Vector2(L[v][2].x,L[v][2].y))}t&&(c.computeFaceNormals(),c.computeVertexNormals());for(varD=[],G=0;G<d.length;G++)D.push(GameLib.D3.Material.createInstanceMaterial(d[G],n,s,o));varT=Q.all(D).then(function(e,i){returnfunction(t){console.log("loaded material : "+t[0].name);vars=t[0],o=GameLib.D3.Mesh.createInstanceMesh(e,i,s,n);returno.name=e.name,o.position.x=e.position.x,o.position.y=e.position.y,o.position.z=e.position.z,o.rotation.x=e.rotation.x,o.rotation.y=e.rotation.y,o.rotation.z=e.rotation.z,o.scale.x=e.scale.x,o.scale.y=e.scale.y,o.scale.z=e.scale.z,o.quaternion.x=e.quaternion.x,o.quaternion.y=e.quaternion.y,o.quaternion.z=e.quaternion.z,o.quaternion.w=e.quaternion.w,o}}(h,c)).catch(function(e){console.log(e)});a.push(T)}Q.all(a).then(function(t){if(console.log("all meshes have loaded"),"undefined"!=typeofi){for(vars=[],o=0;o<e.lights.length;o++){vara=e.lights[o],r=null;"AmbientLight"==a.lightType&&(r=newn.instance.AmbientLight(a.color,a.intensity)),"DirectionalLight"==a.lightType&&(r=newn.instance.DirectionalLight(a.color,a.intensity)),"PointLight"==a.lightType&&(r=newn.instance.PointLight(a.color,a.intensity),r.distance=a.distance,r.decay=a.decay),"SpotLight"==a.lightType&&(r=newn.instance.SpotLight(a.color,a.intensity),r.distance=a.distance,r.angle=a.angle,r.penumbra=a.penumbra,r.decay=a.decay),r.position.x=a.position.x,r.position.y=a.position.y,r.position.z=a.position.z,r.rotation.x=a.rotation.x,r.rotation.y=a.rotation.y,r.rotation.z=a.rotation.z,null==r?console.warn("Does not support lights of type :"+a.lightType+", not imported"):(r.name=a.name,s.push(r))}varh=newn.instance.Scene;h.name=e.name,h.position.x=e.position.x,h.position.y=e.position.y,h.position.z=e.position.z,h.rotation.x=e.rotation.x,h.rotation.y=e.rotation.y,h.rotation.z=e.rotation.z,h.scale.x=e.scale.x,h.scale.y=e.scale.y,h.scale.z=e.scale.z,h.quaternion.x=e.quaternion.x,h.quaternion.y=e.quaternion.y,h.quaternion.z=e.quaternion.z,h.quaternion.w=e.quaternion.w;for(varc=0;c<t.length;c++)h.add(t[c]);for(varl=0;l<s.length;l++)h.add(s[l]);i(e,{scene:h,lights:s,meshes:t})}}).catch(func