/** * 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( this, GameLib.Component.COMPONENT_SCENE, { 'meshes' : [GameLib.D3.Mesh], 'lights' : [GameLib.D3.Light], 'textures' : [GameLib.D3.Texture], 'materials' : [GameLib.D3.Material] }, false, parentEntity ); if (GameLib.Utils.UndefinedOrNull(id)) { id = GameLib.Utils.RandomId(); } this.id = id; if (GameLib.Utils.UndefinedOrNull(name)) { name = 'Scene (' + 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(meshes)) { meshes = []; } this.meshes = meshes; 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(parentGameId)) { parentGameId = null; } this.parentGameId = parentGameId; if (GameLib.Utils.UndefinedOrNull(lights)) { lights = []; } 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.constructor = GameLib.D3.API.Scene; /** * Returns an API scene from an Object scene * @param objectScene * @constructor */ 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(); var apiScale = new GameLib.API.Vector3(1,1,1); if (objectScene.meshes) { apiMeshes = objectScene.meshes.map( function(objectMesh) { return GameLib.D3.API.Mesh.FromObjectMesh(objectMesh); } ) } if (objectScene.lights) { apiLights = objectScene.lights.map( function(objectLight) { return GameLib.D3.API.Light.FromObjectLight(objectLight); } ) } 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); } if (objectScene.quaternion) { apiQuaternion = GameLib.API.Quaternion.FromObjectQuaternion(objectScene.quaternion); } if (objectScene.scale) { apiScale = GameLib.API.Vector3.FromObjectVector(objectScene.scale); } 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 ); };