Skip to content

Commit

Permalink
feature(ElevationLayer): add visible property.
Browse files Browse the repository at this point in the history
  • Loading branch information
gchoqueux committed Dec 16, 2021
1 parent 7db9bcb commit a64b81a
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 8 deletions.
14 changes: 11 additions & 3 deletions examples/js/GUI/GuiTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions src/Layer/ElevationLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
});

Expand Down
3 changes: 2 additions & 1 deletion src/Process/LayeredMaterialNodeProcessing.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
21 changes: 18 additions & 3 deletions src/Renderer/RasterTile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand All @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/Renderer/Shader/Chunk/elevation_pars_vertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
int mode;
float zmin;
float zmax;
bool visible;
};

uniform Layer elevationLayers[NUM_VS_TEXTURES];
Expand Down
2 changes: 1 addition & 1 deletion src/Renderer/Shader/Chunk/elevation_vertex.glsl
Original file line number Diff line number Diff line change
@@ -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;
}
Expand Down

0 comments on commit a64b81a

Please sign in to comment.