157 lines
3.9 KiB
JavaScript
157 lines
3.9 KiB
JavaScript
/**
|
|
* R3.D3.Light.RectArea
|
|
* @param graphics R3.GraphicsRuntime
|
|
* @param apiRectAreaLight
|
|
* @constructor
|
|
*/
|
|
R3.D3.Light.RectArea = function(
|
|
graphics,
|
|
apiRectAreaLight
|
|
) {
|
|
|
|
this.graphics = graphics;
|
|
this.graphics.isNotThreeThrow();
|
|
|
|
if (R3.Utils.UndefinedOrNull(apiRectAreaLight)) {
|
|
apiRectAreaLight = {
|
|
lightType : R3.D3.API.Light.LIGHT_TYPE_RECT_AREA
|
|
};
|
|
}
|
|
|
|
R3.D3.API.Light.RectArea.call(
|
|
this,
|
|
apiRectAreaLight,
|
|
apiRectAreaLight.position,
|
|
apiRectAreaLight.castShadow,
|
|
apiRectAreaLight.decay,
|
|
apiRectAreaLight.distance,
|
|
apiRectAreaLight.width,
|
|
apiRectAreaLight.height,
|
|
apiRectAreaLight.target
|
|
);
|
|
|
|
this.position = new R3.Vector3(
|
|
this.graphics,
|
|
this.position,
|
|
this
|
|
);
|
|
|
|
R3.D3.Light.call(
|
|
this,
|
|
this.graphics,
|
|
apiRectAreaLight
|
|
);
|
|
|
|
};
|
|
|
|
R3.D3.Light.RectArea.prototype = Object.create(R3.D3.Light.prototype);
|
|
R3.D3.Light.RectArea.prototype.constructor = R3.D3.Light.RectArea;
|
|
|
|
/**
|
|
* Creates a light instance
|
|
* @returns {*}
|
|
*/
|
|
R3.D3.Light.RectArea.prototype.createInstance = function() {
|
|
|
|
this.instance = new THREE.RectAreaLight();
|
|
|
|
this.instance.position.x = this.position.x;
|
|
this.instance.position.y = this.position.y;
|
|
this.instance.position.z = this.position.z;
|
|
|
|
//TODO: not yet implemented
|
|
//this.instance.castShadow = this.castShadow;
|
|
//this.instance.decay = this.decay;
|
|
//this.instance.distance = this.distance;
|
|
|
|
this.instance.width = this.width;
|
|
this.instance.height = this.height;
|
|
|
|
if (this.target && this.target.instance) {
|
|
this.instance.target = this.target.instance;
|
|
|
|
if (this.parentScene && this.parentScene.instance) {
|
|
this.parentScene.addObject(this.target);
|
|
}
|
|
}
|
|
R3.D3.Light.prototype.createInstance.call(this);
|
|
};
|
|
|
|
/**
|
|
* Updates the instance with the current state
|
|
*/
|
|
R3.D3.Light.RectArea.prototype.updateInstance = function(property, oldTarget) {
|
|
|
|
if (property === 'castShadow') {
|
|
console.warn('not yet implemented : castShadow');
|
|
// this.instance.castShadow = this.castShadow;
|
|
return;
|
|
}
|
|
|
|
if (property === 'position') {
|
|
this.instance.position.x = this.position.x;
|
|
this.instance.position.y = this.position.y;
|
|
this.instance.position.z = this.position.z;
|
|
return;
|
|
}
|
|
|
|
if (property === 'decay') {
|
|
console.warn('not yet implemented : decay');
|
|
// this.instance.decay = this.decay;
|
|
return;
|
|
}
|
|
|
|
if (property === 'distance') {
|
|
console.warn('not yet implemented : distance');
|
|
// this.instance.distance = this.distance;
|
|
return;
|
|
}
|
|
|
|
if (property === 'width') {
|
|
this.instance.width = this.width;
|
|
return;
|
|
}
|
|
|
|
if (property === 'height') {
|
|
this.instance.height = this.height;
|
|
return;
|
|
}
|
|
|
|
if (property === 'target') {
|
|
|
|
if (typeof oldTarget === 'undefined') {
|
|
console.warn('oldTarget undefined');
|
|
}
|
|
|
|
if (oldTarget) {
|
|
if (this.parentScene) {
|
|
this.parentScene.removeObject(oldTarget);
|
|
this.parentScene.addObject(this.target);
|
|
}
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
R3.D3.Light.prototype.updateInstance.call(this, property);
|
|
};
|
|
|
|
/**
|
|
* Converts a R3.D3.Light to a R3.D3.API.Light
|
|
* @returns {R3.D3.API.Light}
|
|
*/
|
|
R3.D3.Light.RectArea.prototype.toApiObject = function() {
|
|
|
|
var apiRectAreaLight = R3.D3.Light.prototype.toApiObject.call(this);
|
|
|
|
apiRectAreaLight.position = this.position.toApiObject();
|
|
apiRectAreaLight.castShadow = this.castShadow;
|
|
apiRectAreaLight.decay = this.decay;
|
|
apiRectAreaLight.distance = this.distance;
|
|
apiRectAreaLight.width = this.width;
|
|
apiRectAreaLight.height = this.height;
|
|
apiRectAreaLight.target = R3.Utils.IdOrNull(this.target);
|
|
|
|
return apiRectAreaLight;
|
|
};
|