diff --git a/crates/bevy_transform/Cargo.toml b/crates/bevy_transform/Cargo.toml index 13173244318ea..cd384e9a919c6 100644 --- a/crates/bevy_transform/Cargo.toml +++ b/crates/bevy_transform/Cargo.toml @@ -10,26 +10,42 @@ keywords = ["bevy"] [dependencies] # bevy -bevy_app = { path = "../bevy_app", version = "0.14.0-dev" } +bevy_app = { path = "../bevy_app", version = "0.14.0-dev", optional = true } bevy_ecs = { path = "../bevy_ecs", version = "0.14.0-dev", features = [ "bevy_reflect", -] } -bevy_hierarchy = { path = "../bevy_hierarchy", version = "0.14.0-dev" } -bevy_math = { path = "../bevy_math", version = "0.14.0-dev" } +], optional = true } +bevy_hierarchy = { path = "../bevy_hierarchy", version = "0.14.0-dev", optional = true } +bevy_math = { path = "../bevy_math", version = "0.14.0-dev", default-features = false } bevy_reflect = { path = "../bevy_reflect", version = "0.14.0-dev", features = [ "bevy", -] } +], optional = true } serde = { version = "1", features = ["derive"], optional = true } thiserror = "1.0" [dev-dependencies] bevy_tasks = { path = "../bevy_tasks", version = "0.14.0-dev" } -bevy_math = { path = "../bevy_math", version = "0.14.0-dev", features = [ +bevy_math = { path = "../bevy_math", version = "0.14.0-dev", default-features = false, features = [ "approx", ] } approx = "0.5.1" [features] +# Adds normal Bevy impls like deriving components, bundles, reflection, as well as adding +# systems for transform propagation and more. +# This exists because it allows opting out of all of this, leaving only a bare-bones transform struct, +# which enables users to depend on that without needing the larger Bevy dependency tree. +bevy-support = [ + "dep:bevy_app", + "dep:bevy_ecs", + "dep:bevy_hierarchy", + "dep:bevy_reflect", + "bevy_math/bevy_reflect", +] + +# Turning off default features leaves you with a barebones +# definition of transform. +default = ["bevy-support"] + serialize = ["dep:serde", "bevy_math/serialize"] [lints] diff --git a/crates/bevy_transform/src/components/global_transform.rs b/crates/bevy_transform/src/components/global_transform.rs index 5ce11f45fbb92..3348119c39d3b 100644 --- a/crates/bevy_transform/src/components/global_transform.rs +++ b/crates/bevy_transform/src/components/global_transform.rs @@ -1,8 +1,10 @@ use std::ops::Mul; use super::Transform; +#[cfg(feature = "bevy-support")] use bevy_ecs::{component::Component, reflect::ReflectComponent}; use bevy_math::{Affine3A, Dir3, Mat4, Quat, Vec3, Vec3A}; +#[cfg(feature = "bevy-support")] use bevy_reflect::{std_traits::ReflectDefault, Reflect}; /// Describe the position of an entity relative to the reference frame. @@ -33,9 +35,13 @@ use bevy_reflect::{std_traits::ReflectDefault, Reflect}; /// - [`transform`] /// /// [`transform`]: https://github.com/bevyengine/bevy/blob/latest/examples/transforms/transform.rs -#[derive(Component, Debug, PartialEq, Clone, Copy, Reflect)] +#[derive(Debug, PartialEq, Clone, Copy)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] -#[reflect(Component, Default, PartialEq)] +#[cfg_attr( + feature = "bevy-support", + derive(Component, Reflect), + reflect(Component, Default, PartialEq) +)] pub struct GlobalTransform(Affine3A); macro_rules! impl_local_axis { diff --git a/crates/bevy_transform/src/components/transform.rs b/crates/bevy_transform/src/components/transform.rs index a7c3d4db0c397..64ed8909307b0 100644 --- a/crates/bevy_transform/src/components/transform.rs +++ b/crates/bevy_transform/src/components/transform.rs @@ -1,8 +1,9 @@ use super::GlobalTransform; +#[cfg(feature = "bevy-support")] use bevy_ecs::{component::Component, reflect::ReflectComponent}; use bevy_math::{Affine3A, Dir3, Mat3, Mat4, Quat, Vec3}; -use bevy_reflect::prelude::*; -use bevy_reflect::Reflect; +#[cfg(feature = "bevy-support")] +use bevy_reflect::{prelude::*, Reflect}; use std::ops::Mul; /// Describe the position of an entity. If the entity has a parent, the position is relative @@ -32,9 +33,13 @@ use std::ops::Mul; /// - [`transform`] /// /// [`transform`]: https://github.com/bevyengine/bevy/blob/latest/examples/transforms/transform.rs -#[derive(Component, Debug, PartialEq, Clone, Copy, Reflect)] +#[derive(Debug, PartialEq, Clone, Copy)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] -#[reflect(Component, Default, PartialEq)] +#[cfg_attr( + feature = "bevy-support", + derive(Component, Reflect), + reflect(Component, Default, PartialEq) +)] pub struct Transform { /// Position of the entity. In 2d, the last value of the `Vec3` is used for z-ordering. /// diff --git a/crates/bevy_transform/src/lib.rs b/crates/bevy_transform/src/lib.rs index 9176a0f4d5e07..9d06635b099e2 100644 --- a/crates/bevy_transform/src/lib.rs +++ b/crates/bevy_transform/src/lib.rs @@ -5,22 +5,27 @@ html_favicon_url = "https://bevyengine.org/assets/icon.png" )] +#[cfg(feature = "bevy-support")] pub mod commands; /// The basic components of the transform crate pub mod components; /// Transform related bundles +#[cfg(feature = "bevy-support")] pub mod bundles; /// Transform related traits pub mod traits; /// Transform related plugins +#[cfg(feature = "bevy-support")] pub mod plugins; /// Helpers related to computing global transforms +#[cfg(feature = "bevy-support")] pub mod helper; /// Systems responsible for transform propagation +#[cfg(feature = "bevy-support")] pub mod systems; #[doc(hidden)] @@ -28,6 +33,7 @@ pub mod prelude { #[doc(hidden)] pub use crate::components::*; + #[cfg(feature = "bevy-support")] #[doc(hidden)] pub use crate::{ bundles::TransformBundle, commands::BuildChildrenTransformExt, helper::TransformHelper, @@ -35,4 +41,5 @@ pub mod prelude { }; } +#[cfg(feature = "bevy-support")] pub use prelude::{TransformPlugin, TransformPoint, TransformSystem};