functionGameLib(){}var__DATE__="Tue Dec 05 2017 21:13:00 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.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.Event.GAME_DATA=98,GameLib.Event.
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=null,GameLib.Event.Emit(GameLib.Event.DONE_SAVING
this.instance.penumbra=this.penumbra,this.instance.decay=this.decay}this.instance.name=this.name,this.instance.position.x=this.position.x,this.instance.position.y=this.position.y,this.instance.position.z=this.position.z,this.instance.scale.x=this.scale.x,this.instance.scale.y=this.scale.y,this.instance.scale.z=this.scale.z,this.instance.target&&(this.instance.target.position.x=this.targetPosition.x,this.instance.target.position.y=this.targetPosition.y,this.instance.target.position.z=this.targetPosition.z),this.instance.quaternion.x=this.quaternion.x,this.instance.quaternion.y=this.quaternion.y,this.instance.quaternion.z=this.quaternion.z,this.instance.quaternion.w=this.quaternion.w,this.instance.intensity=this.intensity,this.instance.color.set(this.color.toHex()),GameLib.Component.prototype.createInstance.call(this)},GameLib.D3.Light.prototype.updateInstance=function(e){GameLib.Utils.UndefinedOrNull(e)&&console.warn("no property for light: "+this.name),"lightType"===e&&(this.parentScene.instance.remove(this.instance),this.createInstance(),this.parentScene.instance.add(this.instance)),"name"===e&&(this.instance.name=this.name),"position"===e&&(this.instance.position.x=this.position.x,this.instance.position.y=this.position.y,this.instance.position.z=this.position.z),"scale"===e&&(this.instance.scale.x=this.scale.x,this.instance.scale.y=this.scale.y,this.instance.scale.z=this.scale.z),"target"===e&&this.instance.target&&(this.instance.target.position.x=this.targetPosition.x,this.instance.target.position.y=this.targetPosition.y,this.instance.target.position.z=this.targetPosition.z),"quaternion"===e&&(this.instance.quaternion.x=this.quaternion.x,this.instance.quaternion.y=this.quaternion.y,this.instance.quaternion.z=this.quaternion.z,this.instance.quaternion.w=this.quaternion.w),"intensity"===e&&(this.instance.intensity=this.intensity),"color"===e&&this.instance.color.set(this.color.toHex())},GameLib.D3.Light.prototype.toApiObject=function(){returnnewGameLib.D3.API.Light(this.id,this.lightType,this.name,this.color.toApiObject(),this.intensity,this.position.toApiObject(),this.targetPosition.toApiObject(),this.quaternion.toApiObject(),this.rotation.toApiObject(),this.scale.toApiObject(),this.distance,this.decay,this.power,this.angle,this.penumbra,GameLib.Utils.IdOrNull(this.parentScene),GameLib.Utils.IdOrNull(this.parentEntity))},GameLib.D3.Light.FromObject=function(e,t){returnnewGameLib.D3.Light(e,GameLib.D3.API.Light.FromObject(t))},GameLib.D3.Material=function(e,t){if(this.graphics=e,this.graphics.isNotThreeThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),tinstanceofGameLib.D3.Material)returnt;GameLib.D3.API.Material.call(this,t.id,t.materialType,t.name,t.opacity,t.side,t.transparent,t.specular,t.lightMapIntensity,t.aoMapIntensity,t.color,t.emissive,t.emissiveIntensity,t.combine,t.shininess,t.reflectivity,t.refractionRatio,t.fog,t.wireframe,t.wireframeLineWidth,t.wireframeLineCap,t.wireframeLineJoin,t.vertexColors,t.skinning,t.morphTargets,t.morphNormals,t.lineWidth,t.lineCap,t.lineJoin,t.dashSize,t.gapWidth,t.blending,t.blendSrc,t.blendDst,t.blendEquation,t.depthTest,t.depthFunc,t.depthWrite,t.polygonOffset,t.polygonOffsetFactor,t.polygonOffsetUnits,t.alphaTest,t.clippingPlanes,t.clipShadows,t.visible,t.overdraw,t.flatShading,t.bumpScale,t.normalScale,t.displacementScale,t.displacementBias,t.roughness,t.metalness,t.pointSize,t.pointSizeAttenuation,t.spriteRotation,t.envMapIntensity,t.alphaMap,t.aoMap,t.bumpMap,t.diffuseMap,t.displacementMap,t.emissiveMap,t.environmentMap,t.lightMap,t.metalnessMap,t.normalMap,t.roughnessMap,t.specularMap,t.parentEntity),this.specular=newGameLib.Color(e,this.specular,this),this.color=newGameLib.Color(e,this.color,this),this.emissive=newGameLib.Color(e,this.emissive,this),this.alphaMap&&this.alphaMapinstanceofGameLib.D3.API.Texture&&(this.alphaMap=newGameLib.D3.Texture(this.graphics,this.alphaMap)),this.aoMap&&this.aoMapinstanceofGameLib.D3.API.Texture&&(this.aoMap=newGameLib.D3.Texture(this.graphics,this.aoMap)),this.bumpMap&&this.bumpMapinstanceofGameLib.D3.API.Texture&&(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.clone(),this.templateParticle.direction.updateInstance("direction",!0))},GameLib.D3.ParticleEngine.prototype.remove=function(){if(this.removeSubscription)returnvoidconsole.log("already another remove subscription for "+this.name);this.removeSubscription=GameLib.Event.Subscribe(GameLib.Event.REMOVE_PARTICLE_ENGINE,function(e){e.component===this&&(this.isClone?(GameLib.Event.Emit(GameLib.Event.REMOVE_COMPONENT,{component:this.templateParticle.mesh}),GameLib.Event.Emit(GameLib.Event.REMOVE_COMPONENT,{component:this.templateParticle}),GameLib.Event.Emit(GameLib.Event.REMOVE_COMPONENT,{component:this})):GameLib.Component.prototype.remove.call(this),this.removeSubscription.remove(),this.removeSubscription=null)}.bind(this)),this.disabledForRemoval=!0},GameLib.D3.ParticleEngine.prototype.clone=function(){vare=this.templateParticle.mesh.clone(),t=this.templateParticle.clone();t.mesh=e,t.instance=e.instance;vari=GameLib.Component.prototype.clone.call(this);returni.templateParticle=t,i},GameLib.D3.ParticleEngine.prototype.processParticles=function(e){},GameLib.D3.ParticleEngine.prototype.createNewParticle=function(e){},GameLib.D3.ParticleEngine.prototype.toApiObject=function(){returnnewGameLib.D3.API.ParticleEngine(this.id,this.n
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.autoClear),"preserveDrawingBuffer"===e&&(this.instance.preserveDrawingBuffer=this.preserveDrawingBuffer),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.clippingPlanes=[],"sortObjects"===e&&(this.instance.sortObjects=this.sortObjects);elsetry{this.createInstance()}catch(e){console.error(e.message)}},GameLib.D3.Renderer.prototype.toApiObject=function(){returnnewGameLib.D3.API.Renderer(this.id,this.name,this.autoClear,this.localClipping,this.width,this.height,this.preserveDrawingBuffer,GameLib.Utils.IdOrNull(this.domElement),this.clearColor.toApiObject(),GameLib.Utils.IdOrNull(this.camera),this.scenes.map(function(e){returnGameLib.Utils.IdOrNull(e)}),this.viewports.map(function(e){returnGameLib.Utils.IdOrNull(e)}),this.clippingPlanes.map(function(e){returnGameLib.Utils.IdOrNull(e)}),GameLib.Utils.IdOrNull(this.bufferScene),GameLib.Utils.IdOrNull(this.bufferCamera),GameLib.Utils.IdOrNull(this.renderTarget),GameLib.Utils.IdOrNull(this.defaultScene),this.sortObjects,GameLib.Utils.IdOrNull(this.parentEntity))},
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={}),tinstanceofGameLib.D3.Solver)returnt;GameLib.D3.API.Solver.call(this,t.id,t.name,t.solverType,t.iterations,t.tolerance,t.parentEntity),GameLib.Component.call(this)},GameLib.D3.Solver.prototype=Object.create(GameLib.D3.API.Solver.prototype),GameLib.D3.Solver.prototype.constructor=GameLib.D3.Solver,GameLib.D3.Solver.prototype.createInstance=function(){if(this.solverType===GameLib.D3.API.Solver.GS_SOLVER)this.instance=newCANNON.GSSolver;else{if(this.solverType!==GameLib.D3.API.Solver.SPLIT_SOLVER)thrownewError("unsupported solver type: "+this.solverType);this.instance=newCANNON.SplitSolver}this.instance.tolerance=this.tolerance,this.instance.iterations=this.iterations,GameLib.Component.prototype.createInstance.call(this)},GameLib.D3.Solver.prototype.updateInstance=function(){this.solverType===GameLib.D3.API.Solver.GS_SOLVER&&(this.instanceinstanceofCANNON.GSSolver||(this.instance=newCANNON.GSSolver)),this.solverType===GameLib.D3.API.Solver.SPLIT_SOLVER&&(this.instanceinstanceofCANNON.SplitSolver||(this.instance=newCANNON.SplitSolver)),this.instance.iterations=this.iterations,this.instance.tolerance=this.tolerance},GameLib.D3.Solver.prototype.toApiObject=function(){returnnewGameLib.D3.API.Solver(this.id,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[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.updateInstance(i)}),this.initialValue=n})},GameLib.System.GUI.prototype.buildControl=function(e,t,i){varn=t.template,a=!1;1===t.affected.length&&(n=t.affected[0],a=!0);vars=t.componentType,o=[];if((GameLib.Utils.isString(n[i])||GameLib.Utils.isBoolean(n[i]))&&o.push(e.add(n,i)),GameLib.Utils.isNumber(n[i])){if(n.grain&&n.grain,"componentType"===i){varr={componentType:GameLib.Component.GetComponentInfo(n[i]).name};o.push(e.add(r,"componentType"))}elseif("systemType"===i)o.push(e.add(n,i,{animation:GameLib.System.SYSTEM_TYPE_ANIMATION,gui:GameLib.System.SYSTEM_TYPE_GUI,input:GameLib.System.SYSTEM_TYPE_INPUT,render:GameLib.System.SYSTEM_TYPE_RENDER,storage:GameLib.System.SYSTEM_TYPE_STORAGE,linking:GameLib.System.SYSTEM_TYPE_LINKING,physics:GameLib.System.SYSTEM_TYPE_PHYSICS,"custom code":GameLib.System.SYSTEM_TYPE_CUSTOM}));elseif("castType"===i)o.push(e.add(n,i,{room:GameLib.API.Cast.CAST_TYPE_ROOM,peer:GameLib.API.Cast.CAST_TYPE_PEER,all:GameLib.API.Cast.CAST_TYPE_ALL,"all but peer":GameLib.API.Cast.CAST_TYPE_ALL_BUT_PEER}));elseif("opacityType"===i)o.push(e.add(n,i,{constant:GameLib.D3.Particle.OPACITY_TYPE_CONSTANT,decrease:GameLib.D3.Particle.OPACITY_TYPE_DECREASE_LINEAR,increase:GameLib.D3.Particle.OPACITY_TYPE_INCREASE_LINEAR}));elseif("positionOffsetType"===i)o.push(e.add(n,i,{constant:GameLib.D3.Particle.POSITION_OFFSET_TYPE_CONSTANT,random:GameLib.D3.Particle.POSITION_OFFSET_TYPE_RANDOM,function:GameLib.D3.Par
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+aJAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH4QoWEQMQBXD4hQAAABl0RVh0Q29tbWVudABDcmVhdGVkIHdpdGggR0lNUFeBDhcAAABRSURBVGje7c8xDQAwCAAwmA3koA/PU8FB0jpo1nRc9uI4AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBgX0fjEoBa8xN1z4AAAAASUVORK5CYII=";try{"application/json"!==this.response.type&&(s=window.URL.createObjectURL(this.response),n=!0)}catch(t){i&&i({result:"failure",message:"invalid server response trying to download image "+e.image.name})}varo=document.createElement("img");o.onload=function(){n&&window.URL.revokeObjectURL(s),t&&t(o),a&&a(r,e.createTexture)},o.src=s},n.onprogress=function(e){vart=0;0!==e.total&&(t=Math.round(100*Number(e.loaded/e.total))),s&&s(r,t),r.size=e.total},n.onerror=function(e){console.warn("image load failed for image "+r.name),i&&i(e),o&&o(r,e)},n.send()},m.onerror=function(e){console.warn("image pre-flight request failed for image "+r.name),i&&i(e),o&&o(r,e)},m.send()}.bind(this),function(e){throwconsole.error(e.message),newError(e.message)})},GameLib.System.Storage.prototype.stop=function(){GameLib.System.prototype.stop.call(this),this.loginSubscription.remove(),this.loadSubscription.remove(),this.saveSubscription.remove(),this.loadImageSubscription.remove(),this.loadFontSubscription.remove(),this.blenderDataSubscription.remove(),this.imageUploadCompleteSubscription.remove(),this.deleteSubscription.remove(),this.fetchComponentTypesSubscription.remove(),this.fetchComponentsSubscription.remove()},GameLib.System.Visualization=function(e,