Merge branch 'bike-fields'

This commit is contained in:
Joe Ardent 2022-03-04 16:02:27 -08:00
commit 474190118e
10 changed files with 302 additions and 202 deletions

19
Cargo.lock generated
View file

@ -4,9 +4,9 @@ version = 3
[[package]] [[package]]
name = "ab_glyph" name = "ab_glyph"
version = "0.2.13" version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "61caed9aec6daeee1ea38ccf5fb225e4f96c1eeead1b4a5c267324a63cf02326" checksum = "d54a65e0d4f66f8536c98cb3ca81ca33b7e2ca43442465507a3a62291ec0d9e4"
dependencies = [ dependencies = [
"ab_glyph_rasterizer", "ab_glyph_rasterizer",
"owned_ttf_parser", "owned_ttf_parser",
@ -461,8 +461,7 @@ dependencies = [
[[package]] [[package]]
name = "bevy_rapier3d" name = "bevy_rapier3d"
version = "0.12.1" version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "git+https://github.com/nebkor/bevy_rapier?branch=debug-render-capsule#3387b8ff9d3615033144cb2e22ad4a965caa6b2b"
checksum = "5186c735d7aa202e982f93c71b444d34bf15fed44aca942f9b5f2940e3d06764"
dependencies = [ dependencies = [
"bevy", "bevy",
"nalgebra", "nalgebra",
@ -2010,9 +2009,9 @@ checksum = "da32515d9f6e6e489d7bc9d84c71b060db7247dc035bbe44eac88cf87486d8d5"
[[package]] [[package]]
name = "owned_ttf_parser" name = "owned_ttf_parser"
version = "0.14.0" version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ef05f2882a8b3e7acc10c153ade2631f7bfc8ce00d2bf3fb8f4e9d2ae6ea5c3" checksum = "4fb1e509cfe7a12db2a90bfa057dfcdbc55a347f5da677c506b53dd099cfec9d"
dependencies = [ dependencies = [
"ttf-parser", "ttf-parser",
] ]
@ -2329,9 +2328,9 @@ checksum = "a0d463f2884048e7153449a55166f91028d5b0ea53c79377099ce4e8cf0cf9bb"
[[package]] [[package]]
name = "redox_syscall" name = "redox_syscall"
version = "0.2.10" version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8383f39639269cde97d255a32bdb68c047337295414940c68bdd30c2e13203ff" checksum = "8380fe0152551244f0747b1bf41737e0f8a74f97a14ccefd1148187271634f3c"
dependencies = [ dependencies = [
"bitflags", "bitflags",
] ]
@ -2757,9 +2756,9 @@ dependencies = [
[[package]] [[package]]
name = "ttf-parser" name = "ttf-parser"
version = "0.14.0" version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ccbe8381883510b6a2d8f1e32905bddd178c11caef8083086d0c0c9ab0ac281" checksum = "c74c96594835e10fa545e2a51e8709f30b173a092bfd6036ef2cec53376244f3"
[[package]] [[package]]
name = "typenum" name = "typenum"

View file

@ -10,6 +10,8 @@ noise = { git = "https://github.com/Razaekel/noise-rs" }
hexasphere = "7" hexasphere = "7"
wgpu = "0.12" wgpu = "0.12"
[features]
debug_render = []
[dependencies.bevy] [dependencies.bevy]
version = "0.6" version = "0.6"
@ -24,8 +26,11 @@ features = [
] ]
[dependencies.bevy_rapier3d] [dependencies.bevy_rapier3d]
version = "0.12" git = "https://github.com/nebkor/bevy_rapier"
#path = "../bevy_rapier/bevy_rapier3d"
branch = "debug-render-capsule"
features = ["parallel", "simd-nightly"] features = ["parallel", "simd-nightly"]
# version = "0.12"
# 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]

View file

@ -1,137 +1,38 @@
use bevy::{ use bevy::prelude::*;
prelude::*, use bevy_rapier3d::{na::Vector3, prelude::*};
render::mesh::{Indices, VertexAttributeValues},
};
#[allow(unused_imports)]
use bevy_rapier3d::{na::Vector3, physics::PhysicsSystems::StepWorld, prelude::*};
use crate::{ use crate::{
geometry::{CyberBike, CyberSphere, PLANET_RADIUS, SPAWN_ALTITUDE}, colliders::{CyberBikeBody, CyberBikeCollider},
input::InputState, input::InputState,
}; };
/// Mouse sensitivity and movement speed
pub struct MovementSettings { pub struct MovementSettings {
pub sensitivity: f32, pub sensitivity: f32,
pub accel: f32, pub accel: f32,
pub gravity: f32,
} }
impl Default for MovementSettings { impl Default for MovementSettings {
fn default() -> Self { fn default() -> Self {
Self { Self {
sensitivity: 1.0, sensitivity: 10.0,
accel: 40., accel: 20.0,
gravity: 9.8,
} }
} }
} }
fn setup_colliders( fn gravity(
mut commands: Commands, xform: Query<&Transform, With<CyberBikeBody>>,
meshes: Res<Assets<Mesh>>, settings: Res<MovementSettings>,
planet_query: Query<(Entity, &Handle<Mesh>), With<CyberSphere>>, mut config: ResMut<RapierConfiguration>,
bike_query: Query<(Entity, &Transform), With<CyberBike>>,
) { ) {
let (planet, mesh_handle) = planet_query.single(); let gravity = xform.single().translation.normalize() * -settings.gravity;
let mesh = meshes.get(mesh_handle).unwrap();
let mut shape = ColliderShape::ball(PLANET_RADIUS);
let vertices = mesh.attribute(Mesh::ATTRIBUTE_POSITION).unwrap();
if let VertexAttributeValues::Float32x3(verts) = vertices {
if let Some(Indices::U32(indices)) = mesh.indices() {
let mut idxs = Vec::new();
for idx in indices.chunks_exact(3) {
idxs.push([idx[0], idx[1], idx[2]]);
}
let vertices = verts
.iter()
.map(|p| Point::from_slice(p))
.collect::<Vec<Point<_>>>();
shape = ColliderShape::trimesh(vertices, idxs);
}
}
let pbody = RigidBodyBundle {
body_type: RigidBodyType::Static.into(),
ccd: RigidBodyCcd {
ccd_enabled: true,
ccd_thickness: 2.0,
ccd_max_dist: SPAWN_ALTITUDE,
..Default::default()
}
.into(),
..Default::default()
};
let pcollide = ColliderBundle {
shape: shape.into(),
material: ColliderMaterial {
friction: 0.05,
restitution: 0.00,
..Default::default()
}
.into(),
..Default::default()
};
commands
.entity(planet)
.insert_bundle(pbody)
.insert_bundle(pcollide);
// bike is the easy part
let (bike, xform) = bike_query.single();
setup_bike_collider(bike, xform, &mut commands);
}
fn setup_bike_collider(bike: Entity, xform: &Transform, commands: &mut Commands) {
let mut bbody = RigidBodyBundle::default();
bbody.damping.angular_damping = 0.8;
bbody.damping.linear_damping = 0.1;
bbody.ccd = RigidBodyCcd {
ccd_enabled: true,
ccd_thickness: 0.7,
ccd_max_dist: 1.5,
..Default::default()
}
.into();
let isometry = Isometry::from_parts(xform.translation.into(), xform.rotation.into());
bbody.position = isometry.into();
// collider
let shape = ColliderShape::capsule(
Vec3::new(0.0, 0.0, -1.25).into(),
Vec3::new(0.0, 0.0, 1.25).into(),
0.4,
);
let bcollide = ColliderBundle {
shape: shape.into(),
mass_properties: ColliderMassProps::Density(0.6).into(),
material: ColliderMaterial {
friction: 0.0,
restitution: 0.0,
..Default::default()
}
.into(),
..Default::default()
};
commands
.entity(bike)
.insert_bundle(bbody)
.insert_bundle(bcollide)
.insert(ColliderPositionSync::Discrete);
}
fn gravity(xform: Query<&Transform, With<CyberBike>>, mut config: ResMut<RapierConfiguration>) {
let gravity = xform.single().translation.normalize() * -7.80;
config.gravity = gravity.into(); config.gravity = gravity.into();
} }
fn falling_cat( fn falling_cat(
mut bike_query: Query<(&Transform, &mut RigidBodyForcesComponent), With<CyberBike>>, mut bike_query: Query<(&Transform, &mut RigidBodyForcesComponent), With<CyberBikeBody>>,
) { ) {
let (bike_xform, mut forces) = bike_query.single_mut(); let (bike_xform, mut forces) = bike_query.single_mut();
let up = bike_xform.translation.normalize(); let up = bike_xform.translation.normalize();
@ -145,19 +46,28 @@ fn falling_cat(
forces.torque = torque.into(); forces.torque = torque.into();
} }
fn update_forces( fn drag(
settings: Res<MovementSettings>,
input: Res<InputState>,
mut query: Query< mut query: Query<
( (&RigidBodyVelocityComponent, &mut RigidBodyForcesComponent),
&Transform, With<CyberBikeBody>,
&mut RigidBodyForcesComponent,
&mut ColliderMaterialComponent,
),
With<CyberBike>,
>, >,
) { ) {
let (xform, mut forces, mut cmat) = query.single_mut(); let (vels, mut forces) = query.single_mut();
if let Some(vel) = vels.linvel.try_normalize(0.001) {
let v2 = vels.linvel.magnitude_squared();
forces.force -= vel * v2 * 0.002;
}
}
fn input_forces(
settings: Res<MovementSettings>,
input: Res<InputState>,
mut cquery: Query<&mut ColliderMaterialComponent, With<CyberBikeCollider>>,
mut bquery: Query<(&Transform, &mut RigidBodyForcesComponent), With<CyberBikeBody>>,
) {
let (xform, mut forces) = bquery.single_mut();
let mut cmat = cquery.single_mut();
// thrust // thrust
let thrust: Vector3<f32> = (xform.forward() * input.throttle * settings.accel).into(); let thrust: Vector3<f32> = (xform.forward() * input.throttle * settings.accel).into();
@ -171,29 +81,14 @@ fn update_forces(
forces.torque += torque; forces.torque += torque;
} }
fn drag(
mut query: Query<(&RigidBodyVelocityComponent, &mut RigidBodyForcesComponent), With<CyberBike>>,
) {
let (vels, mut forces) = query.single_mut();
if let Some(vel) = vels.linvel.try_normalize(0.001) {
let v2 = vels.linvel.magnitude_squared();
forces.force -= vel * v2 * 0.002;
}
}
pub struct CyberActionPlugin; pub struct CyberActionPlugin;
impl Plugin for CyberActionPlugin { impl Plugin for CyberActionPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.init_resource::<MovementSettings>() app.init_resource::<MovementSettings>()
.add_plugin(RapierPhysicsPlugin::<NoUserData>::default()) .add_plugin(RapierPhysicsPlugin::<NoUserData>::default())
.add_startup_system_to_stage(
StartupStage::PostStartup,
setup_colliders.label("colliders"),
)
.add_system(gravity) .add_system(gravity)
.add_system(falling_cat.label("cat")) .add_system(falling_cat.label("cat"))
.add_system(drag.label("drag").after("uforces")) .add_system(drag.label("drag").after("iforces"))
.add_system(update_forces.label("uforces").after("cat")); .add_system(input_forces.label("iforces").after("cat"));
} }
} }

View file

@ -1,45 +1,63 @@
use bevy::prelude::*; use bevy::{
prelude::*,
use crate::{ render::camera::{ActiveCameras, Camera, CameraPlugin},
geometry::{CyberBike, SPAWN_ALTITUDE},
input::InputState,
}; };
pub(crate) const CAM_DIST: f32 = 15.0; use crate::{geometry::CyberBikeModel, input::InputState};
// 85 degrees in radians // 85 degrees in radians
const MAX_PITCH: f32 = 1.48353; const MAX_PITCH: f32 = 1.48353;
#[derive(Component, Debug)] #[derive(Clone, Copy, Eq, PartialEq, Debug, Hash, Component)]
pub struct CyberCam; enum CyberCameras {
Hero,
Debug,
}
fn setup_cybercam(mut commands: Commands) { impl CyberCameras {
let projection = PerspectiveProjection { fn next(self) -> Self {
match self {
CyberCameras::Debug => CyberCameras::Hero,
CyberCameras::Hero => CyberCameras::Debug,
}
}
}
fn setup_cybercams(mut commands: Commands) {
let hero_projection = PerspectiveProjection {
fov: std::f32::consts::FRAC_PI_3, fov: std::f32::consts::FRAC_PI_3,
..Default::default() ..Default::default()
}; };
commands commands
.spawn_bundle(PerspectiveCameraBundle { .spawn_bundle(PerspectiveCameraBundle {
transform: Transform::from_xyz(SPAWN_ALTITUDE + CAM_DIST, 0.0, 0.0) perspective_projection: hero_projection,
.looking_at(Vec3::ZERO, Vec3::Y),
perspective_projection: projection,
..Default::default() ..Default::default()
}) })
.insert(CyberCam); .insert(CyberCameras::Hero);
commands
.spawn_bundle(PerspectiveCameraBundle::with_name("Inactive"))
.insert(CyberCameras::Debug);
} }
fn follow_cyberbike( fn follow_cyberbike(
bike_query: Query<&Transform, (Without<CyberCam>, With<CyberBike>)>, mut query: QuerySet<(
mut cam_query: Query<&mut Transform, (With<CyberCam>, Without<CyberBike>)>, // 0: the bike
QueryState<&Transform, With<CyberBikeModel>>,
// 1: the cameras
QueryState<(&mut Transform, &CyberCameras)>,
)>,
input: Res<InputState>, input: Res<InputState>,
) { ) {
let bike_xform = bike_query.single(); let bike_xform = *query.q0().single();
let up = bike_xform.translation.normalize(); let up = bike_xform.translation.normalize();
for (mut cam_xform, cam_type) in query.q1().iter_mut() {
match *cam_type {
CyberCameras::Hero => {
let look_at = bike_xform.translation + (bike_xform.forward() * 200.0); let look_at = bike_xform.translation + (bike_xform.forward() * 200.0);
let cam_pos = bike_xform.translation + (bike_xform.back() * 2.7) + (up * 2.4); let cam_pos = bike_xform.translation + (bike_xform.back() * 2.7) + (up * 2.4);
let mut cam_xform = cam_query.single_mut();
cam_xform.translation = cam_pos; cam_xform.translation = cam_pos;
cam_xform.look_at(look_at, up); cam_xform.look_at(look_at, up);
@ -48,11 +66,57 @@ fn follow_cyberbike(
let axis = cam_xform.right(); let axis = cam_xform.right();
cam_xform.rotate(Quat::from_axis_angle(axis, angle)); cam_xform.rotate(Quat::from_axis_angle(axis, angle));
} }
CyberCameras::Debug => {
let pos = bike_xform.translation
+ (bike_xform.forward() * 10.0)
+ (bike_xform.left() * 30.0)
+ (bike_xform.up() * 7.0);
cam_xform.translation = pos;
cam_xform.look_at(bike_xform.translation, up);
}
}
}
}
fn update_active_camera(
mut active_cams: ResMut<ActiveCameras>,
state: Res<State<CyberCameras>>,
mut query: Query<(&mut Camera, &CyberCameras)>,
) {
active_cams.remove(CameraPlugin::CAMERA_3D);
// set all cameras to inactive
for (mut cam, _) in query.iter_mut() {
cam.name = Some("Inactive".to_string());
}
// find the camera with the current state, set its name to be active
for (mut cam, _) in query
.iter_mut()
.filter(|(_, cybercam)| state.current().eq(cybercam))
{
cam.name = Some(CameraPlugin::CAMERA_3D.to_string());
}
active_cams.add(CameraPlugin::CAMERA_3D);
}
fn cycle_cam_state(mut state: ResMut<State<CyberCameras>>, mut keys: ResMut<Input<KeyCode>>) {
if keys.just_pressed(KeyCode::D) {
let new_state = state.current().next();
info!("{:?}", new_state);
state.set(new_state).unwrap();
keys.reset(KeyCode::D);
}
}
pub struct CyberCamPlugin; pub struct CyberCamPlugin;
impl Plugin for CyberCamPlugin { impl Plugin for CyberCamPlugin {
fn build(&self, app: &mut bevy::prelude::App) { fn build(&self, app: &mut bevy::prelude::App) {
app.add_startup_system(setup_cybercam) app.add_startup_system(setup_cybercams)
.add_state(CyberCameras::Hero)
.add_system(cycle_cam_state)
.add_system(update_active_camera)
.add_system(follow_cyberbike); .add_system(follow_cyberbike);
} }
} }

142
src/colliders.rs Normal file
View file

@ -0,0 +1,142 @@
use bevy::{
prelude::*,
render::mesh::{Indices, VertexAttributeValues},
};
use bevy_rapier3d::prelude::*;
use crate::geometry::{CyberBikeModel, CyberPlanet, PLANET_RADIUS, SPAWN_ALTITUDE};
#[derive(Component)]
pub struct CyberBikeBody;
#[derive(Component)]
pub struct CyberBikeCollider;
fn setup_colliders(
mut commands: Commands,
meshes: Res<Assets<Mesh>>,
planet_query: Query<(Entity, &Handle<Mesh>), With<CyberPlanet>>,
bike_query: Query<(Entity, &Transform), With<CyberBikeModel>>,
) {
let (planet, mesh_handle) = planet_query.single();
let mesh = meshes.get(mesh_handle).unwrap();
let mut shape = ColliderShape::ball(PLANET_RADIUS);
let vertices = mesh.attribute(Mesh::ATTRIBUTE_POSITION).unwrap();
if let VertexAttributeValues::Float32x3(verts) = vertices {
if let Some(Indices::U32(indices)) = mesh.indices() {
let mut idxs = Vec::new();
for idx in indices.chunks_exact(3) {
idxs.push([idx[0], idx[1], idx[2]]);
}
let vertices = verts
.iter()
.map(|p| Point::from_slice(p))
.collect::<Vec<Point<_>>>();
shape = ColliderShape::trimesh(vertices, idxs);
}
}
let pbody = RigidBodyBundle {
body_type: RigidBodyType::Static.into(),
ccd: RigidBodyCcd {
ccd_enabled: true,
ccd_thickness: 2.0,
ccd_max_dist: SPAWN_ALTITUDE,
..Default::default()
}
.into(),
..Default::default()
};
let pcollide = ColliderBundle {
shape: shape.into(),
material: ColliderMaterial {
friction: 0.05,
restitution: 0.00,
..Default::default()
}
.into(),
..Default::default()
};
commands
.entity(planet)
.insert_bundle(pbody)
.insert_bundle(pcollide);
// bike is the easy part
let (bike, xform) = bike_query.single();
setup_bike_collider(bike, xform, &mut commands);
}
fn setup_bike_collider(bike: Entity, xform: &Transform, commands: &mut Commands) {
let mut bbody = RigidBodyBundle::default();
bbody.damping.angular_damping = 0.8;
bbody.damping.linear_damping = 0.1;
bbody.activation = RigidBodyActivation::cannot_sleep().into();
bbody.ccd = RigidBodyCcd {
ccd_enabled: true,
ccd_thickness: 0.7,
ccd_max_dist: 1.5,
..Default::default()
}
.into();
let isometry = Isometry::from_parts(xform.translation.into(), xform.rotation.into());
bbody.position = isometry.into();
// collider
let shape = ColliderShape::capsule(
Vec3::new(0.0, 0.0, -2.7).into(),
Vec3::new(0.0, 0.0, 2.0).into(),
1.0,
);
let bcollide = ColliderBundle {
shape: shape.into(),
mass_properties: ColliderMassProps::Density(0.04).into(),
material: ColliderMaterial {
friction: 0.0,
restitution: 0.0,
..Default::default()
}
.into(),
..Default::default()
};
commands
.entity(bike)
.insert_bundle(bbody)
.insert(CyberBikeBody)
.insert(RigidBodyPositionSync::Discrete)
.with_children(|e| {
e.spawn_bundle(bcollide)
.insert(ColliderDebugRender {
color: Color::GREEN,
})
.insert(CyberBikeCollider)
.insert(ColliderPositionSync::Discrete);
});
}
pub struct CyberCollidersPlugin;
impl Plugin for CyberCollidersPlugin {
#[cfg(feature = "debug_render")]
fn build(&self, app: &mut App) {
app.add_plugin(RapierRenderPlugin)
.add_startup_system_to_stage(
StartupStage::PostStartup,
setup_colliders.label("colliders"),
);
}
#[cfg(not(feature = "debug_render"))]
fn build(&self, app: &mut App) {
app.add_startup_system_to_stage(
StartupStage::PostStartup,
setup_colliders.label("colliders"),
);
}
}

View file

@ -12,17 +12,17 @@ pub const PLANET_RADIUS: f32 = 5000.0;
pub(crate) const SPAWN_ALTITUDE: f32 = PLANET_RADIUS * 1.015; pub(crate) const SPAWN_ALTITUDE: f32 = PLANET_RADIUS * 1.015;
#[derive(Component, Debug)] #[derive(Component, Debug)]
pub struct CyberBike; pub struct CyberBikeModel;
#[derive(Component)] #[derive(Component)]
pub struct CyberSphere; pub struct CyberPlanet;
fn spawn_giant_sphere( fn spawn_planet(
mut commands: Commands, mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>, mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>, mut materials: ResMut<Assets<StandardMaterial>>,
) { ) {
let color = Color::rgb(0.2, 0.17, 0.2); let color = Color::rgb(0.2, 0.1, 0.2);
let isphere = shape::Icosphere { let isphere = shape::Icosphere {
radius: PLANET_RADIUS, radius: PLANET_RADIUS,
subdivisions: 79, subdivisions: 79,
@ -43,7 +43,7 @@ fn spawn_giant_sphere(
..Default::default() ..Default::default()
}) })
.insert(CyberSphere); .insert(CyberPlanet);
} }
fn spawn_cyberbike(mut commands: Commands, asset_server: Res<AssetServer>) { fn spawn_cyberbike(mut commands: Commands, asset_server: Res<AssetServer>) {
@ -59,13 +59,13 @@ fn spawn_cyberbike(mut commands: Commands, asset_server: Res<AssetServer>) {
.with_children(|rider| { .with_children(|rider| {
rider.spawn_scene(asset_server.load("cyber-bike_no_y_up.glb#Scene0")); rider.spawn_scene(asset_server.load("cyber-bike_no_y_up.glb#Scene0"));
}) })
.insert(CyberBike); .insert(CyberBikeModel);
} }
pub struct CyberGeomPlugin; pub struct CyberGeomPlugin;
impl Plugin for CyberGeomPlugin { impl Plugin for CyberGeomPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.add_startup_system(spawn_giant_sphere.label(Label::Geometry)) app.add_startup_system(spawn_planet.label(Label::Geometry))
.add_startup_system(spawn_cyberbike.label(Label::Geometry)); .add_startup_system(spawn_cyberbike.label(Label::Geometry));
} }
} }
@ -87,31 +87,23 @@ fn gen_planet(sphere: Icosphere) -> Mesh {
[norm_azimuth, norm_inclination] [norm_azimuth, norm_inclination]
}); });
// TODO: use displaced points for normals by replacing raw_points with
// noise-displaced points.
let noise = HybridMulti::<SuperSimplex>::default(); let noise = HybridMulti::<SuperSimplex>::default();
let raw_points = generated let noisy_points = generated
.raw_points() .raw_points()
.iter() .iter()
.map(|&p| { .map(|&p| {
let disp = noise.get(p.as_dvec3().into()) as f32 * 0.05; let disp = noise.get(p.as_dvec3().into()) as f32 * 0.05;
let pt = p + disp; let pt = p + (p.normalize() * disp);
pt.into() pt.into()
}) })
.collect::<Vec<[f32; 3]>>(); .collect::<Vec<[f32; 3]>>();
let points = raw_points let points = noisy_points
.iter() .iter()
.map(|&p| (Vec3::from_slice(&p) * sphere.radius).into()) .map(|&p| (Vec3::from_slice(&p) * sphere.radius).into())
.collect::<Vec<[f32; 3]>>(); .collect::<Vec<[f32; 3]>>();
let normals = raw_points
.iter()
.copied()
.map(Into::into)
.collect::<Vec<[f32; 3]>>();
let uvs = generated.raw_data().to_owned(); let uvs = generated.raw_data().to_owned();
let mut indices = Vec::with_capacity(generated.indices_per_main_triangle() * 20); let mut indices = Vec::with_capacity(generated.indices_per_main_triangle() * 20);
@ -125,7 +117,6 @@ fn gen_planet(sphere: Icosphere) -> Mesh {
let mut mesh = Mesh::new(PrimitiveTopology::TriangleList); let mut mesh = Mesh::new(PrimitiveTopology::TriangleList);
mesh.set_indices(Some(indices)); mesh.set_indices(Some(indices));
mesh.set_attribute(Mesh::ATTRIBUTE_POSITION, points); mesh.set_attribute(Mesh::ATTRIBUTE_POSITION, points);
mesh.set_attribute(Mesh::ATTRIBUTE_NORMAL, normals);
mesh.set_attribute(Mesh::ATTRIBUTE_UV_0, uvs); mesh.set_attribute(Mesh::ATTRIBUTE_UV_0, uvs);
mesh mesh
} }

View file

@ -10,7 +10,7 @@ use bevy::{
use bevy_polyline::{Polyline, PolylineBundle, PolylineMaterial, PolylinePlugin}; 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::CyberPlanet, lights::AnimateCyberLightWireframe};
pub const BISEXY_COLOR: Color = Color::hsla(292.0, 0.9, 0.60, 1.1); pub const BISEXY_COLOR: Color = Color::hsla(292.0, 0.9, 0.60, 1.1);
@ -19,7 +19,7 @@ fn wireframe_planet(
mut meshes: ResMut<Assets<Mesh>>, mut meshes: ResMut<Assets<Mesh>>,
mut polylines: ResMut<Assets<Polyline>>, mut polylines: ResMut<Assets<Polyline>>,
mut polymats: ResMut<Assets<PolylineMaterial>>, mut polymats: ResMut<Assets<PolylineMaterial>>,
query: Query<&Handle<Mesh>, With<CyberSphere>>, query: Query<&Handle<Mesh>, With<CyberPlanet>>,
) { ) {
let handle = query.single(); let handle = query.single();
let mesh = meshes.get_mut(handle).unwrap(); let mesh = meshes.get_mut(handle).unwrap();

View file

@ -5,6 +5,7 @@ use bevy::{
pub mod action; pub mod action;
pub mod camera; pub mod camera;
pub mod colliders;
pub mod geometry; pub mod geometry;
pub mod glamor; pub mod glamor;
pub mod input; pub mod input;

View file

@ -2,6 +2,7 @@ use bevy::prelude::*;
use cyber_rider::{ use cyber_rider::{
action::{CyberActionPlugin, MovementSettings}, action::{CyberActionPlugin, MovementSettings},
camera::CyberCamPlugin, camera::CyberCamPlugin,
colliders::CyberCollidersPlugin,
disable_mouse_trap, disable_mouse_trap,
geometry::CyberGeomPlugin, geometry::CyberGeomPlugin,
glamor::CyberGlamorPlugin, glamor::CyberGlamorPlugin,
@ -11,8 +12,9 @@ use cyber_rider::{
}; };
const MOVEMENT_SETTINGS: MovementSettings = MovementSettings { const MOVEMENT_SETTINGS: MovementSettings = MovementSettings {
sensitivity: 10.0, // default: 1.0 sensitivity: 10.0, // steering
accel: 30.0, // default: 40.0 accel: 30.0, // thrust
gravity: 8.0,
}; };
fn main() { fn main() {
@ -33,6 +35,7 @@ fn main() {
.add_plugin(CyberCamPlugin) .add_plugin(CyberCamPlugin)
.add_plugin(CyberSpaceLightsPlugin) .add_plugin(CyberSpaceLightsPlugin)
.add_plugin(CyberUIPlugin) .add_plugin(CyberUIPlugin)
.add_plugin(CyberCollidersPlugin)
.add_startup_system(disable_mouse_trap) .add_startup_system(disable_mouse_trap)
.add_system(bevy::input::system::exit_on_esc_system); .add_system(bevy::input::system::exit_on_esc_system);

View file

@ -1,7 +1,7 @@
use bevy::prelude::*; use bevy::prelude::*;
use bevy_rapier3d::prelude::*; use bevy_rapier3d::prelude::*;
use crate::geometry::CyberBike; use crate::colliders::CyberBikeBody;
#[derive(Component)] #[derive(Component)]
struct UpText; struct UpText;
@ -34,7 +34,7 @@ fn setup_ui(mut commands: Commands, asset_server: Res<AssetServer>) {
} }
fn update_ui( fn update_ui(
state_query: Query<&RigidBodyVelocityComponent, With<CyberBike>>, state_query: Query<&RigidBodyVelocityComponent, With<CyberBikeBody>>,
mut text_query: Query<&mut Text, With<UpText>>, mut text_query: Query<&mut Text, With<UpText>>,
) { ) {
let mut text = text_query.single_mut(); let mut text = text_query.single_mut();