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

173 lines
4.1 KiB
JavaScript
Raw Normal View History

2016-11-29 12:54:25 +01:00
/**
* 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
2017-01-02 17:05:40 +01:00
* @param parentEntity
2016-11-29 12:54:25 +01:00
* @constructor
*/
GameLib.D3.API.Light = function(
id,
lightType,
name,
color,
intensity,
position,
targetPosition,
quaternion,
rotation,
scale,
distance,
decay,
power,
angle,
2017-01-02 17:05:40 +01:00
penumbra,
parentScene,
2017-01-02 17:05:40 +01:00
parentEntity
2016-11-29 12:54:25 +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(lightType)) {
2016-11-29 12:54:25 +01:00
lightType = GameLib.D3.Light.LIGHT_TYPE_AMBIENT;
}
this.lightType = lightType;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(name)) {
if (this.lightType === GameLib.D3.Light.LIGHT_TYPE_AMBIENT) {
name = 'Ambient ';
}
if (this.lightType === GameLib.D3.Light.LIGHT_TYPE_DIRECTIONAL) {
name = 'Directional ';
}
if (this.lightType === GameLib.D3.Light.LIGHT_TYPE_POINT) {
name = 'Point ';
}
if (this.lightType === GameLib.D3.Light.LIGHT_TYPE_SPOT) {
name = 'Spot ';
}
name += 'Light (' + id + ')';
2016-11-29 12:54:25 +01:00
}
this.name = name;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(color)) {
2017-01-06 16:53:53 +01:00
color = new GameLib.API.Color(1,1,1,1);
2016-11-29 12:54:25 +01:00
}
this.color = color;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(intensity)) {
2016-11-29 12:54:25 +01:00
intensity = 1;
}
this.intensity = intensity;
2017-05-11 17:52:33 +02:00
if (GameLib.Utils.UndefinedOrNull(position)) {
2016-12-15 14:53:39 +01:00
position = new GameLib.API.Vector3(0,10,0);
2016-11-29 12:54:25 +01:00
}
this.position = position;
2017-05-11 17:52:33 +02:00
if (GameLib.Utils.UndefinedOrNull(targetPosition)) {
2016-12-15 14:53:39 +01:00
targetPosition = new GameLib.API.Vector3(0,0,0);
2016-11-29 12:54:25 +01:00
}
this.targetPosition = targetPosition;
2017-05-11 17:52:33 +02:00
if (GameLib.Utils.UndefinedOrNull(quaternion)){
2016-12-15 14:53:39 +01:00
quaternion = new GameLib.API.Quaternion();
2016-11-29 12:54:25 +01:00
}
this.quaternion = quaternion;
2017-05-11 17:52:33 +02:00
if (GameLib.Utils.UndefinedOrNull(rotation)){
2016-12-15 14:53:39 +01:00
rotation = new GameLib.API.Vector3(0,0,0);
2016-11-29 12:54:25 +01:00
}
this.rotation = rotation;
2017-05-11 17:52:33 +02:00
if (GameLib.Utils.UndefinedOrNull(scale)){
2016-12-15 14:53:39 +01:00
scale = new GameLib.API.Vector3(1,1,1);
2016-11-29 12:54:25 +01:00
}
this.scale = scale;
2017-05-11 17:52:33 +02:00
if (GameLib.Utils.UndefinedOrNull(distance)){
2016-11-29 12:54:25 +01:00
distance = 0;
}
this.distance = distance;
2017-05-11 17:52:33 +02:00
if (GameLib.Utils.UndefinedOrNull(decay)){
2016-11-29 12:54:25 +01:00
decay = 1;
}
this.decay = decay;
2017-05-11 17:52:33 +02:00
if (GameLib.Utils.UndefinedOrNull(power)){
2016-11-29 12:54:25 +01:00
power = 4 * Math.PI;
}
this.power = power;
2017-05-11 17:52:33 +02:00
if (GameLib.Utils.UndefinedOrNull(angle)){
2016-11-29 12:54:25 +01:00
angle = Math.PI / 3;
}
this.angle = angle;
2017-05-11 17:52:33 +02:00
if (GameLib.Utils.UndefinedOrNull(penumbra)){
2016-11-29 12:54:25 +01:00
penumbra = 0;
}
this.penumbra = penumbra;
if (GameLib.Utils.UndefinedOrNull(parentScene)){
parentScene = null;
}
this.parentScene = parentScene;
2017-06-16 15:49:53 +02:00
if (GameLib.Utils.UndefinedOrNull(parentEntity)){
parentEntity = null;
}
this.parentEntity = parentEntity;
2017-01-02 17:05:40 +01:00
};
GameLib.D3.API.Light.prototype = Object.create(GameLib.Component.prototype);
2017-01-05 19:34:28 +01:00
GameLib.D3.API.Light.prototype.constructor = GameLib.D3.API.Light;
/**
* Returns an API light from an Object light
* @param objectLight
* @constructor
*/
2017-06-14 14:21:57 +02:00
GameLib.D3.API.Light.FromObject = function(objectLight) {
2017-01-05 19:34:28 +01:00
return new GameLib.D3.API.Light(
objectLight.id,
objectLight.lightType,
objectLight.name,
2017-06-14 14:21:57 +02:00
GameLib.API.Color.FromObject(objectLight.color),
2017-01-05 19:34:28 +01:00
objectLight.intensity,
2017-06-14 14:21:57 +02:00
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),
2017-01-05 19:34:28 +01:00
objectLight.distance,
objectLight.decay,
objectLight.power,
objectLight.angle,
objectLight.penumbra,
objectLight.parentScene,
2017-01-05 19:34:28 +01:00
objectLight.parentEntity
);
};