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

2 lines
56 KiB
JavaScript
Raw Normal View History

2016-10-18 13:37:38 +02:00
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
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.shapeObje