@openhps/core
Version:
Open Hybrid Positioning System - Core component
63 lines (58 loc) • 1.65 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _Nodes = require("../../nodes/Nodes.js");
var _ChainMap = _interopRequireDefault(require("./ChainMap.js"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const _defaultLights = /*@__PURE__*/new _Nodes.LightsNode();
const _chainKeys = [];
/**
* This renderer module manages the lights nodes which are unique
* per scene and camera combination.
*
* The lights node itself is later configured in the render list
* with the actual lights from the scene.
*
* @private
* @augments ChainMap
*/
class Lighting extends _ChainMap.default {
/**
* Constructs a lighting management component.
*/
constructor() {
super();
}
/**
* Creates a new lights node for the given array of lights.
*
* @param {Array<Light>} lights - The render object.
* @return {LightsNode} The lights node.
*/
createNode(lights = []) {
return new _Nodes.LightsNode().setLights(lights);
}
/**
* Returns a lights node for the given scene and camera.
*
* @param {Scene} scene - The scene.
* @param {Camera} camera - The camera.
* @return {LightsNode} The lights node.
*/
getNode(scene, camera) {
// ignore post-processing
if (scene.isQuadMesh) return _defaultLights;
_chainKeys[0] = scene;
_chainKeys[1] = camera;
let node = this.get(_chainKeys);
if (node === undefined) {
node = this.createNode();
this.set(_chainKeys, node);
}
_chainKeys.length = 0;
return node;
}
}
var _default = exports.default = Lighting;