Files
bevy-mocap/examples/simple_example.rs
T
2024-02-12 12:23:59 -05:00

71 lines
2.0 KiB
Rust

#![allow(clippy::type_complexity)]
use bevy::{
pbr::{CascadeShadowConfigBuilder, DirectionalLightShadowMap},
prelude::*,
};
use bevy_facial_mocap::CSVAnimationLoader;
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(
"fake_test.morph_anim.json"
);
let mut player = AnimationPlayer::default();
player.play(handle.clone()).repeat();
commands
.entity(entity)
.insert((AnimationRunning(handle), player));
}
}