Use bevy_polyline to wireframe the big sphere.
This commit is contained in:
parent
d773e78333
commit
c11845db90
2 changed files with 42 additions and 8 deletions
|
@ -1,20 +1,52 @@
|
|||
use bevy::{
|
||||
pbr::wireframe::{Wireframe, WireframeConfig, WireframePlugin},
|
||||
prelude::*,
|
||||
render::{options::WgpuOptions, render_resource::WgpuFeatures},
|
||||
render::{
|
||||
mesh::{Indices, VertexAttributeValues},
|
||||
options::WgpuOptions,
|
||||
render_resource::WgpuFeatures,
|
||||
},
|
||||
};
|
||||
use bevy_polyline::{Polyline, PolylineBundle, PolylineMaterial, PolylinePlugin};
|
||||
use rand::{thread_rng, Rng};
|
||||
|
||||
use crate::{geometry::CyberSphere, lights::AnimateCyberLightWireframe};
|
||||
|
||||
fn wireframe_planet(
|
||||
mut commands: Commands,
|
||||
mut wireframe_config: ResMut<WireframeConfig>,
|
||||
query: Query<Entity, With<CyberSphere>>,
|
||||
meshes: Res<Assets<Mesh>>,
|
||||
mut polylines: ResMut<Assets<Polyline>>,
|
||||
mut polymats: ResMut<Assets<PolylineMaterial>>,
|
||||
query: Query<&Handle<Mesh>, With<CyberSphere>>,
|
||||
) {
|
||||
let ent = query.single();
|
||||
wireframe_config.global = false;
|
||||
commands.entity(ent).insert(Wireframe);
|
||||
let handle = query.single();
|
||||
let mesh = meshes.get(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !pts.is_empty() {
|
||||
commands.spawn_bundle(PolylineBundle {
|
||||
polyline: polylines.add(Polyline { vertices: pts }),
|
||||
material: polymats.add(PolylineMaterial {
|
||||
width: 6.0,
|
||||
color: Color::hsla(292.0, 1.0, 0.60, 1.0),
|
||||
perspective: false,
|
||||
}),
|
||||
..Default::default()
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
fn wireframify_lights(
|
||||
|
@ -45,8 +77,10 @@ impl Plugin for CyberGlamorPlugin {
|
|||
features: WgpuFeatures::POLYGON_MODE_LINE,
|
||||
..Default::default()
|
||||
})
|
||||
.insert_resource(WireframeConfig { global: false })
|
||||
.add_startup_system_to_stage(StartupStage::PostStartup, wireframe_planet)
|
||||
.add_system(wireframify_lights)
|
||||
.add_plugin(PolylinePlugin)
|
||||
.add_plugin(WireframePlugin);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,8 +22,8 @@ fn spawn_moving_lights(
|
|||
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||
) {
|
||||
let rng = &mut thread_rng();
|
||||
// spawn 200 orbiting bisexual lights
|
||||
for _ in 0..255 {
|
||||
// spawn orbiting bisexual lights
|
||||
for _ in 0..511 {
|
||||
// mechanics
|
||||
let axis = crate::random_unit_vec(rng);
|
||||
let angle = rng.gen_range(0.0..TAU);
|
||||
|
|
Loading…
Reference in a new issue