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
|
2017-06-10 10:04:29 +02:00
|
|
|
* @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,
|
2017-06-10 10:04:29 +02:00
|
|
|
parentScene,
|
2017-01-02 17:05:40 +01:00
|
|
|
parentEntity
|
2016-11-29 12:54:25 +01:00
|
|
|
) {
|
2017-01-02 17:05:40 +01:00
|
|
|
GameLib.Component.call(
|
|
|
|
this,
|
|
|
|
GameLib.Component.COMPONENT_LIGHT,
|
2017-06-10 10:04:29 +02:00
|
|
|
{
|
|
|
|
'parentScene' : GameLib.D3.Scene
|
|
|
|
},
|
2017-01-02 17:05:40 +01:00
|
|
|
null,
|
|
|
|
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(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)) {
|
2016-11-29 12:54:25 +01:00
|
|
|
name = 'Light (' + lightType + ')';
|
|
|
|
}
|
|
|
|
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;
|
2017-06-10 10:04:29 +02:00
|
|
|
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(parentScene)){
|
|
|
|
parentScene = null;
|
|
|
|
}
|
|
|
|
this.parentScene = parentScene;
|
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
|
|
|
|
*/
|
|
|
|
GameLib.D3.API.Light.FromObjectLight = function(objectLight) {
|
|
|
|
return new GameLib.D3.API.Light(
|
|
|
|
objectLight.id,
|
|
|
|
objectLight.lightType,
|
|
|
|
objectLight.name,
|
2017-01-06 16:53:53 +01:00
|
|
|
GameLib.API.Color.FromObjectColor(objectLight.color),
|
2017-01-05 19:34:28 +01:00
|
|
|
objectLight.intensity,
|
|
|
|
GameLib.API.Vector3.FromObjectVector(objectLight.position),
|
|
|
|
GameLib.API.Vector3.FromObjectVector(objectLight.targetPosition),
|
|
|
|
GameLib.API.Quaternion.FromObjectQuaternion(objectLight.quaternion),
|
|
|
|
GameLib.API.Vector3.FromObjectVector(objectLight.rotation),
|
|
|
|
GameLib.API.Vector3.FromObjectVector(objectLight.scale),
|
|
|
|
objectLight.distance,
|
|
|
|
objectLight.decay,
|
|
|
|
objectLight.power,
|
|
|
|
objectLight.angle,
|
|
|
|
objectLight.penumbra,
|
2017-06-10 10:04:29 +02:00
|
|
|
objectLight.parentScene,
|
2017-01-05 19:34:28 +01:00
|
|
|
objectLight.parentEntity
|
|
|
|
);
|
|
|
|
};
|