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,33 +41,37 @@ Controls:
|
||||||
Enter - Cycle through animations
|
Enter - Cycle through animations
|
||||||
"
|
"
|
||||||
);
|
);
|
||||||
App::new()
|
let mut app = App::new();
|
||||||
.insert_resource(AmbientLight {
|
app.insert_resource(AmbientLight {
|
||||||
color: Color::WHITE,
|
color: Color::WHITE,
|
||||||
brightness: 1.0 / 5.0f32,
|
brightness: 1.0 / 5.0f32,
|
||||||
})
|
})
|
||||||
.insert_resource(AssetServerSettings {
|
.insert_resource(AssetServerSettings {
|
||||||
asset_folder: std::env::var("CARGO_MANIFEST_DIR").unwrap_or_else(|_| ".".to_string()),
|
asset_folder: std::env::var("CARGO_MANIFEST_DIR").unwrap_or_else(|_| ".".to_string()),
|
||||||
watch_for_changes: true,
|
watch_for_changes: true,
|
||||||
})
|
})
|
||||||
.insert_resource(WindowDescriptor {
|
.insert_resource(WindowDescriptor {
|
||||||
title: "bevy scene viewer".to_string(),
|
title: "bevy scene viewer".to_string(),
|
||||||
..default()
|
..default()
|
||||||
})
|
})
|
||||||
.add_plugins(DefaultPlugins)
|
.add_plugins(DefaultPlugins)
|
||||||
.add_startup_system(setup)
|
.add_startup_system(setup)
|
||||||
.add_system_to_stage(CoreStage::PreUpdate, scene_load_check)
|
.add_system_to_stage(CoreStage::PreUpdate, scene_load_check)
|
||||||
.add_system_to_stage(CoreStage::PreUpdate, camera_spawn_check)
|
.add_system_to_stage(CoreStage::PreUpdate, camera_spawn_check)
|
||||||
.add_system(update_lights)
|
.add_system(update_lights)
|
||||||
.add_system(camera_controller)
|
.add_system(camera_controller)
|
||||||
.add_system(start_animation)
|
.add_system(keyboard_cameras_control);
|
||||||
.add_system(keyboard_animation_control)
|
|
||||||
.add_system(keyboard_cameras_control)
|
#[cfg(feature = "animation")]
|
||||||
.run();
|
app.add_system(start_animation)
|
||||||
|
.add_system(keyboard_animation_control);
|
||||||
|
|
||||||
|
app.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SceneHandle {
|
struct SceneHandle {
|
||||||
handle: Handle<Gltf>,
|
handle: Handle<Gltf>,
|
||||||
|
#[cfg(feature = "animation")]
|
||||||
animations: Vec<Handle<AnimationClip>>,
|
animations: Vec<Handle<AnimationClip>>,
|
||||||
instance_id: Option<InstanceId>,
|
instance_id: Option<InstanceId>,
|
||||||
is_loaded: bool,
|
is_loaded: bool,
|
||||||
|
@ -82,6 +86,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||||
info!("Loading {}", scene_path);
|
info!("Loading {}", scene_path);
|
||||||
commands.insert_resource(SceneHandle {
|
commands.insert_resource(SceneHandle {
|
||||||
handle: asset_server.load(&scene_path),
|
handle: asset_server.load(&scene_path),
|
||||||
|
#[cfg(feature = "animation")]
|
||||||
animations: Vec::new(),
|
animations: Vec::new(),
|
||||||
instance_id: None,
|
instance_id: None,
|
||||||
is_loaded: false,
|
is_loaded: false,
|
||||||
|
@ -117,17 +122,20 @@ fn scene_load_check(
|
||||||
scene_handle.instance_id =
|
scene_handle.instance_id =
|
||||||
Some(scene_spawner.spawn(gltf_scene_handle.clone_weak()));
|
Some(scene_spawner.spawn(gltf_scene_handle.clone_weak()));
|
||||||
|
|
||||||
scene_handle.animations = gltf.animations.clone();
|
#[cfg(feature = "animation")]
|
||||||
if !scene_handle.animations.is_empty() {
|
{
|
||||||
info!(
|
scene_handle.animations = gltf.animations.clone();
|
||||||
"Found {} animation{}",
|
if !scene_handle.animations.is_empty() {
|
||||||
scene_handle.animations.len(),
|
info!(
|
||||||
if scene_handle.animations.len() == 1 {
|
"Found {} animation{}",
|
||||||
""
|
scene_handle.animations.len(),
|
||||||
} else {
|
if scene_handle.animations.len() == 1 {
|
||||||
"s"
|
""
|
||||||
}
|
} else {
|
||||||
);
|
"s"
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
info!("Spawning scene...");
|
info!("Spawning scene...");
|
||||||
|
@ -143,6 +151,7 @@ fn scene_load_check(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "animation")]
|
||||||
fn start_animation(
|
fn start_animation(
|
||||||
mut player: Query<&mut AnimationPlayer>,
|
mut player: Query<&mut AnimationPlayer>,
|
||||||
mut done: Local<bool>,
|
mut done: Local<bool>,
|
||||||
|
@ -158,6 +167,7 @@ fn start_animation(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "animation")]
|
||||||
fn keyboard_animation_control(
|
fn keyboard_animation_control(
|
||||||
keyboard_input: Res<Input<KeyCode>>,
|
keyboard_input: Res<Input<KeyCode>>,
|
||||||
mut animation_player: Query<&mut AnimationPlayer>,
|
mut animation_player: Query<&mut AnimationPlayer>,
|
||||||
|
|
Loading…
Reference in a new issue