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

13 lines
405 KiB
JavaScript
Raw Normal View History

2017-11-24 11:17:32 +01:00
function GameLib(){}var __DATE__="Thu Nov 23 2017 09:50:09 GMT+0100 (CET)";if(void 0===GameLib.D3&&(GameLib.D3=function(){}),void 0===GameLib.D3.API&&(GameLib.D3.API=function(){}),void 0===GameLib.API&&(GameLib.API=function(){}),void 0===GameLib.D3.Runtime&&(GameLib.D3.Runtime=function(){}),void 0===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")}if(void 0===_){if("undefined"==typeof require)throw console.warn("You need the lodash library for the GameLib.D3"),new Error("You need the lodash library for the GameLib.D3");var _=require("lodash")}console.log("Loading GameLib compiled at: "+__DATE__),GameLib.Event=function(){},GameLib.Event.Subscriptions={},GameLib.Event.OnceSubscriptions={},GameLib.Event.WINDOW_RESIZE=1,GameLib.Event.PARENT_SCENE_CHANGE=2,GameLib.Event.PARENT_ENTITY_CHANGE=3,GameLib.Event.INSTANCE_CLONED=4,GameLib.Event.LOAD_IMAGE=5,GameLib.Event.NEW_ENTITY=6,GameLib.Event.MATERIAL_TYPE_CHANGED=7,GameLib.Event.SAVE_COMPONENT=8,GameLib.Event.SAVE_COMPONENT_ERROR=9,GameLib.Event.COMPONENT_SAVED=10,GameLib.Event.LOAD_COMPONENT=11,GameLib.Event.LOAD_COMPONENT_ERROR=12,GameLib.Event.LOGGED_IN=13,GameLib.Event.COMPONENT_CREATED=14,GameLib.Event.COMPONENT_CLONED=15,GameLib.Event.TEXTURE_ANIMATED_CHANGE=16,GameLib.Event.ANIMATE_TEXTURE_INSTANCE=17,GameLib.Event.REMOVE_PARTICLE_ENGINE=18,GameLib.Event.GAME_PAUSE=19,GameLib.Event.TEXTURE_INSTANCE_UPDATED=20,GameLib.Event.PLAY_AUDIO=21,GameLib.Event.MATERIAL_INSTANCE_UPDATED=22,GameLib.Event.PAUSE_AUDIO=23,GameLib.Event.MESH_INSTANCE_UPDATED=24,GameLib.Event.STOP_AUDIO=25,GameLib.Event.LIGHT_INSTANCE_UPDATED=26,GameLib.Event.DELETE_COMPONENT=27,GameLib.Event.COMPONENT_DOWNLOAD_COMPLETE=28,GameLib.Event.COMPONENTS_LINKED=29,GameLib.Event.UNRESOLVED_DEPENDENCIES_UPDATE=30,GameLib.Event.REGISTER_UPDATE=31,GameLib.Event.BUILD_GUI=32,GameLib.Event.REMOVE_MESH=33,GameLib.Event.MESH_SELECTED=34,GameLib.Event.MESH_DESELECTED=35,GameLib.Event.COMPONENT_REGISTER=36,GameLib.Event.IMAGE_NOT_FOUND=37,GameLib.Event.BLENDER_DATA_RECEIVED=38,GameLib.Event.IMAGE_UPLOAD_COMPLETE=39,GameLib.Event.REMOVE_COMPONENT=40,GameLib.Event.KEY_DOWN=41,GameLib.Event.KEY_UP=42,GameLib.Event.RENDER=43,GameLib.Event.EVENT_LIST=44,GameLib.Event.COMPILE_SUCCESS=45,GameLib.Event.COMPILE_FAILED=46,GameLib.Event.IMAGE_CHANGED=47,GameLib.Event.PARENT_ENTITY_CHANGED=48,GameLib.Event.MATERIAL_TEXTURES_UPDATED=49,GameLib.Event.DELETE_COMPONENT_ERROR=50,GameLib.Event.COMPONENT_DELETED=51,GameLib.Event.COMPONENT_TYPES_UPDATED=52,GameLib.Event.AUDIO_ENDED=53,GameLib.Event.COMPONENT_LINKED=54,GameLib.Event.DONE_SAVING=55,GameLib.Event.BEFORE_RENDER=56,GameLib.Event.AFTER_RENDER=57,GameLib.Event.ARRAY_ITEM_ADDED=58,GameLib.Event.INSTANCE_CREATED=59,GameLib.Event.VISUALIZE=60,GameLib.Event.STOP_VISUALIZE=61,GameLib.Event.FETCH_COMPONENT_TYPES=62,GameLib.Event.FETCH_COMPONENTS=63,GameLib.Event.GET_API_URL=64,GameLib.Event.GET_PHYSICS_IMPLEMENTATION=65,GameLib.Event.PARENT_WORLD_CHANGE=66,GameLib.Event.ANIMATE=67,GameLib.Event.ANIMATION_COMPILE_SUCCESS=68,GameLib.Event.ANIMATION_COMPILE_FAILED=69,GameLib.Event.SAVING=70,GameLib.Event.GAME_OVER=71,GameLib.Event.GAME_START=72,GameLib.Event.TOUCH_START=73,GameLib.Event.TOUCH_END=74,GameLib.Event.TOUCH_MOVE=75,GameLib.Event.TOUCH_CANCEL=76,GameLib.Event.GET_REMOTE_API_URL=77,GameLib.Event.GET_GRAPHICS_IMPLEMENTATION=78,GameLib.Event.DELAYED_INSTANCE_ENCOUNTERED=79,GameLib.Event.GET_CODER_IMPLEMENTATION=80,GameLib.Event.ANIMATION_MESH_ADDED=81,GameLib.Event.ANIMATION_MESH_REMOVED=82,GameLib.Event.GET_SCENE=83,GameLib.Event.CUSTOM_CODE_WINDOW_RESIZE=84,GameLib.Event.LOAD_FONT=85,GameLib.Event.FONT_NOT_FOUND=86,GameLib.Event.STOP_ALL_AUDIO=87,GameLib.Event.REGISTER_DEPENDENCIES=88,GameLib.Event.GAME_LOADED=89,GameLib.Event.GAME_RESTART=90,GameLib.Event.LOAD_PROGRESS=91,GameLib.Event.ENTITY_LOADED=92,GameLib.Event.MOUSE_DOWN=93,GameLib.Event.MOUSE_MOVE=94,GameLib.Event.MOUSE_WHEEL=95,GameLib.Event.MOUSE_UP=96,GameLib.Event.PARTICLE_INSTAN
2017-11-22 16:10:58 +01:00
;if(e instanceof Array)return new GameLib.API.Matrix4(GameLib.API.Vector4.FromObject(e[0]),GameLib.API.Vector4.FromObject(e[1]),GameLib.API.Vector4.FromObject(e[2]),GameLib.API.Vector4.FromObject(e[3]));throw console.warn("Unsupported object matrix type - whats your DB version?"),new Error("Unsupported object matrix type - whats your DB version?")},GameLib.API.Matrix4.prototype.rotationMatrixX=function(e){return this.identity(),this.rows[1]=new GameLib.API.Vector4(0,Math.cos(e),-1*Math.sin(e),0),this.rows[2]=new GameLib.API.Vector4(0,Math.sin(e),Math.cos(e),0),this},GameLib.API.Matrix4.prototype.rotationMatrixY=function(e){return this.identity(),this.rows[0]=new GameLib.API.Vector4(Math.cos(e),0,Math.sin(e),0),this.rows[2]=new GameLib.API.Vector4(-1*Math.sin(e),0,Math.cos(e),0),this},GameLib.API.Matrix4.prototype.rotationMatrixZ=function(e){return this.identity(),this.rows[0]=new GameLib.API.Vector4(Math.cos(e),-1*Math.sin(e),0,0),this.rows[1]=new GameLib.API.Vector4(Math.sin(e),Math.cos(e),0,0),this},GameLib.API.Matrix4.prototype.rotateX=function(e,t){return this.identity(),this.rotationMatrixX(e),this.multiply(t)},GameLib.API.Matrix4.prototype.rotateY=function(e,t){return this.identity(),this.rotationMatrixY(e),this.multiply(t)},GameLib.API.Matrix4.prototype.rotateZ=function(e,t){return this.identity(),this.rotationMatrixZ(e),this.multiply(t)},GameLib.API.Matrix4.prototype.multiply=function(e){return e instanceof GameLib.API.Quaternion||e instanceof GameLib.API.Vector4?new GameLib.API.Quaternion(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.API.Vector3?new GameLib.API.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.API.Matrix4.prototype.identity=function(){this.rows=[new GameLib.API.Vector4(1,0,0,0),new GameLib.API.Vector4(0,1,0,0),new GameLib.API.Vector4(0,0,1,0),new GameLib.API.Vector4(0,0,0,1)]},GameLib.API.Mouse=function(e,t,i,n,s){GameLib.Utils.UndefinedOrNull(s)&&(s=null),this.parentEntity=s,GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="Mouse ("+this.id+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=0),this.x=i,GameLib.Utils.UndefinedOrNull(n)&&(n=0),this.y=n},GameLib.API.Mouse.prototype=Object.create(GameLib.Component.prototype),GameLib.API.Mouse.prototype.constructor=GameLib.API.Mouse,GameLib.API.Mouse.FromObject=function(e){return new GameLib.API.Mouse(e.id,e.name,e.x,e.y,e.parentEntity)},GameLib.API.Quaternion=function(e,t,i,n,s,a){GameLib.Utils.UndefinedOrNull(e)&&(e=0),this.x=e,GameLib.Utils.UndefinedOrNull(t)&&(t=0),this.y=t,GameLib.Utils.UndefinedOrNull(i)&&(i=0),this.z=i,GameLib.Utils.UndefinedOrNull(n)&&(n=1),this.w=n,GameLib.Utils.UndefinedOrNull(s)&&(s=new GameLib.API.Vector3),this.axis=s,GameLib.Utils.UndefinedOrNull(a)&&(a=0),this.angle=a},GameLib.API.Quaternion.prototype.translate=function(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this},GameLib.API.Quaternion.prototype.copy=function(){return new GameLib.API.Quaternion(this.x,this.y,this.z,this.w)},GameLib.API.Quaternion.prototype.normalize=function(){var e=this.x*this.x+this.y*this.y+this.z*this.z;if(e<1e-6)return this;var t=1/Math.sqrt(e);this.x*=t,this.y*=t,this.z*=t},GameLib.API.Quaternion.prototype.multiply=function(e){var t,i,n,s,a=e,o=this;if(e instanceof GameLib.API.Matrix4)return t=a.rows[0].x*o.x+a.rows[0].y*o.y+a.rows[0].z*o.z+a.rows[0].w*o.w,i=a.rows[1].x*o.x+a.rows[1].y*o.y+a.rows[1].z*o.z+a.rows[1].w*o.w,n=a.rows[2].x*o.x+a.rows[2].y*o.y+a.rows[2].z*o.z+a.rows[2].w*o.w,s=a.rows[3].x*o.x+a.rows[3].y*o.y+a.rows[3].z*o.z+a.rows[3].w*o.w,this.x=t,this.y=i,this.z=n,this.w=s,this;if(e instanceof GameLib.API.Quaternion)return t=a.x*o.x-a.y*o.y-a.z
2017-11-21 15:35:57 +01:00
GameLib.D3.API.Image.FromObject=function(e){return new GameLib.D3.API.Image(e.id,e.name,e.fileName,e.extension,e.path,e.contentType,e.size,e.parentEntity)},GameLib.D3.API.Light=function(e,t,i,n,s,a,o,r,h,c,m,l,p,u,b,d,L){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t=GameLib.D3.Light.LIGHT_TYPE_AMBIENT),this.lightType=t,GameLib.Utils.UndefinedOrNull(i)&&(this.lightType===GameLib.D3.Light.LIGHT_TYPE_AMBIENT&&(i="Ambient "),this.lightType===GameLib.D3.Light.LIGHT_TYPE_DIRECTIONAL&&(i="Directional "),this.lightType===GameLib.D3.Light.LIGHT_TYPE_POINT&&(i="Point "),this.lightType===GameLib.D3.Light.LIGHT_TYPE_SPOT&&(i="Spot "),i+="Light ("+e+")"),this.name=i,GameLib.Utils.UndefinedOrNull(n)&&(n=new GameLib.API.Color(1,1,1,1)),this.color=n,GameLib.Utils.UndefinedOrNull(s)&&(s=1),this.intensity=s,GameLib.Utils.UndefinedOrNull(a)&&(a=new GameLib.API.Vector3(10,10,10)),this.position=a,GameLib.Utils.UndefinedOrNull(o)&&(o=new GameLib.API.Vector3(0,0,0)),this.targetPosition=o,GameLib.Utils.UndefinedOrNull(r)&&(r=new GameLib.API.Quaternion),this.quaternion=r,GameLib.Utils.UndefinedOrNull(h)&&(h=new GameLib.API.Vector3(0,0,0)),this.rotation=h,GameLib.Utils.UndefinedOrNull(c)&&(c=new GameLib.API.Vector3(1,1,1)),this.scale=c,GameLib.Utils.UndefinedOrNull(m)&&(m=0),this.distance=m,GameLib.Utils.UndefinedOrNull(l)&&(l=1),this.decay=l,GameLib.Utils.UndefinedOrNull(p)&&(p=4*Math.PI),this.power=p,GameLib.Utils.UndefinedOrNull(u)&&(u=Math.PI/3),this.angle=u,GameLib.Utils.UndefinedOrNull(b)&&(b=0),this.penumbra=b,GameLib.Utils.UndefinedOrNull(d)&&(d=null),this.parentScene=d,GameLib.Utils.UndefinedOrNull(L)&&(L=null),this.parentEntity=L},GameLib.D3.API.Light.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.API.Light.prototype.constructor=GameLib.D3.API.Light,GameLib.D3.API.Light.FromObject=function(e){return new GameLib.D3.API.Light(e.id,e.lightType,e.name,GameLib.API.Color.FromObject(e.color),e.intensity,GameLib.API.Vector3.FromObject(e.position),GameLib.API.Vector3.FromObject(e.targetPosition),GameLib.API.Quaternion.FromObject(e.quaternion),GameLib.API.Vector3.FromObject(e.rotation),GameLib.API.Vector3.FromObject(e.scale),e.distance,e.decay,e.power,e.angle,e.penumbra,e.parentScene,e.parentEntity)},GameLib.D3.API.LookAt=function(e,t,i,n,s,a,o){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t=this.constructor.name),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=null),this.currentComponent=i,GameLib.Utils.UndefinedOrNull(n)&&(n=null),this.targetComponent=n,GameLib.Utils.UndefinedOrNull(s)&&(s=new GameLib.API.Vector3(0,0,0)),this.targetPositionOffset=s,GameLib.Utils.UndefinedOrNull(a)&&(a=22),this.rotationSpeed=a,this.lookAtMatrix=new GameLib.API.Matrix4,this.up=new GameLib.API.Vector3(0,1,0),this.currentRotation=new GameLib.API.Quaternion,this.targetPosition=new GameLib.API.Vector3,GameLib.Utils.UndefinedOrNull(o)&&(o=null),this.parentEntity=o},GameLib.D3.API.LookAt.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.API.LookAt.prototype.constructor=GameLib.D3.API.LookAt,GameLib.D3.API.LookAt.FromObject=function(e){return new GameLib.D3.API.LookAt(e.id,e.name,e.currentComponent,e.targetComponent,GameLib.API.Vector3.FromObject(e.targetPositionOffset),e.rotationSpeed,e.parentEntity)},GameLib.D3.API.Material=function(e,t,i,n,s,a,o,r,h,c,m,l,p,u,b,d,L,G,f,E,y,O,D,P,T,I,g,A,N,S,C,U,v,M,_,w,x,R,F,j,V,Y,H,z,q,B,k,W,Q,X,K,Z,J,$,ee,te,ie,ne,se,ae,oe,re,he,ce,me,le,pe,ue,be){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t=GameLib.D3.Material.MATERIAL_TYPE_STANDARD),this.materialType=t,GameLib.Utils.UndefinedOrNull(i)&&(i="Material ("+t+")"),this.name=i,GameLib.Utils.UndefinedOrNull(n)&&(n=1),this.opacity=n,GameLib.Utils.UndefinedOrNull(s)&&(s=GameLib.D3.Material.TYPE_FRONT_SIDE),this.side=s,GameLib.Utils.UndefinedOrNull(a)&&(a=!1),this.transparent=a,GameLib.Utils.UndefinedOrNull(o)&&(o=new GameLib.API.Color(.06,.06,.06,.06)),this.specular=o,
2017-11-24 11:17:32 +01:00
new GameLib.D3.API.Scene(e.id,e.name,t,i,n,s,a,e.fog,e.renderCamera,e.showGrid,e.showAxis,e.gridSize,GameLib.API.Color.FromObject(e.gridColor),e.parentEntity)},GameLib.D3.API.Shape=function(e,t,i,n,s,a,o){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="Shape ("+this.id+")",this instanceof GameLib.D3.Shape.ConvexHull&&(t="Shape Convex Hull ("+this.id+")"),this instanceof GameLib.D3.Shape.ConvexHull.Cylinder&&(t="Shape Convex Hull Cylinder ("+this.id+")"),this instanceof GameLib.D3.Shape.HeightMap&&(t="Shape Heightmap ("+this.id+")"),this instanceof GameLib.D3.Shape.Box&&(t="Shape Box ("+this.id+")"),this instanceof GameLib.D3.Shape.Plane&&(t="Shape Plane ("+this.id+")"),this instanceof GameLib.D3.Shape.Sphere&&(t="Shape Sphere ("+this.id+")"),this instanceof GameLib.D3.Shape.TriMesh&&(t="Shape TriMesh ("+this.id+")")),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=0),this.boundingSphereRadius=i,GameLib.Utils.UndefinedOrNull(n)&&(n=!0),this.collisionResponse=n,GameLib.Utils.UndefinedOrNull(s)&&(s=null),this.frictionMaterial=s,GameLib.Utils.UndefinedOrNull(a)&&(a=null),this.parentMesh=a,GameLib.Utils.UndefinedOrNull(o)&&(o=null),this.parentEntity=o},GameLib.D3.API.Shape.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.API.Shape.prototype.constructor=GameLib.D3.API.Shape,GameLib.D3.API.Shape.FromObject=function(e){return new GameLib.D3.API.Shape(e.id,e.name,e.boundingSphereRadius,e.collisionResponse,e.frictionMaterial,e.parentMesh,e.parentEntity)},GameLib.D3.API.Skeleton=function(e,t,i,n,s,a,o,r,h,c){GameLib.Utils.UndefinedOrNull(c)&&(c=null),this.parentEntity=c,GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="Skeleton"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=[]),this.bones=i,GameLib.Utils.UndefinedOrNull(n)&&(n=[]),this.boneInverses=n,GameLib.Utils.UndefinedOrNull(s)&&(s=!1),this.useVertexTexture=s,s&&console.warn("support for vertex texture bones is not supported yet - something could break somewhere"),GameLib.Utils.UndefinedOrNull(a)&&(a=0),this.boneTextureWidth=a,GameLib.Utils.UndefinedOrNull(o)&&(o=0),this.boneTextureHeight=o,GameLib.Utils.UndefinedOrNull(r)&&(r=[]),this.boneMatrices=r,GameLib.Utils.UndefinedOrNull(h)&&(h=null),this.boneTexture=h},GameLib.D3.API.Skeleton.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.API.Skeleton.prototype.constructor=GameLib.D3.API.Skeleton,GameLib.D3.API.Skeleton.FromObject=function(e){return new GameLib.D3.API.Skeleton(e.id,e.name,e.bones.map(function(e){return GameLib.D3.API.Bone.FromObject(e)}),e.boneInverses.map(function(e){return GameLib.D3.API.Matrix4.FromObject(e)}),e.useVertexTexture,e.boneTextureWidth,e.boneTextureHeight,e.boneMatrices.map(function(e){return GameLib.D3.API.Matrix4.FromObject(e)}),e.boneTexture,e.parentEntity)},GameLib.D3.API.Solver=function(e,t,i,n,s,a){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="Solver ("+this.id+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=GameLib.D3.Solver.GS_SOLVER),this.solverType=i,GameLib.Utils.UndefinedOrNull(n)&&(n=10),this.iterations=n,GameLib.Utils.UndefinedOrNull(s)&&(s=1e-7),this.tolerance=s,GameLib.Utils.UndefinedOrNull(a)&&(a=null),this.parentEntity=a},GameLib.D3.API.Solver.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.API.Solver.prototype.constructor=GameLib.D3.API.Solver,GameLib.D3.API.Solver.FromObject=function(e){return new GameLib.D3.API.Solver(e.id,e.name,e.solverType,e.iterations,e.tolerance,e.parentEntity)},GameLib.D3.API.Spline=function(e,t,i,n){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="Spline (unknown)"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=[]),this.vertices=i,GameLib.Utils.UndefinedOrNull(n)&&(n=null),this.parentEntity=n},GameLib.D3.API.Spline.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.API.Spline.prototype.constructor=GameLib.D3.API.Spline,GameLib.D3.API.Spl
return GameLib.D3.Controls.prototype.toApiObject.call(this)},GameLib.D3.Controls.Mouse.FromObject=function(e,t){var i=GameLib.D3.API.Controls.FromObject(t);return new GameLib.D3.Controls.Mouse(e,i)},GameLib.D3.Controls.Touch=function(e,t,i){this.graphics=e,this.graphics.isNotThreeThrow(),GameLib.Utils.UndefinedOrNull(i)&&(i=5),this.sensitivity=i,GameLib.D3.Controls.call(this,this.graphics,t)},GameLib.D3.Controls.Touch.prototype=Object.create(GameLib.D3.Controls.prototype),GameLib.D3.Controls.Touch.prototype.constructor=GameLib.D3.Controls.Touch,GameLib.D3.Controls.Touch.prototype.createInstance=function(){this.instance=!0,GameLib.D3.Controls.prototype.createInstance.call(this)},GameLib.D3.Controls.Touch.prototype.updateInstance=function(){GameLib.D3.Controls.prototype.updateInstance.call(this)},GameLib.D3.Controls.Touch.prototype.toApiObject=function(){var e=GameLib.D3.Controls.prototype.toApiObject.call(this);return e.sensitivity=this.sensitivity,e},GameLib.D3.Controls.Touch.FromObject=function(e,t){var i=GameLib.D3.API.Controls.FromObject(t);return new GameLib.D3.Controls.Touch(e,i,t.sensitivity)},GameLib.D3.CustomCode=function(e){if(GameLib.Utils.UndefinedOrNull(e)&&(e={}),e instanceof GameLib.D3.CustomCode)return e;GameLib.D3.API.CustomCode.call(this,e.id,e.name,e.eventId,e.code,e.parentEntity),this.editor=null,GameLib.Component.call(this,GameLib.Component.COMPONENT_CUSTOM_CODE)},GameLib.D3.CustomCode.prototype=Object.create(GameLib.D3.API.CustomCode.prototype),GameLib.D3.CustomCode.prototype.constructor=GameLib.D3.CustomCode,GameLib.D3.CustomCode.prototype.createInstance=function(){try{this.instance=new Function("data",this.code).bind(this)}catch(e){this.instance=new Function("data","console.log('compilation failed for : "+this.name+"');").bind(this)}GameLib.Component.prototype.createInstance.call(this)},GameLib.D3.CustomCode.prototype.updateInstance=function(){try{this.instance=new Function("data",this.code).bind(this),this.publish(GameLib.Event.COMPILE_SUCCESS,{component:this})}catch(e){this.instance=new Function("data","console.log('compilation update failed for : "+this.name+"');").bind(this),this.publish(GameLib.Event.COMPILE_FAILED,{component:this})}},GameLib.D3.CustomCode.prototype.toApiObject=function(){return new GameLib.D3.API.CustomCode(this.id,this.name,this.eventId,this.code,GameLib.Utils.IdOrNull(this.parentEntity))},GameLib.D3.CustomCode.FromObject=function(e){var t=GameLib.D3.API.CustomCode.FromObject(e);return new GameLib.D3.CustomCode(t)},GameLib.D3.CustomCode.prototype.launchEditor=function(){GameLib.Event.Emit(GameLib.Event.GET_CODER_IMPLEMENTATION,null,function(e){this.coder=e,this.coder.isNotCodeMirrorThrow()}.bind(this)),this.editor=this.coder.instance(document.body,{value:this.code,mode:"javascript",lineNumbers:!0,scrollbarStyle:"overlay",indentWithTabs:!0,indentUnit:4}),this.editor.on("change",function(){this.code=this.editor.getValue(),this.updateInstance()}.bind(this))},GameLib.D3.CustomCode.prototype.closeEditor=function(){var e=this.editor.getWrapperElement();e.parentElement.removeChild(e)},GameLib.D3.Face=function(e,t){if(this.implementation=e,e instanceof GameLib.D3.Graphics)this.implementation.isNotThreeThrow();else{if(!(e instanceof GameLib.D3.Physics))throw new Error("Unhandled implementation : "+e);this.implementation.isNotCannonThrow()}if(GameLib.Utils.UndefinedOrNull(t)&&(t={}),t instanceof GameLib.D3.Face)return t;GameLib.D3.API.Face.call(this,t.id,t.name,t.v0index,t.v1index,t.v2index,t.materialIndex,t.uvs,t.color,t.vertexColors,t.vertexNormals,t.normal),this.implementation instanceof GameLib.D3.Graphics&&(this.color=new GameLib.Color(this.implementation,this.color,this),this.vertexColors=this.vertexColors.map(function(e){return e instanceof GameLib.Color?e:e instanceof GameLib.API.Color?new GameLib.Color(this.implementation,e,this):void console.warn("unknown vertex color type",e)}.bind(this))),this.vertexNormals=this.vertexNormals.map(function(e){return e instanceof GameLib.Vector3?e:e instanceof GameLib.API.Vector3?new GameLib.Vector3(this.implementation,e,this):void console.
sizeAttenuation:this.pointSizeAttenuation})},GameLib.D3.Material.prototype.createLineBasicMaterialInstance=function(){var e="round";this.lineCap===GameLib.D3.Material.LINE_CAP_BUTT&&(e="butt"),this.lineCap===GameLib.D3.Material.LINE_CAP_SQUARE&&(e="square");var t="round";return this.lineJoin===GameLib.D3.Material.LINE_JOIN_BEVEL&&(t="bevel"),this.lineJoin===GameLib.D3.Material.LINE_JOIN_MITER&&(t="miter"),new THREE.LineBasicMaterial({name:this.name,opacity:this.opacity,transparent:this.transparent,depthTest:this.depthTest,depthFunc:this.depthFunc,depthWrite:this.depthWrite,visible:this.visible,side:this.side,color:this.color.instance,linewidth:this.lineWidth,linecap:e,linejoin:t})},GameLib.D3.Material.prototype.createPhongMaterialInstance=function(){return new THREE.MeshPhongMaterial({name:this.name,opacity:this.opacity,transparent:this.transparent,blending:this.blending,blendSrc:this.blendSrc,blendDst:this.blendDst,blendEquation:this.blendEquation,depthTest:this.depthTest,depthFunc:this.depthFunc,depthWrite:this.depthWrite,polygonOffset:this.polygonOffset,polygonOffsetFactor:this.polygonOffsetFactor,polygonOffsetUnits:this.polygonOffsetUnits,alphaTest:this.alphaTest,clippingPlanes:this.clippingPlanes,clipShadows:this.clipShadows,overdraw:this.overdraw,visible:this.visible,side:this.side,color:this.color.instance,specular:this.specular.instance,shininess:this.shininess,lightMapIntensity:this.lightMapIntensity,aoMapIntensity:this.aoMapIntensity,emissive:this.emissive.instance,emissiveIntensity:this.emissiveIntensity,bumpScale:this.bumpScale,normalScale:this.normalScale,displacementScale:this.displacementScale,combine:this.combine,refractionRatio:this.refractionRatio,fog:this.fog,flatShading:this.flatShading,wireframe:this.wireframe,wireframeLinewidth:this.wireframeLineWidth,wireframeLinecap:this.wireframeLineCap,wireframeLinejoin:this.wireframeLineJoin,vertexColors:GameLib.D3.Material.TYPE_VERTEX_COLORS,skinning:this.skinning,morphTargets:this.morphTargets,morphNormals:this.morphNormals})},GameLib.D3.Material.prototype.createMeshBasicMaterialInstance=function(){return new THREE.MeshBasicMaterial({name:this.name,opacity:this.opacity,transparent:this.transparent,blending:this.blending,blendSrc:this.blendSrc,blendDst:this.blendDst,blendEquation:this.blendEquation,depthTest:this.depthTest,depthFunc:this.depthFunc,depthWrite:this.depthWrite,polygonOffset:this.polygonOffset,polygonOffsetFactor:this.polygonOffsetFactor,polygonOffsetUnits:this.polygonOffsetUnits,alphaTest:this.alphaTest,clippingPlanes:this.clippingPlanes,clipShadows:this.clipShadows,overdraw:this.overdraw,visible:this.visible,side:this.side,color:this.color.instance,vertexColors:GameLib.D3.Material.TYPE_VERTEX_COLORS,fog:this.fog})},GameLib.D3.Material.prototype.checkTexture=function(e,t){var i=!1;return this[e]&&this[e].instance?this.instance[t]!==this[e].instance&&(this.instance[t]=this[e].instance,i=!0):null!==this.instance[t]&&(this.instance[t]=null,i=!0),i},GameLib.D3.Material.prototype.updateTextures=function(){var e=!1;return this.checkTexture("alphaMap","alphaMap")&&(e=!0),this.checkTexture("aoMap","aoMap")&&(e=!0),this.checkTexture("bumpMap","bumpMap")&&(e=!0),this.checkTexture("diffuseMap","map")&&(e=!0),this.checkTexture("displacementMap","displacementMap")&&(e=!0),this.checkTexture("emissiveMap","emissiveMap")&&(e=!0),this.checkTexture("environmentMap","envMap")&&(e=!0),this.checkTexture("lightMap","lightMap")&&(e=!0),this.checkTexture("metalnessMap","metalnessMap")&&(e=!0),this.checkTexture("normalMap","normalMap")&&(e=!0),this.checkTexture("roughnessMap","roughnessMap")&&(e=!0),this.checkTexture("specularMap","specularMap")&&(e=!0),e&&this.publish(GameLib.Event.MATERIAL_TEXTURES_UPDATED,{material:this}),e},GameLib.D3.Material.prototype.updateToonMaterialInstance=function(e){this.instance.name=this.name,this.instance.opacity=this.opacity,this.instance.transparent=this.transparent,this.instance.blending=this.blending,this.instance.blendSrc=this.blendSrc,this.instance.blendDst=this.blendDst,this.instance.blendEquation=this.blendEquation,this.instance.
this.position.instance.set(this.position.x,this.position.y,this.position.z),this.instance.position.copy(this.position.instance),this.helper&&(this.removeHelper(),this.createHelper())},GameLib.D3.Mesh.prototype.updateInstanceScale=function(){this.scale.instance.set(this.scale.x,this.scale.y,this.scale.z),this.instance.scale.copy(this.scale.instance),this.helper&&(this.removeHelper(),this.createHelper())},GameLib.D3.Mesh.prototype.getChildrenComponents=function(){var e=[];return this.materials.map(function(t){if(t instanceof GameLib.D3.Material){GameLib.Utils.PushUnique(e,t);for(var i in t.linkedObjects)if(t.linkedObjects.hasOwnProperty(i)&&t.hasOwnProperty(i)&&t[i]&&"string"!=typeof t[i]&&"parentEntity"!==i){GameLib.Utils.PushUnique(e,t[i]);for(var n in t[i].linkedObjects)t[i].linkedObjects.hasOwnProperty(n)&&t[i].hasOwnProperty(n)&&t[i][n]&&"string"!=typeof t[i][n]&&"parentEntity"!==n&&(t[i][n]instanceof Array?t[i][n].map(function(t){GameLib.Utils.PushUnique(e,t)}):GameLib.Utils.PushUnique(e,t[i][n]))}}}.bind(this)),GameLib.EntityManager.Instance.queryComponents(GameLib.D3.RigidBody).map(function(t){t.parentMesh===this&&GameLib.Utils.PushUnique(e,t)}.bind(this)),GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Shape).map(function(t){t.parentMesh===this&&GameLib.Utils.PushUnique(e,t)}.bind(this)),e},GameLib.D3.Mesh.prototype.createHelper=function(){if(GameLib.Utils.UndefinedOrNull(this.parentScene)||GameLib.Utils.UndefinedOrNull(this.parentScene.instance))return void console.warn("this mesh has no parent scene - cannot create helper");this.helper&&this.removeHelper(),this.helper=new GameLib.D3.Helper(this.graphics,null,this.name+" Helper",this,GameLib.D3.Helper.HELPER_TYPE_EDGES),this.helper.updateInstance(),this.polygonOffset=this.instance.material.polygonOffset,this.instance.material.polygonOffset=!0,this.parentScene.instance.add(this.helper.instance)},GameLib.D3.Mesh.prototype.addMaterial=function(e){1===this.materials.length?this.instance.material=e.instance:this.instance.material=this.materials.map(function(e){return e.instance})},GameLib.D3.Mesh.prototype.removeHelper=function(){if(GameLib.Utils.UndefinedOrNull(this.parentScene)||GameLib.Utils.UndefinedOrNull(this.parentScene.instance))return void console.warn("this mesh has no parent scene - cannot remove helper");this.helper&&this.helper.instance&&(this.parentScene.instance.remove(this.helper.instance),delete this.helper.instance),this.instance.material.polygonOffset=this.polygonOffset,this.helper=null},GameLib.D3.Mesh.prototype.computeBoundingBox=function(e){GameLib.Utils.UndefinedOrNull(e)&&(this.instance&&this.instance.geometry?e=this.instance.geometry:console.log("no instance geometry to compute bounding box")),e.computeBoundingBox(),this.dimensions.x=e.boundingBox.getSize().x,this.dimensions.y=e.boundingBox.getSize().y,this.dimensions.z=e.boundingBox.getSize().z},GameLib.D3.Mesh.Box=function(e,t,i,n,s){if(this.graphics=e,this.graphics.isNotThreeThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),t instanceof GameLib.D3.Mesh.Box)return t;t.meshType=GameLib.D3.Mesh.MESH_TYPE_BOX,GameLib.Utils.UndefinedOrNull(i)&&(i=1),this.width=i,GameLib.Utils.UndefinedOrNull(n)&&(n=1),this.height=n,GameLib.Utils.UndefinedOrNull(s)&&(s=1),this.depth=s,GameLib.D3.Mesh.call(this,this.graphics,t)},GameLib.D3.Mesh.Box.prototype=Object.create(GameLib.D3.Mesh.prototype),GameLib.D3.Mesh.Box.prototype.constructor=GameLib.D3.Mesh.Box,GameLib.D3.Mesh.Box.prototype.createInstance=function(){var e=null;0===this.vertices.length&&(e=new THREE.BoxGeometry(this.width,this.height,this.depth),this.updateVerticesFromGeometryInstance(e)),GameLib.D3.Mesh.prototype.createInstance.call(this),this.instance.userData.width=this.width,this.instance.userData.height=this.height,this.instance.userData.depth=this.depth},GameLib.D3.Mesh.Box.prototype.updateInstance=function(e){if(this.instance.userData.width!==this.width||this.instance.userData.height!==this.height||this.instance.userData.depth!==this.depth){this.instance.userData.width=this.width,this.instance.userData.height=this.height,this.instanc
e.scale.y-=Math.random()*this.scale.y,e.scale.z-=Math.random()*this.scale.z)),this.scaleType===GameLib.D3.Particle.SCALE_TYPE_RANDOM_X_EQUALS_Y){add=GameLib.Utils.GetRandomIntInclusive(1,2);var s=Math.random()*this.scale.x;1===add?(e.scale.x+=s,e.scale.y+=s,e.scale.z+=Math.random()*this.scale.z):(e.scale.x-=s,e.scale.y-=s,e.scale.z-=Math.random()*this.scale.z)}return e.userData.scale=this.scale.clone(),e.userData.lifeTime=this.lifeTime,e.userData.speedType=this.speedType,e.userData.speed=this.speed,e.userData.scene=this.mesh.parentScene.instance,e.userData.elapsed=0,e.userData.scene.add(e),e},GameLib.D3.Particle.prototype.toApiObject=function(){return new GameLib.D3.API.Particle(this.id,this.name,this.lifeTime,this.elapsed,GameLib.Utils.IdOrNull(this.mesh),this.opacityType,this.opacityFactor,this.positionOffsetType,this.positionOffset.toApiObject(),this.positionOffsetFn,this.directionType,this.direction.toApiObject(),this.directionFn,this.speedType,this.speed,this.scaleType,this.scale.toApiObject(),this.scaleFn,this.rotationType,this.rotation.toApiObject(),this.rotationFn,GameLib.Utils.IdOrNull(this.parentEngine),GameLib.Utils.IdOrNull(this.parentEntity))},GameLib.D3.Particle.FromObject=function(e,t){var i=GameLib.D3.API.Particle.FromObject(t);return new GameLib.D3.Particle(e,i)},GameLib.D3.Pass=function(e,t){if(this.graphics=e,this.graphics.isNotThreeThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),t instanceof GameLib.D3.Pass)return t;GameLib.D3.API.Pass.call(this,t.id,t.name,t.passType,t.camera,t.scene,t.renderToScreen,t.parentEntity),GameLib.Component.call(this,GameLib.Component.COMPONENT_PASS,{camera:GameLib.D3.Camera,scene:GameLib.D3.Scene})},GameLib.D3.Pass.prototype=Object.create(GameLib.D3.API.Pass.prototype),GameLib.D3.Pass.prototype.constructor=GameLib.D3.Pass,GameLib.D3.Pass.PASS_TYPE_RENDER=1,GameLib.D3.Pass.PASS_TYPE_COPY_SHADER=2,GameLib.D3.Pass.prototype.createInstance=function(){if(this.passType===GameLib.D3.Pass.PASS_TYPE_RENDER){if(GameLib.Utils.UndefinedOrNull(this.scene))throw new Error("no scene object");if(GameLib.Utils.UndefinedOrNull(this.camera))throw new Error("no camera object");if(GameLib.Utils.UndefinedOrNull(THREE.RenderPass))throw new Error("no render pass library");this.instance=new THREE.RenderPass(this.scene.instance,this.camera.instance)}else{if(this.passType!==GameLib.D3.Pass.PASS_TYPE_COPY_SHADER)throw console.warn("Render pass not supported yet: "+this.passType),new Error("Render pass not supported yet: "+this.passType);if(GameLib.Utils.UndefinedOrNull(THREE.CopyShader))throw new Error("no copyshader library");this.instance=THREE.CopyShader}this.instance.renderToScreen=this.renderToScreen,GameLib.Component.prototype.createInstance.call(this)},GameLib.D3.Pass.prototype.updateInstance=function(){this.passType!==GameLib.D3.Pass.PASS_TYPE_RENDER||this.instance instanceof THREE.RenderPass||this.createInstance(),this.passType!==GameLib.D3.Pass.PASS_TYPE_COPY_SHADER||this.instance instanceof THREE.CopyShader||this.createInstance(),this.instance.renderToScreen=this.renderToScreen},GameLib.D3.Pass.prototype.toApiObject=function(){return new GameLib.D3.API.Pass(this.id,this.name,this.passType,GameLib.Utils.IdOrNull(this.camera),GameLib.Utils.IdOrNull(this.scene),this.renderToScreen,GameLib.Utils.IdOrNull(this.parentEntity))},GameLib.D3.Pass.FromObject=function(e,t){var i=GameLib.D3.API.Pass.FromObject(t);return new GameLib.D3.Pass(e,i)},GameLib.D3.PathFollowing=function(e,t){if(this.graphics=e,this.graphics.isNotThreeThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),t instanceof GameLib.D3.PathFollowing)return t;GameLib.D3.API.PathFollowing.call(this,t.id,t.name,t.spline,t.mesh,t.raytraceMesh,t.accelleration,t.maxSpeed,t.baseOffset,t.maxOffset,t.steeringSpeed,t.targetOffset,t.currentOffset,t.currentPathValue,t.currentSpeed,t.direction,t.raycaster,t.currentPosition,t.futurePosition,t.up,t.rotationMatrix,t.rotationVector,t.parentEntity),this.baseOffset=new GameLib.Vector3(this.graphics,this.baseOffset,this),this.maxOffset=new GameLib.Vector3(this.graphics,this.maxOffset,this),this.targetOffset=
;GameLib.D3.API.RigidBody.call(this,t.id,t.name,t.mass,t.friction,t.position,t.quaternion,t.velocity,t.angularVelocity,t.linearDamping,t.angularDamping,t.allowSleep,t.sleepSpeedLimit,t.sleepTimeLimit,t.collisionFilterGroup,t.collisionFilterMask,t.fixedRotation,t.shapes,t.kinematic,t.parentMesh,t.parentWorld,t.parentEntity),this.position=new GameLib.Vector3(this.physics,this.position,this),this.quaternion=new GameLib.Quaternion(this.physics,this.quaternion,this),this.velocity=new GameLib.Vector3(this.physics,this.velocity,this),this.angularVelocity=new GameLib.Vector3(this.physics,this.angularVelocity,this),this.force=new GameLib.Vector3(this.physics),this.forcePoint=new GameLib.Vector3(this.physics),GameLib.Component.call(this,GameLib.Component.COMPONENT_RIGID_BODY,{shapes:[GameLib.D3.Shape],parentMesh:GameLib.D3.Mesh,parentWorld:GameLib.D3.PhysicsWorld})},GameLib.D3.RigidBody.prototype=Object.create(GameLib.D3.API.RigidBody.prototype),GameLib.D3.RigidBody.prototype.constructor=GameLib.D3.RigidBody,GameLib.D3.RigidBody.prototype.createInstance=function(){this.instance=new CANNON.Body({mass:this.mass,friction:this.friction,position:this.position.instance,quaternion:this.quaternion.instance,velocity:this.velocity.instance,angularVelocity:this.angularVelocity.instance,linearDamping:this.linearDamping,angularDamping:this.angularDamping,allowSleep:this.allowSleep,sleepSpeedLimit:this.sleepSpeedLimit,sleepTimeLimit:this.sleepTimeLimit,collisionFilterGroup:this.collisionFilterGroup,collisionFilterMask:this.collisionFilterMask,fixedRotation:this.fixedRotation,kinematic:this.kinematic}),this.instance.addEventListener("sleepy",function(){console.log(this.name+" is feeling sleepy...")}.bind(this)),this.instance.addEventListener("sleep",function(){console.log(this.name+" fell asleep!")}.bind(this)),this.instance.addEventListener("wakeup",function(){console.log(this.name+" woke up!")}.bind(this)),this.shapes.map(function(e){if(GameLib.Utils.UndefinedOrNull(e))throw new Error("no shape");if(GameLib.Utils.UndefinedOrNull(e.instance))throw new Error("no shape instance");this.instance.addShape(e.instance)}.bind(this)),GameLib.Component.prototype.createInstance.call(this)};GameLib.D3.RigidBody.prototype.updateInstance=function(){this.instance.mass=this.mass,this.instance.friction=this.friction,this.instance.position.x=this.position.x,this.instance.position.y=this.position.y,this.instance.position.z=this.position.z,this.quaternion.axis.instance.x=this.quaternion.axis.x,this.quaternion.axis.instance.y=this.quaternion.axis.y,this.quaternion.axis.instance.z=this.quaternion.axis.z,this.instance.quaternion.setFromAxisAngle(this.quaternion.axis.instance,this.quaternion.angle),this.quaternion.x=this.instance.quaternion.x,this.quaternion.y=this.instance.quaternion.y,this.quaternion.z=this.instance.quaternion.z,this.quaternion.w=this.instance.quaternion.w,this.parentMesh.position.setFrom(this.position),this.parentMesh.quaternion.setFrom(this.quaternion),this.parentMesh.updateInstance(),this.instance.velocity.x=this.velocity.x,this.instance.velocity.y=this.velocity.y,this.instance.velocity.z=this.velocity.z,this.instance.angularVelocity.x=this.angularVelocity.x,this.instance.angularVelocity.y=this.angularVelocity.y,this.instance.angularVelocity.z=this.angularVelocity.z,this.instance.linearDamping=this.linearDamping,this.instance.angularDamping=this.angularDamping,this.instance.allowSleep=this.allowSleep,this.instance.sleepSpeedLimit=this.sleepSpeedLimit,this.instance.sleepTimeLimit=this.sleepTimeLimit,this.instance.collisionFilterGroup=this.collisionFilterGroup,this.instance.collisionFilterMask=this.collisionFilterMask,this.instance.fixedRotation=this.fixedRotation,this.instance.kinematic=this.kinematic},GameLib.D3.RigidBody.prototype.setFromParentMesh=function(){this.parentMesh&&this.parentMesh.instance||console.log("no parent mesh or instance"),this.instance.position.x=this.parentMesh.position.x,this.instance.position.y=this.parentMesh.position.y,this.instance.position.z=this.parentMesh.position.z,this.instance.quaternion.x=this.parentMesh.quater
return e.toApiObject()}),GameLib.Utils.IdOrNull(this.parentEntity))},GameLib.D3.Spline.FromObject=function(e,t){var i=GameLib.D3.API.Spline.FromObject(t);return new GameLib.D3.Spline(e,i)},GameLib.D3.Spline.prototype.getPointAt=function(e){var t=this.instance.getPointAt(e);return new GameLib.Vector3(this.graphics,new GameLib.API.Vector3(t.x,t.y,t.z),this,.1)},GameLib.D3.Stats=function(e,t,i,n,s){if(GameLib.Utils.UndefinedOrNull(e))throw new Error("Need Stats object");if(this.stats=e,GameLib.Utils.UndefinedOrNull(t)&&(t=GameLib.Utils.RandomId()),this.id=t,GameLib.Utils.UndefinedOrNull(i)&&(i="Stats ("+t+")"),this.name=i,GameLib.Utils.UndefinedOrNull(n))throw console.warn("Need a DOM element for stats"),new Error("Need a DOM element for stats");this.domElement=n,GameLib.Utils.UndefinedOrNull(s)&&(s=null),this.parentEntity=s,GameLib.Component.call(this,GameLib.Component.COMPONENT_STATS,{domElement:GameLib.DomElement})},GameLib.D3.Stats.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.Stats.prototype.constructor=GameLib.D3.Stats,GameLib.D3.Stats.prototype.resize=function(){console.log("override stats resize per implementation")},GameLib.D3.Stats.prototype.createInstance=function(){this.instance=this.stats(),this.resize(),this.domElement.instance.parentElement.appendChild(this.instance.dom),GameLib.Component.prototype.createInstance.call(this)},GameLib.D3.Stats.prototype.updateInstance=function(){this.instance=new this.stats},GameLib.D3.Stats.prototype.start=function(){this.instance.begin()},GameLib.D3.Stats.prototype.end=function(){this.instance.end()},GameLib.D3.Texture=function(e,t){if(this.graphics=e,this.graphics.isNotThreeThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),t instanceof GameLib.D3.Texture)return t;GameLib.D3.API.Texture.call(this,t.id,t.typeId,t.name,t.image,t.images,t.wrapS,t.wrapT,t.repeat,t.data,t.format,t.mapping,t.magFilter,t.minFilter,t.textureType,t.anisotropy,t.offset,t.generateMipmaps,t.flipY,t.mipmaps,t.unpackAlignment,t.premultiplyAlpha,t.encoding,t.canvas,t.animated,t.reverseAnimation,t.forward,t.parentEntity),this.offset=new GameLib.Vector2(this.graphics,this.offset,this),this.repeat=new GameLib.Vector2(this.graphics,this.repeat,this),this.image instanceof GameLib.D3.API.Image&&(this.image=new GameLib.D3.Image(this.graphics,this.image)),this.images=this.images.map(function(e){return e instanceof GameLib.D3.API.Image?new GameLib.D3.Image(this.graphics,e):e}.bind(this)),this.canvas instanceof GameLib.D3.API.Canvas&&(this.canvas=new GameLib.D3.Canvas(this.graphics,this.canvas)),GameLib.Component.call(this,GameLib.Component.COMPONENT_TEXTURE,{image:GameLib.D3.Image,images:[GameLib.D3.Image],canvas:GameLib.D3.Canvas})},GameLib.D3.Texture.prototype=Object.create(GameLib.D3.API.Texture.prototype),GameLib.D3.Texture.prototype.constructor=GameLib.D3.Texture,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
if(e.texture.repeat.x>1||e.texture.repeat.x<0)return console.warn("cannot animate a texture with repeat.x greater than 1 or less than 0"),void(e.texture.animated=!1);if(e.texture.repeat.y>1||e.texture.repeat.y<0)return console.warn("cannot animate a texture with repeat.y greater than 1 or less than 0"),void(e.texture.animated=!1);this.textures[e.texture.id]=e.texture,this.textureIds=Object.keys(this.textures)}else GameLib.Utils.UndefinedOrNull(this.textures[e.texture.id])?console.warn("tried to remove an animated texture, which should have been in the list but isnt: "+e.texture.name):(delete this.textures[e.texture.id],this.textureIds=Object.keys(this.textures))},GameLib.System.Animation.prototype.animateTextureInstance=function(e){return e.texture.repeat.x>1||e.texture.repeat.x<0?(console.warn("cannot animate a texture with repeat.x greater than 1 or less than 0"),void(e.texture.userData.animated=!1)):e.texture.repeat.y>1||e.texture.repeat.y<0?(console.warn("cannot animate a texture with repeat.y greater than 1 or less than 0"),void(e.texture.userData.animated=!1)):(e.texture.userData.animated=!0,this.textures[e.texture.id]=e.texture,void(this.textureIds=Object.keys(this.textures)))},GameLib.System.Animation.prototype.beforeRender=function(e){if(!this.paused){var t=e.delta;for(var i in this.animations)if(this.animations.hasOwnProperty(i)){var n=[];if(this.animations[i].length>0)for(var s=!1,a=0;a<this.animations[i].length;a++)"rotation"!==this.animations[i][a].type||s||(s=!0,n.push(this.animations[i][a])),"position"===this.animations[i][a].type&&n.push(this.animations[i][a]),"scale"===this.animations[i][a].type&&n.push(this.animations[i][a]);n.map(function(e){return function(i){var n=!1,s=0;if("rotation"===i.type&&(s=i.animation.rotationSpeed*t),"position"===i.type&&(s=i.animation.translationSpeed*t),"scale"===i.type&&(s=i.animation.scaleSpeed*t),i.from<i.to?i.from+=s:i.from-=s,Math.abs(i.from-i.to)<s?(i.mesh.instance[i.type][i.axis]=i.to,n=!0):i.mesh.instance[i.type][i.axis]=i.from,n){var a=this.animations[e].indexOf(i);this.animations[e].splice(a,1)}}.bind(this)}.bind(this)(i))}this.textureIds.map(function(e){var t=this.textures[e];t.reverseAnimation||t.userData&&t.userData.reverseAnimation?((!0===t.forward||t.userData&&!0===t.userData.forward)&&(t.offset.x+=t.repeat.x,t.offset.x>=1-t.repeat.x&&(t.offset.y>=1-t.repeat.y?(t.offset.x=1-t.repeat.x,t.offset.y=1-t.repeat.y,t.userData?t.userData.forward=!1:t.forward=!1):(t.offset.x=0,t.offset.y+=t.repeat.y))),(!1===t.forward||t.userData&&!1===t.userData.forward)&&(t.offset.x-=t.repeat.x,t.offset.x<=0&&(t.offset.x=0,t.offset.y<t.repeat.y?(t.offset.x=t.repeat.x,t.offset.y=0,t.userData?t.userData.forward=!0:t.forward=!0):(t.offset.x=1-t.repeat.x,t.offset.y-=t.repeat.y)))):(t.offset.x+=t.repeat.x,t.offset.x>=1-t.repeat.x&&(t.offset.y>=1-t.repeat.y?(t.offset.x=0,t.offset.y=0):(t.offset.x=0,t.offset.y+=t.repeat.y))),t.userData||t.updateInstance("offset")}.bind(this))}},GameLib.System.Animation.prototype.detachAnimation=function(e){var t=!1;e.backupQuaternionAngleDescriptor&&(Object.defineProperty(e.quaternion,"angle",e.backupQuaternionAngleDescriptor),delete e.backupQuaternionAngleDescriptor,t=!0),e.backupQuaternionAxisXDescriptor&&(Object.defineProperty(e.quaternion.axis,"x",e.backupQuaternionAxisXDescriptor),delete e.backupQuaternionAxisXDescriptor,t=!0),e.backupQuaternionAxisYDescriptor&&(Object.defineProperty(e.quaternion.axis,"y",e.backupQuaternionAxisYDescriptor),delete e.backupQuaternionAxisYDescriptor,t=!0),e.backupQuaternionAxisZDescriptor&&(Object.defineProperty(e.quaternion.axis,"z",e.backupQuaternionAxisZDescriptor),delete e.backupQuaternionAxisXDescriptor,t=!0),e.backupRotationXDescriptor&&(Object.defineProperty(e.rotation,"x",e.backupRotationXDescriptor),delete e.backupRotationXDescriptor,t=!0),e.backupRotationYDescriptor&&(Object.defineProperty(e.rotation,"y",e.backupRotationYDescriptor),delete e.backupRotationYDescriptor,t=!0),e.backupRotationZDescriptor&&(Object.defineProperty(e.rotation,"z",e.backupRotationZDescriptor),delete e.backupRotationZDescriptor,t=!0),e
"spherical reflection":GameLib.D3.Texture.TYPE_SPHERICAL_REFLECTION_MAPPING,"cube uv reflection":GameLib.D3.Texture.TYPE_CUBE_UV_REFLECTION_MAPPING,"cube uv refraction":GameLib.D3.Texture.TYPE_CUBE_UV_REFRACTION_MAPPING}));else if("magFilter"===i)o.push(e.add(n,i,{nearest:GameLib.D3.Texture.TYPE_NEAREST_FILTER,"nearest mipmap nearest":GameLib.D3.Texture.TYPE_NEAREST_MIPMAP_NEAREST_FILTER,"nearest mipmap linear":GameLib.D3.Texture.TYPE_NEAREST_MIPMAP_LINEAR_FILTER,linear:GameLib.D3.Texture.TYPE_LINEAR_FILTER,"linear mipmap nearest":GameLib.D3.Texture.TYPE_LINEAR_MIPMAP_NEAREST_FILTER,"linear mipmap linear":GameLib.D3.Texture.TYPE_LINEAR_MIPMAP_LINEAR_FILTER}));else if("minFilter"===i)o.push(e.add(n,i,{nearest:GameLib.D3.Texture.TYPE_NEAREST_FILTER,"nearest mipmap nearest":GameLib.D3.Texture.TYPE_NEAREST_MIPMAP_NEAREST_FILTER,"nearest mipmap linear":GameLib.D3.Texture.TYPE_NEAREST_MIPMAP_LINEAR_FILTER,linear:GameLib.D3.Texture.TYPE_LINEAR_FILTER,"linear mipmap nearest":GameLib.D3.Texture.TYPE_LINEAR_MIPMAP_NEAREST_FILTER,"linear mipmap linear":GameLib.D3.Texture.TYPE_LINEAR_MIPMAP_LINEAR_FILTER}));else if(a===GameLib.Component.COMPONENT_TEXTURE&&"typeId"===i)o.push(e.add(n,i,{normal:GameLib.D3.Texture.TEXTURE_TYPE_NORMAL,cube:GameLib.D3.Texture.TEXTURE_TYPE_CUBE,canvas:GameLib.D3.Texture.TEXTURE_TYPE_CANVAS}));else if("textureType"===i)o.push(e.add(n,i,{"unsigned byte":GameLib.D3.Texture.TYPE_UNSIGNED_BYTE,byte:GameLib.D3.Texture.TYPE_BYTE,short:GameLib.D3.Texture.TYPE_SHORT,"unsigned short":GameLib.D3.Texture.TYPE_UNSIGNED_SHORT,int:GameLib.D3.Texture.TYPE_INT,"unsigned int":GameLib.D3.Texture.TYPE_UNSIGNED_INT,float:GameLib.D3.Texture.TYPE_FLOAT,"half float":GameLib.D3.Texture.TYPE_HALF_FLOAT}));else if("encoding"===i)o.push(e.add(n,i,{linear:GameLib.D3.Texture.TYPE_LINEAR_ENCODING,srgb:GameLib.D3.Texture.TYPE_SRGB_ENCODING,gamma:GameLib.D3.Texture.TYPE_GAMMA_ENCODING,rgbe:GameLib.D3.Texture.TYPE_RGBE_ENCODING,"log luv":GameLib.D3.Texture.TYPE_LOG_LUV_ENCODING,rgbm7:GameLib.D3.Texture.TYPE_RGBM7_ENCODING,rgbm16:GameLib.D3.Texture.TYPE_RGBM16_ENCODING,rgbd:GameLib.D3.Texture.TYPE_RGBD_ENCODING}));else if("lightType"===i)o.push(e.add(n,i,{ambient:GameLib.D3.Light.LIGHT_TYPE_AMBIENT,directional:GameLib.D3.Light.LIGHT_TYPE_DIRECTIONAL,spot:GameLib.D3.Light.LIGHT_TYPE_SPOT,point:GameLib.D3.Light.LIGHT_TYPE_POINT}));else if("eventId"===i){for(var r={},h=0;h<200;h++)try{r[GameLib.Event.GetEventName(h)]=h}catch(e){}o.push(e.add(n,i,r))}else"functionType"===i?o.push(e.add(n,i,{rotation:GameLib.D3.Animation.ANIMATION_FUNCTION_TYPE_ROTATION,translation:GameLib.D3.Animation.ANIMATION_FUNCTION_TYPE_TRANSLATION,scale:GameLib.D3.Animation.ANIMATION_FUNCTION_TYPE_SCALE})):"opacity"===i||"opacityFactor"===i||"metalness"===i||"roughness"===i||"volume"===i?o.push(e.add(n,i,0,1,.001)):"shininess"===i||"fov"===i?o.push(e.add(n,i,-255,255,1)):"aspect"===i||"wireframeLineWidth"===i||"lineWidth"===i?o.push(e.add(n,i,0,5,.001)):"bumpScale"===i||"normalScale"===i||"displacementScale"===i||"heightMapScale"===i||"intensity"===i?o.push(e.add(n,i,-10,10,.001)):"minX"===i||"minY"===i||"minZ"===i||"maxX"===i||"maxY"===i||"maxZ"===i||"offsetX"===i?o.push(e.add(n,i,-1e3,1e3,.01)):"widthSegments"===i||"radiusSegments"===i||"heightSegments"===i||"particlesPerSecond"===i?o.push(e.add(n,i,1,1e3,1)):"width"===i||"height"===i||"depth"===i||"radius"===i?o.push(e.add(n,i,0,1e3,.1)):"near"===i||"distanceGrain"===i||"envMapIntensity"===i?o.push(e.add(n,i,-10,100,.001)):"bumpScale"===i?o.push(e.add(n,i,0,20,.001)):"heightOffset"===i||"rotationFactor"===i?o.push(e.add(n,i,-100,100,.001)):"friction"===i?o.push(e.add(n,i,0,1e3,.01)):"radiusTop"===i||"radiusBottom"===i?o.push(e.add(n,i,0,100,.1)):"mass"===i?o.push(e.add(n,i,0,1e3,.1)):"sensitivity"===i?o.push(e.add(n,i,1,50,1)):"density"===i?o.push(e.add(n,i,0,1,1e-4)):"thetaLength"===i||"angle"===i?o.push(e.add(n,i,2*-Math.PI,2*Math.PI,.01)):o.push(e.add(n,i,-1e3,1e3,.1))}o.map(function(n){"name"===i?n.onFinishChange(function(e,n){return function(e){t.affected.map(function(t){t[i]=e,t.updateInstance(i)}),n.domElement
},!1)&&(1===t.materials.length?t.instance.material=t.materials[0].instance:t.instance.material=t.materials.map(function(e){return e.instance}),t.instance.geometry.uvsNeedUpdate=!0,t.instance.material.needsUpdate=!0)})},GameLib.System.Linking.prototype.onParentWorldChange=function(e){e.object instanceof GameLib.D3.RigidBody&&(e.originalWorld instanceof GameLib.D3.PhysicsWorld&&e.originalWorld.removeRigidBody(e.object),e.newWorld instanceof GameLib.D3.PhysicsWorld&&e.newWorld.addRigidBody(e.object))},GameLib.System.Linking.prototype.onParentSceneChange=function(e){if(e.object instanceof GameLib.D3.Mesh||e.object instanceof GameLib.D3.Light){var t=GameLib.EntityManager.Instance.findHelperByObject(e.object);t&&(e.originalScene&&e.originalScene.instance&&e.originalScene.instance.remove(t.instance),e.newScene.instance.add(t.instance)),e.originalScene&&e.originalScene.removeObject&&e.originalScene.removeObject(e.object),e.newScene&&e.newScene.addObject(e.object)}},GameLib.System.Linking.prototype.onParentEntityChange=function(e){e.originalEntity instanceof GameLib.Entity&&e.originalEntity.removeComponent(e.object),e.newEntity instanceof GameLib.Entity&&e.newEntity.addComponent(e.object),GameLib.Event.Emit(GameLib.Event.PARENT_ENTITY_CHANGED,{originalEntity:e.originalEntity,newEntity:e.newEntity,component:e.object})},GameLib.System.Linking.prototype.removeMesh=function(e){var t=e.meshes.reduce(function(e,t){return e.push(t),t.getChildrenComponents().map(function(t){e.push(t)}),e},[]),i=GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Mesh);i=i.filter(function(t){return-1===e.meshes.indexOf(t)});var n=i.reduce(function(e,t){return e.push(t),t.getChildrenComponents().map(function(t){e.push(t)}),e},[]);t=t.filter(function(e){return-1===n.indexOf(e)}),t.map(function(e){e.remove()})},GameLib.System.Linking.prototype.stop=function(){GameLib.System.prototype.stop.call(this),this.componentCreatedSubscription.remove(),this.componentClonedSubscription.remove(),this.registerDependenciesSubscription.remove(),this.componentRemoveSubscription.remove(),this.parentSceneChangeSubscription.remove(),this.parentWorldChangeSubscription.remove(),this.parentEntityChangeSubscription.remove(),this.instanceCreatedSubscription.remove(),this.instanceClonedSubscription.remove(),this.removeMeshSubscription.remove(),this.imageChangedSubscription.remove(),this.materialTypeChangedSubscription.remove(),this.arrayItemAddedSubscription.remove()},GameLib.System.Particle=function(e,t,i){this.graphics=e,this.graphics.isNotThreeThrow(),GameLib.System.call(this,i),this.engines=[],this.camera=t,this.totalTime=0,this.instanceCreatedSubscription=null,this.removeComponentSubscription=null,this.beforeRenderSubscription=null},GameLib.System.Particle.prototype=Object.create(GameLib.System.prototype),GameLib.System.Particle.prototype.constructor=GameLib.System.Particle,GameLib.System.Particle.prototype.start=function(){GameLib.System.prototype.start.call(this),this.particleEngines=GameLib.EntityManager.Instance.queryComponents(GameLib.D3.ParticleEngine),this.instanceCreatedSubscription=GameLib.Event.Subscribe(GameLib.Event.INSTANCE_CREATED,this.instanceCreated.bind(this)),this.removeComponentSubscription=GameLib.Event.Subscribe(GameLib.Event.REMOVE_COMPONENT,this.removeComponent.bind(this)),this.beforeRenderSubscription=GameLib.Event.Subscribe(GameLib.Event.BEFORE_RENDER,this.beforeRender.bind(this))},GameLib.System.Particle.prototype.instanceCreated=function(e){e.component instanceof GameLib.D3.ParticleEngine&&this.particleEngines.push(e.component),e.component instanceof GameLib.D3.Camera&&(this.camera=e.component)},GameLib.System.Particle.prototype.removeComponent=function(e){if(e.component instanceof GameLib.D3.ParticleEngine){var t=this.particleEngines.indexOf(e.component);-1!==t&&this.particleEngines.splice(t,1)}},GameLib.System.Particle.prototype.beforeRender=function(e){this.totalTime+=e.delta,this.particleEngines.map(function(t){if(!(GameLib.Utils.UndefinedOrNull(t.camera)||GameLib.Utils.UndefinedOrNull(t.templateParticle)||GameLib.Utils.UndefinedOrNull(t.tem