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

2 lines
56 KiB
JavaScript

function GameLib(){}"undefined"==typeof GameLib.D3&&(GameLib.D3=function(){}),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,l){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 l&&(l=new GameLib.D3.Vector3(0,1,0)),this.up=l},GameLib.D3.Broadphase=function(e,i,t,n,s){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,"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,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.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],l=h.threeMesh,c=h.physicsBody;if(l&&a.engineType===GameLib.D3.Physics.TYPE_CANNON){var p=new THREE.Quaternion;p.copy(c.rigidBodyInstance.quaternion);var m=p.clone(),d=new THREE.Vector3;if(d.copy(c.rigidBodyInstance.position),l.permutate&&l.permutate.offset){if(l.permutate.offset.quaternion){var y=new THREE.Quaternion;y.copy(l.permutate.offset.quaternion),p=p.multiply(y).normalize()}if(l.permutate.offset.position){var u=new THREE.Vector3;u.copy(l.permutate.offset.position),d=d.add(u.applyQuaternion(m))}}l.position.copy(d),l.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.Heightmap=function(e,i,t){"undefined"==typeof e&&(e=0),this.sizeX=e,"undefined"==typeof i&&(i=0),this.sizeY=i,"undefined"==typeof t&&(t=[]),this.matrix=t},GameLib.D3.Heightmap.prototype.generateThreeMeshFromHeightField=function(e,i,t){for(var n=new e.Geometry,s=new this.physics.CANNON.Vec3,o=new this.physics.CANNON.Vec3,a=new this.physics.CANNON.Vec3,r=i,h=0;h<r.data.length-1;h++)for(var l=0;l<r.data[h].length-1;l++)for(var c=0;c<2;c++){r.getConvexTrianglePillar(h,l,0===c),s.copy(r.pillarConvex.vertices[0]),o.copy(r.pillarConvex.vertices[1]),a.copy(r.pillarConvex.vertices[2]),s.vadd(r.pillarOffset,s),o.vadd(r.pillarOffset,o),a.vadd(r.pillarOffset,a),n.vertices.push(new e.Vector3(s.x,s.y,s.z),new e.Vector3(o.x,o.y,o.z),new e.Vector3(a.x,a.y,a.z));var p=n.vertices.length-3;n.faces.push(new e.Face3(p,p+1,p+2))}return n.computeBoundingSphere(),n.computeFaceNormals(),new e.Mesh(n,new e.MeshNormalMaterial({wireframe:!1,shading:e.SmoothShading}))},GameLib.D3.Heightmap.prototype.generateHeightmapDataFromImage=function(e,i){var t=new Image;t.onload=function(){var e=document.createElement("canvas");e.width=t.width,e.height=t.height;var n=e.getContext("2d");n.drawImage(t,0,0);for(var s=n.getImageData(0,0,t.width,t.height),o=s.data,a=[],r=0,h=o.length;r<h;r+=4)a.push(o[r]);for(var l=[],c=t.width,p=t.height,r=0;r<c;r++){l.push([]);for(var m=0;m<p;m++){var d=a[c-r+m*p]/255*15;l[r].push(d)}}i(new GameLib.D3.HeightmapData(c,p,l))},t.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,l,c,p,m,d,y){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 l&&(l=new GameLib.D3.Vector3(1,1,1)),this.scale=l,"undefined"==typeof c&&(c=0),this.distance=c,"undefined"==typeof p&&(p=1),this.decay=p,"undefined"==typeof m&&(m=4*Math.PI),this.power=m,"undefined"==typeof d&&(d=Math.PI/3),this.angle=d,"undefined"==typeof y&&(y=0),this.penumbra=y},GameLib.D3.Material=function(e,i,t,n,s,o,a,r,h,l,c,p,m,d,y,u,f,b,L,v,E,D,T,G,g,w,P,x,_,N,M,A,R,S,O,V,I,C,z,Y,H,F,k,B,W,U,q,j,Q,X,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 l&&(l=1),this.aoMapIntensity=l,"undefined"==typeof c&&(c=new GameLib.D3.Color(1,1,1,1)),this.color=c,"undefined"==typeof p&&(p=new GameLib.D3.Color(0,0,0,0)),this.emissive=p,"undefined"==typeof m&&(m=1),this.emissiveIntensity=m,"undefined"==typeof d&&(d=GameLib.D3.Material.TYPE_MULTIPLY_OPERATION),this.combine=d,"undefined"==typeof y&&(y=30),this.shininess=y,"undefined"==typeof u&&(u=1),this.reflectivity=u,"undefined"==typeof f&&(f=.98),this.refractionRatio=f,"undefined"==typeof b&&(b=!0),this.fog=b,"undefined"==typeof L&&(L=!1),this.wireframe=L,"undefined"==typeof v&&(v=1),this.wireframeLineWidth=v,"undefined"==typeof E&&(E="round"),this.wireframeLineCap=E,"undefined"==typeof D&&(D="round"),this.wireframeLineJoin=D,"undefined"==typeof T&&(T=GameLib.D3.Material.TYPE_NO_COLORS),this.vertexColors=T,"undefined"==typeof G&&(G=!1),this.skinning=G,"undefined"==typeof g&&(g=!1),this.morphTargets=g,"undefined"==typeof w&&(w=!1),this.morphNormals=w,"undefined"==typeof U&&(U=0),this.overdraw=U,"undefined"==typeof P&&(P=1),this.lineWidth=P,"undefined"==typeof x&&(x="round"),this.lineCap=x,"undefined"==typeof _&&(_="round"),this.lineJoin=_,"undefined"==typeof N&&(N=3),this.dashSize=N,"undefined"==typeof M&&(M=1),this.gapWidth=M,"undefined"==typeof A&&(A=GameLib.D3.Material.TYPE_NORMAL_BLENDING),this.blending=A,"undefined"==typeof R&&(R=GameLib.D3.Material.TYPE_SRC_ALPHA_FACTOR),this.blendSrc=R,"undefined"==typeof S&&(S=GameLib.D3.Material.TYPE_ONE_MINUS_SRC_ALPHA_FACTOR),this.blendDst=S,"undefined"==typeof O&&(O=GameLib.D3.Material.TYPE_ADD_EQUATION),this.blendEquation=O,"undefined"==typeof V&&(V=!0),this.depthTest=V,"undefined"==typeof I&&(I=GameLib.D3.Material.TYPE_LESS_EQUAL_DEPTH),this.depthFunc=I,"undefined"==typeof C&&(C=!0),this.depthWrite=C,"undefined"==typeof z&&(z=!1),this.polygonOffset=z,"undefined"==typeof Y&&(Y=1),this.polygonOffsetFactor=Y,"undefined"==typeof H&&(H=1),this.polygonOffsetUnits=H,"undefined"==typeof F&&(F=0),this.alphaTest=F,"undefined"==typeof k&&(k=[]),this.clippingPlanes=k,"undefined"==typeof B&&(B=!1),this.clipShadows=B,"undefined"==typeof W&&(W=!0),this.visible=W,"undefined"==typeof q&&(q=GameLib.D3.Material.TYPE_FLAT_SHADING),this.shading=q,"undefined"==typeof j&&(j=1),this.bumpScale=j,"undefined"==typeof Q&&(Q=1),this.normalScale=Q,"undefined"==typeof X&&(X=1),this.displacementScale=X,"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.prototype.createThreeMaterial=function(e){var i=this.Q.defer(),t=null,n=[];if(e.materialType==GameLib.D3.Material.TYPE_MESH_STANDARD?(t=new this.THREE.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 this.THREE.Color(e.color.r,e.color.g,e.color.b),roughness:e.roughness,metalness:e.metalness,lightMapIntensity:e.lightMapIntensity,aoMapIntensity:e.aoMapIntensity,emissive:new this.THREE.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}),n.push("diffuse","light","ao","emissive","bump","normal","displacement","roughness","metalness","alpha","environment")):e.materialType==GameLib.D3.Material.TYPE_MESH_PHONG?(t=new this.THREE.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 this.THREE.Color(e.color.r,e.color.g,e.color.b),specular:new this.THREE.Color(e.specular.r,e.specular.g,e.specular.b),shininess:e.shininess,lightMapIntensity:e.lightMapIntensity,aoMapIntensity:e.aoMapIntensity,emissive:new this.THREE.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}),n.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"),n.length>0){var s=this.loadMaps(e,n,t);Q.all(s).then(function(){i.resolve(t)}).catch(function(e){console.log(e),i.reject(e)})}else i.resolve(t);return i.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,l,c,p,m,d,y,u,f,b,L,v){this.id=e,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 l&&(l=[]),this.skinWeights=l,"undefined"==typeof c&&(c=[]),this.materials=c,"undefined"==typeof p&&(p=new GameLib.D3.Vector3(0,0,0)),this.position=p,"undefined"==typeof m&&new GameLib.D3.Vector4,this.quaternion=m,"undefined"==typeof d&&(d=new GameLib.D3.Vector3(0,0,0)),this.rotation=d,"undefined"==typeof y&&(y=new GameLib.D3.Vector3(1,1,1)),this.scale=y,"undefined"==typeof u&&(u=new GameLib.D3.Vector3(0,1,0)),this.up=u,this.physics=f,this.parentMeshId=b,this.parentSceneId=L,this.rawData=null},GameLib.D3.Mesh.TYPE_NORMAL=0,GameLib.D3.Mesh.TYPE_SKINNED=1,GameLib.D3.prototype.createThreeMesh=function(e,i,t){var n=null;if(e.meshType==GameLib.D3.Mesh.TYPE_NORMAL&&(n=new this.THREE.Mesh(i,t)),e.meshType==GameLib.D3.Mesh.TYPE_SKINNED){for(var s=e.skeleton.bones,o=e.skinIndices,a=e.skinWeights,r=[],h=0;h<s.length;h++){var l=new this.THREE.Bone;l.name=s[h].name,l.position.x=s[h].position.x,l.position.y=s[h].position.y,l.position.z=s[h].position.z,l.rotation.x=s[h].rotation.x,l.rotation.y=s[h].rotation.y,l.rotation.z=s[h].rotation.z,l.quaternion.x=s[h].quaternion.x,l.quaternion.y=s[h].quaternion.y,l.quaternion.z=s[h].quaternion.z,l.quaternion.w=s[h].quaternion.w,l.scale.x=s[h].scale.x,l.scale.y=s[h].scale.y,l.scale.z=s[h].scale.z,l.up.x=s[h].up.x,l.up.y=s[h].up.y,l.up.z=s[h].up.z,r.push(l)}for(var c=0;c<s.length;c++)for(var p=0;p<s[c].childBoneIds.length;p++)r[c].add(r[s[c].childBoneIds[p]]);for(var m=0;m<o.length;m++)i.skinIndices.push(new this.THREE.Vector4(o[m].x,o[m].y,o[m].z,o[m].w));for(var d=0;d<a.length;d++)i.skinWeights.push(new this.THREE.Vector4(a[d].x,a[d].y,a[d].z,a[d].w));n=new this.THREE.SkinnedMesh(i,t);var y=new this.THREE.Skeleton(r);y.useVertexTexture=e.skeleton.useVertexTexture;for(var u=0;u<s.length;u++)if(null===s[u].parentBoneId){n.add(r[u]);break}n.bind(y),n.pose(),n.skeleton.skeletonHelper=new this.THREE.SkeletonHelper(n),n.skeleton.skeletonHelper.material.linewidth=5}return null==n&&console.log("cannot handle meshes of type "+e.meshType+" yet."),e.threeMeshId=n.id,n},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],l=e[a+2];o.push({v0:r,v1:h,v2:l,edges:[{v0:r,v1:h},{v0:h,v1:l},{v0:l,v1:r}],winding:0,edgeIndex:-1,processed:!1})}for(var c=0;c<o.length;c++)if(GameLib.D3.Vector3.clockwise(i[o[c].v0].position,i[o[c].v1].position,i[o[c].v2].position,s)){console.log("clockwise");var p=o[c].v1;o[c].v1=o[c].v2,o[c].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 l=[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)],c=0;c<l.length;c++){var p=n(l[c],e,a.triangle);p&&!t(o,p.triangle)&&s.push(p)}}for(var m=[],d=0;d<o.length;d++){for(var y=!1,u=0;u<m.length;u++)if(m[u].equals(o[d].triangle)){y=!0;break}y||m.push(o[d].triangle)}return m},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.Physics.RaycastVehicle=function(){this.vehicleObject=null},GameLib.D3.Physics.RigidVehicle=function(){this.vehicleObject=null},GameLib.D3.Physics.RigidBody=function(e,i,t,n,s,o,a,r,h,l,c,p,m,d,y){this.position=t||new GameLib.D3.Vector3,this.velocity=s||new GameLib.D3.Vector3,this.angularVelocity=o||new GameLib.D3.Vector3,this.quaternion=n||new GameLib.D3.Vector4(0,0,0,1),this.mass="undefined"==typeof e?0:e,this.friction="undefined"==typeof i?5:i,this.linearDamping="undefined"==typeof a?.01:a,this.angularDamping="undefined"==typeof r?.01:r,this.allowSleep="undefined"==typeof h||h,this.sleepSpeedLimit="undefined"==typeof l?.1:l,this.sleepTimeLimit="undefined"==typeof c?1:c,this.collisionFilterGroup="undefined"==typeof p?1:p,this.collisionFilterMask="undefined"==typeof m?1:m,this.fixedRotation="undefined"!=typeof d&&d,this.shape="undefined"==typeof y?null:y,this.rigidBodyInstance=this.createRigidBodyInstance()},GameLib.D3.Physics.World.RigidBody.prototype.createRigidBodyInstance=function(){var e=null;return this.physics.engineType==GameLib.D3.Physics.TYPE_CANNON&&(e=new this.physics.CANNON.Body({mass:mass,friction:friction,position:new this.physics.CANNON.Vec3(position.x,position.y,position.z),velocity:new this.physics.CANNON.Vec3(velocity.x,velocity.y,velocity.z),quaternion:new this.physics.CANNON.Quaternion(quaternion.x,quaternion.y,quaternion.z,quaternion.w),angularVelocity:new this.physics.CANNON.Vec3(angularVelocity.x,angularVelocity.y,angularVelocity.z),linearDamping:linearDamping,angularDamping:angularDamping,allowSleep:allowSleep,sleepSpeedLimit:sleepSpeedLimit,sleepTimeLimit:sleepTimeLimit,collisionFilterGroup:collisionFilterGroup,collisionFilterMask:collisionFilterMask,fixedRotation:fixedRotation,shape:shape})),e},GameLib.D3.Scene=function(e,i,t,n,s,o,a,r,h,l,c){this.id=e,this.path=i,this.name=t,""==this.name.trim()&&(this.name="unnamed"),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 l&&(l=[]),this.lights=l,"undefined"==typeof c&&(c=[]),this.physics=c},GameLib.D3.prototype.loadSceneFromApi=function(e,i){if("undefined"==typeof XMLHttpRequest)return console.warn("implement server side loading from API here"),i(null,new Error("not implemented"));var t=new XMLHttpRequest;t.open("GET",this.apiUrl+"/scene/load"+e.path+"/"+e.name),t.onreadystatechange=function(e,t){return function(){if(4==e.readyState){var n=JSON.parse(e.responseText);if(!n.scene||0==n.scene.length)return i(null,null,new Error("Could not load scene"));var s=n.scene[0],o=[];if(s.physics&&s.physics.length>0)for(var a=0;a<s.physics.length;a++){for(var r=s.physics[a],h=new GameLib.D3.Physics(r.id,r.name,r.engineType,t.CANNON,null,null),l=[],c=0;c<r.worlds.length;c++){for(var p=r.worlds[c],m=p.broadphase,d=new GameLib.D3.Physics.Broadphase(m.id,m.name,m.broadphaseType),y=p.solver,u=new GameLib.D3.Physics.Solver(y.id,y.name,y.solverType,y.iterations,y.tolerance),f=p.rigidBodies,b=[],L=0;L<f.length;L++){var v=f[L],E=new GameLib.D3.Physics.RigidBody(v.id,v.name);b.push(E)}var D=new GameLib.D3.Physics.World(null,p.name,h,new GameLib.D3.Vector3(p.gravity.x,p.gravity.y,p.gravity.z),d,u,b);l.push(D)}o.push(h)}for(var T=[],G=0;G<s.lights.length;G++){var g=s.lights[G],w=new GameLib.D3.Light(g.id,g.lightType,g.name,new GameLib.D3.Color(g.color.r,g.color.g,g.color.b,g.color.a),g.intensity,new GameLib.D3.Vector3(g.position.x,g.position.y,g.position.z),new GameLib.D3.Vector3(g.targetPosition.x,g.targetPosition.y,g.targetPosition.z),new GameLib.D3.Vector4(g.quaternion.x,g.quaternion.y,g.quaternion.z,g.quaternion.w),new GameLib.D3.Vector3(g.rotation.x,g.rotation.y,g.rotation.z),new GameLib.D3.Vector3(g.scale.x,g.scale.y,g.scale.z),g.distance,g.decay,g.power,g.angle,g.penumbra);T.push(w)}var P=new GameLib.D3.Scene(s._id||s.id,s.path,s.name,s.meshes,new GameLib.D3.Vector4(s.quaternion.x,s.quaternion.y,s.quaternion.z,s.quaternion.w),new GameLib.D3.Vector3(s.position.x,s.position.y,s.position.z),new GameLib.D3.Vector3(s.rotation.x,s.rotation.y,s.rotation.z),new GameLib.D3.Vector3(s.scale.x,s.scale.y,s.scale.z),s.parentSceneId,T,o);t.loadScene(P,i,!1)}}}(t,this),t.send()},GameLib.D3.prototype.loadScene=function(e,i,t){console.log("loading scene "+e.name),this.path=e.path;for(var n=[],s=0;s<e.meshes.length;s++){var o=e.meshes[s];
console.log("loading mesh "+o.name);for(var a=new this.THREE.Geometry,r=o.vertices,h=o.faces,l=o.faceVertexUvs,c=o.materials,p=0;p<r.length;p++)a.vertices.push(new this.THREE.Vector3(r[p].position.x,r[p].position.y,r[p].position.z));for(var m=0;m<h.length;m++){var d=new this.THREE.Face3(h[m].v0,h[m].v1,h[m].v2,new this.THREE.Vector3(h[m].normal.x,h[m].normal.y,h[m].normal.z),new this.THREE.Color(h[m].color.r,h[m].color.g,h[m].color.b),h[m].materialIndex);d.vertexColors=[new this.THREE.Color(h[m].vertexColors[0].r,h[m].vertexColors[0].g,h[m].vertexColors[0].b),new this.THREE.Color(h[m].vertexColors[1].r,h[m].vertexColors[1].g,h[m].vertexColors[1].b),new this.THREE.Color(h[m].vertexColors[2].r,h[m].vertexColors[2].g,h[m].vertexColors[2].b)],d.normal=new this.THREE.Vector3(h[m].normal.x,h[m].normal.y,h[m].normal.z),d.vertexNormals=[new this.THREE.Vector3(h[m].vertexNormals[0].x,h[m].vertexNormals[0].y,h[m].vertexNormals[0].z),new this.THREE.Vector3(h[m].vertexNormals[1].x,h[m].vertexNormals[1].y,h[m].vertexNormals[1].z),new this.THREE.Vector3(h[m].vertexNormals[2].x,h[m].vertexNormals[2].y,h[m].vertexNormals[2].z)],a.faces.push(d)}a.faceVertexUvs=[];for(var y=0;y<l.length;y++){var u=l[y];a.faceVertexUvs[y]=[];for(var f=0;f<u.length;f++)a.faceVertexUvs[y][f]=[],a.faceVertexUvs[y][f].push(new this.THREE.Vector2(u[f][0].x,u[f][0].y),new this.THREE.Vector2(u[f][1].x,u[f][1].y),new this.THREE.Vector2(u[f][2].x,u[f][2].y))}t&&(a.computeFaceNormals(),a.computeVertexNormals());for(var b=[],L=0;L<c.length;L++)b.push(this.createThreeMaterial(c[L]));var v=this.Q.all(b).then(function(e,i,t){return function(n){console.log("loaded material : "+n[0].name);var s=n[0],o=e.createThreeMesh(i,t,s);return o.name=i.name,o.position.x=i.position.x,o.position.y=i.position.y,o.position.z=i.position.z,o.rotation.x=i.rotation.x,o.rotation.y=i.rotation.y,o.rotation.z=i.rotation.z,o.scale.x=i.scale.x,o.scale.y=i.scale.y,o.scale.z=i.scale.z,o.quaternion.x=i.quaternion.x,o.quaternion.y=i.quaternion.y,o.quaternion.z=i.quaternion.z,o.quaternion.w=i.quaternion.w,o}}(this,o,a)).catch(function(e){console.log(e)});n.push(v)}this.Q.all(n).then(function(t){if(console.log("all meshes have loaded"),"undefined"!=typeof i){for(var n=[],s=0;s<e.lights.length;s++){var o=e.lights[s],a=null;"AmbientLight"==o.lightType&&(a=new this.THREE.AmbientLight(o.color,o.intensity)),"DirectionalLight"==o.lightType&&(a=new this.THREE.DirectionalLight(o.color,o.intensity)),"PointLight"==o.lightType&&(a=new this.THREE.PointLight(o.color,o.intensity),a.distance=o.distance,a.decay=o.decay),"SpotLight"==o.lightType&&(a=new this.THREE.SpotLight(o.color,o.intensity),a.distance=o.distance,a.angle=o.angle,a.penumbra=o.penumbra,a.decay=o.decay),a.position.x=o.position.x,a.position.y=o.position.y,a.position.z=o.position.z,a.rotation.x=o.rotation.x,a.rotation.y=o.rotation.y,a.rotation.z=o.rotation.z,null==a?console.warn("Does not support lights of type :"+o.lightType+", not imported"):(a.name=o.name,n.push(a))}var r=new this.THREE.Scene;r.name=e.name,r.position.x=e.position.x,r.position.y=e.position.y,r.position.z=e.position.z,r.rotation.x=e.rotation.x,r.rotation.y=e.rotation.y,r.rotation.z=e.rotation.z,r.scale.x=e.scale.x,r.scale.y=e.scale.y,r.scale.z=e.scale.z,r.quaternion.x=e.quaternion.x,r.quaternion.y=e.quaternion.y,r.quaternion.z=e.quaternion.z,r.quaternion.w=e.quaternion.w;for(var h=0;h<t.length;h++)r.add(t[h]);for(var l=0;l<n.length;l++)r.add(n[l]);i(e,{scene:r,lights:n,meshes:t})}}.bind(this)).catch(function(e){console.log(e)})},GameLib.D3.Physics.Shape=function(e,i){this.shapeObject=e,this.shapeType=i,this.scale=new GameLib.D3.Vector3(1,1,1)},GameLib.D3.Physics.SHAPE_TYPE_SPHERE=1,GameLib.D3.Physics.SHAPE_TYPE_BOX=2,GameLib.D3.Physics.SHAPE_TYPE_TRIMESH=3,GameLib.D3.Physics.SHAPE_TYPE_CYLINDER=4,GameLib.D3.Physics.Shape.prototype.Update=function(){this.physics.engineType===GameLib.D3.Physics.TYPE_CANNON&&this.shapeType===GameLib.D3.Physics.SHAPE_TYPE_TRIMESH&&(this.shapeObject.setScale(new this.physics.CANNON.Vec3(this.scale.x,this.scale.y,this.scale.z)),this.shapeObject.updateAABB(),this.shapeObject.updateNormals(),this.shapeObject.updateEdges(),this.shapeObject.updateBoundingSphereRadius(),this.shapeObject.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(){this.id=null,this.texturesFolder=null},GameLib.D3.SkyBox.prototype.Load=function(e){this.texturesFolder=e,this.textures=[],this.materials=[],this.mesh={},this.scene=new THREE.Scene,this.textureCube=null;var i=new THREE.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 THREE.MeshBasicMaterial({map:this.textures[t]}));this.mesh=new THREE.Mesh(new THREE.CubeGeometry(1,1,1),new THREE.MeshFaceMaterial(this.materials)),this.mesh.applyMatrix((new THREE.Matrix4).makeScale(1,1,-1)),this.scene.add(this.mesh),this.textureCube=(new THREE.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 THREE.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.Physics.Solver=function(e,i,t,n,s){this.id=e,"undefined"==typeof i&&(i=t==GameLib.D3.Physics.SPLIT_SOLVER?"split solver":t==GameLib.D3.Physics.GS_SOLVER?"gs solver":"unknown solver"),this.name=i,this.solverType=t,this.iterations=n,this.tolerance=s},GameLib.D3.Physics.SPLIT_SOLVER=1,GameLib.D3.Physics.GS_SOLVER=2,GameLib.D3.Texture=function(e,i,t,n,s,o,a,r,h,l,c,p,m,d,y,u,f,b,L,v){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 l&&(l=GameLib.D3.Texture.TYPE_LINEAR_FILTER),this.magFilter=l,"undefined"==typeof c&&(c=GameLib.D3.Texture.TYPE_LINEAR_MIPMAP_LINEAR_FILTER),this.minFilter=c,"undefined"==typeof p&&(p=GameLib.D3.Texture.TYPE_UNSIGNED_BYTE),this.textureType=p,"undefined"==typeof m&&(m=1),this.anisotropy=m,"undefined"==typeof d&&(d=new GameLib.D3.Vector2(0,0)),this.offset=d,"undefined"==typeof y&&(y=!0),this.generateMipmaps=y,"undefined"==typeof u&&(u=!0),this.flipY=u,"undefined"==typeof f&&(f=[]),this.mipmaps=f,"undefined"==typeof b&&(b=4),this.unpackAlignment=b,"undefined"==typeof L&&(L=!1),this.premultiplyAlpha=L,"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.prototype.loadMap=function(e,i,t){var n=this.Q.defer(),s=null;return e&&e.image&&e.image.filename&&(s=this.editorUrl+"/uploads"+this.path+"/"+e.image.filename),s?(this.textureLoader.crossOrigin="",this.textureLoader.load(s,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 this.THREE.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,n.resolve(!0)},function(e){this.editor&&this.editor.setServerStatus(Math.round(e.loaded/e.total*100)+"% complete","success")},function(e){console.log("an error occurred while trying to load the image : "+s),n.resolve(null)})):n.resolve(null),n.promise},GameLib.D3.prototype.loadMaps=function(e,i,t){for(var n=[],s=0;s<i.length;s++){var o=i[s];if(e.maps.hasOwnProperty(o)){var a=e.maps[o];if(a&&a.image&&a.image.filename){var r=null;"alpha"==o&&(r="alhpaMap"),"ao"==o&&(r="aoMap"),"bump"==o&&(r="bumpMap"),"displacement"==o&&(r="displacementMap"),"emissive"==o&&(r="emissiveMap"),"environment"==o&&(r="envMap"),"light"==o&&(r="lightMap"),"specular"==o&&(r="specularMap"),"diffuse"==o&&(r="map"),"roughness"==o&&(r="roughnessMap"),"metalness"==o&&(r="metalnessMap"),null==r&&console.warn("unsupported map type : "+o),n.push(this.loadMap(e.maps[o],t,r))}}}return n},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,l,c){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,l||(l=[new GameLib.D3.Vector3,new GameLib.D3.Vector3,new GameLib.D3.Vector3]),this.vertexNormals=l,c||(c=new GameLib.D3.Vector3(0)),this.normal=c},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.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 l=(new GameLib.D3.Matrix4).rotationMatrixY(n),c=0;c<this.vectors.length;c++)this.vectors[c]=l.multiply(this.vectors[c])},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 l=(new GameLib.D3.Matrix4).rotationMatrixX(n),c=0;c<this.vectors.length;c++)this.vectors[c]=l.multiply(this.vectors[c])},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.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.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.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=null,this.worldInstance=null,t&&(this.engine=t,this.worldInstance=this.createWorldInstance())},GameLib.D3.World.prototype.createWorldInstance=function(){this.engine.isNotCannonThrow();var e=new this.engine.instance.World,i=null;e.broadphase=i;var t=null;this.solver.solverType==GameLib.D3.Physics.SPLIT_SOLVER?t=new this.engine.instance.SplitSolver:this.solver.solverType==GameLib.D3.Physics.GS_SOLVER&&(t=new this.engine.instance.GSSolver,t.iterations=this.solver.iterations),e.solver=t,e.gravity.x=this.gravity.x,e.gravity.y=this.gravity.y,e.gravity.z=this.gravity.z;for(var n=0;n<this.rigidBodies.length;n++){this.createCustomBody(this.rigidBodies[n])}return e.name=this.name,e},GameLib.D3.Physics.World.prototype.AddShape=function(e,i,t,n){if(e.shape=e,this.physics.engineType===GameLib.D3.Physics.TYPE_CANNON){var s=null,o=null;null!=t&&"undefined"!=typeof t&&(s=new this.physics.CANNON.Vec3(t.x,t.y,t.z)),null!=n&&"undefined"!=typeof n&&(o=new this.physics.CANNON.Quaternion(n.x,n.y,n.z,n.w)),i.bodyObject.addShape(e.shapeObject,s,o)}},GameLib.D3.Physics.World.prototype.Wheel=function(){},GameLib.D3.Physics.World.prototype.CreateRigidVehicle=function(e){var i=new GameLib.D3.Physics.RigidVehicle;if(this.physics.engineType==GameLib.D3.Physics.TYPE_CANNON){var t=new this.physics.CANNON.RigidVehicle({chassisBody:e.bodyObject});return i.vehicleObject=t,i}},GameLib.D3.Physics.World.prototype.CreateRaycastVehicle=function(e){var i=new GameLib.D3.Physics.RaycastVehicle;if(this.physics.engineType==GameLib.D3.Physics.TYPE_CANNON){var t=new this.physics.CANNON.RaycastVehicle({chassisBody:e.bodyObject});return i.vehicleObject=t,i}},GameLib.D3.Physics.World.prototype.AddWheelToRigidVehicle=function(e,i,t,n,s){this.physics.engineType==GameLib.D3.Physics.TYPE_CANNON&&e.vehicleObject.addWheel({body:i.bodyObject,position:new this.physics.CANNON.Vec3(t.x,t.y,t.z),axis:new this.physics.CANNON.Vec3(n.x,n.y,n.z),direction:new this.physics.CANNON.Vec3(s.x,s.y,s.z)})},GameLib.D3.Physics.World.prototype.AddWheelToRaycastVehicle=function(e,i){this.physics.engineType==GameLib.D3.Physics.TYPE_CANNON?e.vehicleObject.addWheel(i):console.log("function for engine not implemented")},GameLib.D3.Physics.World.prototype.RigidVehicle.prototype.GetWheelInfo=function(){return this.vehicleObject.wheelBodies},GameLib.D3.Physics.World.prototype.RaycastVehicle.prototype.GetWheelInfo=function(){return this.vehicleObject.wheelInfos},GameLib.D3.Physics.World.prototype.CreateTriMeshShape=function(e,i){if(this.physics.engineType==GameLib.D3.Physics.TYPE_CANNON)return new GameLib.D3.Physics.Shape(new this.physics.CANNON.Trimesh(e,i),GameLib.D3.Physics.SHAPE_TYPE_TRIMESH)},GameLib.D3.Physics.World.prototype.CreateSphereShape=function(e){if(this.physics.engineType==GameLib.D3.Physics.TYPE_CANNON)return new GameLib.D3.Physics.Shape(new this.physics.CANNON.Sphere(e),GameLib.D3.Physics.SHAPE_TYPE_SPHERE)},GameLib.D3.Physics.World.prototype.CreateBoxShape=function(e){if(this.physics.engineType==GameLib.D3.Physics.TYPE_CANNON)return new GameLib.D3.Physics.Shape(new this.physics.CANNON.Box(new this.physics.CANNON.Vec3(e.x,e.y,e.z)),GameLib.D3.Physics.SHAPE_TYPE_BOX)},GameLib.D3.Physics.World.prototype.CreateCylinderShape=function(e,i,t,n){if(this.physics.engineType==GameLib.D3.Physics.TYPE_CANNON)return new GameLib.D3.Physics.Shape(new this.physics.CANNON.Cylinder(e,i,t,n),GameLib.D3.Physics.SHAPE_TYPE_CYLINDER)},GameLib.D3.Physics.World.prototype.AddRigidBody=function(e){this.physics.engineType===GameLib.D3.Physics.TYPE_CANNON&&this.worldObject.addBody(e.bodyObject)},GameLib.D3.Physics.World.prototype.AddVehicle=function(e){this.physics.engineType==GameLib.D3.Physics.TYPE_CANNON&&e.vehicleObject.addToWorld(this.worldObject)},GameLib.D3.Physics.World.prototype.Step=function(e){if(this.physics.engineType==GameLib.D3.Physics.TYPE_CANNON){var i=performance.now()/1e3;if(!this.lastCallTime)return this.worldObject.step(e),void(this.lastCallTime=i);var t=i-this.lastCallTime;this.worldObject.step(e,t),this.lastCallTime=i}},GameLib.D3.Physics.World.prototype.GetIndexedVertices=function(e){return this.engine.engineType==GameLib.D3.Physics.TYPE_CANNON?{vertices:e.vertices,indices:e.indices}:null},GameLib.D3.Physics.World.prototype.GenerateWireframeViewMesh=function(e,i,t,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,l=r.vertices.length/3;h<l;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,l=r.indices.length/3;h<l;h++){var c=r.indices[3*h],p=r.indices[3*h+1],m=r.indices[3*h+2];o.faces.push(new THREE.Face3(c,p,m));var d=(new THREE.Vector3).add(o.vertices[c]).add(o.vertices[p]).add(o.vertices[m]).divideScalar(3),y=null;if(this.engine.engineType==GameLib.D3.Physics.TYPE_CANNON){var y=new this.physics.CANNON.Vec3;e.getNormal(h,y)}var u=new THREE.ArrowHelper(new THREE.Vector3(y.x,y.y,y.z),d,i,new THREE.Color(y.x,y.y,y.z));a.add(u)}return a.scale.x=t.x,a.scale.y=t.y,a.scale.z=t.z,a},GameLib.D3.Physics.World.prototype.GenerateTriangleCollisionMesh=function(e,i,t,n,s,o){for(var a=0,r=s||0,h=o||0,l=e.geometry.faces.length,c=n?h*r:l,p=[],m=[],d=[],y=0;y<=l;y++){if(a==c||y==l){var u=null;if(this.engine.engineType==GameLib.D3.Physics.TYPE_CANNON){var f=new this.physics.CANNON.Trimesh(m,d);f.setScale(new this.physics.CANNON.Vec3(e.scale.x,e.scale.y,e.scale.z)),f.updateAABB(),f.updateNormals(),f.updateEdges(),f.updateBoundingSphereRadius(),f.updateTree(),u=new this.physics.CANNON.Body({mass:i?i:0,friction:t?t:10}),u.addShape(f)}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:u}),m=[],d=[],a=0,y==l)return p}var b=e.geometry.faces[y];d.push(d.length),d.push(d.length),d.push(d.length);var L=e.geometry.vertices[b.a],v=e.geometry.vertices[b.b],E=e.geometry.vertices[b.c];m.push(L.x,L.y,L.z),m.push(v.x,v.y,v.z),m.push(E.x,E.y,E.z),a++}},"undefined"!=typeof module&&(module.exports=GameLib);