functionGameLib(){}var__DATE__="Mon Dec 04 2017 21:03:18 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.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.PAUSE_ALL_AUDIO=99,GameLib.Event.CONT
!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,{failed:n,saved:i}))}.bind(this));for(varainthis.idToObject)if(this.idToObject.hasOwnProperty(a)&&this.idToObject[a]instanceofGameLib.Component){vars=this.idToObject[a].toApiObject();t.push(s),this.publish(GameLib.Event.SAVE_COMPONENT,{apiObject:s,remote:e})}},GameLib.Component.Construct=function(e){vart=null,i=GameLib.Component.GetComponentInfo(e.componentType),n=i.constructor,a=n.FromObject,s=null;returnGameLib.Event.Emit(GameLib.Event.GET_RUNTIME,null,function(e){s=e}),e.componentType===GameLib.Component.ENTITY?t=a(e,GameLib.EntityManager.Instance):i.runtime===GameLib.Component.GRAPHICS_RUNTIME?(GameLib.Utils.UndefinedOrNull(s.graphics)&&console.warn("no runtime graphics"),t=a(s.graphics,e)):i.runtime===GameLib.Component.PHYSICS_RUNTIME?(GameLib.Utils.UndefinedOrNull(s.physics)&&console.warn("no runtime physics"),t=a(s.physics,e)):i.runtime===GameLib.Component.GUI_RUNTIME?(GameLib.Utils.UndefinedOrNull(s.gui)&&console.warn("no runtime gui"),t=a(s.gui,e)):i.runtime===GameLib.Component.SOCKET_RUNTIME?(GameLib.Utils.UndefinedOrNull(s.sockets)&&console.warn("no runtime sockets"),t=a(s.sockets,e)):i.runtime===GameLib.Component.STATISTICS_RUNTIME?(GameLib.Utils.UndefinedOrNull(s.statistics)&&console.warn("no runtime statistics"),t=a(s.statistics,e)):i.runtime===GameLib.Component.DEFAULT_RUNTIME?t=a(e):(console.log("unknown runtime object found : "+e.name),console.error(e)),t},GameLib.API.Canvas=function(e,t,i,n,a){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="Canvas ("+e+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=512),this.width=i,GameLib.Utils.UndefinedOrNull(n)&&(n=512),this.height=n,GameLib.API.Component.call(this,GameLib.Component.CANVAS,a)},GameLib.API.Canvas.prototype=Object.create(GameLib.Component.prototype),GameLib.API.Canvas.prototype.constructor=GameLib.API.Canvas,GameLib.API.Canvas.FromObject=function(e){returnnewGameLib.API.Canvas(e.id,e.name,e.width,e.height,e.parentEntity)},GameLib.API.Cast=function(e,t,i,n,a,s,o,r){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="Cast ("+this.id+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=GameLib.Cast.CAST_TYPE_ROOM),this.castType=i,GameLib.Utils.UndefinedOrNull(n)&&(n="default"),this.roomId=n,GameLib.Utils.UndefinedOrNull(a)&&(a=null),this.peer=a,GameLib.Utils.UndefinedOrNull(s)&&(s="127.0.0.1"),this.serverIp=s,GameLib.Utils.UndefinedOrNull(o)&&(o=80),this.port=o,GameLib.API.Component.call(this,GameLib.Component.CAST,r)},GameLib.API.Cast.prototype=Object.create(GameLib.Component.prototype),GameLib.API.Cast.prototype.constructor=GameLib.API.Cast,GameLib.API.Cast.FromObject=function(e){returnnewGameLib.API.Cast(e.id,e.name,e.castType,e.roomId,e.peer,e.serverIp,e.port,e.parentEntity)},GameLib.API.Clock=function(e,t,i){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="Clock ("+this.
this.scaleFn&&(this.instance.scale=newFunction("data",this.scaleFn).bind(this))}catch(e){console.error(e),this.publish(GameLib.Event.ANIMATION_COMPILE_FAILED,{component:this})}GameLib.Component.prototype.createInstance.call(this)},GameLib.D3.Animation.prototype.updateInstance=function(){try{this.rotationFn&&(this.instance.rotation=newFunction("data",this.rotationFn).bind(this),this.publish(GameLib.Event.ANIMATION_COMPILE_SUCCESS,{component:this,type:GameLib.D3.Animation.ANIMATION_FUNCTION_TYPE_ROTATION})),this.translationFn&&(this.instance.translation=newFunction("data",this.translationFn).bind(this),this.publish(GameLib.Event.ANIMATION_COMPILE_SUCCESS,{component:this,type:GameLib.D3.Animation.ANIMATION_FUNCTION_TYPE_TRANSLATION})),this.scaleFn&&(this.instance.scale=newFunction("data",this.scaleFn).bind(this),this.publish(GameLib.Event.ANIMATION_COMPILE_SUCCESS,{component:this,type:GameLib.D3.Animation.ANIMATION_FUNCTION_TYPE_SCALE}))}catch(e){console.error(e),this.publish(GameLib.Event.ANIMATION_COMPILE_FAILED,{component:this})}},GameLib.D3.Animation.prototype.toApiObject=function(){returnnewGameLib.D3.API.Animation(this.id,this.name,this.rotationSpeed,this.translationSpeed,this.scaleSpeed,this.rotationFn,this.translationFn,this.scaleFn,this.blocking,this.applyToMeshWhenDone,this.meshes.map(function(e){returnGameLib.Utils.IdOrNull(e)}),GameLib.Utils.IdOrNull(this.parentEntity))},GameLib.D3.Animation.FromObject=function(e){vart=GameLib.D3.API.Animation.FromObject(e);returnnewGameLib.D3.Animation(t)},GameLib.D3.Animation.prototype.launchEditor=function(){GameLib.Event.Emit(GameLib.Event.GET_RUNTIME,null,function(e){this.coder=e.coder,this.coder.isNotCodeMirrorThrow()}.bind(this));vare=null;this.functionType===GameLib.D3.Animation.ANIMATION_FUNCTION_TYPE_ROTATION&&(this.rotationFn="//when the animation is complete, return true\nreturn true;",e="rotationFn"),this.functionType===GameLib.D3.Animation.ANIMATION_FUNCTION_TYPE_TRANSLATION&&(this.translationFn="//when the animation is complete, return true\nreturn true;",e="translationFn"),this.functionType===GameLib.D3.Animation.ANIMATION_FUNCTION_TYPE_SCALE&&(this.scaleFn="//when the animation is complete, return true\nreturn true;",e="scaleFn"),e?(this.editor=this.coder.instance(document.body,{value:this[e],mode:"javascript",lineNumbers:!0,scrollbarStyle:"overlay"}),this.editor.on("change",function(){this[e]=this.editor.getValue(),this.updateInstance()}.bind(this))):console.warn("invalid function type selected")},GameLib.D3.Animation.prototype.closeEditor=function(){vare=this.editor.getWrapperElement();e.parentElement.removeChild(e)},GameLib.D3.Animation.prototype.addMesh=function(e){GameLib.Utils.PushUnique(this.meshes,e),GameLib.Event.Emit(GameLib.Event.ANIMATION_MESH_ADDED,{animation:this,mesh:e})},GameLib.D3.Animation.prototype.removeMesh=function(e){vart=this.meshes.indexOf(e);this.meshes.splice(t,1),GameLib.Event.Emit(GameLib.Event.ANIMATION_MESH_REMOVED,{animation:this,mesh:e})},GameLib.D3.Audio=function(e,t){if(this.graphics=e,this.graphics.isNotThreeThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),tinstanceofGameLib.D3.Audio)returnt;GameLib.D3.API.Audio.call(this,t.id,t.name,t.path,t.loop,t.volume,t.camera,t.overplay,t.pause,t.parentEntity),this.camerainstanceofGameLib.D3.API.Camera&&(this.camera=newGameLib.D3.Camera(this.graphics,this.camera)),GameLib.Component.call(this,{camera:GameLib.D3.Camera})},GameLib.D3.Audio.prototype=Object.create(GameLib.D3.API.Audio.prototype),GameLib.D3.Audio.prototype.constructor=GameLib.D3.Audio,GameLib.D3.Audio.prototype.createInstance=function(){if(GameLib.Utils.UndefinedOrNull(this.camera)||GameLib.Utils.UndefinedOrNull(this.camera.instance))returnvoidconsole.log("audio not ready to create instance");GameLib.Event.Emit(GameLib.Event.GET_API_URL,null,function(e){this.apiUrl=e.apiUrl}.bind(this));vare=newTHREE.AudioListener;this.camera.instance.add(e),this.instance=newTHREE.Audio(e),(newTHREE.AudioLoader).load(this.apiUrl+this.path+"?ts="+Date.now(),function(e){this.instance.setBuffer(e),this.instance.setLoop(
"rotation"!==e&&"quaternion"!==e&&"useQuaternion"!==e||this.updateInstanceRotation(),"parentMesh"===e&&this.parentMesh&&this.parentMesh.instance&&this.instance.parent!==this.parentMesh.instance&&(this.instance.parent=this.parentMesh.instance),"scale"===e&&this.updateInstanceScale(),"position"===e&&this.updateInstancePosition(),"up"===e&&(this.instance.up.x=this.up.x,this.instance.up.y=this.up.y,this.instance.up.z=this.up.z),"name"===e&&(this.instance.name=this.name),"materials"===e&&1===this.materials.length&&this.materials[0].instance&&(this.instance.material=this.materials[0].instance),"renderOrder"===e&&(this.instance.renderOrder=this.renderOrder),"visible"===e&&(this.instance.visible=this.visible),this.helper&&(this.removeHelper(),this.createHelper())},GameLib.D3.Mesh.prototype.updateVerticesFromGeometryInstance=function(e){if(this.vertices=[],this.faces=[],einstanceofTHREE.BufferGeometry){vart=e.getAttribute("position").array,i=e.getAttribute("uv").array;e.groups.map(function(e){for(varn=e.materialIndex,a=e.start,s=e.count,o=[],r=[],c=a;c<s;c++){varm=newGameLib.D3.Vertex(this.graphics,newGameLib.D3.API.Vertex(newGameLib.Vector3(this.graphics,newGameLib.API.Vector3(t[3*c],t[3*c+1],t[3*c+2])))),h=newGameLib.Vector2(this.graphics,newGameLib.API.Vector2(i[2*c],i[2*c+1]));r.push(h);varl=this.vertices.reduce(function(e,t,i){returnt.position.equals(m.position)&&(e=i),e},-1),p=l;-1===l&&(this.vertices.push(m),p=this.vertices.length-1),o.push(p),3===o.length&&(this.faces.push(newGameLib.D3.Face(this.graphics,newGameLib.D3.API.Face(null,null,o[0],o[1],o[2],n,[[r[0],r[1],r[2]]]))),r=[],o=[])}}.bind(this)),console.log("todo : update vertices from buffer geometry")}else{varn=0;e.faces.map(function(t,i){n++,n%100==0&&console.log("processed "+n+" faces"),this.faces.push(newGameLib.D3.Face(this.graphics,newGameLib.D3.API.Face(null,null,t.a,t.b,t.c,t.materialIndex,[[newGameLib.API.Vector2(e.faceVertexUvs[0][i][0].x,e.faceVertexUvs[0][i][0].y),newGameLib.API.Vector2(e.faceVertexUvs[0][i][1].x,e.faceVertexUvs[0][i][1].y),newGameLib.API.Vector2(e.faceVertexUvs[0][i][2].x,e.faceVertexUvs[0][i][2].y)]],newGameLib.Color(this.graphics,newGameLib.API.Color(t.color.r,t.color.g,t.color.b)),t.vertexColors.map(function(e){returnnewGameLib.Color(this.graphics,newGameLib.API.Color(e.r,e.g,e.b))}.bind(this)),t.vertexNormals.map(function(e){returnnewGameLib.Vector3(this.graphics,newGameLib.API.Vector3(e.x,e.y,e.z))}.bind(this)),newGameLib.Vector3(this.graphics,newGameLib.API.Vector3(t.normal.x,t.normal.y,t.normal.z)))))}.bind(this)),n=0,e.vertices.map(function(e){n++,n%100==0&&console.log("processed "+n+" vertices"),this.vertices.push(newGameLib.D3.Vertex(this.graphics,newGameLib.D3.API.Vertex(newGameLib.Vector3(this.graphics,newGameLib.API.Vector3(e.x,e.y,e.z)))))}.bind(this))}},GameLib.D3.Mesh.prototype.applyBones=function(e){this.skinIndices.map(function(t){e.skinIndices.push(newTHREE.Vector4(t.x,t.y,t.z,t.w))}),this.skinWeights.map(function(t){e.skinWeights.push(newTHREE.Vector4(t.x,t.y,t.z,t.w))})},GameLib.D3.Mesh.prototype.addChild=function(e,t){if(!this.instance)thrownewError("mesh instance not loaded yet : "+this.name);if(GameLib.Utils.UndefinedOrNull(e))thrownewError("no child mesh instance");if(GameLib.Utils.UndefinedOrNull(t))thrownewError("no child mesh");this.instance.add(e),e.parent=this.instance,t.parentMesh=this},GameLib.D3.Mesh.prototype.setParentMesh=function(e){if(GameLib.Utils.UndefinedOrNull(e)){if(!(this.instance&&this.instance.parent&&this.parentScene.instance))thrownewError("Not enough information to detach");this.instance.parent.updateMatrixWorld();vart=newTHREE.Vector3;t.setFromMatrixPosition(this.instance.matrixWorld),THREE.SceneUtils.detach(this.instance,this.instance.parent,this.parentScene.instance),this.parentMesh=null,this.position.x=t.x,this.position.y=t.y,this.position.z=t.z,this.updateInstancePosition()}else{if(!this.instance)thrownewError("No valid instance at time of adding to parent for mesh "+this.name);if(!(einstanceofGameLib.D3.Mesh))thrownewError("Nota
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.name,this.position.toApiObject(),this.direction.toApiObject(),this.enabled,GameLib.Utils.IdOrNull(this.templateParticle),this.particlesPerSecond,this.frequency,this.elapsed,GameLib.Utils.IdOrNull(this.camera),this.pulse,GameLib.Utils.IdOrNull(this.parentEntity))},GameLib.D3.ParticleEngine.FromObject=function(e,t){vari=GameLib.D3.API.ParticleEngine.FromObject(t);returnnewGameLib.D3.ParticleEngine(e,i)},GameLib.D3.Particle=function(e,t){if(this.graphics=e,this.graphics.isNotThreeThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),tinstanceofGameLib.D3.Particle)returnt;if(GameLib.D3.API.Particle.call(this,t.id,t.name,t.lifeTime,t.elapsed,t.mesh,t.opacityType,t.opacityFactor,t.positionOffsetType,t.positionOffset,t.positionOffsetFn,t.directionType,t.direction,t.directionFn,t.speedType,t.speed,t.scaleType,t.scale,t.scaleFn,t.rotationType,t.rotation,t.rotationFn,t.parentEngine,t.parentEntity),this.meshinstanceofGameLib.D3.API.Mesh&&(this.mesh=newGameLib.D3.Mesh(e,this.mesh)),!(this.positionOffsetinstanceofGameLib.API.Vector3))throwconsole.warn("positionOffset not instance of API.Vector3"),newError("positionOffset not instance of API.Vector3");if(this.positionOffset=newGameLib.Vector3(e,this.positionOffset,this),!(this.directioninstanceofGameLib.API.Vector3))throwconsole.warn("direction not instance of API.Vector3"),newError("direction not instance of API.Vector3");if(this.direction=newGameLib.Vector3(e,this.direction,this),!(this.scaleinstanceofGameLib.API.Vector3))throwconsole.warn("scale not instance of API.Vector3"),newError("scale not instance of API.Vector3");if(this.scale=newGameLib.Vector3(e,this.scale,this),!(this.rotationinstanceofGameLib.API.Vector3))throwconsole.warn("rotation not instance of API.Vector3"),newError("rotation not instance of API.Vector3");this.rotation=newGameLib.Vector3(e,this.rotation,this),GameLib.Component.call(this,{mesh:GameLib.D3.Mesh,parentEngine:GameLib.D3.ParticleEngine})},GameLib.D3.Particle.prototype=Object.create(GameLib.D3.API.Particle.prototype),GameLib.D3.Particle.prototype.constructor=GameLib.D3.Particle,GameLib.D3.Particle.OPACITY_TYPE_CONSTANT=1,GameLib.D3.Particle.OPACITY_TYPE_DECREASE_LINEAR=2,GameLib.D3.Particle.OPACITY_TYPE_INCREASE_LINEAR=3,GameLib.D3.Particle.POSITION_OFFSET_TYPE_CONSTANT=1,GameLib.D3.Particle.POSITION_OFFSET_TYPE_RANDOM=2,GameLib.D3.Particle.POSITION_OFFSET_TYPE_FUNCTION=3,GameLib.D3.Particle.DIRECTION_TYPE_CONSTANT=1,GameLib.D3.Particle.DIRECTION_TYPE_RANDOM=2,GameLib.D3.Particle.DIRECTION_TYPE_RANDOM_NORMALIZED=3,GameLib.D3.Particle.DIRECTION_TYPE_FUNCTION=4,Game
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.D3.Renderer.FromObject=function(e,t){vari=GameLib.D3.API.Renderer.FromObject(t);returnnewGameLib.D3.Renderer(e,i)},GameLib.D3.Renderer.prototype.render=function(e,t){this.instance&&(GameLib.Utils.UndefinedOrNull(t)&&(t=this.scenes),this.viewports.length>1&&(this.instance.autoClear=!1),t.length>1&&(this.instance.autoClear=!1),this.instance.clear(),this.bufferScene&&this.bufferScene.instance&&this.bufferCamera&&this.bufferCamera.instance&&this.renderTarget&&this.renderTarget.instance&&this.instance.render(this.bufferScene.instance,this.bufferCamera.instance,this.renderTarget.instance),this.viewports.map(function(e){this.instance.setViewport(e.x*this.width,e.y*this.height,e.width*this.width,e.height*this.height),t.map(function(e){e.instance&&(this.camera.instance||e.renderCamera||e.renderCamera.instance)&&(e.renderCamera&&e.renderCamera.instance?this.instance.render(e.instance,e.renderCamera.instance):this.instance.render(e.instance,this.camera.instance))}.bind(this))}.bind(this)))},GameLib.D3.Renderer.prototype.setSize=function(e,t){this.width=e,this.height=t,this.instance?this.instance.setSize(this.width,this.height):console.log("renderer not ready to set size")},GameLib.D3.RigidBody=function(e,t){if(this.physics=e,this.physics.isNotCannonThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),tinstanceofGameLib.D3.RigidBody)returnt;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.parentPhysicsWorld,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,{shapes:[GameLib.D3.Shape],parentMesh:GameLib.D3.Mesh,parentPhysicsWorld: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,
i.vertices.push(newGameLib.D3.API.Vertex(newGameLib.API.Vector3(n.x,n.y,n.z)),newGameLib.D3.API.Vertex(newGameLib.API.Vector3(a.x,a.y,a.z)),newGameLib.D3.API.Vertex(newGameLib.API.Vector3(s.x,s.y,s.z)));varm=i.vertices.length-3;i.faces.push(newGameLib.D3.API.Face(null,null,m,m+1,m+2))}newGameLib.D3.Mesh(this.graphics,i)},GameLib.System.Visualization.prototype.stopVisualize=function(e){},GameLib.System.Visualization.prototype.stop=function(){GameLib.System.prototype.stop.call(this),this.visualizationSubscription&&this.visualizationSubscription.remove(),this.stopVisualizationSubscription&&this.stopVisualizationSubscription.remove()},GameLib.Vector2=function(e,t,i,n){if(this.graphics=e,this.graphics.isNotThreeThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={},t={}),tinstanceofGameLib.Vector2)returnt;GameLib.API.Vector2.call(this,t.x,t.y),GameLib.Utils.UndefinedOrNull(i)&&(i=null),this.parentObject=i,GameLib.Utils.UndefinedOrNull(n)&&(n=.001),this.grain=n,this.createInstance()},GameLib.Vector2.prototype=Object.create(GameLib.API.Vector2.prototype),GameLib.Vector2.prototype.constructor=GameLib.Vector2,GameLib.Vector2.prototype.createInstance=function(){this.instance=newTHREE.Vector2(this.x,this.y)},GameLib.Vector2.prototype.updateInstance=function(e){this.instance.x=this.x,this.instance.y=this.y,this.parentObject&&this.parentObject.updateInstance&&this.parentObject.updateInstance(e)},GameLib.Vector2.prototype.toApiObject=function(){returnnewGameLib.API.Vector2(this.x,this.y)},GameLib.Vector2.prototype.copy=function(e){returnGameLib.Utils.UndefinedOrNull(e)?newGameLib.Vector2(this.graphics,newGameLib.API.Vector2(this.x,this.y),this.parentObject,this.grain):(this.x=e.x,this.y=e.y,this)},GameLib.Vector2.prototype.equals=function(e){returnthis.x==e.x&&this.y==e.y},GameLib.Vector2.prototype.add=function(e){if(!(einstanceofGameLib.API.Vector2||einstanceofGameLib.API.Vector3||einstanceofGameLib.API.Vector4||einstanceofGameLib.API.Quaternion))throwconsole.warn("Could not add Vector2"),newError("Could not add Vector2");this.x+=e.x,this.y+=e.y},GameLib.Vector2.prototype.subtract=function(e){if(!(einstanceofGameLib.API.Vector2||einstanceofGameLib.API.Vector3||einstanceofGameLib.API.Vector4||einstanceofGameLib.API.Quaternion))throwconsole.warn("Could not subtract Vector2"),newError("Could not subtract Vector2");this.x-=e.x,this.y-=e.y},GameLib.Vector2.prototype.multiply=function(e){if(einstanceofGameLib.API.Vector2||einstanceofGameLib.API.Vector3||einstanceofGameLib.API.Vector4||einstanceofGameLib.API.Quaternion)this.x*=e.x,this.y*=e.y;else{if("number"!=typeofe)throwconsole.warn("Could not multiply Vector2"),newError("Could not multiply Vector2");this.x*=e,this.y*=e}},GameLib.Vector2.prototype.divide=function(e){if(einstanceofGameLib.API.Vector2||einstanceofGameLib.API.Vector3||einstanceofGameLib.API.Vector4||einstanceofGameLib.API.Quaternion)this.x*=1/e.x,this.y*=1/e.y;else{if("number"!=typeofe)throwconsole.warn("Could not divide Vector2"),newError("Could not divide Vector2");this.x*=1/e,this.y*=1/e}},GameLib.Vector2.prototype.clamp=function(e,t){returnthis.x=Math.max(e.x,Math.min(t.x,this.x)),this.y=Math.max(e.y,Math.min(t.y,this.y)),this},GameLib.Vector2.prototype.length=function(){returnMath.sqrt(this.x*this.x+this.y*this.y)},GameLib.Vector2.prototype.dot=function(e){returnthis.x*e.x+this.y*e.y},GameLib.Vector2.prototype.normalize=function(){returnthis.multiply(1/this.length())},GameLib.Vector2.prototype.angle=function(){vare=Math.atan2(this.y,this.x);returne<0&&(e+=2*Math.PI),e},GameLib.Vector2.prototype.lerp=function(e,t){returnnewGameLib.Vector2(this.x+(e.x-this.x)*t,this.y+(e.y-this.y)*t)},GameLib.Vector3=function(e,t,i,n){if(this.implementation=e,einstanceofGameLib.GraphicsRuntime)this.physics=null,this.graphics=e,this.graphics.isNotThreeThrow();else{if(!(einstanceofGameLib.PhysicsRuntime))thrownewError("Unhandled implementation : "+e);this.graphics=null,this.physics=e,this.physics.isNotCannonThrow()}if(GameLib.Utils.UndefinedOrNull(t)&&(t={}),tinstanceof