mirror of
https://github.com/eliasstepanik/big_space_with_trim.git
synced 2026-01-11 18:48:27 +00:00
v 0.7.0 (#29)
This commit is contained in:
parent
6fa7d31a0e
commit
87e96a700d
35
Cargo.toml
35
Cargo.toml
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "big_space"
|
name = "big_space"
|
||||||
version = "0.6.0"
|
version = "0.7.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
description = "A floating origin plugin for bevy"
|
description = "A floating origin plugin for bevy"
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
@ -9,22 +9,23 @@ repository = "https://github.com/aevyrie/big_space"
|
|||||||
documentation = "https://docs.rs/crate/big_space/latest"
|
documentation = "https://docs.rs/crate/big_space/latest"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bevy_app = { version = "0.13", default_features = false }
|
bevy_app = { version = "0.14.0", default-features = false }
|
||||||
bevy_ecs = { version = "0.13", default_features = false }
|
bevy_ecs = { version = "0.14.0", default-features = false }
|
||||||
bevy_hierarchy = { version = "0.13", default_features = false }
|
bevy_hierarchy = { version = "0.14.0", default-features = false }
|
||||||
bevy_log = { version = "0.13", default_features = false }
|
bevy_log = { version = "0.14.0", default-features = false }
|
||||||
bevy_math = { version = "0.13", default_features = false }
|
bevy_math = { version = "0.14.0", default-features = false }
|
||||||
bevy_reflect = { version = "0.13", default_features = false }
|
bevy_reflect = { version = "0.14.0", default-features = false }
|
||||||
bevy_transform = { version = "0.13", default_features = false }
|
bevy_transform = { version = "0.14.0", default-features = false }
|
||||||
bevy_utils = { version = "0.13", default_features = false }
|
bevy_utils = { version = "0.14.0", default-features = false }
|
||||||
# Optional
|
# Optional
|
||||||
bevy_gizmos = { version = "0.13", default_features = false, optional = true }
|
bevy_color = { version = "0.14.0", default-features = false, optional = true }
|
||||||
bevy_render = { version = "0.13", default_features = false, optional = true }
|
bevy_gizmos = { version = "0.14.0", default-features = false, optional = true }
|
||||||
bevy_input = { version = "0.13", default_features = false, optional = true }
|
bevy_render = { version = "0.14.0", default-features = false, optional = true }
|
||||||
bevy_time = { version = "0.13", default_features = false, optional = true }
|
bevy_input = { version = "0.14.0", default-features = false, optional = true }
|
||||||
|
bevy_time = { version = "0.14.0", default-features = false, optional = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
bevy = { version = "0.13", default-features = false, features = [
|
bevy = { version = "0.14.0", default-features = false, features = [
|
||||||
"bevy_scene",
|
"bevy_scene",
|
||||||
"bevy_gltf",
|
"bevy_gltf",
|
||||||
"bevy_winit",
|
"bevy_winit",
|
||||||
@ -34,14 +35,14 @@ bevy = { version = "0.13", default-features = false, features = [
|
|||||||
"bevy_gizmos",
|
"bevy_gizmos",
|
||||||
"x11",
|
"x11",
|
||||||
"tonemapping_luts",
|
"tonemapping_luts",
|
||||||
"multi-threaded",
|
"multi_threaded",
|
||||||
] }
|
] }
|
||||||
bevy-inspector-egui = "0.24"
|
# bevy-inspector-egui = "0.24"
|
||||||
rand = "0.8.5"
|
rand = "0.8.5"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["debug", "camera", "bevy_render"]
|
default = ["debug", "camera", "bevy_render"]
|
||||||
debug = ["bevy_gizmos", "bevy_render"]
|
debug = ["bevy_gizmos", "bevy_color"]
|
||||||
camera = ["bevy_render", "bevy_time", "bevy_input"]
|
camera = ["bevy_render", "bevy_time", "bevy_input"]
|
||||||
|
|
||||||
[[example]]
|
[[example]]
|
||||||
|
|||||||
@ -38,6 +38,7 @@ From the docs: https://docs.rs/big_space/latest/big_space/precision/trait.GridPr
|
|||||||
|
|
||||||
| bevy | big_space |
|
| bevy | big_space |
|
||||||
| ---- | --------- |
|
| ---- | --------- |
|
||||||
|
| 0.14 | 0.7 |
|
||||||
| 0.13 | 0.5, 0.6 |
|
| 0.13 | 0.5, 0.6 |
|
||||||
| 0.12 | 0.4 |
|
| 0.12 | 0.4 |
|
||||||
| 0.11 | 0.3 |
|
| 0.11 | 0.3 |
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
#![allow(clippy::type_complexity)]
|
#![allow(clippy::type_complexity)]
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
use bevy_color::palettes;
|
||||||
use big_space::{commands::BigSpaceCommands, reference_frame::ReferenceFrame, FloatingOrigin};
|
use big_space::{commands::BigSpaceCommands, reference_frame::ReferenceFrame, FloatingOrigin};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
@ -13,7 +14,7 @@ fn main() {
|
|||||||
.insert_resource(ClearColor(Color::BLACK))
|
.insert_resource(ClearColor(Color::BLACK))
|
||||||
.add_systems(Startup, setup)
|
.add_systems(Startup, setup)
|
||||||
.add_systems(Update, (movement, rotation))
|
.add_systems(Update, (movement, rotation))
|
||||||
.run()
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
@ -61,7 +62,7 @@ fn setup(
|
|||||||
) {
|
) {
|
||||||
let mesh_handle = meshes.add(Sphere::new(0.1).mesh().ico(16).unwrap());
|
let mesh_handle = meshes.add(Sphere::new(0.1).mesh().ico(16).unwrap());
|
||||||
let matl_handle = materials.add(StandardMaterial {
|
let matl_handle = materials.add(StandardMaterial {
|
||||||
base_color: Color::YELLOW,
|
base_color: Color::Srgba(palettes::basic::YELLOW),
|
||||||
..default()
|
..default()
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -3,6 +3,7 @@ use bevy::{
|
|||||||
transform::TransformSystem,
|
transform::TransformSystem,
|
||||||
window::{CursorGrabMode, PrimaryWindow},
|
window::{CursorGrabMode, PrimaryWindow},
|
||||||
};
|
};
|
||||||
|
use bevy_color::palettes;
|
||||||
use big_space::{
|
use big_space::{
|
||||||
camera::{CameraController, CameraInput},
|
camera::{CameraController, CameraInput},
|
||||||
commands::BigSpaceCommands,
|
commands::BigSpaceCommands,
|
||||||
@ -26,7 +27,7 @@ fn main() {
|
|||||||
PostUpdate,
|
PostUpdate,
|
||||||
highlight_nearest_sphere.after(TransformSystem::TransformPropagate),
|
highlight_nearest_sphere.after(TransformSystem::TransformPropagate),
|
||||||
)
|
)
|
||||||
.run()
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn setup(
|
fn setup(
|
||||||
@ -54,7 +55,7 @@ fn setup(
|
|||||||
|
|
||||||
let mesh_handle = meshes.add(Sphere::new(0.5).mesh().ico(32).unwrap());
|
let mesh_handle = meshes.add(Sphere::new(0.5).mesh().ico(32).unwrap());
|
||||||
let matl_handle = materials.add(StandardMaterial {
|
let matl_handle = materials.add(StandardMaterial {
|
||||||
base_color: Color::BLUE,
|
base_color: Color::Srgba(palettes::basic::BLUE),
|
||||||
perceptual_roughness: 0.8,
|
perceptual_roughness: 0.8,
|
||||||
reflectance: 1.0,
|
reflectance: 1.0,
|
||||||
..default()
|
..default()
|
||||||
@ -78,7 +79,7 @@ fn setup(
|
|||||||
// light
|
// light
|
||||||
root.spawn_spatial(DirectionalLightBundle {
|
root.spawn_spatial(DirectionalLightBundle {
|
||||||
directional_light: DirectionalLight {
|
directional_light: DirectionalLight {
|
||||||
illuminance: 100_000.0,
|
illuminance: 10_000.0,
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
..default()
|
..default()
|
||||||
@ -145,10 +146,15 @@ fn highlight_nearest_sphere(
|
|||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
// Ignore rotation due to panicking in gizmos, as of bevy 0.13
|
// Ignore rotation due to panicking in gizmos, as of bevy 0.13
|
||||||
let (scale, rotation, translation) = transform.to_scale_rotation_translation();
|
let (scale, _, translation) = transform.to_scale_rotation_translation();
|
||||||
gizmos
|
gizmos
|
||||||
.sphere(translation, rotation, scale.x * 0.505, Color::RED)
|
.sphere(
|
||||||
.circle_segments(128);
|
translation,
|
||||||
|
Quat::IDENTITY, // Bevy likes to explode on non-normalized quats in gizmos,
|
||||||
|
scale.x * 0.505,
|
||||||
|
Color::Srgba(palettes::basic::RED),
|
||||||
|
)
|
||||||
|
.resolution(128);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::type_complexity)]
|
#[allow(clippy::type_complexity)]
|
||||||
|
|||||||
@ -20,7 +20,7 @@ fn main() {
|
|||||||
))
|
))
|
||||||
.add_systems(Startup, (setup_scene, setup_ui))
|
.add_systems(Startup, (setup_scene, setup_ui))
|
||||||
.add_systems(Update, (rotator_system, toggle_plugin))
|
.add_systems(Update, (rotator_system, toggle_plugin))
|
||||||
.run()
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// You can put things really, really far away from the origin. The distance we use here is actually
|
/// You can put things really, really far away from the origin. The distance we use here is actually
|
||||||
|
|||||||
@ -1,18 +1,19 @@
|
|||||||
//! This example demonstrates error accumulating from parent to children in nested reference frames.
|
//! This example demonstrates error accumulating from parent to children in nested reference frames.
|
||||||
use bevy::{math::DVec3, prelude::*};
|
use bevy::{math::DVec3, prelude::*};
|
||||||
|
use bevy_color::palettes;
|
||||||
use big_space::{commands::BigSpaceCommands, reference_frame::ReferenceFrame, FloatingOrigin};
|
use big_space::{commands::BigSpaceCommands, reference_frame::ReferenceFrame, FloatingOrigin};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
App::new()
|
App::new()
|
||||||
.add_plugins((
|
.add_plugins((
|
||||||
DefaultPlugins.build().disable::<TransformPlugin>(),
|
DefaultPlugins.build().disable::<TransformPlugin>(),
|
||||||
bevy_inspector_egui::quick::WorldInspectorPlugin::new(),
|
// bevy_inspector_egui::quick::WorldInspectorPlugin::new(),
|
||||||
big_space::BigSpacePlugin::<i64>::default(),
|
big_space::BigSpacePlugin::<i64>::default(),
|
||||||
big_space::camera::CameraControllerPlugin::<i64>::default(),
|
big_space::camera::CameraControllerPlugin::<i64>::default(),
|
||||||
big_space::debug::FloatingOriginDebugPlugin::<i64>::default(),
|
big_space::debug::FloatingOriginDebugPlugin::<i64>::default(),
|
||||||
))
|
))
|
||||||
.add_systems(Startup, setup_scene)
|
.add_systems(Startup, setup_scene)
|
||||||
.run()
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
// The nearby object is NEARBY meters away from us. The distance object is DISTANT meters away from
|
// The nearby object is NEARBY meters away from us. The distance object is DISTANT meters away from
|
||||||
@ -28,7 +29,7 @@ fn setup_scene(
|
|||||||
) {
|
) {
|
||||||
let mesh_handle = meshes.add(Sphere::new(SPHERE_RADIUS).mesh());
|
let mesh_handle = meshes.add(Sphere::new(SPHERE_RADIUS).mesh());
|
||||||
let matl_handle = materials.add(StandardMaterial {
|
let matl_handle = materials.add(StandardMaterial {
|
||||||
base_color: Color::rgb(0.8, 0.7, 0.6),
|
base_color: Color::srgb(0.8, 0.7, 0.6),
|
||||||
..default()
|
..default()
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -37,7 +38,7 @@ fn setup_scene(
|
|||||||
|root_frame| {
|
|root_frame| {
|
||||||
root_frame.spawn_spatial(PbrBundle {
|
root_frame.spawn_spatial(PbrBundle {
|
||||||
mesh: mesh_handle.clone(),
|
mesh: mesh_handle.clone(),
|
||||||
material: materials.add(Color::BLUE),
|
material: materials.add(Color::from(palettes::css::BLUE)),
|
||||||
transform: Transform::from_translation(NEARBY),
|
transform: Transform::from_translation(NEARBY),
|
||||||
..default()
|
..default()
|
||||||
});
|
});
|
||||||
@ -46,8 +47,8 @@ fn setup_scene(
|
|||||||
root_frame.with_frame(
|
root_frame.with_frame(
|
||||||
ReferenceFrame::new(SPHERE_RADIUS * 100.0, 0.0),
|
ReferenceFrame::new(SPHERE_RADIUS * 100.0, 0.0),
|
||||||
|parent_frame| {
|
|parent_frame| {
|
||||||
// This function introduces a small amount of error, because it can only work up to
|
// This function introduces a small amount of error, because it can only work up
|
||||||
// double precision floats. (f64).
|
// to double precision floats. (f64).
|
||||||
let child = parent_frame
|
let child = parent_frame
|
||||||
.frame()
|
.frame()
|
||||||
.translation_to_grid(-DISTANT + NEARBY.as_dvec3());
|
.translation_to_grid(-DISTANT + NEARBY.as_dvec3());
|
||||||
@ -60,16 +61,16 @@ fn setup_scene(
|
|||||||
parent_frame.insert(parent.0);
|
parent_frame.insert(parent.0);
|
||||||
|
|
||||||
parent_frame.with_children(|child_builder| {
|
parent_frame.with_children(|child_builder| {
|
||||||
// A green sphere that is a child of the sphere very far from the origin. This
|
// A green sphere that is a child of the sphere very far from the origin.
|
||||||
// child is very far from its parent, and should be located exactly at the
|
// This child is very far from its parent, and should be located exactly at
|
||||||
// origin (if there was no floating point error). The distance from the green
|
// the origin (if there was no floating point error). The distance from the
|
||||||
// sphere to the red sphere is the error caused by float imprecision. Note that
|
// green sphere to the red sphere is the error caused by float imprecision.
|
||||||
// the sphere does not have any rendering artifacts, its position just has a
|
// Note that the sphere does not have any rendering artifacts, its position
|
||||||
// fixed error.
|
// just has a fixed error.
|
||||||
child_builder.spawn((
|
child_builder.spawn((
|
||||||
PbrBundle {
|
PbrBundle {
|
||||||
mesh: mesh_handle,
|
mesh: mesh_handle,
|
||||||
material: materials.add(Color::GREEN),
|
material: materials.add(Color::from(palettes::css::GREEN)),
|
||||||
transform: Transform::from_translation(child.1),
|
transform: Transform::from_translation(child.1),
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
|
|||||||
@ -11,6 +11,7 @@ use bevy::{
|
|||||||
render::camera::Exposure,
|
render::camera::Exposure,
|
||||||
transform::TransformSystem,
|
transform::TransformSystem,
|
||||||
};
|
};
|
||||||
|
use bevy_color::palettes;
|
||||||
use big_space::{
|
use big_space::{
|
||||||
camera::{CameraController, CameraInput},
|
camera::{CameraController, CameraInput},
|
||||||
commands::BigSpaceCommands,
|
commands::BigSpaceCommands,
|
||||||
@ -51,7 +52,7 @@ fn main() {
|
|||||||
)
|
)
|
||||||
.register_type::<Sun>()
|
.register_type::<Sun>()
|
||||||
.register_type::<Rotates>()
|
.register_type::<Rotates>()
|
||||||
.run()
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
const EARTH_ORBIT_RADIUS_M: f64 = 149.60e9;
|
const EARTH_ORBIT_RADIUS_M: f64 = 149.60e9;
|
||||||
@ -129,7 +130,7 @@ fn spawn_solar_system(
|
|||||||
let earth_mesh_handle = meshes.add(Sphere::new(1.0).mesh().ico(35).unwrap());
|
let earth_mesh_handle = meshes.add(Sphere::new(1.0).mesh().ico(35).unwrap());
|
||||||
let moon_mesh_handle = meshes.add(Sphere::new(MOON_RADIUS_M as f32).mesh().ico(15).unwrap());
|
let moon_mesh_handle = meshes.add(Sphere::new(MOON_RADIUS_M as f32).mesh().ico(15).unwrap());
|
||||||
let ball_mesh_handle = meshes.add(Sphere::new(5.0).mesh().ico(5).unwrap());
|
let ball_mesh_handle = meshes.add(Sphere::new(5.0).mesh().ico(5).unwrap());
|
||||||
let plane_mesh_handle = meshes.add(Plane3d::new(Vec3::X));
|
let plane_mesh_handle = meshes.add(Plane3d::new(Vec3::X, Vec2::splat(0.5)));
|
||||||
|
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
PrimaryLight,
|
PrimaryLight,
|
||||||
@ -160,7 +161,7 @@ fn spawn_solar_system(
|
|||||||
mesh: sun_mesh_handle,
|
mesh: sun_mesh_handle,
|
||||||
material: materials.add(StandardMaterial {
|
material: materials.add(StandardMaterial {
|
||||||
base_color: Color::WHITE,
|
base_color: Color::WHITE,
|
||||||
emissive: Color::rgb_linear(100000000., 100000000., 100000000.),
|
emissive: LinearRgba::rgb(100000., 100000., 100000.),
|
||||||
..default()
|
..default()
|
||||||
}),
|
}),
|
||||||
..default()
|
..default()
|
||||||
@ -177,7 +178,7 @@ fn spawn_solar_system(
|
|||||||
PbrBundle {
|
PbrBundle {
|
||||||
mesh: earth_mesh_handle,
|
mesh: earth_mesh_handle,
|
||||||
material: materials.add(StandardMaterial {
|
material: materials.add(StandardMaterial {
|
||||||
base_color: Color::BLUE,
|
base_color: Color::Srgba(palettes::css::BLUE),
|
||||||
perceptual_roughness: 0.8,
|
perceptual_roughness: 0.8,
|
||||||
reflectance: 1.0,
|
reflectance: 1.0,
|
||||||
..default()
|
..default()
|
||||||
@ -197,7 +198,7 @@ fn spawn_solar_system(
|
|||||||
PbrBundle {
|
PbrBundle {
|
||||||
mesh: moon_mesh_handle,
|
mesh: moon_mesh_handle,
|
||||||
material: materials.add(StandardMaterial {
|
material: materials.add(StandardMaterial {
|
||||||
base_color: Color::GRAY,
|
base_color: Color::Srgba(palettes::css::GRAY),
|
||||||
perceptual_roughness: 1.0,
|
perceptual_roughness: 1.0,
|
||||||
reflectance: 0.0,
|
reflectance: 0.0,
|
||||||
..default()
|
..default()
|
||||||
@ -226,7 +227,7 @@ fn spawn_solar_system(
|
|||||||
children.spawn((PbrBundle {
|
children.spawn((PbrBundle {
|
||||||
mesh: plane_mesh_handle,
|
mesh: plane_mesh_handle,
|
||||||
material: materials.add(StandardMaterial {
|
material: materials.add(StandardMaterial {
|
||||||
base_color: Color::DARK_GREEN,
|
base_color: Color::Srgba(palettes::css::DARK_GREEN),
|
||||||
perceptual_roughness: 1.0,
|
perceptual_roughness: 1.0,
|
||||||
reflectance: 0.0,
|
reflectance: 0.0,
|
||||||
..default()
|
..default()
|
||||||
@ -282,7 +283,7 @@ fn spawn_solar_system(
|
|||||||
|
|
||||||
let star_mat = materials.add(StandardMaterial {
|
let star_mat = materials.add(StandardMaterial {
|
||||||
base_color: Color::WHITE,
|
base_color: Color::WHITE,
|
||||||
emissive: Color::rgb_linear(100000., 100000., 100000.),
|
emissive: LinearRgba::rgb(2., 2., 2.),
|
||||||
..default()
|
..default()
|
||||||
});
|
});
|
||||||
let star_mesh_handle = meshes.add(Sphere::new(1e10).mesh().ico(5).unwrap());
|
let star_mesh_handle = meshes.add(Sphere::new(1e10).mesh().ico(5).unwrap());
|
||||||
|
|||||||
@ -9,6 +9,7 @@ use bevy::{
|
|||||||
render::{camera::Viewport, view::RenderLayers},
|
render::{camera::Viewport, view::RenderLayers},
|
||||||
transform::TransformSystem,
|
transform::TransformSystem,
|
||||||
};
|
};
|
||||||
|
use bevy_color::palettes;
|
||||||
use big_space::{
|
use big_space::{
|
||||||
camera::{CameraController, CameraControllerPlugin},
|
camera::{CameraController, CameraControllerPlugin},
|
||||||
commands::BigSpaceCommands,
|
commands::BigSpaceCommands,
|
||||||
@ -33,7 +34,7 @@ fn main() {
|
|||||||
.after(big_space::camera::camera_controller::<i32>)
|
.after(big_space::camera::camera_controller::<i32>)
|
||||||
.before(TransformSystem::TransformPropagate),
|
.before(TransformSystem::TransformPropagate),
|
||||||
)
|
)
|
||||||
.run()
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
@ -58,7 +59,7 @@ fn setup(
|
|||||||
transform: Transform::default().looking_to(Vec3::NEG_ONE, Vec3::Y),
|
transform: Transform::default().looking_to(Vec3::NEG_ONE, Vec3::Y),
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
RenderLayers::all(),
|
RenderLayers::from_layers(&[1, 2]),
|
||||||
));
|
));
|
||||||
|
|
||||||
// Big Space 1
|
// Big Space 1
|
||||||
@ -80,7 +81,7 @@ fn setup(
|
|||||||
PbrBundle {
|
PbrBundle {
|
||||||
mesh: meshes.add(Cuboid::new(1.0, 2.0, 1.0)),
|
mesh: meshes.add(Cuboid::new(1.0, 2.0, 1.0)),
|
||||||
material: materials.add(StandardMaterial {
|
material: materials.add(StandardMaterial {
|
||||||
base_color: Color::YELLOW,
|
base_color: Color::Srgba(palettes::css::YELLOW),
|
||||||
..default()
|
..default()
|
||||||
}),
|
}),
|
||||||
..default()
|
..default()
|
||||||
@ -94,7 +95,7 @@ fn setup(
|
|||||||
PbrBundle {
|
PbrBundle {
|
||||||
mesh: meshes.add(Cuboid::new(1.0, 2.0, 1.0)),
|
mesh: meshes.add(Cuboid::new(1.0, 2.0, 1.0)),
|
||||||
material: materials.add(StandardMaterial {
|
material: materials.add(StandardMaterial {
|
||||||
base_color: Color::PINK,
|
base_color: Color::Srgba(palettes::css::FUCHSIA),
|
||||||
..default()
|
..default()
|
||||||
}),
|
}),
|
||||||
..default()
|
..default()
|
||||||
@ -106,7 +107,7 @@ fn setup(
|
|||||||
PbrBundle {
|
PbrBundle {
|
||||||
mesh: meshes.add(Sphere::new(1.0).mesh().ico(35).unwrap()),
|
mesh: meshes.add(Sphere::new(1.0).mesh().ico(35).unwrap()),
|
||||||
material: materials.add(StandardMaterial {
|
material: materials.add(StandardMaterial {
|
||||||
base_color: Color::BLUE,
|
base_color: Color::Srgba(palettes::css::BLUE),
|
||||||
..default()
|
..default()
|
||||||
}),
|
}),
|
||||||
transform: Transform::from_xyz(1_000_000.0, 0.0, 0.0)
|
transform: Transform::from_xyz(1_000_000.0, 0.0, 0.0)
|
||||||
@ -120,7 +121,7 @@ fn setup(
|
|||||||
PbrBundle {
|
PbrBundle {
|
||||||
mesh: meshes.add(Sphere::new(1.0).mesh().ico(35).unwrap()),
|
mesh: meshes.add(Sphere::new(1.0).mesh().ico(35).unwrap()),
|
||||||
material: materials.add(StandardMaterial {
|
material: materials.add(StandardMaterial {
|
||||||
base_color: Color::GREEN,
|
base_color: Color::Srgba(palettes::css::GREEN),
|
||||||
..default()
|
..default()
|
||||||
}),
|
}),
|
||||||
transform: Transform::from_xyz(-1_000_000.0, 0.0, 0.0)
|
transform: Transform::from_xyz(-1_000_000.0, 0.0, 0.0)
|
||||||
@ -154,7 +155,7 @@ fn setup(
|
|||||||
PbrBundle {
|
PbrBundle {
|
||||||
mesh: meshes.add(Cuboid::new(1.0, 2.0, 1.0)),
|
mesh: meshes.add(Cuboid::new(1.0, 2.0, 1.0)),
|
||||||
material: materials.add(StandardMaterial {
|
material: materials.add(StandardMaterial {
|
||||||
base_color: Color::PINK,
|
base_color: Color::Srgba(palettes::css::PINK),
|
||||||
..default()
|
..default()
|
||||||
}),
|
}),
|
||||||
..default()
|
..default()
|
||||||
@ -168,7 +169,7 @@ fn setup(
|
|||||||
PbrBundle {
|
PbrBundle {
|
||||||
mesh: meshes.add(Cuboid::new(1.0, 2.0, 1.0)),
|
mesh: meshes.add(Cuboid::new(1.0, 2.0, 1.0)),
|
||||||
material: materials.add(StandardMaterial {
|
material: materials.add(StandardMaterial {
|
||||||
base_color: Color::YELLOW,
|
base_color: Color::Srgba(palettes::css::YELLOW),
|
||||||
..default()
|
..default()
|
||||||
}),
|
}),
|
||||||
..default()
|
..default()
|
||||||
@ -180,7 +181,7 @@ fn setup(
|
|||||||
PbrBundle {
|
PbrBundle {
|
||||||
mesh: meshes.add(Sphere::new(1.0).mesh().ico(35).unwrap()),
|
mesh: meshes.add(Sphere::new(1.0).mesh().ico(35).unwrap()),
|
||||||
material: materials.add(StandardMaterial {
|
material: materials.add(StandardMaterial {
|
||||||
base_color: Color::BLUE,
|
base_color: Color::Srgba(palettes::css::BLUE),
|
||||||
..default()
|
..default()
|
||||||
}),
|
}),
|
||||||
transform: Transform::from_xyz(1_000_000.0, 0.0, 0.0)
|
transform: Transform::from_xyz(1_000_000.0, 0.0, 0.0)
|
||||||
@ -194,7 +195,7 @@ fn setup(
|
|||||||
PbrBundle {
|
PbrBundle {
|
||||||
mesh: meshes.add(Sphere::new(1.0).mesh().ico(35).unwrap()),
|
mesh: meshes.add(Sphere::new(1.0).mesh().ico(35).unwrap()),
|
||||||
material: materials.add(StandardMaterial {
|
material: materials.add(StandardMaterial {
|
||||||
base_color: Color::GREEN,
|
base_color: Color::Srgba(palettes::css::GREEN),
|
||||||
..default()
|
..default()
|
||||||
}),
|
}),
|
||||||
transform: Transform::from_xyz(-1_000_000.0, 0.0, 0.0)
|
transform: Transform::from_xyz(-1_000_000.0, 0.0, 0.0)
|
||||||
|
|||||||
@ -45,6 +45,12 @@ pub struct CameraController {
|
|||||||
pub rotational_smoothness: f64,
|
pub rotational_smoothness: f64,
|
||||||
/// Base speed.
|
/// Base speed.
|
||||||
pub speed: f64,
|
pub speed: f64,
|
||||||
|
/// Rotational yaw speed multiplier.
|
||||||
|
pub speed_yaw: f64,
|
||||||
|
/// Rotational pitch speed multiplier.
|
||||||
|
pub speed_pitch: f64,
|
||||||
|
/// Rotational roll speed multiplier.
|
||||||
|
pub speed_roll: f64,
|
||||||
/// Minimum and maximum speed.
|
/// Minimum and maximum speed.
|
||||||
pub speed_bounds: [f64; 2],
|
pub speed_bounds: [f64; 2],
|
||||||
/// Whether the camera should slow down when approaching an entity's [`Aabb`].
|
/// Whether the camera should slow down when approaching an entity's [`Aabb`].
|
||||||
@ -73,6 +79,25 @@ impl CameraController {
|
|||||||
self.speed = speed;
|
self.speed = speed;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Sets the yaw angular velocity of the controller, and returns the modified result.
|
||||||
|
pub fn with_speed_yaw(mut self, speed: f64) -> Self {
|
||||||
|
self.speed_yaw = speed;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Sets the pitch angular velocity of the controller, and returns the modified result.
|
||||||
|
pub fn with_speed_pitch(mut self, speed: f64) -> Self {
|
||||||
|
self.speed_pitch = speed;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Sets the pitch angular velocity of the controller, and returns the modified result.
|
||||||
|
pub fn with_speed_roll(mut self, speed: f64) -> Self {
|
||||||
|
self.speed_roll = speed;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// Sets the speed of the controller, and returns the modified result.
|
/// Sets the speed of the controller, and returns the modified result.
|
||||||
pub fn with_speed_bounds(mut self, speed_limits: [f64; 2]) -> Self {
|
pub fn with_speed_bounds(mut self, speed_limits: [f64; 2]) -> Self {
|
||||||
self.speed_bounds = speed_limits;
|
self.speed_bounds = speed_limits;
|
||||||
@ -96,6 +121,9 @@ impl Default for CameraController {
|
|||||||
smoothness: 0.8,
|
smoothness: 0.8,
|
||||||
rotational_smoothness: 0.5,
|
rotational_smoothness: 0.5,
|
||||||
speed: 1.0,
|
speed: 1.0,
|
||||||
|
speed_pitch: 1.0,
|
||||||
|
speed_yaw: 1.0,
|
||||||
|
speed_roll: 1.0,
|
||||||
speed_bounds: [1e-17, 1e30],
|
speed_bounds: [1e-17, 1e30],
|
||||||
slow_near_objects: true,
|
slow_near_objects: true,
|
||||||
nearest_object: None,
|
nearest_object: None,
|
||||||
@ -137,12 +165,17 @@ impl CameraInput {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the desired velocity transform.
|
/// Returns the desired velocity transform.
|
||||||
pub fn target_velocity(&self, speed: f64, dt: f64) -> (DVec3, DQuat) {
|
pub fn target_velocity(
|
||||||
|
&self,
|
||||||
|
controller: &CameraController,
|
||||||
|
speed: f64,
|
||||||
|
dt: f64,
|
||||||
|
) -> (DVec3, DQuat) {
|
||||||
let rotation = DQuat::from_euler(
|
let rotation = DQuat::from_euler(
|
||||||
EulerRot::XYZ,
|
EulerRot::XYZ,
|
||||||
self.pitch * dt,
|
self.pitch * dt * controller.speed_pitch,
|
||||||
self.yaw * dt,
|
self.yaw * dt * controller.speed_yaw,
|
||||||
self.roll * dt,
|
self.roll * dt * controller.speed_roll,
|
||||||
);
|
);
|
||||||
|
|
||||||
let translation = DVec3::new(self.right, self.up, self.forward) * speed * dt;
|
let translation = DVec3::new(self.right, self.up, self.forward) * speed * dt;
|
||||||
@ -196,15 +229,15 @@ pub fn nearest_objects_in_frame<P: GridPrecision>(
|
|||||||
let Ok((cam_entity, mut camera, cam_pos, cam_layer)) = camera.get_single_mut() else {
|
let Ok((cam_entity, mut camera, cam_pos, cam_layer)) = camera.get_single_mut() else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
let cam_layer = cam_layer.copied().unwrap_or(RenderLayers::all());
|
let cam_layer = cam_layer.to_owned().unwrap_or_default();
|
||||||
let cam_children: HashSet<Entity> = children.iter_descendants(cam_entity).collect();
|
let cam_children: HashSet<Entity> = children.iter_descendants(cam_entity).collect();
|
||||||
|
|
||||||
let nearest_object = objects
|
let nearest_object = objects
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|(entity, ..)| !cam_children.contains(entity))
|
.filter(|(entity, ..)| !cam_children.contains(entity))
|
||||||
.filter(|(.., obj_layer)| {
|
.filter(|(.., obj_layer)| {
|
||||||
let obj_layer = obj_layer.copied().unwrap_or(RenderLayers::layer(0));
|
let obj_layer = obj_layer.unwrap_or_default();
|
||||||
cam_layer.intersects(&obj_layer)
|
cam_layer.intersects(obj_layer)
|
||||||
})
|
})
|
||||||
.map(|(entity, object_local, obj_pos, aabb, _)| {
|
.map(|(entity, object_local, obj_pos, aabb, _)| {
|
||||||
let center_distance =
|
let center_distance =
|
||||||
@ -243,7 +276,8 @@ pub fn camera_controller<P: GridPrecision>(
|
|||||||
let lerp_rotation = 1.0 - controller.rotational_smoothness.clamp(0.0, 0.999);
|
let lerp_rotation = 1.0 - controller.rotational_smoothness.clamp(0.0, 0.999);
|
||||||
|
|
||||||
let (vel_t_current, vel_r_current) = (controller.vel_translation, controller.vel_rotation);
|
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 (vel_t_target, vel_r_target) =
|
||||||
|
input.target_velocity(&controller, speed, time.delta_seconds_f64());
|
||||||
|
|
||||||
let cam_rot = position.transform.rotation.as_dquat();
|
let cam_rot = position.transform.rotation.as_dquat();
|
||||||
let vel_t_next = cam_rot * vel_t_target; // Orients the translation to match the camera
|
let vel_t_next = cam_rot * vel_t_target; // Orients the translation to match the camera
|
||||||
|
|||||||
13
src/debug.rs
13
src/debug.rs
@ -3,10 +3,13 @@
|
|||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
|
||||||
use bevy_app::prelude::*;
|
use bevy_app::prelude::*;
|
||||||
|
use bevy_color::{
|
||||||
|
palettes::css::{BLUE, GREEN, RED},
|
||||||
|
prelude::*,
|
||||||
|
};
|
||||||
use bevy_ecs::prelude::*;
|
use bevy_ecs::prelude::*;
|
||||||
use bevy_gizmos::prelude::*;
|
use bevy_gizmos::prelude::*;
|
||||||
use bevy_math::prelude::*;
|
use bevy_math::prelude::*;
|
||||||
use bevy_render::prelude::*;
|
|
||||||
use bevy_transform::prelude::*;
|
use bevy_transform::prelude::*;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@ -44,7 +47,7 @@ pub fn update_debug_bounds<P: GridPrecision>(
|
|||||||
&Transform::from_scale(Vec3::splat(frame.cell_edge_length() * 0.999)),
|
&Transform::from_scale(Vec3::splat(frame.cell_edge_length() * 0.999)),
|
||||||
);
|
);
|
||||||
if origin.is_none() {
|
if origin.is_none() {
|
||||||
gizmos.cuboid(transform, Color::GREEN)
|
gizmos.cuboid(transform, Color::Srgba(GREEN))
|
||||||
} else {
|
} else {
|
||||||
// gizmos.cuboid(transform, Color::rgba(0.0, 0.0, 1.0, 0.5))
|
// gizmos.cuboid(transform, Color::rgba(0.0, 0.0, 1.0, 0.5))
|
||||||
}
|
}
|
||||||
@ -59,8 +62,8 @@ pub fn update_reference_frame_axes<P: GridPrecision>(
|
|||||||
for (transform, frame) in frames.iter() {
|
for (transform, frame) in frames.iter() {
|
||||||
let start = transform.translation();
|
let start = transform.translation();
|
||||||
let len = frame.cell_edge_length() * 2.0;
|
let len = frame.cell_edge_length() * 2.0;
|
||||||
gizmos.ray(start, transform.right() * len, Color::RED);
|
gizmos.ray(start, transform.right() * len, Color::Srgba(RED));
|
||||||
gizmos.ray(start, transform.up() * len, Color::GREEN);
|
gizmos.ray(start, transform.up() * len, Color::Srgba(GREEN));
|
||||||
gizmos.ray(start, transform.back() * len, Color::BLUE);
|
gizmos.ray(start, transform.back() * len, Color::Srgba(BLUE));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
use bevy_app::prelude::*;
|
use bevy_app::prelude::*;
|
||||||
use bevy_ecs::prelude::*;
|
use bevy_ecs::prelude::*;
|
||||||
use bevy_reflect::prelude::*;
|
use bevy_reflect::{prelude::*, GetTypeRegistration};
|
||||||
use bevy_transform::{prelude::*, TransformSystem};
|
use bevy_transform::{prelude::*, TransformSystem};
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
|
||||||
@ -52,7 +52,9 @@ pub enum FloatingOriginSet {
|
|||||||
PropagateLowPrecision,
|
PropagateLowPrecision,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<P: GridPrecision + Reflect + FromReflect + TypePath> Plugin for BigSpacePlugin<P> {
|
impl<P: GridPrecision + Reflect + FromReflect + TypePath + GetTypeRegistration> Plugin
|
||||||
|
for BigSpacePlugin<P>
|
||||||
|
{
|
||||||
fn build(&self, app: &mut App) {
|
fn build(&self, app: &mut App) {
|
||||||
let system_set_config = || {
|
let system_set_config = || {
|
||||||
(
|
(
|
||||||
|
|||||||
@ -506,18 +506,18 @@ mod tests {
|
|||||||
ReferenceFrame::<i32>::default(),
|
ReferenceFrame::<i32>::default(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let child_1 = app.world.spawn(frame_bundle.clone()).id();
|
let child_1 = app.world_mut().spawn(frame_bundle.clone()).id();
|
||||||
let child_2 = app.world.spawn(frame_bundle.clone()).id();
|
let child_2 = app.world_mut().spawn(frame_bundle.clone()).id();
|
||||||
let parent = app.world.spawn(frame_bundle.clone()).id();
|
let parent = app.world_mut().spawn(frame_bundle.clone()).id();
|
||||||
let root = app.world.spawn(frame_bundle.clone()).id();
|
let root = app.world_mut().spawn(frame_bundle.clone()).id();
|
||||||
|
|
||||||
app.world.entity_mut(root).push_children(&[parent]);
|
app.world_mut().entity_mut(root).push_children(&[parent]);
|
||||||
app.world
|
app.world_mut()
|
||||||
.entity_mut(parent)
|
.entity_mut(parent)
|
||||||
.push_children(&[child_1, child_2]);
|
.push_children(&[child_1, child_2]);
|
||||||
|
|
||||||
let mut state = SystemState::<ReferenceFramesMut<i32>>::new(&mut app.world);
|
let mut state = SystemState::<ReferenceFramesMut<i32>>::new(app.world_mut());
|
||||||
let mut ref_frames = state.get_mut(&mut app.world);
|
let mut ref_frames = state.get_mut(app.world_mut());
|
||||||
|
|
||||||
// Children
|
// Children
|
||||||
let result = ref_frames.child_frames(root);
|
let result = ref_frames.child_frames(root);
|
||||||
@ -559,12 +559,12 @@ mod tests {
|
|||||||
..default()
|
..default()
|
||||||
};
|
};
|
||||||
let root = app
|
let root = app
|
||||||
.world
|
.world_mut()
|
||||||
.spawn((Transform::default(), GridCell::<i32>::default(), root_frame))
|
.spawn((Transform::default(), GridCell::<i32>::default(), root_frame))
|
||||||
.id();
|
.id();
|
||||||
|
|
||||||
let child = app
|
let child = app
|
||||||
.world
|
.world_mut()
|
||||||
.spawn((
|
.spawn((
|
||||||
Transform::from_rotation(Quat::from_rotation_z(std::f32::consts::FRAC_PI_2))
|
Transform::from_rotation(Quat::from_rotation_z(std::f32::consts::FRAC_PI_2))
|
||||||
.with_translation(Vec3::new(1.0, 1.0, 0.0)),
|
.with_translation(Vec3::new(1.0, 1.0, 0.0)),
|
||||||
@ -573,10 +573,10 @@ mod tests {
|
|||||||
))
|
))
|
||||||
.id();
|
.id();
|
||||||
|
|
||||||
app.world.entity_mut(root).push_children(&[child]);
|
app.world_mut().entity_mut(root).push_children(&[child]);
|
||||||
|
|
||||||
let mut state = SystemState::<ReferenceFramesMut<i32>>::new(&mut app.world);
|
let mut state = SystemState::<ReferenceFramesMut<i32>>::new(app.world_mut());
|
||||||
let mut reference_frames = state.get_mut(&mut app.world);
|
let mut reference_frames = state.get_mut(app.world_mut());
|
||||||
|
|
||||||
// The function we are testing
|
// The function we are testing
|
||||||
propagate_origin_to_child(root, &mut reference_frames, child);
|
propagate_origin_to_child(root, &mut reference_frames, child);
|
||||||
@ -615,10 +615,10 @@ mod tests {
|
|||||||
GridCell::<i64>::default(),
|
GridCell::<i64>::default(),
|
||||||
ReferenceFrame::<i64>::default(),
|
ReferenceFrame::<i64>::default(),
|
||||||
);
|
);
|
||||||
let root = app.world.spawn(frame_bundle.clone()).id();
|
let root = app.world_mut().spawn(frame_bundle.clone()).id();
|
||||||
|
|
||||||
let child = app
|
let child = app
|
||||||
.world
|
.world_mut()
|
||||||
.spawn((
|
.spawn((
|
||||||
Transform::from_rotation(Quat::from_rotation_z(std::f32::consts::FRAC_PI_2))
|
Transform::from_rotation(Quat::from_rotation_z(std::f32::consts::FRAC_PI_2))
|
||||||
.with_translation(Vec3::new(1.0, 1.0, 0.0)),
|
.with_translation(Vec3::new(1.0, 1.0, 0.0)),
|
||||||
@ -634,10 +634,10 @@ mod tests {
|
|||||||
))
|
))
|
||||||
.id();
|
.id();
|
||||||
|
|
||||||
app.world.entity_mut(root).push_children(&[child]);
|
app.world_mut().entity_mut(root).push_children(&[child]);
|
||||||
|
|
||||||
let mut state = SystemState::<ReferenceFramesMut<i64>>::new(&mut app.world);
|
let mut state = SystemState::<ReferenceFramesMut<i64>>::new(app.world_mut());
|
||||||
let mut reference_frames = state.get_mut(&mut app.world);
|
let mut reference_frames = state.get_mut(app.world_mut());
|
||||||
|
|
||||||
// The function we are testing
|
// The function we are testing
|
||||||
propagate_origin_to_parent(child, &mut reference_frames, root);
|
propagate_origin_to_parent(child, &mut reference_frames, root);
|
||||||
@ -672,7 +672,7 @@ mod tests {
|
|||||||
app.add_plugins(BigSpacePlugin::<i32>::default());
|
app.add_plugins(BigSpacePlugin::<i32>::default());
|
||||||
|
|
||||||
let root = app
|
let root = app
|
||||||
.world
|
.world_mut()
|
||||||
.spawn((
|
.spawn((
|
||||||
Transform::default(),
|
Transform::default(),
|
||||||
GridCell::<i32>::default(),
|
GridCell::<i32>::default(),
|
||||||
@ -688,7 +688,7 @@ mod tests {
|
|||||||
.id();
|
.id();
|
||||||
|
|
||||||
let child = app
|
let child = app
|
||||||
.world
|
.world_mut()
|
||||||
.spawn((
|
.spawn((
|
||||||
Transform::default()
|
Transform::default()
|
||||||
.with_rotation(Quat::from_rotation_z(-std::f32::consts::FRAC_PI_2))
|
.with_rotation(Quat::from_rotation_z(-std::f32::consts::FRAC_PI_2))
|
||||||
@ -698,10 +698,10 @@ mod tests {
|
|||||||
))
|
))
|
||||||
.id();
|
.id();
|
||||||
|
|
||||||
app.world.entity_mut(root).push_children(&[child]);
|
app.world_mut().entity_mut(root).push_children(&[child]);
|
||||||
|
|
||||||
let mut state = SystemState::<ReferenceFramesMut<i32>>::new(&mut app.world);
|
let mut state = SystemState::<ReferenceFramesMut<i32>>::new(app.world_mut());
|
||||||
let mut reference_frames = state.get_mut(&mut app.world);
|
let mut reference_frames = state.get_mut(app.world_mut());
|
||||||
|
|
||||||
propagate_origin_to_child(root, &mut reference_frames, child);
|
propagate_origin_to_child(root, &mut reference_frames, child);
|
||||||
|
|
||||||
|
|||||||
@ -34,7 +34,7 @@ pub mod propagation;
|
|||||||
/// the same rotating reference frame, instead of moving rapidly through space around a star, or
|
/// the same rotating reference frame, instead of moving rapidly through space around a star, or
|
||||||
/// worse, around the center of the galaxy.
|
/// worse, around the center of the galaxy.
|
||||||
#[derive(Debug, Clone, Reflect, Component)]
|
#[derive(Debug, Clone, Reflect, Component)]
|
||||||
pub struct ReferenceFrame<P: GridPrecision> {
|
pub struct ReferenceFrame<P: GridPrecision + Reflect> {
|
||||||
/// The high-precision position of the floating origin's current grid cell local to this
|
/// The high-precision position of the floating origin's current grid cell local to this
|
||||||
/// reference frame.
|
/// reference frame.
|
||||||
local_floating_origin: LocalFloatingOrigin<P>,
|
local_floating_origin: LocalFloatingOrigin<P>,
|
||||||
|
|||||||
26
src/tests.rs
26
src/tests.rs
@ -8,7 +8,7 @@ fn changing_floating_origin_updates_global_transform() {
|
|||||||
app.add_plugins(BigSpacePlugin::<i32>::default());
|
app.add_plugins(BigSpacePlugin::<i32>::default());
|
||||||
|
|
||||||
let first = app
|
let first = app
|
||||||
.world
|
.world_mut()
|
||||||
.spawn((
|
.spawn((
|
||||||
TransformBundle::from_transform(Transform::from_translation(Vec3::new(
|
TransformBundle::from_transform(Transform::from_translation(Vec3::new(
|
||||||
150.0, 0.0, 0.0,
|
150.0, 0.0, 0.0,
|
||||||
@ -19,7 +19,7 @@ fn changing_floating_origin_updates_global_transform() {
|
|||||||
.id();
|
.id();
|
||||||
|
|
||||||
let second = app
|
let second = app
|
||||||
.world
|
.world_mut()
|
||||||
.spawn((
|
.spawn((
|
||||||
TransformBundle::from_transform(Transform::from_translation(Vec3::new(
|
TransformBundle::from_transform(Transform::from_translation(Vec3::new(
|
||||||
0.0, 0.0, 300.0,
|
0.0, 0.0, 300.0,
|
||||||
@ -28,18 +28,18 @@ fn changing_floating_origin_updates_global_transform() {
|
|||||||
))
|
))
|
||||||
.id();
|
.id();
|
||||||
|
|
||||||
app.world
|
app.world_mut()
|
||||||
.spawn(BigSpaceRootBundle::<i32>::default())
|
.spawn(BigSpaceRootBundle::<i32>::default())
|
||||||
.push_children(&[first, second]);
|
.push_children(&[first, second]);
|
||||||
|
|
||||||
app.update();
|
app.update();
|
||||||
|
|
||||||
app.world.entity_mut(first).remove::<FloatingOrigin>();
|
app.world_mut().entity_mut(first).remove::<FloatingOrigin>();
|
||||||
app.world.entity_mut(second).insert(FloatingOrigin);
|
app.world_mut().entity_mut(second).insert(FloatingOrigin);
|
||||||
|
|
||||||
app.update();
|
app.update();
|
||||||
|
|
||||||
let second_global_transform = app.world.get::<GlobalTransform>(second).unwrap();
|
let second_global_transform = app.world_mut().get::<GlobalTransform>(second).unwrap();
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
second_global_transform.translation(),
|
second_global_transform.translation(),
|
||||||
@ -53,7 +53,7 @@ fn child_global_transforms_are_updated_when_floating_origin_changes() {
|
|||||||
app.add_plugins(BigSpacePlugin::<i32>::default());
|
app.add_plugins(BigSpacePlugin::<i32>::default());
|
||||||
|
|
||||||
let first = app
|
let first = app
|
||||||
.world
|
.world_mut()
|
||||||
.spawn((
|
.spawn((
|
||||||
TransformBundle::from_transform(Transform::from_translation(Vec3::new(
|
TransformBundle::from_transform(Transform::from_translation(Vec3::new(
|
||||||
150.0, 0.0, 0.0,
|
150.0, 0.0, 0.0,
|
||||||
@ -64,7 +64,7 @@ fn child_global_transforms_are_updated_when_floating_origin_changes() {
|
|||||||
.id();
|
.id();
|
||||||
|
|
||||||
let second = app
|
let second = app
|
||||||
.world
|
.world_mut()
|
||||||
.spawn((
|
.spawn((
|
||||||
TransformBundle::from_transform(Transform::from_translation(Vec3::new(
|
TransformBundle::from_transform(Transform::from_translation(Vec3::new(
|
||||||
0.0, 0.0, 300.0,
|
0.0, 0.0, 300.0,
|
||||||
@ -78,19 +78,19 @@ fn child_global_transforms_are_updated_when_floating_origin_changes() {
|
|||||||
})
|
})
|
||||||
.id();
|
.id();
|
||||||
|
|
||||||
app.world
|
app.world_mut()
|
||||||
.spawn(BigSpaceRootBundle::<i32>::default())
|
.spawn(BigSpaceRootBundle::<i32>::default())
|
||||||
.push_children(&[first, second]);
|
.push_children(&[first, second]);
|
||||||
|
|
||||||
app.update();
|
app.update();
|
||||||
|
|
||||||
app.world.entity_mut(first).remove::<FloatingOrigin>();
|
app.world_mut().entity_mut(first).remove::<FloatingOrigin>();
|
||||||
app.world.entity_mut(second).insert(FloatingOrigin);
|
app.world_mut().entity_mut(second).insert(FloatingOrigin);
|
||||||
|
|
||||||
app.update();
|
app.update();
|
||||||
|
|
||||||
let child = app.world.get::<Children>(second).unwrap()[0];
|
let child = app.world_mut().get::<Children>(second).unwrap()[0];
|
||||||
let child_transform = app.world.get::<GlobalTransform>(child).unwrap();
|
let child_transform = app.world_mut().get::<GlobalTransform>(child).unwrap();
|
||||||
|
|
||||||
assert_eq!(child_transform.translation(), Vec3::new(0.0, 0.0, 600.0));
|
assert_eq!(child_transform.translation(), Vec3::new(0.0, 0.0, 600.0));
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user