This commit is contained in:
Joe Ardent 2023-01-20 14:40:51 -08:00
parent bd96c52f3a
commit ca59748849
13 changed files with 588 additions and 628 deletions

1122
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -5,17 +5,17 @@ edition = "2021"
[dependencies] [dependencies]
rand = "0.8" rand = "0.8"
bevy_polyline = "0.3" bevy_polyline = "0.4"
noise = { git = "https://github.com/Razaekel/noise-rs" } noise = { git = "https://github.com/Razaekel/noise-rs" }
hexasphere = "7" hexasphere = "7"
wgpu = "0.13" wgpu = "0.14"
# wgpu = "0.12" # wgpu = "0.12"
[features] [features]
debug_render = [] debug_render = []
[dependencies.bevy] [dependencies.bevy]
version = "0.8" version = "0.9"
default-features = false default-features = false
features = [ features = [
"bevy_gilrs", "bevy_gilrs",
@ -28,7 +28,7 @@ features = [
[dependencies.bevy_rapier3d] [dependencies.bevy_rapier3d]
features = ["simd-nightly"] features = ["simd-nightly"]
version = "0.16" version = "0.20"
# Maybe also enable only a small amount of optimization for our code: # Maybe also enable only a small amount of optimization for our code:
[profile.dev] [profile.dev]

BIN
assets/cb-no-y_up.glb Normal file

Binary file not shown.

View file

@ -1,6 +1,4 @@
use bevy::prelude::{ use bevy::prelude::*;
App, ParallelSystemDescriptorCoercion, Plugin, Query, Res, ResMut, Transform, Vec3, With,
};
use bevy_rapier3d::prelude::{ use bevy_rapier3d::prelude::{
ExternalForce, Friction, NoUserData, RapierConfiguration, RapierPhysicsPlugin, Velocity, ExternalForce, Friction, NoUserData, RapierConfiguration, RapierPhysicsPlugin, Velocity,
}; };
@ -10,6 +8,7 @@ use crate::{
input::InputState, input::InputState,
}; };
#[derive(Resource)]
pub struct MovementSettings { pub struct MovementSettings {
pub accel: f32, pub accel: f32,
pub gravity: f32, pub gravity: f32,

View file

@ -1,5 +1,5 @@
use bevy::prelude::*; use bevy::prelude::*;
use bevy_rapier3d::prelude::*; use bevy_rapier3d::{geometry::Group, prelude::*};
use crate::planet::PLANET_RADIUS; use crate::planet::PLANET_RADIUS;
@ -22,8 +22,8 @@ pub struct CyberBikeControl {
pub prev_pitch_error: f32, pub prev_pitch_error: f32,
} }
const BIKE_BODY_COLLISION_GROUP: (u32, u32) = (0b01, 0b01); const BIKE_BODY_COLLISION_GROUP: (Group, Group) = (Group::GROUP_1, Group::GROUP_1);
const BIKE_WHEEL_COLLISION_GROUP: (u32, u32) = (0b10, 0b10); const BIKE_WHEEL_COLLISION_GROUP: (Group, Group) = (Group::GROUP_10, Group::GROUP_10);
fn spawn_cyberbike(mut commands: Commands, asset_server: Res<AssetServer>) { fn spawn_cyberbike(mut commands: Commands, asset_server: Res<AssetServer>) {
let xform = Transform::from_translation(Vec3::X * SPAWN_ALTITUDE) let xform = Transform::from_translation(Vec3::X * SPAWN_ALTITUDE)
@ -53,13 +53,13 @@ fn spawn_cyberbike(mut commands: Commands, asset_server: Res<AssetServer>) {
let mass_properties = ColliderMassProperties::Density(0.2); let mass_properties = ColliderMassProperties::Density(0.2);
let (membership, filter) = BIKE_BODY_COLLISION_GROUP; let (membership, filter) = BIKE_BODY_COLLISION_GROUP;
let bike_collision_group = CollisionGroups::new(membership, filter); let bike_collision_group = CollisionGroups::new(membership.into(), filter.into());
let bike = commands let bike = commands
.spawn() .spawn_empty()
.insert(RigidBody::Dynamic) .insert(RigidBody::Dynamic)
.insert_bundle((xform, GlobalTransform::default())) .insert((xform, GlobalTransform::default()))
.insert_bundle(( .insert((
bcollider_shape, bcollider_shape,
bike_collision_group, bike_collision_group,
mass_properties, mass_properties,
@ -77,8 +77,8 @@ fn spawn_cyberbike(mut commands: Commands, asset_server: Res<AssetServer>) {
.insert(ExternalForce::default()) .insert(ExternalForce::default())
.insert(CyberBikeCollider) .insert(CyberBikeCollider)
.with_children(|rider| { .with_children(|rider| {
rider.spawn_bundle(SceneBundle { rider.spawn(SceneBundle {
scene: asset_server.load("cyber-bike_no_y_up.glb#Scene0"), scene: asset_server.load("cb-no-y_up.glb#Scene0"),
..Default::default() ..Default::default()
}); });
}) })
@ -119,10 +119,10 @@ fn spawn_cyberbike(mut commands: Commands, asset_server: Res<AssetServer>) {
let joint = ImpulseJoint::new(bike, prismatic); let joint = ImpulseJoint::new(bike, prismatic);
let _wheel_rb = commands let _wheel_rb = commands
.spawn() .spawn_empty()
.insert(RigidBody::Dynamic) .insert(RigidBody::Dynamic)
.insert_bundle((wheel_pos_in_world, GlobalTransform::default())) .insert((wheel_pos_in_world, GlobalTransform::default()))
.insert_bundle(( .insert((
wheel_collider, wheel_collider,
mass_props, mass_props,
wheel_damping, wheel_damping,

View file

@ -1,7 +1,4 @@
use bevy::prelude::{ use bevy::prelude::*;
info, Camera, Camera3dBundle, Commands, Component, Input, KeyCode, ParamSet,
PerspectiveProjection, Plugin, Quat, Query, Res, ResMut, State, Transform, With,
};
use crate::{bike::CyberBikeModel, input::InputState}; use crate::{bike::CyberBikeModel, input::InputState};
@ -29,14 +26,14 @@ fn setup_cybercams(mut commands: Commands) {
..Default::default() ..Default::default()
}; };
commands commands
.spawn_bundle(Camera3dBundle { .spawn(Camera3dBundle {
projection: bevy::render::camera::Projection::Perspective(hero_projection), projection: bevy::render::camera::Projection::Perspective(hero_projection),
..Default::default() ..Default::default()
}) })
.insert(CyberCameras::Hero); .insert(CyberCameras::Hero);
commands commands
.spawn_bundle(Camera3dBundle::default()) .spawn(Camera3dBundle::default())
.insert(CyberCameras::Debug); .insert(CyberCameras::Debug);
} }

View file

@ -45,7 +45,7 @@ fn wireframe_planet(
mesh.duplicate_vertices(); mesh.duplicate_vertices();
mesh.compute_flat_normals(); mesh.compute_flat_normals();
commands.spawn_bundle(PolylineBundle { commands.spawn(PolylineBundle {
polyline: polylines.add(Polyline { vertices: verts }), polyline: polylines.add(Polyline { vertices: verts }),
material: polymats.add(PolylineMaterial { material: polymats.add(PolylineMaterial {
width: 101.0, width: 101.0,

View file

@ -1,9 +1,5 @@
use bevy::prelude::{ use bevy::prelude::*;
info, App, EventReader, GamepadAxisType, GamepadButtonType, GamepadEvent, GamepadEventType, #[derive(Default, Debug, Resource)]
Plugin, ResMut,
};
#[derive(Default, Debug)]
pub(crate) struct InputState { pub(crate) struct InputState {
pub yaw: f32, pub yaw: f32,
pub throttle: f32, pub throttle: f32,

View file

@ -22,7 +22,7 @@ pub enum Label {
pub fn disable_mouse_trap(mut windows: ResMut<Windows>) { pub fn disable_mouse_trap(mut windows: ResMut<Windows>) {
let window = windows.get_primary_mut().unwrap(); let window = windows.get_primary_mut().unwrap();
window.set_cursor_lock_mode(false); window.set_cursor_grab_mode(bevy::window::CursorGrabMode::None);
window.set_cursor_visibility(true); window.set_cursor_visibility(true);
} }

View file

@ -55,7 +55,7 @@ fn spawn_moving_lights(
commands commands
// first, spawn an entity with a transform we can rotate // first, spawn an entity with a transform we can rotate
.spawn_bundle(( .spawn((
AnimatedCyberLight { axis, rate }, AnimatedCyberLight { axis, rate },
Transform::from_rotation(rotation), Transform::from_rotation(rotation),
GlobalTransform::default(), GlobalTransform::default(),
@ -64,7 +64,7 @@ fn spawn_moving_lights(
parent parent
// now spawn a child entity with a pointlight, and a relative transform that's // now spawn a child entity with a pointlight, and a relative transform that's
// just translation from the parent // just translation from the parent
.spawn_bundle(PointLightBundle { .spawn(PointLightBundle {
transform, transform,
point_light, point_light,
..Default::default() ..Default::default()
@ -72,7 +72,7 @@ fn spawn_moving_lights(
.with_children(|builder| { .with_children(|builder| {
builder builder
// now a simple mesh to show a wireframe. // now a simple mesh to show a wireframe.
.spawn_bundle(PbrBundle { .spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Icosphere { mesh: meshes.add(Mesh::from(shape::Icosphere {
radius, radius,
subdivisions: 1, subdivisions: 1,
@ -120,13 +120,13 @@ fn spawn_static_lights(
// up light // up light
commands commands
.spawn_bundle(PointLightBundle { .spawn(PointLightBundle {
transform: Transform::from_xyz(0.0, PLANET_RADIUS + 30.0, 0.0), transform: Transform::from_xyz(0.0, PLANET_RADIUS + 30.0, 0.0),
point_light: pink_light, point_light: pink_light,
..Default::default() ..Default::default()
}) })
.with_children(|builder| { .with_children(|builder| {
builder.spawn_bundle(PbrBundle { builder.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Icosphere { mesh: meshes.add(Mesh::from(shape::Icosphere {
radius: 10.0, radius: 10.0,
subdivisions: 2, subdivisions: 2,
@ -141,13 +141,13 @@ fn spawn_static_lights(
}); });
// down light // down light
commands commands
.spawn_bundle(PointLightBundle { .spawn(PointLightBundle {
transform: Transform::from_xyz(0.0, -PLANET_RADIUS - 30.0, 0.0), transform: Transform::from_xyz(0.0, -PLANET_RADIUS - 30.0, 0.0),
point_light: blue_light, point_light: blue_light,
..Default::default() ..Default::default()
}) })
.with_children(|builder| { .with_children(|builder| {
builder.spawn_bundle(PbrBundle { builder.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Icosphere { mesh: meshes.add(Mesh::from(shape::Icosphere {
radius: 10.0, radius: 10.0,
subdivisions: 2, subdivisions: 2,

View file

@ -21,13 +21,15 @@ fn main() {
let mut app = App::new(); let mut app = App::new();
app.insert_resource(Msaa { samples: 4 }) app.insert_resource(Msaa { samples: 4 })
.insert_resource(ClearColor(Color::rgb(0.07, 0.001, 0.02))) .insert_resource(ClearColor(Color::rgb(0.07, 0.001, 0.02)))
.insert_resource(WindowDescriptor { .add_plugins(DefaultPlugins.set(WindowPlugin {
width: 2560.0, window: WindowDescriptor {
height: 1440.0, width: 2560.0,
height: 1440.0,
..Default::default()
},
..Default::default() ..Default::default()
}) }))
.insert_resource(MOVEMENT_SETTINGS) .insert_resource(MOVEMENT_SETTINGS)
.add_plugins(DefaultPlugins)
.add_plugin(CyberPlanetPlugin) .add_plugin(CyberPlanetPlugin)
.add_plugin(CyberGlamorPlugin) .add_plugin(CyberGlamorPlugin)
.add_plugin(CyberInputPlugin) .add_plugin(CyberInputPlugin)

View file

@ -39,7 +39,7 @@ fn spawn_planet(
); );
commands commands
.spawn_bundle(PbrBundle { .spawn(PbrBundle {
mesh: meshes.add(mesh), mesh: meshes.add(mesh),
material: materials.add(StandardMaterial { material: materials.add(StandardMaterial {
base_color: color, base_color: color,
@ -51,8 +51,8 @@ fn spawn_planet(
..Default::default() ..Default::default()
}) })
.insert_bundle(pbody) .insert(pbody)
.insert_bundle(pcollide) .insert(pcollide)
.insert(CyberPlanet); .insert(CyberPlanet);
} }

View file

@ -7,10 +7,10 @@ use crate::bike::CyberBikeBody;
struct UpText; struct UpText;
fn setup_ui(mut commands: Commands, asset_server: Res<AssetServer>) { fn setup_ui(mut commands: Commands, asset_server: Res<AssetServer>) {
//commands.spawn_bundle(UiCameraBundle::default()); //commands.spawn(UiCameraBundle::default());
commands commands
.spawn_bundle(TextBundle { .spawn(TextBundle {
style: Style { style: Style {
align_self: AlignSelf::FlexEnd, align_self: AlignSelf::FlexEnd,
..Default::default() ..Default::default()