Skip to content
6 changes: 6 additions & 0 deletions examples/large_scenes/bevy_city/src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub struct CityAssets {
pub tree_large: Handle<WorldAsset>,
pub path_stones_long: Handle<WorldAsset>,
pub fence: Handle<WorldAsset>,
pub traffic_lights: Handle<WorldAsset>,
}

impl CityAssets {
Expand Down Expand Up @@ -232,6 +233,10 @@ pub fn load_assets(
GltfAssetLabel::Scene(0).from_asset(format!("{base_url}/city-kit-suburban/fence.glb"))
);

let traffic_lights: Handle<WorldAsset> =
load_asset!(GltfAssetLabel::Scene(0)
.from_asset(format!("{base_url}/city-kit-roads/light-square.glb")));

commands.insert_resource(CityAssets {
untyped_assets,
cars,
Expand All @@ -247,6 +252,7 @@ pub fn load_assets(
tree_large,
path_stones_long,
fence,
traffic_lights,
});
}

Expand Down
20 changes: 20 additions & 0 deletions examples/large_scenes/bevy_city/src/generate_city.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ pub fn spawn_city(commands: &mut Commands, assets: &CityAssets, seed: u64, size:
});
}

#[derive(Component)]
pub struct TrafficLight;

fn spawn_roads_and_cars<R: RngExt>(
commands: &mut ChildSpawnerCommands,
assets: &CityAssets,
Expand Down Expand Up @@ -206,6 +209,23 @@ fn spawn_roads_and_cars<R: RngExt>(
}
}
});
let corners = [
(
Vec3::new(-0.4, 0.0, -0.4),
5.0 * std::f32::consts::FRAC_PI_4,
),
(Vec3::new(0.4, 0.0, -0.4), 3.0 * std::f32::consts::FRAC_PI_4),
(Vec3::new(0.4, 0.0, 0.4), std::f32::consts::FRAC_PI_4),
(Vec3::new(-0.4, 0.0, 0.4), 7.0 * std::f32::consts::FRAC_PI_4),
];
for (pos, rot) in corners {
commands.spawn((
WorldAssetRoot(assets.traffic_lights.clone()),
Transform::from_translation(pos + offset)
.with_rotation(Quat::from_axis_angle(Vec3::Y, rot)),
TrafficLight,
));
}
}

fn spawn_low_density<R: RngExt>(
Expand Down
39 changes: 35 additions & 4 deletions examples/large_scenes/bevy_city/src/settings.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[allow(unused_imports)]
use bevy::{
camera::visibility::NoCpuCulling,
camera_controller::free_camera::FreeCameraState,
Expand All @@ -11,14 +12,20 @@ use bevy::{
ui::Checked,
ui_widgets::{checkbox_self_update, Activate, ValueChange},
};
use rand::RngExt;

#[allow(unused_imports)]
use crate::assets::CityAssets;
use crate::generate_city::{spawn_city, CityRoot};
#[allow(unused_imports)]
use crate::generate_city::{spawn_city, CityRoot, TrafficLight};
#[allow(unused_imports)]
use crate::CitySpawned;
#[allow(unused_imports)]
use rand::RngExt;

#[derive(Resource)]
pub struct Settings {
pub simulate_cars: bool,
pub traffic_lights: bool,
pub shadow_maps_enabled: bool,
pub contact_shadows_enabled: bool,
pub wireframe_enabled: bool,
Expand All @@ -29,6 +36,7 @@ impl Default for Settings {
fn default() -> Self {
Self {
simulate_cars: true,
traffic_lights: true,
shadow_maps_enabled: true,
contact_shadows_enabled: true,
wireframe_enabled: false,
Expand Down Expand Up @@ -90,8 +98,31 @@ pub fn settings_ui() -> impl Scene {
}
)
),
(
@FeathersCheckbox {
(
:FeathersCheckbox {
@caption: {bsn! { Text("Traffic lights") ThemedText }}
}
Checked
on(checkbox_self_update)
on(
|change: On<ValueChange<bool>>,
mut settings: ResMut<Settings>,
mut traffic_light: Query<&mut Visibility, With<TrafficLight>>|
{
settings.traffic_lights = change.value;
let vis = if change.value {
Visibility::Inherited
}
else {
Visibility::Hidden
};
for mut v in &mut traffic_light {
*v = vis;
}
})
),
(
:FeathersCheckbox {
@caption: {bsn! { Text("Contact shadows enabled") ThemedText }}
}
Checked
Expand Down
Loading