Skip to content

Commit

Permalink
feat: robot arm phone animations
Browse files Browse the repository at this point in the history
  • Loading branch information
mrchantey committed Oct 29, 2024
1 parent 1f2401e commit 4b977f6
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 28 deletions.
5 changes: 4 additions & 1 deletion crates/beet_flow/src/actions/global/end_continued_run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ pub fn end_continued_run(
mut commands: Commands,
running: Populated<Entity, With<Running>>,
children: Query<&Children>,
children_should_remove: Populated<(), (With<Running>, Without<NoInterrupt>)>,
children_should_remove: Populated<
(),
(With<Running>, Without<NoInterrupt>),
>,
) {
if let Some(entity) = running.get(trigger.entity()).ok() {
commands.entity(entity).remove::<Running>();
Expand Down
28 changes: 25 additions & 3 deletions crates/beet_flow/src/actions/misc/repeat.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
use crate::prelude::*;
use bevy::prelude::*;


/// This does **not** trigger observers, making it safe from infinite loops
/// Reattaches the [`RunOnSpawn`] component whenever [`OnRunResult`] is called.
pub type Repeat = InsertOnRunResult<RunOnSpawn>;


// /// This does **not** trigger observers, making it safe from infinite loops
// /// Reattaches the [`RunOnSpawn`] component whenever [`OnRunResult`] is called.
#[derive(Debug, Clone, PartialEq, Component, Action, Reflect)]
#[reflect(Default, Component, ActionMeta)]
#[category(ActionCategory::Behavior)]
#[observers(repeat)]
pub struct Repeat {
// TODO times
// pub times: RepeatAnimation,
}

impl Default for Repeat {
fn default() -> Self {
Self {
// times: RepeatAnimation::Forever,
}
}
}

fn repeat(trigger: Trigger<OnRunResult>, mut commands: Commands) {
commands.entity(trigger.entity()).insert(RunOnSpawn);
}
4 changes: 4 additions & 0 deletions crates/beet_flow/src/lifecycle/lifecycle_plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ impl Plugin for LifecyclePlugin {
RunTimer,
LogOnRun,
Repeat,
InsertOnRun<Repeat>,
RemoveOnRun<Repeat>,
InsertOnRunResult<Repeat>,
RemoveOnRunResult<Repeat>,
SequenceFlow,
FallbackFlow,
ParallelFlow,
Expand Down
7 changes: 4 additions & 3 deletions crates/emby/examples/emote_arm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ use emby::prelude::*;

pub fn main() {
App::new()
.add_plugins((crate_test_beet_example_plugin, EmbyPlugin))
.add_plugins((crate_test_beet_example_plugin, plugin_ml, EmbyPlugin))
.add_systems(
Startup,
(
beetmash::core::scenes::lighting_3d,
beetmash::core::scenes::ground_3d,
beet_examples::scenes::flow::beet_debug_start_and_stop,
beet_examples::scenes::spatial::spawn_ik_camera,
beetmash::core::scenes::ui_terminal_input,
// beet_examples::scenes::flow::beet_debug_start_and_stop,
emby::scenes::emote_arm_camera,
emby::scenes::emote_arm,
emby::scenes::spawn_barbarian,
emby::scenes::phone_texture_camera_3d,
Expand Down
4 changes: 3 additions & 1 deletion crates/emby/examples/interaction.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use beet::prelude::*;
use beet_examples::prelude::*;
use bevy::prelude::*;
use bevy::render::view::RenderLayers;
use emby::prelude::*;

fn main() {
Expand All @@ -23,6 +24,7 @@ fn main() {
fn setup(mut commands: Commands) {
commands.spawn((
Camera3d::default(),
Transform::from_xyz(0., 1.6, 5.)
RenderLayers::layer(0).with(RENDER_TEXTURE_LAYER),
Transform::from_xyz(0., 1.6, 5.),
));
}
67 changes: 47 additions & 20 deletions crates/emby/src/scenes/emote_arm.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
use beet::prelude::*;
use beetmash::prelude::*;
use bevy::color::palettes::tailwind;
use bevy::prelude::*;
use forky::prelude::TransformExt;
use std::f32::consts::TAU;
use std::time::Duration;




pub fn emote_arm_camera(mut commands: Commands) {
commands.spawn((
Name::new("Camera"),
BundlePlaceholder::Camera3d,
Transform::from_xyz(0., 2., 5.)
.looking_at(Vec3::new(0., 2., 0.), Vec3::Y),
));
}


pub fn emote_arm(mut commands: Commands) {
let mut target = Entity::PLACEHOLDER;
let pos_happy = Vec3::new(0., 3., 0.);
let pos_happy = Vec3::new(0., 2.5, 0.);
let pos_idle = Vec3::new(0., 2., 0.);

let transform_idle = Transform::from_translation(pos_idle)
Expand All @@ -22,10 +34,14 @@ pub fn emote_arm(mut commands: Commands) {
.spawn((Name::new("Target Parent"), transform_idle))
.with_children(|parent| {
target = parent
.spawn((Name::new("Target"), BundlePlaceholder::Pbr {
mesh: Sphere::new(0.2).into(),
material: MaterialPlaceholder::unlit(tailwind::BLUE_500),
}))
.spawn((
Name::new("Target"),
Transform::default(),
// BundlePlaceholder::Pbr {
// mesh: Sphere::new(0.2).into(),
// material: MaterialPlaceholder::unlit(tailwind::BLUE_500),
// }
))
.id();
})
.id();
Expand All @@ -39,9 +55,9 @@ pub fn emote_arm(mut commands: Commands) {
IkSpawner::default(),
));

commands
let idle_behavior = commands
.spawn((
Name::new("Behavior"),
Name::new("Idle Behavior"),
RunOnSpawn,
Repeat::default(),
SequenceFlow,
Expand All @@ -51,7 +67,10 @@ pub fn emote_arm(mut commands: Commands) {
Name::new("New Pos"),
InsertOnRun::new(transform_idle).with_target(target_parent),
TargetAgent(target),
SetCurveOnRun::default(),
SetCurveOnRun::EaseRangeDir2 {
range: -TAU * 0.1..TAU * 0.1,
func: EaseFunction::CubicInOut,
},
PlayProceduralAnimation::default()
// .with_meter_per_second(1.),
.with_duration_secs(2.),
Expand All @@ -63,15 +82,23 @@ pub fn emote_arm(mut commands: Commands) {
Duration::from_secs(1)..Duration::from_secs(4),
),
));
parent.spawn((
Name::new("Happy"),
TargetAgent(target_parent),
SetCurveOnRun::PingPongPause {
target: pos_happy,
pause: 1.,
func: EaseFunction::CubicInOut,
},
PlayProceduralAnimation::default().with_duration_secs(4.),
));
});
})
.id();

commands.spawn((
Name::new("Happy"),
RemoveOnRun::<Repeat>::default().with_target(idle_behavior),
EndOnRun::success().with_target(idle_behavior),
TargetAgent(target_parent),
InsertSentenceOnUserInput::default(),
RunOnInsertSentence::default(),
SetCurveOnRun::PingPongPause {
target: pos_happy,
pause: 0.1,
func: EaseFunction::CubicInOut,
},
PlayProceduralAnimation::default().with_duration_secs(2.),
RunOnRunResult::new_with_target(idle_behavior),
InsertOnRunResult::<Repeat>::default().with_target(idle_behavior),
));
}

0 comments on commit 4b977f6

Please sign in to comment.