mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 15:14:50 +00:00
scene_viewer: Make it possible to disable the animation feature (#4849)
# Objective - The `scene_viewer` example assumes the `animation` feature is enabled, which it is by default. However, animations may have a performance cost that is undesirable when testing performance, for example. Then it is useful to be able to disable the `animation` feature and one would still like the `scene_viewer` example to work. ## Solution - Gate animation code in `scene_viewer` on the `animation` feature being enabled.
This commit is contained in:
parent
575ffa7c0c
commit
1e8ca45aeb
1 changed files with 44 additions and 34 deletions
|
@ -41,8 +41,8 @@ Controls:
|
|||
Enter - Cycle through animations
|
||||
"
|
||||
);
|
||||
App::new()
|
||||
.insert_resource(AmbientLight {
|
||||
let mut app = App::new();
|
||||
app.insert_resource(AmbientLight {
|
||||
color: Color::WHITE,
|
||||
brightness: 1.0 / 5.0f32,
|
||||
})
|
||||
|
@ -60,14 +60,18 @@ Controls:
|
|||
.add_system_to_stage(CoreStage::PreUpdate, camera_spawn_check)
|
||||
.add_system(update_lights)
|
||||
.add_system(camera_controller)
|
||||
.add_system(start_animation)
|
||||
.add_system(keyboard_animation_control)
|
||||
.add_system(keyboard_cameras_control)
|
||||
.run();
|
||||
.add_system(keyboard_cameras_control);
|
||||
|
||||
#[cfg(feature = "animation")]
|
||||
app.add_system(start_animation)
|
||||
.add_system(keyboard_animation_control);
|
||||
|
||||
app.run();
|
||||
}
|
||||
|
||||
struct SceneHandle {
|
||||
handle: Handle<Gltf>,
|
||||
#[cfg(feature = "animation")]
|
||||
animations: Vec<Handle<AnimationClip>>,
|
||||
instance_id: Option<InstanceId>,
|
||||
is_loaded: bool,
|
||||
|
@ -82,6 +86,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
|||
info!("Loading {}", scene_path);
|
||||
commands.insert_resource(SceneHandle {
|
||||
handle: asset_server.load(&scene_path),
|
||||
#[cfg(feature = "animation")]
|
||||
animations: Vec::new(),
|
||||
instance_id: None,
|
||||
is_loaded: false,
|
||||
|
@ -117,6 +122,8 @@ fn scene_load_check(
|
|||
scene_handle.instance_id =
|
||||
Some(scene_spawner.spawn(gltf_scene_handle.clone_weak()));
|
||||
|
||||
#[cfg(feature = "animation")]
|
||||
{
|
||||
scene_handle.animations = gltf.animations.clone();
|
||||
if !scene_handle.animations.is_empty() {
|
||||
info!(
|
||||
|
@ -129,6 +136,7 @@ fn scene_load_check(
|
|||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
info!("Spawning scene...");
|
||||
}
|
||||
|
@ -143,6 +151,7 @@ fn scene_load_check(
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "animation")]
|
||||
fn start_animation(
|
||||
mut player: Query<&mut AnimationPlayer>,
|
||||
mut done: Local<bool>,
|
||||
|
@ -158,6 +167,7 @@ fn start_animation(
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "animation")]
|
||||
fn keyboard_animation_control(
|
||||
keyboard_input: Res<Input<KeyCode>>,
|
||||
mut animation_player: Query<&mut AnimationPlayer>,
|
||||
|
|
Loading…
Reference in a new issue