@babylonjs/viewer
Version:
The Babylon Viewer aims to simplify a specific but common Babylon.js use case: loading, viewing, and interacting with a 3D model.
125 lines (122 loc) • 4.76 kB
JavaScript
import { aZ as SceneComponentConstants } from './index-MZPybX0H.esm.js';
/** This file must only contain pure code and pure imports */
/**
* Defines the shadow generator component responsible to manage any shadow generators
* in a given scene.
*/
class ShadowGeneratorSceneComponent {
/**
* Creates a new instance of the component for the given scene
* @param scene Defines the scene to register the component in
*/
constructor(scene) {
/**
* The component name helpful to identify the component in the list of scene components.
*/
this.name = SceneComponentConstants.NAME_SHADOWGENERATOR;
this.scene = scene;
}
/**
* Registers the component in a given scene
*/
register() {
this.scene._gatherRenderTargetsStage.registerStep(SceneComponentConstants.STEP_GATHERRENDERTARGETS_SHADOWGENERATOR, this, this._gatherRenderTargets);
}
/**
* Rebuilds the elements related to this component in case of
* context lost for instance.
*/
rebuild() {
// Nothing To Do Here.
}
/**
* Serializes the component data to the specified json object
* @param serializationObject The object to serialize to
*/
serialize(serializationObject) {
// Shadows
serializationObject.shadowGenerators = [];
const lights = this.scene.lights;
for (const light of lights) {
if (light.doNotSerialize) {
continue;
}
const shadowGenerators = light.getShadowGenerators();
if (shadowGenerators) {
const iterator = shadowGenerators.values();
for (let key = iterator.next(); key.done !== true; key = iterator.next()) {
const shadowGenerator = key.value;
if (shadowGenerator.doNotSerialize) {
continue;
}
serializationObject.shadowGenerators.push(shadowGenerator.serialize());
}
}
}
}
/**
* Adds all the elements from the container to the scene
* @param container the container holding the elements
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
addFromContainer(container) {
// Nothing To Do Here. (directly attached to a light)
}
/**
* Removes all the elements in the container from the scene
* @param container contains the elements to remove
* @param dispose if the removed element should be disposed (default: false)
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
removeFromContainer(container, dispose) {
// Nothing To Do Here. (directly attached to a light)
}
/**
* Rebuilds the elements related to this component in case of
* context lost for instance.
*/
dispose() {
// Nothing To Do Here.
}
_gatherRenderTargets(renderTargets) {
// Shadows
const scene = this.scene;
if (this.scene.shadowsEnabled) {
for (let lightIndex = 0; lightIndex < scene.lights.length; lightIndex++) {
const light = scene.lights[lightIndex];
const shadowGenerators = light.getShadowGenerators();
if (light.isEnabled() && light.shadowEnabled && shadowGenerators) {
const iterator = shadowGenerators.values();
for (let key = iterator.next(); key.done !== true; key = iterator.next()) {
const shadowGenerator = key.value;
const shadowMap = shadowGenerator.getShadowMap();
if (scene.textures.indexOf(shadowMap) !== -1) {
renderTargets.push(shadowMap);
}
}
}
}
}
}
}
let _Registered = false;
/**
* Register side effects for shadowGeneratorSceneComponent.
* Safe to call multiple times; only the first call has an effect.
* @param shadowGeneratorClass The class of the shadow generator to register the component for
*/
function RegisterShadowGeneratorSceneComponent(shadowGeneratorClass) {
if (_Registered) {
return;
}
_Registered = true;
shadowGeneratorClass._SceneComponentInitialization = (scene) => {
let component = scene._getComponent(SceneComponentConstants.NAME_SHADOWGENERATOR);
if (!component) {
component = new ShadowGeneratorSceneComponent(scene);
scene._addComponent(component);
}
};
}
export { RegisterShadowGeneratorSceneComponent, ShadowGeneratorSceneComponent };
//# sourceMappingURL=shadowGeneratorSceneComponent-COvjeyOV.esm.js.map