Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion benches/benches/bevy_camera/primitives.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use bevy_camera::primitives::{Aabb, Frustum, Sphere};
use bevy_math::{
primitives::{HalfSpace, ViewFrustum},
camera::{HalfSpace, ViewFrustum},
Affine3A, Quat, Vec3, Vec3A, Vec4,
};
use core::hint::black_box;
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_camera/src/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use bevy_derive::{Deref, DerefMut};
use bevy_ecs::{component::Component, entity::EntityHashMap, reflect::ReflectComponent};
use bevy_math::{
bounding::{Aabb3d, BoundingVolume},
primitives::{HalfSpace, ViewFrustum},
camera::{HalfSpace, ViewFrustum},
Affine3A, Mat3A, Vec3, Vec3A,
};
use bevy_mesh::{Mesh, VertexAttributeValues};
Expand Down
4 changes: 1 addition & 3 deletions crates/bevy_camera/src/projection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ use core::ops::{Deref, DerefMut};
use crate::{primitives::Frustum, visibility::VisibilitySystems};
use bevy_app::{App, Plugin, PostUpdate};
use bevy_ecs::prelude::*;
use bevy_math::{
ops, primitives::ViewFrustum, proj, vec4, AspectRatio, Mat4, Rect, Vec2, Vec3A, Vec4,
};
use bevy_math::{camera::ViewFrustum, ops, proj, vec4, AspectRatio, Mat4, Rect, Vec2, Vec3A, Vec4};
use bevy_reflect::{std_traits::ReflectDefault, Reflect, ReflectDeserialize, ReflectSerialize};
use bevy_transform::{components::GlobalTransform, TransformSystems};
use derive_more::derive::From;
Expand Down
4 changes: 3 additions & 1 deletion crates/bevy_gizmos/src/gizmos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,9 @@ where
Config: GizmoConfigGroup,
Clear: 'static + Send + Sync,
{
pub(crate) enabled: bool,
// needs to be public for [`bevy_shapes`]
/// whether or not this buffer will be rendered
pub enabled: bool,
/// The positions of line segment endpoints.
pub list_positions: Vec<Vec3>,
/// The colors of line segment endpoints.
Expand Down
2 changes: 0 additions & 2 deletions crates/bevy_gizmos/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ pub mod frustum;
pub mod gizmos;
mod global;
pub mod grid;
pub mod primitives;
pub mod retained;
pub mod rounded_box;
mod simplex_stroke_font;
Expand Down Expand Up @@ -65,7 +64,6 @@ pub mod prelude {
},
gizmos::Gizmos,
global::gizmo,
primitives::{dim2::GizmoPrimitive2d, dim3::GizmoPrimitive3d},
retained::Gizmo,
AppGizmoBuilder, GizmoAsset,
};
Expand Down
1 change: 1 addition & 0 deletions crates/bevy_gizmos_render/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ bevy_utils = { path = "../bevy_utils", version = "0.20.0-dev" }
bevy_core_pipeline = { path = "../bevy_core_pipeline", version = "0.20.0-dev" }
bevy_transform = { path = "../bevy_transform", version = "0.20.0-dev" }
bevy_reflect = { path = "../bevy_reflect", version = "0.20.0-dev" }
bevy_shapes = { path = "../bevy_shapes", version = "0.20.0-dev", features = [ "meshing" ] }
bevy_color = { path = "../bevy_color", version = "0.20.0-dev" }
bevy_material = { path = "../bevy_material", version = "0.20.0-dev" }
bevy_log = { path = "../bevy_log", version = "0.20.0-dev" }
Expand Down
28 changes: 10 additions & 18 deletions crates/bevy_gizmos_render/src/transform_gizmo_render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@ use bevy_ecs::{
schedule::IntoScheduleConfigs,
system::{Commands, Query, Res, ResMut},
};
use bevy_math::{
primitives::{Cone, Cuboid, Cylinder, Torus},
Quat, Vec3,
};
use bevy_mesh::{Mesh, Mesh3d, MeshBuilder, Meshable};
use bevy_math::{Quat, Vec3};
use bevy_mesh::{Mesh, Mesh3d, Meshable};
use bevy_pbr::{MeshMaterial3d, StandardMaterial};
use bevy_shapes::primitives::{Cone, Cuboid, Cylinder, Torus};
use bevy_transform::{
components::{GlobalTransform, Transform},
systems::propagate_transforms_for,
Expand Down Expand Up @@ -167,36 +165,30 @@ fn spawn_gizmo_meshes(
};

// Pre-create meshes
let shaft_mesh = meshes.add(Cylinder::new(SHAFT_RADIUS, SHAFT_LENGTH).mesh().build());
let cone_mesh = meshes.add(Cone::new(CONE_RADIUS, CONE_HEIGHT).mesh().build());
let scale_cube_mesh = meshes.add(
Cuboid::new(SCALE_CUBE_SIZE, SCALE_CUBE_SIZE, SCALE_CUBE_SIZE)
.mesh()
.build(),
);
let shaft_mesh = meshes.add(Cylinder::new(SHAFT_RADIUS, SHAFT_LENGTH).mesh());
let cone_mesh = meshes.add(Cone::new(CONE_RADIUS, CONE_HEIGHT).mesh());
let scale_cube_mesh =
meshes.add(Cuboid::new(SCALE_CUBE_SIZE, SCALE_CUBE_SIZE, SCALE_CUBE_SIZE).mesh());
let rotate_torus_mesh = meshes.add(
Torus {
minor_radius: 0.015,
major_radius: ROTATE_RING_RADIUS,
}
.mesh()
.build(),
.mesh(),
);
let view_circle_mesh = meshes.add(
Torus {
minor_radius: VIEW_CIRCLE_MINOR,
major_radius: VIEW_CIRCLE_MAJOR,
}
.mesh()
.build(),
.mesh(),
);
let view_ring_mesh = meshes.add(
Torus {
minor_radius: VIEW_RING_MINOR,
major_radius: VIEW_RING_MAJOR,
}
.mesh()
.build(),
.mesh(),
);

// Axis rotations: cylinder default is Y-up
Expand Down
8 changes: 8 additions & 0 deletions crates/bevy_internal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,17 @@ shader_format_wesl = ["bevy_shader/shader_format_wesl"]
serialize = [
"bevy_a11y?/serialize",
"bevy_color?/serialize",
"bevy_dev_tools?/serialize",
"bevy_ecs/serialize",
"bevy_image?/serialize",
"bevy_input/serialize",
"bevy_math/serialize",
"bevy_shapes/serialize",
"bevy_world_serialization?/serialize",
"bevy_time/serialize",
"bevy_transform/serialize",
"bevy_ui?/serialize",
"bevy_utils/serialize",
"bevy_window?/serialize",
"bevy_winit?/serialize",
"bevy_platform/serialize",
Expand Down Expand Up @@ -416,6 +419,7 @@ std = [
"bevy_input/std",
"bevy_input_focus?/std",
"bevy_math/std",
"bevy_shapes/std",
"bevy_platform/std",
"bevy_reflect/std",
"bevy_state?/std",
Expand Down Expand Up @@ -505,6 +509,10 @@ bevy_math = { path = "../bevy_math", version = "0.20.0-dev", default-features =
"bevy_reflect",
"nostd-libm",
] }
bevy_shapes = { path = "../bevy_shapes", version = "0.20.0-dev", default-features = false, features = [
"bevy_reflect",
"nostd-libm",
] }
bevy_platform = { path = "../bevy_platform", version = "0.20.0-dev", default-features = false, features = [
"alloc",
] }
Expand Down
1 change: 1 addition & 0 deletions crates/bevy_internal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ pub use bevy_scene as scene;
pub use bevy_settings as settings;
#[cfg(feature = "bevy_shader")]
pub use bevy_shader as shader;
pub use bevy_shapes as shapes;
#[cfg(feature = "bevy_solari")]
pub use bevy_solari as solari;
#[cfg(feature = "bevy_sprite")]
Expand Down
3 changes: 3 additions & 0 deletions crates/bevy_internal/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,6 @@ pub use crate::picking::prelude::*;
#[doc(hidden)]
#[cfg(feature = "bevy_clipboard")]
pub use crate::clipboard::prelude::*;

#[doc(hidden)]
pub use crate::shapes::prelude::*;
5 changes: 4 additions & 1 deletion crates/bevy_light/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ bevy_color = { path = "../bevy_color", version = "0.20.0-dev", features = [
] }
bevy_gizmos = { path = "../bevy_gizmos", version = "0.20.0-dev", optional = true }
bevy_log = { path = "../bevy_log", version = "0.20.0-dev" }
bevy_shapes = { path = "../bevy_shapes", version = "0.20.0-dev", optional = true }
bevy_gizmos = { path = "../bevy_gizmos", version = "0.20.0-dev", optional = true }

# other
tracing = { version = "0.1", default-features = false }
wgpu-types = { version = "29.0.3", default-features = false }
wgpu-types = { version = "30", default-features = false }
half = "2.7.1"
smallvec = { version = "1", default-features = false }

Expand All @@ -38,6 +40,7 @@ default = []
experimental_pbr_pcss = []
webgl = []
webgpu = []
bevy_gizmos = ["bevy_shapes?/gizmos", "dep:bevy_gizmos", "dep:bevy_shapes"]

[lints]
workspace = true
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_light/src/cluster/assign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use bevy_ecs::{
system::{Local, Query, Res},
};
use bevy_math::{
camera::HalfSpace,
ops::{self, sin_cos},
primitives::HalfSpace,
Mat4, UVec3, Vec2, Vec3, Vec3A, Vec3Swizzles as _, Vec4, Vec4Swizzles as _,
};
use bevy_transform::components::GlobalTransform;
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_light/src/directional_light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use bevy_camera::{
use bevy_color::Color;
use bevy_ecs::prelude::*;
use bevy_image::Image;
use bevy_math::primitives::ViewFrustum;
use bevy_math::camera::ViewFrustum;
use bevy_reflect::prelude::*;
use bevy_transform::components::Transform;
use tracing::warn;
Expand Down
9 changes: 3 additions & 6 deletions crates/bevy_light/src/gizmos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

use core::f32::consts::PI;

use bevy_gizmos::primitives::dim3::GizmoPrimitive3d;
use bevy_shapes::gizmos::GizmoPrimitive3d;
use bevy_shapes::primitives::{Cone, Sphere};

use crate::{DirectionalLight, PointLight, RectLight, SpotLight};
use bevy_app::{Plugin, PostUpdate};
Expand All @@ -18,11 +19,7 @@ use bevy_ecs::{
schedule::IntoScheduleConfigs,
system::{Query, Res},
};
use bevy_math::{
ops,
primitives::{Cone, Sphere},
Isometry3d, Quat, Vec3,
};
use bevy_math::{ops, Isometry3d, Quat, Vec3};
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
use bevy_transform::{components::GlobalTransform, TransformSystems};

Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_light/src/point_light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use bevy_camera::{
use bevy_color::Color;
use bevy_ecs::prelude::*;
use bevy_image::Image;
use bevy_math::{primitives::ViewFrustum, proj};
use bevy_math::{camera::ViewFrustum, proj};
use bevy_reflect::prelude::*;
use bevy_transform::components::{GlobalTransform, Transform};

Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_light/src/spot_light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use bevy_camera::{
use bevy_color::Color;
use bevy_ecs::prelude::*;
use bevy_image::Image;
use bevy_math::{primitives::ViewFrustum, proj, Affine3A, Dir3, Mat3, Mat4, Vec3};
use bevy_math::{camera::ViewFrustum, proj, Affine3A, Dir3, Mat3, Mat4, Vec3};
use bevy_reflect::prelude::*;
use bevy_transform::components::{GlobalTransform, Transform};

Expand Down
30 changes: 18 additions & 12 deletions crates/bevy_math/src/bounding/bounded2d/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
mod primitive_impls;

use super::{BoundingVolume, IntersectsVolume};
use crate::{
ops,
Expand Down Expand Up @@ -469,8 +467,6 @@ mod aabb2d_tests {
}
}

use crate::primitives::Circle;

/// A bounding circle
#[derive(Clone, Copy, Debug, PartialEq)]
#[cfg_attr(
Expand All @@ -486,19 +482,16 @@ use crate::primitives::Circle;
pub struct BoundingCircle {
/// The center of the bounding circle
pub center: Vec2,
/// The circle
pub circle: Circle,
/// The radius of the circle
pub radius: f32,
}

impl BoundingCircle {
/// Constructs a bounding circle from its center and radius.
#[inline]
pub const fn new(center: Vec2, radius: f32) -> Self {
debug_assert!(radius >= 0.);
Self {
center,
circle: Circle { radius },
}
Self { center, radius }
}

/// Computes a [`BoundingCircle`] containing the given set of points,
Expand Down Expand Up @@ -526,7 +519,7 @@ impl BoundingCircle {
/// Get the radius of the bounding circle
#[inline]
pub const fn radius(&self) -> f32 {
self.circle.radius
self.radius
}

/// Computes the smallest [`Aabb2d`] containing this [`BoundingCircle`].
Expand All @@ -544,7 +537,20 @@ impl BoundingCircle {
/// Otherwise, it will be inside the circle and returned as is.
#[inline]
pub fn closest_point(&self, point: Vec2) -> Vec2 {
self.circle.closest_point(point - self.center) + self.center
let centered_point = point - self.center;
let distance_squared = centered_point.length_squared();

let closest_point = if distance_squared <= self.radius.squared() {
// The point is inside the circle.
point
} else {
// The point is outside the circle.
// Find the closest point on the perimeter of the circle.
let dir_to_point = point / ops::sqrt(distance_squared);
self.radius * dir_to_point
};

closest_point + self.center
}
}

Expand Down
Loading
Loading