Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - Split bevy_hierarchy out from bevy_transform #4168

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
d9ed018
Clone bevy_transform contents into bevy_hierarchy
alice-i-cecile Mar 10, 2022
d843703
Remove Transform types from bevy_hierarchy
alice-i-cecile Mar 10, 2022
54e43f0
Remove hierarchy code from bevy_transform
alice-i-cecile Mar 10, 2022
b1c51a5
Fix imports
alice-i-cecile Mar 10, 2022
a258ef9
Add `HierarchyPlugin` to `DefaultPlugins`
alice-i-cecile Mar 10, 2022
58de51d
Fix missing import
alice-i-cecile Mar 10, 2022
7138216
Export bevy_hierarchy prelude in bevy::prelude
alice-i-cecile Mar 10, 2022
de8786d
System labels belong to bevy_hierarchy
alice-i-cecile Mar 10, 2022
9eba280
Fix broken doc links
alice-i-cecile Mar 10, 2022
8559e58
Fix label imports
alice-i-cecile Mar 10, 2022
0484273
Remove broken doc links
alice-i-cecile Mar 10, 2022
c1f279b
Fix broken doc link
alice-i-cecile Mar 10, 2022
e65f14f
Remove redundant .gitignore files
alice-i-cecile Mar 11, 2022
9db9e08
Move transform_propagate_system back to bevy_transform
alice-i-cecile Mar 11, 2022
78e2327
Expose Transform and GlobalTransform at root of bevy_transform
alice-i-cecile Mar 11, 2022
a4fd724
Re-add doc links
alice-i-cecile Mar 11, 2022
41bcf61
Expose ChildBuilder traits in prelude
alice-i-cecile Mar 11, 2022
5fb826c
Revert "Expose Transform and GlobalTransform at root of bevy_transform"
alice-i-cecile Mar 11, 2022
21849e1
Remove dead doc link
alice-i-cecile Mar 12, 2022
ffcea84
Fix doc link
alice-i-cecile Mar 12, 2022
0deeede
Remove unused dependencies
alice-i-cecile Mar 12, 2022
c0db93c
Update crates/bevy_transform/src/lib.rs
cart Mar 15, 2022
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
1 change: 1 addition & 0 deletions crates/bevy_gltf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ bevy_app = { path = "../bevy_app", version = "0.6.0" }
bevy_asset = { path = "../bevy_asset", version = "0.6.0" }
bevy_core = { path = "../bevy_core", version = "0.6.0" }
bevy_ecs = { path = "../bevy_ecs", version = "0.6.0" }
bevy_hierarchy = { path = "../bevy_hierarchy", version = "0.6.0" }
bevy_pbr = { path = "../bevy_pbr", version = "0.6.0" }
bevy_reflect = { path = "../bevy_reflect", version = "0.6.0", features = ["bevy"] }
bevy_render = { path = "../bevy_render", version = "0.6.0" }
Expand Down
8 changes: 3 additions & 5 deletions crates/bevy_gltf/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use bevy_asset::{
};
use bevy_core::Name;
use bevy_ecs::world::World;
use bevy_hierarchy::{BuildWorldChildren, WorldChildBuilder};
use bevy_log::warn;
use bevy_math::{Mat4, Vec3};
use bevy_pbr::{
Expand All @@ -24,11 +25,8 @@ use bevy_render::{
view::VisibleEntities,
};
use bevy_scene::Scene;
use bevy_transform::{
hierarchy::{BuildWorldChildren, WorldChildBuilder},
prelude::Transform,
TransformBundle,
};
use bevy_transform::{components::Transform, TransformBundle};

use bevy_utils::{HashMap, HashSet};
use gltf::{
mesh::Mode,
Expand Down
19 changes: 19 additions & 0 deletions crates/bevy_hierarchy/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "bevy_hierarchy"
version = "0.6.0"
edition = "2021"
description = "Provides hierarchy functionality for Bevy Engine"
homepage = "https://bevyengine.org"
repository = "https://github.com/bevyengine/bevy"
license = "MIT OR Apache-2.0"
keywords = ["bevy"]

[dependencies]
# bevy
bevy_app = { path = "../bevy_app", version = "0.6.0" }
bevy_ecs = { path = "../bevy_ecs", version = "0.6.0", features = ["bevy_reflect"] }
bevy_reflect = { path = "../bevy_reflect", version = "0.6.0", features = ["bevy"] }
bevy_utils = { path = "../bevy_utils", version = "0.6.0" }

# other
smallvec = { version = "1.6", features = ["serde", "union", "const_generics"] }
5 changes: 5 additions & 0 deletions crates/bevy_hierarchy/src/components/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mod children;
mod parent;

pub use children::Children;
pub use parent::{Parent, PreviousParent};
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ mod tests {
};

use super::DespawnRecursiveExt;
use crate::{components::Children, hierarchy::BuildChildren};
use crate::{child_builder::BuildChildren, components::Children};

#[derive(Component, Clone, Copy, PartialEq, Eq, Ord, PartialOrd, Debug)]
struct Idx(u32);
Expand Down
53 changes: 53 additions & 0 deletions crates/bevy_hierarchy/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#![warn(missing_docs)]
//! `bevy_hierarchy` can be used to define hierarchies of entities.
//!
//! Most commonly, these hierarchies are used for inheriting `Transform` values
//! from the [`Parent`] to its [`Children`].

mod components;
pub use components::*;

mod hierarchy;
pub use hierarchy::*;

mod child_builder;
pub use child_builder::*;

mod systems;
pub use systems::*;

#[doc(hidden)]
pub mod prelude {
#[doc(hidden)]
pub use crate::{child_builder::*, components::*, hierarchy::*, HierarchyPlugin};
}

use bevy_app::prelude::*;
use bevy_ecs::prelude::*;

/// The base plugin for handling [`Parent`] and [`Children`] components
#[derive(Default)]
pub struct HierarchyPlugin;

/// Label enum for the systems relating to hierarchy upkeep
#[derive(Debug, Hash, PartialEq, Eq, Clone, SystemLabel)]
pub enum HierarchySystem {
/// Updates [`Parent`] when changes in the hierarchy occur
ParentUpdate,
}

impl Plugin for HierarchyPlugin {
fn build(&self, app: &mut App) {
app.register_type::<Children>()
.register_type::<Parent>()
.register_type::<PreviousParent>()
.add_startup_system_to_stage(
StartupStage::PostStartup,
parent_update_system.label(HierarchySystem::ParentUpdate),
)
.add_system_to_stage(
CoreStage::PostUpdate,
parent_update_system.label(HierarchySystem::ParentUpdate),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,101 +70,3 @@ pub fn parent_update_system(
commands.entity(*e).insert(Children::with(v));
});
}
#[cfg(test)]
mod test {
use bevy_ecs::{
schedule::{Schedule, Stage, SystemStage},
system::CommandQueue,
world::World,
};

use super::*;
use crate::{hierarchy::BuildChildren, transform_propagate_system::transform_propagate_system};

#[test]
fn correct_children() {
let mut world = World::default();

let mut update_stage = SystemStage::parallel();
update_stage.add_system(parent_update_system);
update_stage.add_system(transform_propagate_system);

let mut schedule = Schedule::default();
schedule.add_stage("update", update_stage);

// Add parent entities
let mut command_queue = CommandQueue::default();
let mut commands = Commands::new(&mut command_queue, &world);
let mut children = Vec::new();
let parent = commands
.spawn()
.insert(Transform::from_xyz(1.0, 0.0, 0.0))
.id();
commands.entity(parent).with_children(|parent| {
children.push(
parent
.spawn()
.insert(Transform::from_xyz(0.0, 2.0, 0.0))
.id(),
);
children.push(
parent
.spawn()
.insert(Transform::from_xyz(0.0, 3.0, 0.0))
.id(),
);
});
command_queue.apply(&mut world);
schedule.run(&mut world);

assert_eq!(
world
.get::<Children>(parent)
.unwrap()
.0
.iter()
.cloned()
.collect::<Vec<_>>(),
children,
);

// Parent `e1` to `e2`.
(*world.get_mut::<Parent>(children[0]).unwrap()).0 = children[1];

schedule.run(&mut world);

assert_eq!(
world
.get::<Children>(parent)
.unwrap()
.iter()
.cloned()
.collect::<Vec<_>>(),
vec![children[1]]
);

assert_eq!(
world
.get::<Children>(children[1])
.unwrap()
.iter()
.cloned()
.collect::<Vec<_>>(),
vec![children[0]]
);

assert!(world.despawn(children[0]));

schedule.run(&mut world);

assert_eq!(
world
.get::<Children>(parent)
.unwrap()
.iter()
.cloned()
.collect::<Vec<_>>(),
vec![children[1]]
);
}
}
1 change: 1 addition & 0 deletions crates/bevy_internal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ bevy_core = { path = "../bevy_core", version = "0.6.0" }
bevy_derive = { path = "../bevy_derive", version = "0.6.0" }
bevy_diagnostic = { path = "../bevy_diagnostic", version = "0.6.0" }
bevy_ecs = { path = "../bevy_ecs", version = "0.6.0" }
bevy_hierarchy = { path = "../bevy_hierarchy", version = "0.6.0" }
bevy_input = { path = "../bevy_input", version = "0.6.0" }
bevy_log = { path = "../bevy_log", version = "0.6.0" }
bevy_math = { path = "../bevy_math", version = "0.6.0" }
Expand Down
2 changes: 2 additions & 0 deletions crates/bevy_internal/src/default_plugins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use bevy_app::{PluginGroup, PluginGroupBuilder};
/// * [`LogPlugin`](bevy_log::LogPlugin)
/// * [`CorePlugin`](bevy_core::CorePlugin)
/// * [`TransformPlugin`](bevy_transform::TransformPlugin)
/// * [`HierarchyPlugin`](bevy_hierarchy::HierarchyPlugin)
/// * [`DiagnosticsPlugin`](bevy_diagnostic::DiagnosticsPlugin)
/// * [`InputPlugin`](bevy_input::InputPlugin)
/// * [`WindowPlugin`](bevy_window::WindowPlugin)
Expand All @@ -27,6 +28,7 @@ impl PluginGroup for DefaultPlugins {
group.add(bevy_log::LogPlugin::default());
group.add(bevy_core::CorePlugin::default());
group.add(bevy_transform::TransformPlugin::default());
group.add(bevy_hierarchy::HierarchyPlugin::default());
group.add(bevy_diagnostic::DiagnosticsPlugin::default());
group.add(bevy_input::InputPlugin::default());
group.add(bevy_window::WindowPlugin::default());
Expand Down
5 changes: 5 additions & 0 deletions crates/bevy_internal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ pub mod tasks {
pub use bevy_tasks::*;
}

pub mod hierarchy {
//! Entity hierarchies and property inheritance
pub use bevy_hierarchy::*;
}

pub mod transform {
//! Local and global transforms (e.g. translation, scale, rotation).
pub use bevy_transform::*;
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,7 +1,7 @@
#[doc(hidden)]
pub use crate::{
app::prelude::*, asset::prelude::*, core::prelude::*, ecs::prelude::*, input::prelude::*,
log::prelude::*, math::prelude::*, reflect::prelude::*, scene::prelude::*,
app::prelude::*, asset::prelude::*, core::prelude::*, ecs::prelude::*, hierarchy::prelude::*,
input::prelude::*, log::prelude::*, math::prelude::*, reflect::prelude::*, scene::prelude::*,
transform::prelude::*, utils::prelude::*, window::prelude::*, DefaultPlugins, MinimalPlugins,
};

Expand Down
3 changes: 2 additions & 1 deletion crates/bevy_render/src/view/visibility/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use bevy_app::{CoreStage, Plugin};
use bevy_asset::{Assets, Handle};
use bevy_ecs::prelude::*;
use bevy_reflect::Reflect;
use bevy_transform::{components::GlobalTransform, TransformSystem};
use bevy_transform::components::GlobalTransform;
use bevy_transform::TransformSystem;

use crate::{
camera::{Camera, CameraProjection, OrthographicProjection, PerspectiveProjection},
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_scene/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ bevy_app = { path = "../bevy_app", version = "0.6.0" }
bevy_asset = { path = "../bevy_asset", version = "0.6.0" }
bevy_ecs = { path = "../bevy_ecs", version = "0.6.0" }
bevy_reflect = { path = "../bevy_reflect", version = "0.6.0", features = ["bevy"] }
bevy_transform = { path = "../bevy_transform", version = "0.6.0" }
bevy_hierarchy = { path = "../bevy_hierarchy", version = "0.6.0" }
bevy_utils = { path = "../bevy_utils", version = "0.6.0" }

# other
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_scene/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use bevy_ecs::{
system::{Command, Commands},
world::World,
};
use bevy_transform::hierarchy::ChildBuilder;
use bevy_hierarchy::ChildBuilder;

use crate::{Scene, SceneSpawner};

Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_scene/src/scene_spawner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use bevy_ecs::{
system::Command,
world::{Mut, World},
};
use bevy_hierarchy::{AddChild, Parent};
use bevy_reflect::TypeRegistryArc;
use bevy_transform::{hierarchy::AddChild, prelude::Parent};
use bevy_utils::{tracing::error, HashMap};
use thiserror::Error;
use uuid::Uuid;
Expand Down
24 changes: 0 additions & 24 deletions crates/bevy_transform/.gitignore

This file was deleted.

7 changes: 2 additions & 5 deletions crates/bevy_transform/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "bevy_transform"
version = "0.6.0"
edition = "2021"
description = "Provides hierarchy and transform functionality for Bevy Engine"
description = "Provides transform functionality for Bevy Engine"
homepage = "https://bevyengine.org"
repository = "https://github.com/bevyengine/bevy"
license = "MIT OR Apache-2.0"
Expand All @@ -12,9 +12,6 @@ keywords = ["bevy"]
# bevy
bevy_app = { path = "../bevy_app", version = "0.6.0" }
bevy_ecs = { path = "../bevy_ecs", version = "0.6.0", features = ["bevy_reflect"] }
bevy_hierarchy = { path = "../bevy_hierarchy", version = "0.6.0"}
bevy_math = { path = "../bevy_math", version = "0.6.0" }
bevy_reflect = { path = "../bevy_reflect", version = "0.6.0", features = ["bevy"] }
bevy_utils = { path = "../bevy_utils", version = "0.6.0" }

# other
smallvec = { version = "1.6", features = ["serde", "union", "const_generics"] }
4 changes: 2 additions & 2 deletions crates/bevy_transform/src/components/global_transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ use std::ops::Mul;
/// ## [`Transform`] and [`GlobalTransform`]
///
/// [`Transform`] is the position of an entity relative to its parent position, or the reference
/// frame if it doesn't have a [`Parent`](super::Parent).
/// frame if it doesn't have a [`Parent`](bevy_hierarchy::Parent).
///
/// [`GlobalTransform`] is the position of an entity relative to the reference frame.
///
/// [`GlobalTransform`] is updated from [`Transform`] in the system
/// [`transform_propagate_system`](crate::transform_propagate_system::transform_propagate_system).
/// [`transform_propagate_system`](crate::transform_propagate_system).
///
/// This system runs in stage [`CoreStage::PostUpdate`](crate::CoreStage::PostUpdate). If you
/// update the[`Transform`] of an entity in this stage or after, you will notice a 1 frame lag
Expand Down
4 changes: 0 additions & 4 deletions crates/bevy_transform/src/components/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
mod children;
mod global_transform;
mod parent;
mod transform;

pub use children::Children;
pub use global_transform::*;
pub use parent::{Parent, PreviousParent};
pub use transform::*;
4 changes: 2 additions & 2 deletions crates/bevy_transform/src/components/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ use std::ops::Mul;
/// ## [`Transform`] and [`GlobalTransform`]
///
/// [`Transform`] is the position of an entity relative to its parent position, or the reference
/// frame if it doesn't have a [`Parent`](super::Parent).
/// frame if it doesn't have a [`Parent`](bevy_hierarchy::Parent).
///
/// [`GlobalTransform`] is the position of an entity relative to the reference frame.
///
/// [`GlobalTransform`] is updated from [`Transform`] in the system
/// [`transform_propagate_system`](crate::transform_propagate_system::transform_propagate_system).
/// [`transform_propagate_system`](crate::transform_propagate_system).
///
/// This system runs in stage [`CoreStage::PostUpdate`](crate::CoreStage::PostUpdate). If you
/// update the[`Transform`] of an entity in this stage or after, you will notice a 1 frame lag
Expand Down
8 changes: 0 additions & 8 deletions crates/bevy_transform/src/hierarchy/mod.rs

This file was deleted.

Loading