diff --git a/studio/assets/gltf/Mannequin.glb b/studio/assets/gltf/Mannequin.glb new file mode 100644 index 0000000..a5a9e32 Binary files /dev/null and b/studio/assets/gltf/Mannequin.glb differ diff --git a/studio/assets/gltf/base_human_female.glb b/studio/assets/gltf/base_human_female.glb new file mode 100644 index 0000000..9263769 Binary files /dev/null and b/studio/assets/gltf/base_human_female.glb differ diff --git a/studio/src/bvh/mod.rs b/studio/src/bvh/mod.rs index 7d14815..1ed962b 100644 --- a/studio/src/bvh/mod.rs +++ b/studio/src/bvh/mod.rs @@ -1,7 +1,7 @@ use std::backtrace::Backtrace; use bevy::{ - asset::AsyncReadExt, + asset::{AsyncReadExt, LoadState}, ecs::{ query::{self, ReadOnlyWorldQuery, WorldQuery}, system::{Command, EntityCommands, SystemParam}, @@ -9,7 +9,7 @@ use bevy::{ gltf::Gltf, prelude::*, render::INSTANCE_INDEX_SHADER_HANDLE, - scene, + scene::{self, InstanceId}, transform::commands, ui::debug::print_ui_layout_tree, utils::hashbrown::HashMap, @@ -17,7 +17,7 @@ use bevy::{ use bevy_inspector_egui::egui::TextBuffer; use bevy_mod_picking::prelude::EntityEvent; use bevy_rapier3d::parry::transformation; -use studio_bvh::{frames::Frame, joint}; +use studio_bvh::{frames::Frame, joint, Bvh as BvhFile}; mod error; mod loader; @@ -35,12 +35,15 @@ impl Plugin for BvhPlugin { fn build(&self, app: &mut App) { app.init_asset::() .register_asset_loader(BvhLoader) + .init_resource::() + .add_systems(PreUpdate, tick_pending_bvh_anims.run_if(in_state(SceneState::Spawning))) + .add_systems(Update, animate_bvh.run_if(in_state(SceneState::Active))) + .register_type::() .register_type::() //Events - .add_event::() - .add_systems(PreUpdate, update_bvh_anim); + ; } } @@ -57,14 +60,20 @@ pub struct BvhAnim { bvh: Handle, should_play: bool, frame: usize, - #[reflect(ignore)] - retarget: Option, + // #[reflect(ignore)] + // retarget: Option, #[reflect(ignore)] timer: Timer, #[reflect(ignore)] last_frame: usize, } +impl BvhAnim { + fn new(handle : Handle, bvh : &BvhFile) -> Self { + BvhAnim { bvh: handle, should_play: true, frame: 0, timer: Timer::from_seconds(bvh.frame_time().as_secs_f32(), TimerMode::Repeating), last_frame:0 } + } +} + pub fn animate_bvh( mut command: Commands, mut bvh_anims: Query<(Entity, &mut BvhAnim, &mut Transform, &mut Children)>, @@ -136,13 +145,13 @@ fn apply_frame( new_pos.z = frame.as_slice()[channel.motion_index()] } studio_bvh::ChannelType::RotationX => { - new_rot.x = frame.as_slice()[channel.motion_index()] + new_rot.x += frame.as_slice()[channel.motion_index()] } studio_bvh::ChannelType::RotationY => { - new_rot.y = frame.as_slice()[channel.motion_index()] + new_rot.y += frame.as_slice()[channel.motion_index()] } studio_bvh::ChannelType::RotationZ => { - new_rot.z = frame.as_slice()[channel.motion_index()] + new_rot.z += frame.as_slice()[channel.motion_index()] } } } @@ -189,100 +198,38 @@ pub struct JointQuery { } //============================================================================== -// Commands Plugin +// Unloaded Scenes //============================================================================== -pub trait CommandsSpawnBvhExt { - fn spawn_bvh(&mut self, asset: &Handle) -> Entity; - - fn spawn_bvh_with_transform(&mut self, asset: &Handle, transform: Transform) -> Entity; - - fn spawn_skined_bvh_with_transform( - &mut self, - asset: Handle, - scene: Handle, - retarget_map: RetargetMap, - transform: Transform, - ) -> Entity; +#[derive(Resource, Default)] +pub struct PendingBVHAnims { + pub items: Vec<(Entity, InstanceId, Handle, RetargetMap)>, } -impl<'w, 's> CommandsSpawnBvhExt for Commands<'w, 's> { - fn spawn_bvh(&mut self, asset: &Handle) -> Entity { - let entity = self.spawn_empty().id(); - self.add(SpawnBvhCommand( - entity, - asset.clone(), - Transform::default(), - None, - )); - entity - } +fn tick_pending_bvh_anims( + mut commands : Commands, + mut pending_bvh_anims: ResMut, + mut next_state : ResMut>, + named_entities : Query<&Name>, + scene_spawner: Res, + asset_server: Res, + bvh_assets: Res>, +) { + let is_done_loading = |bvh_handle : &Handle, instance_id : &InstanceId| -> bool { + asset_server.get_load_state(bvh_handle.id()) == Some(LoadState::Loaded) && scene_spawner.instance_is_ready(instance_id.clone()) + }; + + let mut i = 0; + while i < pending_bvh_anims.items.len() { + let (parent, instance_id, bvh_handle, retarget_map) = pending_bvh_anims.items.get(i).unwrap(); + if is_done_loading(bvh_handle, instance_id) { + println!("Bvh anim is ready!"); - fn spawn_bvh_with_transform(&mut self, asset: &Handle, transform: Transform) -> Entity { - let entity = self.spawn_empty().id(); - self.add(SpawnBvhCommand(entity, asset.clone(), transform, None)); - entity - } + let bvh = bvh_assets.get(bvh_handle.id()).unwrap(); + + for entity in scene_spawner.iter_instance_entities(*instance_id) { - fn spawn_skined_bvh_with_transform( - &mut self, - asset: Handle, - scene: Handle, - retarget_map: RetargetMap, - transform: Transform, - ) -> Entity { - let entity = self.spawn_empty().id(); - - self.add(SpawnBvhCommand( - entity, - asset, - transform, - Some((scene, retarget_map)), - )); - entity - } -} - -pub struct SpawnBvhCommand( - Entity, - Handle, - Transform, - Option<(Handle, RetargetMap)>, -); - -impl Command for SpawnBvhCommand { - //TODO: This loading process with have to be async eventually. - fn apply(self, world: &mut World) { - let bvh = { - let Some(bvh) = world.get_resource::>().unwrap().get(&self.1) else { - panic!( - "Could not create the BVH entity because the bvh file has not been loaded yet" - ) - }; - - bvh.clone() - }; - - let Some(root) = bvh.0.root_joint() else { - panic!("Could not create the BVH entity because the bvh file has no root joint") - }; - - if let Some((scene_handle, retarget_map)) = self.3 { - println!("Starting Scene Spawn"); - let mut scene_spawner = SceneSpawner::from_world(world); - - let id = match scene_spawner.spawn_sync(world, scene_handle.id()) { - Ok(val) => val, - Err(err) => { - println!("There was an Error: {:?}", err); - return; - } - }; - - for entity in scene_spawner.iter_instance_entities(id) { - println!("Bone {:?}", entity); - - let Ok(potential_bone_name) = world.query::<&Name>().get(&world, entity) else { + let Ok(potential_bone_name) = named_entities.get(entity) else { continue; }; let Some(mapped_bone_name) = retarget_map.map.get(potential_bone_name.as_str()) @@ -295,114 +242,198 @@ impl Command for SpawnBvhCommand { println!("Bone Index {}", bone_data.index()); - world.entity_mut(entity).insert(BvhJoint(bone_data.index())); + commands.entity(entity).insert(BvhJoint(bone_data.index())); } + + commands.entity(*parent) + .insert(SpatialBundle::default()) + .insert(BvhAnim::new(bvh_handle.clone(), &bvh.0)); - world.insert_resource(ActiveScene { - instance: id, - source: scene_handle, - }); - - // world.entity_mut(skinned_model).insert(( - // BvhAnim { - // bvh: self.1, - // frame: 0, - // last_frame: 0, - // retarget: Some(retarget_map), - // should_play: true, - // timer: Timer::from_seconds( - // bvh.0.frame_time().as_secs_f32(), - // TimerMode::Repeating, - // ), - // }, - // Name::new("BVH Anim"), - // )); - - // world.send_event(UpdateBVHAnim { - // entity: skinned_model, - // }); + commands.insert_resource(ActiveScene { instance: instance_id.clone() }); + + pending_bvh_anims.items.remove(i); } else { - let entity = world.spawn_empty().id(); - spawn_bvh_recursive(world, &entity, root); - world - .entity_mut(self.0) - .insert(( - BvhAnim { - bvh: self.1, - frame: 0, - last_frame: 0, - should_play: true, - retarget: None, - timer: Timer::from_seconds( - bvh.0.frame_time().as_secs_f32(), - TimerMode::Repeating, - ), - }, - SpatialBundle::from_transform(self.2), - Name::new("BVH Anim"), - )) - .add_child(entity); + i += 1; } } + + if pending_bvh_anims.items.is_empty() { + println!("Moving to Active state."); + next_state.set(SceneState::Active); + } + // for (parent, instance_id, bvh_handle, retarget_map) in pending_bvh_anims.items.iter() { + // if let Some(LoadState::Loaded) = asset_server.get_load_state(bvh_handle) { + // if scene_spawner.instance_is_ready(*instance_idance_id) { + // println!("Bvh anim is ready!"); + + // let bvh = bvh_assets.get(bvh_handle.id()).unwrap(); + // // commands.entity(parent).insert(BvhAnim{ bvh, should_play: todo!(), frame: todo!(), retarget: todo!(), timer: todo!(), last_frame: todo!() }) + + // for entity in scene_spawner.iter_instance_entities(*instance_id) { + + // let Ok(potential_bone_name) = named_entities.get(entity) else { + // continue; + // }; + // let Some(mapped_bone_name) = retarget_map.map.get(potential_bone_name.as_str()) + // else { + // continue; + // }; + // let Some(bone_data) = bvh.0.get_joint_by_name(&mapped_bone_name) else { + // continue; + // }; + + // println!("Bone Index {}", bone_data.index()); + + // commands.entity(entity).insert(BvhJoint(bone_data.index())); + // } + + // commands.entity(*parent) + // .insert(SpatialBundle::default()) + // .insert(BvhAnim::new(bvh_handle.clone(), &bvh.0)); + // } + // } + // } +} + +//============================================================================== +// Commands Plugin +//============================================================================== + +pub trait CommandsSpawnBvhExt { + fn spawn_bvh( + &mut self, + asset: Handle, + scene: Handle, + retarget_map: RetargetMap, + transform: Transform, + ) -> Entity; +} + +impl<'w, 's> CommandsSpawnBvhExt for Commands<'w, 's> { + fn spawn_bvh( + &mut self, + asset: Handle, + scene: Handle, + retarget_map: RetargetMap, + transform: Transform, + ) -> Entity { + let entity = self.spawn_empty().id(); + + self.add(SpawnBvhCommand( + entity, + scene, + asset, + retarget_map, + transform, + )); + entity + } +} + +pub struct SpawnBvhCommand(Entity, Handle, Handle, RetargetMap, Transform); + +impl Command for SpawnBvhCommand { + //TODO: This loading process with have to be async eventually. + fn apply(self, world: &mut World) { + // let bvh = { + // let Some(bvh) = world.get_resource::>().unwrap().get(&self.1) else { + // panic!( + // "Could not create the BVH entity because the bvh file has not been loaded yet" + // ) + // }; + + // bvh.clone() + // }; + + let mut scene_spanwer = world + .get_resource_mut::() + .expect("The scene spawner has not been initialized."); + let scene_id = scene_spanwer.spawn_as_child(self.1, self.0); + + drop(scene_spanwer); + + let mut pending_bvh_scenes = world.get_resource_mut::().expect("Pending bvh Resource has not been initialized."); + pending_bvh_scenes.items.push((self.0, scene_id, self.2, self.3)); + + // let Some(root) = bvh.0.root_joint() else { + // panic!("Could not create the BVH entity because the bvh file has no root joint") + // }; + + // println!("Starting Scene Spawn"); + // let mut scene_spawner = SceneSpawner::from_world(world); + + // let id = match scene_spawner.spawn_sync(world, scene_handle.id()) { + // Ok(val) => val, + // Err(err) => { + // println!("There was an Error: {:?}", err); + // return; + // } + // }; + + // world.insert_resource(ActiveScene { + // instance: id, + // source: scene_handle, + // }); + } } //============================================================================== // Update BVH anim Event Functions //============================================================================== -#[derive(Event)] -pub struct UpdateBVHAnim { - pub entity: Entity, -} +// #[derive(Event)] +// pub struct UpdateBVHAnim { +// pub entity: Entity, +// } -fn update_bvh_anim( - mut commands: Commands, - mut update_events: EventReader, - bvh_anims: Query<(Entity, &BvhAnim, Option<&Children>)>, - skinned_model_nodes: Query<(&Name, Option<&Children>)>, - bvh_assets: Res>, -) { - for event in update_events.read() { - // println!("Updating BVHs"); - // println!("{:?} | {:?}", event.entity, bvh_anims.single().0); - // for anim in bvh_anims.iter() { - // println!("Children {:?}", anim); - // }; +// fn update_bvh_anim( +// mut commands: Commands, +// mut update_events: EventReader, +// bvh_anims: Query<(Entity, &BvhAnim, Option<&Children>)>, +// skinned_model_nodes: Query<(&Name, Option<&Children>)>, +// bvh_assets: Res>, +// ) { +// for event in update_events.read() { +// // println!("Updating BVHs"); +// // println!("{:?} | {:?}", event.entity, bvh_anims.single().0); +// // for anim in bvh_anims.iter() { +// // println!("Children {:?}", anim); +// // }; - if let Ok(bvh_anim) = bvh_anims.get(event.entity) { - let Some(bvh) = bvh_assets.get(bvh_anim.1.bvh.id()) else { - continue; - }; +// if let Ok(bvh_anim) = bvh_anims.get(event.entity) { +// let Some(bvh) = bvh_assets.get(bvh_anim.1.bvh.id()) else { +// continue; +// }; - println!("Children {:?}", bvh_anim.2); +// println!("Children {:?}", bvh_anim.2); - if let Some(children) = bvh_anim.2 { - for child in children { - update_bvh_recursive(child, &mut commands, &bvh, &skinned_model_nodes); - } - } - }; - } -} +// if let Some(children) = bvh_anim.2 { +// for child in children { +// update_bvh_recursive(child, &mut commands, &bvh, &skinned_model_nodes); +// } +// } +// }; +// } +// } -fn update_bvh_recursive( - current_node: &Entity, - commands: &mut Commands, - bvh_anim: &Bvh, - skinned_model_nodes: &Query<(&Name, Option<&Children>)>, -) { - println!("Called Function"); +// fn update_bvh_recursive( +// current_node: &Entity, +// commands: &mut Commands, +// bvh_anim: &Bvh, +// skinned_model_nodes: &Query<(&Name, Option<&Children>)>, +// ) { +// println!("Called Function"); - let Ok((current_name, current_children)) = skinned_model_nodes.get(*current_node) else { - return; - }; +// let Ok((current_name, current_children)) = skinned_model_nodes.get(*current_node) else { +// return; +// }; - if let Some(children) = current_children { - for child in children.iter() { - update_bvh_recursive(child, commands, bvh_anim, skinned_model_nodes); - } - } -} +// if let Some(children) = current_children { +// for child in children.iter() { +// update_bvh_recursive(child, commands, bvh_anim, skinned_model_nodes); +// } +// } +// } //============================================================================== // Utility Functions @@ -471,75 +502,23 @@ pub struct RetargetMap { impl RetargetMap { pub fn mocap_to_rigify() -> RetargetMap { RetargetMap { - // map: [ - // ("hip", "DEF-spine"), - // ("abdomen", "DEF-spine.002"), - // ("chest", "DEF-spine.003"), - // ("neck", "DEF-spine.004"), - // ("neck1", "DEF-spine.005"), - // ("head", "DEF-spine.006"), - // ("rCollar", "DEF-shoulder.R"), - // ("rShldr", "DEF-upper_arm.R"), - // ("rForeArm", "DEF-forearm.R"), - // ("rHand", "DEF-hand.R"), - // ("metacarpal1.r", "DEF-palm.01.R"), - // ("finger2-1.r", "DEF-f_index.01.R"), - // ("finger3-2.r", "DEF-f_middle.02.R"), - // ("finger3-3.r", "DEF-f_middle.03.R"), - // ("metacarpal3.r", "DEF-palm.03.R"), - // ("finger4-1.r", "DEF-f_ring.01.R"), - // ("finger4-2.r", "DEF-f_ring.02.R"), - // ("finger4-3.r", "DEF-f_ring.03.R"), - // ("metacarpal4.r", "DEF-palm.04.R"), - // ("finger5-1.r", "DEF-f_pinky.01.R"), - // ("finger5-2.r", "DEF-f_pinky.02.R"), - // ("finger5-3.r", "DEF-f_pinky.03.R"), - // ("rthumb", "DEF-thumb.01.R"), - // ("finger1-2.r", "DEF-thumb.02.R"), - // ("finger1-3.r", "DEF-thumb.03.R"), - // ("rThigh", "DEF-thumb.03.R"), - // ("rShin", "DEF-shin.R"), - // ("rFoot", "DEF-foot.R"), - // ("lCollar", "DEF-shoulder.L"), - // ("lShldr", "DEF-upper_arm.L"), - // ("lForeArm", "DEF-forearm.L"), - // ("lHand", "DEF-hand.L"), - // ("metacarpal1.l", "DEF-palm.01.L"), - // ("finger2-1.l", "DEF-f_index.01.L"), - // ("finger2-2.l", "DEF-f_index.02.L"), - // ("finger2-3.l", "DEF-f_index.03.L"), - // ("metacarpal2.l", "DEF-palm.02.L"), - // ("finger3-1.l", "DEF-f_middle.01.L"), - // ("finger3-2.l", "DEF-f_middle.02.L"), - // ("finger3-3.l", "DEF-f_middle.03.L"), - // ("metacarpal3.l", "DEF-palm.03.L"), - // ("finger4-1.l", "DEF-f_ring.01.L"), - // ("finger4-2.l", "DEF-f_ring.02.L"), - // ("finger4-3.l", "DEF-f_ring.03.L"), - // ("metacarpal4.l", "DEF-palm.04.L"), - // ("finger5-1.l", "DEF-f_pinky.01.L"), - // ("finger5-2.l", "DEF-f_pinky.02.L"), - // ("finger5-3.l", "DEF-f_pinky.03.L"), - // ("lthumb", "DEF-thumb.01.L"), - // ("finger1-2.l", "DEF-thumb.02.L"), - // ("finger1-3.l", "DEF-thumb.03.L"), - // ("lThigh", "DEF-thigh.L"), - // ("lShin", "DEF-shin.L"), - // ("lFoot", "DEF-foot.L"), - // ] map: [ - ("DEF-spine", "hip"), + ("DEF-spine", "LowerBack"), ("DEF-spine.002", "abdomen"), ("DEF-spine.003", "chest"), - ("DEF-spine.004", "neck"), - ("DEF-spine.005", "neck1"), - ("DEF-spine.006", "head"), - ("DEF-shoulder.R", "rCollar"), - ("DEF-upper_arm.R", "rShldr"), - ("DEF-forearm.R", "rForeArm"), - ("DEF-hand.R", "rHand"), + ("DEF-spine.004", "Neck"), + ("DEF-spine.005", "Neck1"), + ("DEF-spine.006", "Head"), + ("DEF-shoulder.R", "rcollar"), + ("DEF-upper_arm.R", "rshoulder"), + ("DEF-forearm.R", "relbow"), + ("DEF-hand.R", "rhand"), ("DEF-palm.01.R", "metacarpal1.r"), ("DEF-f_index.01.R", "finger2-1.r"), + ("DEF-f_index.02.R", "finger2-2.r"), + ("DEF-f_index.03.R", "finger2-3.r"), + ("DEF-palm.02.R", "metacarpal2.r"), + ("DEF-f_middle.01.R", "finger3-1.r"), ("DEF-f_middle.02.R", "finger3-2.r"), ("DEF-f_middle.03.R", "finger3-3.r"), ("DEF-palm.03.R", "metacarpal3.r"), @@ -553,13 +532,14 @@ impl RetargetMap { ("DEF-thumb.01.R", "rthumb"), ("DEF-thumb.02.R", "finger1-2.r"), ("DEF-thumb.03.R", "finger1-3.r"), - ("DEF-thumb.03.R", "rThigh"), - ("DEF-shin.R", "rShin"), - ("DEF-foot.R", "rFoot"), - ("DEF-shoulder.L", "lCollar"), - ("DEF-upper_arm.L", "lShldr"), - ("DEF-forearm.L", "lForeArm"), - ("DEF-hand.L", "lHand"), + ("DEF-thigh.R", "rhip"), + ("DEF-shin.R", "rknee"), + ("DEF-foot.R", "rfoot"), + ("DEF-toe.R", "RightToeBase"), + ("DEF-shoulder.L", "lcollar"), + ("DEF-upper_arm.L", "lshoulder"), + ("DEF-forearm.L", "lelbow"), + ("DEF-hand.L", "lhand"), ("DEF-palm.01.L", "metacarpal1.l"), ("DEF-f_index.01.L", "finger2-1.l"), ("DEF-f_index.02.L", "finger2-2.l"), @@ -579,9 +559,12 @@ impl RetargetMap { ("DEF-thumb.01.L", "lthumb"), ("DEF-thumb.02.L", "finger1-2.l"), ("DEF-thumb.03.L", "finger1-3.l"), - ("DEF-thigh.L", "lThigh"), - ("DEF-shin.L", "lShin"), - ("DEF-foot.L", "lFoot"), + ("DEF-thigh.L", "lhip"), + ("DEF-shin.L", "lknee"), + ("DEF-foot.L", "lfoot"), + ("DEF-toe.L", "LeftToeBase"), + ("DEF-pelvis.R", "RHipJoint"), + ("DEF-pelvis.L", "LHipJoint"), ] .iter() .map(|v| (v.0.to_string(), v.1.to_string())) diff --git a/studio/src/debug.rs b/studio/src/debug.rs index f340523..86f03f5 100644 --- a/studio/src/debug.rs +++ b/studio/src/debug.rs @@ -2,14 +2,15 @@ use std::fmt; use bevy::{prelude::*, window::PrimaryWindow}; use bevy_inspector_egui::quick::WorldInspectorPlugin; -use bevy_mod_picking::debug::{DebugPickingMode, self}; +use bevy_mod_picking::debug::{self, DebugPickingMode}; use bevy_rapier3d::na::Quaternion; use crate::{ + bvh::BvhJoint, camera_controller::{CameraController, CameraMotionSystem}, input::{Action, InputAction, Lifecycle}, scene::SkeletalJoint, - MainCamera, bvh::BvhJoint, + MainCamera, }; #[derive(Resource, Deref, DerefMut)] @@ -51,8 +52,8 @@ impl Plugin for DebugPlugin { fn debug_bvh_model( mut gizmos: Gizmos, - bvh_joints : Query<(&GlobalTransform, Option<&Children>), With>, - debug_mode : Res, + bvh_joints: Query<(&GlobalTransform, Option<&Children>), With>, + debug_mode: Res, ) { if true { for (transform, children) in bvh_joints.iter() { @@ -60,11 +61,35 @@ fn debug_bvh_model( if let Some(children) = children { for child in children.iter() { - if let Ok((child_transform, _)) = bvh_joints.get(child.clone()) { - gizmos.line(transform.translation(), child_transform.translation(), Color::RED); + if let Ok((child_transform, _)) = bvh_joints.get(child.clone()) { + gizmos.line( + transform.translation(), + child_transform.translation(), + Color::RED, + ); } } } + + let local_x = transform.left() * 0.05; + let local_y = transform.up() * 0.05; + let local_z = transform.forward() * 0.05; + + gizmos.line( + transform.translation(), + transform.translation() + local_x, + Color::RED, + ); + gizmos.line( + transform.translation(), + transform.translation() + local_y, + Color::GREEN, + ); + gizmos.line( + transform.translation(), + transform.translation() + local_z, + Color::BLUE, + ); } } } @@ -145,6 +170,14 @@ fn draw_skeletal_joints( gizmos.sphere(xlation, rotation, joint_radius, joint.0); gizmos.line(xlation, parent_xlation, joint.0); + + let local_x = world_xform.left() * 0.05; + let local_y = world_xform.up() * 0.05; + let local_z = world_xform.forward() * 0.05; + + gizmos.line(xlation, xlation + local_x, Color::RED); + gizmos.line(xlation, xlation + local_y, Color::GREEN); + gizmos.line(xlation, xlation + local_z, Color::BLUE); } else { gizmos.sphere(xlation, rotation, 0.01, joint.0); } diff --git a/studio/src/lib.rs b/studio/src/lib.rs index 7863ccb..bf59804 100644 --- a/studio/src/lib.rs +++ b/studio/src/lib.rs @@ -1,6 +1,6 @@ #![allow(clippy::type_complexity, clippy::too_many_arguments)] -use bevy::prelude::*; +use bevy::{prelude::*, window::close_on_esc}; use bevy_mod_picking::DefaultPickingPlugins; #[cfg(feature = "wasm")] @@ -87,9 +87,10 @@ pub fn init(viewport_size: ViewportSize) { Startup, (move |mut cmd: Commands, mut ew: EventWriter| { cmd.insert_resource(SkyboxId("gum_trees_4k".to_string())); - ew.send(LoadSceneEvent("base-human-female".to_string())); + ew.send(LoadSceneEvent("base_human_female".to_string())); }) ) + .add_systems(Update, close_on_esc) // .add_systems( // Update, // bevy::window::close_on_esc diff --git a/studio/src/scene.rs b/studio/src/scene.rs index 579c384..19b2e04 100644 --- a/studio/src/scene.rs +++ b/studio/src/scene.rs @@ -43,7 +43,7 @@ impl Plugin for ScenePlugin { spawn_test_bvh, // TODO init_scene_loading, tick_scene_loading.run_if(in_state(SceneState::Loading)), - tick_scene_spawning.run_if(in_state(SceneState::Spawning)), + // tick_scene_spawning.run_if(in_state(SceneState::Spawning)), ) .in_set(SceneSpawnerSystem), ) @@ -95,7 +95,7 @@ struct PendingScene(pub Handle); pub struct ActiveScene { #[deref] pub instance: InstanceId, - pub source: Handle, + // pub source: Handle, } #[derive(Event, Deref)] @@ -151,7 +151,7 @@ fn initialize(mut cmd: Commands, r_assets: Res) { )); // TODO - cmd.insert_resource(TestBvh(r_assets.load("mocap/scott.bvh"))); + cmd.insert_resource(TestBvh(r_assets.load("mocap/shuffle.bvh"))); } // TODO @@ -185,16 +185,16 @@ fn init_scene_loading( ) { if let Some(id) = er.read().last() { let name = &**id; - let path = format!("gltf/{name}.gltf#Scene0"); + let path = format!("gltf/{name}.glb#Scene0"); // Avoid trying to re-load this scene if it's already active - if let Some(active_scene_path) = - r_active_scene.and_then(|scene| scene.source.path().cloned()) - { - if active_scene_path == AssetPath::parse(&path) { - return; - } - } + // if let Some(active_scene_path) = + // r_active_scene.and_then(|scene| scene.source.path().cloned()) + // { + // if active_scene_path == AssetPath::parse(&path) { + // return; + // } + // } cmd.insert_resource(PendingScene(assets.load(path))); st_next.set(SceneState::Loading); @@ -230,7 +230,7 @@ fn spawn_next_scene( mut r_scene_spawner: ResMut, ) { println!("Spawning Scene"); - cmd.spawn_skined_bvh_with_transform( + cmd.spawn_bvh( test_bvh.0.clone(), r_pending_scene.0.clone(), RetargetMap::mocap_to_rigify(),