Re-org the lights, tweak the colors.
This commit is contained in:
parent
13543a6553
commit
5978191691
2 changed files with 81 additions and 70 deletions
|
@ -3,7 +3,7 @@ use heron::prelude::{CollisionShape, RigidBody};
|
||||||
|
|
||||||
use crate::Label;
|
use crate::Label;
|
||||||
|
|
||||||
pub const PLANET_RADIUS: f32 = 340.0;
|
pub const PLANET_RADIUS: f32 = 360.0;
|
||||||
pub(crate) const SPAWN_ALTITUDE: f32 = PLANET_RADIUS + 100.0;
|
pub(crate) const SPAWN_ALTITUDE: f32 = PLANET_RADIUS + 100.0;
|
||||||
|
|
||||||
#[derive(Component, Debug)]
|
#[derive(Component, Debug)]
|
||||||
|
@ -21,7 +21,7 @@ fn spawn_giant_sphere(
|
||||||
.spawn_bundle(PbrBundle {
|
.spawn_bundle(PbrBundle {
|
||||||
mesh: meshes.add(Mesh::from(shape::Icosphere {
|
mesh: meshes.add(Mesh::from(shape::Icosphere {
|
||||||
radius: PLANET_RADIUS,
|
radius: PLANET_RADIUS,
|
||||||
subdivisions: 8,
|
subdivisions: 32,
|
||||||
})),
|
})),
|
||||||
material: materials.add(StandardMaterial {
|
material: materials.add(StandardMaterial {
|
||||||
base_color: Color::GRAY,
|
base_color: Color::GRAY,
|
||||||
|
|
147
src/lights.rs
147
src/lights.rs
|
@ -16,7 +16,79 @@ struct AnimatedCyberLight {
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
pub(crate) struct AnimateCyberLightWireframe;
|
pub(crate) struct AnimateCyberLightWireframe;
|
||||||
|
|
||||||
fn spawn_lights(
|
fn spawn_moving_lights(
|
||||||
|
mut commands: Commands,
|
||||||
|
mut meshes: ResMut<Assets<Mesh>>,
|
||||||
|
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||||
|
) {
|
||||||
|
let rng = &mut thread_rng();
|
||||||
|
// spawn 200 orbiting bisexual lights
|
||||||
|
for _ in 0..255 {
|
||||||
|
// mechanics
|
||||||
|
let axis = crate::random_sphere_vec(rng);
|
||||||
|
let angle = rng.gen_range(0.0..TAU);
|
||||||
|
let rate: f32 = rng.gen_range(7.0..10.0);
|
||||||
|
let rate = rate.to_radians();
|
||||||
|
let rotation = Quat::from_axis_angle(axis, angle);
|
||||||
|
let altitude = PLANET_RADIUS + rng.gen_range(8.0..20.0);
|
||||||
|
let perp = axis.any_orthonormal_vector();
|
||||||
|
let translation = perp * altitude;
|
||||||
|
let transform = Transform::from_translation(translation);
|
||||||
|
|
||||||
|
// optics
|
||||||
|
let hue = rng.gen_range(240.0..300.0);
|
||||||
|
let saturation = rng.gen_range(0.85..0.99);
|
||||||
|
let lightness = rng.gen_range(0.3..0.7);
|
||||||
|
let color = Color::hsl(hue, saturation, lightness);
|
||||||
|
let intensity = rng.gen_range(500.0..900.0);
|
||||||
|
let radius = rng.gen::<f32>() * 2.2; // why can't this infer the gen type?
|
||||||
|
let point_light = PointLight {
|
||||||
|
intensity,
|
||||||
|
range: LIGHT_RANGE,
|
||||||
|
color,
|
||||||
|
radius: radius - 0.1,
|
||||||
|
shadows_enabled: true,
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
commands
|
||||||
|
// first, spawn an entity with a transform we can rotate
|
||||||
|
.spawn_bundle((
|
||||||
|
AnimatedCyberLight { axis, rate },
|
||||||
|
Transform::from_rotation(rotation),
|
||||||
|
GlobalTransform::default(),
|
||||||
|
))
|
||||||
|
.with_children(|parent| {
|
||||||
|
parent
|
||||||
|
// now spawn a child entity with a pointlight, and a relative transform that's
|
||||||
|
// just translation from the parent
|
||||||
|
.spawn_bundle(PointLightBundle {
|
||||||
|
transform,
|
||||||
|
point_light,
|
||||||
|
..Default::default()
|
||||||
|
})
|
||||||
|
.with_children(|builder| {
|
||||||
|
builder
|
||||||
|
// now a simple mesh to show a wireframe.
|
||||||
|
.spawn_bundle(PbrBundle {
|
||||||
|
mesh: meshes.add(Mesh::from(shape::Icosphere {
|
||||||
|
radius,
|
||||||
|
subdivisions: 1,
|
||||||
|
})),
|
||||||
|
material: materials.add(StandardMaterial {
|
||||||
|
base_color: Color::hsla(272.0, 0.7, 0.56, 0.7),
|
||||||
|
emissive: color,
|
||||||
|
..Default::default()
|
||||||
|
}),
|
||||||
|
..Default::default()
|
||||||
|
})
|
||||||
|
.insert(AnimateCyberLightWireframe);
|
||||||
|
}); // mesh child
|
||||||
|
}); // light child
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn spawn_static_lights(
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
mut meshes: ResMut<Assets<Mesh>>,
|
mut meshes: ResMut<Assets<Mesh>>,
|
||||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||||
|
@ -44,68 +116,6 @@ fn spawn_lights(
|
||||||
brightness: 0.32,
|
brightness: 0.32,
|
||||||
});
|
});
|
||||||
|
|
||||||
let rng = &mut thread_rng();
|
|
||||||
// spawn 200 orbiting bisexual lights
|
|
||||||
for _ in 0..255 {
|
|
||||||
let hue = rng.gen_range(260.0..320.0);
|
|
||||||
let saturation = rng.gen_range(0.85..0.99);
|
|
||||||
let lightness = rng.gen_range(0.3..0.7);
|
|
||||||
let color = Color::hsl(hue, saturation, lightness);
|
|
||||||
|
|
||||||
let axis = crate::random_sphere_vec(rng);
|
|
||||||
let angle = rng.gen_range(0.0..TAU);
|
|
||||||
let rate: f32 = rng.gen_range(7.0..10.0);
|
|
||||||
let rate = rate.to_radians();
|
|
||||||
let rotation = Quat::from_axis_angle(axis, angle);
|
|
||||||
|
|
||||||
let altitude = PLANET_RADIUS + rng.gen_range(8.0..20.0);
|
|
||||||
let perp = axis.any_orthonormal_vector();
|
|
||||||
let translation = perp * altitude;
|
|
||||||
let transform = Transform::from_translation(translation);
|
|
||||||
|
|
||||||
let intensity = rng.gen_range(500.0..900.0);
|
|
||||||
let radius = rng.gen::<f32>() * 2.5; // why can't this infer the gen type?
|
|
||||||
let point_light = PointLight {
|
|
||||||
intensity,
|
|
||||||
range: LIGHT_RANGE,
|
|
||||||
color,
|
|
||||||
radius,
|
|
||||||
shadows_enabled: true,
|
|
||||||
..Default::default()
|
|
||||||
};
|
|
||||||
|
|
||||||
commands
|
|
||||||
.spawn_bundle((
|
|
||||||
AnimatedCyberLight { axis, rate },
|
|
||||||
Transform::from_rotation(rotation),
|
|
||||||
GlobalTransform::default(),
|
|
||||||
))
|
|
||||||
.with_children(|parent| {
|
|
||||||
parent
|
|
||||||
.spawn_bundle(PointLightBundle {
|
|
||||||
transform,
|
|
||||||
point_light,
|
|
||||||
..Default::default()
|
|
||||||
})
|
|
||||||
.with_children(|builder| {
|
|
||||||
builder
|
|
||||||
.spawn_bundle(PbrBundle {
|
|
||||||
mesh: meshes.add(Mesh::from(shape::Icosphere {
|
|
||||||
radius,
|
|
||||||
subdivisions: 1,
|
|
||||||
})),
|
|
||||||
material: materials.add(StandardMaterial {
|
|
||||||
base_color: color,
|
|
||||||
emissive: color,
|
|
||||||
..Default::default()
|
|
||||||
}),
|
|
||||||
..Default::default()
|
|
||||||
})
|
|
||||||
.insert(AnimateCyberLightWireframe);
|
|
||||||
}); // mesh child
|
|
||||||
}); // light child
|
|
||||||
}
|
|
||||||
|
|
||||||
// up light
|
// up light
|
||||||
commands
|
commands
|
||||||
.spawn_bundle(PointLightBundle {
|
.spawn_bundle(PointLightBundle {
|
||||||
|
@ -120,8 +130,8 @@ fn spawn_lights(
|
||||||
subdivisions: 2,
|
subdivisions: 2,
|
||||||
})),
|
})),
|
||||||
material: materials.add(StandardMaterial {
|
material: materials.add(StandardMaterial {
|
||||||
base_color: Color::RED,
|
base_color: Color::BLUE,
|
||||||
emissive: Color::rgba_linear(100.0, 0.0, 0.0, 0.0),
|
emissive: Color::PINK,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
@ -141,8 +151,8 @@ fn spawn_lights(
|
||||||
subdivisions: 2,
|
subdivisions: 2,
|
||||||
})),
|
})),
|
||||||
material: materials.add(StandardMaterial {
|
material: materials.add(StandardMaterial {
|
||||||
base_color: Color::BLUE,
|
base_color: Color::PINK,
|
||||||
emissive: Color::rgba_linear(0.0, 0.0, 100.0, 0.0),
|
emissive: Color::BLUE,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
@ -162,7 +172,8 @@ fn orbit_lights(time: Res<Time>, mut query: Query<(&mut Transform, &AnimatedCybe
|
||||||
pub struct CyberSpaceLightsPlugin;
|
pub struct CyberSpaceLightsPlugin;
|
||||||
impl Plugin for CyberSpaceLightsPlugin {
|
impl Plugin for CyberSpaceLightsPlugin {
|
||||||
fn build(&self, app: &mut App) {
|
fn build(&self, app: &mut App) {
|
||||||
app.add_startup_system(spawn_lights)
|
app.add_startup_system(spawn_static_lights)
|
||||||
|
.add_startup_system(spawn_moving_lights)
|
||||||
.add_system(orbit_lights);
|
.add_system(orbit_lights);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue