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

3 lines
70 KiB
JavaScript
Raw Normal View History

2016-11-01 10:30:55 +01: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,t){this.boneIndex=e,this.weight=t},GameLib.D3.Bone=function(e,t,i,n,s,o,a,r,h,c){this.id=e,this.name=i,this.boneId=t,"undefined"==typeof n&&(n=[]),this.childBoneIds=n,"undefined"==typeof s&&(s=null),this.parentBoneId=s,"undefined"==typeof o&&(o=new GameLib.D3.Vector4),this.quaternion=o,"undefined"==typeof a&&(a=new GameLib.D3.Vector3(0,0,0)),this.position=a,"undefined"==typeof r&&(r=new GameLib.D3.Vector3(0,0,0)),this.rotation=r,"undefined"==typeof h&&(h=new GameLib.D3.Vector3(1,1,1)),this.scale=h,"undefined"==typeof c&&(c=new GameLib.D3.Vector3(0,1,0)),this.up=c},GameLib.D3.Broadphase=function(e,t,i,n){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,this.engine=n,this.engine.isNotCannonThrow(),this.instance=this.createInstance()},GameLib.D3.Broadphase.prototype.createInstance=function(){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.SAPBroadphase}return 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.ComponentColorFlash=function(e){this.componentId=e||GameLib.D3.Tools.RandomId(),this.parentEntity=null,GameLib.D3.Utils.Extend(GameLib.D3.ComponentColorFlash,GameLib.D3.ComponentInterface)},GameLib.D3.ComponentColorFlash.prototype.onUpdate=function(e,t){this.parentEntity.mesh.material.color=new THREE.Color(Math.random(),Math.random(),Math.random())},GameLib.D3.ComponentColorFlash.prototype.onSetParentEntity=function(e,t){t.mesh.material=new THREE.MeshBasicMaterial},GameLib.D3.ComponentInterface=function(e){this.componentId=e||GameLib.D3.Tools.RandomId(),this.parentEntity=null},GameLib.D3.ComponentInterface.prototype.setParentEntity=function(e,t){this.parentEntity=t,this.onSetParentEntity(e,t)},GameLib.D3.ComponentInterface.prototype.update=function(e,t){this.onUpdate(e,t)},GameLib.D3.ComponentInterface.prototype.lateUpdate=function(e,t){this.onLateUpdate(e,t)},GameLib.D3.ComponentInterface.prototype.register=function(e){this.onRegistered(e)},GameLib.D3.ComponentInterface.prototype.onUpdate=function(e,t){},GameLib.D3.ComponentInterface.prototype.onLateUpdate=function(e,t){},GameLib.D3.ComponentInterface.prototype.onRegistered=function(e){},GameLib.D3.ComponentInterface.prototype.onSetParentEntity=function(e,t){},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.Entity=function(e,t){this.meshId=e,"undefined"==typeof t&&(t=[]),this.componentIds=t,this.parentScene=null,this.mesh=null},GameLib.D3.Entity.prototype.update=function(e){for(
this.suspensionMaxLength=h,"undefined"==typeof c&&(c=1),this.radius=c,"undefined"==typeof p&&(p=100),this.suspensionStiffness=p,"undefined"==typeof l&&(l=10),this.dampingCompression=l,"undefined"==typeof d&&(d=10),this.dampingRelaxation=d,"undefined"==typeof m&&(m=1e4),this.frictionSlip=m,"undefined"==typeof u&&(u=0),this.steering=u,"undefined"==typeof f&&(f=0),this.rotation=f,"undefined"==typeof y&&(y=0),this.deltaRotation=y,"undefined"==typeof L&&(L=.01),this.rollInfluence=L,"undefined"==typeof v&&(v=Number.MAX_VALUE),this.maxSuspensionForce=v,"undefined"==typeof b&&(b=!0),this.isFrontWheel=b,"undefined"==typeof g&&(g=1),this.clippedInvContactDotSuspension=g,"undefined"==typeof D&&(D=0),this.suspensionRelativeVelocity=D,"undefined"==typeof G&&(G=0),this.suspensionForce=G,"undefined"==typeof w&&(w=0),this.skidInfo=w,"undefined"==typeof T&&(T=0),this.suspensionLength=T,"undefined"==typeof E&&(E=1),this.maxSuspensionTravel=E,"undefined"==typeof x&&(x=!1),this.useCustomSlidingRotationalSpeed=x,"undefined"==typeof _&&(_=-.1),this.customSlidingRotationalSpeed=_,this.instance=this.createInstance()},GameLib.D3.RaycastWheel.prototype.createInstance=function(){return new this.engine.instance.WheelInfo({chassisConnectionPointLocal:this.chassisConnectionPointLocal,chassisConnectionPointWorld:this.chassisConnectionPointWorld,directionLocal:this.directionLocal,directionWorld:this.directionWorld,axleLocal:this.axleLocal,axleWorld:this.axleWorld,suspensionRestLength:this.suspensionRestLength,suspensionMaxLength:this.suspensionMaxLength,radius:this.radius,suspensionStiffness:this.suspensionStiffness,dampingCompression:this.dampingCompression,dampingRelaxation:this.dampingRelaxation,frictionSlip:this.frictionSlip,steering:this.steering,rotation:this.rotation,deltaRotation:this.deltaRotation,rollInfluence:this.rollInfluence,maxSuspensionForce:this.maxSuspensionForce,isFrontWheel:this.isFrontWheel,clippedInvContactDotSuspension:this.clippedInvContactDotSuspension,suspensionRelativeVelocity:this.suspensionRelativeVelocity,suspensionForce:this.suspensionForce,skidInfo:this.skidInfo,suspensionLength:this.suspensionLength,maxSuspensionTravel:this.maxSuspensionTravel,useCustomSlidingRotationalSpeed:this.useCustomSlidingRotationalSpeed,customSlidingRotationalSpeed:this.customSlidingRotationalSpeed})},GameLib.D3.RigidBodyVehicle=function(e,t,i){this.componentId=GameLib.D3.Tools.RandomId(),this.engine=e,this.engine.isNotCannonThrow(),this.chassisBody=t,"undefined"==typeof i&&(i=[]),this.wheels=i,this.instance=this.createInstance()},GameLib.D3.RigidBodyVehicle.prototype.getWheelInfo=function(){return this.instance.wheelBodies},GameLib.D3.RigidBodyVehicle.prototype.createInstance=function(){return new this.engine.instance.RigidVehicle({chassisBody:this.chassisBody.instance})},GameLib.D3.RigidBodyVehicle.prototype.addWheel=function(e){this.wheels.push(e),this.instance.addWheel({body:e.body.instance,position:new this.engine.instance.Vec3(e.position.x,e.position.y,e.position.z),axis:new this.engine.instance.Vec3(e.axis.x,e.axis.y,e.axis.z),direction:new this.engine.instance.Vec3(e.direction.x,e.direction.y,e.direction.z)})},GameLib.D3.RigidBody=function(e,t,i,n,s,o,a,r,h,c,p,l,d,m,u,f){this.componentId=GameLib.D3.Tools.RandomId(),this.position=n||new GameLib.D3.Vector3,this.velocity=o||new GameLib.D3.Vector3,this.angularVelocity=a||new GameLib.D3.Vector3,this.quaternion=s||new GameLib.D3.Vector4(0,0,0,1),this.mass="undefined"==typeof t?0:t,this.friction="undefined"==typeof i?5:i,this.linearDamping="undefined"==typeof r?.01:r,this.angularDamping="undefined"==typeof h?.01:h,this.allowSleep="undefined"==typeof c||c,this.sleepSpeedLimit="undefined"==typeof p?.1:p,this.sleepTimeLimit="undefined"==typeof l?1:l,this.collisionFilterGroup="undefined"==typeof d?1:d,this.collisionFilterMask="undefined"==typeof m?1:m,this.fixedRotation="undefined"!=typeof u&&u,this.shape="undefined"==typeof f?null:f,this.engine=e,this.engine.isNotCannonThrow(),this.instance=this.createInstance()},GameLib.D3.RigidBody.prototype.createInstance=function(){var e=new this.engine.inst
this.instance.step(e,i),this.lastCallTime=t},GameLib.D3.World.prototype.GetIndexedVertices=function(e){return this.engine.engineType==GameLib.D3.Physics.TYPE_CANNON?{vertices:e.vertices,indices:e.indices}:null},GameLib.D3.World.prototype.generateWireframeViewTriangleMesh=function(e,t,i,n,s,o){e.isNotThreeThrow(),this.engine.isNotCannonThrow(),"undefined"==typeof i&&(i=10),"undefined"==typeof n&&(n=new e.instance.Vector3(1,1,1)),"undefined"==typeof s&&(s=.5),"undefined"==typeof o&&(o=16711422);for(var a=new e.instance.Geometry,r=new e.instance.Mesh(a,new e.instance.MeshBasicMaterial({color:o,wireframe:!0,opacity:s})),h=0,c=t.instance.vertices.length/3;h<c;++h)a.vertices.push(new e.instance.Vector3(t.instance.vertices[3*h],t.instance.vertices[3*h+1],t.instance.vertices[3*h+2]));for(var p=0,c=t.instance.indices.length/3;p<c;++p){var l=t.instance.indices[3*p],d=t.instance.indices[3*p+1],m=t.instance.indices[3*p+2];a.faces.push(new e.instance.Face3(l,d,m));var u=(new e.instance.Vector3).add(a.vertices[l]).add(a.vertices[d]).add(a.vertices[m]).divideScalar(3),f=new this.engine.instance.Vec3;t.instance.getNormal(p,f);var y=new e.instance.ArrowHelper(new e.instance.Vector3(f.x,f.y,f.z),u,i,new e.instance.Color(f.x,f.y,f.z));r.add(y)}return r.scale.x=n.x,r.scale.y=n.y,r.scale.z=n.z,r},GameLib.D3.World.prototype.generateWireframeViewConvexPolyMesh=function(e,t,i,n,s,o){e.isNotThreeThrow(),this.engine.isNotCannonThrow(),"undefined"==typeof i&&(i=10),"undefined"==typeof n&&(n=new e.instance.Vector3(1,1,1)),"undefined"==typeof s&&(s=.5),"undefined"==typeof o&&(o=16711422);for(var a=new e.instance.Geometry,r=new e.instance.Mesh(a,new e.instance.MeshBasicMaterial({color:o,wireframe:!0,opacity:s})),h=0,c=t.instance.vertices.length;h<c;h++){var p=t.instance.vertices[h];a.vertices.push(new e.instance.Vector3(p.x,p.y,p.z))}for(var h=0,c=t.instance.faces.length;h<c;h++){var l=t.instance.faces[h],d=l[0],m=l[1],u=l[2];a.faces.push(new e.instance.Face3(d,m,u));var f=(new e.instance.Vector3).add(a.vertices[d]).add(a.vertices[m]).add(a.vertices[u]).divideScalar(3),y=t.instance.faceNormals[h],L=new e.instance.Vector3(y.x,y.y,y.z),v=new e.instance.ArrowHelper(L,f,i,new e.instance.Color(L.x,L.y,L.z));r.add(v)}return r.scale.x=n.x,r.scale.y=n.y,r.scale.z=n.z,r},GameLib.D3.World.prototype.generateTriangleMeshShapeDivided=function(e,t,i,n,s,o,a){e.isNotThreeThrow(),this.engine.isNotCannonThrow(),null!=i&&"undefined"!=typeof i||(i=0),null!=n&&"undefined"!=typeof n||(n=10),null!=s&&"undefined"!=typeof s||(s=!1);for(var r=0,h=o||0,c=a||0,p=t.geometry.faces.length,l=s?c*h:p,d=[],m=[],u=[],f=0;f<=p;f++){if(r==l||f==p){var y=null,L=new this.engine.instance.Trimesh(m,u);if(L.setScale(new this.engine.instance.Vec3(t.scale.x,t.scale.y,t.scale.z)),L.updateAABB(),L.updateNormals(),L.updateEdges(),L.updateBoundingSphereRadius(),L.updateTree(),y=new this.engine.instance.Body({mass:i,friction:n}),y.addShape(L),d.push({threeObject:s?null:t,physicsObject:y}),m=[],u=[],r=0,f==p)return d}var v=t.geometry.faces[f];u.push(u.length),u.push(u.length),u.push(u.length);var b=t.geometry.vertices[v.a],g=t.geometry.vertices[v.b],D=t.geometry.vertices[v.c];m.push(b.x,b.y,b.z),m.push(g.x,g.y,g.z),m.push(D.x,D.y,D.z),r++}},GameLib.D3.World.prototype.generateTriangleMeshShape=function(e,t){for(var i=[],n=0,s=t.geometry.vertices.length;n<s;n++){var o=t.geometry.vertices[n];i.push(new this.engine.instance.Vec3(o.x*t.scale.x,o.y*t.scale.y,o.z*t.scale.z))}for(var a=[],r=0,h=t.geometry.faces.length;r<h;r++){var c=t.geometry.faces[r].a,p=t.geometry.faces[r].b,l=t.geometry.faces[r].c;a.push([c,p,l])}for(var d={},m=[],u=[],f=0,y=a.length,L=0,r=0;r<y;r++){var c=a[r][0],p=a[r][1],l=a[r][2];"undefined"==typeof d[c]&&(m.push(i[c].x,i[c].y,i[c].z),d[c]=L,L++),"undefined"==typeof d[p]&&(m.push(i[p].x,i[p].y,i[p].z),d[p]=L,L++),"undefined"==typeof d[l]&&(m.push(i[l].x,i[l].y,i[l].z),d[l]=L,L++),u.push(d[c],d[p],d[l]),f++}var v=GameLib.D3.Shape(this.engine,GameLib.D3.Shape.SHAPE_TYPE_TRIMESH,t.scale,m,u),b=GameLib.D3.RigidBody(this.engine,0,12);b.addShape(v),this.addRigidBody(b);for(var g in t.ch