r3-legacy/build/game-lib-min.js

14 lines
420 KiB
JavaScript
Raw Normal View History

2017-12-10 12:57:24 +01:00
function GameLib(){}var __DATE__="Sun Dec 10 2017 12:56:56 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_FETCHED=52,GameLib.Event.AUDIO_ENDED=53,GameLib.Event.COMPONENT_LINKED=54,GameLib.Event.DONE_SAVING=55,GameLib.Event.BEFORE_RENDER=56,GameLib.Event.AFTER_RENDER=57,GameLib.Event.ARRAY_ITEM_ADDED=58,GameLib.Event.INSTANCE_CREATED=59,GameLib.Event.VISUALIZE=60,GameLib.Event.STOP_VISUALIZE=61,GameLib.Event.FETCH_COMPONENT_TYPES=62,GameLib.Event.FETCH_COMPONENTS=63,GameLib.Event.GET_API_URL=64,GameLib.Event.GET_RUNTIME=65,GameLib.Event.PARENT_WORLD_CHANGE=66,GameLib.Event.ANIMATE=67,GameLib.Event.ANIMATION_COMPILE_SUCCESS=68,GameLib.Event.ANIMATION_COMPILE_FAILED=69,GameLib.Event.SAVING=70,GameLib.Event.GAME_OVER=71,GameLib.Event.GAME_START=72,GameLib.Event.TOUCH_START=73,GameLib.Event.TOUCH_END=74,GameLib.Event.TOUCH_MOVE=75,GameLib.Event.TOUCH_CANCEL=76,GameLib.Event.GET_REMOTE_API_URL=77,GameLib.Event.COMPONENT_TYPES_UPDATE=78,GameLib.Event.DELAYED_INSTANCE_ENCOUNTERED=79,GameLib.Event.CAST_SOURCE_CHANGED=80,GameLib.Event.ANIMATION_MESH_ADDED=81,GameLib.Event.ANIMATION_MESH_REMOVED=82,GameLib.Event.GET_SCENE=83,GameLib.Event.CUSTOM_CODE_WINDOW_RESIZE=84,GameLib.Event.LOAD_FONT=85,GameLib.Event.FONT_NOT_FOUND=86,GameLib.Event.STOP_ALL_AUDIO=87,GameLib.Event.REGISTER_DEPENDENCIES=88,GameLib.Event.GAME_LOADED=89,GameLib.Event.COMPONENT_UPDATE=90,GameLib.Event.LOAD_PROGRESS=91,GameLib.Event.ENTITY_LOADED=92,GameLib.Event.MOUSE_DOWN=93,GameLib.Event.MOUSE_MOVE=94,GameLib.Event.MOUSE_WHEEL=95,GameLib.Event.MOUSE_UP=96,GameLib.Event.PARTICLE_INSTANCE_UPDATED=97,GameLib
throw new Error("Unknown component type: "+e)},GameLib.Component.GetRuntimeName=function(e){return e===GameLib.Component.GRAPHICS_RUNTIME?"Graphics":e===GameLib.Component.PHYSICS_RUNTIME?"Physics":e===GameLib.Component.GUI_RUNTIME?"GUI":e===GameLib.Component.STATISTICS_RUNTIME?"Statistics":e===GameLib.Component.SOCKET_RUNTIME?"Sockets":e===GameLib.Component.CODER_RUNTIME?"Coder":"Default"},GameLib.Component.GetComponentName=function(e){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.ConstructFromObject(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=nu
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.source,t.sourceProperties,t.roomId,t.peerId,t.serverIp,t.port,t.parentEntity),this.connected=!1,GameLib.Component.call(this,{source:GameLib.Component})};GameLib.Cast.prototype=Object.create(GameLib.API.Cast.prototype),GameLib.Cast.prototype.constructor=GameLib.Cast,GameLib.Cast.prototype.createInstance=function(){this.instance=!0,GameLib.Component.prototype.createInstance.call(this)},GameLib.Cast.prototype.buildVectorSource=function(e,t,i){return 2===i?(e[t]={},e[t].x=!1,void(e[t].y=!1)):3===i?(e[t]={},e[t].x=!1,e[t].y=!1,void(e[t].y=!1)):4===i?(e[t]={},e[t].x=!1,e[t].y=!1,e[t].z=!1,void(e[t].w=!1)):void console.warn("unknown dimension : "+i)},GameLib.Cast.prototype.buildQuaternionSource=function(e,t){e[t]={},e[t].axis={},e[t].axis.x=!1,e[t].axis.y=!1,e[t].axis.z=!1,e[t].angle=!1,e[t].x=!1,e[t].y=!1,e[t].z=!1,e[t].w=!1},GameLib.Cast.prototype.updateInstance=function(e){"source"===e&&(null!==this.source?this.sourceProperties=Object.keys(this.source).reduce(function(e,t){return"function"==typeof this.source[t]?e:(e[t]=!1,e)}.bind(this),{}):this.sourceProperties={},GameLib.Event.Emit(GameLib.Event.CAST_SOURCE_CHANGED,{component:this})),"sourceProperties"===e&&console.log(this.sourceProperties)},GameLib.Cast.prototype.toApiObject=function(){return new GameLib.API.Cast(this.id,this.name,this.castType,GameLib.Utils.IdOrNull(this.source),this.sourceProperties,this.roomId,this.peerId,this.serverIp,this.port,GameLib.Utils.IdOrNull(this.parentEntity))},GameLib.Cast.FromObject=function(e,t){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.pr
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),th
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.typeId||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.storageType,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(
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.refr
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.upda
GameLib.D3.Mesh.Text.prototype.updateInstance=function(e){if(this.instance.userData.text!==this.text||this.instance.userData.font!==this.font||this.instance.userData.size!==this.size||this.instance.userData.height!==this.height||this.instance.userData.curveSegments!==this.curveSegments||this.instance.userData.bevelEnabled!==this.bevelEnabled||this.instance.userData.bevelThickness!==this.bevelThickness||this.instance.userData.bevelSize!==this.bevelSize||this.instance.userData.bevelSegments!==this.bevelSegments){this.instance.userData.text=this.text,this.instance.userData.font=this.font,this.instance.userData.size=this.size,this.instance.userData.height=this.height,this.instance.userData.curveSegments=this.curveSegments,this.instance.userData.bevelEnabled=this.bevelEnabled,this.instance.userData.bevelThickness=this.bevelThickness,this.instance.userData.bevelSize=this.bevelSize,this.instance.userData.bevelSegments=this.bevelSegments;var t=new THREE.TextGeometry(this.text,{font:this.font.instance,size:this.size,height:this.height,curveSegments:this.curveSegments,bevelEnabled:this.bevelEnabled,bevelThickness:this.bevelThickness,bevelSize:this.bevelSize,bevelSegments:this.bevelSegments});this.updateVerticesFromGeometryInstance(t),t=this.createInstanceGeometry(),this.instance.geometry=t}GameLib.D3.Mesh.prototype.updateInstance.call(this,e)},GameLib.D3.Mesh.Text.prototype.toApiObject=function(){var e=GameLib.D3.Mesh.prototype.toApiObject.call(this);return e.text=this.text,e.font=GameLib.Utils.IdOrNull(this.font),e.size=this.size,e.height=this.height,e.curveSegments=this.curveSegments,e.bevelEnabled=this.bevelEnabled,e.bevelThickness=this.bevelThickness,e.bevelSize=this.bevelSize,e.bevelSegments=this.bevelSegments,e},GameLib.D3.Mesh.Text.FromObject=function(e,t){var i=GameLib.D3.API.Mesh.FromObject(t);return new GameLib.D3.Mesh.Text(e,i,t.text,t.font,t.size,t.height,t.curveSegments,t.bevelEnabled,t.bevelThickness,t.bevelSize,t.bevelSegments)},GameLib.D3.ParticleEngine=function(e,t){if(this.graphics=e,this.graphics.isNotThreeThrow(),GameLib.Utils.UndefinedOrNull(t)&&(t={}),t instanceof GameLib.D3.ParticleEngine)return t;if(GameLib.D3.API.ParticleEngine.call(this,t.id,t.name,t.position,t.direction,t.enabled,t.templateParticle,t.particlesPerSecond,t.frequency,t.elapsed,t.camera,t.pulse,t.parentEntity),!(this.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.direction instanceof GameLib.API.Vector3))throw console.warn("direction not instance of API.Vector3"),new Error("direction not instance of API.Vector3");this.direction=new GameLib.Vector3(e,this.direction,this),this.camera instanceof GameLib.D3.API.Camera&&(this.camera=new GameLib.D3.Camera(e,this.camera)),this.templateParticle instanceof GameLib.D3.API.Particle&&(this.templateParticle=new GameLib.D3.Particle(e,this.templateParticle)),this.particles=[],this.disabledForRemoval=!1,GameLib.Component.call(this,{templateParticle:GameLib.D3.Particle,camera:GameLib.D3.Camera})},GameLib.D3.ParticleEngine.prototype=Object.create(GameLib.D3.API.ParticleEngine.prototype),GameLib.D3.ParticleEngine.prototype.constructor=GameLib.D3.ParticleEngine,GameLib.D3.ParticleEngine.prototype.createInstance=function(){this.instance=!0,GameLib.Component.prototype.createInstance.call(this)},GameLib.D3.ParticleEngine.prototype.updateInstance=function(e){"particlesPerSecond"===e&&(this.frequency=Number(1/this.particlesPerSecond)),"frequency"===e&&(this.particlesPerSecond=Math.round(1/this.frequency)),"position"===e&&(this.position.instance.x=this.position.x,this.position.instance.y=this.position.y,this.position.instance.z=this.position.z,this.templateParticle.mesh.position=this.position.clone(),this.templateParticle.mesh.updateInstance("position",!0)),"direction"===e&&(this.direction.instance.x=this.direction.x,this.direction.instance.y=this.direction.y,this.direction.instance.z=this.direction.z,this.templateParticle.direction=this.direction.cl
GameLib.D3.RenderTarget.prototype.toApiObject=function(){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.aut
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 instanc
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.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.pro
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.Component.GetComponentConstructor(a),o=GameLib.EntityManager.Instance.queryComponentsByConstructor(s).reduce(function(e,t){return e[t.name]=t,e},{none:null}),r=t.template,c=t.affected;e.add(r,i,o).listen().onChange(function(e){var t=null;"null"!==e&&(t=GameLib.EntityManager.Instance.findComponentById(e)),c.map(function(e){e[i]=t,"parentEntity"===i&&GameLib.Event.Emit(GameLib.Event.PARENT_ENTITY_CHANGE,{originalEntity:this.initialValue,newEntity:t,object:e}),"parentPhysicsWorld"===i&&GameLib.Event.Emit(GameLib.Event.PARENT_WORLD_CHANGE,{originalWorld:this.initialValue,newWorld:t,object:e}),"parentScene"===i&&GameLib.Event.Emit(GameLib.Event.PARENT_SCENE_CHANGE,{originalScene:this.initialValue,newScene:t,object:e})}.bind(this)),"parentEntity"===i&&GameLib.Event.Emit(GameLib.Event.BUILD_GUI,null),this.initialValue=t})},GameLib.System.GUI.prototype.buildArrayManagerControl=function(e,t,i){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.buildObjectControl=function(e,t,i){var n=t.template[i];null!==n&&"sourceProperties"===i&&Object.keys(n).map(function(a){e.add(n,a).name(i+"."+a).listen().onChange(function(e){t.affected.map(function(t){t.sourceProperties[a]=e,t.updateInstance("sourceProperties")})})})},GameLib.System.GUI.prototype.buildSelectControl=function(e,t,i){var n=null;if(t.template.linkedObjects&&t.template.linkedObjects[i]?n=t.template.linkedObjects[i]:t.template[i]&&(n=t.template[i].constructor),!n)return void console.log("cannot determine constructor");var a=t.template,s=GameLib.EntityManager.Instance.queryComponentsByConstructor(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.updateInstan
s=this.touches[e.changedTouches[0].identifier]):(a=this.touches[e.changedTouches[0].identifier],s=this.touches[e.changedTouches[1].identifier])),i&&i.left&&n&&n.right&&(r=!0),i&&i.right&&n&&n.left&&(o=!0),a&&a.up&&s&&s.down&&(c=!0),a&&a.down&&s&&s.up&&(m=!0),this.touches.event=e,this.touches.meta={inward:o,outward:r,pinch:c,zoom:m},this.sensitivityCounter>=this.touchSensitivity&&(this.sensitivityCounter=0,GameLib.Event.Emit(GameLib.Event.TOUCH_MOVE,this.touches))},GameLib.System.Input.prototype.onTouchCancel=function(e){this.sensitivityCounter=0;for(var t=0;t<e.changedTouches.length;t++)this.touches[e.changedTouches[t].identifier].cancelled=!0,this.touches[e.changedTouches[t].identifier].event=e,GameLib.Event.Emit(GameLib.Event.TOUCH_CANCEL,this.touches[e.changedTouches[t].identifier]),delete this.touches[e.changedTouches[t].identifier]},GameLib.System.Input.prototype.onTouchEnd=function(e){this.sensitivityCounter=0;for(var t=0;t<e.changedTouches.length;t++)this.touches[e.changedTouches[t].identifier].ended=!0,this.touches[e.changedTouches[t].identifier].event=e,GameLib.Event.Emit(GameLib.Event.TOUCH_END,this.touches[e.changedTouches[t].identifier]),delete this.touches[e.changedTouches[t].identifier]},GameLib.System.Input.prototype.onKeyDown=function(e){console.log("input system emitted keypress "+e.code),GameLib.Event.Emit(GameLib.Event.KEY_DOWN,{code:e.code});var t=null;if("Delete"===e.code){t=GameLib.EntityManager.Instance.queryComponentsByConstructor(GameLib.D3.Mesh);var i=[];t.map(function(e){if(e.selected){i.push(e),e.removeHelper();var t=e.parentScene;t.removeObject(e),t.buildIdToObject()}}.bind(this)),GameLib.Event.Emit(GameLib.Event.REMOVE_MESH,{meshes:i})}"ControlLeft"===e.code&&(this.controlLeft=!0),"KeyA"===e.code&&(this.selectAll=!this.selectAll,t=GameLib.EntityManager.Instance.queryComponentsByConstructor(GameLib.D3.Mesh),t.map(function(e){this.selectAll?this.selectMesh(e):this.deSelectMesh(e)}.bind(this)),GameLib.Event.Emit(GameLib.Event.BUILD_GUI,null)),"KeyP"===e.code&&GameLib.Event.Emit(GameLib.Event.GAME_PAUSE)},GameLib.System.Input.prototype.onKeyUp=function(e){GameLib.Event.Emit(GameLib.Event.KEY_UP,{code:e.code}),"ControlLeft"===e.code&&(this.controlLeft=!1)},GameLib.System.Input.prototype.onMouseDown=function(e){GameLib.Event.Emit(GameLib.Event.MOUSE_DOWN,{event:e})},GameLib.System.Input.prototype.onMouseMove=function(e){GameLib.Event.Emit(GameLib.Event.MOUSE_MOVE,{event:e})},GameLib.System.Input.prototype.onMouseWheel=function(e){GameLib.Event.Emit(GameLib.Event.MOUSE_WHEEL,{event:e})},GameLib.System.Input.prototype.onMouseUp=function(e){GameLib.Event.Emit(GameLib.Event.MOUSE_UP,{event:e})},GameLib.System.Input.prototype.onMouseDownEdit=function(e){2===e.button&&this.editorControls.map(function(t){if(!this.controlLeft){this.mouse.x=e.offsetX/e.target.width*2-1,this.mouse.y=-e.offsetY/e.target.height*2+1;var i=GameLib.EntityManager.Instance.queryComponents(GameLib.Component.SCENE),n=i.reduce(function(e,i){return t.raycaster.instance.setFromCamera(this.mouse,t.camera.instance),n=t.raycaster.getIntersectedObjects(i.meshes),n.map(function(t){e.push(t)}),e}.bind(this),[]);n.sort(function(e,t){return e.distance<t.distance?-1:e.distance>t.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
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){e.images.map(function(e){var t=GameLib.EntityManager.Instance.findComponentById(e.id);t?(t.updateFromRawObject(e),t.updateInstance("path")):GameLib.Component.ConstructFromObject(e)}.bind(this))},GameLib.System.Storage.prototype.processBlenderData=function(e){console.log("loading blender data"),e.images.map(function(e){var t=GameLib.Component.ConstructFromObject(e);GameLib.Event.Emit(GameLib.Event.COMPONENT_CREATED,{component:t})}.bind(this)),e.textures.map(function(e){var t=GameLib.Component.ConstructFromObject(e);GameLib.Event.Emit(GameLib.Event.COMPONENT_CREATED,{component:t})}.bind(this)),e.materials.map(function(e){var t=GameLib.Component.ConstructFromObject(e);GameLib.Event.Emit(GameLib.Event.COMPONENT_CREATED,{component:t})}.bind(this)),e.meshes.map(function(e){var t=GameLib.Component.ConstructFromObject(e);GameLib.Event.Emit(GameLib.Event.COMPONENT_CREATED,{component:t})}.bind(this))},GameLib.System.Storage.prototype.loadFont=function(e,t,i){console.log("loading font : "+e.font.name),this.publish(GameLib.Event.GET_API_URL,null,function(n){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+aJAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH4QoWEQMQBXD4hQAAABl0RVh0Q29tbWVudABDcmVhdGVkIHdpdGggR0lNUFeB