r3-legacy/build/game-lib-min.js

3 lines
66 KiB
JavaScript

function GameLib(){}if("undefined"==typeof GameLib.D3&&(GameLib.D3=function(){}),"undefined"==typeof Q){if("undefined"==typeof require)throw console.warn("You need the Q promise library for the GameLib.D3"),new Error("You need the Q promise library for the GameLib.D3");var Q=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"==typeof n&&(n=[]),this.childBoneIds=n,"undefined"==typeof s&&(s=null),this.parentBoneId=s,"undefined"==typeof o&&(o=new GameLib.D3.Vector4),this.quaternion=o,"undefined"==typeof a&&(a=new GameLib.D3.Vector3(0,0,0)),this.position=a,"undefined"==typeof r&&(r=new GameLib.D3.Vector3(0,0,0)),this.rotation=r,"undefined"==typeof h&&(h=new GameLib.D3.Vector3(1,1,1)),this.scale=h,"undefined"==typeof c&&(c=new GameLib.D3.Vector3(0,1,0)),this.up=c},GameLib.D3.Broadphase=function(e,i,t,n){this.id=e,"undefined"==typeof i&&(i="broadphase-"+t),this.name=i,"undefined"==typeof t&&(t=GameLib.D3.Broadphase.BROADPHASE_TYPE_NAIVE),this.broadphaseType=t,this.engine=n,this.engine.isNotCannonThrow(),this.instance=this.createInstance()},GameLib.D3.Broadphase.prototype.createInstance=function(){var e=null;if(this.broadphaseType==GameLib.D3.Broadphase.BROADPHASE_TYPE_NAIVE)e=new this.engine.instance.NaiveBroadphase;else if(this.broadphaseType==GameLib.D3.Broadphase.BROADPHASE_TYPE_GRID)e=new this.engine.instance.GridBroadphase;else{if(this.broadphaseType!=GameLib.D3.Broadphase.BROADPHASE_TYPE_SAP)throw console.warn("Unsupported broadphase type: "+this.broadphaseType),new Error("Unsupported broadphase type: "+this.broadphaseType);e=new this.engine.instance.SAPBroadphase}return 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(){return this.engineType==GameLib.D3.Engine.ENGINE_TYPE_CANNON},GameLib.D3.Engine.prototype.isNotCannonThrow=function(){if(this.engineType!=GameLib.D3.Engine.ENGINE_TYPE_CANNON)throw console.warn("Only CANNON supported for this function"),new Error("Only CANNON supported for this function")},GameLib.D3.Engine.prototype.isAmmo=function(){return this.engineType==GameLib.D3.Engine.ENGINE_TYPE_AMMO},GameLib.D3.Engine.prototype.isGoblin=function(){return this.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"==typeof i&&(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"in document||"mozPointerLockElement"in document||"webkitPointerLockElement"in document,this.element=document.body,this.havePointerLock&&(this.element.requestPointerLock=this.element.requestPointerLock||this.element.mozRequestPointerLock||this.element.webkitRequestPointerLock,document.exitPointerLock=document.exitPointerLock||document.mozExitPointerLock||document.webkitExitPointerLock)},GameLib.D3.FlyControls.prototype.onMouseWheel=function(e){this.moveForward=!0,this.applyTranslation(.001*e.wheelDelta),e.preventDefault(),this.moveForward=!1},GameLib.D3.FlyControls.prototype.onMouseDown=function(e){1==e.button&&(this.canRotate=!0,this.canvas.addEventListener("mousemove",this.mouseMoveCallback,!1))},GameLib.D3.FlyControls.prototype.onMouseUp=function(e){1==e.button&&(this.canRotate=!1,this.canvas.removeEventListener("mousemove",this.mouseMoveCallback))},GameLib.D3.FlyControls.prototype.applyRotation=function(){this.camera.rotation.set(this.pitch,this.yaw,0,"YXZ")},GameLib.D3.FlyControls.prototype.applyTranslation=function(e){var i=new this.THREE.Vector3(0,0,-1),t=new this.THREE.Euler(0,0,0,"YXZ");t.set(this.pitch,this.yaw,0,"YXZ"),i=i.applyEuler(t);var n=i.normalize(),s=n.cross(new this.THREE.Vector3(0,1,0));this.moveForward?(this.camera.position.x+=n.x*(e*this.flySpeed),this.camera.position.y+=n.y*(e*this.flySpeed),this.camera.position.z+=n.z*(e*this.flySpeed)):this.moveBackward&&(this.camera.position.x-=n.x*(e*this.flySpeed),this.camera.position.y-=n.y*(e*this.flySpeed),this.camera.position.z-=n.z*(e*this.flySpeed)),this.moveLeft?(this.camera.position.x-=s.x*(e*this.flySpeed),this.camera.position.y-=s.y*(e*this.flySpeed),this.camera.position.z-=s.z*(e*this.flySpeed)):this.moveRight&&(this.camera.position.x+=s.x*(e*this.flySpeed),this.camera.position.y+=s.y*(e*this.flySpeed),this.camera.position.z+=s.z*(e*this.flySpeed)),this.moveUp?this.camera.position.y+=e*this.flySpeed:this.moveDown&&(this.camera.position.y-=e*this.flySpeed)},GameLib.D3.FlyControls.prototype.update=function(e){this.applyRotation(),this.applyTranslation(e)},GameLib.D3.FlyControls.prototype.onMouseMove=function(e){if(this.canRotate){var i=e.movementX||e.mozMovementX||e.webkitMovementX||0,t=e.movementY||e.mozMovementY||e.webkitMovementY||0;this.yaw-=.002*i,this.pitch-=.002*t}},GameLib.D3.FlyControls.prototype.onKeyDown=function(e){switch(e.keyCode){case 87:this.moveForward=!0;break;case 65:this.moveLeft=!0;break;case 83:this.moveBackward=!0;break;case 68:this.moveRight=!0;break;case 104:this.moveUp=!0;break;case 98:this.moveDown=!0}},GameLib.D3.FlyControls.prototype.onKeyUp=function(e){switch(e.keyCode){case 38:case 87:this.moveForward=!1;break;case 37:case 65:this.moveLeft=!1;break;case 40:case 83:this.moveBackward=!1;break;case 39:case 68:this.moveRight=!1;break;case 104:this.moveUp=!1;break;case 98:this.moveDown=!1}},GameLib.D3.Game=function(){this.scenes={},this.physicsWorlds=[],this.sceneToPhysicsWorldsMap={}},GameLib.D3.Game.prototype.AddScene=function(e){this.scenes[e.name]=e},GameLib.D3.Game.prototype.AddPhysicsWorld=function(e){this.physicsWorlds.push(e)},GameLib.D3.Game.prototype.LinkPhysicsWorldToScene=function(e,i){this.sceneToPhysicsWorldsMap[i.name]=this.sceneToPhysicsWorldsMap[i.name]||[],this.sceneToPhysicsWorldsMap[i.name].push(e)},GameLib.D3.Game.prototype.GetPhysicsWorldsForScene=function(e){return this.sceneToPhysicsWorldsMap[e.name]},GameLib.D3.Game.prototype.ProcessPhysics=function(e){for(var i in this.sceneToPhysicsWorldsMap){var t=this.sceneToPhysicsWorldsMap[i],n=this.scenes[i];if(n&&t)for(var s=0,o=t.length;s<o;s++){var a=t[s];a.Step(e);for(var r in a.linkedPairs){var h=a.linkedPairs[r],c=h.threeMesh,l=h.physicsBody;if(c&&a.engineType===GameLib.D3.Physics.TYPE_CANNON){var p=new THREE.Quaternion;p.copy(l.rigidBodyInstance.quaternion);var d=p.clone(),m=new THREE.Vector3;if(m.copy(l.rigidBodyInstance.position),c.permutate&&c.permutate.offset){if(c.permutate.offset.quaternion){var u=new THREE.Quaternion;u.copy(c.permutate.offset.quaternion),p=p.multiply(u).normalize()}if(c.permutate.offset.position){var f=new THREE.Vector3;f.copy(c.permutate.offset.position),m=m.add(f.applyQuaternion(d))}}c.position.copy(m),c.quaternion.copy(p)}}}}},GameLib.D3.Game.prototype.LinkPair=function(e,i,t){t.linkedPairs=t.linkedPairs||[],t.linkedPairs.push({threeMesh:e,physicsBody:i})},GameLib.D3.Graphics=function(e,i){this.graphicsType=e,this.instance=i},GameLib.D3.Graphics.prototype.isThree=function(){return this.graphicsType==GameLib.D3.Graphics.GRAPHICS_TYPE_THREE},GameLib.D3.Graphics.prototype.isNotThreeThrow=function(){if(this.graphicsType!=GameLib.D3.Graphics.GRAPHICS_TYPE_THREE)throw console.warn("Only THREE supported for this function"),new Error("Only THREE supported for this function")},GameLib.D3.Graphics.GRAPHICS_TYPE_THREE=1,GameLib.D3.Heightmap=function(e,i,t,n,s){"undefined"==typeof e&&(e=0),this.sizeX=e,"undefined"==typeof i&&(i=0),this.sizeY=i,"undefined"==typeof t&&(t=[]),this.matrix=t,"undefined"==typeof n&&(n=10),this.elementSize=n,"undefined"==typeof s&&(s=15),this.elementSize=s},GameLib.D3.Heightmap.GenerateInstanceMesh=function(e,i,t){e.isNotThreeThrow(),t.isNotCannonThrow();for(var n=new e.instance.Geometry,s=new t.instance.Vec3,o=new t.instance.Vec3,a=new t.instance.Vec3,r=0;r<i.instance.data.length-1;r++)for(var h=0;h<i.instance.data[r].length-1;h++)for(var c=0;c<2;c++){i.instance.getConvexTrianglePillar(r,h,0===c),s.copy(i.instance.pillarConvex.vertices[0]),o.copy(i.instance.pillarConvex.vertices[1]),a.copy(i.instance.pillarConvex.vertices[2]),s.vadd(i.instance.pillarOffset,s),o.vadd(i.instance.pillarOffset,o),a.vadd(i.instance.pillarOffset,a),n.vertices.push(new e.instance.Vector3(s.x,s.y,s.z),new e.instance.Vector3(o.x,o.y,o.z),new e.instance.Vector3(a.x,a.y,a.z));var l=n.vertices.length-3;n.faces.push(new e.instance.Face3(l,l+1,l+2))}return n.computeBoundingSphere(),n.computeFaceNormals(),new e.instance.Mesh(n,new e.instance.MeshNormalMaterial({wireframe:!1,shading:e.instance.SmoothShading}))},GameLib.D3.Heightmap.GenerateHeightmapDataFromImage=function(e,i,t){var n=new Image;n.onload=function(){var e=document.createElement("canvas");e.width=n.width,e.height=n.height;var s=e.getContext("2d");s.drawImage(n,0,0);for(var o=s.getImageData(0,0,n.width,n.height),a=o.data,r=[],h=0,c=a.length;h<c;h+=4)r.push(a[h]);for(var l=[],p=n.width,d=n.height,m=0;m<p;m++){l.push([]);for(var u=0;u<d;u++){var f=r[p-m+u*d]/255*i;l[m].push(f)}}t(new GameLib.D3.Heightmap(p,d,l,10,i))},n.src=e},GameLib.D3.Image=function(e,i,t,n,s){this.id=e,this.filename=t,this.textureLink=i,"undefined"==typeof n&&(n=0),this.size=n,"undefined"==typeof s&&(s="application/octet-stream",this.filename.match(/(png)$/i)&&(s="image/png"),this.filename.match(/(jpg|jpeg)$/i)&&(s="image/jpeg"),this.filename.match(/(gif)$/i)&&(s="image/gif")),this.contentType=s},GameLib.D3.Light=function(e,i,t,n,s,o,a,r,h,c,l,p,d,m,u){this.id=e,this.lightType=i,this.name=t,this.color=n,this.intensity=s,"undefined"==typeof o&&(o=new GameLib.D3.Vector3(0,0,0)),this.position=o,"undefined"==typeof a&&(a=new GameLib.D3.Vector3(0,0,0)),this.targetPosition=a,"undefined"==typeof r&&(r=new GameLib.D3.Vector4),this.quaternion=r,"undefined"==typeof h&&(h=new GameLib.D3.Vector3(0,0,0)),this.rotation=h,"undefined"==typeof c&&(c=new GameLib.D3.Vector3(1,1,1)),this.scale=c,"undefined"==typeof l&&(l=0),this.distance=l,"undefined"==typeof p&&(p=1),this.decay=p,"undefined"==typeof d&&(d=4*Math.PI),this.power=d,"undefined"==typeof m&&(m=Math.PI/3),this.angle=m,"undefined"==typeof u&&(u=0),this.penumbra=u},GameLib.D3.Material=function(e,i,t,n,s,o,a,r,h,c,l,p,d,m,u,f,y,v,L,b,g,D,G,w,T,E,x,_,P,M,S,I,V,N,R,A,z,C,Y,O,F,B,k,H,W,U,q,Q,X,J,j,Z,K,$,ee,ie,te){this.id=e,this.name=i,"undefined"==typeof t&&(t=GameLib.D3.Material.TYPE_MESH_STANDARD),this.materialType=t,"undefined"==typeof n&&(n=1),this.opacity=n,"undefined"==typeof s&&(s=GameLib.D3.Material.TYPE_FRONT_SIDE),this.side=s,"undefined"==typeof o&&(o=!1),this.transparent=o,"undefined"==typeof a&&(a={alpha:null,ao:null,bump:null,diffuse:null,displacement:null,emissive:null,environment:null,light:null,metalness:null,normal:null,roughness:null,specular:null}),this.maps=a,"undefined"==typeof r&&(r=new GameLib.D3.Color(.06,.06,.06,.06)),this.specular=r,"undefined"==typeof h&&(h=1),this.lightMapIntensity=h,"undefined"==typeof c&&(c=1),this.aoMapIntensity=c,"undefined"==typeof l&&(l=new GameLib.D3.Color(1,1,1,1)),this.color=l,"undefined"==typeof p&&(p=new GameLib.D3.Color(0,0,0,0)),this.emissive=p,"undefined"==typeof d&&(d=1),this.emissiveIntensity=d,"undefined"==typeof m&&(m=GameLib.D3.Material.TYPE_MULTIPLY_OPERATION),this.combine=m,"undefined"==typeof u&&(u=30),this.shininess=u,"undefined"==typeof f&&(f=1),this.reflectivity=f,"undefined"==typeof y&&(y=.98),this.refractionRatio=y,"undefined"==typeof v&&(v=!0),this.fog=v,"undefined"==typeof L&&(L=!1),this.wireframe=L,"undefined"==typeof b&&(b=1),this.wireframeLineWidth=b,"undefined"==typeof g&&(g="round"),this.wireframeLineCap=g,"undefined"==typeof D&&(D="round"),this.wireframeLineJoin=D,"undefined"==typeof G&&(G=GameLib.D3.Material.TYPE_NO_COLORS),this.vertexColors=G,"undefined"==typeof w&&(w=!1),this.skinning=w,"undefined"==typeof T&&(T=!1),this.morphTargets=T,"undefined"==typeof E&&(E=!1),this.morphNormals=E,"undefined"==typeof U&&(U=0),this.overdraw=U,"undefined"==typeof x&&(x=1),this.lineWidth=x,"undefined"==typeof _&&(_="round"),this.lineCap=_,"undefined"==typeof P&&(P="round"),this.lineJoin=P,"undefined"==typeof M&&(M=3),this.dashSize=M,"undefined"==typeof S&&(S=1),this.gapWidth=S,"undefined"==typeof I&&(I=GameLib.D3.Material.TYPE_NORMAL_BLENDING),this.blending=I,"undefined"==typeof V&&(V=GameLib.D3.Material.TYPE_SRC_ALPHA_FACTOR),this.blendSrc=V,"undefined"==typeof N&&(N=GameLib.D3.Material.TYPE_ONE_MINUS_SRC_ALPHA_FACTOR),this.blendDst=N,"undefined"==typeof R&&(R=GameLib.D3.Material.TYPE_ADD_EQUATION),this.blendEquation=R,"undefined"==typeof A&&(A=!0),this.depthTest=A,"undefined"==typeof z&&(z=GameLib.D3.Material.TYPE_LESS_EQUAL_DEPTH),this.depthFunc=z,"undefined"==typeof C&&(C=!0),this.depthWrite=C,"undefined"==typeof Y&&(Y=!1),this.polygonOffset=Y,"undefined"==typeof O&&(O=1),this.polygonOffsetFactor=O,"undefined"==typeof F&&(F=1),this.polygonOffsetUnits=F,"undefined"==typeof B&&(B=0),this.alphaTest=B,"undefined"==typeof k&&(k=[]),this.clippingPlanes=k,"undefined"==typeof H&&(H=!1),this.clipShadows=H,"undefined"==typeof W&&(W=!0),this.visible=W,"undefined"==typeof q&&(q=GameLib.D3.Material.TYPE_FLAT_SHADING),this.shading=q,"undefined"==typeof Q&&(Q=1),this.bumpScale=Q,"undefined"==typeof X&&(X=1),this.normalScale=X,"undefined"==typeof J&&(J=1),this.displacementScale=J,"undefined"==typeof j&&(j=0),this.displacementBias=j,"undefined"==typeof Z&&(Z=.5),this.roughness=Z,"undefined"==typeof K&&(K=.5),this.metalness=K,"undefined"==typeof $&&($=1),this.pointSize=$,"undefined"==typeof ee&&(ee=!0),this.pointSizeAttenuation=ee,"undefined"==typeof ie&&(ie=0),this.spriteRotation=ie,"undefined"==typeof te&&(te=1),this.envMapIntensity=te},GameLib.D3.Material.TYPE_MULTIPLY_OPERATION=0,GameLib.D3.Material.TYPE_MIX_OPERATION=1,GameLib.D3.Material.TYPE_ADD_OPERATION=2,GameLib.D3.Material.TYPE_NO_COLORS=0,GameLib.D3.Material.TYPE_FACE_COLORS=1,GameLib.D3.Material.TYPE_VERTEX_COLORS=2,GameLib.D3.Material.TYPE_NORMAL_BLENDING=1,GameLib.D3.Material.TYPE_ADDITIVE_BLENDING=2,GameLib.D3.Material.TYPE_SUBTRACTIVE_BLENDING=3,GameLib.D3.Material.TYPE_MULTIPLY_BLENDING=4,GameLib.D3.Material.TYPE_CUSTOM_BLENDING=5,GameLib.D3.Material.TYPE_ZERO_FACTOR=200,GameLib.D3.Material.TYPE_ONE_FACTOR=201,GameLib.D3.Material.TYPE_SRC_COLOR_FACTOR=202,GameLib.D3.Material.TYPE_ONE_MINUS_SRC_COLOR_FACTOR=203,GameLib.D3.Material.TYPE_SRC_ALPHA_FACTOR=204,GameLib.D3.Material.TYPE_ONE_MINUS_SRC_ALPHA_FACTOR=205,GameLib.D3.Material.TYPE_DST_ALPHA_FACTOR=206,GameLib.D3.Material.TYPE_ONE_MINUS_DST_ALPHA_FACTOR=207,GameLib.D3.Material.TYPE_DST_COLOR_FACTOR=208,GameLib.D3.Material.TYPE_ONE_MINUS_DST_COLOR_FACTOR=209,GameLib.D3.Material.TYPE_SRC_ALPHA_SATURATE_FACTOR=210,GameLib.D3.Material.TYPE_ADD_EQUATION=100,GameLib.D3.Material.TYPE_SUBTRACT_EQUATION=101,GameLib.D3.Material.TYPE_REVERSE_SUBTRACT_EQUATION=102,GameLib.D3.Material.TYPE_MIN_EQUATION=103,GameLib.D3.Material.TYPE_MAX_EQUATION=104,GameLib.D3.Material.TYPE_NEVER_DEPTH=0,GameLib.D3.Material.TYPE_ALWAYS_DEPTH=1,GameLib.D3.Material.TYPE_LESS_DEPTH=2,GameLib.D3.Material.TYPE_LESS_EQUAL_DEPTH=3,GameLib.D3.Material.TYPE_EQUAL_DEPTH=4,GameLib.D3.Material.TYPE_GREATER_EQUAL_DEPTH=5,GameLib.D3.Material.TYPE_GREATER_DEPTH=6,GameLib.D3.Material.TYPE_NOT_EQUAL_DEPTH=7,GameLib.D3.Material.TYPE_FRONT_SIDE=0,GameLib.D3.Material.TYPE_BACK_SIDE=1,GameLib.D3.Material.TYPE_DOUBLE_SIDE=2,GameLib.D3.Material.TYPE_FLAT_SHADING=1,GameLib.D3.Material.TYPE_SMOOTH_SHADING=2,GameLib.D3.Material.TYPE_LINE_BASIC="LineBasicMaterial",GameLib.D3.Material.TYPE_LINE_DASHED="LineDashedMaterial",GameLib.D3.Material.TYPE_MESH_BASIC="MeshBasicMaterial",GameLib.D3.Material.TYPE_MESH_DEPTH="MeshDepthMaterial",GameLib.D3.Material.TYPE_MESH_LAMBERT="MeshLambertMaterial",GameLib.D3.Material.TYPE_MESH_NORMAL="MeshNormalMaterial",GameLib.D3.Material.TYPE_MESH_PHONG="MeshPhongMaterial",GameLib.D3.Material.TYPE_MESH_STANDARD="MeshStandardMaterial",GameLib.D3.Material.TYPE_POINTS="PointsMaterial",GameLib.D3.Material.TYPE_SPRITE="SpriteMaterial",GameLib.D3.Material.TYPE_MULTI_MATERIAL="MultiMaterial",GameLib.D3.Material.createInstanceMaterial=function(e,i,t,n){var s=Q.defer(),o=null,a=[];if(e.materialType==GameLib.D3.Material.TYPE_MESH_STANDARD?(o=new i.instance.MeshStandardMaterial({name:e.name,opacity:e.opacity,transparent:e.transparent,blending:e.blending,blendSrc:e.blendSrc,blendDst:e.blendDst,blendEquation:e.blendEquation,depthTest:e.depthTest,depthFunc:e.depthFunc,depthWrite:e.depthWrite,polygonOffset:e.polygonOffset,polygonOffsetFactor:e.polygonOffsetFactor,polygonOffsetUnits:e.polygonOffsetUnits,alphaTest:e.alphaTest,clippingPlanes:e.clippingPlanes,clipShadows:e.clipShadows,overdraw:e.overdraw,visible:e.visible,side:e.side,color:new i.instance.Color(e.color.r,e.color.g,e.color.b),roughness:e.roughness,metalness:e.metalness,lightMapIntensity:e.lightMapIntensity,aoMapIntensity:e.aoMapIntensity,emissive:new i.instance.Color(e.emissive.r,e.emissive.g,e.emissive.b),emissiveIntensity:e.emissiveIntensity,bumpScale:e.bumpScale,normalScale:e.normalScale,displacementScale:e.displacementScale,refractionRatio:e.refractionRatio,fog:e.fog,shading:e.shading,wireframe:e.wireframe,wireframeLinewidth:e.wireframeLineWidth,wireframeLinecap:e.wireframeLineCap,wireframeLinejoin:e.wireframeLineJoin,vertexColors:e.vertexColors,skinning:e.skinning,morphTargets:e.morphTargets,morphNormals:e.morphNormals}),a.push("diffuse","light","ao","emissive","bump","normal","displacement","roughness","metalness","alpha","environment")):e.materialType==GameLib.D3.Material.TYPE_MESH_PHONG?(o=new i.instance.MeshPhongMaterial({name:e.name,opacity:e.opacity,transparent:e.transparent,blending:e.blending,blendSrc:e.blendSrc,blendDst:e.blendDst,blendEquation:e.blendEquation,depthTest:e.depthTest,depthFunc:e.depthFunc,depthWrite:e.depthWrite,polygonOffset:e.polygonOffset,polygonOffsetFactor:e.polygonOffsetFactor,polygonOffsetUnits:e.polygonOffsetUnits,alphaTest:e.alphaTest,clippingPlanes:e.clippingPlanes,clipShadows:e.clipShadows,overdraw:e.overdraw,visible:e.visible,side:e.side,color:new i.instance.Color(e.color.r,e.color.g,e.color.b),specular:new i.instance.Color(e.specular.r,e.specular.g,e.specular.b),shininess:e.shininess,lightMapIntensity:e.lightMapIntensity,aoMapIntensity:e.aoMapIntensity,emissive:new i.instance.Color(e.emissive.r,e.emissive.g,e.emissive.b),emissiveIntensity:e.emissiveIntensity,bumpScale:e.bumpScale,normalScale:e.normalScale,displacementScale:e.displacementScale,combine:e.combine,refractionRatio:e.refractionRatio,fog:e.fog,shading:e.shading,wireframe:e.wireframe,wireframeLinewidth:e.wireframeLineWidth,wireframeLinecap:e.wireframeLineCap,wireframeLinejoin:e.wireframeLineJoin,vertexColors:e.vertexColors,skinning:e.skinning,morphTargets:e.morphTargets,morphNormals:e.morphNormals}),a.push("diffuse","light","ao","emissive","bump","normal","displacement","specular","alpha","environment")):console.log("material type is not implemented yet: "+e.materialType+" - material indexes could be screwed up"),a.length>0){var r=GameLib.D3.Texture.loadMaps(e,a,o,i,t,n);Q.all(r).then(function(){s.resolve(o)}).catch(function(e){console.log(e),s.reject(e)})}else s.resolve(o);return s.promise},GameLib.D3.Matrix3=function(e,i,t){this.identity(),e&&(this.rows[0]=e),i&&(this.rows[1]=i),t&&(this.rows[2]=t)},GameLib.D3.Matrix3.prototype.identity=function(){this.rows=[new GameLib.D3.Vector4(1,0,0),new GameLib.D3.Vector4(0,1,0),new GameLib.D3.Vector4(0,0,1)]},GameLib.D3.Matrix4=function(e,i,t,n){this.identity(),e&&(this.rows[0]=e),i&&(this.rows[1]=i),t&&(this.rows[2]=t),n&&(this.rows[3]=n)},GameLib.D3.Matrix4.prototype.rotationMatrixX=function(e){return this.identity(),this.rows[1]=new GameLib.D3.Vector4(0,Math.cos(e),-1*Math.sin(e),0),this.rows[2]=new GameLib.D3.Vector4(0,Math.sin(e),Math.cos(e),0),this},GameLib.D3.Matrix4.prototype.rotationMatrixY=function(e){return this.identity(),this.rows[0]=new GameLib.D3.Vector4(Math.cos(e),0,Math.sin(e),0),this.rows[2]=new GameLib.D3.Vector4(-1*Math.sin(e),0,Math.cos(e),0),this},GameLib.D3.Matrix4.prototype.rotationMatrixZ=function(e){return this.identity(),this.rows[0]=new GameLib.D3.Vector4(Math.cos(e),-1*Math.sin(e),0,0),this.rows[1]=new GameLib.D3.Vector4(Math.sin(e),Math.cos(e),0,0),this},GameLib.D3.Matrix4.prototype.rotateX=function(e,i){return this.identity(),this.rotationMatrixX(e),this.multiply(i)},GameLib.D3.Matrix4.prototype.rotateY=function(e,i){return this.identity(),this.rotationMatrixY(e),this.multiply(i)},GameLib.D3.Matrix4.prototype.rotateZ=function(e,i){return this.identity(),this.rotationMatrixZ(e),this.multiply(i)},GameLib.D3.Matrix4.prototype.multiply=function(e){return e instanceof GameLib.D3.Vector4?new GameLib.D3.Vector4(this.rows[0].x*e.x+this.rows[0].y*e.y+this.rows[0].z*e.z+this.rows[0].w*e.w,this.rows[1].x*e.x+this.rows[1].y*e.y+this.rows[1].z*e.z+this.rows[1].w*e.w,this.rows[2].x*e.x+this.rows[2].y*e.y+this.rows[2].z*e.z+this.rows[2].w*e.w,this.rows[3].x*e.x+this.rows[3].y*e.y+this.rows[3].z*e.z+this.rows[3].w*e.w):e instanceof GameLib.D3.Vector3?new GameLib.D3.Vector3(this.rows[0].x*e.x+this.rows[0].y*e.y+this.rows[0].z*e.z,this.rows[1].x*e.x+this.rows[1].y*e.y+this.rows[1].z*e.z,this.rows[2].x*e.x+this.rows[2].y*e.y+this.rows[2].z*e.z):void 0},GameLib.D3.Matrix4.prototype.identity=function(){this.rows=[new GameLib.D3.Vector4(1,0,0,0),new GameLib.D3.Vector4(0,1,0,0),new GameLib.D3.Vector4(0,0,1,0),new GameLib.D3.Vector4(0,0,0,1)]},GameLib.D3.Matrix4.prototype.lookAt=function(e,i,t){var n=new GameLib.D3.Vector3(e.x,e.y,e.z),s=n.subtract(i).normalize();0===s.squared()&&(s.z=1);var o=t.cross(s).normalize();0===o.squared()&&(s.x+=1e-4,o=t.cross(s).normalize());var a=s.cross(o);return this.rows[0].x=o.x,this.rows[0].y=o.y,this.rows[0].z=o.z,this.rows[1].x=a.x,this.rows[1].y=a.y,this.rows[1].z=a.z,this.rows[2].x=s.x,this.rows[2].y=s.y,this.rows[2].z=s.z,this},GameLib.D3.Mesh=function(e,i,t,n,s,o,a,r,h,c,l,p,d,m,u,f,y,v,L){this.id=e,this.meshId=GameLib.D3.Tools.RandomId(),this.path=i,this.name=t,this.meshType=n,this.vertices=s,this.faces=o,"undefined"==typeof a&&(a=null),this.skeleton=a,"undefined"==typeof r&&(r=[]),this.faceVertexUvs=r,"undefined"==typeof h&&(h=[]),this.skinIndices=h,"undefined"==typeof c&&(c=[]),this.skinWeights=c,"undefined"==typeof l&&(l=[]),this.materials=l,"undefined"==typeof p&&(p=new GameLib.D3.Vector3(0,0,0)),this.position=p,"undefined"==typeof d&&new GameLib.D3.Vector4,this.quaternion=d,"undefined"==typeof m&&(m=new GameLib.D3.Vector3(0,0,0)),this.rotation=m,"undefined"==typeof u&&(u=new GameLib.D3.Vector3(1,1,1)),this.scale=u,"undefined"==typeof f&&(f=new GameLib.D3.Vector3(0,1,0)),this.up=f,this.physics=y,this.parentMeshId=v,this.parentSceneId=L},GameLib.D3.Mesh.TYPE_NORMAL=0,GameLib.D3.Mesh.TYPE_SKINNED=1,GameLib.D3.Mesh.createInstanceMesh=function(e,i,t,n){var s=null;if(e.meshType==GameLib.D3.Mesh.TYPE_NORMAL&&(s=new n.instance.Mesh(i,t)),e.meshType==GameLib.D3.Mesh.TYPE_SKINNED){for(var o=e.skeleton.bones,a=e.skinIndices,r=e.skinWeights,h=[],c=0;c<o.length;c++){var l=new n.instance.Bone;l.name=o[c].name,l.position.x=o[c].position.x,l.position.y=o[c].position.y,l.position.z=o[c].position.z,l.rotation.x=o[c].rotation.x,l.rotation.y=o[c].rotation.y,l.rotation.z=o[c].rotation.z,l.quaternion.x=o[c].quaternion.x,l.quaternion.y=o[c].quaternion.y,l.quaternion.z=o[c].quaternion.z,l.quaternion.w=o[c].quaternion.w,l.scale.x=o[c].scale.x,l.scale.y=o[c].scale.y,l.scale.z=o[c].scale.z,l.up.x=o[c].up.x,l.up.y=o[c].up.y,l.up.z=o[c].up.z,h.push(l)}for(var p=0;p<o.length;p++)for(var d=0;d<o[p].childBoneIds.length;d++)h[p].add(h[o[p].childBoneIds[d]]);for(var m=0;m<a.length;m++)i.skinIndices.push(new n.instance.Vector4(a[m].x,a[m].y,a[m].z,a[m].w));for(var u=0;u<r.length;u++)i.skinWeights.push(new n.instance.Vector4(r[u].x,r[u].y,r[u].z,r[u].w));s=new n.instance.SkinnedMesh(i,t);var f=new n.instance.Skeleton(h);f.useVertexTexture=e.skeleton.useVertexTexture;for(var y=0;y<o.length;y++)if(null===o[y].parentBoneId){s.add(h[y]);break}s.bind(f),s.pose(),s.skeleton.skeletonHelper=new n.instance.SkeletonHelper(s),s.skeleton.skeletonHelper.material.linewidth=5}return null==s&&console.log("cannot handle meshes of type "+e.meshType+" yet."),e.threeMeshId=s.id,s},GameLib.D3.prototype.invertWindingOrder=function(e){for(var i=0;i<e.length;i++){var t=e[i].v1;e[i].v1=e[i].v2,e[i].v2=t;var n=e[i].triangle.v1uv;e[i].triangle.v1uv=e[i].triangle.v2uv,e[i].triangle.v2uv=n}return e},GameLib.D3.prototype.resetWindingOrder=function(e,i){for(var t=new GameLib.D3.Vector3.Points,n=0;n<i.length;n++)t.add(new GameLib.D3.Vector3(i[n].position.x,i[n].position.y,i[n].position.z));for(var s=t.average(),o=[],a=0;a<e.length;a+=3){var r=e[a],h=e[a+1],c=e[a+2];o.push({v0:r,v1:h,v2:c,edges:[{v0:r,v1:h},{v0:h,v1:c},{v0:c,v1:r}],winding:0,edgeIndex:-1,processed:!1})}for(var l=0;l<o.length;l++)if(GameLib.D3.Vector3.clockwise(i[o[l].v0].position,i[o[l].v1].position,i[o[l].v2].position,s)){console.log("clockwise");var p=o[l].v1;o[l].v1=o[l].v2,o[l].v2=p}else console.log("not clockwise");return o},GameLib.D3.fixWindingOrder=function(e,i){function t(e,i){for(var t=0;t<e.length;t++)if(e[t].triangle.equals(i))return!0;return!1}function n(e,i,t){for(var n=0;n<i.length;n++)if(i[n].v0==e.x&&i[n].v1==e.y||i[n].v1==e.x&&i[n].v2==e.y||i[n].v2==e.x&&i[n].v0==e.y||i[n].v0==e.y&&i[n].v1==e.x||i[n].v1==e.y&&i[n].v2==e.x||i[n].v2==e.y&&i[n].v0==e.x){var s=new GameLib.D3.TriangleFace(i[n].v0,i[n].v1,i[n].v2,i[n].materialIndex,i[n].v0uv,i[n].v1uv,i[n].v2uv);if(s.equals(t))continue;return new GameLib.D3.TriangleEdge(s,e)}return null}for(var s=[new GameLib.D3.TriangleEdge(new GameLib.D3.TriangleFace(e[0].v0,e[0].v1,e[0].v2,e[0].materialIndex,e[0].v0uv,e[0].v1uv,e[0].v2uv),i)],o=[];s.length>0;){var a=s.pop();if(a.triangle.v0==a.edge.x&&a.triangle.v1==a.edge.y||a.triangle.v1==a.edge.x&&a.triangle.v2==a.edge.y||a.triangle.v2==a.edge.x&&a.triangle.v0==a.edge.y){var r=a.triangle.v1;a.triangle.v1=a.triangle.v2,a.triangle.v2=r;var h=a.triangle.v1uv;a.triangle.v1uv=a.triangle.v2uv,a.triangle.v2uv=h}o.push(a);for(var c=[new GameLib.D3.Vector2(a.triangle.v0,a.triangle.v1),new GameLib.D3.Vector2(a.triangle.v1,a.triangle.v2),new GameLib.D3.Vector2(a.triangle.v2,a.triangle.v0)],l=0;l<c.length;l++){var p=n(c[l],e,a.triangle);p&&!t(o,p.triangle)&&s.push(p)}}for(var d=[],m=0;m<o.length;m++){for(var u=!1,f=0;f<d.length;f++)if(d[f].equals(o[m].triangle)){u=!0;break}u||d.push(o[m].triangle)}return d},GameLib.D3.fixPolyZPlane=function(e,i){e.length%3==0||e.length>9||console.log("The vertices are not in the right length : "+e.length);for(var t=[],n=new GameLib.D3.Vector4.Points,s=0;s<e.length;s+=3)n.add(new GameLib.D3.Vector3(e[s],e[s+1],e[s+2]));for(n.toOrigin(),n.maximizeXDistance(i),n.maximizeYDistance(i),s=0;s<n.vectors.length;s++)t.push([n.vectors[s].x,n.vectors[s].y]);return t},GameLib.D3.Physics=function(e,i,t,n){this.id=e,this.name=i,this.engine=t,"undefined"==typeof n&&(n=[]),this.worlds=n},GameLib.D3.Physics.SPLIT_SOLVER=1,GameLib.D3.Physics.GS_SOLVER=2,GameLib.D3.PolyVertex=function(e,i,t,n,s){this.localIndex=e,this.mvertIndex=i,this.uv=t,this.materialIndex=n,this.edgeIndex=s},GameLib.D3.PolyVertex.prototype.clone=function(){return new GameLib.D3.PolyVertex(this.localIndex,this.mvertIndex,this.uv.copy(),this.materialIndex,this.edgeIndex)},GameLib.D3.RaycastVehicle=function(e,i,t){this.engine=e,this.engine.isNotCannonThrow(),this.componentId=GameLib.D3.Tools.RandomId(),this.chassisBody=i,"undefined"==typeof t&&(t=[]),this.wheels=t,this.instance=this.createInstance()},GameLib.D3.RaycastVehicle.prototype.createInstance=function(){return new this.engine.instance.RaycastVehicle({chassisBody:this.chassisBody.instance})},GameLib.D3.RaycastVehicle.prototype.addWheel=function(e){this.wheels.push(e),this.instance.addWheel(e.instance)},GameLib.D3.RaycastVehicle.prototype.getWheelInfo=function(){return this.instance.wheelInfos},GameLib.D3.RaycastWheel=function(e,i,t,n,s,o,a,r,h,c,l,p,d,m,u,f,y,v,L,b,g,D,G,w,T,E,x,_){this.engine=e,this.engine.isNotCannonThrow(),this.componentId=GameLib.D3.Tools.RandomId(),"undefined"==typeof i&&(i=new this.engine.instance.Vec3),this.chassisConnectionPointLocal=i,"undefined"==typeof t&&(t=new this.engine.instance.Vec3),this.chassisConnectionPointWorld=t,"undefined"==typeof n&&(n=new this.engine.instance.Vec3),this.directionLocal=n,"undefined"==typeof s&&(s=new this.engine.instance.Vec3),this.directionWorld=s,"undefined"==typeof o&&(o=new this.engine.instance.Vec3),this.axleLocal=o,"undefined"==typeof a&&(a=new this.engine.instance.Vec3),this.axleWorld=a,"undefined"==typeof r&&(r=1),this.suspensionRestLength=r,"undefined"==typeof h&&(h=2),this.suspensionMaxLength=h,"undefined"==typeof c&&(c=1),this.radius=c,"undefined"==typeof l&&(l=100),this.suspensionStiffness=l,"undefined"==typeof p&&(p=10),this.dampingCompression=p,"undefined"==typeof d&&(d=10),this.dampingRelaxation=d,"undefined"==typeof m&&(m=1e4),this.frictionSlip=m,"undefined"==typeof u&&(u=0),this.steering=u,"undefined"==typeof f&&(f=0),this.rotation=f,"undefined"==typeof y&&(y=0),this.deltaRotation=y,"undefined"==typeof v&&(v=.01),this.rollInfluence=v,"undefined"==typeof L&&(L=Number.MAX_VALUE),this.maxSuspensionForce=L,"undefined"==typeof b&&(b=!0),this.isFrontWheel=b,"undefined"==typeof g&&(g=1),this.clippedInvContactDotSuspension=g,"undefined"==typeof D&&(D=0),this.suspensionRelativeVelocity=D,"undefined"==typeof G&&(G=0),this.suspensionForce=G,"undefined"==typeof w&&(w=0),this.skidInfo=w,"undefined"==typeof T&&(T=0),this.suspensionLength=T,"undefined"==typeof E&&(E=1),this.maxSuspensionTravel=E,"undefined"==typeof x&&(x=!1),this.useCustomSlidingRotationalSpeed=x,"undefined"==typeof _&&(_=-.1),this.customSlidingRotationalSpeed=_,this.instance=this.createInstance()},GameLib.D3.RaycastWheel.prototype.createInstance=function(){return new this.engine.instance.WheelInfo({chassisConnectionPointLocal:this.chassisConnectionPointLocal,chassisConnectionPointWorld:this.chassisConnectionPointWorld,directionLocal:this.directionLocal,directionWorld:this.directionWorld,axleLocal:this.axleLocal,axleWorld:this.axleWorld,suspensionRestLength:this.suspensionRestLength,suspensionMaxLength:this.suspensionMaxLength,radius:this.radius,suspensionStiffness:this.suspensionStiffness,dampingCompression:this.dampingCompression,dampingRelaxation:this.dampingRelaxation,frictionSlip:this.frictionSlip,steering:this.steering,rotation:this.rotation,deltaRotation:this.deltaRotation,rollInfluence:this.rollInfluence,maxSuspensionForce:this.maxSuspensionForce,isFrontWheel:this.isFrontWheel,clippedInvContactDotSuspension:this.clippedInvContactDotSuspension,suspensionRelativeVelocity:this.suspensionRelativeVelocity,suspensionForce:this.suspensionForce,skidInfo:this.skidInfo,suspensionLength:this.suspensionLength,maxSuspensionTravel:this.maxSuspensionTravel,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"==typeof t&&(t=[]),this.wheels=t,this.instance=this.createInstance()},GameLib.D3.RigidBodyVehicle.prototype.getWheelInfo=function(){return this.instance.wheelBodies},GameLib.D3.RigidBodyVehicle.prototype.createInstance=function(){return new this.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:new this.engine.instance.Vec3(e.position.x,e.position.y,e.position.z),axis:new this.engine.instance.Vec3(e.axis.x,e.axis.y,e.axis.z),direction:new this.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||new GameLib.D3.Vector3,this.velocity=o||new GameLib.D3.Vector3,this.angularVelocity=a||new GameLib.D3.Vector3,this.quaternion=s||new GameLib.D3.Vector4(0,0,0,1),this.mass="undefined"==typeof i?0:i,this.friction="undefined"==typeof t?5:t,this.linearDamping="undefined"==typeof r?.01:r,this.angularDamping="undefined"==typeof h?.01:h,this.allowSleep="undefined"==typeof c||c,this.sleepSpeedLimit="undefined"==typeof l?.1:l,this.sleepTimeLimit="undefined"==typeof p?1:p,this.collisionFilterGroup="undefined"==typeof d?1:d,this.collisionFilterMask="undefined"==typeof m?1:m,this.fixedRotation="undefined"!=typeof u&&u,this.shape="undefined"==typeof f?null:f,this.engine=e,this.engine.isNotCannonThrow(),this.instance=this.createInstance()},GameLib.D3.RigidBody.prototype.createInstance=function(){var e=new this.engine.instance.Body({mass:mass,friction:this.friction,position:new this.engine.instance.Vec3(this.position.x,this.position.y,this.position.z),velocity:new this.engine.instance.Vec3(this.velocity.x,this.velocity.y,this.velocity.z),quaternion:new this.engine.instance.Quaternion(this.quaternion.x,this.quaternion.y,this.quaternion.z,this.quaternion.w),angularVelocity:new this.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});return this.instance=e,e},GameLib.D3.RigidBody.prototype.addShape=function(e,i,t){i||(i=new GameLib.D3.Vector3(0,0,0)),t||(t=new GameLib.D3.Vector4(0,0,0,1)),this.instance.addShape(e.instance,new this.engine.instance.Vec3(i.x,i.y,i.z),new this.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"==typeof n&&(n=[]),this.meshes=n,"undefined"==typeof s&&(s=new GameLib.D3.Vector4),this.quaternion=s,"undefined"==typeof o&&(o=new GameLib.D3.Vector3(0,0,0)),this.position=o,"undefined"==typeof a&&(a=new GameLib.D3.Vector3(0,0,0)),this.rotation=a,"undefined"==typeof r&&(r=new GameLib.D3.Vector3(1,1,1)),this.scale=r,"undefined"==typeof h&&(h=null),this.parentSceneId=h,"undefined"==typeof c&&(c=[]),this.lights=c,"undefined"==typeof l&&(l=[]),this.worlds=l,"undefined"==typeof p&&(p=[]),this.entities=p},GameLib.D3.Scene.LoadSceneFromApi=function(e,i,t,n,s,o){if("undefined"==typeof XMLHttpRequest)return console.warn("implement server side loading from API here"),i(null,new Error("not implemented"));var a=new XMLHttpRequest;a.open("GET",o+"/scene/load"+e.path+"/"+e.name),a.onreadystatechange=function(e){return function(){if(4==e.readyState){var o=JSON.parse(e.responseText);if(!o.scene||0==o.scene.length)return i(null,null,new Error("Could not load scene"));var a=o.scene[0],r=[];if(a.physics&&a.physics.length>0)for(var h=0;h<a.physics.length;h++){var c=a.physics[h],l=null;c.engine.engineType==GameLib.D3.Engine.ENGINE_TYPE_CANNON&&(l=new GameLib.D3.Engine(GameLib.D3.Engine.ENGINE_TYPE_CANNON,CANNON));for(var p=new GameLib.D3.Physics(c.id,c.name,l,null),d=[],m=0;m<c.worlds.length;m++){for(var u=c.worlds[m],f=u.broadphase,y=new GameLib.D3.Physics.Broadphase(f.id,f.name,f.broadphaseType),v=u.solver,L=new GameLib.D3.Physics.Solver(v.id,v.name,v.solverType,v.iterations,v.tolerance),b=u.rigidBodies,g=[],D=0;D<b.length;D++){var G=b[D],w=new GameLib.D3.Physics.RigidBody(G.id,G.name);g.push(w)}var T=new GameLib.D3.Physics.World(null,u.name,p,new GameLib.D3.Vector3(u.gravity.x,u.gravity.y,u.gravity.z),y,L,g);d.push(T)}r.push(p)}for(var E=[],x=0;x<a.lights.length;x++){var _=a.lights[x],P=new GameLib.D3.Light(_.id,_.lightType,_.name,new GameLib.D3.Color(_.color.r,_.color.g,_.color.b,_.color.a),_.intensity,new GameLib.D3.Vector3(_.position.x,_.position.y,_.position.z),new GameLib.D3.Vector3(_.targetPosition.x,_.targetPosition.y,_.targetPosition.z),new GameLib.D3.Vector4(_.quaternion.x,_.quaternion.y,_.quaternion.z,_.quaternion.w),new GameLib.D3.Vector3(_.rotation.x,_.rotation.y,_.rotation.z),new GameLib.D3.Vector3(_.scale.x,_.scale.y,_.scale.z),_.distance,_.decay,_.power,_.angle,_.penumbra);E.push(P)}var M=new GameLib.D3.Scene(a._id||a.id,a.path,a.name,a.meshes,new GameLib.D3.Vector4(a.quaternion.x,a.quaternion.y,a.quaternion.z,a.quaternion.w),new GameLib.D3.Vector3(a.position.x,a.position.y,a.position.z),new GameLib.D3.Vector3(a.rotation.x,a.rotation.y,a.rotation.z),new GameLib.D3.Vector3(a.scale.x,a.scale.y,a.scale.z),a.parentSceneId,E,r);GameLib.D3.Scene.loadScene(M,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(var a=[],r=0;r<e.meshes.length;r++){var h=e.meshes[r];console.log("loading mesh "+h.name);for(var c=new n.instance.Geometry,l=h.vertices,p=h.faces,d=h.faceVertexUvs,m=h.materials,u=0;u<l.length;u++)c.vertices.push(new n.instance.Vector3(l[u].position.x,l[u].position.y,l[u].position.z));for(var f=0;f<p.length;f++){var y=new n.instance.Face3(p[f].v0,p[f].v1,p[f].v2,new n.instance.Vector3(p[f].normal.x,p[f].normal.y,p[f].normal.z),new n.instance.Color(p[f].color.r,p[f].color.g,p[f].color.b),p[f].materialIndex);y.vertexColors=[new n.instance.Color(p[f].vertexColors[0].r,p[f].vertexColors[0].g,p[f].vertexColors[0].b),new n.instance.Color(p[f].vertexColors[1].r,p[f].vertexColors[1].g,p[f].vertexColors[1].b),new n.instance.Color(p[f].vertexColors[2].r,p[f].vertexColors[2].g,p[f].vertexColors[2].b)],y.normal=new n.instance.Vector3(p[f].normal.x,p[f].normal.y,p[f].normal.z),y.vertexNormals=[new n.instance.Vector3(p[f].vertexNormals[0].x,p[f].vertexNormals[0].y,p[f].vertexNormals[0].z),new n.instance.Vector3(p[f].vertexNormals[1].x,p[f].vertexNormals[1].y,p[f].vertexNormals[1].z),new n.instance.Vector3(p[f].vertexNormals[2].x,p[f].vertexNormals[2].y,p[f].vertexNormals[2].z)],c.faces.push(y)}c.faceVertexUvs=[];for(var v=0;v<d.length;v++){var L=d[v];c.faceVertexUvs[v]=[];for(var b=0;b<L.length;b++)c.faceVertexUvs[v][b]=[],c.faceVertexUvs[v][b].push(new n.instance.Vector2(L[b][0].x,L[b][0].y),new n.instance.Vector2(L[b][1].x,L[b][1].y),new n.instance.Vector2(L[b][2].x,L[b][2].y))}t&&(c.computeFaceNormals(),c.computeVertexNormals());for(var g=[],D=0;D<m.length;D++)g.push(GameLib.D3.Material.createInstanceMaterial(m[D],n,s,o));var G=Q.all(g).then(function(e,i){return function(t){console.log("loaded material : "+t[0].name);var s=t[0],o=GameLib.D3.Mesh.createInstanceMesh(e,i,s,n);return o.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(G)}Q.all(a).then(function(t){if(console.log("all meshes have loaded"),"undefined"!=typeof i){for(var s=[],o=0;o<e.lights.length;o++){var a=e.lights[o],r=null;"AmbientLight"==a.lightType&&(r=new n.instance.AmbientLight(a.color,a.intensity)),"DirectionalLight"==a.lightType&&(r=new n.instance.DirectionalLight(a.color,a.intensity)),"PointLight"==a.lightType&&(r=new n.instance.PointLight(a.color,a.intensity),r.distance=a.distance,r.decay=a.decay),"SpotLight"==a.lightType&&(r=new n.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))}var h=new n.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(var c=0;c<t.length;c++)h.add(t[c]);for(var l=0;l<s.length;l++)h.add(s[l]);i(e,{scene:h,lights:s,meshes:t})}}).catch(function(e){console.log(e)})},GameLib.D3.Shape=function(e,i,t,n,s,o,a,r,h,c,l,p){this.engine=e,this.engine.isNotCannonThrow(),this.shapeType=i,this.instance=this.createInstance(),"undefined"==typeof t&&(t=new GameLib.D3.Vector3(1,1,1)),this.scale=t,"undefined"==typeof n&&(n=[]),this.vertices=n,"undefined"==typeof s&&(s=[]),this.indices=s,"undefined"==typeof o&&(o=1),this.radius=o,"undefined"==typeof a&&(a=new GameLib.D3.Vector3(1,1,1)),this.halfExtensions=a,"undefined"==typeof r&&(r=1),this.radiusTop=r,"undefined"==typeof h&&(h=1),this.radiusBottom=h,"undefined"==typeof c&&(c=1),this.height=c,"undefined"==typeof l&&(l=1),this.numSegments=l,"undefined"==typeof p&&(p=new GameLib.D3.Heightmap),this.heightmap=p},GameLib.D3.Shape.SHAPE_TYPE_SPHERE=1,GameLib.D3.Shape.SHAPE_TYPE_BOX=2,GameLib.D3.Shape.SHAPE_TYPE_TRIMESH=3,GameLib.D3.Shape.SHAPE_TYPE_CYLINDER=4,GameLib.D3.Shape.SHAPE_TYPE_HEIGHT_MAP=5,GameLib.D3.Shape.SHAPE_TYPE_CONVEX_HULL=6,GameLib.D3.Shape.prototype.createInstance=function(){var e=null;if(this.shapeType==GameLib.D3.Shape.SHAPE_TYPE_TRIMESH)e=new this.engine.instance.Trimesh(this.vertices,this.indices);else if(this.shapeType==GameLib.D3.Shape.SHAPE_TYPE_SPHERE)e=new this.engine.instance.Sphere(this.radius);else if(this.shapeType==GameLib.D3.Shape.SHAPE_TYPE_BOX)e=new this.engine.instance.Box(new this.engine.instance.Vec3(this.halfExtensions.x,this.halfExtensions.y,this.halfExtensions.z));else if(this.shapeType==GameLib.D3.Shape.SHAPE_TYPE_CYLINDER)e=new this.engine.instance.Cylinder(this.radiusTop,this.radiusBottom,this.height,this.numSegments);else{if(this.shapeType!=GameLib.D3.Shape.SHAPE_TYPE_HEIGHT_MAP)throw this.shapeType==GameLib.D3.Shape.SHAPE_TYPE_CONVEX_HULL?(console.warn("Shape type not implemented: "+this.shapeType),new Error("Shape type not implemented: "+this.shapeType)):(console.warn("Shape type not implemented: "+this.shapeType),new Error("Shape type not implemented: "+this.shapeType));e=new this.engine.instance.Heightfield(this.heightmap.matrix,{elementSize:this.heightmap.elementSize})}return this.instance=e,e},GameLib.D3.Shape.prototype.update=function(e){e.isNotCannonThrow(),this.shapeType===GameLib.D3.Shape.SHAPE_TYPE_TRIMESH&&(this.instance.setScale(new e.instance.Vec3(this.scale.x,this.scale.y,this.scale.z)),this.instance.updateAABB(),this.instance.updateNormals(),this.instance.updateEdges(),this.instance.updateBoundingSphereRadius(),this.instance.updateTree())},GameLib.D3.Skeleton=function(e,i,t,n,s,o,a,r){this.id=e,this.bones=i,"undefined"==typeof t&&(t=[]),this.boneInverses=t,"undefined"==typeof n&&(n=!1),this.useVertexTexture=n,1==this.useVertexTexture&&console.warn("support for vertex texture bones is not supported yet - something could break somewhere"),"undefined"==typeof s&&(s=0),this.boneTextureWidth=s,"undefined"==typeof o&&(o=0),this.boneTextureHeight=o,"undefined"==typeof a&&(a=[]),this.boneMatrices=a,"undefined"==typeof r&&(r=[]),this.boneTexture=r},GameLib.D3.SkyBox=function(e){this.id=null,this.graphics=e,this.graphics.isNotThreeThrow(),this.texturesFolder=null},GameLib.D3.SkyBox.prototype.load=function(e){this.texturesFolder=e,this.textures=[],this.materials=[],this.mesh={},this.scene=new this.graphics.instance.Scene,this.textureCube=null;var i=new this.graphics.instance.TextureLoader;this.textures.push(i.load(this.texturesFolder+"px.png")),this.textures.push(i.load(this.texturesFolder+"nx.png")),this.textures.push(i.load(this.texturesFolder+"py.png")),this.textures.push(i.load(this.texturesFolder+"ny.png")),this.textures.push(i.load(this.texturesFolder+"pz.png")),this.textures.push(i.load(this.texturesFolder+"nz.png"));for(var t=0;t<6;t++)this.materials.push(new this.graphics.instance.MeshBasicMaterial({map:this.textures[t]}));this.mesh=new this.graphics.instance.Mesh(new this.graphics.instance.CubeGeometry(1,1,1),new this.graphics.instance.MeshFaceMaterial(this.materials)),this.mesh.applyMatrix((new this.graphics.instance.Matrix4).makeScale(1,1,-1)),this.scene.add(this.mesh),this.textureCube=(new this.graphics.instance.CubeTextureLoader).load([this.texturesFolder+"px.png",this.texturesFolder+"nx.png",this.texturesFolder+"py.png",this.texturesFolder+"ny.png",this.texturesFolder+"pz.png",this.texturesFolder+"nz.png"])},GameLib.D3.SkyBox.prototype.render=function(e,i){var t=new this.graphics.instance.Vector3(i.position.x,i.position.y,i.position.z);i.position.set(0,0,0);var n=e.context;n.disable(n.DEPTH_TEST),e.render(this.scene,i),n.enable(n.DEPTH_TEST),i.position.copy(t)},GameLib.D3.Solver=function(e,i,t,n,s,o){this.id=e,this.engine=i,this.engine.isNotCannonThrow(),"undefined"==typeof t&&(t=GameLib.D3.Solver.GS_SOLVER),this.solverType=t,"undefined"==typeof n&&(n=this.solverType==GameLib.D3.Solver.SPLIT_SOLVER?"split solver":this.solverType==GameLib.D3.Solver.GS_SOLVER?"gs solver":"unknown solver"),this.name=n,"undefined"==typeof s&&(s=10),this.iterations=s,"undefined"==typeof o&&(o=1e-7),this.tolerance=o,this.instance=this.createInstance(),this.instance.tolerance=o,this.instance.iterations=s},GameLib.D3.Solver.prototype.createInstance=function(){var e=null;if(this.solverType==GameLib.D3.Solver.SPLIT_SOLVER)e=new this.engine.instance.SplitSolver;else{if(this.solverType!=GameLib.D3.Solver.GS_SOLVER)throw console.warn("Unsupported solver type: "+this.solverType),new Error("Unsupported solver type: "+this.solverType);e=new this.engine.instance.GSSolver}return e},GameLib.D3.Solver.SPLIT_SOLVER=1,GameLib.D3.Solver.GS_SOLVER=2,GameLib.D3.Texture=function(e,i,t,n,s,o,a,r,h,c,l,p,d,m,u,f,y,v,L,b){this.id=e,this.name=i,this.image=t,"undefined"==typeof n&&(n=GameLib.D3.Texture.TYPE_REPEAT_WRAPPING),this.wrapS=n,"undefined"==typeof s&&(s=GameLib.D3.Texture.TYPE_REPEAT_WRAPPING),this.wrapT=s,"undefined"==typeof o&&(o=new GameLib.D3.Vector2(1,1)),this.repeat=o,"undefined"==typeof a&&(a=null),this.data=a,"undefined"==typeof r&&(r=GameLib.D3.Texture.TYPE_RGBA_FORMAT),this.format=r,"undefined"==typeof h&&(h=GameLib.D3.Texture.TYPE_UV_MAPPING),this.mapping=h,"undefined"==typeof c&&(c=GameLib.D3.Texture.TYPE_LINEAR_FILTER),this.magFilter=c,"undefined"==typeof l&&(l=GameLib.D3.Texture.TYPE_LINEAR_MIPMAP_LINEAR_FILTER),this.minFilter=l,"undefined"==typeof p&&(p=GameLib.D3.Texture.TYPE_UNSIGNED_BYTE),this.textureType=p,"undefined"==typeof d&&(d=1),this.anisotropy=d,"undefined"==typeof m&&(m=new GameLib.D3.Vector2(0,0)),this.offset=m,"undefined"==typeof u&&(u=!0),this.generateMipmaps=u,"undefined"==typeof f&&(f=!0),this.flipY=f,"undefined"==typeof y&&(y=[]),this.mipmaps=y,"undefined"==typeof v&&(v=4),this.unpackAlignment=v,"undefined"==typeof L&&(L=!1),this.premultiplyAlpha=L,"undefined"==typeof b&&(b=GameLib.D3.Texture.TYPE_LINEAR_ENCODING),this.encoding=b},GameLib.D3.Texture.TYPE_ALPHA_FORMAT=1019,GameLib.D3.Texture.TYPE_RGB_FORMAT=1020,GameLib.D3.Texture.TYPE_RGBA_FORMAT=1021,GameLib.D3.Texture.TYPE_LUMINANCE_FORMAT=1022,GameLib.D3.Texture.TYPE_LUMINANCE_ALPHA_FORMAT=1023,GameLib.D3.Texture.TYPE_DEPTH_FORMAT=1026,GameLib.D3.Texture.TYPE_UV_MAPPING=300,GameLib.D3.Texture.TYPE_CUBE_REFLECTION_MAPPING=301,GameLib.D3.Texture.TYPE_CUBE_REFRACTION_MAPPING=302,GameLib.D3.Texture.TYPE_EQUI_RECTANGULAR_REFLECTION_MAPPING=303,GameLib.D3.Texture.TYPE_EQUI_RECTANGULAR_REFRACTION_MAPPING=304,GameLib.D3.Texture.TYPE_SPHERICAL_REFLECTION_MAPPING=305,GameLib.D3.Texture.TYPE_CUBE_UV_REFLECTION_MAPPING=306,GameLib.D3.Texture.TYPE_CUBE_UV_REFRACTION_MAPPING=307,GameLib.D3.Texture.TYPE_REPEAT_WRAPPING=1e3,GameLib.D3.Texture.TYPE_CLAMP_TO_EDGE_WRAPPING=1001,GameLib.D3.Texture.TYPE_MIRRORED_REPEAT_WRAPPING=1002,GameLib.D3.Texture.TYPE_NEAREST_FILTER=1003,GameLib.D3.Texture.TYPE_NEAREST_MIPMAP_NEAREST_FILTER=1004,GameLib.D3.Texture.TYPE_NEAREST_MIPMAP_LINEAR_FILTER=1005,GameLib.D3.Texture.TYPE_LINEAR_FILTER=1006,GameLib.D3.Texture.TYPE_LINEAR_MIPMAP_NEAREST_FILTER=1007,GameLib.D3.Texture.TYPE_LINEAR_MIPMAP_LINEAR_FILTER=1008,GameLib.D3.Texture.TYPE_UNSIGNED_BYTE=1009,GameLib.D3.Texture.TYPE_BYTE=1010,GameLib.D3.Texture.TYPE_SHORT=1011,GameLib.D3.Texture.TYPE_UNSIGNED_SHORT=1012,GameLib.D3.Texture.TYPE_INT=1013,GameLib.D3.Texture.TYPE_UNSIGNED_INT=1014,GameLib.D3.Texture.TYPE_FLOAT=1015,GameLib.D3.Texture.TYPE_HALF_FLOAT=1025,GameLib.D3.Texture.TYPE_LINEAR_ENCODING=3e3,GameLib.D3.Texture.TYPE_SRGB_ENCODING=3001,GameLib.D3.Texture.TYPE_GAMMA_ENCODING=3007,GameLib.D3.Texture.TYPE_RGBE_ENCODING=3002,GameLib.D3.Texture.TYPE_LOG_LUV_ENCODING=3003,GameLib.D3.Texture.TYPE_RGBM7_ENCODING=3004,GameLib.D3.Texture.TYPE_RGBM16_ENCODING=3005,GameLib.D3.Texture.TYPE_RGBD_ENCODING=3006,GameLib.D3.Texture.loadMap=function(e,i,t,n,s,o){var a=Q.defer(),r=null,h=new n.instance.TextureLoader;return e&&e.image&&e.image.filename&&(r=s+"/"+e.image.filename),r?(h.crossOrigin="",h.load(r,function(s){i[t]=s,i[t].name=e.name,i[t].anisotropy=e.anisotropy,i[t].encoding=e.encoding,i[t].flipY=e.flipY,i[t].generateMipmaps=e.generateMipmaps,i[t].magFilter=e.magFilter,i[t].minFilter=e.minFilter,i[t].mapping=e.mapping,i[t].mipmaps=e.mipmaps,i[t].offset=new n.instance.Vector2(e.offset.x,e.offset.y),i[t].premultiplyAlpha=e.premultiplyAlpha,i[t].textureType=e.textureType,i[t].wrapS=e.wrapS,i[t].wrapT=e.wrapT,i[t].unpackAlignment=e.unpackAlignment,i.needsUpdate=!0,a.resolve(!0)},function(e){o&&o(Math.round(e.loaded/e.total*100))},function(e){console.log("an error occurred while trying to load the image : "+r),a.resolve(null)})):a.resolve(null),a.promise},GameLib.D3.Texture.loadMaps=function(e,i,t,n,s,o){for(var a=[],r=0;r<i.length;r++){var h=i[r];if(e.maps.hasOwnProperty(h)){var c=e.maps[h];if(c&&c.image&&c.image.filename){var l=null;"alpha"==h&&(l="alhpaMap"),"ao"==h&&(l="aoMap"),"bump"==h&&(l="bumpMap"),"displacement"==h&&(l="displacementMap"),"emissive"==h&&(l="emissiveMap"),"environment"==h&&(l="envMap"),"light"==h&&(l="lightMap"),"specular"==h&&(l="specularMap"),"diffuse"==h&&(l="map"),"roughness"==h&&(l="roughnessMap"),"metalness"==h&&(l="metalnessMap"),null==l&&console.warn("unsupported map type : "+h),a.push(GameLib.D3.Texture.loadMap(e.maps[h],t,l,n,s,o))}}}return a},GameLib.D3.Tools=function(){},GameLib.D3.Tools.RandomId=function(){return Math.random().toString(36).substr(2,10)},GameLib.D3.TriangleEdge=function(e,i){this.triangle=e,this.edge=i};GameLib.D3.TriangleFace=function(e,i,t,n,s,o,a,r,h,c,l){this.v0=e,this.v1=i,this.v2=t,this.materialIndex=n,this.v0uv=s,this.v1uv=o,this.v2uv=a,r||(r=new GameLib.D3.Color(255,255,255,255)),this.color=r,h||(h=[new GameLib.D3.Color(255,255,255,255),new GameLib.D3.Color(255,255,255,255),new GameLib.D3.Color(255,255,255,255)]),this.vertexColors=h,c||(c=[new GameLib.D3.Vector3,new GameLib.D3.Vector3,new GameLib.D3.Vector3]),this.vertexNormals=c,l||(l=new GameLib.D3.Vector3(0)),this.normal=l};GameLib.D3.TriangleFace.prototype.clone=function(){return new GameLib.D3.TriangleFace(this.v0,this.v1,this.v2,this.materialIndex,this.v0uv.copy(),this.v1uv.copy(),this.v2uv.copy())},GameLib.D3.TriangleFace.prototype.equals=function(e){return!!(this.v0==e.v0&&this.v1==e.v1&&this.v2==e.v2||this.v0==e.v0&&this.v1==e.v2&&this.v2==e.v1||this.v0==e.v1&&this.v1==e.v0&&this.v2==e.v2||this.v0==e.v1&&this.v1==e.v2&&this.v2==e.v0||this.v0==e.v2&&this.v1==e.v0&&this.v2==e.v1||this.v0==e.v2&&this.v1==e.v1&&this.v2==e.v0)},GameLib.D3.Vector2=function(e,i){this.x=0,this.y=0,e&&(this.x=e),i&&(this.y=i)},GameLib.D3.Vector2.prototype.copy=function(){return new GameLib.D3.Vector2(this.x,this.y)},GameLib.D3.Vector2.prototype.equals=function(e){return!!(this.x==e.x&&this.y==e.y||this.y==e.x&&this.x==e.y)},GameLib.D3.Vector3=function(e,i,t){this.x=0,this.y=0,this.z=0,e&&(this.x=e),i&&(this.y=i),t&&(this.z=t)},GameLib.D3.Vector3.prototype.subtract=function(e){return e instanceof GameLib.D3.Vector3&&(this.x-=e.x,this.y-=e.y,this.z-=e.z),e instanceof GameLib.D3.Vector4&&console.warn("trying to subtract vector of bigger length (4 vs 3))"),this},GameLib.D3.Vector3.prototype.cross=function(e){return new GameLib.D3.Vector3(this.y*e.z-this.z*e.y,this.z*e.x-this.x*e.z,this.x*e.y-this.y*e.x)},GameLib.D3.Vector3.prototype.negative=function(){return this.x*=-1,this.y*=-1,this.z*=-1,this},GameLib.D3.Vector3.clockwise=function(e,i,t,n){var s=GameLib.D3.Vector3.normal(e,i,t),o=e.copy(),a=s.dot(o.subtract(n));return a>0},GameLib.D3.Vector3.normal=function(e,i,t){var n=i.copy(),s=t.copy();return n.subtract(e).cross(s.subtract(e))},GameLib.D3.Vector3.prototype.lookAt=function(e,i){var t=GameLib.D3.Matrix4.lookAt(this,e,i);this.multiply(t)},GameLib.D3.Vector3.prototype.translate=function(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this},GameLib.D3.Vector3.prototype.squared=function(){return this.x*this.x+this.y*this.y+this.z*this.z},GameLib.D3.Vector3.prototype.copy=function(){return new GameLib.D3.Vector3(this.x,this.y,this.z)},GameLib.D3.Vector3.prototype.multiply=function(e){if(e instanceof GameLib.D3.Vector3)this.x*=e.x,this.y*=e.y,this.z*=e.z;else{if(!(e instanceof GameLib.D3.Matrix4))throw console.log("functionality not implemented - please do this"),new Error("not implemented");var i=e.rows[0].x*this.x+e.rows[0].y*this.y+e.rows[0].z*this.z,t=e.rows[1].x*this.x+e.rows[1].y*this.y+e.rows[1].z*this.z,n=e.rows[2].x*this.x+e.rows[2].y*this.y+e.rows[2].z*this.z;this.x=i,this.y=t,this.z=n}return this},GameLib.D3.Vector3.prototype.dot=function(e){return this.x*e.x+this.y*e.y+this.z*e.z},GameLib.D3.Vector3.prototype.normalize=function(){var e=1e-6,i=this.squared();if(i<e)return this;var t=1/Math.sqrt(i);return this.x*=t,this.y*=t,this.z*=t,this},GameLib.D3.Vector4=function(e,i,t,n){this.x=0,this.y=0,this.z=0,this.w=0,e&&(this.x=e),i&&(this.y=i),t&&(this.z=t),n&&(this.w=n)},GameLib.D3.Vector4.prototype.translate=function(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this},GameLib.D3.Vector4.prototype.copy=function(){return new GameLib.D3.Vector4(this.x,this.y,this.z,this.w)},GameLib.D3.Vector4.prototype.multiply=function(e){if(e instanceof GameLib.D3.Vector3)this.x*=e.x,this.y*=e.y,this.z*=e.z;else{if(!(e instanceof GameLib.D3.Matrix4))throw console.log("functionality not implemented - please do this"),new Error("not implemented");var i=e.rows[0].x*this.x+e.rows[0].y*this.y+e.rows[0].z*this.z+e.rows[0].w*this.w,t=e.rows[1].x*this.x+e.rows[1].y*this.y+e.rows[1].z*this.z+e.rows[1].w*this.w,n=e.rows[2].x*this.x+e.rows[2].y*this.y+e.rows[2].z*this.z+e.rows[2].w*this.w,s=e.rows[3].x*this.x+e.rows[3].y*this.y+e.rows[3].z*this.z+e.rows[3].w*this.w;this.x=i,this.y=t,this.z=n,this.w=s}},GameLib.D3.Vector4.prototype.normalize=function(){var e=1e-6,i=this.x*this.x+this.y*this.y+this.z*this.z;if(i<e)return this;var t=1/Math.sqrt(i);return this.x*=t,this.y*=t,this.z*=t,this},GameLib.D3.Vector4.prototype.subtract=function(e){return e instanceof GameLib.D3.Vector3&&(this.x-=e.x,this.y-=e.y,this.z-=e.z),e instanceof GameLib.D3.Vector4&&(this.x-=e.x,this.y-=e.y,this.z-=e.z,this.w-=e.w),this},GameLib.D3.Vector4.Points=function(){this.vectors=[]},GameLib.D3.Vector4.Points.prototype.add=function(e){if(e instanceof GameLib.D3.Vector3&&(e=new GameLib.D3.Vector4(e.x,e.y,e.z,1)),!e instanceof GameLib.D3.Vector4)throw console.warn("Vector needs to be of type Vector4"),new Error("Vector needs to be of type Vector4");return this.vectors.push(e),this},GameLib.D3.Vector4.Points.prototype.copy=function(){for(var e=[],i=0;i<this.vectors.length;i++)e.push(this.vectors[i].copy());return e},GameLib.D3.Vector4.Points.prototype.maximizeXDistance=function(e){for(var i=0,t=(new GameLib.D3.Matrix4).rotationMatrixY(e),n=0,s=this.copy(),o=0,a=0;a<2*Math.PI;a+=e){i++;for(var r=0;r<this.vectors.length;r++)this.vectors[r]=t.multiply(this.vectors[r]);var h=this.distances();h.x>o&&(o=h.x,n=i*e)}this.vectors=s;for(var c=(new GameLib.D3.Matrix4).rotationMatrixY(n),l=0;l<this.vectors.length;l++)this.vectors[l]=c.multiply(this.vectors[l])},GameLib.D3.Vector4.Points.prototype.maximizeYDistance=function(e){for(var i=0,t=(new GameLib.D3.Matrix4).rotationMatrixX(e),n=0,s=this.copy(),o=0,a=0;a<2*Math.PI;a+=e){i++;for(var r=0;r<this.vectors.length;r++)this.vectors[r]=t.multiply(this.vectors[r]);var h=this.distances();h.y>o&&(o=h.y,n=i*e)}this.vectors=s;for(var c=(new GameLib.D3.Matrix4).rotationMatrixX(n),l=0;l<this.vectors.length;l++)this.vectors[l]=c.multiply(this.vectors[l])},GameLib.D3.Vector4.Points.prototype.lookAt=function(e,i){var t=this.average();console.log("poly center : "+JSON.stringify(t));var n=(new GameLib.D3.Matrix4).lookAt(t,e,i);n.rows[0]=new GameLib.D3.Vector4(1,0,0,0),n.rows[1]=new GameLib.D3.Vector4(0,0,1,0),n.rows[2]=new GameLib.D3.Vector4(0,1,0,0),console.log("look at matrix : "+JSON.stringify(n,null,2));for(var s=0;s<this.vectors.length;s++)console.log("vector "+s+" (before): "+JSON.stringify(this.vectors[s])),this.vectors[s]=n.multiply(this.vectors[s]),console.log("vector "+s+" (after) : "+JSON.stringify(this.vectors[s]))},GameLib.D3.Vector4.Points.prototype.distances=function(){for(var e=this.vectors[0].x,i=this.vectors[0].y,t=this.vectors[0].z,n=this.vectors[0].x,s=this.vectors[0].y,o=this.vectors[0].z,a=0;a<this.vectors.length;a++)this.vectors[a].x<e&&(e=this.vectors[a].x),this.vectors[a].y<i&&(i=this.vectors[a].y),this.vectors[a].z<t&&(t=this.vectors[a].z),this.vectors[a].x>n&&(n=this.vectors[a].x),this.vectors[a].y>s&&(s=this.vectors[a].y),this.vectors[a].z>o&&(o=this.vectors[a].z);return new GameLib.D3.Vector3(Math.abs(n-e),Math.abs(s-i),Math.abs(s-t))},GameLib.D3.Vector4.Points.prototype.average=function(){for(var e=0,i=0,t=0,n=0;n<this.vectors.length;n++)e+=this.vectors[n].x,i+=this.vectors[n].y,t+=this.vectors[n].z;return new GameLib.D3.Vector3(e/this.vectors.length,i/this.vectors.length,t/this.vectors.length)},GameLib.D3.Vector4.Points.prototype.negative=function(){for(var e=0;e<this.vectors.length;e++)this.vectors[e].x*=-1,this.vectors[e].y*=-1,this.vectors[e].z*=-1;return this},GameLib.D3.Vector4.Points.prototype.toOrigin=function(){for(var e=this.average().negative(),i=0;i<this.vectors.length;i++)this.vectors[i].translate(e)},GameLib.D3.Vertex=function(e,i){this.position=e,this.boneWeights=i},GameLib.D3.World=function(e,i,t,n,s,o,a){this.id=e,this.name=i,"undefined"==typeof n&&(n=new GameLib.D3.Vector3(0,-9.81,0)),this.gravity=n,"undefined"==typeof s&&(s=new GameLib.D3.Broadphase(null,"broadPhaseNaive",GameLib.D3.Broadphase.BROADPHASE_TYPE_NAIVE,t)),this.broadphase=s,"undefined"==typeof o&&(o=new GameLib.D3.Solver(null,"GSSolver",GameLib.D3.Solver.GS_SOLVER)),this.solver=o,"undefined"==typeof a&&(a=[]),this.rigidBodies=a,this.engine=t,this.engine.isNotCannonThrow(),this.instance=this.createInstance()},GameLib.D3.World.prototype.createInstance=function(){var e=new this.engine.instance.World;return e.broadphase=this.broadphase.instance,e.solver=this.solver.instance,e.gravity.x=this.gravity.x,e.gravity.y=this.gravity.y,e.gravity.z=this.gravity.z,e.name=this.name,e},GameLib.D3.World.prototype.addRigidBody=function(e){this.instance.addBody(e.instance)},GameLib.D3.World.prototype.addVehicle=function(e){e.instance.addToWorld(this.instance)},GameLib.D3.World.prototype.step=function(e){var i=performance.now()/1e3;if(!this.lastCallTime)return this.instance.step(e),void(this.lastCallTime=i);var t=i-this.lastCallTime;this.instance.step(e,t),this.lastCallTime=i},GameLib.D3.World.prototype.GetIndexedVertices=function(e){return this.engine.engineType==GameLib.D3.Physics.TYPE_CANNON?{vertices:e.vertices,indices:e.indices}:null},GameLib.D3.World.prototype.generateWireframeViewTriangleMesh=function(e,i,t,n,s,o){e.isNotThreeThrow(),this.engine.isNotCannonThrow(),"undefined"==typeof t&&(t=10),"undefined"==typeof n&&(n=new e.instance.Vector3(1,1,1)),"undefined"==typeof s&&(s=.5),"undefined"==typeof o&&(o=16711422);for(var a=new e.instance.Geometry,r=new e.instance.Mesh(a,new e.instance.MeshBasicMaterial({color:o,wireframe:!0,opacity:s})),h=0,c=i.instance.vertices.length/3;h<c;++h)a.vertices.push(new e.instance.Vector3(i.instance.vertices[3*h],i.instance.vertices[3*h+1],i.instance.vertices[3*h+2]));for(var l=0,c=i.instance.indices.length/3;l<c;++l){var p=i.instance.indices[3*l],d=i.instance.indices[3*l+1],m=i.instance.indices[3*l+2];a.faces.push(new e.instance.Face3(p,d,m));var u=(new e.instance.Vector3).add(a.vertices[p]).add(a.vertices[d]).add(a.vertices[m]).divideScalar(3),f=new this.engine.instance.Vec3;i.instance.getNormal(l,f);var y=new e.instance.ArrowHelper(new e.instance.Vector3(f.x,f.y,f.z),u,t,new e.instance.Color(f.x,f.y,f.z));r.add(y)}return r.scale.x=n.x,r.scale.y=n.y,r.scale.z=n.z,r},GameLib.D3.World.prototype.generateWireframeViewConvexPolyMesh=function(e,i,t,n,s,o){e.isNotThreeThrow(),this.engine.isNotCannonThrow(),"undefined"==typeof t&&(t=10),"undefined"==typeof n&&(n=new e.instance.Vector3(1,1,1)),"undefined"==typeof s&&(s=.5),"undefined"==typeof o&&(o=16711422);for(var a=new e.instance.Geometry,r=new e.instance.Mesh(a,new e.instance.MeshBasicMaterial({color:o,wireframe:!0,opacity:s})),h=0,c=i.instance.vertices.length;h<c;h++){var l=i.instance.vertices[h];a.vertices.push(new e.instance.Vector3(l.x,l.y,l.z))}for(var h=0,c=i.instance.faces.length;h<c;h++){var p=i.instance.faces[h],d=p[0],m=p[1],u=p[2];a.faces.push(new e.instance.Face3(d,m,u));var f=(new e.instance.Vector3).add(a.vertices[d]).add(a.vertices[m]).add(a.vertices[u]).divideScalar(3),y=i.instance.faceNormals[h],v=new e.instance.Vector3(y.x,y.y,y.z),L=new e.instance.ArrowHelper(v,f,t,new e.instance.Color(v.x,v.y,v.z));r.add(L)}return r.scale.x=n.x,r.scale.y=n.y,r.scale.z=n.z,r},GameLib.D3.World.prototype.generateTriangleMeshShapeDivided=function(e,i,t,n,s,o,a){e.isNotThreeThrow(),this.engine.isNotCannonThrow(),null!=t&&"undefined"!=typeof t||(t=0),null!=n&&"undefined"!=typeof n||(n=10),null!=s&&"undefined"!=typeof s||(s=!1);for(var r=0,h=o||0,c=a||0,l=i.geometry.faces.length,p=s?c*h:l,d=[],m=[],u=[],f=0;f<=l;f++){if(r==p||f==l){var y=null,v=new this.engine.instance.Trimesh(m,u);if(v.setScale(new this.engine.instance.Vec3(i.scale.x,i.scale.y,i.scale.z)),v.updateAABB(),v.updateNormals(),v.updateEdges(),v.updateBoundingSphereRadius(),v.updateTree(),y=new this.engine.instance.Body({mass:t,friction:n}),y.addShape(v),d.push({threeObject:s?null:i,physicsObject:y}),m=[],u=[],r=0,f==l)return d}var L=i.geometry.faces[f];u.push(u.length),u.push(u.length),u.push(u.length);var b=i.geometry.vertices[L.a],g=i.geometry.vertices[L.b],D=i.geometry.vertices[L.c];m.push(b.x,b.y,b.z),m.push(g.x,g.y,g.z),m.push(D.x,D.y,D.z),r++}},GameLib.D3.World.prototype.generateTriangleMeshShape=function(e,i){for(var t=[],n=0,s=i.geometry.vertices.length;n<s;n++){var o=i.geometry.vertices[n];
t.push(new this.engine.instance.Vec3(o.x*i.scale.x,o.y*i.scale.y,o.z*i.scale.z))}for(var a=[],r=0,h=i.geometry.faces.length;r<h;r++){var c=i.geometry.faces[r].a,l=i.geometry.faces[r].b,p=i.geometry.faces[r].c;a.push([c,l,p])}for(var d={},m=[],u=[],f=0,y=a.length,v=0,r=0;r<y;r++){var c=a[r][0],l=a[r][1],p=a[r][2];"undefined"==typeof d[c]&&(m.push(t[c].x,t[c].y,t[c].z),d[c]=v,v++),"undefined"==typeof d[l]&&(m.push(t[l].x,t[l].y,t[l].z),d[l]=v,v++),"undefined"==typeof d[p]&&(m.push(t[p].x,t[p].y,t[p].z),d[p]=v,v++),u.push(d[c],d[l],d[p]),f++}var L=GameLib.D3.Shape(this.engine,GameLib.D3.Shape.SHAPE_TYPE_TRIMESH,i.scale,m,u),b=GameLib.D3.RigidBody(this.engine,0,12);b.addShape(L),this.addRigidBody(b);for(var g in i.children)this.generateTriangleMeshShape(e,i.children[g]);return b},GameLib.D3.World.prototype.fixupTriangleMeshShape=function(e,i,t,n,s,o,a){this.engine.isNotCannonThrow(),o.isNotThreeThrow(),null!=t&&"undefined"!=typeof t&&0!=t||(t=10),null!=n&&"undefined"!=typeof n||(n=13);var r=this.instance,h=new this.engine.instance.RaycastResult,c=[],l=[],p=0,d=0,m=0,u=[];for(var f in i){var y=i[f],v=[];p+=y.indices.length/3;for(var L=0;L<y.indices.length/3;L++){var b=y.indices[3*L],g=y.indices[3*L+1],D=y.indices[3*L+2],G=(new o.instance.Vector3).add(new o.instance.Vector3(y.vertices[3*b],y.vertices[3*b+1],y.vertices[3*b+2])).add(new o.instance.Vector3(y.vertices[3*g],y.vertices[3*g+1],y.vertices[3*g+2])).add(new o.instance.Vector3(y.vertices[3*D],y.vertices[3*D+1],y.vertices[3*D+2])).divideScalar(3),w=new this.engine.instance.Vec3;y.getNormal(L,w);var T=new this.engine.instance.Vec3(G.x+w.x,G.y+w.y,G.z+w.z),E=new this.engine.instance.Vec3(T.x-w.x*t,T.y-w.y*t,T.z-w.z*t);if(r.raycastClosest(T,E,{},h),a){var x=new o.instance.Geometry,_=new o.instance.Mesh(x,new o.instance.MeshBasicMaterial({color:16711680,wireframe:!0,opacity:1})),P=new o.instance.ArrowHelper(new o.instance.Vector3(w.x,w.y,w.z).normalize(),new o.instance.Vector3(T.x,T.y,T.z),t/2,h.hasHit?new o.instance.Color(0,1,0):new o.instance.Color(1,0,0));_.add(P),l.add(_),c.push(_)}h.hasHit||v.push({faceIndex:L,vertices:[new this.engine.instance.Vec3(y.vertices[3*b],y.vertices[3*b+1],y.vertices[3*b+2]),new this.engine.instance.Vec3(y.vertices[3*g],y.vertices[3*g+1],y.vertices[3*g+2]),new this.engine.instance.Vec3(y.vertices[3*D],y.vertices[3*D+1],y.vertices[3*D+2])],center:G,parent:y})}for(var M={},S=0;S<v.length;S++){var I=v[S];if(!I.marked){M[S]={indices:[],vertices:[]};var V=M[S].indices.length;M[S].indices.push(V,V+1,V+2),M[S].vertices.push(I.vertices[0].x,I.vertices[0].y,I.vertices[0].z),M[S].vertices.push(I.vertices[1].x,I.vertices[1].y,I.vertices[1].z),M[S].vertices.push(I.vertices[2].x,I.vertices[2].y,I.vertices[2].z);for(var N=0;N<v.length;N++)if(N!=S){var R=v[N];if(!R.marked&&I.center.distanceTo(R.center)<=n){var V=M[S].indices.length;M[S].indices.push(V,V+1,V+2),M[S].vertices.push(R.vertices[0].x,R.vertices[0].y,R.vertices[0].z),M[S].vertices.push(R.vertices[1].x,R.vertices[1].y,R.vertices[1].z),M[S].vertices.push(R.vertices[2].x,R.vertices[2].y,R.vertices[2].z),R.marked=!0}}}}for(var A in M){var z=M[A],C=new GameLib.D3.Shape(this.engine,GameLib.D3.Shape.SHAPE_TYPE_TRIMESH,null,z.vertices,z.indices);if(s)e.addShape(C);else{var Y=new GameLib.D3.RigidBody(this.engine,0,12);Y.addShape(C),this.instance.addRigidBody(Y)}u.push(C),m+=z.indices.length/3,console.log("created mesh shape",z.indices.length/3)}console.log("i = "+f,v),d+=v.length}return console.log("total faces",p),console.log("total broken faces",d),console.log("broken faces in percent",d/p*100),console.log("total fixed faces",m),console.log("fixed triangle mesh shapes",u.length),{brokenFaceIndicators:c,fixedTriangleMeshShapes:u,wireframeMeshes:l}},"undefined"!=typeof module&&(module.exports=GameLib);