From 355d30f59a9b9d58efdf76d515509dc44de108b4 Mon Sep 17 00:00:00 2001 From: Brooks Palin Date: Mon, 18 Mar 2024 16:43:36 -0600 Subject: [PATCH] Stopping for now --- studio/src/anim/mod.rs | 46 +++++++++++++++++++++++++++++++++++++--- studio/src/bvh/loader.rs | 3 +-- studio/src/main.rs | 7 +++++- studio/src/mixamo.rs | 9 ++++++-- 4 files changed, 57 insertions(+), 8 deletions(-) diff --git a/studio/src/anim/mod.rs b/studio/src/anim/mod.rs index ce98564..ad0c471 100644 --- a/studio/src/anim/mod.rs +++ b/studio/src/anim/mod.rs @@ -2,11 +2,11 @@ use bevy::{ math::Affine3A, prelude::*, render::{mesh::skinning::SkinnedMesh, view::NoFrustumCulling}, - utils::{EntityHashMap, EntityHashSet}, + utils::{EntityHashMap, EntityHashSet, HashMap}, }; use space_editor::space_prefab::editor_registry::EditorRegistryExt; -use crate::{hierarchy, scene::SceneElement}; +use crate::{hierarchy, interaction::Selected, scene::SceneElement}; pub use retargeting::*; mod camera; @@ -26,15 +26,22 @@ impl Plugin for AnimPlugin { .register_type::() .editor_registry::() .register_type::() - .editor_registry::(); + .editor_registry::() + .register_type::() + ; app.add_systems(Update, process_skinned_meshes); app.insert_resource(GlobalSeekTime(0.)); app.add_plugins((retargeting::RetargetingPlugin, camera::CameraAnimPlugin)); + + //Stuff for animation atachment + app.add_systems(PostUpdate, check_selected_for_animation); #[cfg(feature = "wasm")] app.add_systems(Update, wasm::update_global_seek_time); + + app.init_resource::(); } } @@ -150,6 +157,39 @@ fn process_skinned_meshes( } } +//============================================================================== +// Loaded anims +//============================================================================== + +#[derive(Resource, Default, Reflect)] +#[reflect(Resource)] +pub struct LoadedAnimations { + pub animations : Vec> +} + +//============================================================================== +// Animation attachment +//============================================================================== + +fn check_selected_for_animation( + selected : Query<&Name, (With, Added)>, + loaded_animations : Res, + animation_assets : Res>, +) { + for name in selected.iter() { + println!("Thing selected"); + let animations = loaded_animations.animations.iter() + .map(|handle| animation_assets.get(handle).unwrap()); + + for animation in animations { + println!("Animation Compatible: {}", animation.compatible_with(name)); + if animation.compatible_with(name) { + println!("Compatible animation: {:?}", animation); + } + } + } +} + #[cfg(feature = "wasm")] mod wasm { use bevy::prelude::*; diff --git a/studio/src/bvh/loader.rs b/studio/src/bvh/loader.rs index bdc3a5c..f73a5b9 100644 --- a/studio/src/bvh/loader.rs +++ b/studio/src/bvh/loader.rs @@ -28,13 +28,12 @@ impl AssetLoader for BvhLoader { let mut buf = vec![]; reader.read_to_end(&mut buf).await.anyhow()?; let bvh = studio_bvh::from_bytes(&buf).anyhow()?; - // println!("{:?}", bvh.joints_len()); let mut anim_clip = AnimationClip::default(); for (index, joint) in bvh.joints().enumerate() { let path = get_entity_path(&joint, &RetargetMap::default()); - println!("{} - {:?}", index, path); + // println!("{} - {:?}", index, path); let mut timestamps = Vec::new(); let mut motions = Vec::new(); let mut rotations = Vec::new(); diff --git a/studio/src/main.rs b/studio/src/main.rs index 0d0d6d6..1837d3e 100644 --- a/studio/src/main.rs +++ b/studio/src/main.rs @@ -2,7 +2,7 @@ use bevy::{ app::Update, ecs::{query::With, system::Query}, window::{close_on_esc, Window}, prelude::* }; use clap::Parser; -use studio::{anim::Skeleton, scene::{tag_scene_elements, SceneState}, screenshot::ScreenShotPlugin, InitAsset, InitParams, StudioMode}; +use studio::{anim::Skeleton, scene::{tag_scene_elements, SceneState}, screenshot::ScreenShotPlugin, InitAsset, InitParams, MixamoImportEvent, MixamoPlugin, StudioMode}; #[derive(Parser)] #[command(name = "StorytellerStudio")] @@ -39,6 +39,11 @@ fn main() { app.add_systems(Update, add_anim); app.add_plugins(ScreenShotPlugin); + app.add_plugins(MixamoPlugin); + app.add_systems(Startup, move |mut mixamo_load_event : EventWriter| { + mixamo_load_event.send(MixamoImportEvent("mocap/hip-hop-dancing.gltf".into())) + }); + app.run(); } diff --git a/studio/src/mixamo.rs b/studio/src/mixamo.rs index 4534d7f..575db60 100644 --- a/studio/src/mixamo.rs +++ b/studio/src/mixamo.rs @@ -1,6 +1,6 @@ use bevy::{gltf::Gltf, prelude::*, scene::InstanceId}; -use crate::anim::RetargetSource; +use crate::anim::{LoadedAnimations, RetargetSource}; pub struct MixamoPlugin; impl Plugin for MixamoPlugin { @@ -97,6 +97,8 @@ fn tick_scene_spawning( r_scene_spawner: Res, r_mixamo_scene: Res, mut st_next: ResMut>, + mut loaded_animations : ResMut, + ra_gltfs: Res>, ) { if r_scene_spawner.instance_is_ready(**r_mixamo_scene) { st_next.set(MixamoState::Processing); @@ -112,11 +114,14 @@ fn start_mixamo_anim( r_scene_spawner: Res, q_names: Query<&Name>, mut st_next: ResMut>, + mut loaded_animations : ResMut, ) { let gltf = ra_gltfs.get(&**r_mixamo_import).unwrap(); let src_anim_handle = gltf.animations[0].clone(); let src_anim = ra_animations.get(src_anim_handle.clone()).unwrap(); - + + loaded_animations.animations.push(src_anim_handle.clone()); + let Some(src_root) = r_scene_spawner .iter_instance_entities(**r_mixamo_scene) .find(|ent| match q_names.get(*ent) {