From 5ae478efe13c96eb522e8d34429ec9670fae7d6c Mon Sep 17 00:00:00 2001 From: Robin KAY Date: Tue, 22 Nov 2022 00:05:47 +0000 Subject: [PATCH] Port to Bevy 0.9. --- Cargo.toml | 4 ++-- examples/animated_fox.rs | 24 ++++++++++++------------ examples/pieces.rs | 18 +++++++++--------- examples/shapes.rs | 14 +++++++------- src/pipeline.rs | 1 + src/uniforms.rs | 2 ++ src/view_uniforms.rs | 1 + 7 files changed, 34 insertions(+), 30 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 955df20..601659e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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", ] } diff --git a/examples/animated_fox.rs b/examples/animated_fox.rs index 9d31155..a04117d 100644 --- a/examples/animated_fox.rs +++ b/examples/animated_fox.rs @@ -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); fn main() { App::new() @@ -27,24 +28,24 @@ fn setup( mut materials: ResMut>, ) { // Insert a resource with the current animation - commands.insert_resource::>(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>, + animation: Res, mut player: Query<&mut AnimationPlayer>, entities: Query>>, mut done: Local, ) { 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() }); } diff --git a/examples/pieces.rs b/examples/pieces.rs index aaa48b2..cb87b4a 100644 --- a/examples/pieces.rs +++ b/examples/pieces.rs @@ -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() }); diff --git a/examples/shapes.rs b/examples/shapes.rs index 192c1d8..c77d88f 100644 --- a/examples/shapes.rs +++ b/examples/shapes.rs @@ -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() }); diff --git a/src/pipeline.rs b/src/pipeline.rs index 63c88f9..8fdda8e 100644 --- a/src/pipeline.rs +++ b/src/pipeline.rs @@ -101,6 +101,7 @@ impl PipelineKey { } } +#[derive(Resource)] pub struct OutlinePipeline { mesh_pipeline: MeshPipeline, pub outline_view_bind_group_layout: BindGroupLayout, diff --git a/src/uniforms.rs b/src/uniforms.rs index 6d931cb..84ecd6e 100644 --- a/src/uniforms.rs +++ b/src/uniforms.rs @@ -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, } diff --git a/src/view_uniforms.rs b/src/view_uniforms.rs index 59bce4c..5cf4d32 100644 --- a/src/view_uniforms.rs +++ b/src/view_uniforms.rs @@ -19,6 +19,7 @@ pub struct OutlineViewUniform { scale: Vec2, } +#[derive(Resource)] pub struct OutlineViewBindGroup { bind_group: BindGroup, }