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

Fix/remaining issues camera inside terrain #4551

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
6ce770b
Revert "Remove padding from camera elevation if inside terrain."
chrneumann Aug 13, 2024
2efeea5
Reapply "Fix render tests for terrain."
chrneumann Aug 13, 2024
d569899
Don't directly update transform in _finalizeElevation.
chrneumann Aug 13, 2024
fe6191c
Prevent throwing in case of wrong zoom calculation.
chrneumann Aug 13, 2024
db287d1
Merge branch 'main' into fix/remaining-issues-camera-inside-terrain
HarelM Aug 28, 2024
b5efbf6
Merge branch 'main' into fix/remaining-issues-camera-inside-terrain
HarelM Aug 28, 2024
9950b94
Merge branch 'main' into fix/remaining-issues-camera-inside-terrain
HarelM Sep 4, 2024
3484b91
Rework catching of errors on zoom recalculation.
chrneumann Sep 12, 2024
1d83c6e
Merge branch 'main' into fix/remaining-issues-camera-inside-terrain
HarelM Sep 14, 2024
c2825a0
Merge remote-tracking branch 'origin/main' into fix/remaining-issues-…
chrneumann Sep 19, 2024
103794d
Fix camera unit test.
chrneumann Sep 19, 2024
1ee53ee
Fix render test.
chrneumann Sep 19, 2024
cba97c1
Merge branch 'main' into fix/remaining-issues-camera-inside-terrain
HarelM Sep 19, 2024
a5dc76d
Merge remote-tracking branch 'origin/main' into fix/remaining-issues-…
chrneumann Sep 30, 2024
cd88615
Add changelog entry.
chrneumann Sep 30, 2024
9940ea5
Remove old transform, apply changes to mercator transform.
chrneumann Sep 30, 2024
0f0d4de
Merge remote-tracking branch 'origin/main' into fix/remaining-issues-…
chrneumann Oct 30, 2024
a177ba4
Fix build and render tests.
chrneumann Oct 30, 2024
e412a62
Merge remote-tracking branch 'origin/main' into fix/remaining-issues-…
chrneumann Oct 30, 2024
dfeb449
Merge branch 'main' into fix/remaining-issues-camera-inside-terrain
HarelM Oct 31, 2024
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
- _...Add new stuff here..._

### 🐞 Bug fixes

- Fix line-placed map-pitch-aligned texts being too large when viewed from some latitudes on a globe ([#4786](https://github.com/maplibre/maplibre-gl-js/issues/4786))
- Fix crashes when camera is inside terrain. Add padding between camera and surface to prevent cases like this. ([#1542](https://github.com/maplibre/maplibre-gl-js/issues/1542))
- _...Add new stuff here..._

## 5.0.0-pre.4
Expand Down
3 changes: 3 additions & 0 deletions src/ui/camera.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2028,6 +2028,9 @@ describe('#flyTo', () => {
};
camera.transform = {
elevation: 0,
recalculateZoom: () => true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be recalculateZoomAndCenter() now

clone: () => camera.transform,
apply: () => {},
recalculateZoomAndCenter: () => true,
setMinElevationForCurrentTile: (_a) => true,
setElevation: (e) => { camera.transform.elevation = e; }
Expand Down
9 changes: 6 additions & 3 deletions src/ui/camera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1205,7 +1205,9 @@ export abstract class Camera extends Evented {
_finalizeElevation() {
this._elevationFreeze = false;
if (this.getCenterClampedToGround()) {
this.transform.recalculateZoomAndCenter(this.terrain);
const tr = this._getTransformForUpdate();
tr.recalculateZoomAndCenter(this.terrain);
this._applyUpdatedTransform(tr);
}
}

Expand Down Expand Up @@ -1238,13 +1240,14 @@ export abstract class Camera extends Evented {
*
* @param tr - The transform to check.
*/
_elevateCameraIfInsideTerrain(tr: ITransform) : { pitch?: number; zoom?: number } {
_elevateCameraIfInsideTerrain(tr: ITransform): { pitch?: number; zoom?: number } {
if (!this.terrain && tr.elevation >= 0 && tr.pitch <= 90) {
return {};
}
const surfacePadding = Math.min(500, 20 * (25 - tr.zoom));
Copy link
Contributor

@NathanMOlson NathanMOlson Oct 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this surface padding?

At a typical zoom of 15, this sets the minimum altitude at 200m. This amount of surface padding is problematic for ground-level use cases (like an aircraft on the runway, or touring a city at eye-level.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can help prevent graphic glitches when the camera is directly moving on the surface. Do these use cases have terrain enabled? If so, one could make the padding optional.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "aircraft on runway" (#4717) use case (#4717) will definitely have terrain enabled.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The linear scaling with zoom level doesn't make sense to me. I think it would be more appropriate to have something like 500 / (2**tr.zoom).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have strong arguments for the current calculation, but why do you think non-linear is better?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the distance from camera to center point (in meters) is inversely proportional to 2**tr.zoom

If you increase zoom by 1, you are cutting the distance from camera to center point in half. So it seems like you should also cut the padding in half.

const cameraLngLat = tr.getCameraLngLat();
const cameraAltitude = tr.getCameraAltitude();
const minAltitude = this.terrain ? this.terrain.getElevationForLngLatZoom(cameraLngLat, tr.zoom) : 0;
const minAltitude = this.terrain ? this.terrain.getElevationForLngLatZoom(cameraLngLat, tr.zoom) + surfacePadding : 0;
if (cameraAltitude < minAltitude) {
const newCamera = this.calculateCameraOptionsFromTo(
cameraLngLat, minAltitude, tr.center, tr.elevation);
Expand Down
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think any of the "expected" images for these render tests should change. The fact that they are changing means that the pitch angle is being adjusted, and I don't think it should be in any of these cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's shifted because the padding is added which results in a changed angle (the center stays the same).

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/integration/render/tests/terrain/fog-sky-blend/expected.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/integration/render/tests/terrain/fog/expected.png
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "expected" image shows this bug: #4859

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.