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

Recreate OSM viewer with Bevy #1038

Draft
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

matthieu-foucault
Copy link
Contributor

Day 1: lost way too much time because I tried using dynamic linking, but I have meshes

image

Copy link
Collaborator

@dabreegster dabreegster left a comment

Choose a reason for hiding this comment

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

Super cool to see this come together! Things like the pancam plugin really reduce common effort

let mut builder = PolygonMeshBuilder::new();
// Call `add_earcutr_input` or each polygon you want in the mesh.
builder.add_earcutr_input(EarcutrInput {
vertices: poly
Copy link
Collaborator

Choose a reason for hiding this comment

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

In case it's useful later for polygons with holes, there's a way to run earcutr and get vertices + indices already: geom::Tessellation::from(polygon).consume()

if let Some(mesh) = builder.build() {
commands.spawn(MaterialMesh2dBundle {
mesh: meshes.add(Mesh::from(mesh)).into(),
material: materials.add(ColorMaterial::from(Color::PURPLE)),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do you know if there's always one material per mesh in Bevy, or is there an easy way to specify material through per-vertex attributes? I could imagine cases where both could be useful

Copy link
Collaborator

Choose a reason for hiding this comment

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

@matthieu-foucault
Copy link
Contributor Author

Progress screenshot with road color and intersections.

image

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.

@Zireael07
Copy link

Suggestion: don't change the model, just invert when displaying in Bevy?

@dabreegster
Copy link
Collaborator

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 Pt2Ds to Bevy-land.

@matthieu-foucault
Copy link
Contributor Author

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

@matthieu-foucault
Copy link
Contributor Author

matthieu-foucault commented Dec 22, 2022

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;
}

@matthieu-foucault
Copy link
Contributor Author

👋 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!

@dabreegster
Copy link
Collaborator

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!

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

Successfully merging this pull request may close these issues.

None yet

3 participants