Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature(ElevationLayer): add visible property. #1769

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions examples/js/GUI/GuiTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,16 @@ 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;
}));
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.addGeoidLayerGUI = function addGeoidLayerGUI(layer) {
Expand Down
8 changes: 8 additions & 0 deletions src/Core/View.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ function _preprocessLayer(view, layer, parentLayer) {
}
}

if (layer.isElevationLayer && view.controls) {
layer.addEventListener('visible-property-changed', () => {
// To update collision camera with terrain
view.notifyChange(view.camera);
view.controls.update();
});
}

if (layer.isLabelLayer) {
view.mainLoop.gfxEngine.label2dRenderer.registerLayer(layer);
} else if (layer.labelEnabled || layer.addLabelLayer) {
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 @@ -81,8 +82,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