Skip to content
Merged
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
30 changes: 30 additions & 0 deletions _release-content/migration-guides/bevy_shape.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
title: "split out `bevy_shape` from `bevy_math`"
pull_requests: [25302]
---

`bevy_shape` is a new crate centered around the geometric primitives provided
by bevy. These primtiives and related traits have been split out from
`bevy_math` and are now available from different import paths than they used to
be.

Notably:

- all the `bevy_math::primitives::*` are now exposed either on the top level
via `bevy_shape::*` or in the `bevy_shape::prelude::*`
- the following traits have also moved from `bevy_math` into `bevy_shape`
- `Primitive2d` & `Primitive3d`
- `Bounded2d` & `Bounded3d`
- `BoundingVolume` & `IntersectsVolume`
- `ToRing`
- `Inset`
- `ShapeSample`

If you use the `bevy::prelude::*`, there should be nothing you have to change
as all of this is still included in the general prelude. Otherwise you might
need to include a dependency on `bevy_shape` now and import your desired
structures from there.

Note that `Bounded2d`, `Bounded3d`, `BoundingVolume` & `IntersectsVolume` are
also included in the prelude now, which wasn't the case before. You can check,
if the imports of these in your code base are still necessary.
1 change: 1 addition & 0 deletions benches/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ bevy_app = { path = "../crates/bevy_app" }
bevy_ecs = { path = "../crates/bevy_ecs", features = ["multi_threaded"] }
bevy_extract = { path = "../crates/bevy_extract" }
bevy_math = { path = "../crates/bevy_math" }
bevy_shape = { path = "../crates/bevy_shape" }
bevy_picking = { path = "../crates/bevy_picking", features = ["mesh_picking"] }
bevy_reflect = { path = "../crates/bevy_reflect", features = ["functions"] }
bevy_camera = { path = "../crates/bevy_camera" }
Expand Down
6 changes: 2 additions & 4 deletions benches/benches/bevy_camera/primitives.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use bevy_camera::primitives::{Aabb, Frustum, Sphere};
use bevy_math::{
primitives::{HalfSpace, ViewFrustum},
Affine3A, Quat, Vec3, Vec3A, Vec4,
};
use bevy_math::{Affine3A, Quat, Vec3, Vec3A, Vec4};
use bevy_shape::{HalfSpace, ViewFrustum};
use core::hint::black_box;
use criterion::{criterion_group, Criterion};

Expand Down
6 changes: 2 additions & 4 deletions benches/benches/bevy_math/bounding.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use benches::bench;
use bevy_math::{
bounding::{Aabb3d, BoundingSphere, BoundingVolume},
prelude::*,
};
use bevy_math::prelude::*;
use bevy_shape::prelude::*;
use core::hint::black_box;
use criterion::{criterion_group, Criterion};
use rand::{
Expand Down
3 changes: 2 additions & 1 deletion benches/benches/bevy_picking/ray_mesh_intersection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ use core::hint::black_box;
use std::time::Duration;

use benches::bench;
use bevy_math::{Affine3A, Dir3, Ray3d, Vec3};
use bevy_math::{Affine3A, Dir3, Vec3};
use bevy_picking::mesh_picking::ray_cast::{self, Backfaces};
use bevy_shape::Ray3d;
use criterion::{criterion_group, AxisScale, BenchmarkId, Criterion, PlotConfiguration};

criterion_group!(benches, bench);
Expand Down
1 change: 1 addition & 0 deletions crates/bevy_camera/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ bevy_asset = { path = "../bevy_asset", version = "0.20.0-dev" }
bevy_image = { path = "../bevy_image", version = "0.20.0-dev" }
bevy_mesh = { path = "../bevy_mesh", version = "0.20.0-dev" }
bevy_math = { path = "../bevy_math", version = "0.20.0-dev" }
bevy_shape = { path = "../bevy_shape", version = "0.20.0-dev" }
bevy_reflect = { path = "../bevy_reflect", version = "0.20.0-dev", features = [
"wgpu-types",
] }
Expand Down
3 changes: 2 additions & 1 deletion crates/bevy_camera/src/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ use bevy_ecs::{
component::Component, entity::Entity, reflect::ReflectComponent, template::FromTemplate,
};
use bevy_image::Image;
use bevy_math::{ops, Dir3, FloatOrd, Mat4, Ray3d, Rect, URect, UVec2, Vec2, Vec3, Vec3A};
use bevy_math::{ops, Dir3, FloatOrd, Mat4, Rect, URect, UVec2, Vec2, Vec3, Vec3A};
use bevy_reflect::prelude::*;
use bevy_shape::Ray3d;
use bevy_transform::components::{GlobalTransform, Transform};
use bevy_window::{NormalizedWindowRef, WindowRef};
use core::ops::Range;
Expand Down
7 changes: 2 additions & 5 deletions crates/bevy_camera/src/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@ use core::borrow::Borrow;

use bevy_derive::{Deref, DerefMut};
use bevy_ecs::{component::Component, entity::EntityHashMap, reflect::ReflectComponent};
use bevy_math::{
bounding::{Aabb3d, BoundingVolume},
primitives::{HalfSpace, ViewFrustum},
Affine3A, Mat3A, Vec3, Vec3A,
};
use bevy_math::{Affine3A, Mat3A, Vec3, Vec3A};
use bevy_mesh::{Mesh, VertexAttributeValues};
use bevy_reflect::prelude::*;
use bevy_shape::{Aabb3d, BoundingVolume, HalfSpace, ViewFrustum};

pub trait MeshAabb {
/// Compute the Axis-Aligned Bounding Box of the mesh vertices in model space,
Expand Down
5 changes: 2 additions & 3 deletions crates/bevy_camera/src/projection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ 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::{ops, proj, vec4, AspectRatio, Mat4, Rect, Vec2, Vec3A, Vec4};
use bevy_reflect::{std_traits::ReflectDefault, Reflect, ReflectDeserialize, ReflectSerialize};
use bevy_shape::ViewFrustum;
use bevy_transform::{components::GlobalTransform, TransformSystems};
use derive_more::derive::From;
use serde::{Deserialize, Serialize};
Expand Down
1 change: 1 addition & 0 deletions crates/bevy_gizmos/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ bevy_camera = { path = "../bevy_camera", version = "0.20.0-dev" }
bevy_color = { path = "../bevy_color", version = "0.20.0-dev" }
bevy_ecs = { path = "../bevy_ecs", version = "0.20.0-dev" }
bevy_math = { path = "../bevy_math", version = "0.20.0-dev" }
bevy_shape = { path = "../bevy_shape", version = "0.20.0-dev" }
bevy_asset = { path = "../bevy_asset", version = "0.20.0-dev" }
bevy_utils = { path = "../bevy_utils", version = "0.20.0-dev" }
bevy_reflect = { path = "../bevy_reflect", version = "0.20.0-dev" }
Expand Down
6 changes: 4 additions & 2 deletions crates/bevy_gizmos/src/gizmos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ use bevy_ecs::{
},
world::{unsafe_world_cell::UnsafeWorldCell, DeferredWorld, World},
};
use bevy_math::{bounding::Aabb3d, Isometry2d, Isometry3d, Vec2, Vec3};
use bevy_math::{Isometry2d, Isometry3d, Vec2, Vec3};
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
use bevy_shape::Aabb3d;
use bevy_transform::TransformPoint;
use bevy_utils::default;

Expand Down Expand Up @@ -665,7 +666,8 @@ where
/// ```
/// # use bevy_gizmos::prelude::*;
/// # use bevy_transform::prelude::*;
/// # use bevy_math::{bounding::Aabb3d, Vec3};
/// # use bevy_math::Vec3;
/// # use bevy_shape::Aabb3d;
/// # use bevy_color::palettes::basic::GREEN;
/// fn system(mut gizmos: Gizmos) {
/// gizmos.aabb_3d(Aabb3d::new(Vec3::ZERO, Vec3::ONE), Transform::IDENTITY, GREEN);
Expand Down
13 changes: 5 additions & 8 deletions crates/bevy_gizmos/src/primitives/dim2.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
//! A module for rendering each of the 2D [`bevy_math::primitives`] with [`GizmoBuffer`].
//! A module for rendering each of the 2D [`bevy_shape`] primitives with [`GizmoBuffer`].

use core::f32::consts::{FRAC_PI_2, PI};

use super::helpers::*;

use bevy_color::Color;
use bevy_math::{
primitives::{
Annulus, Arc2d, Capsule2d, Circle, CircularSector, CircularSegment, Ellipse, Line2d,
Plane2d, Polygon, Polyline2d, Primitive2d, Rectangle, RegularPolygon, Rhombus, Segment2d,
Triangle2d,
},
Dir2, Isometry2d, Rot2, Vec2,
use bevy_math::{Dir2, Isometry2d, Rot2, Vec2};
use bevy_shape::{
Annulus, Arc2d, Capsule2d, Circle, CircularSector, CircularSegment, Ellipse, Line2d, Plane2d,
Polygon, Polyline2d, Primitive2d, Rectangle, RegularPolygon, Rhombus, Segment2d, Triangle2d,
};

use crate::{gizmos::GizmoBuffer, prelude::GizmoConfigGroup};
Expand Down
12 changes: 5 additions & 7 deletions crates/bevy_gizmos/src/primitives/dim3.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
//! A module for rendering each of the 3D [`bevy_math::primitives`] with [`GizmoBuffer`].
//! A module for rendering each of the 3D [`bevy_shape`] primitives with [`GizmoBuffer`].

use super::helpers::*;

use bevy_color::Color;
use bevy_math::{
primitives::{
Capsule3d, Cone, ConicalFrustum, Cuboid, Cylinder, Line3d, Plane3d, Polyline3d,
Primitive3d, Segment3d, Sphere, Tetrahedron, Torus, Triangle3d,
},
Dir3, Isometry3d, Quat, UVec2, Vec2, Vec3,
use bevy_math::{Dir3, Isometry3d, Quat, UVec2, Vec2, Vec3};
use bevy_shape::{
Capsule3d, Cone, ConicalFrustum, Cuboid, Cylinder, Line3d, Plane3d, Polyline3d, Primitive3d,
Segment3d, Sphere, Tetrahedron, Torus, Triangle3d,
};

use crate::{circles::SphereBuilder, gizmos::GizmoBuffer, prelude::GizmoConfigGroup};
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_gizmos/src/primitives/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! A module for rendering each of the 2D and 3D [`bevy_math::primitives`] with [`Gizmos`](`crate::prelude::Gizmos`).
//! A module for rendering all [`bevy_shape`] primitives with [`Gizmos`](`crate::prelude::Gizmos`).

pub mod dim2;
pub mod dim3;
Expand Down
3 changes: 2 additions & 1 deletion crates/bevy_gizmos/src/transform_gizmo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ use bevy_ecs::{
system::{Local, Query, Res, ResMut, Single},
};
use bevy_input::{mouse::MouseButton, ButtonInput};
use bevy_math::{Quat, Ray3d, Vec2, Vec3};
use bevy_math::{Quat, Vec2, Vec3};
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
use bevy_shape::Ray3d;
use bevy_transform::components::{GlobalTransform, Transform};
use bevy_transform::TransformSystems;
use bevy_window::{CursorGrabMode, CursorOptions, PrimaryWindow, Window};
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 @@ -24,6 +24,7 @@ bevy_extract = { path = "../bevy_extract", version = "0.20.0-dev" }
bevy_image = { path = "../bevy_image", version = "0.20.0-dev" }
bevy_mesh = { path = "../bevy_mesh", version = "0.20.0-dev" }
bevy_math = { path = "../bevy_math", version = "0.20.0-dev" }
bevy_shape = { path = "../bevy_shape", version = "0.20.0-dev" }
bevy_asset = { path = "../bevy_asset", version = "0.20.0-dev" }
bevy_shader = { path = "../bevy_shader", version = "0.20.0-dev" }
bevy_render = { path = "../bevy_render", version = "0.20.0-dev" }
Expand Down
6 changes: 2 additions & 4 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_math::{Quat, Vec3};
use bevy_mesh::{Mesh, Mesh3d, MeshBuilder, Meshable};
use bevy_pbr::{MeshMaterial3d, StandardMaterial};
use bevy_shape::{Cone, Cuboid, Cylinder, Torus};
use bevy_transform::{
components::{GlobalTransform, Transform},
systems::propagate_transforms_for,
Expand Down
5 changes: 5 additions & 0 deletions crates/bevy_internal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ serialize = [
"bevy_image?/serialize",
"bevy_input/serialize",
"bevy_math/serialize",
"bevy_shape/serialize",
"bevy_world_serialization?/serialize",
"bevy_time/serialize",
"bevy_transform/serialize",
Expand Down Expand Up @@ -419,6 +420,7 @@ std = [
"bevy_input/std",
"bevy_input_focus?/std",
"bevy_math/std",
"bevy_shape/std",
"bevy_platform/std",
"bevy_reflect/std",
"bevy_state?/std",
Expand Down Expand Up @@ -508,6 +510,9 @@ bevy_math = { path = "../bevy_math", version = "0.20.0-dev", default-features =
"bevy_reflect",
"nostd-libm",
] }
bevy_shape = { path = "../bevy_shape", version = "0.20.0-dev", default-features = false, features = [
"bevy_reflect",
] }
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 @@ -86,6 +86,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_shape as shape;
#[cfg(feature = "bevy_solari")]
pub use bevy_solari as solari;
#[cfg(feature = "bevy_sprite")]
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_internal/src/prelude.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#[doc(hidden)]
pub use crate::{
app::prelude::*, ecs::prelude::*, input::prelude::*, math::prelude::*, platform::prelude::*,
reflect::prelude::*, time::prelude::*, transform::prelude::*, utils::prelude::*,
DefaultPlugins, MinimalPlugins,
reflect::prelude::*, shape::prelude::*, time::prelude::*, transform::prelude::*,
utils::prelude::*, DefaultPlugins, MinimalPlugins,
};

#[doc(hidden)]
Expand Down
1 change: 1 addition & 0 deletions crates/bevy_light/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ bevy_asset = { path = "../bevy_asset", version = "0.20.0-dev" }
bevy_image = { path = "../bevy_image", version = "0.20.0-dev" }
bevy_mesh = { path = "../bevy_mesh", version = "0.20.0-dev" }
bevy_math = { path = "../bevy_math", version = "0.20.0-dev" }
bevy_shape = { path = "../bevy_shape", version = "0.20.0-dev" }
bevy_reflect = { path = "../bevy_reflect", version = "0.20.0-dev" }
bevy_camera = { path = "../bevy_camera", version = "0.20.0-dev" }
bevy_ecs = { path = "../bevy_ecs", version = "0.20.0-dev" }
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 @@ -12,9 +12,9 @@ use bevy_ecs::{
};
use bevy_math::{
ops::{self, sin_cos},
primitives::HalfSpace,
Mat4, UVec3, Vec2, Vec3, Vec3A, Vec3Swizzles as _, Vec4, Vec4Swizzles as _,
};
use bevy_shape::HalfSpace;
use bevy_transform::components::GlobalTransform;
use tracing::{error, warn};

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,8 +7,8 @@ use bevy_camera::{
use bevy_color::Color;
use bevy_ecs::prelude::*;
use bevy_image::Image;
use bevy_math::primitives::ViewFrustum;
use bevy_reflect::prelude::*;
use bevy_shape::ViewFrustum;
use bevy_transform::components::Transform;
use tracing::warn;

Expand Down
7 changes: 2 additions & 5 deletions crates/bevy_light/src/gizmos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,9 @@ 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_shape::{Cone, Sphere};
use bevy_transform::{components::GlobalTransform, TransformSystems};

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

use crate::{cluster::ClusterVisibilityClass, light_consts};
Expand Down
3 changes: 2 additions & 1 deletion crates/bevy_light/src/spot_light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ 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::{proj, Affine3A, Dir3, Mat3, Mat4, Vec3};
use bevy_reflect::prelude::*;
use bevy_shape::ViewFrustum;
use bevy_transform::components::{GlobalTransform, Transform};

use crate::cluster::ClusterVisibilityClass;
Expand Down
13 changes: 2 additions & 11 deletions crates/bevy_math/Cargo.toml
Comment thread
JasmineLowen marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ serde = { version = "1", default-features = false, features = [
libm = { version = "0.2", optional = true }
approx = { version = "0.5", default-features = false, optional = true }
rand = { version = "0.10", default-features = false, optional = true }
rand_distr = { version = "0.6", optional = true }
arrayvec = { version = "0.7", default-features = false }
bevy_reflect = { path = "../bevy_reflect", version = "0.20.0-dev", default-features = false, features = [
"glam",
], optional = true }
Expand All @@ -39,7 +37,6 @@ variadics_please = "2.0"
approx = "0.5"
# Supply rngs for examples and tests
rand = "0.10"
chacha20 = { version = "0.10.0", default-features = false, features = ["rng"] }
# Enable the approx feature when testing.
bevy_math = { path = ".", default-features = false, features = ["approx"] }
glam = { version = "0.33.2", default-features = false, features = ["approx"] }
Expand All @@ -59,15 +56,9 @@ std = [
"serde?/std",
"approx?/std",
"rand?/std",
"rand_distr?/std",
"bevy_reflect?/std",
]
alloc = [
"itertools/use_alloc",
"serde?/alloc",
"rand?/alloc",
"rand_distr?/alloc",
]
alloc = ["itertools/use_alloc", "serde?/alloc", "rand?/alloc"]

serialize = ["dep:serde", "glam/serde"]
# Enable approx for glam types to approximate floating point equality comparisons and assertions
Expand All @@ -82,7 +73,7 @@ glam_assert = ["glam/glam-assert"]
# Enable assertions in debug builds to check the validity of parameters passed to glam
debug_glam_assert = ["glam/debug-glam-assert"]
# Enable the rand dependency for shape_sampling
rand = ["dep:rand", "dep:rand_distr", "glam/rand"]
rand = ["dep:rand", "glam/rand"]
# Include code related to the Curve trait
curve = []
# Enable bevy_reflect (requires alloc)
Expand Down
Loading