Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
175 commits
Select commit Hold shift + click to select a range
2c7f8c9
A working prototype, which adds 3d-terrain to maplibre-gl. Sadly, dur…
prozessor13 Jun 2, 2021
abed684
render more tiles to avoid wholes on tiled maps at canvas bottom
prozessor13 Jun 2, 2021
5f77f5c
Proof of concept! to get mercator-coords from the 3d-mesh on screen.
prozessor13 Jun 2, 2021
6f3278c
fix bug in picking correct coords from coordsFramebuffer
prozessor13 Jun 4, 2021
341ef2f
Add Depthbuffer to RTT Framebuffer
prozessor13 Jun 4, 2021
2a2a35d
add z-dimension to circle layers
prozessor13 Jun 16, 2021
71fa7a5
switch to regular grid, correct rendering below ZL14, remove visible …
prozessor13 Jun 18, 2021
2ae33e3
fix raster-rendering, hacky performance improvement
prozessor13 Jun 21, 2021
ebf5ea4
add z-dimension to fill-extrusion
prozessor13 Jun 22, 2021
bdf3eea
fix regular grid
prozessor13 Jun 23, 2021
129bda2
hide symbols behind terrain
prozessor13 Jun 25, 2021
ac2f0ee
calculate elevation of symbol/circle/extrusion only once
prozessor13 Jun 29, 2021
5c21371
render coords-framebuffer only on camera movement
prozessor13 Jun 29, 2021
9e4c74e
improve performacne: render layers to texture only once
prozessor13 Jul 2, 2021
2a3f99a
* raise camera to correct zoomlevel-distance over terrain
prozessor13 Jul 14, 2021
9af3979
Merge branch 'maplibre:main' into terrain3d
prozessor13 Jul 14, 2021
d95a197
Add an elevation offset of 450m to put the dead sea into positive values
prozessor13 Jul 14, 2021
0ff2e33
add yarn.lock file with martini entries
prozessor13 Jul 14, 2021
fe3b92a
render tiles only if terrain is loaded
prozessor13 Jul 26, 2021
5d24943
reuse framebuffer objects during rtt rendering
prozessor13 Jul 26, 2021
7aaff8f
reuse regular-mesh in all tiles
prozessor13 Jul 26, 2021
87e8205
add transform.elevation
prozessor13 Jul 27, 2021
ba9bd36
create transform.invProjMatrix before elevation correcture
prozessor13 Jul 28, 2021
55ad06a
* move exaggeration calculation into shaders
prozessor13 Aug 10, 2021
9f7edd4
convert to ts, but do not test this, it still has issues
prozessor13 Sep 6, 2021
1875f51
some minor fixes, add map.addTerrain and map.removeTerrain
prozessor13 Sep 10, 2021
7c6903a
refactor texture rendering
prozessor13 Sep 14, 2021
35a5e1b
moved elevation-calculation to GPU
prozessor13 Sep 24, 2021
7ecbc8a
fix calculate_visibility in overzoomed terrain-tiles
prozessor13 Sep 28, 2021
398c5a5
Merge branch 'main' into terrain3d
prozessor13 Sep 28, 2021
6b395d1
add very basic logic of loading tiles in respect of their elevation
prozessor13 Sep 29, 2021
7df734d
correct unprojecting coordinates
prozessor13 Oct 5, 2021
e644791
correct calculation of elevation in CPU for different maxzoom settings
prozessor13 Oct 6, 2021
1b36830
calcuate symbol visibility via a depth-framebuffer, because the coord…
prozessor13 Oct 7, 2021
cd34a3a
fix symbol flickering
prozessor13 Oct 7, 2021
b838fcd
typo
prozessor13 Oct 7, 2021
3d75e2f
move symbol/circle/fill_extrusion height calculation to GPU
prozessor13 Oct 15, 2021
10c7332
bugfix when rerender tiles, closes #24
prozessor13 Oct 19, 2021
11a133b
* free GPU less aggressive
prozessor13 Oct 21, 2021
f819944
bugfix with TerrainSourceCache.deltaZoom
prozessor13 Nov 3, 2021
eb595ce
* bugfix in u_terrain_matrix
prozessor13 Nov 3, 2021
e8fad6e
add linear interpolation
prozessor13 Nov 5, 2021
e41daac
remove visible tile-boundaries
prozessor13 Nov 5, 2021
68cad1e
reimplement deltaZoom
prozessor13 Nov 5, 2021
fa57d70
fix marker wobbling & check visibility
prozessor13 Nov 5, 2021
0535ad0
Merge branch 'main' into terrain3d
prozessor13 Nov 8, 2021
939a924
some code cleanup
prozessor13 Nov 9, 2021
86b7dbd
...
prozessor13 Nov 9, 2021
4efafc0
use preloaded terraintiles when zooming in and out
prozessor13 Nov 10, 2021
6e8beab
...
prozessor13 Nov 10, 2021
4b76529
bugfix for empty render-to-texture stack
prozessor13 Nov 10, 2021
9f02eba
set LOD tile-loading in case of terrain3d
prozessor13 Nov 12, 2021
b490d1a
avoid double-rendering (because of fading logic) of raster tiles
prozessor13 Nov 17, 2021
be076a6
calculate_visibility now checks visibility also some pixels above
prozessor13 Nov 19, 2021
ab0d337
...
prozessor13 Nov 19, 2021
4c4ff8f
add code-documentation
prozessor13 Nov 25, 2021
7d5d217
remove mtk raster-dem tiles hack
prozessor13 Nov 25, 2021
bc2ec6a
add more minor fixes and add some comments
prozessor13 Nov 26, 2021
53865a8
bugfix for collision-index calculation with disabled 3d,
prozessor13 Nov 26, 2021
b508431
Merge branch 'main' into terrain3d
prozessor13 Nov 26, 2021
2299f30
revert old fill_extrusion_bucket centroid code,
prozessor13 Nov 26, 2021
98137d3
fixes #36
prozessor13 Nov 29, 2021
0b81a41
Update CHANGELOG.md
acalcutt Dec 6, 2021
2192c1d
Revert "Update CHANGELOG.md"
acalcutt-wsu Dec 6, 2021
2031d8e
attribution fixes (from astridx)
acalcutt-wsu Dec 6, 2021
032b16e
Update .gitignore
acalcutt Dec 7, 2021
711436a
fix missing new line lint complained about
acalcutt Dec 7, 2021
41be4b5
Merge branch 'maplibre:main' into main
acalcutt Dec 8, 2021
629e818
Merge branch 'maplibre:main' into main
acalcutt Dec 9, 2021
7895d04
first try (not finished) to leave the camera at the same height when …
prozessor13 Dec 9, 2021
c68a94c
Merge branch 'maplibre:main' into main
acalcutt Dec 11, 2021
53d97eb
Revert "attribution fixes (from astridx)"
acalcutt Dec 11, 2021
5a28802
Merge remote-tracking branch 'prozessor13/terrain3d' into terrain_but…
acalcutt Dec 17, 2021
466f964
Create a TerrainControl to toggle terrain
acalcutt Dec 17, 2021
c1b695d
fix tabs and comment
acalcutt Dec 17, 2021
46bed6a
Merge branch 'maplibre:main' into main
acalcutt Dec 17, 2021
f967ea8
change exaggeration type to number. add options to control example
acalcutt Dec 19, 2021
b263230
change terrain icon fill color when enabled
acalcutt Dec 19, 2021
24af518
Merge branch 'maplibre:main' into main
acalcutt Dec 21, 2021
8f9d5e7
Merge branch 'maplibre:main' into main
acalcutt Dec 23, 2021
f6ac710
Merge branch 'main' into terrain3d
prozessor13 Dec 23, 2021
dcb1f88
Merge branch 'main' into terrain_button_test
acalcutt Dec 26, 2021
c414948
Merge remote-tracking branch 'terrain/terrain3d' into terrain_button_…
acalcutt Dec 26, 2021
8ab66b0
revert some merge changes
acalcutt Dec 26, 2021
be5e0e9
Revert package-lock.json for pull request
acalcutt Dec 26, 2021
d4f75f4
Merge branch 'main' into terrain3d
prozessor13 Jan 13, 2022
a27c387
some improvements leave the camera in the same height during paning
prozessor13 Jan 13, 2022
4e5f5a8
set default pitch back to 65, because of too much labels & missing sky
prozessor13 Jan 13, 2022
b2a730b
fix "mismatched image size" errors in some of our stylesheets
prozessor13 Jan 14, 2022
72cea62
Merge branch 'maplibre:main' into main
prozessor13 Jan 14, 2022
cfcba57
Merge branch 'main' into terrain3d
prozessor13 Jan 14, 2022
136b7d4
add default values during tinySDF generation
prozessor13 Jan 14, 2022
d8b7dcf
Merge pull request #51 from acalcutt/terrain_button_test
prozessor13 Jan 19, 2022
7cf9085
fire "terrain" events
prozessor13 Jan 19, 2022
94734ca
let use TerrainControl use terrain-Event
prozessor13 Jan 19, 2022
2fc3a57
typo
prozessor13 Jan 20, 2022
ffc30c9
may fix farZ clippingplane calculation
prozessor13 Jan 20, 2022
26a325a
fix TileID-order of transform.coveringTiles result
prozessor13 Jan 20, 2022
0ca7148
call transform.updateElevation on every rendering
prozessor13 Jan 20, 2022
c5ef800
rerender rtt tiles on geojson.setData
prozessor13 Feb 8, 2022
e1c00c7
freezeElevation while camera-easing
prozessor13 Feb 8, 2022
1298a76
Merge branch 'maplibre:main' into main
prozessor13 Feb 8, 2022
12e091a
Merge branch 'main' into terrain3d
prozessor13 Feb 8, 2022
84674ef
make tests running
prozessor13 Feb 10, 2022
b924457
speedup symbol-placement in 2D mode
prozessor13 Feb 15, 2022
daaf8ca
...
prozessor13 Feb 15, 2022
32b01dd
add first very poor TerrainSourceCache test
prozessor13 Feb 16, 2022
f146f67
...
prozessor13 Feb 16, 2022
3343d35
show correct tileBoundaries & collisionBoxes in terrain
prozessor13 Feb 17, 2022
87601e2
load LOD tiles in respect of terrain
prozessor13 Feb 17, 2022
2439a60
rename getElevationWithExaggeration to getElevation
prozessor13 Feb 17, 2022
a2246ba
calculate tileDistanceToCamera form future-use in tile reduction algo…
prozessor13 Feb 21, 2022
0aea4c6
update terrain-test page to maxPitch = 85
prozessor13 Feb 21, 2022
4c8f629
Merge main
wipfli Feb 24, 2022
6e87782
Merge branch 'main' into terrain3d
wipfli Feb 24, 2022
bbc1f9c
Fix some lint warnings
HarelM Feb 25, 2022
c3df5a3
Fix some lint warnings
HarelM Feb 25, 2022
4ee0bf9
lint warning fixes
HarelM Feb 25, 2022
18d2686
Improve typings, fix lint warnings
HarelM Feb 26, 2022
06d8798
Merge branch 'main' into terrain3d
HarelM Feb 26, 2022
7e8bdc8
Add type to getElevation parameter
HarelM Feb 26, 2022
a296202
Update collision expected again?
HarelM Feb 26, 2022
d5b894b
calculate farZ clipping-plane in respect of transform.getHorizon
prozessor13 Mar 7, 2022
9124a0f
reduce number of loaded tiles
prozessor13 Mar 7, 2022
64dda49
fix transform.locationPoint in 3d-mode
prozessor13 Mar 7, 2022
5e1f2ee
fix not rendered areas in high zoomlevels
prozessor13 Mar 9, 2022
16a6e30
fix typescript errors
prozessor13 Mar 9, 2022
269080e
fix mouse zoom & tilt logic in 2D
prozessor13 Mar 9, 2022
7d4bbc4
if last layer is a rtt layer, do not render it twice, fixes #1036
prozessor13 Mar 9, 2022
cc0f4c7
correct calculation of queryRenderedFeatures coordinates in 3d-mode. …
prozessor13 Mar 9, 2022
0dfdb7b
Fix build typescript generation
HarelM Mar 9, 2022
dde636c
remove fixme's and create issues for that
prozessor13 Mar 10, 2022
668d35f
Merge branch 'main' into terrain3d
HarelM Mar 10, 2022
e4674f5
Small code fixes to avoid review comments
HarelM Mar 12, 2022
5149215
Merge branch 'main' into terrain3d
HarelM Mar 12, 2022
a0bc5aa
Fix lint
HarelM Mar 12, 2022
2691ae5
Fix draw_symbol unit test
HarelM Mar 12, 2022
5fe1e30
Merge branch 'main' into terrain3d
wipfli Mar 15, 2022
ea6b9f4
Fix unit test
wipfli Mar 15, 2022
6f824b5
Remove console.log
wipfli Mar 15, 2022
6cd4cf9
Merge main, fix collisions, remove `fromValues()`
wipfli Mar 22, 2022
21c703b
Fix build
wipfli Mar 22, 2022
3c476e4
Merge branch 'main' into terrain3d
wipfli Mar 22, 2022
99a6b13
refacture TerrainSourceCache class
prozessor13 Mar 30, 2022
e6f46d1
Merge branch 'main' into terrain3d
prozessor13 Mar 30, 2022
e9dab61
Merge branch 'terrain3d' of github.com:maplibre/maplibre-gl-js into t…
prozessor13 Mar 30, 2022
4ea0c2a
fix lint errors
prozessor13 Mar 30, 2022
485db09
add tests for sourceCache.usedForTerrain partent-tile-logic
prozessor13 Mar 30, 2022
de9e7da
minor fixes
prozessor13 Mar 30, 2022
433d14e
Added some types and minor changes.
HarelM Mar 30, 2022
1d9683f
encapsulate a_centroid shader attributes to #TERRAIN3D preprocessor
prozessor13 Mar 31, 2022
d344a57
Merge branch 'terrain3d' of github.com:maplibre/maplibre-gl-js into t…
prozessor13 Mar 31, 2022
bd572d6
remove terrain-instance from transform class, instead put as argument
prozessor13 Apr 6, 2022
e87a482
Merge branch 'main' into terrain3d
prozessor13 Apr 6, 2022
c591a2e
add forgotten return statements
prozessor13 Apr 6, 2022
6a40579
Add terrain to style spec (#1138)
HarelM Apr 6, 2022
5c1103c
update some code-comments
prozessor13 Apr 6, 2022
fa219ed
Merge branch 'terrain3d' of github.com:maplibre/maplibre-gl-js into t…
prozessor13 Apr 6, 2022
51cdd81
do not upload fill-extrusion centroid vertextbuffer in 2d
prozessor13 Apr 7, 2022
9aeccbb
transform.elevation setter: do not set unmodified state to let map.lo…
prozessor13 Apr 7, 2022
5600392
fix minor bugs when enable/disable terrain
prozessor13 Apr 7, 2022
c88fe10
fix lint
prozessor13 Apr 7, 2022
c2ab1b4
add test for recalcuateZoom
prozessor13 Apr 7, 2022
4fe5615
Merge branch 'main' into terrain3d
HarelM Apr 8, 2022
5772b4c
Fixes related to console errors and some typings improvement in terra…
HarelM Apr 14, 2022
d8aa186
Use MapTiler terrain tiles (#1184)
wipfli Apr 15, 2022
c030812
remove freezeElevation event when disable terrain3d, fixes #1185
prozessor13 Apr 16, 2022
409535e
Merge branch 'terrain3d' of github.com:maplibre/maplibre-gl-js into t…
prozessor13 Apr 16, 2022
c92f7a4
Fixes #1186 - add typeof guard check
HarelM Apr 16, 2022
84a1339
Terrain3D symbol cutoff at horizon (#1188)
prozessor13 Apr 18, 2022
806dd3e
Use demotiles.maplibre.org (#1190)
wipfli Apr 20, 2022
6a9d9cc
Fix terrain source button (#1192)
wipfli Apr 20, 2022
b280511
When terrain is on, render last layer correct, fixes #1124 (#1189)
prozessor13 May 12, 2022
7a05024
Merge branch 'main' into terrain3d
HarelM May 12, 2022
b3c2c94
Fix lint
HarelM May 12, 2022
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
2 changes: 2 additions & 0 deletions build/generate-style-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ ${objectDeclaration('StyleSpecification', spec.$root)}

${objectDeclaration('LightSpecification', spec.light)}

${objectDeclaration('TerrainSpecification', spec.terrain)}

${spec.source.map(key => objectDeclaration(sourceTypeName(key), spec[key])).join('\n\n')}

export type SourceSpecification =
Expand Down
93 changes: 93 additions & 0 deletions debug/terrain.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<!DOCTYPE html>
<html>

<head>
<title>MapLibre GL JS debug page for terrian</title>
<meta charset='utf-8'>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<link rel='stylesheet' href='../dist/maplibre-gl.css' />
<style>
body {
margin: 0;
padding: 0;
}

html,
body,
#map {
height: 100%;
}
</style>
</head>

<body>
<div id='map'></div>

<script src='../dist/maplibre-gl-dev.js'></script>
<script>
var map = window.map = new maplibregl.Map({
container: 'map',
zoom: 12,
center: [11.39085, 47.27574],
pitch: 52,
hash: true,
style: {
version: 8,
sources: {
osm: {
type: 'raster',
tiles: ['https://a.tile.openstreetmap.org/{z}/{x}/{y}.png'],
tileSize: 256,
attribution: '&copy; OpenStreetMap Contributors',
maxzoom: 19
},
terrainSource: {
type: 'raster-dem',
url: 'https://demotiles.maplibre.org/terrain-tiles/tiles.json',
tileSize: 256
},
hillshadeSource: {
type: 'raster-dem',
url: 'https://demotiles.maplibre.org/terrain-tiles/tiles.json',
tileSize: 256
},
},
layers: [
{
id: 'osm',
type: 'raster',
source: 'osm'
},
{
id: 'hills',
type: 'hillshade',
source: 'hillshadeSource',
layout: {'visibility': 'visible'},
paint: {'hillshade-shadow-color': '#473B24'}
}
],
terrain: {
source: 'terrainSource',
exaggeration: 1
}
},
maxZoom: 18,
maxPitch: 85
});

map.addControl(new maplibregl.NavigationControl({
visualizePitch: true,
showZoom: true,
showCompass: true
}));

map.addControl(
new maplibregl.TerrainControl({
source: 'terrainSource',
exaggeration: 1
})
);
</script>
</body>

</html>
20 changes: 20 additions & 0 deletions src/css/maplibre-gl.css
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,26 @@
}
}

@svg-load ctrl-terrain url("svg/maplibregl-ctrl-terrain.svg") {
fill: #333;
#stroke { display: none; }
}

@svg-load ctrl-terrain-enabled url("svg/maplibregl-ctrl-terrain.svg") {
fill: #33b5e5;
#stroke { display: none; }
}

.maplibregl-ctrl button.maplibregl-ctrl-terrain .maplibregl-ctrl-icon,
.mapboxgl-ctrl button.mapboxgl-ctrl-terrain .mapboxgl-ctrl-icon {
background-image: svg-inline(ctrl-terrain);
}

.maplibregl-ctrl button.maplibregl-ctrl-terrain-enabled .maplibregl-ctrl-icon,
.mapboxgl-ctrl button.mapboxgl-ctrl-terrain-enabled .mapboxgl-ctrl-icon {
background-image: svg-inline(ctrl-terrain-enabled);
}

@svg-load ctrl-geolocate url("svg/maplibregl-ctrl-geolocate.svg") {
fill: #333;
#stroke { display: none; }
Expand Down
7 changes: 7 additions & 0 deletions src/css/svg/maplibregl-ctrl-terrain.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/data/bucket/fill_extrusion_attributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@ const layout = createLayout([
{name: 'a_normal_ed', components: 4, type: 'Int16'},
], 4);

export const centroidAttributes = createLayout([
{name: 'a_centroid', components: 2, type: 'Int16'}
], 4);

export default layout;
export const {members, size, alignment} = layout;
32 changes: 28 additions & 4 deletions src/data/bucket/fill_extrusion_bucket.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {FillExtrusionLayoutArray} from '../array_types.g';
import {FillExtrusionLayoutArray, PosArray} from '../array_types.g';

import {members as layoutAttributes} from './fill_extrusion_attributes';
import {members as layoutAttributes, centroidAttributes} from './fill_extrusion_attributes';
import SegmentVector from '../segment';
import {ProgramConfigurationSet} from '../program_configuration';
import {TriangleIndexArray} from '../index_array_type';
Expand Down Expand Up @@ -63,6 +63,9 @@ class FillExtrusionBucket implements Bucket {
layoutVertexArray: FillExtrusionLayoutArray;
layoutVertexBuffer: VertexBuffer;

centroidVertexArray: PosArray;
centroidVertexBuffer: VertexBuffer;

indexArray: TriangleIndexArray;
indexBuffer: IndexBuffer;

Expand All @@ -81,11 +84,11 @@ class FillExtrusionBucket implements Bucket {
this.hasPattern = false;

this.layoutVertexArray = new FillExtrusionLayoutArray();
this.centroidVertexArray = new PosArray();
this.indexArray = new TriangleIndexArray();
this.programConfigurations = new ProgramConfigurationSet(options.layers, options.zoom);
this.segments = new SegmentVector();
this.stateDependentLayerIds = this.layers.filter((l) => l.isStateDependent()).map((l) => l.id);

}

populate(features: Array<IndexedFeature>, options: PopulateParameters, canonical: CanonicalTileID) {
Expand Down Expand Up @@ -131,7 +134,7 @@ class FillExtrusionBucket implements Bucket {
}

isEmpty() {
return this.layoutVertexArray.length === 0;
return this.layoutVertexArray.length === 0 && this.centroidVertexArray.length === 0;
}

uploadPending() {
Expand All @@ -141,6 +144,7 @@ class FillExtrusionBucket implements Bucket {
upload(context: Context) {
if (!this.uploaded) {
this.layoutVertexBuffer = context.createVertexBuffer(this.layoutVertexArray, layoutAttributes);
this.centroidVertexBuffer = context.createVertexBuffer(this.centroidVertexArray, centroidAttributes.members, true);
this.indexBuffer = context.createIndexBuffer(this.indexArray);
}
this.programConfigurations.upload(context);
Expand All @@ -153,9 +157,11 @@ class FillExtrusionBucket implements Bucket {
this.indexBuffer.destroy();
this.programConfigurations.destroy();
this.segments.destroy();
this.centroidVertexBuffer.destroy();
}

addFeature(feature: BucketFeature, geometry: Array<Array<Point>>, index: number, canonical: CanonicalTileID, imagePositions: {[_: string]: ImagePosition}) {
const centroid = {x: 0, y: 0, vertexCount: 0};
for (const polygon of classifyRings(geometry, EARCUT_MAX_RINGS)) {
let numVertices = 0;
for (const ring of polygon) {
Expand Down Expand Up @@ -191,11 +197,17 @@ class FillExtrusionBucket implements Bucket {

addVertex(this.layoutVertexArray, p1.x, p1.y, perp.x, perp.y, 0, 0, edgeDistance);
addVertex(this.layoutVertexArray, p1.x, p1.y, perp.x, perp.y, 0, 1, edgeDistance);
centroid.x += 2 * p1.x;
centroid.y += 2 * p1.y;
centroid.vertexCount += 2;

edgeDistance += dist;

addVertex(this.layoutVertexArray, p2.x, p2.y, perp.x, perp.y, 0, 0, edgeDistance);
addVertex(this.layoutVertexArray, p2.x, p2.y, perp.x, perp.y, 0, 1, edgeDistance);
centroid.x += 2 * p2.x;
centroid.y += 2 * p2.y;
centroid.vertexCount += 2;

const bottomRight = segment.vertexLength;

Expand All @@ -212,6 +224,7 @@ class FillExtrusionBucket implements Bucket {
}
}
}

}

if (segment.vertexLength + numVertices > SegmentVector.MAX_VERTEX_ARRAY_LENGTH) {
Expand Down Expand Up @@ -240,10 +253,14 @@ class FillExtrusionBucket implements Bucket {
const p = ring[i];

addVertex(this.layoutVertexArray, p.x, p.y, 0, 0, 1, 1, 0);
centroid.x += p.x;
centroid.y += p.y;
centroid.vertexCount += 1;

flattened.push(p.x);
flattened.push(p.y);
}

}

const indices = earcut(flattened, holeIndices);
Expand All @@ -261,6 +278,13 @@ class FillExtrusionBucket implements Bucket {
segment.vertexLength += numVertices;
}

// remember polygon centroid to calculate elevation in GPU
for (let i = 0; i < centroid.vertexCount; i++) {
this.centroidVertexArray.emplaceBack(
Math.floor(centroid.x / centroid.vertexCount),
Math.floor(centroid.y / centroid.vertexCount)
);
}
this.programConfigurations.populatePaintArrays(this.layoutVertexArray.length, feature, index, imagePositions, canonical);
}
}
Expand Down
15 changes: 14 additions & 1 deletion src/data/dem_data.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,26 @@ describe('DEMData is correctly serialized and deserialized', () => {
const dem0 = new DEMData('0', imageData0, 'mapbox');
const serialized = serialize(dem0);

// calculate min/max values
let min = Number.MAX_SAFE_INTEGER;
let max = Number.MIN_SAFE_INTEGER;
for (let x = 0; x < 4; x++) {
for (let y = 0; y < 4; y++) {
const ele = dem0.get(x, y);
if (ele > max) max = ele;
if (ele < min) min = ele;
}
}

expect(serialized).toEqual({
$name: 'DEMData',
uid: '0',
dim: 4,
stride: 6,
data: dem0.data,
encoding: 'mapbox'
encoding: 'mapbox',
max,
Comment thread
HarelM marked this conversation as resolved.
min,
});

const transferrables = [];
Expand Down
13 changes: 13 additions & 0 deletions src/data/dem_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export default class DEMData {
data: Uint32Array;
stride: number;
dim: number;
min: number;
max: number;
encoding: 'mapbox' | 'terrarium';

// RGBAImage data has uniform 1px padding on all sides: square tile edge size defines stride
Expand Down Expand Up @@ -52,6 +54,17 @@ export default class DEMData {
this.data[this._idx(dim, -1)] = this.data[this._idx(dim - 1, 0)];
this.data[this._idx(-1, dim)] = this.data[this._idx(0, dim - 1)];
this.data[this._idx(dim, dim)] = this.data[this._idx(dim - 1, dim - 1)];

// calculate min/max values
this.min = Number.MAX_SAFE_INTEGER;
this.max = Number.MIN_SAFE_INTEGER;
for (let x = 0; x < dim; x++) {
for (let y = 0; y < dim; y++) {
const ele = this.get(x, y);
if (ele > this.max) this.max = ele;
if (ele < this.min) this.min = ele;
}
}
}

get(x: number, y: number) {
Expand Down
57 changes: 56 additions & 1 deletion src/geo/transform.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Transform from './transform';
import LngLat from './lng_lat';
import {OverscaledTileID, CanonicalTileID} from '../source/tile_id';
import {fixedLngLat, fixedCoord} from '../../test/unit/lib/fixed';
import type Terrain from '../render/terrain';

describe('transform', () => {
test('creates a transform', () => {
Expand Down Expand Up @@ -340,7 +341,6 @@ describe('transform', () => {
});

test('maintains high float precision when calculating matrices', () => {

const transform = new Transform(0, 22, 0, 60, true);
transform.resize(200.25, 200.25);
transform.zoom = 20.25;
Expand All @@ -352,4 +352,59 @@ describe('transform', () => {
expect(transform.glCoordMatrix[0].toString().length).toBeGreaterThan(10);
expect(transform.maxPitchScaleFactor()).toBeCloseTo(2.366025418080343, 10);
});

test('recalcuateZoom', () => {
const transform = new Transform(0, 22, 0, 60, true);
transform.elevation = 200;
transform.center = new LngLat(10.0, 50.0);
transform.zoom = 14;
transform.resize(512, 512);

// expect same values because of no elevation change
transform.getElevation = () => 200;
transform.recalculateZoom(null);
expect(transform.zoom).toBe(14);

// expect new zoom because of elevation change
transform.getElevation = () => 400;
transform.recalculateZoom(null);
expect(transform.zoom).toBe(14.127997275621933);
expect(transform.elevation).toBe(400);
expect(transform._center.lng).toBe(10.00000000000071);
expect(transform._center.lat).toBe(50.00000000000017);
});

test('pointCoordinate with terrain when returning null should fall back to 2D', () => {
const transform = new Transform(0, 22, 0, 60, true);
transform.resize(500, 500);
const terrain = {
pointCoordinate: () => null
} as any as Terrain;
const coordinate = transform.pointCoordinate(new Point(0, 0), terrain);

expect(coordinate).toBeDefined();
});

test('horizon', () => {
const transform = new Transform(0, 22, 0, 85, true);
transform.resize(500, 500);
transform.pitch = 75;
const horizon = transform.getHorizon();

expect(horizon).toBeCloseTo(170.8176101748407, 10);
});

test('getBounds with horizon', () => {
const transform = new Transform(0, 22, 0, 85, true);
transform.resize(500, 500);

transform.pitch = 60;
expect(transform.getBounds().getNorthWest().toArray()).toStrictEqual(transform.pointLocation(new Point(0, 0)).toArray());

transform.pitch = 75;
const top = Math.max(0, transform.height / 2 - transform.getHorizon());
expect(top).toBeCloseTo(79.1823898251593, 10);
expect(transform.getBounds().getNorthWest().toArray()).toStrictEqual(transform.pointLocation(new Point(0, top)).toArray());
});

});
Loading