r3-legacy/src/game-lib-d3-api-scene.js

154 lines
3.7 KiB
JavaScript
Raw Normal View History

2016-11-29 12:54:25 +01:00
/**
* Raw Scene API object - should always correspond with the Scene Schema
* @param id String
* @param name String
2017-01-10 17:04:30 +01:00
* @param meshes [GameLib.D3.API.Mesh]
* @param lights [GameLib.D3.API.Light]
2017-01-31 15:23:38 +01:00
* @param textures [GameLib.D3.API.Texture]
* @param materials [GameLib.D3.API.Material]
2017-06-09 16:03:05 +02:00
* @param images
2017-01-10 17:04:30 +01:00
* @param parentEntity
2016-11-29 12:54:25 +01:00
* @constructor
*/
GameLib.D3.API.Scene = function(
id,
name,
meshes,
lights,
2017-01-31 11:37:55 +01:00
textures,
materials,
2017-06-09 16:03:05 +02:00
images,
2017-01-10 17:04:30 +01:00
parentEntity
2016-11-29 12:54:25 +01:00
) {
2017-01-10 17:04:30 +01:00
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
2016-11-29 12:54:25 +01:00
}
this.id = id;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(name)) {
2017-01-10 17:04:30 +01:00
name = 'Scene (' + this.id + ')';
2016-11-29 12:54:25 +01:00
}
this.name = name;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(meshes)) {
2016-11-29 12:54:25 +01:00
meshes = [];
}
this.meshes = meshes;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(lights)) {
2016-11-29 12:54:25 +01:00
lights = [];
}
this.lights = lights;
2017-01-31 11:37:55 +01:00
if (GameLib.Utils.UndefinedOrNull(textures)) {
textures = [];
}
this.textures = textures;
if (GameLib.Utils.UndefinedOrNull(materials)) {
materials = [];
}
this.materials = materials;
2017-06-09 16:03:05 +02:00
if (GameLib.Utils.UndefinedOrNull(images)) {
images = [];
}
this.images = images;
2017-06-16 15:49:53 +02:00
if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
parentEntity = null;
}
this.parentEntity = parentEntity;
2016-11-29 12:54:25 +01:00
};
2017-01-05 19:34:28 +01:00
2017-01-17 17:16:10 +01:00
GameLib.D3.API.Scene.prototype = Object.create(GameLib.Component.prototype);
2017-01-10 17:04:30 +01:00
GameLib.D3.API.Scene.prototype.constructor = GameLib.D3.API.Scene;
2017-01-05 19:34:28 +01:00
/**
* Returns an API scene from an Object scene
* @param objectScene
* @constructor
*/
2017-06-14 14:21:57 +02:00
GameLib.D3.API.Scene.FromObject = function(objectScene) {
2017-01-05 19:34:28 +01:00
2017-01-10 17:04:30 +01:00
var apiMeshes = [];
var apiLights = [];
2017-01-31 11:37:55 +01:00
var apiTextures = [];
var apiMaterials = [];
2017-06-09 16:03:05 +02:00
var apiImages = [];
2017-01-05 19:34:28 +01:00
2017-01-10 17:04:30 +01:00
if (objectScene.meshes) {
apiMeshes = objectScene.meshes.map(
function(objectMesh) {
if (objectMesh instanceof Object){
return GameLib.D3.API.Mesh.FromObject(objectMesh);
} else {
return objectMesh;
}
2017-01-10 17:04:30 +01:00
}
)
}
2017-01-06 16:53:53 +01:00
2017-01-10 17:04:30 +01:00
if (objectScene.lights) {
apiLights = objectScene.lights.map(
function(objectLight) {
if (objectLight instanceof Object) {
return GameLib.D3.API.Light.FromObject(objectLight);
} else {
return objectLight;
}
2017-01-10 17:04:30 +01:00
}
)
2017-01-05 19:34:28 +01:00
}
2017-01-31 11:37:55 +01:00
if (objectScene.textures) {
apiTextures = objectScene.textures.map(
function(objectTexture) {
if (objectTexture instanceof Object) {
return GameLib.D3.API.Texture.FromObject(objectTexture)
} else {
return objectTexture;
}
2017-01-31 11:37:55 +01:00
}
)
}
if (objectScene.materials) {
apiMaterials = objectScene.materials.map(
function(objectMaterial) {
if (objectMaterial instanceof Object) {
return GameLib.D3.API.Material.FromObject(objectMaterial)
} else {
return objectMaterial;
}
2017-01-31 11:37:55 +01:00
}
)
}
2017-06-09 16:03:05 +02:00
if (objectScene.images) {
apiImages = objectScene.images.map(
function(objectImage) {
if (objectImage instanceof Object) {
return GameLib.D3.API.Image.FromObject(objectImage)
} else {
return objectImage;
}
2017-06-09 16:03:05 +02:00
}
)
}
2017-01-05 19:34:28 +01:00
return new GameLib.D3.API.Scene(
objectScene.id,
objectScene.name,
2017-01-10 17:04:30 +01:00
apiMeshes,
apiLights,
2017-01-31 11:37:55 +01:00
apiTextures,
apiMaterials,
2017-06-09 16:03:05 +02:00
apiImages,
2017-01-10 17:04:30 +01:00
objectScene.parentEntity
2017-01-05 19:34:28 +01:00
);
};