Files
bevy-mocap/examples/simple_example.rs
T
2024-02-08 19:01:18 -05:00

63 lines
2.2 KiB
Rust

#![allow(clippy::type_complexity)]
use bevy::{
pbr::{CascadeShadowConfigBuilder, DirectionalLightShadowMap},
prelude::*,
};
use bevy_facial_mocap::{CSVAnimationLoader, CSVAnimationLoaderSettings};
use bevy_inspector_egui::quick::WorldInspectorPlugin;
fn main() {
App::new()
.insert_resource(DirectionalLightShadowMap { size: 4096 })
.add_plugins(DefaultPlugins)
.add_plugins(WorldInspectorPlugin::new())
.init_asset_loader::<CSVAnimationLoader>()
.add_systems(Startup, setup)
.add_systems(Update, setup_animation)
.run();
}
#[derive(Component)]
struct AnimationRunning(Handle<AnimationClip>);
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(0.7, 0.7, 1.0).looking_at(Vec3::new(0.0, 0.3, 0.0), Vec3::Y),
..default()
});
commands.spawn(DirectionalLightBundle {
directional_light: DirectionalLight {
shadows_enabled: true,
..default()
},
// This is a relatively small scene, so use tighter shadow
// cascade bounds than the default for better quality.
// We also adjusted the shadow map to be larger since we're
// only using a single cascade.
cascade_shadow_config: CascadeShadowConfigBuilder {
num_cascades: 1,
maximum_distance: 1.6,
..default()
}
.into(),
..default()
});
commands.spawn(SceneBundle {
scene: asset_server.load("example.gltf#Scene0"),
..default()
});
}
fn setup_animation(mut commands: Commands, asset_server: Res<AssetServer>, mut players: Query<Entity, (With<MorphWeights>, Without<AnimationRunning>)>) {
for entity in &mut players {
let handle = asset_server.load_with_settings("20240205_shapekey_BevyImplementationFaceCap_5/shapekey_BevyImplementationFaceCap_5_ScottiPhone_raw.morph_anim.csv", |s: &mut CSVAnimationLoaderSettings| { s.0.parts = vec![Name::new("pascal_Head")]; });
let mut player = AnimationPlayer::default();
player.play(handle.clone()).repeat();
commands.entity(entity).insert((AnimationRunning(handle), player));
}
}