neuter glamor

This commit is contained in:
Joe Ardent 2023-03-10 11:45:01 -08:00
parent a4c268f72d
commit b8751a7374
6 changed files with 42 additions and 184 deletions

View file

@ -26,7 +26,7 @@ features = [
"bevy_ui",
"bevy_text",
"bevy_gltf",
"bevy_sprite"
"bevy_sprite",
]
[dependencies.bevy_rapier3d]

View file

@ -43,15 +43,32 @@ fn setup_cybercams(mut commands: Commands) {
fov: std::f32::consts::FRAC_PI_3,
..Default::default()
};
let fog_settings = FogSettings {
color: Color::rgba(0.1, 0.2, 0.4, 1.0),
directional_light_color: Color::rgba(1.0, 0.95, 0.75, 0.5),
directional_light_exponent: 30.0,
falloff: FogFalloff::from_visibility_colors(
350.0, /* distance in world units up to which objects retain visibility (>= 5%
* contrast) */
Color::rgb(0.35, 0.5, 0.66), /* atmospheric extinction color (after light is lost
* due to absorption by atmospheric particles) */
Color::rgb(0.8, 0.844, 1.0), /* atmospheric inscattering color (light gained due to
* scattering from the sun) */
),
};
commands
.spawn(Camera3dBundle {
projection: bevy::render::camera::Projection::Perspective(hero_projection),
..Default::default()
})
.insert(fog_settings.clone())
.insert(CyberCameras::Hero);
commands
.spawn(Camera3dBundle::default())
.insert(fog_settings)
.insert(CyberCameras::Debug);
}

View file

@ -1,80 +1,13 @@
use bevy::{
prelude::*,
render::mesh::{Indices, VertexAttributeValues},
};
// use bevy_polyline::prelude::{Polyline, PolylineBundle, PolylineMaterial, PolylinePlugin};
use rand::{thread_rng, Rng};
use bevy::prelude::{App, Color, Plugin};
use crate::{lights::AnimateCyberLightWireframe, planet::CyberPlanet};
// use crate::planet::CyberPlanet;
pub const BISEXY_COLOR: Color = Color::hsla(292.0, 0.9, 0.60, 1.1);
// fn wireframe_planet(
// mut commands: Commands,
// mut meshes: ResMut<Assets<Mesh>>,
// mut polylines: ResMut<Assets<Polyline>>,
// mut polymats: ResMut<Assets<PolylineMaterial>>,
// query: Query<&Handle<Mesh>, With<CyberPlanet>>,
// ) {
// let handle = query.single();
// let mesh = meshes.get_mut(handle).unwrap();
// let vertices = mesh.attribute(Mesh::ATTRIBUTE_POSITION).unwrap();
// let mut pts = Vec::with_capacity(vertices.len());
// if let VertexAttributeValues::Float32x3(verts) = vertices {
// let indices = mesh.indices().unwrap();
// if let Indices::U32(indices) = indices {
// for i in indices.iter() {
// let v = verts[*i as usize];
// let v = Vec3::from_slice(&v);
// pts.push(v);
// }
// }
// }
// let mut verts = Vec::with_capacity((pts.len() as f32 * 1.4) as usize);
// for pts in pts.chunks(3) {
// if pts.len() > 1 {
// verts.extend_from_slice(pts);
// verts.push(Vec3::NAN);
// }
// }
// // don't need the indices anymore
// mesh.duplicate_vertices();
// mesh.compute_flat_normals();
// commands.spawn(PolylineBundle {
// polyline: polylines.add(Polyline { vertices: verts }),
// material: polymats.add(PolylineMaterial {
// width: 101.0,
// color: BISEXY_COLOR,
// perspective: true,
// depth_bias: -0.001,
// }),
// ..Default::default()
// });
// }
fn wireframify_lights(mut lights: Query<&mut AnimateCyberLightWireframe>) {
let chance = 0.005;
let rng = &mut thread_rng();
for mut light in lights.iter_mut() {
if rng.gen::<f32>() < chance {
let new = !light.wired;
light.wired = new;
}
}
}
// public plugin
pub struct CyberGlamorPlugin;
impl Plugin for CyberGlamorPlugin {
fn build(&self, app: &mut App) {
#[cfg(feature = "inspector")]
{
use bevy_rapier3d::render::{
DebugRenderMode, DebugRenderStyle, RapierDebugRenderPlugin,
@ -97,7 +30,5 @@ impl Plugin for CyberGlamorPlugin {
app.add_plugin(rplugin);
}
app.add_system(wireframify_lights);
}
}

View file

@ -1,99 +1,9 @@
use std::f32::consts::TAU;
use bevy::prelude::*;
use rand::prelude::*;
use bevy::{pbr::CascadeShadowConfigBuilder, prelude::*};
use crate::planet::PLANET_RADIUS;
pub const LIGHT_RANGE: f32 = 90.0;
#[derive(Component)]
struct AnimatedCyberLight {
axis: Vec3,
rate: f32,
}
#[derive(Component, Default)]
pub(crate) struct AnimateCyberLightWireframe {
pub wired: bool,
}
fn spawn_moving_lights(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
let rng = &mut thread_rng();
// spawn orbiting bisexual lights
for _ in 0..655 {
// mechanics
let axis = crate::random_unit_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(900.0..1300.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()
};
let sbundle = SpatialBundle {
transform: Transform::from_rotation(rotation),
..Default::default()
};
commands
// first, spawn an entity with a transform we can rotate
.spawn((AnimatedCyberLight { axis, rate },))
.insert(sbundle)
.with_children(|parent| {
parent
// now spawn a child entity with a pointlight, and a relative transform that's
// just translation from the parent
.spawn(PointLightBundle {
transform,
point_light,
..Default::default()
})
.with_children(|builder| {
builder
// now a simple mesh to show a wireframe.
.spawn(PbrBundle {
mesh: meshes.add(
Mesh::try_from(shape::Icosphere {
radius,
subdivisions: 1,
})
.unwrap(),
),
material: materials.add(StandardMaterial {
base_color: Color::hsla(272.0, 0.7, 0.56, 0.7),
emissive: color,
..Default::default()
}),
..Default::default()
})
.insert(AnimateCyberLightWireframe::default());
}); // mesh child
}); // light child
}
}
fn spawn_static_lights(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
@ -122,6 +32,13 @@ fn spawn_static_lights(
brightness: 0.2,
});
let _cascade_shadow_config = CascadeShadowConfigBuilder {
first_cascade_far_bound: 0.3,
maximum_distance: 3.0,
..default()
}
.build();
// up light
commands
.spawn(PointLightBundle {
@ -172,20 +89,9 @@ fn spawn_static_lights(
});
}
fn orbit_lights(time: Res<Time>, mut query: Query<(&mut Transform, &AnimatedCyberLight)>) {
let dt = time.delta_seconds();
for (mut transform, light) in query.iter_mut() {
let AnimatedCyberLight { axis, rate } = *light;
let theta = rate * dt;
transform.rotation *= Quat::from_axis_angle(axis, theta);
}
}
pub struct CyberSpaceLightsPlugin;
impl Plugin for CyberSpaceLightsPlugin {
fn build(&self, app: &mut App) {
app.add_startup_system(spawn_static_lights)
.add_startup_system(spawn_moving_lights)
.add_system(orbit_lights);
app.add_startup_system(spawn_static_lights);
}
}

View file

@ -1,12 +1,14 @@
use bevy::prelude::*;
#[cfg(feature = "inspector")]
use cyber_rider::glamor::CyberGlamorPlugin;
use cyber_rider::{
action::CyberActionPlugin, bike::CyberBikePlugin, camera::CyberCamPlugin, disable_mouse_trap,
glamor::CyberGlamorPlugin, input::CyberInputPlugin, lights::CyberSpaceLightsPlugin,
planet::CyberPlanetPlugin, ui::CyberUIPlugin,
input::CyberInputPlugin, lights::CyberSpaceLightsPlugin, planet::CyberPlanetPlugin,
ui::CyberUIPlugin,
};
const CYBER_SKY: Color = Color::rgb(0.07, 0.001, 0.02);
// const CYBER_SKY: Color = Color::rgb(0.64, 0.745, 0.937); // a light blue sky
//const CYBER_SKY: Color = Color::rgb(0.07, 0.001, 0.02);
const CYBER_SKY: Color = Color::rgb(0.64, 0.745, 0.937); // a light blue sky
fn main() {
let mut app = App::new();
@ -20,7 +22,6 @@ fn main() {
..Default::default()
}))
.add_plugin(CyberPlanetPlugin)
.add_plugin(CyberGlamorPlugin)
.add_plugin(CyberInputPlugin)
.add_plugin(CyberActionPlugin)
.add_plugin(CyberCamPlugin)
@ -30,5 +31,8 @@ fn main() {
.add_startup_system(disable_mouse_trap)
.add_system(bevy::window::close_on_esc);
#[cfg(feature = "inspector")]
app.add_plugin(CyberGlamorPlugin);
app.run();
}

View file

@ -19,7 +19,7 @@ fn spawn_planet(
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
let color = Color::rgb(0.2, 0.1, 0.2);
let color = Color::rgb(0.74, 0.5334, 0.176);
let isphere = Icosphere {
radius: PLANET_RADIUS,
subdivisions: 88,
@ -43,9 +43,9 @@ fn spawn_planet(
mesh: meshes.add(mesh),
material: materials.add(StandardMaterial {
base_color: color,
metallic: 0.1,
metallic: 0.3,
perceptual_roughness: 0.3,
alpha_mode: AlphaMode::Opaque,
//alpha_mode: AlphaMode::Opaque,
..Default::default()
}),
@ -86,7 +86,7 @@ fn gen_planet(sphere: Icosphere) -> (Mesh, Collider) {
.raw_points()
.iter()
.map(|&p| {
let disp = noise.get(p.as_dvec3().into()) as f32 * 0.04;
let disp = noise.get(p.as_dvec3().into()) as f32 * 0.01;
let pt = p + (p.normalize() * disp);
pt.into()
})