Merge from bevy-0.10 branch.
This commit is contained in:
commit
a4c268f72d
11 changed files with 690 additions and 571 deletions
986
Cargo.lock
generated
986
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
16
Cargo.toml
16
Cargo.toml
|
@ -5,31 +5,33 @@ edition = "2021"
|
|||
|
||||
[dependencies]
|
||||
rand = "0.8"
|
||||
bevy_polyline = "0.4"
|
||||
# bevy_polyline = "0.4"
|
||||
noise = { git = "https://github.com/Razaekel/noise-rs" }
|
||||
hexasphere = "7"
|
||||
wgpu = "0.14"
|
||||
bevy-inspector-egui = "0.17.0"
|
||||
# wgpu = "0.12"
|
||||
wgpu = "0.15"
|
||||
bevy-inspector-egui = "0.18"
|
||||
|
||||
[features]
|
||||
inspector = []
|
||||
|
||||
[dependencies.bevy]
|
||||
version = "0.9"
|
||||
version = "0.10"
|
||||
default-features = false
|
||||
features = [
|
||||
"bevy_gilrs",
|
||||
"bevy_winit",
|
||||
"render",
|
||||
"png",
|
||||
"hdr",
|
||||
"x11",
|
||||
"bevy_ui",
|
||||
"bevy_text",
|
||||
"bevy_gltf",
|
||||
"bevy_sprite"
|
||||
]
|
||||
|
||||
[dependencies.bevy_rapier3d]
|
||||
features = ["debug-render-3d"]
|
||||
version = "0.20"
|
||||
version = "0.21"
|
||||
|
||||
# Maybe also enable only a small amount of optimization for our code:
|
||||
[profile.dev]
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
use bevy::{
|
||||
diagnostic::FrameTimeDiagnosticsPlugin,
|
||||
prelude::{App, IntoSystemDescriptor, Plugin, ReflectResource, Resource},
|
||||
ecs::reflect::ReflectResource,
|
||||
prelude::{App, IntoSystemConfigs, Plugin, Resource},
|
||||
reflect::Reflect,
|
||||
};
|
||||
use bevy_rapier3d::prelude::{NoUserData, RapierPhysicsPlugin};
|
||||
|
@ -30,18 +31,17 @@ impl Plugin for CyberActionPlugin {
|
|||
.add_plugin(RapierPhysicsPlugin::<NoUserData>::default())
|
||||
.add_startup_system(timestep_setup)
|
||||
.add_plugin(FrameTimeDiagnosticsPlugin::default())
|
||||
.add_system(surface_fix.label("surface_fix"))
|
||||
.add_system(gravity.label("gravity").before("cat"))
|
||||
.add_system(cyber_lean.before("cat").after("gravity"))
|
||||
.add_system(falling_cat.label("cat"))
|
||||
.add_system(input_forces.label("iforces").after("cat"))
|
||||
.add_system(
|
||||
tunnel_out
|
||||
.label("tunnel")
|
||||
.before("surface_fix")
|
||||
.after("drag"),
|
||||
)
|
||||
.add_system(surface_fix.label("surface_fix").after("cat"))
|
||||
.add_system(drag.label("drag").after("iforces"));
|
||||
.add_systems(
|
||||
(
|
||||
gravity,
|
||||
cyber_lean,
|
||||
falling_cat,
|
||||
input_forces,
|
||||
drag,
|
||||
tunnel_out,
|
||||
surface_fix,
|
||||
)
|
||||
.chain(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,9 @@ mod body;
|
|||
mod components;
|
||||
mod wheels;
|
||||
|
||||
use bevy::prelude::{App, Assets, Mesh, Plugin, ResMut, StandardMaterial, StartupStage};
|
||||
use bevy::prelude::{
|
||||
App, Assets, IntoSystemConfig, Mesh, Plugin, ResMut, StandardMaterial, StartupSet,
|
||||
};
|
||||
use bevy_rapier3d::prelude::Group;
|
||||
|
||||
pub(crate) use self::components::*;
|
||||
|
@ -21,6 +23,6 @@ impl Plugin for CyberBikePlugin {
|
|||
fn build(&self, app: &mut App) {
|
||||
app.insert_resource(WheelConfig::default())
|
||||
.register_type::<WheelConfig>()
|
||||
.add_startup_system_to_stage(StartupStage::PostStartup, spawn_cyberbike);
|
||||
.add_startup_system(spawn_cyberbike.in_base_set(StartupSet::PostStartup));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,8 +5,9 @@ use crate::{bike::CyberBikeBody, input::InputState};
|
|||
// 85 degrees in radians
|
||||
const MAX_PITCH: f32 = 1.48353;
|
||||
|
||||
#[derive(Clone, Copy, Eq, PartialEq, Debug, Hash, Component)]
|
||||
#[derive(Clone, Copy, Eq, PartialEq, Debug, Hash, Component, States, Default)]
|
||||
enum CyberCameras {
|
||||
#[default]
|
||||
Hero,
|
||||
Debug,
|
||||
}
|
||||
|
@ -99,7 +100,7 @@ fn update_active_camera(
|
|||
) {
|
||||
// find the camera with the current state, set it as the ActiveCamera
|
||||
query.iter_mut().for_each(|(mut cam, cyber)| {
|
||||
if cyber.eq(state.current()) {
|
||||
if cyber.eq(&state.0) {
|
||||
cam.is_active = true;
|
||||
} else {
|
||||
cam.is_active = false;
|
||||
|
@ -107,11 +108,15 @@ fn update_active_camera(
|
|||
});
|
||||
}
|
||||
|
||||
fn cycle_cam_state(mut state: ResMut<State<CyberCameras>>, mut keys: ResMut<Input<KeyCode>>) {
|
||||
fn cycle_cam_state(
|
||||
state: Res<State<CyberCameras>>,
|
||||
mut next: ResMut<NextState<CyberCameras>>,
|
||||
mut keys: ResMut<Input<KeyCode>>,
|
||||
) {
|
||||
if keys.just_pressed(KeyCode::D) {
|
||||
let new_state = state.current().next();
|
||||
let new_state = state.0.next();
|
||||
info!("{:?}", new_state);
|
||||
state.set(new_state).unwrap();
|
||||
next.set(new_state);
|
||||
keys.reset(KeyCode::D);
|
||||
}
|
||||
}
|
||||
|
@ -127,7 +132,7 @@ impl Plugin for CyberCamPlugin {
|
|||
fn common(app: &mut bevy::prelude::App) {
|
||||
app.insert_resource(DebugCamOffset::default())
|
||||
.add_startup_system(setup_cybercams)
|
||||
.add_state(CyberCameras::Hero)
|
||||
.add_state::<CyberCameras>()
|
||||
.add_system(cycle_cam_state)
|
||||
.add_system(update_active_camera)
|
||||
.add_system(follow_cyberbike);
|
||||
|
|
|
@ -2,60 +2,60 @@ use bevy::{
|
|||
prelude::*,
|
||||
render::mesh::{Indices, VertexAttributeValues},
|
||||
};
|
||||
use bevy_polyline::prelude::{Polyline, PolylineBundle, PolylineMaterial, PolylinePlugin};
|
||||
// use bevy_polyline::prelude::{Polyline, PolylineBundle, PolylineMaterial, PolylinePlugin};
|
||||
use rand::{thread_rng, Rng};
|
||||
|
||||
use crate::{lights::AnimateCyberLightWireframe, 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();
|
||||
// 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());
|
||||
// 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 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);
|
||||
}
|
||||
}
|
||||
// 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();
|
||||
// // 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()
|
||||
});
|
||||
}
|
||||
// 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;
|
||||
|
@ -98,8 +98,6 @@ impl Plugin for CyberGlamorPlugin {
|
|||
app.add_plugin(rplugin);
|
||||
}
|
||||
|
||||
app.add_startup_system_to_stage(StartupStage::PostStartup, wireframe_planet)
|
||||
.add_system(wireframify_lights)
|
||||
.add_plugin(PolylinePlugin);
|
||||
app.add_system(wireframify_lights);
|
||||
}
|
||||
}
|
||||
|
|
59
src/input.rs
59
src/input.rs
|
@ -1,4 +1,8 @@
|
|||
use bevy::{prelude::*, utils::HashSet};
|
||||
use bevy::{
|
||||
input::gamepad::{GamepadAxisChangedEvent, GamepadButtonChangedEvent, GamepadEvent},
|
||||
prelude::*,
|
||||
utils::HashSet,
|
||||
};
|
||||
|
||||
use crate::camera::DebugCamOffset;
|
||||
|
||||
|
@ -46,39 +50,36 @@ fn update_debug_cam(mut offset: ResMut<DebugCamOffset>, mut keys: ResMut<Input<K
|
|||
}
|
||||
|
||||
fn update_input(mut events: EventReader<GamepadEvent>, mut istate: ResMut<InputState>) {
|
||||
for GamepadEvent {
|
||||
gamepad: _,
|
||||
event_type: ev,
|
||||
} in events.iter()
|
||||
{
|
||||
match *ev {
|
||||
GamepadEventType::ButtonChanged(GamepadButtonType::RightTrigger2, val) => {
|
||||
istate.throttle = val;
|
||||
}
|
||||
GamepadEventType::ButtonChanged(GamepadButtonType::LeftTrigger2, val) => {
|
||||
istate.throttle = -val;
|
||||
}
|
||||
GamepadEventType::ButtonChanged(GamepadButtonType::East, val) => {
|
||||
if val > 0.5 {
|
||||
istate.brake = true;
|
||||
} else {
|
||||
istate.brake = false;
|
||||
for pad_event in events.iter() {
|
||||
match pad_event {
|
||||
GamepadEvent::Button(button_event) => {
|
||||
let GamepadButtonChangedEvent {
|
||||
button_type, value, ..
|
||||
} = button_event;
|
||||
match button_type {
|
||||
GamepadButtonType::RightTrigger => istate.throttle = *value,
|
||||
GamepadButtonType::LeftTrigger => istate.throttle = -value,
|
||||
GamepadButtonType::East => {
|
||||
if value > &0.5 {
|
||||
istate.brake = true;
|
||||
} else {
|
||||
istate.brake = false;
|
||||
}
|
||||
}
|
||||
_ => info!("unhandled button press: {button_event:?}"),
|
||||
}
|
||||
}
|
||||
GamepadEventType::AxisChanged(GamepadAxisType::LeftStickX, val) => {
|
||||
istate.yaw = val;
|
||||
}
|
||||
// ignore spurious vertical movement for now
|
||||
GamepadEventType::AxisChanged(GamepadAxisType::LeftStickY, val) => {
|
||||
istate.pitch = val;
|
||||
}
|
||||
_ => {
|
||||
info!("unhandled gamepad event: {:?}", ev);
|
||||
GamepadEvent::Axis(axis_event) => {
|
||||
let GamepadAxisChangedEvent {
|
||||
axis_type, value, ..
|
||||
} = axis_event;
|
||||
match axis_type {
|
||||
_ => info!("unhandled axis event: {axis_event:?}"),
|
||||
}
|
||||
}
|
||||
GamepadEvent::Connection(_) => {}
|
||||
}
|
||||
}
|
||||
|
||||
//dbg!(&istate);
|
||||
}
|
||||
|
||||
pub struct CyberInputPlugin;
|
||||
|
|
15
src/lib.rs
15
src/lib.rs
|
@ -1,6 +1,7 @@
|
|||
use bevy::{
|
||||
ecs::schedule::StageLabel,
|
||||
prelude::{ResMut, SystemLabel, Vec3, Windows},
|
||||
ecs::schedule::SystemSet,
|
||||
prelude::{Query, Vec3, Window, With},
|
||||
window::PrimaryWindow,
|
||||
};
|
||||
|
||||
pub mod action;
|
||||
|
@ -12,7 +13,7 @@ pub mod lights;
|
|||
pub mod planet;
|
||||
pub mod ui;
|
||||
|
||||
#[derive(Clone, Debug, Hash, PartialEq, Eq, SystemLabel, StageLabel)]
|
||||
#[derive(Clone, Debug, Hash, PartialEq, Eq, SystemSet)]
|
||||
pub enum Label {
|
||||
Geometry,
|
||||
Glamor,
|
||||
|
@ -20,10 +21,10 @@ pub enum Label {
|
|||
Action,
|
||||
}
|
||||
|
||||
pub fn disable_mouse_trap(mut windows: ResMut<Windows>) {
|
||||
let window = windows.get_primary_mut().unwrap();
|
||||
window.set_cursor_grab_mode(bevy::window::CursorGrabMode::None);
|
||||
window.set_cursor_visibility(true);
|
||||
pub fn disable_mouse_trap(mut window: Query<&mut Window, With<PrimaryWindow>>) {
|
||||
let mut window = window.get_single_mut().unwrap();
|
||||
window.cursor.grab_mode = bevy::window::CursorGrabMode::None;
|
||||
window.cursor.visible = true;
|
||||
}
|
||||
|
||||
pub fn random_unit_vec(r: &mut impl rand::prelude::Rng) -> Vec3 {
|
||||
|
|
|
@ -74,10 +74,13 @@ fn spawn_moving_lights(
|
|||
builder
|
||||
// now a simple mesh to show a wireframe.
|
||||
.spawn(PbrBundle {
|
||||
mesh: meshes.add(Mesh::from(shape::Icosphere {
|
||||
radius,
|
||||
subdivisions: 1,
|
||||
})),
|
||||
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,
|
||||
|
@ -128,10 +131,13 @@ fn spawn_static_lights(
|
|||
})
|
||||
.with_children(|builder| {
|
||||
builder.spawn(PbrBundle {
|
||||
mesh: meshes.add(Mesh::from(shape::Icosphere {
|
||||
radius: 10.0,
|
||||
subdivisions: 2,
|
||||
})),
|
||||
mesh: meshes.add(
|
||||
Mesh::try_from(shape::Icosphere {
|
||||
radius: 10.0,
|
||||
subdivisions: 2,
|
||||
})
|
||||
.unwrap(),
|
||||
),
|
||||
material: materials.add(StandardMaterial {
|
||||
base_color: Color::BLUE,
|
||||
emissive: Color::PINK,
|
||||
|
@ -149,10 +155,13 @@ fn spawn_static_lights(
|
|||
})
|
||||
.with_children(|builder| {
|
||||
builder.spawn(PbrBundle {
|
||||
mesh: meshes.add(Mesh::from(shape::Icosphere {
|
||||
radius: 10.0,
|
||||
subdivisions: 2,
|
||||
})),
|
||||
mesh: meshes.add(
|
||||
Mesh::try_from(shape::Icosphere {
|
||||
radius: 10.0,
|
||||
subdivisions: 2,
|
||||
})
|
||||
.unwrap(),
|
||||
),
|
||||
material: materials.add(StandardMaterial {
|
||||
base_color: Color::PINK,
|
||||
emissive: Color::BLUE,
|
||||
|
|
|
@ -10,14 +10,13 @@ const CYBER_SKY: Color = Color::rgb(0.07, 0.001, 0.02);
|
|||
|
||||
fn main() {
|
||||
let mut app = App::new();
|
||||
app.insert_resource(Msaa { samples: 4 })
|
||||
app.insert_resource(Msaa::Sample4)
|
||||
.insert_resource(ClearColor(CYBER_SKY))
|
||||
.add_plugins(DefaultPlugins.set(WindowPlugin {
|
||||
window: WindowDescriptor {
|
||||
width: 2560.0,
|
||||
height: 1440.0,
|
||||
primary_window: Some(Window {
|
||||
resolution: (2560.0, 1440.0).into(),
|
||||
..Default::default()
|
||||
},
|
||||
}),
|
||||
..Default::default()
|
||||
}))
|
||||
.add_plugin(CyberPlanetPlugin)
|
||||
|
|
|
@ -59,7 +59,7 @@ fn spawn_planet(
|
|||
pub struct CyberPlanetPlugin;
|
||||
impl Plugin for CyberPlanetPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_startup_system(spawn_planet.label(Label::Geometry));
|
||||
app.add_startup_system(spawn_planet);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue