From a64b81ad4dcba5a8d03cfa1ba3158223ac104866 Mon Sep 17 00:00:00 2001 From: gchoqueux Date: Mon, 13 Dec 2021 13:58:36 +0100 Subject: [PATCH] feature(ElevationLayer): add visible property. --- examples/js/GUI/GuiTools.js | 14 ++++++++++--- src/Layer/ElevationLayer.js | 4 ++++ src/Process/LayeredMaterialNodeProcessing.js | 3 ++- src/Renderer/RasterTile.js | 21 ++++++++++++++++--- .../Shader/Chunk/elevation_pars_vertex.glsl | 1 + .../Shader/Chunk/elevation_vertex.glsl | 2 +- 6 files changed, 37 insertions(+), 8 deletions(-) diff --git a/examples/js/GUI/GuiTools.js b/examples/js/GUI/GuiTools.js index a925b40672..916ddc27e5 100644 --- a/examples/js/GUI/GuiTools.js +++ b/examples/js/GUI/GuiTools.js @@ -98,13 +98,21 @@ GuiTools.prototype.addElevationLayerGUI = function addElevationLayerGUI(layer) { if (this.elevationGui.hasFolder(layer.id)) { return; } this.elevationGui.show(); var folder = this.elevationGui.addFolder(layer.id); - folder.add({ frozen: layer.frozen }, 'frozen').onChange(function refreshFrozenGui(value) { - layer.frozen = value; - }); + folder.add({ visible: layer.visible }, 'visible').onChange((function updateVisibility(value) { + layer.visible = value; + this.view.notifyChange(layer); + this.view.notifyChange(this.view.camera); + if (this.view.controls && this.view.controls.update) { + this.view.controls.update(); + } + }).bind(this)); folder.add({ scale: layer.scale }, 'scale').min(1.0).max(20000.0).onChange((function updateScale(value) { layer.scale = value; this.view.notifyChange(layer); }).bind(this)); + folder.add({ frozen: layer.frozen }, 'frozen').onChange(function refreshFrozenGui(value) { + layer.frozen = value; + }); }; GuiTools.prototype.addImageryLayersGUI = function addImageryLayersGUI(layers) { diff --git a/src/Layer/ElevationLayer.js b/src/Layer/ElevationLayer.js index 72f14c098a..668937dff6 100644 --- a/src/Layer/ElevationLayer.js +++ b/src/Layer/ElevationLayer.js @@ -55,6 +55,7 @@ class ElevationLayer extends RasterLayer { constructor(id, config = {}) { super(id, config); this.isElevationLayer = true; + this.defineLayerProperty('visible', true); this.defineLayerProperty('scale', this.scale || 1.0); } @@ -79,8 +80,11 @@ class ElevationLayer extends RasterLayer { // listen scaling elevation updating this.addEventListener('scale-property-changed', updateBBox); + // listen visibility elevation updating + this.addEventListener('visible-property-changed', updateBBox); // remove scaling elevation updating if node is removed node.addEventListener('dispose', () => { + this.removeEventListener('visible-property-changed', updateBBox); this.removeEventListener('scale-property-changed', updateBBox); }); diff --git a/src/Process/LayeredMaterialNodeProcessing.js b/src/Process/LayeredMaterialNodeProcessing.js index 1b56088fa3..c7aadd0f54 100644 --- a/src/Process/LayeredMaterialNodeProcessing.js +++ b/src/Process/LayeredMaterialNodeProcessing.js @@ -192,7 +192,8 @@ export function updateLayeredMaterialNodeElevation(context, layer, node, parent) } // Possible conditions to *not* update the elevation texture - if (layer.frozen || + if (!layer.visible || + layer.frozen || !material.visible || !node.layerUpdateState[layer.id].canTryUpdate()) { return; diff --git a/src/Renderer/RasterTile.js b/src/Renderer/RasterTile.js index a42480f4bd..d92663d4e3 100644 --- a/src/Renderer/RasterTile.js +++ b/src/Renderer/RasterTile.js @@ -127,6 +127,8 @@ export class RasterElevationTile extends RasterTile { }; this.scaleFactor = 1.0; + this._min = 0; + this._max = 0; // Define elevation properties if (layer.useRgbaTextureElevation) { @@ -139,9 +141,6 @@ export class RasterElevationTile extends RasterTile { defaultEle.bias = layer.colorTextureElevationMinZ; this.min = this.layer.colorTextureElevationMinZ; this.max = this.layer.colorTextureElevationMaxZ; - } else { - this.min = 0; - this.max = 0; } this.bias = layer.bias || defaultEle.bias; @@ -156,6 +155,22 @@ export class RasterElevationTile extends RasterTile { return this.layer.scale * this.scaleFactor; } + get min() { + return this.visible ? this._min : 0; + } + + set min(value) { + this._min = value; + } + + get max() { + return this.visible ? this._max : 0; + } + + set max(value) { + this._max = value; + } + dispose(removeEvent) { super.dispose(removeEvent); if (removeEvent) { diff --git a/src/Renderer/Shader/Chunk/elevation_pars_vertex.glsl b/src/Renderer/Shader/Chunk/elevation_pars_vertex.glsl index bcb3c9b67c..1f6d694315 100644 --- a/src/Renderer/Shader/Chunk/elevation_pars_vertex.glsl +++ b/src/Renderer/Shader/Chunk/elevation_pars_vertex.glsl @@ -5,6 +5,7 @@ int mode; float zmin; float zmax; + bool visible; }; uniform Layer elevationLayers[NUM_VS_TEXTURES]; diff --git a/src/Renderer/Shader/Chunk/elevation_vertex.glsl b/src/Renderer/Shader/Chunk/elevation_vertex.glsl index b415e820bd..aa12608c96 100644 --- a/src/Renderer/Shader/Chunk/elevation_vertex.glsl +++ b/src/Renderer/Shader/Chunk/elevation_vertex.glsl @@ -1,5 +1,5 @@ #if NUM_VS_TEXTURES > 0 - if(elevationTextureCount > 0) { + if(elevationTextureCount > 0 && elevationLayers[0].visible) { float elevation = getElevation(uv, elevationTextures[0], elevationOffsetScales[0], elevationLayers[0]); transformed += elevation * normal; }