2023-03-10 19:45:01 +00:00
|
|
|
use bevy::{pbr::CascadeShadowConfigBuilder, prelude::*};
|
2022-01-12 08:18:13 +00:00
|
|
|
|
2022-03-13 00:06:36 +00:00
|
|
|
use crate::planet::PLANET_RADIUS;
|
2022-01-12 08:18:13 +00:00
|
|
|
|
2022-01-29 21:31:15 +00:00
|
|
|
pub const LIGHT_RANGE: f32 = 90.0;
|
2022-01-12 08:18:13 +00:00
|
|
|
|
2022-01-19 23:07:24 +00:00
|
|
|
fn spawn_static_lights(
|
|
|
|
mut commands: Commands,
|
|
|
|
mut meshes: ResMut<Assets<Mesh>>,
|
|
|
|
mut materials: ResMut<Assets<StandardMaterial>>,
|
|
|
|
) {
|
|
|
|
let pink_light = PointLight {
|
|
|
|
intensity: 1_00.0,
|
|
|
|
range: LIGHT_RANGE,
|
|
|
|
color: Color::PINK,
|
|
|
|
radius: 1.0,
|
|
|
|
shadows_enabled: true,
|
|
|
|
..Default::default()
|
|
|
|
};
|
|
|
|
|
|
|
|
let blue_light = PointLight {
|
|
|
|
intensity: 1_000.0,
|
|
|
|
range: LIGHT_RANGE,
|
|
|
|
color: Color::BLUE,
|
|
|
|
radius: 1.0,
|
|
|
|
shadows_enabled: true,
|
|
|
|
..Default::default()
|
|
|
|
};
|
|
|
|
|
|
|
|
commands.insert_resource(AmbientLight {
|
|
|
|
color: Color::WHITE,
|
2022-02-21 21:08:49 +00:00
|
|
|
brightness: 0.2,
|
2022-01-19 23:07:24 +00:00
|
|
|
});
|
2022-01-19 04:08:47 +00:00
|
|
|
|
2023-03-10 19:45:01 +00:00
|
|
|
let _cascade_shadow_config = CascadeShadowConfigBuilder {
|
|
|
|
first_cascade_far_bound: 0.3,
|
|
|
|
maximum_distance: 3.0,
|
|
|
|
..default()
|
|
|
|
}
|
|
|
|
.build();
|
|
|
|
|
2022-01-12 08:18:13 +00:00
|
|
|
// up light
|
|
|
|
commands
|
2023-01-20 22:40:51 +00:00
|
|
|
.spawn(PointLightBundle {
|
2023-02-23 01:10:36 +00:00
|
|
|
transform: Transform::from_xyz(0.0, PLANET_RADIUS + 30.0, 0.0),
|
2022-01-19 04:08:47 +00:00
|
|
|
point_light: pink_light,
|
2022-01-12 08:18:13 +00:00
|
|
|
..Default::default()
|
|
|
|
})
|
|
|
|
.with_children(|builder| {
|
2023-01-20 22:40:51 +00:00
|
|
|
builder.spawn(PbrBundle {
|
2023-03-10 01:50:14 +00:00
|
|
|
mesh: meshes.add(
|
|
|
|
Mesh::try_from(shape::Icosphere {
|
|
|
|
radius: 10.0,
|
|
|
|
subdivisions: 2,
|
|
|
|
})
|
|
|
|
.unwrap(),
|
|
|
|
),
|
2022-01-12 08:18:13 +00:00
|
|
|
material: materials.add(StandardMaterial {
|
2022-01-19 23:07:24 +00:00
|
|
|
base_color: Color::BLUE,
|
|
|
|
emissive: Color::PINK,
|
2022-01-12 08:18:13 +00:00
|
|
|
..Default::default()
|
|
|
|
}),
|
|
|
|
..Default::default()
|
|
|
|
});
|
|
|
|
});
|
|
|
|
// down light
|
|
|
|
commands
|
2023-01-20 22:40:51 +00:00
|
|
|
.spawn(PointLightBundle {
|
2023-02-23 01:10:36 +00:00
|
|
|
transform: Transform::from_xyz(0.0, -PLANET_RADIUS - 30.0, 0.0),
|
2022-01-12 08:18:13 +00:00
|
|
|
point_light: blue_light,
|
|
|
|
..Default::default()
|
|
|
|
})
|
|
|
|
.with_children(|builder| {
|
2023-01-20 22:40:51 +00:00
|
|
|
builder.spawn(PbrBundle {
|
2023-03-10 01:50:14 +00:00
|
|
|
mesh: meshes.add(
|
|
|
|
Mesh::try_from(shape::Icosphere {
|
|
|
|
radius: 10.0,
|
|
|
|
subdivisions: 2,
|
|
|
|
})
|
|
|
|
.unwrap(),
|
|
|
|
),
|
2022-01-12 08:18:13 +00:00
|
|
|
material: materials.add(StandardMaterial {
|
2022-01-19 23:07:24 +00:00
|
|
|
base_color: Color::PINK,
|
|
|
|
emissive: Color::BLUE,
|
2022-01-12 08:18:13 +00:00
|
|
|
..Default::default()
|
|
|
|
}),
|
|
|
|
..Default::default()
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-01-14 00:14:08 +00:00
|
|
|
pub struct CyberSpaceLightsPlugin;
|
|
|
|
impl Plugin for CyberSpaceLightsPlugin {
|
|
|
|
fn build(&self, app: &mut App) {
|
2024-06-13 20:00:39 +00:00
|
|
|
app.add_systems(Startup, spawn_static_lights);
|
2022-01-14 00:14:08 +00:00
|
|
|
}
|
|
|
|
}
|