diff --git a/src/game-lib-api-system.js b/src/game-lib-api-system.js index 08bd704..8d0ee8a 100644 --- a/src/game-lib-api-system.js +++ b/src/game-lib-api-system.js @@ -44,9 +44,6 @@ GameLib.API.System = function ( this.entityManager = entityManager; }; -GameLib.API.System.prototype = Object.create(GameLib.Component.prototype); -GameLib.API.System.prototype.constructor = GameLib.API.System; - /** * Object to GameLib.D3.API.System * @param objectComponent diff --git a/src/game-lib-d3-api-game.js b/src/game-lib-d3-api-game.js index 8c141a5..4728421 100644 --- a/src/game-lib-d3-api-game.js +++ b/src/game-lib-d3-api-game.js @@ -5,6 +5,8 @@ * @param gameType * @param width * @param height + * @param baseUrl + * @param path * @param scenes * @param cameras * @param renderers @@ -13,14 +15,14 @@ * @param viewports * @param entityManager * @param mouse - * @param activeCameraIndex - * @param activeRendererIndex * @param parentEntity * @constructor */ GameLib.D3.API.Game = function( id, name, + baseUrl, + path, gameType, width, height, @@ -45,7 +47,7 @@ GameLib.D3.API.Game = function( 'systems' : [GameLib.D3.System], 'viewports' : [GameLib.D3.Viewport], 'entityManager' : GameLib.EntityManager, - 'mouse' : GameLib.D3.Mouse + 'mouse' : GameLib.Mouse }, null, parentEntity @@ -60,7 +62,18 @@ GameLib.D3.API.Game = function( name = 'Game (' + this.id + ')'; } this.name = name; - + + if (GameLib.Utils.UndefinedOrNull(baseUrl)) { + baseUrl = ''; + console.warn('The base URL required for downloading images is not set - textured meshes will not render properly'); + } + this.baseUrl = baseUrl; + + if (GameLib.Utils.UndefinedOrNull(path)) { + path = null; + } + this.path = path; + if (GameLib.Utils.UndefinedOrNull(gameType)) { gameType = GameLib.D3.Game.GAME_TYPE_VR_PONG; } @@ -196,6 +209,8 @@ GameLib.D3.API.Game.FromObjectGame = function(objectGame) { return new GameLib.D3.API.Game( objectGame.id, objectGame.name, + objectGame.baseUrl, + objectGame.path, objectGame.gameType, objectGame.width, objectGame.height, diff --git a/src/game-lib-d3-api-scene.js b/src/game-lib-d3-api-scene.js index c772001..f3d2956 100644 --- a/src/game-lib-d3-api-scene.js +++ b/src/game-lib-d3-api-scene.js @@ -2,32 +2,24 @@ * Raw Scene API object - should always correspond with the Scene Schema * @param id String * @param name String - * @param baseUrl String - * @param path String * @param meshes [GameLib.D3.API.Mesh] * @param position GameLib.API.Vector3 * @param quaternion GameLib.API.Quaternion * @param scale GameLib.API.Vector3 * @param parentGameId * @param lights [GameLib.D3.API.Light] - * @param materials [GameLib.D3.API.Material] - * @param textures [GameLib.D3.API.Texture] * @param parentEntity * @constructor */ GameLib.D3.API.Scene = function( id, name, - baseUrl, - path, meshes, position, quaternion, scale, parentGameId, lights, - materials, - textures, parentEntity ) { GameLib.Component.call( @@ -35,9 +27,7 @@ GameLib.D3.API.Scene = function( GameLib.Component.COMPONENT_SCENE, { 'meshes' : [GameLib.D3.Mesh], - 'lights' : [GameLib.D3.Light], - 'textures' : [GameLib.D3.Texture], - 'materials' : [GameLib.D3.Material] + 'lights' : [GameLib.D3.Light] }, false, parentEntity @@ -53,17 +43,6 @@ GameLib.D3.API.Scene = function( } this.name = name; - if (GameLib.Utils.UndefinedOrNull(baseUrl)) { - baseUrl = ''; - console.warn('The base URL required for downloading images is not set - textured meshes will not render properly'); - } - this.baseUrl = baseUrl; - - if (GameLib.Utils.UndefinedOrNull(path)) { - path = null; - } - this.path = path; - if (GameLib.Utils.UndefinedOrNull(meshes)) { meshes = []; } @@ -94,18 +73,9 @@ GameLib.D3.API.Scene = function( } this.lights = lights; - if (GameLib.Utils.UndefinedOrNull(materials)) { - materials = []; - } - this.materials = materials; - - if (GameLib.Utils.UndefinedOrNull(textures)) { - textures = []; - } - this.textures = textures; }; -GameLib.D3.API.Scene.prototype = Object.create(GameLib.Scene.prototype); +GameLib.D3.API.Scene.prototype = Object.create(GameLib.Component.prototype); GameLib.D3.API.Scene.prototype.constructor = GameLib.D3.API.Scene; /** @@ -117,8 +87,6 @@ GameLib.D3.API.Scene.FromObjectScene = function(objectScene) { var apiMeshes = []; var apiLights = []; - var apiMaterials = []; - var apiTextures = []; var apiPosition = new GameLib.API.Vector3(); var apiQuaternion = new GameLib.API.Quaternion(); @@ -140,22 +108,6 @@ GameLib.D3.API.Scene.FromObjectScene = function(objectScene) { ) } - if (objectScene.textures) { - apiTextures = objectScene.textures.map( - function(objectTexture) { - return GameLib.D3.API.Texture.FromObjectTexture(objectTexture); - } - ) - } - - if (objectScene.materials) { - apiMaterials = objectScene.materials.map( - function(objectMaterial) { - return GameLib.D3.API.Material.FromObjectMaterial(objectMaterial); - } - ) - } - if (objectScene.position) { apiPosition = GameLib.API.Vector3.FromObjectVector(objectScene.position); } @@ -171,16 +123,12 @@ GameLib.D3.API.Scene.FromObjectScene = function(objectScene) { return new GameLib.D3.API.Scene( objectScene.id, objectScene.name, - objectScene.baseUrl, - objectScene.path, apiMeshes, apiPosition, apiQuaternion, apiScale, objectScene.parentGameId, apiLights, - apiMaterials, - apiTextures, objectScene.parentEntity ); diff --git a/src/game-lib-d3-coder.js b/src/game-lib-d3-coder.js index 3c75bab..e908934 100644 --- a/src/game-lib-d3-coder.js +++ b/src/game-lib-d3-coder.js @@ -28,9 +28,6 @@ GameLib.D3.Coder = function Coder( this.instance = this.createInstance(); }; -GameLib.D3.Coder.prototype = Object.create(GameLib.D3.API.Coder.prototype); -GameLib.D3.Coder.prototype.constructor = GameLib.D3.Coder; - /** * GameLib.D3.Coder Types * @type {number} diff --git a/src/game-lib-d3-game.js b/src/game-lib-d3-game.js index 5228bee..9b99b02 100644 --- a/src/game-lib-d3-game.js +++ b/src/game-lib-d3-game.js @@ -2,11 +2,13 @@ * Game Runtime * @param graphics GameLib.D3.Graphics * @param apiGame GameLib.D3.API.Game + * @param imageFactory * @constructor */ GameLib.D3.Game = function ( graphics, - apiGame + apiGame, + imageFactory ) { this.graphics = graphics; @@ -20,6 +22,8 @@ GameLib.D3.Game = function ( this, apiGame.id, apiGame.name, + apiGame.baseUrl, + apiGame.path, apiGame.gameType, apiGame.width, apiGame.height, @@ -34,6 +38,14 @@ GameLib.D3.Game = function ( apiGame.parentEntity ); + if (GameLib.Utils.UndefinedOrNull(imageFactory)) { + imageFactory = GameLib.D3.ImageFactory( + this.graphics, + this.baseUrl + ); + } + this.imageFactory = imageFactory; + this.scenes = this.scenes.map( function(apiScene) { @@ -130,39 +142,7 @@ GameLib.D3.Game = function ( }.bind(this) ); - this.idToObject = {}; - - if (this.entityManager instanceof GameLib.API.EntityManager) { - - this.entityManager = new GameLib.EntityManager( - this.graphics, - this.entityManager - ); - - this.entityManager.entities.map( - function (entity) { - this.idToObject[entity.id] = entity; - entity.components.map( - function(component) { - if (component instanceof GameLib.Component) { - this.idToObject[component.id] = component; - } else { - console.warn('Component not of type Component'); - throw new Error('Component not of type Component'); - } - }.bind(this) - ) - }.bind(this) - ); - - this.entityManager.linkObjects(this.idToObject); - - } else { - console.warn('EntityManager not of type API.EntityManager'); - throw new Error('EntityManager not of type API.EntityManager'); - } - - this.scenes = {}; + this.buildIdToObject(); }; GameLib.D3.Game.prototype = Object.create(GameLib.D3.API.Game.prototype); @@ -216,6 +196,55 @@ GameLib.D3.Game.prototype.updateInstance = function() { this.instance = this.createInstance(true); }; +GameLib.D3.Game.prototype.buildIdToObject = function() { + + this.idToObject = {}; + + if (this.entityManager instanceof GameLib.API.EntityManager) { + + this.entityManager = new GameLib.EntityManager( + this.graphics, + this.entityManager + ); + + this.entityManager.entities.map( + function (entity) { + this.idToObject[entity.id] = entity; + entity.components.map( + function(component) { + if (component instanceof GameLib.Component) { + this.idToObject[component.id] = component; + } else { + console.warn('Component not of type Component'); + throw new Error('Component not of type Component'); + } + }.bind(this) + ) + }.bind(this) + ); + + this.entityManager.linkObjects(this.idToObject); + + } else { + console.warn('EntityManager not of type API.EntityManager'); + throw new Error('EntityManager not of type API.EntityManager'); + } + + this.scenes.map( + function(scene) { + + var idToObject = scene.idToObject; + + for (var property in idToObject) { + if (idToObject.hasOwnProperty(property)) { + this.idToObject[property] = idToObject[property]; + } + } + }.bind(this) + ) + +}; + /** * Converts a GameLib.D3.Game to a new GameLib.D3.API.Game * @returns {GameLib.D3.API.Game} @@ -329,6 +358,8 @@ GameLib.D3.Game.prototype.toApiGame = function() { return new GameLib.D3.API.Game( this.id, this.name, + this.baseUrl, + this.path, this.gameType, this.width, this.height, diff --git a/src/game-lib-d3-graphics.js b/src/game-lib-d3-graphics.js index 5d6dd28..f884712 100644 --- a/src/game-lib-d3-graphics.js +++ b/src/game-lib-d3-graphics.js @@ -28,9 +28,6 @@ GameLib.D3.Graphics = function Graphics( this.instance = this.createInstance(); }; -GameLib.D3.Graphics.prototype = Object.create(GameLib.D3.API.Graphics.prototype); -GameLib.D3.Graphics.prototype.constructor = GameLib.D3.Graphics; - /** * GameLib.D3.Graphics Types * @type {number} diff --git a/src/game-lib-d3-input-editor.js b/src/game-lib-d3-input-editor.js index bb16dfa..b242fb1 100644 --- a/src/game-lib-d3-input-editor.js +++ b/src/game-lib-d3-input-editor.js @@ -63,6 +63,10 @@ GameLib.D3.Input.Editor = function ( this.graphics ); + this.mouse = new GameLib.Mouse( + this.graphics + ); + this.instance = this.createInstance(); }; @@ -372,12 +376,12 @@ GameLib.D3.Input.Editor.prototype.onMouseMove = function(event) { var clientX = event.clientX - this.widthOffset; - this.scene.mouse.x = ((clientX / (window.innerWidth - this.widthOffset))) * 2 - 1; - this.scene.mouse.y = -(event.clientY / window.innerHeight) * 2 + 1; + this.mouse.x = ((clientX / (window.innerWidth - this.widthOffset))) * 2 - 1; + this.mouse.y = -(event.clientY / window.innerHeight) * 2 + 1; - this.scene.raycaster.instance.setFromCamera( - this.scene.mouse, - this.scene.cameras[this.scene.activeCameraIndex].instance + this.raycaster.instance.setFromCamera( + this.mouse, + this.cameras[this.scene.activeCameraIndex].instance ); if (this.meshMoveMode) { @@ -398,6 +402,35 @@ GameLib.D3.Input.Editor.prototype.onMouseMove = function(event) { } }; +/** + * Moves selected objects along an axis + * @param alongAxis + * @param units + */ +GameLib.D3.Input.Editor.prototype.moveSelectedObjects = function(alongAxis, units) { + + for (var s = 0; s < this.editor.selectedObjects.length; s++) { + + var object = this.editor.selectedObjects[s].object; + + if (object.position) { + if (alongAxis == 'x') { + object.position.x += units; + } + if (alongAxis == 'y') { + object.position.y += units; + } + if (alongAxis == 'z') { + object.position.z += units; + } + + if (object.updateInstance) { + object.updateInstance(); + } + } + } +}; + /** * Prevent Context Menu creation * @param event diff --git a/src/game-lib-d3-material.js b/src/game-lib-d3-material.js index b447528..fe8993a 100644 --- a/src/game-lib-d3-material.js +++ b/src/game-lib-d3-material.js @@ -117,123 +117,159 @@ GameLib.D3.Material = function Material( ); if (this.alphaMap) { - this.alphaMap = new GameLib.D3.Texture( - this.graphics, - this.alphaMap, - this, - 'alphaMap', - imageFactory - ); + if (this.alphaMap instanceof GameLib.D3.API.Texture) { + this.alphaMap = new GameLib.D3.Texture( + this.graphics, + this.alphaMap, + imageFactory + ); + } else { + console.warn('this.alphaMap is not an instance of API.Texture'); + throw new Error('this.alphaMap is not an instance of API.Texture'); + } } if (this.aoMap) { - this.aoMap = new GameLib.D3.Texture( - this.graphics, - this.aoMap, - this, - 'aoMap', - imageFactory - ); + if (this.aoMap instanceof GameLib.D3.API.Texture) { + this.aoMap = new GameLib.D3.Texture( + this.graphics, + this.aoMap, + imageFactory + ); + } else { + console.warn('this.aoMap is not an instance of API.Texture'); + throw new Error('this.aoMap is not an instance of API.Texture'); + } } if (this.bumpMap) { - this.bumpMap = new GameLib.D3.Texture( - this.graphics, - this.bumpMap, - this, - 'bumpMap', - imageFactory - ); + if (this.bumpMap instanceof GameLib.D3.API.Texture) { + this.bumpMap = new GameLib.D3.Texture( + this.graphics, + this.bumpMap, + imageFactory + ); + } else { + console.warn('this.bumpMap is not an instance of API.Texture'); + throw new Error('this.bumpMap is not an instance of API.Texture'); + } } if (this.diffuseMap) { - this.diffuseMap = new GameLib.D3.Texture( - this.graphics, - this.diffuseMap, - this, - 'map', - imageFactory - ); + if (this.diffuseMap instanceof GameLib.D3.API.Texture) { + this.diffuseMap = new GameLib.D3.Texture( + this.graphics, + this.diffuseMap, + imageFactory + ); + } else { + console.warn('this.diffuseMap is not an instance of API.Texture'); + throw new Error('this.diffuseMap is not an instance of API.Texture'); + } } if (this.displacementMap) { - this.displacementMap = new GameLib.D3.Texture( - this.graphics, - this.displacementMap, - this, - 'displacementMap', - imageFactory - ); + if (this.displacementMap instanceof GameLib.D3.API.Texture) { + this.displacementMap = new GameLib.D3.Texture( + this.graphics, + this.displacementMap, + imageFactory + ); + } else { + console.warn('this.displacementMap is not an instance of API.Texture'); + throw new Error('this.displacementMap is not an instance of API.Texture'); + } } if (this.emissiveMap) { - this.emissiveMap = new GameLib.D3.Texture( - this.graphics, - this.emissiveMap, - this, - 'emissiveMap', - imageFactory - ); + if (this.emissiveMap instanceof GameLib.D3.API.Texture) { + this.emissiveMap = new GameLib.D3.Texture( + this.graphics, + this.emissiveMap, + imageFactory + ); + } else { + console.warn('this.emissiveMap is not an instance of API.Texture'); + throw new Error('this.emissiveMap is not an instance of API.Texture'); + } } if (this.environmentMap) { - this.environmentMap = new GameLib.D3.Texture( - this.graphics, - this.environmentMap, - this, - 'envMap', - imageFactory - ); + if (this.environmentMap instanceof GameLib.D3.API.Texture) { + this.environmentMap = new GameLib.D3.Texture( + this.graphics, + this.environmentMap, + imageFactory + ); + } else { + console.warn('this.environmentMap is not an instance of API.Texture'); + throw new Error('this.environmentMap is not an instance of API.Texture'); + } } if (this.lightMap) { - this.lightMap = new GameLib.D3.Texture( - this.graphics, - this.lightMap, - this, - 'lightMap', - imageFactory - ); + if (this.lightMap instanceof GameLib.D3.API.Texture) { + this.lightMap = new GameLib.D3.Texture( + this.graphics, + this.lightMap, + imageFactory + ); + } else { + console.warn('this.lightMap is not an instance of API.Texture'); + throw new Error('this.lightMap is not an instance of API.Texture'); + } } if (this.metalnessMap) { - this.metalnessMap = new GameLib.D3.Texture( - this.graphics, - this.metalnessMap, - this, - 'metalnessMap', - imageFactory - ); + if (this.metalnessMap instanceof GameLib.D3.API.Texture) { + this.metalnessMap = new GameLib.D3.Texture( + this.graphics, + this.metalnessMap, + imageFactory + ); + } else { + console.warn('this.metalnessMap is not an instance of API.Texture'); + throw new Error('this.metalnessMap is not an instance of API.Texture'); + } } if (this.normalMap) { - this.normalMap = new GameLib.D3.Texture( - this.graphics, - this.normalMap, - this, - 'normalMap', - imageFactory - ); + if (this.normalMap instanceof GameLib.D3.API.Texture) { + this.normalMap = new GameLib.D3.Texture( + this.graphics, + this.normalMap, + imageFactory + ); + } else { + console.warn('this.normalMap is not an instance of API.Texture'); + throw new Error('this.normalMap is not an instance of API.Texture'); + } } if (this.roughnessMap) { - this.roughnessMap = new GameLib.D3.Texture( - this.graphics, - this.roughnessMap, - this, - 'roughnessMap', - imageFactory - ); + if (this.roughnessMap instanceof GameLib.D3.API.Texture) { + this.roughnessMap = new GameLib.D3.Texture( + this.graphics, + this.roughnessMap, + imageFactory + ); + } else { + console.warn('this.roughnessMap is not an instance of API.Texture'); + throw new Error('this.roughnessMap is not an instance of API.Texture'); + } } if (this.specularMap) { - this.specularMap = new GameLib.D3.Texture( - this.graphics, - this.specularMap, - this, - 'specularMap', - imageFactory - ); + if (this.specularMap instanceof GameLib.D3.API.Texture) { + this.specularMap = new GameLib.D3.Texture( + this.graphics, + this.specularMap, + imageFactory + ); + } else { + console.warn('this.specularMap is not an instance of API.Texture'); + throw new Error('this.specularMap is not an instance of API.Texture'); + } } this.instance = this.createInstance(); @@ -512,61 +548,85 @@ GameLib.D3.Material.prototype.createInstance = function(update) { if (property == 'alphaMap') { if (this.alphaMap) { instance.alphaMap = this.alphaMap.instance; + } else { + instance.alphaMap = null; } } else if (property == 'aoMap') { if (this.aoMap) { instance.aoMap = this.aoMap.instance; + } else { + instance.aoMap = null; } } else if (property == 'bumpMap') { if (this.bumpMap) { instance.bumpMap = this.bumpMap.instance; + } else { + instance.bumpMap = null; } } else if (property == 'map') { if (this.diffuseMap) { instance.map = this.diffuseMap.instance; + } else { + instance.map = null; } } else if (property == 'displacementMap') { if (this.displacementMap) { instance.displacementMap = this.displacementMap.instance; + } else { + instance.displacementMap = null; } } else if (property == 'emissiveMap') { if (this.emissiveMap) { instance.emissiveMap = this.emissiveMap.instance; + } else { + instance.emissiveMap = null; } } else if (property == 'envMap') { if (this.environmentMap) { instance.envMap = this.environmentMap.instance; + } else { + instance.envMap = null; } } else if (property == 'lightMap') { if (this.lightMap) { instance.lightMap = this.lightMap.instance; + } else { + instance.lightMap = null; } } else if (property == 'metalnessMap') { if (this.metalnessMap) { instance.metalnessMap = this.metalnessMap.instance; + } else { + instance.metalnessMap = null; } } else if (property == 'normalMap') { if (this.normalMap) { instance.normalMap = this.normalMap.instance; + } else { + instance.normalMap = null; } } else if (property == 'roughnessMap') { if (this.roughnessMap) { instance.roughnessMap = this.roughnessMap.instance; + } else { + instance.roughnessMap = null; } } else if (property == 'specularMap') { if (this.specularMap) { instance.specularMap = this.specularMap.instance; + } else { + instance.specularMap = null; } } else if (property == 'size') { diff --git a/src/game-lib-d3-mesh.js b/src/game-lib-d3-mesh.js index b2da058..b890342 100644 --- a/src/game-lib-d3-mesh.js +++ b/src/game-lib-d3-mesh.js @@ -25,8 +25,8 @@ GameLib.D3.Mesh = function ( this.computeNormals = computeNormals; if (GameLib.Utils.UndefinedOrNull(imageFactory)) { - console.warn('Cannot create a mesh without specifying an ImageFactory'); - throw new Error('Cannot create a mesh without specifying an ImageFactory'); + console.warn('Cannot create a Mesh without specifying an ImageFactory'); + throw new Error('Cannot create a Mesh without specifying an ImageFactory'); } GameLib.D3.API.Mesh.call( diff --git a/src/game-lib-d3-scene.js b/src/game-lib-d3-scene.js index 24b70f4..d75f5ef 100644 --- a/src/game-lib-d3-scene.js +++ b/src/game-lib-d3-scene.js @@ -3,11 +3,10 @@ * created * @param graphics * @param apiScene GameLib.D3.API.Scene - * @param imageFactory * @param computeNormals * @constructor */ -GameLib.D3.Scene = function Scene( +GameLib.D3.Scene = function ( graphics, apiScene, imageFactory, @@ -20,14 +19,6 @@ GameLib.D3.Scene = function Scene( apiScene = {}; } - if (GameLib.Utils.UndefinedOrNull(imageFactory)) { - imageFactory = GameLib.D3.ImageFactory( - this.graphics, - this.baseUrl - ); - } - this.imageFactory = imageFactory; - if (GameLib.Utils.UndefinedOrNull(computeNormals)) { computeNormals = true; } @@ -37,8 +28,6 @@ GameLib.D3.Scene = function Scene( this, apiScene.id, apiScene.name, - apiScene.baseUrl, - apiScene.path, apiScene.meshes, apiScene.position, apiScene.quaternion, @@ -50,6 +39,12 @@ GameLib.D3.Scene = function Scene( apiScene.parentEntity ); + if (GameLib.Utils.UndefinedOrNull(imageFactory)) { + console.warn('Cannot create a Scene without specifying an ImageFactory'); + throw new Error('Cannot create a Scene without specifying an ImageFactory'); + } + this.imageFactory = imageFactory; + this.idToObject = {}; this.meshes = this.meshes.map( @@ -59,7 +54,7 @@ GameLib.D3.Scene = function Scene( this.graphics, apiMesh, this.computeNormals, - imageFactory + this.imageFactory ); this.idToObject[mesh.id] = mesh; @@ -75,6 +70,21 @@ GameLib.D3.Scene = function Scene( ) } + mesh.materials.map( + function(material) { + this.idToObject[material.id] = material; + + for (var property in material) { + if (material.hasOwnProperty(property)) { + if (material[property] instanceof GameLib.D3.Texture) { + this.idToObject[material[property].id] = material[property]; + } + } + } + + }.bind(this) + ); + return mesh; }.bind(this) @@ -117,45 +127,6 @@ GameLib.D3.Scene = function Scene( }.bind(this) ); - this.materials = this.materials.map( - function(apiMaterial) { - if (apiMaterial instanceof GameLib.D3.API.Material) { - var material = new GameLib.D3.Material( - this.graphics, - apiMaterial, - this.imageFactory - ); - - this.idToObject[material.id] = material; - - return material; - } else { - console.warn('apiMaterial not an instance of API.Material'); - throw new Error('apiMaterial not an instance of API.Material'); - } - }.bind(this) - ); - - - this.textures = this.textures.map( - function(apiTexture) { - if (apiTexture instanceof GameLib.D3.API.Texture) { - var texture = new GameLib.D3.Texture( - this.graphics, - apiTexture, - this.imageFactory - ); - - this.idToObject[texture.id] = texture; - - return texture; - } else { - console.warn('apiTexture not an instance of API.Texture'); - throw new Error('apiTexture not an instance of API.Texture'); - } - }.bind(this) - ); - this.idToObject[this.id] = this; this.instance = this.createInstance(); @@ -209,31 +180,15 @@ GameLib.D3.Scene.prototype.toApiScene = function() { } ); - var apiMaterials = this.materials.map( - function(material) { - return material.toApiShape(); - } - ); - - var apiTextures = this.textures.map( - function(texture) { - return texture.toApiTexture(); - } - ); - return new GameLib.D3.API.Scene( this.id, this.name, - this.baseUrl, - this.path, apiMeshes, this.position.toApiVector(), this.quaternion.toApiQuaternion(), this.scale.toApiVector(), this.parentGameId, apiLights, - apiMaterials, - apiTextures, GameLib.Utils.IdOrNull(this.parentEntity) ); }; @@ -270,18 +225,21 @@ GameLib.D3.Scene.FromObjectScene = function( * @param objectScene Object (as it comes from the API) * @param computeNormals * @param onLoaded + * @param imageFactory GameLib.D3.ImageFactory * @constructor */ GameLib.D3.Scene.LoadScene = function( graphics, objectScene, computeNormals, - onLoaded + onLoaded, + imageFactory ) { var scene = GameLib.D3.Scene.FromObjectScene( graphics, objectScene, - computeNormals + computeNormals, + imageFactory ); onLoaded(scene); @@ -293,12 +251,14 @@ GameLib.D3.Scene.LoadScene = function( * @param partialSceneObject Object {path: '', name: ''} * @param apiUrl * @param onLoaded + * @param imageFactory GameLib.D3.ImageFactory */ GameLib.D3.Scene.LoadSceneFromApi = function( graphics, partialSceneObject, apiUrl, - onLoaded + onLoaded, + imageFactory ) { /** @@ -337,7 +297,8 @@ GameLib.D3.Scene.LoadSceneFromApi = function( graphics, objectScene, true, - onLoaded + onLoaded, + imageFactory ); } } diff --git a/src/game-lib-vector2.js b/src/game-lib-vector2.js index 8db932b..da8e7f7 100644 --- a/src/game-lib-vector2.js +++ b/src/game-lib-vector2.js @@ -19,7 +19,7 @@ GameLib.Vector2 = function ( apiVector2 = {}; } - GameLib.Vector2.call( + GameLib.API.Vector2.call( this, apiVector2.x, apiVector2.y diff --git a/src/game-lib-vector3.js b/src/game-lib-vector3.js index 00b9085..9e48636 100644 --- a/src/game-lib-vector3.js +++ b/src/game-lib-vector3.js @@ -19,7 +19,7 @@ GameLib.Vector3 = function ( apiVector3 = {}; } - GameLib.Vector3.call( + GameLib.API.Vector3.call( this, apiVector3.x, apiVector3.y, diff --git a/src/game-lib-z.js b/src/game-lib-z.js index 771958c..d839557 100644 --- a/src/game-lib-z.js +++ b/src/game-lib-z.js @@ -1,3 +1,6 @@ +GameLib.API.System.prototype = Object.create(GameLib.Component.prototype); +GameLib.API.System.prototype.constructor = GameLib.API.System; + if (typeof module !== 'undefined') { module.exports = GameLib; } \ No newline at end of file