src/viewer/scene/PerformanceModel/lib/layers/pointsInstancing/PointsInstancingRenderers.js
import {PointsInstancingColorRenderer} from "./renderers/PointsInstancingColorRenderer.js";
import {PointsInstancingSilhouetteRenderer} from "./renderers/PointsInstancingSilhouetteRenderer.js";
import {PointsInstancingPickMeshRenderer} from "./renderers/PointsInstancingPickMeshRenderer.js";
import {PointsInstancingPickDepthRenderer} from "./renderers/PointsInstancingPickDepthRenderer.js";
import {PointsInstancingOcclusionRenderer} from "./renderers/PointsInstancingOcclusionRenderer.js";
import {PointsInstancingDepthRenderer} from "./renderers/PointsInstancingDepthRenderer.js";
import {PointsInstancingShadowRenderer} from "./renderers/PointsInstancingShadowRenderer.js";
/**
* @private
*/
class PointsInstancingRenderers {
constructor(scene) {
this._scene = scene;
}
_compile() {
if (this._colorRenderer && (!this._colorRenderer.getValid())) {
this._colorRenderer.destroy();
this._colorRenderer = null;
}
if (this._depthRenderer && (!this._depthRenderer.getValid())) {
this._depthRenderer.destroy();
this._depthRenderer = null;
}
if (this._silhouetteRenderer && (!this._silhouetteRenderer.getValid())) {
this._silhouetteRenderer.destroy();
this._silhouetteRenderer = null;
}
if (this._pickMeshRenderer && (!this._pickMeshRenderer.getValid())) {
this._pickMeshRenderer.destroy();
this._pickMeshRenderer = null;
}
if (this._pickDepthRenderer && (!this._pickDepthRenderer.getValid())) {
this._pickDepthRenderer.destroy();
this._pickDepthRenderer = null;
}
if (this._occlusionRenderer && this._occlusionRenderer.getValid() === false) {
this._occlusionRenderer.destroy();
this._occlusionRenderer = null;
}
if (this._shadowRenderer && (!this._shadowRenderer.getValid())) {
this._shadowRenderer.destroy();
this._shadowRenderer = null;
}
}
get colorRenderer() {
if (!this._colorRenderer) {
this._colorRenderer = new PointsInstancingColorRenderer(this._scene, false);
}
return this._colorRenderer;
}
get silhouetteRenderer() {
if (!this._silhouetteRenderer) {
this._silhouetteRenderer = new PointsInstancingSilhouetteRenderer(this._scene);
}
return this._silhouetteRenderer;
}
get depthRenderer() {
if (!this._depthRenderer) {
this._depthRenderer = new PointsInstancingDepthRenderer(this._scene);
}
return this._depthRenderer;
}
get pickMeshRenderer() {
if (!this._pickMeshRenderer) {
this._pickMeshRenderer = new PointsInstancingPickMeshRenderer(this._scene);
}
return this._pickMeshRenderer;
}
get pickDepthRenderer() {
if (!this._pickDepthRenderer) {
this._pickDepthRenderer = new PointsInstancingPickDepthRenderer(this._scene);
}
return this._pickDepthRenderer;
}
get occlusionRenderer() {
if (!this._occlusionRenderer) {
this._occlusionRenderer = new PointsInstancingOcclusionRenderer(this._scene);
}
return this._occlusionRenderer;
}
get shadowRenderer() {
if (!this._shadowRenderer) {
this._shadowRenderer = new PointsInstancingShadowRenderer(this._scene);
}
return this._shadowRenderer;
}
_destroy() {
if (this._colorRenderer) {
this._colorRenderer.destroy();
}
if (this._depthRenderer) {
this._depthRenderer.destroy();
}
if (this._silhouetteRenderer) {
this._silhouetteRenderer.destroy();
}
if (this._pickMeshRenderer) {
this._pickMeshRenderer.destroy();
}
if (this._pickDepthRenderer) {
this._pickDepthRenderer.destroy();
}
if (this._occlusionRenderer) {
this._occlusionRenderer.destroy();
}
if (this._shadowRenderer) {
this._shadowRenderer.destroy();
}
}
}
const cachedRenderers = {};
/**
* @private
*/
function getPointsInstancingRenderers(scene) {
const sceneId = scene.id;
let instancingRenderers = cachedRenderers[sceneId];
if (!instancingRenderers) {
instancingRenderers = new PointsInstancingRenderers(scene);
cachedRenderers[sceneId] = instancingRenderers;
instancingRenderers._compile();
scene.on("compile", () => {
instancingRenderers._compile();
});
scene.on("destroyed", () => {
delete cachedRenderers[sceneId];
instancingRenderers._destroy();
});
}
return instancingRenderers;
}
export {getPointsInstancingRenderers};