transform: TransformPlugin
This commit is contained in:
parent
f546aad7f4
commit
d9adea1b5e
@ -74,6 +74,10 @@ impl AppBuilder {
|
||||
self.add_system_to_stage(stage::UPDATE, system)
|
||||
}
|
||||
|
||||
pub fn add_systems(&mut self, systems: Vec<Box<dyn System>>) -> &mut Self {
|
||||
self.add_systems_to_stage(stage::UPDATE, systems)
|
||||
}
|
||||
|
||||
pub fn init_system(
|
||||
&mut self,
|
||||
build: impl FnMut(&mut Resources) -> Box<dyn System>,
|
||||
@ -101,6 +105,19 @@ impl AppBuilder {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn add_startup_systems_to_stage(
|
||||
&mut self,
|
||||
stage_name: &'static str,
|
||||
systems: Vec<Box<dyn System>>,
|
||||
) -> &mut Self {
|
||||
for system in systems {
|
||||
self.app
|
||||
.startup_schedule
|
||||
.add_system_to_stage(stage_name, system);
|
||||
}
|
||||
self
|
||||
}
|
||||
|
||||
pub fn add_startup_system(&mut self, system: Box<dyn System>) -> &mut Self {
|
||||
self.app
|
||||
.startup_schedule
|
||||
@ -108,6 +125,10 @@ impl AppBuilder {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn add_startup_systems(&mut self, systems: Vec<Box<dyn System>>) -> &mut Self {
|
||||
self.add_startup_systems_to_stage(startup_stage::STARTUP, systems)
|
||||
}
|
||||
|
||||
pub fn init_startup_system(
|
||||
&mut self,
|
||||
build: impl FnMut(&mut Resources) -> Box<dyn System>,
|
||||
@ -144,6 +165,17 @@ impl AppBuilder {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn add_systems_to_stage(
|
||||
&mut self,
|
||||
stage_name: &'static str,
|
||||
systems: Vec<Box<dyn System>>,
|
||||
) -> &mut Self {
|
||||
for system in systems {
|
||||
self.app.schedule.add_system_to_stage(stage_name, system);
|
||||
}
|
||||
self
|
||||
}
|
||||
|
||||
pub fn add_event<T>(&mut self) -> &mut Self
|
||||
where
|
||||
T: Send + Sync + 'static,
|
||||
|
||||
@ -10,5 +10,4 @@ bevy_derive = { path = "../bevy_derive" }
|
||||
bevy_ecs = { path = "../bevy_ecs" }
|
||||
bevy_property = { path = "../bevy_property" }
|
||||
bevy_type_registry = { path = "../bevy_type_registry" }
|
||||
bevy_transform = { path = "../bevy_transform" }
|
||||
glam = "0.8.7"
|
||||
@ -1,16 +1,10 @@
|
||||
pub mod bytes;
|
||||
pub mod float_ord;
|
||||
pub mod time;
|
||||
pub mod transform;
|
||||
pub mod math;
|
||||
|
||||
use bevy_app::{stage, startup_stage, AppBuilder, AppPlugin};
|
||||
use bevy_app::{stage, AppBuilder, AppPlugin};
|
||||
use bevy_ecs::IntoQuerySystem;
|
||||
use bevy_transform::{
|
||||
build_systems,
|
||||
components::{
|
||||
Children, LocalTransform, NonUniformScale, Rotation, Scale, Transform, Translation,
|
||||
},
|
||||
};
|
||||
use bevy_type_registry::RegisterType;
|
||||
use glam::{Mat3, Mat4, Quat, Vec2, Vec3};
|
||||
use time::{time_system, timer_system, Time, Timer};
|
||||
@ -20,22 +14,7 @@ pub struct CorePlugin;
|
||||
|
||||
impl AppPlugin for CorePlugin {
|
||||
fn build(&self, app: &mut AppBuilder) {
|
||||
// we also add a copy of transform systems to startup to ensure we begin with correct transform/parent state
|
||||
for transform_system in build_systems() {
|
||||
app.add_startup_system_to_stage(startup_stage::POST_STARTUP, transform_system);
|
||||
}
|
||||
for transform_system in build_systems() {
|
||||
app.add_system_to_stage(stage::POST_UPDATE, transform_system);
|
||||
}
|
||||
|
||||
app.init_resource::<Time>()
|
||||
.register_component::<Children>()
|
||||
.register_component::<LocalTransform>()
|
||||
.register_component::<Transform>()
|
||||
.register_component::<Translation>()
|
||||
.register_component::<Rotation>()
|
||||
.register_component::<Scale>()
|
||||
.register_component::<NonUniformScale>()
|
||||
.register_component::<Timer>()
|
||||
.register_property_type::<Vec2>()
|
||||
.register_property_type::<Vec3>()
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
mod face_toward;
|
||||
mod hierarchy;
|
||||
|
||||
pub use face_toward::*;
|
||||
pub use hierarchy::*;
|
||||
@ -7,8 +7,10 @@ edition = "2018"
|
||||
license = "MIT"
|
||||
|
||||
[dependencies]
|
||||
bevy_app = { path = "../bevy_app"}
|
||||
bevy_ecs = { path = "../bevy_ecs"}
|
||||
bevy_property = { path = "../bevy_property" }
|
||||
bevy_type_registry = { path = "../bevy_type_registry" }
|
||||
glam = "0.8.7"
|
||||
log = "0.4"
|
||||
smallvec = { version = "1.4", features = ["serde"] }
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
use crate::components::Children;
|
||||
use bevy_ecs::{Entity, Query};
|
||||
use bevy_transform::prelude::Children;
|
||||
|
||||
pub fn run_on_hierarchy<T, S>(
|
||||
children_query: &Query<&Children>,
|
||||
@ -109,7 +109,7 @@ pub fn hierarchy_maintenance_systems() -> Vec<Box<dyn System>> {
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use crate::build_systems;
|
||||
use crate::transform_systems;
|
||||
use bevy_ecs::{Resources, Schedule, World};
|
||||
|
||||
#[test]
|
||||
@ -119,7 +119,7 @@ mod test {
|
||||
|
||||
let mut schedule = Schedule::default();
|
||||
schedule.add_stage("update");
|
||||
for system in build_systems() {
|
||||
for system in transform_systems() {
|
||||
schedule.add_system_to_stage("update", system);
|
||||
}
|
||||
|
||||
9
crates/bevy_transform/src/hierarchy/mod.rs
Normal file
9
crates/bevy_transform/src/hierarchy/mod.rs
Normal file
@ -0,0 +1,9 @@
|
||||
mod child_builder;
|
||||
mod hierarchy;
|
||||
mod hierarchy_maintenance_system;
|
||||
mod world_child_builder;
|
||||
|
||||
pub use child_builder::*;
|
||||
pub use hierarchy::*;
|
||||
pub use hierarchy_maintenance_system::*;
|
||||
pub use world_child_builder::*;
|
||||
@ -1,27 +1,45 @@
|
||||
pub use glam as math;
|
||||
|
||||
pub mod child_builder;
|
||||
pub mod hierarchy;
|
||||
pub mod components;
|
||||
pub mod hierarchy_maintenance_system;
|
||||
pub mod local_transform_systems;
|
||||
pub mod transform_propagate_system;
|
||||
pub mod transform_systems;
|
||||
pub mod world_child_builder;
|
||||
|
||||
pub mod prelude {
|
||||
pub use crate::{build_systems, child_builder::*, components::*, world_child_builder::*};
|
||||
pub use crate::{components::*, hierarchy::*, TransformPlugin};
|
||||
}
|
||||
|
||||
use bevy_app::{AppBuilder, AppPlugin};
|
||||
use bevy_ecs::{IntoQuerySystem, System};
|
||||
use bevy_type_registry::RegisterType;
|
||||
use prelude::{Children, LocalTransform, NonUniformScale, Rotation, Scale, Transform, Translation};
|
||||
|
||||
// TODO: make this a plugin
|
||||
pub fn build_systems() -> Vec<Box<dyn System>> {
|
||||
let mut all_systems = Vec::with_capacity(5);
|
||||
pub(crate) fn transform_systems() -> Vec<Box<dyn System>> {
|
||||
let mut systems = Vec::with_capacity(5);
|
||||
|
||||
all_systems.append(&mut hierarchy_maintenance_system::hierarchy_maintenance_systems());
|
||||
all_systems.append(&mut local_transform_systems::local_transform_systems());
|
||||
all_systems.append(&mut transform_systems::transform_systems());
|
||||
all_systems.push(transform_propagate_system::transform_propagate_system.system());
|
||||
systems.append(&mut hierarchy::hierarchy_maintenance_systems());
|
||||
systems.append(&mut local_transform_systems::local_transform_systems());
|
||||
systems.append(&mut transform_systems::transform_systems());
|
||||
systems.push(transform_propagate_system::transform_propagate_system.system());
|
||||
|
||||
all_systems
|
||||
systems
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct TransformPlugin;
|
||||
|
||||
impl AppPlugin for TransformPlugin {
|
||||
fn build(&self, app: &mut AppBuilder) {
|
||||
app.register_component::<Children>()
|
||||
.register_component::<LocalTransform>()
|
||||
.register_component::<Transform>()
|
||||
.register_component::<Translation>()
|
||||
.register_component::<Rotation>()
|
||||
.register_component::<Scale>()
|
||||
.register_component::<NonUniformScale>()
|
||||
// add transform systems to startup so the first update is "correct"
|
||||
.add_startup_systems(transform_systems())
|
||||
.add_systems(transform_systems());
|
||||
}
|
||||
}
|
||||
|
||||
@ -70,7 +70,7 @@ fn propagate_recursive(
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use crate::build_systems;
|
||||
use crate::transform_systems;
|
||||
use bevy_ecs::{Resources, Schedule, World};
|
||||
use glam::{Mat4, Vec3};
|
||||
|
||||
@ -81,7 +81,7 @@ mod test {
|
||||
|
||||
let mut schedule = Schedule::default();
|
||||
schedule.add_stage("update");
|
||||
for system in build_systems() {
|
||||
for system in transform_systems() {
|
||||
schedule.add_system_to_stage("update", system);
|
||||
}
|
||||
|
||||
|
||||
@ -8,7 +8,6 @@ edition = "2018"
|
||||
bevy_app = { path = "../bevy_app" }
|
||||
bevy_asset = { path = "../bevy_asset" }
|
||||
bevy_type_registry = { path = "../bevy_type_registry" }
|
||||
bevy_core = { path = "../bevy_core" }
|
||||
bevy_derive = { path = "../bevy_derive" }
|
||||
bevy_ecs = { path = "../bevy_ecs" }
|
||||
bevy_sprite = { path = "../bevy_sprite" }
|
||||
|
||||
@ -1,7 +1,9 @@
|
||||
use super::Node;
|
||||
use bevy_core::transform::run_on_hierarchy;
|
||||
use bevy_ecs::{Entity, Query, Res, Without};
|
||||
use bevy_transform::prelude::{Children, Parent, Translation};
|
||||
use bevy_transform::{
|
||||
hierarchy,
|
||||
prelude::{Children, Parent, Translation},
|
||||
};
|
||||
use bevy_window::Windows;
|
||||
use glam::Vec2;
|
||||
|
||||
@ -39,7 +41,7 @@ pub fn ui_update_system(
|
||||
size: window_size,
|
||||
});
|
||||
for entity in orphan_nodes {
|
||||
previous_sibling_result = run_on_hierarchy(
|
||||
previous_sibling_result = hierarchy::run_on_hierarchy(
|
||||
&children_query,
|
||||
&mut node_query,
|
||||
entity,
|
||||
|
||||
@ -7,7 +7,7 @@ pub use crate::{
|
||||
audio::{AudioOutput, AudioSource},
|
||||
core::{
|
||||
time::{Time, Timer},
|
||||
transform::FaceToward,
|
||||
math::FaceToward,
|
||||
},
|
||||
diagnostic::DiagnosticsPlugin,
|
||||
ecs::{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user