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

160 lines
3.8 KiB
JavaScript

/**
* Raw Light API object - should always correspond with the Light Schema
* @param id
* @param lightType
* @param name
* @param color
* @param intensity
* @param position
* @param targetPosition
* @param quaternion
* @param rotation
* @param scale
* @param distance
* @param decay
* @param power
* @param angle
* @param penumbra
* @param parentScene
* @param parentEntity
* @constructor
*/
GameLib.D3.API.Light = function(
id,
lightType,
name,
color,
intensity,
position,
targetPosition,
quaternion,
rotation,
scale,
distance,
decay,
power,
angle,
penumbra,
parentScene,
parentEntity
) {
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_LIGHT,
{
'parentScene' : GameLib.D3.Scene
},
parentEntity
);
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
}
this.id = id;
if (GameLib.Utils.UndefinedOrNull(lightType)) {
lightType = GameLib.D3.Light.LIGHT_TYPE_AMBIENT;
}
this.lightType = lightType;
if (GameLib.Utils.UndefinedOrNull(name)) {
name = 'Light (' + id + ')';
}
this.name = name;
if (GameLib.Utils.UndefinedOrNull(color)) {
color = new GameLib.API.Color(1,1,1,1);
}
this.color = color;
if (GameLib.Utils.UndefinedOrNull(intensity)) {
intensity = 1;
}
this.intensity = intensity;
if (GameLib.Utils.UndefinedOrNull(position)) {
position = new GameLib.API.Vector3(0,10,0);
}
this.position = position;
if (GameLib.Utils.UndefinedOrNull(targetPosition)) {
targetPosition = new GameLib.API.Vector3(0,0,0);
}
this.targetPosition = targetPosition;
if (GameLib.Utils.UndefinedOrNull(quaternion)){
quaternion = new GameLib.API.Quaternion();
}
this.quaternion = quaternion;
if (GameLib.Utils.UndefinedOrNull(rotation)){
rotation = new GameLib.API.Vector3(0,0,0);
}
this.rotation = rotation;
if (GameLib.Utils.UndefinedOrNull(scale)){
scale = new GameLib.API.Vector3(1,1,1);
}
this.scale = scale;
if (GameLib.Utils.UndefinedOrNull(distance)){
distance = 0;
}
this.distance = distance;
if (GameLib.Utils.UndefinedOrNull(decay)){
decay = 1;
}
this.decay = decay;
if (GameLib.Utils.UndefinedOrNull(power)){
power = 4 * Math.PI;
}
this.power = power;
if (GameLib.Utils.UndefinedOrNull(angle)){
angle = Math.PI / 3;
}
this.angle = angle;
if (GameLib.Utils.UndefinedOrNull(penumbra)){
penumbra = 0;
}
this.penumbra = penumbra;
if (GameLib.Utils.UndefinedOrNull(parentScene)){
parentScene = null;
}
this.parentScene = parentScene;
};
GameLib.D3.API.Light.prototype = Object.create(GameLib.Component.prototype);
GameLib.D3.API.Light.prototype.constructor = GameLib.D3.API.Light;
/**
* Returns an API light from an Object light
* @param objectLight
* @constructor
*/
GameLib.D3.API.Light.FromObject = function(objectLight) {
return new GameLib.D3.API.Light(
objectLight.id,
objectLight.lightType,
objectLight.name,
GameLib.API.Color.FromObject(objectLight.color),
objectLight.intensity,
GameLib.API.Vector3.FromObject(objectLight.position),
GameLib.API.Vector3.FromObject(objectLight.targetPosition),
GameLib.API.Quaternion.FromObject(objectLight.quaternion),
GameLib.API.Vector3.FromObject(objectLight.rotation),
GameLib.API.Vector3.FromObject(objectLight.scale),
objectLight.distance,
objectLight.decay,
objectLight.power,
objectLight.angle,
objectLight.penumbra,
objectLight.parentScene,
objectLight.parentEntity
);
};