2022-01-14 06:05:51 +00:00
|
|
|
use bevy::{
|
|
|
|
prelude::*,
|
2022-03-13 22:54:33 +00:00
|
|
|
render::mesh::{Indices, VertexAttributeValues},
|
2022-01-14 06:05:51 +00:00
|
|
|
};
|
2022-05-08 17:58:48 +00:00
|
|
|
use bevy_polyline::prelude::{Polyline, PolylineBundle, PolylineMaterial, PolylinePlugin};
|
2022-01-19 06:20:58 +00:00
|
|
|
use rand::{thread_rng, Rng};
|
2022-01-14 06:05:51 +00:00
|
|
|
|
2022-03-13 00:06:36 +00:00
|
|
|
use crate::{lights::AnimateCyberLightWireframe, planet::CyberPlanet};
|
2022-01-14 06:05:51 +00:00
|
|
|
|
2022-01-29 21:31:15 +00:00
|
|
|
pub const BISEXY_COLOR: Color = Color::hsla(292.0, 0.9, 0.60, 1.1);
|
|
|
|
|
2022-01-19 06:20:58 +00:00
|
|
|
fn wireframe_planet(
|
2022-01-14 06:05:51 +00:00
|
|
|
mut commands: Commands,
|
2022-02-21 23:42:44 +00:00
|
|
|
mut meshes: ResMut<Assets<Mesh>>,
|
2022-01-26 21:33:48 +00:00
|
|
|
mut polylines: ResMut<Assets<Polyline>>,
|
|
|
|
mut polymats: ResMut<Assets<PolylineMaterial>>,
|
2022-03-02 06:31:44 +00:00
|
|
|
query: Query<&Handle<Mesh>, With<CyberPlanet>>,
|
2022-01-14 06:05:51 +00:00
|
|
|
) {
|
2022-01-26 21:33:48 +00:00
|
|
|
let handle = query.single();
|
2022-02-21 23:42:44 +00:00
|
|
|
let mesh = meshes.get_mut(handle).unwrap();
|
2022-01-26 21:33:48 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-21 21:08:49 +00:00
|
|
|
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);
|
|
|
|
}
|
2022-01-26 21:33:48 +00:00
|
|
|
}
|
2022-02-21 21:08:49 +00:00
|
|
|
|
2022-02-21 23:42:44 +00:00
|
|
|
// don't need the indices anymore
|
|
|
|
mesh.duplicate_vertices();
|
|
|
|
mesh.compute_flat_normals();
|
|
|
|
|
2023-01-20 22:40:51 +00:00
|
|
|
commands.spawn(PolylineBundle {
|
2022-02-21 21:08:49 +00:00
|
|
|
polyline: polylines.add(Polyline { vertices: verts }),
|
|
|
|
material: polymats.add(PolylineMaterial {
|
|
|
|
width: 101.0,
|
|
|
|
color: BISEXY_COLOR,
|
|
|
|
perspective: true,
|
2022-08-13 22:30:37 +00:00
|
|
|
depth_bias: -0.001,
|
2022-02-21 21:08:49 +00:00
|
|
|
}),
|
|
|
|
..Default::default()
|
|
|
|
});
|
2022-01-14 06:05:51 +00:00
|
|
|
}
|
|
|
|
|
2022-03-13 22:54:33 +00:00
|
|
|
fn wireframify_lights(mut lights: Query<&mut AnimateCyberLightWireframe>) {
|
2022-01-19 06:20:58 +00:00
|
|
|
let chance = 0.005;
|
|
|
|
|
|
|
|
let rng = &mut thread_rng();
|
2022-03-13 22:54:33 +00:00
|
|
|
|
|
|
|
for mut light in lights.iter_mut() {
|
2022-01-19 06:20:58 +00:00
|
|
|
if rng.gen::<f32>() < chance {
|
2022-03-13 22:54:33 +00:00
|
|
|
let new = !light.wired;
|
|
|
|
light.wired = new;
|
2022-01-19 06:20:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-14 06:05:51 +00:00
|
|
|
// public plugin
|
|
|
|
pub struct CyberGlamorPlugin;
|
|
|
|
impl Plugin for CyberGlamorPlugin {
|
|
|
|
fn build(&self, app: &mut App) {
|
2023-01-27 01:16:05 +00:00
|
|
|
#[cfg(feature = "inspector")]
|
|
|
|
{
|
|
|
|
use bevy_rapier3d::render::{
|
|
|
|
DebugRenderMode, DebugRenderStyle, RapierDebugRenderPlugin,
|
|
|
|
};
|
|
|
|
let style = DebugRenderStyle {
|
|
|
|
multibody_joint_anchor_color: Color::GREEN.as_rgba_f32(),
|
|
|
|
..Default::default()
|
|
|
|
};
|
|
|
|
let mode = DebugRenderMode::CONTACTS
|
|
|
|
| DebugRenderMode::SOLVER_CONTACTS
|
|
|
|
| DebugRenderMode::JOINTS
|
|
|
|
| DebugRenderMode::RIGID_BODY_AXES;
|
|
|
|
|
|
|
|
let rplugin = RapierDebugRenderPlugin {
|
|
|
|
style,
|
|
|
|
always_on_top: true,
|
|
|
|
enabled: true,
|
|
|
|
mode,
|
|
|
|
};
|
|
|
|
|
|
|
|
app.add_plugin(rplugin);
|
|
|
|
}
|
|
|
|
|
2022-03-13 22:54:33 +00:00
|
|
|
app.add_startup_system_to_stage(StartupStage::PostStartup, wireframe_planet)
|
|
|
|
.add_system(wireframify_lights)
|
|
|
|
.add_plugin(PolylinePlugin);
|
2022-01-14 06:05:51 +00:00
|
|
|
}
|
|
|
|
}
|