Blink moving lights' meshes on and off.
This commit is contained in:
parent
718884a8da
commit
13543a6553
2 changed files with 43 additions and 17 deletions
|
@ -3,10 +3,11 @@ use bevy::{
|
|||
prelude::*,
|
||||
render::{options::WgpuOptions, render_resource::WgpuFeatures},
|
||||
};
|
||||
use rand::{thread_rng, Rng};
|
||||
|
||||
use crate::geometry::CyberSphere;
|
||||
use crate::{geometry::CyberSphere, lights::AnimateCyberLightWireframe};
|
||||
|
||||
fn wireframe(
|
||||
fn wireframe_planet(
|
||||
mut commands: Commands,
|
||||
mut wireframe_config: ResMut<WireframeConfig>,
|
||||
query: Query<Entity, With<CyberSphere>>,
|
||||
|
@ -16,6 +17,26 @@ fn wireframe(
|
|||
commands.entity(ent).insert(Wireframe);
|
||||
}
|
||||
|
||||
fn wireframify_lights(
|
||||
mut commands: Commands,
|
||||
no_wires: Query<Entity, (With<AnimateCyberLightWireframe>, Without<Wireframe>)>,
|
||||
wires: Query<Entity, (With<AnimateCyberLightWireframe>, With<Wireframe>)>,
|
||||
) {
|
||||
let chance = 0.005;
|
||||
|
||||
let rng = &mut thread_rng();
|
||||
for e in no_wires.iter() {
|
||||
if rng.gen::<f32>() < chance {
|
||||
commands.entity(e).insert(Wireframe);
|
||||
}
|
||||
}
|
||||
for e in wires.iter() {
|
||||
if rng.gen::<f32>() < chance {
|
||||
commands.entity(e).remove::<Wireframe>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// public plugin
|
||||
pub struct CyberGlamorPlugin;
|
||||
impl Plugin for CyberGlamorPlugin {
|
||||
|
@ -24,7 +45,8 @@ impl Plugin for CyberGlamorPlugin {
|
|||
features: WgpuFeatures::POLYGON_MODE_LINE,
|
||||
..Default::default()
|
||||
})
|
||||
.add_startup_system_to_stage(StartupStage::PostStartup, wireframe)
|
||||
.add_startup_system_to_stage(StartupStage::PostStartup, wireframe_planet)
|
||||
.add_system(wireframify_lights)
|
||||
.add_plugin(WireframePlugin);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,9 @@ struct AnimatedCyberLight {
|
|||
rate: f32,
|
||||
}
|
||||
|
||||
#[derive(Component)]
|
||||
pub(crate) struct AnimateCyberLightWireframe;
|
||||
|
||||
fn spawn_lights(
|
||||
mut commands: Commands,
|
||||
mut meshes: ResMut<Assets<Mesh>>,
|
||||
|
@ -45,8 +48,8 @@ fn spawn_lights(
|
|||
// spawn 200 orbiting bisexual lights
|
||||
for _ in 0..255 {
|
||||
let hue = rng.gen_range(260.0..320.0);
|
||||
let saturation = rng.gen_range(0.8..0.95);
|
||||
let lightness = rng.gen_range(0.4..0.7);
|
||||
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);
|
||||
|
@ -85,19 +88,20 @@ fn spawn_lights(
|
|||
..Default::default()
|
||||
})
|
||||
.with_children(|builder| {
|
||||
builder.spawn_bundle(PbrBundle {
|
||||
mesh: meshes.add(Mesh::from(shape::Icosphere {
|
||||
radius,
|
||||
subdivisions: 2,
|
||||
})),
|
||||
|
||||
material: materials.add(StandardMaterial {
|
||||
base_color: color,
|
||||
emissive: color,
|
||||
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()
|
||||
}),
|
||||
..Default::default()
|
||||
});
|
||||
})
|
||||
.insert(AnimateCyberLightWireframe);
|
||||
}); // mesh child
|
||||
}); // light child
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue