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

refactor(LayeredMaterial): migrate to TypeScript #2477

Open
wants to merge 3 commits 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
6 changes: 3 additions & 3 deletions src/Converter/convertToTile.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
import * as THREE from 'three';
import TileMesh from 'Core/TileMesh';
import LayeredMaterial from 'Renderer/LayeredMaterial';
import { LayeredMaterial } from 'Renderer/LayeredMaterial';
import { newTileGeometry } from 'Core/Prefab/TileBuilder';
import ReferLayerProperties from 'Layer/ReferencingLayerProperties';
import { geoidLayerIsVisible } from 'Layer/GeoidLayer';
Expand All @@ -18,7 +18,7 @@ function setTileFromTiledLayer(tile, tileLayer) {
}

if (__DEBUG__) {
tile.material.showOutline = tileLayer.showOutline || false;
tile.material.setUniform('showOutline', tileLayer.showOutline || false);
}

if (tileLayer.isGlobeLayer) {
Expand Down Expand Up @@ -78,7 +78,7 @@ export default {
tile.geoidHeight = parent.geoidHeight;
const geoidHeight = geoidLayerIsVisible(layer) ? tile.geoidHeight : 0;
tile.setBBoxZ({ min: parent.obb.z.min, max: parent.obb.z.max, geoidHeight });
tile.material.geoidHeight = geoidHeight;
tile.material.setUniform('geoidHeight', geoidHeight);
}

return tile;
Expand Down
4 changes: 2 additions & 2 deletions src/Layer/ColorLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ class ColorLayer extends RasterLayer {
setupRasterNode(node) {
const rasterColorNode = new RasterColorTile(node.material, this);

node.material.addLayer(rasterColorNode);
node.material.addColorLayer(rasterColorNode);
// set up ColorLayer ordering.
node.material.setSequence(this.parent.colorLayersOrder);
node.material.setColorLayerIds(this.parent.colorLayersOrder);

return rasterColorNode;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Layer/ElevationLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ class ElevationLayer extends RasterLayer {
setupRasterNode(node) {
const rasterElevationNode = new RasterElevationTile(node.material, this);

node.material.addLayer(rasterElevationNode);
node.material.setSequenceElevation(this.id);
node.material.setElevationLayer(rasterElevationNode);
node.material.setElevationLayerId(this.id);
// bounding box initialisation
const updateBBox = () => node.setBBoxZ({
min: rasterElevationNode.min, max: rasterElevationNode.max, scale: this.scale,
Expand Down
4 changes: 2 additions & 2 deletions src/Layer/GeoidLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ class GeoidLayer extends Layer {
}

updateNodeZ(node) {
node.material.geoidHeight = this.visible ? node.geoidHeight : 0;
node.obb.updateZ({ geoidHeight: node.material.geoidHeight });
node.material.setUniform('geoidHeight', this.visible ? node.geoidHeight : 0);
node.obb.updateZ({ geoidHeight: node.material.getUniform('geoidHeight') });
}

update(context, layer, node, parent) {
Expand Down
2 changes: 1 addition & 1 deletion src/Layer/TiledGeometryLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ class TiledGeometryLayer extends GeometryLayer {
if (layerUpdateState[c.id] && layerUpdateState[c.id].inError()) {
continue;
}
nodeLayer = node.material.getLayer(c.id);
nodeLayer = node.material.getColorLayer(c.id);
if (c.source.extentInsideLimit(node.extent, zoom) && (!nodeLayer || nodeLayer.level < 0)) {
return false;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Process/LayeredMaterialNodeProcessing.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ export function updateLayeredMaterialNodeElevation(context, layer, node, parent)

// Possible conditions to *not* update the elevation texture
if (layer.frozen ||
!material.visible ||
!node.layerUpdateState[layer.id].canTryUpdate()) {
!material.visible ||
!node.layerUpdateState[layer.id].canTryUpdate()) {
return;
}

Expand Down Expand Up @@ -238,7 +238,7 @@ export function removeLayeredMaterialNodeLayer(layerId) {
*/
return function removeLayeredMaterialNodeLayer(node) {
if (node.material?.removeLayer) {
if (node.material.elevationLayerIds.indexOf(layerId) > -1) {
if (node.material.elevationTile !== undefined) {
node.setBBoxZ({ min: 0, max: 0 });
}
node.material.removeLayer(layerId);
Expand Down
13 changes: 8 additions & 5 deletions src/Renderer/ColorLayersOrdering.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { ImageryLayers } from 'Layer/Layer';
function updateLayersOrdering(geometryLayer, imageryLayers) {
const sequence = ImageryLayers.getColorLayersIdOrderedBySequence(imageryLayers);
const cO = function cO(object) {
if (object.material?.setSequence) {
object.material.setSequence(sequence);
if (object.material?.setColorLayerIds) {
object.material.setColorLayerIds(sequence);
}
};

Expand Down Expand Up @@ -38,7 +38,8 @@ export default {
const previousSequence = ImageryLayers.getColorLayersIdOrderedBySequence(imageryLayers);
ImageryLayers.moveLayerUp(layer, imageryLayers);
updateLayersOrdering(view.tileLayer, imageryLayers);
view.dispatchEvent({ type: COLOR_LAYERS_ORDER_CHANGED,
view.dispatchEvent({
type: COLOR_LAYERS_ORDER_CHANGED,
previous: { sequence: previousSequence },
new: { sequence: ImageryLayers.getColorLayersIdOrderedBySequence(imageryLayers) },
});
Expand All @@ -64,7 +65,8 @@ export default {
const previousSequence = ImageryLayers.getColorLayersIdOrderedBySequence(imageryLayers);
ImageryLayers.moveLayerDown(layer, imageryLayers);
updateLayersOrdering(view.tileLayer, imageryLayers);
view.dispatchEvent({ type: COLOR_LAYERS_ORDER_CHANGED,
view.dispatchEvent({
type: COLOR_LAYERS_ORDER_CHANGED,
previous: { sequence: previousSequence },
new: { sequence: ImageryLayers.getColorLayersIdOrderedBySequence(imageryLayers) },
});
Expand All @@ -91,7 +93,8 @@ export default {
const previousSequence = ImageryLayers.getColorLayersIdOrderedBySequence(imageryLayers);
ImageryLayers.moveLayerToIndex(layer, index, imageryLayers);
updateLayersOrdering(view.tileLayer, imageryLayers);
view.dispatchEvent({ type: COLOR_LAYERS_ORDER_CHANGED,
view.dispatchEvent({
type: COLOR_LAYERS_ORDER_CHANGED,
previous: { sequence: previousSequence },
new: { sequence: ImageryLayers.getColorLayersIdOrderedBySequence(imageryLayers) },
});
Expand Down
Loading
Loading