- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 355
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
771e166
a725b82
3b5a7f8
f6ba5ff
dda4383
e35c765
6ec1d1e
20e9167
8b14289
ee1674c
e184384
973db8e
f6f4c22
7ff8352
93af6c7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[target.x86_64-unknown-linux-gnu] | ||
linker = "clang" | ||
rustflags = ["-C", "link-arg=-fuse-ld=/usr/bin/mold"] |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
[workspace] | ||
|
||
resolver = "2" | ||
members = [ | ||
"abstio", | ||
"abstutil", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[package] | ||
name = "osm_viewer_bevy" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
bevy_pancam = "0.7.0" | ||
map_model = { path = "../../map_model" } | ||
abstutil = { path = "../../abstutil" } | ||
bevy-earcutr = "0.7.0" | ||
|
||
[dependencies.bevy] | ||
version = "0.9.1" | ||
default-features = true |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
use abstutil; | ||
use bevy::{prelude::*, sprite::MaterialMesh2dBundle}; | ||
use bevy_earcutr::*; | ||
use bevy_pancam::{PanCam, PanCamPlugin}; | ||
use map_model::Map; | ||
|
||
#[derive(Debug, Clone, Eq, PartialEq, Hash)] | ||
enum AppState { | ||
Loading, | ||
Running, | ||
} | ||
|
||
fn main() { | ||
App::new() | ||
.add_plugins(DefaultPlugins) | ||
.add_plugin(PanCamPlugin::default()) | ||
.add_startup_system(setup) | ||
.run(); | ||
} | ||
|
||
fn setup( | ||
mut commands: Commands, | ||
mut meshes: ResMut<Assets<Mesh>>, | ||
mut materials: ResMut<Assets<ColorMaterial>>, | ||
) { | ||
let mut timer = abstutil::time::Timer::new("load_map"); | ||
let map_model = Map::load_synchronously( | ||
"../../data/system/us/seattle/maps/montlake.bin".to_string(), | ||
&mut timer, | ||
); | ||
|
||
for road in map_model.all_roads().iter() { | ||
let poly = road.get_thick_polygon(); | ||
|
||
let mut builder = PolygonMeshBuilder::new(); | ||
// Call `add_earcutr_input` or each polygon you want in the mesh. | ||
builder.add_earcutr_input(EarcutrInput { | ||
vertices: poly | ||
.get_outer_ring() | ||
.points() | ||
.iter() | ||
.flat_map(|p| vec![p.x(), p.y()]) | ||
.collect::<Vec<f64>>(), | ||
interior_indices: vec![], | ||
}); | ||
|
||
if let Some(mesh) = builder.build() { | ||
commands.spawn(MaterialMesh2dBundle { | ||
mesh: meshes.add(Mesh::from(mesh)).into(), | ||
material: materials.add(ColorMaterial::from(Color::PURPLE)), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
..default() | ||
}); | ||
}; | ||
} | ||
|
||
commands.spawn((Camera2dBundle::default(), PanCam::default())); | ||
} |
There was a problem hiding this comment.
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()