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::{
|
use bevy::{
|
||||||
pbr::wireframe::{Wireframe, WireframeConfig, WireframePlugin},
|
pbr::wireframe::{Wireframe, WireframeConfig, WireframePlugin},
|
||||||
prelude::*,
|
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 rand::{thread_rng, Rng};
|
||||||
|
|
||||||
use crate::{geometry::CyberSphere, lights::AnimateCyberLightWireframe};
|
use crate::{geometry::CyberSphere, lights::AnimateCyberLightWireframe};
|
||||||
|
|
||||||
fn wireframe_planet(
|
fn wireframe_planet(
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
mut wireframe_config: ResMut<WireframeConfig>,
|
meshes: Res<Assets<Mesh>>,
|
||||||
query: Query<Entity, With<CyberSphere>>,
|
mut polylines: ResMut<Assets<Polyline>>,
|
||||||
|
mut polymats: ResMut<Assets<PolylineMaterial>>,
|
||||||
|
query: Query<&Handle<Mesh>, With<CyberSphere>>,
|
||||||
) {
|
) {
|
||||||
let ent = query.single();
|
let handle = query.single();
|
||||||
wireframe_config.global = false;
|
let mesh = meshes.get(handle).unwrap();
|
||||||
commands.entity(ent).insert(Wireframe);
|
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(
|
fn wireframify_lights(
|
||||||
|
@ -45,8 +77,10 @@ impl Plugin for CyberGlamorPlugin {
|
||||||
features: WgpuFeatures::POLYGON_MODE_LINE,
|
features: WgpuFeatures::POLYGON_MODE_LINE,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
|
.insert_resource(WireframeConfig { global: false })
|
||||||
.add_startup_system_to_stage(StartupStage::PostStartup, wireframe_planet)
|
.add_startup_system_to_stage(StartupStage::PostStartup, wireframe_planet)
|
||||||
.add_system(wireframify_lights)
|
.add_system(wireframify_lights)
|
||||||
|
.add_plugin(PolylinePlugin)
|
||||||
.add_plugin(WireframePlugin);
|
.add_plugin(WireframePlugin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,8 +22,8 @@ fn spawn_moving_lights(
|
||||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||||
) {
|
) {
|
||||||
let rng = &mut thread_rng();
|
let rng = &mut thread_rng();
|
||||||
// spawn 200 orbiting bisexual lights
|
// spawn orbiting bisexual lights
|
||||||
for _ in 0..255 {
|
for _ in 0..511 {
|
||||||
// mechanics
|
// mechanics
|
||||||
let axis = crate::random_unit_vec(rng);
|
let axis = crate::random_unit_vec(rng);
|
||||||
let angle = rng.gen_range(0.0..TAU);
|
let angle = rng.gen_range(0.0..TAU);
|
||||||
|
|
Loading…
Reference in a new issue