154 lines
3.7 KiB
JavaScript
154 lines
3.7 KiB
JavaScript
/**
|
|
* Raw Scene API object - should always correspond with the Scene Schema
|
|
* @param id String
|
|
* @param name String
|
|
* @param meshes [GameLib.D3.API.Mesh]
|
|
* @param lights [GameLib.D3.API.Light]
|
|
* @param textures [GameLib.D3.API.Texture]
|
|
* @param materials [GameLib.D3.API.Material]
|
|
* @param images
|
|
* @param parentEntity
|
|
* @constructor
|
|
*/
|
|
GameLib.D3.API.Scene = function(
|
|
id,
|
|
name,
|
|
meshes,
|
|
lights,
|
|
textures,
|
|
materials,
|
|
images,
|
|
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(lights)) {
|
|
lights = [];
|
|
}
|
|
this.lights = lights;
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(textures)) {
|
|
textures = [];
|
|
}
|
|
this.textures = textures;
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(materials)) {
|
|
materials = [];
|
|
}
|
|
this.materials = materials;
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(images)) {
|
|
images = [];
|
|
}
|
|
this.images = images;
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
|
|
parentEntity = null;
|
|
}
|
|
this.parentEntity = parentEntity;
|
|
|
|
};
|
|
|
|
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.FromObject = function(objectScene) {
|
|
|
|
var apiMeshes = [];
|
|
var apiLights = [];
|
|
var apiTextures = [];
|
|
var apiMaterials = [];
|
|
var apiImages = [];
|
|
|
|
if (objectScene.meshes) {
|
|
apiMeshes = objectScene.meshes.map(
|
|
function(objectMesh) {
|
|
if (objectMesh instanceof Object){
|
|
return GameLib.D3.API.Mesh.FromObject(objectMesh);
|
|
} else {
|
|
return objectMesh;
|
|
}
|
|
}
|
|
)
|
|
}
|
|
|
|
if (objectScene.lights) {
|
|
apiLights = objectScene.lights.map(
|
|
function(objectLight) {
|
|
if (objectLight instanceof Object) {
|
|
return GameLib.D3.API.Light.FromObject(objectLight);
|
|
} else {
|
|
return objectLight;
|
|
}
|
|
}
|
|
)
|
|
}
|
|
|
|
if (objectScene.textures) {
|
|
apiTextures = objectScene.textures.map(
|
|
function(objectTexture) {
|
|
if (objectTexture instanceof Object) {
|
|
return GameLib.D3.API.Texture.FromObject(objectTexture)
|
|
} else {
|
|
return objectTexture;
|
|
}
|
|
}
|
|
)
|
|
}
|
|
|
|
if (objectScene.materials) {
|
|
apiMaterials = objectScene.materials.map(
|
|
function(objectMaterial) {
|
|
if (objectMaterial instanceof Object) {
|
|
return GameLib.D3.API.Material.FromObject(objectMaterial)
|
|
} else {
|
|
return objectMaterial;
|
|
}
|
|
}
|
|
)
|
|
}
|
|
|
|
if (objectScene.images) {
|
|
apiImages = objectScene.images.map(
|
|
function(objectImage) {
|
|
if (objectImage instanceof Object) {
|
|
return GameLib.D3.API.Image.FromObject(objectImage)
|
|
} else {
|
|
return objectImage;
|
|
}
|
|
}
|
|
)
|
|
}
|
|
|
|
return new GameLib.D3.API.Scene(
|
|
objectScene.id,
|
|
objectScene.name,
|
|
apiMeshes,
|
|
apiLights,
|
|
apiTextures,
|
|
apiMaterials,
|
|
apiImages,
|
|
objectScene.parentEntity
|
|
);
|
|
|
|
};
|