functionGameLib(){}var__DATE__="Sun Dec 10 2017 12:56:56 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
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=function(e){vart=[],i=[],n=[];if(this.buildIdToObject(),this.saveSubscription||this.saveErrorSubscription)returnvoidconsole.warn("another save is in progress");GameLib.Event.Emit(GameLib.Event.SAVING,{component:this}),this.saveSubscription=GameLib.Event.Subscribe(GameLib.Event.COMPONENT_SAVED,function(e){i.push(e.component),n.length+i.length===t.length&&(this.saveSubscription.remove(),this.saveSubscription=null,this.saveErrorSubscription.remove(),this.saveErrorSubscription=null,GameLib.Event.Emit(GameLib.Event.DONE_SAVING,{failed:n,saved:i}))}.bind(this)),this.saveErrorSubscription=GameLib.Event.Subscribe(GameLib.Event.SAVE_COMPONENT_ERROR,function(e){n.push(e.component),n.length+i.length===t.length&&(this.saveSubscription.remove(),this.saveSubscription=null,this.saveErrorSubscription.remove(),this.saveErrorSubscription=nu
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.buildVectorSource=function(e,t,i){return2===i?(e[t]={},e[t].x=!1,void(e[t].y=!1)):3===i?(e[t]={},e[t].x=!1,e[t].y=!1,void(e[t].y=!1)):4===i?(e[t]={},e[t].x=!1,e[t].y=!1,e[t].z=!1,void(e[t].w=!1)):voidconsole.warn("unknown dimension : "+i)},GameLib.Cast.prototype.buildQuaternionSource=function(e,t){e[t]={},e[t].axis={},e[t].axis.x=!1,e[t].axis.y=!1,e[t].axis.z=!1,e[t].angle=!1,e[t].x=!1,e[t].y=!1,e[t].z=!1,e[t].w=!1},GameLib.Cast.prototype.updateInstance=function(e){"source"===e&&(null!==this.source?this.sourceProperties=Object.keys(this.source).reduce(function(e,t){return"function"==typeofthis.source[t]?e:(e[t]=!1,e)}.bind(this),{}):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.graphics=e,this.graphics.isNotThreeThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),tinstanceofGameLib.Clock)returnt;GameLib.API.Clock.call(this,t.id,t.name,t.parentEntity),GameLib.Component.call(this)},GameLib.Clock.prototype=Object.create(GameLib.API.Clock.prototype),GameLib.Clock.prototype.constructor=GameLib.Clock,GameLib.Clock.pr
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"===e&&(this.position.instance.x=this.position.x,this.position.instance.y=this.position.y,this.position.instance.z=this.position.z,this.templateParticle.mesh.position=this.position.clone(),this.templateParticle.mesh.updateInstance("position",!0)),"direction"===e&&(this.direction.instance.x=this.direction.x,this.direction.instance.y=this.direction.y,this.direction.instance.z=this.direction.z,this.templateParticle.direction=this.direction.cl
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.error("no property for renderer"),"localClipping"===e&&(this.instance.localClippingEnabled=this.localClipping),this.instance.setSize(this.width,this.height),this.instance.domElement.width=this.width,this.instance.domElement.height=this.height,"clearColor"===e&&this.instance.setClearColor(newTHREE.Color(this.clearColor.r,this.clearColor.g,this.clearColor.b),1-this.clearColor.a),"autoClear"===e&&(this.instance.autoClear=this.aut
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,this.boneTextureWidth,this.boneTextureHeight,this.boneMatrices.map(function(e){returne.toApiObject()}),this.boneTexture,GameLib.Utils.IdOrNull(this.parentEntity))},GameLib.D3.Skeleton.FromObject=function(e,t){if(!t)returnnull;vari=GameLib.D3.API.Skeleton.FromObject(t);returnnewGameLib.D3.Skeleton(e,i)},GameLib.D3.Solver=function(e,t){if(this.physics=e,this.physics.isNotCannonThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),tinstanc
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=function(n,a){vars="invalid item";n&&n.name&&(s=n.name);varo=e.add({remove:function(){t.affected.map(function(t){t[i].splice(a,1),e.remove(o)})}},"remove").name("remove "+i+"["+a+"] - "+s);e.updateDisplay()};s.map(o);varr={},c=GameLib.EntityManager.Instance.queryComponents(n).reduce(function(e,t){returne[t.name]=t,r[t.id]=t,e},{none:null}),m={component:null,add:function(){t.affected.map(function(e){-1===e[i].indexOf(m.component)&&(e[i].push(m.component),GameLib.Event.Emit(GameLib.Event.ARRAY_ITEM_ADDED,{component:e,property:i,item:m.component}))}),GameLib.Event.Emit(GameLib.Event.BUILD_GUI)}};e.add(m,"component",c).name("select "+i).onChange(function(e){m.component="null"===e?null:r[e]}).listen(),e.add(m,"add").name("add to "+i)},GameLib.System.GUI.prototype.buildColorControl=function(e,t,i){varn=t.template,a={hexColor:n[i].toHex()};e.addColor(a,"hexColor").name(i).listen().onChange(function(e){t.affected.map(function(t){t[i].fromHex(e),t[i].updateInstance(i)})}),e.add(a,"hexColor").name(i).listen().onChange(function(e){t.affected.map(function(t){t[i].fromHex(e),t[i].updateInstance(i)})})},GameLib.System.GUI.prototype.buildObjectControl=function(e,t,i){varn=t.template[i];null!==n&&"sourceProperties"===i&&Object.keys(n).map(function(a){e.add(n,a).name(i+"."+a).listen().onChange(function(e){t.affected.map(function(t){t.sourceProperties[a]=e,t.updateInstance("sourceProperties")})})})},GameLib.System.GUI.prototype.buildSelectControl=function(e,t,i){varn=null;if(t.template.linkedObjects&&t.template.linkedObjects[i]?n=t.template.linkedObjects[i]:t.template[i]&&(n=t.template[i].constructor),!n)returnvoidconsole.log("cannot determine constructor");vara=t.template,s=GameLib.EntityManager.Instance.queryComponentsByConstructor(n),o={},r=s.reduce(function(e,t){returne[t.name]=t,o[t.id]=t,e},{none:null});e.add(a,i,r).name(i).listen().onChange(function(e){varn=null;"null"!==e&&(n=o[e]),t.affected.map(function(e){e[i]=n,e.updateInstan
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),t.map(function(e){this.selectAll?this.selectMesh(e):this.deSelectMesh(e)}.bind(this)),GameLib.Event.Emit(GameLib.Event.BUILD_GUI,null)),"KeyP"===e.code&&GameLib.Event.Emit(GameLib.Event.GAME_PAUSE)},GameLib.System.Input.prototype.onKeyUp=function(e){GameLib.Event.Emit(GameLib.Event.KEY_UP,{code:e.code}),"ControlLeft"===e.code&&(this.controlLeft=!1)},GameLib.System.Input.prototype.onMouseDown=function(e){GameLib.Event.Emit(GameLib.Event.MOUSE_DOWN,{event:e})},GameLib.System.Input.prototype.onMouseMove=function(e){GameLib.Event.Emit(GameLib.Event.MOUSE_MOVE,{event:e})},GameLib.System.Input.prototype.onMouseWheel=function(e){GameLib.Event.Emit(GameLib.Event.MOUSE_WHEEL,{event:e})},GameLib.System.Input.prototype.onMouseUp=function(e){GameLib.Event.Emit(GameLib.Event.MOUSE_UP,{event:e})},GameLib.System.Input.prototype.onMouseDownEdit=function(e){2===e.button&&this.editorControls.map(function(t){if(!this.controlLeft){this.mouse.x=e.offsetX/e.target.width*2-1,this.mouse.y=-e.offsetY/e.target.height*2+1;vari=GameLib.EntityManager.Instance.queryComponents(GameLib.Component.SCENE),n=i.reduce(function(e,i){returnt.raycaster.instance.setFromCamera(this.mouse,t.camera.instance),n=t.raycaster.getIntersectedObjects(i.meshes),n.map(function(t){e.push(t)}),e}.bind(this),[]);n.sort(function(e,t){returne.distance<t.distance?-1:e.distance>t.distance?1:0});vara=n.map(function(e){returne.mesh}),s=a[0];s&&(e.preventDefault(),e.stopImmediatePropagation(),s.selected?this.deSelectMesh(s):this.selectMesh(s),GameLib.Event.Emit(GameLib.Event.BUILD_GUI,null))}}.bind(this))},GameLib.System.Input.prototype.onMouseMoveEdit=function(e){},GameLib.System.Input.prototype.onMouseUpEdit=function(e){this.editorControls.map(function(e){e.camera.position.x=e.camera.instance.position.x,e.camera.position.y=e.camera.instance.position.y,e.camera.position.z=e.camera.instance.position.z,e.camera.quaternion.x=e.camera.instance.quaternion.x,e.camera.quaternion.y=e.camera.instance.quaternion.y,e.camera.quaternion.z=e.camera.instance.quaternion.z,e.camera.quaternion.w=e.camera.instance.quaternion.w,e.camera.lookAt.x=e.instance.center.x,e.camera.lookAt.y=e.instance.center.y,e.camera.lookAt.z=e.instance.center.z,e.camera.lookAt.instance
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.ids})},i)},GameLib.System.Storage.prototype.fetchComponents=function(e,t,i){this.xhrLoad(e.url,function(e){t({components:e.component})},i)},GameLib.System.Storage.prototype.imageUploadComplete=function(e){e.images.map(function(e){vart=GameLib.EntityManager.Instance.findComponentById(e.id);t?(t.updateFromRawObject(e),t.updateInstance("path")):GameLib.Component.ConstructFromObject(e)}.bind(this))},GameLib.System.Storage.prototype.processBlenderData=function(e){console.log("loading blender data"),e.images.map(function(e){vart=GameLib.Component.ConstructFromObject(e);GameLib.Event.Emit(GameLib.Event.COMPONENT_CREATED,{component:t})}.bind(this)),e.textures.map(function(e){vart=GameLib.Component.ConstructFromObject(e);GameLib.Event.Emit(GameLib.Event.COMPONENT_CREATED,{component:t})}.bind(this)),e.materials.map(function(e){vart=GameLib.Component.ConstructFromObject(e);GameLib.Event.Emit(GameLib.Event.COMPONENT_CREATED,{component:t})}.bind(this)),e.meshes.map(function(e){vart=GameLib.Component.ConstructFromObject(e);GameLib.Event.Emit(GameLib.Event.COMPONENT_CREATED,{component:t})}.bind(this))},GameLib.System.Storage.prototype.loadFont=function(e,t,i){console.log("loading font : "+e.font.name),this.publish(GameLib.Event.GET_API_URL,null,function(n){vara=n.apiUrl+"/fonts/"+e.font.url+"?ts="+Date.now();(newTHREE.FontLoader).load(a,function(e){GameLib.Utils.IsEmpty(e.data)?i({message:"font is empty"}):t(e)})}.bind(this),function(e){i(e)})},GameLib.System.Storage.prototype.loadImage=function(e,t,i){console.log("loading image : "+e.image.name),this.publish(GameLib.Event.GET_API_URL,null,function(n){vara=this.onImageLoaded,s=this.onImageProgress,o=this.onImageError,r=e.image,c=n.apiUrl+r.path+r.fileName+r.extension+"?ts="+Date.now(),m=newXMLHttpRequest;m.withCredentials=!0,m.open("OPTIONS",c),m.setRequestHeader("Content-Type","application/json"),m.onload=function(){varn=newXMLHttpRequest;n.withCredentials=!0,n.open("GET",c),n.setRequestHeader("Content-Type",r.contentType),n.responseType="blob",n.onload=function(){varn=!1,s="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAIAAAAlC+aJAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH4QoWEQMQBXD4hQAAABl0RVh0Q29tbWVudABDcmVhdGVkIHdpdGggR0lNUFeB