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

2 lines
60 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,t){this.boneIndex=e,this.weight=t},GameLib.D3.Bone=function(e,t,i,n,s,o,a,r,h,c){this.id=e,this.name=i,this.boneId=t,"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,t,i,n,s){this.id=e,"undefined"==typeof t&&(t="broadphase-"+i),this.name=t,"undefined"==typeof i&&(i=GameLib.D3.Broadphase.BROADPHASE_TYPE_NAIVE),this.broadphaseType=i,"undefined"==typeof n&&(n=null),this.engine=n,this.instance=null,s&&this.createInstance()},GameLib.D3.Broadphase.prototype.createInstance=function(){if(!(this.engine instanceof GameLib.D3.Engine))throw console.warn("No Engine"),new Error("No Engine");this.engine.isNotCannonThrow();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.SAPBroardphase}return this.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,t,i,n){this.r=e,this.g=t,this.b=i,this.a=n},GameLib.D3.Engine=function(e,t){this.engineType=e,this.instance=t},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.FlyControls=function(e,t,i){this.flySpeed=100,this.canvas=i,this.THREE=t,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 t=new this.THREE.Vector3(0,0,-1),i=new this.THREE.Euler(0,0,0,"YXZ");i.set(this.pitch,this.yaw,0,"YXZ"),t=t.applyEuler(i);var n=t.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 t=e.movementX||e.mozMovementX||e.webkitMovementX||0,i=e.movementY||e.mozMovementY||e.webkitMovementY||0;this.yaw-=.002*t,this.pitch-=.002*i}},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,t){this.sceneToPhysicsWorldsMap[t.name]=this.sceneToPhysicsWorldsMap[t.name]||[],this.sceneToPhysicsWorldsMap[t.name].push(e)},GameLib.D3.Game.prototype.GetPhysicsWorldsForScene=function(e){return this.sceneToPhysicsWorldsMap[e.name]},GameLib.D3.Game.prototype.ProcessPhysics=function(e){for(var t in this.sceneToPhysicsWorldsMap){var i=this.sceneToPhysicsWorldsMap[t],n=this.scenes[t];if(n&&i)for(var s=0,o=i.length;s<o;s++){var a=i[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,t,i){i.linkedPairs=i.linkedPairs||[],i.linkedPairs.push({threeMesh:e,physicsBody:t})},GameLib.D3.Graphics=function(e,t){this.graphicsType=e,this.instance=t},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,t,i,n,s){"undefined"==typeof e&&(e=0),this.sizeX=e,"undefined"==typeof t&&(t=0),this.sizeY=t,"undefined"==typeof i&&(i=[]),this.matrix=i,"undefined"==typeof n&&(n=10),this.elementSize=n,"undefined"==typeof s&&(s=15),this.elementSize=s},GameLib.D3.Heightmap.GenerateInstanceMesh=function(e,t,i){e.isNotThreeThrow(),i.isNotCannonThrow();for(var n=new e.instance.Geometry,s=new i.instance.Vec3,o=new i.instance.Vec3,a=new i.instance.Vec3,r=0;r<t.instance.data.length-1;r++)for(var h=0;h<t.instance.data[r].length-1;h++)for(var c=0;c<2;c++){t.instance.getConvexTrianglePillar(r,h,0===c),s.copy(t.instance.pillarConvex.vertices[0]),o.copy(t.instance.pillarConvex.vertices[1]),a.copy(t.instance.pillarConvex.vertices[2]),s.vadd(t.instance.pillarOffset,s),o.vadd(t.instance.pillarOffset,o),a.vadd(t.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,t,i){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*t;l[m].push(f)}}i(new GameLib.D3.Heightmap(p,d,l,10,t))},n.src=e},GameLib.D3.Image=function(e,t,i,n,s){this.id=e,this.filename=i,this.textureLink=t,"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,t,i,n,s,o,a,r,h,c,l,p,d,m,u){this.id=e,this.lightType=t,this.name=i,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,t,i,n,s,o,a,r,h,c,l,p,d,m,u,f,y,L,b,v,D,G,g,T,E,w,x,P,_,M,S,N,A,R,I,V,C,z,Y,O,F,H,k,B,U,W,q,Q,X,J,j,Z,K,$,ee,te,ie){this.id=e,this.name=t,"undefined"==typeof i&&(i=GameLib.D3.Material.TYPE_MESH_STANDARD),this.materialType=i,"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 L&&(L=!0),this.fog=L,"undefined"==typeof b&&(b=!1),this.wireframe=b,"undefined"==typeof v&&(v=1),this.wireframeLineWidth=v,"undefined"==typeof D&&(D="round"),this.wireframeLineCap=D,"undefined"==typeof G&&(G="round"),this.wireframeLineJoin=G,"undefined"==typeof g&&(g=GameLib.D3.Material.TYPE_NO_COLORS),this.vertexColors=g,"undefined"==typeof T&&(T=!1),this.skinning=T,"undefined"==typeof E&&(E=!1),this.morphTargets=E,"undefined"==typeof w&&(w=!1),this.morphNormals=w,"undefined"==typeof W&&(W=0),this.overdraw=W,"undefined"==typeof x&&(x=1),this.lineWidth=x,"undefined"==typeof P&&(P="round"),this.lineCap=P,"undefined"==typeof _&&(_="round"),this.lineJoin=_,"undefined"==typeof M&&(M=3),this.dashSize=M,"undefined"==typeof S&&(S=1),this.gapWidth=S,"undefined"==typeof N&&(N=GameLib.D3.Material.TYPE_NORMAL_BLENDING),this.blending=N,"undefined"==typeof A&&(A=GameLib.D3.Material.TYPE_SRC_ALPHA_FACTOR),this.blendSrc=A,"undefined"==typeof R&&(R=GameLib.D3.Material.TYPE_ONE_MINUS_SRC_ALPHA_FACTOR),this.blendDst=R,"undefined"==typeof I&&(I=GameLib.D3.Material.TYPE_ADD_EQUATION),this.blendEquation=I,"undefined"==typeof V&&(V=!0),this.depthTest=V,"undefined"==typeof C&&(C=GameLib.D3.Material.TYPE_LESS_EQUAL_DEPTH),this.depthFunc=C,"undefined"==typeof z&&(z=!0),this.depthWrite=z,"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 H&&(H=0),this.alphaTest=H,"undefined"==typeof k&&(k=[]),this.clippingPlanes=k,"undefined"==typeof B&&(B=!1),this.clipShadows=B,"undefined"==typeof U&&(U=!0),this.visible=U,"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 te&&(te=0),this.spriteRotation=te,"undefined"==typeof ie&&(ie=1),this.envMapIntensity=ie},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,t,i,n){var s=Q.defer(),o=null,a=[];if(e.materialType==GameLib.D3.Material.TYPE_MESH_STANDARD?(o=new t.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 t.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 t.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 t.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 t.instance.Color(e.color.r,e.color.g,e.color.b),specular:new t.instance.Color(e.specular.r,e.specular.g,e.specular.b),shininess:e.shininess,lightMapIntensity:e.lightMapIntensity,aoMapIntensity:e.aoMapIntensity,emissive:new t.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,t,i,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,t,i){this.identity(),e&&(this.rows[0]=e),t&&(this.rows[1]=t),i&&(this.rows[2]=i)},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,t,i,n){this.identity(),e&&(this.rows[0]=e),t&&(this.rows[1]=t),i&&(this.rows[2]=i),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,t){return this.identity(),this.rotationMatrixX(e),this.multiply(t)},GameLib.D3.Matrix4.prototype.rotateY=function(e,t){return this.identity(),this.rotationMatrixY(e),this.multiply(t)},GameLib.D3.Matrix4.prototype.rotateZ=function(e,t){return this.identity(),this.rotationMatrixZ(e),this.multiply(t)},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,t,i){var n=new GameLib.D3.Vector3(e.x,e.y,e.z),s=n.subtract(t).normalize();0===s.squared()&&(s.z=1);var o=i.cross(s).normalize();0===o.squared()&&(s.x+=1e-4,o=i.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,t,i,n,s,o,a,r,h,c,l,p,d,m,u,f,y,L,b,v){this.id=e,this.path=t,this.name=i,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=L,this.parentSceneId=b,this.rawData=null},GameLib.D3.Mesh.TYPE_NORMAL=0,GameLib.D3.Mesh.TYPE_SKINNED=1,GameLib.D3.Mesh.createInstanceMesh=function(e,t,i,n){var s=null;if(e.meshType==GameLib.D3.Mesh.TYPE_NORMAL&&(s=new n.instance.Mesh(t,i)),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++)t.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++)t.skinWeights.push(new n.instance.Vector4(r[u].x,r[u].y,r[u].z,r[u].w));s=new n.instance.SkinnedMesh(t,i);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 t=0;t<e.length;t++){var i=e[t].v1;e[t].v1=e[t].v2,e[t].v2=i;var n=e[t].triangle.v1uv;e[t].triangle.v1uv=e[t].triangle.v2uv,e[t].triangle.v2uv=n}return e},GameLib.D3.prototype.resetWindingOrder=function(e,t){for(var i=new GameLib.D3.Vector3.Points,n=0;n<t.length;n++)i.add(new GameLib.D3.Vector3(t[n].position.x,t[n].position.y,t[n].position.z));for(var s=i.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(t[o[l].v0].position,t[o[l].v1].position,t[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,t){function i(e,t){for(var i=0;i<e.length;i++)if(e[i].triangle.equals(t))return!0;return!1}function n(e,t,i){for(var n=0;n<t.length;n++)if(t[n].v0==e.x&&t[n].v1==e.y||t[n].v1==e.x&&t[n].v2==e.y||t[n].v2==e.x&&t[n].v0==e.y||t[n].v0==e.y&&t[n].v1==e.x||t[n].v1==e.y&&t[n].v2==e.x||t[n].v2==e.y&&t[n].v0==e.x){var s=new GameLib.D3.TriangleFace(t[n].v0,t[n].v1,t[n].v2,t[n].materialIndex,t[n].v0uv,t[n].v1uv,t[n].v2uv);if(s.equals(i))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),t)],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&&!i(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,t){e.length%3==0||e.length>9||console.log("The vertices are not in the right length : "+e.length);for(var i=[],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(t),n.maximizeYDistance(t),s=0;s<n.vectors.length;s++)i.push([n.vectors[s].x,n.vectors[s].y]);return i},GameLib.D3.Physics=function(e,t,i,n){this.id=e,this.name=t,this.engine=i,"undefined"==typeof n&&(n=[]),this.worlds=n},GameLib.D3.Physics.SPLIT_SOLVER=1,GameLib.D3.Physics.GS_SOLVER=2,GameLib.D3.PolyVertex=function(e,t,i,n,s){this.localIndex=e,this.mvertIndex=t,this.uv=i,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,t,i){this.engine=e,this.engine.isNotCannonThrow(),this.chassisBody=t,"undefined"==typeof i&&(i=[]),this.wheels=i,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.RaycastWheel=function(e,t,i,n,s,o,a,r,h,c,l,p,d,m,u,f,y,L,b,v,D,G,g,T,E,w,x,P){this.engine=e,this.engine.isNotCannonThrow(),"undefined"==typeof t&&(t=new this.engine.instance.Vec3),this.chassisConnectionPointLocal=t,"undefined"==typeof i&&(i=new this.engine.instance.Vec3),this.chassisConnectionPointWorld=i,"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 L&&(L=.01),this.rollInfluence=L,"undefined"==typeof b&&(b=Number.MAX_VALUE),this.maxSuspensionForce=b,"undefined"==typeof v&&(v=!0),this.isFrontWheel=v,"undefined"==typeof D&&(D=1),this.clippedInvContactDotSuspension=D,"undefined"==typeof G&&(G=0),this.suspensionRelativeVelocity=G,"undefined"==typeof g&&(g=0),this.suspensionForce=g,"undefined"==typeof T&&(T=0),this.skidInfo=T,"undefined"==typeof E&&(E=0),this.suspensionLength=E,"undefined"==typeof w&&(w=1),this.maxSuspensionTravel=w,"undefined"==typeof x&&(x=!1),this.useCustomSlidingRotationalSpeed=x,"undefined"==typeof P&&(P=-.1),this.customSlidingRotationalSpeed=P,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,t,i){this.engine=e,this.engine.isNotCannonThrow(),this.chassisBody=t,"undefined"==typeof i&&(i=[]),this.wheels=i,this.instance=this.createInstance();
},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(e.instance)},GameLib.D3.RigidBody=function(e,t,i,n,s,o,a,r,h,c,l,p,d,m,u,f){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 t?0:t,this.friction="undefined"==typeof i?5:i,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,t,i){t||(t=new GameLib.D3.Vector3(0,0,0)),i||(i=new GameLib.D3.Vector4(0,0,0,1)),this.instance.addShape(e.instance,new this.engine.instance.Vec3(t.x,t.y,t.z),new this.engine.instance.Quaternion(i.x,i.y,i.z,i.w))},GameLib.D3.Scene=function(e,t,i,n,s,o,a,r,h,c,l){this.id=e,this.path=t,this.name=i,""==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.physics=l},GameLib.D3.Scene.loadSceneFromApi=function(e,t,i,n,s,o){if("undefined"==typeof XMLHttpRequest)return console.warn("implement server side loading from API here"),t(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 t(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),L=u.solver,b=new GameLib.D3.Physics.Solver(L.id,L.name,L.solverType,L.iterations,L.tolerance),v=u.rigidBodies,D=[],G=0;G<v.length;G++){var g=v[G],T=new GameLib.D3.Physics.RigidBody(g.id,g.name);D.push(T)}var E=new GameLib.D3.Physics.World(null,u.name,p,new GameLib.D3.Vector3(u.gravity.x,u.gravity.y,u.gravity.z),y,b,D);d.push(E)}r.push(p)}for(var w=[],x=0;x<a.lights.length;x++){var P=a.lights[x],_=new GameLib.D3.Light(P.id,P.lightType,P.name,new GameLib.D3.Color(P.color.r,P.color.g,P.color.b,P.color.a),P.intensity,new GameLib.D3.Vector3(P.position.x,P.position.y,P.position.z),new GameLib.D3.Vector3(P.targetPosition.x,P.targetPosition.y,P.targetPosition.z),new GameLib.D3.Vector4(P.quaternion.x,P.quaternion.y,P.quaternion.z,P.quaternion.w),new GameLib.D3.Vector3(P.rotation.x,P.rotation.y,P.rotation.z),new GameLib.D3.Vector3(P.scale.x,P.scale.y,P.scale.z),P.distance,P.decay,P.power,P.angle,P.penumbra);w.push(_)}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,w,r);GameLib.D3.Scene.loadScene(M,t,!1,i,n,s)}}}(a),a.send()},GameLib.D3.Scene.loadScene=function(e,t,i,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 L=0;L<d.length;L++){var b=d[L];c.faceVertexUvs[L]=[];for(var v=0;v<b.length;v++)c.faceVertexUvs[L][v]=[],c.faceVertexUvs[L][v].push(new n.instance.Vector2(b[v][0].x,b[v][0].y),new n.instance.Vector2(b[v][1].x,b[v][1].y),new n.instance.Vector2(b[v][2].x,b[v][2].y))}i&&(c.computeFaceNormals(),c.computeVertexNormals());for(var D=[],G=0;G<m.length;G++)D.push(GameLib.D3.Material.createInstanceMaterial(m[G],n,s,o));var g=Q.all(D).then(function(e,t){return function(i){console.log("loaded material : "+i[0].name);var s=i[0],o=GameLib.D3.Mesh.createInstanceMesh(e,t,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(i){if(console.log("all meshes have loaded"),"undefined"!=typeof t){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<i.length;c++)h.add(i[c]);for(var l=0;l<s.length;l++)h.add(s[l]);t(e,{scene:h,lights:s,meshes:i})}}).catch(function(e){console.log(e)})},GameLib.D3.Shape=function(e,t,i,n,s,o,a,r,h,c,l,p){this.engine=e,this.engine.isNotCannonThrow(),this.shapeType=t,this.instance=this.createInstance(),"undefined"==typeof i&&(i=new GameLib.D3.Vector3(1,1,1)),this.scale=i,"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,t,i,n,s,o,a,r){this.id=e,this.bones=t,"undefined"==typeof i&&(i=[]),this.boneInverses=i,"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 t=new this.graphics.instance.TextureLoader;this.textures.push(t.load(this.texturesFolder+"px.png")),this.textures.push(t.load(this.texturesFolder+"nx.png")),this.textures.push(t.load(this.texturesFolder+"py.png")),this.textures.push(t.load(this.texturesFolder+"ny.png")),this.textures.push(t.load(this.texturesFolder+"pz.png")),this.textures.push(t.load(this.texturesFolder+"nz.png"));for(var i=0;i<6;i++)this.materials.push(new this.graphics.instance.MeshBasicMaterial({map:this.textures[i]}));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,t){var i=new this.graphics.instance.Vector3(t.position.x,t.position.y,t.position.z);t.position.set(0,0,0);var n=e.context;n.disable(n.DEPTH_TEST),e.render(this.scene,t),n.enable(n.DEPTH_TEST),t.position.copy(i)},GameLib.D3.Physics.Solver=function(e,t,i,n,s){this.id=e,"undefined"==typeof t&&(t=i==GameLib.D3.Physics.SPLIT_SOLVER?"split solver":i==GameLib.D3.Physics.GS_SOLVER?"gs solver":"unknown solver"),this.name=t,this.solverType=i,this.iterations=n,this.tolerance=s},GameLib.D3.Physics.SPLIT_SOLVER=1,GameLib.D3.Physics.GS_SOLVER=2,GameLib.D3.Texture=function(e,t,i,n,s,o,a,r,h,c,l,p,d,m,u,f,y,L,b,v){this.id=e,this.name=t,this.image=i,"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 L&&(L=4),this.unpackAlignment=L,"undefined"==typeof b&&(b=!1),this.premultiplyAlpha=b,"undefined"==typeof v&&(v=GameLib.D3.Texture.TYPE_LINEAR_ENCODING),this.encoding=v},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,t,i,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){t[i]=s,t[i].name=e.name,t[i].anisotropy=e.anisotropy,t[i].encoding=e.encoding,t[i].flipY=e.flipY,t[i].generateMipmaps=e.generateMipmaps,t[i].magFilter=e.magFilter,t[i].minFilter=e.minFilter,t[i].mapping=e.mapping,t[i].mipmaps=e.mipmaps,t[i].offset=new n.instance.Vector2(e.offset.x,e.offset.y),t[i].premultiplyAlpha=e.premultiplyAlpha,t[i].textureType=e.textureType,t[i].wrapS=e.wrapS,t[i].wrapT=e.wrapT,t[i].unpackAlignment=e.unpackAlignment,t.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,t,i,n,s,o){for(var a=[],r=0;r<t.length;r++){var h=t[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],i,l,n,s,o))}}}return a},GameLib.D3.TriangleEdge=function(e,t){this.triangle=e,this.edge=t},GameLib.D3.TriangleFace=function(e,t,i,n,s,o,a,r,h,c,l){this.v0=e,this.v1=t,this.v2=i,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,t){this.x=0,this.y=0,e&&(this.x=e),t&&(this.y=t)},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,t,i){this.x=0,this.y=0,this.z=0,e&&(this.x=e),t&&(this.y=t),i&&(this.z=i)};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,t,i,n){var s=GameLib.D3.Vector3.normal(e,t,i),o=e.copy(),a=s.dot(o.subtract(n));return a>0},GameLib.D3.Vector3.normal=function(e,t,i){var n=t.copy(),s=i.copy();return n.subtract(e).cross(s.subtract(e))},GameLib.D3.Vector3.prototype.lookAt=function(e,t){var i=GameLib.D3.Matrix4.lookAt(this,e,t);this.multiply(i)},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 t=e.rows[0].x*this.x+e.rows[0].y*this.y+e.rows[0].z*this.z,i=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=t,this.y=i,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,t=this.squared();if(t<e)return this;var i=1/Math.sqrt(t);return this.x*=i,this.y*=i,this.z*=i,this},GameLib.D3.Vector4=function(e,t,i,n){this.x=0,this.y=0,this.z=0,this.w=0,e&&(this.x=e),t&&(this.y=t),i&&(this.z=i),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 t=e.rows[0].x*this.x+e.rows[0].y*this.y+e.rows[0].z*this.z+e.rows[0].w*this.w,i=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=t,this.y=i,this.z=n,this.w=s}},GameLib.D3.Vector4.prototype.normalize=function(){var e=1e-6,t=this.x*this.x+this.y*this.y+this.z*this.z;if(t<e)return this;var i=1/Math.sqrt(t);return this.x*=i,this.y*=i,this.z*=i,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=[],t=0;t<this.vectors.length;t++)e.push(this.vectors[t].copy());return e},GameLib.D3.Vector4.Points.prototype.maximizeXDistance=function(e){for(var t=0,i=(new GameLib.D3.Matrix4).rotationMatrixY(e),n=0,s=this.copy(),o=0,a=0;a<2*Math.PI;a+=e){t++;for(var r=0;r<this.vectors.length;r++)this.vectors[r]=i.multiply(this.vectors[r]);var h=this.distances();h.x>o&&(o=h.x,n=t*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 t=0,i=(new GameLib.D3.Matrix4).rotationMatrixX(e),n=0,s=this.copy(),o=0,a=0;a<2*Math.PI;a+=e){t++;for(var r=0;r<this.vectors.length;r++)this.vectors[r]=i.multiply(this.vectors[r]);var h=this.distances();h.y>o&&(o=h.y,n=t*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,t){var i=this.average();console.log("poly center : "+JSON.stringify(i));var n=(new GameLib.D3.Matrix4).lookAt(i,e,t);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,t=this.vectors[0].y,i=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<t&&(t=this.vectors[a].y),this.vectors[a].z<i&&(i=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-t),Math.abs(s-i))},GameLib.D3.Vector4.Points.prototype.average=function(){for(var e=0,t=0,i=0,n=0;n<this.vectors.length;n++)e+=this.vectors[n].x,t+=this.vectors[n].y,i+=this.vectors[n].z;return new GameLib.D3.Vector3(e/this.vectors.length,t/this.vectors.length,i/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(),t=0;t<this.vectors.length;t++)this.vectors[t].translate(e)},GameLib.D3.Vertex=function(e,t){this.position=e,this.boneWeights=t},GameLib.D3.World=function(e,t,i,n,s,o,a){this.id=e,this.name=t,"undefined"==typeof n&&(n=new GameLib.D3.Vector3(0,-9.81,0)),this.gravity=n,"undefined"==typeof s&&(s=new GameLib.D3.Physics.Broadphase(null,"broadPhaseNaive",GameLib.D3.Physics.BROADPHASE_TYPE_NAIVE)),this.broadphase=s,"undefined"==typeof o&&(o=new GameLib.D3.Physics.Solver(null,"GSSolver",GameLib.D3.Physics.GS_SOLVER)),this.solver=o,"undefined"==typeof a&&(a=[]),this.rigidBodies=a,this.engine=i,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.world.instance)},GameLib.D3.World.prototype.step=function(e){var t=performance.now()/1e3;if(!this.lastCallTime)return this.instance.step(e),void(this.lastCallTime=t);var i=t-this.lastCallTime;this.instance.step(e,i),this.lastCallTime=t},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.GenerateWireframeViewMesh=function(e,t,i,n,s){for(var o=new THREE.Geometry,a=new THREE.Mesh(o,new THREE.MeshBasicMaterial({color:s?s:16711422,wireframe:!0,opacity:n?n:.5})),r=this.GetIndexedVertices(e),h=0,c=r.vertices.length/3;h<c;h++)o.vertices.push(new THREE.Vector3(r.vertices[3*h],r.vertices[3*h+1],r.vertices[3*h+2]));for(var h=0,c=r.indices.length/3;h<c;h++){var l=r.indices[3*h],p=r.indices[3*h+1],d=r.indices[3*h+2];o.faces.push(new THREE.Face3(l,p,d));var m=(new THREE.Vector3).add(o.vertices[l]).add(o.vertices[p]).add(o.vertices[d]).divideScalar(3),u=null;if(this.engine.engineType==GameLib.D3.Physics.TYPE_CANNON){var u=new this.physics.CANNON.Vec3;e.getNormal(h,u)}var f=new THREE.ArrowHelper(new THREE.Vector3(u.x,u.y,u.z),m,t,new THREE.Color(u.x,u.y,u.z));a.add(f)}return a.scale.x=i.x,a.scale.y=i.y,a.scale.z=i.z,a},GameLib.D3.World.GenerateTriangleCollisionMesh=function(e,t,i,n,s,o){for(var a=0,r=s||0,h=o||0,c=e.geometry.faces.length,l=n?h*r:c,p=[],d=[],m=[],u=0;u<=c;u++){if(a==l||u==c){var f=null;if(this.engine.engineType==GameLib.D3.Physics.TYPE_CANNON){var y=new this.physics.CANNON.Trimesh(d,m);y.setScale(new this.physics.CANNON.Vec3(e.scale.x,e.scale.y,e.scale.z)),y.updateAABB(),y.updateNormals(),y.updateEdges(),y.updateBoundingSphereRadius(),y.updateTree(),f=new this.physics.CANNON.Body({mass:t?t:0,friction:i?i:10}),f.addShape(y)}else this.engine.engineType==GameLib.D3.Physics.Engine.TYPE_AMMO||this.engine.engineType==GameLib.D3.Physics.Engine.TYPE_GOBLIN;if(p.push({threeObject:n?null:e,physicsObject:f}),d=[],m=[],a=0,u==c)return p}var L=e.geometry.faces[u];m.push(m.length),m.push(m.length),m.push(m.length);var b=e.geometry.vertices[L.a],v=e.geometry.vertices[L.b],D=e.geometry.vertices[L.c];d.push(b.x,b.y,b.z),d.push(v.x,v.y,v.z),d.push(D.x,D.y,D.z),a++}},"undefined"!=typeof module&&(module.exports=GameLib);