Port to Bevy 0.9.

This commit is contained in:
Robin KAY 2022-11-22 00:05:47 +00:00
parent 8afc8f9d14
commit 5ae478efe1
7 changed files with 34 additions and 30 deletions

View File

@ -11,7 +11,7 @@ keywords = ["gamedev", "bevy", "outline"]
categories = ["game-engines", "rendering"]
[dependencies]
bevy = { version = "0.8", default-features = false, features = [
bevy = { version = "0.9", default-features = false, features = [
"bevy_asset",
"bevy_render",
"bevy_pbr",
@ -21,7 +21,7 @@ bitfield = "0.14"
thiserror = "1.0"
[dev-dependencies]
bevy = { version = "0.8", default-features = false, features = [
bevy = { version = "0.9", default-features = false, features = [
"bevy_winit",
"x11",
] }

View File

@ -1,9 +1,10 @@
use std::f32::consts::PI;
use bevy::{prelude::*, window::close_on_esc};
use bevy_mod_outline::{
AutoGenerateOutlineNormalsPlugin, Outline, OutlineBundle, OutlinePlugin, OutlineStencil,
};
use bevy_mod_outline::{AutoGenerateOutlineNormalsPlugin, Outline, OutlineBundle, OutlinePlugin};
#[derive(Resource)]
struct Fox(Handle<AnimationClip>);
fn main() {
App::new()
@ -27,24 +28,24 @@ fn setup(
mut materials: ResMut<Assets<StandardMaterial>>,
) {
// Insert a resource with the current animation
commands.insert_resource::<Handle<AnimationClip>>(asset_server.load("Fox.glb#Animation0"));
commands.insert_resource(Fox(asset_server.load("Fox.glb#Animation0")));
// Camera
commands.spawn_bundle(Camera3dBundle {
commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(100.0, 100.0, 150.0)
.looking_at(Vec3::new(0.0, 20.0, 0.0), Vec3::Y),
..default()
});
// Plane
commands.spawn_bundle(PbrBundle {
commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Plane { size: 500000.0 })),
material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()),
..default()
});
// Light
commands.spawn_bundle(DirectionalLightBundle {
commands.spawn(DirectionalLightBundle {
transform: Transform::from_rotation(Quat::from_euler(EulerRot::ZYX, 0.0, 1.0, -PI / 4.)),
directional_light: DirectionalLight {
shadows_enabled: true,
@ -54,7 +55,7 @@ fn setup(
});
// Fox
commands.spawn_bundle(SceneBundle {
commands.spawn(SceneBundle {
scene: asset_server.load("Fox.glb#Scene0"),
..default()
});
@ -63,22 +64,21 @@ fn setup(
// Once the scene is loaded, start the animation and add an outline
fn setup_scene_once_loaded(
mut commands: Commands,
animation: Res<Handle<AnimationClip>>,
animation: Res<Fox>,
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() {
player.play(animation.clone_weak()).repeat();
player.play(animation.0.clone_weak()).repeat();
for entity in entities.iter() {
commands.entity(entity).insert_bundle(OutlineBundle {
commands.entity(entity).insert(OutlineBundle {
outline: Outline {
visible: true,
width: 3.0,
colour: Color::RED,
},
stencil: OutlineStencil,
..default()
});
}

View File

@ -33,7 +33,7 @@ fn setup(
) {
// Add sphere with child meshes sticking out of it
commands
.spawn_bundle(PbrBundle {
.spawn(PbrBundle {
mesh: meshes.add(
UVSphere {
radius: 0.75,
@ -47,7 +47,7 @@ fn setup(
..default()
})
.insert_bundle(OutlineBundle {
.insert(OutlineBundle {
outline: Outline {
visible: true,
colour: Color::WHITE,
@ -59,7 +59,7 @@ fn setup(
.insert(Rotates)
.with_children(|parent| {
parent
.spawn_bundle(PbrBundle {
.spawn(PbrBundle {
mesh: meshes.add(
Capsule {
radius: 0.2,
@ -76,7 +76,7 @@ fn setup(
.with_translation(Vec3::new(0.0, 0.0, 0.75)),
..default()
})
.insert_bundle(OutlineBundle {
.insert(OutlineBundle {
outline: Outline {
visible: true,
colour: Color::WHITE,
@ -87,7 +87,7 @@ fn setup(
})
.insert(InheritOutlineDepth);
parent
.spawn_bundle(PbrBundle {
.spawn(PbrBundle {
mesh: meshes.add(
Torus {
radius: 0.5,
@ -102,7 +102,7 @@ fn setup(
.with_translation(Vec3::new(0.0, 0.0, -0.75)),
..default()
})
.insert_bundle(OutlineBundle {
.insert(OutlineBundle {
outline: Outline {
visible: true,
colour: Color::WHITE,
@ -115,12 +115,12 @@ fn setup(
});
// Add plane, light source, and camera
commands.spawn_bundle(PbrBundle {
commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(bevy::prelude::shape::Plane { size: 5.0 })),
material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()),
..default()
});
commands.spawn_bundle(PointLightBundle {
commands.spawn(PointLightBundle {
point_light: PointLight {
intensity: 1500.0,
shadows_enabled: true,
@ -129,7 +129,7 @@ fn setup(
transform: Transform::from_xyz(4.0, 8.0, 4.0),
..default()
});
commands.spawn_bundle(Camera3dBundle {
commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
..default()
});

View File

@ -39,13 +39,13 @@ fn setup(
let mut cube_mesh = Mesh::from(Cube { size: 1.0 });
cube_mesh.generate_outline_normals().unwrap();
commands
.spawn_bundle(PbrBundle {
.spawn(PbrBundle {
mesh: meshes.add(cube_mesh),
material: materials.add(Color::rgb(0.1, 0.1, 0.9).into()),
transform: Transform::from_xyz(0.0, 1.0, 0.0),
..default()
})
.insert_bundle(OutlineBundle {
.insert(OutlineBundle {
outline: Outline {
visible: true,
colour: Color::rgba(0.0, 1.0, 0.0, 1.0),
@ -57,7 +57,7 @@ fn setup(
// Add torus using the regular surface normals for outlining
commands
.spawn_bundle(PbrBundle {
.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(Torus {
radius: 0.3,
ring_radius: 0.1,
@ -69,7 +69,7 @@ fn setup(
.with_rotation(Quat::from_rotation_x(0.5 * PI)),
..default()
})
.insert_bundle(OutlineBundle {
.insert(OutlineBundle {
outline: Outline {
visible: true,
colour: Color::rgba(1.0, 0.0, 1.0, 0.3),
@ -80,12 +80,12 @@ fn setup(
.insert(Orbits);
// Add plane, light source, and camera
commands.spawn_bundle(PbrBundle {
commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(bevy::prelude::shape::Plane { size: 5.0 })),
material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()),
..default()
});
commands.spawn_bundle(PointLightBundle {
commands.spawn(PointLightBundle {
point_light: PointLight {
intensity: 1500.0,
shadows_enabled: true,
@ -94,7 +94,7 @@ fn setup(
transform: Transform::from_xyz(4.0, 8.0, 4.0),
..default()
});
commands.spawn_bundle(Camera3dBundle {
commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
..default()
});

View File

@ -101,6 +101,7 @@ impl PipelineKey {
}
}
#[derive(Resource)]
pub struct OutlinePipeline {
mesh_pipeline: MeshPipeline,
pub outline_view_bind_group_layout: BindGroupLayout,

View File

@ -35,10 +35,12 @@ pub struct OutlineFragmentUniform {
pub colour: Vec4,
}
#[derive(Resource)]
pub struct OutlineStencilBindGroup {
pub bind_group: BindGroup,
}
#[derive(Resource)]
pub struct OutlineVolumeBindGroup {
pub bind_group: BindGroup,
}

View File

@ -19,6 +19,7 @@ pub struct OutlineViewUniform {
scale: Vec2,
}
#[derive(Resource)]
pub struct OutlineViewBindGroup {
bind_group: BindGroup,
}