From 70ebe7a5ec112459f1db0f85201a3304c18d9658 Mon Sep 17 00:00:00 2001 From: -=yb4f310 Date: Mon, 4 Dec 2017 13:23:15 +0100 Subject: [PATCH] start with linked objects --- {src => bak}/game-lib-dom.js | 0 build/game-lib-min.js | 28 +- build/game-lib.js | 5331 ++++++++--------- src/game-lib-a-2-utils.js | 15 + src/game-lib-a-api-component.js | 3 +- src/game-lib-a-component-a.js | 427 +- src/game-lib-api-canvas.js | 9 +- src/game-lib-api-cast.js | 9 +- src/game-lib-api-clock.js | 9 +- src/game-lib-api-controls.js | 30 +- src/game-lib-api-custom-code.js | 10 +- src/game-lib-api-dom-element.js | 9 +- src/game-lib-api-entity-manager.js | 13 +- src/game-lib-api-entity.js | 9 +- src/game-lib-api-gui.js | 72 + src/game-lib-api-image.js | 9 +- src/game-lib-api-mouse.js | 11 +- src/game-lib-api-stats.js | 64 + src/game-lib-api-system.js | 63 +- src/game-lib-canvas.js | 5 +- src/game-lib-cast.js | 1 - src/game-lib-clock.js | 6 +- src/game-lib-controls-0.js | 19 +- ...itor.js => game-lib-controls-d3-editor.js} | 20 +- src/game-lib-custom-code.js | 5 +- src/game-lib-d3-api-animation.js | 9 +- src/game-lib-d3-api-audio.js | 10 +- src/game-lib-d3-api-bone.js | 16 +- src/game-lib-d3-api-broadphase.js | 9 +- src/game-lib-d3-api-camera.js | 19 +- src/game-lib-d3-api-composer.js | 9 +- src/game-lib-d3-api-fog.js | 10 +- src/game-lib-d3-api-font.js | 9 +- ...me-lib-d3-api-friction-contact-material.js | 12 +- src/game-lib-d3-api-friction-material.js | 9 +- src/game-lib-d3-api-light.js | 9 +- src/game-lib-d3-api-material.js | 9 +- src/game-lib-d3-api-mesh.js | 82 +- src/game-lib-d3-api-particle-engine.js | 9 +- src/game-lib-d3-api-particle.js | 9 +- src/game-lib-d3-api-pass.js | 9 +- src/game-lib-d3-api-physics-world.js | 10 +- src/game-lib-d3-api-raycast-vehicle.js | 21 +- src/game-lib-d3-api-raycast-wheel.js | 19 +- src/game-lib-d3-api-raycaster.js | 13 +- src/game-lib-d3-api-render-target.js | 18 +- src/game-lib-d3-api-renderer.js | 10 +- src/game-lib-d3-api-rigid-body.js | 21 +- src/game-lib-d3-api-scene.js | 9 +- src/game-lib-d3-api-shape.js | 86 +- src/game-lib-d3-api-skeleton.js | 11 +- src/game-lib-d3-api-solver.js | 18 +- src/game-lib-d3-api-spline.js | 11 +- src/game-lib-d3-api-texture.js | 112 +- src/game-lib-d3-api-viewport.js | 9 +- src/game-lib-d3-api-z-animation.js | 1 - src/game-lib-d3-audio.js | 1 - src/game-lib-d3-bone.js | 11 +- src/game-lib-d3-broadphase.js | 5 +- src/game-lib-d3-camera.js | 10 +- src/game-lib-d3-composer.js | 1 - src/game-lib-d3-fog.js | 5 +- src/game-lib-d3-font.js | 5 +- src/game-lib-d3-friction-contact-material.js | 1 - src/game-lib-d3-friction-material.js | 5 +- src/game-lib-d3-helper.js | 4 +- src/game-lib-d3-light.js | 1 - src/game-lib-d3-material.js | 1 - src/game-lib-d3-mesh-0.js | 56 +- src/game-lib-d3-mesh-box.js | 6 +- src/game-lib-d3-mesh-curve.js | 10 + src/game-lib-d3-mesh-cylinder.js | 8 +- src/game-lib-d3-mesh-line.js | 6 +- src/game-lib-d3-mesh-plane.js | 8 +- src/game-lib-d3-mesh-sphere.js | 8 +- src/game-lib-d3-mesh-text.js | 8 +- src/game-lib-d3-particle-engine.js | 1 - src/game-lib-d3-particle.js | 1 - src/game-lib-d3-pass.js | 1 - src/game-lib-d3-physics-world.js | 11 +- src/game-lib-d3-raycast-vehicle.js | 13 +- src/game-lib-d3-raycast-wheel.js | 9 +- src/game-lib-d3-raycaster.js | 8 +- src/game-lib-d3-render-target.js | 1 - src/game-lib-d3-renderer.js | 1 - src/game-lib-d3-rigid-body.js | 7 +- src/game-lib-d3-scene.js | 1 - src/game-lib-d3-shape-0.js | 38 +- src/game-lib-d3-shape-box.js | 10 + src/game-lib-d3-shape-convex-hull-0.js | 4 +- src/game-lib-d3-shape-convex-hull-cylinder.js | 10 + src/game-lib-d3-shape-height-map.js | 10 + src/game-lib-d3-shape-plane.js | 10 + src/game-lib-d3-shape-sphere.js | 10 + src/game-lib-d3-shape-tri-mesh.js | 10 + src/game-lib-d3-skeleton.js | 6 +- src/game-lib-d3-solver.js | 20 +- src/game-lib-d3-spline.js | 5 +- src/game-lib-d3-stats.js | 84 - src/game-lib-d3-texture.js | 90 +- src/game-lib-d3-viewport.js | 5 +- src/game-lib-dom-element.js | 5 +- src/game-lib-entity-manager.js | 171 +- src/game-lib-entity.js | 3 - src/game-lib-gui.js | 90 +- src/game-lib-image.js | 7 +- src/game-lib-mouse.js | 5 +- src/game-lib-stats.js | 107 + src/game-lib-system-0.js | 46 +- src/game-lib-system-animation.js | 4 +- src/game-lib-system-custom-code.js | 2 +- src/game-lib-system-gui.js | 153 +- src/game-lib-system-input.js | 22 +- src/game-lib-system-linking.js | 30 +- src/game-lib-system-particle.js | 2 +- src/game-lib-system-physics.js | 8 +- src/game-lib-system-render.js | 6 +- src/game-lib-system-storage.js | 31 +- 118 files changed, 4013 insertions(+), 3990 deletions(-) rename {src => bak}/game-lib-dom.js (100%) create mode 100644 src/game-lib-api-gui.js create mode 100644 src/game-lib-api-stats.js rename src/{game-lib-d3-controls-editor.js => game-lib-controls-d3-editor.js} (80%) delete mode 100644 src/game-lib-d3-stats.js create mode 100644 src/game-lib-stats.js diff --git a/src/game-lib-dom.js b/bak/game-lib-dom.js similarity index 100% rename from src/game-lib-dom.js rename to bak/game-lib-dom.js diff --git a/build/game-lib-min.js b/build/game-lib-min.js index dd860b9..7199492 100644 --- a/build/game-lib-min.js +++ b/build/game-lib-min.js @@ -1,14 +1,14 @@ -function GameLib(){}var __DATE__="Fri Dec 01 2017 17:42:45 GMT+0100 (CET)";if(void 0===GameLib.D3&&(GameLib.D3=function(){}),void 0===GameLib.D3.API&&(GameLib.D3.API=function(){}),void 0===GameLib.API&&(GameLib.API=function(){}),void 0===GameLib.D3.Runtime&&(GameLib.D3.Runtime=function(){}),void 0===Q){if("undefined"==typeof require)throw console.warn("You need the Q promise library for the GameLib.D3"),new Error("You need the Q promise library for the GameLib.D3");var Q=require("q")}if(void 0===_){if("undefined"==typeof require)throw console.warn("You need the lodash library for the GameLib.D3"),new Error("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_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.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.CONTINUE_ALL_AUDIO=100,GameLib.Event.MUTE_AUDIO=101,GameLib.Event.GAME_STARTED=102,GameLib.Event.GAME_PAUSED=103,GameLib.Event.GAME_RESUMED=104,GameLib.Event.CUSTOM_GAME_START=105,GameLib.Event.AUDIO_MUTED=106,GameLib.Event.AUDIO_UNMUTED=107,GameLib.Event.GetEventName=function(e){switch(e){case 1:return"window_resize";case 2:return"parent_scene_change";case 3:return"parent_entity_change";case 4:return"instance_cloned";case 5:return"load_image";case 6:return"new_entity";case 7:return"material_type_changed";case 8:return"save_component";case 9:return"save_component_error";case 10:return"component_saved";case 11:return"load_component";case 12:return"load_component_error";case 13:return"logged_in";case 14:return"component_created";case 15:return"component_cloned";case 16:return"texture_animated_change";case 17:return"animate_texture_instance";case 18:return"remove_particle_engine";case 19:return"pause";case 20:return"texture_instance_updated";case 21:return"play_audio";case 22:return"material_instance_updated";case 23:return"pause_audio";case 24:return"mesh_instance_updated";case 25:return"stop_audio";case 26:return"light_instance_updated";case 27:return"delete_component";case 28:return"component_download_complete";case 29:return"components_linked";case 30:return"unresolved_dependencies_update";case 31:return"register_update";case 32:return"build_gui";case 33:return"remove_mesh";case 34:return"mesh_selected";case 35:return"mesh_deselected";case 36:return"component_register";case 37:return"image_not_found";case 38:return"blender_data_received";case 39:return"image_upload_complete";case 40:return"remove_component";case 41:return"key_down";case 42:return"key_up";case 43:return"render";case 44:return"event_list";case 45:return"compile_success";case 46:return"compile_failed";case 47:return"image_changed";case 48:return"parent_entity_changed";case 49:return"material_textures_updated";case 50:return"delete_component_error";case 51:return"component_deleted";case 52:return"component_types_updated";case 53:return"audio_ended";case 54:return"component_linked";case 55:return"done_saving";case 56:return"before_render";case 57:return"after_render";case 58:return"array_item_added";case 59:return"instance_created";case 60:return"visualize";case 61:return"stop_visualize";case 62:return"fetch_component_types";case 63:return"fetch_components";case 64:return"get_api_url";case 65:return"get_runtime";case 66:return"parent_world_change";case 67:return"animate";case 68:return"animation_compile_success";case 69:return"animation_compile_failed";case 70:return"saving";case 71:return"game_over";case 72:return"game_start";case 73:return"touch_start";case 74:return"touch_end";case 75:return"touch_move";case 76:return"touch_cancel";case 77:return"get_remote_api_url";case 78:return"unused";case 79:return"delayed_instance_encountered";case 80:return"unused";case 81:return"animation_mesh_added";case 82:return"animation_mesh_removed";case 83:return"get_scene";case 84:return"custom_code_window_resize";case 85:return"load_font";case 86:return"font_not_found";case 87:return"stop_all_audio";case 88:return"register_dependencies";case 89:return"game_loaded";case 90:return"unused";case 91:return"load_progress";case 92:return"entity_loaded";case 93:return"mouse_down";case 94:return"mouse_move";case 95:return"mouse_wheel";case 96:return"mouse_up";case 97:return"particle_instance_updated";case 98:return"game_data";case 99:return"pause_all_audio";case 100:return"continue_all_audio";case 101:return"mute_audio";case 102:return"game_started";case 103:return"game_paused";case 104:return"game_resumed";case 105:return"custom_game_start";case 106:return"audio_muted";case 107:return"audio_unmuted"}throw new error("unknown event id: "+e)},GameLib.Event.prototype.subscribe=function(e,t){return GameLib.Event.Subscribe(e,t.bind(this))},GameLib.Event.prototype.publish=function(e,t,i,n){return GameLib.Event.Emit(e,t,i,n)},GameLib.Event.Emit=function(e,t,i,n){var a=0;return GameLib.Event.Subscriptions.hasOwnProperty(e)?(0===GameLib.Event.Subscriptions[e].length&&(i&&i(),n&&n({message:"No subscriptions for event "+e})),GameLib.Event.Subscriptions[e].map(function(e){e&&(e(t,i,n),a++)})):(i&&i(),n&&n({message:"No subscriptions for event "+e})),a},GameLib.Event.Subscribe=function(e,t){return GameLib.Event.Subscriptions.hasOwnProperty(e)?GameLib.Event.Subscriptions[e].push(t):(GameLib.Event.Subscriptions[e]=[],GameLib.Event.Subscriptions[e].push(t)),{fn:t,remove:function(){var i=GameLib.Event.Subscriptions[e].indexOf(t);if(-1===i)throw new Error("could not remove subscription");GameLib.Event.Subscriptions[e].splice(i,1)}}},GameLib.Utils=function(){},GameLib.Utils.StripImageExtension=function(e){return e.replace(/(\.png$|\.gif$|\.jpeg$|\.jpg$)/,"")},GameLib.Utils.ObjectIdWithNameInArray=function(e,t){return t.reduce(function(t,i){return t||(e===i.name?i.id:null)},null)},GameLib.Utils.LoadIdsFromArrayToIdObject=function(e,t){},GameLib.Utils.LoadIdsFromObjectToIdObject=function(e,t){},GameLib.Utils.GetRandomInt=function(e,t){return e=Math.ceil(e),t=Math.floor(t),Math.floor(Math.random()*(t-e))+e},GameLib.Utils.GetRandomIntInclusive=function(e,t){return e=Math.ceil(e),t=Math.floor(t),Math.floor(Math.random()*(t-e+1))+e},GameLib.Utils.InterpolateArray=function(e,t){var i=[],n=Number((e.length-1)/(t-1));i[0]=e[0];for(var a=1;aMath.PI;)e-=2*Math.PI;for(;e<-Math.PI;)e+=2*Math.PI;i=e}}},GameLib.Utils.IdArrayOrEmptyArray=function(e){return GameLib.Utils.UndefinedOrNull(e)?[]:e.map(function(e){if(GameLib.Utils.UndefinedOrNull(e.id))throw new Error("No ID found while trying to store IDs to array");return e.id})},GameLib.Utils.Link=function(e,t,i,n){GameLib.Utils.UndefinedOrNull(i[e])||(t.hasOwnProperty(n)||console.warn("Linking failed for object:"+i.name),i[e]=t[n])},GameLib.Utils.RandomId=function(e){return GameLib.Utils.UndefinedOrNull(e)&&(e=10),Math.random().toString(36).substr(2,e)},GameLib.Utils.InvertWindingOrder=function(e){for(var t=0;t0;){var a=i.pop();if(a.triangle.v0index===a.edge.x&&a.triangle.v1index===a.edge.y||a.triangle.v1index===a.edge.x&&a.triangle.v2index===a.edge.y||a.triangle.v2index===a.edge.x&&a.triangle.v0index===a.edge.y){var s=a.triangle.v1index;a.triangle.v1index=a.triangle.v2index,a.triangle.v2index=s;var o=a.triangle.uvs[0][1];a.triangle.uvs[0][1]=a.triangle.uvs[0][2],a.triangle.uvs[0][2]=o}n.push(a);for(var r=[new GameLib.API.Vector2(a.triangle.v0index,a.triangle.v1index),new GameLib.API.Vector2(a.triangle.v1index,a.triangle.v2index),new GameLib.API.Vector2(a.triangle.v2index,a.triangle.v0index)],c=0;c9||console.log("The vertices are not in the right length : "+e.length);for(var i=[],n=new GameLib.API.Quaternion.Points,a=0;ae&&t.splice(0,1);var n=0;for(var a in t)n+=t[a];var s=e;return t.lengthe.length&&(i=t,t=e,e=i),e.filter(function(e){return t.indexOf(e)>-1}).filter(function(e,t,i){return i.indexOf(e)===t})},GameLib.Utils.Difference=function(e,t){var i;return t.length>e.length&&(i=t,t=e,e=i),e.filter(function(e){return-1===t.indexOf(e)}).filter(function(e,t,i){return i.indexOf(e)===t})},GameLib.Utils.PushUnique=function(e,t){-1===e.indexOf(t)&&e.push(t)},GameLib.Utils.IsEmpty=function(e){return 0===Object.keys(e).length&&e.constructor===Object},GameLib.Utils.isString=function(e){return"string"==typeof e},GameLib.Utils.isBoolean=function(e){return!0===e||!1===e},GameLib.Utils.isColor=function(e){return e instanceof GameLib.Color},GameLib.Utils.isNumber=function(e){return"number"==typeof e},GameLib.Utils.isVector2=function(e){return e instanceof GameLib.API.Vector2||e instanceof GameLib.Vector2},GameLib.Utils.isVector3=function(e){return e instanceof GameLib.API.Vector3||e instanceof GameLib.Vector3},GameLib.Utils.isVector4=function(e){return e instanceof GameLib.API.Vector4||e instanceof GameLib.Vector4||e instanceof GameLib.API.Quaternion||e instanceof GameLib.Quaternion},GameLib.Utils.LowerUnderscore=function(e){return e.toLowerCase().replace(/\s+/,"_")},GameLib.Utils.UpperCaseWordsSpaces=function(e){return e.replace(/[-_]/g," ").split(" ").reduce(function(e,t){return(e+=t[0].toUpperCase()+t.substr(1))+" "},"").trim()},GameLib.API.Component=function(e,t){this.componentType=e,GameLib.Utils.UndefinedOrNull(t)&&(t=null),this.parentEntity=t},GameLib.API.Component.prototype=Object.create(GameLib.Event.prototype),GameLib.API.Component.prototype.constructor=GameLib.API.Component,GameLib.Component=function(e,t,i){GameLib.Utils.UndefinedOrNull(t)&&(t={}),this.linkedObjects=t,this.linkedObjects.parentEntity=GameLib.Entity,GameLib.API.Component.call(this,e,this.parentEntity),this.idToObject={},this.selected=!1,this.building=!1,this.loaded=!1,this.linked=!1,this.cloneNumber=0,this.isClone=!1,GameLib.Utils.UndefinedOrNull(i)&&(i=!1),this.delayed=i,this.dependencies=this.getDependencies(),GameLib.Event.Emit(GameLib.Event.COMPONENT_REGISTER,{component:this}),0===this.dependencies.length?this.performInstanceCreation():GameLib.Event.Emit(GameLib.Event.REGISTER_DEPENDENCIES,{component:this})},GameLib.Component.prototype=Object.create(GameLib.API.Component.prototype),GameLib.Component.prototype.constructor=GameLib.Component,GameLib.Component.prototype.performInstanceCreation=function(){var e=!0;if(GameLib.Utils.UndefinedOrNull(this.dependencies)&&(e=!1),this.dependencies&&this.dependencies instanceof Array&&0===this.dependencies.length&&(e=!1),e)throw new Error("performInstanceCreation called while this object still has dependencies");if(delete this.dependencies,this.buildIdToObject(),this.linked)if(this.delayed)GameLib.Event.Emit(GameLib.Event.DELAYED_INSTANCE_ENCOUNTERED,{component:this});else try{this.createInstance()}catch(e){console.error(e)}},GameLib.Component.prototype.createInstance=function(){this.delayed=!1,this.instance&&(this.loaded=!0,GameLib.Event.Emit(GameLib.Event.INSTANCE_CREATED,{component:this})),this instanceof GameLib.Entity&&GameLib.Event.Emit(GameLib.Event.ENTITY_LOADED,{entity:this})},GameLib.Component.prototype.getDependencies=function(){var e=[];for(var t in this.linkedObjects)this.linkedObjects.hasOwnProperty(t)&&0!==t.indexOf("parent")&&this.hasOwnProperty(t)&&("string"==typeof this[t]&&GameLib.Utils.PushUnique(e,this[t]),this[t]instanceof Array&&this[t].map(function(t){"string"==typeof t&&GameLib.Utils.PushUnique(e,t),t&&t instanceof GameLib.Component&&GameLib.Utils.PushUnique(e,t.id)}),this[t]&&this[t]instanceof GameLib.Component&&GameLib.Utils.PushUnique(e,this[t].id));return e},GameLib.Component.prototype.toString=function(){return this.id},GameLib.Component.COMPONENT_MATERIAL=2,GameLib.Component.COMPONENT_RENDERER=3,GameLib.Component.COMPONENT_CAMERA=5,GameLib.Component.COMPONENT_MESH=7,GameLib.Component.COMPONENT_SPLINE=8,GameLib.Component.COMPONENT_LIGHT=9,GameLib.Component.COMPONENT_COMPOSER=11,GameLib.Component.COMPONENT_RENDER_TARGET=12,GameLib.Component.COMPONENT_PASS=13,GameLib.Component.COMPONENT_SCENE=14,GameLib.Component.COMPONENT_RAYCASTER=15,GameLib.Component.COMPONENT_VIEWPORT=18,GameLib.Component.COMPONENT_SYSTEM=19,GameLib.Component.COMPONENT_GRAPHICS=20,GameLib.Component.COMPONENT_HELPER=21,GameLib.Component.COMPONENT_CUSTOM_CODE=22,GameLib.Component.COMPONENT_MOUSE=23,GameLib.Component.COMPONENT_SKELETON=24,GameLib.Component.COMPONENT_TEXTURE=25,GameLib.Component.COMPONENT_ENTITY_MANAGER=26,GameLib.Component.COMPONENT_DOM_ELEMENT=27,GameLib.Component.COMPONENT_STATS=29,GameLib.Component.COMPONENT_GUI=30,GameLib.Component.COMPONENT_IMAGE=31,GameLib.Component.COMPONENT_ENTITY=32,GameLib.Component.COMPONENT_MESH_SPHERE=33,GameLib.Component.COMPONENT_MESH_PLANE=34,GameLib.Component.COMPONENT_MESH_CURVE=35,GameLib.Component.COMPONENT_PHYSICS_WORLD=36,GameLib.Component.COMPONENT_BROADPHASE=37,GameLib.Component.COMPONENT_SOLVER=38,GameLib.Component.COMPONENT_RIGID_BODY=39,GameLib.Component.COMPONENT_SHAPE=40,GameLib.Component.COMPONENT_SHAPE_BOX=41,GameLib.Component.COMPONENT_SHAPE_SPHERE=42,GameLib.Component.COMPONENT_SHAPE_TRI_MESH=43,GameLib.Component.COMPONENT_SHAPE_CONVEX_HULL=44,GameLib.Component.COMPONENT_SHAPE_CONVEX_HULL_CYLINDER=45,GameLib.Component.COMPONENT_SHAPE_HEIGHT_MAP=46,GameLib.Component.COMPONENT_SHAPE_PLANE=47,GameLib.Component.COMPONENT_CONTROLS=48,GameLib.Component.COMPONENT_CONTROLS_EDITOR=49,GameLib.Component.COMPONENT_CONTROLS_TOUCH=50,GameLib.Component.COMPONENT_FRICTION_MATERIAL=51;GameLib.Component.COMPONENT_FRICTION_CONTACT_MATERIAL=52,GameLib.Component.COMPONENT_RAYCAST_VEHICLE=53,GameLib.Component.COMPONENT_RAYCAST_WHEEL=54,GameLib.Component.COMPONENT_CLOCK=55,GameLib.Component.COMPONENT_ANIMATION=56,GameLib.Component.COMPONENT_CONTROLS_KEYBOARD=57,GameLib.Component.COMPONENT_CONTROLS_MOUSE=58,GameLib.Component.COMPONENT_MESH_TEXT=59,GameLib.Component.COMPONENT_FONT=60,GameLib.Component.COMPONENT_CANVAS=61,GameLib.Component.COMPONENT_BONE=62,GameLib.Component.COMPONENT_MESH_BOX=63,GameLib.Component.COMPONENT_MESH_CYLINDER=64,GameLib.Component.COMPONENT_SYSTEM_ANIMATION=65,GameLib.Component.COMPONENT_SYSTEM_CUSTOM_CODE=66,GameLib.Component.COMPONENT_SYSTEM_GUI=67,GameLib.Component.COMPONENT_SYSTEM_INPUT=68,GameLib.Component.COMPONENT_SYSTEM_LINKING=69,GameLib.Component.COMPONENT_SYSTEM_PHYSICS=70,GameLib.Component.COMPONENT_SYSTEM_RENDER=71,GameLib.Component.COMPONENT_SYSTEM_STORAGE=72,GameLib.Component.COMPONENT_SYSTEM_VISUALIZATION=73,GameLib.Component.COMPONENT_FOG=80,GameLib.Component.COMPONENT_MESH_LINE=81,GameLib.Component.COMPONENT_PARTICLE_ENGINE=82,GameLib.Component.COMPONENT_SYSTEM_PARTICLE=83,GameLib.Component.COMPONENT_PARTICLE=84,GameLib.Component.COMPONENT_AUDIO=85,GameLib.Component.COMPONENT_SYSTEM_AUDIO=86,GameLib.Component.COMPONENT_CAST=87,GameLib.Component.GRAPHICS_RUNTIME=1,GameLib.Component.PHYSICS_RUNTIME=2,GameLib.Component.SOCKET_RUNTIME=3,GameLib.Component.STATISTICS_RUNTIME=4,GameLib.Component.DEFAULT_RUNTIME=5,GameLib.Component.GUI_RUNTIME=6,GameLib.Component.CODER_RUNTIME=7,GameLib.Component.GetComponentInfo=function(e){switch(e){case 1:return null;case 2:return{name:"GameLib.D3.Material",runtime:GameLib.Component.GRAPHICS_RUNTIME};case 3:return{name:"GameLib.D3.Renderer",runtime:GameLib.Component.GRAPHICS_RUNTIME};case 4:return null;case 5:return{name:"GameLib.D3.Camera",runtime:GameLib.Component.GRAPHICS_RUNTIME};case 6:return null;case 7:return{name:"GameLib.D3.Mesh",runtime:GameLib.Component.GRAPHICS_RUNTIME};case 8:return{name:"GameLib.D3.Spline",runtime:GameLib.Component.GRAPHICS_RUNTIME};case 9:return{name:"GameLib.D3.Light",runtime:GameLib.Component.GRAPHICS_RUNTIME};case 10:return null;case 11:return{name:"GameLib.D3.Composer",runtime:GameLib.Component.GRAPHICS_RUNTIME};case 12:return{name:"GameLib.D3.RenderTarget",runtime:GameLib.Component.GRAPHICS_RUNTIME};case 13:return{name:"GameLib.D3.Pass",runtime:GameLib.Component.GRAPHICS_RUNTIME};case 14:return{name:"GameLib.D3.Scene",runtime:GameLib.Component.GRAPHICS_RUNTIME};case 15:return{name:"GameLib.D3.Raycaster",runtime:GameLib.Component.GRAPHICS_RUNTIME};case 16:case 17:return null;case 18:return{name:"GameLib.D3.Viewport",runtime:GameLib.Component.GRAPHICS_RUNTIME};case 19:return{name:"GameLib.System",runtime:GameLib.Component.DEFAULT_RUNTIME};case 20:return{name:"GameLib.GraphicsRuntime",runtime:GameLib.Component.DEFAULT_RUNTIME};case 21:return{name:"GameLib.D3.Helper",runtime:GameLib.Component.GRAPHICS_RUNTIME};case 22:return{name:"GameLib.D3.CustomCode",runtime:GameLib.Component.DEFAULT_RUNTIME};case 23:return{name:"GameLib.Mouse",runtime:GameLib.Component.GRAPHICS_RUNTIME};case 24:return{name:"GameLib.D3.Skeleton",runtime:GameLib.Component.GRAPHICS_RUNTIME};case 25:return{name:"GameLib.D3.Texture",runtime:GameLib.Component.GRAPHICS_RUNTIME};case 26:return{name:"GameLib.EntityManager",runtime:GameLib.Component.DEFAULT_RUNTIME};case 27:return{name:"GameLib.DomElement",runtime:GameLib.Component.DEFAULT_RUNTIME};case 28:return null;case 29:return{name:"GameLib.D3.Stats",runtime:GameLib.Component.STATISTICS_RUNTIME};case 30:return{name:"GameLib.GUI",runtime:GameLib.Component.GUI_RUNTIME};case 31:return{name:"GameLib.D3.Image",runtime:GameLib.Component.GRAPHICS_RUNTIME};case 32:return{name:"GameLib.Entity",runtime:GameLib.Component.DEFAULT_RUNTIME};case 33:return{name:"GameLib.D3.Mesh.Sphere",runtime:GameLib.Component.GRAPHICS_RUNTIME};case 34:return{name:"GameLib.D3.Mesh.Plane",runtime:GameLib.Component.GRAPHICS_RUNTIME};case 35:return{name:"GameLib.D3.Mesh.Curve",runtime:GameLib.Component.GRAPHICS_RUNTIME};case 36:return{name:"GameLib.D3.PhysicsWorld",runtime:GameLib.Component.PHYSICS_RUNTIME};case 37:return{name:"GameLib.D3.Broadphase",runtime:GameLib.Component.PHYSICS_RUNTIME};case 38:return{name:"GameLib.D3.Solver",runtime:GameLib.Component.PHYSICS_RUNTIME};case 39:return{name:"GameLib.D3.RigidBody",runtime:GameLib.Component.PHYSICS_RUNTIME};case 40:return{name:"GameLib.D3.Shape",runtime:GameLib.Component.PHYSICS_RUNTIME};case 41:return{name:"GameLib.D3.Shape.Box",runtime:GameLib.Component.PHYSICS_RUNTIME};case 42:return{name:"GameLib.D3.Shape.Sphere",runtime:GameLib.Component.PHYSICS_RUNTIME};case 43:return{name:"GameLib.D3.Shape.TriMesh",runtime:GameLib.Component.PHYSICS_RUNTIME};case 44:return{name:"GameLib.D3.Shape.ConvexHull",runtime:GameLib.Component.PHYSICS_RUNTIME};case 45:return{name:"GameLib.D3.Shape.ConvexHull.Cylinder",runtime:GameLib.Component.PHYSICS_RUNTIME};case 46:return{name:"GameLib.D3.Shape.HeightMap",runtime:GameLib.Component.DEFAULT_RUNTIME};case 47:return{name:"GameLib.D3.Shape.Plane",runtime:GameLib.Component.PHYSICS_RUNTIME};case 48:return{name:"GameLib.D3.Controls",runtime:GameLib.Component.DEFAULT_RUNTIME};case 49:return{name:"GameLib.D3.Controls.Editor",runtime:GameLib.Component.GRAPHICS_RUNTIME};case 50:return{name:"GameLib.D3.Controls.Touch",runtime:GameLib.Component.DEFAULT_RUNTIME};case 51:return{name:"GameLib.D3.FrictionMaterial",runtime:GameLib.Component.PHYSICS_RUNTIME};case 52:return{name:"GameLib.D3.FrictionContactMaterial",runtime:GameLib.Component.PHYSICS_RUNTIME};case 53:return{name:"GameLib.D3.RaycastVehicle",runtime:GameLib.Component.PHYSICS_RUNTIME};case 54:return{name:"GameLib.D3.RaycastWheel",runtime:GameLib.Component.PHYSICS_RUNTIME};case 55:return{name:"GameLib.Clock",runtime:GameLib.Component.GRAPHICS_RUNTIME};case 56:return{name:"GameLib.D3.Animation",runtime:GameLib.Component.DEFAULT_RUNTIME};case 57:return{name:"GameLib.D3.Controls.Keyboard",runtime:GameLib.Component.DEFAULT_RUNTIME};case 58:return{name:"GameLib.D3.Controls.Mouse",runtime:GameLib.Component.DEFAULT_RUNTIME};case 59:return{name:"GameLib.D3.Mesh.Text",runtime:GameLib.Component.GRAPHICS_RUNTIME};case 60:return{name:"GameLib.D3.Font",runtime:GameLib.Component.GRAPHICS_RUNTIME};case 61:return{name:"GameLib.Canvas",runtime:GameLib.Component.DEFAULT_RUNTIME};case 62:return{name:"GameLib.D3.Bone",runtime:GameLib.Component.GRAPHICS_RUNTIME};case 63:return{name:"GameLib.D3.Mesh.Box",runtime:GameLib.Component.GRAPHICS_RUNTIME};case 64:return{name:"GameLib.D3.Mesh.Cylinder",runtime:GameLib.Component.GRAPHICS_RUNTIME};case 65:return{name:"GameLib.D3.System.Animation",runtime:GameLib.Component.DEFAULT_RUNTIME};case 66:return{name:"GameLib.D3.System.CustomCode",runtime:GameLib.Component.DEFAULT_RUNTIME};case 67:return{name:"GameLib.D3.System.GUI",runtime:GameLib.Component.DEFAULT_RUNTIME};case 68:return{name:"GameLib.D3.System.Input",runtime:GameLib.Component.DEFAULT_RUNTIME};case 69:return{name:"GameLib.D3.System.Linking",runtime:GameLib.Component.DEFAULT_RUNTIME};case 70:return{name:"GameLib.D3.System.Physics",runtime:GameLib.Component.DEFAULT_RUNTIME};case 71:return{name:"GameLib.D3.System.Render",runtime:GameLib.Component.DEFAULT_RUNTIME};case 72:return{name:"GameLib.D3.System.Storage",runtime:GameLib.Component.DEFAULT_RUNTIME};case 73:return{name:"GameLib.D3.System.Visualization",runtime:GameLib.Component.DEFAULT_RUNTIME};case 80:return{name:"GameLib.D3.Fog",runtime:GameLib.Component.GRAPHICS_RUNTIME};case 81:return{name:"GameLib.D3.Mesh.Line",runtime:GameLib.Component.GRAPHICS_RUNTIME};case 82:return{name:"GameLib.D3.ParticleEngine",runtime:GameLib.Component.GRAPHICS_RUNTIME};case 83:return{name:"GameLib.D3.System.Particle",runtime:GameLib.Component.DEFAULT_RUNTIME};case 84:return{name:"GameLib.D3.Particle",runtime:GameLib.Component.GRAPHICS_RUNTIME};case 85:return{name:"GameLib.D3.Audio",runtime:GameLib.Component.GRAPHICS_RUNTIME};case 86:return{name:"GameLib.System.Audio",runtime:GameLib.Component.DEFAULT_RUNTIME};case 87:return{name:"GameLib.Cast",runtime:GameLib.Component.SOCKET_RUNTIME}}throw new Error("Unknown component type: "+e)},GameLib.Component.GetComponentName=function(e){var t=GameLib.Component.GetComponentInfo(e);return t?t.name:"unused"},GameLib.Component.GetComponentRuntime=function(e){var t=GameLib.Component.GetComponentInfo(e);return t?t.runtime:null},GameLib.Component.prototype.toApiObject=function(){return this.id},GameLib.Component.prototype.processComponent=function(e){if(e instanceof GameLib.Component){e.buildIdToObject(),e.linked||(this.linked=!1);var t=e.idToObject;for(var i in t)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"==typeof e?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(var e in this.linkedObjects)this.linkedObjects.hasOwnProperty(e)&&this.hasOwnProperty(e)&&this[e]&&0!==e.indexOf("parent")&&(this.linkedObjects[e]instanceof Array?(this[e]=this[e].filter(function(e){return null!==e||(console.log("null object found and removed"),!1)}),this[e].map(function(e){this.processComponent(e)}.bind(this))):this.processComponent(this[e]));this instanceof GameLib.D3.Scene&&(this.storeClones||this.clones.map(function(e){this.idToObject.hasOwnProperty(e.id)&&delete this.idToObject[e.id]}.bind(this))),this.idToObject[this.id]=this,this.building=!1}},GameLib.Component.prototype.generateNewIds=function(){this.buildIdToObject();var e=GameLib.EntityManager.Instance.queryComponents(GameLib.D3.CustomCode);for(var t in this.idToObject)if(this.idToObject.hasOwnProperty(t)){var i=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){var t=this.idToObject[e];t instanceof GameLib.Component&&t.remove()}.bind(this)),GameLib.Event.Emit(GameLib.Event.REMOVE_COMPONENT,{component:this})},GameLib.Component.prototype.clone=function(){var e=this.toApiObject();this.cloneNumber+=1,e.id=GameLib.Utils.RandomId(),e.name=this.name+" Clone ("+this.cloneNumber+")";var t=GameLib.Component.Construct(e);return t.isClone=!0,GameLib.Event.Emit(GameLib.Event.COMPONENT_CLONED,{parent:this,component:t}),t.parentEntity=null,t},GameLib.Component.prototype.cloneInstance=function(){var e=null;return this.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){var t=[],i=[],n=[];if(this.buildIdToObject(),this.saveSubscription||this.saveErrorSubscription)return void console.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(var a in this.idToObject)if(this.idToObject.hasOwnProperty(a)&&this.idToObject[a]instanceof GameLib.Component){var s=this.idToObject[a].toApiObject();s.componentType=this.idToObject[a].componentType,t.push(s),this.publish(GameLib.Event.SAVE_COMPONENT,{apiObject:s,remote:e})}},GameLib.Component.Construct=function(rawComponentObject){var runtimeComponent=null,info=GameLib.Component.GetComponentInfo(rawComponentObject.componentType),componentClass=eval(info.name),fn=componentClass.FromObject,runtime=null;return GameLib.Event.Emit(GameLib.Event.GET_RUNTIME,function(e){runtime=e}),rawComponentObject.componentType===GameLib.Component.COMPONENT_ENTITY?runtimeComponent=fn(rawComponentObject,GameLib.EntityManager.Instance):info.runtime===GameLib.Component.GRAPHICS_RUNTIME?(GameLib.Utils.UndefinedOrNull(runtime.graphics)&&console.warn("no runtime graphics"), -runtimeComponent=fn(runtime.graphics,rawComponentObject)):info.runtime===GameLib.Component.PHYSICS_RUNTIME?(GameLib.Utils.UndefinedOrNull(runtime.physics)&&console.warn("no runtime physics"),runtimeComponent=fn(runtime.physics,rawComponentObject)):info.runtime===GameLib.Component.GUI_RUNTIME?(GameLib.Utils.UndefinedOrNull(runtime.gui)&&console.warn("no runtime gui"),runtimeComponent=fn(runtime.gui,rawComponentObject)):info.runtime===GameLib.Component.SOCKET_RUNTIME?(GameLib.Utils.UndefinedOrNull(runtime.sockets)&&console.warn("no runtime sockets"),runtimeComponent=fn(runtime.sockets,rawComponentObject)):info.runtime===GameLib.Component.STATISTICS_RUNTIME?(GameLib.Utils.UndefinedOrNull(runtime.statistics)&&console.warn("no runtime statistics"),runtimeComponent=fn(runtime.statistics,rawComponentObject)):info.runtime===GameLib.Component.DEFAULT_RUNTIME?runtimeComponent=fn(rawComponentObject):(console.log("unknown runtime object found : "+rawComponentObject.name),console.error(rawComponentObject)),runtimeComponent},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.Utils.UndefinedOrNull(a)&&(a=null),this.parentEntity=a},GameLib.API.Canvas.prototype=Object.create(GameLib.Component.prototype),GameLib.API.Canvas.prototype.constructor=GameLib.API.Canvas,GameLib.API.Canvas.FromObject=function(e){return new GameLib.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.Utils.UndefinedOrNull(r)&&(r=null),this.parentEntity=r},GameLib.API.Cast.prototype=Object.create(GameLib.Component.prototype),GameLib.API.Cast.prototype.constructor=GameLib.API.Cast,GameLib.API.Cast.FromObject=function(e){return new GameLib.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.id+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=null),this.parentEntity=i},GameLib.API.Clock.prototype=Object.create(GameLib.Component.prototype),GameLib.API.Clock.prototype.constructor=GameLib.API.Clock,GameLib.API.Clock.FromObject=function(e){return new GameLib.API.Clock(e.id,e.name,e.parentEntity)},GameLib.API.Color=function(e,t,i,n){GameLib.Utils.UndefinedOrNull(e)&&(e=1),this.r=e,GameLib.Utils.UndefinedOrNull(t)&&(t=1),this.g=t,GameLib.Utils.UndefinedOrNull(i)&&(i=1),this.b=i,GameLib.Utils.UndefinedOrNull(n)&&(n=0),this.a=n},GameLib.API.Color.FromObject=function(e){return GameLib.Utils.UndefinedOrNull(e)&&(e={}),new GameLib.API.Color(e.r,e.g,e.b,e.a)},GameLib.API.Color.prototype.toHex=function(){this.r<0&&(this.r=0),this.g<0&&(this.g=0),this.b<0&&(this.b=0),this.r>1&&(this.r=1),this.g>1&&(this.g=1),this.b>1&&(this.b=1);var e=Math.floor(this.r>=1?255:256*this.r).toString(16),t=Math.floor(this.g>=1?255:256*this.g).toString(16),i=Math.floor(this.b>=1?255:256*this.b).toString(16);return e.length<2&&(e="0"+e),t.length<2&&(t="0"+t),i.length<2&&(i="0"+i),"#"+e+t+i},GameLib.API.Color.prototype.fromHex=function(e){var t=e.match(new RegExp("#+(..)(..)(..)"));this.r=parseInt(t[1],16)/255,this.g=parseInt(t[2],16)/255,this.b=parseInt(t[3],16)/255},GameLib.API.DomElement=function(e,t,i,n){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="DOM Element ("+this.id+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=""),this.domElementId=i,GameLib.Utils.UndefinedOrNull(n)&&(n=null),this.parentEntity=n},GameLib.API.DomElement.prototype=Object.create(GameLib.Component.prototype),GameLib.API.DomElement.prototype.constructor=GameLib.API.DomElement,GameLib.API.DomElement.FromObject=function(e){return new GameLib.API.DomElement(e.id,e.name,e.domElementId,e.parentEntity)},GameLib.API.EntityManager=function(e,t,i,n,a){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="Entity Manager ("+this.id+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=[]),this.entities=i,GameLib.Utils.UndefinedOrNull(n)&&(n=null),this.defaultEntity=n,GameLib.Utils.UndefinedOrNull(a)&&(a=null),this.defaultRenderer=a},GameLib.API.EntityManager.prototype=Object.create(GameLib.Component.prototype),GameLib.API.EntityManager.prototype.constructor=GameLib.API.EntityManager,GameLib.API.EntityManager.FromObject=function(e){var t=e.entities.map(function(e){return GameLib.API.Entity.FromObject(e)});return new GameLib.API.EntityManager(e.id,e.name,t,e.defaultEntity,e.defaultRenderer)},GameLib.API.Entity=function(e,t,i,n,a){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="Entity ("+this.id+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=[]),this.components=i,GameLib.Utils.UndefinedOrNull(n)&&(n=null),this.parentEntity=n,GameLib.Utils.UndefinedOrNull(a)&&(a=null),this.parentEntityManager=a,this.activeComponent=null},GameLib.API.Entity.prototype=Object.create(GameLib.Component.prototype),GameLib.API.Entity.prototype.constructor=GameLib.API.Entity,GameLib.API.Entity.FromObject=function(e){return new GameLib.API.Entity(e.id,e.name,e.components,e.parentEntity,e.parentEntityManager)},GameLib.API.Matrix4=function(e,t,i,n){this.rows=[],GameLib.Utils.UndefinedOrNull(e)&&(e=new GameLib.API.Vector4(1,0,0,0)),this.rows[0]=e,GameLib.Utils.UndefinedOrNull(t)&&(t=new GameLib.API.Vector4(0,1,0,0)),this.rows[1]=t,GameLib.Utils.UndefinedOrNull(i)&&(i=new GameLib.API.Vector4(0,0,1,0)),this.rows[2]=i,GameLib.Utils.UndefinedOrNull(n)&&(n=new GameLib.API.Vector4(0,0,0,1)),this.rows[3]=n,this.temp=[],this.temp.push(new GameLib.API.Vector4),this.temp.push(new GameLib.API.Vector4),this.temp.push(new GameLib.API.Vector4),this.temp.push(new GameLib.API.Vector4),this.forward=new GameLib.API.Vector4,this.left=new GameLib.API.Vector4,this.up=new GameLib.API.Vector4},GameLib.API.Matrix4.FromObject=function(e){if(e.rows)return new GameLib.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(e instanceof Array)return new GameLib.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]));throw console.warn("Unsupported object matrix type - whats your DB version?"),new Error("Unsupported object matrix type - whats your DB version?")},GameLib.API.Matrix4.prototype.rotationMatrixX=function(e){return this.identity(),this.rows[1]=new GameLib.API.Vector4(0,Math.cos(e),-1*Math.sin(e),0),this.rows[2]=new GameLib.API.Vector4(0,Math.sin(e),Math.cos(e),0),this},GameLib.API.Matrix4.prototype.rotationMatrixY=function(e){return this.identity(),this.rows[0]=new GameLib.API.Vector4(Math.cos(e),0,Math.sin(e),0),this.rows[2]=new GameLib.API.Vector4(-1*Math.sin(e),0,Math.cos(e),0),this},GameLib.API.Matrix4.prototype.rotationMatrixZ=function(e){return this.identity(),this.rows[0]=new GameLib.API.Vector4(Math.cos(e),-1*Math.sin(e),0,0),this.rows[1]=new GameLib.API.Vector4(Math.sin(e),Math.cos(e),0,0),this},GameLib.API.Matrix4.prototype.rotateX=function(e,t){return this.identity(),this.rotationMatrixX(e),this.multiply(t)},GameLib.API.Matrix4.prototype.rotateY=function(e,t){return this.identity(),this.rotationMatrixY(e),this.multiply(t)},GameLib.API.Matrix4.prototype.rotateZ=function(e,t){return this.identity(),this.rotationMatrixZ(e),this.multiply(t)},GameLib.API.Matrix4.prototype.multiply=function(e){return e instanceof GameLib.API.Quaternion||e instanceof GameLib.API.Vector4?new GameLib.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):e instanceof GameLib.API.Vector3?new GameLib.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):void 0},GameLib.API.Matrix4.prototype.identity=function(){this.rows=[new GameLib.API.Vector4(1,0,0,0),new GameLib.API.Vector4(0,1,0,0),new GameLib.API.Vector4(0,0,1,0),new GameLib.API.Vector4(0,0,0,1)]},GameLib.API.Mouse=function(e,t,i,n,a){GameLib.Utils.UndefinedOrNull(a)&&(a=null),this.parentEntity=a,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){return new GameLib.API.Mouse(e.id,e.name,e.x,e.y,e.parentEntity)},GameLib.API.Quaternion=function(e,t,i,n,a,s){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(a)&&(a=new GameLib.API.Vector3),this.axis=a,GameLib.Utils.UndefinedOrNull(s)&&(s=0),this.angle=s},GameLib.API.Quaternion.prototype.translate=function(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this},GameLib.API.Quaternion.prototype.copy=function(){return new GameLib.API.Quaternion(this.x,this.y,this.z,this.w)},GameLib.API.Quaternion.prototype.normalize=function(){var e=this.x*this.x+this.y*this.y+this.z*this.z;if(e<1e-6)return this;var t=1/Math.sqrt(e);this.x*=t,this.y*=t,this.z*=t},GameLib.API.Quaternion.prototype.multiply=function(e){var t,i,n,a,s=e,o=this;if(e instanceof GameLib.API.Matrix4)return t=s.rows[0].x*o.x+s.rows[0].y*o.y+s.rows[0].z*o.z+s.rows[0].w*o.w,i=s.rows[1].x*o.x+s.rows[1].y*o.y+s.rows[1].z*o.z+s.rows[1].w*o.w,n=s.rows[2].x*o.x+s.rows[2].y*o.y+s.rows[2].z*o.z+s.rows[2].w*o.w,a=s.rows[3].x*o.x+s.rows[3].y*o.y+s.rows[3].z*o.z+s.rows[3].w*o.w,this.x=t,this.y=i,this.z=n,this.w=a,this;if(e instanceof GameLib.API.Quaternion)return t=s.x*o.x-s.y*o.y-s.z*o.z-s.w*s.w,i=s.x*o.y+s.y*o.x-s.z*o.w+s.w*s.z,n=s.x*o.z+s.y*o.w+s.z*o.x-s.w*s.y,a=s.x*o.w-s.y*o.z+s.z*o.y+s.w*s.x,this.x=t,this.y=i,this.z=n,this.w=a,this;throw console.log("This functionality not implemented - please do this"),new Error("This functionality not implemented - please do this")},GameLib.API.Quaternion.prototype.setFromAngle=function(e){return this.instance.setFromAxisAngle(this.axis.instance,e),this.x=this.instance.x,this.y=this.instance.y,this.z=this.instance.z,this.w=this.instance.w,this},GameLib.API.Quaternion.prototype.subtract=function(e){return e instanceof GameLib.API.Vector3&&(this.x-=e.x,this.y-=e.y,this.z-=e.z),e instanceof GameLib.API.Quaternion&&(this.x-=e.x,this.y-=e.y,this.z-=e.z,this.w-=e.w),this},GameLib.API.Quaternion.prototype.magnitude=function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)},GameLib.API.Quaternion.prototype.normalize=function(){var e=this.magnitude();return e<1e-6?this:(this.x*=e,this.y*=e,this.z*=e,this.w*=e,this)},GameLib.API.Quaternion.prototype.setFromRotationMatrix=function(e){this.instance.setFromRotationMatrix(e.instance),this.x=this.instance.x,this.y=this.instance.y,this.z=this.instance.z,this.w=this.instance.w},GameLib.API.Quaternion.prototype.slerp=function(e,t){return this.updateInstance(),this.instance.slerp(e.instance,t),this.x=this.instance.x,this.y=this.instance.y,this.z=this.instance.z,this.w=this.instance.w,this},GameLib.API.Quaternion.FromObject=function(e){var t=null;return e.axis&&(t=GameLib.API.Vector3.FromObject(e.axis)),new GameLib.API.Quaternion(e.x,e.y,e.z,e.w,t,e.angle)},GameLib.API.Quaternion.Points=function(){this.vectors=[]},GameLib.API.Quaternion.Points.prototype.add=function(e){if(e instanceof GameLib.API.Vector3&&(e=new GameLib.API.Quaternion(e.x,e.y,e.z,1)),!e instanceof GameLib.API.Quaternion)throw console.warn("Vector needs to be of type Quaternion"),new Error("Vector needs to be of type Quaternion");return this.vectors.push(e),this},GameLib.API.Quaternion.Points.prototype.copy=function(){for(var e=[],t=0;ts&&(s=c.x,n=t*e)}this.vectors=a;for(var h=(new GameLib.API.Matrix4).rotationMatrixY(n),m=0;ms&&(s=c.y,n=t*e)}this.vectors=a;for(var h=(new GameLib.API.Matrix4).rotationMatrixX(n),m=0;mn&&(n=this.vectors[o].x),this.vectors[o].y>a&&(a=this.vectors[o].y),this.vectors[o].z>s&&(s=this.vectors[o].z);return new GameLib.API.Vector3(Math.abs(n-e),Math.abs(a-t),Math.abs(a-i))},GameLib.API.Quaternion.Points.prototype.average=function(){for(var e=0,t=0,i=0,n=0;n0},GameLib.API.Vector3.normal=function(e,t,i){var n=t.copy(),a=i.copy();return n.subtract(e).cross(a.subtract(e))},GameLib.API.Vector3.prototype.lookAt=function(e,t){var i=GameLib.API.Matrix4.lookAt(this,e,t);return this.multiply(i)},GameLib.API.Vector3.prototype.translate=function(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this},GameLib.API.Vector3.prototype.add=function(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this},GameLib.API.Vector3.prototype.squared=function(){return this.x*this.x+this.y*this.y+this.z*this.z},GameLib.API.Vector3.prototype.copy=function(){return new GameLib.API.Vector3(this.x,this.y,this.z)},GameLib.API.Vector3.prototype.set=function(e,t,i){this.x=e,this.y=t,this.z=i},GameLib.API.Vector3.prototype.lerp=function(e,t){return new GameLib.API.Vector3(this.x+(e.x-this.x)*t,this.y+(e.y-this.y)*t,this.z+(e.z-this.z)*t)},GameLib.API.Vector3.prototype.distanceTo=function(e){var t=this.x-e.x,i=this.y-e.y,n=this.z-e.z;return Math.sqrt(t*t+i*i+n*n)},GameLib.API.Vector3.AngleDirection=function(e,t,i){var n=e.cross(t),a=n.dot(i);return a>0?1:a<0?-1:0},GameLib.API.Vector3.prototype.multiply=function(e,t){var i,n,a,s=e,o=this;if(GameLib.Utils.UndefinedOrNull(t)&&(t=!1),"number"==typeof e)return t?(this.x*=e,this.y*=e,this.z*=e,this):this.x*e+this.y*e+this.z*e;if(e instanceof GameLib.API.Vector3)return t?(i=s.y*o.z-s.z*o.y,n=s.z*o.x-s.x*o.z,a=s.x*o.y-s.y*o.x,this.x=i,this.y=n,this.z=a,this):this.x*e.x+this.y*e.y+this.z*e.z;throw console.log("functionality not implemented - please do this"),new Error("not implemented")},GameLib.API.Vector3.prototype.dot=function(e){return this.x*e.x+this.y*e.y+this.z*e.z},GameLib.API.Vector3.prototype.normalize=function(){var e=this.squared();if(e<1e-6)return this;var t=1/Math.sqrt(e);return new GameLib.API.Vector3(this.x*t,this.y*t,this.z*t)},GameLib.API.Vector3.prototype.clone=function(){return new GameLib.API.Vector3(this.x,this.y,this.z)},GameLib.API.Vector3.prototype.applyQuaternion=function(e){var t=this.x,i=this.y,n=this.z,a=e.x,s=e.y,o=e.z,r=e.w,c=r*t+s*n-o*i,h=r*i+o*t-a*n,m=r*n+a*i-s*t,l=-a*t-s*i-o*n;return this.x=c*r+l*-a+h*-o-m*-s,this.y=h*r+l*-s+m*-a-c*-o,this.z=m*r+l*-o+c*-s-h*-a,this},GameLib.API.Vector3.prototype.clamp=function(e,t){return this.x=Math.max(e.x,Math.min(t.x,this.x)),this.y=Math.max(e.y,Math.min(t.y,this.y)),this.z=Math.max(e.z,Math.min(t.z,this.z)),this},GameLib.API.Vector3.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)},GameLib.API.Vector3.prototype.reflect=function(e){return this.sub(v1.copy(e).multiply(2*this.dot(e)))},GameLib.API.Vector3.prototype.angleTo=function(e){var t=this.dot(e)/Math.sqrt(this.lengthSq()*e.lengthSq());return Math.acos(exports.Math.clamp(t,-1,1))},GameLib.API.Vector3.FromObject=function(e){return new GameLib.API.Vector3(e.x,e.y,e.z)},GameLib.API.Vector4=function(e,t,i,n){GameLib.Utils.UndefinedOrNull(e)&&(e=0),this.x=e,GameLib.Utils.UndefinedOrNull(t)&&(t=0),this.y=t,GameLib.Utils.UndefinedOrNull(i)&&(i=0),this.z=i,GameLib.Utils.UndefinedOrNull(n)&&(n=1),this.w=n},GameLib.API.Vector4.prototype.equals=function(e){return this.x===e.x&&this.y===e.y&&this.z===e.z&&this.w===e.w},GameLib.API.Vector4.FromObject=function(e){return new GameLib.API.Vector4(e.x,e.y,e.z,e.w)},GameLib.Canvas=function(e){if(GameLib.Utils.UndefinedOrNull(e)&&(e={}),e instanceof GameLib.Canvas)return e;GameLib.API.Canvas.call(this,e.id,e.name,e.width,e.height,e.parentEntity),GameLib.Component.call(this,GameLib.Component.COMPONENT_CANVAS)},GameLib.Canvas.prototype=Object.create(GameLib.API.Canvas.prototype),GameLib.Canvas.prototype.constructor=GameLib.Canvas,GameLib.Canvas.prototype.createInstance=function(){this.instance=document.createElement("canvas"),this.instance.width=this.width,this.instance.height=this.height,GameLib.Component.prototype.createInstance.call(this)},GameLib.Canvas.prototype.updateInstance=function(e){GameLib.Utils.UndefinedOrNull(e)&&console.warn("unknown property update for Canvas: "+e),"width"===e&&(this.instance.width=this.width),"height"===e&&(this.instance.height=this.height)},GameLib.Canvas.prototype.toApiObject=function(){return new GameLib.API.Canvas(this.id,this.name,this.width,this.height,GameLib.Utils.IdOrNull(this.parentEntity))},GameLib.Canvas.FromObject=function(e){return new GameLib.Canvas(GameLib.API.Canvas.FromObject(e))},GameLib.Cast=function(e,t){if(this.socket=e,this.socket.isNotWebSocketThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),t instanceof GameLib.Cast)return t;GameLib.API.Cast.call(this,t.id,t.name,t.castType,t.roomId,t.peer,t.serverIp,t.port,t.parentEntity),GameLib.Component.call(this,GameLib.Component.COMPONENT_CAST,{peer:GameLib.Component})},GameLib.Cast.prototype=Object.create(GameLib.API.Cast.prototype),GameLib.Cast.prototype.constructor=GameLib.Cast,GameLib.Cast.CAST_TYPE_ROOM=1,GameLib.Cast.CAST_TYPE_PEER=2,GameLib.Cast.CAST_TYPE_ALL=3,GameLib.Cast.CAST_TYPE_ALL_BUT_PEER=4,GameLib.Cast.prototype.createInstance=function(){this.instance=!0,GameLib.Component.prototype.createInstance.call(this)},GameLib.Cast.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.Cast.prototype.remove=function(){if(this.removeSubscription)return void console.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.Cast.prototype.clone=function(){var e=this.templateParticle.mesh.clone(),t=this.templateParticle.clone();t.mesh=e,t.instance=e.instance;var i=GameLib.Component.prototype.clone.call(this);return i.templateParticle=t,i},GameLib.Cast.prototype.processParticles=function(e){},GameLib.Cast.prototype.createNewParticle=function(e){},GameLib.Cast.prototype.toApiObject=function(){return new GameLib.API.Cast(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.Cast.FromObject=function(e,t){var i=GameLib.API.Cast.FromObject(t);return new GameLib.Cast(e,i)},GameLib.Clock=function(e,t){if(this.graphics=e,this.graphics.isNotThreeThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),t instanceof GameLib.Clock)return t;GameLib.API.Clock.call(this,t.id,t.name,t.parentEntity),GameLib.Component.call(this,GameLib.Component.COMPONENT_CLOCK)},GameLib.Clock.prototype=Object.create(GameLib.API.Clock.prototype),GameLib.Clock.prototype.constructor=GameLib.Clock,GameLib.Clock.prototype.createInstance=function(){this.instance=new THREE.Clock,GameLib.Component.prototype.createInstance.call(this)},GameLib.Clock.prototype.updateInstance=function(){},GameLib.Clock.prototype.getDelta=function(){var e=this.instance.getDelta();return e>1/30&&(e=1/30),e},GameLib.Clock.prototype.toApiObject=function(){return new GameLib.API.Clock(this.id,this.name,GameLib.Utils.IdOrNull(this.parentEntity))},GameLib.Clock.FromObject=function(e,t){var i=GameLib.API.Clock.FromObject(t);return new GameLib.Clock(e,i)},GameLib.CoderRuntime=function(e,t,i){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="Coder ("+e+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=GameLib.CoderRuntime.TYPE_CODE_MIRROR),this.coderType=i,this.createInstance()},GameLib.CoderRuntime.TYPE_CODE_MIRROR=1,GameLib.CoderRuntime.prototype.createInstance=function(){this.coderType===GameLib.CoderRuntime.TYPE_CODE_MIRROR?this.instance=CodeMirror:this.instance=null},GameLib.CoderRuntime.prototype.updateInstance=function(e){"coderType"===e&&this.createInstance()},GameLib.CoderRuntime.prototype.isNotCodeMirrorThrow=function(){if(!(this.instance instanceof CodeMirror))throw console.error("Only CodeMirror supported"),new Error("Only CodeMirror supported")},GameLib.Color=function(e,t,i,n){if(this.graphics=e,this.graphics.isNotThreeThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),t instanceof GameLib.Color)return t;GameLib.API.Color.call(this,t.r,t.g,t.b,t.a),GameLib.Utils.UndefinedOrNull(i)&&(i=null),this.parentObject=i,GameLib.Utils.UndefinedOrNull(n)&&(n=.001),this.grain=n,this.createInstance()},GameLib.Color.prototype=Object.create(GameLib.API.Color.prototype),GameLib.Color.prototype.constructor=GameLib.Color,GameLib.Color.prototype.createInstance=function(){this.instance=new THREE.Color(this.r,this.g,this.b)},GameLib.Color.prototype.updateInstance=function(e){this.instance.r=this.r,this.instance.g=this.g,this.instance.b=this.b,this.parentObject&&this.parentObject.updateInstance&&this.parentObject.updateInstance(e)},GameLib.Color.prototype.toApiObject=function(){return new GameLib.API.Color(this.r,this.g,this.b,this.a)},GameLib.D3.API.Animation=function(e,t,i,n,a,s,o,r,c,h,m,l){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="Animation ("+this.id+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=0),this.rotationSpeed=i,GameLib.Utils.UndefinedOrNull(n)&&(n=0),this.translationSpeed=n,GameLib.Utils.UndefinedOrNull(a)&&(a=0),this.scaleSpeed=a,GameLib.Utils.UndefinedOrNull(s)&&(s=null),this.rotationFn=s,GameLib.Utils.UndefinedOrNull(o)&&(o=null),this.translationFn=o,GameLib.Utils.UndefinedOrNull(r)&&(r=null),this.scaleFn=r,GameLib.Utils.UndefinedOrNull(c)&&(c={position:!1,rotation:!0,scale:!1}),this.blocking=c,GameLib.Utils.UndefinedOrNull(h)&&(h=!0),this.applyToMeshWhenDone=h,GameLib.Utils.UndefinedOrNull(m)&&(m=[]),this.meshes=m,GameLib.Utils.UndefinedOrNull(l)&&(l=null),this.parentEntity=l},GameLib.D3.API.Animation.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.API.Animation.prototype.constructor=GameLib.D3.API.Animation,GameLib.D3.API.Animation.FromObject=function(e){return new GameLib.D3.API.Animation(e.id,e.name,e.rotationSpeed,e.translationSpeed,e.scaleSpeed,e.rotationFn,e.translationFn,e.scaleFn,e.blocking,e.applyToMeshWhenDone,e.meshes,e.parentEntity)},GameLib.D3.API.Audio=function(e,t,i,n,a,s,o,r,c){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="Audio ("+this.id+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=""),this.path=i,GameLib.Utils.UndefinedOrNull(n)&&(n=!1),this.loop=n,GameLib.Utils.UndefinedOrNull(a)&&(a=.5),this.volume=a,GameLib.Utils.UndefinedOrNull(s)&&(s=null),this.camera=s,GameLib.Utils.UndefinedOrNull(o)&&(o=!1),this.overplay=o,GameLib.Utils.UndefinedOrNull(r)&&(r=!1),this.paused=r,GameLib.Utils.UndefinedOrNull(c)&&(c=null),this.parentEntity=c},GameLib.D3.API.Audio.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.API.Audio.prototype.constructor=GameLib.D3.API.Audio;GameLib.D3.API.Audio.FromObject=function(e){var t=null;return e.camera&&(t=e.camera instanceof Object?GameLib.D3.API.Camera.FromObject(e.camera):e.camera),new GameLib.D3.API.Audio(e.id,e.name,e.path,e.loop,e.volume,t,e.overplay,e.paused,e.parentEntity)},GameLib.D3.API.BoneWeight=function(e,t){this.boneIndex=e,this.weight=t},GameLib.D3.API.BoneWeight.FromObject=function(e){return new GameLib.D3.API.BoneWeight(e.boneIndex,e.weight)},GameLib.D3.API.Bone=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="Bone ("+this.id+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=[]),this.childBoneIds=i,GameLib.Utils.UndefinedOrNull(n)&&(n=[]),this.parentBoneIds=n,GameLib.Utils.UndefinedOrNull(a)&&(a=new GameLib.API.Vector3),this.position=a,GameLib.Utils.UndefinedOrNull(s)&&(s=new GameLib.API.Quaternion),this.quaternion=s,GameLib.Utils.UndefinedOrNull(o)&&(o=new GameLib.API.Vector3(1,1,1)),this.scale=o,GameLib.Utils.UndefinedOrNull(r)&&(r=new GameLib.API.Vector3(0,1,0)),this.up=r},GameLib.D3.API.Bone.FromObject=function(e){return new GameLib.D3.API.Bone(e.id,e.name,e.childBoneIds,e.parentBoneIds,GameLib.API.Vector3.FromObject(e.position),GameLib.API.Quaternion.FromObject(e.quaternion),GameLib.API.Vector3.FromObject(e.scale),GameLib.API.Vector3.FromObject(e.up))},GameLib.D3.API.Broadphase=function(e,t,i,n){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="Broadphase ("+this.id+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=GameLib.D3.Broadphase.BROADPHASE_TYPE_NAIVE),this.broadphaseType=i,GameLib.Utils.UndefinedOrNull(n)&&(n=null),this.parentEntity=n},GameLib.D3.API.Broadphase.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.API.Broadphase.prototype.constructor=GameLib.D3.API.Broadphase,GameLib.D3.API.Broadphase.FromObject=function(e){return new GameLib.D3.API.Broadphase(e.id,e.name,e.broadphaseType,e.parentEntity)},GameLib.D3.API.Camera=function(e,t,i,n,a,s,o,r,c,h,m,l,p,u,b,d,L,G,f,E,y){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t=GameLib.D3.Camera.CAMERA_TYPE_PERSPECTIVE),this.cameraType=t,GameLib.Utils.UndefinedOrNull(i)&&(i="Camera ("+this.id+")"),this.name=i,GameLib.Utils.UndefinedOrNull(n)&&(n=75),this.fov=n,GameLib.Utils.UndefinedOrNull(a)&&(a=window.innerWidth/window.innerHeight),this.aspect=a,GameLib.Utils.UndefinedOrNull(s)&&(s=.01),this.near=s,GameLib.Utils.UndefinedOrNull(o)&&(o=1e3),this.far=o,GameLib.Utils.UndefinedOrNull(r)&&(r=new GameLib.API.Vector3(15,15,15)), -this.position=r,GameLib.Utils.UndefinedOrNull(G)&&(G=new GameLib.API.Quaternion),this.quaternion=G,GameLib.Utils.UndefinedOrNull(c)&&(c=new GameLib.API.Vector3(0,0,0)),this.lookAt=c,GameLib.Utils.UndefinedOrNull(h)&&(h=-100),this.minX=h,GameLib.Utils.UndefinedOrNull(m)&&(m=100),this.maxX=m,GameLib.Utils.UndefinedOrNull(l)&&(l=-100),this.minY=l,GameLib.Utils.UndefinedOrNull(p)&&(p=100),this.maxY=p,GameLib.Utils.UndefinedOrNull(u)&&(u=-100),this.minZ=u,GameLib.Utils.UndefinedOrNull(b)&&(b=100),this.maxZ=b,GameLib.Utils.UndefinedOrNull(d)&&(d=0),this.offsetX=d,GameLib.Utils.UndefinedOrNull(L)&&(L=0),this.offsetY=L,GameLib.Utils.UndefinedOrNull(E)&&(E=30),this.eyeSeparation=E,GameLib.Utils.UndefinedOrNull(y)&&(y=150),this.focalLength=y,GameLib.Utils.UndefinedOrNull(f)&&(f=null),this.parentEntity=f},GameLib.D3.API.Camera.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.API.Camera.prototype.constructor=GameLib.D3.API.Camera,GameLib.D3.API.Camera.FromObject=function(e){return new GameLib.D3.API.Camera(e.id,e.cameraType,e.name,e.fov,e.aspect,e.near,e.far,GameLib.API.Vector3.FromObject(e.position),GameLib.API.Vector3.FromObject(e.lookAt),e.minX,e.maxX,e.minY,e.maxY,e.minZ,e.maxZ,e.offsetX,e.offsetY,GameLib.API.Quaternion.FromObject(e.quaternion),e.parentEntity,e.eyeSeparation,e.focalLength)},GameLib.D3.API.Composer=function(e,t,i,n,a,s){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="Composer ("+e+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=null),this.renderer=i,GameLib.Utils.UndefinedOrNull(n)&&(n=null),this.renderTarget=n,GameLib.Utils.UndefinedOrNull(a)&&(a=[]),this.passes=a,GameLib.Utils.UndefinedOrNull(s)&&(s=null),this.parentEntity=s},GameLib.D3.API.Composer.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.API.Composer.prototype.constructor=GameLib.D3.API.Composer,GameLib.D3.API.Composer.FromObject=function(e){return new GameLib.D3.API.Composer(e.id,e.name,e.renderer,e.renderTarget,e.passes,e.parentEntity)},GameLib.D3.API.Controls=function(e,t,i,n,a){if(GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(this instanceof GameLib.D3.Controls.Editor&&(t=GameLib.D3.Controls.CONTROLS_TYPE_EDITOR),this instanceof GameLib.D3.Controls.Touch&&(t=GameLib.D3.Controls.CONTROLS_TYPE_TOUCH),this instanceof GameLib.D3.Controls.Keyboard&&(t=GameLib.D3.Controls.CONTROLS_TYPE_KEYBOARD),this instanceof GameLib.D3.Controls.Mouse&&(t=GameLib.D3.Controls.CONTROLS_TYPE_MOUSE),GameLib.Utils.UndefinedOrNull(t)))throw new Error("Could not determine controls type from this");this.controlsType=t,GameLib.Utils.UndefinedOrNull(i)&&(t===GameLib.D3.Controls.CONTROLS_TYPE_EDITOR&&(i="Editing Controls"),t===GameLib.D3.Controls.CONTROLS_TYPE_TOUCH&&(i="Touch Controls"),t===GameLib.D3.Controls.CONTROLS_TYPE_KEYBOARD&&(i="Keyboard Controls"),t===GameLib.D3.Controls.CONTROLS_TYPE_MOUSE&&(i="Mouse Controls"),i+=" ("+this.id+")"),this.name=i,GameLib.Utils.UndefinedOrNull(n)&&(n=null),this.domElement=n,GameLib.Utils.UndefinedOrNull(a)&&(a=null),this.parentEntity=a},GameLib.D3.API.Controls.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.API.Controls.prototype.constructor=GameLib.D3.API.Controls,GameLib.D3.API.Controls.FromObject=function(e){return new GameLib.D3.API.Controls(e.id,e.controlsType,e.name,e.domElement,e.parentEntity)},GameLib.D3.API.CustomCode=function(e,t,i,n,a){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="CustomCode ("+this.id+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=42),this.eventId=i,GameLib.Utils.UndefinedOrNull(n)&&(n="return null;\n//@ sourceURL="+this.name+".js"),this.code=n,GameLib.Utils.UndefinedOrNull(a)&&(a=null),this.parentEntity=a},GameLib.D3.API.CustomCode.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.API.CustomCode.prototype.constructor=GameLib.D3.API.CustomCode,GameLib.D3.API.CustomCode.FromObject=function(e){return new GameLib.D3.API.CustomCode(e.id,e.name,e.eventId,e.code,e.parentEntity)},GameLib.D3.API.Face=function(e,t,i,n,a,s,o,r,c,h,m){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="Face "+e),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=-1),this.v0index=i,GameLib.Utils.UndefinedOrNull(n)&&(n=-1),this.v1index=n,GameLib.Utils.UndefinedOrNull(a)&&(a=-1),this.v2index=a,GameLib.Utils.UndefinedOrNull(s)&&(s=-1),this.materialIndex=s,GameLib.Utils.UndefinedOrNull(o)&&(o=[[]]),this.uvs=o,GameLib.Utils.UndefinedOrNull(r)&&(r=null),this.color=r,GameLib.Utils.UndefinedOrNull(c)&&(c=[]),this.vertexColors=c,GameLib.Utils.UndefinedOrNull(h)&&(h=[]),this.vertexNormals=h,GameLib.Utils.UndefinedOrNull(m)&&(m=null),this.normal=m},GameLib.D3.API.Face.FromObject=function(e){var t=e.uvs.reduce(function(e,t,i){return e[i]=t.reduce(function(e,t){return e.push(GameLib.API.Vector2.FromObject(t)),e},[]),e},[]),i=e.vertexColors.map(function(e){return GameLib.API.Color.FromObject(e)}),n=null;e.color&&(n=GameLib.API.Color.FromObject(e.color));var a=e.vertexNormals.map(function(e){return GameLib.API.Vector3.FromObject(e)}),s=null;return e.normal&&(s=GameLib.API.Vector3.FromObject(e.normal)),new GameLib.D3.API.Face(e.id,e.name,e.v0index,e.v1index,e.v2index,e.materialIndex,t,n,i,a,s)},GameLib.D3.API.Face.prototype.clone=function(){return new GameLib.D3.API.Face(this.id,this.name,this.v0index,this.v1index,this.v2index,this.materialIndex,this.uvs,this.color,this.vertexColors,this.vertexNormals,this.normal)},GameLib.D3.API.Face.prototype.equals=function(e){return this.v0index===e.v0index&&this.v1index===e.v1index&&this.v2index===e.v2index||this.v0index===e.v0index&&this.v1index===e.v2index&&this.v2index===e.v1index||this.v0index===e.v1index&&this.v1index===e.v0index&&this.v2index===e.v2index||this.v0index===e.v1index&&this.v1index===e.v2index&&this.v2index===e.v0index||this.v0index===e.v2index&&this.v1index===e.v0index&&this.v2index===e.v1index||this.v0index===e.v2index&&this.v1index===e.v1index&&this.v2index===e.v0index},GameLib.D3.API.Fog=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="Fog ("+this.id+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=!1),this.exponential=i,GameLib.Utils.UndefinedOrNull(n)&&(n=new GameLib.API.Color(1,1,1,1)),this.color=n,GameLib.Utils.UndefinedOrNull(a)&&(a=1),this.near=a,GameLib.Utils.UndefinedOrNull(s)&&(s=1e3),this.far=s,GameLib.Utils.UndefinedOrNull(o)&&(o=25e-5),this.density=o,GameLib.Utils.UndefinedOrNull(r)&&(r=null),this.parentEntity=r},GameLib.D3.API.Fog.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.API.Fog.prototype.constructor=GameLib.D3.API.Fog,GameLib.D3.API.Fog.FromObject=function(e){return new GameLib.D3.API.Fog(e.id,e.name,e.exponential,e.color,e.near,e.far,e.density,e.parentEntity)},GameLib.D3.API.Font=function(e,t,i,n){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="Font ("+e+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i="/apiRelative/path/to/font"),this.url=i,GameLib.Utils.UndefinedOrNull(n)&&(n=null),this.parentEntity=n},GameLib.D3.API.Font.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.API.Font.prototype.constructor=GameLib.D3.API.Font,GameLib.D3.API.Font.FromObject=function(e){return new GameLib.D3.API.Font(e.id,e.name,e.url,e.parentEntity)},GameLib.D3.API.FrictionContactMaterial=function(e,t,i,n,a,s,o,r,c,h){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="Friction Material ("+this.id+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=[]),this.materials=i,GameLib.Utils.UndefinedOrNull(n)&&(n=.3),this.friction=n,GameLib.Utils.UndefinedOrNull(a)&&(a=.3),this.restitution=a,GameLib.Utils.UndefinedOrNull(s)&&(s=1e7),this.contactEquationStiffness=s,GameLib.Utils.UndefinedOrNull(o)&&(o=3),this.contactEquationRelaxation=o,GameLib.Utils.UndefinedOrNull(r)&&(r=1e7),this.frictionEquationStiffness=r,GameLib.Utils.UndefinedOrNull(c)&&(c=3),this.frictionEquationRelaxation=c,GameLib.Utils.UndefinedOrNull(h)&&(h=null),this.parentEntity=h},GameLib.D3.API.FrictionContactMaterial.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.API.FrictionContactMaterial.prototype.constructor=GameLib.D3.API.FrictionContactMaterial,GameLib.D3.API.FrictionContactMaterial.FromObject=function(e){return new GameLib.D3.API.FrictionContactMaterial(e.id,e.name,e.materials,e.friction,e.restitution,e.contactEquationStiffness,e.contactEquationRelaxation,e.frictionEquationStiffness,e.frictionEquationRelaxation,e.parentEntity)},GameLib.D3.API.FrictionMaterial=function(e,t,i,n,a){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="Friction Material ("+this.id+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=-1),this.friction=i,GameLib.Utils.UndefinedOrNull(n)&&(n=-1),this.restitution=n,GameLib.Utils.UndefinedOrNull(a)&&(a=null),this.parentEntity=a},GameLib.D3.API.FrictionMaterial.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.API.FrictionMaterial.prototype.constructor=GameLib.D3.API.FrictionMaterial,GameLib.D3.API.FrictionMaterial.FromObject=function(e){return new GameLib.D3.API.FrictionMaterial(e.id,e.name,e.friction,e.restitution,e.parentEntity)},GameLib.D3.API.ImageFactory=function(e,t,i,n){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="ImageFactory ("+this.id+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i="",console.warn("No baseURL defined for image factory")),this.baseUrl=i,GameLib.Utils.UndefinedOrNull(n)&&(n=null),this.parentEntity=n},GameLib.D3.API.ImageFactory.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.API.ImageFactory.prototype.constructor=GameLib.D3.API.ImageFactory,GameLib.D3.API.ImageFactory.FromObject=function(e){return new GameLib.D3.API.ImageFactory(e.id,e.name,e.baseUrl,e.parentEntity)},GameLib.D3.API.Image=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="Image "+e),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=GameLib.Utils.LowerUnderscore(t)),this.fileName=i,GameLib.Utils.UndefinedOrNull(n)&&(n=".unknown"),this.extension=n,GameLib.Utils.UndefinedOrNull(a)&&(a="/"),this.path=a,GameLib.Utils.UndefinedOrNull(s)&&(s="application/octet-stream",this.extension.match(/(png)$/i)&&(s="image/png"),this.extension.match(/(jpg|jpeg)$/i)&&(s="image/jpeg"),this.extension.match(/(gif)$/i)&&(s="image/gif")),this.contentType=s,GameLib.Utils.UndefinedOrNull(o)&&(o=0),this.size=o,GameLib.Utils.UndefinedOrNull(r)&&(r=null),this.parentEntity=r},GameLib.D3.API.Image.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.API.Image.prototype.constructor=GameLib.D3.API.Image,GameLib.D3.API.Image.FromObject=function(e){return new GameLib.D3.API.Image(e.id,e.name,e.fileName,e.extension,e.path,e.contentType,e.size,e.parentEntity)},GameLib.D3.API.Light=function(e,t,i,n,a,s,o,r,c,h,m,l,p,u,b,d,L){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t=GameLib.D3.Light.LIGHT_TYPE_AMBIENT),this.lightType=t,GameLib.Utils.UndefinedOrNull(i)&&(this.lightType===GameLib.D3.Light.LIGHT_TYPE_AMBIENT&&(i="Ambient "),this.lightType===GameLib.D3.Light.LIGHT_TYPE_DIRECTIONAL&&(i="Directional "),this.lightType===GameLib.D3.Light.LIGHT_TYPE_POINT&&(i="Point "),this.lightType===GameLib.D3.Light.LIGHT_TYPE_SPOT&&(i="Spot "),i+="Light ("+e+")"),this.name=i,GameLib.Utils.UndefinedOrNull(n)&&(n=new GameLib.API.Color(1,1,1,1)),this.color=n,GameLib.Utils.UndefinedOrNull(a)&&(a=1),this.intensity=a,GameLib.Utils.UndefinedOrNull(s)&&(s=new GameLib.API.Vector3(10,10,10)),this.position=s,GameLib.Utils.UndefinedOrNull(o)&&(o=new GameLib.API.Vector3(0,0,0)),this.targetPosition=o,GameLib.Utils.UndefinedOrNull(r)&&(r=new GameLib.API.Quaternion),this.quaternion=r,GameLib.Utils.UndefinedOrNull(c)&&(c=new GameLib.API.Vector3(0,0,0)),this.rotation=c,GameLib.Utils.UndefinedOrNull(h)&&(h=new GameLib.API.Vector3(1,1,1)),this.scale=h,GameLib.Utils.UndefinedOrNull(m)&&(m=0),this.distance=m,GameLib.Utils.UndefinedOrNull(l)&&(l=1),this.decay=l,GameLib.Utils.UndefinedOrNull(p)&&(p=4*Math.PI),this.power=p,GameLib.Utils.UndefinedOrNull(u)&&(u=Math.PI/3),this.angle=u,GameLib.Utils.UndefinedOrNull(b)&&(b=0),this.penumbra=b,GameLib.Utils.UndefinedOrNull(d)&&(d=null),this.parentScene=d,GameLib.Utils.UndefinedOrNull(L)&&(L=null),this.parentEntity=L},GameLib.D3.API.Light.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.API.Light.prototype.constructor=GameLib.D3.API.Light,GameLib.D3.API.Light.FromObject=function(e){return new GameLib.D3.API.Light(e.id,e.lightType,e.name,GameLib.API.Color.FromObject(e.color),e.intensity,GameLib.API.Vector3.FromObject(e.position),GameLib.API.Vector3.FromObject(e.targetPosition),GameLib.API.Quaternion.FromObject(e.quaternion),GameLib.API.Vector3.FromObject(e.rotation),GameLib.API.Vector3.FromObject(e.scale),e.distance,e.decay,e.power,e.angle,e.penumbra,e.parentScene,e.parentEntity)},GameLib.D3.API.LookAt=function(e,t,i,n,a,s,o){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t=this.constructor.name),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=null),this.currentComponent=i,GameLib.Utils.UndefinedOrNull(n)&&(n=null),this.targetComponent=n,GameLib.Utils.UndefinedOrNull(a)&&(a=new GameLib.API.Vector3(0,0,0)),this.targetPositionOffset=a,GameLib.Utils.UndefinedOrNull(s)&&(s=22),this.rotationSpeed=s,this.lookAtMatrix=new GameLib.API.Matrix4,this.up=new GameLib.API.Vector3(0,1,0),this.currentRotation=new GameLib.API.Quaternion,this.targetPosition=new GameLib.API.Vector3,GameLib.Utils.UndefinedOrNull(o)&&(o=null),this.parentEntity=o},GameLib.D3.API.LookAt.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.API.LookAt.prototype.constructor=GameLib.D3.API.LookAt,GameLib.D3.API.LookAt.FromObject=function(e){return new GameLib.D3.API.LookAt(e.id,e.name,e.currentComponent,e.targetComponent,GameLib.API.Vector3.FromObject(e.targetPositionOffset),e.rotationSpeed,e.parentEntity)},GameLib.D3.API.Material=function(e,t,i,n,a,s,o,r,c,h,m,l,p,u,b,d,L,G,f,E,y,O,I,T,D,P,A,g,N,C,U,S,M,v,_,w,x,R,F,j,Y,V,H,z,q,B,k,W,Q,X,K,Z,J,$,ee,te,ie,ne,ae,se,oe,re,ce,he,me,le,pe,ue,be){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t=GameLib.D3.Material.MATERIAL_TYPE_STANDARD),this.materialType=t,GameLib.Utils.UndefinedOrNull(i)&&(i="Material ("+t+")"),this.name=i,GameLib.Utils.UndefinedOrNull(n)&&(n=1),this.opacity=n,GameLib.Utils.UndefinedOrNull(a)&&(a=GameLib.D3.Material.TYPE_FRONT_SIDE),this.side=a,GameLib.Utils.UndefinedOrNull(s)&&(s=!1),this.transparent=s,GameLib.Utils.UndefinedOrNull(o)&&(o=new GameLib.API.Color(.06,.06,.06,.06)),this.specular=o,GameLib.Utils.UndefinedOrNull(r)&&(r=1),this.lightMapIntensity=r,GameLib.Utils.UndefinedOrNull(c)&&(c=1),this.aoMapIntensity=c,GameLib.Utils.UndefinedOrNull(h)&&(h=new GameLib.API.Color(1,1,1,1)),this.color=h,GameLib.Utils.UndefinedOrNull(m)&&(m=new GameLib.API.Color(0,0,0,0)),this.emissive=m,GameLib.Utils.UndefinedOrNull(l)&&(l=1),this.emissiveIntensity=l,GameLib.Utils.UndefinedOrNull(p)&&(p=GameLib.D3.Material.TYPE_MULTIPLY_OPERATION),this.combine=p,GameLib.Utils.UndefinedOrNull(u)&&(u=30),this.shininess=u,GameLib.Utils.UndefinedOrNull(b)&&(b=1),this.reflectivity=b,GameLib.Utils.UndefinedOrNull(d)&&(d=.98),this.refractionRatio=d,GameLib.Utils.UndefinedOrNull(L)&&(L=!0),this.fog=L,GameLib.Utils.UndefinedOrNull(G)&&(G=!1),this.wireframe=G,GameLib.Utils.UndefinedOrNull(f)&&(f=1),this.wireframeLineWidth=f,GameLib.Utils.UndefinedOrNull(E)&&(E="round"),this.wireframeLineCap=E,GameLib.Utils.UndefinedOrNull(y)&&(y="round"),this.wireframeLineJoin=y,GameLib.Utils.UndefinedOrNull(O)&&(O=GameLib.D3.Material.TYPE_NO_COLORS),this.vertexColors=O,GameLib.Utils.UndefinedOrNull(I)&&(I=!1),this.skinning=I,GameLib.Utils.UndefinedOrNull(T)&&(T=!1),this.morphTargets=T,GameLib.Utils.UndefinedOrNull(D)&&(D=!1),this.morphNormals=D,GameLib.Utils.UndefinedOrNull(q)&&(q=0),this.overdraw=q,GameLib.Utils.UndefinedOrNull(P)&&(P=1),this.lineWidth=P,GameLib.Utils.UndefinedOrNull(A)&&(A="round"),this.lineCap=A,GameLib.Utils.UndefinedOrNull(g)&&(g="round"),this.lineJoin=g,GameLib.Utils.UndefinedOrNull(N)&&(N=3),this.dashSize=N,GameLib.Utils.UndefinedOrNull(C)&&(C=1),this.gapWidth=C,GameLib.Utils.UndefinedOrNull(U)&&(U=GameLib.D3.Material.TYPE_NORMAL_BLENDING),this.blending=U,GameLib.Utils.UndefinedOrNull(S)&&(S=GameLib.D3.Material.TYPE_SRC_ALPHA_FACTOR),this.blendSrc=S,GameLib.Utils.UndefinedOrNull(M)&&(M=GameLib.D3.Material.TYPE_ONE_MINUS_SRC_ALPHA_FACTOR),this.blendDst=M,GameLib.Utils.UndefinedOrNull(v)&&(v=GameLib.D3.Material.TYPE_ADD_EQUATION),this.blendEquation=v,GameLib.Utils.UndefinedOrNull(_)&&(_=!0),this.depthTest=_,GameLib.Utils.UndefinedOrNull(w)&&(w=GameLib.D3.Material.TYPE_LESS_EQUAL_DEPTH),this.depthFunc=w,GameLib.Utils.UndefinedOrNull(x)&&(x=!0),this.depthWrite=x,GameLib.Utils.UndefinedOrNull(R)&&(R=!1),this.polygonOffset=R,GameLib.Utils.UndefinedOrNull(F)&&(F=1),this.polygonOffsetFactor=F,GameLib.Utils.UndefinedOrNull(j)&&(j=1),this.polygonOffsetUnits=j,GameLib.Utils.UndefinedOrNull(Y)&&(Y=0),this.alphaTest=Y,GameLib.Utils.UndefinedOrNull(V)&&(V=[]),this.clippingPlanes=V,GameLib.Utils.UndefinedOrNull(H)&&(H=!1),this.clipShadows=H,GameLib.Utils.UndefinedOrNull(z)&&(z=!0),this.visible=z,GameLib.Utils.UndefinedOrNull(B)&&(B=!1),this.flatShading=B,GameLib.Utils.UndefinedOrNull(k)&&(k=1),this.bumpScale=k,GameLib.Utils.UndefinedOrNull(W)&&(W=1),this.normalScale=W,GameLib.Utils.UndefinedOrNull(Q)&&(Q=1),this.displacementScale=Q,GameLib.Utils.UndefinedOrNull(X)&&(X=0),this.displacementBias=X,GameLib.Utils.UndefinedOrNull(K)&&(K=.5),this.roughness=K,GameLib.Utils.UndefinedOrNull(Z)&&(Z=.5),this.metalness=Z,GameLib.Utils.UndefinedOrNull(J)&&(J=1),this.pointSize=J,GameLib.Utils.UndefinedOrNull($)&&($=!0),this.pointSizeAttenuation=$,GameLib.Utils.UndefinedOrNull(ee)&&(ee=0),this.spriteRotation=ee,GameLib.Utils.UndefinedOrNull(te)&&(te=1),this.envMapIntensity=te,GameLib.Utils.UndefinedOrNull(ie)&&(ie=null),this.alphaMap=ie,GameLib.Utils.UndefinedOrNull(ne)&&(ne=null),this.aoMap=ne,GameLib.Utils.UndefinedOrNull(ae)&&(ae=null),this.bumpMap=ae,GameLib.Utils.UndefinedOrNull(se)&&(se=null),this.diffuseMap=se,GameLib.Utils.UndefinedOrNull(oe)&&(oe=null),this.displacementMap=oe,GameLib.Utils.UndefinedOrNull(re)&&(re=null),this.emissiveMap=re,GameLib.Utils.UndefinedOrNull(ce)&&(ce=null),this.environmentMap=ce,GameLib.Utils.UndefinedOrNull(he)&&(he=null),this.lightMap=he,GameLib.Utils.UndefinedOrNull(me)&&(me=null),this.metalnessMap=me,GameLib.Utils.UndefinedOrNull(le)&&(le=null),this.normalMap=le,GameLib.Utils.UndefinedOrNull(pe)&&(pe=null),this.roughnessMap=pe,GameLib.Utils.UndefinedOrNull(ue)&&(ue=null),this.specularMap=ue,GameLib.Utils.UndefinedOrNull(be)&&(be=null),this.parentEntity=be,this.needsUpdate=!1},GameLib.D3.API.Material.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.API.Material.prototype.constructor=GameLib.D3.API.Material,GameLib.D3.API.Material.FromObject=function(e){var t=null,i=null,n=null,a=null,s=null,o=null,r=null,c=null,h=null,m=null,l=null,p=null;return e.alphaMap&&(t=e.alphaMap),e.aoMap&&(i=e.aoMap),e.bumpMap&&(n=e.bumpMap),e.diffuseMap&&(a=e.diffuseMap),e.displacementMap&&(s=e.displacementMap),e.emissiveMap&&(o=e.emissiveMap),e.environmentMap&&(r=e.environmentMap),e.lightMap&&(c=e.lightMap),e.metalnessMap&&(h=e.metalnessMap),e.normalMap&&(m=e.normalMap),e.roughnessMap&&(l=e.roughnessMap),e.specularMap&&(p=e.specularMap),new GameLib.D3.API.Material(e.id,e.materialType,e.name,e.opacity,e.side,e.transparent,GameLib.API.Color.FromObject(e.specular),e.lightMapIntensity,e.aoMapIntensity,GameLib.API.Color.FromObject(e.color),GameLib.API.Color.FromObject(e.emissive),e.emissiveIntensity,e.combine,e.shininess,e.reflectivity,e.refractionRatio,e.fog,e.wireframe,e.wireframeLineWidth,e.wireframeLineCap,e.wireframeLineJoin,e.vertexColors,e.skinning,e.morphTargets,e.morphNormals,e.lineWidth,e.lineCap,e.lineJoin,e.dashSize,e.gapWidth,e.blending,e.blendSrc,e.blendDst,e.blendEquation,e.depthTest,e.depthFunc,e.depthWrite,e.polygonOffset,e.polygonOffsetFactor,e.polygonOffsetUnits,e.alphaTest,e.clippingPlanes,e.clipShadows,e.visible,e.overdraw,e.flatShading,e.bumpScale,e.normalScale,e.displacementScale,e.displacementBias,e.roughness,e.metalness,e.pointSize,e.pointSizeAttenuation,e.spriteRotation,e.envMapIntensity,t,i,n,a,s,o,r,c,h,m,l,p,e.parentEntity)},GameLib.D3.API.Mesh=function(e,t,i,n,a,s,o,r,c,h,m,l,p,u,b,d,L,G,f,E,y,O){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t=GameLib.D3.Mesh.MESH_TYPE_NORMAL),this.meshType=t,GameLib.Utils.UndefinedOrNull(i)&&(i="Mesh ("+e+")"),this.name=i,GameLib.Utils.UndefinedOrNull(n)&&(n=[]),this.vertices=n,GameLib.Utils.UndefinedOrNull(a)&&(a=[]),this.faces=a,GameLib.Utils.UndefinedOrNull(o)&&(o=null),this.parentMesh=o,GameLib.Utils.UndefinedOrNull(r)&&(r=null),this.parentScene=r,GameLib.Utils.UndefinedOrNull(c)&&(c=null),this.skeleton=c,GameLib.Utils.UndefinedOrNull(h)&&(h=[]),this.skinIndices=h,GameLib.Utils.UndefinedOrNull(m)&&(m=[]),this.skinWeights=m,(GameLib.Utils.UndefinedOrNull(s)||s instanceof Array&&0===s.length)&&(s=[new GameLib.D3.API.Material(null,GameLib.D3.Material.MATERIAL_TYPE_STANDARD,"Material ("+this.name+")")]),this.materials=s,GameLib.Utils.UndefinedOrNull(l)&&(l=new GameLib.API.Vector3(0,0,0)),this.position=l,GameLib.Utils.UndefinedOrNull(p)&&(p=new GameLib.API.Quaternion),this.quaternion=p,GameLib.Utils.UndefinedOrNull(u)&&(u=new GameLib.API.Vector3(0,0,0)),this.rotation=u,GameLib.Utils.UndefinedOrNull(b)&&(b=new GameLib.API.Vector3(1,1,1)),this.scale=b,GameLib.Utils.UndefinedOrNull(d)&&(d=new GameLib.API.Vector3(0,1,0)),this.up=d,GameLib.Utils.UndefinedOrNull(L)&&(L=new GameLib.API.Matrix4),this.modelMatrix=L,GameLib.Utils.UndefinedOrNull(f)&&(f=0),this.renderOrder=f,GameLib.Utils.UndefinedOrNull(G)&&(G=null),this.parentEntity=G,GameLib.Utils.UndefinedOrNull(E)&&(E=!1),this.isBufferMesh=E,GameLib.Utils.UndefinedOrNull(y)&&(y=!0),this.useQuaternion=y,GameLib.Utils.UndefinedOrNull(O)&&(O=!0),this.visible=O},GameLib.D3.API.Mesh.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.API.Mesh.prototype.constructor=GameLib.D3.API.Mesh,GameLib.D3.API.Mesh.FromObject=function(e){var t=[];e.faces&&(t=e.faces.map(function(e){return GameLib.D3.API.Face.FromObject(e)}));var i=null;e.skeleton&&(i=GameLib.D3.API.Skeleton.FromObject(e.skeleton));var n=[];e.materials&&(n=e.materials.map(function(e){return e instanceof Object?GameLib.D3.API.Material.FromObject(e):e}));var a=[];e.vertices&&(a=e.vertices.map(function(e){return GameLib.D3.API.Vertex.FromObject(e)}));var s=new GameLib.API.Vector3;e.position&&(s=GameLib.API.Vector3.FromObject(e.position));var o=new GameLib.API.Vector3;e.rotation&&(o=GameLib.API.Vector3.FromObject(e.rotation));var r=new GameLib.API.Quaternion;e.quaternion&&(r=GameLib.API.Quaternion.FromObject(e.quaternion));var c=new GameLib.API.Vector3(1,1,1);e.scale&&(c=GameLib.API.Vector3.FromObject(e.scale));var h=new GameLib.API.Vector3(0,1,0);e.up&&(h=GameLib.API.Vector3.FromObject(e.up));var m=new GameLib.API.Matrix4;return e.modelMatrix&&(m=GameLib.API.Matrix4.FromObject(e.modelMatrix)),new GameLib.D3.API.Mesh(e.id,e.meshType,e.name,a,t,n,e.parentMesh,e.parentScene,i,e.skinIndices,e.skinWeights,s,r,o,c,h,m,e.parentEntity,e.renderOrder,e.isBufferMesh,e.useQuaternion,e.visible)},GameLib.D3.API.ParticleEngine=function(e,t,i,n,a,s,o,r,c,h,m,l){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="ParticleEngine ("+this.id+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=new GameLib.API.Vector3(0,0,0)),this.position=i,GameLib.Utils.UndefinedOrNull(n)&&(n=new GameLib.API.Vector3(0,1,0)),this.direction=n,GameLib.Utils.UndefinedOrNull(a)&&(a=!1),this.enabled=a,GameLib.Utils.UndefinedOrNull(s)&&(s=null),this.templateParticle=s,GameLib.Utils.UndefinedOrNull(o)&&(o=1),this.particlesPerSecond=o,GameLib.Utils.UndefinedOrNull(r)&&(r=Number(1/Number(this.particlesPerSecond))),this.frequency=r,GameLib.Utils.UndefinedOrNull(c)&&(c=0),this.elapsed=c,GameLib.Utils.UndefinedOrNull(h)&&(h=null),this.camera=h,GameLib.Utils.UndefinedOrNull(m)&&(m=!1),this.pulse=m,GameLib.Utils.UndefinedOrNull(l)&&(l=null),this.parentEntity=l},GameLib.D3.API.ParticleEngine.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.API.ParticleEngine.prototype.constructor=GameLib.D3.API.ParticleEngine,GameLib.D3.API.ParticleEngine.FromObject=function(e){var t=null;e.templateParticle&&(t=e.templateParticle instanceof Object?GameLib.D3.API.Particle.FromObject(e.templateParticle):e.templateParticle);var i=null;e.camera&&(i=e.camera instanceof Object?GameLib.D3.API.Camera.FromObject(e.camera):e.camera);var n=null;e.position&&(n=GameLib.API.Vector3.FromObject(e.position));var a=null;return e.direction&&(a=GameLib.API.Vector3.FromObject(e.direction)),new GameLib.D3.API.ParticleEngine(e.id,e.name,n,a,e.enabled,t,e.particlesPerSecond,e.frequency,e.elapsed,i,e.pulse,e.parentEntity)},GameLib.D3.API.Particle=function(e,t,i,n,a,s,o,r,c,h,m,l,p,u,b,d,L,G,f,E,y,O,I){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="Particle ("+this.id+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=10),this.lifeTime=i,GameLib.Utils.UndefinedOrNull(n)&&(n=0),this.elapsed=n,GameLib.Utils.UndefinedOrNull(a)&&(a=null),this.mesh=a,GameLib.Utils.UndefinedOrNull(s)&&(s=GameLib.D3.Particle.OPACITY_TYPE_CONSTANT),this.opacityType=s,GameLib.Utils.UndefinedOrNull(o)&&(o=.01),this.opacityFactor=o,GameLib.Utils.UndefinedOrNull(r)&&(r=GameLib.D3.Particle.POSITION_OFFSET_TYPE_CONSTANT),this.positionOffsetType=r,GameLib.Utils.UndefinedOrNull(c)&&(c=new GameLib.API.Vector3(0,0,0)),this.positionOffset=c,GameLib.Utils.UndefinedOrNull(h)&&(h="//@ sourceURL=positionOffsetFn.js"),this.positionOffsetFn=h,GameLib.Utils.UndefinedOrNull(m)&&(m=GameLib.D3.Particle.DIRECTION_TYPE_CONSTANT),this.directionType=m,GameLib.Utils.UndefinedOrNull(l)&&(l=new GameLib.API.Vector3(0,1,0)),this.direction=l,GameLib.Utils.UndefinedOrNull(p)&&(p="//@ sourceURL=directionFn.js"),this.directionFn=p,GameLib.Utils.UndefinedOrNull(u)&&(u=GameLib.D3.Particle.SPEED_TYPE_CONSTANT),this.speedType=u,GameLib.Utils.UndefinedOrNull(b)&&(b=1),this.speed=b,GameLib.Utils.UndefinedOrNull(d)&&(d=GameLib.D3.Particle.SCALE_TYPE_CONSTANT),this.scaleType=d,GameLib.Utils.UndefinedOrNull(L)&&(L=new GameLib.API.Vector3(1,1,1)),this.scale=L,GameLib.Utils.UndefinedOrNull(G)&&(G="//@ sourceURL=scaleFn.js"),this.scaleFn=G,GameLib.Utils.UndefinedOrNull(f)&&(f=GameLib.D3.Particle.ROTATION_TYPE_CONSTANT),this.rotationType=f,GameLib.Utils.UndefinedOrNull(E)&&(E=new GameLib.API.Vector3(0,0,0)),this.rotation=E,GameLib.Utils.UndefinedOrNull(y)&&(y="//@ sourceURL=rotationFn.js"),this.rotationFn=y,GameLib.Utils.UndefinedOrNull(O)&&(O=null),this.parentEngine=O,GameLib.Utils.UndefinedOrNull(I)&&(I=null),this.parentEntity=I},GameLib.D3.API.Particle.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.API.Particle.prototype.constructor=GameLib.D3.API.Particle,GameLib.D3.API.Particle.FromObject=function(e){var t=null;return e.mesh&&(t=e.mesh instanceof Object?GameLib.D3.API.Mesh.FromObject(e.mesh):e.mesh),new GameLib.D3.API.Particle(e.id,e.name,e.lifeTime,e.elapsed,t,e.opacityType,e.opacityFactor,e.positionOffsetType,GameLib.API.Vector3.FromObject(e.positionOffset),e.positionOffsetFn,e.directionType,GameLib.API.Vector3.FromObject(e.direction),e.directionFn,e.speedType,e.speed,e.scaleType,GameLib.API.Vector3.FromObject(e.scale),e.scaleFn,e.rotationType,GameLib.API.Vector3.FromObject(e.rotation),e.rotationFn,e.parentEngine,e.parentEntity)},GameLib.D3.API.Pass=function(e,t,i,n,a,s,o){if(GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="Pass ("+e+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=GameLib.D3.Pass.PASS_TYPE_RENDER),this.passType=i,GameLib.Utils.UndefinedOrNull(n)&&(n=null),this.camera=n,GameLib.Utils.UndefinedOrNull(a)&&(a=null),this.scene=a,GameLib.Utils.UndefinedOrNull(s))if(this.passType===GameLib.D3.Pass.PASS_TYPE_RENDER)s=!1;else{if(!GameLib.D3.Pass.PASS_TYPE_COPY_SHADER)throw console.warn("Unsupported Render Pass Type : "+this.passType),new Error("Unsupported Render Pass Type : "+this.passType);s=!0}this.renderToScreen=s,GameLib.Utils.UndefinedOrNull(o)&&(o=null),this.parentEntity=o},GameLib.D3.API.Pass.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.API.Pass.prototype.constructor=GameLib.D3.API.Pass,GameLib.D3.API.Pass.FromObject=function(e){return new GameLib.D3.API.Pass(e.id,e.name,e.passType,e.camera,e.scene,e.renderToScreen,e.parentEntity)},GameLib.D3.API.PathFollowing=function(e,t,i,n,a,s,o,r,c,h,m,l,p,u,b,d,L,G,f,E,y,O){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t=this.constructor.name),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=null),this.spline=i,GameLib.Utils.UndefinedOrNull(n)&&(n=null),this.mesh=n,GameLib.Utils.UndefinedOrNull(a)&&(a=null),this.raytraceMesh=a,GameLib.Utils.UndefinedOrNull(o)&&(o=.03),this.maxSpeed=o,GameLib.Utils.UndefinedOrNull(s)&&(s=.1),this.accelleration=s,GameLib.Utils.UndefinedOrNull(r)&&(r=new GameLib.API.Vector3),this.baseOffset=r,GameLib.Utils.UndefinedOrNull(c)&&(c=new GameLib.API.Vector3),this.maxOffset=c,GameLib.Utils.UndefinedOrNull(h)&&(h=1),this.steeringSpeed=h,GameLib.Utils.UndefinedOrNull(m)&&(m=new GameLib.API.Vector3),this.targetOffset=m,GameLib.Utils.UndefinedOrNull(l)&&(l=new GameLib.API.Vector3),this.currentOffset=l,GameLib.Utils.UndefinedOrNull(p)&&(p=0),this.currentPathValue=p,GameLib.Utils.UndefinedOrNull(u)&&(u=0),this.currentSpeed=u,GameLib.Utils.UndefinedOrNull(b)&&(b=1),this.direction=b,GameLib.Utils.UndefinedOrNull(d)&&(d=new GameLib.D3.API.Raycaster),this.raycaster=d,GameLib.Utils.UndefinedOrNull(L)&&(L=new GameLib.API.Vector3),this.currentPosition=L,GameLib.Utils.UndefinedOrNull(G)&&(G=new GameLib.API.Vector3),this.futurePosition=G,GameLib.Utils.UndefinedOrNull(f)&&(f=new GameLib.API.Vector3(0,1,0)),this.up=f,GameLib.Utils.UndefinedOrNull(E)&&(E=new GameLib.API.Matrix4),this.rotationMatrix=E,GameLib.Utils.UndefinedOrNull(y)&&(y=new GameLib.API.Quaternion),this.rotationVector=y,GameLib.Utils.UndefinedOrNull(O)&&(O=null),this.parentEntity=O},GameLib.D3.API.PathFollowing.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.API.PathFollowing.prototype.constructor=GameLib.D3.API.PathFollowing,GameLib.D3.API.PathFollowing.FromObject=function(e){var t=null;return e.raycaster&&(t=GameLib.D3.API.Raycaster.FromObject(e.raycaster)),new GameLib.D3.API.PathFollowing(e.id,e.name,e.spline,e.mesh,e.raytraceMesh,e.accelleration,e.maxSpeed,GameLib.API.Vector3.FromObject(e.baseOffset),GameLib.API.Vector3.FromObject(e.maxOffset),e.steeringSpeed,GameLib.API.Vector3.FromObject(e.targetOffset),GameLib.API.Vector3.FromObject(e.currentOffset),e.currentPathValue,e.currentSpeed,e.direction,t,GameLib.API.Vector3.FromObject(e.currentPosition),GameLib.API.Vector3.FromObject(e.futurePosition),GameLib.API.Vector3.FromObject(e.up),GameLib.API.Matrix4.FromObject(e.rotationMatrix),GameLib.API.Quaternion.FromObject(e.rotationVector),e.parentEntity)},GameLib.D3.API.PhysicsWorld=function(e,t,i,n,a,s,o,r,c,h){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="Physics World ("+this.id+")"),this.name=t, -GameLib.Utils.UndefinedOrNull(i)&&(i=new GameLib.API.Vector3(0,-9.81,0)),this.gravity=i,GameLib.Utils.UndefinedOrNull(n)&&(n=new GameLib.D3.API.Broadphase(null,"Broadphase (Physics World "+this.id+")")),this.broadphase=n,GameLib.Utils.UndefinedOrNull(a)&&(a=new GameLib.D3.API.Solver(null,"Solver (Physics World "+this.id+")")),this.solver=a,GameLib.Utils.UndefinedOrNull(s)&&(s=[]),this.rigidBodies=s,GameLib.Utils.UndefinedOrNull(o)&&(o=[]),this.contactMaterials=o,GameLib.Utils.UndefinedOrNull(r)&&(r=!0),this.allowSleep=r,GameLib.Utils.UndefinedOrNull(c)&&(c=new GameLib.D3.API.FrictionContactMaterial(null,"Default Contact Material (Physics World "+this.id+")")),this.defaultContactMaterial=c,GameLib.Utils.UndefinedOrNull(h)&&(h=null),this.parentEntity=h},GameLib.D3.API.PhysicsWorld.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.API.PhysicsWorld.prototype.constructor=GameLib.D3.API.PhysicsWorld,GameLib.D3.API.PhysicsWorld.FromObject=function(e){return new GameLib.D3.API.PhysicsWorld(e.id,e.name,GameLib.API.Vector3.FromObject(e.gravity),e.broadphase,e.solver,e.rigidBodies,e.contactMaterials,e.allowSleep,e.defaultContactMaterial,e.parentEntity)},GameLib.D3.API.RaycastVehicle=function(e,t,i,n,a,s,o){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="RaycastVehicle ("+this.id+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=null),this.chassis=i,GameLib.Utils.UndefinedOrNull(n)&&(n=[]),this.wheels=n,GameLib.Utils.UndefinedOrNull(a)&&(a=[]),this.raycastWheels=a,GameLib.Utils.UndefinedOrNull(s)&&(s=null),this.parentWorld=s,GameLib.Utils.UndefinedOrNull(o)&&(o=null),this.parentEntity=o},GameLib.D3.API.RaycastVehicle.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.API.RaycastVehicle.prototype.constructor=GameLib.D3.API.RaycastVehicle,GameLib.D3.API.RaycastVehicle.FromObject=function(e){return new GameLib.D3.API.RaycastVehicle(e.id,e.name,e.chassis,e.wheels,e.raycastWheels,e.parentWorld,e.parentEntity)},GameLib.D3.API.RaycastWheel=function(e,t,i,n,a,s,o,r,c,h,m,l,p,u,b,d,L,G){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="RaycastWheel ("+this.id+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=.5),this.radius=i,GameLib.Utils.UndefinedOrNull(n)&&(n=new GameLib.API.Vector3(0,0,-1)),this.directionLocal=n,GameLib.Utils.UndefinedOrNull(a)&&(a=30),this.suspensionStiffness=a,GameLib.Utils.UndefinedOrNull(s)&&(s=.3),this.suspensionRestLength=s,GameLib.Utils.UndefinedOrNull(o)&&(o=5),this.frictionSlip=o,GameLib.Utils.UndefinedOrNull(r)&&(r=2.3),this.dampingRelaxation=r,GameLib.Utils.UndefinedOrNull(c)&&(c=4.4),this.dampingCompression=c,GameLib.Utils.UndefinedOrNull(h)&&(h=1e5),this.maxSuspensionForce=h,GameLib.Utils.UndefinedOrNull(m)&&(m=.01),this.rollInfluence=m,GameLib.Utils.UndefinedOrNull(l)&&(l=new GameLib.API.Vector3(0,1,0)),this.axleLocal=l,GameLib.Utils.UndefinedOrNull(p)&&(p=new GameLib.API.Vector3(1,1,0)),this.chassisConnectionPointLocal=p,GameLib.Utils.UndefinedOrNull(u)&&(u=.3),this.maxSuspensionTravel=u,GameLib.Utils.UndefinedOrNull(b)&&(b=-30),this.customSlidingRotationalSpeed=b,GameLib.Utils.UndefinedOrNull(d)&&(d=!0),this.useCustomSlidingRotationalSpeed=d,GameLib.Utils.UndefinedOrNull(L)&&(L=null),this.parentEntity=L,GameLib.Utils.UndefinedOrNull(G)&&(G=null),this.parentMesh=G},GameLib.D3.API.RaycastWheel.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.API.RaycastWheel.prototype.constructor=GameLib.D3.API.RaycastWheel,GameLib.D3.API.RaycastWheel.FromObject=function(e){return new GameLib.D3.API.RaycastWheel(e.id,e.name,e.radius,e.directionLocal,e.suspensionStiffness,e.suspensionRestLength,e.frictionSlip,e.dampingRelaxation,e.dampingCompression,e.maxSuspensionForce,e.rollInfluence,e.axleLocal,e.chassisConnectionPointLocal,e.maxSuspensionTravel,e.customSlidingRotationalSpeed,e.useCustomSlidingRotationalSpeed,e.parentEntity,e.parentMesh)},GameLib.D3.API.Raycaster=function(e,t,i,n){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="Raycaster ("+this.id+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=new GameLib.API.Vector3),this.position=i,GameLib.Utils.UndefinedOrNull(n)&&(n=new GameLib.API.Vector3(0,-1,0)),this.direction=n},GameLib.D3.API.Raycaster.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.API.Raycaster.prototype.constructor=GameLib.D3.API.Raycaster,GameLib.D3.API.Raycaster.FromObject=function(e){return new GameLib.D3.API.Raycaster(e.id,e.name,GameLib.API.Vector3.FromObject(e.position),GameLib.API.Vector3.FromObject(e.direction))},GameLib.D3.API.RenderTarget=function(e,t,i,n,a,s,o){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="Render Target ("+e+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=800),this.width=i,GameLib.Utils.UndefinedOrNull(n)&&(n=600),this.height=n,GameLib.Utils.UndefinedOrNull(a)&&(a=!1),this.stencilBuffer=a,GameLib.Utils.UndefinedOrNull(s)&&(s=null),this.texture=s,GameLib.Utils.UndefinedOrNull(o)&&(o=null),this.parentEntity=o},GameLib.D3.API.RenderTarget.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.API.RenderTarget.prototype.constructor=GameLib.D3.API.RenderTarget,GameLib.D3.API.RenderTarget.FromObject=function(e){return new GameLib.D3.API.RenderTarget(e.id,e.name,e.width,e.height,e.stencilBuffer,e.texture,e.parentEntity)},GameLib.D3.API.Renderer=function(e,t,i,n,a,s,o,r,c,h,m,l,p,u,b,d,L,G,f){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="Renderer ("+this.id+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=!0),this.autoClear=i,GameLib.Utils.UndefinedOrNull(n)&&(n=!1,p&&p.length>0&&(n=!0)),this.localClipping=n,GameLib.Utils.UndefinedOrNull(a)&&(a=800),this.width=a,GameLib.Utils.UndefinedOrNull(s)&&(s=600),this.height=s,GameLib.Utils.UndefinedOrNull(o)&&(o=!1),this.preserveDrawingBuffer=o,GameLib.Utils.UndefinedOrNull(r)&&(r=null),this.domElement=r,GameLib.Utils.UndefinedOrNull(c)&&(c=new GameLib.API.Color(.11,.11,.11)),this.clearColor=c,GameLib.Utils.UndefinedOrNull(h)&&(h=null),this.camera=h,GameLib.Utils.UndefinedOrNull(m)&&(m=[]),this.scenes=m,GameLib.Utils.UndefinedOrNull(l)&&(l=[]),this.viewports=l,GameLib.Utils.UndefinedOrNull(p)&&(p=[]),this.clippingPlanes=p,GameLib.Utils.UndefinedOrNull(u)&&(u=null),this.bufferScene=u,GameLib.Utils.UndefinedOrNull(b)&&(b=h),this.bufferCamera=b,GameLib.Utils.UndefinedOrNull(d)&&(d=null),this.renderTarget=d,GameLib.Utils.UndefinedOrNull(L)&&(L=null),this.defaultScene=L,GameLib.Utils.UndefinedOrNull(G)&&(G=!0),this.sortObjects=G,GameLib.Utils.UndefinedOrNull(f)&&(f=null),this.parentEntity=f},GameLib.D3.API.Renderer.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.API.Renderer.prototype.constructor=GameLib.D3.API.Renderer,GameLib.D3.API.Renderer.FromObject=function(e){return new GameLib.D3.API.Renderer(e.id,e.name,e.autoClear,e.localClipping,e.width,e.height,e.preserveDrawingBuffer,e.domElement,e.clearColor,e.camera,e.scenes,e.viewports,e.clippingPlanes,e.bufferScene,e.bufferCamera,e.renderTarget,e.defaultScene,e.sortObjects,e.parentEntity)},GameLib.D3.API.RigidBody=function(e,t,i,n,a,s,o,r,c,h,m,l,p,u,b,d,L,G,f,E,y){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="RigidBody ("+this.id+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=0),this.mass=i,GameLib.Utils.UndefinedOrNull(n)&&(n=5),this.friction=n,GameLib.Utils.UndefinedOrNull(a)&&(a=new GameLib.API.Vector3(0,0,0)),this.position=a,GameLib.Utils.UndefinedOrNull(s)&&(s=new GameLib.API.Quaternion),this.quaternion=s,GameLib.Utils.UndefinedOrNull(o)&&(o=new GameLib.API.Vector3),this.velocity=o,GameLib.Utils.UndefinedOrNull(r)&&(r=new GameLib.API.Vector3),this.angularVelocity=r,GameLib.Utils.UndefinedOrNull(c)&&(c=.01),this.linearDamping=c,GameLib.Utils.UndefinedOrNull(h)&&(h=.01),this.angularDamping=h,GameLib.Utils.UndefinedOrNull(m)&&(m=!0),this.allowSleep=m,GameLib.Utils.UndefinedOrNull(l)&&(l=.1),this.sleepSpeedLimit=l,GameLib.Utils.UndefinedOrNull(p)&&(p=1),this.sleepTimeLimit=p,GameLib.Utils.UndefinedOrNull(u)&&(u=1),this.collisionFilterGroup=u,GameLib.Utils.UndefinedOrNull(b)&&(b=1),this.collisionFilterMask=b,GameLib.Utils.UndefinedOrNull(d)&&(d=!1),this.fixedRotation=d,GameLib.Utils.UndefinedOrNull(L)&&(L=[]),this.shapes=L,GameLib.Utils.UndefinedOrNull(G)&&(G=!1),this.kinematic=G,GameLib.Utils.UndefinedOrNull(f)&&(f=null),this.parentMesh=f,GameLib.Utils.UndefinedOrNull(E)&&(E=null),this.parentWorld=E,GameLib.Utils.UndefinedOrNull(y)&&(y=null),this.parentEntity=y},GameLib.D3.API.RigidBody.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.API.RigidBody.prototype.constructor=GameLib.D3.API.RigidBody,GameLib.D3.API.RigidBody.FromObject=function(e){return new GameLib.D3.API.RigidBody(e.id,e.name,e.mass,e.friction,e.position,e.quaternion,e.velocity,e.angularVelocity,e.linearDamping,e.angularDamping,e.allowSleep,e.sleepSpeedLimit,e.sleepTimeLimit,e.collisionFilterGroup,e.collisionFilterMask,e.fixedRotation,e.shapes,e.kinematic,e.parentMesh,e.parentWorld,e.parentEntity)},GameLib.D3.API.Scene=function(e,t,i,n,a,s,o,r,c,h,m,l,p,u){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="Scene ("+this.id+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=[]),this.meshes=i,GameLib.Utils.UndefinedOrNull(n)&&(n=[]),this.lights=n,GameLib.Utils.UndefinedOrNull(a)&&(a=[]),this.textures=a,GameLib.Utils.UndefinedOrNull(s)&&(s=[]),this.materials=s,GameLib.Utils.UndefinedOrNull(o)&&(o=[]),this.images=o,GameLib.Utils.UndefinedOrNull(r)&&(r=null),this.fog=r,GameLib.Utils.UndefinedOrNull(c)&&(c=null),this.renderCamera=c,GameLib.Utils.UndefinedOrNull(h)&&(h=!0),this.showGrid=h,GameLib.Utils.UndefinedOrNull(m)&&(m=!0),this.showAxis=m,GameLib.Utils.UndefinedOrNull(l)&&(l=10),this.gridSize=l,GameLib.Utils.UndefinedOrNull(p)&&(p=new GameLib.API.Color(.1,.1,.1)),this.gridColor=p,GameLib.Utils.UndefinedOrNull(u)&&(u=null),this.parentEntity=u},GameLib.D3.API.Scene.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.API.Scene.prototype.constructor=GameLib.D3.API.Scene,GameLib.D3.API.Scene.FromObject=function(e){var t=[],i=[],n=[],a=[],s=[];return e.meshes&&(t=e.meshes.map(function(e){return e instanceof Object?GameLib.D3.API.Mesh.FromObject(e):e})),e.lights&&(i=e.lights.map(function(e){return e instanceof Object?GameLib.D3.API.Light.FromObject(e):e})),e.textures&&(n=e.textures.map(function(e){return e instanceof Object?GameLib.D3.API.Texture.FromObject(e):e})),e.materials&&(a=e.materials.map(function(e){return e instanceof Object?GameLib.D3.API.Material.FromObject(e):e})),e.images&&(s=e.images.map(function(e){return e instanceof Object?GameLib.D3.API.Image.FromObject(e):e})),new GameLib.D3.API.Scene(e.id,e.name,t,i,n,a,s,e.fog,e.renderCamera,e.showGrid,e.showAxis,e.gridSize,GameLib.API.Color.FromObject(e.gridColor),e.parentEntity)},GameLib.D3.API.Shape=function(e,t,i,n,a,s,o){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="Shape ("+this.id+")",this instanceof GameLib.D3.Shape.ConvexHull&&(t="Shape Convex Hull ("+this.id+")"),this instanceof GameLib.D3.Shape.ConvexHull.Cylinder&&(t="Shape Convex Hull Cylinder ("+this.id+")"),this instanceof GameLib.D3.Shape.HeightMap&&(t="Shape Heightmap ("+this.id+")"),this instanceof GameLib.D3.Shape.Box&&(t="Shape Box ("+this.id+")"),this instanceof GameLib.D3.Shape.Plane&&(t="Shape Plane ("+this.id+")"),this instanceof GameLib.D3.Shape.Sphere&&(t="Shape Sphere ("+this.id+")"),this instanceof GameLib.D3.Shape.TriMesh&&(t="Shape TriMesh ("+this.id+")")),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=0),this.boundingSphereRadius=i,GameLib.Utils.UndefinedOrNull(n)&&(n=!0),this.collisionResponse=n,GameLib.Utils.UndefinedOrNull(a)&&(a=null),this.frictionMaterial=a,GameLib.Utils.UndefinedOrNull(s)&&(s=null),this.parentMesh=s,GameLib.Utils.UndefinedOrNull(o)&&(o=null),this.parentEntity=o},GameLib.D3.API.Shape.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.API.Shape.prototype.constructor=GameLib.D3.API.Shape,GameLib.D3.API.Shape.FromObject=function(e){return new GameLib.D3.API.Shape(e.id,e.name,e.boundingSphereRadius,e.collisionResponse,e.frictionMaterial,e.parentMesh,e.parentEntity)},GameLib.D3.API.Skeleton=function(e,t,i,n,a,s,o,r,c,h){GameLib.Utils.UndefinedOrNull(h)&&(h=null),this.parentEntity=h,GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="Skeleton"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=[]),this.bones=i,GameLib.Utils.UndefinedOrNull(n)&&(n=[]),this.boneInverses=n,GameLib.Utils.UndefinedOrNull(a)&&(a=!1),this.useVertexTexture=a,a&&console.warn("support for vertex texture bones is not supported yet - something could break somewhere"),GameLib.Utils.UndefinedOrNull(s)&&(s=0),this.boneTextureWidth=s,GameLib.Utils.UndefinedOrNull(o)&&(o=0),this.boneTextureHeight=o,GameLib.Utils.UndefinedOrNull(r)&&(r=[]),this.boneMatrices=r,GameLib.Utils.UndefinedOrNull(c)&&(c=null),this.boneTexture=c},GameLib.D3.API.Skeleton.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.API.Skeleton.prototype.constructor=GameLib.D3.API.Skeleton,GameLib.D3.API.Skeleton.FromObject=function(e){return new GameLib.D3.API.Skeleton(e.id,e.name,e.bones.map(function(e){return GameLib.D3.API.Bone.FromObject(e)}),e.boneInverses.map(function(e){return GameLib.D3.API.Matrix4.FromObject(e)}),e.useVertexTexture,e.boneTextureWidth,e.boneTextureHeight,e.boneMatrices.map(function(e){return GameLib.D3.API.Matrix4.FromObject(e)}),e.boneTexture,e.parentEntity)},GameLib.D3.API.Solver=function(e,t,i,n,a,s){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="Solver ("+this.id+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=GameLib.D3.Solver.GS_SOLVER),this.solverType=i,GameLib.Utils.UndefinedOrNull(n)&&(n=10),this.iterations=n,GameLib.Utils.UndefinedOrNull(a)&&(a=1e-7),this.tolerance=a,GameLib.Utils.UndefinedOrNull(s)&&(s=null),this.parentEntity=s},GameLib.D3.API.Solver.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.API.Solver.prototype.constructor=GameLib.D3.API.Solver,GameLib.D3.API.Solver.FromObject=function(e){return new GameLib.D3.API.Solver(e.id,e.name,e.solverType,e.iterations,e.tolerance,e.parentEntity)},GameLib.D3.API.Spline=function(e,t,i,n){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="Spline (unknown)"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=[]),this.vertices=i,GameLib.Utils.UndefinedOrNull(n)&&(n=null),this.parentEntity=n},GameLib.D3.API.Spline.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.API.Spline.prototype.constructor=GameLib.D3.API.Spline,GameLib.D3.API.Spline.FromObject=function(e){return new GameLib.D3.API.Spline(e.id,e.name,e.vertices.map(function(e){return GameLib.API.Vector3.FromObject(e)}),e.parentEntity)},GameLib.D3.API.Texture=function(e,t,i,n,a,s,o,r,c,h,m,l,p,u,b,d,L,G,f,E,y,O,I,T,D,P,A){GameLib.Utils.UndefinedOrNull(A)&&(A=null),this.parentEntity=A,GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t=GameLib.D3.Texture.TEXTURE_TYPE_NORMAL),this.typeId=t,GameLib.Utils.UndefinedOrNull(i)&&(i="Texture ("+e+")"),this.name=i,GameLib.Utils.UndefinedOrNull(n)&&(n=null),this.image=n,GameLib.Utils.UndefinedOrNull(a)&&(a=[]),this.images=a,GameLib.Utils.UndefinedOrNull(s)&&(s=GameLib.D3.Texture.TYPE_REPEAT_WRAPPING),this.wrapS=s,GameLib.Utils.UndefinedOrNull(o)&&(o=GameLib.D3.Texture.TYPE_REPEAT_WRAPPING),this.wrapT=o,GameLib.Utils.UndefinedOrNull(r)&&(r=new GameLib.API.Vector2(1,1)),this.repeat=r,GameLib.Utils.UndefinedOrNull(c)&&(c=null),this.data=c,GameLib.Utils.UndefinedOrNull(h)&&(h=GameLib.D3.Texture.TYPE_RGBA_FORMAT),this.format=h,GameLib.Utils.UndefinedOrNull(m)&&(m=GameLib.D3.Texture.TYPE_UV_MAPPING),this.mapping=m,GameLib.Utils.UndefinedOrNull(l)&&(l=GameLib.D3.Texture.TYPE_LINEAR_FILTER),this.magFilter=l,GameLib.Utils.UndefinedOrNull(p)&&(p=GameLib.D3.Texture.TYPE_LINEAR_MIPMAP_LINEAR_FILTER),this.minFilter=p,GameLib.Utils.UndefinedOrNull(u)&&(u=GameLib.D3.Texture.TYPE_UNSIGNED_BYTE),this.textureType=u,GameLib.Utils.UndefinedOrNull(b)&&(b=1),this.anisotropy=b,GameLib.Utils.UndefinedOrNull(d)&&(d=new GameLib.API.Vector2(0,0)),this.offset=d,GameLib.Utils.UndefinedOrNull(L)&&(L=!0),this.generateMipmaps=L,GameLib.Utils.UndefinedOrNull(G)&&(G=!0),this.flipY=G,GameLib.Utils.UndefinedOrNull(f)&&(f=[]),this.mipmaps=f,GameLib.Utils.UndefinedOrNull(E)&&(E=4),this.unpackAlignment=E,GameLib.Utils.UndefinedOrNull(y)&&(y=!1),this.premultiplyAlpha=y,GameLib.Utils.UndefinedOrNull(O)&&(O=GameLib.D3.Texture.TYPE_LINEAR_ENCODING),this.encoding=O,GameLib.Utils.UndefinedOrNull(I)&&(I=null),this.canvas=I,GameLib.Utils.UndefinedOrNull(T)&&(T=!1),this.animated=T,GameLib.Utils.UndefinedOrNull(D)&&(D=!1),this.reverseAnimation=D,GameLib.Utils.UndefinedOrNull(P)&&(P=!0),this.forward=P,this.needsUpdate=!1},GameLib.D3.API.Texture.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.API.Texture.prototype.constructor=GameLib.D3.API.Texture,GameLib.D3.API.Texture.FromObject=function(e){return new GameLib.D3.API.Texture(e.id,e.typeId,e.name,e.image,e.images,e.wrapS,e.wrapT,GameLib.API.Vector2.FromObject(e.repeat),e.data,e.format,e.mapping,e.magFilter,e.minFilter,e.textureType,e.anisotropy,GameLib.API.Vector2.FromObject(e.offset),e.generateMipmaps,e.flipY,e.mipmaps,e.unpackAlignment,e.premultiplyAlpha,e.encoding,e.canvas,e.animated,e.reverseAnimation,e.forward,e.parentEntity)},GameLib.D3.API.Vertex=function(e,t){GameLib.Utils.UndefinedOrNull(e)&&(e=new GameLib.API.Vector3),this.position=e,GameLib.Utils.UndefinedOrNull(t)&&(t=[]),this.boneWeights=t},GameLib.D3.API.Vertex.FromObject=function(e){return new GameLib.D3.API.Vertex(GameLib.API.Vector3.FromObject(e.position),e.boneWeights.map(function(e){return GameLib.D3.API.BoneWeight.FromObject(e)}))},GameLib.D3.API.Viewport=function(e,t,i,n,a,s,o){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="Viewport ("+this.id+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=800),this.width=i,GameLib.Utils.UndefinedOrNull(n)&&(n=600),this.height=n,GameLib.Utils.UndefinedOrNull(a)&&(a=0),this.x=a,GameLib.Utils.UndefinedOrNull(s)&&(s=0),this.y=s,GameLib.Utils.UndefinedOrNull(o)&&(o=null),this.parentEntity=o},GameLib.D3.API.Viewport.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.API.Viewport.prototype.constructor=GameLib.D3.API.Viewport,GameLib.D3.API.Viewport.FromObject=function(e){return new GameLib.D3.API.Viewport(e.id,e.name,e.width,e.height,e.x,e.y,e.parentEntity)},GameLib.D3.Animation=function(e){if(GameLib.Utils.UndefinedOrNull(e)&&(e={}),e instanceof GameLib.D3.Animation)return e;GameLib.D3.API.Animation.call(this,e.id,e.name,e.rotationSpeed,e.translationSpeed,e.scaleSpeed,e.rotationFn,e.translationFn,e.scaleFn,e.blocking,e.applyToMeshWhenDone,e.meshes,e.parentEntity),this.functionType=GameLib.D3.Animation.ANIMATION_FUNCTION_TYPE_ROTATION,this.editor=null,this.inProcess=!1,GameLib.Component.call(this,GameLib.Component.COMPONENT_ANIMATION,{meshes:[GameLib.D3.Mesh]})},GameLib.D3.Animation.prototype=Object.create(GameLib.D3.API.Animation.prototype),GameLib.D3.Animation.prototype.constructor=GameLib.D3.Animation,GameLib.D3.Animation.ANIMATION_FUNCTION_TYPE_ROTATION=1,GameLib.D3.Animation.ANIMATION_FUNCTION_TYPE_TRANSLATION=2,GameLib.D3.Animation.ANIMATION_FUNCTION_TYPE_SCALE=3,GameLib.D3.Animation.prototype.createInstance=function(){this.instance={rotation:null,translation:null,scale:null};try{this.rotationFn&&(this.instance.rotation=new Function("data",this.rotationFn).bind(this)),this.translationFn&&(this.instance.translation=new Function("data",this.translationFn).bind(this)),this.scaleFn&&(this.instance.scale=new Function("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=new Function("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=new Function("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=new Function("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(){return new GameLib.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){return GameLib.Utils.IdOrNull(e)}),GameLib.Utils.IdOrNull(this.parentEntity))},GameLib.D3.Animation.FromObject=function(e){var t=GameLib.D3.API.Animation.FromObject(e);return new GameLib.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));var e=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(){var e=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){var t=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={}),t instanceof GameLib.D3.Audio)return t;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.camera instanceof GameLib.D3.API.Camera&&(this.camera=new GameLib.D3.Camera(this.graphics,this.camera)),GameLib.Component.call(this,GameLib.Component.COMPONENT_AUDIO,{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))return void console.log("audio not ready to create instance");GameLib.Event.Emit(GameLib.Event.GET_API_URL,null,function(e){this.apiUrl=e.apiUrl}.bind(this));var e=new THREE.AudioListener;this.camera.instance.add(e),this.instance=new THREE.Audio(e),(new THREE.AudioLoader).load(this.apiUrl+this.path+"?ts="+Date.now(),function(e){this.instance.setBuffer(e),this.instance.setLoop(this.loop),this.instance.setVolume(this.volume),GameLib.Component.prototype.createInstance.call(this)}.bind(this))},GameLib.D3.Audio.prototype.updateInstance=function(e){"loop"===e&&this.instance.setLoop(this.loop),"volume"===e&&this.instance.setVolume(this.volume),"paused"===e&&(this.paused?this.instance.pause():this.instance.play())},GameLib.D3.Audio.prototype.toApiObject=function(){return new GameLib.D3.API.Audio(this.id,this.name,this.path,this.loop,this.volume,GameLib.Utils.IdOrNull(this.camera),this.overplay,this.paused,GameLib.Utils.IdOrNull(this.parentEntity))},GameLib.D3.Audio.FromObject=function(e,t){var i=GameLib.D3.API.Audio.FromObject(t);return new GameLib.D3.Audio(e,i)},GameLib.D3.Audio.prototype.play=function(){this.instance.play()},GameLib.D3.BoneWeight=function(e,t){if(this.graphics=e,this.graphics.isNotThreeThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),t instanceof GameLib.D3.BoneWeight)return t;GameLib.D3.API.BoneWeight.call(this,t.boneIndex,t.weight)},GameLib.D3.BoneWeight.prototype=Object.create(GameLib.D3.API.BoneWeight.prototype),GameLib.D3.BoneWeight.prototype.constructor=GameLib.D3.BoneWeight,GameLib.D3.BoneWeight.prototype.toApiObject=function(){return new GameLib.D3.API.BoneWeight(this.boneIndex,this.weight)},GameLib.D3.BoneWeight.FromObject=function(e,t){var i=GameLib.D3.API.BoneWeight.FromObject(t);return new GameLib.D3.BoneWeight(e,i)},GameLib.D3.Bone=function(e,t){if(this.graphics=e,this.graphics.isNotThreeThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),t instanceof GameLib.D3.Bone)return t;GameLib.D3.API.Bone.call(this,t.id,t.name,t.childBoneIds,t.parentBoneIds,t.position,t.quaternion,t.scale,t.up),this.position=new GameLib.Vector3(e,this.position,this),this.quaternion=new GameLib.Quaternion(e,this.quaternion,this),this.scale=new GameLib.Vector3(e,this.scale,this),this.up=new GameLib.Vector3(e,this.up,this),GameLib.Component.call(this,GameLib.Component.COMPONENT_BONE)},GameLib.D3.Bone.prototype=Object.create(GameLib.D3.API.Bone.prototype),GameLib.D3.Bone.prototype.constructor=GameLib.D3.Bone,GameLib.D3.Bone.prototype.createInstance=function(){this.instance=new THREE.Bone,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.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.scale.x=this.scale.x,this.instance.scale.y=this.scale.y,this.instance.scale.z=this.scale.z,this.instance.up.x=this.up.x,this.instance.up.y=this.up.y,this.instance.up.z=this.up.z,GameLib.Component.prototype.createInstance.call(this)},GameLib.D3.Bone.prototype.updateInstance=function(){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.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.scale.x=this.scale.x,this.instance.scale.y=this.scale.y,this.instance.scale.z=this.scale.z,this.instance.up.x=this.up.x,this.instance.up.y=this.up.y,this.instance.up.z=this.up.z},GameLib.D3.Bone.prototype.toApiObject=function(){return new GameLib.D3.API.Bone(this.id,this.name,this.childBoneIds,this.parentBoneIds,this.position.toApiObject(),this.quaternion.toApiObject(),this.scale.toApiObject(),this.up.toApiObject())},GameLib.D3.Bone.FromObject=function(e,t){var i=GameLib.D3.API.Bone.FromObject(t);return GameLib.D3.Bone(e,i)},GameLib.D3.Broadphase=function(e,t){if(this.physics=e,this.physics.isNotCannonThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),t instanceof GameLib.D3.Broadphase)return t;GameLib.D3.API.Broadphase.call(this,t.id,t.name,t.broadphaseType,t.parentEntity),GameLib.Component.call(this,GameLib.Component.COMPONENT_BROADPHASE)},GameLib.D3.Broadphase.prototype=Object.create(GameLib.D3.API.Broadphase.prototype),GameLib.D3.Broadphase.prototype.constructor=GameLib.D3.Broadphase,GameLib.D3.Broadphase.prototype.createInstance=function(){if(this.broadphaseType===GameLib.D3.Broadphase.BROADPHASE_TYPE_NAIVE)this.instance=new CANNON.NaiveBroadphase;else if(this.broadphaseType===GameLib.D3.Broadphase.BROADPHASE_TYPE_GRID)this.instance=new CANNON.GridBroadphase;else{if(this.broadphaseType!==GameLib.D3.Broadphase.BROADPHASE_TYPE_SAP)throw console.warn("Unsupported broadphase type: "+this.broadphaseType),new Error("Unsupported broadphase type: "+this.broadphaseType);this.instance=new CANNON.SAPBroadphase}GameLib.Component.prototype.createInstance.call(this)},GameLib.D3.Broadphase.prototype.updateInstance=function(){this.broadphaseType===GameLib.D3.Broadphase.BROADPHASE_TYPE_NAIVE&&(this.instance instanceof CANNON.NaiveBroadphase||this.createInstance()),this.broadphaseType===GameLib.D3.Broadphase.BROADPHASE_TYPE_GRID&&(this.instance instanceof CANNON.GridBroadphase||this.createInstance()),this.broadphaseType===GameLib.D3.Broadphase.BROADPHASE_TYPE_SAP&&(this.instance instanceof CANNON.SAPBroadphase||this.createInstance())},GameLib.D3.Broadphase.prototype.toApiObject=function(){return new GameLib.D3.API.Broadphase(this.id,this.name,this.broadphaseType,GameLib.Utils.IdOrNull(this.parentEntity))},GameLib.D3.Broadphase.FromObject=function(e,t){var i=GameLib.D3.API.Broadphase.FromObject(t);return new GameLib.D3.Broadphase(e,i)},GameLib.D3.Broadphase.BROADPHASE_TYPE_NAIVE=1,GameLib.D3.Broadphase.BROADPHASE_TYPE_GRID=2,GameLib.D3.Broadphase.BROADPHASE_TYPE_SAP=3,GameLib.D3.Camera=function(e,t){if(this.graphics=e,this.graphics.isNotThreeThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),t instanceof GameLib.D3.Camera)return t;if(GameLib.D3.API.Camera.call(this,t.id,t.cameraType,t.name,t.fov,t.aspect,t.near,t.far,t.position,t.lookAt,t.minX,t.maxX,t.minY,t.maxY,t.minZ,t.maxZ,t.offsetX,t.offsetY,t.quaternion,t.parentEntity,t.eyeSeparation,t.focalLength),!(this.position instanceof GameLib.API.Vector3))throw console.warn("position not instance of API.Vector3"),new Error("position not instance of API.Vector3");if(this.position=new GameLib.Vector3(e,this.position,this),!(this.quaternion instanceof GameLib.API.Quaternion))throw console.warn("quaternion not instance of API.Quaternion"),new Error("quaternion not instance of API.Quaternion");if(this.quaternion=new GameLib.Quaternion(e,this.quaternion,this),!(this.lookAt instanceof GameLib.API.Vector3))throw console.warn("lookAt not instance of API.Vector3"),new Error("lookAt not instance of API.Vector3");this.lookAt=new GameLib.Vector3(e,this.lookAt,this),GameLib.Component.call(this,GameLib.Component.COMPONENT_CAMERA)},GameLib.D3.Camera.prototype=Object.create(GameLib.D3.API.Camera.prototype),GameLib.D3.Camera.prototype.constructor=GameLib.D3.Camera,GameLib.D3.Camera.CAMERA_TYPE_PERSPECTIVE=1,GameLib.D3.Camera.CAMERA_TYPE_ORTHOGONAL=2,GameLib.D3.Camera.CAMERA_TYPE_STEREO=3,GameLib.D3.Camera.prototype.createInstance=function(){if(this.cameraType===GameLib.D3.Camera.CAMERA_TYPE_PERSPECTIVE)this.instance=new THREE.PerspectiveCamera(this.fov,this.aspect,this.near,this.far);else if(this.cameraType===GameLib.D3.Camera.CAMERA_TYPE_ORTHOGONAL)this.instance=new THREE.OrthographicCamera(this.minX+this.offsetX,this.maxX+this.offsetX,this.maxY,this.minY,this.minZ,this.maxZ);else{if(this.cameraType!==GameLib.D3.Camera.CAMERA_TYPE_STEREO)throw new Error("unsupported camera type : "+this.cameraType);this.instance=new THREE.StereoCamera}this.instance.position.x=this.position.x,this.instance.position.y=this.position.y,this.instance.position.z=this.position.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.lookAt(this.lookAt.instance),this.instance.updateProjectionMatrix(),GameLib.Component.prototype.createInstance.call(this)},GameLib.D3.Camera.prototype.updateInstance=function(e){GameLib.Utils.UndefinedOrNull(e)&&console.warn("no camera property specified for : "+this.name),"cameraType"===e&&(this.cameraType!==GameLib.D3.Camera.CAMERA_TYPE_ORTHOGONAL||this.instance instanceof THREE.OrthographicCamera||this.createInstance(),this.cameraType!==GameLib.D3.Camera.CAMERA_TYPE_PERSPECTIVE||this.instance instanceof THREE.PerspectiveCamera||this.createInstance()),"aspect"!==e&&"minX"!==e&&"maxX"!==e&&"minY"!==e&&"maxY"!==e&&"minZ"!==e&&"maxZ"!==e&&"offsetX"!==e&&"offsetY"!==e&&"fov"!==e&&"near"!==e&&"far"!==e&&"eyeSeparation"!==e&&"focalLength"!==e||(this.cameraType===GameLib.D3.Camera.CAMERA_TYPE_ORTHOGONAL&&(this.minX=this.aspect*this.minY,this.maxX=this.aspect*this.maxY,this.instance.left=this.minX+this.offsetX,this.instance.right=this.maxX+this.offsetX,this.instance.bottom=this.minY+this.offsetY,this.instance.top=this.maxY+this.offsetY,this.instance.near=this.minZ,this.instance.far=this.maxZ),this.cameraType!==GameLib.D3.Camera.CAMERA_TYPE_PERSPECTIVE&&this.cameraType!==GameLib.D3.Camera.CAMERA_TYPE_STEREO||(this.instance.fov=this.fov,this.instance.aspect=this.aspect,this.instance.near=this.near,this.instance.far=this.far),this.cameraType===GameLib.D3.Camera.CAMERA_TYPE_STEREO&&(this.instance.eyeSeparation=this.eyeSeparation,this.instance.focalLength=this.focalLength,this.instance.update(this.instance))),"position"===e&&(this.instance.position.x=this.position.x,this.instance.position.y=this.position.y,this.instance.position.z=this.position.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),"lookAt"===e&&(this.lookAt.instance.x=this.lookAt.x,this.lookAt.instance.y=this.lookAt.y,this.lookAt.instance.z=this.lookAt.z,this.instance.lookAt(this.lookAt.instance)),this.instance.updateProjectionMatrix()},GameLib.D3.Camera.prototype.resize=function(e,t){camera.aspect=e/t,camera.updateInstance()},GameLib.D3.Camera.prototype.toApiObject=function(){return new GameLib.D3.API.Camera(this.id,this.cameraType,this.name,this.fov,this.aspect,this.near,this.far,this.position.toApiObject(),this.lookAt.toApiObject(),this.minX,this.maxX,this.minY,this.maxY,this.minZ,this.maxZ,this.offsetX,this.offsetY,this.quaternion.toApiObject(),GameLib.Utils.IdOrNull(this.parentEntity),this.eyeSeparation,this.focalLength)},GameLib.D3.Camera.FromObject=function(e,t){var i=GameLib.D3.API.Camera.FromObject(t);return new GameLib.D3.Camera(e,i)},GameLib.D3.Composer=function(e,t){if(this.graphics=e,this.graphics.isNotThreeThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),t instanceof GameLib.D3.Composer)return t;GameLib.D3.API.Composer.call(this,t.id,t.name,t.renderer,t.renderTarget,t.passes,t.parentEntity),GameLib.Component.call(this,GameLib.Component.COMPONENT_COMPOSER,{renderer:GameLib.D3.Renderer,renderTarget:GameLib.D3.RenderTarget,passes:[GameLib.D3.Pass]})},GameLib.D3.Composer.prototype=Object.create(GameLib.D3.API.Composer.prototype);GameLib.D3.Composer.prototype.constructor=GameLib.D3.Composer,GameLib.D3.Composer.prototype.createInstance=function(){console.log("GameLib.D3.Composer.prototype.createInstance() - fix me"),GameLib.Component.prototype.createInstance.call(this)},GameLib.D3.Composer.prototype.updateInstance=function(){console.log("GameLib.D3.Composer.prototype.updateInstance() - fix me")},GameLib.D3.Composer.prototype.toApiObject=function(){return new GameLib.D3.API.Composer(this.id,this.name,GameLib.Utils.IdOrNull(this.renderer),GameLib.Utils.IdOrNull(this.renderTarget),this.passes.map(function(e){return GameLib.Utils.IdOrNull(e)}),GameLib.Utils.IdOrNull(this.parentEntity))},GameLib.D3.Composer.FromObject=function(e,t){var i=GameLib.D3.API.Composer.FromObject(t);return new GameLib.D3.Composer(e,i)},GameLib.D3.Controls=function(e){if(GameLib.Utils.UndefinedOrNull(e)&&(e={}),e instanceof GameLib.D3.Controls)return e;GameLib.D3.API.Controls.call(this,e.id,e.controlsType,e.name,e.domElement,e.parentEntity);var t=GameLib.Component.COMPONENT_CONTROLS,i={domElement:GameLib.DomElement},n=!1;this.controlsType===GameLib.D3.Controls.CONTROLS_TYPE_EDITOR&&(t=GameLib.Component.COMPONENT_CONTROLS_EDITOR,i.raycaster=GameLib.D3.Raycaster,i.camera=GameLib.D3.Camera,n=!0),this.controlsType===GameLib.D3.Controls.CONTROLS_TYPE_TOUCH&&(t=GameLib.Component.COMPONENT_CONTROLS_TOUCH),this.controlsType===GameLib.D3.Controls.CONTROLS_TYPE_KEYBOARD&&(t=GameLib.Component.COMPONENT_CONTROLS_KEYBOARD),this.controlsType===GameLib.D3.Controls.CONTROLS_TYPE_MOUSE&&(t=GameLib.Component.COMPONENT_CONTROLS_MOUSE),GameLib.Component.call(this,t,i,n)},GameLib.D3.Controls.prototype=Object.create(GameLib.D3.API.Controls.prototype),GameLib.D3.Controls.prototype.constructor=GameLib.D3.Controls,GameLib.D3.Controls.CONTROLS_TYPE_EDITOR=0,GameLib.D3.Controls.CONTROLS_TYPE_TOUCH=1,GameLib.D3.Controls.CONTROLS_TYPE_KEYBOARD=2,GameLib.D3.Controls.CONTROLS_TYPE_MOUSE=3,GameLib.D3.Controls.prototype.createInstance=function(){GameLib.Component.prototype.createInstance.call(this)},GameLib.D3.Controls.prototype.updateInstance=function(){console.log("default controls update instance")},GameLib.D3.Controls.prototype.toApiObject=function(){return new GameLib.D3.API.Controls(this.id,this.controlsType,this.name,GameLib.Utils.IdOrNull(this.domElement),GameLib.Utils.IdOrNull(this.parentEntity))},GameLib.D3.Controls.FromObject=function(e){var t=GameLib.D3.API.Controls.FromObject(e);return new GameLib.D3.Controls(t)},GameLib.D3.Controls.Editor=function(e,t,i,n){this.graphics=e,this.graphics.isNotThreeThrow(),GameLib.Utils.UndefinedOrNull(i)&&(i=null),this.raycaster=i,GameLib.Utils.UndefinedOrNull(n)&&(n=null),this.camera=n,this.raycaster instanceof GameLib.D3.API.Raycaster&&(this.raycaster=new GameLib.D3.Raycaster(this.graphics,this.raycaster)),this.camera instanceof GameLib.D3.API.Camera&&(this.camera=new GameLib.D3.Camera(this.graphics,this.camera)),GameLib.D3.Controls.call(this,t)},GameLib.D3.Controls.Editor.prototype=Object.create(GameLib.D3.Controls.prototype),GameLib.D3.Controls.Editor.prototype.constructor=GameLib.D3.Controls.Editor,GameLib.D3.Controls.Editor.prototype.createInstance=function(){if(!this.camera||!this.camera.instance)throw new Error("No camera at time of instance");if(!this.domElement||!this.domElement.instance)throw new Error("No dom element at time of instance");this.instance=new THREE.EditorControls(this.camera.instance,this.domElement.instance),GameLib.D3.Controls.prototype.createInstance.call(this)},GameLib.D3.Controls.Editor.prototype.updateInstance=function(){console.warn("an update instance was called on editor controls - which, if not called from within a running system at the right time will affect the order of input event handling and cause system instability"),GameLib.D3.Controls.prototype.updateInstance.call(this)},GameLib.D3.Controls.Editor.prototype.toApiObject=function(){var e=GameLib.D3.Controls.prototype.toApiObject.call(this);return e.raycaster=GameLib.Utils.IdOrNull(this.raycaster),e.camera=GameLib.Utils.IdOrNull(this.camera),e},GameLib.D3.Controls.Editor.FromObject=function(e,t){var i=GameLib.D3.API.Controls.FromObject(t);return new GameLib.D3.Controls.Editor(e,i,t.raycaster,t.camera)},GameLib.D3.Controls.Keyboard=function(e){GameLib.D3.Controls.call(this,e)},GameLib.D3.Controls.Keyboard.prototype=Object.create(GameLib.D3.Controls.prototype),GameLib.D3.Controls.Keyboard.prototype.constructor=GameLib.D3.Controls.Keyboard,GameLib.D3.Controls.Keyboard.prototype.createInstance=function(){this.instance=!0,GameLib.D3.Controls.prototype.createInstance.call(this)},GameLib.D3.Controls.Keyboard.prototype.updateInstance=function(){GameLib.D3.Controls.prototype.updateInstance.call(this)},GameLib.D3.Controls.Keyboard.prototype.toApiObject=function(){return GameLib.D3.Controls.prototype.toApiObject.call(this)},GameLib.D3.Controls.Keyboard.FromObject=function(e){var t=GameLib.D3.API.Controls.FromObject(e);return new GameLib.D3.Controls.Keyboard(t)},GameLib.D3.Controls.Mouse=function(e){GameLib.D3.Controls.call(this,e)},GameLib.D3.Controls.Mouse.prototype=Object.create(GameLib.D3.Controls.prototype),GameLib.D3.Controls.Mouse.prototype.constructor=GameLib.D3.Controls.Mouse,GameLib.D3.Controls.Mouse.prototype.createInstance=function(){this.instance=!0,GameLib.D3.Controls.prototype.createInstance.call(this)},GameLib.D3.Controls.Mouse.prototype.updateInstance=function(){GameLib.D3.Controls.prototype.updateInstance.call(this)},GameLib.D3.Controls.Mouse.prototype.toApiObject=function(){return GameLib.D3.Controls.prototype.toApiObject.call(this)},GameLib.D3.Controls.Mouse.FromObject=function(e){var t=GameLib.D3.API.Controls.FromObject(e);return new GameLib.D3.Controls.Mouse(t)},GameLib.D3.Controls.Touch=function(e,t){GameLib.Utils.UndefinedOrNull(t)&&(t=5),this.sensitivity=t,GameLib.D3.Controls.call(this,e)},GameLib.D3.Controls.Touch.prototype=Object.create(GameLib.D3.Controls.prototype),GameLib.D3.Controls.Touch.prototype.constructor=GameLib.D3.Controls.Touch,GameLib.D3.Controls.Touch.prototype.createInstance=function(){this.instance=!0,GameLib.D3.Controls.prototype.createInstance.call(this)},GameLib.D3.Controls.Touch.prototype.updateInstance=function(){GameLib.D3.Controls.prototype.updateInstance.call(this)},GameLib.D3.Controls.Touch.prototype.toApiObject=function(){var e=GameLib.D3.Controls.prototype.toApiObject.call(this);return e.sensitivity=this.sensitivity,e},GameLib.D3.Controls.Touch.FromObject=function(e){var t=GameLib.D3.API.Controls.FromObject(e);return new GameLib.D3.Controls.Touch(t,e.sensitivity)},GameLib.D3.CustomCode=function(e){if(GameLib.Utils.UndefinedOrNull(e)&&(e={}),e instanceof GameLib.D3.CustomCode)return e;GameLib.D3.API.CustomCode.call(this,e.id,e.name,e.eventId,e.code,e.parentEntity),this.editor=null,GameLib.Component.call(this,GameLib.Component.COMPONENT_CUSTOM_CODE)},GameLib.D3.CustomCode.prototype=Object.create(GameLib.D3.API.CustomCode.prototype),GameLib.D3.CustomCode.prototype.constructor=GameLib.D3.CustomCode,GameLib.D3.CustomCode.prototype.createInstance=function(){try{this.instance=new Function("data",this.code).bind(this)}catch(e){this.instance=new Function("data","console.log('compilation failed for : "+this.name+"');").bind(this)}GameLib.Component.prototype.createInstance.call(this)},GameLib.D3.CustomCode.prototype.updateInstance=function(){try{this.instance=new Function("data",this.code).bind(this),this.publish(GameLib.Event.COMPILE_SUCCESS,{component:this})}catch(e){this.instance=new Function("data","console.log('compilation update failed for : "+this.name+"');").bind(this),this.publish(GameLib.Event.COMPILE_FAILED,{component:this})}},GameLib.D3.CustomCode.prototype.toApiObject=function(){return new GameLib.D3.API.CustomCode(this.id,this.name,this.eventId,this.code,GameLib.Utils.IdOrNull(this.parentEntity))},GameLib.D3.CustomCode.FromObject=function(e){var t=GameLib.D3.API.CustomCode.FromObject(e);return new GameLib.D3.CustomCode(t)},GameLib.D3.CustomCode.prototype.launchEditor=function(){GameLib.Event.Emit(GameLib.Event.GET_RUNTIME,null,function(e){this.coder=e.coder,this.coder.isNotCodeMirrorThrow()}.bind(this)),this.editor=this.coder.instance(document.body,{value:this.code,mode:"javascript",lineNumbers:!0,scrollbarStyle:"overlay",indentWithTabs:!0,indentUnit:4}),this.editor.on("change",function(){this.code=this.editor.getValue(),this.updateInstance()}.bind(this))},GameLib.D3.CustomCode.prototype.closeEditor=function(){var e=this.editor.getWrapperElement();e.parentElement.removeChild(e)},GameLib.D3.Face=function(e,t){if(this.implementation=e,e instanceof GameLib.GraphicsRuntime)this.implementation.isNotThreeThrow();else{if(!(e instanceof GameLib.PhysicsRuntime))throw new Error("Unhandled implementation : "+e);this.implementation.isNotCannonThrow()}if(GameLib.Utils.UndefinedOrNull(t)&&(t={}),t instanceof GameLib.D3.Face)return t;GameLib.D3.API.Face.call(this,t.id,t.name,t.v0index,t.v1index,t.v2index,t.materialIndex,t.uvs,t.color,t.vertexColors,t.vertexNormals,t.normal),this.implementation instanceof GameLib.GraphicsRuntime&&(this.color=new GameLib.Color(this.implementation,this.color,this),this.vertexColors=this.vertexColors.map(function(e){return e instanceof GameLib.Color?e:e instanceof GameLib.API.Color?new GameLib.Color(this.implementation,e,this):void console.warn("unknown vertex color type",e)}.bind(this))),this.vertexNormals=this.vertexNormals.map(function(e){return e instanceof GameLib.Vector3?e:e instanceof GameLib.API.Vector3?new GameLib.Vector3(this.implementation,e,this):void console.warn("unknown vertex normal type",e)}.bind(this)),this.uvs=this.uvs.reduce(function(e,t,i){return e[i]=t.reduce(function(e,t){return t instanceof GameLib.API.Vector2?e.push(new GameLib.Vector2(this.implementation,t,this)):console.warn("unknown uv type"),e}.bind(this),[]),e}.bind(this),[]),this.normal=new GameLib.Vector3(this.implementation,this.normal,this)},GameLib.D3.Face.prototype=Object.create(GameLib.D3.API.Face.prototype),GameLib.D3.Face.prototype.constructor=GameLib.D3.Face,GameLib.D3.Face.prototype.createInstance=function(){},GameLib.D3.Face.prototype.updateInstance=function(){},GameLib.D3.Face.prototype.toApiObject=function(){return new GameLib.D3.API.Face(this.id,this.name,this.v0index,this.v1index,this.v2index,this.materialIndex,this.uvs.reduce(function(e,t,i){return e[i]=t.reduce(function(e,t){return t instanceof GameLib.Vector2?e.push(t.toApiObject()):console.warn("unknown uv type - cannot commit to API"),e}.bind(this),[]),e}.bind(this),[]),this.color.toApiObject(),this.vertexColors.map(function(e){return e.toApiObject()}),this.vertexNormals.map(function(e){return e.toApiObject()}),this.normal.toApiObject())},GameLib.D3.Face.FromObject=function(e,t){return new GameLib.D3.Face(e,GameLib.D3.API.Face.FromObject(t))},GameLib.D3.Fog=function(e,t){if(this.graphics=e,this.graphics.isNotThreeThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),t instanceof GameLib.D3.Fog)return t;GameLib.D3.API.Fog.call(this,t.id,t.name,t.exponential,t.color,t.near,t.far,t.density,t.parentEntity),this.color=new GameLib.Color(this.graphics,this.color,this),GameLib.Component.call(this,GameLib.Component.COMPONENT_FOG)},GameLib.D3.Fog.prototype=Object.create(GameLib.D3.API.Fog.prototype),GameLib.D3.Fog.prototype.constructor=GameLib.D3.Fog,GameLib.D3.Fog.prototype.createInstance=function(){this.exponential?this.instance=new THREE.FogExp2(this.color.instance,this.density):this.instance=new THREE.Fog(this.color.instance,this.near,this.far),this.instance.name=this.name,GameLib.Component.prototype.createInstance.call(this)},GameLib.D3.Fog.prototype.updateInstance=function(e){if("exponential"===e){if(this.exponential&&!(this.instance instanceof THREE.FogExp2))return void this.createInstance();if(!(this.exponential||this.instance instanceof THREE.Fog))return void this.createInstance()}"color"===e&&(this.color.instance.setRGB(this.color.r,this.color.g,this.color.b),this.instance.color=this.color.instance),"near"!==e&&"far"!==e||this.instance instanceof THREE.Fog&&(this.instance.near=this.near,this.instance.far=this.far),"density"===e&&this.instance instanceof THREE.FogExp2&&(this.instance.density=this.density)},GameLib.D3.Fog.prototype.toApiObject=function(){return new GameLib.D3.API.Fog(this.id,this.name,this.exponential,this.color.toApiObject(),this.near,this.far,this.density,GameLib.Utils.IdOrNull(this.parentEntity))},GameLib.D3.Fog.FromObject=function(e,t){var i=GameLib.D3.API.Fog.FromObject(t);return new GameLib.D3.Fog(e,i)},GameLib.D3.Font=function(e,t){if(this.graphics=e,this.graphics.isNotThreeThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),t instanceof GameLib.D3.Font)return t;GameLib.D3.API.Font.call(this,t.id,t.name,t.url,t.parentEntity),GameLib.Component.call(this,GameLib.Component.COMPONENT_FONT)},GameLib.D3.Font.prototype=Object.create(GameLib.D3.API.Font.prototype),GameLib.D3.Font.prototype.constructor=GameLib.D3.Font,GameLib.D3.Font.prototype.createInstance=function(){GameLib.Event.Emit(GameLib.Event.LOAD_FONT,{font:this},function(e){this.instance=e,GameLib.Component.prototype.createInstance.call(this)}.bind(this),function(e){console.error(e),this.instance=null,GameLib.Component.prototype.createInstance.call(this)}.bind(this))},GameLib.D3.Font.prototype.updateInstance=function(){GameLib.Event.Emit(GameLib.Event.LOAD_FONT,{font:this})},GameLib.D3.Font.prototype.toApiObject=function(){return new GameLib.D3.API.Font(this.id,this.name,this.url,GameLib.Utils.IdOrNull(this.parentEntity))},GameLib.D3.Font.FromObject=function(e,t){return new GameLib.D3.Font(e,GameLib.D3.API.Font.FromObject(t))},GameLib.D3.FrictionContactMaterial=function(e,t){if(this.physics=e,this.physics.isNotCannonThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),t instanceof GameLib.D3.FrictionContactMaterial)return t;GameLib.D3.API.FrictionContactMaterial.call(this,t.id,t.name,t.materials,t.friction,t.restitution,t.contactEquationStiffness,t.contactEquationRelaxation,t.frictionEquationStiffness,t.frictionEquationRelaxation,t.parentEntity),GameLib.Component.call(this,GameLib.Component.COMPONENT_FRICTION_CONTACT_MATERIAL,{materials:[GameLib.D3.FrictionMaterial]})},GameLib.D3.FrictionContactMaterial.prototype=Object.create(GameLib.D3.API.FrictionContactMaterial.prototype),GameLib.D3.FrictionContactMaterial.prototype.constructor=GameLib.D3.FrictionContactMaterial,GameLib.D3.FrictionContactMaterial.prototype.createInstance=function(){this.instance=new CANNON.ContactMaterial(null,null,{friction:this.friction,restitution:this.restitution,contactEquationStiffness:this.contactEquationStiffness}),this.instance.materials=this.materials.map(function(e){return e.instance}),GameLib.Component.prototype.createInstance.call(this)},GameLib.D3.FrictionContactMaterial.prototype.updateInstance=function(){this.instance.materials=this.materials.map(function(e){return e.instance}),this.instance.friction=this.friction,this.instance.restitution=this.restitution,this.instance.contactEquationStiffness=this.contactEquationStiffness,this.instance.contactEquationRelaxation=this.contactEquationRelaxation,this.instance.frictionEquationStiffness=this.frictionEquationStiffness,this.instance.frictionEquationRelaxation=this.frictionEquationRelaxation},GameLib.D3.FrictionContactMaterial.prototype.toApiObject=function(){return new GameLib.D3.API.FrictionContactMaterial(this.id,this.name,this.materials.map(function(e){return GameLib.Utils.IdOrNull(e)}),this.friction,this.restitution,this.contactEquationStiffness,this.contactEquationRelaxation,this.frictionEquationStiffness,this.frictionEquationRelaxation,GameLib.Utils.IdOrNull(this.parentEntity))},GameLib.D3.FrictionContactMaterial.FromObject=function(e,t){var i=GameLib.D3.API.FrictionContactMaterial.FromObject(t);return new GameLib.D3.FrictionContactMaterial(e,i)},GameLib.D3.FrictionMaterial=function(e,t){if(this.physics=e,this.physics.isNotCannonThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),t instanceof GameLib.D3.FrictionMaterial)return t;GameLib.D3.API.FrictionMaterial.call(this,t.id,t.name,t.friction,t.restitution,t.parentEntity),GameLib.Component.call(this,GameLib.Component.COMPONENT_FRICTION_MATERIAL)},GameLib.D3.FrictionMaterial.prototype=Object.create(GameLib.D3.API.FrictionMaterial.prototype),GameLib.D3.FrictionMaterial.prototype.constructor=GameLib.D3.FrictionMaterial,GameLib.D3.FrictionMaterial.prototype.createInstance=function(){this.instance=new CANNON.Material(this.name),this.instance.friction=this.friction,this.instance.restitution=this.restitution,GameLib.Component.prototype.createInstance.call(this)},GameLib.D3.FrictionMaterial.prototype.updateInstance=function(){this.instance.friction=this.friction,this.instance.restitution=this.restitution,this.instance.name=this.name},GameLib.D3.FrictionMaterial.prototype.toApiObject=function(){return new GameLib.D3.API.FrictionMaterial(this.id,this.name,this.friction,this.restitution,GameLib.Utils.IdOrNull(this.parentEntity))},GameLib.D3.FrictionMaterial.FromObject=function(e,t){var i=GameLib.D3.API.FrictionMaterial.FromObject(t);return new GameLib.D3.FrictionMaterial(e,i)},GameLib.D3.Helper=function(e,t,i,n,a,s){if(this.graphics=e,this.graphics.isNotThreeThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t=GameLib.Utils.RandomId()),this.id=t,GameLib.Utils.UndefinedOrNull(i)&&(i="Helper ("+t+")"),this.name=i,GameLib.Utils.UndefinedOrNull(n))throw console.warn("Cannot create a helper for an Object which does not exist"),new Error("Cannot create a helper for an Object which does not exist");this.object=n,GameLib.Utils.UndefinedOrNull(a)&&(a=GameLib.D3.Helper.HELPER_TYPE_NONE,n instanceof GameLib.D3.Mesh&&n.meshType!==GameLib.D3.Mesh.MESH_TYPE_CURVE&&(a=GameLib.D3.Helper.HELPER_TYPE_EDGES),n instanceof GameLib.D3.Light&&(n.lightType===GameLib.D3.Light.LIGHT_TYPE_DIRECTIONAL&&(a=GameLib.D3.Helper.HELPER_TYPE_DIRECTIONAL_LIGHT),n.lightType===GameLib.D3.Light.LIGHT_TYPE_POINT&&(a=GameLib.D3.Helper.HELPER_TYPE_POINT_LIGHT),n.lightType===GameLib.D3.Light.LIGHT_TYPE_SPOT&&(a=GameLib.D3.Helper.HELPER_TYPE_SPOT_LIGHT)),n instanceof GameLib.D3.Skeleton&&(a=GameLib.D3.Helper.HELPER_TYPE_SKELETON)),this.helperType=a,GameLib.Utils.UndefinedOrNull(s)&&(s=null),this.parentEntity=s,this.createInstance()},GameLib.D3.Helper.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.Helper.prototype.constructor=GameLib.D3.Helper,GameLib.D3.Helper.HELPER_TYPE_NONE=0,GameLib.D3.Helper.HELPER_TYPE_EDGES=1,GameLib.D3.Helper.HELPER_TYPE_DIRECTIONAL_LIGHT=2,GameLib.D3.Helper.HELPER_TYPE_SPOT_LIGHT=3,GameLib.D3.Helper.HELPER_TYPE_POINT_LIGHT=4,GameLib.D3.Helper.HELPER_TYPE_WIREFRAME=5,GameLib.D3.Helper.HELPER_TYPE_SKELETON=6,GameLib.D3.Helper.prototype.createInstance=function(){this.helperType===GameLib.D3.Helper.HELPER_TYPE_EDGES&&(this.instance=new THREE.LineSegments(new THREE.EdgesGeometry(this.object.instance.geometry),new THREE.LineBasicMaterial({color:65280,linewidth:2}))),this.helperType===GameLib.D3.Helper.HELPER_TYPE_DIRECTIONAL_LIGHT&&(this.instance=new THREE.DirectionalLightHelper(this.object.instance)),this.helperType===GameLib.D3.Helper.HELPER_TYPE_POINT_LIGHT&&(this.instance=new THREE.PointLightHelper(this.object.instance,1)),this.helperType===GameLib.D3.Helper.HELPER_TYPE_SPOT_LIGHT&&(this.instance=new THREE.SpotLightHelper(this.object.instance)),this.helperType===GameLib.D3.Helper.HELPER_TYPE_WIREFRAME&&(this.instance=new THREE.WireframeGeometry(this.object.instance,65280)),this.helperType===GameLib.D3.Helper.HELPER_TYPE_SKELETON&&(this.instance=new THREE.SkeletonHelper(this.object.instance))},GameLib.D3.Helper.prototype.updateInstance=function(){this.instance.position.copy(this.object.instance.position),this.object.instance.parentMesh&&this.object.instance.parentMesh.instance&&this.instance.position.add(this.object.instance.parentMesh.instance.position),this.instance.scale.copy(this.object.instance.scale),this.instance.quaternion.copy(this.object.instance.quaternion)},GameLib.D3.Image=function(e,t){if(this.graphics=e,this.graphics.isNotThreeThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),t instanceof GameLib.D3.Image)return t;GameLib.D3.API.Image.call(this,t.id,t.name,t.fileName,t.extension,t.path,t.contentType,t.size,t.parentEntity),GameLib.Component.call(this,GameLib.Component.COMPONENT_IMAGE)},GameLib.D3.Image.prototype=Object.create(GameLib.D3.API.Image.prototype),GameLib.D3.Image.prototype.constructor=GameLib.D3.Image,GameLib.D3.Image.prototype.createInstance=function(){GameLib.Event.Emit(GameLib.Event.LOAD_IMAGE,{image:this},function(e){this.instance=e,GameLib.Component.prototype.createInstance.call(this)}.bind(this),function(e){console.error(e),this.instance=null,GameLib.Component.prototype.createInstance.call(this)}.bind(this))},GameLib.D3.Image.prototype.updateInstance=function(e){GameLib.Utils.UndefinedOrNull(e)&&console.warn("unknown property update for Image: "+e),"fileName"!==e&&"extension"!==e&&"path"!==e||this.createInstance()},GameLib.D3.Image.prototype.toApiObject=function(){return new GameLib.D3.API.Image(this.id,this.name,this.fileName,this.extension,this.path,this.contentType,this.size,GameLib.Utils.IdOrNull(this.parentEntity))},GameLib.D3.Image.FromObject=function(e,t){return new GameLib.D3.Image(e,GameLib.D3.API.Image.FromObject(t))},GameLib.D3.Light=function(e,t){if(this.graphics=e,this.graphics.isNotThreeThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),t instanceof GameLib.D3.Light)return t;GameLib.D3.API.Light.call(this,t.id,t.lightType,t.name,t.color,t.intensity,t.position,t.targetPosition,t.quaternion,t.rotation,t.scale,t.distance,t.decay,t.power,t.angle,t.penumbra,t.parentScene,t.parentEntity),this.color=new GameLib.Color(e,this.color,this),this.position=new GameLib.Vector3(e,this.position,this),this.targetPosition=new GameLib.Vector3(e,this.targetPosition,this),this.scale=new GameLib.Vector3(e,this.scale,this),this.quaternion=new GameLib.Quaternion(e,this.quaternion,this),this.rotation=new GameLib.Vector3(e,this.rotation,this),GameLib.Component.call(this,GameLib.Component.COMPONENT_LIGHT,{parentScene:GameLib.D3.Scene})},GameLib.D3.Light.prototype=Object.create(GameLib.D3.API.Light.prototype),GameLib.D3.Light.prototype.constructor=GameLib.D3.Light,GameLib.D3.Light.LIGHT_TYPE_AMBIENT=1,GameLib.D3.Light.LIGHT_TYPE_DIRECTIONAL=2,GameLib.D3.Light.LIGHT_TYPE_POINT=3,GameLib.D3.Light.LIGHT_TYPE_SPOT=4,GameLib.D3.Light.prototype.createInstance=function(){if(this.lightType===GameLib.D3.Light.LIGHT_TYPE_AMBIENT||"AmbientLight"===this.lightType)this.instance=new THREE.AmbientLight(this.color.instance,this.intensity);else if(this.lightType===GameLib.D3.Light.LIGHT_TYPE_DIRECTIONAL||"DirectionalLight"===this.lightType)this.instance=new THREE.DirectionalLight(this.color.instance,this.intensity);else if(this.lightType===GameLib.D3.Light.LIGHT_TYPE_POINT||"PointLight"===this.lightType)this.instance=new THREE.PointLight(this.color.instance,this.intensity),this.instance.distance=this.distance,this.instance.decay=this.decay;else{if(this.lightType!==GameLib.D3.Light.LIGHT_TYPE_SPOT&&"SpotLight"!==this.lightType)return void console.warn("unsupported light type: "+this.lightType);this.instance=new THREE.SpotLight(this.color.instance,this.intensity),this.instance.distance=this.distance,this.instance.angle=this.angle,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(){return new GameLib.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){return new GameLib.D3.Light(e,GameLib.D3.API.Light.FromObject(t))},GameLib.D3.LookAt=function(e,t){if(this.graphics=e,this.graphics.isNotThreeThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),t instanceof GameLib.D3.LookAt)return t;GameLib.D3.API.LookAt.call(this,t.id,t.name,t.currentComponent,t.targetComponent,t.targetPositionOffset,t.rotationSpeed,t.parentEntity),this.targetPositionOffset=new GameLib.Vector3(this.graphics,this.targetPositionOffset,this),this.lookAtMatrix=new GameLib.Matrix4(this.graphics,this.lookAtMatrix,this),this.up=new GameLib.Vector3(this.graphics,this.up,this),this.currentRotation=new GameLib.Quaternion(this.graphics,this.currentRotation,this),this.targetPosition=new GameLib.Vector3(this.graphics,this.targetPosition,this),GameLib.Component.call(this,GameLib.Component.COMPONENT_LOOK_AT,{currentComponent:GameLib.Component,targetComponent:GameLib.Component})},GameLib.D3.LookAt.prototype=Object.create(GameLib.D3.API.LookAt.prototype),GameLib.D3.LookAt.prototype.constructor=GameLib.D3.LookAt,GameLib.D3.LookAt.prototype.createInstance=function(){this.instance=!0,GameLib.Component.prototype.createInstance.call(this)},GameLib.D3.LookAt.prototype.updateInstance=function(){},GameLib.D3.LookAt.prototype.toApiObject=function(){return new GameLib.D3.API.LookAt(this.id,this.name,GameLib.Utils.IdOrNull(this.currentComponent),GameLib.Utils.IdOrNull(this.targetComponent),this.targetPositionOffset.toApiObject(),this.rotationSpeed,GameLib.Utils.IdOrNull(this.parentEntity))},GameLib.D3.LookAt.FromObject=function(e,t){var i=GameLib.D3.API.LookAt.FromObject(t);return new GameLib.D3.LookAt(e,i)},GameLib.D3.LookAt.prototype.update=function(e){this.currentComponent&&this.targetComponent&&(this.targetPosition.x=this.targetComponent.position.x+this.targetPositionOffset.x,this.targetPosition.y=this.targetComponent.position.y+this.targetPositionOffset.y,this.targetPosition.z=this.targetComponent.position.z+this.targetPositionOffset.z,this.targetPosition.updateInstance(),this.currentComponent.lookAt.x=this.targetPosition.x,this.currentComponent.lookAt.y=this.targetPosition.y,this.currentComponent.lookAt.z=this.targetPosition.z,this.currentComponent.lookAt.updateInstance())},GameLib.D3.Material=function(e,t){if(this.graphics=e,this.graphics.isNotThreeThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),t instanceof GameLib.D3.Material)return t -;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=new GameLib.Color(e,this.specular,this),this.color=new GameLib.Color(e,this.color,this),this.emissive=new GameLib.Color(e,this.emissive,this),this.alphaMap&&this.alphaMap instanceof GameLib.D3.API.Texture&&(this.alphaMap=new GameLib.D3.Texture(this.graphics,this.alphaMap)),this.aoMap&&this.aoMap instanceof GameLib.D3.API.Texture&&(this.aoMap=new GameLib.D3.Texture(this.graphics,this.aoMap)),this.bumpMap&&this.bumpMap instanceof GameLib.D3.API.Texture&&(this.bumpMap=new GameLib.D3.Texture(this.graphics,this.bumpMap)),this.diffuseMap&&this.diffuseMap instanceof GameLib.D3.API.Texture&&(this.diffuseMap=new GameLib.D3.Texture(this.graphics,this.diffuseMap)),this.displacementMap&&this.displacementMap instanceof GameLib.D3.API.Texture&&(this.displacementMap=new GameLib.D3.Texture(this.graphics,this.displacementMap)),this.emissiveMap&&this.emissiveMap instanceof GameLib.D3.API.Texture&&(this.emissiveMap=new GameLib.D3.Texture(this.graphics,this.emissiveMap)),this.environmentMap&&this.environmentMap instanceof GameLib.D3.API.Texture&&(this.environmentMap=new GameLib.D3.Texture(this.graphics,this.environmentMap)),this.lightMap&&this.lightMap instanceof GameLib.D3.API.Texture&&(this.lightMap=new GameLib.D3.Texture(this.graphics,this.lightMap)),this.metalnessMap&&this.metalnessMap instanceof GameLib.D3.API.Texture&&(this.metalnessMap=new GameLib.D3.Texture(this.graphics,this.metalnessMap)),this.normalMap&&this.normalMap instanceof GameLib.D3.API.Texture&&(this.normalMap=new GameLib.D3.Texture(this.graphics,this.normalMap)),this.roughnessMap&&this.roughnessMap instanceof GameLib.D3.API.Texture&&(this.roughnessMap=new GameLib.D3.Texture(this.graphics,this.roughnessMap)),this.specularMap&&this.specularMap instanceof GameLib.D3.API.Texture&&(this.specularMap=new GameLib.D3.Texture(this.graphics,this.specularMap)),GameLib.Component.call(this,GameLib.Component.COMPONENT_MATERIAL,{alphaMap:GameLib.D3.Texture,aoMap:GameLib.D3.Texture,bumpMap:GameLib.D3.Texture,diffuseMap:GameLib.D3.Texture,displacementMap:GameLib.D3.Texture,emissiveMap:GameLib.D3.Texture,environmentMap:GameLib.D3.Texture,lightMap:GameLib.D3.Texture,metalnessMap:GameLib.D3.Texture,normalMap:GameLib.D3.Texture,roughnessMap:GameLib.D3.Texture,specularMap:GameLib.D3.Texture})},GameLib.D3.Material.prototype=Object.create(GameLib.D3.API.Material.prototype),GameLib.D3.Material.prototype.constructor=GameLib.D3.Material,GameLib.D3.Material.TYPE_MULTIPLY_OPERATION=0,GameLib.D3.Material.TYPE_MIX_OPERATION=1,GameLib.D3.Material.TYPE_ADD_OPERATION=2,GameLib.D3.Material.TYPE_NO_COLORS=0,GameLib.D3.Material.TYPE_FACE_COLORS=1,GameLib.D3.Material.TYPE_VERTEX_COLORS=2,GameLib.D3.Material.TYPE_NO_BLENDING=0,GameLib.D3.Material.TYPE_NORMAL_BLENDING=1,GameLib.D3.Material.TYPE_ADDITIVE_BLENDING=2,GameLib.D3.Material.TYPE_SUBTRACTIVE_BLENDING=3,GameLib.D3.Material.TYPE_MULTIPLY_BLENDING=4,GameLib.D3.Material.TYPE_CUSTOM_BLENDING=5,GameLib.D3.Material.TYPE_ZERO_FACTOR=200,GameLib.D3.Material.TYPE_ONE_FACTOR=201,GameLib.D3.Material.TYPE_SRC_COLOR_FACTOR=202,GameLib.D3.Material.TYPE_ONE_MINUS_SRC_COLOR_FACTOR=203,GameLib.D3.Material.TYPE_SRC_ALPHA_FACTOR=204,GameLib.D3.Material.TYPE_ONE_MINUS_SRC_ALPHA_FACTOR=205,GameLib.D3.Material.TYPE_DST_ALPHA_FACTOR=206,GameLib.D3.Material.TYPE_ONE_MINUS_DST_ALPHA_FACTOR=207,GameLib.D3.Material.TYPE_DST_COLOR_FACTOR=208,GameLib.D3.Material.TYPE_ONE_MINUS_DST_COLOR_FACTOR=209,GameLib.D3.Material.TYPE_SRC_ALPHA_SATURATE_FACTOR=210,GameLib.D3.Material.TYPE_ADD_EQUATION=100,GameLib.D3.Material.TYPE_SUBTRACT_EQUATION=101,GameLib.D3.Material.TYPE_REVERSE_SUBTRACT_EQUATION=102,GameLib.D3.Material.TYPE_MIN_EQUATION=103,GameLib.D3.Material.TYPE_MAX_EQUATION=104,GameLib.D3.Material.TYPE_NEVER_DEPTH=0,GameLib.D3.Material.TYPE_ALWAYS_DEPTH=1,GameLib.D3.Material.TYPE_LESS_DEPTH=2,GameLib.D3.Material.TYPE_LESS_EQUAL_DEPTH=3,GameLib.D3.Material.TYPE_EQUAL_DEPTH=4,GameLib.D3.Material.TYPE_GREATER_EQUAL_DEPTH=5,GameLib.D3.Material.TYPE_GREATER_DEPTH=6,GameLib.D3.Material.TYPE_NOT_EQUAL_DEPTH=7,GameLib.D3.Material.TYPE_FRONT_SIDE=0,GameLib.D3.Material.TYPE_BACK_SIDE=1,GameLib.D3.Material.TYPE_DOUBLE_SIDE=2,GameLib.D3.Material.TYPE_FLAT_SHADING=1,GameLib.D3.Material.TYPE_SMOOTH_SHADING=2,GameLib.D3.Material.MATERIAL_TYPE_LINE_BASIC=1,GameLib.D3.Material.MATERIAL_TYPE_LINE_DASHED=2,GameLib.D3.Material.MATERIAL_TYPE_BASIC=3,GameLib.D3.Material.MATERIAL_TYPE_DEPTH=4,GameLib.D3.Material.MATERIAL_TYPE_LAMBERT=5,GameLib.D3.Material.MATERIAL_TYPE_NORMAL=6,GameLib.D3.Material.MATERIAL_TYPE_PHONG=7,GameLib.D3.Material.MATERIAL_TYPE_STANDARD=8,GameLib.D3.Material.MATERIAL_TYPE_POINTS=9,GameLib.D3.Material.MATERIAL_TYPE_SPRITE=10,GameLib.D3.Material.MATERIAL_TYPE_TOON=11,GameLib.D3.Material.LINE_CAP_BUTT=1,GameLib.D3.Material.LINE_CAP_ROUND=2,GameLib.D3.Material.LINE_CAP_SQUARE=3,GameLib.D3.Material.LINE_JOIN_ROUND=1,GameLib.D3.Material.LINE_JOIN_BEVEL=2,GameLib.D3.Material.LINE_JOIN_MITER=3,GameLib.D3.Material.prototype.createToonMaterialInstance=function(){return new THREE.MeshToonMaterial({name:this.name,opacity:this.opacity,transparent:this.transparent,blending:this.blending,blendSrc:this.blendSrc,blendDst:this.blendDst,blendEquation:this.blendEquation,depthTest:this.depthTest,depthFunc:this.depthFunc,depthWrite:this.depthWrite,polygonOffset:this.polygonOffset,polygonOffsetFactor:this.polygonOffsetFactor,polygonOffsetUnits:this.polygonOffsetUnits,alphaTest:this.alphaTest,clippingPlanes:this.clippingPlanes,clipShadows:this.clipShadows,overdraw:this.overdraw,visible:this.visible,side:this.side,color:this.color.instance,roughness:this.roughness,metalness:this.metalness,lightMapIntensity:this.lightMapIntensity,aoMapIntensity:this.aoMapIntensity,emissive:this.emissive.instance,emissiveIntensity:this.emissiveIntensity,bumpScale:this.bumpScale,normalScale:this.normalScale,displacementScale:this.displacementScale,refractionRatio:this.refractionRatio,fog:this.fog,flatShading:this.flatShading,wireframe:this.wireframe,wireframeLinewidth:this.wireframeLineWidth,wireframeLinecap:this.wireframeLineCap,wireframeLinejoin:this.wireframeLineJoin,vertexColors:GameLib.D3.Material.TYPE_VERTEX_COLORS,skinning:this.skinning,morphTargets:this.morphTargets,morphNormals:this.morphNormals})},GameLib.D3.Material.prototype.createStandardMaterialInstance=function(){return new THREE.MeshStandardMaterial({name:this.name,opacity:this.opacity,transparent:this.transparent,blending:this.blending,blendSrc:this.blendSrc,blendDst:this.blendDst,blendEquation:this.blendEquation,depthTest:this.depthTest,depthFunc:this.depthFunc,depthWrite:this.depthWrite,polygonOffset:this.polygonOffset,polygonOffsetFactor:this.polygonOffsetFactor,polygonOffsetUnits:this.polygonOffsetUnits,alphaTest:this.alphaTest,clippingPlanes:this.clippingPlanes,clipShadows:this.clipShadows,overdraw:this.overdraw,visible:this.visible,side:this.side,color:this.color.instance,roughness:this.roughness,metalness:this.metalness,lightMapIntensity:this.lightMapIntensity,aoMapIntensity:this.aoMapIntensity,emissive:this.emissive.instance,emissiveIntensity:this.emissiveIntensity,bumpScale:this.bumpScale,normalScale:this.normalScale,displacementScale:this.displacementScale,refractionRatio:this.refractionRatio,fog:this.fog,flatShading:this.flatShading,wireframe:this.wireframe,wireframeLinewidth:this.wireframeLineWidth,wireframeLinecap:this.wireframeLineCap,wireframeLinejoin:this.wireframeLineJoin,vertexColors:GameLib.D3.Material.TYPE_VERTEX_COLORS,skinning:this.skinning,morphTargets:this.morphTargets,morphNormals:this.morphNormals})},GameLib.D3.Material.prototype.createPointsMaterialInstance=function(){return new THREE.PointsMaterial({name:this.name,opacity:this.opacity,transparent:this.transparent,depthTest:this.depthTest,depthFunc:this.depthFunc,depthWrite:this.depthWrite,visible:this.visible,side:this.side,color:this.color.instance,size:this.pointSize,sizeAttenuation:this.pointSizeAttenuation})},GameLib.D3.Material.prototype.createLineBasicMaterialInstance=function(){var e="round";this.lineCap===GameLib.D3.Material.LINE_CAP_BUTT&&(e="butt"),this.lineCap===GameLib.D3.Material.LINE_CAP_SQUARE&&(e="square");var t="round";return this.lineJoin===GameLib.D3.Material.LINE_JOIN_BEVEL&&(t="bevel"),this.lineJoin===GameLib.D3.Material.LINE_JOIN_MITER&&(t="miter"),new THREE.LineBasicMaterial({name:this.name,opacity:this.opacity,transparent:this.transparent,depthTest:this.depthTest,depthFunc:this.depthFunc,depthWrite:this.depthWrite,visible:this.visible,side:this.side,color:this.color.instance,linewidth:this.lineWidth,linecap:e,linejoin:t})},GameLib.D3.Material.prototype.createPhongMaterialInstance=function(){return new THREE.MeshPhongMaterial({name:this.name,opacity:this.opacity,transparent:this.transparent,blending:this.blending,blendSrc:this.blendSrc,blendDst:this.blendDst,blendEquation:this.blendEquation,depthTest:this.depthTest,depthFunc:this.depthFunc,depthWrite:this.depthWrite,polygonOffset:this.polygonOffset,polygonOffsetFactor:this.polygonOffsetFactor,polygonOffsetUnits:this.polygonOffsetUnits,alphaTest:this.alphaTest,clippingPlanes:this.clippingPlanes,clipShadows:this.clipShadows,overdraw:this.overdraw,visible:this.visible,side:this.side,color:this.color.instance,specular:this.specular.instance,shininess:this.shininess,lightMapIntensity:this.lightMapIntensity,aoMapIntensity:this.aoMapIntensity,emissive:this.emissive.instance,emissiveIntensity:this.emissiveIntensity,bumpScale:this.bumpScale,normalScale:this.normalScale,displacementScale:this.displacementScale,combine:this.combine,refractionRatio:this.refractionRatio,fog:this.fog,flatShading:this.flatShading,wireframe:this.wireframe,wireframeLinewidth:this.wireframeLineWidth,wireframeLinecap:this.wireframeLineCap,wireframeLinejoin:this.wireframeLineJoin,vertexColors:GameLib.D3.Material.TYPE_VERTEX_COLORS,skinning:this.skinning,morphTargets:this.morphTargets,morphNormals:this.morphNormals})},GameLib.D3.Material.prototype.createMeshBasicMaterialInstance=function(){return new THREE.MeshBasicMaterial({name:this.name,opacity:this.opacity,transparent:this.transparent,blending:this.blending,blendSrc:this.blendSrc,blendDst:this.blendDst,blendEquation:this.blendEquation,depthTest:this.depthTest,depthFunc:this.depthFunc,depthWrite:this.depthWrite,polygonOffset:this.polygonOffset,polygonOffsetFactor:this.polygonOffsetFactor,polygonOffsetUnits:this.polygonOffsetUnits,alphaTest:this.alphaTest,clippingPlanes:this.clippingPlanes,clipShadows:this.clipShadows,overdraw:this.overdraw,visible:this.visible,side:this.side,color:this.color.instance,vertexColors:GameLib.D3.Material.TYPE_VERTEX_COLORS,fog:this.fog})},GameLib.D3.Material.prototype.checkTexture=function(e,t){var i=!1;return this[e]&&this[e].instance?this.instance[t]!==this[e].instance&&(this.instance[t]=this[e].instance,i=!0):null!==this.instance[t]&&(this.instance[t]=null,i=!0),i},GameLib.D3.Material.prototype.updateTextures=function(){var e=!1;return this.checkTexture("alphaMap","alphaMap")&&(e=!0),this.checkTexture("aoMap","aoMap")&&(e=!0),this.checkTexture("bumpMap","bumpMap")&&(e=!0),this.checkTexture("diffuseMap","map")&&(e=!0),this.checkTexture("displacementMap","displacementMap")&&(e=!0),this.checkTexture("emissiveMap","emissiveMap")&&(e=!0),this.checkTexture("environmentMap","envMap")&&(e=!0),this.checkTexture("lightMap","lightMap")&&(e=!0),this.checkTexture("metalnessMap","metalnessMap")&&(e=!0),this.checkTexture("normalMap","normalMap")&&(e=!0),this.checkTexture("roughnessMap","roughnessMap")&&(e=!0),this.checkTexture("specularMap","specularMap")&&(e=!0),e&&this.publish(GameLib.Event.MATERIAL_TEXTURES_UPDATED,{material:this}),e},GameLib.D3.Material.prototype.updateToonMaterialInstance=function(e){this.instance.name=this.name,this.instance.opacity=this.opacity,this.instance.transparent=this.transparent,this.instance.blending=this.blending,this.instance.blendSrc=this.blendSrc,this.instance.blendDst=this.blendDst,this.instance.blendEquation=this.blendEquation,this.instance.depthTest=this.depthTest,this.instance.depthFunc=this.depthFunc,this.instance.depthWrite=this.depthWrite,this.instance.polygonOffset=this.polygonOffset,this.instance.polygonOffsetFactor=this.polygonOffsetFactor,this.instance.polygonOffsetUnits=this.polygonOffsetUnits,this.instance.alphaTest=this.alphaTest,this.instance.clippingPlanes=this.clippingPlanes,this.instance.clipShadows=this.clipShadows,this.instance.overdraw=this.overdraw,this.instance.visible=this.visible,this.instance.side=this.side,this.instance.color=this.color.instance,this.instance.envMapIntensity=this.envMapIntensity,this.instance.roughness=this.roughness,this.instance.metalness=this.metalness,this.instance.lightMapIntensity=this.lightMapIntensity,this.instance.aoMapIntensity=this.aoMapIntensity,this.instance.emissive=this.emissive.instance,this.instance.emissiveIntensity=this.emissiveIntensity,this.instance.bumpScale=this.bumpScale,this.instance.normalScale=this.normalScale,this.instance.displacementScale=this.displacementScale,this.instance.refractionRatio=this.refractionRatio,this.instance.fog=this.fog,this.instance.flatShading=this.flatShading,this.instance.wireframe=this.wireframe,this.instance.wireframeLinewidth=this.wireframeLineWidth,this.instance.wireframeLinecap=this.wireframeLineCap,this.instance.wireframeLinejoin=this.wireframeLineJoin,this.instance.vertexColors=GameLib.D3.Material.TYPE_VERTEX_COLORS,this.instance.skinning=this.skinning,this.instance.morphTargets=this.morphTargets,this.instance.morphNormals=this.morphNormals},GameLib.D3.Material.prototype.updateStandardMaterialInstance=function(e){this.instance.name=this.name,this.instance.opacity=this.opacity,this.instance.transparent=this.transparent,this.instance.blending=this.blending,this.instance.blendSrc=this.blendSrc,this.instance.blendDst=this.blendDst,this.instance.blendEquation=this.blendEquation,this.instance.depthTest=this.depthTest,this.instance.depthFunc=this.depthFunc,this.instance.depthWrite=this.depthWrite,this.instance.polygonOffset=this.polygonOffset,this.instance.polygonOffsetFactor=this.polygonOffsetFactor,this.instance.polygonOffsetUnits=this.polygonOffsetUnits,this.instance.alphaTest=this.alphaTest,this.instance.clippingPlanes=this.clippingPlanes,this.instance.clipShadows=this.clipShadows,this.instance.overdraw=this.overdraw,this.instance.visible=this.visible,this.instance.side=this.side,this.instance.color=this.color.instance,this.instance.envMapIntensity=this.envMapIntensity,this.instance.roughness=this.roughness,this.instance.metalness=this.metalness,this.instance.lightMapIntensity=this.lightMapIntensity,this.instance.aoMapIntensity=this.aoMapIntensity,this.instance.emissive=this.emissive.instance,this.instance.emissiveIntensity=this.emissiveIntensity,this.instance.bumpScale=this.bumpScale,this.instance.normalScale=this.normalScale,this.instance.displacementScale=this.displacementScale,this.instance.refractionRatio=this.refractionRatio,this.instance.fog=this.fog,this.instance.flatShading=this.flatShading,this.instance.wireframe=this.wireframe,this.instance.wireframeLinewidth=this.wireframeLineWidth,this.instance.wireframeLinecap=this.wireframeLineCap,this.instance.wireframeLinejoin=this.wireframeLineJoin,this.instance.vertexColors=GameLib.D3.Material.TYPE_VERTEX_COLORS,this.instance.skinning=this.skinning,this.instance.morphTargets=this.morphTargets,this.instance.morphNormals=this.morphNormals},GameLib.D3.Material.prototype.updatePointsMaterialInstance=function(e){this.instance.name=this.name,this.instance.opacity=this.opacity,this.instance.transparent=this.transparent,this.instance.depthFunc=this.depthFunc,this.instance.depthWrite=this.depthWrite,this.instance.visible=this.visible,this.instance.side=this.side,this.instance.color=this.color.instance,this.instance.size=this.pointSize,this.instance.sizeAttenuation=this.pointSizeAttenuation},GameLib.D3.Material.prototype.updateLineBasicMaterialInstance=function(e){var t="round";this.lineCap===GameLib.D3.Material.LINE_CAP_BUTT&&(t="butt"),this.lineCap===GameLib.D3.Material.LINE_CAP_SQUARE&&(t="square");var i="round";this.lineJoin===GameLib.D3.Material.LINE_JOIN_BEVEL&&(i="bevel"),this.lineJoin===GameLib.D3.Material.LINE_JOIN_MITER&&(i="miter"),this.instance.name=this.name,this.instance.opacity=this.opacity,this.instance.transparent=this.transparent,this.instance.depthFunc=this.depthFunc,this.instance.depthWrite=this.depthWrite,this.instance.visible=this.visible,this.instance.side=this.side,this.instance.color=this.color.instance,this.instance.linewidth=this.lineWidth,this.instance.linecap=t,this.instance.linejoin=i},GameLib.D3.Material.prototype.updatePhongMaterialInstance=function(e){this.instance.name=this.name,this.instance.opacity=this.opacity,this.instance.transparent=this.transparent,this.instance.blending=this.blending,this.instance.blendSrc=this.blendSrc,this.instance.blendDst=this.blendDst,this.instance.blendEquation=this.blendEquation,this.instance.depthTest=this.depthTest,this.instance.depthFunc=this.depthFunc,this.instance.depthWrite=this.depthWrite,this.instance.polygonOffset=this.polygonOffset,this.instance.polygonOffsetFactor=this.polygonOffsetFactor,this.instance.polygonOffsetUnits=this.polygonOffsetUnits,this.instance.alphaTest=this.alphaTest,this.instance.clippingPlanes=this.clippingPlanes,this.instance.clipShadows=this.clipShadows,this.instance.overdraw=this.overdraw,this.instance.visible=this.visible,this.instance.side=this.side,this.instance.color=this.color.instance,this.instance.specular=this.specular.instance,this.instance.shininess=this.shininess,this.instance.lightMapIntensity=this.lightMapIntensity,this.instance.aoMapIntensity=this.aoMapIntensity,this.instance.emissive=this.emissive.instance,this.instance.emissiveIntensity=this.emissiveIntensity,this.instance.envMapIntensity=this.envMapIntensity,this.instance.bumpScale=this.bumpScale,this.instance.normalScale=this.normalScale,this.instance.displacementScale=this.displacementScale,this.instance.combine=this.combine,this.instance.refractionRatio=this.refractionRatio,this.instance.fog=this.fog,this.instance.flatShading=this.flatShading,this.instance.wireframe=this.wireframe,this.instance.wireframeLinewidth=this.wireframeLineWidth,this.instance.wireframeLinecap=this.wireframeLineCap,this.instance.wireframeLinejoin=this.wireframeLineJoin,this.instance.vertexColors=GameLib.D3.Material.TYPE_VERTEX_COLORS,this.instance.skinning=this.skinning,this.instance.morphTargets=this.morphTargets,this.instance.morphNormals=this.morphNormals};GameLib.D3.Material.prototype.updateMeshBasicMaterialInstance=function(e){this.instance.name=this.name,this.instance.opacity=this.opacity,this.instance.transparent=this.transparent,this.instance.blending=this.blending,this.instance.blendSrc=this.blendSrc,this.instance.blendDst=this.blendDst,this.instance.blendEquation=this.blendEquation,this.instance.depthTest=this.depthTest,this.instance.depthFunc=this.depthFunc,this.instance.depthWrite=this.depthWrite,this.instance.polygonOffset=this.polygonOffset,this.instance.polygonOffsetFactor=this.polygonOffsetFactor,this.instance.polygonOffsetUnits=this.polygonOffsetUnits,this.instance.alphaTest=this.alphaTest,this.instance.clippingPlanes=this.clippingPlanes,this.instance.clipShadows=this.clipShadows,this.instance.overdraw=this.overdraw,this.instance.visible=this.visible,this.instance.side=this.side,this.instance.color=this.color.instance,this.instance.vertexColors=GameLib.D3.Material.TYPE_VERTEX_COLORS,this.instance.fog=this.fog},GameLib.D3.Material.prototype.createInstance=function(){this.materialType===GameLib.D3.Material.MATERIAL_TYPE_STANDARD?this.instance=this.createStandardMaterialInstance():this.materialType===GameLib.D3.Material.MATERIAL_TYPE_POINTS?this.instance=this.createPointsMaterialInstance():this.materialType===GameLib.D3.Material.MATERIAL_TYPE_PHONG?this.instance=this.createPhongMaterialInstance():this.materialType===GameLib.D3.Material.MATERIAL_TYPE_BASIC?this.instance=this.createMeshBasicMaterialInstance():this.materialType===GameLib.D3.Material.MATERIAL_TYPE_LINE_BASIC?this.instance=this.createLineBasicMaterialInstance():this.materialType===GameLib.D3.Material.MATERIAL_TYPE_TOON?this.instance=this.createToonMaterialInstance():console.warn("material type is not implemented yet: "+this.materialType),this.instance.needsUpdate=!0,this.updateTextures(),GameLib.Component.prototype.createInstance.call(this)},GameLib.D3.Material.prototype.updateInstance=function(e){return this.instance?"materialType"===e?(this.createInstance(),void this.publish(GameLib.Event.MATERIAL_TYPE_CHANGED,{material:this})):("alphaMap"!==e&&"aoMap"!==e&&"bumpMap"!==e&&"diffuseMap"!==e&&"displacementMap"!==e&&"emissiveMap"!==e&&"environmentMap"!==e&&"lightMap"!==e&&"metalnessMap"!==e&&"normalMap"!==e&&"roughnessMap"!==e&&"specularMap"!==e||this.updateTextures(),this.materialType===GameLib.D3.Material.MATERIAL_TYPE_STANDARD?this.updateStandardMaterialInstance(e):this.materialType===GameLib.D3.Material.MATERIAL_TYPE_POINTS?this.updatePointsMaterialInstance(e):this.materialType===GameLib.D3.Material.MATERIAL_TYPE_PHONG?this.updatePhongMaterialInstance(e):this.materialType===GameLib.D3.Material.MATERIAL_TYPE_BASIC?this.updateMeshBasicMaterialInstance(e):this.materialType===GameLib.D3.Material.MATERIAL_TYPE_LINE_BASIC?this.updateLineBasicMaterialInstance(e):this.materialType===GameLib.D3.Material.MATERIAL_TYPE_TOON?this.updateToonMaterialInstance(e):console.warn("not yet implemented (material type = "+this.materialType+")"),void(this.instance.needsUpdate=!0)):void console.warn("Attempt to update a non-existent instance")},GameLib.D3.Material.prototype.toApiObject=function(e){GameLib.Utils.UndefinedOrNull(e)&&(e=!1);var t=null;this.alphaMap&&(e&&this.alphaMap.save(),t=this.alphaMap.id);var i=null;this.aoMap&&(e&&this.aoMap.save(),i=this.aoMap.id);var n=null;this.bumpMap&&(e&&this.bumpMap.save(),n=this.bumpMap.id);var a=null;this.diffuseMap&&(e&&this.diffuseMap.save(),a=this.diffuseMap.id);var s=null;this.displacementMap&&(e&&this.displacementMap.save(),s=this.displacementMap.id);var o=null;this.emissiveMap&&(e&&this.emissiveMap.save(),o=this.emissiveMap.id);var r=null;this.environmentMap&&(e&&this.environmentMap.save(),r=this.environmentMap.id);var c=null;this.lightMap&&(e&&this.lightMap.save(),c=this.lightMap.id);var h=null;this.metalnessMap&&(e&&this.metalnessMap.save(),h=this.metalnessMap.id);var m=null;this.normalMap&&(this.normalMap.save(),m=this.normalMap.id);var l=null;this.roughnessMap&&(e&&this.roughnessMap.save(),l=this.roughnessMap.id);var p=null;return this.specularMap&&(e&&this.specularMap.save(),p=this.specularMap.id),new GameLib.D3.API.Material(this.id,this.materialType,this.name,this.opacity,this.side,this.transparent,this.specular.toApiObject(),this.lightMapIntensity,this.aoMapIntensity,this.color.toApiObject(),this.emissive.toApiObject(),this.emissiveIntensity,this.combine,this.shininess,this.reflectivity,this.refractionRatio,this.fog,this.wireframe,this.wireframeLineWidth,this.wireframeLineCap,this.wireframeLineJoin,this.vertexColors,this.skinning,this.morphTargets,this.morphNormals,this.lineWidth,this.lineCap,this.lineJoin,this.dashSize,this.gapWidth,this.blending,this.blendSrc,this.blendDst,this.blendEquation,this.depthTest,this.depthFunc,this.depthWrite,this.polygonOffset,this.polygonOffsetFactor,this.polygonOffsetUnits,this.alphaTest,this.clippingPlanes,this.clipShadows,this.visible,this.overdraw,this.flatShading,this.bumpScale,this.normalScale,this.displacementScale,this.displacementBias,this.roughness,this.metalness,this.pointSize,this.pointSizeAttenuation,this.spriteRotation,this.envMapIntensity,t,i,n,a,s,o,r,c,h,m,l,p,GameLib.Utils.IdOrNull(this.parentEntity))},GameLib.D3.Material.prototype.getTextures=function(){var e=[];return this.alphaMap&&e.push(this.alphaMap),this.aoMap&&e.push(this.aoMap),this.bumpMap&&e.push(this.bumpMap),this.diffuseMap&&e.push(this.diffuseMap),this.displacementMap&&e.push(this.displacementMap),this.emissiveMap&&e.push(this.emissiveMap),this.environmentMap&&e.push(this.environmentMap),this.lightMap&&e.push(this.lightMap),this.metalnessMap&&e.push(this.metalnessMap),this.normalMap&&e.push(this.normalMap),this.roughnessMap&&e.push(this.roughnessMap),this.specularMap&&e.push(this.specularMap),e},GameLib.D3.Material.FromObject=function(e,t){return new GameLib.D3.Material(e,GameLib.D3.API.Material.FromObject(t))},GameLib.D3.Mesh=function(e,t){if(this.graphics=e,this.graphics.isNotThreeThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),t instanceof GameLib.D3.Mesh)return t;GameLib.D3.API.Mesh.call(this,t.id,t.meshType,t.name,t.vertices,t.faces,t.materials,t.parentMesh,t.parentScene,t.skeleton,t.skinIndices,t.skinWeights,t.position,t.quaternion,t.rotation,t.scale,t.up,t.modelMatrix,t.parentEntity,t.renderOrder,t.isBufferMesh,t.useQuaternion,t.visible),this.faces=this.faces.map(function(e){return e instanceof GameLib.D3.API.Face?new GameLib.D3.Face(this.graphics,e):e}.bind(this)),this.materials=this.materials.map(function(e){return e instanceof GameLib.D3.API.Material?new GameLib.D3.Material(this.graphics,e):e}.bind(this)),this.skeleton&&(this.skeleton=new GameLib.D3.Skeleton(this.graphics,this.skeleton)),this.vertices=this.vertices.map(function(e){return new GameLib.D3.Vertex(this.graphics,e)}.bind(this)),this.position=new GameLib.Vector3(this.graphics,this.position,this),this.quaternion=new GameLib.Quaternion(this.graphics,this.quaternion,this),this.rotation=new GameLib.Vector3(this.graphics,this.rotation,this),this.scale=new GameLib.Vector3(this.graphics,this.scale,this),this.up=new GameLib.Vector3(this.graphics,this.up,this),this.modelMatrix=new GameLib.Matrix4(this.graphics,this.modelMatrix,this),this.dimensions=new GameLib.Vector3(this.graphics,new GameLib.API.Vector3,this);var i={parentMesh:GameLib.D3.Mesh,parentScene:GameLib.D3.Scene,materials:[GameLib.D3.Material],skeleton:GameLib.D3.Skeleton},n=GameLib.Component.COMPONENT_MESH;this.meshType===GameLib.D3.Mesh.MESH_TYPE_PLANE&&(n=GameLib.Component.COMPONENT_MESH_PLANE),this.meshType===GameLib.D3.Mesh.MESH_TYPE_BOX&&(n=GameLib.Component.COMPONENT_MESH_BOX),this.meshType===GameLib.D3.Mesh.MESH_TYPE_CYLINDER&&(n=GameLib.Component.COMPONENT_MESH_CYLINDER),this.meshType===GameLib.D3.Mesh.MESH_TYPE_SPHERE&&(n=GameLib.Component.COMPONENT_MESH_SPHERE),this.meshType===GameLib.D3.Mesh.MESH_TYPE_LINE&&(n=GameLib.Component.COMPONENT_MESH_LINE),this.meshType===GameLib.D3.Mesh.MESH_TYPE_TEXT&&(n=GameLib.Component.COMPONENT_MESH_TEXT,i.font=GameLib.D3.Font),this.helper=null,this.updateRotationFromAxisAngle=!0,GameLib.Component.call(this,n,i)},GameLib.D3.Mesh.prototype=Object.create(GameLib.D3.API.Mesh.prototype),GameLib.D3.Mesh.prototype.constructor=GameLib.D3.Mesh,GameLib.D3.Mesh.MESH_TYPE_NORMAL=0,GameLib.D3.Mesh.MESH_TYPE_SKINNED=1,GameLib.D3.Mesh.MESH_TYPE_CURVE=2,GameLib.D3.Mesh.MESH_TYPE_SPHERE=3,GameLib.D3.Mesh.MESH_TYPE_PLANE=4,GameLib.D3.Mesh.MESH_TYPE_BOX=5,GameLib.D3.Mesh.MESH_TYPE_CYLINDER=6,GameLib.D3.Mesh.MESH_TYPE_TEXT=7,GameLib.D3.Mesh.MESH_TYPE_LINE=8,GameLib.D3.Mesh.prototype.lookAt=function(e){this.instance.lookAt(new THREE.Vector3(e.x,e.y,e.z)),this.rotation.x=this.instance.rotation.x,this.rotation.y=this.instance.rotation.y,this.rotation.z=this.instance.rotation.z,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},GameLib.D3.Mesh.prototype.createInstanceGeometry=function(e){if(e instanceof THREE.Geometry&&(this.computeBoundingBox(e),this.isBufferMesh))return(new THREE.BufferGeometry).fromGeometry(e);this.faces.sort(function(e,t){return e.materialIndext.materialIndex?1:0});var t=new Float32Array(this.faces.reduce(function(e,t){return e.push(this.vertices[t.v0index].position.x),e.push(this.vertices[t.v0index].position.y),e.push(this.vertices[t.v0index].position.z),e.push(this.vertices[t.v1index].position.x),e.push(this.vertices[t.v1index].position.y),e.push(this.vertices[t.v1index].position.z),e.push(this.vertices[t.v2index].position.x),e.push(this.vertices[t.v2index].position.y),e.push(this.vertices[t.v2index].position.z),e}.bind(this),[])),i=null;if(this.isBufferMesh){i=new THREE.BufferGeometry,i.addAttribute("position",new THREE.BufferAttribute(t,3));var n=new Float32Array(this.faces.reduce(function(e,t){return e.push(1,1,1,1,1,1,1,1,1),e}.bind(this),[]));i.addAttribute("color",new THREE.BufferAttribute(n,3,!0));var a=new Float32Array(this.faces.reduce(function(e,t){return t.uvs[0].map(function(t){e.push(t.x),e.push(t.y)}),e},[]));i.addAttribute("uv",new THREE.BufferAttribute(a,2));var s=new Float32Array(this.faces.reduce(function(e,t){return e.push(t.normal.x,t.normal.y,t.normal.z),e.push(t.normal.x,t.normal.y,t.normal.z),e.push(t.normal.x,t.normal.y,t.normal.z),e},[]));i.addAttribute("normal",new THREE.BufferAttribute(s,3)),i.computeVertexNormals();this.faces.reduce(function(e,t){var i=e.pop();return i.index!==t.materialIndex?(e.push(i),e.push({index:t.materialIndex,count:3})):(i.count+=3,e.push(i)),e},[{index:0,count:0}]).reduce(function(e,t){return i.addGroup(e,t.count,t.index),e+t.count},0)}else{i=new THREE.Geometry;var o=[];i.faces=this.faces.map(function(e){e.uvs[0].length>0&&o.push(e.uvs[0].map(function(e){return new THREE.Vector2(e.x,e.y)}));var t=new THREE.Face3(e.v0index,e.v1index,e.v2index);return e.normal&&(t.normal=new THREE.Vector3(e.normal.x,e.normal.y,e.normal.z)),e.color&&(t.color=new THREE.Color(e.color.r,e.color.g,e.color.b)),t.materialIndex=e.materialIndex,t}),i.vertices=this.vertices.map(function(e){return new THREE.Vector3(e.position.x,e.position.y,e.position.z)}),i.verticesNeedUpdate=!0,o.length>0&&(i.faceVertexUvs=[o]),i.computeFaceNormals(),i.computeVertexNormals()}return this.computeBoundingBox(i),i},GameLib.D3.Mesh.prototype.createInstance=function(){var e=this.createInstanceGeometry();this.skeleton?(1===this.materials.length?this.instance=new THREE.SkinnedMesh(e,this.materials[0].instance):this.instance=new THREE.SkinnedMesh(e,this.materials.map(function(e){return e.instance})),this.instance.add(this.skeleton.rootBoneInstance),this.instance.bind(this.skeleton.instance)):1===this.materials.length?this.instance=new THREE.Mesh(e,this.materials[0].instance):this.instance=new THREE.Mesh(e,this.materials.map(function(e){return e.instance})),this.instance.name=this.name,this.parentMesh&&this.parentMesh.instance&&this.parentMesh.add(this.instance,this),this.instance.position.x=this.position.x,this.instance.position.y=this.position.y,this.instance.position.z=this.position.z,this.useQuaternion?(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.quaternion.setFromAxisAngle(new THREE.Vector3(this.quaternion.axis.x,this.quaternion.axis.y,this.quaternion.axis.z),this.quaternion.angle)):(this.instance.rotation.x=this.rotation.x, -this.instance.rotation.y=this.rotation.y,this.instance.rotation.z=this.rotation.z),this.instance.scale.x=this.scale.x,this.instance.scale.y=this.scale.y,this.instance.scale.z=this.scale.z,this.instance.up.x=this.up.x,this.instance.up.y=this.up.y,this.instance.up.z=this.up.z,this.instance.renderOrder=this.renderOrder,this.instance.visible=this.visible,GameLib.Component.prototype.createInstance.call(this)},GameLib.D3.Mesh.prototype.updateInstance=function(e){GameLib.Utils.UndefinedOrNull(e)&&console.warn("unknown mesh property update"),"isBufferMesh"===e&&(this.isBufferMesh&&!(this.instance.geometry instanceof THREE.BufferGeometry)||!this.isBufferMesh&&this.instance.geometry instanceof THREE.BufferGeometry)&&(this.instance.geometry=this.createInstanceGeometry(this.instance.geometry)),"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=[],e instanceof THREE.BufferGeometry){var t=e.getAttribute("position").array,i=e.getAttribute("uv").array;e.groups.map(function(e){for(var n=e.materialIndex,a=e.start,s=e.count,o=[],r=[],c=a;cthis.maxSpeed&&(this.currentSpeed=this.maxSpeed),this.grain=this.currentSpeed/100;var t=this.spline.getPointAt(this.currentPathValue);this.currentPosition.x=t.x,this.currentPosition.y=t.y,this.currentPosition.z=t.z,this.currentPathValue+=this.grain,this.currentPathValue>=1&&(this.currentPathValue=this.currentPathValue-1),this.currentPathValue<0&&(this.currentPathValue=0);var i=this.spline.getPointAt(this.currentPathValue);this.futurePosition.x=i.x,this.futurePosition.y=i.y,this.futurePosition.z=i.z,this.raycaster.setPosition(this.currentPosition),this.raycaster.setDirection({x:-this.up.x,y:-this.up.y,z:-this.up.z});var n=this.raycaster.getFaceNormal(this.raytraceMesh);n&&(this.up.x=this.mx(n.x),this.up.y=this.my(n.y),this.up.z=this.mz(n.z)),this.rotationMatrix.lookAt(this.currentPosition,this.futurePosition,this.up),this.rotationVector.setFromRotationMatrix(this.rotationMatrix),this.mesh.position.x=this.futurePosition.x,this.mesh.position.y=this.futurePosition.y,this.mesh.position.z=this.futurePosition.z,this.mesh.quaternion.x=this.rotationVector.x,this.mesh.quaternion.y=this.rotationVector.y,this.mesh.quaternion.z=this.rotationVector.z,this.mesh.quaternion.w=this.rotationVector.w}},GameLib.D3.PhysicsWorld=function(e,t){if(this.physics=e,this.physics.isNotCannonThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),t instanceof GameLib.D3.PhysicsWorld)return t;GameLib.D3.API.PhysicsWorld.call(this,t.id,t.name,t.gravity,t.broadphase,t.solver,t.rigidBodies,t.contactMaterials,t.allowSleep,t.defaultContactMaterial,t.parentEntity),this.gravity instanceof GameLib.API.Vector3&&(this.gravity=new GameLib.Vector3(this.physics,this.gravity,this)),this.broadphase instanceof GameLib.D3.API.Broadphase&&(this.broadphase=new GameLib.D3.Broadphase(this.physics,this.broadphase)),this.solver instanceof GameLib.D3.API.Solver&&(this.solver=new GameLib.D3.Solver(this.physics,this.solver)),this.rigidBodies=this.rigidBodies.map(function(e){return e instanceof GameLib.D3.API.RigidBody?new GameLib.D3.RigidBody(this.physics,e):e}.bind(this)),this.contactMaterials=this.contactMaterials.map(function(e){return e instanceof GameLib.D3.API.FrictionContactMaterial?new GameLib.D3.FrictionContactMaterial(this.physics,e):e}.bind(this)),this.defaultContactMaterial instanceof GameLib.D3.API.FrictionContactMaterial&&(this.defaultContactMaterial=new GameLib.D3.FrictionContactMaterial(this.physics,this.defaultContactMaterial)),GameLib.Component.call(this,GameLib.Component.COMPONENT_PHYSICS_WORLD,{broadphase:GameLib.D3.Broadphase,solver:GameLib.D3.Solver,rigidBodies:[GameLib.D3.RigidBody],contactMaterials:[GameLib.D3.FrictionContactMaterial],defaultContactMaterial:GameLib.D3.FrictionContactMaterial})},GameLib.D3.PhysicsWorld.prototype=Object.create(GameLib.D3.API.PhysicsWorld.prototype),GameLib.D3.PhysicsWorld.prototype.constructor=GameLib.D3.PhysicsWorld,GameLib.D3.PhysicsWorld.prototype.createInstance=function(){if(GameLib.Utils.UndefinedOrNull(this.broadphase))throw new Error("no broadphase");if(GameLib.Utils.UndefinedOrNull(this.broadphase.instance))throw new Error("no broadphase instance");if(GameLib.Utils.UndefinedOrNull(this.solver))throw new Error("no solver");if(GameLib.Utils.UndefinedOrNull(this.solver.instance))throw new Error("no solver instance");this.instance=new CANNON.World,this.instance.broadphase=this.broadphase.instance,this.instance.solver=this.solver.instance,this.instance.gravity=this.gravity.instance,this.instance.allowSleep=this.allowSleep,this.contactMaterials.map(function(e){if(GameLib.Utils.UndefinedOrNull(e))throw new Error("no contact material");if(GameLib.Utils.UndefinedOrNull(e.instance))throw new Error("no contact material instance");this.instance.addContactMaterial(e.instance)}.bind(this)),this.rigidBodies.map(function(e){if(GameLib.Utils.UndefinedOrNull(e))throw new Error("no rigidbody");if(GameLib.Utils.UndefinedOrNull(e.instance))throw new Error("no rigidbody instance");e.parentWorld=this,this.instance.add(e.instance)}.bind(this)),this.instance.defaultContactMaterial.friction=this.defaultContactMaterial.friction,this.instance.defaultContactMaterial.restitution=this.defaultContactMaterial.restitution,this.instance.defaultContactMaterial.contactEquationStiffness=this.defaultContactMaterial.contactEquationStiffness,this.instance.defaultContactMaterial.contactEquationRelaxation=this.defaultContactMaterial.contactEquationRelaxation,this.instance.defaultContactMaterial.frictionEquationStiffness=this.defaultContactMaterial.frictionEquationStiffness,this.instance.defaultContactMaterial.frictionEquationRelaxation=this.defaultContactMaterial.frictionEquationRelaxation,GameLib.Component.prototype.createInstance.call(this)},GameLib.D3.PhysicsWorld.prototype.addRigidBody=function(e){e&&e.instance?(this.instance.add(e.instance),e.parentWorld=this,GameLib.Utils.PushUnique(this.rigidBodies,e)):console.warn("Attempt to add rigidBody "+e.name+" without an instance")},GameLib.D3.PhysicsWorld.prototype.removeRigidBody=function(e){if(!e instanceof GameLib.D3.RigidBody)return void console.warn("not a rigid body");e.instance?this.instance.remove(e.instance):console.warn("Attempt to remove rigidBody "+e.name+" without an instance"),e.parentWorld=null;var t=this.rigidBodies.indexOf(e);-1!==t?this.rigidBodies.splice(t,1):console.warn("could not remove a rigidbody from an array where it should have existed")},GameLib.D3.PhysicsWorld.prototype.updateInstance=function(){if(!this.instance)return void console.log("no world instance");this.instance.broadphase=this.broadphase.instance,this.instance.solver=this.solver.instance,this.instance.gravity=this.gravity.instance,this.instance.allowSleep=this.allowSleep,this.instance.defaultContactMaterial.friction=this.defaultContactMaterial.friction,this.instance.defaultContactMaterial.restitution=this.defaultContactMaterial.restitution,this.instance.defaultContactMaterial.contactEquationStiffness=this.defaultContactMaterial.contactEquationStiffness,this.instance.defaultContactMaterial.contactEquationRelaxation=this.defaultContactMaterial.contactEquationRelaxation,this.instance.defaultContactMaterial.frictionEquationStiffness=this.defaultContactMaterial.frictionEquationStiffness,this.instance.defaultContactMaterial.frictionEquationRelaxation=this.defaultContactMaterial.frictionEquationRelaxation},GameLib.D3.PhysicsWorld.prototype.toApiObject=function(){return new GameLib.D3.API.PhysicsWorld(this.id,this.name,this.gravity.toApiObject(),GameLib.Utils.IdOrNull(this.broadphase),GameLib.Utils.IdOrNull(this.solver),this.rigidBodies.map(function(e){return GameLib.Utils.IdOrNull(e)}),this.contactMaterials.map(function(e){return GameLib.Utils.IdOrNull(e)}),this.allowSleep,GameLib.Utils.IdOrNull(this.defaultContactMaterial),GameLib.Utils.IdOrNull(this.parentEntity))},GameLib.D3.PhysicsWorld.FromObject=function(e,t){var i=GameLib.D3.API.PhysicsWorld.FromObject(t);return new GameLib.D3.PhysicsWorld(e,i)},GameLib.D3.PolyVertex=function(e,t,i,n,a){this.localIndex=e,this.mvertIndex=t,this.uv=i,this.materialIndex=n,this.edgeIndex=a},GameLib.D3.PolyVertex.prototype.clone=function(){return new GameLib.D3.PolyVertex(this.localIndex,this.mvertIndex,this.uv.copy(),this.materialIndex,this.edgeIndex)},GameLib.D3.RaycastVehicle=function(e,t){if(this.physics=e,this.physics.isNotCannonThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),t instanceof GameLib.D3.RaycastVehicle)return t;GameLib.D3.API.RaycastVehicle.call(this,t.id,t.name,t.chassis,t.wheels,t.raycastWheels,t.parentWorld,t.parentEntity),this.chassis instanceof GameLib.D3.API.RaycastVehicle&&(this.chassis=new GameLib.D3.RaycastVehicle(this.physics,this.chassis)),this.wheels=this.wheels.map(function(e){return e instanceof GameLib.D3.API.RigidBody?new GameLib.D3.RigidBody(this.physics,e):e}.bind(this)),this.raycastWheels=this.raycastWheels.map(function(e){return e instanceof GameLib.D3.API.RaycastWheel?new GameLib.D3.RaycastWheel(this.physics,e):e}.bind(this)),GameLib.Component.call(this,GameLib.Component.COMPONENT_RAYCAST_VEHICLE,{chassis:GameLib.D3.RigidBody,wheels:[GameLib.D3.RigidBody],raycastWheels:[GameLib.D3.RaycastWheel],parentWorld:GameLib.D3.PhysicsWorld})},GameLib.D3.RaycastVehicle.prototype=Object.create(GameLib.D3.API.RaycastVehicle.prototype),GameLib.D3.RaycastVehicle.prototype.constructor=GameLib.D3.RaycastVehicle,GameLib.D3.RaycastVehicle.prototype.createInstance=function(){if(GameLib.Utils.UndefinedOrNull(this.chassis))throw new Error("no chassis");if(GameLib.Utils.UndefinedOrNull(this.chassis.instance))throw new Error("no chassis instance");if(GameLib.Utils.UndefinedOrNull(this.parentWorld))throw new Error("no parent world");if(GameLib.Utils.UndefinedOrNull(this.parentWorld.instance))throw new Error("no parent world instance");this.instance=new CANNON.RaycastVehicle({chassisBody:this.chassis.instance}),this.raycastWheels.map(function(e){if(GameLib.Utils.UndefinedOrNull(e))throw new Error("no wheel");if(GameLib.Utils.UndefinedOrNull(e.instance))throw new Error("no wheel instance");this.instance.addWheel(e.instance)}.bind(this)),this.instance.addToWorld(this.parentWorld.instance),GameLib.Component.prototype.createInstance.call(this)},GameLib.D3.RaycastVehicle.prototype.updateInstance=function(){console.log("TODO: update raycast vehicle instance")},GameLib.D3.RaycastVehicle.prototype.toApiObject=function(){return new GameLib.D3.API.RaycastVehicle(this.id,this.name,GameLib.Utils.IdOrNull(this.chassis),this.wheels.map(function(e){return GameLib.Utils.IdOrNull(e)}),this.raycastWheels.map(function(e){return GameLib.Utils.IdOrNull(e)}),GameLib.Utils.IdOrNull(this.parentWorld),GameLib.Utils.IdOrNull(this.parentEntity))},GameLib.D3.RaycastVehicle.FromObject=function(e,t){var i=GameLib.D3.API.RaycastVehicle.FromObject(t);return new GameLib.D3.RaycastVehicle(e,i)},GameLib.D3.RaycastWheel=function(e,t){if(this.physics=e,this.physics.isNotCannonThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),t instanceof GameLib.D3.RaycastWheel)return t;GameLib.D3.API.RaycastWheel.call(this,t.id,t.name,t.radius,t.directionLocal,t.suspensionStiffness,t.suspensionRestLength,t.frictionSlip,t.dampingRelaxation,t.dampingCompression,t.maxSuspensionForce,t.rollInfluence,t.axleLocal,t.chassisConnectionPointLocal,t.maxSuspensionTravel,t.customSlidingRotationalSpeed,t.useCustomSlidingRotationalSpeed,t.parentEntity,t.parentMesh),this.directionLocal=new GameLib.Vector3(this.physics,this.directionLocal,this),this.axleLocal=new GameLib.Vector3(this.physics,this.axleLocal,this),this.chassisConnectionPointLocal=new GameLib.Vector3(this.physics,this.chassisConnectionPointLocal,this),GameLib.Component.call(this,GameLib.Component.COMPONENT_RAYCAST_WHEEL,{parentMesh:GameLib.D3.Mesh})},GameLib.D3.RaycastWheel.prototype=Object.create(GameLib.D3.API.RaycastWheel.prototype),GameLib.D3.RaycastWheel.prototype.constructor=GameLib.D3.RaycastWheel,GameLib.D3.RaycastWheel.prototype.createInstance=function(){this.instance={radius:this.radius,directionLocal:this.directionLocal.instance,suspensionStiffness:this.suspensionStiffness,suspensionRestLength:this.suspensionRestLength,frictionSlip:this.frictionSlip,dampingRelaxation:this.dampingRelaxation,dampingCompression:this.dampingCompression,maxSuspensionForce:this.maxSuspensionForce,rollInfluence:this.rollInfluence,axleLocal:this.axleLocal.instance,chassisConnectionPointLocal:this.chassisConnectionPointLocal.instance,maxSuspensionTravel:this.maxSuspensionTravel,customSlidingRotationalSpeed:this.customSlidingRotationalSpeed,useCustomSlidingRotationalSpeed:this.useCustomSlidingRotationalSpeed},GameLib.Component.prototype.createInstance.call(this)},GameLib.D3.RaycastWheel.prototype.updateInstance=function(){this.instance.radius=this.radius,this.instance.directionLocal=this.directionLocal.instance,this.instance.suspensionStiffness=this.suspensionStiffness,this.instance.suspensionRestLength=this.suspensionRestLength,this.instance.frictionSlip=this.frictionSlip,this.instance.dampingRelaxation=this.dampingRelaxation,this.instance.dampingCompression=this.dampingCompression,this.instance.maxSuspensionForce=this.maxSuspensionForce,this.instance.rollInfluence=this.rollInfluence,this.instance.axleLocal=this.axleLocal.instance,this.instance.chassisConnectionPointLocal=this.chassisConnectionPointLocal.instance,this.instance.maxSuspensionTravel=this.maxSuspensionTravel,this.instance.customSlidingRotationalSpeed=this.customSlidingRotationalSpeed,this.instance.useCustomSlidingRotationalSpeed=this.useCustomSlidingRotationalSpeed},GameLib.D3.RaycastWheel.prototype.toApiObject=function(){return new GameLib.D3.API.RaycastWheel(this.id,this.name,this.radius,this.directionLocal.toApiObject(),this.suspensionStiffness,this.suspensionRestLength,this.frictionSlip,this.dampingRelaxation,this.dampingCompression,this.maxSuspensionForce,this.rollInfluence,this.axleLocal.toApiObject(),this.chassisConnectionPointLocal.toApiObject(),this.maxSuspensionTravel,this.customSlidingRotationalSpeed,this.useCustomSlidingRotationalSpeed,GameLib.Utils.IdOrNull(this.parentEntity),GameLib.Utils.IdOrNull(this.parentMesh))},GameLib.D3.RaycastWheel.FromObject=function(e,t){var i=GameLib.D3.API.RaycastWheel.FromObject(t);return new GameLib.D3.RaycastWheel(e,i)},GameLib.D3.RaycastWheel.prototype.setChassisLocalConnectionPoint=function(){this.parentMesh||console.log("you need to set the parent mesh first"),this.chassisConnectionPointLocal.x=this.parentMesh.position.x,this.chassisConnectionPointLocal.y=this.parentMesh.position.y,this.chassisConnectionPointLocal.z=this.parentMesh.position.z},GameLib.D3.Raycaster=function(e,t){if(this.graphics=e,this.graphics.isNotThreeThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),t instanceof GameLib.D3.Raycaster)return t;GameLib.D3.API.Raycaster.call(this,t.id,t.name,t.position,t.direction),this.position=new GameLib.Vector3(this.graphics,this.position,this),this.direction=new GameLib.Vector3(this.graphics,this.direction,this),GameLib.Component.call(this,GameLib.Component.COMPONENT_RAYCASTER)},GameLib.D3.Raycaster.prototype=Object.create(GameLib.D3.API.Raycaster.prototype),GameLib.D3.Raycaster.prototype.constructor=GameLib.D3.Raycaster,GameLib.D3.Raycaster.prototype.createInstance=function(){this.instance=new THREE.Raycaster,this.instance.set(this.position.instance,this.direction.instance),GameLib.Component.prototype.createInstance.call(this)},GameLib.D3.Raycaster.prototype.updateInstance=function(){this.position.instance.x=this.position.x,this.position.instance.y=this.position.y,this.position.instance.z=this.position.z,this.direction.instance.x=this.direction.x,this.direction.instance.y=this.direction.y,this.direction.instance.z=this.direction.z,this.instance.set(this.position.instance,this.direction.instance)},GameLib.D3.Raycaster.prototype.toApiObject=function(){return new GameLib.D3.API.Raycaster(this.id,this.name,this.position.toApiObject(),this.direction.toApiObject())},GameLib.D3.Raycaster.FromObject=function(e,t){var i=GameLib.D3.API.Raycaster.FromObject(t);return new GameLib.D3.Raycaster(e,i)},GameLib.D3.Raycaster.prototype.set=function(e,t){this.position.x=e.x,this.position.y=e.y,this.position.z=e.z,this.direction.x=t.x,this.direction.y=t.y,this.direction.z=t.z,this.position.updateInstance(),this.direction.updateInstance()},GameLib.D3.Raycaster.prototype.setDirection=function(e){this.direction.x=e.x,this.direction.y=e.y,this.direction.z=e.z,this.direction.updateInstance()},GameLib.D3.Raycaster.prototype.setPosition=function(e){this.position.x=e.x,this.position.y=e.y,this.position.z=e.z,this.position.updateInstance()},GameLib.D3.Raycaster.prototype.setFromCamera=function(e,t){this.instance.setFromCamera(e,t.instance),this.position.x=this.instance.ray.origin.x,this.position.y=this.instance.ray.origin.y,this.position.z=this.instance.ray.origin.z,this.direction.x=this.instance.ray.direction.x,this.direction.y=this.instance.ray.direction.y,this.direction.z=this.instance.ray.direction.z},GameLib.D3.Raycaster.prototype.getIntersectedObjects=function(e){return e.reduce(function(e,t){var i=this.instance.intersectObject(t.instance);return i.length>0&&e.push({mesh:t,distance:i[0].distance}),e}.bind(this),[])},GameLib.D3.Raycaster.prototype.getFaceNormal=function(e){var t=null,i=this.instance.intersectObject(e.instance);return i&&i.length>0&&(t=new GameLib.Vector3(this.graphics,new GameLib.API.Vector3(i[0].face.normal.x,i[0].face.normal.y,i[0].face.normal.z),this)),t},GameLib.D3.Raycaster.prototype.getIntersectPoint=function(e){var t=null,i=this.instance.intersectObject(e.instance);return i&&i.length>0&&(t=new GameLib.Vector3(this.graphics,new GameLib.API.Vector3(i[0].point.x,i[0].point.y,i[0].point.z),this)),t},GameLib.D3.RenderTarget=function(e,t){if(this.graphics=e,this.graphics.isNotThreeThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),t instanceof GameLib.D3.RenderTarget)return t -;GameLib.D3.API.RenderTarget.call(this,t.id,t.name,t.width,t.height,t.stencilBuffer,t.texture),GameLib.Component.call(this,GameLib.Component.COMPONENT_RENDER_TARGET,{texture:GameLib.D3.Texture})},GameLib.D3.RenderTarget.prototype=Object.create(GameLib.D3.API.RenderTarget.prototype),GameLib.D3.RenderTarget.prototype.constructor=GameLib.D3.RenderTarget,GameLib.D3.RenderTarget.prototype.createInstance=function(){if(GameLib.Utils.UndefinedOrNull(this.texture))throw new Error("no texture");if(GameLib.Utils.UndefinedOrNull(this.texture.instance))throw new Error("no texture instance");this.instance=new THREE.WebGLRenderTarget(this.width,this.height,{stencilBuffer:this.stencilBuffer}),this.instance.texture=this.texture.instance,GameLib.Component.prototype.createInstance.call(this)},GameLib.D3.RenderTarget.prototype.updateInstance=function(){if(this.instance)this.instance.setSize(this.width,this.height),this.instance.stencilBuffer=this.stencilBuffer,this.texture&&this.texture.instance?(this.instance.texture=this.texture.instance,this.instance.texture.needsUpdate=!0):this.instance.texture=null;else try{this.createInstance()}catch(e){console.error(e)}},GameLib.D3.RenderTarget.prototype.toApiObject=function(){return new GameLib.D3.API.RenderTarget(this.id,this.name,this.width,this.height,this.stencilBuffer,GameLib.Utils.IdOrNull(this.texture),GameLib.Utils.IdOrNull(this.parentEntity))};GameLib.D3.RenderTarget.FromObject=function(e,t){var i=GameLib.D3.API.RenderTarget.FromObject(t);return new GameLib.D3.RenderTarget(e,i)},GameLib.D3.Renderer=function(e,t){if(this.graphics=e,this.graphics.isNotThreeThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),t instanceof GameLib.D3.Renderer)return t;GameLib.D3.API.Renderer.call(this,t.id,t.name,t.autoClear,t.localClipping,t.width,t.height,t.preserveDrawingBuffer,t.domElement,t.clearColor,t.camera,t.scenes,t.viewports,t.clippingPlanes,t.bufferScene,t.bufferCamera,t.renderTarget,t.defaultScene,t.sortObjects,t.parentEntity),this.clearColor=new GameLib.Color(this.graphics,this.clearColor,this),this.domElement instanceof GameLib.API.DomElement&&(this.domElement=new GameLib.DomElement(this.domElement)),this.camera instanceof GameLib.D3.API.Camera&&(this.camera=new GameLib.D3.Camera(this.graphics,this.camera)),this.scenes=this.scenes.map(function(e){return e instanceof GameLib.D3.API.Scene?new GameLib.D3.Scene(this.graphics,e):e}.bind(this)),this.viewports=this.viewports.map(function(e){return e instanceof GameLib.D3.API.Viewport?new GameLib.D3.Viewport(this.graphics,e):e}.bind(this)),this.clippingPlanes=this.clippingPlanes.map(function(e){return e instanceof GameLib.D3.API.Mesh?new GameLib.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.bufferScene instanceof GameLib.D3.API.Scene&&(this.bufferScene=new GameLib.D3.Scene(this.graphics,this.bufferScene)),this.bufferCamera instanceof GameLib.D3.API.Camera&&(this.bufferCamera=new GameLib.D3.Camera(this.graphics,this.bufferCamera)),this.renderTarget instanceof GameLib.D3.API.RenderTarget&&(this.renderTarget=new GameLib.D3.RenderTarget(this.graphics,this.renderTarget)),GameLib.Component.call(this,GameLib.Component.COMPONENT_RENDERER,{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))throw new Error("no dom element");if(GameLib.Utils.UndefinedOrNull(this.domElement.instance))throw new Error("no dom element instance");this.instance=new THREE.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)throw new Error("is not a clipping plane or no clipping plane instance");return e.instance.clipping})),this.instance.localClippingEnabled=this.localClipping,this.instance.setSize(this.width,this.height),this.instance.setClearColor(new THREE.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(new THREE.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)throw new Error("is not a clipping plane or no clipping plane instance");return e.instance.clipping}):this.instance.clippingPlanes=[],"sortObjects"===e&&(this.instance.sortObjects=this.sortObjects);else try{this.createInstance()}catch(e){console.error(e.message)}},GameLib.D3.Renderer.prototype.toApiObject=function(){return new GameLib.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){return GameLib.Utils.IdOrNull(e)}),this.viewports.map(function(e){return GameLib.Utils.IdOrNull(e)}),this.clippingPlanes.map(function(e){return GameLib.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){var i=GameLib.D3.API.Renderer.FromObject(t);return new GameLib.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={}),t instanceof GameLib.D3.RigidBody)return t;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=new GameLib.Vector3(this.physics,this.position,this),this.quaternion=new GameLib.Quaternion(this.physics,this.quaternion,this),this.velocity=new GameLib.Vector3(this.physics,this.velocity,this),this.angularVelocity=new GameLib.Vector3(this.physics,this.angularVelocity,this),this.force=new GameLib.Vector3(this.physics),this.forcePoint=new GameLib.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=new CANNON.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))throw new Error("no shape");if(GameLib.Utils.UndefinedOrNull(e.instance))throw new Error("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.quaternion.x,this.instance.quaternion.y=this.parentMesh.quaternion.y,this.instance.quaternion.z=this.parentMesh.quaternion.z,this.instance.quaternion.w=this.parentMesh.quaternion.w},GameLib.D3.RigidBody.prototype.toApiObject=function(){return new GameLib.D3.API.RigidBody(this.id,this.name,this.mass,this.friction,this.position.toApiObject(),this.quaternion.toApiObject(),this.velocity.toApiObject(),this.angularVelocity.toApiObject(),this.linearDamping,this.angularDamping,this.allowSleep,this.sleepSpeedLimit,this.sleepTimeLimit,this.collisionFilterGroup,this.collisionFilterMask,this.fixedRotation,this.shapes.map(function(e){return GameLib.Utils.IdOrNull(e)}),this.kinematic,GameLib.Utils.IdOrNull(this.parentMesh),GameLib.Utils.IdOrNull(this.parentWorld),GameLib.Utils.IdOrNull(this.parentEntity))},GameLib.D3.RigidBody.FromObject=function(e,t){var i=GameLib.D3.API.RigidBody.FromObject(t);return new GameLib.D3.RigidBody(e,i)},GameLib.D3.RigidBody.prototype.applyForce=function(){this.instance.applyForce(this.force.instance,this.forcePoint.instance)},GameLib.D3.RigidBody.prototype.applyLocalForce=function(){this.instance.applyLocalForce(this.force.instance,this.forcePoint.instance)},GameLib.D3.Scene=function(e,t){if(this.graphics=e,this.graphics.isNotThreeThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),t instanceof GameLib.D3.Scene)return t;GameLib.D3.API.Scene.call(this,t.id,t.name,t.meshes,t.lights,t.textures,t.materials,t.images,t.fog,t.renderCamera,t.showGrid,t.showAxis,t.gridSize,t.gridColor,t.parentEntity),this.meshes=this.meshes.map(function(e){return e instanceof GameLib.D3.API.Mesh?(e.parentScene=this,new GameLib.D3.Mesh(this.graphics,e)):e}.bind(this)),this.lights=this.lights.map(function(e){return e instanceof GameLib.D3.API.Light?new GameLib.D3.Light(this.graphics,e):e}.bind(this)),this.textures=this.textures.map(function(e){if(e instanceof GameLib.D3.API.Texture){return new GameLib.D3.Texture(this.graphics,e)}return e}.bind(this)),this.materials=this.materials.map(function(e){if(e instanceof GameLib.D3.API.Material){return new GameLib.D3.Material(this.graphics,e)}return e}.bind(this)),this.images=this.images.map(function(e){if(e instanceof GameLib.D3.API.Image){return new GameLib.D3.Image(this.graphics,e)}return e}.bind(this)),this.fog instanceof GameLib.D3.API.Fog&&(this.fog=new GameLib.D3.Fog(this.graphics,this.fog)),this.renderCamera instanceof GameLib.D3.API.Camera&&(this.renderCamera=new GameLib.D3.Camera(this.graphics,this.renderCamera)),this.gridColor instanceof GameLib.API.Color&&(this.gridColor=new GameLib.Color(this.graphics,this.gridColor,this)),this.helpers=[],this.clones=[],this.grid=[],this.axis=[],this.storeClones=!1,GameLib.Component.call(this,GameLib.Component.COMPONENT_SCENE,{meshes:[GameLib.D3.Mesh],lights:[GameLib.D3.Light],textures:[GameLib.D3.Texture],materials:[GameLib.D3.Material],images:[GameLib.D3.Image],fog:GameLib.D3.Fog,renderCamera:GameLib.D3.Camera})},GameLib.D3.Scene.prototype=Object.create(GameLib.D3.API.Scene.prototype),GameLib.D3.Scene.prototype.constructor=GameLib.D3.Scene,GameLib.D3.Scene.prototype.createInstance=function(){this.instance=new THREE.Scene,this.instance.name=this.name,this.fog&&this.fog.instance&&(this.instance.fog=this.fog.instance),this.meshes.map(function(e){if(GameLib.Utils.UndefinedOrNull(e))throw new Error("no mesh");if(GameLib.Utils.UndefinedOrNull(e.instance))throw new Error("no mesh instance");this.instance.add(e.instance),e.parentScene=this}.bind(this)),this.lights.map(function(e){if(GameLib.Utils.UndefinedOrNull(e))throw new Error("no light");if(GameLib.Utils.UndefinedOrNull(e.instance))throw new Error("no light instance");this.instance.add(e.instance),e.parentScene=this}.bind(this)),this.showGrid&&this.drawGrid(),this.showAxis&&this.drawAxis(),GameLib.Component.prototype.createInstance.call(this)},GameLib.D3.Scene.prototype.updateInstance=function(e){if("name"===e)return void(this.instance.name=this.name);this.fog&&this.fog.instance!==this.instance.fog&&(this.instance.fog=this.fog.instance),this.meshes.map(function(e){this.instance.children.indexOf(-1===e.instance)&&this.instance.add(e.instance)}.bind(this)),this.lights.map(function(e){-1===this.instance.children.indexOf(e.instance)&&this.instance.add(e.instance)}.bind(this)),this.instance.children.map(function(e){var t=this.meshes.map(function(e){return e.instance}),i=this.lights.map(function(e){return e.instance});(e instanceof THREE.Mesh||e instanceof THREE.Light)&&-1===i.indexOf(e)&&-1===t.indexOf(e)&&this.instance.remove(e)}.bind(this)),"showGrid"!==e&&"gridSize"!==e&&"gridColor"!==e||(this.showGrid?this.drawGrid():this.removeGrid()),"showAxis"===e&&(this.showAxis?this.drawAxis():this.removeAxis())},GameLib.D3.Scene.prototype.toApiObject=function(){var e=this.meshes.reduce(function(e,t){return(-1===this.clones.indexOf(t)||this.storeClones)&&e.push(GameLib.Utils.IdOrNull(t)),e}.bind(this),[]),t=this.lights.reduce(function(e,t){return(-1===this.clones.indexOf(t)||this.storeClones)&&e.push(GameLib.Utils.IdOrNull(t)),e}.bind(this),[]),i=this.textures.map(function(e){return GameLib.Utils.IdOrNull(e)}),n=this.materials.map(function(e){return GameLib.Utils.IdOrNull(e)}),a=this.images.map(function(e){return GameLib.Utils.IdOrNull(e)});return new GameLib.D3.API.Scene(this.id,this.name,e,t,i,n,a,GameLib.Utils.IdOrNull(this.fog),GameLib.Utils.IdOrNull(this.renderCamera),this.showGrid,this.showAxis,this.gridSize,this.gridColor.toApiObject(),GameLib.Utils.IdOrNull(this.parentEntity))},GameLib.D3.Scene.FromObject=function(e,t){var i=GameLib.D3.API.Scene.FromObject(t);return new GameLib.D3.Scene(e,i)},GameLib.D3.Scene.prototype.addObject=function(e){e instanceof GameLib.D3.Mesh?-1===this.meshes.indexOf(e)&&this.meshes.push(e):e instanceof GameLib.D3.API.Mesh&&(e=new GameLib.D3.Mesh(this.graphics,e),this.meshes.push(e)),e instanceof GameLib.D3.Light?-1===this.lights.indexOf(e)&&this.lights.push(e):e instanceof GameLib.D3.API.Light&&(e=new GameLib.D3.Light(this.graphics,e),this.lights.push(e)),e.parentScene=this,this.instance&&e.instance&&-1===this.instance.children.indexOf(e.instance)&&this.instance.add(e.instance)},GameLib.D3.Scene.prototype.addClone=function(e){(e instanceof GameLib.D3.Mesh||e instanceof GameLib.D3.Light)&&(this.instance&&e.instance&&this.instance.add(e.instance),GameLib.Utils.PushUnique(this.clones,e),e.parentScene=this)},GameLib.D3.Scene.prototype.removeObject=function(e){var t=-1;if(e instanceof GameLib.D3.Mesh)t=this.meshes.indexOf(e),-1!==t&&this.meshes.splice(t,1),-1!==(t=this.clones.indexOf(e))&&this.clones.splice(t,1);else{if(!(e instanceof GameLib.D3.Light))return void console.warn("Cannot remove this object - what is this ?"+e.toString());t=this.lights.indexOf(e),-1!==t&&this.lights.splice(t,1),-1!==(t=this.clones.indexOf(e))&&this.clones.splice(t,1)}-1!==this.instance.children.indexOf(e.instance)?this.instance.remove(e.instance):console.warn("no scene instance"),e.parentScene===this&&(e.parentScene=null)},GameLib.D3.Scene.prototype.drawGrid=function(){this.removeGrid();for(var e=new THREE.LineBasicMaterial({color:this.gridColor.toHex(),linewidth:1}),t=-this.gridSize;t<=this.gridSize;t+=1){var i=new THREE.Geometry;i.vertices.push(new THREE.Vector3(t,0,-1*this.gridSize),new THREE.Vector3(t,0,this.gridSize));var n=new THREE.Line(i,e);this.instance.add(n),this.grid.push(n);var a=new THREE.Geometry;a.vertices.push(new THREE.Vector3(-1*this.gridSize,0,t),new THREE.Vector3(this.gridSize,0,t));var s=new THREE.Line(a,e);this.instance.add(s),this.grid.push(s)}},GameLib.D3.Scene.prototype.removeGrid=function(){this.grid.map(function(e){this.instance.remove(e)}.bind(this))},GameLib.D3.Scene.prototype.drawAxis=function(){this.removeAxis();var e=new THREE.LineBasicMaterial({color:16711680,linewidth:2}),t=new THREE.Geometry;t.vertices.push(new THREE.Vector3(0,0,0),new THREE.Vector3(100,0,0));var i=new THREE.Line(t,e);this.instance.add(i),this.axis.push(i);var n=new THREE.LineBasicMaterial({color:65280,linewidth:2}),a=new THREE.Geometry;a.vertices.push(new THREE.Vector3(0,0,0),new THREE.Vector3(0,100,0));var s=new THREE.Line(a,n);this.instance.add(s),this.axis.push(s);var o=new THREE.LineBasicMaterial({color:255,linewidth:2}),r=new THREE.Geometry;r.vertices.push(new THREE.Vector3(0,0,0),new THREE.Vector3(0,0,100));var c=new THREE.Line(r,o);this.instance.add(c),this.axis.push(c)},GameLib.D3.Scene.prototype.removeAxis=function(){this.axis.map(function(e){this.instance.remove(e)}.bind(this))},GameLib.D3.Shape=function(e,t){if(this.physics=e,this.physics.isNotCannonThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),t instanceof GameLib.D3.Shape)return t;GameLib.D3.API.Shape.call(this,t.id,t.name,t.boundingSphereRadius,t.collisionResponse,t.frictionMaterial,t.parentMesh,t.parentEntity);var i=GameLib.Component.COMPONENT_SHAPE,n={frictionMaterial:GameLib.D3.FrictionMaterial,parentMesh:GameLib.D3.Mesh};this instanceof GameLib.D3.Shape.Box&&(i=GameLib.Component.COMPONENT_SHAPE_BOX),this instanceof GameLib.D3.Shape.ConvexHull&&(i=GameLib.Component.COMPONENT_SHAPE_CONVEX_HULL),this instanceof GameLib.D3.Shape.ConvexHull.Cylinder&&(i=GameLib.Component.COMPONENT_SHAPE_CONVEX_HULL_CYLINDER),this instanceof GameLib.D3.Shape.Sphere&&(i=GameLib.Component.COMPONENT_SHAPE_SPHERE),this instanceof GameLib.D3.Shape.TriMesh&&(i=GameLib.Component.COMPONENT_SHAPE_TRI_MESH),this instanceof GameLib.D3.Shape.Plane&&(i=GameLib.Component.COMPONENT_SHAPE_PLANE),this instanceof GameLib.D3.Shape.HeightMap&&(i=GameLib.Component.COMPONENT_SHAPE_HEIGHT_MAP),GameLib.Component.call(this,i,n)},GameLib.D3.Shape.prototype=Object.create(GameLib.D3.API.Shape.prototype),GameLib.D3.Shape.prototype.constructor=GameLib.D3.Shape,GameLib.D3.Shape.prototype.createInstance=function(){GameLib.Component.prototype.createInstance.call(this)},GameLib.D3.Shape.prototype.updateInstance=function(){throw new Error("Do not instantiate this class directly - use a child class instead")},GameLib.D3.Shape.prototype.toApiObject=function(){return new GameLib.D3.API.Shape(this.id,this.name,this.boundingSphereRadius,this.collisionResponse,GameLib.Utils.IdOrNull(this.frictionMaterial),GameLib.Utils.IdOrNull(this.parentMesh),GameLib.Utils.IdOrNull(this.parentEntity))},GameLib.D3.Shape.FromObject=function(e,t){throw"not implemented"},GameLib.D3.Shape.prototype.stopVisualize=function(){GameLib.Event.Emit(GameLib.Event.STOP_VISUALIZE,{mesh:this.mesh})},GameLib.D3.Shape.prototype.visualize=function(){GameLib.Event.Emit(GameLib.Event.VISUALIZE,{shape:this})},GameLib.D3.Shape.Box=function(e,t,i){this.physics=e,this.physics.isNotCannonThrow(),GameLib.Utils.UndefinedOrNull(i)?i=new GameLib.Vector3(e,new GameLib.API.Vector3(1,1,1)):i instanceof GameLib.API.Vector3&&(i=new GameLib.Vector3(this.physics,i,this)),this.halfExtents=i,GameLib.D3.Shape.call(this,this.physics,t)},GameLib.D3.Shape.Box.prototype=Object.create(GameLib.D3.Shape.prototype),GameLib.D3.Shape.Box.prototype.constructor=GameLib.D3.Shape.Box,GameLib.D3.Shape.Box.prototype.createInstance=function(){if(GameLib.Utils.UndefinedOrNull(this.halfExtents))throw new Error("no halfExtents");if(GameLib.Utils.UndefinedOrNull(this.halfExtents.instance))throw new Error("no halfExtents instance");this.instance=new CANNON.Box(this.halfExtents.instance),GameLib.D3.Shape.prototype.createInstance.call(this)},GameLib.D3.Shape.Box.prototype.updateInstance=function(){this.instance.halfExtents.x=this.halfExtents.x,this.instance.halfExtents.y=this.halfExtents.y,this.instance.halfExtents.z=this.halfExtents.z,this.instance.updateBoundingSphereRadius(),this.instance.updateConvexPolyhedronRepresentation()},GameLib.D3.Shape.Box.prototype.toApiObject=function(){var e=GameLib.D3.Shape.prototype.toApiObject.call(this);return e.halfExtents=this.halfExtents.toApiObject(),e},GameLib.D3.Shape.Box.prototype.setFromMesh=function(){if(null===this.parentMesh)return void console.log("select a mesh first");var e=this.parentMesh.getBoundingBox();this.halfExtents.x=e.x/2,this.halfExtents.y=e.y/2,this.halfExtents.z=e.z/2,this.halfExtents.updateInstance()},GameLib.D3.Shape.Box.FromObject=function(e,t){var i=GameLib.D3.API.Shape.FromObject(t);return i.halfExtents=GameLib.API.Vector3.FromObject(t.halfExtents),new GameLib.D3.Shape.Box(e,i,i.halfExtents)},GameLib.D3.Shape.ConvexHull=function(e,t,i,n,a,s){if(this.physics=e,this.physics.isNotCannonThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),t instanceof GameLib.D3.Shape.ConvexHull)return t;GameLib.Utils.UndefinedOrNull(i)&&(i=[]),this.vertices=i,GameLib.Utils.UndefinedOrNull(n)&&(n=[]),this.faces=n,GameLib.Utils.UndefinedOrNull(a)&&(a=[]),this.uniqueAxes=a,GameLib.Utils.UndefinedOrNull(s)&&(s=[]),this.uniqueEdges=s,this.vertices=this.vertices.map(function(e){return e instanceof GameLib.D3.API.Vertex?new GameLib.D3.Vertex(this.physics,e):e}.bind(this)),this.faces=this.faces.map(function(e){return e instanceof GameLib.D3.API.Face?new GameLib.D3.Face(this.physics,e):e}.bind(this)),this.uniqueAxes=this.uniqueAxes.map(function(e){return e instanceof GameLib.API.Vector3?new GameLib.Vector3(this.physics,e,this):e}.bind(this)),this.uniqueEdges=this.uniqueEdges.map(function(e){return e instanceof GameLib.API.Vector3?new GameLib.Vector3(this.physics,e,this):e}.bind(this)),GameLib.D3.Shape.call(this,this.physics,t)},GameLib.D3.Shape.ConvexHull.prototype=Object.create(GameLib.D3.Shape.prototype),GameLib.D3.Shape.ConvexHull.prototype.constructor=GameLib.D3.Shape.ConvexHull,GameLib.D3.Shape.ConvexHull.prototype.createInstance=function(){var e=[];this.instance=new CANNON.ConvexPolyhedron(this.vertices.map(function(e){if(GameLib.Utils.UndefinedOrNull(e))throw new Error("no vertex");if(GameLib.Utils.UndefinedOrNull(e.position))throw new Error("no vertex position");if(GameLib.Utils.UndefinedOrNull(e.position.instance))throw new Error("no vertex position instance");return e.position.instance}),this.faces.map(function(t){if(GameLib.Utils.UndefinedOrNull(t))throw new Error("no face");if(GameLib.Utils.UndefinedOrNull(t.normal))throw new Error("no face normal");if(GameLib.Utils.UndefinedOrNull(t.normal.instance))throw new Error("no face normal instance");if(GameLib.Utils.UndefinedOrNull(t.v0index))throw new Error("no face v0index");if(GameLib.Utils.UndefinedOrNull(t.v1index))throw new Error("no face v1index");if(GameLib.Utils.UndefinedOrNull(t.v2index))throw new Error("no face v2index");return e.push(t.normal.instance),[t.v0index,t.v1index,t.v2index]})),this.instance.faceNormals=e,GameLib.D3.Shape.prototype.createInstance.call(this)},GameLib.D3.Shape.ConvexHull.prototype.updateInstance=function(){console.log("todo: update convex hull instance")},GameLib.D3.Shape.ConvexHull.prototype.loadFromInstance=function(){console.log("todo: eventually load the faces and vertices from the instance faces and vertices and normals"),console.log("todo: this way we can nicely visualize them with our gamelib classes :)")},GameLib.D3.Shape.ConvexHull.prototype.toApiObject=function(){var e=GameLib.D3.Shape.prototype.toApiObject.call(this);return e.vertices=this.vertices.map(function(e){return e instanceof GameLib.D3.Vertex?e.toApiObject():e}),e.faces=this.faces.map(function(e){return e instanceof GameLib.D3.Face?e.toApiObject():e}),e.uniqueAxes=this.uniqueAxes.map(function(e){return e instanceof GameLib.Vector3?e.toApiObject():e}),e.uniqueEdges=this.uniqueEdges.map(function(e){return e instanceof GameLib.Vector3?e.toApiObject():e}),e},GameLib.D3.Shape.ConvexHull.prototype.setFromMesh=function(){console.log("todo: set convex hull from mesh"),this.updateInstance()},GameLib.D3.Shape.ConvexHull.InheritableProperties=function(e,t){return{vertices:t.vertices.map(function(t){return GameLib.D3.Vertex.FromObject(e,t)}),faces:t.faces.map(function(t){return GameLib.D3.Face.FromObject(e,t)}),uniqueAxes:t.uniqueAxes.map(function(e){return GameLib.API.Vector3.FromObject(e)}),uniqueEdges:t.uniqueEdges.map(function(e){return GameLib.API.Vector3.FromObject(e)})}},GameLib.D3.Shape.ConvexHull.FromObject=function(e,t){var i=GameLib.D3.API.Shape.FromObject(t),n=GameLib.D3.Shape.ConvexHull.InheritableProperties(e,t);return new GameLib.D3.Shape.ConvexHull.call(this,e,i,n.vertices,n.faces,n.uniqueAxes,n.uniqueEdges)},GameLib.D3.Shape.ConvexHull.Cylinder=function(e,t,i,n,a,s){this.physics=e,this.physics.isNotCannonThrow(),GameLib.Utils.UndefinedOrNull(i)&&(i=1),this.radiusTop=i,GameLib.Utils.UndefinedOrNull(n)&&(n=1),this.radiusBottom=n,GameLib.Utils.UndefinedOrNull(a)&&(a=n/2),this.height=a,GameLib.Utils.UndefinedOrNull(s)&&(s=20),this.numSegments=s,GameLib.D3.Shape.ConvexHull.call(this,this.physics,t)},GameLib.D3.Shape.ConvexHull.Cylinder.prototype=Object.create(GameLib.D3.Shape.ConvexHull.prototype),GameLib.D3.Shape.ConvexHull.Cylinder.prototype.constructor=GameLib.D3.Shape.ConvexHull.Cylinder,GameLib.D3.Shape.ConvexHull.Cylinder.prototype.createInstance=function(){this.instance=new CANNON.Cylinder(this.radiusTop,this.radiusBottom,this.height,this.numSegments),GameLib.D3.Shape.prototype.createInstance.call(this)},GameLib.D3.Shape.ConvexHull.Cylinder.prototype.updateInstance=function(){console.log("todo : update cylinder instance")},GameLib.D3.Shape.ConvexHull.Cylinder.prototype.setFromMesh=function(){this.radiusTop=this.parentMesh.dimensions.x/2,this.radiusBottom=this.parentMesh.dimensions.x/2,this.height=this.parentMesh.dimensions.z},GameLib.D3.Shape.ConvexHull.Cylinder.prototype.toApiObject=function(){var e=GameLib.D3.Shape.ConvexHull.prototype.toApiObject.call(this);return e.radiusTop=this.radiusTop,e.radiusBottom=this.radiusBottom,e.height=this.height,e.numSegments=this.numSegments,e},GameLib.D3.Shape.ConvexHull.Cylinder.FromObject=function(e,t){var i=GameLib.D3.API.Shape.FromObject(t),n=GameLib.D3.Shape.ConvexHull.InheritableProperties(e,t);for(var a in n)n.hasOwnProperty(a)&&(i[a]=n[a]);return new GameLib.D3.Shape.ConvexHull.Cylinder(e,i,t.radiusTop,t.radiusBottom,t.height,t.numSegments)},GameLib.D3.Shape.HeightMap=function(e,t,i,n,a,s){this.physics=e,this.physics.isNotCannonThrow(),GameLib.Utils.UndefinedOrNull(i)&&(i=[[10,10,10],[10,10,10],[10,10,10]]),this.heightData=i,GameLib.Utils.UndefinedOrNull(n)&&(n=0),this.minValue=n,GameLib.Utils.UndefinedOrNull(a)&&(a=10),this.maxValue=a,GameLib.Utils.UndefinedOrNull(s)&&(s=1),this.elementSize=s,GameLib.D3.Shape.call(this,this.physics,t)},GameLib.D3.Shape.HeightMap.prototype=Object.create(GameLib.D3.Shape.prototype),GameLib.D3.Shape.HeightMap.prototype.constructor=GameLib.D3.Shape.HeightMap,GameLib.D3.Shape.HeightMap.prototype.createInstance=function(){this.instance=new CANNON.Heightfield(this.heightData,{elemSize:this.elementSize}),GameLib.D3.Shape.prototype.createInstance.call(this)},GameLib.D3.Shape.HeightMap.prototype.updateInstance=function(){this.instance.data=this.heightData,this.instance.elemSize=this.elemSize,this.instance.update()},GameLib.D3.Shape.HeightMap.prototype.toApiObject=function(){var e=GameLib.D3.Shape.prototype.toApiObject.call(this);return e.heightData=this.heightData,e.minValue=this.minValue,e.maxValue=this.maxValue,e.elemSize=this.elemSize,e},GameLib.D3.Shape.HeightMap.prototype.setFromMesh=function(){if(null===this.parentMesh)return void console.log("select a mesh first");if(!this.parentMesh.isHeightMap)return void console.log("not a heightmap mesh");var e=Array.prototype.slice.call(this.parentMesh.getHeightData());this.heightData=[];for(var t=0;t<=this.parentMesh.widthSegments;t++){this.heightData[t]=[];for(var i=0;i<=this.parentMesh.heightSegments;i++)this.heightData[t][i]=e[t*(this.parentMesh.widthSegments+1)+i]}this.updateInstance()},GameLib.D3.Shape.HeightMap.FromObject=function(e,t){var i=GameLib.D3.API.Shape.FromObject(t);return new GameLib.D3.Shape.HeightMap(e,i,t.heightData,t.minValue,t.maxValue,t.elemSize)},GameLib.D3.Shape.Plane=function(e,t){this.physics=e,this.physics.isNotCannonThrow(),GameLib.D3.Shape.call(this,this.physics,t)},GameLib.D3.Shape.Plane.prototype=Object.create(GameLib.D3.Shape.prototype),GameLib.D3.Shape.Plane.prototype.constructor=GameLib.D3.Shape.Plane, -GameLib.D3.Shape.Plane.prototype.createInstance=function(){this.instance=new CANNON.Plane,GameLib.D3.Shape.prototype.createInstance.call(this)},GameLib.D3.Shape.Plane.prototype.updateInstance=function(){},GameLib.D3.Shape.Plane.FromObject=function(e,t){var i=GameLib.D3.API.Shape.FromObject(t);return new GameLib.D3.Shape.Plane(e,i)},GameLib.D3.Shape.Sphere=function(e,t,i){this.physics=e,this.physics.isNotCannonThrow(),GameLib.Utils.UndefinedOrNull(i)&&(i=1),this.radius=i,GameLib.D3.Shape.call(this,this.physics,t)},GameLib.D3.Shape.Sphere.prototype=Object.create(GameLib.D3.Shape.prototype),GameLib.D3.Shape.Sphere.prototype.constructor=GameLib.D3.Shape.Sphere,GameLib.D3.Shape.Sphere.prototype.createInstance=function(){this.instance=new CANNON.Sphere(this.radius),GameLib.D3.Shape.prototype.createInstance.call(this)},GameLib.D3.Shape.Sphere.prototype.updateInstance=function(){this.instance.radius=this.radius,this.instance.updateBoundingSphereRadius()},GameLib.D3.Shape.Sphere.prototype.toApiObject=function(){var e=GameLib.D3.Shape.prototype.toApiObject.call(this);return e.radius=this.radius,e},GameLib.D3.Shape.Sphere.FromObject=function(e,t){var i=GameLib.D3.API.Shape.FromObject(t);return new GameLib.D3.Shape.Sphere(e,i,t.radius)},GameLib.D3.Shape.TriMesh=function(e,t,i,n){this.physics=e,this.physics.isNotCannonThrow(),GameLib.Utils.UndefinedOrNull(i)&&(i=[]),this.vertices=i,GameLib.Utils.UndefinedOrNull(n)&&(n=[]),this.indices=n,GameLib.D3.Shape.call(this,this.physics,t)},GameLib.D3.Shape.TriMesh.prototype=Object.create(GameLib.D3.Shape.prototype),GameLib.D3.Shape.TriMesh.prototype.constructor=GameLib.D3.Shape.TriMesh,GameLib.D3.Shape.TriMesh.prototype.createInstance=function(){this.instance=new CANNON.TriMesh(this.vertices,this.indices),GameLib.D3.Shape.prototype.createInstance.call(this)},GameLib.D3.Shape.TriMesh.prototype.updateInstance=function(){this.instance.vertices=this.vertices,this.instance.indices=this.indices,this.instance.updateAABB(),this.instance.updateBoundingSphereRadius(),this.instance.updateEdges(),this.instance.updateNormals(),this.instance.updateTree()},GameLib.D3.Skeleton=function(e,t){if(this.graphics=e,this.graphics.isNotThreeThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),t instanceof GameLib.D3.Skeleton)return t;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(e instanceof GameLib.D3.API.Bone)return new GameLib.D3.Bone(this.graphics,e);throw console.warn("apiBone not an instance of API.Bone"),new Error("apiBone not an instance of API.Bone")}.bind(this)),this.boneInverses=this.boneInverses.map(function(e){if(e instanceof GameLib.API.Matrix4)return new GameLib.Matrix4(this.graphics,e,this);throw console.warn("boneInverse not an instance of API.Matrix4"),new Error("boneInverse not an instance of API.Matrix4")}.bind(this)),this.boneMatrices=this.boneMatrices.map(function(e){if(e instanceof GameLib.API.Matrix4)return new GameLib.Matrix4(this.graphics,e,this);throw console.warn("boneMatrices not an instance of API.Matrix4"),new Error("boneMatrices not an instance of API.Matrix4")}.bind(this)),GameLib.Component.call(this,GameLib.Component.COMPONENT_SKELETON,{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){var t=this.bones.map(function(e){if(GameLib.Utils.UndefinedOrNull(e))throw new Error("no bone");if(GameLib.Utils.UndefinedOrNull(e.instance))throw new Error("no bone instance");return e.instance}),i=this.bones.reduce(function(e,t){return e||(0===t.parentBoneIds.length?t.instance:null)},null);if(GameLib.Utils.UndefinedOrNull(i))throw new Error("could not find parent bone instance");this.instance=new THREE.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){return function(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(){return new GameLib.D3.API.Skeleton(this.id,this.name,this.bones.map(function(e){return e.toApiObject()}),this.boneInverses.map(function(e){return e.toApiObject()}),this.useVertexTexture,this.boneTextureWidth,this.boneTextureHeight,this.boneMatrices.map(function(e){return e.toApiObject()}),this.boneTexture,this.parentEntity)},GameLib.D3.Skeleton.FromObject=function(e,t){if(!t)return null;var i=GameLib.D3.API.Skeleton.FromObject(t);return new GameLib.D3.Skeleton(e,i)},GameLib.D3.Solver=function(e,t){if(this.physics=e,this.physics.isNotCannonThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),t instanceof GameLib.D3.Solver)return t;GameLib.D3.API.Solver.call(this,t.id,t.name,t.solverType,t.iterations,t.tolerance,t.parentEntity),GameLib.Component.call(this,GameLib.Component.COMPONENT_SOLVER)},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.Solver.GS_SOLVER)this.instance=new CANNON.GSSolver;else{if(this.solverType!==GameLib.D3.Solver.SPLIT_SOLVER)throw new Error("unsupported solver type: "+this.solverType);this.instance=new CANNON.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.Solver.GS_SOLVER&&(this.instance instanceof CANNON.GSSolver||(this.instance=new CANNON.GSSolver)),this.solverType===GameLib.D3.Solver.SPLIT_SOLVER&&(this.instance instanceof CANNON.SplitSolver||(this.instance=new CANNON.SplitSolver)),this.instance.iterations=this.iterations,this.instance.tolerance=this.tolerance},GameLib.D3.Solver.prototype.toApiObject=function(){return new GameLib.D3.API.Solver(this.id,this.name,this.solverType,this.iterations,this.tolerance,GameLib.Utils.IdOrNull(this.parentEntity))},GameLib.D3.Solver.FromObject=function(e,t){var i=GameLib.D3.API.Solver.FromObject(t);return new GameLib.D3.Solver(e,i)},GameLib.D3.Solver.GS_SOLVER=1,GameLib.D3.Solver.SPLIT_SOLVER=2,GameLib.D3.Spline=function(e,t){if(this.graphics=e,this.graphics.isNotThreeThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),t instanceof GameLib.D3.Spline)return t;GameLib.D3.API.Spline.call(this,t.id,t.name,t.vertices,t.parentEntity),this.vertices=this.vertices.map(function(t){return new GameLib.Vector3(e,t,this)}),GameLib.Component.call(this,GameLib.Component.COMPONENT_SPLINE)},GameLib.D3.Spline.prototype=Object.create(GameLib.D3.API.Spline.prototype),GameLib.D3.Spline.prototype.constructor=GameLib.D3.Spline,GameLib.D3.Spline.prototype.createInstance=function(){var e=this.vertices.map(function(e){if(GameLib.Utils.UndefinedOrNull(e))throw new Error("no vertex");if(GameLib.Utils.UndefinedOrNull(e.instance))throw new Error("no vertex instance");return e.instance});this.instance=THREE.CatmullRomCurve3(e),GameLib.Component.prototype.createInstance.call(this)},GameLib.D3.Spline.prototype.updateInstance=function(){var e=this.vertices.map(function(e){if(GameLib.Utils.UndefinedOrNull(e))throw new Error("no vertex");if(GameLib.Utils.UndefinedOrNull(e.instance))throw new Error("no vertex instance");return e.instance});this.instance=new THREE.CatmullRomCurve3(e)},GameLib.D3.Spline.prototype.toApiObject=function(){return new GameLib.D3.API.Spline(this.id,this.name,this.vertices.map(function(e){return e.toApiObject()}),GameLib.Utils.IdOrNull(this.parentEntity))},GameLib.D3.Spline.FromObject=function(e,t){var i=GameLib.D3.API.Spline.FromObject(t);return new GameLib.D3.Spline(e,i)},GameLib.D3.Spline.prototype.getPointAt=function(e){var t=this.instance.getPointAt(e);return new GameLib.Vector3(this.graphics,new GameLib.API.Vector3(t.x,t.y,t.z),this,.1)},GameLib.D3.Stats=function(e,t,i,n,a){if(this.stats=e,this.stats.isNotStatsThrow(),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))throw console.warn("Need a DOM element for stats"),new Error("Need a DOM element for stats");this.domElement=n,GameLib.Utils.UndefinedOrNull(a)&&(a=null),this.parentEntity=a,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.instance(),this.resize(),this.domElement.instance.parentElement.appendChild(this.instance.dom),GameLib.Component.prototype.createInstance.call(this)},GameLib.D3.Stats.prototype.updateInstance=function(){this.instance=new this.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={}),t instanceof GameLib.D3.Texture)return t;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=new GameLib.Vector2(this.graphics,this.offset,this),this.repeat=new GameLib.Vector2(this.graphics,this.repeat,this),this.image instanceof GameLib.D3.API.Image&&(this.image=new GameLib.D3.Image(this.graphics,this.image)),this.images=this.images.map(function(e){return e instanceof GameLib.D3.API.Image?new GameLib.D3.Image(this.graphics,e):e}.bind(this)),this.canvas instanceof GameLib.API.Canvas&&(this.canvas=new GameLib.Canvas(this.graphics,this.canvas)),GameLib.Component.call(this,GameLib.Component.COMPONENT_TEXTURE,{image:GameLib.D3.Image,images:[GameLib.D3.Image],canvas:GameLib.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.D3.Texture.TYPE_SHORT=1011,GameLib.D3.Texture.TYPE_UNSIGNED_SHORT=1012,GameLib.D3.Texture.TYPE_INT=1013,GameLib.D3.Texture.TYPE_UNSIGNED_INT=1014,GameLib.D3.Texture.TYPE_FLOAT=1015,GameLib.D3.Texture.TYPE_HALF_FLOAT=1025,GameLib.D3.Texture.TYPE_LINEAR_ENCODING=3e3,GameLib.D3.Texture.TYPE_SRGB_ENCODING=3001,GameLib.D3.Texture.TYPE_GAMMA_ENCODING=3007,GameLib.D3.Texture.TYPE_RGBE_ENCODING=3002,GameLib.D3.Texture.TYPE_LOG_LUV_ENCODING=3003,GameLib.D3.Texture.TYPE_RGBM7_ENCODING=3004,GameLib.D3.Texture.TYPE_RGBM16_ENCODING=3005,GameLib.D3.Texture.TYPE_RGBD_ENCODING=3006,GameLib.D3.Texture.TEXTURE_TYPE_NORMAL=1,GameLib.D3.Texture.TEXTURE_TYPE_CUBE=2,GameLib.D3.Texture.TEXTURE_TYPE_CANVAS=3,GameLib.D3.Texture.prototype.createInstance=function(){if(this.typeId===GameLib.D3.Texture.TEXTURE_TYPE_CUBE){if(6!==this.images.length)throw new Error("not enough images for cube texture");var e=this.images.map(function(e){if(GameLib.Utils.UndefinedOrNull(e))throw new Error("no image");if(GameLib.Utils.UndefinedOrNull(e.instance))throw new Error("no image instance");return e.instance});this.instance=new THREE.CubeTexture(e)}else if(this.typeId===GameLib.D3.Texture.TEXTURE_TYPE_NORMAL)GameLib.Utils.UndefinedOrNull(this.image)||GameLib.Utils.UndefinedOrNull(this.image.instance)?this.instance=new THREE.Texture:this.instance=new THREE.Texture(this.image.instance);else if(this.typeId===GameLib.D3.Texture.TEXTURE_TYPE_CANVAS)if(GameLib.Utils.UndefinedOrNull(this.canvas))this.instance=new THREE.Texture;else{if(GameLib.Utils.UndefinedOrNull(this.canvas.instance))throw new Error("no canvas instance");this.instance=new THREE.Texture(this.canvas.instance)}this.mapping=this.instance.mapping,this.encoding=this.instance.encoding,this.format=this.instance.format,this.instance.name=this.name,this.instance.flipY=this.flipY,this.instance.offset.x=this.offset.x,this.instance.offset.y=this.offset.y,this.instance.repeat.x=this.repeat.x,this.instance.repeat.y=this.repeat.y,this.instance.wrapS=this.wrapS,this.instance.wrapT=this.wrapT,this.instance.needsUpdate=!0,GameLib.Component.prototype.createInstance.call(this)},GameLib.D3.Texture.prototype.updateInstance=function(e){if(GameLib.Utils.UndefinedOrNull(this.instance))try{return void this.createInstance()}catch(e){console.error(e)}if(GameLib.Utils.UndefinedOrNull(e))throw new Error("need to specify a property");if("image"===e){if(this.typeId===GameLib.D3.Texture.TEXTURE_TYPE_NORMAL){if(GameLib.Utils.UndefinedOrNull(this.image)&&this.instance.image)try{this.createInstance()}catch(e){console.error(e)}if(this.image&&this.image.instance&&this.instance.image!==this.image.instance)try{this.createInstance()}catch(e){console.error(e)}}else if(this.typeId===GameLib.D3.Texture.TEXTURE_TYPE_CANVAS){if(GameLib.Utils.UndefinedOrNull(this.canvas)&&this.instance.canvas)try{this.createInstance()}catch(e){console.error(e)}if(this.canvas&&this.canvas.instance&&this.instance.image!==this.canvas.instance)try{this.createInstance()}catch(e){console.error(e)}}else this.typeId===GameLib.D3.Texture.TEXTURE_TYPE_CUBE&&console.log("todo : cube images change check here");this.publish(GameLib.Event.IMAGE_CHANGED,{texture:this}),this.instance.needsUpdate=!0}"name"===e&&(this.instance.name=this.name),"flipY"===e&&(this.instance.flipY=this.flipY),"encoding"===e&&(this.instance.encoding=this.encoding),"offset"===e&&(this.instance.offset.x=this.offset.x,this.instance.offset.y=this.offset.y),"repeat"===e&&(this.instance.repeat.x=this.repeat.x,this.instance.repeat.y=this.repeat.y),"mapping"===e&&(this.instance.mapping=this.mapping),"format"===e&&(this.instance.format=this.format),"wrapS"===e&&(this.instance.wrapS=this.wrapS),"wrapT"===e&&(this.instance.wrapT=this.wrapT),"animated"===e&&GameLib.Event.Emit(GameLib.Event.TEXTURE_ANIMATED_CHANGE,{texture:this})},GameLib.D3.Texture.prototype.toApiObject=function(){return new GameLib.D3.API.Texture(this.id,this.typeId,this.name,GameLib.Utils.IdOrNull(this.image),this.images.map(function(e){return GameLib.Utils.IdOrNull(e)}),this.wrapS,this.wrapT,this.repeat.toApiObject(),this.data,this.format,this.mapping,this.magFilter,this.minFilter,this.textureType,this.anisotropy,this.offset.toApiObject(),this.generateMipmaps,this.flipY,this.mipmaps,this.unpackAlignment,this.premultiplyAlpha,this.encoding,GameLib.Utils.IdOrNull(this.canvas),this.animated,this.reverseAnimation,this.forward,GameLib.Utils.IdOrNull(this.parentEntity))},GameLib.D3.Texture.FromObject=function(e,t){var i=GameLib.D3.API.Texture.FromObject(t);return new GameLib.D3.Texture(e,i)},GameLib.D3.TriangleEdge=function(e,t){this.triangle=e,this.edge=t},GameLib.D3.Vertex=function(e,t){if(this.implementation=e,e instanceof GameLib.GraphicsRuntime)this.implementation.isNotThreeThrow();else{if(!(e instanceof GameLib.PhysicsRuntime))throw new Error("Unhandled implementation : "+e);this.implementation.isNotCannonThrow()}if(GameLib.Utils.UndefinedOrNull(t)&&(t={}),t instanceof GameLib.D3.Vertex)return t;GameLib.D3.API.Vertex.call(this,t.position,t.boneWeights),this.position=new GameLib.Vector3(this.implementation,this.position,null),e instanceof GameLib.GraphicsRuntime&&(this.boneWeights=this.boneWeights.map(function(e){return new GameLib.D3.BoneWeight(this.implementation,e)}.bind(this)))},GameLib.D3.Vertex.prototype=Object.create(GameLib.D3.API.Vertex.prototype),GameLib.D3.Vertex.prototype.constructor=GameLib.D3.Vertex,GameLib.D3.Vertex.prototype.toApiObject=function(){return new GameLib.D3.API.Vertex(this.position.toApiObject(),this.boneWeights.map(function(e){return e.toApiObject()}))},GameLib.D3.Vertex.FromObject=function(e,t){var i=GameLib.D3.API.Vertex.FromObject(t);return new GameLib.D3.Vertex(e,i)},GameLib.D3.Viewport=function(e,t){if(this.graphics=e,this.graphics.isNotThreeThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),t instanceof GameLib.D3.Viewport)return t;GameLib.D3.API.Viewport.call(this,t.id,t.name,t.width,t.height,t.x,t.y,t.parentEntity),GameLib.Component.call(this,GameLib.Component.COMPONENT_VIEWPORT)},GameLib.D3.Viewport.prototype=Object.create(GameLib.D3.API.Viewport.prototype),GameLib.D3.Viewport.prototype.constructor=GameLib.D3.Viewport,GameLib.D3.Viewport.prototype.createInstance=function(){this.instance=!0,GameLib.Component.prototype.createInstance.call(this)},GameLib.D3.Viewport.prototype.updateInstance=function(){},GameLib.D3.Viewport.prototype.toApiObject=function(){return new GameLib.D3.API.Viewport(this.id,this.name,this.width,this.height,this.x,this.y,GameLib.Utils.IdOrNull(this.parentEntity))},GameLib.D3.Viewport.FromObject=function(e,t){var i=GameLib.D3.API.Viewport.FromObject(t);return new GameLib.D3.Viewport(e,i)},GameLib.DomElement=function(e){if(GameLib.Utils.UndefinedOrNull(e)&&(e={}),e instanceof GameLib.DomElement)return e;GameLib.API.DomElement.call(this,e.id,e.name,e.domElementId,e.parentEntity),this.fullscreen=!1,GameLib.Component.call(this,GameLib.Component.COMPONENT_DOM_ELEMENT)},GameLib.DomElement.prototype=Object.create(GameLib.API.DomElement.prototype),GameLib.DomElement.prototype.constructor=GameLib.DomElement,GameLib.DomElement.prototype.createInstance=function(){this.instance=document.getElementById(this.domElementId),GameLib.Component.prototype.createInstance.call(this)},GameLib.DomElement.prototype.updateInstance=function(){this.instance=document.getElementById(this.domElementId)},GameLib.DomElement.prototype.toApiObject=function(){return new GameLib.API.DomElement(this.id,this.name,this.domElementId,GameLib.Utils.IdOrNull(this.parentEntity))},GameLib.DomElement.prototype.append=function(e){this.instance.appendChild(e)},GameLib.DomElement.prototype.clear=function(){this.instance.innerHTML=""},GameLib.DomElement.prototype.requestFullscreen=function(e){var t=document.documentElement;t.requestFullscreen?t.requestFullscreen():t.msRequestFullscreen?t.msRequestFullscreen():t.mozRequestFullScreen?t.mozRequestFullScreen():t.webkitRequestFullscreen&&t.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT),this.fullscreen=!0},GameLib.DomElement.prototype.exitFullscreen=function(e){document.exitFullscreen?document.exitFullscreen():document.msExitFullscreen?document.msExitFullscreen():document.mozCancelFullScreen?document.mozCancelFullScreen():document.webkitExitFullscreen&&document.webkitExitFullscreen(),this.fullscreen=!1},GameLib.DomElement.FromObject=function(e){var t=GameLib.API.DomElement.FromObject(e);return new GameLib.DomElement(t)};GameLib.Dom=function(e,t){this.document=e,this.window=t},GameLib.EntityManager=function(e){if(GameLib.Utils.UndefinedOrNull(e)&&(e={}),e instanceof GameLib.EntityManager)return e;GameLib.API.EntityManager.call(this,e.id,e.name,e.entities,e.defaultEntity,e.defaultRenderer),this.register=[],GameLib.Event.Subscribe(GameLib.Event.COMPONENT_REGISTER,this.registerComponent.bind(this)),GameLib.Event.Subscribe(GameLib.Event.REMOVE_COMPONENT,this.removeComponent.bind(this)),GameLib.Component.call(this,GameLib.Component.COMPONENT_ENTITY_MANAGER,{entities:[GameLib.Entity],defaultEntity:GameLib.Entity,defaultRenderer:GameLib.D3.Renderer})},GameLib.EntityManager.prototype=Object.create(GameLib.API.EntityManager.prototype),GameLib.EntityManager.prototype.constructor=GameLib.EntityManager,GameLib.EntityManager.prototype.createInstance=function(){this.instance=GameLib.EntityManager.Instance,GameLib.Component.prototype.createInstance.call(this)},GameLib.EntityManager.prototype.registerComponent=function(e){var t=this.register.length;GameLib.Utils.PushUnique(this.register,e.component),t!==this.register.length&&GameLib.Event.Emit(GameLib.Event.REGISTER_UPDATE,{register:this.register})},GameLib.EntityManager.prototype.removeComponent=function(e){var t=this.register.indexOf(e.component);-1!==t&&(this.register.splice(t,1),GameLib.Event.Emit(GameLib.Event.REGISTER_UPDATE,{register:this.register}))},GameLib.EntityManager.prototype.createEntity=function(e){var t=new GameLib.API.Entity(null,e,null,null,this),i=new GameLib.Entity(t);return this.entities.push(i),this.defaultEntity=i,GameLib.Event.Emit(GameLib.Event.NEW_ENTITY,{entity:i}),i},GameLib.EntityManager.prototype.findEntityById=function(e){return this.entities.reduce(function(t,i){return i.id===e&&(t=i),t},null)},GameLib.EntityManager.prototype.findComponentById=function(e){return this.register.reduce(function(t,i){return i.id===e&&(t=i),t},null)},GameLib.EntityManager.prototype.findHelperByObject=function(e){return this.register.reduce(function(t,i){return i instanceof GameLib.D3.Helper&&i.object===e&&(t=i),t},null)},GameLib.EntityManager.prototype.findSceneByObject=function(e){return this.register.reduce(function(t,i){return i instanceof GameLib.D3.Scene&&(-1!==i.meshes.indexOf(e)&&(t=i),-1!==i.lights.indexOf(e)&&(t=i)),t},null)},GameLib.EntityManager.prototype.addEntity=function(e){e.parentEntityManager=this,this.entities.push(e)},GameLib.EntityManager.prototype.queryByName=function(e){return this.entities.reduce(function(t,i){return i.name===e&&(t=i),t},null)},GameLib.EntityManager.prototype.removeEntity=function(e){var t=this.entities.indexOf(e);return-1===t?(console.log("failed to remove entity : ",e),!1):(this.entities.splice(t,1),e.parentEntityManager=null,!0)},GameLib.EntityManager.prototype.findEntities=function(e){return this.entities.reduce(function(t,i){return e.reduce(function(e,t){return i.hasComponent(t)||(e=!1),e},!0)&&t.push(i),t},[])},GameLib.EntityManager.prototype.queryComponents=function(e){return this.register.reduce(function(t,i){return e instanceof Array?e.map(function(e){i instanceof e&&-1===t.indexOf(i)&&t.push(i)}):i instanceof e&&-1===t.indexOf(i)&&t.push(i),t},[])},GameLib.EntityManager.prototype.toApiObject=function(){var e=this.entities.map(function(e){return GameLib.Utils.IdOrNull(e)});return new GameLib.API.EntityManager(this.id,this.name,e,GameLib.Utils.IdOrNull(this.defaultEntity),GameLib.Utils.IdOrNull(this.defaultRenderer))},GameLib.EntityManager.FromObject=function(e){var t=GameLib.API.EntityManager.FromObject(e);return new GameLib.EntityManager(t)},GameLib.Entity=function(e){if(GameLib.Utils.UndefinedOrNull(e)&&(e={}),e instanceof GameLib.Entity)return e;GameLib.API.Entity.call(this,e.id,e.name,e.components,e.parentEntity,e.parentEntityManager),this.componentToCreate=0,GameLib.Component.call(this,GameLib.Component.COMPONENT_ENTITY,{components:[GameLib.Component],activeComponent:GameLib.Component})},GameLib.Entity.prototype=Object.create(GameLib.API.Entity.prototype),GameLib.Entity.prototype.constructor=GameLib.Entity,GameLib.Entity.prototype.createInstance=function(){this.instance=!0,GameLib.Component.prototype.createInstance.call(this)},GameLib.Entity.prototype.addComponent=function(e){if(GameLib.Utils.PushUnique(this.components,e),e instanceof GameLib.D3.Mesh)e.getChildrenComponents().map(function(e){GameLib.Utils.PushUnique(this.components,e),e.parentEntity=this}.bind(this));else{e.buildIdToObject();for(var t in e.idToObject)e.idToObject.hasOwnProperty(t)&&e.idToObject[t]!==e&&e.idToObject[t]instanceof GameLib.Component&&(GameLib.Utils.PushUnique(this.components,e.idToObject[t]),e.idToObject[t].parentEntity=this)}e.parentEntity=this},GameLib.Entity.prototype.getComponents=function(e){return this.components.reduce(function(t,i){return i instanceof e&&t.push(i),t},[])},GameLib.Entity.prototype.getFirstComponent=function(e){var t=this.getComponents(e);return t.length>0?t[0]:null},GameLib.Entity.prototype.hasComponent=function(e){return this.components.reduce(function(t,i){return i instanceof e&&(t=!0),t},!1)},GameLib.Entity.prototype.removeComponent=function(e){GameLib.Utils.UndefinedOrNull(e)&&(e=this.activeComponent);var t=this.components.indexOf(e);return-1!==t?this.components.splice(t,1):console.error("component not found"),e.parentEntity=null,!0},GameLib.Entity.prototype.updateInstance=function(){console.log("entity update instance called")},GameLib.Entity.prototype.toApiObject=function(){var e=this.components.map(function(e){return GameLib.Utils.IdOrNull(e)});return new GameLib.API.Entity(this.id,this.name,e,GameLib.Utils.IdOrNull(this.parentEntity),GameLib.Utils.IdOrNull(this.parentEntityManager))},GameLib.Entity.FromObject=function(e,t){var i=GameLib.API.Entity.FromObject(e),n=new GameLib.Entity(i);return GameLib.Utils.UndefinedOrNull(t)?n:(t.addEntity(n),n)},GameLib.GraphicsRuntime=function(e,t,i){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="Graphics ("+e+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=GameLib.GraphicsRuntime.TYPE_THREE_JS),this.graphicsType=i,this.createInstance()},GameLib.GraphicsRuntime.TYPE_THREE_JS=1,GameLib.GraphicsRuntime.prototype.createInstance=function(){this.graphicsType===GameLib.GraphicsRuntime.TYPE_THREE_JS?this.instance=THREE:this.instance=null},GameLib.GraphicsRuntime.prototype.updateInstance=function(e){"graphicsType"===e&&this.createInstance()},GameLib.GraphicsRuntime.prototype.isNotThreeThrow=function(){if(this.instance!==THREE)throw console.error("Only THREE supported"),new Error("Only THREE supported")},GameLib.GUIRuntime=function(e,t,i){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="GUI ("+e+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=GameLib.GUIRuntime.TYPE_DAT_GUI),this.guiType=i,this.createInstance()},GameLib.GUIRuntime.TYPE_DAT_GUI=1,GameLib.GUIRuntime.prototype.createInstance=function(){this.guiType===GameLib.GUIRuntime.TYPE_DAT_GUI?this.instance=dat.GUI:this.instance=null},GameLib.GUIRuntime.prototype.updateInstance=function(e){"guiType"===e&&this.createInstance()},GameLib.GUIRuntime.prototype.isNotDatGuiThrow=function(){if(this.instance!==dat.GUI)throw console.error("Only dat.gui supported"),new Error("Only dat.gui supported")},GameLib.GUI=function(e,t,i,n,a,s){this.guiRuntime=e,this.guiRuntime.isNotDatGuiThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t=GameLib.Utils.RandomId()),this.id=t,GameLib.Utils.UndefinedOrNull(i)&&(i="GUI ("+t+")"),this.name=i,GameLib.Utils.UndefinedOrNull(n)&&(n=null),this.domElement=n,GameLib.Utils.UndefinedOrNull(a)&&(a=[]),this.objects=a,GameLib.Utils.UndefinedOrNull(s)&&(s=null),this.parentEntity=s,GameLib.Component.call(this,GameLib.Component.COMPONENT_GUI,{domElement:GameLib.DomElement})},GameLib.GUI.prototype=Object.create(GameLib.Component.prototype),GameLib.GUI.prototype.constructor=GameLib.GUI,GameLib.GUI.prototype.createInstance=function(){this.instance=new this.guiRuntime.instance({autoPlace:!1}),GameLib.Component.prototype.createInstance.call(this)},GameLib.GUI.prototype.updateInstance=function(e){console.log("todo: implement gui update instance")},GameLib.GUI.prototype.removeEmtpyFolders=function(){this.instance.removeEmptyFolders()},GameLib.GUI.prototype.removeAllFolders=function(){this.instance.removeAllFolders()},GameLib.GUI.prototype.addFolder=function(e){try{return this.instance.addFolder(e)}catch(t){try{return e+=" duplicate ("+GameLib.Utils.RandomId()+")",this.instance.addFolder(e)}catch(e){return console.log(e.message),null}}},GameLib.Matrix4=function(e,t,i,n){if(this.graphics=e,this.graphics.isNotThreeThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),t instanceof GameLib.Matrix4)return t;GameLib.API.Matrix4.call(this,t.rows[0],t.rows[1],t.rows[2],t.rows[3]),GameLib.Utils.UndefinedOrNull(i)&&(i=null),this.parentObject=i,GameLib.Utils.UndefinedOrNull(n)&&(n=.001),this.grain=n,this.rows=this.rows.map(function(e){if(e instanceof GameLib.API.Vector4)return new GameLib.Vector4(this.graphics,e,this,this.grain);throw console.warn("Attempted conversion of wrong instance"),new Error("Attempted conversion of wrong instance")}.bind(this)),this.forward=new GameLib.Vector4(this.graphics,this.forward,this,this.grain),this.left=new GameLib.Vector4(this.graphics,this.left,this,this.grain),this.up=new GameLib.Vector4(this.graphics,this.up,this,this.grain),this.createInstance()},GameLib.Matrix4.prototype=Object.create(GameLib.API.Matrix4.prototype),GameLib.Matrix4.prototype.constructor=GameLib.Matrix4,GameLib.Matrix4.prototype.createInstance=function(e){this.instance=new THREE.Matrix4,this.instance.set(this.rows[0].x,this.rows[1].x,this.rows[2].x,this.rows[3].x,this.rows[0].y,this.rows[1].y,this.rows[2].y,this.rows[3].y,this.rows[0].z,this.rows[1].z,this.rows[2].z,this.rows[3].z,this.rows[0].w,this.rows[1].w,this.rows[2].w,this.rows[3].w)},GameLib.Matrix4.prototype.updateInstance=function(){this.instance.set(this.rows[0].x,this.rows[1].x,this.rows[2].x,this.rows[3].x,this.rows[0].y,this.rows[1].y,this.rows[2].y,this.rows[3].y,this.rows[0].z,this.rows[1].z,this.rows[2].z,this.rows[3].z,this.rows[0].w,this.rows[1].w,this.rows[2].w,this.rows[3].w),this.parentObject&&this.parentObject.updateInstance&&this.parentObject.updateInstance()},GameLib.Matrix4.prototype.toApiObject=function(){return new GameLib.API.Matrix4(this.rows[0].toApiObject(),this.rows[1].toApiObject(),this.rows[2].toApiObject(),this.rows[3].toApiObject())},GameLib.Matrix4.FromObject=function(e,t,i){var n=new GameLib.API.Matrix4.FromObject(t);return new GameLib.Matrix4(e,i,n)},GameLib.Matrix4.prototype.lookAt=function(e,t,i){var n=new GameLib.API.Vector3(e.x,e.y,e.z),a=n.subtract(t).normalize();0===a.squared()&&(a.z=1);var s=i.cross(a).normalize();0===s.squared()&&(a.x+=1e-4,s=i.cross(a).normalize());var o=a.cross(s);return this.rows[0].x=s.x,this.rows[0].y=s.y,this.rows[0].z=s.z,this.rows[1].x=o.x,this.rows[1].y=o.y,this.rows[1].z=o.z,this.rows[2].x=a.x,this.rows[2].y=a.y,this.rows[2].z=a.z,this.forward.x=a.x,this.forward.y=a.y,this.forward.z=a.z,this.left.x=s.x,this.left.y=s.y,this.left.z=s.z,this.up.x=o.x,this.up.y=o.y,this.up.z=o.z,this.updateInstance(),this},GameLib.Matrix4.prototype.identity=function(){this.rows=[new GameLib.Vector4(this.graphics,new GameLib.API.Vector4(1,0,0,0),this,this.grain),new GameLib.Vector4(this.graphics,new GameLib.API.Vector4(0,1,0,0),this,this.grain),new GameLib.Vector4(this.graphics,new GameLib.API.Vector4(0,0,1,0),this,this.grain),new GameLib.Vector4(this.graphics,new GameLib.API.Vector4(0,0,0,1),this,this.grain)]}, -GameLib.Matrix4.prototype.transpose=function(){return this.temp[0].x=this.rows[0].x,this.temp[0].y=this.rows[1].x,this.temp[0].z=this.rows[2].x,this.temp[0].w=this.rows[3].x,this.temp[1].x=this.rows[0].y,this.temp[1].y=this.rows[1].y,this.temp[1].z=this.rows[2].y,this.temp[1].w=this.rows[3].y,this.temp[2].x=this.rows[0].z,this.temp[2].y=this.rows[1].z,this.temp[2].z=this.rows[2].z,this.temp[2].w=this.rows[3].z,this.temp[3].x=this.rows[0].w,this.temp[3].y=this.rows[1].w,this.temp[3].z=this.rows[2].w,this.temp[3].w=this.rows[3].w,this.rows[0].x=this.temp[0].x,this.rows[0].y=this.temp[0].y,this.rows[0].z=this.temp[0].z,this.rows[0].w=this.temp[0].w,this.rows[1].x=this.temp[1].x,this.rows[1].y=this.temp[1].y,this.rows[1].z=this.temp[1].z,this.rows[1].w=this.temp[1].w,this.rows[2].x=this.temp[2].x,this.rows[2].y=this.temp[2].y,this.rows[2].z=this.temp[2].z,this.rows[2].w=this.temp[2].w,this.rows[3].x=this.temp[3].x,this.rows[3].y=this.temp[3].y,this.rows[3].z=this.temp[3].z,this.rows[3].w=this.temp[3].w,this},GameLib.Mouse=function(e){if(GameLib.Utils.UndefinedOrNull(e)&&(e={}),e instanceof GameLib.Mouse)return e;GameLib.API.Mouse.call(this,e.id,e.name,e.x,e.y,e.parentEntity),GameLib.Component.call(this,GameLib.Component.COMPONENT_MOUSE)},GameLib.Mouse.prototype=Object.create(GameLib.API.Mouse.prototype),GameLib.Mouse.prototype.constructor=GameLib.Mouse,GameLib.Mouse.prototype.createInstance=function(){this.instance=!0,GameLib.Component.prototype.createInstance.call(this)},GameLib.Mouse.prototype.updateInstance=function(e){GameLib.Utils.UndefinedOrNull(e)&&console.warn("unknown property update for Mouse: "+e)},GameLib.Mouse.prototype.toApiObject=function(){return new GameLib.API.Mouse(this.id,this.name,this.x,this.y,this.parentEntity)},GameLib.Mouse.prototype.FromObject=function(e){return new GameLib.Mouse(GameLib.API.Mouse.FromObject(e))},GameLib.PhysicsRuntime=function(e,t,i){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="Physics ("+e+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=GameLib.PhysicsRuntime.TYPE_CANNON_JS),this.physicsType=i,this.createInstance()},GameLib.PhysicsRuntime.TYPE_CANNON_JS=1,GameLib.PhysicsRuntime.prototype.createInstance=function(){this.physicsType===GameLib.PhysicsRuntime.TYPE_CANNON_JS?this.instance=CANNON:this.instance=null},GameLib.PhysicsRuntime.prototype.updateInstance=function(e){"physicsType"===e&&this.createInstance()},GameLib.PhysicsRuntime.prototype.isNotCannonThrow=function(){if(this.instance!==CANNON)throw console.error("Only CANNON supported"),new Error("Only CANNON supported")},GameLib.Quaternion=function(e,t,i,n){if(this.implementation=e,e instanceof GameLib.GraphicsRuntime)this.physics=null,this.graphics=e,this.graphics.isNotThreeThrow();else{if(!(e instanceof GameLib.PhysicsRuntime))throw new Error("Unhandled implementation : "+e);this.graphics=null,this.physics=e,this.physics.isNotCannonThrow()}if(GameLib.Utils.UndefinedOrNull(t)&&(t={}),t instanceof GameLib.Quaternion)return t;GameLib.API.Quaternion.call(this,t.x,t.y,t.z,t.w,t.axis,t.angle),GameLib.Utils.UndefinedOrNull(i)&&(i=null),this.parentObject=i,this.axis=new GameLib.Vector3(this.implementation,this.axis,this,this.grain),Object.defineProperty(this,"angle",GameLib.Utils.LimitToPI("angle",this.angle)),GameLib.Utils.UndefinedOrNull(n)&&(n=.001),this.grain=n,this.createInstance()},GameLib.Quaternion.prototype=Object.create(GameLib.API.Quaternion.prototype),GameLib.Quaternion.prototype.constructor=GameLib.Quaternion,GameLib.Quaternion.prototype.createInstance=function(){this.graphics&&(this.instance=new THREE.Quaternion(this.x,this.y,this.z,this.w)),this.physics&&(this.instance=new CANNON.Quaternion(this.x,this.y,this.z,this.w))},GameLib.Quaternion.prototype.updateInstance=function(e){this.instance.x=this.x,this.instance.y=this.y,this.instance.z=this.z,this.instance.w=this.w,this.parentObject&&this.parentObject.updateInstance&&this.parentObject.updateInstance(e)},GameLib.Quaternion.prototype.toApiObject=function(){return new GameLib.API.Quaternion(this.x,this.y,this.z,this.w,this.axis.toApiObject(),this.angle)},GameLib.Quaternion.prototype.equals=function(e){return this.x===e.x&&this.y===e.y&&this.z===e.z&&this.w===e.w&&this.axis.equals(e.axis)&&this.angle===e.angle},GameLib.Quaternion.prototype.setFrom=function(e){this.x=e.x,this.y=e.y,this.z=e.z,this.w=e.w,this.axis.setFrom(e.axis),this.angle=e.angle},GameLib.Quaternion.prototype.copy=function(e){console.log("todo")},GameLib.SocketsRuntime=function(e,t,i){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="Sockets ("+e+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=GameLib.SocketsRuntime.TYPE_WEB_SOCKET),this.socketsType=i,this.createInstance()},GameLib.SocketsRuntime.TYPE_WEB_SOCKET=1,GameLib.SocketsRuntime.prototype.createInstance=function(){this.socketsType===GameLib.SocketsRuntime.TYPE_WEB_SOCKET?this.instance=WebSocket:this.instance=null},GameLib.SocketsRuntime.prototype.updateInstance=function(e){"socketsType"===e&&this.createInstance()},GameLib.SocketsRuntime.prototype.isNotWebSocketThrow=function(){if(!(this.instance instanceof stats))throw console.error("Only WebSocket supported"),new Error("Only WebSocket supported")},GameLib.StatisticsRuntime=function(e,t,i){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="Statistics ("+e+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=GameLib.StatisticsRuntime.TYPE_STATS),this.statisticsType=i,this.createInstance()},GameLib.StatisticsRuntime.TYPE_STATS=1,GameLib.StatisticsRuntime.prototype.createInstance=function(){this.statisticsType===GameLib.StatisticsRuntime.TYPE_STATS?this.instance=Stats:this.instance=null},GameLib.StatisticsRuntime.prototype.updateInstance=function(e){"statisticsType"===e&&this.createInstance()},GameLib.StatisticsRuntime.prototype.isNotStatsThrow=function(){if(this.instance!==Stats)throw console.error("Only stats supported"),new Error("Only stats supported")},GameLib.System=function(e){if(GameLib.Utils.UndefinedOrNull(e)&&(e={}),e instanceof GameLib.System)return e;GameLib.API.System.call(this,e.id,e.name,e.systemType,e.parentEntity),this.started=!1,this.paused=!1;var t=GameLib.Component.COMPONENT_SYSTEM,i={};e.systemType===GameLib.System.SYSTEM_TYPE_ANIMATION&&(t=GameLib.Component.COMPONENT_SYSTEM_ANIMATION),e.systemType===GameLib.System.SYSTEM_TYPE_CUSTOM&&(t=GameLib.Component.COMPONENT_SYSTEM_CUSTOM_CODE),e.systemType===GameLib.System.SYSTEM_TYPE_GUI&&(t=GameLib.Component.COMPONENT_SYSTEM_GUI),e.systemType===GameLib.System.SYSTEM_TYPE_INPUT&&(t=GameLib.Component.COMPONENT_SYSTEM_INPUT,i.mouseControls=[GameLib.D3.Controls.Mouse],i.keyboardControls=[GameLib.D3.Controls.Keyboard],i.touchControls=[GameLib.D3.Controls.Touch],i.editorControls=[GameLib.D3.Controls.Editor]),e.systemType===GameLib.System.SYSTEM_TYPE_LINKING&&(t=GameLib.Component.COMPONENT_SYSTEM_LINKING),e.systemType===GameLib.System.SYSTEM_TYPE_PHYSICS&&(t=GameLib.Component.COMPONENT_SYSTEM_PHYSICS),e.systemType===GameLib.System.SYSTEM_TYPE_RENDER&&(t=GameLib.Component.COMPONENT_SYSTEM_RENDER),e.systemType===GameLib.System.SYSTEM_TYPE_STORAGE&&(t=GameLib.Component.COMPONENT_SYSTEM_STORAGE),e.systemType===GameLib.System.SYSTEM_TYPE_VISUALIZATION&&(t=GameLib.Component.COMPONENT_SYSTEM_VISUALIZATION),e.systemType===GameLib.System.SYSTEM_TYPE_PARTICLE&&(t=GameLib.Component.COMPONENT_SYSTEM_PARTICLE),e.systemType===GameLib.System.SYSTEM_TYPE_AUDIO&&(t=GameLib.Component.COMPONENT_SYSTEM_AUDIO,i.audioComponents=[GameLib.D3.Audio]),GameLib.Component.call(this,t)},GameLib.System.prototype=Object.create(GameLib.API.System.prototype),GameLib.System.prototype.constructor=GameLib.System,GameLib.System.SYSTEM_TYPE_NONE=0,GameLib.System.SYSTEM_TYPE_RENDER=1,GameLib.System.SYSTEM_TYPE_ANIMATION=2,GameLib.System.SYSTEM_TYPE_INPUT=4,GameLib.System.SYSTEM_TYPE_STORAGE=8,GameLib.System.SYSTEM_TYPE_GUI=16,GameLib.System.SYSTEM_TYPE_PHYSICS=32,GameLib.System.SYSTEM_TYPE_LINKING=64,GameLib.System.SYSTEM_TYPE_CUSTOM=128,GameLib.System.SYSTEM_TYPE_VISUALIZATION=256,GameLib.System.SYSTEM_TYPE_PARTICLE=512,GameLib.System.SYSTEM_TYPE_AUDIO=1024,GameLib.System.SYSTEM_TYPE_ALL=65535,GameLib.System.prototype.createInstance=function(){this.instance=!0,GameLib.Component.prototype.createInstance.call(this)},GameLib.System.prototype.start=function(){this.started=!0,console.log("starting "+this.name)},GameLib.System.prototype.stop=function(){this.started=!1,console.log("stopping "+this.name)},GameLib.System.prototype.toApiObject=function(){return new GameLib.API.System(this.id,this.name,this.systemType,GameLib.Utils.IdOrNull(this.parentEntity))},GameLib.System.prototype.restart=function(){console.log("restarting system : "+this.name),this.stop(),this.start()},GameLib.System.Animation=function(e){GameLib.System.call(this,e),this.animations={},this.latest={},this.textures={},this.textureIds=[],this.animationMeshAddedSubscription=null,this.animationMeshRemovedSubscription=null,this.instanceCreatedSubscription=null,this.removeComponentSubscription=null,this.textureAnimatedSubscription=null,this.animateTextureInstanceSubscription=null},GameLib.System.Animation.prototype=Object.create(GameLib.System.prototype),GameLib.System.Animation.prototype.constructor=GameLib.System.Animation,GameLib.System.Animation.prototype.start=function(){GameLib.System.prototype.start.call(this),this.beforeRenderSubscription=GameLib.Event.Subscribe(GameLib.Event.BEFORE_RENDER,this.beforeRender.bind(this)),GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Animation).map(function(e){e.meshes.map(function(t){this.attachAnimation(e,t)}.bind(this))}.bind(this)),this.animationMeshAddedSubscription=GameLib.Event.Subscribe(GameLib.Event.ANIMATION_MESH_ADDED,function(e){this.attachAnimation(e.animation,e.mesh)}.bind(this)),this.animationMeshRemovedSubscription=GameLib.Event.Subscribe(GameLib.Event.ANIMATION_MESH_REMOVED,function(e){this.detachAnimation(e.mesh)}.bind(this)),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.textureAnimatedSubscription=GameLib.Event.Subscribe(GameLib.Event.TEXTURE_ANIMATED_CHANGE,this.textureAnimatedChange.bind(this)),this.animateTextureInstanceSubscription=GameLib.Event.Subscribe(GameLib.Event.ANIMATE_TEXTURE_INSTANCE,this.animateTextureInstance.bind(this))},GameLib.System.Animation.prototype.instanceCreated=function(e){if(e.component instanceof GameLib.D3.Texture&&e.component.animated){if(e.component.repeat.x>1||e.component.repeat.x<0)return console.warn("cannot animate a texture with repeat.x greater than 1 or less than 0"),void(e.component.animated=!1);if(e.component.repeat.y>1||e.component.repeat.y<0)return console.warn("cannot animate a texture with repeat.y greater than 1 or less than 0"),void(e.component.animated=!1);this.textures[e.component.id]=e.component,this.textureIds=Object.keys(this.textures)}},GameLib.System.Animation.prototype.removeComponent=function(e){e.component instanceof GameLib.D3.Texture&&e.component.animated&&(GameLib.Utils.UndefinedOrNull(this.textures[e.component.id])?console.warn("tried to remove an animated texture, which should have been in the list but isnt: "+e.component.name):(delete this.textures[e.component.id],this.textureIds=Object.keys(this.textures)))},GameLib.System.Animation.prototype.textureAnimatedChange=function(e){if(e.texture.animated){if(e.texture.repeat.x>1||e.texture.repeat.x<0)return console.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)return console.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)}else GameLib.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):(delete this.textures[e.texture.id],this.textureIds=Object.keys(this.textures))},GameLib.System.Animation.prototype.animateTextureInstance=function(e){return e.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){var t=e.delta;for(var i in this.animations)if(this.animations.hasOwnProperty(i)){var n=[];if(this.animations[i].length>0)for(var a=!1,s=0;s=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=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){var t=!1;e.backupQuaternionAngleDescriptor&&(Object.defineProperty(e.quaternion,"angle",e.backupQuaternionAngleDescriptor),delete e.backupQuaternionAngleDescriptor,t=!0),e.backupQuaternionAxisXDescriptor&&(Object.defineProperty(e.quaternion.axis,"x",e.backupQuaternionAxisXDescriptor),delete e.backupQuaternionAxisXDescriptor,t=!0),e.backupQuaternionAxisYDescriptor&&(Object.defineProperty(e.quaternion.axis,"y",e.backupQuaternionAxisYDescriptor),delete e.backupQuaternionAxisYDescriptor,t=!0),e.backupQuaternionAxisZDescriptor&&(Object.defineProperty(e.quaternion.axis,"z",e.backupQuaternionAxisZDescriptor),delete e.backupQuaternionAxisXDescriptor,t=!0),e.backupRotationXDescriptor&&(Object.defineProperty(e.rotation,"x",e.backupRotationXDescriptor),delete e.backupRotationXDescriptor,t=!0),e.backupRotationYDescriptor&&(Object.defineProperty(e.rotation,"y",e.backupRotationYDescriptor),delete e.backupRotationYDescriptor,t=!0),e.backupRotationZDescriptor&&(Object.defineProperty(e.rotation,"z",e.backupRotationZDescriptor),delete e.backupRotationZDescriptor,t=!0),e.backupPositionXDescriptor&&(Object.defineProperty(e.position,"x",e.backupPositionXDescriptor),delete e.backupPositionXDescriptor,t=!0),e.backupPositionYDescriptor&&(Object.defineProperty(e.position,"y",e.backupPositionYDescriptor),delete e.backupPositionYDescriptor,t=!0),e.backupPositionZDescriptor&&(Object.defineProperty(e.position,"z",e.backupPositionZDescriptor),delete e.backupPositionZDescriptor,t=!0),e.backupScaleXDescriptor&&(Object.defineProperty(e.scale,"x",e.backupScaleXDescriptor),delete e.backupScaleXDescriptor,t=!0),e.backupScaleYDescriptor&&(Object.defineProperty(e.scale,"y",e.backupScaleYDescriptor),delete e.backupScaleYDescriptor,t=!0),e.backupScaleZDescriptor&&(Object.defineProperty(e.scale,"z",e.backupScaleZDescriptor),delete e.backupScaleZDescriptor,t=!0),this.latest[e.id]&&(e.rotation.x=this.latest[e.id].rotation.x,e.rotation.y=this.latest[e.id].rotation.y,e.rotation.z=this.latest[e.id].rotation.z,e.position.x=this.latest[e.id].position.x,e.position.y=this.latest[e.id].position.y,e.position.z=this.latest[e.id].position.z,e.scale.x=this.latest[e.id].scale.x,e.scale.y=this.latest[e.id].scale.y,e.scale.z=this.latest[e.id].scale.z,e.quaternion.axis.x=this.latest[e.id].quaternion.axis.x,e.quaternion.axis.y=this.latest[e.id].quaternion.axis.y,e.quaternion.axis.z=this.latest[e.id].quaternion.axis.z,e.quaternion.angle=this.latest[e.id].quaternion.angle,delete this.latest[e.id],t=!0),this.animations[e.id]&&(delete this.animations[e.id],t=!0),t&&e.updateInstance()},GameLib.System.Animation.prototype.attachAnimation=function(e,t){if(this.latest[t.id]={rotation:{x:t.rotation.x,y:t.rotation.y,z:t.rotation.z},position:{x:t.position.x,y:t.position.y,z:t.position.z},scale:{x:t.scale.x,y:t.scale.y,z:t.scale.z},quaternion:{axis:{x:t.quaternion.axis.x,y:t.quaternion.axis.y,z:t.quaternion.axis.z},angle:t.quaternion.angle}},this.animations[t.id]=[],t.backupRotationXDescriptor)throw new Error("already a backed up x descriptor");t.backupQuaternionAngleDescriptor=Object.getOwnPropertyDescriptor(t.quaternion,"angle"),t.backupQuaternionAxisXDescriptor=Object.getOwnPropertyDescriptor(t.quaternion.axis,"x"),t.backupQuaternionAxisYDescriptor=Object.getOwnPropertyDescriptor(t.quaternion.axis,"y"),t.backupQuaternionAxisZDescriptor=Object.getOwnPropertyDescriptor(t.quaternion.axis,"z"),t.backupRotationXDescriptor=Object.getOwnPropertyDescriptor(t.rotation,"x"),t.backupRotationYDescriptor=Object.getOwnPropertyDescriptor(t.rotation,"y"),t.backupRotationZDescriptor=Object.getOwnPropertyDescriptor(t.rotation,"z"),t.backupPositionXDescriptor=Object.getOwnPropertyDescriptor(t.position,"x"),t.backupPositionYDescriptor=Object.getOwnPropertyDescriptor(t.position,"y"),t.backupPositionZDescriptor=Object.getOwnPropertyDescriptor(t.position,"z"),t.backupScaleXDescriptor=Object.getOwnPropertyDescriptor(t.scale,"x"),t.backupScaleYDescriptor=Object.getOwnPropertyDescriptor(t.scale,"y"),t.backupScaleZDescriptor=Object.getOwnPropertyDescriptor(t.scale,"z"),Object.defineProperty(t.quaternion,"angle",{get:this.getProperty(t,"angle","quaternion"),set:this.setProperty(t,e,"angle","quaternion"),configurable:!0}),Object.defineProperty(t.quaternion.axis,"x",{get:this.getSubProperty(t,"x","quaternion","axis"),set:this.setSubProperty(t,e,"x","quaternion","axis"),configurable:!0}),Object.defineProperty(t.quaternion.axis,"y",{get:this.getSubProperty(t,"y","quaternion","axis"),set:this.setSubProperty(t,e,"y","quaternion","axis"),configurable:!0}),Object.defineProperty(t.quaternion.axis,"z",{get:this.getSubProperty(t,"z","quaternion","axis"),set:this.setSubProperty(t,e,"z","quaternion","axis"),configurable:!0}),Object.defineProperty(t.rotation,"x",{get:this.getProperty(t,"x","rotation"),set:this.setProperty(t,e,"x","rotation"),configurable:!0}),Object.defineProperty(t.rotation,"y",{get:this.getProperty(t,"y","rotation"),set:this.setProperty(t,e,"y","rotation"),configurable:!0}),Object.defineProperty(t.rotation,"z",{get:this.getProperty(t,"z","rotation"),set:this.setProperty(t,e,"z","rotation"),configurable:!0}),Object.defineProperty(t.scale,"x",{get:this.getProperty(t,"x","scale"),set:this.setProperty(t,e,"x","scale"),configurable:!0}),Object.defineProperty(t.scale,"y",{get:this.getProperty(t,"y","scale"),set:this.setProperty(t,e,"y","scale"),configurable:!0}),Object.defineProperty(t.scale,"z",{get:this.getProperty(t,"z","scale"),set:this.setProperty(t,e,"z","scale"),configurable:!0}),Object.defineProperty(t.position,"x",{get:this.getProperty(t,"x","position"),set:this.setProperty(t,e,"x","position"),configurable:!0}),Object.defineProperty(t.position,"y",{get:this.getProperty(t,"y","position"),set:this.setProperty(t,e,"y","position"),configurable:!0}),Object.defineProperty(t.position,"z",{get:this.getProperty(t,"z","position"),set:this.setProperty(t,e,"z","position"),configurable:!0})},GameLib.System.Animation.prototype.getSubProperty=function(e,t,i,n){return function(){return this.latest[e.id][i][n][t]}.bind(this)},GameLib.System.Animation.prototype.setSubProperty=function(e,t,i,n,a){return function(s){var o=Number(this.latest[e.id][n][a][i]);this.latest[e.id][n][a][i]=s,this.animations[e.id].push({type:n,axis:i,from:o,to:s,animation:t,mesh:e})}.bind(this)},GameLib.System.Animation.prototype.getProperty=function(e,t,i){return function(){return this.latest[e.id][i][t]}.bind(this)},GameLib.System.Animation.prototype.setProperty=function(e,t,i,n){return function(a){var s=Number(this.latest[e.id][n][i]);this.latest[e.id][n][i]=a,this.animations[e.id].push({type:n,axis:i,from:s,to:a,animation:t,mesh:e})}.bind(this)},GameLib.System.Animation.prototype.stop=function(){GameLib.System.prototype.stop.call(this),this.beforeRenderSubscription.remove(),this.animationMeshAddedSubscription.remove(),this.animationMeshRemovedSubscription.remove(),this.animations={},GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Mesh).map(function(e){for(var t in this.latest)this.latest.hasOwnProperty(t)&&t===e.id&&this.detachAnimation(e)}.bind(this)),this.instanceCreatedSubscription.remove(),this.removeComponentSubscription.remove(),this.textureAnimatedSubscription.remove(),this.animateTextureInstanceSubscription.remove()},GameLib.System.Audio=function(e){GameLib.System.call(this,e),this.instanceCreatedSubscription=null,this.removeComponentSubscription=null,this.playAudioSubscription=null,this.pauseAllAudioSubscription=null,this.muteAudioSubscription=null,this.continueAllAudioSubscription=null,this.stopAudioSubscription=null,this.stopAllAudioSubscription=null,this.mute=!1,this.paused=[],this.audioComponents=[],this.toPlay=[]},GameLib.System.Audio.prototype=Object.create(GameLib.System.prototype),GameLib.System.Audio.prototype.constructor=GameLib.System.Audio,GameLib.System.Audio.prototype.start=function(){GameLib.System.prototype.start.call(this),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.playAudioSubscription=GameLib.Event.Subscribe(GameLib.Event.PLAY_AUDIO,this.playAudio.bind(this)),this.pauseAllAudioSubscription=GameLib.Event.Subscribe(GameLib.Event.PAUSE_ALL_AUDIO,this.pauseAllAudio.bind(this)),this.muteAudioSubscription=GameLib.Event.Subscribe(GameLib.Event.MUTE_AUDIO,this.muteAudio.bind(this)),this.continueAllAudioSubscription=GameLib.Event.Subscribe(GameLib.Event.CONTINUE_ALL_AUDIO,this.continueAllAudio.bind(this)),this.stopAudioSubscription=GameLib.Event.Subscribe(GameLib.Event.STOP_AUDIO,this.stopAudio.bind(this)),this.stopAllAudioSubscription=GameLib.Event.Subscribe(GameLib.Event.STOP_ALL_AUDIO,this.stopAllAudio.bind(this))},GameLib.System.Audio.prototype.instanceCreated=function(e){if(e.component instanceof GameLib.D3.Audio){GameLib.Utils.PushUnique(this.audioComponents,e.component),e.component.instance.onEnded=function(){this.isPlaying=!1,GameLib.Event.Emit(GameLib.Event.AUDIO_ENDED,{audio:e.component})};var t=this.toPlay.indexOf(e.component.name);-1!==t&&(GameLib.Event.Emit(GameLib.Event.PLAY_AUDIO,{name:e.component.name}),this.toPlay.splice(t,1))}},GameLib.System.Audio.prototype.playAudio=function(e){var t=!1;this.audioComponents.map(function(i){i.name===e.name&&(t=!0,i.instance||console.log("audio not ready yet"),i.overplay?(i.instance.isPlaying&&i.instance.stop(),i.instance.offset=0,i.instance.play()):i.instance.isPlaying||i.instance.play())}.bind(this)),t||(console.log("delaying audio play until loaded for: "+e.name),this.toPlay.push(e.name))},GameLib.System.Audio.prototype.pauseAllAudio=function(e){this.paused=[],this.audioComponents.map(function(e){e.instance.isPlaying&&(this.paused.push(e),e.paused=!0,e.updateInstance("paused"))}.bind(this))},GameLib.System.Audio.prototype.continueAllAudio=function(e){this.paused.map(function(e){e.paused=!1,e.updateInstance("paused")}),this.paused=[]},GameLib.System.Audio.prototype.stopAllAudio=function(e){this.audioComponents.map(function(e){e.instance.isPlaying&&e.instance.stop()})},GameLib.System.Audio.prototype.stopAudio=function(e){this.audioComponents.map(function(t){t.name===e.name&&t.instance.isPlaying&&t.instance.stop()})},GameLib.System.Audio.prototype.removeComponent=function(e){},GameLib.System.Audio.prototype.muteAudio=function(){this.mute=!this.mute,this.mute?(this.audioVolumes=this.audioComponents.reduce(function(e,t){return e.push({audio:t,volume:t.volume}),t.volume=0,t.updateInstance("volume"),e},[]),GameLib.Event.Emit(GameLib.Event.AUDIO_MUTED,{audioSystem:this})):(this.audioVolumes.map(function(e){e.audio.volume=e.volume,e.audio.updateInstance("volume")}),GameLib.Event.Emit(GameLib.Event.AUDIO_UNMUTED,{audioSystem:this}))},GameLib.System.Audio.prototype.stop=function(){GameLib.System.prototype.stop.call(this),this.instanceCreatedSubscription.remove(),this.removeComponentSubscription.remove(),this.playAudioSubscription.remove(),this.pauseAllAudioSubscription.remove(),this.muteAudioSubscription.remove(),this.continueAllAudioSubscription.remove(),this.stopAudioSubscription.remove(),this.stopAllAudioSubscription.remove()},GameLib.System.CustomCode=function(e){GameLib.System.call(this,e),this.instanceCreatedSubscription=null,this.removeComponentSubscription=null,this.compileSuccessSubscription=null,this.compileFailedSubscription=null,this.subscriptions={}},GameLib.System.CustomCode.prototype=Object.create(GameLib.System.prototype),GameLib.System.CustomCode.prototype.constructor=GameLib.System.CustomCode,GameLib.System.CustomCode.prototype.start=function(){GameLib.System.prototype.start.call(this),GameLib.EntityManager.Instance.queryComponents(GameLib.D3.CustomCode).map(function(e){this.subscriptions[e.id]=GameLib.Event.Subscribe(e.eventId,e.instance)}.bind(this)),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.compileSuccessSubscription=GameLib.Event.Subscribe(GameLib.Event.COMPILE_SUCCESS,this.compileSuccess.bind(this)),this.compileFailedSubscription=GameLib.Event.Subscribe(GameLib.Event.COMPILE_FAILED,this.compileFailed.bind(this))},GameLib.System.CustomCode.prototype.instanceCreated=function(e){e.component instanceof GameLib.D3.CustomCode&&(this.subscriptions[e.component.id]&&(console.warn("a component already existed"),this.subscriptions[e.component.id].remove()),this.subscriptions[e.component.id]=GameLib.Event.Subscribe(e.component.eventId,e.component.instance))},GameLib.System.CustomCode.prototype.removeComponent=function(e){e.component instanceof GameLib.D3.CustomCode&&this.subscriptions[e.component.id]&&(this.subscriptions[e.component.id].remove(),delete this.subscriptions[e.component.id])},GameLib.System.CustomCode.prototype.compileSuccess=function(e){this.subscriptions[e.component.id]&&this.subscriptions[e.component.id].remove(),this.subscriptions[e.component.id]=GameLib.Event.Subscribe(e.component.eventId,e.component.instance)},GameLib.System.CustomCode.prototype.compileFailed=function(e){this.subscriptions[e.component.id]&&(this.subscriptions[e.component.id].remove(),delete this.subscriptions[e.component.id])},GameLib.System.CustomCode.prototype.stop=function(){GameLib.System.prototype.stop.call(this),this.instanceCreatedSubscription&&(this.instanceCreatedSubscription.remove(),this.instanceCreatedSubscription=null),this.removeComponentSubscription&&(this.removeComponentSubscription.remove(),this.removeComponentSubscription=null),this.compileSuccessSubscription&&(this.compileSuccessSubscription.remove(),this.compileSuccessSubscription=null),this.compileFailedSubscription&&(this.compileFailedSubscription.remove(),this.compileFailedSubscription=null),Object.keys(this.subscriptions).map(function(e){this.subscriptions[e]&&(this.subscriptions[e].remove(),delete this.subscriptions[e])}.bind(this))},GameLib.System.GUI=function(e){GameLib.System.call(this,e),this.guis=[],this.components=[],this.backupComponents=[],this.exclusiveMode=!1,this.buildGUISubscription=null,this.meshDeletedSubscription=null,this.meshSelectedSubscription=null,this.meshDeselectedSubscription=null,this.newEntitySubscription=null,this.meshSelectionObjects={}},GameLib.System.GUI.prototype=Object.create(GameLib.System.prototype),GameLib.System.GUI.prototype.constructor=GameLib.System.GUI,GameLib.System.GUI.prototype.start=function(){GameLib.System.prototype.start.call(this),this.guis=GameLib.EntityManager.Instance.queryComponents(GameLib.GUI),dat.GUI.prototype.removeEmtpyFolders=function(){for(var e in this.__folders)if(this.__folders.hasOwnProperty(e)){var t=this.__folders[e];0===t.__listening.length&&(t.close(),this.__ul.removeChild(t.domElement.parentNode),delete this.__folders[e],this.onResize())}},dat.GUI.prototype.listen=function(e){this.__listening.length;this.__listening.push(e),delete this.closed,Object.defineProperty(this,"closed",{get:function(){return this.params.closed},set:function(e){this.params.closed=e,this.params.closed?(this.dom.addClass(this.__ul,"closed"),cancelAnimationFrame(this.animationId)):(this.dom.removeClass(this.__ul,"closed"),this.updateDisplaysCallback=function(){this.animationId=requestAnimationFrame(this.updateDisplaysCallback.bind(this)),this.__listening.map(function(e){e.updateDisplay()})}.bind(this),this.animationId=requestAnimationFrame(this.updateDisplaysCallback)),this.onResize(),this.__closeButton&&(this.__closeButton.innerHTML=e?"Open Controls":"Close Controls")},configurable:!0})},dat.GUI.prototype.removeAllFolders=function(){for(var e in this.__folders)if(this.__folders.hasOwnProperty(e)){var t=this.__folders[e];cancelAnimationFrame(t.animationId),t.__controllers.map(function(e){e.remove()}),t.__controllers=[],t.__listening=[],t.close(),this.__ul.removeChild(t.domElement.parentNode),delete this.__folders[e],this.onResize()}},this.guis.map(function(e){e.domElement.instance.parentElement.appendChild(e.instance.domElement)}),this.buildGUISubscription=this.subscribe(GameLib.Event.BUILD_GUI,this.buildGUI),this.meshDeletedSubscription=this.subscribe(GameLib.Event.REMOVE_MESH,this.meshDeleted),this.meshSelectedSubscription=this.subscribe(GameLib.Event.MESH_SELECTED,this.meshSelected),this.meshDeselectedSubscription=this.subscribe(GameLib.Event.MESH_DESELECTED,this.meshDeslected),this.newEntitySubscription=this.subscribe(GameLib.Event.NEW_ENTITY,this.newEntity),this.componentRemovedSubscription=this.subscribe(GameLib.Event.REMOVE_COMPONENT,this.removeComponent)},GameLib.System.GUI.prototype.onChange=function(e,t,i){return function(n){i.map(function(i){i[e][t]=n,i instanceof GameLib.D3.Mesh&&"rotation"===e&&(i.useQuaternion=!1),i instanceof GameLib.D3.Mesh&&"quaternion"===e&&(i.useQuaternion=!0),"function"==typeof i[e].updateInstance?i[e].updateInstance(e):"function"==typeof i[e][t].updateInstance?i[e][t].updateInstance(t):i.updateInstance(e)})}},GameLib.System.GUI.prototype.controller=function(e,t,i,n,a,s,o,r,c){GameLib.Utils.UndefinedOrNull(r)&&(r=-1e3),GameLib.Utils.UndefinedOrNull(c)&&(c=1e3),"axleLocal"!==i&&"directionLocal"!==i||(r=-1,c=1,a=1),"offset"!==i&&"repeat"!==i||(r=-1e3,c=1e3,a=1e-5);var h=e.add(t[i],n,r,c,a).name(i+"."+n) -;return h.onChange(this.onChange(i,n,o)),s&&h.listen(),h},GameLib.System.GUI.prototype.buildQuaternionControl=function(e,t,i){var n=t.template,a=!1;1===t.affected.length&&(n=t.affected[0],a=!0);var s=t.affected;this.controller(e,n,i,"x",.1,a,s),this.controller(e,n,i,"y",.1,a,s),this.controller(e,n,i,"z",.1,a,s),this.controller(e,n,i,"w",.1,a,s),this.controller(e,n,i,"angle",.001,a,s,-Math.PI,Math.PI),e.add(n[i].axis,"x",-1,1,.01).name("quaternion.axis.x").onChange(function(e){s.map(function(t){t.useQuaternion=!0,t[i].axis.x=Number(e),t.updateInstance("x")})}),e.add(n[i].axis,"y",-1,1,.01).name("quaternion.axis.y").onChange(function(e){s.map(function(t){t.useQuaternion=!0,t[i].axis.y=Number(e),t.updateInstance("y")})}),e.add(n[i].axis,"z",-1,1,.01).name("quaternion.axis.z").onChange(function(e){s.map(function(t){t.useQuaternion=!0,t[i].axis.z=Number(e),t.updateInstance("z")})})},GameLib.System.GUI.prototype.buildVectorControl=function(e,t,i){var n=t.template,a=!1;1===t.affected.length&&(n=t.affected[0],a=!0);var s=t.affected,o=[];GameLib.Utils.isVector4(n[i])&&o.push(this.controller(e,n,i,"w",.01,a,s)),o.push(this.controller(e,n,i,"x",.01,a,s)),o.push(this.controller(e,n,i,"y",.01,a,s)),(GameLib.Utils.isVector3(n[i])||GameLib.Utils.isVector4(n[i]))&&o.push(this.controller(e,n,i,"z",.01,a,s))},GameLib.System.GUI.prototype.buildParentSelectionControl=function(e,t,i){var n=null;"parentEntity"===i&&(n=GameLib.Entity),"parentMesh"===i&&(n=GameLib.D3.Mesh),"parentWorld"===i&&(n=GameLib.D3.PhysicsWorld),"parentScene"===i&&(n=GameLib.D3.Scene);var a=GameLib.EntityManager.Instance.queryComponents(n).reduce(function(e,t){return e[t.name]=t,e},{none:null}),s=t.template,o=t.affected;e.add(s,i,a).listen().onChange(function(e){var t=null;"null"!==e&&(t=GameLib.EntityManager.Instance.findComponentById(e)),o.map(function(e){e[i]=t,"parentEntity"===i&&GameLib.Event.Emit(GameLib.Event.PARENT_ENTITY_CHANGE,{originalEntity:this.initialValue,newEntity:t,object:e}),"parentWorld"===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){var n=t.template.linkedObjects[i];if(!(n instanceof Array))return void console.error("data mismatch - something not an array");var a=t.template,s=a[i],o=function(n,a){var s="invalid item";n&&n.name&&(s=n.name);var o=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);var r={},c=GameLib.EntityManager.Instance.queryComponents(n).reduce(function(e,t){return e[t.name]=t,r[t.id]=t,e},{none:null}),h={component:null,add:function(){t.affected.map(function(e){-1===e[i].indexOf(h.component)&&(e[i].push(h.component),GameLib.Event.Emit(GameLib.Event.ARRAY_ITEM_ADDED,{component:e,property:i,item:h.component}))}),GameLib.Event.Emit(GameLib.Event.BUILD_GUI)}};e.add(h,"component",c).name("select "+i).onChange(function(e){h.component="null"===e?null:r[e]}).listen(),e.add(h,"add").name("add to "+i)},GameLib.System.GUI.prototype.buildColorControl=function(e,t,i){var n=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.buildSelectControl=function(e,t,i){var n=null;t.template[i]?n=t.template[i].constructor:t.template.linkedObjects[i]&&(n=t.template.linkedObjects[i]);var a=t.template,s=GameLib.EntityManager.Instance.queryComponents(n),o={},r=s.reduce(function(e,t){return e[t.name]=t,o[t.id]=t,e},{none:null});e.add(a,i,r).name(i).listen().onChange(function(e){var n=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){var n=t.template,a=!1;1===t.affected.length&&(n=t.affected[0],a=!0);var s=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,"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}));else if("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}));else if("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.Particle.POSITION_OFFSET_TYPE_FUNCTION}));else if("directionType"===i)o.push(e.add(n,i,{constant:GameLib.D3.Particle.DIRECTION_TYPE_CONSTANT,random:GameLib.D3.Particle.DIRECTION_TYPE_RANDOM,"random normalized":GameLib.D3.Particle.DIRECTION_TYPE_RANDOM_NORMALIZED,function:GameLib.D3.Particle.DIRECTION_TYPE_FUNCTION}));else if("speedType"===i)o.push(e.add(n,i,{constant:GameLib.D3.Particle.SPEED_TYPE_CONSTANT,linear:GameLib.D3.Particle.SPEED_TYPE_LINEAR,exponential:GameLib.D3.Particle.SPEED_TYPE_EXPONENTIAL,logarithmic:GameLib.D3.Particle.SPEED_TYPE_LOGARITHMIC,"1 / log":GameLib.D3.Particle.SPEED_TYPE_ONE_OVER_LOG,exp:GameLib.D3.Particle.SPEED_TYPE_EXP,"1 / exp":GameLib.D3.Particle.SPEED_TYPE_ONE_OVER_EXP}));else if("scaleType"===i)o.push(e.add(n,i,{constant:GameLib.D3.Particle.SCALE_TYPE_CONSTANT,linear:GameLib.D3.Particle.SCALE_TYPE_LINEAR,exponential:GameLib.D3.Particle.SCALE_TYPE_EXPONENTIAL,random:GameLib.D3.Particle.SCALE_TYPE_RANDOM,"random (x = y)":GameLib.D3.Particle.SCALE_TYPE_RANDOM_X_EQUALS_Y,function:GameLib.D3.Particle.SCALE_TYPE_FUNCTION}));else if("rotationType"===i)o.push(e.add(n,i,{constant:GameLib.D3.Particle.ROTATION_TYPE_CONSTANT,random:GameLib.D3.Particle.ROTATION_TYPE_RANDOM,function:GameLib.D3.Particle.ROTATION_TYPE_FUNCTION}));else if("broadphaseType"===i)o.push(e.add(n,i,{naive:GameLib.D3.Broadphase.BROADPHASE_TYPE_NAIVE,grid:GameLib.D3.Image.BROADPHASE_TYPE_GRID,sap:GameLib.D3.Image.BROADPHASE_TYPE_SAP}));else if("solverType"===i)o.push(e.add(n,i,{gs:GameLib.D3.Solver.GS_SOLVER,split:GameLib.D3.Solver.SPLIT_SOLVER}));else if("meshType"===i)o.push(e.add(n,i,{normal:GameLib.D3.Mesh.MESH_TYPE_NORMAL,curve:GameLib.D3.Mesh.MESH_TYPE_CURVE,skinned:GameLib.D3.Mesh.MESH_TYPE_SKINNED,plane:GameLib.D3.Mesh.MESH_TYPE_PLANE,sphere:GameLib.D3.Mesh.MESH_TYPE_SPHERE,box:GameLib.D3.Mesh.MESH_TYPE_BOX,cylinder:GameLib.D3.Mesh.MESH_TYPE_CYLINDER,text:GameLib.D3.Mesh.MESH_TYPE_TEXT}));else if("cameraType"===i)o.push(e.add(n,i,{perspective:GameLib.D3.Camera.CAMERA_TYPE_PERSPECTIVE,orthographic:GameLib.D3.Camera.CAMERA_TYPE_ORTHOGONAL}));else if("materialType"===i)o.push(e.add(n,i,{standard:GameLib.D3.Material.MATERIAL_TYPE_STANDARD,basic:GameLib.D3.Material.MATERIAL_TYPE_BASIC,phong:GameLib.D3.Material.MATERIAL_TYPE_PHONG,points:GameLib.D3.Material.MATERIAL_TYPE_POINTS,toon:GameLib.D3.Material.MATERIAL_TYPE_TOON,"line basic":GameLib.D3.Material.MATERIAL_TYPE_LINE_BASIC}));else if("side"===i)o.push(e.add(n,i,{double:GameLib.D3.Material.TYPE_DOUBLE_SIDE,front:GameLib.D3.Material.TYPE_FRONT_SIDE,back:GameLib.D3.Material.TYPE_BACK_SIDE}));else if("combine"===i)o.push(e.add(n,i,{multiply:GameLib.D3.Material.TYPE_MULTIPLY_OPERATION,mix:GameLib.D3.Material.TYPE_MIX_OPERATION,add:GameLib.D3.Material.TYPE_ADD_OPERATION}));else if("vertexColors"===i)o.push(e.add(n,i,{none:GameLib.D3.Material.TYPE_NO_COLORS,face:GameLib.D3.Material.TYPE_FACE_COLORS,vertex:GameLib.D3.Material.TYPE_VERTEX_COLORS}));else if("blending"===i)o.push(e.add(n,i,{none:GameLib.D3.Material.TYPE_NO_BLENDING,normal:GameLib.D3.Material.TYPE_NORMAL_BLENDING,additive:GameLib.D3.Material.TYPE_ADDITIVE_BLENDING,subtractive:GameLib.D3.Material.TYPE_SUBTRACTIVE_BLENDING,multiply:GameLib.D3.Material.TYPE_MULTIPLY_BLENDING,custom:GameLib.D3.Material.TYPE_CUSTOM_BLENDING}));else if("blendSrc"===i)o.push(e.add(n,i,{zero:GameLib.D3.Material.TYPE_ZERO_FACTOR,one:GameLib.D3.Material.TYPE_ONE_FACTOR,"source color":GameLib.D3.Material.TYPE_SRC_COLOR_FACTOR,"one minus source color":GameLib.D3.Material.TYPE_ONE_MINUS_SRC_COLOR_FACTOR,"source alpha":GameLib.D3.Material.TYPE_SRC_ALPHA_FACTOR,"one minus source alpha":GameLib.D3.Material.TYPE_ONE_MINUS_SRC_ALPHA_FACTOR,"destination alpha":GameLib.D3.Material.TYPE_DST_ALPHA_FACTOR,"one minus destination alpha":GameLib.D3.Material.TYPE_ONE_MINUS_DST_ALPHA_FACTOR,"destination color":GameLib.D3.Material.TYPE_DST_COLOR_FACTOR,"one minus destination color":GameLib.D3.Material.TYPE_ONE_MINUS_DST_COLOR_FACTOR,"source alpha saturate":GameLib.D3.Material.TYPE_SRC_ALPHA_SATURATE_FACTOR}));else if("blendDst"===i)o.push(e.add(n,i,{zero:GameLib.D3.Material.TYPE_ZERO_FACTOR,one:GameLib.D3.Material.TYPE_ONE_FACTOR,"source color":GameLib.D3.Material.TYPE_SRC_COLOR_FACTOR,"one minus source color":GameLib.D3.Material.TYPE_ONE_MINUS_SRC_COLOR_FACTOR,"source alpha":GameLib.D3.Material.TYPE_SRC_ALPHA_FACTOR,"one minus source alpha":GameLib.D3.Material.TYPE_ONE_MINUS_SRC_ALPHA_FACTOR,"destination alpha":GameLib.D3.Material.TYPE_DST_ALPHA_FACTOR,"one minus destination alpha":GameLib.D3.Material.TYPE_ONE_MINUS_DST_ALPHA_FACTOR,"destination color":GameLib.D3.Material.TYPE_DST_COLOR_FACTOR,"one minus destination color":GameLib.D3.Material.TYPE_ONE_MINUS_DST_COLOR_FACTOR,"source alpha saturate":GameLib.D3.Material.TYPE_SRC_ALPHA_SATURATE_FACTOR}));else if("blendEquation"===i)o.push(e.add(n,i,{add:GameLib.D3.Material.TYPE_ADD_EQUATION,subtract:GameLib.D3.Material.TYPE_SUBTRACT_EQUATION,"reverse subtract":GameLib.D3.Material.TYPE_REVERSE_SUBTRACT_EQUATION,min:GameLib.D3.Material.TYPE_MIN_EQUATION,max:GameLib.D3.Material.TYPE_MAX_EQUATION}));else if("depthFunc"===i)o.push(e.add(n,i,{never:GameLib.D3.Material.TYPE_NEVER_DEPTH,always:GameLib.D3.Material.TYPE_ALWAYS_DEPTH,"less depth":GameLib.D3.Material.TYPE_LESS_DEPTH,"less equal depth":GameLib.D3.Material.TYPE_LESS_EQUAL_DEPTH,"equal depth":GameLib.D3.Material.TYPE_EQUAL_DEPTH,"greated equal depth":GameLib.D3.Material.TYPE_GREATER_EQUAL_DEPTH,"greated depth":GameLib.D3.Material.TYPE_GREATER_DEPTH,"not equal depth":GameLib.D3.Material.TYPE_NOT_EQUAL_DEPTH}));else if("wrapS"===i)o.push(e.add(n,i,{repeat:GameLib.D3.Texture.TYPE_REPEAT_WRAPPING,clamp:GameLib.D3.Texture.TYPE_CLAMP_TO_EDGE_WRAPPING,"mirrored repeat":GameLib.D3.Texture.TYPE_MIRRORED_REPEAT_WRAPPING}));else if("wrapT"===i)o.push(e.add(n,i,{repeat:GameLib.D3.Texture.TYPE_REPEAT_WRAPPING,clamp:GameLib.D3.Texture.TYPE_CLAMP_TO_EDGE_WRAPPING,"mirrored repeat":GameLib.D3.Texture.TYPE_MIRRORED_REPEAT_WRAPPING}));else if("format"===i)o.push(e.add(n,i,{alpha:GameLib.D3.Texture.TYPE_ALPHA_FORMAT,rgb:GameLib.D3.Texture.TYPE_RGB_FORMAT,rgba:GameLib.D3.Texture.TYPE_RGBA_FORMAT,luminance:GameLib.D3.Texture.TYPE_LUMINANCE_FORMAT,"luminance alpha":GameLib.D3.Texture.TYPE_LUMINANCE_ALPHA_FORMAT,depth:GameLib.D3.Texture.TYPE_DEPTH_FORMAT}));else if("mapping"===i)o.push(e.add(n,i,{uv:GameLib.D3.Texture.TYPE_UV_MAPPING,"cube reflection":GameLib.D3.Texture.TYPE_CUBE_REFLECTION_MAPPING,"cube refraction":GameLib.D3.Texture.TYPE_CUBE_REFRACTION_MAPPING,"equi rectangular reflection":GameLib.D3.Texture.TYPE_EQUI_RECTANGULAR_REFLECTION_MAPPING,"equi rectangular refraction":GameLib.D3.Texture.TYPE_EQUI_RECTANGULAR_REFRACTION_MAPPING,"spherical reflection":GameLib.D3.Texture.TYPE_SPHERICAL_REFLECTION_MAPPING,"cube uv reflection":GameLib.D3.Texture.TYPE_CUBE_UV_REFLECTION_MAPPING,"cube uv refraction":GameLib.D3.Texture.TYPE_CUBE_UV_REFRACTION_MAPPING}));else if("magFilter"===i)o.push(e.add(n,i,{nearest:GameLib.D3.Texture.TYPE_NEAREST_FILTER,"nearest mipmap nearest":GameLib.D3.Texture.TYPE_NEAREST_MIPMAP_NEAREST_FILTER,"nearest mipmap linear":GameLib.D3.Texture.TYPE_NEAREST_MIPMAP_LINEAR_FILTER,linear:GameLib.D3.Texture.TYPE_LINEAR_FILTER,"linear mipmap nearest":GameLib.D3.Texture.TYPE_LINEAR_MIPMAP_NEAREST_FILTER,"linear mipmap linear":GameLib.D3.Texture.TYPE_LINEAR_MIPMAP_LINEAR_FILTER}));else if("minFilter"===i)o.push(e.add(n,i,{nearest:GameLib.D3.Texture.TYPE_NEAREST_FILTER,"nearest mipmap nearest":GameLib.D3.Texture.TYPE_NEAREST_MIPMAP_NEAREST_FILTER,"nearest mipmap linear":GameLib.D3.Texture.TYPE_NEAREST_MIPMAP_LINEAR_FILTER,linear:GameLib.D3.Texture.TYPE_LINEAR_FILTER,"linear mipmap nearest":GameLib.D3.Texture.TYPE_LINEAR_MIPMAP_NEAREST_FILTER,"linear mipmap linear":GameLib.D3.Texture.TYPE_LINEAR_MIPMAP_LINEAR_FILTER}));else if(s===GameLib.Component.COMPONENT_TEXTURE&&"typeId"===i)o.push(e.add(n,i,{normal:GameLib.D3.Texture.TEXTURE_TYPE_NORMAL,cube:GameLib.D3.Texture.TEXTURE_TYPE_CUBE,canvas:GameLib.D3.Texture.TEXTURE_TYPE_CANVAS}));else if("textureType"===i)o.push(e.add(n,i,{"unsigned byte":GameLib.D3.Texture.TYPE_UNSIGNED_BYTE,byte:GameLib.D3.Texture.TYPE_BYTE,short:GameLib.D3.Texture.TYPE_SHORT,"unsigned short":GameLib.D3.Texture.TYPE_UNSIGNED_SHORT,int:GameLib.D3.Texture.TYPE_INT,"unsigned int":GameLib.D3.Texture.TYPE_UNSIGNED_INT,float:GameLib.D3.Texture.TYPE_FLOAT,"half float":GameLib.D3.Texture.TYPE_HALF_FLOAT}));else if("encoding"===i)o.push(e.add(n,i,{linear:GameLib.D3.Texture.TYPE_LINEAR_ENCODING,srgb:GameLib.D3.Texture.TYPE_SRGB_ENCODING,gamma:GameLib.D3.Texture.TYPE_GAMMA_ENCODING,rgbe:GameLib.D3.Texture.TYPE_RGBE_ENCODING,"log luv":GameLib.D3.Texture.TYPE_LOG_LUV_ENCODING,rgbm7:GameLib.D3.Texture.TYPE_RGBM7_ENCODING,rgbm16:GameLib.D3.Texture.TYPE_RGBM16_ENCODING,rgbd:GameLib.D3.Texture.TYPE_RGBD_ENCODING}));else if("lightType"===i)o.push(e.add(n,i,{ambient:GameLib.D3.Light.LIGHT_TYPE_AMBIENT,directional:GameLib.D3.Light.LIGHT_TYPE_DIRECTIONAL,spot:GameLib.D3.Light.LIGHT_TYPE_SPOT,point:GameLib.D3.Light.LIGHT_TYPE_POINT}));else if("eventId"===i){for(var r={},c=0;c<200;c++)try{r[GameLib.Event.GetEventName(c)]=c}catch(e){}o.push(e.add(n,i,r))}else"functionType"===i?o.push(e.add(n,i,{rotation:GameLib.D3.Animation.ANIMATION_FUNCTION_TYPE_ROTATION,translation:GameLib.D3.Animation.ANIMATION_FUNCTION_TYPE_TRANSLATION,scale:GameLib.D3.Animation.ANIMATION_FUNCTION_TYPE_SCALE})):"opacity"===i||"opacityFactor"===i||"metalness"===i||"roughness"===i||"volume"===i?o.push(e.add(n,i,0,1,.001)):"shininess"===i||"fov"===i?o.push(e.add(n,i,-255,255,1)):"aspect"===i||"wireframeLineWidth"===i||"lineWidth"===i?o.push(e.add(n,i,0,5,.001)):"bumpScale"===i||"normalScale"===i||"displacementScale"===i||"heightMapScale"===i||"intensity"===i?o.push(e.add(n,i,-10,10,.001)):"minX"===i||"minY"===i||"minZ"===i||"maxX"===i||"maxY"===i||"maxZ"===i||"offsetX"===i?o.push(e.add(n,i,-1e3,1e3,.01)):"widthSegments"===i||"radiusSegments"===i||"heightSegments"===i||"particlesPerSecond"===i?o.push(e.add(n,i,1,1e3,1)):"width"===i||"height"===i||"depth"===i||"radius"===i?o.push(e.add(n,i,0,1e3,.1)):"near"===i||"distanceGrain"===i||"envMapIntensity"===i?o.push(e.add(n,i,-10,100,.001)):"bumpScale"===i?o.push(e.add(n,i,0,20,.001)):"heightOffset"===i||"rotationFactor"===i?o.push(e.add(n,i,-100,100,.001)):"friction"===i?o.push(e.add(n,i,0,1e3,.01)):"radiusTop"===i||"radiusBottom"===i?o.push(e.add(n,i,0,100,.1)):"mass"===i?o.push(e.add(n,i,0,1e3,.1)):"sensitivity"===i?o.push(e.add(n,i,1,50,1)):"density"===i?o.push(e.add(n,i,0,1,1e-4)):"thetaLength"===i||"angle"===i?o.push(e.add(n,i,2*-Math.PI,2*Math.PI,.01)):o.push(e.add(n,i,-1e3,1e3,.1))}o.map(function(n){"name"===i?n.onFinishChange(function(e,n){return function(e){t.affected.map(function(t){t[i]=e,t.updateInstance(i)}),n.domElement.getElementsByClassName("title")[0].innerHTML=e}}(0,e)):n.onChange(function(e){"number"==typeof this.initialValue&&(e=Number(e)),t.affected.map(function(t){t[i]=e,t.updateInstance(i)})}),a&&n.listen()})},GameLib.System.GUI.prototype.meshSelected=function(e){this.exclusiveMode?GameLib.Utils.PushUnique(this.backupComponents,e.mesh):GameLib.Utils.PushUnique(this.components,e.mesh)},GameLib.System.GUI.prototype.meshDeslected=function(e){var t=-1;this.exclusiveMode?-1!==(t=this.backupComponents.indexOf(e.mesh))&&this.backupComponents.splice(t,1):-1!==(t=this.components.indexOf(e.mesh))&&this.components.splice(t,1)},GameLib.System.GUI.prototype.buildGUI=function(e){this.guis.map(function(t){if(t.instance.destroy(),t.removeAllFolders(),e&&(e.components?(this.exclusiveMode||(this.exclusiveMode=!0,this.backupComponents=this.components.map(function(e){return e})),this.components=e.components.map(function(e){return e})):this.exclusiveMode?(this.exclusiveMode=!1,this.components=this.backupComponents.map(function(e){return e})):console.log("we are already not in mesh select mode - not doing anything with the backup")),this.exclusiveMode||(this.components=this.components.filter(function(e){return e instanceof GameLib.D3.Mesh})),!(GameLib.Utils.UndefinedOrNull(this.components.length)||this.components.length<1)){this.exclusiveMode||(this.components=this.components.reduce(function(e,t){var i=t.getChildrenComponents();return GameLib.Utils.PushUnique(e,t),i.map(function(t){GameLib.Utils.PushUnique(e,t)}),e}.bind(this),[])),this.components.sort(function(e,t){return e.componentType>t.componentType?1:e.componentType0?console.log("ignoring multiple editor controls"):(this.editorControls.push(e.component),this.registerEditorControls())),e.component instanceof GameLib.D3.Controls.Touch&&(this.touchControls.length>0?console.log("ignoring multiple touch controls"):(this.touchControls.push(e.component),this.registerTouchControls())),e.component instanceof GameLib.D3.Controls.Keyboard&&(this.keyboardControls.length>0?console.log("ignoring multiple keyboard controls"):(this.keyboardControls.push(e.component),this.registerKeyboardControls())),e.component instanceof GameLib.D3.Controls.Mouse&&(this.mouseControls.length>0?console.log("ignoring multiple mouse controls"):(this.mouseControls.push(e.component),this.registerMouseControls()))},GameLib.System.Input.prototype.removeComponent=function(e){if(e.component instanceof GameLib.D3.Controls.Editor){var t=this.editorControls.indexOf(e.component);-1!==t?(console.log("removing editor controls from system"),this.deRegisterEditorControls(),this.editorControls.splice(t,1)):console.log("failed to find the editor controls in the system - probably it was ignored - "+e.component.name)}},GameLib.System.Input.prototype.delayedInstanceEncountered=function(e){e.component instanceof GameLib.D3.Controls.Editor&&(0===this.editorControls.length?(this.editorControls.push(e.component),this.registerEditorControls()):e.component.createInstance())},GameLib.System.Input.prototype.registerTouchControls=function(){if(1===this.touchControls.length){var e=this.touchControls[0];this.touchSensitivity=e.sensitivity,this.touchStart=this.onTouchStart.bind(this),this.touchMove=this.onTouchMove.bind(this),this.touchEnd=this.onTouchEnd.bind(this),this.touchCancel=this.onTouchCancel.bind(this),e.domElement.instance.addEventListener("touchstart",this.touchStart,!1),e.domElement.instance.addEventListener("touchmove",this.touchMove,!1),e.domElement.instance.addEventListener("touchend",this.touchEnd,!1),e.domElement.instance.addEventListener("touchcancel",this.touchCancel,!1)}},GameLib.System.Input.prototype.registerKeyboardControls=function(){if(1===this.keyboardControls.length){var e=this.keyboardControls[0];this.keyboardKeyUp=this.onKeyboardKeyUp.bind(this),this.keyboardKeyDown=this.onKeyboardKeyDown.bind(this),e.domElement.instance.addEventListener("keyup",this.keyboardKeyUp,!1),e.domElement.instance.addEventListener("keydown",this.keyboardKeyDown,!1)}},GameLib.System.Input.prototype.registerMouseControls=function(){if(1===this.mouseControls.length){var e=this.mouseControls[0];this.mouseDown=this.onMouseDown.bind(this),this.mouseMove=this.onMouseMove.bind(this),this.mouseWheel=this.onMouseWheel.bind(this),this.mouseUp=this.onMouseUp.bind(this),e.domElement.instance.addEventListener("mousedown",this.mouseDown,!1),e.domElement.instance.addEventListener("mousemove",this.mouseMove,!1),e.domElement.instance.addEventListener("wheel",this.mouseWheel,!1),e.domElement.instance.addEventListener("mouseup",this.mouseUp,!1)}},GameLib.System.Input.prototype.registerEditorControls=function(){if(1===this.editorControls.length){var e=this.editorControls[0];this.mouseDownEdit=this.onMouseDownEdit.bind(this),this.mouseMoveEdit=this.onMouseMoveEdit.bind(this),e.domElement.instance.addEventListener("mousedown",this.mouseDownEdit,!1),e.domElement.instance.addEventListener("mousemove",this.mouseMoveEdit,!1),this.keyboardControls.length>0||(this.keyDown=this.onKeyDown.bind(this),this.keyUp=this.onKeyUp.bind(this),e.domElement.instance.addEventListener("keydown",this.keyDown,!1),e.domElement.instance.addEventListener("keyup",this.keyUp,!1)),e.createInstance(),this.mouseWheelEdit=this.onMouseWheelEdit.bind(this),this.mouseUpEdit=this.onMouseUpEdit.bind(this),e.domElement.instance.addEventListener("wheel",this.mouseWheelEdit,!1),e.domElement.instance.addEventListener("mouseup",this.mouseUpEdit,!1)}},GameLib.System.Input.prototype.deRegisterEditorControls=function(){if(1===this.editorControls.length){var e=this.editorControls[0];e.domElement.instance.removeEventListener("mousedown",this.mouseDownEdit,!1),e.domElement.instance.removeEventListener("mousemove",this.mouseMoveEdit,!1),this.keyboardControls.length<1&&(e.domElement.instance.removeEventListener("keydown",this.keyDown,!1),e.domElement.instance.removeEventListener("keyup",this.keyUp,!1)),e.instance.dispose(),e.domElement.instance.removeEventListener("wheel",this.mouseWheelEdit,!1),e.domElement.instance.removeEventListener("mouseup",this.mouseUpEdit,!1)}},GameLib.System.Input.prototype.deRegisterTouchControls=function(){if(1===this.touchControls.length){var e=this.touchControls[0];e.domElement.instance.removeEventListener("touchstart",this.touchStart,!1),e.domElement.instance.removeEventListener("touchmove",this.touchMove,!1),e.domElement.instance.removeEventListener("touchend",this.touchEnd,!1),e.domElement.instance.removeEventListener("touchcancel",this.touchCancel,!1)}},GameLib.System.Input.prototype.deRegisterKeyboardControls=function(){if(1===this.keyboardControls.length){var e=this.keyboardControls[0];e.domElement.instance.removeEventListener("keydown",this.keyboardKeyDown,!1),e.domElement.instance.removeEventListener("keyup",this.keyboardKeyUp,!1)}},GameLib.System.Input.prototype.deRegisterMouseControls=function(){if(1===this.mouseControls.length){var e=this.mouseControls[0];e.domElement.instance.removeEventListener("mousedown",this.mouseDown,!1),e.domElement.instance.removeEventListener("mousemove",this.mouseMove,!1),e.domElement.instance.removeEventListener("wheel",this.mouseWheel,!1),e.domElement.instance.removeEventListener("mouseup",this.mouseUp,!1)}},GameLib.System.Input.prototype.onKeyboardKeyUp=function(e){GameLib.Event.Emit(GameLib.Event.KEY_DOWN,{code:e.code})},GameLib.System.Input.prototype.onKeyboardKeyDown=function(e){GameLib.Event.Emit(GameLib.Event.KEY_UP,{code:e.code})},GameLib.System.Input.prototype.onTouchStart=function(e){this.sensitivityCounter=0,this.touches={};for(var t=0;te.changedTouches[m].pageX&&(u+=l),this.touches[t].lastTouchY>e.changedTouches[m].pageY&&(d+=p),this.touches[t].lastTouchY=this.touchSensitivity&&(this.sensitivityCounter=0,GameLib.Event.Emit(GameLib.Event.TOUCH_MOVE,this.touches))},GameLib.System.Input.prototype.onTouchCancel=function(e){this.sensitivityCounter=0;for(var t=0;tt.distance?1:0});var a=n.map(function(e){return e.mesh}),s=a[0];s&&(e.preventDefault(),e.stopImmediatePropagation(),s.selected?this.deSelectMesh(s):this.selectMesh(s),GameLib.Event.Emit(GameLib.Event.BUILD_GUI,null))}}.bind(this))},GameLib.System.Input.prototype.onMouseMoveEdit=function(e){},GameLib.System.Input.prototype.onMouseUpEdit=function(e){this.editorControls.map(function(e){e.camera.position.x=e.camera.instance.position.x,e.camera.position.y=e.camera.instance.position.y,e.camera.position.z=e.camera.instance.position.z,e.camera.quaternion.x=e.camera.instance.quaternion.x,e.camera.quaternion.y=e.camera.instance.quaternion.y,e.camera.quaternion.z=e.camera.instance.quaternion.z,e.camera.quaternion.w=e.camera.instance.quaternion.w,e.camera.lookAt.x=e.instance.center.x,e.camera.lookAt.y=e.instance.center.y,e.camera.lookAt.z=e.instance.center.z,e.camera.lookAt.instance.copy(e.instance.center)})};GameLib.System.Input.prototype.onMouseWheelEdit=function(e){this.editorControls.map(function(e){e.camera.position.x=e.camera.instance.position.x,e.camera.position.y=e.camera.instance.position.y,e.camera.position.z=e.camera.instance.position.z})},GameLib.System.Input.prototype.selectMesh=function(e){!0!==e.selected&&(e.selected=!0,e.createHelper(),GameLib.Event.Emit(GameLib.Event.MESH_SELECTED,{mesh:e}))},GameLib.System.Input.prototype.deSelectMesh=function(e){e.selected=!1,e.removeHelper(),GameLib.Event.Emit(GameLib.Event.MESH_DESELECTED,{mesh:e})},GameLib.System.Linking=function(e){GameLib.System.call(this,e),this.dependencies={},this.resolved=[],this.componentCreatedSubscription=null,this.componentClonedSubscription=null,this.registerDependenciesSubscription=null,this.componentRemoveSubscription=null,this.parentSceneChangeSubscription=null,this.parentWorldChangeSubscription=null,this.parentEntityChangeSubscription=null,this.instanceCreatedSubscription=null,this.instanceClonedSubscription=null,this.removeMeshSubscription=null,this.imageChangedSubscription=null,this.materialTypeChangedSubscription=null,this.arrayItemAddedSubscription=null},GameLib.System.Linking.prototype=Object.create(GameLib.System.prototype),GameLib.System.Linking.prototype.constructor=GameLib.System.Linking,GameLib.System.Linking.prototype.start=function(){GameLib.System.prototype.start.call(this),this.componentCreatedSubscription=this.subscribe(GameLib.Event.COMPONENT_CREATED,this.componentCreated.bind(this)),this.componentClonedSubscription=this.subscribe(GameLib.Event.COMPONENT_CLONED,this.componentCloned.bind(this)),this.registerDependenciesSubscription=this.subscribe(GameLib.Event.REGISTER_DEPENDENCIES,this.registerDependenciesDirect),this.componentRemoveSubscription=this.subscribe(GameLib.Event.REMOVE_COMPONENT,this.removeComponent),this.parentSceneChangeSubscription=this.subscribe(GameLib.Event.PARENT_SCENE_CHANGE,this.onParentSceneChange),this.parentWorldChangeSubscription=this.subscribe(GameLib.Event.PARENT_WORLD_CHANGE,this.onParentWorldChange),this.parentEntityChangeSubscription=this.subscribe(GameLib.Event.PARENT_ENTITY_CHANGE,this.onParentEntityChange),this.instanceCreatedSubscription=this.subscribe(GameLib.Event.INSTANCE_CREATED,this.instanceCreated),this.instanceClonedSubscription=this.subscribe(GameLib.Event.INSTANCE_CLONED,this.instanceCloned),this.removeMeshSubscription=this.subscribe(GameLib.Event.REMOVE_MESH,this.removeMesh),this.imageChangedSubscription=this.subscribe(GameLib.Event.IMAGE_CHANGED,this.imageChanged),this.materialTypeChangedSubscription=this.subscribe(GameLib.Event.MATERIAL_TYPE_CHANGED,this.materialTypeChanged),this.arrayItemAddedSubscription=this.subscribe(GameLib.Event.ARRAY_ITEM_ADDED,this.arrayItemAdded)},GameLib.System.Linking.prototype.link=function(e,t){for(var i in e.linkedObjects)if(e.linkedObjects.hasOwnProperty(i))if(e.linkedObjects[i]instanceof Array){var n=[];e[i]=e[i].map(function(a){return a===t.component.id?(n.push({parent:e,property:i,child:t.component}),t.component):a}),n.map(function(e){GameLib.Event.Emit(GameLib.Event.COMPONENT_LINKED,e)})}else e[i]&&e[i]===t.component.id&&(e[i]=t.component,GameLib.Event.Emit(GameLib.Event.COMPONENT_LINKED,{parent:e,property:i,child:t.component}))},GameLib.System.Linking.prototype.resolveDependencies=function(e){if(!e.loaded)return!1;var t=this.dependencies[e.id];if(GameLib.Utils.UndefinedOrNull(t))return!1;t.map(function(t){if(this.link(t,{component:e}),GameLib.Utils.PushUnique(this.resolved,e),GameLib.Utils.UndefinedOrNull(t.dependencies)||t.dependencies instanceof Array&&0===t.dependencies.length){if(!t.loaded||GameLib.Utils.UndefinedOrNull(t.instance))try{t.performInstanceCreation()}catch(e){console.error(e)}}else{var i=t.dependencies.indexOf(e.id);-1!==i&&t.dependencies.splice(i,1),0===t.dependencies.length&&t.performInstanceCreation()}}.bind(this)),delete this.dependencies[e.id],GameLib.Event.Emit(GameLib.Event.UNRESOLVED_DEPENDENCIES_UPDATE,{dependencies:this.dependencies}),GameLib.Utils.IsEmpty(this.dependencies)&&(GameLib.Event.Emit(GameLib.Event.COMPONENTS_LINKED,{components:this.resolved.map(function(e){return e})}),this.resolved=[])},GameLib.System.Linking.prototype.registerDependencies=function(e){e.dependencies&&e.dependencies.length>0&&(e.dependencies=e.dependencies.reduce(function(t,i){var n=GameLib.EntityManager.Instance.findComponentById(i);return n&&n.loaded?(this.link(e,{component:n}),GameLib.Utils.PushUnique(this.resolved,n)):(GameLib.Utils.UndefinedOrNull(this.dependencies[i])&&(this.dependencies[i]=[]),-1===this.dependencies[i].indexOf(e)&&(this.dependencies[i].push(e),GameLib.Event.Emit(GameLib.Event.UNRESOLVED_DEPENDENCIES_UPDATE,{dependencies:this.dependencies})),t.push(i)),t}.bind(this),[]),0===e.dependencies.length&&e.performInstanceCreation())},GameLib.System.Linking.prototype.componentCreated=function(e){var t=e.component;this.registerDependencies(t),this.resolveDependencies(t)},GameLib.System.Linking.prototype.componentCloned=function(e){if(this.componentCreated(e),e.component instanceof GameLib.D3.Mesh){if(!(e.parent instanceof GameLib.D3.Mesh))throw new Error("no scene parent");e.parent.parentScene&&e.parent.parentScene.addClone(e.component)}},GameLib.System.Linking.prototype.registerDependenciesDirect=function(e){this.registerDependencies(e.component)},GameLib.System.Linking.prototype.removeComponent=function(e){if(!e.component)return void console.error("no component to remove");var t=e.component;t.parentEntity instanceof GameLib.Entity&&t.parentEntity.removeComponent(t),t instanceof GameLib.D3.Mesh&&t.parentScene instanceof GameLib.D3.Scene&&(t.removeHelper(),t.parentScene.removeObject(t)),t instanceof GameLib.D3.Light&&t.parentScene instanceof GameLib.D3.Scene&&t.parentScene.removeObject(t),t instanceof GameLib.Entity&&GameLib.EntityManager.Instance.removeEntity(t)},GameLib.System.Linking.prototype.imageChanged=function(e){GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Material).map(function(t){-1!==t.getTextures().indexOf(e.texture)&&t.updateInstance()})},GameLib.System.Linking.prototype.arrayItemAdded=function(e){e.component instanceof GameLib.D3.PhysicsWorld&&e.item instanceof GameLib.D3.RigidBody&&e.component.addRigidBody(e.item),e.component instanceof GameLib.D3.Mesh&&e.item instanceof GameLib.D3.Material&&e.component.addMaterial(e.item)},GameLib.System.Linking.prototype.instanceCloned=function(e){},GameLib.System.Linking.prototype.instanceCreated=function(e){this.resolveDependencies(e.component),e.component instanceof GameLib.D3.Image&&GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Texture).map(function(t){t.image!==e.component&&-1===t.images.indexOf(e.component)||t.updateInstance("image")}),e.component instanceof GameLib.D3.Scene&&GameLib.EntityManager.Instance.register.map(function(t){t.parentScene===e.component.id&&(t.parentScene=e.component)}),e.component.parentScene&&"string"==typeof e.component.parentScene&&GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Scene).map(function(t){e.component.parentScene===t.id&&(e.component.parentScene=t,t.addObject(e.component))}),e.component.parentEngine&&"string"==typeof e.component.parentEngine&&GameLib.EntityManager.Instance.queryComponents(GameLib.D3.ParticleEngine).map(function(t){e.component.parentEngine===t.id&&(e.component.parentEngine=t)}),e.component instanceof GameLib.D3.Mesh&&(e.preventParentMeshCheck||GameLib.EntityManager.Instance.register.map(function(t){t.parentMesh&&t.parentMesh===e.component.id&&(t.parentMesh=e.component,t instanceof GameLib.D3.Mesh&&t.setParentMesh(e.component))})),e.component.parentMesh&&"string"==typeof e.component.parentMesh&&GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Mesh).map(function(t){e.component.parentMesh===t.id&&(e.component.parentMesh=t,e.component instanceof GameLib.D3.Mesh&&e.component.setParentMesh(t))}),e.component.parentWorld&&"string"==typeof e.component.parentWorld&&GameLib.EntityManager.Instance.queryComponents(GameLib.D3.PhysicsWorld).map(function(t){e.component.parentWorld===t.id&&(e.component.parentWorld=t,"function"==typeof e.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){return i===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){return e.instance}),t.instance.geometry.uvsNeedUpdate=!0,t.instance.material.needsUpdate=!0)})},GameLib.System.Linking.prototype.onParentWorldChange=function(e){e.object instanceof GameLib.D3.RigidBody&&(e.originalWorld instanceof GameLib.D3.PhysicsWorld&&e.originalWorld.removeRigidBody(e.object),e.newWorld instanceof GameLib.D3.PhysicsWorld&&e.newWorld.addRigidBody(e.object))},GameLib.System.Linking.prototype.onParentSceneChange=function(e){if(e.object instanceof GameLib.D3.Mesh||e.object instanceof GameLib.D3.Light){var t=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.originalEntity instanceof GameLib.Entity&&e.originalEntity.removeComponent(e.object),e.newEntity instanceof GameLib.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){var t=e.meshes.reduce(function(e,t){return e.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)});var n=i.reduce(function(e,t){return e.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){GameLib.System.call(this,e),this.engines=[],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.component instanceof GameLib.D3.ParticleEngine&&this.particleEngines.push(e.component)},GameLib.System.Particle.prototype.removeComponent=function(e){if(e.component instanceof GameLib.D3.ParticleEngine){var t=this.particleEngines.indexOf(e.component);-1!==t&&this.particleEngines.splice(t,1)}},GameLib.System.Particle.prototype.beforeRender=function(e){this.totalTime+=e.delta,this.particleEngines.map(function(t){if(!(GameLib.Utils.UndefinedOrNull(t.camera)||GameLib.Utils.UndefinedOrNull(t.templateParticle)||GameLib.Utils.UndefinedOrNull(t.templateParticle.mesh)||GameLib.Utils.UndefinedOrNull(t.templateParticle.mesh.parentScene)||GameLib.Utils.UndefinedOrNull(t.templateParticle.mesh.parentScene.instance))&&(t.elapsed+=e.delta,t.particles=t.particles.reduce(function(i,n){var a=n.userData.speed;return n.userData.speedType===GameLib.D3.Particle.SPEED_TYPE_CONSTANT&&(a=e.delta*n.userData.speed),n.userData.speedType===GameLib.D3.Particle.SPEED_TYPE_LINEAR&&(a=e.delta*n.userData.speed,n.userData.speed+=a),n.userData.speedType===GameLib.D3.Particle.SPEED_TYPE_EXPONENTIAL&&(a=Math.pow(n.userData.speed,2)*e.delta,n.userData.speed+=a),n.userData.speedType===GameLib.D3.Particle.SPEED_TYPE_LOGARITHMIC&&(a=Math.log(n.userData.speed)*e.delta,n.userData.speed+=a),n.userData.speedType===GameLib.D3.Particle.SPEED_TYPE_ONE_OVER_LOG&&(a=1/Math.log(n.userData.speed)*e.delta,n.userData.speed+=a),n.userData.speedType===GameLib.D3.Particle.SPEED_TYPE_EXP&&(a=Math.exp(n.userData.speed)*e.delta,n.userData.speed+=a),n.userData.speedType===GameLib.D3.Particle.SPEED_TYPE_ONE_OVER_EXP&&(a=1/Math.exp(n.userData.speed)*e.delta,n.userData.speed+=a),n.position.x+=n.userData.direction.x*a,n.position.y+=n.userData.direction.y*a,n.position.z+=n.userData.direction.z*a,t.templateParticle.scaleType,GameLib.D3.Particle.SCALE_TYPE_CONSTANT,t.templateParticle.scaleType===GameLib.D3.Particle.SCALE_TYPE_LINEAR&&(n.scale.x+=n.userData.scale.x*e.delta,n.scale.y+=n.userData.scale.x*e.delta,n.scale.z+=n.userData.scale.x*e.delta),n.quaternion.copy(t.camera.instance.quaternion),t.templateParticle.opacityType===GameLib.D3.Particle.OPACITY_TYPE_INCREASE_LINEAR&&(n.material.opacity+=t.templateParticle.opacityFactor),t.templateParticle.opacityType===GameLib.D3.Particle.OPACITY_TYPE_DECREASE_LINEAR&&(n.material.opacity-=t.templateParticle.opacityFactor),n.userData.elapsed+=e.delta,n.userData.elapsed>n.userData.lifeTime||n.material.opacity<0?(n.userData.scene.remove(n),n.geometry.dispose(),n.material.dispose()):i.push(n),i},[]),t.disabledForRemoval&&0===t.particles.length&&GameLib.Event.Emit(GameLib.Event.REMOVE_PARTICLE_ENGINE,{component:t}),t.enabled&&!t.disabledForRemoval)){var i=null;if(t.pulse){if(0===t.particles.length){t.elapsed=0;for(var n=0;nt.frequency&&(t.elapsed=0,i=t.templateParticle.cloneInstance(),t.particles.push(i))}}.bind(this))},GameLib.System.Particle.prototype.stop=function(){GameLib.System.prototype.stop.call(this),this.instanceCreatedSubscription.remove(),this.removeComponentSubscription.remove(),this.beforeRenderSubscription.remove()},GameLib.System.Physics=function(e){GameLib.System.call(this,e),this.worlds=[],this.beforeRenderSubscription=null,this.afterRenderSubscription=null},GameLib.System.Physics.prototype=Object.create(GameLib.System.prototype),GameLib.System.Physics.prototype.constructor=GameLib.System.Physics,GameLib.System.Physics.prototype.start=function(){GameLib.System.prototype.start.call(this),this.worlds=GameLib.EntityManager.Instance.queryComponents(GameLib.D3.PhysicsWorld),this.beforeRenderSubscription=this.subscribe(GameLib.Event.BEFORE_RENDER,this.beforeRender)},GameLib.System.Physics.prototype.beforeRender=function(e){this.worlds.map(function(t){t.instance&&(t.instance.step(e.delta),t.rigidBodies.map(function(e){e.position.x=e.instance.position.x,e.position.y=e.instance.position.y,e.position.z=e.instance.position.z,e.quaternion.x=e.instance.quaternion.x,e.quaternion.y=e.instance.quaternion.y,e.quaternion.z=e.instance.quaternion.z,e.quaternion.w=e.instance.quaternion.w,e.parentMesh.position.x=e.instance.position.x,e.parentMesh.position.y=e.instance.position.y,e.parentMesh.position.z=e.instance.position.z,e.parentMesh.quaternion.x=e.instance.quaternion.x,e.parentMesh.quaternion.y=e.instance.quaternion.y,e.parentMesh.quaternion.z=e.instance.quaternion.z,e.parentMesh.quaternion.w=e.instance.quaternion.w,e.instance.getVelocityAtWorldPoint(new CANNON.Vec3(0,0,0),e.velocity.instance),e.velocity.x=e.velocity.instance.x,e.velocity.y=e.velocity.instance.y,e.velocity.z=e.velocity.instance.z,e.parentMesh.updateRotationFromAxisAngle=!1,e.parentMesh.updateInstance(),e.parentMesh.updateRotationFromAxisAngle=!0}))}.bind(this))},GameLib.System.Physics.prototype.stop=function(){GameLib.System.prototype.stop.call(this),this.worlds=[],this.rigidBodies=[],this.wheels=[],this.vehicles=[],this.beforeRenderSubscription&&this.beforeRenderSubscription.remove(),this.afterRenderSubscription&&this.afterRenderSubscription.remove()},GameLib.System.Render=function(e){GameLib.System.call(this,e),this.renderSubscription=null},GameLib.System.Render.prototype=Object.create(GameLib.System.prototype),GameLib.System.Render.prototype.constructor=GameLib.System.Render,GameLib.System.Render.prototype.start=function(){GameLib.System.prototype.start.call(this),this.renderers=GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Renderer),this.statistics=GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Stats),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.renderSubscription=this.subscribe(GameLib.Event.RENDER,this.render)},GameLib.System.Render.prototype.instanceCreated=function(e){e.component instanceof GameLib.D3.Renderer&&(console.log("new renderer"),this.renderers.push(e.component)),e.component instanceof GameLib.D3.Stats&&(console.log("new stats"),this.statistics.push(e.component))},GameLib.System.Render.prototype.removeComponent=function(e){if(e.component instanceof GameLib.D3.Renderer){var t=this.renderers.indexOf(e.component);-1!==t?(console.log("removing renderer from system"),this.renderers.splice(t,1)):console.log("failed to find the renderer in the system : "+e.component.name)}},GameLib.System.Render.prototype.render=function(e){if(this.statistics&&this.statistics.map(function(e){e.start()}),GameLib.Event.Emit(GameLib.Event.BEFORE_RENDER,e),this.renderers.length<1);else if(1===this.renderers.length)this.renderers[0].render(e.delta);else{var t=this.renderers.reduce(function(e,t){return t.scenes.map(function(t){e.push(t)}),e},[]),i=GameLib.EntityManager.Instance.defaultRenderer;GameLib.Utils.UndefinedOrNull(i)&&(i=this.renderers[0]),i.render(e.delta,t)}GameLib.Event.Emit(GameLib.Event.AFTER_RENDER,e),this.statistics&&this.statistics.map(function(e){e.end()})},GameLib.System.Render.prototype.stop=function(){GameLib.System.prototype.stop.call(this),this.instanceCreatedSubscription.remove(),this.removeComponentSubscription.remove(),this.renderSubscription.remove(),this.renderers.map(function(e){e.statistics&&(e.statistics.resize(),e.domElement.instance.parentElement.removeChild(e.statistics.instance.dom))}),this.renderers=[]},GameLib.System.Storage=function(e,t,i,n,a,s,o,r,c){GameLib.System.call(this,e),GameLib.Utils.UndefinedOrNull(t)&&(t=null),this.token=t,GameLib.Utils.UndefinedOrNull(i)&&(console.warn("Need an API Upload URL for a storage system"),i=""),this.apiUploadUrl=i,GameLib.Utils.UndefinedOrNull(n)&&(n=null),this.onImageLoaded=n,GameLib.Utils.UndefinedOrNull(a)&&(a=null),this.onImageProgress=a,GameLib.Utils.UndefinedOrNull(s)&&(s=null),this.onImageError=s,GameLib.Utils.UndefinedOrNull(o)&&(o=null),this.onComponentLoaded=o,GameLib.Utils.UndefinedOrNull(r)&&(r=null),this.onComponentProgress=r,GameLib.Utils.UndefinedOrNull(c)&&(c=null),this.onComponentError=c,this.loaded=[],this.loading=[],this.failed=[],this.otherDependencies=[],this.loginSubscription=null,this.saveSubscription=null,this.loadSubscription=null,this.loadImageSubscription=null,this.blenderDataSubscription=null,this.imageUploadCompleteSubscription=null,this.fetchComponentTypesSubscription=null,this.fetchComponentsSubscription=null},GameLib.System.Storage.prototype=Object.create(GameLib.System.prototype),GameLib.System.Storage.prototype.constructor=GameLib.System.Storage,GameLib.System.Storage.prototype.start=function(){GameLib.System.prototype.start.call(this),this.loginSubscription=this.subscribe(GameLib.Event.LOGGED_IN,function(e){this.token=e.token}),this.saveSubscription=this.subscribe(GameLib.Event.SAVE_COMPONENT,this.save),this.loadSubscription=this.subscribe(GameLib.Event.LOAD_COMPONENT,this.load),this.deleteSubscription=this.subscribe(GameLib.Event.DELETE_COMPONENT,this.delete),this.loadImageSubscription=this.subscribe(GameLib.Event.LOAD_IMAGE,this.loadImage),this.loadFontSubscription=this.subscribe(GameLib.Event.LOAD_FONT,this.loadFont),this.blenderDataSubscription=this.subscribe(GameLib.Event.BLENDER_DATA_RECEIVED,this.processBlenderData),this.imageUploadCompleteSubscription=this.subscribe(GameLib.Event.IMAGE_UPLOAD_COMPLETE,this.imageUploadComplete),this.fetchComponentTypesSubscription=this.subscribe(GameLib.Event.FETCH_COMPONENT_TYPES,this.fetchComponentTypes),this.fetchComponentsSubscription=this.subscribe(GameLib.Event.FETCH_COMPONENTS,this.fetchComponents)},GameLib.System.Storage.prototype.delete=function(e){this.publish(GameLib.Event.GET_API_URL,null,function(t){if("undefined"==typeof XMLHttpRequest)return void console.log("Implement server side delete here");e.ids.map(function(e){var i=new XMLHttpRequest;i.open("POST",t.apiUrl+"/component/delete/"+e),i.setRequestHeader("Accept","application/json"),i.setRequestHeader("Content-Type","application/json"),i.setRequestHeader("x-authorization",t.passwoid),i.onreadystatechange=function(){if(4===this.readyState){try{var e=JSON.parse(this.responseText)}catch(e){GameLib.Event.Emit(GameLib.Event.DELETE_COMPONENT_ERROR,{message:this.responseText})}"success"===e.result?GameLib.Event.Emit(GameLib.Event.COMPONENT_DELETED,{message:e.message||"Successfully saved the component"}):GameLib.Event.Emit(GameLib.Event.DELETE_COMPONENT_ERROR,{message:e.message||"The server responded but failed to save the component"})}},i.send(JSON.stringify({session:this.token}))}.bind(this))}.bind(this),function(e){throw console.error(e.message),new Error(e.message)})},GameLib.System.Storage.prototype.save=function(e){var t=GameLib.Event.GET_API_URL;e.remote&&(t=GameLib.Event.GET_REMOTE_API_URL),this.publish(t,null,function(t){if("undefined"==typeof XMLHttpRequest)return void console.log("Implement server side save here");var i=new XMLHttpRequest;i.open("POST",t.apiUrl+"/component/create"),i.setRequestHeader("Accept","application/json"),i.setRequestHeader("Content-Type","application/json"),i.setRequestHeader("x-authorization",t.passwoid),i.onreadystatechange=function(){if(4===this.readyState){try{var t=JSON.parse(this.responseText)}catch(t){GameLib.Event.Emit(GameLib.Event.SAVE_COMPONENT_ERROR,{message:this.responseText,component:e.apiObject})}"success"===t.result?GameLib.Event.Emit(GameLib.Event.COMPONENT_SAVED,{message:t.message||"Successfully saved the component",component:e.apiObject}):GameLib.Event.Emit(GameLib.Event.SAVE_COMPONENT_ERROR,{message:t.message||"The server responded but failed to save the component",component:e.apiObject})}},i.send(JSON.stringify({component:e.apiObject,session:this.token}))})},GameLib.System.Storage.prototype.createRuntimeObject=function(e,t){try{var i=JSON.parse(e)}catch(e){return this.onComponentError&&this.onComponentError(e),t&&t({message:e.message||"JSON parse error"}),GameLib.Event.Emit(GameLib.Event.LOAD_COMPONENT_ERROR,{error:e}),null}if("success"!==i.result)return this.onComponentError&&this.onComponentError(id,i),t&&t({message:i.message||"Server load error"}),GameLib.Event.Emit(GameLib.Event.LOAD_COMPONENT_ERROR,{error:i}),null;var n=GameLib.Component.Construct(i.component[0]);return n||t&&t({result:"failure",message:"Could not create a runtime component: "+i.component[0].name}),n},GameLib.System.Storage.prototype.loadComponent=function(e,t,i,n,a){t.map(function(e){GameLib.Utils.PushUnique(this.loading,e);var t=GameLib.EntityManager.Instance.findComponentById(e);t&&t.remove()}.bind(this)),t.map(function(t){var s=new XMLHttpRequest;s.onload=function(s){return function(){var o=s.createRuntimeObject.bind(s)(this.responseText);if(!o)return void s.failed.push(t);if(o.parentEntity&&"string"==typeof o.parentEntity&&GameLib.EntityManager.Instance.queryComponents(GameLib.Entity).map(function(e){o.parentEntity===e.id&&(o.parentEntity=e)}),GameLib.Event.Emit(GameLib.Event.COMPONENT_CREATED,{component:o}),s.loaded.push(o.id),i){var r=o.getDependencies();s.otherDependencies.map(function(e){var t=r.indexOf(e);-1!==t&&r.splice(t,1)}),r.map(function(e){GameLib.Utils.PushUnique(this.otherDependencies,e)}.bind(s)),r=r.reduce(function(e,t){return-1===s.failed.indexOf(t)?e.push(t):console.log("ignoring failed component : "+t),e}.bind(s),[]),r=r.reduce(function(e,t){return GameLib.EntityManager.Instance.findComponentById(t)||e.push(t),e},[]),r=r.reduce(function(e,t){return-1===s.loaded.indexOf(t)&&e.push(t),e},[]),r.map(function(e){GameLib.Utils.PushUnique(s.loading,e)}),s.loadComponent(e,r,i,n,a),GameLib.Event.Emit(GameLib.Event.LOAD_PROGRESS,{loaded:s.loaded.length,toProcess:r.length})}s.onComponentLoaded&&s.onComponentLoaded(o)}}(this),s.onprogress=function(e){return function(t){var i=0;0!==t.total&&(i=Math.round(100*Number(t.loaded/t.total))),this.onComponentProgress&&this.onComponentProgress(e,i)}.bind(this)}(t),s.onerror=function(e){return function(t){console.warn("component load failed for component ID "+e),this.onComponentError&&this.onComponentError(e,t),a&&a({message:"xhr request failure"})}.bind(this)}(t),s.open("GET",e+"/component/load/"+t),s.send()}.bind(this))},GameLib.System.Storage.prototype.load=function(e,t,i){this.publish(GameLib.Event.GET_API_URL,null,function(n){if("undefined"==typeof XMLHttpRequest)return void console.log("Implement server side load here");e.ids&&e.ids.length>0?this.loadComponent(n.apiUrl,e.ids,e.includeDependencies,t,i):console.log("No components selected")}.bind(this),function(e){throw console.error(e.message),new Error(e.message)})},GameLib.System.Storage.prototype.xhrLoad=function(e,t,i){if("undefined"==typeof XMLHttpRequest)return void console.log("Implement server side load here");console.log("Loading...","success");var n=new XMLHttpRequest;n.open("GET",e),n.setRequestHeader("Accept","application/json"),n.setRequestHeader("Content-Type","application/json"),n.onreadystatechange=function(){if(4===n.readyState){if(!n.responseText)return console.log("Invalid response from server"),void i({message:"Invalid response from server"});try{var e=JSON.parse(n.responseText)}catch(e){e.message="Could not parse JSON",i(e)}if("success"!==e.result)return i({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){var t=GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Image);e.images.map(function(e){var i=null;e?GameLib.Component.Construct(e):(i=t.reduce(function(t,i){return e.id===i.id&&(t=i),t},null),i.updateInstance("path"))}.bind(this))},GameLib.System.Storage.prototype.processBlenderData=function(e){console.log("loading blender data"),e.images.map(function(e){var t=GameLib.Component.Construct(e);GameLib.Event.Emit(GameLib.Event.COMPONENT_CREATED,{component:t})}.bind(this)),e.textures.map(function(e){var t=GameLib.Component.Construct(e);GameLib.Event.Emit(GameLib.Event.COMPONENT_CREATED,{component:t})}.bind(this)),e.materials.map(function(e){var t=GameLib.Component.Construct(e);GameLib.Event.Emit(GameLib.Event.COMPONENT_CREATED,{component:t})}.bind(this)),e.meshes.map(function(e){var t=GameLib.Component.Construct(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){var a=n.apiUrl+"/fonts/"+e.font.url+"?ts="+Date.now();(new THREE.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){console.log("loading image : "+e.image.name),this.publish(GameLib.Event.GET_API_URL,null,function(t){var i=this.onImageLoaded,n=this.onImageProgress,a=this.onImageError,s=e.image,o=t.apiUrl+s.path+s.fileName+s.extension+"?ts="+Date.now(),r=new XMLHttpRequest;r.withCredentials=!0,r.open("OPTIONS",o),r.setRequestHeader("Content-Type","application/json"),r.onload=function(){var t=new XMLHttpRequest;t.withCredentials=!0,t.open("GET",o),t.setRequestHeader("Content-Type",s.contentType),t.responseType="blob",t.onload=function(){var t=!1,n="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAIAAAAlC+aJAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH4QoWEQMQBXD4hQAAABl0RVh0Q29tbWVudABDcmVhdGVkIHdpdGggR0lNUFeBDhcAAABRSURBVGje7c8xDQAwCAAwmA3koA/PU8FB0jpo1nRc9uI4AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBgX0fjEoBa8xN1z4AAAAASUVORK5CYII=";try{"application/json"!==this.response.type&&(n=window.URL.createObjectURL(this.response),t=!0)}catch(e){}var a=document.createElement("img");a.onload=function(){t&&window.URL.revokeObjectURL(n),s.instance=a,s.createInstance(),i&&i(s,e.createTexture)},a.src=n},t.onprogress=function(e){var t=0;0!==e.total&&(t=Math.round(100*Number(e.loaded/e.total))),n&&n(s,t),s.size=e.total},t.onerror=function(e){console.warn("image load failed for image "+s.name),a&&a(s,e)},t.send()},r.onerror=function(e){console.warn("image pre-flight request failed for image "+s.name),a&&a(s,e)},r.send()}.bind(this),function(e){throw console.error(e.message),new Error(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,t,i){GameLib.System.call(this,e),GameLib.Utils.UndefinedOrNull(t)&&GameLib.Event.Emit(GameLib.Event.GET_GRAPHICS_RUNTIME,null,function(e){t=e}.bind(this),function(){t=null}.bind(this)),this.graphics=t,GameLib.Utils.UndefinedOrNull(i)&&GameLib.Event.Emit(GameLib.Event.GET_PHYSICS_RUNTIME,null,function(e){i=e}.bind(this),function(){i=null}.bind(this)),this.physics=i,this.visualizationSubscription=null,this.stopVisualizationSubscription=null},GameLib.System.Visualization.prototype=Object.create(GameLib.System.prototype),GameLib.System.Visualization.prototype.constructor=GameLib.System.Visualization,GameLib.System.Visualization.prototype.start=function(){GameLib.System.prototype.start.call(this),this.visualizationSubscription=this.subscribe(GameLib.Event.VISUALIZE,this.visualize),this.stopVisualizationSubscription=this.subscribe(GameLib.Event.STOP_VISUALIZE,this.stopVisualize)},GameLib.System.Visualization.prototype.visualize=function(e){var t=e.shape;t.parentMesh;t.setFromMesh();var i=new GameLib.D3.API.Mesh;if(i.name="Visualization Mesh for Shape "+t.name,t instanceof GameLib.D3.Shape.HeightMap)for(var n=new CANNON.Vec3,a=new CANNON.Vec3,s=new CANNON.Vec3,o=0;oMath.PI;)e-=2*Math.PI;for(;e<-Math.PI;)e+=2*Math.PI;i=e}}},GameLib.Utils.IdArrayOrEmptyArray=function(e){return GameLib.Utils.UndefinedOrNull(e)?[]:e.map(function(e){if(GameLib.Utils.UndefinedOrNull(e.id))throw new Error("No ID found while trying to store IDs to array");return e.id})},GameLib.Utils.Link=function(e,t,i,n){GameLib.Utils.UndefinedOrNull(i[e])||(t.hasOwnProperty(n)||console.warn("Linking failed for object:"+i.name),i[e]=t[n])},GameLib.Utils.RandomId=function(e){return GameLib.Utils.UndefinedOrNull(e)&&(e=10),Math.random().toString(36).substr(2,e)},GameLib.Utils.InvertWindingOrder=function(e){for(var t=0;t0;){var a=i.pop();if(a.triangle.v0index===a.edge.x&&a.triangle.v1index===a.edge.y||a.triangle.v1index===a.edge.x&&a.triangle.v2index===a.edge.y||a.triangle.v2index===a.edge.x&&a.triangle.v0index===a.edge.y){var s=a.triangle.v1index;a.triangle.v1index=a.triangle.v2index,a.triangle.v2index=s;var o=a.triangle.uvs[0][1];a.triangle.uvs[0][1]=a.triangle.uvs[0][2],a.triangle.uvs[0][2]=o}n.push(a);for(var r=[new GameLib.API.Vector2(a.triangle.v0index,a.triangle.v1index),new GameLib.API.Vector2(a.triangle.v1index,a.triangle.v2index),new GameLib.API.Vector2(a.triangle.v2index,a.triangle.v0index)],c=0;c9||console.log("The vertices are not in the right length : "+e.length);for(var i=[],n=new GameLib.API.Quaternion.Points,a=0;ae&&t.splice(0,1);var n=0;for(var a in t)n+=t[a];var s=e;return t.lengthe.length&&(i=t,t=e,e=i),e.filter(function(e){return t.indexOf(e)>-1}).filter(function(e,t,i){return i.indexOf(e)===t})},GameLib.Utils.Difference=function(e,t){var i;return t.length>e.length&&(i=t,t=e,e=i),e.filter(function(e){return-1===t.indexOf(e)}).filter(function(e,t,i){return i.indexOf(e)===t})},GameLib.Utils.PushUnique=function(e,t){-1===e.indexOf(t)&&e.push(t)},GameLib.Utils.IsEmpty=function(e){return 0===Object.keys(e).length&&e.constructor===Object},GameLib.Utils.isString=function(e){return"string"==typeof e},GameLib.Utils.isBoolean=function(e){return!0===e||!1===e},GameLib.Utils.isColor=function(e){return e instanceof GameLib.Color},GameLib.Utils.isNumber=function(e){return"number"==typeof e},GameLib.Utils.isVector2=function(e){return e instanceof GameLib.API.Vector2||e instanceof GameLib.Vector2},GameLib.Utils.isVector3=function(e){return e instanceof GameLib.API.Vector3||e instanceof GameLib.Vector3},GameLib.Utils.isVector4=function(e){return e instanceof GameLib.API.Vector4||e instanceof GameLib.Vector4||e instanceof GameLib.API.Quaternion||e instanceof GameLib.Quaternion},GameLib.Utils.LowerUnderscore=function(e){return e.toLowerCase().replace(/\s+/,"_")},GameLib.Utils.UpperCaseWordsSpaces=function(e){return e.replace(/[-_]/g," ").split(" ").reduce(function(e,t){return(e+=t[0].toUpperCase()+t.substr(1))+" "},"").trim()},GameLib.Utils.UpperCaseUnderscore=function(e){var t="";return e.map(function(e){e===e.toUpperCase()?t+="_"+e:t+=e.toUpperCase()}),t},GameLib.API.Component=function(e,t){this.componentType=e,GameLib.Utils.UndefinedOrNull(t)&&(t=null),this.parentEntity=t},GameLib.API.Component.prototype=Object.create(GameLib.Event.prototype),GameLib.API.Component.prototype.constructor=GameLib.API.Component,GameLib.Component=function(e,t){GameLib.Utils.UndefinedOrNull(e)&&(e={}),this.linkedObjects=e,this.linkedObjects.parentEntity=GameLib.Entity,this.idToObject={},this.selected=!1,this.building=!1,this.loaded=!1,this.linked=!1,this.cloneNumber=0,this.isClone=!1,GameLib.Utils.UndefinedOrNull(t)&&(t=!1),this.delayed=t,this.dependencies=this.getDependencies(),GameLib.Event.Emit(GameLib.Event.COMPONENT_REGISTER,{component:this}),0===this.dependencies.length?this.performInstanceCreation():GameLib.Event.Emit(GameLib.Event.REGISTER_DEPENDENCIES,{component:this})},GameLib.Component.prototype=Object.create(GameLib.API.Component.prototype),GameLib.Component.prototype.constructor=GameLib.Component,GameLib.Component.prototype.performInstanceCreation=function(){var e=!0;if(GameLib.Utils.UndefinedOrNull(this.dependencies)&&(e=!1),this.dependencies&&this.dependencies instanceof Array&&0===this.dependencies.length&&(e=!1),e)throw new Error("performInstanceCreation called while this object still has dependencies");if(delete this.dependencies,this.buildIdToObject(),this.linked)if(this.delayed)GameLib.Event.Emit(GameLib.Event.DELAYED_INSTANCE_ENCOUNTERED,{component:this});else try{this.createInstance()}catch(e){console.error(e)}},GameLib.Component.prototype.createInstance=function(){this.delayed=!1,this.instance&&(this.loaded=!0,GameLib.Event.Emit(GameLib.Event.INSTANCE_CREATED,{component:this})),this instanceof GameLib.Entity&&GameLib.Event.Emit(GameLib.Event.ENTITY_LOADED,{entity:this})},GameLib.Component.prototype.getDependencies=function(){var e=[];for(var t in this.linkedObjects)this.linkedObjects.hasOwnProperty(t)&&0!==t.indexOf("parent")&&this.hasOwnProperty(t)&&("string"==typeof this[t]&&GameLib.Utils.PushUnique(e,this[t]),this[t]instanceof Array&&this[t].map(function(t){"string"==typeof t&&GameLib.Utils.PushUnique(e,t),t&&t instanceof GameLib.Component&&GameLib.Utils.PushUnique(e,t.id)}),this[t]&&this[t]instanceof GameLib.Component&&GameLib.Utils.PushUnique(e,this[t].id));return e},GameLib.Component.prototype.toString=function(){return this.id},GameLib.Component.MATERIAL=2,GameLib.Component.RENDERER=3,GameLib.Component.CAMERA=5,GameLib.Component.MESH=7,GameLib.Component.SPLINE=8,GameLib.Component.LIGHT=9,GameLib.Component.COMPOSER=11,GameLib.Component.RENDER_TARGET=12,GameLib.Component.PASS=13,GameLib.Component.SCENE=14,GameLib.Component.RAYCASTER=15,GameLib.Component.VIEWPORT=18,GameLib.Component.SYSTEM=19,GameLib.Component.GRAPHICS=20,GameLib.Component.HELPER=21,GameLib.Component.CUSTOM_CODE=22,GameLib.Component.MOUSE=23,GameLib.Component.SKELETON=24,GameLib.Component.TEXTURE=25,GameLib.Component.ENTITY_MANAGER=26,GameLib.Component.DOM_ELEMENT=27,GameLib.Component.STATS=29,GameLib.Component.GUI=30,GameLib.Component.IMAGE=31,GameLib.Component.ENTITY=32,GameLib.Component.MESH_SPHERE=33,GameLib.Component.MESH_PLANE=34,GameLib.Component.MESH_CURVE=35,GameLib.Component.PHYSICS_WORLD=36,GameLib.Component.BROADPHASE=37,GameLib.Component.SOLVER=38,GameLib.Component.RIGID_BODY=39,GameLib.Component.SHAPE=40,GameLib.Component.SHAPE_BOX=41,GameLib.Component.SHAPE_SPHERE=42,GameLib.Component.SHAPE_TRI_MESH=43,GameLib.Component.SHAPE_CONVEX_HULL=44,GameLib.Component.SHAPE_CONVEX_HULL_CYLINDER=45,GameLib.Component.SHAPE_HEIGHT_MAP=46,GameLib.Component.SHAPE_PLANE=47,GameLib.Component.CONTROLS=48,GameLib.Component.CONTROLS_EDITOR=49,GameLib.Component.CONTROLS_TOUCH=50;GameLib.Component.FRICTION_MATERIAL=51,GameLib.Component.FRICTION_CONTACT_MATERIAL=52,GameLib.Component.RAYCAST_VEHICLE=53,GameLib.Component.RAYCAST_WHEEL=54,GameLib.Component.CLOCK=55,GameLib.Component.ANIMATION=56,GameLib.Component.CONTROLS_KEYBOARD=57,GameLib.Component.CONTROLS_MOUSE=58,GameLib.Component.MESH_TEXT=59,GameLib.Component.FONT=60,GameLib.Component.CANVAS=61,GameLib.Component.BONE=62,GameLib.Component.MESH_BOX=63,GameLib.Component.MESH_CYLINDER=64,GameLib.Component.SYSTEM_ANIMATION=65,GameLib.Component.SYSTEM_CUSTOM_CODE=66,GameLib.Component.SYSTEM_GUI=67,GameLib.Component.SYSTEM_INPUT=68,GameLib.Component.SYSTEM_LINKING=69,GameLib.Component.SYSTEM_PHYSICS=70,GameLib.Component.SYSTEM_RENDER=71,GameLib.Component.SYSTEM_STORAGE=72,GameLib.Component.SYSTEM_VISUALIZATION=73,GameLib.Component.FOG=80,GameLib.Component.MESH_LINE=81,GameLib.Component.PARTICLE_ENGINE=82,GameLib.Component.SYSTEM_PARTICLE=83,GameLib.Component.PARTICLE=84,GameLib.Component.AUDIO=85,GameLib.Component.SYSTEM_AUDIO=86,GameLib.Component.CAST=87,GameLib.Component.GRAPHICS_RUNTIME=1,GameLib.Component.PHYSICS_RUNTIME=2,GameLib.Component.SOCKET_RUNTIME=3,GameLib.Component.STATISTICS_RUNTIME=4,GameLib.Component.DEFAULT_RUNTIME=5,GameLib.Component.GUI_RUNTIME=6,GameLib.Component.CODER_RUNTIME=7,GameLib.Component.GetCompentType=function(e){console.log("todo: implement?")},GameLib.Component.GetComponentInfo=function(e){switch(e){case 1:return null;case 2:return{name:"GameLib.D3.Material",runtime:GameLib.Component.GRAPHICS_RUNTIME,constructor:GameLib.D3.Material};case 3:return{name:"GameLib.D3.Renderer",runtime:GameLib.Component.GRAPHICS_RUNTIME,constructor:GameLib.D3.Renderer};case 4:return null;case 5:return{name:"GameLib.D3.Camera",runtime:GameLib.Component.GRAPHICS_RUNTIME,constructor:GameLib.D3.Camera};case 6:return null;case 7:return{name:"GameLib.D3.Mesh",runtime:GameLib.Component.GRAPHICS_RUNTIME,constructor:GameLib.D3.Mesh};case 8:return{name:"GameLib.D3.Spline",runtime:GameLib.Component.GRAPHICS_RUNTIME,constructor:GameLib.D3.Spline};case 9:return{name:"GameLib.D3.Light",runtime:GameLib.Component.GRAPHICS_RUNTIME,constructor:GameLib.D3.Light};case 10:return null;case 11:return{name:"GameLib.D3.Composer",runtime:GameLib.Component.GRAPHICS_RUNTIME,constructor:GameLib.D3.Composer};case 12:return{name:"GameLib.D3.RenderTarget",runtime:GameLib.Component.GRAPHICS_RUNTIME,constructor:GameLib.D3.RenderTarget};case 13:return{name:"GameLib.D3.Pass",runtime:GameLib.Component.GRAPHICS_RUNTIME,constructor:GameLib.D3.Pass};case 14:return{name:"GameLib.D3.Scene",runtime:GameLib.Component.GRAPHICS_RUNTIME,constructor:GameLib.D3.Scene};case 15:return{name:"GameLib.D3.Raycaster",runtime:GameLib.Component.GRAPHICS_RUNTIME,constructor:GameLib.D3.Raycaster};case 16:case 17:return null;case 18:return{name:"GameLib.D3.Viewport",runtime:GameLib.Component.GRAPHICS_RUNTIME,constructor:GameLib.D3.Viewport};case 19:return{name:"GameLib.System",runtime:GameLib.Component.DEFAULT_RUNTIME,constructor:GameLib.System};case 20:return{name:"GameLib.GraphicsRuntime",runtime:GameLib.Component.DEFAULT_RUNTIME,constructor:GameLib.GraphicsRuntime};case 21:return{name:"GameLib.D3.Helper",runtime:GameLib.Component.GRAPHICS_RUNTIME,constructor:GameLib.D3.Helper};case 22:return{name:"GameLib.CustomCode",runtime:GameLib.Component.DEFAULT_RUNTIME,constructor:GameLib.CustomCode};case 23:return{name:"GameLib.Mouse",runtime:GameLib.Component.GRAPHICS_RUNTIME,constructor:GameLib.Mouse};case 24:return{name:"GameLib.D3.Skeleton",runtime:GameLib.Component.GRAPHICS_RUNTIME,constructor:GameLib.D3.Skeleton};case 25:return{name:"GameLib.D3.Texture",runtime:GameLib.Component.GRAPHICS_RUNTIME,constructor:GameLib.D3.Texture};case 26:return{name:"GameLib.EntityManager",runtime:GameLib.Component.DEFAULT_RUNTIME,constructor:GameLib.EntityManager};case 27:return{name:"GameLib.DomElement",runtime:GameLib.Component.DEFAULT_RUNTIME,constructor:GameLib.DomElement};case 28:return null;case 29:return{name:"GameLib.Stats",runtime:GameLib.Component.STATISTICS_RUNTIME,constructor:GameLib.Stats};case 30:return{name:"GameLib.GUI",runtime:GameLib.Component.GUI_RUNTIME,constructor:GameLib.GUI};case 31:return{name:"GameLib.Image",runtime:GameLib.Component.DEFAULT_RUNTIME,constructor:GameLib.Image};case 32:return{name:"GameLib.Entity",runtime:GameLib.Component.DEFAULT_RUNTIME,constructor:GameLib.Entity};case 33:return{name:"GameLib.D3.Mesh.Sphere",runtime:GameLib.Component.GRAPHICS_RUNTIME,constructor:GameLib.D3.Mesh.Sphere};case 34:return{name:"GameLib.D3.Mesh.Plane",runtime:GameLib.Component.GRAPHICS_RUNTIME,constructor:GameLib.D3.Mesh.Plane};case 35:return{name:"GameLib.D3.Mesh.Curve",runtime:GameLib.Component.GRAPHICS_RUNTIME,constructor:GameLib.D3.Mesh.Curve};case 36:return{name:"GameLib.D3.PhysicsWorld",runtime:GameLib.Component.PHYSICS_RUNTIME,constructor:GameLib.D3.PhysicsWorld};case 37:return{name:"GameLib.D3.Broadphase",runtime:GameLib.Component.PHYSICS_RUNTIME,constructor:GameLib.D3.Broadphase};case 38:return{name:"GameLib.D3.Solver",runtime:GameLib.Component.PHYSICS_RUNTIME,constructor:GameLib.D3.Solver};case 39:return{name:"GameLib.D3.RigidBody",runtime:GameLib.Component.PHYSICS_RUNTIME,constructor:GameLib.D3.RigidBody};case 40:return{name:"GameLib.D3.Shape",runtime:GameLib.Component.PHYSICS_RUNTIME,constructor:GameLib.D3.Shape};case 41:return{name:"GameLib.D3.Shape.Box",runtime:GameLib.Component.PHYSICS_RUNTIME,constructor:GameLib.D3.Shape.Box};case 42:return{name:"GameLib.D3.Shape.Sphere",runtime:GameLib.Component.PHYSICS_RUNTIME,constructor:GameLib.D3.Shape.Sphere};case 43:return{name:"GameLib.D3.Shape.TriMesh",runtime:GameLib.Component.PHYSICS_RUNTIME,constructor:GameLib.D3.Shape.TriMesh};case 44:return{name:"GameLib.D3.Shape.ConvexHull",runtime:GameLib.Component.PHYSICS_RUNTIME,constructor:GameLib.D3.Shape.ConvexHull};case 45:return{name:"GameLib.D3.Shape.ConvexHull.Cylinder",runtime:GameLib.Component.PHYSICS_RUNTIME,constructor:GameLib.D3.Shape.ConvexHull.Cylinder};case 46:return{name:"GameLib.D3.Shape.HeightMap",runtime:GameLib.Component.DEFAULT_RUNTIME,constructor:GameLib.D3.Shape.HeightMap};case 47:return{name:"GameLib.D3.Shape.Plane",runtime:GameLib.Component.PHYSICS_RUNTIME,constructor:GameLib.D3.Shape.Plane};case 48:return{name:"GameLib.Controls",runtime:GameLib.Component.DEFAULT_RUNTIME,constructor:GameLib.Controls};case 49:return{name:"GameLib.Controls.D3.Editor",runtime:GameLib.Component.GRAPHICS_RUNTIME,constructor:GameLib.Controls.D3.Editor};case 50:return{name:"GameLib.Controls.Touch",runtime:GameLib.Component.DEFAULT_RUNTIME,constructor:GameLib.Controls.Touch};case 51:return{name:"GameLib.D3.FrictionMaterial",runtime:GameLib.Component.PHYSICS_RUNTIME,constructor:GameLib.D3.FrictionMaterial};case 52:return{name:"GameLib.D3.FrictionContactMaterial",runtime:GameLib.Component.PHYSICS_RUNTIME,constructor:GameLib.D3.FrictionContactMaterial};case 53:return{name:"GameLib.D3.RaycastVehicle",runtime:GameLib.Component.PHYSICS_RUNTIME,constructor:GameLib.D3.RaycastVehicle};case 54:return{name:"GameLib.D3.RaycastWheel",runtime:GameLib.Component.PHYSICS_RUNTIME,constructor:GameLib.D3.RaycastWheel};case 55:return{name:"GameLib.Clock",runtime:GameLib.Component.GRAPHICS_RUNTIME,constructor:GameLib.Clock};case 56:return{name:"GameLib.D3.Animation",runtime:GameLib.Component.DEFAULT_RUNTIME,constructor:GameLib.D3.Animation};case 57:return{name:"GameLib.Controls.Keyboard",runtime:GameLib.Component.DEFAULT_RUNTIME,constructor:GameLib.Controls.Keyboard};case 58:return{name:"GameLib.Controls.Mouse",runtime:GameLib.Component.DEFAULT_RUNTIME,constructor:GameLib.Controls.Mouse};case 59:return{name:"GameLib.D3.Mesh.Text",runtime:GameLib.Component.GRAPHICS_RUNTIME,constructor:GameLib.D3.Mesh.Text};case 60:return{name:"GameLib.D3.Font",runtime:GameLib.Component.GRAPHICS_RUNTIME,constructor:GameLib.D3.Font};case 61:return{name:"GameLib.Canvas",runtime:GameLib.Component.DEFAULT_RUNTIME,constructor:GameLib.Canvas};case 62:return{name:"GameLib.D3.Bone",runtime:GameLib.Component.GRAPHICS_RUNTIME,constructor:GameLib.D3.Bone};case 63:return{name:"GameLib.D3.Mesh.Box",runtime:GameLib.Component.GRAPHICS_RUNTIME,constructor:GameLib.D3.Mesh.Box};case 64:return{name:"GameLib.D3.Mesh.Cylinder",runtime:GameLib.Component.GRAPHICS_RUNTIME,constructor:GameLib.D3.Mesh.Cylinder};case 65:return{name:"GameLib.D3.System.Animation",runtime:GameLib.Component.DEFAULT_RUNTIME,constructor:GameLib.D3.System.Animation};case 66:return{name:"GameLib.D3.System.CustomCode",runtime:GameLib.Component.DEFAULT_RUNTIME,constructor:GameLib.D3.System.CustomCode};case 67:return{name:"GameLib.D3.System.GUI",runtime:GameLib.Component.DEFAULT_RUNTIME,constructor:GameLib.D3.System.GUI};case 68:return{name:"GameLib.D3.System.Input",runtime:GameLib.Component.DEFAULT_RUNTIME,constructor:GameLib.D3.System.Input};case 69:return{name:"GameLib.D3.System.Linking",runtime:GameLib.Component.DEFAULT_RUNTIME,constructor:GameLib.D3.System.Linking};case 70:return{name:"GameLib.D3.System.Physics",runtime:GameLib.Component.DEFAULT_RUNTIME,constructor:GameLib.D3.System.Physics};case 71:return{name:"GameLib.D3.System.Render",runtime:GameLib.Component.DEFAULT_RUNTIME,constructor:GameLib.D3.System.Render};case 72:return{name:"GameLib.D3.System.Storage",runtime:GameLib.Component.DEFAULT_RUNTIME,constructor:GameLib.D3.System.Storage};case 73:return{name:"GameLib.D3.System.Visualization",runtime:GameLib.Component.DEFAULT_RUNTIME,constructor:GameLib.D3.System.Visualization};case 80:return{name:"GameLib.D3.Fog",runtime:GameLib.Component.GRAPHICS_RUNTIME,constructor:GameLib.D3.Fog};case 81:return{name:"GameLib.D3.Mesh.Line",runtime:GameLib.Component.GRAPHICS_RUNTIME,constructor:GameLib.D3.Mesh.Line};case 82:return{name:"GameLib.D3.ParticleEngine",runtime:GameLib.Component.GRAPHICS_RUNTIME,constructor:GameLib.D3.ParticleEngine};case 83:return{name:"GameLib.D3.System.Particle",runtime:GameLib.Component.DEFAULT_RUNTIME,constructor:GameLib.D3.System.Particle};case 84:return{name:"GameLib.D3.Particle",runtime:GameLib.Component.GRAPHICS_RUNTIME,constructor:GameLib.D3.Particle};case 85:return{name:"GameLib.D3.Audio",runtime:GameLib.Component.GRAPHICS_RUNTIME,constructor:GameLib.D3.Audio};case 86:return{name:"GameLib.System.Audio",runtime:GameLib.Component.DEFAULT_RUNTIME,constructor:GameLib.System.Audio};case 87:return{name:"GameLib.Cast",runtime:GameLib.Component.SOCKET_RUNTIME,constructor:GameLib.Cast}}throw new Error("Unknown component type: "+e)},GameLib.Component.GetComponentName=function(e){var t=GameLib.Component.GetComponentInfo(e);return t?t.name:"unused"},GameLib.Component.GetComponentRuntime=function(e){var t=GameLib.Component.GetComponentInfo(e);return t?t.runtime:null},GameLib.Component.GetComponentConstructor=function(e){var t=GameLib.Component.GetComponentInfo(e);return t?t.constructor:null},GameLib.Component.prototype.toApiObject=function(){return this.id},GameLib.Component.prototype.processComponent=function(e){if(e instanceof GameLib.Component){e.buildIdToObject(),e.linked||(this.linked=!1);var t=e.idToObject;for(var i in t)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"==typeof e?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(var e in this.linkedObjects)this.linkedObjects.hasOwnProperty(e)&&this.hasOwnProperty(e)&&this[e]&&0!==e.indexOf("parent")&&(this.linkedObjects[e]instanceof Array?(this[e]=this[e].filter(function(e){return null!==e||(console.log("null object found and removed"),!1)}),this[e].map(function(e){this.processComponent(e)}.bind(this))):this.processComponent(this[e]));this instanceof GameLib.D3.Scene&&(this.storeClones||this.clones.map(function(e){this.idToObject.hasOwnProperty(e.id)&&delete this.idToObject[e.id]}.bind(this))),this.idToObject[this.id]=this,this.building=!1}},GameLib.Component.prototype.generateNewIds=function(){this.buildIdToObject();var e=GameLib.EntityManager.Instance.queryComponents(GameLib.Component.CUSTOM_CODE);for(var t in this.idToObject)if(this.idToObject.hasOwnProperty(t)){var i=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){var t=this.idToObject[e];t instanceof GameLib.Component&&t.remove()}.bind(this)),GameLib.Event.Emit(GameLib.Event.REMOVE_COMPONENT,{component:this})},GameLib.Component.prototype.clone=function(){var e=this.toApiObject();this.cloneNumber+=1,e.id=GameLib.Utils.RandomId(),e.name=this.name+" Clone ("+this.cloneNumber+")";var t=GameLib.Component.Construct(e);return t.isClone=!0,GameLib.Event.Emit(GameLib.Event.COMPONENT_CLONED,{parent:this,component:t}),t.parentEntity=null,t},GameLib.Component.prototype.cloneInstance=function(){var e=null;return this.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){var t=[],i=[],n=[];if(this.buildIdToObject(),this.saveSubscription||this.saveErrorSubscription)return void console.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(var a in this.idToObject)if(this.idToObject.hasOwnProperty(a)&&this.idToObject[a]instanceof GameLib.Component){var s=this.idToObject[a].toApiObject();t.push(s),this.publish(GameLib.Event.SAVE_COMPONENT,{apiObject:s,remote:e})}},GameLib.Component.Construct=function(e){var t=null,i=GameLib.Component.GetComponentInfo(e.componentType),n=i.constructor,a=n.FromObject,s=null;return GameLib.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){return new GameLib.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){return new GameLib.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.id+")"),this.name=t,GameLib.API.Component.call(this,GameLib.Component.CLOCK,i)},GameLib.API.Clock.prototype=Object.create(GameLib.Component.prototype),GameLib.API.Clock.prototype.constructor=GameLib.API.Clock,GameLib.API.Clock.FromObject=function(e){return new GameLib.API.Clock(e.id,e.name,e.parentEntity)},GameLib.API.Color=function(e,t,i,n){GameLib.Utils.UndefinedOrNull(e)&&(e=1),this.r=e,GameLib.Utils.UndefinedOrNull(t)&&(t=1),this.g=t,GameLib.Utils.UndefinedOrNull(i)&&(i=1),this.b=i,GameLib.Utils.UndefinedOrNull(n)&&(n=0),this.a=n},GameLib.API.Color.FromObject=function(e){return GameLib.Utils.UndefinedOrNull(e)&&(e={}),new GameLib.API.Color(e.r,e.g,e.b,e.a)},GameLib.API.Color.prototype.toHex=function(){this.r<0&&(this.r=0),this.g<0&&(this.g=0),this.b<0&&(this.b=0),this.r>1&&(this.r=1),this.g>1&&(this.g=1),this.b>1&&(this.b=1);var e=Math.floor(this.r>=1?255:256*this.r).toString(16),t=Math.floor(this.g>=1?255:256*this.g).toString(16),i=Math.floor(this.b>=1?255:256*this.b).toString(16);return e.length<2&&(e="0"+e),t.length<2&&(t="0"+t),i.length<2&&(i="0"+i),"#"+e+t+i},GameLib.API.Color.prototype.fromHex=function(e){var t=e.match(new RegExp("#+(..)(..)(..)"));this.r=parseInt(t[1],16)/255,this.g=parseInt(t[2],16)/255,this.b=parseInt(t[3],16)/255},GameLib.API.Controls=function(e,t,i,n,a){if(GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(this instanceof GameLib.Controls.D3.Editor&&(t=GameLib.Controls.CONTROLS_TYPE_EDITOR),this instanceof GameLib.Controls.Touch&&(t=GameLib.Controls.CONTROLS_TYPE_TOUCH),this instanceof GameLib.Controls.Keyboard&&(t=GameLib.Controls.CONTROLS_TYPE_KEYBOARD),this instanceof GameLib.Controls.Mouse&&(t=GameLib.Controls.CONTROLS_TYPE_MOUSE),GameLib.Utils.UndefinedOrNull(t)))throw new Error("Could not determine controls type from this");this.controlsType=t,GameLib.Utils.UndefinedOrNull(i)&&(t===GameLib.Controls.CONTROLS_TYPE_EDITOR&&(i="Editing Controls"),t===GameLib.Controls.CONTROLS_TYPE_TOUCH&&(i="Touch Controls"),t===GameLib.Controls.CONTROLS_TYPE_KEYBOARD&&(i="Keyboard Controls"),t===GameLib.Controls.CONTROLS_TYPE_MOUSE&&(i="Mouse Controls"),i+=" ("+this.id+")"),this.name=i,GameLib.Utils.UndefinedOrNull(n)&&(n=null),this.domElement=n;var s=GameLib.Component.CONTROLS;this.controlsType===GameLib.Controls.CONTROLS_TYPE_EDITOR&&(s=GameLib.Component.CONTROLS_EDITOR),this.controlsType===GameLib.Controls.CONTROLS_TYPE_TOUCH&&(s=GameLib.Component.CONTROLS_TOUCH),this.controlsType===GameLib.Controls.CONTROLS_TYPE_KEYBOARD&&(s=GameLib.Component.CONTROLS_KEYBOARD),this.controlsType===GameLib.Controls.CONTROLS_TYPE_MOUSE&&(s=GameLib.Component.CONTROLS_MOUSE),GameLib.API.Component.call(this,s,a)},GameLib.API.Controls.prototype=Object.create(GameLib.Component.prototype),GameLib.API.Controls.prototype.constructor=GameLib.API.Controls,GameLib.API.Controls.FromObject=function(e){return new GameLib.API.Controls(e.id,e.controlsType,e.name,e.domElement,e.parentEntity)},GameLib.API.CustomCode=function(e,t,i,n,a){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="CustomCode ("+this.id+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=42),this.eventId=i,GameLib.Utils.UndefinedOrNull(n)&&(n="return null;\n//@ sourceURL="+this.name+".js"),this.code=n,GameLib.API.Component.call(this,GameLib.Component.CUSTOM_CODE,a)},GameLib.API.CustomCode.prototype=Object.create(GameLib.Component.prototype),GameLib.API.CustomCode.prototype.constructor=GameLib.API.CustomCode,GameLib.API.CustomCode.FromObject=function(e){return new GameLib.API.CustomCode(e.id,e.name,e.eventId,e.code,e.parentEntity)},GameLib.API.DomElement=function(e,t,i,n){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="DOM Element ("+this.id+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=""),this.domElementId=i,GameLib.API.Component.call(this,GameLib.Component.DOM_ELEMENT,n)},GameLib.API.DomElement.prototype=Object.create(GameLib.Component.prototype),GameLib.API.DomElement.prototype.constructor=GameLib.API.DomElement,GameLib.API.DomElement.FromObject=function(e){return new GameLib.API.DomElement(e.id,e.name,e.domElementId,e.parentEntity)},GameLib.API.EntityManager=function(e,t,i,n,a,s){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="Entity Manager ("+this.id+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=[]),this.entities=i,GameLib.Utils.UndefinedOrNull(n)&&(n=null),this.defaultEntity=n,GameLib.Utils.UndefinedOrNull(a)&&(a=null),this.defaultRenderer=a,GameLib.API.Component.call(this,GameLib.Component.ENTITY_MANAGER,s)},GameLib.API.EntityManager.prototype=Object.create(GameLib.Component.prototype),GameLib.API.EntityManager.prototype.constructor=GameLib.API.EntityManager,GameLib.API.EntityManager.FromObject=function(e){var t=e.entities.map(function(e){return GameLib.API.Entity.FromObject(e)});return new GameLib.API.EntityManager(e.id,e.name,t,e.defaultEntity,e.defaultRenderer,e.parentEntity)},GameLib.API.Entity=function(e,t,i,n,a){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="Entity ("+this.id+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=[]),this.components=i,GameLib.API.Component.call(this,GameLib.Component.ENTITY,n),GameLib.Utils.UndefinedOrNull(a)&&(a=null),this.parentEntityManager=a,this.activeComponent=null},GameLib.API.Entity.prototype=Object.create(GameLib.Component.prototype),GameLib.API.Entity.prototype.constructor=GameLib.API.Entity,GameLib.API.Entity.FromObject=function(e){return new GameLib.API.Entity(e.id,e.name,e.components,e.parentEntity,e.parentEntityManager)},GameLib.API.GUI=function(e,t,i,n,a){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="GUI ("+this.id+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=null),this.domElement=i,GameLib.Utils.UndefinedOrNull(n)&&(n=[]),this.objects=n,GameLib.API.Component.call(this,GameLib.Component.GUI,a)},GameLib.API.GUI.prototype=Object.create(GameLib.Component.prototype),GameLib.API.GUI.prototype.constructor=GameLib.API.GUI,GameLib.API.GUI.FromObject=function(e){var t=null;return e.domElement&&(t=e.domElement instanceof Object?GameLib.API.DomElement.FromObject(e.domElement):e.domElement),new GameLib.API.GUI(e.id,e.name,t,e.objects,e.parentEntity)},GameLib.API.Image=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="Image "+e),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=GameLib.Utils.LowerUnderscore(t)),this.fileName=i,GameLib.Utils.UndefinedOrNull(n)&&(n=".unknown"),this.extension=n,GameLib.Utils.UndefinedOrNull(a)&&(a="/"),this.path=a,GameLib.Utils.UndefinedOrNull(s)&&(s="application/octet-stream",this.extension.match(/(png)$/i)&&(s="image/png"),this.extension.match(/(jpg|jpeg)$/i)&&(s="image/jpeg"),this.extension.match(/(gif)$/i)&&(s="image/gif")),this.contentType=s,GameLib.Utils.UndefinedOrNull(o)&&(o=0),this.size=o,GameLib.API.Component.call(this,GameLib.Component.IMAGE,r)},GameLib.API.Image.prototype=Object.create(GameLib.Component.prototype),GameLib.API.Image.prototype.constructor=GameLib.API.Image,GameLib.API.Image.FromObject=function(e){return new GameLib.API.Image(e.id,e.name,e.fileName,e.extension,e.path,e.contentType,e.size,e.parentEntity)},GameLib.API.Matrix4=function(e,t,i,n){this.rows=[],GameLib.Utils.UndefinedOrNull(e)&&(e=new GameLib.API.Vector4(1,0,0,0)),this.rows[0]=e,GameLib.Utils.UndefinedOrNull(t)&&(t=new GameLib.API.Vector4(0,1,0,0)),this.rows[1]=t,GameLib.Utils.UndefinedOrNull(i)&&(i=new GameLib.API.Vector4(0,0,1,0)),this.rows[2]=i,GameLib.Utils.UndefinedOrNull(n)&&(n=new GameLib.API.Vector4(0,0,0,1)),this.rows[3]=n,this.temp=[],this.temp.push(new GameLib.API.Vector4),this.temp.push(new GameLib.API.Vector4),this.temp.push(new GameLib.API.Vector4),this.temp.push(new GameLib.API.Vector4),this.forward=new GameLib.API.Vector4,this.left=new GameLib.API.Vector4,this.up=new GameLib.API.Vector4},GameLib.API.Matrix4.FromObject=function(e){if(e.rows)return new GameLib.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(e instanceof Array)return new GameLib.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]));throw console.warn("Unsupported object matrix type - whats your DB version?"),new Error("Unsupported object matrix type - whats your DB version?")},GameLib.API.Matrix4.prototype.rotationMatrixX=function(e){return this.identity(),this.rows[1]=new GameLib.API.Vector4(0,Math.cos(e),-1*Math.sin(e),0),this.rows[2]=new GameLib.API.Vector4(0,Math.sin(e),Math.cos(e),0),this},GameLib.API.Matrix4.prototype.rotationMatrixY=function(e){return this.identity(),this.rows[0]=new GameLib.API.Vector4(Math.cos(e),0,Math.sin(e),0),this.rows[2]=new GameLib.API.Vector4(-1*Math.sin(e),0,Math.cos(e),0),this},GameLib.API.Matrix4.prototype.rotationMatrixZ=function(e){return this.identity(),this.rows[0]=new GameLib.API.Vector4(Math.cos(e),-1*Math.sin(e),0,0),this.rows[1]=new GameLib.API.Vector4(Math.sin(e),Math.cos(e),0,0),this},GameLib.API.Matrix4.prototype.rotateX=function(e,t){return this.identity(),this.rotationMatrixX(e),this.multiply(t)},GameLib.API.Matrix4.prototype.rotateY=function(e,t){return this.identity(),this.rotationMatrixY(e),this.multiply(t)},GameLib.API.Matrix4.prototype.rotateZ=function(e,t){return this.identity(),this.rotationMatrixZ(e),this.multiply(t)},GameLib.API.Matrix4.prototype.multiply=function(e){return e instanceof GameLib.API.Quaternion||e instanceof GameLib.API.Vector4?new GameLib.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):e instanceof GameLib.API.Vector3?new GameLib.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):void 0},GameLib.API.Matrix4.prototype.identity=function(){this.rows=[new GameLib.API.Vector4(1,0,0,0),new GameLib.API.Vector4(0,1,0,0),new GameLib.API.Vector4(0,0,1,0),new GameLib.API.Vector4(0,0,0,1)]},GameLib.API.Mouse=function(e,t,i,n,a){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.Component.call(this,GameLib.Component.MOUSE,a)},GameLib.API.Mouse.prototype=Object.create(GameLib.Component.prototype),GameLib.API.Mouse.prototype.constructor=GameLib.API.Mouse,GameLib.API.Mouse.FromObject=function(e){return new GameLib.API.Mouse(e.id,e.name,e.x,e.y,e.parentEntity)},GameLib.API.Quaternion=function(e,t,i,n,a,s){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(a)&&(a=new GameLib.API.Vector3),this.axis=a,GameLib.Utils.UndefinedOrNull(s)&&(s=0),this.angle=s},GameLib.API.Quaternion.prototype.translate=function(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this},GameLib.API.Quaternion.prototype.copy=function(){return new GameLib.API.Quaternion(this.x,this.y,this.z,this.w)},GameLib.API.Quaternion.prototype.normalize=function(){var e=this.x*this.x+this.y*this.y+this.z*this.z;if(e<1e-6)return this;var t=1/Math.sqrt(e);this.x*=t,this.y*=t,this.z*=t},GameLib.API.Quaternion.prototype.multiply=function(e){var t,i,n,a,s=e,o=this;if(e instanceof GameLib.API.Matrix4)return t=s.rows[0].x*o.x+s.rows[0].y*o.y+s.rows[0].z*o.z+s.rows[0].w*o.w,i=s.rows[1].x*o.x+s.rows[1].y*o.y+s.rows[1].z*o.z+s.rows[1].w*o.w,n=s.rows[2].x*o.x+s.rows[2].y*o.y+s.rows[2].z*o.z+s.rows[2].w*o.w,a=s.rows[3].x*o.x+s.rows[3].y*o.y+s.rows[3].z*o.z+s.rows[3].w*o.w,this.x=t,this.y=i,this.z=n,this.w=a,this;if(e instanceof GameLib.API.Quaternion)return t=s.x*o.x-s.y*o.y-s.z*o.z-s.w*s.w,i=s.x*o.y+s.y*o.x-s.z*o.w+s.w*s.z,n=s.x*o.z+s.y*o.w+s.z*o.x-s.w*s.y,a=s.x*o.w-s.y*o.z+s.z*o.y+s.w*s.x,this.x=t,this.y=i,this.z=n,this.w=a,this;throw console.log("This functionality not implemented - please do this"),new Error("This functionality not implemented - please do this")},GameLib.API.Quaternion.prototype.setFromAngle=function(e){return this.instance.setFromAxisAngle(this.axis.instance,e),this.x=this.instance.x,this.y=this.instance.y,this.z=this.instance.z,this.w=this.instance.w,this},GameLib.API.Quaternion.prototype.subtract=function(e){return e instanceof GameLib.API.Vector3&&(this.x-=e.x,this.y-=e.y,this.z-=e.z),e instanceof GameLib.API.Quaternion&&(this.x-=e.x,this.y-=e.y,this.z-=e.z,this.w-=e.w),this},GameLib.API.Quaternion.prototype.magnitude=function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)},GameLib.API.Quaternion.prototype.normalize=function(){var e=this.magnitude();return e<1e-6?this:(this.x*=e,this.y*=e,this.z*=e,this.w*=e,this)},GameLib.API.Quaternion.prototype.setFromRotationMatrix=function(e){this.instance.setFromRotationMatrix(e.instance),this.x=this.instance.x,this.y=this.instance.y,this.z=this.instance.z,this.w=this.instance.w},GameLib.API.Quaternion.prototype.slerp=function(e,t){return this.updateInstance(),this.instance.slerp(e.instance,t),this.x=this.instance.x,this.y=this.instance.y,this.z=this.instance.z,this.w=this.instance.w,this},GameLib.API.Quaternion.FromObject=function(e){var t=null;return e.axis&&(t=GameLib.API.Vector3.FromObject(e.axis)),new GameLib.API.Quaternion(e.x,e.y,e.z,e.w,t,e.angle)},GameLib.API.Quaternion.Points=function(){this.vectors=[]},GameLib.API.Quaternion.Points.prototype.add=function(e){if(e instanceof GameLib.API.Vector3&&(e=new GameLib.API.Quaternion(e.x,e.y,e.z,1)),!e instanceof GameLib.API.Quaternion)throw console.warn("Vector needs to be of type Quaternion"),new Error("Vector needs to be of type Quaternion");return this.vectors.push(e),this},GameLib.API.Quaternion.Points.prototype.copy=function(){for(var e=[],t=0;ts&&(s=c.x,n=t*e)}this.vectors=a;for(var m=(new GameLib.API.Matrix4).rotationMatrixY(n),h=0;hs&&(s=c.y,n=t*e)}this.vectors=a;for(var m=(new GameLib.API.Matrix4).rotationMatrixX(n),h=0;hn&&(n=this.vectors[o].x),this.vectors[o].y>a&&(a=this.vectors[o].y),this.vectors[o].z>s&&(s=this.vectors[o].z);return new GameLib.API.Vector3(Math.abs(n-e),Math.abs(a-t),Math.abs(a-i))},GameLib.API.Quaternion.Points.prototype.average=function(){for(var e=0,t=0,i=0,n=0;n0},GameLib.API.Vector3.normal=function(e,t,i){var n=t.copy(),a=i.copy();return n.subtract(e).cross(a.subtract(e))},GameLib.API.Vector3.prototype.lookAt=function(e,t){var i=GameLib.API.Matrix4.lookAt(this,e,t);return this.multiply(i)},GameLib.API.Vector3.prototype.translate=function(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this},GameLib.API.Vector3.prototype.add=function(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this},GameLib.API.Vector3.prototype.squared=function(){return this.x*this.x+this.y*this.y+this.z*this.z},GameLib.API.Vector3.prototype.copy=function(){return new GameLib.API.Vector3(this.x,this.y,this.z)},GameLib.API.Vector3.prototype.set=function(e,t,i){this.x=e,this.y=t,this.z=i},GameLib.API.Vector3.prototype.lerp=function(e,t){return new GameLib.API.Vector3(this.x+(e.x-this.x)*t,this.y+(e.y-this.y)*t,this.z+(e.z-this.z)*t)},GameLib.API.Vector3.prototype.distanceTo=function(e){var t=this.x-e.x,i=this.y-e.y,n=this.z-e.z;return Math.sqrt(t*t+i*i+n*n)},GameLib.API.Vector3.AngleDirection=function(e,t,i){var n=e.cross(t),a=n.dot(i);return a>0?1:a<0?-1:0},GameLib.API.Vector3.prototype.multiply=function(e,t){var i,n,a,s=e,o=this;if(GameLib.Utils.UndefinedOrNull(t)&&(t=!1),"number"==typeof e)return t?(this.x*=e,this.y*=e,this.z*=e,this):this.x*e+this.y*e+this.z*e;if(e instanceof GameLib.API.Vector3)return t?(i=s.y*o.z-s.z*o.y,n=s.z*o.x-s.x*o.z,a=s.x*o.y-s.y*o.x,this.x=i,this.y=n,this.z=a,this):this.x*e.x+this.y*e.y+this.z*e.z;throw console.log("functionality not implemented - please do this"),new Error("not implemented")},GameLib.API.Vector3.prototype.dot=function(e){return this.x*e.x+this.y*e.y+this.z*e.z},GameLib.API.Vector3.prototype.normalize=function(){var e=this.squared();if(e<1e-6)return this;var t=1/Math.sqrt(e);return new GameLib.API.Vector3(this.x*t,this.y*t,this.z*t)},GameLib.API.Vector3.prototype.clone=function(){return new GameLib.API.Vector3(this.x,this.y,this.z)},GameLib.API.Vector3.prototype.applyQuaternion=function(e){var t=this.x,i=this.y,n=this.z,a=e.x,s=e.y,o=e.z,r=e.w,c=r*t+s*n-o*i,m=r*i+o*t-a*n,h=r*n+a*i-s*t,l=-a*t-s*i-o*n;return this.x=c*r+l*-a+m*-o-h*-s,this.y=m*r+l*-s+h*-a-c*-o,this.z=h*r+l*-o+c*-s-m*-a,this},GameLib.API.Vector3.prototype.clamp=function(e,t){return this.x=Math.max(e.x,Math.min(t.x,this.x)),this.y=Math.max(e.y,Math.min(t.y,this.y)),this.z=Math.max(e.z,Math.min(t.z,this.z)),this},GameLib.API.Vector3.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)},GameLib.API.Vector3.prototype.reflect=function(e){return this.sub(v1.copy(e).multiply(2*this.dot(e)))},GameLib.API.Vector3.prototype.angleTo=function(e){var t=this.dot(e)/Math.sqrt(this.lengthSq()*e.lengthSq());return Math.acos(exports.Math.clamp(t,-1,1))},GameLib.API.Vector3.FromObject=function(e){return new GameLib.API.Vector3(e.x,e.y,e.z)},GameLib.API.Vector4=function(e,t,i,n){GameLib.Utils.UndefinedOrNull(e)&&(e=0),this.x=e,GameLib.Utils.UndefinedOrNull(t)&&(t=0),this.y=t,GameLib.Utils.UndefinedOrNull(i)&&(i=0),this.z=i,GameLib.Utils.UndefinedOrNull(n)&&(n=1),this.w=n},GameLib.API.Vector4.prototype.equals=function(e){return this.x===e.x&&this.y===e.y&&this.z===e.z&&this.w===e.w},GameLib.API.Vector4.FromObject=function(e){return new GameLib.API.Vector4(e.x,e.y,e.z,e.w)},GameLib.Canvas=function(e){if(GameLib.Utils.UndefinedOrNull(e)&&(e={}),e instanceof GameLib.Canvas)return e;GameLib.API.Canvas.call(this,e.id,e.name,e.width,e.height,e.parentEntity),GameLib.Component.call(this)},GameLib.Canvas.prototype=Object.create(GameLib.API.Canvas.prototype),GameLib.Canvas.prototype.constructor=GameLib.Canvas,GameLib.Canvas.prototype.createInstance=function(){this.instance=document.createElement("canvas"),this.instance.width=this.width,this.instance.height=this.height,GameLib.Component.prototype.createInstance.call(this)},GameLib.Canvas.prototype.updateInstance=function(e){GameLib.Utils.UndefinedOrNull(e)&&console.warn("unknown property update for Canvas: "+e),"width"===e&&(this.instance.width=this.width),"height"===e&&(this.instance.height=this.height)},GameLib.Canvas.prototype.toApiObject=function(){return new GameLib.API.Canvas(this.id,this.name,this.width,this.height,GameLib.Utils.IdOrNull(this.parentEntity))},GameLib.Canvas.FromObject=function(e){return new GameLib.Canvas(GameLib.API.Canvas.FromObject(e))},GameLib.Cast=function(e,t){if(this.socket=e,this.socket.isNotWebSocketThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),t instanceof GameLib.Cast)return t;GameLib.API.Cast.call(this,t.id,t.name,t.castType,t.roomId,t.peer,t.serverIp,t.port,t.parentEntity),GameLib.Component.call(this,{peer:GameLib.Component})},GameLib.Cast.prototype=Object.create(GameLib.API.Cast.prototype),GameLib.Cast.prototype.constructor=GameLib.Cast,GameLib.Cast.CAST_TYPE_ROOM=1,GameLib.Cast.CAST_TYPE_PEER=2,GameLib.Cast.CAST_TYPE_ALL=3,GameLib.Cast.CAST_TYPE_ALL_BUT_PEER=4,GameLib.Cast.prototype.createInstance=function(){this.instance=!0,GameLib.Component.prototype.createInstance.call(this)},GameLib.Cast.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.Cast.prototype.remove=function(){if(this.removeSubscription)return void console.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.Cast.prototype.clone=function(){var e=this.templateParticle.mesh.clone(),t=this.templateParticle.clone();t.mesh=e,t.instance=e.instance;var i=GameLib.Component.prototype.clone.call(this);return i.templateParticle=t,i},GameLib.Cast.prototype.processParticles=function(e){},GameLib.Cast.prototype.createNewParticle=function(e){},GameLib.Cast.prototype.toApiObject=function(){return new GameLib.API.Cast(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.Cast.FromObject=function(e,t){var i=GameLib.API.Cast.FromObject(t);return new GameLib.Cast(e,i)},GameLib.Clock=function(e,t){if(this.graphics=e,this.graphics.isNotThreeThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),t instanceof GameLib.Clock)return t;GameLib.API.Clock.call(this,t.id,t.name,t.parentEntity),GameLib.Component.call(this)},GameLib.Clock.prototype=Object.create(GameLib.API.Clock.prototype),GameLib.Clock.prototype.constructor=GameLib.Clock;GameLib.Clock.prototype.createInstance=function(){this.instance=new THREE.Clock,GameLib.Component.prototype.createInstance.call(this)},GameLib.Clock.prototype.updateInstance=function(){},GameLib.Clock.prototype.getDelta=function(){var e=this.instance.getDelta();return e>1/30&&(e=1/30),e},GameLib.Clock.prototype.toApiObject=function(){return new GameLib.API.Clock(this.id,this.name,GameLib.Utils.IdOrNull(this.parentEntity))},GameLib.Clock.FromObject=function(e,t){var i=GameLib.API.Clock.FromObject(t);return new GameLib.Clock(e,i)},GameLib.CoderRuntime=function(e,t,i){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="Coder ("+e+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=GameLib.CoderRuntime.TYPE_CODE_MIRROR),this.coderType=i,this.createInstance()},GameLib.CoderRuntime.TYPE_CODE_MIRROR=1,GameLib.CoderRuntime.prototype.createInstance=function(){this.coderType===GameLib.CoderRuntime.TYPE_CODE_MIRROR?this.instance=CodeMirror:this.instance=null},GameLib.CoderRuntime.prototype.updateInstance=function(e){"coderType"===e&&this.createInstance()},GameLib.CoderRuntime.prototype.isNotCodeMirrorThrow=function(){if(!(this.instance instanceof CodeMirror))throw console.error("Only CodeMirror supported"),new Error("Only CodeMirror supported")},GameLib.Color=function(e,t,i,n){if(this.graphics=e,this.graphics.isNotThreeThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),t instanceof GameLib.Color)return t;GameLib.API.Color.call(this,t.r,t.g,t.b,t.a),GameLib.Utils.UndefinedOrNull(i)&&(i=null),this.parentObject=i,GameLib.Utils.UndefinedOrNull(n)&&(n=.001),this.grain=n,this.createInstance()},GameLib.Color.prototype=Object.create(GameLib.API.Color.prototype),GameLib.Color.prototype.constructor=GameLib.Color,GameLib.Color.prototype.createInstance=function(){this.instance=new THREE.Color(this.r,this.g,this.b)},GameLib.Color.prototype.updateInstance=function(e){this.instance.r=this.r,this.instance.g=this.g,this.instance.b=this.b,this.parentObject&&this.parentObject.updateInstance&&this.parentObject.updateInstance(e)},GameLib.Color.prototype.toApiObject=function(){return new GameLib.API.Color(this.r,this.g,this.b,this.a)},GameLib.Controls=function(e){if(GameLib.Utils.UndefinedOrNull(e)&&(e={}),e instanceof GameLib.Controls)return e;GameLib.API.Controls.call(this,e.id,e.controlsType,e.name,e.domElement,e.parentEntity);var t={domElement:GameLib.DomElement},i=!1;this.controlsType===GameLib.Controls.CONTROLS_TYPE_EDITOR&&(t.raycaster=GameLib.D3.Raycaster,t.camera=GameLib.D3.Camera,i=!0),GameLib.Component.call(this,t,i)},GameLib.Controls.prototype=Object.create(GameLib.API.Controls.prototype),GameLib.Controls.prototype.constructor=GameLib.Controls,GameLib.Controls.D3=function(){},GameLib.Controls.CONTROLS_TYPE_EDITOR=0,GameLib.Controls.CONTROLS_TYPE_TOUCH=1,GameLib.Controls.CONTROLS_TYPE_KEYBOARD=2,GameLib.Controls.CONTROLS_TYPE_MOUSE=3,GameLib.Controls.prototype.createInstance=function(){GameLib.Component.prototype.createInstance.call(this)},GameLib.Controls.prototype.updateInstance=function(){console.log("default controls update instance")},GameLib.Controls.prototype.toApiObject=function(){return new GameLib.API.Controls(this.id,this.controlsType,this.name,GameLib.Utils.IdOrNull(this.domElement),GameLib.Utils.IdOrNull(this.parentEntity))},GameLib.Controls.FromObject=function(e){var t=GameLib.API.Controls.FromObject(e);return new GameLib.Controls(t)},GameLib.Controls.D3.Editor=function(e,t,i,n){this.graphics=e,this.graphics.isNotThreeThrow(),GameLib.Utils.UndefinedOrNull(i)&&(i=null),this.raycaster=i,GameLib.Utils.UndefinedOrNull(n)&&(n=null),this.camera=n,this.raycaster instanceof GameLib.D3.API.Raycaster&&(this.raycaster=new GameLib.D3.Raycaster(this.graphics,this.raycaster)),this.camera instanceof GameLib.D3.API.Camera&&(this.camera=new GameLib.D3.Camera(this.graphics,this.camera)),GameLib.Controls.call(this,t)},GameLib.Controls.D3.Editor.prototype=Object.create(GameLib.Controls.prototype),GameLib.Controls.D3.Editor.prototype.constructor=GameLib.Controls.D3.Editor,GameLib.Controls.D3.Editor.prototype.createInstance=function(){if(!this.camera||!this.camera.instance)throw new Error("No camera at time of instance");if(!this.domElement||!this.domElement.instance)throw new Error("No dom element at time of instance");this.instance=new THREE.EditorControls(this.camera.instance,this.domElement.instance),GameLib.Controls.prototype.createInstance.call(this)},GameLib.Controls.D3.Editor.prototype.updateInstance=function(){console.warn("an update instance was called on editor controls - which, if not called from within a running system at the right time will affect the order of input event handling and cause system instability"),GameLib.Controls.prototype.updateInstance.call(this)},GameLib.Controls.D3.Editor.prototype.toApiObject=function(){var e=GameLib.Controls.prototype.toApiObject.call(this);return e.raycaster=GameLib.Utils.IdOrNull(this.raycaster),e.camera=GameLib.Utils.IdOrNull(this.camera),e},GameLib.Controls.D3.Editor.FromObject=function(e,t){var i=GameLib.API.Controls.FromObject(t);return new GameLib.Controls.D3.Editor(e,i,t.raycaster,t.camera)},GameLib.Controls.Keyboard=function(e){GameLib.Controls.call(this,e)},GameLib.Controls.Keyboard.prototype=Object.create(GameLib.Controls.prototype),GameLib.Controls.Keyboard.prototype.constructor=GameLib.Controls.Keyboard,GameLib.Controls.Keyboard.prototype.createInstance=function(){this.instance=!0,GameLib.Controls.prototype.createInstance.call(this)},GameLib.Controls.Keyboard.prototype.updateInstance=function(){GameLib.Controls.prototype.updateInstance.call(this)},GameLib.Controls.Keyboard.prototype.toApiObject=function(){return GameLib.Controls.prototype.toApiObject.call(this)},GameLib.Controls.Keyboard.FromObject=function(e){var t=GameLib.API.Controls.FromObject(e);return new GameLib.Controls.Keyboard(t)},GameLib.Controls.Mouse=function(e){GameLib.Controls.call(this,e)},GameLib.Controls.Mouse.prototype=Object.create(GameLib.Controls.prototype),GameLib.Controls.Mouse.prototype.constructor=GameLib.Controls.Mouse,GameLib.Controls.Mouse.prototype.createInstance=function(){this.instance=!0,GameLib.Controls.prototype.createInstance.call(this)},GameLib.Controls.Mouse.prototype.updateInstance=function(){GameLib.Controls.prototype.updateInstance.call(this)},GameLib.Controls.Mouse.prototype.toApiObject=function(){return GameLib.Controls.prototype.toApiObject.call(this)},GameLib.Controls.Mouse.FromObject=function(e){var t=GameLib.API.Controls.FromObject(e);return new GameLib.Controls.Mouse(t)},GameLib.Controls.Touch=function(e,t){GameLib.Utils.UndefinedOrNull(t)&&(t=5),this.sensitivity=t,GameLib.Controls.call(this,e)},GameLib.Controls.Touch.prototype=Object.create(GameLib.Controls.prototype),GameLib.Controls.Touch.prototype.constructor=GameLib.Controls.Touch,GameLib.Controls.Touch.prototype.createInstance=function(){this.instance=!0,GameLib.Controls.prototype.createInstance.call(this)},GameLib.Controls.Touch.prototype.updateInstance=function(){GameLib.Controls.prototype.updateInstance.call(this)},GameLib.Controls.Touch.prototype.toApiObject=function(){var e=GameLib.Controls.prototype.toApiObject.call(this);return e.sensitivity=this.sensitivity,e},GameLib.Controls.Touch.FromObject=function(e){var t=GameLib.API.Controls.FromObject(e);return new GameLib.Controls.Touch(t,e.sensitivity)},GameLib.CustomCode=function(e){if(GameLib.Utils.UndefinedOrNull(e)&&(e={}),e instanceof GameLib.CustomCode)return e;GameLib.API.CustomCode.call(this,e.id,e.name,e.eventId,e.code,e.parentEntity),this.editor=null,GameLib.Component.call(this)},GameLib.CustomCode.prototype=Object.create(GameLib.API.CustomCode.prototype),GameLib.CustomCode.prototype.constructor=GameLib.CustomCode,GameLib.CustomCode.prototype.createInstance=function(){try{this.instance=new Function("data",this.code).bind(this)}catch(e){this.instance=new Function("data","console.log('compilation failed for : "+this.name+"');").bind(this)}GameLib.Component.prototype.createInstance.call(this)},GameLib.CustomCode.prototype.updateInstance=function(){try{this.instance=new Function("data",this.code).bind(this),this.publish(GameLib.Event.COMPILE_SUCCESS,{component:this})}catch(e){this.instance=new Function("data","console.log('compilation update failed for : "+this.name+"');").bind(this),this.publish(GameLib.Event.COMPILE_FAILED,{component:this})}},GameLib.CustomCode.prototype.toApiObject=function(){return new GameLib.API.CustomCode(this.id,this.name,this.eventId,this.code,GameLib.Utils.IdOrNull(this.parentEntity))},GameLib.CustomCode.FromObject=function(e){var t=GameLib.API.CustomCode.FromObject(e);return new GameLib.CustomCode(t)},GameLib.CustomCode.prototype.launchEditor=function(){GameLib.Event.Emit(GameLib.Event.GET_RUNTIME,null,function(e){this.coder=e.coder,this.coder.isNotCodeMirrorThrow()}.bind(this)),this.editor=this.coder.instance(document.body,{value:this.code,mode:"javascript",lineNumbers:!0,scrollbarStyle:"overlay",indentWithTabs:!0,indentUnit:4}),this.editor.on("change",function(){this.code=this.editor.getValue(),this.updateInstance()}.bind(this))},GameLib.CustomCode.prototype.closeEditor=function(){var e=this.editor.getWrapperElement();e.parentElement.removeChild(e)},GameLib.D3.API.Animation=function(e,t,i,n,a,s,o,r,c,m,h,l){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="Animation ("+this.id+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=0),this.rotationSpeed=i,GameLib.Utils.UndefinedOrNull(n)&&(n=0),this.translationSpeed=n,GameLib.Utils.UndefinedOrNull(a)&&(a=0),this.scaleSpeed=a,GameLib.Utils.UndefinedOrNull(s)&&(s=null),this.rotationFn=s,GameLib.Utils.UndefinedOrNull(o)&&(o=null),this.translationFn=o,GameLib.Utils.UndefinedOrNull(r)&&(r=null),this.scaleFn=r,GameLib.Utils.UndefinedOrNull(c)&&(c={position:!1,rotation:!0,scale:!1}),this.blocking=c,GameLib.Utils.UndefinedOrNull(m)&&(m=!0),this.applyToMeshWhenDone=m,GameLib.Utils.UndefinedOrNull(h)&&(h=[]),this.meshes=h,GameLib.API.Component.call(this,GameLib.Component.ANIMATION,l)},GameLib.D3.API.Animation.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.API.Animation.prototype.constructor=GameLib.D3.API.Animation,GameLib.D3.API.Animation.FromObject=function(e){return new GameLib.D3.API.Animation(e.id,e.name,e.rotationSpeed,e.translationSpeed,e.scaleSpeed,e.rotationFn,e.translationFn,e.scaleFn,e.blocking,e.applyToMeshWhenDone,e.meshes,e.parentEntity)},GameLib.D3.API.Audio=function(e,t,i,n,a,s,o,r,c){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="Audio ("+this.id+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=""),this.path=i,GameLib.Utils.UndefinedOrNull(n)&&(n=!1),this.loop=n,GameLib.Utils.UndefinedOrNull(a)&&(a=.5),this.volume=a,GameLib.Utils.UndefinedOrNull(s)&&(s=null),this.camera=s,GameLib.Utils.UndefinedOrNull(o)&&(o=!1),this.overplay=o,GameLib.Utils.UndefinedOrNull(r)&&(r=!1),this.paused=r,GameLib.API.Component.call(this,GameLib.Component.AUDIO,c)},GameLib.D3.API.Audio.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.API.Audio.prototype.constructor=GameLib.D3.API.Audio,GameLib.D3.API.Audio.FromObject=function(e){var t=null;return e.camera&&(t=e.camera instanceof Object?GameLib.D3.API.Camera.FromObject(e.camera):e.camera),new GameLib.D3.API.Audio(e.id,e.name,e.path,e.loop,e.volume,t,e.overplay,e.paused,e.parentEntity)},GameLib.D3.API.BoneWeight=function(e,t){this.boneIndex=e,this.weight=t},GameLib.D3.API.BoneWeight.FromObject=function(e){return new GameLib.D3.API.BoneWeight(e.boneIndex,e.weight)},GameLib.D3.API.Bone=function(e,t,i,n,a,s,o,r,c){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="Bone ("+this.id+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=[]),this.childBoneIds=i,GameLib.Utils.UndefinedOrNull(n)&&(n=[]),this.parentBoneIds=n,GameLib.Utils.UndefinedOrNull(a)&&(a=new GameLib.API.Vector3),this.position=a,GameLib.Utils.UndefinedOrNull(s)&&(s=new GameLib.API.Quaternion),this.quaternion=s,GameLib.Utils.UndefinedOrNull(o)&&(o=new GameLib.API.Vector3(1,1,1)),this.scale=o,GameLib.Utils.UndefinedOrNull(r)&&(r=new GameLib.API.Vector3(0,1,0)),this.up=r,GameLib.API.Component.call(this,GameLib.Component.BONE,c)},GameLib.D3.API.Bone.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.API.Bone.prototype.constructor=GameLib.D3.API.Bone,GameLib.D3.API.Bone.FromObject=function(e){return new GameLib.D3.API.Bone(e.id,e.name,e.childBoneIds,e.parentBoneIds,GameLib.API.Vector3.FromObject(e.position),GameLib.API.Quaternion.FromObject(e.quaternion),GameLib.API.Vector3.FromObject(e.scale),GameLib.API.Vector3.FromObject(e.up),e.parentEntity)},GameLib.D3.API.Broadphase=function(e,t,i,n){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="Broadphase ("+this.id+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=GameLib.D3.Broadphase.BROADPHASE_TYPE_NAIVE),this.broadphaseType=i,GameLib.API.Component.call(this,GameLib.Component.BROADPHASE,n)},GameLib.D3.API.Broadphase.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.API.Broadphase.prototype.constructor=GameLib.D3.API.Broadphase,GameLib.D3.API.Broadphase.FromObject=function(e){return new GameLib.D3.API.Broadphase(e.id,e.name,e.broadphaseType,e.parentEntity)},GameLib.D3.API.Camera=function(e,t,i,n,a,s,o,r,c,m,h,l,p,u,b,d,L,G,f,E,y){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t=GameLib.D3.Camera.CAMERA_TYPE_PERSPECTIVE),this.cameraType=t,GameLib.Utils.UndefinedOrNull(i)&&(i="Camera ("+this.id+")"),this.name=i,GameLib.Utils.UndefinedOrNull(n)&&(n=75),this.fov=n,GameLib.Utils.UndefinedOrNull(a)&&(a=window.innerWidth/window.innerHeight),this.aspect=a,GameLib.Utils.UndefinedOrNull(s)&&(s=.01),this.near=s,GameLib.Utils.UndefinedOrNull(o)&&(o=1e3),this.far=o,GameLib.Utils.UndefinedOrNull(r)&&(r=new GameLib.API.Vector3(15,15,15)),this.position=r,GameLib.Utils.UndefinedOrNull(G)&&(G=new GameLib.API.Quaternion),this.quaternion=G,GameLib.Utils.UndefinedOrNull(c)&&(c=new GameLib.API.Vector3(0,0,0)),this.lookAt=c,GameLib.Utils.UndefinedOrNull(m)&&(m=-100),this.minX=m,GameLib.Utils.UndefinedOrNull(h)&&(h=100),this.maxX=h,GameLib.Utils.UndefinedOrNull(l)&&(l=-100),this.minY=l,GameLib.Utils.UndefinedOrNull(p)&&(p=100),this.maxY=p,GameLib.Utils.UndefinedOrNull(u)&&(u=-100),this.minZ=u,GameLib.Utils.UndefinedOrNull(b)&&(b=100),this.maxZ=b,GameLib.Utils.UndefinedOrNull(d)&&(d=0),this.offsetX=d,GameLib.Utils.UndefinedOrNull(L)&&(L=0),this.offsetY=L,GameLib.Utils.UndefinedOrNull(f)&&(f=30),this.eyeSeparation=f,GameLib.Utils.UndefinedOrNull(E)&&(E=150),this.focalLength=E,GameLib.API.Component.call(this,GameLib.Component.CAMERA,y)},GameLib.D3.API.Camera.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.API.Camera.prototype.constructor=GameLib.D3.API.Camera,GameLib.D3.API.Camera.FromObject=function(e){return new GameLib.D3.API.Camera(e.id,e.cameraType,e.name,e.fov,e.aspect,e.near,e.far,GameLib.API.Vector3.FromObject(e.position),GameLib.API.Vector3.FromObject(e.lookAt),e.minX,e.maxX,e.minY,e.maxY,e.minZ,e.maxZ,e.offsetX,e.offsetY,GameLib.API.Quaternion.FromObject(e.quaternion),e.eyeSeparation,e.focalLength,e.parentEntity)},GameLib.D3.API.Composer=function(e,t,i,n,a,s){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="Composer ("+e+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=null),this.renderer=i,GameLib.Utils.UndefinedOrNull(n)&&(n=null),this.renderTarget=n,GameLib.Utils.UndefinedOrNull(a)&&(a=[]),this.passes=a,GameLib.API.Component.call(this,GameLib.Component.COMPOSER,s)},GameLib.D3.API.Composer.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.API.Composer.prototype.constructor=GameLib.D3.API.Composer,GameLib.D3.API.Composer.FromObject=function(e){return new GameLib.D3.API.Composer(e.id,e.name,e.renderer,e.renderTarget,e.passes,e.parentEntity)},GameLib.D3.API.Face=function(e,t,i,n,a,s,o,r,c,m,h){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="Face "+e),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=-1),this.v0index=i,GameLib.Utils.UndefinedOrNull(n)&&(n=-1),this.v1index=n,GameLib.Utils.UndefinedOrNull(a)&&(a=-1),this.v2index=a,GameLib.Utils.UndefinedOrNull(s)&&(s=-1),this.materialIndex=s,GameLib.Utils.UndefinedOrNull(o)&&(o=[[]]),this.uvs=o,GameLib.Utils.UndefinedOrNull(r)&&(r=null),this.color=r,GameLib.Utils.UndefinedOrNull(c)&&(c=[]),this.vertexColors=c,GameLib.Utils.UndefinedOrNull(m)&&(m=[]),this.vertexNormals=m,GameLib.Utils.UndefinedOrNull(h)&&(h=null),this.normal=h},GameLib.D3.API.Face.FromObject=function(e){var t=e.uvs.reduce(function(e,t,i){return e[i]=t.reduce(function(e,t){return e.push(GameLib.API.Vector2.FromObject(t)),e},[]),e},[]),i=e.vertexColors.map(function(e){return GameLib.API.Color.FromObject(e)}),n=null;e.color&&(n=GameLib.API.Color.FromObject(e.color));var a=e.vertexNormals.map(function(e){return GameLib.API.Vector3.FromObject(e)}),s=null;return e.normal&&(s=GameLib.API.Vector3.FromObject(e.normal)),new GameLib.D3.API.Face(e.id,e.name,e.v0index,e.v1index,e.v2index,e.materialIndex,t,n,i,a,s)},GameLib.D3.API.Face.prototype.clone=function(){return new GameLib.D3.API.Face(this.id,this.name,this.v0index,this.v1index,this.v2index,this.materialIndex,this.uvs,this.color,this.vertexColors,this.vertexNormals,this.normal)},GameLib.D3.API.Face.prototype.equals=function(e){return this.v0index===e.v0index&&this.v1index===e.v1index&&this.v2index===e.v2index||this.v0index===e.v0index&&this.v1index===e.v2index&&this.v2index===e.v1index||this.v0index===e.v1index&&this.v1index===e.v0index&&this.v2index===e.v2index||this.v0index===e.v1index&&this.v1index===e.v2index&&this.v2index===e.v0index||this.v0index===e.v2index&&this.v1index===e.v0index&&this.v2index===e.v1index||this.v0index===e.v2index&&this.v1index===e.v1index&&this.v2index===e.v0index},GameLib.D3.API.Fog=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="Fog ("+this.id+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=!1),this.exponential=i,GameLib.Utils.UndefinedOrNull(n)&&(n=new GameLib.API.Color(1,1,1,1)),this.color=n,GameLib.Utils.UndefinedOrNull(a)&&(a=1),this.near=a,GameLib.Utils.UndefinedOrNull(s)&&(s=1e3),this.far=s,GameLib.Utils.UndefinedOrNull(o)&&(o=25e-5),this.density=o,GameLib.API.Component.call(this,GameLib.Component.FOG,r)},GameLib.D3.API.Fog.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.API.Fog.prototype.constructor=GameLib.D3.API.Fog,GameLib.D3.API.Fog.FromObject=function(e){return new GameLib.D3.API.Fog(e.id,e.name,e.exponential,e.color,e.near,e.far,e.density,e.parentEntity)},GameLib.D3.API.Font=function(e,t,i,n){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="Font ("+e+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i="/apiRelative/path/to/font"),this.url=i,GameLib.API.Component.call(this,GameLib.Component.FONT,n)},GameLib.D3.API.Font.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.API.Font.prototype.constructor=GameLib.D3.API.Font,GameLib.D3.API.Font.FromObject=function(e){return new GameLib.D3.API.Font(e.id,e.name,e.url,e.parentEntity)},GameLib.D3.API.FrictionContactMaterial=function(e,t,i,n,a,s,o,r,c,m){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="Friction Material ("+this.id+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=[]),this.materials=i,GameLib.Utils.UndefinedOrNull(n)&&(n=.3),this.friction=n,GameLib.Utils.UndefinedOrNull(a)&&(a=.3),this.restitution=a,GameLib.Utils.UndefinedOrNull(s)&&(s=1e7),this.contactEquationStiffness=s,GameLib.Utils.UndefinedOrNull(o)&&(o=3),this.contactEquationRelaxation=o,GameLib.Utils.UndefinedOrNull(r)&&(r=1e7),this.frictionEquationStiffness=r,GameLib.Utils.UndefinedOrNull(c)&&(c=3),this.frictionEquationRelaxation=c,GameLib.API.Component.call(this,GameLib.Component.FRICTION_CONTACT_MATERIAL,m)},GameLib.D3.API.FrictionContactMaterial.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.API.FrictionContactMaterial.prototype.constructor=GameLib.D3.API.FrictionContactMaterial,GameLib.D3.API.FrictionContactMaterial.FromObject=function(e){return new GameLib.D3.API.FrictionContactMaterial(e.id,e.name,e.materials,e.friction,e.restitution,e.contactEquationStiffness,e.contactEquationRelaxation,e.frictionEquationStiffness,e.frictionEquationRelaxation,e.parentEntity)},GameLib.D3.API.FrictionMaterial=function(e,t,i,n,a){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="Friction Material ("+this.id+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=-1),this.friction=i,GameLib.Utils.UndefinedOrNull(n)&&(n=-1),this.restitution=n,GameLib.API.Component.call(this,GameLib.Component.FRICTION_MATERIAL,a)},GameLib.D3.API.FrictionMaterial.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.API.FrictionMaterial.prototype.constructor=GameLib.D3.API.FrictionMaterial,GameLib.D3.API.FrictionMaterial.FromObject=function(e){return new GameLib.D3.API.FrictionMaterial(e.id,e.name,e.friction,e.restitution,e.parentEntity)},GameLib.D3.API.Light=function(e,t,i,n,a,s,o,r,c,m,h,l,p,u,b,d,L){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t=GameLib.D3.Light.LIGHT_TYPE_AMBIENT),this.lightType=t,GameLib.Utils.UndefinedOrNull(i)&&(this.lightType===GameLib.D3.Light.LIGHT_TYPE_AMBIENT&&(i="Ambient "),this.lightType===GameLib.D3.Light.LIGHT_TYPE_DIRECTIONAL&&(i="Directional "),this.lightType===GameLib.D3.Light.LIGHT_TYPE_POINT&&(i="Point "),this.lightType===GameLib.D3.Light.LIGHT_TYPE_SPOT&&(i="Spot "),i+="Light ("+e+")"),this.name=i,GameLib.Utils.UndefinedOrNull(n)&&(n=new GameLib.API.Color(1,1,1,1)),this.color=n,GameLib.Utils.UndefinedOrNull(a)&&(a=1),this.intensity=a,GameLib.Utils.UndefinedOrNull(s)&&(s=new GameLib.API.Vector3(10,10,10)),this.position=s,GameLib.Utils.UndefinedOrNull(o)&&(o=new GameLib.API.Vector3(0,0,0)),this.targetPosition=o,GameLib.Utils.UndefinedOrNull(r)&&(r=new GameLib.API.Quaternion),this.quaternion=r,GameLib.Utils.UndefinedOrNull(c)&&(c=new GameLib.API.Vector3(0,0,0)),this.rotation=c,GameLib.Utils.UndefinedOrNull(m)&&(m=new GameLib.API.Vector3(1,1,1)),this.scale=m,GameLib.Utils.UndefinedOrNull(h)&&(h=0),this.distance=h,GameLib.Utils.UndefinedOrNull(l)&&(l=1),this.decay=l,GameLib.Utils.UndefinedOrNull(p)&&(p=4*Math.PI),this.power=p,GameLib.Utils.UndefinedOrNull(u)&&(u=Math.PI/3),this.angle=u,GameLib.Utils.UndefinedOrNull(b)&&(b=0),this.penumbra=b,GameLib.Utils.UndefinedOrNull(d)&&(d=null),this.parentScene=d,GameLib.API.Component.call(this,GameLib.Component.LIGHT,L)},GameLib.D3.API.Light.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.API.Light.prototype.constructor=GameLib.D3.API.Light,GameLib.D3.API.Light.FromObject=function(e){return new GameLib.D3.API.Light(e.id,e.lightType,e.name,GameLib.API.Color.FromObject(e.color),e.intensity,GameLib.API.Vector3.FromObject(e.position),GameLib.API.Vector3.FromObject(e.targetPosition),GameLib.API.Quaternion.FromObject(e.quaternion),GameLib.API.Vector3.FromObject(e.rotation),GameLib.API.Vector3.FromObject(e.scale),e.distance,e.decay,e.power,e.angle,e.penumbra,e.parentScene,e.parentEntity)},GameLib.D3.API.Material=function(e,t,i,n,a,s,o,r,c,m,h,l,p,u,b,d,L,G,f,E,y,I,P,T,A,O,D,S,g,C,U,N,v,M,_,w,R,x,F,Y,j,V,H,z,B,q,k,W,X,Q,K,Z,J,$,ee,te,ie,ne,ae,se,oe,re,ce,me,he,le,pe,ue,be){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t=GameLib.D3.Material.MATERIAL_TYPE_STANDARD),this.materialType=t,GameLib.Utils.UndefinedOrNull(i)&&(i="Material ("+t+")"),this.name=i,GameLib.Utils.UndefinedOrNull(n)&&(n=1),this.opacity=n,GameLib.Utils.UndefinedOrNull(a)&&(a=GameLib.D3.Material.TYPE_FRONT_SIDE),this.side=a,GameLib.Utils.UndefinedOrNull(s)&&(s=!1),this.transparent=s,GameLib.Utils.UndefinedOrNull(o)&&(o=new GameLib.API.Color(.06,.06,.06,.06)),this.specular=o,GameLib.Utils.UndefinedOrNull(r)&&(r=1),this.lightMapIntensity=r,GameLib.Utils.UndefinedOrNull(c)&&(c=1),this.aoMapIntensity=c,GameLib.Utils.UndefinedOrNull(m)&&(m=new GameLib.API.Color(1,1,1,1)),this.color=m,GameLib.Utils.UndefinedOrNull(h)&&(h=new GameLib.API.Color(0,0,0,0)),this.emissive=h,GameLib.Utils.UndefinedOrNull(l)&&(l=1),this.emissiveIntensity=l,GameLib.Utils.UndefinedOrNull(p)&&(p=GameLib.D3.Material.TYPE_MULTIPLY_OPERATION),this.combine=p,GameLib.Utils.UndefinedOrNull(u)&&(u=30),this.shininess=u,GameLib.Utils.UndefinedOrNull(b)&&(b=1),this.reflectivity=b,GameLib.Utils.UndefinedOrNull(d)&&(d=.98),this.refractionRatio=d,GameLib.Utils.UndefinedOrNull(L)&&(L=!0),this.fog=L,GameLib.Utils.UndefinedOrNull(G)&&(G=!1),this.wireframe=G,GameLib.Utils.UndefinedOrNull(f)&&(f=1),this.wireframeLineWidth=f,GameLib.Utils.UndefinedOrNull(E)&&(E="round"),this.wireframeLineCap=E,GameLib.Utils.UndefinedOrNull(y)&&(y="round"),this.wireframeLineJoin=y,GameLib.Utils.UndefinedOrNull(I)&&(I=GameLib.D3.Material.TYPE_NO_COLORS),this.vertexColors=I,GameLib.Utils.UndefinedOrNull(P)&&(P=!1),this.skinning=P,GameLib.Utils.UndefinedOrNull(T)&&(T=!1),this.morphTargets=T,GameLib.Utils.UndefinedOrNull(A)&&(A=!1),this.morphNormals=A,GameLib.Utils.UndefinedOrNull(B)&&(B=0),this.overdraw=B,GameLib.Utils.UndefinedOrNull(O)&&(O=1),this.lineWidth=O,GameLib.Utils.UndefinedOrNull(D)&&(D="round"),this.lineCap=D,GameLib.Utils.UndefinedOrNull(S)&&(S="round"),this.lineJoin=S,GameLib.Utils.UndefinedOrNull(g)&&(g=3),this.dashSize=g,GameLib.Utils.UndefinedOrNull(C)&&(C=1),this.gapWidth=C,GameLib.Utils.UndefinedOrNull(U)&&(U=GameLib.D3.Material.TYPE_NORMAL_BLENDING),this.blending=U,GameLib.Utils.UndefinedOrNull(N)&&(N=GameLib.D3.Material.TYPE_SRC_ALPHA_FACTOR),this.blendSrc=N,GameLib.Utils.UndefinedOrNull(v)&&(v=GameLib.D3.Material.TYPE_ONE_MINUS_SRC_ALPHA_FACTOR),this.blendDst=v,GameLib.Utils.UndefinedOrNull(M)&&(M=GameLib.D3.Material.TYPE_ADD_EQUATION),this.blendEquation=M,GameLib.Utils.UndefinedOrNull(_)&&(_=!0),this.depthTest=_,GameLib.Utils.UndefinedOrNull(w)&&(w=GameLib.D3.Material.TYPE_LESS_EQUAL_DEPTH),this.depthFunc=w,GameLib.Utils.UndefinedOrNull(R)&&(R=!0),this.depthWrite=R,GameLib.Utils.UndefinedOrNull(x)&&(x=!1),this.polygonOffset=x,GameLib.Utils.UndefinedOrNull(F)&&(F=1),this.polygonOffsetFactor=F,GameLib.Utils.UndefinedOrNull(Y)&&(Y=1),this.polygonOffsetUnits=Y,GameLib.Utils.UndefinedOrNull(j)&&(j=0),this.alphaTest=j,GameLib.Utils.UndefinedOrNull(V)&&(V=[]),this.clippingPlanes=V,GameLib.Utils.UndefinedOrNull(H)&&(H=!1),this.clipShadows=H,GameLib.Utils.UndefinedOrNull(z)&&(z=!0),this.visible=z,GameLib.Utils.UndefinedOrNull(q)&&(q=!1),this.flatShading=q,GameLib.Utils.UndefinedOrNull(k)&&(k=1),this.bumpScale=k,GameLib.Utils.UndefinedOrNull(W)&&(W=1),this.normalScale=W,GameLib.Utils.UndefinedOrNull(X)&&(X=1),this.displacementScale=X,GameLib.Utils.UndefinedOrNull(Q)&&(Q=0),this.displacementBias=Q,GameLib.Utils.UndefinedOrNull(K)&&(K=.5),this.roughness=K,GameLib.Utils.UndefinedOrNull(Z)&&(Z=.5),this.metalness=Z,GameLib.Utils.UndefinedOrNull(J)&&(J=1),this.pointSize=J,GameLib.Utils.UndefinedOrNull($)&&($=!0),this.pointSizeAttenuation=$,GameLib.Utils.UndefinedOrNull(ee)&&(ee=0),this.spriteRotation=ee,GameLib.Utils.UndefinedOrNull(te)&&(te=1),this.envMapIntensity=te,GameLib.Utils.UndefinedOrNull(ie)&&(ie=null),this.alphaMap=ie,GameLib.Utils.UndefinedOrNull(ne)&&(ne=null),this.aoMap=ne,GameLib.Utils.UndefinedOrNull(ae)&&(ae=null),this.bumpMap=ae,GameLib.Utils.UndefinedOrNull(se)&&(se=null),this.diffuseMap=se,GameLib.Utils.UndefinedOrNull(oe)&&(oe=null),this.displacementMap=oe,GameLib.Utils.UndefinedOrNull(re)&&(re=null),this.emissiveMap=re,GameLib.Utils.UndefinedOrNull(ce)&&(ce=null),this.environmentMap=ce,GameLib.Utils.UndefinedOrNull(me)&&(me=null),this.lightMap=me,GameLib.Utils.UndefinedOrNull(he)&&(he=null),this.metalnessMap=he,GameLib.Utils.UndefinedOrNull(le)&&(le=null),this.normalMap=le,GameLib.Utils.UndefinedOrNull(pe)&&(pe=null),this.roughnessMap=pe,GameLib.Utils.UndefinedOrNull(ue)&&(ue=null),this.specularMap=ue,GameLib.API.Component.call(this,GameLib.Component.MATERIAL,be),this.needsUpdate=!1},GameLib.D3.API.Material.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.API.Material.prototype.constructor=GameLib.D3.API.Material,GameLib.D3.API.Material.FromObject=function(e){var t=null,i=null,n=null,a=null,s=null,o=null,r=null,c=null,m=null,h=null,l=null,p=null;return e.alphaMap&&(t=e.alphaMap),e.aoMap&&(i=e.aoMap),e.bumpMap&&(n=e.bumpMap),e.diffuseMap&&(a=e.diffuseMap),e.displacementMap&&(s=e.displacementMap),e.emissiveMap&&(o=e.emissiveMap),e.environmentMap&&(r=e.environmentMap),e.lightMap&&(c=e.lightMap),e.metalnessMap&&(m=e.metalnessMap),e.normalMap&&(h=e.normalMap),e.roughnessMap&&(l=e.roughnessMap),e.specularMap&&(p=e.specularMap),new GameLib.D3.API.Material(e.id,e.materialType,e.name,e.opacity,e.side,e.transparent,GameLib.API.Color.FromObject(e.specular),e.lightMapIntensity,e.aoMapIntensity,GameLib.API.Color.FromObject(e.color),GameLib.API.Color.FromObject(e.emissive),e.emissiveIntensity,e.combine,e.shininess,e.reflectivity,e.refractionRatio,e.fog,e.wireframe,e.wireframeLineWidth,e.wireframeLineCap,e.wireframeLineJoin,e.vertexColors,e.skinning,e.morphTargets,e.morphNormals,e.lineWidth,e.lineCap,e.lineJoin,e.dashSize,e.gapWidth,e.blending,e.blendSrc,e.blendDst,e.blendEquation,e.depthTest,e.depthFunc,e.depthWrite,e.polygonOffset,e.polygonOffsetFactor,e.polygonOffsetUnits,e.alphaTest,e.clippingPlanes,e.clipShadows,e.visible,e.overdraw,e.flatShading,e.bumpScale,e.normalScale,e.displacementScale,e.displacementBias,e.roughness,e.metalness,e.pointSize,e.pointSizeAttenuation,e.spriteRotation,e.envMapIntensity,t,i,n,a,s,o,r,c,m,h,l,p,e.parentEntity)},GameLib.D3.API.Mesh=function(e,t,i,n,a,s,o,r,c,m,h,l,p,u,b,d,L,G,f,E,y,I){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t=GameLib.D3.API.Mesh.MESH_TYPE_NORMAL),this.meshType=t,GameLib.Utils.UndefinedOrNull(i)&&(i="Mesh ("+e+")"),this.name=i,GameLib.Utils.UndefinedOrNull(n)&&(n=[]),this.vertices=n,GameLib.Utils.UndefinedOrNull(a)&&(a=[]),this.faces=a,GameLib.Utils.UndefinedOrNull(o)&&(o=null),this.parentMesh=o,GameLib.Utils.UndefinedOrNull(r)&&(r=null),this.parentScene=r,GameLib.Utils.UndefinedOrNull(c)&&(c=null),this.skeleton=c,GameLib.Utils.UndefinedOrNull(m)&&(m=[]),this.skinIndices=m,GameLib.Utils.UndefinedOrNull(h)&&(h=[]),this.skinWeights=h,(GameLib.Utils.UndefinedOrNull(s)||s instanceof Array&&0===s.length)&&(s=[new GameLib.D3.API.Material(null,GameLib.D3.Material.MATERIAL_TYPE_STANDARD,"Material ("+this.name+")")]),this.materials=s,GameLib.Utils.UndefinedOrNull(l)&&(l=new GameLib.API.Vector3(0,0,0)),this.position=l,GameLib.Utils.UndefinedOrNull(p)&&(p=new GameLib.API.Quaternion),this.quaternion=p,GameLib.Utils.UndefinedOrNull(u)&&(u=new GameLib.API.Vector3(0,0,0)),this.rotation=u,GameLib.Utils.UndefinedOrNull(b)&&(b=new GameLib.API.Vector3(1,1,1)),this.scale=b,GameLib.Utils.UndefinedOrNull(d)&&(d=new GameLib.API.Vector3(0,1,0)),this.up=d,GameLib.Utils.UndefinedOrNull(L)&&(L=new GameLib.API.Matrix4),this.modelMatrix=L,GameLib.Utils.UndefinedOrNull(G)&&(G=0), +this.renderOrder=G,GameLib.Utils.UndefinedOrNull(f)&&(f=!1),this.isBufferMesh=f,GameLib.Utils.UndefinedOrNull(E)&&(E=!0),this.useQuaternion=E,GameLib.Utils.UndefinedOrNull(y)&&(y=!0),this.visible=y;var P=GameLib.Component.MESH;this.meshType===GameLib.D3.API.Mesh.MESH_TYPE_PLANE&&(P=GameLib.Component.MESH_PLANE),this.meshType===GameLib.D3.API.Mesh.MESH_TYPE_BOX&&(P=GameLib.Component.MESH_BOX),this.meshType===GameLib.D3.API.Mesh.MESH_TYPE_CYLINDER&&(P=GameLib.Component.MESH_CYLINDER),this.meshType===GameLib.D3.API.Mesh.MESH_TYPE_SPHERE&&(P=GameLib.Component.MESH_SPHERE),this.meshType===GameLib.D3.API.Mesh.MESH_TYPE_LINE&&(P=GameLib.Component.MESH_LINE),this.meshType===GameLib.D3.API.Mesh.MESH_TYPE_TEXT&&(P=GameLib.Component.MESH_TEXT),GameLib.API.Component.call(this,P,I)},GameLib.D3.API.Mesh.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.API.Mesh.prototype.constructor=GameLib.D3.API.Mesh,GameLib.D3.API.Mesh.MESH_TYPE_NORMAL=0,GameLib.D3.API.Mesh.MESH_TYPE_SKINNED=1,GameLib.D3.API.Mesh.MESH_TYPE_CURVE=2,GameLib.D3.API.Mesh.MESH_TYPE_SPHERE=3,GameLib.D3.API.Mesh.MESH_TYPE_PLANE=4,GameLib.D3.API.Mesh.MESH_TYPE_BOX=5,GameLib.D3.API.Mesh.MESH_TYPE_CYLINDER=6,GameLib.D3.API.Mesh.MESH_TYPE_TEXT=7,GameLib.D3.API.Mesh.MESH_TYPE_LINE=8,GameLib.D3.API.Mesh.FromObject=function(e){var t=[];e.faces&&(t=e.faces.map(function(e){return GameLib.D3.API.Face.FromObject(e)}));var i=null;e.skeleton&&(i=GameLib.D3.API.Skeleton.FromObject(e.skeleton));var n=[];e.materials&&(n=e.materials.map(function(e){return e instanceof Object?GameLib.D3.API.Material.FromObject(e):e}));var a=[];e.vertices&&(a=e.vertices.map(function(e){return GameLib.D3.API.Vertex.FromObject(e)}));var s=new GameLib.API.Vector3;e.position&&(s=GameLib.API.Vector3.FromObject(e.position));var o=new GameLib.API.Vector3;e.rotation&&(o=GameLib.API.Vector3.FromObject(e.rotation));var r=new GameLib.API.Quaternion;e.quaternion&&(r=GameLib.API.Quaternion.FromObject(e.quaternion));var c=new GameLib.API.Vector3(1,1,1);e.scale&&(c=GameLib.API.Vector3.FromObject(e.scale));var m=new GameLib.API.Vector3(0,1,0);e.up&&(m=GameLib.API.Vector3.FromObject(e.up));var h=new GameLib.API.Matrix4;return e.modelMatrix&&(h=GameLib.API.Matrix4.FromObject(e.modelMatrix)),new GameLib.D3.API.Mesh(e.id,e.meshType,e.name,a,t,n,e.parentMesh,e.parentScene,i,e.skinIndices,e.skinWeights,s,r,o,c,m,h,e.renderOrder,e.isBufferMesh,e.useQuaternion,e.visible,e.parentEntity)},GameLib.D3.API.ParticleEngine=function(e,t,i,n,a,s,o,r,c,m,h,l){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="ParticleEngine ("+this.id+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=new GameLib.API.Vector3(0,0,0)),this.position=i,GameLib.Utils.UndefinedOrNull(n)&&(n=new GameLib.API.Vector3(0,1,0)),this.direction=n,GameLib.Utils.UndefinedOrNull(a)&&(a=!1),this.enabled=a,GameLib.Utils.UndefinedOrNull(s)&&(s=null),this.templateParticle=s,GameLib.Utils.UndefinedOrNull(o)&&(o=1),this.particlesPerSecond=o,GameLib.Utils.UndefinedOrNull(r)&&(r=Number(1/Number(this.particlesPerSecond))),this.frequency=r,GameLib.Utils.UndefinedOrNull(c)&&(c=0),this.elapsed=c,GameLib.Utils.UndefinedOrNull(m)&&(m=null),this.camera=m,GameLib.Utils.UndefinedOrNull(h)&&(h=!1),this.pulse=h,GameLib.API.Component.call(this,GameLib.Component.PARTICLE_ENGINE,l)},GameLib.D3.API.ParticleEngine.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.API.ParticleEngine.prototype.constructor=GameLib.D3.API.ParticleEngine,GameLib.D3.API.ParticleEngine.FromObject=function(e){var t=null;e.templateParticle&&(t=e.templateParticle instanceof Object?GameLib.D3.API.Particle.FromObject(e.templateParticle):e.templateParticle);var i=null;e.camera&&(i=e.camera instanceof Object?GameLib.D3.API.Camera.FromObject(e.camera):e.camera);var n=null;e.position&&(n=GameLib.API.Vector3.FromObject(e.position));var a=null;return e.direction&&(a=GameLib.API.Vector3.FromObject(e.direction)),new GameLib.D3.API.ParticleEngine(e.id,e.name,n,a,e.enabled,t,e.particlesPerSecond,e.frequency,e.elapsed,i,e.pulse,e.parentEntity)},GameLib.D3.API.Particle=function(e,t,i,n,a,s,o,r,c,m,h,l,p,u,b,d,L,G,f,E,y,I,P){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="Particle ("+this.id+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=10),this.lifeTime=i,GameLib.Utils.UndefinedOrNull(n)&&(n=0),this.elapsed=n,GameLib.Utils.UndefinedOrNull(a)&&(a=null),this.mesh=a,GameLib.Utils.UndefinedOrNull(s)&&(s=GameLib.D3.Particle.OPACITY_TYPE_CONSTANT),this.opacityType=s,GameLib.Utils.UndefinedOrNull(o)&&(o=.01),this.opacityFactor=o,GameLib.Utils.UndefinedOrNull(r)&&(r=GameLib.D3.Particle.POSITION_OFFSET_TYPE_CONSTANT),this.positionOffsetType=r,GameLib.Utils.UndefinedOrNull(c)&&(c=new GameLib.API.Vector3(0,0,0)),this.positionOffset=c,GameLib.Utils.UndefinedOrNull(m)&&(m="//@ sourceURL=positionOffsetFn.js"),this.positionOffsetFn=m,GameLib.Utils.UndefinedOrNull(h)&&(h=GameLib.D3.Particle.DIRECTION_TYPE_CONSTANT),this.directionType=h,GameLib.Utils.UndefinedOrNull(l)&&(l=new GameLib.API.Vector3(0,1,0)),this.direction=l,GameLib.Utils.UndefinedOrNull(p)&&(p="//@ sourceURL=directionFn.js"),this.directionFn=p,GameLib.Utils.UndefinedOrNull(u)&&(u=GameLib.D3.Particle.SPEED_TYPE_CONSTANT),this.speedType=u,GameLib.Utils.UndefinedOrNull(b)&&(b=1),this.speed=b,GameLib.Utils.UndefinedOrNull(d)&&(d=GameLib.D3.Particle.SCALE_TYPE_CONSTANT),this.scaleType=d,GameLib.Utils.UndefinedOrNull(L)&&(L=new GameLib.API.Vector3(1,1,1)),this.scale=L,GameLib.Utils.UndefinedOrNull(G)&&(G="//@ sourceURL=scaleFn.js"),this.scaleFn=G,GameLib.Utils.UndefinedOrNull(f)&&(f=GameLib.D3.Particle.ROTATION_TYPE_CONSTANT),this.rotationType=f,GameLib.Utils.UndefinedOrNull(E)&&(E=new GameLib.API.Vector3(0,0,0)),this.rotation=E,GameLib.Utils.UndefinedOrNull(y)&&(y="//@ sourceURL=rotationFn.js"),this.rotationFn=y,GameLib.Utils.UndefinedOrNull(I)&&(I=null),this.parentEngine=I,GameLib.API.Component.call(this,GameLib.Component.PARTICLE,P)},GameLib.D3.API.Particle.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.API.Particle.prototype.constructor=GameLib.D3.API.Particle,GameLib.D3.API.Particle.FromObject=function(e){var t=null;return e.mesh&&(t=e.mesh instanceof Object?GameLib.D3.API.Mesh.FromObject(e.mesh):e.mesh),new GameLib.D3.API.Particle(e.id,e.name,e.lifeTime,e.elapsed,t,e.opacityType,e.opacityFactor,e.positionOffsetType,GameLib.API.Vector3.FromObject(e.positionOffset),e.positionOffsetFn,e.directionType,GameLib.API.Vector3.FromObject(e.direction),e.directionFn,e.speedType,e.speed,e.scaleType,GameLib.API.Vector3.FromObject(e.scale),e.scaleFn,e.rotationType,GameLib.API.Vector3.FromObject(e.rotation),e.rotationFn,e.parentEngine,e.parentEntity)},GameLib.D3.API.Pass=function(e,t,i,n,a,s,o){if(GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="Pass ("+e+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=GameLib.D3.Pass.PASS_TYPE_RENDER),this.passType=i,GameLib.Utils.UndefinedOrNull(n)&&(n=null),this.camera=n,GameLib.Utils.UndefinedOrNull(a)&&(a=null),this.scene=a,GameLib.Utils.UndefinedOrNull(s))if(this.passType===GameLib.D3.Pass.PASS_TYPE_RENDER)s=!1;else{if(!GameLib.D3.Pass.PASS_TYPE_COPY_SHADER)throw console.warn("Unsupported Render Pass Type : "+this.passType),new Error("Unsupported Render Pass Type : "+this.passType);s=!0}this.renderToScreen=s,GameLib.API.Component.call(this,GameLib.Component.PASS,o)},GameLib.D3.API.Pass.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.API.Pass.prototype.constructor=GameLib.D3.API.Pass,GameLib.D3.API.Pass.FromObject=function(e){return new GameLib.D3.API.Pass(e.id,e.name,e.passType,e.camera,e.scene,e.renderToScreen,e.parentEntity)},GameLib.D3.API.PhysicsWorld=function(e,t,i,n,a,s,o,r,c,m){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="Physics World ("+this.id+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=new GameLib.API.Vector3(0,-9.81,0)),this.gravity=i,GameLib.Utils.UndefinedOrNull(n)&&(n=new GameLib.D3.API.Broadphase(null,"Broadphase (Physics World "+this.id+")")),this.broadphase=n,GameLib.Utils.UndefinedOrNull(a)&&(a=new GameLib.D3.API.Solver(null,"Solver (Physics World "+this.id+")")),this.solver=a,GameLib.Utils.UndefinedOrNull(s)&&(s=[]),this.rigidBodies=s,GameLib.Utils.UndefinedOrNull(o)&&(o=[]),this.contactMaterials=o,GameLib.Utils.UndefinedOrNull(r)&&(r=!0),this.allowSleep=r,GameLib.Utils.UndefinedOrNull(c)&&(c=new GameLib.D3.API.FrictionContactMaterial(null,"Default Contact Material (Physics World "+this.id+")")),this.defaultContactMaterial=c,GameLib.API.Component.call(this,GameLib.Component.PHYSICS_WORLD,m)},GameLib.D3.API.PhysicsWorld.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.API.PhysicsWorld.prototype.constructor=GameLib.D3.API.PhysicsWorld,GameLib.D3.API.PhysicsWorld.FromObject=function(e){return new GameLib.D3.API.PhysicsWorld(e.id,e.name,GameLib.API.Vector3.FromObject(e.gravity),e.broadphase,e.solver,e.rigidBodies,e.contactMaterials,e.allowSleep,e.defaultContactMaterial,e.parentEntity)},GameLib.D3.API.RaycastVehicle=function(e,t,i,n,a,s,o){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="RaycastVehicle ("+this.id+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=null),this.chassis=i,GameLib.Utils.UndefinedOrNull(n)&&(n=[]),this.wheels=n,GameLib.Utils.UndefinedOrNull(a)&&(a=[]),this.raycastWheels=a,GameLib.Utils.UndefinedOrNull(s)&&(s=null),this.parentPhysicsWorld=s,GameLib.API.Component.call(this,GameLib.Component.RAYCAST_VEHICLE,o)},GameLib.D3.API.RaycastVehicle.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.API.RaycastVehicle.prototype.constructor=GameLib.D3.API.RaycastVehicle,GameLib.D3.API.RaycastVehicle.FromObject=function(e){return new GameLib.D3.API.RaycastVehicle(e.id,e.name,e.chassis,e.wheels,e.raycastWheels,e.parentPhysicsWorld,e.parentEntity)},GameLib.D3.API.RaycastWheel=function(e,t,i,n,a,s,o,r,c,m,h,l,p,u,b,d,L,G){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="RaycastWheel ("+this.id+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=.5),this.radius=i,GameLib.Utils.UndefinedOrNull(n)&&(n=new GameLib.API.Vector3(0,0,-1)),this.directionLocal=n,GameLib.Utils.UndefinedOrNull(a)&&(a=30),this.suspensionStiffness=a,GameLib.Utils.UndefinedOrNull(s)&&(s=.3),this.suspensionRestLength=s,GameLib.Utils.UndefinedOrNull(o)&&(o=5),this.frictionSlip=o,GameLib.Utils.UndefinedOrNull(r)&&(r=2.3),this.dampingRelaxation=r,GameLib.Utils.UndefinedOrNull(c)&&(c=4.4),this.dampingCompression=c,GameLib.Utils.UndefinedOrNull(m)&&(m=1e5),this.maxSuspensionForce=m,GameLib.Utils.UndefinedOrNull(h)&&(h=.01),this.rollInfluence=h,GameLib.Utils.UndefinedOrNull(l)&&(l=new GameLib.API.Vector3(0,1,0)),this.axleLocal=l,GameLib.Utils.UndefinedOrNull(p)&&(p=new GameLib.API.Vector3(1,1,0)),this.chassisConnectionPointLocal=p,GameLib.Utils.UndefinedOrNull(u)&&(u=.3),this.maxSuspensionTravel=u,GameLib.Utils.UndefinedOrNull(b)&&(b=-30),this.customSlidingRotationalSpeed=b,GameLib.Utils.UndefinedOrNull(d)&&(d=!0),this.useCustomSlidingRotationalSpeed=d,GameLib.Utils.UndefinedOrNull(L)&&(L=null),this.parentMesh=L,GameLib.API.Component.call(this,GameLib.Component.RAYCAST_WHEEL,G)},GameLib.D3.API.RaycastWheel.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.API.RaycastWheel.prototype.constructor=GameLib.D3.API.RaycastWheel,GameLib.D3.API.RaycastWheel.FromObject=function(e){return new GameLib.D3.API.RaycastWheel(e.id,e.name,e.radius,e.directionLocal,e.suspensionStiffness,e.suspensionRestLength,e.frictionSlip,e.dampingRelaxation,e.dampingCompression,e.maxSuspensionForce,e.rollInfluence,e.axleLocal,e.chassisConnectionPointLocal,e.maxSuspensionTravel,e.customSlidingRotationalSpeed,e.useCustomSlidingRotationalSpeed,e.parentMesh,e.parentEntity)},GameLib.D3.API.Raycaster=function(e,t,i,n,a){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="Raycaster ("+this.id+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=new GameLib.API.Vector3),this.position=i,GameLib.Utils.UndefinedOrNull(n)&&(n=new GameLib.API.Vector3(0,-1,0)),this.direction=n,GameLib.API.Component.call(this,GameLib.Component.RAYCASTER,a)},GameLib.D3.API.Raycaster.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.API.Raycaster.prototype.constructor=GameLib.D3.API.Raycaster,GameLib.D3.API.Raycaster.FromObject=function(e){return new GameLib.D3.API.Raycaster(e.id,e.name,GameLib.API.Vector3.FromObject(e.position),GameLib.API.Vector3.FromObject(e.direction),e.parentEntity)},GameLib.D3.API.RenderTarget=function(e,t,i,n,a,s,o){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="Render Target ("+e+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=800),this.width=i,GameLib.Utils.UndefinedOrNull(n)&&(n=600),this.height=n,GameLib.Utils.UndefinedOrNull(a)&&(a=!1),this.stencilBuffer=a,GameLib.Utils.UndefinedOrNull(s)&&(s=null),this.texture=s,GameLib.API.Component.call(this,GameLib.Component.RENDER_TARGET,o)},GameLib.D3.API.RenderTarget.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.API.RenderTarget.prototype.constructor=GameLib.D3.API.RenderTarget,GameLib.D3.API.RenderTarget.FromObject=function(e){return new GameLib.D3.API.RenderTarget(e.id,e.name,e.width,e.height,e.stencilBuffer,e.texture,e.parentEntity)},GameLib.D3.API.Renderer=function(e,t,i,n,a,s,o,r,c,m,h,l,p,u,b,d,L,G,f){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="Renderer ("+this.id+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=!0),this.autoClear=i,GameLib.Utils.UndefinedOrNull(n)&&(n=!1,p&&p.length>0&&(n=!0)),this.localClipping=n,GameLib.Utils.UndefinedOrNull(a)&&(a=800),this.width=a,GameLib.Utils.UndefinedOrNull(s)&&(s=600),this.height=s,GameLib.Utils.UndefinedOrNull(o)&&(o=!1),this.preserveDrawingBuffer=o,GameLib.Utils.UndefinedOrNull(r)&&(r=null),this.domElement=r,GameLib.Utils.UndefinedOrNull(c)&&(c=new GameLib.API.Color(.11,.11,.11)),this.clearColor=c,GameLib.Utils.UndefinedOrNull(m)&&(m=null),this.camera=m,GameLib.Utils.UndefinedOrNull(h)&&(h=[]),this.scenes=h,GameLib.Utils.UndefinedOrNull(l)&&(l=[]),this.viewports=l,GameLib.Utils.UndefinedOrNull(p)&&(p=[]),this.clippingPlanes=p,GameLib.Utils.UndefinedOrNull(u)&&(u=null),this.bufferScene=u,GameLib.Utils.UndefinedOrNull(b)&&(b=m),this.bufferCamera=b,GameLib.Utils.UndefinedOrNull(d)&&(d=null),this.renderTarget=d,GameLib.Utils.UndefinedOrNull(L)&&(L=null),this.defaultScene=L,GameLib.Utils.UndefinedOrNull(G)&&(G=!0),this.sortObjects=G,GameLib.API.Component.call(this,GameLib.Component.RENDERER,f)},GameLib.D3.API.Renderer.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.API.Renderer.prototype.constructor=GameLib.D3.API.Renderer,GameLib.D3.API.Renderer.FromObject=function(e){return new GameLib.D3.API.Renderer(e.id,e.name,e.autoClear,e.localClipping,e.width,e.height,e.preserveDrawingBuffer,e.domElement,e.clearColor,e.camera,e.scenes,e.viewports,e.clippingPlanes,e.bufferScene,e.bufferCamera,e.renderTarget,e.defaultScene,e.sortObjects,e.parentEntity)},GameLib.D3.API.RigidBody=function(e,t,i,n,a,s,o,r,c,m,h,l,p,u,b,d,L,G,f,E,y){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="RigidBody ("+this.id+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=0),this.mass=i,GameLib.Utils.UndefinedOrNull(n)&&(n=5),this.friction=n,GameLib.Utils.UndefinedOrNull(a)&&(a=new GameLib.API.Vector3(0,0,0)),this.position=a,GameLib.Utils.UndefinedOrNull(s)&&(s=new GameLib.API.Quaternion),this.quaternion=s,GameLib.Utils.UndefinedOrNull(o)&&(o=new GameLib.API.Vector3),this.velocity=o,GameLib.Utils.UndefinedOrNull(r)&&(r=new GameLib.API.Vector3),this.angularVelocity=r,GameLib.Utils.UndefinedOrNull(c)&&(c=.01),this.linearDamping=c,GameLib.Utils.UndefinedOrNull(m)&&(m=.01),this.angularDamping=m,GameLib.Utils.UndefinedOrNull(h)&&(h=!0),this.allowSleep=h,GameLib.Utils.UndefinedOrNull(l)&&(l=.1),this.sleepSpeedLimit=l,GameLib.Utils.UndefinedOrNull(p)&&(p=1),this.sleepTimeLimit=p,GameLib.Utils.UndefinedOrNull(u)&&(u=1),this.collisionFilterGroup=u,GameLib.Utils.UndefinedOrNull(b)&&(b=1),this.collisionFilterMask=b,GameLib.Utils.UndefinedOrNull(d)&&(d=!1),this.fixedRotation=d,GameLib.Utils.UndefinedOrNull(L)&&(L=[]),this.shapes=L,GameLib.Utils.UndefinedOrNull(G)&&(G=!1),this.kinematic=G,GameLib.Utils.UndefinedOrNull(f)&&(f=null),this.parentMesh=f,GameLib.Utils.UndefinedOrNull(E)&&(E=null),this.parentPhysicsWorld=E,GameLib.API.Component.call(this,GameLib.Component.RIGID_BODY,y)},GameLib.D3.API.RigidBody.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.API.RigidBody.prototype.constructor=GameLib.D3.API.RigidBody,GameLib.D3.API.RigidBody.FromObject=function(e){return new GameLib.D3.API.RigidBody(e.id,e.name,e.mass,e.friction,e.position,e.quaternion,e.velocity,e.angularVelocity,e.linearDamping,e.angularDamping,e.allowSleep,e.sleepSpeedLimit,e.sleepTimeLimit,e.collisionFilterGroup,e.collisionFilterMask,e.fixedRotation,e.shapes,e.kinematic,e.parentMesh,e.parentPhysicsWorld,e.parentEntity)},GameLib.D3.API.Scene=function(e,t,i,n,a,s,o,r,c,m,h,l,p,u){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="Scene ("+this.id+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=[]),this.meshes=i,GameLib.Utils.UndefinedOrNull(n)&&(n=[]),this.lights=n,GameLib.Utils.UndefinedOrNull(a)&&(a=[]),this.textures=a,GameLib.Utils.UndefinedOrNull(s)&&(s=[]),this.materials=s,GameLib.Utils.UndefinedOrNull(o)&&(o=[]),this.images=o,GameLib.Utils.UndefinedOrNull(r)&&(r=null),this.fog=r,GameLib.Utils.UndefinedOrNull(c)&&(c=null),this.renderCamera=c,GameLib.Utils.UndefinedOrNull(m)&&(m=!0),this.showGrid=m,GameLib.Utils.UndefinedOrNull(h)&&(h=!0),this.showAxis=h,GameLib.Utils.UndefinedOrNull(l)&&(l=10),this.gridSize=l,GameLib.Utils.UndefinedOrNull(p)&&(p=new GameLib.API.Color(.1,.1,.1)),this.gridColor=p,GameLib.API.Component.call(this,GameLib.Component.SCENE,u)},GameLib.D3.API.Scene.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.API.Scene.prototype.constructor=GameLib.D3.API.Scene,GameLib.D3.API.Scene.FromObject=function(e){var t=[],i=[],n=[],a=[],s=[];return e.meshes&&(t=e.meshes.map(function(e){return e instanceof Object?GameLib.D3.API.Mesh.FromObject(e):e})),e.lights&&(i=e.lights.map(function(e){return e instanceof Object?GameLib.D3.API.Light.FromObject(e):e})),e.textures&&(n=e.textures.map(function(e){return e instanceof Object?GameLib.D3.API.Texture.FromObject(e):e})),e.materials&&(a=e.materials.map(function(e){return e instanceof Object?GameLib.D3.API.Material.FromObject(e):e})),e.images&&(s=e.images.map(function(e){return e instanceof Object?GameLib.API.Image.FromObject(e):e})),new GameLib.D3.API.Scene(e.id,e.name,t,i,n,a,s,e.fog,e.renderCamera,e.showGrid,e.showAxis,e.gridSize,GameLib.API.Color.FromObject(e.gridColor),e.parentEntity)},GameLib.D3.API.Shape=function(e,t,i,n,a,s,o,r){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(i)&&(i=GameLib.D3.API.Shape.SHAPE_TYPE_NONE),this.shapeType=i,GameLib.Utils.UndefinedOrNull(t)&&(t="Shape ("+this.id+")",this.shapeType===GameLib.D3.API.Shape.SHAPE_TYPE_BOX&&(t="Shape Box ("+this.id+")"),this.shapeType===GameLib.D3.API.Shape.SHAPE_TYPE_CONVEX_HULL&&(t="Shape Convex Hull ("+this.id+")"),this.shapeType===GameLib.D3.API.Shape.SHAPE_TYPE_CONVEX_HULL_CYLINDER&&(t="Shape Convex Hull Cylinder ("+this.id+")"),this.shapeType===GameLib.D3.API.Shape.SHAPE_TYPE_HEIGHT_MAP&&(t="Shape HeightMap ("+this.id+")"),this.shapeType===GameLib.D3.API.Shape.SHAPE_TYPE_PLANE&&(t="Shape Plane ("+this.id+")"),this.shapeType===GameLib.D3.API.Shape.SHAPE_TYPE_SPHERE&&(t="Shape Sphere ("+this.id+")"),this.shapeType===GameLib.D3.API.Shape.SHAPE_TYPE_TRIMESH&&(t="Shape TriMesh ("+this.id+")")),this.name=t,GameLib.Utils.UndefinedOrNull(n)&&(n=0),this.boundingSphereRadius=n,GameLib.Utils.UndefinedOrNull(a)&&(a=!0),this.collisionResponse=a,GameLib.Utils.UndefinedOrNull(s)&&(s=null),this.frictionMaterial=s,GameLib.Utils.UndefinedOrNull(o)&&(o=null),this.parentMesh=o;var c=GameLib.Component.SHAPE;this.shapeType===GameLib.D3.API.Shape.SHAPE_TYPE_BOX&&(c=GameLib.Component.SHAPE_BOX),this.shapeType===GameLib.D3.API.Shape.SHAPE_TYPE_CONVEX_HULL&&(c=GameLib.Component.SHAPE_CONVEX_HULL),this.shapeType===GameLib.D3.API.Shape.SHAPE_TYPE_CONVEX_HULL_CYLINDER&&(c=GameLib.Component.SHAPE_CONVEX_HULL_CYLINDER),this.shapeType===GameLib.D3.API.Shape.SHAPE_TYPE_HEIGHT_MAP&&(c=GameLib.Component.SHAPE_HEIGHT_MAP),this.shapeType===GameLib.D3.API.Shape.SHAPE_TYPE_PLANE&&(c=GameLib.Component.SHAPE_PLANE),this.shapeType===GameLib.D3.API.Shape.SHAPE_TYPE_SPHERE&&(c=GameLib.Component.SHAPE_SPHERE),this.shapeType===GameLib.D3.API.Shape.SHAPE_TYPE_TRIMESH&&(c=GameLib.Component.SHAPE_TRI_MESH),GameLib.API.Component.call(this,c,r)},GameLib.D3.API.Shape.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.API.Shape.prototype.constructor=GameLib.D3.API.Shape,GameLib.D3.API.Shape.SHAPE_TYPE_NONE=0,GameLib.D3.API.Shape.SHAPE_TYPE_BOX=1,GameLib.D3.API.Shape.SHAPE_TYPE_CONVEX_HULL=2,GameLib.D3.API.Shape.SHAPE_TYPE_CONVEX_HULL_CYLINDER=3,GameLib.D3.API.Shape.SHAPE_TYPE_HEIGHT_MAP=4,GameLib.D3.API.Shape.SHAPE_TYPE_PLANE=5,GameLib.D3.API.Shape.SHAPE_TYPE_SPHERE=6,GameLib.D3.API.Shape.SHAPE_TYPE_TRIMESH=7,GameLib.D3.API.Shape.FromObject=function(e){return new GameLib.D3.API.Shape(e.id,e.name,e.shapeType,e.boundingSphereRadius,e.collisionResponse,e.frictionMaterial,e.parentMesh,e.parentEntity)},GameLib.D3.API.Skeleton=function(e,t,i,n,a,s,o,r,c,m){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="Skeleton"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=[]),this.bones=i,GameLib.Utils.UndefinedOrNull(n)&&(n=[]),this.boneInverses=n,GameLib.Utils.UndefinedOrNull(a)&&(a=!1),this.useVertexTexture=a,a&&console.warn("support for vertex texture bones is not supported yet - something could break somewhere"),GameLib.Utils.UndefinedOrNull(s)&&(s=0),this.boneTextureWidth=s,GameLib.Utils.UndefinedOrNull(o)&&(o=0),this.boneTextureHeight=o,GameLib.Utils.UndefinedOrNull(r)&&(r=[]),this.boneMatrices=r,GameLib.Utils.UndefinedOrNull(c)&&(c=null),this.boneTexture=c,GameLib.API.Component.call(this,GameLib.Component.SKELETON,m)},GameLib.D3.API.Skeleton.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.API.Skeleton.prototype.constructor=GameLib.D3.API.Skeleton,GameLib.D3.API.Skeleton.FromObject=function(e){return new GameLib.D3.API.Skeleton(e.id,e.name,e.bones.map(function(e){return GameLib.D3.API.Bone.FromObject(e)}),e.boneInverses.map(function(e){return GameLib.D3.API.Matrix4.FromObject(e)}),e.useVertexTexture,e.boneTextureWidth,e.boneTextureHeight,e.boneMatrices.map(function(e){return GameLib.D3.API.Matrix4.FromObject(e)}),e.boneTexture,e.parentEntity)},GameLib.D3.API.Solver=function(e,t,i,n,a,s){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="Solver ("+this.id+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=GameLib.D3.API.Solver.GS_SOLVER),this.solverType=i,GameLib.Utils.UndefinedOrNull(n)&&(n=10),this.iterations=n,GameLib.Utils.UndefinedOrNull(a)&&(a=1e-7),this.tolerance=a,GameLib.API.Component.call(this,GameLib.Component.SOLVER,s)},GameLib.D3.API.Solver.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.API.Solver.prototype.constructor=GameLib.D3.API.Solver,GameLib.D3.API.Solver.GS_SOLVER=1,GameLib.D3.API.Solver.SPLIT_SOLVER=2,GameLib.D3.API.Solver.FromObject=function(e){return new GameLib.D3.API.Solver(e.id,e.name,e.solverType,e.iterations,e.tolerance,e.parentEntity)},GameLib.D3.API.Spline=function(e,t,i,n){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="Spline ("+this.id+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=[]),this.vertices=i,GameLib.API.Component.call(this,GameLib.Component.SPLINE,n)},GameLib.D3.API.Spline.prototype=Object.create(GameLib.Component.prototype);GameLib.D3.API.Spline.prototype.constructor=GameLib.D3.API.Spline,GameLib.D3.API.Spline.FromObject=function(e){return new GameLib.D3.API.Spline(e.id,e.name,e.vertices.map(function(e){return GameLib.API.Vector3.FromObject(e)}),e.parentEntity)},GameLib.D3.API.Texture=function(e,t,i,n,a,s,o,r,c,m,h,l,p,t,u,b,d,L,G,f,E,y,I,P,T,A,O){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t=GameLib.D3.API.Texture.TEXTURE_TYPE_NORMAL),this.textureType=t,GameLib.Utils.UndefinedOrNull(i)&&(i="Texture ("+e+")"),this.name=i,GameLib.Utils.UndefinedOrNull(n)&&(n=null),this.image=n,GameLib.Utils.UndefinedOrNull(a)&&(a=[]),this.images=a,GameLib.Utils.UndefinedOrNull(s)&&(s=GameLib.D3.API.Texture.TYPE_REPEAT_WRAPPING),this.wrapS=s,GameLib.Utils.UndefinedOrNull(o)&&(o=GameLib.D3.API.Texture.TYPE_REPEAT_WRAPPING),this.wrapT=o,GameLib.Utils.UndefinedOrNull(r)&&(r=new GameLib.API.Vector2(1,1)),this.repeat=r,GameLib.Utils.UndefinedOrNull(c)&&(c=null),this.data=c,GameLib.Utils.UndefinedOrNull(m)&&(m=GameLib.D3.API.Texture.TYPE_RGBA_FORMAT),this.format=m,GameLib.Utils.UndefinedOrNull(h)&&(h=GameLib.D3.API.Texture.TYPE_UV_MAPPING),this.mapping=h,GameLib.Utils.UndefinedOrNull(l)&&(l=GameLib.D3.API.Texture.TYPE_LINEAR_FILTER),this.magFilter=l,GameLib.Utils.UndefinedOrNull(p)&&(p=GameLib.D3.API.Texture.TYPE_LINEAR_MIPMAP_LINEAR_FILTER),this.minFilter=p,GameLib.Utils.UndefinedOrNull(t)&&(t=GameLib.D3.API.Texture.TYPE_UNSIGNED_BYTE),this.textureType=t,GameLib.Utils.UndefinedOrNull(u)&&(u=1),this.anisotropy=u,GameLib.Utils.UndefinedOrNull(b)&&(b=new GameLib.API.Vector2(0,0)),this.offset=b,GameLib.Utils.UndefinedOrNull(d)&&(d=!0),this.generateMipmaps=d,GameLib.Utils.UndefinedOrNull(L)&&(L=!0),this.flipY=L,GameLib.Utils.UndefinedOrNull(G)&&(G=[]),this.mipmaps=G,GameLib.Utils.UndefinedOrNull(f)&&(f=4),this.unpackAlignment=f,GameLib.Utils.UndefinedOrNull(E)&&(E=!1),this.premultiplyAlpha=E,GameLib.Utils.UndefinedOrNull(y)&&(y=GameLib.D3.API.Texture.TYPE_LINEAR_ENCODING),this.encoding=y,GameLib.Utils.UndefinedOrNull(I)&&(I=null),this.canvas=I,GameLib.Utils.UndefinedOrNull(P)&&(P=!1),this.animated=P,GameLib.Utils.UndefinedOrNull(T)&&(T=!1),this.reverseAnimation=T,GameLib.Utils.UndefinedOrNull(A)&&(A=!0),this.forward=A,this.needsUpdate=!1,GameLib.API.Component.call(this,GameLib.Component.TEXTURE,O)},GameLib.D3.API.Texture.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.API.Texture.prototype.constructor=GameLib.D3.API.Texture,GameLib.D3.API.Texture.TYPE_ALPHA_FORMAT=1019,GameLib.D3.API.Texture.TYPE_RGB_FORMAT=1020,GameLib.D3.API.Texture.TYPE_RGBA_FORMAT=1021,GameLib.D3.API.Texture.TYPE_LUMINANCE_FORMAT=1022,GameLib.D3.API.Texture.TYPE_LUMINANCE_ALPHA_FORMAT=1023,GameLib.D3.API.Texture.TYPE_DEPTH_FORMAT=1026,GameLib.D3.API.Texture.TYPE_UV_MAPPING=300,GameLib.D3.API.Texture.TYPE_CUBE_REFLECTION_MAPPING=301,GameLib.D3.API.Texture.TYPE_CUBE_REFRACTION_MAPPING=302,GameLib.D3.API.Texture.TYPE_EQUI_RECTANGULAR_REFLECTION_MAPPING=303,GameLib.D3.API.Texture.TYPE_EQUI_RECTANGULAR_REFRACTION_MAPPING=304,GameLib.D3.API.Texture.TYPE_SPHERICAL_REFLECTION_MAPPING=305,GameLib.D3.API.Texture.TYPE_CUBE_UV_REFLECTION_MAPPING=306,GameLib.D3.API.Texture.TYPE_CUBE_UV_REFRACTION_MAPPING=307,GameLib.D3.API.Texture.TYPE_REPEAT_WRAPPING=1e3,GameLib.D3.API.Texture.TYPE_CLAMP_TO_EDGE_WRAPPING=1001,GameLib.D3.API.Texture.TYPE_MIRRORED_REPEAT_WRAPPING=1002,GameLib.D3.API.Texture.TYPE_NEAREST_FILTER=1003,GameLib.D3.API.Texture.TYPE_NEAREST_MIPMAP_NEAREST_FILTER=1004,GameLib.D3.API.Texture.TYPE_NEAREST_MIPMAP_LINEAR_FILTER=1005,GameLib.D3.API.Texture.TYPE_LINEAR_FILTER=1006,GameLib.D3.API.Texture.TYPE_LINEAR_MIPMAP_NEAREST_FILTER=1007,GameLib.D3.API.Texture.TYPE_LINEAR_MIPMAP_LINEAR_FILTER=1008,GameLib.D3.API.Texture.TYPE_UNSIGNED_BYTE=1009,GameLib.D3.API.Texture.TYPE_BYTE=1010,GameLib.D3.API.Texture.TYPE_SHORT=1011,GameLib.D3.API.Texture.TYPE_UNSIGNED_SHORT=1012,GameLib.D3.API.Texture.TYPE_INT=1013,GameLib.D3.API.Texture.TYPE_UNSIGNED_INT=1014,GameLib.D3.API.Texture.TYPE_FLOAT=1015,GameLib.D3.API.Texture.TYPE_HALF_FLOAT=1025,GameLib.D3.API.Texture.TYPE_LINEAR_ENCODING=3e3,GameLib.D3.API.Texture.TYPE_SRGB_ENCODING=3001,GameLib.D3.API.Texture.TYPE_GAMMA_ENCODING=3007,GameLib.D3.API.Texture.TYPE_RGBE_ENCODING=3002,GameLib.D3.API.Texture.TYPE_LOG_LUV_ENCODING=3003,GameLib.D3.API.Texture.TYPE_RGBM7_ENCODING=3004,GameLib.D3.API.Texture.TYPE_RGBM16_ENCODING=3005,GameLib.D3.API.Texture.TYPE_RGBD_ENCODING=3006,GameLib.D3.API.Texture.TEXTURE_TYPE_NORMAL=1,GameLib.D3.API.Texture.TEXTURE_TYPE_CUBE=2,GameLib.D3.API.Texture.TEXTURE_TYPE_CANVAS=3,GameLib.D3.API.Texture.FromObject=function(e){return new GameLib.D3.API.Texture(e.id,e.textureType,e.name,e.image,e.images,e.wrapS,e.wrapT,GameLib.API.Vector2.FromObject(e.repeat),e.data,e.format,e.mapping,e.magFilter,e.minFilter,e.textureType,e.anisotropy,GameLib.API.Vector2.FromObject(e.offset),e.generateMipmaps,e.flipY,e.mipmaps,e.unpackAlignment,e.premultiplyAlpha,e.encoding,e.canvas,e.animated,e.reverseAnimation,e.forward,e.parentEntity)},GameLib.D3.API.Vertex=function(e,t){GameLib.Utils.UndefinedOrNull(e)&&(e=new GameLib.API.Vector3),this.position=e,GameLib.Utils.UndefinedOrNull(t)&&(t=[]),this.boneWeights=t},GameLib.D3.API.Vertex.FromObject=function(e){return new GameLib.D3.API.Vertex(GameLib.API.Vector3.FromObject(e.position),e.boneWeights.map(function(e){return GameLib.D3.API.BoneWeight.FromObject(e)}))},GameLib.D3.API.Viewport=function(e,t,i,n,a,s,o){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="Viewport ("+this.id+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=800),this.width=i,GameLib.Utils.UndefinedOrNull(n)&&(n=600),this.height=n,GameLib.Utils.UndefinedOrNull(a)&&(a=0),this.x=a,GameLib.Utils.UndefinedOrNull(s)&&(s=0),this.y=s,GameLib.API.Component.call(this,GameLib.Component.VIEWPORT,o)},GameLib.D3.API.Viewport.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.API.Viewport.prototype.constructor=GameLib.D3.API.Viewport,GameLib.D3.API.Viewport.FromObject=function(e){return new GameLib.D3.API.Viewport(e.id,e.name,e.width,e.height,e.x,e.y,e.parentEntity)},GameLib.D3.Animation=function(e){if(GameLib.Utils.UndefinedOrNull(e)&&(e={}),e instanceof GameLib.D3.Animation)return e;GameLib.D3.API.Animation.call(this,e.id,e.name,e.rotationSpeed,e.translationSpeed,e.scaleSpeed,e.rotationFn,e.translationFn,e.scaleFn,e.blocking,e.applyToMeshWhenDone,e.meshes,e.parentEntity),this.functionType=GameLib.D3.Animation.ANIMATION_FUNCTION_TYPE_ROTATION,this.editor=null,this.inProcess=!1,GameLib.Component.call(this,{meshes:[GameLib.D3.Mesh]})},GameLib.D3.Animation.prototype=Object.create(GameLib.D3.API.Animation.prototype),GameLib.D3.Animation.prototype.constructor=GameLib.D3.Animation,GameLib.D3.Animation.ANIMATION_FUNCTION_TYPE_ROTATION=1,GameLib.D3.Animation.ANIMATION_FUNCTION_TYPE_TRANSLATION=2,GameLib.D3.Animation.ANIMATION_FUNCTION_TYPE_SCALE=3,GameLib.D3.Animation.prototype.createInstance=function(){this.instance={rotation:null,translation:null,scale:null};try{this.rotationFn&&(this.instance.rotation=new Function("data",this.rotationFn).bind(this)),this.translationFn&&(this.instance.translation=new Function("data",this.translationFn).bind(this)),this.scaleFn&&(this.instance.scale=new Function("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=new Function("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=new Function("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=new Function("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(){return new GameLib.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){return GameLib.Utils.IdOrNull(e)}),GameLib.Utils.IdOrNull(this.parentEntity))},GameLib.D3.Animation.FromObject=function(e){var t=GameLib.D3.API.Animation.FromObject(e);return new GameLib.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));var e=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(){var e=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){var t=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={}),t instanceof GameLib.D3.Audio)return t;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.camera instanceof GameLib.D3.API.Camera&&(this.camera=new GameLib.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))return void console.log("audio not ready to create instance");GameLib.Event.Emit(GameLib.Event.GET_API_URL,null,function(e){this.apiUrl=e.apiUrl}.bind(this));var e=new THREE.AudioListener;this.camera.instance.add(e),this.instance=new THREE.Audio(e),(new THREE.AudioLoader).load(this.apiUrl+this.path+"?ts="+Date.now(),function(e){this.instance.setBuffer(e),this.instance.setLoop(this.loop),this.instance.setVolume(this.volume),GameLib.Component.prototype.createInstance.call(this)}.bind(this))},GameLib.D3.Audio.prototype.updateInstance=function(e){"loop"===e&&this.instance.setLoop(this.loop),"volume"===e&&this.instance.setVolume(this.volume),"paused"===e&&(this.paused?this.instance.pause():this.instance.play())},GameLib.D3.Audio.prototype.toApiObject=function(){return new GameLib.D3.API.Audio(this.id,this.name,this.path,this.loop,this.volume,GameLib.Utils.IdOrNull(this.camera),this.overplay,this.paused,GameLib.Utils.IdOrNull(this.parentEntity))},GameLib.D3.Audio.FromObject=function(e,t){var i=GameLib.D3.API.Audio.FromObject(t);return new GameLib.D3.Audio(e,i)},GameLib.D3.Audio.prototype.play=function(){this.instance.play()},GameLib.D3.BoneWeight=function(e,t){if(this.graphics=e,this.graphics.isNotThreeThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),t instanceof GameLib.D3.BoneWeight)return t;GameLib.D3.API.BoneWeight.call(this,t.boneIndex,t.weight)},GameLib.D3.BoneWeight.prototype=Object.create(GameLib.D3.API.BoneWeight.prototype),GameLib.D3.BoneWeight.prototype.constructor=GameLib.D3.BoneWeight,GameLib.D3.BoneWeight.prototype.toApiObject=function(){return new GameLib.D3.API.BoneWeight(this.boneIndex,this.weight)},GameLib.D3.BoneWeight.FromObject=function(e,t){var i=GameLib.D3.API.BoneWeight.FromObject(t);return new GameLib.D3.BoneWeight(e,i)},GameLib.D3.Bone=function(e,t){if(this.graphics=e,this.graphics.isNotThreeThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),t instanceof GameLib.D3.Bone)return t;GameLib.D3.API.Bone.call(this,t.id,t.name,t.childBoneIds,t.parentBoneIds,t.position,t.quaternion,t.scale,t.up,t.parentEntity),this.position=new GameLib.Vector3(e,this.position,this),this.quaternion=new GameLib.Quaternion(e,this.quaternion,this),this.scale=new GameLib.Vector3(e,this.scale,this),this.up=new GameLib.Vector3(e,this.up,this),GameLib.Component.call(this)},GameLib.D3.Bone.prototype=Object.create(GameLib.D3.API.Bone.prototype),GameLib.D3.Bone.prototype.constructor=GameLib.D3.Bone,GameLib.D3.Bone.prototype.createInstance=function(){this.instance=new THREE.Bone,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.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.scale.x=this.scale.x,this.instance.scale.y=this.scale.y,this.instance.scale.z=this.scale.z,this.instance.up.x=this.up.x,this.instance.up.y=this.up.y,this.instance.up.z=this.up.z,GameLib.Component.prototype.createInstance.call(this)},GameLib.D3.Bone.prototype.updateInstance=function(){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.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.scale.x=this.scale.x,this.instance.scale.y=this.scale.y,this.instance.scale.z=this.scale.z,this.instance.up.x=this.up.x,this.instance.up.y=this.up.y,this.instance.up.z=this.up.z},GameLib.D3.Bone.prototype.toApiObject=function(){return new GameLib.D3.API.Bone(this.id,this.name,this.childBoneIds,this.parentBoneIds,this.position.toApiObject(),this.quaternion.toApiObject(),this.scale.toApiObject(),this.up.toApiObject(),GameLib.Utils.IdOrNull(this.parentEntity))},GameLib.D3.Bone.FromObject=function(e,t){var i=GameLib.D3.API.Bone.FromObject(t);return GameLib.D3.Bone(e,i)},GameLib.D3.Broadphase=function(e,t){if(this.physics=e,this.physics.isNotCannonThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),t instanceof GameLib.D3.Broadphase)return t;GameLib.D3.API.Broadphase.call(this,t.id,t.name,t.broadphaseType,t.parentEntity),GameLib.Component.call(this)},GameLib.D3.Broadphase.prototype=Object.create(GameLib.D3.API.Broadphase.prototype),GameLib.D3.Broadphase.prototype.constructor=GameLib.D3.Broadphase,GameLib.D3.Broadphase.BROADPHASE_TYPE_NAIVE=1,GameLib.D3.Broadphase.BROADPHASE_TYPE_GRID=2,GameLib.D3.Broadphase.BROADPHASE_TYPE_SAP=3,GameLib.D3.Broadphase.prototype.createInstance=function(){if(this.broadphaseType===GameLib.D3.Broadphase.BROADPHASE_TYPE_NAIVE)this.instance=new CANNON.NaiveBroadphase;else if(this.broadphaseType===GameLib.D3.Broadphase.BROADPHASE_TYPE_GRID)this.instance=new CANNON.GridBroadphase;else{if(this.broadphaseType!==GameLib.D3.Broadphase.BROADPHASE_TYPE_SAP)throw console.warn("Unsupported broadphase type: "+this.broadphaseType),new Error("Unsupported broadphase type: "+this.broadphaseType);this.instance=new CANNON.SAPBroadphase}GameLib.Component.prototype.createInstance.call(this)},GameLib.D3.Broadphase.prototype.updateInstance=function(){this.broadphaseType===GameLib.D3.Broadphase.BROADPHASE_TYPE_NAIVE&&(this.instance instanceof CANNON.NaiveBroadphase||this.createInstance()),this.broadphaseType===GameLib.D3.Broadphase.BROADPHASE_TYPE_GRID&&(this.instance instanceof CANNON.GridBroadphase||this.createInstance()),this.broadphaseType===GameLib.D3.Broadphase.BROADPHASE_TYPE_SAP&&(this.instance instanceof CANNON.SAPBroadphase||this.createInstance())},GameLib.D3.Broadphase.prototype.toApiObject=function(){return new GameLib.D3.API.Broadphase(this.id,this.name,this.broadphaseType,GameLib.Utils.IdOrNull(this.parentEntity))},GameLib.D3.Broadphase.FromObject=function(e,t){var i=GameLib.D3.API.Broadphase.FromObject(t);return new GameLib.D3.Broadphase(e,i)},GameLib.D3.Camera=function(e,t){if(this.graphics=e,this.graphics.isNotThreeThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),t instanceof GameLib.D3.Camera)return t;if(GameLib.D3.API.Camera.call(this,t.id,t.cameraType,t.name,t.fov,t.aspect,t.near,t.far,t.position,t.lookAt,t.minX,t.maxX,t.minY,t.maxY,t.minZ,t.maxZ,t.offsetX,t.offsetY,t.quaternion,t.eyeSeparation,t.focalLength,t.parentEntity),!(this.position instanceof GameLib.API.Vector3))throw console.warn("position not instance of API.Vector3"),new Error("position not instance of API.Vector3");if(this.position=new GameLib.Vector3(e,this.position,this),!(this.quaternion instanceof GameLib.API.Quaternion))throw console.warn("quaternion not instance of API.Quaternion"),new Error("quaternion not instance of API.Quaternion");if(this.quaternion=new GameLib.Quaternion(e,this.quaternion,this),!(this.lookAt instanceof GameLib.API.Vector3))throw console.warn("lookAt not instance of API.Vector3"),new Error("lookAt not instance of API.Vector3");this.lookAt=new GameLib.Vector3(e,this.lookAt,this),GameLib.Component.call(this,GameLib.Component.CAMERA)},GameLib.D3.Camera.prototype=Object.create(GameLib.D3.API.Camera.prototype),GameLib.D3.Camera.prototype.constructor=GameLib.D3.Camera,GameLib.D3.Camera.CAMERA_TYPE_PERSPECTIVE=1,GameLib.D3.Camera.CAMERA_TYPE_ORTHOGONAL=2,GameLib.D3.Camera.CAMERA_TYPE_STEREO=3,GameLib.D3.Camera.prototype.createInstance=function(){if(this.cameraType===GameLib.D3.Camera.CAMERA_TYPE_PERSPECTIVE)this.instance=new THREE.PerspectiveCamera(this.fov,this.aspect,this.near,this.far);else if(this.cameraType===GameLib.D3.Camera.CAMERA_TYPE_ORTHOGONAL)this.instance=new THREE.OrthographicCamera(this.minX+this.offsetX,this.maxX+this.offsetX,this.maxY,this.minY,this.minZ,this.maxZ);else{if(this.cameraType!==GameLib.D3.Camera.CAMERA_TYPE_STEREO)throw new Error("unsupported camera type : "+this.cameraType);this.instance=new THREE.StereoCamera}this.instance.position.x=this.position.x,this.instance.position.y=this.position.y,this.instance.position.z=this.position.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.lookAt(this.lookAt.instance),this.instance.updateProjectionMatrix(),GameLib.Component.prototype.createInstance.call(this)},GameLib.D3.Camera.prototype.updateInstance=function(e){GameLib.Utils.UndefinedOrNull(e)&&console.warn("no camera property specified for : "+this.name),"cameraType"===e&&(this.cameraType!==GameLib.D3.Camera.CAMERA_TYPE_ORTHOGONAL||this.instance instanceof THREE.OrthographicCamera||this.createInstance(),this.cameraType!==GameLib.D3.Camera.CAMERA_TYPE_PERSPECTIVE||this.instance instanceof THREE.PerspectiveCamera||this.createInstance()),"aspect"!==e&&"minX"!==e&&"maxX"!==e&&"minY"!==e&&"maxY"!==e&&"minZ"!==e&&"maxZ"!==e&&"offsetX"!==e&&"offsetY"!==e&&"fov"!==e&&"near"!==e&&"far"!==e&&"eyeSeparation"!==e&&"focalLength"!==e||(this.cameraType===GameLib.D3.Camera.CAMERA_TYPE_ORTHOGONAL&&(this.minX=this.aspect*this.minY,this.maxX=this.aspect*this.maxY,this.instance.left=this.minX+this.offsetX,this.instance.right=this.maxX+this.offsetX,this.instance.bottom=this.minY+this.offsetY,this.instance.top=this.maxY+this.offsetY,this.instance.near=this.minZ,this.instance.far=this.maxZ),this.cameraType!==GameLib.D3.Camera.CAMERA_TYPE_PERSPECTIVE&&this.cameraType!==GameLib.D3.Camera.CAMERA_TYPE_STEREO||(this.instance.fov=this.fov,this.instance.aspect=this.aspect,this.instance.near=this.near,this.instance.far=this.far),this.cameraType===GameLib.D3.Camera.CAMERA_TYPE_STEREO&&(this.instance.eyeSeparation=this.eyeSeparation,this.instance.focalLength=this.focalLength,this.instance.update(this.instance))),"position"===e&&(this.instance.position.x=this.position.x,this.instance.position.y=this.position.y,this.instance.position.z=this.position.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),"lookAt"===e&&(this.lookAt.instance.x=this.lookAt.x,this.lookAt.instance.y=this.lookAt.y,this.lookAt.instance.z=this.lookAt.z,this.instance.lookAt(this.lookAt.instance)),this.instance.updateProjectionMatrix()},GameLib.D3.Camera.prototype.resize=function(e,t){camera.aspect=e/t,camera.updateInstance()},GameLib.D3.Camera.prototype.toApiObject=function(){return new GameLib.D3.API.Camera(this.id,this.cameraType,this.name,this.fov,this.aspect,this.near,this.far,this.position.toApiObject(),this.lookAt.toApiObject(),this.minX,this.maxX,this.minY,this.maxY,this.minZ,this.maxZ,this.offsetX,this.offsetY,this.quaternion.toApiObject(),this.eyeSeparation,this.focalLength,GameLib.Utils.IdOrNull(this.parentEntity))},GameLib.D3.Camera.FromObject=function(e,t){var i=GameLib.D3.API.Camera.FromObject(t);return new GameLib.D3.Camera(e,i)},GameLib.D3.Composer=function(e,t){if(this.graphics=e,this.graphics.isNotThreeThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),t instanceof GameLib.D3.Composer)return t;GameLib.D3.API.Composer.call(this,t.id,t.name,t.renderer,t.renderTarget,t.passes,t.parentEntity),GameLib.Component.call(this,{renderer:GameLib.D3.Renderer,renderTarget:GameLib.D3.RenderTarget,passes:[GameLib.D3.Pass]})},GameLib.D3.Composer.prototype=Object.create(GameLib.D3.API.Composer.prototype),GameLib.D3.Composer.prototype.constructor=GameLib.D3.Composer,GameLib.D3.Composer.prototype.createInstance=function(){console.log("GameLib.D3.Composer.prototype.createInstance() - fix me"),GameLib.Component.prototype.createInstance.call(this)},GameLib.D3.Composer.prototype.updateInstance=function(){console.log("GameLib.D3.Composer.prototype.updateInstance() - fix me")},GameLib.D3.Composer.prototype.toApiObject=function(){return new GameLib.D3.API.Composer(this.id,this.name,GameLib.Utils.IdOrNull(this.renderer),GameLib.Utils.IdOrNull(this.renderTarget),this.passes.map(function(e){return GameLib.Utils.IdOrNull(e)}),GameLib.Utils.IdOrNull(this.parentEntity))},GameLib.D3.Composer.FromObject=function(e,t){var i=GameLib.D3.API.Composer.FromObject(t);return new GameLib.D3.Composer(e,i)},GameLib.D3.Face=function(e,t){if(this.implementation=e,e instanceof GameLib.GraphicsRuntime)this.implementation.isNotThreeThrow();else{if(!(e instanceof GameLib.PhysicsRuntime))throw new Error("Unhandled implementation : "+e);this.implementation.isNotCannonThrow()}if(GameLib.Utils.UndefinedOrNull(t)&&(t={}),t instanceof GameLib.D3.Face)return t;GameLib.D3.API.Face.call(this,t.id,t.name,t.v0index,t.v1index,t.v2index,t.materialIndex,t.uvs,t.color,t.vertexColors,t.vertexNormals,t.normal),this.implementation instanceof GameLib.GraphicsRuntime&&(this.color=new GameLib.Color(this.implementation,this.color,this),this.vertexColors=this.vertexColors.map(function(e){return e instanceof GameLib.Color?e:e instanceof GameLib.API.Color?new GameLib.Color(this.implementation,e,this):void console.warn("unknown vertex color type",e)}.bind(this))),this.vertexNormals=this.vertexNormals.map(function(e){return e instanceof GameLib.Vector3?e:e instanceof GameLib.API.Vector3?new GameLib.Vector3(this.implementation,e,this):void console.warn("unknown vertex normal type",e)}.bind(this)),this.uvs=this.uvs.reduce(function(e,t,i){return e[i]=t.reduce(function(e,t){return t instanceof GameLib.API.Vector2?e.push(new GameLib.Vector2(this.implementation,t,this)):console.warn("unknown uv type"),e}.bind(this),[]),e}.bind(this),[]),this.normal=new GameLib.Vector3(this.implementation,this.normal,this)},GameLib.D3.Face.prototype=Object.create(GameLib.D3.API.Face.prototype),GameLib.D3.Face.prototype.constructor=GameLib.D3.Face,GameLib.D3.Face.prototype.createInstance=function(){},GameLib.D3.Face.prototype.updateInstance=function(){},GameLib.D3.Face.prototype.toApiObject=function(){return new GameLib.D3.API.Face(this.id,this.name,this.v0index,this.v1index,this.v2index,this.materialIndex,this.uvs.reduce(function(e,t,i){return e[i]=t.reduce(function(e,t){return t instanceof GameLib.Vector2?e.push(t.toApiObject()):console.warn("unknown uv type - cannot commit to API"),e}.bind(this),[]),e}.bind(this),[]),this.color.toApiObject(),this.vertexColors.map(function(e){return e.toApiObject()}),this.vertexNormals.map(function(e){return e.toApiObject()}),this.normal.toApiObject())},GameLib.D3.Face.FromObject=function(e,t){return new GameLib.D3.Face(e,GameLib.D3.API.Face.FromObject(t))},GameLib.D3.Fog=function(e,t){if(this.graphics=e,this.graphics.isNotThreeThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),t instanceof GameLib.D3.Fog)return t;GameLib.D3.API.Fog.call(this,t.id,t.name,t.exponential,t.color,t.near,t.far,t.density,t.parentEntity),this.color=new GameLib.Color(this.graphics,this.color,this),GameLib.Component.call(this)},GameLib.D3.Fog.prototype=Object.create(GameLib.D3.API.Fog.prototype),GameLib.D3.Fog.prototype.constructor=GameLib.D3.Fog,GameLib.D3.Fog.prototype.createInstance=function(){this.exponential?this.instance=new THREE.FogExp2(this.color.instance,this.density):this.instance=new THREE.Fog(this.color.instance,this.near,this.far),this.instance.name=this.name,GameLib.Component.prototype.createInstance.call(this)},GameLib.D3.Fog.prototype.updateInstance=function(e){if("exponential"===e){if(this.exponential&&!(this.instance instanceof THREE.FogExp2))return void this.createInstance();if(!(this.exponential||this.instance instanceof THREE.Fog))return void this.createInstance()}"color"===e&&(this.color.instance.setRGB(this.color.r,this.color.g,this.color.b),this.instance.color=this.color.instance),"near"!==e&&"far"!==e||this.instance instanceof THREE.Fog&&(this.instance.near=this.near,this.instance.far=this.far),"density"===e&&this.instance instanceof THREE.FogExp2&&(this.instance.density=this.density)},GameLib.D3.Fog.prototype.toApiObject=function(){return new GameLib.D3.API.Fog(this.id,this.name,this.exponential,this.color.toApiObject(),this.near,this.far,this.density,GameLib.Utils.IdOrNull(this.parentEntity))},GameLib.D3.Fog.FromObject=function(e,t){var i=GameLib.D3.API.Fog.FromObject(t);return new GameLib.D3.Fog(e,i)},GameLib.D3.Font=function(e,t){if(this.graphics=e,this.graphics.isNotThreeThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),t instanceof GameLib.D3.Font)return t;GameLib.D3.API.Font.call(this,t.id,t.name,t.url,t.parentEntity),GameLib.Component.call(this)},GameLib.D3.Font.prototype=Object.create(GameLib.D3.API.Font.prototype),GameLib.D3.Font.prototype.constructor=GameLib.D3.Font,GameLib.D3.Font.prototype.createInstance=function(){GameLib.Event.Emit(GameLib.Event.LOAD_FONT,{font:this},function(e){this.instance=e,GameLib.Component.prototype.createInstance.call(this)}.bind(this),function(e){console.error(e),this.instance=null,GameLib.Component.prototype.createInstance.call(this)}.bind(this))},GameLib.D3.Font.prototype.updateInstance=function(){GameLib.Event.Emit(GameLib.Event.LOAD_FONT,{font:this})},GameLib.D3.Font.prototype.toApiObject=function(){return new GameLib.D3.API.Font(this.id,this.name,this.url,GameLib.Utils.IdOrNull(this.parentEntity))},GameLib.D3.Font.FromObject=function(e,t){return new GameLib.D3.Font(e,GameLib.D3.API.Font.FromObject(t))},GameLib.D3.FrictionContactMaterial=function(e,t){if(this.physics=e,this.physics.isNotCannonThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),t instanceof GameLib.D3.FrictionContactMaterial)return t;GameLib.D3.API.FrictionContactMaterial.call(this,t.id,t.name,t.materials,t.friction,t.restitution,t.contactEquationStiffness,t.contactEquationRelaxation,t.frictionEquationStiffness,t.frictionEquationRelaxation,t.parentEntity),GameLib.Component.call(this,{materials:[GameLib.D3.FrictionMaterial]})},GameLib.D3.FrictionContactMaterial.prototype=Object.create(GameLib.D3.API.FrictionContactMaterial.prototype),GameLib.D3.FrictionContactMaterial.prototype.constructor=GameLib.D3.FrictionContactMaterial,GameLib.D3.FrictionContactMaterial.prototype.createInstance=function(){this.instance=new CANNON.ContactMaterial(null,null,{friction:this.friction,restitution:this.restitution,contactEquationStiffness:this.contactEquationStiffness}),this.instance.materials=this.materials.map(function(e){return e.instance}),GameLib.Component.prototype.createInstance.call(this)},GameLib.D3.FrictionContactMaterial.prototype.updateInstance=function(){this.instance.materials=this.materials.map(function(e){return e.instance}),this.instance.friction=this.friction,this.instance.restitution=this.restitution,this.instance.contactEquationStiffness=this.contactEquationStiffness,this.instance.contactEquationRelaxation=this.contactEquationRelaxation,this.instance.frictionEquationStiffness=this.frictionEquationStiffness,this.instance.frictionEquationRelaxation=this.frictionEquationRelaxation},GameLib.D3.FrictionContactMaterial.prototype.toApiObject=function(){return new GameLib.D3.API.FrictionContactMaterial(this.id,this.name,this.materials.map(function(e){return GameLib.Utils.IdOrNull(e)}),this.friction,this.restitution,this.contactEquationStiffness,this.contactEquationRelaxation,this.frictionEquationStiffness,this.frictionEquationRelaxation,GameLib.Utils.IdOrNull(this.parentEntity))},GameLib.D3.FrictionContactMaterial.FromObject=function(e,t){var i=GameLib.D3.API.FrictionContactMaterial.FromObject(t);return new GameLib.D3.FrictionContactMaterial(e,i)},GameLib.D3.FrictionMaterial=function(e,t){if(this.physics=e,this.physics.isNotCannonThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),t instanceof GameLib.D3.FrictionMaterial)return t;GameLib.D3.API.FrictionMaterial.call(this,t.id,t.name,t.friction,t.restitution,t.parentEntity),GameLib.Component.call(this)},GameLib.D3.FrictionMaterial.prototype=Object.create(GameLib.D3.API.FrictionMaterial.prototype),GameLib.D3.FrictionMaterial.prototype.constructor=GameLib.D3.FrictionMaterial,GameLib.D3.FrictionMaterial.prototype.createInstance=function(){this.instance=new CANNON.Material(this.name),this.instance.friction=this.friction,this.instance.restitution=this.restitution,GameLib.Component.prototype.createInstance.call(this)},GameLib.D3.FrictionMaterial.prototype.updateInstance=function(){this.instance.friction=this.friction,this.instance.restitution=this.restitution,this.instance.name=this.name},GameLib.D3.FrictionMaterial.prototype.toApiObject=function(){return new GameLib.D3.API.FrictionMaterial(this.id,this.name,this.friction,this.restitution,GameLib.Utils.IdOrNull(this.parentEntity))},GameLib.D3.FrictionMaterial.FromObject=function(e,t){var i=GameLib.D3.API.FrictionMaterial.FromObject(t);return new GameLib.D3.FrictionMaterial(e,i)},GameLib.D3.Helper=function(e,t,i,n,a,s){if(this.graphics=e,this.graphics.isNotThreeThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t=GameLib.Utils.RandomId()),this.id=t,GameLib.Utils.UndefinedOrNull(i)&&(i="Helper ("+t+")"),this.name=i,GameLib.Utils.UndefinedOrNull(n))throw console.warn("Cannot create a helper for an Object which does not exist"),new Error("Cannot create a helper for an Object which does not exist");this.object=n,GameLib.Utils.UndefinedOrNull(a)&&(a=GameLib.D3.Helper.HELPER_TYPE_NONE,n instanceof GameLib.D3.Mesh&&n.meshType!==GameLib.D3.API.Mesh.MESH_TYPE_CURVE&&(a=GameLib.D3.Helper.HELPER_TYPE_EDGES),n instanceof GameLib.D3.Light&&(n.lightType===GameLib.D3.Light.LIGHT_TYPE_DIRECTIONAL&&(a=GameLib.D3.Helper.HELPER_TYPE_DIRECTIONAL_LIGHT),n.lightType===GameLib.D3.Light.LIGHT_TYPE_POINT&&(a=GameLib.D3.Helper.HELPER_TYPE_POINT_LIGHT),n.lightType===GameLib.D3.Light.LIGHT_TYPE_SPOT&&(a=GameLib.D3.Helper.HELPER_TYPE_SPOT_LIGHT)),n instanceof GameLib.D3.Skeleton&&(a=GameLib.D3.Helper.HELPER_TYPE_SKELETON)),this.helperType=a,GameLib.Utils.UndefinedOrNull(s)&&(s=null),this.parentEntity=s,this.createInstance()},GameLib.D3.Helper.prototype=Object.create(GameLib.Component.prototype),GameLib.D3.Helper.prototype.constructor=GameLib.D3.Helper,GameLib.D3.Helper.HELPER_TYPE_NONE=0,GameLib.D3.Helper.HELPER_TYPE_EDGES=1,GameLib.D3.Helper.HELPER_TYPE_DIRECTIONAL_LIGHT=2,GameLib.D3.Helper.HELPER_TYPE_SPOT_LIGHT=3,GameLib.D3.Helper.HELPER_TYPE_POINT_LIGHT=4,GameLib.D3.Helper.HELPER_TYPE_WIREFRAME=5,GameLib.D3.Helper.HELPER_TYPE_SKELETON=6,GameLib.D3.Helper.prototype.createInstance=function(){this.helperType===GameLib.D3.Helper.HELPER_TYPE_EDGES&&(this.instance=new THREE.LineSegments(new THREE.EdgesGeometry(this.object.instance.geometry),new THREE.LineBasicMaterial({color:65280,linewidth:2}))),this.helperType===GameLib.D3.Helper.HELPER_TYPE_DIRECTIONAL_LIGHT&&(this.instance=new THREE.DirectionalLightHelper(this.object.instance)),this.helperType===GameLib.D3.Helper.HELPER_TYPE_POINT_LIGHT&&(this.instance=new THREE.PointLightHelper(this.object.instance,1)),this.helperType===GameLib.D3.Helper.HELPER_TYPE_SPOT_LIGHT&&(this.instance=new THREE.SpotLightHelper(this.object.instance)),this.helperType===GameLib.D3.Helper.HELPER_TYPE_WIREFRAME&&(this.instance=new THREE.WireframeGeometry(this.object.instance,65280)),this.helperType===GameLib.D3.Helper.HELPER_TYPE_SKELETON&&(this.instance=new THREE.SkeletonHelper(this.object.instance))},GameLib.D3.Helper.prototype.updateInstance=function(){this.instance.position.copy(this.object.instance.position),this.object.instance.parentMesh&&this.object.instance.parentMesh.instance&&this.instance.position.add(this.object.instance.parentMesh.instance.position),this.instance.scale.copy(this.object.instance.scale),this.instance.quaternion.copy(this.object.instance.quaternion)},GameLib.D3.Light=function(e,t){if(this.graphics=e,this.graphics.isNotThreeThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),t instanceof GameLib.D3.Light)return t;GameLib.D3.API.Light.call(this,t.id,t.lightType,t.name,t.color,t.intensity,t.position,t.targetPosition,t.quaternion,t.rotation,t.scale,t.distance,t.decay,t.power,t.angle,t.penumbra,t.parentScene,t.parentEntity),this.color=new GameLib.Color(e,this.color,this),this.position=new GameLib.Vector3(e,this.position,this),this.targetPosition=new GameLib.Vector3(e,this.targetPosition,this),this.scale=new GameLib.Vector3(e,this.scale,this),this.quaternion=new GameLib.Quaternion(e,this.quaternion,this),this.rotation=new GameLib.Vector3(e,this.rotation,this),GameLib.Component.call(this,{parentScene:GameLib.D3.Scene})},GameLib.D3.Light.prototype=Object.create(GameLib.D3.API.Light.prototype),GameLib.D3.Light.prototype.constructor=GameLib.D3.Light,GameLib.D3.Light.LIGHT_TYPE_AMBIENT=1,GameLib.D3.Light.LIGHT_TYPE_DIRECTIONAL=2,GameLib.D3.Light.LIGHT_TYPE_POINT=3,GameLib.D3.Light.LIGHT_TYPE_SPOT=4,GameLib.D3.Light.prototype.createInstance=function(){if(this.lightType===GameLib.D3.Light.LIGHT_TYPE_AMBIENT||"AmbientLight"===this.lightType)this.instance=new THREE.AmbientLight(this.color.instance,this.intensity);else if(this.lightType===GameLib.D3.Light.LIGHT_TYPE_DIRECTIONAL||"DirectionalLight"===this.lightType)this.instance=new THREE.DirectionalLight(this.color.instance,this.intensity);else if(this.lightType===GameLib.D3.Light.LIGHT_TYPE_POINT||"PointLight"===this.lightType)this.instance=new THREE.PointLight(this.color.instance,this.intensity),this.instance.distance=this.distance,this.instance.decay=this.decay;else{if(this.lightType!==GameLib.D3.Light.LIGHT_TYPE_SPOT&&"SpotLight"!==this.lightType)return void console.warn("unsupported light type: "+this.lightType);this.instance=new THREE.SpotLight(this.color.instance,this.intensity),this.instance.distance=this.distance,this.instance.angle=this.angle,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(){return new GameLib.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){return new GameLib.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={}),t instanceof GameLib.D3.Material)return t +;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=new GameLib.Color(e,this.specular,this),this.color=new GameLib.Color(e,this.color,this),this.emissive=new GameLib.Color(e,this.emissive,this),this.alphaMap&&this.alphaMap instanceof GameLib.D3.API.Texture&&(this.alphaMap=new GameLib.D3.Texture(this.graphics,this.alphaMap)),this.aoMap&&this.aoMap instanceof GameLib.D3.API.Texture&&(this.aoMap=new GameLib.D3.Texture(this.graphics,this.aoMap)),this.bumpMap&&this.bumpMap instanceof GameLib.D3.API.Texture&&(this.bumpMap=new GameLib.D3.Texture(this.graphics,this.bumpMap)),this.diffuseMap&&this.diffuseMap instanceof GameLib.D3.API.Texture&&(this.diffuseMap=new GameLib.D3.Texture(this.graphics,this.diffuseMap)),this.displacementMap&&this.displacementMap instanceof GameLib.D3.API.Texture&&(this.displacementMap=new GameLib.D3.Texture(this.graphics,this.displacementMap)),this.emissiveMap&&this.emissiveMap instanceof GameLib.D3.API.Texture&&(this.emissiveMap=new GameLib.D3.Texture(this.graphics,this.emissiveMap)),this.environmentMap&&this.environmentMap instanceof GameLib.D3.API.Texture&&(this.environmentMap=new GameLib.D3.Texture(this.graphics,this.environmentMap)),this.lightMap&&this.lightMap instanceof GameLib.D3.API.Texture&&(this.lightMap=new GameLib.D3.Texture(this.graphics,this.lightMap)),this.metalnessMap&&this.metalnessMap instanceof GameLib.D3.API.Texture&&(this.metalnessMap=new GameLib.D3.Texture(this.graphics,this.metalnessMap)),this.normalMap&&this.normalMap instanceof GameLib.D3.API.Texture&&(this.normalMap=new GameLib.D3.Texture(this.graphics,this.normalMap)),this.roughnessMap&&this.roughnessMap instanceof GameLib.D3.API.Texture&&(this.roughnessMap=new GameLib.D3.Texture(this.graphics,this.roughnessMap)),this.specularMap&&this.specularMap instanceof GameLib.D3.API.Texture&&(this.specularMap=new GameLib.D3.Texture(this.graphics,this.specularMap)),GameLib.Component.call(this,{alphaMap:GameLib.D3.Texture,aoMap:GameLib.D3.Texture,bumpMap:GameLib.D3.Texture,diffuseMap:GameLib.D3.Texture,displacementMap:GameLib.D3.Texture,emissiveMap:GameLib.D3.Texture,environmentMap:GameLib.D3.Texture,lightMap:GameLib.D3.Texture,metalnessMap:GameLib.D3.Texture,normalMap:GameLib.D3.Texture,roughnessMap:GameLib.D3.Texture,specularMap:GameLib.D3.Texture})},GameLib.D3.Material.prototype=Object.create(GameLib.D3.API.Material.prototype),GameLib.D3.Material.prototype.constructor=GameLib.D3.Material,GameLib.D3.Material.TYPE_MULTIPLY_OPERATION=0,GameLib.D3.Material.TYPE_MIX_OPERATION=1,GameLib.D3.Material.TYPE_ADD_OPERATION=2,GameLib.D3.Material.TYPE_NO_COLORS=0,GameLib.D3.Material.TYPE_FACE_COLORS=1,GameLib.D3.Material.TYPE_VERTEX_COLORS=2,GameLib.D3.Material.TYPE_NO_BLENDING=0,GameLib.D3.Material.TYPE_NORMAL_BLENDING=1,GameLib.D3.Material.TYPE_ADDITIVE_BLENDING=2,GameLib.D3.Material.TYPE_SUBTRACTIVE_BLENDING=3,GameLib.D3.Material.TYPE_MULTIPLY_BLENDING=4,GameLib.D3.Material.TYPE_CUSTOM_BLENDING=5,GameLib.D3.Material.TYPE_ZERO_FACTOR=200,GameLib.D3.Material.TYPE_ONE_FACTOR=201,GameLib.D3.Material.TYPE_SRC_COLOR_FACTOR=202,GameLib.D3.Material.TYPE_ONE_MINUS_SRC_COLOR_FACTOR=203,GameLib.D3.Material.TYPE_SRC_ALPHA_FACTOR=204,GameLib.D3.Material.TYPE_ONE_MINUS_SRC_ALPHA_FACTOR=205,GameLib.D3.Material.TYPE_DST_ALPHA_FACTOR=206,GameLib.D3.Material.TYPE_ONE_MINUS_DST_ALPHA_FACTOR=207,GameLib.D3.Material.TYPE_DST_COLOR_FACTOR=208,GameLib.D3.Material.TYPE_ONE_MINUS_DST_COLOR_FACTOR=209,GameLib.D3.Material.TYPE_SRC_ALPHA_SATURATE_FACTOR=210;GameLib.D3.Material.TYPE_ADD_EQUATION=100,GameLib.D3.Material.TYPE_SUBTRACT_EQUATION=101,GameLib.D3.Material.TYPE_REVERSE_SUBTRACT_EQUATION=102,GameLib.D3.Material.TYPE_MIN_EQUATION=103,GameLib.D3.Material.TYPE_MAX_EQUATION=104,GameLib.D3.Material.TYPE_NEVER_DEPTH=0,GameLib.D3.Material.TYPE_ALWAYS_DEPTH=1,GameLib.D3.Material.TYPE_LESS_DEPTH=2,GameLib.D3.Material.TYPE_LESS_EQUAL_DEPTH=3,GameLib.D3.Material.TYPE_EQUAL_DEPTH=4,GameLib.D3.Material.TYPE_GREATER_EQUAL_DEPTH=5,GameLib.D3.Material.TYPE_GREATER_DEPTH=6,GameLib.D3.Material.TYPE_NOT_EQUAL_DEPTH=7,GameLib.D3.Material.TYPE_FRONT_SIDE=0,GameLib.D3.Material.TYPE_BACK_SIDE=1,GameLib.D3.Material.TYPE_DOUBLE_SIDE=2,GameLib.D3.Material.TYPE_FLAT_SHADING=1,GameLib.D3.Material.TYPE_SMOOTH_SHADING=2,GameLib.D3.Material.MATERIAL_TYPE_LINE_BASIC=1,GameLib.D3.Material.MATERIAL_TYPE_LINE_DASHED=2,GameLib.D3.Material.MATERIAL_TYPE_BASIC=3,GameLib.D3.Material.MATERIAL_TYPE_DEPTH=4,GameLib.D3.Material.MATERIAL_TYPE_LAMBERT=5,GameLib.D3.Material.MATERIAL_TYPE_NORMAL=6,GameLib.D3.Material.MATERIAL_TYPE_PHONG=7,GameLib.D3.Material.MATERIAL_TYPE_STANDARD=8,GameLib.D3.Material.MATERIAL_TYPE_POINTS=9,GameLib.D3.Material.MATERIAL_TYPE_SPRITE=10,GameLib.D3.Material.MATERIAL_TYPE_TOON=11,GameLib.D3.Material.LINE_CAP_BUTT=1,GameLib.D3.Material.LINE_CAP_ROUND=2,GameLib.D3.Material.LINE_CAP_SQUARE=3,GameLib.D3.Material.LINE_JOIN_ROUND=1,GameLib.D3.Material.LINE_JOIN_BEVEL=2,GameLib.D3.Material.LINE_JOIN_MITER=3,GameLib.D3.Material.prototype.createToonMaterialInstance=function(){return new THREE.MeshToonMaterial({name:this.name,opacity:this.opacity,transparent:this.transparent,blending:this.blending,blendSrc:this.blendSrc,blendDst:this.blendDst,blendEquation:this.blendEquation,depthTest:this.depthTest,depthFunc:this.depthFunc,depthWrite:this.depthWrite,polygonOffset:this.polygonOffset,polygonOffsetFactor:this.polygonOffsetFactor,polygonOffsetUnits:this.polygonOffsetUnits,alphaTest:this.alphaTest,clippingPlanes:this.clippingPlanes,clipShadows:this.clipShadows,overdraw:this.overdraw,visible:this.visible,side:this.side,color:this.color.instance,roughness:this.roughness,metalness:this.metalness,lightMapIntensity:this.lightMapIntensity,aoMapIntensity:this.aoMapIntensity,emissive:this.emissive.instance,emissiveIntensity:this.emissiveIntensity,bumpScale:this.bumpScale,normalScale:this.normalScale,displacementScale:this.displacementScale,refractionRatio:this.refractionRatio,fog:this.fog,flatShading:this.flatShading,wireframe:this.wireframe,wireframeLinewidth:this.wireframeLineWidth,wireframeLinecap:this.wireframeLineCap,wireframeLinejoin:this.wireframeLineJoin,vertexColors:GameLib.D3.Material.TYPE_VERTEX_COLORS,skinning:this.skinning,morphTargets:this.morphTargets,morphNormals:this.morphNormals})},GameLib.D3.Material.prototype.createStandardMaterialInstance=function(){return new THREE.MeshStandardMaterial({name:this.name,opacity:this.opacity,transparent:this.transparent,blending:this.blending,blendSrc:this.blendSrc,blendDst:this.blendDst,blendEquation:this.blendEquation,depthTest:this.depthTest,depthFunc:this.depthFunc,depthWrite:this.depthWrite,polygonOffset:this.polygonOffset,polygonOffsetFactor:this.polygonOffsetFactor,polygonOffsetUnits:this.polygonOffsetUnits,alphaTest:this.alphaTest,clippingPlanes:this.clippingPlanes,clipShadows:this.clipShadows,overdraw:this.overdraw,visible:this.visible,side:this.side,color:this.color.instance,roughness:this.roughness,metalness:this.metalness,lightMapIntensity:this.lightMapIntensity,aoMapIntensity:this.aoMapIntensity,emissive:this.emissive.instance,emissiveIntensity:this.emissiveIntensity,bumpScale:this.bumpScale,normalScale:this.normalScale,displacementScale:this.displacementScale,refractionRatio:this.refractionRatio,fog:this.fog,flatShading:this.flatShading,wireframe:this.wireframe,wireframeLinewidth:this.wireframeLineWidth,wireframeLinecap:this.wireframeLineCap,wireframeLinejoin:this.wireframeLineJoin,vertexColors:GameLib.D3.Material.TYPE_VERTEX_COLORS,skinning:this.skinning,morphTargets:this.morphTargets,morphNormals:this.morphNormals})},GameLib.D3.Material.prototype.createPointsMaterialInstance=function(){return new THREE.PointsMaterial({name:this.name,opacity:this.opacity,transparent:this.transparent,depthTest:this.depthTest,depthFunc:this.depthFunc,depthWrite:this.depthWrite,visible:this.visible,side:this.side,color:this.color.instance,size:this.pointSize,sizeAttenuation:this.pointSizeAttenuation})},GameLib.D3.Material.prototype.createLineBasicMaterialInstance=function(){var e="round";this.lineCap===GameLib.D3.Material.LINE_CAP_BUTT&&(e="butt"),this.lineCap===GameLib.D3.Material.LINE_CAP_SQUARE&&(e="square");var t="round";return this.lineJoin===GameLib.D3.Material.LINE_JOIN_BEVEL&&(t="bevel"),this.lineJoin===GameLib.D3.Material.LINE_JOIN_MITER&&(t="miter"),new THREE.LineBasicMaterial({name:this.name,opacity:this.opacity,transparent:this.transparent,depthTest:this.depthTest,depthFunc:this.depthFunc,depthWrite:this.depthWrite,visible:this.visible,side:this.side,color:this.color.instance,linewidth:this.lineWidth,linecap:e,linejoin:t})},GameLib.D3.Material.prototype.createPhongMaterialInstance=function(){return new THREE.MeshPhongMaterial({name:this.name,opacity:this.opacity,transparent:this.transparent,blending:this.blending,blendSrc:this.blendSrc,blendDst:this.blendDst,blendEquation:this.blendEquation,depthTest:this.depthTest,depthFunc:this.depthFunc,depthWrite:this.depthWrite,polygonOffset:this.polygonOffset,polygonOffsetFactor:this.polygonOffsetFactor,polygonOffsetUnits:this.polygonOffsetUnits,alphaTest:this.alphaTest,clippingPlanes:this.clippingPlanes,clipShadows:this.clipShadows,overdraw:this.overdraw,visible:this.visible,side:this.side,color:this.color.instance,specular:this.specular.instance,shininess:this.shininess,lightMapIntensity:this.lightMapIntensity,aoMapIntensity:this.aoMapIntensity,emissive:this.emissive.instance,emissiveIntensity:this.emissiveIntensity,bumpScale:this.bumpScale,normalScale:this.normalScale,displacementScale:this.displacementScale,combine:this.combine,refractionRatio:this.refractionRatio,fog:this.fog,flatShading:this.flatShading,wireframe:this.wireframe,wireframeLinewidth:this.wireframeLineWidth,wireframeLinecap:this.wireframeLineCap,wireframeLinejoin:this.wireframeLineJoin,vertexColors:GameLib.D3.Material.TYPE_VERTEX_COLORS,skinning:this.skinning,morphTargets:this.morphTargets,morphNormals:this.morphNormals})},GameLib.D3.Material.prototype.createMeshBasicMaterialInstance=function(){return new THREE.MeshBasicMaterial({name:this.name,opacity:this.opacity,transparent:this.transparent,blending:this.blending,blendSrc:this.blendSrc,blendDst:this.blendDst,blendEquation:this.blendEquation,depthTest:this.depthTest,depthFunc:this.depthFunc,depthWrite:this.depthWrite,polygonOffset:this.polygonOffset,polygonOffsetFactor:this.polygonOffsetFactor,polygonOffsetUnits:this.polygonOffsetUnits,alphaTest:this.alphaTest,clippingPlanes:this.clippingPlanes,clipShadows:this.clipShadows,overdraw:this.overdraw,visible:this.visible,side:this.side,color:this.color.instance,vertexColors:GameLib.D3.Material.TYPE_VERTEX_COLORS,fog:this.fog})},GameLib.D3.Material.prototype.checkTexture=function(e,t){var i=!1;return this[e]&&this[e].instance?this.instance[t]!==this[e].instance&&(this.instance[t]=this[e].instance,i=!0):null!==this.instance[t]&&(this.instance[t]=null,i=!0),i},GameLib.D3.Material.prototype.updateTextures=function(){var e=!1;return this.checkTexture("alphaMap","alphaMap")&&(e=!0),this.checkTexture("aoMap","aoMap")&&(e=!0),this.checkTexture("bumpMap","bumpMap")&&(e=!0),this.checkTexture("diffuseMap","map")&&(e=!0),this.checkTexture("displacementMap","displacementMap")&&(e=!0),this.checkTexture("emissiveMap","emissiveMap")&&(e=!0),this.checkTexture("environmentMap","envMap")&&(e=!0),this.checkTexture("lightMap","lightMap")&&(e=!0),this.checkTexture("metalnessMap","metalnessMap")&&(e=!0),this.checkTexture("normalMap","normalMap")&&(e=!0),this.checkTexture("roughnessMap","roughnessMap")&&(e=!0),this.checkTexture("specularMap","specularMap")&&(e=!0),e&&this.publish(GameLib.Event.MATERIAL_TEXTURES_UPDATED,{material:this}),e},GameLib.D3.Material.prototype.updateToonMaterialInstance=function(e){this.instance.name=this.name,this.instance.opacity=this.opacity,this.instance.transparent=this.transparent,this.instance.blending=this.blending,this.instance.blendSrc=this.blendSrc,this.instance.blendDst=this.blendDst,this.instance.blendEquation=this.blendEquation,this.instance.depthTest=this.depthTest,this.instance.depthFunc=this.depthFunc,this.instance.depthWrite=this.depthWrite,this.instance.polygonOffset=this.polygonOffset,this.instance.polygonOffsetFactor=this.polygonOffsetFactor,this.instance.polygonOffsetUnits=this.polygonOffsetUnits,this.instance.alphaTest=this.alphaTest,this.instance.clippingPlanes=this.clippingPlanes,this.instance.clipShadows=this.clipShadows,this.instance.overdraw=this.overdraw,this.instance.visible=this.visible,this.instance.side=this.side,this.instance.color=this.color.instance,this.instance.envMapIntensity=this.envMapIntensity,this.instance.roughness=this.roughness,this.instance.metalness=this.metalness,this.instance.lightMapIntensity=this.lightMapIntensity,this.instance.aoMapIntensity=this.aoMapIntensity,this.instance.emissive=this.emissive.instance,this.instance.emissiveIntensity=this.emissiveIntensity,this.instance.bumpScale=this.bumpScale,this.instance.normalScale=this.normalScale,this.instance.displacementScale=this.displacementScale,this.instance.refractionRatio=this.refractionRatio,this.instance.fog=this.fog,this.instance.flatShading=this.flatShading,this.instance.wireframe=this.wireframe,this.instance.wireframeLinewidth=this.wireframeLineWidth,this.instance.wireframeLinecap=this.wireframeLineCap,this.instance.wireframeLinejoin=this.wireframeLineJoin,this.instance.vertexColors=GameLib.D3.Material.TYPE_VERTEX_COLORS,this.instance.skinning=this.skinning,this.instance.morphTargets=this.morphTargets,this.instance.morphNormals=this.morphNormals},GameLib.D3.Material.prototype.updateStandardMaterialInstance=function(e){this.instance.name=this.name,this.instance.opacity=this.opacity,this.instance.transparent=this.transparent,this.instance.blending=this.blending,this.instance.blendSrc=this.blendSrc,this.instance.blendDst=this.blendDst,this.instance.blendEquation=this.blendEquation,this.instance.depthTest=this.depthTest,this.instance.depthFunc=this.depthFunc,this.instance.depthWrite=this.depthWrite,this.instance.polygonOffset=this.polygonOffset,this.instance.polygonOffsetFactor=this.polygonOffsetFactor,this.instance.polygonOffsetUnits=this.polygonOffsetUnits,this.instance.alphaTest=this.alphaTest,this.instance.clippingPlanes=this.clippingPlanes,this.instance.clipShadows=this.clipShadows,this.instance.overdraw=this.overdraw,this.instance.visible=this.visible,this.instance.side=this.side,this.instance.color=this.color.instance,this.instance.envMapIntensity=this.envMapIntensity,this.instance.roughness=this.roughness,this.instance.metalness=this.metalness,this.instance.lightMapIntensity=this.lightMapIntensity,this.instance.aoMapIntensity=this.aoMapIntensity,this.instance.emissive=this.emissive.instance,this.instance.emissiveIntensity=this.emissiveIntensity,this.instance.bumpScale=this.bumpScale,this.instance.normalScale=this.normalScale,this.instance.displacementScale=this.displacementScale,this.instance.refractionRatio=this.refractionRatio,this.instance.fog=this.fog,this.instance.flatShading=this.flatShading,this.instance.wireframe=this.wireframe,this.instance.wireframeLinewidth=this.wireframeLineWidth,this.instance.wireframeLinecap=this.wireframeLineCap,this.instance.wireframeLinejoin=this.wireframeLineJoin,this.instance.vertexColors=GameLib.D3.Material.TYPE_VERTEX_COLORS,this.instance.skinning=this.skinning,this.instance.morphTargets=this.morphTargets,this.instance.morphNormals=this.morphNormals},GameLib.D3.Material.prototype.updatePointsMaterialInstance=function(e){this.instance.name=this.name,this.instance.opacity=this.opacity,this.instance.transparent=this.transparent,this.instance.depthFunc=this.depthFunc,this.instance.depthWrite=this.depthWrite,this.instance.visible=this.visible,this.instance.side=this.side,this.instance.color=this.color.instance,this.instance.size=this.pointSize,this.instance.sizeAttenuation=this.pointSizeAttenuation},GameLib.D3.Material.prototype.updateLineBasicMaterialInstance=function(e){var t="round";this.lineCap===GameLib.D3.Material.LINE_CAP_BUTT&&(t="butt"),this.lineCap===GameLib.D3.Material.LINE_CAP_SQUARE&&(t="square");var i="round";this.lineJoin===GameLib.D3.Material.LINE_JOIN_BEVEL&&(i="bevel"),this.lineJoin===GameLib.D3.Material.LINE_JOIN_MITER&&(i="miter"),this.instance.name=this.name,this.instance.opacity=this.opacity,this.instance.transparent=this.transparent,this.instance.depthFunc=this.depthFunc,this.instance.depthWrite=this.depthWrite,this.instance.visible=this.visible,this.instance.side=this.side,this.instance.color=this.color.instance,this.instance.linewidth=this.lineWidth,this.instance.linecap=t,this.instance.linejoin=i},GameLib.D3.Material.prototype.updatePhongMaterialInstance=function(e){this.instance.name=this.name,this.instance.opacity=this.opacity,this.instance.transparent=this.transparent,this.instance.blending=this.blending,this.instance.blendSrc=this.blendSrc,this.instance.blendDst=this.blendDst,this.instance.blendEquation=this.blendEquation,this.instance.depthTest=this.depthTest,this.instance.depthFunc=this.depthFunc,this.instance.depthWrite=this.depthWrite,this.instance.polygonOffset=this.polygonOffset,this.instance.polygonOffsetFactor=this.polygonOffsetFactor,this.instance.polygonOffsetUnits=this.polygonOffsetUnits,this.instance.alphaTest=this.alphaTest,this.instance.clippingPlanes=this.clippingPlanes,this.instance.clipShadows=this.clipShadows,this.instance.overdraw=this.overdraw,this.instance.visible=this.visible,this.instance.side=this.side,this.instance.color=this.color.instance,this.instance.specular=this.specular.instance,this.instance.shininess=this.shininess,this.instance.lightMapIntensity=this.lightMapIntensity,this.instance.aoMapIntensity=this.aoMapIntensity,this.instance.emissive=this.emissive.instance,this.instance.emissiveIntensity=this.emissiveIntensity,this.instance.envMapIntensity=this.envMapIntensity,this.instance.bumpScale=this.bumpScale,this.instance.normalScale=this.normalScale,this.instance.displacementScale=this.displacementScale,this.instance.combine=this.combine,this.instance.refractionRatio=this.refractionRatio,this.instance.fog=this.fog,this.instance.flatShading=this.flatShading,this.instance.wireframe=this.wireframe,this.instance.wireframeLinewidth=this.wireframeLineWidth,this.instance.wireframeLinecap=this.wireframeLineCap,this.instance.wireframeLinejoin=this.wireframeLineJoin,this.instance.vertexColors=GameLib.D3.Material.TYPE_VERTEX_COLORS,this.instance.skinning=this.skinning,this.instance.morphTargets=this.morphTargets,this.instance.morphNormals=this.morphNormals},GameLib.D3.Material.prototype.updateMeshBasicMaterialInstance=function(e){this.instance.name=this.name,this.instance.opacity=this.opacity,this.instance.transparent=this.transparent,this.instance.blending=this.blending,this.instance.blendSrc=this.blendSrc,this.instance.blendDst=this.blendDst,this.instance.blendEquation=this.blendEquation,this.instance.depthTest=this.depthTest,this.instance.depthFunc=this.depthFunc,this.instance.depthWrite=this.depthWrite,this.instance.polygonOffset=this.polygonOffset,this.instance.polygonOffsetFactor=this.polygonOffsetFactor,this.instance.polygonOffsetUnits=this.polygonOffsetUnits,this.instance.alphaTest=this.alphaTest,this.instance.clippingPlanes=this.clippingPlanes,this.instance.clipShadows=this.clipShadows,this.instance.overdraw=this.overdraw,this.instance.visible=this.visible,this.instance.side=this.side,this.instance.color=this.color.instance,this.instance.vertexColors=GameLib.D3.Material.TYPE_VERTEX_COLORS,this.instance.fog=this.fog},GameLib.D3.Material.prototype.createInstance=function(){this.materialType===GameLib.D3.Material.MATERIAL_TYPE_STANDARD?this.instance=this.createStandardMaterialInstance():this.materialType===GameLib.D3.Material.MATERIAL_TYPE_POINTS?this.instance=this.createPointsMaterialInstance():this.materialType===GameLib.D3.Material.MATERIAL_TYPE_PHONG?this.instance=this.createPhongMaterialInstance():this.materialType===GameLib.D3.Material.MATERIAL_TYPE_BASIC?this.instance=this.createMeshBasicMaterialInstance():this.materialType===GameLib.D3.Material.MATERIAL_TYPE_LINE_BASIC?this.instance=this.createLineBasicMaterialInstance():this.materialType===GameLib.D3.Material.MATERIAL_TYPE_TOON?this.instance=this.createToonMaterialInstance():console.warn("material type is not implemented yet: "+this.materialType),this.instance.needsUpdate=!0,this.updateTextures(),GameLib.Component.prototype.createInstance.call(this)},GameLib.D3.Material.prototype.updateInstance=function(e){return this.instance?"materialType"===e?(this.createInstance(),void this.publish(GameLib.Event.MATERIAL_TYPE_CHANGED,{material:this})):("alphaMap"!==e&&"aoMap"!==e&&"bumpMap"!==e&&"diffuseMap"!==e&&"displacementMap"!==e&&"emissiveMap"!==e&&"environmentMap"!==e&&"lightMap"!==e&&"metalnessMap"!==e&&"normalMap"!==e&&"roughnessMap"!==e&&"specularMap"!==e||this.updateTextures(),this.materialType===GameLib.D3.Material.MATERIAL_TYPE_STANDARD?this.updateStandardMaterialInstance(e):this.materialType===GameLib.D3.Material.MATERIAL_TYPE_POINTS?this.updatePointsMaterialInstance(e):this.materialType===GameLib.D3.Material.MATERIAL_TYPE_PHONG?this.updatePhongMaterialInstance(e):this.materialType===GameLib.D3.Material.MATERIAL_TYPE_BASIC?this.updateMeshBasicMaterialInstance(e):this.materialType===GameLib.D3.Material.MATERIAL_TYPE_LINE_BASIC?this.updateLineBasicMaterialInstance(e):this.materialType===GameLib.D3.Material.MATERIAL_TYPE_TOON?this.updateToonMaterialInstance(e):console.warn("not yet implemented (material type = "+this.materialType+")"),void(this.instance.needsUpdate=!0)):void console.warn("Attempt to update a non-existent instance")},GameLib.D3.Material.prototype.toApiObject=function(e){GameLib.Utils.UndefinedOrNull(e)&&(e=!1);var t=null;this.alphaMap&&(e&&this.alphaMap.save(),t=this.alphaMap.id);var i=null;this.aoMap&&(e&&this.aoMap.save(),i=this.aoMap.id);var n=null;this.bumpMap&&(e&&this.bumpMap.save(),n=this.bumpMap.id);var a=null;this.diffuseMap&&(e&&this.diffuseMap.save(),a=this.diffuseMap.id);var s=null;this.displacementMap&&(e&&this.displacementMap.save(),s=this.displacementMap.id);var o=null;this.emissiveMap&&(e&&this.emissiveMap.save(),o=this.emissiveMap.id);var r=null;this.environmentMap&&(e&&this.environmentMap.save(),r=this.environmentMap.id);var c=null;this.lightMap&&(e&&this.lightMap.save(),c=this.lightMap.id);var m=null;this.metalnessMap&&(e&&this.metalnessMap.save(),m=this.metalnessMap.id);var h=null;this.normalMap&&(this.normalMap.save(),h=this.normalMap.id);var l=null;this.roughnessMap&&(e&&this.roughnessMap.save(),l=this.roughnessMap.id);var p=null;return this.specularMap&&(e&&this.specularMap.save(),p=this.specularMap.id),new GameLib.D3.API.Material(this.id,this.materialType,this.name,this.opacity,this.side,this.transparent,this.specular.toApiObject(),this.lightMapIntensity,this.aoMapIntensity,this.color.toApiObject(),this.emissive.toApiObject(),this.emissiveIntensity,this.combine,this.shininess,this.reflectivity,this.refractionRatio,this.fog,this.wireframe,this.wireframeLineWidth,this.wireframeLineCap,this.wireframeLineJoin,this.vertexColors,this.skinning,this.morphTargets,this.morphNormals,this.lineWidth,this.lineCap,this.lineJoin,this.dashSize,this.gapWidth,this.blending,this.blendSrc,this.blendDst,this.blendEquation,this.depthTest,this.depthFunc,this.depthWrite,this.polygonOffset,this.polygonOffsetFactor,this.polygonOffsetUnits,this.alphaTest,this.clippingPlanes,this.clipShadows,this.visible,this.overdraw,this.flatShading,this.bumpScale,this.normalScale,this.displacementScale,this.displacementBias,this.roughness,this.metalness,this.pointSize,this.pointSizeAttenuation,this.spriteRotation,this.envMapIntensity,t,i,n,a,s,o,r,c,m,h,l,p,GameLib.Utils.IdOrNull(this.parentEntity))},GameLib.D3.Material.prototype.getTextures=function(){var e=[];return this.alphaMap&&e.push(this.alphaMap),this.aoMap&&e.push(this.aoMap),this.bumpMap&&e.push(this.bumpMap),this.diffuseMap&&e.push(this.diffuseMap),this.displacementMap&&e.push(this.displacementMap),this.emissiveMap&&e.push(this.emissiveMap),this.environmentMap&&e.push(this.environmentMap),this.lightMap&&e.push(this.lightMap),this.metalnessMap&&e.push(this.metalnessMap),this.normalMap&&e.push(this.normalMap),this.roughnessMap&&e.push(this.roughnessMap),this.specularMap&&e.push(this.specularMap),e},GameLib.D3.Material.FromObject=function(e,t){return new GameLib.D3.Material(e,GameLib.D3.API.Material.FromObject(t))},GameLib.D3.Mesh=function(e,t){if(this.graphics=e,this.graphics.isNotThreeThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={meshType:GameLib.D3.API.Mesh.MESH_TYPE_NORMAL}),t instanceof GameLib.D3.Mesh)return t;GameLib.D3.API.Mesh.call(this,t.id,t.meshType,t.name,t.vertices,t.faces,t.materials,t.parentMesh,t.parentScene,t.skeleton,t.skinIndices,t.skinWeights,t.position,t.quaternion,t.rotation,t.scale,t.up,t.modelMatrix,t.renderOrder,t.isBufferMesh,t.useQuaternion,t.visible,t.parentEntity),this.faces=this.faces.map(function(e){return e instanceof GameLib.D3.API.Face?new GameLib.D3.Face(this.graphics,e):e}.bind(this)),this.materials=this.materials.map(function(e){return e instanceof GameLib.D3.API.Material?new GameLib.D3.Material(this.graphics,e):e}.bind(this)),this.skeleton&&(this.skeleton=new GameLib.D3.Skeleton(this.graphics,this.skeleton)),this.vertices=this.vertices.map(function(e){return new GameLib.D3.Vertex(this.graphics,e)}.bind(this)),this.position=new GameLib.Vector3(this.graphics,this.position,this),this.quaternion=new GameLib.Quaternion(this.graphics,this.quaternion,this),this.rotation=new GameLib.Vector3(this.graphics,this.rotation,this),this.scale=new GameLib.Vector3(this.graphics,this.scale,this),this.up=new GameLib.Vector3(this.graphics,this.up,this),this.modelMatrix=new GameLib.Matrix4(this.graphics,this.modelMatrix,this),this.dimensions=new GameLib.Vector3(this.graphics,new GameLib.API.Vector3,this);var i={parentMesh:GameLib.D3.Mesh,parentScene:GameLib.D3.Scene,materials:[GameLib.D3.Material],skeleton:GameLib.D3.Skeleton};this.meshType===GameLib.D3.API.Mesh.MESH_TYPE_TEXT&&(i.font=GameLib.D3.Font),this.helper=null,this.updateRotationFromAxisAngle=!0,GameLib.Component.call(this,i)},GameLib.D3.Mesh.prototype=Object.create(GameLib.D3.API.Mesh.prototype),GameLib.D3.Mesh.prototype.constructor=GameLib.D3.Mesh,GameLib.D3.Mesh.prototype.lookAt=function(e){this.instance.lookAt(new THREE.Vector3(e.x,e.y,e.z)),this.rotation.x=this.instance.rotation.x,this.rotation.y=this.instance.rotation.y,this.rotation.z=this.instance.rotation.z,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},GameLib.D3.Mesh.prototype.createInstanceGeometry=function(e){if(e instanceof THREE.Geometry&&(this.computeBoundingBox(e),this.isBufferMesh))return(new THREE.BufferGeometry).fromGeometry(e);this.faces.sort(function(e,t){return e.materialIndext.materialIndex?1:0});var t=new Float32Array(this.faces.reduce(function(e,t){return e.push(this.vertices[t.v0index].position.x),e.push(this.vertices[t.v0index].position.y),e.push(this.vertices[t.v0index].position.z),e.push(this.vertices[t.v1index].position.x),e.push(this.vertices[t.v1index].position.y),e.push(this.vertices[t.v1index].position.z),e.push(this.vertices[t.v2index].position.x),e.push(this.vertices[t.v2index].position.y),e.push(this.vertices[t.v2index].position.z),e}.bind(this),[])),i=null;if(this.isBufferMesh){i=new THREE.BufferGeometry,i.addAttribute("position",new THREE.BufferAttribute(t,3));var n=new Float32Array(this.faces.reduce(function(e,t){return e.push(1,1,1,1,1,1,1,1,1),e}.bind(this),[]));i.addAttribute("color",new THREE.BufferAttribute(n,3,!0));var a=new Float32Array(this.faces.reduce(function(e,t){return t.uvs[0].map(function(t){e.push(t.x),e.push(t.y)}),e},[]));i.addAttribute("uv",new THREE.BufferAttribute(a,2));var s=new Float32Array(this.faces.reduce(function(e,t){return e.push(t.normal.x,t.normal.y,t.normal.z),e.push(t.normal.x,t.normal.y,t.normal.z),e.push(t.normal.x,t.normal.y,t.normal.z),e},[]));i.addAttribute("normal",new THREE.BufferAttribute(s,3)),i.computeVertexNormals();this.faces.reduce(function(e,t){var i=e.pop();return i.index!==t.materialIndex?(e.push(i),e.push({index:t.materialIndex,count:3})):(i.count+=3,e.push(i)),e},[{index:0,count:0}]).reduce(function(e,t){return i.addGroup(e,t.count,t.index),e+t.count},0)}else{i=new THREE.Geometry;var o=[];i.faces=this.faces.map(function(e){e.uvs[0].length>0&&o.push(e.uvs[0].map(function(e){return new THREE.Vector2(e.x,e.y)}));var t=new THREE.Face3(e.v0index,e.v1index,e.v2index);return e.normal&&(t.normal=new THREE.Vector3(e.normal.x,e.normal.y,e.normal.z)),e.color&&(t.color=new THREE.Color(e.color.r,e.color.g,e.color.b)),t.materialIndex=e.materialIndex,t}),i.vertices=this.vertices.map(function(e){return new THREE.Vector3(e.position.x,e.position.y,e.position.z)}),i.verticesNeedUpdate=!0,o.length>0&&(i.faceVertexUvs=[o]),i.computeFaceNormals(),i.computeVertexNormals()}return this.computeBoundingBox(i),i},GameLib.D3.Mesh.prototype.createInstance=function(){var e=this.createInstanceGeometry();this.skeleton?(1===this.materials.length?this.instance=new THREE.SkinnedMesh(e,this.materials[0].instance):this.instance=new THREE.SkinnedMesh(e,this.materials.map(function(e){return e.instance})),this.instance.add(this.skeleton.rootBoneInstance),this.instance.bind(this.skeleton.instance)):1===this.materials.length?this.instance=new THREE.Mesh(e,this.materials[0].instance):this.instance=new THREE.Mesh(e,this.materials.map(function(e){return e.instance})),this.instance.name=this.name,this.parentMesh&&this.parentMesh.instance&&this.parentMesh.add(this.instance,this),this.instance.position.x=this.position.x,this.instance.position.y=this.position.y,this.instance.position.z=this.position.z,this.useQuaternion?(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.quaternion.setFromAxisAngle(new THREE.Vector3(this.quaternion.axis.x,this.quaternion.axis.y,this.quaternion.axis.z),this.quaternion.angle)):(this.instance.rotation.x=this.rotation.x,this.instance.rotation.y=this.rotation.y,this.instance.rotation.z=this.rotation.z),this.instance.scale.x=this.scale.x,this.instance.scale.y=this.scale.y,this.instance.scale.z=this.scale.z,this.instance.up.x=this.up.x,this.instance.up.y=this.up.y,this.instance.up.z=this.up.z,this.instance.renderOrder=this.renderOrder,this.instance.visible=this.visible,GameLib.Component.prototype.createInstance.call(this)},GameLib.D3.Mesh.prototype.updateInstance=function(e){GameLib.Utils.UndefinedOrNull(e)&&console.warn("unknown mesh property update"),"isBufferMesh"===e&&(this.isBufferMesh&&!(this.instance.geometry instanceof THREE.BufferGeometry)||!this.isBufferMesh&&this.instance.geometry instanceof THREE.BufferGeometry)&&(this.instance.geometry=this.createInstanceGeometry(this.instance.geometry)), +"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=[],e instanceof THREE.BufferGeometry){var t=e.getAttribute("position").array,i=e.getAttribute("uv").array;e.groups.map(function(e){for(var n=e.materialIndex,a=e.start,s=e.count,o=[],r=[],c=a;c0&&e.push({mesh:t,distance:i[0].distance}),e}.bind(this),[])},GameLib.D3.Raycaster.prototype.getFaceNormal=function(e){var t=null,i=this.instance.intersectObject(e.instance);return i&&i.length>0&&(t=new GameLib.Vector3(this.graphics,new GameLib.API.Vector3(i[0].face.normal.x,i[0].face.normal.y,i[0].face.normal.z),this)),t},GameLib.D3.Raycaster.prototype.getIntersectPoint=function(e){var t=null,i=this.instance.intersectObject(e.instance);return i&&i.length>0&&(t=new GameLib.Vector3(this.graphics,new GameLib.API.Vector3(i[0].point.x,i[0].point.y,i[0].point.z),this)),t},GameLib.D3.RenderTarget=function(e,t){if(this.graphics=e,this.graphics.isNotThreeThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),t instanceof GameLib.D3.RenderTarget)return t;GameLib.D3.API.RenderTarget.call(this,t.id,t.name,t.width,t.height,t.stencilBuffer,t.texture),GameLib.Component.call(this,{texture:GameLib.D3.Texture})},GameLib.D3.RenderTarget.prototype=Object.create(GameLib.D3.API.RenderTarget.prototype),GameLib.D3.RenderTarget.prototype.constructor=GameLib.D3.RenderTarget,GameLib.D3.RenderTarget.prototype.createInstance=function(){if(GameLib.Utils.UndefinedOrNull(this.texture))throw new Error("no texture");if(GameLib.Utils.UndefinedOrNull(this.texture.instance))throw new Error("no texture instance");this.instance=new THREE.WebGLRenderTarget(this.width,this.height,{stencilBuffer:this.stencilBuffer}),this.instance.texture=this.texture.instance,GameLib.Component.prototype.createInstance.call(this)},GameLib.D3.RenderTarget.prototype.updateInstance=function(){if(this.instance)this.instance.setSize(this.width,this.height),this.instance.stencilBuffer=this.stencilBuffer,this.texture&&this.texture.instance?(this.instance.texture=this.texture.instance,this.instance.texture.needsUpdate=!0):this.instance.texture=null;else try{this.createInstance()}catch(e){console.error(e)}},GameLib.D3.RenderTarget.prototype.toApiObject=function(){return new GameLib.D3.API.RenderTarget(this.id,this.name,this.width,this.height,this.stencilBuffer,GameLib.Utils.IdOrNull(this.texture),GameLib.Utils.IdOrNull(this.parentEntity))},GameLib.D3.RenderTarget.FromObject=function(e,t){var i=GameLib.D3.API.RenderTarget.FromObject(t);return new GameLib.D3.RenderTarget(e,i)},GameLib.D3.Renderer=function(e,t){if(this.graphics=e,this.graphics.isNotThreeThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),t instanceof GameLib.D3.Renderer)return t;GameLib.D3.API.Renderer.call(this,t.id,t.name,t.autoClear,t.localClipping,t.width,t.height,t.preserveDrawingBuffer,t.domElement,t.clearColor,t.camera,t.scenes,t.viewports,t.clippingPlanes,t.bufferScene,t.bufferCamera,t.renderTarget,t.defaultScene,t.sortObjects,t.parentEntity),this.clearColor=new GameLib.Color(this.graphics,this.clearColor,this),this.domElement instanceof GameLib.API.DomElement&&(this.domElement=new GameLib.DomElement(this.domElement)),this.camera instanceof GameLib.D3.API.Camera&&(this.camera=new GameLib.D3.Camera(this.graphics,this.camera)),this.scenes=this.scenes.map(function(e){return e instanceof GameLib.D3.API.Scene?new GameLib.D3.Scene(this.graphics,e):e}.bind(this)),this.viewports=this.viewports.map(function(e){return e instanceof GameLib.D3.API.Viewport?new GameLib.D3.Viewport(this.graphics,e):e}.bind(this)),this.clippingPlanes=this.clippingPlanes.map(function(e){return e instanceof GameLib.D3.API.Mesh?new GameLib.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.bufferScene instanceof GameLib.D3.API.Scene&&(this.bufferScene=new GameLib.D3.Scene(this.graphics,this.bufferScene)),this.bufferCamera instanceof GameLib.D3.API.Camera&&(this.bufferCamera=new GameLib.D3.Camera(this.graphics,this.bufferCamera)),this.renderTarget instanceof GameLib.D3.API.RenderTarget&&(this.renderTarget=new GameLib.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))throw new Error("no dom element");if(GameLib.Utils.UndefinedOrNull(this.domElement.instance))throw new Error("no dom element instance");this.instance=new THREE.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)throw new Error("is not a clipping plane or no clipping plane instance");return e.instance.clipping})),this.instance.localClippingEnabled=this.localClipping,this.instance.setSize(this.width,this.height),this.instance.setClearColor(new THREE.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(new THREE.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)throw new Error("is not a clipping plane or no clipping plane instance");return e.instance.clipping}):this.instance.clippingPlanes=[],"sortObjects"===e&&(this.instance.sortObjects=this.sortObjects);else try{this.createInstance()}catch(e){console.error(e.message)}},GameLib.D3.Renderer.prototype.toApiObject=function(){return new GameLib.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){return GameLib.Utils.IdOrNull(e)}),this.viewports.map(function(e){return GameLib.Utils.IdOrNull(e)}),this.clippingPlanes.map(function(e){return GameLib.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){var i=GameLib.D3.API.Renderer.FromObject(t);return new GameLib.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={}),t instanceof GameLib.D3.RigidBody)return t;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=new GameLib.Vector3(this.physics,this.position,this),this.quaternion=new GameLib.Quaternion(this.physics,this.quaternion,this),this.velocity=new GameLib.Vector3(this.physics,this.velocity,this),this.angularVelocity=new GameLib.Vector3(this.physics,this.angularVelocity,this),this.force=new GameLib.Vector3(this.physics),this.forcePoint=new GameLib.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=new CANNON.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))throw new Error("no shape");if(GameLib.Utils.UndefinedOrNull(e.instance))throw new Error("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.quaternion.x,this.instance.quaternion.y=this.parentMesh.quaternion.y,this.instance.quaternion.z=this.parentMesh.quaternion.z,this.instance.quaternion.w=this.parentMesh.quaternion.w},GameLib.D3.RigidBody.prototype.toApiObject=function(){return new GameLib.D3.API.RigidBody(this.id,this.name,this.mass,this.friction,this.position.toApiObject(),this.quaternion.toApiObject(),this.velocity.toApiObject(),this.angularVelocity.toApiObject(),this.linearDamping,this.angularDamping,this.allowSleep,this.sleepSpeedLimit,this.sleepTimeLimit,this.collisionFilterGroup,this.collisionFilterMask,this.fixedRotation,this.shapes.map(function(e){return GameLib.Utils.IdOrNull(e)}),this.kinematic,GameLib.Utils.IdOrNull(this.parentMesh),GameLib.Utils.IdOrNull(this.parentPhysicsWorld),GameLib.Utils.IdOrNull(this.parentEntity))},GameLib.D3.RigidBody.FromObject=function(e,t){var i=GameLib.D3.API.RigidBody.FromObject(t);return new GameLib.D3.RigidBody(e,i)},GameLib.D3.RigidBody.prototype.applyForce=function(){this.instance.applyForce(this.force.instance,this.forcePoint.instance)},GameLib.D3.RigidBody.prototype.applyLocalForce=function(){this.instance.applyLocalForce(this.force.instance,this.forcePoint.instance)},GameLib.D3.Scene=function(e,t){if(this.graphics=e,this.graphics.isNotThreeThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),t instanceof GameLib.D3.Scene)return t;GameLib.D3.API.Scene.call(this,t.id,t.name,t.meshes,t.lights,t.textures,t.materials,t.images,t.fog,t.renderCamera,t.showGrid,t.showAxis,t.gridSize,t.gridColor,t.parentEntity),this.meshes=this.meshes.map(function(e){return e instanceof GameLib.D3.API.Mesh?(e.parentScene=this,new GameLib.D3.Mesh(this.graphics,e)):e}.bind(this)),this.lights=this.lights.map(function(e){return e instanceof GameLib.D3.API.Light?new GameLib.D3.Light(this.graphics,e):e}.bind(this)),this.textures=this.textures.map(function(e){if(e instanceof GameLib.D3.API.Texture){return new GameLib.D3.Texture(this.graphics,e)}return e}.bind(this)),this.materials=this.materials.map(function(e){if(e instanceof GameLib.D3.API.Material){return new GameLib.D3.Material(this.graphics,e)}return e}.bind(this)),this.images=this.images.map(function(e){if(e instanceof GameLib.API.Image){return new GameLib.Image(this.graphics,e)}return e}.bind(this)),this.fog instanceof GameLib.D3.API.Fog&&(this.fog=new GameLib.D3.Fog(this.graphics,this.fog)),this.renderCamera instanceof GameLib.D3.API.Camera&&(this.renderCamera=new GameLib.D3.Camera(this.graphics,this.renderCamera)),this.gridColor instanceof GameLib.API.Color&&(this.gridColor=new GameLib.Color(this.graphics,this.gridColor,this)),this.helpers=[],this.clones=[],this.grid=[],this.axis=[],this.storeClones=!1,GameLib.Component.call(this,{meshes:[GameLib.D3.Mesh],lights:[GameLib.D3.Light],textures:[GameLib.D3.Texture],materials:[GameLib.D3.Material],images:[GameLib.Image],fog:GameLib.D3.Fog,renderCamera:GameLib.D3.Camera})},GameLib.D3.Scene.prototype=Object.create(GameLib.D3.API.Scene.prototype),GameLib.D3.Scene.prototype.constructor=GameLib.D3.Scene,GameLib.D3.Scene.prototype.createInstance=function(){this.instance=new THREE.Scene,this.instance.name=this.name,this.fog&&this.fog.instance&&(this.instance.fog=this.fog.instance),this.meshes.map(function(e){if(GameLib.Utils.UndefinedOrNull(e))throw new Error("no mesh");if(GameLib.Utils.UndefinedOrNull(e.instance))throw new Error("no mesh instance");this.instance.add(e.instance),e.parentScene=this}.bind(this)),this.lights.map(function(e){if(GameLib.Utils.UndefinedOrNull(e))throw new Error("no light");if(GameLib.Utils.UndefinedOrNull(e.instance))throw new Error("no light instance");this.instance.add(e.instance),e.parentScene=this}.bind(this)),this.showGrid&&this.drawGrid(),this.showAxis&&this.drawAxis(),GameLib.Component.prototype.createInstance.call(this)},GameLib.D3.Scene.prototype.updateInstance=function(e){if("name"===e)return void(this.instance.name=this.name);this.fog&&this.fog.instance!==this.instance.fog&&(this.instance.fog=this.fog.instance),this.meshes.map(function(e){this.instance.children.indexOf(-1===e.instance)&&this.instance.add(e.instance)}.bind(this)),this.lights.map(function(e){-1===this.instance.children.indexOf(e.instance)&&this.instance.add(e.instance)}.bind(this)),this.instance.children.map(function(e){var t=this.meshes.map(function(e){return e.instance}),i=this.lights.map(function(e){return e.instance});(e instanceof THREE.Mesh||e instanceof THREE.Light)&&-1===i.indexOf(e)&&-1===t.indexOf(e)&&this.instance.remove(e)}.bind(this)),"showGrid"!==e&&"gridSize"!==e&&"gridColor"!==e||(this.showGrid?this.drawGrid():this.removeGrid()),"showAxis"===e&&(this.showAxis?this.drawAxis():this.removeAxis())},GameLib.D3.Scene.prototype.toApiObject=function(){var e=this.meshes.reduce(function(e,t){return(-1===this.clones.indexOf(t)||this.storeClones)&&e.push(GameLib.Utils.IdOrNull(t)),e}.bind(this),[]),t=this.lights.reduce(function(e,t){return(-1===this.clones.indexOf(t)||this.storeClones)&&e.push(GameLib.Utils.IdOrNull(t)),e}.bind(this),[]),i=this.textures.map(function(e){return GameLib.Utils.IdOrNull(e)}),n=this.materials.map(function(e){return GameLib.Utils.IdOrNull(e)}),a=this.images.map(function(e){return GameLib.Utils.IdOrNull(e)});return new GameLib.D3.API.Scene(this.id,this.name,e,t,i,n,a,GameLib.Utils.IdOrNull(this.fog),GameLib.Utils.IdOrNull(this.renderCamera),this.showGrid,this.showAxis,this.gridSize,this.gridColor.toApiObject(),GameLib.Utils.IdOrNull(this.parentEntity))},GameLib.D3.Scene.FromObject=function(e,t){var i=GameLib.D3.API.Scene.FromObject(t);return new GameLib.D3.Scene(e,i)},GameLib.D3.Scene.prototype.addObject=function(e){e instanceof GameLib.D3.Mesh?-1===this.meshes.indexOf(e)&&this.meshes.push(e):e instanceof GameLib.D3.API.Mesh&&(e=new GameLib.D3.Mesh(this.graphics,e),this.meshes.push(e)),e instanceof GameLib.D3.Light?-1===this.lights.indexOf(e)&&this.lights.push(e):e instanceof GameLib.D3.API.Light&&(e=new GameLib.D3.Light(this.graphics,e),this.lights.push(e)),e.parentScene=this,this.instance&&e.instance&&-1===this.instance.children.indexOf(e.instance)&&this.instance.add(e.instance)},GameLib.D3.Scene.prototype.addClone=function(e){(e instanceof GameLib.D3.Mesh||e instanceof GameLib.D3.Light)&&(this.instance&&e.instance&&this.instance.add(e.instance),GameLib.Utils.PushUnique(this.clones,e),e.parentScene=this)},GameLib.D3.Scene.prototype.removeObject=function(e){var t=-1;if(e instanceof GameLib.D3.Mesh)t=this.meshes.indexOf(e),-1!==t&&this.meshes.splice(t,1),-1!==(t=this.clones.indexOf(e))&&this.clones.splice(t,1);else{if(!(e instanceof GameLib.D3.Light))return void console.warn("Cannot remove this object - what is this ?"+e.toString());t=this.lights.indexOf(e),-1!==t&&this.lights.splice(t,1),-1!==(t=this.clones.indexOf(e))&&this.clones.splice(t,1)}-1!==this.instance.children.indexOf(e.instance)?this.instance.remove(e.instance):console.warn("no scene instance"),e.parentScene===this&&(e.parentScene=null)},GameLib.D3.Scene.prototype.drawGrid=function(){this.removeGrid();for(var e=new THREE.LineBasicMaterial({color:this.gridColor.toHex(),linewidth:1}),t=-this.gridSize;t<=this.gridSize;t+=1){var i=new THREE.Geometry;i.vertices.push(new THREE.Vector3(t,0,-1*this.gridSize),new THREE.Vector3(t,0,this.gridSize));var n=new THREE.Line(i,e);this.instance.add(n),this.grid.push(n);var a=new THREE.Geometry;a.vertices.push(new THREE.Vector3(-1*this.gridSize,0,t),new THREE.Vector3(this.gridSize,0,t));var s=new THREE.Line(a,e);this.instance.add(s),this.grid.push(s)}},GameLib.D3.Scene.prototype.removeGrid=function(){this.grid.map(function(e){this.instance.remove(e)}.bind(this))},GameLib.D3.Scene.prototype.drawAxis=function(){this.removeAxis();var e=new THREE.LineBasicMaterial({color:16711680,linewidth:2}),t=new THREE.Geometry;t.vertices.push(new THREE.Vector3(0,0,0),new THREE.Vector3(100,0,0));var i=new THREE.Line(t,e);this.instance.add(i),this.axis.push(i);var n=new THREE.LineBasicMaterial({color:65280,linewidth:2}),a=new THREE.Geometry;a.vertices.push(new THREE.Vector3(0,0,0),new THREE.Vector3(0,100,0));var s=new THREE.Line(a,n);this.instance.add(s),this.axis.push(s);var o=new THREE.LineBasicMaterial({color:255,linewidth:2}),r=new THREE.Geometry;r.vertices.push(new THREE.Vector3(0,0,0),new THREE.Vector3(0,0,100));var c=new THREE.Line(r,o);this.instance.add(c),this.axis.push(c)},GameLib.D3.Scene.prototype.removeAxis=function(){this.axis.map(function(e){this.instance.remove(e)}.bind(this))},GameLib.D3.Shape=function(e,t){if(this.physics=e,this.physics.isNotCannonThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={shapeType:GameLib.D3.API.Shape.SHAPE_TYPE_NONE}),t instanceof GameLib.D3.Shape)return t;GameLib.D3.API.Shape.call(this,t.id,t.name,t.shapeType,t.boundingSphereRadius,t.collisionResponse,t.frictionMaterial,t.parentMesh,t.parentEntity);var i={frictionMaterial:GameLib.D3.FrictionMaterial,parentMesh:GameLib.D3.Mesh};GameLib.Component.call(this,i)},GameLib.D3.Shape.prototype=Object.create(GameLib.D3.API.Shape.prototype),GameLib.D3.Shape.prototype.constructor=GameLib.D3.Shape,GameLib.D3.Shape.prototype.createInstance=function(){GameLib.Component.prototype.createInstance.call(this)},GameLib.D3.Shape.prototype.updateInstance=function(){throw new Error("Do not instantiate this class directly - use a child class instead")},GameLib.D3.Shape.prototype.toApiObject=function(){return new GameLib.D3.API.Shape(this.id,this.name,this.shapeType,this.boundingSphereRadius,this.collisionResponse,GameLib.Utils.IdOrNull(this.frictionMaterial),GameLib.Utils.IdOrNull(this.parentMesh),GameLib.Utils.IdOrNull(this.parentEntity))},GameLib.D3.Shape.FromObject=function(e,t){throw"not implemented"},GameLib.D3.Shape.prototype.stopVisualize=function(){GameLib.Event.Emit(GameLib.Event.STOP_VISUALIZE,{mesh:this.mesh})},GameLib.D3.Shape.prototype.visualize=function(){GameLib.Event.Emit(GameLib.Event.VISUALIZE,{shape:this})},GameLib.D3.Shape.Box=function(e,t,i){if(this.physics=e,this.physics.isNotCannonThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={shapeType:GameLib.D3.API.Shape.SHAPE_TYPE_BOX}),t instanceof GameLib.D3.Shape.Box)return t;GameLib.Utils.UndefinedOrNull(i)?i=new GameLib.Vector3(e,new GameLib.API.Vector3(1,1,1)):i instanceof GameLib.API.Vector3&&(i=new GameLib.Vector3(this.physics,i,this)),this.halfExtents=i,GameLib.D3.Shape.call(this,this.physics,t)},GameLib.D3.Shape.Box.prototype=Object.create(GameLib.D3.Shape.prototype),GameLib.D3.Shape.Box.prototype.constructor=GameLib.D3.Shape.Box,GameLib.D3.Shape.Box.prototype.createInstance=function(){if(GameLib.Utils.UndefinedOrNull(this.halfExtents))throw new Error("no halfExtents");if(GameLib.Utils.UndefinedOrNull(this.halfExtents.instance))throw new Error("no halfExtents instance");this.instance=new CANNON.Box(this.halfExtents.instance),GameLib.D3.Shape.prototype.createInstance.call(this)},GameLib.D3.Shape.Box.prototype.updateInstance=function(){this.instance.halfExtents.x=this.halfExtents.x,this.instance.halfExtents.y=this.halfExtents.y,this.instance.halfExtents.z=this.halfExtents.z,this.instance.updateBoundingSphereRadius(),this.instance.updateConvexPolyhedronRepresentation()},GameLib.D3.Shape.Box.prototype.toApiObject=function(){var e=GameLib.D3.Shape.prototype.toApiObject.call(this);return e.halfExtents=this.halfExtents.toApiObject(),e},GameLib.D3.Shape.Box.prototype.setFromMesh=function(){if(null===this.parentMesh)return void console.log("select a mesh first");var e=this.parentMesh.getBoundingBox();this.halfExtents.x=e.x/2,this.halfExtents.y=e.y/2,this.halfExtents.z=e.z/2,this.halfExtents.updateInstance()},GameLib.D3.Shape.Box.FromObject=function(e,t){var i=GameLib.D3.API.Shape.FromObject(t);return i.halfExtents=GameLib.API.Vector3.FromObject(t.halfExtents),new GameLib.D3.Shape.Box(e,i,i.halfExtents)},GameLib.D3.Shape.ConvexHull=function(e,t,i,n,a,s){if(this.physics=e,this.physics.isNotCannonThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={shapeType:GameLib.D3.API.Shape.SHAPE_TYPE_CONVEX_HULL}),t instanceof GameLib.D3.Shape.ConvexHull)return t;GameLib.Utils.UndefinedOrNull(i)&&(i=[]),this.vertices=i,GameLib.Utils.UndefinedOrNull(n)&&(n=[]),this.faces=n,GameLib.Utils.UndefinedOrNull(a)&&(a=[]),this.uniqueAxes=a,GameLib.Utils.UndefinedOrNull(s)&&(s=[]),this.uniqueEdges=s,this.vertices=this.vertices.map(function(e){return e instanceof GameLib.D3.API.Vertex?new GameLib.D3.Vertex(this.physics,e):e}.bind(this)),this.faces=this.faces.map(function(e){return e instanceof GameLib.D3.API.Face?new GameLib.D3.Face(this.physics,e):e}.bind(this)),this.uniqueAxes=this.uniqueAxes.map(function(e){return e instanceof GameLib.API.Vector3?new GameLib.Vector3(this.physics,e,this):e}.bind(this)),this.uniqueEdges=this.uniqueEdges.map(function(e){return e instanceof GameLib.API.Vector3?new GameLib.Vector3(this.physics,e,this):e}.bind(this)),GameLib.D3.Shape.call(this,this.physics,t)},GameLib.D3.Shape.ConvexHull.prototype=Object.create(GameLib.D3.Shape.prototype),GameLib.D3.Shape.ConvexHull.prototype.constructor=GameLib.D3.Shape.ConvexHull,GameLib.D3.Shape.ConvexHull.prototype.createInstance=function(){var e=[];this.instance=new CANNON.ConvexPolyhedron(this.vertices.map(function(e){if(GameLib.Utils.UndefinedOrNull(e))throw new Error("no vertex");if(GameLib.Utils.UndefinedOrNull(e.position))throw new Error("no vertex position");if(GameLib.Utils.UndefinedOrNull(e.position.instance))throw new Error("no vertex position instance");return e.position.instance}),this.faces.map(function(t){if(GameLib.Utils.UndefinedOrNull(t))throw new Error("no face");if(GameLib.Utils.UndefinedOrNull(t.normal))throw new Error("no face normal");if(GameLib.Utils.UndefinedOrNull(t.normal.instance))throw new Error("no face normal instance");if(GameLib.Utils.UndefinedOrNull(t.v0index))throw new Error("no face v0index");if(GameLib.Utils.UndefinedOrNull(t.v1index))throw new Error("no face v1index");if(GameLib.Utils.UndefinedOrNull(t.v2index))throw new Error("no face v2index");return e.push(t.normal.instance),[t.v0index,t.v1index,t.v2index]})),this.instance.faceNormals=e,GameLib.D3.Shape.prototype.createInstance.call(this)},GameLib.D3.Shape.ConvexHull.prototype.updateInstance=function(){console.log("todo: update convex hull instance")},GameLib.D3.Shape.ConvexHull.prototype.loadFromInstance=function(){console.log("todo: eventually load the faces and vertices from the instance faces and vertices and normals"),console.log("todo: this way we can nicely visualize them with our gamelib classes :)")},GameLib.D3.Shape.ConvexHull.prototype.toApiObject=function(){var e=GameLib.D3.Shape.prototype.toApiObject.call(this);return e.vertices=this.vertices.map(function(e){return e instanceof GameLib.D3.Vertex?e.toApiObject():e}),e.faces=this.faces.map(function(e){return e instanceof GameLib.D3.Face?e.toApiObject():e}),e.uniqueAxes=this.uniqueAxes.map(function(e){return e instanceof GameLib.Vector3?e.toApiObject():e}),e.uniqueEdges=this.uniqueEdges.map(function(e){return e instanceof GameLib.Vector3?e.toApiObject():e}),e},GameLib.D3.Shape.ConvexHull.prototype.setFromMesh=function(){console.log("todo: set convex hull from mesh"),this.updateInstance()},GameLib.D3.Shape.ConvexHull.InheritableProperties=function(e,t){return{vertices:t.vertices.map(function(t){return GameLib.D3.Vertex.FromObject(e,t)}),faces:t.faces.map(function(t){return GameLib.D3.Face.FromObject(e,t)}),uniqueAxes:t.uniqueAxes.map(function(e){return GameLib.API.Vector3.FromObject(e)}),uniqueEdges:t.uniqueEdges.map(function(e){return GameLib.API.Vector3.FromObject(e)})}},GameLib.D3.Shape.ConvexHull.FromObject=function(e,t){var i=GameLib.D3.API.Shape.FromObject(t),n=GameLib.D3.Shape.ConvexHull.InheritableProperties(e,t);return new GameLib.D3.Shape.ConvexHull.call(this,e,i,n.vertices,n.faces,n.uniqueAxes,n.uniqueEdges)},GameLib.D3.Shape.ConvexHull.Cylinder=function(e,t,i,n,a,s){if(this.physics=e,this.physics.isNotCannonThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={shapeType:GameLib.D3.API.Shape.SHAPE_TYPE_CONVEX_HULL_CYLINDER}),t instanceof GameLib.D3.Shape.ConvexHull.Cylinder)return t;GameLib.Utils.UndefinedOrNull(i)&&(i=1),this.radiusTop=i,GameLib.Utils.UndefinedOrNull(n)&&(n=1),this.radiusBottom=n,GameLib.Utils.UndefinedOrNull(a)&&(a=n/2),this.height=a,GameLib.Utils.UndefinedOrNull(s)&&(s=20),this.numSegments=s,GameLib.D3.Shape.ConvexHull.call(this,this.physics,t)},GameLib.D3.Shape.ConvexHull.Cylinder.prototype=Object.create(GameLib.D3.Shape.ConvexHull.prototype),GameLib.D3.Shape.ConvexHull.Cylinder.prototype.constructor=GameLib.D3.Shape.ConvexHull.Cylinder,GameLib.D3.Shape.ConvexHull.Cylinder.prototype.createInstance=function(){this.instance=new CANNON.Cylinder(this.radiusTop,this.radiusBottom,this.height,this.numSegments),GameLib.D3.Shape.prototype.createInstance.call(this)},GameLib.D3.Shape.ConvexHull.Cylinder.prototype.updateInstance=function(){console.log("todo : update cylinder instance")},GameLib.D3.Shape.ConvexHull.Cylinder.prototype.setFromMesh=function(){this.radiusTop=this.parentMesh.dimensions.x/2,this.radiusBottom=this.parentMesh.dimensions.x/2,this.height=this.parentMesh.dimensions.z},GameLib.D3.Shape.ConvexHull.Cylinder.prototype.toApiObject=function(){var e=GameLib.D3.Shape.ConvexHull.prototype.toApiObject.call(this);return e.radiusTop=this.radiusTop,e.radiusBottom=this.radiusBottom,e.height=this.height,e.numSegments=this.numSegments,e},GameLib.D3.Shape.ConvexHull.Cylinder.FromObject=function(e,t){var i=GameLib.D3.API.Shape.FromObject(t),n=GameLib.D3.Shape.ConvexHull.InheritableProperties(e,t);for(var a in n)n.hasOwnProperty(a)&&(i[a]=n[a]);return new GameLib.D3.Shape.ConvexHull.Cylinder(e,i,t.radiusTop,t.radiusBottom,t.height,t.numSegments)},GameLib.D3.Shape.HeightMap=function(e,t,i,n,a,s){if(this.physics=e,this.physics.isNotCannonThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={shapeType:GameLib.D3.API.Shape.SHAPE_TYPE_HEIGHT_MAP}),t instanceof GameLib.D3.Shape.HeightMap)return t;GameLib.Utils.UndefinedOrNull(i)&&(i=[[10,10,10],[10,10,10],[10,10,10]]),this.heightData=i,GameLib.Utils.UndefinedOrNull(n)&&(n=0),this.minValue=n,GameLib.Utils.UndefinedOrNull(a)&&(a=10),this.maxValue=a,GameLib.Utils.UndefinedOrNull(s)&&(s=1),this.elementSize=s,GameLib.D3.Shape.call(this,this.physics,t)},GameLib.D3.Shape.HeightMap.prototype=Object.create(GameLib.D3.Shape.prototype),GameLib.D3.Shape.HeightMap.prototype.constructor=GameLib.D3.Shape.HeightMap,GameLib.D3.Shape.HeightMap.prototype.createInstance=function(){this.instance=new CANNON.Heightfield(this.heightData,{elemSize:this.elementSize}),GameLib.D3.Shape.prototype.createInstance.call(this)},GameLib.D3.Shape.HeightMap.prototype.updateInstance=function(){this.instance.data=this.heightData,this.instance.elemSize=this.elemSize,this.instance.update()},GameLib.D3.Shape.HeightMap.prototype.toApiObject=function(){var e=GameLib.D3.Shape.prototype.toApiObject.call(this);return e.heightData=this.heightData,e.minValue=this.minValue,e.maxValue=this.maxValue,e.elemSize=this.elemSize,e},GameLib.D3.Shape.HeightMap.prototype.setFromMesh=function(){if(null===this.parentMesh)return void console.log("select a mesh first");if(!this.parentMesh.isHeightMap)return void console.log("not a heightmap mesh");var e=Array.prototype.slice.call(this.parentMesh.getHeightData());this.heightData=[];for(var t=0;t<=this.parentMesh.widthSegments;t++){this.heightData[t]=[];for(var i=0;i<=this.parentMesh.heightSegments;i++)this.heightData[t][i]=e[t*(this.parentMesh.widthSegments+1)+i]}this.updateInstance()},GameLib.D3.Shape.HeightMap.FromObject=function(e,t){var i=GameLib.D3.API.Shape.FromObject(t);return new GameLib.D3.Shape.HeightMap(e,i,t.heightData,t.minValue,t.maxValue,t.elemSize)},GameLib.D3.Shape.Plane=function(e,t){if(this.physics=e,this.physics.isNotCannonThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={shapeType:GameLib.D3.API.Shape.SHAPE_TYPE_PLANE}),t instanceof GameLib.D3.Shape.Plane)return t;GameLib.D3.Shape.call(this,this.physics,t)},GameLib.D3.Shape.Plane.prototype=Object.create(GameLib.D3.Shape.prototype),GameLib.D3.Shape.Plane.prototype.constructor=GameLib.D3.Shape.Plane,GameLib.D3.Shape.Plane.prototype.createInstance=function(){this.instance=new CANNON.Plane,GameLib.D3.Shape.prototype.createInstance.call(this)},GameLib.D3.Shape.Plane.prototype.updateInstance=function(){},GameLib.D3.Shape.Plane.FromObject=function(e,t){var i=GameLib.D3.API.Shape.FromObject(t);return new GameLib.D3.Shape.Plane(e,i)},GameLib.D3.Shape.Sphere=function(e,t,i){if(this.physics=e,this.physics.isNotCannonThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={shapeType:GameLib.D3.API.Shape.SHAPE_TYPE_SPHERE}),t instanceof GameLib.D3.Shape.Sphere)return t;GameLib.Utils.UndefinedOrNull(i)&&(i=1),this.radius=i,GameLib.D3.Shape.call(this,this.physics,t)},GameLib.D3.Shape.Sphere.prototype=Object.create(GameLib.D3.Shape.prototype),GameLib.D3.Shape.Sphere.prototype.constructor=GameLib.D3.Shape.Sphere,GameLib.D3.Shape.Sphere.prototype.createInstance=function(){this.instance=new CANNON.Sphere(this.radius),GameLib.D3.Shape.prototype.createInstance.call(this)},GameLib.D3.Shape.Sphere.prototype.updateInstance=function(){this.instance.radius=this.radius,this.instance.updateBoundingSphereRadius()},GameLib.D3.Shape.Sphere.prototype.toApiObject=function(){var e=GameLib.D3.Shape.prototype.toApiObject.call(this);return e.radius=this.radius,e},GameLib.D3.Shape.Sphere.FromObject=function(e,t){var i=GameLib.D3.API.Shape.FromObject(t);return new GameLib.D3.Shape.Sphere(e,i,t.radius)},GameLib.D3.Shape.TriMesh=function(e,t,i,n){if(this.physics=e,this.physics.isNotCannonThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={shapeType:GameLib.D3.API.Shape.SHAPE_TYPE_TRIMESH}),t instanceof GameLib.D3.Shape.TriMesh)return t;GameLib.Utils.UndefinedOrNull(i)&&(i=[]),this.vertices=i,GameLib.Utils.UndefinedOrNull(n)&&(n=[]),this.indices=n,GameLib.D3.Shape.call(this,this.physics,t)},GameLib.D3.Shape.TriMesh.prototype=Object.create(GameLib.D3.Shape.prototype),GameLib.D3.Shape.TriMesh.prototype.constructor=GameLib.D3.Shape.TriMesh,GameLib.D3.Shape.TriMesh.prototype.createInstance=function(){this.instance=new CANNON.TriMesh(this.vertices,this.indices),GameLib.D3.Shape.prototype.createInstance.call(this)},GameLib.D3.Shape.TriMesh.prototype.updateInstance=function(){this.instance.vertices=this.vertices,this.instance.indices=this.indices,this.instance.updateAABB(),this.instance.updateBoundingSphereRadius(),this.instance.updateEdges(),this.instance.updateNormals(),this.instance.updateTree()},GameLib.D3.Skeleton=function(e,t){if(this.graphics=e,this.graphics.isNotThreeThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),t instanceof GameLib.D3.Skeleton)return t;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(e instanceof GameLib.D3.API.Bone)return new GameLib.D3.Bone(this.graphics,e);throw console.warn("apiBone not an instance of API.Bone"),new Error("apiBone not an instance of API.Bone")}.bind(this)),this.boneInverses=this.boneInverses.map(function(e){if(e instanceof GameLib.API.Matrix4)return new GameLib.Matrix4(this.graphics,e,this);throw console.warn("boneInverse not an instance of API.Matrix4"),new Error("boneInverse not an instance of API.Matrix4")}.bind(this)),this.boneMatrices=this.boneMatrices.map(function(e){if(e instanceof GameLib.API.Matrix4)return new GameLib.Matrix4(this.graphics,e,this);throw console.warn("boneMatrices not an instance of API.Matrix4"),new Error("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){var t=this.bones.map(function(e){if(GameLib.Utils.UndefinedOrNull(e))throw new Error("no bone");if(GameLib.Utils.UndefinedOrNull(e.instance))throw new Error("no bone instance");return e.instance}),i=this.bones.reduce(function(e,t){return e||(0===t.parentBoneIds.length?t.instance:null)},null);if(GameLib.Utils.UndefinedOrNull(i))throw new Error("could not find parent bone instance");this.instance=new THREE.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){return function(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(){return new GameLib.D3.API.Skeleton(this.id,this.name,this.bones.map(function(e){return e.toApiObject()}),this.boneInverses.map(function(e){return e.toApiObject()}),this.useVertexTexture,this.boneTextureWidth,this.boneTextureHeight,this.boneMatrices.map(function(e){return e.toApiObject()}),this.boneTexture,GameLib.Utils.IdOrNull(this.parentEntity))},GameLib.D3.Skeleton.FromObject=function(e,t){ +if(!t)return null;var i=GameLib.D3.API.Skeleton.FromObject(t);return new GameLib.D3.Skeleton(e,i)},GameLib.D3.Solver=function(e,t){if(this.physics=e,this.physics.isNotCannonThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),t instanceof GameLib.D3.Solver)return t;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=new CANNON.GSSolver;else{if(this.solverType!==GameLib.D3.API.Solver.SPLIT_SOLVER)throw new Error("unsupported solver type: "+this.solverType);this.instance=new CANNON.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.instance instanceof CANNON.GSSolver||(this.instance=new CANNON.GSSolver)),this.solverType===GameLib.D3.API.Solver.SPLIT_SOLVER&&(this.instance instanceof CANNON.SplitSolver||(this.instance=new CANNON.SplitSolver)),this.instance.iterations=this.iterations,this.instance.tolerance=this.tolerance},GameLib.D3.Solver.prototype.toApiObject=function(){return new GameLib.D3.API.Solver(this.id,this.name,this.solverType,this.iterations,this.tolerance,GameLib.Utils.IdOrNull(this.parentEntity))},GameLib.D3.Solver.FromObject=function(e,t){var i=GameLib.D3.API.Solver.FromObject(t);return new GameLib.D3.Solver(e,i)},GameLib.D3.Spline=function(e,t){if(this.graphics=e,this.graphics.isNotThreeThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),t instanceof GameLib.D3.Spline)return t;GameLib.D3.API.Spline.call(this,t.id,t.name,t.vertices,t.parentEntity),this.vertices=this.vertices.map(function(t){return new GameLib.Vector3(e,t,this)}),GameLib.Component.call(this)},GameLib.D3.Spline.prototype=Object.create(GameLib.D3.API.Spline.prototype),GameLib.D3.Spline.prototype.constructor=GameLib.D3.Spline,GameLib.D3.Spline.prototype.createInstance=function(){var e=this.vertices.map(function(e){if(GameLib.Utils.UndefinedOrNull(e))throw new Error("no vertex");if(GameLib.Utils.UndefinedOrNull(e.instance))throw new Error("no vertex instance");return e.instance});this.instance=THREE.CatmullRomCurve3(e),GameLib.Component.prototype.createInstance.call(this)},GameLib.D3.Spline.prototype.updateInstance=function(){var e=this.vertices.map(function(e){if(GameLib.Utils.UndefinedOrNull(e))throw new Error("no vertex");if(GameLib.Utils.UndefinedOrNull(e.instance))throw new Error("no vertex instance");return e.instance});this.instance=new THREE.CatmullRomCurve3(e)},GameLib.D3.Spline.prototype.toApiObject=function(){return new GameLib.D3.API.Spline(this.id,this.name,this.vertices.map(function(e){return e.toApiObject()}),GameLib.Utils.IdOrNull(this.parentEntity))},GameLib.D3.Spline.FromObject=function(e,t){var i=GameLib.D3.API.Spline.FromObject(t);return new GameLib.D3.Spline(e,i)},GameLib.D3.Spline.prototype.getPointAt=function(e){var t=this.instance.getPointAt(e);return new GameLib.Vector3(this.graphics,new GameLib.API.Vector3(t.x,t.y,t.z),this,.1)},GameLib.D3.Texture=function(e,t){if(this.graphics=e,this.graphics.isNotThreeThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),t instanceof GameLib.D3.Texture)return t;GameLib.D3.API.Texture.call(this,t.id,t.textureType,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=new GameLib.Vector2(this.graphics,this.offset,this),this.repeat=new GameLib.Vector2(this.graphics,this.repeat,this),this.image instanceof GameLib.API.Image&&(this.image=new GameLib.Image(this.graphics,this.image)),this.images=this.images.map(function(e){return e instanceof GameLib.API.Image?new GameLib.Image(this.graphics,e):e}.bind(this)),this.canvas instanceof GameLib.API.Canvas&&(this.canvas=new GameLib.Canvas(this.graphics,this.canvas)),GameLib.Component.call(this,{image:GameLib.Image,images:[GameLib.Image],canvas:GameLib.Canvas})},GameLib.D3.Texture.prototype=Object.create(GameLib.D3.API.Texture.prototype),GameLib.D3.Texture.prototype.constructor=GameLib.D3.Texture,GameLib.D3.Texture.prototype.createInstance=function(){if(this.textureType===GameLib.D3.API.Texture.TEXTURE_TYPE_CUBE){if(6!==this.images.length)throw new Error("not enough images for cube texture");var e=this.images.map(function(e){if(GameLib.Utils.UndefinedOrNull(e))throw new Error("no image");if(GameLib.Utils.UndefinedOrNull(e.instance))throw new Error("no image instance");return e.instance});this.instance=new THREE.CubeTexture(e)}else if(this.textureType===GameLib.D3.API.Texture.TEXTURE_TYPE_NORMAL)GameLib.Utils.UndefinedOrNull(this.image)||GameLib.Utils.UndefinedOrNull(this.image.instance)?this.instance=new THREE.Texture:this.instance=new THREE.Texture(this.image.instance);else if(this.textureType===GameLib.D3.API.Texture.TEXTURE_TYPE_CANVAS)if(GameLib.Utils.UndefinedOrNull(this.canvas))this.instance=new THREE.Texture;else{if(GameLib.Utils.UndefinedOrNull(this.canvas.instance))throw new Error("no canvas instance");this.instance=new THREE.Texture(this.canvas.instance)}this.mapping=this.instance.mapping,this.encoding=this.instance.encoding,this.format=this.instance.format,this.instance.name=this.name,this.instance.flipY=this.flipY,this.instance.offset.x=this.offset.x,this.instance.offset.y=this.offset.y,this.instance.repeat.x=this.repeat.x,this.instance.repeat.y=this.repeat.y,this.instance.wrapS=this.wrapS,this.instance.wrapT=this.wrapT,this.instance.needsUpdate=!0,GameLib.Component.prototype.createInstance.call(this)},GameLib.D3.Texture.prototype.updateInstance=function(e){if(GameLib.Utils.UndefinedOrNull(this.instance))try{return void this.createInstance()}catch(e){console.error(e)}if(GameLib.Utils.UndefinedOrNull(e))throw new Error("need to specify a property");if("image"===e){if(this.textureType===GameLib.D3.API.Texture.TEXTURE_TYPE_NORMAL){if(GameLib.Utils.UndefinedOrNull(this.image)&&this.instance.image)try{this.createInstance()}catch(e){console.error(e)}if(this.image&&this.image.instance&&this.instance.image!==this.image.instance)try{this.createInstance()}catch(e){console.error(e)}}else if(this.textureType===GameLib.D3.API.Texture.TEXTURE_TYPE_CANVAS){if(GameLib.Utils.UndefinedOrNull(this.canvas)&&this.instance.canvas)try{this.createInstance()}catch(e){console.error(e)}if(this.canvas&&this.canvas.instance&&this.instance.image!==this.canvas.instance)try{this.createInstance()}catch(e){console.error(e)}}else this.textureType===GameLib.D3.API.Texture.TEXTURE_TYPE_CUBE&&console.log("todo : cube images change check here");this.publish(GameLib.Event.IMAGE_CHANGED,{texture:this}),this.instance.needsUpdate=!0}"name"===e&&(this.instance.name=this.name),"flipY"===e&&(this.instance.flipY=this.flipY),"encoding"===e&&(this.instance.encoding=this.encoding),"offset"===e&&(this.instance.offset.x=this.offset.x,this.instance.offset.y=this.offset.y),"repeat"===e&&(this.instance.repeat.x=this.repeat.x,this.instance.repeat.y=this.repeat.y),"mapping"===e&&(this.instance.mapping=this.mapping),"format"===e&&(this.instance.format=this.format),"wrapS"===e&&(this.instance.wrapS=this.wrapS),"wrapT"===e&&(this.instance.wrapT=this.wrapT),"animated"===e&&GameLib.Event.Emit(GameLib.Event.TEXTURE_ANIMATED_CHANGE,{texture:this})},GameLib.D3.Texture.prototype.toApiObject=function(){return new GameLib.D3.API.Texture(this.id,this.textureType,this.name,GameLib.Utils.IdOrNull(this.image),this.images.map(function(e){return GameLib.Utils.IdOrNull(e)}),this.wrapS,this.wrapT,this.repeat.toApiObject(),this.data,this.format,this.mapping,this.magFilter,this.minFilter,this.textureType,this.anisotropy,this.offset.toApiObject(),this.generateMipmaps,this.flipY,this.mipmaps,this.unpackAlignment,this.premultiplyAlpha,this.encoding,GameLib.Utils.IdOrNull(this.canvas),this.animated,this.reverseAnimation,this.forward,GameLib.Utils.IdOrNull(this.parentEntity))},GameLib.D3.Texture.FromObject=function(e,t){var i=GameLib.D3.API.Texture.FromObject(t);return new GameLib.D3.Texture(e,i)},GameLib.D3.TriangleEdge=function(e,t){this.triangle=e,this.edge=t},GameLib.D3.Vertex=function(e,t){if(this.implementation=e,e instanceof GameLib.GraphicsRuntime)this.implementation.isNotThreeThrow();else{if(!(e instanceof GameLib.PhysicsRuntime))throw new Error("Unhandled implementation : "+e);this.implementation.isNotCannonThrow()}if(GameLib.Utils.UndefinedOrNull(t)&&(t={}),t instanceof GameLib.D3.Vertex)return t;GameLib.D3.API.Vertex.call(this,t.position,t.boneWeights),this.position=new GameLib.Vector3(this.implementation,this.position,null),e instanceof GameLib.GraphicsRuntime&&(this.boneWeights=this.boneWeights.map(function(e){return new GameLib.D3.BoneWeight(this.implementation,e)}.bind(this)))},GameLib.D3.Vertex.prototype=Object.create(GameLib.D3.API.Vertex.prototype),GameLib.D3.Vertex.prototype.constructor=GameLib.D3.Vertex,GameLib.D3.Vertex.prototype.toApiObject=function(){return new GameLib.D3.API.Vertex(this.position.toApiObject(),this.boneWeights.map(function(e){return e.toApiObject()}))},GameLib.D3.Vertex.FromObject=function(e,t){var i=GameLib.D3.API.Vertex.FromObject(t);return new GameLib.D3.Vertex(e,i)},GameLib.D3.Viewport=function(e,t){if(this.graphics=e,this.graphics.isNotThreeThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),t instanceof GameLib.D3.Viewport)return t;GameLib.D3.API.Viewport.call(this,t.id,t.name,t.width,t.height,t.x,t.y,t.parentEntity),GameLib.Component.call(this)},GameLib.D3.Viewport.prototype=Object.create(GameLib.D3.API.Viewport.prototype),GameLib.D3.Viewport.prototype.constructor=GameLib.D3.Viewport,GameLib.D3.Viewport.prototype.createInstance=function(){this.instance=!0,GameLib.Component.prototype.createInstance.call(this)},GameLib.D3.Viewport.prototype.updateInstance=function(){},GameLib.D3.Viewport.prototype.toApiObject=function(){return new GameLib.D3.API.Viewport(this.id,this.name,this.width,this.height,this.x,this.y,GameLib.Utils.IdOrNull(this.parentEntity))},GameLib.D3.Viewport.FromObject=function(e,t){var i=GameLib.D3.API.Viewport.FromObject(t);return new GameLib.D3.Viewport(e,i)},GameLib.DomElement=function(e){if(GameLib.Utils.UndefinedOrNull(e)&&(e={}),e instanceof GameLib.DomElement)return e;GameLib.API.DomElement.call(this,e.id,e.name,e.domElementId,e.parentEntity),this.fullscreen=!1,GameLib.Component.call(this)},GameLib.DomElement.prototype=Object.create(GameLib.API.DomElement.prototype),GameLib.DomElement.prototype.constructor=GameLib.DomElement,GameLib.DomElement.prototype.createInstance=function(){this.instance=document.getElementById(this.domElementId),GameLib.Component.prototype.createInstance.call(this)},GameLib.DomElement.prototype.updateInstance=function(){this.instance=document.getElementById(this.domElementId)},GameLib.DomElement.prototype.toApiObject=function(){return new GameLib.API.DomElement(this.id,this.name,this.domElementId,GameLib.Utils.IdOrNull(this.parentEntity))},GameLib.DomElement.prototype.append=function(e){this.instance.appendChild(e)},GameLib.DomElement.prototype.clear=function(){this.instance.innerHTML=""},GameLib.DomElement.prototype.requestFullscreen=function(e){var t=document.documentElement;t.requestFullscreen?t.requestFullscreen():t.msRequestFullscreen?t.msRequestFullscreen():t.mozRequestFullScreen?t.mozRequestFullScreen():t.webkitRequestFullscreen&&t.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT),this.fullscreen=!0},GameLib.DomElement.prototype.exitFullscreen=function(e){document.exitFullscreen?document.exitFullscreen():document.msExitFullscreen?document.msExitFullscreen():document.mozCancelFullScreen?document.mozCancelFullScreen():document.webkitExitFullscreen&&document.webkitExitFullscreen(),this.fullscreen=!1},GameLib.DomElement.FromObject=function(e){var t=GameLib.API.DomElement.FromObject(e);return new GameLib.DomElement(t)},GameLib.EntityManager=function(e){if(GameLib.Utils.UndefinedOrNull(e)&&(e={}),e instanceof GameLib.EntityManager)return e;GameLib.API.EntityManager.call(this,e.id,e.name,e.entities,e.defaultEntity,e.defaultRenderer,e.parentEntity),this.register={},this.idRegister={},GameLib.Event.Subscribe(GameLib.Event.COMPONENT_REGISTER,this.registerComponent.bind(this)),GameLib.Event.Subscribe(GameLib.Event.REMOVE_COMPONENT,this.removeComponent.bind(this)),GameLib.Component.call(this,{entities:[GameLib.Entity],defaultEntity:GameLib.Entity,defaultRenderer:GameLib.D3.Renderer})},GameLib.EntityManager.prototype=Object.create(GameLib.API.EntityManager.prototype),GameLib.EntityManager.prototype.constructor=GameLib.EntityManager,GameLib.EntityManager.prototype.createInstance=function(){this.instance=GameLib.EntityManager.Instance,GameLib.Component.prototype.createInstance.call(this)},GameLib.EntityManager.prototype.registerComponent=function(e){var t=!1;GameLib.Utils.UndefinedOrNull(this.register[e.component.componentType])&&(this.register[e.component.componentType]={},t=!0),GameLib.Utils.UndefinedOrNull(this.register[e.component.componentType][e.component.id])&&(this.register[e.component.componentType][e.component.id]=e.component,t=!0),GameLib.Utils.UndefinedOrNull(this.idRegister[e.component.id])&&(this.idRegister[e.component.id]=e.component,t=!0),t&&GameLib.Event.Emit(GameLib.Event.REGISTER_UPDATE,{componentType:e.component.componentType,components:this.register[e.component.componentType],idRegister:this.idRegister})},GameLib.EntityManager.prototype.removeComponent=function(e){var t=!0;GameLib.Utils.UndefinedOrNull(this.register[e.component.componentType])||GameLib.Utils.UndefinedOrNull(this.register[e.component.componentType][e.component.id])||GameLib.Utils.UndefinedOrNull(this.idRegister[e.component.id])?(console.warn("register out of sync"),t=!1):(delete this.register[e.component.componentType][e.component.id],delete this.idRegister[e.component.id]),t&&GameLib.Event.Emit(GameLib.Event.REGISTER_UPDATE,{componentType:e.component.componentType,components:this.register[e.component.componentType],idRegister:this.idRegister})},GameLib.EntityManager.prototype.createEntity=function(e){var t=new GameLib.API.Entity(null,e,null,null,this),i=new GameLib.Entity(t);return this.entities.push(i),this.defaultEntity=i,GameLib.Event.Emit(GameLib.Event.NEW_ENTITY,{entity:i}),i},GameLib.EntityManager.prototype.findEntityById=function(e){var t=this.register[GameLib.Component.ENTITY][e];return t||null},GameLib.EntityManager.prototype.findComponentById=function(e){return this.idRegister[e]},GameLib.EntityManager.prototype.findHelperByObject=function(e){return Object.keys(this.register[GameLib.Component.HELPER]).reduce(function(t,i){return this.register[GameLib.Component.HELPER][i].object===e&&(t=this.register[GameLib.Component.HELPER][i]),t}.bind(this),null)},GameLib.EntityManager.prototype.findSceneByObject=function(e){return Object.keys(this.register[GameLib.Component.SCENE]).reduce(function(t,i){return-1===this.register[GameLib.Component.SCENE][i].meshes.indexOf(e)&&-1===this.register[GameLib.Component.SCENE][i].lights.indexOf(e)||(t=this.register[GameLib.Component.SCENE][i]),t}.bind(this),null)},GameLib.EntityManager.prototype.addEntity=function(e){e.parentEntityManager=this,this.entities.push(e)},GameLib.EntityManager.prototype.queryByName=function(e){return this.entities.reduce(function(t,i){return i.name===e&&(t=i),t},null)},GameLib.EntityManager.prototype.removeEntity=function(e){var t=this.entities.indexOf(e);return-1===t?(console.log("failed to remove entity : ",e),!1):(this.entities.splice(t,1),e.parentEntityManager=null,!0)},GameLib.EntityManager.prototype.findEntities=function(e){return this.entities.reduce(function(t,i){return e.reduce(function(e,t){return i.hasComponent(t)||(e=!1),e},!0)&&t.push(i),t},[])},GameLib.EntityManager.prototype.queryComponents=function(e){var t=[];return e instanceof Array?e.map(function(e){Object.keys(this.register[e]).map(function(i){t.push(this.register[e][i])}.bind(this))}.bind(this)):Object.keys(this.register[e]).map(function(i){t.push(this.register[e][i])}.bind(this)),t},GameLib.EntityManager.prototype.toApiObject=function(){var e=this.entities.map(function(e){return GameLib.Utils.IdOrNull(e)});return new GameLib.API.EntityManager(this.id,this.name,e,GameLib.Utils.IdOrNull(this.defaultEntity),GameLib.Utils.IdOrNull(this.defaultRenderer),GameLib.Utils.IdOrNull(this.parentEntity))},GameLib.EntityManager.FromObject=function(e){var t=GameLib.API.EntityManager.FromObject(e);return new GameLib.EntityManager(t)},GameLib.Entity=function(e){if(GameLib.Utils.UndefinedOrNull(e)&&(e={}),e instanceof GameLib.Entity)return e;GameLib.API.Entity.call(this,e.id,e.name,e.components,e.parentEntity,e.parentEntityManager),GameLib.Component.call(this,{components:[GameLib.Component],activeComponent:GameLib.Component})},GameLib.Entity.prototype=Object.create(GameLib.API.Entity.prototype);GameLib.Entity.prototype.constructor=GameLib.Entity,GameLib.Entity.prototype.createInstance=function(){this.instance=!0,GameLib.Component.prototype.createInstance.call(this)},GameLib.Entity.prototype.addComponent=function(e){if(GameLib.Utils.PushUnique(this.components,e),e instanceof GameLib.D3.Mesh)e.getChildrenComponents().map(function(e){GameLib.Utils.PushUnique(this.components,e),e.parentEntity=this}.bind(this));else{e.buildIdToObject();for(var t in e.idToObject)e.idToObject.hasOwnProperty(t)&&e.idToObject[t]!==e&&e.idToObject[t]instanceof GameLib.Component&&(GameLib.Utils.PushUnique(this.components,e.idToObject[t]),e.idToObject[t].parentEntity=this)}e.parentEntity=this},GameLib.Entity.prototype.getComponents=function(e){return this.components.reduce(function(t,i){return i instanceof e&&t.push(i),t},[])},GameLib.Entity.prototype.getFirstComponent=function(e){var t=this.getComponents(e);return t.length>0?t[0]:null},GameLib.Entity.prototype.hasComponent=function(e){return this.components.reduce(function(t,i){return i instanceof e&&(t=!0),t},!1)},GameLib.Entity.prototype.removeComponent=function(e){GameLib.Utils.UndefinedOrNull(e)&&(e=this.activeComponent);var t=this.components.indexOf(e);return-1!==t?this.components.splice(t,1):console.error("component not found"),e.parentEntity=null,!0},GameLib.Entity.prototype.updateInstance=function(){console.log("entity update instance called")},GameLib.Entity.prototype.toApiObject=function(){var e=this.components.map(function(e){return GameLib.Utils.IdOrNull(e)});return new GameLib.API.Entity(this.id,this.name,e,GameLib.Utils.IdOrNull(this.parentEntity),GameLib.Utils.IdOrNull(this.parentEntityManager))},GameLib.Entity.FromObject=function(e,t){var i=GameLib.API.Entity.FromObject(e),n=new GameLib.Entity(i);return GameLib.Utils.UndefinedOrNull(t)?n:(t.addEntity(n),n)},GameLib.GraphicsRuntime=function(e,t,i){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="Graphics ("+e+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=GameLib.GraphicsRuntime.TYPE_THREE_JS),this.graphicsType=i,this.createInstance()},GameLib.GraphicsRuntime.TYPE_THREE_JS=1,GameLib.GraphicsRuntime.prototype.createInstance=function(){this.graphicsType===GameLib.GraphicsRuntime.TYPE_THREE_JS?this.instance=THREE:this.instance=null},GameLib.GraphicsRuntime.prototype.updateInstance=function(e){"graphicsType"===e&&this.createInstance()},GameLib.GraphicsRuntime.prototype.isNotThreeThrow=function(){if(this.instance!==THREE)throw console.error("Only THREE supported"),new Error("Only THREE supported")},GameLib.GUIRuntime=function(e,t,i){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="GUI ("+e+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=GameLib.GUIRuntime.TYPE_DAT_GUI),this.guiType=i,this.createInstance()},GameLib.GUIRuntime.TYPE_DAT_GUI=1,GameLib.GUIRuntime.prototype.createInstance=function(){this.guiType===GameLib.GUIRuntime.TYPE_DAT_GUI?this.instance=dat.GUI:this.instance=null},GameLib.GUIRuntime.prototype.updateInstance=function(e){"guiType"===e&&this.createInstance()},GameLib.GUIRuntime.prototype.isNotDatGuiThrow=function(){if(this.instance!==dat.GUI)throw console.error("Only dat.gui supported"),new Error("Only dat.gui supported")},GameLib.GUI=function(e,t){if(this.guiRuntime=e,this.guiRuntime.isNotDatGuiThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),t instanceof GameLib.GUI)return t;GameLib.API.GUI.call(this,t.id,t.name,t.domElement,t.objects,t.parentEntity),GameLib.Component.call(this,{domElement:GameLib.DomElement})},GameLib.GUI.prototype=Object.create(GameLib.Component.prototype),GameLib.GUI.prototype.constructor=GameLib.GUI,GameLib.GUI.prototype.createInstance=function(){this.instance=new this.guiRuntime.instance({autoPlace:!1}),GameLib.Component.prototype.createInstance.call(this)},GameLib.GUI.prototype.updateInstance=function(e){console.log("todo: implement gui update instance:"+e)},GameLib.GUI.prototype.toApiObject=function(){return new GameLib.API.GUI(this.id,this.name,GameLib.Utils.IdOrNull(this.domElement),objects.map(function(e){return console.log("todo: check this"+e),GameLib.Utils.IdOrNull(e)}),GameLib.Utils.IdOrNull(this.parentEntity))},GameLib.GUI.FromObject=function(e,t){var i=GameLib.API.GUI.FromObject(t);return new GameLib.GUI(e,i)},GameLib.GUI.prototype.removeEmtpyFolders=function(){this.instance.removeEmptyFolders()},GameLib.GUI.prototype.removeAllFolders=function(){this.instance.removeAllFolders()},GameLib.GUI.prototype.addFolder=function(e){try{return this.instance.addFolder(e)}catch(t){try{return e+=" duplicate ("+GameLib.Utils.RandomId()+")",this.instance.addFolder(e)}catch(e){return console.log(e.message),null}}},GameLib.Image=function(e){if(GameLib.Utils.UndefinedOrNull(e)&&(e={}),e instanceof GameLib.Image)return e;GameLib.API.Image.call(this,e.id,e.name,e.fileName,e.extension,e.path,e.contentType,e.size,e.parentEntity),GameLib.Component.call(this)},GameLib.Image.prototype=Object.create(GameLib.API.Image.prototype),GameLib.Image.prototype.constructor=GameLib.Image,GameLib.Image.prototype.createInstance=function(){GameLib.Event.Emit(GameLib.Event.LOAD_IMAGE,{image:this},function(e){this.instance=e,GameLib.Component.prototype.createInstance.call(this)}.bind(this),function(e){console.error(e),this.instance=null,GameLib.Component.prototype.createInstance.call(this)}.bind(this))},GameLib.Image.prototype.updateInstance=function(e){GameLib.Utils.UndefinedOrNull(e)&&console.warn("unknown property update for Image: "+e),"fileName"!==e&&"extension"!==e&&"path"!==e||this.createInstance()},GameLib.Image.prototype.toApiObject=function(){return new GameLib.API.Image(this.id,this.name,this.fileName,this.extension,this.path,this.contentType,this.size,GameLib.Utils.IdOrNull(this.parentEntity))},GameLib.Image.FromObject=function(e){return new GameLib.Image(GameLib.API.Image.FromObject(e))},GameLib.Matrix4=function(e,t,i,n){if(this.graphics=e,this.graphics.isNotThreeThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),t instanceof GameLib.Matrix4)return t;GameLib.API.Matrix4.call(this,t.rows[0],t.rows[1],t.rows[2],t.rows[3]),GameLib.Utils.UndefinedOrNull(i)&&(i=null),this.parentObject=i,GameLib.Utils.UndefinedOrNull(n)&&(n=.001),this.grain=n,this.rows=this.rows.map(function(e){if(e instanceof GameLib.API.Vector4)return new GameLib.Vector4(this.graphics,e,this,this.grain);throw console.warn("Attempted conversion of wrong instance"),new Error("Attempted conversion of wrong instance")}.bind(this)),this.forward=new GameLib.Vector4(this.graphics,this.forward,this,this.grain),this.left=new GameLib.Vector4(this.graphics,this.left,this,this.grain),this.up=new GameLib.Vector4(this.graphics,this.up,this,this.grain),this.createInstance()},GameLib.Matrix4.prototype=Object.create(GameLib.API.Matrix4.prototype),GameLib.Matrix4.prototype.constructor=GameLib.Matrix4,GameLib.Matrix4.prototype.createInstance=function(e){this.instance=new THREE.Matrix4,this.instance.set(this.rows[0].x,this.rows[1].x,this.rows[2].x,this.rows[3].x,this.rows[0].y,this.rows[1].y,this.rows[2].y,this.rows[3].y,this.rows[0].z,this.rows[1].z,this.rows[2].z,this.rows[3].z,this.rows[0].w,this.rows[1].w,this.rows[2].w,this.rows[3].w)},GameLib.Matrix4.prototype.updateInstance=function(){this.instance.set(this.rows[0].x,this.rows[1].x,this.rows[2].x,this.rows[3].x,this.rows[0].y,this.rows[1].y,this.rows[2].y,this.rows[3].y,this.rows[0].z,this.rows[1].z,this.rows[2].z,this.rows[3].z,this.rows[0].w,this.rows[1].w,this.rows[2].w,this.rows[3].w),this.parentObject&&this.parentObject.updateInstance&&this.parentObject.updateInstance()},GameLib.Matrix4.prototype.toApiObject=function(){return new GameLib.API.Matrix4(this.rows[0].toApiObject(),this.rows[1].toApiObject(),this.rows[2].toApiObject(),this.rows[3].toApiObject())},GameLib.Matrix4.FromObject=function(e,t,i){var n=new GameLib.API.Matrix4.FromObject(t);return new GameLib.Matrix4(e,i,n)},GameLib.Matrix4.prototype.lookAt=function(e,t,i){var n=new GameLib.API.Vector3(e.x,e.y,e.z),a=n.subtract(t).normalize();0===a.squared()&&(a.z=1);var s=i.cross(a).normalize();0===s.squared()&&(a.x+=1e-4,s=i.cross(a).normalize());var o=a.cross(s);return this.rows[0].x=s.x,this.rows[0].y=s.y,this.rows[0].z=s.z,this.rows[1].x=o.x,this.rows[1].y=o.y,this.rows[1].z=o.z,this.rows[2].x=a.x,this.rows[2].y=a.y,this.rows[2].z=a.z,this.forward.x=a.x,this.forward.y=a.y,this.forward.z=a.z,this.left.x=s.x,this.left.y=s.y,this.left.z=s.z,this.up.x=o.x,this.up.y=o.y,this.up.z=o.z,this.updateInstance(),this},GameLib.Matrix4.prototype.identity=function(){this.rows=[new GameLib.Vector4(this.graphics,new GameLib.API.Vector4(1,0,0,0),this,this.grain),new GameLib.Vector4(this.graphics,new GameLib.API.Vector4(0,1,0,0),this,this.grain),new GameLib.Vector4(this.graphics,new GameLib.API.Vector4(0,0,1,0),this,this.grain),new GameLib.Vector4(this.graphics,new GameLib.API.Vector4(0,0,0,1),this,this.grain)]},GameLib.Matrix4.prototype.transpose=function(){return this.temp[0].x=this.rows[0].x,this.temp[0].y=this.rows[1].x,this.temp[0].z=this.rows[2].x,this.temp[0].w=this.rows[3].x,this.temp[1].x=this.rows[0].y,this.temp[1].y=this.rows[1].y,this.temp[1].z=this.rows[2].y,this.temp[1].w=this.rows[3].y,this.temp[2].x=this.rows[0].z,this.temp[2].y=this.rows[1].z,this.temp[2].z=this.rows[2].z,this.temp[2].w=this.rows[3].z,this.temp[3].x=this.rows[0].w,this.temp[3].y=this.rows[1].w,this.temp[3].z=this.rows[2].w,this.temp[3].w=this.rows[3].w,this.rows[0].x=this.temp[0].x,this.rows[0].y=this.temp[0].y,this.rows[0].z=this.temp[0].z,this.rows[0].w=this.temp[0].w,this.rows[1].x=this.temp[1].x,this.rows[1].y=this.temp[1].y,this.rows[1].z=this.temp[1].z,this.rows[1].w=this.temp[1].w,this.rows[2].x=this.temp[2].x,this.rows[2].y=this.temp[2].y,this.rows[2].z=this.temp[2].z,this.rows[2].w=this.temp[2].w,this.rows[3].x=this.temp[3].x,this.rows[3].y=this.temp[3].y,this.rows[3].z=this.temp[3].z,this.rows[3].w=this.temp[3].w,this},GameLib.Mouse=function(e){if(GameLib.Utils.UndefinedOrNull(e)&&(e={}),e instanceof GameLib.Mouse)return e;GameLib.API.Mouse.call(this,e.id,e.name,e.x,e.y,e.parentEntity),GameLib.Component.call(this)},GameLib.Mouse.prototype=Object.create(GameLib.API.Mouse.prototype),GameLib.Mouse.prototype.constructor=GameLib.Mouse,GameLib.Mouse.prototype.createInstance=function(){this.instance=!0,GameLib.Component.prototype.createInstance.call(this)},GameLib.Mouse.prototype.updateInstance=function(e){GameLib.Utils.UndefinedOrNull(e)&&console.warn("unknown property update for Mouse: "+e)},GameLib.Mouse.prototype.toApiObject=function(){return new GameLib.API.Mouse(this.id,this.name,this.x,this.y,this.parentEntity)},GameLib.Mouse.prototype.FromObject=function(e){return new GameLib.Mouse(GameLib.API.Mouse.FromObject(e))},GameLib.PhysicsRuntime=function(e,t,i){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="Physics ("+e+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=GameLib.PhysicsRuntime.TYPE_CANNON_JS),this.physicsType=i,this.createInstance()},GameLib.PhysicsRuntime.TYPE_CANNON_JS=1,GameLib.PhysicsRuntime.prototype.createInstance=function(){this.physicsType===GameLib.PhysicsRuntime.TYPE_CANNON_JS?this.instance=CANNON:this.instance=null},GameLib.PhysicsRuntime.prototype.updateInstance=function(e){"physicsType"===e&&this.createInstance()},GameLib.PhysicsRuntime.prototype.isNotCannonThrow=function(){if(this.instance!==CANNON)throw console.error("Only CANNON supported"),new Error("Only CANNON supported")},GameLib.Quaternion=function(e,t,i,n){if(this.implementation=e,e instanceof GameLib.GraphicsRuntime)this.physics=null,this.graphics=e,this.graphics.isNotThreeThrow();else{if(!(e instanceof GameLib.PhysicsRuntime))throw new Error("Unhandled implementation : "+e);this.graphics=null,this.physics=e,this.physics.isNotCannonThrow()}if(GameLib.Utils.UndefinedOrNull(t)&&(t={}),t instanceof GameLib.Quaternion)return t;GameLib.API.Quaternion.call(this,t.x,t.y,t.z,t.w,t.axis,t.angle),GameLib.Utils.UndefinedOrNull(i)&&(i=null),this.parentObject=i,this.axis=new GameLib.Vector3(this.implementation,this.axis,this,this.grain),Object.defineProperty(this,"angle",GameLib.Utils.LimitToPI("angle",this.angle)),GameLib.Utils.UndefinedOrNull(n)&&(n=.001),this.grain=n,this.createInstance()},GameLib.Quaternion.prototype=Object.create(GameLib.API.Quaternion.prototype),GameLib.Quaternion.prototype.constructor=GameLib.Quaternion,GameLib.Quaternion.prototype.createInstance=function(){this.graphics&&(this.instance=new THREE.Quaternion(this.x,this.y,this.z,this.w)),this.physics&&(this.instance=new CANNON.Quaternion(this.x,this.y,this.z,this.w))},GameLib.Quaternion.prototype.updateInstance=function(e){this.instance.x=this.x,this.instance.y=this.y,this.instance.z=this.z,this.instance.w=this.w,this.parentObject&&this.parentObject.updateInstance&&this.parentObject.updateInstance(e)},GameLib.Quaternion.prototype.toApiObject=function(){return new GameLib.API.Quaternion(this.x,this.y,this.z,this.w,this.axis.toApiObject(),this.angle)},GameLib.Quaternion.prototype.equals=function(e){return this.x===e.x&&this.y===e.y&&this.z===e.z&&this.w===e.w&&this.axis.equals(e.axis)&&this.angle===e.angle},GameLib.Quaternion.prototype.setFrom=function(e){this.x=e.x,this.y=e.y,this.z=e.z,this.w=e.w,this.axis.setFrom(e.axis),this.angle=e.angle},GameLib.Quaternion.prototype.copy=function(e){console.log("todo")},GameLib.SocketsRuntime=function(e,t,i){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="Sockets ("+e+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=GameLib.SocketsRuntime.TYPE_WEB_SOCKET),this.socketsType=i,this.createInstance()},GameLib.SocketsRuntime.TYPE_WEB_SOCKET=1,GameLib.SocketsRuntime.prototype.createInstance=function(){this.socketsType===GameLib.SocketsRuntime.TYPE_WEB_SOCKET?this.instance=WebSocket:this.instance=null},GameLib.SocketsRuntime.prototype.updateInstance=function(e){"socketsType"===e&&this.createInstance()},GameLib.SocketsRuntime.prototype.isNotWebSocketThrow=function(){if(!(this.instance instanceof stats))throw console.error("Only WebSocket supported"),new Error("Only WebSocket supported")},GameLib.StatisticsRuntime=function(e,t,i){GameLib.Utils.UndefinedOrNull(e)&&(e=GameLib.Utils.RandomId()),this.id=e,GameLib.Utils.UndefinedOrNull(t)&&(t="Statistics ("+e+")"),this.name=t,GameLib.Utils.UndefinedOrNull(i)&&(i=GameLib.StatisticsRuntime.TYPE_STATS),this.statisticsType=i,this.createInstance()},GameLib.StatisticsRuntime.TYPE_STATS=1,GameLib.StatisticsRuntime.prototype.createInstance=function(){this.statisticsType===GameLib.StatisticsRuntime.TYPE_STATS?this.instance=Stats:this.instance=null},GameLib.StatisticsRuntime.prototype.updateInstance=function(e){ +"statisticsType"===e&&this.createInstance()},GameLib.StatisticsRuntime.prototype.isNotStatsThrow=function(){if(this.instance!==Stats)throw console.error("Only stats supported"),new Error("Only stats supported")},GameLib.Stats=function(e,t){if(this.stats=e,this.stats.isNotStatsThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),t instanceof GameLib.Stats)return t;GameLib.API.Stats.call(this,t.id,t.name,t.domElement,t.parentEntity),GameLib.Component.call(this,{domElement:GameLib.DomElement})},GameLib.Stats.prototype=Object.create(GameLib.Component.prototype),GameLib.Stats.prototype.constructor=GameLib.Stats,GameLib.Stats.prototype.createInstance=function(){this.instance=this.stats.instance(),this.resize(),this.domElement.instance.parentElement.appendChild(this.instance.dom),GameLib.Component.prototype.createInstance.call(this)},GameLib.Stats.prototype.updateInstance=function(){this.instance=new this.stats},GameLib.Stats.prototype.toApiObject=function(){return new GameLib.API.Stats(this.id,this.name,GameLib.Utils.IdOrNull(this.domElement),GameLib.Utils.IdOrNull(this.parentEntity))},GameLib.Stats.FromObject=function(e,t){var i=GameLib.API.Stats.FromObject(t);return new GameLib.Stats(e,i)},GameLib.Stats.prototype.resize=function(){console.log("override stats resize per implementation")},GameLib.Stats.prototype.start=function(){this.instance.begin()},GameLib.Stats.prototype.end=function(){this.instance.end()},GameLib.System=function(e){if(GameLib.Utils.UndefinedOrNull(e)&&(e={}),e instanceof GameLib.System)return e;GameLib.API.System.call(this,e.id,e.name,e.systemType,e.parentEntity),this.started=!1,this.paused=!1;var t={};e.systemType===GameLib.System.SYSTEM_TYPE_INPUT&&(t.mouseControls=[GameLib.Controls.Mouse],t.keyboardControls=[GameLib.Controls.Keyboard],t.touchControls=[GameLib.Controls.Touch],t.editorControls=[GameLib.Controls.D3.Editor]),e.systemType===GameLib.System.SYSTEM_TYPE_AUDIO&&(t.audioComponents=[GameLib.D3.Audio]),GameLib.Component.call(this,t)},GameLib.System.prototype=Object.create(GameLib.API.System.prototype),GameLib.System.prototype.constructor=GameLib.System,GameLib.System.SYSTEM_TYPE_NONE=0,GameLib.System.SYSTEM_TYPE_RENDER=1,GameLib.System.SYSTEM_TYPE_ANIMATION=2,GameLib.System.SYSTEM_TYPE_INPUT=4,GameLib.System.SYSTEM_TYPE_STORAGE=8,GameLib.System.SYSTEM_TYPE_GUI=16,GameLib.System.SYSTEM_TYPE_PHYSICS=32,GameLib.System.SYSTEM_TYPE_LINKING=64,GameLib.System.SYSTEM_TYPE_CUSTOM=128,GameLib.System.SYSTEM_TYPE_VISUALIZATION=256,GameLib.System.SYSTEM_TYPE_PARTICLE=512,GameLib.System.SYSTEM_TYPE_AUDIO=1024,GameLib.System.SYSTEM_TYPE_ALL=65535,GameLib.System.prototype.createInstance=function(){this.instance=!0,GameLib.Component.prototype.createInstance.call(this)},GameLib.System.prototype.start=function(){this.started=!0,console.log("starting "+this.name)},GameLib.System.prototype.stop=function(){this.started=!1,console.log("stopping "+this.name)},GameLib.System.prototype.toApiObject=function(){return new GameLib.API.System(this.id,this.name,this.systemType,GameLib.Utils.IdOrNull(this.parentEntity))},GameLib.System.prototype.restart=function(){console.log("restarting system : "+this.name),this.stop(),this.start()},GameLib.System.Animation=function(e){GameLib.System.call(this,e),this.animations={},this.latest={},this.textures={},this.textureIds=[],this.animationMeshAddedSubscription=null,this.animationMeshRemovedSubscription=null,this.instanceCreatedSubscription=null,this.removeComponentSubscription=null,this.textureAnimatedSubscription=null,this.animateTextureInstanceSubscription=null},GameLib.System.Animation.prototype=Object.create(GameLib.System.prototype),GameLib.System.Animation.prototype.constructor=GameLib.System.Animation,GameLib.System.Animation.prototype.start=function(){GameLib.System.prototype.start.call(this),this.beforeRenderSubscription=GameLib.Event.Subscribe(GameLib.Event.BEFORE_RENDER,this.beforeRender.bind(this)),GameLib.EntityManager.Instance.queryComponents(GameLib.Component.ANIMATION).map(function(e){e.meshes.map(function(t){this.attachAnimation(e,t)}.bind(this))}.bind(this)),this.animationMeshAddedSubscription=GameLib.Event.Subscribe(GameLib.Event.ANIMATION_MESH_ADDED,function(e){this.attachAnimation(e.animation,e.mesh)}.bind(this)),this.animationMeshRemovedSubscription=GameLib.Event.Subscribe(GameLib.Event.ANIMATION_MESH_REMOVED,function(e){this.detachAnimation(e.mesh)}.bind(this)),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.textureAnimatedSubscription=GameLib.Event.Subscribe(GameLib.Event.TEXTURE_ANIMATED_CHANGE,this.textureAnimatedChange.bind(this)),this.animateTextureInstanceSubscription=GameLib.Event.Subscribe(GameLib.Event.ANIMATE_TEXTURE_INSTANCE,this.animateTextureInstance.bind(this))},GameLib.System.Animation.prototype.instanceCreated=function(e){if(e.component instanceof GameLib.D3.Texture&&e.component.animated){if(e.component.repeat.x>1||e.component.repeat.x<0)return console.warn("cannot animate a texture with repeat.x greater than 1 or less than 0"),void(e.component.animated=!1);if(e.component.repeat.y>1||e.component.repeat.y<0)return console.warn("cannot animate a texture with repeat.y greater than 1 or less than 0"),void(e.component.animated=!1);this.textures[e.component.id]=e.component,this.textureIds=Object.keys(this.textures)}},GameLib.System.Animation.prototype.removeComponent=function(e){e.component instanceof GameLib.D3.Texture&&e.component.animated&&(GameLib.Utils.UndefinedOrNull(this.textures[e.component.id])?console.warn("tried to remove an animated texture, which should have been in the list but isnt: "+e.component.name):(delete this.textures[e.component.id],this.textureIds=Object.keys(this.textures)))},GameLib.System.Animation.prototype.textureAnimatedChange=function(e){if(e.texture.animated){if(e.texture.repeat.x>1||e.texture.repeat.x<0)return console.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)return console.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)}else GameLib.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):(delete this.textures[e.texture.id],this.textureIds=Object.keys(this.textures))},GameLib.System.Animation.prototype.animateTextureInstance=function(e){return e.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){var t=e.delta;for(var i in this.animations)if(this.animations.hasOwnProperty(i)){var n=[];if(this.animations[i].length>0)for(var a=!1,s=0;s=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=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){var t=!1;e.backupQuaternionAngleDescriptor&&(Object.defineProperty(e.quaternion,"angle",e.backupQuaternionAngleDescriptor),delete e.backupQuaternionAngleDescriptor,t=!0),e.backupQuaternionAxisXDescriptor&&(Object.defineProperty(e.quaternion.axis,"x",e.backupQuaternionAxisXDescriptor),delete e.backupQuaternionAxisXDescriptor,t=!0),e.backupQuaternionAxisYDescriptor&&(Object.defineProperty(e.quaternion.axis,"y",e.backupQuaternionAxisYDescriptor),delete e.backupQuaternionAxisYDescriptor,t=!0),e.backupQuaternionAxisZDescriptor&&(Object.defineProperty(e.quaternion.axis,"z",e.backupQuaternionAxisZDescriptor),delete e.backupQuaternionAxisXDescriptor,t=!0),e.backupRotationXDescriptor&&(Object.defineProperty(e.rotation,"x",e.backupRotationXDescriptor),delete e.backupRotationXDescriptor,t=!0),e.backupRotationYDescriptor&&(Object.defineProperty(e.rotation,"y",e.backupRotationYDescriptor),delete e.backupRotationYDescriptor,t=!0),e.backupRotationZDescriptor&&(Object.defineProperty(e.rotation,"z",e.backupRotationZDescriptor),delete e.backupRotationZDescriptor,t=!0),e.backupPositionXDescriptor&&(Object.defineProperty(e.position,"x",e.backupPositionXDescriptor),delete e.backupPositionXDescriptor,t=!0),e.backupPositionYDescriptor&&(Object.defineProperty(e.position,"y",e.backupPositionYDescriptor),delete e.backupPositionYDescriptor,t=!0),e.backupPositionZDescriptor&&(Object.defineProperty(e.position,"z",e.backupPositionZDescriptor),delete e.backupPositionZDescriptor,t=!0),e.backupScaleXDescriptor&&(Object.defineProperty(e.scale,"x",e.backupScaleXDescriptor),delete e.backupScaleXDescriptor,t=!0),e.backupScaleYDescriptor&&(Object.defineProperty(e.scale,"y",e.backupScaleYDescriptor),delete e.backupScaleYDescriptor,t=!0),e.backupScaleZDescriptor&&(Object.defineProperty(e.scale,"z",e.backupScaleZDescriptor),delete e.backupScaleZDescriptor,t=!0),this.latest[e.id]&&(e.rotation.x=this.latest[e.id].rotation.x,e.rotation.y=this.latest[e.id].rotation.y,e.rotation.z=this.latest[e.id].rotation.z,e.position.x=this.latest[e.id].position.x,e.position.y=this.latest[e.id].position.y,e.position.z=this.latest[e.id].position.z,e.scale.x=this.latest[e.id].scale.x,e.scale.y=this.latest[e.id].scale.y,e.scale.z=this.latest[e.id].scale.z,e.quaternion.axis.x=this.latest[e.id].quaternion.axis.x,e.quaternion.axis.y=this.latest[e.id].quaternion.axis.y,e.quaternion.axis.z=this.latest[e.id].quaternion.axis.z,e.quaternion.angle=this.latest[e.id].quaternion.angle,delete this.latest[e.id],t=!0),this.animations[e.id]&&(delete this.animations[e.id],t=!0),t&&e.updateInstance()},GameLib.System.Animation.prototype.attachAnimation=function(e,t){if(this.latest[t.id]={rotation:{x:t.rotation.x,y:t.rotation.y,z:t.rotation.z},position:{x:t.position.x,y:t.position.y,z:t.position.z},scale:{x:t.scale.x,y:t.scale.y,z:t.scale.z},quaternion:{axis:{x:t.quaternion.axis.x,y:t.quaternion.axis.y,z:t.quaternion.axis.z},angle:t.quaternion.angle}},this.animations[t.id]=[],t.backupRotationXDescriptor)throw new Error("already a backed up x descriptor");t.backupQuaternionAngleDescriptor=Object.getOwnPropertyDescriptor(t.quaternion,"angle"),t.backupQuaternionAxisXDescriptor=Object.getOwnPropertyDescriptor(t.quaternion.axis,"x"),t.backupQuaternionAxisYDescriptor=Object.getOwnPropertyDescriptor(t.quaternion.axis,"y"),t.backupQuaternionAxisZDescriptor=Object.getOwnPropertyDescriptor(t.quaternion.axis,"z"),t.backupRotationXDescriptor=Object.getOwnPropertyDescriptor(t.rotation,"x"),t.backupRotationYDescriptor=Object.getOwnPropertyDescriptor(t.rotation,"y"),t.backupRotationZDescriptor=Object.getOwnPropertyDescriptor(t.rotation,"z"),t.backupPositionXDescriptor=Object.getOwnPropertyDescriptor(t.position,"x"),t.backupPositionYDescriptor=Object.getOwnPropertyDescriptor(t.position,"y"),t.backupPositionZDescriptor=Object.getOwnPropertyDescriptor(t.position,"z"),t.backupScaleXDescriptor=Object.getOwnPropertyDescriptor(t.scale,"x"),t.backupScaleYDescriptor=Object.getOwnPropertyDescriptor(t.scale,"y"),t.backupScaleZDescriptor=Object.getOwnPropertyDescriptor(t.scale,"z"),Object.defineProperty(t.quaternion,"angle",{get:this.getProperty(t,"angle","quaternion"),set:this.setProperty(t,e,"angle","quaternion"),configurable:!0}),Object.defineProperty(t.quaternion.axis,"x",{get:this.getSubProperty(t,"x","quaternion","axis"),set:this.setSubProperty(t,e,"x","quaternion","axis"),configurable:!0}),Object.defineProperty(t.quaternion.axis,"y",{get:this.getSubProperty(t,"y","quaternion","axis"),set:this.setSubProperty(t,e,"y","quaternion","axis"),configurable:!0}),Object.defineProperty(t.quaternion.axis,"z",{get:this.getSubProperty(t,"z","quaternion","axis"),set:this.setSubProperty(t,e,"z","quaternion","axis"),configurable:!0}),Object.defineProperty(t.rotation,"x",{get:this.getProperty(t,"x","rotation"),set:this.setProperty(t,e,"x","rotation"),configurable:!0}),Object.defineProperty(t.rotation,"y",{get:this.getProperty(t,"y","rotation"),set:this.setProperty(t,e,"y","rotation"),configurable:!0}),Object.defineProperty(t.rotation,"z",{get:this.getProperty(t,"z","rotation"),set:this.setProperty(t,e,"z","rotation"),configurable:!0}),Object.defineProperty(t.scale,"x",{get:this.getProperty(t,"x","scale"),set:this.setProperty(t,e,"x","scale"),configurable:!0}),Object.defineProperty(t.scale,"y",{get:this.getProperty(t,"y","scale"),set:this.setProperty(t,e,"y","scale"),configurable:!0}),Object.defineProperty(t.scale,"z",{get:this.getProperty(t,"z","scale"),set:this.setProperty(t,e,"z","scale"),configurable:!0}),Object.defineProperty(t.position,"x",{get:this.getProperty(t,"x","position"),set:this.setProperty(t,e,"x","position"),configurable:!0}),Object.defineProperty(t.position,"y",{get:this.getProperty(t,"y","position"),set:this.setProperty(t,e,"y","position"),configurable:!0}),Object.defineProperty(t.position,"z",{get:this.getProperty(t,"z","position"),set:this.setProperty(t,e,"z","position"),configurable:!0})},GameLib.System.Animation.prototype.getSubProperty=function(e,t,i,n){return function(){return this.latest[e.id][i][n][t]}.bind(this)},GameLib.System.Animation.prototype.setSubProperty=function(e,t,i,n,a){return function(s){var o=Number(this.latest[e.id][n][a][i]);this.latest[e.id][n][a][i]=s,this.animations[e.id].push({type:n,axis:i,from:o,to:s,animation:t,mesh:e})}.bind(this)},GameLib.System.Animation.prototype.getProperty=function(e,t,i){return function(){return this.latest[e.id][i][t]}.bind(this)},GameLib.System.Animation.prototype.setProperty=function(e,t,i,n){return function(a){var s=Number(this.latest[e.id][n][i]);this.latest[e.id][n][i]=a,this.animations[e.id].push({type:n,axis:i,from:s,to:a,animation:t,mesh:e})}.bind(this)},GameLib.System.Animation.prototype.stop=function(){GameLib.System.prototype.stop.call(this),this.beforeRenderSubscription.remove(),this.animationMeshAddedSubscription.remove(),this.animationMeshRemovedSubscription.remove(),this.animations={},GameLib.EntityManager.Instance.queryComponents(GameLib.Component.MESH).map(function(e){for(var t in this.latest)this.latest.hasOwnProperty(t)&&t===e.id&&this.detachAnimation(e)}.bind(this)),this.instanceCreatedSubscription.remove(),this.removeComponentSubscription.remove(),this.textureAnimatedSubscription.remove(),this.animateTextureInstanceSubscription.remove()},GameLib.System.Audio=function(e){GameLib.System.call(this,e),this.instanceCreatedSubscription=null,this.removeComponentSubscription=null,this.playAudioSubscription=null,this.pauseAllAudioSubscription=null,this.muteAudioSubscription=null,this.continueAllAudioSubscription=null,this.stopAudioSubscription=null,this.stopAllAudioSubscription=null,this.mute=!1,this.paused=[],this.audioComponents=[],this.toPlay=[]},GameLib.System.Audio.prototype=Object.create(GameLib.System.prototype),GameLib.System.Audio.prototype.constructor=GameLib.System.Audio,GameLib.System.Audio.prototype.start=function(){GameLib.System.prototype.start.call(this),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.playAudioSubscription=GameLib.Event.Subscribe(GameLib.Event.PLAY_AUDIO,this.playAudio.bind(this)),this.pauseAllAudioSubscription=GameLib.Event.Subscribe(GameLib.Event.PAUSE_ALL_AUDIO,this.pauseAllAudio.bind(this)),this.muteAudioSubscription=GameLib.Event.Subscribe(GameLib.Event.MUTE_AUDIO,this.muteAudio.bind(this)),this.continueAllAudioSubscription=GameLib.Event.Subscribe(GameLib.Event.CONTINUE_ALL_AUDIO,this.continueAllAudio.bind(this)),this.stopAudioSubscription=GameLib.Event.Subscribe(GameLib.Event.STOP_AUDIO,this.stopAudio.bind(this)),this.stopAllAudioSubscription=GameLib.Event.Subscribe(GameLib.Event.STOP_ALL_AUDIO,this.stopAllAudio.bind(this))},GameLib.System.Audio.prototype.instanceCreated=function(e){if(e.component instanceof GameLib.D3.Audio){GameLib.Utils.PushUnique(this.audioComponents,e.component),e.component.instance.onEnded=function(){this.isPlaying=!1,GameLib.Event.Emit(GameLib.Event.AUDIO_ENDED,{audio:e.component})};var t=this.toPlay.indexOf(e.component.name);-1!==t&&(GameLib.Event.Emit(GameLib.Event.PLAY_AUDIO,{name:e.component.name}),this.toPlay.splice(t,1))}},GameLib.System.Audio.prototype.playAudio=function(e){var t=!1;this.audioComponents.map(function(i){i.name===e.name&&(t=!0,i.instance||console.log("audio not ready yet"),i.overplay?(i.instance.isPlaying&&i.instance.stop(),i.instance.offset=0,i.instance.play()):i.instance.isPlaying||i.instance.play())}.bind(this)),t||(console.log("delaying audio play until loaded for: "+e.name),this.toPlay.push(e.name))},GameLib.System.Audio.prototype.pauseAllAudio=function(e){this.paused=[],this.audioComponents.map(function(e){e.instance.isPlaying&&(this.paused.push(e),e.paused=!0,e.updateInstance("paused"))}.bind(this))},GameLib.System.Audio.prototype.continueAllAudio=function(e){this.paused.map(function(e){e.paused=!1,e.updateInstance("paused")}),this.paused=[]},GameLib.System.Audio.prototype.stopAllAudio=function(e){this.audioComponents.map(function(e){e.instance.isPlaying&&e.instance.stop()})},GameLib.System.Audio.prototype.stopAudio=function(e){this.audioComponents.map(function(t){t.name===e.name&&t.instance.isPlaying&&t.instance.stop()})},GameLib.System.Audio.prototype.removeComponent=function(e){},GameLib.System.Audio.prototype.muteAudio=function(){this.mute=!this.mute,this.mute?(this.audioVolumes=this.audioComponents.reduce(function(e,t){return e.push({audio:t,volume:t.volume}),t.volume=0,t.updateInstance("volume"),e},[]),GameLib.Event.Emit(GameLib.Event.AUDIO_MUTED,{audioSystem:this})):(this.audioVolumes.map(function(e){e.audio.volume=e.volume,e.audio.updateInstance("volume")}),GameLib.Event.Emit(GameLib.Event.AUDIO_UNMUTED,{audioSystem:this}))},GameLib.System.Audio.prototype.stop=function(){GameLib.System.prototype.stop.call(this),this.instanceCreatedSubscription.remove(),this.removeComponentSubscription.remove(),this.playAudioSubscription.remove(),this.pauseAllAudioSubscription.remove(),this.muteAudioSubscription.remove(),this.continueAllAudioSubscription.remove(),this.stopAudioSubscription.remove(),this.stopAllAudioSubscription.remove()},GameLib.System.CustomCode=function(e){GameLib.System.call(this,e),this.instanceCreatedSubscription=null,this.removeComponentSubscription=null,this.compileSuccessSubscription=null,this.compileFailedSubscription=null,this.subscriptions={}},GameLib.System.CustomCode.prototype=Object.create(GameLib.System.prototype),GameLib.System.CustomCode.prototype.constructor=GameLib.System.CustomCode,GameLib.System.CustomCode.prototype.start=function(){GameLib.System.prototype.start.call(this),GameLib.EntityManager.Instance.queryComponents(GameLib.Component.CUSTOM_CODE).map(function(e){this.subscriptions[e.id]=GameLib.Event.Subscribe(e.eventId,e.instance)}.bind(this)),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.compileSuccessSubscription=GameLib.Event.Subscribe(GameLib.Event.COMPILE_SUCCESS,this.compileSuccess.bind(this)),this.compileFailedSubscription=GameLib.Event.Subscribe(GameLib.Event.COMPILE_FAILED,this.compileFailed.bind(this))},GameLib.System.CustomCode.prototype.instanceCreated=function(e){e.component instanceof GameLib.CustomCode&&(this.subscriptions[e.component.id]&&(console.warn("a component already existed"),this.subscriptions[e.component.id].remove()),this.subscriptions[e.component.id]=GameLib.Event.Subscribe(e.component.eventId,e.component.instance))},GameLib.System.CustomCode.prototype.removeComponent=function(e){e.component instanceof GameLib.CustomCode&&this.subscriptions[e.component.id]&&(this.subscriptions[e.component.id].remove(),delete this.subscriptions[e.component.id])},GameLib.System.CustomCode.prototype.compileSuccess=function(e){this.subscriptions[e.component.id]&&this.subscriptions[e.component.id].remove(),this.subscriptions[e.component.id]=GameLib.Event.Subscribe(e.component.eventId,e.component.instance)},GameLib.System.CustomCode.prototype.compileFailed=function(e){this.subscriptions[e.component.id]&&(this.subscriptions[e.component.id].remove(),delete this.subscriptions[e.component.id])},GameLib.System.CustomCode.prototype.stop=function(){GameLib.System.prototype.stop.call(this),this.instanceCreatedSubscription&&(this.instanceCreatedSubscription.remove(),this.instanceCreatedSubscription=null),this.removeComponentSubscription&&(this.removeComponentSubscription.remove(),this.removeComponentSubscription=null),this.compileSuccessSubscription&&(this.compileSuccessSubscription.remove(),this.compileSuccessSubscription=null),this.compileFailedSubscription&&(this.compileFailedSubscription.remove(),this.compileFailedSubscription=null),Object.keys(this.subscriptions).map(function(e){this.subscriptions[e]&&(this.subscriptions[e].remove(),delete this.subscriptions[e])}.bind(this))},GameLib.System.GUI=function(e){GameLib.System.call(this,e),this.guis=[],this.components=[],this.backupComponents=[],this.exclusiveMode=!1,this.buildGUISubscription=null,this.meshDeletedSubscription=null,this.meshSelectedSubscription=null,this.meshDeselectedSubscription=null,this.newEntitySubscription=null,this.meshSelectionObjects={}},GameLib.System.GUI.prototype=Object.create(GameLib.System.prototype),GameLib.System.GUI.prototype.constructor=GameLib.System.GUI,GameLib.System.GUI.prototype.start=function(){GameLib.System.prototype.start.call(this),this.guis=GameLib.EntityManager.Instance.queryComponents(GameLib.Component.GUI),dat.GUI.prototype.removeEmtpyFolders=function(){for(var e in this.__folders)if(this.__folders.hasOwnProperty(e)){var t=this.__folders[e];0===t.__listening.length&&(t.close(),this.__ul.removeChild(t.domElement.parentNode),delete this.__folders[e],this.onResize())}},dat.GUI.prototype.listen=function(e){this.__listening.length;this.__listening.push(e),delete this.closed,Object.defineProperty(this,"closed",{get:function(){return this.params.closed},set:function(e){this.params.closed=e,this.params.closed?(this.dom.addClass(this.__ul,"closed"),cancelAnimationFrame(this.animationId)):(this.dom.removeClass(this.__ul,"closed"),this.updateDisplaysCallback=function(){this.animationId=requestAnimationFrame(this.updateDisplaysCallback.bind(this)),this.__listening.map(function(e){e.updateDisplay()})}.bind(this),this.animationId=requestAnimationFrame(this.updateDisplaysCallback)),this.onResize(),this.__closeButton&&(this.__closeButton.innerHTML=e?"Open Controls":"Close Controls")},configurable:!0})},dat.GUI.prototype.removeAllFolders=function(){for(var e in this.__folders)if(this.__folders.hasOwnProperty(e)){var t=this.__folders[e];cancelAnimationFrame(t.animationId),t.__controllers.map(function(e){e.remove()}),t.__controllers=[],t.__listening=[],t.close(),this.__ul.removeChild(t.domElement.parentNode),delete this.__folders[e],this.onResize()}},this.guis.map(function(e){e.domElement.instance.parentElement.appendChild(e.instance.domElement)}),this.buildGUISubscription=this.subscribe(GameLib.Event.BUILD_GUI,this.buildGUI),this.meshDeletedSubscription=this.subscribe(GameLib.Event.REMOVE_MESH,this.meshDeleted),this.meshSelectedSubscription=this.subscribe(GameLib.Event.MESH_SELECTED,this.meshSelected),this.meshDeselectedSubscription=this.subscribe(GameLib.Event.MESH_DESELECTED,this.meshDeslected),this.newEntitySubscription=this.subscribe(GameLib.Event.NEW_ENTITY,this.newEntity),this.componentRemovedSubscription=this.subscribe(GameLib.Event.REMOVE_COMPONENT,this.removeComponent)},GameLib.System.GUI.prototype.onChange=function(e,t,i){return function(n){i.map(function(i){i[e][t]=n,i instanceof GameLib.D3.Mesh&&"rotation"===e&&(i.useQuaternion=!1),i instanceof GameLib.D3.Mesh&&"quaternion"===e&&(i.useQuaternion=!0),"function"==typeof i[e].updateInstance?i[e].updateInstance(e):"function"==typeof i[e][t].updateInstance?i[e][t].updateInstance(t):i.updateInstance(e)})}},GameLib.System.GUI.prototype.controller=function(e,t,i,n,a,s,o,r,c){GameLib.Utils.UndefinedOrNull(r)&&(r=-1e3),GameLib.Utils.UndefinedOrNull(c)&&(c=1e3),"axleLocal"!==i&&"directionLocal"!==i||(r=-1,c=1,a=1),"offset"!==i&&"repeat"!==i||(r=-1e3,c=1e3,a=1e-5);var m=e.add(t[i],n,r,c,a).name(i+"."+n);return m.onChange(this.onChange(i,n,o)),s&&m.listen(),m},GameLib.System.GUI.prototype.buildQuaternionControl=function(e,t,i){var n=t.template,a=!1;1===t.affected.length&&(n=t.affected[0],a=!0);var s=t.affected;this.controller(e,n,i,"x",.1,a,s),this.controller(e,n,i,"y",.1,a,s),this.controller(e,n,i,"z",.1,a,s),this.controller(e,n,i,"w",.1,a,s),this.controller(e,n,i,"angle",.001,a,s,-Math.PI,Math.PI),e.add(n[i].axis,"x",-1,1,.01).name("quaternion.axis.x").onChange(function(e){s.map(function(t){t.useQuaternion=!0,t[i].axis.x=Number(e),t.updateInstance("x")})}),e.add(n[i].axis,"y",-1,1,.01).name("quaternion.axis.y").onChange(function(e){s.map(function(t){t.useQuaternion=!0,t[i].axis.y=Number(e),t.updateInstance("y")})}),e.add(n[i].axis,"z",-1,1,.01).name("quaternion.axis.z").onChange(function(e){s.map(function(t){t.useQuaternion=!0,t[i].axis.z=Number(e),t.updateInstance("z")})})},GameLib.System.GUI.prototype.buildVectorControl=function(e,t,i){var n=t.template,a=!1;1===t.affected.length&&(n=t.affected[0],a=!0);var s=t.affected,o=[];GameLib.Utils.isVector4(n[i])&&o.push(this.controller(e,n,i,"w",.01,a,s)),o.push(this.controller(e,n,i,"x",.01,a,s)),o.push(this.controller(e,n,i,"y",.01,a,s)),(GameLib.Utils.isVector3(n[i])||GameLib.Utils.isVector4(n[i]))&&o.push(this.controller(e,n,i,"z",.01,a,s))},GameLib.System.GUI.prototype.buildParentSelectionControl=function(e,t,i){var n=GameLib.Utils.UpperCaseUnderscore(i.replace("parent","")),a=GameLib.Component[n],s=GameLib.EntityManager.Instance.queryComponents(a).reduce(function(e,t){return e[t.name]=t,e},{none:null}),o=t.template,r=t.affected;e.add(o,i,s).listen().onChange(function(e){var t=null;"null"!==e&&(t=GameLib.EntityManager.Instance.findComponentById(e)),r.map(function(e){e[i]=t,"parentEntity"===i&&GameLib.Event.Emit(GameLib.Event.PARENT_ENTITY_CHANGE,{originalEntity:this.initialValue,newEntity:t,object:e}),"parentPhysicsWorld"===i&&GameLib.Event.Emit(GameLib.Event.PARENT_WORLD_CHANGE,{originalWorld:this.initialValue,newWorld:t,object:e}),"parentScene"===i&&GameLib.Event.Emit(GameLib.Event.PARENT_SCENE_CHANGE,{originalScene:this.initialValue,newScene:t,object:e})}.bind(this)),"parentEntity"===i&&GameLib.Event.Emit(GameLib.Event.BUILD_GUI,null),this.initialValue=t})},GameLib.System.GUI.prototype.buildArrayManagerControl=function(e,t,i){var n=t.template.linkedObjects[i];if(!(n instanceof Array))return void console.error("data mismatch - something not an array");var a=t.template,s=a[i],o=function(n,a){var s="invalid item";n&&n.name&&(s=n.name);var o=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);var r={},c=GameLib.EntityManager.Instance.queryComponents(n).reduce(function(e,t){return e[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){var n=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.buildSelectControl=function(e,t,i){var n=null;t.template[i]?n=t.template[i].constructor:t.template.linkedObjects[i]&&(n=t.template.linkedObjects[i]);var a=t.template,s=GameLib.EntityManager.Instance.queryComponents(n),o={},r=s.reduce(function(e,t){return e[t.name]=t,o[t.id]=t,e},{none:null});e.add(a,i,r).name(i).listen().onChange(function(e){var n=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){var n=t.template,a=!1;1===t.affected.length&&(n=t.affected[0],a=!0);var s=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,"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}));else if("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}));else if("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.Particle.POSITION_OFFSET_TYPE_FUNCTION}));else if("directionType"===i)o.push(e.add(n,i,{constant:GameLib.D3.Particle.DIRECTION_TYPE_CONSTANT,random:GameLib.D3.Particle.DIRECTION_TYPE_RANDOM,"random normalized":GameLib.D3.Particle.DIRECTION_TYPE_RANDOM_NORMALIZED,function:GameLib.D3.Particle.DIRECTION_TYPE_FUNCTION}));else if("speedType"===i)o.push(e.add(n,i,{constant:GameLib.D3.Particle.SPEED_TYPE_CONSTANT,linear:GameLib.D3.Particle.SPEED_TYPE_LINEAR,exponential:GameLib.D3.Particle.SPEED_TYPE_EXPONENTIAL, +logarithmic:GameLib.D3.Particle.SPEED_TYPE_LOGARITHMIC,"1 / log":GameLib.D3.Particle.SPEED_TYPE_ONE_OVER_LOG,exp:GameLib.D3.Particle.SPEED_TYPE_EXP,"1 / exp":GameLib.D3.Particle.SPEED_TYPE_ONE_OVER_EXP}));else if("scaleType"===i)o.push(e.add(n,i,{constant:GameLib.D3.Particle.SCALE_TYPE_CONSTANT,linear:GameLib.D3.Particle.SCALE_TYPE_LINEAR,exponential:GameLib.D3.Particle.SCALE_TYPE_EXPONENTIAL,random:GameLib.D3.Particle.SCALE_TYPE_RANDOM,"random (x = y)":GameLib.D3.Particle.SCALE_TYPE_RANDOM_X_EQUALS_Y,function:GameLib.D3.Particle.SCALE_TYPE_FUNCTION}));else if("rotationType"===i)o.push(e.add(n,i,{constant:GameLib.D3.Particle.ROTATION_TYPE_CONSTANT,random:GameLib.D3.Particle.ROTATION_TYPE_RANDOM,function:GameLib.D3.Particle.ROTATION_TYPE_FUNCTION}));else if("broadphaseType"===i)o.push(e.add(n,i,{naive:GameLib.D3.Broadphase.BROADPHASE_TYPE_NAIVE,grid:GameLib.D3.Broadphase.BROADPHASE_TYPE_GRID,sap:GameLib.D3.Broadphase.BROADPHASE_TYPE_SAP}));else if("solverType"===i)o.push(e.add(n,i,{gs:GameLib.D3.API.Solver.GS_SOLVER,split:GameLib.D3.API.Solver.SPLIT_SOLVER}));else if("meshType"===i)o.push(e.add(n,i,{normal:GameLib.D3.API.Mesh.MESH_TYPE_NORMAL,curve:GameLib.D3.API.Mesh.MESH_TYPE_CURVE,skinned:GameLib.D3.API.Mesh.MESH_TYPE_SKINNED,plane:GameLib.D3.API.Mesh.MESH_TYPE_PLANE,sphere:GameLib.D3.API.Mesh.MESH_TYPE_SPHERE,box:GameLib.D3.API.Mesh.MESH_TYPE_BOX,cylinder:GameLib.D3.API.Mesh.MESH_TYPE_CYLINDER,text:GameLib.D3.API.Mesh.MESH_TYPE_TEXT}));else if("cameraType"===i)o.push(e.add(n,i,{perspective:GameLib.D3.Camera.CAMERA_TYPE_PERSPECTIVE,orthographic:GameLib.D3.Camera.CAMERA_TYPE_ORTHOGONAL}));else if("materialType"===i)o.push(e.add(n,i,{standard:GameLib.D3.Material.MATERIAL_TYPE_STANDARD,basic:GameLib.D3.Material.MATERIAL_TYPE_BASIC,phong:GameLib.D3.Material.MATERIAL_TYPE_PHONG,points:GameLib.D3.Material.MATERIAL_TYPE_POINTS,toon:GameLib.D3.Material.MATERIAL_TYPE_TOON,"line basic":GameLib.D3.Material.MATERIAL_TYPE_LINE_BASIC}));else if("side"===i)o.push(e.add(n,i,{double:GameLib.D3.Material.TYPE_DOUBLE_SIDE,front:GameLib.D3.Material.TYPE_FRONT_SIDE,back:GameLib.D3.Material.TYPE_BACK_SIDE}));else if("combine"===i)o.push(e.add(n,i,{multiply:GameLib.D3.Material.TYPE_MULTIPLY_OPERATION,mix:GameLib.D3.Material.TYPE_MIX_OPERATION,add:GameLib.D3.Material.TYPE_ADD_OPERATION}));else if("vertexColors"===i)o.push(e.add(n,i,{none:GameLib.D3.Material.TYPE_NO_COLORS,face:GameLib.D3.Material.TYPE_FACE_COLORS,vertex:GameLib.D3.Material.TYPE_VERTEX_COLORS}));else if("blending"===i)o.push(e.add(n,i,{none:GameLib.D3.Material.TYPE_NO_BLENDING,normal:GameLib.D3.Material.TYPE_NORMAL_BLENDING,additive:GameLib.D3.Material.TYPE_ADDITIVE_BLENDING,subtractive:GameLib.D3.Material.TYPE_SUBTRACTIVE_BLENDING,multiply:GameLib.D3.Material.TYPE_MULTIPLY_BLENDING,custom:GameLib.D3.Material.TYPE_CUSTOM_BLENDING}));else if("blendSrc"===i)o.push(e.add(n,i,{zero:GameLib.D3.Material.TYPE_ZERO_FACTOR,one:GameLib.D3.Material.TYPE_ONE_FACTOR,"source color":GameLib.D3.Material.TYPE_SRC_COLOR_FACTOR,"one minus source color":GameLib.D3.Material.TYPE_ONE_MINUS_SRC_COLOR_FACTOR,"source alpha":GameLib.D3.Material.TYPE_SRC_ALPHA_FACTOR,"one minus source alpha":GameLib.D3.Material.TYPE_ONE_MINUS_SRC_ALPHA_FACTOR,"destination alpha":GameLib.D3.Material.TYPE_DST_ALPHA_FACTOR,"one minus destination alpha":GameLib.D3.Material.TYPE_ONE_MINUS_DST_ALPHA_FACTOR,"destination color":GameLib.D3.Material.TYPE_DST_COLOR_FACTOR,"one minus destination color":GameLib.D3.Material.TYPE_ONE_MINUS_DST_COLOR_FACTOR,"source alpha saturate":GameLib.D3.Material.TYPE_SRC_ALPHA_SATURATE_FACTOR}));else if("blendDst"===i)o.push(e.add(n,i,{zero:GameLib.D3.Material.TYPE_ZERO_FACTOR,one:GameLib.D3.Material.TYPE_ONE_FACTOR,"source color":GameLib.D3.Material.TYPE_SRC_COLOR_FACTOR,"one minus source color":GameLib.D3.Material.TYPE_ONE_MINUS_SRC_COLOR_FACTOR,"source alpha":GameLib.D3.Material.TYPE_SRC_ALPHA_FACTOR,"one minus source alpha":GameLib.D3.Material.TYPE_ONE_MINUS_SRC_ALPHA_FACTOR,"destination alpha":GameLib.D3.Material.TYPE_DST_ALPHA_FACTOR,"one minus destination alpha":GameLib.D3.Material.TYPE_ONE_MINUS_DST_ALPHA_FACTOR,"destination color":GameLib.D3.Material.TYPE_DST_COLOR_FACTOR,"one minus destination color":GameLib.D3.Material.TYPE_ONE_MINUS_DST_COLOR_FACTOR,"source alpha saturate":GameLib.D3.Material.TYPE_SRC_ALPHA_SATURATE_FACTOR}));else if("blendEquation"===i)o.push(e.add(n,i,{add:GameLib.D3.Material.TYPE_ADD_EQUATION,subtract:GameLib.D3.Material.TYPE_SUBTRACT_EQUATION,"reverse subtract":GameLib.D3.Material.TYPE_REVERSE_SUBTRACT_EQUATION,min:GameLib.D3.Material.TYPE_MIN_EQUATION,max:GameLib.D3.Material.TYPE_MAX_EQUATION}));else if("depthFunc"===i)o.push(e.add(n,i,{never:GameLib.D3.Material.TYPE_NEVER_DEPTH,always:GameLib.D3.Material.TYPE_ALWAYS_DEPTH,"less depth":GameLib.D3.Material.TYPE_LESS_DEPTH,"less equal depth":GameLib.D3.Material.TYPE_LESS_EQUAL_DEPTH,"equal depth":GameLib.D3.Material.TYPE_EQUAL_DEPTH,"greated equal depth":GameLib.D3.Material.TYPE_GREATER_EQUAL_DEPTH,"greated depth":GameLib.D3.Material.TYPE_GREATER_DEPTH,"not equal depth":GameLib.D3.Material.TYPE_NOT_EQUAL_DEPTH}));else if("wrapS"===i)o.push(e.add(n,i,{repeat:GameLib.D3.API.Texture.TYPE_REPEAT_WRAPPING,clamp:GameLib.D3.API.Texture.TYPE_CLAMP_TO_EDGE_WRAPPING,"mirrored repeat":GameLib.D3.API.Texture.TYPE_MIRRORED_REPEAT_WRAPPING}));else if("wrapT"===i)o.push(e.add(n,i,{repeat:GameLib.D3.API.Texture.TYPE_REPEAT_WRAPPING,clamp:GameLib.D3.API.Texture.TYPE_CLAMP_TO_EDGE_WRAPPING,"mirrored repeat":GameLib.D3.API.Texture.TYPE_MIRRORED_REPEAT_WRAPPING}));else if("format"===i)o.push(e.add(n,i,{alpha:GameLib.D3.API.Texture.TYPE_ALPHA_FORMAT,rgb:GameLib.D3.API.Texture.TYPE_RGB_FORMAT,rgba:GameLib.D3.API.Texture.TYPE_RGBA_FORMAT,luminance:GameLib.D3.API.Texture.TYPE_LUMINANCE_FORMAT,"luminance alpha":GameLib.D3.API.Texture.TYPE_LUMINANCE_ALPHA_FORMAT,depth:GameLib.D3.API.Texture.TYPE_DEPTH_FORMAT}));else if("mapping"===i)o.push(e.add(n,i,{uv:GameLib.D3.API.Texture.TYPE_UV_MAPPING,"cube reflection":GameLib.D3.API.Texture.TYPE_CUBE_REFLECTION_MAPPING,"cube refraction":GameLib.D3.API.Texture.TYPE_CUBE_REFRACTION_MAPPING,"equi rectangular reflection":GameLib.D3.API.Texture.TYPE_EQUI_RECTANGULAR_REFLECTION_MAPPING,"equi rectangular refraction":GameLib.D3.API.Texture.TYPE_EQUI_RECTANGULAR_REFRACTION_MAPPING,"spherical reflection":GameLib.D3.API.Texture.TYPE_SPHERICAL_REFLECTION_MAPPING,"cube uv reflection":GameLib.D3.API.Texture.TYPE_CUBE_UV_REFLECTION_MAPPING,"cube uv refraction":GameLib.D3.API.Texture.TYPE_CUBE_UV_REFRACTION_MAPPING}));else if("magFilter"===i)o.push(e.add(n,i,{nearest:GameLib.D3.API.Texture.TYPE_NEAREST_FILTER,"nearest mipmap nearest":GameLib.D3.API.Texture.TYPE_NEAREST_MIPMAP_NEAREST_FILTER,"nearest mipmap linear":GameLib.D3.API.Texture.TYPE_NEAREST_MIPMAP_LINEAR_FILTER,linear:GameLib.D3.API.Texture.TYPE_LINEAR_FILTER,"linear mipmap nearest":GameLib.D3.API.Texture.TYPE_LINEAR_MIPMAP_NEAREST_FILTER,"linear mipmap linear":GameLib.D3.API.Texture.TYPE_LINEAR_MIPMAP_LINEAR_FILTER}));else if("minFilter"===i)o.push(e.add(n,i,{nearest:GameLib.D3.API.Texture.TYPE_NEAREST_FILTER,"nearest mipmap nearest":GameLib.D3.API.Texture.TYPE_NEAREST_MIPMAP_NEAREST_FILTER,"nearest mipmap linear":GameLib.D3.API.Texture.TYPE_NEAREST_MIPMAP_LINEAR_FILTER,linear:GameLib.D3.API.Texture.TYPE_LINEAR_FILTER,"linear mipmap nearest":GameLib.D3.API.Texture.TYPE_LINEAR_MIPMAP_NEAREST_FILTER,"linear mipmap linear":GameLib.D3.API.Texture.TYPE_LINEAR_MIPMAP_LINEAR_FILTER}));else if(s===GameLib.Component.TEXTURE&&"textureType"===i)o.push(e.add(n,i,{normal:GameLib.D3.API.Texture.TEXTURE_TYPE_NORMAL,cube:GameLib.D3.API.Texture.TEXTURE_TYPE_CUBE,canvas:GameLib.D3.API.Texture.TEXTURE_TYPE_CANVAS}));else if("textureType"===i)o.push(e.add(n,i,{"unsigned byte":GameLib.D3.API.Texture.TYPE_UNSIGNED_BYTE,byte:GameLib.D3.API.Texture.TYPE_BYTE,short:GameLib.D3.API.Texture.TYPE_SHORT,"unsigned short":GameLib.D3.API.Texture.TYPE_UNSIGNED_SHORT,int:GameLib.D3.API.Texture.TYPE_INT,"unsigned int":GameLib.D3.API.Texture.TYPE_UNSIGNED_INT,float:GameLib.D3.API.Texture.TYPE_FLOAT,"half float":GameLib.D3.API.Texture.TYPE_HALF_FLOAT}));else if("encoding"===i)o.push(e.add(n,i,{linear:GameLib.D3.API.Texture.TYPE_LINEAR_ENCODING,srgb:GameLib.D3.API.Texture.TYPE_SRGB_ENCODING,gamma:GameLib.D3.API.Texture.TYPE_GAMMA_ENCODING,rgbe:GameLib.D3.API.Texture.TYPE_RGBE_ENCODING,"log luv":GameLib.D3.API.Texture.TYPE_LOG_LUV_ENCODING,rgbm7:GameLib.D3.API.Texture.TYPE_RGBM7_ENCODING,rgbm16:GameLib.D3.API.Texture.TYPE_RGBM16_ENCODING,rgbd:GameLib.D3.API.Texture.TYPE_RGBD_ENCODING}));else if("lightType"===i)o.push(e.add(n,i,{ambient:GameLib.D3.Light.LIGHT_TYPE_AMBIENT,directional:GameLib.D3.Light.LIGHT_TYPE_DIRECTIONAL,spot:GameLib.D3.Light.LIGHT_TYPE_SPOT,point:GameLib.D3.Light.LIGHT_TYPE_POINT}));else if("eventId"===i){for(var r={},c=0;c<200;c++)try{r[GameLib.Event.GetEventName(c)]=c}catch(e){}o.push(e.add(n,i,r))}else"functionType"===i?o.push(e.add(n,i,{rotation:GameLib.D3.Animation.ANIMATION_FUNCTION_TYPE_ROTATION,translation:GameLib.D3.Animation.ANIMATION_FUNCTION_TYPE_TRANSLATION,scale:GameLib.D3.Animation.ANIMATION_FUNCTION_TYPE_SCALE})):"opacity"===i||"opacityFactor"===i||"metalness"===i||"roughness"===i||"volume"===i?o.push(e.add(n,i,0,1,.001)):"shininess"===i||"fov"===i?o.push(e.add(n,i,-255,255,1)):"aspect"===i||"wireframeLineWidth"===i||"lineWidth"===i?o.push(e.add(n,i,0,5,.001)):"bumpScale"===i||"normalScale"===i||"displacementScale"===i||"heightMapScale"===i||"intensity"===i?o.push(e.add(n,i,-10,10,.001)):"minX"===i||"minY"===i||"minZ"===i||"maxX"===i||"maxY"===i||"maxZ"===i||"offsetX"===i?o.push(e.add(n,i,-1e3,1e3,.01)):"widthSegments"===i||"radiusSegments"===i||"heightSegments"===i||"particlesPerSecond"===i?o.push(e.add(n,i,1,1e3,1)):"width"===i||"height"===i||"depth"===i||"radius"===i?o.push(e.add(n,i,0,1e3,.1)):"near"===i||"distanceGrain"===i||"envMapIntensity"===i?o.push(e.add(n,i,-10,100,.001)):"bumpScale"===i?o.push(e.add(n,i,0,20,.001)):"heightOffset"===i||"rotationFactor"===i?o.push(e.add(n,i,-100,100,.001)):"friction"===i?o.push(e.add(n,i,0,1e3,.01)):"radiusTop"===i||"radiusBottom"===i?o.push(e.add(n,i,0,100,.1)):"mass"===i?o.push(e.add(n,i,0,1e3,.1)):"sensitivity"===i?o.push(e.add(n,i,1,50,1)):"density"===i?o.push(e.add(n,i,0,1,1e-4)):"thetaLength"===i||"angle"===i?o.push(e.add(n,i,2*-Math.PI,2*Math.PI,.01)):o.push(e.add(n,i,-1e3,1e3,.1))}o.map(function(n){"name"===i?n.onFinishChange(function(e,n){return function(e){t.affected.map(function(t){t[i]=e,t.updateInstance(i)}),n.domElement.getElementsByClassName("title")[0].innerHTML=e}}(0,e)):n.onChange(function(e){"number"==typeof this.initialValue&&(e=Number(e)),t.affected.map(function(t){t[i]=e,t.updateInstance(i)})}),a&&n.listen()})},GameLib.System.GUI.prototype.meshSelected=function(e){this.exclusiveMode?GameLib.Utils.PushUnique(this.backupComponents,e.mesh):GameLib.Utils.PushUnique(this.components,e.mesh)},GameLib.System.GUI.prototype.meshDeslected=function(e){var t=-1;this.exclusiveMode?-1!==(t=this.backupComponents.indexOf(e.mesh))&&this.backupComponents.splice(t,1):-1!==(t=this.components.indexOf(e.mesh))&&this.components.splice(t,1)},GameLib.System.GUI.prototype.buildGUI=function(e){this.guis.map(function(t){if(t.instance.destroy(),t.removeAllFolders(),e&&(e.components?(this.exclusiveMode||(this.exclusiveMode=!0,this.backupComponents=this.components.map(function(e){return e})),this.components=e.components.map(function(e){return e})):this.exclusiveMode?(this.exclusiveMode=!1,this.components=this.backupComponents.map(function(e){return e})):console.log("we are already not in mesh select mode - not doing anything with the backup")),this.exclusiveMode||(this.components=this.components.filter(function(e){return e instanceof GameLib.D3.Mesh})),!(GameLib.Utils.UndefinedOrNull(this.components.length)||this.components.length<1)){this.exclusiveMode||(this.components=this.components.reduce(function(e,t){var i=t.getChildrenComponents();return GameLib.Utils.PushUnique(e,t),i.map(function(t){GameLib.Utils.PushUnique(e,t)}),e}.bind(this),[])),this.components.sort(function(e,t){return e.componentType>t.componentType?1:e.componentType0?console.log("ignoring multiple editor controls"):(this.editorControls.push(e.component),this.registerEditorControls())),e.component instanceof GameLib.Controls.Touch&&(this.touchControls.length>0?console.log("ignoring multiple touch controls"):(this.touchControls.push(e.component),this.registerTouchControls())),e.component instanceof GameLib.Controls.Keyboard&&(this.keyboardControls.length>0?console.log("ignoring multiple keyboard controls"):(this.keyboardControls.push(e.component),this.registerKeyboardControls())),e.component instanceof GameLib.Controls.Mouse&&(this.mouseControls.length>0?console.log("ignoring multiple mouse controls"):(this.mouseControls.push(e.component),this.registerMouseControls()))},GameLib.System.Input.prototype.removeComponent=function(e){if(e.component instanceof GameLib.Controls.D3.Editor){var t=this.editorControls.indexOf(e.component);-1!==t?(console.log("removing editor controls from system"),this.deRegisterEditorControls(),this.editorControls.splice(t,1)):console.log("failed to find the editor controls in the system - probably it was ignored - "+e.component.name)}},GameLib.System.Input.prototype.delayedInstanceEncountered=function(e){e.component instanceof GameLib.Controls.D3.Editor&&(0===this.editorControls.length?(this.editorControls.push(e.component),this.registerEditorControls()):e.component.createInstance())},GameLib.System.Input.prototype.registerTouchControls=function(){if(1===this.touchControls.length){var e=this.touchControls[0];this.touchSensitivity=e.sensitivity,this.touchStart=this.onTouchStart.bind(this),this.touchMove=this.onTouchMove.bind(this),this.touchEnd=this.onTouchEnd.bind(this),this.touchCancel=this.onTouchCancel.bind(this),e.domElement.instance.addEventListener("touchstart",this.touchStart,!1),e.domElement.instance.addEventListener("touchmove",this.touchMove,!1),e.domElement.instance.addEventListener("touchend",this.touchEnd,!1),e.domElement.instance.addEventListener("touchcancel",this.touchCancel,!1)}},GameLib.System.Input.prototype.registerKeyboardControls=function(){if(1===this.keyboardControls.length){var e=this.keyboardControls[0];this.keyboardKeyUp=this.onKeyboardKeyUp.bind(this),this.keyboardKeyDown=this.onKeyboardKeyDown.bind(this),e.domElement.instance.addEventListener("keyup",this.keyboardKeyUp,!1),e.domElement.instance.addEventListener("keydown",this.keyboardKeyDown,!1)}},GameLib.System.Input.prototype.registerMouseControls=function(){if(1===this.mouseControls.length){var e=this.mouseControls[0];this.mouseDown=this.onMouseDown.bind(this),this.mouseMove=this.onMouseMove.bind(this),this.mouseWheel=this.onMouseWheel.bind(this),this.mouseUp=this.onMouseUp.bind(this),e.domElement.instance.addEventListener("mousedown",this.mouseDown,!1),e.domElement.instance.addEventListener("mousemove",this.mouseMove,!1),e.domElement.instance.addEventListener("wheel",this.mouseWheel,!1),e.domElement.instance.addEventListener("mouseup",this.mouseUp,!1)}},GameLib.System.Input.prototype.registerEditorControls=function(){if(1===this.editorControls.length){var e=this.editorControls[0];this.mouseDownEdit=this.onMouseDownEdit.bind(this),this.mouseMoveEdit=this.onMouseMoveEdit.bind(this),e.domElement.instance.addEventListener("mousedown",this.mouseDownEdit,!1),e.domElement.instance.addEventListener("mousemove",this.mouseMoveEdit,!1),this.keyboardControls.length>0||(this.keyDown=this.onKeyDown.bind(this),this.keyUp=this.onKeyUp.bind(this),e.domElement.instance.addEventListener("keydown",this.keyDown,!1),e.domElement.instance.addEventListener("keyup",this.keyUp,!1)),e.createInstance(),this.mouseWheelEdit=this.onMouseWheelEdit.bind(this),this.mouseUpEdit=this.onMouseUpEdit.bind(this),e.domElement.instance.addEventListener("wheel",this.mouseWheelEdit,!1),e.domElement.instance.addEventListener("mouseup",this.mouseUpEdit,!1)}},GameLib.System.Input.prototype.deRegisterEditorControls=function(){if(1===this.editorControls.length){var e=this.editorControls[0];e.domElement.instance.removeEventListener("mousedown",this.mouseDownEdit,!1),e.domElement.instance.removeEventListener("mousemove",this.mouseMoveEdit,!1),this.keyboardControls.length<1&&(e.domElement.instance.removeEventListener("keydown",this.keyDown,!1),e.domElement.instance.removeEventListener("keyup",this.keyUp,!1)),e.instance.dispose(),e.domElement.instance.removeEventListener("wheel",this.mouseWheelEdit,!1),e.domElement.instance.removeEventListener("mouseup",this.mouseUpEdit,!1)}},GameLib.System.Input.prototype.deRegisterTouchControls=function(){if(1===this.touchControls.length){var e=this.touchControls[0];e.domElement.instance.removeEventListener("touchstart",this.touchStart,!1),e.domElement.instance.removeEventListener("touchmove",this.touchMove,!1),e.domElement.instance.removeEventListener("touchend",this.touchEnd,!1),e.domElement.instance.removeEventListener("touchcancel",this.touchCancel,!1)}},GameLib.System.Input.prototype.deRegisterKeyboardControls=function(){if(1===this.keyboardControls.length){var e=this.keyboardControls[0];e.domElement.instance.removeEventListener("keydown",this.keyboardKeyDown,!1),e.domElement.instance.removeEventListener("keyup",this.keyboardKeyUp,!1)}},GameLib.System.Input.prototype.deRegisterMouseControls=function(){if(1===this.mouseControls.length){var e=this.mouseControls[0];e.domElement.instance.removeEventListener("mousedown",this.mouseDown,!1),e.domElement.instance.removeEventListener("mousemove",this.mouseMove,!1),e.domElement.instance.removeEventListener("wheel",this.mouseWheel,!1),e.domElement.instance.removeEventListener("mouseup",this.mouseUp,!1)}},GameLib.System.Input.prototype.onKeyboardKeyUp=function(e){GameLib.Event.Emit(GameLib.Event.KEY_DOWN,{code:e.code})},GameLib.System.Input.prototype.onKeyboardKeyDown=function(e){GameLib.Event.Emit(GameLib.Event.KEY_UP,{code:e.code})},GameLib.System.Input.prototype.onTouchStart=function(e){this.sensitivityCounter=0,this.touches={};for(var t=0;te.changedTouches[h].pageX&&(u+=l),this.touches[t].lastTouchY>e.changedTouches[h].pageY&&(d+=p),this.touches[t].lastTouchY=this.touchSensitivity&&(this.sensitivityCounter=0,GameLib.Event.Emit(GameLib.Event.TOUCH_MOVE,this.touches))},GameLib.System.Input.prototype.onTouchCancel=function(e){this.sensitivityCounter=0;for(var t=0;tt.distance?1:0});var a=n.map(function(e){return e.mesh}),s=a[0];s&&(e.preventDefault(),e.stopImmediatePropagation(),s.selected?this.deSelectMesh(s):this.selectMesh(s),GameLib.Event.Emit(GameLib.Event.BUILD_GUI,null))}}.bind(this))},GameLib.System.Input.prototype.onMouseMoveEdit=function(e){},GameLib.System.Input.prototype.onMouseUpEdit=function(e){this.editorControls.map(function(e){e.camera.position.x=e.camera.instance.position.x,e.camera.position.y=e.camera.instance.position.y,e.camera.position.z=e.camera.instance.position.z,e.camera.quaternion.x=e.camera.instance.quaternion.x,e.camera.quaternion.y=e.camera.instance.quaternion.y,e.camera.quaternion.z=e.camera.instance.quaternion.z,e.camera.quaternion.w=e.camera.instance.quaternion.w,e.camera.lookAt.x=e.instance.center.x,e.camera.lookAt.y=e.instance.center.y,e.camera.lookAt.z=e.instance.center.z,e.camera.lookAt.instance.copy(e.instance.center)})},GameLib.System.Input.prototype.onMouseWheelEdit=function(e){this.editorControls.map(function(e){e.camera.position.x=e.camera.instance.position.x,e.camera.position.y=e.camera.instance.position.y,e.camera.position.z=e.camera.instance.position.z})},GameLib.System.Input.prototype.selectMesh=function(e){!0!==e.selected&&(e.selected=!0,e.createHelper(),GameLib.Event.Emit(GameLib.Event.MESH_SELECTED,{mesh:e}))};GameLib.System.Input.prototype.deSelectMesh=function(e){e.selected=!1,e.removeHelper(),GameLib.Event.Emit(GameLib.Event.MESH_DESELECTED,{mesh:e})},GameLib.System.Linking=function(e){GameLib.System.call(this,e),this.dependencies={},this.resolved=[],this.componentCreatedSubscription=null,this.componentClonedSubscription=null,this.registerDependenciesSubscription=null,this.componentRemoveSubscription=null,this.parentSceneChangeSubscription=null,this.parentPhysicsWorldChangeSubscription=null,this.parentEntityChangeSubscription=null,this.instanceCreatedSubscription=null,this.instanceClonedSubscription=null,this.removeMeshSubscription=null,this.imageChangedSubscription=null,this.materialTypeChangedSubscription=null,this.arrayItemAddedSubscription=null},GameLib.System.Linking.prototype=Object.create(GameLib.System.prototype),GameLib.System.Linking.prototype.constructor=GameLib.System.Linking,GameLib.System.Linking.prototype.start=function(){GameLib.System.prototype.start.call(this),this.componentCreatedSubscription=this.subscribe(GameLib.Event.COMPONENT_CREATED,this.componentCreated.bind(this)),this.componentClonedSubscription=this.subscribe(GameLib.Event.COMPONENT_CLONED,this.componentCloned.bind(this)),this.registerDependenciesSubscription=this.subscribe(GameLib.Event.REGISTER_DEPENDENCIES,this.registerDependenciesDirect),this.componentRemoveSubscription=this.subscribe(GameLib.Event.REMOVE_COMPONENT,this.removeComponent),this.parentSceneChangeSubscription=this.subscribe(GameLib.Event.PARENT_SCENE_CHANGE,this.onParentSceneChange),this.parentPhysicsWorldChangeSubscription=this.subscribe(GameLib.Event.PARENT_WORLD_CHANGE,this.onParentWorldChange), +this.parentEntityChangeSubscription=this.subscribe(GameLib.Event.PARENT_ENTITY_CHANGE,this.onParentEntityChange),this.instanceCreatedSubscription=this.subscribe(GameLib.Event.INSTANCE_CREATED,this.instanceCreated),this.instanceClonedSubscription=this.subscribe(GameLib.Event.INSTANCE_CLONED,this.instanceCloned),this.removeMeshSubscription=this.subscribe(GameLib.Event.REMOVE_MESH,this.removeMesh),this.imageChangedSubscription=this.subscribe(GameLib.Event.IMAGE_CHANGED,this.imageChanged),this.materialTypeChangedSubscription=this.subscribe(GameLib.Event.MATERIAL_TYPE_CHANGED,this.materialTypeChanged),this.arrayItemAddedSubscription=this.subscribe(GameLib.Event.ARRAY_ITEM_ADDED,this.arrayItemAdded)},GameLib.System.Linking.prototype.link=function(e,t){for(var i in e.linkedObjects)if(e.linkedObjects.hasOwnProperty(i))if(e.linkedObjects[i]instanceof Array){var n=[];e[i]=e[i].map(function(a){return a===t.component.id?(n.push({parent:e,property:i,child:t.component}),t.component):a}),n.map(function(e){GameLib.Event.Emit(GameLib.Event.COMPONENT_LINKED,e)})}else e[i]&&e[i]===t.component.id&&(e[i]=t.component,GameLib.Event.Emit(GameLib.Event.COMPONENT_LINKED,{parent:e,property:i,child:t.component}))},GameLib.System.Linking.prototype.resolveDependencies=function(e){if(!e.loaded)return!1;var t=this.dependencies[e.id];if(GameLib.Utils.UndefinedOrNull(t))return!1;t.map(function(t){if(this.link(t,{component:e}),GameLib.Utils.PushUnique(this.resolved,e),GameLib.Utils.UndefinedOrNull(t.dependencies)||t.dependencies instanceof Array&&0===t.dependencies.length){if(!t.loaded||GameLib.Utils.UndefinedOrNull(t.instance))try{t.performInstanceCreation()}catch(e){console.error(e)}}else{var i=t.dependencies.indexOf(e.id);-1!==i&&t.dependencies.splice(i,1),0===t.dependencies.length&&t.performInstanceCreation()}}.bind(this)),delete this.dependencies[e.id],GameLib.Event.Emit(GameLib.Event.UNRESOLVED_DEPENDENCIES_UPDATE,{dependencies:this.dependencies}),GameLib.Utils.IsEmpty(this.dependencies)&&(GameLib.Event.Emit(GameLib.Event.COMPONENTS_LINKED,{components:this.resolved.map(function(e){return e})}),this.resolved=[])},GameLib.System.Linking.prototype.registerDependencies=function(e){e.dependencies&&e.dependencies.length>0&&(e.dependencies=e.dependencies.reduce(function(t,i){var n=GameLib.EntityManager.Instance.findComponentById(i);return n&&n.loaded?(this.link(e,{component:n}),GameLib.Utils.PushUnique(this.resolved,n)):(GameLib.Utils.UndefinedOrNull(this.dependencies[i])&&(this.dependencies[i]=[]),-1===this.dependencies[i].indexOf(e)&&(this.dependencies[i].push(e),GameLib.Event.Emit(GameLib.Event.UNRESOLVED_DEPENDENCIES_UPDATE,{dependencies:this.dependencies})),t.push(i)),t}.bind(this),[]),0===e.dependencies.length&&e.performInstanceCreation())},GameLib.System.Linking.prototype.componentCreated=function(e){var t=e.component;this.registerDependencies(t),this.resolveDependencies(t)},GameLib.System.Linking.prototype.componentCloned=function(e){if(this.componentCreated(e),e.component instanceof GameLib.D3.Mesh){if(!(e.parent instanceof GameLib.D3.Mesh))throw new Error("no scene parent");e.parent.parentScene&&e.parent.parentScene.addClone(e.component)}},GameLib.System.Linking.prototype.registerDependenciesDirect=function(e){this.registerDependencies(e.component)},GameLib.System.Linking.prototype.removeComponent=function(e){if(!e.component)return void console.error("no component to remove");var t=e.component;t.parentEntity instanceof GameLib.Entity&&t.parentEntity.removeComponent(t),t instanceof GameLib.D3.Mesh&&t.parentScene instanceof GameLib.D3.Scene&&(t.removeHelper(),t.parentScene.removeObject(t)),t instanceof GameLib.D3.Light&&t.parentScene instanceof GameLib.D3.Scene&&t.parentScene.removeObject(t),t instanceof GameLib.Entity&&GameLib.EntityManager.Instance.removeEntity(t)},GameLib.System.Linking.prototype.imageChanged=function(e){GameLib.EntityManager.Instance.queryComponents(GameLib.Component.MATERIAL).map(function(t){-1!==t.getTextures().indexOf(e.texture)&&t.updateInstance()})},GameLib.System.Linking.prototype.arrayItemAdded=function(e){e.component instanceof GameLib.D3.PhysicsWorld&&e.item instanceof GameLib.D3.RigidBody&&e.component.addRigidBody(e.item),e.component instanceof GameLib.D3.Mesh&&e.item instanceof GameLib.D3.Material&&e.component.addMaterial(e.item)},GameLib.System.Linking.prototype.instanceCloned=function(e){},GameLib.System.Linking.prototype.instanceCreated=function(e){this.resolveDependencies(e.component),e.component instanceof GameLib.Image&&GameLib.EntityManager.Instance.queryComponents(GameLib.Component.TEXTURE).map(function(t){t.image!==e.component&&-1===t.images.indexOf(e.component)||t.updateInstance("image")}),e.component instanceof GameLib.D3.Scene&&GameLib.EntityManager.Instance.register.map(function(t){t.parentScene===e.component.id&&(t.parentScene=e.component)}),e.component.parentScene&&"string"==typeof e.component.parentScene&&GameLib.EntityManager.Instance.queryComponents(GameLib.Component.SCENE).map(function(t){e.component.parentScene===t.id&&(e.component.parentScene=t,t.addObject(e.component))}),e.component.parentEngine&&"string"==typeof e.component.parentEngine&&GameLib.EntityManager.Instance.queryComponents(GameLib.Component.PARTICLE_ENGINE).map(function(t){e.component.parentEngine===t.id&&(e.component.parentEngine=t)}),e.component instanceof GameLib.D3.Mesh&&(e.preventParentMeshCheck||GameLib.EntityManager.Instance.register.map(function(t){t.parentMesh&&t.parentMesh===e.component.id&&(t.parentMesh=e.component,t instanceof GameLib.D3.Mesh&&t.setParentMesh(e.component))})),e.component.parentMesh&&"string"==typeof e.component.parentMesh&&GameLib.EntityManager.Instance.queryComponents(GameLib.Component.MESH).map(function(t){e.component.parentMesh===t.id&&(e.component.parentMesh=t,e.component instanceof GameLib.D3.Mesh&&e.component.setParentMesh(t))}),e.component.parentPhysicsWorld&&"string"==typeof e.component.parentPhysicsWorld&&GameLib.EntityManager.Instance.queryComponents(GameLib.Component.PHYSICS_WORLD).map(function(t){e.component.parentPhysicsWorld===t.id&&(e.component.parentPhysicsWorld=t,"function"==typeof e.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.Component.MESH).map(function(t){t.materials.reduce(function(t,i){return i===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){return e.instance}),t.instance.geometry.uvsNeedUpdate=!0,t.instance.material.needsUpdate=!0)})},GameLib.System.Linking.prototype.onParentWorldChange=function(e){e.object instanceof GameLib.D3.RigidBody&&(e.originalWorld instanceof GameLib.D3.PhysicsWorld&&e.originalWorld.removeRigidBody(e.object),e.newWorld instanceof GameLib.D3.PhysicsWorld&&e.newWorld.addRigidBody(e.object))},GameLib.System.Linking.prototype.onParentSceneChange=function(e){if(e.object instanceof GameLib.D3.Mesh||e.object instanceof GameLib.D3.Light){var t=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.originalEntity instanceof GameLib.Entity&&e.originalEntity.removeComponent(e.object),e.newEntity instanceof GameLib.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){var t=e.meshes.reduce(function(e,t){return e.push(t),t.getChildrenComponents().map(function(t){e.push(t)}),e},[]),i=GameLib.EntityManager.Instance.queryComponents(GameLib.Component.MESH);i=i.filter(function(t){return-1===e.meshes.indexOf(t)});var n=i.reduce(function(e,t){return e.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.parentPhysicsWorldChangeSubscription.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){GameLib.System.call(this,e),this.engines=[],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.Component.PARTICLE_ENGINE),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.component instanceof GameLib.D3.ParticleEngine&&this.particleEngines.push(e.component)},GameLib.System.Particle.prototype.removeComponent=function(e){if(e.component instanceof GameLib.D3.ParticleEngine){var t=this.particleEngines.indexOf(e.component);-1!==t&&this.particleEngines.splice(t,1)}},GameLib.System.Particle.prototype.beforeRender=function(e){this.totalTime+=e.delta,this.particleEngines.map(function(t){if(!(GameLib.Utils.UndefinedOrNull(t.camera)||GameLib.Utils.UndefinedOrNull(t.templateParticle)||GameLib.Utils.UndefinedOrNull(t.templateParticle.mesh)||GameLib.Utils.UndefinedOrNull(t.templateParticle.mesh.parentScene)||GameLib.Utils.UndefinedOrNull(t.templateParticle.mesh.parentScene.instance))&&(t.elapsed+=e.delta,t.particles=t.particles.reduce(function(i,n){var a=n.userData.speed;return n.userData.speedType===GameLib.D3.Particle.SPEED_TYPE_CONSTANT&&(a=e.delta*n.userData.speed),n.userData.speedType===GameLib.D3.Particle.SPEED_TYPE_LINEAR&&(a=e.delta*n.userData.speed,n.userData.speed+=a),n.userData.speedType===GameLib.D3.Particle.SPEED_TYPE_EXPONENTIAL&&(a=Math.pow(n.userData.speed,2)*e.delta,n.userData.speed+=a),n.userData.speedType===GameLib.D3.Particle.SPEED_TYPE_LOGARITHMIC&&(a=Math.log(n.userData.speed)*e.delta,n.userData.speed+=a),n.userData.speedType===GameLib.D3.Particle.SPEED_TYPE_ONE_OVER_LOG&&(a=1/Math.log(n.userData.speed)*e.delta,n.userData.speed+=a),n.userData.speedType===GameLib.D3.Particle.SPEED_TYPE_EXP&&(a=Math.exp(n.userData.speed)*e.delta,n.userData.speed+=a),n.userData.speedType===GameLib.D3.Particle.SPEED_TYPE_ONE_OVER_EXP&&(a=1/Math.exp(n.userData.speed)*e.delta,n.userData.speed+=a),n.position.x+=n.userData.direction.x*a,n.position.y+=n.userData.direction.y*a,n.position.z+=n.userData.direction.z*a,t.templateParticle.scaleType,GameLib.D3.Particle.SCALE_TYPE_CONSTANT,t.templateParticle.scaleType===GameLib.D3.Particle.SCALE_TYPE_LINEAR&&(n.scale.x+=n.userData.scale.x*e.delta,n.scale.y+=n.userData.scale.x*e.delta,n.scale.z+=n.userData.scale.x*e.delta),n.quaternion.copy(t.camera.instance.quaternion),t.templateParticle.opacityType===GameLib.D3.Particle.OPACITY_TYPE_INCREASE_LINEAR&&(n.material.opacity+=t.templateParticle.opacityFactor),t.templateParticle.opacityType===GameLib.D3.Particle.OPACITY_TYPE_DECREASE_LINEAR&&(n.material.opacity-=t.templateParticle.opacityFactor),n.userData.elapsed+=e.delta,n.userData.elapsed>n.userData.lifeTime||n.material.opacity<0?(n.userData.scene.remove(n),n.geometry.dispose(),n.material.dispose()):i.push(n),i},[]),t.disabledForRemoval&&0===t.particles.length&&GameLib.Event.Emit(GameLib.Event.REMOVE_PARTICLE_ENGINE,{component:t}),t.enabled&&!t.disabledForRemoval)){var i=null;if(t.pulse){if(0===t.particles.length){t.elapsed=0;for(var n=0;nt.frequency&&(t.elapsed=0,i=t.templateParticle.cloneInstance(),t.particles.push(i))}}.bind(this))},GameLib.System.Particle.prototype.stop=function(){GameLib.System.prototype.stop.call(this),this.instanceCreatedSubscription.remove(),this.removeComponentSubscription.remove(),this.beforeRenderSubscription.remove()},GameLib.System.Physics=function(e){GameLib.System.call(this,e),this.worlds=[],this.beforeRenderSubscription=null,this.afterRenderSubscription=null},GameLib.System.Physics.prototype=Object.create(GameLib.System.prototype),GameLib.System.Physics.prototype.constructor=GameLib.System.Physics,GameLib.System.Physics.prototype.start=function(){GameLib.System.prototype.start.call(this),this.worlds=GameLib.EntityManager.Instance.queryComponents(GameLib.Component.PHYSICS_WORLD),this.beforeRenderSubscription=this.subscribe(GameLib.Event.BEFORE_RENDER,this.beforeRender)},GameLib.System.Physics.prototype.beforeRender=function(e){this.worlds.map(function(t){t.instance&&(t.instance.step(e.delta),t.rigidBodies.map(function(e){e.position.x=e.instance.position.x,e.position.y=e.instance.position.y,e.position.z=e.instance.position.z,e.quaternion.x=e.instance.quaternion.x,e.quaternion.y=e.instance.quaternion.y,e.quaternion.z=e.instance.quaternion.z,e.quaternion.w=e.instance.quaternion.w,e.parentMesh.position.x=e.instance.position.x,e.parentMesh.position.y=e.instance.position.y,e.parentMesh.position.z=e.instance.position.z,e.parentMesh.quaternion.x=e.instance.quaternion.x,e.parentMesh.quaternion.y=e.instance.quaternion.y,e.parentMesh.quaternion.z=e.instance.quaternion.z,e.parentMesh.quaternion.w=e.instance.quaternion.w,e.instance.getVelocityAtWorldPoint(new CANNON.Vec3(0,0,0),e.velocity.instance),e.velocity.x=e.velocity.instance.x,e.velocity.y=e.velocity.instance.y,e.velocity.z=e.velocity.instance.z,e.parentMesh.updateRotationFromAxisAngle=!1,e.parentMesh.updateInstance(),e.parentMesh.updateRotationFromAxisAngle=!0}))}.bind(this))},GameLib.System.Physics.prototype.stop=function(){GameLib.System.prototype.stop.call(this),this.worlds=[],this.rigidBodies=[],this.wheels=[],this.vehicles=[],this.beforeRenderSubscription&&this.beforeRenderSubscription.remove(),this.afterRenderSubscription&&this.afterRenderSubscription.remove()},GameLib.System.Render=function(e){GameLib.System.call(this,e),this.renderSubscription=null},GameLib.System.Render.prototype=Object.create(GameLib.System.prototype),GameLib.System.Render.prototype.constructor=GameLib.System.Render,GameLib.System.Render.prototype.start=function(){GameLib.System.prototype.start.call(this),this.renderers=GameLib.EntityManager.Instance.queryComponents(GameLib.Component.RENDERER),this.statistics=GameLib.EntityManager.Instance.queryComponents(GameLib.Component.STATS),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.renderSubscription=this.subscribe(GameLib.Event.RENDER,this.render)},GameLib.System.Render.prototype.instanceCreated=function(e){e.component instanceof GameLib.D3.Renderer&&(console.log("new renderer"),this.renderers.push(e.component)),e.component instanceof GameLib.Stats&&(console.log("new stats"),this.statistics.push(e.component))},GameLib.System.Render.prototype.removeComponent=function(e){if(e.component instanceof GameLib.D3.Renderer){var t=this.renderers.indexOf(e.component);-1!==t?(console.log("removing renderer from system"),this.renderers.splice(t,1)):console.log("failed to find the renderer in the system : "+e.component.name)}},GameLib.System.Render.prototype.render=function(e){if(this.statistics&&this.statistics.map(function(e){e.start()}),GameLib.Event.Emit(GameLib.Event.BEFORE_RENDER,e),this.renderers.length<1);else if(1===this.renderers.length)this.renderers[0].render(e.delta);else{var t=this.renderers.reduce(function(e,t){return t.scenes.map(function(t){e.push(t)}),e},[]),i=GameLib.EntityManager.Instance.defaultRenderer;GameLib.Utils.UndefinedOrNull(i)&&(i=this.renderers[0]),i.render(e.delta,t)}GameLib.Event.Emit(GameLib.Event.AFTER_RENDER,e),this.statistics&&this.statistics.map(function(e){e.end()})},GameLib.System.Render.prototype.stop=function(){GameLib.System.prototype.stop.call(this),this.instanceCreatedSubscription.remove(),this.removeComponentSubscription.remove(),this.renderSubscription.remove(),this.renderers.map(function(e){e.statistics&&(e.statistics.resize(),e.domElement.instance.parentElement.removeChild(e.statistics.instance.dom))}),this.renderers=[]},GameLib.System.Storage=function(e,t,i,n,a,s,o,r,c){GameLib.System.call(this,e),GameLib.Utils.UndefinedOrNull(t)&&(t=null),this.token=t,GameLib.Utils.UndefinedOrNull(i)&&(console.warn("Need an API Upload URL for a storage system"),i=""),this.apiUploadUrl=i,GameLib.Utils.UndefinedOrNull(n)&&(n=null),this.onImageLoaded=n,GameLib.Utils.UndefinedOrNull(a)&&(a=null),this.onImageProgress=a,GameLib.Utils.UndefinedOrNull(s)&&(s=null),this.onImageError=s,GameLib.Utils.UndefinedOrNull(o)&&(o=null),this.onComponentLoaded=o,GameLib.Utils.UndefinedOrNull(r)&&(r=null),this.onComponentProgress=r,GameLib.Utils.UndefinedOrNull(c)&&(c=null),this.onComponentError=c,this.loaded=[],this.loading=[],this.failed=[],this.otherDependencies=[],this.loginSubscription=null,this.saveSubscription=null,this.loadSubscription=null,this.loadImageSubscription=null,this.blenderDataSubscription=null,this.imageUploadCompleteSubscription=null,this.fetchComponentTypesSubscription=null,this.fetchComponentsSubscription=null},GameLib.System.Storage.prototype=Object.create(GameLib.System.prototype),GameLib.System.Storage.prototype.constructor=GameLib.System.Storage,GameLib.System.Storage.prototype.start=function(){GameLib.System.prototype.start.call(this),this.loginSubscription=this.subscribe(GameLib.Event.LOGGED_IN,function(e){this.token=e.token}),this.saveSubscription=this.subscribe(GameLib.Event.SAVE_COMPONENT,this.save),this.loadSubscription=this.subscribe(GameLib.Event.LOAD_COMPONENT,this.load),this.deleteSubscription=this.subscribe(GameLib.Event.DELETE_COMPONENT,this.delete),this.loadImageSubscription=this.subscribe(GameLib.Event.LOAD_IMAGE,this.loadImage),this.loadFontSubscription=this.subscribe(GameLib.Event.LOAD_FONT,this.loadFont),this.blenderDataSubscription=this.subscribe(GameLib.Event.BLENDER_DATA_RECEIVED,this.processBlenderData),this.imageUploadCompleteSubscription=this.subscribe(GameLib.Event.IMAGE_UPLOAD_COMPLETE,this.imageUploadComplete),this.fetchComponentTypesSubscription=this.subscribe(GameLib.Event.FETCH_COMPONENT_TYPES,this.fetchComponentTypes),this.fetchComponentsSubscription=this.subscribe(GameLib.Event.FETCH_COMPONENTS,this.fetchComponents)},GameLib.System.Storage.prototype.delete=function(e){this.publish(GameLib.Event.GET_API_URL,null,function(t){if("undefined"==typeof XMLHttpRequest)return void console.log("Implement server side delete here");e.ids.map(function(e){var i=new XMLHttpRequest;i.open("POST",t.apiUrl+"/component/delete/"+e),i.setRequestHeader("Accept","application/json"),i.setRequestHeader("Content-Type","application/json"),i.setRequestHeader("x-authorization",t.passwoid),i.onreadystatechange=function(){if(4===this.readyState){try{var e=JSON.parse(this.responseText)}catch(e){GameLib.Event.Emit(GameLib.Event.DELETE_COMPONENT_ERROR,{message:this.responseText})}"success"===e.result?GameLib.Event.Emit(GameLib.Event.COMPONENT_DELETED,{message:e.message||"Successfully saved the component"}):GameLib.Event.Emit(GameLib.Event.DELETE_COMPONENT_ERROR,{message:e.message||"The server responded but failed to save the component"})}},i.send(JSON.stringify({session:this.token}))}.bind(this))}.bind(this),function(e){throw console.error(e.message),new Error(e.message)})},GameLib.System.Storage.prototype.save=function(e){var t=GameLib.Event.GET_API_URL;e.remote&&(t=GameLib.Event.GET_REMOTE_API_URL),this.publish(t,null,function(t){if("undefined"==typeof XMLHttpRequest)return void console.log("Implement server side save here");var i=new XMLHttpRequest;i.open("POST",t.apiUrl+"/component/create"),i.setRequestHeader("Accept","application/json"),i.setRequestHeader("Content-Type","application/json"),i.setRequestHeader("x-authorization",t.passwoid),i.onreadystatechange=function(){if(4===this.readyState){try{var t=JSON.parse(this.responseText)}catch(t){GameLib.Event.Emit(GameLib.Event.SAVE_COMPONENT_ERROR,{message:this.responseText,component:e.apiObject})}"success"===t.result?GameLib.Event.Emit(GameLib.Event.COMPONENT_SAVED,{message:t.message||"Successfully saved the component",component:e.apiObject}):GameLib.Event.Emit(GameLib.Event.SAVE_COMPONENT_ERROR,{message:t.message||"The server responded but failed to save the component",component:e.apiObject})}},i.send(JSON.stringify({component:e.apiObject,session:this.token}))})},GameLib.System.Storage.prototype.createRuntimeObject=function(e,t){try{var i=JSON.parse(e)}catch(e){return this.onComponentError&&this.onComponentError(e),t&&t({message:e.message||"JSON parse error"}),GameLib.Event.Emit(GameLib.Event.LOAD_COMPONENT_ERROR,{error:e}),null}if("success"!==i.result)return this.onComponentError&&this.onComponentError(id,i),t&&t({message:i.message||"Server load error"}),GameLib.Event.Emit(GameLib.Event.LOAD_COMPONENT_ERROR,{error:i}),null;var n=GameLib.Component.Construct(i.component[0]);return n||t&&t({result:"failure",message:"Could not create a runtime component: "+i.component[0].name}),n},GameLib.System.Storage.prototype.loadComponent=function(e,t,i,n,a){t.map(function(e){GameLib.Utils.PushUnique(this.loading,e);var t=GameLib.EntityManager.Instance.findComponentById(e);t&&t.remove()}.bind(this)),t.map(function(t){var s=new XMLHttpRequest;s.onload=function(s){return function(){var o=s.createRuntimeObject.bind(s)(this.responseText);if(!o)return void s.failed.push(t);if(o.parentEntity&&"string"==typeof o.parentEntity&&GameLib.EntityManager.Instance.queryComponents(GameLib.Component.ENTITY).map(function(e){o.parentEntity===e.id&&(o.parentEntity=e)}),GameLib.Event.Emit(GameLib.Event.COMPONENT_CREATED,{component:o}),s.loaded.push(o.id),i){var r=o.getDependencies();s.otherDependencies.map(function(e){var t=r.indexOf(e);-1!==t&&r.splice(t,1)}),r.map(function(e){GameLib.Utils.PushUnique(this.otherDependencies,e)}.bind(s)),r=r.reduce(function(e,t){return-1===s.failed.indexOf(t)?e.push(t):console.log("ignoring failed component : "+t),e}.bind(s),[]),r=r.reduce(function(e,t){return GameLib.EntityManager.Instance.findComponentById(t)||e.push(t),e},[]),r=r.reduce(function(e,t){return-1===s.loaded.indexOf(t)&&e.push(t),e},[]),r.map(function(e){GameLib.Utils.PushUnique(s.loading,e)}),s.loadComponent(e,r,i,n,a),GameLib.Event.Emit(GameLib.Event.LOAD_PROGRESS,{loaded:s.loaded.length,toProcess:r.length})}s.onComponentLoaded&&s.onComponentLoaded(o)}}(this),s.onprogress=function(e){return function(t){var i=0;0!==t.total&&(i=Math.round(100*Number(t.loaded/t.total))),this.onComponentProgress&&this.onComponentProgress(e,i)}.bind(this)}(t),s.onerror=function(e){return function(t){console.warn("component load failed for component ID "+e),this.onComponentError&&this.onComponentError(e,t),a&&a({message:"xhr request failure"})}.bind(this)}(t),s.open("GET",e+"/component/load/"+t),s.send()}.bind(this))},GameLib.System.Storage.prototype.load=function(e,t,i){this.publish(GameLib.Event.GET_API_URL,null,function(n){if("undefined"==typeof XMLHttpRequest)return void console.log("Implement server side load here");e.ids&&e.ids.length>0?this.loadComponent(n.apiUrl,e.ids,e.includeDependencies,t,i):console.log("No components selected")}.bind(this),function(e){throw console.error(e.message),new Error(e.message)})},GameLib.System.Storage.prototype.xhrLoad=function(e,t,i){if("undefined"==typeof XMLHttpRequest)return void console.log("Implement server side load here");console.log("Loading...","success");var n=new XMLHttpRequest;n.open("GET",e),n.setRequestHeader("Accept","application/json"),n.setRequestHeader("Content-Type","application/json"),n.onreadystatechange=function(){if(4===n.readyState){if(!n.responseText)return console.log("Invalid response from server"),void i({message:"Invalid response from server"});try{var e=JSON.parse(n.responseText)}catch(e){e.message="Could not parse JSON",i(e)}if("success"!==e.result)return i({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){var t=GameLib.EntityManager.Instance.queryComponents(GameLib.Component.IMAGE);e.images.map(function(e){var i=null;e?GameLib.Component.Construct(e):(i=t.reduce(function(t,i){return e.id===i.id&&(t=i),t},null),i.updateInstance("path"))}.bind(this))},GameLib.System.Storage.prototype.processBlenderData=function(e){console.log("loading blender data"),e.images.map(function(e){var t=GameLib.Component.Construct(e);GameLib.Event.Emit(GameLib.Event.COMPONENT_CREATED,{component:t})}.bind(this)),e.textures.map(function(e){var t=GameLib.Component.Construct(e);GameLib.Event.Emit(GameLib.Event.COMPONENT_CREATED,{component:t})}.bind(this)),e.materials.map(function(e){var t=GameLib.Component.Construct(e);GameLib.Event.Emit(GameLib.Event.COMPONENT_CREATED,{component:t})}.bind(this)),e.meshes.map(function(e){var t=GameLib.Component.Construct(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){var a=n.apiUrl+"/fonts/"+e.font.url+"?ts="+Date.now();(new THREE.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){var a=this.onImageLoaded,s=this.onImageProgress,o=this.onImageError,r=e.image,c=n.apiUrl+r.path+r.fileName+r.extension+"?ts="+Date.now(),m=new XMLHttpRequest;m.withCredentials=!0,m.open("OPTIONS",c),m.setRequestHeader("Content-Type","application/json"),m.onload=function(){var n=new XMLHttpRequest;n.withCredentials=!0,n.open("GET",c),n.setRequestHeader("Content-Type",r.contentType),n.responseType="blob",n.onload=function(){var n=!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})}var o=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){var t=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){throw console.error(e.message),new Error(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,t,i){GameLib.System.call(this,e),GameLib.Utils.UndefinedOrNull(t)&&GameLib.Event.Emit(GameLib.Event.GET_GRAPHICS_RUNTIME,null,function(e){t=e}.bind(this),function(){t=null}.bind(this)),this.graphics=t,GameLib.Utils.UndefinedOrNull(i)&&GameLib.Event.Emit(GameLib.Event.GET_PHYSICS_RUNTIME,null,function(e){i=e}.bind(this),function(){i=null}.bind(this)),this.physics=i,this.visualizationSubscription=null,this.stopVisualizationSubscription=null},GameLib.System.Visualization.prototype=Object.create(GameLib.System.prototype),GameLib.System.Visualization.prototype.constructor=GameLib.System.Visualization,GameLib.System.Visualization.prototype.start=function(){GameLib.System.prototype.start.call(this),this.visualizationSubscription=this.subscribe(GameLib.Event.VISUALIZE,this.visualize),this.stopVisualizationSubscription=this.subscribe(GameLib.Event.STOP_VISUALIZE,this.stopVisualize)},GameLib.System.Visualization.prototype.visualize=function(e){var t=e.shape;t.parentMesh;t.setFromMesh();var i=new GameLib.D3.API.Mesh;if(i.name="Visualization Mesh for Shape "+t.name,t instanceof GameLib.D3.Shape.HeightMap)for(var n=new CANNON.Vec3,a=new CANNON.Vec3,s=new CANNON.Vec3,o=0;o this.maxSpeed) { - this.currentSpeed = this.maxSpeed; - } - this.grain = (this.currentSpeed / 100.0); - - var currentPosition = this.spline.getPointAt(this.currentPathValue); - - this.currentPosition.x = currentPosition.x; - this.currentPosition.y = currentPosition.y; - this.currentPosition.z = currentPosition.z; - - this.currentPathValue += this.grain; - - if (this.currentPathValue >= 1) { - this.currentPathValue = this.currentPathValue - 1; - } - - if (this.currentPathValue < 0) { - this.currentPathValue = 0.0; - } - - var futurePosition = this.spline.getPointAt(this.currentPathValue); - - this.futurePosition.x = futurePosition.x; - this.futurePosition.y = futurePosition.y; - this.futurePosition.z = futurePosition.z; - - this.raycaster.setPosition( - this.currentPosition - ); - - this.raycaster.setDirection( - { - x : -this.up.x, - y : -this.up.y, - z : -this.up.z - } - ); - - var normal = this.raycaster.getFaceNormal(this.raytraceMesh); - - if (normal) { - this.up.x = this.mx(normal.x); - this.up.y = this.my(normal.y); - this.up.z = this.mz(normal.z); - } - - this.rotationMatrix.lookAt( - this.currentPosition, - this.futurePosition, - this.up - ); - - this.rotationVector.setFromRotationMatrix(this.rotationMatrix); - - this.mesh.position.x = this.futurePosition.x; - this.mesh.position.y = this.futurePosition.y; - this.mesh.position.z = this.futurePosition.z; - - /** - * Update Rotation - */ - this.mesh.quaternion.x = this.rotationVector.x; - this.mesh.quaternion.y = this.rotationVector.y; - this.mesh.quaternion.z = this.rotationVector.z; - this.mesh.quaternion.w = this.rotationVector.w; - } -}; /** * World SuperSet - contains the custom world instance * @constructor @@ -18093,7 +17680,6 @@ GameLib.D3.PhysicsWorld = function( GameLib.Component.call( this, - GameLib.Component.COMPONENT_PHYSICS_WORLD, { 'broadphase' : GameLib.D3.Broadphase, 'solver' : GameLib.D3.Solver, @@ -18162,7 +17748,7 @@ GameLib.D3.PhysicsWorld.prototype.createInstance = function() { throw new Error('no rigidbody instance'); } - rigidBody.parentWorld = this; + rigidBody.parentPhysicsWorld = this; this.instance.add(rigidBody.instance); @@ -18189,10 +17775,10 @@ GameLib.D3.PhysicsWorld.prototype.addRigidBody = function(rigidBody) { this.instance.add(rigidBody.instance); /** - * Remember to set the parentWorld for this rigidBody + * Remember to set the parentPhysicsWorld for this rigidBody * @type {GameLib.D3.PhysicsWorld} */ - rigidBody.parentWorld = this; + rigidBody.parentPhysicsWorld = this; /** * Ensure this rigidBody is in our rigidBodies array, just not too many times.. @@ -18227,10 +17813,10 @@ GameLib.D3.PhysicsWorld.prototype.removeRigidBody = function(rigidBody) { } /** - * Remember to set the parentWorld for this rigidBody + * Remember to set the parentPhysicsWorld for this rigidBody * @type {GameLib.D3.PhysicsWorld} */ - rigidBody.parentWorld = null; + rigidBody.parentPhysicsWorld = null; /** * Remove from this rigidBodies array @@ -19115,7 +18701,7 @@ GameLib.D3.RaycastVehicle = function ( apiRaycastVehicle.chassis, apiRaycastVehicle.wheels, apiRaycastVehicle.raycastWheels, - apiRaycastVehicle.parentWorld, + apiRaycastVehicle.parentPhysicsWorld, apiRaycastVehicle.parentEntity ); @@ -19150,12 +18736,11 @@ GameLib.D3.RaycastVehicle = function ( GameLib.Component.call( this, - GameLib.Component.COMPONENT_RAYCAST_VEHICLE, { 'chassis' : GameLib.D3.RigidBody, 'wheels' : [GameLib.D3.RigidBody], 'raycastWheels' : [GameLib.D3.RaycastWheel], - 'parentWorld' : GameLib.D3.PhysicsWorld + 'parentPhysicsWorld' : GameLib.D3.PhysicsWorld } ); }; @@ -19184,11 +18769,11 @@ GameLib.D3.RaycastVehicle.prototype.createInstance = function() { throw new Error('no chassis instance'); } - if (GameLib.Utils.UndefinedOrNull(this.parentWorld)) { + if (GameLib.Utils.UndefinedOrNull(this.parentPhysicsWorld)) { throw new Error('no parent world'); } - if (GameLib.Utils.UndefinedOrNull(this.parentWorld.instance)) { + if (GameLib.Utils.UndefinedOrNull(this.parentPhysicsWorld.instance)) { throw new Error('no parent world instance'); } @@ -19212,7 +18797,7 @@ GameLib.D3.RaycastVehicle.prototype.createInstance = function() { }.bind(this) ); - this.instance.addToWorld(this.parentWorld.instance); + this.instance.addToWorld(this.parentPhysicsWorld.instance); GameLib.Component.prototype.createInstance.call(this); @@ -19240,7 +18825,7 @@ GameLib.D3.RaycastVehicle.prototype.toApiObject = function() { this.raycastWheels.map(function(raycastWheel){ return GameLib.Utils.IdOrNull(raycastWheel); }), - GameLib.Utils.IdOrNull(this.parentWorld), + GameLib.Utils.IdOrNull(this.parentPhysicsWorld), GameLib.Utils.IdOrNull(this.parentEntity) ); @@ -19304,8 +18889,8 @@ GameLib.D3.RaycastWheel = function ( apiRaycastWheel.maxSuspensionTravel, apiRaycastWheel.customSlidingRotationalSpeed, apiRaycastWheel.useCustomSlidingRotationalSpeed, - apiRaycastWheel.parentEntity, - apiRaycastWheel.parentMesh + apiRaycastWheel.parentMesh, + apiRaycastWheel.parentEntity ); this.directionLocal = new GameLib.Vector3( @@ -19328,7 +18913,6 @@ GameLib.D3.RaycastWheel = function ( GameLib.Component.call( this, - GameLib.Component.COMPONENT_RAYCAST_WHEEL, { 'parentMesh' : GameLib.D3.Mesh } @@ -19404,8 +18988,8 @@ GameLib.D3.RaycastWheel.prototype.toApiObject = function() { this.maxSuspensionTravel, this.customSlidingRotationalSpeed, this.useCustomSlidingRotationalSpeed, - GameLib.Utils.IdOrNull(this.parentEntity), - GameLib.Utils.IdOrNull(this.parentMesh) + GameLib.Utils.IdOrNull(this.parentMesh), + GameLib.Utils.IdOrNull(this.parentEntity) ); return apiRaycastWheel; @@ -19481,10 +19065,7 @@ GameLib.D3.Raycaster = function( this ); - GameLib.Component.call( - this, - GameLib.Component.COMPONENT_RAYCASTER - ); + GameLib.Component.call(this); }; GameLib.D3.Raycaster.prototype = Object.create(GameLib.D3.API.Raycaster.prototype); @@ -19524,7 +19105,8 @@ GameLib.D3.Raycaster.prototype.toApiObject = function() { this.id, this.name, this.position.toApiObject(), - this.direction.toApiObject() + this.direction.toApiObject(), + GameLib.Utils.IdOrNull(this.parentEntity) ) }; @@ -19754,7 +19336,6 @@ GameLib.D3.RenderTarget = function ( GameLib.Component.call( this, - GameLib.Component.COMPONENT_RENDER_TARGET, { 'texture' : GameLib.D3.Texture } @@ -19978,7 +19559,6 @@ GameLib.D3.Renderer = function ( GameLib.Component.call( this, - GameLib.Component.COMPONENT_RENDERER, { 'domElement' : GameLib.DomElement, 'camera' : GameLib.D3.Camera, @@ -20330,7 +19910,7 @@ GameLib.D3.RigidBody = function ( apiRigidBody.shapes, apiRigidBody.kinematic, apiRigidBody.parentMesh, - apiRigidBody.parentWorld, + apiRigidBody.parentPhysicsWorld, apiRigidBody.parentEntity ); @@ -20368,11 +19948,10 @@ GameLib.D3.RigidBody = function ( GameLib.Component.call( this, - GameLib.Component.COMPONENT_RIGID_BODY, { 'shapes' : [GameLib.D3.Shape], 'parentMesh' : GameLib.D3.Mesh, - 'parentWorld' : GameLib.D3.PhysicsWorld + 'parentPhysicsWorld' : GameLib.D3.PhysicsWorld } ); }; @@ -20540,7 +20119,7 @@ GameLib.D3.RigidBody.prototype.toApiObject = function() { this.shapes.map(function(shape){return GameLib.Utils.IdOrNull(shape)}), this.kinematic, GameLib.Utils.IdOrNull(this.parentMesh), - GameLib.Utils.IdOrNull(this.parentWorld), + GameLib.Utils.IdOrNull(this.parentPhysicsWorld), GameLib.Utils.IdOrNull(this.parentEntity) ); @@ -20695,9 +20274,9 @@ GameLib.D3.Scene = function ( this.images = this.images.map( function(apiImage) { - if (apiImage instanceof GameLib.D3.API.Image) { + if (apiImage instanceof GameLib.API.Image) { - var image = new GameLib.D3.Image( + var image = new GameLib.Image( this.graphics, apiImage ); @@ -20748,13 +20327,12 @@ GameLib.D3.Scene = function ( GameLib.Component.call( this, - GameLib.Component.COMPONENT_SCENE, { 'meshes' : [GameLib.D3.Mesh], 'lights' : [GameLib.D3.Light], 'textures' : [GameLib.D3.Texture], 'materials' : [GameLib.D3.Material], - 'images' : [GameLib.D3.Image], + 'images' : [GameLib.Image], 'fog' : GameLib.D3.Fog, 'renderCamera' : GameLib.D3.Camera } @@ -21240,7 +20818,9 @@ GameLib.D3.Shape = function ( this.physics.isNotCannonThrow(); if (GameLib.Utils.UndefinedOrNull(apiShape)) { - apiShape = {}; + apiShape = { + shapeType : GameLib.D3.API.Shape.SHAPE_TYPE_NONE + }; } if (apiShape instanceof GameLib.D3.Shape) { @@ -21251,6 +20831,7 @@ GameLib.D3.Shape = function ( this, apiShape.id, apiShape.name, + apiShape.shapeType, apiShape.boundingSphereRadius, apiShape.collisionResponse, apiShape.frictionMaterial, @@ -21258,44 +20839,13 @@ GameLib.D3.Shape = function ( apiShape.parentEntity ); - var componentType = GameLib.Component.COMPONENT_SHAPE; - var linkedObjects = { frictionMaterial : GameLib.D3.FrictionMaterial, parentMesh : GameLib.D3.Mesh }; - if (this instanceof GameLib.D3.Shape.Box) { - componentType = GameLib.Component.COMPONENT_SHAPE_BOX; - } - - if (this instanceof GameLib.D3.Shape.ConvexHull) { - componentType = GameLib.Component.COMPONENT_SHAPE_CONVEX_HULL; - } - - if (this instanceof GameLib.D3.Shape.ConvexHull.Cylinder) { - componentType = GameLib.Component.COMPONENT_SHAPE_CONVEX_HULL_CYLINDER; - } - - if (this instanceof GameLib.D3.Shape.Sphere) { - componentType = GameLib.Component.COMPONENT_SHAPE_SPHERE; - } - - if (this instanceof GameLib.D3.Shape.TriMesh) { - componentType = GameLib.Component.COMPONENT_SHAPE_TRI_MESH; - } - - if (this instanceof GameLib.D3.Shape.Plane) { - componentType = GameLib.Component.COMPONENT_SHAPE_PLANE; - } - - if (this instanceof GameLib.D3.Shape.HeightMap) { - componentType = GameLib.Component.COMPONENT_SHAPE_HEIGHT_MAP; - } - GameLib.Component.call( this, - componentType, linkedObjects ); }; @@ -21303,6 +20853,7 @@ GameLib.D3.Shape = function ( GameLib.D3.Shape.prototype = Object.create(GameLib.D3.API.Shape.prototype); GameLib.D3.Shape.prototype.constructor = GameLib.D3.Shape; + /** * Creates a shape instance or updates it */ @@ -21326,6 +20877,7 @@ GameLib.D3.Shape.prototype.toApiObject = function() { var apiShape = new GameLib.D3.API.Shape( this.id, this.name, + this.shapeType, this.boundingSphereRadius, this.collisionResponse, GameLib.Utils.IdOrNull(this.frictionMaterial), @@ -21378,6 +20930,16 @@ GameLib.D3.Shape.Box = function ( this.physics = physics; this.physics.isNotCannonThrow(); + if (GameLib.Utils.UndefinedOrNull(apiShape)) { + apiShape = { + shapeType : GameLib.D3.API.Shape.SHAPE_TYPE_BOX + }; + } + + if (apiShape instanceof GameLib.D3.Shape.Box) { + return apiShape; + } + if (GameLib.Utils.UndefinedOrNull(halfExtents)) { halfExtents = new GameLib.Vector3( physics, @@ -21494,7 +21056,9 @@ GameLib.D3.Shape.ConvexHull = function ( this.physics.isNotCannonThrow(); if (GameLib.Utils.UndefinedOrNull(apiShape)) { - apiShape = {}; + apiShape = { + shapeType : GameLib.D3.API.Shape.SHAPE_TYPE_CONVEX_HULL + }; } if (apiShape instanceof GameLib.D3.Shape.ConvexHull) { @@ -21776,6 +21340,16 @@ GameLib.D3.Shape.ConvexHull.Cylinder = function ( this.physics = physics; this.physics.isNotCannonThrow(); + if (GameLib.Utils.UndefinedOrNull(apiShape)) { + apiShape = { + shapeType : GameLib.D3.API.Shape.SHAPE_TYPE_CONVEX_HULL_CYLINDER + }; + } + + if (apiShape instanceof GameLib.D3.Shape.ConvexHull.Cylinder) { + return apiShape; + } + if (GameLib.Utils.UndefinedOrNull(radiusTop)) { radiusTop = 1; } @@ -21903,6 +21477,16 @@ GameLib.D3.Shape.HeightMap = function ( this.physics = physics; this.physics.isNotCannonThrow(); + if (GameLib.Utils.UndefinedOrNull(apiShape)) { + apiShape = { + shapeType : GameLib.D3.API.Shape.SHAPE_TYPE_HEIGHT_MAP + }; + } + + if (apiShape instanceof GameLib.D3.Shape.HeightMap) { + return apiShape; + } + if (GameLib.Utils.UndefinedOrNull(heightData)) { heightData = [[10, 10, 10], [10, 10, 10], [10, 10, 10]]; } @@ -22060,6 +21644,16 @@ GameLib.D3.Shape.Plane = function ( this.physics = physics; this.physics.isNotCannonThrow(); + if (GameLib.Utils.UndefinedOrNull(apiShape)) { + apiShape = { + shapeType : GameLib.D3.API.Shape.SHAPE_TYPE_PLANE + }; + } + + if (apiShape instanceof GameLib.D3.Shape.Plane) { + return apiShape; + } + GameLib.D3.Shape.call( this, this.physics, @@ -22109,6 +21703,16 @@ GameLib.D3.Shape.Sphere = function ( this.physics = physics; this.physics.isNotCannonThrow(); + if (GameLib.Utils.UndefinedOrNull(apiShape)) { + apiShape = { + shapeType : GameLib.D3.API.Shape.SHAPE_TYPE_SPHERE + }; + } + + if (apiShape instanceof GameLib.D3.Shape.Sphere) { + return apiShape; + } + if (GameLib.Utils.UndefinedOrNull(radius)) { radius = 1; } @@ -22176,6 +21780,16 @@ GameLib.D3.Shape.TriMesh = function ( this.physics = physics; this.physics.isNotCannonThrow(); + if (GameLib.Utils.UndefinedOrNull(apiShape)) { + apiShape = { + shapeType : GameLib.D3.API.Shape.SHAPE_TYPE_TRIMESH + }; + } + + if (apiShape instanceof GameLib.D3.Shape.TriMesh) { + return apiShape; + } + if (GameLib.Utils.UndefinedOrNull(vertices)) { vertices = []; } @@ -22291,7 +21905,6 @@ GameLib.D3.Skeleton = function Skeleton( }.bind(this) ); - this.boneMatrices = this.boneMatrices.map( function(boneMatrices) { if (boneMatrices instanceof GameLib.API.Matrix4) { @@ -22310,9 +21923,8 @@ GameLib.D3.Skeleton = function Skeleton( GameLib.Component.call( this, - GameLib.Component.COMPONENT_SKELETON, { - 'bones' : [GameLib.D3.Bone] + 'bones' : [GameLib.D3.Bone] } ); }; @@ -22434,7 +22046,7 @@ GameLib.D3.Skeleton.prototype.toApiObject = function() { } ), this.boneTexture, - this.parentEntity + GameLib.Utils.IdOrNull(this.parentEntity) ); return apiSkeleton; @@ -22497,10 +22109,7 @@ GameLib.D3.Solver = function ( apiSolver.parentEntity ); - GameLib.Component.call( - this, - GameLib.Component.COMPONENT_SOLVER - ); + GameLib.Component.call(this); }; GameLib.D3.Solver.prototype = Object.create(GameLib.D3.API.Solver.prototype); @@ -22512,9 +22121,9 @@ GameLib.D3.Solver.prototype.constructor = GameLib.D3.Solver; */ GameLib.D3.Solver.prototype.createInstance = function() { - if (this.solverType === GameLib.D3.Solver.GS_SOLVER) { + if (this.solverType === GameLib.D3.API.Solver.GS_SOLVER) { this.instance = new CANNON.GSSolver(); - } else if (this.solverType === GameLib.D3.Solver.SPLIT_SOLVER) { + } else if (this.solverType === GameLib.D3.API.Solver.SPLIT_SOLVER) { this.instance = new CANNON.SplitSolver(); } else { throw new Error('unsupported solver type: ' + this.solverType); @@ -22531,13 +22140,13 @@ GameLib.D3.Solver.prototype.createInstance = function() { */ GameLib.D3.Solver.prototype.updateInstance = function() { - if (this.solverType === GameLib.D3.Solver.GS_SOLVER) { + if (this.solverType === GameLib.D3.API.Solver.GS_SOLVER) { if (!(this.instance instanceof CANNON.GSSolver)) { this.instance = new CANNON.GSSolver(); } } - if (this.solverType === GameLib.D3.Solver.SPLIT_SOLVER) { + if (this.solverType === GameLib.D3.API.Solver.SPLIT_SOLVER) { if (!(this.instance instanceof CANNON.SplitSolver)) { this.instance = new CANNON.SplitSolver(); } @@ -22582,13 +22191,6 @@ GameLib.D3.Solver.FromObject = function(graphics, objectComponent) { ); }; -/** - * Solver Types - * @type {number} - */ -GameLib.D3.Solver.GS_SOLVER = 0x1; -GameLib.D3.Solver.SPLIT_SOLVER = 0x2; - /** * Spline constructor * @param graphics GameLib.GraphicsRuntime @@ -22628,10 +22230,7 @@ GameLib.D3.Spline = function ( } ); - GameLib.Component.call( - this, - GameLib.Component.COMPONENT_SPLINE - ); + GameLib.Component.call(this); }; GameLib.D3.Spline.prototype = Object.create(GameLib.D3.API.Spline.prototype); @@ -22738,91 +22337,6 @@ GameLib.D3.Spline.prototype.getPointAt = function(proper) { ); }; -/** - * Stats component for displaying some render statistics (framerate, memory consumption, etc) - * @param stats - * @param id - * @param name - * @param domElement - * @param parentEntity - * @constructor - */ -GameLib.D3.Stats = function( - stats, - id, - name, - domElement, - parentEntity -) { - this.stats = stats; - this.stats.isNotStatsThrow(); - - if (GameLib.Utils.UndefinedOrNull(id)) { - id = GameLib.Utils.RandomId(); - } - this.id = id; - - if (GameLib.Utils.UndefinedOrNull(name)) { - name = 'Stats (' + id + ')'; - } - this.name = name; - - if (GameLib.Utils.UndefinedOrNull(domElement)) { - console.warn('Need a DOM element for stats'); - throw new Error('Need a DOM element for stats'); - } - this.domElement = domElement; - - if (GameLib.Utils.UndefinedOrNull(parentEntity)) { - parentEntity = null; - } - this.parentEntity = parentEntity; - - 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'); -}; - -/** - * Creates a helper instance - */ -GameLib.D3.Stats.prototype.createInstance = function() { - - this.instance = this.stats.instance(); - - this.resize(); - - this.domElement.instance.parentElement.appendChild(this.instance.dom); - - GameLib.Component.prototype.createInstance.call(this); -}; - -/** - * Updates the instance with the current state - */ -GameLib.D3.Stats.prototype.updateInstance = function() { - this.instance = new this.stats(); -}; - -GameLib.D3.Stats.prototype.start = function() { - this.instance.begin(); -}; - -GameLib.D3.Stats.prototype.end = function() { - this.instance.end(); -}; - /** * Texture Superset - The apiTexture properties get moved into the Texture object itself, and then the instance is * created @@ -22848,7 +22362,7 @@ GameLib.D3.Texture = function( GameLib.D3.API.Texture.call( this, apiTexture.id, - apiTexture.typeId, + apiTexture.textureType, apiTexture.name, apiTexture.image, apiTexture.images, @@ -22888,8 +22402,8 @@ GameLib.D3.Texture = function( this ); - if (this.image instanceof GameLib.D3.API.Image) { - this.image = new GameLib.D3.Image( + if (this.image instanceof GameLib.API.Image) { + this.image = new GameLib.Image( this.graphics, this.image ); @@ -22897,8 +22411,8 @@ GameLib.D3.Texture = function( this.images = this.images.map( function(image) { - if (image instanceof GameLib.D3.API.Image) { - return new GameLib.D3.Image( + if (image instanceof GameLib.API.Image) { + return new GameLib.Image( this.graphics, image ); @@ -22917,10 +22431,9 @@ GameLib.D3.Texture = function( GameLib.Component.call( this, - GameLib.Component.COMPONENT_TEXTURE, { - 'image' : GameLib.D3.Image, - 'images' : [GameLib.D3.Image], + 'image' : GameLib.Image, + 'images' : [GameLib.Image], 'canvas' : GameLib.Canvas } ); @@ -22929,86 +22442,13 @@ GameLib.D3.Texture = function( GameLib.D3.Texture.prototype = Object.create(GameLib.D3.API.Texture.prototype); GameLib.D3.Texture.prototype.constructor = GameLib.D3.Texture; -/** - * Texture Formats - * @type {number} - */ -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; - -/** - * Mapping modes - * @type {number} - */ -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; - -/** - * Wrapping Modes - * @type {number} - */ -GameLib.D3.Texture.TYPE_REPEAT_WRAPPING = 1000; -GameLib.D3.Texture.TYPE_CLAMP_TO_EDGE_WRAPPING = 1001; -GameLib.D3.Texture.TYPE_MIRRORED_REPEAT_WRAPPING = 1002; - -/** - * Mipmap Filters - * @type {number} - */ -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; - -/** - * Texture Data Types - * @type {number} - */ -GameLib.D3.Texture.TYPE_UNSIGNED_BYTE = 1009; -GameLib.D3.Texture.TYPE_BYTE = 1010; -GameLib.D3.Texture.TYPE_SHORT = 1011; -GameLib.D3.Texture.TYPE_UNSIGNED_SHORT = 1012; -GameLib.D3.Texture.TYPE_INT = 1013; -GameLib.D3.Texture.TYPE_UNSIGNED_INT = 1014; -GameLib.D3.Texture.TYPE_FLOAT = 1015; -GameLib.D3.Texture.TYPE_HALF_FLOAT = 1025; - -/** - * Encoding Modes - * @type {number} - */ -GameLib.D3.Texture.TYPE_LINEAR_ENCODING = 3000; // NO ENCODING AT ALL. -GameLib.D3.Texture.TYPE_SRGB_ENCODING = 3001; -GameLib.D3.Texture.TYPE_GAMMA_ENCODING = 3007; // USES GAMMA_FACTOR, FOR BACKWARDS COMPATIBILITY WITH WEBGLRENDERER.GAMMAINPUT/GAMMAOUTPUT -GameLib.D3.Texture.TYPE_RGBE_ENCODING = 3002; // AKA RADIANCE. -GameLib.D3.Texture.TYPE_LOG_LUV_ENCODING = 3003; -GameLib.D3.Texture.TYPE_RGBM7_ENCODING = 3004; -GameLib.D3.Texture.TYPE_RGBM16_ENCODING = 3005; -GameLib.D3.Texture.TYPE_RGBD_ENCODING = 3006; // MAXRANGE IS 256. - -GameLib.D3.Texture.TEXTURE_TYPE_NORMAL = 0x1; -GameLib.D3.Texture.TEXTURE_TYPE_CUBE = 0x2; -GameLib.D3.Texture.TEXTURE_TYPE_CANVAS = 0x3; - /** * Creates an instance of our texture object * @returns {*} */ GameLib.D3.Texture.prototype.createInstance = function() { - if (this.typeId === GameLib.D3.Texture.TEXTURE_TYPE_CUBE) { + if (this.textureType === GameLib.D3.API.Texture.TEXTURE_TYPE_CUBE) { if (this.images.length !== 6) { throw new Error('not enough images for cube texture'); @@ -23031,7 +22471,7 @@ GameLib.D3.Texture.prototype.createInstance = function() { this.instance = new THREE.CubeTexture(imageInstances); - } else if (this.typeId === GameLib.D3.Texture.TEXTURE_TYPE_NORMAL) { + } else if (this.textureType === GameLib.D3.API.Texture.TEXTURE_TYPE_NORMAL) { if ( GameLib.Utils.UndefinedOrNull(this.image) || @@ -23052,7 +22492,7 @@ GameLib.D3.Texture.prototype.createInstance = function() { } - } else if (this.typeId === GameLib.D3.Texture.TEXTURE_TYPE_CANVAS) { + } else if (this.textureType === GameLib.D3.API.Texture.TEXTURE_TYPE_CANVAS) { if (GameLib.Utils.UndefinedOrNull(this.canvas)) { @@ -23116,7 +22556,7 @@ GameLib.D3.Texture.prototype.updateInstance = function(property) { if (property === 'image') { - if (this.typeId === GameLib.D3.Texture.TEXTURE_TYPE_NORMAL) { + if (this.textureType === GameLib.D3.API.Texture.TEXTURE_TYPE_NORMAL) { if ( GameLib.Utils.UndefinedOrNull(this.image) && @@ -23137,7 +22577,7 @@ GameLib.D3.Texture.prototype.updateInstance = function(property) { } } - } else if (this.typeId === GameLib.D3.Texture.TEXTURE_TYPE_CANVAS) { + } else if (this.textureType === GameLib.D3.API.Texture.TEXTURE_TYPE_CANVAS) { if ( GameLib.Utils.UndefinedOrNull(this.canvas) && @@ -23158,7 +22598,7 @@ GameLib.D3.Texture.prototype.updateInstance = function(property) { } } - } else if (this.typeId === GameLib.D3.Texture.TEXTURE_TYPE_CUBE) { + } else if (this.textureType === GameLib.D3.API.Texture.TEXTURE_TYPE_CUBE) { console.log('todo : cube images change check here'); @@ -23230,7 +22670,7 @@ GameLib.D3.Texture.prototype.toApiObject = function() { var apiTexture = new GameLib.D3.API.Texture( this.id, - this.typeId, + this.textureType, this.name, GameLib.Utils.IdOrNull(this.image), this.images.map( @@ -23418,10 +22858,7 @@ GameLib.D3.Viewport = function ( apiViewport.parentEntity ); - GameLib.Component.call( - this, - GameLib.Component.COMPONENT_VIEWPORT - ); + GameLib.Component.call(this); }; GameLib.D3.Viewport.prototype = Object.create(GameLib.D3.API.Viewport.prototype); @@ -23502,10 +22939,7 @@ GameLib.DomElement = function (apiDomElement) { this.fullscreen = false; - GameLib.Component.call( - this, - GameLib.Component.COMPONENT_DOM_ELEMENT - ); + GameLib.Component.call(this); }; GameLib.DomElement.prototype = Object.create(GameLib.API.DomElement.prototype); @@ -23599,20 +23033,6 @@ GameLib.DomElement.FromObject = function(objectDom) { return domElement; }; -/** - * Runtime Dom - * @constructor - * @param document DOM Document - * @param window DOM Window - */ -GameLib.Dom = function( - document, - window -) { - this.document = document; - this.window = window; -}; - /** * GameLib.EntityManager * @constructor @@ -23633,7 +23053,8 @@ GameLib.EntityManager = function(apiEntityManager) { apiEntityManager.name, apiEntityManager.entities, apiEntityManager.defaultEntity, - apiEntityManager.defaultRenderer + apiEntityManager.defaultRenderer, + apiEntityManager.parentEntity ); /** @@ -23641,7 +23062,9 @@ GameLib.EntityManager = function(apiEntityManager) { * system starts it also loads all the current components from the entity manager * @type {Array} */ - this.register = []; + this.register = {}; + + this.idRegister = {}; GameLib.Event.Subscribe( GameLib.Event.COMPONENT_REGISTER, @@ -23655,7 +23078,6 @@ GameLib.EntityManager = function(apiEntityManager) { GameLib.Component.call( this, - GameLib.Component.COMPONENT_ENTITY_MANAGER, { 'entities' : [GameLib.Entity], 'defaultEntity' : GameLib.Entity, @@ -23674,15 +23096,30 @@ GameLib.EntityManager.prototype.createInstance = function() { GameLib.EntityManager.prototype.registerComponent = function(data) { - var length = this.register.length; + var updated = false; - GameLib.Utils.PushUnique(this.register, data.component); + if (GameLib.Utils.UndefinedOrNull(this.register[data.component.componentType])) { + this.register[data.component.componentType] = {}; + updated = true; + } - if (length !== this.register.length) { - GameLib.Event.Emit( + if (GameLib.Utils.UndefinedOrNull(this.register[data.component.componentType][data.component.id])) { + this.register[data.component.componentType][data.component.id] = data.component; + updated = true; + } + + if (GameLib.Utils.UndefinedOrNull(this.idRegister[data.component.id])) { + this.idRegister[data.component.id] = data.component; + updated = true; + } + + if (updated) { + GameLib.Event.Emit( GameLib.Event.REGISTER_UPDATE, { - register : this.register + componentType : data.component.componentType, + components : this.register[data.component.componentType], + idRegister : this.idRegister } ); } @@ -23690,16 +23127,26 @@ GameLib.EntityManager.prototype.registerComponent = function(data) { GameLib.EntityManager.prototype.removeComponent = function(data) { - var index = this.register.indexOf(data.component); + var updated = true; - if (index !== -1) { - - this.register.splice(index, 1); + if (GameLib.Utils.UndefinedOrNull(this.register[data.component.componentType]) || + GameLib.Utils.UndefinedOrNull(this.register[data.component.componentType][data.component.id]) || + GameLib.Utils.UndefinedOrNull(this.idRegister[data.component.id]) + ) { + console.warn('register out of sync'); + updated = false; + } else { + delete this.register[data.component.componentType][data.component.id]; + delete this.idRegister[data.component.id]; + } + if (updated) { GameLib.Event.Emit( GameLib.Event.REGISTER_UPDATE, { - register : this.register + componentType : data.component.componentType, + components : this.register[data.component.componentType], + idRegister : this.idRegister } ); } @@ -23745,62 +23192,52 @@ GameLib.EntityManager.prototype.createEntity = function(name) { */ GameLib.EntityManager.prototype.findEntityById = function(id) { - return this.entities.reduce( - function(result, entity){ + var entity = this.register[GameLib.Component.ENTITY][id]; - if (entity.id === id) { - result = entity; - } + if (entity) { + return entity; + } - return result; - }, - null - ); + return null; }; GameLib.EntityManager.prototype.findComponentById = function(id) { - return this.register.reduce( - function(result, component){ - if (component.id === id){ - result = component; - } - return result; - }, - null - ); + return this.idRegister[id]; }; GameLib.EntityManager.prototype.findHelperByObject = function(object) { - return this.register.reduce( - function(result, component) { - if (component instanceof GameLib.D3.Helper) { - if (component.object === object) { - result = component; - } + + return Object.keys(this.register[GameLib.Component.HELPER]).reduce( + function(result, helperId) { + + if (this.register[GameLib.Component.HELPER][helperId].object === object) { + result = this.register[GameLib.Component.HELPER][helperId]; } + return result; - }, + }.bind(this), null ); + }; GameLib.EntityManager.prototype.findSceneByObject = function(object) { - return this.register.reduce( - function(result, component) { - if (component instanceof GameLib.D3.Scene) { - if (component.meshes.indexOf(object) !== -1) { - result = component; - } + return Object.keys(this.register[GameLib.Component.SCENE]).reduce( + function(result, sceneId) { + + if ( + this.register[GameLib.Component.SCENE][sceneId].meshes.indexOf(object) !== -1 || + this.register[GameLib.Component.SCENE][sceneId].lights.indexOf(object) !== -1 + ) { + result = this.register[GameLib.Component.SCENE][sceneId]; + } + + return result; + }.bind(this), + null + ); - if (component.lights.indexOf(object) !== -1) { - result = component; - } - } - return result; - }, - null - ); }; @@ -23883,36 +23320,31 @@ GameLib.EntityManager.prototype.findEntities = function(components) { /** * Returns all actual components of all entities that contain this component - * @param constructors (array of constructor or just a single constructor) + * @param componentTypes (array of constructor or just a single constructor) */ -GameLib.EntityManager.prototype.queryComponents = function(constructors) { +GameLib.EntityManager.prototype.queryComponents = function(componentTypes) { - return this.register.reduce( - function(result, component) { + var result = []; - if (constructors instanceof Array) { - constructors.map( - function(constructor) { - if (component instanceof constructor) { - if (result.indexOf(component) === -1) { - result.push(component); - } - } - } - ); - } else { - if (component instanceof constructors) { - if (result.indexOf(component) === -1) { - result.push(component); - } - } - } - - return result; - }, - [] - ); + if (componentTypes instanceof Array) { + componentTypes.map( + function(componentType) { + Object.keys(this.register[componentType]).map( + function(componentId) { + result.push(this.register[componentType][componentId]); + }.bind(this) + ) + }.bind(this) + ) + } else { + Object.keys(this.register[componentTypes]).map( + function(componentId) { + result.push(this.register[componentTypes][componentId]); + }.bind(this) + ) + } + return result; }; /** @@ -23932,7 +23364,8 @@ GameLib.EntityManager.prototype.toApiObject = function() { this.name, apiEntities, GameLib.Utils.IdOrNull(this.defaultEntity), - GameLib.Utils.IdOrNull(this.defaultRenderer) + GameLib.Utils.IdOrNull(this.defaultRenderer), + GameLib.Utils.IdOrNull(this.parentEntity) ); return apiEntityManager; @@ -23977,11 +23410,8 @@ GameLib.Entity = function ( apiEntity.parentEntityManager ); - this.componentToCreate = 0; - GameLib.Component.call( this, - GameLib.Component.COMPONENT_ENTITY, { 'components' : [GameLib.Component], 'activeComponent' : GameLib.Component @@ -24303,54 +23733,37 @@ GameLib.GUIRuntime.prototype.isNotDatGuiThrow = function() { }; /** - * Stats component for displaying some render statistics (framerate, memory consumption, etc) + * GUI component * @param guiRuntime - * @param id - * @param name - * @param domElement - * @param objects - * @param parentEntity + * @param apiGUI * @constructor */ GameLib.GUI = function( guiRuntime, - id, - name, - domElement, - objects, - parentEntity + apiGUI ) { this.guiRuntime = guiRuntime; this.guiRuntime.isNotDatGuiThrow(); - if (GameLib.Utils.UndefinedOrNull(id)) { - id = GameLib.Utils.RandomId(); + if (GameLib.Utils.UndefinedOrNull(apiGUI)) { + apiGUI = {}; } - this.id = id; - if (GameLib.Utils.UndefinedOrNull(name)) { - name = 'GUI (' + id + ')'; + if (apiGUI instanceof GameLib.GUI) { + return apiGUI; } - this.name = name; - - if (GameLib.Utils.UndefinedOrNull(domElement)) { - domElement = null; - } - this.domElement = domElement; - - if (GameLib.Utils.UndefinedOrNull(objects)) { - objects = []; - } - this.objects = objects; - - if (GameLib.Utils.UndefinedOrNull(parentEntity)) { - parentEntity = null; - } - this.parentEntity = parentEntity; + GameLib.API.GUI.call( + this, + apiGUI.id, + apiGUI.name, + apiGUI.domElement, + apiGUI.objects, + apiGUI.parentEntity + ); + GameLib.Component.call( this, - GameLib.Component.COMPONENT_GUI, { 'domElement': GameLib.DomElement } @@ -24372,7 +23785,46 @@ GameLib.GUI.prototype.createInstance = function() { * Updates the instance with the current state */ GameLib.GUI.prototype.updateInstance = function(property) { - console.log('todo: implement gui update instance'); + console.log('todo: implement gui update instance:' + property); +}; + +/** + * Converts a GameLib.GUI to a new GameLib.API.GUI + * @returns {GameLib.API.GUI} + */ +GameLib.GUI.prototype.toApiObject = function() { + + return new GameLib.API.GUI( + this.id, + this.name, + GameLib.Utils.IdOrNull(this.domElement), + objects.map( + function(object){ + console.log('todo: check this' + object); + return GameLib.Utils.IdOrNull(object); + } + ), + GameLib.Utils.IdOrNull(this.parentEntity) + ); + +}; + +/** + * Converts from an Object GUI to a GameLib.GUI + * @param guiRuntime GameLib.GUIRuntime + * @param objectGUI Object + * @returns {GameLib.GUI} + * @constructor + */ +GameLib.GUI.FromObject = function(guiRuntime, objectGUI) { + + var apiGUI = GameLib.API.GUI.FromObject(objectGUI); + + return new GameLib.GUI( + guiRuntime, + apiGUI + ); + }; /** @@ -24408,6 +23860,114 @@ GameLib.GUI.prototype.addFolder = function(folderName) { } }; +/** + * Image + * @constructor + * @param apiImage + */ +GameLib.Image = function( + apiImage +) { + + if (GameLib.Utils.UndefinedOrNull(apiImage)) { + apiImage = {}; + } + + if (apiImage instanceof GameLib.Image) { + return apiImage; + } + + GameLib.API.Image.call( + this, + apiImage.id, + apiImage.name, + apiImage.fileName, + apiImage.extension, + apiImage.path, + apiImage.contentType, + apiImage.size, + apiImage.parentEntity + ); + + GameLib.Component.call(this); +}; + +GameLib.Image.prototype = Object.create(GameLib.API.Image.prototype); +GameLib.Image.prototype.constructor = GameLib.Image; + +/** + * Creates an image instance + * @returns {*} + */ +GameLib.Image.prototype.createInstance = function() { + + GameLib.Event.Emit( + GameLib.Event.LOAD_IMAGE, + { + image : this + }, + function(imageInstance) { + this.instance = imageInstance; + GameLib.Component.prototype.createInstance.call(this); + }.bind(this), + function(error) { + console.error(error); + this.instance = null; + GameLib.Component.prototype.createInstance.call(this); + }.bind(this) + ); + +}; + +/** + * Updates the instance with the current state + */ +GameLib.Image.prototype.updateInstance = function(property) { + + if (GameLib.Utils.UndefinedOrNull(property)) { + console.warn('unknown property update for Image: ' + property); + } + + if ( + property === 'fileName' || + property === 'extension' || + property === 'path' + ) { + this.createInstance(); + } +}; + +/** + * + * @returns {GameLib.API.Image} + */ +GameLib.Image.prototype.toApiObject = function() { + + var apiImage = new GameLib.API.Image( + this.id, + this.name, + this.fileName, + this.extension, + this.path, + this.contentType, + this.size, + GameLib.Utils.IdOrNull(this.parentEntity) + ); + + return apiImage; +}; + +/** + * @param objectImage + * @returns {GameLib.Image} + * @constructor + */ +GameLib.Image.FromObject = function(objectImage) { + return new GameLib.Image( + GameLib.API.Image.FromObject(objectImage) + ); +}; + /** * Runtime Matrix4 * @param graphics @@ -24752,10 +24312,7 @@ GameLib.Mouse = function (apiMouse) { apiMouse.parentEntity ); - GameLib.Component.call( - this, - GameLib.Component.COMPONENT_MOUSE - ); + GameLib.Component.call(this); }; GameLib.Mouse.prototype = Object.create(GameLib.API.Mouse.prototype); @@ -25145,9 +24702,116 @@ GameLib.StatisticsRuntime.prototype.isNotStatsThrow = function() { } }; +/** + * Stats component for displaying some render statistics (framerate, memory consumption, etc) + * @param statisticsRuntime + * @param apiStats + * @constructor + */ +GameLib.Stats = function( + statisticsRuntime, + apiStats +) { + this.stats = statisticsRuntime; + this.stats.isNotStatsThrow(); + + if (GameLib.Utils.UndefinedOrNull(apiStats)) { + apiStats = {}; + } + + if (apiStats instanceof GameLib.Stats) { + return apiStats; + } + + GameLib.API.Stats.call( + this, + apiStats.id, + apiStats.name, + apiStats.domElement, + apiStats.parentEntity + ); + + GameLib.Component.call( + this, + { + 'domElement': GameLib.DomElement + } + ); +}; + +GameLib.Stats.prototype = Object.create(GameLib.Component.prototype); +GameLib.Stats.prototype.constructor = GameLib.Stats; + +/** + * Creates a helper instance + */ +GameLib.Stats.prototype.createInstance = function() { + + this.instance = this.stats.instance(); + + this.resize(); + + this.domElement.instance.parentElement.appendChild(this.instance.dom); + + GameLib.Component.prototype.createInstance.call(this); +}; + +/** + * Updates the instance with the current state + */ +GameLib.Stats.prototype.updateInstance = function() { + this.instance = new this.stats(); +}; + + +/** + * Converts a GameLib.Stats to a new GameLib.API.Stats + * @returns {GameLib.API.Stats} + */ +GameLib.Stats.prototype.toApiObject = function() { + + return new GameLib.API.Stats( + this.id, + this.name, + GameLib.Utils.IdOrNull(this.domElement), + GameLib.Utils.IdOrNull(this.parentEntity) + ); + +}; + +/** + * Converts from an Object Stats to a GameLib.Stats + * @param statisticsRuntime GameLib.StatisticsRuntime + * @param objectStats Object + * @returns {GameLib.Stats} + * @constructor + */ +GameLib.Stats.FromObject = function(statisticsRuntime, objectStats) { + + var apiStats = GameLib.API.Stats.FromObject(objectStats); + + return new GameLib.Stats( + statisticsRuntime, + apiStats + ); + +}; + +GameLib.Stats.prototype.resize = function() { + console.log('override stats resize per implementation'); +}; + + +GameLib.Stats.prototype.start = function() { + this.instance.begin(); +}; + +GameLib.Stats.prototype.end = function() { + this.instance.end(); +}; + /** * System takes care of updating all the entities (based on their component data) - * @param implementation * @param apiSystem GameLib.API.System * @constructor */ @@ -25175,61 +24839,22 @@ GameLib.System = function( this.paused = false; - var componentType = GameLib.Component.COMPONENT_SYSTEM; var linkedObjects = {}; - if (apiSystem.systemType === GameLib.System.SYSTEM_TYPE_ANIMATION) { - componentType = GameLib.Component.COMPONENT_SYSTEM_ANIMATION; - } - - if (apiSystem.systemType === GameLib.System.SYSTEM_TYPE_CUSTOM) { - componentType = GameLib.Component.COMPONENT_SYSTEM_CUSTOM_CODE; - } - - if (apiSystem.systemType === GameLib.System.SYSTEM_TYPE_GUI) { - componentType = GameLib.Component.COMPONENT_SYSTEM_GUI; - } - if (apiSystem.systemType === GameLib.System.SYSTEM_TYPE_INPUT) { - componentType = GameLib.Component.COMPONENT_SYSTEM_INPUT; - linkedObjects.mouseControls = [GameLib.D3.Controls.Mouse]; - linkedObjects.keyboardControls = [GameLib.D3.Controls.Keyboard]; - linkedObjects.touchControls = [GameLib.D3.Controls.Touch]; - linkedObjects.editorControls = [GameLib.D3.Controls.Editor]; - } - - if (apiSystem.systemType === GameLib.System.SYSTEM_TYPE_LINKING) { - componentType = GameLib.Component.COMPONENT_SYSTEM_LINKING; - } - - if (apiSystem.systemType === GameLib.System.SYSTEM_TYPE_PHYSICS) { - componentType = GameLib.Component.COMPONENT_SYSTEM_PHYSICS; - } - - if (apiSystem.systemType === GameLib.System.SYSTEM_TYPE_RENDER) { - componentType = GameLib.Component.COMPONENT_SYSTEM_RENDER; - } - - if (apiSystem.systemType === GameLib.System.SYSTEM_TYPE_STORAGE) { - componentType = GameLib.Component.COMPONENT_SYSTEM_STORAGE; - } - - if (apiSystem.systemType === GameLib.System.SYSTEM_TYPE_VISUALIZATION) { - componentType = GameLib.Component.COMPONENT_SYSTEM_VISUALIZATION; - } - - if (apiSystem.systemType === GameLib.System.SYSTEM_TYPE_PARTICLE) { - componentType = GameLib.Component.COMPONENT_SYSTEM_PARTICLE; + linkedObjects.mouseControls = [GameLib.Controls.Mouse]; + linkedObjects.keyboardControls = [GameLib.Controls.Keyboard]; + linkedObjects.touchControls = [GameLib.Controls.Touch]; + linkedObjects.editorControls = [GameLib.Controls.D3.Editor]; } if (apiSystem.systemType === GameLib.System.SYSTEM_TYPE_AUDIO) { - componentType = GameLib.Component.COMPONENT_SYSTEM_AUDIO; - linkedObjects.audioComponents = [GameLib.D3.Audio]; + linkedObjects.audioComponents = [GameLib.D3.Audio]; } GameLib.Component.call( this, - componentType + linkedObjects ); }; @@ -25334,7 +24959,7 @@ GameLib.System.Animation.prototype.start = function() { this.beforeRender.bind(this) ); - var animations = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Animation); + var animations = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.ANIMATION); animations.map(function(animation){ animation.meshes.map( @@ -26410,7 +26035,7 @@ GameLib.System.Animation.prototype.stop = function() { this.animations = {}; - var meshes = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Mesh); + var meshes = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.MESH); meshes.map( function(mesh) { @@ -26762,7 +26387,7 @@ GameLib.System.CustomCode.prototype.start = function() { GameLib.System.prototype.start.call(this); - GameLib.EntityManager.Instance.queryComponents(GameLib.D3.CustomCode).map( + GameLib.EntityManager.Instance.queryComponents(GameLib.Component.CUSTOM_CODE).map( function(component) { this.subscriptions[component.id] = GameLib.Event.Subscribe( component.eventId, @@ -26795,7 +26420,7 @@ GameLib.System.CustomCode.prototype.start = function() { }; GameLib.System.CustomCode.prototype.instanceCreated = function(data) { - if (data.component instanceof GameLib.D3.CustomCode) { + if (data.component instanceof GameLib.CustomCode) { if (this.subscriptions[data.component.id]) { console.warn('a component already existed'); @@ -26810,7 +26435,7 @@ GameLib.System.CustomCode.prototype.instanceCreated = function(data) { }; GameLib.System.CustomCode.prototype.removeComponent = function(data) { - if (data.component instanceof GameLib.D3.CustomCode) { + if (data.component instanceof GameLib.CustomCode) { if (this.subscriptions[data.component.id]) { this.subscriptions[data.component.id].remove(); delete this.subscriptions[data.component.id]; @@ -26924,7 +26549,7 @@ GameLib.System.GUI.prototype.start = function() { GameLib.System.prototype.start.call(this); - this.guis = GameLib.EntityManager.Instance.queryComponents(GameLib.GUI); + this.guis = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.GUI); /** * Add some GUI behaviour @@ -27255,28 +26880,15 @@ GameLib.System.GUI.prototype.buildVectorControl = function(folder, componentTemp * Builds an Entity Selection control * @param folder * @param componentTemplate + * @param property */ GameLib.System.GUI.prototype.buildParentSelectionControl = function(folder, componentTemplate, property) { - var constructor = null; + var type = GameLib.Utils.UpperCaseUnderscore(property.replace('parent','')); - if (property === 'parentEntity') { - constructor = GameLib.Entity; - } - - if (property === 'parentMesh') { - constructor = GameLib.D3.Mesh; - } - - if (property === 'parentWorld') { - constructor = GameLib.D3.PhysicsWorld; - } - - if (property === 'parentScene') { - constructor = GameLib.D3.Scene; - } - - var options = GameLib.EntityManager.Instance.queryComponents(constructor).reduce( + var componentType = GameLib.Component[type]; + + var options = GameLib.EntityManager.Instance.queryComponents(componentType).reduce( function(result, object) { result[object.name] = object; return result; @@ -27316,7 +26928,7 @@ GameLib.System.GUI.prototype.buildParentSelectionControl = function(folder, comp ); } - if (property === 'parentWorld') { + if (property === 'parentPhysicsWorld') { GameLib.Event.Emit( GameLib.Event.PARENT_WORLD_CHANGE, { @@ -27690,8 +27302,8 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate, property, { 'naive': GameLib.D3.Broadphase.BROADPHASE_TYPE_NAIVE, - 'grid': GameLib.D3.Image.BROADPHASE_TYPE_GRID, - 'sap': GameLib.D3.Image.BROADPHASE_TYPE_SAP + 'grid': GameLib.D3.Broadphase.BROADPHASE_TYPE_GRID, + 'sap': GameLib.D3.Broadphase.BROADPHASE_TYPE_SAP } ) ); @@ -27701,8 +27313,8 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate, object, property, { - 'gs': GameLib.D3.Solver.GS_SOLVER, - 'split': GameLib.D3.Solver.SPLIT_SOLVER + 'gs': GameLib.D3.API.Solver.GS_SOLVER, + 'split': GameLib.D3.API.Solver.SPLIT_SOLVER } ) ); @@ -27712,14 +27324,14 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate, object, property, { - 'normal' : GameLib.D3.Mesh.MESH_TYPE_NORMAL, - 'curve' : GameLib.D3.Mesh.MESH_TYPE_CURVE, - 'skinned' : GameLib.D3.Mesh.MESH_TYPE_SKINNED, - 'plane' : GameLib.D3.Mesh.MESH_TYPE_PLANE, - 'sphere' : GameLib.D3.Mesh.MESH_TYPE_SPHERE, - 'box' : GameLib.D3.Mesh.MESH_TYPE_BOX, - 'cylinder' : GameLib.D3.Mesh.MESH_TYPE_CYLINDER, - 'text' : GameLib.D3.Mesh.MESH_TYPE_TEXT + 'normal' : GameLib.D3.API.Mesh.MESH_TYPE_NORMAL, + 'curve' : GameLib.D3.API.Mesh.MESH_TYPE_CURVE, + 'skinned' : GameLib.D3.API.Mesh.MESH_TYPE_SKINNED, + 'plane' : GameLib.D3.API.Mesh.MESH_TYPE_PLANE, + 'sphere' : GameLib.D3.API.Mesh.MESH_TYPE_SPHERE, + 'box' : GameLib.D3.API.Mesh.MESH_TYPE_BOX, + 'cylinder' : GameLib.D3.API.Mesh.MESH_TYPE_CYLINDER, + 'text' : GameLib.D3.API.Mesh.MESH_TYPE_TEXT } ) ); @@ -27877,9 +27489,9 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate, object, property, { - 'repeat': GameLib.D3.Texture.TYPE_REPEAT_WRAPPING, - 'clamp': GameLib.D3.Texture.TYPE_CLAMP_TO_EDGE_WRAPPING, - 'mirrored repeat': GameLib.D3.Texture.TYPE_MIRRORED_REPEAT_WRAPPING + 'repeat': GameLib.D3.API.Texture.TYPE_REPEAT_WRAPPING, + 'clamp': GameLib.D3.API.Texture.TYPE_CLAMP_TO_EDGE_WRAPPING, + 'mirrored repeat': GameLib.D3.API.Texture.TYPE_MIRRORED_REPEAT_WRAPPING } ) ); @@ -27889,9 +27501,9 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate, object, property, { - 'repeat': GameLib.D3.Texture.TYPE_REPEAT_WRAPPING, - 'clamp': GameLib.D3.Texture.TYPE_CLAMP_TO_EDGE_WRAPPING, - 'mirrored repeat': GameLib.D3.Texture.TYPE_MIRRORED_REPEAT_WRAPPING + 'repeat': GameLib.D3.API.Texture.TYPE_REPEAT_WRAPPING, + 'clamp': GameLib.D3.API.Texture.TYPE_CLAMP_TO_EDGE_WRAPPING, + 'mirrored repeat': GameLib.D3.API.Texture.TYPE_MIRRORED_REPEAT_WRAPPING } ) ); @@ -27901,12 +27513,12 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate, object, property, { - 'alpha': GameLib.D3.Texture.TYPE_ALPHA_FORMAT, - 'rgb': GameLib.D3.Texture.TYPE_RGB_FORMAT, - 'rgba': GameLib.D3.Texture.TYPE_RGBA_FORMAT, - 'luminance': GameLib.D3.Texture.TYPE_LUMINANCE_FORMAT, - 'luminance alpha': GameLib.D3.Texture.TYPE_LUMINANCE_ALPHA_FORMAT, - 'depth': GameLib.D3.Texture.TYPE_DEPTH_FORMAT + 'alpha': GameLib.D3.API.Texture.TYPE_ALPHA_FORMAT, + 'rgb': GameLib.D3.API.Texture.TYPE_RGB_FORMAT, + 'rgba': GameLib.D3.API.Texture.TYPE_RGBA_FORMAT, + 'luminance': GameLib.D3.API.Texture.TYPE_LUMINANCE_FORMAT, + 'luminance alpha': GameLib.D3.API.Texture.TYPE_LUMINANCE_ALPHA_FORMAT, + 'depth': GameLib.D3.API.Texture.TYPE_DEPTH_FORMAT } ) ); @@ -27916,14 +27528,14 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate, object, property, { - 'uv': GameLib.D3.Texture.TYPE_UV_MAPPING, - 'cube reflection': GameLib.D3.Texture.TYPE_CUBE_REFLECTION_MAPPING, - 'cube refraction': GameLib.D3.Texture.TYPE_CUBE_REFRACTION_MAPPING, - 'equi rectangular reflection': GameLib.D3.Texture.TYPE_EQUI_RECTANGULAR_REFLECTION_MAPPING, - 'equi rectangular refraction': GameLib.D3.Texture.TYPE_EQUI_RECTANGULAR_REFRACTION_MAPPING, - 'spherical reflection': GameLib.D3.Texture.TYPE_SPHERICAL_REFLECTION_MAPPING, - 'cube uv reflection': GameLib.D3.Texture.TYPE_CUBE_UV_REFLECTION_MAPPING, - 'cube uv refraction': GameLib.D3.Texture.TYPE_CUBE_UV_REFRACTION_MAPPING + 'uv': GameLib.D3.API.Texture.TYPE_UV_MAPPING, + 'cube reflection': GameLib.D3.API.Texture.TYPE_CUBE_REFLECTION_MAPPING, + 'cube refraction': GameLib.D3.API.Texture.TYPE_CUBE_REFRACTION_MAPPING, + 'equi rectangular reflection': GameLib.D3.API.Texture.TYPE_EQUI_RECTANGULAR_REFLECTION_MAPPING, + 'equi rectangular refraction': GameLib.D3.API.Texture.TYPE_EQUI_RECTANGULAR_REFRACTION_MAPPING, + 'spherical reflection': GameLib.D3.API.Texture.TYPE_SPHERICAL_REFLECTION_MAPPING, + 'cube uv reflection': GameLib.D3.API.Texture.TYPE_CUBE_UV_REFLECTION_MAPPING, + 'cube uv refraction': GameLib.D3.API.Texture.TYPE_CUBE_UV_REFRACTION_MAPPING } ) ); @@ -27933,12 +27545,12 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate, object, property, { - 'nearest': GameLib.D3.Texture.TYPE_NEAREST_FILTER, - 'nearest mipmap nearest': GameLib.D3.Texture.TYPE_NEAREST_MIPMAP_NEAREST_FILTER, - 'nearest mipmap linear': GameLib.D3.Texture.TYPE_NEAREST_MIPMAP_LINEAR_FILTER, - 'linear': GameLib.D3.Texture.TYPE_LINEAR_FILTER, - 'linear mipmap nearest': GameLib.D3.Texture.TYPE_LINEAR_MIPMAP_NEAREST_FILTER, - 'linear mipmap linear': GameLib.D3.Texture.TYPE_LINEAR_MIPMAP_LINEAR_FILTER + 'nearest': GameLib.D3.API.Texture.TYPE_NEAREST_FILTER, + 'nearest mipmap nearest': GameLib.D3.API.Texture.TYPE_NEAREST_MIPMAP_NEAREST_FILTER, + 'nearest mipmap linear': GameLib.D3.API.Texture.TYPE_NEAREST_MIPMAP_LINEAR_FILTER, + 'linear': GameLib.D3.API.Texture.TYPE_LINEAR_FILTER, + 'linear mipmap nearest': GameLib.D3.API.Texture.TYPE_LINEAR_MIPMAP_NEAREST_FILTER, + 'linear mipmap linear': GameLib.D3.API.Texture.TYPE_LINEAR_MIPMAP_LINEAR_FILTER } ) ); @@ -27948,24 +27560,24 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate, object, property, { - 'nearest': GameLib.D3.Texture.TYPE_NEAREST_FILTER, - 'nearest mipmap nearest': GameLib.D3.Texture.TYPE_NEAREST_MIPMAP_NEAREST_FILTER, - 'nearest mipmap linear': GameLib.D3.Texture.TYPE_NEAREST_MIPMAP_LINEAR_FILTER, - 'linear': GameLib.D3.Texture.TYPE_LINEAR_FILTER, - 'linear mipmap nearest': GameLib.D3.Texture.TYPE_LINEAR_MIPMAP_NEAREST_FILTER, - 'linear mipmap linear': GameLib.D3.Texture.TYPE_LINEAR_MIPMAP_LINEAR_FILTER + 'nearest': GameLib.D3.API.Texture.TYPE_NEAREST_FILTER, + 'nearest mipmap nearest': GameLib.D3.API.Texture.TYPE_NEAREST_MIPMAP_NEAREST_FILTER, + 'nearest mipmap linear': GameLib.D3.API.Texture.TYPE_NEAREST_MIPMAP_LINEAR_FILTER, + 'linear': GameLib.D3.API.Texture.TYPE_LINEAR_FILTER, + 'linear mipmap nearest': GameLib.D3.API.Texture.TYPE_LINEAR_MIPMAP_NEAREST_FILTER, + 'linear mipmap linear': GameLib.D3.API.Texture.TYPE_LINEAR_MIPMAP_LINEAR_FILTER } ) ); - } else if (componentType === GameLib.Component.COMPONENT_TEXTURE && property === 'typeId') { + } else if (componentType === GameLib.Component.TEXTURE && property === 'textureType') { controllers.push( folder.add( object, property, { - 'normal': GameLib.D3.Texture.TEXTURE_TYPE_NORMAL, - 'cube': GameLib.D3.Texture.TEXTURE_TYPE_CUBE, - 'canvas': GameLib.D3.Texture.TEXTURE_TYPE_CANVAS + 'normal': GameLib.D3.API.Texture.TEXTURE_TYPE_NORMAL, + 'cube': GameLib.D3.API.Texture.TEXTURE_TYPE_CUBE, + 'canvas': GameLib.D3.API.Texture.TEXTURE_TYPE_CANVAS } ) ); @@ -27975,14 +27587,14 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate, object, property, { - 'unsigned byte': GameLib.D3.Texture.TYPE_UNSIGNED_BYTE, - 'byte': GameLib.D3.Texture.TYPE_BYTE, - 'short': GameLib.D3.Texture.TYPE_SHORT, - 'unsigned short': GameLib.D3.Texture.TYPE_UNSIGNED_SHORT, - 'int': GameLib.D3.Texture.TYPE_INT, - 'unsigned int': GameLib.D3.Texture.TYPE_UNSIGNED_INT, - 'float': GameLib.D3.Texture.TYPE_FLOAT, - 'half float': GameLib.D3.Texture.TYPE_HALF_FLOAT + 'unsigned byte': GameLib.D3.API.Texture.TYPE_UNSIGNED_BYTE, + 'byte': GameLib.D3.API.Texture.TYPE_BYTE, + 'short': GameLib.D3.API.Texture.TYPE_SHORT, + 'unsigned short': GameLib.D3.API.Texture.TYPE_UNSIGNED_SHORT, + 'int': GameLib.D3.API.Texture.TYPE_INT, + 'unsigned int': GameLib.D3.API.Texture.TYPE_UNSIGNED_INT, + 'float': GameLib.D3.API.Texture.TYPE_FLOAT, + 'half float': GameLib.D3.API.Texture.TYPE_HALF_FLOAT } ) ); @@ -27992,14 +27604,14 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate, object, property, { - 'linear': GameLib.D3.Texture.TYPE_LINEAR_ENCODING, - 'srgb': GameLib.D3.Texture.TYPE_SRGB_ENCODING, - 'gamma': GameLib.D3.Texture.TYPE_GAMMA_ENCODING, - 'rgbe': GameLib.D3.Texture.TYPE_RGBE_ENCODING, - 'log luv': GameLib.D3.Texture.TYPE_LOG_LUV_ENCODING, - 'rgbm7': GameLib.D3.Texture.TYPE_RGBM7_ENCODING, - 'rgbm16': GameLib.D3.Texture.TYPE_RGBM16_ENCODING, - 'rgbd': GameLib.D3.Texture.TYPE_RGBD_ENCODING + 'linear': GameLib.D3.API.Texture.TYPE_LINEAR_ENCODING, + 'srgb': GameLib.D3.API.Texture.TYPE_SRGB_ENCODING, + 'gamma': GameLib.D3.API.Texture.TYPE_GAMMA_ENCODING, + 'rgbe': GameLib.D3.API.Texture.TYPE_RGBE_ENCODING, + 'log luv': GameLib.D3.API.Texture.TYPE_LOG_LUV_ENCODING, + 'rgbm7': GameLib.D3.API.Texture.TYPE_RGBM7_ENCODING, + 'rgbm16': GameLib.D3.API.Texture.TYPE_RGBM16_ENCODING, + 'rgbd': GameLib.D3.API.Texture.TYPE_RGBD_ENCODING } ) ); @@ -28592,7 +28204,7 @@ GameLib.System.GUI.prototype.buildGUI = function(data) { if ( templateProperty === 'parentEntity' || - templateProperty === 'parentWorld' || + templateProperty === 'parentPhysicsWorld' || templateProperty === 'parentMesh' || templateProperty === 'parentScene' ) { @@ -28820,13 +28432,13 @@ GameLib.System.Input.prototype.start = function() { GameLib.System.prototype.start.call(this); - this.editorControls = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Controls.Editor); + this.editorControls = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.CONTROLS_EDITOR); - this.touchControls = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Controls.Touch); + this.touchControls = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.CONTROLS_TOUCH); - this.keyboardControls = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Controls.Keyboard); + this.keyboardControls = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.CONTROLS_KEYBOARD); - this.mouseControls = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Controls.Mouse); + this.mouseControls = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.CONTROLS_MOUSE); this.instanceCreatedSubscription = GameLib.Event.Subscribe( GameLib.Event.INSTANCE_CREATED, @@ -28893,7 +28505,7 @@ GameLib.System.Input.prototype.stop = function() { */ GameLib.System.Input.prototype.instanceCreated = function(data) { - if (data.component instanceof GameLib.D3.Controls.Editor) { + if (data.component instanceof GameLib.Controls.D3.Editor) { if (this.editorControls.length > 0) { console.log('ignoring multiple editor controls') } else { @@ -28902,7 +28514,7 @@ GameLib.System.Input.prototype.instanceCreated = function(data) { } } - if (data.component instanceof GameLib.D3.Controls.Touch) { + if (data.component instanceof GameLib.Controls.Touch) { if (this.touchControls.length > 0) { console.log('ignoring multiple touch controls') } else { @@ -28911,7 +28523,7 @@ GameLib.System.Input.prototype.instanceCreated = function(data) { } } - if (data.component instanceof GameLib.D3.Controls.Keyboard) { + if (data.component instanceof GameLib.Controls.Keyboard) { if (this.keyboardControls.length > 0) { console.log('ignoring multiple keyboard controls') } else { @@ -28920,7 +28532,7 @@ GameLib.System.Input.prototype.instanceCreated = function(data) { } } - if (data.component instanceof GameLib.D3.Controls.Mouse) { + if (data.component instanceof GameLib.Controls.Mouse) { if (this.mouseControls.length > 0) { console.log('ignoring multiple mouse controls') } else { @@ -28937,7 +28549,7 @@ GameLib.System.Input.prototype.instanceCreated = function(data) { */ GameLib.System.Input.prototype.removeComponent = function(data) { - if (data.component instanceof GameLib.D3.Controls.Editor) { + if (data.component instanceof GameLib.Controls.D3.Editor) { var index = this.editorControls.indexOf(data.component); @@ -28963,7 +28575,7 @@ GameLib.System.Input.prototype.removeComponent = function(data) { */ GameLib.System.Input.prototype.delayedInstanceEncountered = function(data) { - if (data.component instanceof GameLib.D3.Controls.Editor) { + if (data.component instanceof GameLib.Controls.D3.Editor) { if (this.editorControls.length === 0) { /** @@ -29501,7 +29113,7 @@ GameLib.System.Input.prototype.onKeyDown = function(event) { if (event.code === 'Delete') { - meshes = GameLib.EntityManager.Instance.queryComponents([GameLib.D3.Mesh]); + meshes = GameLib.EntityManager.Instance.queryComponents([GameLib.Component.MESH]); var deletedMeshes = []; @@ -29537,7 +29149,7 @@ GameLib.System.Input.prototype.onKeyDown = function(event) { this.selectAll = !this.selectAll; - meshes = GameLib.EntityManager.Instance.queryComponents([GameLib.D3.Mesh]); + meshes = GameLib.EntityManager.Instance.queryComponents([GameLib.Component.MESH]); meshes.map(function(mesh){ if (this.selectAll) { @@ -29629,7 +29241,7 @@ GameLib.System.Input.prototype.onMouseDownEdit = function(event) { this.mouse.position.x = (event.offsetX / event.target.width ) * 2 - 1; this.mouse.position.y = -(event.offsetY / event.target.height) * 2 + 1; - var scenes = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Scene); + var scenes = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.SCENE); var intersects = scenes.reduce( @@ -29864,7 +29476,7 @@ GameLib.System.Input.prototype.deSelectMesh = function(mesh) { // event.stopPropagation(); // } // -// var meshes = entity.queryComponents(GameLib.D3.Mesh); +// var meshes = entity.queryComponents(GameLib.Component.MESH); // // var intersects = this.raycaster.getIntersectedObjects(meshes); // @@ -30037,7 +29649,7 @@ GameLib.System.Linking = function( * Parents */ this.parentSceneChangeSubscription = null; - this.parentWorldChangeSubscription = null; + this.parentPhysicsWorldChangeSubscription = null; this.parentEntityChangeSubscription = null; /** @@ -30105,7 +29717,7 @@ GameLib.System.Linking.prototype.start = function() { this.onParentSceneChange ); - this.parentWorldChangeSubscription = this.subscribe( + this.parentPhysicsWorldChangeSubscription = this.subscribe( GameLib.Event.PARENT_WORLD_CHANGE, this.onParentWorldChange ); @@ -30535,7 +30147,7 @@ GameLib.System.Linking.prototype.removeComponent = function(data) { GameLib.System.Linking.prototype.imageChanged = function(data) { - var materials = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Material); + var materials = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.MATERIAL); materials.map(function(material){ @@ -30582,11 +30194,11 @@ GameLib.System.Linking.prototype.instanceCreated = function(data) { this.resolveDependencies(data.component); - if (data.component instanceof GameLib.D3.Image) { + if (data.component instanceof GameLib.Image) { /** * Find all textures which use this image */ - GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Texture).map( + GameLib.EntityManager.Instance.queryComponents(GameLib.Component.TEXTURE).map( function(texture) { if (texture.image === data.component || texture.images.indexOf(data.component) !== -1 @@ -30621,7 +30233,7 @@ GameLib.System.Linking.prototype.instanceCreated = function(data) { data.component.parentScene && typeof data.component.parentScene === 'string' ) { - GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Scene).map( + GameLib.EntityManager.Instance.queryComponents(GameLib.Component.SCENE).map( function (scene) { if (data.component.parentScene === scene.id) { data.component.parentScene = scene; @@ -30635,7 +30247,7 @@ GameLib.System.Linking.prototype.instanceCreated = function(data) { data.component.parentEngine && typeof data.component.parentEngine === 'string' ) { - GameLib.EntityManager.Instance.queryComponents(GameLib.D3.ParticleEngine).map( + GameLib.EntityManager.Instance.queryComponents(GameLib.Component.PARTICLE_ENGINE).map( function (particleEngine) { if (data.component.parentEngine === particleEngine.id) { data.component.parentEngine = particleEngine; @@ -30681,7 +30293,7 @@ GameLib.System.Linking.prototype.instanceCreated = function(data) { data.component.parentMesh && typeof data.component.parentMesh === 'string' ) { - GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Mesh).map( + GameLib.EntityManager.Instance.queryComponents(GameLib.Component.MESH).map( function (mesh) { if (data.component.parentMesh === mesh.id) { @@ -30696,13 +30308,13 @@ GameLib.System.Linking.prototype.instanceCreated = function(data) { } if ( - data.component.parentWorld && - typeof data.component.parentWorld === 'string' + data.component.parentPhysicsWorld && + typeof data.component.parentPhysicsWorld === 'string' ) { - GameLib.EntityManager.Instance.queryComponents(GameLib.D3.PhysicsWorld).map( + GameLib.EntityManager.Instance.queryComponents(GameLib.Component.PHYSICS_WORLD).map( function (world) { - if (data.component.parentWorld === world.id) { - data.component.parentWorld = world; + if (data.component.parentPhysicsWorld === world.id) { + data.component.parentPhysicsWorld = world; if (typeof data.component.instance.addToWorld === 'function') { data.component.instance.addToWorld(world.instance); @@ -30717,7 +30329,7 @@ GameLib.System.Linking.prototype.instanceCreated = function(data) { GameLib.System.Linking.prototype.materialTypeChanged = function(data) { - var meshes = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Mesh); + var meshes = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.MESH); meshes.map( function(mesh){ @@ -30864,7 +30476,7 @@ GameLib.System.Linking.prototype.removeMesh = function(data) { /** * Now, we want to get a list of all the meshes which we don't want to delete, and all their children */ - var meshes = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Mesh); + var meshes = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.MESH); meshes = meshes.filter(function(mesh){ return data.meshes.indexOf(mesh) === -1; }); @@ -30921,7 +30533,7 @@ GameLib.System.Linking.prototype.stop = function() { * Parents */ this.parentSceneChangeSubscription.remove(); - this.parentWorldChangeSubscription.remove(); + this.parentPhysicsWorldChangeSubscription.remove(); this.parentEntityChangeSubscription.remove(); /** @@ -30991,7 +30603,7 @@ GameLib.System.Particle.prototype.start = function() { GameLib.System.prototype.start.call(this); - this.particleEngines = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.ParticleEngine); + this.particleEngines = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.PARTICLE_ENGINE); this.instanceCreatedSubscription = GameLib.Event.Subscribe( GameLib.Event.INSTANCE_CREATED, @@ -31252,10 +30864,10 @@ GameLib.System.Physics.prototype.start = function() { GameLib.System.prototype.start.call(this); - this.worlds = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.PhysicsWorld); - // this.rigidBodies = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.RigidBody); - // this.wheels = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.RaycastWheel); - // this.vehicles = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.RaycastVehicle); + this.worlds = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.PHYSICS_WORLD); + // this.rigidBodies = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.RIGID_BODY); + // this.wheels = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.RAYCAST_WHEEL); + // this.vehicles = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.RAYCAST_VEHICLE); @@ -31396,9 +31008,9 @@ GameLib.System.Render.prototype.start = function() { GameLib.System.prototype.start.call(this); - this.renderers = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Renderer); + this.renderers = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.RENDERER); - this.statistics = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Stats); + this.statistics = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.STATS); this.instanceCreatedSubscription = GameLib.Event.Subscribe( GameLib.Event.INSTANCE_CREATED, @@ -31428,7 +31040,7 @@ GameLib.System.Render.prototype.instanceCreated = function(data) { this.renderers.push(data.component); } - if (data.component instanceof GameLib.D3.Stats) { + if (data.component instanceof GameLib.Stats) { console.log('new stats'); this.statistics.push(data.component); } @@ -31956,7 +31568,7 @@ GameLib.System.Storage.prototype.loadComponent = function(apiUrl, toProcess, inc runtimeComponent.parentEntity && typeof runtimeComponent.parentEntity === 'string' ) { - GameLib.EntityManager.Instance.queryComponents(GameLib.Entity).map( + GameLib.EntityManager.Instance.queryComponents(GameLib.Component.ENTITY).map( function (entity) { if (runtimeComponent.parentEntity === entity.id) { runtimeComponent.parentEntity = entity; @@ -32269,7 +31881,7 @@ GameLib.System.Storage.prototype.fetchComponents = function(data, clientCallback */ GameLib.System.Storage.prototype.imageUploadComplete = function(data) { - var runtimeImages = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Image); + var runtimeImages = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.IMAGE); /** * Process all images - we have to load them in addition to creating their runtime components @@ -32414,7 +32026,7 @@ GameLib.System.Storage.prototype.loadFont = function(data, callback, errorCallba }; -GameLib.System.Storage.prototype.loadImage = function(data) { +GameLib.System.Storage.prototype.loadImage = function(data, callback, errorCallback) { console.log('loading image : ' + data.image.name); @@ -32468,9 +32080,12 @@ GameLib.System.Storage.prototype.loadImage = function(data) { objectUrl = true; } } catch (error) { - /** - * Do Nothing - */ + if (errorCallback) { + errorCallback({ + result: 'failure', + message: 'invalid server response trying to download image ' + data.image.name + }); + } } var img = document.createElement('img'); @@ -32481,9 +32096,9 @@ GameLib.System.Storage.prototype.loadImage = function(data) { window.URL.revokeObjectURL(url); } - image.instance = img; - - image.createInstance(); + if (callback) { + callback(img); + } if (onLoaded) { onLoaded(image, data.createTexture); @@ -32510,6 +32125,11 @@ GameLib.System.Storage.prototype.loadImage = function(data) { xhr.onerror = function(error) { console.warn('image load failed for image ' + image.name); + + if (errorCallback) { + errorCallback(error); + } + if (onError) { onError(image, error) } @@ -32520,6 +32140,11 @@ GameLib.System.Storage.prototype.loadImage = function(data) { preflight.onerror = function(error) { console.warn('image pre-flight request failed for image ' + image.name); + + if (errorCallback) { + errorCallback(error); + } + if (onError) { onError(image, error); } diff --git a/src/game-lib-a-2-utils.js b/src/game-lib-a-2-utils.js index 60628ec..75fe1fa 100644 --- a/src/game-lib-a-2-utils.js +++ b/src/game-lib-a-2-utils.js @@ -727,4 +727,19 @@ GameLib.Utils.UpperCaseWordsSpaces = function(word) { }, '' ).trim(); +}; + +GameLib.Utils.UpperCaseUnderscore = function(word) { + + var str = ''; + + word.map(function(letter){ + if (letter === letter.toUpperCase()) { + str += '_' + letter; + } else { + str += letter.toUpperCase(); + } + }); + + return str; }; \ No newline at end of file diff --git a/src/game-lib-a-api-component.js b/src/game-lib-a-api-component.js index 92f5eb8..97a047f 100644 --- a/src/game-lib-a-api-component.js +++ b/src/game-lib-a-api-component.js @@ -9,12 +9,11 @@ GameLib.API.Component = function( parentEntity ) { this.componentType = componentType; - + if (GameLib.Utils.UndefinedOrNull(parentEntity)) { parentEntity = null; } this.parentEntity = parentEntity; - }; GameLib.API.Component.prototype = Object.create(GameLib.Event.prototype); diff --git a/src/game-lib-a-component-a.js b/src/game-lib-a-component-a.js index 796dbd3..7cccf41 100644 --- a/src/game-lib-a-component-a.js +++ b/src/game-lib-a-component-a.js @@ -1,12 +1,10 @@ /** * Component Interface * @constructor - * @param componentType * @param linkedObjects * @param delayed */ GameLib.Component = function( - componentType, linkedObjects, delayed ) { @@ -16,12 +14,6 @@ GameLib.Component = function( this.linkedObjects = linkedObjects; this.linkedObjects.parentEntity = GameLib.Entity; - GameLib.API.Component.call( - this, - componentType, - this.parentEntity - ); - this.idToObject = {}; this.selected = false; @@ -212,87 +204,87 @@ GameLib.Component.prototype.toString = function() { return this.id; }; -//GameLib.Component.COMPONENT_PATH_FOLLOWING = 0x1; -GameLib.Component.COMPONENT_MATERIAL = 0x2; -GameLib.Component.COMPONENT_RENDERER = 0x3; -//GameLib.Component.COMPONENT_LOOK_AT = 0x4; -GameLib.Component.COMPONENT_CAMERA = 0x5; -//GameLib.Component.COMPONENT_FOLLOW = 0x6; -GameLib.Component.COMPONENT_MESH = 0x7; -GameLib.Component.COMPONENT_SPLINE = 0x8; -GameLib.Component.COMPONENT_LIGHT = 0x9; -//GameLib.Component.COMPONENT_INPUT_DRIVE = 0xa; -GameLib.Component.COMPONENT_COMPOSER = 0xb; -GameLib.Component.COMPONENT_RENDER_TARGET = 0xc; -GameLib.Component.COMPONENT_PASS = 0xd; -GameLib.Component.COMPONENT_SCENE = 0xe; -GameLib.Component.COMPONENT_RAYCASTER = 0xf; -//GameLib.Component.COMPONENT_INPUT_EDITOR = 0x10; -//GameLib.Component.COMPONENT_EDITOR = 0x11; -GameLib.Component.COMPONENT_VIEWPORT = 0x12; -GameLib.Component.COMPONENT_SYSTEM = 0x13; -GameLib.Component.COMPONENT_GRAPHICS = 0x14; -GameLib.Component.COMPONENT_HELPER = 0x15; -GameLib.Component.COMPONENT_CUSTOM_CODE = 0x16; -GameLib.Component.COMPONENT_MOUSE = 0x17; -GameLib.Component.COMPONENT_SKELETON = 0x18; -GameLib.Component.COMPONENT_TEXTURE = 0x19; -GameLib.Component.COMPONENT_ENTITY_MANAGER = 0x1a; -GameLib.Component.COMPONENT_DOM_ELEMENT = 0x1b; -//GameLib.Component.COMPONENT_IMAGE_FACTORY = 0x1c; -GameLib.Component.COMPONENT_STATS = 0x1d; -GameLib.Component.COMPONENT_GUI = 0x1e; -GameLib.Component.COMPONENT_IMAGE = 0x1f; -GameLib.Component.COMPONENT_ENTITY = 0x20; -GameLib.Component.COMPONENT_MESH_SPHERE = 0x21; -GameLib.Component.COMPONENT_MESH_PLANE = 0x22; -GameLib.Component.COMPONENT_MESH_CURVE = 0x23; -GameLib.Component.COMPONENT_PHYSICS_WORLD = 0x24; -GameLib.Component.COMPONENT_BROADPHASE = 0x25; -GameLib.Component.COMPONENT_SOLVER = 0x26; -GameLib.Component.COMPONENT_RIGID_BODY = 0x27; -GameLib.Component.COMPONENT_SHAPE = 0x28; -GameLib.Component.COMPONENT_SHAPE_BOX = 0x29; -GameLib.Component.COMPONENT_SHAPE_SPHERE = 0x2a; -GameLib.Component.COMPONENT_SHAPE_TRI_MESH = 0x2b; -GameLib.Component.COMPONENT_SHAPE_CONVEX_HULL = 0x2c; -GameLib.Component.COMPONENT_SHAPE_CONVEX_HULL_CYLINDER = 0x2d; -GameLib.Component.COMPONENT_SHAPE_HEIGHT_MAP = 0x2e; -GameLib.Component.COMPONENT_SHAPE_PLANE = 0x2f; -GameLib.Component.COMPONENT_CONTROLS = 0x30; -GameLib.Component.COMPONENT_CONTROLS_EDITOR = 0x31; -GameLib.Component.COMPONENT_CONTROLS_TOUCH = 0x32; -GameLib.Component.COMPONENT_FRICTION_MATERIAL = 0x33; -GameLib.Component.COMPONENT_FRICTION_CONTACT_MATERIAL = 0x34; -GameLib.Component.COMPONENT_RAYCAST_VEHICLE = 0x35; -GameLib.Component.COMPONENT_RAYCAST_WHEEL = 0x36; -GameLib.Component.COMPONENT_CLOCK = 0x37; -GameLib.Component.COMPONENT_ANIMATION = 0x38; -GameLib.Component.COMPONENT_CONTROLS_KEYBOARD = 0x39; -GameLib.Component.COMPONENT_CONTROLS_MOUSE = 0x3a; -GameLib.Component.COMPONENT_MESH_TEXT = 0x3b; -GameLib.Component.COMPONENT_FONT = 0x3c; -GameLib.Component.COMPONENT_CANVAS = 0x3d; -GameLib.Component.COMPONENT_BONE = 0x3e; -GameLib.Component.COMPONENT_MESH_BOX = 0x3f; -GameLib.Component.COMPONENT_MESH_CYLINDER = 0x40; -GameLib.Component.COMPONENT_SYSTEM_ANIMATION = 0x41; -GameLib.Component.COMPONENT_SYSTEM_CUSTOM_CODE = 0x42; -GameLib.Component.COMPONENT_SYSTEM_GUI = 0x43; -GameLib.Component.COMPONENT_SYSTEM_INPUT = 0x44; -GameLib.Component.COMPONENT_SYSTEM_LINKING = 0x45; -GameLib.Component.COMPONENT_SYSTEM_PHYSICS = 0x46; -GameLib.Component.COMPONENT_SYSTEM_RENDER = 0x47; -GameLib.Component.COMPONENT_SYSTEM_STORAGE = 0x48; -GameLib.Component.COMPONENT_SYSTEM_VISUALIZATION = 0x49; -GameLib.Component.COMPONENT_FOG = 0x50; -GameLib.Component.COMPONENT_MESH_LINE = 0x51; -GameLib.Component.COMPONENT_PARTICLE_ENGINE = 0x52; -GameLib.Component.COMPONENT_SYSTEM_PARTICLE = 0x53; -GameLib.Component.COMPONENT_PARTICLE = 0x54; -GameLib.Component.COMPONENT_AUDIO = 0x55; -GameLib.Component.COMPONENT_SYSTEM_AUDIO = 0x56; -GameLib.Component.COMPONENT_CAST = 0x57; +//GameLib.Component.PATH_FOLLOWING = 0x1; +GameLib.Component.MATERIAL = 0x2; +GameLib.Component.RENDERER = 0x3; +//GameLib.Component.LOOK_AT = 0x4; +GameLib.Component.CAMERA = 0x5; +//GameLib.Component.FOLLOW = 0x6; +GameLib.Component.MESH = 0x7; +GameLib.Component.SPLINE = 0x8; +GameLib.Component.LIGHT = 0x9; +//GameLib.Component.INPUT_DRIVE = 0xa; +GameLib.Component.COMPOSER = 0xb; +GameLib.Component.RENDER_TARGET = 0xc; +GameLib.Component.PASS = 0xd; +GameLib.Component.SCENE = 0xe; +GameLib.Component.RAYCASTER = 0xf; +//GameLib.Component.INPUT_EDITOR = 0x10; +//GameLib.Component.EDITOR = 0x11; +GameLib.Component.VIEWPORT = 0x12; +GameLib.Component.SYSTEM = 0x13; +GameLib.Component.GRAPHICS = 0x14; +GameLib.Component.HELPER = 0x15; +GameLib.Component.CUSTOM_CODE = 0x16; +GameLib.Component.MOUSE = 0x17; +GameLib.Component.SKELETON = 0x18; +GameLib.Component.TEXTURE = 0x19; +GameLib.Component.ENTITY_MANAGER = 0x1a; +GameLib.Component.DOM_ELEMENT = 0x1b; +//GameLib.Component.IMAGE_FACTORY = 0x1c; +GameLib.Component.STATS = 0x1d; +GameLib.Component.GUI = 0x1e; +GameLib.Component.IMAGE = 0x1f; +GameLib.Component.ENTITY = 0x20; +GameLib.Component.MESH_SPHERE = 0x21; +GameLib.Component.MESH_PLANE = 0x22; +GameLib.Component.MESH_CURVE = 0x23; +GameLib.Component.PHYSICS_WORLD = 0x24; +GameLib.Component.BROADPHASE = 0x25; +GameLib.Component.SOLVER = 0x26; +GameLib.Component.RIGID_BODY = 0x27; +GameLib.Component.SHAPE = 0x28; +GameLib.Component.SHAPE_BOX = 0x29; +GameLib.Component.SHAPE_SPHERE = 0x2a; +GameLib.Component.SHAPE_TRI_MESH = 0x2b; +GameLib.Component.SHAPE_CONVEX_HULL = 0x2c; +GameLib.Component.SHAPE_CONVEX_HULL_CYLINDER = 0x2d; +GameLib.Component.SHAPE_HEIGHT_MAP = 0x2e; +GameLib.Component.SHAPE_PLANE = 0x2f; +GameLib.Component.CONTROLS = 0x30; +GameLib.Component.CONTROLS_EDITOR = 0x31; +GameLib.Component.CONTROLS_TOUCH = 0x32; +GameLib.Component.FRICTION_MATERIAL = 0x33; +GameLib.Component.FRICTION_CONTACT_MATERIAL = 0x34; +GameLib.Component.RAYCAST_VEHICLE = 0x35; +GameLib.Component.RAYCAST_WHEEL = 0x36; +GameLib.Component.CLOCK = 0x37; +GameLib.Component.ANIMATION = 0x38; +GameLib.Component.CONTROLS_KEYBOARD = 0x39; +GameLib.Component.CONTROLS_MOUSE = 0x3a; +GameLib.Component.MESH_TEXT = 0x3b; +GameLib.Component.FONT = 0x3c; +GameLib.Component.CANVAS = 0x3d; +GameLib.Component.BONE = 0x3e; +GameLib.Component.MESH_BOX = 0x3f; +GameLib.Component.MESH_CYLINDER = 0x40; +GameLib.Component.SYSTEM_ANIMATION = 0x41; +GameLib.Component.SYSTEM_CUSTOM_CODE = 0x42; +GameLib.Component.SYSTEM_GUI = 0x43; +GameLib.Component.SYSTEM_INPUT = 0x44; +GameLib.Component.SYSTEM_LINKING = 0x45; +GameLib.Component.SYSTEM_PHYSICS = 0x46; +GameLib.Component.SYSTEM_RENDER = 0x47; +GameLib.Component.SYSTEM_STORAGE = 0x48; +GameLib.Component.SYSTEM_VISUALIZATION = 0x49; +GameLib.Component.FOG = 0x50; +GameLib.Component.MESH_LINE = 0x51; +GameLib.Component.PARTICLE_ENGINE = 0x52; +GameLib.Component.SYSTEM_PARTICLE = 0x53; +GameLib.Component.PARTICLE = 0x54; +GameLib.Component.AUDIO = 0x55; +GameLib.Component.SYSTEM_AUDIO = 0x56; +GameLib.Component.CAST = 0x57; GameLib.Component.GRAPHICS_RUNTIME = 0x1; GameLib.Component.PHYSICS_RUNTIME = 0x2; @@ -302,6 +294,10 @@ GameLib.Component.DEFAULT_RUNTIME = 0x5; GameLib.Component.GUI_RUNTIME = 0x6; GameLib.Component.CODER_RUNTIME = 0x7; +GameLib.Component.GetCompentType = function(constructor) { + console.log('todo: implement?'); +}; + /** * Returns string name for component number * @param number @@ -313,305 +309,379 @@ GameLib.Component.GetComponentInfo = function(number) { case 0x1 : return null; case 0x2 : return { name : 'GameLib.D3.Material', - runtime : GameLib.Component.GRAPHICS_RUNTIME + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.Material }; case 0x3 : return { name : 'GameLib.D3.Renderer', - runtime : GameLib.Component.GRAPHICS_RUNTIME + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.Renderer }; case 0x4 : return null; case 0x5 : return { name : 'GameLib.D3.Camera', - runtime : GameLib.Component.GRAPHICS_RUNTIME + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.Camera }; case 0x6 : return null; case 0x7 : return { name : 'GameLib.D3.Mesh', - runtime : GameLib.Component.GRAPHICS_RUNTIME + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.Mesh }; case 0x8 : return { name : 'GameLib.D3.Spline', - runtime : GameLib.Component.GRAPHICS_RUNTIME + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.Spline }; case 0x9 : return { name : 'GameLib.D3.Light', - runtime : GameLib.Component.GRAPHICS_RUNTIME + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.Light }; case 0xa : return null; case 0xb : return { name : 'GameLib.D3.Composer', - runtime : GameLib.Component.GRAPHICS_RUNTIME + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.Composer }; case 0xc : return { name : 'GameLib.D3.RenderTarget', - runtime : GameLib.Component.GRAPHICS_RUNTIME + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.RenderTarget }; case 0xd : return { name : 'GameLib.D3.Pass', - runtime : GameLib.Component.GRAPHICS_RUNTIME + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.Pass }; case 0xe : return { name : 'GameLib.D3.Scene', - runtime : GameLib.Component.GRAPHICS_RUNTIME + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.Scene }; case 0xf : return { name : 'GameLib.D3.Raycaster', - runtime : GameLib.Component.GRAPHICS_RUNTIME + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.Raycaster }; case 0x10 : return null; case 0x11 : return null; case 0x12 : return { name : 'GameLib.D3.Viewport', - runtime : GameLib.Component.GRAPHICS_RUNTIME + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.Viewport }; case 0x13 : return { name : 'GameLib.System', - runtime : GameLib.Component.DEFAULT_RUNTIME + runtime : GameLib.Component.DEFAULT_RUNTIME, + constructor : GameLib.System }; case 0x14 : return { name : 'GameLib.GraphicsRuntime', - runtime : GameLib.Component.DEFAULT_RUNTIME + runtime : GameLib.Component.DEFAULT_RUNTIME, + constructor : GameLib.GraphicsRuntime }; case 0x15 : return { name : 'GameLib.D3.Helper', - runtime : GameLib.Component.GRAPHICS_RUNTIME + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.Helper }; case 0x16 : return { name : 'GameLib.CustomCode', - runtime : GameLib.Component.DEFAULT_RUNTIME + runtime : GameLib.Component.DEFAULT_RUNTIME, + constructor : GameLib.CustomCode }; case 0x17 : return { name : 'GameLib.Mouse', - runtime : GameLib.Component.GRAPHICS_RUNTIME + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.Mouse }; case 0x18 : return { name : 'GameLib.D3.Skeleton', - runtime : GameLib.Component.GRAPHICS_RUNTIME + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.Skeleton }; case 0x19 : return { name : 'GameLib.D3.Texture', - runtime : GameLib.Component.GRAPHICS_RUNTIME + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.Texture }; case 0x1a : return { name : 'GameLib.EntityManager', - runtime : GameLib.Component.DEFAULT_RUNTIME + runtime : GameLib.Component.DEFAULT_RUNTIME, + constructor : GameLib.EntityManager }; case 0x1b : return { name : 'GameLib.DomElement', - runtime : GameLib.Component.DEFAULT_RUNTIME + runtime : GameLib.Component.DEFAULT_RUNTIME, + constructor : GameLib.DomElement }; case 0x1c : return null; case 0x1d : return { - name : 'GameLib.D3.Stats', - runtime : GameLib.Component.STATISTICS_RUNTIME + name : 'GameLib.Stats', + runtime : GameLib.Component.STATISTICS_RUNTIME, + constructor : GameLib.Stats }; case 0x1e : return { name : 'GameLib.GUI', - runtime : GameLib.Component.GUI_RUNTIME + runtime : GameLib.Component.GUI_RUNTIME, + constructor : GameLib.GUI }; case 0x1f : return { name : 'GameLib.Image', - runtime : GameLib.Component.DEFAULT_RUNTIME + runtime : GameLib.Component.DEFAULT_RUNTIME, + constructor : GameLib.Image }; case 0x20 : return { name : 'GameLib.Entity', - runtime : GameLib.Component.DEFAULT_RUNTIME + runtime : GameLib.Component.DEFAULT_RUNTIME, + constructor : GameLib.Entity }; case 0x21 : return { name : 'GameLib.D3.Mesh.Sphere', - runtime : GameLib.Component.GRAPHICS_RUNTIME + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.Mesh.Sphere }; case 0x22 : return { name : 'GameLib.D3.Mesh.Plane', - runtime : GameLib.Component.GRAPHICS_RUNTIME + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.Mesh.Plane }; case 0x23 : return { name : 'GameLib.D3.Mesh.Curve', - runtime : GameLib.Component.GRAPHICS_RUNTIME + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.Mesh.Curve }; case 0x24 : return { name : 'GameLib.D3.PhysicsWorld', - runtime : GameLib.Component.PHYSICS_RUNTIME + runtime : GameLib.Component.PHYSICS_RUNTIME, + constructor : GameLib.D3.PhysicsWorld }; case 0x25 : return { name : 'GameLib.D3.Broadphase', - runtime : GameLib.Component.PHYSICS_RUNTIME + runtime : GameLib.Component.PHYSICS_RUNTIME, + constructor : GameLib.D3.Broadphase }; case 0x26 : return { name : 'GameLib.D3.Solver', - runtime : GameLib.Component.PHYSICS_RUNTIME + runtime : GameLib.Component.PHYSICS_RUNTIME, + constructor : GameLib.D3.Solver }; case 0x27 : return { name : 'GameLib.D3.RigidBody', - runtime : GameLib.Component.PHYSICS_RUNTIME + runtime : GameLib.Component.PHYSICS_RUNTIME, + constructor : GameLib.D3.RigidBody }; case 0x28 : return { name : 'GameLib.D3.Shape', - runtime : GameLib.Component.PHYSICS_RUNTIME + runtime : GameLib.Component.PHYSICS_RUNTIME, + constructor : GameLib.D3.Shape }; case 0x29 : return { name : 'GameLib.D3.Shape.Box', - runtime : GameLib.Component.PHYSICS_RUNTIME + runtime : GameLib.Component.PHYSICS_RUNTIME, + constructor : GameLib.D3.Shape.Box }; case 0x2a : return { name : 'GameLib.D3.Shape.Sphere', - runtime : GameLib.Component.PHYSICS_RUNTIME + runtime : GameLib.Component.PHYSICS_RUNTIME, + constructor : GameLib.D3.Shape.Sphere }; case 0x2b : return { name : 'GameLib.D3.Shape.TriMesh', - runtime : GameLib.Component.PHYSICS_RUNTIME + runtime : GameLib.Component.PHYSICS_RUNTIME, + constructor : GameLib.D3.Shape.TriMesh }; case 0x2c : return { name : 'GameLib.D3.Shape.ConvexHull', - runtime : GameLib.Component.PHYSICS_RUNTIME + runtime : GameLib.Component.PHYSICS_RUNTIME, + constructor : GameLib.D3.Shape.ConvexHull }; case 0x2d : return { name : 'GameLib.D3.Shape.ConvexHull.Cylinder', - runtime : GameLib.Component.PHYSICS_RUNTIME + runtime : GameLib.Component.PHYSICS_RUNTIME, + constructor : GameLib.D3.Shape.ConvexHull.Cylinder }; case 0x2e : return { name : 'GameLib.D3.Shape.HeightMap', - runtime : GameLib.Component.DEFAULT_RUNTIME + runtime : GameLib.Component.DEFAULT_RUNTIME, + constructor : GameLib.D3.Shape.HeightMap }; case 0x2f : return { name : 'GameLib.D3.Shape.Plane', - runtime : GameLib.Component.PHYSICS_RUNTIME + runtime : GameLib.Component.PHYSICS_RUNTIME, + constructor : GameLib.D3.Shape.Plane }; case 0x30 : return { name : 'GameLib.Controls', - runtime : GameLib.Component.DEFAULT_RUNTIME + runtime : GameLib.Component.DEFAULT_RUNTIME, + constructor : GameLib.Controls }; case 0x31 : return { - name : 'GameLib.D3.Controls.Editor', - runtime : GameLib.Component.GRAPHICS_RUNTIME + name : 'GameLib.Controls.D3.Editor', + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.Controls.D3.Editor }; case 0x32 : return { name : 'GameLib.Controls.Touch', - runtime : GameLib.Component.DEFAULT_RUNTIME + runtime : GameLib.Component.DEFAULT_RUNTIME, + constructor : GameLib.Controls.Touch }; case 0x33 : return { name : 'GameLib.D3.FrictionMaterial', - runtime : GameLib.Component.PHYSICS_RUNTIME + runtime : GameLib.Component.PHYSICS_RUNTIME, + constructor : GameLib.D3.FrictionMaterial }; case 0x34 : return { name : 'GameLib.D3.FrictionContactMaterial', - runtime : GameLib.Component.PHYSICS_RUNTIME + runtime : GameLib.Component.PHYSICS_RUNTIME, + constructor : GameLib.D3.FrictionContactMaterial }; case 0x35 : return { name : 'GameLib.D3.RaycastVehicle', - runtime : GameLib.Component.PHYSICS_RUNTIME + runtime : GameLib.Component.PHYSICS_RUNTIME, + constructor : GameLib.D3.RaycastVehicle }; case 0x36 : return { name : 'GameLib.D3.RaycastWheel', - runtime : GameLib.Component.PHYSICS_RUNTIME + runtime : GameLib.Component.PHYSICS_RUNTIME, + constructor : GameLib.D3.RaycastWheel }; case 0x37 : return { name : 'GameLib.Clock', - runtime : GameLib.Component.GRAPHICS_RUNTIME + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.Clock }; case 0x38 : return { name : 'GameLib.D3.Animation', - runtime : GameLib.Component.DEFAULT_RUNTIME + runtime : GameLib.Component.DEFAULT_RUNTIME, + constructor : GameLib.D3.Animation }; case 0x39 : return { name : 'GameLib.Controls.Keyboard', - runtime : GameLib.Component.DEFAULT_RUNTIME + runtime : GameLib.Component.DEFAULT_RUNTIME, + constructor : GameLib.Controls.Keyboard }; case 0x3a : return { name : 'GameLib.Controls.Mouse', - runtime : GameLib.Component.DEFAULT_RUNTIME + runtime : GameLib.Component.DEFAULT_RUNTIME, + constructor : GameLib.Controls.Mouse }; case 0x3b : return { name : 'GameLib.D3.Mesh.Text', - runtime : GameLib.Component.GRAPHICS_RUNTIME + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.Mesh.Text }; case 0x3c : return { name : 'GameLib.D3.Font', - runtime : GameLib.Component.GRAPHICS_RUNTIME + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.Font }; case 0x3d : return { name : 'GameLib.Canvas', - runtime : GameLib.Component.DEFAULT_RUNTIME + runtime : GameLib.Component.DEFAULT_RUNTIME, + constructor : GameLib.Canvas }; case 0x3e : return { name : 'GameLib.D3.Bone', - runtime : GameLib.Component.GRAPHICS_RUNTIME + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.Bone }; case 0x3f : return { name : 'GameLib.D3.Mesh.Box', - runtime : GameLib.Component.GRAPHICS_RUNTIME + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.Mesh.Box }; case 0x40 : return { name : 'GameLib.D3.Mesh.Cylinder', - runtime : GameLib.Component.GRAPHICS_RUNTIME + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.Mesh.Cylinder }; case 0x41 : return { name : 'GameLib.D3.System.Animation', - runtime : GameLib.Component.DEFAULT_RUNTIME + runtime : GameLib.Component.DEFAULT_RUNTIME, + constructor : GameLib.D3.System.Animation }; case 0x42 : return { name : 'GameLib.D3.System.CustomCode', - runtime : GameLib.Component.DEFAULT_RUNTIME + runtime : GameLib.Component.DEFAULT_RUNTIME, + constructor : GameLib.D3.System.CustomCode }; case 0x43 : return { name : 'GameLib.D3.System.GUI', - runtime : GameLib.Component.DEFAULT_RUNTIME + runtime : GameLib.Component.DEFAULT_RUNTIME, + constructor : GameLib.D3.System.GUI }; case 0x44 : return { name : 'GameLib.D3.System.Input', - runtime : GameLib.Component.DEFAULT_RUNTIME + runtime : GameLib.Component.DEFAULT_RUNTIME, + constructor : GameLib.D3.System.Input }; case 0x45 : return { name : 'GameLib.D3.System.Linking', - runtime : GameLib.Component.DEFAULT_RUNTIME + runtime : GameLib.Component.DEFAULT_RUNTIME, + constructor : GameLib.D3.System.Linking }; case 0x46 : return { name : 'GameLib.D3.System.Physics', - runtime : GameLib.Component.DEFAULT_RUNTIME + runtime : GameLib.Component.DEFAULT_RUNTIME, + constructor : GameLib.D3.System.Physics }; case 0x47 : return { name : 'GameLib.D3.System.Render', - runtime : GameLib.Component.DEFAULT_RUNTIME + runtime : GameLib.Component.DEFAULT_RUNTIME, + constructor : GameLib.D3.System.Render }; case 0x48 : return { name : 'GameLib.D3.System.Storage', - runtime : GameLib.Component.DEFAULT_RUNTIME + runtime : GameLib.Component.DEFAULT_RUNTIME, + constructor : GameLib.D3.System.Storage }; case 0x49 : return { name : 'GameLib.D3.System.Visualization', - runtime : GameLib.Component.DEFAULT_RUNTIME + runtime : GameLib.Component.DEFAULT_RUNTIME, + constructor : GameLib.D3.System.Visualization }; case 0x50 : return { name : 'GameLib.D3.Fog', - runtime : GameLib.Component.GRAPHICS_RUNTIME + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.Fog }; case 0x51 : return { name : 'GameLib.D3.Mesh.Line', - runtime : GameLib.Component.GRAPHICS_RUNTIME + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.Mesh.Line }; case 0x52 : return { name : 'GameLib.D3.ParticleEngine', - runtime : GameLib.Component.GRAPHICS_RUNTIME + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.ParticleEngine }; case 0x53 : return { name : 'GameLib.D3.System.Particle', - runtime : GameLib.Component.DEFAULT_RUNTIME + runtime : GameLib.Component.DEFAULT_RUNTIME, + constructor : GameLib.D3.System.Particle }; case 0x54 : return { name : 'GameLib.D3.Particle', - runtime : GameLib.Component.GRAPHICS_RUNTIME + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.Particle }; case 0x55 : return { name : 'GameLib.D3.Audio', - runtime : GameLib.Component.GRAPHICS_RUNTIME + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.Audio }; case 0x56 : return { name : 'GameLib.System.Audio', - runtime : GameLib.Component.DEFAULT_RUNTIME + runtime : GameLib.Component.DEFAULT_RUNTIME, + constructor : GameLib.System.Audio }; case 0x57 : return { name : 'GameLib.Cast', - runtime : GameLib.Component.SOCKET_RUNTIME + runtime : GameLib.Component.SOCKET_RUNTIME, + constructor : GameLib.Cast }; break; } @@ -634,7 +704,7 @@ GameLib.Component.GetComponentName = function(componentType) { }; /** - * @return {null} + * @return {null || Object} */ GameLib.Component.GetComponentRuntime = function(componentType) { @@ -646,6 +716,22 @@ GameLib.Component.GetComponentRuntime = function(componentType) { return null; }; + +/** + * @return {null || Object} + */ +GameLib.Component.GetComponentConstructor = function(componentType) { + + var info = GameLib.Component.GetComponentInfo(componentType); + + if (info) { + return info.constructor; + } + + return null; +}; + + /** * Components are linked at runtime - for storing, we just store the ID * @returns {*} @@ -764,7 +850,7 @@ GameLib.Component.prototype.generateNewIds = function() { this.buildIdToObject(); - var codeComponents = GameLib.EntityManager.Instance.queryComponents(GameLib.CustomCode); + var codeComponents = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.CUSTOM_CODE); for (var property in this.idToObject) { if (this.idToObject.hasOwnProperty(property)) { @@ -950,8 +1036,6 @@ GameLib.Component.prototype.save = function(remote) { var apiObject = this.idToObject[property].toApiObject(); - apiObject.componentType = this.idToObject[property].componentType; - toSave.push(apiObject); this.publish( @@ -971,7 +1055,7 @@ GameLib.Component.Construct = function(rawComponentObject) { var info = GameLib.Component.GetComponentInfo(rawComponentObject.componentType); - var componentClass = eval(info.name); + var componentClass = info.constructor; var fn = componentClass['FromObject']; @@ -979,12 +1063,13 @@ GameLib.Component.Construct = function(rawComponentObject) { GameLib.Event.Emit( GameLib.Event.GET_RUNTIME, + null, function(runtimeObject) { runtime = runtimeObject; } ); - if (rawComponentObject.componentType === GameLib.Component.COMPONENT_ENTITY) { + if (rawComponentObject.componentType === GameLib.Component.ENTITY) { runtimeComponent = fn(rawComponentObject, GameLib.EntityManager.Instance); diff --git a/src/game-lib-api-canvas.js b/src/game-lib-api-canvas.js index b7a66f6..79dd4bd 100644 --- a/src/game-lib-api-canvas.js +++ b/src/game-lib-api-canvas.js @@ -34,10 +34,11 @@ GameLib.API.Canvas = function( } this.height = height; - if (GameLib.Utils.UndefinedOrNull(parentEntity)){ - parentEntity = null; - } - this.parentEntity = parentEntity; + GameLib.API.Component.call( + this, + GameLib.Component.CANVAS, + parentEntity + ); }; GameLib.API.Canvas.prototype = Object.create(GameLib.Component.prototype); diff --git a/src/game-lib-api-cast.js b/src/game-lib-api-cast.js index 9424cf7..b8938b5 100644 --- a/src/game-lib-api-cast.js +++ b/src/game-lib-api-cast.js @@ -56,10 +56,11 @@ GameLib.API.Cast = function( } this.port = port; - if (GameLib.Utils.UndefinedOrNull(parentEntity)) { - parentEntity = null; - } - this.parentEntity = parentEntity; + GameLib.API.Component.call( + this, + GameLib.Component.CAST, + parentEntity + ); }; GameLib.API.Cast.prototype = Object.create(GameLib.Component.prototype); diff --git a/src/game-lib-api-clock.js b/src/game-lib-api-clock.js index 965d02e..bb98503 100644 --- a/src/game-lib-api-clock.js +++ b/src/game-lib-api-clock.js @@ -21,10 +21,11 @@ GameLib.API.Clock = function( } this.name = name; - if (GameLib.Utils.UndefinedOrNull(parentEntity)) { - parentEntity = null; - } - this.parentEntity = parentEntity; + GameLib.API.Component.call( + this, + GameLib.Component.CLOCK, + parentEntity + ); }; GameLib.API.Clock.prototype = Object.create(GameLib.Component.prototype); diff --git a/src/game-lib-api-controls.js b/src/game-lib-api-controls.js index ae46272..209e911 100644 --- a/src/game-lib-api-controls.js +++ b/src/game-lib-api-controls.js @@ -22,7 +22,7 @@ GameLib.API.Controls = function( if (GameLib.Utils.UndefinedOrNull(controlsType)) { - if (this instanceof GameLib.D3.Controls.Editor) { + if (this instanceof GameLib.Controls.D3.Editor) { controlsType = GameLib.Controls.CONTROLS_TYPE_EDITOR; } @@ -71,15 +71,29 @@ GameLib.API.Controls = function( } this.domElement = domElement; - // if (GameLib.Utils.UndefinedOrNull(fullscreen)) { - // fullscreen = false; - // } - // this.fullscreen = fullscreen; + var componentType = GameLib.Component.CONTROLS; - if (GameLib.Utils.UndefinedOrNull(parentEntity)) { - parentEntity = null; + if (this.controlsType === GameLib.Controls.CONTROLS_TYPE_EDITOR) { + componentType = GameLib.Component.CONTROLS_EDITOR; } - this.parentEntity = parentEntity; + + if (this.controlsType === GameLib.Controls.CONTROLS_TYPE_TOUCH) { + componentType = GameLib.Component.CONTROLS_TOUCH + } + + if (this.controlsType === GameLib.Controls.CONTROLS_TYPE_KEYBOARD) { + componentType = GameLib.Component.CONTROLS_KEYBOARD + } + + if (this.controlsType === GameLib.Controls.CONTROLS_TYPE_MOUSE) { + componentType = GameLib.Component.CONTROLS_MOUSE + } + + GameLib.API.Component.call( + this, + componentType, + parentEntity + ); }; GameLib.API.Controls.prototype = Object.create(GameLib.Component.prototype); diff --git a/src/game-lib-api-custom-code.js b/src/game-lib-api-custom-code.js index 9735e84..6ca97c3 100644 --- a/src/game-lib-api-custom-code.js +++ b/src/game-lib-api-custom-code.js @@ -34,11 +34,11 @@ GameLib.API.CustomCode = function ( } this.code = code; - if (GameLib.Utils.UndefinedOrNull(parentEntity)) { - parentEntity = null; - } - this.parentEntity = parentEntity; - + GameLib.API.Component.call( + this, + GameLib.Component.CUSTOM_CODE, + parentEntity + ); }; GameLib.API.CustomCode.prototype = Object.create(GameLib.Component.prototype); diff --git a/src/game-lib-api-dom-element.js b/src/game-lib-api-dom-element.js index fdfb451..341f331 100644 --- a/src/game-lib-api-dom-element.js +++ b/src/game-lib-api-dom-element.js @@ -28,10 +28,11 @@ GameLib.API.DomElement = function( } this.domElementId = domElementId; - if (GameLib.Utils.UndefinedOrNull(parentEntity)) { - parentEntity = null; - } - this.parentEntity = parentEntity; + GameLib.API.Component.call( + this, + GameLib.Component.DOM_ELEMENT, + parentEntity + ); }; GameLib.API.DomElement.prototype = Object.create(GameLib.Component.prototype); diff --git a/src/game-lib-api-entity-manager.js b/src/game-lib-api-entity-manager.js index 8f22978..6c6e6ad 100644 --- a/src/game-lib-api-entity-manager.js +++ b/src/game-lib-api-entity-manager.js @@ -6,13 +6,15 @@ * @param entities GameLib.API.Entity[] * @param defaultEntity * @param defaultRenderer + * @param parentEntity */ GameLib.API.EntityManager = function( id, name, entities, defaultEntity, - defaultRenderer + defaultRenderer, + parentEntity ) { if (GameLib.Utils.UndefinedOrNull(id)) { id = GameLib.Utils.RandomId(); @@ -38,6 +40,12 @@ GameLib.API.EntityManager = function( defaultRenderer = null; } this.defaultRenderer = defaultRenderer; + + GameLib.API.Component.call( + this, + GameLib.Component.ENTITY_MANAGER, + parentEntity + ); }; GameLib.API.EntityManager.prototype = Object.create(GameLib.Component.prototype); @@ -61,6 +69,7 @@ GameLib.API.EntityManager.FromObject = function(objectEntityManager) { objectEntityManager.name, apiEntities, objectEntityManager.defaultEntity, - objectEntityManager.defaultRenderer + objectEntityManager.defaultRenderer, + objectEntityManager.parentEntity ); }; diff --git a/src/game-lib-api-entity.js b/src/game-lib-api-entity.js index 6bc9100..659e5ab 100644 --- a/src/game-lib-api-entity.js +++ b/src/game-lib-api-entity.js @@ -29,10 +29,11 @@ GameLib.API.Entity = function( } this.components = components; - if (GameLib.Utils.UndefinedOrNull(parentEntity)) { - parentEntity = null; - } - this.parentEntity = parentEntity; + GameLib.API.Component.call( + this, + GameLib.Component.ENTITY, + parentEntity + ); if (GameLib.Utils.UndefinedOrNull(parentEntityManager)) { parentEntityManager = null; diff --git a/src/game-lib-api-gui.js b/src/game-lib-api-gui.js new file mode 100644 index 0000000..a89e3d8 --- /dev/null +++ b/src/game-lib-api-gui.js @@ -0,0 +1,72 @@ +/** + * Raw GUI API object - should always correspond with the GUI Schema + * @param id + * @param name + * @param domElement + * @param objects + * @param parentEntity + * @constructor + */ +GameLib.API.GUI = function( + id, + name, + domElement, + objects, + parentEntity +) { + + if (GameLib.Utils.UndefinedOrNull(id)) { + id = GameLib.Utils.RandomId(); + } + this.id = id; + + if (GameLib.Utils.UndefinedOrNull(name)) { + name = 'GUI (' + this.id + ')'; + } + this.name = name; + + if (GameLib.Utils.UndefinedOrNull(domElement)) { + domElement = null; + } + this.domElement = domElement; + + if (GameLib.Utils.UndefinedOrNull(objects)) { + objects = []; + } + this.objects = objects; + + GameLib.API.Component.call( + this, + GameLib.Component.GUI, + parentEntity + ); +}; + +GameLib.API.GUI.prototype = Object.create(GameLib.Component.prototype); +GameLib.API.GUI.prototype.constructor = GameLib.API.GUI; + +/** + * Creates an API GUI from an Object GUI + * @param objectGUI + * @constructor + */ +GameLib.API.GUI.FromObject = function(objectGUI) { + + var apiDomElement = null; + if (objectGUI.domElement) { + if (objectGUI.domElement instanceof Object) { + apiDomElement = GameLib.API.DomElement.FromObject(objectGUI.domElement); + } else { + apiDomElement = objectGUI.domElement; + } + } + + return new GameLib.API.GUI( + objectGUI.id, + objectGUI.name, + apiDomElement, + objectGUI.objects, + objectGUI.parentEntity + ); + +}; diff --git a/src/game-lib-api-image.js b/src/game-lib-api-image.js index 7cc2b28..a2efd91 100644 --- a/src/game-lib-api-image.js +++ b/src/game-lib-api-image.js @@ -68,10 +68,11 @@ GameLib.API.Image = function( } this.size = size; - if (GameLib.Utils.UndefinedOrNull(parentEntity)) { - parentEntity = null; - } - this.parentEntity = parentEntity; + GameLib.API.Component.call( + this, + GameLib.Component.IMAGE, + parentEntity + ); }; GameLib.API.Image.prototype = Object.create(GameLib.Component.prototype); diff --git a/src/game-lib-api-mouse.js b/src/game-lib-api-mouse.js index c51b85c..3cc7ad8 100644 --- a/src/game-lib-api-mouse.js +++ b/src/game-lib-api-mouse.js @@ -14,12 +14,6 @@ GameLib.API.Mouse = function( y, parentEntity ) { - - if (GameLib.Utils.UndefinedOrNull(parentEntity)) { - parentEntity = null; - } - this.parentEntity = parentEntity; - if (GameLib.Utils.UndefinedOrNull(id)) { id = GameLib.Utils.RandomId(); } @@ -40,6 +34,11 @@ GameLib.API.Mouse = function( } this.y = y; + GameLib.API.Component.call( + this, + GameLib.Component.MOUSE, + parentEntity + ); }; GameLib.API.Mouse.prototype = Object.create(GameLib.Component.prototype); diff --git a/src/game-lib-api-stats.js b/src/game-lib-api-stats.js new file mode 100644 index 0000000..0725bfe --- /dev/null +++ b/src/game-lib-api-stats.js @@ -0,0 +1,64 @@ +/** + * Raw Stats API object - should always correspond with the Stats Schema + * @param id + * @param name + * @param domElement + * @param parentEntity + * @constructor + */ +GameLib.API.Stats = function( + id, + name, + domElement, + parentEntity +) { + + if (GameLib.Utils.UndefinedOrNull(id)) { + id = GameLib.Utils.RandomId(); + } + this.id = id; + + if (GameLib.Utils.UndefinedOrNull(name)) { + name = 'Stats (' + this.id + ')'; + } + this.name = name; + + if (GameLib.Utils.UndefinedOrNull(domElement)) { + domElement = null; + } + this.domElement = domElement; + + GameLib.API.Component.call( + this, + GameLib.Component.STATS, + parentEntity + ); +}; + +GameLib.API.Stats.prototype = Object.create(GameLib.Component.prototype); +GameLib.API.Stats.prototype.constructor = GameLib.API.Stats; + +/** + * Creates an API Stats from an Object Stats + * @param objectStats + * @constructor + */ +GameLib.API.Stats.FromObject = function(objectStats) { + + var apiDomElement = null; + if (objectStats.domElement) { + if (objectStats.domElement instanceof Object) { + apiDomElement = GameLib.API.DomElement.FromObject(objectStats.domElement); + } else { + apiDomElement = objectStats.domElement; + } + } + + return new GameLib.API.Stats( + objectStats.id, + objectStats.name, + apiDomElement, + objectStats.parentEntity + ); + +}; diff --git a/src/game-lib-api-system.js b/src/game-lib-api-system.js index d93725c..5900323 100644 --- a/src/game-lib-api-system.js +++ b/src/game-lib-api-system.js @@ -22,16 +22,67 @@ GameLib.API.System = function ( name = "System (" + this.id + ")"; } this.name = name; - + if (GameLib.Utils.UndefinedOrNull(systemType)) { - systemType = GameLib.System.SYSTEM_TYPE_RENDER; + systemType = GameLib.System.SYSTEM_TYPE_NONE; } this.systemType = systemType; - - if (GameLib.Utils.UndefinedOrNull(parentEntity)) { - parentEntity = null; + + var componentType = GameLib.Component.SYSTEM; + + if (this.systemType === GameLib.System.SYSTEM_TYPE_NONE) { + componentType = GameLib.Component.SYSTEM; } - this.parentEntity = parentEntity; + + if (this.systemType === GameLib.System.SYSTEM_TYPE_ANIMATION) { + componentType = GameLib.Component.SYSTEM_ANIMATION; + } + + if (this.systemType === GameLib.System.SYSTEM_TYPE_CUSTOM) { + componentType = GameLib.Component.SYSTEM_CUSTOM_CODE; + } + + if (this.systemType === GameLib.System.SYSTEM_TYPE_GUI) { + componentType = GameLib.Component.SYSTEM_GUI; + } + + if (this.systemType === GameLib.System.SYSTEM_TYPE_INPUT) { + componentType = GameLib.Component.SYSTEM_INPUT; + } + + if (this.systemType === GameLib.System.SYSTEM_TYPE_LINKING) { + componentType = GameLib.Component.SYSTEM_LINKING; + } + + if (this.systemType === GameLib.System.SYSTEM_TYPE_PHYSICS) { + componentType = GameLib.Component.SYSTEM_PHYSICS; + } + + if (this.systemType === GameLib.System.SYSTEM_TYPE_RENDER) { + componentType = GameLib.Component.SYSTEM_RENDER; + } + + if (this.systemType === GameLib.System.SYSTEM_TYPE_STORAGE) { + componentType = GameLib.Component.SYSTEM_STORAGE; + } + + if (this.systemType === GameLib.System.SYSTEM_TYPE_VISUALIZATION) { + componentType = GameLib.Component.SYSTEM_VISUALIZATION; + } + + if (this.systemType === GameLib.System.SYSTEM_TYPE_PARTICLE) { + componentType = GameLib.Component.SYSTEM_PARTICLE; + } + + if (this.systemType === GameLib.System.SYSTEM_TYPE_AUDIO) { + componentType = GameLib.Component.SYSTEM_AUDIO; + } + + GameLib.API.Component.call( + this, + componentType, + parentEntity + ); }; diff --git a/src/game-lib-canvas.js b/src/game-lib-canvas.js index 3d8efa9..af11fe0 100644 --- a/src/game-lib-canvas.js +++ b/src/game-lib-canvas.js @@ -24,10 +24,7 @@ GameLib.Canvas = function( apiCanvas.parentEntity ); - GameLib.Component.call( - this, - GameLib.Component.COMPONENT_CANVAS - ); + GameLib.Component.call(this); }; GameLib.Canvas.prototype = Object.create(GameLib.API.Canvas.prototype); diff --git a/src/game-lib-cast.js b/src/game-lib-cast.js index 5f93c74..67c0247 100644 --- a/src/game-lib-cast.js +++ b/src/game-lib-cast.js @@ -34,7 +34,6 @@ GameLib.Cast = function( GameLib.Component.call( this, - GameLib.Component.COMPONENT_CAST, { peer : GameLib.Component } diff --git a/src/game-lib-clock.js b/src/game-lib-clock.js index 3a9618b..4e640d9 100644 --- a/src/game-lib-clock.js +++ b/src/game-lib-clock.js @@ -27,11 +27,7 @@ GameLib.Clock = function( apiClock.parentEntity ); - GameLib.Component.call( - this, - GameLib.Component.COMPONENT_CLOCK - ); - + GameLib.Component.call(this); } ; GameLib.Clock.prototype = Object.create(GameLib.API.Clock.prototype); diff --git a/src/game-lib-controls-0.js b/src/game-lib-controls-0.js index 94713dd..f4cb62b 100644 --- a/src/game-lib-controls-0.js +++ b/src/game-lib-controls-0.js @@ -24,8 +24,6 @@ GameLib.Controls = function ( apiControls.parentEntity ); - var componentType = GameLib.Component.COMPONENT_CONTROLS; - var linkedObjects = { domElement : GameLib.DomElement }; @@ -34,29 +32,14 @@ GameLib.Controls = function ( if (this.controlsType === GameLib.Controls.CONTROLS_TYPE_EDITOR) { - componentType = GameLib.Component.COMPONENT_CONTROLS_EDITOR; - linkedObjects.raycaster = GameLib.D3.Raycaster; linkedObjects.camera = GameLib.D3.Camera; delayed = true; } - if (this.controlsType === GameLib.Controls.CONTROLS_TYPE_TOUCH) { - componentType = GameLib.Component.COMPONENT_CONTROLS_TOUCH - } - - if (this.controlsType === GameLib.Controls.CONTROLS_TYPE_KEYBOARD) { - componentType = GameLib.Component.COMPONENT_CONTROLS_KEYBOARD - } - - if (this.controlsType === GameLib.Controls.CONTROLS_TYPE_MOUSE) { - componentType = GameLib.Component.COMPONENT_CONTROLS_MOUSE - } - GameLib.Component.call( this, - componentType, linkedObjects, delayed ); @@ -65,6 +48,8 @@ GameLib.Controls = function ( GameLib.Controls.prototype = Object.create(GameLib.API.Controls.prototype); GameLib.Controls.prototype.constructor = GameLib.Controls; +GameLib.Controls.D3 = function() {}; + /** * Controls Type * @type {number} diff --git a/src/game-lib-d3-controls-editor.js b/src/game-lib-controls-d3-editor.js similarity index 80% rename from src/game-lib-d3-controls-editor.js rename to src/game-lib-controls-d3-editor.js index 300c55c..8816ede 100644 --- a/src/game-lib-d3-controls-editor.js +++ b/src/game-lib-controls-d3-editor.js @@ -6,7 +6,7 @@ * @param camera * @constructor */ -GameLib.D3.Controls.Editor = function ( +GameLib.Controls.D3.Editor = function ( graphics, apiControls, raycaster, @@ -50,14 +50,14 @@ GameLib.D3.Controls.Editor = function ( * Inheritance * @type {GameLib.Controls} */ -GameLib.D3.Controls.Editor.prototype = Object.create(GameLib.Controls.prototype); -GameLib.D3.Controls.Editor.prototype.constructor = GameLib.D3.Controls.Editor; +GameLib.Controls.D3.Editor.prototype = Object.create(GameLib.Controls.prototype); +GameLib.Controls.D3.Editor.prototype.constructor = GameLib.Controls.D3.Editor; /** * Create Instance * @returns {THREE.EditorControls} */ -GameLib.D3.Controls.Editor.prototype.createInstance = function() { +GameLib.Controls.D3.Editor.prototype.createInstance = function() { if (!this.camera || !this.camera.instance) { throw new Error('No camera at time of instance'); @@ -78,7 +78,7 @@ GameLib.D3.Controls.Editor.prototype.createInstance = function() { /** * Update Instance */ -GameLib.D3.Controls.Editor.prototype.updateInstance = function() { +GameLib.Controls.D3.Editor.prototype.updateInstance = function() { console.warn('an update instance was called on editor controls - which, if not called from within a running system at the right time will affect the order of input event handling and cause system instability'); @@ -86,10 +86,10 @@ GameLib.D3.Controls.Editor.prototype.updateInstance = function() { }; /** - * Converts a GameLib.D3.Controls.Editor to a GameLib.D3.API.Mesh + * Converts a GameLib.Controls.D3.Editor to a GameLib.D3.API.Mesh * @returns {GameLib.API.Controls} */ -GameLib.D3.Controls.Editor.prototype.toApiObject = function() { +GameLib.Controls.D3.Editor.prototype.toApiObject = function() { var apiControls = GameLib.Controls.prototype.toApiObject.call(this); @@ -103,14 +103,14 @@ GameLib.D3.Controls.Editor.prototype.toApiObject = function() { * Construct an Editor Controls object from data * @param graphics * @param objectControls - * @returns {GameLib.D3.Controls.Editor} + * @returns {GameLib.Controls.D3.Editor} * @constructor */ -GameLib.D3.Controls.Editor.FromObject = function(graphics, objectControls) { +GameLib.Controls.D3.Editor.FromObject = function(graphics, objectControls) { var apiControls = GameLib.API.Controls.FromObject(objectControls); - return new GameLib.D3.Controls.Editor( + return new GameLib.Controls.D3.Editor( graphics, apiControls, objectControls.raycaster, diff --git a/src/game-lib-custom-code.js b/src/game-lib-custom-code.js index ca12f39..0cbc308 100644 --- a/src/game-lib-custom-code.js +++ b/src/game-lib-custom-code.js @@ -26,10 +26,7 @@ GameLib.CustomCode = function( this.editor = null; - GameLib.Component.call( - this, - GameLib.Component.COMPONENT_CUSTOM_CODE - ); + GameLib.Component.call(this); }; GameLib.CustomCode.prototype = Object.create(GameLib.API.CustomCode.prototype); diff --git a/src/game-lib-d3-api-animation.js b/src/game-lib-d3-api-animation.js index 6ce6554..340767c 100644 --- a/src/game-lib-d3-api-animation.js +++ b/src/game-lib-d3-api-animation.js @@ -87,10 +87,11 @@ GameLib.D3.API.Animation = function ( } this.meshes = meshes; - if (GameLib.Utils.UndefinedOrNull(parentEntity)) { - parentEntity = null; - } - this.parentEntity = parentEntity; + GameLib.API.Component.call( + this, + GameLib.Component.ANIMATION, + parentEntity + ); }; GameLib.D3.API.Animation.prototype = Object.create(GameLib.Component.prototype); diff --git a/src/game-lib-d3-api-audio.js b/src/game-lib-d3-api-audio.js index 8b931b1..ab6b951 100644 --- a/src/game-lib-d3-api-audio.js +++ b/src/game-lib-d3-api-audio.js @@ -7,6 +7,7 @@ * @param volume * @param camera * @param overplay + * @param paused * @param parentEntity * @constructor */ @@ -62,10 +63,11 @@ GameLib.D3.API.Audio = function( } this.paused = paused; - if (GameLib.Utils.UndefinedOrNull(parentEntity)) { - parentEntity = null; - } - this.parentEntity = parentEntity; + GameLib.API.Component.call( + this, + GameLib.Component.AUDIO, + parentEntity + ); }; GameLib.D3.API.Audio.prototype = Object.create(GameLib.Component.prototype); diff --git a/src/game-lib-d3-api-bone.js b/src/game-lib-d3-api-bone.js index 096b583..04d6d35 100644 --- a/src/game-lib-d3-api-bone.js +++ b/src/game-lib-d3-api-bone.js @@ -8,6 +8,7 @@ * @param position GameLib.API.Vector3 * @param scale GameLib.API.Vector3 * @param up GameLib.API.Vector3 + * @param parentEntity * @constructor */ GameLib.D3.API.Bone = function ( @@ -18,7 +19,8 @@ GameLib.D3.API.Bone = function ( position, quaternion, scale, - up + up, + parentEntity ) { if (GameLib.Utils.UndefinedOrNull(id)) { @@ -60,8 +62,17 @@ GameLib.D3.API.Bone = function ( up = new GameLib.API.Vector3(0,1,0); } this.up = up; + + GameLib.API.Component.call( + this, + GameLib.Component.BONE, + parentEntity + ); }; +GameLib.D3.API.Bone.prototype = Object.create(GameLib.Component.prototype); +GameLib.D3.API.Bone.prototype.constructor = GameLib.D3.API.Bone; + /** * Returns an API bone from an Object bone * @param objectBone @@ -76,6 +87,7 @@ GameLib.D3.API.Bone.FromObject = function(objectBone) { GameLib.API.Vector3.FromObject(objectBone.position), GameLib.API.Quaternion.FromObject(objectBone.quaternion), GameLib.API.Vector3.FromObject(objectBone.scale), - GameLib.API.Vector3.FromObject(objectBone.up) + GameLib.API.Vector3.FromObject(objectBone.up), + objectBone.parentEntity ); }; diff --git a/src/game-lib-d3-api-broadphase.js b/src/game-lib-d3-api-broadphase.js index 9822881..ccbd619 100644 --- a/src/game-lib-d3-api-broadphase.js +++ b/src/game-lib-d3-api-broadphase.js @@ -28,10 +28,11 @@ GameLib.D3.API.Broadphase = function( } this.broadphaseType = broadphaseType; - if (GameLib.Utils.UndefinedOrNull(parentEntity)) { - parentEntity = null; - } - this.parentEntity = parentEntity; + GameLib.API.Component.call( + this, + GameLib.Component.BROADPHASE, + parentEntity + ); }; GameLib.D3.API.Broadphase.prototype = Object.create(GameLib.Component.prototype); diff --git a/src/game-lib-d3-api-camera.js b/src/game-lib-d3-api-camera.js index f350261..fb09225 100644 --- a/src/game-lib-d3-api-camera.js +++ b/src/game-lib-d3-api-camera.js @@ -18,9 +18,9 @@ * @param offsetX * @param offsetY * @param quaternion GameLib.Quaternion - * @param parentEntity * @param eyeSeparation * @param focalLength + * @param parentEntity * @constructor */ GameLib.D3.API.Camera = function( @@ -42,9 +42,9 @@ GameLib.D3.API.Camera = function( offsetX, offsetY, quaternion, - parentEntity, eyeSeparation, - focalLength + focalLength, + parentEntity ) { if (GameLib.Utils.UndefinedOrNull(id)) { @@ -155,10 +155,11 @@ GameLib.D3.API.Camera = function( } this.focalLength = focalLength; - if (GameLib.Utils.UndefinedOrNull(parentEntity)) { - parentEntity = null; - } - this.parentEntity = parentEntity; + GameLib.API.Component.call( + this, + GameLib.Component.CAMERA, + parentEntity + ); }; GameLib.D3.API.Camera.prototype = Object.create(GameLib.Component.prototype); @@ -190,9 +191,9 @@ GameLib.D3.API.Camera.FromObject = function(objectCamera) { objectCamera.offsetX, objectCamera.offsetY, GameLib.API.Quaternion.FromObject(objectCamera.quaternion), - objectCamera.parentEntity, objectCamera.eyeSeparation, - objectCamera.focalLength + objectCamera.focalLength, + objectCamera.parentEntity ); }; diff --git a/src/game-lib-d3-api-composer.js b/src/game-lib-d3-api-composer.js index 951c705..97514ad 100644 --- a/src/game-lib-d3-api-composer.js +++ b/src/game-lib-d3-api-composer.js @@ -41,10 +41,11 @@ GameLib.D3.API.Composer = function ( } this.passes = passes; - if (GameLib.Utils.UndefinedOrNull(parentEntity)) { - parentEntity = null; - } - this.parentEntity = parentEntity; + GameLib.API.Component.call( + this, + GameLib.Component.COMPOSER, + parentEntity + ); }; GameLib.D3.API.Composer.prototype = Object.create(GameLib.Component.prototype); diff --git a/src/game-lib-d3-api-fog.js b/src/game-lib-d3-api-fog.js index fe59c76..9ca9c31 100644 --- a/src/game-lib-d3-api-fog.js +++ b/src/game-lib-d3-api-fog.js @@ -56,11 +56,11 @@ GameLib.D3.API.Fog = function( } this.density = density; - if (GameLib.Utils.UndefinedOrNull(parentEntity)) { - parentEntity = null; - } - this.parentEntity = parentEntity; - + GameLib.API.Component.call( + this, + GameLib.Component.FOG, + parentEntity + ); }; GameLib.D3.API.Fog.prototype = Object.create(GameLib.Component.prototype); diff --git a/src/game-lib-d3-api-font.js b/src/game-lib-d3-api-font.js index e4409b5..eb920f6 100644 --- a/src/game-lib-d3-api-font.js +++ b/src/game-lib-d3-api-font.js @@ -27,10 +27,11 @@ GameLib.D3.API.Font = function( } this.url = url; - if (GameLib.Utils.UndefinedOrNull(parentEntity)){ - parentEntity = null; - } - this.parentEntity = parentEntity; + GameLib.API.Component.call( + this, + GameLib.Component.FONT, + parentEntity + ); }; GameLib.D3.API.Font.prototype = Object.create(GameLib.Component.prototype); diff --git a/src/game-lib-d3-api-friction-contact-material.js b/src/game-lib-d3-api-friction-contact-material.js index fdd1022..c6b9729 100644 --- a/src/game-lib-d3-api-friction-contact-material.js +++ b/src/game-lib-d3-api-friction-contact-material.js @@ -2,8 +2,7 @@ * Raw FrictionContactMaterial API object - should always correspond with the FrictionContactMaterial Schema * @param id * @param name - * @param material1 - * @param material2 + * @param materials * @param friction * @param restitution * @param contactEquationStiffness @@ -71,10 +70,11 @@ GameLib.D3.API.FrictionContactMaterial = function( } this.frictionEquationRelaxation = frictionEquationRelaxation; - if (GameLib.Utils.UndefinedOrNull(parentEntity)) { - parentEntity = null; - } - this.parentEntity = parentEntity; + GameLib.API.Component.call( + this, + GameLib.Component.FRICTION_CONTACT_MATERIAL, + parentEntity + ); }; GameLib.D3.API.FrictionContactMaterial.prototype = Object.create(GameLib.Component.prototype); diff --git a/src/game-lib-d3-api-friction-material.js b/src/game-lib-d3-api-friction-material.js index 818aa76..4852998 100644 --- a/src/game-lib-d3-api-friction-material.js +++ b/src/game-lib-d3-api-friction-material.js @@ -35,10 +35,11 @@ GameLib.D3.API.FrictionMaterial = function( } this.restitution = restitution; - if (GameLib.Utils.UndefinedOrNull(parentEntity)) { - parentEntity = null; - } - this.parentEntity = parentEntity; + GameLib.API.Component.call( + this, + GameLib.Component.FRICTION_MATERIAL, + parentEntity + ); }; GameLib.D3.API.FrictionMaterial.prototype = Object.create(GameLib.Component.prototype); diff --git a/src/game-lib-d3-api-light.js b/src/game-lib-d3-api-light.js index 2858ca1..89860be 100644 --- a/src/game-lib-d3-api-light.js +++ b/src/game-lib-d3-api-light.js @@ -135,10 +135,11 @@ GameLib.D3.API.Light = function( } this.parentScene = parentScene; - if (GameLib.Utils.UndefinedOrNull(parentEntity)){ - parentEntity = null; - } - this.parentEntity = parentEntity; + GameLib.API.Component.call( + this, + GameLib.Component.LIGHT, + parentEntity + ); }; GameLib.D3.API.Light.prototype = Object.create(GameLib.Component.prototype); diff --git a/src/game-lib-d3-api-material.js b/src/game-lib-d3-api-material.js index 5a156d4..769cdd0 100644 --- a/src/game-lib-d3-api-material.js +++ b/src/game-lib-d3-api-material.js @@ -483,10 +483,11 @@ GameLib.D3.API.Material = function( } this.specularMap = specularMap; - if (GameLib.Utils.UndefinedOrNull(parentEntity)) { - parentEntity = null; - } - this.parentEntity = parentEntity; + GameLib.API.Component.call( + this, + GameLib.Component.MATERIAL, + parentEntity + ); this.needsUpdate = false; }; diff --git a/src/game-lib-d3-api-mesh.js b/src/game-lib-d3-api-mesh.js index 619daaa..2e05721 100644 --- a/src/game-lib-d3-api-mesh.js +++ b/src/game-lib-d3-api-mesh.js @@ -2,25 +2,27 @@ * Raw Mesh API object - should always correspond with the Mesh Schema * @param id * @param meshType + * @param name - * @param vertices GameLib.D3.Vertex[] - * @param faces GameLib.D3.Face[] - * @param materials GameLib.D3.API.Material[] + * @param vertices + * @param faces + * @param materials * @param parentMesh * @param parentScene * @param skeleton * @param skinIndices * @param skinWeights - * @param position GameLib.API.Vector3 - * @param quaternion GameLib.API.Quaternion + * @param position + * @param quaternion * @param rotation - * @param scale GameLib.API.Vector3 + * @param scale * @param up - * @param modelMatrix GameLib.API.Matrix4 - * @param parentEntity + * @param modelMatrix * @param renderOrder * @param isBufferMesh - * @param useQuaternion (use quaternion property for rotation rather than rotation property) + * @param useQuaternion + * @param visible + * @param parentEntity * @constructor */ GameLib.D3.API.Mesh = function( @@ -41,11 +43,11 @@ GameLib.D3.API.Mesh = function( scale, up, modelMatrix, - parentEntity, renderOrder, isBufferMesh, useQuaternion, - visible + visible, + parentEntity ) { if (GameLib.Utils.UndefinedOrNull(id)) { id = GameLib.Utils.RandomId(); @@ -53,7 +55,7 @@ GameLib.D3.API.Mesh = function( this.id = id; if (GameLib.Utils.UndefinedOrNull(meshType)) { - meshType = GameLib.D3.Mesh.MESH_TYPE_NORMAL; + meshType = GameLib.D3.API.Mesh.MESH_TYPE_NORMAL; } this.meshType = meshType; @@ -137,11 +139,6 @@ GameLib.D3.API.Mesh = function( } this.renderOrder = renderOrder; - if (GameLib.Utils.UndefinedOrNull(parentEntity)) { - parentEntity = null; - } - this.parentEntity = parentEntity; - if (GameLib.Utils.UndefinedOrNull(isBufferMesh)) { isBufferMesh = false; } @@ -156,11 +153,58 @@ GameLib.D3.API.Mesh = function( visible = true; } this.visible = visible; + + var componentType = GameLib.Component.MESH; + + if (this.meshType === GameLib.D3.API.Mesh.MESH_TYPE_PLANE) { + componentType = GameLib.Component.MESH_PLANE + } + + if (this.meshType === GameLib.D3.API.Mesh.MESH_TYPE_BOX) { + componentType = GameLib.Component.MESH_BOX + } + + if (this.meshType === GameLib.D3.API.Mesh.MESH_TYPE_CYLINDER) { + componentType = GameLib.Component.MESH_CYLINDER + } + + if (this.meshType === GameLib.D3.API.Mesh.MESH_TYPE_SPHERE) { + componentType = GameLib.Component.MESH_SPHERE + } + + if (this.meshType === GameLib.D3.API.Mesh.MESH_TYPE_LINE) { + componentType = GameLib.Component.MESH_LINE + } + + if (this.meshType === GameLib.D3.API.Mesh.MESH_TYPE_TEXT) { + componentType = GameLib.Component.MESH_TEXT; + } + + GameLib.API.Component.call( + this, + componentType, + parentEntity + ); }; GameLib.D3.API.Mesh.prototype = Object.create(GameLib.Component.prototype); GameLib.D3.API.Mesh.prototype.constructor = GameLib.D3.API.Mesh; + +/** + * Mesh Type + * @type {number} + */ +GameLib.D3.API.Mesh.MESH_TYPE_NORMAL = 0x0; +GameLib.D3.API.Mesh.MESH_TYPE_SKINNED = 0x1; +GameLib.D3.API.Mesh.MESH_TYPE_CURVE = 0x2; +GameLib.D3.API.Mesh.MESH_TYPE_SPHERE = 0x3; +GameLib.D3.API.Mesh.MESH_TYPE_PLANE = 0x4; +GameLib.D3.API.Mesh.MESH_TYPE_BOX = 0x5; +GameLib.D3.API.Mesh.MESH_TYPE_CYLINDER = 0x6; +GameLib.D3.API.Mesh.MESH_TYPE_TEXT = 0x7; +GameLib.D3.API.Mesh.MESH_TYPE_LINE = 0x8; + /** * Returns an API Mesh from an Object mesh * @param objectMesh @@ -255,10 +299,10 @@ GameLib.D3.API.Mesh.FromObject = function (objectMesh){ apiScale, apiUp, apiModelMatrix, - objectMesh.parentEntity, objectMesh.renderOrder, objectMesh.isBufferMesh, objectMesh.useQuaternion, - objectMesh.visible + objectMesh.visible, + objectMesh.parentEntity ); }; diff --git a/src/game-lib-d3-api-particle-engine.js b/src/game-lib-d3-api-particle-engine.js index f86680e..d810247 100644 --- a/src/game-lib-d3-api-particle-engine.js +++ b/src/game-lib-d3-api-particle-engine.js @@ -84,10 +84,11 @@ GameLib.D3.API.ParticleEngine = function( } this.pulse = pulse; - if (GameLib.Utils.UndefinedOrNull(parentEntity)) { - parentEntity = null; - } - this.parentEntity = parentEntity; + GameLib.API.Component.call( + this, + GameLib.Component.PARTICLE_ENGINE, + parentEntity + ); }; GameLib.D3.API.ParticleEngine.prototype = Object.create(GameLib.Component.prototype); diff --git a/src/game-lib-d3-api-particle.js b/src/game-lib-d3-api-particle.js index 449deec..d4a4039 100644 --- a/src/game-lib-d3-api-particle.js +++ b/src/game-lib-d3-api-particle.js @@ -161,10 +161,11 @@ GameLib.D3.API.Particle = function( } this.parentEngine = parentEngine; - if (GameLib.Utils.UndefinedOrNull(parentEntity)) { - parentEntity = null; - } - this.parentEntity = parentEntity; + GameLib.API.Component.call( + this, + GameLib.Component.PARTICLE, + parentEntity + ); }; GameLib.D3.API.Particle.prototype = Object.create(GameLib.Component.prototype); diff --git a/src/game-lib-d3-api-pass.js b/src/game-lib-d3-api-pass.js index a99d920..1cbabe1 100644 --- a/src/game-lib-d3-api-pass.js +++ b/src/game-lib-d3-api-pass.js @@ -57,10 +57,11 @@ GameLib.D3.API.Pass = function ( } this.renderToScreen = renderToScreen; - if (GameLib.Utils.UndefinedOrNull(parentEntity)) { - parentEntity = null; - } - this.parentEntity = parentEntity; + GameLib.API.Component.call( + this, + GameLib.Component.PASS, + parentEntity + ); }; GameLib.D3.API.Pass.prototype = Object.create(GameLib.Component.prototype); diff --git a/src/game-lib-d3-api-physics-world.js b/src/game-lib-d3-api-physics-world.js index 677800c..cc2104a 100644 --- a/src/game-lib-d3-api-physics-world.js +++ b/src/game-lib-d3-api-physics-world.js @@ -8,6 +8,7 @@ * @param rigidBodies * @param contactMaterials * @param allowSleep + * @param defaultContactMaterial * @param parentEntity * @constructor */ @@ -78,10 +79,11 @@ GameLib.D3.API.PhysicsWorld = function( } this.defaultContactMaterial = defaultContactMaterial; - if (GameLib.Utils.UndefinedOrNull(parentEntity)) { - parentEntity = null; - } - this.parentEntity = parentEntity; + GameLib.API.Component.call( + this, + GameLib.Component.PHYSICS_WORLD, + parentEntity + ); }; GameLib.D3.API.PhysicsWorld.prototype = Object.create(GameLib.Component.prototype); diff --git a/src/game-lib-d3-api-raycast-vehicle.js b/src/game-lib-d3-api-raycast-vehicle.js index bc7c3b3..b618c7c 100644 --- a/src/game-lib-d3-api-raycast-vehicle.js +++ b/src/game-lib-d3-api-raycast-vehicle.js @@ -5,7 +5,7 @@ * @param chassis * @param wheels * @param raycastWheels - * @param parentWorld + * @param parentPhysicsWorld * @param parentEntity * @constructor */ @@ -15,7 +15,7 @@ GameLib.D3.API.RaycastVehicle = function( chassis, wheels, raycastWheels, - parentWorld, + parentPhysicsWorld, parentEntity ) { @@ -44,15 +44,16 @@ GameLib.D3.API.RaycastVehicle = function( } this.raycastWheels = raycastWheels; - if (GameLib.Utils.UndefinedOrNull(parentWorld)) { - parentWorld = null; + if (GameLib.Utils.UndefinedOrNull(parentPhysicsWorld)) { + parentPhysicsWorld = null; } - this.parentWorld = parentWorld; + this.parentPhysicsWorld = parentPhysicsWorld; - if (GameLib.Utils.UndefinedOrNull(parentEntity)) { - parentEntity = null; - } - this.parentEntity = parentEntity; + GameLib.API.Component.call( + this, + GameLib.Component.RAYCAST_VEHICLE, + parentEntity + ); }; GameLib.D3.API.RaycastVehicle.prototype = Object.create(GameLib.Component.prototype); @@ -70,7 +71,7 @@ GameLib.D3.API.RaycastVehicle.FromObject = function(objectRaycastVehicle) { objectRaycastVehicle.chassis, objectRaycastVehicle.wheels, objectRaycastVehicle.raycastWheels, - objectRaycastVehicle.parentWorld, + objectRaycastVehicle.parentPhysicsWorld, objectRaycastVehicle.parentEntity ); }; diff --git a/src/game-lib-d3-api-raycast-wheel.js b/src/game-lib-d3-api-raycast-wheel.js index e814638..792d931 100644 --- a/src/game-lib-d3-api-raycast-wheel.js +++ b/src/game-lib-d3-api-raycast-wheel.js @@ -37,8 +37,8 @@ GameLib.D3.API.RaycastWheel = function( maxSuspensionTravel, customSlidingRotationalSpeed, useCustomSlidingRotationalSpeed, - parentEntity, - parentMesh + parentMesh, + parentEntity ) { if (GameLib.Utils.UndefinedOrNull(id)) { @@ -121,15 +121,16 @@ GameLib.D3.API.RaycastWheel = function( } this.useCustomSlidingRotationalSpeed = useCustomSlidingRotationalSpeed; - if (GameLib.Utils.UndefinedOrNull(parentEntity)) { - parentEntity = null; - } - this.parentEntity = parentEntity; - if (GameLib.Utils.UndefinedOrNull(parentMesh)) { parentMesh = null; } this.parentMesh = parentMesh; + + GameLib.API.Component.call( + this, + GameLib.Component.RAYCAST_WHEEL, + parentEntity + ); }; GameLib.D3.API.RaycastWheel.prototype = Object.create(GameLib.Component.prototype); @@ -158,8 +159,8 @@ GameLib.D3.API.RaycastWheel.FromObject = function(objectRaycastWheel) { objectRaycastWheel.maxSuspensionTravel, objectRaycastWheel.customSlidingRotationalSpeed, objectRaycastWheel.useCustomSlidingRotationalSpeed, - objectRaycastWheel.parentEntity, - objectRaycastWheel.parentMesh + objectRaycastWheel.parentMesh, + objectRaycastWheel.parentEntity ); }; diff --git a/src/game-lib-d3-api-raycaster.js b/src/game-lib-d3-api-raycaster.js index b953615..0b6f957 100644 --- a/src/game-lib-d3-api-raycaster.js +++ b/src/game-lib-d3-api-raycaster.js @@ -4,13 +4,15 @@ * @param name * @param position GameLib.API.Vector3 * @param direction GameLib.API.Vector3 + * @param parentEntity * @constructor */ GameLib.D3.API.Raycaster = function( id, name, position, - direction + direction, + parentEntity ) { if (GameLib.Utils.UndefinedOrNull(id)) { @@ -32,6 +34,12 @@ GameLib.D3.API.Raycaster = function( direction = new GameLib.API.Vector3(0, -1, 0); } this.direction = direction; + + GameLib.API.Component.call( + this, + GameLib.Component.RAYCASTER, + parentEntity + ); }; GameLib.D3.API.Raycaster.prototype = Object.create(GameLib.Component.prototype); @@ -47,6 +55,7 @@ GameLib.D3.API.Raycaster.FromObject = function(objectRaycaster) { objectRaycaster.id, objectRaycaster.name, GameLib.API.Vector3.FromObject(objectRaycaster.position), - GameLib.API.Vector3.FromObject(objectRaycaster.direction) + GameLib.API.Vector3.FromObject(objectRaycaster.direction), + objectRaycaster.parentEntity ); }; diff --git a/src/game-lib-d3-api-render-target.js b/src/game-lib-d3-api-render-target.js index 71640bf..d5862d9 100644 --- a/src/game-lib-d3-api-render-target.js +++ b/src/game-lib-d3-api-render-target.js @@ -1,12 +1,9 @@ /** - * This component renders a scene - * @param id String - * @param name String + * RenderTarget is used to render a scene to a target + * @param id + * @param name * @param width * @param height - * @param minFilter - * @param magFilter - * @param format * @param stencilBuffer * @param texture * @param parentEntity @@ -51,10 +48,11 @@ GameLib.D3.API.RenderTarget = function ( } this.texture = texture; - if (GameLib.Utils.UndefinedOrNull(parentEntity)) { - parentEntity = null; - } - this.parentEntity = parentEntity; + GameLib.API.Component.call( + this, + GameLib.Component.RENDER_TARGET, + parentEntity + ); }; diff --git a/src/game-lib-d3-api-renderer.js b/src/game-lib-d3-api-renderer.js index 2419453..2b31d7d 100644 --- a/src/game-lib-d3-api-renderer.js +++ b/src/game-lib-d3-api-renderer.js @@ -17,6 +17,7 @@ * @param bufferScene * @param bufferCamera * @param renderTarget + * @param sortObjects * @param defaultScene * @constructor */ @@ -135,10 +136,11 @@ GameLib.D3.API.Renderer = function ( } this.sortObjects = sortObjects; - if (GameLib.Utils.UndefinedOrNull(parentEntity)) { - parentEntity = null; - } - this.parentEntity = parentEntity; + GameLib.API.Component.call( + this, + GameLib.Component.RENDERER, + parentEntity + ); }; diff --git a/src/game-lib-d3-api-rigid-body.js b/src/game-lib-d3-api-rigid-body.js index 832cfc3..4a94872 100644 --- a/src/game-lib-d3-api-rigid-body.js +++ b/src/game-lib-d3-api-rigid-body.js @@ -19,7 +19,7 @@ * @param shapes * @param kinematic * @param parentMesh - * @param parentWorld + * @param parentPhysicsWorld * @param parentEntity * @constructor */ @@ -43,7 +43,7 @@ GameLib.D3.API.RigidBody = function( shapes, kinematic, parentMesh, - parentWorld, + parentPhysicsWorld, parentEntity ) { @@ -142,15 +142,16 @@ GameLib.D3.API.RigidBody = function( } this.parentMesh = parentMesh; - if (GameLib.Utils.UndefinedOrNull(parentWorld)) { - parentWorld = null; + if (GameLib.Utils.UndefinedOrNull(parentPhysicsWorld)) { + parentPhysicsWorld = null; } - this.parentWorld = parentWorld; + this.parentPhysicsWorld = parentPhysicsWorld; - if (GameLib.Utils.UndefinedOrNull(parentEntity)) { - parentEntity = null; - } - this.parentEntity = parentEntity; + GameLib.API.Component.call( + this, + GameLib.Component.RIGID_BODY, + parentEntity + ); }; GameLib.D3.API.RigidBody.prototype = Object.create(GameLib.Component.prototype); @@ -182,7 +183,7 @@ GameLib.D3.API.RigidBody.FromObject = function(objectRigidBody) { objectRigidBody.shapes, objectRigidBody.kinematic, objectRigidBody.parentMesh, - objectRigidBody.parentWorld, + objectRigidBody.parentPhysicsWorld, objectRigidBody.parentEntity ); }; diff --git a/src/game-lib-d3-api-scene.js b/src/game-lib-d3-api-scene.js index 6ef60e7..a864025 100644 --- a/src/game-lib-d3-api-scene.js +++ b/src/game-lib-d3-api-scene.js @@ -98,10 +98,11 @@ GameLib.D3.API.Scene = function( } this.gridColor = gridColor; - if (GameLib.Utils.UndefinedOrNull(parentEntity)) { - parentEntity = null; - } - this.parentEntity = parentEntity; + GameLib.API.Component.call( + this, + GameLib.Component.SCENE, + parentEntity + ); }; diff --git a/src/game-lib-d3-api-shape.js b/src/game-lib-d3-api-shape.js index ccc549a..490d6d5 100644 --- a/src/game-lib-d3-api-shape.js +++ b/src/game-lib-d3-api-shape.js @@ -2,6 +2,7 @@ * Raw Shape API object - should always correspond with the Shape Schema * @param id * @param name + * @param shapeType * @param boundingSphereRadius * @param collisionResponse * @param frictionMaterial @@ -12,6 +13,7 @@ GameLib.D3.API.Shape = function( id, name, + shapeType, boundingSphereRadius, collisionResponse, frictionMaterial, @@ -24,35 +26,40 @@ GameLib.D3.API.Shape = function( } this.id = id; + if (GameLib.Utils.UndefinedOrNull(shapeType)) { + shapeType = GameLib.D3.API.Shape.SHAPE_TYPE_NONE; + } + this.shapeType = shapeType; + if (GameLib.Utils.UndefinedOrNull(name)) { name = 'Shape (' + this.id + ')'; - if (this instanceof GameLib.D3.Shape.ConvexHull) { - name = 'Shape Convex Hull (' + this.id + ')'; - } - - if (this instanceof GameLib.D3.Shape.ConvexHull.Cylinder) { - name = 'Shape Convex Hull Cylinder (' + this.id + ')'; - } - - if (this instanceof GameLib.D3.Shape.HeightMap) { - name = 'Shape Heightmap (' + this.id + ')'; - } - - if (this instanceof GameLib.D3.Shape.Box) { + if (this.shapeType === GameLib.D3.API.Shape.SHAPE_TYPE_BOX) { name = 'Shape Box (' + this.id + ')'; } - if (this instanceof GameLib.D3.Shape.Plane) { + if (this.shapeType === GameLib.D3.API.Shape.SHAPE_TYPE_CONVEX_HULL) { + name = 'Shape Convex Hull (' + this.id + ')'; + } + + if (this.shapeType === GameLib.D3.API.Shape.SHAPE_TYPE_CONVEX_HULL_CYLINDER) { + name = 'Shape Convex Hull Cylinder (' + this.id + ')'; + } + + if (this.shapeType === GameLib.D3.API.Shape.SHAPE_TYPE_HEIGHT_MAP) { + name = 'Shape HeightMap (' + this.id + ')'; + } + + if (this.shapeType === GameLib.D3.API.Shape.SHAPE_TYPE_PLANE) { name = 'Shape Plane (' + this.id + ')'; } - if (this instanceof GameLib.D3.Shape.Sphere) { + if (this.shapeType === GameLib.D3.API.Shape.SHAPE_TYPE_SPHERE) { name = 'Shape Sphere (' + this.id + ')'; } - if (this instanceof GameLib.D3.Shape.TriMesh) { + if (this.shapeType === GameLib.D3.API.Shape.SHAPE_TYPE_TRIMESH) { name = 'Shape TriMesh (' + this.id + ')'; } } @@ -78,15 +85,55 @@ GameLib.D3.API.Shape = function( } this.parentMesh = parentMesh; - if (GameLib.Utils.UndefinedOrNull(parentEntity)) { - parentEntity = null; + var componentType = GameLib.Component.SHAPE; + + if (this.shapeType === GameLib.D3.API.Shape.SHAPE_TYPE_BOX) { + componentType = GameLib.Component.SHAPE_BOX; } - this.parentEntity = parentEntity; + + if (this.shapeType === GameLib.D3.API.Shape.SHAPE_TYPE_CONVEX_HULL) { + componentType = GameLib.Component.SHAPE_CONVEX_HULL; + } + + if (this.shapeType === GameLib.D3.API.Shape.SHAPE_TYPE_CONVEX_HULL_CYLINDER) { + componentType = GameLib.Component.SHAPE_CONVEX_HULL_CYLINDER; + } + + if (this.shapeType === GameLib.D3.API.Shape.SHAPE_TYPE_HEIGHT_MAP) { + componentType = GameLib.Component.SHAPE_HEIGHT_MAP; + } + + if (this.shapeType === GameLib.D3.API.Shape.SHAPE_TYPE_PLANE) { + componentType = GameLib.Component.SHAPE_PLANE; + } + + if (this.shapeType === GameLib.D3.API.Shape.SHAPE_TYPE_SPHERE) { + componentType = GameLib.Component.SHAPE_SPHERE; + } + + if (this.shapeType === GameLib.D3.API.Shape.SHAPE_TYPE_TRIMESH) { + componentType = GameLib.Component.SHAPE_TRI_MESH; + } + + GameLib.API.Component.call( + this, + componentType, + parentEntity + ); }; GameLib.D3.API.Shape.prototype = Object.create(GameLib.Component.prototype); GameLib.D3.API.Shape.prototype.constructor = GameLib.D3.API.Shape; +GameLib.D3.API.Shape.SHAPE_TYPE_NONE = 0x0; +GameLib.D3.API.Shape.SHAPE_TYPE_BOX = 0x1; +GameLib.D3.API.Shape.SHAPE_TYPE_CONVEX_HULL = 0x2; +GameLib.D3.API.Shape.SHAPE_TYPE_CONVEX_HULL_CYLINDER = 0x3; +GameLib.D3.API.Shape.SHAPE_TYPE_HEIGHT_MAP = 0x4; +GameLib.D3.API.Shape.SHAPE_TYPE_PLANE = 0x5; +GameLib.D3.API.Shape.SHAPE_TYPE_SPHERE = 0x6; +GameLib.D3.API.Shape.SHAPE_TYPE_TRIMESH = 0x7; + /** * Creates an API Shape from an Object Shape * @param objectShape @@ -96,6 +143,7 @@ GameLib.D3.API.Shape.FromObject = function(objectShape) { return new GameLib.D3.API.Shape( objectShape.id, objectShape.name, + objectShape.shapeType, objectShape.boundingSphereRadius, objectShape.collisionResponse, objectShape.frictionMaterial, diff --git a/src/game-lib-d3-api-skeleton.js b/src/game-lib-d3-api-skeleton.js index 7b723a4..0150c52 100644 --- a/src/game-lib-d3-api-skeleton.js +++ b/src/game-lib-d3-api-skeleton.js @@ -24,11 +24,6 @@ GameLib.D3.API.Skeleton = function ( boneTexture, parentEntity ) { - if (GameLib.Utils.UndefinedOrNull(parentEntity)) { - parentEntity = null; - } - this.parentEntity = parentEntity; - if (GameLib.Utils.UndefinedOrNull(id)) { id = GameLib.Utils.RandomId(); } @@ -82,6 +77,12 @@ GameLib.D3.API.Skeleton = function ( boneTexture = null; } this.boneTexture = boneTexture; + + GameLib.API.Component.call( + this, + GameLib.Component.SKELETON, + parentEntity + ); }; GameLib.D3.API.Skeleton.prototype = Object.create(GameLib.Component.prototype); diff --git a/src/game-lib-d3-api-solver.js b/src/game-lib-d3-api-solver.js index 0c2ecbd..f1778ac 100644 --- a/src/game-lib-d3-api-solver.js +++ b/src/game-lib-d3-api-solver.js @@ -28,7 +28,7 @@ GameLib.D3.API.Solver = function( this.name = name; if (GameLib.Utils.UndefinedOrNull(solverType)) { - solverType = GameLib.D3.Solver.GS_SOLVER; + solverType = GameLib.D3.API.Solver.GS_SOLVER; } this.solverType = solverType; @@ -42,15 +42,23 @@ GameLib.D3.API.Solver = function( } this.tolerance = tolerance; - if (GameLib.Utils.UndefinedOrNull(parentEntity)) { - parentEntity = null; - } - this.parentEntity = parentEntity; + GameLib.API.Component.call( + this, + GameLib.Component.SOLVER, + parentEntity + ); }; GameLib.D3.API.Solver.prototype = Object.create(GameLib.Component.prototype); GameLib.D3.API.Solver.prototype.constructor = GameLib.D3.API.Solver; +/** + * Solver Types + * @type {number} + */ +GameLib.D3.API.Solver.GS_SOLVER = 0x1; +GameLib.D3.API.Solver.SPLIT_SOLVER = 0x2; + /** * Creates an API Solver from an Object Solver * @param objectSolver diff --git a/src/game-lib-d3-api-spline.js b/src/game-lib-d3-api-spline.js index ffef0e2..4e87bdf 100644 --- a/src/game-lib-d3-api-spline.js +++ b/src/game-lib-d3-api-spline.js @@ -18,7 +18,7 @@ GameLib.D3.API.Spline = function( this.id = id; if (GameLib.Utils.UndefinedOrNull(name)) { - name = 'Spline (unknown)'; + name = 'Spline (' + this.id + ')'; } this.name = name; @@ -27,10 +27,11 @@ GameLib.D3.API.Spline = function( } this.vertices = vertices; - if (GameLib.Utils.UndefinedOrNull(parentEntity)) { - parentEntity = null; - } - this.parentEntity = parentEntity; + GameLib.API.Component.call( + this, + GameLib.Component.SPLINE, + parentEntity + ); }; GameLib.D3.API.Spline.prototype = Object.create(GameLib.Component.prototype); diff --git a/src/game-lib-d3-api-texture.js b/src/game-lib-d3-api-texture.js index df9a29e..8e5c612 100644 --- a/src/game-lib-d3-api-texture.js +++ b/src/game-lib-d3-api-texture.js @@ -1,7 +1,7 @@ /** * Raw Texture API object - should always correspond with the Texture Schema * @param id - * @param typeId + * @param textureType * @param name * @param image * @param images @@ -31,7 +31,7 @@ */ GameLib.D3.API.Texture = function( id, - typeId, + textureType, name, image, images, @@ -58,20 +58,16 @@ GameLib.D3.API.Texture = function( forward, parentEntity ) { - if (GameLib.Utils.UndefinedOrNull(parentEntity)) { - parentEntity = null; - } - this.parentEntity = parentEntity; if (GameLib.Utils.UndefinedOrNull(id)) { id = GameLib.Utils.RandomId(); } this.id = id; - if (GameLib.Utils.UndefinedOrNull(typeId)) { - typeId = GameLib.D3.Texture.TEXTURE_TYPE_NORMAL; + if (GameLib.Utils.UndefinedOrNull(textureType)) { + textureType = GameLib.D3.API.Texture.TEXTURE_TYPE_NORMAL; } - this.typeId = typeId; + this.textureType = textureType; if (GameLib.Utils.UndefinedOrNull(name)) { name = 'Texture (' + id + ')'; @@ -89,12 +85,12 @@ GameLib.D3.API.Texture = function( this.images = images; if (GameLib.Utils.UndefinedOrNull(wrapS)) { - wrapS = GameLib.D3.Texture.TYPE_REPEAT_WRAPPING; + wrapS = GameLib.D3.API.Texture.TYPE_REPEAT_WRAPPING; } this.wrapS = wrapS; if (GameLib.Utils.UndefinedOrNull(wrapT)) { - wrapT = GameLib.D3.Texture.TYPE_REPEAT_WRAPPING; + wrapT = GameLib.D3.API.Texture.TYPE_REPEAT_WRAPPING; } this.wrapT = wrapT; @@ -109,27 +105,27 @@ GameLib.D3.API.Texture = function( this.data = data; if (GameLib.Utils.UndefinedOrNull(format)) { - format = GameLib.D3.Texture.TYPE_RGBA_FORMAT; + format = GameLib.D3.API.Texture.TYPE_RGBA_FORMAT; } this.format = format; if (GameLib.Utils.UndefinedOrNull(mapping)) { - mapping = GameLib.D3.Texture.TYPE_UV_MAPPING; + mapping = GameLib.D3.API.Texture.TYPE_UV_MAPPING; } this.mapping = mapping; if (GameLib.Utils.UndefinedOrNull(magFilter)) { - magFilter = GameLib.D3.Texture.TYPE_LINEAR_FILTER; + magFilter = GameLib.D3.API.Texture.TYPE_LINEAR_FILTER; } this.magFilter = magFilter; if (GameLib.Utils.UndefinedOrNull(minFilter)) { - minFilter = GameLib.D3.Texture.TYPE_LINEAR_MIPMAP_LINEAR_FILTER; + minFilter = GameLib.D3.API.Texture.TYPE_LINEAR_MIPMAP_LINEAR_FILTER; } this.minFilter = minFilter; if (GameLib.Utils.UndefinedOrNull(textureType)) { - textureType = GameLib.D3.Texture.TYPE_UNSIGNED_BYTE; + textureType = GameLib.D3.API.Texture.TYPE_UNSIGNED_BYTE; } this.textureType = textureType; @@ -169,7 +165,7 @@ GameLib.D3.API.Texture = function( this.premultiplyAlpha = premultiplyAlpha; if (GameLib.Utils.UndefinedOrNull(encoding)) { - encoding = GameLib.D3.Texture.TYPE_LINEAR_ENCODING; + encoding = GameLib.D3.API.Texture.TYPE_LINEAR_ENCODING; } this.encoding = encoding; @@ -194,11 +190,91 @@ GameLib.D3.API.Texture = function( this.forward = forward; this.needsUpdate = false; + + GameLib.API.Component.call( + this, + GameLib.Component.TEXTURE, + parentEntity + ); }; GameLib.D3.API.Texture.prototype = Object.create(GameLib.Component.prototype); GameLib.D3.API.Texture.prototype.constructor = GameLib.D3.API.Texture; +/** + * Texture Formats + * @type {number} + */ +GameLib.D3.API.Texture.TYPE_ALPHA_FORMAT = 1019; +GameLib.D3.API.Texture.TYPE_RGB_FORMAT = 1020; +GameLib.D3.API.Texture.TYPE_RGBA_FORMAT = 1021; +GameLib.D3.API.Texture.TYPE_LUMINANCE_FORMAT = 1022; +GameLib.D3.API.Texture.TYPE_LUMINANCE_ALPHA_FORMAT = 1023; +GameLib.D3.API.Texture.TYPE_DEPTH_FORMAT = 1026; + +/** + * Mapping modes + * @type {number} + */ +GameLib.D3.API.Texture.TYPE_UV_MAPPING = 300; +GameLib.D3.API.Texture.TYPE_CUBE_REFLECTION_MAPPING = 301; +GameLib.D3.API.Texture.TYPE_CUBE_REFRACTION_MAPPING = 302; +GameLib.D3.API.Texture.TYPE_EQUI_RECTANGULAR_REFLECTION_MAPPING = 303; +GameLib.D3.API.Texture.TYPE_EQUI_RECTANGULAR_REFRACTION_MAPPING = 304; +GameLib.D3.API.Texture.TYPE_SPHERICAL_REFLECTION_MAPPING = 305; +GameLib.D3.API.Texture.TYPE_CUBE_UV_REFLECTION_MAPPING = 306; +GameLib.D3.API.Texture.TYPE_CUBE_UV_REFRACTION_MAPPING = 307; + +/** + * Wrapping Modes + * @type {number} + */ +GameLib.D3.API.Texture.TYPE_REPEAT_WRAPPING = 1000; +GameLib.D3.API.Texture.TYPE_CLAMP_TO_EDGE_WRAPPING = 1001; +GameLib.D3.API.Texture.TYPE_MIRRORED_REPEAT_WRAPPING = 1002; + +/** + * Mipmap Filters + * @type {number} + */ +GameLib.D3.API.Texture.TYPE_NEAREST_FILTER = 1003; +GameLib.D3.API.Texture.TYPE_NEAREST_MIPMAP_NEAREST_FILTER = 1004; +GameLib.D3.API.Texture.TYPE_NEAREST_MIPMAP_LINEAR_FILTER = 1005; +GameLib.D3.API.Texture.TYPE_LINEAR_FILTER = 1006; +GameLib.D3.API.Texture.TYPE_LINEAR_MIPMAP_NEAREST_FILTER = 1007; +GameLib.D3.API.Texture.TYPE_LINEAR_MIPMAP_LINEAR_FILTER = 1008; + +/** + * Texture Data Types + * @type {number} + */ +GameLib.D3.API.Texture.TYPE_UNSIGNED_BYTE = 1009; +GameLib.D3.API.Texture.TYPE_BYTE = 1010; +GameLib.D3.API.Texture.TYPE_SHORT = 1011; +GameLib.D3.API.Texture.TYPE_UNSIGNED_SHORT = 1012; +GameLib.D3.API.Texture.TYPE_INT = 1013; +GameLib.D3.API.Texture.TYPE_UNSIGNED_INT = 1014; +GameLib.D3.API.Texture.TYPE_FLOAT = 1015; +GameLib.D3.API.Texture.TYPE_HALF_FLOAT = 1025; + +/** + * Encoding Modes + * @type {number} + */ +GameLib.D3.API.Texture.TYPE_LINEAR_ENCODING = 3000; // NO ENCODING AT ALL. +GameLib.D3.API.Texture.TYPE_SRGB_ENCODING = 3001; +GameLib.D3.API.Texture.TYPE_GAMMA_ENCODING = 3007; // USES GAMMA_FACTOR, FOR BACKWARDS COMPATIBILITY WITH WEBGLRENDERER.GAMMAINPUT/GAMMAOUTPUT +GameLib.D3.API.Texture.TYPE_RGBE_ENCODING = 3002; // AKA RADIANCE. +GameLib.D3.API.Texture.TYPE_LOG_LUV_ENCODING = 3003; +GameLib.D3.API.Texture.TYPE_RGBM7_ENCODING = 3004; +GameLib.D3.API.Texture.TYPE_RGBM16_ENCODING = 3005; +GameLib.D3.API.Texture.TYPE_RGBD_ENCODING = 3006; // MAXRANGE IS 256. + +GameLib.D3.API.Texture.TEXTURE_TYPE_NORMAL = 0x1; +GameLib.D3.API.Texture.TEXTURE_TYPE_CUBE = 0x2; +GameLib.D3.API.Texture.TEXTURE_TYPE_CANVAS = 0x3; + + /** * Creates an API texture from Object data * @param objectTexture @@ -207,7 +283,7 @@ GameLib.D3.API.Texture.prototype.constructor = GameLib.D3.API.Texture; GameLib.D3.API.Texture.FromObject = function(objectTexture) { return new GameLib.D3.API.Texture( objectTexture.id, - objectTexture.typeId, + objectTexture.textureType, objectTexture.name, objectTexture.image, objectTexture.images, diff --git a/src/game-lib-d3-api-viewport.js b/src/game-lib-d3-api-viewport.js index 75d05d4..ef46895 100644 --- a/src/game-lib-d3-api-viewport.js +++ b/src/game-lib-d3-api-viewport.js @@ -49,10 +49,11 @@ GameLib.D3.API.Viewport = function( } this.y = y; - if (GameLib.Utils.UndefinedOrNull(parentEntity)) { - parentEntity = null; - } - this.parentEntity = parentEntity; + GameLib.API.Component.call( + this, + GameLib.Component.VIEWPORT, + parentEntity + ); }; GameLib.D3.API.Viewport.prototype = Object.create(GameLib.Component.prototype); diff --git a/src/game-lib-d3-api-z-animation.js b/src/game-lib-d3-api-z-animation.js index d79286e..aba0978 100644 --- a/src/game-lib-d3-api-z-animation.js +++ b/src/game-lib-d3-api-z-animation.js @@ -43,7 +43,6 @@ GameLib.D3.Animation = function( GameLib.Component.call( this, - GameLib.Component.COMPONENT_ANIMATION, { 'meshes' : [GameLib.D3.Mesh] } diff --git a/src/game-lib-d3-audio.js b/src/game-lib-d3-audio.js index 6bbd711..f7051e2 100644 --- a/src/game-lib-d3-audio.js +++ b/src/game-lib-d3-audio.js @@ -42,7 +42,6 @@ GameLib.D3.Audio = function( GameLib.Component.call( this, - GameLib.Component.COMPONENT_AUDIO, { 'camera' : GameLib.D3.Camera } diff --git a/src/game-lib-d3-bone.js b/src/game-lib-d3-bone.js index a9b833b..e3073f7 100644 --- a/src/game-lib-d3-bone.js +++ b/src/game-lib-d3-bone.js @@ -28,7 +28,8 @@ GameLib.D3.Bone = function ( apiBone.position, apiBone.quaternion, apiBone.scale, - apiBone.up + apiBone.up, + apiBone.parentEntity ); this.position = new GameLib.Vector3( @@ -55,10 +56,7 @@ GameLib.D3.Bone = function ( this ); - GameLib.Component.call( - this, - GameLib.Component.COMPONENT_BONE - ); + GameLib.Component.call(this); }; GameLib.D3.Bone.prototype = Object.create(GameLib.D3.API.Bone.prototype); @@ -133,7 +131,8 @@ GameLib.D3.Bone.prototype.toApiObject = function() { this.position.toApiObject(), this.quaternion.toApiObject(), this.scale.toApiObject(), - this.up.toApiObject() + this.up.toApiObject(), + GameLib.Utils.IdOrNull(this.parentEntity) ); return apiBone; diff --git a/src/game-lib-d3-broadphase.js b/src/game-lib-d3-broadphase.js index 183cce2..f662841 100644 --- a/src/game-lib-d3-broadphase.js +++ b/src/game-lib-d3-broadphase.js @@ -28,10 +28,7 @@ GameLib.D3.Broadphase = function ( apiBroadphase.parentEntity ); - GameLib.Component.call( - this, - GameLib.Component.COMPONENT_BROADPHASE - ); + GameLib.Component.call(this); }; GameLib.D3.Broadphase.prototype = Object.create(GameLib.D3.API.Broadphase.prototype); diff --git a/src/game-lib-d3-camera.js b/src/game-lib-d3-camera.js index 215e41e..c82a8ac 100644 --- a/src/game-lib-d3-camera.js +++ b/src/game-lib-d3-camera.js @@ -40,9 +40,9 @@ GameLib.D3.Camera = function( apiCamera.offsetX, apiCamera.offsetY, apiCamera.quaternion, - apiCamera.parentEntity, apiCamera.eyeSeparation, - apiCamera.focalLength + apiCamera.focalLength, + apiCamera.parentEntity ); if (this.position instanceof GameLib.API.Vector3) { @@ -80,7 +80,7 @@ GameLib.D3.Camera = function( GameLib.Component.call( this, - GameLib.Component.COMPONENT_CAMERA + GameLib.Component.CAMERA ); } ; @@ -268,9 +268,9 @@ GameLib.D3.Camera.prototype.toApiObject = function() { this.offsetX, this.offsetY, this.quaternion.toApiObject(), - GameLib.Utils.IdOrNull(this.parentEntity), this.eyeSeparation, - this.focalLength + this.focalLength, + GameLib.Utils.IdOrNull(this.parentEntity) ); }; diff --git a/src/game-lib-d3-composer.js b/src/game-lib-d3-composer.js index 543df1e..f7df6f3 100644 --- a/src/game-lib-d3-composer.js +++ b/src/game-lib-d3-composer.js @@ -32,7 +32,6 @@ GameLib.D3.Composer = function ( GameLib.Component.call( this, - GameLib.Component.COMPONENT_COMPOSER, { 'renderer' : GameLib.D3.Renderer, 'renderTarget' : GameLib.D3.RenderTarget, diff --git a/src/game-lib-d3-fog.js b/src/game-lib-d3-fog.js index 993c48f..cfd0c5f 100644 --- a/src/game-lib-d3-fog.js +++ b/src/game-lib-d3-fog.js @@ -38,10 +38,7 @@ GameLib.D3.Fog = function ( this ); - GameLib.Component.call( - this, - GameLib.Component.COMPONENT_FOG - ); + GameLib.Component.call(this); }; GameLib.D3.Fog.prototype = Object.create(GameLib.D3.API.Fog.prototype); diff --git a/src/game-lib-d3-font.js b/src/game-lib-d3-font.js index 75fcb87..abf57cc 100644 --- a/src/game-lib-d3-font.js +++ b/src/game-lib-d3-font.js @@ -27,10 +27,7 @@ GameLib.D3.Font = function( apiFont.parentEntity ); - GameLib.Component.call( - this, - GameLib.Component.COMPONENT_FONT - ); + GameLib.Component.call(this); }; GameLib.D3.Font.prototype = Object.create(GameLib.D3.API.Font.prototype); diff --git a/src/game-lib-d3-friction-contact-material.js b/src/game-lib-d3-friction-contact-material.js index 3deb905..3cf9a57 100644 --- a/src/game-lib-d3-friction-contact-material.js +++ b/src/game-lib-d3-friction-contact-material.js @@ -36,7 +36,6 @@ GameLib.D3.FrictionContactMaterial = function ( GameLib.Component.call( this, - GameLib.Component.COMPONENT_FRICTION_CONTACT_MATERIAL, { materials : [GameLib.D3.FrictionMaterial] } diff --git a/src/game-lib-d3-friction-material.js b/src/game-lib-d3-friction-material.js index 24f8833..d5e19f7 100644 --- a/src/game-lib-d3-friction-material.js +++ b/src/game-lib-d3-friction-material.js @@ -29,10 +29,7 @@ GameLib.D3.FrictionMaterial = function ( apiFrictionMaterial.parentEntity ); - GameLib.Component.call( - this, - GameLib.Component.COMPONENT_FRICTION_MATERIAL - ); + GameLib.Component.call(this); }; GameLib.D3.FrictionMaterial.prototype = Object.create(GameLib.D3.API.FrictionMaterial.prototype); diff --git a/src/game-lib-d3-helper.js b/src/game-lib-d3-helper.js index 59db751..b95d469 100644 --- a/src/game-lib-d3-helper.js +++ b/src/game-lib-d3-helper.js @@ -41,7 +41,7 @@ GameLib.D3.Helper = function( if ( object instanceof GameLib.D3.Mesh && - object.meshType !== GameLib.D3.Mesh.MESH_TYPE_CURVE + object.meshType !== GameLib.D3.API.Mesh.MESH_TYPE_CURVE ) { helperType = GameLib.D3.Helper.HELPER_TYPE_EDGES; } @@ -77,7 +77,7 @@ GameLib.D3.Helper = function( */ // GameLib.Component.call( // this, - // GameLib.Component.COMPONENT_HELPER + // GameLib.Component.HELPER // ); }; diff --git a/src/game-lib-d3-light.js b/src/game-lib-d3-light.js index f85a46f..719b125 100644 --- a/src/game-lib-d3-light.js +++ b/src/game-lib-d3-light.js @@ -78,7 +78,6 @@ GameLib.D3.Light = function( GameLib.Component.call( this, - GameLib.Component.COMPONENT_LIGHT, { 'parentScene' : GameLib.D3.Scene } diff --git a/src/game-lib-d3-material.js b/src/game-lib-d3-material.js index 3db335e..9ae47a7 100644 --- a/src/game-lib-d3-material.js +++ b/src/game-lib-d3-material.js @@ -223,7 +223,6 @@ GameLib.D3.Material = function( GameLib.Component.call( this, - GameLib.Component.COMPONENT_MATERIAL, { 'alphaMap' : GameLib.D3.Texture, 'aoMap' : GameLib.D3.Texture, diff --git a/src/game-lib-d3-mesh-0.js b/src/game-lib-d3-mesh-0.js index f056f35..482647c 100644 --- a/src/game-lib-d3-mesh-0.js +++ b/src/game-lib-d3-mesh-0.js @@ -12,7 +12,9 @@ GameLib.D3.Mesh = function ( this.graphics.isNotThreeThrow(); if (GameLib.Utils.UndefinedOrNull(apiMesh)) { - apiMesh = {}; + apiMesh = { + meshType: GameLib.D3.API.Mesh.MESH_TYPE_NORMAL + }; } if (apiMesh instanceof GameLib.D3.Mesh) { @@ -38,11 +40,11 @@ GameLib.D3.Mesh = function ( apiMesh.scale, apiMesh.up, apiMesh.modelMatrix, - apiMesh.parentEntity, apiMesh.renderOrder, apiMesh.isBufferMesh, apiMesh.useQuaternion, - apiMesh.visible + apiMesh.visible, + apiMesh.parentEntity ); this.faces = this.faces.map( @@ -136,30 +138,7 @@ GameLib.D3.Mesh = function ( 'skeleton' : GameLib.D3.Skeleton }; - var componentType = GameLib.Component.COMPONENT_MESH; - - if (this.meshType === GameLib.D3.Mesh.MESH_TYPE_PLANE) { - componentType = GameLib.Component.COMPONENT_MESH_PLANE - } - - if (this.meshType === GameLib.D3.Mesh.MESH_TYPE_BOX) { - componentType = GameLib.Component.COMPONENT_MESH_BOX - } - - if (this.meshType === GameLib.D3.Mesh.MESH_TYPE_CYLINDER) { - componentType = GameLib.Component.COMPONENT_MESH_CYLINDER - } - - if (this.meshType === GameLib.D3.Mesh.MESH_TYPE_SPHERE) { - componentType = GameLib.Component.COMPONENT_MESH_SPHERE - } - - if (this.meshType === GameLib.D3.Mesh.MESH_TYPE_LINE) { - componentType = GameLib.Component.COMPONENT_MESH_LINE - } - - if (this.meshType === GameLib.D3.Mesh.MESH_TYPE_TEXT) { - componentType = GameLib.Component.COMPONENT_MESH_TEXT; + if (this.meshType === GameLib.D3.API.Mesh.MESH_TYPE_TEXT) { linkedObjects.font = GameLib.D3.Font; } @@ -173,7 +152,6 @@ GameLib.D3.Mesh = function ( GameLib.Component.call( this, - componentType, linkedObjects ); }; @@ -181,20 +159,6 @@ GameLib.D3.Mesh = function ( GameLib.D3.Mesh.prototype = Object.create(GameLib.D3.API.Mesh.prototype); GameLib.D3.Mesh.prototype.constructor = GameLib.D3.Mesh; -/** - * Mesh Type - * @type {number} - */ -GameLib.D3.Mesh.MESH_TYPE_NORMAL = 0x0; -GameLib.D3.Mesh.MESH_TYPE_SKINNED = 0x1; -GameLib.D3.Mesh.MESH_TYPE_CURVE = 0x2; -GameLib.D3.Mesh.MESH_TYPE_SPHERE = 0x3; -GameLib.D3.Mesh.MESH_TYPE_PLANE = 0x4; -GameLib.D3.Mesh.MESH_TYPE_BOX = 0x5; -GameLib.D3.Mesh.MESH_TYPE_CYLINDER = 0x6; -GameLib.D3.Mesh.MESH_TYPE_TEXT = 0x7; -GameLib.D3.Mesh.MESH_TYPE_LINE = 0x8; - GameLib.D3.Mesh.prototype.lookAt = function(vector) { this.instance.lookAt( @@ -1084,11 +1048,11 @@ GameLib.D3.Mesh.prototype.toApiObject = function() { this.scale.toApiObject(), this.up.toApiObject(), this.modelMatrix.toApiObject(), - GameLib.Utils.IdOrNull(this.parentEntity), this.renderOrder, this.isBufferMesh, this.useQuaternion, - this.visible + this.visible, + GameLib.Utils.IdOrNull(this.parentEntity) ); return apiMesh; @@ -1408,7 +1372,7 @@ GameLib.D3.Mesh.prototype.getChildrenComponents = function() { /** * Push RigidBodies */ - var rigidBodies = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.RigidBody); + var rigidBodies = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.RIGID_BODY); rigidBodies.map( function(rigidBody) { @@ -1422,7 +1386,7 @@ GameLib.D3.Mesh.prototype.getChildrenComponents = function() { /** * Push Shapes */ - var shapes = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Shape); + var shapes = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.SHAPE); shapes.map( function(shape) { diff --git a/src/game-lib-d3-mesh-box.js b/src/game-lib-d3-mesh-box.js index 06e0aca..4929afd 100644 --- a/src/game-lib-d3-mesh-box.js +++ b/src/game-lib-d3-mesh-box.js @@ -18,15 +18,15 @@ GameLib.D3.Mesh.Box = function ( this.graphics.isNotThreeThrow(); if (GameLib.Utils.UndefinedOrNull(apiMesh)) { - apiMesh = {}; + apiMesh = { + meshType: GameLib.D3.API.Mesh.MESH_TYPE_BOX + }; } if (apiMesh instanceof GameLib.D3.Mesh.Box) { return apiMesh; } - apiMesh.meshType = GameLib.D3.Mesh.MESH_TYPE_BOX; - if (GameLib.Utils.UndefinedOrNull(width)) { width = 1; } diff --git a/src/game-lib-d3-mesh-curve.js b/src/game-lib-d3-mesh-curve.js index 517c701..63ed564 100644 --- a/src/game-lib-d3-mesh-curve.js +++ b/src/game-lib-d3-mesh-curve.js @@ -11,6 +11,16 @@ GameLib.D3.Mesh.Curve = function ( this.graphics = graphics; this.graphics.isNotThreeThrow(); + if (GameLib.Utils.UndefinedOrNull(apiMesh)) { + apiMesh = { + meshType: GameLib.D3.API.Mesh.MESH_TYPE_CURVE + }; + } + + if (apiMesh instanceof GameLib.D3.Mesh.Curve) { + return apiMesh; + } + GameLib.D3.Mesh.call( this, this.graphics, diff --git a/src/game-lib-d3-mesh-cylinder.js b/src/game-lib-d3-mesh-cylinder.js index 0f801bc..d46c8fb 100644 --- a/src/game-lib-d3-mesh-cylinder.js +++ b/src/game-lib-d3-mesh-cylinder.js @@ -29,15 +29,15 @@ GameLib.D3.Mesh.Cylinder = function ( if (GameLib.Utils.UndefinedOrNull(apiMesh)) { - apiMesh = {}; + apiMesh = { + meshType: GameLib.D3.API.Mesh.MESH_TYPE_CYLINDER + }; } - if (apiMesh instanceof GameLib.D3.Mesh.Box) { + if (apiMesh instanceof GameLib.D3.Mesh.Cylinder) { return apiMesh; } - apiMesh.meshType = GameLib.D3.Mesh.MESH_TYPE_CYLINDER; - if (GameLib.Utils.UndefinedOrNull(radiusTop)) { radiusTop = 1; } diff --git a/src/game-lib-d3-mesh-line.js b/src/game-lib-d3-mesh-line.js index 84e03f9..2690f17 100644 --- a/src/game-lib-d3-mesh-line.js +++ b/src/game-lib-d3-mesh-line.js @@ -14,15 +14,15 @@ GameLib.D3.Mesh.Line = function ( this.graphics.isNotThreeThrow(); if (GameLib.Utils.UndefinedOrNull(apiMesh)) { - apiMesh = {}; + apiMesh = { + meshType: GameLib.D3.API.Mesh.MESH_TYPE_LINE + }; } if (apiMesh instanceof GameLib.D3.Mesh.Line) { return apiMesh; } - apiMesh.meshType = GameLib.D3.Mesh.MESH_TYPE_LINE; - if (GameLib.Utils.UndefinedOrNull(lineWidth)) { lineWidth = 1; } diff --git a/src/game-lib-d3-mesh-plane.js b/src/game-lib-d3-mesh-plane.js index b43ba50..e253ccf 100644 --- a/src/game-lib-d3-mesh-plane.js +++ b/src/game-lib-d3-mesh-plane.js @@ -28,15 +28,15 @@ GameLib.D3.Mesh.Plane = function ( this.graphics.isNotThreeThrow(); if (GameLib.Utils.UndefinedOrNull(apiMesh)) { - apiMesh = {}; + apiMesh = { + meshType: GameLib.D3.API.Mesh.MESH_TYPE_PLANE + }; } - if (apiMesh instanceof GameLib.D3.Mesh.Box) { + if (apiMesh instanceof GameLib.D3.Mesh.Plane) { return apiMesh; } - apiMesh.meshType = GameLib.D3.Mesh.MESH_TYPE_PLANE; - if (GameLib.Utils.UndefinedOrNull(width)) { width = 1; } diff --git a/src/game-lib-d3-mesh-sphere.js b/src/game-lib-d3-mesh-sphere.js index aa37f71..d5c78aa 100644 --- a/src/game-lib-d3-mesh-sphere.js +++ b/src/game-lib-d3-mesh-sphere.js @@ -18,15 +18,15 @@ GameLib.D3.Mesh.Sphere = function ( this.graphics.isNotThreeThrow(); if (GameLib.Utils.UndefinedOrNull(apiMesh)) { - apiMesh = {}; + apiMesh = { + meshType: GameLib.D3.API.Mesh.MESH_TYPE_SPHERE + }; } - if (apiMesh instanceof GameLib.D3.Mesh.Box) { + if (apiMesh instanceof GameLib.D3.Mesh.Sphere) { return apiMesh; } - apiMesh.meshType = GameLib.D3.Mesh.MESH_TYPE_SPHERE; - if (GameLib.Utils.UndefinedOrNull(radius)) { radius = 1; } diff --git a/src/game-lib-d3-mesh-text.js b/src/game-lib-d3-mesh-text.js index 5bd36a4..d573a84 100644 --- a/src/game-lib-d3-mesh-text.js +++ b/src/game-lib-d3-mesh-text.js @@ -30,15 +30,15 @@ GameLib.D3.Mesh.Text = function ( this.graphics.isNotThreeThrow(); if (GameLib.Utils.UndefinedOrNull(apiMesh)) { - apiMesh = {}; + apiMesh = { + meshType : GameLib.D3.API.Mesh.MESH_TYPE_TEXT + }; } - if (apiMesh instanceof GameLib.D3.Mesh.Box) { + if (apiMesh instanceof GameLib.D3.Mesh.Text) { return apiMesh; } - apiMesh.meshType = GameLib.D3.Mesh.MESH_TYPE_TEXT; - if (GameLib.Utils.UndefinedOrNull(text)) { text = '-= 0) { console.log('ignoring multiple editor controls') } else { @@ -192,7 +192,7 @@ GameLib.System.Input.prototype.instanceCreated = function(data) { */ GameLib.System.Input.prototype.removeComponent = function(data) { - if (data.component instanceof GameLib.D3.Controls.Editor) { + if (data.component instanceof GameLib.Controls.D3.Editor) { var index = this.editorControls.indexOf(data.component); @@ -218,7 +218,7 @@ GameLib.System.Input.prototype.removeComponent = function(data) { */ GameLib.System.Input.prototype.delayedInstanceEncountered = function(data) { - if (data.component instanceof GameLib.D3.Controls.Editor) { + if (data.component instanceof GameLib.Controls.D3.Editor) { if (this.editorControls.length === 0) { /** @@ -756,7 +756,7 @@ GameLib.System.Input.prototype.onKeyDown = function(event) { if (event.code === 'Delete') { - meshes = GameLib.EntityManager.Instance.queryComponents([GameLib.D3.Mesh]); + meshes = GameLib.EntityManager.Instance.queryComponents([GameLib.Component.MESH]); var deletedMeshes = []; @@ -792,7 +792,7 @@ GameLib.System.Input.prototype.onKeyDown = function(event) { this.selectAll = !this.selectAll; - meshes = GameLib.EntityManager.Instance.queryComponents([GameLib.D3.Mesh]); + meshes = GameLib.EntityManager.Instance.queryComponents([GameLib.Component.MESH]); meshes.map(function(mesh){ if (this.selectAll) { @@ -884,7 +884,7 @@ GameLib.System.Input.prototype.onMouseDownEdit = function(event) { this.mouse.position.x = (event.offsetX / event.target.width ) * 2 - 1; this.mouse.position.y = -(event.offsetY / event.target.height) * 2 + 1; - var scenes = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Scene); + var scenes = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.SCENE); var intersects = scenes.reduce( @@ -1119,7 +1119,7 @@ GameLib.System.Input.prototype.deSelectMesh = function(mesh) { // event.stopPropagation(); // } // -// var meshes = entity.queryComponents(GameLib.D3.Mesh); +// var meshes = entity.queryComponents(GameLib.Component.MESH); // // var intersects = this.raycaster.getIntersectedObjects(meshes); // diff --git a/src/game-lib-system-linking.js b/src/game-lib-system-linking.js index bedd31f..b592aa8 100644 --- a/src/game-lib-system-linking.js +++ b/src/game-lib-system-linking.js @@ -35,7 +35,7 @@ GameLib.System.Linking = function( * Parents */ this.parentSceneChangeSubscription = null; - this.parentWorldChangeSubscription = null; + this.parentPhysicsWorldChangeSubscription = null; this.parentEntityChangeSubscription = null; /** @@ -103,7 +103,7 @@ GameLib.System.Linking.prototype.start = function() { this.onParentSceneChange ); - this.parentWorldChangeSubscription = this.subscribe( + this.parentPhysicsWorldChangeSubscription = this.subscribe( GameLib.Event.PARENT_WORLD_CHANGE, this.onParentWorldChange ); @@ -533,7 +533,7 @@ GameLib.System.Linking.prototype.removeComponent = function(data) { GameLib.System.Linking.prototype.imageChanged = function(data) { - var materials = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Material); + var materials = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.MATERIAL); materials.map(function(material){ @@ -584,7 +584,7 @@ GameLib.System.Linking.prototype.instanceCreated = function(data) { /** * Find all textures which use this image */ - GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Texture).map( + GameLib.EntityManager.Instance.queryComponents(GameLib.Component.TEXTURE).map( function(texture) { if (texture.image === data.component || texture.images.indexOf(data.component) !== -1 @@ -619,7 +619,7 @@ GameLib.System.Linking.prototype.instanceCreated = function(data) { data.component.parentScene && typeof data.component.parentScene === 'string' ) { - GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Scene).map( + GameLib.EntityManager.Instance.queryComponents(GameLib.Component.SCENE).map( function (scene) { if (data.component.parentScene === scene.id) { data.component.parentScene = scene; @@ -633,7 +633,7 @@ GameLib.System.Linking.prototype.instanceCreated = function(data) { data.component.parentEngine && typeof data.component.parentEngine === 'string' ) { - GameLib.EntityManager.Instance.queryComponents(GameLib.D3.ParticleEngine).map( + GameLib.EntityManager.Instance.queryComponents(GameLib.Component.PARTICLE_ENGINE).map( function (particleEngine) { if (data.component.parentEngine === particleEngine.id) { data.component.parentEngine = particleEngine; @@ -679,7 +679,7 @@ GameLib.System.Linking.prototype.instanceCreated = function(data) { data.component.parentMesh && typeof data.component.parentMesh === 'string' ) { - GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Mesh).map( + GameLib.EntityManager.Instance.queryComponents(GameLib.Component.MESH).map( function (mesh) { if (data.component.parentMesh === mesh.id) { @@ -694,13 +694,13 @@ GameLib.System.Linking.prototype.instanceCreated = function(data) { } if ( - data.component.parentWorld && - typeof data.component.parentWorld === 'string' + data.component.parentPhysicsWorld && + typeof data.component.parentPhysicsWorld === 'string' ) { - GameLib.EntityManager.Instance.queryComponents(GameLib.D3.PhysicsWorld).map( + GameLib.EntityManager.Instance.queryComponents(GameLib.Component.PHYSICS_WORLD).map( function (world) { - if (data.component.parentWorld === world.id) { - data.component.parentWorld = world; + if (data.component.parentPhysicsWorld === world.id) { + data.component.parentPhysicsWorld = world; if (typeof data.component.instance.addToWorld === 'function') { data.component.instance.addToWorld(world.instance); @@ -715,7 +715,7 @@ GameLib.System.Linking.prototype.instanceCreated = function(data) { GameLib.System.Linking.prototype.materialTypeChanged = function(data) { - var meshes = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Mesh); + var meshes = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.MESH); meshes.map( function(mesh){ @@ -862,7 +862,7 @@ GameLib.System.Linking.prototype.removeMesh = function(data) { /** * Now, we want to get a list of all the meshes which we don't want to delete, and all their children */ - var meshes = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Mesh); + var meshes = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.MESH); meshes = meshes.filter(function(mesh){ return data.meshes.indexOf(mesh) === -1; }); @@ -919,7 +919,7 @@ GameLib.System.Linking.prototype.stop = function() { * Parents */ this.parentSceneChangeSubscription.remove(); - this.parentWorldChangeSubscription.remove(); + this.parentPhysicsWorldChangeSubscription.remove(); this.parentEntityChangeSubscription.remove(); /** diff --git a/src/game-lib-system-particle.js b/src/game-lib-system-particle.js index 7a91261..ebfd87e 100644 --- a/src/game-lib-system-particle.js +++ b/src/game-lib-system-particle.js @@ -37,7 +37,7 @@ GameLib.System.Particle.prototype.start = function() { GameLib.System.prototype.start.call(this); - this.particleEngines = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.ParticleEngine); + this.particleEngines = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.PARTICLE_ENGINE); this.instanceCreatedSubscription = GameLib.Event.Subscribe( GameLib.Event.INSTANCE_CREATED, diff --git a/src/game-lib-system-physics.js b/src/game-lib-system-physics.js index 00fcc00..d2b1889 100644 --- a/src/game-lib-system-physics.js +++ b/src/game-lib-system-physics.js @@ -34,10 +34,10 @@ GameLib.System.Physics.prototype.start = function() { GameLib.System.prototype.start.call(this); - this.worlds = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.PhysicsWorld); - // this.rigidBodies = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.RigidBody); - // this.wheels = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.RaycastWheel); - // this.vehicles = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.RaycastVehicle); + this.worlds = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.PHYSICS_WORLD); + // this.rigidBodies = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.RIGID_BODY); + // this.wheels = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.RAYCAST_WHEEL); + // this.vehicles = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.RAYCAST_VEHICLE); diff --git a/src/game-lib-system-render.js b/src/game-lib-system-render.js index 6d5e97b..84994f7 100644 --- a/src/game-lib-system-render.js +++ b/src/game-lib-system-render.js @@ -26,9 +26,9 @@ GameLib.System.Render.prototype.start = function() { GameLib.System.prototype.start.call(this); - this.renderers = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Renderer); + this.renderers = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.RENDERER); - this.statistics = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Stats); + this.statistics = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.STATS); this.instanceCreatedSubscription = GameLib.Event.Subscribe( GameLib.Event.INSTANCE_CREATED, @@ -58,7 +58,7 @@ GameLib.System.Render.prototype.instanceCreated = function(data) { this.renderers.push(data.component); } - if (data.component instanceof GameLib.D3.Stats) { + if (data.component instanceof GameLib.Stats) { console.log('new stats'); this.statistics.push(data.component); } diff --git a/src/game-lib-system-storage.js b/src/game-lib-system-storage.js index cb0e599..0a8987d 100644 --- a/src/game-lib-system-storage.js +++ b/src/game-lib-system-storage.js @@ -397,7 +397,7 @@ GameLib.System.Storage.prototype.loadComponent = function(apiUrl, toProcess, inc runtimeComponent.parentEntity && typeof runtimeComponent.parentEntity === 'string' ) { - GameLib.EntityManager.Instance.queryComponents(GameLib.Entity).map( + GameLib.EntityManager.Instance.queryComponents(GameLib.Component.ENTITY).map( function (entity) { if (runtimeComponent.parentEntity === entity.id) { runtimeComponent.parentEntity = entity; @@ -710,7 +710,7 @@ GameLib.System.Storage.prototype.fetchComponents = function(data, clientCallback */ GameLib.System.Storage.prototype.imageUploadComplete = function(data) { - var runtimeImages = GameLib.EntityManager.Instance.queryComponents(GameLib.Image); + var runtimeImages = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.IMAGE); /** * Process all images - we have to load them in addition to creating their runtime components @@ -855,7 +855,7 @@ GameLib.System.Storage.prototype.loadFont = function(data, callback, errorCallba }; -GameLib.System.Storage.prototype.loadImage = function(data) { +GameLib.System.Storage.prototype.loadImage = function(data, callback, errorCallback) { console.log('loading image : ' + data.image.name); @@ -909,9 +909,12 @@ GameLib.System.Storage.prototype.loadImage = function(data) { objectUrl = true; } } catch (error) { - /** - * Do Nothing - */ + if (errorCallback) { + errorCallback({ + result: 'failure', + message: 'invalid server response trying to download image ' + data.image.name + }); + } } var img = document.createElement('img'); @@ -922,9 +925,9 @@ GameLib.System.Storage.prototype.loadImage = function(data) { window.URL.revokeObjectURL(url); } - image.instance = img; - - image.createInstance(); + if (callback) { + callback(img); + } if (onLoaded) { onLoaded(image, data.createTexture); @@ -951,6 +954,11 @@ GameLib.System.Storage.prototype.loadImage = function(data) { xhr.onerror = function(error) { console.warn('image load failed for image ' + image.name); + + if (errorCallback) { + errorCallback(error); + } + if (onError) { onError(image, error) } @@ -961,6 +969,11 @@ GameLib.System.Storage.prototype.loadImage = function(data) { preflight.onerror = function(error) { console.warn('image pre-flight request failed for image ' + image.name); + + if (errorCallback) { + errorCallback(error); + } + if (onError) { onError(image, error); }