functionGameLib(){}var__DATE__="Tue Nov 28 2017 09:08:58 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_UPDATED=52,GameLib.Event.AUDIO_ENDED=53,GameLib.Event.COMPONENT_LINKED=54,GameLib.Event.DONE_SAVING=55,GameLib.Event.BEFORE_RENDER=56,GameLib.Event.AFTER_RENDER=57,GameLib.Event.ARRAY_ITEM_ADDED=58,GameLib.Event.INSTANCE_CREATED=59,GameLib.Event.VISUALIZE=60,GameLib.Event.STOP_VISUALIZE=61,GameLib.Event.FETCH_COMPONENT_TYPES=62,GameLib.Event.FETCH_COMPONENTS=63,GameLib.Event.GET_API_URL=64,GameLib.Event.GET_PHYSICS_IMPLEMENTATION=65,GameLib.Event.PARENT_WORLD_CHANGE=66,GameLib.Event.ANIMATE=67,GameLib.Event.ANIMATION_COMPILE_SUCCESS=68,GameLib.Event.ANIMATION_COMPILE_FAILED=69,GameLib.Event.SAVING=70,GameLib.Event.GAME_OVER=71,GameLib.Event.GAME_START=72,GameLib.Event.TOUCH_START=73,GameLib.Event.TOUCH_END=74,GameLib.Event.TOUCH_MOVE=75,GameLib.Event.TOUCH_CANCEL=76,GameLib.Event.GET_REMOTE_API_URL=77,GameLib.Event.GET_GRAPHICS_IMPLEMENTATION=78,GameLib.Event.DELAYED_INSTANCE_ENCOUNTERED=79,GameLib.Event.GET_CODER_IMPLEMENTATION=80,GameLib.Event.ANIMATION_MESH_ADDED=81,GameLib.Event.ANIMATION_MESH_REMOVED=82,GameLib.Event.GET_SCENE=83,GameLib.Event.CUSTOM_CODE_WINDOW_RESIZE=84,GameLib.Event.LOAD_FONT=85,GameLib.Event.FONT_NOT_FOUND=86,GameLib.Event.STOP_ALL_AUDIO=87,GameLib.Event.REGISTER_DEPENDENCIES=88,GameLib.Event.GAME_LOADED=89,GameLib.Event.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.GA
this.forward=newGameLib.API.Vector4,this.left=newGameLib.API.Vector4,this.up=newGameLib.API.Vector4},GameLib.API.Matrix4.FromObject=function(e){if(e.rows)returnnewGameLib.API.Matrix4(GameLib.API.Vector4.FromObject(e.rows[0]),GameLib.API.Vector4.FromObject(e.rows[1]),GameLib.API.Vector4.FromObject(e.rows[2]),GameLib.API.Vector4.FromObject(e.rows[3]));if(einstanceofArray)returnnewGameLib.API.Matrix4(GameLib.API.Vector4.FromObject(e[0]),GameLib.API.Vector4.FromObject(e[1]),GameLib.API.Vector4.FromObject(e[2]),GameLib.API.Vector4.FromObject(e[3]));throwconsole.warn("Unsupported object matrix type - whats your DB version?"),newError("Unsupported object matrix type - whats your DB version?")},GameLib.API.Matrix4.prototype.rotationMatrixX=function(e){returnthis.identity(),this.rows[1]=newGameLib.API.Vector4(0,Math.cos(e),-1*Math.sin(e),0),this.rows[2]=newGameLib.API.Vector4(0,Math.sin(e),Math.cos(e),0),this},GameLib.API.Matrix4.prototype.rotationMatrixY=function(e){returnthis.identity(),this.rows[0]=newGameLib.API.Vector4(Math.cos(e),0,Math.sin(e),0),this.rows[2]=newGameLib.API.Vector4(-1*Math.sin(e),0,Math.cos(e),0),this},GameLib.API.Matrix4.prototype.rotationMatrixZ=function(e){returnthis.identity(),this.rows[0]=newGameLib.API.Vector4(Math.cos(e),-1*Math.sin(e),0,0),this.rows[1]=newGameLib.API.Vector4(Math.sin(e),Math.cos(e),0,0),this},GameLib.API.Matrix4.prototype.rotateX=function(e,t){returnthis.identity(),this.rotationMatrixX(e),this.multiply(t)},GameLib.API.Matrix4.prototype.rotateY=function(e,t){returnthis.identity(),this.rotationMatrixY(e),this.multiply(t)},GameLib.API.Matrix4.prototype.rotateZ=function(e,t){returnthis.identity(),this.rotationMatrixZ(e),this.multiply(t)},GameLib.API.Matrix4.prototype.multiply=function(e){returneinstanceofGameLib.API.Quaternion||einstanceofGameLib.API.Vector4?newGameLib.API.Quaternion(this.rows[0].x*e.x+this.rows[0].y*e.y+this.rows[0].z*e.z+this.rows[0].w*e.w,this.rows[1].x*e.x+this.rows[1].y*e.y+this.rows[1].z*e.z+this.rows[1].w*e.w,this.rows[2].x*e.x+this.rows[2].y*e.y+this.rows[2].z*e.z+this.rows[2].w*e.w,this.rows[3].x*e.x+this.rows[3].y*e.y+this.rows[3].z*e.z+this.rows[3].w*e.w):einstanceofGameLib.API.Vector3?newGameLib.API.Vector3(this.rows[0].x*e.x+this.rows[0].y*e.y+this.rows[0].z*e.z,this.rows[1].x*e.x+this.rows[1].y*e.y+this.rows[1].z*e.z,this.rows[2].x*e.x+this.rows[2].y*e.y+this.rows[2].z*e.z):void0},GameLib.API.Matrix4.prototype.identity=function(){this.rows=[newGameLib.API.Vector4(1,0,0,0),newGameLib.API.Vector4(0,1,0,0),newGameLib.API.Vector4(0,0,1,0),newGameLib.API.Vector4(0,0,0,1)]},GameLib.API.Mouse=function(e,t,i,n,s){GameLib.Utils.UndefinedOrNull(s)&&(s=null),this.parentEntity=s,GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="Mouse ("+this.id+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=0),this.x=i,GameLib.Utils.UndefinedOrNull(n)&&(n=0),this.y=n},GameLib.API.Mouse.prototype=Object.create(GameLib.Component.prototype),GameLib.API.Mouse.prototype.constructor=GameLib.API.Mouse,GameLib.API.Mouse.FromObject=function(e){returnnewGameLib.API.Mouse(e.id,e.name,e.x,e.y,e.parentEntity)},GameLib.API.Quaternion=function(e,t,i,n,s,a){GameLib.Utils.UndefinedOrNull(e)&&(e=0),this.x=e,GameLib.Utils.UndefinedOrNull(t)&&(t=0),this.y=t,GameLib.Utils.UndefinedOrNull(i)&&(i=0),this.z=i,GameLib.Utils.UndefinedOrNull(n)&&(n=1),this.w=n,GameLib.Utils.UndefinedOrNull(s)&&(s=newGameLib.API.Vector3),this.axis=s,GameLib.Utils.UndefinedOrNull(a)&&(a=0),this.angle=a},GameLib.API.Quaternion.prototype.translate=function(e){returnthis.x+=e.x,this.y+=e.y,this.z+=e.z,this},GameLib.API.Quaternion.prototype.copy=function(){returnnewGameLib.API.Quaternion(this.x,this.y,this.z,this.w)},GameLib.API.Quaternion.prototype.normalize=function(){vare=this.x*this.x+this.y*this.y+this.z*this.z;if(e<1e-6)returnthis;vart=1/Math.sqrt(e);this.x*=t,this.y*=t,this.z*=t},GameLib.API.Quaternion.prototype.multiply=function(e){vart,i,n,s,a=e,o=this;if(einstanceofGameLib.API.Matrix4)returnt=a.rows[0].x*o.
this.instance.rotation.set(this.rotation.x,this.rotation.y,this.rotation.z)),this.helper&&this.helper.updateInstance()},GameLib.D3.Mesh.prototype.updateInstancePosition=function(){this.position.instance.set(this.position.x,this.position.y,this.position.z),this.instance.position.copy(this.position.instance),this.helper&&(this.removeHelper(),this.createHelper())},GameLib.D3.Mesh.prototype.updateInstanceScale=function(){this.scale.instance.set(this.scale.x,this.scale.y,this.scale.z),this.instance.scale.copy(this.scale.instance),this.helper&&(this.removeHelper(),this.createHelper())},GameLib.D3.Mesh.prototype.getChildrenComponents=function(){vare=[];returnthis.materials.map(function(t){if(tinstanceofGameLib.D3.Material){GameLib.Utils.PushUnique(e,t);for(variint.linkedObjects)if(t.linkedObjects.hasOwnProperty(i)&&t.hasOwnProperty(i)&&t[i]&&"string"!=typeoft[i]&&"parentEntity"!==i){GameLib.Utils.PushUnique(e,t[i]);for(varnint[i].linkedObjects)t[i].linkedObjects.hasOwnProperty(n)&&t[i].hasOwnProperty(n)&&t[i][n]&&"string"!=typeoft[i][n]&&"parentEntity"!==n&&(t[i][n]instanceofArray?t[i][n].map(function(t){GameLib.Utils.PushUnique(e,t)}):GameLib.Utils.PushUnique(e,t[i][n]))}}}.bind(this)),GameLib.EntityManager.Instance.queryComponents(GameLib.D3.RigidBody).map(function(t){t.parentMesh===this&&GameLib.Utils.PushUnique(e,t)}.bind(this)),GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Shape).map(function(t){t.parentMesh===this&&GameLib.Utils.PushUnique(e,t)}.bind(this)),e},GameLib.D3.Mesh.prototype.createHelper=function(){if(GameLib.Utils.UndefinedOrNull(this.parentScene)||GameLib.Utils.UndefinedOrNull(this.parentScene.instance))returnvoidconsole.warn("this mesh has no parent scene - cannot create helper");this.helper&&this.removeHelper(),this.helper=newGameLib.D3.Helper(this.graphics,null,this.name+" Helper",this,GameLib.D3.Helper.HELPER_TYPE_EDGES),this.helper.updateInstance(),this.polygonOffset=this.instance.material.polygonOffset,this.instance.material.polygonOffset=!0,this.parentScene.instance.add(this.helper.instance)},GameLib.D3.Mesh.prototype.addMaterial=function(e){1===this.materials.length?this.instance.material=e.instance:this.instance.material=this.materials.map(function(e){returne.instance})},GameLib.D3.Mesh.prototype.removeHelper=function(){if(GameLib.Utils.UndefinedOrNull(this.parentScene)||GameLib.Utils.UndefinedOrNull(this.parentScene.instance))returnvoidconsole.warn("this mesh has no parent scene - cannot remove helper");this.helper&&this.helper.instance&&(this.parentScene.instance.remove(this.helper.instance),deletethis.helper.instance),this.instance.material.polygonOffset=this.polygonOffset,this.helper=null},GameLib.D3.Mesh.prototype.computeBoundingBox=function(e){GameLib.Utils.UndefinedOrNull(e)&&(this.instance&&this.instance.geometry?e=this.instance.geometry:console.log("no instance geometry to compute bounding box")),e.computeBoundingBox(),this.dimensions.x=e.boundingBox.getSize().x,this.dimensions.y=e.boundingBox.getSize().y,this.dimensions.z=e.boundingBox.getSize().z},GameLib.D3.Mesh.Box=function(e,t,i,n,s){if(this.graphics=e,this.graphics.isNotThreeThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),tinstanceofGameLib.D3.Mesh.Box)returnt;t.meshType=GameLib.D3.Mesh.MESH_TYPE_BOX,GameLib.Utils.UndefinedOrNull(i)&&(i=1),this.width=i,GameLib.Utils.UndefinedOrNull(n)&&(n=1),this.height=n,GameLib.Utils.UndefinedOrNull(s)&&(s=1),this.depth=s,GameLib.D3.Mesh.call(this,this.graphics,t)},GameLib.D3.Mesh.Box.prototype=Object.create(GameLib.D3.Mesh.prototype),GameLib.D3.Mesh.Box.prototype.constructor=GameLib.D3.Mesh.Box,GameLib.D3.Mesh.Box.prototype.createInstance=function(){vare=null;0===this.vertices.length&&(e=newTHREE.BoxGeometry(this.width,this.height,this.depth),this.updateVerticesFromGeometryInstance(e)),GameLib.D3.Mesh.prototype.createInstance.call(this),this.instance.userData.width=this.width,this.instance.userData.height=this.height,this.instance.userData.depth=this.depth},GameLib.D3.Mesh.Box.prototype.updateInstance=function(e){if(this.instance.userData.width!==this.width||th
1===add?(e.scale.x+=Math.random()*this.scale.x,e.scale.y+=Math.random()*this.scale.y,e.scale.z+=Math.random()*this.scale.z):(e.scale.x-=Math.random()*this.scale.x,e.scale.y-=Math.random()*this.scale.y,e.scale.z-=Math.random()*this.scale.z)),this.scaleType===GameLib.D3.Particle.SCALE_TYPE_RANDOM_X_EQUALS_Y){add=GameLib.Utils.GetRandomIntInclusive(1,2);vars=Math.random()*this.scale.x;1===add?(e.scale.x+=s,e.scale.y+=s,e.scale.z+=Math.random()*this.scale.z):(e.scale.x-=s,e.scale.y-=s,e.scale.z-=Math.random()*this.scale.z)}returne.userData.scale=this.scale.clone(),e.userData.lifeTime=this.lifeTime,e.userData.speedType=this.speedType,e.userData.speed=this.speed,e.userData.scene=this.mesh.parentScene.instance,e.userData.elapsed=0,e.userData.scene.add(e),e},GameLib.D3.Particle.prototype.toApiObject=function(){returnnewGameLib.D3.API.Particle(this.id,this.name,this.lifeTime,this.elapsed,GameLib.Utils.IdOrNull(this.mesh),this.opacityType,this.opacityFactor,this.positionOffsetType,this.positionOffset.toApiObject(),this.positionOffsetFn,this.directionType,this.direction.toApiObject(),this.directionFn,this.speedType,this.speed,this.scaleType,this.scale.toApiObject(),this.scaleFn,this.rotationType,this.rotation.toApiObject(),this.rotationFn,GameLib.Utils.IdOrNull(this.parentEngine),GameLib.Utils.IdOrNull(this.parentEntity))},GameLib.D3.Particle.FromObject=function(e,t){vari=GameLib.D3.API.Particle.FromObject(t);returnnewGameLib.D3.Particle(e,i)},GameLib.D3.Pass=function(e,t){if(this.graphics=e,this.graphics.isNotThreeThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),tinstanceofGameLib.D3.Pass)returnt;GameLib.D3.API.Pass.call(this,t.id,t.name,t.passType,t.camera,t.scene,t.renderToScreen,t.parentEntity),GameLib.Component.call(this,GameLib.Component.COMPONENT_PASS,{camera:GameLib.D3.Camera,scene:GameLib.D3.Scene})},GameLib.D3.Pass.prototype=Object.create(GameLib.D3.API.Pass.prototype),GameLib.D3.Pass.prototype.constructor=GameLib.D3.Pass,GameLib.D3.Pass.PASS_TYPE_RENDER=1,GameLib.D3.Pass.PASS_TYPE_COPY_SHADER=2,GameLib.D3.Pass.prototype.createInstance=function(){if(this.passType===GameLib.D3.Pass.PASS_TYPE_RENDER){if(GameLib.Utils.UndefinedOrNull(this.scene))thrownewError("no scene object");if(GameLib.Utils.UndefinedOrNull(this.camera))thrownewError("no camera object");if(GameLib.Utils.UndefinedOrNull(THREE.RenderPass))thrownewError("no render pass library");this.instance=newTHREE.RenderPass(this.scene.instance,this.camera.instance)}else{if(this.passType!==GameLib.D3.Pass.PASS_TYPE_COPY_SHADER)throwconsole.warn("Render pass not supported yet: "+this.passType),newError("Render pass not supported yet: "+this.passType);if(GameLib.Utils.UndefinedOrNull(THREE.CopyShader))thrownewError("no copyshader library");this.instance=THREE.CopyShader}this.instance.renderToScreen=this.renderToScreen,GameLib.Component.prototype.createInstance.call(this)},GameLib.D3.Pass.prototype.updateInstance=function(){this.passType!==GameLib.D3.Pass.PASS_TYPE_RENDER||this.instanceinstanceofTHREE.RenderPass||this.createInstance(),this.passType!==GameLib.D3.Pass.PASS_TYPE_COPY_SHADER||this.instanceinstanceofTHREE.CopyShader||this.createInstance(),this.instance.renderToScreen=this.renderToScreen},GameLib.D3.Pass.prototype.toApiObject=function(){returnnewGameLib.D3.API.Pass(this.id,this.name,this.passType,GameLib.Utils.IdOrNull(this.camera),GameLib.Utils.IdOrNull(this.scene),this.renderToScreen,GameLib.Utils.IdOrNull(this.parentEntity))},GameLib.D3.Pass.FromObject=function(e,t){vari=GameLib.D3.API.Pass.FromObject(t);returnnewGameLib.D3.Pass(e,i)},GameLib.D3.PathFollowing=function(e,t){if(this.graphics=e,this.graphics.isNotThreeThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),tinstanceofGameLib.D3.PathFollowing)returnt;GameLib.D3.API.PathFollowing.call(this,t.id,t.name,t.spline,t.mesh,t.raytraceMesh,t.accelleration,t.maxSpeed,t.baseOffset,t.maxOffset,t.steeringSpeed,t.targetOffset,t.currentOffset,t.currentPathValue,t.currentSpeed,t.direction,t.raycaster,t.currentPosition,t.futurePosition,t.up,t.rotationMatrix,t.rotationVector,t.parentEntit
;GameLib.D3.API.RigidBody.call(this,t.id,t.name,t.mass,t.friction,t.position,t.quaternion,t.velocity,t.angularVelocity,t.linearDamping,t.angularDamping,t.allowSleep,t.sleepSpeedLimit,t.sleepTimeLimit,t.collisionFilterGroup,t.collisionFilterMask,t.fixedRotation,t.shapes,t.kinematic,t.parentMesh,t.parentWorld,t.parentEntity),this.position=newGameLib.Vector3(this.physics,this.position,this),this.quaternion=newGameLib.Quaternion(this.physics,this.quaternion,this),this.velocity=newGameLib.Vector3(this.physics,this.velocity,this),this.angularVelocity=newGameLib.Vector3(this.physics,this.angularVelocity,this),this.force=newGameLib.Vector3(this.physics),this.forcePoint=newGameLib.Vector3(this.physics),GameLib.Component.call(this,GameLib.Component.COMPONENT_RIGID_BODY,{shapes:[GameLib.D3.Shape],parentMesh:GameLib.D3.Mesh,parentWorld:GameLib.D3.PhysicsWorld})},GameLib.D3.RigidBody.prototype=Object.create(GameLib.D3.API.RigidBody.prototype),GameLib.D3.RigidBody.prototype.constructor=GameLib.D3.RigidBody,GameLib.D3.RigidBody.prototype.createInstance=function(){this.instance=newCANNON.Body({mass:this.mass,friction:this.friction,position:this.position.instance,quaternion:this.quaternion.instance,velocity:this.velocity.instance,angularVelocity:this.angularVelocity.instance,linearDamping:this.linearDamping,angularDamping:this.angularDamping,allowSleep:this.allowSleep,sleepSpeedLimit:this.sleepSpeedLimit,sleepTimeLimit:this.sleepTimeLimit,collisionFilterGroup:this.collisionFilterGroup,collisionFilterMask:this.collisionFilterMask,fixedRotation:this.fixedRotation,kinematic:this.kinematic}),this.instance.addEventListener("sleepy",function(){console.log(this.name+" is feeling sleepy...")}.bind(this)),this.instance.addEventListener("sleep",function(){console.log(this.name+" fell asleep!")}.bind(this)),this.instance.addEventListener("wakeup",function(){console.log(this.name+" woke up!")}.bind(this)),this.shapes.map(function(e){if(GameLib.Utils.UndefinedOrNull(e))thrownewError("no shape");if(GameLib.Utils.UndefinedOrNull(e.instance))thrownewError("no shape instance");this.instance.addShape(e.instance)}.bind(this)),GameLib.Component.prototype.createInstance.call(this)},GameLib.D3.RigidBody.prototype.updateInstance=function(){this.instance.mass=this.mass,this.instance.friction=this.friction,this.instance.position.x=this.position.x,this.instance.position.y=this.position.y,this.instance.position.z=this.position.z,this.quaternion.axis.instance.x=this.quaternion.axis.x,this.quaternion.axis.instance.y=this.quaternion.axis.y,this.quaternion.axis.instance.z=this.quaternion.axis.z,this.instance.quaternion.setFromAxisAngle(this.quaternion.axis.instance,this.quaternion.angle),this.quaternion.x=this.instance.quaternion.x,this.quaternion.y=this.instance.quaternion.y,this.quaternion.z=this.instance.quaternion.z,this.quaternion.w=this.instance.quaternion.w,this.parentMesh.position.setFrom(this.position),this.parentMesh.quaternion.setFrom(this.quaternion),this.parentMesh.updateInstance(),this.instance.velocity.x=this.velocity.x,this.instance.velocity.y=this.velocity.y,this.instance.velocity.z=this.velocity.z,this.instance.angularVelocity.x=this.angularVelocity.x,this.instance.angularVelocity.y=this.angularVelocity.y,this.instance.angularVelocity.z=this.angularVelocity.z,this.instance.linearDamping=this.linearDamping,this.instance.angularDamping=this.angularDamping,this.instance.allowSleep=this.allowSleep,this.instance.sleepSpeedLimit=this.sleepSpeedLimit,this.instance.sleepTimeLimit=this.sleepTimeLimit,this.instance.collisionFilterGroup=this.collisionFilterGroup,this.instance.collisionFilterMask=this.collisionFilterMask,this.instance.fixedRotation=this.fixedRotation,this.instance.kinematic=this.kinematic},GameLib.D3.RigidBody.prototype.setFromParentMesh=function(){this.parentMesh&&this.parentMesh.instance||console.log("no parent mesh or instance"),this.instance.position.x=this.parentMesh.position.x,this.instance.position.y=this.parentMesh.position.y,this.instance.position.z=this.parentMesh.position.z,this.instance.quaternion.x=this.parentMesh.quater
returne.toApiObject()}),GameLib.Utils.IdOrNull(this.parentEntity))},GameLib.D3.Spline.FromObject=function(e,t){vari=GameLib.D3.API.Spline.FromObject(t);returnnewGameLib.D3.Spline(e,i)},GameLib.D3.Spline.prototype.getPointAt=function(e){vart=this.instance.getPointAt(e);returnnewGameLib.Vector3(this.graphics,newGameLib.API.Vector3(t.x,t.y,t.z),this,.1)},GameLib.D3.Stats=function(e,t,i,n,s){if(GameLib.Utils.UndefinedOrNull(e))thrownewError("Need Stats object");if(this.stats=e,GameLib.Utils.UndefinedOrNull(t)&&(t=GameLib.Utils.RandomId()),this.id=t,GameLib.Utils.UndefinedOrNull(i)&&(i="Stats ("+t+")"),this.name=i,GameLib.Utils.UndefinedOrNull(n))throwconsole.warn("Need a DOM element for stats"),newError("Need a DOM element for stats");this.domElement=n,GameLib.Utils.UndefinedOrNull(s)&&(s=null),this.parentEntity=s,GameLib.Component.call(this,GameLib.Component.COMPONENT_STATS,{domElement:GameLib.DomElement})},GameLib.D3.Stats.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.Stats.prototype.constructor=GameLib.D3.Stats,GameLib.D3.Stats.prototype.resize=function(){console.log("override stats resize per implementation")},GameLib.D3.Stats.prototype.createInstance=function(){this.instance=this.stats(),this.resize(),this.domElement.instance.parentElement.appendChild(this.instance.dom),GameLib.Component.prototype.createInstance.call(this)},GameLib.D3.Stats.prototype.updateInstance=function(){this.instance=newthis.stats},GameLib.D3.Stats.prototype.start=function(){this.instance.begin()},GameLib.D3.Stats.prototype.end=function(){this.instance.end()},GameLib.D3.Texture=function(e,t){if(this.graphics=e,this.graphics.isNotThreeThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),tinstanceofGameLib.D3.Texture)returnt;GameLib.D3.API.Texture.call(this,t.id,t.typeId,t.name,t.image,t.images,t.wrapS,t.wrapT,t.repeat,t.data,t.format,t.mapping,t.magFilter,t.minFilter,t.textureType,t.anisotropy,t.offset,t.generateMipmaps,t.flipY,t.mipmaps,t.unpackAlignment,t.premultiplyAlpha,t.encoding,t.canvas,t.animated,t.reverseAnimation,t.forward,t.parentEntity),this.offset=newGameLib.Vector2(this.graphics,this.offset,this),this.repeat=newGameLib.Vector2(this.graphics,this.repeat,this),this.imageinstanceofGameLib.D3.API.Image&&(this.image=newGameLib.D3.Image(this.graphics,this.image)),this.images=this.images.map(function(e){returneinstanceofGameLib.D3.API.Image?newGameLib.D3.Image(this.graphics,e):e}.bind(this)),this.canvasinstanceofGameLib.D3.API.Canvas&&(this.canvas=newGameLib.D3.Canvas(this.graphics,this.canvas)),GameLib.Component.call(this,GameLib.Component.COMPONENT_TEXTURE,{image:GameLib.D3.Image,images:[GameLib.D3.Image],canvas:GameLib.D3.Canvas})},GameLib.D3.Texture.prototype=Object.create(GameLib.D3.API.Texture.prototype),GameLib.D3.Texture.prototype.constructor=GameLib.D3.Texture,GameLib.D3.Texture.TYPE_ALPHA_FORMAT=1019,GameLib.D3.Texture.TYPE_RGB_FORMAT=1020,GameLib.D3.Texture.TYPE_RGBA_FORMAT=1021,GameLib.D3.Texture.TYPE_LUMINANCE_FORMAT=1022,GameLib.D3.Texture.TYPE_LUMINANCE_ALPHA_FORMAT=1023,GameLib.D3.Texture.TYPE_DEPTH_FORMAT=1026,GameLib.D3.Texture.TYPE_UV_MAPPING=300,GameLib.D3.Texture.TYPE_CUBE_REFLECTION_MAPPING=301,GameLib.D3.Texture.TYPE_CUBE_REFRACTION_MAPPING=302,GameLib.D3.Texture.TYPE_EQUI_RECTANGULAR_REFLECTION_MAPPING=303,GameLib.D3.Texture.TYPE_EQUI_RECTANGULAR_REFRACTION_MAPPING=304,GameLib.D3.Texture.TYPE_SPHERICAL_REFLECTION_MAPPING=305,GameLib.D3.Texture.TYPE_CUBE_UV_REFLECTION_MAPPING=306,GameLib.D3.Texture.TYPE_CUBE_UV_REFRACTION_MAPPING=307,GameLib.D3.Texture.TYPE_REPEAT_WRAPPING=1e3,GameLib.D3.Texture.TYPE_CLAMP_TO_EDGE_WRAPPING=1001,GameLib.D3.Texture.TYPE_MIRRORED_REPEAT_WRAPPING=1002,GameLib.D3.Texture.TYPE_NEAREST_FILTER=1003,GameLib.D3.Texture.TYPE_NEAREST_MIPMAP_NEAREST_FILTER=1004,GameLib.D3.Texture.TYPE_NEAREST_MIPMAP_LINEAR_FILTER=1005,GameLib.D3.Texture.TYPE_LINEAR_FILTER=1006,GameLib.D3.Texture.TYPE_LINEAR_MIPMAP_NEAREST_FILTER=1007,GameLib.D3.Texture.TYPE_LINEAR_MIPMAP_LINEAR_FILTER=1008,GameLib.D3.Texture.TYPE_UNSIGNED_BYTE=1009,GameLib.D3.Texture.TYPE_BYTE=1010,GameLib
if(e.texture.repeat.x>1||e.texture.repeat.x<0)returnconsole.warn("cannot animate a texture with repeat.x greater than 1 or less than 0"),void(e.texture.animated=!1);if(e.texture.repeat.y>1||e.texture.repeat.y<0)returnconsole.warn("cannot animate a texture with repeat.y greater than 1 or less than 0"),void(e.texture.animated=!1);this.textures[e.texture.id]=e.texture,this.textureIds=Object.keys(this.textures)}elseGameLib.Utils.UndefinedOrNull(this.textures[e.texture.id])?console.warn("tried to remove an animated texture, which should have been in the list but isnt: "+e.texture.name):(deletethis.textures[e.texture.id],this.textureIds=Object.keys(this.textures))},GameLib.System.Animation.prototype.animateTextureInstance=function(e){returne.texture.repeat.x>1||e.texture.repeat.x<0?(console.warn("cannot animate a texture with repeat.x greater than 1 or less than 0"),void(e.texture.userData.animated=!1)):e.texture.repeat.y>1||e.texture.repeat.y<0?(console.warn("cannot animate a texture with repeat.y greater than 1 or less than 0"),void(e.texture.userData.animated=!1)):(e.texture.userData.animated=!0,this.textures[e.texture.id]=e.texture,void(this.textureIds=Object.keys(this.textures)))},GameLib.System.Animation.prototype.beforeRender=function(e){if(!this.paused){vart=e.delta;for(variinthis.animations)if(this.animations.hasOwnProperty(i)){varn=[];if(this.animations[i].length>0)for(vars=!1,a=0;a<this.animations[i].length;a++)"rotation"!==this.animations[i][a].type||s||(s=!0,n.push(this.animations[i][a])),"position"===this.animations[i][a].type&&n.push(this.animations[i][a]),"scale"===this.animations[i][a].type&&n.push(this.animations[i][a]);n.map(function(e){returnfunction(i){varn=!1,s=0;if("rotation"===i.type&&(s=i.animation.rotationSpeed*t),"position"===i.type&&(s=i.animation.translationSpeed*t),"scale"===i.type&&(s=i.animation.scaleSpeed*t),i.from<i.to?i.from+=s:i.from-=s,Math.abs(i.from-i.to)<s?(i.mesh.instance[i.type][i.axis]=i.to,n=!0):i.mesh.instance[i.type][i.axis]=i.from,n){vara=this.animations[e].indexOf(i);this.animations[e].splice(a,1)}}.bind(this)}.bind(this)(i))}this.textureIds.map(function(e){vart=this.textures[e];t.reverseAnimation||t.userData&&t.userData.reverseAnimation?((!0===t.forward||t.userData&&!0===t.userData.forward)&&(t.offset.x+=t.repeat.x,t.offset.x>=1-t.repeat.x&&(t.offset.y>=1-t.repeat.y?(t.offset.x=1-t.repeat.x,t.offset.y=1-t.repeat.y,t.userData?t.userData.forward=!1:t.forward=!1):(t.offset.x=0,t.offset.y+=t.repeat.y))),(!1===t.forward||t.userData&&!1===t.userData.forward)&&(t.offset.x-=t.repeat.x,t.offset.x<=0&&(t.offset.x=0,t.offset.y<t.repeat.y?(t.offset.x=t.repeat.x,t.offset.y=0,t.userData?t.userData.forward=!0:t.forward=!0):(t.offset.x=1-t.repeat.x,t.offset.y-=t.repeat.y)))):(t.offset.x+=t.repeat.x,t.offset.x>=1-t.repeat.x&&(t.offset.y>=1-t.repeat.y?(t.offset.x=0,t.offset.y=0):(t.offset.x=0,t.offset.y+=t.repeat.y))),t.userData||t.updateInstance("offset")}.bind(this))}},GameLib.System.Animation.prototype.detachAnimation=function(e){vart=!1;e.backupQuaternionAngleDescriptor&&(Object.defineProperty(e.quaternion,"angle",e.backupQuaternionAngleDescriptor),deletee.backupQuaternionAngleDescriptor,t=!0),e.backupQuaternionAxisXDescriptor&&(Object.defineProperty(e.quaternion.axis,"x",e.backupQuaternionAxisXDescriptor),deletee.backupQuaternionAxisXDescriptor,t=!0),e.backupQuaternionAxisYDescriptor&&(Object.defineProperty(e.quaternion.axis,"y",e.backupQuaternionAxisYDescriptor),deletee.backupQuaternionAxisYDescriptor,t=!0),e.backupQuaternionAxisZDescriptor&&(Object.defineProperty(e.quaternion.axis,"z",e.backupQuaternionAxisZDescriptor),deletee.backupQuaternionAxisXDescriptor,t=!0),e.backupRotationXDescriptor&&(Object.defineProperty(e.rotation,"x",e.backupRotationXDescriptor),deletee.backupRotationXDescriptor,t=!0),e.backupRotationYDescriptor&&(Object.defineProperty(e.rotation,"y",e.backupRotationYDescriptor),deletee.backupRotationYDescriptor,t=!0),e.backupRotationZDescriptor&&(Object.defineProperty(e.rotation,"z",e.backupRotationZDescriptor),deletee.backupRotationZDescriptor,t=!0),e
e.component.parentWorld&&"string"==typeofe.component.parentWorld&&GameLib.EntityManager.Instance.queryComponents(GameLib.D3.PhysicsWorld).map(function(t){e.component.parentWorld===t.id&&(e.component.parentWorld=t,"function"==typeofe.component.instance.addToWorld&&(e.component.instance.addToWorld(t.instance),console.log("instance added to physics world")))})},GameLib.System.Linking.prototype.materialTypeChanged=function(e){GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Mesh).map(function(t){t.materials.reduce(function(t,i){returni===e.material&&(t=!0),t},!1)&&(1===t.materials.length?t.instance.material=t.materials[0].instance:t.instance.material=t.materials.map(function(e){returne.instance}),t.instance.geometry.uvsNeedUpdate=!0,t.instance.material.needsUpdate=!0)})},GameLib.System.Linking.prototype.onParentWorldChange=function(e){e.objectinstanceofGameLib.D3.RigidBody&&(e.originalWorldinstanceofGameLib.D3.PhysicsWorld&&e.originalWorld.removeRigidBody(e.object),e.newWorldinstanceofGameLib.D3.PhysicsWorld&&e.newWorld.addRigidBody(e.object))},GameLib.System.Linking.prototype.onParentSceneChange=function(e){if(e.objectinstanceofGameLib.D3.Mesh||e.objectinstanceofGameLib.D3.Light){vart=GameLib.EntityManager.Instance.findHelperByObject(e.object);t&&(e.originalScene&&e.originalScene.instance&&e.originalScene.instance.remove(t.instance),e.newScene.instance.add(t.instance)),e.originalScene&&e.originalScene.removeObject&&e.originalScene.removeObject(e.object),e.newScene&&e.newScene.addObject(e.object)}},GameLib.System.Linking.prototype.onParentEntityChange=function(e){e.originalEntityinstanceofGameLib.Entity&&e.originalEntity.removeComponent(e.object),e.newEntityinstanceofGameLib.Entity&&e.newEntity.addComponent(e.object),GameLib.Event.Emit(GameLib.Event.PARENT_ENTITY_CHANGED,{originalEntity:e.originalEntity,newEntity:e.newEntity,component:e.object})},GameLib.System.Linking.prototype.removeMesh=function(e){vart=e.meshes.reduce(function(e,t){returne.push(t),t.getChildrenComponents().map(function(t){e.push(t)}),e},[]),i=GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Mesh);i=i.filter(function(t){return-1===e.meshes.indexOf(t)});varn=i.reduce(function(e,t){returne.push(t),t.getChildrenComponents().map(function(t){e.push(t)}),e},[]);t=t.filter(function(e){return-1===n.indexOf(e)}),t.map(function(e){e.remove()})},GameLib.System.Linking.prototype.stop=function(){GameLib.System.prototype.stop.call(this),this.componentCreatedSubscription.remove(),this.componentClonedSubscription.remove(),this.registerDependenciesSubscription.remove(),this.componentRemoveSubscription.remove(),this.parentSceneChangeSubscription.remove(),this.parentWorldChangeSubscription.remove(),this.parentEntityChangeSubscription.remove(),this.instanceCreatedSubscription.remove(),this.instanceClonedSubscription.remove(),this.removeMeshSubscription.remove(),this.imageChangedSubscription.remove(),this.materialTypeChangedSubscription.remove(),this.arrayItemAddedSubscription.remove()},GameLib.System.Particle=function(e,t,i){this.graphics=e,this.graphics.isNotThreeThrow(),GameLib.System.call(this,i),this.engines=[],this.camera=t,this.totalTime=0,this.instanceCreatedSubscription=null,this.removeComponentSubscription=null,this.beforeRenderSubscription=null},GameLib.System.Particle.prototype=Object.create(GameLib.System.prototype),GameLib.System.Particle.prototype.constructor=GameLib.System.Particle,GameLib.System.Particle.prototype.start=function(){GameLib.System.prototype.start.call(this),this.particleEngines=GameLib.EntityManager.Instance.queryComponents(GameLib.D3.ParticleEngine),this.instanceCreatedSubscription=GameLib.Event.Subscribe(GameLib.Event.INSTANCE_CREATED,this.instanceCreated.bind(this)),this.removeComponentSubscription=GameLib.Event.Subscribe(GameLib.Event.REMOVE_COMPONENT,this.removeComponent.bind(this)),this.beforeRenderSubscription=GameLib.Event.Subscribe(GameLib.Event.BEFORE_RENDER,this.beforeRender.bind(this))},GameLib.System.Particle.prototype.instanceCreated=function(e){e.componentinstanceofGameLib.D3.ParticleEn