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]
|
2016-12-15 14:53:39 +01:00
|
|
|
* @param position GameLib.API.Vector3
|
2016-12-15 15:28:00 +01:00
|
|
|
* @param quaternion GameLib.API.Quaternion
|
2016-12-15 14:53:39 +01:00
|
|
|
* @param scale GameLib.API.Vector3
|
2017-01-10 17:04:30 +01:00
|
|
|
* @param parentGameId
|
|
|
|
* @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-06-01 16:58:22 +02:00
|
|
|
* @param activeCamera [GameLib.D3.Camera]
|
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,
|
|
|
|
position,
|
2016-12-15 15:28:00 +01:00
|
|
|
quaternion,
|
2016-11-29 12:54:25 +01:00
|
|
|
scale,
|
2017-01-10 17:04:30 +01:00
|
|
|
parentGameId,
|
2016-11-29 12:54:25 +01:00
|
|
|
lights,
|
2017-01-31 11:37:55 +01:00
|
|
|
textures,
|
|
|
|
materials,
|
2017-06-09 16:03:05 +02:00
|
|
|
images,
|
2017-06-01 16:58:22 +02:00
|
|
|
activeCamera,
|
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
|
|
|
GameLib.Component.call(
|
|
|
|
this,
|
|
|
|
GameLib.Component.COMPONENT_SCENE,
|
|
|
|
{
|
|
|
|
'meshes' : [GameLib.D3.Mesh],
|
2017-01-20 13:40:27 +01:00
|
|
|
'lights' : [GameLib.D3.Light],
|
2017-01-31 11:37:55 +01:00
|
|
|
'textures' : [GameLib.D3.Texture],
|
2017-06-01 16:58:22 +02:00
|
|
|
'materials' : [GameLib.D3.Material],
|
2017-06-09 16:03:05 +02:00
|
|
|
'images' : [GameLib.D3.Image],
|
2017-06-01 16:58:22 +02:00
|
|
|
'activeCamera' : GameLib.D3.Camera
|
2017-01-10 17:04:30 +01:00
|
|
|
},
|
|
|
|
parentEntity
|
|
|
|
);
|
|
|
|
|
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(position)) {
|
|
|
|
position = new GameLib.API.Vector3();
|
2016-11-29 12:54:25 +01:00
|
|
|
}
|
|
|
|
this.position = position;
|
|
|
|
|
2016-12-15 15:28:00 +01:00
|
|
|
if (GameLib.Utils.UndefinedOrNull(quaternion)) {
|
|
|
|
quaternion = new GameLib.API.Quaternion();
|
|
|
|
}
|
|
|
|
this.quaternion = quaternion;
|
|
|
|
|
2016-12-15 14:53:39 +01:00
|
|
|
if (GameLib.Utils.UndefinedOrNull(scale)) {
|
|
|
|
scale = new GameLib.API.Vector3(1,1,1);
|
2016-11-29 12:54:25 +01:00
|
|
|
}
|
|
|
|
this.scale = scale;
|
|
|
|
|
2017-01-10 17:04:30 +01:00
|
|
|
if (GameLib.Utils.UndefinedOrNull(parentGameId)) {
|
|
|
|
parentGameId = null;
|
2016-11-29 12:54:25 +01:00
|
|
|
}
|
2017-01-10 17:04:30 +01:00
|
|
|
this.parentGameId = parentGameId;
|
2016-11-29 12:54:25 +01:00
|
|
|
|
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-01 16:58:22 +02:00
|
|
|
if (GameLib.Utils.UndefinedOrNull(activeCamera)) {
|
|
|
|
activeCamera = null;
|
|
|
|
}
|
|
|
|
this.activeCamera = activeCamera;
|
|
|
|
|
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-08 18:17:03 +02:00
|
|
|
GameLib.D3.API.Scene.FromObjectScene = 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
|
|
|
var apiPosition = new GameLib.API.Vector3();
|
|
|
|
var apiQuaternion = new GameLib.API.Quaternion();
|
|
|
|
var apiScale = new GameLib.API.Vector3(1,1,1);
|
|
|
|
|
2017-06-01 16:58:22 +02:00
|
|
|
var apiActiveCamera = null;
|
|
|
|
|
2017-01-10 17:04:30 +01:00
|
|
|
if (objectScene.meshes) {
|
|
|
|
apiMeshes = objectScene.meshes.map(
|
|
|
|
function(objectMesh) {
|
|
|
|
return GameLib.D3.API.Mesh.FromObjectMesh(objectMesh);
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
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) {
|
|
|
|
return GameLib.D3.API.Light.FromObjectLight(objectLight);
|
|
|
|
}
|
|
|
|
)
|
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) {
|
|
|
|
return GameLib.D3.API.Texture.FromObjectTexture(objectTexture)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
if (objectScene.materials) {
|
|
|
|
apiMaterials = objectScene.materials.map(
|
|
|
|
function(objectMaterial) {
|
|
|
|
return GameLib.D3.API.Material.FromObjectMaterial(objectMaterial)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2017-06-09 16:03:05 +02:00
|
|
|
if (objectScene.images) {
|
|
|
|
apiImages = objectScene.images.map(
|
|
|
|
function(objectImage) {
|
|
|
|
return GameLib.D3.API.Image.FromObject(objectImage)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2017-01-10 17:04:30 +01:00
|
|
|
if (objectScene.position) {
|
|
|
|
apiPosition = GameLib.API.Vector3.FromObjectVector(objectScene.position);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (objectScene.quaternion) {
|
|
|
|
apiQuaternion = GameLib.API.Quaternion.FromObjectQuaternion(objectScene.quaternion);
|
2017-01-09 15:20:48 +01:00
|
|
|
}
|
|
|
|
|
2017-01-10 17:04:30 +01:00
|
|
|
if (objectScene.scale) {
|
|
|
|
apiScale = GameLib.API.Vector3.FromObjectVector(objectScene.scale);
|
2017-01-09 15:20:48 +01:00
|
|
|
}
|
|
|
|
|
2017-06-01 16:58:22 +02:00
|
|
|
if (objectScene.activeCamera) {
|
|
|
|
apiActiveCamera = objectScene.activeCamera;
|
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
apiPosition,
|
|
|
|
apiQuaternion,
|
|
|
|
apiScale,
|
|
|
|
objectScene.parentGameId,
|
|
|
|
apiLights,
|
2017-01-31 11:37:55 +01:00
|
|
|
apiTextures,
|
|
|
|
apiMaterials,
|
2017-06-09 16:03:05 +02:00
|
|
|
apiImages,
|
2017-06-01 16:58:22 +02:00
|
|
|
apiActiveCamera,
|
2017-01-10 17:04:30 +01:00
|
|
|
objectScene.parentEntity
|
2017-01-05 19:34:28 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
};
|