2022-10-12 17:31:02 +00:00
|
|
|
use std::f32::consts::PI;
|
|
|
|
|
|
|
|
use bevy::{prelude::*, window::close_on_esc};
|
2022-11-22 19:11:36 +00:00
|
|
|
use bevy_mod_outline::{
|
|
|
|
AutoGenerateOutlineNormalsPlugin, OutlineBundle, OutlinePlugin, OutlineVolume,
|
|
|
|
};
|
2022-11-22 00:05:47 +00:00
|
|
|
|
|
|
|
#[derive(Resource)]
|
|
|
|
struct Fox(Handle<AnimationClip>);
|
2022-10-12 17:31:02 +00:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
App::new()
|
|
|
|
.add_plugins(DefaultPlugins)
|
|
|
|
.add_plugin(OutlinePlugin)
|
|
|
|
.add_plugin(AutoGenerateOutlineNormalsPlugin)
|
|
|
|
.insert_resource(AmbientLight {
|
|
|
|
color: Color::WHITE,
|
|
|
|
brightness: 1.0,
|
|
|
|
})
|
|
|
|
.add_startup_system(setup)
|
|
|
|
.add_system(setup_scene_once_loaded)
|
|
|
|
.add_system(close_on_esc)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn setup(
|
|
|
|
mut commands: Commands,
|
|
|
|
asset_server: Res<AssetServer>,
|
|
|
|
mut meshes: ResMut<Assets<Mesh>>,
|
|
|
|
mut materials: ResMut<Assets<StandardMaterial>>,
|
|
|
|
) {
|
|
|
|
// Insert a resource with the current animation
|
2022-11-22 00:05:47 +00:00
|
|
|
commands.insert_resource(Fox(asset_server.load("Fox.glb#Animation0")));
|
2022-10-12 17:31:02 +00:00
|
|
|
|
|
|
|
// Camera
|
2022-11-22 00:05:47 +00:00
|
|
|
commands.spawn(Camera3dBundle {
|
2022-10-12 17:31:02 +00:00
|
|
|
transform: Transform::from_xyz(100.0, 100.0, 150.0)
|
|
|
|
.looking_at(Vec3::new(0.0, 20.0, 0.0), Vec3::Y),
|
|
|
|
..default()
|
|
|
|
});
|
|
|
|
|
|
|
|
// Plane
|
2022-11-22 00:05:47 +00:00
|
|
|
commands.spawn(PbrBundle {
|
2022-10-12 17:31:02 +00:00
|
|
|
mesh: meshes.add(Mesh::from(shape::Plane { size: 500000.0 })),
|
|
|
|
material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()),
|
|
|
|
..default()
|
|
|
|
});
|
|
|
|
|
|
|
|
// Light
|
2022-11-22 00:05:47 +00:00
|
|
|
commands.spawn(DirectionalLightBundle {
|
2022-10-12 17:31:02 +00:00
|
|
|
transform: Transform::from_rotation(Quat::from_euler(EulerRot::ZYX, 0.0, 1.0, -PI / 4.)),
|
|
|
|
directional_light: DirectionalLight {
|
|
|
|
shadows_enabled: true,
|
|
|
|
..default()
|
|
|
|
},
|
|
|
|
..default()
|
|
|
|
});
|
|
|
|
|
|
|
|
// Fox
|
2022-11-22 00:05:47 +00:00
|
|
|
commands.spawn(SceneBundle {
|
2022-10-12 17:31:02 +00:00
|
|
|
scene: asset_server.load("Fox.glb#Scene0"),
|
|
|
|
..default()
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Once the scene is loaded, start the animation and add an outline
|
|
|
|
fn setup_scene_once_loaded(
|
|
|
|
mut commands: Commands,
|
2022-11-22 00:05:47 +00:00
|
|
|
animation: Res<Fox>,
|
2022-10-12 17:31:02 +00:00
|
|
|
mut player: Query<&mut AnimationPlayer>,
|
|
|
|
entities: Query<Entity, With<Handle<Mesh>>>,
|
|
|
|
mut done: Local<bool>,
|
|
|
|
) {
|
|
|
|
if !*done {
|
|
|
|
if let Ok(mut player) = player.get_single_mut() {
|
2022-11-22 00:05:47 +00:00
|
|
|
player.play(animation.0.clone_weak()).repeat();
|
2022-10-12 17:31:02 +00:00
|
|
|
for entity in entities.iter() {
|
2022-11-22 00:05:47 +00:00
|
|
|
commands.entity(entity).insert(OutlineBundle {
|
2022-11-22 19:11:36 +00:00
|
|
|
outline: OutlineVolume {
|
2022-10-12 17:31:02 +00:00
|
|
|
visible: true,
|
|
|
|
width: 3.0,
|
|
|
|
colour: Color::RED,
|
|
|
|
},
|
2022-11-18 21:43:15 +00:00
|
|
|
..default()
|
2022-10-12 17:31:02 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
*done = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|