Skip to content

Commit

Permalink
Merge branch 'main' into spatial-hashing
Browse files Browse the repository at this point in the history
  • Loading branch information
aevyrie committed Jul 16, 2024
2 parents c847fcc + b2ebb02 commit b59aec7
Show file tree
Hide file tree
Showing 16 changed files with 186 additions and 127 deletions.
35 changes: 18 additions & 17 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "big_space"
version = "0.6.0"
version = "0.7.0"
edition = "2021"
description = "A floating origin plugin for bevy"
license = "MIT OR Apache-2.0"
Expand All @@ -9,22 +9,23 @@ repository = "https://github.com/aevyrie/big_space"
documentation = "https://docs.rs/crate/big_space/latest"

[dependencies]
bevy_app = { version = "0.13", default-features = false }
bevy_ecs = { version = "0.13", default-features = false }
bevy_hierarchy = { version = "0.13", default-features = false }
bevy_log = { version = "0.13", default-features = false }
bevy_math = { version = "0.13", default-features = false }
bevy_reflect = { version = "0.13", default-features = false }
bevy_transform = { version = "0.13", default-features = false }
bevy_utils = { version = "0.13", default-features = false }
bevy_app = { version = "0.14.0", default-features = false }
bevy_ecs = { version = "0.14.0", default-features = false }
bevy_hierarchy = { version = "0.14.0", default-features = false }
bevy_log = { version = "0.14.0", default-features = false }
bevy_math = { version = "0.14.0", default-features = false }
bevy_reflect = { version = "0.14.0", default-features = false }
bevy_transform = { version = "0.14.0", default-features = false }
bevy_utils = { version = "0.14.0", default-features = false }
# Optional
bevy_gizmos = { version = "0.13", default-features = false, optional = true }
bevy_render = { version = "0.13", default-features = false, optional = true }
bevy_input = { version = "0.13", default-features = false, optional = true }
bevy_time = { version = "0.13", default-features = false, optional = true }
bevy_color = { version = "0.14.0", default-features = false, optional = true }
bevy_gizmos = { version = "0.14.0", default-features = false, optional = true }
bevy_render = { version = "0.14.0", 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]
bevy = { version = "0.13", default-features = false, features = [
bevy = { version = "0.14.0", default-features = false, features = [
"bevy_scene",
"bevy_gltf",
"bevy_winit",
Expand All @@ -34,9 +35,9 @@ bevy = { version = "0.13", default-features = false, features = [
"bevy_gizmos",
"x11",
"tonemapping_luts",
"multi-threaded",
"multi_threaded",
] }
bevy-inspector-egui = "0.24"
# bevy-inspector-egui = "0.24"
rand = "0.8.5"
criterion = "0.5"

Expand All @@ -47,7 +48,7 @@ harness = false

[features]
default = ["debug", "camera", "bevy_render"]
debug = ["bevy_gizmos", "bevy_render"]
debug = ["bevy_gizmos", "bevy_color"]
camera = ["bevy_render", "bevy_time", "bevy_input"]

[[example]]
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ From the docs: https://docs.rs/big_space/latest/big_space/precision/trait.GridPr

| bevy | big_space |
| ---- | --------- |
| 0.14 | 0.7 |
| 0.13 | 0.5, 0.6 |
| 0.12 | 0.4 |
| 0.11 | 0.3 |
Expand Down
2 changes: 1 addition & 1 deletion benches/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ fn spatial_hashing(c: &mut Criterion) {
});
});

let map = app.world.resource::<SpatialHashMap<i32>>();
let map = app.world().resource::<SpatialHashMap<i32>>();
let first = map.iter().next().unwrap();
group.bench_function("SpatialHashMap::get", |b| {
b.iter(|| {
Expand Down
5 changes: 3 additions & 2 deletions examples/debug.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![allow(clippy::type_complexity)]

use bevy::prelude::*;
use bevy_color::palettes;
use big_space::{commands::BigSpaceCommands, reference_frame::ReferenceFrame, FloatingOrigin};

fn main() {
Expand All @@ -13,7 +14,7 @@ fn main() {
.insert_resource(ClearColor(Color::BLACK))
.add_systems(Startup, setup)
.add_systems(Update, (movement, rotation))
.run()
.run();
}

#[derive(Component)]
Expand Down Expand Up @@ -61,7 +62,7 @@ fn setup(
) {
let mesh_handle = meshes.add(Sphere::new(0.1).mesh().ico(16).unwrap());
let matl_handle = materials.add(StandardMaterial {
base_color: Color::YELLOW,
base_color: Color::Srgba(palettes::basic::YELLOW),
..default()
});

Expand Down
18 changes: 12 additions & 6 deletions examples/demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use bevy::{
transform::TransformSystem,
window::{CursorGrabMode, PrimaryWindow},
};
use bevy_color::palettes;
use big_space::{
camera::{CameraController, CameraInput},
commands::BigSpaceCommands,
Expand All @@ -26,7 +27,7 @@ fn main() {
PostUpdate,
highlight_nearest_sphere.after(TransformSystem::TransformPropagate),
)
.run()
.run();
}

fn setup(
Expand Down Expand Up @@ -54,7 +55,7 @@ fn setup(

let mesh_handle = meshes.add(Sphere::new(0.5).mesh().ico(32).unwrap());
let matl_handle = materials.add(StandardMaterial {
base_color: Color::BLUE,
base_color: Color::Srgba(palettes::basic::BLUE),
perceptual_roughness: 0.8,
reflectance: 1.0,
..default()
Expand All @@ -78,7 +79,7 @@ fn setup(
// light
root.spawn_spatial(DirectionalLightBundle {
directional_light: DirectionalLight {
illuminance: 100_000.0,
illuminance: 10_000.0,
..default()
},
..default()
Expand Down Expand Up @@ -145,10 +146,15 @@ fn highlight_nearest_sphere(
return;
};
// 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
.sphere(translation, rotation, scale.x * 0.505, Color::RED)
.circle_segments(128);
.sphere(
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)]
Expand Down
2 changes: 1 addition & 1 deletion examples/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn main() {
))
.add_systems(Startup, (setup_scene, setup_ui))
.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
Expand Down
27 changes: 14 additions & 13 deletions examples/error_child.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
//! This example demonstrates error accumulating from parent to children in nested reference frames.
use bevy::{math::DVec3, prelude::*};
use bevy_color::palettes;
use big_space::{commands::BigSpaceCommands, reference_frame::ReferenceFrame, FloatingOrigin};

fn main() {
App::new()
.add_plugins((
DefaultPlugins.build().disable::<TransformPlugin>(),
bevy_inspector_egui::quick::WorldInspectorPlugin::new(),
// bevy_inspector_egui::quick::WorldInspectorPlugin::new(),
big_space::BigSpacePlugin::<i64>::default(),
big_space::camera::CameraControllerPlugin::<i64>::default(),
big_space::debug::FloatingOriginDebugPlugin::<i64>::default(),
))
.add_systems(Startup, setup_scene)
.run()
.run();
}

// The nearby object is NEARBY meters away from us. The distance object is DISTANT meters away from
Expand All @@ -28,7 +29,7 @@ fn setup_scene(
) {
let mesh_handle = meshes.add(Sphere::new(SPHERE_RADIUS).mesh());
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()
});

Expand All @@ -37,7 +38,7 @@ fn setup_scene(
|root_frame| {
root_frame.spawn_spatial(PbrBundle {
mesh: mesh_handle.clone(),
material: materials.add(Color::BLUE),
material: materials.add(Color::from(palettes::css::BLUE)),
transform: Transform::from_translation(NEARBY),
..default()
});
Expand All @@ -46,8 +47,8 @@ fn setup_scene(
root_frame.with_frame(
ReferenceFrame::new(SPHERE_RADIUS * 100.0, 0.0),
|parent_frame| {
// This function introduces a small amount of error, because it can only work up to
// double precision floats. (f64).
// This function introduces a small amount of error, because it can only work up
// to double precision floats. (f64).
let child = parent_frame
.frame()
.translation_to_grid(-DISTANT + NEARBY.as_dvec3());
Expand All @@ -60,16 +61,16 @@ fn setup_scene(
parent_frame.insert(parent.0);

parent_frame.with_children(|child_builder| {
// A green sphere that is a child of the sphere very far from the origin. This
// child is very far from its parent, and should be located exactly at the
// origin (if there was no floating point error). The distance from the green
// sphere to the red sphere is the error caused by float imprecision. Note that
// the sphere does not have any rendering artifacts, its position just has a
// fixed error.
// A green sphere that is a child of the sphere very far from the origin.
// This child is very far from its parent, and should be located exactly at
// the origin (if there was no floating point error). The distance from the
// green sphere to the red sphere is the error caused by float imprecision.
// Note that the sphere does not have any rendering artifacts, its position
// just has a fixed error.
child_builder.spawn((
PbrBundle {
mesh: mesh_handle,
material: materials.add(Color::GREEN),
material: materials.add(Color::from(palettes::css::GREEN)),
transform: Transform::from_translation(child.1),
..default()
},
Expand Down
15 changes: 8 additions & 7 deletions examples/planets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use bevy::{
render::camera::Exposure,
transform::TransformSystem,
};
use bevy_color::palettes;
use big_space::{
camera::{CameraController, CameraInput},
commands::BigSpaceCommands,
Expand Down Expand Up @@ -51,7 +52,7 @@ fn main() {
)
.register_type::<Sun>()
.register_type::<Rotates>()
.run()
.run();
}

const EARTH_ORBIT_RADIUS_M: f64 = 149.60e9;
Expand Down Expand Up @@ -129,7 +130,7 @@ fn spawn_solar_system(
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 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((
PrimaryLight,
Expand Down Expand Up @@ -160,7 +161,7 @@ fn spawn_solar_system(
mesh: sun_mesh_handle,
material: materials.add(StandardMaterial {
base_color: Color::WHITE,
emissive: Color::rgb_linear(100000000., 100000000., 100000000.),
emissive: LinearRgba::rgb(100000., 100000., 100000.),
..default()
}),
..default()
Expand All @@ -177,7 +178,7 @@ fn spawn_solar_system(
PbrBundle {
mesh: earth_mesh_handle,
material: materials.add(StandardMaterial {
base_color: Color::BLUE,
base_color: Color::Srgba(palettes::css::BLUE),
perceptual_roughness: 0.8,
reflectance: 1.0,
..default()
Expand All @@ -197,7 +198,7 @@ fn spawn_solar_system(
PbrBundle {
mesh: moon_mesh_handle,
material: materials.add(StandardMaterial {
base_color: Color::GRAY,
base_color: Color::Srgba(palettes::css::GRAY),
perceptual_roughness: 1.0,
reflectance: 0.0,
..default()
Expand Down Expand Up @@ -226,7 +227,7 @@ fn spawn_solar_system(
children.spawn((PbrBundle {
mesh: plane_mesh_handle,
material: materials.add(StandardMaterial {
base_color: Color::DARK_GREEN,
base_color: Color::Srgba(palettes::css::DARK_GREEN),
perceptual_roughness: 1.0,
reflectance: 0.0,
..default()
Expand Down Expand Up @@ -282,7 +283,7 @@ fn spawn_solar_system(

let star_mat = materials.add(StandardMaterial {
base_color: Color::WHITE,
emissive: Color::rgb_linear(100000., 100000., 100000.),
emissive: LinearRgba::rgb(2., 2., 2.),
..default()
});
let star_mesh_handle = meshes.add(Sphere::new(1e10).mesh().ico(5).unwrap());
Expand Down
Loading

0 comments on commit b59aec7

Please sign in to comment.