Let's cover these changes in detail. We have created a new JavaScript module, Lights.js, that has two objects:
- Light: Aggregates light properties (position, diffuse, specular, and so on) in a single entity.
- LightsManager: Contains the lights in our scene. This allows us to retrieve each light by index or name.
LightsManager also contains the getArray method to flatten the arrays of properties by type:
getArray(type) {
return this.list.reduce((result, light) => {
result = result.concat(light[type]);
return result;
}, []);
}
This will be useful when we use uniform arrays later on.