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

Conversation

chrneumann
Copy link
Contributor

@chrneumann chrneumann commented Aug 13, 2024

Launch Checklist

Add buffer so that camera doesn't sit directly on terrain. Prevent crashes when zoom is wrongly calculated.

  • Confirm your changes do not include backports from Mapbox projects (unless with compliant license) - if you are not sure about this, please ask!
  • Briefly describe the changes in this PR.
  • Link to related issues.
  • Include before/after visuals or gifs if this PR includes visual changes.
  • Write tests for all new functionality.
  • Document any changes to public APIs.
  • Post benchmark scores.
  • Add an entry to CHANGELOG.md under the ## main section.

@codecov-commenter
Copy link

codecov-commenter commented Aug 13, 2024

Codecov Report

Attention: Patch coverage is 50.00000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 90.70%. Comparing base (d3f2bca) to head (dfeb449).
Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
src/ui/camera.ts 50.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4551      +/-   ##
==========================================
+ Coverage   90.48%   90.70%   +0.22%     
==========================================
  Files         265      265              
  Lines       38113    38116       +3     
  Branches     3166     3150      -16     
==========================================
+ Hits        34488    34575      +87     
+ Misses       2650     2601      -49     
+ Partials      975      940      -35     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

src/geo/transform.ts Outdated Show resolved Hide resolved
@HarelM
Copy link
Collaborator

HarelM commented Aug 24, 2024

@chrneumann where are we with this?

@chrneumann
Copy link
Contributor Author

@chrneumann where are we with this?

Waiting for your reply, see the open code review.

@HarelM
Copy link
Collaborator

HarelM commented Aug 24, 2024

Hu?
Can you link to it?

@chrneumann
Copy link
Contributor Author

chrneumann commented Aug 28, 2024

@HarelM
Copy link
Collaborator

HarelM commented Aug 28, 2024

Are you sure you have submitted your response?
This is what I see on my side:
image

@chrneumann
Copy link
Contributor Author

Are you sure you have submitted your response?

Ok, sorry, I did not submit the review.

@HarelM
Copy link
Collaborator

HarelM commented Sep 14, 2024

Ok, looks good, can you check why the test is failing?

@chrneumann
Copy link
Contributor Author

Ok, looks good, can you check why the test is failing?

Fixed that, a render test failed because of the readded buffer between terrain surface and camera.

@HarelM
Copy link
Collaborator

HarelM commented Sep 19, 2024

Should this PR still be in draft mode?

@chrneumann chrneumann marked this pull request as ready for review September 19, 2024 16:29
@HarelM
Copy link
Collaborator

HarelM commented Sep 19, 2024

Can you please add a changelog entry?

@chrneumann
Copy link
Contributor Author

Done. New transform stuff also merged.

src/geo/transform.ts Outdated Show resolved Hide resolved
@HarelM
Copy link
Collaborator

HarelM commented Sep 30, 2024

Looking at the fact that you added code without a failing test can indicate that the added code in the transform class is not covered by tests?

@chrneumann
Copy link
Contributor Author

Yes, the try/catch is not covered by a test. We talked about that before: #4551 (comment) Best would be to have more insights from someone who knows more about the recalculation code. Not sure, if you got a reply? But yeah, I could also try to crash it and find out which values lead to the crash and add a test with these values. But knowing why it crashes in the first place would be better.

@HarelM
Copy link
Collaborator

HarelM commented Oct 1, 2024

Did you push the commit? I still see that the code coverage is not getting to this catch block...

@chrneumann
Copy link
Contributor Author

No, did you see the discussion at #4551 (comment) ?

@HarelM
Copy link
Collaborator

HarelM commented Oct 1, 2024

Yes, regardless of if the solution is an "if" or a try-catch, there's a need to add a test the reproduces this issue (I think a unit test is the right kind of test here, but I don't mind either way).
Once you have a scenario that can be reproduced we can better talk about the solution, I believe.

@chrneumann
Copy link
Contributor Author

I can't reproduce the crash any more in the current main branch. Still kept the added surface padding (camera stays not directly on the ground), as it prevents some graphic glitches.

But there seems to be a regression with the transformCameraUpdate. Possibly because the camera transform is updated in the new changes without considering this option. Needs a closer look.

@chrneumann
Copy link
Contributor Author

But there seems to be a regression with the transformCameraUpdate. Possibly because the camera transform is updated in the new changes without considering this option. Needs a closer look.

Started with 5.0.0-pre.4

@HarelM
Copy link
Collaborator

HarelM commented Oct 31, 2024

@NathanMOlson is this change problematic for what you are working on?
I think this is a good addition to the camera elevation logic, but it might complicate things for your use case.
@chrneumann is this ready to me merged?

HarelM
HarelM previously approved these changes Oct 31, 2024
@chrneumann
Copy link
Contributor Author

@chrneumann is this ready to me merged?

Yes, it's ready.

@@ -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

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.

if (!this.terrain && tr.elevation >= 0 && tr.pitch <= 90) {
return {};
}
const surfacePadding = Math.min(500, 20 * (25 - tr.zoom));
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.

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

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).

@HarelM HarelM dismissed their stale review October 31, 2024 19:21

More comments

@HarelM
Copy link
Collaborator

HarelM commented Oct 31, 2024

Thanks @NathanMOlson! These are interesting questions and observations.

@Samarth1696
Copy link
Contributor

Tbh I would like to disable this feature for the use case for aircraft. Currently motion control works with jumpTo() in every frame. From what I have seen from my work of motion control that the camera goes under the terrain regardless of elevateCameraIfInsideTerrain is being called, this is because of jumpTo() I think. This feature would be correct for the use case for normal users but things might go wrong for aircraft motion control use case.

We can have a on and off switch for this feature where the user can choose between going under the terrain and not going under it. I know for the default UX no one wants to go under the Terrain but we have to find a solution for the aircraft use case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants