mirror of
https://github.com/eliasstepanik/big_space_with_trim.git
synced 2026-01-10 08:48:28 +00:00
parent
6c3cf18816
commit
a2e3f05a70
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "big_space"
|
||||
version = "0.4.0"
|
||||
version = "0.5.0"
|
||||
edition = "2021"
|
||||
description = "A floating origin plugin for bevy"
|
||||
license = "MIT OR Apache-2.0"
|
||||
@ -11,10 +11,10 @@ documentation = "https://docs.rs/crate/big_space/latest"
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
bevy = { version = "0.12", default_features = false }
|
||||
bevy = { version = "0.13", default_features = false }
|
||||
|
||||
[dev-dependencies]
|
||||
bevy = { version = "0.12", default-features = false, features = [
|
||||
bevy = { version = "0.13", default-features = false, features = [
|
||||
"bevy_winit",
|
||||
"default_font",
|
||||
"bevy_ui",
|
||||
@ -22,7 +22,7 @@ bevy = { version = "0.12", default-features = false, features = [
|
||||
"x11",
|
||||
"tonemapping_luts",
|
||||
] }
|
||||
bevy_framepace = { version = "0.14", default-features = false }
|
||||
bevy_framepace = { version = "0.15", default-features = false }
|
||||
|
||||
[features]
|
||||
default = ["debug", "camera", "bevy_render"]
|
||||
|
||||
@ -36,6 +36,7 @@ I intend to track the `main` branch of Bevy. PRs supporting this are welcome!
|
||||
|
||||
| bevy | big_space |
|
||||
| ---- | --------- |
|
||||
| 0.13 | 0.5 |
|
||||
| 0.12 | 0.4 |
|
||||
| 0.11 | 0.3 |
|
||||
| 0.10 | 0.2 |
|
||||
|
||||
@ -57,14 +57,7 @@ fn setup(
|
||||
mut meshes: ResMut<Assets<Mesh>>,
|
||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||
) {
|
||||
let mesh_handle = meshes.add(
|
||||
shape::Icosphere {
|
||||
radius: 0.1,
|
||||
..default()
|
||||
}
|
||||
.try_into()
|
||||
.unwrap(),
|
||||
);
|
||||
let mesh_handle = meshes.add(Sphere::new(0.1).mesh().ico(16).unwrap());
|
||||
let matl_handle = materials.add(StandardMaterial {
|
||||
base_color: Color::YELLOW,
|
||||
..default()
|
||||
@ -115,10 +108,6 @@ fn setup(
|
||||
commands.spawn((
|
||||
PointLightBundle {
|
||||
transform: Transform::from_xyz(4.0, 8.0, 4.0),
|
||||
point_light: PointLight {
|
||||
intensity: 10_000f32,
|
||||
..default()
|
||||
},
|
||||
..default()
|
||||
},
|
||||
GridCell::<i64>::default(),
|
||||
|
||||
@ -51,14 +51,7 @@ fn setup(
|
||||
.with_speed(1.0),
|
||||
));
|
||||
|
||||
let mesh_handle = meshes.add(
|
||||
shape::Icosphere {
|
||||
radius: 0.5,
|
||||
subdivisions: 32,
|
||||
}
|
||||
.try_into()
|
||||
.unwrap(),
|
||||
);
|
||||
let mesh_handle = meshes.add(Sphere::new(0.5).mesh().ico(32).unwrap());
|
||||
let matl_handle = materials.add(StandardMaterial {
|
||||
base_color: Color::BLUE,
|
||||
perceptual_roughness: 0.8,
|
||||
@ -107,7 +100,7 @@ fn ui_setup(mut commands: Commands) {
|
||||
..default()
|
||||
},
|
||||
)
|
||||
.with_text_alignment(TextAlignment::Left)
|
||||
.with_text_justify(JustifyText::Left)
|
||||
.with_style(Style {
|
||||
position_type: PositionType::Absolute,
|
||||
top: Val::Px(10.0),
|
||||
@ -133,7 +126,7 @@ fn ui_setup(mut commands: Commands) {
|
||||
left: Val::Px(10.0),
|
||||
..default()
|
||||
})
|
||||
.with_text_alignment(TextAlignment::Center),
|
||||
.with_text_justify(JustifyText::Center),
|
||||
FunFactText,
|
||||
));
|
||||
}
|
||||
@ -149,9 +142,10 @@ fn highlight_nearest_sphere(
|
||||
let Ok(transform) = objects.get(entity) else {
|
||||
return;
|
||||
};
|
||||
let (scale, rotation, translation) = transform.to_scale_rotation_translation();
|
||||
// Ignore rotation due to panicking in gizmos, as of bevy 0.13
|
||||
let (scale, _, translation) = transform.to_scale_rotation_translation();
|
||||
gizmos
|
||||
.sphere(translation, rotation, scale.x * 0.505, Color::RED)
|
||||
.sphere(translation, Quat::IDENTITY, scale.x * 0.505, Color::RED)
|
||||
.circle_segments(128);
|
||||
}
|
||||
|
||||
@ -247,8 +241,8 @@ fn closest<'a>(diameter: f32) -> (f32, &'a str) {
|
||||
fn cursor_grab_system(
|
||||
mut windows: Query<&mut Window, With<PrimaryWindow>>,
|
||||
mut cam: ResMut<CameraInput>,
|
||||
btn: Res<Input<MouseButton>>,
|
||||
key: Res<Input<KeyCode>>,
|
||||
btn: Res<ButtonInput<MouseButton>>,
|
||||
key: Res<ButtonInput<KeyCode>>,
|
||||
) {
|
||||
let Some(mut window) = windows.get_single_mut().ok() else {
|
||||
return;
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
//! independently from the camera, which is equivalent to what would happen when moving far from the
|
||||
//! origin when not using this plugin.
|
||||
|
||||
use bevy::prelude::{shape::UVSphere, *};
|
||||
use bevy::prelude::*;
|
||||
use big_space::{FloatingOrigin, FloatingOriginSettings, GridCell};
|
||||
|
||||
fn main() {
|
||||
@ -20,19 +20,19 @@ fn main() {
|
||||
}
|
||||
|
||||
/// You can put things really, really far away from the origin. The distance we use here is actually
|
||||
/// quite small, because we want the cubes to still be visible when the floating origin is far from
|
||||
/// the camera. If you go much further than this, the cubes will simply disappear in a *POOF* of
|
||||
/// quite small, because we want the mesh to still be visible when the floating origin is far from
|
||||
/// the camera. If you go much further than this, the mesh will simply disappear in a *POOF* of
|
||||
/// floating point error.
|
||||
///
|
||||
/// This plugin can function much further from the origin without any issues. Try setting this to:
|
||||
/// 10_000_000_000_000_000_000_000_000_000_000_000_000
|
||||
const DISTANCE: i128 = 20_000_000;
|
||||
const DISTANCE: i128 = 21_000_000;
|
||||
|
||||
/// Move the floating origin back to the "true" origin when the user presses the spacebar to emulate
|
||||
/// disabling the plugin. Normally you would make your active camera the floating origin to avoid
|
||||
/// this issue.
|
||||
fn toggle_plugin(
|
||||
input: Res<Input<KeyCode>>,
|
||||
input: Res<ButtonInput<KeyCode>>,
|
||||
settings: Res<big_space::FloatingOriginSettings>,
|
||||
mut text: Query<&mut Text>,
|
||||
mut disabled: Local<bool>,
|
||||
@ -74,7 +74,7 @@ fn toggle_plugin(
|
||||
};
|
||||
|
||||
text.single_mut().sections[0].value =
|
||||
format!("Press Spacebar to toggle: {msg}\nCamera distance to floating origin: {}\nCubes distance from origin: {}", thousands(dist), thousands(DISTANCE))
|
||||
format!("Press Spacebar to toggle: {msg}\nCamera distance to floating origin: {}\nMesh distance from origin: {}", thousands(dist), thousands(DISTANCE))
|
||||
}
|
||||
|
||||
#[derive(Component)]
|
||||
@ -108,15 +108,14 @@ fn setup_ui(mut commands: Commands) {
|
||||
});
|
||||
}
|
||||
|
||||
/// set up a simple scene with a "parent" cube and a "child" cube
|
||||
fn setup_scene(
|
||||
mut commands: Commands,
|
||||
mut meshes: ResMut<Assets<Mesh>>,
|
||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||
settings: Res<FloatingOriginSettings>,
|
||||
) {
|
||||
let cube_handle = meshes.add(Mesh::from(shape::Cube { size: 2.0 }));
|
||||
let cube_material_handle = materials.add(StandardMaterial {
|
||||
let mesh_handle = meshes.add(Sphere::new(1.5).mesh());
|
||||
let matl_handle = materials.add(StandardMaterial {
|
||||
base_color: Color::rgb(0.8, 0.7, 0.6),
|
||||
..default()
|
||||
});
|
||||
@ -129,8 +128,8 @@ fn setup_scene(
|
||||
// plugin isn't used.
|
||||
commands.spawn((
|
||||
PbrBundle {
|
||||
mesh: meshes.add(UVSphere::default().into()),
|
||||
material: materials.add(Color::RED.into()),
|
||||
mesh: meshes.add(Sphere::default().mesh()),
|
||||
material: materials.add(StandardMaterial::from(Color::RED)),
|
||||
transform: Transform::from_scale(Vec3::splat(10000.0)),
|
||||
..default()
|
||||
},
|
||||
@ -138,23 +137,21 @@ fn setup_scene(
|
||||
FloatingOrigin,
|
||||
));
|
||||
|
||||
// parent cube
|
||||
commands
|
||||
.spawn((
|
||||
PbrBundle {
|
||||
mesh: cube_handle.clone(),
|
||||
material: cube_material_handle.clone(),
|
||||
mesh: mesh_handle.clone(),
|
||||
material: matl_handle.clone(),
|
||||
..default()
|
||||
},
|
||||
distant_grid_cell,
|
||||
Rotator,
|
||||
))
|
||||
.with_children(|parent| {
|
||||
// child cube
|
||||
parent.spawn(PbrBundle {
|
||||
mesh: cube_handle,
|
||||
material: cube_material_handle,
|
||||
transform: Transform::from_xyz(0.0, 0.0, 3.0),
|
||||
mesh: mesh_handle,
|
||||
material: matl_handle,
|
||||
transform: Transform::from_xyz(0.0, 0.0, 4.0),
|
||||
..default()
|
||||
});
|
||||
});
|
||||
|
||||
@ -99,7 +99,7 @@ impl Default for CameraController {
|
||||
}
|
||||
}
|
||||
|
||||
/// Input state used to command camera motion. Reset every time the values are read to update the
|
||||
/// ButtonInput state used to command camera motion. Reset every time the values are read to update the
|
||||
/// camera. Allows you to map any input to camera motions. Uses aircraft principle axes conventions.
|
||||
#[derive(Clone, Debug, Default, Reflect, Resource)]
|
||||
pub struct CameraInput {
|
||||
@ -147,20 +147,20 @@ impl CameraInput {
|
||||
|
||||
/// Provides sensible keyboard and mouse input defaults
|
||||
pub fn default_camera_inputs(
|
||||
keyboard: Res<Input<KeyCode>>,
|
||||
keyboard: Res<ButtonInput<KeyCode>>,
|
||||
mut mouse_move: EventReader<MouseMotion>,
|
||||
mut cam: ResMut<CameraInput>,
|
||||
) {
|
||||
keyboard.pressed(KeyCode::W).then(|| cam.forward -= 1.0);
|
||||
keyboard.pressed(KeyCode::S).then(|| cam.forward += 1.0);
|
||||
keyboard.pressed(KeyCode::A).then(|| cam.right -= 1.0);
|
||||
keyboard.pressed(KeyCode::D).then(|| cam.right += 1.0);
|
||||
keyboard.pressed(KeyCode::KeyW).then(|| cam.forward -= 1.0);
|
||||
keyboard.pressed(KeyCode::KeyS).then(|| cam.forward += 1.0);
|
||||
keyboard.pressed(KeyCode::KeyA).then(|| cam.right -= 1.0);
|
||||
keyboard.pressed(KeyCode::KeyD).then(|| cam.right += 1.0);
|
||||
keyboard.pressed(KeyCode::Space).then(|| cam.up += 1.0);
|
||||
keyboard
|
||||
.pressed(KeyCode::ControlLeft)
|
||||
.then(|| cam.up -= 1.0);
|
||||
keyboard.pressed(KeyCode::Q).then(|| cam.roll += 1.0);
|
||||
keyboard.pressed(KeyCode::E).then(|| cam.roll -= 1.0);
|
||||
keyboard.pressed(KeyCode::KeyQ).then(|| cam.roll += 1.0);
|
||||
keyboard.pressed(KeyCode::KeyE).then(|| cam.roll -= 1.0);
|
||||
keyboard
|
||||
.pressed(KeyCode::ShiftLeft)
|
||||
.then(|| cam.boost = true);
|
||||
@ -215,7 +215,7 @@ pub fn camera_controller<P: GridPrecision>(
|
||||
let (vel_t_current, vel_r_current) = (controller.vel_translation, controller.vel_rotation);
|
||||
let (vel_t_target, vel_r_target) = input.target_velocity(speed, time.delta_seconds_f64());
|
||||
|
||||
let cam_rot = cam_transform.rotation.as_f64();
|
||||
let cam_rot = cam_transform.rotation.as_dquat();
|
||||
let vel_t_next = cam_rot * vel_t_target; // Orients the translation to match the camera
|
||||
let vel_t_next = vel_t_current.lerp(vel_t_next, lerp_translation);
|
||||
// Convert the high precision translation to a grid cell and low precision translation
|
||||
@ -224,7 +224,7 @@ pub fn camera_controller<P: GridPrecision>(
|
||||
cam_transform.translation += new_translation;
|
||||
|
||||
let new_rotation = vel_r_current.slerp(vel_r_target, lerp_rotation);
|
||||
cam_transform.rotation *= new_rotation.as_f32();
|
||||
cam_transform.rotation *= new_rotation.as_quat();
|
||||
|
||||
// Store the new velocity to be used in the next frame
|
||||
controller.vel_translation = vel_t_next;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user