function GameLib(){}if("undefined"==typeof GameLib.D3&&(GameLib.D3=function(){}),"undefined"==typeof 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")}GameLib.D3.BoneWeight=function(e,t){this.boneIndex=e,this.weight=t},GameLib.D3.Bone=function(e,t,i,n,o,s,a,r,h,c){this.id=e,this.name=i,this.boneId=t,"undefined"==typeof n&&(n=[]),this.childBoneIds=n,"undefined"==typeof o&&(o=null),this.parentBoneId=o,"undefined"==typeof s&&(s=new GameLib.D3.Vector4),this.quaternion=s,"undefined"==typeof a&&(a=new GameLib.D3.Vector3(0,0,0)),this.position=a,"undefined"==typeof r&&(r=new GameLib.D3.Vector3(0,0,0)),this.rotation=r,"undefined"==typeof h&&(h=new GameLib.D3.Vector3(1,1,1)),this.scale=h,"undefined"==typeof c&&(c=new GameLib.D3.Vector3(0,1,0)),this.up=c},GameLib.D3.Broadphase=function(e,t,i,n){this.id=e,"undefined"==typeof t&&(t="broadphase-"+i),this.name=t,"undefined"==typeof i&&(i=GameLib.D3.Broadphase.BROADPHASE_TYPE_NAIVE),this.broadphaseType=i,this.engine=n,this.engine.isNotCannonThrow(),this.instance=this.createInstance()},GameLib.D3.Broadphase.prototype.createInstance=function(){var e=null;if(this.broadphaseType==GameLib.D3.Broadphase.BROADPHASE_TYPE_NAIVE)e=new this.engine.instance.NaiveBroadphase;else if(this.broadphaseType==GameLib.D3.Broadphase.BROADPHASE_TYPE_GRID)e=new this.engine.instance.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);e=new this.engine.instance.SAPBroadphase}return e},GameLib.D3.Broadphase.BROADPHASE_TYPE_NAIVE=1,GameLib.D3.Broadphase.BROADPHASE_TYPE_GRID=2,GameLib.D3.Broadphase.BROADPHASE_TYPE_SAP=3,GameLib.D3.Color=function(e,t,i,n){this.r=e,this.g=t,this.b=i,this.a=n},GameLib.D3.ComponentCamera=function(e,t){this.componentId=e||GameLib.D3.Tools.RandomId(),this.parentEntity=null,GameLib.D3.Utils.Extend(GameLib.D3.ComponentCamera,GameLib.D3.ComponentInterface),this.threeCamera=t},GameLib.D3.ComponentCamera.prototype.onLateUpdate=function(e,t){this.threeCamera.quaternion.copy(t.quaternion),this.threeCamera.position.copy(t.position)},GameLib.D3.ComponentColorFlash=function(e){this.componentId=e||GameLib.D3.Tools.RandomId(),this.parentEntity=null,GameLib.D3.Utils.Extend(GameLib.D3.ComponentColorFlash,GameLib.D3.ComponentInterface)},GameLib.D3.ComponentColorFlash.prototype.onUpdate=function(e,t){this.parentEntity.mesh.material.color=new THREE.Color(Math.random(),Math.random(),Math.random())},GameLib.D3.ComponentColorFlash.prototype.onSetParentEntity=function(e,t){t.mesh.material=new THREE.MeshBasicMaterial},GameLib.D3.ComponentFlyControls=function(e){this.componentId=e||GameLib.D3.Tools.RandomId(),this.parentEntity=null,GameLib.D3.Utils.Extend(GameLib.D3.ComponentFlyControls,GameLib.D3.ComponentInterface),this.pitch=0,this.yaw=0,this.canRotate=!1,this.moveSpeed=22.2,this.moveForward=!1,this.moveBackward=!1,this.moveLeft=!1,this.moveRight=!1,this.moveUp=!1,this.moveDown=!1},GameLib.D3.ComponentFlyControls.prototype.onUpdate=function(e,t){var i=new THREE.Euler(this.pitch,this.yaw,0,"YXZ"),n=(new THREE.Quaternion).setFromEuler(i);t.quaternion.x=n.x,t.quaternion.y=n.y,t.quaternion.z=n.z,t.quaternion.w=n.w;var o=new THREE.Vector3(0,0,-1);if(o=o.applyEuler(i).normalize(),this.moveForward?(t.position.x+=o.x*(e*this.moveSpeed),t.position.y+=o.y*(e*this.moveSpeed),t.position.z+=o.z*(e*this.moveSpeed)):this.moveBackward&&(t.position.x-=o.x*(e*this.moveSpeed),t.position.y-=o.y*(e*this.moveSpeed),t.position.z-=o.z*(e*this.moveSpeed)),this.moveLeft){var s=o.cross(new THREE.Vector3(0,1,0));t.position.x-=s.x*(e*this.moveSpeed),t.position.y-=s.y*(e*this.moveSpeed),t.position.z-=s.z*(e*this.moveSpeed)}else if(this.moveRight){var s=o.cross(new THREE.Vector3(0,1,0));t.position.x+=s.x*(e*this.moveSpeed),t.position.y+=s.y*(e*this.moveSpeed),t.position.z+=s.z*(e*this.moveSpeed)}this.moveUp?t.position.y+=e*this.moveSpeed:this.moveDown&&(t.position.y-=e*this.moveSpeed)},GameLib.D3.ComponentFlyControls.prototype.onSetParentEntity=function(e,t){var i=this,n="pointerLockElement"in document||"mozPointerLockElement"in document||"webkitPointerLockElement"in document,o=document.body;document.addEventListener("click",function(e){n&&(0==e.button?(i.canRotate=!0,o.requestPointerLock()):2==e.button&&(i.canRotate=!1,document.exitPointerLock()))}),n&&(o.requestPointerLock=o.requestPointerLock||o.mozRequestPointerLock||o.webkitRequestPointerLock,document.exitPointerLock=document.exitPointerLock||document.mozExitPointerLock||document.webkitExitPointerLock),document.addEventListener("mousemove",function(e){if(i.canRotate){var t=e.movementX||e.mozMovementX||e.webkitMovementX||0,n=e.movementY||e.mozMovementY||e.webkitMovementY||0;i.yaw-=.002*t,i.pitch-=.002*n}sys.mouseCoords.set(e.clientX/window.innerWidth*2-1,2*-(e.clientY/window.innerHeight)+1)},!1),document.addEventListener("keydown",function(e){switch(e.keyCode){case 87:i.moveForward=!0;break;case 65:i.moveLeft=!0;break;case 83:i.moveBackward=!0;break;case 68:i.moveRight=!0;break;case 32:i.moveUp=!0;break;case 16:i.moveDown=!0}},!1),document.addEventListener("keyup",function(e){switch(e.keyCode){case 38:case 87:i.moveForward=!1;break;case 37:case 65:i.moveLeft=!1;break;case 40:case 83:i.moveBackward=!1;break;case 39:case 68:i.moveRight=!1;break;case 32:i.moveUp=!1;break;case 16:i.moveDown=!1}},!1)},GameLib.D3.ComponentFollow=function(e,t,i,n){this.componentId=e||GameLib.D3.Tools.RandomId(),this.parentEntity=null,GameLib.D3.Utils.Extend(GameLib.D3.ComponentFollow,GameLib.D3.ComponentInterface),this.targetEntity=t,this.moveSpeed=2.5,GameLib.D3.Utils.UndefinedOrNull(i)&&(i=new GameLib.D3.Vector3(0,0,0)),this.targetOffset=i,this.minDistance=n||0},GameLib.D3.ComponentFollow.prototype.onUpdate=function(e,t){if(this.targetEntity){var i=(new THREE.Vector3).copy(this.targetEntity.position);i.x+=this.targetOffset.x,i.y+=this.targetOffset.y,i.z+=this.targetOffset.z,i.distanceTo(t.position)>this.minDistance&&(t.position=t.position.lerp(i,this.moveSpeed*e))}},GameLib.D3.ComponentInterface=function(e){this.componentId=e||GameLib.D3.Tools.RandomId(),this.parentEntity=null},GameLib.D3.ComponentInterface.prototype.setParentEntity=function(e,t){this.parentEntity=t,this.onSetParentEntity(e,t)},GameLib.D3.ComponentInterface.prototype.update=function(e,t){this.onUpdate(e,t)},GameLib.D3.ComponentInterface.prototype.lateUpdate=function(e,t){this.onLateUpdate(e,t)},GameLib.D3.ComponentInterface.prototype.register=function(e){this.onRegistered(e)},GameLib.D3.ComponentInterface.prototype.onUpdate=function(e,t){},GameLib.D3.ComponentInterface.prototype.onLateUpdate=function(e,t){},GameLib.D3.ComponentInterface.prototype.onRegistered=function(e){},GameLib.D3.ComponentInterface.prototype.onSetParentEntity=function(e,t){},GameLib.D3.ComponentLookAt=function(e,t,i){this.componentId=e||GameLib.D3.Tools.RandomId(),this.parentEntity=null,GameLib.D3.Utils.Extend(GameLib.D3.ComponentLookAt,GameLib.D3.ComponentInterface),this.targetEntity=t,this.targetOffset=i||new GameLib.D3.Vector3(0,0,0)},GameLib.D3.ComponentLookAt.prototype.onUpdate=function(e,t){if(this.targetEntity){var i=this.targetEntity.position,n=(new THREE.Matrix4).lookAt(new THREE.Vector3(t.position.x,t.position.y,t.position.z),new THREE.Vector3(i.x,i.y,i.z),new THREE.Vector3(0,1,0)),o=(new THREE.Quaternion).setFromRotationMatrix(n);this.parentEntity.quaternion.x=o.x,this.parentEntity.quaternion.y=o.y,this.parentEntity.quaternion.z=o.z,this.parentEntity.quaternion.w=o.w}},GameLib.D3.ComponentMeshPermutation=function(e,t,i,n){this.componentId=e||GameLib.D3.Tools.RandomId(),this.parentEntity=null,this.positionOffset=t||new GameLib.D3.Vector3(0,0,0),this.quaternionOffset=i||new GameLib.D3.Quaternion(0,0,0,1),this.scaleOffset=n||new GameLib.D3.Vector3(0,0,0),GameLib.D3.Utils.Extend(GameLib.D3.ComponentMeshPermutation,GameLib.D3.ComponentInterface)},GameLib.D3.ComponentMeshPermutation.prototype.onLateUpdate=function(e,t){if(t&&t.mesh){var i=new THREE.Quaternion;i.copy(t.mesh.quaternion);var n=i.clone(),o=new THREE.Vector3;o.copy(t.mesh.position);var s=new THREE.Quaternion;s.copy(this.quaternionOffset),i=i.multiply(s).normalize();var a=new THREE.Vector3;a.copy(this.positionOffset),o=o.add(a.applyQuaternion(n));var r=new THREE.Vector3;r.copy(t.mesh.scale);var h=new THREE.Vector3;h.copy(this.scaleOffset),r=r.add(h),t.mesh.position.copy(o),t.mesh.quaternion.copy(i),t.mesh.scale.copy(r)}},GameLib.D3.ComponentRaycastVehicleControls=function(e,t,i,n,o,s,a){this.componentId=e||GameLib.D3.Tools.RandomId(),this.parentEntity=null,this.raycastVehicleComponent=null,this.frontLWheelIndex=t||0,this.frontRWheelIndex=i||1,this.backLWheelIndex=n||2,this.backRWheelIndex=o||3,this.maxForce=s||400,this.steering=a||.5,GameLib.D3.Utils.Extend(GameLib.D3.ComponentRaycastVehicleControls,GameLib.D3.ComponentInterface)},GameLib.D3.ComponentRaycastVehicleControls.prototype.onSetParentEntity=function(e,t){if(console.log("Set parent!"),this.raycastVehicleComponent=t.getComponent(GameLib.D3.RaycastVehicle),this.raycastVehicleComponent){var i=this;document.addEventListener("keydown",function(e){73==e.keyCode?(i.raycastVehicleComponent.instance.applyEngineForce(-i.maxForce,i.backLWheelIndex),i.raycastVehicleComponent.instance.applyEngineForce(-i.maxForce,i.backRWheelIndex)):74==e.keyCode?(i.raycastVehicleComponent.instance.setSteeringValue(i.steering,i.frontLWheelIndex),i.raycastVehicleComponent.instance.setSteeringValue(i.steering,i.frontRWheelIndex)):75==e.keyCode?(i.raycastVehicleComponent.instance.applyEngineForce(i.maxForce,i.backLWheelIndex),i.raycastVehicleComponent.instance.applyEngineForce(i.maxForce,i.backRWheelIndex)):76==e.keyCode&&(i.raycastVehicleComponent.instance.setSteeringValue(-i.steering,i.frontLWheelIndex),i.raycastVehicleComponent.instance.setSteeringValue(-i.steering,i.frontRWheelIndex))},!1),document.addEventListener("keyup",function(e){73==e.keyCode?(i.raycastVehicleComponent.instance.applyEngineForce(0,i.backLWheelIndex),i.raycastVehicleComponent.instance.applyEngineForce(0,i.backRWheelIndex)):74==e.keyCode?(i.raycastVehicleComponent.instance.setSteeringValue(0,i.frontLWheelIndex),i.raycastVehicleComponent.instance.setSteeringValue(0,i.frontRWheelIndex)):75==e.keyCode?(i.raycastVehicleComponent.instance.applyEngineForce(0,i.backLWheelIndex),i.raycastVehicleComponent.instance.applyEngineForce(0,i.backRWheelIndex)):76==e.keyCode&&(i.raycastVehicleComponent.instance.setSteeringValue(0,i.frontLWheelIndex),i.raycastVehicleComponent.instance.setSteeringValue(0,i.frontRWheelIndex))},!1)}else console.warn("NO RAYCAST VEHICLE FOUND!")},GameLib.D3.Engine=function(e,t){this.engineType=e,this.instance=t},GameLib.D3.Engine.prototype.isCannon=function(){return this.engineType==GameLib.D3.Engine.ENGINE_TYPE_CANNON},GameLib.D3.Engine.prototype.isNotCannonThrow=function(){if(this.engineType!=GameLib.D3.Engine.ENGINE_TYPE_CANNON)throw console.warn("Only CANNON supported for this function"),new Error("Only CANNON supported for this function")},GameLib.D3.Engine.prototype.isAmmo=function(){return this.engineType==GameLib.D3.Engine.ENGINE_TYPE_AMMO},GameLib.D3.Engine.prototype.isGoblin=function(){return this.engineType==GameLib.D3.Engine.ENGINE_TYPE_GOBLIN},GameLib.D3.Engine.ENGINE_TYPE_CANNON=1,GameLib.D3.Engine.ENGINE_TYPE_AMMO=2,GameLib.D3.Engine.ENGINE_TYPE_GOBLIN=3,GameLib.D3.Entity=function(e,t,i,n,o){this.meshId=e,"undefined"==typeof t&&(t=[]),this.componentIds=t,this.parentScene=null,this.mesh=null,GameLib.D3.Utils.UndefinedOrNull(i)&&(i=new GameLib.D3.Vector3(0,0,0)),this.position=i,GameLib.D3.Utils.UndefinedOrNull(n)&&(n=new GameLib.D3.Vector4(0,0,0,1)),this.quaternion=n,GameLib.D3.Utils.UndefinedOrNull(o)&&(o=new GameLib.D3.Vector3(1,1,1)),this.scale=o},GameLib.D3.Entity.prototype.update=function(e){for(var t in this.componentIds){var i=this.componentIds[t],n=this.parentScene.componentIdToComponent[i];n&&n.onUpdate&&n.onUpdate(e,this)}this.mesh&&(this.mesh.position.set(this.position.x,this.position.y,this.position.z),this.mesh.quaternion.set(this.quaternion.x,this.quaternion.y,this.quaternion.z,this.quaternion.w),this.mesh.scale.set(this.scale.x,this.scale.y,this.scale.z)),this.onUpdate(e)},GameLib.D3.Entity.prototype.lateUpdate=function(e){for(var t in this.componentIds){var i=this.componentIds[t],n=this.parentScene.componentIdToComponent[i];n&&n.onLateUpdate&&n.onLateUpdate(e,this)}this.onLateUpdate(e)},GameLib.D3.Entity.prototype.register=function(e){this.parentScene=e,null!=this.meshId&&e.meshIdToMesh[this.meshId]&&(e.instance.add(e.meshIdToMesh[this.meshId]),this.mesh=e.meshIdToMesh[this.meshId]),this.onRegistered(e)},GameLib.D3.Entity.prototype.addComponentId=function(e){this.componentIds.push(e)},GameLib.D3.Entity.prototype.addComponent=function(e){this.parentScene.registerComponent(e),this.componentIds.push(e.componentId),e.setParentEntity&&"function"==typeof e.setParentEntity&&e.setParentEntity(this.parentScene,this)},GameLib.D3.Entity.prototype.getComponent=function(e){for(var t in this.componentIds){var i=this.componentIds[t],n=this.parentScene.componentIdToComponent[i];if(n instanceof e)return n}return null},GameLib.D3.Entity.prototype.onUpdate=function(e){},GameLib.D3.Entity.prototype.onLateUpdate=function(e){},GameLib.D3.Entity.prototype.onRegistered=function(e){},GameLib.D3.FlyControls=function(e,t,i){this.flySpeed=100,this.canvas=i,this.THREE=t,this.yaw=0,this.pitch=0,this.canRotate=!1,this.moveForward=!1,this.moveBackward=!1,this.moveLeft=!1,this.moveRight=!1,this.moveUp=!1,this.moveDown=!1,this.mouseUpCallback=this.onMouseUp.bind(this),this.mouseDownCallback=this.onMouseDown.bind(this),this.mouseMoveCallback=this.onMouseMove.bind(this),this.mouseWheelCallback=this.onMouseWheel.bind(this),this.keyDownCallback=this.onKeyDown.bind(this),this.keyUpCallback=this.onKeyUp.bind(this),this.camera=e,this.canvas.addEventListener("keydown",this.keyDownCallback,!1),this.canvas.addEventListener("keyup",this.keyUpCallback,!1),this.canvas.addEventListener("mousedown",this.mouseDownCallback,!1),this.canvas.addEventListener("mouseup",this.mouseUpCallback,!1),this.canvas.addEventListener("mousewheel",this.mouseWheelCallback,!1),this.havePointerLock="pointerLockElement"in document||"mozPointerLockElement"in document||"webkitPointerLockElement"in document,this.element=document.body,this.havePointerLock&&(this.element.requestPointerLock=this.element.requestPointerLock||this.element.mozRequestPointerLock||this.element.webkitRequestPointerLock,document.exitPointerLock=document.exitPointerLock||document.mozExitPointerLock||document.webkitExitPointerLock)},GameLib.D3.FlyControls.prototype.onMouseWheel=function(e){this.moveForward=!0,this.applyTranslation(.001*e.wheelDelta),e.preventDefault(),this.moveForward=!1},GameLib.D3.FlyControls.prototype.onMouseDown=function(e){1==e.button&&(this.canRotate=!0,this.canvas.addEventListener("mousemove",this.mouseMoveCallback,!1))},GameLib.D3.FlyControls.prototype.onMouseUp=function(e){1==e.button&&(this.canRotate=!1,this.canvas.removeEventListener("mousemove",this.mouseMoveCallback))},GameLib.D3.FlyControls.prototype.applyRotation=function(){this.camera.rotation.set(this.pitch,this.yaw,0,"YXZ")},GameLib.D3.FlyControls.prototype.applyTranslation=function(e){var t=new this.THREE.Vector3(0,0,-1),i=new this.THREE.Euler(0,0,0,"YXZ");i.set(this.pitch,this.yaw,0,"YXZ"),t=t.applyEuler(i);var n=t.normalize(),o=n.cross(new this.THREE.Vector3(0,1,0));this.moveForward?(this.camera.position.x+=n.x*(e*this.flySpeed),this.camera.position.y+=n.y*(e*this.flySpeed),this.camera.position.z+=n.z*(e*this.flySpeed)):this.moveBackward&&(this.camera.position.x-=n.x*(e*this.flySpeed),this.camera.position.y-=n.y*(e*this.flySpeed),this.camera.position.z-=n.z*(e*this.flySpeed)),this.moveLeft?(this.camera.position.x-=o.x*(e*this.flySpeed),this.camera.position.y-=o.y*(e*this.flySpeed),this.camera.position.z-=o.z*(e*this.flySpeed)):this.moveRight&&(this.camera.position.x+=o.x*(e*this.flySpeed),this.camera.position.y+=o.y*(e*this.flySpeed),this.camera.position.z+=o.z*(e*this.flySpeed)),this.moveUp?this.camera.position.y+=e*this.flySpeed:this.moveDown&&(this.camera.position.y-=e*this.flySpeed)},GameLib.D3.FlyControls.prototype.update=function(e){this.applyRotation(),this.applyTranslation(e)},GameLib.D3.FlyControls.prototype.onMouseMove=function(e){if(this.canRotate){var t=e.movementX||e.mozMovementX||e.webkitMovementX||0,i=e.movementY||e.mozMovementY||e.webkitMovementY||0;this.yaw-=.002*t,this.pitch-=.002*i}},GameLib.D3.FlyControls.prototype.onKeyDown=function(e){switch(e.keyCode){case 87:this.moveForward=!0;break;case 65:this.moveLeft=!0;break;case 83:this.moveBackward=!0;break;case 68:this.moveRight=!0;break;case 104:this.moveUp=!0;break;case 98:this.moveDown=!0}},GameLib.D3.FlyControls.prototype.onKeyUp=function(e){switch(e.keyCode){case 38:case 87:this.moveForward=!1;break;case 37:case 65:this.moveLeft=!1;break;case 40:case 83:this.moveBackward=!1;break;case 39:case 68:this.moveRight=!1;break;case 104:this.moveUp=!1;break;case 98:this.moveDown=!1}},GameLib.D3.Game=function(){this.scenes={}},GameLib.D3.Game.prototype.addScene=function(e,t){this.scenes[t]=e},GameLib.D3.Game.prototype.processPhysics=function(e){for(var t in this.scenes){var i=this.scenes[t];for(var n in i.worlds){var o=i.worlds[n];o.step(e)}}},GameLib.D3.Game.prototype.render=function(e,t,i){for(var n in this.scenes){var o=this.scenes[n];o.render(e,t,i)}},GameLib.D3.Game.prototype.update=function(e,t){for(var i in this.scenes){var n=this.scenes[i];for(var o in n.worlds){var s=n.worlds[o];s.step(t)}n.update(e),n.lateUpdate(e)}},GameLib.D3.Graphics=function(e,t){this.graphicsType=e,this.instance=t},GameLib.D3.Graphics.prototype.isThree=function(){return this.graphicsType==GameLib.D3.Graphics.GRAPHICS_TYPE_THREE},GameLib.D3.Graphics.prototype.isNotThreeThrow=function(){if(this.graphicsType!=GameLib.D3.Graphics.GRAPHICS_TYPE_THREE)throw console.warn("Only THREE supported for this function"),new Error("Only THREE supported for this function")},GameLib.D3.Graphics.GRAPHICS_TYPE_THREE=1,GameLib.D3.Heightmap=function(e,t,i,n,o){"undefined"==typeof e&&(e=0),this.sizeX=e,"undefined"==typeof t&&(t=0),this.sizeY=t,"undefined"==typeof i&&(i=[]),this.matrix=i,"undefined"==typeof n&&(n=10),this.elementSize=n,"undefined"==typeof o&&(o=15),this.elementSize=o},GameLib.D3.Heightmap.GenerateInstanceMesh=function(e,t,i){e.isNotThreeThrow(),i.isNotCannonThrow();for(var n=new e.instance.Geometry,o=new i.instance.Vec3,s=new i.instance.Vec3,a=new i.instance.Vec3,r=0;r0){var r=GameLib.D3.Texture.loadMaps(e,a,s,t,i,n);Q.all(r).then(function(){o.resolve(s)}).catch(function(e){console.log(e),o.reject(e)})}else o.resolve(s);return o.promise},GameLib.D3.Matrix3=function(e,t,i){this.identity(),e&&(this.rows[0]=e),t&&(this.rows[1]=t),i&&(this.rows[2]=i)},GameLib.D3.Matrix3.prototype.identity=function(){this.rows=[new GameLib.D3.Vector4(1,0,0),new GameLib.D3.Vector4(0,1,0),new GameLib.D3.Vector4(0,0,1)]},GameLib.D3.Matrix4=function(e,t,i,n){this.identity(),e&&(this.rows[0]=e),t&&(this.rows[1]=t),i&&(this.rows[2]=i),n&&(this.rows[3]=n)},GameLib.D3.Matrix4.prototype.rotationMatrixX=function(e){return this.identity(),this.rows[1]=new GameLib.D3.Vector4(0,Math.cos(e),-1*Math.sin(e),0),this.rows[2]=new GameLib.D3.Vector4(0,Math.sin(e),Math.cos(e),0),this},GameLib.D3.Matrix4.prototype.rotationMatrixY=function(e){return this.identity(),this.rows[0]=new GameLib.D3.Vector4(Math.cos(e),0,Math.sin(e),0),this.rows[2]=new GameLib.D3.Vector4(-1*Math.sin(e),0,Math.cos(e),0),this},GameLib.D3.Matrix4.prototype.rotationMatrixZ=function(e){return this.identity(),this.rows[0]=new GameLib.D3.Vector4(Math.cos(e),-1*Math.sin(e),0,0),this.rows[1]=new GameLib.D3.Vector4(Math.sin(e),Math.cos(e),0,0),this},GameLib.D3.Matrix4.prototype.rotateX=function(e,t){return this.identity(),this.rotationMatrixX(e),this.multiply(t)},GameLib.D3.Matrix4.prototype.rotateY=function(e,t){return this.identity(),this.rotationMatrixY(e),this.multiply(t)},GameLib.D3.Matrix4.prototype.rotateZ=function(e,t){return this.identity(),this.rotationMatrixZ(e),this.multiply(t)},GameLib.D3.Matrix4.prototype.multiply=function(e){return e instanceof GameLib.D3.Vector4?new GameLib.D3.Vector4(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.D3.Vector3?new GameLib.D3.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.D3.Matrix4.prototype.identity=function(){this.rows=[new GameLib.D3.Vector4(1,0,0,0),new GameLib.D3.Vector4(0,1,0,0),new GameLib.D3.Vector4(0,0,1,0),new GameLib.D3.Vector4(0,0,0,1)]},GameLib.D3.Matrix4.prototype.lookAt=function(e,t,i){var n=new GameLib.D3.Vector3(e.x,e.y,e.z),o=n.subtract(t).normalize();0===o.squared()&&(o.z=1);var s=i.cross(o).normalize();0===s.squared()&&(o.x+=1e-4,s=i.cross(o).normalize());var a=o.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=a.x,this.rows[1].y=a.y,this.rows[1].z=a.z,this.rows[2].x=o.x,this.rows[2].y=o.y,this.rows[2].z=o.z,this},GameLib.D3.Mesh=function(e,t,i,n,o,s,a,r,h,c,p,l,d,m,u,f,y,L,v){this.id=e,this.meshId=GameLib.D3.Tools.RandomId(),this.path=t,this.name=i,this.meshType=n,this.vertices=o,this.faces=s,"undefined"==typeof a&&(a=null),this.skeleton=a,"undefined"==typeof r&&(r=[]),this.faceVertexUvs=r,"undefined"==typeof h&&(h=[]),this.skinIndices=h,"undefined"==typeof c&&(c=[]),this.skinWeights=c,"undefined"==typeof p&&(p=[]),this.materials=p,"undefined"==typeof l&&(l=new GameLib.D3.Vector3(0,0,0)),this.position=l,"undefined"==typeof d&&new GameLib.D3.Vector4,this.quaternion=d,"undefined"==typeof m&&(m=new GameLib.D3.Vector3(0,0,0)),this.rotation=m,"undefined"==typeof u&&(u=new GameLib.D3.Vector3(1,1,1)),this.scale=u,"undefined"==typeof f&&(f=new GameLib.D3.Vector3(0,1,0)),this.up=f,this.physics=y,this.parentMeshId=L,this.parentSceneId=v},GameLib.D3.Mesh.TYPE_NORMAL=0,GameLib.D3.Mesh.TYPE_SKINNED=1,GameLib.D3.Mesh.createInstanceMesh=function(e,t,i,n){var o=null;if(e.meshType==GameLib.D3.Mesh.TYPE_NORMAL&&(o=new n.instance.Mesh(t,i)),e.meshType==GameLib.D3.Mesh.TYPE_SKINNED){for(var s=e.skeleton.bones,a=e.skinIndices,r=e.skinWeights,h=[],c=0;c0;){var a=o.pop();if(a.triangle.v0==a.edge.x&&a.triangle.v1==a.edge.y||a.triangle.v1==a.edge.x&&a.triangle.v2==a.edge.y||a.triangle.v2==a.edge.x&&a.triangle.v0==a.edge.y){var r=a.triangle.v1;a.triangle.v1=a.triangle.v2,a.triangle.v2=r;var h=a.triangle.v1uv;a.triangle.v1uv=a.triangle.v2uv,a.triangle.v2uv=h}s.push(a);for(var c=[new GameLib.D3.Vector2(a.triangle.v0,a.triangle.v1),new GameLib.D3.Vector2(a.triangle.v1,a.triangle.v2),new GameLib.D3.Vector2(a.triangle.v2,a.triangle.v0)],p=0;p9||console.log("The vertices are not in the right length : "+e.length);for(var i=[],n=new GameLib.D3.Vector4.Points,o=0;o0&&console.warn("Implement physics worlds code here");for(var h=[],c=0;c0},GameLib.D3.Vector3.normal=function(e,t,i){var n=t.copy(),o=i.copy();return n.subtract(e).cross(o.subtract(e))},GameLib.D3.Vector3.prototype.lookAt=function(e,t){var i=GameLib.D3.Matrix4.lookAt(this,e,t);this.multiply(i)},GameLib.D3.Vector3.prototype.translate=function(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this},GameLib.D3.Vector3.prototype.squared=function(){return this.x*this.x+this.y*this.y+this.z*this.z},GameLib.D3.Vector3.prototype.copy=function(){return new GameLib.D3.Vector3(this.x,this.y,this.z)},GameLib.D3.Vector3.prototype.multiply=function(e){if(e instanceof GameLib.D3.Vector3)this.x*=e.x,this.y*=e.y,this.z*=e.z;else{if(!(e instanceof GameLib.D3.Matrix4))throw console.log("functionality not implemented - please do this"),new Error("not implemented");var t=e.rows[0].x*this.x+e.rows[0].y*this.y+e.rows[0].z*this.z,i=e.rows[1].x*this.x+e.rows[1].y*this.y+e.rows[1].z*this.z,n=e.rows[2].x*this.x+e.rows[2].y*this.y+e.rows[2].z*this.z;this.x=t,this.y=i,this.z=n}return this},GameLib.D3.Vector3.prototype.dot=function(e){return this.x*e.x+this.y*e.y+this.z*e.z},GameLib.D3.Vector3.prototype.normalize=function(){var e=1e-6,t=this.squared();if(ts&&(s=h.x,n=t*e)}this.vectors=o;for(var c=(new GameLib.D3.Matrix4).rotationMatrixY(n),p=0;ps&&(s=h.y,n=t*e)}this.vectors=o;for(var c=(new GameLib.D3.Matrix4).rotationMatrixX(n),p=0;pn&&(n=this.vectors[a].x),this.vectors[a].y>o&&(o=this.vectors[a].y),this.vectors[a].z>s&&(s=this.vectors[a].z);return new GameLib.D3.Vector3(Math.abs(n-e),Math.abs(o-t),Math.abs(o-i))},GameLib.D3.Vector4.Points.prototype.average=function(){for(var e=0,t=0,i=0,n=0;n