Skip to content

Commit

Permalink
feat(LayeredMaterial): migrate to TypeScript
Browse files Browse the repository at this point in the history
fix(tests): add new empty methods to mock Material
refactor: use interface where possible

fix: use setUniform for material showOutline set

wip

fix(elevation): correct antilogy
  • Loading branch information
HoloTheDrunk committed Jan 16, 2025
1 parent c4629d6 commit 9136549
Show file tree
Hide file tree
Showing 16 changed files with 587 additions and 312 deletions.
6 changes: 3 additions & 3 deletions src/Converter/convertToTile.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
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 @@ -13,7 +13,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 @@ -73,7 +73,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

0 comments on commit 9136549

Please sign in to comment.