abstreet
abstreet copied to clipboard
Recreate OSM viewer with Bevy
Day 1: lost way too much time because I tried using dynamic linking, but I have meshes
Progress screenshot with road color and intersections.
I've hit a blocker: I noticed that the map is flipped vertically, because Bevy's coordinate system is inverted compared to A/B streets'. I asked on discord to see if there's a Bevy way to fix this, but let me know if you can think of a small change to the map model that would solve this issue.
Suggestion: don't change the model, just invert when displaying in Bevy?
Awesome progress! I'm quite curious to see what the Bevy patterns for lazily rendering the high-zoom details will look like. I also got curious about Bevy and started some experiments. Even if something isn't possible yet, the process for making a new general-purpose plugin is pretty lightweight, and the effort helps any other Bevy project out there.
Someone in the Discord suggested a -1
transform... I'd also maybe expect that to work. Not sure how the 2D renderer works, but maybe we need to try double_sided
or cull_mode: None
with https://docs.rs/bevy/latest/bevy/pbr/struct.StandardMaterial.html in case the camera / lighting doesn't understand the flipped things.
As a workaround, what if we do this transformation in the RoadBundle
code? We could do something like map_model.get_bounds().max_y - y
when transforming all of the Pt2D
s to Bevy-land.
I saw you started experimenting with bevy and made some notes about using bevy_earcutr
, that's why I started using it :) .
The solution, whether we're using a transform or map_model.get_bounds().max_y - y
(which I had both tried), is to reverse the order of the vertices in the earcutr
output.
Using double_sided
or cull_mode: None
were not valid options as StandardMaterial
doesn't implement Material2d
I'm quite curious to see what the Bevy patterns for lazily rendering the high-zoom details will look like.
I have a simple implementation where the details layer visibility is changed depending on the zoom level. All the entities are spawned at startup, and toggling visibility is as simple as adding the following system
pub fn toggle_details_visibility(
camera_projection: Query<&OrthographicProjection, With<Camera2d>>,
mut details_visibility: Query<&mut Visibility, With<DetailsLayer>>,
) {
details_visibility.single_mut().is_visible = camera_projection.single().scale < 0.75;
}
:wave: Just a status update: I have a new full time commitment and won't have time to contribute more to this branch. Hopefully some of this exploration is useful for the future of this project. Best of luck with the year ahead!
Thanks for the heads up and for all you've done here! I'll leave the PR open as a draft for now, and maybe get it a little further along and merge if I have time, or wait for someone else to pick it up. Enjoy your new job!