/** * Raw Scene API object - should always correspond with the Scene Schema * @param id String * @param name 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 parentEntity * @constructor */ GameLib.D3.API.Scene = function( id, name, meshes, position, quaternion, scale, parentGameId, lights, textures, materials, 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], 'imageFactory' : GameLib.D3.ImageFactory }, 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(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(textures)) { textures = []; } this.textures = textures; if (GameLib.Utils.UndefinedOrNull(materials)) { materials = []; } this.materials = materials; }; GameLib.D3.API.Scene.prototype = Object.create(GameLib.Component.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 apiTextures = []; var apiMaterials = []; 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, apiMeshes, apiPosition, apiQuaternion, apiScale, objectScene.parentGameId, apiLights, apiTextures, apiMaterials, objectScene.parentEntity ); };