diff --git a/crates/beet_examples/examples/render_texture.rs b/crates/beet_examples/examples/render_texture.rs new file mode 100644 index 00000000..13f49276 --- /dev/null +++ b/crates/beet_examples/examples/render_texture.rs @@ -0,0 +1,32 @@ +use beet_examples::prelude::*; +use beet_flow::prelude::*; +use bevy::prelude::*; + + +fn main() { + App::new() + .add_plugins((crate_test_beet_example_plugin, plugin_ml)) + .insert_resource(BeetDebugConfig::default()) + .add_systems( + Startup, + ( + setup, + beetmash::core::scenes::lighting_3d, + beetmash::core::scenes::ground_3d, + beetmash::core::scenes::ui_terminal_input, + beet_examples::emote_agent::scenes::spawn_barbarian, + ), + ) + // .add_systems(Update,disable_barbarian) + .run(); +} + + +fn setup(mut commands: Commands, asset_server: Res) { + commands.spawn(( + Camera3d::default(), + Transform::from_xyz(0., 1.6, 5.), // .looking_at(Vec3::ZERO, Vec3::Y), + )); + + commands.insert_resource(EmojiMap::new(&asset_server)); +} diff --git a/crates/beet_examples/src/emote_agent/apply_render_layers.rs b/crates/beet_examples/src/emote_agent/apply_render_layers.rs new file mode 100644 index 00000000..064b0600 --- /dev/null +++ b/crates/beet_examples/src/emote_agent/apply_render_layers.rs @@ -0,0 +1,24 @@ +use bevy::prelude::*; +use bevy::render::view::RenderLayers; +use bevy::scene::SceneInstanceReady; + + +/// Currently [`RenderLayers`] are not applied to children of a scene. +/// This [`SceneInstanceReady`] observer applies the [`RenderLayers`] +/// of a [`SceneRoot`] to all children with a [`Transform`]. +pub fn apply_render_layers_to_children( + trigger: Trigger, + mut commands: Commands, + children: Query<&Children>, + transforms: Query<&Transform>, + query: Populated<(Entity, &RenderLayers)>, +) { + let Ok((parent, render_layers)) = query.get(trigger.entity()) else { + return; + }; + children.iter_descendants(parent).for_each(|entity| { + if transforms.contains(entity) { + commands.entity(entity).insert(render_layers.clone()); + } + }); +} diff --git a/crates/beet_examples/src/emote_agent/emote_agent_plugin.rs b/crates/beet_examples/src/emote_agent/emote_agent_plugin.rs new file mode 100644 index 00000000..b1048785 --- /dev/null +++ b/crates/beet_examples/src/emote_agent/emote_agent_plugin.rs @@ -0,0 +1,16 @@ +use crate::prelude::*; +use bevy::prelude::*; + + + +pub fn emote_agent_plugin(app: &mut App) { + app.add_observer(apply_render_layers_to_children) + .add_systems( + Update, + ( + ik_spawner.never_param_warn(), + update_emoji_swapper.never_param_warn(), + ), + ) + .register_type::(); +} diff --git a/crates/beet_examples/src/emote_agent/mod.rs b/crates/beet_examples/src/emote_agent/mod.rs index a839b21a..91728bd9 100644 --- a/crates/beet_examples/src/emote_agent/mod.rs +++ b/crates/beet_examples/src/emote_agent/mod.rs @@ -1,3 +1,6 @@ +pub mod apply_render_layers; +#[allow(unused_imports)] +pub use self::apply_render_layers::*; pub mod emoji; #[allow(unused_imports)] pub use self::emoji::*; @@ -7,6 +10,9 @@ pub use self::emoji_map::*; pub mod emoji_swapper; #[allow(unused_imports)] pub use self::emoji_swapper::*; +pub mod emote_agent_plugin; +#[allow(unused_imports)] +pub use self::emote_agent_plugin::*; pub mod emote_bubble; #[allow(unused_imports)] pub use self::emote_bubble::*; diff --git a/crates/beet_examples/src/emote_agent/scenes/barbarian.rs b/crates/beet_examples/src/emote_agent/scenes/barbarian.rs index f74248c8..832f44f6 100644 --- a/crates/beet_examples/src/emote_agent/scenes/barbarian.rs +++ b/crates/beet_examples/src/emote_agent/scenes/barbarian.rs @@ -3,6 +3,7 @@ use crate::prelude::*; use beetmash::prelude::*; use bevy::animation::RepeatAnimation; use bevy::prelude::*; +use bevy::render::view::RenderLayers; pub fn spawn_barbarian(mut commands: Commands) { let mut graph = AnimationGraphPlaceholder::default(); @@ -30,6 +31,7 @@ pub fn spawn_barbarian(mut commands: Commands) { AssetLoadBlockAppReady, graph, AnimationTransitions::default(), + // RenderLayers::layer(RENDER_TEXTURE_LAYER), )) .with_children(|parent| { let agent = parent.parent_entity(); @@ -37,6 +39,7 @@ pub fn spawn_barbarian(mut commands: Commands) { let emote_bubble = spawn_emote_bubble(&mut parent.spawn(( Transform::from_xyz(0.5, 2.5, 0.5), Visibility::Hidden, + RenderLayers::layer(RENDER_TEXTURE_LAYER), ))); idle_behavior = parent @@ -52,12 +55,9 @@ pub fn spawn_barbarian(mut commands: Commands) { EndOnRun::success().with_target(idle_behavior), InsertSentenceOnUserInput::default(), RunOnInsertSentence::default(), - InsertOnTrigger::::new(Visibility::Visible) + InsertOnRun::new(Visibility::Visible).with_target(emote_bubble), + InsertOnRunResult::new(Visibility::Hidden) .with_target(emote_bubble), - InsertOnTrigger::::new( - Visibility::Hidden, - ) - .with_target(emote_bubble), TargetAgent(agent), cheer_animation_bundle, RunOnRunResult::new_with_target(idle_behavior), diff --git a/crates/beet_examples/src/emote_agent/scenes/phone_texture.rs b/crates/beet_examples/src/emote_agent/scenes/phone_texture.rs index c1e6489c..746d7ab7 100644 --- a/crates/beet_examples/src/emote_agent/scenes/phone_texture.rs +++ b/crates/beet_examples/src/emote_agent/scenes/phone_texture.rs @@ -2,7 +2,7 @@ use crate::prelude::*; use bevy::prelude::*; use bevy::render::view::RenderLayers; -pub fn phone_texture( +pub fn phone_texture_emoji( mut commands: Commands, asset_server: Res, mut texture_atlas_layouts: ResMut>, @@ -23,7 +23,7 @@ pub fn phone_texture( )); } -pub fn phone_texture_camera( +pub fn phone_texture_camera_2d( mut commands: Commands, mut images: ResMut>, mut materials: ResMut>, @@ -34,3 +34,13 @@ pub fn phone_texture_camera( Camera2d, )); } +pub fn phone_texture_camera_3d( + mut commands: Commands, + mut images: ResMut>, + mut materials: ResMut>, +) { + commands.spawn(( + render_texture_bundle(&mut images, &mut materials), + Camera3d::default(), + )); +} diff --git a/crates/beet_examples/src/plugins/beet_example_plugin.rs b/crates/beet_examples/src/plugins/beet_example_plugin.rs index 0ed52876..31da8c18 100644 --- a/crates/beet_examples/src/plugins/beet_example_plugin.rs +++ b/crates/beet_examples/src/plugins/beet_example_plugin.rs @@ -43,7 +43,7 @@ pub fn beet_example_plugin(app: &mut App) { DefaultReplicatePlugin, temp_patches, )) - .add_plugins((plugin_spatial, plugin_2d, plugin_3d)) + .add_plugins((plugin_spatial, plugin_2d, plugin_3d, emote_agent_plugin)) .register_type::(); } @@ -52,10 +52,10 @@ pub fn beet_example_plugin(app: &mut App) { fn plugin_spatial(app: &mut App) { app .add_plugins(ActionPlugin::<( - RemoveOnTrigger, - RemoveOnTrigger, - InsertOnTrigger, - RemoveOnTrigger, + RemoveOnRunResult, + RemoveOnRunResult, + InsertOnRun, + RemoveOnRun, )>::default()) /*-*/; } @@ -75,7 +75,7 @@ pub fn plugin_ml(app: &mut App) { // fetch .add_plugins(ActionPlugin::<( InsertSentenceSteerTarget, - RemoveOnTrigger, + RemoveOnRunResult, )>::default()) /*-*/; } @@ -106,10 +106,7 @@ fn plugin_3d(app: &mut App) { camera_distance, rotate_collectables, keyboard_controller, - ik_spawner.never_param_warn(), - update_emoji_swapper.never_param_warn() )) - .register_type::() .register_type::() .register_type::() .register_type::() diff --git a/crates/beet_examples/src/scenes/ml/fetch.rs b/crates/beet_examples/src/scenes/ml/fetch.rs index 2d8dda10..ea7a45a9 100644 --- a/crates/beet_examples/src/scenes/ml/fetch.rs +++ b/crates/beet_examples/src/scenes/ml/fetch.rs @@ -40,7 +40,7 @@ pub fn fetch_npc(mut commands: Commands) { RunOnSteerTargetInsert::new_with_source(agent), RunOnSteerTargetRemove::new_with_source(agent), ScoreFlow::default(), - RemoveOnTrigger::::default(), + RemoveOnRunResult::::default(), )) .with_children(|parent| { parent.spawn(( @@ -57,11 +57,13 @@ pub fn fetch_npc(mut commands: Commands) { max_radius: 10., }, PlayAnimation::new(walk_index).repeat_forever(), - InsertOnTrigger::::new_with_target(agent), + InsertOnRun::::new_with_target(agent), Seek::default(), EndOnArrive::new(1.), - RemoveOnTrigger::::new_with_target(agent), - RemoveOnTrigger::::new_with_target(agent), + RemoveOnRunResult::::new_with_target( + agent, + ), + RemoveOnRunResult::::new_with_target(agent), )); }); }); diff --git a/crates/beet_examples/src/scenes/spatial/seek_3d.rs b/crates/beet_examples/src/scenes/spatial/seek_3d.rs index 0ec35b78..01545439 100644 --- a/crates/beet_examples/src/scenes/spatial/seek_3d.rs +++ b/crates/beet_examples/src/scenes/spatial/seek_3d.rs @@ -64,9 +64,7 @@ pub fn seek_3d(mut commands: Commands) { .with_children(|parent| { parent.spawn(( Name::new("Idle"), - RemoveOnTrigger::::new_with_target( - agent, - ), + RemoveOnRun::::new_with_target(agent), TargetAgent(agent), PlayAnimation::new(idle_index) .with_transition_duration(transition_duration), @@ -81,9 +79,7 @@ pub fn seek_3d(mut commands: Commands) { Name::new("Seek"), TargetAgent(agent), Seek::default(), - InsertOnTrigger::::new_with_target( - agent, - ), + InsertOnRun::::new_with_target(agent), PlayAnimation::new(walk_index) .repeat_forever() .with_transition_duration(transition_duration), diff --git a/crates/beet_flow/src/actions/misc/repeat.rs b/crates/beet_flow/src/actions/misc/repeat.rs index 094e2add..6d9bd102 100644 --- a/crates/beet_flow/src/actions/misc/repeat.rs +++ b/crates/beet_flow/src/actions/misc/repeat.rs @@ -3,4 +3,4 @@ use crate::prelude::*; /// This does **not** trigger observers, making it safe from infinite loops /// Reattaches the [`RunOnSpawn`] component whenever [`OnRunResult`] is called. -pub type Repeat = InsertOnTrigger; +pub type Repeat = InsertOnRunResult; diff --git a/crates/beet_flow/src/actions/on_trigger/aliases.rs b/crates/beet_flow/src/actions/on_trigger/aliases.rs new file mode 100644 index 00000000..6f7960cc --- /dev/null +++ b/crates/beet_flow/src/actions/on_trigger/aliases.rs @@ -0,0 +1,8 @@ +use crate::prelude::*; + + +pub type InsertOnRun = InsertOnTrigger; +pub type InsertOnRunResult = InsertOnTrigger; + +pub type RemoveOnRun = RemoveOnTrigger; +pub type RemoveOnRunResult = RemoveOnTrigger; diff --git a/crates/beet_flow/src/actions/on_trigger/continue_run.rs b/crates/beet_flow/src/actions/on_trigger/continue_run.rs index a697acbf..72139685 100644 --- a/crates/beet_flow/src/actions/on_trigger/continue_run.rs +++ b/crates/beet_flow/src/actions/on_trigger/continue_run.rs @@ -25,7 +25,7 @@ use bevy::prelude::*; /// ``` #[derive(Debug, Default, Component, Reflect)] #[reflect(Default, Component)] -#[require(RunTimer, InsertOnTrigger, RemoveOnTrigger)] +#[require(RunTimer, InsertOnRun, RemoveOnRunResult)] pub struct ContinueRun; #[cfg(test)] @@ -39,15 +39,12 @@ mod test { fn works() -> Result<()> { let mut app = App::new(); app.add_plugins(ActionPlugin::<( - InsertOnTrigger, - RemoveOnTrigger, + InsertOnRun, + RemoveOnRunResult, )>::default()); let world = app.world_mut(); - let entity = world - .spawn(ContinueRun) - .flush_trigger(OnRun) - .id(); + let entity = world.spawn(ContinueRun).flush_trigger(OnRun).id(); expect(world.entities().len()).to_be(3)?; expect(&*world).to_have_component::(entity)?; world diff --git a/crates/beet_flow/src/actions/on_trigger/insert_on_trigger.rs b/crates/beet_flow/src/actions/on_trigger/insert_on_trigger.rs index 52848178..ae973cc6 100644 --- a/crates/beet_flow/src/actions/on_trigger/insert_on_trigger.rs +++ b/crates/beet_flow/src/actions/on_trigger/insert_on_trigger.rs @@ -3,8 +3,6 @@ use bevy::prelude::*; use std::marker::PhantomData; -pub type InsertOnRun = InsertOnTrigger; - /// Inserts the provided `Bundle` on the [`TriggerOnTrigger::target`] when /// the `EventIn` is triggered on one of the [`TriggerOnTrigger::sources`]. @@ -48,13 +46,11 @@ mod test { #[test] fn works() -> Result<()> { let mut app = App::new(); - app.add_plugins( - ActionPlugin::>::default(), - ); + app.add_plugins(ActionPlugin::>::default()); let world = app.world_mut(); let entity = world - .spawn(InsertOnTrigger::::default()) + .spawn(InsertOnRun::::default()) .flush_trigger(OnRun) .id(); expect(world.entities().len()).to_be(2)?; diff --git a/crates/beet_flow/src/actions/on_trigger/mod.rs b/crates/beet_flow/src/actions/on_trigger/mod.rs index 54cdb5ab..c0f0ca3a 100644 --- a/crates/beet_flow/src/actions/on_trigger/mod.rs +++ b/crates/beet_flow/src/actions/on_trigger/mod.rs @@ -10,6 +10,9 @@ pub use self::insert_on_trigger::*; pub mod on_global_trigger; #[allow(unused_imports)] pub use self::on_global_trigger::*; +pub mod aliases; +#[allow(unused_imports)] +pub use self::aliases::*; pub mod on_trigger_action; #[allow(unused_imports)] pub use self::on_trigger_action::*; diff --git a/crates/beet_flow/src/actions/on_trigger/on_trigger_action.rs b/crates/beet_flow/src/actions/on_trigger/on_trigger_action.rs index 956a5fd5..48ad6172 100644 --- a/crates/beet_flow/src/actions/on_trigger/on_trigger_action.rs +++ b/crates/beet_flow/src/actions/on_trigger/on_trigger_action.rs @@ -144,13 +144,11 @@ mod test { #[test] fn works() -> Result<()> { let mut app = App::new(); - app.add_plugins( - ActionPlugin::>::default(), - ); + app.add_plugins(ActionPlugin::>::default()); let world = app.world_mut(); let entity = world - .spawn(InsertOnTrigger::::default()) + .spawn(InsertOnRun::::default()) .flush_trigger(OnRun) .id(); expect(world.entities().len()).to_be(2)?; @@ -160,17 +158,12 @@ mod test { #[test] fn other_sources() -> Result<()> { let mut app = App::new(); - app.add_plugins( - ActionPlugin::>::default(), - ); + app.add_plugins(ActionPlugin::>::default()); let world = app.world_mut(); let source = world.spawn_empty().id(); let entity = world - .spawn( - InsertOnTrigger::::default() - .with_source(source), - ) + .spawn(InsertOnRun::::default().with_source(source)) .id(); world.entity_mut(source).flush_trigger(OnRun); diff --git a/crates/beet_flow/src/lifecycle/lifecycle_plugin.rs b/crates/beet_flow/src/lifecycle/lifecycle_plugin.rs index a7e03eb8..3a374813 100644 --- a/crates/beet_flow/src/lifecycle/lifecycle_plugin.rs +++ b/crates/beet_flow/src/lifecycle/lifecycle_plugin.rs @@ -14,8 +14,8 @@ impl Plugin for LifecyclePlugin { ActionPlugin::<( EndOnRun, TriggerInDuration, - InsertOnTrigger, - RemoveOnTrigger, + InsertOnRun, + RemoveOnRunResult, RunOnRunResult, RunOnSceneReady, )>::default(), diff --git a/crates/beet_spatial/src/plugins/beet_plugins.rs b/crates/beet_spatial/src/plugins/beet_plugins.rs index 2dc09c51..03a80531 100644 --- a/crates/beet_spatial/src/plugins/beet_plugins.rs +++ b/crates/beet_spatial/src/plugins/beet_plugins.rs @@ -27,7 +27,7 @@ impl PluginGroup for BeetSpatialPlugins { pub fn spatial_observers_plugin(app: &mut App) { app.add_plugins(ActionPlugin::<( - InsertOnTrigger, - InsertOnTrigger, + InsertOnRun, + InsertOnRunResult, )>::default()); } diff --git a/crates/beet_spatial/src/procedural_animation/mod.rs b/crates/beet_spatial/src/procedural_animation/mod.rs index c6006b25..23eddc13 100644 --- a/crates/beet_spatial/src/procedural_animation/mod.rs +++ b/crates/beet_spatial/src/procedural_animation/mod.rs @@ -1,6 +1,3 @@ -pub mod set_curve_on_run; -#[allow(unused_imports)] -pub use self::set_curve_on_run::*; pub mod play_procedural_animation; #[allow(unused_imports)] pub use self::play_procedural_animation::*; @@ -13,3 +10,6 @@ pub use self::procedural_animation_speed::*; pub mod serde_curve; #[allow(unused_imports)] pub use self::serde_curve::*; +pub mod set_curve_on_run; +#[allow(unused_imports)] +pub use self::set_curve_on_run::*; diff --git a/crates/beet_spatial/src/procedural_animation/procedural_animation_plugin.rs b/crates/beet_spatial/src/procedural_animation/procedural_animation_plugin.rs index 49022f6b..7b3f9b8a 100644 --- a/crates/beet_spatial/src/procedural_animation/procedural_animation_plugin.rs +++ b/crates/beet_spatial/src/procedural_animation/procedural_animation_plugin.rs @@ -4,7 +4,7 @@ use bevy::prelude::*; pub fn procedural_animation_plugin(app: &mut App) { - app.add_plugins(ActionPlugin::<( - InsertOnTrigger, - )>::default()); + app.add_plugins( + ActionPlugin::>::default(), + ); } diff --git a/crates/beet_spatial/src/robotics/robotics_plugin.rs b/crates/beet_spatial/src/robotics/robotics_plugin.rs index d126e4a6..7f6effee 100644 --- a/crates/beet_spatial/src/robotics/robotics_plugin.rs +++ b/crates/beet_spatial/src/robotics/robotics_plugin.rs @@ -8,7 +8,7 @@ pub struct RoboticsPlugin; impl Plugin for RoboticsPlugin { fn build(&self, app: &mut App) { app.add_plugins(ActionPlugin::<( - InsertOnTrigger, + InsertOnRun, DepthSensorScorer, )>::default()) .register_type::() diff --git a/examples/inverse_kinematics.rs b/examples/inverse_kinematics.rs index f64067db..164f00a2 100644 --- a/examples/inverse_kinematics.rs +++ b/examples/inverse_kinematics.rs @@ -11,8 +11,8 @@ pub fn main() { beetmash::core::scenes::ground_3d, beet_examples::emote_agent::scenes::spawn_ik_camera, beet_examples::emote_agent::scenes::spawn_arm_with_keyboard_target, - beet_examples::emote_agent::scenes::phone_texture, - beet_examples::emote_agent::scenes::phone_texture_camera, + beet_examples::emote_agent::scenes::phone_texture_emoji, + beet_examples::emote_agent::scenes::phone_texture_camera_2d, ), ) .run();