functionGameLib(){}var__DATE__="Sun Dec 10 2017 13:45:44 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.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.Cast",runtime:GameLib.Component.SOCKET_RUNTIME,constructor:GameLib.Cast,apiConstructor:GameLib.API.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.Component.prototype.cloneInstance=function(){vare=null;returnthis.instance&&this.instance.clone&&(this.instance.clone,!0)&&(e=this.instance.clone(),GameLib.Event.Emit(GameLib.Event.INSTANCE_CLONED,{component:this,instance:e})),e},GameLib.Component.prototype.saveToRemoteAPI=function(){this.save(!0)},GameLib.Component.prototype.save=fu
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&&(this.instance.width=this.width),"height"===e&&(this.instance.height=this.height)},GameLib.Canvas.prototype.toApiObject=function(){returnnewGameLib.API.Canvas(this.id,this.name,this.width,this.height,GameLib.Utils.IdOrNull(this.parentEntity))},GameLib.Canvas.FromObject=function(e){returnnewGameLib.Canvas(GameLib.API.Canvas.FromObject(e))},GameLib.Cast=function(e,t){if(this.socket=e,this.socket.isNotWebSocketThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),tinstanceofGameLib.Cast)returnt;GameLib.API.Cast.call(this,t.id,t.name,t.castType,t.source,t.sourceProperties,t.roomId,t.peerId,t.serverIp,t.port,t.parentEntity),this.connected=!1,GameLib.Component.call(this,{source:GameLib.Component})},GameLib.Cast.prototype=Object.create(GameLib.API.Cast.prototype),GameLib.Cast.prototype.constructor=GameLib.Cast,GameLib.Cast.prototype.createInstance=function(){this.instance=!0,GameLib.Component.prototype.createInstance.call(this)},GameLib.Cast.prototype.updateInstance=function(e){"source"===e&&(null!==this.source?this.sourceProperties=GameLib.Utils.ObjectPropertiesAsBoolean(this.source):this.sourceProperties={},GameLib.Event.Emit(GameLib.Event.CAST_SOURCE_CHANGED,{component:this})),"sourceProperties"===e&&console.log(this.sourceProperties)},GameLib.Cast.prototype.toApiObject=function(){returnnewGameLib.API.Cast(this.id,this.name,this.castType,GameLib.Utils.IdOrNull(this.source),this.sourceProperties,this.roomId,this.peerId,this.serverIp,this.port,GameLib.Utils.IdOrNull(this.parentEntity))},GameLib.Cast.FromObject=function(e,t){vari=GameLib.API.Cast.FromObject(t);returnnewGameLib.Cast(e,i)},GameLib.Clock=function(e,t){if(this.grap
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.Component.prototype.createInstance.call(this)},GameLib.D3.ParticleEngine.prototype.updateInstance=function(e){"particlesPerSecond"===e&&(this.frequency=Number(1/this.particlesPerSecond)),"frequency"===e&&(this.particlesPerSecond=Math.round(1/this.frequency)),"position
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.instance.preserveDrawingBuffer=this.preserveDrawingBuffer,this.instance.sortObjects=this.sortObjects,GameLib.Component.prototype.createInstance.call(this)},GameLib.D3.Renderer.prototype.updateInstance=function(e){if(this.instance)e||console.e
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(){},GameLib.D3.Skeleton.prototype.toApiObject=function(){returnnewGameLib.D3.API.Skeleton(this.id,this.name,this.bones.map(function(e){returne.toApiObject()}),this.boneInverses.map(function(e){returne.toApiObject()}),this.useVertexTexture,t
this.guis.map(function(e){e.domElement.instance.parentElement.appendChild(e.instance.domElement)}),this.buildGUISubscription=this.subscribe(GameLib.Event.BUILD_GUI,this.buildGUI),this.meshDeletedSubscription=this.subscribe(GameLib.Event.REMOVE_MESH,this.meshDeleted),this.meshSelectedSubscription=this.subscribe(GameLib.Event.MESH_SELECTED,this.meshSelected),this.meshDeselectedSubscription=this.subscribe(GameLib.Event.MESH_DESELECTED,this.meshDeslected),this.newEntitySubscription=this.subscribe(GameLib.Event.NEW_ENTITY,this.newEntity),this.componentRemovedSubscription=this.subscribe(GameLib.Event.REMOVE_COMPONENT,this.removeComponent),this.sourceChangedSubscription=this.subscribe(GameLib.Event.CAST_SOURCE_CHANGED,this.castSourceChanged),this.destinationChangedSubscription=this.subscribe(GameLib.Event.RECEIVE_DESTINATION_CHANGED,this.receiveDestinationChanged)},GameLib.System.GUI.prototype.onChange=function(e,t,i){returnfunction(n){i.map(function(i){i[e][t]=n,iinstanceofGameLib.D3.Mesh&&"rotation"===e&&(i.useQuaternion=!1),iinstanceofGameLib.D3.Mesh&&"quaternion"===e&&(i.useQuaternion=!0),"function"==typeofi[e].updateInstance?i[e].updateInstance(e):"function"==typeofi[e][t].updateInstance?i[e][t].updateInstance(t):i.updateInstance(e)})}},GameLib.System.GUI.prototype.controller=function(e,t,i,n,a,s,o,r,c){GameLib.Utils.UndefinedOrNull(r)&&(r=-1e3),GameLib.Utils.UndefinedOrNull(c)&&(c=1e3),"axleLocal"!==i&&"directionLocal"!==i||(r=-1,c=1,a=1),"offset"!==i&&"repeat"!==i||(r=-1e3,c=1e3,a=.01);varm=e.add(t[i],n,r,c,a).name(i+"."+n);returnm.onChange(this.onChange(i,n,o)),s&&m.listen(),m},GameLib.System.GUI.prototype.buildQuaternionControl=function(e,t,i){varn=t.template,a=!1;1===t.affected.length&&(n=t.affected[0],a=!0);vars=t.affected;this.controller(e,n,i,"x",.1,a,s),this.controller(e,n,i,"y",.1,a,s),this.controller(e,n,i,"z",.1,a,s),this.controller(e,n,i,"w",.1,a,s),this.controller(e,n,i,"angle",.001,a,s,-Math.PI,Math.PI),e.add(n[i].axis,"x",-1,1,.01).name("quaternion.axis.x").onChange(function(e){s.map(function(t){t.useQuaternion=!0,t[i].axis.x=Number(e),t.updateInstance("x")})}),e.add(n[i].axis,"y",-1,1,.01).name("quaternion.axis.y").onChange(function(e){s.map(function(t){t.useQuaternion=!0,t[i].axis.y=Number(e),t.updateInstance("y")})}),e.add(n[i].axis,"z",-1,1,.01).name("quaternion.axis.z").onChange(function(e){s.map(function(t){t.useQuaternion=!0,t[i].axis.z=Number(e),t.updateInstance("z")})})},GameLib.System.GUI.prototype.buildVectorControl=function(e,t,i){varn=t.template,a=!1;1===t.affected.length&&(n=t.affected[0],a=!0);vars=t.affected,o=[];GameLib.Utils.isVector4(n[i])&&o.push(this.controller(e,n,i,"w",.01,a,s)),o.push(this.controller(e,n,i,"x",.01,a,s)),o.push(this.controller(e,n,i,"y",.01,a,s)),(GameLib.Utils.isVector3(n[i])||GameLib.Utils.isVector4(n[i]))&&o.push(this.controller(e,n,i,"z",.01,a,s))},GameLib.System.GUI.prototype.buildParentSelectionControl=function(e,t,i){varn=GameLib.Utils.UpperCaseUnderscore(i.replace("parent","")),a=GameLib.Component[n],s=GameLib.Component.GetComponentConstructor(a),o=GameLib.EntityManager.Instance.queryComponentsByConstructor(s).reduce(function(e,t){returne[t.name]=t,e},{none:null}),r=t.template,c=t.affected;e.add(r,i,o).listen().onChange(function(e){vart=null;"null"!==e&&(t=GameLib.EntityManager.Instance.findComponentById(e)),c.map(function(e){e[i]=t,"parentEntity"===i&&GameLib.Event.Emit(GameLib.Event.PARENT_ENTITY_CHANGE,{originalEntity:this.initialValue,newEntity:t,object:e}),"parentPhysicsWorld"===i&&GameLib.Event.Emit(GameLib.Event.PARENT_WORLD_CHANGE,{originalWorld:this.initialValue,newWorld:t,object:e}),"parentScene"===i&&GameLib.Event.Emit(GameLib.Event.PARENT_SCENE_CHANGE,{originalScene:this.initialValue,newScene:t,object:e})}.bind(this)),"parentEntity"===i&&GameLib.Event.Emit(GameLib.Event.BUILD_GUI,null),this.initialValue=t})},GameLib.System.GUI.prototype.buildArrayManagerControl=function(e,t,i){varn=t.template.linkedObjects[i];if(!(ninstanceofArray))returnvoidconsole.error("data mismatch - something not an array");vara=t.template,s=a[i],o=func
;e.domElement.instance.removeEventListener("mousedown",this.mouseDown,!1),e.domElement.instance.removeEventListener("mousemove",this.mouseMove,!1),e.domElement.instance.removeEventListener("wheel",this.mouseWheel,!1),e.domElement.instance.removeEventListener("mouseup",this.mouseUp,!1)}},GameLib.System.Input.prototype.onKeyboardKeyUp=function(e){GameLib.Event.Emit(GameLib.Event.KEY_DOWN,{code:e.code})},GameLib.System.Input.prototype.onKeyboardKeyDown=function(e){GameLib.Event.Emit(GameLib.Event.KEY_UP,{code:e.code})},GameLib.System.Input.prototype.onTouchStart=function(e){this.sensitivityCounter=0,this.touches={};for(vart=0;t<e.touches.length;t++)this.touches[e.touches[t].identifier]={left:0,right:0,up:0,down:0,lastTouchX:e.touches[t].pageX,lastTouchY:e.touches[t].pageY,pageX:e.touches[t].pageX,pageY:e.touches[t].pageY,cancelled:!1,ended:!1};this.touches.event=e,GameLib.Event.Emit(GameLib.Event.TOUCH_START,this.touches)},GameLib.System.Input.prototype.onTouchMove=function(e){this.sensitivityCounter++;for(vart=null,i=null,n=null,a=null,s=null,o=!1,r=!1,c=!1,m=!1,h=0;h<e.changedTouches.length;h++)if(t=e.changedTouches[h].identifier,this.touches[t]){varl=Math.abs(this.touches[t].lastTouchX-e.changedTouches[h].pageX),p=Math.abs(this.touches[t].lastTouchY-e.changedTouches[h].pageY),u=0,b=0,d=0,L=0;this.touches[t].lastTouchX<e.changedTouches[h].pageX&&(b+=l),this.touches[t].lastTouchX>e.changedTouches[h].pageX&&(u+=l),this.touches[t].lastTouchY>e.changedTouches[h].pageY&&(d+=p),this.touches[t].lastTouchY<e.changedTouches[h].pageY&&(L+=p),this.touches[t].right=b,this.touches[t].left=u,this.touches[t].up=d,this.touches[t].down=L,this.touches[t].lastTouchX=e.changedTouches[h].pageX,this.touches[t].lastTouchY=e.changedTouches[h].pageY,this.touches[t].pageX=e.changedTouches[h].pageX,this.touches[t].pageY=e.changedTouches[h].pageY}2===e.changedTouches.length&&(e.changedTouches[0].pageX<e.changedTouches[1].pageX?(i=this.touches[e.changedTouches[0].identifier],n=this.touches[e.changedTouches[1].identifier]):(i=this.touches[e.changedTouches[1].identifier],n=this.touches[e.changedTouches[0].identifier]),e.changedTouches[0].pageY<e.changedTouches[1].pageY?(a=this.touches[e.changedTouches[1].identifier],s=this.touches[e.changedTouches[0].identifier]):(a=this.touches[e.changedTouches[0].identifier],s=this.touches[e.changedTouches[1].identifier])),i&&i.left&&n&&n.right&&(r=!0),i&&i.right&&n&&n.left&&(o=!0),a&&a.up&&s&&s.down&&(c=!0),a&&a.down&&s&&s.up&&(m=!0),this.touches.event=e,this.touches.meta={inward:o,outward:r,pinch:c,zoom:m},this.sensitivityCounter>=this.touchSensitivity&&(this.sensitivityCounter=0,GameLib.Event.Emit(GameLib.Event.TOUCH_MOVE,this.touches))},GameLib.System.Input.prototype.onTouchCancel=function(e){this.sensitivityCounter=0;for(vart=0;t<e.changedTouches.length;t++)this.touches[e.changedTouches[t].identifier].cancelled=!0,this.touches[e.changedTouches[t].identifier].event=e,GameLib.Event.Emit(GameLib.Event.TOUCH_CANCEL,this.touches[e.changedTouches[t].identifier]),deletethis.touches[e.changedTouches[t].identifier]},GameLib.System.Input.prototype.onTouchEnd=function(e){this.sensitivityCounter=0;for(vart=0;t<e.changedTouches.length;t++)this.touches[e.changedTouches[t].identifier].ended=!0,this.touches[e.changedTouches[t].identifier].event=e,GameLib.Event.Emit(GameLib.Event.TOUCH_END,this.touches[e.changedTouches[t].identifier]),deletethis.touches[e.changedTouches[t].identifier]},GameLib.System.Input.prototype.onKeyDown=function(e){console.log("input system emitted keypress "+e.code),GameLib.Event.Emit(GameLib.Event.KEY_DOWN,{code:e.code});vart=null;if("Delete"===e.code){t=GameLib.EntityManager.Instance.queryComponentsByConstructor(GameLib.D3.Mesh);vari=[];t.map(function(e){if(e.selected){i.push(e),e.removeHelper();vart=e.parentScene;t.removeObject(e),t.buildIdToObject()}}.bind(this)),GameLib.Event.Emit(GameLib.Event.REMOVE_MESH,{meshes:i})}"ControlLeft"===e.code&&(this.controlLeft=!0),"KeyA"===e.code&&(this.selectAll=!this.selectAll,t=GameLib.EntityManager.Instance.queryComponentsByConstructor(GameLib.D3.Mesh),
message:this.responseText,component:e.apiObject})}"success"===t.result?GameLib.Event.Emit(GameLib.Event.COMPONENT_SAVED,{message:t.message||"Successfully saved the component",component:e.apiObject}):GameLib.Event.Emit(GameLib.Event.SAVE_COMPONENT_ERROR,{message:t.message||"The server responded but failed to save the component",component:e.apiObject})}},i.send(JSON.stringify({component:e.apiObject,session:this.token}))})},GameLib.System.Storage.prototype.createRuntimeObject=function(e,t){try{vari=JSON.parse(e)}catch(e){returnthis.onComponentError&&this.onComponentError(e),t&&t({message:e.message||"JSON parse error"}),GameLib.Event.Emit(GameLib.Event.LOAD_COMPONENT_ERROR,{error:e}),null}if("success"!==i.result)returnthis.onComponentError&&this.onComponentError(id,i),t&&t({message:i.message||"Server load error"}),GameLib.Event.Emit(GameLib.Event.LOAD_COMPONENT_ERROR,{error:i}),null;varn=GameLib.Component.ConstructFromObject(i.component[0]);returnn||t&&t({result:"failure",message:"Could not create a runtime component: "+i.component[0].name}),n},GameLib.System.Storage.prototype.loadComponent=function(e,t,i,n,a){t.map(function(e){GameLib.Utils.PushUnique(this.loading,e);vart=GameLib.EntityManager.Instance.findComponentById(e);t&&t.remove()}.bind(this)),t.map(function(t){vars=newXMLHttpRequest;s.onload=function(s){returnfunction(){varo=s.createRuntimeObject.bind(s)(this.responseText);if(!o)returnvoids.failed.push(t);if(o.parentEntity&&"string"==typeofo.parentEntity&&GameLib.EntityManager.Instance.queryComponents(GameLib.Component.ENTITY).map(function(e){o.parentEntity===e.id&&(o.parentEntity=e)}),GameLib.Event.Emit(GameLib.Event.COMPONENT_CREATED,{component:o}),s.loaded.push(o.id),i){varr=o.getDependencies();s.otherDependencies.map(function(e){vart=r.indexOf(e);-1!==t&&r.splice(t,1)}),r.map(function(e){GameLib.Utils.PushUnique(this.otherDependencies,e)}.bind(s)),r=r.reduce(function(e,t){return-1===s.failed.indexOf(t)?e.push(t):console.log("ignoring failed component : "+t),e}.bind(s),[]),r=r.reduce(function(e,t){returnGameLib.EntityManager.Instance.findComponentById(t)||e.push(t),e},[]),r=r.reduce(function(e,t){return-1===s.loaded.indexOf(t)&&e.push(t),e},[]),r.map(function(e){GameLib.Utils.PushUnique(s.loading,e)}),s.loadComponent(e,r,i,n,a),GameLib.Event.Emit(GameLib.Event.LOAD_PROGRESS,{loaded:s.loaded.length,toProcess:r.length})}s.onComponentLoaded&&s.onComponentLoaded(o)}}(this),s.onprogress=function(e){returnfunction(t){vari=0;0!==t.total&&(i=Math.round(100*Number(t.loaded/t.total))),this.onComponentProgress&&this.onComponentProgress(e,i)}.bind(this)}(t),s.onerror=function(e){returnfunction(t){console.warn("component load failed for component ID "+e),this.onComponentError&&this.onComponentError(e,t),a&&a({message:"xhr request failure"})}.bind(this)}(t),s.open("GET",e+"/component/load/"+t),s.send()}.bind(this))},GameLib.System.Storage.prototype.load=function(e,t,i){this.publish(GameLib.Event.GET_API_URL,null,function(n){if("undefined"==typeofXMLHttpRequest)returnvoidconsole.log("Implement server side load here");e.ids&&e.ids.length>0?this.loadComponent(n.apiUrl,e.ids,e.includeDependencies,t,i):console.log("No components selected")}.bind(this),function(e){throwconsole.error(e.message),newError(e.message)})},GameLib.System.Storage.prototype.xhrLoad=function(e,t,i){if("undefined"==typeofXMLHttpRequest)returnvoidconsole.log("Implement server side load here");console.log("Loading...","success");varn=newXMLHttpRequest;n.open("GET",e),n.setRequestHeader("Accept","application/json"),n.setRequestHeader("Content-Type","application/json"),n.onreadystatechange=function(){if(4===n.readyState){if(!n.responseText)returnconsole.log("Invalid response from server"),voidi({message:"Invalid response from server"});try{vare=JSON.parse(n.responseText)}catch(e){e.message="Could not parse JSON",i(e)}if("success"!==e.result)returni({message:e.message||"Unknown Error Occurred"});t(e)}},n.onerror=i,n.send()},GameLib.System.Storage.prototype.fetchComponentTypes=function(e,t,i){this.xhrLoad(e.url,function(e){t({ids:e.i