82 lines
2.4 KiB
JavaScript
82 lines
2.4 KiB
JavaScript
/**
|
|
* R3.D3.Shadow
|
|
*
|
|
* - R3.D3.Shadow components are not intended to be created directly
|
|
*
|
|
* https://threejs.org/docs/#api/en/lights/shadows/SpotLightShadow
|
|
* - "This is used internally by SpotLights for calculating shadows."
|
|
*
|
|
* https://threejs.org/docs/#api/en/lights/shadows/DirectionalLightShadow
|
|
* - "This is not intended to be called directly - it is called internally by DirectionalLight."
|
|
*
|
|
* - For this reason - we create them as normal components - but instead of creating their instances, they get
|
|
* assigned to them through parent objects at create instance time, and the runtime shadow object gets updated
|
|
* accordingly
|
|
*
|
|
* - We also don't create Shadow objects at API level unless they come from the API - this way we know whether or
|
|
* not we need to update the shadow with our information or update our information with the shadow information
|
|
*
|
|
* @param inherited
|
|
*
|
|
* @constructor
|
|
*/
|
|
R3.D3.Shadow = function(
|
|
inherited
|
|
) {
|
|
|
|
if (R3.Utils.UndefinedOrNull(inherited)) {
|
|
throw new Error('R3.D3.Shadow should not be instantiated directly');
|
|
}
|
|
|
|
__UPGRADE_TO_RUNTIME__;
|
|
};
|
|
|
|
R3.D3.Shadow.prototype = Object.create(R3.Component.prototype);
|
|
R3.D3.Shadow.prototype.constructor = R3.D3.Shadow;
|
|
|
|
/**
|
|
* Updates the instance with the current state
|
|
*/
|
|
R3.D3.Shadow.prototype.updateInstance = function(property) {
|
|
|
|
if (property === 'camera') {
|
|
this.instance.camera = this.camera.instance;
|
|
return;
|
|
}
|
|
|
|
if (property === 'bias') {
|
|
this.instance.bias = this.bias;
|
|
return;
|
|
}
|
|
|
|
if (property === 'mapSize') {
|
|
this.instance.mapSize.x = this.mapSize.x;
|
|
this.instance.mapSize.y = this.mapSize.y;
|
|
return;
|
|
}
|
|
|
|
if (property === 'radius') {
|
|
this.instance.radius = this.radius;
|
|
return;
|
|
}
|
|
|
|
__UPDATE_INSTANCE__;
|
|
|
|
};
|
|
|
|
/**
|
|
* Until this can be moved into a more generic way into R3.Component - we do it this way for now
|
|
*/
|
|
R3.D3.Shadow.prototype.updateInstanceAll = function() {
|
|
this.updateInstance('camera');
|
|
this.updateInstance('bias');
|
|
this.updateInstance('mapSize');
|
|
this.updateInstance('radius');
|
|
};
|
|
|
|
R3.D3.Shadow.prototype.updateFromInstanceAll = function() {
|
|
this.updateFromInstance('camera');
|
|
this.updateFromInstance('bias');
|
|
this.updateFromInstance('mapSize');
|
|
this.updateFromInstance('radius');
|
|
}; |