diff --git a/src/game-lib-a-0.js b/src/game-lib-a-0.js deleted file mode 100644 index f467345..0000000 --- a/src/game-lib-a-0.js +++ /dev/null @@ -1,59 +0,0 @@ -/** - * GameLib Namespace - */ -if (typeof GameLib === 'undefined') { - function GameLib() {} -} - -/** - * GameLib.D3 Namespace - */ -if (typeof GameLib.D3 === 'undefined') { - GameLib.D3 = function(){}; -} - -/** - * GameLib.D3.API Namespace - * @constructor - */ -if (typeof GameLib.D3.API === 'undefined') { - GameLib.D3.API = function(){}; -} - -/** - * GameLib.API Namespace - */ -if (typeof GameLib.API === 'undefined') { - GameLib.API = function(){}; -} - -/** - * GameLib.D3.Runtime Namespace - * @constructor - */ -if (typeof GameLib.D3.Runtime === 'undefined') { - GameLib.D3.Runtime = function(){}; -} - -// if (typeof Q === 'undefined') { -// -// if (typeof require === 'undefined') { -// console.warn('You need the Q promise library for the GameLib.D3'); -// throw new Error('You need the Q promise library for the GameLib.D3'); -// } -// -// var Q = require('q'); -// } -// -// if (typeof _ === 'undefined') { -// -// if (typeof require === 'undefined') { -// console.warn('You need the lodash library for the GameLib.D3'); -// throw new Error('You need the lodash library for the GameLib.D3'); -// } -// -// var _ = require('lodash'); -// } - -// This gets injected by gulp -console.log("Loading GameLib compiled at: " + __DATE__); diff --git a/src/game-lib-a-component-a.js b/src/game-lib-a-component-a.js deleted file mode 100644 index aedaafc..0000000 --- a/src/game-lib-a-component-a.js +++ /dev/null @@ -1,2003 +0,0 @@ -/** - * Component Interface - * @constructor - * @param linkedObjects - * @param delayed - */ -GameLib.Component = function( - linkedObjects, - delayed -) { - if (GameLib.Utils.UndefinedOrNull(linkedObjects)) { - linkedObjects = {}; - } - this.linkedObjects = linkedObjects; - this.linkedObjects.parentEntity = GameLib.Entity; - - this.idToObject = {}; - - this.selected = false; - - this.building = false; - - this.loaded = false; - - this.linked = false; - - this.cloneNumber = 0; - - this.isClone = false; - - this.generateNewImageIds = false; - - if (GameLib.Utils.UndefinedOrNull(delayed)) { - delayed = false; - } - this.delayed = delayed; - - this.dependencies = this.getDependencies(); - - GameLib.Event.Emit( - GameLib.Event.COMPONENT_REGISTER, - { - component : this - } - ); - - if (this.dependencies.length === 0) { - - this.performInstanceCreation(); - - } else { - GameLib.Event.Emit( - GameLib.Event.REGISTER_DEPENDENCIES, - { - component : this - } - ); - } - - -}; - -GameLib.Component.prototype = Object.create(GameLib.Event.prototype); -GameLib.Component.prototype.constructor = GameLib.Component; - -/** - * This function, performs standard instance creation steps for all our components, which means - * Ensure we have no dependencies - * Build a list of all child components - if they are all linked, we are ready to create an instance - * Ensure we are linked - * Ensure we are not delayed - * Try to create the instance - * Error Log if failed - * Don't do anything if we are not fully linked - */ -GameLib.Component.prototype.performInstanceCreation = function() { - - var dependencies = true; - - if (GameLib.Utils.UndefinedOrNull(this.dependencies)) { - dependencies = false; - } - - if (this.dependencies && this.dependencies instanceof Array && this.dependencies.length === 0) { - dependencies = false; - } - - if (dependencies) { - throw new Error('performInstanceCreation called while this object still has dependencies'); - } - - delete this.dependencies; - - /** - * Build ID to object should run through all sub components - - * if one is found which is not linked, this component is not linked fully - */ - this.buildIdToObject(); - - /** - * Don't try to create an instance of this object until it is fully linked - */ - if (this.linked) { - if (!this.delayed) { - try { - this.createInstance(); - } catch (error) { - console.error(error); - } - } else { - /** - * Some systems require an instance creation at an exact time, like System.Input for Edit Controls - - * we need to give them the opportunity to handle this situation - */ - GameLib.Event.Emit( - GameLib.Event.DELAYED_INSTANCE_ENCOUNTERED, - { - component : this - } - ) - } - } -}; - -GameLib.Component.prototype.createInstance = function() { - - // console.log('create instance : '+ this.name); - - /** - * When you do actually call 'createInstance' - it is wise to state we are no longer delayed - we assume the caller - * knows when to call createInstance, so we do the housekeeping here - * @type {boolean} - */ - this.delayed = false; - - if (this.instance) { - - this.loaded = true; - - GameLib.Event.Emit( - GameLib.Event.INSTANCE_CREATED, - { - component: this - } - ); - - GameLib.Event.Emit( - GameLib.Event.RESOLVE_DEPENDENCIES, - { - component: this - } - ); - } - - if (this instanceof GameLib.Entity) { - GameLib.Event.Emit( - GameLib.Event.ENTITY_LOADED, - { - entity:this - } - ) - } -}; - -/** - * Dependencies are everything which is either a string or an object with an id which is linked to this object - * @returns {Array} - */ -GameLib.Component.prototype.getDependencies = function() { - - var dependencies = []; - - for (var property in this.linkedObjects) { - - if ( - this.linkedObjects.hasOwnProperty(property) && - property.indexOf('parent') !== 0 && - this.hasOwnProperty(property) - ){ - if (typeof this[property] === 'string') { - GameLib.Utils.PushUnique(dependencies, this[property]); - } - - if (this[property] instanceof Array) { - this[property].map( - function(arrayProperty) { - - if (typeof arrayProperty === 'string') { - GameLib.Utils.PushUnique(dependencies, arrayProperty); - } - - if (arrayProperty && - arrayProperty instanceof GameLib.Component - ) { - GameLib.Utils.PushUnique(dependencies, arrayProperty.id); - } - } - ); - } - - if (this[property] && - this[property] instanceof GameLib.Component - ) { - GameLib.Utils.PushUnique(dependencies, this[property].id); - } - } - } - - return dependencies; -}; - -GameLib.Component.prototype.updateInstance = function(property) { - - if (property === 'parentEntity') { - - if (this.parentEntity instanceof GameLib.Entity) { - this.parentEntity.addComponent(this); - - this.buildIdToObject(); - - Object.keys(this.idToObject).map( - function(componentId) { - - if (this.id !== componentId) { - this.parentEntity.addComponent(this.idToObject[componentId]); - } - - }.bind(this) - ) - } - - } - -}; - -GameLib.Component.prototype.toString = function() { - return this.id; -}; - -GameLib.Component.SOCKET_RECEIVE = 0x1; -GameLib.Component.MATERIAL_STANDARD = 0x2; -GameLib.Component.RENDERER = 0x3; -GameLib.Component.SERVER = 0x4; -GameLib.Component.CAMERA_PERSPECTIVE = 0x5; -GameLib.Component.SOCKET = 0x6; -GameLib.Component.MESH = 0x7; -GameLib.Component.SPLINE = 0x8; -GameLib.Component.SHADOW_DIRECTIONAL = 0x9; -GameLib.Component.PLANE = 0xa; -GameLib.Component.COMPOSER = 0xb; -GameLib.Component.RENDER_TARGET = 0xc; -GameLib.Component.PASS_RENDER = 0xd; -GameLib.Component.SCENE = 0xe; -GameLib.Component.RAYCASTER = 0xf; -GameLib.Component.TEXT = 0x10; -GameLib.Component.FACE = 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_IMAGE = 0x19; -GameLib.Component.ENTITY_MANAGER = 0x1a; -GameLib.Component.DOM_ELEMENT = 0x1b; -GameLib.Component.SHADOW_SPOT = 0x1c; -GameLib.Component.STATS = 0x1d; -GameLib.Component.GUI = 0x1e; -GameLib.Component.IMAGE = 0x1f; -GameLib.Component.ENTITY = 0x20; -GameLib.Component.OBJECT = 0x21; -GameLib.Component.RENDERER_D2 = 0x22; -GameLib.Component.RENDERER_D3 = 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.GRAPHICS_THREE = 0x3b; -GameLib.Component.FONT = 0x3c; -GameLib.Component.CANVAS = 0x3d; -GameLib.Component.BONE = 0x3e; -GameLib.Component.GRAPHICS_IMPACT = 0x3f; -GameLib.Component.CONTROLS_FIRST_PERSON = 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.LIGHT_AMBIENT = 0x4a; -GameLib.Component.LIGHT_DIRECTIONAL = 0x4b; -GameLib.Component.LIGHT_HEMISPHERE = 0x4c; -GameLib.Component.LIGHT_POINT = 0x4d; -GameLib.Component.LIGHT_RECT_AREA = 0x4e; -GameLib.Component.LIGHT_SPOT = 0x4f; -GameLib.Component.FOG = 0x50; -GameLib.Component.CONTROLS_ORBIT = 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.SOCKET_CAST = 0x57; -GameLib.Component.CAMERA_ORTHOGRAPHIC = 0x58; -GameLib.Component.CAMERA_STEREO = 0x59; -GameLib.Component.CAMERA_CUBE = 0x5a; -GameLib.Component.SHADOW = 0x5b; -GameLib.Component.RENDER_TARGET_CUBE = 0x5c; -GameLib.Component.TEXTURE_CUBE = 0x5d; -GameLib.Component.TEXTURE_CANVAS = 0x5e; -GameLib.Component.EFFECT_STEREO = 0x5f; -GameLib.Component.EFFECT_ANAGLYPH = 0x60; -GameLib.Component.EFFECT_PARALLAX = 0x61; -GameLib.Component.PASS_SSAO = 0x62; -GameLib.Component.PASS_BLOOM = 0x63; -GameLib.Component.PASS_FXAA = 0x64; -GameLib.Component.RENDER_CONFIGURATION = 0x65; -GameLib.Component.MATERIAL_BASIC = 0x66; -GameLib.Component.TEXTURE = 0x67; -GameLib.Component.MATERIAL_PHONG = 0x68; - -GameLib.Component.GEOMETRY_NORMAL = 0x69; -GameLib.Component.GEOMETRY_NORMAL_BOX = 0x6a; -GameLib.Component.GEOMETRY_NORMAL_CIRCLE = 0x6b; -GameLib.Component.GEOMETRY_NORMAL_CONE = 0x6c; -GameLib.Component.GEOMETRY_NORMAL_CYLINDER = 0x6d; -GameLib.Component.GEOMETRY_NORMAL_DODECAHEDRON = 0x6e; -GameLib.Component.GEOMETRY_NORMAL_EDGES = 0x6f; -GameLib.Component.GEOMETRY_NORMAL_EXTRUDE = 0x70; -GameLib.Component.GEOMETRY_NORMAL_ICOSAHEDRON = 0x71; -GameLib.Component.GEOMETRY_NORMAL_LATHE = 0x72; -GameLib.Component.GEOMETRY_NORMAL_OCTAHEDRON = 0x73; -GameLib.Component.GEOMETRY_NORMAL_PARAMETRIC = 0x74; -GameLib.Component.GEOMETRY_NORMAL_PLANE = 0x75; -GameLib.Component.GEOMETRY_NORMAL_POLYHEDRON = 0x76; -GameLib.Component.GEOMETRY_NORMAL_RING = 0x77; -GameLib.Component.GEOMETRY_NORMAL_SHAPE = 0x78; -GameLib.Component.GEOMETRY_NORMAL_SPHERE = 0x79; -GameLib.Component.GEOMETRY_NORMAL_TETRAHEDRON = 0x7a; -GameLib.Component.GEOMETRY_NORMAL_TEXT = 0x7b; -GameLib.Component.GEOMETRY_NORMAL_TORUS = 0x7c; -GameLib.Component.GEOMETRY_NORMAL_TORUS_KNOT = 0x7d; -GameLib.Component.GEOMETRY_NORMAL_TUBE = 0x7e; -GameLib.Component.GEOMETRY_NORMAL_WIREFRAME = 0x7f; - -GameLib.Component.GEOMETRY_BUFFER = 0x80; -GameLib.Component.GEOMETRY_BUFFER_BOX = 0x81; -GameLib.Component.GEOMETRY_BUFFER_CIRCLE = 0x82; -GameLib.Component.GEOMETRY_BUFFER_CONE = 0x83; -GameLib.Component.GEOMETRY_BUFFER_CYLINDER = 0x84; -GameLib.Component.GEOMETRY_BUFFER_DODECAHEDRON = 0x85; -GameLib.Component.GEOMETRY_BUFFER_EXTRUDE = 0x86; -GameLib.Component.GEOMETRY_BUFFER_ICOSAHEDRON = 0x87; -GameLib.Component.GEOMETRY_BUFFER_LATHE = 0x88; -GameLib.Component.GEOMETRY_BUFFER_OCTAHEDRON = 0x89; -GameLib.Component.GEOMETRY_BUFFER_PARAMETRIC = 0x8a; -GameLib.Component.GEOMETRY_BUFFER_PLANE = 0x8b; -GameLib.Component.GEOMETRY_BUFFER_POLYHEDRON = 0x8c; -GameLib.Component.GEOMETRY_BUFFER_RING = 0x8d; -GameLib.Component.GEOMETRY_BUFFER_SHAPE = 0x8e; -GameLib.Component.GEOMETRY_BUFFER_SPHERE = 0x8f; -GameLib.Component.GEOMETRY_BUFFER_TETRAHEDRON = 0x90; -GameLib.Component.GEOMETRY_BUFFER_TEXT = 0x91; -GameLib.Component.GEOMETRY_BUFFER_TORUS = 0x92; -GameLib.Component.GEOMETRY_BUFFER_TORUS_KNOT = 0x93; -GameLib.Component.GEOMETRY_BUFFER_TUBE = 0x94; - -GameLib.Component.GEOMETRY = 0x95; - -GameLib.Component.CURVE = 0x96; -GameLib.Component.CURVE_PATH = 0x97; -GameLib.Component.CURVE_PATH_D2 = 0x98; -GameLib.Component.CURVE_PATH_D2_SHAPE = 0x99; -GameLib.Component.BOX3 = 0x9a; -GameLib.Component.DRAW_RANGE = 0x9b; -GameLib.Component.GROUP = 0x9c; - -GameLib.Component.MATERIAL_SHADER = 0x9d; - -GameLib.Component.SHADER = 0x9e; -GameLib.Component.SHADER_VERTEX = 0x9f; -GameLib.Component.SHADER_FRAGMENT = 0xa0; -GameLib.Component.GEOMETRY_BUFFER_INSTANCED = 0xa1; -GameLib.Component.MATERIAL_SHADER_RAW = 0xa2; -GameLib.Component.MATERIAL_POINTS = 0xa3; - -GameLib.Component.MAX_COMPONENTS = 0xa4; - -GameLib.Component.GRAPHICS_RUNTIME = 0x1; -GameLib.Component.PHYSICS_RUNTIME = 0x2; -GameLib.Component.SOCKET_RUNTIME = 0x3; -GameLib.Component.STATISTICS_RUNTIME = 0x4; -GameLib.Component.DEFAULT_RUNTIME = 0x5; -GameLib.Component.GUI_RUNTIME = 0x6; -GameLib.Component.CODER_RUNTIME = 0x7; - -GameLib.Component.GetCompentTypes = function(constructor) { - - if (constructor === GameLib.Component) { - - } -}; - -/** - * Returns string name for component number - * @param number - * @returns {*} - * @constructor - */ -GameLib.Component.GetComponentInfo = function(number) { - switch(number) { - case 0x1 : return { - name : 'GameLib.Socket.Receive', - runtime : GameLib.Component.SOCKET_RUNTIME, - constructor : GameLib.Socket.Receive, - apiConstructor : GameLib.API.Socket.Receive - }; - case 0x2 : return { - name : 'GameLib.D3.Material.Standard', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Material.Standard, - apiConstructor : GameLib.D3.API.Material.Standard - }; - case 0x3 : return { - name : 'GameLib.Renderer', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.Renderer, - apiConstructor : GameLib.API.Renderer - }; - case 0x4 : return { - name : 'GameLib.Server', - runtime : GameLib.Component.DEFAULT_RUNTIME, - constructor : GameLib.Server, - apiConstructor : GameLib.API.Server - }; - case 0x5 : return { - name : 'GameLib.D3.Camera.Perspective', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Camera.Perspective, - apiConstructor : GameLib.D3.API.Camera.Perspective - }; - case 0x6 : return { - name : 'GameLib.Socket', - runtime : GameLib.Component.SOCKET_RUNTIME, - constructor : GameLib.Socket, - apiConstructor : GameLib.API.Socket - }; - case 0x7 : return { - name : 'GameLib.D3.Mesh', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Mesh, - apiConstructor : GameLib.D3.API.Mesh - }; - case 0x8 : return { - name : 'GameLib.D3.Spline', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Spline, - apiConstructor : GameLib.D3.API.Spline - }; - case 0x9 : return { - name : 'GameLib.D3.Shadow.Directional', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Shadow.Directional, - apiConstructor : GameLib.D3.API.Shadow.Directional - }; - case 0xa : return { - name : 'GameLib.Plane', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.Plane, - apiConstructor : GameLib.API.Plane - }; - case 0xb : return { - name : 'GameLib.D3.Composer', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Composer, - apiConstructor : GameLib.D3.API.Composer - }; - case 0xc : return { - name : 'GameLib.D3.RenderTarget', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.RenderTarget, - apiConstructor : GameLib.D3.API.RenderTarget - }; - case 0xd : return { - name : 'GameLib.D3.Pass.Render', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Pass.Render, - apiConstructor : GameLib.D3.API.Pass.Render - }; - case 0xe : return { - name : 'GameLib.D3.Scene', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Scene - }; - case 0xf : return { - name : 'GameLib.D3.Raycaster', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Raycaster, - apiConstructor : GameLib.D3.API.Raycaster - }; - case 0x10 : return { - name : 'GameLib.D3.Text', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Text, - apiConstructor : GameLib.D3.API.Text - }; - case 0x11 : return { - name : 'GameLib.D3.Face', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Face, - apiConstructor : GameLib.D3.API.Face - }; - case 0x12 : return { - name : 'GameLib.D3.Viewport', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Viewport, - apiConstructor : GameLib.D3.API.Viewport - }; - case 0x13 : return { - name : 'GameLib.System', - runtime : GameLib.Component.DEFAULT_RUNTIME, - constructor : GameLib.System, - apiConstructor : GameLib.API.System - }; - case 0x14 : return { - name : 'GameLib.GraphicsRuntime', - runtime : GameLib.Component.DEFAULT_RUNTIME, - constructor : GameLib.GraphicsRuntime - }; - case 0x15 : return { - name : 'GameLib.D3.Helper', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Helper - }; - case 0x16 : return { - name : 'GameLib.CustomCode', - runtime : GameLib.Component.DEFAULT_RUNTIME, - constructor : GameLib.CustomCode, - apiConstructor : GameLib.API.CustomCode - }; - case 0x17 : return { - name : 'GameLib.Mouse', - runtime : GameLib.Component.DEFAULT_RUNTIME, - constructor : GameLib.Mouse, - apiConstructor : GameLib.API.Mouse - }; - case 0x18 : return { - name : 'GameLib.D3.Skeleton', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Skeleton, - apiConstructor : GameLib.D3.API.Skeleton - }; - case 0x19 : return { - name : 'GameLib.D3.Texture.Image', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Texture.Image, - apiConstructor : GameLib.D3.API.Texture.Image - }; - case 0x1a : return { - name : 'GameLib.EntityManager', - runtime : GameLib.Component.DEFAULT_RUNTIME, - constructor : GameLib.EntityManager, - apiConstructor : GameLib.API.EntityManager - }; - case 0x1b : return { - name : 'GameLib.DomElement', - runtime : GameLib.Component.DEFAULT_RUNTIME, - constructor : GameLib.DomElement, - apiConstructor : GameLib.API.DomElement - }; - case 0x1c : return { - name : 'GameLib.D3.Shadow.Spot', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Shadow.Spot, - apiConstructor : GameLib.D3.API.Shadow.Spot - }; - case 0x1d : return { - name : 'GameLib.Stats', - runtime : GameLib.Component.STATISTICS_RUNTIME, - constructor : GameLib.Stats, - apiConstructor : GameLib.API.Stats - }; - case 0x1e : return { - name : 'GameLib.GUI', - runtime : GameLib.Component.GUI_RUNTIME, - constructor : GameLib.GUI, - apiConstructor : GameLib.API.GUI - }; - case 0x1f : return { - name : 'GameLib.Image', - runtime : GameLib.Component.DEFAULT_RUNTIME, - constructor : GameLib.Image - }; - case 0x20 : return { - name : 'GameLib.Entity', - runtime : GameLib.Component.DEFAULT_RUNTIME, - constructor : GameLib.Entity, - apiConstructor : GameLib.API.Entity - }; - case 0x21 : return { - name : 'GameLib.D3.Object', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Object, - apiConstructor : GameLib.D3.API.Object - }; - case 0x22 : return { - name : 'GameLib.Renderer.D2', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.Renderer.D2, - apiConstructor : GameLib.API.Renderer.D2 - }; - case 0x23 : return { - name : 'GameLib.Renderer.D3', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.Renderer.D3, - apiConstructor : GameLib.API.Renderer.D3 - }; - case 0x24 : return { - name : 'GameLib.D3.PhysicsWorld', - runtime : GameLib.Component.PHYSICS_RUNTIME, - constructor : GameLib.D3.PhysicsWorld, - apiConstructor : GameLib.D3.API.PhysicsWorld - }; - case 0x25 : return { - name : 'GameLib.D3.Broadphase', - runtime : GameLib.Component.PHYSICS_RUNTIME, - constructor : GameLib.D3.Broadphase, - apiConstructor : GameLib.D3.API.Broadphase - }; - case 0x26 : return { - name : 'GameLib.D3.Solver', - runtime : GameLib.Component.PHYSICS_RUNTIME, - constructor : GameLib.D3.Solver, - apiConstructor : GameLib.D3.API.Solver - }; - case 0x27 : return { - name : 'GameLib.D3.RigidBody', - runtime : GameLib.Component.PHYSICS_RUNTIME, - constructor : GameLib.D3.RigidBody, - apiConstructor : GameLib.D3.API.RigidBody - }; - case 0x28 : return { - name : 'GameLib.D3.Shape', - runtime : GameLib.Component.PHYSICS_RUNTIME, - constructor : GameLib.D3.Shape, - apiConstructor : GameLib.D3.API.Shape - }; - case 0x29 : return { - name : 'GameLib.D3.Shape.Box', - runtime : GameLib.Component.PHYSICS_RUNTIME, - constructor : GameLib.D3.Shape.Box, - apiConstructor : GameLib.D3.API.Shape - }; - case 0x2a : return { - name : 'GameLib.D3.Shape.Sphere', - runtime : GameLib.Component.PHYSICS_RUNTIME, - constructor : GameLib.D3.Shape.Sphere, - apiConstructor : GameLib.D3.API.Shape - }; - case 0x2b : return { - name : 'GameLib.D3.Shape.TriMesh', - runtime : GameLib.Component.PHYSICS_RUNTIME, - constructor : GameLib.D3.Shape.TriMesh, - apiConstructor : GameLib.D3.API.Shape - }; - case 0x2c : return { - name : 'GameLib.D3.Shape.ConvexHull', - runtime : GameLib.Component.PHYSICS_RUNTIME, - constructor : GameLib.D3.Shape.ConvexHull, - apiConstructor : GameLib.D3.API.Shape - }; - case 0x2d : return { - name : 'GameLib.D3.Shape.ConvexHull.Cylinder', - runtime : GameLib.Component.PHYSICS_RUNTIME, - constructor : GameLib.D3.Shape.ConvexHull.Cylinder, - apiConstructor : GameLib.D3.API.Shape - }; - case 0x2e : return { - name : 'GameLib.D3.Shape.HeightMap', - runtime : GameLib.Component.DEFAULT_RUNTIME, - constructor : GameLib.D3.Shape.HeightMap, - apiConstructor : GameLib.D3.API.Shape - }; - case 0x2f : return { - name : 'GameLib.D3.Shape.Plane', - runtime : GameLib.Component.PHYSICS_RUNTIME, - constructor : GameLib.D3.Shape.Plane, - apiConstructor : GameLib.D3.API.Shape - }; - case 0x30 : return { - name : 'GameLib.Controls', - runtime : GameLib.Component.DEFAULT_RUNTIME, - constructor : GameLib.Controls, - apiConstructor : GameLib.API.Controls - }; - case 0x31 : return { - name : 'GameLib.Controls.D3.Editor', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.Controls.D3.Editor, - apiConstructor : GameLib.API.Controls - }; - case 0x32 : return { - name : 'GameLib.Controls.Touch', - runtime : GameLib.Component.DEFAULT_RUNTIME, - constructor : GameLib.Controls.Touch, - apiConstructor : GameLib.API.Controls - }; - case 0x33 : return { - name : 'GameLib.D3.FrictionMaterial', - runtime : GameLib.Component.PHYSICS_RUNTIME, - constructor : GameLib.D3.FrictionMaterial, - apiConstructor : GameLib.D3.API.FrictionMaterial - }; - case 0x34 : return { - name : 'GameLib.D3.FrictionContactMaterial', - runtime : GameLib.Component.PHYSICS_RUNTIME, - constructor : GameLib.D3.FrictionContactMaterial, - apiConstructor : GameLib.D3.API.FrictionContactMaterial - }; - case 0x35 : return { - name : 'GameLib.D3.RaycastVehicle', - runtime : GameLib.Component.PHYSICS_RUNTIME, - constructor : GameLib.D3.RaycastVehicle, - apiConstructor : GameLib.D3.API.RaycastVehicle - }; - case 0x36 : return { - name : 'GameLib.D3.RaycastWheel', - runtime : GameLib.Component.PHYSICS_RUNTIME, - constructor : GameLib.D3.RaycastWheel, - apiConstructor : GameLib.D3.API.RaycastWheel - }; - case 0x37 : return { - name : 'GameLib.Clock', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.Clock, - apiConstructor : GameLib.API.Clock - }; - case 0x38 : return { - name : 'GameLib.D3.Animation', - runtime : GameLib.Component.DEFAULT_RUNTIME, - constructor : GameLib.D3.Animation, - apiConstructor : GameLib.D3.API.Animation - }; - case 0x39 : return { - name : 'GameLib.Controls.Keyboard', - runtime : GameLib.Component.DEFAULT_RUNTIME, - constructor : GameLib.Controls.Keyboard, - apiConstructor : GameLib.API.Controls - }; - case 0x3a : return { - name : 'GameLib.Controls.Mouse', - runtime : GameLib.Component.DEFAULT_RUNTIME, - constructor : GameLib.Controls.Mouse, - apiConstructor : GameLib.API.Controls - }; - case 0x3b : return { - name : 'GameLib.GraphicsRuntime.Three', - runtime : GameLib.Component.DEFAULT_RUNTIME, - constructor : GameLib.GraphicsRuntime.Three, - apiConstructor : GameLib.API.GraphicsRuntime.Three - }; - case 0x3c : return { - name : 'GameLib.D3.Font', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Font, - apiConstructor : GameLib.D3.API.Font - }; - case 0x3d : return { - name : 'GameLib.Canvas', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.Canvas, - apiConstructor : GameLib.API.Canvas - }; - case 0x3e : return { - name : 'GameLib.D3.Bone', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Bone, - apiConstructor : GameLib.D3.API.Bone - }; - case 0x3f : return { - name : 'GameLib.GraphicsRuntime.Impact', - runtime : GameLib.Component.DEFAULT_RUNTIME, - constructor : GameLib.GraphicsRuntime.Impact, - apiConstructor : GameLib.API.GraphicsRuntime.Impact - }; - case 0x40 : return { - name : 'GameLib.Controls.D3.FirstPerson', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.Controls.D3.FirstPerson, - apiConstructor : GameLib.API.Controls.D3.FirstPerson - }; - case 0x41 : return { - name : 'GameLib.System.Animation', - runtime : GameLib.Component.DEFAULT_RUNTIME, - constructor : GameLib.System.Animation, - apiConstructor : GameLib.API.System - }; - case 0x42 : return { - name : 'GameLib.System.CustomCode', - runtime : GameLib.Component.DEFAULT_RUNTIME, - constructor : GameLib.System.CustomCode, - apiConstructor : GameLib.API.System - }; - case 0x43 : return { - name : 'GameLib.System.GUI', - runtime : GameLib.Component.DEFAULT_RUNTIME, - constructor : GameLib.System.GUI, - apiConstructor : GameLib.API.System - }; - case 0x44 : return { - name : 'GameLib.System.Input', - runtime : GameLib.Component.DEFAULT_RUNTIME, - constructor : GameLib.System.Input, - apiConstructor : GameLib.API.System - }; - case 0x45 : return { - name : 'GameLib.System.Linking', - runtime : GameLib.Component.DEFAULT_RUNTIME, - constructor : GameLib.System.Linking, - apiConstructor : GameLib.API.System - }; - case 0x46 : return { - name : 'GameLib.System.Physics', - runtime : GameLib.Component.DEFAULT_RUNTIME, - constructor : GameLib.System.Physics, - apiConstructor : GameLib.API.System - }; - case 0x47 : return { - name : 'GameLib.System.Render', - runtime : GameLib.Component.DEFAULT_RUNTIME, - constructor : GameLib.System.Render, - apiConstructor : GameLib.API.System - }; - case 0x48 : return { - name : 'GameLib.System.Storage', - runtime : GameLib.Component.DEFAULT_RUNTIME, - constructor : GameLib.System.Storage, - apiConstructor : GameLib.API.System - }; - case 0x49 : return { - name : 'GameLib.System.Visualization', - runtime : GameLib.Component.DEFAULT_RUNTIME, - constructor : GameLib.System.Visualization, - apiConstructor : GameLib.API.System - }; - case 0x4a : return { - name : 'GameLib.D3.Light.Ambient', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Light.Ambient, - apiConstructor : GameLib.D3.API.Light.Ambient - }; - case 0x4b : return { - name : 'GameLib.D3.Light.Directional', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Light.Directional, - apiConstructor : GameLib.D3.API.Light.Directional - }; - case 0x4c : return { - name : 'GameLib.D3.Light.Hemisphere', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Light.Hemisphere, - apiConstructor : GameLib.D3.API.Light.Hemisphere - }; - case 0x4d : return { - name : 'GameLib.D3.Light.Point', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Light.Point, - apiConstructor : GameLib.D3.API.Light.Point - }; - case 0x4e : return { - name : 'GameLib.D3.Light.RectArea', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Light.RectArea, - apiConstructor : GameLib.D3.API.Light.RectArea - }; - case 0x4f : return { - name : 'GameLib.D3.Light.Spot', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Light.Spot, - apiConstructor : GameLib.D3.API.Light.Spot - }; - case 0x50 : return { - name : 'GameLib.D3.Fog', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Fog, - apiConstructor : GameLib.D3.API.Fog - }; - case 0x51 : return { - name : 'GameLib.Controls.D3.Orbit', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.Controls.D3.Orbit, - apiConstructor : GameLib.API.Controls.D3.Orbit - }; - case 0x52 : return { - name : 'GameLib.D3.ParticleEngine', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.ParticleEngine, - apiConstructor : GameLib.D3.API.ParticleEngine - }; - case 0x53 : return { - name : 'GameLib.System.Particle', - runtime : GameLib.Component.DEFAULT_RUNTIME, - constructor : GameLib.System.Particle, - apiConstructor : GameLib.API.System - }; - case 0x54 : return { - name : 'GameLib.D3.Particle', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Particle, - apiConstructor : GameLib.D3.API.Particle - }; - case 0x55 : return { - name : 'GameLib.D3.Audio', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Audio, - apiConstructor : GameLib.D3.API.Audio - }; - case 0x56 : return { - name : 'GameLib.System.Audio', - runtime : GameLib.Component.DEFAULT_RUNTIME, - constructor : GameLib.System.Audio, - apiConstructor : GameLib.API.System - }; - case 0x57 : return { - name : 'GameLib.Socket.Cast', - runtime : GameLib.Component.SOCKET_RUNTIME, - constructor : GameLib.Socket.Cast, - apiConstructor : GameLib.API.Socket.Cast - }; - case 0x58 : return { - name : 'GameLib.D3.Camera.Orthographic', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Camera.Orthographic, - apiConstructor : GameLib.D3.API.Camera.Orthographic - }; - case 0x59 : return { - name : 'GameLib.D3.Camera.Stereo', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Camera.Stereo, - apiConstructor : GameLib.D3.API.Camera.Stereo - }; - case 0x5a : return { - name : 'GameLib.D3.Camera.Cube', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Camera.Cube, - apiConstructor : GameLib.D3.API.Camera.Cube - }; - case 0x5b : return { - name : 'GameLib.D3.Shadow', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Shadow, - apiConstructor : GameLib.D3.API.Shadow - }; - case 0x5c : return { - name : 'GameLib.D3.RenderTarget.Cube', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.RenderTarget.Cube, - apiConstructor : GameLib.D3.API.RenderTarget.Cube - }; - case 0x5d : return { - name : 'GameLib.D3.Texture.Cube', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Texture.Cube, - apiConstructor : GameLib.D3.API.Texture.Cube - }; - case 0x5e : return { - name : 'GameLib.D3.Texture.Canvas', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Texture.Canvas, - apiConstructor : GameLib.D3.API.Texture.Canvas - }; - case 0x5f : return { - name : 'GameLib.D3.Effect.Stereo', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Effect.Stereo, - apiConstructor : GameLib.D3.API.Effect.Stereo - }; - case 0x60 : return { - name : 'GameLib.D3.Effect.Anaglyph', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Effect.Anaglyph, - apiConstructor : GameLib.D3.API.Effect.Anaglyph - }; - case 0x61 : return { - name : 'GameLib.D3.Effect.Parallax', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Effect.Parallax, - apiConstructor : GameLib.D3.API.Effect.Parallax - }; - case 0x62 : return { - name : 'GameLib.D3.Pass.SSAO', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Pass.SSAO, - apiConstructor : GameLib.D3.API.Pass.SSAO - }; - case 0x63 : return { - name : 'GameLib.D3.Pass.Bloom', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Pass.Bloom, - apiConstructor : GameLib.D3.API.Pass.Bloom - }; - case 0x64 : return { - name : 'GameLib.D3.Pass.FXAA', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Pass.FXAA, - apiConstructor : GameLib.D3.API.Pass.FXAA - }; - case 0x65 : return { - name : 'GameLib.RenderConfiguration', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.RenderConfiguration, - apiConstructor : GameLib.API.RenderConfiguration - }; - case 0x66 : return { - name : 'GameLib.D3.Material.Basic', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Material.Basic, - apiConstructor : GameLib.D3.API.Material.Basic - }; - case 0x67 : return { - name : 'GameLib.D3.Texture', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Texture, - apiConstructor : GameLib.D3.API.Texture - }; - case 0x68 : return { - name : 'GameLib.D3.Material.Phong', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Material.Phong, - apiConstructor : GameLib.D3.API.Material.Phong - }; - case 0x69 : return { - name : 'GameLib.D3.Geometry.Normal', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Geometry.Normal, - apiConstructor : GameLib.D3.API.Geometry.Normal - }; - case 0x6a : return { - name : 'GameLib.D3.Geometry.Normal.Box', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Geometry.Normal.Box, - apiConstructor : GameLib.D3.API.Geometry.Normal.Box - }; - case 0x6b : return { - name : 'GameLib.D3.Geometry.Normal.Circle', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Geometry.Normal.Circle, - apiConstructor : GameLib.D3.API.Geometry.Normal.Circle - }; - case 0x6c : return { - name : 'GameLib.D3.Geometry.Normal.Cone', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Geometry.Normal.Cone, - apiConstructor : GameLib.D3.API.Geometry.Normal.Cone - }; - case 0x6d : return { - name : 'GameLib.D3.Geometry.Normal.Cylinder', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Geometry.Normal.Cylinder, - apiConstructor : GameLib.D3.API.Geometry.Normal.Cylinder - }; - case 0x6e : return { - name : 'GameLib.D3.Geometry.Normal.Dodecahedron', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Geometry.Normal.Dodecahedron, - apiConstructor : GameLib.D3.API.Geometry.Normal.Dodecahedron - }; - case 0x6f : return { - name : 'GameLib.D3.Geometry.Normal.Edges', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Geometry.Normal.Edges, - apiConstructor : GameLib.D3.API.Geometry.Normal.Edges - }; - case 0x70 : return { - name : 'GameLib.D3.Geometry.Normal.Extrude', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Geometry.Normal.Extrude, - apiConstructor : GameLib.D3.API.Geometry.Normal.Extrude - }; - case 0x71 : return { - name : 'GameLib.D3.Geometry.Normal.Icosahedron', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Geometry.Normal.Icosahedron, - apiConstructor : GameLib.D3.API.Geometry.Normal.Icosahedron - }; - case 0x72 : return { - name : 'GameLib.D3.Geometry.Normal.Lathe', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Geometry.Normal.Lathe, - apiConstructor : GameLib.D3.API.Geometry.Normal.Lathe - }; - case 0x73 : return { - name : 'GameLib.D3.Geometry.Normal.Octahedron', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Geometry.Normal.Octahedron, - apiConstructor : GameLib.D3.API.Geometry.Normal.Octahedron - }; - case 0x74 : return { - name : 'GameLib.D3.Geometry.Normal.Parametric', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Geometry.Normal.Parametric, - apiConstructor : GameLib.D3.API.Geometry.Normal.Parametric - }; - case 0x75 : return { - name : 'GameLib.D3.Geometry.Normal.Plane', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Geometry.Normal.Plane, - apiConstructor : GameLib.D3.API.Geometry.Normal.Plane - }; - case 0x76 : return { - name : 'GameLib.D3.Geometry.Normal.Polyhedron', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Geometry.Normal.Polyhedron, - apiConstructor : GameLib.D3.API.Geometry.Normal.Polyhedron - }; - case 0x77 : return { - name : 'GameLib.D3.Geometry.Normal.Ring', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Geometry.Normal.Ring, - apiConstructor : GameLib.D3.API.Geometry.Normal.Ring - }; - case 0x78 : return { - name : 'GameLib.D3.Geometry.Normal.Shape', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Geometry.Normal.Shape, - apiConstructor : GameLib.D3.API.Geometry.Normal.Shape - }; - case 0x79 : return { - name : 'GameLib.D3.Geometry.Normal.Sphere', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Geometry.Normal.Sphere, - apiConstructor : GameLib.D3.API.Geometry.Normal.Sphere - }; - case 0x7a : return { - name : 'GameLib.D3.Geometry.Normal.Tetrahedron', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Geometry.Normal.Tetrahedron, - apiConstructor : GameLib.D3.API.Geometry.Normal.Tetrahedron - }; - case 0x7b : return { - name : 'GameLib.D3.Geometry.Normal.Text', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Geometry.Normal.Text, - apiConstructor : GameLib.D3.API.Geometry.Normal.Text - }; - case 0x7c : return { - name : 'GameLib.D3.Geometry.Normal.Torus', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Geometry.Normal.Torus, - apiConstructor : GameLib.D3.API.Geometry.Normal.Torus - }; - case 0x7d : return { - name : 'GameLib.D3.Geometry.Normal.TorusKnot', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Geometry.Normal.TorusKnot, - apiConstructor : GameLib.D3.API.Geometry.Normal.TorusKnot - }; - case 0x7e : return { - name : 'GameLib.D3.Geometry.Normal.Tube', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Geometry.Normal.Tube, - apiConstructor : GameLib.D3.API.Geometry.Normal.Tube - }; - case 0x7f : return { - name : 'GameLib.D3.Geometry.Normal.Wireframe', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Geometry.Normal.Wireframe, - apiConstructor : GameLib.D3.API.Geometry.Normal.Wireframe - }; - case 0x80 : return { - name : 'GameLib.D3.Geometry.Buffer', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Geometry.Buffer, - apiConstructor : GameLib.D3.API.Geometry.Buffer - }; - case 0x81 : return { - name : 'GameLib.D3.Geometry.Buffer.Box', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Geometry.Buffer.Box, - apiConstructor : GameLib.D3.API.Geometry.Buffer.Box - }; - case 0x82 : return { - name : 'GameLib.D3.Geometry.Buffer.Circle', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Geometry.Buffer.Circle, - apiConstructor : GameLib.D3.API.Geometry.Buffer.Circle - }; - case 0x83 : return { - name : 'GameLib.D3.Geometry.Buffer.Cone', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Geometry.Buffer.Cone, - apiConstructor : GameLib.D3.API.Geometry.Buffer.Cone - }; - case 0x84 : return { - name : 'GameLib.D3.Geometry.Buffer.Cylinder', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Geometry.Buffer.Cylinder, - apiConstructor : GameLib.D3.API.Geometry.Buffer.Cylinder - }; - case 0x85 : return { - name : 'GameLib.D3.Geometry.Buffer.Dodecahedron', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Geometry.Buffer.Dodecahedron, - apiConstructor : GameLib.D3.API.Geometry.Buffer.Dodecahedron - }; - case 0x86 : return { - name : 'GameLib.D3.Geometry.Buffer.Extrude', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Geometry.Buffer.Extrude, - apiConstructor : GameLib.D3.API.Geometry.Buffer.Extrude - }; - case 0x87 : return { - name : 'GameLib.D3.Geometry.Buffer.Icosahedron', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Geometry.Buffer.Icosahedron, - apiConstructor : GameLib.D3.API.Geometry.Buffer.Icosahedron - }; - case 0x88 : return { - name : 'GameLib.D3.Geometry.Buffer.Lathe', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Geometry.Buffer.Lathe, - apiConstructor : GameLib.D3.API.Geometry.Buffer.Lathe - }; - case 0x89 : return { - name : 'GameLib.D3.Geometry.Buffer.Octahedron', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Geometry.Buffer.Octahedron, - apiConstructor : GameLib.D3.API.Geometry.Buffer.Octahedron - }; - case 0x8a : return { - name : 'GameLib.D3.Geometry.Buffer.Parametric', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Geometry.Buffer.Parametric, - apiConstructor : GameLib.D3.API.Geometry.Buffer.Parametric - }; - case 0x8b : return { - name : 'GameLib.D3.Geometry.Buffer.Plane', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Geometry.Buffer.Plane, - apiConstructor : GameLib.D3.API.Geometry.Buffer.Plane - }; - case 0x8c : return { - name : 'GameLib.D3.Geometry.Buffer.Polyhedron', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Geometry.Buffer.Polyhedron, - apiConstructor : GameLib.D3.API.Geometry.Buffer.Polyhedron - }; - case 0x8d : return { - name : 'GameLib.D3.Geometry.Buffer.Ring', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Geometry.Buffer.Ring, - apiConstructor : GameLib.D3.API.Geometry.Buffer.Ring - }; - case 0x8e : return { - name : 'GameLib.D3.Geometry.Buffer.Shape', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Geometry.Buffer.Shape, - apiConstructor : GameLib.D3.API.Geometry.Buffer.Shape - }; - case 0x8f : return { - name : 'GameLib.D3.Geometry.Buffer.Sphere', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Geometry.Buffer.Sphere, - apiConstructor : GameLib.D3.API.Geometry.Buffer.Sphere - }; - case 0x90 : return { - name : 'GameLib.D3.Geometry.Buffer.Tetrahedron', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Geometry.Buffer.Tetrahedron, - apiConstructor : GameLib.D3.API.Geometry.Buffer.Tetrahedron - }; - case 0x91 : return { - name : 'GameLib.D3.Geometry.Buffer.Text', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Geometry.Buffer.Text, - apiConstructor : GameLib.D3.API.Geometry.Buffer.Text - }; - case 0x92 : return { - name : 'GameLib.D3.Geometry.Buffer.Torus', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Geometry.Buffer.Torus, - apiConstructor : GameLib.D3.API.Geometry.Buffer.Torus - }; - case 0x93 : return { - name : 'GameLib.D3.Geometry.Buffer.TorusKnot', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Geometry.Buffer.TorusKnot, - apiConstructor : GameLib.D3.API.Geometry.Buffer.TorusKnot - }; - case 0x94 : return { - name : 'GameLib.D3.Geometry.Buffer.Tube', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Geometry.Buffer.Tube, - apiConstructor : GameLib.D3.API.Geometry.Buffer.Tube - }; - case 0x95 : return { - name : 'GameLib.D3.Geometry', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Geometry, - apiConstructor : GameLib.D3.API.Geometry - }; - case 0x96 : return { - name : 'GameLib.Curve', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.Curve, - apiConstructor : GameLib.API.Curve - }; - case 0x97 : return { - name : 'GameLib.Curve.Path', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.Curve.Path, - apiConstructor : GameLib.API.Curve.Path - }; - case 0x98 : return { - name : 'GameLib.Curve.Path.D2', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.Curve.Path.D2, - apiConstructor : GameLib.API.Curve.Path.D2 - }; - case 0x99 : return { - name : 'GameLib.Curve.Path.D2.Shape', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.Curve.Path.D2.Shape, - apiConstructor : GameLib.API.Curve.Path.D2.Shape - }; - case 0x9a : return { - name : 'GameLib.Box3', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.Box3, - apiConstructor : GameLib.API.Box3 - }; - case 0x9b : return { - name : 'GameLib.DrawRange', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.DrawRange, - apiConstructor : GameLib.API.DrawRange - }; - case 0x9c : return { - name : 'GameLib.Group', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.Group, - apiConstructor : GameLib.API.Group - }; - case 0x9d : return { - name : 'GameLib.D3.Material.Shader', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Material.Shader, - apiConstructor : GameLib.D3.API.Material.Shader - }; - case 0x9e : return { - name : 'GameLib.D3.Shader', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Shader, - apiConstructor : GameLib.D3.API.Shader - }; - case 0x9f : return { - name : 'GameLib.D3.Shader.Vertex', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Shader.Vertex, - apiConstructor : GameLib.D3.API.Shader.Vertex - }; - case 0xa0 : return { - name : 'GameLib.D3.Shader.Fragment', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Shader.Fragment, - apiConstructor : GameLib.D3.API.Shader.Fragment - }; - case 0xa1 : return { - name : 'GameLib.D3.Geometry.Buffer.Instanced', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Geometry.Buffer.Instanced, - apiConstructor : GameLib.D3.API.Geometry.Buffer.Instanced - }; - case 0xa2 : return { - name : 'GameLib.D3.Material.Shader.Raw', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Material.Shader.Raw, - apiConstructor : GameLib.D3.API.Material.Shader.Raw - }; - case 0xa3 : return { - name : 'GameLib.D3.Material.Points', - runtime : GameLib.Component.GRAPHICS_RUNTIME, - constructor : GameLib.D3.Material.Points, - apiConstructor : GameLib.D3.API.Material.Points - }; - break; - } - - throw new Error('Unknown component type: ' + number ); -}; - -/** - * Returns the runtime friendly name - * @param runtime - * @returns {*} - * @constructor - */ -GameLib.Component.GetRuntimeName = function(runtime) { - - if (runtime === GameLib.Component.GRAPHICS_RUNTIME) { - return 'Graphics'; - } - - if (runtime === GameLib.Component.PHYSICS_RUNTIME) { - return 'Physics'; - } - - if (runtime === GameLib.Component.GUI_RUNTIME) { - return 'GUI'; - } - - if (runtime === GameLib.Component.STATISTICS_RUNTIME) { - return 'Statistics'; - } - - if (runtime === GameLib.Component.SOCKET_RUNTIME) { - return 'Sockets'; - } - - if (runtime === GameLib.Component.CODER_RUNTIME) { - return 'Coder'; - } - - return 'Default'; -}; - -/** - * @return {string} - */ -GameLib.Component.GetComponentName = function(componentType) { - - var info = GameLib.Component.GetComponentInfo(componentType); - - if (info) { - return info.name; - } - - return 'unused'; -}; - -/** - * @return {null || Object} - */ -GameLib.Component.GetComponentRuntime = function(componentType) { - - var info = GameLib.Component.GetComponentInfo(componentType); - - if (info) { - return info.runtime; - } - 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 {*} - */ -GameLib.Component.prototype.toApiObject = function() { - - var info = GameLib.Component.GetComponentInfo(this.componentType); - - var apiConstructor = info.apiConstructor; - - console.warn('implement generic component toApiObject'); - - var parameters = GameLib.Utils.GetParameters(apiConstructor); - - throw new Error(parameters); - - return this.id; - // return new info.apiConstructor() - -}; - -/** - * Gets all children components of this Object (all linked objects only - no object references i.e. string ids) - * @returns {Array} - */ -GameLib.Component.prototype.getChildrenComponents = function() { - - var components = []; - - this.buildIdToObject(); - - Object.keys(this.idToObject).map( - function (objectId) { - if (this.id !== objectId) { - components.push(this.idToObject[objectId]); - } - }.bind(this) - ); - - return components; -}; - -GameLib.Component.prototype.processComponent = function(object) { - if (object instanceof GameLib.Component) { - - object.buildIdToObject(); - - if (!object.linked) { - this.linked = false; - } - - var idToObject = object.idToObject; - - for (var objectProperty in idToObject) { - if (idToObject.hasOwnProperty(objectProperty)) { - this.idToObject[objectProperty] = idToObject[objectProperty]; - } - } - - if (object.id) { - this.idToObject[object.id] = object; - } else { - console.warn('Object with no ID passed: ' + object) - } - - } else if (typeof object === 'string') { - this.linked = false; - } else { - console.warn('Unhandled type of object: ', object); - } -}; - -/** - * This function - builds an 'id to object' object - which contains the ids which point directly - * to its corresponding object, for all the objects contained inside this object - */ -GameLib.Component.prototype.buildIdToObject = function() { - - if (this.building) { - return; - } - - /** - * If this component 'building' flag is true - it is in the process of building idToObject up the callstack and the - * caller should know to not try to build idToObject again (prevent infinite recursion) - */ - this.building = true; - - /** - * If any child component is not fully linked, this component will show as not linked - * @type {boolean} - */ - this.linked = true; - - this.idToObject = {}; - - for (var property in this.linkedObjects) { - if ( - this.linkedObjects.hasOwnProperty(property) && - this.hasOwnProperty(property) && - this[property] && - property.indexOf('parent') !== 0 - ) { - - if (this.linkedObjects[property] instanceof Array) { - - /** - * Remove null objects (can happen) - */ - this[property] = this[property].filter( - function (object) { - if (object === null) { - console.log('null object found and removed'); - return false; - } - return true; - } - ); - - this[property].map( - function (object) { - this.processComponent(object); - }.bind(this) - ); - - } else { - this.processComponent(this[property]); - } - } - } - - if (this instanceof GameLib.D3.Scene) { - if (!this.storeClones) { - this.clones.map( - function (clone) { - if (this.idToObject.hasOwnProperty(clone.id)) { - delete this.idToObject[clone.id]; - } - }.bind(this) - ) - } - } - - this.idToObject[this.id] = this; - - this.building = false; -}; - -GameLib.Component.prototype.generateNewIds = function() { - - this.buildIdToObject(); - - var codeComponents = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.CUSTOM_CODE); - - for (var property in this.idToObject) { - if (this.idToObject.hasOwnProperty(property)) { - - var oldId = this.idToObject[property].id; - var newId = GameLib.Utils.RandomId(); - - this.idToObject[property].id = newId; - this.idToObject[property].name = this.idToObject[property].name.replace(oldId,newId); - - if (this.generateNewImageIds) { - - // TODO: replace image filenames - but then also copy them server side? - if (this.idToObject[property].fileName) { - this.idToObject[property].fileName = this.idToObject[property].fileName.replace(oldId,newId); - } - } - - codeComponents.map(function(codeComponent){ - codeComponent.code = codeComponent.code.replace(oldId,newId); - }); - } - } - -}; - -/** - * TODO: don't remove components which are still in use elsewhere - this is important to prevent 'register out - * of sync' messages - */ -GameLib.Component.prototype.remove = function() { - - this.buildIdToObject(); - - Object.keys(this.idToObject).map( - function(componentId){ - GameLib.Event.Emit( - GameLib.Event.REMOVE_COMPONENT, - { - component : this.idToObject[componentId] - } - ) - }.bind(this) - ); - -}; - -GameLib.Component.prototype.replace = function(componentType) { - - var replacement = GameLib.Component.Construct(componentType); - - GameLib.Event.Emit( - GameLib.Event.REPLACE_COMPONENT, - { - current : this, - replacement : replacement - } - ); - - if (this.parentEntity && this.parentEntity.loaded) { - this.parentEntity.addComponent(replacement); - } - - this.remove(); - - GameLib.Event.Emit( - GameLib.Event.COMPONENT_REPLACED - ); -}; - - -GameLib.Component.prototype.clone = function() { - - var apiObject = this.toApiObject(); - - this.cloneNumber += 1; - - apiObject.id = GameLib.Utils.RandomId(); - - apiObject.name = this.name + ' Clone (' + this.cloneNumber + ')'; - - var runtimeComponent = GameLib.Component.ConstructFromObject(apiObject); - - runtimeComponent.isClone = true; - - GameLib.Event.Emit( - GameLib.Event.COMPONENT_CLONED, - { - parent : this, - component : runtimeComponent - } - ); - - runtimeComponent.parentEntity = null; - - return runtimeComponent; -}; - -/** - * Clones only the instance - */ -GameLib.Component.prototype.cloneInstance = function() { - - var clone = null; - - if ( - this.instance && - this.instance.clone && - typeof (this.instance.clone === 'function')) { - - clone = this.instance.clone(); - - GameLib.Event.Emit( - GameLib.Event.INSTANCE_CLONED, - { - component : this, - instance : clone - } - ) - } - - return clone; -}; - -GameLib.Component.prototype.saveToRemoteAPI = function() { - this.save(true); -}; - -GameLib.Component.prototype.save = function(remote) { - - var toSave = []; - var saved = []; - var failed = []; - - this.buildIdToObject(); - - if (this.saveSubscription || this.saveErrorSubscription) { - console.warn('another save is in progress'); - return; - } - - GameLib.Event.Emit( - GameLib.Event.SAVING, - { - component: this - } - ); - - this.saveSubscription = GameLib.Event.Subscribe( - GameLib.Event.COMPONENT_SAVED, - function(data) { - - saved.push(data.component); - - if (failed.length + saved.length === toSave.length) { - - this.saveSubscription.remove(); - - this.saveSubscription = null; - - this.saveErrorSubscription.remove(); - - this.saveErrorSubscription = null; - - GameLib.Event.Emit( - GameLib.Event.DONE_SAVING, - { - failed: failed, - saved: saved - } - ) - } - - }.bind(this) - ); - - this.saveErrorSubscription = GameLib.Event.Subscribe( - GameLib.Event.SAVE_COMPONENT_ERROR, - function(data) { - - failed.push(data.component); - - if (failed.length + saved.length === toSave.length) { - - this.saveSubscription.remove(); - - this.saveSubscription = null; - - this.saveErrorSubscription.remove(); - - this.saveErrorSubscription = null; - - GameLib.Event.Emit( - GameLib.Event.DONE_SAVING, - { - failed: failed, - saved: saved - } - ) - } - - }.bind(this) - ); - - - - Object.keys(this.idToObject).map( - function(componentId) { - - var component = this.idToObject[componentId]; - - if (this instanceof GameLib.Entity) { - - /** - * We don't store children objects of entities which are not explicitly defined as children of this entity. - */ - if ( - this.components.indexOf(component) === -1 && - this !== component - ) { - - /** - * We don't want to store this component - but other components may depend on it - */ - console.warn(component.name + ' is being stored because a component depends on it - even though it was not explicitly added to this entity.'); - } - } - - var apiObject = component.toApiObject(); - - toSave.push(apiObject); - - this.publish( - GameLib.Event.SAVE_COMPONENT, - { - apiObject: apiObject, - remote: remote - }, - function success(result) { - console.log(result); - }, - function error(error) { - console.log(error); - } - ); - - }.bind(this) - ); -}; - -/** - * @return {null|Object} - */ -GameLib.Component.GetRuntimeObject = function(runtimeInfo) { - - var runtime = null; - - GameLib.Event.Emit( - GameLib.Event.GET_RUNTIME, - null, - function(runtimeObject) { - runtime = runtimeObject; - } - ); - - if (runtimeInfo === GameLib.Component.GRAPHICS_RUNTIME) { - - if (GameLib.Utils.UndefinedOrNull(runtime.graphics)) { - console.warn('no runtime graphics'); - return null; - } - - return runtime.graphics; - - } else if (runtimeInfo === GameLib.Component.PHYSICS_RUNTIME) { - - if (GameLib.Utils.UndefinedOrNull(runtime.physics)) { - console.warn('no runtime physics'); - return null; - } - - return runtime.physics; - - } else if (runtimeInfo === GameLib.Component.GUI_RUNTIME) { - - if (GameLib.Utils.UndefinedOrNull(runtime.gui)) { - console.warn('no runtime gui'); - return null; - } - - return runtime.gui; - - } else if (runtimeInfo === GameLib.Component.SOCKET_RUNTIME) { - - if (GameLib.Utils.UndefinedOrNull(runtime.sockets)) { - console.warn('no runtime sockets'); - return null; - } - - return runtime.sockets; - - } else if (runtimeInfo === GameLib.Component.STATISTICS_RUNTIME) { - - if (GameLib.Utils.UndefinedOrNull(runtime.statistics)) { - console.warn('no runtime statistics'); - return null; - } - - return runtime.statistics; - - } else if (runtimeInfo === GameLib.Component.DEFAULT_RUNTIME) { - - } else { - console.log('unknown runtime object found : ' + info.runtime); - } - - return null; -}; - -GameLib.Component.Construct = function(componentType) { - - var info = GameLib.Component.GetComponentInfo(componentType); - - var componentClass = info.constructor; - - var runtime = GameLib.Component.GetRuntimeObject(info.runtime); - - if (runtime) { - return new componentClass(runtime); - } else { - return new componentClass(); - } - -}; - -GameLib.Component.ConstructFromObject = function(rawComponentObject) { - - var runtimeComponent = null; - - // if ( - // rawComponentObject.componentType === 34 && - // rawComponentObject.name.indexOf('Mesh') !== -1 - // ) { - // rawComponentObject.componentType = 7; - // } - - var info = GameLib.Component.GetComponentInfo(rawComponentObject.componentType); - - var runtime = GameLib.Component.GetRuntimeObject(info.runtime); - - if (runtime) { - runtimeComponent = new info.constructor(runtime, rawComponentObject); - } else { - runtimeComponent = new info.constructor(rawComponentObject); - } - - return runtimeComponent; -}; \ No newline at end of file diff --git a/src/game-lib-api-box3.js b/src/game-lib-api-box3.js deleted file mode 100644 index e19ec17..0000000 --- a/src/game-lib-api-box3.js +++ /dev/null @@ -1,45 +0,0 @@ -/** - * GameLib.API.Box3 - * @param id - * @param name - * @param parentEntity - * @param min - * @param max - * @constructor - */ -GameLib.API.Box3 = function ( - id, - name, - parentEntity, - min, - max -) { - if (GameLib.Utils.UndefinedOrNull(id)) { - id = GameLib.Utils.RandomId(); - } - this.id = id; - - if (GameLib.Utils.UndefinedOrNull(name)) { - name = 'Box (' + id + ')'; - } - this.name = name; - - if (GameLib.Utils.UndefinedOrNull(min)) { - min = new GameLib.API.Vector3(0,0,0); - } - this.min = min; - - if (GameLib.Utils.UndefinedOrNull(max)) { - max = new GameLib.API.Vector3(1,1,1); - } - this.max = max; - - GameLib.API.Component.call( - this, - GameLib.Component.BOX3, - parentEntity - ) -}; - -GameLib.API.Box3.prototype = Object.create(GameLib.API.Component.prototype); -GameLib.API.Box3.prototype.constructor = GameLib.API.Box3; diff --git a/src/game-lib-api-controls-0.js b/src/game-lib-api-controls-0.js deleted file mode 100644 index 522a35d..0000000 --- a/src/game-lib-api-controls-0.js +++ /dev/null @@ -1,115 +0,0 @@ -/** - * Raw Controls API object - * @param id - * @param controlsType - * @param name - * @param canvas - * @param parentEntity - * @property controlsType - * @constructor - */ -GameLib.API.Controls = function( - id, - name, - controlsType, - canvas, - parentEntity -) { - if (GameLib.Utils.UndefinedOrNull(id)) { - id = GameLib.Utils.RandomId(); - } - this.id = id; - - if (GameLib.Utils.UndefinedOrNull(controlsType)) { - controlsType = GameLib.API.Controls.CONTROLS_TYPE_NONE; - } - this.controlsType = controlsType; - - if (GameLib.Utils.UndefinedOrNull(name)) { - - name = 'Controls'; - - switch (this.controlsType) { - case GameLib.API.Controls.CONTROLS_TYPE_TOUCH : - name = 'Controls Editor'; - break; - case GameLib.API.Controls.CONTROLS_TYPE_KEYBOARD : - name = 'Controls Keyboard'; - break; - case GameLib.API.Controls.CONTROLS_TYPE_MOUSE : - name = 'Controls Mouse'; - break; - case GameLib.API.Controls.CONTROLS_TYPE_EDITOR : - name = 'Controls Editor'; - break; - case GameLib.API.Controls.CONTROLS_TYPE_FIRST_PERSON : - name = 'Controls First Person'; - break; - case GameLib.API.Controls.CONTROLS_TYPE_ORBIT : - name = 'Controls Orbit'; - break; - } - - name += ' (' + this.id + ')'; - } - this.name = name; - - if (GameLib.Utils.UndefinedOrNull(canvas)) { - canvas = null; - } - this.canvas = canvas; - - GameLib.API.Component.call( - this, - GameLib.API.Controls.GetComponentType(this.controlsType), - parentEntity - ); -}; - -GameLib.API.Controls.prototype = Object.create(GameLib.API.Component.prototype); -GameLib.API.Controls.prototype.constructor = GameLib.API.Controls; - -GameLib.API.Controls.GetComponentType = function(controlsType) { - - var componentType = null; - - switch (controlsType) { - case GameLib.API.Controls.CONTROLS_TYPE_NONE : - componentType = GameLib.Component.CONTROLS; - break; - case GameLib.API.Controls.CONTROLS_TYPE_TOUCH : - componentType = GameLib.Component.CONTROLS_TOUCH; - break; - case GameLib.API.Controls.CONTROLS_TYPE_KEYBOARD : - componentType = GameLib.Component.CONTROLS_KEYBOARD; - break; - case GameLib.API.Controls.CONTROLS_TYPE_MOUSE : - componentType = GameLib.Component.CONTROLS_MOUSE; - break; - case GameLib.API.Controls.CONTROLS_TYPE_EDITOR : - componentType = GameLib.Component.CONTROLS_EDITOR; - break; - case GameLib.API.Controls.CONTROLS_TYPE_ORBIT : - componentType = GameLib.Component.CONTROLS_ORBIT; - break; - default : - throw new Error('unhandled controls type: ' + controlsType); - break; - } - - return componentType; -}; - -GameLib.API.Controls.D3 = function() {}; - -/** - * Controls Type - * @type {number} - */ -GameLib.API.Controls.CONTROLS_TYPE_NONE = 0x0; -GameLib.API.Controls.CONTROLS_TYPE_TOUCH = 0x1; -GameLib.API.Controls.CONTROLS_TYPE_KEYBOARD = 0x2; -GameLib.API.Controls.CONTROLS_TYPE_MOUSE = 0x3; -GameLib.API.Controls.CONTROLS_TYPE_EDITOR = 0x4; -GameLib.API.Controls.CONTROLS_TYPE_FIRST_PERSON = 0x5; -GameLib.API.Controls.CONTROLS_TYPE_ORBIT = 0x6; diff --git a/src/game-lib-api-controls-d3-editor.js b/src/game-lib-api-controls-d3-editor.js deleted file mode 100644 index f3bdb1f..0000000 --- a/src/game-lib-api-controls-d3-editor.js +++ /dev/null @@ -1,44 +0,0 @@ -/** - * @param apiControls - * @param raycaster - * @param camera - * @constructor - */ -GameLib.API.Controls.D3.Editor = function( - apiControls, - raycaster, - camera -) { - - if (GameLib.Utils.UndefinedOrNull(apiControls)) { - apiControls = { - controlsType : GameLib.API.Controls.CONTROLS_TYPE_EDITOR - }; - } - - if (GameLib.Utils.UndefinedOrNull(apiControls.controlsType)) { - apiControls.controlsType = GameLib.API.Controls.CONTROLS_TYPE_EDITOR; - } - - if (GameLib.Utils.UndefinedOrNull(raycaster)) { - raycaster = new GameLib.D3.API.Raycaster(); - } - this.raycaster = raycaster; - - if (GameLib.Utils.UndefinedOrNull(camera)) { - camera = null; - } - this.camera = camera; - - GameLib.API.Controls.call( - this, - apiControls.id, - apiControls.name, - apiControls.controlsType, - apiControls.canvas, - apiControls.parentEntity - ); -}; - -GameLib.API.Controls.D3.Editor.prototype = Object.create(GameLib.API.Controls.prototype); -GameLib.API.Controls.D3.Editor.prototype.constructor = GameLib.API.Controls.D3.Editor; diff --git a/src/game-lib-api-controls-keyboard.js b/src/game-lib-api-controls-keyboard.js deleted file mode 100644 index e829851..0000000 --- a/src/game-lib-api-controls-keyboard.js +++ /dev/null @@ -1,30 +0,0 @@ -/** - * @param apiControls - * @constructor - */ -GameLib.API.Controls.Keyboard = function( - apiControls -) { - - if (GameLib.Utils.UndefinedOrNull(apiControls)) { - apiControls = { - controlsType : GameLib.API.Controls.CONTROLS_TYPE_KEYBOARD - }; - } - - if (GameLib.Utils.UndefinedOrNull(apiControls.controlsType)) { - apiControls.controlsType = GameLib.API.Controls.CONTROLS_TYPE_KEYBOARD; - } - - GameLib.API.Controls.call( - this, - apiControls.id, - apiControls.name, - apiControls.controlsType, - apiControls.canvas, - apiControls.parentEntity - ); -}; - -GameLib.API.Controls.Keyboard.prototype = Object.create(GameLib.API.Controls.prototype); -GameLib.API.Controls.Keyboard.prototype.constructor = GameLib.API.Controls.Keyboard; diff --git a/src/game-lib-api-controls-mouse.js b/src/game-lib-api-controls-mouse.js deleted file mode 100644 index c557ba4..0000000 --- a/src/game-lib-api-controls-mouse.js +++ /dev/null @@ -1,31 +0,0 @@ -/** - * @param apiControls - * @constructor - */ -GameLib.API.Controls.Mouse = function( - apiControls -) { - - if (GameLib.Utils.UndefinedOrNull(apiControls)) { - apiControls = { - controlsType : GameLib.API.Controls.CONTROLS_TYPE_MOUSE - }; - } - - if (GameLib.Utils.UndefinedOrNull(apiControls.controlsType)) { - apiControls.controlsType = GameLib.API.Controls.CONTROLS_TYPE_MOUSE; - } - - GameLib.API.Controls.call( - this, - apiControls.id, - apiControls.name, - apiControls.controlsType, - apiControls.canvas, - apiControls.parentEntity - ); -}; - -GameLib.API.Controls.Mouse.prototype = Object.create(GameLib.API.Controls.prototype); -GameLib.API.Controls.Mouse.prototype.constructor = GameLib.API.Controls.Mouse; - diff --git a/src/game-lib-api-controls-touch.js b/src/game-lib-api-controls-touch.js deleted file mode 100644 index 296d292..0000000 --- a/src/game-lib-api-controls-touch.js +++ /dev/null @@ -1,37 +0,0 @@ -/** - * @param apiControls - * @param sensitivity - * @constructor - */ -GameLib.API.Controls.Touch = function( - apiControls, - sensitivity -) { - - if (GameLib.Utils.UndefinedOrNull(apiControls)) { - apiControls = { - controlsType : GameLib.API.Controls.CONTROLS_TYPE_TOUCH - }; - } - - if (GameLib.Utils.UndefinedOrNull(apiControls.controlsType)) { - apiControls.controlsType = GameLib.API.Controls.CONTROLS_TYPE_TOUCH; - } - - if (GameLib.Utils.UndefinedOrNull(sensitivity)) { - sensitivity = 5; - } - this.sensitivity = sensitivity; - - GameLib.API.Controls.call( - this, - apiControls.id, - apiControls.name, - apiControls.controlsType, - apiControls.canvas, - apiControls.parentEntity - ); -}; - -GameLib.API.Controls.Touch.prototype = Object.create(GameLib.API.Controls.prototype); -GameLib.API.Controls.Touch.prototype.constructor = GameLib.API.Controls.Touch; diff --git a/src/game-lib-api-curve-a.js b/src/game-lib-api-curve-a.js deleted file mode 100644 index 35b871c..0000000 --- a/src/game-lib-api-curve-a.js +++ /dev/null @@ -1,89 +0,0 @@ -/** - * GameLib.API.Curve - * @param id - * @param name - * @param curveType - * @param parentEntity - * @param arcLenghDivisions - * @constructor - */ -GameLib.API.Curve = function ( - id, - name, - curveType, - parentEntity, - arcLenghDivisions -) { - - if (GameLib.Utils.UndefinedOrNull(id)) { - id = GameLib.Utils.RandomId(); - } - this.id = id; - - if (GameLib.Utils.UndefinedOrNull(curveType)) { - curveType = GameLib.API.Curve.CURVE_TYPE_NONE; - } - this.curveType = curveType; - - if (GameLib.Utils.UndefinedOrNull(name)) { - - switch (this.curveType) { - case GameLib.API.Curve.CURVE_TYPE_NONE : - name = 'Curve'; - break; - case GameLib.API.Curve.CURVE_TYPE_PATH : - name = 'Curve Path'; - break; - default: - console.log('no nice name for curve'); - } - - name += ' (' + this.id + ')'; - } - this.name = name; - - if (GameLib.Utils.UndefinedOrNull(arcLenghDivisions)) { - arcLenghDivisions = 200; - } - this.arcLenghDivisions = arcLenghDivisions; - - GameLib.API.Component.call( - this, - GameLib.API.Curve.GetComponentType(this.curveType), - parentEntity - ); -}; - -GameLib.API.Curve.prototype = Object.create(GameLib.API.Curve.prototype); -GameLib.API.Curve.prototype.constructor = GameLib.API.Curve; - -GameLib.API.Curve.GetComponentType = function(curveType) { - - var componentType = null; - - switch (curveType) { - case GameLib.API.Curve.CURVE_TYPE_NONE : - componentType = GameLib.Component.CURVE; - break; - case GameLib.API.Curve.CURVE_TYPE_PATH : - componentType = GameLib.Component.CURVE_PATH; - break; - case GameLib.API.Curve.CURVE_TYPE_PATH_2D : - componentType = GameLib.Component.CURVE_PATH_D2; - break; - case GameLib.API.Curve.CURVE_TYPE_PATH_2D_SHAPE : - componentType = GameLib.Component.CURVE_PATH_D2_SHAPE; - break; - default : - throw new Error('unhandled curve type'); - } - - return componentType; -}; - -GameLib.API.Curve.CURVE_TYPE_NONE = 0x0; -GameLib.API.Curve.CURVE_TYPE_PATH = 0x1; -GameLib.API.Curve.CURVE_TYPE_PATH_2D = 0x2; -GameLib.API.Curve.CURVE_TYPE_PATH_2D_SHAPE = 0x3; - - diff --git a/src/game-lib-api-curve-path-a.js b/src/game-lib-api-curve-path-a.js deleted file mode 100644 index d2e0e6d..0000000 --- a/src/game-lib-api-curve-path-a.js +++ /dev/null @@ -1,44 +0,0 @@ -/** - * GameLib.API.Curve.Path - * @constructor - * @param apiCurve - * @param curves - * @param autoClose - */ -GameLib.API.Curve.Path = function ( - apiCurve, - curves, - autoClose -) { - if (GameLib.Utils.UndefinedOrNull(apiCurve)) { - apiCurve = { - curveType: GameLib.API.Curve.CURVE_TYPE_PATH - }; - } - - if (GameLib.Utils.UndefinedOrNull(apiCurve.curveType)) { - apiCurve.curveType = GameLib.API.Curve.CURVE_TYPE_PATH; - } - - if (GameLib.Utils.UndefinedOrNull(curves)) { - curves = []; - } - this.curves = curves; - - if (GameLib.Utils.UndefinedOrNull(autoClose)) { - autoClose = false; - } - this.autoClose = autoClose; - - GameLib.API.Curve.call( - this, - apiCurve.id, - apiCurve.name, - apiCurve.curveType, - apiCurve.parentEntity, - apiCurve.arcLenghDivisions - ); -}; - -GameLib.API.Curve.Path.prototype = Object.create(GameLib.API.Curve.prototype); -GameLib.API.Curve.Path.prototype.constructor = GameLib.API.Curve.Path; diff --git a/src/game-lib-api-curve-path-d2-a.js b/src/game-lib-api-curve-path-d2-a.js deleted file mode 100644 index fca147c..0000000 --- a/src/game-lib-api-curve-path-d2-a.js +++ /dev/null @@ -1,35 +0,0 @@ -/** - * GameLib.API.Curve.Path.D2 - * @constructor - * @param apiCurvePath - * @param points - */ -GameLib.API.Curve.Path.D2 = function ( - apiCurvePath, - points -) { - if (GameLib.Utils.UndefinedOrNull(apiCurvePath)) { - apiCurvePath = { - curveType: GameLib.API.Curve.CURVE_TYPE_PATH_2D - }; - } - - if (GameLib.Utils.UndefinedOrNull(apiCurvePath.curveType)) { - apiCurvePath.curveType = GameLib.API.Curve.CURVE_TYPE_PATH_2D; - } - - if (GameLib.Utils.UndefinedOrNull(points)) { - points = []; - } - this.points = points; - - GameLib.API.Curve.Path.call( - this, - apiCurvePath, - apiCurvePath.curves, - apiCurvePath.autoClose - ); -}; - -GameLib.API.Curve.Path.D2.prototype = Object.create(GameLib.API.Curve.Path.prototype); -GameLib.API.Curve.Path.D2.prototype.constructor = GameLib.API.Curve.Path.D2; diff --git a/src/game-lib-api-curve-path-d2-shape.js b/src/game-lib-api-curve-path-d2-shape.js deleted file mode 100644 index dd88a66..0000000 --- a/src/game-lib-api-curve-path-d2-shape.js +++ /dev/null @@ -1,27 +0,0 @@ -/** - * GameLib.API.Curve.Path.D2.Shape - * @constructor - * @param apiCurvePathD2 - */ -GameLib.API.Curve.Path.D2.Shape = function ( - apiCurvePathD2 -) { - if (GameLib.Utils.UndefinedOrNull(apiCurvePathD2)) { - apiCurvePathD2 = { - curveType : GameLib.API.Curve.CURVE_TYPE_PATH_2D_SHAPE - }; - } - - if (GameLib.Utils.UndefinedOrNull(apiCurvePathD2.curveType)) { - apiCurvePathD2.curveType = GameLib.API.Curve.CURVE_TYPE_PATH_2D_SHAPE ; - } - - GameLib.API.Curve.Path.call( - this, - apiCurvePathD2, - apiCurvePathD2.points - ); -}; - -GameLib.API.Curve.Path.D2.Shape.prototype = Object.create(GameLib.API.Curve.Path.D2.prototype); -GameLib.API.Curve.Path.D2.Shape.prototype.constructor = GameLib.API.Curve.Path.D2.Shape; diff --git a/src/game-lib-api-custom-code.js b/src/game-lib-api-custom-code.js deleted file mode 100644 index 1f414b3..0000000 --- a/src/game-lib-api-custom-code.js +++ /dev/null @@ -1,45 +0,0 @@ -/** - * Custom Code Component - * @param id - * @param name - * @param eventId - * @param code - * @param parentEntity - * @constructor - */ -GameLib.API.CustomCode = function ( - id, - name, - eventId, - code, - parentEntity -) { - if (GameLib.Utils.UndefinedOrNull(id)) { - id = GameLib.Utils.RandomId(); - } - this.id = id; - - if (GameLib.Utils.UndefinedOrNull(name)) { - name = 'CustomCode (' + this.id + ')'; - } - this.name = name; - - if (GameLib.Utils.UndefinedOrNull(eventId)) { - eventId = 42; - } - this.eventId = eventId; - - if (GameLib.Utils.UndefinedOrNull(code)) { - code = "return null;\n//@ sourceURL=" + this.name + ".js"; - } - this.code = code; - - GameLib.API.Component.call( - this, - GameLib.Component.CUSTOM_CODE, - parentEntity - ); -}; - -GameLib.API.CustomCode.prototype = Object.create(GameLib.API.Component.prototype); -GameLib.API.CustomCode.prototype.constructor = GameLib.API.CustomCode; diff --git a/src/game-lib-api-draw-range.js b/src/game-lib-api-draw-range.js deleted file mode 100644 index a829787..0000000 --- a/src/game-lib-api-draw-range.js +++ /dev/null @@ -1,45 +0,0 @@ -/** - * GameLib.API.Box3 - * @constructor - * @param id - * @param name - * @param parentEntity - * @param start - * @param count - */ -GameLib.API.DrawRange = function ( - id, - name, - parentEntity, - start, - count -) { - if (GameLib.Utils.UndefinedOrNull(id)) { - id = GameLib.Utils.RandomId(); - } - this.id = id; - - if (GameLib.Utils.UndefinedOrNull(name)) { - name = 'DrawRange (' + id + ')'; - } - this.name = name; - - if (GameLib.Utils.UndefinedOrNull(start)) { - start = 0; - } - this.start = start; - - if (GameLib.Utils.UndefinedOrNull(count)) { - count = Infinity; - } - this.count = count; - - GameLib.API.Component.call( - this, - GameLib.Component.DRAW_RANGE, - parentEntity - ) -}; - -GameLib.API.DrawRange.prototype = Object.create(GameLib.API.Component.prototype); -GameLib.API.DrawRange.prototype.constructor = GameLib.API.DrawRange; diff --git a/src/game-lib-api-graphics-runtime-a.js b/src/game-lib-api-graphics-runtime-a.js deleted file mode 100644 index 6cb9032..0000000 --- a/src/game-lib-api-graphics-runtime-a.js +++ /dev/null @@ -1,64 +0,0 @@ -/** - * GameLib.API.GraphicsRuntime - * @param id - * @param name - * @param graphicsType - * @param parentEntity - * @constructor - */ -GameLib.API.GraphicsRuntime = function( - id, - name, - graphicsType, - parentEntity -) { - if (GameLib.Utils.UndefinedOrNull(id)) { - id = GameLib.Utils.RandomId(); - } - this.id = id; - - if (GameLib.Utils.UndefinedOrNull(name)) { - name = 'Graphics Runtime (' + id + ')'; - } - this.name = name; - - if (GameLib.Utils.UndefinedOrNull(graphicsType)) { - graphicsType = null; - } - this.graphicsType = graphicsType; - - GameLib.API.Component.call( - this, - GameLib.API.GraphicsRuntime.GetComponentType(this.graphicsType), - parentEntity - ); -}; - -GameLib.API.GraphicsRuntime.prototype = Object.create(GameLib.API.Component.prototype); -GameLib.API.GraphicsRuntime.prototype.constructor = GameLib.API.GraphicsRuntime; - -GameLib.API.GraphicsRuntime.GetComponentType = function(graphicsType) { - - var componentType = null; - - switch (graphicsType) { - case GameLib.API.GraphicsRuntime.GRAPHICS_TYPE_NONE : - componentType = GameLib.Component.GRAPHICS; - break; - case GameLib.API.GraphicsRuntime.GRAPHICS_TYPE_THREE_JS : - componentType = GameLib.Component.GRAPHICS_THREE; - break; - case GameLib.API.GraphicsRuntime.GRAPHICS_TYPE_IMPACT_JS : - componentType = GameLib.Component.GRAPHICS_IMPACT; - break; - default: - throw new Error('Invalid graphics type'); - - } - - return componentType; -}; - -GameLib.API.GraphicsRuntime.GRAPHICS_TYPE_NONE = 0x0; -GameLib.API.GraphicsRuntime.GRAPHICS_TYPE_THREE_JS = 0x1; -GameLib.API.GraphicsRuntime.GRAPHICS_TYPE_IMPACT_JS = 0x2; diff --git a/src/game-lib-api-graphics-runtime-impact.js b/src/game-lib-api-graphics-runtime-impact.js deleted file mode 100644 index 488568d..0000000 --- a/src/game-lib-api-graphics-runtime-impact.js +++ /dev/null @@ -1,30 +0,0 @@ -/** - * GameLib.API.GraphicsRuntime.Impact - * @constructor - * @param apiGraphicsRuntime - */ -GameLib.API.GraphicsRuntime.Impact = function( - apiGraphicsRuntime -) { - if (GameLib.Utils.UndefinedOrNull(apiGraphicsRuntime)) { - apiGraphicsRuntime = { - graphicsType : GameLib.API.GraphicsRuntime.GRAPHICS_TYPE_IMPACT_JS - }; - } - - if (GameLib.Utils.UndefinedOrNull(apiGraphicsRuntime.graphicsType)) { - apiGraphicsRuntime.graphicsType = GameLib.API.GraphicsRuntime.GRAPHICS_TYPE_IMPACT_JS; - } - - GameLib.API.GraphicsRuntime.call( - this, - apiGraphicsRuntime.id, - apiGraphicsRuntime.name, - apiGraphicsRuntime.graphicsType, - apiGraphicsRuntime.parentEntity - ); - -}; - -GameLib.API.GraphicsRuntime.Impact.prototype = Object.create(GameLib.API.GraphicsRuntime.prototype); -GameLib.API.GraphicsRuntime.Impact.prototype.constructor = GameLib.API.GraphicsRuntime.Impact; diff --git a/src/game-lib-api-graphics-runtime-three.js b/src/game-lib-api-graphics-runtime-three.js deleted file mode 100644 index 5c07759..0000000 --- a/src/game-lib-api-graphics-runtime-three.js +++ /dev/null @@ -1,30 +0,0 @@ -/** - * GameLib.API.GraphicsRuntime.Three - * @constructor - * @param apiGraphicsRuntime - */ -GameLib.API.GraphicsRuntime.Three = function( - apiGraphicsRuntime -) { - if (GameLib.Utils.UndefinedOrNull(apiGraphicsRuntime)) { - apiGraphicsRuntime = { - graphicsType : GameLib.API.GraphicsRuntime.GRAPHICS_TYPE_THREE_JS - }; - } - - if (GameLib.Utils.UndefinedOrNull(apiGraphicsRuntime.graphicsType)) { - apiGraphicsRuntime.graphicsType = GameLib.API.GraphicsRuntime.GRAPHICS_TYPE_THREE_JS; - } - - GameLib.API.GraphicsRuntime.call( - this, - apiGraphicsRuntime.id, - apiGraphicsRuntime.name, - apiGraphicsRuntime.graphicsType, - apiGraphicsRuntime.parentEntity - ); - -}; - -GameLib.API.GraphicsRuntime.Three.prototype = Object.create(GameLib.API.GraphicsRuntime.prototype); -GameLib.API.GraphicsRuntime.Three.prototype.constructor = GameLib.API.GraphicsRuntime.Three; diff --git a/src/game-lib-api-group.js b/src/game-lib-api-group.js deleted file mode 100644 index 2406cf2..0000000 --- a/src/game-lib-api-group.js +++ /dev/null @@ -1,52 +0,0 @@ -/** - * GameLib.API.Group - * @constructor - * @param id - * @param name - * @param parentEntity - * @param start - * @param count - * @param materialIndex - */ -GameLib.API.Group = function ( - id, - name, - parentEntity, - start, - count, - materialIndex -) { - if (GameLib.Utils.UndefinedOrNull(id)) { - id = GameLib.Utils.RandomId(); - } - this.id = id; - - if (GameLib.Utils.UndefinedOrNull(name)) { - name = 'Group (' + id + ')'; - } - this.name = name; - - if (GameLib.Utils.UndefinedOrNull(start)) { - start = 0; - } - this.start = start; - - if (GameLib.Utils.UndefinedOrNull(count)) { - count = 0; - } - this.count = count; - - if (GameLib.Utils.UndefinedOrNull(materialIndex)) { - materialIndex = 0; - } - this.materialIndex = materialIndex; - - GameLib.API.Component.call( - this, - GameLib.Component.GROUP, - parentEntity - ) -}; - -GameLib.API.Group.prototype = Object.create(GameLib.API.Component.prototype); -GameLib.API.Group.prototype.constructor = GameLib.API.Group; diff --git a/src/game-lib-api-matrix4.js b/src/game-lib-api-matrix4.js deleted file mode 100644 index 1eb4b9f..0000000 --- a/src/game-lib-api-matrix4.js +++ /dev/null @@ -1,159 +0,0 @@ -/** - * Api Matrix 4 - * @param row0 GameLib.API.Vector4 - * @param row1 GameLib.API.Vector4 - * @param row2 GameLib.API.Vector4 - * @param row3 GameLib.API.Vector4 - * @constructor - */ -GameLib.API.Matrix4 = function ApiMatrix4( - row0, - row1, - row2, - row3 -) { - this.rows = []; - - if (GameLib.Utils.UndefinedOrNull(row0)) { - row0 = new GameLib.API.Vector4(1, 0, 0, 0); - } - this.rows[0] = row0; - - if (GameLib.Utils.UndefinedOrNull(row1)) { - row1 = new GameLib.API.Vector4(0, 1, 0, 0); - } - this.rows[1] = row1; - - if (GameLib.Utils.UndefinedOrNull(row2)) { - row2 = new GameLib.API.Vector4(0, 0, 1, 0); - } - this.rows[2] = row2; - - if (GameLib.Utils.UndefinedOrNull(row3)) { - row3 = new GameLib.API.Vector4(0, 0, 0, 1); - } - this.rows[3] = row3; - - 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(); -}; - -/** - * Returns an API matrix from an Object matrix - * @param objectMatrix - * @constructor - */ -GameLib.API.Matrix4.FromObject = function(objectMatrix) { - - if (objectMatrix.rows) { - return new GameLib.API.Matrix4( - GameLib.API.Vector4.FromObject(objectMatrix.rows[0]), - GameLib.API.Vector4.FromObject(objectMatrix.rows[1]), - GameLib.API.Vector4.FromObject(objectMatrix.rows[2]), - GameLib.API.Vector4.FromObject(objectMatrix.rows[3]) - ); - } else if (objectMatrix instanceof Array) { - return new GameLib.API.Matrix4( - GameLib.API.Vector4.FromObject(objectMatrix[0]), - GameLib.API.Vector4.FromObject(objectMatrix[1]), - GameLib.API.Vector4.FromObject(objectMatrix[2]), - GameLib.API.Vector4.FromObject(objectMatrix[3]) - ); - } else { - console.warn('Unsupported object matrix type - whats your DB version?'); - throw new Error('Unsupported object matrix type - whats your DB version?'); - } -}; - -GameLib.API.Matrix4.prototype.rotationMatrixX = function (radians) { - this.identity(); - this.rows[1] = new GameLib.API.Vector4(0, Math.cos(radians), -1 * Math.sin(radians), 0); - this.rows[2] = new GameLib.API.Vector4(0, Math.sin(radians), Math.cos(radians), 0); - return this; -}; - -GameLib.API.Matrix4.prototype.rotationMatrixY = function (radians) { - this.identity(); - this.rows[0] = new GameLib.API.Vector4( - Math.cos(radians), - 0, - Math.sin(radians), - 0 - ); - this.rows[2] = new GameLib.API.Vector4( - -1 * Math.sin(radians), - 0, - Math.cos(radians), - 0 - ); - return this; -}; - -GameLib.API.Matrix4.prototype.rotationMatrixZ = function (radians) { - this.identity(); - this.rows[0] = new GameLib.API.Vector4(Math.cos(radians), -1 * Math.sin(radians), 0, 0); - this.rows[1] = new GameLib.API.Vector4(Math.sin(radians), Math.cos(radians), 0, 0); - return this; -}; - -GameLib.API.Matrix4.prototype.rotateX = function (radians, point) { - this.identity(); - this.rotationMatrixX(radians); - return this.multiply(point); -}; - -GameLib.API.Matrix4.prototype.rotateY = function (radians, point) { - this.identity(); - this.rotationMatrixY(radians); - return this.multiply(point); -}; - -GameLib.API.Matrix4.prototype.rotateZ = function (radians, point) { - this.identity(); - this.rotationMatrixZ(radians); - return this.multiply(point); -}; - -GameLib.API.Matrix4.prototype.multiply = function (mvp) { - if (mvp instanceof GameLib.API.Quaternion || mvp instanceof GameLib.API.Vector4) { - return new GameLib.API.Quaternion( - this.rows[0].x * mvp.x + this.rows[0].y * mvp.y + this.rows[0].z * mvp.z + this.rows[0].w * mvp.w, - this.rows[1].x * mvp.x + this.rows[1].y * mvp.y + this.rows[1].z * mvp.z + this.rows[1].w * mvp.w, - this.rows[2].x * mvp.x + this.rows[2].y * mvp.y + this.rows[2].z * mvp.z + this.rows[2].w * mvp.w, - this.rows[3].x * mvp.x + this.rows[3].y * mvp.y + this.rows[3].z * mvp.z + this.rows[3].w * mvp.w - ); - } else if (mvp instanceof GameLib.API.Vector3) { - return new GameLib.API.Vector3( - this.rows[0].x * mvp.x + this.rows[0].y * mvp.y + this.rows[0].z * mvp.z, - this.rows[1].x * mvp.x + this.rows[1].y * mvp.y + this.rows[1].z * mvp.z, - this.rows[2].x * mvp.x + this.rows[2].y * mvp.y + this.rows[2].z * mvp.z - ); - } -}; - -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) - ]; -}; diff --git a/src/game-lib-api-mouse.js b/src/game-lib-api-mouse.js deleted file mode 100644 index a986b48..0000000 --- a/src/game-lib-api-mouse.js +++ /dev/null @@ -1,45 +0,0 @@ -/** - * API Mouse - * @param id - * @param name - * @param parentEntity - * @param x - * @param y - * @constructor - */ -GameLib.API.Mouse = function( - id, - name, - parentEntity, - x, - y -) { - if (GameLib.Utils.UndefinedOrNull(id)) { - id = GameLib.Utils.RandomId(); - } - this.id = id; - - if (GameLib.Utils.UndefinedOrNull(name)) { - name = 'Mouse (' + this.id + ')'; - } - this.name = name; - - if (GameLib.Utils.UndefinedOrNull(x)) { - x = 0; - } - this.x = x; - - if (GameLib.Utils.UndefinedOrNull(y)) { - y = 0; - } - this.y = y; - - GameLib.API.Component.call( - this, - GameLib.Component.MOUSE, - parentEntity - ); -}; - -GameLib.API.Mouse.prototype = Object.create(GameLib.API.Component.prototype); -GameLib.API.Mouse.prototype.constructor = GameLib.API.Mouse; diff --git a/src/game-lib-api-plane.js b/src/game-lib-api-plane.js deleted file mode 100644 index 15de4b8..0000000 --- a/src/game-lib-api-plane.js +++ /dev/null @@ -1,53 +0,0 @@ -GameLib.API.Plane = function ( - id, - name, - normal, - constant, - parentEntity -) { - - if (GameLib.Utils.UndefinedOrNull(id)) { - id = GameLib.Utils.RandomId(); - } - this.id = id; - - if (GameLib.Utils.UndefinedOrNull(name)) { - name = 'Plane (' + this.id + ')'; - } - this.name = name; - - if (GameLib.Utils.UndefinedOrNull(normal)) { - normal = new GameLib.API.Vector3(1,0,0); - } - this.normal = normal; - - if (GameLib.Utils.UndefinedOrNull(constant)) { - constant = 0; - } - this.constant = constant; - - GameLib.API.Component.call( - this, - GameLib.Component.PLANE, - parentEntity - ); -}; - - -GameLib.API.Plane.prototype = Object.create(GameLib.API.Component.prototype); -GameLib.API.Plane.prototype.constructor = GameLib.API.Plane; - -/** - * Returns an API vector from an Object vector - * @param objectPlane - * @constructor - */ -GameLib.API.Plane.FromObject = function (objectPlane) { - return new GameLib.API.Plane( - objectPlane.id, - objectPlane.name, - GameLib.API.Vector3.FromObject(objectPlane.normal), - objectPlane.constant, - objectPlane.parentEntity - ); -}; diff --git a/src/game-lib-api-render-configuration.js b/src/game-lib-api-render-configuration.js deleted file mode 100644 index f0a85e6..0000000 --- a/src/game-lib-api-render-configuration.js +++ /dev/null @@ -1,117 +0,0 @@ -/** - * GameLib.API.RenderConfiguration - * @param id - * @param name - * @param parentEntity - * @param logicalSize - * @param aspectRatio - * @param scaleMode - * @param activeCamera - * @param activeScenes - * @param activeComposer - * @param activeEffect - * @param activeRenderer - * @param enableComposer - * @param enableEffect - * @constructor - */ -GameLib.API.RenderConfiguration = function ( - id, - name, - parentEntity, - logicalSize, - aspectRatio, - scaleMode, - activeCamera, - activeScenes, - activeRenderer, - activeComposer, - activeEffect, - enableComposer, - enableEffect -) { - if (GameLib.Utils.UndefinedOrNull(id)) { - id = GameLib.Utils.RandomId(); - } - this.id = id; - - if (GameLib.Utils.UndefinedOrNull(name)) { - name = "RenderConfiguration (" + this.id + ")"; - } - this.name = name; - - if (GameLib.Utils.UndefinedOrNull(logicalSize)) { - logicalSize = new GameLib.API.Vector2( - 480, - 320 - ); - } - this.logicalSize = logicalSize; - - if (GameLib.Utils.UndefinedOrNull(aspectRatio)) { - aspectRatio = GameLib.API.Renderer.ASPECT_RATIO_3_2; - } - this.aspectRatio = aspectRatio; - - if (GameLib.Utils.UndefinedOrNull(scaleMode)) { - scaleMode = GameLib.API.Renderer.SCALE_MODE_LETTERBOX; - } - this.scaleMode = scaleMode; - - if (GameLib.Utils.UndefinedOrNull(activeCamera)) { - activeCamera = null; - } - this.activeCamera = activeCamera; - - if (GameLib.Utils.UndefinedOrNull(activeScenes)) { - activeScenes = []; - } - this.activeScenes = activeScenes; - - if (GameLib.Utils.UndefinedOrNull(activeRenderer)) { - activeRenderer = null; - } - this.activeRenderer = activeRenderer; - - if (GameLib.Utils.UndefinedOrNull(activeComposer)) { - activeComposer = null; - } - this.activeComposer = activeComposer; - - if (GameLib.Utils.UndefinedOrNull(activeEffect)) { - activeEffect = null; - } - this.activeEffect = activeEffect; - - if (GameLib.Utils.UndefinedOrNull(enableComposer)) { - enableComposer = false; - } - this.enableComposer = enableComposer; - - if (GameLib.Utils.UndefinedOrNull(enableEffect)) { - enableEffect = false; - } - this.enableEffect = enableEffect; - - GameLib.API.Component.call( - this, - GameLib.Component.RENDER_CONFIGURATION, - parentEntity - ); - -}; - -GameLib.API.RenderConfiguration.prototype = Object.create(GameLib.API.Component.prototype); -GameLib.API.RenderConfiguration.prototype.constructor = GameLib.API.RenderConfiguration; - -GameLib.API.RenderConfiguration.ASPECT_RATIO_NONE = 0x1; -GameLib.API.RenderConfiguration.ASPECT_RATIO_4_3 = 0x2; -GameLib.API.RenderConfiguration.ASPECT_RATIO_3_2 = 0x3; -GameLib.API.RenderConfiguration.ASPECT_RATIO_16_10 = 0x4; -GameLib.API.RenderConfiguration.ASPECT_RATIO_17_10 = 0x5; -GameLib.API.RenderConfiguration.ASPECT_RATIO_16_9 = 0x6; - -GameLib.API.RenderConfiguration.SCALE_MODE_NONE = 0x1; -GameLib.API.RenderConfiguration.SCALE_MODE_LETTERBOX = 0x2; -GameLib.API.RenderConfiguration.SCALE_MODE_ZOOM_TO_BIGGER = 0x3; -GameLib.API.RenderConfiguration.SCALE_MODE_NON_UNIFORM = 0x4; diff --git a/src/game-lib-api-renderer-a.js b/src/game-lib-api-renderer-a.js deleted file mode 100644 index 4367ce5..0000000 --- a/src/game-lib-api-renderer-a.js +++ /dev/null @@ -1,122 +0,0 @@ -/** - * GameLib.API.Renderer - * @param id - * @param name - * @param rendererType - * @param parentEntity - * @param width - * @param height - * @param offset - * @param canvas - * @constructor - */ -GameLib.API.Renderer = function ( - id, - name, - rendererType, - parentEntity, - width, - height, - offset, - canvas -) { - if (GameLib.Utils.UndefinedOrNull(id)) { - id = GameLib.Utils.RandomId(); - } - this.id = id; - - if (GameLib.Utils.UndefinedOrNull(rendererType)) { - rendererType = GameLib.API.Renderer.RENDERER_TYPE_NONE; - } - this.rendererType = rendererType; - - if (GameLib.Utils.UndefinedOrNull(name)) { - - switch (this.rendererType) { - case GameLib.API.Renderer.RENDERER_TYPE_NONE : - name = "Renderer"; - break; - case GameLib.API.Renderer.RENDERER_TYPE_2D : - name = "Renderer 2D"; - break; - case GameLib.API.Renderer.RENDERER_TYPE_3D : - name = "Renderer 3D"; - break; - default : - console.warn('no nice name for renderer'); - break; - } - - name += " (" + this.id + ")"; - } - this.name = name; - - if (GameLib.Utils.UndefinedOrNull(width)) { - width = 1; - } - this.width = width; - - if (GameLib.Utils.UndefinedOrNull(height)) { - height = 1; - } - this.height = height; - - if (GameLib.Utils.UndefinedOrNull(offset)) { - offset = new GameLib.API.Vector2(0,0); - } - this.offset = offset; - - if (GameLib.Utils.UndefinedOrNull(canvas)) { - canvas = new GameLib.API.Canvas(); - } - this.canvas = canvas; - - GameLib.API.Component.call( - this, - GameLib.API.Renderer.GetComponentType(this.rendererType), - parentEntity - ); - -}; - -GameLib.API.Renderer.prototype = Object.create(GameLib.API.Component.prototype); -GameLib.API.Renderer.prototype.constructor = GameLib.API.Renderer; - -GameLib.API.Renderer.GetComponentType = function(rendererType) { - - var componentType = null; - - switch (rendererType) { - case GameLib.API.Renderer.RENDERER_TYPE_NONE : - componentType = GameLib.Component.RENDERER; - break; - case GameLib.API.Renderer.RENDERER_TYPE_2D : - componentType = GameLib.Component.RENDERER_D2; - break; - case GameLib.API.Renderer.RENDERER_TYPE_3D : - componentType = GameLib.Component.RENDERER_D3; - break; - default : - console.warn('could not determine component type'); - break; - } - - return componentType; -}; - -GameLib.API.Renderer.RENDERER_TYPE_NONE = 0x0; -GameLib.API.Renderer.RENDERER_TYPE_2D = 0x1; -GameLib.API.Renderer.RENDERER_TYPE_3D = 0x2; - -GameLib.API.Renderer.MODE_CANVAS = 0x1; -GameLib.API.Renderer.MODE_TARGET = 0x2; -GameLib.API.Renderer.MODE_CANVAS_AND_TARGET = 0x3; - -GameLib.API.Renderer.SHADOW_MAP_TYPE_BASIC = 0; -GameLib.API.Renderer.SHADOW_MAP_TYPE_PCF = 1; -GameLib.API.Renderer.SHADOW_MAP_TYPE_PCF_SOFT = 2; - -GameLib.API.Renderer.TONE_MAPPING_LINEAR = 1; -GameLib.API.Renderer.TONE_MAPPING_REINHARD = 2; -GameLib.API.Renderer.TONE_MAPPING_UNCHARTED_2 = 3; -GameLib.API.Renderer.TONE_MAPPING_CINEON = 4; diff --git a/src/game-lib-api-renderer-d2.js b/src/game-lib-api-renderer-d2.js deleted file mode 100644 index fe11f87..0000000 --- a/src/game-lib-api-renderer-d2.js +++ /dev/null @@ -1,35 +0,0 @@ -/** - * GameLib.API.Renderer.D2 - * @constructor - * @param apiRenderer - */ -GameLib.API.Renderer.D2 = function ( - apiRenderer -) { - - if (GameLib.Utils.UndefinedOrNull(apiRenderer)) { - apiRenderer = { - rendererType : GameLib.API.Renderer.RENDERER_TYPE_2D - }; - } - - if (GameLib.Utils.UndefinedOrNull(apiRenderer.rendererType)) { - apiRenderer.rendererType = GameLib.API.Renderer.RENDERER_TYPE_2D; - } - - GameLib.API.Renderer.call( - this, - apiRenderer.id, - apiRenderer.name, - apiRenderer.rendererType, - apiRenderer.parentEntity, - apiRenderer.width, - apiRenderer.height, - apiRenderer.offset, - apiRenderer.canvas - ); - -}; - -GameLib.API.Renderer.D2.prototype = Object.create(GameLib.API.Renderer.prototype); -GameLib.API.Renderer.D2.prototype.constructor = GameLib.API.Renderer.D2; \ No newline at end of file diff --git a/src/game-lib-api-socket-0.js b/src/game-lib-api-socket-0.js deleted file mode 100644 index 9f022e7..0000000 --- a/src/game-lib-api-socket-0.js +++ /dev/null @@ -1,93 +0,0 @@ -/** - * Raw Socket API object - should always correspond with the Socket Schema - * @param id - * @param name - * @param socketType - * @param roomId - * @param peerId - * @param server GameLib.Server - * @param parentEntity - * @constructor - */ -GameLib.API.Socket = function( - id, - name, - socketType, - roomId, - peerId, - server, - parentEntity -) { - - if (GameLib.Utils.UndefinedOrNull(id)) { - id = GameLib.Utils.RandomId(); - } - this.id = id; - - if (GameLib.Utils.UndefinedOrNull(name)) { - name = 'Socket (' + this.id + ')'; - } - this.name = name; - - if (GameLib.Utils.UndefinedOrNull(socketType)) { - socketType = GameLib.API.Socket.TYPE_NONE; - } - this.socketType = socketType; - - if (GameLib.Utils.UndefinedOrNull(roomId)) { - roomId = 'room_' + GameLib.Utils.RandomId(); - } - this.roomId = roomId; - - if (GameLib.Utils.UndefinedOrNull(peerId)) { - peerId = null; - } - this.peerId = peerId; - - if (GameLib.Utils.UndefinedOrNull(server)) { - server = null; - } - this.server = server; - - var componentType = GameLib.Component.SOCKET; - - if (this.socketType === GameLib.API.Socket.TYPE_CAST) { - componentType = GameLib.Component.SOCKET_CAST; - } - - if (this.socketType === GameLib.API.Socket.TYPE_RECEIVE) { - componentType = GameLib.Component.SOCKET_RECEIVE; - } - - GameLib.API.Component.call( - this, - componentType, - parentEntity - ); -}; - -GameLib.API.Socket.prototype = Object.create(GameLib.API.Component.prototype); -GameLib.API.Socket.prototype.constructor = GameLib.API.Socket; - -GameLib.API.Socket.TYPE_NONE = 0x1; -GameLib.API.Socket.TYPE_CAST = 0x2; -GameLib.API.Socket.TYPE_RECEIVE = 0x3; - -/** - * Creates an API Socket from an Object Socket - * @param objectSocket - * @constructor - */ -GameLib.API.Socket.FromObject = function(objectSocket) { - - return new GameLib.API.Socket( - objectSocket.id, - objectSocket.name, - objectSocket.socketType, - objectSocket.roomId, - objectSocket.peerId, - objectSocket.server, - objectSocket.parentEntity - ); - -}; diff --git a/src/game-lib-api-socket-cast.js b/src/game-lib-api-socket-cast.js deleted file mode 100644 index 309e698..0000000 --- a/src/game-lib-api-socket-cast.js +++ /dev/null @@ -1,78 +0,0 @@ -/** - * Raw Cast API object - should always correspond with the Cast Schema - * @param apiSocket - * @param castType - * @param source - * @param sourceProperties - * @constructor - */ -GameLib.API.Socket.Cast = function( - apiSocket, - castType, - source, - sourceProperties -) { - - if (GameLib.Utils.UndefinedOrNull(apiSocket)) { - apiSocket = { - socketType : GameLib.API.Socket.SOCKET_CAST - }; - } - - GameLib.API.Socket.call( - this, - apiSocket.id, - apiSocket.name, - apiSocket.socketType, - apiSocket.roomId, - apiSocket.peerId, - apiSocket.server, - apiSocket.parentEntity - ); - - if (GameLib.Utils.UndefinedOrNull(castType)) { - castType = GameLib.API.Socket.Cast.CAST_TYPE_ROOM; - } - this.castType = castType; - - if (GameLib.Utils.UndefinedOrNull(source)) { - source = null; - } - this.source = source; - - if (GameLib.Utils.UndefinedOrNull(sourceProperties)) { - sourceProperties = null; - } - this.sourceProperties = sourceProperties; - - GameLib.API.Component.call( - this, - GameLib.Component.SOCKET_CAST - ); -}; - -GameLib.API.Socket.Cast.prototype = Object.create(GameLib.API.Socket.prototype); -GameLib.API.Socket.Cast.prototype.constructor = GameLib.API.Socket.Cast.Receive; - -GameLib.API.Socket.Cast.CAST_TYPE_ROOM = 0x1; -GameLib.API.Socket.Cast.CAST_TYPE_PEER = 0x2; -GameLib.API.Socket.Cast.CAST_TYPE_ALL = 0x3; -GameLib.API.Socket.Cast.CAST_TYPE_ALL_BUT_PEER = 0x4; - - -/** - * Creates an API.Socket.Cast from an Object Cast - * @param objectSocketCast - * @constructor - */ -GameLib.API.Socket.Cast.FromObject = function(objectSocketCast) { - - var apiSocket = GameLib.API.Socket.FromObject(objectSocketCast); - - return new GameLib.API.Socket.Cast( - apiSocket, - objectSocketCast.castType, - objectSocketCast.source, - objectSocketCast.sourceProperties - ); -}; diff --git a/src/game-lib-api-sphere.js b/src/game-lib-api-sphere.js deleted file mode 100644 index 0811bc4..0000000 --- a/src/game-lib-api-sphere.js +++ /dev/null @@ -1,20 +0,0 @@ -/** - * GameLib.API.Sphere - * @constructor - * @param center - * @param radius - */ -GameLib.API.Sphere = function ( - center, - radius -) { - if (GameLib.Utils.UndefinedOrNull(center)) { - center = new GameLib.API.Vector3(0,0,0); - } - this.center = center; - - if (GameLib.Utils.UndefinedOrNull(radius)) { - radius = 1; - } - this.radius = radius; -}; diff --git a/src/game-lib-api-system.js b/src/game-lib-api-system.js deleted file mode 100644 index 24b47ca..0000000 --- a/src/game-lib-api-system.js +++ /dev/null @@ -1,104 +0,0 @@ -/** - * This component renders a scene - * @param id String - * @param name String - * @param systemType - * @param parentEntity - * @constructor - */ -GameLib.API.System = function ( - id, - name, - systemType, - parentEntity -) { - - if (GameLib.Utils.UndefinedOrNull(id)) { - id = GameLib.Utils.RandomId(); - } - this.id = id; - - if (GameLib.Utils.UndefinedOrNull(name)) { - name = "System (" + this.id + ")"; - } - this.name = name; - - if (GameLib.Utils.UndefinedOrNull(systemType)) { - systemType = GameLib.System.SYSTEM_TYPE_NONE; - } - this.systemType = systemType; - - var componentType = GameLib.Component.SYSTEM; - - if (this.systemType === GameLib.System.SYSTEM_TYPE_NONE) { - componentType = GameLib.Component.SYSTEM; - } - - 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 - ); - -}; - -GameLib.API.System.prototype = Object.create(GameLib.API.Component.prototype); -GameLib.API.System.prototype.constructor = GameLib.API.System; - -/** - * Object to GameLib.D3.API.System - * @param objectComponent - * @constructor - */ -GameLib.API.System.FromObject = function(objectComponent) { - return new GameLib.API.System( - objectComponent.id, - objectComponent.name, - objectComponent.systemType, - objectComponent.parentEntity - ); -}; diff --git a/src/game-lib-clock.js b/src/game-lib-clock.js deleted file mode 100644 index 6274948..0000000 --- a/src/game-lib-clock.js +++ /dev/null @@ -1,96 +0,0 @@ -/** - * Creates a Clock object - * @param graphics - * @param apiClock GameLib.API.Clock - * @constructor - */ -GameLib.Clock = function( - graphics, - apiClock -) { - - this.graphics = graphics; - this.graphics.isNotThreeThrow(); - - if (GameLib.Utils.UndefinedOrNull(apiClock)) { - apiClock = {}; - } - - GameLib.API.Clock.call( - this, - apiClock.id, - apiClock.name, - apiClock.parentEntity - ); - - GameLib.Component.call(this); -} ; - -GameLib.Clock.prototype = Object.create(GameLib.Component.prototype); -GameLib.Clock.prototype.constructor = GameLib.Clock; - -/** - * Creates a camera instance of 'graphics' type (only THREE for now) - * @returns {THREE.Clock} - */ -GameLib.Clock.prototype.createInstance = function() { - - this.instance = new THREE.Clock(); - - GameLib.Component.prototype.createInstance.call(this); -}; - -/** - * Updates the instance with the current state - */ -GameLib.Clock.prototype.updateInstance = function() { - -}; - -GameLib.Clock.prototype.getDelta = function() { - - var delta = this.instance.getDelta(); - - /** - * clamp the delta to 1/60 - */ - - if (delta > (1 / 30.0)) { - // console.log('clipped ' + (delta - (1/30.0)) + ' seconds - essentially lost time'); - delta = (1 / 30.0); - } - - return delta; -}; - -/** - * Converts a GameLib.Clock to a new GameLib.API.Clock - * @returns {GameLib.API.Clock} - */ -GameLib.Clock.prototype.toApiObject = function() { - - return new GameLib.API.Clock( - this.id, - this.name, - GameLib.Utils.IdOrNull(this.parentEntity) - ); - -}; - -/** - * Converts from an Object camera to a GameLib.Clock - * @param graphics GameLib.Graphics - * @param objectClock Object - * @returns {GameLib.Clock} - * @constructor - */ -GameLib.Clock.FromObject = function(graphics, objectClock) { - - var apiClock = GameLib.API.Clock.FromObject(objectClock); - - return new GameLib.Clock( - graphics, - apiClock - ); - -}; diff --git a/src/game-lib-controls-0.js b/src/game-lib-controls-0.js deleted file mode 100644 index 17b96db..0000000 --- a/src/game-lib-controls-0.js +++ /dev/null @@ -1,100 +0,0 @@ -/** - * GameLib.Controls - * @param apiControls - * @property controlsType - * @constructor - */ -GameLib.Controls = function ( - apiControls -) { - - if (GameLib.Utils.UndefinedOrNull(apiControls)) { - apiControls = {}; - } - - GameLib.API.Controls.call( - this, - apiControls.id, - apiControls.name, - apiControls.controlsType, - apiControls.canvas, - apiControls.parentEntity - ); - - var linkedObjects = { - canvas : GameLib.Canvas - }; - - var delayed = false; - - switch (this.controlsType) { - case (GameLib.API.Controls.CONTROLS_TYPE_EDITOR) : - linkedObjects.raycaster = GameLib.D3.Raycaster; - linkedObjects.camera = GameLib.D3.Camera; - delayed = true; - break; - case (GameLib.API.Controls.CONTROLS_TYPE_FIRST_PERSON) : - linkedObjects.camera = GameLib.D3.Camera; - delayed = true; - break; - case (GameLib.API.Controls.CONTROLS_TYPE_ORBIT) : - linkedObjects.camera = GameLib.D3.Camera; - linkedObjects.target = GameLib.Component; - delayed = true; - break; - } - - GameLib.Component.call( - this, - linkedObjects, - delayed - ); -}; - -GameLib.Controls.prototype = Object.create(GameLib.Component.prototype); -GameLib.Controls.prototype.constructor = GameLib.Controls; - -GameLib.Controls.D3 = function() {}; -GameLib.Controls.D3.prototype = Object.create(GameLib.Controls.prototype); -GameLib.Controls.D3.prototype.constructor = GameLib.Controls.D3; - -/** - * Creates a mesh instance or updates it - */ -GameLib.Controls.prototype.createInstance = function() { - GameLib.Component.prototype.createInstance.call(this); -}; - -/** - * Updates the mesh instance - */ -GameLib.Controls.prototype.updateInstance = function(property) { - - if (property === 'canvas') { - GameLib.Event.Emit( - GameLib.Event.CANVAS_CHANGE, - { - component: this - } - ); - } - - GameLib.Component.prototype.updateInstance.call(this, property); -}; - -/** - * Converts a GameLib.Controls to a GameLib.API.Controls - * @returns {GameLib.API.Controls} - */ -GameLib.Controls.prototype.toApiObject = function() { - - var apiControls = new GameLib.API.Controls( - this.id, - this.name, - this.controlsType, - GameLib.Utils.IdOrNull(this.canvas), - GameLib.Utils.IdOrNull(this.parentEntity) - ); - - return apiControls; -}; diff --git a/src/game-lib-controls-d3-editor.js b/src/game-lib-controls-d3-editor.js deleted file mode 100644 index d1ac676..0000000 --- a/src/game-lib-controls-d3-editor.js +++ /dev/null @@ -1,116 +0,0 @@ -/** - * Controls Superset - The apiControls properties get moved into the Controls object itself, and then the instance is created - * @param graphics GameLib.GraphicsRuntime - * @param apiEditorControls - * @constructor - */ -GameLib.Controls.D3.Editor = function ( - graphics, - apiEditorControls -) { - - this.graphics = graphics; - this.graphics.isNotThreeThrow(); - - if (GameLib.Utils.UndefinedOrNull(apiEditorControls)) { - apiEditorControls = { - controlsType : GameLib.API.Controls.CONTROLS_TYPE_EDITOR - }; - } - - if (GameLib.Utils.UndefinedOrNull()) { - apiEditorControls.controlsType = GameLib.API.Controls.CONTROLS_TYPE_EDITOR; - } - - GameLib.API.Controls.D3.Editor.call( - this, - apiEditorControls, - apiEditorControls.raycaster, - apiEditorControls.camera - ); - - if (this.raycaster instanceof GameLib.D3.API.Raycaster) { - this.raycaster = new GameLib.D3.Raycaster( - this.graphics, - this.raycaster - ); - } - - GameLib.Controls.call( - this, - apiEditorControls - ); - -}; - -/** - * Inheritance - * @type {GameLib.Controls} - */ -GameLib.Controls.D3.Editor.prototype = Object.create(GameLib.Controls.D3.prototype); -GameLib.Controls.D3.Editor.prototype.constructor = GameLib.Controls.D3.Editor; - -/** - * Create Instance - */ -GameLib.Controls.D3.Editor.prototype.createInstance = function() { - - if ( - GameLib.Utils.UndefinedOrNull(this.camera) || - GameLib.Utils.UndefinedOrNull(this.camera.instance) - ) { - console.warn('no camera at time of editor-controls create instance'); - return; - } - - if ( - GameLib.Utils.UndefinedOrNull(this.canvas) || - GameLib.Utils.UndefinedOrNull(this.canvas.instance) - ) { - console.warn('no canvas at time of editor-controls create instance'); - return; - } - - this.instance = new THREE.EditorControls( - this.camera.instance, - this.canvas.instance - ); - - GameLib.Controls.prototype.createInstance.call(this); -}; - -/** - * Update Instance - */ -GameLib.Controls.D3.Editor.prototype.updateInstance = function(property) { - - if ( - property === 'canvas' || - property === 'camera' - ) { - if (GameLib.Utils.UndefinedOrNull(this.instance)) { - this.createInstance(); - } else { - this.instance.dispose(); - this.createInstance(); - } - } - - 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, property); -}; - -/** - * Converts a GameLib.Controls.D3.Editor to a GameLib.D3.API.Mesh - * @returns {GameLib.API.Controls} - */ -GameLib.Controls.D3.Editor.prototype.toApiObject = function() { - - var apiControls = GameLib.Controls.prototype.toApiObject.call(this); - - apiControls.raycaster = GameLib.Utils.IdOrNull(this.raycaster); - apiControls.camera = GameLib.Utils.IdOrNull(this.camera); - - return apiControls; -}; diff --git a/src/game-lib-controls-keyboard.js b/src/game-lib-controls-keyboard.js deleted file mode 100644 index fe6ba33..0000000 --- a/src/game-lib-controls-keyboard.js +++ /dev/null @@ -1,79 +0,0 @@ -/** - * Keyboard Controls - * @param apiKeyboardControls GameLib.API.Controls - * @constructor - */ -GameLib.Controls.Keyboard = function ( - apiKeyboardControls -) { - - if (GameLib.Utils.UndefinedOrNull(apiKeyboardControls)) { - apiKeyboardControls = { - controlsType : GameLib.API.Controls.CONTROLS_TYPE_KEYBOARD - }; - } - - GameLib.API.Controls.Keyboard.call( - this, - apiKeyboardControls - ); - - GameLib.Controls.call( - this, - apiKeyboardControls - ); -}; - -/** - * Inheritance - * @type {GameLib.Controls} - */ -GameLib.Controls.Keyboard.prototype = Object.create(GameLib.Controls.prototype); -GameLib.Controls.Keyboard.prototype.constructor = GameLib.Controls.Keyboard; - -/** - * Create Instance - * @returns - */ -GameLib.Controls.Keyboard.prototype.createInstance = function() { - /** - * Set instance to true to indicate no dependencies to other components - */ - this.instance = true; - GameLib.Controls.prototype.createInstance.call(this); -}; - -/** - * Update Instance - */ -GameLib.Controls.Keyboard.prototype.updateInstance = function(property) { - GameLib.Controls.prototype.updateInstance.call(this, property); -}; - -/** - * Converts a GameLib.Controls.Keyboard to a GameLib.API.Controls - * @returns {GameLib.API.Controls} - */ -GameLib.Controls.Keyboard.prototype.toApiObject = function() { - var apiControls = GameLib.Controls.prototype.toApiObject.call(this); - /** - * add other properties here as this component develops... - */ - return apiControls; -}; - -/** - * Construct an Keyboard Controls object from data - * @param objectControls - * @returns {GameLib.Controls.Keyboard} - * @constructor - */ -GameLib.Controls.Keyboard.FromObject = function(objectControls) { - - var apiKeyboardControls = GameLib.API.Controls.Keyboard.FromObject(objectControls); - - return new GameLib.Controls.Keyboard( - apiKeyboardControls - ); - -}; \ No newline at end of file diff --git a/src/game-lib-controls-mouse.js b/src/game-lib-controls-mouse.js deleted file mode 100644 index a800339..0000000 --- a/src/game-lib-controls-mouse.js +++ /dev/null @@ -1,79 +0,0 @@ -/** - * Mouse Controls - * @param apiMouseControls GameLib.API.Controls - * @constructor - */ -GameLib.Controls.Mouse = function ( - apiMouseControls -) { - - if (GameLib.Utils.UndefinedOrNull(apiMouseControls)) { - apiMouseControls = { - controlsType : GameLib.API.Controls.CONTROLS_TYPE_MOUSE - }; - } - - GameLib.API.Controls.Mouse.call( - this, - apiMouseControls - ); - - GameLib.Controls.call( - this, - apiMouseControls - ); -}; - -/** - * Inheritance - * @type {GameLib.Controls} - */ -GameLib.Controls.Mouse.prototype = Object.create(GameLib.Controls.prototype); -GameLib.Controls.Mouse.prototype.constructor = GameLib.Controls.Mouse; - -/** - * Create Instance - * @returns - */ -GameLib.Controls.Mouse.prototype.createInstance = function() { - /** - * Set instance to true to indicate no dependencies to other components - */ - this.instance = true; - GameLib.Controls.prototype.createInstance.call(this); -}; - -/** - * Update Instance - */ -GameLib.Controls.Mouse.prototype.updateInstance = function(property) { - GameLib.Controls.prototype.updateInstance.call(this, property); -}; - -/** - * Converts a GameLib.Controls.Mouse to a GameLib.API.Controls - * @returns {GameLib.API.Controls} - */ -GameLib.Controls.Mouse.prototype.toApiObject = function() { - var apiControls = GameLib.Controls.prototype.toApiObject.call(this); - /** - * add other properties here as this component develops... - */ - return apiControls; -}; - -/** - * Construct an Mouse Controls object from data - * @param objectControls - * @returns {GameLib.Controls.Mouse} - * @constructor - */ -GameLib.Controls.Mouse.FromObject = function(objectControls) { - - var apiMouseControls = GameLib.API.Controls.Mouse.FromObject(objectControls); - - return new GameLib.Controls.Mouse( - apiMouseControls - ); - -}; \ No newline at end of file diff --git a/src/game-lib-controls-touch.js b/src/game-lib-controls-touch.js deleted file mode 100644 index 9540cba..0000000 --- a/src/game-lib-controls-touch.js +++ /dev/null @@ -1,82 +0,0 @@ -/** - * Touch Controls - * @constructor - * @param apiTouchControls - */ -GameLib.Controls.Touch = function ( - apiTouchControls -) { - - if (GameLib.Utils.UndefinedOrNull(apiTouchControls)) { - apiTouchControls = { - controlsType : GameLib.API.Controls.CONTROLS_TYPE_TOUCH - }; - } - - GameLib.API.Controls.Touch.call( - this, - apiTouchControls, - apiTouchControls.sensitivity - ); - - GameLib.Controls.call( - this, - apiTouchControls - ); -}; - -/** - * Inheritance - * @type {GameLib.Controls} - */ -GameLib.Controls.Touch.prototype = Object.create(GameLib.Controls.prototype); -GameLib.Controls.Touch.prototype.constructor = GameLib.Controls.Touch; - -/** - * Create Instance - * @returns - */ -GameLib.Controls.Touch.prototype.createInstance = function() { - /** - * Set instance to true to indicate no dependencies to other components - */ - this.instance = true; - GameLib.Controls.prototype.createInstance.call(this); -}; - -/** - * Update Instance - */ -GameLib.Controls.Touch.prototype.updateInstance = function(property) { - GameLib.Controls.prototype.updateInstance.call(this, property); -}; - -/** - * Converts a GameLib.Controls.Touch to a GameLib.API.Controls - * @returns {GameLib.API.Controls} - */ -GameLib.Controls.Touch.prototype.toApiObject = function() { - - var apiControls = GameLib.Controls.prototype.toApiObject.call(this); - - apiControls.sensitivity = this.sensitivity; - - /** - * add other properties here as this component develops... - */ - return apiControls; -}; - -/** - * Construct an Touch Controls object from data - * @param objectControls - * @returns {GameLib.Controls.Touch} - * @constructor - */ -GameLib.Controls.Touch.FromObject = function(objectControls) { - - var apiTouchControls = GameLib.API.Controls.Touch.FromObject(objectControls); - - return new GameLib.Controls.Touch(apiTouchControls); - -}; \ No newline at end of file diff --git a/src/game-lib-curve-path-d2-shape.js b/src/game-lib-curve-path-d2-shape.js deleted file mode 100644 index 0ea12b8..0000000 --- a/src/game-lib-curve-path-d2-shape.js +++ /dev/null @@ -1,74 +0,0 @@ -/** - * GameLib.Curve.Path.D2 - * @param graphics GameLib.GraphicsRuntime - * @param apiCurvePathD2 - * @constructor - */ -GameLib.Curve.Path.D2.Shape = function( - graphics, - apiCurvePathD2 -) { - - this.graphics = graphics; - this.graphics.isNotThreeThrow(); - - if (GameLib.Utils.UndefinedOrNull(apiCurvePathD2)) { - apiCurvePathD2 = { - curveType : GameLib.API.Curve.CURVE_TYPE_PATH_2D_SHAPE - }; - } - - GameLib.API.Curve.Path.D2.call( - this, - apiCurvePathD2, - apiCurvePathD2.points - ); - - GameLib.Curve.Path.D2.call( - this, - this.graphics, - this - ); - -}; - -GameLib.Curve.Path.D2.Shape.prototype = Object.create(GameLib.Curve.Path.D2.prototype); -GameLib.Curve.Path.D2.Shape.prototype.constructor = GameLib.Curve.Path.D2.Shape; - -/** - * Creates a camera instance - * @returns {*} - */ -GameLib.Curve.Path.D2.Shape.prototype.createInstance = function() { - - this.instance = new THREE.Shape( - this.points.map( - function(point) { - return point.instance; - } - ) - ); - - GameLib.Curve.Path.D2.prototype.createInstance.call(this); -}; - -/** - * Updates the instance with the current state - */ -GameLib.Curve.Path.D2.Shape.prototype.updateInstance = function(property) { - GameLib.Curve.Path.D2.prototype.updateInstance.call(this, property); -}; - -/** - * Converts a GameLib.Curve to a GameLib.API.Curve - * @returns {GameLib.API.Curve} - */ -GameLib.Curve.Path.D2.Shape.prototype.toApiObject = function() { - - var apiCurvePathD2 = GameLib.Curve.Path.D2.prototype.toApiObject.call(this); - - return new GameLib.API.Curve.Path.D2.Shape( - apiCurvePathD2 - ); - -}; diff --git a/src/game-lib-d3-api-a-object.js b/src/game-lib-d3-api-a-object.js deleted file mode 100644 index 59248bf..0000000 --- a/src/game-lib-d3-api-a-object.js +++ /dev/null @@ -1,173 +0,0 @@ -/** - * GameLib.D3.API.Object - * @param id - * @param name - * @param objectType - * @param parentEntity - * @param useQuaternion - * @param position - * @param quaternion - * @param rotation - * @param scale - * @param up - * @param lookAt - * @constructor - */ -GameLib.D3.API.Object = function( - id, - name, - objectType, - parentEntity, - useQuaternion, - position, - quaternion, - rotation, - scale, - up, - lookAt -) { - if (GameLib.Utils.UndefinedOrNull(id)) { - id = GameLib.Utils.RandomId(); - } - this.id = id; - - if (GameLib.Utils.UndefinedOrNull(objectType)) { - objectType = 0; - } - this.objectType = objectType; - - if (GameLib.Utils.UndefinedOrNull(name)) { - switch (this.objectType) { - case GameLib.D3.API.Object.OBJECT_TYPE_NONE : - name = 'Object'; - break; - /** - * Cameras - */ - case GameLib.D3.API.Object.OBJECT_TYPE_CAMERA : - name = 'Camera'; - break; - case GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_ORTHOGRAPHIC : - name = 'Camera Orthographic'; - break; - case GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_PERSPECTIVE : - name = 'Camera Perspective'; - break; - case GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_CUBE : - name = 'Camera Cube'; - break; - case GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_STEREO : - name = 'Camera Stereo'; - break; - /** - * Meshes - */ - case GameLib.D3.API.Object.OBJECT_TYPE_MESH : - name = 'Mesh'; - break; - } - name += ' (' + this.id + ')'; - } - this.name = name; - - if (GameLib.Utils.UndefinedOrNull(useQuaternion)) { - useQuaternion = true; - } - this.useQuaternion = useQuaternion; - - if (GameLib.Utils.UndefinedOrNull(position)) { - position = new GameLib.API.Vector3(); - } - this.position = position; - - if (GameLib.Utils.UndefinedOrNull(quaternion)) { - quaternion = new GameLib.API.Quaternion(); - } - this.quaternion = quaternion; - - if (GameLib.Utils.UndefinedOrNull(rotation)) { - rotation = new GameLib.API.Vector3(); - } - this.rotation = rotation; - - if (GameLib.Utils.UndefinedOrNull(scale)) { - scale = new GameLib.API.Vector3(1,1,1); - } - this.scale = scale; - - if (GameLib.Utils.UndefinedOrNull(up)) { - up = new GameLib.API.Vector3(0,1,0); - } - this.up = up; - - if (GameLib.Utils.UndefinedOrNull(lookAt)) { - lookAt = new GameLib.API.Vector3(); - } - this.lookAt = lookAt; - - GameLib.API.Component.call( - this, - GameLib.D3.API.Object.GetComponentType(this.objectType), - parentEntity - ); -}; - -GameLib.D3.API.Object.prototype = Object.create(GameLib.API.Component.prototype); -GameLib.D3.API.Object.prototype.constructor = GameLib.D3.API.Object; - -GameLib.D3.API.Object.GetComponentType = function(objectType) { - - var componentType = null; - - switch (objectType) { - case GameLib.D3.API.Object.OBJECT_TYPE_NONE : - componentType = GameLib.Component.OBJECT; - break; - /** - * Cameras - */ - case GameLib.D3.API.Object.OBJECT_TYPE_CAMERA : - componentType = GameLib.Component.CAMERA; - break; - case GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_PERSPECTIVE : - componentType = GameLib.Component.CAMERA_PERSPECTIVE; - break; - case GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_ORTHOGRAPHIC : - componentType = GameLib.Component.CAMERA_ORTHOGRAPHIC; - break; - case GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_STEREO : - componentType = GameLib.Component.CAMERA_STEREO; - break; - case GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_CUBE : - componentType = GameLib.Component.CAMERA_CUBE; - break; - /** - * Meshes - */ - case GameLib.D3.API.Object.OBJECT_TYPE_MESH : - componentType = GameLib.Component.MESH; - break; - default: - throw new Error('unsupported camera type: ' + objectType); - } - - return componentType; -}; - -GameLib.D3.API.Object.OBJECT_TYPE_NONE = 0x0; - -/** - * Cameras - * @type {number} - */ -GameLib.D3.API.Object.OBJECT_TYPE_CAMERA = 0x11; -GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_PERSPECTIVE = 0x12;//0x1; -GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_ORTHOGRAPHIC = 0x13;//0x2; -GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_STEREO = 0x14;//0x3; -GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_CUBE = 0x15;//0x4; - -/** - * Meshes - * @type {number} - */ -GameLib.D3.API.Object.OBJECT_TYPE_MESH = 0x21; diff --git a/src/game-lib-d3-api-bone.js b/src/game-lib-d3-api-bone.js deleted file mode 100644 index 8151621..0000000 --- a/src/game-lib-d3-api-bone.js +++ /dev/null @@ -1,93 +0,0 @@ -/** - * Bone Superset - * @param id - * @param name string - * @param childBoneIds - * @param parentBoneIds - * @param quaternion GameLib.API.Quaternion - * @param position GameLib.API.Vector3 - * @param scale GameLib.API.Vector3 - * @param up GameLib.API.Vector3 - * @param parentEntity - * @constructor - */ -GameLib.D3.API.Bone = function ( - id, - name, - childBoneIds, - parentBoneIds, - position, - quaternion, - scale, - up, - parentEntity -) { - - if (GameLib.Utils.UndefinedOrNull(id)) { - id = GameLib.Utils.RandomId(); - } - this.id = id; - - if (GameLib.Utils.UndefinedOrNull(name)) { - name = 'Bone (' + this.id + ')'; - } - this.name = name; - - if (GameLib.Utils.UndefinedOrNull(childBoneIds)) { - childBoneIds = []; - } - this.childBoneIds = childBoneIds; - - if (GameLib.Utils.UndefinedOrNull(parentBoneIds)) { - parentBoneIds = []; - } - this.parentBoneIds = parentBoneIds; - - if (GameLib.Utils.UndefinedOrNull(position)) { - position = new GameLib.API.Vector3(); - } - this.position = position; - - if (GameLib.Utils.UndefinedOrNull(quaternion)) { - quaternion = new GameLib.API.Quaternion(); - } - this.quaternion = quaternion; - - if (GameLib.Utils.UndefinedOrNull(scale)) { - scale = new GameLib.API.Vector3(1,1,1); - } - this.scale = scale; - - if (GameLib.Utils.UndefinedOrNull(up)) { - 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.API.Component.prototype); -GameLib.D3.API.Bone.prototype.constructor = GameLib.D3.API.Bone; - -/** - * Returns an API bone from an Object bone - * @param objectBone - * @constructor - */ -GameLib.D3.API.Bone.FromObject = function(objectBone) { - return new GameLib.D3.API.Bone( - objectBone.id, - objectBone.name, - objectBone.childBoneIds, - objectBone.parentBoneIds, - GameLib.API.Vector3.FromObject(objectBone.position), - GameLib.API.Quaternion.FromObject(objectBone.quaternion), - GameLib.API.Vector3.FromObject(objectBone.scale), - GameLib.API.Vector3.FromObject(objectBone.up), - objectBone.parentEntity - ); -}; diff --git a/src/game-lib-d3-api-camera-a.js b/src/game-lib-d3-api-camera-a.js deleted file mode 100644 index a58782c..0000000 --- a/src/game-lib-d3-api-camera-a.js +++ /dev/null @@ -1,52 +0,0 @@ -/** - * GameLib.D3.API.Camera - * @param apiD3Object - * @param aspect - * @constructor - */ -GameLib.D3.API.Camera = function( - apiD3Object, - aspect -) { - - if (GameLib.Utils.UndefinedOrNull(apiD3Object)) { - apiD3Object = { - objectType : GameLib.D3.API.Object.OBJECT_TYPE_CAMERA - }; - } - - if (GameLib.Utils.UndefinedOrNull(apiD3Object.objectType)) { - apiD3Object.objectType = GameLib.D3.API.Object.OBJECT_TYPE_CAMERA; - } - - if (GameLib.Utils.UndefinedOrNull(aspect)) { - aspect = 1; - } - this.aspect = aspect; - - if (GameLib.Utils.UndefinedOrNull(apiD3Object.position)) { - apiD3Object.position = new GameLib.API.Vector3( - 15, - 15, - 15 - ); - } - - GameLib.D3.API.Object.call( - this, - apiD3Object.id, - apiD3Object.name, - apiD3Object.objectType, - apiD3Object.parentEntity, - apiD3Object.useQuaternion, - apiD3Object.position, - apiD3Object.quaternion, - apiD3Object.rotation, - apiD3Object.scale, - apiD3Object.up, - apiD3Object.lookAt - ); -}; - -GameLib.D3.API.Camera.prototype = Object.create(GameLib.D3.API.Object.prototype); -GameLib.D3.API.Camera.prototype.constructor = GameLib.D3.API.Camera; diff --git a/src/game-lib-d3-api-camera-cube.js b/src/game-lib-d3-api-camera-cube.js deleted file mode 100644 index 7fc38f5..0000000 --- a/src/game-lib-d3-api-camera-cube.js +++ /dev/null @@ -1,59 +0,0 @@ -/** - * GameLib.D3.API.Camera.Cube - * @constructor - * @param apiD3ObjectCamera - * @param near - * @param far - * @param cubeResolution - * @param renderTarget - */ -GameLib.D3.API.Camera.Cube = function( - apiD3ObjectCamera, - near, - far, - cubeResolution, - renderTarget -) { - - if (GameLib.Utils.UndefinedOrNull(apiD3ObjectCamera)) { - apiD3ObjectCamera = { - objectType : GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_CUBE - }; - } - - if (GameLib.Utils.UndefinedOrNull(apiD3ObjectCamera.objectType)) { - apiD3ObjectCamera.objectType = GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_CUBE; - } - - if (GameLib.Utils.UndefinedOrNull(near)) { - near = 0.1; - } - this.near = near; - - if (GameLib.Utils.UndefinedOrNull(far)) { - far = 2000; - } - this.far = far; - - if (GameLib.Utils.UndefinedOrNull(cubeResolution)) { - cubeResolution = 128; - } - this.cubeResolution = cubeResolution; - - if (GameLib.Utils.UndefinedOrNull(renderTarget)) { - renderTarget = null; - } - this.renderTarget = renderTarget; - - /** - * CubeCamera's have hardcoded fov=90 and aspect=1 - */ - GameLib.D3.API.Camera.call( - this, - apiD3ObjectCamera, - apiD3ObjectCamera.aspect - ); -}; - -GameLib.D3.API.Camera.Cube.prototype = Object.create(GameLib.D3.API.Camera.prototype); -GameLib.D3.API.Camera.Cube.prototype.constructor = GameLib.D3.API.Camera.Cube; diff --git a/src/game-lib-d3-api-camera-perspective.js b/src/game-lib-d3-api-camera-perspective.js deleted file mode 100644 index 7315219..0000000 --- a/src/game-lib-d3-api-camera-perspective.js +++ /dev/null @@ -1,84 +0,0 @@ -/** - * GameLib.D3.API.Camera.Perspective - * @constructor - * @param apiD3ObjectCamera - * @param fov - * @param near - * @param far - * @param filmGauge - * @param filmOffset - * @param focus - * @param zoom - */ -GameLib.D3.API.Camera.Perspective = function( - apiD3ObjectCamera, - near, - far, - fov, - filmGauge, - filmOffset, - focus, - zoom -) { - - if (GameLib.Utils.UndefinedOrNull(apiD3ObjectCamera)) { - apiD3ObjectCamera = { - objectType : GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_PERSPECTIVE - }; - } - - if (GameLib.Utils.UndefinedOrNull(apiD3ObjectCamera.objectType)) { - apiD3ObjectCamera.objectType = GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_PERSPECTIVE; - } - - if (GameLib.Utils.UndefinedOrNull(near)) { - // near = new GameLib.API.Number(0.1, 0.001, 0.001, 2000); - near = 0.1; - } - this.near = near; - - if (GameLib.Utils.UndefinedOrNull(far)) { - // far = new GameLib.API.Number(2000, 1, 1, 4000); - far = 2000; - } - this.far = far; - - if (GameLib.Utils.UndefinedOrNull(fov)) { - // fov = new GameLib.API.Number(50, 1, 0, 180); - fov = 50; - } - this.fov = fov; - - if (GameLib.Utils.UndefinedOrNull(filmGauge)) { - // filmGauge = new GameLib.API.Number(35, 1, 0, 200); - filmGauge = 35; - } - this.filmGauge = filmGauge; - - if (GameLib.Utils.UndefinedOrNull(filmOffset)) { - // filmOffset = new GameLib.API.Number(0, 1, 0, 200); - filmOffset = 0; - } - this.filmOffset = filmOffset; - - if (GameLib.Utils.UndefinedOrNull(focus)) { - // focus = new GameLib.API.Number(10, 0.1, 0, 200); - focus = 10; - } - this.focus = focus; - - if (GameLib.Utils.UndefinedOrNull(zoom)) { - // zoom = new GameLib.API.Number(1, 0.01, 0, 10); - zoom = 1; - } - this.zoom = zoom; - - GameLib.D3.API.Camera.call( - this, - apiD3ObjectCamera, - apiD3ObjectCamera.aspect - ); -}; - -GameLib.D3.API.Camera.Perspective.prototype = Object.create(GameLib.D3.API.Camera.prototype); -GameLib.D3.API.Camera.Perspective.prototype.constructor = GameLib.D3.API.Camera.Perspective; \ No newline at end of file diff --git a/src/game-lib-d3-api-camera-stereo-a.js b/src/game-lib-d3-api-camera-stereo-a.js deleted file mode 100644 index da7c79d..0000000 --- a/src/game-lib-d3-api-camera-stereo-a.js +++ /dev/null @@ -1,40 +0,0 @@ -/** - * GameLib.D3.API.Camera.Stereo - * @constructor - * @param apiD3ObjectCamera - * @param stereoMode - */ -GameLib.D3.API.Camera.Stereo = function( - apiD3ObjectCamera, - stereoMode -) { - - if (GameLib.Utils.UndefinedOrNull(apiD3ObjectCamera)) { - apiD3ObjectCamera = { - objectType : GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_STEREO - }; - } - - if (GameLib.Utils.UndefinedOrNull(apiD3ObjectCamera.objectType)) { - apiD3ObjectCamera.objectType = GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_STEREO; - } - - - if (GameLib.Utils.UndefinedOrNull(stereoMode)) { - stereoMode = GameLib.D3.API.Camera.Stereo.STEREO_MODE_STEREO; - } - this.stereoMode = stereoMode; - - GameLib.D3.API.Camera.call( - this, - apiD3ObjectCamera, - apiD3ObjectCamera.aspect - ); -}; - -GameLib.D3.API.Camera.Stereo.prototype = Object.create(GameLib.D3.API.Camera.prototype); -GameLib.D3.API.Camera.Stereo.prototype.constructor = GameLib.D3.API.Camera.Stereo; - -GameLib.D3.API.Camera.Stereo.STEREO_MODE_STEREO = 0x1; -GameLib.D3.API.Camera.Stereo.STEREO_MODE_ANAGLYPH = 0x2; -GameLib.D3.API.Camera.Stereo.STEREO_MODE_PARALLAX = 0x3; diff --git a/src/game-lib-d3-api-effect-a.js b/src/game-lib-d3-api-effect-a.js deleted file mode 100644 index 12a2ac8..0000000 --- a/src/game-lib-d3-api-effect-a.js +++ /dev/null @@ -1,100 +0,0 @@ -/** - * GameLib.D3.API.Effect - * @param id - * @param name - * @param effectType - * @param parentEntity - * @param renderer - * @param width - * @param height - * - * @property effectType - * - * @constructor - */ -GameLib.D3.API.Effect = function( - id, - name, - effectType, - parentEntity, - renderer, - width, - height -) { - - if (GameLib.Utils.UndefinedOrNull(id)) { - id = GameLib.Utils.RandomId(); - } - this.id = id; - - if (GameLib.Utils.UndefinedOrNull(effectType)) { - effectType = GameLib.D3.API.Effect.EFFECT_TYPE_NONE; - } - this.effectType = effectType; - - if (GameLib.Utils.UndefinedOrNull(name)) { - - switch (this.effectType) { - case GameLib.D3.API.Effect.EFFECT_TYPE_ANAGLYPH : - name = 'Effect Anaglyph'; - break; - case GameLib.D3.API.Effect.EFFECT_TYPE_PARALLAX : - name = 'Effect Parallax'; - break; - case GameLib.D3.API.Effect.EFFECT_TYPE_STEREO : - name = 'Effect Stereo'; - break; - default : - console.warn('no nice name for effect'); - name = 'Effect'; - } - - name += ' (' + this.id + ')'; - } - this.name = name; - - if (GameLib.Utils.UndefinedOrNull(renderer)) { - renderer = null; - } - this.renderer = renderer; - - if (GameLib.Utils.UndefinedOrNull(width)) { - width = 512; - } - this.width = width; - - if (GameLib.Utils.UndefinedOrNull(height)) { - height = 512; - } - this.height = height; - - var componentType = null; - - switch (this.effectType) { - case GameLib.D3.API.Effect.EFFECT_TYPE_STEREO : - componentType = GameLib.Component.EFFECT_STEREO; - break; - case GameLib.D3.API.Effect.EFFECT_TYPE_ANAGLYPH : - componentType = GameLib.Component.EFFECT_ANAGLYPH; - break; - case GameLib.D3.API.Effect.EFFECT_TYPE_PARALLAX : - componentType = GameLib.Component.EFFECT_PARALLAX; - break; - default: - throw new Error('unsupported effect type: ' + this.effectType); - } - - GameLib.API.Component.call( - this, - componentType, - parentEntity - ); -}; - -GameLib.D3.API.Effect.prototype = Object.create(GameLib.API.Component.prototype); -GameLib.D3.API.Effect.prototype.constructor = GameLib.D3.API.Effect; - -GameLib.D3.API.Effect.EFFECT_TYPE_NONE = 0x0; -GameLib.D3.API.Effect.EFFECT_TYPE_STEREO = 0x1; -GameLib.D3.API.Effect.EFFECT_TYPE_ANAGLYPH = 0x2; -GameLib.D3.API.Effect.EFFECT_TYPE_PARALLAX = 0x3; diff --git a/src/game-lib-d3-api-effect-anaglyph.js b/src/game-lib-d3-api-effect-anaglyph.js deleted file mode 100644 index 2e76f92..0000000 --- a/src/game-lib-d3-api-effect-anaglyph.js +++ /dev/null @@ -1,34 +0,0 @@ -/** - * GameLib.D3.API.Effect.Anaglyph - * @constructor - * @param apiEffect - */ -GameLib.D3.API.Effect.Anaglyph = function( - apiEffect -) { - - if (GameLib.Utils.UndefinedOrNull(apiEffect)) { - apiEffect = { - effectType : GameLib.D3.API.Effect.EFFECT_TYPE_ANAGLYPH - }; - } - - if (GameLib.Utils.UndefinedOrNull(apiEffect.cameraType)) { - apiEffect.effectType = GameLib.D3.API.Effect.EFFECT_TYPE_ANAGLYPH; - } - - GameLib.D3.API.Effect.call( - this, - apiEffect.id, - apiEffect.name, - apiEffect.effectType, - apiEffect.parentEntity, - apiEffect.renderer, - apiEffect.width, - apiEffect.height - ); - -}; - -GameLib.D3.API.Effect.Anaglyph.prototype = Object.create(GameLib.D3.API.Effect.prototype); -GameLib.D3.API.Effect.Anaglyph.prototype.constructor = GameLib.D3.API.Effect.Anaglyph; \ No newline at end of file diff --git a/src/game-lib-d3-api-effect-parallax.js b/src/game-lib-d3-api-effect-parallax.js deleted file mode 100644 index 0d27eb0..0000000 --- a/src/game-lib-d3-api-effect-parallax.js +++ /dev/null @@ -1,34 +0,0 @@ -/** - * GameLib.D3.API.Effect.Parallax - * @constructor - * @param apiEffect - */ -GameLib.D3.API.Effect.Parallax = function( - apiEffect -) { - - if (GameLib.Utils.UndefinedOrNull(apiEffect)) { - apiEffect = { - effectType : GameLib.D3.API.Effect.EFFECT_TYPE_PARALLAX - }; - } - - if (GameLib.Utils.UndefinedOrNull(apiEffect.cameraType)) { - apiEffect.effectType = GameLib.D3.API.Effect.EFFECT_TYPE_PARALLAX; - } - - GameLib.D3.API.Effect.call( - this, - apiEffect.id, - apiEffect.name, - apiEffect.effectType, - apiEffect.parentEntity, - apiEffect.renderer, - apiEffect.width, - apiEffect.height - ); - -}; - -GameLib.D3.API.Effect.Parallax.prototype = Object.create(GameLib.D3.API.Effect.prototype); -GameLib.D3.API.Effect.Parallax.prototype.constructor = GameLib.D3.API.Effect.Parallax; \ No newline at end of file diff --git a/src/game-lib-d3-api-effect-stereo.js b/src/game-lib-d3-api-effect-stereo.js deleted file mode 100644 index 9db45f5..0000000 --- a/src/game-lib-d3-api-effect-stereo.js +++ /dev/null @@ -1,41 +0,0 @@ -/** - * GameLib.D3.API.Effect.Stereo - * @constructor - * @param apiEffect - * @param eyeSeperation - */ -GameLib.D3.API.Effect.Stereo = function( - apiEffect, - eyeSeperation -) { - - if (GameLib.Utils.UndefinedOrNull(apiEffect)) { - apiEffect = { - effectType : GameLib.D3.API.Effect.EFFECT_TYPE_STEREO - }; - } - - if (GameLib.Utils.UndefinedOrNull(apiEffect.cameraType)) { - apiEffect.effectType = GameLib.D3.API.Effect.EFFECT_TYPE_STEREO; - } - - if (GameLib.Utils.UndefinedOrNull(eyeSeperation)) { - eyeSeperation = 0.064; - } - this.eyeSeperation = eyeSeperation; - - GameLib.D3.API.Effect.call( - this, - apiEffect.id, - apiEffect.name, - apiEffect.effectType, - apiEffect.parentEntity, - apiEffect.renderer, - apiEffect.width, - apiEffect.height - ); - -}; - -GameLib.D3.API.Effect.Stereo.prototype = Object.create(GameLib.D3.API.Effect.prototype); -GameLib.D3.API.Effect.Stereo.prototype.constructor = GameLib.D3.API.Effect.Stereo; \ No newline at end of file diff --git a/src/game-lib-d3-api-geometry-a.js b/src/game-lib-d3-api-geometry-a.js deleted file mode 100644 index de7c9ff..0000000 --- a/src/game-lib-d3-api-geometry-a.js +++ /dev/null @@ -1,413 +0,0 @@ -/** - * GameLib.D3.API.Geometry - * @param id - * @param name - * @param geometryType - * @param parentEntity - * @param parentMesh - * @param boundingBox - * @param boundingSphere - * @param faces - * @param vertices - * @constructor - */ -GameLib.D3.API.Geometry = function( - id, - name, - geometryType, - parentEntity, - parentMesh, - boundingBox, - boundingSphere, - faces, - vertices -) { - if (GameLib.Utils.UndefinedOrNull(id)) { - id = GameLib.Utils.RandomId(); - } - this.id = id; - - if (GameLib.Utils.UndefinedOrNull(geometryType)) { - geometryType = GameLib.D3.API.Geometry.GEOMETRY_TYPE_NONE; - } - this.geometryType = geometryType; - - if (GameLib.Utils.UndefinedOrNull(name)) { - - switch (this.geometryType) { - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL : - name = 'Geometry'; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_BOX : - name = 'Geometry Normal Box'; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_CIRCLE : - name = 'Geometry Normal Circle'; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_CONE : - name = 'Geometry Normal Cone'; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_CYLINDER : - name = 'Geometry Normal Cylinder'; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_DODECAHEDRON : - name = 'Geometry Normal Dodecahedron'; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_EDGES : - name = 'Geometry Normal Edges'; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_EXTRUDE : - name = 'Geometry Normal Extrude'; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_ICOSAHEDRON : - name = 'Geometry Normal Icosahedron'; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_LATHE : - name = 'Geometry Normal Lathe'; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_OCTAHEDRON : - name = 'Geometry Normal Octahedron'; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_PARAMETRIC : - name = 'Geometry Normal Parametric'; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_PLANE : - name = 'Geometry Normal Plane'; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_POLYHEDRON : - name = 'Geometry Normal Polyhedron'; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_RING : - name = 'Geometry Normal Ring'; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_SHAPE : - name = 'Geometry Normal Shape'; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_SPHERE : - name = 'Geometry Normal Sphere'; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TETRAHEDRON : - name = 'Geometry Normal Tetrahedron'; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TEXT : - name = 'Geometry Normal Text'; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TORUS : - name = 'Geometry Normal Torus'; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TORUS_KNOT : - name = 'Geometry Normal Torus Knot'; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TUBE : - name = 'Geometry Normal Tube'; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_WIREFRAME : - name = 'Geometry Normal Wireframe'; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER : - name = 'Geometry Buffer'; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_BOX : - name = 'Geometry Buffer Box'; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CIRCLE : - name = 'Geometry Buffer Circle'; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CONE : - name = 'Geometry Buffer Cone'; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CYLINDER : - name = 'Geometry Buffer Cylinder'; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_DODECAHEDRON : - name = 'Geometry Buffer Dodecahedron'; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_EXTRUDE : - name = 'Geometry Buffer Extrude'; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_ICOSAHEDRON : - name = 'Geometry Buffer Icosahedron'; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_LATHE : - name = 'Geometry Buffer Lathe'; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_OCTAHEDRON : - name = 'Geometry Buffer Octahedron'; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_PARAMETRIC : - name = 'Geometry Buffer Parametric'; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_PLANE : - name = 'Geometry Buffer Plane'; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_POLYHEDRON : - name = 'Geometry Buffer Polyhedron'; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_RING : - name = 'Geometry Buffer Ring'; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_SHAPE : - name = 'Geometry Buffer Shape'; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_SPHERE : - name = 'Geometry Buffer Sphere'; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TETRAHEDRON : - name = 'Geometry Buffer Tetrahedron'; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TEXT : - name = 'Geometry Buffer Text'; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TORUS : - name = 'Geometry Buffer Torus'; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TORUS_KNOT : - name = 'Geometry Buffer Torus Knot'; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TUBE : - name = 'Geometry Buffer Tube'; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_INSTANCED : - name = 'Geometry Buffer Instanced'; - break; - default : - console.warn('no nice name for geometry'); - name = 'Geometry'; - } - - name += ' (' + id + ')'; - } - this.name = name; - - if (GameLib.Utils.UndefinedOrNull(parentMesh)) { - parentMesh = null; - } - this.parentMesh = parentMesh; - - if (GameLib.Utils.UndefinedOrNull(boundingBox)) { - boundingBox = new GameLib.API.Box3(); - } - this.boundingBox = boundingBox; - - if (GameLib.Utils.UndefinedOrNull(boundingSphere)) { - boundingSphere = new GameLib.API.Sphere(); - } - this.boundingSphere = boundingSphere; - - if (GameLib.Utils.UndefinedOrNull(faces)) { - faces = []; - } - this.faces = faces; - - if (GameLib.Utils.UndefinedOrNull(vertices)) { - vertices = []; - } - this.vertices = vertices; - - GameLib.API.Component.call( - this, - GameLib.D3.API.Geometry.GetComponentType(this.geometryType), - parentEntity - ); -}; - -GameLib.D3.API.Geometry.prototype = Object.create(GameLib.API.Component.prototype); -GameLib.D3.API.Geometry.prototype.constructor = GameLib.D3.API.Geometry; - -GameLib.D3.API.Geometry.GetComponentType = function(geometryType) { - - var componentType = null; - - switch (geometryType) { - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL : - componentType = GameLib.Component.GEOMETRY_NORMAL; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_BOX : - componentType = GameLib.Component.GEOMETRY_NORMAL_BOX; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_CIRCLE : - componentType = GameLib.Component.GEOMETRY_NORMAL_CIRCLE; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_CONE : - componentType = GameLib.Component.GEOMETRY_NORMAL_CONE; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_CYLINDER : - componentType = GameLib.Component.GEOMETRY_NORMAL_CYLINDER; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_DODECAHEDRON : - componentType = GameLib.Component.GEOMETRY_NORMAL_DODECAHEDRON; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_EDGES : - componentType = GameLib.Component.GEOMETRY_NORMAL_EDGES; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_EXTRUDE : - componentType = GameLib.Component.GEOMETRY_NORMAL_EXTRUDE; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_ICOSAHEDRON : - componentType = GameLib.Component.GEOMETRY_NORMAL_ICOSAHEDRON; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_LATHE : - componentType = GameLib.Component.GEOMETRY_NORMAL_LATHE; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_OCTAHEDRON : - componentType = GameLib.Component.GEOMETRY_NORMAL_OCTAHEDRON; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_PARAMETRIC : - componentType = GameLib.Component.GEOMETRY_NORMAL_PARAMETRIC; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_PLANE : - componentType = GameLib.Component.GEOMETRY_NORMAL_PLANE; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_POLYHEDRON : - componentType = GameLib.Component.GEOMETRY_NORMAL_POLYHEDRON; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_RING : - componentType = GameLib.Component.GEOMETRY_NORMAL_RING; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_SHAPE : - componentType = GameLib.Component.GEOMETRY_NORMAL_SHAPE; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_SPHERE : - componentType = GameLib.Component.GEOMETRY_NORMAL_SPHERE; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TETRAHEDRON : - componentType = GameLib.Component.GEOMETRY_NORMAL_TETRAHEDRON; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TEXT : - componentType = GameLib.Component.GEOMETRY_NORMAL_TEXT; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TORUS : - componentType = GameLib.Component.GEOMETRY_NORMAL_TORUS; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TORUS_KNOT : - componentType = GameLib.Component.GEOMETRY_NORMAL_TORUS_KNOT; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TUBE : - componentType = GameLib.Component.GEOMETRY_NORMAL_TUBE; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_WIREFRAME : - componentType = GameLib.Component.GEOMETRY_NORMAL_WIREFRAME; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER : - componentType = GameLib.Component.GEOMETRY_BUFFER; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_BOX : - componentType = GameLib.Component.GEOMETRY_BUFFER_BOX; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CIRCLE : - componentType = GameLib.Component.GEOMETRY_BUFFER_CIRCLE; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CONE : - componentType = GameLib.Component.GEOMETRY_BUFFER_CONE; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CYLINDER : - componentType = GameLib.Component.GEOMETRY_BUFFER_CYLINDER; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_DODECAHEDRON : - componentType = GameLib.Component.GEOMETRY_BUFFER_DODECAHEDRON; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_EXTRUDE : - componentType = GameLib.Component.GEOMETRY_BUFFER_EXTRUDE; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_ICOSAHEDRON : - componentType = GameLib.Component.GEOMETRY_BUFFER_ICOSAHEDRON; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_LATHE : - componentType = GameLib.Component.GEOMETRY_BUFFER_LATHE; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_OCTAHEDRON : - componentType = GameLib.Component.GEOMETRY_BUFFER_OCTAHEDRON; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_PARAMETRIC: - componentType = GameLib.Component.GEOMETRY_BUFFER_PARAMETRIC; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_PLANE : - componentType = GameLib.Component.GEOMETRY_BUFFER_PLANE; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_POLYHEDRON : - componentType = GameLib.Component.GEOMETRY_BUFFER_POLYHEDRON; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_RING: - componentType = GameLib.Component.GEOMETRY_BUFFER_RING; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_SHAPE : - componentType = GameLib.Component.GEOMETRY_BUFFER_SHAPE; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_SPHERE : - componentType = GameLib.Component.GEOMETRY_BUFFER_SPHERE; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TETRAHEDRON : - componentType = GameLib.Component.GEOMETRY_BUFFER_TETRAHEDRON; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TEXT : - componentType = GameLib.Component.GEOMETRY_BUFFER_TEXT; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TORUS : - componentType = GameLib.Component.GEOMETRY_BUFFER_TORUS; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TORUS_KNOT : - componentType = GameLib.Component.GEOMETRY_BUFFER_TORUS_KNOT; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TUBE : - componentType = GameLib.Component.GEOMETRY_BUFFER_TUBE; - break; - case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_INSTANCED : - componentType = GameLib.Component.GEOMETRY_BUFFER_INSTANCED; - break; - default: - throw new Error('unhandled geometry type: ' + geometryType); - } - - return componentType; -}; - -/** - * Geometry Type - * @type {number} - */ -GameLib.D3.API.Geometry.GEOMETRY_TYPE_NONE = 0x0; -GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL = 0x1; -GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_BOX = 0x2; -GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_CIRCLE = 0x3; -GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_CONE = 0x4; -GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_CYLINDER = 0x5; -GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_DODECAHEDRON = 0x6; -GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_EDGES = 0x7; -GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_EXTRUDE = 0x8; -GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_ICOSAHEDRON = 0x9; -GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_LATHE = 0xa; -GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_OCTAHEDRON = 0xb; -GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_PARAMETRIC = 0xc; -GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_PLANE = 0xd; -GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_POLYHEDRON = 0xe; -GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_RING = 0xf; -GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_SHAPE = 0x10; -GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_SPHERE = 0x11; -GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TETRAHEDRON = 0x12; -GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TEXT = 0x13; -GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TORUS = 0x14; -GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TORUS_KNOT = 0x15; -GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TUBE = 0x16; -GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_WIREFRAME = 0x17; -GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER = 0x18; -GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_BOX = 0x19; -GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CIRCLE = 0x1a; -GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CONE = 0x1b; -GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CYLINDER = 0x1c; -GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_DODECAHEDRON = 0x1d; -GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_EXTRUDE = 0x1e; -GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_ICOSAHEDRON = 0x1f; -GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_LATHE = 0x20; -GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_OCTAHEDRON = 0x21; -GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_PARAMETRIC = 0x22; -GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_PLANE = 0x23; -GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_POLYHEDRON = 0x24; -GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_RING = 0x25; -GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_SHAPE = 0x26; -GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_SPHERE = 0x27; -GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TETRAHEDRON = 0x28; -GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TEXT = 0x29; -GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TORUS = 0x2a; -GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TORUS_KNOT = 0x2b; -GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TUBE = 0x2c; -GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_INSTANCED = 0x2d; diff --git a/src/game-lib-d3-api-geometry-buffer-box.js b/src/game-lib-d3-api-geometry-buffer-box.js deleted file mode 100644 index a867708..0000000 --- a/src/game-lib-d3-api-geometry-buffer-box.js +++ /dev/null @@ -1,74 +0,0 @@ -/** - * GameLib.D3.API.Geometry.Buffer.Box - * @param apiGeometry - * @param width - * @param height - * @param depth - * @param widthSegments - * @param heightSegments - * @param depthSegments - * @constructor - */ -GameLib.D3.API.Geometry.Buffer.Box = function( - apiGeometry, - width, - height, - depth, - widthSegments, - heightSegments, - depthSegments -) { - - if (GameLib.Utils.UndefinedOrNull(apiGeometry)) { - apiGeometry = { - geometryType: GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_BOX - }; - } - - if (GameLib.Utils.UndefinedOrNull(apiGeometry.geometryType)) { - apiGeometry.geometryType = GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_BOX; - } - - if (GameLib.Utils.UndefinedOrNull(width)) { - width = 1; - } - this.width = width; - - if (GameLib.Utils.UndefinedOrNull(height)) { - height = 1; - } - this.height = height; - - if (GameLib.Utils.UndefinedOrNull(depth)) { - depth = 1; - } - this.depth = depth; - - if (GameLib.Utils.UndefinedOrNull(widthSegments)) { - widthSegments = 1; - } - this.widthSegments = widthSegments; - - if (GameLib.Utils.UndefinedOrNull(heightSegments)) { - heightSegments = 1; - } - this.heightSegments = heightSegments; - - if (GameLib.Utils.UndefinedOrNull(depthSegments)) { - depthSegments = 1; - } - this.depthSegments = depthSegments; - - GameLib.D3.API.Geometry.Buffer.call( - this, - apiGeometry, - apiGeometry.attributes, - apiGeometry.drawRange, - apiGeometry.groups, - apiGeometry.index, - apiGeometry.morphAttributes - ); -}; - -GameLib.D3.API.Geometry.Buffer.Box.prototype = Object.create(GameLib.D3.API.Geometry.Buffer.prototype); -GameLib.D3.API.Geometry.Buffer.Box.prototype.constructor = GameLib.D3.API.Geometry.Buffer.Box; diff --git a/src/game-lib-d3-api-geometry-buffer-circle.js b/src/game-lib-d3-api-geometry-buffer-circle.js deleted file mode 100644 index a7b20df..0000000 --- a/src/game-lib-d3-api-geometry-buffer-circle.js +++ /dev/null @@ -1,60 +0,0 @@ -/** - * GameLib.D3.API.Geometry.Buffer.Circle - * @param apiGeometry - * @param radius - * @param segments - * @param thetaStart - * @param thetaLength - * @constructor - */ -GameLib.D3.API.Geometry.Buffer.Circle = function( - apiGeometry, - radius, - segments, - thetaStart, - thetaLength -) { - - if (GameLib.Utils.UndefinedOrNull(apiGeometry)) { - apiGeometry = { - geometryType: GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CIRCLE - }; - } - - if (GameLib.Utils.UndefinedOrNull(apiGeometry.geometryType)) { - apiGeometry.geometryType = GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CIRCLE; - } - - if (GameLib.Utils.UndefinedOrNull(radius)) { - radius = 1; - } - this.radius = radius; - - if (GameLib.Utils.UndefinedOrNull(segments)) { - segments = 8; - } - this.segments = segments; - - if (GameLib.Utils.UndefinedOrNull(thetaStart)) { - thetaStart = 0; - } - this.thetaStart = thetaStart; - - if (GameLib.Utils.UndefinedOrNull(thetaLength)) { - thetaLength = Math.PI * 2; - } - this.thetaLength = thetaLength; - - GameLib.D3.API.Geometry.Buffer.call( - this, - apiGeometry, - apiGeometry.attributes, - apiGeometry.drawRange, - apiGeometry.groups, - apiGeometry.index, - apiGeometry.morphAttributes - ); -}; - -GameLib.D3.API.Geometry.Buffer.Circle.prototype = Object.create(GameLib.D3.API.Geometry.Buffer.prototype); -GameLib.D3.API.Geometry.Buffer.Circle.prototype.constructor = GameLib.D3.API.Geometry.Buffer.Circle; diff --git a/src/game-lib-d3-api-geometry-buffer-dodecahedron.js b/src/game-lib-d3-api-geometry-buffer-dodecahedron.js deleted file mode 100644 index 1bca3ed..0000000 --- a/src/game-lib-d3-api-geometry-buffer-dodecahedron.js +++ /dev/null @@ -1,46 +0,0 @@ -/** - * GameLib.D3.API.Geometry.Buffer.Dodecahedron - * @param apiGeometry - * @param radius - * @param detail - * @constructor - */ -GameLib.D3.API.Geometry.Buffer.Dodecahedron = function( - apiGeometry, - radius, - detail -) { - - if (GameLib.Utils.UndefinedOrNull(apiGeometry)) { - apiGeometry = { - geometryType: GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_DODECAHEDRON - }; - } - - if (GameLib.Utils.UndefinedOrNull(apiGeometry.geometryType)) { - apiGeometry.geometryType = GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_DODECAHEDRON; - } - - if (GameLib.Utils.UndefinedOrNull(radius)) { - radius = 1; - } - this.radius = radius; - - if (GameLib.Utils.UndefinedOrNull(detail)) { - detail = 0; - } - this.detail = detail; - - GameLib.D3.API.Geometry.Buffer.call( - this, - apiGeometry, - apiGeometry.attributes, - apiGeometry.drawRange, - apiGeometry.groups, - apiGeometry.index, - apiGeometry.morphAttributes - ); -}; - -GameLib.D3.API.Geometry.Buffer.Dodecahedron.prototype = Object.create(GameLib.D3.API.Geometry.Buffer.prototype); -GameLib.D3.API.Geometry.Buffer.Dodecahedron.prototype.constructor = GameLib.D3.API.Geometry.Buffer.Dodecahedron; diff --git a/src/game-lib-d3-api-geometry-buffer-icosahedron.js b/src/game-lib-d3-api-geometry-buffer-icosahedron.js deleted file mode 100644 index 00e8bf7..0000000 --- a/src/game-lib-d3-api-geometry-buffer-icosahedron.js +++ /dev/null @@ -1,46 +0,0 @@ -/** - * GameLib.D3.API.Geometry.Buffer.Icosahedron - * @param apiGeometry - * @param radius - * @param detail - * @constructor - */ -GameLib.D3.API.Geometry.Buffer.Icosahedron = function( - apiGeometry, - radius, - detail -) { - - if (GameLib.Utils.UndefinedOrNull(apiGeometry)) { - apiGeometry = { - geometryType: GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_ICOSAHEDRON - }; - } - - if (GameLib.Utils.UndefinedOrNull(apiGeometry.geometryType)) { - apiGeometry.geometryType = GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_ICOSAHEDRON; - } - - if (GameLib.Utils.UndefinedOrNull(radius)) { - radius = 1; - } - this.radius = radius; - - if (GameLib.Utils.UndefinedOrNull(detail)) { - detail = 0; - } - this.detail = detail; - - GameLib.D3.API.Geometry.Buffer.call( - this, - apiGeometry, - apiGeometry.attributes, - apiGeometry.drawRange, - apiGeometry.groups, - apiGeometry.index, - apiGeometry.morphAttributes - ); -}; - -GameLib.D3.API.Geometry.Buffer.Icosahedron.prototype = Object.create(GameLib.D3.API.Geometry.Buffer.prototype); -GameLib.D3.API.Geometry.Buffer.Icosahedron.prototype.constructor = GameLib.D3.API.Geometry.Buffer.Icosahedron; diff --git a/src/game-lib-d3-api-geometry-buffer-instanced.js b/src/game-lib-d3-api-geometry-buffer-instanced.js deleted file mode 100644 index b70a081..0000000 --- a/src/game-lib-d3-api-geometry-buffer-instanced.js +++ /dev/null @@ -1,39 +0,0 @@ -/** - * GameLib.D3.API.Geometry.Buffer.Instanced - * @param apiGeometry - * @param maxInstancedCount - * @constructor - */ -GameLib.D3.API.Geometry.Buffer.Instanced = function( - apiGeometry, - maxInstancedCount -) { - - if (GameLib.Utils.UndefinedOrNull(apiGeometry)) { - apiGeometry = { - geometryType: GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_INSTANCED - }; - } - - if (GameLib.Utils.UndefinedOrNull(apiGeometry.geometryType)) { - apiGeometry.geometryType = GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_INSTANCED; - } - - if (GameLib.Utils.UndefinedOrNull(maxInstancedCount)) { - maxInstancedCount = null; - } - this.maxInstancedCount = maxInstancedCount; - - GameLib.D3.API.Geometry.Buffer.call( - this, - apiGeometry, - apiGeometry.attributes, - apiGeometry.drawRange, - apiGeometry.groups, - apiGeometry.index, - apiGeometry.morphAttributes - ); -}; - -GameLib.D3.API.Geometry.Buffer.Instanced.prototype = Object.create(GameLib.D3.API.Geometry.Buffer.prototype); -GameLib.D3.API.Geometry.Buffer.Instanced.prototype.constructor = GameLib.D3.API.Geometry.Buffer.Instanced; diff --git a/src/game-lib-d3-api-geometry-buffer-lathe.js b/src/game-lib-d3-api-geometry-buffer-lathe.js deleted file mode 100644 index a7ae05c..0000000 --- a/src/game-lib-d3-api-geometry-buffer-lathe.js +++ /dev/null @@ -1,60 +0,0 @@ -/** - * GameLib.D3.API.Geometry.Buffer.Lathe - * @param apiGeometry - * @param points [GameLib.Vector2] (x must be larger than 0) - * @param segments - * @param phiStart - * @param phiLength - * @constructor - */ -GameLib.D3.API.Geometry.Buffer.Lathe = function( - apiGeometry, - points, - segments, - phiStart, - phiLength -) { - - if (GameLib.Utils.UndefinedOrNull(apiGeometry)) { - apiGeometry = { - geometryType: GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_LATHE - }; - } - - if (GameLib.Utils.UndefinedOrNull(apiGeometry.geometryType)) { - apiGeometry.geometryType = GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_LATHE; - } - - if (GameLib.Utils.UndefinedOrNull(points)) { - points = []; - } - this.points = points; - - if (GameLib.Utils.UndefinedOrNull(segments)) { - segments = 12; - } - this.segments = segments; - - if (GameLib.Utils.UndefinedOrNull(phiStart)) { - phiStart = 0; - } - this.phiStart = phiStart; - - if (GameLib.Utils.UndefinedOrNull(phiLength)) { - phiLength = Math.PI * 2; - } - this.phiLength = phiLength; - - GameLib.D3.API.Geometry.Buffer.call( - this, - apiGeometry, - apiGeometry.attributes, - apiGeometry.drawRange, - apiGeometry.groups, - apiGeometry.index, - apiGeometry.morphAttributes - ); -}; - -GameLib.D3.API.Geometry.Buffer.Lathe.prototype = Object.create(GameLib.D3.API.Geometry.Buffer.prototype); -GameLib.D3.API.Geometry.Buffer.Lathe.prototype.constructor = GameLib.D3.API.Geometry.Buffer.Lathe; diff --git a/src/game-lib-d3-api-geometry-buffer-octahedron.js b/src/game-lib-d3-api-geometry-buffer-octahedron.js deleted file mode 100644 index c3ea69b..0000000 --- a/src/game-lib-d3-api-geometry-buffer-octahedron.js +++ /dev/null @@ -1,46 +0,0 @@ -/** - * GameLib.D3.API.Geometry.Buffer.Octahedron - * @param apiGeometry - * @param radius - * @param detail - * @constructor - */ -GameLib.D3.API.Geometry.Buffer.Octahedron = function( - apiGeometry, - radius, - detail -) { - - if (GameLib.Utils.UndefinedOrNull(apiGeometry)) { - apiGeometry = { - geometryType: GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_OCTAHEDRON - }; - } - - if (GameLib.Utils.UndefinedOrNull(apiGeometry.geometryType)) { - apiGeometry.geometryType = GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_OCTAHEDRON; - } - - if (GameLib.Utils.UndefinedOrNull(radius)) { - radius = 1; - } - this.radius = radius; - - if (GameLib.Utils.UndefinedOrNull(detail)) { - detail = 0; - } - this.detail = detail; - - GameLib.D3.API.Geometry.Buffer.call( - this, - apiGeometry, - apiGeometry.attributes, - apiGeometry.drawRange, - apiGeometry.groups, - apiGeometry.index, - apiGeometry.morphAttributes - ); -}; - -GameLib.D3.API.Geometry.Buffer.Octahedron.prototype = Object.create(GameLib.D3.API.Geometry.Buffer.prototype); -GameLib.D3.API.Geometry.Buffer.Octahedron.prototype.constructor = GameLib.D3.API.Geometry.Buffer.Octahedron; diff --git a/src/game-lib-d3-api-geometry-buffer-parametric.js b/src/game-lib-d3-api-geometry-buffer-parametric.js deleted file mode 100644 index dd14186..0000000 --- a/src/game-lib-d3-api-geometry-buffer-parametric.js +++ /dev/null @@ -1,53 +0,0 @@ -/** - * GameLib.D3.API.Geometry.Buffer.Parametric - * @param apiGeometry - * @param generatorFn(u,v) => returns Vector3, u and v is values between 0 and 1 - * @param slices - * @param stacks - * @constructor - */ -GameLib.D3.API.Geometry.Buffer.Parametric = function( - apiGeometry, - generatorFn, - slices, - stacks -) { - - if (GameLib.Utils.UndefinedOrNull(apiGeometry)) { - apiGeometry = { - geometryType: GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_PARAMETRIC - }; - } - - if (GameLib.Utils.UndefinedOrNull(apiGeometry.geometryType)) { - apiGeometry.geometryType = GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_PARAMETRIC; - } - - if (GameLib.Utils.UndefinedOrNull(generatorFn)) { - generatorFn = ''; - } - this.generatorFn = generatorFn; - - if (GameLib.Utils.UndefinedOrNull(slices)) { - slices = 20; - } - this.slices = slices; - - if (GameLib.Utils.UndefinedOrNull(stacks)) { - stacks = 20; - } - this.stacks = stacks; - - GameLib.D3.API.Geometry.Buffer.call( - this, - apiGeometry, - apiGeometry.attributes, - apiGeometry.drawRange, - apiGeometry.groups, - apiGeometry.index, - apiGeometry.morphAttributes - ); -}; - -GameLib.D3.API.Geometry.Buffer.Parametric.prototype = Object.create(GameLib.D3.API.Geometry.Buffer.prototype); -GameLib.D3.API.Geometry.Buffer.Parametric.prototype.constructor = GameLib.D3.API.Geometry.Buffer.Parametric; diff --git a/src/game-lib-d3-api-geometry-buffer-plane.js b/src/game-lib-d3-api-geometry-buffer-plane.js deleted file mode 100644 index f1c7a7a..0000000 --- a/src/game-lib-d3-api-geometry-buffer-plane.js +++ /dev/null @@ -1,60 +0,0 @@ -/** - * GameLib.D3.API.Geometry.Buffer.Plane - * @param apiGeometry - * @param width - * @param height - * @param widthSegments - * @param heightSegments - * @constructor - */ -GameLib.D3.API.Geometry.Buffer.Plane = function( - apiGeometry, - width, - height, - widthSegments, - heightSegments -) { - - if (GameLib.Utils.UndefinedOrNull(apiGeometry)) { - apiGeometry = { - geometryType: GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_PLANE - }; - } - - if (GameLib.Utils.UndefinedOrNull(apiGeometry.geometryType)) { - apiGeometry.geometryType = GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_PLANE; - } - - if (GameLib.Utils.UndefinedOrNull(width)) { - width = 1; - } - this.width = width; - - if (GameLib.Utils.UndefinedOrNull(height)) { - height = 1; - } - this.height = height; - - if (GameLib.Utils.UndefinedOrNull(widthSegments)) { - widthSegments = 1; - } - this.widthSegments = widthSegments; - - if (GameLib.Utils.UndefinedOrNull(heightSegments)) { - heightSegments = 1; - } - this.heightSegments = heightSegments; - - GameLib.D3.API.Geometry.Buffer.call( - this, - apiGeometry, - apiGeometry.attributes, - apiGeometry.drawRange, - apiGeometry.groups, - apiGeometry.index, - apiGeometry.morphAttributes - ); -}; - -GameLib.D3.API.Geometry.Buffer.Plane.prototype = Object.create(GameLib.D3.API.Geometry.Buffer.prototype); -GameLib.D3.API.Geometry.Buffer.Plane.prototype.constructor = GameLib.D3.API.Geometry.Buffer.Plane; diff --git a/src/game-lib-d3-api-geometry-buffer-polyhedron.js b/src/game-lib-d3-api-geometry-buffer-polyhedron.js deleted file mode 100644 index b654990..0000000 --- a/src/game-lib-d3-api-geometry-buffer-polyhedron.js +++ /dev/null @@ -1,60 +0,0 @@ -/** - * GameLib.D3.API.Geometry.Buffer.Polyhedron - * @param apiGeometry - * @param vertices - * @param indices - * @param radius - * @param detail - * @constructor - */ -GameLib.D3.API.Geometry.Buffer.Polyhedron = function( - apiGeometry, - vertices, - indices, - radius, - detail -) { - - if (GameLib.Utils.UndefinedOrNull(apiGeometry)) { - apiGeometry = { - geometryType: GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_POLYHEDRON - }; - } - - if (GameLib.Utils.UndefinedOrNull(apiGeometry.geometryType)) { - apiGeometry.geometryType = GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_POLYHEDRON; - } - - if (GameLib.Utils.UndefinedOrNull(vertices)) { - vertices = []; - } - this.vertices = vertices; - - if (GameLib.Utils.UndefinedOrNull(indices)) { - indices = 1; - } - this.indices = indices; - - if (GameLib.Utils.UndefinedOrNull(radius)) { - radius = 5; - } - this.radius = radius; - - if (GameLib.Utils.UndefinedOrNull(detail)) { - detail = 0; - } - this.detail = detail; - - GameLib.D3.API.Geometry.Buffer.call( - this, - apiGeometry, - apiGeometry.attributes, - apiGeometry.drawRange, - apiGeometry.groups, - apiGeometry.index, - apiGeometry.morphAttributes - ); -}; - -GameLib.D3.API.Geometry.Buffer.Polyhedron.prototype = Object.create(GameLib.D3.API.Geometry.Buffer.prototype); -GameLib.D3.API.Geometry.Buffer.Polyhedron.prototype.constructor = GameLib.D3.API.Geometry.Buffer.Polyhedron; diff --git a/src/game-lib-d3-api-geometry-buffer-shape.js b/src/game-lib-d3-api-geometry-buffer-shape.js deleted file mode 100644 index 68626ac..0000000 --- a/src/game-lib-d3-api-geometry-buffer-shape.js +++ /dev/null @@ -1,46 +0,0 @@ -/** - * GameLib.D3.API.Geometry.Buffer.Shape - * @param apiGeometry - * @param shapes - * @param curveSegments - * @constructor - */ -GameLib.D3.API.Geometry.Buffer.Shape = function( - apiGeometry, - shapes, - curveSegments -) { - - if (GameLib.Utils.UndefinedOrNull(apiGeometry)) { - apiGeometry = { - geometryType: GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_SHAPE - }; - } - - if (GameLib.Utils.UndefinedOrNull(apiGeometry.geometryType)) { - apiGeometry.geometryType = GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_SHAPE; - } - - if (GameLib.Utils.UndefinedOrNull(shapes)) { - shapes = []; - } - this.shapes = shapes; - - if (GameLib.Utils.UndefinedOrNull(curveSegments)) { - curveSegments = 12; - } - this.curveSegments = curveSegments; - - GameLib.D3.API.Geometry.Buffer.call( - this, - apiGeometry, - apiGeometry.attributes, - apiGeometry.drawRange, - apiGeometry.groups, - apiGeometry.index, - apiGeometry.morphAttributes - ); -}; - -GameLib.D3.API.Geometry.Buffer.Shape.prototype = Object.create(GameLib.D3.API.Geometry.Buffer.prototype); -GameLib.D3.API.Geometry.Buffer.Shape.prototype.constructor = GameLib.D3.API.Geometry.Buffer.Shape; diff --git a/src/game-lib-d3-api-geometry-buffer-tetrahedron.js b/src/game-lib-d3-api-geometry-buffer-tetrahedron.js deleted file mode 100644 index aaa0569..0000000 --- a/src/game-lib-d3-api-geometry-buffer-tetrahedron.js +++ /dev/null @@ -1,46 +0,0 @@ -/** - * GameLib.D3.API.Geometry.Buffer.Tetrahedron - * @param apiGeometry - * @param radius - * @param detail - * @constructor - */ -GameLib.D3.API.Geometry.Buffer.Tetrahedron = function( - apiGeometry, - radius, - detail -) { - - if (GameLib.Utils.UndefinedOrNull(apiGeometry)) { - apiGeometry = { - geometryType: GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TETRAHEDRON - }; - } - - if (GameLib.Utils.UndefinedOrNull(apiGeometry.geometryType)) { - apiGeometry.geometryType = GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TETRAHEDRON; - } - - if (GameLib.Utils.UndefinedOrNull(radius)) { - radius = 1; - } - this.radius = radius; - - if (GameLib.Utils.UndefinedOrNull(detail)) { - detail = 0; - } - this.detail = detail; - - GameLib.D3.API.Geometry.Buffer.call( - this, - apiGeometry, - apiGeometry.attributes, - apiGeometry.drawRange, - apiGeometry.groups, - apiGeometry.index, - apiGeometry.morphAttributes - ); -}; - -GameLib.D3.API.Geometry.Buffer.Tetrahedron.prototype = Object.create(GameLib.D3.API.Geometry.Buffer.prototype); -GameLib.D3.API.Geometry.Buffer.Tetrahedron.prototype.constructor = GameLib.D3.API.Geometry.Buffer.Tetrahedron; diff --git a/src/game-lib-d3-api-geometry-buffer-torus-knot.js b/src/game-lib-d3-api-geometry-buffer-torus-knot.js deleted file mode 100644 index a0d4a4b..0000000 --- a/src/game-lib-d3-api-geometry-buffer-torus-knot.js +++ /dev/null @@ -1,74 +0,0 @@ -/** - * GameLib.D3.API.Geometry.Buffer.TorusKnot - * @param apiGeometry - * @param radius - * @param tube - * @param radialSegments - * @param tubularSegments - * @param p - * @param q - * @constructor - */ -GameLib.D3.API.Geometry.Buffer.TorusKnot = function( - apiGeometry, - radius, - tube, - radialSegments, - tubularSegments, - p, - q -) { - - if (GameLib.Utils.UndefinedOrNull(apiGeometry)) { - apiGeometry = { - geometryType: GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TORUS_KNOT - }; - } - - if (GameLib.Utils.UndefinedOrNull(apiGeometry.geometryType)) { - apiGeometry.geometryType = GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TORUS_KNOT; - } - - if (GameLib.Utils.UndefinedOrNull(radius)) { - radius = 1; - } - this.radius = radius; - - if (GameLib.Utils.UndefinedOrNull(tube)) { - tube = 0.4; - } - this.tube = tube; - - if (GameLib.Utils.UndefinedOrNull(radialSegments)) { - radialSegments = 8; - } - this.radialSegments = radialSegments; - - if (GameLib.Utils.UndefinedOrNull(tubularSegments)) { - tubularSegments = 64; - } - this.tubularSegments = tubularSegments; - - if (GameLib.Utils.UndefinedOrNull(p)) { - p = 2; - } - this.p = p; - - if (GameLib.Utils.UndefinedOrNull(q)) { - q = 3; - } - this.q = q; - - GameLib.D3.API.Geometry.Buffer.call( - this, - apiGeometry, - apiGeometry.attributes, - apiGeometry.drawRange, - apiGeometry.groups, - apiGeometry.index, - apiGeometry.morphAttributes - ); -}; - -GameLib.D3.API.Geometry.Buffer.TorusKnot.prototype = Object.create(GameLib.D3.API.Geometry.Buffer.prototype); -GameLib.D3.API.Geometry.Buffer.TorusKnot.prototype.constructor = GameLib.D3.API.Geometry.Buffer.TorusKnot; diff --git a/src/game-lib-d3-api-geometry-buffer-torus.js b/src/game-lib-d3-api-geometry-buffer-torus.js deleted file mode 100644 index 0538eda..0000000 --- a/src/game-lib-d3-api-geometry-buffer-torus.js +++ /dev/null @@ -1,67 +0,0 @@ -/** - * GameLib.D3.API.Geometry.Buffer.Torus - * @param apiGeometry - * @param radius - * @param tube - * @param radialSegments - * @param tubularSegments - * @param arc - * @constructor - */ -GameLib.D3.API.Geometry.Buffer.Torus = function( - apiGeometry, - radius, - tube, - radialSegments, - tubularSegments, - arc -) { - - if (GameLib.Utils.UndefinedOrNull(apiGeometry)) { - apiGeometry = { - geometryType: GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TORUS - }; - } - - if (GameLib.Utils.UndefinedOrNull(apiGeometry.geometryType)) { - apiGeometry.geometryType = GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TORUS; - } - - if (GameLib.Utils.UndefinedOrNull(radius)) { - radius = 1; - } - this.radius = radius; - - if (GameLib.Utils.UndefinedOrNull(tube)) { - tube = 0.4; - } - this.tube = tube; - - if (GameLib.Utils.UndefinedOrNull(radialSegments)) { - radialSegments = 8; - } - this.radialSegments = radialSegments; - - if (GameLib.Utils.UndefinedOrNull(tubularSegments)) { - tubularSegments = 6; - } - this.tubularSegments = tubularSegments; - - if (GameLib.Utils.UndefinedOrNull(arc)) { - arc = Math.PI * 2; - } - this.arc = arc; - - GameLib.D3.API.Geometry.Buffer.call( - this, - apiGeometry, - apiGeometry.attributes, - apiGeometry.drawRange, - apiGeometry.groups, - apiGeometry.index, - apiGeometry.morphAttributes - ); -}; - -GameLib.D3.API.Geometry.Buffer.Torus.prototype = Object.create(GameLib.D3.API.Geometry.Buffer.prototype); -GameLib.D3.API.Geometry.Buffer.Torus.prototype.constructor = GameLib.D3.API.Geometry.Buffer.Torus; diff --git a/src/game-lib-d3-api-geometry-buffer-tube.js b/src/game-lib-d3-api-geometry-buffer-tube.js deleted file mode 100644 index 0a700b9..0000000 --- a/src/game-lib-d3-api-geometry-buffer-tube.js +++ /dev/null @@ -1,67 +0,0 @@ -/** - * GameLib.D3.API.Geometry.Buffer.Tube - * @param apiGeometry - * @param path - * @param tubularSegments - * @param radius - * @param radialSegments - * @param closed - * @constructor - */ -GameLib.D3.API.Geometry.Buffer.Tube = function( - apiGeometry, - path, - tubularSegments, - radius, - radialSegments, - closed -) { - - if (GameLib.Utils.UndefinedOrNull(apiGeometry)) { - apiGeometry = { - geometryType: GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TUBE - }; - } - - if (GameLib.Utils.UndefinedOrNull(apiGeometry.geometryType)) { - apiGeometry.geometryType = GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TUBE; - } - - if (GameLib.Utils.UndefinedOrNull(path)) { - path = null; - } - this.path = path; - - if (GameLib.Utils.UndefinedOrNull(tubularSegments)) { - tubularSegments = 64; - } - this.tubularSegments = tubularSegments; - - if (GameLib.Utils.UndefinedOrNull(radius)) { - radius = 1; - } - this.radius = radius; - - if (GameLib.Utils.UndefinedOrNull(radialSegments)) { - radialSegments = 8; - } - this.radialSegments = radialSegments; - - if (GameLib.Utils.UndefinedOrNull(closed)) { - closed = false; - } - this.closed = closed; - - GameLib.D3.API.Geometry.Buffer.call( - this, - apiGeometry, - apiGeometry.attributes, - apiGeometry.drawRange, - apiGeometry.groups, - apiGeometry.index, - apiGeometry.morphAttributes - ); -}; - -GameLib.D3.API.Geometry.Buffer.Tube.prototype = Object.create(GameLib.D3.API.Geometry.Buffer.prototype); -GameLib.D3.API.Geometry.Buffer.Tube.prototype.constructor = GameLib.D3.API.Geometry.Buffer.Tube; diff --git a/src/game-lib-d3-api-light-a.js b/src/game-lib-d3-api-light-a.js deleted file mode 100644 index f018d42..0000000 --- a/src/game-lib-d3-api-light-a.js +++ /dev/null @@ -1,127 +0,0 @@ -/** - * Raw Light API object - should always correspond with the Light Schema - * @param id - * @param lightType - * @param name - * @param color - * @param intensity - * @param parentScene - * @param parentEntity - * @constructor - */ -GameLib.D3.API.Light = function( - id, - name, - lightType, - color, - intensity, - parentScene, - parentEntity -) { - if (GameLib.Utils.UndefinedOrNull(id)) { - id = GameLib.Utils.RandomId(); - } - this.id = id; - - if (GameLib.Utils.UndefinedOrNull(lightType)) { - lightType = GameLib.D3.API.Light.LIGHT_TYPE_AMBIENT; - } - this.lightType = lightType; - - if (GameLib.Utils.UndefinedOrNull(name)) { - - switch (this.lightType) { - case GameLib.D3.API.Light.LIGHT_TYPE_SPOT : - name = 'Light Spot'; - break; - case GameLib.D3.API.Light.LIGHT_TYPE_RECT_AREA : - name = 'Light RectArea'; - break; - case GameLib.D3.API.Light.LIGHT_TYPE_POINT : - name = 'Light Point'; - break; - case GameLib.D3.API.Light.LIGHT_TYPE_DIRECTIONAL : - name = 'Light Directional'; - break; - case GameLib.D3.API.Light.LIGHT_TYPE_HEMISPHERE : - name = 'Light Hemisphere'; - break; - case GameLib.D3.API.Light.LIGHT_TYPE_AMBIENT : - name = 'Light Ambient'; - break; - default : - console.warn('no nice name for light'); - name = 'Light'; - } - - name += ' (' + this.id + ')'; - } - this.name = name; - - if (GameLib.Utils.UndefinedOrNull(color)) { - color = new GameLib.API.Color(1,1,1); - } - this.color = color; - - if (GameLib.Utils.UndefinedOrNull(intensity)) { - intensity = 1; - } - this.intensity = intensity; - - if (GameLib.Utils.UndefinedOrNull(parentScene)) { - parentScene = null; - } - this.parentScene = parentScene; - - var componentType = GameLib.D3.API.Light.GetComponentType(this.lightType); - - GameLib.API.Component.call( - this, - componentType, - parentEntity - ); -}; - -GameLib.D3.API.Light.GetComponentType = function(lightType) { - - var componentType = null; - - switch (lightType) { - case GameLib.D3.API.Light.LIGHT_TYPE_AMBIENT : - componentType = GameLib.Component.LIGHT_AMBIENT; - break; - case GameLib.D3.API.Light.LIGHT_TYPE_DIRECTIONAL : - componentType = GameLib.Component.LIGHT_DIRECTIONAL; - break; - case GameLib.D3.API.Light.LIGHT_TYPE_POINT : - componentType = GameLib.Component.LIGHT_POINT; - break; - case GameLib.D3.API.Light.LIGHT_TYPE_SPOT : - componentType = GameLib.Component.LIGHT_SPOT; - break; - case GameLib.D3.API.Light.LIGHT_TYPE_HEMISPHERE : - componentType = GameLib.Component.LIGHT_HEMISPHERE; - break; - case GameLib.D3.API.Light.LIGHT_TYPE_RECT_AREA : - componentType = GameLib.Component.LIGHT_RECT_AREA; - break; - default : - console.error('could not determine light component type'); - } - - return componentType; -}; - -GameLib.D3.API.Light.prototype = Object.create(GameLib.API.Component.prototype); -GameLib.D3.API.Light.prototype.constructor = GameLib.D3.API.Light; - -/** - * Light Types - * @type {number} - */ -GameLib.D3.API.Light.LIGHT_TYPE_AMBIENT = 0x1; -GameLib.D3.API.Light.LIGHT_TYPE_DIRECTIONAL = 0x2; -GameLib.D3.API.Light.LIGHT_TYPE_POINT = 0x3; -GameLib.D3.API.Light.LIGHT_TYPE_SPOT = 0x4; -GameLib.D3.API.Light.LIGHT_TYPE_HEMISPHERE = 0x5; -GameLib.D3.API.Light.LIGHT_TYPE_RECT_AREA = 0x6; \ No newline at end of file diff --git a/src/game-lib-d3-api-light-ambient.js b/src/game-lib-d3-api-light-ambient.js deleted file mode 100644 index 7c77f47..0000000 --- a/src/game-lib-d3-api-light-ambient.js +++ /dev/null @@ -1,33 +0,0 @@ -/** - * Raw Light API object - should always correspond with the Light Schema - * @constructor - * @param apiLight - */ -GameLib.D3.API.Light.Ambient = function( - apiLight -) { - - if (GameLib.Utils.UndefinedOrNull(apiLight)) { - apiLight = { - lightType : GameLib.D3.API.Light.LIGHT_TYPE_AMBIENT - }; - } - - if (GameLib.Utils.UndefinedOrNull(apiLight.lightType)) { - apiLight.lightType = GameLib.D3.API.Light.LIGHT_TYPE_AMBIENT; - } - - GameLib.D3.API.Light.call( - this, - apiLight.id, - apiLight.name, - apiLight.lightType, - apiLight.color, - apiLight.intensity, - apiLight.parentScene, - apiLight.parentEntity - ); -}; - -GameLib.D3.API.Light.Ambient.prototype = Object.create(GameLib.D3.API.Light.prototype); -GameLib.D3.API.Light.Ambient.prototype.constructor = GameLib.D3.API.Light.Ambient; \ No newline at end of file diff --git a/src/game-lib-d3-api-light-hemisphere.js b/src/game-lib-d3-api-light-hemisphere.js deleted file mode 100644 index 6f8944f..0000000 --- a/src/game-lib-d3-api-light-hemisphere.js +++ /dev/null @@ -1,50 +0,0 @@ -/** - * Raw Light API object - should always correspond with the Light Schema - * @constructor - * @param apiLight - * @param position - * @param groundColor - */ -GameLib.D3.API.Light.Hemisphere = function( - apiLight, - position, - groundColor -) { - - if (GameLib.Utils.UndefinedOrNull(apiLight)) { - apiLight = { - lightType : GameLib.D3.API.Light.LIGHT_TYPE_HEMISPHERE - }; - } - - if (GameLib.Utils.UndefinedOrNull(apiLight.lightType)) { - apiLight.lightType = GameLib.D3.API.Light.LIGHT_TYPE_HEMISPHERE; - } - - /** - * Light shines from the top - */ - if (GameLib.Utils.UndefinedOrNull(position)) { - position = new GameLib.API.Vector3(0,1,0); - } - this.position = position; - - if (GameLib.Utils.UndefinedOrNull(groundColor)) { - groundColor = new GameLib.API.Color(1,1,1); - } - this.groundColor = groundColor; - - GameLib.D3.API.Light.call( - this, - apiLight.id, - apiLight.name, - apiLight.lightType, - apiLight.color, - apiLight.intensity, - apiLight.parentScene, - apiLight.parentEntity - ); -}; - -GameLib.D3.API.Light.Hemisphere.prototype = Object.create(GameLib.D3.API.Light.prototype); -GameLib.D3.API.Light.Hemisphere.prototype.constructor = GameLib.D3.API.Light.Hemisphere; \ No newline at end of file diff --git a/src/game-lib-d3-api-material-a.js b/src/game-lib-d3-api-material-a.js deleted file mode 100644 index e5196d2..0000000 --- a/src/game-lib-d3-api-material-a.js +++ /dev/null @@ -1,464 +0,0 @@ -/** - * GameLib.D3.API.Material - * @param id - * @param name - * @param materialType - * @param parentEntity - * @param parentMeshes - * @param alphaTest - * @param blendDst - * @param blendDstAlpha - * @param blendEquation - * @param blendEquationAlpha - * @param blending - * @param blendSrc - * @param blendSrcAlpha - * @param clipIntersection - * @param clippingPlanes - * @param clipShadows - * @param colorWrite - * @param customDepthMaterial - * @param customDistanceMaterial - * @param defines - * @param depthFunc - * @param depthTest - * @param depthWrite - * @param fog - * @param lights - * @param opacity - * @param overdraw - * @param polygonOffset - * @param polygonOffsetFactor - * @param polygonOffsetUnits - * @param precision - * @param premultipliedAlpha - * @param dithering - * @param flatShading - * @param side - * @param transparent - * @param vertexColors - * @param visible - * @constructor - */ -GameLib.D3.API.Material = function( - id, - name, - materialType, - parentEntity, - parentMeshes, - alphaTest, - blendDst, - blendDstAlpha, - blendEquation, - blendEquationAlpha, - blending, - blendSrc, - blendSrcAlpha, - clipIntersection, - clippingPlanes, - clipShadows, - colorWrite, - customDepthMaterial, - customDistanceMaterial, - defines, - depthFunc, - depthTest, - depthWrite, - fog, - lights, - opacity, - overdraw, - polygonOffset, - polygonOffsetFactor, - polygonOffsetUnits, - precision, - premultipliedAlpha, - dithering, - flatShading, - side, - transparent, - vertexColors, - visible -) { - - if (GameLib.Utils.UndefinedOrNull(id)) { - id = GameLib.Utils.RandomId(); - } - this.id = id; - - if (GameLib.Utils.UndefinedOrNull(materialType)) { - materialType = GameLib.D3.API.Material.MATERIAL_TYPE_NONE; - } - this.materialType = materialType; - - if (GameLib.Utils.UndefinedOrNull(name)) { - - switch (this.materialType) { - case GameLib.D3.API.Material.MATERIAL_TYPE_BASIC : - name = 'Material Basic'; - break; - case GameLib.D3.API.Material.MATERIAL_TYPE_STANDARD : - name = 'Material Standard'; - break; - case GameLib.D3.API.Material.MATERIAL_TYPE_PHONG : - name = 'Material Phong'; - break; - case GameLib.D3.API.Material.MATERIAL_TYPE_SHADER : - name = 'Material Shader'; - break; - case GameLib.D3.API.Material.MATERIAL_TYPE_SHADER_RAW : - name = 'Material Shader Raw'; - break; - case GameLib.D3.API.Material.MATERIAL_TYPE_POINTS : - name = 'Material Points'; - break; - default : - console.warn('no nice name for material'); - name = 'Material'; - } - - name += ' (' + this.id + ')'; - } - this.name = name; - - if (GameLib.Utils.UndefinedOrNull(parentMeshes)) { - parentMeshes = []; - } - this.parentMeshes = parentMeshes; - - if (GameLib.Utils.UndefinedOrNull(alphaTest)) { - alphaTest = 0; - } - this.alphaTest = alphaTest; - - if (GameLib.Utils.UndefinedOrNull(blendDst)) { - blendDst = GameLib.D3.API.Material.TYPE_ONE_MINUS_SRC_ALPHA_FACTOR; - } - this.blendDst = blendDst; - - if (GameLib.Utils.UndefinedOrNull(blendDstAlpha)) { - blendDstAlpha = null; - } - this.blendDstAlpha = blendDstAlpha; - - if (GameLib.Utils.UndefinedOrNull(blendEquation)) { - blendEquation = GameLib.D3.API.Material.TYPE_ADD_EQUATION; - } - this.blendEquation = blendEquation; - - if (GameLib.Utils.UndefinedOrNull(blendEquationAlpha)) { - blendEquationAlpha = null; - } - this.blendEquationAlpha = blendEquationAlpha; - - if (GameLib.Utils.UndefinedOrNull(blending)) { - blending = GameLib.D3.API.Material.TYPE_NORMAL_BLENDING; - } - this.blending = blending; - - if (GameLib.Utils.UndefinedOrNull(blendSrc)) { - blendSrc = GameLib.D3.API.Material.TYPE_SRC_ALPHA_FACTOR; - } - this.blendSrc = blendSrc; - - if (GameLib.Utils.UndefinedOrNull(blendSrcAlpha)) { - blendSrcAlpha = null; - } - this.blendSrcAlpha = blendSrcAlpha; - - if (GameLib.Utils.UndefinedOrNull(clipIntersection)) { - clipIntersection = false; - } - this.clipIntersection = clipIntersection; - - if (GameLib.Utils.UndefinedOrNull(clippingPlanes)) { - clippingPlanes = []; - } - this.clippingPlanes = clippingPlanes; - - if (GameLib.Utils.UndefinedOrNull(clipShadows)) { - clipShadows = false; - } - this.clipShadows = clipShadows; - - if (GameLib.Utils.UndefinedOrNull(colorWrite)) { - colorWrite = true; - } - this.colorWrite = colorWrite; - - if (GameLib.Utils.UndefinedOrNull(customDepthMaterial)) { - customDepthMaterial = null; - } - this.customDepthMaterial = customDepthMaterial; - - if (GameLib.Utils.UndefinedOrNull(customDistanceMaterial)) { - customDistanceMaterial = null; - } - this.customDistanceMaterial = customDistanceMaterial; - - if (GameLib.Utils.UndefinedOrNull(defines)) { - defines = null; - } - this.defines = defines; - - if (GameLib.Utils.UndefinedOrNull(depthFunc)) { - depthFunc = GameLib.D3.API.Material.TYPE_LESS_EQUAL_DEPTH; - } - this.depthFunc = depthFunc; - - if (GameLib.Utils.UndefinedOrNull(depthTest)) { - depthTest = true; - } - this.depthTest = depthTest; - - if (GameLib.Utils.UndefinedOrNull(depthWrite)) { - depthWrite = true; - } - this.depthWrite = depthWrite; - - if (GameLib.Utils.UndefinedOrNull(fog)) { - fog = true; - } - this.fog = fog; - - if (GameLib.Utils.UndefinedOrNull(lights)) { - - if ( - this.materialType === GameLib.D3.API.Material.MATERIAL_TYPE_BASIC || - this.materialType === GameLib.D3.API.Material.MATERIAL_TYPE_SHADER || - this.materialType === GameLib.D3.API.Material.MATERIAL_TYPE_SHADER_RAW || - this.materialType === GameLib.D3.API.Material.MATERIAL_TYPE_POINTS - ) { - lights = false; - } else { - lights = true; - } - } - this.lights = lights; - - if (GameLib.Utils.UndefinedOrNull(opacity)) { - opacity = 1.0; - } - this.opacity = opacity; - - if (GameLib.Utils.UndefinedOrNull(overdraw)) { - overdraw = 0; - } - this.overdraw = overdraw; - - if (GameLib.Utils.UndefinedOrNull(polygonOffset)) { - polygonOffset = false; - } - this.polygonOffset = polygonOffset; - - if (GameLib.Utils.UndefinedOrNull(polygonOffsetFactor)) { - polygonOffsetFactor = 0; - } - this.polygonOffsetFactor = polygonOffsetFactor; - - if (GameLib.Utils.UndefinedOrNull(polygonOffsetUnits)) { - polygonOffsetUnits = 0; - } - this.polygonOffsetUnits = polygonOffsetUnits; - - if (GameLib.Utils.UndefinedOrNull(precision)) { - precision = null; - } - this.precision = precision; - - if (GameLib.Utils.UndefinedOrNull(premultipliedAlpha)) { - premultipliedAlpha = false; - } - this.premultipliedAlpha = premultipliedAlpha; - - if (GameLib.Utils.UndefinedOrNull(dithering)) { - dithering = false; - } - this.dithering = dithering; - - if (GameLib.Utils.UndefinedOrNull(flatShading)) { - flatShading = false; - } - this.flatShading = flatShading; - - if (GameLib.Utils.UndefinedOrNull(side)) { - side = GameLib.D3.API.Material.TYPE_FRONT_SIDE; - } - this.side = side; - - if (GameLib.Utils.UndefinedOrNull(transparent)) { - transparent = false; - } - this.transparent = transparent; - - if (GameLib.Utils.UndefinedOrNull(vertexColors)) { - vertexColors = GameLib.D3.API.Material.TYPE_NO_COLORS; - } - this.vertexColors = vertexColors; - - if (GameLib.Utils.UndefinedOrNull(visible)) { - visible = true; - } - this.visible = visible; - - var componentType = GameLib.D3.API.Material.GetComponentType(this.materialType); - - this.needsUpdate = false; - - GameLib.API.Component.call( - this, - componentType, - parentEntity - ); - -}; - -GameLib.D3.API.Material.GetComponentType = function(materialType) { - - var componentType = null; - - switch (materialType) { - case GameLib.D3.API.Material.MATERIAL_TYPE_STANDARD : - componentType = GameLib.Component.MATERIAL_STANDARD; - break; - case GameLib.D3.API.Material.MATERIAL_TYPE_BASIC : - componentType = GameLib.Component.MATERIAL_BASIC; - break; - case GameLib.D3.API.Material.MATERIAL_TYPE_PHONG : - componentType = GameLib.Component.MATERIAL_PHONG; - break; - case GameLib.D3.API.Material.MATERIAL_TYPE_SHADER : - componentType = GameLib.Component.MATERIAL_SHADER; - break; - case GameLib.D3.API.Material.MATERIAL_TYPE_SHADER_RAW : - componentType = GameLib.Component.MATERIAL_SHADER_RAW; - break; - case GameLib.D3.API.Material.MATERIAL_TYPE_POINTS : - componentType = GameLib.Component.MATERIAL_POINTS; - break; - default : - throw new Error('unhandled material type: ' + materialType); - } - - return componentType; - -}; - -GameLib.D3.API.Material.prototype = Object.create(GameLib.API.Component.prototype); -GameLib.D3.API.Material.prototype.constructor = GameLib.D3.API.Material; - -/** - * Combine Method - * @type {number} - */ -GameLib.D3.API.Material.COMBINE_MULTIPLY_OPERATION = 0; -GameLib.D3.API.Material.COMBINE_MIX_OPERATION = 1; -GameLib.D3.API.Material.COMBINE_ADD_OPERATION = 2; - -/** - * Vertex Color Mode - * @type {number} - */ -GameLib.D3.API.Material.TYPE_NO_COLORS = 0; -GameLib.D3.API.Material.TYPE_FACE_COLORS = 1; -GameLib.D3.API.Material.TYPE_VERTEX_COLORS = 2; - -/** - * Blending Mode - * @type {number} - */ -GameLib.D3.API.Material.TYPE_NO_BLENDING = 0; -GameLib.D3.API.Material.TYPE_NORMAL_BLENDING = 1; -GameLib.D3.API.Material.TYPE_ADDITIVE_BLENDING = 2; -GameLib.D3.API.Material.TYPE_SUBTRACTIVE_BLENDING = 3; -GameLib.D3.API.Material.TYPE_MULTIPLY_BLENDING = 4; -GameLib.D3.API.Material.TYPE_CUSTOM_BLENDING = 5; - -/** - * Blend Source and Destination - * @type {number} - */ -GameLib.D3.API.Material.TYPE_ZERO_FACTOR = 200; -GameLib.D3.API.Material.TYPE_ONE_FACTOR = 201; -GameLib.D3.API.Material.TYPE_SRC_COLOR_FACTOR = 202; -GameLib.D3.API.Material.TYPE_ONE_MINUS_SRC_COLOR_FACTOR = 203; -GameLib.D3.API.Material.TYPE_SRC_ALPHA_FACTOR = 204; -GameLib.D3.API.Material.TYPE_ONE_MINUS_SRC_ALPHA_FACTOR = 205; -GameLib.D3.API.Material.TYPE_DST_ALPHA_FACTOR = 206; -GameLib.D3.API.Material.TYPE_ONE_MINUS_DST_ALPHA_FACTOR = 207; -GameLib.D3.API.Material.TYPE_DST_COLOR_FACTOR = 208; -GameLib.D3.API.Material.TYPE_ONE_MINUS_DST_COLOR_FACTOR = 209; -GameLib.D3.API.Material.TYPE_SRC_ALPHA_SATURATE_FACTOR = 210; - -/** - * Blend Operation - * @type {number} - */ -GameLib.D3.API.Material.TYPE_ADD_EQUATION = 100; -GameLib.D3.API.Material.TYPE_SUBTRACT_EQUATION = 101; -GameLib.D3.API.Material.TYPE_REVERSE_SUBTRACT_EQUATION = 102; -GameLib.D3.API.Material.TYPE_MIN_EQUATION = 103; -GameLib.D3.API.Material.TYPE_MAX_EQUATION = 104; - -/** - * Depth Function - * @type {number} - */ -GameLib.D3.API.Material.TYPE_NEVER_DEPTH = 0; -GameLib.D3.API.Material.TYPE_ALWAYS_DEPTH = 1; -GameLib.D3.API.Material.TYPE_LESS_DEPTH = 2; -GameLib.D3.API.Material.TYPE_LESS_EQUAL_DEPTH = 3; -GameLib.D3.API.Material.TYPE_EQUAL_DEPTH = 4; -GameLib.D3.API.Material.TYPE_GREATER_EQUAL_DEPTH = 5; -GameLib.D3.API.Material.TYPE_GREATER_DEPTH = 6; -GameLib.D3.API.Material.TYPE_NOT_EQUAL_DEPTH = 7; - -/** - * Culling Mode - * @type {number} - */ -GameLib.D3.API.Material.TYPE_FRONT_SIDE = 0; -GameLib.D3.API.Material.TYPE_BACK_SIDE = 1; -GameLib.D3.API.Material.TYPE_DOUBLE_SIDE = 2; - -/** - * Shading Type - * @type {number} - */ -GameLib.D3.API.Material.TYPE_FLAT_SHADING = 1; -GameLib.D3.API.Material.TYPE_SMOOTH_SHADING = 2; - -/** - * Material Type - * @type {string} - */ -GameLib.D3.API.Material.MATERIAL_TYPE_NONE = 0x0; -GameLib.D3.API.Material.MATERIAL_TYPE_LINE_BASIC = 0x1; -GameLib.D3.API.Material.MATERIAL_TYPE_LINE_DASHED = 0x2; -GameLib.D3.API.Material.MATERIAL_TYPE_BASIC = 0x3; -GameLib.D3.API.Material.MATERIAL_TYPE_DEPTH = 0x4; -GameLib.D3.API.Material.MATERIAL_TYPE_LAMBERT = 0x5; -GameLib.D3.API.Material.MATERIAL_TYPE_NORMAL = 0x6; -GameLib.D3.API.Material.MATERIAL_TYPE_PHONG = 0x7; -GameLib.D3.API.Material.MATERIAL_TYPE_STANDARD = 0x8; -GameLib.D3.API.Material.MATERIAL_TYPE_POINTS = 0x9; -GameLib.D3.API.Material.MATERIAL_TYPE_SPRITE = 0xa; -GameLib.D3.API.Material.MATERIAL_TYPE_TOON = 0xb; -GameLib.D3.API.Material.MATERIAL_TYPE_SHADER = 0xc; -GameLib.D3.API.Material.MATERIAL_TYPE_SHADER_RAW = 0xd; - -/** - * Line Cap - * @type {number} - */ -GameLib.D3.API.Material.LINE_CAP_BUTT = 0x1;//'butt'; -GameLib.D3.API.Material.LINE_CAP_ROUND = 0x2;//'round'; -GameLib.D3.API.Material.LINE_CAP_SQUARE = 0x3;//'square'; - -/** - * Line Join - * @type {number} - */ -GameLib.D3.API.Material.LINE_JOIN_ROUND = 0x1;//'round'; -GameLib.D3.API.Material.LINE_JOIN_BEVEL = 0x2;//'bevel'; -GameLib.D3.API.Material.LINE_JOIN_MITER = 0x3;//'miter'; diff --git a/src/game-lib-d3-api-particle.js b/src/game-lib-d3-api-particle.js deleted file mode 100644 index 0a7f52e..0000000 --- a/src/game-lib-d3-api-particle.js +++ /dev/null @@ -1,229 +0,0 @@ -/** - * Raw Particle API object - should always correspond with the Particle Schema - * @param id - * @param name - * @param lifeTime - * @param elapsed - * @param mesh - * @param opacityType - * @param fadeInFactor - * @param fadeOutFactor - * @param fadeInAfter - * @param fadeOutAfter - * @param positionOffsetType - * @param positionOffset - * @param positionOffsetFn - * @param directionType - * @param rotation - * @param scale - * @param direction - * @param directionFn - * @param speedType - * @param speed - * @param scaleFn - * @param scaleType - * @param rotationType - * @param rotationFn - * @param parentParticleEngine - * @param parentEntity - * @constructor - */ -GameLib.D3.API.Particle = function( - id, - name, - lifeTime, - elapsed, - mesh, - opacityType, - fadeInFactor, - fadeOutFactor, - fadeInAfter, - fadeOutAfter, - positionOffsetType, - positionOffset, - positionOffsetFn, - directionType, - direction, - directionFn, - speedType, - speed, - scaleType, - scale, - scaleFn, - rotationType, - rotation, - rotationFn, - parentParticleEngine, - parentEntity -) { - - if (GameLib.Utils.UndefinedOrNull(id)) { - id = GameLib.Utils.RandomId(); - } - this.id = id; - - if (GameLib.Utils.UndefinedOrNull(name)) { - name = 'Particle (' + this.id + ')'; - } - this.name = name; - - if (GameLib.Utils.UndefinedOrNull(lifeTime)) { - lifeTime = 10; - } - this.lifeTime = lifeTime; - - if (GameLib.Utils.UndefinedOrNull(elapsed)) { - elapsed = 0; - } - this.elapsed = elapsed; - - if (GameLib.Utils.UndefinedOrNull(mesh)) { - mesh = null; - } - this.mesh = mesh; - - if (GameLib.Utils.UndefinedOrNull(opacityType)) { - opacityType = GameLib.D3.API.Particle.OPACITY_TYPE_CONSTANT; - } - this.opacityType = opacityType; - - if (GameLib.Utils.UndefinedOrNull(fadeInFactor)) { - fadeInFactor = 0.01; - } - this.fadeInFactor = fadeInFactor; - - if (GameLib.Utils.UndefinedOrNull(fadeOutFactor)) { - fadeOutFactor = 0.01; - } - this.fadeOutFactor = fadeOutFactor; - - if (GameLib.Utils.UndefinedOrNull(fadeInAfter)) { - fadeInAfter = 0; - } - this.fadeInAfter = fadeInAfter; - - if (GameLib.Utils.UndefinedOrNull(fadeOutAfter)) { - fadeOutAfter = 0; - } - this.fadeOutAfter = fadeOutAfter; - - if (GameLib.Utils.UndefinedOrNull(positionOffsetType)) { - positionOffsetType = GameLib.D3.API.Particle.POSITION_OFFSET_TYPE_CONSTANT; - } - this.positionOffsetType = positionOffsetType; - - if (GameLib.Utils.UndefinedOrNull(positionOffset)) { - positionOffset = new GameLib.API.Vector3(0, 0, 0); - } - this.positionOffset = positionOffset; - - if (GameLib.Utils.UndefinedOrNull(positionOffsetFn)) { - positionOffsetFn = '//@ sourceURL=positionOffsetFn.js'; - } - this.positionOffsetFn = positionOffsetFn; - - if (GameLib.Utils.UndefinedOrNull(directionType)) { - directionType = GameLib.D3.API.Particle.DIRECTION_TYPE_CONSTANT; - } - this.directionType = directionType; - - if (GameLib.Utils.UndefinedOrNull(direction)) { - direction = new GameLib.API.Vector3(0, 1, 0); - } - this.direction = direction; - - if (GameLib.Utils.UndefinedOrNull(directionFn)) { - directionFn = '//@ sourceURL=directionFn.js'; - } - this.directionFn = directionFn; - - if (GameLib.Utils.UndefinedOrNull(speedType)) { - speedType = GameLib.D3.API.Particle.SPEED_TYPE_CONSTANT; - } - this.speedType = speedType; - - if (GameLib.Utils.UndefinedOrNull(speed)) { - speed = 1; - } - this.speed = speed; - - if (GameLib.Utils.UndefinedOrNull(scaleType)) { - scaleType = GameLib.D3.API.Particle.SCALE_TYPE_CONSTANT; - } - this.scaleType = scaleType; - - if (GameLib.Utils.UndefinedOrNull(scale)) { - scale = new GameLib.API.Vector3(1, 1, 1); - } - this.scale = scale; - - if (GameLib.Utils.UndefinedOrNull(scaleFn)) { - scaleFn = '//@ sourceURL=scaleFn.js'; - } - this.scaleFn = scaleFn; - - if (GameLib.Utils.UndefinedOrNull(rotationType)) { - rotationType = GameLib.D3.API.Particle.ROTATION_TYPE_CONSTANT; - } - this.rotationType = rotationType; - - if (GameLib.Utils.UndefinedOrNull(rotation)) { - rotation = new GameLib.API.Vector3(0, 0, 0); - } - this.rotation = rotation; - - if (GameLib.Utils.UndefinedOrNull(rotationFn)) { - rotationFn = '//@ sourceURL=rotationFn.js'; - } - this.rotationFn = rotationFn; - - if (GameLib.Utils.UndefinedOrNull(parentParticleEngine)) { - parentParticleEngine = null; - } - this.parentParticleEngine = parentParticleEngine; - - GameLib.API.Component.call( - this, - GameLib.Component.PARTICLE, - parentEntity - ); -}; - -GameLib.D3.API.Particle.prototype = Object.create(GameLib.API.Component.prototype); -GameLib.D3.API.Particle.prototype.constructor = GameLib.D3.API.Particle; - -GameLib.D3.API.Particle.OPACITY_TYPE_CONSTANT = 0x1; -GameLib.D3.API.Particle.OPACITY_TYPE_FADE_OUT_LINEAR = 0x2; -GameLib.D3.API.Particle.OPACITY_TYPE_FADE_IN_LINEAR = 0x3; -GameLib.D3.API.Particle.OPACITY_TYPE_FADE_IN_OUT_LINEAR = 0x4; - -GameLib.D3.API.Particle.POSITION_OFFSET_TYPE_CONSTANT = 0x1; -GameLib.D3.API.Particle.POSITION_OFFSET_TYPE_RANDOM = 0x2; -GameLib.D3.API.Particle.POSITION_OFFSET_TYPE_FUNCTION = 0x3; - -GameLib.D3.API.Particle.DIRECTION_TYPE_CONSTANT = 0x1; -GameLib.D3.API.Particle.DIRECTION_TYPE_RANDOM = 0x2; -GameLib.D3.API.Particle.DIRECTION_TYPE_RANDOM_NORMALIZED = 0x3; -GameLib.D3.API.Particle.DIRECTION_TYPE_FUNCTION = 0x4; - -GameLib.D3.API.Particle.SCALE_TYPE_CONSTANT = 0x1; -GameLib.D3.API.Particle.SCALE_TYPE_LINEAR = 0x2; -GameLib.D3.API.Particle.SCALE_TYPE_EXPONENTIAL = 0x3; -GameLib.D3.API.Particle.SCALE_TYPE_RANDOM = 0x4; -GameLib.D3.API.Particle.SCALE_TYPE_RANDOM_X_EQUALS_Y = 0x6; -GameLib.D3.API.Particle.SCALE_TYPE_FUNCTION = 0x7; - -GameLib.D3.API.Particle.SPEED_TYPE_CONSTANT = 0x1; -GameLib.D3.API.Particle.SPEED_TYPE_LINEAR = 0x2; -GameLib.D3.API.Particle.SPEED_TYPE_EXPONENTIAL = 0x3; -GameLib.D3.API.Particle.SPEED_TYPE_LOGARITHMIC = 0x4; -GameLib.D3.API.Particle.SPEED_TYPE_ONE_OVER_LOG = 0x5; -GameLib.D3.API.Particle.SPEED_TYPE_EXP = 0x6; -GameLib.D3.API.Particle.SPEED_TYPE_ONE_OVER_EXP = 0x7; - -GameLib.D3.API.Particle.ROTATION_TYPE_CONSTANT = 0x1; -GameLib.D3.API.Particle.ROTATION_TYPE_RANDOM = 0x2; -GameLib.D3.API.Particle.ROTATION_TYPE_RANDOM_X = 0x3; -GameLib.D3.API.Particle.ROTATION_TYPE_RANDOM_Y = 0x4; -GameLib.D3.API.Particle.ROTATION_TYPE_RANDOM_Z = 0x5; -GameLib.D3.API.Particle.ROTATION_TYPE_FUNCTION = 0x6; diff --git a/src/game-lib-d3-api-pass-0.js b/src/game-lib-d3-api-pass-0.js deleted file mode 100644 index 0fecc84..0000000 --- a/src/game-lib-d3-api-pass-0.js +++ /dev/null @@ -1,95 +0,0 @@ -/** - * GameLib.D3.API.Pass - * @param id - * @param name - * @param passType - * @param parentEntity - * @param renderToScreen - * @constructor - */ -GameLib.D3.API.Pass = function ( - id, - name, - passType, - parentEntity, - renderToScreen -) { - if (GameLib.Utils.UndefinedOrNull(id)) { - id = GameLib.Utils.RandomId(); - } - this.id = id; - - if (GameLib.Utils.UndefinedOrNull(passType)) { - passType = GameLib.D3.API.Pass.PASS_TYPE_RENDER; - } - this.passType = passType; - - if (GameLib.Utils.UndefinedOrNull(name)) { - switch (this.passType) { - case GameLib.D3.API.Pass.PASS_TYPE_RENDER: - name = 'Pass Render'; - break; - case GameLib.D3.API.Pass.PASS_TYPE_FXAA: - name = 'Pass FXAA'; - break; - case GameLib.D3.API.Pass.PASS_TYPE_BLOOM: - name = 'Pass Bloom'; - break; - case GameLib.D3.API.Pass.PASS_TYPE_SSAO: - name = 'Pass SSAO'; - break; - default: - console.warn('no custom pass name'); - name = 'Pass'; - } - - name += ' (' + id + ')'; - } - this.name = name; - - if (GameLib.Utils.UndefinedOrNull(renderToScreen)) { - renderToScreen = false; - } - this.renderToScreen = renderToScreen; - - var componentType = GameLib.D3.API.Pass.GetComponentType(this.passType); - - GameLib.API.Component.call( - this, - componentType, - parentEntity - ); -}; - -GameLib.D3.API.Pass.GetComponentType = function(passType) { - - var componentType = null; - - switch (passType) { - case GameLib.D3.API.Pass.PASS_TYPE_RENDER: - componentType = GameLib.Component.PASS_RENDER; - break; - case GameLib.D3.API.Pass.PASS_TYPE_SSAO: - componentType = GameLib.Component.PASS_SSAO; - break; - case GameLib.D3.API.Pass.PASS_TYPE_BLOOM: - componentType = GameLib.Component.PASS_BLOOM; - break; - case GameLib.D3.API.Pass.PASS_TYPE_FXAA: - componentType = GameLib.Component.PASS_FXAA; - break; - default : - throw new Error('unsupported pass type: ' + passType); - } - - return componentType; -}; - -GameLib.D3.API.Pass.prototype = Object.create(GameLib.API.Component.prototype); -GameLib.D3.API.Pass.prototype.constructor = GameLib.D3.API.Pass; - -GameLib.D3.API.Pass.PASS_TYPE_NONE = 0x0; -GameLib.D3.API.Pass.PASS_TYPE_RENDER = 0x1; -GameLib.D3.API.Pass.PASS_TYPE_SSAO = 0x2; -GameLib.D3.API.Pass.PASS_TYPE_BLOOM = 0x3; -GameLib.D3.API.Pass.PASS_TYPE_FXAA = 0x4; diff --git a/src/game-lib-d3-api-pass-fxaa.js b/src/game-lib-d3-api-pass-fxaa.js deleted file mode 100644 index 32b26c1..0000000 --- a/src/game-lib-d3-api-pass-fxaa.js +++ /dev/null @@ -1,51 +0,0 @@ -/** - * GameLib.D3.API.Pass.FXAA - * @param apiPass - * @param autoUpdateSize - * @param width - * @param height - * @constructor - */ -GameLib.D3.API.Pass.FXAA = function ( - apiPass, - autoUpdateSize, - width, - height -) { - if (GameLib.Utils.UndefinedOrNull(apiPass)) { - apiPass = { - passType: GameLib.D3.API.Pass.PASS_TYPE_FXAA - }; - } - - if (GameLib.Utils.UndefinedOrNull(apiPass.passType)) { - apiPass.passType = GameLib.D3.API.Pass.PASS_TYPE_FXAA; - } - - if (GameLib.Utils.UndefinedOrNull(autoUpdateSize)) { - autoUpdateSize = true; - } - this.autoUpdateSize = autoUpdateSize; - - if (GameLib.Utils.UndefinedOrNull(width)) { - width = 512; - } - this.width = width; - - if (GameLib.Utils.UndefinedOrNull(height)) { - height = 512; - } - this.height = height; - - GameLib.D3.API.Pass.call( - this, - apiPass.id, - apiPass.name, - apiPass.passType, - apiPass.parentEntity, - apiPass.renderToScreen - ) -}; - -GameLib.D3.API.Pass.FXAA.prototype = Object.create(GameLib.D3.API.Pass.prototype); -GameLib.D3.API.Pass.FXAA.prototype.constructor = GameLib.D3.API.Pass.FXAA; diff --git a/src/game-lib-d3-api-pass-render.js b/src/game-lib-d3-api-pass-render.js deleted file mode 100644 index f9b0fd7..0000000 --- a/src/game-lib-d3-api-pass-render.js +++ /dev/null @@ -1,44 +0,0 @@ -/** - * GameLib.D3.API.Pass.Render - * @param apiPass - * @param camera - * @param scene - * @constructor - */ -GameLib.D3.API.Pass.Render = function ( - apiPass, - scene, - camera -) { - if (GameLib.Utils.UndefinedOrNull(apiPass)) { - apiPass = { - passType: GameLib.D3.API.Pass.PASS_TYPE_RENDER - }; - } - - if (GameLib.Utils.UndefinedOrNull(apiPass.passType)) { - apiPass.passType = GameLib.D3.API.Pass.PASS_TYPE_RENDER; - } - - if (GameLib.Utils.UndefinedOrNull(scene)) { - scene = null; - } - this.scene = scene; - - if (GameLib.Utils.UndefinedOrNull(camera)) { - camera = null; - } - this.camera = camera; - - GameLib.D3.API.Pass.call( - this, - apiPass.id, - apiPass.name, - apiPass.passType, - apiPass.parentEntity, - apiPass.renderToScreen - ) -}; - -GameLib.D3.API.Pass.Render.prototype = Object.create(GameLib.D3.API.Pass.prototype); -GameLib.D3.API.Pass.Render.prototype.constructor = GameLib.D3.API.Pass.Render; diff --git a/src/game-lib-d3-api-raycaster.js b/src/game-lib-d3-api-raycaster.js deleted file mode 100644 index 0a4c3e8..0000000 --- a/src/game-lib-d3-api-raycaster.js +++ /dev/null @@ -1,46 +0,0 @@ -/** - * Raycaster for GameLib.D3 - * @param id - * @param name - * @param position GameLib.API.Vector3 - * @param direction GameLib.API.Vector3 - * @param parentEntity - * @constructor - */ -GameLib.D3.API.Raycaster = function( - id, - name, - parentEntity, - position, - direction -) { - - if (GameLib.Utils.UndefinedOrNull(id)) { - id = GameLib.Utils.RandomId(); - } - this.id = id; - - if (GameLib.Utils.UndefinedOrNull(name)) { - name = 'Raycaster (' + this.id + ')'; - } - this.name = name; - - if (GameLib.Utils.UndefinedOrNull(position)) { - position = new GameLib.API.Vector3(); - } - this.position = position; - - if (GameLib.Utils.UndefinedOrNull(direction)) { - 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.API.Component.prototype); -GameLib.D3.API.Raycaster.prototype.constructor = GameLib.D3.API.Raycaster; diff --git a/src/game-lib-d3-api-render-target-cube.js b/src/game-lib-d3-api-render-target-cube.js deleted file mode 100644 index 8093dce..0000000 --- a/src/game-lib-d3-api-render-target-cube.js +++ /dev/null @@ -1,52 +0,0 @@ -/** - * GameLib.D3.API.RenderTarget.Cube - * @constructor - * @param apiRenderTarget - */ -GameLib.D3.API.RenderTarget.Cube = function ( - apiRenderTarget -) { - - if (GameLib.Utils.UndefinedOrNull(apiRenderTarget)) { - apiRenderTarget = { - renderTargetType : GameLib.D3.API.RenderTarget.TARGET_TYPE_CUBE - }; - } - - if (GameLib.Utils.UndefinedOrNull(apiRenderTarget.renderTargetType)) { - apiRenderTarget.renderTargetType = GameLib.D3.API.RenderTarget.TARGET_TYPE_CUBE; - } - - if (GameLib.Utils.UndefinedOrNull(apiRenderTarget.textureParameters)) { - apiRenderTarget.textureParameters = { - minFilter : GameLib.D3.API.Texture.TYPE_LINEAR_MIPMAP_LINEAR_FILTER - } - } - - if (GameLib.Utils.UndefinedOrNull(apiRenderTarget.textureParameters.minFilter)) { - apiRenderTarget.textureParameters.minFilter = GameLib.D3.API.Texture.TYPE_LINEAR_MIPMAP_LINEAR_FILTER; - } - - GameLib.D3.API.RenderTarget.call( - this, - apiRenderTarget.id, - apiRenderTarget.name, - apiRenderTarget.renderTargetType, - apiRenderTarget.parentEntity, - apiRenderTarget.autoUpdateSize, - apiRenderTarget.width, - apiRenderTarget.height, - apiRenderTarget.scissor, - apiRenderTarget.scissorTest, - apiRenderTarget.viewport, - apiRenderTarget.texture, - apiRenderTarget.depthBuffer, - apiRenderTarget.depthTexture, - apiRenderTarget.stencilBuffer, - apiRenderTarget.textureParameters - ); - -}; - -GameLib.D3.API.RenderTarget.Cube.prototype = Object.create(GameLib.D3.API.RenderTarget.prototype); -GameLib.D3.API.RenderTarget.Cube.prototype.constructor = GameLib.D3.API.RenderTarget.Cube; diff --git a/src/game-lib-d3-api-shader-fragment.js b/src/game-lib-d3-api-shader-fragment.js deleted file mode 100644 index d1c6588..0000000 --- a/src/game-lib-d3-api-shader-fragment.js +++ /dev/null @@ -1,32 +0,0 @@ -/** - * GameLib.D3.API.Shader.Fragment - * @param apiShader - * @constructor - */ -GameLib.D3.API.Shader.Fragment = function( - apiShader -) { - - if (GameLib.Utils.UndefinedOrNull(apiShader)) { - apiShader = { - shaderType: GameLib.D3.API.Shader.SHADER_TYPE_FRAGMENT - }; - } - - if (GameLib.Utils.UndefinedOrNull(apiShader.materialType)) { - apiShader.shaderType = GameLib.D3.API.Shader.SHADER_TYPE_FRAGMENT; - } - - GameLib.D3.API.Shader.call( - this, - apiShader.id, - apiShader.name, - apiShader.shaderType, - apiShader.parentEntity, - apiShader.parentMaterialShader, - apiShader.code - ); -}; - -GameLib.D3.API.Shader.Fragment.prototype = Object.create(GameLib.D3.API.Shader.prototype); -GameLib.D3.API.Shader.Fragment.prototype.constructor = GameLib.D3.API.Shader.Fragment; diff --git a/src/game-lib-d3-api-shader-vertex.js b/src/game-lib-d3-api-shader-vertex.js deleted file mode 100644 index 7f769e7..0000000 --- a/src/game-lib-d3-api-shader-vertex.js +++ /dev/null @@ -1,32 +0,0 @@ -/** - * GameLib.D3.API.Shader.Vertex - * @param apiShader - * @constructor - */ -GameLib.D3.API.Shader.Vertex = function( - apiShader -) { - - if (GameLib.Utils.UndefinedOrNull(apiShader)) { - apiShader = { - shaderType: GameLib.D3.API.Shader.SHADER_TYPE_VERTEX - }; - } - - if (GameLib.Utils.UndefinedOrNull(apiShader.materialType)) { - apiShader.shaderType = GameLib.D3.API.Shader.SHADER_TYPE_VERTEX; - } - - GameLib.D3.API.Shader.call( - this, - apiShader.id, - apiShader.name, - apiShader.shaderType, - apiShader.parentEntity, - apiShader.parentMaterialShader, - apiShader.code - ); -}; - -GameLib.D3.API.Shader.Vertex.prototype = Object.create(GameLib.D3.API.Shader.prototype); -GameLib.D3.API.Shader.Vertex.prototype.constructor = GameLib.D3.API.Shader.Vertex; diff --git a/src/game-lib-d3-api-shadow-a.js b/src/game-lib-d3-api-shadow-a.js deleted file mode 100644 index 1fb5dec..0000000 --- a/src/game-lib-d3-api-shadow-a.js +++ /dev/null @@ -1,133 +0,0 @@ -/** - * GameLib.D3.API.Shadow - * @param id - * @param name - * @param shadowType - * @param camera - * @param bias - * @param mapSize - * @param radius - * @param parentEntity - * @constructor - */ -GameLib.D3.API.Shadow = function( - id, - name, - shadowType, - camera, - bias, - mapSize, - radius, - parentEntity -) { - if (GameLib.Utils.UndefinedOrNull(id)) { - id = GameLib.Utils.RandomId(); - } - this.id = id; - - if (GameLib.Utils.UndefinedOrNull(shadowType)) { - shadowType = GameLib.D3.API.Shadow.SHADOW_TYPE_NORMAL; - } - this.shadowType = shadowType; - - if (GameLib.Utils.UndefinedOrNull(name)) { - - switch (this.shadowType) { - case GameLib.D3.API.Shadow.SHADOW_TYPE_NORMAL : - name = 'Shadow Normal'; - break; - case GameLib.D3.API.Shadow.SHADOW_TYPE_DIRECTIONAL : - name = 'Shadow Directional'; - break; - case GameLib.D3.API.Shadow.SHADOW_TYPE_SPOT : - name = 'Shadow Spot'; - break; - default : - console.warn('no nice name for shadow'); - name = 'Shadow'; - } - - name += ' (' + id + ')'; - } - this.name = name; - - if (GameLib.Utils.UndefinedOrNull(camera)) { - - var cameraName = 'Camera ' + this.name; - - if (this.shadowType === GameLib.D3.API.Shadow.SHADOW_TYPE_DIRECTIONAL) { - camera = new GameLib.D3.API.Camera.Orthographic( - { - name : cameraName - }, - 10, - 0.5, - 500, - -5, - 5, - 5, - -5 - ) - } else { - camera = new GameLib.D3.API.Camera.Perspective( - { - name: cameraName, - aspect: 1 - }, - 0.5, - 500, - 90 - ); - } - } - this.camera = camera; - - if (GameLib.Utils.UndefinedOrNull(bias)) { - bias = 0;//new GameLib.API.Number(0, 0.0001, -0.1, 0.1); - } - this.bias = bias; - - if (GameLib.Utils.UndefinedOrNull(mapSize)) { - mapSize = new GameLib.API.Vector2(512, 512); - } - this.mapSize = mapSize; - - if (GameLib.Utils.UndefinedOrNull(radius)) { - radius = 1;//new GameLib.API.Number(1, 0.01, 0, 5); - } - this.radius = radius; - - var componentType = null; - - switch (this.shadowType) { - case GameLib.D3.API.Shadow.SHADOW_TYPE_NORMAL : - componentType = GameLib.Component.SHADOW; - break; - case GameLib.D3.API.Shadow.SHADOW_TYPE_DIRECTIONAL : - componentType = GameLib.Component.SHADOW_DIRECTIONAL; - break; - case GameLib.D3.API.Shadow.SHADOW_TYPE_SPOT : - componentType = GameLib.Component.SHADOW_SPOT; - break; - default : - console.error('could not determine shadow component type'); - } - - GameLib.API.Component.call( - this, - componentType, - parentEntity - ); -}; - -GameLib.D3.API.Shadow.prototype = Object.create(GameLib.API.Component.prototype); -GameLib.D3.API.Shadow.prototype.constructor = GameLib.D3.API.Shadow; - -/** - * Shadow Types - * @type {number} - */ -GameLib.D3.API.Shadow.SHADOW_TYPE_NORMAL = 0x1; -GameLib.D3.API.Shadow.SHADOW_TYPE_DIRECTIONAL = 0x2; -GameLib.D3.API.Shadow.SHADOW_TYPE_SPOT = 0x3; - diff --git a/src/game-lib-d3-api-shadow-directional.js b/src/game-lib-d3-api-shadow-directional.js deleted file mode 100644 index efce9f8..0000000 --- a/src/game-lib-d3-api-shadow-directional.js +++ /dev/null @@ -1,34 +0,0 @@ -/** - * GameLib.D3.API.Shadow - * @constructor - * @param apiDirectionalShadow - */ -GameLib.D3.API.Shadow.Directional = function( - apiDirectionalShadow -) { - - if (GameLib.Utils.UndefinedOrNull(apiDirectionalShadow)) { - apiDirectionalShadow = { - shadowType : GameLib.D3.API.Shadow.SHADOW_TYPE_DIRECTIONAL - }; - } - - if (GameLib.Utils.UndefinedOrNull(apiDirectionalShadow.shadowType)) { - apiDirectionalShadow.shadowType = GameLib.D3.API.Shadow.SHADOW_TYPE_DIRECTIONAL; - } - - GameLib.D3.API.Shadow.call( - this, - apiDirectionalShadow.id, - apiDirectionalShadow.name, - apiDirectionalShadow.shadowType, - apiDirectionalShadow.camera, - apiDirectionalShadow.bias, - apiDirectionalShadow.mapSize, - apiDirectionalShadow.radius, - apiDirectionalShadow.parentEntity - ); -}; - -GameLib.D3.API.Shadow.Directional.prototype = Object.create(GameLib.D3.API.Shadow.prototype); -GameLib.D3.API.Shadow.Directional.prototype.constructor = GameLib.D3.API.Shadow.Directional; diff --git a/src/game-lib-d3-api-shape.js b/src/game-lib-d3-api-shape.js deleted file mode 100644 index 4404551..0000000 --- a/src/game-lib-d3-api-shape.js +++ /dev/null @@ -1,154 +0,0 @@ -/** - * Raw Shape API object - should always correspond with the Shape Schema - * @param id - * @param name - * @param shapeType - * @param boundingSphereRadius - * @param collisionResponse - * @param frictionMaterial - * @param parentMesh - * @param parentEntity - * @constructor - */ -GameLib.D3.API.Shape = function( - id, - name, - shapeType, - boundingSphereRadius, - collisionResponse, - frictionMaterial, - parentMesh, - parentEntity -) { - - if (GameLib.Utils.UndefinedOrNull(id)) { - id = GameLib.Utils.RandomId(); - } - 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.shapeType === GameLib.D3.API.Shape.SHAPE_TYPE_BOX) { - name = 'Shape Box (' + this.id + ')'; - } - - 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.shapeType === GameLib.D3.API.Shape.SHAPE_TYPE_SPHERE) { - name = 'Shape Sphere (' + this.id + ')'; - } - - if (this.shapeType === GameLib.D3.API.Shape.SHAPE_TYPE_TRIMESH) { - name = 'Shape TriMesh (' + this.id + ')'; - } - } - this.name = name; - - if (GameLib.Utils.UndefinedOrNull(boundingSphereRadius)) { - boundingSphereRadius = 0; - } - this.boundingSphereRadius = boundingSphereRadius; - - if (GameLib.Utils.UndefinedOrNull(collisionResponse)) { - collisionResponse = true; - } - this.collisionResponse = collisionResponse; - - if (GameLib.Utils.UndefinedOrNull(frictionMaterial)) { - frictionMaterial = null; - } - this.frictionMaterial = frictionMaterial; - - if (GameLib.Utils.UndefinedOrNull(parentMesh)) { - parentMesh = null; - } - this.parentMesh = parentMesh; - - var componentType = GameLib.Component.SHAPE; - - if (this.shapeType === GameLib.D3.API.Shape.SHAPE_TYPE_BOX) { - componentType = GameLib.Component.SHAPE_BOX; - } - - 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.API.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 - * @constructor - */ -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, - objectShape.parentMesh, - objectShape.parentEntity - ); -}; - diff --git a/src/game-lib-d3-api-spline.js b/src/game-lib-d3-api-spline.js deleted file mode 100644 index 66b6581..0000000 --- a/src/game-lib-d3-api-spline.js +++ /dev/null @@ -1,56 +0,0 @@ -/** - * API Spline - * @param id String - * @param name String - * @param vertices GameLib.API.Vector3[] - * @param parentEntity - * @constructor - */ -GameLib.D3.API.Spline = function( - id, - name, - vertices, - parentEntity -) { - if (GameLib.Utils.UndefinedOrNull(id)) { - id = GameLib.Utils.RandomId(); - } - this.id = id; - - if (GameLib.Utils.UndefinedOrNull(name)) { - name = 'Spline (' + this.id + ')'; - } - this.name = name; - - if (GameLib.Utils.UndefinedOrNull(vertices)) { - vertices = []; - } - this.vertices = vertices; - - GameLib.API.Component.call( - this, - GameLib.Component.SPLINE, - parentEntity - ); -}; - -GameLib.D3.API.Spline.prototype = Object.create(GameLib.API.Component.prototype); -GameLib.D3.API.Spline.prototype.constructor = GameLib.D3.API.Spline; - -/** - * Object to GameLib.D3.API.Spline - * @param objectComponent - * @constructor - */ -GameLib.D3.API.Spline.FromObject = function(objectComponent) { - return new GameLib.D3.API.Spline( - objectComponent.id, - objectComponent.name, - objectComponent.vertices.map( - function (objectVertex) { - return GameLib.API.Vector3.FromObject(objectVertex); - } - ), - objectComponent.parentEntity - ); -}; diff --git a/src/game-lib-d3-api-texture-a.js b/src/game-lib-d3-api-texture-a.js deleted file mode 100644 index e61e383..0000000 --- a/src/game-lib-d3-api-texture-a.js +++ /dev/null @@ -1,327 +0,0 @@ -/** - * GameLib.D3.API.Texture - * @param id - * @param name - * @param textureType - * @param parentEntity - * @param parentMaterials - * @param mipmaps - * @param mapping - * @param wrapS - * @param wrapT - * @param magFilter - * @param minFilter - * @param anisotropy - * @param format - * @param storageType - * @param offset - * @param repeat - * @param rotation - * @param center - * @param matrixAutoUpdate - * @param generateMipMaps - * @param premultiplyAlpha - * @param flipY - * @param unpackAlignment - * @param encoding - * @param version - * @param animated - * @param reverseAnimation - * @param forward - * @constructor - */ -GameLib.D3.API.Texture = function( - id, - name, - textureType, - parentEntity, - parentMaterials, - mipmaps, - mapping, - wrapS, - wrapT, - magFilter, - minFilter, - anisotropy, - format, - storageType, - offset, - repeat, - rotation, - center, - matrixAutoUpdate, - generateMipMaps, - premultiplyAlpha, - flipY, - unpackAlignment, - encoding, - version, - animated, - reverseAnimation, - forward -) { - - if (GameLib.Utils.UndefinedOrNull(id)) { - id = GameLib.Utils.RandomId(); - } - this.id = id; - - if (GameLib.Utils.UndefinedOrNull(textureType)) { - textureType = GameLib.D3.API.Texture.TEXTURE_TYPE_NONE; - } - this.textureType = textureType; - - if (GameLib.Utils.UndefinedOrNull(name)) { - - switch (this.textureType) { - case GameLib.D3.API.Texture.TEXTURE_TYPE_IMAGE : - name = 'Texture Image'; - break; - case GameLib.D3.API.Texture.TEXTURE_TYPE_CANVAS : - name = 'Texture Canvas'; - break; - case GameLib.D3.API.Texture.TEXTURE_TYPE_CUBE : - name = 'Texture Cube'; - break; - default: - name = 'Texture'; - break; - } - - name += ' (' + id + ')'; - } - this.name = name; - - if (GameLib.Utils.UndefinedOrNull(parentMaterials)) { - parentMaterials = []; - } - this.parentMaterials = parentMaterials; - - if (GameLib.Utils.UndefinedOrNull(mipmaps)) { - mipmaps = []; - } - this.mipmaps = mipmaps; - - if (GameLib.Utils.UndefinedOrNull(mapping)) { - mapping = GameLib.D3.API.Texture.TYPE_UV_MAPPING; - } - this.mapping = mapping; - - if (GameLib.Utils.UndefinedOrNull(wrapS)) { - wrapS = GameLib.D3.API.Texture.TYPE_REPEAT_WRAPPING; - } - this.wrapS = wrapS; - - if (GameLib.Utils.UndefinedOrNull(wrapT)) { - wrapT = GameLib.D3.API.Texture.TYPE_REPEAT_WRAPPING; - } - this.wrapT = wrapT; - - if (GameLib.Utils.UndefinedOrNull(magFilter)) { - magFilter = GameLib.D3.API.Texture.TYPE_LINEAR_FILTER; - } - this.magFilter = magFilter; - - if (GameLib.Utils.UndefinedOrNull(minFilter)) { - minFilter = GameLib.D3.API.Texture.TYPE_LINEAR_MIPMAP_LINEAR_FILTER; - } - this.minFilter = minFilter; - - if (GameLib.Utils.UndefinedOrNull(anisotropy)) { - anisotropy = 1; - } - this.anisotropy = anisotropy; - - if (GameLib.Utils.UndefinedOrNull(format)) { - format = GameLib.D3.API.Texture.TYPE_RGBA_FORMAT; - } - this.format = format; - - if (GameLib.Utils.UndefinedOrNull(storageType)) { - storageType = GameLib.D3.API.Texture.TYPE_UNSIGNED_BYTE; - } - this.storageType = storageType; - - if (GameLib.Utils.UndefinedOrNull(offset)) { - offset = new GameLib.API.Vector2(0, 0); - } - this.offset = offset; - - if (GameLib.Utils.UndefinedOrNull(repeat)) { - repeat = new GameLib.API.Vector2(1, 1); - } - this.repeat = repeat; - - if (GameLib.Utils.UndefinedOrNull(rotation)) { - rotation = 0; - } - this.rotation = rotation; - - if (GameLib.Utils.UndefinedOrNull(center)) { - center = new GameLib.API.Vector2(0.5, 0.5); - } - this.center = center; - - if (GameLib.Utils.UndefinedOrNull(matrixAutoUpdate)) { - matrixAutoUpdate = true; - } - this.matrixAutoUpdate = matrixAutoUpdate; - - if (GameLib.Utils.UndefinedOrNull(generateMipMaps)) { - generateMipMaps = true; - } - this.generateMipMaps = generateMipMaps; - - if (GameLib.Utils.UndefinedOrNull(premultiplyAlpha)) { - premultiplyAlpha = false; - } - this.premultiplyAlpha = premultiplyAlpha; - - if (GameLib.Utils.UndefinedOrNull(flipY)) { - flipY = true; - } - this.flipY = flipY; - - if (GameLib.Utils.UndefinedOrNull(unpackAlignment)) { - unpackAlignment = 4; - } - this.unpackAlignment = unpackAlignment; - - if (GameLib.Utils.UndefinedOrNull(encoding)) { - encoding = GameLib.D3.API.Texture.TYPE_LINEAR_ENCODING; - } - this.encoding = encoding; - - if (GameLib.Utils.UndefinedOrNull(version)) { - version = 0 - } - this.version = version; - - if (GameLib.Utils.UndefinedOrNull(animated)) { - animated = false; - } - this.animated = animated; - - if (GameLib.Utils.UndefinedOrNull(reverseAnimation)) { - reverseAnimation = false; - } - this.reverseAnimation = reverseAnimation; - - if (GameLib.Utils.UndefinedOrNull(forward)) { - forward = true; - } - this.forward = forward; - - this.needsUpdate = false; - - GameLib.API.Component.call( - this, - GameLib.D3.API.Texture.GetComponentType(this.textureType), - parentEntity - ); -}; - -GameLib.D3.API.Texture.GetComponentType = function(textureType) { - - var componentType = null; - - switch (textureType) { - case GameLib.D3.API.Texture.TEXTURE_TYPE_NONE : - componentType = GameLib.Component.TEXTURE; - break; - case GameLib.D3.API.Texture.TEXTURE_TYPE_IMAGE : - componentType = GameLib.Component.TEXTURE_IMAGE; - break; - case GameLib.D3.API.Texture.TEXTURE_TYPE_CUBE : - componentType = GameLib.Component.TEXTURE_CUBE; - break; - case GameLib.D3.API.Texture.TEXTURE_TYPE_CANVAS : - componentType = GameLib.Component.TEXTURE_CANVAS; - break; - default : - throw new Error('unhandled texture type: ' + textureType); - } - - return componentType; -}; - -GameLib.D3.API.Texture.prototype = Object.create(GameLib.API.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. - -/** - * Texture Component Types - * @type {number} - */ -GameLib.D3.API.Texture.TEXTURE_TYPE_NONE = 0x0; -GameLib.D3.API.Texture.TEXTURE_TYPE_IMAGE = 0x1; -GameLib.D3.API.Texture.TEXTURE_TYPE_CUBE = 0x2; -GameLib.D3.API.Texture.TEXTURE_TYPE_CANVAS = 0x3; diff --git a/src/game-lib-d3-api-vertex.js b/src/game-lib-d3-api-vertex.js deleted file mode 100644 index 1d90746..0000000 --- a/src/game-lib-d3-api-vertex.js +++ /dev/null @@ -1,21 +0,0 @@ -/** - * API Vertex - * @param position GameLib.API.Vector3 - * @param boneWeights GameLib.API.BoneWeight[] - * @constructor - */ -GameLib.D3.API.Vertex = function( - position, - boneWeights -) { - - if (GameLib.Utils.UndefinedOrNull(position)) { - position = new GameLib.API.Vector3(); - } - this.position = position; - - if (GameLib.Utils.UndefinedOrNull(boneWeights)) { - boneWeights = []; - } - this.boneWeights = boneWeights; -}; diff --git a/src/game-lib-d3-bone-weight.js b/src/game-lib-d3-bone-weight.js deleted file mode 100644 index 3bfc68d..0000000 --- a/src/game-lib-d3-bone-weight.js +++ /dev/null @@ -1,40 +0,0 @@ -/** - * BoneWeight Superset - * @constructor - * @param graphics GameLib.GraphicsRuntime - * @param apiBoneWeight GameLib.D3.API.BoneWeight - */ -GameLib.D3.BoneWeight = function ( - graphics, - apiBoneWeight -) { - this.graphics = graphics; - this.graphics.isNotThreeThrow(); - - if (GameLib.Utils.UndefinedOrNull(apiBoneWeight)) { - apiBoneWeight = {}; - } - - GameLib.D3.API.BoneWeight.call( - this, - apiBoneWeight.boneIndex, - apiBoneWeight.weight - ); -}; - -GameLib.D3.BoneWeight.prototype = Object.create(GameLib.Component.prototype); -GameLib.D3.BoneWeight.prototype.constructor = GameLib.D3.BoneWeight; - -/** - * Converts a GameLib.D3.BoneWeight to GameLib.D3.API.BoneWeight - * @returns {GameLib.D3.API.BoneWeight} - */ -GameLib.D3.BoneWeight.prototype.toApiObject = function() { - - var apiBoneWeight = new GameLib.D3.API.BoneWeight( - this.boneIndex, - this.weight - ); - - return apiBoneWeight; -}; diff --git a/src/game-lib-d3-broadphase.js b/src/game-lib-d3-broadphase.js deleted file mode 100644 index 41c9173..0000000 --- a/src/game-lib-d3-broadphase.js +++ /dev/null @@ -1,118 +0,0 @@ -/** - * Broadphase Runtime - * @param physics GameLib.GraphicsRuntime - * @param apiBroadphase GameLib.D3.API.Broadphase - * @constructor - */ -GameLib.D3.Broadphase = function ( - physics, - apiBroadphase -) { - - this.physics = physics; - this.physics.isNotCannonThrow(); - - if (GameLib.Utils.UndefinedOrNull(apiBroadphase)) { - apiBroadphase = {}; - } - - GameLib.D3.API.Broadphase.call( - this, - apiBroadphase.id, - apiBroadphase.name, - apiBroadphase.broadphaseType, - apiBroadphase.parentEntity - ); - - GameLib.Component.call(this); -}; - -GameLib.D3.Broadphase.prototype = Object.create(GameLib.Component.prototype); -GameLib.D3.Broadphase.prototype.constructor = GameLib.D3.Broadphase; - -/** - * Broadphase Types - * @type {number} - */ -GameLib.D3.Broadphase.BROADPHASE_TYPE_NAIVE = 0x1; -GameLib.D3.Broadphase.BROADPHASE_TYPE_GRID = 0x2; -GameLib.D3.Broadphase.BROADPHASE_TYPE_SAP = 0x3; - -/** - * - * @returns {*} - */ -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) { - this.instance = new CANNON.SAPBroadphase(); - } else { - console.warn('Unsupported broadphase type: ' + this.broadphaseType); - throw new Error('Unsupported broadphase type: ' + this.broadphaseType); - } - - GameLib.Component.prototype.createInstance.call(this); -}; - -/** - * - */ -GameLib.D3.Broadphase.prototype.updateInstance = function(property) { - - if (this.broadphaseType === GameLib.D3.Broadphase.BROADPHASE_TYPE_NAIVE) { - if (!(this.instance instanceof CANNON.NaiveBroadphase)) { - this.createInstance(); - } - } - - if (this.broadphaseType === GameLib.D3.Broadphase.BROADPHASE_TYPE_GRID) { - if (!(this.instance instanceof CANNON.GridBroadphase)) { - this.createInstance(); - } - } - - if (this.broadphaseType === GameLib.D3.Broadphase.BROADPHASE_TYPE_SAP) { - if (!(this.instance instanceof CANNON.SAPBroadphase)) { - this.createInstance(); - } - } - - GameLib.Component.prototype.updateInstance.call(this, property); -}; - -/** - * GameLib.D3.Broadphase to GameLib.D3.API.Broadphase - * @returns {GameLib.D3.API.Broadphase} - */ -GameLib.D3.Broadphase.prototype.toApiObject = function() { - - var apiBroadphase = new GameLib.D3.API.Broadphase( - this.id, - this.name, - this.broadphaseType, - GameLib.Utils.IdOrNull(this.parentEntity) - ); - - return apiBroadphase; -}; - -/** - * GameLib.D3.Broadphase from Object Broadphase - * @param graphics - * @param objectComponent - * @returns {GameLib.D3.Broadphase} - * @constructor - */ -GameLib.D3.Broadphase.FromObject = function(graphics, objectComponent) { - - var apiBroadphase = GameLib.D3.API.Broadphase.FromObject(objectComponent); - - return new GameLib.D3.Broadphase( - graphics, - apiBroadphase - ); -}; \ No newline at end of file diff --git a/src/game-lib-d3-effect-anaglyph.js b/src/game-lib-d3-effect-anaglyph.js deleted file mode 100644 index c71e7f3..0000000 --- a/src/game-lib-d3-effect-anaglyph.js +++ /dev/null @@ -1,80 +0,0 @@ -/** - * GameLib.D3.Effect.Anaglyph - * @param graphics GameLib.GraphicsRuntime - * @param apiAnaglyphEffect - * @constructor - */ -GameLib.D3.Effect.Anaglyph = function( - graphics, - apiAnaglyphEffect -) { - - this.graphics = graphics; - this.graphics.isNotThreeThrow(); - - if (GameLib.Utils.UndefinedOrNull(apiAnaglyphEffect)) { - apiAnaglyphEffect = { - effectType : GameLib.D3.API.Effect.EFFECT_TYPE_ANAGLYPH - }; - } - - GameLib.D3.API.Effect.Anaglyph.call( - this, - apiAnaglyphEffect - ); - - GameLib.D3.Effect.call( - this, - this.graphics, - this - ); - -}; - -GameLib.D3.Effect.Anaglyph.prototype = Object.create(GameLib.D3.Effect.prototype); -GameLib.D3.Effect.Anaglyph.prototype.constructor = GameLib.D3.Effect.Anaglyph; - -/** - * Creates a camera instance - * @returns {*} - */ -GameLib.D3.Effect.Anaglyph.prototype.createInstance = function() { - - if ( - GameLib.Utils.UndefinedOrNull(this.renderer) || - GameLib.Utils.UndefinedOrNull(this.renderer.instance) - ) { - console.warn('anaglyph not ready for instance - needs a renderer'); - return; - } - - this.instance = new THREE.AnaglyphEffect( - this.renderer.instance - ); - - console.log('anaglyph effect instance created'); - - GameLib.D3.Effect.prototype.createInstance.call(this); -}; - -/** - * Updates the instance with the current state - */ -GameLib.D3.Effect.Anaglyph.prototype.updateInstance = function(property) { - GameLib.D3.Effect.prototype.updateInstance.call(this, property); -}; - -/** - * Converts a GameLib.D3.Effect to a GameLib.D3.API.Effect - * @returns {GameLib.D3.API.Effect} - */ -GameLib.D3.Effect.Anaglyph.prototype.toApiObject = function() { - - var apiEffect = GameLib.D3.Effect.prototype.toApiObject.call(this); - - var apiAnaglyphEffect = new GameLib.D3.API.Effect.Anaglyph( - apiEffect - ); - - return apiAnaglyphEffect; -}; diff --git a/src/game-lib-d3-effect-parallax.js b/src/game-lib-d3-effect-parallax.js deleted file mode 100644 index d6939fc..0000000 --- a/src/game-lib-d3-effect-parallax.js +++ /dev/null @@ -1,80 +0,0 @@ -/** - * GameLib.D3.Effect.Parallax - * @param graphics GameLib.GraphicsRuntime - * @param apiParallaxEffect - * @constructor - */ -GameLib.D3.Effect.Parallax = function( - graphics, - apiParallaxEffect -) { - - this.graphics = graphics; - this.graphics.isNotThreeThrow(); - - if (GameLib.Utils.UndefinedOrNull(apiParallaxEffect)) { - apiParallaxEffect = { - effectType : GameLib.D3.API.Effect.EFFECT_TYPE_PARALLAX - }; - } - - GameLib.D3.API.Effect.Parallax.call( - this, - apiParallaxEffect - ); - - GameLib.D3.Effect.call( - this, - this.graphics, - this - ); - -}; - -GameLib.D3.Effect.Parallax.prototype = Object.create(GameLib.D3.Effect.prototype); -GameLib.D3.Effect.Parallax.prototype.constructor = GameLib.D3.Effect.Parallax; - -/** - * Creates a camera instance - * @returns {*} - */ -GameLib.D3.Effect.Parallax.prototype.createInstance = function() { - - if ( - GameLib.Utils.UndefinedOrNull(this.renderer) || - GameLib.Utils.UndefinedOrNull(this.renderer.instance) - ) { - console.warn('parallax not ready for instance - needs a renderer'); - return; - } - - this.instance = new THREE.ParallaxBarrierEffect( - this.renderer.instance - ); - - console.log('parallax effect instance created'); - - GameLib.D3.Effect.prototype.createInstance.call(this); -}; - -/** - * Updates the instance with the current state - */ -GameLib.D3.Effect.Parallax.prototype.updateInstance = function(property) { - GameLib.D3.Effect.prototype.updateInstance.call(this, property); -}; - -/** - * Converts a GameLib.D3.Effect to a GameLib.D3.API.Effect - * @returns {GameLib.D3.API.Effect} - */ -GameLib.D3.Effect.Parallax.prototype.toApiObject = function() { - - var apiEffect = GameLib.D3.Effect.prototype.toApiObject.call(this); - - var apiParallaxEffect = new GameLib.D3.API.Effect.Parallax( - apiEffect - ); - - return apiParallaxEffect; -}; diff --git a/src/game-lib-d3-effect-stereo.js b/src/game-lib-d3-effect-stereo.js deleted file mode 100644 index 645dddf..0000000 --- a/src/game-lib-d3-effect-stereo.js +++ /dev/null @@ -1,90 +0,0 @@ -/** - * GameLib.D3.Effect.Stereo - * @param graphics GameLib.GraphicsRuntime - * @param apiStereoEffect - * @constructor - */ -GameLib.D3.Effect.Stereo = function( - graphics, - apiStereoEffect -) { - - this.graphics = graphics; - this.graphics.isNotThreeThrow(); - - if (GameLib.Utils.UndefinedOrNull(apiStereoEffect)) { - apiStereoEffect = { - effectType : GameLib.D3.API.Effect.EFFECT_TYPE_STEREO - }; - } - - GameLib.D3.API.Effect.Stereo.call( - this, - apiStereoEffect, - apiStereoEffect.eyeSeperation - ); - - GameLib.D3.Effect.call( - this, - this.graphics, - this - ); - -}; - -GameLib.D3.Effect.Stereo.prototype = Object.create(GameLib.D3.Effect.prototype); -GameLib.D3.Effect.Stereo.prototype.constructor = GameLib.D3.Effect.Stereo; - -/** - * Creates a camera instance - * @returns {*} - */ -GameLib.D3.Effect.Stereo.prototype.createInstance = function() { - - if ( - GameLib.Utils.UndefinedOrNull(this.renderer) || - GameLib.Utils.UndefinedOrNull(this.renderer.instance) - ) { - console.warn('stereo effect not ready for instance - needs a renderer'); - return; - } - - this.instance = new THREE.StereoEffect( - this.renderer.instance - ); - - this.instance.setEyeSeparation(this.eyeSeperation); - - console.log('stereo effect instance created'); - - GameLib.D3.Effect.prototype.createInstance.call(this); -}; - -/** - * Updates the instance with the current state - */ -GameLib.D3.Effect.Stereo.prototype.updateInstance = function(property) { - - if (property === 'eyeSeperation') { - this.instance.setEyeSeparation(this.eyeSeperation); - return; - } - - GameLib.D3.Effect.prototype.updateInstance.call(this, property); -}; - -/** - * Converts a GameLib.D3.Effect to a GameLib.D3.API.Effect - * @returns {GameLib.D3.API.Effect} - */ -GameLib.D3.Effect.Stereo.prototype.toApiObject = function() { - - var apiEffect = GameLib.D3.Effect.prototype.toApiObject.call(this); - - var apiStereoEffect = new GameLib.D3.API.Effect.Stereo( - apiEffect, - this.eyeSeperation - ); - - return apiStereoEffect; -}; diff --git a/src/game-lib-d3-font.js b/src/game-lib-d3-font.js deleted file mode 100644 index 874457e..0000000 --- a/src/game-lib-d3-font.js +++ /dev/null @@ -1,97 +0,0 @@ -/** - * Font Superset - The apiFont properties get moved into the Font object itself, and then the instance is created - * @param graphics GameLib.GraphicsRuntime - * @param apiFont GameLib.D3.API.Font - * @constructor - */ -GameLib.D3.Font = function( - graphics, - apiFont -) { - this.graphics = graphics; - this.graphics.isNotThreeThrow(); - - if (GameLib.Utils.UndefinedOrNull(apiFont)) { - apiFont = {}; - } - - GameLib.D3.API.Font.call( - this, - apiFont.id, - apiFont.name, - apiFont.url, - apiFont.parentEntity - ); - - GameLib.Component.call(this); -}; - -GameLib.D3.Font.prototype = Object.create(GameLib.Component.prototype); -GameLib.D3.Font.prototype.constructor = GameLib.D3.Font; - -/** - * Creates a light instance - * @returns {*} - */ -GameLib.D3.Font.prototype.createInstance = function() { - - GameLib.Event.Emit( - GameLib.Event.LOAD_FONT, - { - font : this - }, - function(fontInstance) { - this.instance = fontInstance; - - console.log('font instance loaded'); - - 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.D3.Font.prototype.updateInstance = function(property) { - - if (property === 'url') { - this.createInstance(); - } - - GameLib.Component.prototype.updateInstance.call(this, property); -}; - -/** - * Converts a GameLib.D3.Font to a GameLib.D3.API.Font - * @returns {GameLib.D3.API.Font} - */ -GameLib.D3.Font.prototype.toApiObject = function() { - return new GameLib.D3.API.Font( - this.id, - this.name, - this.url, - GameLib.Utils.IdOrNull(this.parentEntity) - ); -}; - -/** - * Returns a new GameLib.D3.Font from a GameLib.D3.API.Font - * @param graphics GameLib.GraphicsRuntime - * @param objectFont GameLib.D3.API.Font - * @returns {GameLib.D3.Font} - */ -GameLib.D3.Font.FromObject = function(graphics, objectFont) { - - return new GameLib.D3.Font( - graphics, - GameLib.D3.API.Font.FromObject(objectFont) - ); - -}; \ No newline at end of file diff --git a/src/game-lib-d3-friction-material.js b/src/game-lib-d3-friction-material.js deleted file mode 100644 index 9b6396e..0000000 --- a/src/game-lib-d3-friction-material.js +++ /dev/null @@ -1,90 +0,0 @@ -/** - * FrictionMaterial Runtime - * @param physics GameLib.GraphicsRuntime - * @param apiFrictionMaterial GameLib.D3.API.FrictionMaterial - * @constructor - */ -GameLib.D3.FrictionMaterial = function ( - physics, - apiFrictionMaterial -) { - - this.physics = physics; - this.physics.isNotCannonThrow(); - - if (GameLib.Utils.UndefinedOrNull(apiFrictionMaterial)) { - apiFrictionMaterial = {}; - } - - GameLib.D3.API.FrictionMaterial.call( - this, - apiFrictionMaterial.id, - apiFrictionMaterial.name, - apiFrictionMaterial.friction, - apiFrictionMaterial.restitution, - apiFrictionMaterial.parentEntity - ); - - GameLib.Component.call(this); -}; - -GameLib.D3.FrictionMaterial.prototype = Object.create(GameLib.Component.prototype); -GameLib.D3.FrictionMaterial.prototype.constructor = GameLib.D3.FrictionMaterial; - -/** - * create instance - */ -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 to GameLib.D3.API.FrictionMaterial - * @returns {GameLib.D3.API.FrictionMaterial} - */ -GameLib.D3.FrictionMaterial.prototype.toApiObject = function() { - - var apiFrictionMaterial = new GameLib.D3.API.FrictionMaterial( - this.id, - this.name, - this.friction, - this.restitution, - GameLib.Utils.IdOrNull(this.parentEntity) - ); - - return apiFrictionMaterial; -}; - -/** - * GameLib.D3.FrictionMaterial from Object FrictionMaterial - * @param physics - * @param objectComponent - * @returns {GameLib.D3.FrictionMaterial} - * @constructor - */ -GameLib.D3.FrictionMaterial.FromObject = function(physics, objectComponent) { - - var apiFrictionMaterial = GameLib.D3.API.FrictionMaterial.FromObject(objectComponent); - - return new GameLib.D3.FrictionMaterial( - physics, - apiFrictionMaterial - ); -}; diff --git a/src/game-lib-d3-geometry-buffer-instanced.js b/src/game-lib-d3-geometry-buffer-instanced.js deleted file mode 100644 index 5db91f7..0000000 --- a/src/game-lib-d3-geometry-buffer-instanced.js +++ /dev/null @@ -1,82 +0,0 @@ -/** - * GameLib.D3.Geometry.Buffer.Instanced - * @param graphics GameLib.GraphicsRuntime - * @param apiGeometryBufferInstanced - * @constructor - */ -GameLib.D3.Geometry.Buffer.Instanced = function( - graphics, - apiGeometryBufferInstanced -) { - - this.graphics = graphics; - this.graphics.isNotThreeThrow(); - - if (GameLib.Utils.UndefinedOrNull(apiGeometryBufferInstanced)) { - apiGeometryBufferInstanced = { - geometryType : GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_INSTANCED - }; - } - - GameLib.D3.API.Geometry.Buffer.Instanced.call( - this, - apiGeometryBufferInstanced, - apiGeometryBufferInstanced.maxInstancedCount - ); - - GameLib.D3.Geometry.Buffer.call( - this, - this.graphics, - apiGeometryBufferInstanced - ); - -}; - -GameLib.D3.Geometry.Buffer.Instanced.prototype = Object.create(GameLib.D3.Geometry.Buffer.prototype); -GameLib.D3.Geometry.Buffer.Instanced.prototype.constructor = GameLib.D3.Geometry.Buffer.Instanced; - -/** - * Creates a light instance - * @returns {*} - */ -GameLib.D3.Geometry.Buffer.Instanced.prototype.createInstance = function() { - - this.instance = new THREE.InstancedBufferGeometry(); - - if (GameLib.Utils.Defined(this.maxInstancedCount)) { - this.instance.maxInstancedCount = this.maxInstancedCount; - } - - GameLib.D3.Geometry.Buffer.prototype.createInstance.call(this); -}; - -/** - * Updates the instance with the current state - */ -GameLib.D3.Geometry.Buffer.Instanced.prototype.updateInstance = function(property) { - - if ( - property === 'maxInstancedCount' - ) { - this.instance.maxInstancedCount = this.maxInstancedCount; - return; - } - - GameLib.D3.Geometry.Buffer.prototype.updateInstance.call(this, property); -}; - -/** - * Converts a GameLib.D3.Geometry.Buffer.Instanced to a GameLib.D3.API.Geometry.Buffer.Instanced - * @returns {GameLib.D3.API.Geometry.Buffer} - */ -GameLib.D3.Geometry.Buffer.Instanced.prototype.toApiObject = function() { - - var apiBufferGeometry = GameLib.D3.Geometry.Buffer.prototype.toApiObject.call(this); - - var apiGeometryBufferInstanced = new GameLib.D3.API.Geometry.Buffer.Instanced( - apiBufferGeometry, - this.maxInstancedCount - ); - - return apiGeometryBufferInstanced; -}; diff --git a/src/game-lib-d3-helper.js b/src/game-lib-d3-helper.js deleted file mode 100644 index 6ad21af..0000000 --- a/src/game-lib-d3-helper.js +++ /dev/null @@ -1,159 +0,0 @@ -/** - * Helpers for displaying outlines or making 'invisible' scene objects visible - * @param graphics GameLib.GraphicsRuntime - * @param id - * @param name - * @param object - * @param helperType - * @param parentEntity - * @constructor - */ -GameLib.D3.Helper = function( - graphics, - id, - name, - object, - helperType, - parentEntity -) { - this.graphics = graphics; - this.graphics.isNotThreeThrow(); - - if (GameLib.Utils.UndefinedOrNull(id)) { - id = GameLib.Utils.RandomId(); - } - this.id = id; - - if (GameLib.Utils.UndefinedOrNull(name)) { - name = 'Helper (' + id + ')'; - } - this.name = name; - - if (GameLib.Utils.UndefinedOrNull(object)) { - console.warn('Cannot create a helper for an Object which does not exist'); - throw new Error('Cannot create a helper for an Object which does not exist'); - } - this.object = object; - - if (GameLib.Utils.UndefinedOrNull(helperType)) { - - helperType = GameLib.D3.Helper.HELPER_TYPE_NONE; - - if ( - object instanceof GameLib.D3.Mesh && - object.meshType !== GameLib.D3.API.Object.OBJECT_TYPE_MESH_CURVE - ) { - helperType = GameLib.D3.Helper.HELPER_TYPE_EDGES; - } - - if (object instanceof GameLib.D3.Light) { - if (object.lightType === GameLib.D3.API.Light.LIGHT_TYPE_DIRECTIONAL) { - helperType = GameLib.D3.Helper.HELPER_TYPE_DIRECTIONAL_LIGHT; - } - - if (object.lightType === GameLib.D3.API.Light.LIGHT_TYPE_POINT) { - helperType = GameLib.D3.Helper.HELPER_TYPE_POINT_LIGHT; - } - - if (object.lightType === GameLib.D3.API.Light.LIGHT_TYPE_SPOT) { - helperType = GameLib.D3.Helper.HELPER_TYPE_SPOT_LIGHT; - } - } - - if (object instanceof GameLib.D3.Skeleton) { - helperType = GameLib.D3.Helper.HELPER_TYPE_SKELETON; - } - } - this.helperType = helperType; - - if (GameLib.Utils.UndefinedOrNull(parentEntity)) { - parentEntity = null; - } - this.parentEntity = parentEntity; - - this.createInstance(); - /** - * A helper as a component - does this make sense at all? - */ - // GameLib.Component.call( - // this, - // GameLib.Component.HELPER - // ); -}; - -GameLib.D3.Helper.prototype = Object.create(GameLib.Component.prototype); -GameLib.D3.Helper.prototype.constructor = GameLib.D3.Helper; - -/** - * Helper types - * @type {string} - */ -GameLib.D3.Helper.HELPER_TYPE_NONE = 0x0; -GameLib.D3.Helper.HELPER_TYPE_EDGES = 0x1; -GameLib.D3.Helper.HELPER_TYPE_DIRECTIONAL_LIGHT = 0x2; -GameLib.D3.Helper.HELPER_TYPE_SPOT_LIGHT = 0x3; -GameLib.D3.Helper.HELPER_TYPE_POINT_LIGHT = 0x4; -GameLib.D3.Helper.HELPER_TYPE_WIREFRAME = 0x5; -GameLib.D3.Helper.HELPER_TYPE_SKELETON = 0x6; - -/** - * Creates a helper instance - */ -GameLib.D3.Helper.prototype.createInstance = function() { - - if (this.helperType === GameLib.D3.Helper.HELPER_TYPE_EDGES) { - this.instance = new THREE.LineSegments( - new THREE.EdgesGeometry( - this.object.instance.geometry - ), - new THREE.LineBasicMaterial( - { - color:0x00ff00, - linewidth:2 - } - ) - ); - - this.updateInstance(); - } - - if (this.helperType === GameLib.D3.Helper.HELPER_TYPE_DIRECTIONAL_LIGHT) { - this.instance = new THREE.DirectionalLightHelper(this.object.instance); - } - - if (this.helperType === GameLib.D3.Helper.HELPER_TYPE_POINT_LIGHT) { - this.instance = new THREE.PointLightHelper(this.object.instance, 1); - } - - if (this.helperType === GameLib.D3.Helper.HELPER_TYPE_SPOT_LIGHT) { - this.instance = new THREE.SpotLightHelper(this.object.instance); - } - - if (this.helperType === GameLib.D3.Helper.HELPER_TYPE_WIREFRAME) { - this.instance = new THREE.WireframeGeometry(this.object.instance, 0x00FF00); - } - - if (this.helperType === GameLib.D3.Helper.HELPER_TYPE_SKELETON) { - this.instance = new THREE.SkeletonHelper(this.object.instance); - } - -}; - -/** - * Updates the instance with the current state - */ -GameLib.D3.Helper.prototype.updateInstance = function() { - - this.instance.position.copy(this.object.instance.position); - this.instance.scale.copy(this.object.instance.scale); - this.instance.quaternion.copy(this.object.instance.quaternion); - - if (this.object.parentMesh && this.object.parentMesh.instance) { - this.object.parentMesh.instance.add(this.instance); - - this.instance.applyMatrix(this.object.instance.matrix); - this.instance.updateMatrix(); - - this.instance.updateMatrixWorld(); - } -}; diff --git a/src/game-lib-d3-light-ambient.js b/src/game-lib-d3-light-ambient.js deleted file mode 100644 index 83806c1..0000000 --- a/src/game-lib-d3-light-ambient.js +++ /dev/null @@ -1,64 +0,0 @@ -/** - * GameLib.D3.Light.Ambient - * @param graphics GameLib.GraphicsRuntime - * @param apiAmbientLight - * @constructor - */ -GameLib.D3.Light.Ambient = function( - graphics, - apiAmbientLight -) { - - this.graphics = graphics; - this.graphics.isNotThreeThrow(); - - if (GameLib.Utils.UndefinedOrNull(apiAmbientLight)) { - apiAmbientLight = { - lightType : GameLib.D3.API.Light.LIGHT_TYPE_AMBIENT - }; - } - - GameLib.D3.API.Light.Ambient.call( - this, - apiAmbientLight - ); - - GameLib.D3.Light.call( - this, - this.graphics, - apiAmbientLight - ); - -}; - -GameLib.D3.Light.Ambient.prototype = Object.create(GameLib.D3.Light.prototype); -GameLib.D3.Light.Ambient.prototype.constructor = GameLib.D3.Light.Ambient; - -/** - * Creates a light instance - * @returns {*} - */ -GameLib.D3.Light.Ambient.prototype.createInstance = function() { - - this.instance = new THREE.AmbientLight(); - - GameLib.D3.Light.prototype.createInstance.call(this); -}; - -/** - * Updates the instance with the current state - */ -GameLib.D3.Light.Ambient.prototype.updateInstance = function(property) { - GameLib.D3.Light.prototype.updateInstance.call(this, property); -}; - -/** - * Converts a GameLib.D3.Light to a GameLib.D3.API.Light - * @returns {GameLib.D3.API.Light} - */ -GameLib.D3.Light.Ambient.prototype.toApiObject = function() { - - var apiLight = GameLib.D3.Light.prototype.toApiObject.call(this); - - return apiLight; -}; diff --git a/src/game-lib-d3-pass-0.js b/src/game-lib-d3-pass-0.js deleted file mode 100644 index 29e9e55..0000000 --- a/src/game-lib-d3-pass-0.js +++ /dev/null @@ -1,114 +0,0 @@ -/** - * GameLib.D3.Pass - * @param graphics GameLib.GraphicsRuntime - * @param apiPass GameLib.D3.API.Pass - * @property passType - * @constructor - */ -GameLib.D3.Pass = function ( - graphics, - apiPass -) { - - this.graphics = graphics; - this.graphics.isNotThreeThrow(); - - if (GameLib.Utils.UndefinedOrNull(apiPass)) { - apiPass = { - passType : GameLib.D3.API.Pass.PASS_TYPE_NONE - } - } - - GameLib.D3.API.Pass.call( - this, - apiPass.id, - apiPass.name, - apiPass.passType, - apiPass.parentEntity, - apiPass.renderToScreen - ); - - var linkedObjects = {}; - - switch (this.passType) { - case GameLib.D3.API.Pass.PASS_TYPE_RENDER: - case GameLib.D3.API.Pass.PASS_TYPE_SSAO: - linkedObjects.scene = GameLib.D3.Scene; - linkedObjects.camera = GameLib.D3.Camera; - break; - default : - break; - } - - GameLib.Component.call( - this, - linkedObjects - ); -}; - -GameLib.D3.Pass.prototype = Object.create(GameLib.Component.prototype); -GameLib.D3.Pass.prototype.constructor = GameLib.D3.Pass; - - -/** - * Create Pass instance - * @returns {*} - */ -GameLib.D3.Pass.prototype.createInstance = function() { - - if (GameLib.Utils.UndefinedOrNull(this.instance)) { - console.warn('no instance - call the child createInstance() first'); - return; - } - - this.instance.renderToScreen = this.renderToScreen; - - GameLib.Component.prototype.createInstance.call(this); - -}; - -/** - * Update Pass instance - */ -GameLib.D3.Pass.prototype.updateInstance = function(property) { - - - if (property === 'passType') { - - var componentType = GameLib.D3.API.Pass.GetComponentType(this.passType); - - this.replace(componentType); - - return; - } - - if (property === 'renderToScreen') { - this.instance.renderToScreen = this.renderToScreen; - } - - GameLib.Component.prototype.updateInstance.call(this, property); -}; - -/** - * Not all passes have setSize, but this is just a safety function in case someone calls setSize on a pass component - * @param property - */ -GameLib.D3.Pass.prototype.setSize = function(property) { -}; - -/** - * GameLib.D3.Pass to GameLib.D3.API.Pass - * @returns {GameLib.D3.API.Pass} - */ -GameLib.D3.Pass.prototype.toApiObject = function() { - - var apiPass = new GameLib.D3.API.Pass( - this.id, - this.name, - this.passType, - GameLib.Utils.IdOrNull(this.parentEntity), - this.renderToScreen - ); - - return apiPass; -}; diff --git a/src/game-lib-d3-pass-render.js b/src/game-lib-d3-pass-render.js deleted file mode 100644 index 3a4c93d..0000000 --- a/src/game-lib-d3-pass-render.js +++ /dev/null @@ -1,130 +0,0 @@ -/** - * GameLib.D3.Pass.Render - * @param graphics GameLib.GraphicsRuntime - * @param apiPassRender GameLib.D3.API.Pass.Render - * @constructor - */ -GameLib.D3.Pass.Render = function ( - graphics, - apiPassRender -) { - - this.graphics = graphics; - this.graphics.isNotThreeThrow(); - - if (GameLib.Utils.UndefinedOrNull(apiPassRender)) { - apiPassRender = { - passType : GameLib.D3.API.Pass.PASS_TYPE_RENDER - }; - } - - GameLib.D3.API.Pass.Render.call( - this, - apiPassRender, - apiPassRender.scene, - apiPassRender.camera - ); - - if (this.scene instanceof GameLib.D3.API.Scene) { - this.scene = new GameLib.D3.Scene( - this.graphics, - this.scene - ) - } - - if (this.camera instanceof GameLib.D3.API.Camera) { - this.camera = new GameLib.D3.Camera( - this.graphics, - this.camera - ) - } - - GameLib.D3.Pass.call( - this, - this.graphics, - this - ); -}; - -GameLib.D3.Pass.Render.prototype = Object.create(GameLib.D3.Pass.prototype); -GameLib.D3.Pass.Render.prototype.constructor = GameLib.D3.Pass.Render; - -/** - * Create Pass.Render instance - * @returns {*} - */ -GameLib.D3.Pass.Render.prototype.createInstance = function() { - - if (GameLib.Utils.UndefinedOrNull(this.scene) || - GameLib.Utils.UndefinedOrNull(this.scene.instance) - ) { - console.warn('scene not ready'); - return; - } - - if (GameLib.Utils.UndefinedOrNull(this.camera) || - GameLib.Utils.UndefinedOrNull(this.camera.instance) - ) { - console.warn('camera not ready'); - return; - } - - this.instance = new THREE.RenderPass( - this.scene.instance, - this.camera.instance - ); - - console.log('Constructed a render pass instance'); - - GameLib.D3.Pass.prototype.createInstance.call(this); -}; - -/** - * Update Pass.Render instance - */ -GameLib.D3.Pass.Render.prototype.updateInstance = function(property) { - - if (property === 'scene') { - if (GameLib.Utils.UndefinedOrNull(this.instance)) { - this.createInstance(); - } - - if (this.instance && this.scene.instance) { - this.instance.scene = this.scene.instance; - } - - return; - } - - if (property === 'camera') { - if (GameLib.Utils.UndefinedOrNull(this.instance)) { - this.createInstance(); - } - - if (this.instance && this.camera.instance) { - this.instance.camera = this.camera.instance; - } - - return; - } - - GameLib.D3.Pass.prototype.updateInstance.call(this, property); - -}; - -/** - * GameLib.D3.Pass.Render to GameLib.D3.API.Pass.Render - * @returns {GameLib.D3.API.Pass.Render} - */ -GameLib.D3.Pass.Render.prototype.toApiObject = function() { - - var apiPass = GameLib.D3.Pass.prototype.toApiObject.call(this); - - var apiRenderPass = new GameLib.D3.API.Pass.Render( - apiPass, - GameLib.Utils.IdOrNull(this.scene), - GameLib.Utils.IdOrNull(this.camera) - ); - - return apiRenderPass; -}; diff --git a/src/game-lib-d3-raycast-vehicle.js b/src/game-lib-d3-raycast-vehicle.js deleted file mode 100644 index c206864..0000000 --- a/src/game-lib-d3-raycast-vehicle.js +++ /dev/null @@ -1,173 +0,0 @@ -/** - * RaycastVehicle Runtime - * @param physics GameLib.GraphicsRuntime - * @param apiRaycastVehicle GameLib.D3.API.RaycastVehicle - * @constructor - */ -GameLib.D3.RaycastVehicle = function ( - physics, - apiRaycastVehicle -) { - - this.physics = physics; - this.physics.isNotCannonThrow(); - - if (GameLib.Utils.UndefinedOrNull(apiRaycastVehicle)) { - apiRaycastVehicle = {}; - } - - GameLib.D3.API.RaycastVehicle.call( - this, - apiRaycastVehicle.id, - apiRaycastVehicle.name, - apiRaycastVehicle.chassis, - apiRaycastVehicle.wheels, - apiRaycastVehicle.raycastWheels, - apiRaycastVehicle.parentPhysicsWorld, - apiRaycastVehicle.parentEntity - ); - - if (this.chassis instanceof GameLib.D3.API.RaycastVehicle) { - this.chassis = new GameLib.D3.RaycastVehicle( - this.physics, - this.chassis - ) - } - - this.wheels = this.wheels.map(function(wheel){ - if (wheel instanceof GameLib.D3.API.RigidBody) { - return new GameLib.D3.RigidBody( - this.physics, - wheel - ) - } else { - return wheel; - } - }.bind(this)); - - this.raycastWheels = this.raycastWheels.map(function(raycastWheel){ - if (raycastWheel instanceof GameLib.D3.API.RaycastWheel) { - return new GameLib.D3.RaycastWheel( - this.physics, - raycastWheel - ) - } else { - return raycastWheel; - } - }.bind(this)); - - GameLib.Component.call( - this, - { - 'chassis' : GameLib.D3.RigidBody, - 'wheels' : [GameLib.D3.RigidBody], - 'raycastWheels' : [GameLib.D3.RaycastWheel], - 'parentPhysicsWorld' : GameLib.D3.PhysicsWorld - } - ); -}; - -GameLib.D3.RaycastVehicle.prototype = Object.create(GameLib.Component.prototype); -GameLib.D3.RaycastVehicle.prototype.constructor = GameLib.D3.RaycastVehicle; - -/** - * - * @returns {*} - */ -GameLib.D3.RaycastVehicle.prototype.createInstance = function() { - - /** - * At this point - even though this component exists - the chassis could maybe not been have assigned, failed to - * register as a dependency, and therefore is not present at the time of createInstance() - we will need to call - * delayedInstance somehow... - * @type {GameLib.D3.RaycastVehicle|GameLib.D3.API.RaycastVehicle|*} - */ - - 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.parentPhysicsWorld)) { - throw new Error('no parent world'); - } - - if (GameLib.Utils.UndefinedOrNull(this.parentPhysicsWorld.instance)) { - throw new Error('no parent world instance'); - } - - this.instance = new CANNON.RaycastVehicle({ - chassisBody: this.chassis.instance - }); - - this.raycastWheels.map( - function(wheel){ - - if (GameLib.Utils.UndefinedOrNull(wheel)) { - throw new Error('no wheel'); - } - - if (GameLib.Utils.UndefinedOrNull(wheel.instance)) { - throw new Error('no wheel instance'); - } - - this.instance.addWheel(wheel.instance); - - }.bind(this) - ); - - this.instance.addToWorld(this.parentPhysicsWorld.instance); - - GameLib.Component.prototype.createInstance.call(this); - -}; - -GameLib.D3.RaycastVehicle.prototype.updateInstance = function(property) { - // this.instance.chassisBody = this.chassis.instance; - //TODO: add / remove wheels? - console.log('TODO: update raycast vehicle instance'); - GameLib.Component.prototype.updateInstance.call(this, property); -}; - -/** - * GameLib.D3.RaycastVehicle to GameLib.D3.API.RaycastVehicle - * @returns {GameLib.D3.API.RaycastVehicle} - */ -GameLib.D3.RaycastVehicle.prototype.toApiObject = function() { - - var apiRaycastVehicle = new GameLib.D3.API.RaycastVehicle( - this.id, - this.name, - GameLib.Utils.IdOrNull(this.chassis), - this.wheels.map(function(wheel){ - return GameLib.Utils.IdOrNull(wheel); - }), - this.raycastWheels.map(function(raycastWheel){ - return GameLib.Utils.IdOrNull(raycastWheel); - }), - GameLib.Utils.IdOrNull(this.parentPhysicsWorld), - GameLib.Utils.IdOrNull(this.parentEntity) - ); - - return apiRaycastVehicle; -}; - -/** - * GameLib.D3.RaycastVehicle from Object RaycastVehicle - * @param physics - * @param objectComponent - * @returns {GameLib.D3.RaycastVehicle} - * @constructor - */ -GameLib.D3.RaycastVehicle.FromObject = function(physics, objectComponent) { - - var apiRaycastVehicle = GameLib.D3.API.RaycastVehicle.FromObject(objectComponent); - - return new GameLib.D3.RaycastVehicle( - physics, - apiRaycastVehicle - ); -}; diff --git a/src/game-lib-d3-render-target-cube.js b/src/game-lib-d3-render-target-cube.js deleted file mode 100644 index 9533edd..0000000 --- a/src/game-lib-d3-render-target-cube.js +++ /dev/null @@ -1,73 +0,0 @@ -/** - * Renders a scene with a camera - * @param graphics GameLib.GraphicsRuntime - * @param apiRenderTargetCube GameLib.D3.API.RenderTarget.Cube - * @constructor - */ -GameLib.D3.RenderTarget.Cube = function ( - graphics, - apiRenderTargetCube -) { - - this.graphics = graphics; - this.graphics.isNotThreeThrow(); - - if (GameLib.Utils.UndefinedOrNull(apiRenderTargetCube)) { - apiRenderTargetCube = { - renderTargetType : GameLib.D3.API.RenderTarget.TARGET_TYPE_CUBE - }; - } - - GameLib.D3.API.RenderTarget.Cube.call( - this, - apiRenderTargetCube - ); - - GameLib.D3.RenderTarget.call( - this, - this.graphics, - this - ); -}; - -GameLib.D3.RenderTarget.Cube.prototype = Object.create(GameLib.D3.RenderTarget.prototype); -GameLib.D3.RenderTarget.Cube.prototype.constructor = GameLib.D3.RenderTarget.Cube; - -/** - * Creates a Render Target instance - * @returns {*} - */ -GameLib.D3.RenderTarget.Cube.prototype.createInstance = function() { - - this.instance = new THREE.WebGLRenderTargetCube( - this.width, - this.height, - this.textureParameters - ); - - GameLib.D3.RenderTarget.prototype.createInstance.call(this); -}; - -/** - * updates instance - */ -GameLib.D3.RenderTarget.Cube.prototype.updateInstance = function(property) { - GameLib.D3.RenderTarget.prototype.updateInstance.call(this, property); -}; - -/** - * Render Target to API Render Target - * @returns {GameLib.D3.API.RenderTarget.Cube} - */ -GameLib.D3.RenderTarget.Cube.prototype.toApiObject = function() { - - var apiRenderTarget = GameLib.D3.RenderTarget.prototype.toApiObject.call( - this - ); - - var apiRenderTargetCube = new GameLib.D3.API.RenderTarget.Cube( - apiRenderTarget - ); - - return apiRenderTargetCube; -}; diff --git a/src/game-lib-d3-shader-fragment.js b/src/game-lib-d3-shader-fragment.js deleted file mode 100644 index 3631ff4..0000000 --- a/src/game-lib-d3-shader-fragment.js +++ /dev/null @@ -1,59 +0,0 @@ -/** - * GameLib.D3.Shader.Fragment - * @param graphics GameLib.GraphicsRuntime - * @param apiFragmentShader - * @constructor - */ -GameLib.D3.Shader.Fragment = function( - graphics, - apiFragmentShader -) { - - this.graphics = graphics; - this.graphics.isNotThreeThrow(); - - if (GameLib.Utils.UndefinedOrNull(apiFragmentShader)) { - apiFragmentShader = { - shaderType : GameLib.D3.API.Shader.SHADER_TYPE_FRAGMENT - }; - } - - GameLib.D3.API.Shader.Fragment.call( - this, - apiFragmentShader - ); - - GameLib.D3.Shader.call( - this, - this.graphics, - apiFragmentShader - ); - -}; - -GameLib.D3.Shader.Fragment.prototype = Object.create(GameLib.D3.Shader.prototype); -GameLib.D3.Shader.Fragment.prototype.constructor = GameLib.D3.Shader.Fragment; - -/** - * Creates a shader instance - * @returns {*} - */ -GameLib.D3.Shader.Fragment.prototype.createInstance = function() { - GameLib.D3.Shader.prototype.createInstance.call(this); -}; - -/** - * Updates the instance with the current state - */ -GameLib.D3.Shader.Fragment.prototype.updateInstance = function(property) { - GameLib.D3.Shader.prototype.updateInstance.call(this, property); -}; - -/** - * Converts a GameLib.D3.Shader to a GameLib.D3.API.Shader - * @returns {GameLib.D3.API.Shader} - */ -GameLib.D3.Shader.Fragment.prototype.toApiObject = function() { - var apiShader = GameLib.D3.Shader.prototype.toApiObject.call(this); - return apiShader; -}; diff --git a/src/game-lib-d3-shader-vertex.js b/src/game-lib-d3-shader-vertex.js deleted file mode 100644 index 042a76e..0000000 --- a/src/game-lib-d3-shader-vertex.js +++ /dev/null @@ -1,59 +0,0 @@ -/** - * GameLib.D3.Shader.Vertex - * @param graphics GameLib.GraphicsRuntime - * @param apiVertexShader - * @constructor - */ -GameLib.D3.Shader.Vertex = function( - graphics, - apiVertexShader -) { - - this.graphics = graphics; - this.graphics.isNotThreeThrow(); - - if (GameLib.Utils.UndefinedOrNull(apiVertexShader)) { - apiVertexShader = { - shaderType : GameLib.D3.API.Shader.SHADER_TYPE_VERTEX - }; - } - - GameLib.D3.API.Shader.Vertex.call( - this, - apiVertexShader - ); - - GameLib.D3.Shader.call( - this, - this.graphics, - apiVertexShader - ); - -}; - -GameLib.D3.Shader.Vertex.prototype = Object.create(GameLib.D3.Shader.prototype); -GameLib.D3.Shader.Vertex.prototype.constructor = GameLib.D3.Shader.Vertex; - -/** - * Creates a shader instance - * @returns {*} - */ -GameLib.D3.Shader.Vertex.prototype.createInstance = function() { - GameLib.D3.Shader.prototype.createInstance.call(this); -}; - -/** - * Updates the instance with the current state - */ -GameLib.D3.Shader.Vertex.prototype.updateInstance = function(property) { - GameLib.D3.Shader.prototype.updateInstance.call(this, property); -}; - -/** - * Converts a GameLib.D3.Shader to a GameLib.D3.API.Shader - * @returns {GameLib.D3.API.Shader} - */ -GameLib.D3.Shader.Vertex.prototype.toApiObject = function() { - var apiShader = GameLib.D3.Shader.prototype.toApiObject.call(this); - return apiShader; -}; diff --git a/src/game-lib-d3-shadow-directional.js b/src/game-lib-d3-shadow-directional.js deleted file mode 100644 index b75968a..0000000 --- a/src/game-lib-d3-shadow-directional.js +++ /dev/null @@ -1,90 +0,0 @@ -/** - * GameLib.D3.Shadow.Directional - * @param graphics GameLib.GraphicsRuntime - * @param apiDirectionalShadow - * @constructor - */ -GameLib.D3.Shadow.Directional = function( - graphics, - apiDirectionalShadow -) { - - this.graphics = graphics; - this.graphics.isNotThreeThrow(); - - if (GameLib.Utils.UndefinedOrNull(apiDirectionalShadow)) { - apiDirectionalShadow = { - shadowType : GameLib.D3.API.Shadow.SHADOW_TYPE_DIRECTIONAL - }; - } - - GameLib.D3.API.Shadow.Directional.call( - this, - apiDirectionalShadow - ); - - if (this.camera instanceof GameLib.D3.API.Camera.Orthographic) { - this.camera = new GameLib.D3.Camera.Orthographic( - this.graphics, - this.camera - ) - } - - GameLib.D3.Shadow.call( - this, - this.graphics, - this - ); - -}; - -GameLib.D3.Shadow.Directional.prototype = Object.create(GameLib.D3.Shadow.prototype); -GameLib.D3.Shadow.Directional.prototype.constructor = GameLib.D3.Shadow.Directional; - -/** - * Creates a shadow instance - * @returns {*} - */ -GameLib.D3.Shadow.Directional.prototype.createInstance = function() { - - this.instance = {}; - - GameLib.D3.Shadow.prototype.createInstance.call(this); -}; - -/** - * Updates the instance with the current state - */ -GameLib.D3.Shadow.Directional.prototype.updateInstance = function(property) { - - if (property === 'camera') { - - //console.warn('todo: updateInstance for directional shadow camera instance'); - - return; - } - - GameLib.D3.Shadow.prototype.updateInstance.call(this, property); -}; - -/** - * Converts a GameLib.D3.Shadow to a GameLib.D3.API.Shadow - * @returns {GameLib.D3.API.Shadow} - */ -GameLib.D3.Shadow.Directional.prototype.toApiObject = function() { - - var apiShadow = GameLib.D3.Shadow.prototype.toApiObject.call(this); - - var apiDirectionalShadow = new GameLib.D3.API.Shadow.Directional( - apiShadow - ); - - return apiDirectionalShadow; -}; - -GameLib.D3.Shadow.Directional.prototype.updateFromInstance = function() { - - - GameLib.D3.Shadow.prototype.updateFromInstance.call(this); - -}; \ No newline at end of file diff --git a/src/game-lib-d3-shadow-spot.js b/src/game-lib-d3-shadow-spot.js deleted file mode 100644 index fb735ac..0000000 --- a/src/game-lib-d3-shadow-spot.js +++ /dev/null @@ -1,83 +0,0 @@ -/** - * GameLib.D3.Shadow.Spot - * @param graphics GameLib.GraphicsRuntime - * @param apiSpotShadow - * @constructor - */ -GameLib.D3.Shadow.Spot = function( - graphics, - apiSpotShadow -) { - - this.graphics = graphics; - this.graphics.isNotThreeThrow(); - - if (GameLib.Utils.UndefinedOrNull(apiSpotShadow)) { - apiSpotShadow = { - shadowType : GameLib.D3.API.Shadow.SHADOW_TYPE_SPOT - }; - } - - GameLib.D3.API.Shadow.Spot.call( - this, - apiSpotShadow - ); - - if (this.camera instanceof GameLib.D3.API.Camera.Perspective) { - this.camera = new GameLib.D3.Camera.Perspective( - this.graphics, - this.camera - ) - } - - GameLib.D3.Shadow.call( - this, - this.graphics, - apiSpotShadow - ); - -}; - -GameLib.D3.Shadow.Spot.prototype = Object.create(GameLib.D3.Shadow.prototype); -GameLib.D3.Shadow.Spot.prototype.constructor = GameLib.D3.Shadow.Spot; - -/** - * Creates a shadow instance - * @returns {*} - */ -GameLib.D3.Shadow.Spot.prototype.createInstance = function() { - - this.instance = {}; - - GameLib.D3.Shadow.prototype.createInstance.call(this); -}; - -/** - * Updates the instance with the current state - */ -GameLib.D3.Shadow.Spot.prototype.updateInstance = function(property) { - - if (property === 'camera') { - - console.warn('todo: updateInstance for spot shadow camera instance'); - - return; - } - - GameLib.D3.Shadow.prototype.updateInstance.call(this, property); -}; - -/** - * Converts a GameLib.D3.Shadow to a GameLib.D3.API.Shadow - * @returns {GameLib.D3.API.Shadow} - */ -GameLib.D3.Shadow.Spot.prototype.toApiObject = function() { - - var apiShadow = GameLib.D3.Shadow.prototype.toApiObject.call(this); - - var apiSpotShadow = new GameLib.D3.API.Shadow.Spot( - apiShadow - ); - - return apiSpotShadow; -}; diff --git a/src/game-lib-d3-shape-0.js b/src/game-lib-d3-shape-0.js deleted file mode 100644 index 0e5db14..0000000 --- a/src/game-lib-d3-shape-0.js +++ /dev/null @@ -1,108 +0,0 @@ -/** - * Shape Superset - The apiShape properties get moved into the Shape object itself, and then the instance is created - * @param physics GameLib.PhysicsRuntime - * @param apiShape GameLib.D3.API.Shape - * @constructor - */ -GameLib.D3.Shape = function ( - physics, - apiShape -) { - this.physics = physics; - this.physics.isNotCannonThrow(); - - if (GameLib.Utils.UndefinedOrNull(apiShape)) { - apiShape = { - shapeType : GameLib.D3.API.Shape.SHAPE_TYPE_NONE - }; - } - - GameLib.D3.API.Shape.call( - this, - apiShape.id, - apiShape.name, - apiShape.shapeType, - apiShape.boundingSphereRadius, - apiShape.collisionResponse, - apiShape.frictionMaterial, - apiShape.parentMesh, - apiShape.parentEntity - ); - - var linkedObjects = { - frictionMaterial : GameLib.D3.FrictionMaterial, - parentMesh : GameLib.D3.Mesh - }; - - GameLib.Component.call( - this, - linkedObjects - ); -}; - -GameLib.D3.Shape.prototype = Object.create(GameLib.Component.prototype); -GameLib.D3.Shape.prototype.constructor = GameLib.D3.Shape; - - -/** - * Creates a shape instance or updates it - */ -GameLib.D3.Shape.prototype.createInstance = function() { - GameLib.Component.prototype.createInstance.call(this); -}; - -/** - * Updates the mesh instance - */ -GameLib.D3.Shape.prototype.updateInstance = function(property) { - throw new Error('Do not instantiate this class directly - use a child class instead'); - GameLib.Component.prototype.updateInstance.call(this, property); -}; - -/** - * Converts a GameLib.D3.Shape to a GameLib.D3.API.Shape - * @returns {GameLib.D3.API.Shape} - */ -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), - GameLib.Utils.IdOrNull(this.parentMesh), - GameLib.Utils.IdOrNull(this.parentEntity) - ); - - return apiShape; -}; - -/** - * Converts a standard object mesh to a GameLib.D3.Shape - * @param physics GameLib.PhysicsRuntime - * @param objectShape {Object} - * @constructor - */ -GameLib.D3.Shape.FromObject = function(physics, objectShape) { - 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 - } - ) -}; \ No newline at end of file diff --git a/src/game-lib-d3-shape-plane.js b/src/game-lib-d3-shape-plane.js deleted file mode 100644 index cf96d9a..0000000 --- a/src/game-lib-d3-shape-plane.js +++ /dev/null @@ -1,53 +0,0 @@ -/** - * Shape Superset - The apiShape properties get moved into the Shape object itself, and then the instance is created - * @param physics - * @param apiShape GameLib.D3.API.Shape - * @constructor - */ -GameLib.D3.Shape.Plane = function ( - physics, - apiShape -) { - this.physics = physics; - this.physics.isNotCannonThrow(); - - if (GameLib.Utils.UndefinedOrNull(apiShape)) { - apiShape = { - shapeType : GameLib.D3.API.Shape.SHAPE_TYPE_PLANE - }; - } - - GameLib.D3.Shape.call( - this, - this.physics, - apiShape - ); -}; - -GameLib.D3.Shape.Plane.prototype = Object.create(GameLib.D3.Shape.prototype); -GameLib.D3.Shape.Plane.prototype.constructor = GameLib.D3.Shape.Plane; - -/** - * - * @returns {GameLib.D3.Shape.Plane|*|SEA3D.Plane} - */ -GameLib.D3.Shape.Plane.prototype.createInstance = function() { - /** - * A plane is just a plane at z = 0, to rotate it put it inside a rigid body and rotate the body - */ - 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(physics, objectShape) { - - var apiShape = GameLib.D3.API.Shape.FromObject(objectShape); - - return new GameLib.D3.Shape.Plane( - physics, - apiShape - ); -}; \ No newline at end of file diff --git a/src/game-lib-d3-shape-sphere.js b/src/game-lib-d3-shape-sphere.js deleted file mode 100644 index a0fc9fa..0000000 --- a/src/game-lib-d3-shape-sphere.js +++ /dev/null @@ -1,71 +0,0 @@ -/** - * Shape Superset - The apiShape properties get moved into the Shape object itself, and then the instance is created - * @param physics - * @param apiShape GameLib.D3.API.Shape - * @param radius - * @constructor - */ -GameLib.D3.Shape.Sphere = function ( - physics, - apiShape, - radius -) { - this.physics = physics; - this.physics.isNotCannonThrow(); - - if (GameLib.Utils.UndefinedOrNull(apiShape)) { - apiShape = { - shapeType : GameLib.D3.API.Shape.SHAPE_TYPE_SPHERE - }; - } - - if (GameLib.Utils.UndefinedOrNull(radius)) { - radius = 1; - } - this.radius = radius; - - GameLib.D3.Shape.call( - this, - this.physics, - apiShape - ); -}; - -GameLib.D3.Shape.Sphere.prototype = Object.create(GameLib.D3.Shape.prototype); -GameLib.D3.Shape.Sphere.prototype.constructor = GameLib.D3.Shape.Sphere; - -/** - * - * @returns {GameLib.D3.Shape.Sphere|*|SEA3D.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 apiShape = GameLib.D3.Shape.prototype.toApiObject.call(this); - apiShape.radius = this.radius; - return apiShape; -}; - -GameLib.D3.Shape.Sphere.FromObject = function(physics, objectShape) { - - var apiShape = GameLib.D3.API.Shape.FromObject(objectShape); - - return new GameLib.D3.Shape.Sphere( - physics, - apiShape, - objectShape.radius - ); -}; \ No newline at end of file diff --git a/src/game-lib-d3-solver.js b/src/game-lib-d3-solver.js deleted file mode 100644 index e7e18b7..0000000 --- a/src/game-lib-d3-solver.js +++ /dev/null @@ -1,111 +0,0 @@ -/** - * Solver Runtime - * @param physics GameLib.GraphicsRuntime - * @param apiSolver GameLib.D3.API.Solver - * @constructor - */ -GameLib.D3.Solver = function ( - physics, - apiSolver -) { - - this.physics = physics; - this.physics.isNotCannonThrow(); - - if (GameLib.Utils.UndefinedOrNull(apiSolver)) { - apiSolver = {}; - } - - GameLib.D3.API.Solver.call( - this, - apiSolver.id, - apiSolver.name, - apiSolver.solverType, - apiSolver.iterations, - apiSolver.tolerance, - apiSolver.parentEntity - ); - - GameLib.Component.call(this); -}; - -GameLib.D3.Solver.prototype = Object.create(GameLib.Component.prototype); -GameLib.D3.Solver.prototype.constructor = GameLib.D3.Solver; - -/** - * - * @returns {*} - */ -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) { - this.instance = new CANNON.SplitSolver(); - } else { - throw new Error('unsupported solver type: ' + this.solverType); - } - - this.instance.tolerance = this.tolerance; - this.instance.iterations = this.iterations; - - GameLib.Component.prototype.createInstance.call(this); -}; - -/** - * - */ -GameLib.D3.Solver.prototype.updateInstance = function(property) { - - 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.API.Solver.SPLIT_SOLVER) { - if (!(this.instance instanceof CANNON.SplitSolver)) { - this.instance = new CANNON.SplitSolver(); - } - } - - this.instance.iterations = this.iterations; - this.instance.tolerance = this.tolerance; - - GameLib.Component.prototype.updateInstance.call(this, property); -}; - -/** - * GameLib.D3.Solver to GameLib.D3.API.Solver - * @returns {GameLib.D3.API.Solver} - */ -GameLib.D3.Solver.prototype.toApiObject = function() { - - var apiSolver = new GameLib.D3.API.Solver( - this.id, - this.name, - this.solverType, - this.iterations, - this.tolerance, - GameLib.Utils.IdOrNull(this.parentEntity) - ); - - return apiSolver; -}; - -/** - * GameLib.D3.Solver from Object Solver - * @param graphics - * @param objectComponent - * @returns {GameLib.D3.Solver} - * @constructor - */ -GameLib.D3.Solver.FromObject = function(graphics, objectComponent) { - - var apiSolver = GameLib.D3.API.Solver.FromObject(objectComponent); - - return new GameLib.D3.Solver( - graphics, - apiSolver - ); -}; diff --git a/src/game-lib-d3-texture-canvas.js b/src/game-lib-d3-texture-canvas.js deleted file mode 100644 index 82cfc79..0000000 --- a/src/game-lib-d3-texture-canvas.js +++ /dev/null @@ -1,96 +0,0 @@ -/** - * GameLib.D3.Texture.Canvas - * @param graphics - * @param apiTextureCanvas - * @constructor - */ -GameLib.D3.Texture.Canvas = function( - graphics, - apiTextureCanvas -) { - this.graphics = graphics; - this.graphics.isNotThreeThrow(); - - if (GameLib.Utils.UndefinedOrNull(apiTextureCanvas)) { - apiTextureCanvas = { - textureType : GameLib.D3.API.Texture.TEXTURE_TYPE_CANVAS - }; - } - - GameLib.D3.API.Texture.Canvas.call( - this, - apiTextureCanvas, - apiTextureCanvas.canvas - ); - - if (this.canvas instanceof GameLib.API.Canvas) { - this.canvas = new GameLib.Canvas( - this.graphics, - this.canvas - ); - } - - GameLib.D3.Texture.call( - this, - this.graphics, - this - ); - -}; - -GameLib.D3.Texture.Canvas.prototype = Object.create(GameLib.D3.Texture.prototype); -GameLib.D3.Texture.Canvas.prototype.constructor = GameLib.D3.Texture.Canvas; - -/** - * Creates an instance of our texture object - * @returns {*} - */ -GameLib.D3.Texture.Canvas.prototype.createInstance = function() { - - if ( - GameLib.Utils.UndefinedOrNull(this.canvas) || - GameLib.Utils.UndefinedOrNull(this.canvas.instance) - ) { - console.warn('canvas not ready at time of texture create instance'); - return; - } - - this.canvas.parentTexture = this; - - this.instance = new THREE.Texture( - this.canvas.instance - ); - - GameLib.D3.Texture.prototype.createInstance.call(this); -}; - -/** - * Updates the instance with the current state - */ -GameLib.D3.Texture.Canvas.prototype.updateInstance = function(property) { - - if (property === 'canvas') { - - this.createInstance(); - - return; - } - - GameLib.D3.Texture.prototype.updateInstance.call(this, property); -}; - -/** - * Converts a GameLib.D3.Texture.Canvas to a GameLib.D3.API.Texture.Canvas - * @returns {GameLib.D3.API.Texture.Canvas} - */ -GameLib.D3.Texture.Canvas.prototype.toApiObject = function() { - - var apiTexture = GameLib.D3.Texture.prototype.toApiObject.call(this); - - var apiTextureCanvas = new GameLib.D3.API.Texture.Canvas( - apiTexture, - GameLib.Utils.IdOrNull(this.canvas) - ); - - return apiTextureCanvas; -}; diff --git a/src/game-lib-graphics-runtime-a.js b/src/game-lib-graphics-runtime-a.js deleted file mode 100644 index ce8d5d1..0000000 --- a/src/game-lib-graphics-runtime-a.js +++ /dev/null @@ -1,71 +0,0 @@ -/** - * Graphics - * @constructor - * @param apiGraphics - */ -GameLib.GraphicsRuntime = function( - apiGraphics -) { - - if (GameLib.Utils.UndefinedOrNull(apiGraphics)) { - apiGraphics = { - graphicsType : GameLib.API.GraphicsRuntime.GRAPHICS_TYPE_NONE - }; - } - - GameLib.API.GraphicsRuntime.call( - this, - apiGraphics.id, - apiGraphics.name, - apiGraphics.graphicsType, - apiGraphics.parentEntity - ); - - GameLib.Component.call(this); -}; - -GameLib.GraphicsRuntime.prototype = Object.create(GameLib.Component.prototype); -GameLib.GraphicsRuntime.prototype.constructor = GameLib.GraphicsRuntime; - -GameLib.GraphicsRuntime.prototype.createInstance = function() { - console.log(this.graphicsType + ' graphics runtime created'); - GameLib.Component.prototype.createInstance.call(this); -}; - -GameLib.GraphicsRuntime.prototype.updateInstance = function(property) { - - if (property === 'graphicsType') { - var componentType = GameLib.API.Renderer.GetComponentType(this.graphicsType); - - this.replace(componentType); - - return; - } - - GameLib.Component.prototype.updateInstance.call(this, property); -}; - -GameLib.GraphicsRuntime.prototype.toApiObject = function(property) { - - return new GameLib.API.GraphicsRuntime( - this.id, - this.name, - this.graphicsType, - GameLib.Utils.IdOrNull(this.parentEntity) - ); - -}; - -/** - * Logs a warning and throws an error if not cannon - */ -GameLib.GraphicsRuntime.prototype.isNotThreeThrow = function() { - if (this.instance !== THREE) { - console.error('Only THREE supported'); - throw new Error('Only THREE supported'); - } -}; - -GameLib.GraphicsRuntime.prototype.isThree = function() { - return (this.instance === THREE); -}; \ No newline at end of file diff --git a/src/game-lib-graphics-runtime-three.js b/src/game-lib-graphics-runtime-three.js deleted file mode 100644 index dd21097..0000000 --- a/src/game-lib-graphics-runtime-three.js +++ /dev/null @@ -1,63 +0,0 @@ -/** - * GameLib.GraphicsRuntime.Three - * @param apiGraphicsRuntimeThree - * @constructor - */ -GameLib.GraphicsRuntime.Three = function ( - apiGraphicsRuntimeThree -) { - - if (GameLib.Utils.UndefinedOrNull(apiGraphicsRuntimeThree)) { - apiGraphicsRuntimeThree = { - graphicsType : GameLib.API.GraphicsRuntime.GRAPHICS_TYPE_THREE_JS - }; - } - - GameLib.API.GraphicsRuntime.Three.call( - this, - apiGraphicsRuntimeThree - ); - - GameLib.GraphicsRuntime.call( - this, - this - ); - -}; - -GameLib.GraphicsRuntime.Three.prototype = Object.create(GameLib.GraphicsRuntime.prototype); -GameLib.GraphicsRuntime.Three.prototype.constructor = GameLib.GraphicsRuntime.Three; - -/** - * Create GameLib.GraphicsRuntime.Three Instance - * @returns {*} - */ -GameLib.GraphicsRuntime.Three.prototype.createInstance = function() { - - this.instance = THREE; - - GameLib.GraphicsRuntime.prototype.createInstance.call(this); -}; - -/** - * Update GraphicsRuntime.Three Instance - */ -GameLib.GraphicsRuntime.Three.prototype.updateInstance = function(property) { - - GameLib.GraphicsRuntime.prototype.updateInstance.call(this, property); -}; - -/** - * - * @returns {GameLib.API.GraphicsRuntime.Three} - */ -GameLib.GraphicsRuntime.Three.prototype.toApiObject = function() { - - var apiGraphicsRuntime = GameLib.GraphicsRuntime.prototype.toApiObject.call(this); - - var apiGraphicsRuntimeThree = new GameLib.API.GraphicsRuntime.Three( - apiGraphicsRuntime - ); - - return apiGraphicsRuntimeThree; -}; diff --git a/src/game-lib-mouse.js b/src/game-lib-mouse.js deleted file mode 100644 index 7406df4..0000000 --- a/src/game-lib-mouse.js +++ /dev/null @@ -1,67 +0,0 @@ -/** - * Runtime Mouse - * @param apiMouse - * @returns {GameLib.Mouse} - * @constructor - */ -GameLib.Mouse = function (apiMouse) { - - if (GameLib.Utils.UndefinedOrNull(apiMouse)){ - apiMouse = {}; - } - - GameLib.API.Mouse.call( - this, - apiMouse.id, - apiMouse.name, - apiMouse.parentEntity, - apiMouse.x, - apiMouse.y - ); - - GameLib.Component.call(this); -}; - -GameLib.Mouse.prototype = Object.create(GameLib.Component.prototype); -GameLib.Mouse.prototype.constructor = GameLib.Mouse; - -/** - * createInstance - */ -GameLib.Mouse.prototype.createInstance = function() { - this.instance = {}; - GameLib.Component.prototype.createInstance.call(this); -}; - -/** - * updateInstance - * @param property - */ -GameLib.Mouse.prototype.updateInstance = function(property) { - - if ( - property === 'x' || - property === 'y' - ) { - this.instance.x = this.x; - this.instance.y = this.y; - return; - } - - GameLib.Component.prototype.updateInstance.call(this, property); - -}; - -/** - * Converts GameLib.Mouse vector to GameLib.API.Mouse - * @returns {GameLib.API.Mouse} - */ -GameLib.Mouse.prototype.toApiObject = function() { - return new GameLib.API.Mouse( - this.id, - this.name, - GameLib.Utils.IdOrNull(this.parentEntity), - this.x, - this.y - ); -}; diff --git a/src/game-lib-plane.js b/src/game-lib-plane.js deleted file mode 100644 index 212fc2e..0000000 --- a/src/game-lib-plane.js +++ /dev/null @@ -1,101 +0,0 @@ -/** - * Creates a Plane object - * @param graphics GameLib.GraphicsRuntime - * @param apiPlane GameLib.API.Plane - * @constructor - */ -GameLib.Plane = function( - graphics, - apiPlane -) { - - this.graphics = graphics; - this.graphics.isNotThreeThrow(); - - if (GameLib.Utils.UndefinedOrNull(apiPlane)) { - apiPlane = {}; - } - - GameLib.API.Plane.call( - this, - apiPlane.id, - apiPlane.name, - apiPlane.normal, - apiPlane.constant, - apiPlane.parentEntity - ); - - this.normal = new GameLib.Vector3( - this.graphics, - this.normal, - this - ); - - GameLib.Component.call(this); -}; - -GameLib.Plane.prototype = Object.create(GameLib.Component.prototype); -GameLib.Plane.prototype.constructor = GameLib.Plane; - -GameLib.Plane.prototype.createInstance = function() { - - this.instance = new THREE.Plane( - this.normal.instance, - this.constant - ); - - GameLib.Component.prototype.createInstance.call(this); -}; - -/** - * Updates the instance with the current state - */ -GameLib.Plane.prototype.updateInstance = function(property) { - - if (property === 'normal') { - - this.normal.normalize(); - - this.instance.normal.x = this.normal.x; - this.instance.normal.y = this.normal.y; - this.instance.normal.z = this.normal.z; - } - - if (property === 'constant') { - this.instance.constant = this.constant; - } - - GameLib.D3.Texture.prototype.updateInstance.call(this, property); - -}; - -/** - * Converts a GameLib.Plane to a new GameLib.API.Plane - * @returns {GameLib.API.Plane} - */ -GameLib.Plane.prototype.toApiObject = function() { - - return new GameLib.API.Plane( - this.id, - this.name, - this.normal.toApiObject(), - this.constant, - GameLib.Utils.IdOrNull(this.parentEntity) - ); - -}; - -/** - * Converts from an Object Plane to a GameLib.Plane - * @param graphics GameLib.GraphicsRuntime - * @param objectPlane Object - * @returns {GameLib.Plane} - * @constructor - */ -GameLib.Plane.FromObject = function(graphics, objectPlane) { - var apiPlane = GameLib.API.Plane.FromObject(objectPlane); - return new GameLib.Plane( - graphics, - apiPlane - ); -}; diff --git a/src/game-lib-renderer-d2.js b/src/game-lib-renderer-d2.js deleted file mode 100644 index 955b3fe..0000000 --- a/src/game-lib-renderer-d2.js +++ /dev/null @@ -1,94 +0,0 @@ -/** - * GameLib.Renderer.D2 - * @param graphics - * @param apiRendererD2 GameLib.API.Renderer.D2 - * @constructor - */ -GameLib.Renderer.D2 = function ( - graphics, - apiRendererD2 -) { - - if (GameLib.Utils.UndefinedOrNull(graphics)) { - graphics = GameLib.GraphicsRuntime(null, null, GameLib.GraphicsRuntime.GRAPHICS_RUNTIME_IMPACT); - } - this.graphics = graphics; - - if (GameLib.Utils.UndefinedOrNull(apiRendererD2)) { - apiRendererD2 = { - rendererType : GameLib.API.Renderer.RENDERER_TYPE_2D - }; - } - - GameLib.API.Renderer.D2.call( - this, - apiRendererD2 - ); - - GameLib.Renderer.call( - this, - this.graphics, - this - ); - -}; - -GameLib.Renderer.D2.prototype = Object.create(GameLib.Renderer.prototype); -GameLib.Renderer.D2.prototype.constructor = GameLib.Renderer.D2; - -/** - * Create GameLib.Renderer.D2 Instance - * @returns {*} - */ -GameLib.Renderer.D2.prototype.createInstance = function() { - - if ( - GameLib.Utils.UndefinedOrNull(this.canvas) || - GameLib.Utils.UndefinedOrNull(this.canvas.instance) - ) { - console.warn('no canvas instance'); - return; - } - - this.instance = true; - - GameLib.Renderer.prototype.createInstance.call(this); -}; - -/** - * Update Renderer.D2 Instance - */ -GameLib.Renderer.D2.prototype.updateInstance = function(property) { - - if (!property) { - throw new Error('no renderer property'); - } - - if (!this.instance) { - throw new Error('no renderer instance'); - } - - GameLib.Renderer.prototype.updateInstance.call(this, property); -}; - -/** - * - * @returns {GameLib.API.Renderer.D2} - */ -GameLib.Renderer.D2.prototype.toApiObject = function() { - - var apiRenderer = GameLib.Renderer.prototype.toApiObject.call(this); - - var apiRendererD2 = new GameLib.API.Renderer.D2( - apiRenderer - ); - - return apiRendererD2; -}; - -/** - * set size - */ -GameLib.Renderer.D2.prototype.setSize = function(width, height) { - GameLib.Renderer.prototype.setSize.call(this); -}; diff --git a/src/game-lib-server.js b/src/game-lib-server.js deleted file mode 100644 index 57cdd0e..0000000 --- a/src/game-lib-server.js +++ /dev/null @@ -1,87 +0,0 @@ -/** - * Creates a Server object - * @param apiServer GameLib.API.Server - * @constructor - */ -GameLib.Server = function( - apiServer -) { - - if (GameLib.Utils.UndefinedOrNull(apiServer)) { - apiServer = {}; - } - - GameLib.API.Server.call( - this, - apiServer.id, - apiServer.name, - apiServer.protocol, - apiServer.ip, - apiServer.port, - apiServer.protocols, - apiServer.parentEntity - ); - - this.connected = false; - - GameLib.Component.call(this); -}; - -GameLib.Server.prototype = Object.create(GameLib.Component.prototype); -GameLib.Server.prototype.constructor = GameLib.Server; - -GameLib.Server.prototype.createInstance = function() { - - this.instance = true; - - GameLib.Component.prototype.createInstance.call(this); -}; - -/** - * Updates the instance with the current state - */ -GameLib.Server.prototype.updateInstance = function(property) { - if (property === 'protocol') { - console.log('todo: server protocol update'); - } - if (property === 'ip') { - console.log('todo: server ip update'); - } - if (property === 'port') { - console.log('todo: server port update'); - } - if (property === 'protocols') { - console.log('todo: server protocols update'); - } - - GameLib.D3.Texture.prototype.updateInstance.call(this, property); -}; - -/** - * Converts a GameLib.Server to a new GameLib.API.Server - * @returns {GameLib.API.Server} - */ -GameLib.Server.prototype.toApiObject = function() { - - return new GameLib.API.Server( - this.id, - this.name, - this.protocol, - this.ip, - this.port, - this.protocols, - GameLib.Utils.IdOrNull(this.parentEntity) - ); - -}; - -/** - * Converts from an Object Server to a GameLib.Server - * @param objectServer Object - * @returns {GameLib.Server} - * @constructor - */ -GameLib.Server.FromObject = function(objectServer) { - var apiServer = GameLib.API.Server.FromObject(objectServer); - return new GameLib.Server(apiServer); -}; diff --git a/src/game-lib-socket-0.js b/src/game-lib-socket-0.js deleted file mode 100644 index d14df5c..0000000 --- a/src/game-lib-socket-0.js +++ /dev/null @@ -1,115 +0,0 @@ -/** - * Creates a Socket object - * @param socket GameLib.Socket - * @param apiSocket GameLib.API.Socket - * @constructor - */ -GameLib.Socket = function( - socket, - apiSocket -) { - - this.socket = socket; - this.socket.isNotWebSocketThrow(); - - if (GameLib.Utils.UndefinedOrNull(apiSocket)) { - apiSocket = {}; - } - - GameLib.API.Socket.call( - this, - apiSocket.id, - apiSocket.name, - apiSocket.socketType, - apiSocket.roomId, - apiSocket.peerId, - apiSocket.server, - apiSocket.parentEntity - ); - - if (this.server instanceof GameLib.API.Server) { - this.server = new GameLib.Server(this.server); - } - - this.connected = false; - - var linkedObjects = { - server : GameLib.Server - }; - - if (this.socketType === GameLib.API.Socket.TYPE_CAST) { - linkedObjects.source = GameLib.Component; - } - - if (this.socketType === GameLib.API.Socket.TYPE_RECEIVE) { - linkedObjects.destination = GameLib.Component; - } - - GameLib.Component.call( - this, - linkedObjects - ); - -}; - -GameLib.Socket.prototype = Object.create(GameLib.Component.prototype); -GameLib.Socket.prototype.constructor = GameLib.Socket; - -GameLib.Socket.prototype.createInstance = function() { - - this.instance = true; - - GameLib.Component.prototype.createInstance.call(this); -}; - -/** - * Updates the instance with the current state - */ -GameLib.Socket.prototype.updateInstance = function(property) { - if (property === 'socketType') { - console.log('todo: implement socket socketType update'); - } - if (property === 'roomId') { - console.log('todo: implement socket roomId update'); - } - if (property === 'peerId') { - console.log('todo: implement socket peerId update'); - } - if (property === 'server') { - console.log('todo: implement socket server update'); - } - GameLib.D3.Texture.prototype.updateInstance.call(this, property); -}; - -/** - * Converts a GameLib.Socket to a new GameLib.API.Socket - * @returns {GameLib.API.Socket} - */ -GameLib.Socket.prototype.toApiObject = function() { - - return new GameLib.API.Socket( - this.id, - this.name, - this.socketType, - this.roomId, - this.peerId, - GameLib.Utils.IdOrNull(this.server), - GameLib.Utils.IdOrNull(this.parentEntity) - ); - -}; - -/** - * Converts from an Object Socket to a GameLib.Socket - * @param sockets GameLib.SocketsRuntime - * @param objectSocket Object - * @returns {GameLib.Socket} - * @constructor - */ -GameLib.Socket.FromObject = function(sockets, objectSocket) { - var apiSocket = GameLib.API.Socket.FromObject(objectSocket); - return new GameLib.Socket( - sockets, - apiSocket - ); -}; diff --git a/src/game-lib-socket-cast.js b/src/game-lib-socket-cast.js deleted file mode 100644 index 43f6aa5..0000000 --- a/src/game-lib-socket-cast.js +++ /dev/null @@ -1,119 +0,0 @@ -/** - * Creates a Cast object - * @param socket GameLib.Socket - * @param apiSocketCast - * @constructor - */ -GameLib.Socket.Cast = function( - socket, - apiSocketCast -) { - - this.socket = socket; - this.socket.isNotWebSocketThrow(); - - if (GameLib.Utils.UndefinedOrNull(apiSocketCast)) { - apiSocketCast = { - socketType : GameLib.API.Socket.TYPE_CAST - }; - } - - GameLib.API.Socket.Cast.call( - this, - apiSocketCast, - apiSocketCast.castType, - apiSocketCast.source, - apiSocketCast.sourceProperties - ); - - GameLib.Socket.call( - this, - socket, - apiSocketCast - ); -}; - -GameLib.Socket.Cast.prototype = Object.create(GameLib.Socket.prototype); -GameLib.Socket.Cast.prototype.constructor = GameLib.Socket.Cast; - -GameLib.Socket.Cast.prototype.createInstance = function() { - - this.instance = true; - - GameLib.Socket.prototype.createInstance.call(this); -}; - -/** - * Updates the instance with the current state - */ -GameLib.Socket.Cast.prototype.updateInstance = function(property) { - - GameLib.Socket.prototype.updateInstance.call( - this, - property - ); - - if (property === 'castType') { - console.log('todo: implement socket.receive.castType update'); - } - - if (property === 'source') { - if (this.source !== null) { - this.sourceProperties = GameLib.Utils.ObjectPropertiesAsBoolean(this.source); - } else { - this.sourceProperties = {}; - } - - GameLib.Event.Emit( - GameLib.Event.CAST_SOURCE_CHANGED, - { - component:this - } - ) - } - - if (property === 'sourceProperties') { - console.log('todo: implement socket.receive.sourceProperties update'); - } - -}; - -/** - * Converts a GameLib.Socket.Cast to a new GameLib.API.Socket.Cast - * @returns {GameLib.API.Socket.Cast} - */ -GameLib.Socket.Cast.prototype.toApiObject = function() { - - var apiSocket = new GameLib.API.Socket( - this.id, - this.name, - this.socketType, - this.roomId, - this.peerId, - GameLib.Utils.IdOrNull(this.server), - GameLib.Utils.IdOrNull(this.parentEntity) - ); - - return new GameLib.API.Socket.Cast( - apiSocket, - this.castType, - GameLib.Utils.IdOrNull(this.source), - this.sourceProperties - ); - -}; - -/** - * Converts from an Object Cast to a GameLib.Socket.Cast - * @param sockets GameLib.SocketsRuntime - * @param objectCast Object - * @returns {GameLib.Socket.Cast} - * @constructor - */ -GameLib.Socket.Cast.FromObject = function(sockets, objectCast) { - var apiCast = GameLib.API.Socket.Cast.FromObject(objectCast); - return new GameLib.Socket.Cast( - sockets, - apiCast - ); -}; diff --git a/src/game-lib-socket-receive.js b/src/game-lib-socket-receive.js deleted file mode 100644 index c0fc5a9..0000000 --- a/src/game-lib-socket-receive.js +++ /dev/null @@ -1,123 +0,0 @@ -/** - * Creates a Receive object - * @param socket GameLib.Socket - * @param apiSocketReceive GameLib.API.Socket.Receive - * @constructor - */ -GameLib.Socket.Receive = function( - socket, - apiSocketReceive -) { - - this.socket = socket; - this.socket.isNotWebSocketThrow(); - - if (GameLib.Utils.UndefinedOrNull(apiSocketReceive)) { - apiSocketReceive = { - socketType : GameLib.API.Socket.TYPE_RECEIVE - }; - } - - GameLib.API.Socket.Receive.call( - this, - apiSocketReceive, - apiSocketReceive.receiveType, - apiSocketReceive.destination, - apiSocketReceive.destinationProperties - ); - - GameLib.Socket.call( - this, - socket, - apiSocketReceive - ); - -}; - -GameLib.Socket.Receive.prototype = Object.create(GameLib.Socket.prototype); -GameLib.Socket.Receive.prototype.constructor = GameLib.Socket.Receive; - -GameLib.Socket.Receive.prototype.createInstance = function() { - - this.instance = true; - - GameLib.Socket.prototype.createInstance.call(this); -}; - -/** - * Updates the instance with the current state - */ -GameLib.Socket.Receive.prototype.updateInstance = function(property) { - - GameLib.Socket.prototype.updateInstance.call( - this, - property - ); - - if (property === 'receiveType') { - console.log('todo: implement socket.receive.receiveType update'); - } - - if (property === 'destination') { - - if (this.destination !== null) { - this.destinationProperties = GameLib.Utils.ObjectPropertiesAsBoolean(this.destination); - } else { - this.destinationProperties = {}; - } - - GameLib.Event.Emit( - GameLib.Event.RECEIVE_DESTINATION_CHANGED, - { - component:this - } - ) - } - - if (property === 'destinationProperties') { - console.log('todo: implement socket.receive.destinationProperties update'); - } -}; - -/** - * Converts a GameLib.Socket.Receive to a new GameLib.API.Socket.Receive - * @returns {GameLib.API.Socket.Receive} - */ -GameLib.Socket.Receive.prototype.toApiObject = function() { - - var apiSocket = new GameLib.API.Socket( - this.id, - this.name, - this.socketType, - this.roomId, - this.peerId, - GameLib.Utils.IdOrNull(this.server), - GameLib.Utils.IdOrNull(this.parentEntity) - ); - - return new GameLib.API.Socket.Receive( - apiSocket, - this.receiveType, - this.destination, - this.destinationProperties - ); - -}; - -/** - * Converts from an Object Receive to a GameLib.Socket.Receive - * @param sockets GameLib.SocketsRuntime - * @param objectReceive Object - * @returns {GameLib.Socket.Receive} - * @constructor - */ -GameLib.Socket.Receive.FromObject = function(sockets, objectReceive) { - - var apiSocketReceive = GameLib.API.Socket.Receive.FromObject(objectReceive); - - return new GameLib.Socket.Receive( - sockets, - apiSocketReceive - ); - -}; diff --git a/src/game-lib-stats.js b/src/game-lib-stats.js deleted file mode 100644 index dc0dc2b..0000000 --- a/src/game-lib-stats.js +++ /dev/null @@ -1,103 +0,0 @@ -/** - * 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 = {}; - } - - 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(); -}; diff --git a/src/game-lib-system-0.js b/src/game-lib-system-0.js deleted file mode 100644 index 70983ef..0000000 --- a/src/game-lib-system-0.js +++ /dev/null @@ -1,104 +0,0 @@ -/** - * System takes care of updating all the entities (based on their component data) - * @param apiSystem GameLib.API.System - * @constructor - */ -GameLib.System = function( - apiSystem -) { - - if (GameLib.Utils.UndefinedOrNull(apiSystem)) { - apiSystem = {}; - } - - GameLib.API.System.call( - this, - apiSystem.id, - apiSystem.name, - apiSystem.systemType, - apiSystem.parentEntity - ); - - this.started = false; - - this.paused = false; - - var linkedObjects = {}; - - if (apiSystem.systemType === GameLib.System.SYSTEM_TYPE_INPUT) { - 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) { - linkedObjects.audioComponents = [GameLib.D3.Audio]; - } - - GameLib.Component.call( - this, - linkedObjects - ); - -}; - -GameLib.System.prototype = Object.create(GameLib.Component.prototype); -GameLib.System.prototype.constructor = GameLib.System; - -GameLib.System.SYSTEM_TYPE_NONE = 0x0; -GameLib.System.SYSTEM_TYPE_RENDER = 0x1; -GameLib.System.SYSTEM_TYPE_ANIMATION = 0x2; -GameLib.System.SYSTEM_TYPE_INPUT = 0x4; -GameLib.System.SYSTEM_TYPE_STORAGE = 0x8; -GameLib.System.SYSTEM_TYPE_GUI = 0x10; -GameLib.System.SYSTEM_TYPE_PHYSICS = 0x20; -GameLib.System.SYSTEM_TYPE_LINKING = 0x40; -GameLib.System.SYSTEM_TYPE_CUSTOM = 0x80; -GameLib.System.SYSTEM_TYPE_VISUALIZATION = 0x100; -GameLib.System.SYSTEM_TYPE_PARTICLE = 0x200; -GameLib.System.SYSTEM_TYPE_AUDIO = 0x400; -GameLib.System.SYSTEM_TYPE_SOCKET = 0x800; -GameLib.System.SYSTEM_TYPE_ALL = 0xFFFF; - -GameLib.System.prototype.createInstance = function() { - this.instance = true; - GameLib.Component.prototype.createInstance.call(this); -}; - -/** - * @callback - * @override - */ -GameLib.System.prototype.start = function() { - this.started = true; -// console.log('starting ' + this.name); -}; - -/** - * @callback - * @override - */ -GameLib.System.prototype.stop = function() { - this.started = false; -// console.log('stopping ' + this.name); -}; - -/** - * Converts runtime vector to API Vector - * @returns {GameLib.API.System} - */ -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(); -}; \ No newline at end of file diff --git a/src/game-lib-z.js b/src/game-lib-z.js deleted file mode 100644 index 8974ace..0000000 --- a/src/game-lib-z.js +++ /dev/null @@ -1,10 +0,0 @@ - -GameLib.EntityManager.Instance = new GameLib.EntityManager(); - -if (typeof window !== 'undefined') { - window.GameLib = GameLib; -} - -if (typeof module !== 'undefined') { - module.exports = GameLib; -} \ No newline at end of file diff --git a/src/r3-a-0.js b/src/r3-a-0.js new file mode 100644 index 0000000..33c0616 --- /dev/null +++ b/src/r3-a-0.js @@ -0,0 +1,59 @@ +/** + * R3 Namespace + */ +if (typeof R3 === 'undefined') { + function R3() {} +} + +/** + * R3.D3 Namespace + */ +if (typeof R3.D3 === 'undefined') { + R3.D3 = function(){}; +} + +/** + * R3.D3.API Namespace + * @constructor + */ +if (typeof R3.D3.API === 'undefined') { + R3.D3.API = function(){}; +} + +/** + * R3.API Namespace + */ +if (typeof R3.API === 'undefined') { + R3.API = function(){}; +} + +/** + * R3.D3.Runtime Namespace + * @constructor + */ +if (typeof R3.D3.Runtime === 'undefined') { + R3.D3.Runtime = function(){}; +} + +// if (typeof Q === 'undefined') { +// +// if (typeof require === 'undefined') { +// console.warn('You need the Q promise library for the R3.D3'); +// throw new Error('You need the Q promise library for the R3.D3'); +// } +// +// var Q = require('q'); +// } +// +// if (typeof _ === 'undefined') { +// +// if (typeof require === 'undefined') { +// console.warn('You need the lodash library for the R3.D3'); +// throw new Error('You need the lodash library for the R3.D3'); +// } +// +// var _ = require('lodash'); +// } + +// This gets injected by gulp +console.log("Loading R3 compiled at: " + __DATE__); diff --git a/src/game-lib-a-1-event.js b/src/r3-a-1-event.js similarity index 53% rename from src/game-lib-a-1-event.js rename to src/r3-a-1-event.js index 8f810a3..808c064 100644 --- a/src/game-lib-a-1-event.js +++ b/src/r3-a-1-event.js @@ -2,137 +2,137 @@ * Event Core * @constructor */ -GameLib.Event = function() { +R3.Event = function() { }; /** * Some nice Events handling * @type {{}} */ -GameLib.Event.Subscriptions = {}; -GameLib.Event.OnceSubscriptions = {}; +R3.Event.Subscriptions = {}; +R3.Event.OnceSubscriptions = {}; /** * Events we can subscribe to and publish */ -GameLib.Event.WINDOW_RESIZE = 0x1; -GameLib.Event.PARENT_SCENE_CHANGE = 0x2; -GameLib.Event.EXCLUDE_FROM_ENVIRONMENT = 0x3; -GameLib.Event.INSTANCE_CLONED = 0x4; -GameLib.Event.LOAD_IMAGE = 0x5; -GameLib.Event.NEW_ENTITY = 0x6; -GameLib.Event.MATERIAL_TYPE_CHANGED = 0x7; -GameLib.Event.SAVE_COMPONENT = 0x8; -GameLib.Event.SAVE_COMPONENT_ERROR = 0x9; -GameLib.Event.COMPONENT_SAVED = 0xa; -GameLib.Event.LOAD_COMPONENT = 0xb; -GameLib.Event.LOAD_COMPONENT_ERROR = 0xc; -GameLib.Event.LOGGED_IN = 0xd; -GameLib.Event.COMPONENT_CREATED = 0xe; -GameLib.Event.COMPONENT_CLONED = 0xf; -GameLib.Event.TEXTURE_ANIMATED_CHANGE = 0x10; -GameLib.Event.ANIMATE_TEXTURE_INSTANCE = 0x11; -GameLib.Event.REMOVE_PARTICLE_ENGINE = 0x12; -GameLib.Event.GAME_PAUSE = 0x13; -GameLib.Event.SHADER_UPDATE = 0x14; -GameLib.Event.PLAY_AUDIO = 0x15; -GameLib.Event.MATERIAL_INSTANCE_UPDATED = 0x16; -GameLib.Event.PAUSE_AUDIO = 0x17; -GameLib.Event.MESH_INSTANCE_UPDATED = 0x18; -GameLib.Event.STOP_AUDIO = 0x19; -GameLib.Event.LIGHT_INSTANCE_UPDATED = 0x1a; -GameLib.Event.DELETE_COMPONENT = 0x1b; -GameLib.Event.COMPONENT_DOWNLOAD_COMPLETE = 0x1c; -GameLib.Event.COMPONENTS_LINKED = 0x1d; -GameLib.Event.UNRESOLVED_DEPENDENCIES_UPDATE = 0x1e; -GameLib.Event.REGISTER_UPDATE = 0x1f; -GameLib.Event.BUILD_GUI = 0x20; -GameLib.Event.REMOVE_MESH = 0x21; -GameLib.Event.MESH_SELECTED = 0x22; -GameLib.Event.MESH_DESELECTED = 0x23; -GameLib.Event.COMPONENT_REGISTER = 0x24; -GameLib.Event.IMAGE_NOT_FOUND = 0x25; -GameLib.Event.BLENDER_DATA_RECEIVED = 0x26; -GameLib.Event.IMAGE_UPLOAD_COMPLETE = 0x27; -GameLib.Event.REMOVE_COMPONENT = 0x28; -GameLib.Event.KEY_DOWN = 0x29; -GameLib.Event.KEY_UP = 0x2a; -GameLib.Event.RENDER = 0x2b; -GameLib.Event.EVENT_LIST = 0x2c; -GameLib.Event.COMPILE_SUCCESS = 0x2d; -GameLib.Event.COMPILE_FAILED = 0x2e; -GameLib.Event.TEXTURE_INSTANCE_UPDATED = 0x2f; -GameLib.Event.EVENT_ID_UPDATE = 0x30; -GameLib.Event.MATERIAL_TEXTURES_UPDATED = 0x31; -GameLib.Event.DELETE_COMPONENT_ERROR = 0x32; -GameLib.Event.COMPONENT_DELETED = 0x33; -GameLib.Event.COMPONENT_TYPES_FETCHED = 0x34; -GameLib.Event.AUDIO_ENDED = 0x35; -GameLib.Event.COMPONENT_LINKED = 0x36; -GameLib.Event.DONE_SAVING = 0x37; -GameLib.Event.BEFORE_RENDER = 0x38; -GameLib.Event.AFTER_RENDER = 0x39; -GameLib.Event.ARRAY_ITEM_ADDED = 0x3a; -GameLib.Event.INSTANCE_CREATED = 0x3b; -GameLib.Event.VISUALIZE = 0x3c; -GameLib.Event.STOP_VISUALIZE = 0x3d; -GameLib.Event.FETCH_COMPONENT_TYPES = 0x3e; -GameLib.Event.FETCH_COMPONENTS = 0x3f; -GameLib.Event.GET_API_URL = 0x40; -GameLib.Event.GET_RUNTIME = 0x41; -GameLib.Event.PARENT_WORLD_CHANGE = 0x42; -GameLib.Event.ANIMATE = 0x43; -GameLib.Event.ANIMATION_COMPILE_SUCCESS = 0x44; -GameLib.Event.ANIMATION_COMPILE_FAILED = 0x45; -GameLib.Event.SAVING = 0x46; -GameLib.Event.GAME_OVER = 0x47; -GameLib.Event.GAME_START = 0x48; -GameLib.Event.TOUCH_START = 0x49; -GameLib.Event.TOUCH_END = 0x4a; -GameLib.Event.TOUCH_MOVE = 0x4b; -GameLib.Event.TOUCH_CANCEL = 0x4c; -GameLib.Event.GET_REMOTE_API_URL = 0x4d; -GameLib.Event.COMPONENT_TYPES_UPDATE = 0x4e; -GameLib.Event.DELAYED_INSTANCE_ENCOUNTERED = 0x4f; -GameLib.Event.CAST_SOURCE_CHANGED = 0x50; -GameLib.Event.RESOLVE_DEPENDENCIES = 0x51; -GameLib.Event.NAME_UPDATE = 0x52; -GameLib.Event.CANVAS_CHANGE = 0x53; -GameLib.Event.AFTER_WINDOW_RESIZE = 0x54; -GameLib.Event.LOAD_FONT = 0x55; -GameLib.Event.FONT_NOT_FOUND = 0x56; -GameLib.Event.STOP_ALL_AUDIO = 0x57; -GameLib.Event.REGISTER_DEPENDENCIES = 0x58; -GameLib.Event.GAME_LOADED = 0x59; -GameLib.Event.COMPONENT_UPDATE = 0x5a; -GameLib.Event.LOAD_PROGRESS = 0x5b; -GameLib.Event.ENTITY_LOADED = 0x5c; -GameLib.Event.MOUSE_DOWN = 0x5d; -GameLib.Event.MOUSE_MOVE = 0x5e; -GameLib.Event.MOUSE_WHEEL = 0x5f; -GameLib.Event.MOUSE_UP = 0x60; -GameLib.Event.PARTICLE_INSTANCE_UPDATED = 0x61; -GameLib.Event.GAME_DATA = 0x62; -GameLib.Event.PAUSE_ALL_AUDIO = 0x63; -GameLib.Event.CONTINUE_ALL_AUDIO = 0x64; -GameLib.Event.MUTE_AUDIO = 0x65; -GameLib.Event.GAME_STARTED = 0x66; -GameLib.Event.GAME_PAUSED = 0x67; -GameLib.Event.GAME_RESUMED = 0x68; -GameLib.Event.CUSTOM_GAME_START = 0x69; -GameLib.Event.AUDIO_MUTED = 0x6a; -GameLib.Event.AUDIO_UNMUTED = 0x6b; -GameLib.Event.RECEIVE_DESTINATION_CHANGED = 0x6c; -GameLib.Event.SELECTION_MODE_CHANGE = 0x6d; -GameLib.Event.MESH_FACE_SELECTED = 0x6e; -GameLib.Event.MESH_FACE_DESELECTED = 0x6f; -GameLib.Event.BEFORE_WINDOW_RESIZE = 0x70; -GameLib.Event.GET_WINDOW_SIZE = 0x71; -GameLib.Event.GET_RENDER_CONFIGURATION = 0x72; -GameLib.Event.SET_ACTIVE_RENDER_CONFIGURATION = 0x73; -GameLib.Event.REPLACE_COMPONENT = 0x74; -GameLib.Event.COMPONENT_REPLACED = 0x75; -GameLib.Event.ENGINE_FIRED_PARTICLES_ZERO = 0x76; +R3.Event.WINDOW_RESIZE = 0x1; +R3.Event.PARENT_SCENE_CHANGE = 0x2; +R3.Event.EXCLUDE_FROM_ENVIRONMENT = 0x3; +R3.Event.INSTANCE_CLONED = 0x4; +R3.Event.LOAD_IMAGE = 0x5; +R3.Event.NEW_ENTITY = 0x6; +R3.Event.MATERIAL_TYPE_CHANGED = 0x7; +R3.Event.SAVE_COMPONENT = 0x8; +R3.Event.SAVE_COMPONENT_ERROR = 0x9; +R3.Event.COMPONENT_SAVED = 0xa; +R3.Event.LOAD_COMPONENT = 0xb; +R3.Event.LOAD_COMPONENT_ERROR = 0xc; +R3.Event.LOGGED_IN = 0xd; +R3.Event.COMPONENT_CREATED = 0xe; +R3.Event.COMPONENT_CLONED = 0xf; +R3.Event.TEXTURE_ANIMATED_CHANGE = 0x10; +R3.Event.ANIMATE_TEXTURE_INSTANCE = 0x11; +R3.Event.REMOVE_PARTICLE_ENGINE = 0x12; +R3.Event.GAME_PAUSE = 0x13; +R3.Event.SHADER_UPDATE = 0x14; +R3.Event.PLAY_AUDIO = 0x15; +R3.Event.MATERIAL_INSTANCE_UPDATED = 0x16; +R3.Event.PAUSE_AUDIO = 0x17; +R3.Event.MESH_INSTANCE_UPDATED = 0x18; +R3.Event.STOP_AUDIO = 0x19; +R3.Event.LIGHT_INSTANCE_UPDATED = 0x1a; +R3.Event.DELETE_COMPONENT = 0x1b; +R3.Event.COMPONENT_DOWNLOAD_COMPLETE = 0x1c; +R3.Event.COMPONENTS_LINKED = 0x1d; +R3.Event.UNRESOLVED_DEPENDENCIES_UPDATE = 0x1e; +R3.Event.REGISTER_UPDATE = 0x1f; +R3.Event.BUILD_GUI = 0x20; +R3.Event.REMOVE_MESH = 0x21; +R3.Event.MESH_SELECTED = 0x22; +R3.Event.MESH_DESELECTED = 0x23; +R3.Event.COMPONENT_REGISTER = 0x24; +R3.Event.IMAGE_NOT_FOUND = 0x25; +R3.Event.BLENDER_DATA_RECEIVED = 0x26; +R3.Event.IMAGE_UPLOAD_COMPLETE = 0x27; +R3.Event.REMOVE_COMPONENT = 0x28; +R3.Event.KEY_DOWN = 0x29; +R3.Event.KEY_UP = 0x2a; +R3.Event.RENDER = 0x2b; +R3.Event.EVENT_LIST = 0x2c; +R3.Event.COMPILE_SUCCESS = 0x2d; +R3.Event.COMPILE_FAILED = 0x2e; +R3.Event.TEXTURE_INSTANCE_UPDATED = 0x2f; +R3.Event.EVENT_ID_UPDATE = 0x30; +R3.Event.MATERIAL_TEXTURES_UPDATED = 0x31; +R3.Event.DELETE_COMPONENT_ERROR = 0x32; +R3.Event.COMPONENT_DELETED = 0x33; +R3.Event.COMPONENT_TYPES_FETCHED = 0x34; +R3.Event.AUDIO_ENDED = 0x35; +R3.Event.COMPONENT_LINKED = 0x36; +R3.Event.DONE_SAVING = 0x37; +R3.Event.BEFORE_RENDER = 0x38; +R3.Event.AFTER_RENDER = 0x39; +R3.Event.ARRAY_ITEM_ADDED = 0x3a; +R3.Event.INSTANCE_CREATED = 0x3b; +R3.Event.VISUALIZE = 0x3c; +R3.Event.STOP_VISUALIZE = 0x3d; +R3.Event.FETCH_COMPONENT_TYPES = 0x3e; +R3.Event.FETCH_COMPONENTS = 0x3f; +R3.Event.GET_API_URL = 0x40; +R3.Event.GET_RUNTIME = 0x41; +R3.Event.PARENT_WORLD_CHANGE = 0x42; +R3.Event.ANIMATE = 0x43; +R3.Event.ANIMATION_COMPILE_SUCCESS = 0x44; +R3.Event.ANIMATION_COMPILE_FAILED = 0x45; +R3.Event.SAVING = 0x46; +R3.Event.GAME_OVER = 0x47; +R3.Event.GAME_START = 0x48; +R3.Event.TOUCH_START = 0x49; +R3.Event.TOUCH_END = 0x4a; +R3.Event.TOUCH_MOVE = 0x4b; +R3.Event.TOUCH_CANCEL = 0x4c; +R3.Event.GET_REMOTE_API_URL = 0x4d; +R3.Event.COMPONENT_TYPES_UPDATE = 0x4e; +R3.Event.DELAYED_INSTANCE_ENCOUNTERED = 0x4f; +R3.Event.CAST_SOURCE_CHANGED = 0x50; +R3.Event.RESOLVE_DEPENDENCIES = 0x51; +R3.Event.NAME_UPDATE = 0x52; +R3.Event.CANVAS_CHANGE = 0x53; +R3.Event.AFTER_WINDOW_RESIZE = 0x54; +R3.Event.LOAD_FONT = 0x55; +R3.Event.FONT_NOT_FOUND = 0x56; +R3.Event.STOP_ALL_AUDIO = 0x57; +R3.Event.REGISTER_DEPENDENCIES = 0x58; +R3.Event.GAME_LOADED = 0x59; +R3.Event.COMPONENT_UPDATE = 0x5a; +R3.Event.LOAD_PROGRESS = 0x5b; +R3.Event.ENTITY_LOADED = 0x5c; +R3.Event.MOUSE_DOWN = 0x5d; +R3.Event.MOUSE_MOVE = 0x5e; +R3.Event.MOUSE_WHEEL = 0x5f; +R3.Event.MOUSE_UP = 0x60; +R3.Event.PARTICLE_INSTANCE_UPDATED = 0x61; +R3.Event.GAME_DATA = 0x62; +R3.Event.PAUSE_ALL_AUDIO = 0x63; +R3.Event.CONTINUE_ALL_AUDIO = 0x64; +R3.Event.MUTE_AUDIO = 0x65; +R3.Event.GAME_STARTED = 0x66; +R3.Event.GAME_PAUSED = 0x67; +R3.Event.GAME_RESUMED = 0x68; +R3.Event.CUSTOM_GAME_START = 0x69; +R3.Event.AUDIO_MUTED = 0x6a; +R3.Event.AUDIO_UNMUTED = 0x6b; +R3.Event.RECEIVE_DESTINATION_CHANGED = 0x6c; +R3.Event.SELECTION_MODE_CHANGE = 0x6d; +R3.Event.MESH_FACE_SELECTED = 0x6e; +R3.Event.MESH_FACE_DESELECTED = 0x6f; +R3.Event.BEFORE_WINDOW_RESIZE = 0x70; +R3.Event.GET_WINDOW_SIZE = 0x71; +R3.Event.GET_RENDER_CONFIGURATION = 0x72; +R3.Event.SET_ACTIVE_RENDER_CONFIGURATION = 0x73; +R3.Event.REPLACE_COMPONENT = 0x74; +R3.Event.COMPONENT_REPLACED = 0x75; +R3.Event.ENGINE_FIRED_PARTICLES_ZERO = 0x76; /** * Returns string name of event ID @@ -140,7 +140,7 @@ GameLib.Event.ENGINE_FIRED_PARTICLES_ZERO = 0x76; * @returns {*} * @constructor */ -GameLib.Event.GetEventName = function(number) { +R3.Event.GetEventName = function(number) { switch(number) { case 0x1 : return 'window_resize'; @@ -272,11 +272,11 @@ GameLib.Event.GetEventName = function(number) { * @param eventName * @param callback */ -GameLib.Event.prototype.subscribe = function( +R3.Event.prototype.subscribe = function( eventName, callback ) { - return GameLib.Event.Subscribe(eventName, callback.bind(this)); + return R3.Event.Subscribe(eventName, callback.bind(this)); }; @@ -286,18 +286,18 @@ GameLib.Event.prototype.subscribe = function( // * @param callback // * @returns {{fn, remove: remove}} // */ -// GameLib.Event.prototype.subscribeOnce = function( +// R3.Event.prototype.subscribeOnce = function( // eventName, // callback // ) { // throw new Error('implement first properly'); // // var fn = callback.bind(this); // // -// // if (GameLib.Event.OnceSubscriptions.hasOwnProperty(eventName)) { -// // GameLib.Event.OnceSubscriptions[eventName].push(fn); +// // if (R3.Event.OnceSubscriptions.hasOwnProperty(eventName)) { +// // R3.Event.OnceSubscriptions[eventName].push(fn); // // } else { -// // GameLib.Event.OnceSubscriptions[eventName] = []; -// // GameLib.Event.OnceSubscriptions[eventName].push(fn); +// // R3.Event.OnceSubscriptions[eventName] = []; +// // R3.Event.OnceSubscriptions[eventName].push(fn); // // } // // // // /** @@ -306,8 +306,8 @@ GameLib.Event.prototype.subscribe = function( // // return { // // fn : fn, // // remove : function() { -// // GameLib.Event.Subscriptions[eventName].splice( -// // GameLib.Event.Subscriptions[eventName].indexOf(fn), +// // R3.Event.Subscriptions[eventName].splice( +// // R3.Event.Subscriptions[eventName].indexOf(fn), // // 1 // // ); // // } @@ -327,13 +327,13 @@ GameLib.Event.prototype.subscribe = function( * @param clientErrorCallback * @returns {number} of callbacks executed */ -GameLib.Event.prototype.publish = function( +R3.Event.prototype.publish = function( eventName, data, clientCallback, clientErrorCallback ) { - return GameLib.Event.Emit( + return R3.Event.Emit( eventName, data, clientCallback, @@ -350,7 +350,7 @@ GameLib.Event.prototype.publish = function( * @returns {number} of callbacks executed * @constructor */ -GameLib.Event.Emit = function( +R3.Event.Emit = function( eventName, data, clientCallback, @@ -359,9 +359,9 @@ GameLib.Event.Emit = function( var count = 0; - if (GameLib.Event.Subscriptions.hasOwnProperty(eventName)) { + if (R3.Event.Subscriptions.hasOwnProperty(eventName)) { - if (GameLib.Event.Subscriptions[eventName].length === 0) { + if (R3.Event.Subscriptions[eventName].length === 0) { if (clientCallback) { /** @@ -381,33 +381,33 @@ GameLib.Event.Emit = function( * We need to execute all the callbacks, but not execute them twice, but also keep in mind they can remove * themselves during execution */ - // var length = GameLib.Event.Subscriptions[eventName].length; + // var length = R3.Event.Subscriptions[eventName].length; // // for (var i = 0; i < length; i++) { // - // var object = GameLib.Event.Subscriptions[eventName][i]; + // var object = R3.Event.Subscriptions[eventName][i]; // // if (object.fn && object.executed === false) { // object.fn(data, clientCallback, clientErrorCallback); // object.executed = true; // } // - // if (length !== GameLib.Event.Subscriptions[eventName].length) { + // if (length !== R3.Event.Subscriptions[eventName].length) { // /** // * this callback removed a subscription - reset i and reset the length // */ // i = 0; - // length = GameLib.Event.Subscriptions[eventName].length; + // length = R3.Event.Subscriptions[eventName].length; // } // } // - // GameLib.Event.Subscriptions[eventName].map( + // R3.Event.Subscriptions[eventName].map( // function(object){ // object.executed = false; // } // ) - GameLib.Event.Subscriptions[eventName].map( + R3.Event.Subscriptions[eventName].map( function(callback) { if (callback) { callback(data, clientCallback, clientErrorCallback); @@ -433,21 +433,21 @@ GameLib.Event.Emit = function( return count; }; -GameLib.Event.Subscribe = function( +R3.Event.Subscribe = function( eventName, fn ) { - if (GameLib.Event.Subscriptions.hasOwnProperty(eventName)) { - GameLib.Event.Subscriptions[eventName].push(fn); + if (R3.Event.Subscriptions.hasOwnProperty(eventName)) { + R3.Event.Subscriptions[eventName].push(fn); // { // fn : fn, // executed : false // } // ); } else { - GameLib.Event.Subscriptions[eventName] = []; - GameLib.Event.Subscriptions[eventName].push(fn); + R3.Event.Subscriptions[eventName] = []; + R3.Event.Subscriptions[eventName].push(fn); // { // fn : fn, // executed : false @@ -462,7 +462,7 @@ GameLib.Event.Subscribe = function( fn : fn, remove : function() { - var index = GameLib.Event.Subscriptions[eventName].indexOf(fn); + var index = R3.Event.Subscriptions[eventName].indexOf(fn); // reduce( // function(result, object, index) { // if (object.fn === fn) { @@ -477,7 +477,7 @@ GameLib.Event.Subscribe = function( throw new Error('could not remove subscription'); } - GameLib.Event.Subscriptions[eventName].splice( + R3.Event.Subscriptions[eventName].splice( index, 1 ); diff --git a/src/game-lib-a-2-utils.js b/src/r3-a-2-utils.js similarity index 80% rename from src/game-lib-a-2-utils.js rename to src/r3-a-2-utils.js index d2b7698..5c59a5e 100644 --- a/src/game-lib-a-2-utils.js +++ b/src/r3-a-2-utils.js @@ -1,15 +1,15 @@ -GameLib.Utils = function() {}; +R3.Utils = function() {}; /** * Strips image extension from given path * @param imagePath * @constructor */ -GameLib.Utils.StripImageExtension = function(imagePath) { +R3.Utils.StripImageExtension = function(imagePath) { return imagePath.replace(/(\.png$|\.gif$|\.jpeg$|\.jpg$)/,'') }; -GameLib.Utils.BuildVectorSource = function(result, name, dimension) { +R3.Utils.BuildVectorSource = function(result, name, dimension) { if (dimension === 2) { result[name] = {}; @@ -43,7 +43,7 @@ GameLib.Utils.BuildVectorSource = function(result, name, dimension) { * @constructor * @param array */ -GameLib.Utils.GetArrayInstances = function(array) { +R3.Utils.GetArrayInstances = function(array) { return array.reduce( function(result, object) { @@ -51,7 +51,7 @@ GameLib.Utils.GetArrayInstances = function(array) { return result; } - if (GameLib.Utils.UndefinedOrNull(object.instance)) { + if (R3.Utils.UndefinedOrNull(object.instance)) { result = null; } else { result.push(object.instance); @@ -63,7 +63,7 @@ GameLib.Utils.GetArrayInstances = function(array) { ); }; -GameLib.Utils.SortFacesByMaterialIndex = function(faces) { +R3.Utils.SortFacesByMaterialIndex = function(faces) { /** * Sorts faces according to material index because later we will create @@ -85,7 +85,7 @@ GameLib.Utils.SortFacesByMaterialIndex = function(faces) { return faces; }; -GameLib.Utils.BuildQuaternionSource = function(result, name) { +R3.Utils.BuildQuaternionSource = function(result, name) { result[name] = {}; result[name].axis = {}; result[name].axis.x = false; @@ -98,7 +98,7 @@ GameLib.Utils.BuildQuaternionSource = function(result, name) { result[name].w = false; }; -GameLib.Utils.ObjectPropertiesAsBoolean = function(object) { +R3.Utils.ObjectPropertiesAsBoolean = function(object) { return Object.keys(object).reduce( function(result, propertyId) { @@ -108,20 +108,20 @@ GameLib.Utils.ObjectPropertiesAsBoolean = function(object) { result[propertyId] = false; - // if (object[propertyId] instanceof GameLib.Vector2) { - // GameLib.Utils.BuildVectorSource(result, propertyId, 2); + // if (object[propertyId] instanceof R3.Vector2) { + // R3.Utils.BuildVectorSource(result, propertyId, 2); // } // - // if (object[propertyId] instanceof GameLib.Vector3) { - // GameLib.Utils.BuildVectorSource(result, propertyId, 3); + // if (object[propertyId] instanceof R3.Vector3) { + // R3.Utils.BuildVectorSource(result, propertyId, 3); // } // - // if (object[propertyId] instanceof GameLib.Vector4) { - // GameLib.Utils.BuildVectorSource(result, propertyId, 4); + // if (object[propertyId] instanceof R3.Vector4) { + // R3.Utils.BuildVectorSource(result, propertyId, 4); // } // - // if (object[propertyId] instanceof GameLib.Quaternion) { - // GameLib.Utils.BuildQuaternionSource(result, propertyId); + // if (object[propertyId] instanceof R3.Quaternion) { + // R3.Utils.BuildQuaternionSource(result, propertyId); // } return result; @@ -131,12 +131,12 @@ GameLib.Utils.ObjectPropertiesAsBoolean = function(object) { ); }; -GameLib.Utils.GetRuntime = function() { +R3.Utils.GetRuntime = function() { var result = null; - GameLib.Event.Emit( - GameLib.Event.GET_RUNTIME, + R3.Event.Emit( + R3.Event.GET_RUNTIME, null, function(runtime) { result = runtime; @@ -151,12 +151,12 @@ GameLib.Utils.GetRuntime = function() { * @returns {*} * @constructor */ -GameLib.Utils.GetWindowSize = function() { +R3.Utils.GetWindowSize = function() { var size = null; - GameLib.Event.Emit( - GameLib.Event.GET_WINDOW_SIZE, + R3.Event.Emit( + R3.Event.GET_WINDOW_SIZE, null, function (data) { size = data; @@ -172,8 +172,8 @@ GameLib.Utils.GetWindowSize = function() { * @param object * @constructor */ -GameLib.Utils.UpdateWindowSize = function(object) { - var size = GameLib.Utils.GetWindowSize(); +R3.Utils.UpdateWindowSize = function(object) { + var size = R3.Utils.GetWindowSize(); object.width = size.width; object.height = size.height; }; @@ -186,7 +186,7 @@ GameLib.Utils.UpdateWindowSize = function(object) { * @returns {*} * @constructor */ -GameLib.Utils.ObjectIdWithNameInArray = function(name, array) { +R3.Utils.ObjectIdWithNameInArray = function(name, array) { return array.reduce( function(result, object) { @@ -205,7 +205,7 @@ GameLib.Utils.ObjectIdWithNameInArray = function(name, array) { ); }; -// GameLib.Utils.ObjectFactory = function() { +// R3.Utils.ObjectFactory = function() { // // var promiseList = {}; // @@ -224,17 +224,17 @@ GameLib.Utils.ObjectIdWithNameInArray = function(name, array) { // // promiseList[objectId] = defer.promise; // -// GameLib.Utils.ObjectFactory.Link(idToObject, objectId, defer); +// R3.Utils.ObjectFactory.Link(idToObject, objectId, defer); // // return promiseList[objectId]; // } // }; -GameLib.Utils.LoadIdsFromArrayToIdObject = function(array, idToObject) { +R3.Utils.LoadIdsFromArrayToIdObject = function(array, idToObject) { }; -GameLib.Utils.LoadIdsFromObjectToIdObject = function(object, idToObject) { +R3.Utils.LoadIdsFromObjectToIdObject = function(object, idToObject) { }; @@ -246,7 +246,7 @@ GameLib.Utils.LoadIdsFromObjectToIdObject = function(object, idToObject) { * @returns {*} * @constructor */ -GameLib.Utils.GetRandomInt = function(min, max) { +R3.Utils.GetRandomInt = function(min, max) { min = Math.ceil(min); max = Math.floor(max); return Math.floor(Math.random() * (max - min)) + min; //The maximum is exclusive and the minimum is inclusive @@ -259,13 +259,13 @@ GameLib.Utils.GetRandomInt = function(min, max) { * @returns {*} * @constructor */ -GameLib.Utils.GetRandomIntInclusive = function(min, max) { +R3.Utils.GetRandomIntInclusive = function(min, max) { min = Math.ceil(min); max = Math.floor(max); return Math.floor(Math.random() * (max - min + 1)) + min; //The maximum is inclusive and the minimum is inclusive }; -GameLib.Utils.InterpolateArray = function(data, fitCount) { +R3.Utils.InterpolateArray = function(data, fitCount) { var linearInterpolate = function (before, after, atPoint) { return before + (after - before) * atPoint; @@ -296,7 +296,7 @@ GameLib.Utils.InterpolateArray = function(data, fitCount) { * @returns {boolean} * @constructor */ -GameLib.Utils.UndefinedOrNull = function ( +R3.Utils.UndefinedOrNull = function ( variable ) { return typeof variable === 'undefined' || variable === null; @@ -308,7 +308,7 @@ GameLib.Utils.UndefinedOrNull = function ( * @returns {boolean} * @constructor */ -GameLib.Utils.Defined = function ( +R3.Utils.Defined = function ( variable ) { return typeof variable !== 'undefined' && variable !== null; @@ -319,7 +319,7 @@ GameLib.Utils.Defined = function ( * @param fn * @constructor */ -GameLib.Utils.GetParameters = function(fn) { +R3.Utils.GetParameters = function(fn) { var FN_ARGS = /^function\s*[^\(]*\(\s*([^\)]*)\)/m; var FN_ARG_SPLIT = /,/; @@ -352,11 +352,11 @@ GameLib.Utils.GetParameters = function(fn) { * @returns {null} * @constructor */ -GameLib.Utils.IdOrNull = function (object) { - if (GameLib.Utils.UndefinedOrNull(object)) { +R3.Utils.IdOrNull = function (object) { + if (R3.Utils.UndefinedOrNull(object)) { return null; } else { - if (GameLib.Utils.UndefinedOrNull(object.id)) { + if (R3.Utils.UndefinedOrNull(object.id)) { console.warn('saving an object reference with no ID : ', object); return null; } @@ -371,7 +371,7 @@ GameLib.Utils.IdOrNull = function (object) { * @returns {{configurable?: boolean, enumerable?: boolean, value?, writable?: boolean, get?: Function, set?: Function}} * @constructor */ -GameLib.Utils.LimitToPI = function(property, objectProperty) { +R3.Utils.LimitToPI = function(property, objectProperty) { var store = objectProperty; @@ -399,14 +399,14 @@ GameLib.Utils.LimitToPI = function(property, objectProperty) { * @returns [] * @constructor */ -GameLib.Utils.IdArrayOrEmptyArray = function (array) { - if (GameLib.Utils.UndefinedOrNull(array)) { +R3.Utils.IdArrayOrEmptyArray = function (array) { + if (R3.Utils.UndefinedOrNull(array)) { return []; } else { return array.map(function(item) { - if (GameLib.Utils.UndefinedOrNull(item.id)) { + if (R3.Utils.UndefinedOrNull(item.id)) { throw new Error('No ID found while trying to store IDs to array'); } @@ -423,9 +423,9 @@ GameLib.Utils.IdArrayOrEmptyArray = function (array) { * @param id * @constructor */ -GameLib.Utils.Link = function(propertyString, idToObject, parentObject, id) { +R3.Utils.Link = function(propertyString, idToObject, parentObject, id) { - if (!GameLib.Utils.UndefinedOrNull(parentObject[propertyString])) { + if (!R3.Utils.UndefinedOrNull(parentObject[propertyString])) { if (!idToObject.hasOwnProperty(id)) { console.warn('Linking failed for object:' + parentObject.name); @@ -440,16 +440,16 @@ GameLib.Utils.Link = function(propertyString, idToObject, parentObject, id) { * @returns {string} * @constructor */ -GameLib.Utils.RandomId = function(length) { +R3.Utils.RandomId = function(length) { - if (GameLib.Utils.UndefinedOrNull(length)) { + if (R3.Utils.UndefinedOrNull(length)) { length = 10; } return Math.random().toString(36).substr(2, length); }; -GameLib.Utils.InvertWindingOrder = function(triangles) { +R3.Utils.InvertWindingOrder = function(triangles) { for (var i = 0; i < triangles.length; i++) { var v1 = triangles[i].v1; @@ -466,11 +466,11 @@ GameLib.Utils.InvertWindingOrder = function(triangles) { /** * Inverts a mesh winding order (and its instance) - * @param mesh GameLib.D3.Mesh + * @param mesh R3.D3.Mesh * @returns {*} * @constructor */ -GameLib.Utils.InvertMeshWindingOrder = function(mesh) { +R3.Utils.InvertMeshWindingOrder = function(mesh) { mesh.faces.forEach( function (face) { @@ -493,12 +493,12 @@ GameLib.Utils.InvertMeshWindingOrder = function(mesh) { /** * This function resets a the winding order of a mesh from a reference point V (the average center of the mesh) */ -GameLib.Utils.ResetWindingOrder = function(faces, vertices) { +R3.Utils.ResetWindingOrder = function(faces, vertices) { - var vertexList = new GameLib.API.Vector3.Points(); + var vertexList = new R3.API.Vector3.Points(); for (var v = 0; v < vertices.length; v++) { - vertexList.add(new GameLib.API.Vector3( + vertexList.add(new R3.API.Vector3( vertices[v].position.x, vertices[v].position.y, vertices[v].position.z @@ -534,7 +534,7 @@ GameLib.Utils.ResetWindingOrder = function(faces, vertices) { for (var i = 0; i < triangles.length; i++) { if ( - GameLib.API.Vector3.clockwise( + R3.API.Vector3.clockwise( vertices[triangles[i].v0].position, vertices[triangles[i].v1].position, vertices[triangles[i].v2].position, @@ -574,11 +574,11 @@ GameLib.Utils.ResetWindingOrder = function(faces, vertices) { * neighbor_tria = neighbor_on_egde( next_tria, edge ) * if neighbor_tria exists and neighbor_tria not in processed: * to_process add (neighbor_tria, edge opposite oriented (BA)) - * @param faces GameLib.D3.Face[] - * @param orientationEdge GameLib.API.Vector2 + * @param faces R3.D3.Face[] + * @param orientationEdge R3.API.Vector2 * @returns {Array} */ -GameLib.Utils.FixWindingOrder = function(faces, orientationEdge) { +R3.Utils.FixWindingOrder = function(faces, orientationEdge) { /** * Checks if a Face belonging to a TriangleEdge has already been processed @@ -599,8 +599,8 @@ GameLib.Utils.FixWindingOrder = function(faces, orientationEdge) { /** * Returns a neighbouring triangle on a specific edge - preserving the edge orientation - * @param edge GameLib.API.Vector2 - * @param faces GameLib.D3.Face[] + * @param edge R3.API.Vector2 + * @param faces R3.D3.Face[] * @param currentTriangle * @returns {*} */ @@ -616,7 +616,7 @@ GameLib.Utils.FixWindingOrder = function(faces, orientationEdge) { (faces[i].v2 === edge.y && faces[i].v0 === edge.x) ) { - var triangle = new GameLib.D3.API.Face( + var triangle = new R3.D3.API.Face( null, null, faces[i].v0index, @@ -630,7 +630,7 @@ GameLib.Utils.FixWindingOrder = function(faces, orientationEdge) { continue; } - return new GameLib.D3.TriangleEdge( + return new R3.D3.TriangleEdge( triangle, edge ); @@ -641,8 +641,8 @@ GameLib.Utils.FixWindingOrder = function(faces, orientationEdge) { } var toProcess = [ - new GameLib.D3.TriangleEdge( - new GameLib.D3.API.Face( + new R3.D3.TriangleEdge( + new R3.D3.API.Face( null, null, faces[0].v0index, @@ -689,15 +689,15 @@ GameLib.Utils.FixWindingOrder = function(faces, orientationEdge) { processed.push(triangleEdge); var edges = [ - new GameLib.API.Vector2( + new R3.API.Vector2( triangleEdge.triangle.v0index, triangleEdge.triangle.v1index ), - new GameLib.API.Vector2( + new R3.API.Vector2( triangleEdge.triangle.v1index, triangleEdge.triangle.v2index ), - new GameLib.API.Vector2( + new R3.API.Vector2( triangleEdge.triangle.v2index, triangleEdge.triangle.v0index ) @@ -740,7 +740,7 @@ GameLib.Utils.FixWindingOrder = function(faces, orientationEdge) { * @param grain is the amount to systematically rotate the poly by - a finer grain means a more accurate maximum XY * @return [] */ -GameLib.Utils.FixPolyZPlane = function(verticesFlat, grain) { +R3.Utils.FixPolyZPlane = function(verticesFlat, grain) { if ((verticesFlat.length % 3) !== 0 && !(verticesFlat.length > 9)) { console.log("The vertices are not in the right length : " + verticesFlat.length); @@ -748,10 +748,10 @@ GameLib.Utils.FixPolyZPlane = function(verticesFlat, grain) { var vertices = []; - var points = new GameLib.API.Quaternion.Points(); + var points = new R3.API.Quaternion.Points(); for (var i = 0; i < verticesFlat.length; i += 3) { - points.add(new GameLib.API.Vector3( + points.add(new R3.API.Vector3( verticesFlat[i], verticesFlat[i + 1], verticesFlat[i + 2] @@ -776,7 +776,7 @@ GameLib.Utils.FixPolyZPlane = function(verticesFlat, grain) { return vertices; }; -GameLib.Utils.MovingAverage = function(period) { +R3.Utils.MovingAverage = function(period) { var nums = []; return function(num) { nums.push(num); @@ -792,7 +792,7 @@ GameLib.Utils.MovingAverage = function(period) { } }; -GameLib.Utils.Intersect = function (a, b) { +R3.Utils.Intersect = function (a, b) { var t; @@ -828,7 +828,7 @@ GameLib.Utils.Intersect = function (a, b) { ); }; -GameLib.Utils.Difference = function (a, b) { +R3.Utils.Difference = function (a, b) { var t; @@ -870,7 +870,7 @@ GameLib.Utils.Difference = function (a, b) { * @param object * @constructor */ -GameLib.Utils.PushUnique = function(array, object) { +R3.Utils.PushUnique = function(array, object) { if (array.indexOf(object) === -1) { array.push(object); @@ -883,57 +883,57 @@ GameLib.Utils.PushUnique = function(array, object) { * @returns {boolean} * @constructor */ -GameLib.Utils.IsEmpty = function(obj) { +R3.Utils.IsEmpty = function(obj) { return (Object.keys(obj).length === 0 && obj.constructor === Object); }; -GameLib.Utils.isString = function(member) { +R3.Utils.isString = function(member) { return (typeof member === 'string'); }; -GameLib.Utils.isBoolean = function(member) { +R3.Utils.isBoolean = function(member) { return (member === true || member === false); }; -GameLib.Utils.isColor = function(member) { - return (member instanceof GameLib.Color); +R3.Utils.isColor = function(member) { + return (member instanceof R3.Color); }; -GameLib.Utils.isNumber = function(member) { +R3.Utils.isNumber = function(member) { return (typeof member === 'number'); }; -GameLib.Utils.isVector2 = function(member) { +R3.Utils.isVector2 = function(member) { return ( - member instanceof GameLib.API.Vector2 || - member instanceof GameLib.Vector2 + member instanceof R3.API.Vector2 || + member instanceof R3.Vector2 ); }; -GameLib.Utils.isVector3 = function(member) { +R3.Utils.isVector3 = function(member) { return ( - member instanceof GameLib.API.Vector3 || - member instanceof GameLib.Vector3 + member instanceof R3.API.Vector3 || + member instanceof R3.Vector3 ); }; -GameLib.Utils.isVector4 = function(member) { +R3.Utils.isVector4 = function(member) { return ( - member instanceof GameLib.API.Vector4 || - member instanceof GameLib.Vector4 || - member instanceof GameLib.API.Quaternion || - member instanceof GameLib.Quaternion + member instanceof R3.API.Vector4 || + member instanceof R3.Vector4 || + member instanceof R3.API.Quaternion || + member instanceof R3.Quaternion ); }; /** * @return {string} */ -GameLib.Utils.LowerUnderscore = function(name) { +R3.Utils.LowerUnderscore = function(name) { return name.toLowerCase().replace(/\s+/, '_'); }; -GameLib.Utils.UpperCaseWordsSpaces = function(input) { +R3.Utils.UpperCaseWordsSpaces = function(input) { var word = input.replace(/[-_]/g, ' '); @@ -953,7 +953,7 @@ GameLib.Utils.UpperCaseWordsSpaces = function(input) { /** * @return {string} */ -GameLib.Utils.UpperCaseUnderscore = function(word) { +R3.Utils.UpperCaseUnderscore = function(word) { var str = ''; @@ -978,7 +978,7 @@ GameLib.Utils.UpperCaseUnderscore = function(word) { * @returns {string} * @constructor */ -GameLib.Utils.PaddedText = function(length, padChar, string) { +R3.Utils.PaddedText = function(length, padChar, string) { var pad = ""; diff --git a/src/game-lib-a-api-component.js b/src/r3-a-api-component.js similarity index 66% rename from src/game-lib-a-api-component.js rename to src/r3-a-api-component.js index f5dfef7..36c2159 100644 --- a/src/game-lib-a-api-component.js +++ b/src/r3-a-api-component.js @@ -4,16 +4,16 @@ * @param parentEntity * @constructor */ -GameLib.API.Component = function( +R3.API.Component = function( componentType, parentEntity ) { this.componentType = componentType; - if (GameLib.Utils.UndefinedOrNull(parentEntity)) { + if (R3.Utils.UndefinedOrNull(parentEntity)) { parentEntity = null; } this.parentEntity = parentEntity; }; -GameLib.API.Component.prototype.constructor = GameLib.API.Component; \ No newline at end of file +R3.API.Component.prototype.constructor = R3.API.Component; \ No newline at end of file diff --git a/src/r3-a-component-a.js b/src/r3-a-component-a.js new file mode 100644 index 0000000..13dae37 --- /dev/null +++ b/src/r3-a-component-a.js @@ -0,0 +1,2003 @@ +/** + * Component Interface + * @constructor + * @param linkedObjects + * @param delayed + */ +R3.Component = function( + linkedObjects, + delayed +) { + if (R3.Utils.UndefinedOrNull(linkedObjects)) { + linkedObjects = {}; + } + this.linkedObjects = linkedObjects; + this.linkedObjects.parentEntity = R3.Entity; + + this.idToObject = {}; + + this.selected = false; + + this.building = false; + + this.loaded = false; + + this.linked = false; + + this.cloneNumber = 0; + + this.isClone = false; + + this.generateNewImageIds = false; + + if (R3.Utils.UndefinedOrNull(delayed)) { + delayed = false; + } + this.delayed = delayed; + + this.dependencies = this.getDependencies(); + + R3.Event.Emit( + R3.Event.COMPONENT_REGISTER, + { + component : this + } + ); + + if (this.dependencies.length === 0) { + + this.performInstanceCreation(); + + } else { + R3.Event.Emit( + R3.Event.REGISTER_DEPENDENCIES, + { + component : this + } + ); + } + + +}; + +R3.Component.prototype = Object.create(R3.Event.prototype); +R3.Component.prototype.constructor = R3.Component; + +/** + * This function, performs standard instance creation steps for all our components, which means + * Ensure we have no dependencies + * Build a list of all child components - if they are all linked, we are ready to create an instance + * Ensure we are linked + * Ensure we are not delayed + * Try to create the instance + * Error Log if failed + * Don't do anything if we are not fully linked + */ +R3.Component.prototype.performInstanceCreation = function() { + + var dependencies = true; + + if (R3.Utils.UndefinedOrNull(this.dependencies)) { + dependencies = false; + } + + if (this.dependencies && this.dependencies instanceof Array && this.dependencies.length === 0) { + dependencies = false; + } + + if (dependencies) { + throw new Error('performInstanceCreation called while this object still has dependencies'); + } + + delete this.dependencies; + + /** + * Build ID to object should run through all sub components - + * if one is found which is not linked, this component is not linked fully + */ + this.buildIdToObject(); + + /** + * Don't try to create an instance of this object until it is fully linked + */ + if (this.linked) { + if (!this.delayed) { + try { + this.createInstance(); + } catch (error) { + console.error(error); + } + } else { + /** + * Some systems require an instance creation at an exact time, like System.Input for Edit Controls - + * we need to give them the opportunity to handle this situation + */ + R3.Event.Emit( + R3.Event.DELAYED_INSTANCE_ENCOUNTERED, + { + component : this + } + ) + } + } +}; + +R3.Component.prototype.createInstance = function() { + + // console.log('create instance : '+ this.name); + + /** + * When you do actually call 'createInstance' - it is wise to state we are no longer delayed - we assume the caller + * knows when to call createInstance, so we do the housekeeping here + * @type {boolean} + */ + this.delayed = false; + + if (this.instance) { + + this.loaded = true; + + R3.Event.Emit( + R3.Event.INSTANCE_CREATED, + { + component: this + } + ); + + R3.Event.Emit( + R3.Event.RESOLVE_DEPENDENCIES, + { + component: this + } + ); + } + + if (this instanceof R3.Entity) { + R3.Event.Emit( + R3.Event.ENTITY_LOADED, + { + entity:this + } + ) + } +}; + +/** + * Dependencies are everything which is either a string or an object with an id which is linked to this object + * @returns {Array} + */ +R3.Component.prototype.getDependencies = function() { + + var dependencies = []; + + for (var property in this.linkedObjects) { + + if ( + this.linkedObjects.hasOwnProperty(property) && + property.indexOf('parent') !== 0 && + this.hasOwnProperty(property) + ){ + if (typeof this[property] === 'string') { + R3.Utils.PushUnique(dependencies, this[property]); + } + + if (this[property] instanceof Array) { + this[property].map( + function(arrayProperty) { + + if (typeof arrayProperty === 'string') { + R3.Utils.PushUnique(dependencies, arrayProperty); + } + + if (arrayProperty && + arrayProperty instanceof R3.Component + ) { + R3.Utils.PushUnique(dependencies, arrayProperty.id); + } + } + ); + } + + if (this[property] && + this[property] instanceof R3.Component + ) { + R3.Utils.PushUnique(dependencies, this[property].id); + } + } + } + + return dependencies; +}; + +R3.Component.prototype.updateInstance = function(property) { + + if (property === 'parentEntity') { + + if (this.parentEntity instanceof R3.Entity) { + this.parentEntity.addComponent(this); + + this.buildIdToObject(); + + Object.keys(this.idToObject).map( + function(componentId) { + + if (this.id !== componentId) { + this.parentEntity.addComponent(this.idToObject[componentId]); + } + + }.bind(this) + ) + } + + } + +}; + +R3.Component.prototype.toString = function() { + return this.id; +}; + +R3.Component.SOCKET_RECEIVE = 0x1; +R3.Component.MATERIAL_STANDARD = 0x2; +R3.Component.RENDERER = 0x3; +R3.Component.SERVER = 0x4; +R3.Component.CAMERA_PERSPECTIVE = 0x5; +R3.Component.SOCKET = 0x6; +R3.Component.MESH = 0x7; +R3.Component.SPLINE = 0x8; +R3.Component.SHADOW_DIRECTIONAL = 0x9; +R3.Component.PLANE = 0xa; +R3.Component.COMPOSER = 0xb; +R3.Component.RENDER_TARGET = 0xc; +R3.Component.PASS_RENDER = 0xd; +R3.Component.SCENE = 0xe; +R3.Component.RAYCASTER = 0xf; +R3.Component.TEXT = 0x10; +R3.Component.FACE = 0x11; +R3.Component.VIEWPORT = 0x12; +R3.Component.SYSTEM = 0x13; +R3.Component.GRAPHICS = 0x14; +R3.Component.HELPER = 0x15; +R3.Component.CUSTOM_CODE = 0x16; +R3.Component.MOUSE = 0x17; +R3.Component.SKELETON = 0x18; +R3.Component.TEXTURE_IMAGE = 0x19; +R3.Component.ENTITY_MANAGER = 0x1a; +R3.Component.DOM_ELEMENT = 0x1b; +R3.Component.SHADOW_SPOT = 0x1c; +R3.Component.STATS = 0x1d; +R3.Component.GUI = 0x1e; +R3.Component.IMAGE = 0x1f; +R3.Component.ENTITY = 0x20; +R3.Component.OBJECT = 0x21; +R3.Component.RENDERER_D2 = 0x22; +R3.Component.RENDERER_D3 = 0x23; +R3.Component.PHYSICS_WORLD = 0x24; +R3.Component.BROADPHASE = 0x25; +R3.Component.SOLVER = 0x26; +R3.Component.RIGID_BODY = 0x27; +R3.Component.SHAPE = 0x28; +R3.Component.SHAPE_BOX = 0x29; +R3.Component.SHAPE_SPHERE = 0x2a; +R3.Component.SHAPE_TRI_MESH = 0x2b; +R3.Component.SHAPE_CONVEX_HULL = 0x2c; +R3.Component.SHAPE_CONVEX_HULL_CYLINDER = 0x2d; +R3.Component.SHAPE_HEIGHT_MAP = 0x2e; +R3.Component.SHAPE_PLANE = 0x2f; +R3.Component.CONTROLS = 0x30; +R3.Component.CONTROLS_EDITOR = 0x31; +R3.Component.CONTROLS_TOUCH = 0x32; +R3.Component.FRICTION_MATERIAL = 0x33; +R3.Component.FRICTION_CONTACT_MATERIAL = 0x34; +R3.Component.RAYCAST_VEHICLE = 0x35; +R3.Component.RAYCAST_WHEEL = 0x36; +R3.Component.CLOCK = 0x37; +R3.Component.ANIMATION = 0x38; +R3.Component.CONTROLS_KEYBOARD = 0x39; +R3.Component.CONTROLS_MOUSE = 0x3a; +R3.Component.GRAPHICS_THREE = 0x3b; +R3.Component.FONT = 0x3c; +R3.Component.CANVAS = 0x3d; +R3.Component.BONE = 0x3e; +R3.Component.GRAPHICS_IMPACT = 0x3f; +R3.Component.CONTROLS_FIRST_PERSON = 0x40; +R3.Component.SYSTEM_ANIMATION = 0x41; +R3.Component.SYSTEM_CUSTOM_CODE = 0x42; +R3.Component.SYSTEM_GUI = 0x43; +R3.Component.SYSTEM_INPUT = 0x44; +R3.Component.SYSTEM_LINKING = 0x45; +R3.Component.SYSTEM_PHYSICS = 0x46; +R3.Component.SYSTEM_RENDER = 0x47; +R3.Component.SYSTEM_STORAGE = 0x48; +R3.Component.SYSTEM_VISUALIZATION = 0x49; +R3.Component.LIGHT_AMBIENT = 0x4a; +R3.Component.LIGHT_DIRECTIONAL = 0x4b; +R3.Component.LIGHT_HEMISPHERE = 0x4c; +R3.Component.LIGHT_POINT = 0x4d; +R3.Component.LIGHT_RECT_AREA = 0x4e; +R3.Component.LIGHT_SPOT = 0x4f; +R3.Component.FOG = 0x50; +R3.Component.CONTROLS_ORBIT = 0x51; +R3.Component.PARTICLE_ENGINE = 0x52; +R3.Component.SYSTEM_PARTICLE = 0x53; +R3.Component.PARTICLE = 0x54; +R3.Component.AUDIO = 0x55; +R3.Component.SYSTEM_AUDIO = 0x56; +R3.Component.SOCKET_CAST = 0x57; +R3.Component.CAMERA_ORTHOGRAPHIC = 0x58; +R3.Component.CAMERA_STEREO = 0x59; +R3.Component.CAMERA_CUBE = 0x5a; +R3.Component.SHADOW = 0x5b; +R3.Component.RENDER_TARGET_CUBE = 0x5c; +R3.Component.TEXTURE_CUBE = 0x5d; +R3.Component.TEXTURE_CANVAS = 0x5e; +R3.Component.EFFECT_STEREO = 0x5f; +R3.Component.EFFECT_ANAGLYPH = 0x60; +R3.Component.EFFECT_PARALLAX = 0x61; +R3.Component.PASS_SSAO = 0x62; +R3.Component.PASS_BLOOM = 0x63; +R3.Component.PASS_FXAA = 0x64; +R3.Component.RENDER_CONFIGURATION = 0x65; +R3.Component.MATERIAL_BASIC = 0x66; +R3.Component.TEXTURE = 0x67; +R3.Component.MATERIAL_PHONG = 0x68; + +R3.Component.GEOMETRY_NORMAL = 0x69; +R3.Component.GEOMETRY_NORMAL_BOX = 0x6a; +R3.Component.GEOMETRY_NORMAL_CIRCLE = 0x6b; +R3.Component.GEOMETRY_NORMAL_CONE = 0x6c; +R3.Component.GEOMETRY_NORMAL_CYLINDER = 0x6d; +R3.Component.GEOMETRY_NORMAL_DODECAHEDRON = 0x6e; +R3.Component.GEOMETRY_NORMAL_EDGES = 0x6f; +R3.Component.GEOMETRY_NORMAL_EXTRUDE = 0x70; +R3.Component.GEOMETRY_NORMAL_ICOSAHEDRON = 0x71; +R3.Component.GEOMETRY_NORMAL_LATHE = 0x72; +R3.Component.GEOMETRY_NORMAL_OCTAHEDRON = 0x73; +R3.Component.GEOMETRY_NORMAL_PARAMETRIC = 0x74; +R3.Component.GEOMETRY_NORMAL_PLANE = 0x75; +R3.Component.GEOMETRY_NORMAL_POLYHEDRON = 0x76; +R3.Component.GEOMETRY_NORMAL_RING = 0x77; +R3.Component.GEOMETRY_NORMAL_SHAPE = 0x78; +R3.Component.GEOMETRY_NORMAL_SPHERE = 0x79; +R3.Component.GEOMETRY_NORMAL_TETRAHEDRON = 0x7a; +R3.Component.GEOMETRY_NORMAL_TEXT = 0x7b; +R3.Component.GEOMETRY_NORMAL_TORUS = 0x7c; +R3.Component.GEOMETRY_NORMAL_TORUS_KNOT = 0x7d; +R3.Component.GEOMETRY_NORMAL_TUBE = 0x7e; +R3.Component.GEOMETRY_NORMAL_WIREFRAME = 0x7f; + +R3.Component.GEOMETRY_BUFFER = 0x80; +R3.Component.GEOMETRY_BUFFER_BOX = 0x81; +R3.Component.GEOMETRY_BUFFER_CIRCLE = 0x82; +R3.Component.GEOMETRY_BUFFER_CONE = 0x83; +R3.Component.GEOMETRY_BUFFER_CYLINDER = 0x84; +R3.Component.GEOMETRY_BUFFER_DODECAHEDRON = 0x85; +R3.Component.GEOMETRY_BUFFER_EXTRUDE = 0x86; +R3.Component.GEOMETRY_BUFFER_ICOSAHEDRON = 0x87; +R3.Component.GEOMETRY_BUFFER_LATHE = 0x88; +R3.Component.GEOMETRY_BUFFER_OCTAHEDRON = 0x89; +R3.Component.GEOMETRY_BUFFER_PARAMETRIC = 0x8a; +R3.Component.GEOMETRY_BUFFER_PLANE = 0x8b; +R3.Component.GEOMETRY_BUFFER_POLYHEDRON = 0x8c; +R3.Component.GEOMETRY_BUFFER_RING = 0x8d; +R3.Component.GEOMETRY_BUFFER_SHAPE = 0x8e; +R3.Component.GEOMETRY_BUFFER_SPHERE = 0x8f; +R3.Component.GEOMETRY_BUFFER_TETRAHEDRON = 0x90; +R3.Component.GEOMETRY_BUFFER_TEXT = 0x91; +R3.Component.GEOMETRY_BUFFER_TORUS = 0x92; +R3.Component.GEOMETRY_BUFFER_TORUS_KNOT = 0x93; +R3.Component.GEOMETRY_BUFFER_TUBE = 0x94; + +R3.Component.GEOMETRY = 0x95; + +R3.Component.CURVE = 0x96; +R3.Component.CURVE_PATH = 0x97; +R3.Component.CURVE_PATH_D2 = 0x98; +R3.Component.CURVE_PATH_D2_SHAPE = 0x99; +R3.Component.BOX3 = 0x9a; +R3.Component.DRAW_RANGE = 0x9b; +R3.Component.GROUP = 0x9c; + +R3.Component.MATERIAL_SHADER = 0x9d; + +R3.Component.SHADER = 0x9e; +R3.Component.SHADER_VERTEX = 0x9f; +R3.Component.SHADER_FRAGMENT = 0xa0; +R3.Component.GEOMETRY_BUFFER_INSTANCED = 0xa1; +R3.Component.MATERIAL_SHADER_RAW = 0xa2; +R3.Component.MATERIAL_POINTS = 0xa3; + +R3.Component.MAX_COMPONENTS = 0xa4; + +R3.Component.GRAPHICS_RUNTIME = 0x1; +R3.Component.PHYSICS_RUNTIME = 0x2; +R3.Component.SOCKET_RUNTIME = 0x3; +R3.Component.STATISTICS_RUNTIME = 0x4; +R3.Component.DEFAULT_RUNTIME = 0x5; +R3.Component.GUI_RUNTIME = 0x6; +R3.Component.CODER_RUNTIME = 0x7; + +R3.Component.GetCompentTypes = function(constructor) { + + if (constructor === R3.Component) { + + } +}; + +/** + * Returns string name for component number + * @param number + * @returns {*} + * @constructor + */ +R3.Component.GetComponentInfo = function(number) { + switch(number) { + case 0x1 : return { + name : 'R3.Socket.Receive', + runtime : R3.Component.SOCKET_RUNTIME, + constructor : R3.Socket.Receive, + apiConstructor : R3.API.Socket.Receive + }; + case 0x2 : return { + name : 'R3.D3.Material.Standard', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Material.Standard, + apiConstructor : R3.D3.API.Material.Standard + }; + case 0x3 : return { + name : 'R3.Renderer', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.Renderer, + apiConstructor : R3.API.Renderer + }; + case 0x4 : return { + name : 'R3.Server', + runtime : R3.Component.DEFAULT_RUNTIME, + constructor : R3.Server, + apiConstructor : R3.API.Server + }; + case 0x5 : return { + name : 'R3.D3.Camera.Perspective', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Camera.Perspective, + apiConstructor : R3.D3.API.Camera.Perspective + }; + case 0x6 : return { + name : 'R3.Socket', + runtime : R3.Component.SOCKET_RUNTIME, + constructor : R3.Socket, + apiConstructor : R3.API.Socket + }; + case 0x7 : return { + name : 'R3.D3.Mesh', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Mesh, + apiConstructor : R3.D3.API.Mesh + }; + case 0x8 : return { + name : 'R3.D3.Spline', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Spline, + apiConstructor : R3.D3.API.Spline + }; + case 0x9 : return { + name : 'R3.D3.Shadow.Directional', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Shadow.Directional, + apiConstructor : R3.D3.API.Shadow.Directional + }; + case 0xa : return { + name : 'R3.Plane', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.Plane, + apiConstructor : R3.API.Plane + }; + case 0xb : return { + name : 'R3.D3.Composer', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Composer, + apiConstructor : R3.D3.API.Composer + }; + case 0xc : return { + name : 'R3.D3.RenderTarget', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.RenderTarget, + apiConstructor : R3.D3.API.RenderTarget + }; + case 0xd : return { + name : 'R3.D3.Pass.Render', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Pass.Render, + apiConstructor : R3.D3.API.Pass.Render + }; + case 0xe : return { + name : 'R3.D3.Scene', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Scene + }; + case 0xf : return { + name : 'R3.D3.Raycaster', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Raycaster, + apiConstructor : R3.D3.API.Raycaster + }; + case 0x10 : return { + name : 'R3.D3.Text', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Text, + apiConstructor : R3.D3.API.Text + }; + case 0x11 : return { + name : 'R3.D3.Face', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Face, + apiConstructor : R3.D3.API.Face + }; + case 0x12 : return { + name : 'R3.D3.Viewport', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Viewport, + apiConstructor : R3.D3.API.Viewport + }; + case 0x13 : return { + name : 'R3.System', + runtime : R3.Component.DEFAULT_RUNTIME, + constructor : R3.System, + apiConstructor : R3.API.System + }; + case 0x14 : return { + name : 'R3.GraphicsRuntime', + runtime : R3.Component.DEFAULT_RUNTIME, + constructor : R3.GraphicsRuntime + }; + case 0x15 : return { + name : 'R3.D3.Helper', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Helper + }; + case 0x16 : return { + name : 'R3.CustomCode', + runtime : R3.Component.DEFAULT_RUNTIME, + constructor : R3.CustomCode, + apiConstructor : R3.API.CustomCode + }; + case 0x17 : return { + name : 'R3.Mouse', + runtime : R3.Component.DEFAULT_RUNTIME, + constructor : R3.Mouse, + apiConstructor : R3.API.Mouse + }; + case 0x18 : return { + name : 'R3.D3.Skeleton', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Skeleton, + apiConstructor : R3.D3.API.Skeleton + }; + case 0x19 : return { + name : 'R3.D3.Texture.Image', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Texture.Image, + apiConstructor : R3.D3.API.Texture.Image + }; + case 0x1a : return { + name : 'R3.EntityManager', + runtime : R3.Component.DEFAULT_RUNTIME, + constructor : R3.EntityManager, + apiConstructor : R3.API.EntityManager + }; + case 0x1b : return { + name : 'R3.DomElement', + runtime : R3.Component.DEFAULT_RUNTIME, + constructor : R3.DomElement, + apiConstructor : R3.API.DomElement + }; + case 0x1c : return { + name : 'R3.D3.Shadow.Spot', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Shadow.Spot, + apiConstructor : R3.D3.API.Shadow.Spot + }; + case 0x1d : return { + name : 'R3.Stats', + runtime : R3.Component.STATISTICS_RUNTIME, + constructor : R3.Stats, + apiConstructor : R3.API.Stats + }; + case 0x1e : return { + name : 'R3.GUI', + runtime : R3.Component.GUI_RUNTIME, + constructor : R3.GUI, + apiConstructor : R3.API.GUI + }; + case 0x1f : return { + name : 'R3.Image', + runtime : R3.Component.DEFAULT_RUNTIME, + constructor : R3.Image + }; + case 0x20 : return { + name : 'R3.Entity', + runtime : R3.Component.DEFAULT_RUNTIME, + constructor : R3.Entity, + apiConstructor : R3.API.Entity + }; + case 0x21 : return { + name : 'R3.D3.Object', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Object, + apiConstructor : R3.D3.API.Object + }; + case 0x22 : return { + name : 'R3.Renderer.D2', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.Renderer.D2, + apiConstructor : R3.API.Renderer.D2 + }; + case 0x23 : return { + name : 'R3.Renderer.D3', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.Renderer.D3, + apiConstructor : R3.API.Renderer.D3 + }; + case 0x24 : return { + name : 'R3.D3.PhysicsWorld', + runtime : R3.Component.PHYSICS_RUNTIME, + constructor : R3.D3.PhysicsWorld, + apiConstructor : R3.D3.API.PhysicsWorld + }; + case 0x25 : return { + name : 'R3.D3.Broadphase', + runtime : R3.Component.PHYSICS_RUNTIME, + constructor : R3.D3.Broadphase, + apiConstructor : R3.D3.API.Broadphase + }; + case 0x26 : return { + name : 'R3.D3.Solver', + runtime : R3.Component.PHYSICS_RUNTIME, + constructor : R3.D3.Solver, + apiConstructor : R3.D3.API.Solver + }; + case 0x27 : return { + name : 'R3.D3.RigidBody', + runtime : R3.Component.PHYSICS_RUNTIME, + constructor : R3.D3.RigidBody, + apiConstructor : R3.D3.API.RigidBody + }; + case 0x28 : return { + name : 'R3.D3.Shape', + runtime : R3.Component.PHYSICS_RUNTIME, + constructor : R3.D3.Shape, + apiConstructor : R3.D3.API.Shape + }; + case 0x29 : return { + name : 'R3.D3.Shape.Box', + runtime : R3.Component.PHYSICS_RUNTIME, + constructor : R3.D3.Shape.Box, + apiConstructor : R3.D3.API.Shape + }; + case 0x2a : return { + name : 'R3.D3.Shape.Sphere', + runtime : R3.Component.PHYSICS_RUNTIME, + constructor : R3.D3.Shape.Sphere, + apiConstructor : R3.D3.API.Shape + }; + case 0x2b : return { + name : 'R3.D3.Shape.TriMesh', + runtime : R3.Component.PHYSICS_RUNTIME, + constructor : R3.D3.Shape.TriMesh, + apiConstructor : R3.D3.API.Shape + }; + case 0x2c : return { + name : 'R3.D3.Shape.ConvexHull', + runtime : R3.Component.PHYSICS_RUNTIME, + constructor : R3.D3.Shape.ConvexHull, + apiConstructor : R3.D3.API.Shape + }; + case 0x2d : return { + name : 'R3.D3.Shape.ConvexHull.Cylinder', + runtime : R3.Component.PHYSICS_RUNTIME, + constructor : R3.D3.Shape.ConvexHull.Cylinder, + apiConstructor : R3.D3.API.Shape + }; + case 0x2e : return { + name : 'R3.D3.Shape.HeightMap', + runtime : R3.Component.DEFAULT_RUNTIME, + constructor : R3.D3.Shape.HeightMap, + apiConstructor : R3.D3.API.Shape + }; + case 0x2f : return { + name : 'R3.D3.Shape.Plane', + runtime : R3.Component.PHYSICS_RUNTIME, + constructor : R3.D3.Shape.Plane, + apiConstructor : R3.D3.API.Shape + }; + case 0x30 : return { + name : 'R3.Controls', + runtime : R3.Component.DEFAULT_RUNTIME, + constructor : R3.Controls, + apiConstructor : R3.API.Controls + }; + case 0x31 : return { + name : 'R3.Controls.D3.Editor', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.Controls.D3.Editor, + apiConstructor : R3.API.Controls + }; + case 0x32 : return { + name : 'R3.Controls.Touch', + runtime : R3.Component.DEFAULT_RUNTIME, + constructor : R3.Controls.Touch, + apiConstructor : R3.API.Controls + }; + case 0x33 : return { + name : 'R3.D3.FrictionMaterial', + runtime : R3.Component.PHYSICS_RUNTIME, + constructor : R3.D3.FrictionMaterial, + apiConstructor : R3.D3.API.FrictionMaterial + }; + case 0x34 : return { + name : 'R3.D3.FrictionContactMaterial', + runtime : R3.Component.PHYSICS_RUNTIME, + constructor : R3.D3.FrictionContactMaterial, + apiConstructor : R3.D3.API.FrictionContactMaterial + }; + case 0x35 : return { + name : 'R3.D3.RaycastVehicle', + runtime : R3.Component.PHYSICS_RUNTIME, + constructor : R3.D3.RaycastVehicle, + apiConstructor : R3.D3.API.RaycastVehicle + }; + case 0x36 : return { + name : 'R3.D3.RaycastWheel', + runtime : R3.Component.PHYSICS_RUNTIME, + constructor : R3.D3.RaycastWheel, + apiConstructor : R3.D3.API.RaycastWheel + }; + case 0x37 : return { + name : 'R3.Clock', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.Clock, + apiConstructor : R3.API.Clock + }; + case 0x38 : return { + name : 'R3.D3.Animation', + runtime : R3.Component.DEFAULT_RUNTIME, + constructor : R3.D3.Animation, + apiConstructor : R3.D3.API.Animation + }; + case 0x39 : return { + name : 'R3.Controls.Keyboard', + runtime : R3.Component.DEFAULT_RUNTIME, + constructor : R3.Controls.Keyboard, + apiConstructor : R3.API.Controls + }; + case 0x3a : return { + name : 'R3.Controls.Mouse', + runtime : R3.Component.DEFAULT_RUNTIME, + constructor : R3.Controls.Mouse, + apiConstructor : R3.API.Controls + }; + case 0x3b : return { + name : 'R3.GraphicsRuntime.Three', + runtime : R3.Component.DEFAULT_RUNTIME, + constructor : R3.GraphicsRuntime.Three, + apiConstructor : R3.API.GraphicsRuntime.Three + }; + case 0x3c : return { + name : 'R3.D3.Font', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Font, + apiConstructor : R3.D3.API.Font + }; + case 0x3d : return { + name : 'R3.Canvas', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.Canvas, + apiConstructor : R3.API.Canvas + }; + case 0x3e : return { + name : 'R3.D3.Bone', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Bone, + apiConstructor : R3.D3.API.Bone + }; + case 0x3f : return { + name : 'R3.GraphicsRuntime.Impact', + runtime : R3.Component.DEFAULT_RUNTIME, + constructor : R3.GraphicsRuntime.Impact, + apiConstructor : R3.API.GraphicsRuntime.Impact + }; + case 0x40 : return { + name : 'R3.Controls.D3.FirstPerson', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.Controls.D3.FirstPerson, + apiConstructor : R3.API.Controls.D3.FirstPerson + }; + case 0x41 : return { + name : 'R3.System.Animation', + runtime : R3.Component.DEFAULT_RUNTIME, + constructor : R3.System.Animation, + apiConstructor : R3.API.System + }; + case 0x42 : return { + name : 'R3.System.CustomCode', + runtime : R3.Component.DEFAULT_RUNTIME, + constructor : R3.System.CustomCode, + apiConstructor : R3.API.System + }; + case 0x43 : return { + name : 'R3.System.GUI', + runtime : R3.Component.DEFAULT_RUNTIME, + constructor : R3.System.GUI, + apiConstructor : R3.API.System + }; + case 0x44 : return { + name : 'R3.System.Input', + runtime : R3.Component.DEFAULT_RUNTIME, + constructor : R3.System.Input, + apiConstructor : R3.API.System + }; + case 0x45 : return { + name : 'R3.System.Linking', + runtime : R3.Component.DEFAULT_RUNTIME, + constructor : R3.System.Linking, + apiConstructor : R3.API.System + }; + case 0x46 : return { + name : 'R3.System.Physics', + runtime : R3.Component.DEFAULT_RUNTIME, + constructor : R3.System.Physics, + apiConstructor : R3.API.System + }; + case 0x47 : return { + name : 'R3.System.Render', + runtime : R3.Component.DEFAULT_RUNTIME, + constructor : R3.System.Render, + apiConstructor : R3.API.System + }; + case 0x48 : return { + name : 'R3.System.Storage', + runtime : R3.Component.DEFAULT_RUNTIME, + constructor : R3.System.Storage, + apiConstructor : R3.API.System + }; + case 0x49 : return { + name : 'R3.System.Visualization', + runtime : R3.Component.DEFAULT_RUNTIME, + constructor : R3.System.Visualization, + apiConstructor : R3.API.System + }; + case 0x4a : return { + name : 'R3.D3.Light.Ambient', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Light.Ambient, + apiConstructor : R3.D3.API.Light.Ambient + }; + case 0x4b : return { + name : 'R3.D3.Light.Directional', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Light.Directional, + apiConstructor : R3.D3.API.Light.Directional + }; + case 0x4c : return { + name : 'R3.D3.Light.Hemisphere', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Light.Hemisphere, + apiConstructor : R3.D3.API.Light.Hemisphere + }; + case 0x4d : return { + name : 'R3.D3.Light.Point', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Light.Point, + apiConstructor : R3.D3.API.Light.Point + }; + case 0x4e : return { + name : 'R3.D3.Light.RectArea', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Light.RectArea, + apiConstructor : R3.D3.API.Light.RectArea + }; + case 0x4f : return { + name : 'R3.D3.Light.Spot', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Light.Spot, + apiConstructor : R3.D3.API.Light.Spot + }; + case 0x50 : return { + name : 'R3.D3.Fog', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Fog, + apiConstructor : R3.D3.API.Fog + }; + case 0x51 : return { + name : 'R3.Controls.D3.Orbit', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.Controls.D3.Orbit, + apiConstructor : R3.API.Controls.D3.Orbit + }; + case 0x52 : return { + name : 'R3.D3.ParticleEngine', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.ParticleEngine, + apiConstructor : R3.D3.API.ParticleEngine + }; + case 0x53 : return { + name : 'R3.System.Particle', + runtime : R3.Component.DEFAULT_RUNTIME, + constructor : R3.System.Particle, + apiConstructor : R3.API.System + }; + case 0x54 : return { + name : 'R3.D3.Particle', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Particle, + apiConstructor : R3.D3.API.Particle + }; + case 0x55 : return { + name : 'R3.D3.Audio', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Audio, + apiConstructor : R3.D3.API.Audio + }; + case 0x56 : return { + name : 'R3.System.Audio', + runtime : R3.Component.DEFAULT_RUNTIME, + constructor : R3.System.Audio, + apiConstructor : R3.API.System + }; + case 0x57 : return { + name : 'R3.Socket.Cast', + runtime : R3.Component.SOCKET_RUNTIME, + constructor : R3.Socket.Cast, + apiConstructor : R3.API.Socket.Cast + }; + case 0x58 : return { + name : 'R3.D3.Camera.Orthographic', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Camera.Orthographic, + apiConstructor : R3.D3.API.Camera.Orthographic + }; + case 0x59 : return { + name : 'R3.D3.Camera.Stereo', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Camera.Stereo, + apiConstructor : R3.D3.API.Camera.Stereo + }; + case 0x5a : return { + name : 'R3.D3.Camera.Cube', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Camera.Cube, + apiConstructor : R3.D3.API.Camera.Cube + }; + case 0x5b : return { + name : 'R3.D3.Shadow', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Shadow, + apiConstructor : R3.D3.API.Shadow + }; + case 0x5c : return { + name : 'R3.D3.RenderTarget.Cube', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.RenderTarget.Cube, + apiConstructor : R3.D3.API.RenderTarget.Cube + }; + case 0x5d : return { + name : 'R3.D3.Texture.Cube', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Texture.Cube, + apiConstructor : R3.D3.API.Texture.Cube + }; + case 0x5e : return { + name : 'R3.D3.Texture.Canvas', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Texture.Canvas, + apiConstructor : R3.D3.API.Texture.Canvas + }; + case 0x5f : return { + name : 'R3.D3.Effect.Stereo', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Effect.Stereo, + apiConstructor : R3.D3.API.Effect.Stereo + }; + case 0x60 : return { + name : 'R3.D3.Effect.Anaglyph', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Effect.Anaglyph, + apiConstructor : R3.D3.API.Effect.Anaglyph + }; + case 0x61 : return { + name : 'R3.D3.Effect.Parallax', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Effect.Parallax, + apiConstructor : R3.D3.API.Effect.Parallax + }; + case 0x62 : return { + name : 'R3.D3.Pass.SSAO', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Pass.SSAO, + apiConstructor : R3.D3.API.Pass.SSAO + }; + case 0x63 : return { + name : 'R3.D3.Pass.Bloom', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Pass.Bloom, + apiConstructor : R3.D3.API.Pass.Bloom + }; + case 0x64 : return { + name : 'R3.D3.Pass.FXAA', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Pass.FXAA, + apiConstructor : R3.D3.API.Pass.FXAA + }; + case 0x65 : return { + name : 'R3.RenderConfiguration', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.RenderConfiguration, + apiConstructor : R3.API.RenderConfiguration + }; + case 0x66 : return { + name : 'R3.D3.Material.Basic', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Material.Basic, + apiConstructor : R3.D3.API.Material.Basic + }; + case 0x67 : return { + name : 'R3.D3.Texture', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Texture, + apiConstructor : R3.D3.API.Texture + }; + case 0x68 : return { + name : 'R3.D3.Material.Phong', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Material.Phong, + apiConstructor : R3.D3.API.Material.Phong + }; + case 0x69 : return { + name : 'R3.D3.Geometry.Normal', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Geometry.Normal, + apiConstructor : R3.D3.API.Geometry.Normal + }; + case 0x6a : return { + name : 'R3.D3.Geometry.Normal.Box', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Geometry.Normal.Box, + apiConstructor : R3.D3.API.Geometry.Normal.Box + }; + case 0x6b : return { + name : 'R3.D3.Geometry.Normal.Circle', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Geometry.Normal.Circle, + apiConstructor : R3.D3.API.Geometry.Normal.Circle + }; + case 0x6c : return { + name : 'R3.D3.Geometry.Normal.Cone', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Geometry.Normal.Cone, + apiConstructor : R3.D3.API.Geometry.Normal.Cone + }; + case 0x6d : return { + name : 'R3.D3.Geometry.Normal.Cylinder', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Geometry.Normal.Cylinder, + apiConstructor : R3.D3.API.Geometry.Normal.Cylinder + }; + case 0x6e : return { + name : 'R3.D3.Geometry.Normal.Dodecahedron', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Geometry.Normal.Dodecahedron, + apiConstructor : R3.D3.API.Geometry.Normal.Dodecahedron + }; + case 0x6f : return { + name : 'R3.D3.Geometry.Normal.Edges', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Geometry.Normal.Edges, + apiConstructor : R3.D3.API.Geometry.Normal.Edges + }; + case 0x70 : return { + name : 'R3.D3.Geometry.Normal.Extrude', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Geometry.Normal.Extrude, + apiConstructor : R3.D3.API.Geometry.Normal.Extrude + }; + case 0x71 : return { + name : 'R3.D3.Geometry.Normal.Icosahedron', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Geometry.Normal.Icosahedron, + apiConstructor : R3.D3.API.Geometry.Normal.Icosahedron + }; + case 0x72 : return { + name : 'R3.D3.Geometry.Normal.Lathe', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Geometry.Normal.Lathe, + apiConstructor : R3.D3.API.Geometry.Normal.Lathe + }; + case 0x73 : return { + name : 'R3.D3.Geometry.Normal.Octahedron', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Geometry.Normal.Octahedron, + apiConstructor : R3.D3.API.Geometry.Normal.Octahedron + }; + case 0x74 : return { + name : 'R3.D3.Geometry.Normal.Parametric', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Geometry.Normal.Parametric, + apiConstructor : R3.D3.API.Geometry.Normal.Parametric + }; + case 0x75 : return { + name : 'R3.D3.Geometry.Normal.Plane', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Geometry.Normal.Plane, + apiConstructor : R3.D3.API.Geometry.Normal.Plane + }; + case 0x76 : return { + name : 'R3.D3.Geometry.Normal.Polyhedron', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Geometry.Normal.Polyhedron, + apiConstructor : R3.D3.API.Geometry.Normal.Polyhedron + }; + case 0x77 : return { + name : 'R3.D3.Geometry.Normal.Ring', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Geometry.Normal.Ring, + apiConstructor : R3.D3.API.Geometry.Normal.Ring + }; + case 0x78 : return { + name : 'R3.D3.Geometry.Normal.Shape', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Geometry.Normal.Shape, + apiConstructor : R3.D3.API.Geometry.Normal.Shape + }; + case 0x79 : return { + name : 'R3.D3.Geometry.Normal.Sphere', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Geometry.Normal.Sphere, + apiConstructor : R3.D3.API.Geometry.Normal.Sphere + }; + case 0x7a : return { + name : 'R3.D3.Geometry.Normal.Tetrahedron', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Geometry.Normal.Tetrahedron, + apiConstructor : R3.D3.API.Geometry.Normal.Tetrahedron + }; + case 0x7b : return { + name : 'R3.D3.Geometry.Normal.Text', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Geometry.Normal.Text, + apiConstructor : R3.D3.API.Geometry.Normal.Text + }; + case 0x7c : return { + name : 'R3.D3.Geometry.Normal.Torus', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Geometry.Normal.Torus, + apiConstructor : R3.D3.API.Geometry.Normal.Torus + }; + case 0x7d : return { + name : 'R3.D3.Geometry.Normal.TorusKnot', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Geometry.Normal.TorusKnot, + apiConstructor : R3.D3.API.Geometry.Normal.TorusKnot + }; + case 0x7e : return { + name : 'R3.D3.Geometry.Normal.Tube', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Geometry.Normal.Tube, + apiConstructor : R3.D3.API.Geometry.Normal.Tube + }; + case 0x7f : return { + name : 'R3.D3.Geometry.Normal.Wireframe', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Geometry.Normal.Wireframe, + apiConstructor : R3.D3.API.Geometry.Normal.Wireframe + }; + case 0x80 : return { + name : 'R3.D3.Geometry.Buffer', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Geometry.Buffer, + apiConstructor : R3.D3.API.Geometry.Buffer + }; + case 0x81 : return { + name : 'R3.D3.Geometry.Buffer.Box', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Geometry.Buffer.Box, + apiConstructor : R3.D3.API.Geometry.Buffer.Box + }; + case 0x82 : return { + name : 'R3.D3.Geometry.Buffer.Circle', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Geometry.Buffer.Circle, + apiConstructor : R3.D3.API.Geometry.Buffer.Circle + }; + case 0x83 : return { + name : 'R3.D3.Geometry.Buffer.Cone', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Geometry.Buffer.Cone, + apiConstructor : R3.D3.API.Geometry.Buffer.Cone + }; + case 0x84 : return { + name : 'R3.D3.Geometry.Buffer.Cylinder', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Geometry.Buffer.Cylinder, + apiConstructor : R3.D3.API.Geometry.Buffer.Cylinder + }; + case 0x85 : return { + name : 'R3.D3.Geometry.Buffer.Dodecahedron', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Geometry.Buffer.Dodecahedron, + apiConstructor : R3.D3.API.Geometry.Buffer.Dodecahedron + }; + case 0x86 : return { + name : 'R3.D3.Geometry.Buffer.Extrude', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Geometry.Buffer.Extrude, + apiConstructor : R3.D3.API.Geometry.Buffer.Extrude + }; + case 0x87 : return { + name : 'R3.D3.Geometry.Buffer.Icosahedron', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Geometry.Buffer.Icosahedron, + apiConstructor : R3.D3.API.Geometry.Buffer.Icosahedron + }; + case 0x88 : return { + name : 'R3.D3.Geometry.Buffer.Lathe', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Geometry.Buffer.Lathe, + apiConstructor : R3.D3.API.Geometry.Buffer.Lathe + }; + case 0x89 : return { + name : 'R3.D3.Geometry.Buffer.Octahedron', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Geometry.Buffer.Octahedron, + apiConstructor : R3.D3.API.Geometry.Buffer.Octahedron + }; + case 0x8a : return { + name : 'R3.D3.Geometry.Buffer.Parametric', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Geometry.Buffer.Parametric, + apiConstructor : R3.D3.API.Geometry.Buffer.Parametric + }; + case 0x8b : return { + name : 'R3.D3.Geometry.Buffer.Plane', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Geometry.Buffer.Plane, + apiConstructor : R3.D3.API.Geometry.Buffer.Plane + }; + case 0x8c : return { + name : 'R3.D3.Geometry.Buffer.Polyhedron', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Geometry.Buffer.Polyhedron, + apiConstructor : R3.D3.API.Geometry.Buffer.Polyhedron + }; + case 0x8d : return { + name : 'R3.D3.Geometry.Buffer.Ring', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Geometry.Buffer.Ring, + apiConstructor : R3.D3.API.Geometry.Buffer.Ring + }; + case 0x8e : return { + name : 'R3.D3.Geometry.Buffer.Shape', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Geometry.Buffer.Shape, + apiConstructor : R3.D3.API.Geometry.Buffer.Shape + }; + case 0x8f : return { + name : 'R3.D3.Geometry.Buffer.Sphere', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Geometry.Buffer.Sphere, + apiConstructor : R3.D3.API.Geometry.Buffer.Sphere + }; + case 0x90 : return { + name : 'R3.D3.Geometry.Buffer.Tetrahedron', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Geometry.Buffer.Tetrahedron, + apiConstructor : R3.D3.API.Geometry.Buffer.Tetrahedron + }; + case 0x91 : return { + name : 'R3.D3.Geometry.Buffer.Text', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Geometry.Buffer.Text, + apiConstructor : R3.D3.API.Geometry.Buffer.Text + }; + case 0x92 : return { + name : 'R3.D3.Geometry.Buffer.Torus', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Geometry.Buffer.Torus, + apiConstructor : R3.D3.API.Geometry.Buffer.Torus + }; + case 0x93 : return { + name : 'R3.D3.Geometry.Buffer.TorusKnot', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Geometry.Buffer.TorusKnot, + apiConstructor : R3.D3.API.Geometry.Buffer.TorusKnot + }; + case 0x94 : return { + name : 'R3.D3.Geometry.Buffer.Tube', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Geometry.Buffer.Tube, + apiConstructor : R3.D3.API.Geometry.Buffer.Tube + }; + case 0x95 : return { + name : 'R3.D3.Geometry', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Geometry, + apiConstructor : R3.D3.API.Geometry + }; + case 0x96 : return { + name : 'R3.Curve', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.Curve, + apiConstructor : R3.API.Curve + }; + case 0x97 : return { + name : 'R3.Curve.Path', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.Curve.Path, + apiConstructor : R3.API.Curve.Path + }; + case 0x98 : return { + name : 'R3.Curve.Path.D2', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.Curve.Path.D2, + apiConstructor : R3.API.Curve.Path.D2 + }; + case 0x99 : return { + name : 'R3.Curve.Path.D2.Shape', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.Curve.Path.D2.Shape, + apiConstructor : R3.API.Curve.Path.D2.Shape + }; + case 0x9a : return { + name : 'R3.Box3', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.Box3, + apiConstructor : R3.API.Box3 + }; + case 0x9b : return { + name : 'R3.DrawRange', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.DrawRange, + apiConstructor : R3.API.DrawRange + }; + case 0x9c : return { + name : 'R3.Group', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.Group, + apiConstructor : R3.API.Group + }; + case 0x9d : return { + name : 'R3.D3.Material.Shader', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Material.Shader, + apiConstructor : R3.D3.API.Material.Shader + }; + case 0x9e : return { + name : 'R3.D3.Shader', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Shader, + apiConstructor : R3.D3.API.Shader + }; + case 0x9f : return { + name : 'R3.D3.Shader.Vertex', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Shader.Vertex, + apiConstructor : R3.D3.API.Shader.Vertex + }; + case 0xa0 : return { + name : 'R3.D3.Shader.Fragment', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Shader.Fragment, + apiConstructor : R3.D3.API.Shader.Fragment + }; + case 0xa1 : return { + name : 'R3.D3.Geometry.Buffer.Instanced', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Geometry.Buffer.Instanced, + apiConstructor : R3.D3.API.Geometry.Buffer.Instanced + }; + case 0xa2 : return { + name : 'R3.D3.Material.Shader.Raw', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Material.Shader.Raw, + apiConstructor : R3.D3.API.Material.Shader.Raw + }; + case 0xa3 : return { + name : 'R3.D3.Material.Points', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.D3.Material.Points, + apiConstructor : R3.D3.API.Material.Points + }; + break; + } + + throw new Error('Unknown component type: ' + number ); +}; + +/** + * Returns the runtime friendly name + * @param runtime + * @returns {*} + * @constructor + */ +R3.Component.GetRuntimeName = function(runtime) { + + if (runtime === R3.Component.GRAPHICS_RUNTIME) { + return 'Graphics'; + } + + if (runtime === R3.Component.PHYSICS_RUNTIME) { + return 'Physics'; + } + + if (runtime === R3.Component.GUI_RUNTIME) { + return 'GUI'; + } + + if (runtime === R3.Component.STATISTICS_RUNTIME) { + return 'Statistics'; + } + + if (runtime === R3.Component.SOCKET_RUNTIME) { + return 'Sockets'; + } + + if (runtime === R3.Component.CODER_RUNTIME) { + return 'Coder'; + } + + return 'Default'; +}; + +/** + * @return {string} + */ +R3.Component.GetComponentName = function(componentType) { + + var info = R3.Component.GetComponentInfo(componentType); + + if (info) { + return info.name; + } + + return 'unused'; +}; + +/** + * @return {null || Object} + */ +R3.Component.GetComponentRuntime = function(componentType) { + + var info = R3.Component.GetComponentInfo(componentType); + + if (info) { + return info.runtime; + } + return null; +}; + + +/** + * @return {null || Object} + */ +R3.Component.GetComponentConstructor = function(componentType) { + + var info = R3.Component.GetComponentInfo(componentType); + + if (info) { + return info.constructor; + } + + return null; +}; + + +/** + * Components are linked at runtime - for storing, we just store the ID + * @returns {*} + */ +R3.Component.prototype.toApiObject = function() { + + var info = R3.Component.GetComponentInfo(this.componentType); + + var apiConstructor = info.apiConstructor; + + console.warn('implement generic component toApiObject'); + + var parameters = R3.Utils.GetParameters(apiConstructor); + + throw new Error(parameters); + + return this.id; + // return new info.apiConstructor() + +}; + +/** + * Gets all children components of this Object (all linked objects only - no object references i.e. string ids) + * @returns {Array} + */ +R3.Component.prototype.getChildrenComponents = function() { + + var components = []; + + this.buildIdToObject(); + + Object.keys(this.idToObject).map( + function (objectId) { + if (this.id !== objectId) { + components.push(this.idToObject[objectId]); + } + }.bind(this) + ); + + return components; +}; + +R3.Component.prototype.processComponent = function(object) { + if (object instanceof R3.Component) { + + object.buildIdToObject(); + + if (!object.linked) { + this.linked = false; + } + + var idToObject = object.idToObject; + + for (var objectProperty in idToObject) { + if (idToObject.hasOwnProperty(objectProperty)) { + this.idToObject[objectProperty] = idToObject[objectProperty]; + } + } + + if (object.id) { + this.idToObject[object.id] = object; + } else { + console.warn('Object with no ID passed: ' + object) + } + + } else if (typeof object === 'string') { + this.linked = false; + } else { + console.warn('Unhandled type of object: ', object); + } +}; + +/** + * This function - builds an 'id to object' object - which contains the ids which point directly + * to its corresponding object, for all the objects contained inside this object + */ +R3.Component.prototype.buildIdToObject = function() { + + if (this.building) { + return; + } + + /** + * If this component 'building' flag is true - it is in the process of building idToObject up the callstack and the + * caller should know to not try to build idToObject again (prevent infinite recursion) + */ + this.building = true; + + /** + * If any child component is not fully linked, this component will show as not linked + * @type {boolean} + */ + this.linked = true; + + this.idToObject = {}; + + for (var property in this.linkedObjects) { + if ( + this.linkedObjects.hasOwnProperty(property) && + this.hasOwnProperty(property) && + this[property] && + property.indexOf('parent') !== 0 + ) { + + if (this.linkedObjects[property] instanceof Array) { + + /** + * Remove null objects (can happen) + */ + this[property] = this[property].filter( + function (object) { + if (object === null) { + console.log('null object found and removed'); + return false; + } + return true; + } + ); + + this[property].map( + function (object) { + this.processComponent(object); + }.bind(this) + ); + + } else { + this.processComponent(this[property]); + } + } + } + + if (this instanceof R3.D3.Scene) { + if (!this.storeClones) { + this.clones.map( + function (clone) { + if (this.idToObject.hasOwnProperty(clone.id)) { + delete this.idToObject[clone.id]; + } + }.bind(this) + ) + } + } + + this.idToObject[this.id] = this; + + this.building = false; +}; + +R3.Component.prototype.generateNewIds = function() { + + this.buildIdToObject(); + + var codeComponents = R3.EntityManager.Instance.queryComponents(R3.Component.CUSTOM_CODE); + + for (var property in this.idToObject) { + if (this.idToObject.hasOwnProperty(property)) { + + var oldId = this.idToObject[property].id; + var newId = R3.Utils.RandomId(); + + this.idToObject[property].id = newId; + this.idToObject[property].name = this.idToObject[property].name.replace(oldId,newId); + + if (this.generateNewImageIds) { + + // TODO: replace image filenames - but then also copy them server side? + if (this.idToObject[property].fileName) { + this.idToObject[property].fileName = this.idToObject[property].fileName.replace(oldId,newId); + } + } + + codeComponents.map(function(codeComponent){ + codeComponent.code = codeComponent.code.replace(oldId,newId); + }); + } + } + +}; + +/** + * TODO: don't remove components which are still in use elsewhere - this is important to prevent 'register out + * of sync' messages + */ +R3.Component.prototype.remove = function() { + + this.buildIdToObject(); + + Object.keys(this.idToObject).map( + function(componentId){ + R3.Event.Emit( + R3.Event.REMOVE_COMPONENT, + { + component : this.idToObject[componentId] + } + ) + }.bind(this) + ); + +}; + +R3.Component.prototype.replace = function(componentType) { + + var replacement = R3.Component.Construct(componentType); + + R3.Event.Emit( + R3.Event.REPLACE_COMPONENT, + { + current : this, + replacement : replacement + } + ); + + if (this.parentEntity && this.parentEntity.loaded) { + this.parentEntity.addComponent(replacement); + } + + this.remove(); + + R3.Event.Emit( + R3.Event.COMPONENT_REPLACED + ); +}; + + +R3.Component.prototype.clone = function() { + + var apiObject = this.toApiObject(); + + this.cloneNumber += 1; + + apiObject.id = R3.Utils.RandomId(); + + apiObject.name = this.name + ' Clone (' + this.cloneNumber + ')'; + + var runtimeComponent = R3.Component.ConstructFromObject(apiObject); + + runtimeComponent.isClone = true; + + R3.Event.Emit( + R3.Event.COMPONENT_CLONED, + { + parent : this, + component : runtimeComponent + } + ); + + runtimeComponent.parentEntity = null; + + return runtimeComponent; +}; + +/** + * Clones only the instance + */ +R3.Component.prototype.cloneInstance = function() { + + var clone = null; + + if ( + this.instance && + this.instance.clone && + typeof (this.instance.clone === 'function')) { + + clone = this.instance.clone(); + + R3.Event.Emit( + R3.Event.INSTANCE_CLONED, + { + component : this, + instance : clone + } + ) + } + + return clone; +}; + +R3.Component.prototype.saveToRemoteAPI = function() { + this.save(true); +}; + +R3.Component.prototype.save = function(remote) { + + var toSave = []; + var saved = []; + var failed = []; + + this.buildIdToObject(); + + if (this.saveSubscription || this.saveErrorSubscription) { + console.warn('another save is in progress'); + return; + } + + R3.Event.Emit( + R3.Event.SAVING, + { + component: this + } + ); + + this.saveSubscription = R3.Event.Subscribe( + R3.Event.COMPONENT_SAVED, + function(data) { + + saved.push(data.component); + + if (failed.length + saved.length === toSave.length) { + + this.saveSubscription.remove(); + + this.saveSubscription = null; + + this.saveErrorSubscription.remove(); + + this.saveErrorSubscription = null; + + R3.Event.Emit( + R3.Event.DONE_SAVING, + { + failed: failed, + saved: saved + } + ) + } + + }.bind(this) + ); + + this.saveErrorSubscription = R3.Event.Subscribe( + R3.Event.SAVE_COMPONENT_ERROR, + function(data) { + + failed.push(data.component); + + if (failed.length + saved.length === toSave.length) { + + this.saveSubscription.remove(); + + this.saveSubscription = null; + + this.saveErrorSubscription.remove(); + + this.saveErrorSubscription = null; + + R3.Event.Emit( + R3.Event.DONE_SAVING, + { + failed: failed, + saved: saved + } + ) + } + + }.bind(this) + ); + + + + Object.keys(this.idToObject).map( + function(componentId) { + + var component = this.idToObject[componentId]; + + if (this instanceof R3.Entity) { + + /** + * We don't store children objects of entities which are not explicitly defined as children of this entity. + */ + if ( + this.components.indexOf(component) === -1 && + this !== component + ) { + + /** + * We don't want to store this component - but other components may depend on it + */ + console.warn(component.name + ' is being stored because a component depends on it - even though it was not explicitly added to this entity.'); + } + } + + var apiObject = component.toApiObject(); + + toSave.push(apiObject); + + this.publish( + R3.Event.SAVE_COMPONENT, + { + apiObject: apiObject, + remote: remote + }, + function success(result) { + console.log(result); + }, + function error(error) { + console.log(error); + } + ); + + }.bind(this) + ); +}; + +/** + * @return {null|Object} + */ +R3.Component.GetRuntimeObject = function(runtimeInfo) { + + var runtime = null; + + R3.Event.Emit( + R3.Event.GET_RUNTIME, + null, + function(runtimeObject) { + runtime = runtimeObject; + } + ); + + if (runtimeInfo === R3.Component.GRAPHICS_RUNTIME) { + + if (R3.Utils.UndefinedOrNull(runtime.graphics)) { + console.warn('no runtime graphics'); + return null; + } + + return runtime.graphics; + + } else if (runtimeInfo === R3.Component.PHYSICS_RUNTIME) { + + if (R3.Utils.UndefinedOrNull(runtime.physics)) { + console.warn('no runtime physics'); + return null; + } + + return runtime.physics; + + } else if (runtimeInfo === R3.Component.GUI_RUNTIME) { + + if (R3.Utils.UndefinedOrNull(runtime.gui)) { + console.warn('no runtime gui'); + return null; + } + + return runtime.gui; + + } else if (runtimeInfo === R3.Component.SOCKET_RUNTIME) { + + if (R3.Utils.UndefinedOrNull(runtime.sockets)) { + console.warn('no runtime sockets'); + return null; + } + + return runtime.sockets; + + } else if (runtimeInfo === R3.Component.STATISTICS_RUNTIME) { + + if (R3.Utils.UndefinedOrNull(runtime.statistics)) { + console.warn('no runtime statistics'); + return null; + } + + return runtime.statistics; + + } else if (runtimeInfo === R3.Component.DEFAULT_RUNTIME) { + + } else { + console.log('unknown runtime object found : ' + info.runtime); + } + + return null; +}; + +R3.Component.Construct = function(componentType) { + + var info = R3.Component.GetComponentInfo(componentType); + + var componentClass = info.constructor; + + var runtime = R3.Component.GetRuntimeObject(info.runtime); + + if (runtime) { + return new componentClass(runtime); + } else { + return new componentClass(); + } + +}; + +R3.Component.ConstructFromObject = function(rawComponentObject) { + + var runtimeComponent = null; + + // if ( + // rawComponentObject.componentType === 34 && + // rawComponentObject.name.indexOf('Mesh') !== -1 + // ) { + // rawComponentObject.componentType = 7; + // } + + var info = R3.Component.GetComponentInfo(rawComponentObject.componentType); + + var runtime = R3.Component.GetRuntimeObject(info.runtime); + + if (runtime) { + runtimeComponent = new info.constructor(runtime, rawComponentObject); + } else { + runtimeComponent = new info.constructor(rawComponentObject); + } + + return runtimeComponent; +}; \ No newline at end of file diff --git a/src/r3-api-box3.js b/src/r3-api-box3.js new file mode 100644 index 0000000..a16d2fd --- /dev/null +++ b/src/r3-api-box3.js @@ -0,0 +1,45 @@ +/** + * R3.API.Box3 + * @param id + * @param name + * @param parentEntity + * @param min + * @param max + * @constructor + */ +R3.API.Box3 = function ( + id, + name, + parentEntity, + min, + max +) { + if (R3.Utils.UndefinedOrNull(id)) { + id = R3.Utils.RandomId(); + } + this.id = id; + + if (R3.Utils.UndefinedOrNull(name)) { + name = 'Box (' + id + ')'; + } + this.name = name; + + if (R3.Utils.UndefinedOrNull(min)) { + min = new R3.API.Vector3(0,0,0); + } + this.min = min; + + if (R3.Utils.UndefinedOrNull(max)) { + max = new R3.API.Vector3(1,1,1); + } + this.max = max; + + R3.API.Component.call( + this, + R3.Component.BOX3, + parentEntity + ) +}; + +R3.API.Box3.prototype = Object.create(R3.API.Component.prototype); +R3.API.Box3.prototype.constructor = R3.API.Box3; diff --git a/src/game-lib-api-canvas.js b/src/r3-api-canvas.js similarity index 54% rename from src/game-lib-api-canvas.js rename to src/r3-api-canvas.js index d74dcf9..e714e8e 100644 --- a/src/game-lib-api-canvas.js +++ b/src/r3-api-canvas.js @@ -1,5 +1,5 @@ /** - * GameLib.API.Canvas + * R3.API.Canvas * @param id * @param name * @param parentEntity @@ -13,7 +13,7 @@ * @param textBaseline * @constructor */ -GameLib.API.Canvas = function( +R3.API.Canvas = function( id, name, parentEntity, @@ -26,62 +26,62 @@ GameLib.API.Canvas = function( texts, textBaseline ) { - if (GameLib.Utils.UndefinedOrNull(id)) { - id = GameLib.Utils.RandomId(); + if (R3.Utils.UndefinedOrNull(id)) { + id = R3.Utils.RandomId(); } this.id = id; - if (GameLib.Utils.UndefinedOrNull(name)) { + if (R3.Utils.UndefinedOrNull(name)) { name = 'Canvas (' + id + ')'; } this.name = name; - if (GameLib.Utils.UndefinedOrNull(parentTexture)) { + if (R3.Utils.UndefinedOrNull(parentTexture)) { parentTexture = null; } this.parentTexture = parentTexture; - if (GameLib.Utils.UndefinedOrNull(autoUpdateSize)) { + if (R3.Utils.UndefinedOrNull(autoUpdateSize)) { autoUpdateSize = true; } this.autoUpdateSize = autoUpdateSize; - if (GameLib.Utils.UndefinedOrNull(width)) { + if (R3.Utils.UndefinedOrNull(width)) { width = 512; } this.width = width; - if (GameLib.Utils.UndefinedOrNull(height)) { + if (R3.Utils.UndefinedOrNull(height)) { height = 512; } this.height = height; - if (GameLib.Utils.UndefinedOrNull(offset)) { - offset = new GameLib.API.Vector2(0,0); + if (R3.Utils.UndefinedOrNull(offset)) { + offset = new R3.API.Vector2(0,0); } this.offset = offset; - if (GameLib.Utils.UndefinedOrNull(tabIndex)) { + if (R3.Utils.UndefinedOrNull(tabIndex)) { tabIndex = 1; } this.tabIndex = tabIndex; - if (GameLib.Utils.UndefinedOrNull(texts)) { + if (R3.Utils.UndefinedOrNull(texts)) { texts = []; } this.texts = texts; - if (GameLib.Utils.UndefinedOrNull(textBaseline)) { + if (R3.Utils.UndefinedOrNull(textBaseline)) { textBaseline = 'middle'; } this.textBaseline = textBaseline; - GameLib.API.Component.call( + R3.API.Component.call( this, - GameLib.Component.CANVAS, + R3.Component.CANVAS, parentEntity ); }; -GameLib.API.Canvas.prototype = Object.create(GameLib.API.Component.prototype); -GameLib.API.Canvas.prototype.constructor = GameLib.API.Canvas; +R3.API.Canvas.prototype = Object.create(R3.API.Component.prototype); +R3.API.Canvas.prototype.constructor = R3.API.Canvas; diff --git a/src/game-lib-api-clock.js b/src/r3-api-clock.js similarity index 53% rename from src/game-lib-api-clock.js rename to src/r3-api-clock.js index 2118dbd..4a4e902 100644 --- a/src/game-lib-api-clock.js +++ b/src/r3-api-clock.js @@ -5,40 +5,40 @@ * @param name * @param parentEntity */ -GameLib.API.Clock = function( +R3.API.Clock = function( id, name, parentEntity ) { - if (GameLib.Utils.UndefinedOrNull(id)) { - id = GameLib.Utils.RandomId(); + if (R3.Utils.UndefinedOrNull(id)) { + id = R3.Utils.RandomId(); } this.id = id; - if (GameLib.Utils.UndefinedOrNull(name)) { + if (R3.Utils.UndefinedOrNull(name)) { name = 'Clock (' + this.id + ')'; } this.name = name; - GameLib.API.Component.call( + R3.API.Component.call( this, - GameLib.Component.CLOCK, + R3.Component.CLOCK, parentEntity ); }; -GameLib.API.Clock.prototype = Object.create(GameLib.API.Component.prototype); -GameLib.API.Clock.prototype.constructor = GameLib.API.Clock; +R3.API.Clock.prototype = Object.create(R3.API.Component.prototype); +R3.API.Clock.prototype.constructor = R3.API.Clock; /** * Creates an API camera from an Object camera * @param objectClock * @constructor */ -GameLib.API.Clock.FromObject = function(objectClock) { +R3.API.Clock.FromObject = function(objectClock) { - return new GameLib.API.Clock( + return new R3.API.Clock( objectClock.id, objectClock.name, objectClock.parentEntity diff --git a/src/game-lib-api-color.js b/src/r3-api-color.js similarity index 56% rename from src/game-lib-api-color.js rename to src/r3-api-color.js index e1107ff..8fa9e86 100644 --- a/src/game-lib-api-color.js +++ b/src/r3-api-color.js @@ -6,24 +6,24 @@ * @param a * @constructor */ -GameLib.API.Color = function (r, g, b, a) { +R3.API.Color = function (r, g, b, a) { - if (GameLib.Utils.UndefinedOrNull(r)) { + if (R3.Utils.UndefinedOrNull(r)) { r = 1; } this.r = r; - if (GameLib.Utils.UndefinedOrNull(g)) { + if (R3.Utils.UndefinedOrNull(g)) { g = 1; } this.g = g; - if (GameLib.Utils.UndefinedOrNull(b)) { + if (R3.Utils.UndefinedOrNull(b)) { b = 1; } this.b = b; - if (GameLib.Utils.UndefinedOrNull(a)) { + if (R3.Utils.UndefinedOrNull(a)) { a = 0; } this.a = a; @@ -35,13 +35,13 @@ GameLib.API.Color = function (r, g, b, a) { * @param objectColor * @constructor */ -GameLib.API.Color.FromObject = function(objectColor) { +R3.API.Color.FromObject = function(objectColor) { - if (GameLib.Utils.UndefinedOrNull(objectColor)){ + if (R3.Utils.UndefinedOrNull(objectColor)){ objectColor = {}; } - return new GameLib.API.Color( + return new R3.API.Color( objectColor.r, objectColor.g, objectColor.b, diff --git a/src/r3-api-controls-0.js b/src/r3-api-controls-0.js new file mode 100644 index 0000000..c34eca2 --- /dev/null +++ b/src/r3-api-controls-0.js @@ -0,0 +1,115 @@ +/** + * Raw Controls API object + * @param id + * @param controlsType + * @param name + * @param canvas + * @param parentEntity + * @property controlsType + * @constructor + */ +R3.API.Controls = function( + id, + name, + controlsType, + canvas, + parentEntity +) { + if (R3.Utils.UndefinedOrNull(id)) { + id = R3.Utils.RandomId(); + } + this.id = id; + + if (R3.Utils.UndefinedOrNull(controlsType)) { + controlsType = R3.API.Controls.CONTROLS_TYPE_NONE; + } + this.controlsType = controlsType; + + if (R3.Utils.UndefinedOrNull(name)) { + + name = 'Controls'; + + switch (this.controlsType) { + case R3.API.Controls.CONTROLS_TYPE_TOUCH : + name = 'Controls Editor'; + break; + case R3.API.Controls.CONTROLS_TYPE_KEYBOARD : + name = 'Controls Keyboard'; + break; + case R3.API.Controls.CONTROLS_TYPE_MOUSE : + name = 'Controls Mouse'; + break; + case R3.API.Controls.CONTROLS_TYPE_EDITOR : + name = 'Controls Editor'; + break; + case R3.API.Controls.CONTROLS_TYPE_FIRST_PERSON : + name = 'Controls First Person'; + break; + case R3.API.Controls.CONTROLS_TYPE_ORBIT : + name = 'Controls Orbit'; + break; + } + + name += ' (' + this.id + ')'; + } + this.name = name; + + if (R3.Utils.UndefinedOrNull(canvas)) { + canvas = null; + } + this.canvas = canvas; + + R3.API.Component.call( + this, + R3.API.Controls.GetComponentType(this.controlsType), + parentEntity + ); +}; + +R3.API.Controls.prototype = Object.create(R3.API.Component.prototype); +R3.API.Controls.prototype.constructor = R3.API.Controls; + +R3.API.Controls.GetComponentType = function(controlsType) { + + var componentType = null; + + switch (controlsType) { + case R3.API.Controls.CONTROLS_TYPE_NONE : + componentType = R3.Component.CONTROLS; + break; + case R3.API.Controls.CONTROLS_TYPE_TOUCH : + componentType = R3.Component.CONTROLS_TOUCH; + break; + case R3.API.Controls.CONTROLS_TYPE_KEYBOARD : + componentType = R3.Component.CONTROLS_KEYBOARD; + break; + case R3.API.Controls.CONTROLS_TYPE_MOUSE : + componentType = R3.Component.CONTROLS_MOUSE; + break; + case R3.API.Controls.CONTROLS_TYPE_EDITOR : + componentType = R3.Component.CONTROLS_EDITOR; + break; + case R3.API.Controls.CONTROLS_TYPE_ORBIT : + componentType = R3.Component.CONTROLS_ORBIT; + break; + default : + throw new Error('unhandled controls type: ' + controlsType); + break; + } + + return componentType; +}; + +R3.API.Controls.D3 = function() {}; + +/** + * Controls Type + * @type {number} + */ +R3.API.Controls.CONTROLS_TYPE_NONE = 0x0; +R3.API.Controls.CONTROLS_TYPE_TOUCH = 0x1; +R3.API.Controls.CONTROLS_TYPE_KEYBOARD = 0x2; +R3.API.Controls.CONTROLS_TYPE_MOUSE = 0x3; +R3.API.Controls.CONTROLS_TYPE_EDITOR = 0x4; +R3.API.Controls.CONTROLS_TYPE_FIRST_PERSON = 0x5; +R3.API.Controls.CONTROLS_TYPE_ORBIT = 0x6; diff --git a/src/r3-api-controls-d3-editor.js b/src/r3-api-controls-d3-editor.js new file mode 100644 index 0000000..086ef11 --- /dev/null +++ b/src/r3-api-controls-d3-editor.js @@ -0,0 +1,44 @@ +/** + * @param apiControls + * @param raycaster + * @param camera + * @constructor + */ +R3.API.Controls.D3.Editor = function( + apiControls, + raycaster, + camera +) { + + if (R3.Utils.UndefinedOrNull(apiControls)) { + apiControls = { + controlsType : R3.API.Controls.CONTROLS_TYPE_EDITOR + }; + } + + if (R3.Utils.UndefinedOrNull(apiControls.controlsType)) { + apiControls.controlsType = R3.API.Controls.CONTROLS_TYPE_EDITOR; + } + + if (R3.Utils.UndefinedOrNull(raycaster)) { + raycaster = new R3.D3.API.Raycaster(); + } + this.raycaster = raycaster; + + if (R3.Utils.UndefinedOrNull(camera)) { + camera = null; + } + this.camera = camera; + + R3.API.Controls.call( + this, + apiControls.id, + apiControls.name, + apiControls.controlsType, + apiControls.canvas, + apiControls.parentEntity + ); +}; + +R3.API.Controls.D3.Editor.prototype = Object.create(R3.API.Controls.prototype); +R3.API.Controls.D3.Editor.prototype.constructor = R3.API.Controls.D3.Editor; diff --git a/src/game-lib-api-controls-d3-first-person.js b/src/r3-api-controls-d3-first-person.js similarity index 57% rename from src/game-lib-api-controls-d3-first-person.js rename to src/r3-api-controls-d3-first-person.js index 6771d17..6822d19 100644 --- a/src/game-lib-api-controls-d3-first-person.js +++ b/src/r3-api-controls-d3-first-person.js @@ -1,5 +1,5 @@ /** - * GameLib.API.Controls.D3.FirstPerson + * R3.API.Controls.D3.FirstPerson * @param apiControls * @param camera * @param enabled @@ -18,7 +18,7 @@ * @param autoSpeedFactor * @constructor */ -GameLib.API.Controls.D3.FirstPerson = function( +R3.API.Controls.D3.FirstPerson = function( apiControls, camera, enabled, @@ -37,92 +37,92 @@ GameLib.API.Controls.D3.FirstPerson = function( autoSpeedFactor ) { - if (GameLib.Utils.UndefinedOrNull(apiControls)) { + if (R3.Utils.UndefinedOrNull(apiControls)) { apiControls = { - controlsType : GameLib.API.Controls.CONTROLS_TYPE_FIRST_PERSON + controlsType : R3.API.Controls.CONTROLS_TYPE_FIRST_PERSON }; } - if (GameLib.Utils.UndefinedOrNull(apiControls.controlsType)) { - apiControls.controlsType = GameLib.API.Controls.CONTROLS_TYPE_FIRST_PERSON; + if (R3.Utils.UndefinedOrNull(apiControls.controlsType)) { + apiControls.controlsType = R3.API.Controls.CONTROLS_TYPE_FIRST_PERSON; } - if (GameLib.Utils.UndefinedOrNull(camera)) { + if (R3.Utils.UndefinedOrNull(camera)) { camera = null; } this.camera = camera; - if (GameLib.Utils.UndefinedOrNull(enabled)) { + if (R3.Utils.UndefinedOrNull(enabled)) { enabled = true; } this.enabled = enabled; - if (GameLib.Utils.UndefinedOrNull(movementSpeed)) { + if (R3.Utils.UndefinedOrNull(movementSpeed)) { movementSpeed = 1.0; } this.movementSpeed = movementSpeed; - if (GameLib.Utils.UndefinedOrNull(lookSpeed)) { + if (R3.Utils.UndefinedOrNull(lookSpeed)) { lookSpeed = 0.005; } this.lookSpeed = lookSpeed; - if (GameLib.Utils.UndefinedOrNull(lookVertical)) { + if (R3.Utils.UndefinedOrNull(lookVertical)) { lookVertical = true; } this.lookVertical = lookVertical; - if (GameLib.Utils.UndefinedOrNull(autoForward)) { + if (R3.Utils.UndefinedOrNull(autoForward)) { autoForward = false; } this.autoForward = autoForward; - if (GameLib.Utils.UndefinedOrNull(activeLook)) { + if (R3.Utils.UndefinedOrNull(activeLook)) { activeLook = false; } this.activeLook = activeLook; - if (GameLib.Utils.UndefinedOrNull(heightSpeed)) { + if (R3.Utils.UndefinedOrNull(heightSpeed)) { heightSpeed = false; } this.heightSpeed = heightSpeed; - if (GameLib.Utils.UndefinedOrNull(heightCoef)) { + if (R3.Utils.UndefinedOrNull(heightCoef)) { heightCoef = 1.0; } this.heightCoef = heightCoef; - if (GameLib.Utils.UndefinedOrNull(heightMin)) { + if (R3.Utils.UndefinedOrNull(heightMin)) { heightMin = 0.0; } this.heightMin = heightMin; - if (GameLib.Utils.UndefinedOrNull(heightMax)) { + if (R3.Utils.UndefinedOrNull(heightMax)) { heightMax = 1.0; } this.heightMax = heightMax; - if (GameLib.Utils.UndefinedOrNull(constrainVertical)) { + if (R3.Utils.UndefinedOrNull(constrainVertical)) { constrainVertical = false; } this.constrainVertical = constrainVertical; - if (GameLib.Utils.UndefinedOrNull(verticalMin)) { + if (R3.Utils.UndefinedOrNull(verticalMin)) { verticalMin = 0; } this.verticalMin = verticalMin; - if (GameLib.Utils.UndefinedOrNull(verticalMax)) { + if (R3.Utils.UndefinedOrNull(verticalMax)) { verticalMax = Math.PI; } this.verticalMax = verticalMax; - if (GameLib.Utils.UndefinedOrNull(autoSpeedFactor)) { + if (R3.Utils.UndefinedOrNull(autoSpeedFactor)) { autoSpeedFactor = 0; } this.autoSpeedFactor = autoSpeedFactor; - GameLib.API.Controls.call( + R3.API.Controls.call( this, apiControls.id, apiControls.name, @@ -132,5 +132,5 @@ GameLib.API.Controls.D3.FirstPerson = function( ); }; -GameLib.API.Controls.D3.FirstPerson.prototype = Object.create(GameLib.API.Controls.prototype); -GameLib.API.Controls.D3.FirstPerson.prototype.constructor = GameLib.API.Controls.D3.FirstPerson; +R3.API.Controls.D3.FirstPerson.prototype = Object.create(R3.API.Controls.prototype); +R3.API.Controls.D3.FirstPerson.prototype.constructor = R3.API.Controls.D3.FirstPerson; diff --git a/src/game-lib-api-controls-d3-orbit.js b/src/r3-api-controls-d3-orbit.js similarity index 59% rename from src/game-lib-api-controls-d3-orbit.js rename to src/r3-api-controls-d3-orbit.js index d9da8a8..38c39a1 100644 --- a/src/game-lib-api-controls-d3-orbit.js +++ b/src/r3-api-controls-d3-orbit.js @@ -1,5 +1,5 @@ /** - * GameLib.API.Controls.D3.Orbit + * R3.API.Controls.D3.Orbit * @param apiControls * @param camera * @param target @@ -23,7 +23,7 @@ * @param enableKeys * @constructor */ -GameLib.API.Controls.D3.Orbit = function( +R3.API.Controls.D3.Orbit = function( apiControls, camera, target, @@ -43,97 +43,97 @@ GameLib.API.Controls.D3.Orbit = function( enableKeys ) { - if (GameLib.Utils.UndefinedOrNull(apiControls)) { + if (R3.Utils.UndefinedOrNull(apiControls)) { apiControls = { - controlsType : GameLib.API.Controls.CONTROLS_TYPE_ORBIT + controlsType : R3.API.Controls.CONTROLS_TYPE_ORBIT }; } - if (GameLib.Utils.UndefinedOrNull(apiControls.controlsType)) { - apiControls.controlsType = GameLib.API.Controls.CONTROLS_TYPE_ORBIT; + if (R3.Utils.UndefinedOrNull(apiControls.controlsType)) { + apiControls.controlsType = R3.API.Controls.CONTROLS_TYPE_ORBIT; } - if (GameLib.Utils.UndefinedOrNull(camera)) { + if (R3.Utils.UndefinedOrNull(camera)) { camera = null; } this.camera = camera; - if (GameLib.Utils.UndefinedOrNull(target)) { + if (R3.Utils.UndefinedOrNull(target)) { target = null; } this.target = target; - if (GameLib.Utils.UndefinedOrNull(enabled)) { + if (R3.Utils.UndefinedOrNull(enabled)) { enabled = true; } this.enabled = enabled; - if (GameLib.Utils.UndefinedOrNull(minPolarAngle)) { + if (R3.Utils.UndefinedOrNull(minPolarAngle)) { minPolarAngle = 0; } this.minPolarAngle = minPolarAngle; - if (GameLib.Utils.UndefinedOrNull(maxPolarAngle)) { + if (R3.Utils.UndefinedOrNull(maxPolarAngle)) { maxPolarAngle = Math.PI; } this.maxPolarAngle = maxPolarAngle; - if (GameLib.Utils.UndefinedOrNull(enableDamping)) { + if (R3.Utils.UndefinedOrNull(enableDamping)) { enableDamping = false; } this.enableDamping = enableDamping; - if (GameLib.Utils.UndefinedOrNull(dampingFactor)) { + if (R3.Utils.UndefinedOrNull(dampingFactor)) { dampingFactor = 0.25; } this.dampingFactor = dampingFactor; - if (GameLib.Utils.UndefinedOrNull(enableZoom)) { + if (R3.Utils.UndefinedOrNull(enableZoom)) { enableZoom = true; } this.enableZoom = enableZoom; - if (GameLib.Utils.UndefinedOrNull(zoomSpeed)) { + if (R3.Utils.UndefinedOrNull(zoomSpeed)) { zoomSpeed = 1.0; } this.zoomSpeed = zoomSpeed; - if (GameLib.Utils.UndefinedOrNull(enableRotate)) { + if (R3.Utils.UndefinedOrNull(enableRotate)) { enableRotate = true; } this.enableRotate = enableRotate; - if (GameLib.Utils.UndefinedOrNull(rotateSpeed)) { + if (R3.Utils.UndefinedOrNull(rotateSpeed)) { rotateSpeed = 1.0; } this.rotateSpeed = rotateSpeed; - if (GameLib.Utils.UndefinedOrNull(enablePan)) { + if (R3.Utils.UndefinedOrNull(enablePan)) { enablePan = true; } this.enablePan = enablePan; - if (GameLib.Utils.UndefinedOrNull(keyPanSpeed)) { + if (R3.Utils.UndefinedOrNull(keyPanSpeed)) { keyPanSpeed = 7.0; } this.keyPanSpeed = keyPanSpeed; - if (GameLib.Utils.UndefinedOrNull(autoRotate)) { + if (R3.Utils.UndefinedOrNull(autoRotate)) { autoRotate = false; } this.autoRotate = autoRotate; - if (GameLib.Utils.UndefinedOrNull(autoRotateSpeed)) { + if (R3.Utils.UndefinedOrNull(autoRotateSpeed)) { autoRotateSpeed = 2.0; } this.autoRotateSpeed = autoRotateSpeed; - if (GameLib.Utils.UndefinedOrNull(enableKeys)) { + if (R3.Utils.UndefinedOrNull(enableKeys)) { enableKeys = false; } this.enableKeys = enableKeys; - GameLib.API.Controls.call( + R3.API.Controls.call( this, apiControls.id, apiControls.name, @@ -143,5 +143,5 @@ GameLib.API.Controls.D3.Orbit = function( ); }; -GameLib.API.Controls.D3.Orbit.prototype = Object.create(GameLib.API.Controls.prototype); -GameLib.API.Controls.D3.Orbit.prototype.constructor = GameLib.API.Controls.D3.Orbit; +R3.API.Controls.D3.Orbit.prototype = Object.create(R3.API.Controls.prototype); +R3.API.Controls.D3.Orbit.prototype.constructor = R3.API.Controls.D3.Orbit; diff --git a/src/r3-api-controls-keyboard.js b/src/r3-api-controls-keyboard.js new file mode 100644 index 0000000..132fbeb --- /dev/null +++ b/src/r3-api-controls-keyboard.js @@ -0,0 +1,30 @@ +/** + * @param apiControls + * @constructor + */ +R3.API.Controls.Keyboard = function( + apiControls +) { + + if (R3.Utils.UndefinedOrNull(apiControls)) { + apiControls = { + controlsType : R3.API.Controls.CONTROLS_TYPE_KEYBOARD + }; + } + + if (R3.Utils.UndefinedOrNull(apiControls.controlsType)) { + apiControls.controlsType = R3.API.Controls.CONTROLS_TYPE_KEYBOARD; + } + + R3.API.Controls.call( + this, + apiControls.id, + apiControls.name, + apiControls.controlsType, + apiControls.canvas, + apiControls.parentEntity + ); +}; + +R3.API.Controls.Keyboard.prototype = Object.create(R3.API.Controls.prototype); +R3.API.Controls.Keyboard.prototype.constructor = R3.API.Controls.Keyboard; diff --git a/src/r3-api-controls-mouse.js b/src/r3-api-controls-mouse.js new file mode 100644 index 0000000..2b46176 --- /dev/null +++ b/src/r3-api-controls-mouse.js @@ -0,0 +1,31 @@ +/** + * @param apiControls + * @constructor + */ +R3.API.Controls.Mouse = function( + apiControls +) { + + if (R3.Utils.UndefinedOrNull(apiControls)) { + apiControls = { + controlsType : R3.API.Controls.CONTROLS_TYPE_MOUSE + }; + } + + if (R3.Utils.UndefinedOrNull(apiControls.controlsType)) { + apiControls.controlsType = R3.API.Controls.CONTROLS_TYPE_MOUSE; + } + + R3.API.Controls.call( + this, + apiControls.id, + apiControls.name, + apiControls.controlsType, + apiControls.canvas, + apiControls.parentEntity + ); +}; + +R3.API.Controls.Mouse.prototype = Object.create(R3.API.Controls.prototype); +R3.API.Controls.Mouse.prototype.constructor = R3.API.Controls.Mouse; + diff --git a/src/r3-api-controls-touch.js b/src/r3-api-controls-touch.js new file mode 100644 index 0000000..bdedc7f --- /dev/null +++ b/src/r3-api-controls-touch.js @@ -0,0 +1,37 @@ +/** + * @param apiControls + * @param sensitivity + * @constructor + */ +R3.API.Controls.Touch = function( + apiControls, + sensitivity +) { + + if (R3.Utils.UndefinedOrNull(apiControls)) { + apiControls = { + controlsType : R3.API.Controls.CONTROLS_TYPE_TOUCH + }; + } + + if (R3.Utils.UndefinedOrNull(apiControls.controlsType)) { + apiControls.controlsType = R3.API.Controls.CONTROLS_TYPE_TOUCH; + } + + if (R3.Utils.UndefinedOrNull(sensitivity)) { + sensitivity = 5; + } + this.sensitivity = sensitivity; + + R3.API.Controls.call( + this, + apiControls.id, + apiControls.name, + apiControls.controlsType, + apiControls.canvas, + apiControls.parentEntity + ); +}; + +R3.API.Controls.Touch.prototype = Object.create(R3.API.Controls.prototype); +R3.API.Controls.Touch.prototype.constructor = R3.API.Controls.Touch; diff --git a/src/r3-api-curve-a.js b/src/r3-api-curve-a.js new file mode 100644 index 0000000..0c804df --- /dev/null +++ b/src/r3-api-curve-a.js @@ -0,0 +1,89 @@ +/** + * R3.API.Curve + * @param id + * @param name + * @param curveType + * @param parentEntity + * @param arcLenghDivisions + * @constructor + */ +R3.API.Curve = function ( + id, + name, + curveType, + parentEntity, + arcLenghDivisions +) { + + if (R3.Utils.UndefinedOrNull(id)) { + id = R3.Utils.RandomId(); + } + this.id = id; + + if (R3.Utils.UndefinedOrNull(curveType)) { + curveType = R3.API.Curve.CURVE_TYPE_NONE; + } + this.curveType = curveType; + + if (R3.Utils.UndefinedOrNull(name)) { + + switch (this.curveType) { + case R3.API.Curve.CURVE_TYPE_NONE : + name = 'Curve'; + break; + case R3.API.Curve.CURVE_TYPE_PATH : + name = 'Curve Path'; + break; + default: + console.log('no nice name for curve'); + } + + name += ' (' + this.id + ')'; + } + this.name = name; + + if (R3.Utils.UndefinedOrNull(arcLenghDivisions)) { + arcLenghDivisions = 200; + } + this.arcLenghDivisions = arcLenghDivisions; + + R3.API.Component.call( + this, + R3.API.Curve.GetComponentType(this.curveType), + parentEntity + ); +}; + +R3.API.Curve.prototype = Object.create(R3.API.Curve.prototype); +R3.API.Curve.prototype.constructor = R3.API.Curve; + +R3.API.Curve.GetComponentType = function(curveType) { + + var componentType = null; + + switch (curveType) { + case R3.API.Curve.CURVE_TYPE_NONE : + componentType = R3.Component.CURVE; + break; + case R3.API.Curve.CURVE_TYPE_PATH : + componentType = R3.Component.CURVE_PATH; + break; + case R3.API.Curve.CURVE_TYPE_PATH_2D : + componentType = R3.Component.CURVE_PATH_D2; + break; + case R3.API.Curve.CURVE_TYPE_PATH_2D_SHAPE : + componentType = R3.Component.CURVE_PATH_D2_SHAPE; + break; + default : + throw new Error('unhandled curve type'); + } + + return componentType; +}; + +R3.API.Curve.CURVE_TYPE_NONE = 0x0; +R3.API.Curve.CURVE_TYPE_PATH = 0x1; +R3.API.Curve.CURVE_TYPE_PATH_2D = 0x2; +R3.API.Curve.CURVE_TYPE_PATH_2D_SHAPE = 0x3; + + diff --git a/src/r3-api-curve-path-a.js b/src/r3-api-curve-path-a.js new file mode 100644 index 0000000..e1f93a8 --- /dev/null +++ b/src/r3-api-curve-path-a.js @@ -0,0 +1,44 @@ +/** + * R3.API.Curve.Path + * @constructor + * @param apiCurve + * @param curves + * @param autoClose + */ +R3.API.Curve.Path = function ( + apiCurve, + curves, + autoClose +) { + if (R3.Utils.UndefinedOrNull(apiCurve)) { + apiCurve = { + curveType: R3.API.Curve.CURVE_TYPE_PATH + }; + } + + if (R3.Utils.UndefinedOrNull(apiCurve.curveType)) { + apiCurve.curveType = R3.API.Curve.CURVE_TYPE_PATH; + } + + if (R3.Utils.UndefinedOrNull(curves)) { + curves = []; + } + this.curves = curves; + + if (R3.Utils.UndefinedOrNull(autoClose)) { + autoClose = false; + } + this.autoClose = autoClose; + + R3.API.Curve.call( + this, + apiCurve.id, + apiCurve.name, + apiCurve.curveType, + apiCurve.parentEntity, + apiCurve.arcLenghDivisions + ); +}; + +R3.API.Curve.Path.prototype = Object.create(R3.API.Curve.prototype); +R3.API.Curve.Path.prototype.constructor = R3.API.Curve.Path; diff --git a/src/r3-api-curve-path-d2-a.js b/src/r3-api-curve-path-d2-a.js new file mode 100644 index 0000000..e8f1cfc --- /dev/null +++ b/src/r3-api-curve-path-d2-a.js @@ -0,0 +1,35 @@ +/** + * R3.API.Curve.Path.D2 + * @constructor + * @param apiCurvePath + * @param points + */ +R3.API.Curve.Path.D2 = function ( + apiCurvePath, + points +) { + if (R3.Utils.UndefinedOrNull(apiCurvePath)) { + apiCurvePath = { + curveType: R3.API.Curve.CURVE_TYPE_PATH_2D + }; + } + + if (R3.Utils.UndefinedOrNull(apiCurvePath.curveType)) { + apiCurvePath.curveType = R3.API.Curve.CURVE_TYPE_PATH_2D; + } + + if (R3.Utils.UndefinedOrNull(points)) { + points = []; + } + this.points = points; + + R3.API.Curve.Path.call( + this, + apiCurvePath, + apiCurvePath.curves, + apiCurvePath.autoClose + ); +}; + +R3.API.Curve.Path.D2.prototype = Object.create(R3.API.Curve.Path.prototype); +R3.API.Curve.Path.D2.prototype.constructor = R3.API.Curve.Path.D2; diff --git a/src/r3-api-curve-path-d2-shape.js b/src/r3-api-curve-path-d2-shape.js new file mode 100644 index 0000000..bec2134 --- /dev/null +++ b/src/r3-api-curve-path-d2-shape.js @@ -0,0 +1,27 @@ +/** + * R3.API.Curve.Path.D2.Shape + * @constructor + * @param apiCurvePathD2 + */ +R3.API.Curve.Path.D2.Shape = function ( + apiCurvePathD2 +) { + if (R3.Utils.UndefinedOrNull(apiCurvePathD2)) { + apiCurvePathD2 = { + curveType : R3.API.Curve.CURVE_TYPE_PATH_2D_SHAPE + }; + } + + if (R3.Utils.UndefinedOrNull(apiCurvePathD2.curveType)) { + apiCurvePathD2.curveType = R3.API.Curve.CURVE_TYPE_PATH_2D_SHAPE ; + } + + R3.API.Curve.Path.call( + this, + apiCurvePathD2, + apiCurvePathD2.points + ); +}; + +R3.API.Curve.Path.D2.Shape.prototype = Object.create(R3.API.Curve.Path.D2.prototype); +R3.API.Curve.Path.D2.Shape.prototype.constructor = R3.API.Curve.Path.D2.Shape; diff --git a/src/r3-api-custom-code.js b/src/r3-api-custom-code.js new file mode 100644 index 0000000..ad004b4 --- /dev/null +++ b/src/r3-api-custom-code.js @@ -0,0 +1,45 @@ +/** + * Custom Code Component + * @param id + * @param name + * @param eventId + * @param code + * @param parentEntity + * @constructor + */ +R3.API.CustomCode = function ( + id, + name, + eventId, + code, + parentEntity +) { + if (R3.Utils.UndefinedOrNull(id)) { + id = R3.Utils.RandomId(); + } + this.id = id; + + if (R3.Utils.UndefinedOrNull(name)) { + name = 'CustomCode (' + this.id + ')'; + } + this.name = name; + + if (R3.Utils.UndefinedOrNull(eventId)) { + eventId = 42; + } + this.eventId = eventId; + + if (R3.Utils.UndefinedOrNull(code)) { + code = "return null;\n//@ sourceURL=" + this.name + ".js"; + } + this.code = code; + + R3.API.Component.call( + this, + R3.Component.CUSTOM_CODE, + parentEntity + ); +}; + +R3.API.CustomCode.prototype = Object.create(R3.API.Component.prototype); +R3.API.CustomCode.prototype.constructor = R3.API.CustomCode; diff --git a/src/game-lib-api-dom-element.js b/src/r3-api-dom-element.js similarity index 54% rename from src/game-lib-api-dom-element.js rename to src/r3-api-dom-element.js index b55d8c9..5e570ab 100644 --- a/src/game-lib-api-dom-element.js +++ b/src/r3-api-dom-element.js @@ -6,45 +6,45 @@ * @param parentEntity * @constructor */ -GameLib.API.DomElement = function( +R3.API.DomElement = function( id, name, domElementId, parentEntity ) { - if (GameLib.Utils.UndefinedOrNull(id)) { - id = GameLib.Utils.RandomId(); + if (R3.Utils.UndefinedOrNull(id)) { + id = R3.Utils.RandomId(); } this.id = id; - if (GameLib.Utils.UndefinedOrNull(name)) { + if (R3.Utils.UndefinedOrNull(name)) { name = 'DOM Element (' + this.id + ')'; } this.name = name; - if (GameLib.Utils.UndefinedOrNull(domElementId)) { + if (R3.Utils.UndefinedOrNull(domElementId)) { domElementId = ''; } this.domElementId = domElementId; - GameLib.API.Component.call( + R3.API.Component.call( this, - GameLib.Component.DOM_ELEMENT, + R3.Component.DOM_ELEMENT, parentEntity ); }; -GameLib.API.DomElement.prototype = Object.create(GameLib.API.Component.prototype); -GameLib.API.DomElement.prototype.constructor = GameLib.API.DomElement; +R3.API.DomElement.prototype = Object.create(R3.API.Component.prototype); +R3.API.DomElement.prototype.constructor = R3.API.DomElement; /** * Returns an API domElement from an Object domElement * @param objectDomElement * @constructor */ -GameLib.API.DomElement.FromObject = function (objectDomElement) { - return new GameLib.API.DomElement( +R3.API.DomElement.FromObject = function (objectDomElement) { + return new R3.API.DomElement( objectDomElement.id, objectDomElement.name, objectDomElement.domElementId, diff --git a/src/r3-api-draw-range.js b/src/r3-api-draw-range.js new file mode 100644 index 0000000..70516bf --- /dev/null +++ b/src/r3-api-draw-range.js @@ -0,0 +1,45 @@ +/** + * R3.API.Box3 + * @constructor + * @param id + * @param name + * @param parentEntity + * @param start + * @param count + */ +R3.API.DrawRange = function ( + id, + name, + parentEntity, + start, + count +) { + if (R3.Utils.UndefinedOrNull(id)) { + id = R3.Utils.RandomId(); + } + this.id = id; + + if (R3.Utils.UndefinedOrNull(name)) { + name = 'DrawRange (' + id + ')'; + } + this.name = name; + + if (R3.Utils.UndefinedOrNull(start)) { + start = 0; + } + this.start = start; + + if (R3.Utils.UndefinedOrNull(count)) { + count = Infinity; + } + this.count = count; + + R3.API.Component.call( + this, + R3.Component.DRAW_RANGE, + parentEntity + ) +}; + +R3.API.DrawRange.prototype = Object.create(R3.API.Component.prototype); +R3.API.DrawRange.prototype.constructor = R3.API.DrawRange; diff --git a/src/game-lib-api-entity-manager.js b/src/r3-api-entity-manager.js similarity index 55% rename from src/game-lib-api-entity-manager.js rename to src/r3-api-entity-manager.js index 070b5d7..9398d21 100644 --- a/src/game-lib-api-entity-manager.js +++ b/src/r3-api-entity-manager.js @@ -3,61 +3,61 @@ * @constructor * @param id * @param name - * @param entities GameLib.API.Entity[] + * @param entities R3.API.Entity[] * @param defaultEntity * @param parentEntity */ -GameLib.API.EntityManager = function( +R3.API.EntityManager = function( id, name, entities, defaultEntity, parentEntity ) { - if (GameLib.Utils.UndefinedOrNull(id)) { - id = GameLib.Utils.RandomId(); + if (R3.Utils.UndefinedOrNull(id)) { + id = R3.Utils.RandomId(); } this.id = id; - if (GameLib.Utils.UndefinedOrNull(name)) { + if (R3.Utils.UndefinedOrNull(name)) { name = 'Entity Manager (' + this.id + ')'; } this.name = name; - if (GameLib.Utils.UndefinedOrNull(entities)) { + if (R3.Utils.UndefinedOrNull(entities)) { entities = []; } this.entities = entities; - if (GameLib.Utils.UndefinedOrNull(defaultEntity)) { + if (R3.Utils.UndefinedOrNull(defaultEntity)) { defaultEntity = null; } this.defaultEntity = defaultEntity; - GameLib.API.Component.call( + R3.API.Component.call( this, - GameLib.Component.ENTITY_MANAGER, + R3.Component.ENTITY_MANAGER, parentEntity ); }; -GameLib.API.EntityManager.prototype = Object.create(GameLib.API.Component.prototype); -GameLib.API.EntityManager.prototype.constructor = GameLib.API.EntityManager; +R3.API.EntityManager.prototype = Object.create(R3.API.Component.prototype); +R3.API.EntityManager.prototype.constructor = R3.API.EntityManager; /** * Creates an API entity manager from an Object entity manager * @param objectEntityManager * @constructor */ -GameLib.API.EntityManager.FromObject = function(objectEntityManager) { +R3.API.EntityManager.FromObject = function(objectEntityManager) { var apiEntities = objectEntityManager.entities.map( function (objectEntity) { - return GameLib.API.Entity.FromObject(objectEntity); + return R3.API.Entity.FromObject(objectEntity); } ); - return new GameLib.API.EntityManager( + return new R3.API.EntityManager( objectEntityManager.id, objectEntityManager.name, apiEntities, diff --git a/src/game-lib-api-entity.js b/src/r3-api-entity.js similarity index 50% rename from src/game-lib-api-entity.js rename to src/r3-api-entity.js index c1b8f08..8c33190 100644 --- a/src/game-lib-api-entity.js +++ b/src/r3-api-entity.js @@ -2,48 +2,48 @@ * Entity API Object (for storing / loading entities to and from API) * @param id * @param name - * @param components GameLib.Component[] - * @param parentEntity GameLib.Entity + * @param components R3.Component[] + * @param parentEntity R3.Entity * @constructor */ -GameLib.API.Entity = function( +R3.API.Entity = function( id, name, components, parentEntity ) { - if (GameLib.Utils.UndefinedOrNull(id)) { - id = GameLib.Utils.RandomId(); + if (R3.Utils.UndefinedOrNull(id)) { + id = R3.Utils.RandomId(); } this.id = id; - if (GameLib.Utils.UndefinedOrNull(name)) { + if (R3.Utils.UndefinedOrNull(name)) { name = 'Entity (' + this.id + ')'; } this.name = name; - if (GameLib.Utils.UndefinedOrNull(components)) { + if (R3.Utils.UndefinedOrNull(components)) { components = []; } this.components = components; - GameLib.API.Component.call( + R3.API.Component.call( this, - GameLib.Component.ENTITY, + R3.Component.ENTITY, parentEntity ); }; -GameLib.API.Entity.prototype = Object.create(GameLib.API.Component.prototype); -GameLib.API.Entity.prototype.constructor = GameLib.API.Entity; +R3.API.Entity.prototype = Object.create(R3.API.Component.prototype); +R3.API.Entity.prototype.constructor = R3.API.Entity; /** * Returns an API entity from an Object entity * @param objectEntity * @constructor */ -GameLib.API.Entity.FromObject = function(objectEntity) { - return new GameLib.API.Entity( +R3.API.Entity.FromObject = function(objectEntity) { + return new R3.API.Entity( objectEntity.id, objectEntity.name, objectEntity.components, diff --git a/src/r3-api-graphics-runtime-a.js b/src/r3-api-graphics-runtime-a.js new file mode 100644 index 0000000..769621c --- /dev/null +++ b/src/r3-api-graphics-runtime-a.js @@ -0,0 +1,64 @@ +/** + * R3.API.GraphicsRuntime + * @param id + * @param name + * @param graphicsType + * @param parentEntity + * @constructor + */ +R3.API.GraphicsRuntime = function( + id, + name, + graphicsType, + parentEntity +) { + if (R3.Utils.UndefinedOrNull(id)) { + id = R3.Utils.RandomId(); + } + this.id = id; + + if (R3.Utils.UndefinedOrNull(name)) { + name = 'Graphics Runtime (' + id + ')'; + } + this.name = name; + + if (R3.Utils.UndefinedOrNull(graphicsType)) { + graphicsType = null; + } + this.graphicsType = graphicsType; + + R3.API.Component.call( + this, + R3.API.GraphicsRuntime.GetComponentType(this.graphicsType), + parentEntity + ); +}; + +R3.API.GraphicsRuntime.prototype = Object.create(R3.API.Component.prototype); +R3.API.GraphicsRuntime.prototype.constructor = R3.API.GraphicsRuntime; + +R3.API.GraphicsRuntime.GetComponentType = function(graphicsType) { + + var componentType = null; + + switch (graphicsType) { + case R3.API.GraphicsRuntime.GRAPHICS_TYPE_NONE : + componentType = R3.Component.GRAPHICS; + break; + case R3.API.GraphicsRuntime.GRAPHICS_TYPE_THREE_JS : + componentType = R3.Component.GRAPHICS_THREE; + break; + case R3.API.GraphicsRuntime.GRAPHICS_TYPE_IMPACT_JS : + componentType = R3.Component.GRAPHICS_IMPACT; + break; + default: + throw new Error('Invalid graphics type'); + + } + + return componentType; +}; + +R3.API.GraphicsRuntime.GRAPHICS_TYPE_NONE = 0x0; +R3.API.GraphicsRuntime.GRAPHICS_TYPE_THREE_JS = 0x1; +R3.API.GraphicsRuntime.GRAPHICS_TYPE_IMPACT_JS = 0x2; diff --git a/src/r3-api-graphics-runtime-impact.js b/src/r3-api-graphics-runtime-impact.js new file mode 100644 index 0000000..ec62464 --- /dev/null +++ b/src/r3-api-graphics-runtime-impact.js @@ -0,0 +1,30 @@ +/** + * R3.API.GraphicsRuntime.Impact + * @constructor + * @param apiGraphicsRuntime + */ +R3.API.GraphicsRuntime.Impact = function( + apiGraphicsRuntime +) { + if (R3.Utils.UndefinedOrNull(apiGraphicsRuntime)) { + apiGraphicsRuntime = { + graphicsType : R3.API.GraphicsRuntime.GRAPHICS_TYPE_IMPACT_JS + }; + } + + if (R3.Utils.UndefinedOrNull(apiGraphicsRuntime.graphicsType)) { + apiGraphicsRuntime.graphicsType = R3.API.GraphicsRuntime.GRAPHICS_TYPE_IMPACT_JS; + } + + R3.API.GraphicsRuntime.call( + this, + apiGraphicsRuntime.id, + apiGraphicsRuntime.name, + apiGraphicsRuntime.graphicsType, + apiGraphicsRuntime.parentEntity + ); + +}; + +R3.API.GraphicsRuntime.Impact.prototype = Object.create(R3.API.GraphicsRuntime.prototype); +R3.API.GraphicsRuntime.Impact.prototype.constructor = R3.API.GraphicsRuntime.Impact; diff --git a/src/r3-api-graphics-runtime-three.js b/src/r3-api-graphics-runtime-three.js new file mode 100644 index 0000000..a91d5ea --- /dev/null +++ b/src/r3-api-graphics-runtime-three.js @@ -0,0 +1,30 @@ +/** + * R3.API.GraphicsRuntime.Three + * @constructor + * @param apiGraphicsRuntime + */ +R3.API.GraphicsRuntime.Three = function( + apiGraphicsRuntime +) { + if (R3.Utils.UndefinedOrNull(apiGraphicsRuntime)) { + apiGraphicsRuntime = { + graphicsType : R3.API.GraphicsRuntime.GRAPHICS_TYPE_THREE_JS + }; + } + + if (R3.Utils.UndefinedOrNull(apiGraphicsRuntime.graphicsType)) { + apiGraphicsRuntime.graphicsType = R3.API.GraphicsRuntime.GRAPHICS_TYPE_THREE_JS; + } + + R3.API.GraphicsRuntime.call( + this, + apiGraphicsRuntime.id, + apiGraphicsRuntime.name, + apiGraphicsRuntime.graphicsType, + apiGraphicsRuntime.parentEntity + ); + +}; + +R3.API.GraphicsRuntime.Three.prototype = Object.create(R3.API.GraphicsRuntime.prototype); +R3.API.GraphicsRuntime.Three.prototype.constructor = R3.API.GraphicsRuntime.Three; diff --git a/src/r3-api-group.js b/src/r3-api-group.js new file mode 100644 index 0000000..6d0dd7e --- /dev/null +++ b/src/r3-api-group.js @@ -0,0 +1,52 @@ +/** + * R3.API.Group + * @constructor + * @param id + * @param name + * @param parentEntity + * @param start + * @param count + * @param materialIndex + */ +R3.API.Group = function ( + id, + name, + parentEntity, + start, + count, + materialIndex +) { + if (R3.Utils.UndefinedOrNull(id)) { + id = R3.Utils.RandomId(); + } + this.id = id; + + if (R3.Utils.UndefinedOrNull(name)) { + name = 'Group (' + id + ')'; + } + this.name = name; + + if (R3.Utils.UndefinedOrNull(start)) { + start = 0; + } + this.start = start; + + if (R3.Utils.UndefinedOrNull(count)) { + count = 0; + } + this.count = count; + + if (R3.Utils.UndefinedOrNull(materialIndex)) { + materialIndex = 0; + } + this.materialIndex = materialIndex; + + R3.API.Component.call( + this, + R3.Component.GROUP, + parentEntity + ) +}; + +R3.API.Group.prototype = Object.create(R3.API.Component.prototype); +R3.API.Group.prototype.constructor = R3.API.Group; diff --git a/src/game-lib-api-gui.js b/src/r3-api-gui.js similarity index 58% rename from src/game-lib-api-gui.js rename to src/r3-api-gui.js index be420a5..2e6277f 100644 --- a/src/game-lib-api-gui.js +++ b/src/r3-api-gui.js @@ -6,55 +6,55 @@ * @param parentEntity * @constructor */ -GameLib.API.GUI = function( +R3.API.GUI = function( id, name, domElement, parentEntity ) { - if (GameLib.Utils.UndefinedOrNull(id)) { - id = GameLib.Utils.RandomId(); + if (R3.Utils.UndefinedOrNull(id)) { + id = R3.Utils.RandomId(); } this.id = id; - if (GameLib.Utils.UndefinedOrNull(name)) { + if (R3.Utils.UndefinedOrNull(name)) { name = 'GUI (' + this.id + ')'; } this.name = name; - if (GameLib.Utils.UndefinedOrNull(domElement)) { + if (R3.Utils.UndefinedOrNull(domElement)) { domElement = null; } this.domElement = domElement; - GameLib.API.Component.call( + R3.API.Component.call( this, - GameLib.Component.GUI, + R3.Component.GUI, parentEntity ); }; -GameLib.API.GUI.prototype = Object.create(GameLib.API.Component.prototype); -GameLib.API.GUI.prototype.constructor = GameLib.API.GUI; +R3.API.GUI.prototype = Object.create(R3.API.Component.prototype); +R3.API.GUI.prototype.constructor = R3.API.GUI; /** * Creates an API GUI from an Object GUI * @param objectGUI * @constructor */ -GameLib.API.GUI.FromObject = function(objectGUI) { +R3.API.GUI.FromObject = function(objectGUI) { var apiDomElement = null; if (objectGUI.domElement) { if (objectGUI.domElement instanceof Object) { - apiDomElement = GameLib.API.DomElement.FromObject(objectGUI.domElement); + apiDomElement = R3.API.DomElement.FromObject(objectGUI.domElement); } else { apiDomElement = objectGUI.domElement; } } - return new GameLib.API.GUI( + return new R3.API.GUI( objectGUI.id, objectGUI.name, apiDomElement, diff --git a/src/game-lib-api-image.js b/src/r3-api-image.js similarity index 60% rename from src/game-lib-api-image.js rename to src/r3-api-image.js index 2833113..87a6a9e 100644 --- a/src/game-lib-api-image.js +++ b/src/r3-api-image.js @@ -1,5 +1,5 @@ /** - * GameLib.API.Image + * R3.API.Image * @param id * @param name * @param parentEntity @@ -13,7 +13,7 @@ * @param height * @constructor */ -GameLib.API.Image = function( +R3.API.Image = function( id, name, parentEntity, @@ -26,37 +26,37 @@ GameLib.API.Image = function( width, height ) { - if (GameLib.Utils.UndefinedOrNull(id)) { - id = GameLib.Utils.RandomId(); + if (R3.Utils.UndefinedOrNull(id)) { + id = R3.Utils.RandomId(); } this.id = id; - if (GameLib.Utils.UndefinedOrNull(name)) { + if (R3.Utils.UndefinedOrNull(name)) { name = 'Image ' + id; } this.name = name; - if (GameLib.Utils.UndefinedOrNull(parentTexture)) { + if (R3.Utils.UndefinedOrNull(parentTexture)) { parentTexture = null; } this.parentTexture = parentTexture; - if (GameLib.Utils.UndefinedOrNull(fileName)) { - fileName = GameLib.Utils.LowerUnderscore(name); + if (R3.Utils.UndefinedOrNull(fileName)) { + fileName = R3.Utils.LowerUnderscore(name); } this.fileName = fileName; - if (GameLib.Utils.UndefinedOrNull(extension)) { + if (R3.Utils.UndefinedOrNull(extension)) { extension = '.unknown'; } this.extension = extension; - if (GameLib.Utils.UndefinedOrNull(path)) { + if (R3.Utils.UndefinedOrNull(path)) { path = '/'; } this.path = path; - if (GameLib.Utils.UndefinedOrNull(contentType)) { + if (R3.Utils.UndefinedOrNull(contentType)) { contentType = 'application/octet-stream'; @@ -74,27 +74,27 @@ GameLib.API.Image = function( } this.contentType = contentType; - if (GameLib.Utils.UndefinedOrNull(size)) { + if (R3.Utils.UndefinedOrNull(size)) { size = 0; } this.size = size; - if (GameLib.Utils.UndefinedOrNull(width)) { + if (R3.Utils.UndefinedOrNull(width)) { width = 0; } this.width = width; - if (GameLib.Utils.UndefinedOrNull(height)) { + if (R3.Utils.UndefinedOrNull(height)) { height = 0; } this.height = height; - GameLib.API.Component.call( + R3.API.Component.call( this, - GameLib.Component.IMAGE, + R3.Component.IMAGE, parentEntity ); }; -GameLib.API.Image.prototype = Object.create(GameLib.API.Component.prototype); -GameLib.API.Image.prototype.constructor = GameLib.API.Image; +R3.API.Image.prototype = Object.create(R3.API.Component.prototype); +R3.API.Image.prototype.constructor = R3.API.Image; diff --git a/src/r3-api-matrix4.js b/src/r3-api-matrix4.js new file mode 100644 index 0000000..a7db1d5 --- /dev/null +++ b/src/r3-api-matrix4.js @@ -0,0 +1,159 @@ +/** + * Api Matrix 4 + * @param row0 R3.API.Vector4 + * @param row1 R3.API.Vector4 + * @param row2 R3.API.Vector4 + * @param row3 R3.API.Vector4 + * @constructor + */ +R3.API.Matrix4 = function ApiMatrix4( + row0, + row1, + row2, + row3 +) { + this.rows = []; + + if (R3.Utils.UndefinedOrNull(row0)) { + row0 = new R3.API.Vector4(1, 0, 0, 0); + } + this.rows[0] = row0; + + if (R3.Utils.UndefinedOrNull(row1)) { + row1 = new R3.API.Vector4(0, 1, 0, 0); + } + this.rows[1] = row1; + + if (R3.Utils.UndefinedOrNull(row2)) { + row2 = new R3.API.Vector4(0, 0, 1, 0); + } + this.rows[2] = row2; + + if (R3.Utils.UndefinedOrNull(row3)) { + row3 = new R3.API.Vector4(0, 0, 0, 1); + } + this.rows[3] = row3; + + this.temp = []; + this.temp.push( + new R3.API.Vector4() + ); + + this.temp.push( + new R3.API.Vector4() + ); + + this.temp.push( + new R3.API.Vector4() + ); + + this.temp.push( + new R3.API.Vector4() + ); + + this.forward = new R3.API.Vector4(); + this.left = new R3.API.Vector4(); + this.up = new R3.API.Vector4(); +}; + +/** + * Returns an API matrix from an Object matrix + * @param objectMatrix + * @constructor + */ +R3.API.Matrix4.FromObject = function(objectMatrix) { + + if (objectMatrix.rows) { + return new R3.API.Matrix4( + R3.API.Vector4.FromObject(objectMatrix.rows[0]), + R3.API.Vector4.FromObject(objectMatrix.rows[1]), + R3.API.Vector4.FromObject(objectMatrix.rows[2]), + R3.API.Vector4.FromObject(objectMatrix.rows[3]) + ); + } else if (objectMatrix instanceof Array) { + return new R3.API.Matrix4( + R3.API.Vector4.FromObject(objectMatrix[0]), + R3.API.Vector4.FromObject(objectMatrix[1]), + R3.API.Vector4.FromObject(objectMatrix[2]), + R3.API.Vector4.FromObject(objectMatrix[3]) + ); + } else { + console.warn('Unsupported object matrix type - whats your DB version?'); + throw new Error('Unsupported object matrix type - whats your DB version?'); + } +}; + +R3.API.Matrix4.prototype.rotationMatrixX = function (radians) { + this.identity(); + this.rows[1] = new R3.API.Vector4(0, Math.cos(radians), -1 * Math.sin(radians), 0); + this.rows[2] = new R3.API.Vector4(0, Math.sin(radians), Math.cos(radians), 0); + return this; +}; + +R3.API.Matrix4.prototype.rotationMatrixY = function (radians) { + this.identity(); + this.rows[0] = new R3.API.Vector4( + Math.cos(radians), + 0, + Math.sin(radians), + 0 + ); + this.rows[2] = new R3.API.Vector4( + -1 * Math.sin(radians), + 0, + Math.cos(radians), + 0 + ); + return this; +}; + +R3.API.Matrix4.prototype.rotationMatrixZ = function (radians) { + this.identity(); + this.rows[0] = new R3.API.Vector4(Math.cos(radians), -1 * Math.sin(radians), 0, 0); + this.rows[1] = new R3.API.Vector4(Math.sin(radians), Math.cos(radians), 0, 0); + return this; +}; + +R3.API.Matrix4.prototype.rotateX = function (radians, point) { + this.identity(); + this.rotationMatrixX(radians); + return this.multiply(point); +}; + +R3.API.Matrix4.prototype.rotateY = function (radians, point) { + this.identity(); + this.rotationMatrixY(radians); + return this.multiply(point); +}; + +R3.API.Matrix4.prototype.rotateZ = function (radians, point) { + this.identity(); + this.rotationMatrixZ(radians); + return this.multiply(point); +}; + +R3.API.Matrix4.prototype.multiply = function (mvp) { + if (mvp instanceof R3.API.Quaternion || mvp instanceof R3.API.Vector4) { + return new R3.API.Quaternion( + this.rows[0].x * mvp.x + this.rows[0].y * mvp.y + this.rows[0].z * mvp.z + this.rows[0].w * mvp.w, + this.rows[1].x * mvp.x + this.rows[1].y * mvp.y + this.rows[1].z * mvp.z + this.rows[1].w * mvp.w, + this.rows[2].x * mvp.x + this.rows[2].y * mvp.y + this.rows[2].z * mvp.z + this.rows[2].w * mvp.w, + this.rows[3].x * mvp.x + this.rows[3].y * mvp.y + this.rows[3].z * mvp.z + this.rows[3].w * mvp.w + ); + } else if (mvp instanceof R3.API.Vector3) { + return new R3.API.Vector3( + this.rows[0].x * mvp.x + this.rows[0].y * mvp.y + this.rows[0].z * mvp.z, + this.rows[1].x * mvp.x + this.rows[1].y * mvp.y + this.rows[1].z * mvp.z, + this.rows[2].x * mvp.x + this.rows[2].y * mvp.y + this.rows[2].z * mvp.z + ); + } +}; + +R3.API.Matrix4.prototype.identity = function () { + this.rows = [ + new R3.API.Vector4(1, 0, 0, 0), + new R3.API.Vector4(0, 1, 0, 0), + new R3.API.Vector4(0, 0, 1, 0), + new R3.API.Vector4(0, 0, 0, 1) + ]; +}; diff --git a/src/r3-api-mouse.js b/src/r3-api-mouse.js new file mode 100644 index 0000000..ebe6f49 --- /dev/null +++ b/src/r3-api-mouse.js @@ -0,0 +1,45 @@ +/** + * API Mouse + * @param id + * @param name + * @param parentEntity + * @param x + * @param y + * @constructor + */ +R3.API.Mouse = function( + id, + name, + parentEntity, + x, + y +) { + if (R3.Utils.UndefinedOrNull(id)) { + id = R3.Utils.RandomId(); + } + this.id = id; + + if (R3.Utils.UndefinedOrNull(name)) { + name = 'Mouse (' + this.id + ')'; + } + this.name = name; + + if (R3.Utils.UndefinedOrNull(x)) { + x = 0; + } + this.x = x; + + if (R3.Utils.UndefinedOrNull(y)) { + y = 0; + } + this.y = y; + + R3.API.Component.call( + this, + R3.Component.MOUSE, + parentEntity + ); +}; + +R3.API.Mouse.prototype = Object.create(R3.API.Component.prototype); +R3.API.Mouse.prototype.constructor = R3.API.Mouse; diff --git a/src/game-lib-api-number.js b/src/r3-api-number.js similarity index 56% rename from src/game-lib-api-number.js rename to src/r3-api-number.js index 0857828..a22e60f 100644 --- a/src/game-lib-api-number.js +++ b/src/r3-api-number.js @@ -1,33 +1,33 @@ /** - * GameLib.API.Number + * R3.API.Number * @constructor * @param value * @param grain * @param min * @param max */ -GameLib.API.Number = function ( +R3.API.Number = function ( value, grain, min, max ) { - if (GameLib.Utils.UndefinedOrNull(value)) { + if (R3.Utils.UndefinedOrNull(value)) { value = 0; } this.value = value; - if (GameLib.Utils.UndefinedOrNull(grain)) { + if (R3.Utils.UndefinedOrNull(grain)) { grain = 0.1; } this.grain = grain; - if (GameLib.Utils.UndefinedOrNull(min)) { + if (R3.Utils.UndefinedOrNull(min)) { min = 0; } this.min = min; - if (GameLib.Utils.UndefinedOrNull(max)) { + if (R3.Utils.UndefinedOrNull(max)) { max = 100; } this.max = max; diff --git a/src/r3-api-plane.js b/src/r3-api-plane.js new file mode 100644 index 0000000..d6257a1 --- /dev/null +++ b/src/r3-api-plane.js @@ -0,0 +1,53 @@ +R3.API.Plane = function ( + id, + name, + normal, + constant, + parentEntity +) { + + if (R3.Utils.UndefinedOrNull(id)) { + id = R3.Utils.RandomId(); + } + this.id = id; + + if (R3.Utils.UndefinedOrNull(name)) { + name = 'Plane (' + this.id + ')'; + } + this.name = name; + + if (R3.Utils.UndefinedOrNull(normal)) { + normal = new R3.API.Vector3(1,0,0); + } + this.normal = normal; + + if (R3.Utils.UndefinedOrNull(constant)) { + constant = 0; + } + this.constant = constant; + + R3.API.Component.call( + this, + R3.Component.PLANE, + parentEntity + ); +}; + + +R3.API.Plane.prototype = Object.create(R3.API.Component.prototype); +R3.API.Plane.prototype.constructor = R3.API.Plane; + +/** + * Returns an API vector from an Object vector + * @param objectPlane + * @constructor + */ +R3.API.Plane.FromObject = function (objectPlane) { + return new R3.API.Plane( + objectPlane.id, + objectPlane.name, + R3.API.Vector3.FromObject(objectPlane.normal), + objectPlane.constant, + objectPlane.parentEntity + ); +}; diff --git a/src/game-lib-api-quaternion-a.js b/src/r3-api-quaternion-a.js similarity index 70% rename from src/game-lib-api-quaternion-a.js rename to src/r3-api-quaternion-a.js index 5f67d87..5a35d23 100644 --- a/src/game-lib-api-quaternion-a.js +++ b/src/r3-api-quaternion-a.js @@ -8,7 +8,7 @@ * @param angle * @constructor */ -GameLib.API.Quaternion = function ( +R3.API.Quaternion = function ( x, y, z, @@ -17,46 +17,46 @@ GameLib.API.Quaternion = function ( angle ) { - if (GameLib.Utils.UndefinedOrNull(x)) { + if (R3.Utils.UndefinedOrNull(x)) { x = 0; } this.x = x; - if (GameLib.Utils.UndefinedOrNull(y)) { + if (R3.Utils.UndefinedOrNull(y)) { y = 0; } this.y = y; - if (GameLib.Utils.UndefinedOrNull(z)) { + if (R3.Utils.UndefinedOrNull(z)) { z = 0; } this.z = z; - if (GameLib.Utils.UndefinedOrNull(w)) { + if (R3.Utils.UndefinedOrNull(w)) { w = 1; } this.w = w; - if (GameLib.Utils.UndefinedOrNull(axis)) { - axis = new GameLib.API.Vector3(); + if (R3.Utils.UndefinedOrNull(axis)) { + axis = new R3.API.Vector3(); } this.axis = axis; - if (GameLib.Utils.UndefinedOrNull(angle)) { + if (R3.Utils.UndefinedOrNull(angle)) { angle = 0; } this.angle = angle; }; -GameLib.API.Quaternion.prototype.translate = function (v) { +R3.API.Quaternion.prototype.translate = function (v) { this.x += v.x; this.y += v.y; this.z += v.z; return this; }; -GameLib.API.Quaternion.prototype.copy = function () { - return new GameLib.API.Quaternion( +R3.API.Quaternion.prototype.copy = function () { + return new R3.API.Quaternion( this.x, this.y, this.z, @@ -67,7 +67,7 @@ GameLib.API.Quaternion.prototype.copy = function () { /** * Note, this normalize function leaves 'w' component untouched */ -GameLib.API.Quaternion.prototype.normalize = function () { +R3.API.Quaternion.prototype.normalize = function () { var EPSILON = 0.000001; @@ -84,13 +84,13 @@ GameLib.API.Quaternion.prototype.normalize = function () { this.z *= invLength; }; -GameLib.API.Quaternion.prototype.multiply = function (q) { +R3.API.Quaternion.prototype.multiply = function (q) { var x, y, z, w; var a = q; var b = this; - if (q instanceof GameLib.API.Matrix4) { + if (q instanceof R3.API.Matrix4) { x = a.rows[0].x * b.x + a.rows[0].y * b.y + a.rows[0].z * b.z + a.rows[0].w * b.w; y = a.rows[1].x * b.x + a.rows[1].y * b.y + a.rows[1].z * b.z + a.rows[1].w * b.w; @@ -104,7 +104,7 @@ GameLib.API.Quaternion.prototype.multiply = function (q) { return this; - } else if (q instanceof GameLib.API.Quaternion) { + } else if (q instanceof R3.API.Quaternion) { x = ((a.x * b.x) - (a.y * b.y) - (a.z * b.z) - (a.w * a.w)); y = ((a.x * b.y) + (a.y * b.x) - (a.z * b.w) + (a.w * a.z)); @@ -124,7 +124,7 @@ GameLib.API.Quaternion.prototype.multiply = function (q) { } }; -GameLib.API.Quaternion.prototype.setFromAngle = function (angle) { +R3.API.Quaternion.prototype.setFromAngle = function (angle) { this.instance.setFromAxisAngle(this.axis.instance, angle); @@ -136,15 +136,15 @@ GameLib.API.Quaternion.prototype.setFromAngle = function (angle) { return this; }; -GameLib.API.Quaternion.prototype.subtract = function (v) { +R3.API.Quaternion.prototype.subtract = function (v) { - if (v instanceof GameLib.API.Vector3) { + if (v instanceof R3.API.Vector3) { this.x -= v.x; this.y -= v.y; this.z -= v.z; } - if (v instanceof GameLib.API.Quaternion) { + if (v instanceof R3.API.Quaternion) { this.x -= v.x; this.y -= v.y; this.z -= v.z; @@ -154,7 +154,7 @@ GameLib.API.Quaternion.prototype.subtract = function (v) { return this; }; -GameLib.API.Quaternion.prototype.magnitude = function () { +R3.API.Quaternion.prototype.magnitude = function () { return Math.sqrt( (this.x * this.x) + (this.y * this.y) + @@ -163,7 +163,7 @@ GameLib.API.Quaternion.prototype.magnitude = function () { ); }; -GameLib.API.Quaternion.prototype.normalize = function () { +R3.API.Quaternion.prototype.normalize = function () { var magnitude = this.magnitude(); @@ -181,9 +181,9 @@ GameLib.API.Quaternion.prototype.normalize = function () { /** * - * @param matrix4 GameLib.Matrix4 + * @param matrix4 R3.Matrix4 */ -GameLib.API.Quaternion.prototype.setFromRotationMatrix = function(matrix4) { +R3.API.Quaternion.prototype.setFromRotationMatrix = function(matrix4) { this.instance.setFromRotationMatrix(matrix4.instance); @@ -195,11 +195,11 @@ GameLib.API.Quaternion.prototype.setFromRotationMatrix = function(matrix4) { /** * - * @param quaternion GameLib.Quaternion + * @param quaternion R3.Quaternion * @param t - * @returns {GameLib.Quaternion} + * @returns {R3.Quaternion} */ -GameLib.API.Quaternion.prototype.slerp = function (quaternion, t) { +R3.API.Quaternion.prototype.slerp = function (quaternion, t) { this.updateInstance(); @@ -218,15 +218,15 @@ GameLib.API.Quaternion.prototype.slerp = function (quaternion, t) { * @param objectQuaternion * @constructor */ -GameLib.API.Quaternion.FromObject = function (objectQuaternion) { +R3.API.Quaternion.FromObject = function (objectQuaternion) { var apiAxis = null; if (objectQuaternion.axis) { - apiAxis = GameLib.API.Vector3.FromObject(objectQuaternion.axis); + apiAxis = R3.API.Vector3.FromObject(objectQuaternion.axis); } - return new GameLib.API.Quaternion( + return new R3.API.Quaternion( objectQuaternion.x, objectQuaternion.y, objectQuaternion.z, diff --git a/src/game-lib-api-quaternion-points.js b/src/r3-api-quaternion-points.js similarity index 75% rename from src/game-lib-api-quaternion-points.js rename to src/r3-api-quaternion-points.js index d7d45a1..5dd94bb 100644 --- a/src/game-lib-api-quaternion-points.js +++ b/src/r3-api-quaternion-points.js @@ -1,11 +1,11 @@ -GameLib.API.Quaternion.Points = function () { +R3.API.Quaternion.Points = function () { this.vectors = []; }; -GameLib.API.Quaternion.Points.prototype.add = function (vector) { +R3.API.Quaternion.Points.prototype.add = function (vector) { - if (vector instanceof GameLib.API.Vector3) { - vector = new GameLib.API.Quaternion( + if (vector instanceof R3.API.Vector3) { + vector = new R3.API.Quaternion( vector.x, vector.y, vector.z, @@ -13,7 +13,7 @@ GameLib.API.Quaternion.Points.prototype.add = function (vector) { ) } - if (!vector instanceof GameLib.API.Quaternion) { + if (!vector instanceof R3.API.Quaternion) { console.warn("Vector needs to be of type Quaternion"); throw new Error("Vector needs to be of type Quaternion"); } @@ -23,7 +23,7 @@ GameLib.API.Quaternion.Points.prototype.add = function (vector) { return this; }; -GameLib.API.Quaternion.Points.prototype.copy = function () { +R3.API.Quaternion.Points.prototype.copy = function () { var vectors = []; @@ -34,13 +34,13 @@ GameLib.API.Quaternion.Points.prototype.copy = function () { return vectors; }; -GameLib.API.Quaternion.Points.prototype.maximizeXDistance = function (grain) { +R3.API.Quaternion.Points.prototype.maximizeXDistance = function (grain) { // console.log("vectors (before): " + JSON.stringify(this.vectors, null, 2)); var multiplier = 0; - var rotationMatrixY = new GameLib.API.Matrix4().rotationMatrixY(grain); + var rotationMatrixY = new R3.API.Matrix4().rotationMatrixY(grain); var totalRadians = 0; @@ -69,7 +69,7 @@ GameLib.API.Quaternion.Points.prototype.maximizeXDistance = function (grain) { // console.log("distance: " + maxXDistance + " radians : " + totalRadians); - var maxRotationMatrix = new GameLib.API.Matrix4().rotationMatrixY(totalRadians); + var maxRotationMatrix = new R3.API.Matrix4().rotationMatrixY(totalRadians); for (var k = 0; k < this.vectors.length; k++) { this.vectors[k] = maxRotationMatrix.multiply(this.vectors[k]); @@ -79,13 +79,13 @@ GameLib.API.Quaternion.Points.prototype.maximizeXDistance = function (grain) { }; -GameLib.API.Quaternion.Points.prototype.maximizeYDistance = function (grain) { +R3.API.Quaternion.Points.prototype.maximizeYDistance = function (grain) { // console.log("vectors (before): " + JSON.stringify(this.vectors, null, 2)); var multiplier = 0; - var rotationMatrixX = new GameLib.API.Matrix4().rotationMatrixX(grain); + var rotationMatrixX = new R3.API.Matrix4().rotationMatrixX(grain); var totalRadians = 0; @@ -113,7 +113,7 @@ GameLib.API.Quaternion.Points.prototype.maximizeYDistance = function (grain) { // console.log("distance: " + maxYDistance + " radians : " + totalRadians); - var maxRotationMatrix = new GameLib.API.Matrix4().rotationMatrixX(totalRadians); + var maxRotationMatrix = new R3.API.Matrix4().rotationMatrixX(totalRadians); for (var k = 0; k < this.vectors.length; k++) { this.vectors[k] = maxRotationMatrix.multiply(this.vectors[k]); @@ -124,17 +124,17 @@ GameLib.API.Quaternion.Points.prototype.maximizeYDistance = function (grain) { }; -GameLib.API.Quaternion.Points.prototype.lookAt = function (at, up) { +R3.API.Quaternion.Points.prototype.lookAt = function (at, up) { var polyCenter = this.average(); console.log("poly center : " + JSON.stringify(polyCenter)); - var lookAtMatrix = new GameLib.API.Matrix4().lookAt(polyCenter, at, up); + var lookAtMatrix = new R3.API.Matrix4().lookAt(polyCenter, at, up); - lookAtMatrix.rows[0] = new GameLib.API.Quaternion(1, 0, 0, 0); - lookAtMatrix.rows[1] = new GameLib.API.Quaternion(0, 0, 1, 0); - lookAtMatrix.rows[2] = new GameLib.API.Quaternion(0, 1, 0, 0); + lookAtMatrix.rows[0] = new R3.API.Quaternion(1, 0, 0, 0); + lookAtMatrix.rows[1] = new R3.API.Quaternion(0, 0, 1, 0); + lookAtMatrix.rows[2] = new R3.API.Quaternion(0, 1, 0, 0); console.log("look at matrix : " + JSON.stringify(lookAtMatrix, null, 2)); @@ -145,7 +145,7 @@ GameLib.API.Quaternion.Points.prototype.lookAt = function (at, up) { } }; -GameLib.API.Quaternion.Points.prototype.distances = function () { +R3.API.Quaternion.Points.prototype.distances = function () { var minX = this.vectors[0].x; var minY = this.vectors[0].y; @@ -177,14 +177,14 @@ GameLib.API.Quaternion.Points.prototype.distances = function () { } } - return new GameLib.API.Vector3( + return new R3.API.Vector3( Math.abs(maxX - minX), Math.abs(maxY - minY), Math.abs(maxY - minZ) ) }; -GameLib.API.Quaternion.Points.prototype.average = function () { +R3.API.Quaternion.Points.prototype.average = function () { var averageX = 0; var averageY = 0; var averageZ = 0; @@ -195,14 +195,14 @@ GameLib.API.Quaternion.Points.prototype.average = function () { averageZ += this.vectors[i].z; } - return new GameLib.API.Vector3( + return new R3.API.Vector3( averageX / this.vectors.length, averageY / this.vectors.length, averageZ / this.vectors.length ); }; -GameLib.API.Quaternion.Points.prototype.negate = function () { +R3.API.Quaternion.Points.prototype.negate = function () { for (var i = 0; i < this.vectors.length; i++) { this.vectors[i].x *= -1; @@ -214,7 +214,7 @@ GameLib.API.Quaternion.Points.prototype.negate = function () { }; -GameLib.API.Quaternion.Points.prototype.toOrigin = function () { +R3.API.Quaternion.Points.prototype.toOrigin = function () { var distanceFromOrigin = this.average().negate(); diff --git a/src/r3-api-render-configuration.js b/src/r3-api-render-configuration.js new file mode 100644 index 0000000..1585690 --- /dev/null +++ b/src/r3-api-render-configuration.js @@ -0,0 +1,117 @@ +/** + * R3.API.RenderConfiguration + * @param id + * @param name + * @param parentEntity + * @param logicalSize + * @param aspectRatio + * @param scaleMode + * @param activeCamera + * @param activeScenes + * @param activeComposer + * @param activeEffect + * @param activeRenderer + * @param enableComposer + * @param enableEffect + * @constructor + */ +R3.API.RenderConfiguration = function ( + id, + name, + parentEntity, + logicalSize, + aspectRatio, + scaleMode, + activeCamera, + activeScenes, + activeRenderer, + activeComposer, + activeEffect, + enableComposer, + enableEffect +) { + if (R3.Utils.UndefinedOrNull(id)) { + id = R3.Utils.RandomId(); + } + this.id = id; + + if (R3.Utils.UndefinedOrNull(name)) { + name = "RenderConfiguration (" + this.id + ")"; + } + this.name = name; + + if (R3.Utils.UndefinedOrNull(logicalSize)) { + logicalSize = new R3.API.Vector2( + 480, + 320 + ); + } + this.logicalSize = logicalSize; + + if (R3.Utils.UndefinedOrNull(aspectRatio)) { + aspectRatio = R3.API.Renderer.ASPECT_RATIO_3_2; + } + this.aspectRatio = aspectRatio; + + if (R3.Utils.UndefinedOrNull(scaleMode)) { + scaleMode = R3.API.Renderer.SCALE_MODE_LETTERBOX; + } + this.scaleMode = scaleMode; + + if (R3.Utils.UndefinedOrNull(activeCamera)) { + activeCamera = null; + } + this.activeCamera = activeCamera; + + if (R3.Utils.UndefinedOrNull(activeScenes)) { + activeScenes = []; + } + this.activeScenes = activeScenes; + + if (R3.Utils.UndefinedOrNull(activeRenderer)) { + activeRenderer = null; + } + this.activeRenderer = activeRenderer; + + if (R3.Utils.UndefinedOrNull(activeComposer)) { + activeComposer = null; + } + this.activeComposer = activeComposer; + + if (R3.Utils.UndefinedOrNull(activeEffect)) { + activeEffect = null; + } + this.activeEffect = activeEffect; + + if (R3.Utils.UndefinedOrNull(enableComposer)) { + enableComposer = false; + } + this.enableComposer = enableComposer; + + if (R3.Utils.UndefinedOrNull(enableEffect)) { + enableEffect = false; + } + this.enableEffect = enableEffect; + + R3.API.Component.call( + this, + R3.Component.RENDER_CONFIGURATION, + parentEntity + ); + +}; + +R3.API.RenderConfiguration.prototype = Object.create(R3.API.Component.prototype); +R3.API.RenderConfiguration.prototype.constructor = R3.API.RenderConfiguration; + +R3.API.RenderConfiguration.ASPECT_RATIO_NONE = 0x1; +R3.API.RenderConfiguration.ASPECT_RATIO_4_3 = 0x2; +R3.API.RenderConfiguration.ASPECT_RATIO_3_2 = 0x3; +R3.API.RenderConfiguration.ASPECT_RATIO_16_10 = 0x4; +R3.API.RenderConfiguration.ASPECT_RATIO_17_10 = 0x5; +R3.API.RenderConfiguration.ASPECT_RATIO_16_9 = 0x6; + +R3.API.RenderConfiguration.SCALE_MODE_NONE = 0x1; +R3.API.RenderConfiguration.SCALE_MODE_LETTERBOX = 0x2; +R3.API.RenderConfiguration.SCALE_MODE_ZOOM_TO_BIGGER = 0x3; +R3.API.RenderConfiguration.SCALE_MODE_NON_UNIFORM = 0x4; diff --git a/src/r3-api-renderer-a.js b/src/r3-api-renderer-a.js new file mode 100644 index 0000000..95dbda3 --- /dev/null +++ b/src/r3-api-renderer-a.js @@ -0,0 +1,122 @@ +/** + * R3.API.Renderer + * @param id + * @param name + * @param rendererType + * @param parentEntity + * @param width + * @param height + * @param offset + * @param canvas + * @constructor + */ +R3.API.Renderer = function ( + id, + name, + rendererType, + parentEntity, + width, + height, + offset, + canvas +) { + if (R3.Utils.UndefinedOrNull(id)) { + id = R3.Utils.RandomId(); + } + this.id = id; + + if (R3.Utils.UndefinedOrNull(rendererType)) { + rendererType = R3.API.Renderer.RENDERER_TYPE_NONE; + } + this.rendererType = rendererType; + + if (R3.Utils.UndefinedOrNull(name)) { + + switch (this.rendererType) { + case R3.API.Renderer.RENDERER_TYPE_NONE : + name = "Renderer"; + break; + case R3.API.Renderer.RENDERER_TYPE_2D : + name = "Renderer 2D"; + break; + case R3.API.Renderer.RENDERER_TYPE_3D : + name = "Renderer 3D"; + break; + default : + console.warn('no nice name for renderer'); + break; + } + + name += " (" + this.id + ")"; + } + this.name = name; + + if (R3.Utils.UndefinedOrNull(width)) { + width = 1; + } + this.width = width; + + if (R3.Utils.UndefinedOrNull(height)) { + height = 1; + } + this.height = height; + + if (R3.Utils.UndefinedOrNull(offset)) { + offset = new R3.API.Vector2(0,0); + } + this.offset = offset; + + if (R3.Utils.UndefinedOrNull(canvas)) { + canvas = new R3.API.Canvas(); + } + this.canvas = canvas; + + R3.API.Component.call( + this, + R3.API.Renderer.GetComponentType(this.rendererType), + parentEntity + ); + +}; + +R3.API.Renderer.prototype = Object.create(R3.API.Component.prototype); +R3.API.Renderer.prototype.constructor = R3.API.Renderer; + +R3.API.Renderer.GetComponentType = function(rendererType) { + + var componentType = null; + + switch (rendererType) { + case R3.API.Renderer.RENDERER_TYPE_NONE : + componentType = R3.Component.RENDERER; + break; + case R3.API.Renderer.RENDERER_TYPE_2D : + componentType = R3.Component.RENDERER_D2; + break; + case R3.API.Renderer.RENDERER_TYPE_3D : + componentType = R3.Component.RENDERER_D3; + break; + default : + console.warn('could not determine component type'); + break; + } + + return componentType; +}; + +R3.API.Renderer.RENDERER_TYPE_NONE = 0x0; +R3.API.Renderer.RENDERER_TYPE_2D = 0x1; +R3.API.Renderer.RENDERER_TYPE_3D = 0x2; + +R3.API.Renderer.MODE_CANVAS = 0x1; +R3.API.Renderer.MODE_TARGET = 0x2; +R3.API.Renderer.MODE_CANVAS_AND_TARGET = 0x3; + +R3.API.Renderer.SHADOW_MAP_TYPE_BASIC = 0; +R3.API.Renderer.SHADOW_MAP_TYPE_PCF = 1; +R3.API.Renderer.SHADOW_MAP_TYPE_PCF_SOFT = 2; + +R3.API.Renderer.TONE_MAPPING_LINEAR = 1; +R3.API.Renderer.TONE_MAPPING_REINHARD = 2; +R3.API.Renderer.TONE_MAPPING_UNCHARTED_2 = 3; +R3.API.Renderer.TONE_MAPPING_CINEON = 4; diff --git a/src/r3-api-renderer-d2.js b/src/r3-api-renderer-d2.js new file mode 100644 index 0000000..d207dcf --- /dev/null +++ b/src/r3-api-renderer-d2.js @@ -0,0 +1,35 @@ +/** + * R3.API.Renderer.D2 + * @constructor + * @param apiRenderer + */ +R3.API.Renderer.D2 = function ( + apiRenderer +) { + + if (R3.Utils.UndefinedOrNull(apiRenderer)) { + apiRenderer = { + rendererType : R3.API.Renderer.RENDERER_TYPE_2D + }; + } + + if (R3.Utils.UndefinedOrNull(apiRenderer.rendererType)) { + apiRenderer.rendererType = R3.API.Renderer.RENDERER_TYPE_2D; + } + + R3.API.Renderer.call( + this, + apiRenderer.id, + apiRenderer.name, + apiRenderer.rendererType, + apiRenderer.parentEntity, + apiRenderer.width, + apiRenderer.height, + apiRenderer.offset, + apiRenderer.canvas + ); + +}; + +R3.API.Renderer.D2.prototype = Object.create(R3.API.Renderer.prototype); +R3.API.Renderer.D2.prototype.constructor = R3.API.Renderer.D2; \ No newline at end of file diff --git a/src/game-lib-api-renderer-d3.js b/src/r3-api-renderer-d3.js similarity index 62% rename from src/game-lib-api-renderer-d3.js rename to src/r3-api-renderer-d3.js index 2494f62..9de21bf 100644 --- a/src/game-lib-api-renderer-d3.js +++ b/src/r3-api-renderer-d3.js @@ -1,5 +1,5 @@ /** - * GameLib.API.Renderer.D3 + * R3.API.Renderer.D3 * @param apiRenderer * @param renderMode * @param autoClear @@ -35,7 +35,7 @@ * @param viewports * @constructor */ -GameLib.API.Renderer.D3 = function ( +R3.API.Renderer.D3 = function ( apiRenderer, renderMode, autoClear, @@ -71,173 +71,173 @@ GameLib.API.Renderer.D3 = function ( viewports ) { - if (GameLib.Utils.UndefinedOrNull(apiRenderer)) { + if (R3.Utils.UndefinedOrNull(apiRenderer)) { apiRenderer = { - rendererType : GameLib.API.Renderer.RENDERER_TYPE_3D + rendererType : R3.API.Renderer.RENDERER_TYPE_3D }; } - if (GameLib.Utils.UndefinedOrNull(apiRenderer.rendererType)) { - apiRenderer.rendererType = GameLib.API.Renderer.RENDERER_TYPE_3D; + if (R3.Utils.UndefinedOrNull(apiRenderer.rendererType)) { + apiRenderer.rendererType = R3.API.Renderer.RENDERER_TYPE_3D; } - if (GameLib.Utils.UndefinedOrNull(renderMode)) { - renderMode = GameLib.API.Renderer.MODE_CANVAS; + if (R3.Utils.UndefinedOrNull(renderMode)) { + renderMode = R3.API.Renderer.MODE_CANVAS; } this.renderMode = renderMode; - if (GameLib.Utils.UndefinedOrNull(autoClear)) { + if (R3.Utils.UndefinedOrNull(autoClear)) { autoClear = true; } this.autoClear = autoClear; - if (GameLib.Utils.UndefinedOrNull(autoClearColor)) { + if (R3.Utils.UndefinedOrNull(autoClearColor)) { autoClearColor = true; } this.autoClearColor = autoClearColor; - if (GameLib.Utils.UndefinedOrNull(autoClearDepth)) { + if (R3.Utils.UndefinedOrNull(autoClearDepth)) { autoClearDepth = true; } this.autoClearDepth = autoClearDepth; - if (GameLib.Utils.UndefinedOrNull(autoClearStencil)) { + if (R3.Utils.UndefinedOrNull(autoClearStencil)) { autoClearStencil = true; } this.autoClearStencil = autoClearStencil; - if (GameLib.Utils.UndefinedOrNull(gammaFactor)) { + if (R3.Utils.UndefinedOrNull(gammaFactor)) { gammaFactor = 2; } this.gammaFactor = gammaFactor; - if (GameLib.Utils.UndefinedOrNull(gammaInput)) { + if (R3.Utils.UndefinedOrNull(gammaInput)) { gammaInput = false; } this.gammaInput = gammaInput; - if (GameLib.Utils.UndefinedOrNull(gammaOutput)) { + if (R3.Utils.UndefinedOrNull(gammaOutput)) { gammaOutput = false; } this.gammaOutput = gammaOutput; - if (GameLib.Utils.UndefinedOrNull(maxMorphTargets)) { + if (R3.Utils.UndefinedOrNull(maxMorphTargets)) { maxMorphTargets = 8; } this.maxMorphTargets = maxMorphTargets; - if (GameLib.Utils.UndefinedOrNull(maxMorphNormals)) { + if (R3.Utils.UndefinedOrNull(maxMorphNormals)) { maxMorphNormals = 4; } this.maxMorphNormals = maxMorphNormals; - if (GameLib.Utils.UndefinedOrNull(physicallyCorrectLights)) { + if (R3.Utils.UndefinedOrNull(physicallyCorrectLights)) { physicallyCorrectLights = false; } this.physicallyCorrectLights = physicallyCorrectLights; - if (GameLib.Utils.UndefinedOrNull(shadowMapEnabled)) { + if (R3.Utils.UndefinedOrNull(shadowMapEnabled)) { shadowMapEnabled = false; } this.shadowMapEnabled = shadowMapEnabled; - if (GameLib.Utils.UndefinedOrNull(shadowMapAutoUpdate)) { + if (R3.Utils.UndefinedOrNull(shadowMapAutoUpdate)) { shadowMapAutoUpdate = true; } this.shadowMapAutoUpdate = shadowMapAutoUpdate; - if (GameLib.Utils.UndefinedOrNull(shadowMapNeedsUpdate)) { + if (R3.Utils.UndefinedOrNull(shadowMapNeedsUpdate)) { shadowMapNeedsUpdate = false; } this.shadowMapNeedsUpdate = shadowMapNeedsUpdate; - if (GameLib.Utils.UndefinedOrNull(shadowMapType)) { - shadowMapType = GameLib.API.Renderer.SHADOW_MAP_TYPE_BASIC; + if (R3.Utils.UndefinedOrNull(shadowMapType)) { + shadowMapType = R3.API.Renderer.SHADOW_MAP_TYPE_BASIC; } this.shadowMapType = shadowMapType; - if (GameLib.Utils.UndefinedOrNull(shadowMapRenderReverseSided)) { + if (R3.Utils.UndefinedOrNull(shadowMapRenderReverseSided)) { shadowMapRenderReverseSided = true; } this.shadowMapRenderReverseSided = shadowMapRenderReverseSided; - if (GameLib.Utils.UndefinedOrNull(shadowMapRenderSingleSided)) { + if (R3.Utils.UndefinedOrNull(shadowMapRenderSingleSided)) { shadowMapRenderSingleSided = true; } this.shadowMapRenderSingleSided = shadowMapRenderSingleSided; - if (GameLib.Utils.UndefinedOrNull(sortObjects)) { + if (R3.Utils.UndefinedOrNull(sortObjects)) { sortObjects = true; } this.sortObjects = sortObjects; - if (GameLib.Utils.UndefinedOrNull(toneMapping)) { - toneMapping = GameLib.API.Renderer.TONE_MAPPING_LINEAR; + if (R3.Utils.UndefinedOrNull(toneMapping)) { + toneMapping = R3.API.Renderer.TONE_MAPPING_LINEAR; } this.toneMapping = toneMapping; - if (GameLib.Utils.UndefinedOrNull(toneMappingExposure)) { + if (R3.Utils.UndefinedOrNull(toneMappingExposure)) { toneMappingExposure = 1; } this.toneMappingExposure = toneMappingExposure; - if (GameLib.Utils.UndefinedOrNull(toneMappingWhitePoint)) { + if (R3.Utils.UndefinedOrNull(toneMappingWhitePoint)) { toneMappingWhitePoint = 1; } this.toneMappingWhitePoint = toneMappingWhitePoint; - if (GameLib.Utils.UndefinedOrNull(premultipliedAlpha)) { + if (R3.Utils.UndefinedOrNull(premultipliedAlpha)) { premultipliedAlpha = true; } this.premultipliedAlpha = premultipliedAlpha; - if (GameLib.Utils.UndefinedOrNull(antialias)) { + if (R3.Utils.UndefinedOrNull(antialias)) { antialias = false; } this.antialias = antialias; - if (GameLib.Utils.UndefinedOrNull(stencil)) { + if (R3.Utils.UndefinedOrNull(stencil)) { stencil = true; } this.stencil = stencil; - if (GameLib.Utils.UndefinedOrNull(preserveDrawingBuffer)) { + if (R3.Utils.UndefinedOrNull(preserveDrawingBuffer)) { preserveDrawingBuffer = false; } this.preserveDrawingBuffer = preserveDrawingBuffer; - if (GameLib.Utils.UndefinedOrNull(depth)) { + if (R3.Utils.UndefinedOrNull(depth)) { depth = true; } this.depth = depth; - if (GameLib.Utils.UndefinedOrNull(logarithmicDepthBuffer)) { + if (R3.Utils.UndefinedOrNull(logarithmicDepthBuffer)) { logarithmicDepthBuffer = false; } this.logarithmicDepthBuffer = logarithmicDepthBuffer; - if (GameLib.Utils.UndefinedOrNull(localClippingEnabled)) { + if (R3.Utils.UndefinedOrNull(localClippingEnabled)) { localClippingEnabled = false; } this.localClippingEnabled = localClippingEnabled; - if (GameLib.Utils.UndefinedOrNull(renderTarget)) { + if (R3.Utils.UndefinedOrNull(renderTarget)) { renderTarget = null; } this.renderTarget = renderTarget; - if (GameLib.Utils.UndefinedOrNull(clippingPlanes)) { + if (R3.Utils.UndefinedOrNull(clippingPlanes)) { clippingPlanes = []; } this.clippingPlanes = clippingPlanes; - if (GameLib.Utils.UndefinedOrNull(clearColor)) { - clearColor = new GameLib.API.Color(0.11, 0.11, 0.11); + if (R3.Utils.UndefinedOrNull(clearColor)) { + clearColor = new R3.API.Color(0.11, 0.11, 0.11); } this.clearColor = clearColor; - if (GameLib.Utils.UndefinedOrNull(viewports)) { - viewports = [new GameLib.D3.API.Viewport( + if (R3.Utils.UndefinedOrNull(viewports)) { + viewports = [new R3.D3.API.Viewport( null, null, 1, @@ -248,7 +248,7 @@ GameLib.API.Renderer.D3 = function ( } this.viewports = viewports; - GameLib.API.Renderer.call( + R3.API.Renderer.call( this, apiRenderer.id, apiRenderer.name, @@ -262,5 +262,5 @@ GameLib.API.Renderer.D3 = function ( }; -GameLib.API.Renderer.D3.prototype = Object.create(GameLib.API.Renderer.prototype); -GameLib.API.Renderer.D3.prototype.constructor = GameLib.API.Renderer.D3; \ No newline at end of file +R3.API.Renderer.D3.prototype = Object.create(R3.API.Renderer.prototype); +R3.API.Renderer.D3.prototype.constructor = R3.API.Renderer.D3; \ No newline at end of file diff --git a/src/game-lib-api-server.js b/src/r3-api-server.js similarity index 59% rename from src/game-lib-api-server.js rename to src/r3-api-server.js index b6264e8..427a5e8 100644 --- a/src/game-lib-api-server.js +++ b/src/r3-api-server.js @@ -9,7 +9,7 @@ * @param parentEntity * @constructor */ -GameLib.API.Server = function( +R3.API.Server = function( id, name, protocol, @@ -19,54 +19,54 @@ GameLib.API.Server = function( parentEntity ) { - if (GameLib.Utils.UndefinedOrNull(id)) { - id = GameLib.Utils.RandomId(); + if (R3.Utils.UndefinedOrNull(id)) { + id = R3.Utils.RandomId(); } this.id = id; - if (GameLib.Utils.UndefinedOrNull(name)) { + if (R3.Utils.UndefinedOrNull(name)) { name = 'Server (' + this.id + ')'; } this.name = name; - if (GameLib.Utils.UndefinedOrNull(protocol)) { + if (R3.Utils.UndefinedOrNull(protocol)) { protocol = 'http'; } this.protocol = protocol; - if (GameLib.Utils.UndefinedOrNull(ip)) { + if (R3.Utils.UndefinedOrNull(ip)) { ip = '127.0.0.1'; } this.ip = ip; - if (GameLib.Utils.UndefinedOrNull(port)) { + if (R3.Utils.UndefinedOrNull(port)) { port = 80; } this.port = port; - if (GameLib.Utils.UndefinedOrNull(protocols)) { + if (R3.Utils.UndefinedOrNull(protocols)) { protocols = []; } this.protocols = protocols; - GameLib.API.Component.call( + R3.API.Component.call( this, - GameLib.Component.SERVER, + R3.Component.SERVER, parentEntity ); }; -GameLib.API.Server.prototype = Object.create(GameLib.API.Component.prototype); -GameLib.API.Server.prototype.constructor = GameLib.API.Server; +R3.API.Server.prototype = Object.create(R3.API.Component.prototype); +R3.API.Server.prototype.constructor = R3.API.Server; /** * Creates an API Server from an Object Server * @param objectServer * @constructor */ -GameLib.API.Server.FromObject = function(objectServer) { +R3.API.Server.FromObject = function(objectServer) { - return new GameLib.API.Server( + return new R3.API.Server( objectServer.id, objectServer.name, objectServer.protocol, diff --git a/src/r3-api-socket-0.js b/src/r3-api-socket-0.js new file mode 100644 index 0000000..fdfa3a0 --- /dev/null +++ b/src/r3-api-socket-0.js @@ -0,0 +1,93 @@ +/** + * Raw Socket API object - should always correspond with the Socket Schema + * @param id + * @param name + * @param socketType + * @param roomId + * @param peerId + * @param server R3.Server + * @param parentEntity + * @constructor + */ +R3.API.Socket = function( + id, + name, + socketType, + roomId, + peerId, + server, + parentEntity +) { + + if (R3.Utils.UndefinedOrNull(id)) { + id = R3.Utils.RandomId(); + } + this.id = id; + + if (R3.Utils.UndefinedOrNull(name)) { + name = 'Socket (' + this.id + ')'; + } + this.name = name; + + if (R3.Utils.UndefinedOrNull(socketType)) { + socketType = R3.API.Socket.TYPE_NONE; + } + this.socketType = socketType; + + if (R3.Utils.UndefinedOrNull(roomId)) { + roomId = 'room_' + R3.Utils.RandomId(); + } + this.roomId = roomId; + + if (R3.Utils.UndefinedOrNull(peerId)) { + peerId = null; + } + this.peerId = peerId; + + if (R3.Utils.UndefinedOrNull(server)) { + server = null; + } + this.server = server; + + var componentType = R3.Component.SOCKET; + + if (this.socketType === R3.API.Socket.TYPE_CAST) { + componentType = R3.Component.SOCKET_CAST; + } + + if (this.socketType === R3.API.Socket.TYPE_RECEIVE) { + componentType = R3.Component.SOCKET_RECEIVE; + } + + R3.API.Component.call( + this, + componentType, + parentEntity + ); +}; + +R3.API.Socket.prototype = Object.create(R3.API.Component.prototype); +R3.API.Socket.prototype.constructor = R3.API.Socket; + +R3.API.Socket.TYPE_NONE = 0x1; +R3.API.Socket.TYPE_CAST = 0x2; +R3.API.Socket.TYPE_RECEIVE = 0x3; + +/** + * Creates an API Socket from an Object Socket + * @param objectSocket + * @constructor + */ +R3.API.Socket.FromObject = function(objectSocket) { + + return new R3.API.Socket( + objectSocket.id, + objectSocket.name, + objectSocket.socketType, + objectSocket.roomId, + objectSocket.peerId, + objectSocket.server, + objectSocket.parentEntity + ); + +}; diff --git a/src/r3-api-socket-cast.js b/src/r3-api-socket-cast.js new file mode 100644 index 0000000..cf3f1e0 --- /dev/null +++ b/src/r3-api-socket-cast.js @@ -0,0 +1,78 @@ +/** + * Raw Cast API object - should always correspond with the Cast Schema + * @param apiSocket + * @param castType + * @param source + * @param sourceProperties + * @constructor + */ +R3.API.Socket.Cast = function( + apiSocket, + castType, + source, + sourceProperties +) { + + if (R3.Utils.UndefinedOrNull(apiSocket)) { + apiSocket = { + socketType : R3.API.Socket.SOCKET_CAST + }; + } + + R3.API.Socket.call( + this, + apiSocket.id, + apiSocket.name, + apiSocket.socketType, + apiSocket.roomId, + apiSocket.peerId, + apiSocket.server, + apiSocket.parentEntity + ); + + if (R3.Utils.UndefinedOrNull(castType)) { + castType = R3.API.Socket.Cast.CAST_TYPE_ROOM; + } + this.castType = castType; + + if (R3.Utils.UndefinedOrNull(source)) { + source = null; + } + this.source = source; + + if (R3.Utils.UndefinedOrNull(sourceProperties)) { + sourceProperties = null; + } + this.sourceProperties = sourceProperties; + + R3.API.Component.call( + this, + R3.Component.SOCKET_CAST + ); +}; + +R3.API.Socket.Cast.prototype = Object.create(R3.API.Socket.prototype); +R3.API.Socket.Cast.prototype.constructor = R3.API.Socket.Cast.Receive; + +R3.API.Socket.Cast.CAST_TYPE_ROOM = 0x1; +R3.API.Socket.Cast.CAST_TYPE_PEER = 0x2; +R3.API.Socket.Cast.CAST_TYPE_ALL = 0x3; +R3.API.Socket.Cast.CAST_TYPE_ALL_BUT_PEER = 0x4; + + +/** + * Creates an API.Socket.Cast from an Object Cast + * @param objectSocketCast + * @constructor + */ +R3.API.Socket.Cast.FromObject = function(objectSocketCast) { + + var apiSocket = R3.API.Socket.FromObject(objectSocketCast); + + return new R3.API.Socket.Cast( + apiSocket, + objectSocketCast.castType, + objectSocketCast.source, + objectSocketCast.sourceProperties + ); +}; diff --git a/src/game-lib-api-socket-receive.js b/src/r3-api-socket-receive.js similarity index 51% rename from src/game-lib-api-socket-receive.js rename to src/r3-api-socket-receive.js index 0bf2d74..3723a96 100644 --- a/src/game-lib-api-socket-receive.js +++ b/src/r3-api-socket-receive.js @@ -6,20 +6,20 @@ * @param destinationProperties * @constructor */ -GameLib.API.Socket.Receive = function( +R3.API.Socket.Receive = function( apiSocket, receiveType, destination, destinationProperties ) { - if (GameLib.Utils.UndefinedOrNull(apiSocket)) { + if (R3.Utils.UndefinedOrNull(apiSocket)) { apiSocket = { - socketType : GameLib.API.Socket.SOCKET_RECEIVE + socketType : R3.API.Socket.SOCKET_RECEIVE }; } - GameLib.API.Socket.call( + R3.API.Socket.call( this, apiSocket.id, apiSocket.name, @@ -30,44 +30,44 @@ GameLib.API.Socket.Receive = function( apiSocket.parentEntity ); - if (GameLib.Utils.UndefinedOrNull(receiveType)) { - receiveType = GameLib.API.Socket.Receive.RECEIVE_TYPE_ROOM; + if (R3.Utils.UndefinedOrNull(receiveType)) { + receiveType = R3.API.Socket.Receive.RECEIVE_TYPE_ROOM; } this.receiveType = receiveType; - if (GameLib.Utils.UndefinedOrNull(destination)) { + if (R3.Utils.UndefinedOrNull(destination)) { destination = null; } this.destination = destination; - if (GameLib.Utils.UndefinedOrNull(destinationProperties)) { + if (R3.Utils.UndefinedOrNull(destinationProperties)) { destinationProperties = null; } this.destinationProperties = destinationProperties; - GameLib.API.Component.call( + R3.API.Component.call( this, - GameLib.Component.SOCKET_RECEIVE + R3.Component.SOCKET_RECEIVE ); }; -GameLib.API.Socket.Receive.prototype = Object.create(GameLib.API.Socket.prototype); -GameLib.API.Socket.Receive.prototype.constructor = GameLib.API.Socket.Receive; +R3.API.Socket.Receive.prototype = Object.create(R3.API.Socket.prototype); +R3.API.Socket.Receive.prototype.constructor = R3.API.Socket.Receive; -GameLib.API.Socket.Receive.RECEIVE_TYPE_ROOM = 0x1; -GameLib.API.Socket.Receive.RECEIVE_TYPE_PEER = 0x2; +R3.API.Socket.Receive.RECEIVE_TYPE_ROOM = 0x1; +R3.API.Socket.Receive.RECEIVE_TYPE_PEER = 0x2; /** * Creates an API Socket.Receive from an Object Socket.Receive - * @param socket GameLib.SocketsRuntime + * @param socket R3.SocketsRuntime * @param objectSocketReceive * @constructor */ -GameLib.API.Socket.Receive.FromObject = function(socket, objectSocketReceive) { +R3.API.Socket.Receive.FromObject = function(socket, objectSocketReceive) { - var apiSocket = GameLib.API.Socket.FromObject(objectSocketReceive); + var apiSocket = R3.API.Socket.FromObject(objectSocketReceive); - return new GameLib.API.Socket.Receive( + return new R3.API.Socket.Receive( apiSocket, objectSocketReceive.receiveType, objectSocketReceive.destination, diff --git a/src/r3-api-sphere.js b/src/r3-api-sphere.js new file mode 100644 index 0000000..c8901e8 --- /dev/null +++ b/src/r3-api-sphere.js @@ -0,0 +1,20 @@ +/** + * R3.API.Sphere + * @constructor + * @param center + * @param radius + */ +R3.API.Sphere = function ( + center, + radius +) { + if (R3.Utils.UndefinedOrNull(center)) { + center = new R3.API.Vector3(0,0,0); + } + this.center = center; + + if (R3.Utils.UndefinedOrNull(radius)) { + radius = 1; + } + this.radius = radius; +}; diff --git a/src/game-lib-api-stats.js b/src/r3-api-stats.js similarity index 58% rename from src/game-lib-api-stats.js rename to src/r3-api-stats.js index b283811..ccc1dc2 100644 --- a/src/game-lib-api-stats.js +++ b/src/r3-api-stats.js @@ -6,55 +6,55 @@ * @param parentEntity * @constructor */ -GameLib.API.Stats = function( +R3.API.Stats = function( id, name, domElement, parentEntity ) { - if (GameLib.Utils.UndefinedOrNull(id)) { - id = GameLib.Utils.RandomId(); + if (R3.Utils.UndefinedOrNull(id)) { + id = R3.Utils.RandomId(); } this.id = id; - if (GameLib.Utils.UndefinedOrNull(name)) { + if (R3.Utils.UndefinedOrNull(name)) { name = 'Stats (' + this.id + ')'; } this.name = name; - if (GameLib.Utils.UndefinedOrNull(domElement)) { + if (R3.Utils.UndefinedOrNull(domElement)) { domElement = null; } this.domElement = domElement; - GameLib.API.Component.call( + R3.API.Component.call( this, - GameLib.Component.STATS, + R3.Component.STATS, parentEntity ); }; -GameLib.API.Stats.prototype = Object.create(GameLib.API.Component.prototype); -GameLib.API.Stats.prototype.constructor = GameLib.API.Stats; +R3.API.Stats.prototype = Object.create(R3.API.Component.prototype); +R3.API.Stats.prototype.constructor = R3.API.Stats; /** * Creates an API Stats from an Object Stats * @param objectStats * @constructor */ -GameLib.API.Stats.FromObject = function(objectStats) { +R3.API.Stats.FromObject = function(objectStats) { var apiDomElement = null; if (objectStats.domElement) { if (objectStats.domElement instanceof Object) { - apiDomElement = GameLib.API.DomElement.FromObject(objectStats.domElement); + apiDomElement = R3.API.DomElement.FromObject(objectStats.domElement); } else { apiDomElement = objectStats.domElement; } } - return new GameLib.API.Stats( + return new R3.API.Stats( objectStats.id, objectStats.name, apiDomElement, diff --git a/src/r3-api-system.js b/src/r3-api-system.js new file mode 100644 index 0000000..508902c --- /dev/null +++ b/src/r3-api-system.js @@ -0,0 +1,104 @@ +/** + * This component renders a scene + * @param id String + * @param name String + * @param systemType + * @param parentEntity + * @constructor + */ +R3.API.System = function ( + id, + name, + systemType, + parentEntity +) { + + if (R3.Utils.UndefinedOrNull(id)) { + id = R3.Utils.RandomId(); + } + this.id = id; + + if (R3.Utils.UndefinedOrNull(name)) { + name = "System (" + this.id + ")"; + } + this.name = name; + + if (R3.Utils.UndefinedOrNull(systemType)) { + systemType = R3.System.SYSTEM_TYPE_NONE; + } + this.systemType = systemType; + + var componentType = R3.Component.SYSTEM; + + if (this.systemType === R3.System.SYSTEM_TYPE_NONE) { + componentType = R3.Component.SYSTEM; + } + + if (this.systemType === R3.System.SYSTEM_TYPE_ANIMATION) { + componentType = R3.Component.SYSTEM_ANIMATION; + } + + if (this.systemType === R3.System.SYSTEM_TYPE_CUSTOM) { + componentType = R3.Component.SYSTEM_CUSTOM_CODE; + } + + if (this.systemType === R3.System.SYSTEM_TYPE_GUI) { + componentType = R3.Component.SYSTEM_GUI; + } + + if (this.systemType === R3.System.SYSTEM_TYPE_INPUT) { + componentType = R3.Component.SYSTEM_INPUT; + } + + if (this.systemType === R3.System.SYSTEM_TYPE_LINKING) { + componentType = R3.Component.SYSTEM_LINKING; + } + + if (this.systemType === R3.System.SYSTEM_TYPE_PHYSICS) { + componentType = R3.Component.SYSTEM_PHYSICS; + } + + if (this.systemType === R3.System.SYSTEM_TYPE_RENDER) { + componentType = R3.Component.SYSTEM_RENDER; + } + + if (this.systemType === R3.System.SYSTEM_TYPE_STORAGE) { + componentType = R3.Component.SYSTEM_STORAGE; + } + + if (this.systemType === R3.System.SYSTEM_TYPE_VISUALIZATION) { + componentType = R3.Component.SYSTEM_VISUALIZATION; + } + + if (this.systemType === R3.System.SYSTEM_TYPE_PARTICLE) { + componentType = R3.Component.SYSTEM_PARTICLE; + } + + if (this.systemType === R3.System.SYSTEM_TYPE_AUDIO) { + componentType = R3.Component.SYSTEM_AUDIO; + } + + R3.API.Component.call( + this, + componentType, + parentEntity + ); + +}; + +R3.API.System.prototype = Object.create(R3.API.Component.prototype); +R3.API.System.prototype.constructor = R3.API.System; + +/** + * Object to R3.D3.API.System + * @param objectComponent + * @constructor + */ +R3.API.System.FromObject = function(objectComponent) { + return new R3.API.System( + objectComponent.id, + objectComponent.name, + objectComponent.systemType, + objectComponent.parentEntity + ); +}; diff --git a/src/game-lib-api-vector2.js b/src/r3-api-vector2.js similarity index 50% rename from src/game-lib-api-vector2.js rename to src/r3-api-vector2.js index 716f27f..f9a7c36 100644 --- a/src/game-lib-api-vector2.js +++ b/src/r3-api-vector2.js @@ -1,25 +1,25 @@ -GameLib.API.Vector2 = function (x, y) { +R3.API.Vector2 = function (x, y) { - if (GameLib.Utils.UndefinedOrNull(x)) { + if (R3.Utils.UndefinedOrNull(x)) { x = 0; } this.x = x; - if (GameLib.Utils.UndefinedOrNull(y)) { + if (R3.Utils.UndefinedOrNull(y)) { y = 0; } this.y = y; }; -GameLib.API.Vector2.prototype.copy = function () { - return new GameLib.API.Vector2( +R3.API.Vector2.prototype.copy = function () { + return new R3.API.Vector2( this.x, this.y ); }; -GameLib.API.Vector2.prototype.equals = function (v) { +R3.API.Vector2.prototype.equals = function (v) { return this.x === v.x && this.y === v.y; }; @@ -28,14 +28,14 @@ GameLib.API.Vector2.prototype.equals = function (v) { * @param objectVector * @constructor */ -GameLib.API.Vector2.FromObject = function (objectVector) { +R3.API.Vector2.FromObject = function (objectVector) { - if (GameLib.Utils.UndefinedOrNull(objectVector)) { + if (R3.Utils.UndefinedOrNull(objectVector)) { console.warn('vector from db undefined - stale version in db'); objectVector = {}; } - return new GameLib.API.Vector2( + return new R3.API.Vector2( objectVector.x, objectVector.y ) diff --git a/src/game-lib-api-vector3.js b/src/r3-api-vector3.js similarity index 65% rename from src/game-lib-api-vector3.js rename to src/r3-api-vector3.js index 406506a..923b136 100644 --- a/src/game-lib-api-vector3.js +++ b/src/r3-api-vector3.js @@ -1,116 +1,116 @@ -GameLib.API.Vector3 = function (x, y, z) { +R3.API.Vector3 = function (x, y, z) { - if (GameLib.Utils.UndefinedOrNull(x)) { + if (R3.Utils.UndefinedOrNull(x)) { x = 0; } this.x = x; - if (GameLib.Utils.UndefinedOrNull(y)) { + if (R3.Utils.UndefinedOrNull(y)) { y = 0; } this.y = y; - if (GameLib.Utils.UndefinedOrNull(z)) { + if (R3.Utils.UndefinedOrNull(z)) { z = 0; } this.z = z; }; -GameLib.API.Vector3.prototype.negate = function() { +R3.API.Vector3.prototype.negate = function() { this.x = -this.x; this.y = -this.y; this.z = -this.z; return this; }; -GameLib.API.Vector3.prototype.subtract = function (v) { - return new GameLib.API.Vector3( +R3.API.Vector3.prototype.subtract = function (v) { + return new R3.API.Vector3( this.x - v.x, this.y - v.y, this.z - v.z ); }; -GameLib.API.Vector3.prototype.sub = function (v) { - return new GameLib.API.Vector3( +R3.API.Vector3.prototype.sub = function (v) { + return new R3.API.Vector3( this.x - v.x, this.y - v.y, this.z - v.z ); }; -GameLib.API.Vector3.prototype.equals = function (v) { +R3.API.Vector3.prototype.equals = function (v) { return this.x === v.x && this.y === v.y && this.z === v.z; }; -GameLib.API.Vector3.prototype.cross = function (v) { - return new GameLib.API.Vector3( +R3.API.Vector3.prototype.cross = function (v) { + return new R3.API.Vector3( this.y * v.z - this.z * v.y, this.z * v.x - this.x * v.z, this.x * v.y - this.y * v.x ); }; -GameLib.API.Vector3.clockwise = function (u, v, w, viewPoint) { - var normal = GameLib.API.Vector3.normal(u, v, w); +R3.API.Vector3.clockwise = function (u, v, w, viewPoint) { + var normal = R3.API.Vector3.normal(u, v, w); var uv = u.copy(); var winding = normal.dot(uv.subtract(viewPoint)); return (winding > 0); }; -GameLib.API.Vector3.normal = function (u, v, w) { +R3.API.Vector3.normal = function (u, v, w) { var vv = v.copy(); var wv = w.copy(); return vv.subtract(u).cross(wv.subtract(u)); }; -GameLib.API.Vector3.prototype.lookAt = function (at, up) { - var lookAtMatrix = GameLib.API.Matrix4.lookAt(this, at, up); +R3.API.Vector3.prototype.lookAt = function (at, up) { + var lookAtMatrix = R3.API.Matrix4.lookAt(this, at, up); return this.multiply(lookAtMatrix); }; -GameLib.API.Vector3.prototype.translate = function (v) { +R3.API.Vector3.prototype.translate = function (v) { this.x += v.x; this.y += v.y; this.z += v.z; return this; }; -GameLib.API.Vector3.prototype.add = function (v) { +R3.API.Vector3.prototype.add = function (v) { this.x += v.x; this.y += v.y; this.z += v.z; return this; }; -GameLib.API.Vector3.prototype.squared = function () { +R3.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( +R3.API.Vector3.prototype.copy = function () { + return new R3.API.Vector3( this.x, this.y, this.z ); }; -GameLib.API.Vector3.prototype.set = function (x, y, z) { +R3.API.Vector3.prototype.set = function (x, y, z) { this.x = x; this.y = y; this.z = z; }; -GameLib.API.Vector3.prototype.lerp = function ( v, alpha ) { - return new GameLib.API.Vector3( +R3.API.Vector3.prototype.lerp = function ( v, alpha ) { + return new R3.API.Vector3( this.x + ( v.x - this.x ) * alpha, this.y + ( v.y - this.y ) * alpha, this.z + ( v.z - this.z ) * alpha ); }; -GameLib.API.Vector3.prototype.distanceTo = function(v) { +R3.API.Vector3.prototype.distanceTo = function(v) { var dx = this.x - v.x, dy = this.y - v.y, dz = this.z - v.z; @@ -120,7 +120,7 @@ GameLib.API.Vector3.prototype.distanceTo = function(v) { /** * @return {number} */ -GameLib.API.Vector3.AngleDirection = function(forward, directionToCheck, up) { +R3.API.Vector3.AngleDirection = function(forward, directionToCheck, up) { var perp = forward.cross(directionToCheck); var dir = perp.dot(up); @@ -135,18 +135,18 @@ GameLib.API.Vector3.AngleDirection = function(forward, directionToCheck, up) { /** * Multiplies this vector with a scalar, vector or matrix. If you want a copy, copy() it first - * @param object {Number | GameLib.API.Vector3 | GameLib.API.Vector4 | GameLib.API.Matrix3 | GameLib.API.Matrix4} + * @param object {Number | R3.API.Vector3 | R3.API.Vector4 | R3.API.Matrix3 | R3.API.Matrix4} * @param cross boolean true if you want the cross product, otherwise returns the scalar (dot or inner) product - * @returns {GameLib.API.Vector3 | Number} + * @returns {R3.API.Vector3 | Number} */ -GameLib.API.Vector3.prototype.multiply = function (object, cross) { +R3.API.Vector3.prototype.multiply = function (object, cross) { var x, y, z; var a = object; var b = this; - if (GameLib.Utils.UndefinedOrNull(cross)) { + if (R3.Utils.UndefinedOrNull(cross)) { cross = false; } @@ -163,7 +163,7 @@ GameLib.API.Vector3.prototype.multiply = function (object, cross) { } - if (object instanceof GameLib.API.Vector3) { + if (object instanceof R3.API.Vector3) { if (cross) { @@ -188,11 +188,11 @@ GameLib.API.Vector3.prototype.multiply = function (object, cross) { }; -GameLib.API.Vector3.prototype.dot = function (v) { +R3.API.Vector3.prototype.dot = function (v) { return (this.x * v.x) + (this.y * v.y) + (this.z * v.z); }; -GameLib.API.Vector3.prototype.normalize = function () { +R3.API.Vector3.prototype.normalize = function () { var EPSILON = 0.000001; var v2 = this.squared(); @@ -201,22 +201,22 @@ GameLib.API.Vector3.prototype.normalize = function () { } var invLength = 1.0 / Math.sqrt(v2); - return new GameLib.API.Vector3( + return new R3.API.Vector3( this.x * invLength, this.y * invLength, this.z * invLength ); }; -GameLib.API.Vector3.prototype.clone = function () { - return new GameLib.API.Vector3( +R3.API.Vector3.prototype.clone = function () { + return new R3.API.Vector3( this.x, this.y, this.z ); }; -GameLib.API.Vector3.prototype.applyQuaternion = function(q) { +R3.API.Vector3.prototype.applyQuaternion = function(q) { var x = this.x, y = this.y, z = this.z; var qx = q.x, qy = q.y, qz = q.z, qw = q.w; @@ -236,7 +236,7 @@ GameLib.API.Vector3.prototype.applyQuaternion = function(q) { return this; }; -GameLib.API.Vector3.prototype.clamp = function(min, max) { +R3.API.Vector3.prototype.clamp = function(min, max) { this.x = Math.max( min.x, Math.min( max.x, this.x ) ); this.y = Math.max( min.y, Math.min( max.y, this.y ) ); this.z = Math.max( min.z, Math.min( max.z, this.z ) ); @@ -244,15 +244,15 @@ GameLib.API.Vector3.prototype.clamp = function(min, max) { return this; }; -GameLib.API.Vector3.prototype.length = function() { +R3.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(normal) { +R3.API.Vector3.prototype.reflect = function(normal) { return this.sub( v1.copy( normal ).multiply( 2 * this.dot( normal ) ) ); }; -GameLib.API.Vector3.prototype.angleTo = function (v) { +R3.API.Vector3.prototype.angleTo = function (v) { var theta = this.dot( v ) / ( Math.sqrt( this.lengthSq() * v.lengthSq() ) ); return Math.acos( exports.Math.clamp( theta, - 1, 1 ) ); }; @@ -262,14 +262,14 @@ GameLib.API.Vector3.prototype.angleTo = function (v) { * @param objectVector * @constructor */ -GameLib.API.Vector3.FromObject = function (objectVector) { +R3.API.Vector3.FromObject = function (objectVector) { - if (GameLib.Utils.UndefinedOrNull(objectVector)) { + if (R3.Utils.UndefinedOrNull(objectVector)) { console.warn('vector from db undefined - stale version in db'); objectVector = {}; } - return new GameLib.API.Vector3( + return new R3.API.Vector3( objectVector.x, objectVector.y, objectVector.z diff --git a/src/game-lib-api-vector4.js b/src/r3-api-vector4.js similarity index 56% rename from src/game-lib-api-vector4.js rename to src/r3-api-vector4.js index fdaaef7..442bd2a 100644 --- a/src/game-lib-api-vector4.js +++ b/src/r3-api-vector4.js @@ -1,27 +1,27 @@ -GameLib.API.Vector4 = function (x, y, z, w) { +R3.API.Vector4 = function (x, y, z, w) { - if (GameLib.Utils.UndefinedOrNull(x)) { + if (R3.Utils.UndefinedOrNull(x)) { x = 0; } this.x = x; - if (GameLib.Utils.UndefinedOrNull(y)) { + if (R3.Utils.UndefinedOrNull(y)) { y = 0; } this.y = y; - if (GameLib.Utils.UndefinedOrNull(z)) { + if (R3.Utils.UndefinedOrNull(z)) { z = 0; } this.z = z; - if (GameLib.Utils.UndefinedOrNull(w)) { + if (R3.Utils.UndefinedOrNull(w)) { w = 1; } this.w = w; }; -GameLib.API.Vector4.prototype.equals = function (v) { +R3.API.Vector4.prototype.equals = function (v) { return this.x === v.x && this.y === v.y && this.z === v.z && this.w === v.w; }; @@ -30,14 +30,14 @@ GameLib.API.Vector4.prototype.equals = function (v) { * @param objectVector * @constructor */ -GameLib.API.Vector4.FromObject = function (objectVector) { +R3.API.Vector4.FromObject = function (objectVector) { - if (GameLib.Utils.UndefinedOrNull(objectVector)) { + if (R3.Utils.UndefinedOrNull(objectVector)) { console.warn('vector from db undefined - stale version in db'); objectVector = {}; } - return new GameLib.API.Vector4( + return new R3.API.Vector4( objectVector.x, objectVector.y, objectVector.z, diff --git a/src/game-lib-box3.js b/src/r3-box3.js similarity index 62% rename from src/game-lib-box3.js rename to src/r3-box3.js index 818667a..a2f8524 100644 --- a/src/game-lib-box3.js +++ b/src/r3-box3.js @@ -1,11 +1,11 @@ /** - * GameLib.Box3 + * R3.Box3 * @param implementation * @param apiBox3 * @param parentObject * @constructor */ -GameLib.Box3 = function ( +R3.Box3 = function ( implementation, apiBox3, parentObject @@ -14,16 +14,16 @@ GameLib.Box3 = function ( this.implementation = implementation; this.implementation.isNotThreeThrow(); - if (GameLib.Utils.UndefinedOrNull(parentObject)) { + if (R3.Utils.UndefinedOrNull(parentObject)) { parentObject = null; } this.parentObject = parentObject; - if (GameLib.Utils.UndefinedOrNull(apiBox3)) { + if (R3.Utils.UndefinedOrNull(apiBox3)) { apiBox3 = {}; } - GameLib.API.Box3.call( + R3.API.Box3.call( this, apiBox3.id, apiBox3.name, @@ -32,13 +32,13 @@ GameLib.Box3 = function ( apiBox3.max ); - this.min = new GameLib.Vector3( + this.min = new R3.Vector3( this.implementation, this.min, this ); - this.max = new GameLib.Vector3( + this.max = new R3.Vector3( this.implementation, this.max, this @@ -47,14 +47,14 @@ GameLib.Box3 = function ( this.createInstance(); }; -GameLib.Box3.prototype = Object.create(GameLib.Component.prototype); -GameLib.Box3.prototype.constructor = GameLib.Box3; +R3.Box3.prototype = Object.create(R3.Component.prototype); +R3.Box3.prototype.constructor = R3.Box3; /** - * Creates an instance GameLib.Box3 + * Creates an instance R3.Box3 * @returns {*} */ -GameLib.Box3.prototype.createInstance = function() { +R3.Box3.prototype.createInstance = function() { this.instance = new THREE.Box3( this.min.instance, @@ -64,10 +64,10 @@ GameLib.Box3.prototype.createInstance = function() { }; /** - * Updates GameLib.Box3 instance + * Updates R3.Box3 instance * @param property */ -GameLib.Box3.prototype.updateInstance = function(property) { +R3.Box3.prototype.updateInstance = function(property) { if (property === 'min') { this.instance.min.x = this.min.x; @@ -83,14 +83,14 @@ GameLib.Box3.prototype.updateInstance = function(property) { }; /** - * GameLib.Box3 to GameLib.API.Box3 - * @returns {GameLib.API.Box3} + * R3.Box3 to R3.API.Box3 + * @returns {R3.API.Box3} */ -GameLib.Box3.prototype.toApiObject = function() { - return new GameLib.API.Box3( +R3.Box3.prototype.toApiObject = function() { + return new R3.API.Box3( this.id, this.name, - GameLib.Utils.IdOrNull(this.parentEntity), + R3.Utils.IdOrNull(this.parentEntity), this.min.toApiObject(), this.max.toApiObject() ); diff --git a/src/game-lib-canvas.js b/src/r3-canvas.js similarity index 81% rename from src/game-lib-canvas.js rename to src/r3-canvas.js index 3d4abb4..f766141 100644 --- a/src/game-lib-canvas.js +++ b/src/r3-canvas.js @@ -2,20 +2,20 @@ * Canvas object * @param graphics * @param apiCanvas - * @returns {GameLib.Canvas} + * @returns {R3.Canvas} * @constructor */ -GameLib.Canvas = function( +R3.Canvas = function( graphics, apiCanvas ) { this.graphics = graphics; - if (GameLib.Utils.UndefinedOrNull(apiCanvas)) { + if (R3.Utils.UndefinedOrNull(apiCanvas)) { apiCanvas = {}; } - GameLib.API.Canvas.call( + R3.API.Canvas.call( this, apiCanvas.id, apiCanvas.name, @@ -30,31 +30,31 @@ GameLib.Canvas = function( apiCanvas.textBaseline ); - this.offset = new GameLib.Vector2( + this.offset = new R3.Vector2( this.graphics, this.offset, this ); - GameLib.Component.call( + R3.Component.call( this, { - 'parentTexture' : GameLib.D3.Texture, - 'texts' : [GameLib.D3.Text] + 'parentTexture' : R3.D3.Texture, + 'texts' : [R3.D3.Text] } ); this.context = null; }; -GameLib.Canvas.prototype = Object.create(GameLib.Component.prototype); -GameLib.Canvas.prototype.constructor = GameLib.Canvas; +R3.Canvas.prototype = Object.create(R3.Component.prototype); +R3.Canvas.prototype.constructor = R3.Canvas; /** * Creates a light instance * @returns {*} */ -GameLib.Canvas.prototype.createInstance = function() { +R3.Canvas.prototype.createInstance = function() { this.instance = document.createElement('canvas'); @@ -78,15 +78,15 @@ GameLib.Canvas.prototype.createInstance = function() { this.instance.height = this.height; } - GameLib.Component.prototype.createInstance.call(this); + R3.Component.prototype.createInstance.call(this); }; /** * Updates the instance with the current state */ -GameLib.Canvas.prototype.updateInstance = function(property) { +R3.Canvas.prototype.updateInstance = function(property) { - if (GameLib.Utils.UndefinedOrNull(property)) { + if (R3.Utils.UndefinedOrNull(property)) { console.warn('unknown property update for Canvas: ' + property); } @@ -151,33 +151,33 @@ GameLib.Canvas.prototype.updateInstance = function(property) { return; } - GameLib.Component.prototype.updateInstance.call(this, property); + R3.Component.prototype.updateInstance.call(this, property); }; /** - * Converts a GameLib.Canvas to a GameLib.API.Canvas - * @returns {GameLib.API.Canvas} + * Converts a R3.Canvas to a R3.API.Canvas + * @returns {R3.API.Canvas} */ -GameLib.Canvas.prototype.toApiObject = function() { +R3.Canvas.prototype.toApiObject = function() { - return new GameLib.API.Canvas( + return new R3.API.Canvas( this.id, this.name, - GameLib.Utils.IdOrNull(this.parentEntity), - GameLib.Utils.IdOrNull(this.parentTexture), + R3.Utils.IdOrNull(this.parentEntity), + R3.Utils.IdOrNull(this.parentTexture), this.autoUpdateSize, this.width, this.height, this.offset.toApiObject(), this.tabIndex, this.texts.map(function(text){ - return GameLib.Utils.IdOrNull(text) + return R3.Utils.IdOrNull(text) }), this.textBaseline ); }; -GameLib.Canvas.prototype.writeText = function() { +R3.Canvas.prototype.writeText = function() { this.clear(); @@ -203,7 +203,7 @@ GameLib.Canvas.prototype.writeText = function() { ); }; -GameLib.Canvas.prototype.clear = function() { +R3.Canvas.prototype.clear = function() { if (!this.context) { this.context = this.instance.getContext('2d'); @@ -212,7 +212,7 @@ GameLib.Canvas.prototype.clear = function() { this.context.clearRect(0, 0, this.width, this.height); }; -GameLib.Canvas.prototype.filledRectangle = function( +R3.Canvas.prototype.filledRectangle = function( x, y, width, @@ -231,7 +231,7 @@ GameLib.Canvas.prototype.filledRectangle = function( this.context.fillRect(x, y, width, height); }; -GameLib.Canvas.prototype.outlineRectangle = function( +R3.Canvas.prototype.outlineRectangle = function( x, y, width, @@ -255,7 +255,7 @@ GameLib.Canvas.prototype.outlineRectangle = function( this.context.fillRect(x, y, width, height); }; -GameLib.Canvas.prototype.line = function( +R3.Canvas.prototype.line = function( x, y, endX, @@ -282,7 +282,7 @@ GameLib.Canvas.prototype.line = function( this.context.stroke(); }; -GameLib.Canvas.prototype.text = function( +R3.Canvas.prototype.text = function( text, x, y, @@ -305,7 +305,7 @@ GameLib.Canvas.prototype.text = function( this.context.fillText(text, x, y); }; -GameLib.Canvas.prototype.image = function( +R3.Canvas.prototype.image = function( image, x, y, diff --git a/src/r3-clock.js b/src/r3-clock.js new file mode 100644 index 0000000..e04fe0c --- /dev/null +++ b/src/r3-clock.js @@ -0,0 +1,96 @@ +/** + * Creates a Clock object + * @param graphics + * @param apiClock R3.API.Clock + * @constructor + */ +R3.Clock = function( + graphics, + apiClock +) { + + this.graphics = graphics; + this.graphics.isNotThreeThrow(); + + if (R3.Utils.UndefinedOrNull(apiClock)) { + apiClock = {}; + } + + R3.API.Clock.call( + this, + apiClock.id, + apiClock.name, + apiClock.parentEntity + ); + + R3.Component.call(this); +} ; + +R3.Clock.prototype = Object.create(R3.Component.prototype); +R3.Clock.prototype.constructor = R3.Clock; + +/** + * Creates a camera instance of 'graphics' type (only THREE for now) + * @returns {THREE.Clock} + */ +R3.Clock.prototype.createInstance = function() { + + this.instance = new THREE.Clock(); + + R3.Component.prototype.createInstance.call(this); +}; + +/** + * Updates the instance with the current state + */ +R3.Clock.prototype.updateInstance = function() { + +}; + +R3.Clock.prototype.getDelta = function() { + + var delta = this.instance.getDelta(); + + /** + * clamp the delta to 1/60 + */ + + if (delta > (1 / 30.0)) { + // console.log('clipped ' + (delta - (1/30.0)) + ' seconds - essentially lost time'); + delta = (1 / 30.0); + } + + return delta; +}; + +/** + * Converts a R3.Clock to a new R3.API.Clock + * @returns {R3.API.Clock} + */ +R3.Clock.prototype.toApiObject = function() { + + return new R3.API.Clock( + this.id, + this.name, + R3.Utils.IdOrNull(this.parentEntity) + ); + +}; + +/** + * Converts from an Object camera to a R3.Clock + * @param graphics R3.Graphics + * @param objectClock Object + * @returns {R3.Clock} + * @constructor + */ +R3.Clock.FromObject = function(graphics, objectClock) { + + var apiClock = R3.API.Clock.FromObject(objectClock); + + return new R3.Clock( + graphics, + apiClock + ); + +}; diff --git a/src/game-lib-coder-runtime.js b/src/r3-coder-runtime.js similarity index 52% rename from src/game-lib-coder-runtime.js rename to src/r3-coder-runtime.js index 546d91b..ae1ef1b 100644 --- a/src/game-lib-coder-runtime.js +++ b/src/r3-coder-runtime.js @@ -5,23 +5,23 @@ * @param coderType * @constructor */ -GameLib.CoderRuntime = function( +R3.CoderRuntime = function( id, name, coderType ) { - if (GameLib.Utils.UndefinedOrNull(id)) { - id = GameLib.Utils.RandomId(); + if (R3.Utils.UndefinedOrNull(id)) { + id = R3.Utils.RandomId(); } this.id = id; - if (GameLib.Utils.UndefinedOrNull(name)) { + if (R3.Utils.UndefinedOrNull(name)) { name = 'Coder (' + id + ')'; } this.name = name; - if (GameLib.Utils.UndefinedOrNull(coderType)) { - coderType = GameLib.CoderRuntime.TYPE_CODE_MIRROR; + if (R3.Utils.UndefinedOrNull(coderType)) { + coderType = R3.CoderRuntime.TYPE_CODE_MIRROR; } this.coderType = coderType; @@ -29,20 +29,20 @@ GameLib.CoderRuntime = function( }; /** - * GameLib.CoderRuntime Types + * R3.CoderRuntime Types * @type {number} */ -GameLib.CoderRuntime.TYPE_CODE_MIRROR = 0x1; +R3.CoderRuntime.TYPE_CODE_MIRROR = 0x1; -GameLib.CoderRuntime.prototype.createInstance = function() { - if (this.coderType === GameLib.CoderRuntime.TYPE_CODE_MIRROR) { +R3.CoderRuntime.prototype.createInstance = function() { + if (this.coderType === R3.CoderRuntime.TYPE_CODE_MIRROR) { this.instance = CodeMirror; } else { this.instance = null; } }; -GameLib.CoderRuntime.prototype.updateInstance = function(property) { +R3.CoderRuntime.prototype.updateInstance = function(property) { if (property === 'coderType') { this.createInstance(); } @@ -51,7 +51,7 @@ GameLib.CoderRuntime.prototype.updateInstance = function(property) { /** * Logs a warning and throws an error if not cannon */ -GameLib.CoderRuntime.prototype.isNotCodeMirrorThrow = function() { +R3.CoderRuntime.prototype.isNotCodeMirrorThrow = function() { if (this.instance !== CodeMirror) { console.error('Only CodeMirror supported'); throw new Error('Only CodeMirror supported'); diff --git a/src/game-lib-color.js b/src/r3-color.js similarity index 74% rename from src/game-lib-color.js rename to src/r3-color.js index c976819..a7a5683 100644 --- a/src/game-lib-color.js +++ b/src/r3-color.js @@ -1,12 +1,12 @@ /** * Runtime color for updating instance objects - * @param graphics GameLib.GraphicsRuntime - * @param parentObject GameLib.D3.* - * @param apiColor GameLib.API.Color + * @param graphics R3.GraphicsRuntime + * @param parentObject R3.D3.* + * @param apiColor R3.API.Color * @param grain Number * @constructor */ -GameLib.Color = function ( +R3.Color = function ( graphics, apiColor, parentObject, @@ -16,11 +16,11 @@ GameLib.Color = function ( this.graphics = graphics; this.graphics.isNotThreeThrow(); - if (GameLib.Utils.UndefinedOrNull(apiColor)) { + if (R3.Utils.UndefinedOrNull(apiColor)) { apiColor = {}; } - GameLib.API.Color.call( + R3.API.Color.call( this, apiColor.r, apiColor.g, @@ -28,12 +28,12 @@ GameLib.Color = function ( apiColor.a ); - if (GameLib.Utils.UndefinedOrNull(parentObject)) { + if (R3.Utils.UndefinedOrNull(parentObject)) { parentObject = null; } this.parentObject = parentObject; - if (GameLib.Utils.UndefinedOrNull(grain)) { + if (R3.Utils.UndefinedOrNull(grain)) { grain = 0.001; } this.grain = grain; @@ -41,14 +41,14 @@ GameLib.Color = function ( this.createInstance(); }; -GameLib.Color.prototype = Object.create(GameLib.API.Color.prototype); -GameLib.Color.prototype.constructor = GameLib.Color; +R3.Color.prototype = Object.create(R3.API.Color.prototype); +R3.Color.prototype.constructor = R3.Color; /** * Creates an instance color * @returns {*} */ -GameLib.Color.prototype.createInstance = function() { +R3.Color.prototype.createInstance = function() { this.instance = new THREE.Color( this.r, this.g, @@ -59,7 +59,7 @@ GameLib.Color.prototype.createInstance = function() { /** * Updates the instance color, calls updateInstance on the parent object */ -GameLib.Color.prototype.updateInstance = function(property) { +R3.Color.prototype.updateInstance = function(property) { this.instance.r = this.r; this.instance.g = this.g; @@ -73,10 +73,10 @@ GameLib.Color.prototype.updateInstance = function(property) { /** * Converts runtime color to API Color - * @returns {GameLib.API.Color} + * @returns {R3.API.Color} */ -GameLib.Color.prototype.toApiObject = function() { - return new GameLib.API.Color( +R3.Color.prototype.toApiObject = function() { + return new R3.API.Color( this.r, this.g, this.b, @@ -88,7 +88,7 @@ GameLib.Color.prototype.toApiObject = function() { * Converts the current color to HTML hex format (ex. #ffffff) * @returns {string} */ -GameLib.Color.prototype.toHex = function() { +R3.Color.prototype.toHex = function() { if (this.r < 0) { this.r = 0; @@ -138,7 +138,7 @@ GameLib.Color.prototype.toHex = function() { * @param hex * @returns {string} */ -GameLib.Color.prototype.fromHex = function(hex) { +R3.Color.prototype.fromHex = function(hex) { var matches = hex.match(new RegExp('#+(..)(..)(..)')); diff --git a/src/r3-controls-0.js b/src/r3-controls-0.js new file mode 100644 index 0000000..0fbaee7 --- /dev/null +++ b/src/r3-controls-0.js @@ -0,0 +1,100 @@ +/** + * R3.Controls + * @param apiControls + * @property controlsType + * @constructor + */ +R3.Controls = function ( + apiControls +) { + + if (R3.Utils.UndefinedOrNull(apiControls)) { + apiControls = {}; + } + + R3.API.Controls.call( + this, + apiControls.id, + apiControls.name, + apiControls.controlsType, + apiControls.canvas, + apiControls.parentEntity + ); + + var linkedObjects = { + canvas : R3.Canvas + }; + + var delayed = false; + + switch (this.controlsType) { + case (R3.API.Controls.CONTROLS_TYPE_EDITOR) : + linkedObjects.raycaster = R3.D3.Raycaster; + linkedObjects.camera = R3.D3.Camera; + delayed = true; + break; + case (R3.API.Controls.CONTROLS_TYPE_FIRST_PERSON) : + linkedObjects.camera = R3.D3.Camera; + delayed = true; + break; + case (R3.API.Controls.CONTROLS_TYPE_ORBIT) : + linkedObjects.camera = R3.D3.Camera; + linkedObjects.target = R3.Component; + delayed = true; + break; + } + + R3.Component.call( + this, + linkedObjects, + delayed + ); +}; + +R3.Controls.prototype = Object.create(R3.Component.prototype); +R3.Controls.prototype.constructor = R3.Controls; + +R3.Controls.D3 = function() {}; +R3.Controls.D3.prototype = Object.create(R3.Controls.prototype); +R3.Controls.D3.prototype.constructor = R3.Controls.D3; + +/** + * Creates a mesh instance or updates it + */ +R3.Controls.prototype.createInstance = function() { + R3.Component.prototype.createInstance.call(this); +}; + +/** + * Updates the mesh instance + */ +R3.Controls.prototype.updateInstance = function(property) { + + if (property === 'canvas') { + R3.Event.Emit( + R3.Event.CANVAS_CHANGE, + { + component: this + } + ); + } + + R3.Component.prototype.updateInstance.call(this, property); +}; + +/** + * Converts a R3.Controls to a R3.API.Controls + * @returns {R3.API.Controls} + */ +R3.Controls.prototype.toApiObject = function() { + + var apiControls = new R3.API.Controls( + this.id, + this.name, + this.controlsType, + R3.Utils.IdOrNull(this.canvas), + R3.Utils.IdOrNull(this.parentEntity) + ); + + return apiControls; +}; diff --git a/src/r3-controls-d3-editor.js b/src/r3-controls-d3-editor.js new file mode 100644 index 0000000..344be21 --- /dev/null +++ b/src/r3-controls-d3-editor.js @@ -0,0 +1,116 @@ +/** + * Controls Superset - The apiControls properties get moved into the Controls object itself, and then the instance is created + * @param graphics R3.GraphicsRuntime + * @param apiEditorControls + * @constructor + */ +R3.Controls.D3.Editor = function ( + graphics, + apiEditorControls +) { + + this.graphics = graphics; + this.graphics.isNotThreeThrow(); + + if (R3.Utils.UndefinedOrNull(apiEditorControls)) { + apiEditorControls = { + controlsType : R3.API.Controls.CONTROLS_TYPE_EDITOR + }; + } + + if (R3.Utils.UndefinedOrNull()) { + apiEditorControls.controlsType = R3.API.Controls.CONTROLS_TYPE_EDITOR; + } + + R3.API.Controls.D3.Editor.call( + this, + apiEditorControls, + apiEditorControls.raycaster, + apiEditorControls.camera + ); + + if (this.raycaster instanceof R3.D3.API.Raycaster) { + this.raycaster = new R3.D3.Raycaster( + this.graphics, + this.raycaster + ); + } + + R3.Controls.call( + this, + apiEditorControls + ); + +}; + +/** + * Inheritance + * @type {R3.Controls} + */ +R3.Controls.D3.Editor.prototype = Object.create(R3.Controls.D3.prototype); +R3.Controls.D3.Editor.prototype.constructor = R3.Controls.D3.Editor; + +/** + * Create Instance + */ +R3.Controls.D3.Editor.prototype.createInstance = function() { + + if ( + R3.Utils.UndefinedOrNull(this.camera) || + R3.Utils.UndefinedOrNull(this.camera.instance) + ) { + console.warn('no camera at time of editor-controls create instance'); + return; + } + + if ( + R3.Utils.UndefinedOrNull(this.canvas) || + R3.Utils.UndefinedOrNull(this.canvas.instance) + ) { + console.warn('no canvas at time of editor-controls create instance'); + return; + } + + this.instance = new THREE.EditorControls( + this.camera.instance, + this.canvas.instance + ); + + R3.Controls.prototype.createInstance.call(this); +}; + +/** + * Update Instance + */ +R3.Controls.D3.Editor.prototype.updateInstance = function(property) { + + if ( + property === 'canvas' || + property === 'camera' + ) { + if (R3.Utils.UndefinedOrNull(this.instance)) { + this.createInstance(); + } else { + this.instance.dispose(); + this.createInstance(); + } + } + + 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'); + + R3.Controls.prototype.updateInstance.call(this, property); +}; + +/** + * Converts a R3.Controls.D3.Editor to a R3.D3.API.Mesh + * @returns {R3.API.Controls} + */ +R3.Controls.D3.Editor.prototype.toApiObject = function() { + + var apiControls = R3.Controls.prototype.toApiObject.call(this); + + apiControls.raycaster = R3.Utils.IdOrNull(this.raycaster); + apiControls.camera = R3.Utils.IdOrNull(this.camera); + + return apiControls; +}; diff --git a/src/game-lib-controls-d3-first-person.js b/src/r3-controls-d3-first-person.js similarity index 74% rename from src/game-lib-controls-d3-first-person.js rename to src/r3-controls-d3-first-person.js index 364d74a..2f4ecfa 100644 --- a/src/game-lib-controls-d3-first-person.js +++ b/src/r3-controls-d3-first-person.js @@ -1,10 +1,10 @@ /** * Controls Superset - The apiControls properties get moved into the Controls object itself, and then the instance is created - * @param graphics GameLib.GraphicsRuntime + * @param graphics R3.GraphicsRuntime * @param apiFirstPersonControls * @constructor */ -GameLib.Controls.D3.FirstPerson = function ( +R3.Controls.D3.FirstPerson = function ( graphics, apiFirstPersonControls ) { @@ -12,17 +12,17 @@ GameLib.Controls.D3.FirstPerson = function ( this.graphics = graphics; this.graphics.isNotThreeThrow(); - if (GameLib.Utils.UndefinedOrNull(apiFirstPersonControls)) { + if (R3.Utils.UndefinedOrNull(apiFirstPersonControls)) { apiFirstPersonControls = { - controlsType : GameLib.API.Controls.CONTROLS_TYPE_FIRST_PERSON + controlsType : R3.API.Controls.CONTROLS_TYPE_FIRST_PERSON }; } - if (GameLib.Utils.UndefinedOrNull()) { - apiFirstPersonControls.controlsType = GameLib.API.Controls.CONTROLS_TYPE_FIRST_PERSON; + if (R3.Utils.UndefinedOrNull()) { + apiFirstPersonControls.controlsType = R3.API.Controls.CONTROLS_TYPE_FIRST_PERSON; } - GameLib.API.Controls.D3.FirstPerson.call( + R3.API.Controls.D3.FirstPerson.call( this, apiFirstPersonControls, apiFirstPersonControls.camera, @@ -42,7 +42,7 @@ GameLib.Controls.D3.FirstPerson = function ( apiFirstPersonControls.autoSpeedFactor ); - GameLib.Controls.call( + R3.Controls.call( this, apiFirstPersonControls ); @@ -51,27 +51,27 @@ GameLib.Controls.D3.FirstPerson = function ( /** * Inheritance - * @type {GameLib.Controls} + * @type {R3.Controls} */ -GameLib.Controls.D3.FirstPerson.prototype = Object.create(GameLib.Controls.D3.prototype); -GameLib.Controls.D3.FirstPerson.prototype.constructor = GameLib.Controls.D3.FirstPerson; +R3.Controls.D3.FirstPerson.prototype = Object.create(R3.Controls.D3.prototype); +R3.Controls.D3.FirstPerson.prototype.constructor = R3.Controls.D3.FirstPerson; /** * Create Instance */ -GameLib.Controls.D3.FirstPerson.prototype.createInstance = function() { +R3.Controls.D3.FirstPerson.prototype.createInstance = function() { if ( - GameLib.Utils.UndefinedOrNull(this.camera) || - GameLib.Utils.UndefinedOrNull(this.camera.instance) + R3.Utils.UndefinedOrNull(this.camera) || + R3.Utils.UndefinedOrNull(this.camera.instance) ) { console.warn('no camera at time of editor-controls create instance'); return; } if ( - GameLib.Utils.UndefinedOrNull(this.canvas) || - GameLib.Utils.UndefinedOrNull(this.canvas.instance) + R3.Utils.UndefinedOrNull(this.canvas) || + R3.Utils.UndefinedOrNull(this.canvas.instance) ) { console.warn('no canvas at time of editor-controls create instance'); return; @@ -97,19 +97,19 @@ GameLib.Controls.D3.FirstPerson.prototype.createInstance = function() { this.instance.verticalMax = this.verticalMax; this.instance.autoSpeedFactor = this.autoSpeedFactor; - GameLib.Controls.prototype.createInstance.call(this); + R3.Controls.prototype.createInstance.call(this); }; /** * Update Instance */ -GameLib.Controls.D3.FirstPerson.prototype.updateInstance = function(property) { +R3.Controls.D3.FirstPerson.prototype.updateInstance = function(property) { if ( property === 'canvas' || property === 'camera' ) { - if (GameLib.Utils.UndefinedOrNull(this.instance)) { + if (R3.Utils.UndefinedOrNull(this.instance)) { this.createInstance(); } else { this.instance.dispose(); @@ -188,20 +188,20 @@ GameLib.Controls.D3.FirstPerson.prototype.updateInstance = function(property) { } - GameLib.Controls.prototype.updateInstance.call(this, property); + R3.Controls.prototype.updateInstance.call(this, property); }; /** - * Converts a GameLib.Controls.D3.FirstPerson to a GameLib.D3.API.Mesh - * @returns {GameLib.API.Controls} + * Converts a R3.Controls.D3.FirstPerson to a R3.D3.API.Mesh + * @returns {R3.API.Controls} */ -GameLib.Controls.D3.FirstPerson.prototype.toApiObject = function() { +R3.Controls.D3.FirstPerson.prototype.toApiObject = function() { - var apiControls = GameLib.Controls.prototype.toApiObject.call(this); + var apiControls = R3.Controls.prototype.toApiObject.call(this); - return new GameLib.API.Controls.D3.FirstPerson( + return new R3.API.Controls.D3.FirstPerson( apiControls, - GameLib.Utils.IdOrNull(this.camera), + R3.Utils.IdOrNull(this.camera), this.enabled, this.movementSpeed, this.lookSpeed, diff --git a/src/game-lib-controls-d3-orbit.js b/src/r3-controls-d3-orbit.js similarity index 75% rename from src/game-lib-controls-d3-orbit.js rename to src/r3-controls-d3-orbit.js index b194726..52b6454 100644 --- a/src/game-lib-controls-d3-orbit.js +++ b/src/r3-controls-d3-orbit.js @@ -1,10 +1,10 @@ /** * Controls Superset - The apiControls properties get moved into the Controls object itself, and then the instance is created - * @param graphics GameLib.GraphicsRuntime + * @param graphics R3.GraphicsRuntime * @param apiOrbitControls * @constructor */ -GameLib.Controls.D3.Orbit = function ( +R3.Controls.D3.Orbit = function ( graphics, apiOrbitControls ) { @@ -12,17 +12,17 @@ GameLib.Controls.D3.Orbit = function ( this.graphics = graphics; this.graphics.isNotThreeThrow(); - if (GameLib.Utils.UndefinedOrNull(apiOrbitControls)) { + if (R3.Utils.UndefinedOrNull(apiOrbitControls)) { apiOrbitControls = { - controlsType : GameLib.API.Controls.CONTROLS_TYPE_ORBIT + controlsType : R3.API.Controls.CONTROLS_TYPE_ORBIT }; } - if (GameLib.Utils.UndefinedOrNull()) { - apiOrbitControls.controlsType = GameLib.API.Controls.CONTROLS_TYPE_ORBIT; + if (R3.Utils.UndefinedOrNull()) { + apiOrbitControls.controlsType = R3.API.Controls.CONTROLS_TYPE_ORBIT; } - GameLib.API.Controls.D3.Orbit.call( + R3.API.Controls.D3.Orbit.call( this, apiOrbitControls, apiOrbitControls.camera, @@ -43,7 +43,7 @@ GameLib.Controls.D3.Orbit = function ( apiOrbitControls.enableKeys ); - GameLib.Controls.call( + R3.Controls.call( this, apiOrbitControls ); @@ -52,27 +52,27 @@ GameLib.Controls.D3.Orbit = function ( /** * Inheritance - * @type {GameLib.Controls} + * @type {R3.Controls} */ -GameLib.Controls.D3.Orbit.prototype = Object.create(GameLib.Controls.D3.prototype); -GameLib.Controls.D3.Orbit.prototype.constructor = GameLib.Controls.D3.Orbit; +R3.Controls.D3.Orbit.prototype = Object.create(R3.Controls.D3.prototype); +R3.Controls.D3.Orbit.prototype.constructor = R3.Controls.D3.Orbit; /** * Create Instance */ -GameLib.Controls.D3.Orbit.prototype.createInstance = function() { +R3.Controls.D3.Orbit.prototype.createInstance = function() { if ( - GameLib.Utils.UndefinedOrNull(this.camera) || - GameLib.Utils.UndefinedOrNull(this.camera.instance) + R3.Utils.UndefinedOrNull(this.camera) || + R3.Utils.UndefinedOrNull(this.camera.instance) ) { console.warn('no camera at time of editor-controls create instance'); return; } if ( - GameLib.Utils.UndefinedOrNull(this.canvas) || - GameLib.Utils.UndefinedOrNull(this.canvas.instance) + R3.Utils.UndefinedOrNull(this.canvas) || + R3.Utils.UndefinedOrNull(this.canvas.instance) ) { console.warn('no canvas at time of editor-controls create instance'); return; @@ -102,19 +102,19 @@ GameLib.Controls.D3.Orbit.prototype.createInstance = function() { this.instance.autoRotateSpeed = this.autoRotateSpeed; this.instance.enableKeys = this.enableKeys; - GameLib.Controls.prototype.createInstance.call(this); + R3.Controls.prototype.createInstance.call(this); }; /** * Update Instance */ -GameLib.Controls.D3.Orbit.prototype.updateInstance = function(property) { +R3.Controls.D3.Orbit.prototype.updateInstance = function(property) { if ( property === 'canvas' || property === 'camera' ) { - if (GameLib.Utils.UndefinedOrNull(this.instance)) { + if (R3.Utils.UndefinedOrNull(this.instance)) { this.createInstance(); } else { this.instance.dispose(); @@ -202,21 +202,21 @@ GameLib.Controls.D3.Orbit.prototype.updateInstance = function(property) { return; } - GameLib.Controls.prototype.updateInstance.call(this, property); + R3.Controls.prototype.updateInstance.call(this, property); }; /** - * Converts a GameLib.Controls.D3.Orbit to a GameLib.D3.API.Mesh - * @returns {GameLib.API.Controls} + * Converts a R3.Controls.D3.Orbit to a R3.D3.API.Mesh + * @returns {R3.API.Controls} */ -GameLib.Controls.D3.Orbit.prototype.toApiObject = function() { +R3.Controls.D3.Orbit.prototype.toApiObject = function() { - var apiControls = GameLib.Controls.prototype.toApiObject.call(this); + var apiControls = R3.Controls.prototype.toApiObject.call(this); - return new GameLib.API.Controls.D3.Orbit( + return new R3.API.Controls.D3.Orbit( apiControls, - GameLib.Utils.IdOrNull(this.camera), - GameLib.Utils.IdOrNull(this.target), + R3.Utils.IdOrNull(this.camera), + R3.Utils.IdOrNull(this.target), this.enabled, this.minPolarAngle, this.maxPolarAngle, diff --git a/src/r3-controls-keyboard.js b/src/r3-controls-keyboard.js new file mode 100644 index 0000000..3c4630e --- /dev/null +++ b/src/r3-controls-keyboard.js @@ -0,0 +1,79 @@ +/** + * Keyboard Controls + * @param apiKeyboardControls R3.API.Controls + * @constructor + */ +R3.Controls.Keyboard = function ( + apiKeyboardControls +) { + + if (R3.Utils.UndefinedOrNull(apiKeyboardControls)) { + apiKeyboardControls = { + controlsType : R3.API.Controls.CONTROLS_TYPE_KEYBOARD + }; + } + + R3.API.Controls.Keyboard.call( + this, + apiKeyboardControls + ); + + R3.Controls.call( + this, + apiKeyboardControls + ); +}; + +/** + * Inheritance + * @type {R3.Controls} + */ +R3.Controls.Keyboard.prototype = Object.create(R3.Controls.prototype); +R3.Controls.Keyboard.prototype.constructor = R3.Controls.Keyboard; + +/** + * Create Instance + * @returns + */ +R3.Controls.Keyboard.prototype.createInstance = function() { + /** + * Set instance to true to indicate no dependencies to other components + */ + this.instance = true; + R3.Controls.prototype.createInstance.call(this); +}; + +/** + * Update Instance + */ +R3.Controls.Keyboard.prototype.updateInstance = function(property) { + R3.Controls.prototype.updateInstance.call(this, property); +}; + +/** + * Converts a R3.Controls.Keyboard to a R3.API.Controls + * @returns {R3.API.Controls} + */ +R3.Controls.Keyboard.prototype.toApiObject = function() { + var apiControls = R3.Controls.prototype.toApiObject.call(this); + /** + * add other properties here as this component develops... + */ + return apiControls; +}; + +/** + * Construct an Keyboard Controls object from data + * @param objectControls + * @returns {R3.Controls.Keyboard} + * @constructor + */ +R3.Controls.Keyboard.FromObject = function(objectControls) { + + var apiKeyboardControls = R3.API.Controls.Keyboard.FromObject(objectControls); + + return new R3.Controls.Keyboard( + apiKeyboardControls + ); + +}; \ No newline at end of file diff --git a/src/r3-controls-mouse.js b/src/r3-controls-mouse.js new file mode 100644 index 0000000..c8fa81d --- /dev/null +++ b/src/r3-controls-mouse.js @@ -0,0 +1,79 @@ +/** + * Mouse Controls + * @param apiMouseControls R3.API.Controls + * @constructor + */ +R3.Controls.Mouse = function ( + apiMouseControls +) { + + if (R3.Utils.UndefinedOrNull(apiMouseControls)) { + apiMouseControls = { + controlsType : R3.API.Controls.CONTROLS_TYPE_MOUSE + }; + } + + R3.API.Controls.Mouse.call( + this, + apiMouseControls + ); + + R3.Controls.call( + this, + apiMouseControls + ); +}; + +/** + * Inheritance + * @type {R3.Controls} + */ +R3.Controls.Mouse.prototype = Object.create(R3.Controls.prototype); +R3.Controls.Mouse.prototype.constructor = R3.Controls.Mouse; + +/** + * Create Instance + * @returns + */ +R3.Controls.Mouse.prototype.createInstance = function() { + /** + * Set instance to true to indicate no dependencies to other components + */ + this.instance = true; + R3.Controls.prototype.createInstance.call(this); +}; + +/** + * Update Instance + */ +R3.Controls.Mouse.prototype.updateInstance = function(property) { + R3.Controls.prototype.updateInstance.call(this, property); +}; + +/** + * Converts a R3.Controls.Mouse to a R3.API.Controls + * @returns {R3.API.Controls} + */ +R3.Controls.Mouse.prototype.toApiObject = function() { + var apiControls = R3.Controls.prototype.toApiObject.call(this); + /** + * add other properties here as this component develops... + */ + return apiControls; +}; + +/** + * Construct an Mouse Controls object from data + * @param objectControls + * @returns {R3.Controls.Mouse} + * @constructor + */ +R3.Controls.Mouse.FromObject = function(objectControls) { + + var apiMouseControls = R3.API.Controls.Mouse.FromObject(objectControls); + + return new R3.Controls.Mouse( + apiMouseControls + ); + +}; \ No newline at end of file diff --git a/src/r3-controls-touch.js b/src/r3-controls-touch.js new file mode 100644 index 0000000..4fe08f0 --- /dev/null +++ b/src/r3-controls-touch.js @@ -0,0 +1,82 @@ +/** + * Touch Controls + * @constructor + * @param apiTouchControls + */ +R3.Controls.Touch = function ( + apiTouchControls +) { + + if (R3.Utils.UndefinedOrNull(apiTouchControls)) { + apiTouchControls = { + controlsType : R3.API.Controls.CONTROLS_TYPE_TOUCH + }; + } + + R3.API.Controls.Touch.call( + this, + apiTouchControls, + apiTouchControls.sensitivity + ); + + R3.Controls.call( + this, + apiTouchControls + ); +}; + +/** + * Inheritance + * @type {R3.Controls} + */ +R3.Controls.Touch.prototype = Object.create(R3.Controls.prototype); +R3.Controls.Touch.prototype.constructor = R3.Controls.Touch; + +/** + * Create Instance + * @returns + */ +R3.Controls.Touch.prototype.createInstance = function() { + /** + * Set instance to true to indicate no dependencies to other components + */ + this.instance = true; + R3.Controls.prototype.createInstance.call(this); +}; + +/** + * Update Instance + */ +R3.Controls.Touch.prototype.updateInstance = function(property) { + R3.Controls.prototype.updateInstance.call(this, property); +}; + +/** + * Converts a R3.Controls.Touch to a R3.API.Controls + * @returns {R3.API.Controls} + */ +R3.Controls.Touch.prototype.toApiObject = function() { + + var apiControls = R3.Controls.prototype.toApiObject.call(this); + + apiControls.sensitivity = this.sensitivity; + + /** + * add other properties here as this component develops... + */ + return apiControls; +}; + +/** + * Construct an Touch Controls object from data + * @param objectControls + * @returns {R3.Controls.Touch} + * @constructor + */ +R3.Controls.Touch.FromObject = function(objectControls) { + + var apiTouchControls = R3.API.Controls.Touch.FromObject(objectControls); + + return new R3.Controls.Touch(apiTouchControls); + +}; \ No newline at end of file diff --git a/src/game-lib-curve-a.js b/src/r3-curve-a.js similarity index 50% rename from src/game-lib-curve-a.js rename to src/r3-curve-a.js index 12444e9..c9e4a7c 100644 --- a/src/game-lib-curve-a.js +++ b/src/r3-curve-a.js @@ -1,11 +1,11 @@ /** - * GameLib.Curve - * @param graphics GameLib.GraphicsRuntime - * @param apiCurve GameLib.API.Curve + * R3.Curve + * @param graphics R3.GraphicsRuntime + * @param apiCurve R3.API.Curve * @property curveType * @constructor */ -GameLib.Curve = function( +R3.Curve = function( graphics, apiCurve ) { @@ -13,11 +13,11 @@ GameLib.Curve = function( this.graphics = graphics; this.graphics.isNotThreeThrow(); - if (GameLib.Utils.UndefinedOrNull(apiCurve)) { + if (R3.Utils.UndefinedOrNull(apiCurve)) { apiCurve = {}; } - GameLib.API.Curve.call( + R3.API.Curve.call( this, apiCurve.id, apiCurve.name, @@ -29,58 +29,58 @@ GameLib.Curve = function( var linkedObjects = {}; switch (this.curveType) { - case GameLib.API.Curve.CURVE_TYPE_PATH : - linkedObjects.curves = [GameLib.Curve]; + case R3.API.Curve.CURVE_TYPE_PATH : + linkedObjects.curves = [R3.Curve]; break; } - GameLib.Component.call( + R3.Component.call( this, linkedObjects ); }; -GameLib.Curve.prototype = Object.create(GameLib.Component.prototype); -GameLib.Curve.prototype.constructor = GameLib.Curve; +R3.Curve.prototype = Object.create(R3.Component.prototype); +R3.Curve.prototype.constructor = R3.Curve; /** * Create Instance */ -GameLib.Curve.prototype.createInstance = function() { +R3.Curve.prototype.createInstance = function() { - if (GameLib.Utils.UndefinedOrNull(this.instance)) { + if (R3.Utils.UndefinedOrNull(this.instance)) { console.warn('you should not instantiate this curve object directly'); this.instance = new THREE.Curve(); } this.instance.arcLenghDivisions = this.arcLenghDivisions; - GameLib.Component.prototype.createInstance.call(this); + R3.Component.prototype.createInstance.call(this); }; /** * Updates the instance with the current state */ -GameLib.Curve.prototype.updateInstance = function(property) { +R3.Curve.prototype.updateInstance = function(property) { if (property === 'arcLenghDivisions') { this.instance.arcLenghDivisions = this.arcLenghDivisions; } - GameLib.Component.prototype.updateInstance.call(this, property); + R3.Component.prototype.updateInstance.call(this, property); }; /** - * Converts a GameLib.Curve to a new GameLib.API.Curve - * @returns {GameLib.API.Curve} + * Converts a R3.Curve to a new R3.API.Curve + * @returns {R3.API.Curve} */ -GameLib.Curve.prototype.toApiObject = function() { +R3.Curve.prototype.toApiObject = function() { - return new GameLib.API.Curve( + return new R3.API.Curve( this.id, this.name, this.curveType, - GameLib.Utils.IdOrNull(this.parentEntity), + R3.Utils.IdOrNull(this.parentEntity), this.arcLenghDivisions ); diff --git a/src/game-lib-curve-path-a.js b/src/r3-curve-path-a.js similarity index 54% rename from src/game-lib-curve-path-a.js rename to src/r3-curve-path-a.js index 6b65b39..a6a74df 100644 --- a/src/game-lib-curve-path-a.js +++ b/src/r3-curve-path-a.js @@ -1,10 +1,10 @@ /** - * GameLib.Curve.Path - * @param graphics GameLib.GraphicsRuntime + * R3.Curve.Path + * @param graphics R3.GraphicsRuntime * @param apiCurvePath * @constructor */ -GameLib.Curve.Path = function( +R3.Curve.Path = function( graphics, apiCurvePath ) { @@ -12,13 +12,13 @@ GameLib.Curve.Path = function( this.graphics = graphics; this.graphics.isNotThreeThrow(); - if (GameLib.Utils.UndefinedOrNull(apiCurvePath)) { + if (R3.Utils.UndefinedOrNull(apiCurvePath)) { apiCurvePath = { - curveType : GameLib.API.Curve.CURVE_TYPE_PATH + curveType : R3.API.Curve.CURVE_TYPE_PATH }; } - GameLib.API.Curve.Path.call( + R3.API.Curve.Path.call( this, apiCurvePath, apiCurvePath.curves, @@ -27,8 +27,8 @@ GameLib.Curve.Path = function( this.curves = this.curves.map( function(curve) { - if (curve instanceof GameLib.API.Curve) { - return new GameLib.Curve( + if (curve instanceof R3.API.Curve) { + return new R3.Curve( this.graphics, curve ); @@ -36,7 +36,7 @@ GameLib.Curve.Path = function( }.bind(this) ); - GameLib.Curve.call( + R3.Curve.call( this, this.graphics, this @@ -44,16 +44,16 @@ GameLib.Curve.Path = function( }; -GameLib.Curve.Path.prototype = Object.create(GameLib.Curve.prototype); -GameLib.Curve.Path.prototype.constructor = GameLib.Curve.Path; +R3.Curve.Path.prototype = Object.create(R3.Curve.prototype); +R3.Curve.Path.prototype.constructor = R3.Curve.Path; /** * Creates a camera instance * @returns {*} */ -GameLib.Curve.Path.prototype.createInstance = function() { +R3.Curve.Path.prototype.createInstance = function() { - if (GameLib.Utils.UndefinedOrNull(this.instance)) { + if (R3.Utils.UndefinedOrNull(this.instance)) { console.warn('you should not instantiate this curve object directly'); this.instance = new THREE.CurvePath(); } @@ -66,13 +66,13 @@ GameLib.Curve.Path.prototype.createInstance = function() { this.instance.autoClose = this.autoClose; - GameLib.Curve.prototype.createInstance.call(this); + R3.Curve.prototype.createInstance.call(this); }; /** * Updates the instance with the current state */ -GameLib.Curve.Path.prototype.updateInstance = function(property) { +R3.Curve.Path.prototype.updateInstance = function(property) { if (property === 'curves') { console.warn('todo: update curves'); @@ -84,22 +84,22 @@ GameLib.Curve.Path.prototype.updateInstance = function(property) { return; } - GameLib.Curve.prototype.updateInstance.call(this, property); + R3.Curve.prototype.updateInstance.call(this, property); }; /** - * Converts a GameLib.Curve to a GameLib.API.Curve - * @returns {GameLib.API.Curve} + * Converts a R3.Curve to a R3.API.Curve + * @returns {R3.API.Curve} */ -GameLib.Curve.Path.prototype.toApiObject = function() { +R3.Curve.Path.prototype.toApiObject = function() { - var apiCurve = GameLib.Curve.prototype.toApiObject.call(this); + var apiCurve = R3.Curve.prototype.toApiObject.call(this); - var apiCurvePath = new GameLib.API.Curve.Path( + var apiCurvePath = new R3.API.Curve.Path( apiCurve, this.curves.map( function(curve) { - return GameLib.Utils.IdOrNull(curve); + return R3.Utils.IdOrNull(curve); } ), this.autoClose diff --git a/src/game-lib-curve-path-d2-a.js b/src/r3-curve-path-d2-a.js similarity index 53% rename from src/game-lib-curve-path-d2-a.js rename to src/r3-curve-path-d2-a.js index 0694d51..12c1b2b 100644 --- a/src/game-lib-curve-path-d2-a.js +++ b/src/r3-curve-path-d2-a.js @@ -1,10 +1,10 @@ /** - * GameLib.Curve.Path.D2 - * @param graphics GameLib.GraphicsRuntime + * R3.Curve.Path.D2 + * @param graphics R3.GraphicsRuntime * @param apiCurvePath * @constructor */ -GameLib.Curve.Path.D2 = function( +R3.Curve.Path.D2 = function( graphics, apiCurvePath ) { @@ -12,13 +12,13 @@ GameLib.Curve.Path.D2 = function( this.graphics = graphics; this.graphics.isNotThreeThrow(); - if (GameLib.Utils.UndefinedOrNull(apiCurvePath)) { + if (R3.Utils.UndefinedOrNull(apiCurvePath)) { apiCurvePath = { - curveType : GameLib.API.Curve.CURVE_TYPE_PATH_2D + curveType : R3.API.Curve.CURVE_TYPE_PATH_2D }; } - GameLib.API.Curve.Path.D2.call( + R3.API.Curve.Path.D2.call( this, apiCurvePath, apiCurvePath.points @@ -26,14 +26,14 @@ GameLib.Curve.Path.D2 = function( this.points = this.points.map( function(point) { - return new GameLib.Vector2( + return new R3.Vector2( this.graphics, point ); }.bind(this) ); - GameLib.Curve.Path.call( + R3.Curve.Path.call( this, this.graphics, this @@ -41,16 +41,16 @@ GameLib.Curve.Path.D2 = function( }; -GameLib.Curve.Path.D2.prototype = Object.create(GameLib.Curve.Path.prototype); -GameLib.Curve.Path.D2.prototype.constructor = GameLib.Curve.Path.D2; +R3.Curve.Path.D2.prototype = Object.create(R3.Curve.Path.prototype); +R3.Curve.Path.D2.prototype.constructor = R3.Curve.Path.D2; /** * Creates a camera instance * @returns {*} */ -GameLib.Curve.Path.D2.prototype.createInstance = function() { +R3.Curve.Path.D2.prototype.createInstance = function() { - if (GameLib.Utils.UndefinedOrNull(this.instance)) { + if (R3.Utils.UndefinedOrNull(this.instance)) { this.instance = new THREE.Path( this.points.map( function(point) { @@ -60,13 +60,13 @@ GameLib.Curve.Path.D2.prototype.createInstance = function() { ); } - GameLib.Curve.Path.prototype.createInstance.call(this); + R3.Curve.Path.prototype.createInstance.call(this); }; /** * Updates the instance with the current state */ -GameLib.Curve.Path.D2.prototype.updateInstance = function(property) { +R3.Curve.Path.D2.prototype.updateInstance = function(property) { if (property === 'points') { console.warn('todo: update points (and test it)'); @@ -78,18 +78,18 @@ GameLib.Curve.Path.D2.prototype.updateInstance = function(property) { return; } - GameLib.Curve.Path.prototype.updateInstance.call(this, property); + R3.Curve.Path.prototype.updateInstance.call(this, property); }; /** - * Converts a GameLib.Curve to a GameLib.API.Curve - * @returns {GameLib.API.Curve} + * Converts a R3.Curve to a R3.API.Curve + * @returns {R3.API.Curve} */ -GameLib.Curve.Path.D2.prototype.toApiObject = function() { +R3.Curve.Path.D2.prototype.toApiObject = function() { - var apiCurvePath = GameLib.Curve.Path.prototype.toApiObject.call(this); + var apiCurvePath = R3.Curve.Path.prototype.toApiObject.call(this); - return new GameLib.API.Curve.Path.D2( + return new R3.API.Curve.Path.D2( apiCurvePath, this.points.map( function(point) { diff --git a/src/r3-curve-path-d2-shape.js b/src/r3-curve-path-d2-shape.js new file mode 100644 index 0000000..0249956 --- /dev/null +++ b/src/r3-curve-path-d2-shape.js @@ -0,0 +1,74 @@ +/** + * R3.Curve.Path.D2 + * @param graphics R3.GraphicsRuntime + * @param apiCurvePathD2 + * @constructor + */ +R3.Curve.Path.D2.Shape = function( + graphics, + apiCurvePathD2 +) { + + this.graphics = graphics; + this.graphics.isNotThreeThrow(); + + if (R3.Utils.UndefinedOrNull(apiCurvePathD2)) { + apiCurvePathD2 = { + curveType : R3.API.Curve.CURVE_TYPE_PATH_2D_SHAPE + }; + } + + R3.API.Curve.Path.D2.call( + this, + apiCurvePathD2, + apiCurvePathD2.points + ); + + R3.Curve.Path.D2.call( + this, + this.graphics, + this + ); + +}; + +R3.Curve.Path.D2.Shape.prototype = Object.create(R3.Curve.Path.D2.prototype); +R3.Curve.Path.D2.Shape.prototype.constructor = R3.Curve.Path.D2.Shape; + +/** + * Creates a camera instance + * @returns {*} + */ +R3.Curve.Path.D2.Shape.prototype.createInstance = function() { + + this.instance = new THREE.Shape( + this.points.map( + function(point) { + return point.instance; + } + ) + ); + + R3.Curve.Path.D2.prototype.createInstance.call(this); +}; + +/** + * Updates the instance with the current state + */ +R3.Curve.Path.D2.Shape.prototype.updateInstance = function(property) { + R3.Curve.Path.D2.prototype.updateInstance.call(this, property); +}; + +/** + * Converts a R3.Curve to a R3.API.Curve + * @returns {R3.API.Curve} + */ +R3.Curve.Path.D2.Shape.prototype.toApiObject = function() { + + var apiCurvePathD2 = R3.Curve.Path.D2.prototype.toApiObject.call(this); + + return new R3.API.Curve.Path.D2.Shape( + apiCurvePathD2 + ); + +}; diff --git a/src/game-lib-custom-code.js b/src/r3-custom-code.js similarity index 69% rename from src/game-lib-custom-code.js rename to src/r3-custom-code.js index ef3c237..147e85c 100644 --- a/src/game-lib-custom-code.js +++ b/src/r3-custom-code.js @@ -1,17 +1,17 @@ /** * Creates a CustomCode object - * @param apiCustomCode GameLib.API.CustomCode + * @param apiCustomCode R3.API.CustomCode * @constructor */ -GameLib.CustomCode = function( +R3.CustomCode = function( apiCustomCode ) { - if (GameLib.Utils.UndefinedOrNull(apiCustomCode)) { + if (R3.Utils.UndefinedOrNull(apiCustomCode)) { apiCustomCode = {}; } - GameLib.API.CustomCode.call( + R3.API.CustomCode.call( this, apiCustomCode.id, apiCustomCode.name, @@ -22,13 +22,13 @@ GameLib.CustomCode = function( this.editor = null; - GameLib.Component.call(this); + R3.Component.call(this); }; -GameLib.CustomCode.prototype = Object.create(GameLib.Component.prototype); -GameLib.CustomCode.prototype.constructor = GameLib.CustomCode; +R3.CustomCode.prototype = Object.create(R3.Component.prototype); +R3.CustomCode.prototype.constructor = R3.CustomCode; -GameLib.CustomCode.prototype.createInstance = function() { +R3.CustomCode.prototype.createInstance = function() { try { this.instance = new Function('data', this.code).bind(this); @@ -40,17 +40,17 @@ GameLib.CustomCode.prototype.createInstance = function() { this.instance = new Function('data', "console.log('compilation failed for : " + this.name + "');").bind(this); } - GameLib.Component.prototype.createInstance.call(this); + R3.Component.prototype.createInstance.call(this); }; /** * Updates the instance with the current state */ -GameLib.CustomCode.prototype.updateInstance = function(property) { +R3.CustomCode.prototype.updateInstance = function(property) { if (property === 'name') { - GameLib.Event.Emit( - GameLib.Event.NAME_UPDATE, + R3.Event.Emit( + R3.Event.NAME_UPDATE, { component : this } @@ -63,7 +63,7 @@ GameLib.CustomCode.prototype.updateInstance = function(property) { try { this.instance = new Function('data', this.code).bind(this); this.publish( - GameLib.Event.COMPILE_SUCCESS, + R3.Event.COMPILE_SUCCESS, { component: this } @@ -71,7 +71,7 @@ GameLib.CustomCode.prototype.updateInstance = function(property) { } catch (error) { this.instance = new Function('data', "console.log('compilation update failed for : " + this.name + "');").bind(this); this.publish( - GameLib.Event.COMPILE_FAILED, + R3.Event.COMPILE_FAILED, { component: this } @@ -83,36 +83,36 @@ GameLib.CustomCode.prototype.updateInstance = function(property) { if (property === 'eventId') { this.publish( - GameLib.Event.EVENT_ID_UPDATE, + R3.Event.EVENT_ID_UPDATE, { component : this } ) } - GameLib.Component.prototype.updateInstance.call(this, property); + R3.Component.prototype.updateInstance.call(this, property); }; /** - * Converts a GameLib.CustomCode to a new GameLib.API.CustomCode - * @returns {GameLib.API.CustomCode} + * Converts a R3.CustomCode to a new R3.API.CustomCode + * @returns {R3.API.CustomCode} */ -GameLib.CustomCode.prototype.toApiObject = function() { +R3.CustomCode.prototype.toApiObject = function() { - return new GameLib.API.CustomCode( + return new R3.API.CustomCode( this.id, this.name, this.eventId, this.code, - GameLib.Utils.IdOrNull(this.parentEntity) + R3.Utils.IdOrNull(this.parentEntity) ); }; -GameLib.CustomCode.prototype.launchEditor = function(){ +R3.CustomCode.prototype.launchEditor = function(){ - GameLib.Event.Emit( - GameLib.Event.GET_RUNTIME, + R3.Event.Emit( + R3.Event.GET_RUNTIME, null, function(runtime) { this.coder = runtime.coder; @@ -120,7 +120,7 @@ GameLib.CustomCode.prototype.launchEditor = function(){ }.bind(this) ); - if (this instanceof GameLib.D3.Shader.Vertex) { + if (this instanceof R3.D3.Shader.Vertex) { this.editor = this.coder.instance( document.body, { @@ -132,7 +132,7 @@ GameLib.CustomCode.prototype.launchEditor = function(){ indentUnit: 4 } ); - } else if (this instanceof GameLib.D3.Shader.Fragment) { + } else if (this instanceof R3.D3.Shader.Fragment) { this.editor = this.coder.instance( document.body, { @@ -167,7 +167,7 @@ GameLib.CustomCode.prototype.launchEditor = function(){ }.bind(this)) }; -GameLib.CustomCode.prototype.closeEditor = function(){ +R3.CustomCode.prototype.closeEditor = function(){ var dom = this.editor.getWrapperElement(); dom.parentElement.removeChild(dom); }; \ No newline at end of file diff --git a/src/r3-d3-api-a-object.js b/src/r3-d3-api-a-object.js new file mode 100644 index 0000000..54e6125 --- /dev/null +++ b/src/r3-d3-api-a-object.js @@ -0,0 +1,173 @@ +/** + * R3.D3.API.Object + * @param id + * @param name + * @param objectType + * @param parentEntity + * @param useQuaternion + * @param position + * @param quaternion + * @param rotation + * @param scale + * @param up + * @param lookAt + * @constructor + */ +R3.D3.API.Object = function( + id, + name, + objectType, + parentEntity, + useQuaternion, + position, + quaternion, + rotation, + scale, + up, + lookAt +) { + if (R3.Utils.UndefinedOrNull(id)) { + id = R3.Utils.RandomId(); + } + this.id = id; + + if (R3.Utils.UndefinedOrNull(objectType)) { + objectType = 0; + } + this.objectType = objectType; + + if (R3.Utils.UndefinedOrNull(name)) { + switch (this.objectType) { + case R3.D3.API.Object.OBJECT_TYPE_NONE : + name = 'Object'; + break; + /** + * Cameras + */ + case R3.D3.API.Object.OBJECT_TYPE_CAMERA : + name = 'Camera'; + break; + case R3.D3.API.Object.OBJECT_TYPE_CAMERA_ORTHOGRAPHIC : + name = 'Camera Orthographic'; + break; + case R3.D3.API.Object.OBJECT_TYPE_CAMERA_PERSPECTIVE : + name = 'Camera Perspective'; + break; + case R3.D3.API.Object.OBJECT_TYPE_CAMERA_CUBE : + name = 'Camera Cube'; + break; + case R3.D3.API.Object.OBJECT_TYPE_CAMERA_STEREO : + name = 'Camera Stereo'; + break; + /** + * Meshes + */ + case R3.D3.API.Object.OBJECT_TYPE_MESH : + name = 'Mesh'; + break; + } + name += ' (' + this.id + ')'; + } + this.name = name; + + if (R3.Utils.UndefinedOrNull(useQuaternion)) { + useQuaternion = true; + } + this.useQuaternion = useQuaternion; + + if (R3.Utils.UndefinedOrNull(position)) { + position = new R3.API.Vector3(); + } + this.position = position; + + if (R3.Utils.UndefinedOrNull(quaternion)) { + quaternion = new R3.API.Quaternion(); + } + this.quaternion = quaternion; + + if (R3.Utils.UndefinedOrNull(rotation)) { + rotation = new R3.API.Vector3(); + } + this.rotation = rotation; + + if (R3.Utils.UndefinedOrNull(scale)) { + scale = new R3.API.Vector3(1,1,1); + } + this.scale = scale; + + if (R3.Utils.UndefinedOrNull(up)) { + up = new R3.API.Vector3(0,1,0); + } + this.up = up; + + if (R3.Utils.UndefinedOrNull(lookAt)) { + lookAt = new R3.API.Vector3(); + } + this.lookAt = lookAt; + + R3.API.Component.call( + this, + R3.D3.API.Object.GetComponentType(this.objectType), + parentEntity + ); +}; + +R3.D3.API.Object.prototype = Object.create(R3.API.Component.prototype); +R3.D3.API.Object.prototype.constructor = R3.D3.API.Object; + +R3.D3.API.Object.GetComponentType = function(objectType) { + + var componentType = null; + + switch (objectType) { + case R3.D3.API.Object.OBJECT_TYPE_NONE : + componentType = R3.Component.OBJECT; + break; + /** + * Cameras + */ + case R3.D3.API.Object.OBJECT_TYPE_CAMERA : + componentType = R3.Component.CAMERA; + break; + case R3.D3.API.Object.OBJECT_TYPE_CAMERA_PERSPECTIVE : + componentType = R3.Component.CAMERA_PERSPECTIVE; + break; + case R3.D3.API.Object.OBJECT_TYPE_CAMERA_ORTHOGRAPHIC : + componentType = R3.Component.CAMERA_ORTHOGRAPHIC; + break; + case R3.D3.API.Object.OBJECT_TYPE_CAMERA_STEREO : + componentType = R3.Component.CAMERA_STEREO; + break; + case R3.D3.API.Object.OBJECT_TYPE_CAMERA_CUBE : + componentType = R3.Component.CAMERA_CUBE; + break; + /** + * Meshes + */ + case R3.D3.API.Object.OBJECT_TYPE_MESH : + componentType = R3.Component.MESH; + break; + default: + throw new Error('unsupported camera type: ' + objectType); + } + + return componentType; +}; + +R3.D3.API.Object.OBJECT_TYPE_NONE = 0x0; + +/** + * Cameras + * @type {number} + */ +R3.D3.API.Object.OBJECT_TYPE_CAMERA = 0x11; +R3.D3.API.Object.OBJECT_TYPE_CAMERA_PERSPECTIVE = 0x12;//0x1; +R3.D3.API.Object.OBJECT_TYPE_CAMERA_ORTHOGRAPHIC = 0x13;//0x2; +R3.D3.API.Object.OBJECT_TYPE_CAMERA_STEREO = 0x14;//0x3; +R3.D3.API.Object.OBJECT_TYPE_CAMERA_CUBE = 0x15;//0x4; + +/** + * Meshes + * @type {number} + */ +R3.D3.API.Object.OBJECT_TYPE_MESH = 0x21; diff --git a/src/game-lib-d3-api-animation.js b/src/r3-d3-api-animation.js similarity index 64% rename from src/game-lib-d3-api-animation.js rename to src/r3-d3-api-animation.js index b000643..4c7979f 100644 --- a/src/game-lib-d3-api-animation.js +++ b/src/r3-d3-api-animation.js @@ -14,7 +14,7 @@ * @param parentEntity * @constructor */ -GameLib.D3.API.Animation = function ( +R3.D3.API.Animation = function ( id, name, rotationSpeed, @@ -28,47 +28,47 @@ GameLib.D3.API.Animation = function ( meshes, parentEntity ) { - if (GameLib.Utils.UndefinedOrNull(id)) { - id = GameLib.Utils.RandomId(); + if (R3.Utils.UndefinedOrNull(id)) { + id = R3.Utils.RandomId(); } this.id = id; - if (GameLib.Utils.UndefinedOrNull(name)) { + if (R3.Utils.UndefinedOrNull(name)) { name = 'Animation (' + this.id + ')'; } this.name = name; - if (GameLib.Utils.UndefinedOrNull(rotationSpeed)) { + if (R3.Utils.UndefinedOrNull(rotationSpeed)) { rotationSpeed = 0; } this.rotationSpeed = rotationSpeed; - if (GameLib.Utils.UndefinedOrNull(translationSpeed)) { + if (R3.Utils.UndefinedOrNull(translationSpeed)) { translationSpeed = 0; } this.translationSpeed = translationSpeed; - if (GameLib.Utils.UndefinedOrNull(scaleSpeed)) { + if (R3.Utils.UndefinedOrNull(scaleSpeed)) { scaleSpeed = 0; } this.scaleSpeed = scaleSpeed; - if (GameLib.Utils.UndefinedOrNull(rotationFn)) { + if (R3.Utils.UndefinedOrNull(rotationFn)) { rotationFn = null; } this.rotationFn = rotationFn; - if (GameLib.Utils.UndefinedOrNull(translationFn)) { + if (R3.Utils.UndefinedOrNull(translationFn)) { translationFn = null; } this.translationFn = translationFn; - if (GameLib.Utils.UndefinedOrNull(scaleFn)) { + if (R3.Utils.UndefinedOrNull(scaleFn)) { scaleFn = null; } this.scaleFn = scaleFn; - if (GameLib.Utils.UndefinedOrNull(blocking)) { + if (R3.Utils.UndefinedOrNull(blocking)) { blocking = { position : false, //positions can be blocked from accumulating and executing at once rotation : true, //rotations need to execute in order @@ -77,34 +77,34 @@ GameLib.D3.API.Animation = function ( } this.blocking = blocking; - if (GameLib.Utils.UndefinedOrNull(applyToMeshWhenDone)) { + if (R3.Utils.UndefinedOrNull(applyToMeshWhenDone)) { applyToMeshWhenDone = true; } this.applyToMeshWhenDone = applyToMeshWhenDone; - if (GameLib.Utils.UndefinedOrNull(meshes)) { + if (R3.Utils.UndefinedOrNull(meshes)) { meshes = []; } this.meshes = meshes; - GameLib.API.Component.call( + R3.API.Component.call( this, - GameLib.Component.ANIMATION, + R3.Component.ANIMATION, parentEntity ); }; -GameLib.D3.API.Animation.prototype = Object.create(GameLib.API.Component.prototype); -GameLib.D3.API.Animation.prototype.constructor = GameLib.D3.API.Animation; +R3.D3.API.Animation.prototype = Object.create(R3.API.Component.prototype); +R3.D3.API.Animation.prototype.constructor = R3.D3.API.Animation; /** - * Object to GameLib.D3.API.Animation + * Object to R3.D3.API.Animation * @param objectComponent - * @returns {GameLib.D3.API.Animation} + * @returns {R3.D3.API.Animation} * @constructor */ -GameLib.D3.API.Animation.FromObject = function(objectComponent) { - return new GameLib.D3.API.Animation( +R3.D3.API.Animation.FromObject = function(objectComponent) { + return new R3.D3.API.Animation( objectComponent.id, objectComponent.name, objectComponent.rotationSpeed, diff --git a/src/game-lib-d3-api-audio.js b/src/r3-d3-api-audio.js similarity index 61% rename from src/game-lib-d3-api-audio.js rename to src/r3-d3-api-audio.js index 73338de..eb193d1 100644 --- a/src/game-lib-d3-api-audio.js +++ b/src/r3-d3-api-audio.js @@ -11,7 +11,7 @@ * @param parentEntity * @constructor */ -GameLib.D3.API.Audio = function( +R3.D3.API.Audio = function( id, name, path, @@ -23,73 +23,73 @@ GameLib.D3.API.Audio = function( parentEntity ) { - if (GameLib.Utils.UndefinedOrNull(id)) { - id = GameLib.Utils.RandomId(); + if (R3.Utils.UndefinedOrNull(id)) { + id = R3.Utils.RandomId(); } this.id = id; - if (GameLib.Utils.UndefinedOrNull(name)) { + if (R3.Utils.UndefinedOrNull(name)) { name = 'Audio (' + this.id + ')'; } this.name = name; - if (GameLib.Utils.UndefinedOrNull(path)) { + if (R3.Utils.UndefinedOrNull(path)) { path = ''; } this.path = path; - if (GameLib.Utils.UndefinedOrNull(loop)) { + if (R3.Utils.UndefinedOrNull(loop)) { loop = false; } this.loop = loop; - if (GameLib.Utils.UndefinedOrNull(volume)) { + if (R3.Utils.UndefinedOrNull(volume)) { volume = 0.5; } this.volume = volume; - if (GameLib.Utils.UndefinedOrNull(camera)) { + if (R3.Utils.UndefinedOrNull(camera)) { camera = null; } this.camera = camera; - if (GameLib.Utils.UndefinedOrNull(overplay)) { + if (R3.Utils.UndefinedOrNull(overplay)) { overplay = false; } this.overplay = overplay; - if (GameLib.Utils.UndefinedOrNull(paused)) { + if (R3.Utils.UndefinedOrNull(paused)) { paused = false; } this.paused = paused; - GameLib.API.Component.call( + R3.API.Component.call( this, - GameLib.Component.AUDIO, + R3.Component.AUDIO, parentEntity ); }; -GameLib.D3.API.Audio.prototype = Object.create(GameLib.API.Component.prototype); -GameLib.D3.API.Audio.prototype.constructor = GameLib.D3.API.Audio; +R3.D3.API.Audio.prototype = Object.create(R3.API.Component.prototype); +R3.D3.API.Audio.prototype.constructor = R3.D3.API.Audio; /** * Creates an API Audio from an Object Audio * @param objectAudio * @constructor */ -GameLib.D3.API.Audio.FromObject = function(objectAudio) { +R3.D3.API.Audio.FromObject = function(objectAudio) { var apiCamera = null; if (objectAudio.camera) { if (objectAudio.camera instanceof Object) { - apiCamera = GameLib.D3.API.Camera.FromObject(objectAudio.camera); + apiCamera = R3.D3.API.Camera.FromObject(objectAudio.camera); } else { apiCamera = objectAudio.camera; } } - return new GameLib.D3.API.Audio( + return new R3.D3.API.Audio( objectAudio.id, objectAudio.name, objectAudio.path, diff --git a/src/game-lib-d3-api-bone-weight.js b/src/r3-d3-api-bone-weight.js similarity index 61% rename from src/game-lib-d3-api-bone-weight.js rename to src/r3-d3-api-bone-weight.js index 08f7dad..26e139f 100644 --- a/src/game-lib-d3-api-bone-weight.js +++ b/src/r3-d3-api-bone-weight.js @@ -4,7 +4,7 @@ * @param weight float * @constructor */ -GameLib.D3.API.BoneWeight = function ( +R3.D3.API.BoneWeight = function ( boneIndex, weight ) { @@ -13,13 +13,13 @@ GameLib.D3.API.BoneWeight = function ( }; /** - * Object to GameLib.D3.API.BoneWeight + * Object to R3.D3.API.BoneWeight * @param objectBoneWeight - * @returns {GameLib.D3.API.BoneWeight} + * @returns {R3.D3.API.BoneWeight} * @constructor */ -GameLib.D3.API.BoneWeight.FromObject = function(objectBoneWeight) { - return new GameLib.D3.API.BoneWeight( +R3.D3.API.BoneWeight.FromObject = function(objectBoneWeight) { + return new R3.D3.API.BoneWeight( objectBoneWeight.boneIndex, objectBoneWeight.weight ) diff --git a/src/r3-d3-api-bone.js b/src/r3-d3-api-bone.js new file mode 100644 index 0000000..de34c70 --- /dev/null +++ b/src/r3-d3-api-bone.js @@ -0,0 +1,93 @@ +/** + * Bone Superset + * @param id + * @param name string + * @param childBoneIds + * @param parentBoneIds + * @param quaternion R3.API.Quaternion + * @param position R3.API.Vector3 + * @param scale R3.API.Vector3 + * @param up R3.API.Vector3 + * @param parentEntity + * @constructor + */ +R3.D3.API.Bone = function ( + id, + name, + childBoneIds, + parentBoneIds, + position, + quaternion, + scale, + up, + parentEntity +) { + + if (R3.Utils.UndefinedOrNull(id)) { + id = R3.Utils.RandomId(); + } + this.id = id; + + if (R3.Utils.UndefinedOrNull(name)) { + name = 'Bone (' + this.id + ')'; + } + this.name = name; + + if (R3.Utils.UndefinedOrNull(childBoneIds)) { + childBoneIds = []; + } + this.childBoneIds = childBoneIds; + + if (R3.Utils.UndefinedOrNull(parentBoneIds)) { + parentBoneIds = []; + } + this.parentBoneIds = parentBoneIds; + + if (R3.Utils.UndefinedOrNull(position)) { + position = new R3.API.Vector3(); + } + this.position = position; + + if (R3.Utils.UndefinedOrNull(quaternion)) { + quaternion = new R3.API.Quaternion(); + } + this.quaternion = quaternion; + + if (R3.Utils.UndefinedOrNull(scale)) { + scale = new R3.API.Vector3(1,1,1); + } + this.scale = scale; + + if (R3.Utils.UndefinedOrNull(up)) { + up = new R3.API.Vector3(0,1,0); + } + this.up = up; + + R3.API.Component.call( + this, + R3.Component.BONE, + parentEntity + ); +}; + +R3.D3.API.Bone.prototype = Object.create(R3.API.Component.prototype); +R3.D3.API.Bone.prototype.constructor = R3.D3.API.Bone; + +/** + * Returns an API bone from an Object bone + * @param objectBone + * @constructor + */ +R3.D3.API.Bone.FromObject = function(objectBone) { + return new R3.D3.API.Bone( + objectBone.id, + objectBone.name, + objectBone.childBoneIds, + objectBone.parentBoneIds, + R3.API.Vector3.FromObject(objectBone.position), + R3.API.Quaternion.FromObject(objectBone.quaternion), + R3.API.Vector3.FromObject(objectBone.scale), + R3.API.Vector3.FromObject(objectBone.up), + objectBone.parentEntity + ); +}; diff --git a/src/game-lib-d3-api-broadphase.js b/src/r3-d3-api-broadphase.js similarity index 52% rename from src/game-lib-d3-api-broadphase.js rename to src/r3-d3-api-broadphase.js index 44800d2..70bdab0 100644 --- a/src/game-lib-d3-api-broadphase.js +++ b/src/r3-d3-api-broadphase.js @@ -6,45 +6,45 @@ * @param parentEntity * @constructor */ -GameLib.D3.API.Broadphase = function( +R3.D3.API.Broadphase = function( id, name, broadphaseType, parentEntity ) { - if (GameLib.Utils.UndefinedOrNull(id)) { - id = GameLib.Utils.RandomId(); + if (R3.Utils.UndefinedOrNull(id)) { + id = R3.Utils.RandomId(); } this.id = id; - if (GameLib.Utils.UndefinedOrNull(name)) { + if (R3.Utils.UndefinedOrNull(name)) { name = 'Broadphase (' + this.id + ')'; } this.name = name; - if (GameLib.Utils.UndefinedOrNull(broadphaseType)) { - broadphaseType = GameLib.D3.Broadphase.BROADPHASE_TYPE_NAIVE; + if (R3.Utils.UndefinedOrNull(broadphaseType)) { + broadphaseType = R3.D3.Broadphase.BROADPHASE_TYPE_NAIVE; } this.broadphaseType = broadphaseType; - GameLib.API.Component.call( + R3.API.Component.call( this, - GameLib.Component.BROADPHASE, + R3.Component.BROADPHASE, parentEntity ); }; -GameLib.D3.API.Broadphase.prototype = Object.create(GameLib.API.Component.prototype); -GameLib.D3.API.Broadphase.prototype.constructor = GameLib.D3.API.Broadphase; +R3.D3.API.Broadphase.prototype = Object.create(R3.API.Component.prototype); +R3.D3.API.Broadphase.prototype.constructor = R3.D3.API.Broadphase; /** * Creates an API Broadphase from an Object Broadphase * @param objectBroadphase * @constructor */ -GameLib.D3.API.Broadphase.FromObject = function(objectBroadphase) { - return new GameLib.D3.API.Broadphase( +R3.D3.API.Broadphase.FromObject = function(objectBroadphase) { + return new R3.D3.API.Broadphase( objectBroadphase.id, objectBroadphase.name, objectBroadphase.broadphaseType, diff --git a/src/r3-d3-api-camera-a.js b/src/r3-d3-api-camera-a.js new file mode 100644 index 0000000..54ca09a --- /dev/null +++ b/src/r3-d3-api-camera-a.js @@ -0,0 +1,52 @@ +/** + * R3.D3.API.Camera + * @param apiD3Object + * @param aspect + * @constructor + */ +R3.D3.API.Camera = function( + apiD3Object, + aspect +) { + + if (R3.Utils.UndefinedOrNull(apiD3Object)) { + apiD3Object = { + objectType : R3.D3.API.Object.OBJECT_TYPE_CAMERA + }; + } + + if (R3.Utils.UndefinedOrNull(apiD3Object.objectType)) { + apiD3Object.objectType = R3.D3.API.Object.OBJECT_TYPE_CAMERA; + } + + if (R3.Utils.UndefinedOrNull(aspect)) { + aspect = 1; + } + this.aspect = aspect; + + if (R3.Utils.UndefinedOrNull(apiD3Object.position)) { + apiD3Object.position = new R3.API.Vector3( + 15, + 15, + 15 + ); + } + + R3.D3.API.Object.call( + this, + apiD3Object.id, + apiD3Object.name, + apiD3Object.objectType, + apiD3Object.parentEntity, + apiD3Object.useQuaternion, + apiD3Object.position, + apiD3Object.quaternion, + apiD3Object.rotation, + apiD3Object.scale, + apiD3Object.up, + apiD3Object.lookAt + ); +}; + +R3.D3.API.Camera.prototype = Object.create(R3.D3.API.Object.prototype); +R3.D3.API.Camera.prototype.constructor = R3.D3.API.Camera; diff --git a/src/r3-d3-api-camera-cube.js b/src/r3-d3-api-camera-cube.js new file mode 100644 index 0000000..48a7c85 --- /dev/null +++ b/src/r3-d3-api-camera-cube.js @@ -0,0 +1,59 @@ +/** + * R3.D3.API.Camera.Cube + * @constructor + * @param apiD3ObjectCamera + * @param near + * @param far + * @param cubeResolution + * @param renderTarget + */ +R3.D3.API.Camera.Cube = function( + apiD3ObjectCamera, + near, + far, + cubeResolution, + renderTarget +) { + + if (R3.Utils.UndefinedOrNull(apiD3ObjectCamera)) { + apiD3ObjectCamera = { + objectType : R3.D3.API.Object.OBJECT_TYPE_CAMERA_CUBE + }; + } + + if (R3.Utils.UndefinedOrNull(apiD3ObjectCamera.objectType)) { + apiD3ObjectCamera.objectType = R3.D3.API.Object.OBJECT_TYPE_CAMERA_CUBE; + } + + if (R3.Utils.UndefinedOrNull(near)) { + near = 0.1; + } + this.near = near; + + if (R3.Utils.UndefinedOrNull(far)) { + far = 2000; + } + this.far = far; + + if (R3.Utils.UndefinedOrNull(cubeResolution)) { + cubeResolution = 128; + } + this.cubeResolution = cubeResolution; + + if (R3.Utils.UndefinedOrNull(renderTarget)) { + renderTarget = null; + } + this.renderTarget = renderTarget; + + /** + * CubeCamera's have hardcoded fov=90 and aspect=1 + */ + R3.D3.API.Camera.call( + this, + apiD3ObjectCamera, + apiD3ObjectCamera.aspect + ); +}; + +R3.D3.API.Camera.Cube.prototype = Object.create(R3.D3.API.Camera.prototype); +R3.D3.API.Camera.Cube.prototype.constructor = R3.D3.API.Camera.Cube; diff --git a/src/game-lib-d3-api-camera-orthographic.js b/src/r3-d3-api-camera-orthographic.js similarity index 51% rename from src/game-lib-d3-api-camera-orthographic.js rename to src/r3-d3-api-camera-orthographic.js index fa363b5..b8611d1 100644 --- a/src/game-lib-d3-api-camera-orthographic.js +++ b/src/r3-d3-api-camera-orthographic.js @@ -1,5 +1,5 @@ /** - * GameLib.D3.API.Camera.Orthographic + * R3.D3.API.Camera.Orthographic * * OK - since the introduction of fixed aspect ratio's for our canvases, we only need to know * the aspect ratio and width - then we calculate the left, right, up and down coords - @@ -30,7 +30,7 @@ * @param bottom * @param zoom */ -GameLib.D3.API.Camera.Orthographic = function( +R3.D3.API.Camera.Orthographic = function( apiD3ObjectCamera, aspectRatioMode, minWidth, @@ -46,99 +46,99 @@ GameLib.D3.API.Camera.Orthographic = function( zoom ) { - if (GameLib.Utils.UndefinedOrNull(apiD3ObjectCamera)) { + if (R3.Utils.UndefinedOrNull(apiD3ObjectCamera)) { apiD3ObjectCamera = { - objectType : GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_ORTHOGRAPHIC + objectType : R3.D3.API.Object.OBJECT_TYPE_CAMERA_ORTHOGRAPHIC }; } - if (GameLib.Utils.UndefinedOrNull(apiD3ObjectCamera.objectType)) { - apiD3ObjectCamera.objectType = GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_ORTHOGRAPHIC; + if (R3.Utils.UndefinedOrNull(apiD3ObjectCamera.objectType)) { + apiD3ObjectCamera.objectType = R3.D3.API.Object.OBJECT_TYPE_CAMERA_ORTHOGRAPHIC; } - if (GameLib.Utils.UndefinedOrNull(apiD3ObjectCamera.position)) { - apiD3ObjectCamera.position = new GameLib.API.Vector3(0,0,10); + if (R3.Utils.UndefinedOrNull(apiD3ObjectCamera.position)) { + apiD3ObjectCamera.position = new R3.API.Vector3(0,0,10); } - if (GameLib.Utils.UndefinedOrNull(apiD3ObjectCamera.lookAt)) { - apiD3ObjectCamera.lookAt = new GameLib.API.Vector3(0,0,-10); + if (R3.Utils.UndefinedOrNull(apiD3ObjectCamera.lookAt)) { + apiD3ObjectCamera.lookAt = new R3.API.Vector3(0,0,-10); } - if (GameLib.Utils.UndefinedOrNull(aspectRatioMode)) { - aspectRatioMode = GameLib.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_BASED_ON_CURRENT; + if (R3.Utils.UndefinedOrNull(aspectRatioMode)) { + aspectRatioMode = R3.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_BASED_ON_CURRENT; } this.aspectRatioMode = aspectRatioMode; - if (GameLib.Utils.UndefinedOrNull(minWidth)) { + if (R3.Utils.UndefinedOrNull(minWidth)) { minWidth = 10; } this.minWidth = minWidth; - if (GameLib.Utils.UndefinedOrNull(minHeight)) { + if (R3.Utils.UndefinedOrNull(minHeight)) { minHeight = 10; } this.minHeight = minHeight; - if (GameLib.Utils.UndefinedOrNull(height)) { + if (R3.Utils.UndefinedOrNull(height)) { height = 10; } this.height = height; - if (GameLib.Utils.UndefinedOrNull(width)) { + if (R3.Utils.UndefinedOrNull(width)) { width = 10; } this.width = width; - if (GameLib.Utils.UndefinedOrNull(height)) { + if (R3.Utils.UndefinedOrNull(height)) { height = 10; } this.height = height; - if (GameLib.Utils.UndefinedOrNull(near)) { + if (R3.Utils.UndefinedOrNull(near)) { near = 0.1; } this.near = near; - if (GameLib.Utils.UndefinedOrNull(far)) { + if (R3.Utils.UndefinedOrNull(far)) { far = 2000; } this.far = far; - if (GameLib.Utils.UndefinedOrNull(left)) { + if (R3.Utils.UndefinedOrNull(left)) { left = -5; } this.left = left; - if (GameLib.Utils.UndefinedOrNull(right)) { + if (R3.Utils.UndefinedOrNull(right)) { right = 5; } this.right = right; - if (GameLib.Utils.UndefinedOrNull(top)) { + if (R3.Utils.UndefinedOrNull(top)) { top = 5; } this.top = top; - if (GameLib.Utils.UndefinedOrNull(bottom)) { + if (R3.Utils.UndefinedOrNull(bottom)) { bottom = -5; } this.bottom = bottom; - if (GameLib.Utils.UndefinedOrNull(zoom)) { + if (R3.Utils.UndefinedOrNull(zoom)) { zoom = 1; } this.zoom = zoom; - GameLib.D3.API.Camera.call( + R3.D3.API.Camera.call( this, apiD3ObjectCamera, apiD3ObjectCamera.aspect ); }; -GameLib.D3.API.Camera.Orthographic.prototype = Object.create(GameLib.D3.API.Camera.prototype); -GameLib.D3.API.Camera.Orthographic.prototype.constructor = GameLib.D3.API.Camera.Orthographic; +R3.D3.API.Camera.Orthographic.prototype = Object.create(R3.D3.API.Camera.prototype); +R3.D3.API.Camera.Orthographic.prototype.constructor = R3.D3.API.Camera.Orthographic; -GameLib.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_NONE = 0x0; -GameLib.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_FIXED = 0x1; -GameLib.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_BASED_ON_CURRENT = 0x2; +R3.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_NONE = 0x0; +R3.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_FIXED = 0x1; +R3.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_BASED_ON_CURRENT = 0x2; diff --git a/src/r3-d3-api-camera-perspective.js b/src/r3-d3-api-camera-perspective.js new file mode 100644 index 0000000..ad79bfc --- /dev/null +++ b/src/r3-d3-api-camera-perspective.js @@ -0,0 +1,84 @@ +/** + * R3.D3.API.Camera.Perspective + * @constructor + * @param apiD3ObjectCamera + * @param fov + * @param near + * @param far + * @param filmGauge + * @param filmOffset + * @param focus + * @param zoom + */ +R3.D3.API.Camera.Perspective = function( + apiD3ObjectCamera, + near, + far, + fov, + filmGauge, + filmOffset, + focus, + zoom +) { + + if (R3.Utils.UndefinedOrNull(apiD3ObjectCamera)) { + apiD3ObjectCamera = { + objectType : R3.D3.API.Object.OBJECT_TYPE_CAMERA_PERSPECTIVE + }; + } + + if (R3.Utils.UndefinedOrNull(apiD3ObjectCamera.objectType)) { + apiD3ObjectCamera.objectType = R3.D3.API.Object.OBJECT_TYPE_CAMERA_PERSPECTIVE; + } + + if (R3.Utils.UndefinedOrNull(near)) { + // near = new R3.API.Number(0.1, 0.001, 0.001, 2000); + near = 0.1; + } + this.near = near; + + if (R3.Utils.UndefinedOrNull(far)) { + // far = new R3.API.Number(2000, 1, 1, 4000); + far = 2000; + } + this.far = far; + + if (R3.Utils.UndefinedOrNull(fov)) { + // fov = new R3.API.Number(50, 1, 0, 180); + fov = 50; + } + this.fov = fov; + + if (R3.Utils.UndefinedOrNull(filmGauge)) { + // filmGauge = new R3.API.Number(35, 1, 0, 200); + filmGauge = 35; + } + this.filmGauge = filmGauge; + + if (R3.Utils.UndefinedOrNull(filmOffset)) { + // filmOffset = new R3.API.Number(0, 1, 0, 200); + filmOffset = 0; + } + this.filmOffset = filmOffset; + + if (R3.Utils.UndefinedOrNull(focus)) { + // focus = new R3.API.Number(10, 0.1, 0, 200); + focus = 10; + } + this.focus = focus; + + if (R3.Utils.UndefinedOrNull(zoom)) { + // zoom = new R3.API.Number(1, 0.01, 0, 10); + zoom = 1; + } + this.zoom = zoom; + + R3.D3.API.Camera.call( + this, + apiD3ObjectCamera, + apiD3ObjectCamera.aspect + ); +}; + +R3.D3.API.Camera.Perspective.prototype = Object.create(R3.D3.API.Camera.prototype); +R3.D3.API.Camera.Perspective.prototype.constructor = R3.D3.API.Camera.Perspective; \ No newline at end of file diff --git a/src/r3-d3-api-camera-stereo-a.js b/src/r3-d3-api-camera-stereo-a.js new file mode 100644 index 0000000..dad747a --- /dev/null +++ b/src/r3-d3-api-camera-stereo-a.js @@ -0,0 +1,40 @@ +/** + * R3.D3.API.Camera.Stereo + * @constructor + * @param apiD3ObjectCamera + * @param stereoMode + */ +R3.D3.API.Camera.Stereo = function( + apiD3ObjectCamera, + stereoMode +) { + + if (R3.Utils.UndefinedOrNull(apiD3ObjectCamera)) { + apiD3ObjectCamera = { + objectType : R3.D3.API.Object.OBJECT_TYPE_CAMERA_STEREO + }; + } + + if (R3.Utils.UndefinedOrNull(apiD3ObjectCamera.objectType)) { + apiD3ObjectCamera.objectType = R3.D3.API.Object.OBJECT_TYPE_CAMERA_STEREO; + } + + + if (R3.Utils.UndefinedOrNull(stereoMode)) { + stereoMode = R3.D3.API.Camera.Stereo.STEREO_MODE_STEREO; + } + this.stereoMode = stereoMode; + + R3.D3.API.Camera.call( + this, + apiD3ObjectCamera, + apiD3ObjectCamera.aspect + ); +}; + +R3.D3.API.Camera.Stereo.prototype = Object.create(R3.D3.API.Camera.prototype); +R3.D3.API.Camera.Stereo.prototype.constructor = R3.D3.API.Camera.Stereo; + +R3.D3.API.Camera.Stereo.STEREO_MODE_STEREO = 0x1; +R3.D3.API.Camera.Stereo.STEREO_MODE_ANAGLYPH = 0x2; +R3.D3.API.Camera.Stereo.STEREO_MODE_PARALLAX = 0x3; diff --git a/src/game-lib-d3-api-composer.js b/src/r3-d3-api-composer.js similarity index 53% rename from src/game-lib-d3-api-composer.js rename to src/r3-d3-api-composer.js index fae34cd..8852e0d 100644 --- a/src/game-lib-d3-api-composer.js +++ b/src/r3-d3-api-composer.js @@ -1,5 +1,5 @@ /** - * GameLib.D3.API.Composer + * R3.D3.API.Composer * @param id * @param name * @param parentEntity @@ -11,7 +11,7 @@ * @param passes * @constructor */ -GameLib.D3.API.Composer = function ( +R3.D3.API.Composer = function ( id, name, parentEntity, @@ -22,52 +22,52 @@ GameLib.D3.API.Composer = function ( renderTarget, passes ) { - if (GameLib.Utils.UndefinedOrNull(id)) { - id = GameLib.Utils.RandomId(); + if (R3.Utils.UndefinedOrNull(id)) { + id = R3.Utils.RandomId(); } this.id = id; - if (GameLib.Utils.UndefinedOrNull(name)) { + if (R3.Utils.UndefinedOrNull(name)) { name = 'Composer (' + id + ')'; } this.name = name; - if (GameLib.Utils.UndefinedOrNull(autoUpdateSize)) { + if (R3.Utils.UndefinedOrNull(autoUpdateSize)) { autoUpdateSize = true; } this.autoUpdateSize = autoUpdateSize; - if (GameLib.Utils.UndefinedOrNull(width)) { + if (R3.Utils.UndefinedOrNull(width)) { width = 512; } this.width = width; - if (GameLib.Utils.UndefinedOrNull(height)) { + if (R3.Utils.UndefinedOrNull(height)) { height = 512; } this.height = height; - if (GameLib.Utils.UndefinedOrNull(renderer)) { + if (R3.Utils.UndefinedOrNull(renderer)) { renderer = null; } this.renderer = renderer; - if (GameLib.Utils.UndefinedOrNull(renderTarget)) { + if (R3.Utils.UndefinedOrNull(renderTarget)) { renderTarget = null; } this.renderTarget = renderTarget; - if (GameLib.Utils.UndefinedOrNull(passes)) { + if (R3.Utils.UndefinedOrNull(passes)) { passes = []; } this.passes = passes; - GameLib.API.Component.call( + R3.API.Component.call( this, - GameLib.Component.COMPOSER, + R3.Component.COMPOSER, parentEntity ); }; -GameLib.D3.API.Composer.prototype = Object.create(GameLib.API.Component.prototype); -GameLib.D3.API.Composer.prototype.constructor = GameLib.D3.API.Composer; +R3.D3.API.Composer.prototype = Object.create(R3.API.Component.prototype); +R3.D3.API.Composer.prototype.constructor = R3.D3.API.Composer; diff --git a/src/r3-d3-api-effect-a.js b/src/r3-d3-api-effect-a.js new file mode 100644 index 0000000..151219e --- /dev/null +++ b/src/r3-d3-api-effect-a.js @@ -0,0 +1,100 @@ +/** + * R3.D3.API.Effect + * @param id + * @param name + * @param effectType + * @param parentEntity + * @param renderer + * @param width + * @param height + * + * @property effectType + * + * @constructor + */ +R3.D3.API.Effect = function( + id, + name, + effectType, + parentEntity, + renderer, + width, + height +) { + + if (R3.Utils.UndefinedOrNull(id)) { + id = R3.Utils.RandomId(); + } + this.id = id; + + if (R3.Utils.UndefinedOrNull(effectType)) { + effectType = R3.D3.API.Effect.EFFECT_TYPE_NONE; + } + this.effectType = effectType; + + if (R3.Utils.UndefinedOrNull(name)) { + + switch (this.effectType) { + case R3.D3.API.Effect.EFFECT_TYPE_ANAGLYPH : + name = 'Effect Anaglyph'; + break; + case R3.D3.API.Effect.EFFECT_TYPE_PARALLAX : + name = 'Effect Parallax'; + break; + case R3.D3.API.Effect.EFFECT_TYPE_STEREO : + name = 'Effect Stereo'; + break; + default : + console.warn('no nice name for effect'); + name = 'Effect'; + } + + name += ' (' + this.id + ')'; + } + this.name = name; + + if (R3.Utils.UndefinedOrNull(renderer)) { + renderer = null; + } + this.renderer = renderer; + + if (R3.Utils.UndefinedOrNull(width)) { + width = 512; + } + this.width = width; + + if (R3.Utils.UndefinedOrNull(height)) { + height = 512; + } + this.height = height; + + var componentType = null; + + switch (this.effectType) { + case R3.D3.API.Effect.EFFECT_TYPE_STEREO : + componentType = R3.Component.EFFECT_STEREO; + break; + case R3.D3.API.Effect.EFFECT_TYPE_ANAGLYPH : + componentType = R3.Component.EFFECT_ANAGLYPH; + break; + case R3.D3.API.Effect.EFFECT_TYPE_PARALLAX : + componentType = R3.Component.EFFECT_PARALLAX; + break; + default: + throw new Error('unsupported effect type: ' + this.effectType); + } + + R3.API.Component.call( + this, + componentType, + parentEntity + ); +}; + +R3.D3.API.Effect.prototype = Object.create(R3.API.Component.prototype); +R3.D3.API.Effect.prototype.constructor = R3.D3.API.Effect; + +R3.D3.API.Effect.EFFECT_TYPE_NONE = 0x0; +R3.D3.API.Effect.EFFECT_TYPE_STEREO = 0x1; +R3.D3.API.Effect.EFFECT_TYPE_ANAGLYPH = 0x2; +R3.D3.API.Effect.EFFECT_TYPE_PARALLAX = 0x3; diff --git a/src/r3-d3-api-effect-anaglyph.js b/src/r3-d3-api-effect-anaglyph.js new file mode 100644 index 0000000..1d3288d --- /dev/null +++ b/src/r3-d3-api-effect-anaglyph.js @@ -0,0 +1,34 @@ +/** + * R3.D3.API.Effect.Anaglyph + * @constructor + * @param apiEffect + */ +R3.D3.API.Effect.Anaglyph = function( + apiEffect +) { + + if (R3.Utils.UndefinedOrNull(apiEffect)) { + apiEffect = { + effectType : R3.D3.API.Effect.EFFECT_TYPE_ANAGLYPH + }; + } + + if (R3.Utils.UndefinedOrNull(apiEffect.cameraType)) { + apiEffect.effectType = R3.D3.API.Effect.EFFECT_TYPE_ANAGLYPH; + } + + R3.D3.API.Effect.call( + this, + apiEffect.id, + apiEffect.name, + apiEffect.effectType, + apiEffect.parentEntity, + apiEffect.renderer, + apiEffect.width, + apiEffect.height + ); + +}; + +R3.D3.API.Effect.Anaglyph.prototype = Object.create(R3.D3.API.Effect.prototype); +R3.D3.API.Effect.Anaglyph.prototype.constructor = R3.D3.API.Effect.Anaglyph; \ No newline at end of file diff --git a/src/r3-d3-api-effect-parallax.js b/src/r3-d3-api-effect-parallax.js new file mode 100644 index 0000000..7725d57 --- /dev/null +++ b/src/r3-d3-api-effect-parallax.js @@ -0,0 +1,34 @@ +/** + * R3.D3.API.Effect.Parallax + * @constructor + * @param apiEffect + */ +R3.D3.API.Effect.Parallax = function( + apiEffect +) { + + if (R3.Utils.UndefinedOrNull(apiEffect)) { + apiEffect = { + effectType : R3.D3.API.Effect.EFFECT_TYPE_PARALLAX + }; + } + + if (R3.Utils.UndefinedOrNull(apiEffect.cameraType)) { + apiEffect.effectType = R3.D3.API.Effect.EFFECT_TYPE_PARALLAX; + } + + R3.D3.API.Effect.call( + this, + apiEffect.id, + apiEffect.name, + apiEffect.effectType, + apiEffect.parentEntity, + apiEffect.renderer, + apiEffect.width, + apiEffect.height + ); + +}; + +R3.D3.API.Effect.Parallax.prototype = Object.create(R3.D3.API.Effect.prototype); +R3.D3.API.Effect.Parallax.prototype.constructor = R3.D3.API.Effect.Parallax; \ No newline at end of file diff --git a/src/r3-d3-api-effect-stereo.js b/src/r3-d3-api-effect-stereo.js new file mode 100644 index 0000000..ab37ecb --- /dev/null +++ b/src/r3-d3-api-effect-stereo.js @@ -0,0 +1,41 @@ +/** + * R3.D3.API.Effect.Stereo + * @constructor + * @param apiEffect + * @param eyeSeperation + */ +R3.D3.API.Effect.Stereo = function( + apiEffect, + eyeSeperation +) { + + if (R3.Utils.UndefinedOrNull(apiEffect)) { + apiEffect = { + effectType : R3.D3.API.Effect.EFFECT_TYPE_STEREO + }; + } + + if (R3.Utils.UndefinedOrNull(apiEffect.cameraType)) { + apiEffect.effectType = R3.D3.API.Effect.EFFECT_TYPE_STEREO; + } + + if (R3.Utils.UndefinedOrNull(eyeSeperation)) { + eyeSeperation = 0.064; + } + this.eyeSeperation = eyeSeperation; + + R3.D3.API.Effect.call( + this, + apiEffect.id, + apiEffect.name, + apiEffect.effectType, + apiEffect.parentEntity, + apiEffect.renderer, + apiEffect.width, + apiEffect.height + ); + +}; + +R3.D3.API.Effect.Stereo.prototype = Object.create(R3.D3.API.Effect.prototype); +R3.D3.API.Effect.Stereo.prototype.constructor = R3.D3.API.Effect.Stereo; \ No newline at end of file diff --git a/src/game-lib-d3-api-face.js b/src/r3-d3-api-face.js similarity index 67% rename from src/game-lib-d3-api-face.js rename to src/r3-d3-api-face.js index 681a2a3..1c7deed 100644 --- a/src/game-lib-d3-api-face.js +++ b/src/r3-d3-api-face.js @@ -6,7 +6,7 @@ * @param v1index * @param v2index * @param materialIndex - * @param uvs [[v0uv (GameLib.Vector2), v1uv(GameLib.Vector2), v2uv(GameLib.Vector2)]] + * @param uvs [[v0uv (R3.Vector2), v1uv(R3.Vector2), v2uv(R3.Vector2)]] * @param color * @param vertexColors * @param vertexNormals @@ -16,7 +16,7 @@ * @param parentEntity * @constructor */ -GameLib.D3.API.Face = function( +R3.D3.API.Face = function( id, name, v0index, @@ -33,78 +33,78 @@ GameLib.D3.API.Face = function( parentEntity ) { - if (GameLib.Utils.UndefinedOrNull(id)) { - id = GameLib.Utils.RandomId(); + if (R3.Utils.UndefinedOrNull(id)) { + id = R3.Utils.RandomId(); } this.id = id; - if (GameLib.Utils.UndefinedOrNull(name)) { + if (R3.Utils.UndefinedOrNull(name)) { name = 'Face ' + id; } this.name = name; - if (GameLib.Utils.UndefinedOrNull(v0index)) { + if (R3.Utils.UndefinedOrNull(v0index)) { v0index = -1; } this.v0index = v0index; - if (GameLib.Utils.UndefinedOrNull(v1index)) { + if (R3.Utils.UndefinedOrNull(v1index)) { v1index = -1; } this.v1index = v1index; - if (GameLib.Utils.UndefinedOrNull(v2index)) { + if (R3.Utils.UndefinedOrNull(v2index)) { v2index = -1; } this.v2index = v2index; - if (GameLib.Utils.UndefinedOrNull(materialIndex)) { + if (R3.Utils.UndefinedOrNull(materialIndex)) { materialIndex = -1; } this.materialIndex = materialIndex; - if (GameLib.Utils.UndefinedOrNull(uvs)) { + if (R3.Utils.UndefinedOrNull(uvs)) { uvs = [[]]; } this.uvs = uvs; - if (GameLib.Utils.UndefinedOrNull(color)) { - color = new GameLib.API.Color(); + if (R3.Utils.UndefinedOrNull(color)) { + color = new R3.API.Color(); } this.color = color; - if (GameLib.Utils.UndefinedOrNull(vertexColors)) { + if (R3.Utils.UndefinedOrNull(vertexColors)) { vertexColors = [ - new GameLib.API.Color(), - new GameLib.API.Color(), - new GameLib.API.Color() + new R3.API.Color(), + new R3.API.Color(), + new R3.API.Color() ]; } this.vertexColors = vertexColors; - if (GameLib.Utils.UndefinedOrNull(vertexNormals)) { + if (R3.Utils.UndefinedOrNull(vertexNormals)) { vertexNormals = []; } this.vertexNormals = vertexNormals; - if (GameLib.Utils.UndefinedOrNull(normal)) { + if (R3.Utils.UndefinedOrNull(normal)) { normal = null; } this.normal = normal; - if (GameLib.Utils.UndefinedOrNull(selected)) { + if (R3.Utils.UndefinedOrNull(selected)) { selected = false; } this.selected = selected; - if (GameLib.Utils.UndefinedOrNull(parentGeometry)) { + if (R3.Utils.UndefinedOrNull(parentGeometry)) { parentGeometry = null; } this.parentGeometry = parentGeometry; - GameLib.API.Component.call( + R3.API.Component.call( this, - GameLib.Component.FACE, + R3.Component.FACE, parentEntity ); }; @@ -113,15 +113,15 @@ GameLib.D3.API.Face = function( * We don't inherit from component - it makes the entitymanager too heavy - all faces end up in the register etc.. */ -GameLib.D3.API.Face.prototype = Object.create(GameLib.API.Component.prototype); -GameLib.D3.API.Face.prototype.constructor = GameLib.D3.API.Face; +R3.D3.API.Face.prototype = Object.create(R3.API.Component.prototype); +R3.D3.API.Face.prototype.constructor = R3.D3.API.Face; /** * Returns an API Face from a data object * @constructor * @param objectFace */ -// GameLib.D3.API.Face.FromObject = function(objectFace) { +// R3.D3.API.Face.FromObject = function(objectFace) { // // var apiUvs = objectFace.uvs.reduce( // @@ -129,7 +129,7 @@ GameLib.D3.API.Face.prototype.constructor = GameLib.D3.API.Face; // // result[index] = uvArray.reduce( // function(uvResult, uv) { -// uvResult.push(GameLib.API.Vector2.FromObject(uv)); +// uvResult.push(R3.API.Vector2.FromObject(uv)); // return uvResult; // }, // [] @@ -142,27 +142,27 @@ GameLib.D3.API.Face.prototype.constructor = GameLib.D3.API.Face; // // var apiVertexColors = objectFace.vertexColors.map( // function(vertexColor) { -// return GameLib.API.Color.FromObject(vertexColor); +// return R3.API.Color.FromObject(vertexColor); // } // ); // // var apiColor = null; // if (objectFace.color) { -// apiColor = GameLib.API.Color.FromObject(objectFace.color); +// apiColor = R3.API.Color.FromObject(objectFace.color); // } // // var apiVertexNormals = objectFace.vertexNormals.map( // function(vertexNormal) { -// return GameLib.API.Vector3.FromObject(vertexNormal); +// return R3.API.Vector3.FromObject(vertexNormal); // } // ); // // var apiNormal = null; // if (objectFace.normal) { -// apiNormal = GameLib.API.Vector3.FromObject(objectFace.normal); +// apiNormal = R3.API.Vector3.FromObject(objectFace.normal); // } // -// return new GameLib.D3.API.Face( +// return new R3.D3.API.Face( // objectFace.id, // objectFace.name, // objectFace.v0index, @@ -179,10 +179,10 @@ GameLib.D3.API.Face.prototype.constructor = GameLib.D3.API.Face; // /** * Clone a Face - * @returns {GameLib.D3.API.Face} + * @returns {R3.D3.API.Face} */ -GameLib.D3.API.Face.prototype.clone = function(){ - return new GameLib.D3.API.Face( +R3.D3.API.Face.prototype.clone = function(){ + return new R3.D3.API.Face( this.id, this.name, this.v0index, @@ -202,7 +202,7 @@ GameLib.D3.API.Face.prototype.clone = function(){ * @param triangle * @returns {boolean} */ -GameLib.D3.API.Face.prototype.equals = function(triangle) { +R3.D3.API.Face.prototype.equals = function(triangle) { return ( ( (this.v0index === triangle.v0index) && diff --git a/src/game-lib-d3-api-fog.js b/src/r3-d3-api-fog.js similarity index 52% rename from src/game-lib-d3-api-fog.js rename to src/r3-d3-api-fog.js index e4b5f1f..34e0df4 100644 --- a/src/game-lib-d3-api-fog.js +++ b/src/r3-d3-api-fog.js @@ -10,7 +10,7 @@ * @param parentEntity * @constructor */ -GameLib.D3.API.Fog = function( +R3.D3.API.Fog = function( id, name, exponential, @@ -21,47 +21,47 @@ GameLib.D3.API.Fog = function( parentEntity ) { - if (GameLib.Utils.UndefinedOrNull(id)) { - id = GameLib.Utils.RandomId(); + if (R3.Utils.UndefinedOrNull(id)) { + id = R3.Utils.RandomId(); } this.id = id; - if (GameLib.Utils.UndefinedOrNull(name)) { + if (R3.Utils.UndefinedOrNull(name)) { name = 'Fog (' + this.id + ')'; } this.name = name; - if (GameLib.Utils.UndefinedOrNull(exponential)) { + if (R3.Utils.UndefinedOrNull(exponential)) { exponential = false; } this.exponential = exponential; - if (GameLib.Utils.UndefinedOrNull(color)) { - color = new GameLib.API.Color(1, 1, 1, 1) + if (R3.Utils.UndefinedOrNull(color)) { + color = new R3.API.Color(1, 1, 1, 1) } this.color = color; - if (GameLib.Utils.UndefinedOrNull(near)) { + if (R3.Utils.UndefinedOrNull(near)) { near = 1; } this.near = near; - if (GameLib.Utils.UndefinedOrNull(far)) { + if (R3.Utils.UndefinedOrNull(far)) { far = 1000; } this.far = far; - if (GameLib.Utils.UndefinedOrNull(density)) { + if (R3.Utils.UndefinedOrNull(density)) { density = 0.00025; } this.density = density; - GameLib.API.Component.call( + R3.API.Component.call( this, - GameLib.Component.FOG, + R3.Component.FOG, parentEntity ); }; -GameLib.D3.API.Fog.prototype = Object.create(GameLib.API.Component.prototype); -GameLib.D3.API.Fog.prototype.constructor = GameLib.D3.API.Fog; +R3.D3.API.Fog.prototype = Object.create(R3.API.Component.prototype); +R3.D3.API.Fog.prototype.constructor = R3.D3.API.Fog; diff --git a/src/game-lib-d3-api-font.js b/src/r3-d3-api-font.js similarity index 54% rename from src/game-lib-d3-api-font.js rename to src/r3-d3-api-font.js index f1c42fc..aeca15c 100644 --- a/src/game-lib-d3-api-font.js +++ b/src/r3-d3-api-font.js @@ -6,44 +6,44 @@ * @param parentEntity * @constructor */ -GameLib.D3.API.Font = function( +R3.D3.API.Font = function( id, name, url, parentEntity ) { - if (GameLib.Utils.UndefinedOrNull(id)) { - id = GameLib.Utils.RandomId(); + if (R3.Utils.UndefinedOrNull(id)) { + id = R3.Utils.RandomId(); } this.id = id; - if (GameLib.Utils.UndefinedOrNull(name)) { + if (R3.Utils.UndefinedOrNull(name)) { name = 'Font (' + id + ')'; } this.name = name; - if (GameLib.Utils.UndefinedOrNull(url)) { + if (R3.Utils.UndefinedOrNull(url)) { url = '/apiRelative/path/to/font'; } this.url = url; - GameLib.API.Component.call( + R3.API.Component.call( this, - GameLib.Component.FONT, + R3.Component.FONT, parentEntity ); }; -GameLib.D3.API.Font.prototype = Object.create(GameLib.API.Component.prototype); -GameLib.D3.API.Font.prototype.constructor = GameLib.D3.API.Font; +R3.D3.API.Font.prototype = Object.create(R3.API.Component.prototype); +R3.D3.API.Font.prototype.constructor = R3.D3.API.Font; /** * Returns an API light from an Object light * @param objectFont * @constructor */ -GameLib.D3.API.Font.FromObject = function(objectFont) { - return new GameLib.D3.API.Font( +R3.D3.API.Font.FromObject = function(objectFont) { + return new R3.D3.API.Font( objectFont.id, objectFont.name, objectFont.url, diff --git a/src/game-lib-d3-api-friction-contact-material.js b/src/r3-d3-api-friction-contact-material.js similarity index 66% rename from src/game-lib-d3-api-friction-contact-material.js rename to src/r3-d3-api-friction-contact-material.js index af0fbb4..6259c77 100644 --- a/src/game-lib-d3-api-friction-contact-material.js +++ b/src/r3-d3-api-friction-contact-material.js @@ -12,7 +12,7 @@ * @param parentEntity * @constructor */ -GameLib.D3.API.FrictionContactMaterial = function( +R3.D3.API.FrictionContactMaterial = function( id, name, materials, @@ -25,68 +25,68 @@ GameLib.D3.API.FrictionContactMaterial = function( parentEntity ) { - if (GameLib.Utils.UndefinedOrNull(id)) { - id = GameLib.Utils.RandomId(); + if (R3.Utils.UndefinedOrNull(id)) { + id = R3.Utils.RandomId(); } this.id = id; - if (GameLib.Utils.UndefinedOrNull(name)) { + if (R3.Utils.UndefinedOrNull(name)) { name = 'Friction Material (' + this.id + ')'; } this.name = name; - if (GameLib.Utils.UndefinedOrNull(materials)) { + if (R3.Utils.UndefinedOrNull(materials)) { materials = []; } this.materials = materials; - if (GameLib.Utils.UndefinedOrNull(friction)) { + if (R3.Utils.UndefinedOrNull(friction)) { friction = 0.3; } this.friction = friction; - if (GameLib.Utils.UndefinedOrNull(restitution)) { + if (R3.Utils.UndefinedOrNull(restitution)) { restitution = 0.3; } this.restitution = restitution; - if (GameLib.Utils.UndefinedOrNull(contactEquationStiffness)) { + if (R3.Utils.UndefinedOrNull(contactEquationStiffness)) { contactEquationStiffness = 1e7; } this.contactEquationStiffness = contactEquationStiffness; - if (GameLib.Utils.UndefinedOrNull(contactEquationRelaxation)) { + if (R3.Utils.UndefinedOrNull(contactEquationRelaxation)) { contactEquationRelaxation = 3; } this.contactEquationRelaxation = contactEquationRelaxation; - if (GameLib.Utils.UndefinedOrNull(frictionEquationStiffness)) { + if (R3.Utils.UndefinedOrNull(frictionEquationStiffness)) { frictionEquationStiffness = 1e7; } this.frictionEquationStiffness = frictionEquationStiffness; - if (GameLib.Utils.UndefinedOrNull(frictionEquationRelaxation)) { + if (R3.Utils.UndefinedOrNull(frictionEquationRelaxation)) { frictionEquationRelaxation = 3; } this.frictionEquationRelaxation = frictionEquationRelaxation; - GameLib.API.Component.call( + R3.API.Component.call( this, - GameLib.Component.FRICTION_CONTACT_MATERIAL, + R3.Component.FRICTION_CONTACT_MATERIAL, parentEntity ); }; -GameLib.D3.API.FrictionContactMaterial.prototype = Object.create(GameLib.API.Component.prototype); -GameLib.D3.API.FrictionContactMaterial.prototype.constructor = GameLib.D3.API.FrictionContactMaterial; +R3.D3.API.FrictionContactMaterial.prototype = Object.create(R3.API.Component.prototype); +R3.D3.API.FrictionContactMaterial.prototype.constructor = R3.D3.API.FrictionContactMaterial; /** * Creates an API FrictionContactMaterial from an Object FrictionContactMaterial * @param objectFrictionContactMaterial * @constructor */ -GameLib.D3.API.FrictionContactMaterial.FromObject = function(objectFrictionContactMaterial) { - return new GameLib.D3.API.FrictionContactMaterial( +R3.D3.API.FrictionContactMaterial.FromObject = function(objectFrictionContactMaterial) { + return new R3.D3.API.FrictionContactMaterial( objectFrictionContactMaterial.id, objectFrictionContactMaterial.name, objectFrictionContactMaterial.materials, diff --git a/src/game-lib-d3-api-friction-material.js b/src/r3-d3-api-friction-material.js similarity index 56% rename from src/game-lib-d3-api-friction-material.js rename to src/r3-d3-api-friction-material.js index 2f8001e..17f6193 100644 --- a/src/game-lib-d3-api-friction-material.js +++ b/src/r3-d3-api-friction-material.js @@ -7,7 +7,7 @@ * @param parentEntity * @constructor */ -GameLib.D3.API.FrictionMaterial = function( +R3.D3.API.FrictionMaterial = function( id, name, friction, @@ -15,43 +15,43 @@ GameLib.D3.API.FrictionMaterial = function( parentEntity ) { - if (GameLib.Utils.UndefinedOrNull(id)) { - id = GameLib.Utils.RandomId(); + if (R3.Utils.UndefinedOrNull(id)) { + id = R3.Utils.RandomId(); } this.id = id; - if (GameLib.Utils.UndefinedOrNull(name)) { + if (R3.Utils.UndefinedOrNull(name)) { name = 'Friction Material (' + this.id + ')'; } this.name = name; - if (GameLib.Utils.UndefinedOrNull(friction)) { + if (R3.Utils.UndefinedOrNull(friction)) { friction = -1; } this.friction = friction; - if (GameLib.Utils.UndefinedOrNull(restitution)) { + if (R3.Utils.UndefinedOrNull(restitution)) { restitution = -1; } this.restitution = restitution; - GameLib.API.Component.call( + R3.API.Component.call( this, - GameLib.Component.FRICTION_MATERIAL, + R3.Component.FRICTION_MATERIAL, parentEntity ); }; -GameLib.D3.API.FrictionMaterial.prototype = Object.create(GameLib.API.Component.prototype); -GameLib.D3.API.FrictionMaterial.prototype.constructor = GameLib.D3.API.FrictionMaterial; +R3.D3.API.FrictionMaterial.prototype = Object.create(R3.API.Component.prototype); +R3.D3.API.FrictionMaterial.prototype.constructor = R3.D3.API.FrictionMaterial; /** * Creates an API FrictionMaterial from an Object FrictionMaterial * @param objectFrictionMaterial * @constructor */ -GameLib.D3.API.FrictionMaterial.FromObject = function(objectFrictionMaterial) { - return new GameLib.D3.API.FrictionMaterial( +R3.D3.API.FrictionMaterial.FromObject = function(objectFrictionMaterial) { + return new R3.D3.API.FrictionMaterial( objectFrictionMaterial.id, objectFrictionMaterial.name, objectFrictionMaterial.friction, diff --git a/src/r3-d3-api-geometry-a.js b/src/r3-d3-api-geometry-a.js new file mode 100644 index 0000000..8f31a6e --- /dev/null +++ b/src/r3-d3-api-geometry-a.js @@ -0,0 +1,413 @@ +/** + * R3.D3.API.Geometry + * @param id + * @param name + * @param geometryType + * @param parentEntity + * @param parentMesh + * @param boundingBox + * @param boundingSphere + * @param faces + * @param vertices + * @constructor + */ +R3.D3.API.Geometry = function( + id, + name, + geometryType, + parentEntity, + parentMesh, + boundingBox, + boundingSphere, + faces, + vertices +) { + if (R3.Utils.UndefinedOrNull(id)) { + id = R3.Utils.RandomId(); + } + this.id = id; + + if (R3.Utils.UndefinedOrNull(geometryType)) { + geometryType = R3.D3.API.Geometry.GEOMETRY_TYPE_NONE; + } + this.geometryType = geometryType; + + if (R3.Utils.UndefinedOrNull(name)) { + + switch (this.geometryType) { + case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL : + name = 'Geometry'; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_BOX : + name = 'Geometry Normal Box'; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_CIRCLE : + name = 'Geometry Normal Circle'; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_CONE : + name = 'Geometry Normal Cone'; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_CYLINDER : + name = 'Geometry Normal Cylinder'; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_DODECAHEDRON : + name = 'Geometry Normal Dodecahedron'; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_EDGES : + name = 'Geometry Normal Edges'; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_EXTRUDE : + name = 'Geometry Normal Extrude'; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_ICOSAHEDRON : + name = 'Geometry Normal Icosahedron'; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_LATHE : + name = 'Geometry Normal Lathe'; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_OCTAHEDRON : + name = 'Geometry Normal Octahedron'; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_PARAMETRIC : + name = 'Geometry Normal Parametric'; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_PLANE : + name = 'Geometry Normal Plane'; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_POLYHEDRON : + name = 'Geometry Normal Polyhedron'; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_RING : + name = 'Geometry Normal Ring'; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_SHAPE : + name = 'Geometry Normal Shape'; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_SPHERE : + name = 'Geometry Normal Sphere'; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TETRAHEDRON : + name = 'Geometry Normal Tetrahedron'; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TEXT : + name = 'Geometry Normal Text'; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TORUS : + name = 'Geometry Normal Torus'; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TORUS_KNOT : + name = 'Geometry Normal Torus Knot'; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TUBE : + name = 'Geometry Normal Tube'; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_WIREFRAME : + name = 'Geometry Normal Wireframe'; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER : + name = 'Geometry Buffer'; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_BOX : + name = 'Geometry Buffer Box'; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CIRCLE : + name = 'Geometry Buffer Circle'; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CONE : + name = 'Geometry Buffer Cone'; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CYLINDER : + name = 'Geometry Buffer Cylinder'; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_DODECAHEDRON : + name = 'Geometry Buffer Dodecahedron'; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_EXTRUDE : + name = 'Geometry Buffer Extrude'; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_ICOSAHEDRON : + name = 'Geometry Buffer Icosahedron'; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_LATHE : + name = 'Geometry Buffer Lathe'; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_OCTAHEDRON : + name = 'Geometry Buffer Octahedron'; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_PARAMETRIC : + name = 'Geometry Buffer Parametric'; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_PLANE : + name = 'Geometry Buffer Plane'; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_POLYHEDRON : + name = 'Geometry Buffer Polyhedron'; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_RING : + name = 'Geometry Buffer Ring'; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_SHAPE : + name = 'Geometry Buffer Shape'; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_SPHERE : + name = 'Geometry Buffer Sphere'; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TETRAHEDRON : + name = 'Geometry Buffer Tetrahedron'; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TEXT : + name = 'Geometry Buffer Text'; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TORUS : + name = 'Geometry Buffer Torus'; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TORUS_KNOT : + name = 'Geometry Buffer Torus Knot'; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TUBE : + name = 'Geometry Buffer Tube'; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_INSTANCED : + name = 'Geometry Buffer Instanced'; + break; + default : + console.warn('no nice name for geometry'); + name = 'Geometry'; + } + + name += ' (' + id + ')'; + } + this.name = name; + + if (R3.Utils.UndefinedOrNull(parentMesh)) { + parentMesh = null; + } + this.parentMesh = parentMesh; + + if (R3.Utils.UndefinedOrNull(boundingBox)) { + boundingBox = new R3.API.Box3(); + } + this.boundingBox = boundingBox; + + if (R3.Utils.UndefinedOrNull(boundingSphere)) { + boundingSphere = new R3.API.Sphere(); + } + this.boundingSphere = boundingSphere; + + if (R3.Utils.UndefinedOrNull(faces)) { + faces = []; + } + this.faces = faces; + + if (R3.Utils.UndefinedOrNull(vertices)) { + vertices = []; + } + this.vertices = vertices; + + R3.API.Component.call( + this, + R3.D3.API.Geometry.GetComponentType(this.geometryType), + parentEntity + ); +}; + +R3.D3.API.Geometry.prototype = Object.create(R3.API.Component.prototype); +R3.D3.API.Geometry.prototype.constructor = R3.D3.API.Geometry; + +R3.D3.API.Geometry.GetComponentType = function(geometryType) { + + var componentType = null; + + switch (geometryType) { + case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL : + componentType = R3.Component.GEOMETRY_NORMAL; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_BOX : + componentType = R3.Component.GEOMETRY_NORMAL_BOX; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_CIRCLE : + componentType = R3.Component.GEOMETRY_NORMAL_CIRCLE; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_CONE : + componentType = R3.Component.GEOMETRY_NORMAL_CONE; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_CYLINDER : + componentType = R3.Component.GEOMETRY_NORMAL_CYLINDER; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_DODECAHEDRON : + componentType = R3.Component.GEOMETRY_NORMAL_DODECAHEDRON; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_EDGES : + componentType = R3.Component.GEOMETRY_NORMAL_EDGES; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_EXTRUDE : + componentType = R3.Component.GEOMETRY_NORMAL_EXTRUDE; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_ICOSAHEDRON : + componentType = R3.Component.GEOMETRY_NORMAL_ICOSAHEDRON; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_LATHE : + componentType = R3.Component.GEOMETRY_NORMAL_LATHE; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_OCTAHEDRON : + componentType = R3.Component.GEOMETRY_NORMAL_OCTAHEDRON; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_PARAMETRIC : + componentType = R3.Component.GEOMETRY_NORMAL_PARAMETRIC; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_PLANE : + componentType = R3.Component.GEOMETRY_NORMAL_PLANE; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_POLYHEDRON : + componentType = R3.Component.GEOMETRY_NORMAL_POLYHEDRON; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_RING : + componentType = R3.Component.GEOMETRY_NORMAL_RING; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_SHAPE : + componentType = R3.Component.GEOMETRY_NORMAL_SHAPE; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_SPHERE : + componentType = R3.Component.GEOMETRY_NORMAL_SPHERE; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TETRAHEDRON : + componentType = R3.Component.GEOMETRY_NORMAL_TETRAHEDRON; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TEXT : + componentType = R3.Component.GEOMETRY_NORMAL_TEXT; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TORUS : + componentType = R3.Component.GEOMETRY_NORMAL_TORUS; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TORUS_KNOT : + componentType = R3.Component.GEOMETRY_NORMAL_TORUS_KNOT; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TUBE : + componentType = R3.Component.GEOMETRY_NORMAL_TUBE; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_WIREFRAME : + componentType = R3.Component.GEOMETRY_NORMAL_WIREFRAME; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER : + componentType = R3.Component.GEOMETRY_BUFFER; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_BOX : + componentType = R3.Component.GEOMETRY_BUFFER_BOX; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CIRCLE : + componentType = R3.Component.GEOMETRY_BUFFER_CIRCLE; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CONE : + componentType = R3.Component.GEOMETRY_BUFFER_CONE; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CYLINDER : + componentType = R3.Component.GEOMETRY_BUFFER_CYLINDER; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_DODECAHEDRON : + componentType = R3.Component.GEOMETRY_BUFFER_DODECAHEDRON; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_EXTRUDE : + componentType = R3.Component.GEOMETRY_BUFFER_EXTRUDE; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_ICOSAHEDRON : + componentType = R3.Component.GEOMETRY_BUFFER_ICOSAHEDRON; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_LATHE : + componentType = R3.Component.GEOMETRY_BUFFER_LATHE; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_OCTAHEDRON : + componentType = R3.Component.GEOMETRY_BUFFER_OCTAHEDRON; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_PARAMETRIC: + componentType = R3.Component.GEOMETRY_BUFFER_PARAMETRIC; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_PLANE : + componentType = R3.Component.GEOMETRY_BUFFER_PLANE; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_POLYHEDRON : + componentType = R3.Component.GEOMETRY_BUFFER_POLYHEDRON; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_RING: + componentType = R3.Component.GEOMETRY_BUFFER_RING; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_SHAPE : + componentType = R3.Component.GEOMETRY_BUFFER_SHAPE; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_SPHERE : + componentType = R3.Component.GEOMETRY_BUFFER_SPHERE; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TETRAHEDRON : + componentType = R3.Component.GEOMETRY_BUFFER_TETRAHEDRON; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TEXT : + componentType = R3.Component.GEOMETRY_BUFFER_TEXT; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TORUS : + componentType = R3.Component.GEOMETRY_BUFFER_TORUS; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TORUS_KNOT : + componentType = R3.Component.GEOMETRY_BUFFER_TORUS_KNOT; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TUBE : + componentType = R3.Component.GEOMETRY_BUFFER_TUBE; + break; + case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_INSTANCED : + componentType = R3.Component.GEOMETRY_BUFFER_INSTANCED; + break; + default: + throw new Error('unhandled geometry type: ' + geometryType); + } + + return componentType; +}; + +/** + * Geometry Type + * @type {number} + */ +R3.D3.API.Geometry.GEOMETRY_TYPE_NONE = 0x0; +R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL = 0x1; +R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_BOX = 0x2; +R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_CIRCLE = 0x3; +R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_CONE = 0x4; +R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_CYLINDER = 0x5; +R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_DODECAHEDRON = 0x6; +R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_EDGES = 0x7; +R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_EXTRUDE = 0x8; +R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_ICOSAHEDRON = 0x9; +R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_LATHE = 0xa; +R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_OCTAHEDRON = 0xb; +R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_PARAMETRIC = 0xc; +R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_PLANE = 0xd; +R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_POLYHEDRON = 0xe; +R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_RING = 0xf; +R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_SHAPE = 0x10; +R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_SPHERE = 0x11; +R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TETRAHEDRON = 0x12; +R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TEXT = 0x13; +R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TORUS = 0x14; +R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TORUS_KNOT = 0x15; +R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TUBE = 0x16; +R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_WIREFRAME = 0x17; +R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER = 0x18; +R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_BOX = 0x19; +R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CIRCLE = 0x1a; +R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CONE = 0x1b; +R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CYLINDER = 0x1c; +R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_DODECAHEDRON = 0x1d; +R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_EXTRUDE = 0x1e; +R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_ICOSAHEDRON = 0x1f; +R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_LATHE = 0x20; +R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_OCTAHEDRON = 0x21; +R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_PARAMETRIC = 0x22; +R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_PLANE = 0x23; +R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_POLYHEDRON = 0x24; +R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_RING = 0x25; +R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_SHAPE = 0x26; +R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_SPHERE = 0x27; +R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TETRAHEDRON = 0x28; +R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TEXT = 0x29; +R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TORUS = 0x2a; +R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TORUS_KNOT = 0x2b; +R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TUBE = 0x2c; +R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_INSTANCED = 0x2d; diff --git a/src/game-lib-d3-api-geometry-buffer-a.js b/src/r3-d3-api-geometry-buffer-a.js similarity index 50% rename from src/game-lib-d3-api-geometry-buffer-a.js rename to src/r3-d3-api-geometry-buffer-a.js index 5628b8f..7d03872 100644 --- a/src/game-lib-d3-api-geometry-buffer-a.js +++ b/src/r3-d3-api-geometry-buffer-a.js @@ -1,5 +1,5 @@ /** - * GameLib.D3.API.Geometry.Buffer + * R3.D3.API.Geometry.Buffer * @param apiGeometry * @param attributes * @param drawRange @@ -8,7 +8,7 @@ * @param morphAttributes * @constructor */ -GameLib.D3.API.Geometry.Buffer = function( +R3.D3.API.Geometry.Buffer = function( apiGeometry, attributes, drawRange, @@ -16,42 +16,42 @@ GameLib.D3.API.Geometry.Buffer = function( index, morphAttributes ) { - if (GameLib.Utils.UndefinedOrNull(apiGeometry)) { + if (R3.Utils.UndefinedOrNull(apiGeometry)) { apiGeometry = { - geometryType: GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER + geometryType: R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER }; } - if (GameLib.Utils.UndefinedOrNull(apiGeometry.geometryType)) { - apiGeometry.geometryType = GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER; + if (R3.Utils.UndefinedOrNull(apiGeometry.geometryType)) { + apiGeometry.geometryType = R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER; } - if (GameLib.Utils.UndefinedOrNull(attributes)) { + if (R3.Utils.UndefinedOrNull(attributes)) { attributes = []; } this.attributes = attributes; - if (GameLib.Utils.UndefinedOrNull(groups)) { + if (R3.Utils.UndefinedOrNull(groups)) { groups = []; } this.groups = groups; - if (GameLib.Utils.UndefinedOrNull(drawRange)) { - drawRange = new GameLib.API.DrawRange() + if (R3.Utils.UndefinedOrNull(drawRange)) { + drawRange = new R3.API.DrawRange() } this.drawRange = drawRange; - if (GameLib.Utils.UndefinedOrNull(index)) { + if (R3.Utils.UndefinedOrNull(index)) { index = null; } this.index = index; - if (GameLib.Utils.UndefinedOrNull(morphAttributes)) { + if (R3.Utils.UndefinedOrNull(morphAttributes)) { morphAttributes = null; } this.morphAttributes = morphAttributes; - GameLib.D3.API.Geometry.call( + R3.D3.API.Geometry.call( this, apiGeometry.id, apiGeometry.name, @@ -65,5 +65,5 @@ GameLib.D3.API.Geometry.Buffer = function( ); }; -GameLib.D3.API.Geometry.Buffer.prototype = Object.create(GameLib.D3.API.Geometry.prototype); -GameLib.D3.API.Geometry.Buffer.prototype.constructor = GameLib.D3.API.Geometry.Buffer; +R3.D3.API.Geometry.Buffer.prototype = Object.create(R3.D3.API.Geometry.prototype); +R3.D3.API.Geometry.Buffer.prototype.constructor = R3.D3.API.Geometry.Buffer; diff --git a/src/r3-d3-api-geometry-buffer-box.js b/src/r3-d3-api-geometry-buffer-box.js new file mode 100644 index 0000000..a61e41c --- /dev/null +++ b/src/r3-d3-api-geometry-buffer-box.js @@ -0,0 +1,74 @@ +/** + * R3.D3.API.Geometry.Buffer.Box + * @param apiGeometry + * @param width + * @param height + * @param depth + * @param widthSegments + * @param heightSegments + * @param depthSegments + * @constructor + */ +R3.D3.API.Geometry.Buffer.Box = function( + apiGeometry, + width, + height, + depth, + widthSegments, + heightSegments, + depthSegments +) { + + if (R3.Utils.UndefinedOrNull(apiGeometry)) { + apiGeometry = { + geometryType: R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_BOX + }; + } + + if (R3.Utils.UndefinedOrNull(apiGeometry.geometryType)) { + apiGeometry.geometryType = R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_BOX; + } + + if (R3.Utils.UndefinedOrNull(width)) { + width = 1; + } + this.width = width; + + if (R3.Utils.UndefinedOrNull(height)) { + height = 1; + } + this.height = height; + + if (R3.Utils.UndefinedOrNull(depth)) { + depth = 1; + } + this.depth = depth; + + if (R3.Utils.UndefinedOrNull(widthSegments)) { + widthSegments = 1; + } + this.widthSegments = widthSegments; + + if (R3.Utils.UndefinedOrNull(heightSegments)) { + heightSegments = 1; + } + this.heightSegments = heightSegments; + + if (R3.Utils.UndefinedOrNull(depthSegments)) { + depthSegments = 1; + } + this.depthSegments = depthSegments; + + R3.D3.API.Geometry.Buffer.call( + this, + apiGeometry, + apiGeometry.attributes, + apiGeometry.drawRange, + apiGeometry.groups, + apiGeometry.index, + apiGeometry.morphAttributes + ); +}; + +R3.D3.API.Geometry.Buffer.Box.prototype = Object.create(R3.D3.API.Geometry.Buffer.prototype); +R3.D3.API.Geometry.Buffer.Box.prototype.constructor = R3.D3.API.Geometry.Buffer.Box; diff --git a/src/r3-d3-api-geometry-buffer-circle.js b/src/r3-d3-api-geometry-buffer-circle.js new file mode 100644 index 0000000..f831fb6 --- /dev/null +++ b/src/r3-d3-api-geometry-buffer-circle.js @@ -0,0 +1,60 @@ +/** + * R3.D3.API.Geometry.Buffer.Circle + * @param apiGeometry + * @param radius + * @param segments + * @param thetaStart + * @param thetaLength + * @constructor + */ +R3.D3.API.Geometry.Buffer.Circle = function( + apiGeometry, + radius, + segments, + thetaStart, + thetaLength +) { + + if (R3.Utils.UndefinedOrNull(apiGeometry)) { + apiGeometry = { + geometryType: R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CIRCLE + }; + } + + if (R3.Utils.UndefinedOrNull(apiGeometry.geometryType)) { + apiGeometry.geometryType = R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CIRCLE; + } + + if (R3.Utils.UndefinedOrNull(radius)) { + radius = 1; + } + this.radius = radius; + + if (R3.Utils.UndefinedOrNull(segments)) { + segments = 8; + } + this.segments = segments; + + if (R3.Utils.UndefinedOrNull(thetaStart)) { + thetaStart = 0; + } + this.thetaStart = thetaStart; + + if (R3.Utils.UndefinedOrNull(thetaLength)) { + thetaLength = Math.PI * 2; + } + this.thetaLength = thetaLength; + + R3.D3.API.Geometry.Buffer.call( + this, + apiGeometry, + apiGeometry.attributes, + apiGeometry.drawRange, + apiGeometry.groups, + apiGeometry.index, + apiGeometry.morphAttributes + ); +}; + +R3.D3.API.Geometry.Buffer.Circle.prototype = Object.create(R3.D3.API.Geometry.Buffer.prototype); +R3.D3.API.Geometry.Buffer.Circle.prototype.constructor = R3.D3.API.Geometry.Buffer.Circle; diff --git a/src/game-lib-d3-api-geometry-buffer-cone.js b/src/r3-d3-api-geometry-buffer-cone.js similarity index 51% rename from src/game-lib-d3-api-geometry-buffer-cone.js rename to src/r3-d3-api-geometry-buffer-cone.js index 1dc4585..89bc745 100644 --- a/src/game-lib-d3-api-geometry-buffer-cone.js +++ b/src/r3-d3-api-geometry-buffer-cone.js @@ -1,5 +1,5 @@ /** - * GameLib.D3.API.Geometry.Buffer.Cone + * R3.D3.API.Geometry.Buffer.Cone * @param apiGeometry * @param radius * @param height @@ -10,7 +10,7 @@ * @param thetaLength * @constructor */ -GameLib.D3.API.Geometry.Buffer.Cone = function( +R3.D3.API.Geometry.Buffer.Cone = function( apiGeometry, radius, height, @@ -21,52 +21,52 @@ GameLib.D3.API.Geometry.Buffer.Cone = function( thetaLength ) { - if (GameLib.Utils.UndefinedOrNull(apiGeometry)) { + if (R3.Utils.UndefinedOrNull(apiGeometry)) { apiGeometry = { - geometryType: GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CONE + geometryType: R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CONE }; } - if (GameLib.Utils.UndefinedOrNull(apiGeometry.geometryType)) { - apiGeometry.geometryType = GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CONE; + if (R3.Utils.UndefinedOrNull(apiGeometry.geometryType)) { + apiGeometry.geometryType = R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CONE; } - if (GameLib.Utils.UndefinedOrNull(radius)) { + if (R3.Utils.UndefinedOrNull(radius)) { radius = 1; } this.radius = radius; - if (GameLib.Utils.UndefinedOrNull(height)) { + if (R3.Utils.UndefinedOrNull(height)) { height = 100; } this.height = height; - if (GameLib.Utils.UndefinedOrNull(radialSegments)) { + if (R3.Utils.UndefinedOrNull(radialSegments)) { radialSegments = 8; } this.radialSegments = radialSegments; - if (GameLib.Utils.UndefinedOrNull(heightSegments)) { + if (R3.Utils.UndefinedOrNull(heightSegments)) { heightSegments = 1; } this.heightSegments = heightSegments; - if (GameLib.Utils.UndefinedOrNull(openEnded)) { + if (R3.Utils.UndefinedOrNull(openEnded)) { openEnded = false; } this.openEnded = openEnded; - if (GameLib.Utils.UndefinedOrNull(thetaStart)) { + if (R3.Utils.UndefinedOrNull(thetaStart)) { thetaStart = 0; } this.thetaStart = thetaStart; - if (GameLib.Utils.UndefinedOrNull(thetaLength)) { + if (R3.Utils.UndefinedOrNull(thetaLength)) { thetaLength = Math.PI * 2; } this.thetaLength = thetaLength; - GameLib.D3.API.Geometry.Buffer.call( + R3.D3.API.Geometry.Buffer.call( this, apiGeometry, apiGeometry.attributes, @@ -77,5 +77,5 @@ GameLib.D3.API.Geometry.Buffer.Cone = function( ); }; -GameLib.D3.API.Geometry.Buffer.Cone.prototype = Object.create(GameLib.D3.API.Geometry.Buffer.prototype); -GameLib.D3.API.Geometry.Buffer.Cone.prototype.constructor = GameLib.D3.API.Geometry.Buffer.Cone; +R3.D3.API.Geometry.Buffer.Cone.prototype = Object.create(R3.D3.API.Geometry.Buffer.prototype); +R3.D3.API.Geometry.Buffer.Cone.prototype.constructor = R3.D3.API.Geometry.Buffer.Cone; diff --git a/src/game-lib-d3-api-geometry-buffer-cylinder.js b/src/r3-d3-api-geometry-buffer-cylinder.js similarity index 52% rename from src/game-lib-d3-api-geometry-buffer-cylinder.js rename to src/r3-d3-api-geometry-buffer-cylinder.js index 0e4aeae..565c757 100644 --- a/src/game-lib-d3-api-geometry-buffer-cylinder.js +++ b/src/r3-d3-api-geometry-buffer-cylinder.js @@ -1,5 +1,5 @@ /** - * GameLib.D3.API.Geometry.Buffer.Cylinder + * R3.D3.API.Geometry.Buffer.Cylinder * @param apiGeometry * @param radiusTop * @param radiusBottom @@ -11,7 +11,7 @@ * @param thetaLength * @constructor */ -GameLib.D3.API.Geometry.Buffer.Cylinder = function( +R3.D3.API.Geometry.Buffer.Cylinder = function( apiGeometry, radiusTop, radiusBottom, @@ -23,57 +23,57 @@ GameLib.D3.API.Geometry.Buffer.Cylinder = function( thetaLength ) { - if (GameLib.Utils.UndefinedOrNull(apiGeometry)) { + if (R3.Utils.UndefinedOrNull(apiGeometry)) { apiGeometry = { - geometryType: GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CYLINDER + geometryType: R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CYLINDER }; } - if (GameLib.Utils.UndefinedOrNull(apiGeometry.geometryType)) { - apiGeometry.geometryType = GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CYLINDER; + if (R3.Utils.UndefinedOrNull(apiGeometry.geometryType)) { + apiGeometry.geometryType = R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CYLINDER; } - if (GameLib.Utils.UndefinedOrNull(radiusTop)) { + if (R3.Utils.UndefinedOrNull(radiusTop)) { radiusTop = 1; } this.radiusTop = radiusTop; - if (GameLib.Utils.UndefinedOrNull(radiusBottom)) { + if (R3.Utils.UndefinedOrNull(radiusBottom)) { radiusBottom = 1; } this.radiusBottom = radiusBottom; - if (GameLib.Utils.UndefinedOrNull(height)) { + if (R3.Utils.UndefinedOrNull(height)) { height = 100; } this.height = height; - if (GameLib.Utils.UndefinedOrNull(radialSegments)) { + if (R3.Utils.UndefinedOrNull(radialSegments)) { radialSegments = 8; } this.radialSegments = radialSegments; - if (GameLib.Utils.UndefinedOrNull(heightSegments)) { + if (R3.Utils.UndefinedOrNull(heightSegments)) { heightSegments = 1; } this.heightSegments = heightSegments; - if (GameLib.Utils.UndefinedOrNull(openEnded)) { + if (R3.Utils.UndefinedOrNull(openEnded)) { openEnded = false; } this.openEnded = openEnded; - if (GameLib.Utils.UndefinedOrNull(thetaStart)) { + if (R3.Utils.UndefinedOrNull(thetaStart)) { thetaStart = 0; } this.thetaStart = thetaStart; - if (GameLib.Utils.UndefinedOrNull(thetaLength)) { + if (R3.Utils.UndefinedOrNull(thetaLength)) { thetaLength = Math.PI * 2; } this.thetaLength = thetaLength; - GameLib.D3.API.Geometry.Buffer.call( + R3.D3.API.Geometry.Buffer.call( this, apiGeometry, apiGeometry.attributes, @@ -84,5 +84,5 @@ GameLib.D3.API.Geometry.Buffer.Cylinder = function( ); }; -GameLib.D3.API.Geometry.Buffer.Cylinder.prototype = Object.create(GameLib.D3.API.Geometry.Buffer.prototype); -GameLib.D3.API.Geometry.Buffer.Cylinder.prototype.constructor = GameLib.D3.API.Geometry.Buffer.Cylinder; +R3.D3.API.Geometry.Buffer.Cylinder.prototype = Object.create(R3.D3.API.Geometry.Buffer.prototype); +R3.D3.API.Geometry.Buffer.Cylinder.prototype.constructor = R3.D3.API.Geometry.Buffer.Cylinder; diff --git a/src/r3-d3-api-geometry-buffer-dodecahedron.js b/src/r3-d3-api-geometry-buffer-dodecahedron.js new file mode 100644 index 0000000..fd63e60 --- /dev/null +++ b/src/r3-d3-api-geometry-buffer-dodecahedron.js @@ -0,0 +1,46 @@ +/** + * R3.D3.API.Geometry.Buffer.Dodecahedron + * @param apiGeometry + * @param radius + * @param detail + * @constructor + */ +R3.D3.API.Geometry.Buffer.Dodecahedron = function( + apiGeometry, + radius, + detail +) { + + if (R3.Utils.UndefinedOrNull(apiGeometry)) { + apiGeometry = { + geometryType: R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_DODECAHEDRON + }; + } + + if (R3.Utils.UndefinedOrNull(apiGeometry.geometryType)) { + apiGeometry.geometryType = R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_DODECAHEDRON; + } + + if (R3.Utils.UndefinedOrNull(radius)) { + radius = 1; + } + this.radius = radius; + + if (R3.Utils.UndefinedOrNull(detail)) { + detail = 0; + } + this.detail = detail; + + R3.D3.API.Geometry.Buffer.call( + this, + apiGeometry, + apiGeometry.attributes, + apiGeometry.drawRange, + apiGeometry.groups, + apiGeometry.index, + apiGeometry.morphAttributes + ); +}; + +R3.D3.API.Geometry.Buffer.Dodecahedron.prototype = Object.create(R3.D3.API.Geometry.Buffer.prototype); +R3.D3.API.Geometry.Buffer.Dodecahedron.prototype.constructor = R3.D3.API.Geometry.Buffer.Dodecahedron; diff --git a/src/game-lib-d3-api-geometry-buffer-extrude.js b/src/r3-d3-api-geometry-buffer-extrude.js similarity index 54% rename from src/game-lib-d3-api-geometry-buffer-extrude.js rename to src/r3-d3-api-geometry-buffer-extrude.js index 142f3d2..078e189 100644 --- a/src/game-lib-d3-api-geometry-buffer-extrude.js +++ b/src/r3-d3-api-geometry-buffer-extrude.js @@ -1,5 +1,5 @@ /** - * GameLib.D3.API.Geometry.Buffer.Extrude + * R3.D3.API.Geometry.Buffer.Extrude * @param apiGeometry * @param shapes * @param curveSegments @@ -14,7 +14,7 @@ * @param UVGenerator * @constructor */ -GameLib.D3.API.Geometry.Buffer.Extrude = function( +R3.D3.API.Geometry.Buffer.Extrude = function( apiGeometry, shapes, curveSegments, @@ -29,67 +29,67 @@ GameLib.D3.API.Geometry.Buffer.Extrude = function( UVGenerator ) { - if (GameLib.Utils.UndefinedOrNull(apiGeometry)) { + if (R3.Utils.UndefinedOrNull(apiGeometry)) { apiGeometry = { - geometryType: GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_EXTRUDE + geometryType: R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_EXTRUDE }; } - if (GameLib.Utils.UndefinedOrNull(apiGeometry.geometryType)) { - apiGeometry.geometryType = GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_EXTRUDE; + if (R3.Utils.UndefinedOrNull(apiGeometry.geometryType)) { + apiGeometry.geometryType = R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_EXTRUDE; } - if (GameLib.Utils.UndefinedOrNull(shapes)) { + if (R3.Utils.UndefinedOrNull(shapes)) { shapes = []; } this.shapes = shapes; - if (GameLib.Utils.UndefinedOrNull(curveSegments)) { + if (R3.Utils.UndefinedOrNull(curveSegments)) { curveSegments = 12; } this.curveSegments = curveSegments; - if (GameLib.Utils.UndefinedOrNull(steps)) { + if (R3.Utils.UndefinedOrNull(steps)) { steps = 1; } this.steps = steps; - if (GameLib.Utils.UndefinedOrNull(amount)) { + if (R3.Utils.UndefinedOrNull(amount)) { amount = 100; } this.amount = amount; - if (GameLib.Utils.UndefinedOrNull(bevelEnabled)) { + if (R3.Utils.UndefinedOrNull(bevelEnabled)) { bevelEnabled = true; } this.bevelEnabled = bevelEnabled; - if (GameLib.Utils.UndefinedOrNull(bevelThickness)) { + if (R3.Utils.UndefinedOrNull(bevelThickness)) { bevelThickness = 6; } this.bevelThickness = bevelThickness; - if (GameLib.Utils.UndefinedOrNull(bevelSegments)) { + if (R3.Utils.UndefinedOrNull(bevelSegments)) { bevelSegments = 3; } this.bevelSegments = bevelSegments; - if (GameLib.Utils.UndefinedOrNull(extrudePath)) { + if (R3.Utils.UndefinedOrNull(extrudePath)) { extrudePath = null; } this.extrudePath = extrudePath; - if (GameLib.Utils.UndefinedOrNull(frames)) { + if (R3.Utils.UndefinedOrNull(frames)) { frames = null; } this.frames = frames; - if (GameLib.Utils.UndefinedOrNull(UVGenerator)) { + if (R3.Utils.UndefinedOrNull(UVGenerator)) { UVGenerator = null; } this.UVGenerator = UVGenerator; - GameLib.D3.API.Geometry.Buffer.call( + R3.D3.API.Geometry.Buffer.call( this, apiGeometry, apiGeometry.attributes, @@ -100,5 +100,5 @@ GameLib.D3.API.Geometry.Buffer.Extrude = function( ); }; -GameLib.D3.API.Geometry.Buffer.Extrude.prototype = Object.create(GameLib.D3.API.Geometry.Buffer.prototype); -GameLib.D3.API.Geometry.Buffer.Extrude.prototype.constructor = GameLib.D3.API.Geometry.Buffer.Extrude; +R3.D3.API.Geometry.Buffer.Extrude.prototype = Object.create(R3.D3.API.Geometry.Buffer.prototype); +R3.D3.API.Geometry.Buffer.Extrude.prototype.constructor = R3.D3.API.Geometry.Buffer.Extrude; diff --git a/src/r3-d3-api-geometry-buffer-icosahedron.js b/src/r3-d3-api-geometry-buffer-icosahedron.js new file mode 100644 index 0000000..60e2d70 --- /dev/null +++ b/src/r3-d3-api-geometry-buffer-icosahedron.js @@ -0,0 +1,46 @@ +/** + * R3.D3.API.Geometry.Buffer.Icosahedron + * @param apiGeometry + * @param radius + * @param detail + * @constructor + */ +R3.D3.API.Geometry.Buffer.Icosahedron = function( + apiGeometry, + radius, + detail +) { + + if (R3.Utils.UndefinedOrNull(apiGeometry)) { + apiGeometry = { + geometryType: R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_ICOSAHEDRON + }; + } + + if (R3.Utils.UndefinedOrNull(apiGeometry.geometryType)) { + apiGeometry.geometryType = R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_ICOSAHEDRON; + } + + if (R3.Utils.UndefinedOrNull(radius)) { + radius = 1; + } + this.radius = radius; + + if (R3.Utils.UndefinedOrNull(detail)) { + detail = 0; + } + this.detail = detail; + + R3.D3.API.Geometry.Buffer.call( + this, + apiGeometry, + apiGeometry.attributes, + apiGeometry.drawRange, + apiGeometry.groups, + apiGeometry.index, + apiGeometry.morphAttributes + ); +}; + +R3.D3.API.Geometry.Buffer.Icosahedron.prototype = Object.create(R3.D3.API.Geometry.Buffer.prototype); +R3.D3.API.Geometry.Buffer.Icosahedron.prototype.constructor = R3.D3.API.Geometry.Buffer.Icosahedron; diff --git a/src/r3-d3-api-geometry-buffer-instanced.js b/src/r3-d3-api-geometry-buffer-instanced.js new file mode 100644 index 0000000..420397f --- /dev/null +++ b/src/r3-d3-api-geometry-buffer-instanced.js @@ -0,0 +1,39 @@ +/** + * R3.D3.API.Geometry.Buffer.Instanced + * @param apiGeometry + * @param maxInstancedCount + * @constructor + */ +R3.D3.API.Geometry.Buffer.Instanced = function( + apiGeometry, + maxInstancedCount +) { + + if (R3.Utils.UndefinedOrNull(apiGeometry)) { + apiGeometry = { + geometryType: R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_INSTANCED + }; + } + + if (R3.Utils.UndefinedOrNull(apiGeometry.geometryType)) { + apiGeometry.geometryType = R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_INSTANCED; + } + + if (R3.Utils.UndefinedOrNull(maxInstancedCount)) { + maxInstancedCount = null; + } + this.maxInstancedCount = maxInstancedCount; + + R3.D3.API.Geometry.Buffer.call( + this, + apiGeometry, + apiGeometry.attributes, + apiGeometry.drawRange, + apiGeometry.groups, + apiGeometry.index, + apiGeometry.morphAttributes + ); +}; + +R3.D3.API.Geometry.Buffer.Instanced.prototype = Object.create(R3.D3.API.Geometry.Buffer.prototype); +R3.D3.API.Geometry.Buffer.Instanced.prototype.constructor = R3.D3.API.Geometry.Buffer.Instanced; diff --git a/src/r3-d3-api-geometry-buffer-lathe.js b/src/r3-d3-api-geometry-buffer-lathe.js new file mode 100644 index 0000000..2c541d4 --- /dev/null +++ b/src/r3-d3-api-geometry-buffer-lathe.js @@ -0,0 +1,60 @@ +/** + * R3.D3.API.Geometry.Buffer.Lathe + * @param apiGeometry + * @param points [R3.Vector2] (x must be larger than 0) + * @param segments + * @param phiStart + * @param phiLength + * @constructor + */ +R3.D3.API.Geometry.Buffer.Lathe = function( + apiGeometry, + points, + segments, + phiStart, + phiLength +) { + + if (R3.Utils.UndefinedOrNull(apiGeometry)) { + apiGeometry = { + geometryType: R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_LATHE + }; + } + + if (R3.Utils.UndefinedOrNull(apiGeometry.geometryType)) { + apiGeometry.geometryType = R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_LATHE; + } + + if (R3.Utils.UndefinedOrNull(points)) { + points = []; + } + this.points = points; + + if (R3.Utils.UndefinedOrNull(segments)) { + segments = 12; + } + this.segments = segments; + + if (R3.Utils.UndefinedOrNull(phiStart)) { + phiStart = 0; + } + this.phiStart = phiStart; + + if (R3.Utils.UndefinedOrNull(phiLength)) { + phiLength = Math.PI * 2; + } + this.phiLength = phiLength; + + R3.D3.API.Geometry.Buffer.call( + this, + apiGeometry, + apiGeometry.attributes, + apiGeometry.drawRange, + apiGeometry.groups, + apiGeometry.index, + apiGeometry.morphAttributes + ); +}; + +R3.D3.API.Geometry.Buffer.Lathe.prototype = Object.create(R3.D3.API.Geometry.Buffer.prototype); +R3.D3.API.Geometry.Buffer.Lathe.prototype.constructor = R3.D3.API.Geometry.Buffer.Lathe; diff --git a/src/r3-d3-api-geometry-buffer-octahedron.js b/src/r3-d3-api-geometry-buffer-octahedron.js new file mode 100644 index 0000000..191655f --- /dev/null +++ b/src/r3-d3-api-geometry-buffer-octahedron.js @@ -0,0 +1,46 @@ +/** + * R3.D3.API.Geometry.Buffer.Octahedron + * @param apiGeometry + * @param radius + * @param detail + * @constructor + */ +R3.D3.API.Geometry.Buffer.Octahedron = function( + apiGeometry, + radius, + detail +) { + + if (R3.Utils.UndefinedOrNull(apiGeometry)) { + apiGeometry = { + geometryType: R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_OCTAHEDRON + }; + } + + if (R3.Utils.UndefinedOrNull(apiGeometry.geometryType)) { + apiGeometry.geometryType = R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_OCTAHEDRON; + } + + if (R3.Utils.UndefinedOrNull(radius)) { + radius = 1; + } + this.radius = radius; + + if (R3.Utils.UndefinedOrNull(detail)) { + detail = 0; + } + this.detail = detail; + + R3.D3.API.Geometry.Buffer.call( + this, + apiGeometry, + apiGeometry.attributes, + apiGeometry.drawRange, + apiGeometry.groups, + apiGeometry.index, + apiGeometry.morphAttributes + ); +}; + +R3.D3.API.Geometry.Buffer.Octahedron.prototype = Object.create(R3.D3.API.Geometry.Buffer.prototype); +R3.D3.API.Geometry.Buffer.Octahedron.prototype.constructor = R3.D3.API.Geometry.Buffer.Octahedron; diff --git a/src/r3-d3-api-geometry-buffer-parametric.js b/src/r3-d3-api-geometry-buffer-parametric.js new file mode 100644 index 0000000..15bf883 --- /dev/null +++ b/src/r3-d3-api-geometry-buffer-parametric.js @@ -0,0 +1,53 @@ +/** + * R3.D3.API.Geometry.Buffer.Parametric + * @param apiGeometry + * @param generatorFn(u,v) => returns Vector3, u and v is values between 0 and 1 + * @param slices + * @param stacks + * @constructor + */ +R3.D3.API.Geometry.Buffer.Parametric = function( + apiGeometry, + generatorFn, + slices, + stacks +) { + + if (R3.Utils.UndefinedOrNull(apiGeometry)) { + apiGeometry = { + geometryType: R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_PARAMETRIC + }; + } + + if (R3.Utils.UndefinedOrNull(apiGeometry.geometryType)) { + apiGeometry.geometryType = R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_PARAMETRIC; + } + + if (R3.Utils.UndefinedOrNull(generatorFn)) { + generatorFn = ''; + } + this.generatorFn = generatorFn; + + if (R3.Utils.UndefinedOrNull(slices)) { + slices = 20; + } + this.slices = slices; + + if (R3.Utils.UndefinedOrNull(stacks)) { + stacks = 20; + } + this.stacks = stacks; + + R3.D3.API.Geometry.Buffer.call( + this, + apiGeometry, + apiGeometry.attributes, + apiGeometry.drawRange, + apiGeometry.groups, + apiGeometry.index, + apiGeometry.morphAttributes + ); +}; + +R3.D3.API.Geometry.Buffer.Parametric.prototype = Object.create(R3.D3.API.Geometry.Buffer.prototype); +R3.D3.API.Geometry.Buffer.Parametric.prototype.constructor = R3.D3.API.Geometry.Buffer.Parametric; diff --git a/src/r3-d3-api-geometry-buffer-plane.js b/src/r3-d3-api-geometry-buffer-plane.js new file mode 100644 index 0000000..506cbd2 --- /dev/null +++ b/src/r3-d3-api-geometry-buffer-plane.js @@ -0,0 +1,60 @@ +/** + * R3.D3.API.Geometry.Buffer.Plane + * @param apiGeometry + * @param width + * @param height + * @param widthSegments + * @param heightSegments + * @constructor + */ +R3.D3.API.Geometry.Buffer.Plane = function( + apiGeometry, + width, + height, + widthSegments, + heightSegments +) { + + if (R3.Utils.UndefinedOrNull(apiGeometry)) { + apiGeometry = { + geometryType: R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_PLANE + }; + } + + if (R3.Utils.UndefinedOrNull(apiGeometry.geometryType)) { + apiGeometry.geometryType = R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_PLANE; + } + + if (R3.Utils.UndefinedOrNull(width)) { + width = 1; + } + this.width = width; + + if (R3.Utils.UndefinedOrNull(height)) { + height = 1; + } + this.height = height; + + if (R3.Utils.UndefinedOrNull(widthSegments)) { + widthSegments = 1; + } + this.widthSegments = widthSegments; + + if (R3.Utils.UndefinedOrNull(heightSegments)) { + heightSegments = 1; + } + this.heightSegments = heightSegments; + + R3.D3.API.Geometry.Buffer.call( + this, + apiGeometry, + apiGeometry.attributes, + apiGeometry.drawRange, + apiGeometry.groups, + apiGeometry.index, + apiGeometry.morphAttributes + ); +}; + +R3.D3.API.Geometry.Buffer.Plane.prototype = Object.create(R3.D3.API.Geometry.Buffer.prototype); +R3.D3.API.Geometry.Buffer.Plane.prototype.constructor = R3.D3.API.Geometry.Buffer.Plane; diff --git a/src/r3-d3-api-geometry-buffer-polyhedron.js b/src/r3-d3-api-geometry-buffer-polyhedron.js new file mode 100644 index 0000000..ddbcb6c --- /dev/null +++ b/src/r3-d3-api-geometry-buffer-polyhedron.js @@ -0,0 +1,60 @@ +/** + * R3.D3.API.Geometry.Buffer.Polyhedron + * @param apiGeometry + * @param vertices + * @param indices + * @param radius + * @param detail + * @constructor + */ +R3.D3.API.Geometry.Buffer.Polyhedron = function( + apiGeometry, + vertices, + indices, + radius, + detail +) { + + if (R3.Utils.UndefinedOrNull(apiGeometry)) { + apiGeometry = { + geometryType: R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_POLYHEDRON + }; + } + + if (R3.Utils.UndefinedOrNull(apiGeometry.geometryType)) { + apiGeometry.geometryType = R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_POLYHEDRON; + } + + if (R3.Utils.UndefinedOrNull(vertices)) { + vertices = []; + } + this.vertices = vertices; + + if (R3.Utils.UndefinedOrNull(indices)) { + indices = 1; + } + this.indices = indices; + + if (R3.Utils.UndefinedOrNull(radius)) { + radius = 5; + } + this.radius = radius; + + if (R3.Utils.UndefinedOrNull(detail)) { + detail = 0; + } + this.detail = detail; + + R3.D3.API.Geometry.Buffer.call( + this, + apiGeometry, + apiGeometry.attributes, + apiGeometry.drawRange, + apiGeometry.groups, + apiGeometry.index, + apiGeometry.morphAttributes + ); +}; + +R3.D3.API.Geometry.Buffer.Polyhedron.prototype = Object.create(R3.D3.API.Geometry.Buffer.prototype); +R3.D3.API.Geometry.Buffer.Polyhedron.prototype.constructor = R3.D3.API.Geometry.Buffer.Polyhedron; diff --git a/src/game-lib-d3-api-geometry-buffer-ring.js b/src/r3-d3-api-geometry-buffer-ring.js similarity index 50% rename from src/game-lib-d3-api-geometry-buffer-ring.js rename to src/r3-d3-api-geometry-buffer-ring.js index 38072b5..88a3805 100644 --- a/src/game-lib-d3-api-geometry-buffer-ring.js +++ b/src/r3-d3-api-geometry-buffer-ring.js @@ -1,5 +1,5 @@ /** - * GameLib.D3.API.Geometry.Buffer.Ring + * R3.D3.API.Geometry.Buffer.Ring * @param apiGeometry * @param innerRadius * @param outerRadius @@ -9,7 +9,7 @@ * @param thetaLength * @constructor */ -GameLib.D3.API.Geometry.Buffer.Ring = function( +R3.D3.API.Geometry.Buffer.Ring = function( apiGeometry, innerRadius, outerRadius, @@ -19,47 +19,47 @@ GameLib.D3.API.Geometry.Buffer.Ring = function( thetaLength ) { - if (GameLib.Utils.UndefinedOrNull(apiGeometry)) { + if (R3.Utils.UndefinedOrNull(apiGeometry)) { apiGeometry = { - geometryType: GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_RING + geometryType: R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_RING }; } - if (GameLib.Utils.UndefinedOrNull(apiGeometry.geometryType)) { - apiGeometry.geometryType = GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_RING; + if (R3.Utils.UndefinedOrNull(apiGeometry.geometryType)) { + apiGeometry.geometryType = R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_RING; } - if (GameLib.Utils.UndefinedOrNull(innerRadius)) { + if (R3.Utils.UndefinedOrNull(innerRadius)) { innerRadius = 0.5; } this.innerRadius = innerRadius; - if (GameLib.Utils.UndefinedOrNull(outerRadius)) { + if (R3.Utils.UndefinedOrNull(outerRadius)) { outerRadius = 1; } this.outerRadius = outerRadius; - if (GameLib.Utils.UndefinedOrNull(thetaSegments)) { + if (R3.Utils.UndefinedOrNull(thetaSegments)) { thetaSegments = 8; } this.thetaSegments = thetaSegments; - if (GameLib.Utils.UndefinedOrNull(phiSegments)) { + if (R3.Utils.UndefinedOrNull(phiSegments)) { phiSegments = 8; } this.phiSegments = phiSegments; - if (GameLib.Utils.UndefinedOrNull(thetaStart)) { + if (R3.Utils.UndefinedOrNull(thetaStart)) { thetaStart = 0; } this.thetaStart = thetaStart; - if (GameLib.Utils.UndefinedOrNull(thetaLength)) { + if (R3.Utils.UndefinedOrNull(thetaLength)) { thetaLength = Math.PI * 2; } this.thetaLength = thetaLength; - GameLib.D3.API.Geometry.Buffer.call( + R3.D3.API.Geometry.Buffer.call( this, apiGeometry, apiGeometry.attributes, @@ -70,5 +70,5 @@ GameLib.D3.API.Geometry.Buffer.Ring = function( ); }; -GameLib.D3.API.Geometry.Buffer.Ring.prototype = Object.create(GameLib.D3.API.Geometry.Buffer.prototype); -GameLib.D3.API.Geometry.Buffer.Ring.prototype.constructor = GameLib.D3.API.Geometry.Buffer.Ring; +R3.D3.API.Geometry.Buffer.Ring.prototype = Object.create(R3.D3.API.Geometry.Buffer.prototype); +R3.D3.API.Geometry.Buffer.Ring.prototype.constructor = R3.D3.API.Geometry.Buffer.Ring; diff --git a/src/r3-d3-api-geometry-buffer-shape.js b/src/r3-d3-api-geometry-buffer-shape.js new file mode 100644 index 0000000..062d309 --- /dev/null +++ b/src/r3-d3-api-geometry-buffer-shape.js @@ -0,0 +1,46 @@ +/** + * R3.D3.API.Geometry.Buffer.Shape + * @param apiGeometry + * @param shapes + * @param curveSegments + * @constructor + */ +R3.D3.API.Geometry.Buffer.Shape = function( + apiGeometry, + shapes, + curveSegments +) { + + if (R3.Utils.UndefinedOrNull(apiGeometry)) { + apiGeometry = { + geometryType: R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_SHAPE + }; + } + + if (R3.Utils.UndefinedOrNull(apiGeometry.geometryType)) { + apiGeometry.geometryType = R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_SHAPE; + } + + if (R3.Utils.UndefinedOrNull(shapes)) { + shapes = []; + } + this.shapes = shapes; + + if (R3.Utils.UndefinedOrNull(curveSegments)) { + curveSegments = 12; + } + this.curveSegments = curveSegments; + + R3.D3.API.Geometry.Buffer.call( + this, + apiGeometry, + apiGeometry.attributes, + apiGeometry.drawRange, + apiGeometry.groups, + apiGeometry.index, + apiGeometry.morphAttributes + ); +}; + +R3.D3.API.Geometry.Buffer.Shape.prototype = Object.create(R3.D3.API.Geometry.Buffer.prototype); +R3.D3.API.Geometry.Buffer.Shape.prototype.constructor = R3.D3.API.Geometry.Buffer.Shape; diff --git a/src/game-lib-d3-api-geometry-buffer-sphere.js b/src/r3-d3-api-geometry-buffer-sphere.js similarity index 51% rename from src/game-lib-d3-api-geometry-buffer-sphere.js rename to src/r3-d3-api-geometry-buffer-sphere.js index 95acc8a..f7651de 100644 --- a/src/game-lib-d3-api-geometry-buffer-sphere.js +++ b/src/r3-d3-api-geometry-buffer-sphere.js @@ -1,5 +1,5 @@ /** - * GameLib.D3.API.Geometry.Buffer.Sphere + * R3.D3.API.Geometry.Buffer.Sphere * @param apiGeometry * @param radius * @param widthSegments @@ -10,7 +10,7 @@ * @param thetaLength * @constructor */ -GameLib.D3.API.Geometry.Buffer.Sphere = function( +R3.D3.API.Geometry.Buffer.Sphere = function( apiGeometry, radius, widthSegments, @@ -21,52 +21,52 @@ GameLib.D3.API.Geometry.Buffer.Sphere = function( thetaLength ) { - if (GameLib.Utils.UndefinedOrNull(apiGeometry)) { + if (R3.Utils.UndefinedOrNull(apiGeometry)) { apiGeometry = { - geometryType: GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_SPHERE + geometryType: R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_SPHERE }; } - if (GameLib.Utils.UndefinedOrNull(apiGeometry.geometryType)) { - apiGeometry.geometryType = GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_SPHERE; + if (R3.Utils.UndefinedOrNull(apiGeometry.geometryType)) { + apiGeometry.geometryType = R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_SPHERE; } - if (GameLib.Utils.UndefinedOrNull(radius)) { + if (R3.Utils.UndefinedOrNull(radius)) { radius = 1; } this.radius = radius; - if (GameLib.Utils.UndefinedOrNull(widthSegments)) { + if (R3.Utils.UndefinedOrNull(widthSegments)) { widthSegments = 8; } this.widthSegments = widthSegments; - if (GameLib.Utils.UndefinedOrNull(heightSegments)) { + if (R3.Utils.UndefinedOrNull(heightSegments)) { heightSegments = 6; } this.heightSegments = heightSegments; - if (GameLib.Utils.UndefinedOrNull(phiStart)) { + if (R3.Utils.UndefinedOrNull(phiStart)) { phiStart = 0; } this.phiStart = phiStart; - if (GameLib.Utils.UndefinedOrNull(phiLength)) { + if (R3.Utils.UndefinedOrNull(phiLength)) { phiLength = Math.PI * 2; } this.phiLength = phiLength; - if (GameLib.Utils.UndefinedOrNull(thetaStart)) { + if (R3.Utils.UndefinedOrNull(thetaStart)) { thetaStart = 0; } this.thetaStart = thetaStart; - if (GameLib.Utils.UndefinedOrNull(thetaLength)) { + if (R3.Utils.UndefinedOrNull(thetaLength)) { thetaLength = Math.PI; } this.thetaLength = thetaLength; - GameLib.D3.API.Geometry.Buffer.call( + R3.D3.API.Geometry.Buffer.call( this, apiGeometry, apiGeometry.attributes, @@ -77,5 +77,5 @@ GameLib.D3.API.Geometry.Buffer.Sphere = function( ); }; -GameLib.D3.API.Geometry.Buffer.Sphere.prototype = Object.create(GameLib.D3.API.Geometry.Buffer.prototype); -GameLib.D3.API.Geometry.Buffer.Sphere.prototype.constructor = GameLib.D3.API.Geometry.Buffer.Sphere; +R3.D3.API.Geometry.Buffer.Sphere.prototype = Object.create(R3.D3.API.Geometry.Buffer.prototype); +R3.D3.API.Geometry.Buffer.Sphere.prototype.constructor = R3.D3.API.Geometry.Buffer.Sphere; diff --git a/src/r3-d3-api-geometry-buffer-tetrahedron.js b/src/r3-d3-api-geometry-buffer-tetrahedron.js new file mode 100644 index 0000000..734e0f9 --- /dev/null +++ b/src/r3-d3-api-geometry-buffer-tetrahedron.js @@ -0,0 +1,46 @@ +/** + * R3.D3.API.Geometry.Buffer.Tetrahedron + * @param apiGeometry + * @param radius + * @param detail + * @constructor + */ +R3.D3.API.Geometry.Buffer.Tetrahedron = function( + apiGeometry, + radius, + detail +) { + + if (R3.Utils.UndefinedOrNull(apiGeometry)) { + apiGeometry = { + geometryType: R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TETRAHEDRON + }; + } + + if (R3.Utils.UndefinedOrNull(apiGeometry.geometryType)) { + apiGeometry.geometryType = R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TETRAHEDRON; + } + + if (R3.Utils.UndefinedOrNull(radius)) { + radius = 1; + } + this.radius = radius; + + if (R3.Utils.UndefinedOrNull(detail)) { + detail = 0; + } + this.detail = detail; + + R3.D3.API.Geometry.Buffer.call( + this, + apiGeometry, + apiGeometry.attributes, + apiGeometry.drawRange, + apiGeometry.groups, + apiGeometry.index, + apiGeometry.morphAttributes + ); +}; + +R3.D3.API.Geometry.Buffer.Tetrahedron.prototype = Object.create(R3.D3.API.Geometry.Buffer.prototype); +R3.D3.API.Geometry.Buffer.Tetrahedron.prototype.constructor = R3.D3.API.Geometry.Buffer.Tetrahedron; diff --git a/src/game-lib-d3-api-geometry-buffer-text.js b/src/r3-d3-api-geometry-buffer-text.js similarity index 52% rename from src/game-lib-d3-api-geometry-buffer-text.js rename to src/r3-d3-api-geometry-buffer-text.js index 4a34424..2b6d5de 100644 --- a/src/game-lib-d3-api-geometry-buffer-text.js +++ b/src/r3-d3-api-geometry-buffer-text.js @@ -1,5 +1,5 @@ /** - * GameLib.D3.API.Geometry.Buffer.Text + * R3.D3.API.Geometry.Buffer.Text * @param apiGeometry * @param text * @param font @@ -12,7 +12,7 @@ * @param bevelSegments * @constructor */ -GameLib.D3.API.Geometry.Buffer.Text = function( +R3.D3.API.Geometry.Buffer.Text = function( apiGeometry, text, font, @@ -25,62 +25,62 @@ GameLib.D3.API.Geometry.Buffer.Text = function( bevelSegments ) { - if (GameLib.Utils.UndefinedOrNull(apiGeometry)) { + if (R3.Utils.UndefinedOrNull(apiGeometry)) { apiGeometry = { - geometryType: GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TEXT + geometryType: R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TEXT }; } - if (GameLib.Utils.UndefinedOrNull(apiGeometry.geometryType)) { - apiGeometry.geometryType = GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TEXT; + if (R3.Utils.UndefinedOrNull(apiGeometry.geometryType)) { + apiGeometry.geometryType = R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TEXT; } - if (GameLib.Utils.UndefinedOrNull(text)) { + if (R3.Utils.UndefinedOrNull(text)) { text = '-= returns Vector3, u and v is values between 0 and 1 * @param slices * @param stacks * @constructor */ -GameLib.D3.API.Geometry.Normal.Parametric = function( +R3.D3.API.Geometry.Normal.Parametric = function( apiGeometry, generatorFn, slices, stacks ) { - if (GameLib.Utils.UndefinedOrNull(apiGeometry)) { + if (R3.Utils.UndefinedOrNull(apiGeometry)) { apiGeometry = { - geometryType: GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_PARAMETRIC + geometryType: R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_PARAMETRIC }; } - if (GameLib.Utils.UndefinedOrNull(apiGeometry.geometryType)) { - apiGeometry.geometryType = GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_PARAMETRIC; + if (R3.Utils.UndefinedOrNull(apiGeometry.geometryType)) { + apiGeometry.geometryType = R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_PARAMETRIC; } - if (GameLib.Utils.UndefinedOrNull(generatorFn)) { + if (R3.Utils.UndefinedOrNull(generatorFn)) { generatorFn = ''; } this.generatorFn = generatorFn; - if (GameLib.Utils.UndefinedOrNull(slices)) { + if (R3.Utils.UndefinedOrNull(slices)) { slices = 20; } this.slices = slices; - if (GameLib.Utils.UndefinedOrNull(stacks)) { + if (R3.Utils.UndefinedOrNull(stacks)) { stacks = 20; } this.stacks = stacks; - GameLib.D3.API.Geometry.Normal.call( + R3.D3.API.Geometry.Normal.call( this, apiGeometry, apiGeometry.colors, @@ -57,5 +57,5 @@ GameLib.D3.API.Geometry.Normal.Parametric = function( ); }; -GameLib.D3.API.Geometry.Normal.Parametric.prototype = Object.create(GameLib.D3.API.Geometry.Normal.prototype); -GameLib.D3.API.Geometry.Normal.Parametric.prototype.constructor = GameLib.D3.API.Geometry.Normal.Parametric; +R3.D3.API.Geometry.Normal.Parametric.prototype = Object.create(R3.D3.API.Geometry.Normal.prototype); +R3.D3.API.Geometry.Normal.Parametric.prototype.constructor = R3.D3.API.Geometry.Normal.Parametric; diff --git a/src/game-lib-d3-api-geometry-normal-plane.js b/src/r3-d3-api-geometry-normal-plane.js similarity index 55% rename from src/game-lib-d3-api-geometry-normal-plane.js rename to src/r3-d3-api-geometry-normal-plane.js index 683076e..ec54326 100644 --- a/src/game-lib-d3-api-geometry-normal-plane.js +++ b/src/r3-d3-api-geometry-normal-plane.js @@ -1,5 +1,5 @@ /** - * GameLib.D3.API.Geometry.Normal.Plane + * R3.D3.API.Geometry.Normal.Plane * @param apiGeometry * @param width * @param height @@ -7,7 +7,7 @@ * @param heightSegments * @constructor */ -GameLib.D3.API.Geometry.Normal.Plane = function( +R3.D3.API.Geometry.Normal.Plane = function( apiGeometry, width, height, @@ -15,37 +15,37 @@ GameLib.D3.API.Geometry.Normal.Plane = function( heightSegments ) { - if (GameLib.Utils.UndefinedOrNull(apiGeometry)) { + if (R3.Utils.UndefinedOrNull(apiGeometry)) { apiGeometry = { - geometryType: GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_PLANE + geometryType: R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_PLANE }; } - if (GameLib.Utils.UndefinedOrNull(apiGeometry.geometryType)) { - apiGeometry.geometryType = GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_PLANE; + if (R3.Utils.UndefinedOrNull(apiGeometry.geometryType)) { + apiGeometry.geometryType = R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_PLANE; } - if (GameLib.Utils.UndefinedOrNull(width)) { + if (R3.Utils.UndefinedOrNull(width)) { width = 1; } this.width = width; - if (GameLib.Utils.UndefinedOrNull(height)) { + if (R3.Utils.UndefinedOrNull(height)) { height = 1; } this.height = height; - if (GameLib.Utils.UndefinedOrNull(widthSegments)) { + if (R3.Utils.UndefinedOrNull(widthSegments)) { widthSegments = 1; } this.widthSegments = widthSegments; - if (GameLib.Utils.UndefinedOrNull(heightSegments)) { + if (R3.Utils.UndefinedOrNull(heightSegments)) { heightSegments = 1; } this.heightSegments = heightSegments; - GameLib.D3.API.Geometry.Normal.call( + R3.D3.API.Geometry.Normal.call( this, apiGeometry, apiGeometry.colors, @@ -64,5 +64,5 @@ GameLib.D3.API.Geometry.Normal.Plane = function( ); }; -GameLib.D3.API.Geometry.Normal.Plane.prototype = Object.create(GameLib.D3.API.Geometry.Normal.prototype); -GameLib.D3.API.Geometry.Normal.Plane.prototype.constructor = GameLib.D3.API.Geometry.Normal.Plane; +R3.D3.API.Geometry.Normal.Plane.prototype = Object.create(R3.D3.API.Geometry.Normal.prototype); +R3.D3.API.Geometry.Normal.Plane.prototype.constructor = R3.D3.API.Geometry.Normal.Plane; diff --git a/src/game-lib-d3-api-geometry-normal-polyhedron.js b/src/r3-d3-api-geometry-normal-polyhedron.js similarity index 53% rename from src/game-lib-d3-api-geometry-normal-polyhedron.js rename to src/r3-d3-api-geometry-normal-polyhedron.js index c092156..652531f 100644 --- a/src/game-lib-d3-api-geometry-normal-polyhedron.js +++ b/src/r3-d3-api-geometry-normal-polyhedron.js @@ -1,5 +1,5 @@ /** - * GameLib.D3.API.Geometry.Normal.Polyhedron + * R3.D3.API.Geometry.Normal.Polyhedron * @param apiGeometry * @param vertices * @param indices @@ -7,7 +7,7 @@ * @param detail * @constructor */ -GameLib.D3.API.Geometry.Normal.Polyhedron = function( +R3.D3.API.Geometry.Normal.Polyhedron = function( apiGeometry, vertices, indices, @@ -15,37 +15,37 @@ GameLib.D3.API.Geometry.Normal.Polyhedron = function( detail ) { - if (GameLib.Utils.UndefinedOrNull(apiGeometry)) { + if (R3.Utils.UndefinedOrNull(apiGeometry)) { apiGeometry = { - geometryType: GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_POLYHEDRON + geometryType: R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_POLYHEDRON }; } - if (GameLib.Utils.UndefinedOrNull(apiGeometry.geometryType)) { - apiGeometry.geometryType = GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_POLYHEDRON; + if (R3.Utils.UndefinedOrNull(apiGeometry.geometryType)) { + apiGeometry.geometryType = R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_POLYHEDRON; } - if (GameLib.Utils.UndefinedOrNull(vertices)) { + if (R3.Utils.UndefinedOrNull(vertices)) { vertices = []; } this.vertices = vertices; - if (GameLib.Utils.UndefinedOrNull(indices)) { + if (R3.Utils.UndefinedOrNull(indices)) { indices = 1; } this.indices = indices; - if (GameLib.Utils.UndefinedOrNull(radius)) { + if (R3.Utils.UndefinedOrNull(radius)) { radius = 5; } this.radius = radius; - if (GameLib.Utils.UndefinedOrNull(detail)) { + if (R3.Utils.UndefinedOrNull(detail)) { detail = 0; } this.detail = detail; - GameLib.D3.API.Geometry.Normal.call( + R3.D3.API.Geometry.Normal.call( this, apiGeometry, apiGeometry.colors, @@ -64,5 +64,5 @@ GameLib.D3.API.Geometry.Normal.Polyhedron = function( ); }; -GameLib.D3.API.Geometry.Normal.Polyhedron.prototype = Object.create(GameLib.D3.API.Geometry.Normal.prototype); -GameLib.D3.API.Geometry.Normal.Polyhedron.prototype.constructor = GameLib.D3.API.Geometry.Normal.Polyhedron; +R3.D3.API.Geometry.Normal.Polyhedron.prototype = Object.create(R3.D3.API.Geometry.Normal.prototype); +R3.D3.API.Geometry.Normal.Polyhedron.prototype.constructor = R3.D3.API.Geometry.Normal.Polyhedron; diff --git a/src/game-lib-d3-api-geometry-normal-ring.js b/src/r3-d3-api-geometry-normal-ring.js similarity index 57% rename from src/game-lib-d3-api-geometry-normal-ring.js rename to src/r3-d3-api-geometry-normal-ring.js index 0b1891c..0873d80 100644 --- a/src/game-lib-d3-api-geometry-normal-ring.js +++ b/src/r3-d3-api-geometry-normal-ring.js @@ -1,5 +1,5 @@ /** - * GameLib.D3.API.Geometry.Normal.Ring + * R3.D3.API.Geometry.Normal.Ring * @param apiGeometry * @param innerRadius * @param outerRadius @@ -9,7 +9,7 @@ * @param thetaLength * @constructor */ -GameLib.D3.API.Geometry.Normal.Ring = function( +R3.D3.API.Geometry.Normal.Ring = function( apiGeometry, innerRadius, outerRadius, @@ -19,47 +19,47 @@ GameLib.D3.API.Geometry.Normal.Ring = function( thetaLength ) { - if (GameLib.Utils.UndefinedOrNull(apiGeometry)) { + if (R3.Utils.UndefinedOrNull(apiGeometry)) { apiGeometry = { - geometryType: GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_RING + geometryType: R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_RING }; } - if (GameLib.Utils.UndefinedOrNull(apiGeometry.geometryType)) { - apiGeometry.geometryType = GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_RING; + if (R3.Utils.UndefinedOrNull(apiGeometry.geometryType)) { + apiGeometry.geometryType = R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_RING; } - if (GameLib.Utils.UndefinedOrNull(innerRadius)) { + if (R3.Utils.UndefinedOrNull(innerRadius)) { innerRadius = 0.5; } this.innerRadius = innerRadius; - if (GameLib.Utils.UndefinedOrNull(outerRadius)) { + if (R3.Utils.UndefinedOrNull(outerRadius)) { outerRadius = 1; } this.outerRadius = outerRadius; - if (GameLib.Utils.UndefinedOrNull(thetaSegments)) { + if (R3.Utils.UndefinedOrNull(thetaSegments)) { thetaSegments = 8; } this.thetaSegments = thetaSegments; - if (GameLib.Utils.UndefinedOrNull(phiSegments)) { + if (R3.Utils.UndefinedOrNull(phiSegments)) { phiSegments = 8; } this.phiSegments = phiSegments; - if (GameLib.Utils.UndefinedOrNull(thetaStart)) { + if (R3.Utils.UndefinedOrNull(thetaStart)) { thetaStart = 0; } this.thetaStart = thetaStart; - if (GameLib.Utils.UndefinedOrNull(thetaLength)) { + if (R3.Utils.UndefinedOrNull(thetaLength)) { thetaLength = Math.PI * 2; } this.thetaLength = thetaLength; - GameLib.D3.API.Geometry.Normal.call( + R3.D3.API.Geometry.Normal.call( this, apiGeometry, apiGeometry.colors, @@ -78,5 +78,5 @@ GameLib.D3.API.Geometry.Normal.Ring = function( ); }; -GameLib.D3.API.Geometry.Normal.Ring.prototype = Object.create(GameLib.D3.API.Geometry.Normal.prototype); -GameLib.D3.API.Geometry.Normal.Ring.prototype.constructor = GameLib.D3.API.Geometry.Normal.Ring; +R3.D3.API.Geometry.Normal.Ring.prototype = Object.create(R3.D3.API.Geometry.Normal.prototype); +R3.D3.API.Geometry.Normal.Ring.prototype.constructor = R3.D3.API.Geometry.Normal.Ring; diff --git a/src/game-lib-d3-api-geometry-normal-shape.js b/src/r3-d3-api-geometry-normal-shape.js similarity index 53% rename from src/game-lib-d3-api-geometry-normal-shape.js rename to src/r3-d3-api-geometry-normal-shape.js index 3c05c75..1730c0e 100644 --- a/src/game-lib-d3-api-geometry-normal-shape.js +++ b/src/r3-d3-api-geometry-normal-shape.js @@ -1,37 +1,37 @@ /** - * GameLib.D3.API.Geometry.Normal.Shape + * R3.D3.API.Geometry.Normal.Shape * @param apiGeometry * @param shapes * @param curveSegments * @constructor */ -GameLib.D3.API.Geometry.Normal.Shape = function( +R3.D3.API.Geometry.Normal.Shape = function( apiGeometry, shapes, curveSegments ) { - if (GameLib.Utils.UndefinedOrNull(apiGeometry)) { + if (R3.Utils.UndefinedOrNull(apiGeometry)) { apiGeometry = { - geometryType: GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_SHAPE + geometryType: R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_SHAPE }; } - if (GameLib.Utils.UndefinedOrNull(apiGeometry.geometryType)) { - apiGeometry.geometryType = GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_SHAPE; + if (R3.Utils.UndefinedOrNull(apiGeometry.geometryType)) { + apiGeometry.geometryType = R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_SHAPE; } - if (GameLib.Utils.UndefinedOrNull(shapes)) { + if (R3.Utils.UndefinedOrNull(shapes)) { shapes = []; } this.shapes = shapes; - if (GameLib.Utils.UndefinedOrNull(curveSegments)) { + if (R3.Utils.UndefinedOrNull(curveSegments)) { curveSegments = 12; } this.curveSegments = curveSegments; - GameLib.D3.API.Geometry.Normal.call( + R3.D3.API.Geometry.Normal.call( this, apiGeometry, apiGeometry.colors, @@ -50,5 +50,5 @@ GameLib.D3.API.Geometry.Normal.Shape = function( ); }; -GameLib.D3.API.Geometry.Normal.Shape.prototype = Object.create(GameLib.D3.API.Geometry.Normal.prototype); -GameLib.D3.API.Geometry.Normal.Shape.prototype.constructor = GameLib.D3.API.Geometry.Normal.Shape; +R3.D3.API.Geometry.Normal.Shape.prototype = Object.create(R3.D3.API.Geometry.Normal.prototype); +R3.D3.API.Geometry.Normal.Shape.prototype.constructor = R3.D3.API.Geometry.Normal.Shape; diff --git a/src/game-lib-d3-api-geometry-normal-sphere.js b/src/r3-d3-api-geometry-normal-sphere.js similarity index 57% rename from src/game-lib-d3-api-geometry-normal-sphere.js rename to src/r3-d3-api-geometry-normal-sphere.js index 8420f87..2da46a7 100644 --- a/src/game-lib-d3-api-geometry-normal-sphere.js +++ b/src/r3-d3-api-geometry-normal-sphere.js @@ -1,5 +1,5 @@ /** - * GameLib.D3.API.Geometry.Normal.Sphere + * R3.D3.API.Geometry.Normal.Sphere * @param apiGeometry * @param radius * @param widthSegments @@ -10,7 +10,7 @@ * @param thetaLength * @constructor */ -GameLib.D3.API.Geometry.Normal.Sphere = function( +R3.D3.API.Geometry.Normal.Sphere = function( apiGeometry, radius, widthSegments, @@ -21,52 +21,52 @@ GameLib.D3.API.Geometry.Normal.Sphere = function( thetaLength ) { - if (GameLib.Utils.UndefinedOrNull(apiGeometry)) { + if (R3.Utils.UndefinedOrNull(apiGeometry)) { apiGeometry = { - geometryType: GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_SPHERE + geometryType: R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_SPHERE }; } - if (GameLib.Utils.UndefinedOrNull(apiGeometry.geometryType)) { - apiGeometry.geometryType = GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_SPHERE; + if (R3.Utils.UndefinedOrNull(apiGeometry.geometryType)) { + apiGeometry.geometryType = R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_SPHERE; } - if (GameLib.Utils.UndefinedOrNull(radius)) { + if (R3.Utils.UndefinedOrNull(radius)) { radius = 1; } this.radius = radius; - if (GameLib.Utils.UndefinedOrNull(widthSegments)) { + if (R3.Utils.UndefinedOrNull(widthSegments)) { widthSegments = 8; } this.widthSegments = widthSegments; - if (GameLib.Utils.UndefinedOrNull(heightSegments)) { + if (R3.Utils.UndefinedOrNull(heightSegments)) { heightSegments = 6; } this.heightSegments = heightSegments; - if (GameLib.Utils.UndefinedOrNull(phiStart)) { + if (R3.Utils.UndefinedOrNull(phiStart)) { phiStart = 0; } this.phiStart = phiStart; - if (GameLib.Utils.UndefinedOrNull(phiLength)) { + if (R3.Utils.UndefinedOrNull(phiLength)) { phiLength = Math.PI * 2; } this.phiLength = phiLength; - if (GameLib.Utils.UndefinedOrNull(thetaStart)) { + if (R3.Utils.UndefinedOrNull(thetaStart)) { thetaStart = 0; } this.thetaStart = thetaStart; - if (GameLib.Utils.UndefinedOrNull(thetaLength)) { + if (R3.Utils.UndefinedOrNull(thetaLength)) { thetaLength = Math.PI; } this.thetaLength = thetaLength; - GameLib.D3.API.Geometry.Normal.call( + R3.D3.API.Geometry.Normal.call( this, apiGeometry, apiGeometry.colors, @@ -85,5 +85,5 @@ GameLib.D3.API.Geometry.Normal.Sphere = function( ); }; -GameLib.D3.API.Geometry.Normal.Sphere.prototype = Object.create(GameLib.D3.API.Geometry.Normal.prototype); -GameLib.D3.API.Geometry.Normal.Sphere.prototype.constructor = GameLib.D3.API.Geometry.Normal.Sphere; +R3.D3.API.Geometry.Normal.Sphere.prototype = Object.create(R3.D3.API.Geometry.Normal.prototype); +R3.D3.API.Geometry.Normal.Sphere.prototype.constructor = R3.D3.API.Geometry.Normal.Sphere; diff --git a/src/game-lib-d3-api-geometry-normal-dodecahedron.js b/src/r3-d3-api-geometry-normal-tetrahedron.js similarity index 50% rename from src/game-lib-d3-api-geometry-normal-dodecahedron.js rename to src/r3-d3-api-geometry-normal-tetrahedron.js index 5bcb07e..43dade8 100644 --- a/src/game-lib-d3-api-geometry-normal-dodecahedron.js +++ b/src/r3-d3-api-geometry-normal-tetrahedron.js @@ -1,37 +1,37 @@ /** - * GameLib.D3.API.Geometry.Normal.Dodecahedron + * R3.D3.API.Geometry.Normal.Tetrahedron * @param apiGeometry * @param radius * @param detail * @constructor */ -GameLib.D3.API.Geometry.Normal.Dodecahedron = function( +R3.D3.API.Geometry.Normal.Tetrahedron = function( apiGeometry, radius, detail ) { - if (GameLib.Utils.UndefinedOrNull(apiGeometry)) { + if (R3.Utils.UndefinedOrNull(apiGeometry)) { apiGeometry = { - geometryType: GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_DODECAHEDRON + geometryType: R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TETRAHEDRON }; } - if (GameLib.Utils.UndefinedOrNull(apiGeometry.geometryType)) { - apiGeometry.geometryType = GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_DODECAHEDRON; + if (R3.Utils.UndefinedOrNull(apiGeometry.geometryType)) { + apiGeometry.geometryType = R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TETRAHEDRON; } - if (GameLib.Utils.UndefinedOrNull(radius)) { + if (R3.Utils.UndefinedOrNull(radius)) { radius = 1; } this.radius = radius; - if (GameLib.Utils.UndefinedOrNull(detail)) { + if (R3.Utils.UndefinedOrNull(detail)) { detail = 0; } this.detail = detail; - GameLib.D3.API.Geometry.Normal.call( + R3.D3.API.Geometry.Normal.call( this, apiGeometry, apiGeometry.colors, @@ -50,5 +50,5 @@ GameLib.D3.API.Geometry.Normal.Dodecahedron = function( ); }; -GameLib.D3.API.Geometry.Normal.Dodecahedron.prototype = Object.create(GameLib.D3.API.Geometry.Normal.prototype); -GameLib.D3.API.Geometry.Normal.Dodecahedron.prototype.constructor = GameLib.D3.API.Geometry.Normal.Dodecahedron; +R3.D3.API.Geometry.Normal.Tetrahedron.prototype = Object.create(R3.D3.API.Geometry.Normal.prototype); +R3.D3.API.Geometry.Normal.Tetrahedron.prototype.constructor = R3.D3.API.Geometry.Normal.Tetrahedron; diff --git a/src/game-lib-d3-api-geometry-normal-text.js b/src/r3-d3-api-geometry-normal-text.js similarity index 58% rename from src/game-lib-d3-api-geometry-normal-text.js rename to src/r3-d3-api-geometry-normal-text.js index 3b6e712..b9f06ba 100644 --- a/src/game-lib-d3-api-geometry-normal-text.js +++ b/src/r3-d3-api-geometry-normal-text.js @@ -1,5 +1,5 @@ /** - * GameLib.D3.API.Geometry.Normal.Text + * R3.D3.API.Geometry.Normal.Text * @param apiGeometry * @param text * @param font @@ -12,7 +12,7 @@ * @param bevelSegments * @constructor */ -GameLib.D3.API.Geometry.Normal.Text = function( +R3.D3.API.Geometry.Normal.Text = function( apiGeometry, text, font, @@ -25,62 +25,62 @@ GameLib.D3.API.Geometry.Normal.Text = function( bevelSegments ) { - if (GameLib.Utils.UndefinedOrNull(apiGeometry)) { + if (R3.Utils.UndefinedOrNull(apiGeometry)) { apiGeometry = { - geometryType: GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TEXT + geometryType: R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TEXT }; } - if (GameLib.Utils.UndefinedOrNull(apiGeometry.geometryType)) { - apiGeometry.geometryType = GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TEXT; + if (R3.Utils.UndefinedOrNull(apiGeometry.geometryType)) { + apiGeometry.geometryType = R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TEXT; } - if (GameLib.Utils.UndefinedOrNull(text)) { + if (R3.Utils.UndefinedOrNull(text)) { text = '-= 0) { - normal = new GameLib.Vector3( + normal = new R3.Vector3( this.graphics, - new GameLib.API.Vector3( + new R3.API.Vector3( intersect[0].face.normal.x, intersect[0].face.normal.y, intersect[0].face.normal.z @@ -223,10 +223,10 @@ GameLib.D3.Raycaster.prototype.getFaceNormal = function(mesh) { /** * Returns the face normal (if any) of an intersection between current ray position, direction and a provided mesh - * @param mesh GameLib.D3.Mesh - * @returns {null | GameLib.Vector3} + * @param mesh R3.D3.Mesh + * @returns {null | R3.Vector3} */ -GameLib.D3.Raycaster.prototype.getIntersectPoint = function(mesh) { +R3.D3.Raycaster.prototype.getIntersectPoint = function(mesh) { var point = null; @@ -235,9 +235,9 @@ GameLib.D3.Raycaster.prototype.getIntersectPoint = function(mesh) { ); if (intersect && intersect.length > 0) { - point = new GameLib.Vector3( + point = new R3.Vector3( this.graphics, - new GameLib.API.Vector3( + new R3.API.Vector3( intersect[0].point.x, intersect[0].point.y, intersect[0].point.z diff --git a/src/game-lib-d3-render-target-a.js b/src/r3-d3-render-target-a.js similarity index 70% rename from src/game-lib-d3-render-target-a.js rename to src/r3-d3-render-target-a.js index 95f734a..c085061 100644 --- a/src/game-lib-d3-render-target-a.js +++ b/src/r3-d3-render-target-a.js @@ -1,10 +1,10 @@ /** * Renders a scene with a camera - * @param graphics GameLib.GraphicsRuntime - * @param apiRenderTarget GameLib.D3.API.RenderTarget + * @param graphics R3.GraphicsRuntime + * @param apiRenderTarget R3.D3.API.RenderTarget * @constructor */ -GameLib.D3.RenderTarget = function ( +R3.D3.RenderTarget = function ( graphics, apiRenderTarget ) { @@ -12,13 +12,13 @@ GameLib.D3.RenderTarget = function ( this.graphics = graphics; this.graphics.isNotThreeThrow(); - if (GameLib.Utils.UndefinedOrNull(apiRenderTarget)) { + if (R3.Utils.UndefinedOrNull(apiRenderTarget)) { apiRenderTarget = { - renderTargetType : GameLib.D3.API.RenderTarget.TARGET_TYPE_NORMAL + renderTargetType : R3.D3.API.RenderTarget.TARGET_TYPE_NORMAL }; } - GameLib.D3.API.RenderTarget.call( + R3.D3.API.RenderTarget.call( this, apiRenderTarget.id, apiRenderTarget.name, @@ -37,47 +37,47 @@ GameLib.D3.RenderTarget = function ( apiRenderTarget.textureParameters ); - this.scissor = new GameLib.Vector4( + this.scissor = new R3.Vector4( this.graphics, this.scissor, this ); - if (this.viewport instanceof GameLib.D3.API.Viewport) { - this.viewport = new GameLib.D3.Viewport( + if (this.viewport instanceof R3.D3.API.Viewport) { + this.viewport = new R3.D3.Viewport( this.graphics, this.viewport ); } - if (this.texture instanceof GameLib.D3.API.Texture) { - this.texture = new GameLib.D3.Texture( + if (this.texture instanceof R3.D3.API.Texture) { + this.texture = new R3.D3.Texture( this.graphics, this.texture ) } - if (this.depthTexture instanceof GameLib.D3.API.Texture) { - this.depthTexture = new GameLib.D3.Texture( + if (this.depthTexture instanceof R3.D3.API.Texture) { + this.depthTexture = new R3.D3.Texture( this.graphics, this.depthTexture ) } - GameLib.Component.call( + R3.Component.call( this, { - 'texture' : GameLib.D3.Texture, - 'depthTexture' : GameLib.D3.Texture, - 'viewport' : GameLib.D3.Viewport + 'texture' : R3.D3.Texture, + 'depthTexture' : R3.D3.Texture, + 'viewport' : R3.D3.Viewport } ); }; -GameLib.D3.RenderTarget.prototype = Object.create(GameLib.Component.prototype); -GameLib.D3.RenderTarget.prototype.constructor = GameLib.D3.RenderTarget; +R3.D3.RenderTarget.prototype = Object.create(R3.Component.prototype); +R3.D3.RenderTarget.prototype.constructor = R3.D3.RenderTarget; -GameLib.D3.RenderTarget.prototype.applyToInstance = function() { +R3.D3.RenderTarget.prototype.applyToInstance = function() { this.instance.scissor = this.scissor.instance; this.instance.scissorTest = this.scissorTest; @@ -87,8 +87,8 @@ GameLib.D3.RenderTarget.prototype.applyToInstance = function() { if (this.instance.texture) { - if (GameLib.Utils.UndefinedOrNull(this.texture)) { - this.texture = new GameLib.D3.Texture(this.graphics); + if (R3.Utils.UndefinedOrNull(this.texture)) { + this.texture = new R3.D3.Texture(this.graphics); this.texture.instance = this.instance.texture; this.texture.updateFromInstance(); } else { @@ -97,7 +97,7 @@ GameLib.D3.RenderTarget.prototype.applyToInstance = function() { } this.publish( - GameLib.Event.TEXTURE_INSTANCE_UPDATED, + R3.Event.TEXTURE_INSTANCE_UPDATED, { texture : this.texture } @@ -106,8 +106,8 @@ GameLib.D3.RenderTarget.prototype.applyToInstance = function() { if (this.instance.depthTexture) { - if (GameLib.Utils.UndefinedOrNull(this.depthTexture)) { - this.depthTexture = new GameLib.D3.Texture(this.graphics); + if (R3.Utils.UndefinedOrNull(this.depthTexture)) { + this.depthTexture = new R3.D3.Texture(this.graphics); this.depthTexture.instance = this.instance.depthTexture; this.depthTexture.updateFromInstance(); } else { @@ -116,7 +116,7 @@ GameLib.D3.RenderTarget.prototype.applyToInstance = function() { } this.publish( - GameLib.Event.TEXTURE_INSTANCE_UPDATED, + R3.Event.TEXTURE_INSTANCE_UPDATED, { texture : this.depthTexture } @@ -129,16 +129,16 @@ GameLib.D3.RenderTarget.prototype.applyToInstance = function() { * Creates a Render Target instance * @returns {*} */ -GameLib.D3.RenderTarget.prototype.createInstance = function() { +R3.D3.RenderTarget.prototype.createInstance = function() { if (this.autoUpdateSize) { - GameLib.Utils.UpdateWindowSize(this); + R3.Utils.UpdateWindowSize(this); } /** * Only create the instance if it does not already exist - it could be created by a child */ - if (GameLib.Utils.UndefinedOrNull(this.instance)) { + if (R3.Utils.UndefinedOrNull(this.instance)) { this.instance = new THREE.WebGLRenderTarget( this.width, this.height, @@ -151,12 +151,12 @@ GameLib.D3.RenderTarget.prototype.createInstance = function() { * Or, we loaded it from API, so our texture is up to date, and we should update our instance */ - if (GameLib.Utils.UndefinedOrNull(this.texture)) { + if (R3.Utils.UndefinedOrNull(this.texture)) { /** * We need to generate a new texture and update it from the instance (we provide an overrideInstance) */ - this.texture = new GameLib.D3.Texture( + this.texture = new R3.D3.Texture( this.graphics, null, this.instance.texture @@ -172,20 +172,20 @@ GameLib.D3.RenderTarget.prototype.createInstance = function() { } - if (GameLib.Utils.Defined(this.depthTexture)) { + if (R3.Utils.Defined(this.depthTexture)) { this.depthTexture.instance = this.instance.depthTexture; this.depthTexture.applyToInstance(); } this.applyToInstance(); - GameLib.Component.prototype.createInstance.call(this); + R3.Component.prototype.createInstance.call(this); }; /** * updates instance */ -GameLib.D3.RenderTarget.prototype.updateInstance = function(property) { +R3.D3.RenderTarget.prototype.updateInstance = function(property) { if ( property === 'width' || @@ -194,7 +194,7 @@ GameLib.D3.RenderTarget.prototype.updateInstance = function(property) { ) { if (this.autoUpdateSize) { - GameLib.Utils.UpdateWindowSize(this); + R3.Utils.UpdateWindowSize(this); } this.instance.setSize(this.width, this.height); @@ -260,30 +260,30 @@ GameLib.D3.RenderTarget.prototype.updateInstance = function(property) { return; } - GameLib.Component.prototype.updateInstance.call(this, property); + R3.Component.prototype.updateInstance.call(this, property); }; /** * Render Target to API Render Target - * @returns {GameLib.D3.API.RenderTarget} + * @returns {R3.D3.API.RenderTarget} */ -GameLib.D3.RenderTarget.prototype.toApiObject = function() { +R3.D3.RenderTarget.prototype.toApiObject = function() { - var apiRenderTarget = new GameLib.D3.API.RenderTarget( + var apiRenderTarget = new R3.D3.API.RenderTarget( this.id, this.name, this.renderTargetType, - GameLib.Utils.IdOrNull(this.parentEntity), + R3.Utils.IdOrNull(this.parentEntity), this.autoUpdateSize, this.width, this.height, this.scissor.toApiObject(), this.scissorTest, - GameLib.Utils.IdOrNull(this.viewport), - GameLib.Utils.IdOrNull(this.texture), + R3.Utils.IdOrNull(this.viewport), + R3.Utils.IdOrNull(this.texture), this.depthBuffer, - GameLib.Utils.IdOrNull(this.depthTexture), + R3.Utils.IdOrNull(this.depthTexture), this.stencilBuffer, this.textureParameters ); @@ -292,9 +292,9 @@ GameLib.D3.RenderTarget.prototype.toApiObject = function() { }; /** - * Updates GameLib.D3.RenderTarget from instance + * Updates R3.D3.RenderTarget from instance */ -GameLib.D3.RenderTarget.prototype.updateFromInstance = function() { +R3.D3.RenderTarget.prototype.updateFromInstance = function() { this.width = this.instance.width; this.height = this.instance.height; @@ -312,8 +312,8 @@ GameLib.D3.RenderTarget.prototype.updateFromInstance = function() { this.viewport.height = this.instance.viewport.w; if (this.texture.instance) { - if (GameLib.Utils.UndefinedOrNull(this.texture)) { - this.texture = new GameLib.D3.Texture(this.graphics); + if (R3.Utils.UndefinedOrNull(this.texture)) { + this.texture = new R3.D3.Texture(this.graphics); } this.texture.instance = this.instance.texture; this.texture.updateFromInstance(); @@ -323,8 +323,8 @@ GameLib.D3.RenderTarget.prototype.updateFromInstance = function() { if (this.instance.depthTexture) { - if (GameLib.Utils.UndefinedOrNull(this.depthTexture)) { - this.depthTexture = new GameLib.D3.Texture(this.graphics); + if (R3.Utils.UndefinedOrNull(this.depthTexture)) { + this.depthTexture = new R3.D3.Texture(this.graphics); } this.depthTexture.instance = this.instance.depthTexture; diff --git a/src/r3-d3-render-target-cube.js b/src/r3-d3-render-target-cube.js new file mode 100644 index 0000000..0254f79 --- /dev/null +++ b/src/r3-d3-render-target-cube.js @@ -0,0 +1,73 @@ +/** + * Renders a scene with a camera + * @param graphics R3.GraphicsRuntime + * @param apiRenderTargetCube R3.D3.API.RenderTarget.Cube + * @constructor + */ +R3.D3.RenderTarget.Cube = function ( + graphics, + apiRenderTargetCube +) { + + this.graphics = graphics; + this.graphics.isNotThreeThrow(); + + if (R3.Utils.UndefinedOrNull(apiRenderTargetCube)) { + apiRenderTargetCube = { + renderTargetType : R3.D3.API.RenderTarget.TARGET_TYPE_CUBE + }; + } + + R3.D3.API.RenderTarget.Cube.call( + this, + apiRenderTargetCube + ); + + R3.D3.RenderTarget.call( + this, + this.graphics, + this + ); +}; + +R3.D3.RenderTarget.Cube.prototype = Object.create(R3.D3.RenderTarget.prototype); +R3.D3.RenderTarget.Cube.prototype.constructor = R3.D3.RenderTarget.Cube; + +/** + * Creates a Render Target instance + * @returns {*} + */ +R3.D3.RenderTarget.Cube.prototype.createInstance = function() { + + this.instance = new THREE.WebGLRenderTargetCube( + this.width, + this.height, + this.textureParameters + ); + + R3.D3.RenderTarget.prototype.createInstance.call(this); +}; + +/** + * updates instance + */ +R3.D3.RenderTarget.Cube.prototype.updateInstance = function(property) { + R3.D3.RenderTarget.prototype.updateInstance.call(this, property); +}; + +/** + * Render Target to API Render Target + * @returns {R3.D3.API.RenderTarget.Cube} + */ +R3.D3.RenderTarget.Cube.prototype.toApiObject = function() { + + var apiRenderTarget = R3.D3.RenderTarget.prototype.toApiObject.call( + this + ); + + var apiRenderTargetCube = new R3.D3.API.RenderTarget.Cube( + apiRenderTarget + ); + + return apiRenderTargetCube; +}; diff --git a/src/game-lib-d3-rigid-body.js b/src/r3-d3-rigid-body.js similarity index 73% rename from src/game-lib-d3-rigid-body.js rename to src/r3-d3-rigid-body.js index 9700417..8127368 100644 --- a/src/game-lib-d3-rigid-body.js +++ b/src/r3-d3-rigid-body.js @@ -1,10 +1,10 @@ /** * RigidBody Runtime - * @param physics GameLib.GraphicsRuntime - * @param apiRigidBody GameLib.D3.API.RigidBody + * @param physics R3.GraphicsRuntime + * @param apiRigidBody R3.D3.API.RigidBody * @constructor */ -GameLib.D3.RigidBody = function ( +R3.D3.RigidBody = function ( physics, apiRigidBody ) { @@ -12,11 +12,11 @@ GameLib.D3.RigidBody = function ( this.physics = physics; this.physics.isNotCannonThrow(); - if (GameLib.Utils.UndefinedOrNull(apiRigidBody)) { + if (R3.Utils.UndefinedOrNull(apiRigidBody)) { apiRigidBody = {}; } - GameLib.D3.API.RigidBody.call( + R3.D3.API.RigidBody.call( this, apiRigidBody.id, apiRigidBody.name, @@ -41,56 +41,56 @@ GameLib.D3.RigidBody = function ( apiRigidBody.parentEntity ); - this.position = new GameLib.Vector3( + this.position = new R3.Vector3( this.physics, this.position, this ); - this.quaternion = new GameLib.Quaternion( + this.quaternion = new R3.Quaternion( this.physics, this.quaternion, this ); - this.velocity = new GameLib.Vector3( + this.velocity = new R3.Vector3( this.physics, this.velocity, this ); - this.angularVelocity = new GameLib.Vector3( + this.angularVelocity = new R3.Vector3( this.physics, this.angularVelocity, this ); - this.force = new GameLib.Vector3( + this.force = new R3.Vector3( this.physics ); - this.forcePoint = new GameLib.Vector3( + this.forcePoint = new R3.Vector3( this.physics ); - GameLib.Component.call( + R3.Component.call( this, { - 'shapes' : [GameLib.D3.Shape], - 'parentMesh' : GameLib.D3.Mesh, - 'parentPhysicsWorld' : GameLib.D3.PhysicsWorld + 'shapes' : [R3.D3.Shape], + 'parentMesh' : R3.D3.Mesh, + 'parentPhysicsWorld' : R3.D3.PhysicsWorld } ); }; -GameLib.D3.RigidBody.prototype = Object.create(GameLib.Component.prototype); -GameLib.D3.RigidBody.prototype.constructor = GameLib.D3.RigidBody; +R3.D3.RigidBody.prototype = Object.create(R3.Component.prototype); +R3.D3.RigidBody.prototype.constructor = R3.D3.RigidBody; /** * * @returns {*} */ -GameLib.D3.RigidBody.prototype.createInstance = function() { +R3.D3.RigidBody.prototype.createInstance = function() { this.instance = new CANNON.Body( { @@ -136,11 +136,11 @@ GameLib.D3.RigidBody.prototype.createInstance = function() { this.shapes.map( function(shape) { - if (GameLib.Utils.UndefinedOrNull(shape)) { + if (R3.Utils.UndefinedOrNull(shape)) { throw new Error('no shape'); } - if (GameLib.Utils.UndefinedOrNull(shape.instance)) { + if (R3.Utils.UndefinedOrNull(shape.instance)) { throw new Error('no shape instance'); } @@ -149,13 +149,13 @@ GameLib.D3.RigidBody.prototype.createInstance = function() { }.bind(this) ); - GameLib.Component.prototype.createInstance.call(this); + R3.Component.prototype.createInstance.call(this); }; /** * */ -GameLib.D3.RigidBody.prototype.updateInstance = function() { +R3.D3.RigidBody.prototype.updateInstance = function() { this.instance.mass = this.mass; this.instance.friction = this.friction; @@ -200,10 +200,10 @@ GameLib.D3.RigidBody.prototype.updateInstance = function() { this.instance.fixedRotation = this.fixedRotation; this.instance.kinematic = this.kinematic; - GameLib.Component.prototype.updateInstance.call(this, property); + R3.Component.prototype.updateInstance.call(this, property); }; -GameLib.D3.RigidBody.prototype.setFromParentMesh = function() { +R3.D3.RigidBody.prototype.setFromParentMesh = function() { if (!this.parentMesh || !this.parentMesh.instance) { console.log('no parent mesh or instance'); @@ -223,12 +223,12 @@ GameLib.D3.RigidBody.prototype.setFromParentMesh = function() { }; /** - * GameLib.D3.RigidBody to GameLib.D3.API.RigidBody - * @returns {GameLib.D3.API.RigidBody} + * R3.D3.RigidBody to R3.D3.API.RigidBody + * @returns {R3.D3.API.RigidBody} */ -GameLib.D3.RigidBody.prototype.toApiObject = function() { +R3.D3.RigidBody.prototype.toApiObject = function() { - var apiRigidBody = new GameLib.D3.API.RigidBody( + var apiRigidBody = new R3.D3.API.RigidBody( this.id, this.name, this.mass, @@ -245,34 +245,34 @@ GameLib.D3.RigidBody.prototype.toApiObject = function() { this.collisionFilterGroup, this.collisionFilterMask, this.fixedRotation, - this.shapes.map(function(shape){return GameLib.Utils.IdOrNull(shape)}), + this.shapes.map(function(shape){return R3.Utils.IdOrNull(shape)}), this.kinematic, - GameLib.Utils.IdOrNull(this.parentMesh), - GameLib.Utils.IdOrNull(this.parentPhysicsWorld), - GameLib.Utils.IdOrNull(this.parentEntity) + R3.Utils.IdOrNull(this.parentMesh), + R3.Utils.IdOrNull(this.parentPhysicsWorld), + R3.Utils.IdOrNull(this.parentEntity) ); return apiRigidBody; }; /** - * GameLib.D3.RigidBody from Object RigidBody + * R3.D3.RigidBody from Object RigidBody * @param physics * @param objectComponent - * @returns {GameLib.D3.RigidBody} + * @returns {R3.D3.RigidBody} * @constructor */ -GameLib.D3.RigidBody.FromObject = function(physics, objectComponent) { +R3.D3.RigidBody.FromObject = function(physics, objectComponent) { - var apiRigidBody = GameLib.D3.API.RigidBody.FromObject(objectComponent); + var apiRigidBody = R3.D3.API.RigidBody.FromObject(objectComponent); - return new GameLib.D3.RigidBody( + return new R3.D3.RigidBody( physics, apiRigidBody ); }; -GameLib.D3.RigidBody.prototype.applyForce = function() { +R3.D3.RigidBody.prototype.applyForce = function() { this.instance.applyForce( this.force.instance, this.forcePoint.instance @@ -280,7 +280,7 @@ GameLib.D3.RigidBody.prototype.applyForce = function() { }; -GameLib.D3.RigidBody.prototype.applyLocalForce = function() { +R3.D3.RigidBody.prototype.applyLocalForce = function() { this.instance.applyLocalForce( this.force.instance, this.forcePoint.instance diff --git a/src/game-lib-d3-scene.js b/src/r3-d3-scene.js similarity index 77% rename from src/game-lib-d3-scene.js rename to src/r3-d3-scene.js index 4039644..cb798eb 100644 --- a/src/game-lib-d3-scene.js +++ b/src/r3-d3-scene.js @@ -2,21 +2,21 @@ * Scene Superset - The apiScene properties get moved into the Scene object itself, and then the instance is * created * @param graphics - * @param apiScene GameLib.D3.API.Scene + * @param apiScene R3.D3.API.Scene * @constructor */ -GameLib.D3.Scene = function ( +R3.D3.Scene = function ( graphics, apiScene ) { this.graphics = graphics; this.graphics.isNotThreeThrow(); - if (GameLib.Utils.UndefinedOrNull(apiScene)) { + if (R3.Utils.UndefinedOrNull(apiScene)) { apiScene = {}; } - GameLib.D3.API.Scene.call( + R3.D3.API.Scene.call( this, apiScene.id, apiScene.name, @@ -41,7 +41,7 @@ GameLib.D3.Scene = function ( return apiTexture; } - return new GameLib.D3.Texture( + return new R3.D3.Texture( this.graphics, apiTexture ); @@ -56,7 +56,7 @@ GameLib.D3.Scene = function ( return apiMaterial; } - return new GameLib.D3.Material( + return new R3.D3.Material( this.graphics, apiMaterial ); @@ -71,7 +71,7 @@ GameLib.D3.Scene = function ( return apiImage; } - return new GameLib.Image( + return new R3.Image( this.graphics, apiImage ); @@ -79,14 +79,14 @@ GameLib.D3.Scene = function ( }.bind(this) ); - if (this.fog instanceof GameLib.D3.API.Fog) { - this.fog = new GameLib.D3.Fog( + if (this.fog instanceof R3.D3.API.Fog) { + this.fog = new R3.D3.Fog( this.graphics, this.fog ) }; - this.gridColor = new GameLib.Color( + this.gridColor = new R3.Color( this.graphics, this.gridColor, this @@ -106,28 +106,28 @@ GameLib.D3.Scene = function ( this.storeClones = false; - GameLib.Component.call( + R3.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, - 'camera' : GameLib.D3.Camera + 'meshes' : [R3.D3.Mesh], + 'lights' : [R3.D3.Light], + 'textures' : [R3.D3.Texture], + 'materials' : [R3.D3.Material], + 'images' : [R3.Image], + 'fog' : R3.D3.Fog, + 'camera' : R3.D3.Camera } ); }; -GameLib.D3.Scene.prototype = Object.create(GameLib.Component.prototype); -GameLib.D3.Scene.prototype.constructor = GameLib.D3.Scene; +R3.D3.Scene.prototype = Object.create(R3.Component.prototype); +R3.D3.Scene.prototype.constructor = R3.D3.Scene; /** * Creates an instance scene * @returns {THREE.Scene} */ -GameLib.D3.Scene.prototype.createInstance = function() { +R3.D3.Scene.prototype.createInstance = function() { this.instance = new THREE.Scene(); @@ -140,11 +140,11 @@ GameLib.D3.Scene.prototype.createInstance = function() { this.meshes.map( function(mesh) { - if (GameLib.Utils.UndefinedOrNull(mesh)) { + if (R3.Utils.UndefinedOrNull(mesh)) { throw new Error('no mesh'); } - if (GameLib.Utils.UndefinedOrNull(mesh.instance)) { + if (R3.Utils.UndefinedOrNull(mesh.instance)) { throw new Error('no mesh instance'); } @@ -159,11 +159,11 @@ GameLib.D3.Scene.prototype.createInstance = function() { function(light) { - if (GameLib.Utils.UndefinedOrNull(light)) { + if (R3.Utils.UndefinedOrNull(light)) { throw new Error('no light'); } - if (GameLib.Utils.UndefinedOrNull(light.instance)) { + if (R3.Utils.UndefinedOrNull(light.instance)) { throw new Error('no light instance'); } @@ -182,11 +182,11 @@ GameLib.D3.Scene.prototype.createInstance = function() { this.drawAxis(); } - GameLib.Component.prototype.createInstance.call(this); + R3.Component.prototype.createInstance.call(this); }; -GameLib.D3.Scene.prototype.updateInstance = function(property) { +R3.D3.Scene.prototype.updateInstance = function(property) { if (property === 'name') { this.instance.name = this.name; @@ -287,23 +287,23 @@ GameLib.D3.Scene.prototype.updateInstance = function(property) { } } - GameLib.Component.prototype.updateInstance.call(this, property); + R3.Component.prototype.updateInstance.call(this, property); }; /** - * Converts a GameLib.D3.Scene to a GameLib.D3.API.Scene - * @returns {GameLib.D3.API.Scene} + * Converts a R3.D3.Scene to a R3.D3.API.Scene + * @returns {R3.D3.API.Scene} */ -GameLib.D3.Scene.prototype.toApiObject = function() { +R3.D3.Scene.prototype.toApiObject = function() { var apiMeshes = []; if (this.storeClones) { this.clones.map( function (clone) { - GameLib.Utils.PushUnique( + R3.Utils.PushUnique( apiMeshes, - GameLib.Utils.IdOrNull(clone) + R3.Utils.IdOrNull(clone) ); } ); @@ -311,62 +311,62 @@ GameLib.D3.Scene.prototype.toApiObject = function() { this.meshes.map( function(mesh) { - GameLib.Utils.PushUnique( + R3.Utils.PushUnique( apiMeshes, - GameLib.Utils.IdOrNull(mesh) + R3.Utils.IdOrNull(mesh) ); } ); - return new GameLib.D3.API.Scene( + return new R3.D3.API.Scene( this.id, this.name, apiMeshes, this.lights.map( function(light) { - return GameLib.Utils.IdOrNull(light); + return R3.Utils.IdOrNull(light); } ), this.textures.map( function(texture) { - return GameLib.Utils.IdOrNull(texture); + return R3.Utils.IdOrNull(texture); } ), this.materials.map( function(material) { - return GameLib.Utils.IdOrNull(material); + return R3.Utils.IdOrNull(material); } ), this.images.map( function(image) { - return GameLib.Utils.IdOrNull(image); + return R3.Utils.IdOrNull(image); } ), - GameLib.Utils.IdOrNull(this.fog), + R3.Utils.IdOrNull(this.fog), this.showGrid, this.showAxis, this.gridSize, this.gridColor.toApiObject(), - GameLib.Utils.IdOrNull(this.camera), - GameLib.Utils.IdOrNull(this.parentEntity) + R3.Utils.IdOrNull(this.camera), + R3.Utils.IdOrNull(this.parentEntity) ); }; /** * Adds a mesh to the scene - * @param object GameLib.D3.Mesh + * @param object R3.D3.Mesh */ -GameLib.D3.Scene.prototype.addObject = function(object) { +R3.D3.Scene.prototype.addObject = function(object) { - if (object instanceof GameLib.D3.Mesh) { + if (object instanceof R3.D3.Mesh) { if (this.meshes.indexOf(object.id) === -1) { - GameLib.Utils.PushUnique(this.meshes, object); + R3.Utils.PushUnique(this.meshes, object); } } - if (object instanceof GameLib.D3.Light) { + if (object instanceof R3.D3.Light) { if (this.lights.indexOf(object.id) === -1) { - GameLib.Utils.PushUnique(this.lights, object); + R3.Utils.PushUnique(this.lights, object); } } @@ -389,10 +389,10 @@ GameLib.D3.Scene.prototype.addObject = function(object) { }; -GameLib.D3.Scene.prototype.addClone = function(component) { +R3.D3.Scene.prototype.addClone = function(component) { - if (component instanceof GameLib.D3.Mesh || - component instanceof GameLib.D3.Light + if (component instanceof R3.D3.Mesh || + component instanceof R3.D3.Light ) { if (this.instance && component.instance) { if (this.instance.children.indexOf(component.instance) === -1) { @@ -402,7 +402,7 @@ GameLib.D3.Scene.prototype.addClone = function(component) { component.isClone = true; - GameLib.Utils.PushUnique(this.clones, component); + R3.Utils.PushUnique(this.clones, component); var index = this.meshes.indexOf(component); @@ -418,11 +418,11 @@ GameLib.D3.Scene.prototype.addClone = function(component) { * * @param object */ -GameLib.D3.Scene.prototype.removeObject = function(object) { +R3.D3.Scene.prototype.removeObject = function(object) { var index = -1; - if (object instanceof GameLib.D3.Mesh) { + if (object instanceof R3.D3.Mesh) { index = this.meshes.indexOf(object); if (index !== -1) { @@ -434,7 +434,7 @@ GameLib.D3.Scene.prototype.removeObject = function(object) { this.clones.splice(index, 1); } - } else if (object instanceof GameLib.D3.Light) { + } else if (object instanceof R3.D3.Light) { index = this.lights.indexOf(object); if (index !== -1) { @@ -467,7 +467,7 @@ GameLib.D3.Scene.prototype.removeObject = function(object) { // this.buildIdToObject(); }; -GameLib.D3.Scene.prototype.drawGrid = function() { +R3.D3.Scene.prototype.drawGrid = function() { this.removeGrid(); @@ -504,7 +504,7 @@ GameLib.D3.Scene.prototype.drawGrid = function() { } }; -GameLib.D3.Scene.prototype.removeGrid = function() { +R3.D3.Scene.prototype.removeGrid = function() { this.grid.map( function(object) { this.instance.remove(object); @@ -512,7 +512,7 @@ GameLib.D3.Scene.prototype.removeGrid = function() { ); }; -GameLib.D3.Scene.prototype.drawAxis = function() { +R3.D3.Scene.prototype.drawAxis = function() { this.removeAxis(); @@ -568,7 +568,7 @@ GameLib.D3.Scene.prototype.drawAxis = function() { this.axis.push(lineZ); }; -GameLib.D3.Scene.prototype.removeAxis = function() { +R3.D3.Scene.prototype.removeAxis = function() { this.axis.map( function(object) { this.instance.remove(object); diff --git a/src/game-lib-d3-shader-a.js b/src/r3-d3-shader-a.js similarity index 54% rename from src/game-lib-d3-shader-a.js rename to src/r3-d3-shader-a.js index fb23227..3f594e5 100644 --- a/src/game-lib-d3-shader-a.js +++ b/src/r3-d3-shader-a.js @@ -1,10 +1,10 @@ /** - * GameLib.D3.Shader - * @param graphics GameLib.GraphicsRuntime - * @param apiShader GameLib.D3.API.Shader + * R3.D3.Shader + * @param graphics R3.GraphicsRuntime + * @param apiShader R3.D3.API.Shader * @constructor */ -GameLib.D3.Shader = function( +R3.D3.Shader = function( graphics, apiShader ) { @@ -12,11 +12,11 @@ GameLib.D3.Shader = function( this.graphics = graphics; this.graphics.isNotThreeThrow(); - if (GameLib.Utils.UndefinedOrNull(apiShader)) { + if (R3.Utils.UndefinedOrNull(apiShader)) { apiShader = {}; } - GameLib.D3.API.Shader.call( + R3.D3.API.Shader.call( this, apiShader.id, apiShader.name, @@ -26,22 +26,22 @@ GameLib.D3.Shader = function( apiShader.code ); - GameLib.Component.call( + R3.Component.call( this, { - parentMaterialShader : GameLib.D3.Material.Shader + parentMaterialShader : R3.D3.Material.Shader } ); }; -GameLib.D3.Shader.prototype = Object.create(GameLib.CustomCode.prototype); -GameLib.D3.Shader.prototype.constructor = GameLib.D3.Shader; +R3.D3.Shader.prototype = Object.create(R3.CustomCode.prototype); +R3.D3.Shader.prototype.constructor = R3.D3.Shader; /** * Creates a light instance * @returns {*} */ -GameLib.D3.Shader.prototype.createInstance = function() { +R3.D3.Shader.prototype.createInstance = function() { this.instance = this.code; @@ -50,15 +50,15 @@ GameLib.D3.Shader.prototype.createInstance = function() { * GLSL code */ - GameLib.Component.prototype.createInstance.call(this); + R3.Component.prototype.createInstance.call(this); }; /** * Updates the instance with the current state */ -GameLib.D3.Shader.prototype.updateInstance = function(property) { +R3.D3.Shader.prototype.updateInstance = function(property) { - if (GameLib.Utils.UndefinedOrNull(property)) { + if (R3.Utils.UndefinedOrNull(property)) { console.warn('no property for Shader: ' + this.name); } @@ -78,20 +78,20 @@ GameLib.D3.Shader.prototype.updateInstance = function(property) { return; } - GameLib.Component.prototype.updateInstance.call(this, property); + R3.Component.prototype.updateInstance.call(this, property); }; /** - * Converts a GameLib.D3.Shader to a GameLib.D3.API.Shader - * @returns {GameLib.D3.API.Shader} + * Converts a R3.D3.Shader to a R3.D3.API.Shader + * @returns {R3.D3.API.Shader} */ -GameLib.D3.Shader.prototype.toApiObject = function() { - return new GameLib.D3.API.Shader( +R3.D3.Shader.prototype.toApiObject = function() { + return new R3.D3.API.Shader( this.id, this.name, this.shaderType, - GameLib.Utils.IdOrNull(this.parentEntity), - GameLib.Utils.IdOrNull(this.parentMaterialShader), + R3.Utils.IdOrNull(this.parentEntity), + R3.Utils.IdOrNull(this.parentMaterialShader), this.code ); }; diff --git a/src/r3-d3-shader-fragment.js b/src/r3-d3-shader-fragment.js new file mode 100644 index 0000000..97caae3 --- /dev/null +++ b/src/r3-d3-shader-fragment.js @@ -0,0 +1,59 @@ +/** + * R3.D3.Shader.Fragment + * @param graphics R3.GraphicsRuntime + * @param apiFragmentShader + * @constructor + */ +R3.D3.Shader.Fragment = function( + graphics, + apiFragmentShader +) { + + this.graphics = graphics; + this.graphics.isNotThreeThrow(); + + if (R3.Utils.UndefinedOrNull(apiFragmentShader)) { + apiFragmentShader = { + shaderType : R3.D3.API.Shader.SHADER_TYPE_FRAGMENT + }; + } + + R3.D3.API.Shader.Fragment.call( + this, + apiFragmentShader + ); + + R3.D3.Shader.call( + this, + this.graphics, + apiFragmentShader + ); + +}; + +R3.D3.Shader.Fragment.prototype = Object.create(R3.D3.Shader.prototype); +R3.D3.Shader.Fragment.prototype.constructor = R3.D3.Shader.Fragment; + +/** + * Creates a shader instance + * @returns {*} + */ +R3.D3.Shader.Fragment.prototype.createInstance = function() { + R3.D3.Shader.prototype.createInstance.call(this); +}; + +/** + * Updates the instance with the current state + */ +R3.D3.Shader.Fragment.prototype.updateInstance = function(property) { + R3.D3.Shader.prototype.updateInstance.call(this, property); +}; + +/** + * Converts a R3.D3.Shader to a R3.D3.API.Shader + * @returns {R3.D3.API.Shader} + */ +R3.D3.Shader.Fragment.prototype.toApiObject = function() { + var apiShader = R3.D3.Shader.prototype.toApiObject.call(this); + return apiShader; +}; diff --git a/src/r3-d3-shader-vertex.js b/src/r3-d3-shader-vertex.js new file mode 100644 index 0000000..dc97deb --- /dev/null +++ b/src/r3-d3-shader-vertex.js @@ -0,0 +1,59 @@ +/** + * R3.D3.Shader.Vertex + * @param graphics R3.GraphicsRuntime + * @param apiVertexShader + * @constructor + */ +R3.D3.Shader.Vertex = function( + graphics, + apiVertexShader +) { + + this.graphics = graphics; + this.graphics.isNotThreeThrow(); + + if (R3.Utils.UndefinedOrNull(apiVertexShader)) { + apiVertexShader = { + shaderType : R3.D3.API.Shader.SHADER_TYPE_VERTEX + }; + } + + R3.D3.API.Shader.Vertex.call( + this, + apiVertexShader + ); + + R3.D3.Shader.call( + this, + this.graphics, + apiVertexShader + ); + +}; + +R3.D3.Shader.Vertex.prototype = Object.create(R3.D3.Shader.prototype); +R3.D3.Shader.Vertex.prototype.constructor = R3.D3.Shader.Vertex; + +/** + * Creates a shader instance + * @returns {*} + */ +R3.D3.Shader.Vertex.prototype.createInstance = function() { + R3.D3.Shader.prototype.createInstance.call(this); +}; + +/** + * Updates the instance with the current state + */ +R3.D3.Shader.Vertex.prototype.updateInstance = function(property) { + R3.D3.Shader.prototype.updateInstance.call(this, property); +}; + +/** + * Converts a R3.D3.Shader to a R3.D3.API.Shader + * @returns {R3.D3.API.Shader} + */ +R3.D3.Shader.Vertex.prototype.toApiObject = function() { + var apiShader = R3.D3.Shader.prototype.toApiObject.call(this); + return apiShader; +}; diff --git a/src/game-lib-d3-shadow-a.js b/src/r3-d3-shadow-a.js similarity index 62% rename from src/game-lib-d3-shadow-a.js rename to src/r3-d3-shadow-a.js index 9bcae62..44522a9 100644 --- a/src/game-lib-d3-shadow-a.js +++ b/src/r3-d3-shadow-a.js @@ -1,10 +1,10 @@ /** - * GameLib.D3.Shadow - * @param graphics GameLib.GraphicsRuntime - * @param apiShadow GameLib.D3.API.Shadow + * R3.D3.Shadow + * @param graphics R3.GraphicsRuntime + * @param apiShadow R3.D3.API.Shadow * @constructor */ -GameLib.D3.Shadow = function( +R3.D3.Shadow = function( graphics, apiShadow ) { @@ -12,13 +12,13 @@ GameLib.D3.Shadow = function( this.graphics = graphics; this.graphics.isNotThreeThrow(); - if (GameLib.Utils.UndefinedOrNull(apiShadow)) { + if (R3.Utils.UndefinedOrNull(apiShadow)) { apiShadow = { - shadowType : GameLib.D3.API.Shadow.SHADOW_TYPE_NORMAL + shadowType : R3.D3.API.Shadow.SHADOW_TYPE_NORMAL }; } - GameLib.D3.API.Shadow.call( + R3.D3.API.Shadow.call( this, apiShadow.id, apiShadow.name, @@ -30,35 +30,35 @@ GameLib.D3.Shadow = function( apiShadow.parentEntity ); - if (this.camera instanceof GameLib.D3.API.Camera.Perspective) { - this.camera = new GameLib.D3.Camera.Perspective( + if (this.camera instanceof R3.D3.API.Camera.Perspective) { + this.camera = new R3.D3.Camera.Perspective( this.graphics, this.camera ) } - this.mapSize = new GameLib.Vector2( + this.mapSize = new R3.Vector2( this.graphics, this.mapSize, this ); - GameLib.Component.call( + R3.Component.call( this, { - camera : GameLib.D3.Camera + camera : R3.D3.Camera } ); }; -GameLib.D3.Shadow.prototype = Object.create(GameLib.Component.prototype); -GameLib.D3.Shadow.prototype.constructor = GameLib.D3.Shadow; +R3.D3.Shadow.prototype = Object.create(R3.Component.prototype); +R3.D3.Shadow.prototype.constructor = R3.D3.Shadow; /** * Creates a light instance * @returns {*} */ -GameLib.D3.Shadow.prototype.createInstance = function() { +R3.D3.Shadow.prototype.createInstance = function() { /** * Shadow objects are not responsible for creating their instances right now - @@ -68,20 +68,20 @@ GameLib.D3.Shadow.prototype.createInstance = function() { */ this.instance = {}; - GameLib.Component.prototype.createInstance.call(this); + R3.Component.prototype.createInstance.call(this); }; /** * Updates the instance with the current state */ -GameLib.D3.Shadow.prototype.updateInstance = function(property) { +R3.D3.Shadow.prototype.updateInstance = function(property) { if (typeof this.instance !== 'object') { console.warn('this shadow instance is not ready for an update: ' + this.name); return; } - if (GameLib.Utils.UndefinedOrNull(property)) { + if (R3.Utils.UndefinedOrNull(property)) { console.warn('no property for light: ' + this.name); } @@ -106,27 +106,27 @@ GameLib.D3.Shadow.prototype.updateInstance = function(property) { this.instance.radius = this.radius; } - GameLib.Component.prototype.updateInstance.call(this, property); + R3.Component.prototype.updateInstance.call(this, property); }; /** - * Converts a GameLib.D3.Shadow to a GameLib.D3.API.Shadow - * @returns {GameLib.D3.API.Shadow} + * Converts a R3.D3.Shadow to a R3.D3.API.Shadow + * @returns {R3.D3.API.Shadow} */ -GameLib.D3.Shadow.prototype.toApiObject = function() { - return new GameLib.D3.API.Shadow( +R3.D3.Shadow.prototype.toApiObject = function() { + return new R3.D3.API.Shadow( this.id, this.name, this.shadowType, - GameLib.Utils.IdOrNull(this.camera), + R3.Utils.IdOrNull(this.camera), this.bias, this.mapSize.toApiObject(), this.radius, - GameLib.Utils.IdOrNull(this.parentEntity) + R3.Utils.IdOrNull(this.parentEntity) ); }; -GameLib.D3.Shadow.prototype.updateFromInstance = function() { +R3.D3.Shadow.prototype.updateFromInstance = function() { this.bias = this.instance.bias; this.mapSize.x = this.instance.mapSize.x; this.mapSize.y = this.instance.mapSize.y; diff --git a/src/r3-d3-shadow-directional.js b/src/r3-d3-shadow-directional.js new file mode 100644 index 0000000..5820e28 --- /dev/null +++ b/src/r3-d3-shadow-directional.js @@ -0,0 +1,90 @@ +/** + * R3.D3.Shadow.Directional + * @param graphics R3.GraphicsRuntime + * @param apiDirectionalShadow + * @constructor + */ +R3.D3.Shadow.Directional = function( + graphics, + apiDirectionalShadow +) { + + this.graphics = graphics; + this.graphics.isNotThreeThrow(); + + if (R3.Utils.UndefinedOrNull(apiDirectionalShadow)) { + apiDirectionalShadow = { + shadowType : R3.D3.API.Shadow.SHADOW_TYPE_DIRECTIONAL + }; + } + + R3.D3.API.Shadow.Directional.call( + this, + apiDirectionalShadow + ); + + if (this.camera instanceof R3.D3.API.Camera.Orthographic) { + this.camera = new R3.D3.Camera.Orthographic( + this.graphics, + this.camera + ) + } + + R3.D3.Shadow.call( + this, + this.graphics, + this + ); + +}; + +R3.D3.Shadow.Directional.prototype = Object.create(R3.D3.Shadow.prototype); +R3.D3.Shadow.Directional.prototype.constructor = R3.D3.Shadow.Directional; + +/** + * Creates a shadow instance + * @returns {*} + */ +R3.D3.Shadow.Directional.prototype.createInstance = function() { + + this.instance = {}; + + R3.D3.Shadow.prototype.createInstance.call(this); +}; + +/** + * Updates the instance with the current state + */ +R3.D3.Shadow.Directional.prototype.updateInstance = function(property) { + + if (property === 'camera') { + + //console.warn('todo: updateInstance for directional shadow camera instance'); + + return; + } + + R3.D3.Shadow.prototype.updateInstance.call(this, property); +}; + +/** + * Converts a R3.D3.Shadow to a R3.D3.API.Shadow + * @returns {R3.D3.API.Shadow} + */ +R3.D3.Shadow.Directional.prototype.toApiObject = function() { + + var apiShadow = R3.D3.Shadow.prototype.toApiObject.call(this); + + var apiDirectionalShadow = new R3.D3.API.Shadow.Directional( + apiShadow + ); + + return apiDirectionalShadow; +}; + +R3.D3.Shadow.Directional.prototype.updateFromInstance = function() { + + + R3.D3.Shadow.prototype.updateFromInstance.call(this); + +}; \ No newline at end of file diff --git a/src/r3-d3-shadow-spot.js b/src/r3-d3-shadow-spot.js new file mode 100644 index 0000000..eabfe11 --- /dev/null +++ b/src/r3-d3-shadow-spot.js @@ -0,0 +1,83 @@ +/** + * R3.D3.Shadow.Spot + * @param graphics R3.GraphicsRuntime + * @param apiSpotShadow + * @constructor + */ +R3.D3.Shadow.Spot = function( + graphics, + apiSpotShadow +) { + + this.graphics = graphics; + this.graphics.isNotThreeThrow(); + + if (R3.Utils.UndefinedOrNull(apiSpotShadow)) { + apiSpotShadow = { + shadowType : R3.D3.API.Shadow.SHADOW_TYPE_SPOT + }; + } + + R3.D3.API.Shadow.Spot.call( + this, + apiSpotShadow + ); + + if (this.camera instanceof R3.D3.API.Camera.Perspective) { + this.camera = new R3.D3.Camera.Perspective( + this.graphics, + this.camera + ) + } + + R3.D3.Shadow.call( + this, + this.graphics, + apiSpotShadow + ); + +}; + +R3.D3.Shadow.Spot.prototype = Object.create(R3.D3.Shadow.prototype); +R3.D3.Shadow.Spot.prototype.constructor = R3.D3.Shadow.Spot; + +/** + * Creates a shadow instance + * @returns {*} + */ +R3.D3.Shadow.Spot.prototype.createInstance = function() { + + this.instance = {}; + + R3.D3.Shadow.prototype.createInstance.call(this); +}; + +/** + * Updates the instance with the current state + */ +R3.D3.Shadow.Spot.prototype.updateInstance = function(property) { + + if (property === 'camera') { + + console.warn('todo: updateInstance for spot shadow camera instance'); + + return; + } + + R3.D3.Shadow.prototype.updateInstance.call(this, property); +}; + +/** + * Converts a R3.D3.Shadow to a R3.D3.API.Shadow + * @returns {R3.D3.API.Shadow} + */ +R3.D3.Shadow.Spot.prototype.toApiObject = function() { + + var apiShadow = R3.D3.Shadow.prototype.toApiObject.call(this); + + var apiSpotShadow = new R3.D3.API.Shadow.Spot( + apiShadow + ); + + return apiSpotShadow; +}; diff --git a/src/r3-d3-shape-0.js b/src/r3-d3-shape-0.js new file mode 100644 index 0000000..061f96c --- /dev/null +++ b/src/r3-d3-shape-0.js @@ -0,0 +1,108 @@ +/** + * Shape Superset - The apiShape properties get moved into the Shape object itself, and then the instance is created + * @param physics R3.PhysicsRuntime + * @param apiShape R3.D3.API.Shape + * @constructor + */ +R3.D3.Shape = function ( + physics, + apiShape +) { + this.physics = physics; + this.physics.isNotCannonThrow(); + + if (R3.Utils.UndefinedOrNull(apiShape)) { + apiShape = { + shapeType : R3.D3.API.Shape.SHAPE_TYPE_NONE + }; + } + + R3.D3.API.Shape.call( + this, + apiShape.id, + apiShape.name, + apiShape.shapeType, + apiShape.boundingSphereRadius, + apiShape.collisionResponse, + apiShape.frictionMaterial, + apiShape.parentMesh, + apiShape.parentEntity + ); + + var linkedObjects = { + frictionMaterial : R3.D3.FrictionMaterial, + parentMesh : R3.D3.Mesh + }; + + R3.Component.call( + this, + linkedObjects + ); +}; + +R3.D3.Shape.prototype = Object.create(R3.Component.prototype); +R3.D3.Shape.prototype.constructor = R3.D3.Shape; + + +/** + * Creates a shape instance or updates it + */ +R3.D3.Shape.prototype.createInstance = function() { + R3.Component.prototype.createInstance.call(this); +}; + +/** + * Updates the mesh instance + */ +R3.D3.Shape.prototype.updateInstance = function(property) { + throw new Error('Do not instantiate this class directly - use a child class instead'); + R3.Component.prototype.updateInstance.call(this, property); +}; + +/** + * Converts a R3.D3.Shape to a R3.D3.API.Shape + * @returns {R3.D3.API.Shape} + */ +R3.D3.Shape.prototype.toApiObject = function() { + + var apiShape = new R3.D3.API.Shape( + this.id, + this.name, + this.shapeType, + this.boundingSphereRadius, + this.collisionResponse, + R3.Utils.IdOrNull(this.frictionMaterial), + R3.Utils.IdOrNull(this.parentMesh), + R3.Utils.IdOrNull(this.parentEntity) + ); + + return apiShape; +}; + +/** + * Converts a standard object mesh to a R3.D3.Shape + * @param physics R3.PhysicsRuntime + * @param objectShape {Object} + * @constructor + */ +R3.D3.Shape.FromObject = function(physics, objectShape) { + throw ('not implemented'); +}; + +R3.D3.Shape.prototype.stopVisualize = function() { + R3.Event.Emit( + R3.Event.STOP_VISUALIZE, + { + mesh : this.mesh + } + ) +}; + +R3.D3.Shape.prototype.visualize = function() { + R3.Event.Emit( + R3.Event.VISUALIZE, + { + shape : this + } + ) +}; \ No newline at end of file diff --git a/src/game-lib-d3-shape-box.js b/src/r3-d3-shape-box.js similarity index 52% rename from src/game-lib-d3-shape-box.js rename to src/r3-d3-shape-box.js index 8af239f..64c6ab9 100644 --- a/src/game-lib-d3-shape-box.js +++ b/src/r3-d3-shape-box.js @@ -1,11 +1,11 @@ /** * Shape Superset - The apiShape properties get moved into the Shape object itself, and then the instance is created * @param physics - * @param apiShape GameLib.D3.API.Shape + * @param apiShape R3.D3.API.Shape * @param halfExtents * @constructor */ -GameLib.D3.Shape.Box = function ( +R3.D3.Shape.Box = function ( physics, apiShape, halfExtents @@ -13,21 +13,21 @@ GameLib.D3.Shape.Box = function ( this.physics = physics; this.physics.isNotCannonThrow(); - if (GameLib.Utils.UndefinedOrNull(apiShape)) { + if (R3.Utils.UndefinedOrNull(apiShape)) { apiShape = { - shapeType : GameLib.D3.API.Shape.SHAPE_TYPE_BOX + shapeType : R3.D3.API.Shape.SHAPE_TYPE_BOX }; } - if (GameLib.Utils.UndefinedOrNull(halfExtents)) { - halfExtents = new GameLib.Vector3( + if (R3.Utils.UndefinedOrNull(halfExtents)) { + halfExtents = new R3.Vector3( physics, - new GameLib.API.Vector3( + new R3.API.Vector3( 1,1,1 ) ); - } else if (halfExtents instanceof GameLib.API.Vector3) { - halfExtents = new GameLib.Vector3( + } else if (halfExtents instanceof R3.API.Vector3) { + halfExtents = new R3.Vector3( this.physics, halfExtents, this @@ -35,27 +35,27 @@ GameLib.D3.Shape.Box = function ( } this.halfExtents = halfExtents; - GameLib.D3.Shape.call( + R3.D3.Shape.call( this, this.physics, apiShape ); }; -GameLib.D3.Shape.Box.prototype = Object.create(GameLib.D3.Shape.prototype); -GameLib.D3.Shape.Box.prototype.constructor = GameLib.D3.Shape.Box; +R3.D3.Shape.Box.prototype = Object.create(R3.D3.Shape.prototype); +R3.D3.Shape.Box.prototype.constructor = R3.D3.Shape.Box; /** * - * @returns {GameLib.D3.Shape.Box|*|SEA3D.Box} + * @returns {R3.D3.Shape.Box|*|SEA3D.Box} */ -GameLib.D3.Shape.Box.prototype.createInstance = function() { +R3.D3.Shape.Box.prototype.createInstance = function() { - if (GameLib.Utils.UndefinedOrNull(this.halfExtents)) { + if (R3.Utils.UndefinedOrNull(this.halfExtents)) { throw new Error('no halfExtents'); } - if (GameLib.Utils.UndefinedOrNull(this.halfExtents.instance)) { + if (R3.Utils.UndefinedOrNull(this.halfExtents.instance)) { throw new Error('no halfExtents instance'); } @@ -63,11 +63,11 @@ GameLib.D3.Shape.Box.prototype.createInstance = function() { this.halfExtents.instance ); - GameLib.D3.Shape.prototype.createInstance.call(this); + R3.D3.Shape.prototype.createInstance.call(this); }; -GameLib.D3.Shape.Box.prototype.updateInstance = function() { +R3.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; @@ -75,16 +75,16 @@ GameLib.D3.Shape.Box.prototype.updateInstance = function() { this.instance.updateConvexPolyhedronRepresentation(); }; -GameLib.D3.Shape.Box.prototype.toApiObject = function() { +R3.D3.Shape.Box.prototype.toApiObject = function() { - var apiShape = GameLib.D3.Shape.prototype.toApiObject.call(this); + var apiShape = R3.D3.Shape.prototype.toApiObject.call(this); apiShape.halfExtents = this.halfExtents.toApiObject(); return apiShape; }; -GameLib.D3.Shape.Box.prototype.setFromMesh = function() { +R3.D3.Shape.Box.prototype.setFromMesh = function() { if (this.parentMesh === null) { console.log('select a mesh first'); @@ -100,13 +100,13 @@ GameLib.D3.Shape.Box.prototype.setFromMesh = function() { this.halfExtents.updateInstance(); }; -GameLib.D3.Shape.Box.FromObject = function(physics, objectShape) { +R3.D3.Shape.Box.FromObject = function(physics, objectShape) { - var apiShape = GameLib.D3.API.Shape.FromObject(objectShape); + var apiShape = R3.D3.API.Shape.FromObject(objectShape); - apiShape.halfExtents = GameLib.API.Vector3.FromObject(objectShape.halfExtents); + apiShape.halfExtents = R3.API.Vector3.FromObject(objectShape.halfExtents); - return new GameLib.D3.Shape.Box( + return new R3.D3.Shape.Box( physics, apiShape, apiShape.halfExtents diff --git a/src/game-lib-d3-shape-convex-hull-0.js b/src/r3-d3-shape-convex-hull-0.js similarity index 61% rename from src/game-lib-d3-shape-convex-hull-0.js rename to src/r3-d3-shape-convex-hull-0.js index 4e30366..5e246ec 100644 --- a/src/game-lib-d3-shape-convex-hull-0.js +++ b/src/r3-d3-shape-convex-hull-0.js @@ -1,14 +1,14 @@ /** * Shape Superset - The apiShape properties get moved into the Shape object itself, and then the instance is created * @param physics - * @param apiShape GameLib.D3.API.Shape + * @param apiShape R3.D3.API.Shape * @param faces * @param uniqueAxes * @param uniqueEdges * @param vertices * @constructor */ -GameLib.D3.Shape.ConvexHull = function ( +R3.D3.Shape.ConvexHull = function ( physics, apiShape, vertices, @@ -19,35 +19,35 @@ GameLib.D3.Shape.ConvexHull = function ( this.physics = physics; this.physics.isNotCannonThrow(); - if (GameLib.Utils.UndefinedOrNull(apiShape)) { + if (R3.Utils.UndefinedOrNull(apiShape)) { apiShape = { - shapeType : GameLib.D3.API.Shape.SHAPE_TYPE_CONVEX_HULL + shapeType : R3.D3.API.Shape.SHAPE_TYPE_CONVEX_HULL }; } - if (GameLib.Utils.UndefinedOrNull(vertices)) { + if (R3.Utils.UndefinedOrNull(vertices)) { vertices = []; } this.vertices = vertices; - if (GameLib.Utils.UndefinedOrNull(faces)) { + if (R3.Utils.UndefinedOrNull(faces)) { faces = []; } this.faces = faces; - if (GameLib.Utils.UndefinedOrNull(uniqueAxes)) { + if (R3.Utils.UndefinedOrNull(uniqueAxes)) { uniqueAxes = []; } this.uniqueAxes = uniqueAxes; - if (GameLib.Utils.UndefinedOrNull(uniqueEdges)) { + if (R3.Utils.UndefinedOrNull(uniqueEdges)) { uniqueEdges = []; } this.uniqueEdges = uniqueEdges; this.vertices = this.vertices.map(function(vertex){ - if (vertex instanceof GameLib.D3.API.Vertex){ - return new GameLib.D3.Vertex( + if (vertex instanceof R3.D3.API.Vertex){ + return new R3.D3.Vertex( this.physics, vertex ) @@ -56,8 +56,8 @@ GameLib.D3.Shape.ConvexHull = function ( }.bind(this)); this.faces = this.faces.map(function(face){ - if (face instanceof GameLib.D3.API.Face){ - return new GameLib.D3.Face( + if (face instanceof R3.D3.API.Face){ + return new R3.D3.Face( this.physics, face ) @@ -66,8 +66,8 @@ GameLib.D3.Shape.ConvexHull = function ( }.bind(this)); this.uniqueAxes = this.uniqueAxes.map(function(axis){ - if (axis instanceof GameLib.API.Vector3) { - return new GameLib.Vector3( + if (axis instanceof R3.API.Vector3) { + return new R3.Vector3( this.physics, axis, this @@ -77,8 +77,8 @@ GameLib.D3.Shape.ConvexHull = function ( }.bind(this)); this.uniqueEdges = this.uniqueEdges.map(function(edge){ - if (edge instanceof GameLib.API.Vector3) { - return new GameLib.Vector3( + if (edge instanceof R3.API.Vector3) { + return new R3.Vector3( this.physics, edge, this @@ -87,21 +87,21 @@ GameLib.D3.Shape.ConvexHull = function ( return edge; }.bind(this)); - GameLib.D3.Shape.call( + R3.D3.Shape.call( this, this.physics, apiShape ); }; -GameLib.D3.Shape.ConvexHull.prototype = Object.create(GameLib.D3.Shape.prototype); -GameLib.D3.Shape.ConvexHull.prototype.constructor = GameLib.D3.Shape.ConvexHull; +R3.D3.Shape.ConvexHull.prototype = Object.create(R3.D3.Shape.prototype); +R3.D3.Shape.ConvexHull.prototype.constructor = R3.D3.Shape.ConvexHull; /** * Create instance - * @returns {GameLib.D3.Shape.ConvexHull} + * @returns {R3.D3.Shape.ConvexHull} */ -GameLib.D3.Shape.ConvexHull.prototype.createInstance = function() { +R3.D3.Shape.ConvexHull.prototype.createInstance = function() { var faceNormals = []; @@ -109,15 +109,15 @@ GameLib.D3.Shape.ConvexHull.prototype.createInstance = function() { this.vertices.map( function(vertex) { - if (GameLib.Utils.UndefinedOrNull(vertex)) { + if (R3.Utils.UndefinedOrNull(vertex)) { throw new Error('no vertex'); } - if (GameLib.Utils.UndefinedOrNull(vertex.position)) { + if (R3.Utils.UndefinedOrNull(vertex.position)) { throw new Error('no vertex position'); } - if (GameLib.Utils.UndefinedOrNull(vertex.position.instance)) { + if (R3.Utils.UndefinedOrNull(vertex.position.instance)) { throw new Error('no vertex position instance'); } @@ -127,27 +127,27 @@ GameLib.D3.Shape.ConvexHull.prototype.createInstance = function() { this.faces.map( function(face) { - if (GameLib.Utils.UndefinedOrNull(face)) { + if (R3.Utils.UndefinedOrNull(face)) { throw new Error('no face'); } - if (GameLib.Utils.UndefinedOrNull(face.normal)) { + if (R3.Utils.UndefinedOrNull(face.normal)) { throw new Error('no face normal'); } - if (GameLib.Utils.UndefinedOrNull(face.normal.instance)) { + if (R3.Utils.UndefinedOrNull(face.normal.instance)) { throw new Error('no face normal instance'); } - if (GameLib.Utils.UndefinedOrNull(face.v0index)) { + if (R3.Utils.UndefinedOrNull(face.v0index)) { throw new Error('no face v0index'); } - if (GameLib.Utils.UndefinedOrNull(face.v1index)) { + if (R3.Utils.UndefinedOrNull(face.v1index)) { throw new Error('no face v1index'); } - if (GameLib.Utils.UndefinedOrNull(face.v2index)) { + if (R3.Utils.UndefinedOrNull(face.v2index)) { throw new Error('no face v2index'); } @@ -160,13 +160,13 @@ GameLib.D3.Shape.ConvexHull.prototype.createInstance = function() { this.instance.faceNormals = faceNormals; - GameLib.D3.Shape.prototype.createInstance.call(this); + R3.D3.Shape.prototype.createInstance.call(this); }; /** * Update instance */ -GameLib.D3.Shape.ConvexHull.prototype.updateInstance = function() { +R3.D3.Shape.ConvexHull.prototype.updateInstance = function() { console.log('todo: update convex hull instance'); // this.instance.vertices = this.vertices; // this.instance.indices = this.indices; @@ -177,18 +177,18 @@ GameLib.D3.Shape.ConvexHull.prototype.updateInstance = function() { // this.instance.updateTree(); }; -GameLib.D3.Shape.ConvexHull.prototype.loadFromInstance = function() { +R3.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 :)'); + console.log('todo: this way we can nicely visualize them with our r3 classes :)'); }; -GameLib.D3.Shape.ConvexHull.prototype.toApiObject = function() { +R3.D3.Shape.ConvexHull.prototype.toApiObject = function() { - var apiShape = GameLib.D3.Shape.prototype.toApiObject.call(this); + var apiShape = R3.D3.Shape.prototype.toApiObject.call(this); apiShape.vertices = this.vertices.map( function(vertex) { - if (vertex instanceof GameLib.D3.Vertex) { + if (vertex instanceof R3.D3.Vertex) { return vertex.toApiObject(); } return vertex; @@ -197,7 +197,7 @@ GameLib.D3.Shape.ConvexHull.prototype.toApiObject = function() { apiShape.faces = this.faces.map( function(face) { - if (face instanceof GameLib.D3.Face){ + if (face instanceof R3.D3.Face){ return face.toApiObject(); } return face; @@ -206,7 +206,7 @@ GameLib.D3.Shape.ConvexHull.prototype.toApiObject = function() { apiShape.uniqueAxes = this.uniqueAxes.map( function(axis){ - if (axis instanceof GameLib.Vector3) { + if (axis instanceof R3.Vector3) { return axis.toApiObject(); } return axis; @@ -215,7 +215,7 @@ GameLib.D3.Shape.ConvexHull.prototype.toApiObject = function() { apiShape.uniqueEdges = this.uniqueEdges.map( function(edge) { - if (edge instanceof GameLib.Vector3) { + if (edge instanceof R3.Vector3) { return edge.toApiObject(); } return edge; @@ -225,33 +225,33 @@ GameLib.D3.Shape.ConvexHull.prototype.toApiObject = function() { return apiShape; }; -GameLib.D3.Shape.ConvexHull.prototype.setFromMesh = function() { +R3.D3.Shape.ConvexHull.prototype.setFromMesh = function() { console.log('todo: set convex hull from mesh'); this.updateInstance(); }; -GameLib.D3.Shape.ConvexHull.InheritableProperties = function(physics, objectShape) { +R3.D3.Shape.ConvexHull.InheritableProperties = function(physics, objectShape) { var vertices = objectShape.vertices.map( function(objectVertex) { - return GameLib.D3.Vertex.FromObject(physics, objectVertex); + return R3.D3.Vertex.FromObject(physics, objectVertex); } ); var faces = objectShape.faces.map( function(objectFace) { - return GameLib.D3.Face.FromObject(physics, objectFace); + return R3.D3.Face.FromObject(physics, objectFace); } ); var uniqueAxes = objectShape.uniqueAxes.map( function(axis) { - return GameLib.API.Vector3.FromObject(axis); + return R3.API.Vector3.FromObject(axis); } ); var uniqueEdges = objectShape.uniqueEdges.map( function(edge) { - return GameLib.API.Vector3.FromObject(edge); + return R3.API.Vector3.FromObject(edge); } ); @@ -263,13 +263,13 @@ GameLib.D3.Shape.ConvexHull.InheritableProperties = function(physics, objectShap }; }; -GameLib.D3.Shape.ConvexHull.FromObject = function(physics, objectShape) { +R3.D3.Shape.ConvexHull.FromObject = function(physics, objectShape) { - var apiShape = GameLib.D3.API.Shape.FromObject(objectShape); + var apiShape = R3.D3.API.Shape.FromObject(objectShape); - var inheritableProperties = GameLib.D3.Shape.ConvexHull.InheritableProperties(physics, objectShape); + var inheritableProperties = R3.D3.Shape.ConvexHull.InheritableProperties(physics, objectShape); - return new GameLib.D3.Shape.ConvexHull.call( + return new R3.D3.Shape.ConvexHull.call( this, physics, apiShape, diff --git a/src/game-lib-d3-shape-convex-hull-cylinder.js b/src/r3-d3-shape-convex-hull-cylinder.js similarity index 57% rename from src/game-lib-d3-shape-convex-hull-cylinder.js rename to src/r3-d3-shape-convex-hull-cylinder.js index 9bebe3d..56b99ca 100644 --- a/src/game-lib-d3-shape-convex-hull-cylinder.js +++ b/src/r3-d3-shape-convex-hull-cylinder.js @@ -1,14 +1,14 @@ /** * Shape Superset - The apiShape properties get moved into the Shape object itself, and then the instance is created * @param physics - * @param apiShape GameLib.D3.API.Shape + * @param apiShape R3.D3.API.Shape * @param radiusTop * @param radiusBottom * @param height * @param numSegments * @constructor */ -GameLib.D3.Shape.ConvexHull.Cylinder = function ( +R3.D3.Shape.ConvexHull.Cylinder = function ( physics, apiShape, radiusTop, @@ -19,47 +19,47 @@ GameLib.D3.Shape.ConvexHull.Cylinder = function ( this.physics = physics; this.physics.isNotCannonThrow(); - if (GameLib.Utils.UndefinedOrNull(apiShape)) { + if (R3.Utils.UndefinedOrNull(apiShape)) { apiShape = { - shapeType : GameLib.D3.API.Shape.SHAPE_TYPE_CONVEX_HULL_CYLINDER + shapeType : R3.D3.API.Shape.SHAPE_TYPE_CONVEX_HULL_CYLINDER }; } - if (GameLib.Utils.UndefinedOrNull(radiusTop)) { + if (R3.Utils.UndefinedOrNull(radiusTop)) { radiusTop = 1; } this.radiusTop = radiusTop; - if (GameLib.Utils.UndefinedOrNull(radiusBottom)) { + if (R3.Utils.UndefinedOrNull(radiusBottom)) { radiusBottom = 1; } this.radiusBottom = radiusBottom; - if (GameLib.Utils.UndefinedOrNull(height)) { + if (R3.Utils.UndefinedOrNull(height)) { height = radiusBottom / 2; } this.height = height; - if (GameLib.Utils.UndefinedOrNull(numSegments)) { + if (R3.Utils.UndefinedOrNull(numSegments)) { numSegments = 20; } this.numSegments = numSegments; - GameLib.D3.Shape.ConvexHull.call( + R3.D3.Shape.ConvexHull.call( this, this.physics, apiShape ); }; -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; +R3.D3.Shape.ConvexHull.Cylinder.prototype = Object.create(R3.D3.Shape.ConvexHull.prototype); +R3.D3.Shape.ConvexHull.Cylinder.prototype.constructor = R3.D3.Shape.ConvexHull.Cylinder; /** * - * @returns {GameLib.D3.Shape.Cylinder|*|SEA3D.Cylinder} + * @returns {R3.D3.Shape.Cylinder|*|SEA3D.Cylinder} */ -GameLib.D3.Shape.ConvexHull.Cylinder.prototype.createInstance = function() { +R3.D3.Shape.ConvexHull.Cylinder.prototype.createInstance = function() { this.instance = new CANNON.Cylinder( this.radiusTop, @@ -68,10 +68,10 @@ GameLib.D3.Shape.ConvexHull.Cylinder.prototype.createInstance = function() { this.numSegments ); - GameLib.D3.Shape.prototype.createInstance.call(this); + R3.D3.Shape.prototype.createInstance.call(this); }; -GameLib.D3.Shape.ConvexHull.Cylinder.prototype.updateInstance = function() { +R3.D3.Shape.ConvexHull.Cylinder.prototype.updateInstance = function() { console.log('todo : update cylinder instance'); // this.instance.radius = this.radius; @@ -82,15 +82,15 @@ GameLib.D3.Shape.ConvexHull.Cylinder.prototype.updateInstance = function() { // this.instance.updateTree(); }; -GameLib.D3.Shape.ConvexHull.Cylinder.prototype.setFromMesh = function() { +R3.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() { +R3.D3.Shape.ConvexHull.Cylinder.prototype.toApiObject = function() { - var apiShape = GameLib.D3.Shape.ConvexHull.prototype.toApiObject.call(this); + var apiShape = R3.D3.Shape.ConvexHull.prototype.toApiObject.call(this); apiShape.radiusTop = this.radiusTop; apiShape.radiusBottom = this.radiusBottom; @@ -101,19 +101,19 @@ GameLib.D3.Shape.ConvexHull.Cylinder.prototype.toApiObject = function() { }; -GameLib.D3.Shape.ConvexHull.Cylinder.FromObject = function(physics, objectShape) { +R3.D3.Shape.ConvexHull.Cylinder.FromObject = function(physics, objectShape) { /** * Just a reminder that below line is wrong and commented out - we need to call the constructors eventually with * the right 'this' parameter and args. * - * var apiShape = GameLib.D3.Shape.ConvexHull.FromObject(physics, objectShape); + * var apiShape = R3.D3.Shape.ConvexHull.FromObject(physics, objectShape); * * Instead, do this: */ - var apiShape = GameLib.D3.API.Shape.FromObject(objectShape); + var apiShape = R3.D3.API.Shape.FromObject(objectShape); - var inheritableProperties = GameLib.D3.Shape.ConvexHull.InheritableProperties(physics, objectShape); + var inheritableProperties = R3.D3.Shape.ConvexHull.InheritableProperties(physics, objectShape); for (var property in inheritableProperties) { if (inheritableProperties.hasOwnProperty(property)) { @@ -121,7 +121,7 @@ GameLib.D3.Shape.ConvexHull.Cylinder.FromObject = function(physics, objectShape) } } - return new GameLib.D3.Shape.ConvexHull.Cylinder( + return new R3.D3.Shape.ConvexHull.Cylinder( physics, apiShape, objectShape.radiusTop, diff --git a/src/game-lib-d3-shape-height-map.js b/src/r3-d3-shape-height-map.js similarity index 70% rename from src/game-lib-d3-shape-height-map.js rename to src/r3-d3-shape-height-map.js index f3d58fd..4a79ff9 100644 --- a/src/game-lib-d3-shape-height-map.js +++ b/src/r3-d3-shape-height-map.js @@ -8,7 +8,7 @@ * @param elementSize * @constructor */ -GameLib.D3.Shape.HeightMap = function ( +R3.D3.Shape.HeightMap = function ( physics, apiShape, heightData, @@ -19,47 +19,47 @@ GameLib.D3.Shape.HeightMap = function ( this.physics = physics; this.physics.isNotCannonThrow(); - if (GameLib.Utils.UndefinedOrNull(apiShape)) { + if (R3.Utils.UndefinedOrNull(apiShape)) { apiShape = { - shapeType : GameLib.D3.API.Shape.SHAPE_TYPE_HEIGHT_MAP + shapeType : R3.D3.API.Shape.SHAPE_TYPE_HEIGHT_MAP }; } - if (GameLib.Utils.UndefinedOrNull(heightData)) { + if (R3.Utils.UndefinedOrNull(heightData)) { heightData = [[10, 10, 10], [10, 10, 10], [10, 10, 10]]; } this.heightData = heightData; - if (GameLib.Utils.UndefinedOrNull(minValue)) { + if (R3.Utils.UndefinedOrNull(minValue)) { minValue = 0; } this.minValue = minValue; - if (GameLib.Utils.UndefinedOrNull(maxValue)) { + if (R3.Utils.UndefinedOrNull(maxValue)) { maxValue = 10; } this.maxValue = maxValue; - if (GameLib.Utils.UndefinedOrNull(elementSize)) { + if (R3.Utils.UndefinedOrNull(elementSize)) { elementSize = 1; } this.elementSize = elementSize; - GameLib.D3.Shape.call( + R3.D3.Shape.call( this, this.physics, apiShape ); }; -GameLib.D3.Shape.HeightMap.prototype = Object.create(GameLib.D3.Shape.prototype); -GameLib.D3.Shape.HeightMap.prototype.constructor = GameLib.D3.Shape.HeightMap; +R3.D3.Shape.HeightMap.prototype = Object.create(R3.D3.Shape.prototype); +R3.D3.Shape.HeightMap.prototype.constructor = R3.D3.Shape.HeightMap; /** * Create instance - * @returns {GameLib.D3.Shape.HeightMap} + * @returns {R3.D3.Shape.HeightMap} */ -GameLib.D3.Shape.HeightMap.prototype.createInstance = function() { +R3.D3.Shape.HeightMap.prototype.createInstance = function() { //TODO: initialize properly and throw when errors @@ -70,13 +70,13 @@ GameLib.D3.Shape.HeightMap.prototype.createInstance = function() { } ); - GameLib.D3.Shape.prototype.createInstance.call(this); + R3.D3.Shape.prototype.createInstance.call(this); }; /** * Update instance */ -GameLib.D3.Shape.HeightMap.prototype.updateInstance = function() { +R3.D3.Shape.HeightMap.prototype.updateInstance = function() { this.instance.data = this.heightData; // this.instance.minValue = this.minValue; // this.instance.maxValue = this.maxValue; @@ -88,8 +88,8 @@ GameLib.D3.Shape.HeightMap.prototype.updateInstance = function() { }; -GameLib.D3.Shape.HeightMap.prototype.toApiObject = function() { - var apiShape = GameLib.D3.Shape.prototype.toApiObject.call(this); +R3.D3.Shape.HeightMap.prototype.toApiObject = function() { + var apiShape = R3.D3.Shape.prototype.toApiObject.call(this); apiShape.heightData = this.heightData; apiShape.minValue = this.minValue; apiShape.maxValue = this.maxValue; @@ -97,7 +97,7 @@ GameLib.D3.Shape.HeightMap.prototype.toApiObject = function() { return apiShape; }; -GameLib.D3.Shape.HeightMap.prototype.setFromMesh = function() { +R3.D3.Shape.HeightMap.prototype.setFromMesh = function() { if (this.parentMesh === null) { console.log('select a mesh first'); @@ -156,11 +156,11 @@ GameLib.D3.Shape.HeightMap.prototype.setFromMesh = function() { this.updateInstance(); }; -GameLib.D3.Shape.HeightMap.FromObject = function(physics, objectShape) { +R3.D3.Shape.HeightMap.FromObject = function(physics, objectShape) { - var apiShape = GameLib.D3.API.Shape.FromObject(objectShape); + var apiShape = R3.D3.API.Shape.FromObject(objectShape); - return new GameLib.D3.Shape.HeightMap( + return new R3.D3.Shape.HeightMap( physics, apiShape, objectShape.heightData, diff --git a/src/r3-d3-shape-plane.js b/src/r3-d3-shape-plane.js new file mode 100644 index 0000000..c7d1151 --- /dev/null +++ b/src/r3-d3-shape-plane.js @@ -0,0 +1,53 @@ +/** + * Shape Superset - The apiShape properties get moved into the Shape object itself, and then the instance is created + * @param physics + * @param apiShape R3.D3.API.Shape + * @constructor + */ +R3.D3.Shape.Plane = function ( + physics, + apiShape +) { + this.physics = physics; + this.physics.isNotCannonThrow(); + + if (R3.Utils.UndefinedOrNull(apiShape)) { + apiShape = { + shapeType : R3.D3.API.Shape.SHAPE_TYPE_PLANE + }; + } + + R3.D3.Shape.call( + this, + this.physics, + apiShape + ); +}; + +R3.D3.Shape.Plane.prototype = Object.create(R3.D3.Shape.prototype); +R3.D3.Shape.Plane.prototype.constructor = R3.D3.Shape.Plane; + +/** + * + * @returns {R3.D3.Shape.Plane|*|SEA3D.Plane} + */ +R3.D3.Shape.Plane.prototype.createInstance = function() { + /** + * A plane is just a plane at z = 0, to rotate it put it inside a rigid body and rotate the body + */ + this.instance = new CANNON.Plane(); + R3.D3.Shape.prototype.createInstance.call(this); +}; + +R3.D3.Shape.Plane.prototype.updateInstance = function() { +}; + +R3.D3.Shape.Plane.FromObject = function(physics, objectShape) { + + var apiShape = R3.D3.API.Shape.FromObject(objectShape); + + return new R3.D3.Shape.Plane( + physics, + apiShape + ); +}; \ No newline at end of file diff --git a/src/r3-d3-shape-sphere.js b/src/r3-d3-shape-sphere.js new file mode 100644 index 0000000..3a9f3b6 --- /dev/null +++ b/src/r3-d3-shape-sphere.js @@ -0,0 +1,71 @@ +/** + * Shape Superset - The apiShape properties get moved into the Shape object itself, and then the instance is created + * @param physics + * @param apiShape R3.D3.API.Shape + * @param radius + * @constructor + */ +R3.D3.Shape.Sphere = function ( + physics, + apiShape, + radius +) { + this.physics = physics; + this.physics.isNotCannonThrow(); + + if (R3.Utils.UndefinedOrNull(apiShape)) { + apiShape = { + shapeType : R3.D3.API.Shape.SHAPE_TYPE_SPHERE + }; + } + + if (R3.Utils.UndefinedOrNull(radius)) { + radius = 1; + } + this.radius = radius; + + R3.D3.Shape.call( + this, + this.physics, + apiShape + ); +}; + +R3.D3.Shape.Sphere.prototype = Object.create(R3.D3.Shape.prototype); +R3.D3.Shape.Sphere.prototype.constructor = R3.D3.Shape.Sphere; + +/** + * + * @returns {R3.D3.Shape.Sphere|*|SEA3D.Sphere} + */ +R3.D3.Shape.Sphere.prototype.createInstance = function() { + + this.instance = new CANNON.Sphere( + this.radius + ); + + R3.D3.Shape.prototype.createInstance.call(this); +}; + +R3.D3.Shape.Sphere.prototype.updateInstance = function() { + this.instance.radius = this.radius; + this.instance.updateBoundingSphereRadius(); +}; + + +R3.D3.Shape.Sphere.prototype.toApiObject = function() { + var apiShape = R3.D3.Shape.prototype.toApiObject.call(this); + apiShape.radius = this.radius; + return apiShape; +}; + +R3.D3.Shape.Sphere.FromObject = function(physics, objectShape) { + + var apiShape = R3.D3.API.Shape.FromObject(objectShape); + + return new R3.D3.Shape.Sphere( + physics, + apiShape, + objectShape.radius + ); +}; \ No newline at end of file diff --git a/src/game-lib-d3-shape-tri-mesh.js b/src/r3-d3-shape-tri-mesh.js similarity index 56% rename from src/game-lib-d3-shape-tri-mesh.js rename to src/r3-d3-shape-tri-mesh.js index a60010d..4777627 100644 --- a/src/game-lib-d3-shape-tri-mesh.js +++ b/src/r3-d3-shape-tri-mesh.js @@ -1,12 +1,12 @@ /** * Shape Superset - The apiShape properties get moved into the Shape object itself, and then the instance is created * @param physics - * @param apiShape GameLib.D3.API.Shape + * @param apiShape R3.D3.API.Shape * @param vertices * @param indices * @constructor */ -GameLib.D3.Shape.TriMesh = function ( +R3.D3.Shape.TriMesh = function ( physics, apiShape, vertices, @@ -15,51 +15,51 @@ GameLib.D3.Shape.TriMesh = function ( this.physics = physics; this.physics.isNotCannonThrow(); - if (GameLib.Utils.UndefinedOrNull(apiShape)) { + if (R3.Utils.UndefinedOrNull(apiShape)) { apiShape = { - shapeType : GameLib.D3.API.Shape.SHAPE_TYPE_TRIMESH + shapeType : R3.D3.API.Shape.SHAPE_TYPE_TRIMESH }; } - if (GameLib.Utils.UndefinedOrNull(vertices)) { + if (R3.Utils.UndefinedOrNull(vertices)) { vertices = []; } this.vertices = vertices; - if (GameLib.Utils.UndefinedOrNull(indices)) { + if (R3.Utils.UndefinedOrNull(indices)) { indices = []; } this.indices = indices; - GameLib.D3.Shape.call( + R3.D3.Shape.call( this, this.physics, apiShape ); }; -GameLib.D3.Shape.TriMesh.prototype = Object.create(GameLib.D3.Shape.prototype); -GameLib.D3.Shape.TriMesh.prototype.constructor = GameLib.D3.Shape.TriMesh; +R3.D3.Shape.TriMesh.prototype = Object.create(R3.D3.Shape.prototype); +R3.D3.Shape.TriMesh.prototype.constructor = R3.D3.Shape.TriMesh; /** * Create instance - * @returns {GameLib.D3.Shape.TriMesh} + * @returns {R3.D3.Shape.TriMesh} */ -GameLib.D3.Shape.TriMesh.prototype.createInstance = function() { +R3.D3.Shape.TriMesh.prototype.createInstance = function() { this.instance = new CANNON.TriMesh( this.vertices, this.indices ); - GameLib.D3.Shape.prototype.createInstance.call(this); + R3.D3.Shape.prototype.createInstance.call(this); }; /** * Update instance */ -GameLib.D3.Shape.TriMesh.prototype.updateInstance = function() { +R3.D3.Shape.TriMesh.prototype.updateInstance = function() { this.instance.vertices = this.vertices; this.instance.indices = this.indices; this.instance.updateAABB(); diff --git a/src/game-lib-d3-skeleton.js b/src/r3-d3-skeleton.js similarity index 70% rename from src/game-lib-d3-skeleton.js rename to src/r3-d3-skeleton.js index fe4c989..0a7769c 100644 --- a/src/game-lib-d3-skeleton.js +++ b/src/r3-d3-skeleton.js @@ -1,21 +1,21 @@ /** * Skeleton Superset * @constructor - * @param graphics GameLib.GraphicsRuntime - * @param apiSkeleton GameLib.D3.API.Skeleton + * @param graphics R3.GraphicsRuntime + * @param apiSkeleton R3.D3.API.Skeleton */ -GameLib.D3.Skeleton = function Skeleton( +R3.D3.Skeleton = function Skeleton( graphics, apiSkeleton ) { this.graphics = graphics; this.graphics.isNotThreeThrow(); - if (GameLib.Utils.UndefinedOrNull(apiSkeleton)) { + if (R3.Utils.UndefinedOrNull(apiSkeleton)) { apiSkeleton = {}; } - GameLib.D3.API.Skeleton.call( + R3.D3.API.Skeleton.call( this, apiSkeleton.id, apiSkeleton.name, @@ -32,8 +32,8 @@ GameLib.D3.Skeleton = function Skeleton( this.bones = this.bones.map( function(apiBone) { - if (apiBone instanceof GameLib.D3.API.Bone) { - return new GameLib.D3.Bone( + if (apiBone instanceof R3.D3.API.Bone) { + return new R3.D3.Bone( this.graphics, apiBone ) @@ -48,8 +48,8 @@ GameLib.D3.Skeleton = function Skeleton( this.boneInverses = this.boneInverses.map( function(boneInverse) { - if (boneInverse instanceof GameLib.API.Matrix4) { - return new GameLib.Matrix4( + if (boneInverse instanceof R3.API.Matrix4) { + return new R3.Matrix4( this.graphics, boneInverse, this @@ -64,8 +64,8 @@ GameLib.D3.Skeleton = function Skeleton( this.boneMatrices = this.boneMatrices.map( function(boneMatrices) { - if (boneMatrices instanceof GameLib.API.Matrix4) { - return new GameLib.Matrix4( + if (boneMatrices instanceof R3.API.Matrix4) { + return new R3.Matrix4( this.graphics, boneMatrices, this @@ -78,32 +78,32 @@ GameLib.D3.Skeleton = function Skeleton( }.bind(this) ); - GameLib.Component.call( + R3.Component.call( this, { - 'bones' : [GameLib.D3.Bone] + 'bones' : [R3.D3.Bone] } ); }; -GameLib.D3.Skeleton.prototype = Object.create(GameLib.Component.prototype); -GameLib.D3.Skeleton.prototype.constructor = GameLib.D3.Skeleton; +R3.D3.Skeleton.prototype = Object.create(R3.Component.prototype); +R3.D3.Skeleton.prototype.constructor = R3.D3.Skeleton; /** * Creates an instance skeleton * @param update boolean */ -GameLib.D3.Skeleton.prototype.createInstance = function(update) { +R3.D3.Skeleton.prototype.createInstance = function(update) { var boneInstances = this.bones.map ( function (bone) { - if (GameLib.Utils.UndefinedOrNull(bone)) { + if (R3.Utils.UndefinedOrNull(bone)) { throw new Error('no bone'); } - if (GameLib.Utils.UndefinedOrNull(bone.instance)) { + if (R3.Utils.UndefinedOrNull(bone.instance)) { throw new Error('no bone instance'); } @@ -128,7 +128,7 @@ GameLib.D3.Skeleton.prototype.createInstance = function(update) { null ); - if (GameLib.Utils.UndefinedOrNull(parentBoneInstance)) { + if (R3.Utils.UndefinedOrNull(parentBoneInstance)) { throw new Error('could not find parent bone instance'); } @@ -165,23 +165,23 @@ GameLib.D3.Skeleton.prototype.createInstance = function(update) { this.instance.calculateInverses(); - GameLib.Component.prototype.createInstance.call(this); + R3.Component.prototype.createInstance.call(this); }; /** * Updates the instance */ -GameLib.D3.Skeleton.prototype.updateInstance = function(property) { - GameLib.Component.prototype.updateInstance.call(this, property); +R3.D3.Skeleton.prototype.updateInstance = function(property) { + R3.Component.prototype.updateInstance.call(this, property); }; /** - * Converts a GameLib.D3.Skeleton to GameLib.D3.API.Skeleton - * @returns {GameLib.D3.API.Skeleton} + * Converts a R3.D3.Skeleton to R3.D3.API.Skeleton + * @returns {R3.D3.API.Skeleton} */ -GameLib.D3.Skeleton.prototype.toApiObject = function() { +R3.D3.Skeleton.prototype.toApiObject = function() { - var apiSkeleton = new GameLib.D3.API.Skeleton( + var apiSkeleton = new R3.D3.API.Skeleton( this.id, this.name, this.bones.map( @@ -203,20 +203,20 @@ GameLib.D3.Skeleton.prototype.toApiObject = function() { } ), this.boneTexture, - GameLib.Utils.IdOrNull(this.parentEntity) + R3.Utils.IdOrNull(this.parentEntity) ); return apiSkeleton; }; /** - * Returns a GameLib.D3.Skeleton from a skeleton Object - * @param graphics GameLib.GraphicsRuntime + * Returns a R3.D3.Skeleton from a skeleton Object + * @param graphics R3.GraphicsRuntime * @param objectSkeleton Object - * @returns {GameLib.D3.Skeleton} + * @returns {R3.D3.Skeleton} * @constructor */ -GameLib.D3.Skeleton.FromObject = function( +R3.D3.Skeleton.FromObject = function( graphics, objectSkeleton ) { @@ -225,9 +225,9 @@ GameLib.D3.Skeleton.FromObject = function( return null; } - var apiSkeleton = GameLib.D3.API.Skeleton.FromObject(objectSkeleton); + var apiSkeleton = R3.D3.API.Skeleton.FromObject(objectSkeleton); - var skeleton = new GameLib.D3.Skeleton( + var skeleton = new R3.D3.Skeleton( graphics, apiSkeleton ); diff --git a/src/r3-d3-solver.js b/src/r3-d3-solver.js new file mode 100644 index 0000000..61aba53 --- /dev/null +++ b/src/r3-d3-solver.js @@ -0,0 +1,111 @@ +/** + * Solver Runtime + * @param physics R3.GraphicsRuntime + * @param apiSolver R3.D3.API.Solver + * @constructor + */ +R3.D3.Solver = function ( + physics, + apiSolver +) { + + this.physics = physics; + this.physics.isNotCannonThrow(); + + if (R3.Utils.UndefinedOrNull(apiSolver)) { + apiSolver = {}; + } + + R3.D3.API.Solver.call( + this, + apiSolver.id, + apiSolver.name, + apiSolver.solverType, + apiSolver.iterations, + apiSolver.tolerance, + apiSolver.parentEntity + ); + + R3.Component.call(this); +}; + +R3.D3.Solver.prototype = Object.create(R3.Component.prototype); +R3.D3.Solver.prototype.constructor = R3.D3.Solver; + +/** + * + * @returns {*} + */ +R3.D3.Solver.prototype.createInstance = function() { + + if (this.solverType === R3.D3.API.Solver.GS_SOLVER) { + this.instance = new CANNON.GSSolver(); + } else if (this.solverType === R3.D3.API.Solver.SPLIT_SOLVER) { + this.instance = new CANNON.SplitSolver(); + } else { + throw new Error('unsupported solver type: ' + this.solverType); + } + + this.instance.tolerance = this.tolerance; + this.instance.iterations = this.iterations; + + R3.Component.prototype.createInstance.call(this); +}; + +/** + * + */ +R3.D3.Solver.prototype.updateInstance = function(property) { + + if (this.solverType === R3.D3.API.Solver.GS_SOLVER) { + if (!(this.instance instanceof CANNON.GSSolver)) { + this.instance = new CANNON.GSSolver(); + } + } + + if (this.solverType === R3.D3.API.Solver.SPLIT_SOLVER) { + if (!(this.instance instanceof CANNON.SplitSolver)) { + this.instance = new CANNON.SplitSolver(); + } + } + + this.instance.iterations = this.iterations; + this.instance.tolerance = this.tolerance; + + R3.Component.prototype.updateInstance.call(this, property); +}; + +/** + * R3.D3.Solver to R3.D3.API.Solver + * @returns {R3.D3.API.Solver} + */ +R3.D3.Solver.prototype.toApiObject = function() { + + var apiSolver = new R3.D3.API.Solver( + this.id, + this.name, + this.solverType, + this.iterations, + this.tolerance, + R3.Utils.IdOrNull(this.parentEntity) + ); + + return apiSolver; +}; + +/** + * R3.D3.Solver from Object Solver + * @param graphics + * @param objectComponent + * @returns {R3.D3.Solver} + * @constructor + */ +R3.D3.Solver.FromObject = function(graphics, objectComponent) { + + var apiSolver = R3.D3.API.Solver.FromObject(objectComponent); + + return new R3.D3.Solver( + graphics, + apiSolver + ); +}; diff --git a/src/game-lib-d3-spline.js b/src/r3-d3-spline.js similarity index 53% rename from src/game-lib-d3-spline.js rename to src/r3-d3-spline.js index 985079d..859ee8a 100644 --- a/src/game-lib-d3-spline.js +++ b/src/r3-d3-spline.js @@ -1,21 +1,21 @@ /** * Spline constructor - * @param graphics GameLib.GraphicsRuntime - * @param apiSpline GameLib.D3.API.Spline + * @param graphics R3.GraphicsRuntime + * @param apiSpline R3.D3.API.Spline * @constructor */ -GameLib.D3.Spline = function ( +R3.D3.Spline = function ( graphics, apiSpline ) { this.graphics = graphics; this.graphics.isNotThreeThrow(); - if (GameLib.Utils.UndefinedOrNull(apiSpline)) { + if (R3.Utils.UndefinedOrNull(apiSpline)) { apiSpline = {}; } - GameLib.D3.API.Spline.call( + R3.D3.API.Spline.call( this, apiSpline.id, apiSpline.name, @@ -25,7 +25,7 @@ GameLib.D3.Spline = function ( this.vertices = this.vertices.map( function (vertex) { - return new GameLib.Vector3( + return new R3.Vector3( graphics, vertex, this @@ -33,25 +33,25 @@ GameLib.D3.Spline = function ( } ); - GameLib.Component.call(this); + R3.Component.call(this); }; -GameLib.D3.Spline.prototype = Object.create(GameLib.Component.prototype); -GameLib.D3.Spline.prototype.constructor = GameLib.D3.Spline; +R3.D3.Spline.prototype = Object.create(R3.Component.prototype); +R3.D3.Spline.prototype.constructor = R3.D3.Spline; /** * Creates an instance spline */ -GameLib.D3.Spline.prototype.createInstance = function() { +R3.D3.Spline.prototype.createInstance = function() { var vertices = this.vertices.map( function (vertex) { - if (GameLib.Utils.UndefinedOrNull(vertex)) { + if (R3.Utils.UndefinedOrNull(vertex)) { throw new Error('no vertex') } - if (GameLib.Utils.UndefinedOrNull(vertex.instance)) { + if (R3.Utils.UndefinedOrNull(vertex.instance)) { throw new Error('no vertex instance') } @@ -61,22 +61,22 @@ GameLib.D3.Spline.prototype.createInstance = function() { this.instance = THREE.CatmullRomCurve3(vertices); - GameLib.Component.prototype.createInstance.call(this); + R3.Component.prototype.createInstance.call(this); }; /** * Updates the instance */ -GameLib.D3.Spline.prototype.updateInstance = function(property) { +R3.D3.Spline.prototype.updateInstance = function(property) { var vertices = this.vertices.map( function (vertex) { - if (GameLib.Utils.UndefinedOrNull(vertex)) { + if (R3.Utils.UndefinedOrNull(vertex)) { throw new Error('no vertex') } - if (GameLib.Utils.UndefinedOrNull(vertex.instance)) { + if (R3.Utils.UndefinedOrNull(vertex.instance)) { throw new Error('no vertex instance') } @@ -86,16 +86,16 @@ GameLib.D3.Spline.prototype.updateInstance = function(property) { this.instance = new THREE.CatmullRomCurve3(vertices); - GameLib.Component.prototype.updateInstance.call(this, property); + R3.Component.prototype.updateInstance.call(this, property); }; /** - * Converts a GameLib.D3.Spline to GameLib.D3.API.Spline - * @returns {GameLib.D3.API.Spline} + * Converts a R3.D3.Spline to R3.D3.API.Spline + * @returns {R3.D3.API.Spline} */ -GameLib.D3.Spline.prototype.toApiObject = function() { +R3.D3.Spline.prototype.toApiObject = function() { - return new GameLib.D3.API.Spline( + return new R3.D3.API.Spline( this.id, this.name, this.vertices.map( @@ -103,25 +103,25 @@ GameLib.D3.Spline.prototype.toApiObject = function() { return vertex.toApiObject() } ), - GameLib.Utils.IdOrNull(this.parentEntity) + R3.Utils.IdOrNull(this.parentEntity) ); }; /** - * Returns a GameLib.D3.Spline from a spline Object - * @param graphics GameLib.GraphicsRuntime + * Returns a R3.D3.Spline from a spline Object + * @param graphics R3.GraphicsRuntime * @param objectComponent Object - * @returns {GameLib.D3.Spline} + * @returns {R3.D3.Spline} * @constructor */ -GameLib.D3.Spline.FromObject = function( +R3.D3.Spline.FromObject = function( graphics, objectComponent ) { - var apiSpline = GameLib.D3.API.Spline.FromObject(objectComponent); + var apiSpline = R3.D3.API.Spline.FromObject(objectComponent); - return new GameLib.D3.Spline( + return new R3.D3.Spline( graphics, apiSpline ); @@ -132,11 +132,11 @@ GameLib.D3.Spline.FromObject = function( * @param proper Number (fraction between 0 and 1 indicating position on spline) * @returns {*} */ -GameLib.D3.Spline.prototype.getPointAt = function(proper) { +R3.D3.Spline.prototype.getPointAt = function(proper) { var point = this.instance.getPointAt(proper); - return new GameLib.Vector3( + return new R3.Vector3( this.graphics, - new GameLib.API.Vector3(point.x, point.y, point.z), + new R3.API.Vector3(point.x, point.y, point.z), this, 0.1 ); diff --git a/src/game-lib-d3-text.js b/src/r3-d3-text.js similarity index 60% rename from src/game-lib-d3-text.js rename to src/r3-d3-text.js index ce71b86..b4df960 100644 --- a/src/game-lib-d3-text.js +++ b/src/r3-d3-text.js @@ -2,21 +2,21 @@ * Text object * @param graphics * @param apiText - * @returns {GameLib.D3.Text} + * @returns {R3.D3.Text} * @constructor */ -GameLib.D3.Text = function( +R3.D3.Text = function( graphics, apiText ) { this.graphics = graphics; this.graphics.isNotThreeThrow(); - if (GameLib.Utils.UndefinedOrNull(apiText)) { + if (R3.Utils.UndefinedOrNull(apiText)) { apiText = {}; } - GameLib.D3.API.Text.call( + R3.D3.API.Text.call( this, apiText.id, apiText.name, @@ -28,35 +28,35 @@ GameLib.D3.Text = function( apiText.parentEntity ); - this.offset = new GameLib.Vector2( + this.offset = new R3.Vector2( this.graphics, this.offset, this ); - GameLib.Component.call(this); + R3.Component.call(this); }; -GameLib.D3.Text.prototype = Object.create(GameLib.Component.prototype); -GameLib.D3.Text.prototype.constructor = GameLib.D3.Text; +R3.D3.Text.prototype = Object.create(R3.Component.prototype); +R3.D3.Text.prototype.constructor = R3.D3.Text; /** * Creates a light instance * @returns {*} */ -GameLib.D3.Text.prototype.createInstance = function() { +R3.D3.Text.prototype.createInstance = function() { this.instance = true; - GameLib.Component.prototype.createInstance.call(this); + R3.Component.prototype.createInstance.call(this); }; /** * Updates the instance with the current state */ -GameLib.D3.Text.prototype.updateInstance = function(property) { +R3.D3.Text.prototype.updateInstance = function(property) { - if (GameLib.Utils.UndefinedOrNull(property)) { + if (R3.Utils.UndefinedOrNull(property)) { console.warn('unknown property update for Text: ' + property); } @@ -76,7 +76,7 @@ GameLib.D3.Text.prototype.updateInstance = function(property) { if (property === 'parentCanvas') { - GameLib.EntityManager.Instance.queryComponents(GameLib.Component.CANVAS).map( + R3.EntityManager.Instance.queryComponents(R3.Component.CANVAS).map( function(canvas) { var index = canvas.texts.indexOf(this); @@ -89,28 +89,28 @@ GameLib.D3.Text.prototype.updateInstance = function(property) { ); if (this.parentCanvas) { - GameLib.Utils.PushUnique(this.parentCanvas.texts, this); + R3.Utils.PushUnique(this.parentCanvas.texts, this); this.parentCanvas.updateInstance('texts'); } } - GameLib.Component.prototype.updateInstance.call(this, property); + R3.Component.prototype.updateInstance.call(this, property); }; /** - * Converts a GameLib.D3.Text to a GameLib.D3.API.Text - * @returns {GameLib.D3.API.Text} + * Converts a R3.D3.Text to a R3.D3.API.Text + * @returns {R3.D3.API.Text} */ -GameLib.D3.Text.prototype.toApiObject = function() { - return new GameLib.D3.API.Text( +R3.D3.Text.prototype.toApiObject = function() { + return new R3.D3.API.Text( this.id, this.name, this.offset.toApiObject(), this.font, this.fillStyle, this.value, - GameLib.Utils.IdOrNull(this.parentCanvas), - GameLib.Utils.IdOrNull(this.parentEntity) + R3.Utils.IdOrNull(this.parentCanvas), + R3.Utils.IdOrNull(this.parentEntity) ); }; \ No newline at end of file diff --git a/src/game-lib-d3-texture-a.js b/src/r3-d3-texture-a.js similarity index 81% rename from src/game-lib-d3-texture-a.js rename to src/r3-d3-texture-a.js index 159b415..219455b 100644 --- a/src/game-lib-d3-texture-a.js +++ b/src/r3-d3-texture-a.js @@ -2,12 +2,12 @@ * Texture Superset - The apiTexture properties get moved into the Texture object itself, and then the instance is * created * @param apiTexture - * @param graphics GameLib.GraphicsRuntime + * @param graphics R3.GraphicsRuntime * @param overrideInstance * @property textureType * @constructor */ -GameLib.D3.Texture = function( +R3.D3.Texture = function( graphics, apiTexture, overrideInstance @@ -15,18 +15,18 @@ GameLib.D3.Texture = function( this.graphics = graphics; this.graphics.isNotThreeThrow(); - if (GameLib.Utils.UndefinedOrNull(overrideInstance)) { + if (R3.Utils.UndefinedOrNull(overrideInstance)) { overrideInstance = null; } this.overrideInstance = overrideInstance; - if (GameLib.Utils.UndefinedOrNull(apiTexture)) { + if (R3.Utils.UndefinedOrNull(apiTexture)) { apiTexture = { - textureType : GameLib.D3.API.Texture.TEXTURE_TYPE_NONE + textureType : R3.D3.API.Texture.TEXTURE_TYPE_NONE }; } - GameLib.D3.API.Texture.call( + R3.D3.API.Texture.call( this, apiTexture.id, apiTexture.name, @@ -58,19 +58,19 @@ GameLib.D3.Texture = function( apiTexture.forward ); - this.offset = new GameLib.Vector2( + this.offset = new R3.Vector2( this.graphics, this.offset, this ); - this.repeat = new GameLib.Vector2( + this.repeat = new R3.Vector2( this.graphics, this.repeat, this ); - this.center = new GameLib.Vector2( + this.center = new R3.Vector2( this.graphics, this.center, this @@ -79,34 +79,34 @@ GameLib.D3.Texture = function( var linkedObjects = {}; switch (apiTexture.textureType) { - case GameLib.D3.API.Texture.TEXTURE_TYPE_NONE : + case R3.D3.API.Texture.TEXTURE_TYPE_NONE : break; - case GameLib.D3.API.Texture.TEXTURE_TYPE_IMAGE : - linkedObjects.image = GameLib.Image; + case R3.D3.API.Texture.TEXTURE_TYPE_IMAGE : + linkedObjects.image = R3.Image; break; - case GameLib.D3.API.Texture.TEXTURE_TYPE_CUBE : - linkedObjects.images = [GameLib.Image]; + case R3.D3.API.Texture.TEXTURE_TYPE_CUBE : + linkedObjects.images = [R3.Image]; break; - case GameLib.D3.API.Texture.TEXTURE_TYPE_CANVAS : - linkedObjects.canvas = GameLib.Canvas; + case R3.D3.API.Texture.TEXTURE_TYPE_CANVAS : + linkedObjects.canvas = R3.Canvas; break; default : throw new Error('Unhandled texture type : ' + this.textureType); } - GameLib.Component.call( + R3.Component.call( this, linkedObjects ); }; -GameLib.D3.Texture.prototype = Object.create(GameLib.Component.prototype); -GameLib.D3.Texture.prototype.constructor = GameLib.D3.Texture; +R3.D3.Texture.prototype = Object.create(R3.Component.prototype); +R3.D3.Texture.prototype.constructor = R3.D3.Texture; /** * Apply our settings to the instance (which are OK to be applied) */ -GameLib.D3.Texture.prototype.applyToInstance = function() { +R3.D3.Texture.prototype.applyToInstance = function() { this.instance.name = this.name; this.instance.wrapS = this.wrapS; @@ -133,7 +133,7 @@ GameLib.D3.Texture.prototype.applyToInstance = function() { * Creates an instance of our texture object * @returns {*} */ -GameLib.D3.Texture.prototype.createInstance = function() { +R3.D3.Texture.prototype.createInstance = function() { if (this.overrideInstance) { @@ -142,7 +142,7 @@ GameLib.D3.Texture.prototype.createInstance = function() { } else { - if (GameLib.Utils.UndefinedOrNull(this.instance)) { + if (R3.Utils.UndefinedOrNull(this.instance)) { /** * We have no instance - create one @@ -167,20 +167,20 @@ GameLib.D3.Texture.prototype.createInstance = function() { */ this.applyToInstance(); - GameLib.Component.prototype.createInstance.call(this); + R3.Component.prototype.createInstance.call(this); }; /** * Updates the instance with the current state */ -GameLib.D3.Texture.prototype.updateInstance = function(property) { +R3.D3.Texture.prototype.updateInstance = function(property) { - if (GameLib.Utils.UndefinedOrNull(this.instance)) { + if (R3.Utils.UndefinedOrNull(this.instance)) { console.warn('no texture instance'); return; } - if (GameLib.Utils.UndefinedOrNull(property)) { + if (R3.Utils.UndefinedOrNull(property)) { console.warn('no texture property'); return; } @@ -287,8 +287,8 @@ GameLib.D3.Texture.prototype.updateInstance = function(property) { } if (property === 'animated') { - GameLib.Event.Emit( - GameLib.Event.TEXTURE_ANIMATED_CHANGE, + R3.Event.Emit( + R3.Event.TEXTURE_ANIMATED_CHANGE, { texture: this } @@ -306,23 +306,23 @@ GameLib.D3.Texture.prototype.updateInstance = function(property) { this.instance.needsUpdate = true; this.version = this.instance.version; - GameLib.Component.prototype.updateInstance.call(this, property); + R3.Component.prototype.updateInstance.call(this, property); }; /** - * Converts a GameLib.D3.Texture to a GameLib.D3.API.Texture - * @returns {GameLib.D3.API.Texture} + * Converts a R3.D3.Texture to a R3.D3.API.Texture + * @returns {R3.D3.API.Texture} */ -GameLib.D3.Texture.prototype.toApiObject = function() { +R3.D3.Texture.prototype.toApiObject = function() { - var apiTexture = new GameLib.D3.API.Texture( + var apiTexture = new R3.D3.API.Texture( this.id, this.name, this.textureType, - GameLib.Utils.IdOrNull(this.parentEntity), + R3.Utils.IdOrNull(this.parentEntity), this.parentMaterials.map( function(parentMaterial) { - return GameLib.Utils.IdOrNull(parentMaterial); + return R3.Utils.IdOrNull(parentMaterial); } ), this.mipmaps, @@ -354,9 +354,9 @@ GameLib.D3.Texture.prototype.toApiObject = function() { }; /** - * Updates GameLib.D3.Texture from instance + * Updates R3.D3.Texture from instance */ -GameLib.D3.Texture.prototype.updateFromInstance = function() { +R3.D3.Texture.prototype.updateFromInstance = function() { this.name = this.instance.name; this.mipmaps = this.instance.mipmaps; this.mapping = this.instance.mapping; diff --git a/src/r3-d3-texture-canvas.js b/src/r3-d3-texture-canvas.js new file mode 100644 index 0000000..f320a22 --- /dev/null +++ b/src/r3-d3-texture-canvas.js @@ -0,0 +1,96 @@ +/** + * R3.D3.Texture.Canvas + * @param graphics + * @param apiTextureCanvas + * @constructor + */ +R3.D3.Texture.Canvas = function( + graphics, + apiTextureCanvas +) { + this.graphics = graphics; + this.graphics.isNotThreeThrow(); + + if (R3.Utils.UndefinedOrNull(apiTextureCanvas)) { + apiTextureCanvas = { + textureType : R3.D3.API.Texture.TEXTURE_TYPE_CANVAS + }; + } + + R3.D3.API.Texture.Canvas.call( + this, + apiTextureCanvas, + apiTextureCanvas.canvas + ); + + if (this.canvas instanceof R3.API.Canvas) { + this.canvas = new R3.Canvas( + this.graphics, + this.canvas + ); + } + + R3.D3.Texture.call( + this, + this.graphics, + this + ); + +}; + +R3.D3.Texture.Canvas.prototype = Object.create(R3.D3.Texture.prototype); +R3.D3.Texture.Canvas.prototype.constructor = R3.D3.Texture.Canvas; + +/** + * Creates an instance of our texture object + * @returns {*} + */ +R3.D3.Texture.Canvas.prototype.createInstance = function() { + + if ( + R3.Utils.UndefinedOrNull(this.canvas) || + R3.Utils.UndefinedOrNull(this.canvas.instance) + ) { + console.warn('canvas not ready at time of texture create instance'); + return; + } + + this.canvas.parentTexture = this; + + this.instance = new THREE.Texture( + this.canvas.instance + ); + + R3.D3.Texture.prototype.createInstance.call(this); +}; + +/** + * Updates the instance with the current state + */ +R3.D3.Texture.Canvas.prototype.updateInstance = function(property) { + + if (property === 'canvas') { + + this.createInstance(); + + return; + } + + R3.D3.Texture.prototype.updateInstance.call(this, property); +}; + +/** + * Converts a R3.D3.Texture.Canvas to a R3.D3.API.Texture.Canvas + * @returns {R3.D3.API.Texture.Canvas} + */ +R3.D3.Texture.Canvas.prototype.toApiObject = function() { + + var apiTexture = R3.D3.Texture.prototype.toApiObject.call(this); + + var apiTextureCanvas = new R3.D3.API.Texture.Canvas( + apiTexture, + R3.Utils.IdOrNull(this.canvas) + ); + + return apiTextureCanvas; +}; diff --git a/src/game-lib-d3-texture-cube.js b/src/r3-d3-texture-cube.js similarity index 58% rename from src/game-lib-d3-texture-cube.js rename to src/r3-d3-texture-cube.js index c0ad3f1..e1c2da6 100644 --- a/src/game-lib-d3-texture-cube.js +++ b/src/r3-d3-texture-cube.js @@ -1,23 +1,23 @@ /** - * GameLib.D3.Texture.Cube + * R3.D3.Texture.Cube * @param graphics * @param apiTextureCube * @constructor */ -GameLib.D3.Texture.Cube = function( +R3.D3.Texture.Cube = function( graphics, apiTextureCube ) { this.graphics = graphics; this.graphics.isNotThreeThrow(); - if (GameLib.Utils.UndefinedOrNull(apiTextureCube)) { + if (R3.Utils.UndefinedOrNull(apiTextureCube)) { apiTextureCube = { - textureType : GameLib.D3.API.Texture.TEXTURE_TYPE_CUBE + textureType : R3.D3.API.Texture.TEXTURE_TYPE_CUBE }; } - GameLib.D3.API.Texture.Cube.call( + R3.D3.API.Texture.Cube.call( this, apiTextureCube, apiTextureCube.images @@ -25,15 +25,15 @@ GameLib.D3.Texture.Cube = function( this.images = this.images.map( function(image) { - if (image instanceof GameLib.API.Image) { - return new GameLib.Image(image); + if (image instanceof R3.API.Image) { + return new R3.Image(image); } else { return image; } } ); - GameLib.D3.Texture.call( + R3.D3.Texture.call( this, this.graphics, this @@ -41,13 +41,13 @@ GameLib.D3.Texture.Cube = function( }; -GameLib.D3.Texture.Cube.prototype = Object.create(GameLib.D3.Texture.prototype); -GameLib.D3.Texture.Cube.prototype.constructor = GameLib.D3.Texture.Cube; +R3.D3.Texture.Cube.prototype = Object.create(R3.D3.Texture.prototype); +R3.D3.Texture.Cube.prototype.constructor = R3.D3.Texture.Cube; /** * Returns all image instances, or null if one of the images are not loaded */ -GameLib.D3.Texture.Cube.prototype.getImageInstances = function() { +R3.D3.Texture.Cube.prototype.getImageInstances = function() { return this.images.reduce( function(result, image) { @@ -60,7 +60,7 @@ GameLib.D3.Texture.Cube.prototype.getImageInstances = function() { return result; } - if (GameLib.Utils.UndefinedOrNull(image.instance)) { + if (R3.Utils.UndefinedOrNull(image.instance)) { result = null; } else { result.push(image.instance); @@ -77,7 +77,7 @@ GameLib.D3.Texture.Cube.prototype.getImageInstances = function() { * Creates an instance of our texture object * @returns {*} */ -GameLib.D3.Texture.Cube.prototype.createInstance = function() { +R3.D3.Texture.Cube.prototype.createInstance = function() { var imageInstances = this.getImageInstances(); @@ -88,13 +88,13 @@ GameLib.D3.Texture.Cube.prototype.createInstance = function() { this.instance = new THREE.CubeTexture(imageInstances); - GameLib.D3.Texture.prototype.createInstance.call(this); + R3.D3.Texture.prototype.createInstance.call(this); }; /** * Updates the instance with the current state */ -GameLib.D3.Texture.Cube.prototype.updateInstance = function(property) { +R3.D3.Texture.Cube.prototype.updateInstance = function(property) { if (property === 'images') { @@ -107,7 +107,7 @@ GameLib.D3.Texture.Cube.prototype.updateInstance = function(property) { } this.publish( - GameLib.Event.TEXTURE_INSTANCE_UPDATED, + R3.Event.TEXTURE_INSTANCE_UPDATED, { texture : this } @@ -116,22 +116,22 @@ GameLib.D3.Texture.Cube.prototype.updateInstance = function(property) { return; } - GameLib.D3.Texture.prototype.updateInstance.call(this, property); + R3.D3.Texture.prototype.updateInstance.call(this, property); }; /** - * Converts a GameLib.D3.Texture.Cube to a GameLib.D3.API.Texture.Cube - * @returns {GameLib.D3.API.Texture.Cube} + * Converts a R3.D3.Texture.Cube to a R3.D3.API.Texture.Cube + * @returns {R3.D3.API.Texture.Cube} */ -GameLib.D3.Texture.Cube.prototype.toApiObject = function() { +R3.D3.Texture.Cube.prototype.toApiObject = function() { - var apiTexture = GameLib.D3.Texture.prototype.toApiObject.call(this); + var apiTexture = R3.D3.Texture.prototype.toApiObject.call(this); - var apiTextureCube = new GameLib.D3.API.Texture.Cube( + var apiTextureCube = new R3.D3.API.Texture.Cube( apiTexture, this.images.map( function(image) { - return GameLib.Utils.IdOrNull(image); + return R3.Utils.IdOrNull(image); } ) ); diff --git a/src/game-lib-d3-texture-image.js b/src/r3-d3-texture-image.js similarity index 52% rename from src/game-lib-d3-texture-image.js rename to src/r3-d3-texture-image.js index 9c8dd3b..b22543e 100644 --- a/src/game-lib-d3-texture-image.js +++ b/src/r3-d3-texture-image.js @@ -1,11 +1,11 @@ /** - * GameLib.D3.Texture.Image + * R3.D3.Texture.Image * @param graphics * @param apiTextureImage * @param overrideInstance - if we pass an instance to the constructor, we want to skip the construction of this texture * @constructor */ -GameLib.D3.Texture.Image = function( +R3.D3.Texture.Image = function( graphics, apiTextureImage, overrideInstance @@ -13,30 +13,30 @@ GameLib.D3.Texture.Image = function( this.graphics = graphics; this.graphics.isNotThreeThrow(); - if (GameLib.Utils.UndefinedOrNull(apiTextureImage)) { + if (R3.Utils.UndefinedOrNull(apiTextureImage)) { apiTextureImage = { - textureType : GameLib.D3.API.Texture.TEXTURE_TYPE_IMAGE + textureType : R3.D3.API.Texture.TEXTURE_TYPE_IMAGE }; } - if (GameLib.Utils.UndefinedOrNull(overrideInstance)) { + if (R3.Utils.UndefinedOrNull(overrideInstance)) { overrideInstance = null; } this.overrideInstance = overrideInstance; - GameLib.D3.API.Texture.Image.call( + R3.D3.API.Texture.Image.call( this, apiTextureImage, apiTextureImage.image ); - if (this.image instanceof GameLib.API.Image) { - this.image = new GameLib.Image( + if (this.image instanceof R3.API.Image) { + this.image = new R3.Image( this.image ); } - GameLib.D3.Texture.call( + R3.D3.Texture.call( this, this.graphics, this @@ -44,18 +44,18 @@ GameLib.D3.Texture.Image = function( }; -GameLib.D3.Texture.Image.prototype = Object.create(GameLib.D3.Texture.prototype); -GameLib.D3.Texture.Image.prototype.constructor = GameLib.D3.Texture.Image; +R3.D3.Texture.Image.prototype = Object.create(R3.D3.Texture.prototype); +R3.D3.Texture.Image.prototype.constructor = R3.D3.Texture.Image; /** * Creates an instance of our texture object * @returns {*} */ -GameLib.D3.Texture.Image.prototype.createInstance = function() { +R3.D3.Texture.Image.prototype.createInstance = function() { if ( - GameLib.Utils.UndefinedOrNull(this.image) || - GameLib.Utils.UndefinedOrNull(this.image.instance) + R3.Utils.UndefinedOrNull(this.image) || + R3.Utils.UndefinedOrNull(this.image.instance) ) { console.warn('image not ready at time of texture create instance'); return; @@ -78,13 +78,13 @@ GameLib.D3.Texture.Image.prototype.createInstance = function() { } - GameLib.D3.Texture.prototype.createInstance.call(this); + R3.D3.Texture.prototype.createInstance.call(this); }; /** * Updates the instance with the current state */ -GameLib.D3.Texture.Image.prototype.updateInstance = function(property) { +R3.D3.Texture.Image.prototype.updateInstance = function(property) { if (property === 'image') { @@ -94,7 +94,7 @@ GameLib.D3.Texture.Image.prototype.updateInstance = function(property) { } this.publish( - GameLib.Event.TEXTURE_INSTANCE_UPDATED, + R3.Event.TEXTURE_INSTANCE_UPDATED, { texture : this } @@ -103,29 +103,29 @@ GameLib.D3.Texture.Image.prototype.updateInstance = function(property) { return; } - GameLib.D3.Texture.prototype.updateInstance.call(this, property); + R3.D3.Texture.prototype.updateInstance.call(this, property); }; /** - * Converts a GameLib.D3.Texture.Image to a GameLib.D3.API.Texture.Image - * @returns {GameLib.D3.API.Texture.Image} + * Converts a R3.D3.Texture.Image to a R3.D3.API.Texture.Image + * @returns {R3.D3.API.Texture.Image} */ -GameLib.D3.Texture.Image.prototype.toApiObject = function() { +R3.D3.Texture.Image.prototype.toApiObject = function() { - var apiTexture = GameLib.D3.Texture.prototype.toApiObject.call(this); + var apiTexture = R3.D3.Texture.prototype.toApiObject.call(this); - var apiTextureImage = new GameLib.D3.API.Texture.Image( + var apiTextureImage = new R3.D3.API.Texture.Image( apiTexture, - GameLib.Utils.IdOrNull(this.image) + R3.Utils.IdOrNull(this.image) ); return apiTextureImage; }; /** - * Updates GameLib.D3.Texture.Image from instance + * Updates R3.D3.Texture.Image from instance */ -GameLib.D3.Texture.Image.prototype.updateFromInstance = function() { +R3.D3.Texture.Image.prototype.updateFromInstance = function() { this.image.instance = this.instance.image; @@ -133,6 +133,6 @@ GameLib.D3.Texture.Image.prototype.updateFromInstance = function() { this.image.updateFromInstance(); } - GameLib.D3.Texture.prototype.updateFromInstance.call(this); + R3.D3.Texture.prototype.updateFromInstance.call(this); }; \ No newline at end of file diff --git a/src/game-lib-d3-triangle-edge.js b/src/r3-d3-triangle-edge.js similarity index 80% rename from src/game-lib-d3-triangle-edge.js rename to src/r3-d3-triangle-edge.js index 5aecd92..7d6257a 100644 --- a/src/game-lib-d3-triangle-edge.js +++ b/src/r3-d3-triangle-edge.js @@ -4,7 +4,7 @@ * @param edge * @constructor */ -GameLib.D3.TriangleEdge = function( +R3.D3.TriangleEdge = function( triangle, edge ) { diff --git a/src/game-lib-d3-vertex.js b/src/r3-d3-vertex.js similarity index 57% rename from src/game-lib-d3-vertex.js rename to src/r3-d3-vertex.js index d4b3be5..18912ac 100644 --- a/src/game-lib-d3-vertex.js +++ b/src/r3-d3-vertex.js @@ -1,27 +1,27 @@ /** - * GameLib.D3.Vertex + * R3.D3.Vertex * @param implementation * @param apiVertex * @constructor */ -GameLib.D3.Vertex = function Vertex( +R3.D3.Vertex = function Vertex( implementation, apiVertex ) { this.implementation = implementation; this.implementation.isNotThreeThrow(); - if (GameLib.Utils.UndefinedOrNull(apiVertex)) { + if (R3.Utils.UndefinedOrNull(apiVertex)) { apiVertex = {}; } - GameLib.D3.API.Vertex.call( + R3.D3.API.Vertex.call( this, apiVertex.position, apiVertex.boneWeights ); - this.position = new GameLib.Vector3( + this.position = new R3.Vector3( this.implementation, this.position, this @@ -29,7 +29,7 @@ GameLib.D3.Vertex = function Vertex( this.boneWeights = this.boneWeights.map( function(boneWeight) { - return new GameLib.Vector4( + return new R3.Vector4( this.graphics, boneWeight ) @@ -38,16 +38,16 @@ GameLib.D3.Vertex = function Vertex( }; -GameLib.D3.Vertex.prototype = Object.create(GameLib.Component.prototype); -GameLib.D3.Vertex.prototype.constructor = GameLib.D3.Vertex; +R3.D3.Vertex.prototype = Object.create(R3.Component.prototype); +R3.D3.Vertex.prototype.constructor = R3.D3.Vertex; /** - * Converts a GameLib.D3.Vertex to GameLib.D3.API.Vertex - * @returns {GameLib.D3.API.Vertex} + * Converts a R3.D3.Vertex to R3.D3.API.Vertex + * @returns {R3.D3.API.Vertex} */ -GameLib.D3.Vertex.prototype.toApiObject = function() { +R3.D3.Vertex.prototype.toApiObject = function() { - return new GameLib.D3.API.Vertex( + return new R3.D3.API.Vertex( this.position.toApiObject(), this.boneWeights.map( function(boneWeight){ diff --git a/src/game-lib-d3-viewport.js b/src/r3-d3-viewport.js similarity index 54% rename from src/game-lib-d3-viewport.js rename to src/r3-d3-viewport.js index dfa21bd..35e7980 100644 --- a/src/game-lib-d3-viewport.js +++ b/src/r3-d3-viewport.js @@ -1,10 +1,10 @@ /** * Viewport Runtime - * @param graphics GameLib.GraphicsRuntime - * @param apiViewport GameLib.D3.API.Viewport + * @param graphics R3.GraphicsRuntime + * @param apiViewport R3.D3.API.Viewport * @constructor */ -GameLib.D3.Viewport = function ( +R3.D3.Viewport = function ( graphics, apiViewport ) { @@ -12,11 +12,11 @@ GameLib.D3.Viewport = function ( this.graphics = graphics; this.graphics.isNotThreeThrow(); - if (GameLib.Utils.UndefinedOrNull(apiViewport)) { + if (R3.Utils.UndefinedOrNull(apiViewport)) { apiViewport = {}; } - GameLib.D3.API.Viewport.call( + R3.D3.API.Viewport.call( this, apiViewport.id, apiViewport.name, @@ -27,17 +27,17 @@ GameLib.D3.Viewport = function ( apiViewport.parentEntity ); - GameLib.Component.call(this); + R3.Component.call(this); }; -GameLib.D3.Viewport.prototype = Object.create(GameLib.Component.prototype); -GameLib.D3.Viewport.prototype.constructor = GameLib.D3.Viewport; +R3.D3.Viewport.prototype = Object.create(R3.Component.prototype); +R3.D3.Viewport.prototype.constructor = R3.D3.Viewport; /** * * @returns {boolean} */ -GameLib.D3.Viewport.prototype.createInstance = function() { +R3.D3.Viewport.prototype.createInstance = function() { this.instance = new THREE.Vector4( this.x, @@ -46,13 +46,13 @@ GameLib.D3.Viewport.prototype.createInstance = function() { this.height ); - GameLib.Component.prototype.createInstance.call(this); + R3.Component.prototype.createInstance.call(this); }; /** * */ -GameLib.D3.Viewport.prototype.updateInstance = function(property) { +R3.D3.Viewport.prototype.updateInstance = function(property) { if ( property === 'x' || @@ -69,19 +69,19 @@ GameLib.D3.Viewport.prototype.updateInstance = function(property) { }; /** - * GameLib.D3.Viewport to GameLib.D3.API.Viewport - * @returns {GameLib.D3.API.Viewport} + * R3.D3.Viewport to R3.D3.API.Viewport + * @returns {R3.D3.API.Viewport} */ -GameLib.D3.Viewport.prototype.toApiObject = function() { +R3.D3.Viewport.prototype.toApiObject = function() { - var apiViewport = new GameLib.D3.API.Viewport( + var apiViewport = new R3.D3.API.Viewport( this.id, this.name, this.width, this.height, this.x, this.y, - GameLib.Utils.IdOrNull(this.parentEntity) + R3.Utils.IdOrNull(this.parentEntity) ); return apiViewport; diff --git a/src/game-lib-dom-element.js b/src/r3-dom-element.js similarity index 58% rename from src/game-lib-dom-element.js rename to src/r3-dom-element.js index 67e2298..cf6c68a 100644 --- a/src/game-lib-dom-element.js +++ b/src/r3-dom-element.js @@ -1,15 +1,15 @@ /** * Runtime domElement for updating instance objects - * @param apiDomElement GameLib.API.DomElement + * @param apiDomElement R3.API.DomElement * @constructor */ -GameLib.DomElement = function (apiDomElement) { +R3.DomElement = function (apiDomElement) { - if (GameLib.Utils.UndefinedOrNull(apiDomElement)) { + if (R3.Utils.UndefinedOrNull(apiDomElement)) { apiDomElement = {}; } - GameLib.API.DomElement.call( + R3.API.DomElement.call( this, apiDomElement.id, apiDomElement.name, @@ -19,42 +19,42 @@ GameLib.DomElement = function (apiDomElement) { this.fullscreen = false; - GameLib.Component.call(this); + R3.Component.call(this); }; -GameLib.DomElement.prototype = Object.create(GameLib.Component.prototype); -GameLib.DomElement.prototype.constructor = GameLib.DomElement; +R3.DomElement.prototype = Object.create(R3.Component.prototype); +R3.DomElement.prototype.constructor = R3.DomElement; /** * Creates an instance domElement * @returns {*} */ -GameLib.DomElement.prototype.createInstance = function() { +R3.DomElement.prototype.createInstance = function() { this.instance = document.getElementById(this.domElementId); - GameLib.Component.prototype.createInstance.call(this); + R3.Component.prototype.createInstance.call(this); }; /** * Updates instance domElement */ -GameLib.DomElement.prototype.updateInstance = function(property) { +R3.DomElement.prototype.updateInstance = function(property) { if (property === 'domElementId') { this.createInstance() } - GameLib.Component.prototype.updateInstance.call(this, property); + R3.Component.prototype.updateInstance.call(this, property); }; /** * Converts runtime DomElement to API DomElement - * @returns {GameLib.API.DomElement} + * @returns {R3.API.DomElement} */ -GameLib.DomElement.prototype.toApiObject = function() { - return new GameLib.API.DomElement( +R3.DomElement.prototype.toApiObject = function() { + return new R3.API.DomElement( this.id, this.name, this.domElementId, - GameLib.Utils.IdOrNull(this.parentEntity) + R3.Utils.IdOrNull(this.parentEntity) ); }; @@ -62,19 +62,19 @@ GameLib.DomElement.prototype.toApiObject = function() { * Appends domInstance to DOM instance * @param domInstance */ -GameLib.DomElement.prototype.append = function(domInstance) { +R3.DomElement.prototype.append = function(domInstance) { this.instance.appendChild(domInstance); }; /** * Clears DOM instance */ -GameLib.DomElement.prototype.clear = function() { +R3.DomElement.prototype.clear = function() { this.instance.innerHTML = ''; }; -GameLib.DomElement.prototype.requestFullscreen = function(event) { +R3.DomElement.prototype.requestFullscreen = function(event) { var docEl = document.documentElement; @@ -92,7 +92,7 @@ GameLib.DomElement.prototype.requestFullscreen = function(event) { }; -GameLib.DomElement.prototype.exitFullscreen = function(event) { +R3.DomElement.prototype.exitFullscreen = function(event) { if (document.exitFullscreen) { document.exitFullscreen(); @@ -107,11 +107,11 @@ GameLib.DomElement.prototype.exitFullscreen = function(event) { this.fullscreen = false; }; -GameLib.DomElement.FromObject = function(objectDom) { +R3.DomElement.FromObject = function(objectDom) { - var apiDomElement = GameLib.API.DomElement.FromObject(objectDom); + var apiDomElement = R3.API.DomElement.FromObject(objectDom); - var domElement = new GameLib.DomElement( + var domElement = new R3.DomElement( apiDomElement ); diff --git a/src/game-lib-draw-range.js b/src/r3-draw-range.js similarity index 58% rename from src/game-lib-draw-range.js rename to src/r3-draw-range.js index f721328..1075c17 100644 --- a/src/game-lib-draw-range.js +++ b/src/r3-draw-range.js @@ -1,11 +1,11 @@ /** - * GameLib.DrawRange + * R3.DrawRange * @param implementation * @param apiDrawRange * @param parentGeometry * @constructor */ -GameLib.DrawRange = function ( +R3.DrawRange = function ( implementation, apiDrawRange, parentGeometry @@ -14,11 +14,11 @@ GameLib.DrawRange = function ( this.implementation = implementation; this.implementation.isNotThreeThrow(); - if (GameLib.Utils.UndefinedOrNull(apiDrawRange)) { + if (R3.Utils.UndefinedOrNull(apiDrawRange)) { apiDrawRange = {}; } - if (GameLib.Utils.UndefinedOrNull(parentGeometry)) { + if (R3.Utils.UndefinedOrNull(parentGeometry)) { parentGeometry = null; } this.parentGeometry = parentGeometry; @@ -30,7 +30,7 @@ GameLib.DrawRange = function ( apiDrawRange.count = Infinity; } - GameLib.API.DrawRange.call( + R3.API.DrawRange.call( this, apiDrawRange.id, apiDrawRange.name, @@ -42,14 +42,14 @@ GameLib.DrawRange = function ( this.createInstance(); }; -GameLib.DrawRange.prototype = Object.create(GameLib.Component.prototype); -GameLib.DrawRange.prototype.constructor = GameLib.DrawRange; +R3.DrawRange.prototype = Object.create(R3.Component.prototype); +R3.DrawRange.prototype.constructor = R3.DrawRange; /** - * Creates an instance GameLib.DrawRange + * Creates an instance R3.DrawRange * @returns {*} */ -GameLib.DrawRange.prototype.createInstance = function() { +R3.DrawRange.prototype.createInstance = function() { this.instance = { start : this.start, @@ -59,10 +59,10 @@ GameLib.DrawRange.prototype.createInstance = function() { }; /** - * Updates GameLib.DrawRange instance + * Updates R3.DrawRange instance * @param property */ -GameLib.DrawRange.prototype.updateInstance = function(property) { +R3.DrawRange.prototype.updateInstance = function(property) { console.warn('update the geometry instead'); @@ -75,14 +75,14 @@ GameLib.DrawRange.prototype.updateInstance = function(property) { }; /** - * GameLib.DrawRange to GameLib.API.DrawRange - * @returns {GameLib.API.DrawRange} + * R3.DrawRange to R3.API.DrawRange + * @returns {R3.API.DrawRange} */ -GameLib.DrawRange.prototype.toApiObject = function() { - return new GameLib.API.DrawRange( +R3.DrawRange.prototype.toApiObject = function() { + return new R3.API.DrawRange( this.id, this.name, - GameLib.Utils.IdOrNull(this.parentEntity), + R3.Utils.IdOrNull(this.parentEntity), this.start, this.count ); diff --git a/src/game-lib-entity-manager.js b/src/r3-entity-manager.js similarity index 61% rename from src/game-lib-entity-manager.js rename to src/r3-entity-manager.js index 1867f47..d98ae1c 100644 --- a/src/game-lib-entity-manager.js +++ b/src/r3-entity-manager.js @@ -1,14 +1,14 @@ /** - * GameLib.EntityManager + * R3.EntityManager * @constructor */ -GameLib.EntityManager = function(apiEntityManager) { +R3.EntityManager = function(apiEntityManager) { - if (GameLib.Utils.UndefinedOrNull(apiEntityManager)) { + if (R3.Utils.UndefinedOrNull(apiEntityManager)) { apiEntityManager = {}; } - GameLib.API.EntityManager.call( + R3.API.EntityManager.call( this, apiEntityManager.id, apiEntityManager.name, @@ -26,66 +26,66 @@ GameLib.EntityManager = function(apiEntityManager) { this.idRegister = {}; - GameLib.Event.Subscribe( - GameLib.Event.COMPONENT_REGISTER, + R3.Event.Subscribe( + R3.Event.COMPONENT_REGISTER, this.registerComponent.bind(this) ); - GameLib.Event.Subscribe( - GameLib.Event.INSTANCE_CREATED, + R3.Event.Subscribe( + R3.Event.INSTANCE_CREATED, this.instanceCreated.bind(this) ); - GameLib.Event.Subscribe( - GameLib.Event.REMOVE_COMPONENT, + R3.Event.Subscribe( + R3.Event.REMOVE_COMPONENT, this.removeComponent.bind(this) ); - GameLib.Event.Subscribe( - GameLib.Event.ENTITY_LOADED, + R3.Event.Subscribe( + R3.Event.ENTITY_LOADED, this.entityLoaded.bind(this) ); - GameLib.Component.call( + R3.Component.call( this, { - 'entities' : [GameLib.Entity], - 'defaultEntity' : GameLib.Entity + 'entities' : [R3.Entity], + 'defaultEntity' : R3.Entity } ); }; -GameLib.EntityManager.prototype = Object.create(GameLib.Component.prototype); -GameLib.EntityManager.prototype.constructor = GameLib.EntityManager; +R3.EntityManager.prototype = Object.create(R3.Component.prototype); +R3.EntityManager.prototype.constructor = R3.EntityManager; -GameLib.EntityManager.prototype.createInstance = function() { - this.instance = GameLib.EntityManager.Instance; - GameLib.Component.prototype.createInstance.call(this); +R3.EntityManager.prototype.createInstance = function() { + this.instance = R3.EntityManager.Instance; + R3.Component.prototype.createInstance.call(this); }; -GameLib.EntityManager.prototype.updateInstance = function() { +R3.EntityManager.prototype.updateInstance = function() { console.log('todo: entitymanager updateInstance()') }; -GameLib.EntityManager.prototype.instanceCreated = function(data) { - if (data.component instanceof GameLib.Entity) { +R3.EntityManager.prototype.instanceCreated = function(data) { + if (data.component instanceof R3.Entity) { this.addEntity(data.component); } }; -GameLib.EntityManager.prototype.entityLoaded = function(data) { +R3.EntityManager.prototype.entityLoaded = function(data) { this.defaultEntity = data.entity; }; -GameLib.EntityManager.prototype.registerComponent = function(data) { +R3.EntityManager.prototype.registerComponent = function(data) { var updated = false; - if (GameLib.Utils.UndefinedOrNull(this.register[data.component.componentType])) { + if (R3.Utils.UndefinedOrNull(this.register[data.component.componentType])) { this.register[data.component.componentType] = {}; - GameLib.Event.Emit( - GameLib.Event.COMPONENT_TYPES_UPDATE, + R3.Event.Emit( + R3.Event.COMPONENT_TYPES_UPDATE, { componentType : data.component.componentType, componentTypes : Object.keys(this.register) @@ -94,19 +94,19 @@ GameLib.EntityManager.prototype.registerComponent = function(data) { updated = true; } - if (GameLib.Utils.UndefinedOrNull(this.register[data.component.componentType][data.component.id])) { + if (R3.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])) { + if (R3.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, + R3.Event.Emit( + R3.Event.REGISTER_UPDATE, { componentType : data.component.componentType, components : this.register[data.component.componentType], @@ -117,23 +117,23 @@ GameLib.EntityManager.prototype.registerComponent = function(data) { } }; -GameLib.EntityManager.prototype.removeComponent = function(data) { +R3.EntityManager.prototype.removeComponent = function(data) { var updated = true; - 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]) + if (R3.Utils.UndefinedOrNull(this.register[data.component.componentType]) || + R3.Utils.UndefinedOrNull(this.register[data.component.componentType][data.component.id]) || + R3.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]; - if (GameLib.Utils.IsEmpty(this.register[data.component.componentType])) { + if (R3.Utils.IsEmpty(this.register[data.component.componentType])) { delete this.register[data.component.componentType]; - GameLib.Event.Emit( - GameLib.Event.COMPONENT_TYPES_UPDATE, + R3.Event.Emit( + R3.Event.COMPONENT_TYPES_UPDATE, { componentType : data.component.componentType, componentTypes : Object.keys(this.register) @@ -145,8 +145,8 @@ GameLib.EntityManager.prototype.removeComponent = function(data) { } if (updated) { - GameLib.Event.Emit( - GameLib.Event.REGISTER_UPDATE, + R3.Event.Emit( + R3.Event.REGISTER_UPDATE, { componentType : data.component.componentType, components : this.register[data.component.componentType], @@ -163,9 +163,9 @@ GameLib.EntityManager.prototype.removeComponent = function(data) { * @param id * @returns {*} */ -GameLib.EntityManager.prototype.findEntityById = function(id) { +R3.EntityManager.prototype.findEntityById = function(id) { - var entity = this.register[GameLib.Component.ENTITY][id]; + var entity = this.register[R3.Component.ENTITY][id]; if (entity) { return entity; @@ -174,11 +174,11 @@ GameLib.EntityManager.prototype.findEntityById = function(id) { return null; }; -GameLib.EntityManager.prototype.findComponentById = function(id) { +R3.EntityManager.prototype.findComponentById = function(id) { return this.idRegister[id]; }; -GameLib.EntityManager.prototype.findComponentByName = function(name) { +R3.EntityManager.prototype.findComponentByName = function(name) { return Object.keys(this.idRegister).reduce( function(result, componentId) { @@ -195,17 +195,17 @@ GameLib.EntityManager.prototype.findComponentByName = function(name) { }; -GameLib.EntityManager.prototype.findHelperByObject = function(object) { +R3.EntityManager.prototype.findHelperByObject = function(object) { - if (typeof this.register[GameLib.Component.HELPER] === 'undefined') { + if (typeof this.register[R3.Component.HELPER] === 'undefined') { return null; } - return Object.keys(this.register[GameLib.Component.HELPER]).reduce( + return Object.keys(this.register[R3.Component.HELPER]).reduce( function(result, helperId) { - if (this.register[GameLib.Component.HELPER][helperId].object === object) { - result = this.register[GameLib.Component.HELPER][helperId]; + if (this.register[R3.Component.HELPER][helperId].object === object) { + result = this.register[R3.Component.HELPER][helperId]; } return result; @@ -215,16 +215,16 @@ GameLib.EntityManager.prototype.findHelperByObject = function(object) { }; -GameLib.EntityManager.prototype.findSceneByObject = function(object) { +R3.EntityManager.prototype.findSceneByObject = function(object) { - return Object.keys(this.register[GameLib.Component.SCENE]).reduce( + return Object.keys(this.register[R3.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 + this.register[R3.Component.SCENE][sceneId].meshes.indexOf(object) !== -1 || + this.register[R3.Component.SCENE][sceneId].lights.indexOf(object) !== -1 ) { - result = this.register[GameLib.Component.SCENE][sceneId]; + result = this.register[R3.Component.SCENE][sceneId]; } return result; @@ -237,9 +237,9 @@ GameLib.EntityManager.prototype.findSceneByObject = function(object) { /** * Adds an entity to this manager - * @param entity GameLib.Entity + * @param entity R3.Entity */ -GameLib.EntityManager.prototype.addEntity = function(entity) { +R3.EntityManager.prototype.addEntity = function(entity) { this.entities.push(entity); }; @@ -248,7 +248,7 @@ GameLib.EntityManager.prototype.addEntity = function(entity) { * @param name * @returns {*} */ -GameLib.EntityManager.prototype.queryByName = function(name) { +R3.EntityManager.prototype.queryByName = function(name) { return this.entities.reduce( function(result, entity){ if (entity.name === name) { @@ -262,10 +262,10 @@ GameLib.EntityManager.prototype.queryByName = function(name) { /** * Removes an entity - do we remove all its components as well? - * @param entity GameLib.D3.Entity + * @param entity R3.D3.Entity * @returns boolean true if successful */ -GameLib.EntityManager.prototype.removeEntity = function(entity) { +R3.EntityManager.prototype.removeEntity = function(entity) { var index = this.entities.indexOf(entity); @@ -280,9 +280,9 @@ GameLib.EntityManager.prototype.removeEntity = function(entity) { /** * Returns all the entities with the following components - * @param components GameLib.Component[] + * @param components R3.Component[] */ -// GameLib.EntityManager.prototype.findEntities = function(components) { +// R3.EntityManager.prototype.findEntities = function(components) { // // var entities = this.entities.reduce( // function(result, entity) { @@ -314,7 +314,7 @@ GameLib.EntityManager.prototype.removeEntity = function(entity) { * More efficient * @param componentTypes (array of component types or a single component type) */ -GameLib.EntityManager.prototype.queryComponents = function(componentTypes) { +R3.EntityManager.prototype.queryComponents = function(componentTypes) { var result = []; @@ -354,7 +354,7 @@ GameLib.EntityManager.prototype.queryComponents = function(componentTypes) { * @param constructors (array of constructors, or a constructor) * @returns {*} */ -GameLib.EntityManager.prototype.queryComponentsByConstructor = function(constructors) { +R3.EntityManager.prototype.queryComponentsByConstructor = function(constructors) { return Object.keys(this.idRegister).reduce( function(result, componentId) { if (constructors instanceof Array) { @@ -381,23 +381,23 @@ GameLib.EntityManager.prototype.queryComponentsByConstructor = function(construc }; /** - * Converts a GameLib.Entity to GameLib.API.Entity - * @returns {GameLib.API.EntityManager} + * Converts a R3.Entity to R3.API.Entity + * @returns {R3.API.EntityManager} */ -GameLib.EntityManager.prototype.toApiObject = function() { +R3.EntityManager.prototype.toApiObject = function() { var apiEntities = this.entities.map( function (entity) { - return GameLib.Utils.IdOrNull(entity); + return R3.Utils.IdOrNull(entity); } ); - var apiEntityManager = new GameLib.API.EntityManager( + var apiEntityManager = new R3.API.EntityManager( this.id, this.name, apiEntities, this.defaultEntity, - GameLib.Utils.IdOrNull(this.parentEntity) + R3.Utils.IdOrNull(this.parentEntity) ); return apiEntityManager; @@ -408,11 +408,11 @@ GameLib.EntityManager.prototype.toApiObject = function() { * @param objectEntityManager Object * @constructor */ -GameLib.EntityManager.FromObject = function(objectEntityManager) { +R3.EntityManager.FromObject = function(objectEntityManager) { - var apiEntityManager = GameLib.API.EntityManager.FromObject(objectEntityManager); + var apiEntityManager = R3.API.EntityManager.FromObject(objectEntityManager); - var entityManager = new GameLib.EntityManager(apiEntityManager); + var entityManager = new R3.EntityManager(apiEntityManager); return entityManager; }; diff --git a/src/game-lib-entity.js b/src/r3-entity.js similarity index 69% rename from src/game-lib-entity.js rename to src/r3-entity.js index a361f0e..f95117b 100644 --- a/src/game-lib-entity.js +++ b/src/r3-entity.js @@ -1,16 +1,16 @@ /** * Runtime Entity - * @param apiEntity GameLib.D3.API.Entity + * @param apiEntity R3.D3.API.Entity * @constructor */ -GameLib.Entity = function ( +R3.Entity = function ( apiEntity ) { - if (GameLib.Utils.UndefinedOrNull(apiEntity)) { + if (R3.Utils.UndefinedOrNull(apiEntity)) { apiEntity = {}; } - GameLib.API.Entity.call( + R3.API.Entity.call( this, apiEntity.id, apiEntity.name, @@ -19,32 +19,32 @@ GameLib.Entity = function ( ); this.instanceCreatedEventSubscription = this.subscribe( - GameLib.Event.INSTANCE_CREATED, + R3.Event.INSTANCE_CREATED, this.instanceCreatedEvent ); this.removeComponentSubscription = this.subscribe( - GameLib.Event.REMOVE_COMPONENT, + R3.Event.REMOVE_COMPONENT, this.removeComponentEvent ); this.idRegister = {}; - GameLib.Component.call( + R3.Component.call( this, { - 'components' : [GameLib.Component] + 'components' : [R3.Component] } ); }; -GameLib.Entity.prototype = Object.create(GameLib.Component.prototype); -GameLib.Entity.prototype.constructor = GameLib.Entity; +R3.Entity.prototype = Object.create(R3.Component.prototype); +R3.Entity.prototype.constructor = R3.Entity; /** * Links a component to its parent entity */ -GameLib.Entity.prototype.instanceCreatedEvent = function(data) { +R3.Entity.prototype.instanceCreatedEvent = function(data) { if (data.component === this) { /** @@ -59,7 +59,7 @@ GameLib.Entity.prototype.instanceCreatedEvent = function(data) { } }; -GameLib.Entity.prototype.removeComponentEvent = function(data) { +R3.Entity.prototype.removeComponentEvent = function(data) { if (data.component === this) { /** @@ -76,7 +76,7 @@ GameLib.Entity.prototype.removeComponentEvent = function(data) { /** * Creates an entity instance */ -GameLib.Entity.prototype.createInstance = function() { +R3.Entity.prototype.createInstance = function() { this.components.map( function(component) { @@ -84,7 +84,7 @@ GameLib.Entity.prototype.createInstance = function() { Object.keys(component.idToObject).map( function(componentId) { - GameLib.Utils.PushUnique(this.components, component.idToObject[componentId]); + R3.Utils.PushUnique(this.components, component.idToObject[componentId]); component.idToObject[componentId].parentEntity = this; }.bind(this) ); @@ -96,14 +96,14 @@ GameLib.Entity.prototype.createInstance = function() { this.instance = true; - GameLib.Component.prototype.createInstance.call(this); + R3.Component.prototype.createInstance.call(this); }; /** * Adds a component to this entity through the instance (should notify the entity manager instance) * @param component */ -GameLib.Entity.prototype.addComponent = function(component) { +R3.Entity.prototype.addComponent = function(component) { component.parentEntity = this; @@ -115,13 +115,13 @@ GameLib.Entity.prototype.addComponent = function(component) { return; } - GameLib.Utils.PushUnique(this.components, component); + R3.Utils.PushUnique(this.components, component); - if (GameLib.Utils.UndefinedOrNull(this.idRegister[component.componentType])) { + if (R3.Utils.UndefinedOrNull(this.idRegister[component.componentType])) { this.idRegister[component.componentType] = []; } - GameLib.Utils.PushUnique(this.idRegister[component.componentType], component); + R3.Utils.PushUnique(this.idRegister[component.componentType], component); component.buildIdToObject(); @@ -136,7 +136,7 @@ GameLib.Entity.prototype.addComponent = function(component) { ); }; -GameLib.Entity.prototype.removeComponent = function(component) { +R3.Entity.prototype.removeComponent = function(component) { component.parentEntity = null; @@ -148,7 +148,7 @@ GameLib.Entity.prototype.removeComponent = function(component) { this.components.splice(index, 1); } - if (GameLib.Utils.UndefinedOrNull(this.idRegister[component.componentType])) { + if (R3.Utils.UndefinedOrNull(this.idRegister[component.componentType])) { console.warn('component type not found in entity register'); } else { @@ -174,7 +174,7 @@ GameLib.Entity.prototype.removeComponent = function(component) { * Returns all components of type 'constructor' - slower than queryComponents * @param constructor */ -GameLib.Entity.prototype.queryComponentsByConstructor = function(constructor) { +R3.Entity.prototype.queryComponentsByConstructor = function(constructor) { var components = this.components.reduce( function(result, component) { @@ -194,7 +194,7 @@ GameLib.Entity.prototype.queryComponentsByConstructor = function(constructor) { * @param componentType * @returns {*} */ -GameLib.Entity.prototype.queryComponents = function(componentType) { +R3.Entity.prototype.queryComponents = function(componentType) { return this.idRegister[componentType] || []; }; @@ -202,7 +202,7 @@ GameLib.Entity.prototype.queryComponents = function(componentType) { * Returns true when this entity has a certain component, false otherwise * @param constructor */ -// GameLib.Entity.prototype.hasComponent = function(constructor) { +// R3.Entity.prototype.hasComponent = function(constructor) { // // var has = this.components.reduce( // function(result, component) { @@ -217,7 +217,7 @@ GameLib.Entity.prototype.queryComponents = function(componentType) { // return has; // }; -GameLib.Entity.prototype.buildIdRegister = function() { +R3.Entity.prototype.buildIdRegister = function() { console.log('updating id register for entity : ' + this.name); this.idRegister = {}; @@ -225,7 +225,7 @@ GameLib.Entity.prototype.buildIdRegister = function() { this.components.map( function(component) { - if (GameLib.Utils.UndefinedOrNull(this.idRegister[component.componentType])) { + if (R3.Utils.UndefinedOrNull(this.idRegister[component.componentType])) { this.idRegister[component.componentType] = []; } @@ -240,7 +240,7 @@ GameLib.Entity.prototype.buildIdRegister = function() { /** * Updates an entity instance */ -GameLib.Entity.prototype.updateInstance = function(property) { +R3.Entity.prototype.updateInstance = function(property) { if (property === 'components') { @@ -249,27 +249,27 @@ GameLib.Entity.prototype.updateInstance = function(property) { return; } - GameLib.Component.prototype.updateInstance.call(this, property); + R3.Component.prototype.updateInstance.call(this, property); }; /** - * Converts a GameLib.Entity to GameLib.API.Entity - * @returns {GameLib.API.Entity} + * Converts a R3.Entity to R3.API.Entity + * @returns {R3.API.Entity} */ -GameLib.Entity.prototype.toApiObject = function() { +R3.Entity.prototype.toApiObject = function() { var apiComponents = this.components.map( function(component) { - return GameLib.Utils.IdOrNull(component); + return R3.Utils.IdOrNull(component); } ); - return new GameLib.API.Entity( + return new R3.API.Entity( this.id, this.name, apiComponents, - GameLib.Utils.IdOrNull(this.parentEntity) + R3.Utils.IdOrNull(this.parentEntity) ); }; @@ -277,10 +277,10 @@ GameLib.Entity.prototype.toApiObject = function() { /** * Cleanup our subscriptions first */ -GameLib.Entity.prototype.remove = function() { +R3.Entity.prototype.remove = function() { this.instanceCreatedEventSubscription.remove(); this.removeComponentSubscription.remove(); - GameLib.Component.prototype.remove.call(this); + R3.Component.prototype.remove.call(this); }; \ No newline at end of file diff --git a/src/r3-graphics-runtime-a.js b/src/r3-graphics-runtime-a.js new file mode 100644 index 0000000..27dfe6e --- /dev/null +++ b/src/r3-graphics-runtime-a.js @@ -0,0 +1,71 @@ +/** + * Graphics + * @constructor + * @param apiGraphics + */ +R3.GraphicsRuntime = function( + apiGraphics +) { + + if (R3.Utils.UndefinedOrNull(apiGraphics)) { + apiGraphics = { + graphicsType : R3.API.GraphicsRuntime.GRAPHICS_TYPE_NONE + }; + } + + R3.API.GraphicsRuntime.call( + this, + apiGraphics.id, + apiGraphics.name, + apiGraphics.graphicsType, + apiGraphics.parentEntity + ); + + R3.Component.call(this); +}; + +R3.GraphicsRuntime.prototype = Object.create(R3.Component.prototype); +R3.GraphicsRuntime.prototype.constructor = R3.GraphicsRuntime; + +R3.GraphicsRuntime.prototype.createInstance = function() { + console.log(this.graphicsType + ' graphics runtime created'); + R3.Component.prototype.createInstance.call(this); +}; + +R3.GraphicsRuntime.prototype.updateInstance = function(property) { + + if (property === 'graphicsType') { + var componentType = R3.API.Renderer.GetComponentType(this.graphicsType); + + this.replace(componentType); + + return; + } + + R3.Component.prototype.updateInstance.call(this, property); +}; + +R3.GraphicsRuntime.prototype.toApiObject = function(property) { + + return new R3.API.GraphicsRuntime( + this.id, + this.name, + this.graphicsType, + R3.Utils.IdOrNull(this.parentEntity) + ); + +}; + +/** + * Logs a warning and throws an error if not cannon + */ +R3.GraphicsRuntime.prototype.isNotThreeThrow = function() { + if (this.instance !== THREE) { + console.error('Only THREE supported'); + throw new Error('Only THREE supported'); + } +}; + +R3.GraphicsRuntime.prototype.isThree = function() { + return (this.instance === THREE); +}; \ No newline at end of file diff --git a/src/game-lib-graphics-runtime-impact.js b/src/r3-graphics-runtime-impact.js similarity index 63% rename from src/game-lib-graphics-runtime-impact.js rename to src/r3-graphics-runtime-impact.js index 2ad1c8d..ee6152f 100644 --- a/src/game-lib-graphics-runtime-impact.js +++ b/src/r3-graphics-runtime-impact.js @@ -1,38 +1,38 @@ /** - * GameLib.GraphicsRuntime.Impact + * R3.GraphicsRuntime.Impact * @param apiGraphicsRuntimeImpact * @constructor */ -GameLib.GraphicsRuntime.Impact = function ( +R3.GraphicsRuntime.Impact = function ( apiGraphicsRuntimeImpact ) { - if (GameLib.Utils.UndefinedOrNull(apiGraphicsRuntimeImpact)) { + if (R3.Utils.UndefinedOrNull(apiGraphicsRuntimeImpact)) { apiGraphicsRuntimeImpact = { - graphicsType : GameLib.API.GraphicsRuntime.GRAPHICS_TYPE_IMPACT_JS + graphicsType : R3.API.GraphicsRuntime.GRAPHICS_TYPE_IMPACT_JS }; } - GameLib.API.GraphicsRuntime.Impact.call( + R3.API.GraphicsRuntime.Impact.call( this, apiGraphicsRuntimeImpact ); - GameLib.GraphicsRuntime.call( + R3.GraphicsRuntime.call( this, this ); }; -GameLib.GraphicsRuntime.Impact.prototype = Object.create(GameLib.GraphicsRuntime.prototype); -GameLib.GraphicsRuntime.Impact.prototype.constructor = GameLib.GraphicsRuntime.Impact; +R3.GraphicsRuntime.Impact.prototype = Object.create(R3.GraphicsRuntime.prototype); +R3.GraphicsRuntime.Impact.prototype.constructor = R3.GraphicsRuntime.Impact; /** - * Create GameLib.GraphicsRuntime.Impact Instance + * Create R3.GraphicsRuntime.Impact Instance * @returns {*} */ -GameLib.GraphicsRuntime.Impact.prototype.createInstance = function() { +R3.GraphicsRuntime.Impact.prototype.createInstance = function() { this.instance = ig; @@ -45,7 +45,7 @@ GameLib.GraphicsRuntime.Impact.prototype.createInstance = function() { this.fps = fps; this.clock = new ig.Timer(); - this.canvas = GameLib.EntityManager.Instance.findComponentById(canvasId).instance; + this.canvas = R3.EntityManager.Instance.findComponentById(canvasId).instance; this.resize( width, height, scale ); this.context = this.canvas.getContext('2d'); @@ -89,26 +89,26 @@ GameLib.GraphicsRuntime.Impact.prototype.createInstance = function() { } }); - GameLib.GraphicsRuntime.prototype.createInstance.call(this); + R3.GraphicsRuntime.prototype.createInstance.call(this); }; /** * Update GraphicsRuntime.Impact Instance */ -GameLib.GraphicsRuntime.Impact.prototype.updateInstance = function(property) { +R3.GraphicsRuntime.Impact.prototype.updateInstance = function(property) { - GameLib.GraphicsRuntime.prototype.updateInstance.call(this, property); + R3.GraphicsRuntime.prototype.updateInstance.call(this, property); }; /** * - * @returns {GameLib.API.GraphicsRuntime.Impact} + * @returns {R3.API.GraphicsRuntime.Impact} */ -GameLib.GraphicsRuntime.Impact.prototype.toApiObject = function() { +R3.GraphicsRuntime.Impact.prototype.toApiObject = function() { - var apiGraphicsRuntime = GameLib.GraphicsRuntime.prototype.toApiObject.call(this); + var apiGraphicsRuntime = R3.GraphicsRuntime.prototype.toApiObject.call(this); - var apiGraphicsRuntimeImpact = new GameLib.API.GraphicsRuntime.Impact( + var apiGraphicsRuntimeImpact = new R3.API.GraphicsRuntime.Impact( apiGraphicsRuntime ); diff --git a/src/r3-graphics-runtime-three.js b/src/r3-graphics-runtime-three.js new file mode 100644 index 0000000..1c49685 --- /dev/null +++ b/src/r3-graphics-runtime-three.js @@ -0,0 +1,63 @@ +/** + * R3.GraphicsRuntime.Three + * @param apiGraphicsRuntimeThree + * @constructor + */ +R3.GraphicsRuntime.Three = function ( + apiGraphicsRuntimeThree +) { + + if (R3.Utils.UndefinedOrNull(apiGraphicsRuntimeThree)) { + apiGraphicsRuntimeThree = { + graphicsType : R3.API.GraphicsRuntime.GRAPHICS_TYPE_THREE_JS + }; + } + + R3.API.GraphicsRuntime.Three.call( + this, + apiGraphicsRuntimeThree + ); + + R3.GraphicsRuntime.call( + this, + this + ); + +}; + +R3.GraphicsRuntime.Three.prototype = Object.create(R3.GraphicsRuntime.prototype); +R3.GraphicsRuntime.Three.prototype.constructor = R3.GraphicsRuntime.Three; + +/** + * Create R3.GraphicsRuntime.Three Instance + * @returns {*} + */ +R3.GraphicsRuntime.Three.prototype.createInstance = function() { + + this.instance = THREE; + + R3.GraphicsRuntime.prototype.createInstance.call(this); +}; + +/** + * Update GraphicsRuntime.Three Instance + */ +R3.GraphicsRuntime.Three.prototype.updateInstance = function(property) { + + R3.GraphicsRuntime.prototype.updateInstance.call(this, property); +}; + +/** + * + * @returns {R3.API.GraphicsRuntime.Three} + */ +R3.GraphicsRuntime.Three.prototype.toApiObject = function() { + + var apiGraphicsRuntime = R3.GraphicsRuntime.prototype.toApiObject.call(this); + + var apiGraphicsRuntimeThree = new R3.API.GraphicsRuntime.Three( + apiGraphicsRuntime + ); + + return apiGraphicsRuntimeThree; +}; diff --git a/src/game-lib-group.js b/src/r3-group.js similarity index 58% rename from src/game-lib-group.js rename to src/r3-group.js index 35a615f..90421ff 100644 --- a/src/game-lib-group.js +++ b/src/r3-group.js @@ -1,11 +1,11 @@ /** - * GameLib.Group + * R3.Group * @param implementation * @param apiGroup * @param parentGeometry * @constructor */ -GameLib.Group = function ( +R3.Group = function ( implementation, apiGroup, parentGeometry @@ -14,16 +14,16 @@ GameLib.Group = function ( this.implementation = implementation; this.implementation.isNotThreeThrow(); - if (GameLib.Utils.UndefinedOrNull(parentGeometry)) { + if (R3.Utils.UndefinedOrNull(parentGeometry)) { parentGeometry = null; } this.parentGeometry = parentGeometry; - if (GameLib.Utils.UndefinedOrNull(apiGroup)) { + if (R3.Utils.UndefinedOrNull(apiGroup)) { apiGroup = {}; } - GameLib.API.Group.call( + R3.API.Group.call( this, apiGroup.id, apiGroup.name, @@ -33,17 +33,17 @@ GameLib.Group = function ( apiGroup.materialIndex ); - GameLib.Component.call(this); + R3.Component.call(this); }; -GameLib.Group.prototype = Object.create(GameLib.Component.prototype); -GameLib.Group.prototype.constructor = GameLib.Group; +R3.Group.prototype = Object.create(R3.Component.prototype); +R3.Group.prototype.constructor = R3.Group; /** - * Creates an instance GameLib.Group + * Creates an instance R3.Group * @returns {*} */ -GameLib.Group.prototype.createInstance = function() { +R3.Group.prototype.createInstance = function() { this.instance = { start : this.start, @@ -51,15 +51,15 @@ GameLib.Group.prototype.createInstance = function() { materialIndex : this.materialIndex }; - GameLib.Component.prototype.createInstance.call(this); + R3.Component.prototype.createInstance.call(this); }; /** - * Updates GameLib.Group instance + * Updates R3.Group instance * @param property */ -GameLib.Group.prototype.updateInstance = function(property) { +R3.Group.prototype.updateInstance = function(property) { console.warn('update the geometry instead'); @@ -78,18 +78,18 @@ GameLib.Group.prototype.updateInstance = function(property) { return; } - GameLib.Component.prototype.updateInstance.call(this, property); + R3.Component.prototype.updateInstance.call(this, property); }; /** - * GameLib.Group to GameLib.API.Group - * @returns {GameLib.API.Group} + * R3.Group to R3.API.Group + * @returns {R3.API.Group} */ -GameLib.Group.prototype.toApiObject = function() { - return new GameLib.API.Group( +R3.Group.prototype.toApiObject = function() { + return new R3.API.Group( this.id, this.name, - GameLib.Utils.IdOrNull(this.parentEntity), + R3.Utils.IdOrNull(this.parentEntity), this.start, this.count, this.materialIndex diff --git a/src/game-lib-gui-runtime.js b/src/r3-gui-runtime.js similarity index 53% rename from src/game-lib-gui-runtime.js rename to src/r3-gui-runtime.js index bd7633c..b964ddc 100644 --- a/src/game-lib-gui-runtime.js +++ b/src/r3-gui-runtime.js @@ -5,23 +5,23 @@ * @param guiType * @constructor */ -GameLib.GUIRuntime = function( +R3.GUIRuntime = function( id, name, guiType ) { - if (GameLib.Utils.UndefinedOrNull(id)) { - id = GameLib.Utils.RandomId(); + if (R3.Utils.UndefinedOrNull(id)) { + id = R3.Utils.RandomId(); } this.id = id; - if (GameLib.Utils.UndefinedOrNull(name)) { + if (R3.Utils.UndefinedOrNull(name)) { name = 'GUI (' + id + ')'; } this.name = name; - if (GameLib.Utils.UndefinedOrNull(guiType)) { - guiType = GameLib.GUIRuntime.TYPE_DAT_GUI; + if (R3.Utils.UndefinedOrNull(guiType)) { + guiType = R3.GUIRuntime.TYPE_DAT_GUI; } this.guiType = guiType; @@ -29,20 +29,20 @@ GameLib.GUIRuntime = function( }; /** - * GameLib.GUIRuntime Types + * R3.GUIRuntime Types * @type {number} */ -GameLib.GUIRuntime.TYPE_DAT_GUI = 0x1; +R3.GUIRuntime.TYPE_DAT_GUI = 0x1; -GameLib.GUIRuntime.prototype.createInstance = function() { - if (this.guiType === GameLib.GUIRuntime.TYPE_DAT_GUI) { +R3.GUIRuntime.prototype.createInstance = function() { + if (this.guiType === R3.GUIRuntime.TYPE_DAT_GUI) { this.instance = dat.GUI; } else { this.instance = null; } }; -GameLib.GUIRuntime.prototype.updateInstance = function(property) { +R3.GUIRuntime.prototype.updateInstance = function(property) { if (property === 'guiType') { this.createInstance(); } @@ -51,7 +51,7 @@ GameLib.GUIRuntime.prototype.updateInstance = function(property) { /** * Logs a warning and throws an error if not cannon */ -GameLib.GUIRuntime.prototype.isNotDatGuiThrow = function() { +R3.GUIRuntime.prototype.isNotDatGuiThrow = function() { if (this.instance !== dat.GUI) { console.error('Only dat.gui supported'); throw new Error('Only dat.gui supported'); diff --git a/src/game-lib-gui.js b/src/r3-gui.js similarity index 50% rename from src/game-lib-gui.js rename to src/r3-gui.js index 5b8b9d0..49d87ae 100644 --- a/src/game-lib-gui.js +++ b/src/r3-gui.js @@ -4,18 +4,18 @@ * @param apiGUI * @constructor */ -GameLib.GUI = function( +R3.GUI = function( guiRuntime, apiGUI ) { this.guiRuntime = guiRuntime; this.guiRuntime.isNotDatGuiThrow(); - if (GameLib.Utils.UndefinedOrNull(apiGUI)) { + if (R3.Utils.UndefinedOrNull(apiGUI)) { apiGUI = {}; } - GameLib.API.GUI.call( + R3.API.GUI.call( this, apiGUI.id, apiGUI.name, @@ -23,59 +23,59 @@ GameLib.GUI = function( apiGUI.parentEntity ); - GameLib.Component.call( + R3.Component.call( this, { - 'domElement': GameLib.DomElement + 'domElement': R3.DomElement } ); }; -GameLib.GUI.prototype = Object.create(GameLib.Component.prototype); -GameLib.GUI.prototype.constructor = GameLib.GUI; +R3.GUI.prototype = Object.create(R3.Component.prototype); +R3.GUI.prototype.constructor = R3.GUI; /** * Creates a helper instance */ -GameLib.GUI.prototype.createInstance = function() { +R3.GUI.prototype.createInstance = function() { this.instance = new this.guiRuntime.instance( { autoPlace: false } ); - GameLib.Component.prototype.createInstance.call(this); + R3.Component.prototype.createInstance.call(this); }; /** * Updates the instance with the current state */ -GameLib.GUI.prototype.updateInstance = function(property) { +R3.GUI.prototype.updateInstance = function(property) { console.log('todo: implement gui update instance:' + property); }; /** - * Converts a GameLib.GUI to a new GameLib.API.GUI - * @returns {GameLib.API.GUI} + * Converts a R3.GUI to a new R3.API.GUI + * @returns {R3.API.GUI} */ -GameLib.GUI.prototype.toApiObject = function() { +R3.GUI.prototype.toApiObject = function() { - return new GameLib.API.GUI( + return new R3.API.GUI( this.id, this.name, - GameLib.Utils.IdOrNull(this.domElement), - GameLib.Utils.IdOrNull(this.parentEntity) + R3.Utils.IdOrNull(this.domElement), + R3.Utils.IdOrNull(this.parentEntity) ); }; /** - * Converts from an Object GUI to a GameLib.GUI - * @param guiRuntime GameLib.GUIRuntime + * Converts from an Object GUI to a R3.GUI + * @param guiRuntime R3.GUIRuntime * @param objectGUI Object - * @returns {GameLib.GUI} + * @returns {R3.GUI} * @constructor */ -GameLib.GUI.FromObject = function(guiRuntime, objectGUI) { +R3.GUI.FromObject = function(guiRuntime, objectGUI) { - var apiGUI = GameLib.API.GUI.FromObject(objectGUI); + var apiGUI = R3.API.GUI.FromObject(objectGUI); - return new GameLib.GUI( + return new R3.GUI( guiRuntime, apiGUI ); @@ -85,14 +85,14 @@ GameLib.GUI.FromObject = function(guiRuntime, objectGUI) { /** * Removes empty folders from instance */ -GameLib.GUI.prototype.removeEmtpyFolders = function() { +R3.GUI.prototype.removeEmtpyFolders = function() { this.instance.removeEmptyFolders(); }; /** * Remove all folders from instance */ -GameLib.GUI.prototype.removeAllFolders = function() { +R3.GUI.prototype.removeAllFolders = function() { this.instance.removeAllFolders(); }; @@ -101,12 +101,12 @@ GameLib.GUI.prototype.removeAllFolders = function() { * @param folderName * @returns {*} */ -GameLib.GUI.prototype.addFolder = function(folderName) { +R3.GUI.prototype.addFolder = function(folderName) { try { return this.instance.addFolder(folderName); } catch (e) { try { - folderName += ' duplicate (' + GameLib.Utils.RandomId() + ')'; + folderName += ' duplicate (' + R3.Utils.RandomId() + ')'; return this.instance.addFolder(folderName); } catch (e) { console.log(e.message); diff --git a/src/game-lib-image.js b/src/r3-image.js similarity index 73% rename from src/game-lib-image.js rename to src/r3-image.js index 8890cf3..03302b4 100644 --- a/src/game-lib-image.js +++ b/src/r3-image.js @@ -3,15 +3,15 @@ * @constructor * @param apiImage */ -GameLib.Image = function( +R3.Image = function( apiImage ) { - if (GameLib.Utils.UndefinedOrNull(apiImage)) { + if (R3.Utils.UndefinedOrNull(apiImage)) { apiImage = {}; } - GameLib.API.Image.call( + R3.API.Image.call( this, apiImage.id, apiImage.name, @@ -26,25 +26,25 @@ GameLib.Image = function( apiImage.height ); - GameLib.Component.call( + R3.Component.call( this, { - parentTexture : GameLib.D3.Texture + parentTexture : R3.D3.Texture } ); }; -GameLib.Image.prototype = Object.create(GameLib.Component.prototype); -GameLib.Image.prototype.constructor = GameLib.Image; +R3.Image.prototype = Object.create(R3.Component.prototype); +R3.Image.prototype.constructor = R3.Image; /** * Creates an image instance * @returns {*} */ -GameLib.Image.prototype.createInstance = function() { +R3.Image.prototype.createInstance = function() { - GameLib.Event.Emit( - GameLib.Event.LOAD_IMAGE, + R3.Event.Emit( + R3.Event.LOAD_IMAGE, { image : this }, @@ -54,12 +54,12 @@ GameLib.Image.prototype.createInstance = function() { this.width = this.instance.width; this.height = this.instance.height; - GameLib.Component.prototype.createInstance.call(this); + R3.Component.prototype.createInstance.call(this); }.bind(this), function(error) { console.error(error); this.instance = null; - GameLib.Component.prototype.createInstance.call(this); + R3.Component.prototype.createInstance.call(this); }.bind(this) ); @@ -68,9 +68,9 @@ GameLib.Image.prototype.createInstance = function() { /** * Updates the instance with the current state */ -GameLib.Image.prototype.updateInstance = function(property) { +R3.Image.prototype.updateInstance = function(property) { - if (GameLib.Utils.UndefinedOrNull(property)) { + if (R3.Utils.UndefinedOrNull(property)) { console.warn('unknown property update for Image: ' + property); } @@ -83,7 +83,7 @@ GameLib.Image.prototype.updateInstance = function(property) { return; } - if (GameLib.Utils.UndefinedOrNull(this.instance)) { + if (R3.Utils.UndefinedOrNull(this.instance)) { console.warn('image not ready yet'); return; } @@ -98,10 +98,10 @@ GameLib.Image.prototype.updateInstance = function(property) { return; } - GameLib.Component.prototype.updateInstance.call(this, property); + R3.Component.prototype.updateInstance.call(this, property); }; -GameLib.Image.prototype.updateFromRawObject = function(rawObject) { +R3.Image.prototype.updateFromRawObject = function(rawObject) { this.id = rawObject.id; this.name = rawObject.name; this.fileName = rawObject.fileName; @@ -115,15 +115,15 @@ GameLib.Image.prototype.updateFromRawObject = function(rawObject) { /** * - * @returns {GameLib.API.Image} + * @returns {R3.API.Image} */ -GameLib.Image.prototype.toApiObject = function() { +R3.Image.prototype.toApiObject = function() { - var apiImage = new GameLib.API.Image( + var apiImage = new R3.API.Image( this.id, this.name, - GameLib.Utils.IdOrNull(this.parentEntity), - GameLib.Utils.IdOrNull(this.parentTexture), + R3.Utils.IdOrNull(this.parentEntity), + R3.Utils.IdOrNull(this.parentTexture), this.fileName, this.extension, this.path, @@ -137,9 +137,9 @@ GameLib.Image.prototype.toApiObject = function() { }; /** - * Updates GameLib.Image from instance + * Updates R3.Image from instance */ -GameLib.Image.prototype.updateFromInstance = function() { +R3.Image.prototype.updateFromInstance = function() { this.fileName = this.instance.fileName || 'no filename'; this.extension = this.instance.extension || 'no extension'; this.path = this.instance.path || 'no path'; @@ -149,7 +149,7 @@ GameLib.Image.prototype.updateFromInstance = function() { this.height = this.instance.height || 0; }; -GameLib.Image.prototype.getPixelData = function() { +R3.Image.prototype.getPixelData = function() { var canvas = document.createElement( 'canvas' ); canvas.width = this.width; @@ -168,9 +168,9 @@ GameLib.Image.prototype.getPixelData = function() { * Returns an array of Height Data for this image * @returns {Float32Array | null} */ -GameLib.Image.prototype.getHeightData = function() { +R3.Image.prototype.getHeightData = function() { - if (GameLib.Utils.UndefinedOrNull(this.instance)) { + if (R3.Utils.UndefinedOrNull(this.instance)) { console.warn('this image is not ready to have its height data processed'); return null; } diff --git a/src/game-lib-matrix-4.js b/src/r3-matrix-4.js similarity index 75% rename from src/game-lib-matrix-4.js rename to src/r3-matrix-4.js index 1fd803e..9ec6eec 100644 --- a/src/game-lib-matrix-4.js +++ b/src/r3-matrix-4.js @@ -6,7 +6,7 @@ * @param grain * @constructor */ -GameLib.Matrix4 = function( +R3.Matrix4 = function( graphics, apiMatrix4, parentObject, @@ -16,11 +16,11 @@ GameLib.Matrix4 = function( this.graphics = graphics; this.graphics.isNotThreeThrow(); - if (GameLib.Utils.UndefinedOrNull(apiMatrix4)) { + if (R3.Utils.UndefinedOrNull(apiMatrix4)) { apiMatrix4 = {}; } - GameLib.API.Matrix4.call( + R3.API.Matrix4.call( this, apiMatrix4.rows[0], apiMatrix4.rows[1], @@ -28,12 +28,12 @@ GameLib.Matrix4 = function( apiMatrix4.rows[3] ); - if (GameLib.Utils.UndefinedOrNull(parentObject)) { + if (R3.Utils.UndefinedOrNull(parentObject)) { parentObject = null; } this.parentObject = parentObject; - if (GameLib.Utils.UndefinedOrNull(grain)) { + if (R3.Utils.UndefinedOrNull(grain)) { grain = 0.001; } this.grain = grain; @@ -41,7 +41,7 @@ GameLib.Matrix4 = function( this.rows = this.rows.map( function(row) { - return new GameLib.Vector4( + return new R3.Vector4( this.graphics, row, this, @@ -51,21 +51,21 @@ GameLib.Matrix4 = function( }.bind(this) ); - this.forward = new GameLib.Vector4( + this.forward = new R3.Vector4( this.graphics, this.forward, this, this.grain ); - this.left = new GameLib.Vector4( + this.left = new R3.Vector4( this.graphics, this.left, this, this.grain ); - this.up = new GameLib.Vector4( + this.up = new R3.Vector4( this.graphics, this.up, this, @@ -75,14 +75,14 @@ GameLib.Matrix4 = function( this.createInstance(); }; -GameLib.Matrix4.prototype = Object.create(GameLib.Component.prototype); -GameLib.Matrix4.prototype.constructor = GameLib.Matrix4; +R3.Matrix4.prototype = Object.create(R3.Component.prototype); +R3.Matrix4.prototype.constructor = R3.Matrix4; /** * Creates a matrix 4 instance (currently from graphics lib) * @param update */ -GameLib.Matrix4.prototype.createInstance = function(update) { +R3.Matrix4.prototype.createInstance = function(update) { this.instance = new THREE.Matrix4(); @@ -113,7 +113,7 @@ GameLib.Matrix4.prototype.createInstance = function(update) { /** * Updates this instance */ -GameLib.Matrix4.prototype.updateInstance = function() { +R3.Matrix4.prototype.updateInstance = function() { this.instance.set( this.rows[0].x, @@ -141,12 +141,12 @@ GameLib.Matrix4.prototype.updateInstance = function() { }; /** - * GameLib.Matrix4 to GameLib.API.Matrix4 + * R3.Matrix4 to R3.API.Matrix4 * @returns {*} */ -GameLib.Matrix4.prototype.toApiObject = function () { +R3.Matrix4.prototype.toApiObject = function () { - return new GameLib.API.Matrix4( + return new R3.API.Matrix4( this.rows[0].toApiObject(), this.rows[1].toApiObject(), this.rows[2].toApiObject(), @@ -156,18 +156,18 @@ GameLib.Matrix4.prototype.toApiObject = function () { }; /** - * Creates a GameLib.Matrix4 from an Object matrix - * @param graphics GameLib.GraphicsRuntime + * Creates a R3.Matrix4 from an Object matrix + * @param graphics R3.GraphicsRuntime * @param objectMatrix Object * @param parentObject - * @returns {GameLib.Matrix4} + * @returns {R3.Matrix4} * @constructor */ -GameLib.Matrix4.FromObject = function(graphics, objectMatrix, parentObject) { +R3.Matrix4.FromObject = function(graphics, objectMatrix, parentObject) { - var apiMatrix = new GameLib.API.Matrix4.FromObject(objectMatrix); + var apiMatrix = new R3.API.Matrix4.FromObject(objectMatrix); - return new GameLib.Matrix4( + return new R3.Matrix4( graphics, parentObject, apiMatrix @@ -179,11 +179,11 @@ GameLib.Matrix4.FromObject = function(graphics, objectMatrix, parentObject) { * @param position * @param target * @param up - * @returns {GameLib.Matrix4} + * @returns {R3.Matrix4} */ -GameLib.Matrix4.prototype.lookAt = function (position, target, up) { +R3.Matrix4.prototype.lookAt = function (position, target, up) { - var pv = new GameLib.API.Vector3(position.x, position.y, position.z); + var pv = new R3.API.Vector3(position.x, position.y, position.z); var forward = pv.subtract(target).normalize(); @@ -232,29 +232,29 @@ GameLib.Matrix4.prototype.lookAt = function (position, target, up) { /** * Identity */ -GameLib.Matrix4.prototype.identity = function () { +R3.Matrix4.prototype.identity = function () { this.rows = [ - new GameLib.Vector4( + new R3.Vector4( this.graphics, - new GameLib.API.Vector4(1,0,0,0), + new R3.API.Vector4(1,0,0,0), this, this.grain ), - new GameLib.Vector4( + new R3.Vector4( this.graphics, - new GameLib.API.Vector4(0,1,0,0), + new R3.API.Vector4(0,1,0,0), this, this.grain ), - new GameLib.Vector4( + new R3.Vector4( this.graphics, - new GameLib.API.Vector4(0,0,1,0), + new R3.API.Vector4(0,0,1,0), this, this.grain ), - new GameLib.Vector4( + new R3.Vector4( this.graphics, - new GameLib.API.Vector4(0,0,0,1), + new R3.API.Vector4(0,0,0,1), this, this.grain ) @@ -263,9 +263,9 @@ GameLib.Matrix4.prototype.identity = function () { /** * Transpose - * @returns {GameLib.Matrix4} + * @returns {R3.Matrix4} */ -GameLib.Matrix4.prototype.transpose = function () { +R3.Matrix4.prototype.transpose = function () { this.temp[0].x = this.rows[0].x; this.temp[0].y = this.rows[1].x; diff --git a/src/r3-mouse.js b/src/r3-mouse.js new file mode 100644 index 0000000..6f7b69f --- /dev/null +++ b/src/r3-mouse.js @@ -0,0 +1,67 @@ +/** + * Runtime Mouse + * @param apiMouse + * @returns {R3.Mouse} + * @constructor + */ +R3.Mouse = function (apiMouse) { + + if (R3.Utils.UndefinedOrNull(apiMouse)){ + apiMouse = {}; + } + + R3.API.Mouse.call( + this, + apiMouse.id, + apiMouse.name, + apiMouse.parentEntity, + apiMouse.x, + apiMouse.y + ); + + R3.Component.call(this); +}; + +R3.Mouse.prototype = Object.create(R3.Component.prototype); +R3.Mouse.prototype.constructor = R3.Mouse; + +/** + * createInstance + */ +R3.Mouse.prototype.createInstance = function() { + this.instance = {}; + R3.Component.prototype.createInstance.call(this); +}; + +/** + * updateInstance + * @param property + */ +R3.Mouse.prototype.updateInstance = function(property) { + + if ( + property === 'x' || + property === 'y' + ) { + this.instance.x = this.x; + this.instance.y = this.y; + return; + } + + R3.Component.prototype.updateInstance.call(this, property); + +}; + +/** + * Converts R3.Mouse vector to R3.API.Mouse + * @returns {R3.API.Mouse} + */ +R3.Mouse.prototype.toApiObject = function() { + return new R3.API.Mouse( + this.id, + this.name, + R3.Utils.IdOrNull(this.parentEntity), + this.x, + this.y + ); +}; diff --git a/src/game-lib-number.js b/src/r3-number.js similarity index 64% rename from src/game-lib-number.js rename to src/r3-number.js index d26abb8..b057fde 100644 --- a/src/game-lib-number.js +++ b/src/r3-number.js @@ -1,24 +1,24 @@ /** * Runtime vector2 for updating instance objects - * @param apiNumber GameLib.API.Number + * @param apiNumber R3.API.Number * @param parentObject * @constructor */ -GameLib.Number = function ( +R3.Number = function ( apiNumber, parentObject ) { - if (GameLib.Utils.UndefinedOrNull(apiNumber)) { + if (R3.Utils.UndefinedOrNull(apiNumber)) { apiNumber = {}; } - GameLib.API.Number.call( + R3.API.Number.call( this, apiNumber ); - if (GameLib.Utils.UndefinedOrNull(parentObject)) { + if (R3.Utils.UndefinedOrNull(parentObject)) { parentObject = null; } this.parentObject = parentObject; @@ -26,22 +26,22 @@ GameLib.Number = function ( this.createInstance(); }; -GameLib.Number.prototype = Object.create(GameLib.API.Number.prototype); -GameLib.Number.prototype.constructor = GameLib.Number; +R3.Number.prototype = Object.create(R3.API.Number.prototype); +R3.Number.prototype.constructor = R3.Number; /** * Creates an instance vector2 * @returns {*} */ -GameLib.Number.prototype.createInstance = function() { +R3.Number.prototype.createInstance = function() { this.instance = {}; }; /** * Updates the instance vector, calls updateInstance on the parent object */ -GameLib.Number.prototype.updateInstance = function(property, parentProperty) { +R3.Number.prototype.updateInstance = function(property, parentProperty) { if (property === 'value') { if (this.parentObject && this.parentObject.updateInstance) { @@ -64,10 +64,10 @@ GameLib.Number.prototype.updateInstance = function(property, parentProperty) { /** * Converts runtime vector to API Vector - * @returns {GameLib.API.Number} + * @returns {R3.API.Number} */ -GameLib.Number.prototype.toApiObject = function() { - return new GameLib.API.Number( +R3.Number.prototype.toApiObject = function() { + return new R3.API.Number( this.value, this.grain, this.min, diff --git a/src/game-lib-physics-runtime.js b/src/r3-physics-runtime.js similarity index 52% rename from src/game-lib-physics-runtime.js rename to src/r3-physics-runtime.js index 8d1a9b9..f2fb777 100644 --- a/src/game-lib-physics-runtime.js +++ b/src/r3-physics-runtime.js @@ -5,23 +5,23 @@ * @param physicsType * @constructor */ -GameLib.PhysicsRuntime = function( +R3.PhysicsRuntime = function( id, name, physicsType ) { - if (GameLib.Utils.UndefinedOrNull(id)) { - id = GameLib.Utils.RandomId(); + if (R3.Utils.UndefinedOrNull(id)) { + id = R3.Utils.RandomId(); } this.id = id; - if (GameLib.Utils.UndefinedOrNull(name)) { + if (R3.Utils.UndefinedOrNull(name)) { name = 'Physics (' + id + ')'; } this.name = name; - if (GameLib.Utils.UndefinedOrNull(physicsType)) { - physicsType = GameLib.PhysicsRuntime.TYPE_CANNON_JS; + if (R3.Utils.UndefinedOrNull(physicsType)) { + physicsType = R3.PhysicsRuntime.TYPE_CANNON_JS; } this.physicsType = physicsType; @@ -29,20 +29,20 @@ GameLib.PhysicsRuntime = function( }; /** - * GameLib.PhysicsRuntime Types + * R3.PhysicsRuntime Types * @type {number} */ -GameLib.PhysicsRuntime.TYPE_CANNON_JS = 0x1; +R3.PhysicsRuntime.TYPE_CANNON_JS = 0x1; -GameLib.PhysicsRuntime.prototype.createInstance = function() { - if (this.physicsType === GameLib.PhysicsRuntime.TYPE_CANNON_JS) { +R3.PhysicsRuntime.prototype.createInstance = function() { + if (this.physicsType === R3.PhysicsRuntime.TYPE_CANNON_JS) { this.instance = CANNON; } else { this.instance = null; } }; -GameLib.PhysicsRuntime.prototype.updateInstance = function(property) { +R3.PhysicsRuntime.prototype.updateInstance = function(property) { if (property === 'physicsType') { this.createInstance(); } @@ -51,7 +51,7 @@ GameLib.PhysicsRuntime.prototype.updateInstance = function(property) { /** * Logs a warning and throws an error if not cannon */ -GameLib.PhysicsRuntime.prototype.isNotCannonThrow = function() { +R3.PhysicsRuntime.prototype.isNotCannonThrow = function() { if (this.instance !== CANNON) { console.error('Only CANNON supported'); throw new Error('Only CANNON supported'); diff --git a/src/r3-plane.js b/src/r3-plane.js new file mode 100644 index 0000000..4e737bb --- /dev/null +++ b/src/r3-plane.js @@ -0,0 +1,101 @@ +/** + * Creates a Plane object + * @param graphics R3.GraphicsRuntime + * @param apiPlane R3.API.Plane + * @constructor + */ +R3.Plane = function( + graphics, + apiPlane +) { + + this.graphics = graphics; + this.graphics.isNotThreeThrow(); + + if (R3.Utils.UndefinedOrNull(apiPlane)) { + apiPlane = {}; + } + + R3.API.Plane.call( + this, + apiPlane.id, + apiPlane.name, + apiPlane.normal, + apiPlane.constant, + apiPlane.parentEntity + ); + + this.normal = new R3.Vector3( + this.graphics, + this.normal, + this + ); + + R3.Component.call(this); +}; + +R3.Plane.prototype = Object.create(R3.Component.prototype); +R3.Plane.prototype.constructor = R3.Plane; + +R3.Plane.prototype.createInstance = function() { + + this.instance = new THREE.Plane( + this.normal.instance, + this.constant + ); + + R3.Component.prototype.createInstance.call(this); +}; + +/** + * Updates the instance with the current state + */ +R3.Plane.prototype.updateInstance = function(property) { + + if (property === 'normal') { + + this.normal.normalize(); + + this.instance.normal.x = this.normal.x; + this.instance.normal.y = this.normal.y; + this.instance.normal.z = this.normal.z; + } + + if (property === 'constant') { + this.instance.constant = this.constant; + } + + R3.D3.Texture.prototype.updateInstance.call(this, property); + +}; + +/** + * Converts a R3.Plane to a new R3.API.Plane + * @returns {R3.API.Plane} + */ +R3.Plane.prototype.toApiObject = function() { + + return new R3.API.Plane( + this.id, + this.name, + this.normal.toApiObject(), + this.constant, + R3.Utils.IdOrNull(this.parentEntity) + ); + +}; + +/** + * Converts from an Object Plane to a R3.Plane + * @param graphics R3.GraphicsRuntime + * @param objectPlane Object + * @returns {R3.Plane} + * @constructor + */ +R3.Plane.FromObject = function(graphics, objectPlane) { + var apiPlane = R3.API.Plane.FromObject(objectPlane); + return new R3.Plane( + graphics, + apiPlane + ); +}; diff --git a/src/game-lib-quaternion.js b/src/r3-quaternion.js similarity index 70% rename from src/game-lib-quaternion.js rename to src/r3-quaternion.js index fb648e5..abcae2a 100644 --- a/src/game-lib-quaternion.js +++ b/src/r3-quaternion.js @@ -1,12 +1,12 @@ /** * Runtime quaternion for updating instance objects * @param implementation - * @param parentObject GameLib.D3.* - * @param apiQuaternion GameLib.API.Quaternion + * @param parentObject R3.D3.* + * @param apiQuaternion R3.API.Quaternion * @param grain Number * @constructor */ -GameLib.Quaternion = function ( +R3.Quaternion = function ( implementation, apiQuaternion, parentObject, @@ -14,11 +14,11 @@ GameLib.Quaternion = function ( ) { this.implementation = implementation; - if (implementation instanceof GameLib.GraphicsRuntime) { + if (implementation instanceof R3.GraphicsRuntime) { this.physics = null; this.graphics = implementation; this.graphics.isNotThreeThrow(); - } else if (implementation instanceof GameLib.PhysicsRuntime) { + } else if (implementation instanceof R3.PhysicsRuntime) { this.graphics = null; this.physics = implementation; this.physics.isNotCannonThrow(); @@ -26,11 +26,11 @@ GameLib.Quaternion = function ( throw new Error('Unhandled implementation : ' + implementation); } - if (GameLib.Utils.UndefinedOrNull(apiQuaternion)) { + if (R3.Utils.UndefinedOrNull(apiQuaternion)) { apiQuaternion = {}; } - GameLib.API.Quaternion.call( + R3.API.Quaternion.call( this, apiQuaternion.x, apiQuaternion.y, @@ -40,12 +40,12 @@ GameLib.Quaternion = function ( apiQuaternion.angle ); - if (GameLib.Utils.UndefinedOrNull(parentObject)) { + if (R3.Utils.UndefinedOrNull(parentObject)) { parentObject = null; } this.parentObject = parentObject; - this.axis = new GameLib.Vector3( + this.axis = new R3.Vector3( this.implementation, this.axis, this, @@ -55,10 +55,10 @@ GameLib.Quaternion = function ( Object.defineProperty( this, 'angle', - GameLib.Utils.LimitToPI('angle', this.angle) + R3.Utils.LimitToPI('angle', this.angle) ); - if (GameLib.Utils.UndefinedOrNull(grain)) { + if (R3.Utils.UndefinedOrNull(grain)) { grain = 0.001; } this.grain = grain; @@ -66,14 +66,14 @@ GameLib.Quaternion = function ( this.createInstance(); }; -GameLib.Quaternion.prototype = Object.create(GameLib.Component.prototype); -GameLib.Quaternion.prototype.constructor = GameLib.Quaternion; +R3.Quaternion.prototype = Object.create(R3.Component.prototype); +R3.Quaternion.prototype.constructor = R3.Quaternion; /** * Creates an instance quaternion * @returns {*} */ -GameLib.Quaternion.prototype.createInstance = function() { +R3.Quaternion.prototype.createInstance = function() { if (this.graphics) { this.instance = new THREE.Quaternion( @@ -97,7 +97,7 @@ GameLib.Quaternion.prototype.createInstance = function() { /** * Updates the instance vector, calls updateInstance on the parent object */ -GameLib.Quaternion.prototype.updateInstance = function(property) { +R3.Quaternion.prototype.updateInstance = function(property) { this.instance.x = this.x; this.instance.y = this.y; @@ -114,8 +114,8 @@ GameLib.Quaternion.prototype.updateInstance = function(property) { * Converts runtime quaternion to API quaternion * @returns {*} */ -GameLib.Quaternion.prototype.toApiObject = function() { - return new GameLib.API.Quaternion( +R3.Quaternion.prototype.toApiObject = function() { + return new R3.API.Quaternion( this.x, this.y, this.z, @@ -130,7 +130,7 @@ GameLib.Quaternion.prototype.toApiObject = function() { * @param quaternion * @returns {boolean} */ -GameLib.Quaternion.prototype.equals = function(quaternion) { +R3.Quaternion.prototype.equals = function(quaternion) { return ( this.x === quaternion.x && @@ -143,7 +143,7 @@ GameLib.Quaternion.prototype.equals = function(quaternion) { }; -GameLib.Quaternion.prototype.setFrom = function(quaternion) { +R3.Quaternion.prototype.setFrom = function(quaternion) { this.x = quaternion.x; this.y = quaternion.y; this.z = quaternion.z; @@ -152,6 +152,6 @@ GameLib.Quaternion.prototype.setFrom = function(quaternion) { this.angle = quaternion.angle; }; -GameLib.Quaternion.prototype.copy = function(quaternion) { +R3.Quaternion.prototype.copy = function(quaternion) { console.log('todo'); }; \ No newline at end of file diff --git a/src/game-lib-render-configuration.js b/src/r3-render-configuration.js similarity index 72% rename from src/game-lib-render-configuration.js rename to src/r3-render-configuration.js index f821b4a..cf67929 100644 --- a/src/game-lib-render-configuration.js +++ b/src/r3-render-configuration.js @@ -1,10 +1,10 @@ /** - * GameLib.RenderConfiguration + * R3.RenderConfiguration * @param graphics - * @param apiRenderConfiguration GameLib.API.RenderConfiguration + * @param apiRenderConfiguration R3.API.RenderConfiguration * @constructor */ -GameLib.RenderConfiguration = function ( +R3.RenderConfiguration = function ( graphics, apiRenderConfiguration ) { @@ -12,11 +12,11 @@ GameLib.RenderConfiguration = function ( this.graphics = graphics; this.graphics.isNotThreeThrow(); - if (GameLib.Utils.UndefinedOrNull(apiRenderConfiguration)) { + if (R3.Utils.UndefinedOrNull(apiRenderConfiguration)) { apiRenderConfiguration = {}; } - GameLib.API.RenderConfiguration.call( + R3.API.RenderConfiguration.call( this, apiRenderConfiguration.id, apiRenderConfiguration.name, @@ -33,43 +33,43 @@ GameLib.RenderConfiguration = function ( apiRenderConfiguration.enableEffect ); - this.logicalSize = new GameLib.Vector2( + this.logicalSize = new R3.Vector2( this.graphics, this.logicalSize, this ); - GameLib.Component.call( + R3.Component.call( this, { - 'activeCamera' : GameLib.D3.Camera, - 'activeScenes' : [GameLib.D3.Scene], - 'activeRenderer' : GameLib.Renderer, - 'activeComposer' : GameLib.D3.Composer, - 'activeEffect' : GameLib.D3.Effect + 'activeCamera' : R3.D3.Camera, + 'activeScenes' : [R3.D3.Scene], + 'activeRenderer' : R3.Renderer, + 'activeComposer' : R3.D3.Composer, + 'activeEffect' : R3.D3.Effect } ); }; -GameLib.RenderConfiguration.prototype = Object.create(GameLib.Component.prototype); -GameLib.RenderConfiguration.prototype.constructor = GameLib.RenderConfiguration; +R3.RenderConfiguration.prototype = Object.create(R3.Component.prototype); +R3.RenderConfiguration.prototype.constructor = R3.RenderConfiguration; /** * Create RenderConfiguration Instance * @returns {*} */ -GameLib.RenderConfiguration.prototype.createInstance = function() { +R3.RenderConfiguration.prototype.createInstance = function() { this.instance = {}; - GameLib.Component.prototype.createInstance.call(this); + R3.Component.prototype.createInstance.call(this); }; /** * Update RenderConfiguration Instance */ -GameLib.RenderConfiguration.prototype.updateInstance = function(property) { +R3.RenderConfiguration.prototype.updateInstance = function(property) { if ( property === 'logicalSize' || @@ -80,15 +80,15 @@ GameLib.RenderConfiguration.prototype.updateInstance = function(property) { console.log('todo: implement fixed aspect ratios for different scale modes'); if ( - GameLib.Utils.Defined(this.activeCamera) && - GameLib.Utils.Defined(this.activeCamera.instance) + R3.Utils.Defined(this.activeCamera) && + R3.Utils.Defined(this.activeCamera.instance) ) { /** * For now - just use normal aspect ratio */ - GameLib.Event.Emit( - GameLib.Event.GET_WINDOW_SIZE, + R3.Event.Emit( + R3.Event.GET_WINDOW_SIZE, {}, function(data) { @@ -117,15 +117,15 @@ GameLib.RenderConfiguration.prototype.updateInstance = function(property) { if (property === 'activeCamera') { if ( - GameLib.Utils.Defined(this.activeCamera) && - GameLib.Utils.Defined(this.activeCamera.instance) + R3.Utils.Defined(this.activeCamera) && + R3.Utils.Defined(this.activeCamera.instance) ) { /** * Update the aspect ratio for the active camera */ this.updateInstance('aspectRatio'); - GameLib.EntityManager.Instance.queryComponents(GameLib.Component.PASS_RENDER).map( + R3.EntityManager.Instance.queryComponents(R3.Component.PASS_RENDER).map( function(renderPass) { renderPass.camera = this.activeCamera; renderPass.updateInstance('camera'); @@ -227,26 +227,26 @@ GameLib.RenderConfiguration.prototype.updateInstance = function(property) { /** * - * @returns {GameLib.API.RenderConfiguration} + * @returns {R3.API.RenderConfiguration} */ -GameLib.RenderConfiguration.prototype.toApiObject = function() { +R3.RenderConfiguration.prototype.toApiObject = function() { - var apiRenderConfiguration = new GameLib.API.RenderConfiguration( + var apiRenderConfiguration = new R3.API.RenderConfiguration( this.id, this.name, - GameLib.Utils.IdOrNull(this.parentEntity), + R3.Utils.IdOrNull(this.parentEntity), this.logicalSize.toApiObject(), this.aspectRatio, this.scaleMode, - GameLib.Utils.IdOrNull(this.activeCamera), + R3.Utils.IdOrNull(this.activeCamera), this.activeScenes.map( function(activeScene) { - return GameLib.Utils.IdOrNull(activeScene); + return R3.Utils.IdOrNull(activeScene); } ), - GameLib.Utils.IdOrNull(this.activeRenderer), - GameLib.Utils.IdOrNull(this.activeComposer), - GameLib.Utils.IdOrNull(this.activeEffect), + R3.Utils.IdOrNull(this.activeRenderer), + R3.Utils.IdOrNull(this.activeComposer), + R3.Utils.IdOrNull(this.activeEffect), this.enableComposer, this.enableEffect ); diff --git a/src/game-lib-renderer-a.js b/src/r3-renderer-a.js similarity index 51% rename from src/game-lib-renderer-a.js rename to src/r3-renderer-a.js index 20e487f..3ebb5c6 100644 --- a/src/game-lib-renderer-a.js +++ b/src/r3-renderer-a.js @@ -1,27 +1,27 @@ /** - * GameLib.Renderer + * R3.Renderer * @param graphics - * @param apiRenderer GameLib.API.Renderer + * @param apiRenderer R3.API.Renderer * @property rendererType * @constructor */ -GameLib.Renderer = function ( +R3.Renderer = function ( graphics, apiRenderer ) { - if (GameLib.Utils.UndefinedOrNull(graphics)) { + if (R3.Utils.UndefinedOrNull(graphics)) { graphics = null; } this.graphics = graphics; - if (GameLib.Utils.UndefinedOrNull(apiRenderer)) { + if (R3.Utils.UndefinedOrNull(apiRenderer)) { apiRenderer = { - rendererType : GameLib.API.Renderer.RENDERER_TYPE_NONE + rendererType : R3.API.Renderer.RENDERER_TYPE_NONE }; } - GameLib.API.Renderer.call( + R3.API.Renderer.call( this, apiRenderer.id, apiRenderer.name, @@ -33,40 +33,40 @@ GameLib.Renderer = function ( apiRenderer.canvas ); - this.offset = new GameLib.Vector2( + this.offset = new R3.Vector2( this.graphics, this.offset, this ); - if (this.canvas instanceof GameLib.API.Canvas) { - this.canvas = new GameLib.Canvas( + if (this.canvas instanceof R3.API.Canvas) { + this.canvas = new R3.Canvas( this.graphics, this.canvas ); } - GameLib.Component.call( + R3.Component.call( this, - GameLib.Renderer.GetLinkedObjects(this.rendererType) + R3.Renderer.GetLinkedObjects(this.rendererType) ); }; -GameLib.Renderer.prototype = Object.create(GameLib.Component.prototype); -GameLib.Renderer.prototype.constructor = GameLib.Renderer; +R3.Renderer.prototype = Object.create(R3.Component.prototype); +R3.Renderer.prototype.constructor = R3.Renderer; -GameLib.Renderer.GetLinkedObjects = function(rendererType) { +R3.Renderer.GetLinkedObjects = function(rendererType) { var linkedObjects = { - 'canvas' : GameLib.Canvas + 'canvas' : R3.Canvas }; switch (rendererType) { - case GameLib.API.Renderer.RENDERER_TYPE_3D : - linkedObjects.renderTarget = GameLib.D3.RenderTarget; - linkedObjects.clippingPlanes = [GameLib.Plane]; - linkedObjects.viewports = [GameLib.D3.Viewport]; + case R3.API.Renderer.RENDERER_TYPE_3D : + linkedObjects.renderTarget = R3.D3.RenderTarget; + linkedObjects.clippingPlanes = [R3.Plane]; + linkedObjects.viewports = [R3.D3.Viewport]; break; } @@ -78,14 +78,14 @@ GameLib.Renderer.GetLinkedObjects = function(rendererType) { * Create Renderer Instance * @returns {*} */ -GameLib.Renderer.prototype.createInstance = function() { - GameLib.Component.prototype.createInstance.call(this); +R3.Renderer.prototype.createInstance = function() { + R3.Component.prototype.createInstance.call(this); }; /** * Update Renderer Instance */ -GameLib.Renderer.prototype.updateInstance = function(property) { +R3.Renderer.prototype.updateInstance = function(property) { if (!property) { throw new Error('no renderer property'); @@ -97,7 +97,7 @@ GameLib.Renderer.prototype.updateInstance = function(property) { if (property === 'rendererType') { - var componentType = GameLib.API.Renderer.GetComponentType(this.rendererType); + var componentType = R3.API.Renderer.GetComponentType(this.rendererType); this.replace(componentType); @@ -114,7 +114,7 @@ GameLib.Renderer.prototype.updateInstance = function(property) { if (property === 'offset') { - var size = GameLib.Utils.GetWindowSize(); + var size = R3.Utils.GetWindowSize(); this.canvas.offset.x = this.offset.x * size.width; this.canvas.offset.y = this.offset.y * size.height; @@ -128,29 +128,29 @@ GameLib.Renderer.prototype.updateInstance = function(property) { return; } - GameLib.Component.prototype.updateInstance.call(this, property); + R3.Component.prototype.updateInstance.call(this, property); }; /** * - * @returns {GameLib.API.Renderer} + * @returns {R3.API.Renderer} */ -GameLib.Renderer.prototype.toApiObject = function() { +R3.Renderer.prototype.toApiObject = function() { - var apiRenderer = new GameLib.API.Renderer( + var apiRenderer = new R3.API.Renderer( this.id, this.name, this.rendererType, - GameLib.Utils.IdOrNull(this.parentEntity), + R3.Utils.IdOrNull(this.parentEntity), this.width, this.height, this.offset.toApiObject(), - GameLib.Utils.IdOrNull(this.canvas) + R3.Utils.IdOrNull(this.canvas) ); return apiRenderer; }; -GameLib.Renderer.prototype.setSize = function(width, height) { +R3.Renderer.prototype.setSize = function(width, height) { console.warn('please implement me in child class'); }; diff --git a/src/r3-renderer-d2.js b/src/r3-renderer-d2.js new file mode 100644 index 0000000..0c51b0d --- /dev/null +++ b/src/r3-renderer-d2.js @@ -0,0 +1,94 @@ +/** + * R3.Renderer.D2 + * @param graphics + * @param apiRendererD2 R3.API.Renderer.D2 + * @constructor + */ +R3.Renderer.D2 = function ( + graphics, + apiRendererD2 +) { + + if (R3.Utils.UndefinedOrNull(graphics)) { + graphics = R3.GraphicsRuntime(null, null, R3.GraphicsRuntime.GRAPHICS_RUNTIME_IMPACT); + } + this.graphics = graphics; + + if (R3.Utils.UndefinedOrNull(apiRendererD2)) { + apiRendererD2 = { + rendererType : R3.API.Renderer.RENDERER_TYPE_2D + }; + } + + R3.API.Renderer.D2.call( + this, + apiRendererD2 + ); + + R3.Renderer.call( + this, + this.graphics, + this + ); + +}; + +R3.Renderer.D2.prototype = Object.create(R3.Renderer.prototype); +R3.Renderer.D2.prototype.constructor = R3.Renderer.D2; + +/** + * Create R3.Renderer.D2 Instance + * @returns {*} + */ +R3.Renderer.D2.prototype.createInstance = function() { + + if ( + R3.Utils.UndefinedOrNull(this.canvas) || + R3.Utils.UndefinedOrNull(this.canvas.instance) + ) { + console.warn('no canvas instance'); + return; + } + + this.instance = true; + + R3.Renderer.prototype.createInstance.call(this); +}; + +/** + * Update Renderer.D2 Instance + */ +R3.Renderer.D2.prototype.updateInstance = function(property) { + + if (!property) { + throw new Error('no renderer property'); + } + + if (!this.instance) { + throw new Error('no renderer instance'); + } + + R3.Renderer.prototype.updateInstance.call(this, property); +}; + +/** + * + * @returns {R3.API.Renderer.D2} + */ +R3.Renderer.D2.prototype.toApiObject = function() { + + var apiRenderer = R3.Renderer.prototype.toApiObject.call(this); + + var apiRendererD2 = new R3.API.Renderer.D2( + apiRenderer + ); + + return apiRendererD2; +}; + +/** + * set size + */ +R3.Renderer.D2.prototype.setSize = function(width, height) { + R3.Renderer.prototype.setSize.call(this); +}; diff --git a/src/game-lib-renderer-d3.js b/src/r3-renderer-d3.js similarity index 83% rename from src/game-lib-renderer-d3.js rename to src/r3-renderer-d3.js index eebe428..e2eafcc 100644 --- a/src/game-lib-renderer-d3.js +++ b/src/r3-renderer-d3.js @@ -1,23 +1,23 @@ /** - * GameLib.Renderer.D3 - * @param graphics GameLib.GraphicsRuntime - * @param apiRendererD3 GameLib.API.Renderer.D3 + * R3.Renderer.D3 + * @param graphics R3.GraphicsRuntime + * @param apiRendererD3 R3.API.Renderer.D3 * @constructor */ -GameLib.Renderer.D3 = function ( +R3.Renderer.D3 = function ( graphics, apiRendererD3 ) { this.graphics = graphics; this.graphics.isNotThreeThrow(); - if (GameLib.Utils.UndefinedOrNull(apiRendererD3)) { + if (R3.Utils.UndefinedOrNull(apiRendererD3)) { apiRendererD3 = { - rendererType : GameLib.API.Renderer.RENDERER_TYPE_3D + rendererType : R3.API.Renderer.RENDERER_TYPE_3D }; } - GameLib.API.Renderer.D3.call( + R3.API.Renderer.D3.call( this, apiRendererD3, apiRendererD3.renderMode, @@ -54,16 +54,16 @@ GameLib.Renderer.D3 = function ( apiRendererD3.viewports ); - if (this.renderTarget instanceof GameLib.D3.API.RenderTarget) { - this.renderTarget = new GameLib.D3.RenderTarget( + if (this.renderTarget instanceof R3.D3.API.RenderTarget) { + this.renderTarget = new R3.D3.RenderTarget( this.graphics, this.renderTarget ) } this.clippingPlanes = this.clippingPlanes.map(function(clippingPlane){ - if (clippingPlane instanceof GameLib.API.Plane) { - return new GameLib.Plane( + if (clippingPlane instanceof R3.API.Plane) { + return new R3.Plane( this.graphics, clippingPlane ); @@ -72,15 +72,15 @@ GameLib.Renderer.D3 = function ( } }.bind(this)); - this.clearColor = new GameLib.Color( + this.clearColor = new R3.Color( this.graphics, this.clearColor, this ); this.viewports = this.viewports.map(function(viewport){ - if (viewport instanceof GameLib.D3.API.Viewport) { - return new GameLib.D3.Viewport( + if (viewport instanceof R3.D3.API.Viewport) { + return new R3.D3.Viewport( this.graphics, viewport ); @@ -89,7 +89,7 @@ GameLib.Renderer.D3 = function ( } }.bind(this)); - GameLib.Renderer.call( + R3.Renderer.call( this, this.graphics, this @@ -97,18 +97,18 @@ GameLib.Renderer.D3 = function ( }; -GameLib.Renderer.D3.prototype = Object.create(GameLib.Renderer.prototype); -GameLib.Renderer.D3.prototype.constructor = GameLib.Renderer.D3; +R3.Renderer.D3.prototype = Object.create(R3.Renderer.prototype); +R3.Renderer.D3.prototype.constructor = R3.Renderer.D3; /** - * Create GameLib.Renderer.D3 Instance + * Create R3.Renderer.D3 Instance * @returns {*} */ -GameLib.Renderer.D3.prototype.createInstance = function() { +R3.Renderer.D3.prototype.createInstance = function() { if ( - GameLib.Utils.UndefinedOrNull(this.canvas) || - GameLib.Utils.UndefinedOrNull(this.canvas.instance) + R3.Utils.UndefinedOrNull(this.canvas) || + R3.Utils.UndefinedOrNull(this.canvas.instance) ) { console.warn('no canvas instance'); return; @@ -183,13 +183,13 @@ GameLib.Renderer.D3.prototype.createInstance = function() { 1 - this.clearColor.a ); - GameLib.Renderer.prototype.createInstance.call(this); + R3.Renderer.prototype.createInstance.call(this); }; /** * Update Renderer.D3 Instance */ -GameLib.Renderer.D3.prototype.updateInstance = function(property) { +R3.Renderer.D3.prototype.updateInstance = function(property) { if (!property) { throw new Error('no renderer property'); @@ -203,7 +203,7 @@ GameLib.Renderer.D3.prototype.updateInstance = function(property) { property === 'width' || property === 'height' ) { - var size = GameLib.Utils.GetWindowSize(); + var size = R3.Utils.GetWindowSize(); this.instance.setSize(size.width, size.height, false); return; } @@ -355,7 +355,7 @@ GameLib.Renderer.D3.prototype.updateInstance = function(property) { if (property === 'canvas') { - if (GameLib.Utils.UndefinedOrNull(this.instance)) { + if (R3.Utils.UndefinedOrNull(this.instance)) { this.createInstance(); } else { console.warn('experimental canvas change for renderer'); @@ -369,9 +369,9 @@ GameLib.Renderer.D3.prototype.updateInstance = function(property) { if (property === 'renderTarget') { if ( - GameLib.Utils.Defined(this.instance) && - GameLib.Utils.Defined(this.renderTarget) && - GameLib.Utils.Defined(this.renderTarget.instance) + R3.Utils.Defined(this.instance) && + R3.Utils.Defined(this.renderTarget) && + R3.Utils.Defined(this.renderTarget.instance) ) { this.instance.setRenderTarget(this.renderTarget.instance); console.log('updated render target on render instance'); @@ -401,13 +401,13 @@ GameLib.Renderer.D3.prototype.updateInstance = function(property) { console.warn('todo: viewports change'); } - GameLib.Renderer.prototype.updateInstance.call(this, property); + R3.Renderer.prototype.updateInstance.call(this, property); }; /** * Wrapper for clear() */ -GameLib.Renderer.D3.prototype.clear = function() { +R3.Renderer.D3.prototype.clear = function() { return this.instance.clear(); }; @@ -416,7 +416,7 @@ GameLib.Renderer.D3.prototype.clear = function() { * @param width * @param height */ -GameLib.Renderer.D3.prototype.setSize = function(width, height) { +R3.Renderer.D3.prototype.setSize = function(width, height) { this.instance.setSize( this.width * width, @@ -431,7 +431,7 @@ GameLib.Renderer.D3.prototype.setSize = function(width, height) { * Convenience function to get size * @returns {{width, height}} */ -GameLib.Renderer.D3.prototype.getSize = function() { +R3.Renderer.D3.prototype.getSize = function() { return this.instance.getSize(); }; @@ -442,7 +442,7 @@ GameLib.Renderer.D3.prototype.getSize = function() { * @param width * @param height */ -GameLib.Renderer.D3.prototype.setViewport = function( +R3.Renderer.D3.prototype.setViewport = function( x, y, width, @@ -461,7 +461,7 @@ GameLib.Renderer.D3.prototype.setViewport = function( * @param scene * @param camera */ -GameLib.Renderer.D3.prototype.renderToTarget = function(scene, camera) { +R3.Renderer.D3.prototype.renderToTarget = function(scene, camera) { this.instance.render( scene.instance, @@ -476,7 +476,7 @@ GameLib.Renderer.D3.prototype.renderToTarget = function(scene, camera) { * @param scene * @param camera */ -GameLib.Renderer.D3.prototype.render = function(scene, camera) { +R3.Renderer.D3.prototype.render = function(scene, camera) { this.instance.render( scene.instance, camera.instance @@ -486,13 +486,13 @@ GameLib.Renderer.D3.prototype.render = function(scene, camera) { /** * - * @returns {GameLib.API.Renderer.D3} + * @returns {R3.API.Renderer.D3} */ -GameLib.Renderer.D3.prototype.toApiObject = function() { +R3.Renderer.D3.prototype.toApiObject = function() { - var apiRenderer = GameLib.Renderer.prototype.toApiObject.call(this); + var apiRenderer = R3.Renderer.prototype.toApiObject.call(this); - var apiRendererD3 = new GameLib.API.Renderer.D3( + var apiRendererD3 = new R3.API.Renderer.D3( apiRenderer, this.renderMode, this.autoClear, @@ -522,16 +522,16 @@ GameLib.Renderer.D3.prototype.toApiObject = function() { this.depth, this.logarithmicDepthBuffer, this.localClippingEnabled, - GameLib.Utils.IdOrNull(this.renderTarget), + R3.Utils.IdOrNull(this.renderTarget), this.clippingPlanes.map( function(clippingPlane){ - return GameLib.Utils.IdOrNull(clippingPlane); + return R3.Utils.IdOrNull(clippingPlane); } ), this.clearColor.toApiObject(), this.viewports.map( function(viewport){ - return GameLib.Utils.IdOrNull(viewport); + return R3.Utils.IdOrNull(viewport); } ) ); diff --git a/src/r3-server.js b/src/r3-server.js new file mode 100644 index 0000000..d5b5c10 --- /dev/null +++ b/src/r3-server.js @@ -0,0 +1,87 @@ +/** + * Creates a Server object + * @param apiServer R3.API.Server + * @constructor + */ +R3.Server = function( + apiServer +) { + + if (R3.Utils.UndefinedOrNull(apiServer)) { + apiServer = {}; + } + + R3.API.Server.call( + this, + apiServer.id, + apiServer.name, + apiServer.protocol, + apiServer.ip, + apiServer.port, + apiServer.protocols, + apiServer.parentEntity + ); + + this.connected = false; + + R3.Component.call(this); +}; + +R3.Server.prototype = Object.create(R3.Component.prototype); +R3.Server.prototype.constructor = R3.Server; + +R3.Server.prototype.createInstance = function() { + + this.instance = true; + + R3.Component.prototype.createInstance.call(this); +}; + +/** + * Updates the instance with the current state + */ +R3.Server.prototype.updateInstance = function(property) { + if (property === 'protocol') { + console.log('todo: server protocol update'); + } + if (property === 'ip') { + console.log('todo: server ip update'); + } + if (property === 'port') { + console.log('todo: server port update'); + } + if (property === 'protocols') { + console.log('todo: server protocols update'); + } + + R3.D3.Texture.prototype.updateInstance.call(this, property); +}; + +/** + * Converts a R3.Server to a new R3.API.Server + * @returns {R3.API.Server} + */ +R3.Server.prototype.toApiObject = function() { + + return new R3.API.Server( + this.id, + this.name, + this.protocol, + this.ip, + this.port, + this.protocols, + R3.Utils.IdOrNull(this.parentEntity) + ); + +}; + +/** + * Converts from an Object Server to a R3.Server + * @param objectServer Object + * @returns {R3.Server} + * @constructor + */ +R3.Server.FromObject = function(objectServer) { + var apiServer = R3.API.Server.FromObject(objectServer); + return new R3.Server(apiServer); +}; diff --git a/src/r3-socket-0.js b/src/r3-socket-0.js new file mode 100644 index 0000000..f0ffc7d --- /dev/null +++ b/src/r3-socket-0.js @@ -0,0 +1,115 @@ +/** + * Creates a Socket object + * @param socket R3.Socket + * @param apiSocket R3.API.Socket + * @constructor + */ +R3.Socket = function( + socket, + apiSocket +) { + + this.socket = socket; + this.socket.isNotWebSocketThrow(); + + if (R3.Utils.UndefinedOrNull(apiSocket)) { + apiSocket = {}; + } + + R3.API.Socket.call( + this, + apiSocket.id, + apiSocket.name, + apiSocket.socketType, + apiSocket.roomId, + apiSocket.peerId, + apiSocket.server, + apiSocket.parentEntity + ); + + if (this.server instanceof R3.API.Server) { + this.server = new R3.Server(this.server); + } + + this.connected = false; + + var linkedObjects = { + server : R3.Server + }; + + if (this.socketType === R3.API.Socket.TYPE_CAST) { + linkedObjects.source = R3.Component; + } + + if (this.socketType === R3.API.Socket.TYPE_RECEIVE) { + linkedObjects.destination = R3.Component; + } + + R3.Component.call( + this, + linkedObjects + ); + +}; + +R3.Socket.prototype = Object.create(R3.Component.prototype); +R3.Socket.prototype.constructor = R3.Socket; + +R3.Socket.prototype.createInstance = function() { + + this.instance = true; + + R3.Component.prototype.createInstance.call(this); +}; + +/** + * Updates the instance with the current state + */ +R3.Socket.prototype.updateInstance = function(property) { + if (property === 'socketType') { + console.log('todo: implement socket socketType update'); + } + if (property === 'roomId') { + console.log('todo: implement socket roomId update'); + } + if (property === 'peerId') { + console.log('todo: implement socket peerId update'); + } + if (property === 'server') { + console.log('todo: implement socket server update'); + } + R3.D3.Texture.prototype.updateInstance.call(this, property); +}; + +/** + * Converts a R3.Socket to a new R3.API.Socket + * @returns {R3.API.Socket} + */ +R3.Socket.prototype.toApiObject = function() { + + return new R3.API.Socket( + this.id, + this.name, + this.socketType, + this.roomId, + this.peerId, + R3.Utils.IdOrNull(this.server), + R3.Utils.IdOrNull(this.parentEntity) + ); + +}; + +/** + * Converts from an Object Socket to a R3.Socket + * @param sockets R3.SocketsRuntime + * @param objectSocket Object + * @returns {R3.Socket} + * @constructor + */ +R3.Socket.FromObject = function(sockets, objectSocket) { + var apiSocket = R3.API.Socket.FromObject(objectSocket); + return new R3.Socket( + sockets, + apiSocket + ); +}; diff --git a/src/r3-socket-cast.js b/src/r3-socket-cast.js new file mode 100644 index 0000000..533b77e --- /dev/null +++ b/src/r3-socket-cast.js @@ -0,0 +1,119 @@ +/** + * Creates a Cast object + * @param socket R3.Socket + * @param apiSocketCast + * @constructor + */ +R3.Socket.Cast = function( + socket, + apiSocketCast +) { + + this.socket = socket; + this.socket.isNotWebSocketThrow(); + + if (R3.Utils.UndefinedOrNull(apiSocketCast)) { + apiSocketCast = { + socketType : R3.API.Socket.TYPE_CAST + }; + } + + R3.API.Socket.Cast.call( + this, + apiSocketCast, + apiSocketCast.castType, + apiSocketCast.source, + apiSocketCast.sourceProperties + ); + + R3.Socket.call( + this, + socket, + apiSocketCast + ); +}; + +R3.Socket.Cast.prototype = Object.create(R3.Socket.prototype); +R3.Socket.Cast.prototype.constructor = R3.Socket.Cast; + +R3.Socket.Cast.prototype.createInstance = function() { + + this.instance = true; + + R3.Socket.prototype.createInstance.call(this); +}; + +/** + * Updates the instance with the current state + */ +R3.Socket.Cast.prototype.updateInstance = function(property) { + + R3.Socket.prototype.updateInstance.call( + this, + property + ); + + if (property === 'castType') { + console.log('todo: implement socket.receive.castType update'); + } + + if (property === 'source') { + if (this.source !== null) { + this.sourceProperties = R3.Utils.ObjectPropertiesAsBoolean(this.source); + } else { + this.sourceProperties = {}; + } + + R3.Event.Emit( + R3.Event.CAST_SOURCE_CHANGED, + { + component:this + } + ) + } + + if (property === 'sourceProperties') { + console.log('todo: implement socket.receive.sourceProperties update'); + } + +}; + +/** + * Converts a R3.Socket.Cast to a new R3.API.Socket.Cast + * @returns {R3.API.Socket.Cast} + */ +R3.Socket.Cast.prototype.toApiObject = function() { + + var apiSocket = new R3.API.Socket( + this.id, + this.name, + this.socketType, + this.roomId, + this.peerId, + R3.Utils.IdOrNull(this.server), + R3.Utils.IdOrNull(this.parentEntity) + ); + + return new R3.API.Socket.Cast( + apiSocket, + this.castType, + R3.Utils.IdOrNull(this.source), + this.sourceProperties + ); + +}; + +/** + * Converts from an Object Cast to a R3.Socket.Cast + * @param sockets R3.SocketsRuntime + * @param objectCast Object + * @returns {R3.Socket.Cast} + * @constructor + */ +R3.Socket.Cast.FromObject = function(sockets, objectCast) { + var apiCast = R3.API.Socket.Cast.FromObject(objectCast); + return new R3.Socket.Cast( + sockets, + apiCast + ); +}; diff --git a/src/r3-socket-receive.js b/src/r3-socket-receive.js new file mode 100644 index 0000000..ea8b493 --- /dev/null +++ b/src/r3-socket-receive.js @@ -0,0 +1,123 @@ +/** + * Creates a Receive object + * @param socket R3.Socket + * @param apiSocketReceive R3.API.Socket.Receive + * @constructor + */ +R3.Socket.Receive = function( + socket, + apiSocketReceive +) { + + this.socket = socket; + this.socket.isNotWebSocketThrow(); + + if (R3.Utils.UndefinedOrNull(apiSocketReceive)) { + apiSocketReceive = { + socketType : R3.API.Socket.TYPE_RECEIVE + }; + } + + R3.API.Socket.Receive.call( + this, + apiSocketReceive, + apiSocketReceive.receiveType, + apiSocketReceive.destination, + apiSocketReceive.destinationProperties + ); + + R3.Socket.call( + this, + socket, + apiSocketReceive + ); + +}; + +R3.Socket.Receive.prototype = Object.create(R3.Socket.prototype); +R3.Socket.Receive.prototype.constructor = R3.Socket.Receive; + +R3.Socket.Receive.prototype.createInstance = function() { + + this.instance = true; + + R3.Socket.prototype.createInstance.call(this); +}; + +/** + * Updates the instance with the current state + */ +R3.Socket.Receive.prototype.updateInstance = function(property) { + + R3.Socket.prototype.updateInstance.call( + this, + property + ); + + if (property === 'receiveType') { + console.log('todo: implement socket.receive.receiveType update'); + } + + if (property === 'destination') { + + if (this.destination !== null) { + this.destinationProperties = R3.Utils.ObjectPropertiesAsBoolean(this.destination); + } else { + this.destinationProperties = {}; + } + + R3.Event.Emit( + R3.Event.RECEIVE_DESTINATION_CHANGED, + { + component:this + } + ) + } + + if (property === 'destinationProperties') { + console.log('todo: implement socket.receive.destinationProperties update'); + } +}; + +/** + * Converts a R3.Socket.Receive to a new R3.API.Socket.Receive + * @returns {R3.API.Socket.Receive} + */ +R3.Socket.Receive.prototype.toApiObject = function() { + + var apiSocket = new R3.API.Socket( + this.id, + this.name, + this.socketType, + this.roomId, + this.peerId, + R3.Utils.IdOrNull(this.server), + R3.Utils.IdOrNull(this.parentEntity) + ); + + return new R3.API.Socket.Receive( + apiSocket, + this.receiveType, + this.destination, + this.destinationProperties + ); + +}; + +/** + * Converts from an Object Receive to a R3.Socket.Receive + * @param sockets R3.SocketsRuntime + * @param objectReceive Object + * @returns {R3.Socket.Receive} + * @constructor + */ +R3.Socket.Receive.FromObject = function(sockets, objectReceive) { + + var apiSocketReceive = R3.API.Socket.Receive.FromObject(objectReceive); + + return new R3.Socket.Receive( + sockets, + apiSocketReceive + ); + +}; diff --git a/src/game-lib-sockets-runtime.js b/src/r3-sockets-runtime.js similarity index 55% rename from src/game-lib-sockets-runtime.js rename to src/r3-sockets-runtime.js index e1c9a87..31c6a66 100644 --- a/src/game-lib-sockets-runtime.js +++ b/src/r3-sockets-runtime.js @@ -5,23 +5,23 @@ * @param socketsType * @constructor */ -GameLib.SocketsRuntime = function( +R3.SocketsRuntime = function( id, name, socketsType ) { - if (GameLib.Utils.UndefinedOrNull(id)) { - id = GameLib.Utils.RandomId(); + if (R3.Utils.UndefinedOrNull(id)) { + id = R3.Utils.RandomId(); } this.id = id; - if (GameLib.Utils.UndefinedOrNull(name)) { + if (R3.Utils.UndefinedOrNull(name)) { name = 'Sockets (' + id + ')'; } this.name = name; - if (GameLib.Utils.UndefinedOrNull(socketsType)) { - socketsType = GameLib.SocketsRuntime.TYPE_WEB_SOCKET; + if (R3.Utils.UndefinedOrNull(socketsType)) { + socketsType = R3.SocketsRuntime.TYPE_WEB_SOCKET; } this.socketsType = socketsType; @@ -31,25 +31,25 @@ GameLib.SocketsRuntime = function( }; /** - * GameLib.SocketsRuntime Types + * R3.SocketsRuntime Types * @type {number} */ -GameLib.SocketsRuntime.TYPE_WEB_SOCKET = 0x1; +R3.SocketsRuntime.TYPE_WEB_SOCKET = 0x1; -GameLib.SocketsRuntime.prototype.createInstance = function() { - if (this.socketsType === GameLib.SocketsRuntime.TYPE_WEB_SOCKET) { +R3.SocketsRuntime.prototype.createInstance = function() { + if (this.socketsType === R3.SocketsRuntime.TYPE_WEB_SOCKET) { this.instance = WebSocket; } else { this.instance = null; } }; -GameLib.SocketsRuntime.prototype.connect = function(server) { +R3.SocketsRuntime.prototype.connect = function(server) { var connection = new WebSocket(server.protocol + '://' + server.ip + ':' + server.port , server.protocols); this.connections.push(connection); }; -GameLib.SocketsRuntime.prototype.updateInstance = function(property) { +R3.SocketsRuntime.prototype.updateInstance = function(property) { if (property === 'socketsType') { this.createInstance(); } @@ -58,7 +58,7 @@ GameLib.SocketsRuntime.prototype.updateInstance = function(property) { /** * Logs a warning and throws an error if not cannon */ -GameLib.SocketsRuntime.prototype.isNotWebSocketThrow = function() { +R3.SocketsRuntime.prototype.isNotWebSocketThrow = function() { if (this.instance !== WebSocket) { console.error('Only WebSocket supported'); throw new Error('Only WebSocket supported'); diff --git a/src/game-lib-sphere.js b/src/r3-sphere.js similarity index 60% rename from src/game-lib-sphere.js rename to src/r3-sphere.js index f3906a2..4e40e69 100644 --- a/src/game-lib-sphere.js +++ b/src/r3-sphere.js @@ -1,11 +1,11 @@ /** - * GameLib.Sphere + * R3.Sphere * @param implementation * @param apiSphere * @param parentObject * @constructor */ -GameLib.Sphere = function ( +R3.Sphere = function ( implementation, apiSphere, parentObject @@ -14,22 +14,22 @@ GameLib.Sphere = function ( this.implementation = implementation; this.implementation.isNotThreeThrow(); - if (GameLib.Utils.UndefinedOrNull(parentObject)) { + if (R3.Utils.UndefinedOrNull(parentObject)) { parentObject = null; } this.parentObject = parentObject; - if (GameLib.Utils.UndefinedOrNull(apiSphere)) { + if (R3.Utils.UndefinedOrNull(apiSphere)) { apiSphere = {}; } - GameLib.API.Sphere.call( + R3.API.Sphere.call( this, apiSphere.center, apiSphere.radius ); - this.center = new GameLib.Vector3( + this.center = new R3.Vector3( this.implementation, this.center, this @@ -38,14 +38,14 @@ GameLib.Sphere = function ( this.createInstance(); }; -GameLib.Sphere.prototype = Object.create(GameLib.API.Sphere.prototype); -GameLib.Sphere.prototype.constructor = GameLib.Sphere; +R3.Sphere.prototype = Object.create(R3.API.Sphere.prototype); +R3.Sphere.prototype.constructor = R3.Sphere; /** - * Creates an instance GameLib.Sphere + * Creates an instance R3.Sphere * @returns {*} */ -GameLib.Sphere.prototype.createInstance = function() { +R3.Sphere.prototype.createInstance = function() { this.instance = new THREE.Sphere( this.center.instance, @@ -55,10 +55,10 @@ GameLib.Sphere.prototype.createInstance = function() { }; /** - * Updates GameLib.Sphere instance + * Updates R3.Sphere instance * @param property */ -GameLib.Sphere.prototype.updateInstance = function(property) { +R3.Sphere.prototype.updateInstance = function(property) { if (property === 'center') { this.instance.center.x = this.center.x; @@ -75,11 +75,11 @@ GameLib.Sphere.prototype.updateInstance = function(property) { }; /** - * GameLib.Sphere to GameLib.API.Sphere - * @returns {GameLib.API.Sphere} + * R3.Sphere to R3.API.Sphere + * @returns {R3.API.Sphere} */ -GameLib.Sphere.prototype.toApiObject = function() { - return new GameLib.API.Sphere( +R3.Sphere.prototype.toApiObject = function() { + return new R3.API.Sphere( this.center.toApiObject(), this.radius ); diff --git a/src/game-lib-statistics-runtime.js b/src/r3-statistics-runtime.js similarity index 52% rename from src/game-lib-statistics-runtime.js rename to src/r3-statistics-runtime.js index 7b9da26..269703d 100644 --- a/src/game-lib-statistics-runtime.js +++ b/src/r3-statistics-runtime.js @@ -5,23 +5,23 @@ * @param statisticsType * @constructor */ -GameLib.StatisticsRuntime = function( +R3.StatisticsRuntime = function( id, name, statisticsType ) { - if (GameLib.Utils.UndefinedOrNull(id)) { - id = GameLib.Utils.RandomId(); + if (R3.Utils.UndefinedOrNull(id)) { + id = R3.Utils.RandomId(); } this.id = id; - if (GameLib.Utils.UndefinedOrNull(name)) { + if (R3.Utils.UndefinedOrNull(name)) { name = 'Statistics (' + id + ')'; } this.name = name; - if (GameLib.Utils.UndefinedOrNull(statisticsType)) { - statisticsType = GameLib.StatisticsRuntime.TYPE_STATS; + if (R3.Utils.UndefinedOrNull(statisticsType)) { + statisticsType = R3.StatisticsRuntime.TYPE_STATS; } this.statisticsType = statisticsType; @@ -29,20 +29,20 @@ GameLib.StatisticsRuntime = function( }; /** - * GameLib.StatisticsRuntime Types + * R3.StatisticsRuntime Types * @type {number} */ -GameLib.StatisticsRuntime.TYPE_STATS = 0x1; +R3.StatisticsRuntime.TYPE_STATS = 0x1; -GameLib.StatisticsRuntime.prototype.createInstance = function() { - if (this.statisticsType === GameLib.StatisticsRuntime.TYPE_STATS) { +R3.StatisticsRuntime.prototype.createInstance = function() { + if (this.statisticsType === R3.StatisticsRuntime.TYPE_STATS) { this.instance = Stats; } else { this.instance = null; } }; -GameLib.StatisticsRuntime.prototype.updateInstance = function(property) { +R3.StatisticsRuntime.prototype.updateInstance = function(property) { if (property === 'statisticsType') { this.createInstance(); } @@ -51,7 +51,7 @@ GameLib.StatisticsRuntime.prototype.updateInstance = function(property) { /** * Logs a warning and throws an error if not cannon */ -GameLib.StatisticsRuntime.prototype.isNotStatsThrow = function() { +R3.StatisticsRuntime.prototype.isNotStatsThrow = function() { if (this.instance !== Stats) { console.error('Only stats supported'); throw new Error('Only stats supported'); diff --git a/src/r3-stats.js b/src/r3-stats.js new file mode 100644 index 0000000..6152df2 --- /dev/null +++ b/src/r3-stats.js @@ -0,0 +1,103 @@ +/** + * Stats component for displaying some render statistics (framerate, memory consumption, etc) + * @param statisticsRuntime + * @param apiStats + * @constructor + */ +R3.Stats = function( + statisticsRuntime, + apiStats +) { + this.stats = statisticsRuntime; + this.stats.isNotStatsThrow(); + + if (R3.Utils.UndefinedOrNull(apiStats)) { + apiStats = {}; + } + + R3.API.Stats.call( + this, + apiStats.id, + apiStats.name, + apiStats.domElement, + apiStats.parentEntity + ); + + R3.Component.call( + this, + { + 'domElement': R3.DomElement + } + ); +}; + +R3.Stats.prototype = Object.create(R3.Component.prototype); +R3.Stats.prototype.constructor = R3.Stats; + +/** + * Creates a helper instance + */ +R3.Stats.prototype.createInstance = function() { + + this.instance = this.stats.instance(); + + this.resize(); + + this.domElement.instance.parentElement.appendChild(this.instance.dom); + + R3.Component.prototype.createInstance.call(this); +}; + +/** + * Updates the instance with the current state + */ +R3.Stats.prototype.updateInstance = function() { + this.instance = new this.stats(); +}; + + +/** + * Converts a R3.Stats to a new R3.API.Stats + * @returns {R3.API.Stats} + */ +R3.Stats.prototype.toApiObject = function() { + + return new R3.API.Stats( + this.id, + this.name, + R3.Utils.IdOrNull(this.domElement), + R3.Utils.IdOrNull(this.parentEntity) + ); + +}; + +/** + * Converts from an Object Stats to a R3.Stats + * @param statisticsRuntime R3.StatisticsRuntime + * @param objectStats Object + * @returns {R3.Stats} + * @constructor + */ +R3.Stats.FromObject = function(statisticsRuntime, objectStats) { + + var apiStats = R3.API.Stats.FromObject(objectStats); + + return new R3.Stats( + statisticsRuntime, + apiStats + ); + +}; + +R3.Stats.prototype.resize = function() { + console.log('override stats resize per implementation'); +}; + + +R3.Stats.prototype.start = function() { + this.instance.begin(); +}; + +R3.Stats.prototype.end = function() { + this.instance.end(); +}; diff --git a/src/r3-system-0.js b/src/r3-system-0.js new file mode 100644 index 0000000..a5b3657 --- /dev/null +++ b/src/r3-system-0.js @@ -0,0 +1,104 @@ +/** + * System takes care of updating all the entities (based on their component data) + * @param apiSystem R3.API.System + * @constructor + */ +R3.System = function( + apiSystem +) { + + if (R3.Utils.UndefinedOrNull(apiSystem)) { + apiSystem = {}; + } + + R3.API.System.call( + this, + apiSystem.id, + apiSystem.name, + apiSystem.systemType, + apiSystem.parentEntity + ); + + this.started = false; + + this.paused = false; + + var linkedObjects = {}; + + if (apiSystem.systemType === R3.System.SYSTEM_TYPE_INPUT) { + linkedObjects.mouseControls = [R3.Controls.Mouse]; + linkedObjects.keyboardControls = [R3.Controls.Keyboard]; + linkedObjects.touchControls = [R3.Controls.Touch]; + linkedObjects.editorControls = [R3.Controls.D3.Editor]; + } + + if (apiSystem.systemType === R3.System.SYSTEM_TYPE_AUDIO) { + linkedObjects.audioComponents = [R3.D3.Audio]; + } + + R3.Component.call( + this, + linkedObjects + ); + +}; + +R3.System.prototype = Object.create(R3.Component.prototype); +R3.System.prototype.constructor = R3.System; + +R3.System.SYSTEM_TYPE_NONE = 0x0; +R3.System.SYSTEM_TYPE_RENDER = 0x1; +R3.System.SYSTEM_TYPE_ANIMATION = 0x2; +R3.System.SYSTEM_TYPE_INPUT = 0x4; +R3.System.SYSTEM_TYPE_STORAGE = 0x8; +R3.System.SYSTEM_TYPE_GUI = 0x10; +R3.System.SYSTEM_TYPE_PHYSICS = 0x20; +R3.System.SYSTEM_TYPE_LINKING = 0x40; +R3.System.SYSTEM_TYPE_CUSTOM = 0x80; +R3.System.SYSTEM_TYPE_VISUALIZATION = 0x100; +R3.System.SYSTEM_TYPE_PARTICLE = 0x200; +R3.System.SYSTEM_TYPE_AUDIO = 0x400; +R3.System.SYSTEM_TYPE_SOCKET = 0x800; +R3.System.SYSTEM_TYPE_ALL = 0xFFFF; + +R3.System.prototype.createInstance = function() { + this.instance = true; + R3.Component.prototype.createInstance.call(this); +}; + +/** + * @callback + * @override + */ +R3.System.prototype.start = function() { + this.started = true; +// console.log('starting ' + this.name); +}; + +/** + * @callback + * @override + */ +R3.System.prototype.stop = function() { + this.started = false; +// console.log('stopping ' + this.name); +}; + +/** + * Converts runtime vector to API Vector + * @returns {R3.API.System} + */ +R3.System.prototype.toApiObject = function() { + return new R3.API.System( + this.id, + this.name, + this.systemType, + R3.Utils.IdOrNull(this.parentEntity) + ); +}; + +R3.System.prototype.restart = function() { + console.log('restarting system : ' + this.name); + this.stop(); + this.start(); +}; \ No newline at end of file diff --git a/src/game-lib-system-animation.js b/src/r3-system-animation.js similarity index 89% rename from src/game-lib-system-animation.js rename to src/r3-system-animation.js index 8ca6770..c5d7455 100644 --- a/src/game-lib-system-animation.js +++ b/src/r3-system-animation.js @@ -1,12 +1,12 @@ /** * System takes care of updating all the entities (based on their component data) - * @param apiSystem GameLib.API.System + * @param apiSystem R3.API.System * @constructor */ -GameLib.System.Animation = function( +R3.System.Animation = function( apiSystem ) { - GameLib.System.call( + R3.System.call( this, apiSystem ); @@ -26,24 +26,24 @@ GameLib.System.Animation = function( this.textureAnimatedSubscription = null; /** - * Sometimes we want to animate texture instances directly, without the overhead of a GameLib.Texture + * Sometimes we want to animate texture instances directly, without the overhead of a R3.Texture */ this.animateTextureInstanceSubscription = null; }; -GameLib.System.Animation.prototype = Object.create(GameLib.System.prototype); -GameLib.System.Animation.prototype.constructor = GameLib.System.Animation; +R3.System.Animation.prototype = Object.create(R3.System.prototype); +R3.System.Animation.prototype.constructor = R3.System.Animation; -GameLib.System.Animation.prototype.start = function() { +R3.System.Animation.prototype.start = function() { - GameLib.System.prototype.start.call(this); + R3.System.prototype.start.call(this); - this.beforeRenderSubscription = GameLib.Event.Subscribe( - GameLib.Event.BEFORE_RENDER, + this.beforeRenderSubscription = R3.Event.Subscribe( + R3.Event.BEFORE_RENDER, this.beforeRender.bind(this) ); - this.animations = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.ANIMATION); + this.animations = R3.EntityManager.Instance.queryComponents(R3.Component.ANIMATION); // // animations.map(function(animation){ @@ -55,45 +55,45 @@ GameLib.System.Animation.prototype.start = function() { // this.animations[animation.id] = animation; // }.bind(this)); - // this.animationMeshAddedSubscription = GameLib.Event.Subscribe( - // GameLib.Event.ANIMATION_MESH_ADDED, + // this.animationMeshAddedSubscription = R3.Event.Subscribe( + // R3.Event.ANIMATION_MESH_ADDED, // function(data) { // this.attachAnimation(data.animation, data.mesh); // }.bind(this) // ); // - // this.animationMeshRemovedSubscription = GameLib.Event.Subscribe( - // GameLib.Event.ANIMATION_MESH_REMOVED, + // this.animationMeshRemovedSubscription = R3.Event.Subscribe( + // R3.Event.ANIMATION_MESH_REMOVED, // function(data) { // this.detachAnimation(data.mesh); // }.bind(this) // ); - this.instanceCreatedSubscription = GameLib.Event.Subscribe( - GameLib.Event.INSTANCE_CREATED, + this.instanceCreatedSubscription = R3.Event.Subscribe( + R3.Event.INSTANCE_CREATED, this.instanceCreated.bind(this) ); - this.removeComponentSubscription = GameLib.Event.Subscribe( - GameLib.Event.REMOVE_COMPONENT, + this.removeComponentSubscription = R3.Event.Subscribe( + R3.Event.REMOVE_COMPONENT, this.removeComponent.bind(this) ); - this.textureAnimatedSubscription = GameLib.Event.Subscribe( - GameLib.Event.TEXTURE_ANIMATED_CHANGE, + this.textureAnimatedSubscription = R3.Event.Subscribe( + R3.Event.TEXTURE_ANIMATED_CHANGE, this.textureAnimatedChange.bind(this) ); - this.animateTextureInstanceSubscription = GameLib.Event.Subscribe( - GameLib.Event.ANIMATE_TEXTURE_INSTANCE, + this.animateTextureInstanceSubscription = R3.Event.Subscribe( + R3.Event.ANIMATE_TEXTURE_INSTANCE, this.animateTextureInstance.bind(this) ) }; -GameLib.System.Animation.prototype.instanceCreated = function(data) { +R3.System.Animation.prototype.instanceCreated = function(data) { if ( - data.component instanceof GameLib.D3.Texture && + data.component instanceof R3.D3.Texture && data.component.animated ) { @@ -113,9 +113,9 @@ GameLib.System.Animation.prototype.instanceCreated = function(data) { this.textureIds = Object.keys(this.textures); } - if (data.component instanceof GameLib.D3.Animation) { + if (data.component instanceof R3.D3.Animation) { - GameLib.Utils.PushUnique(this.animations, data.component); + R3.Utils.PushUnique(this.animations, data.component); // // this.animations[data.component.id] = data.component; // data.component.meshes.map( @@ -126,13 +126,13 @@ GameLib.System.Animation.prototype.instanceCreated = function(data) { } }; -GameLib.System.Animation.prototype.removeComponent = function(data) { +R3.System.Animation.prototype.removeComponent = function(data) { if ( - data.component instanceof GameLib.D3.Texture && + data.component instanceof R3.D3.Texture && data.component.animated ) { - if (GameLib.Utils.UndefinedOrNull(this.textures[data.component.id])) { + if (R3.Utils.UndefinedOrNull(this.textures[data.component.id])) { console.warn('tried to remove an animated texture, which should have been in the list but isnt: ' + data.component.name); } else { delete this.textures[data.component.id]; @@ -140,7 +140,7 @@ GameLib.System.Animation.prototype.removeComponent = function(data) { } } - if (data.component instanceof GameLib.D3.Animation) { + if (data.component instanceof R3.D3.Animation) { var index = this.animations.indexOf(data.component); @@ -151,7 +151,7 @@ GameLib.System.Animation.prototype.removeComponent = function(data) { } } - if (data.component instanceof GameLib.D3.Mesh) { + if (data.component instanceof R3.D3.Mesh) { this.animations.map( function(animation) { @@ -166,7 +166,7 @@ GameLib.System.Animation.prototype.removeComponent = function(data) { } }; -GameLib.System.Animation.prototype.textureAnimatedChange = function(data) { +R3.System.Animation.prototype.textureAnimatedChange = function(data) { if (data.texture.animated) { @@ -187,7 +187,7 @@ GameLib.System.Animation.prototype.textureAnimatedChange = function(data) { } else { - if (GameLib.Utils.UndefinedOrNull(this.textures[data.texture.id])) { + if (R3.Utils.UndefinedOrNull(this.textures[data.texture.id])) { console.warn('tried to remove an animated texture, which should have been in the list but isnt: ' + data.texture.name); } else { delete this.textures[data.texture.id]; @@ -198,11 +198,11 @@ GameLib.System.Animation.prototype.textureAnimatedChange = function(data) { }; /** - * This adds a texture instance directly on our textures to be animated - to bypass our GameLib component and linking + * This adds a texture instance directly on our textures to be animated - to bypass our R3 component and linking * system, which adds too much overhead for managing textures * @param data */ -GameLib.System.Animation.prototype.animateTextureInstance = function(data) { +R3.System.Animation.prototype.animateTextureInstance = function(data) { if (data.texture.repeat.x > 1 || data.texture.repeat.x < 0) { console.warn('cannot animate a texture with repeat.x greater than 1 or less than 0'); @@ -230,7 +230,7 @@ GameLib.System.Animation.prototype.animateTextureInstance = function(data) { * @param increment * @returns {boolean} */ -GameLib.System.Animation.prototype.slightChange = function(object, property, subProperty, increment) { +R3.System.Animation.prototype.slightChange = function(object, property, subProperty, increment) { var current = object.instance[property][subProperty]; var target = object[property][subProperty]; @@ -247,7 +247,7 @@ GameLib.System.Animation.prototype.slightChange = function(object, property, sub return true; }; -GameLib.System.Animation.prototype.beforeRender = function(data) { +R3.System.Animation.prototype.beforeRender = function(data) { if (this.paused) { return; @@ -371,9 +371,9 @@ GameLib.System.Animation.prototype.beforeRender = function(data) { /** * Stop Animation System */ -GameLib.System.Animation.prototype.stop = function() { +R3.System.Animation.prototype.stop = function() { - GameLib.System.prototype.stop.call(this); + R3.System.prototype.stop.call(this); this.beforeRenderSubscription.remove(); @@ -395,7 +395,7 @@ GameLib.System.Animation.prototype.stop = function() { /* -GameLib.System.Animation.prototype.detachAnimation = function(mesh) { +R3.System.Animation.prototype.detachAnimation = function(mesh) { var detached = false; @@ -594,7 +594,7 @@ GameLib.System.Animation.prototype.detachAnimation = function(mesh) { }; */ -//GameLib.System.Animation.prototype.attachAnimation = function(animation, mesh) { +//R3.System.Animation.prototype.attachAnimation = function(animation, mesh) { /** * Initialize the property with the original mesh z value @@ -776,7 +776,7 @@ GameLib.System.Animation.prototype.detachAnimation = function(mesh) { ); }; */ -// GameLib.System.Animation.prototype.getQuaternionAngle = function(mesh, animation) { +// R3.System.Animation.prototype.getQuaternionAngle = function(mesh, animation) { // // return function() { // return; @@ -926,7 +926,7 @@ GameLib.System.Animation.prototype.detachAnimation = function(mesh) { // } // }; // -// GameLib.System.Animation.prototype.setQuaternionAngle = function(mesh, animation) { +// R3.System.Animation.prototype.setQuaternionAngle = function(mesh, animation) { // // return function(value) { // return; @@ -955,7 +955,7 @@ GameLib.System.Animation.prototype.detachAnimation = function(mesh) { // // // setTargetAngle(value); // -// // GameLib.Utils.PushUnique(mesh.animationObject.storedValues, value); +// // R3.Utils.PushUnique(mesh.animationObject.storedValues, value); // // // // mesh.animationObject.callbacks.push( // // function(__value) { @@ -1002,8 +1002,8 @@ GameLib.System.Animation.prototype.detachAnimation = function(mesh) { // * Now we subscribe to 'before render' events, and slowly increment the value // * @type {{fn, remove}} // */ -// mesh.animationObject.subscription = GameLib.Event.Subscribe( -// GameLib.Event.BEFORE_RENDER, +// mesh.animationObject.subscription = R3.Event.Subscribe( +// R3.Event.BEFORE_RENDER, // function(data) { // // var increment = Math.abs(animation.rotationSpeed); @@ -1018,49 +1018,49 @@ GameLib.System.Animation.prototype.detachAnimation = function(mesh) { // } // }; // -// GameLib.System.Animation.prototype.getQuaternionAxisX = function(mesh, animation) { +// R3.System.Animation.prototype.getQuaternionAxisX = function(mesh, animation) { // return function() { // return this.latest[mesh.id].quaternion.axis.x; // }.bind(this); // }; // -// GameLib.System.Animation.prototype.setQuaternionAxisX = function(mesh, animation) { +// R3.System.Animation.prototype.setQuaternionAxisX = function(mesh, animation) { // return function(value) { // this.latest[mesh.id].quaternion.axis.x = value; // }.bind(this); // }; // -// GameLib.System.Animation.prototype.getQuaternionAxisY = function(mesh, animation) { +// R3.System.Animation.prototype.getQuaternionAxisY = function(mesh, animation) { // return function() { // return this.latest[mesh.id].quaternion.axis.y; // }.bind(this); // }; // -// GameLib.System.Animation.prototype.setQuaternionAxisY = function(mesh, animation) { +// R3.System.Animation.prototype.setQuaternionAxisY = function(mesh, animation) { // return function(value) { // this.latest[mesh.id].quaternion.axis.y = value; // }.bind(this); // }; // -// GameLib.System.Animation.prototype.getQuaternionAxisZ = function(mesh, animation) { +// R3.System.Animation.prototype.getQuaternionAxisZ = function(mesh, animation) { // return function() { // return this.latest[mesh.id].quaternion.axis.z; // }.bind(this); // }; // -// GameLib.System.Animation.prototype.setQuaternionAxisZ = function(mesh, animation) { +// R3.System.Animation.prototype.setQuaternionAxisZ = function(mesh, animation) { // return function(value) { // this.latest[mesh.id].quaternion.axis.z = value; // }.bind(this); // }; // -// GameLib.System.Animation.prototype.getSubProperty = function(mesh, axis, property, subProperty) { +// R3.System.Animation.prototype.getSubProperty = function(mesh, axis, property, subProperty) { // return function() { // return this.latest[mesh.id][property][subProperty][axis]; // }.bind(this); // }; -// GameLib.System.Animation.prototype.setSubProperty = function(mesh, animation, axis, property, subProperty) { +// R3.System.Animation.prototype.setSubProperty = function(mesh, animation, axis, property, subProperty) { // return function(value) { // // var from = Number(this.latest[mesh.id][property][subProperty][axis]); @@ -1107,13 +1107,13 @@ GameLib.System.Animation.prototype.detachAnimation = function(mesh) { // }.bind(this) // }; -// GameLib.System.Animation.prototype.getProperty = function(mesh, axis, property) { +// R3.System.Animation.prototype.getProperty = function(mesh, axis, property) { // return function() { // return this.latest[mesh.id][property][axis]; // }.bind(this); // }; // -// GameLib.System.Animation.prototype.setProperty = function(mesh, animation, axis, property) { +// R3.System.Animation.prototype.setProperty = function(mesh, animation, axis, property) { // return function(value) { // // var from = Number(this.latest[mesh.id][property][axis]); diff --git a/src/game-lib-system-audio.js b/src/r3-system-audio.js similarity index 71% rename from src/game-lib-system-audio.js rename to src/r3-system-audio.js index 13da175..42962d4 100644 --- a/src/game-lib-system-audio.js +++ b/src/r3-system-audio.js @@ -1,12 +1,12 @@ /** * System takes care of updating all the entities (based on their component data) - * @param apiSystem GameLib.API.System + * @param apiSystem R3.API.System * @constructor */ -GameLib.System.Audio = function( +R3.System.Audio = function( apiSystem ) { - GameLib.System.call( + R3.System.call( this, apiSystem ); @@ -36,53 +36,53 @@ GameLib.System.Audio = function( this.toPlay = []; }; -GameLib.System.Audio.prototype = Object.create(GameLib.System.prototype); -GameLib.System.Audio.prototype.constructor = GameLib.System.Audio; +R3.System.Audio.prototype = Object.create(R3.System.prototype); +R3.System.Audio.prototype.constructor = R3.System.Audio; /** * Start this system (add all event listeners) */ -GameLib.System.Audio.prototype.start = function() { +R3.System.Audio.prototype.start = function() { - GameLib.System.prototype.start.call(this); + R3.System.prototype.start.call(this); - this.instanceCreatedSubscription = GameLib.Event.Subscribe( - GameLib.Event.INSTANCE_CREATED, + this.instanceCreatedSubscription = R3.Event.Subscribe( + R3.Event.INSTANCE_CREATED, this.instanceCreated.bind(this) ); - this.removeComponentSubscription = GameLib.Event.Subscribe( - GameLib.Event.REMOVE_COMPONENT, + this.removeComponentSubscription = R3.Event.Subscribe( + R3.Event.REMOVE_COMPONENT, this.removeComponent.bind(this) ); - this.playAudioSubscription = GameLib.Event.Subscribe( - GameLib.Event.PLAY_AUDIO, + this.playAudioSubscription = R3.Event.Subscribe( + R3.Event.PLAY_AUDIO, this.playAudio.bind(this) ); - this.pauseAllAudioSubscription = GameLib.Event.Subscribe( - GameLib.Event.PAUSE_ALL_AUDIO, + this.pauseAllAudioSubscription = R3.Event.Subscribe( + R3.Event.PAUSE_ALL_AUDIO, this.pauseAllAudio.bind(this) ); - this.muteAudioSubscription = GameLib.Event.Subscribe( - GameLib.Event.MUTE_AUDIO, + this.muteAudioSubscription = R3.Event.Subscribe( + R3.Event.MUTE_AUDIO, this.muteAudio.bind(this) ); - this.continueAllAudioSubscription = GameLib.Event.Subscribe( - GameLib.Event.CONTINUE_ALL_AUDIO, + this.continueAllAudioSubscription = R3.Event.Subscribe( + R3.Event.CONTINUE_ALL_AUDIO, this.continueAllAudio.bind(this) ); - this.stopAudioSubscription = GameLib.Event.Subscribe( - GameLib.Event.STOP_AUDIO, + this.stopAudioSubscription = R3.Event.Subscribe( + R3.Event.STOP_AUDIO, this.stopAudio.bind(this) ); - this.stopAllAudioSubscription = GameLib.Event.Subscribe( - GameLib.Event.STOP_ALL_AUDIO, + this.stopAllAudioSubscription = R3.Event.Subscribe( + R3.Event.STOP_ALL_AUDIO, this.stopAllAudio.bind(this) ); @@ -92,16 +92,16 @@ GameLib.System.Audio.prototype.start = function() { * From now on we want to track everything about a component, only from the systems that are active * @param data */ -GameLib.System.Audio.prototype.instanceCreated = function(data) { +R3.System.Audio.prototype.instanceCreated = function(data) { - if (data.component instanceof GameLib.D3.Audio) { + if (data.component instanceof R3.D3.Audio) { - GameLib.Utils.PushUnique(this.audioComponents, data.component); + R3.Utils.PushUnique(this.audioComponents, data.component); data.component.instance.onEnded = function() { this.isPlaying = false; - GameLib.Event.Emit( - GameLib.Event.AUDIO_ENDED, + R3.Event.Emit( + R3.Event.AUDIO_ENDED, { audio : data.component } @@ -112,8 +112,8 @@ GameLib.System.Audio.prototype.instanceCreated = function(data) { if (index !== -1) { - GameLib.Event.Emit( - GameLib.Event.PLAY_AUDIO, + R3.Event.Emit( + R3.Event.PLAY_AUDIO, { name : data.component.name } @@ -128,7 +128,7 @@ GameLib.System.Audio.prototype.instanceCreated = function(data) { * Removes a particle engine from this system * @param data */ -GameLib.System.Audio.prototype.playAudio = function(data) { +R3.System.Audio.prototype.playAudio = function(data) { var found = false; @@ -176,7 +176,7 @@ GameLib.System.Audio.prototype.playAudio = function(data) { } }; -GameLib.System.Audio.prototype.pauseAllAudio = function(data) { +R3.System.Audio.prototype.pauseAllAudio = function(data) { this.paused = []; @@ -193,7 +193,7 @@ GameLib.System.Audio.prototype.pauseAllAudio = function(data) { ) }; -GameLib.System.Audio.prototype.continueAllAudio = function(data) { +R3.System.Audio.prototype.continueAllAudio = function(data) { this.paused.map( function(audio) { @@ -207,7 +207,7 @@ GameLib.System.Audio.prototype.continueAllAudio = function(data) { }; -GameLib.System.Audio.prototype.stopAllAudio = function(data) { +R3.System.Audio.prototype.stopAllAudio = function(data) { this.audioComponents.map( function(audio) { if (audio.instance.isPlaying) { @@ -218,7 +218,7 @@ GameLib.System.Audio.prototype.stopAllAudio = function(data) { }; -GameLib.System.Audio.prototype.stopAudio = function(data) { +R3.System.Audio.prototype.stopAudio = function(data) { this.audioComponents.map( function(audio) { if (audio.name === data.name) { @@ -231,11 +231,11 @@ GameLib.System.Audio.prototype.stopAudio = function(data) { }; -GameLib.System.Audio.prototype.removeComponent = function(data) { +R3.System.Audio.prototype.removeComponent = function(data) { }; -GameLib.System.Audio.prototype.muteAudio = function() { +R3.System.Audio.prototype.muteAudio = function() { this.mute = !this.mute; @@ -257,7 +257,7 @@ GameLib.System.Audio.prototype.muteAudio = function() { [] ); - GameLib.Event.Emit(GameLib.Event.AUDIO_MUTED, {audioSystem:this}); + R3.Event.Emit(R3.Event.AUDIO_MUTED, {audioSystem:this}); } else { @@ -268,7 +268,7 @@ GameLib.System.Audio.prototype.muteAudio = function() { } ); - GameLib.Event.Emit(GameLib.Event.AUDIO_UNMUTED, {audioSystem:this}); + R3.Event.Emit(R3.Event.AUDIO_UNMUTED, {audioSystem:this}); } }; @@ -276,9 +276,9 @@ GameLib.System.Audio.prototype.muteAudio = function() { /** * Stop this system (remove all event listeners) */ -GameLib.System.Audio.prototype.stop = function() { +R3.System.Audio.prototype.stop = function() { - GameLib.System.prototype.stop.call(this); + R3.System.prototype.stop.call(this); this.instanceCreatedSubscription.remove(); this.removeComponentSubscription.remove(); diff --git a/src/game-lib-system-custom-code.js b/src/r3-system-custom-code.js similarity index 63% rename from src/game-lib-system-custom-code.js rename to src/r3-system-custom-code.js index c5187bc..4112cfa 100644 --- a/src/game-lib-system-custom-code.js +++ b/src/r3-system-custom-code.js @@ -1,13 +1,13 @@ /** * System takes care of updating all the entities (based on their component data) - * @param apiSystem GameLib.API.System + * @param apiSystem R3.API.System * @constructor */ -GameLib.System.CustomCode = function( +R3.System.CustomCode = function( apiSystem ) { - GameLib.System.call( + R3.System.call( this, apiSystem ); @@ -22,69 +22,69 @@ GameLib.System.CustomCode = function( }; -GameLib.System.CustomCode.prototype = Object.create(GameLib.System.prototype); -GameLib.System.CustomCode.prototype.constructor = GameLib.System.CustomCode; +R3.System.CustomCode.prototype = Object.create(R3.System.prototype); +R3.System.CustomCode.prototype.constructor = R3.System.CustomCode; /** * Start the rendering system */ -GameLib.System.CustomCode.prototype.start = function() { +R3.System.CustomCode.prototype.start = function() { - GameLib.System.prototype.start.call(this); + R3.System.prototype.start.call(this); - GameLib.EntityManager.Instance.queryComponents(GameLib.Component.CUSTOM_CODE).map( + R3.EntityManager.Instance.queryComponents(R3.Component.CUSTOM_CODE).map( function(component) { - this.subscriptions[component.id] = GameLib.Event.Subscribe( + this.subscriptions[component.id] = R3.Event.Subscribe( component.eventId, component.instance ); }.bind(this) ); - this.instanceCreatedSubscription = GameLib.Event.Subscribe( - GameLib.Event.INSTANCE_CREATED, + this.instanceCreatedSubscription = R3.Event.Subscribe( + R3.Event.INSTANCE_CREATED, this.instanceCreated.bind(this) ); - this.removeComponentSubscription = GameLib.Event.Subscribe( - GameLib.Event.REMOVE_COMPONENT, + this.removeComponentSubscription = R3.Event.Subscribe( + R3.Event.REMOVE_COMPONENT, this.removeComponent.bind(this) ); - this.compileSuccessSubscription = GameLib.Event.Subscribe( - GameLib.Event.COMPILE_SUCCESS, + this.compileSuccessSubscription = R3.Event.Subscribe( + R3.Event.COMPILE_SUCCESS, this.compileSuccess.bind(this) ); - this.compileFailedSubscription = GameLib.Event.Subscribe( - GameLib.Event.COMPILE_FAILED, + this.compileFailedSubscription = R3.Event.Subscribe( + R3.Event.COMPILE_FAILED, this.compileFailed.bind(this) ); this.eventIdUpdateSubscription = this.subscribe( - GameLib.Event.EVENT_ID_UPDATE, + R3.Event.EVENT_ID_UPDATE, this.compileSuccess ); }; -GameLib.System.CustomCode.prototype.instanceCreated = function(data) { - if (data.component instanceof GameLib.CustomCode) { +R3.System.CustomCode.prototype.instanceCreated = function(data) { + if (data.component instanceof R3.CustomCode) { if (this.subscriptions[data.component.id]) { console.warn('a component already existed'); this.subscriptions[data.component.id].remove(); } - this.subscriptions[data.component.id] = GameLib.Event.Subscribe( + this.subscriptions[data.component.id] = R3.Event.Subscribe( data.component.eventId, data.component.instance ); } }; -GameLib.System.CustomCode.prototype.removeComponent = function(data) { - if (data.component instanceof GameLib.CustomCode) { +R3.System.CustomCode.prototype.removeComponent = function(data) { + if (data.component instanceof R3.CustomCode) { if (this.subscriptions[data.component.id]) { this.subscriptions[data.component.id].remove(); delete this.subscriptions[data.component.id]; @@ -92,19 +92,19 @@ GameLib.System.CustomCode.prototype.removeComponent = function(data) { } }; -GameLib.System.CustomCode.prototype.compileSuccess = function(data) { +R3.System.CustomCode.prototype.compileSuccess = function(data) { if (this.subscriptions[data.component.id]) { this.subscriptions[data.component.id].remove(); } - this.subscriptions[data.component.id] = GameLib.Event.Subscribe( + this.subscriptions[data.component.id] = R3.Event.Subscribe( data.component.eventId, data.component.instance ); }; -GameLib.System.CustomCode.prototype.compileFailed = function(data) { +R3.System.CustomCode.prototype.compileFailed = function(data) { if (this.subscriptions[data.component.id]) { this.subscriptions[data.component.id].remove(); delete this.subscriptions[data.component.id]; @@ -115,9 +115,9 @@ GameLib.System.CustomCode.prototype.compileFailed = function(data) { /** * Stop the rendering system */ -GameLib.System.CustomCode.prototype.stop = function() { +R3.System.CustomCode.prototype.stop = function() { - GameLib.System.prototype.stop.call(this); + R3.System.prototype.stop.call(this); if (this.instanceCreatedSubscription) { this.instanceCreatedSubscription.remove(); diff --git a/src/game-lib-system-gui.js b/src/r3-system-gui.js similarity index 67% rename from src/game-lib-system-gui.js rename to src/r3-system-gui.js index f883c47..6961912 100644 --- a/src/game-lib-system-gui.js +++ b/src/r3-system-gui.js @@ -1,12 +1,12 @@ /** * System takes care of updating all the entities (based on their component data) - * @param apiSystem GameLib.API.System + * @param apiSystem R3.API.System * @constructor */ -GameLib.System.GUI = function( +R3.System.GUI = function( apiSystem ) { - GameLib.System.call( + R3.System.call( this, apiSystem ); @@ -52,10 +52,10 @@ GameLib.System.GUI = function( }; -GameLib.System.GUI.prototype = Object.create(GameLib.System.prototype); -GameLib.System.GUI.prototype.constructor = GameLib.System.GUI; +R3.System.GUI.prototype = Object.create(R3.System.prototype); +R3.System.GUI.prototype.constructor = R3.System.GUI; -GameLib.System.GUI.prototype.windowResize = function(data) { +R3.System.GUI.prototype.windowResize = function(data) { this.guis.map( function(gui) { gui.instance.domElement.getElementsByTagName('ul')[0].style.maxHeight = data.height - 93 + 'px'; @@ -63,7 +63,7 @@ GameLib.System.GUI.prototype.windowResize = function(data) { ); }; -GameLib.System.GUI.prototype.initialize = function(gui) { +R3.System.GUI.prototype.initialize = function(gui) { var length = this.guis.length; @@ -76,16 +76,16 @@ GameLib.System.GUI.prototype.initialize = function(gui) { gui.instance.domElement.getElementsByTagName('ul')[0].style.maxHeight = window.screen.availHeight - 93 + 'px'; }; -GameLib.System.GUI.prototype.instanceCreated = function(data) { - if (data.component instanceof GameLib.GUI) { - GameLib.Utils.PushUnique(this.guis, data.component); +R3.System.GUI.prototype.instanceCreated = function(data) { + if (data.component instanceof R3.GUI) { + R3.Utils.PushUnique(this.guis, data.component); this.initialize(data.component); } }; -GameLib.System.GUI.prototype.removeComponent = function(data) { +R3.System.GUI.prototype.removeComponent = function(data) { - if (data.component instanceof GameLib.GUI) { + if (data.component instanceof R3.GUI) { var index = this.guis.indexOf(data.component); if (index === -1) { @@ -101,36 +101,36 @@ GameLib.System.GUI.prototype.removeComponent = function(data) { }; -GameLib.System.GUI.prototype.start = function() { +R3.System.GUI.prototype.start = function() { - GameLib.System.prototype.start.call(this); + R3.System.prototype.start.call(this); - this.instanceCreatedSubscription = GameLib.Event.Subscribe( - GameLib.Event.INSTANCE_CREATED, + this.instanceCreatedSubscription = R3.Event.Subscribe( + R3.Event.INSTANCE_CREATED, this.instanceCreated.bind(this) ); - this.removeComponentSubscription = GameLib.Event.Subscribe( - GameLib.Event.REMOVE_COMPONENT, + this.removeComponentSubscription = R3.Event.Subscribe( + R3.Event.REMOVE_COMPONENT, this.removeComponent.bind(this) ); - this.windowResizeSubscription = GameLib.Event.Subscribe( - GameLib.Event.WINDOW_RESIZE, + this.windowResizeSubscription = R3.Event.Subscribe( + R3.Event.WINDOW_RESIZE, this.windowResize.bind(this) ); - this.meshFaceSelectedSubscription = GameLib.Event.Subscribe( - GameLib.Event.MESH_FACE_SELECTED, + this.meshFaceSelectedSubscription = R3.Event.Subscribe( + R3.Event.MESH_FACE_SELECTED, this.meshFaceSelected.bind(this) ); - this.meshFaceDeselectedSubscription = GameLib.Event.Subscribe( - GameLib.Event.MESH_FACE_DESELECTED, + this.meshFaceDeselectedSubscription = R3.Event.Subscribe( + R3.Event.MESH_FACE_DESELECTED, this.meshFaceDeselected.bind(this) ); - this.guis = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.GUI); + this.guis = R3.EntityManager.Instance.queryComponents(R3.Component.GUI); this.guis.map( function(gui){ this.initialize(gui); @@ -243,53 +243,53 @@ GameLib.System.GUI.prototype.start = function() { }; this.buildGUISubscription = this.subscribe( - GameLib.Event.BUILD_GUI, + R3.Event.BUILD_GUI, this.buildGUI ); this.meshDeletedSubscription = this.subscribe( - GameLib.Event.REMOVE_MESH, + R3.Event.REMOVE_MESH, this.meshDeleted ); this.meshSelectedSubscription = this.subscribe( - GameLib.Event.MESH_SELECTED, + R3.Event.MESH_SELECTED, this.meshSelected ); this.meshDeselectedSubscription = this.subscribe( - GameLib.Event.MESH_DESELECTED, + R3.Event.MESH_DESELECTED, this.meshDeslected ); this.componentRemovedSubscription = this.subscribe( - GameLib.Event.REMOVE_COMPONENT, + R3.Event.REMOVE_COMPONENT, this.removeComponent ); this.sourceChangedSubscription = this.subscribe( - GameLib.Event.CAST_SOURCE_CHANGED, + R3.Event.CAST_SOURCE_CHANGED, this.castSourceChanged ); this.destinationChangedSubscription = this.subscribe( - GameLib.Event.RECEIVE_DESTINATION_CHANGED, + R3.Event.RECEIVE_DESTINATION_CHANGED, this.receiveDestinationChanged ); }; -GameLib.System.GUI.prototype.onChange = function(property, subProperty, affected) { +R3.System.GUI.prototype.onChange = function(property, subProperty, affected) { return function(value) { affected.map(function(component){ component[property][subProperty] = value; - if (component instanceof GameLib.D3.Mesh && property === 'rotation') { + if (component instanceof R3.D3.Mesh && property === 'rotation') { component.useQuaternion = false; } - if (component instanceof GameLib.D3.Mesh && property === 'quaternion') { + if (component instanceof R3.D3.Mesh && property === 'quaternion') { component.useQuaternion = true; } @@ -305,13 +305,13 @@ GameLib.System.GUI.prototype.onChange = function(property, subProperty, affected } }; -GameLib.System.GUI.prototype.controller = function(folder, object, property, subProperty, step, listen, affected, min, max) { +R3.System.GUI.prototype.controller = function(folder, object, property, subProperty, step, listen, affected, min, max) { - if (GameLib.Utils.UndefinedOrNull(min)) { + if (R3.Utils.UndefinedOrNull(min)) { min = -1000; } - if (GameLib.Utils.UndefinedOrNull(max)) { + if (R3.Utils.UndefinedOrNull(max)) { max = 1000; } @@ -377,7 +377,7 @@ GameLib.System.GUI.prototype.controller = function(folder, object, property, sub return handle; }; -GameLib.System.GUI.prototype.buildQuaternionControl = function(folder, componentTemplate, property) { +R3.System.GUI.prototype.buildQuaternionControl = function(folder, componentTemplate, property) { var step = 0.1; @@ -452,7 +452,7 @@ GameLib.System.GUI.prototype.buildQuaternionControl = function(folder, component }; -GameLib.System.GUI.prototype.buildVectorControl = function(folder, componentTemplate, property) { +R3.System.GUI.prototype.buildVectorControl = function(folder, componentTemplate, property) { var step = 0.001; @@ -473,7 +473,7 @@ GameLib.System.GUI.prototype.buildVectorControl = function(folder, componentTemp var controllers = []; - if (GameLib.Utils.isVector4(object[property])) { + if (R3.Utils.isVector4(object[property])) { controllers.push(this.controller(folder, object, property, 'w', step, listen, affected)); } @@ -481,8 +481,8 @@ GameLib.System.GUI.prototype.buildVectorControl = function(folder, componentTemp controllers.push(this.controller(folder, object, property, 'y', step, listen, affected)); if ( - GameLib.Utils.isVector3(object[property]) || - GameLib.Utils.isVector4(object[property]) + R3.Utils.isVector3(object[property]) || + R3.Utils.isVector4(object[property]) ) { controllers.push(this.controller(folder, object, property, 'z', step, listen, affected)); } @@ -495,15 +495,15 @@ GameLib.System.GUI.prototype.buildVectorControl = function(folder, componentTemp * @param componentTemplate * @param property */ -GameLib.System.GUI.prototype.buildParentSelectionControl = function(folder, componentTemplate, property) { +R3.System.GUI.prototype.buildParentSelectionControl = function(folder, componentTemplate, property) { - var type = GameLib.Utils.UpperCaseUnderscore(property.replace('parent','')); + var type = R3.Utils.UpperCaseUnderscore(property.replace('parent','')); - var componentType = GameLib.Component[type]; + var componentType = R3.Component[type]; - var constructor = GameLib.Component.GetComponentConstructor(componentType); + var constructor = R3.Component.GetComponentConstructor(componentType); - var options = GameLib.EntityManager.Instance.queryComponentsByConstructor(constructor).reduce( + var options = R3.EntityManager.Instance.queryComponentsByConstructor(constructor).reduce( function(result, object) { result[object.name] = object; return result; @@ -524,7 +524,7 @@ GameLib.System.GUI.prototype.buildParentSelectionControl = function(folder, comp var newComponent = null; if (value !== 'null') { - newComponent = GameLib.EntityManager.Instance.findComponentById(value); + newComponent = R3.EntityManager.Instance.findComponentById(value); } affected.map( @@ -534,8 +534,8 @@ GameLib.System.GUI.prototype.buildParentSelectionControl = function(folder, comp component.updateInstance(property); if (property === 'parentPhysicsWorld') { - GameLib.Event.Emit( - GameLib.Event.PARENT_WORLD_CHANGE, + R3.Event.Emit( + R3.Event.PARENT_WORLD_CHANGE, { originalWorld : this.initialValue, newWorld : newComponent, @@ -545,8 +545,8 @@ GameLib.System.GUI.prototype.buildParentSelectionControl = function(folder, comp } if (property === 'parentScene') { - GameLib.Event.Emit( - GameLib.Event.PARENT_SCENE_CHANGE, + R3.Event.Emit( + R3.Event.PARENT_SCENE_CHANGE, { originalScene: this.initialValue, newScene: newComponent, @@ -559,8 +559,8 @@ GameLib.System.GUI.prototype.buildParentSelectionControl = function(folder, comp ); if (property === 'parentEntity') { - GameLib.Event.Emit( - GameLib.Event.BUILD_GUI, + R3.Event.Emit( + R3.Event.BUILD_GUI, null ); } @@ -570,7 +570,7 @@ GameLib.System.GUI.prototype.buildParentSelectionControl = function(folder, comp ); }; -GameLib.System.GUI.prototype.buildArrayManagerControl = function( +R3.System.GUI.prototype.buildArrayManagerControl = function( folder, componentTemplate, property @@ -622,7 +622,7 @@ GameLib.System.GUI.prototype.buildArrayManagerControl = function( var idObject = {}; - var selectionObject = GameLib.EntityManager.Instance.queryComponentsByConstructor(constructors).reduce( + var selectionObject = R3.EntityManager.Instance.queryComponentsByConstructor(constructors).reduce( function(result, component) { result[component.name] = component; idObject[component.id] = component; @@ -641,8 +641,8 @@ GameLib.System.GUI.prototype.buildArrayManagerControl = function( //if (component[property].indexOf(activeSelection.component) === -1) { component[property].push(activeSelection.component); - GameLib.Event.Emit( - GameLib.Event.ARRAY_ITEM_ADDED, + R3.Event.Emit( + R3.Event.ARRAY_ITEM_ADDED, { component : component, property : property, @@ -656,8 +656,8 @@ GameLib.System.GUI.prototype.buildArrayManagerControl = function( //} }); - GameLib.Event.Emit( - GameLib.Event.BUILD_GUI + R3.Event.Emit( + R3.Event.BUILD_GUI ); } }; @@ -679,7 +679,7 @@ GameLib.System.GUI.prototype.buildArrayManagerControl = function( /** * This is only for uvs right now */ -GameLib.System.GUI.prototype.buildUVManagerControl = function( +R3.System.GUI.prototype.buildUVManagerControl = function( folder, componentTemplate, property @@ -719,7 +719,7 @@ GameLib.System.GUI.prototype.buildUVManagerControl = function( }; -GameLib.System.GUI.prototype.buildColorControl = function(folder, componentTemplate, property) { +R3.System.GUI.prototype.buildColorControl = function(folder, componentTemplate, property) { var object = componentTemplate.template; @@ -757,7 +757,7 @@ GameLib.System.GUI.prototype.buildColorControl = function(folder, componentTempl }; -GameLib.System.GUI.prototype.buildObjectControl = function(folder, componentTemplate, property) { +R3.System.GUI.prototype.buildObjectControl = function(folder, componentTemplate, property) { var object = componentTemplate.template[property]; @@ -789,7 +789,7 @@ GameLib.System.GUI.prototype.buildObjectControl = function(folder, componentTemp } }; -GameLib.System.GUI.prototype.buildSelectControl = function(folder, componentTemplate, property) { +R3.System.GUI.prototype.buildSelectControl = function(folder, componentTemplate, property) { /** * We need to discover the constructor for this component @@ -811,7 +811,7 @@ GameLib.System.GUI.prototype.buildSelectControl = function(folder, componentTemp var object = componentTemplate.template; - var objects = GameLib.EntityManager.Instance.queryComponentsByConstructor(constructors); + var objects = R3.EntityManager.Instance.queryComponentsByConstructor(constructors); var idObject = {}; @@ -852,7 +852,7 @@ GameLib.System.GUI.prototype.buildSelectControl = function(folder, componentTemp ); }; -GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate, property) { +R3.System.GUI.prototype.buildControl = function(folder, componentTemplate, property) { var object = componentTemplate.template; @@ -872,13 +872,13 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate, var controllers = []; if ( - GameLib.Utils.isString(object[property]) || - GameLib.Utils.isBoolean(object[property]) + R3.Utils.isString(object[property]) || + R3.Utils.isBoolean(object[property]) ) { controllers.push(folder.add(object, property)); } - if (GameLib.Utils.isNumber(object[property])) { + if (R3.Utils.isNumber(object[property])) { var grain = 0.001; @@ -889,7 +889,7 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate, if (property === 'componentType') { var readOnly = { - componentType : GameLib.Component.GetComponentInfo(object[property]).name + componentType : R3.Component.GetComponentInfo(object[property]).name }; controllers.push( @@ -904,14 +904,14 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate, object, property, { - '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 + 'animation' : R3.System.SYSTEM_TYPE_ANIMATION, + 'gui' : R3.System.SYSTEM_TYPE_GUI, + 'input' : R3.System.SYSTEM_TYPE_INPUT, + 'render' : R3.System.SYSTEM_TYPE_RENDER, + 'storage' : R3.System.SYSTEM_TYPE_STORAGE, + 'linking' : R3.System.SYSTEM_TYPE_LINKING, + 'physics' : R3.System.SYSTEM_TYPE_PHYSICS, + 'custom code' : R3.System.SYSTEM_TYPE_CUSTOM } ) ); @@ -921,10 +921,10 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate, object, property, { - 'touch' : GameLib.API.Controls.CONTROLS_TYPE_TOUCH, - 'mouse' : GameLib.API.Controls.CONTROLS_TYPE_MOUSE, - 'keyboard' : GameLib.API.Controls.CONTROLS_TYPE_KEYBOARD, - 'editor' : GameLib.API.Controls.CONTROLS_TYPE_EDITOR + 'touch' : R3.API.Controls.CONTROLS_TYPE_TOUCH, + 'mouse' : R3.API.Controls.CONTROLS_TYPE_MOUSE, + 'keyboard' : R3.API.Controls.CONTROLS_TYPE_KEYBOARD, + 'editor' : R3.API.Controls.CONTROLS_TYPE_EDITOR } ) ); @@ -934,9 +934,9 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate, object, property, { - 'stereo' : GameLib.D3.API.Camera.Stereo.STEREO_MODE_STEREO, - 'anaglyph' : GameLib.D3.API.Camera.Stereo.STEREO_MODE_ANAGLYPH, - 'parallax' : GameLib.D3.API.Camera.Stereo.STEREO_MODE_PARALLAX + 'stereo' : R3.D3.API.Camera.Stereo.STEREO_MODE_STEREO, + 'anaglyph' : R3.D3.API.Camera.Stereo.STEREO_MODE_ANAGLYPH, + 'parallax' : R3.D3.API.Camera.Stereo.STEREO_MODE_PARALLAX } ) ); @@ -946,9 +946,9 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate, object, property, { - 'none' : GameLib.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_NONE, - 'fixed' : GameLib.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_FIXED, - 'based on current' : GameLib.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_BASED_ON_CURRENT + 'none' : R3.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_NONE, + 'fixed' : R3.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_FIXED, + 'based on current' : R3.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_BASED_ON_CURRENT } ) ); @@ -958,9 +958,9 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate, object, property, { - 'none' : GameLib.API.Socket.TYPE_NONE, - 'cast' : GameLib.API.Socket.TYPE_CAST, - 'receive' : GameLib.API.Socket.TYPE_RECEIVE + 'none' : R3.API.Socket.TYPE_NONE, + 'cast' : R3.API.Socket.TYPE_CAST, + 'receive' : R3.API.Socket.TYPE_RECEIVE } ) ); @@ -970,10 +970,10 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate, object, property, { - 'room': GameLib.API.Socket.Cast.CAST_TYPE_ROOM, - 'peer': GameLib.API.Socket.Cast.CAST_TYPE_PEER , - 'all': GameLib.API.Socket.Cast.CAST_TYPE_ALL, - 'all but peer': GameLib.API.Socket.Cast.CAST_TYPE_ALL_BUT_PEER + 'room': R3.API.Socket.Cast.CAST_TYPE_ROOM, + 'peer': R3.API.Socket.Cast.CAST_TYPE_PEER , + 'all': R3.API.Socket.Cast.CAST_TYPE_ALL, + 'all but peer': R3.API.Socket.Cast.CAST_TYPE_ALL_BUT_PEER } ) ); @@ -983,8 +983,8 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate, object, property, { - 'room': GameLib.API.Socket.Receive.RECEIVE_TYPE_ROOM, - 'peer': GameLib.API.Socket.Cast.RECEIVE_TYPE_PEER + 'room': R3.API.Socket.Receive.RECEIVE_TYPE_ROOM, + 'peer': R3.API.Socket.Cast.RECEIVE_TYPE_PEER } ) ); @@ -994,9 +994,9 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate, object, property, { - 'canvas': GameLib.API.Renderer.MODE_CANVAS, - 'target': GameLib.API.Renderer.MODE_TARGET, - 'canvas and target': GameLib.API.Renderer.MODE_CANVAS_AND_TARGET + 'canvas': R3.API.Renderer.MODE_CANVAS, + 'target': R3.API.Renderer.MODE_TARGET, + 'canvas and target': R3.API.Renderer.MODE_CANVAS_AND_TARGET } ) ); @@ -1006,9 +1006,9 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate, object, property, { - 'triangles' : GameLib.D3.API.Mesh.DRAW_MODE_TRIANGLES, - 'triangle strip' : GameLib.D3.API.Mesh.DRAW_MODE_TRIANGLE_STRIP, - 'triangle fan' : GameLib.D3.API.Mesh.DRAW_MODE_TRIANGLE_FAN + 'triangles' : R3.D3.API.Mesh.DRAW_MODE_TRIANGLES, + 'triangle strip' : R3.D3.API.Mesh.DRAW_MODE_TRIANGLE_STRIP, + 'triangle fan' : R3.D3.API.Mesh.DRAW_MODE_TRIANGLE_FAN } ) ); @@ -1018,8 +1018,8 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate, object, property, { - 'directional': GameLib.D3.API.Shadow.SHADOW_TYPE_DIRECTIONAL, - 'spot': GameLib.D3.API.Shadow.SHADOW_TYPE_SPOT + 'directional': R3.D3.API.Shadow.SHADOW_TYPE_DIRECTIONAL, + 'spot': R3.D3.API.Shadow.SHADOW_TYPE_SPOT } ) ); @@ -1029,9 +1029,9 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate, object, property, { - 'basic': GameLib.API.Renderer.SHADOW_MAP_TYPE_BASIC, - 'pcf': GameLib.API.Renderer.SHADOW_MAP_TYPE_PCF, - 'pcf soft': GameLib.API.Renderer.SHADOW_MAP_TYPE_PCF_SOFT + 'basic': R3.API.Renderer.SHADOW_MAP_TYPE_BASIC, + 'pcf': R3.API.Renderer.SHADOW_MAP_TYPE_PCF, + 'pcf soft': R3.API.Renderer.SHADOW_MAP_TYPE_PCF_SOFT } ) ); @@ -1041,10 +1041,10 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate, object, property, { - 'linear': GameLib.API.Renderer.TONE_MAPPING_LINEAR, - 'reinhard': GameLib.API.Renderer.TONE_MAPPING_REINHARD, - 'uncharted 2': GameLib.API.Renderer.TONE_MAPPING_UNCHARTED_2, - 'cineon': GameLib.API.Renderer.TONE_MAPPING_CINEON + 'linear': R3.API.Renderer.TONE_MAPPING_LINEAR, + 'reinhard': R3.API.Renderer.TONE_MAPPING_REINHARD, + 'uncharted 2': R3.API.Renderer.TONE_MAPPING_UNCHARTED_2, + 'cineon': R3.API.Renderer.TONE_MAPPING_CINEON } ) ); @@ -1054,10 +1054,10 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate, object, property, { - 'constant': GameLib.D3.API.Particle.OPACITY_TYPE_CONSTANT, - 'fade out': GameLib.D3.API.Particle.OPACITY_TYPE_FADE_OUT_LINEAR, - 'fade in': GameLib.D3.API.Particle.OPACITY_TYPE_FADE_IN_LINEAR, - 'fade in / out': GameLib.D3.API.Particle.OPACITY_TYPE_FADE_IN_OUT_LINEAR + 'constant': R3.D3.API.Particle.OPACITY_TYPE_CONSTANT, + 'fade out': R3.D3.API.Particle.OPACITY_TYPE_FADE_OUT_LINEAR, + 'fade in': R3.D3.API.Particle.OPACITY_TYPE_FADE_IN_LINEAR, + 'fade in / out': R3.D3.API.Particle.OPACITY_TYPE_FADE_IN_OUT_LINEAR } ) ); @@ -1067,9 +1067,9 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate, object, property, { - 'constant': GameLib.D3.API.Particle.POSITION_OFFSET_TYPE_CONSTANT, - 'random': GameLib.D3.API.Particle.POSITION_OFFSET_TYPE_RANDOM, - 'function': GameLib.D3.API.Particle.POSITION_OFFSET_TYPE_FUNCTION + 'constant': R3.D3.API.Particle.POSITION_OFFSET_TYPE_CONSTANT, + 'random': R3.D3.API.Particle.POSITION_OFFSET_TYPE_RANDOM, + 'function': R3.D3.API.Particle.POSITION_OFFSET_TYPE_FUNCTION } ) ); @@ -1079,10 +1079,10 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate, object, property, { - 'constant': GameLib.D3.API.Particle.DIRECTION_TYPE_CONSTANT, - 'random': GameLib.D3.API.Particle.DIRECTION_TYPE_RANDOM, - 'random normalized': GameLib.D3.API.Particle.DIRECTION_TYPE_RANDOM_NORMALIZED, - 'function': GameLib.D3.API.Particle.DIRECTION_TYPE_FUNCTION + 'constant': R3.D3.API.Particle.DIRECTION_TYPE_CONSTANT, + 'random': R3.D3.API.Particle.DIRECTION_TYPE_RANDOM, + 'random normalized': R3.D3.API.Particle.DIRECTION_TYPE_RANDOM_NORMALIZED, + 'function': R3.D3.API.Particle.DIRECTION_TYPE_FUNCTION } ) ); @@ -1092,13 +1092,13 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate, object, property, { - 'constant': GameLib.D3.API.Particle.SPEED_TYPE_CONSTANT, - 'linear': GameLib.D3.API.Particle.SPEED_TYPE_LINEAR, - 'exponential': GameLib.D3.API.Particle.SPEED_TYPE_EXPONENTIAL, - 'logarithmic': GameLib.D3.API.Particle.SPEED_TYPE_LOGARITHMIC, - '1 / log': GameLib.D3.API.Particle.SPEED_TYPE_ONE_OVER_LOG, - 'exp' : GameLib.D3.API.Particle.SPEED_TYPE_EXP, - '1 / exp' : GameLib.D3.API.Particle.SPEED_TYPE_ONE_OVER_EXP + 'constant': R3.D3.API.Particle.SPEED_TYPE_CONSTANT, + 'linear': R3.D3.API.Particle.SPEED_TYPE_LINEAR, + 'exponential': R3.D3.API.Particle.SPEED_TYPE_EXPONENTIAL, + 'logarithmic': R3.D3.API.Particle.SPEED_TYPE_LOGARITHMIC, + '1 / log': R3.D3.API.Particle.SPEED_TYPE_ONE_OVER_LOG, + 'exp' : R3.D3.API.Particle.SPEED_TYPE_EXP, + '1 / exp' : R3.D3.API.Particle.SPEED_TYPE_ONE_OVER_EXP } ) ); @@ -1108,12 +1108,12 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate, object, property, { - 'constant': GameLib.D3.API.Particle.SCALE_TYPE_CONSTANT, - 'linear': GameLib.D3.API.Particle.SCALE_TYPE_LINEAR, - 'exponential': GameLib.D3.API.Particle.SCALE_TYPE_EXPONENTIAL, - 'random': GameLib.D3.API.Particle.SCALE_TYPE_RANDOM, - 'random (x = y)': GameLib.D3.API.Particle.SCALE_TYPE_RANDOM_X_EQUALS_Y, - 'function': GameLib.D3.API.Particle.SCALE_TYPE_FUNCTION + 'constant': R3.D3.API.Particle.SCALE_TYPE_CONSTANT, + 'linear': R3.D3.API.Particle.SCALE_TYPE_LINEAR, + 'exponential': R3.D3.API.Particle.SCALE_TYPE_EXPONENTIAL, + 'random': R3.D3.API.Particle.SCALE_TYPE_RANDOM, + 'random (x = y)': R3.D3.API.Particle.SCALE_TYPE_RANDOM_X_EQUALS_Y, + 'function': R3.D3.API.Particle.SCALE_TYPE_FUNCTION } ) ); @@ -1123,12 +1123,12 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate, object, property, { - 'constant': GameLib.D3.API.Particle.ROTATION_TYPE_CONSTANT, - 'random': GameLib.D3.API.Particle.ROTATION_TYPE_RANDOM, - 'random - x': GameLib.D3.API.Particle.ROTATION_TYPE_RANDOM_X, - 'random - y': GameLib.D3.API.Particle.ROTATION_TYPE_RANDOM_Y, - 'random - z': GameLib.D3.API.Particle.ROTATION_TYPE_RANDOM_Z, - 'function': GameLib.D3.API.Particle.ROTATION_TYPE_FUNCTION + 'constant': R3.D3.API.Particle.ROTATION_TYPE_CONSTANT, + 'random': R3.D3.API.Particle.ROTATION_TYPE_RANDOM, + 'random - x': R3.D3.API.Particle.ROTATION_TYPE_RANDOM_X, + 'random - y': R3.D3.API.Particle.ROTATION_TYPE_RANDOM_Y, + 'random - z': R3.D3.API.Particle.ROTATION_TYPE_RANDOM_Z, + 'function': R3.D3.API.Particle.ROTATION_TYPE_FUNCTION } ) ); @@ -1138,9 +1138,9 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate, object, property, { - 'naive': GameLib.D3.Broadphase.BROADPHASE_TYPE_NAIVE, - 'grid': GameLib.D3.Broadphase.BROADPHASE_TYPE_GRID, - 'sap': GameLib.D3.Broadphase.BROADPHASE_TYPE_SAP + 'naive': R3.D3.Broadphase.BROADPHASE_TYPE_NAIVE, + 'grid': R3.D3.Broadphase.BROADPHASE_TYPE_GRID, + 'sap': R3.D3.Broadphase.BROADPHASE_TYPE_SAP } ) ); @@ -1150,8 +1150,8 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate, object, property, { - 'gs': GameLib.D3.API.Solver.GS_SOLVER, - 'split': GameLib.D3.API.Solver.SPLIT_SOLVER + 'gs': R3.D3.API.Solver.GS_SOLVER, + 'split': R3.D3.API.Solver.SPLIT_SOLVER } ) ); @@ -1161,14 +1161,14 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate, object, property, { - 'normal' : GameLib.D3.API.Object.OBJECT_TYPE_MESH, - 'curve' : GameLib.D3.API.Object.OBJECT_TYPE_MESH_CURVE, - 'skinned' : GameLib.D3.API.Object.OBJECT_TYPE_MESH_SKINNED, - 'plane' : GameLib.D3.API.Object.OBJECT_TYPE_MESH_PLANE, - 'sphere' : GameLib.D3.API.Object.OBJECT_TYPE_MESH_SPHERE, - 'box' : GameLib.D3.API.Object.OBJECT_TYPE_MESH_BOX, - 'cylinder' : GameLib.D3.API.Object.OBJECT_TYPE_MESH_CYLINDER, - 'text' : GameLib.D3.API.Object.OBJECT_TYPE_MESH_TEXT + 'normal' : R3.D3.API.Object.OBJECT_TYPE_MESH, + 'curve' : R3.D3.API.Object.OBJECT_TYPE_MESH_CURVE, + 'skinned' : R3.D3.API.Object.OBJECT_TYPE_MESH_SKINNED, + 'plane' : R3.D3.API.Object.OBJECT_TYPE_MESH_PLANE, + 'sphere' : R3.D3.API.Object.OBJECT_TYPE_MESH_SPHERE, + 'box' : R3.D3.API.Object.OBJECT_TYPE_MESH_BOX, + 'cylinder' : R3.D3.API.Object.OBJECT_TYPE_MESH_CYLINDER, + 'text' : R3.D3.API.Object.OBJECT_TYPE_MESH_TEXT } ) ); @@ -1178,10 +1178,10 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate, object, property, { - 'perspective' : GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_PERSPECTIVE, - 'orthographic' : GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_ORTHOGRAPHIC, - 'stereo' : GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_STEREO, - 'cube' : GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_CUBE + 'perspective' : R3.D3.API.Object.OBJECT_TYPE_CAMERA_PERSPECTIVE, + 'orthographic' : R3.D3.API.Object.OBJECT_TYPE_CAMERA_ORTHOGRAPHIC, + 'stereo' : R3.D3.API.Object.OBJECT_TYPE_CAMERA_STEREO, + 'cube' : R3.D3.API.Object.OBJECT_TYPE_CAMERA_CUBE } ) ); @@ -1191,10 +1191,10 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate, object, property, { - 'ssao': GameLib.D3.API.Pass.PASS_TYPE_SSAO, - 'bloom': GameLib.D3.API.Pass.PASS_TYPE_BLOOM, - 'fxaa': GameLib.D3.API.Pass.PASS_TYPE_FXAA, - 'render': GameLib.D3.API.Pass.PASS_TYPE_RENDER + 'ssao': R3.D3.API.Pass.PASS_TYPE_SSAO, + 'bloom': R3.D3.API.Pass.PASS_TYPE_BLOOM, + 'fxaa': R3.D3.API.Pass.PASS_TYPE_FXAA, + 'render': R3.D3.API.Pass.PASS_TYPE_RENDER } ) ); @@ -1204,8 +1204,8 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate, object, property, { - '2D': GameLib.API.Renderer.RENDERER_TYPE_2D, - '3D': GameLib.API.Renderer.RENDERER_TYPE_3D + '2D': R3.API.Renderer.RENDERER_TYPE_2D, + '3D': R3.API.Renderer.RENDERER_TYPE_3D } ) ); @@ -1215,14 +1215,14 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate, object, property, { - 'standard': GameLib.D3.API.Material.MATERIAL_TYPE_STANDARD, - 'basic': GameLib.D3.API.Material.MATERIAL_TYPE_BASIC, - 'phong': GameLib.D3.API.Material.MATERIAL_TYPE_PHONG, - 'shader': GameLib.D3.API.Material.MATERIAL_TYPE_SHADER, - 'raw shader': GameLib.D3.API.Material.MATERIAL_TYPE_SHADER_RAW, - 'points': GameLib.D3.API.Material.MATERIAL_TYPE_POINTS - // 'toon': GameLib.D3.API.Material.MATERIAL_TYPE_TOON, - // 'line basic' : GameLib.D3.API.Material.MATERIAL_TYPE_LINE_BASIC + 'standard': R3.D3.API.Material.MATERIAL_TYPE_STANDARD, + 'basic': R3.D3.API.Material.MATERIAL_TYPE_BASIC, + 'phong': R3.D3.API.Material.MATERIAL_TYPE_PHONG, + 'shader': R3.D3.API.Material.MATERIAL_TYPE_SHADER, + 'raw shader': R3.D3.API.Material.MATERIAL_TYPE_SHADER_RAW, + 'points': R3.D3.API.Material.MATERIAL_TYPE_POINTS + // 'toon': R3.D3.API.Material.MATERIAL_TYPE_TOON, + // 'line basic' : R3.D3.API.Material.MATERIAL_TYPE_LINE_BASIC } ) ); @@ -1232,9 +1232,9 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate, object, property, { - 'double': GameLib.D3.API.Material.TYPE_DOUBLE_SIDE, - 'front': GameLib.D3.API.Material.TYPE_FRONT_SIDE, - 'back': GameLib.D3.API.Material.TYPE_BACK_SIDE + 'double': R3.D3.API.Material.TYPE_DOUBLE_SIDE, + 'front': R3.D3.API.Material.TYPE_FRONT_SIDE, + 'back': R3.D3.API.Material.TYPE_BACK_SIDE } ) ); @@ -1244,9 +1244,9 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate, object, property, { - 'multiply': GameLib.D3.API.Material.COMBINE_MULTIPLY_OPERATION, - 'mix': GameLib.D3.API.Material.COMBINE_MIX_OPERATION, - 'add': GameLib.D3.API.Material.COMBINE_ADD_OPERATION + 'multiply': R3.D3.API.Material.COMBINE_MULTIPLY_OPERATION, + 'mix': R3.D3.API.Material.COMBINE_MIX_OPERATION, + 'add': R3.D3.API.Material.COMBINE_ADD_OPERATION } ) ); @@ -1256,9 +1256,9 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate, object, property, { - 'none': GameLib.D3.API.Material.TYPE_NO_COLORS, - 'face': GameLib.D3.API.Material.TYPE_FACE_COLORS, - 'vertex': GameLib.D3.API.Material.TYPE_VERTEX_COLORS + 'none': R3.D3.API.Material.TYPE_NO_COLORS, + 'face': R3.D3.API.Material.TYPE_FACE_COLORS, + 'vertex': R3.D3.API.Material.TYPE_VERTEX_COLORS } ) ); @@ -1268,12 +1268,12 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate, object, property, { - 'none': GameLib.D3.API.Material.TYPE_NO_BLENDING, - 'normal': GameLib.D3.API.Material.TYPE_NORMAL_BLENDING, - 'additive': GameLib.D3.API.Material.TYPE_ADDITIVE_BLENDING, - 'subtractive': GameLib.D3.API.Material.TYPE_SUBTRACTIVE_BLENDING, - 'multiply': GameLib.D3.API.Material.TYPE_MULTIPLY_BLENDING, - 'custom': GameLib.D3.API.Material.TYPE_CUSTOM_BLENDING + 'none': R3.D3.API.Material.TYPE_NO_BLENDING, + 'normal': R3.D3.API.Material.TYPE_NORMAL_BLENDING, + 'additive': R3.D3.API.Material.TYPE_ADDITIVE_BLENDING, + 'subtractive': R3.D3.API.Material.TYPE_SUBTRACTIVE_BLENDING, + 'multiply': R3.D3.API.Material.TYPE_MULTIPLY_BLENDING, + 'custom': R3.D3.API.Material.TYPE_CUSTOM_BLENDING } ) ); @@ -1283,17 +1283,17 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate, object, property, { - 'zero': GameLib.D3.API.Material.TYPE_ZERO_FACTOR, - 'one': GameLib.D3.API.Material.TYPE_ONE_FACTOR, - 'source color': GameLib.D3.API.Material.TYPE_SRC_COLOR_FACTOR, - 'one minus source color': GameLib.D3.API.Material.TYPE_ONE_MINUS_SRC_COLOR_FACTOR, - 'source alpha': GameLib.D3.API.Material.TYPE_SRC_ALPHA_FACTOR, - 'one minus source alpha': GameLib.D3.API.Material.TYPE_ONE_MINUS_SRC_ALPHA_FACTOR, - 'destination alpha': GameLib.D3.API.Material.TYPE_DST_ALPHA_FACTOR, - 'one minus destination alpha': GameLib.D3.API.Material.TYPE_ONE_MINUS_DST_ALPHA_FACTOR, - 'destination color': GameLib.D3.API.Material.TYPE_DST_COLOR_FACTOR, - 'one minus destination color': GameLib.D3.API.Material.TYPE_ONE_MINUS_DST_COLOR_FACTOR, - 'source alpha saturate': GameLib.D3.API.Material.TYPE_SRC_ALPHA_SATURATE_FACTOR + 'zero': R3.D3.API.Material.TYPE_ZERO_FACTOR, + 'one': R3.D3.API.Material.TYPE_ONE_FACTOR, + 'source color': R3.D3.API.Material.TYPE_SRC_COLOR_FACTOR, + 'one minus source color': R3.D3.API.Material.TYPE_ONE_MINUS_SRC_COLOR_FACTOR, + 'source alpha': R3.D3.API.Material.TYPE_SRC_ALPHA_FACTOR, + 'one minus source alpha': R3.D3.API.Material.TYPE_ONE_MINUS_SRC_ALPHA_FACTOR, + 'destination alpha': R3.D3.API.Material.TYPE_DST_ALPHA_FACTOR, + 'one minus destination alpha': R3.D3.API.Material.TYPE_ONE_MINUS_DST_ALPHA_FACTOR, + 'destination color': R3.D3.API.Material.TYPE_DST_COLOR_FACTOR, + 'one minus destination color': R3.D3.API.Material.TYPE_ONE_MINUS_DST_COLOR_FACTOR, + 'source alpha saturate': R3.D3.API.Material.TYPE_SRC_ALPHA_SATURATE_FACTOR } ) ); @@ -1303,17 +1303,17 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate, object, property, { - 'zero': GameLib.D3.API.Material.TYPE_ZERO_FACTOR, - 'one': GameLib.D3.API.Material.TYPE_ONE_FACTOR, - 'source color': GameLib.D3.API.Material.TYPE_SRC_COLOR_FACTOR, - 'one minus source color': GameLib.D3.API.Material.TYPE_ONE_MINUS_SRC_COLOR_FACTOR, - 'source alpha': GameLib.D3.API.Material.TYPE_SRC_ALPHA_FACTOR, - 'one minus source alpha': GameLib.D3.API.Material.TYPE_ONE_MINUS_SRC_ALPHA_FACTOR, - 'destination alpha': GameLib.D3.API.Material.TYPE_DST_ALPHA_FACTOR, - 'one minus destination alpha': GameLib.D3.API.Material.TYPE_ONE_MINUS_DST_ALPHA_FACTOR, - 'destination color': GameLib.D3.API.Material.TYPE_DST_COLOR_FACTOR, - 'one minus destination color': GameLib.D3.API.Material.TYPE_ONE_MINUS_DST_COLOR_FACTOR, - 'source alpha saturate': GameLib.D3.API.Material.TYPE_SRC_ALPHA_SATURATE_FACTOR + 'zero': R3.D3.API.Material.TYPE_ZERO_FACTOR, + 'one': R3.D3.API.Material.TYPE_ONE_FACTOR, + 'source color': R3.D3.API.Material.TYPE_SRC_COLOR_FACTOR, + 'one minus source color': R3.D3.API.Material.TYPE_ONE_MINUS_SRC_COLOR_FACTOR, + 'source alpha': R3.D3.API.Material.TYPE_SRC_ALPHA_FACTOR, + 'one minus source alpha': R3.D3.API.Material.TYPE_ONE_MINUS_SRC_ALPHA_FACTOR, + 'destination alpha': R3.D3.API.Material.TYPE_DST_ALPHA_FACTOR, + 'one minus destination alpha': R3.D3.API.Material.TYPE_ONE_MINUS_DST_ALPHA_FACTOR, + 'destination color': R3.D3.API.Material.TYPE_DST_COLOR_FACTOR, + 'one minus destination color': R3.D3.API.Material.TYPE_ONE_MINUS_DST_COLOR_FACTOR, + 'source alpha saturate': R3.D3.API.Material.TYPE_SRC_ALPHA_SATURATE_FACTOR } ) ); @@ -1323,11 +1323,11 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate, object, property, { - 'add': GameLib.D3.API.Material.TYPE_ADD_EQUATION, - 'subtract': GameLib.D3.API.Material.TYPE_SUBTRACT_EQUATION, - 'reverse subtract': GameLib.D3.API.Material.TYPE_REVERSE_SUBTRACT_EQUATION, - 'min': GameLib.D3.API.Material.TYPE_MIN_EQUATION, - 'max': GameLib.D3.API.Material.TYPE_MAX_EQUATION + 'add': R3.D3.API.Material.TYPE_ADD_EQUATION, + 'subtract': R3.D3.API.Material.TYPE_SUBTRACT_EQUATION, + 'reverse subtract': R3.D3.API.Material.TYPE_REVERSE_SUBTRACT_EQUATION, + 'min': R3.D3.API.Material.TYPE_MIN_EQUATION, + 'max': R3.D3.API.Material.TYPE_MAX_EQUATION } ) ); @@ -1337,14 +1337,14 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate, object, property, { - 'never': GameLib.D3.API.Material.TYPE_NEVER_DEPTH, - 'always': GameLib.D3.API.Material.TYPE_ALWAYS_DEPTH, - 'less depth': GameLib.D3.API.Material.TYPE_LESS_DEPTH, - 'less equal depth': GameLib.D3.API.Material.TYPE_LESS_EQUAL_DEPTH, - 'equal depth': GameLib.D3.API.Material.TYPE_EQUAL_DEPTH, - 'greated equal depth': GameLib.D3.API.Material.TYPE_GREATER_EQUAL_DEPTH, - 'greated depth': GameLib.D3.API.Material.TYPE_GREATER_DEPTH, - 'not equal depth': GameLib.D3.API.Material.TYPE_NOT_EQUAL_DEPTH + 'never': R3.D3.API.Material.TYPE_NEVER_DEPTH, + 'always': R3.D3.API.Material.TYPE_ALWAYS_DEPTH, + 'less depth': R3.D3.API.Material.TYPE_LESS_DEPTH, + 'less equal depth': R3.D3.API.Material.TYPE_LESS_EQUAL_DEPTH, + 'equal depth': R3.D3.API.Material.TYPE_EQUAL_DEPTH, + 'greated equal depth': R3.D3.API.Material.TYPE_GREATER_EQUAL_DEPTH, + 'greated depth': R3.D3.API.Material.TYPE_GREATER_DEPTH, + 'not equal depth': R3.D3.API.Material.TYPE_NOT_EQUAL_DEPTH } ) ); @@ -1354,9 +1354,9 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate, object, property, { - '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 + 'repeat': R3.D3.API.Texture.TYPE_REPEAT_WRAPPING, + 'clamp': R3.D3.API.Texture.TYPE_CLAMP_TO_EDGE_WRAPPING, + 'mirrored repeat': R3.D3.API.Texture.TYPE_MIRRORED_REPEAT_WRAPPING } ) ); @@ -1366,9 +1366,9 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate, object, property, { - '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 + 'repeat': R3.D3.API.Texture.TYPE_REPEAT_WRAPPING, + 'clamp': R3.D3.API.Texture.TYPE_CLAMP_TO_EDGE_WRAPPING, + 'mirrored repeat': R3.D3.API.Texture.TYPE_MIRRORED_REPEAT_WRAPPING } ) ); @@ -1378,12 +1378,12 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate, object, property, { - '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 + 'alpha': R3.D3.API.Texture.TYPE_ALPHA_FORMAT, + 'rgb': R3.D3.API.Texture.TYPE_RGB_FORMAT, + 'rgba': R3.D3.API.Texture.TYPE_RGBA_FORMAT, + 'luminance': R3.D3.API.Texture.TYPE_LUMINANCE_FORMAT, + 'luminance alpha': R3.D3.API.Texture.TYPE_LUMINANCE_ALPHA_FORMAT, + 'depth': R3.D3.API.Texture.TYPE_DEPTH_FORMAT } ) ); @@ -1393,14 +1393,14 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate, object, property, { - '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 + 'uv': R3.D3.API.Texture.TYPE_UV_MAPPING, + 'cube reflection': R3.D3.API.Texture.TYPE_CUBE_REFLECTION_MAPPING, + 'cube refraction': R3.D3.API.Texture.TYPE_CUBE_REFRACTION_MAPPING, + 'equi rectangular reflection': R3.D3.API.Texture.TYPE_EQUI_RECTANGULAR_REFLECTION_MAPPING, + 'equi rectangular refraction': R3.D3.API.Texture.TYPE_EQUI_RECTANGULAR_REFRACTION_MAPPING, + 'spherical reflection': R3.D3.API.Texture.TYPE_SPHERICAL_REFLECTION_MAPPING, + 'cube uv reflection': R3.D3.API.Texture.TYPE_CUBE_UV_REFLECTION_MAPPING, + 'cube uv refraction': R3.D3.API.Texture.TYPE_CUBE_UV_REFRACTION_MAPPING } ) ); @@ -1410,12 +1410,12 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate, object, property, { - '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 + 'nearest': R3.D3.API.Texture.TYPE_NEAREST_FILTER, + 'nearest mipmap nearest': R3.D3.API.Texture.TYPE_NEAREST_MIPMAP_NEAREST_FILTER, + 'nearest mipmap linear': R3.D3.API.Texture.TYPE_NEAREST_MIPMAP_LINEAR_FILTER, + 'linear': R3.D3.API.Texture.TYPE_LINEAR_FILTER, + 'linear mipmap nearest': R3.D3.API.Texture.TYPE_LINEAR_MIPMAP_NEAREST_FILTER, + 'linear mipmap linear': R3.D3.API.Texture.TYPE_LINEAR_MIPMAP_LINEAR_FILTER } ) ); @@ -1425,12 +1425,12 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate, object, property, { - '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 + 'nearest': R3.D3.API.Texture.TYPE_NEAREST_FILTER, + 'nearest mipmap nearest': R3.D3.API.Texture.TYPE_NEAREST_MIPMAP_NEAREST_FILTER, + 'nearest mipmap linear': R3.D3.API.Texture.TYPE_NEAREST_MIPMAP_LINEAR_FILTER, + 'linear': R3.D3.API.Texture.TYPE_LINEAR_FILTER, + 'linear mipmap nearest': R3.D3.API.Texture.TYPE_LINEAR_MIPMAP_NEAREST_FILTER, + 'linear mipmap linear': R3.D3.API.Texture.TYPE_LINEAR_MIPMAP_LINEAR_FILTER } ) ); @@ -1440,10 +1440,10 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate, object, property, { - 'normal': GameLib.D3.API.Texture.TEXTURE_TYPE_NONE, - 'image': GameLib.D3.API.Texture.TEXTURE_TYPE_IMAGE, - 'cube': GameLib.D3.API.Texture.TEXTURE_TYPE_CUBE, - 'canvas': GameLib.D3.API.Texture.TEXTURE_TYPE_CANVAS + 'normal': R3.D3.API.Texture.TEXTURE_TYPE_NONE, + 'image': R3.D3.API.Texture.TEXTURE_TYPE_IMAGE, + 'cube': R3.D3.API.Texture.TEXTURE_TYPE_CUBE, + 'canvas': R3.D3.API.Texture.TEXTURE_TYPE_CANVAS } ) ); @@ -1453,14 +1453,14 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate, object, property, { - '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 + 'unsigned byte': R3.D3.API.Texture.TYPE_UNSIGNED_BYTE, + 'byte': R3.D3.API.Texture.TYPE_BYTE, + 'short': R3.D3.API.Texture.TYPE_SHORT, + 'unsigned short': R3.D3.API.Texture.TYPE_UNSIGNED_SHORT, + 'int': R3.D3.API.Texture.TYPE_INT, + 'unsigned int': R3.D3.API.Texture.TYPE_UNSIGNED_INT, + 'float': R3.D3.API.Texture.TYPE_FLOAT, + 'half float': R3.D3.API.Texture.TYPE_HALF_FLOAT } ) ); @@ -1470,12 +1470,12 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate, object, property, { - 'none': GameLib.API.Renderer.ASPECT_RATIO_NONE, - '4:3 (1.3333)': GameLib.API.Renderer.ASPECT_RATIO_4_3, - '3:2 (1.5)': GameLib.API.Renderer.ASPECT_RATIO_3_2, - '16:10 (1.6667)': GameLib.API.Renderer.ASPECT_RATIO_16_10, - '17:10 (1.7)': GameLib.API.Renderer.ASPECT_RATIO_17_10, - '16:9 (1.7778)': GameLib.API.Renderer.ASPECT_RATIO_16_9 + 'none': R3.API.Renderer.ASPECT_RATIO_NONE, + '4:3 (1.3333)': R3.API.Renderer.ASPECT_RATIO_4_3, + '3:2 (1.5)': R3.API.Renderer.ASPECT_RATIO_3_2, + '16:10 (1.6667)': R3.API.Renderer.ASPECT_RATIO_16_10, + '17:10 (1.7)': R3.API.Renderer.ASPECT_RATIO_17_10, + '16:9 (1.7778)': R3.API.Renderer.ASPECT_RATIO_16_9 } ) ); @@ -1485,10 +1485,10 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate, object, property, { - 'none': GameLib.API.Renderer.SCALE_MODE_NONE, - 'letterbox': GameLib.API.Renderer.SCALE_MODE_LETTERBOX, - 'zoom-bigger': GameLib.API.Renderer.SCALE_MODE_ZOOM_TO_BIGGER, - 'non-uniform': GameLib.API.Renderer.SCALE_MODE_NON_UNIFORM + 'none': R3.API.Renderer.SCALE_MODE_NONE, + 'letterbox': R3.API.Renderer.SCALE_MODE_LETTERBOX, + 'zoom-bigger': R3.API.Renderer.SCALE_MODE_ZOOM_TO_BIGGER, + 'non-uniform': R3.API.Renderer.SCALE_MODE_NON_UNIFORM } ) ); @@ -1498,14 +1498,14 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate, object, property, { - '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 + 'linear': R3.D3.API.Texture.TYPE_LINEAR_ENCODING, + 'srgb': R3.D3.API.Texture.TYPE_SRGB_ENCODING, + 'gamma': R3.D3.API.Texture.TYPE_GAMMA_ENCODING, + 'rgbe': R3.D3.API.Texture.TYPE_RGBE_ENCODING, + 'log luv': R3.D3.API.Texture.TYPE_LOG_LUV_ENCODING, + 'rgbm7': R3.D3.API.Texture.TYPE_RGBM7_ENCODING, + 'rgbm16': R3.D3.API.Texture.TYPE_RGBM16_ENCODING, + 'rgbd': R3.D3.API.Texture.TYPE_RGBD_ENCODING } ) ); @@ -1515,12 +1515,12 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate, object, property, { - 'ambient': GameLib.D3.API.Light.LIGHT_TYPE_AMBIENT, - 'directional': GameLib.D3.API.Light.LIGHT_TYPE_DIRECTIONAL, - 'spot': GameLib.D3.API.Light.LIGHT_TYPE_SPOT, - 'point': GameLib.D3.API.Light.LIGHT_TYPE_POINT, - 'hemisphere': GameLib.D3.API.Light.LIGHT_TYPE_HEMISPHERE, - 'rect area': GameLib.D3.API.Light.LIGHT_TYPE_RECT_AREA + 'ambient': R3.D3.API.Light.LIGHT_TYPE_AMBIENT, + 'directional': R3.D3.API.Light.LIGHT_TYPE_DIRECTIONAL, + 'spot': R3.D3.API.Light.LIGHT_TYPE_SPOT, + 'point': R3.D3.API.Light.LIGHT_TYPE_POINT, + 'hemisphere': R3.D3.API.Light.LIGHT_TYPE_HEMISPHERE, + 'rect area': R3.D3.API.Light.LIGHT_TYPE_RECT_AREA } ) ); @@ -1530,7 +1530,7 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate, for (var i = 0; i < 200; i++) { try { - options[GameLib.Event.GetEventName(i)] = i; + options[R3.Event.GetEventName(i)] = i; } catch (error) { } @@ -1549,9 +1549,9 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate, object, property, { - 'rotation': GameLib.D3.Animation.ANIMATION_FUNCTION_TYPE_ROTATION, - 'translation': GameLib.D3.Animation.ANIMATION_FUNCTION_TYPE_TRANSLATION, - 'scale': GameLib.D3.Animation.ANIMATION_FUNCTION_TYPE_SCALE + 'rotation': R3.D3.Animation.ANIMATION_FUNCTION_TYPE_ROTATION, + 'translation': R3.D3.Animation.ANIMATION_FUNCTION_TYPE_TRANSLATION, + 'scale': R3.D3.Animation.ANIMATION_FUNCTION_TYPE_SCALE } ) ); @@ -1624,7 +1624,7 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate, property === 'radius' ) { - if (object instanceof GameLib.D3.Pass.Bloom) { + if (object instanceof R3.D3.Pass.Bloom) { controllers.push(folder.add(object, property, -10, 10, 0.001)); } else { controllers.push(folder.add(object, property, 0, 1000, 0.1)); @@ -1754,12 +1754,12 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate, * otherwise, just to our normal components * @param data */ -GameLib.System.GUI.prototype.meshSelected = function(data) { +R3.System.GUI.prototype.meshSelected = function(data) { if (this.exclusiveMode) { - GameLib.Utils.PushUnique(this.backupComponents, data.mesh); + R3.Utils.PushUnique(this.backupComponents, data.mesh); } else { - GameLib.Utils.PushUnique(this.components, data.mesh); + R3.Utils.PushUnique(this.components, data.mesh); } }; @@ -1768,7 +1768,7 @@ GameLib.System.GUI.prototype.meshSelected = function(data) { * Same as selected above, but removes the mesh from the components * @param data */ -GameLib.System.GUI.prototype.meshDeslected = function(data) { +R3.System.GUI.prototype.meshDeslected = function(data) { var index = -1; @@ -1786,7 +1786,7 @@ GameLib.System.GUI.prototype.meshDeslected = function(data) { }; -GameLib.System.GUI.prototype.meshFaceSelected = function(data) { +R3.System.GUI.prototype.meshFaceSelected = function(data) { this.faces.push(data.face); @@ -1795,7 +1795,7 @@ GameLib.System.GUI.prototype.meshFaceSelected = function(data) { }) }; -GameLib.System.GUI.prototype.meshFaceDeselected = function(data) { +R3.System.GUI.prototype.meshFaceDeselected = function(data) { var index = this.faces.indexOf(data.face); @@ -1825,7 +1825,7 @@ GameLib.System.GUI.prototype.meshFaceDeselected = function(data) { * * @param data */ -GameLib.System.GUI.prototype.buildGUI = function(data) { +R3.System.GUI.prototype.buildGUI = function(data) { this.guis.map(function(gui){ @@ -1897,7 +1897,7 @@ GameLib.System.GUI.prototype.buildGUI = function(data) { */ this.components = this.components.filter( function (component) { - return (component instanceof GameLib.D3.Mesh); + return (component instanceof R3.D3.Mesh); } ); } @@ -1905,7 +1905,7 @@ GameLib.System.GUI.prototype.buildGUI = function(data) { /** * Check if we have components to build a GUI for */ - if (GameLib.Utils.UndefinedOrNull(this.components.length) || this.components.length < 1) { + if (R3.Utils.UndefinedOrNull(this.components.length) || this.components.length < 1) { // console.log('no components selected'); return; } @@ -1920,10 +1920,10 @@ GameLib.System.GUI.prototype.buildGUI = function(data) { var components = component.getChildrenComponents(); - GameLib.Utils.PushUnique(result, component); + R3.Utils.PushUnique(result, component); components.map(function(component){ - GameLib.Utils.PushUnique(result, component); + R3.Utils.PushUnique(result, component); }); return result; @@ -2009,7 +2009,7 @@ GameLib.System.GUI.prototype.buildGUI = function(data) { }); if (!duplicate) { - GameLib.Utils.PushUnique( + R3.Utils.PushUnique( componentGroups, { componentType : component.componentType, @@ -2095,10 +2095,10 @@ GameLib.System.GUI.prototype.buildGUI = function(data) { } if ( - result.template[property] instanceof GameLib.Vector2 || - result.template[property] instanceof GameLib.Vector3 || - result.template[property] instanceof GameLib.Vector4 || - result.template[property] instanceof GameLib.Quaternion + result.template[property] instanceof R3.Vector2 || + result.template[property] instanceof R3.Vector3 || + result.template[property] instanceof R3.Vector4 || + result.template[property] instanceof R3.Quaternion ) { if (!result.template[property].equals(component[property])) { delete result.template[property]; @@ -2129,8 +2129,8 @@ GameLib.System.GUI.prototype.buildGUI = function(data) { */ var name; - if (GameLib.Utils.UndefinedOrNull(componentTemplate.template.name)) { - name = GameLib.Component.GetComponentName(componentTemplate.componentType) + ' (All Selected (' + componentTemplate.affected.length + '))'; + if (R3.Utils.UndefinedOrNull(componentTemplate.template.name)) { + name = R3.Component.GetComponentName(componentTemplate.componentType) + ' (All Selected (' + componentTemplate.affected.length + '))'; } else { name = componentTemplate.template.name; } @@ -2157,15 +2157,15 @@ GameLib.System.GUI.prototype.buildGUI = function(data) { * We only want to affect runtime vectors because their onchange will execute updateInstance() */ if ( - componentTemplate.template[templateProperty] instanceof GameLib.Vector2 || - componentTemplate.template[templateProperty] instanceof GameLib.Vector3 || - componentTemplate.template[templateProperty] instanceof GameLib.Vector4 + componentTemplate.template[templateProperty] instanceof R3.Vector2 || + componentTemplate.template[templateProperty] instanceof R3.Vector3 || + componentTemplate.template[templateProperty] instanceof R3.Vector4 ) { this.buildVectorControl(folder, componentTemplate, templateProperty); continue; } - if (componentTemplate.template[templateProperty] instanceof GameLib.Quaternion) { + if (componentTemplate.template[templateProperty] instanceof R3.Quaternion) { this.buildQuaternionControl(folder, componentTemplate, templateProperty); } @@ -2205,7 +2205,7 @@ GameLib.System.GUI.prototype.buildGUI = function(data) { continue; } - if (componentTemplate.template[templateProperty] instanceof GameLib.Color) { + if (componentTemplate.template[templateProperty] instanceof R3.Color) { this.buildColorControl(folder, componentTemplate, templateProperty); continue; } @@ -2213,7 +2213,7 @@ GameLib.System.GUI.prototype.buildGUI = function(data) { if (typeof componentTemplate.template[templateProperty] === 'object') { if ( - componentTemplate.template[templateProperty] instanceof GameLib.Component || + componentTemplate.template[templateProperty] instanceof R3.Component || ( componentTemplate.template.linkedObjects && componentTemplate.template.linkedObjects[templateProperty] @@ -2235,7 +2235,7 @@ GameLib.System.GUI.prototype.buildGUI = function(data) { }; -GameLib.System.GUI.prototype.meshDeleted = function(data) { +R3.System.GUI.prototype.meshDeleted = function(data) { data.meshes.map(function(mesh){ this.meshDeslected({ @@ -2246,7 +2246,7 @@ GameLib.System.GUI.prototype.meshDeleted = function(data) { this.buildGUI(null); }; -GameLib.System.GUI.prototype.removeComponent = function(data) { +R3.System.GUI.prototype.removeComponent = function(data) { var index = this.backupComponents.indexOf(data.component); if (index !== -1) { @@ -2260,17 +2260,17 @@ GameLib.System.GUI.prototype.removeComponent = function(data) { }; -GameLib.System.GUI.prototype.castSourceChanged = function(data) { +R3.System.GUI.prototype.castSourceChanged = function(data) { this.buildGUI(null); }; -GameLib.System.GUI.prototype.receiveDestinationChanged = function(data) { +R3.System.GUI.prototype.receiveDestinationChanged = function(data) { this.buildGUI(null); }; -GameLib.System.GUI.prototype.stop = function() { +R3.System.GUI.prototype.stop = function() { - GameLib.System.prototype.stop.call(this); + R3.System.prototype.stop.call(this); this.guis.map(function(gui){ gui.domElement.instance.parentElement.removeChild(gui.instance.domElement); diff --git a/src/game-lib-system-input.js b/src/r3-system-input.js similarity index 74% rename from src/game-lib-system-input.js rename to src/r3-system-input.js index 74b1499..ee1b38f 100644 --- a/src/game-lib-system-input.js +++ b/src/r3-system-input.js @@ -1,14 +1,14 @@ /** * System takes care of updating all the entities (based on their component data) * @param graphics - * @param apiSystem GameLib.API.System + * @param apiSystem R3.API.System * @constructor */ -GameLib.System.Input = function( +R3.System.Input = function( graphics, apiSystem ) { - GameLib.System.call( + R3.System.call( this, apiSystem ); @@ -72,189 +72,189 @@ GameLib.System.Input = function( this.canvasChangeSubscription = null; this.selectionModeChangeSubscription = null; - this.selectionMode = GameLib.System.Input.SELECTION_MODE_DEFAULT; + this.selectionMode = R3.System.Input.SELECTION_MODE_DEFAULT; - this.mouse = new GameLib.Mouse(); - this.raycaster = new GameLib.D3.Raycaster(graphics); + this.mouse = new R3.Mouse(); + this.raycaster = new R3.D3.Raycaster(graphics); }; -GameLib.System.Input.prototype = Object.create(GameLib.System.prototype); -GameLib.System.Input.prototype.constructor = GameLib.System.Input; +R3.System.Input.prototype = Object.create(R3.System.prototype); +R3.System.Input.prototype.constructor = R3.System.Input; -GameLib.System.Input.SELECTION_MODE_MESH = 0x1; -GameLib.System.Input.SELECTION_MODE_FACE = 0x2; -GameLib.System.Input.SELECTION_MODE_DEFAULT = 0x1; +R3.System.Input.SELECTION_MODE_MESH = 0x1; +R3.System.Input.SELECTION_MODE_FACE = 0x2; +R3.System.Input.SELECTION_MODE_DEFAULT = 0x1; -GameLib.System.Input.KEY_CANCEL = 3; -GameLib.System.Input.KEY_HELP = 6; -GameLib.System.Input.KEY_BACK_SPACE = 8; -GameLib.System.Input.KEY_TAB = 9; -GameLib.System.Input.KEY_CLEAR = 12; -GameLib.System.Input.KEY_RETURN = 13; -GameLib.System.Input.KEY_ENTER = 14; -GameLib.System.Input.KEY_SHIFT = 16; -GameLib.System.Input.KEY_CONTROL = 17; -GameLib.System.Input.KEY_ALT = 18; -GameLib.System.Input.KEY_PAUSE = 19; -GameLib.System.Input.KEY_CAPS_LOCK = 20; -GameLib.System.Input.KEY_ESCAPE = 27; -GameLib.System.Input.KEY_SPACE = 32; -GameLib.System.Input.KEY_PAGE_UP = 33; -GameLib.System.Input.KEY_PAGE_DOWN = 34; -GameLib.System.Input.KEY_END = 35; -GameLib.System.Input.KEY_HOME = 36; -GameLib.System.Input.KEY_LEFT = 37; -GameLib.System.Input.KEY_UP = 38; -GameLib.System.Input.KEY_RIGHT = 39; -GameLib.System.Input.KEY_DOWN = 40; -GameLib.System.Input.KEY_PRINTSCREEN = 44; -GameLib.System.Input.KEY_INSERT = 45; -GameLib.System.Input.KEY_DELETE = 46; -GameLib.System.Input.KEY_0 = 48; -GameLib.System.Input.KEY_1 = 49; -GameLib.System.Input.KEY_2 = 50; -GameLib.System.Input.KEY_3 = 51; -GameLib.System.Input.KEY_4 = 52; -GameLib.System.Input.KEY_5 = 53; -GameLib.System.Input.KEY_6 = 54; -GameLib.System.Input.KEY_7 = 55; -GameLib.System.Input.KEY_8 = 56; -GameLib.System.Input.KEY_9 = 57; -GameLib.System.Input.KEY_SEMICOLON = 59; -GameLib.System.Input.KEY_EQUALS = 61; -GameLib.System.Input.KEY_A = 65; -GameLib.System.Input.KEY_B = 66; -GameLib.System.Input.KEY_C = 67; -GameLib.System.Input.KEY_D = 68; -GameLib.System.Input.KEY_E = 69; -GameLib.System.Input.KEY_F = 70; -GameLib.System.Input.KEY_G = 71; -GameLib.System.Input.KEY_H = 72; -GameLib.System.Input.KEY_I = 73; -GameLib.System.Input.KEY_J = 74; -GameLib.System.Input.KEY_K = 75; -GameLib.System.Input.KEY_L = 76; -GameLib.System.Input.KEY_M = 77; -GameLib.System.Input.KEY_N = 78; -GameLib.System.Input.KEY_O = 79; -GameLib.System.Input.KEY_P = 80; -GameLib.System.Input.KEY_Q = 81; -GameLib.System.Input.KEY_R = 82; -GameLib.System.Input.KEY_S = 83; -GameLib.System.Input.KEY_T = 84; -GameLib.System.Input.KEY_U = 85; -GameLib.System.Input.KEY_V = 86; -GameLib.System.Input.KEY_W = 87; -GameLib.System.Input.KEY_X = 88; -GameLib.System.Input.KEY_Y = 89; -GameLib.System.Input.KEY_Z = 90; -GameLib.System.Input.KEY_CONTEXT_MENU = 93; -GameLib.System.Input.KEY_NUMPAD0 = 96; -GameLib.System.Input.KEY_NUMPAD1 = 97; -GameLib.System.Input.KEY_NUMPAD2 = 98; -GameLib.System.Input.KEY_NUMPAD3 = 99; -GameLib.System.Input.KEY_NUMPAD4 = 100; -GameLib.System.Input.KEY_NUMPAD5 = 101; -GameLib.System.Input.KEY_NUMPAD6 = 102; -GameLib.System.Input.KEY_NUMPAD7 = 103; -GameLib.System.Input.KEY_NUMPAD8 = 104; -GameLib.System.Input.KEY_NUMPAD9 = 105; -GameLib.System.Input.KEY_MULTIPLY = 106; -GameLib.System.Input.KEY_ADD = 107; -GameLib.System.Input.KEY_SEPARATOR = 108; -GameLib.System.Input.KEY_SUBTRACT = 109; -GameLib.System.Input.KEY_DECIMAL = 110; -GameLib.System.Input.KEY_DIVIDE = 111; -GameLib.System.Input.KEY_F1 = 112; -GameLib.System.Input.KEY_F2 = 113; -GameLib.System.Input.KEY_F3 = 114; -GameLib.System.Input.KEY_F4 = 115; -GameLib.System.Input.KEY_F5 = 116; -GameLib.System.Input.KEY_F6 = 117; -GameLib.System.Input.KEY_F7 = 118; -GameLib.System.Input.KEY_F8 = 119; -GameLib.System.Input.KEY_F9 = 120; -GameLib.System.Input.KEY_F10 = 121; -GameLib.System.Input.KEY_F11 = 122; -GameLib.System.Input.KEY_F12 = 123; -GameLib.System.Input.KEY_F13 = 124; -GameLib.System.Input.KEY_F14 = 125; -GameLib.System.Input.KEY_F15 = 126; -GameLib.System.Input.KEY_F16 = 127; -GameLib.System.Input.KEY_F17 = 128; -GameLib.System.Input.KEY_F18 = 129; -GameLib.System.Input.KEY_F19 = 130; -GameLib.System.Input.KEY_F20 = 131; -GameLib.System.Input.KEY_F21 = 132; -GameLib.System.Input.KEY_F22 = 133; -GameLib.System.Input.KEY_F23 = 134; -GameLib.System.Input.KEY_F24 = 135; -GameLib.System.Input.KEY_NUM_LOCK = 144; -GameLib.System.Input.KEY_SCROLL_LOCK = 145; -GameLib.System.Input.KEY_COMMA = 188; -GameLib.System.Input.KEY_PERIOD = 190; -GameLib.System.Input.KEY_SLASH = 191; -GameLib.System.Input.KEY_BACK_QUOTE = 192; -GameLib.System.Input.KEY_OPEN_BRACKET = 219; -GameLib.System.Input.KEY_BACK_SLASH = 220; -GameLib.System.Input.KEY_CLOSE_BRACKET = 221; -GameLib.System.Input.KEY_QUOTE = 222; -GameLib.System.Input.KEY_META = 224; +R3.System.Input.KEY_CANCEL = 3; +R3.System.Input.KEY_HELP = 6; +R3.System.Input.KEY_BACK_SPACE = 8; +R3.System.Input.KEY_TAB = 9; +R3.System.Input.KEY_CLEAR = 12; +R3.System.Input.KEY_RETURN = 13; +R3.System.Input.KEY_ENTER = 14; +R3.System.Input.KEY_SHIFT = 16; +R3.System.Input.KEY_CONTROL = 17; +R3.System.Input.KEY_ALT = 18; +R3.System.Input.KEY_PAUSE = 19; +R3.System.Input.KEY_CAPS_LOCK = 20; +R3.System.Input.KEY_ESCAPE = 27; +R3.System.Input.KEY_SPACE = 32; +R3.System.Input.KEY_PAGE_UP = 33; +R3.System.Input.KEY_PAGE_DOWN = 34; +R3.System.Input.KEY_END = 35; +R3.System.Input.KEY_HOME = 36; +R3.System.Input.KEY_LEFT = 37; +R3.System.Input.KEY_UP = 38; +R3.System.Input.KEY_RIGHT = 39; +R3.System.Input.KEY_DOWN = 40; +R3.System.Input.KEY_PRINTSCREEN = 44; +R3.System.Input.KEY_INSERT = 45; +R3.System.Input.KEY_DELETE = 46; +R3.System.Input.KEY_0 = 48; +R3.System.Input.KEY_1 = 49; +R3.System.Input.KEY_2 = 50; +R3.System.Input.KEY_3 = 51; +R3.System.Input.KEY_4 = 52; +R3.System.Input.KEY_5 = 53; +R3.System.Input.KEY_6 = 54; +R3.System.Input.KEY_7 = 55; +R3.System.Input.KEY_8 = 56; +R3.System.Input.KEY_9 = 57; +R3.System.Input.KEY_SEMICOLON = 59; +R3.System.Input.KEY_EQUALS = 61; +R3.System.Input.KEY_A = 65; +R3.System.Input.KEY_B = 66; +R3.System.Input.KEY_C = 67; +R3.System.Input.KEY_D = 68; +R3.System.Input.KEY_E = 69; +R3.System.Input.KEY_F = 70; +R3.System.Input.KEY_G = 71; +R3.System.Input.KEY_H = 72; +R3.System.Input.KEY_I = 73; +R3.System.Input.KEY_J = 74; +R3.System.Input.KEY_K = 75; +R3.System.Input.KEY_L = 76; +R3.System.Input.KEY_M = 77; +R3.System.Input.KEY_N = 78; +R3.System.Input.KEY_O = 79; +R3.System.Input.KEY_P = 80; +R3.System.Input.KEY_Q = 81; +R3.System.Input.KEY_R = 82; +R3.System.Input.KEY_S = 83; +R3.System.Input.KEY_T = 84; +R3.System.Input.KEY_U = 85; +R3.System.Input.KEY_V = 86; +R3.System.Input.KEY_W = 87; +R3.System.Input.KEY_X = 88; +R3.System.Input.KEY_Y = 89; +R3.System.Input.KEY_Z = 90; +R3.System.Input.KEY_CONTEXT_MENU = 93; +R3.System.Input.KEY_NUMPAD0 = 96; +R3.System.Input.KEY_NUMPAD1 = 97; +R3.System.Input.KEY_NUMPAD2 = 98; +R3.System.Input.KEY_NUMPAD3 = 99; +R3.System.Input.KEY_NUMPAD4 = 100; +R3.System.Input.KEY_NUMPAD5 = 101; +R3.System.Input.KEY_NUMPAD6 = 102; +R3.System.Input.KEY_NUMPAD7 = 103; +R3.System.Input.KEY_NUMPAD8 = 104; +R3.System.Input.KEY_NUMPAD9 = 105; +R3.System.Input.KEY_MULTIPLY = 106; +R3.System.Input.KEY_ADD = 107; +R3.System.Input.KEY_SEPARATOR = 108; +R3.System.Input.KEY_SUBTRACT = 109; +R3.System.Input.KEY_DECIMAL = 110; +R3.System.Input.KEY_DIVIDE = 111; +R3.System.Input.KEY_F1 = 112; +R3.System.Input.KEY_F2 = 113; +R3.System.Input.KEY_F3 = 114; +R3.System.Input.KEY_F4 = 115; +R3.System.Input.KEY_F5 = 116; +R3.System.Input.KEY_F6 = 117; +R3.System.Input.KEY_F7 = 118; +R3.System.Input.KEY_F8 = 119; +R3.System.Input.KEY_F9 = 120; +R3.System.Input.KEY_F10 = 121; +R3.System.Input.KEY_F11 = 122; +R3.System.Input.KEY_F12 = 123; +R3.System.Input.KEY_F13 = 124; +R3.System.Input.KEY_F14 = 125; +R3.System.Input.KEY_F15 = 126; +R3.System.Input.KEY_F16 = 127; +R3.System.Input.KEY_F17 = 128; +R3.System.Input.KEY_F18 = 129; +R3.System.Input.KEY_F19 = 130; +R3.System.Input.KEY_F20 = 131; +R3.System.Input.KEY_F21 = 132; +R3.System.Input.KEY_F22 = 133; +R3.System.Input.KEY_F23 = 134; +R3.System.Input.KEY_F24 = 135; +R3.System.Input.KEY_NUM_LOCK = 144; +R3.System.Input.KEY_SCROLL_LOCK = 145; +R3.System.Input.KEY_COMMA = 188; +R3.System.Input.KEY_PERIOD = 190; +R3.System.Input.KEY_SLASH = 191; +R3.System.Input.KEY_BACK_QUOTE = 192; +R3.System.Input.KEY_OPEN_BRACKET = 219; +R3.System.Input.KEY_BACK_SLASH = 220; +R3.System.Input.KEY_CLOSE_BRACKET = 221; +R3.System.Input.KEY_QUOTE = 222; +R3.System.Input.KEY_META = 224; /** * */ -GameLib.System.Input.prototype.start = function() { +R3.System.Input.prototype.start = function() { - GameLib.System.prototype.start.call(this); + R3.System.prototype.start.call(this); - this.instanceCreatedSubscription = GameLib.Event.Subscribe( - GameLib.Event.INSTANCE_CREATED, + this.instanceCreatedSubscription = R3.Event.Subscribe( + R3.Event.INSTANCE_CREATED, this.instanceCreated.bind(this) ); - this.removeComponentSubscription = GameLib.Event.Subscribe( - GameLib.Event.REMOVE_COMPONENT, + this.removeComponentSubscription = R3.Event.Subscribe( + R3.Event.REMOVE_COMPONENT, this.removeComponent.bind(this) ); - this.delayedInstanceEncounteredSubscription = GameLib.Event.Subscribe( - GameLib.Event.DELAYED_INSTANCE_ENCOUNTERED, + this.delayedInstanceEncounteredSubscription = R3.Event.Subscribe( + R3.Event.DELAYED_INSTANCE_ENCOUNTERED, this.delayedInstanceEncountered.bind(this) ); - this.canvasChangeSubscription = GameLib.Event.Subscribe( - GameLib.Event.CANVAS_CHANGE, + this.canvasChangeSubscription = R3.Event.Subscribe( + R3.Event.CANVAS_CHANGE, this.canvasChange.bind(this) ); - this.beforeRenderSubscription = GameLib.Event.Subscribe( - GameLib.Event.BEFORE_RENDER, + this.beforeRenderSubscription = R3.Event.Subscribe( + R3.Event.BEFORE_RENDER, this.beforeRender.bind(this) ); - this.selectionModeChangeSubscription = GameLib.Event.Subscribe( - GameLib.Event.SELECTION_MODE_CHANGE, + this.selectionModeChangeSubscription = R3.Event.Subscribe( + R3.Event.SELECTION_MODE_CHANGE, this.selectionModeChange.bind(this) ); /** * Normal Controls */ - this.touchControls = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.CONTROLS_TOUCH); + this.touchControls = R3.EntityManager.Instance.queryComponents(R3.Component.CONTROLS_TOUCH); - this.keyboardControls = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.CONTROLS_KEYBOARD); + this.keyboardControls = R3.EntityManager.Instance.queryComponents(R3.Component.CONTROLS_KEYBOARD); - this.mouseControls = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.CONTROLS_MOUSE); + this.mouseControls = R3.EntityManager.Instance.queryComponents(R3.Component.CONTROLS_MOUSE); /** * Edit Mode Controls */ - this.editorControls = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.CONTROLS_EDITOR); + this.editorControls = R3.EntityManager.Instance.queryComponents(R3.Component.CONTROLS_EDITOR); - this.orbitControls = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.CONTROLS_ORBIT); + this.orbitControls = R3.EntityManager.Instance.queryComponents(R3.Component.CONTROLS_ORBIT); - this.firstPersonControls = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.CONTROLS_FIRST_PERSON); + this.firstPersonControls = R3.EntityManager.Instance.queryComponents(R3.Component.CONTROLS_FIRST_PERSON); this.setMode(); }; @@ -262,9 +262,9 @@ GameLib.System.Input.prototype.start = function() { /** * */ -GameLib.System.Input.prototype.stop = function() { +R3.System.Input.prototype.stop = function() { - GameLib.System.prototype.stop.call(this); + R3.System.prototype.stop.call(this); this.instanceCreatedSubscription.remove(); @@ -314,7 +314,7 @@ GameLib.System.Input.prototype.stop = function() { }; -GameLib.System.Input.prototype.setMode = function() { +R3.System.Input.prototype.setMode = function() { /** * De-Register everything @@ -342,8 +342,8 @@ GameLib.System.Input.prototype.setMode = function() { * * @param data */ -GameLib.System.Input.prototype.canvasChange = function(data) { - if (data.component instanceof GameLib.Controls) { +R3.System.Input.prototype.canvasChange = function(data) { + if (data.component instanceof R3.Controls) { console.log('todo: implement dom element change'); } }; @@ -352,12 +352,12 @@ GameLib.System.Input.prototype.canvasChange = function(data) { * Changes the selection mode from face to mesh etc. * @param data */ -GameLib.System.Input.prototype.selectionModeChange = function(data) { +R3.System.Input.prototype.selectionModeChange = function(data) { this.selectionMode = data.selectionMode; }; -GameLib.System.Input.prototype.beforeRender = function(data) { +R3.System.Input.prototype.beforeRender = function(data) { if (this.editMode) { @@ -391,9 +391,9 @@ GameLib.System.Input.prototype.beforeRender = function(data) { * From now on we want to track everything about a component, only from the systems that are active * @param data */ -GameLib.System.Input.prototype.instanceCreated = function(data) { +R3.System.Input.prototype.instanceCreated = function(data) { - if (data.component instanceof GameLib.Controls.Touch) { + if (data.component instanceof R3.Controls.Touch) { if (this.touchControls.indexOf(data.component) !== -1) { console.warn('Touch controls already registered'); @@ -404,7 +404,7 @@ GameLib.System.Input.prototype.instanceCreated = function(data) { this.setMode(); } - if (data.component instanceof GameLib.Controls.Keyboard) { + if (data.component instanceof R3.Controls.Keyboard) { if (this.keyboardControls.indexOf(data.component) !== -1) { console.warn('Keyboard controls already registered'); @@ -415,7 +415,7 @@ GameLib.System.Input.prototype.instanceCreated = function(data) { this.setMode(); } - if (data.component instanceof GameLib.Controls.Mouse) { + if (data.component instanceof R3.Controls.Mouse) { if (this.mouseControls.indexOf(data.component) !== -1) { console.warn('Mouse controls already registered'); @@ -431,11 +431,11 @@ GameLib.System.Input.prototype.instanceCreated = function(data) { * Removes controls from this system * @param data */ -GameLib.System.Input.prototype.removeComponent = function(data) { +R3.System.Input.prototype.removeComponent = function(data) { var index; - if (data.component instanceof GameLib.Controls.Touch) { + if (data.component instanceof R3.Controls.Touch) { index = this.touchControls.indexOf(data.component); @@ -453,7 +453,7 @@ GameLib.System.Input.prototype.removeComponent = function(data) { this.setMode(); } - if (data.component instanceof GameLib.Controls.Keyboard) { + if (data.component instanceof R3.Controls.Keyboard) { index = this.keyboardControls.indexOf(data.component); @@ -471,7 +471,7 @@ GameLib.System.Input.prototype.removeComponent = function(data) { this.setMode(); } - if (data.component instanceof GameLib.Controls.Mouse) { + if (data.component instanceof R3.Controls.Mouse) { index = this.mouseControls.indexOf(data.component); @@ -489,7 +489,7 @@ GameLib.System.Input.prototype.removeComponent = function(data) { this.setMode(); } - if (data.component instanceof GameLib.Controls.D3.Editor) { + if (data.component instanceof R3.Controls.D3.Editor) { console.log('removing editor controls from system'); @@ -509,7 +509,7 @@ GameLib.System.Input.prototype.removeComponent = function(data) { this.setMode(); } - if (data.component instanceof GameLib.Controls.D3.FirstPerson) { + if (data.component instanceof R3.Controls.D3.FirstPerson) { console.log('removing first person controls from system'); @@ -529,7 +529,7 @@ GameLib.System.Input.prototype.removeComponent = function(data) { this.setMode(); } - if (data.component instanceof GameLib.Controls.D3.Orbit) { + if (data.component instanceof R3.Controls.D3.Orbit) { console.log('removing orbit controls from system'); @@ -555,9 +555,9 @@ GameLib.System.Input.prototype.removeComponent = function(data) { * Delayed Instance - we need to check if editControls will block the loading process (since only one will be created) * @param data */ -GameLib.System.Input.prototype.delayedInstanceEncountered = function(data) { +R3.System.Input.prototype.delayedInstanceEncountered = function(data) { - if (data.component instanceof GameLib.Controls.D3.Editor) { + if (data.component instanceof R3.Controls.D3.Editor) { if (this.editorControls.indexOf(data.component) !== -1) { console.warn('Editor controls already registered'); @@ -569,7 +569,7 @@ GameLib.System.Input.prototype.delayedInstanceEncountered = function(data) { } - if (data.component instanceof GameLib.Controls.D3.FirstPerson) { + if (data.component instanceof R3.Controls.D3.FirstPerson) { if (this.firstPersonControls.indexOf(data.component) !== -1) { console.warn('First Person Controls already registered'); @@ -580,7 +580,7 @@ GameLib.System.Input.prototype.delayedInstanceEncountered = function(data) { this.setMode(); } - if (data.component instanceof GameLib.Controls.D3.Orbit) { + if (data.component instanceof R3.Controls.D3.Orbit) { if (this.orbitControls.indexOf(data.component) !== -1) { console.warn('Orbit Controls already registered'); @@ -593,7 +593,7 @@ GameLib.System.Input.prototype.delayedInstanceEncountered = function(data) { }; -GameLib.System.Input.prototype.registerTouchControl = function(touchControl) { +R3.System.Input.prototype.registerTouchControl = function(touchControl) { if (!touchControl.canvas || !touchControl.canvas.instance) { console.warn('no canvas at time of registration of touch controls - this part will be skipped'); @@ -623,7 +623,7 @@ GameLib.System.Input.prototype.registerTouchControl = function(touchControl) { ); }; -GameLib.System.Input.prototype.registerKeyboardControl = function(keyboardControl) { +R3.System.Input.prototype.registerKeyboardControl = function(keyboardControl) { if (!keyboardControl.canvas || !keyboardControl.canvas.instance) { console.warn('no canvas at time of registration of keyboard controls - this part will be skipped'); @@ -643,7 +643,7 @@ GameLib.System.Input.prototype.registerKeyboardControl = function(keyboardContro ); }; -GameLib.System.Input.prototype.registerMouseControl = function(mouseControl) { +R3.System.Input.prototype.registerMouseControl = function(mouseControl) { if (!mouseControl.canvas || !mouseControl.canvas.instance) { console.warn('no canvas at time of registration of mouse controls - this part will be skipped'); @@ -678,7 +678,7 @@ GameLib.System.Input.prototype.registerMouseControl = function(mouseControl) { /** * Register all normal mode controls (Touch, Keyboard and Mouse) */ -GameLib.System.Input.prototype.registerNormalModeControls = function() { +R3.System.Input.prototype.registerNormalModeControls = function() { this.touchControls.map( function(touchControl){ @@ -702,14 +702,14 @@ GameLib.System.Input.prototype.registerNormalModeControls = function() { /** * Register all edit mode controls - (Editor, Firs Person and Orbit) */ -GameLib.System.Input.prototype.registerEditModeControls = function() { +R3.System.Input.prototype.registerEditModeControls = function() { /** - * Right now - all edit mode controls happen to live in the namespace GameLib.Controls.D3 + * Right now - all edit mode controls happen to live in the namespace R3.Controls.D3 * They are Editor, First Person and Orbit controls */ - GameLib.EntityManager.Instance.queryComponentsByConstructor(GameLib.Controls.D3).map( + R3.EntityManager.Instance.queryComponentsByConstructor(R3.Controls.D3).map( function(control) { @@ -786,7 +786,7 @@ GameLib.System.Input.prototype.registerEditModeControls = function() { /** * Remove all normal mode event listeners */ -GameLib.System.Input.prototype.deRegisterNormalModeControls = function() { +R3.System.Input.prototype.deRegisterNormalModeControls = function() { this.touchControls.map( function(touchControl){ this.deRegisterTouchControl(touchControl); @@ -806,10 +806,10 @@ GameLib.System.Input.prototype.deRegisterNormalModeControls = function() { ); }; -GameLib.System.Input.prototype.deRegisterEditModeControls = function() { +R3.System.Input.prototype.deRegisterEditModeControls = function() { - GameLib.EntityManager.Instance.queryComponentsByConstructor(GameLib.Controls.D3).map( + R3.EntityManager.Instance.queryComponentsByConstructor(R3.Controls.D3).map( function(control) { @@ -883,7 +883,7 @@ GameLib.System.Input.prototype.deRegisterEditModeControls = function() { }; -GameLib.System.Input.prototype.deRegisterTouchControl = function(touchControl) { +R3.System.Input.prototype.deRegisterTouchControl = function(touchControl) { touchControl.canvas.instance.removeEventListener( 'touchstart', @@ -911,7 +911,7 @@ GameLib.System.Input.prototype.deRegisterTouchControl = function(touchControl) { }; -GameLib.System.Input.prototype.deRegisterKeyboardControl = function(keyboardControl) { +R3.System.Input.prototype.deRegisterKeyboardControl = function(keyboardControl) { keyboardControl.canvas.instance.removeEventListener( 'keydown', @@ -928,7 +928,7 @@ GameLib.System.Input.prototype.deRegisterKeyboardControl = function(keyboardCont }; -GameLib.System.Input.prototype.deRegisterMouseControl = function(mouseControl) { +R3.System.Input.prototype.deRegisterMouseControl = function(mouseControl) { mouseControl.canvas.instance.removeEventListener( 'mousedown', @@ -956,9 +956,9 @@ GameLib.System.Input.prototype.deRegisterMouseControl = function(mouseControl) { }; -GameLib.System.Input.prototype.onKeyboardKeyUp = function(event) { - GameLib.Event.Emit( - GameLib.Event.KEY_DOWN, +R3.System.Input.prototype.onKeyboardKeyUp = function(event) { + R3.Event.Emit( + R3.Event.KEY_DOWN, { code : event.code || event.key, keyCode : event.keyCode @@ -967,9 +967,9 @@ GameLib.System.Input.prototype.onKeyboardKeyUp = function(event) { }; -GameLib.System.Input.prototype.onKeyboardKeyDown = function(event) { - GameLib.Event.Emit( - GameLib.Event.KEY_UP, +R3.System.Input.prototype.onKeyboardKeyDown = function(event) { + R3.Event.Emit( + R3.Event.KEY_UP, { code : event.code || event.key, keyCode : event.keyCode @@ -978,7 +978,7 @@ GameLib.System.Input.prototype.onKeyboardKeyDown = function(event) { }; -GameLib.System.Input.prototype.onTouchStart = function(event) { +R3.System.Input.prototype.onTouchStart = function(event) { if (this.playAudio) { @@ -1014,13 +1014,13 @@ GameLib.System.Input.prototype.onTouchStart = function(event) { this.touches.event = event; - GameLib.Event.Emit( - GameLib.Event.TOUCH_START, + R3.Event.Emit( + R3.Event.TOUCH_START, this.touches ) }; -GameLib.System.Input.prototype.onTouchMove = function (event) { +R3.System.Input.prototype.onTouchMove = function (event) { this.sensitivityCounter++; @@ -1138,8 +1138,8 @@ GameLib.System.Input.prototype.onTouchMove = function (event) { // // this.sensitivityCounter = 0; - GameLib.Event.Emit( - GameLib.Event.TOUCH_MOVE, + R3.Event.Emit( + R3.Event.TOUCH_MOVE, this.touches ); @@ -1148,42 +1148,42 @@ GameLib.System.Input.prototype.onTouchMove = function (event) { }; -GameLib.System.Input.prototype.onTouchCancel = function(event) { +R3.System.Input.prototype.onTouchCancel = function(event) { this.sensitivityCounter = 0; for (var t = 0; t < event.changedTouches.length; t++) { this.touches[event.changedTouches[t].identifier].cancelled = true; this.touches[event.changedTouches[t].identifier].event = event; - GameLib.Event.Emit( - GameLib.Event.TOUCH_CANCEL, + R3.Event.Emit( + R3.Event.TOUCH_CANCEL, this.touches[event.changedTouches[t].identifier] ); delete this.touches[event.changedTouches[t].identifier]; } }; -GameLib.System.Input.prototype.onTouchEnd = function(event) { +R3.System.Input.prototype.onTouchEnd = function(event) { this.sensitivityCounter = 0; for (var t = 0; t < event.changedTouches.length; t++) { this.touches[event.changedTouches[t].identifier].ended = true; this.touches[event.changedTouches[t].identifier].event = event; - GameLib.Event.Emit( - GameLib.Event.TOUCH_END, + R3.Event.Emit( + R3.Event.TOUCH_END, this.touches[event.changedTouches[t].identifier] ); delete this.touches[event.changedTouches[t].identifier]; } }; -GameLib.System.Input.prototype.onKeyDownEdit = function(event) { +R3.System.Input.prototype.onKeyDownEdit = function(event) { console.log('input system emitted keypress ' + event.code); - GameLib.Event.Emit( - GameLib.Event.KEY_DOWN, + R3.Event.Emit( + R3.Event.KEY_DOWN, { code : event.code || event.key, keyCode : event.keyCode @@ -1194,7 +1194,7 @@ GameLib.System.Input.prototype.onKeyDownEdit = function(event) { if (event.code === 'Delete') { - meshes = GameLib.EntityManager.Instance.queryComponentsByConstructor(GameLib.D3.Mesh); + meshes = R3.EntityManager.Instance.queryComponentsByConstructor(R3.D3.Mesh); var deletedMeshes = []; @@ -1213,8 +1213,8 @@ GameLib.System.Input.prototype.onKeyDownEdit = function(event) { }.bind(this) ); - GameLib.Event.Emit( - GameLib.Event.REMOVE_MESH, + R3.Event.Emit( + R3.Event.REMOVE_MESH, { meshes : deletedMeshes } @@ -1230,9 +1230,9 @@ GameLib.System.Input.prototype.onKeyDownEdit = function(event) { this.selectAll = !this.selectAll; - if (this.selectionMode === GameLib.System.Input.SELECTION_MODE_MESH) { + if (this.selectionMode === R3.System.Input.SELECTION_MODE_MESH) { - meshes = GameLib.EntityManager.Instance.queryComponentsByConstructor(GameLib.D3.Mesh); + meshes = R3.EntityManager.Instance.queryComponentsByConstructor(R3.D3.Mesh); meshes.map(function (mesh) { if (this.selectAll) { @@ -1245,22 +1245,22 @@ GameLib.System.Input.prototype.onKeyDownEdit = function(event) { console.warn('todo: implement face select all'); } - GameLib.Event.Emit( - GameLib.Event.BUILD_GUI, + R3.Event.Emit( + R3.Event.BUILD_GUI, null ) } if (event.code === 'KeyP') { - GameLib.Event.Emit(GameLib.Event.GAME_PAUSE); + R3.Event.Emit(R3.Event.GAME_PAUSE); } }; -GameLib.System.Input.prototype.onKeyUpEdit = function(event) { +R3.System.Input.prototype.onKeyUpEdit = function(event) { - GameLib.Event.Emit( - GameLib.Event.KEY_UP, + R3.Event.Emit( + R3.Event.KEY_UP, { code : event.code || event.key, keyCode : event.keyCode @@ -1272,51 +1272,51 @@ GameLib.System.Input.prototype.onKeyUpEdit = function(event) { } }; -GameLib.System.Input.prototype.onMouseDown = function(event) { +R3.System.Input.prototype.onMouseDown = function(event) { - GameLib.Event.Emit( - GameLib.Event.MOUSE_DOWN, + R3.Event.Emit( + R3.Event.MOUSE_DOWN, { event : event } ) }; -GameLib.System.Input.prototype.onMouseMove = function(event) { +R3.System.Input.prototype.onMouseMove = function(event) { - GameLib.Event.Emit( - GameLib.Event.MOUSE_MOVE, + R3.Event.Emit( + R3.Event.MOUSE_MOVE, { event : event } ) }; -GameLib.System.Input.prototype.onMouseWheel = function(event) { +R3.System.Input.prototype.onMouseWheel = function(event) { - GameLib.Event.Emit( - GameLib.Event.MOUSE_WHEEL, + R3.Event.Emit( + R3.Event.MOUSE_WHEEL, { event : event } ) }; -GameLib.System.Input.prototype.onMouseUp = function(event) { +R3.System.Input.prototype.onMouseUp = function(event) { - GameLib.Event.Emit( - GameLib.Event.MOUSE_UP, + R3.Event.Emit( + R3.Event.MOUSE_UP, { event : event } ) }; -GameLib.System.Input.prototype.onMouseDownEdit = function(event) { +R3.System.Input.prototype.onMouseDownEdit = function(event) { if (event.button === 2) { - GameLib.EntityManager.Instance.queryComponentsByConstructor(GameLib.Controls.D3).map( + R3.EntityManager.Instance.queryComponentsByConstructor(R3.Controls.D3).map( function(control) { @@ -1327,8 +1327,8 @@ GameLib.System.Input.prototype.onMouseDownEdit = function(event) { this.mouse.x = (event.offsetX / event.target.width ) * 2 - 1; this.mouse.y = -(event.offsetY / event.target.height) * 2 + 1; - GameLib.Event.Emit( - GameLib.Event.GET_RENDER_CONFIGURATION, + R3.Event.Emit( + R3.Event.GET_RENDER_CONFIGURATION, null, function(configuration) { @@ -1396,7 +1396,7 @@ GameLib.System.Input.prototype.onMouseDownEdit = function(event) { */ event.stopImmediatePropagation(); - if (this.selectionMode === GameLib.System.Input.SELECTION_MODE_MESH) { + if (this.selectionMode === R3.System.Input.SELECTION_MODE_MESH) { if (mesh.selected) { this.deselectMesh(mesh); @@ -1415,8 +1415,8 @@ GameLib.System.Input.prototype.onMouseDownEdit = function(event) { /** * Notify our GUI system to build a GUI */ - GameLib.Event.Emit( - GameLib.Event.BUILD_GUI, + R3.Event.Emit( + R3.Event.BUILD_GUI, null ) }.bind(this) @@ -1431,16 +1431,16 @@ GameLib.System.Input.prototype.onMouseDownEdit = function(event) { * * @param event */ -GameLib.System.Input.prototype.onMouseMoveEdit = function(event) { +R3.System.Input.prototype.onMouseMoveEdit = function(event) { - GameLib.EntityManager.Instance.queryComponents(GameLib.Component.MOUSE).map( + R3.EntityManager.Instance.queryComponents(R3.Component.MOUSE).map( function(mouse) { mouse.x = event.clientX; mouse.y = event.clientY; } ); - GameLib.EntityManager.Instance.queryComponentsByConstructor(GameLib.Controls.D3).map( + R3.EntityManager.Instance.queryComponentsByConstructor(R3.Controls.D3).map( function(control) { control.camera.position.x = control.camera.instance.position.x; @@ -1465,7 +1465,7 @@ GameLib.System.Input.prototype.onMouseMoveEdit = function(event) { * @returns {Function} * @param event */ -GameLib.System.Input.prototype.onMouseUpEdit = function(event) { +R3.System.Input.prototype.onMouseUpEdit = function(event) { }; @@ -1474,9 +1474,9 @@ GameLib.System.Input.prototype.onMouseUpEdit = function(event) { * @returns {Function} * @param event */ -GameLib.System.Input.prototype.onMouseWheelEdit = function(event) { +R3.System.Input.prototype.onMouseWheelEdit = function(event) { - GameLib.EntityManager.Instance.queryComponentsByConstructor(GameLib.Controls.D3).map( + R3.EntityManager.Instance.queryComponentsByConstructor(R3.Controls.D3).map( function(control) { control.camera.position.x = control.camera.instance.position.x; @@ -1487,7 +1487,7 @@ GameLib.System.Input.prototype.onMouseWheelEdit = function(event) { }; -GameLib.System.Input.prototype.selectFace = function(mesh, face) { +R3.System.Input.prototype.selectFace = function(mesh, face) { /** * If mesh is already selected, do nothing @@ -1504,8 +1504,8 @@ GameLib.System.Input.prototype.selectFace = function(mesh, face) { face.createHelper(mesh); - GameLib.Event.Emit( - GameLib.Event.MESH_FACE_SELECTED, + R3.Event.Emit( + R3.Event.MESH_FACE_SELECTED, { mesh : mesh, face : face @@ -1513,7 +1513,7 @@ GameLib.System.Input.prototype.selectFace = function(mesh, face) { ); }; -GameLib.System.Input.prototype.selectMesh = function(mesh) { +R3.System.Input.prototype.selectMesh = function(mesh) { /** * If mesh is already selected, do nothing @@ -1537,22 +1537,22 @@ GameLib.System.Input.prototype.selectMesh = function(mesh) { } ); - GameLib.Event.Emit( - GameLib.Event.MESH_SELECTED, + R3.Event.Emit( + R3.Event.MESH_SELECTED, { mesh : mesh } ); }; -GameLib.System.Input.prototype.deselectFace = function(mesh, face) { +R3.System.Input.prototype.deselectFace = function(mesh, face) { face.selected = false; face.removeHelper(mesh); - GameLib.Event.Emit( - GameLib.Event.MESH_FACE_DESELECTED, + R3.Event.Emit( + R3.Event.MESH_FACE_DESELECTED, { mesh : mesh, face : face @@ -1560,7 +1560,7 @@ GameLib.System.Input.prototype.deselectFace = function(mesh, face) { ); }; -GameLib.System.Input.prototype.deselectMesh = function(mesh) { +R3.System.Input.prototype.deselectMesh = function(mesh) { mesh.selected = false; @@ -1573,8 +1573,8 @@ GameLib.System.Input.prototype.deselectMesh = function(mesh) { } ); - GameLib.Event.Emit( - GameLib.Event.MESH_DESELECTED, + R3.Event.Emit( + R3.Event.MESH_DESELECTED, { mesh : mesh } @@ -1643,7 +1643,7 @@ GameLib.System.Input.prototype.deselectMesh = function(mesh) { // } // }; -// GameLib.D3.Input.Editor.prototype.onMouseDown = function(entity) { +// R3.D3.Input.Editor.prototype.onMouseDown = function(entity) { // // return function(event) { // @@ -1656,7 +1656,7 @@ GameLib.System.Input.prototype.deselectMesh = function(mesh) { // event.stopPropagation(); // } // -// var meshes = entity.queryComponents(GameLib.Component.MESH); +// var meshes = entity.queryComponents(R3.Component.MESH); // // var intersects = this.raycaster.getIntersectedObjects(meshes); // @@ -1704,7 +1704,7 @@ GameLib.System.Input.prototype.deselectMesh = function(mesh) { // * @param event // * @returns {boolean} // */ -// GameLib.D3.Input.Editor.prototype.onMouseDown = function(event) { +// R3.D3.Input.Editor.prototype.onMouseDown = function(event) { // // if (event.button === 2) { // @@ -1728,7 +1728,7 @@ GameLib.System.Input.prototype.deselectMesh = function(mesh) { // * Mouse move events // * @param event // */ -// GameLib.D3.Input.Editor.prototype.onMouseMove = function(event) { +// R3.D3.Input.Editor.prototype.onMouseMove = function(event) { // // // var clientX = event.clientX - this.widthOffset; // // this.mouse.x = ((clientX / (window.innerWidth - this.widthOffset))) * 2 - 1; @@ -1767,7 +1767,7 @@ GameLib.System.Input.prototype.deselectMesh = function(mesh) { // * @param alongAxis // * @param units // */ -// GameLib.D3.Input.Editor.prototype.moveSelectedObjects = function(alongAxis, units) { +// R3.D3.Input.Editor.prototype.moveSelectedObjects = function(alongAxis, units) { // // for (var s = 0; s < this.editor.selectedObjects.length; s++) { // diff --git a/src/game-lib-system-linking.js b/src/r3-system-linking.js similarity index 76% rename from src/game-lib-system-linking.js rename to src/r3-system-linking.js index 4c265f0..ddd5495 100644 --- a/src/game-lib-system-linking.js +++ b/src/r3-system-linking.js @@ -2,13 +2,13 @@ * Linking System takes care of linking components and dependencies (after they have loaded) - * and managing the relationships between objects - ex. what happens when a parent entity changes, * or a parent scene changes. - * @param apiSystem GameLib.API.System + * @param apiSystem R3.API.System * @constructor */ -GameLib.System.Linking = function( +R3.System.Linking = function( apiSystem ) { - GameLib.System.call( + R3.System.call( this, apiSystem ); @@ -63,48 +63,48 @@ GameLib.System.Linking = function( }; -GameLib.System.Linking.prototype = Object.create(GameLib.System.prototype); -GameLib.System.Linking.prototype.constructor = GameLib.System.Linking; +R3.System.Linking.prototype = Object.create(R3.System.prototype); +R3.System.Linking.prototype.constructor = R3.System.Linking; -GameLib.System.Linking.prototype.start = function() { +R3.System.Linking.prototype.start = function() { - GameLib.System.prototype.start.call(this); + R3.System.prototype.start.call(this); /** * Components */ this.componentCreatedSubscription = this.subscribe( - GameLib.Event.COMPONENT_CREATED, + R3.Event.COMPONENT_CREATED, this.componentCreated.bind(this) ); this.componentUpdateSubcription = this.subscribe( - GameLib.Event.COMPONENT_UPDATE, + R3.Event.COMPONENT_UPDATE, this.componentUpdate.bind(this) ); this.componentClonedSubscription = this.subscribe( - GameLib.Event.COMPONENT_CLONED, + R3.Event.COMPONENT_CLONED, this.componentCloned.bind(this) ); this.registerDependenciesSubscription = this.subscribe( - GameLib.Event.REGISTER_DEPENDENCIES, + R3.Event.REGISTER_DEPENDENCIES, this.registerDependenciesDirect ); this.componentRemoveSubscription = this.subscribe( - GameLib.Event.REMOVE_COMPONENT, + R3.Event.REMOVE_COMPONENT, this.removeComponent ); this.resolveDependenciesSubscription = this.subscribe( - GameLib.Event.RESOLVE_DEPENDENCIES, + R3.Event.RESOLVE_DEPENDENCIES, this.resolveDependencies ); this.replaceComponentSubscription = this.subscribe( - GameLib.Event.REPLACE_COMPONENT, + R3.Event.REPLACE_COMPONENT, this.replaceComponent ); @@ -112,12 +112,12 @@ GameLib.System.Linking.prototype.start = function() { * Parents */ this.parentSceneChangeSubscription = this.subscribe( - GameLib.Event.PARENT_SCENE_CHANGE, + R3.Event.PARENT_SCENE_CHANGE, this.onParentSceneChange ); this.parentPhysicsWorldChangeSubscription = this.subscribe( - GameLib.Event.PARENT_WORLD_CHANGE, + R3.Event.PARENT_WORLD_CHANGE, this.onParentWorldChange ); @@ -125,12 +125,12 @@ GameLib.System.Linking.prototype.start = function() { * Instances */ this.instanceCreatedSubscription = this.subscribe( - GameLib.Event.INSTANCE_CREATED, + R3.Event.INSTANCE_CREATED, this.instanceCreated ); this.instanceClonedSubscription = this.subscribe( - GameLib.Event.INSTANCE_CLONED, + R3.Event.INSTANCE_CLONED, this.instanceCloned ); @@ -138,7 +138,7 @@ GameLib.System.Linking.prototype.start = function() { * Meshes */ this.removeMeshSubscription = this.subscribe( - GameLib.Event.REMOVE_MESH, + R3.Event.REMOVE_MESH, this.removeMesh ); @@ -146,7 +146,7 @@ GameLib.System.Linking.prototype.start = function() { * Materials */ this.materialTypeChangedSubscription = this.subscribe( - GameLib.Event.MATERIAL_TYPE_CHANGED, + R3.Event.MATERIAL_TYPE_CHANGED, this.materialTypeChanged ); @@ -154,13 +154,13 @@ GameLib.System.Linking.prototype.start = function() { * Arrays */ this.arrayItemAddedSubscription = this.subscribe( - GameLib.Event.ARRAY_ITEM_ADDED, + R3.Event.ARRAY_ITEM_ADDED, this.arrayItemAdded ); }; -GameLib.System.Linking.prototype.link = function(component, data) { +R3.System.Linking.prototype.link = function(component, data) { for (var property in component.linkedObjects) { if (component.linkedObjects.hasOwnProperty(property)) { if (component.linkedObjects[property] instanceof Array) { @@ -183,8 +183,8 @@ GameLib.System.Linking.prototype.link = function(component, data) { }); linked.map(function(link) { - GameLib.Event.Emit( - GameLib.Event.COMPONENT_LINKED, + R3.Event.Emit( + R3.Event.COMPONENT_LINKED, link ); }) @@ -194,8 +194,8 @@ GameLib.System.Linking.prototype.link = function(component, data) { component[property] === data.component.id) { component[property] = data.component; - GameLib.Event.Emit( - GameLib.Event.COMPONENT_LINKED, + R3.Event.Emit( + R3.Event.COMPONENT_LINKED, { parent : component, property : property, @@ -208,7 +208,7 @@ GameLib.System.Linking.prototype.link = function(component, data) { } }; -GameLib.System.Linking.prototype.resolveDependencies = function(data) { +R3.System.Linking.prototype.resolveDependencies = function(data) { var component = data.component; @@ -227,7 +227,7 @@ GameLib.System.Linking.prototype.resolveDependencies = function(data) { /** * If we don't have any components which depend on this component, simply return */ - if (GameLib.Utils.UndefinedOrNull(parentComponents)) { + if (R3.Utils.UndefinedOrNull(parentComponents)) { /** * We don't know about components which depend on this component - but it could still load. @@ -251,13 +251,13 @@ GameLib.System.Linking.prototype.resolveDependencies = function(data) { /** * We record that we linked a child component to a parent component */ - GameLib.Utils.PushUnique(this.resolved, component); + R3.Utils.PushUnique(this.resolved, component); /** * First check if the dependencies have already been met */ if ( - GameLib.Utils.UndefinedOrNull(parentComponent.dependencies) || + R3.Utils.UndefinedOrNull(parentComponent.dependencies) || ( parentComponent.dependencies instanceof Array && parentComponent.dependencies.length === 0 @@ -271,7 +271,7 @@ GameLib.System.Linking.prototype.resolveDependencies = function(data) { */ if ( !parentComponent.loaded || - GameLib.Utils.UndefinedOrNull(parentComponent.instance) + R3.Utils.UndefinedOrNull(parentComponent.instance) ) { try { @@ -321,8 +321,8 @@ GameLib.System.Linking.prototype.resolveDependencies = function(data) { /** * For now this essentially only notifies the Editor - We have some more work to do however */ - GameLib.Event.Emit( - GameLib.Event.UNRESOLVED_DEPENDENCIES_UPDATE, + R3.Event.Emit( + R3.Event.UNRESOLVED_DEPENDENCIES_UPDATE, { dependencies : this.dependencies } @@ -331,13 +331,13 @@ GameLib.System.Linking.prototype.resolveDependencies = function(data) { /** * If we happen to have no more dependencies - we linked a bunch of components which are ready to use */ - if (GameLib.Utils.IsEmpty(this.dependencies)) { + if (R3.Utils.IsEmpty(this.dependencies)) { /** * This also only notifies the Editor - We still have some more work to here */ - GameLib.Event.Emit( - GameLib.Event.COMPONENTS_LINKED, + R3.Event.Emit( + R3.Event.COMPONENTS_LINKED, { components: this.resolved.map( function(component) { @@ -353,7 +353,7 @@ GameLib.System.Linking.prototype.resolveDependencies = function(data) { }; -GameLib.System.Linking.prototype.registerDependencies = function(component) { +R3.System.Linking.prototype.registerDependencies = function(component) { /** * We only care about components with unloaded dependencies - @@ -369,7 +369,7 @@ GameLib.System.Linking.prototype.registerDependencies = function(component) { /** * Check if we already processed a component on which this component is dependent */ - var processedComponent = GameLib.EntityManager.Instance.findComponentById(id); + var processedComponent = R3.EntityManager.Instance.findComponentById(id); if (processedComponent && processedComponent.loaded) { @@ -378,14 +378,14 @@ GameLib.System.Linking.prototype.registerDependencies = function(component) { */ this.link(component, {component: processedComponent}); - GameLib.Utils.PushUnique(this.resolved, processedComponent); + R3.Utils.PushUnique(this.resolved, processedComponent); } else { /** * Create a new link if none exists */ - if (GameLib.Utils.UndefinedOrNull(this.dependencies[id])) { + if (R3.Utils.UndefinedOrNull(this.dependencies[id])) { this.dependencies[id] = []; } @@ -394,8 +394,8 @@ GameLib.System.Linking.prototype.registerDependencies = function(component) { */ if (this.dependencies[id].indexOf(component) === -1) { this.dependencies[id].push(component); - GameLib.Event.Emit( - GameLib.Event.UNRESOLVED_DEPENDENCIES_UPDATE, + R3.Event.Emit( + R3.Event.UNRESOLVED_DEPENDENCIES_UPDATE, { dependencies : this.dependencies } @@ -424,7 +424,7 @@ GameLib.System.Linking.prototype.registerDependencies = function(component) { * When a component is created, register its dependencies, and try to resolve them * @param data */ -GameLib.System.Linking.prototype.componentCreated = function(data) { +R3.System.Linking.prototype.componentCreated = function(data) { /** * Shorthand @@ -447,21 +447,21 @@ GameLib.System.Linking.prototype.componentCreated = function(data) { * Trigger a component update * @param data */ -GameLib.System.Linking.prototype.componentUpdate = function(data){ +R3.System.Linking.prototype.componentUpdate = function(data){ - var component = GameLib.EntityManager.Instance.findComponentByName(data.name); + var component = R3.EntityManager.Instance.findComponentByName(data.name); - if (GameLib.Utils.UndefinedOrNull(data.property)) { + if (R3.Utils.UndefinedOrNull(data.property)) { console.warn('invalid data format - we expect data.property'); return; } - if (GameLib.Utils.UndefinedOrNull(data.value)) { + if (R3.Utils.UndefinedOrNull(data.value)) { console.warn('invalid data format - we expect data.value'); return; } - if (GameLib.Utils.UndefinedOrNull(data.subProperty)) { + if (R3.Utils.UndefinedOrNull(data.subProperty)) { component[data.property] = data.value; } else { component[data.property][data.subProperty] = data.value; @@ -470,13 +470,13 @@ GameLib.System.Linking.prototype.componentUpdate = function(data){ component.updateInstance(data.property); }; -GameLib.System.Linking.prototype.componentCloned = function(data) { +R3.System.Linking.prototype.componentCloned = function(data) { this.componentCreated(data); - if (data.component instanceof GameLib.D3.Mesh) { + if (data.component instanceof R3.D3.Mesh) { - if (!(data.parent instanceof GameLib.D3.Mesh)){ + if (!(data.parent instanceof R3.D3.Mesh)){ throw new Error('no scene parent'); } @@ -493,18 +493,18 @@ GameLib.System.Linking.prototype.componentCloned = function(data) { * system about it, so the linking system can create the instance when the dependency loads or already exists * @param data */ -GameLib.System.Linking.prototype.registerDependenciesDirect = function(data) { +R3.System.Linking.prototype.registerDependenciesDirect = function(data) { this.registerDependencies(data.component); }; -GameLib.System.Linking.prototype.replaceComponent = function(data) { +R3.System.Linking.prototype.replaceComponent = function(data) { /** * Link canvases */ if ( - data.current instanceof GameLib.D3.Geometry.Buffer && - data.replacement instanceof GameLib.D3.Geometry.Buffer + data.current instanceof R3.D3.Geometry.Buffer && + data.replacement instanceof R3.D3.Geometry.Buffer ) { data.replacement.faces = data.current.faces.map( function(face) { @@ -525,7 +525,7 @@ GameLib.System.Linking.prototype.replaceComponent = function(data) { */ //data.replacement.updateInstance('vertices'); - GameLib.EntityManager.Instance.queryComponents(GameLib.Component.MESH).map( + R3.EntityManager.Instance.queryComponents(R3.Component.MESH).map( function(mesh) { if (mesh.geometry === data.current) { mesh.geometry = data.replacement; @@ -537,7 +537,7 @@ GameLib.System.Linking.prototype.replaceComponent = function(data) { }; -GameLib.System.Linking.prototype.removeComponent = function(data) { +R3.System.Linking.prototype.removeComponent = function(data) { if (!data.component) { console.error('no component to remove'); @@ -546,52 +546,52 @@ GameLib.System.Linking.prototype.removeComponent = function(data) { var component = data.component; - if (component.parentEntity instanceof GameLib.Entity) { + if (component.parentEntity instanceof R3.Entity) { component.parentEntity.removeComponent(component); } - if (component instanceof GameLib.D3.Mesh && - component.parentScene instanceof GameLib.D3.Scene) { + if (component instanceof R3.D3.Mesh && + component.parentScene instanceof R3.D3.Scene) { component.removeHelper(); component.parentScene.removeObject(component); } - if (component instanceof GameLib.D3.Light && - component.parentScene instanceof GameLib.D3.Scene) { + if (component instanceof R3.D3.Light && + component.parentScene instanceof R3.D3.Scene) { component.parentScene.removeObject(component); } - if (component instanceof GameLib.Entity) { - GameLib.EntityManager.Instance.removeEntity(component); + if (component instanceof R3.Entity) { + R3.EntityManager.Instance.removeEntity(component); } - // if (component instanceof GameLib.D3.Particle) { + // if (component instanceof R3.D3.Particle) { // // component.mesh.parentScene.removeObject(component.mesh); // } }; -GameLib.System.Linking.prototype.arrayItemAdded = function(data) { +R3.System.Linking.prototype.arrayItemAdded = function(data) { if ( - data.component instanceof GameLib.D3.PhysicsWorld && - data.item instanceof GameLib.D3.RigidBody + data.component instanceof R3.D3.PhysicsWorld && + data.item instanceof R3.D3.RigidBody ) { data.component.addRigidBody(data.item); } console.warn('todo: check if this is still necessary to add material to mesh'); - // if (data.component instanceof GameLib.D3.Mesh && - // data.item instanceof GameLib.D3.Material + // if (data.component instanceof R3.D3.Mesh && + // data.item instanceof R3.D3.Material // ) { // data.component.updateInstance('materials'); // } }; -GameLib.System.Linking.prototype.instanceCloned = function(data) { +R3.System.Linking.prototype.instanceCloned = function(data) { - // if (data.component instanceof GameLib.D3.Particle) { + // if (data.component instanceof R3.D3.Particle) { // // var mesh = data.component.mesh; // @@ -603,13 +603,13 @@ GameLib.System.Linking.prototype.instanceCloned = function(data) { }; -GameLib.System.Linking.prototype.instanceCreated = function(data) { +R3.System.Linking.prototype.instanceCreated = function(data) { - if (data.component instanceof GameLib.Image) { + if (data.component instanceof R3.Image) { /** * Find all textures which use this image */ - GameLib.EntityManager.Instance.queryComponents(GameLib.Component.TEXTURE_IMAGE).map( + R3.EntityManager.Instance.queryComponents(R3.Component.TEXTURE_IMAGE).map( function(texture) { if (texture.instance && texture.image === data.component) { texture.updateInstance('image'); @@ -617,7 +617,7 @@ GameLib.System.Linking.prototype.instanceCreated = function(data) { } ); - GameLib.EntityManager.Instance.queryComponents(GameLib.Component.TEXTURE_CUBE).map( + R3.EntityManager.Instance.queryComponents(R3.Component.TEXTURE_CUBE).map( function(texture) { if (texture.instance && texture.images.indexOf(data.component) !== -1) { texture.updateInstance('images'); @@ -630,15 +630,15 @@ GameLib.System.Linking.prototype.instanceCreated = function(data) { /** * Link all scenes */ - if (data.component instanceof GameLib.D3.Scene) { + if (data.component instanceof R3.D3.Scene) { /** * Check ALL components for 'parentScenes' - this is expensive so it checks the register directly */ - Object.keys(GameLib.EntityManager.Instance.idRegister).map( + Object.keys(R3.EntityManager.Instance.idRegister).map( function(componentId) { - if (GameLib.EntityManager.Instance.idRegister[componentId].parentScene === data.component.id) { - GameLib.EntityManager.Instance.idRegister[componentId].parentScene = data.component; + if (R3.EntityManager.Instance.idRegister[componentId].parentScene === data.component.id) { + R3.EntityManager.Instance.idRegister[componentId].parentScene = data.component; } } ); @@ -648,7 +648,7 @@ GameLib.System.Linking.prototype.instanceCreated = function(data) { data.component.parentScene && typeof data.component.parentScene === 'string' ) { - GameLib.EntityManager.Instance.queryComponents(GameLib.Component.SCENE).map( + R3.EntityManager.Instance.queryComponents(R3.Component.SCENE).map( function (scene) { if (data.component.parentScene === scene.id) { data.component.parentScene = scene; @@ -662,7 +662,7 @@ GameLib.System.Linking.prototype.instanceCreated = function(data) { /** * Link all meshes */ - if (data.component instanceof GameLib.D3.Mesh) { + if (data.component instanceof R3.D3.Mesh) { /** * Check if this mesh is a parentMesh to any component- this is an expensive call, so check if we should call it @@ -670,11 +670,11 @@ GameLib.System.Linking.prototype.instanceCreated = function(data) { */ if (!data.preventParentMeshCheck) { - Object.keys(GameLib.EntityManager.Instance.idRegister).map( + Object.keys(R3.EntityManager.Instance.idRegister).map( function(componentId) { - if (GameLib.EntityManager.Instance.idRegister[componentId].parentMesh === data.component.id) { - GameLib.EntityManager.Instance.idRegister[componentId].parentMesh = data.component; - GameLib.EntityManager.Instance.idRegister[componentId].updateInstance('parentMesh'); + if (R3.EntityManager.Instance.idRegister[componentId].parentMesh === data.component.id) { + R3.EntityManager.Instance.idRegister[componentId].parentMesh = data.component; + R3.EntityManager.Instance.idRegister[componentId].updateInstance('parentMesh'); } } ); @@ -690,7 +690,7 @@ GameLib.System.Linking.prototype.instanceCreated = function(data) { data.component.parentMesh && typeof data.component.parentMesh === 'string' ) { - GameLib.EntityManager.Instance.queryComponents(GameLib.Component.MESH).map( + R3.EntityManager.Instance.queryComponents(R3.Component.MESH).map( function (mesh) { if (data.component.parentMesh === mesh.id) { data.component.parentMesh = mesh; @@ -704,7 +704,7 @@ GameLib.System.Linking.prototype.instanceCreated = function(data) { data.component.parentPhysicsWorld && typeof data.component.parentPhysicsWorld === 'string' ) { - GameLib.EntityManager.Instance.queryComponents(GameLib.Component.PHYSICS_WORLD).map( + R3.EntityManager.Instance.queryComponents(R3.Component.PHYSICS_WORLD).map( function (world) { if (data.component.parentPhysicsWorld === world.id) { data.component.parentPhysicsWorld = world; @@ -720,9 +720,9 @@ GameLib.System.Linking.prototype.instanceCreated = function(data) { }; -GameLib.System.Linking.prototype.materialTypeChanged = function(data) { +R3.System.Linking.prototype.materialTypeChanged = function(data) { - var meshes = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.MESH); + var meshes = R3.EntityManager.Instance.queryComponents(R3.Component.MESH); meshes.map( function(mesh){ @@ -761,17 +761,17 @@ GameLib.System.Linking.prototype.materialTypeChanged = function(data) { * * @param data */ -GameLib.System.Linking.prototype.onParentWorldChange = function(data) { +R3.System.Linking.prototype.onParentWorldChange = function(data) { if ( - data.object instanceof GameLib.D3.RigidBody + data.object instanceof R3.D3.RigidBody ) { - if (data.originalWorld instanceof GameLib.D3.PhysicsWorld) { + if (data.originalWorld instanceof R3.D3.PhysicsWorld) { data.originalWorld.removeRigidBody(data.object); } - if (data.newWorld instanceof GameLib.D3.PhysicsWorld) { + if (data.newWorld instanceof R3.D3.PhysicsWorld) { data.newWorld.addRigidBody(data.object); } } @@ -782,17 +782,17 @@ GameLib.System.Linking.prototype.onParentWorldChange = function(data) { * Defines what should happen when a parent scene changes * @param data */ -GameLib.System.Linking.prototype.onParentSceneChange = function(data) { +R3.System.Linking.prototype.onParentSceneChange = function(data) { if ( - data.object instanceof GameLib.D3.Mesh || - data.object instanceof GameLib.D3.Light + data.object instanceof R3.D3.Mesh || + data.object instanceof R3.D3.Light ) { /** * We remove the helper (if any) from the old scene and add it to the new scene */ - var helper = GameLib.EntityManager.Instance.findHelperByObject(data.object); + var helper = R3.EntityManager.Instance.findHelperByObject(data.object); if (helper) { if (data.originalScene && data.originalScene.instance) { @@ -820,7 +820,7 @@ GameLib.System.Linking.prototype.onParentSceneChange = function(data) { * children objects are in use by another object - if it is - don't delete it, otherwise, do * @param data */ -GameLib.System.Linking.prototype.removeMesh = function(data) { +R3.System.Linking.prototype.removeMesh = function(data) { /** * First we get the list of all components we would like to delete @@ -844,7 +844,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.Component.MESH); + var meshes = R3.EntityManager.Instance.queryComponents(R3.Component.MESH); meshes = meshes.filter(function(mesh){ return data.meshes.indexOf(mesh) === -1; }); @@ -887,8 +887,8 @@ GameLib.System.Linking.prototype.removeMesh = function(data) { ); }; -GameLib.System.Linking.prototype.stop = function() { - GameLib.System.prototype.stop.call(this); +R3.System.Linking.prototype.stop = function() { + R3.System.prototype.stop.call(this); /** * Components */ diff --git a/src/game-lib-system-particle.js b/src/r3-system-particle.js similarity index 75% rename from src/game-lib-system-particle.js rename to src/r3-system-particle.js index 79b1a2f..0afa659 100644 --- a/src/game-lib-system-particle.js +++ b/src/r3-system-particle.js @@ -1,12 +1,12 @@ /** * System takes care of updating all the entities (based on their component data) - * @param apiSystem GameLib.API.System + * @param apiSystem R3.API.System * @constructor */ -GameLib.System.Particle = function( +R3.System.Particle = function( apiSystem ) { - GameLib.System.call( + R3.System.call( this, apiSystem ); @@ -27,30 +27,30 @@ GameLib.System.Particle = function( this.beforeRenderSubscription = null; }; -GameLib.System.Particle.prototype = Object.create(GameLib.System.prototype); -GameLib.System.Particle.prototype.constructor = GameLib.System.Particle; +R3.System.Particle.prototype = Object.create(R3.System.prototype); +R3.System.Particle.prototype.constructor = R3.System.Particle; /** * Start this system (add all event listeners) */ -GameLib.System.Particle.prototype.start = function() { +R3.System.Particle.prototype.start = function() { - GameLib.System.prototype.start.call(this); + R3.System.prototype.start.call(this); - this.particleEngines = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.PARTICLE_ENGINE); + this.particleEngines = R3.EntityManager.Instance.queryComponents(R3.Component.PARTICLE_ENGINE); - this.instanceCreatedSubscription = GameLib.Event.Subscribe( - GameLib.Event.INSTANCE_CREATED, + this.instanceCreatedSubscription = R3.Event.Subscribe( + R3.Event.INSTANCE_CREATED, this.instanceCreated.bind(this) ); - this.removeComponentSubscription = GameLib.Event.Subscribe( - GameLib.Event.REMOVE_COMPONENT, + this.removeComponentSubscription = R3.Event.Subscribe( + R3.Event.REMOVE_COMPONENT, this.removeComponent.bind(this) ); - this.beforeRenderSubscription = GameLib.Event.Subscribe( - GameLib.Event.BEFORE_RENDER, + this.beforeRenderSubscription = R3.Event.Subscribe( + R3.Event.BEFORE_RENDER, this.beforeRender.bind(this) ); @@ -60,18 +60,18 @@ GameLib.System.Particle.prototype.start = function() { * From now on we want to track everything about a component, only from the systems that are active * @param data */ -GameLib.System.Particle.prototype.instanceCreated = function(data) { +R3.System.Particle.prototype.instanceCreated = function(data) { /** * If we loaded a ParticleEngine - store a reference to it for later, also link all particles with this as parent */ - if (data.component instanceof GameLib.D3.ParticleEngine) { + if (data.component instanceof R3.D3.ParticleEngine) { this.particleEngines.push(data.component); /** * Link parent particle engines of already loaded particles */ - GameLib.EntityManager.Instance.queryComponents(GameLib.Component.PARTICLE).map( + R3.EntityManager.Instance.queryComponents(R3.Component.PARTICLE).map( function(particle){ if (particle.parentParticleEngine === data.component.id) { particle.parentParticleEngine = data.component; @@ -83,8 +83,8 @@ GameLib.System.Particle.prototype.instanceCreated = function(data) { /** * If we load a Particle, check to see if its engine loaded and link it. */ - if (data.component instanceof GameLib.D3.Particle) { - GameLib.EntityManager.Instance.queryComponents(GameLib.Component.PARTICLE_ENGINE).map( + if (data.component instanceof R3.D3.Particle) { + R3.EntityManager.Instance.queryComponents(R3.Component.PARTICLE_ENGINE).map( function (particleEngine) { if (data.component.parentParticleEngine === particleEngine.id) { data.component.parentParticleEngine = particleEngine; @@ -98,9 +98,9 @@ GameLib.System.Particle.prototype.instanceCreated = function(data) { * Removes a particle engine from this system * @param data */ -GameLib.System.Particle.prototype.removeComponent = function(data) { +R3.System.Particle.prototype.removeComponent = function(data) { - if (data.component instanceof GameLib.D3.ParticleEngine) { + if (data.component instanceof R3.D3.ParticleEngine) { var index = this.particleEngines.indexOf(data.component); @@ -120,7 +120,7 @@ GameLib.System.Particle.prototype.removeComponent = function(data) { * This is what actually happens to all particles before render * @param data */ -GameLib.System.Particle.prototype.beforeRender = function(data) { +R3.System.Particle.prototype.beforeRender = function(data) { this.totalTime += data.delta; @@ -128,10 +128,10 @@ GameLib.System.Particle.prototype.beforeRender = function(data) { function(particleEngine) { if ( - GameLib.Utils.UndefinedOrNull(particleEngine.templateParticle) || - GameLib.Utils.UndefinedOrNull(particleEngine.templateParticle.mesh) || - GameLib.Utils.UndefinedOrNull(particleEngine.templateParticle.mesh.parentScene) || - GameLib.Utils.UndefinedOrNull(particleEngine.templateParticle.mesh.parentScene.instance) || + R3.Utils.UndefinedOrNull(particleEngine.templateParticle) || + R3.Utils.UndefinedOrNull(particleEngine.templateParticle.mesh) || + R3.Utils.UndefinedOrNull(particleEngine.templateParticle.mesh.parentScene) || + R3.Utils.UndefinedOrNull(particleEngine.templateParticle.mesh.parentScene.instance) || !particleEngine.enabled ) { return; @@ -145,36 +145,36 @@ GameLib.System.Particle.prototype.beforeRender = function(data) { var speed = particle.userData.speed; - if (particle.userData.speedType === GameLib.D3.API.Particle.SPEED_TYPE_CONSTANT) { + if (particle.userData.speedType === R3.D3.API.Particle.SPEED_TYPE_CONSTANT) { speed = data.delta * particle.userData.speed; } - if (particle.userData.speedType === GameLib.D3.API.Particle.SPEED_TYPE_LINEAR) { + if (particle.userData.speedType === R3.D3.API.Particle.SPEED_TYPE_LINEAR) { speed = data.delta * particle.userData.speed; particle.userData.speed += speed; } - if (particle.userData.speedType === GameLib.D3.API.Particle.SPEED_TYPE_EXPONENTIAL) { + if (particle.userData.speedType === R3.D3.API.Particle.SPEED_TYPE_EXPONENTIAL) { speed = Math.pow(particle.userData.speed, 2) * data.delta; particle.userData.speed += speed; } - if (particle.userData.speedType === GameLib.D3.API.Particle.SPEED_TYPE_LOGARITHMIC) { + if (particle.userData.speedType === R3.D3.API.Particle.SPEED_TYPE_LOGARITHMIC) { speed = Math.log(particle.userData.speed) * data.delta; particle.userData.speed += speed; } - if (particle.userData.speedType === GameLib.D3.API.Particle.SPEED_TYPE_ONE_OVER_LOG) { + if (particle.userData.speedType === R3.D3.API.Particle.SPEED_TYPE_ONE_OVER_LOG) { speed = 1 / Math.log(particle.userData.speed) * data.delta; particle.userData.speed += speed; } - if (particle.userData.speedType === GameLib.D3.API.Particle.SPEED_TYPE_EXP) { + if (particle.userData.speedType === R3.D3.API.Particle.SPEED_TYPE_EXP) { speed = Math.exp(particle.userData.speed) * data.delta; particle.userData.speed += speed; } - if (particle.userData.speedType === GameLib.D3.API.Particle.SPEED_TYPE_ONE_OVER_EXP) { + if (particle.userData.speedType === R3.D3.API.Particle.SPEED_TYPE_ONE_OVER_EXP) { speed = 1 / Math.exp(particle.userData.speed) * data.delta; particle.userData.speed += speed; } @@ -183,7 +183,7 @@ GameLib.System.Particle.prototype.beforeRender = function(data) { particle.position.y += particle.userData.direction.y * speed; particle.position.z += particle.userData.direction.z * speed; - if (particleEngine.templateParticle.scaleType === GameLib.D3.API.Particle.SCALE_TYPE_CONSTANT) { + if (particleEngine.templateParticle.scaleType === R3.D3.API.Particle.SCALE_TYPE_CONSTANT) { /** * Do nothing - scale should already be set */ @@ -193,7 +193,7 @@ GameLib.System.Particle.prototype.beforeRender = function(data) { */ } - if (particleEngine.templateParticle.scaleType === GameLib.D3.API.Particle.SCALE_TYPE_LINEAR) { + if (particleEngine.templateParticle.scaleType === R3.D3.API.Particle.SCALE_TYPE_LINEAR) { particle.scale.x += particle.userData.scale.x * data.delta; particle.scale.y += particle.userData.scale.x * data.delta; particle.scale.z += particle.userData.scale.x * data.delta; @@ -203,19 +203,19 @@ GameLib.System.Particle.prototype.beforeRender = function(data) { particle.quaternion.copy(particleEngine.camera.instance.quaternion); } - if (particleEngine.templateParticle.opacityType === GameLib.D3.API.Particle.OPACITY_TYPE_FADE_IN_LINEAR) { + if (particleEngine.templateParticle.opacityType === R3.D3.API.Particle.OPACITY_TYPE_FADE_IN_LINEAR) { if (particle.userData.elapsed > particleEngine.templateParticle.fadeInAfter) { particle.material.opacity += particleEngine.templateParticle.fadeInFactor; } } - if (particleEngine.templateParticle.opacityType === GameLib.D3.API.Particle.OPACITY_TYPE_FADE_OUT_LINEAR) { + if (particleEngine.templateParticle.opacityType === R3.D3.API.Particle.OPACITY_TYPE_FADE_OUT_LINEAR) { if (particle.userData.elapsed > particleEngine.templateParticle.fadeOutAfter) { particle.material.opacity -= particleEngine.templateParticle.fadeOutFactor; } } - if (particleEngine.templateParticle.opacityType === GameLib.D3.API.Particle.OPACITY_TYPE_FADE_IN_OUT_LINEAR) { + if (particleEngine.templateParticle.opacityType === R3.D3.API.Particle.OPACITY_TYPE_FADE_IN_OUT_LINEAR) { if (particle.userData.fadeIn) { if (particle.userData.elapsed > particleEngine.templateParticle.fadeInAfter) { @@ -251,8 +251,8 @@ GameLib.System.Particle.prototype.beforeRender = function(data) { ); if (particleEngine.disabledForRemoval && particleEngine.particles.length === 0) { - GameLib.Event.Emit( - GameLib.Event.REMOVE_PARTICLE_ENGINE, + R3.Event.Emit( + R3.Event.REMOVE_PARTICLE_ENGINE, { component : particleEngine } @@ -260,8 +260,8 @@ GameLib.System.Particle.prototype.beforeRender = function(data) { } if (particleEngine.fired && particleEngine.particles.length === 0) { - GameLib.Event.Emit( - GameLib.Event.ENGINE_FIRED_PARTICLES_ZERO, + R3.Event.Emit( + R3.Event.ENGINE_FIRED_PARTICLES_ZERO, { component : particleEngine } @@ -314,9 +314,9 @@ GameLib.System.Particle.prototype.beforeRender = function(data) { /** * Stop this system (remove all event listeners) */ -GameLib.System.Particle.prototype.stop = function() { +R3.System.Particle.prototype.stop = function() { - GameLib.System.prototype.stop.call(this); + R3.System.prototype.stop.call(this); this.instanceCreatedSubscription.remove(); this.removeComponentSubscription.remove(); diff --git a/src/game-lib-system-physics.js b/src/r3-system-physics.js similarity index 81% rename from src/game-lib-system-physics.js rename to src/r3-system-physics.js index d2b1889..927659c 100644 --- a/src/game-lib-system-physics.js +++ b/src/r3-system-physics.js @@ -1,13 +1,13 @@ /** * System takes care of updating all the entities (based on their component data) - * @param apiSystem GameLib.API.System + * @param apiSystem R3.API.System * @constructor */ -GameLib.System.Physics = function( +R3.System.Physics = function( apiSystem ) { - GameLib.System.call( + R3.System.call( this, apiSystem ); @@ -27,17 +27,17 @@ GameLib.System.Physics = function( }; -GameLib.System.Physics.prototype = Object.create(GameLib.System.prototype); -GameLib.System.Physics.prototype.constructor = GameLib.System.Physics; +R3.System.Physics.prototype = Object.create(R3.System.prototype); +R3.System.Physics.prototype.constructor = R3.System.Physics; -GameLib.System.Physics.prototype.start = function() { +R3.System.Physics.prototype.start = function() { - GameLib.System.prototype.start.call(this); + R3.System.prototype.start.call(this); - 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); + this.worlds = R3.EntityManager.Instance.queryComponents(R3.Component.PHYSICS_WORLD); + // this.rigidBodies = R3.EntityManager.Instance.queryComponents(R3.Component.RIGID_BODY); + // this.wheels = R3.EntityManager.Instance.queryComponents(R3.Component.RAYCAST_WHEEL); + // this.vehicles = R3.EntityManager.Instance.queryComponents(R3.Component.RAYCAST_VEHICLE); @@ -73,7 +73,7 @@ GameLib.System.Physics.prototype.start = function() { // ); this.beforeRenderSubscription = this.subscribe( - GameLib.Event.BEFORE_RENDER, + R3.Event.BEFORE_RENDER, this.beforeRender ); }; @@ -81,7 +81,7 @@ GameLib.System.Physics.prototype.start = function() { /** * Update script */ -GameLib.System.Physics.prototype.beforeRender = function(data) { +R3.System.Physics.prototype.beforeRender = function(data) { this.worlds.map( function(world) { @@ -130,9 +130,9 @@ GameLib.System.Physics.prototype.beforeRender = function(data) { }; -GameLib.System.Physics.prototype.stop = function() { +R3.System.Physics.prototype.stop = function() { - GameLib.System.prototype.stop.call(this); + R3.System.prototype.stop.call(this); this.worlds = []; this.rigidBodies = []; diff --git a/src/game-lib-system-render.js b/src/r3-system-render.js similarity index 71% rename from src/game-lib-system-render.js rename to src/r3-system-render.js index 878294f..f2646ed 100644 --- a/src/game-lib-system-render.js +++ b/src/r3-system-render.js @@ -1,15 +1,15 @@ /** * System takes care of updating all the entities (based on their component data) - * @param apiSystem GameLib.API.System + * @param apiSystem R3.API.System * @param graphicsRuntime * @constructor */ -GameLib.System.Render = function( +R3.System.Render = function( apiSystem, graphicsRuntime ) { - GameLib.System.call( + R3.System.call( this, apiSystem ); @@ -18,7 +18,7 @@ GameLib.System.Render = function( this.replaceComponentSubscription = null; - this.clock = new GameLib.Clock(graphicsRuntime); + this.clock = new R3.Clock(graphicsRuntime); this.delta = null; @@ -46,29 +46,29 @@ GameLib.System.Render = function( this.cubeCameras = []; }; -GameLib.System.Render.prototype = Object.create(GameLib.System.prototype); -GameLib.System.Render.prototype.constructor = GameLib.System.Render; +R3.System.Render.prototype = Object.create(R3.System.prototype); +R3.System.Render.prototype.constructor = R3.System.Render; /** * Start the rendering system */ -GameLib.System.Render.prototype.start = function() { +R3.System.Render.prototype.start = function() { - GameLib.System.prototype.start.call(this); + R3.System.prototype.start.call(this); - this.renderConfigurations = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.RENDER_CONFIGURATION); + this.renderConfigurations = R3.EntityManager.Instance.queryComponents(R3.Component.RENDER_CONFIGURATION); - this.renderers = GameLib.EntityManager.Instance.queryComponentsByConstructor(GameLib.Renderer); + this.renderers = R3.EntityManager.Instance.queryComponentsByConstructor(R3.Renderer); - this.composers = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.COMPOSER); + this.composers = R3.EntityManager.Instance.queryComponents(R3.Component.COMPOSER); - this.statistics = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.STATS); + this.statistics = R3.EntityManager.Instance.queryComponents(R3.Component.STATS); - this.cubeCameras = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.CAMERA_CUBE); + this.cubeCameras = R3.EntityManager.Instance.queryComponents(R3.Component.CAMERA_CUBE); this.excludedFromEnvironment = []; - GameLib.EntityManager.Instance.queryComponentsByConstructor(GameLib.D3.Mesh).map( + R3.EntityManager.Instance.queryComponentsByConstructor(R3.D3.Mesh).map( function(mesh) { if (mesh.excludeFromEnvironment) { this.excludedFromEnvironment.push(mesh); @@ -77,57 +77,57 @@ GameLib.System.Render.prototype.start = function() { ); this.excludeFromEnvironmentSubscription = this.subscribe( - GameLib.Event.EXCLUDE_FROM_ENVIRONMENT, + R3.Event.EXCLUDE_FROM_ENVIRONMENT, this.excludeFromEnvironmentUpdate ); - this.instanceCreatedSubscription = GameLib.Event.Subscribe( - GameLib.Event.INSTANCE_CREATED, + this.instanceCreatedSubscription = R3.Event.Subscribe( + R3.Event.INSTANCE_CREATED, this.instanceCreated.bind(this) ); - this.removeComponentSubscription = GameLib.Event.Subscribe( - GameLib.Event.REMOVE_COMPONENT, + this.removeComponentSubscription = R3.Event.Subscribe( + R3.Event.REMOVE_COMPONENT, this.removeComponent.bind(this) ); - this.replaceComponentSubscription = GameLib.Event.Subscribe( - GameLib.Event.REPLACE_COMPONENT, + this.replaceComponentSubscription = R3.Event.Subscribe( + R3.Event.REPLACE_COMPONENT, this.replaceComponent.bind(this) ); this.renderSubscription = this.subscribe( - GameLib.Event.RENDER, + R3.Event.RENDER, this.render ); this.windowResizeSubscription = this.subscribe( - GameLib.Event.WINDOW_RESIZE, + R3.Event.WINDOW_RESIZE, this.windowResize ); this.textureUpdatedSubscription = this.subscribe( - GameLib.Event.TEXTURE_INSTANCE_UPDATED, + R3.Event.TEXTURE_INSTANCE_UPDATED, this.textureUpdated ); this.getRenderConfigurationSubscription = this.subscribe( - GameLib.Event.GET_RENDER_CONFIGURATION, + R3.Event.GET_RENDER_CONFIGURATION, this.getRenderConfiguration ); this.setActiveRenderConfigurationSubscription = this.subscribe( - GameLib.Event.SET_ACTIVE_RENDER_CONFIGURATION, + R3.Event.SET_ACTIVE_RENDER_CONFIGURATION, this.setActiveRenderConfiguration ); - this.shaderUpdateSubscription = GameLib.Event.Subscribe( - GameLib.Event.SHADER_UPDATE, + this.shaderUpdateSubscription = R3.Event.Subscribe( + R3.Event.SHADER_UPDATE, this.shaderUpdate.bind(this) ); - // this.delayedInstanceEncounteredSubscription = GameLib.Event.Subscribe( - // GameLib.Event.DELAYED_INSTANCE_ENCOUNTERED, + // this.delayedInstanceEncounteredSubscription = R3.Event.Subscribe( + // R3.Event.DELAYED_INSTANCE_ENCOUNTERED, // this.delayedInstanceEncountered.bind(this) // ); @@ -143,8 +143,8 @@ GameLib.System.Render.prototype.start = function() { // false // ); - // GameLib.Event.Emit( - // GameLib.Event.WINDOW_RESIZE, + // R3.Event.Emit( + // R3.Event.WINDOW_RESIZE, // { // width : window.screen.availWidth, // height : window.screen.availHeight @@ -155,19 +155,19 @@ GameLib.System.Render.prototype.start = function() { }; // -// GameLib.System.Render.prototype.delayedInstanceEncountered = function() { +// R3.System.Render.prototype.delayedInstanceEncountered = function() { // // // }; -GameLib.System.Render.prototype.run = function() { +R3.System.Render.prototype.run = function() { this.animationFrameHook = requestAnimationFrame( this.run.bind(this) ); this.delta = this.clock.getDelta(); - GameLib.Event.Emit( - GameLib.Event.RENDER, + R3.Event.Emit( + R3.Event.RENDER, { delta : this.delta } @@ -175,9 +175,9 @@ GameLib.System.Render.prototype.run = function() { }; -// GameLib.System.Render.prototype.nativeWindowResize = function() { -// GameLib.Event.Emit( -// GameLib.Event.WINDOW_RESIZE, +// R3.System.Render.prototype.nativeWindowResize = function() { +// R3.Event.Emit( +// R3.Event.WINDOW_RESIZE, // { // width : window.screen.availWidth, // height : window.screen.availHeight @@ -185,15 +185,15 @@ GameLib.System.Render.prototype.run = function() { // ); // }; -GameLib.System.Render.prototype.getRenderConfiguration = function (data, callback) { +R3.System.Render.prototype.getRenderConfiguration = function (data, callback) { callback(this.activeRenderConfiguration); }; -GameLib.System.Render.prototype.excludeFromEnvironmentUpdate = function (data) { +R3.System.Render.prototype.excludeFromEnvironmentUpdate = function (data) { if (data.component.excludeFromEnvironment) { console.log('excluding ' + data.component.name + ' from environment'); - GameLib.Utils.PushUnique(this.excludedFromEnvironment, data.component); + R3.Utils.PushUnique(this.excludedFromEnvironment, data.component); } else { var index = this.excludedFromEnvironment.indexOf(data.component); if (index !== -1) { @@ -203,7 +203,7 @@ GameLib.System.Render.prototype.excludeFromEnvironmentUpdate = function (data) { } }; -GameLib.System.Render.prototype.setActiveRenderConfiguration = function (data) { +R3.System.Render.prototype.setActiveRenderConfiguration = function (data) { if (this.renderConfigurations.indexOf(data.renderConfiguration) !== -1) { this.activeRenderConfiguration = data.renderConfiguration; @@ -213,21 +213,21 @@ GameLib.System.Render.prototype.setActiveRenderConfiguration = function (data) { }; -GameLib.System.Render.prototype.getOffset = function (el) { +R3.System.Render.prototype.getOffset = function (el) { var rect = el.getBoundingClientRect(), scrollLeft = window.pageXOffset || document.documentElement.scrollLeft, scrollTop = window.pageYOffset || document.documentElement.scrollTop; return { top: rect.top + scrollTop, left: rect.left + scrollLeft } }; -GameLib.System.Render.prototype.windowResize = function(data) { +R3.System.Render.prototype.windowResize = function(data) { - GameLib.Event.Emit( - GameLib.Event.BEFORE_WINDOW_RESIZE, + R3.Event.Emit( + R3.Event.BEFORE_WINDOW_RESIZE, data ); - GameLib.EntityManager.Instance.queryComponentsByConstructor(GameLib.D3.RenderTarget).map( + R3.EntityManager.Instance.queryComponentsByConstructor(R3.D3.RenderTarget).map( function(renderTarget) { if (renderTarget.autoUpdateSize) { renderTarget.updateInstance('autoUpdateSize'); @@ -235,36 +235,36 @@ GameLib.System.Render.prototype.windowResize = function(data) { } ); - GameLib.EntityManager.Instance.queryComponentsByConstructor(GameLib.Renderer).map( + R3.EntityManager.Instance.queryComponentsByConstructor(R3.Renderer).map( function(renderer) { renderer.setSize(data.width, data.height); } ); - GameLib.EntityManager.Instance.queryComponentsByConstructor(GameLib.D3.Effect).map( + R3.EntityManager.Instance.queryComponentsByConstructor(R3.D3.Effect).map( function(effect){ effect.setSize(data.width, data.height); } ); - GameLib.EntityManager.Instance.queryComponentsByConstructor(GameLib.Canvas).map( + R3.EntityManager.Instance.queryComponentsByConstructor(R3.Canvas).map( function(canvas) { canvas.updateInstance('autoUpdateSize'); } ); - GameLib.EntityManager.Instance.queryComponentsByConstructor(GameLib.D3.Camera).map( + R3.EntityManager.Instance.queryComponentsByConstructor(R3.D3.Camera).map( function(camera){ if ( - camera instanceof GameLib.D3.Camera.Orthographic && - camera.aspectRatioMode !== GameLib.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_NONE + camera instanceof R3.D3.Camera.Orthographic && + camera.aspectRatioMode !== R3.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_NONE ) { camera.updateInstance('aspect'); } if ( - camera instanceof GameLib.D3.Camera.Perspective || - camera instanceof GameLib.D3.Camera.Stereo + camera instanceof R3.D3.Camera.Perspective || + camera instanceof R3.D3.Camera.Stereo ) { camera.aspect = data.width / data.height; camera.updateInstance('aspect'); @@ -272,7 +272,7 @@ GameLib.System.Render.prototype.windowResize = function(data) { } ); - GameLib.EntityManager.Instance.queryComponents(GameLib.Component.COMPOSER).map( + R3.EntityManager.Instance.queryComponents(R3.Component.COMPOSER).map( function(composer){ composer.setSize( @@ -291,14 +291,14 @@ GameLib.System.Render.prototype.windowResize = function(data) { } ); - GameLib.Event.Emit( - GameLib.Event.AFTER_WINDOW_RESIZE, + R3.Event.Emit( + R3.Event.AFTER_WINDOW_RESIZE, data ); }; -GameLib.System.Render.prototype.shaderUpdate = function(data) { +R3.System.Render.prototype.shaderUpdate = function(data) { this.activeRenderConfiguration.activeScenes.map( function(scene){ @@ -311,9 +311,9 @@ GameLib.System.Render.prototype.shaderUpdate = function(data) { }; -GameLib.System.Render.prototype.textureUpdated = function(data) { +R3.System.Render.prototype.textureUpdated = function(data) { - GameLib.EntityManager.Instance.queryComponentsByConstructor(GameLib.D3.Material).map( + R3.EntityManager.Instance.queryComponentsByConstructor(R3.D3.Material).map( function(material) { material.getTextures().map( @@ -339,9 +339,9 @@ GameLib.System.Render.prototype.textureUpdated = function(data) { * From now on we want to track everything about a component, only from the systems that are active * @param data */ -GameLib.System.Render.prototype.instanceCreated = function(data) { +R3.System.Render.prototype.instanceCreated = function(data) { - if (data.component instanceof GameLib.RenderConfiguration) { + if (data.component instanceof R3.RenderConfiguration) { console.log('adding render configuration to render system'); this.renderConfigurations.push(data.component); @@ -350,37 +350,37 @@ GameLib.System.Render.prototype.instanceCreated = function(data) { } } - if (data.component instanceof GameLib.Renderer) { + if (data.component instanceof R3.Renderer) { console.log('adding renderer to render system'); this.renderers.push(data.component); } - if (data.component instanceof GameLib.D3.Composer) { + if (data.component instanceof R3.D3.Composer) { console.log('adding composer to render system'); this.composers.push(data.component); } - if (data.component instanceof GameLib.Stats) { + if (data.component instanceof R3.Stats) { this.statistics.push(data.component); } - if (data.component instanceof GameLib.D3.Camera.Cube) { + if (data.component instanceof R3.D3.Camera.Cube) { this.cubeCameras.push(data.component); } if ( - data.component instanceof GameLib.D3.Mesh && + data.component instanceof R3.D3.Mesh && data.component.excludeFromEnvironment ) { - GameLib.Utils.PushUnique(this.excludedFromEnvironment, data.component); + R3.Utils.PushUnique(this.excludedFromEnvironment, data.component); } - if (data.component instanceof GameLib.D3.Texture) { + if (data.component instanceof R3.D3.Texture) { /** * Link Parent Textures to Canvas Objects */ - GameLib.EntityManager.Instance.queryComponents(GameLib.Component.CANVAS).map( + R3.EntityManager.Instance.queryComponents(R3.Component.CANVAS).map( function(canvas){ if (canvas.parentTexture === data.component.id) { canvas.parentTexture = data.component; @@ -391,7 +391,7 @@ GameLib.System.Render.prototype.instanceCreated = function(data) { /** * Find all Render Targets and see if their textures need updating */ - GameLib.EntityManager.Instance.queryComponents(GameLib.Component.RENDER_TARGET).map( + R3.EntityManager.Instance.queryComponents(R3.Component.RENDER_TARGET).map( function(renderTarget) { if (renderTarget.texture === data.component) { /** @@ -408,8 +408,8 @@ GameLib.System.Render.prototype.instanceCreated = function(data) { ) } - if (data.component instanceof GameLib.Canvas) { - GameLib.EntityManager.Instance.queryComponents(GameLib.Component.TEXTURE_CANVAS).map( + if (data.component instanceof R3.Canvas) { + R3.EntityManager.Instance.queryComponents(R3.Component.TEXTURE_CANVAS).map( function(texture){ if (data.component.parentTexture === texture.id) { data.component.parentTexture = texture; @@ -419,10 +419,10 @@ GameLib.System.Render.prototype.instanceCreated = function(data) { } }; -GameLib.System.Render.prototype.replaceComponent = function(data) { +R3.System.Render.prototype.replaceComponent = function(data) { - if (data.current instanceof GameLib.D3.Material) { - GameLib.EntityManager.Instance.queryComponentsByConstructor(GameLib.D3.Mesh).map( + if (data.current instanceof R3.D3.Material) { + R3.EntityManager.Instance.queryComponentsByConstructor(R3.D3.Mesh).map( function(mesh) { var index = mesh.materials.indexOf(data.current); @@ -438,8 +438,8 @@ GameLib.System.Render.prototype.replaceComponent = function(data) { ); } - if (data.current instanceof GameLib.D3.Light) { - GameLib.EntityManager.Instance.queryComponents(GameLib.Component.SCENE).map( + if (data.current instanceof R3.D3.Light) { + R3.EntityManager.Instance.queryComponents(R3.Component.SCENE).map( function(scene) { var index = scene.lights.indexOf(data.current); @@ -453,8 +453,8 @@ GameLib.System.Render.prototype.replaceComponent = function(data) { ); } - if (data.current instanceof GameLib.D3.Pass) { - GameLib.EntityManager.Instance.queryComponents(GameLib.Component.COMPOSER).map( + if (data.current instanceof R3.D3.Pass) { + R3.EntityManager.Instance.queryComponents(R3.Component.COMPOSER).map( function(composer) { var index = composer.passes.indexOf(data.current); @@ -479,8 +479,8 @@ GameLib.System.Render.prototype.replaceComponent = function(data) { } if ( - data.current instanceof GameLib.Renderer && - data.replacement instanceof GameLib.Renderer + data.current instanceof R3.Renderer && + data.replacement instanceof R3.Renderer ) { data.replacement.canvas.remove(); data.replacement.canvas = data.current.canvas; @@ -490,7 +490,7 @@ GameLib.System.Render.prototype.replaceComponent = function(data) { this.activeRenderConfiguration.activeRenderer = data.replacement; } - if (this.activeRenderConfiguration.activeRenderer instanceof GameLib.Renderer.D2) { + if (this.activeRenderConfiguration.activeRenderer instanceof R3.Renderer.D2) { if (this.activeRenderConfiguration.activeCamera) { this.activeRenderConfiguration.activeCamera.remove(); @@ -513,11 +513,11 @@ GameLib.System.Render.prototype.replaceComponent = function(data) { * Removes a particle engine from this system * @param data */ -GameLib.System.Render.prototype.removeComponent = function(data) { +R3.System.Render.prototype.removeComponent = function(data) { var index; - if (data.component instanceof GameLib.RenderConfiguration) { + if (data.component instanceof R3.RenderConfiguration) { index = this.renderConfigurations.indexOf(data.component); @@ -539,7 +539,7 @@ GameLib.System.Render.prototype.removeComponent = function(data) { } } - if (data.component instanceof GameLib.Renderer) { + if (data.component instanceof R3.Renderer) { index = this.renderers.indexOf(data.component); @@ -553,7 +553,7 @@ GameLib.System.Render.prototype.removeComponent = function(data) { } } - if (data.component instanceof GameLib.D3.Composer) { + if (data.component instanceof R3.D3.Composer) { index = this.composers.indexOf(data.component); @@ -567,7 +567,7 @@ GameLib.System.Render.prototype.removeComponent = function(data) { } } - if (data.component instanceof GameLib.Stats) { + if (data.component instanceof R3.Stats) { index = this.statistics.indexOf(data.component); @@ -581,7 +581,7 @@ GameLib.System.Render.prototype.removeComponent = function(data) { } } - if (data.component instanceof GameLib.D3.Camera.Cube) { + if (data.component instanceof R3.D3.Camera.Cube) { index = this.cubeCameras.indexOf(data.component); @@ -595,7 +595,7 @@ GameLib.System.Render.prototype.removeComponent = function(data) { } } - if (data.component instanceof GameLib.D3.Mesh) { + if (data.component instanceof R3.D3.Mesh) { index = this.excludedFromEnvironment.indexOf(data.component); if (index !== -1) { console.log('removing excluded environment mesh from system'); @@ -607,7 +607,7 @@ GameLib.System.Render.prototype.removeComponent = function(data) { /** * Render subscription script */ -GameLib.System.Render.prototype.render = function(data) { +R3.System.Render.prototype.render = function(data) { if (this.statistics) { this.statistics.map( @@ -617,8 +617,8 @@ GameLib.System.Render.prototype.render = function(data) { ); } - GameLib.Event.Emit( - GameLib.Event.BEFORE_RENDER, + R3.Event.Emit( + R3.Event.BEFORE_RENDER, data ); @@ -630,7 +630,7 @@ GameLib.System.Render.prototype.render = function(data) { var renderer = configuration.activeRenderer; - if (renderer instanceof GameLib.Renderer.D2) { + if (renderer instanceof R3.Renderer.D2) { return; } @@ -659,8 +659,8 @@ GameLib.System.Render.prototype.render = function(data) { } if ( - renderer.renderMode === GameLib.API.Renderer.MODE_TARGET || - renderer.renderMode === GameLib.API.Renderer.MODE_CANVAS_AND_TARGET + renderer.renderMode === R3.API.Renderer.MODE_TARGET || + renderer.renderMode === R3.API.Renderer.MODE_CANVAS_AND_TARGET ) { if (!renderer.renderTarget) { console.warn('no render renderTarget'); @@ -719,8 +719,8 @@ GameLib.System.Render.prototype.render = function(data) { function (scene) { - if (renderer.renderMode === GameLib.API.Renderer.MODE_TARGET || - renderer.renderMode === GameLib.API.Renderer.MODE_CANVAS_AND_TARGET) { + if (renderer.renderMode === R3.API.Renderer.MODE_TARGET || + renderer.renderMode === R3.API.Renderer.MODE_CANVAS_AND_TARGET) { renderer.renderToTarget( scene, @@ -729,8 +729,8 @@ GameLib.System.Render.prototype.render = function(data) { } - if (renderer.renderMode === GameLib.API.Renderer.MODE_CANVAS || - renderer.renderMode === GameLib.API.Renderer.MODE_CANVAS_AND_TARGET) { + if (renderer.renderMode === R3.API.Renderer.MODE_CANVAS || + renderer.renderMode === R3.API.Renderer.MODE_CANVAS_AND_TARGET) { if (configuration.enableEffect) { effect.render(scene, camera); @@ -745,8 +745,8 @@ GameLib.System.Render.prototype.render = function(data) { }.bind(this) ); - GameLib.Event.Emit( - GameLib.Event.AFTER_RENDER, + R3.Event.Emit( + R3.Event.AFTER_RENDER, data ); @@ -762,9 +762,9 @@ GameLib.System.Render.prototype.render = function(data) { /** * Stop the rendering system */ -GameLib.System.Render.prototype.stop = function() { +R3.System.Render.prototype.stop = function() { - GameLib.System.prototype.stop.call(this); + R3.System.prototype.stop.call(this); cancelAnimationFrame(this.animationFrameHook); diff --git a/src/game-lib-system-socket.js b/src/r3-system-socket.js similarity index 57% rename from src/game-lib-system-socket.js rename to src/r3-system-socket.js index 56dc7f5..1381cc9 100644 --- a/src/game-lib-system-socket.js +++ b/src/r3-system-socket.js @@ -1,12 +1,12 @@ /** * System takes care of updating all the entities (based on their component data) - * @param apiSystem GameLib.API.System + * @param apiSystem R3.API.System * @constructor */ -GameLib.System.Socket = function( +R3.System.Socket = function( apiSystem ) { - GameLib.System.call( + R3.System.call( this, apiSystem ); @@ -26,32 +26,32 @@ GameLib.System.Socket = function( this.beforeRenderSubscription = null; }; -GameLib.System.Socket.prototype = Object.create(GameLib.System.prototype); -GameLib.System.Socket.prototype.constructor = GameLib.System.Socket; +R3.System.Socket.prototype = Object.create(R3.System.prototype); +R3.System.Socket.prototype.constructor = R3.System.Socket; /** * Start this system (add all event listeners) */ -GameLib.System.Socket.prototype.start = function() { +R3.System.Socket.prototype.start = function() { - GameLib.System.prototype.start.call(this); + R3.System.prototype.start.call(this); - this.castComponents = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.SOCKET_CAST); - this.receiveComponents = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.SOCKET_RECEIVE); - this.servers = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.SERVER); + this.castComponents = R3.EntityManager.Instance.queryComponents(R3.Component.SOCKET_CAST); + this.receiveComponents = R3.EntityManager.Instance.queryComponents(R3.Component.SOCKET_RECEIVE); + this.servers = R3.EntityManager.Instance.queryComponents(R3.Component.SERVER); - this.instanceCreatedSubscription = GameLib.Event.Subscribe( - GameLib.Event.INSTANCE_CREATED, + this.instanceCreatedSubscription = R3.Event.Subscribe( + R3.Event.INSTANCE_CREATED, this.instanceCreated.bind(this) ); - this.removeComponentSubscription = GameLib.Event.Subscribe( - GameLib.Event.REMOVE_COMPONENT, + this.removeComponentSubscription = R3.Event.Subscribe( + R3.Event.REMOVE_COMPONENT, this.removeComponent.bind(this) ); - this.beforeRenderSubscription = GameLib.Event.Subscribe( - GameLib.Event.BEFORE_RENDER, + this.beforeRenderSubscription = R3.Event.Subscribe( + R3.Event.BEFORE_RENDER, this.beforeRender.bind(this) ); @@ -61,7 +61,7 @@ GameLib.System.Socket.prototype.start = function() { * Connect to the socket server * @param socketComponent */ -GameLib.System.Socket.prototype.connect = function(socketComponent) { +R3.System.Socket.prototype.connect = function(socketComponent) { console.log(socketComponent.name + ' is connecting to the server ' + socketComponent.serverIp); }; @@ -69,7 +69,7 @@ GameLib.System.Socket.prototype.connect = function(socketComponent) { * Disconnect from the socket server * @param socketComponent */ -GameLib.System.Socket.prototype.disconnect = function(socketComponent) { +R3.System.Socket.prototype.disconnect = function(socketComponent) { console.log(socketComponent.name + ' is disconnecting from server ' + socketComponent.serverIp); }; @@ -78,18 +78,18 @@ GameLib.System.Socket.prototype.disconnect = function(socketComponent) { * From now on we want to track everything about a component, only from the systems that are active * @param data */ -GameLib.System.Socket.prototype.instanceCreated = function(data) { +R3.System.Socket.prototype.instanceCreated = function(data) { - if (data.component instanceof GameLib.Socket.Cast) { - GameLib.Utils.PushUnique(this.castComponents, data.component); + if (data.component instanceof R3.Socket.Cast) { + R3.Utils.PushUnique(this.castComponents, data.component); } - if (data.component instanceof GameLib.Socket.Receive) { - GameLib.Utils.PushUnique(this.receiveComponents, data.component); + if (data.component instanceof R3.Socket.Receive) { + R3.Utils.PushUnique(this.receiveComponents, data.component); } - if (data.component instanceof GameLib.Server) { - GameLib.Utils.PushUnique(this.servers, data.component); + if (data.component instanceof R3.Server) { + R3.Utils.PushUnique(this.servers, data.component); } }; @@ -97,11 +97,11 @@ GameLib.System.Socket.prototype.instanceCreated = function(data) { * Removes a cast or receive component from this system * @param data */ -GameLib.System.Socket.prototype.removeComponent = function(data) { +R3.System.Socket.prototype.removeComponent = function(data) { var index; - if (data.component instanceof GameLib.Socket.Cast) { + if (data.component instanceof R3.Socket.Cast) { index = this.castComponents.indexOf(data.component); @@ -112,7 +112,7 @@ GameLib.System.Socket.prototype.removeComponent = function(data) { } } - if (data.component instanceof GameLib.Socket.Receive) { + if (data.component instanceof R3.Socket.Receive) { index = this.receiveComponents.indexOf(data.component); @@ -124,7 +124,7 @@ GameLib.System.Socket.prototype.removeComponent = function(data) { } - if (data.component instanceof GameLib.Server) { + if (data.component instanceof R3.Server) { index = this.servers.indexOf(data.component); @@ -140,7 +140,7 @@ GameLib.System.Socket.prototype.removeComponent = function(data) { /** * @param data */ -GameLib.System.Socket.prototype.beforeRender = function(data) { +R3.System.Socket.prototype.beforeRender = function(data) { this.totalTime += data.delta; @@ -150,9 +150,9 @@ GameLib.System.Socket.prototype.beforeRender = function(data) { /** * Stop this system (remove all event listeners) */ -GameLib.System.Socket.prototype.stop = function() { +R3.System.Socket.prototype.stop = function() { - GameLib.System.prototype.stop.call(this); + R3.System.prototype.stop.call(this); this.instanceCreatedSubscription.remove(); this.removeComponentSubscription.remove(); diff --git a/src/game-lib-system-storage.js b/src/r3-system-storage.js similarity index 83% rename from src/game-lib-system-storage.js rename to src/r3-system-storage.js index a36528d..0e08da9 100644 --- a/src/game-lib-system-storage.js +++ b/src/r3-system-storage.js @@ -1,6 +1,6 @@ /** * Storage System takes care loading and linking components and dependencies - * @param apiSystem GameLib.API.System + * @param apiSystem R3.API.System * @param token * @param apiUploadUrl * @param onImageLoaded @@ -8,7 +8,7 @@ * @param onImageError * @constructor */ -GameLib.System.Storage = function( +R3.System.Storage = function( apiSystem, token, apiUploadUrl, @@ -16,33 +16,33 @@ GameLib.System.Storage = function( onImageProgress, onImageError ) { - GameLib.System.call( + R3.System.call( this, apiSystem ); - if (GameLib.Utils.UndefinedOrNull(token)) { + if (R3.Utils.UndefinedOrNull(token)) { token = null; } this.token = token; - if (GameLib.Utils.UndefinedOrNull(apiUploadUrl)) { + if (R3.Utils.UndefinedOrNull(apiUploadUrl)) { console.warn('Need an API Upload URL for a storage system'); apiUploadUrl = ''; } this.apiUploadUrl = apiUploadUrl; - if (GameLib.Utils.UndefinedOrNull(onImageLoaded)) { + if (R3.Utils.UndefinedOrNull(onImageLoaded)) { onImageLoaded = null; } this.onImageLoaded = onImageLoaded; - if (GameLib.Utils.UndefinedOrNull(onImageProgress)) { + if (R3.Utils.UndefinedOrNull(onImageProgress)) { onImageProgress = null; } this.onImageProgress = onImageProgress; - if (GameLib.Utils.UndefinedOrNull(onImageError)) { + if (R3.Utils.UndefinedOrNull(onImageError)) { onImageError = null; } this.onImageError = onImageError; @@ -63,72 +63,72 @@ GameLib.System.Storage = function( this.fetchComponentsSubscription = null; }; -GameLib.System.Storage.prototype = Object.create(GameLib.System.prototype); -GameLib.System.Storage.prototype.constructor = GameLib.System.Storage; +R3.System.Storage.prototype = Object.create(R3.System.prototype); +R3.System.Storage.prototype.constructor = R3.System.Storage; -GameLib.System.Storage.prototype.start = function() { +R3.System.Storage.prototype.start = function() { - GameLib.System.prototype.start.call(this); + R3.System.prototype.start.call(this); this.loginSubscription = this.subscribe( - GameLib.Event.LOGGED_IN, + R3.Event.LOGGED_IN, function(data) { this.token = data.token; } ); this.saveSubscription = this.subscribe( - GameLib.Event.SAVE_COMPONENT, + R3.Event.SAVE_COMPONENT, this.save ); this.loadSubscription = this.subscribe( - GameLib.Event.LOAD_COMPONENT, + R3.Event.LOAD_COMPONENT, this.load ); this.deleteSubscription = this.subscribe( - GameLib.Event.DELETE_COMPONENT, + R3.Event.DELETE_COMPONENT, this.delete ); this.loadImageSubscription = this.subscribe( - GameLib.Event.LOAD_IMAGE, + R3.Event.LOAD_IMAGE, this.loadImage ); this.loadFontSubscription = this.subscribe( - GameLib.Event.LOAD_FONT, + R3.Event.LOAD_FONT, this.loadFont ); this.blenderDataSubscription = this.subscribe( - GameLib.Event.BLENDER_DATA_RECEIVED, + R3.Event.BLENDER_DATA_RECEIVED, this.processBlenderData ); this.imageUploadCompleteSubscription = this.subscribe( - GameLib.Event.IMAGE_UPLOAD_COMPLETE, + R3.Event.IMAGE_UPLOAD_COMPLETE, this.imageUploadComplete ); this.fetchComponentTypesSubscription = this.subscribe( - GameLib.Event.FETCH_COMPONENT_TYPES, + R3.Event.FETCH_COMPONENT_TYPES, this.fetchComponentTypes ); this.fetchComponentsSubscription = this.subscribe( - GameLib.Event.FETCH_COMPONENTS, + R3.Event.FETCH_COMPONENTS, this.fetchComponents ); }; -GameLib.System.Storage.prototype.delete = function(data) { +R3.System.Storage.prototype.delete = function(data) { this.publish( - GameLib.Event.GET_API_URL, + R3.Event.GET_API_URL, null, function(urlData) { @@ -155,8 +155,8 @@ GameLib.System.Storage.prototype.delete = function(data) { try { var response = JSON.parse(this.responseText) } catch (error) { - GameLib.Event.Emit( - GameLib.Event.DELETE_COMPONENT_ERROR, + R3.Event.Emit( + R3.Event.DELETE_COMPONENT_ERROR, { message: this.responseText } @@ -164,15 +164,15 @@ GameLib.System.Storage.prototype.delete = function(data) { } if (response.result === 'success') { - GameLib.Event.Emit( - GameLib.Event.COMPONENT_DELETED, + R3.Event.Emit( + R3.Event.COMPONENT_DELETED, { message: response.message || 'Successfully saved the component' } ) } else { - GameLib.Event.Emit( - GameLib.Event.DELETE_COMPONENT_ERROR, + R3.Event.Emit( + R3.Event.DELETE_COMPONENT_ERROR, { message: response.message || 'The server responded but failed to save the component' } @@ -200,12 +200,12 @@ GameLib.System.Storage.prototype.delete = function(data) { /** * 'Saves' data to somewhere */ -GameLib.System.Storage.prototype.save = function(data) { +R3.System.Storage.prototype.save = function(data) { - var event = GameLib.Event.GET_API_URL; + var event = R3.Event.GET_API_URL; if (data.remote) { - event = GameLib.Event.GET_REMOTE_API_URL + event = R3.Event.GET_REMOTE_API_URL } this.publish( @@ -233,8 +233,8 @@ GameLib.System.Storage.prototype.save = function(data) { try { var response = JSON.parse(this.responseText) } catch (error) { - GameLib.Event.Emit( - GameLib.Event.SAVE_COMPONENT_ERROR, + R3.Event.Emit( + R3.Event.SAVE_COMPONENT_ERROR, { message: this.responseText, component : data.apiObject @@ -243,16 +243,16 @@ GameLib.System.Storage.prototype.save = function(data) { } if (response.result === 'success') { - GameLib.Event.Emit( - GameLib.Event.COMPONENT_SAVED, + R3.Event.Emit( + R3.Event.COMPONENT_SAVED, { message: response.message || 'Successfully saved the component', component : data.apiObject } ) } else { - GameLib.Event.Emit( - GameLib.Event.SAVE_COMPONENT_ERROR, + R3.Event.Emit( + R3.Event.SAVE_COMPONENT_ERROR, { message: response.message || 'The server responded but failed to save the component', component : data.apiObject @@ -274,7 +274,7 @@ GameLib.System.Storage.prototype.save = function(data) { }; -GameLib.System.Storage.prototype.createRuntimeObject = function(responseText, clientErrorCallback) { +R3.System.Storage.prototype.createRuntimeObject = function(responseText, clientErrorCallback) { try { var object = JSON.parse(responseText); @@ -286,8 +286,8 @@ GameLib.System.Storage.prototype.createRuntimeObject = function(responseText, cl }) } - GameLib.Event.Emit( - GameLib.Event.LOAD_COMPONENT_ERROR, + R3.Event.Emit( + R3.Event.LOAD_COMPONENT_ERROR, {error: errorObject} ); @@ -302,8 +302,8 @@ GameLib.System.Storage.prototype.createRuntimeObject = function(responseText, cl }) } - GameLib.Event.Emit( - GameLib.Event.LOAD_COMPONENT_ERROR, + R3.Event.Emit( + R3.Event.LOAD_COMPONENT_ERROR, {error : object} ); @@ -315,7 +315,7 @@ GameLib.System.Storage.prototype.createRuntimeObject = function(responseText, cl * First, we create an API object from the Object, then a Runtime object from the API object * Each component has a function 'FromObject' which essentially does this for you */ - var runtimeComponent = GameLib.Component.ConstructFromObject(object.component[0]); + var runtimeComponent = R3.Component.ConstructFromObject(object.component[0]); if (!runtimeComponent) { if (clientErrorCallback) { @@ -329,7 +329,7 @@ GameLib.System.Storage.prototype.createRuntimeObject = function(responseText, cl return runtimeComponent; }; -GameLib.System.Storage.prototype.loadComponent = function(apiUrl, toProcess, includeDependencies, clientCallback, clientErrorCallback) { +R3.System.Storage.prototype.loadComponent = function(apiUrl, toProcess, includeDependencies, clientCallback, clientErrorCallback) { /** * We just do an initial check if these components to process are already in the register - @@ -341,9 +341,9 @@ GameLib.System.Storage.prototype.loadComponent = function(apiUrl, toProcess, inc toProcess.map( function(id) { - GameLib.Utils.PushUnique(this.loading, id); + R3.Utils.PushUnique(this.loading, id); - var component = GameLib.EntityManager.Instance.findComponentById(id); + var component = R3.EntityManager.Instance.findComponentById(id); if (component) { component.remove(); @@ -372,7 +372,7 @@ GameLib.System.Storage.prototype.loadComponent = function(apiUrl, toProcess, inc runtimeComponent.parentEntity && typeof runtimeComponent.parentEntity === 'string' ) { - GameLib.EntityManager.Instance.queryComponents(GameLib.Component.ENTITY).map( + R3.EntityManager.Instance.queryComponents(R3.Component.ENTITY).map( function (entity) { if (runtimeComponent.parentEntity === entity.id) { runtimeComponent.parentEntity = entity; @@ -381,8 +381,8 @@ GameLib.System.Storage.prototype.loadComponent = function(apiUrl, toProcess, inc ); } - GameLib.Event.Emit( - GameLib.Event.COMPONENT_CREATED, + R3.Event.Emit( + R3.Event.COMPONENT_CREATED, { component: runtimeComponent } @@ -413,7 +413,7 @@ GameLib.System.Storage.prototype.loadComponent = function(apiUrl, toProcess, inc dependencies.map( function(id) { - GameLib.Utils.PushUnique(this.otherDependencies, id); + R3.Utils.PushUnique(this.otherDependencies, id); }.bind(__system) ); @@ -443,7 +443,7 @@ GameLib.System.Storage.prototype.loadComponent = function(apiUrl, toProcess, inc function (result, dependency) { - if (GameLib.EntityManager.Instance.findComponentById(dependency)) { + if (R3.EntityManager.Instance.findComponentById(dependency)) { /** * Don't add the dependency */ @@ -476,7 +476,7 @@ GameLib.System.Storage.prototype.loadComponent = function(apiUrl, toProcess, inc */ dependencies.map( function (dependency) { - GameLib.Utils.PushUnique(__system.loading, dependency); + R3.Utils.PushUnique(__system.loading, dependency); } ); @@ -484,15 +484,15 @@ GameLib.System.Storage.prototype.loadComponent = function(apiUrl, toProcess, inc } - // GameLib.Event.Emit( - // GameLib.Event.COMPONENT_DOWNLOAD_COMPLETE, + // R3.Event.Emit( + // R3.Event.COMPONENT_DOWNLOAD_COMPLETE, // { // loaded: __system.loaded // } // ); - GameLib.Event.Emit( - GameLib.Event.LOAD_PROGRESS, + R3.Event.Emit( + R3.Event.LOAD_PROGRESS, { loading : __system.loading.length, loaded : __system.loaded.length @@ -547,10 +547,10 @@ GameLib.System.Storage.prototype.loadComponent = function(apiUrl, toProcess, inc /** * 'Loads' data from a url */ -GameLib.System.Storage.prototype.load = function(data, clientCallback, clientErrorCallback) { +R3.System.Storage.prototype.load = function(data, clientCallback, clientErrorCallback) { this.publish( - GameLib.Event.GET_API_URL, + R3.Event.GET_API_URL, null, function(urlData) { if (typeof XMLHttpRequest === 'undefined') { @@ -578,7 +578,7 @@ GameLib.System.Storage.prototype.load = function(data, clientCallback, clientErr }; -GameLib.System.Storage.prototype.xhrLoad = function( +R3.System.Storage.prototype.xhrLoad = function( url, callback, errorCallback @@ -639,7 +639,7 @@ GameLib.System.Storage.prototype.xhrLoad = function( * @param clientCallback * @param clientErrorCallback */ -GameLib.System.Storage.prototype.fetchComponentTypes = function(data, clientCallback, clientErrorCallback) { +R3.System.Storage.prototype.fetchComponentTypes = function(data, clientCallback, clientErrorCallback) { this.xhrLoad( data.url, function(response) { @@ -657,7 +657,7 @@ GameLib.System.Storage.prototype.fetchComponentTypes = function(data, clientCall * @param clientCallback * @param clientErrorCallback */ -GameLib.System.Storage.prototype.fetchComponents = function(data, clientCallback, clientErrorCallback) { +R3.System.Storage.prototype.fetchComponents = function(data, clientCallback, clientErrorCallback) { this.xhrLoad( data.url, function(response) { @@ -675,14 +675,14 @@ GameLib.System.Storage.prototype.fetchComponents = function(data, clientCallback * otherwise, create the runtime version of it * @param data */ -GameLib.System.Storage.prototype.imageUploadComplete = function(data) { +R3.System.Storage.prototype.imageUploadComplete = function(data) { /** * Process all images - we have to load them in addition to creating their runtime components */ data.images.map(function(rawImage){ - var image = GameLib.EntityManager.Instance.findComponentById(rawImage.id); + var image = R3.EntityManager.Instance.findComponentById(rawImage.id); if (image) { /** @@ -699,7 +699,7 @@ GameLib.System.Storage.prototype.imageUploadComplete = function(data) { /** * We are creating a new image */ - GameLib.Component.ConstructFromObject(rawImage); + R3.Component.ConstructFromObject(rawImage); } }.bind(this)); @@ -711,7 +711,7 @@ GameLib.System.Storage.prototype.imageUploadComplete = function(data) { * and announce their creation so the linking system can link them * @param data */ -GameLib.System.Storage.prototype.processBlenderData = function(data) { +R3.System.Storage.prototype.processBlenderData = function(data) { console.log('loading blender data'); @@ -720,9 +720,9 @@ GameLib.System.Storage.prototype.processBlenderData = function(data) { */ data.images.map( function(rawImageObject) { - var image = GameLib.Component.ConstructFromObject(rawImageObject); - GameLib.Event.Emit( - GameLib.Event.COMPONENT_CREATED, + var image = R3.Component.ConstructFromObject(rawImageObject); + R3.Event.Emit( + R3.Event.COMPONENT_CREATED, { component: image } @@ -734,9 +734,9 @@ GameLib.System.Storage.prototype.processBlenderData = function(data) { * Process all textures */ data.textures.map(function(rawTextureObject){ - var texture = GameLib.Component.ConstructFromObject(rawTextureObject); - GameLib.Event.Emit( - GameLib.Event.COMPONENT_CREATED, + var texture = R3.Component.ConstructFromObject(rawTextureObject); + R3.Event.Emit( + R3.Event.COMPONENT_CREATED, { component: texture } @@ -747,9 +747,9 @@ GameLib.System.Storage.prototype.processBlenderData = function(data) { * Process all materials */ data.materials.map(function(rawMaterialObject){ - var material = GameLib.Component.ConstructFromObject(rawMaterialObject); - GameLib.Event.Emit( - GameLib.Event.COMPONENT_CREATED, + var material = R3.Component.ConstructFromObject(rawMaterialObject); + R3.Event.Emit( + R3.Event.COMPONENT_CREATED, { component: material } @@ -760,9 +760,9 @@ GameLib.System.Storage.prototype.processBlenderData = function(data) { * Now process all meshes */ data.meshes.map(function(rawMeshObject){ - var mesh = GameLib.Component.ConstructFromObject(rawMeshObject); - GameLib.Event.Emit( - GameLib.Event.COMPONENT_CREATED, + var mesh = R3.Component.ConstructFromObject(rawMeshObject); + R3.Event.Emit( + R3.Event.COMPONENT_CREATED, { component: mesh } @@ -774,12 +774,12 @@ GameLib.System.Storage.prototype.processBlenderData = function(data) { */ }; -GameLib.System.Storage.prototype.loadFont = function(data, callback, errorCallback) { +R3.System.Storage.prototype.loadFont = function(data, callback, errorCallback) { console.log('loading font : ' + data.font.name); this.publish( - GameLib.Event.GET_API_URL, + R3.Event.GET_API_URL, null, function(urlData) { @@ -791,7 +791,7 @@ GameLib.System.Storage.prototype.loadFont = function(data, callback, errorCallba url, function ( font ) { - if (GameLib.Utils.IsEmpty(font.data)) { + if (R3.Utils.IsEmpty(font.data)) { errorCallback({message:'font is empty'}); @@ -812,12 +812,12 @@ GameLib.System.Storage.prototype.loadFont = function(data, callback, errorCallba }; -GameLib.System.Storage.prototype.loadImage = function(data, callback, errorCallback) { +R3.System.Storage.prototype.loadImage = function(data, callback, errorCallback) { console.log('loading image : ' + data.image.name); this.publish( - GameLib.Event.GET_API_URL, + R3.Event.GET_API_URL, null, function(urlData) { @@ -978,9 +978,9 @@ GameLib.System.Storage.prototype.loadImage = function(data, callback, errorCallb }; -GameLib.System.Storage.prototype.stop = function() { +R3.System.Storage.prototype.stop = function() { - GameLib.System.prototype.stop.call(this); + R3.System.prototype.stop.call(this); this.loginSubscription.remove(); this.loadSubscription.remove(); diff --git a/src/game-lib-system-visualization.js b/src/r3-system-visualization.js similarity index 65% rename from src/game-lib-system-visualization.js rename to src/r3-system-visualization.js index 8a81d84..5e03c0c 100644 --- a/src/game-lib-system-visualization.js +++ b/src/r3-system-visualization.js @@ -2,25 +2,25 @@ * System takes care of updating all the entities (based on their component data) * Visualization System takes care of visualizing all objects which are not meshes (like physics data) * - * @param apiSystem GameLib.API.System + * @param apiSystem R3.API.System * @param graphics * @param physics * @constructor */ -GameLib.System.Visualization = function( +R3.System.Visualization = function( apiSystem, graphics, physics ) { - GameLib.System.call( + R3.System.call( this, apiSystem ); - if (GameLib.Utils.UndefinedOrNull(graphics)){ - GameLib.Event.Emit( - GameLib.Event.GET_GRAPHICS_RUNTIME, + if (R3.Utils.UndefinedOrNull(graphics)){ + R3.Event.Emit( + R3.Event.GET_GRAPHICS_RUNTIME, null, function(graphicsRuntime) { graphics = graphicsRuntime; @@ -32,9 +32,9 @@ GameLib.System.Visualization = function( } this.graphics = graphics; - if (GameLib.Utils.UndefinedOrNull(physics)){ - GameLib.Event.Emit( - GameLib.Event.GET_PHYSICS_RUNTIME, + if (R3.Utils.UndefinedOrNull(physics)){ + R3.Event.Emit( + R3.Event.GET_PHYSICS_RUNTIME, null, function(physicsRuntime) { physics = physicsRuntime; @@ -51,26 +51,26 @@ GameLib.System.Visualization = function( }; -GameLib.System.Visualization.prototype = Object.create(GameLib.System.prototype); -GameLib.System.Visualization.prototype.constructor = GameLib.System.Visualization; +R3.System.Visualization.prototype = Object.create(R3.System.prototype); +R3.System.Visualization.prototype.constructor = R3.System.Visualization; -GameLib.System.Visualization.prototype.start = function() { +R3.System.Visualization.prototype.start = function() { - GameLib.System.prototype.start.call(this); + R3.System.prototype.start.call(this); this.visualizationSubscription = this.subscribe( - GameLib.Event.VISUALIZE, + R3.Event.VISUALIZE, this.visualize ); this.stopVisualizationSubscription = this.subscribe( - GameLib.Event.STOP_VISUALIZE, + R3.Event.STOP_VISUALIZE, this.stopVisualize ) }; -GameLib.System.Visualization.prototype.visualize = function(data) { +R3.System.Visualization.prototype.visualize = function(data) { var shape = data.shape; @@ -78,11 +78,11 @@ GameLib.System.Visualization.prototype.visualize = function(data) { shape.setFromMesh(); - var apiMesh = new GameLib.D3.API.Mesh(); + var apiMesh = new R3.D3.API.Mesh(); apiMesh.name = 'Visualization Mesh for Shape ' + shape.name; - if (shape instanceof GameLib.D3.Shape.HeightMap) { + if (shape instanceof R3.D3.Shape.HeightMap) { var v0 = new CANNON.Vec3(); var v1 = new CANNON.Vec3(); var v2 = new CANNON.Vec3(); @@ -97,19 +97,19 @@ GameLib.System.Visualization.prototype.visualize = function(data) { v1.vadd(shape.instance.pillarOffset, v1); v2.vadd(shape.instance.pillarOffset, v2); apiMesh.vertices.push( - new GameLib.D3.API.Vertex( - new GameLib.API.Vector3(v0.x, v0.y, v0.z) + new R3.D3.API.Vertex( + new R3.API.Vector3(v0.x, v0.y, v0.z) ), - new GameLib.D3.API.Vertex( - new GameLib.API.Vector3(v1.x, v1.y, v1.z) + new R3.D3.API.Vertex( + new R3.API.Vector3(v1.x, v1.y, v1.z) ), - new GameLib.D3.API.Vertex( - new GameLib.API.Vector3(v2.x, v2.y, v2.z) + new R3.D3.API.Vertex( + new R3.API.Vector3(v2.x, v2.y, v2.z) ) ); var i = apiMesh.vertices.length - 3; apiMesh.faces.push( - new GameLib.D3.API.Face( + new R3.D3.API.Face( null, null, i, @@ -122,19 +122,19 @@ GameLib.System.Visualization.prototype.visualize = function(data) { } } - new GameLib.D3.Mesh( + new R3.D3.Mesh( this.graphics, apiMesh ); }; -GameLib.System.Visualization.prototype.stopVisualize = function(data) { +R3.System.Visualization.prototype.stopVisualize = function(data) { }; -GameLib.System.Visualization.prototype.stop = function() { +R3.System.Visualization.prototype.stop = function() { - GameLib.System.prototype.stop.call(this); + R3.System.prototype.stop.call(this); if (this.visualizationSubscription) { this.visualizationSubscription.remove(); diff --git a/src/game-lib-vector2.js b/src/r3-vector2.js similarity index 60% rename from src/game-lib-vector2.js rename to src/r3-vector2.js index 19770ec..ca0a6e8 100644 --- a/src/game-lib-vector2.js +++ b/src/r3-vector2.js @@ -1,12 +1,12 @@ /** * Runtime vector2 for updating instance objects - * @param graphics GameLib.GraphicsRuntime - * @param parentObject GameLib.D3.* - * @param apiVector2 GameLib.API.Vector2 + * @param graphics R3.GraphicsRuntime + * @param parentObject R3.D3.* + * @param apiVector2 R3.API.Vector2 * @param grain Number * @constructor */ -GameLib.Vector2 = function ( +R3.Vector2 = function ( graphics, apiVector2, parentObject, @@ -14,22 +14,22 @@ GameLib.Vector2 = function ( ) { this.graphics = graphics; - if (GameLib.Utils.UndefinedOrNull(apiVector2)) { + if (R3.Utils.UndefinedOrNull(apiVector2)) { apiVector2 = {}; } - GameLib.API.Vector2.call( + R3.API.Vector2.call( this, apiVector2.x, apiVector2.y ); - if (GameLib.Utils.UndefinedOrNull(parentObject)) { + if (R3.Utils.UndefinedOrNull(parentObject)) { parentObject = null; } this.parentObject = parentObject; - if (GameLib.Utils.UndefinedOrNull(grain)) { + if (R3.Utils.UndefinedOrNull(grain)) { grain = 0.001; } this.grain = grain; @@ -37,15 +37,15 @@ GameLib.Vector2 = function ( this.createInstance(); }; -GameLib.Vector2.prototype = Object.create(GameLib.API.Vector2.prototype); -GameLib.Vector2.prototype.constructor = GameLib.Vector2; +R3.Vector2.prototype = Object.create(R3.API.Vector2.prototype); +R3.Vector2.prototype.constructor = R3.Vector2; /** * Creates an instance vector2 * @returns {*} */ -GameLib.Vector2.prototype.createInstance = function() { +R3.Vector2.prototype.createInstance = function() { if (this.graphics && this.graphics.isThree()) { this.instance = new THREE.Vector2(this.x, this.y); @@ -58,7 +58,7 @@ GameLib.Vector2.prototype.createInstance = function() { /** * Updates the instance vector, calls updateInstance on the parent object */ -GameLib.Vector2.prototype.updateInstance = function(property) { +R3.Vector2.prototype.updateInstance = function(property) { this.instance.x = this.x; this.instance.y = this.y; @@ -71,10 +71,10 @@ GameLib.Vector2.prototype.updateInstance = function(property) { /** * Converts runtime vector to API Vector - * @returns {GameLib.API.Vector2} + * @returns {R3.API.Vector2} */ -GameLib.Vector2.prototype.toApiObject = function() { - return new GameLib.API.Vector2( +R3.Vector2.prototype.toApiObject = function() { + return new R3.API.Vector2( this.x, this.y ); @@ -84,15 +84,15 @@ GameLib.Vector2.prototype.toApiObject = function() { * Copy * TODO: Test * @param v optional - * @returns {GameLib.Vector2} + * @returns {R3.Vector2} */ -GameLib.Vector2.prototype.copy = function (v) { +R3.Vector2.prototype.copy = function (v) { - if (GameLib.Utils.UndefinedOrNull(v)) { + if (R3.Utils.UndefinedOrNull(v)) { - return new GameLib.Vector2( + return new R3.Vector2( this.graphics, - new GameLib.API.Vector2( + new R3.API.Vector2( this.x, this.y ), @@ -115,7 +115,7 @@ GameLib.Vector2.prototype.copy = function (v) { * @param v * @returns {boolean} */ -GameLib.Vector2.prototype.equals = function(v) { +R3.Vector2.prototype.equals = function(v) { if ((this.x == v.x) && (this.y == v.y)) { @@ -131,13 +131,13 @@ GameLib.Vector2.prototype.equals = function(v) { * TODO: Test * @param v */ -GameLib.Vector2.prototype.add = function(v) { +R3.Vector2.prototype.add = function(v) { if ( - v instanceof GameLib.API.Vector2 || - v instanceof GameLib.API.Vector3 || - v instanceof GameLib.API.Vector4 || - v instanceof GameLib.API.Quaternion + v instanceof R3.API.Vector2 || + v instanceof R3.API.Vector3 || + v instanceof R3.API.Vector4 || + v instanceof R3.API.Quaternion ) { this.x += v.x; this.y += v.y; @@ -153,13 +153,13 @@ GameLib.Vector2.prototype.add = function(v) { * TODO: Test * @param v */ -GameLib.Vector2.prototype.subtract = function(v) { +R3.Vector2.prototype.subtract = function(v) { if ( - v instanceof GameLib.API.Vector2 || - v instanceof GameLib.API.Vector3 || - v instanceof GameLib.API.Vector4 || - v instanceof GameLib.API.Quaternion + v instanceof R3.API.Vector2 || + v instanceof R3.API.Vector3 || + v instanceof R3.API.Vector4 || + v instanceof R3.API.Quaternion ) { this.x -= v.x; this.y -= v.y; @@ -175,13 +175,13 @@ GameLib.Vector2.prototype.subtract = function(v) { * TODO: Test * @param v */ -GameLib.Vector2.prototype.multiply = function(v) { +R3.Vector2.prototype.multiply = function(v) { if ( - v instanceof GameLib.API.Vector2 || - v instanceof GameLib.API.Vector3 || - v instanceof GameLib.API.Vector4 || - v instanceof GameLib.API.Quaternion + v instanceof R3.API.Vector2 || + v instanceof R3.API.Vector3 || + v instanceof R3.API.Vector4 || + v instanceof R3.API.Quaternion ) { this.x *= v.x; this.y *= v.y; @@ -200,13 +200,13 @@ GameLib.Vector2.prototype.multiply = function(v) { * TODO: Test * @param v */ -GameLib.Vector2.prototype.divide = function(v) { +R3.Vector2.prototype.divide = function(v) { if ( - v instanceof GameLib.API.Vector2 || - v instanceof GameLib.API.Vector3 || - v instanceof GameLib.API.Vector4 || - v instanceof GameLib.API.Quaternion + v instanceof R3.API.Vector2 || + v instanceof R3.API.Vector3 || + v instanceof R3.API.Vector4 || + v instanceof R3.API.Quaternion ) { this.x *= (1.0 / v.x); this.y *= (1.0 / v.y); @@ -223,11 +223,11 @@ GameLib.Vector2.prototype.divide = function(v) { /** * Clamp * TODO: Test - * @param min GameLib.API.Vector2 - * @param max GameLib.API.Vector2 - * @returns {GameLib.Vector2} + * @param min R3.API.Vector2 + * @param max R3.API.Vector2 + * @returns {R3.Vector2} */ -GameLib.Vector2.prototype.clamp = function(min, max) { +R3.Vector2.prototype.clamp = function(min, max) { this.x = Math.max(min.x, Math.min(max.x, this.x)); this.y = Math.max(min.y, Math.min(max.y, this.y)); @@ -241,7 +241,7 @@ GameLib.Vector2.prototype.clamp = function(min, max) { * TODO: Test * @returns {number} */ -GameLib.Vector2.prototype.length = function() { +R3.Vector2.prototype.length = function() { return Math.sqrt( this.x * this.x + this.y * this.y ); @@ -253,7 +253,7 @@ GameLib.Vector2.prototype.length = function() { * @param v * @returns {number} */ -GameLib.Vector2.prototype.dot = function(v) { +R3.Vector2.prototype.dot = function(v) { return this.x * v.x + this.y * v.y; }; @@ -261,7 +261,7 @@ GameLib.Vector2.prototype.dot = function(v) { * Normalize * TODO: Test */ -GameLib.Vector2.prototype.normalize = function() { +R3.Vector2.prototype.normalize = function() { return this.multiply(1.0 / this.length()); }; @@ -270,7 +270,7 @@ GameLib.Vector2.prototype.normalize = function() { * Angle between this vector and origin * @returns {number} */ -GameLib.Vector2.prototype.angle = function() { +R3.Vector2.prototype.angle = function() { var angle = Math.atan2(this.y, this.x); if ( angle < 0 ) angle += 2 * Math.PI; return angle; @@ -281,10 +281,10 @@ GameLib.Vector2.prototype.angle = function() { * TODO: Test * @param v * @param alpha - * @returns {GameLib.Vector2} + * @returns {R3.Vector2} */ -GameLib.Vector2.prototype.lerp = function ( v, alpha ) { - return new GameLib.Vector2( +R3.Vector2.prototype.lerp = function ( v, alpha ) { + return new R3.Vector2( this.x + ( v.x - this.x ) * alpha, this.y + ( v.y - this.y ) * alpha ); diff --git a/src/game-lib-vector3.js b/src/r3-vector3.js similarity index 66% rename from src/game-lib-vector3.js rename to src/r3-vector3.js index ccc31b8..cdff564 100644 --- a/src/game-lib-vector3.js +++ b/src/r3-vector3.js @@ -1,14 +1,14 @@ /** * Runtime apiVector3 for updating instance objects - * @param implementation GameLib.GraphicsRuntime - * @param apiVector3 GameLib.API.Vector3 - * @param parentObject GameLib.* + * @param implementation R3.GraphicsRuntime + * @param apiVector3 R3.API.Vector3 + * @param parentObject R3.* * @param grain Number * @param min * @param max * @constructor */ -GameLib.Vector3 = function ( +R3.Vector3 = function ( implementation, apiVector3, parentObject, @@ -19,11 +19,11 @@ GameLib.Vector3 = function ( this.implementation = implementation; - if (implementation instanceof GameLib.GraphicsRuntime) { + if (implementation instanceof R3.GraphicsRuntime) { this.physics = null; this.graphics = implementation; this.graphics.isNotThreeThrow(); - } else if (implementation instanceof GameLib.PhysicsRuntime) { + } else if (implementation instanceof R3.PhysicsRuntime) { this.graphics = null; this.physics = implementation; this.physics.isNotCannonThrow(); @@ -31,33 +31,33 @@ GameLib.Vector3 = function ( throw new Error('Unhandled implementation : ' + implementation); } - if (GameLib.Utils.UndefinedOrNull(apiVector3)) { + if (R3.Utils.UndefinedOrNull(apiVector3)) { apiVector3 = {}; } - GameLib.API.Vector3.call( + R3.API.Vector3.call( this, apiVector3.x, apiVector3.y, apiVector3.z ); - if (GameLib.Utils.UndefinedOrNull(parentObject)) { + if (R3.Utils.UndefinedOrNull(parentObject)) { parentObject = this; } this.parentObject = parentObject; - if (GameLib.Utils.UndefinedOrNull(grain)) { + if (R3.Utils.UndefinedOrNull(grain)) { grain = 0.001; } this.grain = grain; - if (GameLib.Utils.UndefinedOrNull(min)) { + if (R3.Utils.UndefinedOrNull(min)) { min = 0; } this.min = min; - if (GameLib.Utils.UndefinedOrNull(max)) { + if (R3.Utils.UndefinedOrNull(max)) { max = 1; } this.max = max; @@ -66,14 +66,14 @@ GameLib.Vector3 = function ( this.createInstance(); }; -GameLib.Vector3.prototype = Object.create(GameLib.API.Vector3.prototype); -GameLib.Vector3.prototype.constructor = GameLib.Vector3; +R3.Vector3.prototype = Object.create(R3.API.Vector3.prototype); +R3.Vector3.prototype.constructor = R3.Vector3; /** * Creates an instance vector3 * @returns {*} */ -GameLib.Vector3.prototype.createInstance = function() { +R3.Vector3.prototype.createInstance = function() { if (this.graphics) { this.instance = new THREE.Vector3( @@ -94,7 +94,7 @@ GameLib.Vector3.prototype.createInstance = function() { /** * Updates the instance vector, calls updateInstance on the parent object */ -GameLib.Vector3.prototype.updateInstance = function(property, preventParentUpdate) { +R3.Vector3.prototype.updateInstance = function(property, preventParentUpdate) { this.instance.x = this.x; this.instance.y = this.y; @@ -111,8 +111,8 @@ GameLib.Vector3.prototype.updateInstance = function(property, preventParentUpdat /** * Converts runtime vector to API Vector */ -GameLib.Vector3.prototype.toApiObject = function() { - return new GameLib.API.Vector3( +R3.Vector3.prototype.toApiObject = function() { + return new R3.API.Vector3( this.x, this.y, this.z @@ -122,10 +122,10 @@ GameLib.Vector3.prototype.toApiObject = function() { /** * Creates a new copy of this Vector3 */ -GameLib.Vector3.prototype.copy = function() { - return new GameLib.Vector3( +R3.Vector3.prototype.copy = function() { + return new R3.Vector3( this.implementation, - new GameLib.API.Vector3( + new R3.API.Vector3( this.x, this.y, this.z @@ -135,10 +135,10 @@ GameLib.Vector3.prototype.copy = function() { ) }; -GameLib.Vector3.prototype.clone = function() { - return new GameLib.Vector3( +R3.Vector3.prototype.clone = function() { + return new R3.Vector3( this.implementation, - new GameLib.API.Vector3( + new R3.API.Vector3( this.x, this.y, this.z @@ -150,12 +150,12 @@ GameLib.Vector3.prototype.clone = function() { /** * Create a negative version of this vector - * @returns {GameLib.Vector3} + * @returns {R3.Vector3} */ -GameLib.Vector3.prototype.negativeCopy = function() { - return new GameLib.Vector3( +R3.Vector3.prototype.negativeCopy = function() { + return new R3.Vector3( this.implementation, - new GameLib.API.Vector3( + new R3.API.Vector3( -this.x, -this.y, -this.z @@ -170,7 +170,7 @@ GameLib.Vector3.prototype.negativeCopy = function() { * @param axis * @param angle */ -GameLib.Vector3.prototype.applyAxisAngle = function(axis, angle) { +R3.Vector3.prototype.applyAxisAngle = function(axis, angle) { this.instance.applyAxisAngle( new THREE.Vector3( @@ -186,7 +186,7 @@ GameLib.Vector3.prototype.applyAxisAngle = function(axis, angle) { this.z = this.instance.z; }; -GameLib.Vector3.prototype.setFrom = function(vector3) { +R3.Vector3.prototype.setFrom = function(vector3) { this.x = vector3.x; this.y = vector3.y; this.z = vector3.z; diff --git a/src/game-lib-vector4.js b/src/r3-vector4.js similarity index 63% rename from src/game-lib-vector4.js rename to src/r3-vector4.js index b908012..36e319a 100644 --- a/src/game-lib-vector4.js +++ b/src/r3-vector4.js @@ -1,12 +1,12 @@ /** * Runtime apiVector4 for updating instance objects - * @param graphics GameLib.GraphicsRuntime - * @param apiVector4 GameLib.API.Vector4 - * @param parentObject GameLib.* + * @param graphics R3.GraphicsRuntime + * @param apiVector4 R3.API.Vector4 + * @param parentObject R3.* * @param grain Number * @constructor */ -GameLib.Vector4 = function ( +R3.Vector4 = function ( graphics, apiVector4, parentObject, @@ -16,11 +16,11 @@ GameLib.Vector4 = function ( this.graphics = graphics; this.graphics.isNotThreeThrow(); - if (GameLib.Utils.UndefinedOrNull(apiVector4)) { + if (R3.Utils.UndefinedOrNull(apiVector4)) { apiVector4 = {}; } - GameLib.API.Vector4.call( + R3.API.Vector4.call( this, apiVector4.x, apiVector4.y, @@ -28,12 +28,12 @@ GameLib.Vector4 = function ( apiVector4.w ); - if (GameLib.Utils.UndefinedOrNull(parentObject)) { + if (R3.Utils.UndefinedOrNull(parentObject)) { parentObject = null; } this.parentObject = parentObject; - if (GameLib.Utils.UndefinedOrNull(grain)) { + if (R3.Utils.UndefinedOrNull(grain)) { grain = 0.001; } this.grain = grain; @@ -41,14 +41,14 @@ GameLib.Vector4 = function ( this.createInstance(); }; -GameLib.Vector4.prototype = Object.create(GameLib.API.Vector4.prototype); -GameLib.Vector4.prototype.constructor = GameLib.Vector4; +R3.Vector4.prototype = Object.create(R3.API.Vector4.prototype); +R3.Vector4.prototype.constructor = R3.Vector4; /** * Creates an instance vector4 * @returns {*} */ -GameLib.Vector4.prototype.createInstance = function() { +R3.Vector4.prototype.createInstance = function() { this.instance = new THREE.Quaternion( this.x, this.y, @@ -60,7 +60,7 @@ GameLib.Vector4.prototype.createInstance = function() { /** * Updates the instance vector, calls updateInstance on the parent object */ -GameLib.Vector4.prototype.updateInstance = function(property) { +R3.Vector4.prototype.updateInstance = function(property) { this.instance.x = this.x; this.instance.y = this.y; @@ -76,8 +76,8 @@ GameLib.Vector4.prototype.updateInstance = function(property) { /** * Converts runtime vector to API Vector */ -GameLib.Vector4.prototype.toApiObject = function() { - return new GameLib.API.Vector4( +R3.Vector4.prototype.toApiObject = function() { + return new R3.API.Vector4( this.x, this.y, this.z, diff --git a/src/r3-z.js b/src/r3-z.js new file mode 100644 index 0000000..3c359cb --- /dev/null +++ b/src/r3-z.js @@ -0,0 +1,10 @@ + +R3.EntityManager.Instance = new R3.EntityManager(); + +if (typeof window !== 'undefined') { + window.R3 = R3; +} + +if (typeof module !== 'undefined') { + module.exports = R3; +} \ No newline at end of file