/** * Light Superset - The apiLight properties get moved into the Light object itself, and then the instance is created * @param id * @param graphics GameLib.D3.Graphics * @param apiLight GameLib.D3.Light.API * @constructor */ GameLib.D3.Light = function( id, graphics, apiLight ) { for (var property in apiLight) { if (apiLight.hasOwnProperty(property)) { this[property] = apiLight[property]; } } this.graphics = graphics; this.graphics.isNotThreeThrow(); this.instance = this.createInstance(); }; /** * 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 * @constructor */ GameLib.D3.Light.API = function( id, lightType, name, color, intensity, position, targetPosition, quaternion, rotation, scale, distance, decay, power, angle, penumbra ) { if (GameLib.D3.Utils.UndefinedOrNull(id)) { id = GameLib.D3.Tools.RandomId(); } this.id = id; if (GameLib.D3.Utils.UndefinedOrNull(lightType)) { lightType = GameLib.D3.Light.LIGHT_TYPE_AMBIENT; } this.lightType = lightType; if (GameLib.D3.Utils.UndefinedOrNull(name)) { name = 'Light (' + lightType + ')'; } this.name = name; this.color = color; this.intensity = intensity; if (typeof position == 'undefined') { position = new GameLib.D3.Vector3(0,0,0); } this.position = position; if (typeof targetPosition == 'undefined') { targetPosition = new GameLib.D3.Vector3(0,0,0); } this.targetPosition = targetPosition; if (typeof quaternion == 'undefined'){ quaternion = new GameLib.D3.Vector4(); } this.quaternion = quaternion; if (typeof rotation == 'undefined'){ rotation = new GameLib.D3.Vector3(0,0,0); } this.rotation = rotation; if (typeof scale == 'undefined'){ scale = new GameLib.D3.Vector3(1,1,1); } this.scale = scale; if (typeof distance == 'undefined'){ distance = 0; } this.distance = distance; if (typeof decay == 'undefined'){ decay = 1; } this.decay = decay; if (typeof power == 'undefined'){ power = 4 * Math.PI; } this.power = power; if (typeof angle == 'undefined'){ angle = Math.PI / 3; } this.angle = angle; if (typeof penumbra == 'undefined'){ penumbra = 0; } this.penumbra = penumbra; }; /** * Light Types * @type {number} */ GameLib.D3.Light.LIGHT_TYPE_AMBIENT = 0x1; GameLib.D3.Light.LIGHT_TYPE_DIRECTIONAL = 0x2; GameLib.D3.Light.LIGHT_TYPE_POINT = 0x3; GameLib.D3.Light.LIGHT_TYPE_SPOT = 0x4; /** * Creates a light instance * @returns {*} */ GameLib.D3.Light.createInstance = function() { var instance = null; if (this.lightType == GameLib.D3.Light.LIGHT_TYPE_AMBIENT) { instance = new this.graphics.instance.AmbientLight(this.color, this.intensity); } if (this.lightType == GameLib.D3.Light.LIGHT_TYPE_DIRECTIONAL) { instance = new this.graphics.instance.DirectionalLight(this.color, this.intensity); } if (this.lightType == GameLib.D3.Light.LIGHT_TYPE_POINT) { instance = new this.graphics.instance.PointLight(this.color, this.intensity); instance.distance = this.distance; instance.decay = this.decay; } if (this.lightType == GameLib.D3.Light.LIGHT_TYPE_SPOT ) { instance = new this.graphics.instance.SpotLight(this.color, this.intensity); instance.distance = this.distance; instance.angle = this.angle; instance.penumbra = this.penumbra; instance.decay = this.decay; } instance.gameLibObject = this; instance.position.x = this.position.x; instance.position.y = this.position.y; instance.position.z = this.position.z; instance.rotation.x = this.rotation.x; instance.rotation.y = this.rotation.y; instance.rotation.z = this.rotation.z; return instance; };