r3-legacy/src/r3-d3-api-light-spot.js

112 lines
2.3 KiB
JavaScript

/**
* Raw Light API object - should always correspond with the Light Schema
* @constructor
* @param apiLight
* @param position
* @param angle
* @param castShadow
* @param decay
* @param distance
* @param penumbra
* @param power
* @param shadow
* @param target
*/
R3.D3.API.Light.Spot = function(
apiLight,
position,
angle,
castShadow,
decay,
distance,
penumbra,
power,
shadow,
target
) {
if (R3.Utils.UndefinedOrNull(apiLight)) {
apiLight = {
lightType : R3.D3.API.Light.LIGHT_TYPE_SPOT
};
}
if (R3.Utils.UndefinedOrNull(apiLight.lightType)) {
apiLight.lightType = R3.D3.API.Light.LIGHT_TYPE_SPOT;
}
/**
* Light shines from the top
*/
if (R3.Utils.UndefinedOrNull(position)) {
position = new R3.API.Vector3(0,1,0);
}
this.position = position;
/**
* angle should be no more than Math.PI / 2
*/
if (R3.Utils.UndefinedOrNull(angle)) {
angle = Math.PI / 3;
}
this.angle = angle;
if (R3.Utils.UndefinedOrNull(castShadow)) {
castShadow = false;
}
this.castShadow = castShadow;
/**
* In physically correct mode, decay is 2
*/
if (R3.Utils.UndefinedOrNull(decay)) {
decay = 1;
}
this.decay = decay;
if (R3.Utils.UndefinedOrNull(distance)) {
distance = 0;
}
this.distance = distance;
if (R3.Utils.UndefinedOrNull(penumbra)) {
penumbra = 0;
}
this.penumbra = penumbra;
if (R3.Utils.UndefinedOrNull(power)) {
power = Math.PI * 4;
}
this.power = power;
if (R3.Utils.UndefinedOrNull(shadow)) {
shadow = null;
}
this.shadow = shadow;
if (R3.Utils.UndefinedOrNull(target)) {
target = null;
}
this.target = target;
/**
* Update our intensity based on our power
* @type {number}
*/
apiLight.intensity = this.power / Math.PI;
R3.D3.API.Light.call(
this,
apiLight.id,
apiLight.name,
apiLight.lightType,
apiLight.color,
apiLight.intensity,
apiLight.parentScene,
apiLight.parentEntity
);
};
R3.D3.API.Light.Spot.prototype = Object.create(R3.D3.API.Light.prototype);
R3.D3.API.Light.Spot.prototype.constructor = R3.D3.API.Light.Spot;