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

2 lines
57 KiB
JavaScript
Raw Normal View History

2016-10-27 18:47:02 +02:00
function GameLib(){}if("undefined"==typeof GameLib.D3&&(GameLib.D3=function(){}),"undefined"==typeof Q){if("undefined"==typeof require)throw console.warn("You need the Q promise library for the GameLib.D3"),new Error("You need the Q promise library for the GameLib.D3");var Q=require("q")}GameLib.D3.BoneWeight=function(e,i){this.boneIndex=e,this.weight=i},GameLib.D3.Bone=function(e,i,t,n,s,o,a,r,h,c){this.id=e,this.name=t,this.boneId=i,"undefined"==typeof n&&(n=[]),this.childBoneIds=n,"undefined"==typeof s&&(s=null),this.parentBoneId=s,"undefined"==typeof o&&(o=new GameLib.D3.Vector4),this.quaternion=o,"undefined"==typeof a&&(a=new GameLib.D3.Vector3(0,0,0)),this.position=a,"undefined"==typeof r&&(r=new GameLib.D3.Vector3(0,0,0)),this.rotation=r,"undefined"==typeof h&&(h=new GameLib.D3.Vector3(1,1,1)),this.scale=h,"undefined"==typeof c&&(c=new GameLib.D3.Vector3(0,1,0)),this.up=c},GameLib.D3.Broadphase=function(e,i,t,n,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||doc
2016-10-26 16:13:18 +02:00
w.push(_)}var N=new GameLib.D3.Scene(a._id||a.id,a.path,a.name,a.meshes,new GameLib.D3.Vector4(a.quaternion.x,a.quaternion.y,a.quaternion.z,a.quaternion.w),new GameLib.D3.Vector3(a.position.x,a.position.y,a.position.z),new GameLib.D3.Vector3(a.rotation.x,a.rotation.y,a.rotation.z),new GameLib.D3.Vector3(a.scale.x,a.scale.y,a.scale.z),a.parentSceneId,w,r);GameLib.D3.Scene.loadScene(N,i,!1,t,n,s)}}}(a),a.send()},GameLib.D3.Scene.loadScene=function(e,i,t,n,s,o){console.log("loading scene "+e.name),n.isNotThreeThrow();for(var a=[],r=0;r<e.meshes.length;r++){var h=e.meshes[r];console.log("loading mesh "+h.name);for(var c=new n.instance.Geometry,l=h.vertices,p=h.faces,m=h.faceVertexUvs,d=h.materials,u=0;u<l.length;u++)c.vertices.push(new n.instance.Vector3(l[u].position.x,l[u].position.y,l[u].position.z));for(var y=0;y<p.length;y++){var f=new n.instance.Face3(p[y].v0,p[y].v1,p[y].v2,new n.instance.Vector3(p[y].normal.x,p[y].normal.y,p[y].normal.z),new n.instance.Color(p[y].color.r,p[y].color.g,p[y].color.b),p[y].materialIndex);f.vertexColors=[new n.instance.Color(p[y].vertexColors[0].r,p[y].vertexColors[0].g,p[y].vertexColors[0].b),new n.instance.Color(p[y].vertexColors[1].r,p[y].vertexColors[1].g,p[y].vertexColors[1].b),new n.instance.Color(p[y].vertexColors[2].r,p[y].vertexColors[2].g,p[y].vertexColors[2].b)],f.normal=new n.instance.Vector3(p[y].normal.x,p[y].normal.y,p[y].normal.z),f.vertexNormals=[new n.instance.Vector3(p[y].vertexNormals[0].x,p[y].vertexNormals[0].y,p[y].vertexNormals[0].z),new n.instance.Vector3(p[y].vertexNormals[1].x,p[y].vertexNormals[1].y,p[y].vertexNormals[1].z),new n.instance.Vector3(p[y].vertexNormals[2].x,p[y].vertexNormals[2].y,p[y].vertexNormals[2].z)],c.faces.push(f)}c.faceVertexUvs=[];for(var b=0;b<m.length;b++){var L=m[b];c.faceVertexUvs[b]=[];for(var v=0;v<L.length;v++)c.faceVertexUvs[b][v]=[],c.faceVertexUvs[b][v].push(new n.instance.Vector2(L[v][0].x,L[v][0].y),new n.instance.Vector2(L[v][1].x,L[v][1].y),new n.instance.Vector2(L[v][2].x,L[v][2].y))}t&&(c.computeFaceNormals(),c.computeVertexNormals());for(var D=[],G=0;G<d.length;G++)D.push(GameLib.D3.Material.createInstanceMaterial(d[G],n,s,o));var T=Q.all(D).then(function(e,i){return function(t){console.log("loaded material : "+t[0].name);var s=t[0],o=GameLib.D3.Mesh.createInstanceMesh(e,i,s,n);return o.name=e.name,o.position.x=e.position.x,o.position.y=e.position.y,o.position.z=e.position.z,o.rotation.x=e.rotation.x,o.rotation.y=e.rotation.y,o.rotation.z=e.rotation.z,o.scale.x=e.scale.x,o.scale.y=e.scale.y,o.scale.z=e.scale.z,o.quaternion.x=e.quaternion.x,o.quaternion.y=e.quaternion.y,o.quaternion.z=e.quaternion.z,o.quaternion.w=e.quaternion.w,o}}(h,c)).catch(function(e){console.log(e)});a.push(T)}Q.all(a).then(function(t){if(console.log("all meshes have loaded"),"undefined"!=typeof i){for(var s=[],o=0;o<e.lights.length;o++){var a=e.lights[o],r=null;"AmbientLight"==a.lightType&&(r=new n.instance.AmbientLight(a.color,a.intensity)),"DirectionalLight"==a.lightType&&(r=new n.instance.DirectionalLight(a.color,a.intensity)),"PointLight"==a.lightType&&(r=new n.instance.PointLight(a.color,a.intensity),r.distance=a.distance,r.decay=a.decay),"SpotLight"==a.lightType&&(r=new n.instance.SpotLight(a.color,a.intensity),r.distance=a.distance,r.angle=a.angle,r.penumbra=a.penumbra,r.decay=a.decay),r.position.x=a.position.x,r.position.y=a.position.y,r.position.z=a.position.z,r.rotation.x=a.rotation.x,r.rotation.y=a.rotation.y,r.rotation.z=a.rotation.z,null==r?console.warn("Does not support lights of type :"+a.lightType+", not imported"):(r.name=a.name,s.push(r))}var h=new n.instance.Scene;h.name=e.name,h.position.x=e.position.x,h.position.y=e.position.y,h.position.z=e.position.z,h.rotation.x=e.rotation.x,h.rotation.y=e.rotation.y,h.rotation.z=e.rotation.z,h.scale.x=e.scale.x,h.scale.y=e.scale.y,h.scale.z=e.scale.z,h.quaternion.x=e.quaternion.x,h.quaternion.y=e.quaternion.y,h.quaternion.z=e.quaternion.z,h.quaternion.w=e.quaternion.w;for(var c=0;c<t.length;c++)h.add(t[c]);for(var l=0;l<s.length;l++)h.add(s[l]);i(e,{scene:h,lights:s,meshes:t})}}).catch(func