2 lines
56 KiB
JavaScript
2 lines
56 KiB
JavaScript
function GameLib(){}"undefined"==typeof GameLib.D3&&(GameLib.D3=function(){}),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,l){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 l&&(l=new GameLib.D3.Vector3(0,1,0)),this.up=l},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],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,t,i){i.linkedPairs=i.linkedPairs||[],i.linkedPairs.push({threeMesh:e,physicsBody:t})},GameLib.D3.Heightmap=function(e,t,i){"undefined"==typeof e&&(e=0),this.sizeX=e,"undefined"==typeof t&&(t=0),this.sizeY=t,"undefined"==typeof i&&(i=[]),this.matrix=i},GameLib.D3.Heightmap.prototype.generateThreeMeshFromHeightField=function(e,t,i){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=t,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,t){var i=new Image;i.onload=function(){var e=document.createElement("canvas");e.width=i.width,e.height=i.height;var n=e.getContext("2d");n.drawImage(i,0,0);for(var s=n.getImageData(0,0,i.width,i.height),o=s.data,a=[],r=0,h=o.length;r<h;r+=4)a.push(o[r]);for(var l=[],c=i.width,p=i.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)}}t(new GameLib.D3.HeightmapData(c,p,l))},i.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,l,c,p,m,d,y){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 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,t,i,n,s,o,a,r,h,l,c,p,m,d,y,u,f,b,L,v,D,E,G,T,g,w,x,P,_,N,M,A,R,S,O,V,I,C,z,Y,H,F,k,B,U,W,q,j,Q,X,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 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 D&&(D="round"),this.wireframeLineCap=D,"undefined"==typeof E&&(E="round"),this.wireframeLineJoin=E,"undefined"==typeof G&&(G=GameLib.D3.Material.TYPE_NO_COLORS),this.vertexColors=G,"undefined"==typeof T&&(T=!1),this.skinning=T,"undefined"==typeof g&&(g=!1),this.morphTargets=g,"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 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 U&&(U=!0),this.visible=U,"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 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.prototype.createThreeMaterial=function(e,t){var i=this.Q.defer(),n=null,s=[];if(e.materialType==GameLib.D3.Material.TYPE_MESH_STANDARD?(n=new t.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.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.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}),s.push("diffuse","light","ao","emissive","bump","normal","displacement","roughness","metalness","alpha","environment")):e.materialType==GameLib.D3.Material.TYPE_MESH_PHONG?(n=new t.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.Color(e.color.r,e.color.g,e.color.b),specular:new t.Color(e.specular.r,e.specular.g,e.specular.b),shininess:e.shininess,lightMapIntensity:e.lightMapIntensity,aoMapIntensity:e.aoMapIntensity,emissive:new t.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}),s.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"),s.length>0){var o=this.loadMaps(e,s,n);Q.all(o).then(function(){i.resolve(n)}).catch(function(e){console.log(e),i.reject(e)})}else i.resolve(n);return i.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,l,c,p,m,d,y,u,f,b,L,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 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,t,i){var n=null;if(e.meshType==GameLib.D3.Mesh.TYPE_NORMAL&&(n=new this.THREE.Mesh(t,i)),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++)t.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++)t.skinWeights.push(new this.THREE.Vector4(a[d].x,a[d].y,a[d].z,a[d].w));n=new this.THREE.SkinnedMesh(t,i);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 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],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(t[o[c].v0].position,t[o[c].v1].position,t[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,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 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&&!i(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,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(){this.vehicleObject=null},GameLib.D3.RaycastVehicle.prototype.GetWheelInfo=function(){return this.vehicleObject.wheelInfos},GameLib.D3.RigidVehicle=function(){this.vehicleObject=null},GameLib.D3.RigidVehicle.prototype.GetWheelInfo=function(){return this.vehicleObject.wheelBodies},GameLib.D3.RigidBody=function(e,t,i,n,s,o,a,r,h,l,c,p,m,d,y){this.position=i||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 t?5:t,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.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,t,i,n,s,o,a,r,h,l,c){this.id=e,this.path=t,this.name=i,""==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,t){if("undefined"==typeof XMLHttpRequest)return console.warn("implement server side loading from API here"),t(null,new Error("not implemented"));var i=new XMLHttpRequest;i.open("GET",this.apiUrl+"/scene/load"+e.path+"/"+e.name),i.onreadystatechange=function(e,i){return function(){if(4==e.readyState){var n=JSON.parse(e.responseText);if(!n.scene||0==n.scene.length)return t(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,i.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],D=new GameLib.D3.Physics.RigidBody(v.id,v.name);b.push(D)}var E=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(E)}o.push(h)}for(var G=[],T=0;T<s.lights.length;T++){var g=s.lights[T],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);G.push(w)}var x=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,G,o);i.loadScene(x,t,!1)}}}(i,this),i.send()},GameLib.D3.prototype.loadScene=function(e,t,i){
|
|
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))}i&&(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,t,i){return function(n){console.log("loaded material : "+n[0].name);var s=n[0],o=e.createThreeMesh(t,i,s);return o.name=t.name,o.position.x=t.position.x,o.position.y=t.position.y,o.position.z=t.position.z,o.rotation.x=t.rotation.x,o.rotation.y=t.rotation.y,o.rotation.z=t.rotation.z,o.scale.x=t.scale.x,o.scale.y=t.scale.y,o.scale.z=t.scale.z,o.quaternion.x=t.quaternion.x,o.quaternion.y=t.quaternion.y,o.quaternion.z=t.quaternion.z,o.quaternion.w=t.quaternion.w,o}}(this,o,a)).catch(function(e){console.log(e)});n.push(v)}this.Q.all(n).then(function(i){if(console.log("all meshes have loaded"),"undefined"!=typeof t){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<i.length;h++)r.add(i[h]);for(var l=0;l<n.length;l++)r.add(n[l]);t(e,{scene:r,lights:n,meshes:i})}}.bind(this)).catch(function(e){console.log(e)})},GameLib.D3.Physics.Shape=function(e,t){this.shapeObject=e,this.shapeType=t,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,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(){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 t=new THREE.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 THREE.MeshBasicMaterial({map:this.textures[i]}));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,t){var i=new THREE.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,l,c,p,m,d,y,u,f,b,L,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 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,t,i){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){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 this.THREE.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,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,t,i){for(var n=[],s=0;s<t.length;s++){var o=t[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],i,r))}}}return n},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,l,c){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,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,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 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 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 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,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=null,this.worldInstance=null,i&&(this.engine=i,this.worldInstance=this.createWorldInstance())},GameLib.D3.World.prototype.createWorldInstance=function(){this.engine.isNotCannonThrow();var e=new this.engine.instance.World,t=null;e.broadphase=t;var i=null;this.solver.solverType==GameLib.D3.Physics.SPLIT_SOLVER?i=new this.engine.instance.SplitSolver:this.solver.solverType==GameLib.D3.Physics.GS_SOLVER&&(i=new this.engine.instance.GSSolver,i.iterations=this.solver.iterations),e.solver=i,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.World.prototype.AddShape=function(e,t,i,n){if(e.shape=e,this.physics.engineType===GameLib.D3.Physics.TYPE_CANNON){var s=null,o=null;null!=i&&"undefined"!=typeof i&&(s=new this.physics.CANNON.Vec3(i.x,i.y,i.z)),null!=n&&"undefined"!=typeof n&&(o=new this.physics.CANNON.Quaternion(n.x,n.y,n.z,n.w)),t.bodyObject.addShape(e.shapeObject,s,o)}},GameLib.D3.World.prototype.Wheel=function(){},GameLib.D3.World.prototype.CreateRigidVehicle=function(e){var t=new GameLib.D3.Physics.RigidVehicle;if(this.physics.engineType==GameLib.D3.Physics.TYPE_CANNON){var i=new this.physics.CANNON.RigidVehicle({chassisBody:e.bodyObject});return t.vehicleObject=i,t}},GameLib.D3.World.prototype.CreateRaycastVehicle=function(e){var t=new GameLib.D3.Physics.RaycastVehicle;if(this.physics.engineType==GameLib.D3.Physics.TYPE_CANNON){var i=new this.physics.CANNON.RaycastVehicle({chassisBody:e.bodyObject});return t.vehicleObject=i,t}},GameLib.D3.World.prototype.AddWheelToRigidVehicle=function(e,t,i,n,s){this.physics.engineType==GameLib.D3.Physics.TYPE_CANNON&&e.vehicleObject.addWheel({body:t.bodyObject,position:new this.physics.CANNON.Vec3(i.x,i.y,i.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.World.prototype.AddWheelToRaycastVehicle=function(e,t){this.physics.engineType==GameLib.D3.Physics.TYPE_CANNON?e.vehicleObject.addWheel(t):console.log("function for engine not implemented")},GameLib.D3.World.prototype.CreateTriMeshShape=function(e,t){if(this.physics.engineType==GameLib.D3.Physics.TYPE_CANNON)return new GameLib.D3.Physics.Shape(new this.physics.CANNON.Trimesh(e,t),GameLib.D3.Physics.SHAPE_TYPE_TRIMESH)},GameLib.D3.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.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.World.prototype.CreateCylinderShape=function(e,t,i,n){if(this.physics.engineType==GameLib.D3.Physics.TYPE_CANNON)return new GameLib.D3.Physics.Shape(new this.physics.CANNON.Cylinder(e,t,i,n),GameLib.D3.Physics.SHAPE_TYPE_CYLINDER)},GameLib.D3.World.prototype.AddRigidBody=function(e){this.physics.engineType===GameLib.D3.Physics.TYPE_CANNON&&this.worldObject.addBody(e.bodyObject)},GameLib.D3.World.prototype.AddVehicle=function(e){this.physics.engineType==GameLib.D3.Physics.TYPE_CANNON&&e.vehicleObject.addToWorld(this.worldObject)},GameLib.D3.World.prototype.Step=function(e){if(this.physics.engineType==GameLib.D3.Physics.TYPE_CANNON){var t=performance.now()/1e3;if(!this.lastCallTime)return this.worldObject.step(e),void(this.lastCallTime=t);var i=t-this.lastCallTime;this.worldObject.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.prototype.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,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,t,new THREE.Color(y.x,y.y,y.z));a.add(u)}return a.scale.x=i.x,a.scale.y=i.y,a.scale.z=i.z,a},GameLib.D3.World.prototype.GenerateTriangleCollisionMesh=function(e,t,i,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:t?t:0,friction:i?i: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],D=e.geometry.vertices[b.c];m.push(L.x,L.y,L.z),m.push(v.x,v.y,v.z),m.push(D.x,D.y,D.z),a++}},"undefined"!=typeof module&&(module.exports=GameLib); |