functionGameLib(){}var__DATE__="Mon Dec 11 2017 13:39:17 GMT+0100 (CET)";if(void0===GameLib.D3&&(GameLib.D3=function(){}),void0===GameLib.D3.API&&(GameLib.D3.API=function(){}),void0===GameLib.API&&(GameLib.API=function(){}),void0===GameLib.D3.Runtime&&(GameLib.D3.Runtime=function(){}),void0===Q){if("undefined"==typeofrequire)throwconsole.warn("You need the Q promise library for the GameLib.D3"),newError("You need the Q promise library for the GameLib.D3");varQ=require("q")}if(void0===_){if("undefined"==typeofrequire)throwconsole.warn("You need the lodash library for the GameLib.D3"),newError("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_FETCHED=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_RUNTIME=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.COMPONENT_TYPES_UPDATE=78,GameLib.Event.DELAYED_INSTANCE_ENCOUNTERED=79,GameLib.Event.CAST_SOURCE_CHANGED=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.COMPONENT_UPDATE=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_INSTANCE_UPDATED=97,GameLib
constructor:GameLib.D3.Fog,apiConstructor:GameLib.D3.API.Fog};case81:return{name:"GameLib.D3.Mesh.Line",runtime:GameLib.Component.GRAPHICS_RUNTIME,constructor:GameLib.D3.Mesh.Line,apiConstructor:GameLib.D3.API.Mesh};case82:return{name:"GameLib.D3.ParticleEngine",runtime:GameLib.Component.GRAPHICS_RUNTIME,constructor:GameLib.D3.ParticleEngine,apiConstructor:GameLib.D3.API.ParticleEngine};case83:return{name:"GameLib.System.Particle",runtime:GameLib.Component.DEFAULT_RUNTIME,constructor:GameLib.System.Particle,apiConstructor:GameLib.API.System};case84:return{name:"GameLib.D3.Particle",runtime:GameLib.Component.GRAPHICS_RUNTIME,constructor:GameLib.D3.Particle,apiConstructor:GameLib.D3.API.Particle};case85:return{name:"GameLib.D3.Audio",runtime:GameLib.Component.GRAPHICS_RUNTIME,constructor:GameLib.D3.Audio,apiConstructor:GameLib.D3.API.Audio};case86:return{name:"GameLib.System.Audio",runtime:GameLib.Component.DEFAULT_RUNTIME,constructor:GameLib.System.Audio,apiConstructor:GameLib.API.System};case87:return{name:"GameLib.Socket.Cast",runtime:GameLib.Component.SOCKET_RUNTIME,constructor:GameLib.Socket.Cast,apiConstructor:GameLib.API.Socket.Cast}}thrownewError("Unknown component type: "+e)},GameLib.Component.GetRuntimeName=function(e){returne===GameLib.Component.GRAPHICS_RUNTIME?"Graphics":e===GameLib.Component.PHYSICS_RUNTIME?"Physics":e===GameLib.Component.GUI_RUNTIME?"GUI":e===GameLib.Component.STATISTICS_RUNTIME?"Statistics":e===GameLib.Component.SOCKET_RUNTIME?"Sockets":e===GameLib.Component.CODER_RUNTIME?"Coder":"Default"},GameLib.Component.GetComponentName=function(e){vart=GameLib.Component.GetComponentInfo(e);returnt?t.name:"unused"},GameLib.Component.GetComponentRuntime=function(e){vart=GameLib.Component.GetComponentInfo(e);returnt?t.runtime:null},GameLib.Component.GetComponentConstructor=function(e){vart=GameLib.Component.GetComponentInfo(e);returnt?t.constructor:null},GameLib.Component.prototype.toApiObject=function(){returnthis.id},GameLib.Component.prototype.processComponent=function(e){if(einstanceofGameLib.Component){e.buildIdToObject(),e.linked||(this.linked=!1);vart=e.idToObject;for(variint)t.hasOwnProperty(i)&&(this.idToObject[i]=t[i]);e.id?this.idToObject[e.id]=e:console.warn("Object with no ID passed: "+e)}else"string"==typeofe?this.linked=!1:console.warn("Unhandled type of object: ",e)},GameLib.Component.prototype.buildIdToObject=function(){if(!this.building){this.building=!0,this.linked=!0,this.idToObject={};for(vareinthis.linkedObjects)this.linkedObjects.hasOwnProperty(e)&&this.hasOwnProperty(e)&&this[e]&&0!==e.indexOf("parent")&&(this.linkedObjects[e]instanceofArray?(this[e]=this[e].filter(function(e){returnnull!==e||(console.log("null object found and removed"),!1)}),this[e].map(function(e){this.processComponent(e)}.bind(this))):this.processComponent(this[e]));thisinstanceofGameLib.D3.Scene&&(this.storeClones||this.clones.map(function(e){this.idToObject.hasOwnProperty(e.id)&&deletethis.idToObject[e.id]}.bind(this))),this.idToObject[this.id]=this,this.building=!1}},GameLib.Component.prototype.generateNewIds=function(){this.buildIdToObject();vare=GameLib.EntityManager.Instance.queryComponents(GameLib.Component.CUSTOM_CODE);for(vartinthis.idToObject)if(this.idToObject.hasOwnProperty(t)){vari=this.idToObject[t].id,n=GameLib.Utils.RandomId();this.idToObject[t].id=n,this.idToObject[t].name=this.idToObject[t].name.replace(i,n),e.map(function(e){e.code=e.code.replace(i,n)})}},GameLib.Component.prototype.remove=function(){this.buildIdToObject(),this.getDependencies().map(function(e){vart=this.idToObject[e];tinstanceofGameLib.Component&&t.remove()}.bind(this)),GameLib.Event.Emit(GameLib.Event.REMOVE_COMPONENT,{component:this})},GameLib.Component.prototype.clone=function(){vare=this.toApiObject();this.cloneNumber+=1,e.id=GameLib.Utils.RandomId(),e.name=this.name+" Clone ("+this.cloneNumber+")";vart=GameLib.Component.ConstructFromObject(e);returnt.isClone=!0,GameLib.Event.Emit(GameLib.Event.COMPONENT_CLONED,{parent:this,component:t}),t.parentEntity=null,t},GameLib.Componen
GameLib.API.Vector3.clockwise=function(e,t,i,n){vara=GameLib.API.Vector3.normal(e,t,i),s=e.copy();returna.dot(s.subtract(n))>0},GameLib.API.Vector3.normal=function(e,t,i){varn=t.copy(),a=i.copy();returnn.subtract(e).cross(a.subtract(e))},GameLib.API.Vector3.prototype.lookAt=function(e,t){vari=GameLib.API.Matrix4.lookAt(this,e,t);returnthis.multiply(i)},GameLib.API.Vector3.prototype.translate=function(e){returnthis.x+=e.x,this.y+=e.y,this.z+=e.z,this},GameLib.API.Vector3.prototype.add=function(e){returnthis.x+=e.x,this.y+=e.y,this.z+=e.z,this},GameLib.API.Vector3.prototype.squared=function(){returnthis.x*this.x+this.y*this.y+this.z*this.z},GameLib.API.Vector3.prototype.copy=function(){returnnewGameLib.API.Vector3(this.x,this.y,this.z)},GameLib.API.Vector3.prototype.set=function(e,t,i){this.x=e,this.y=t,this.z=i},GameLib.API.Vector3.prototype.lerp=function(e,t){returnnewGameLib.API.Vector3(this.x+(e.x-this.x)*t,this.y+(e.y-this.y)*t,this.z+(e.z-this.z)*t)},GameLib.API.Vector3.prototype.distanceTo=function(e){vart=this.x-e.x,i=this.y-e.y,n=this.z-e.z;returnMath.sqrt(t*t+i*i+n*n)},GameLib.API.Vector3.AngleDirection=function(e,t,i){varn=e.cross(t),a=n.dot(i);returna>0?1:a<0?-1:0},GameLib.API.Vector3.prototype.multiply=function(e,t){vari,n,a,s=e,o=this;if(GameLib.Utils.UndefinedOrNull(t)&&(t=!1),"number"==typeofe)returnt?(this.x*=e,this.y*=e,this.z*=e,this):this.x*e+this.y*e+this.z*e;if(einstanceofGameLib.API.Vector3)returnt?(i=s.y*o.z-s.z*o.y,n=s.z*o.x-s.x*o.z,a=s.x*o.y-s.y*o.x,this.x=i,this.y=n,this.z=a,this):this.x*e.x+this.y*e.y+this.z*e.z;throwconsole.log("functionality not implemented - please do this"),newError("not implemented")},GameLib.API.Vector3.prototype.dot=function(e){returnthis.x*e.x+this.y*e.y+this.z*e.z},GameLib.API.Vector3.prototype.normalize=function(){vare=this.squared();if(e<1e-6)returnthis;vart=1/Math.sqrt(e);returnnewGameLib.API.Vector3(this.x*t,this.y*t,this.z*t)};GameLib.API.Vector3.prototype.clone=function(){returnnewGameLib.API.Vector3(this.x,this.y,this.z)},GameLib.API.Vector3.prototype.applyQuaternion=function(e){vart=this.x,i=this.y,n=this.z,a=e.x,s=e.y,o=e.z,r=e.w,c=r*t+s*n-o*i,m=r*i+o*t-a*n,h=r*n+a*i-s*t,l=-a*t-s*i-o*n;returnthis.x=c*r+l*-a+m*-o-h*-s,this.y=m*r+l*-s+h*-a-c*-o,this.z=h*r+l*-o+c*-s-m*-a,this},GameLib.API.Vector3.prototype.clamp=function(e,t){returnthis.x=Math.max(e.x,Math.min(t.x,this.x)),this.y=Math.max(e.y,Math.min(t.y,this.y)),this.z=Math.max(e.z,Math.min(t.z,this.z)),this},GameLib.API.Vector3.prototype.length=function(){returnMath.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)},GameLib.API.Vector3.prototype.reflect=function(e){returnthis.sub(v1.copy(e).multiply(2*this.dot(e)))},GameLib.API.Vector3.prototype.angleTo=function(e){vart=this.dot(e)/Math.sqrt(this.lengthSq()*e.lengthSq());returnMath.acos(exports.Math.clamp(t,-1,1))},GameLib.API.Vector3.FromObject=function(e){returnnewGameLib.API.Vector3(e.x,e.y,e.z)},GameLib.API.Vector4=function(e,t,i,n){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.API.Vector4.prototype.equals=function(e){returnthis.x===e.x&&this.y===e.y&&this.z===e.z&&this.w===e.w},GameLib.API.Vector4.FromObject=function(e){returnnewGameLib.API.Vector4(e.x,e.y,e.z,e.w)},GameLib.Canvas=function(e){if(GameLib.Utils.UndefinedOrNull(e)&&(e={}),einstanceofGameLib.Canvas)returne;GameLib.API.Canvas.call(this,e.id,e.name,e.width,e.height,e.parentEntity),GameLib.Component.call(this)},GameLib.Canvas.prototype=Object.create(GameLib.API.Canvas.prototype),GameLib.Canvas.prototype.constructor=GameLib.Canvas,GameLib.Canvas.prototype.createInstance=function(){this.instance=document.createElement("canvas"),this.instance.width=this.width,this.instance.height=this.height,GameLib.Component.prototype.createInstance.call(this)},GameLib.Canvas.prototype.updateInstance=function(e){GameLib.Utils.UndefinedOrNull(e)&&console.warn("unknown property update for Canvas: "+e),"width"===e&&
font:this.font.instance,size:this.size,height:this.height,curveSegments:this.curveSegments,bevelEnabled:this.bevelEnabled,bevelThickness:this.bevelThickness,bevelSize:this.bevelSize,bevelSegments:this.bevelSegments}),this.updateVerticesFromGeometryInstance(e)),GameLib.D3.Mesh.prototype.createInstance.call(this),this.instance.userData.font=this.font,this.instance.userData.size=this.size,this.instance.userData.height=this.height,this.instance.userData.curveSegments=this.curveSegments,this.instance.userData.bevelEnabled=this.bevelEnabled,this.instance.userData.bevelThickness=this.bevelThickness,this.instance.userData.bevelSize=this.bevelSize,this.instance.userData.bevelSegments=this.bevelSegments},GameLib.D3.Mesh.Text.prototype.updateInstance=function(e){if(this.instance.userData.text!==this.text||this.instance.userData.font!==this.font||this.instance.userData.size!==this.size||this.instance.userData.height!==this.height||this.instance.userData.curveSegments!==this.curveSegments||this.instance.userData.bevelEnabled!==this.bevelEnabled||this.instance.userData.bevelThickness!==this.bevelThickness||this.instance.userData.bevelSize!==this.bevelSize||this.instance.userData.bevelSegments!==this.bevelSegments){this.instance.userData.text=this.text,this.instance.userData.font=this.font,this.instance.userData.size=this.size,this.instance.userData.height=this.height,this.instance.userData.curveSegments=this.curveSegments,this.instance.userData.bevelEnabled=this.bevelEnabled,this.instance.userData.bevelThickness=this.bevelThickness,this.instance.userData.bevelSize=this.bevelSize,this.instance.userData.bevelSegments=this.bevelSegments;vart=newTHREE.TextGeometry(this.text,{font:this.font.instance,size:this.size,height:this.height,curveSegments:this.curveSegments,bevelEnabled:this.bevelEnabled,bevelThickness:this.bevelThickness,bevelSize:this.bevelSize,bevelSegments:this.bevelSegments});this.updateVerticesFromGeometryInstance(t),t=this.createInstanceGeometry(),this.instance.geometry=t}GameLib.D3.Mesh.prototype.updateInstance.call(this,e)},GameLib.D3.Mesh.Text.prototype.toApiObject=function(){vare=GameLib.D3.Mesh.prototype.toApiObject.call(this);returne.text=this.text,e.font=GameLib.Utils.IdOrNull(this.font),e.size=this.size,e.height=this.height,e.curveSegments=this.curveSegments,e.bevelEnabled=this.bevelEnabled,e.bevelThickness=this.bevelThickness,e.bevelSize=this.bevelSize,e.bevelSegments=this.bevelSegments,e},GameLib.D3.Mesh.Text.FromObject=function(e,t){vari=GameLib.D3.API.Mesh.FromObject(t);returnnewGameLib.D3.Mesh.Text(e,i,t.text,t.font,t.size,t.height,t.curveSegments,t.bevelEnabled,t.bevelThickness,t.bevelSize,t.bevelSegments)},GameLib.D3.ParticleEngine=function(e,t){if(this.graphics=e,this.graphics.isNotThreeThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),tinstanceofGameLib.D3.ParticleEngine)returnt;if(GameLib.D3.API.ParticleEngine.call(this,t.id,t.name,t.position,t.direction,t.enabled,t.templateParticle,t.particlesPerSecond,t.frequency,t.elapsed,t.camera,t.pulse,t.parentEntity),!(this.positioninstanceofGameLib.API.Vector3))throwconsole.warn("position not instance of API.Vector3"),newError("position not instance of API.Vector3");if(this.position=newGameLib.Vector3(e,this.position,this),!(this.directioninstanceofGameLib.API.Vector3))throwconsole.warn("direction not instance of API.Vector3"),newError("direction not instance of API.Vector3");this.direction=newGameLib.Vector3(e,this.direction,this),this.camerainstanceofGameLib.D3.API.Camera&&(this.camera=newGameLib.D3.Camera(e,this.camera)),this.templateParticleinstanceofGameLib.D3.API.Particle&&(this.templateParticle=newGameLib.D3.Particle(e,this.templateParticle)),this.particles=[],this.disabledForRemoval=!1,GameLib.Component.call(this,{templateParticle:GameLib.D3.Particle,camera:GameLib.D3.Camera})},GameLib.D3.ParticleEngine.prototype=Object.create(GameLib.D3.API.ParticleEngine.prototype),GameLib.D3.ParticleEngine.prototype.constructor=GameLib.D3.ParticleEngine,GameLib.D3.ParticleEngine.prototype.createInstance=function(){this.instance=!0,GameLib.Compone
;if(GameLib.Utils.UndefinedOrNull(this.texture.instance))thrownewError("no texture instance");this.instance=newTHREE.WebGLRenderTarget(this.width,this.height,{stencilBuffer:this.stencilBuffer}),this.instance.texture=this.texture.instance,GameLib.Component.prototype.createInstance.call(this)},GameLib.D3.RenderTarget.prototype.updateInstance=function(){if(this.instance)this.instance.setSize(this.width,this.height),this.instance.stencilBuffer=this.stencilBuffer,this.texture&&this.texture.instance?(this.instance.texture=this.texture.instance,this.instance.texture.needsUpdate=!0):this.instance.texture=null;elsetry{this.createInstance()}catch(e){console.error(e)}},GameLib.D3.RenderTarget.prototype.toApiObject=function(){returnnewGameLib.D3.API.RenderTarget(this.id,this.name,this.width,this.height,this.stencilBuffer,GameLib.Utils.IdOrNull(this.texture),GameLib.Utils.IdOrNull(this.parentEntity))},GameLib.D3.RenderTarget.FromObject=function(e,t){vari=GameLib.D3.API.RenderTarget.FromObject(t);returnnewGameLib.D3.RenderTarget(e,i)},GameLib.D3.Renderer=function(e,t){if(this.graphics=e,this.graphics.isNotThreeThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),tinstanceofGameLib.D3.Renderer)returnt;GameLib.D3.API.Renderer.call(this,t.id,t.name,t.autoClear,t.localClipping,t.width,t.height,t.preserveDrawingBuffer,t.domElement,t.clearColor,t.camera,t.scenes,t.viewports,t.clippingPlanes,t.bufferScene,t.bufferCamera,t.renderTarget,t.defaultScene,t.sortObjects,t.parentEntity),this.clearColor=newGameLib.Color(this.graphics,this.clearColor,this),this.domElementinstanceofGameLib.API.DomElement&&(this.domElement=newGameLib.DomElement(this.domElement)),this.camerainstanceofGameLib.D3.API.Camera&&(this.camera=newGameLib.D3.Camera(this.graphics,this.camera)),this.scenes=this.scenes.map(function(e){returneinstanceofGameLib.D3.API.Scene?newGameLib.D3.Scene(this.graphics,e):e}.bind(this)),this.viewports=this.viewports.map(function(e){returneinstanceofGameLib.D3.API.Viewport?newGameLib.D3.Viewport(this.graphics,e):e}.bind(this)),this.clippingPlanes=this.clippingPlanes.map(function(e){returneinstanceofGameLib.D3.API.Mesh?newGameLib.D3.Mesh.Plane(this.graphics,e,e.width,e.height,e.widthSegments,e.heightSegments,e.heightMapScale,e.isHeightMap,e.isClippingPlane,e.distanceFromOrigin):e}.bind(this)),this.bufferSceneinstanceofGameLib.D3.API.Scene&&(this.bufferScene=newGameLib.D3.Scene(this.graphics,this.bufferScene)),this.bufferCamerainstanceofGameLib.D3.API.Camera&&(this.bufferCamera=newGameLib.D3.Camera(this.graphics,this.bufferCamera)),this.renderTargetinstanceofGameLib.D3.API.RenderTarget&&(this.renderTarget=newGameLib.D3.RenderTarget(this.graphics,this.renderTarget)),GameLib.Component.call(this,{domElement:GameLib.DomElement,camera:GameLib.D3.Camera,scenes:[GameLib.D3.Scene],viewports:[GameLib.D3.Viewport],clippingPlanes:[GameLib.D3.Mesh.Plane],bufferScene:GameLib.D3.Scene,bufferCamera:GameLib.D3.Camera,renderTarget:GameLib.D3.RenderTarget,defaultScene:GameLib.D3.Scene})},GameLib.D3.Renderer.prototype=Object.create(GameLib.D3.API.Renderer.prototype),GameLib.D3.Renderer.prototype.constructor=GameLib.D3.Renderer,GameLib.D3.Renderer.prototype.createInstance=function(){if(GameLib.Utils.UndefinedOrNull(this.domElement))thrownewError("no dom element");if(GameLib.Utils.UndefinedOrNull(this.domElement.instance))thrownewError("no dom element instance");this.instance=newTHREE.WebGLRenderer({canvas:this.domElement.instance}),this.clippingPlanes.length>0&&(this.instance.clippingPlanes=this.clippingPlanes.map(function(e){if(!e.isClippingPlane||!e.instance||!e.instance.clipping)thrownewError("is not a clipping plane or no clipping plane instance");returne.instance.clipping})),this.instance.localClippingEnabled=this.localClipping,this.instance.setSize(this.width,this.height),this.instance.setClearColor(newTHREE.Color(this.clearColor.r,this.clearColor.g,this.clearColor.b),1-this.clearColor.a),this.instance.domElement.width=this.width,this.instance.domElement.height=this.height,this.instance.autoClear=this.autoClear,this.i
;GameLib.Utils.UndefinedOrNull(i)&&(i=1),this.radius=i,GameLib.D3.Shape.call(this,this.physics,t)},GameLib.D3.Shape.Sphere.prototype=Object.create(GameLib.D3.Shape.prototype),GameLib.D3.Shape.Sphere.prototype.constructor=GameLib.D3.Shape.Sphere,GameLib.D3.Shape.Sphere.prototype.createInstance=function(){this.instance=newCANNON.Sphere(this.radius),GameLib.D3.Shape.prototype.createInstance.call(this)},GameLib.D3.Shape.Sphere.prototype.updateInstance=function(){this.instance.radius=this.radius,this.instance.updateBoundingSphereRadius()},GameLib.D3.Shape.Sphere.prototype.toApiObject=function(){vare=GameLib.D3.Shape.prototype.toApiObject.call(this);returne.radius=this.radius,e},GameLib.D3.Shape.Sphere.FromObject=function(e,t){vari=GameLib.D3.API.Shape.FromObject(t);returnnewGameLib.D3.Shape.Sphere(e,i,t.radius)},GameLib.D3.Shape.TriMesh=function(e,t,i,n){if(this.physics=e,this.physics.isNotCannonThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={shapeType:GameLib.D3.API.Shape.SHAPE_TYPE_TRIMESH}),tinstanceofGameLib.D3.Shape.TriMesh)returnt;GameLib.Utils.UndefinedOrNull(i)&&(i=[]),this.vertices=i,GameLib.Utils.UndefinedOrNull(n)&&(n=[]),this.indices=n,GameLib.D3.Shape.call(this,this.physics,t)},GameLib.D3.Shape.TriMesh.prototype=Object.create(GameLib.D3.Shape.prototype),GameLib.D3.Shape.TriMesh.prototype.constructor=GameLib.D3.Shape.TriMesh,GameLib.D3.Shape.TriMesh.prototype.createInstance=function(){this.instance=newCANNON.TriMesh(this.vertices,this.indices),GameLib.D3.Shape.prototype.createInstance.call(this)},GameLib.D3.Shape.TriMesh.prototype.updateInstance=function(){this.instance.vertices=this.vertices,this.instance.indices=this.indices,this.instance.updateAABB(),this.instance.updateBoundingSphereRadius(),this.instance.updateEdges(),this.instance.updateNormals(),this.instance.updateTree()},GameLib.D3.Skeleton=function(e,t){if(this.graphics=e,this.graphics.isNotThreeThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),tinstanceofGameLib.D3.Skeleton)returnt;GameLib.D3.API.Skeleton.call(this,t.id,t.name,t.bones,t.boneInverses,t.useVertexTexture,t.boneTextureWidth,t.boneTextureHeight,t.boneMatrices,t.boneTexture,t.parentEntity),this.bones=this.bones.map(function(e){if(einstanceofGameLib.D3.API.Bone)returnnewGameLib.D3.Bone(this.graphics,e);throwconsole.warn("apiBone not an instance of API.Bone"),newError("apiBone not an instance of API.Bone")}.bind(this)),this.boneInverses=this.boneInverses.map(function(e){if(einstanceofGameLib.API.Matrix4)returnnewGameLib.Matrix4(this.graphics,e,this);throwconsole.warn("boneInverse not an instance of API.Matrix4"),newError("boneInverse not an instance of API.Matrix4")}.bind(this)),this.boneMatrices=this.boneMatrices.map(function(e){if(einstanceofGameLib.API.Matrix4)returnnewGameLib.Matrix4(this.graphics,e,this);throwconsole.warn("boneMatrices not an instance of API.Matrix4"),newError("boneMatrices not an instance of API.Matrix4")}.bind(this)),GameLib.Component.call(this,{bones:[GameLib.D3.Bone]})},GameLib.D3.Skeleton.prototype=Object.create(GameLib.D3.API.Skeleton.prototype),GameLib.D3.Skeleton.prototype.constructor=GameLib.D3.Skeleton,GameLib.D3.Skeleton.prototype.createInstance=function(e){vart=this.bones.map(function(e){if(GameLib.Utils.UndefinedOrNull(e))thrownewError("no bone");if(GameLib.Utils.UndefinedOrNull(e.instance))thrownewError("no bone instance");returne.instance}),i=this.bones.reduce(function(e,t){returne||(0===t.parentBoneIds.length?t.instance:null)},null);if(GameLib.Utils.UndefinedOrNull(i))thrownewError("could not find parent bone instance");this.instance=newTHREE.Skeleton(t),this.rootBoneInstance=i,this.instance.useVertexTexture=this.useVertexTexture,this.boneIdToBone={},this.bones.map(function(e){this.boneIdToBone[e.id]=e}.bind(this)),this.bones.map(function(e){returnfunction(t){t.childBoneIds.map(function(t){e.add(this.boneIdToBone[t].instance)}.bind(this))}}(i).bind(this)),this.instance.update(),this.instance.calculateInverses(),GameLib.Component.prototype.createInstance.call(this)},GameLib.D3.Skeleton.prototype.updateInstance=function
this.mouseControls=GameLib.EntityManager.Instance.queryComponents(GameLib.Component.CONTROLS_MOUSE),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.delayedInstanceEncounteredSubscription=GameLib.Event.Subscribe(GameLib.Event.DELAYED_INSTANCE_ENCOUNTERED,this.delayedInstanceEncountered.bind(this)),this.registerTouchControls(),this.registerKeyboardControls(),this.registerMouseControls(),this.registerEditorControls()},GameLib.System.Input.prototype.stop=function(){GameLib.System.prototype.stop.call(this),this.instanceCreatedSubscription.remove(),this.removeComponentSubscription.remove(),this.delayedInstanceEncounteredSubscription.remove(),this.deRegisterEditorControls(),this.deRegisterTouchControls(),this.deRegisterKeyboardControls(),this.deRegisterMouseControls(),this.editorControls=[],this.touchControls=[],this.keyboardControls=[],this.mouseControls=[]},GameLib.System.Input.prototype.instanceCreated=function(e){e.componentinstanceofGameLib.Controls.D3.Editor&&(this.editorControls.length>0?console.log("ignoring multiple editor controls"):(this.editorControls.push(e.component),this.registerEditorControls())),e.componentinstanceofGameLib.Controls.Touch&&(this.touchControls.length>0?console.log("ignoring multiple touch controls"):(this.touchControls.push(e.component),this.registerTouchControls())),e.componentinstanceofGameLib.Controls.Keyboard&&(this.keyboardControls.length>0?console.log("ignoring multiple keyboard controls"):(this.keyboardControls.push(e.component),this.registerKeyboardControls())),e.componentinstanceofGameLib.Controls.Mouse&&(this.mouseControls.length>0?console.log("ignoring multiple mouse controls"):(this.mouseControls.push(e.component),this.registerMouseControls()))},GameLib.System.Input.prototype.removeComponent=function(e){if(e.componentinstanceofGameLib.Controls.D3.Editor){vart=this.editorControls.indexOf(e.component);-1!==t?(console.log("removing editor controls from system"),this.deRegisterEditorControls(),this.editorControls.splice(t,1)):console.log("failed to find the editor controls in the system - probably it was ignored - "+e.component.name)}},GameLib.System.Input.prototype.delayedInstanceEncountered=function(e){e.componentinstanceofGameLib.Controls.D3.Editor&&(0===this.editorControls.length?(this.editorControls.push(e.component),this.registerEditorControls()):e.component.createInstance())},GameLib.System.Input.prototype.registerTouchControls=function(){if(1===this.touchControls.length){vare=this.touchControls[0];this.touchSensitivity=e.sensitivity,this.touchStart=this.onTouchStart.bind(this),this.touchMove=this.onTouchMove.bind(this),this.touchEnd=this.onTouchEnd.bind(this),this.touchCancel=this.onTouchCancel.bind(this),e.domElement.instance.addEventListener("touchstart",this.touchStart,!1),e.domElement.instance.addEventListener("touchmove",this.touchMove,!1),e.domElement.instance.addEventListener("touchend",this.touchEnd,!1),e.domElement.instance.addEventListener("touchcancel",this.touchCancel,!1)}},GameLib.System.Input.prototype.registerKeyboardControls=function(){if(1===this.keyboardControls.length){vare=this.keyboardControls[0];this.keyboardKeyUp=this.onKeyboardKeyUp.bind(this),this.keyboardKeyDown=this.onKeyboardKeyDown.bind(this),e.domElement.instance.addEventListener("keyup",this.keyboardKeyUp,!1),e.domElement.instance.addEventListener("keydown",this.keyboardKeyDown,!1)}},GameLib.System.Input.prototype.registerMouseControls=function(){if(1===this.mouseControls.length){vare=this.mouseControls[0];this.mouseDown=this.onMouseDown.bind(this),this.mouseMove=this.onMouseMove.bind(this),this.mouseWheel=this.onMouseWheel.bind(this),this.mouseUp=this.onMouseUp.bind(this),e.domElement.instance.addEventListener("mousedown",this.mouseDown,!1),e.domElement.instance.addEventListener("mousemove",this.mouseMove,!1),e.domElement.instance.addEventListener("wheel",this.mouseWheel,!1),e.domElemen
if(this.statistics&&this.statistics.map(function(e){e.start()}),GameLib.Event.Emit(GameLib.Event.BEFORE_RENDER,e),this.renderers.length<1);elseif(1===this.renderers.length)this.renderers[0].render(e.delta);else{vart=this.renderers.reduce(function(e,t){returnt.scenes.map(function(t){e.push(t)}),e},[]),i=GameLib.EntityManager.Instance.defaultRenderer;GameLib.Utils.UndefinedOrNull(i)&&(i=this.renderers[0]),i.render(e.delta,t)}GameLib.Event.Emit(GameLib.Event.AFTER_RENDER,e),this.statistics&&this.statistics.map(function(e){e.end()})},GameLib.System.Render.prototype.stop=function(){GameLib.System.prototype.stop.call(this),this.instanceCreatedSubscription.remove(),this.removeComponentSubscription.remove(),this.renderSubscription.remove(),this.renderers.map(function(e){e.statistics&&(e.statistics.resize(),e.domElement.instance.parentElement.removeChild(e.statistics.instance.dom))}),this.renderers=[]},GameLib.System.Socket=function(e){GameLib.System.call(this,e),this.totalTime=0,this.castComponents=[],this.receiveComponents=[],this.servers=[],this.instanceCreatedSubscription=null,this.removeComponentSubscription=null,this.beforeRenderSubscription=null},GameLib.System.Socket.prototype=Object.create(GameLib.System.prototype),GameLib.System.Socket.prototype.constructor=GameLib.System.Socket,GameLib.System.Socket.prototype.start=function(){GameLib.System.prototype.start.call(this),this.castComponents=GameLib.EntityManager.Instance.queryComponents(GameLib.Component.SOCKET_CAST),this.receiveComponents=GameLib.EntityManager.Instance.queryComponents(GameLib.Component.SOCKET_RECEIVE),this.servers=GameLib.EntityManager.Instance.queryComponents(GameLib.Component.SERVER),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.Socket.prototype.connect=function(e){console.log(e.name+" is connecting to the server "+e.serverIp)},GameLib.System.Socket.prototype.disconnect=function(e){console.log(e.name+" is disconnecting from server "+e.serverIp)},GameLib.System.Socket.prototype.instanceCreated=function(e){e.componentinstanceofGameLib.Socket.Cast&&GameLib.Utils.PushUnique(this.castComponents,e.component),e.componentinstanceofGameLib.Socket.Receive&&GameLib.Utils.PushUnique(this.receiveComponents,e.component),e.componentinstanceofGameLib.Server&&GameLib.Utils.PushUnique(this.servers,e.component)},GameLib.System.Socket.prototype.removeComponent=function(e){vart;e.componentinstanceofGameLib.Socket.Cast&&(t=this.castComponents.indexOf(e.component),-1!==t?this.castComponents.splice(t,1):console.log("Socket System out of Cast Component sync")),e.componentinstanceofGameLib.Socket.Receive&&(t=this.receiveComponents.indexOf(e.component),-1!==t?this.receiveComponents.splice(t,1):console.log("Socket System out of Receive Component sync")),e.componentinstanceofGameLib.Server&&(t=this.servers.indexOf(e.component),-1!==t?this.servers.splice(t,1):console.log("Socket System out of Server Component sync"))},GameLib.System.Socket.prototype.beforeRender=function(e){this.totalTime+=e.delta},GameLib.System.Socket.prototype.stop=function(){GameLib.System.prototype.stop.call(this),this.instanceCreatedSubscription.remove(),this.removeComponentSubscription.remove(),this.beforeRenderSubscription.remove(),this.servers=this.servers.reduce(function(e,t){t.disconnect()||e.push(t)}.bind(this),[]),0!==this.servers.length&&console.warn(this.servers.length+" connections still open after socket system stopped")},GameLib.System.Storage=function(e,t,i,n,a,s,o,r,c){GameLib.System.call(this,e),GameLib.Utils.UndefinedOrNull(t)&&(t=null),this.token=t,GameLib.Utils.UndefinedOrNull(i)&&(console.warn("Need an API Upload URL for a storage system"),i=""),this.apiUploadUrl=i,GameLib.Utils.UndefinedOrNull(n)&&(n=null),this.onImageLoaded=n,GameLib.Utils.UndefinedOrNull