diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 5eb444c..2519bcb 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -2,7 +2,7 @@ name: Checks on: push: - branches: ["main"] + branches: [ "main" ] pull_request: env: @@ -35,5 +35,7 @@ jobs: run: sudo apt-get install libasound2-dev libudev-dev pkg-config - name: Lint run: cargo clippy -- -Dwarnings + - name: Build (examples) + run: cargo build --examples - name: Check format run: cargo fmt --all -- --check diff --git a/Cargo.toml b/Cargo.toml index 4950132..4228de4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,7 @@ version = "3.2.1" edition = "2021" license = "MIT OR Apache-2.0" readme = "README.md" -keywords = ["bevy", "gamedev", "healthbar", "billboard" ] +keywords = ["bevy", "gamedev", "healthbar", "billboard"] categories = ["game-development", "rendering"] repository = "https://github.com/sparten11740/bevy_health_bar3d.git" homepage = "https://github.com/sparten11740/bevy_health_bar3d" @@ -13,10 +13,10 @@ authors = ["Jan Wendland"] include = ["/src", "CHANGELOG.md", "/assets", "LICENSE-APACHE", "LICENSE-MIT"] [dependencies] -bevy = { version = "0.13.1", default-features = false, features = ["bevy_pbr", "bevy_render"] } +bevy = { version = "0.14.0", default-features = false, features = ["bevy_pbr", "bevy_render"] } ordered-float = "3.9.2" [dev-dependencies] -bevy = "0.13.1" -bevy-inspector-egui = "0.23.4" -bevy_tweening = "0.10.0" +bevy = "0.14.0" +bevy-inspector-egui = "0.25.0" +bevy_tweening = { git = "https://github.com/BraymatterOrg/bevy_tweening_0_14", rev = "1e46e67938ef21cfd3b80a9bd7f9e3de1edd425c" } diff --git a/README.md b/README.md index 9a1c4cf..e811396 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,8 @@ or layered cameras out of the box. | Bevy Version | Crate Version | |--------------|--------------:| -| `0.13` | >= `3.2.0` | +| `0.14` | >= `3.3.0` | +| `0.13` | `3.2.0` | | `0.12` | `2.0.0` | | `0.11` | `1.2.0` | | `0.10` | `1.1.0` | diff --git a/assets/shaders/bar.wgsl b/assets/shaders/bar.wgsl index 80f3fd7..a7ffeb8 100644 --- a/assets/shaders/bar.wgsl +++ b/assets/shaders/bar.wgsl @@ -1,6 +1,6 @@ #import bevy_pbr::{ mesh_view_bindings::view, - mesh_functions::get_model_matrix + mesh_functions::get_world_from_local } @group(2) @binding(0) @@ -35,12 +35,12 @@ struct VertexOutput { fn vertex(vertex: Vertex) -> VertexOutput { var out: VertexOutput; - let view_proj = view.view_proj; - let camera_right = normalize(vec3(view_proj.x.x, view_proj.y.x, view_proj.z.x)); - let camera_up = normalize(vec3(view_proj.x.y, view_proj.y.y, view_proj.z.y)); + let clip_from_world = view.clip_from_world; + let camera_right = normalize(vec3(clip_from_world.x.x, clip_from_world.y.x, clip_from_world.z.x)); + let camera_up = normalize(vec3(clip_from_world.x.y, clip_from_world.y.y, clip_from_world.z.y)); let world_space = camera_right * (vertex.position.x + offset.x) + camera_up * (vertex.position.y + offset.y); - let position = view.view_proj * get_model_matrix(vertex.instance_index) * vec4(world_space, 1.); + let position = view.clip_from_world * get_world_from_local(vertex.instance_index) * vec4(world_space, 1.); out.uv = vertex.uv; out.clip_position = position; diff --git a/examples/border.rs b/examples/border.rs index 0641543..c386f94 100644 --- a/examples/border.rs +++ b/examples/border.rs @@ -1,3 +1,4 @@ +use bevy::color::palettes::css::PURPLE; use bevy::prelude::*; use bevy_inspector_egui::quick::WorldInspectorPlugin; @@ -36,7 +37,7 @@ fn setup( // Ground commands.spawn(PbrBundle { mesh: meshes.add(Plane3d::default().mesh().size(5.0, 5.0)), - material: materials.add(Color::rgb(0.3, 0.5, 0.3)), + material: materials.add(Color::srgba(0.3, 0.5, 0.3, 1.)), ..Default::default() }); @@ -52,7 +53,7 @@ fn setup( commands.spawn(( PbrBundle { mesh: meshes.add(Sphere { radius }), - material: materials.add(Color::rgb(1., 0.2, 0.2)), + material: materials.add(Color::srgba(1., 0.2, 0.2, 1.)), transform: Transform::from_xyz(2. * radius, 0.4 + i as f32 / 2., 0.0), ..Default::default() }, @@ -65,7 +66,7 @@ fn setup( width: bar_width, height: BarHeight::Static(bar_height), // here is where the border is defined - border: BarBorder::new(bar_height / 4.).color(Color::PURPLE), + border: BarBorder::new(bar_height / 4.).color(PURPLE.into()), ..default() }, )); diff --git a/examples/custom_background.rs b/examples/custom_background.rs index 91eae3a..1a89c14 100644 --- a/examples/custom_background.rs +++ b/examples/custom_background.rs @@ -1,3 +1,4 @@ +use bevy::color::palettes::basic::RED; use bevy::prelude::*; use bevy_inspector_egui::quick::WorldInspectorPlugin; @@ -23,7 +24,7 @@ fn main() { WorldInspectorPlugin::new(), HealthBarPlugin::::default(), )) - .insert_resource(ColorScheme::::new().background_color(Color::RED)) + .insert_resource(ColorScheme::::new().background_color(RED.into())) .add_systems(Startup, setup) .insert_resource(Msaa::Sample4) .run(); @@ -36,7 +37,7 @@ fn setup( ) { commands.spawn(PbrBundle { mesh: meshes.add(Plane3d::default().mesh().size(5.0, 5.0)), - material: materials.add(Color::rgb(0.3, 0.5, 0.3)), + material: materials.add(Color::srgba(0.3, 0.5, 0.3, 1.)), ..Default::default() }); @@ -45,7 +46,7 @@ fn setup( commands.spawn(( PbrBundle { mesh: meshes.add(Sphere { radius }), - material: materials.add(Color::rgb(1., 0.2, 0.2)), + material: materials.add(Color::srgba(1., 0.2, 0.2, 1.)), transform: Transform::from_xyz(0.0, 1., 0.0), ..Default::default() }, diff --git a/examples/custom_foreground.rs b/examples/custom_foreground.rs index 5a38dff..478d84d 100644 --- a/examples/custom_foreground.rs +++ b/examples/custom_foreground.rs @@ -1,3 +1,5 @@ +use bevy::color::palettes::basic::*; +use bevy::color::palettes::css::*; use bevy::prelude::*; use bevy_inspector_egui::quick::WorldInspectorPlugin; @@ -37,13 +39,13 @@ fn main() { HealthBarPlugin::::default(), )) .insert_resource( - ColorScheme::::new().foreground_color(ForegroundColor::Static(Color::BLUE)), + ColorScheme::::new().foreground_color(ForegroundColor::Static(BLUE.into())), ) .insert_resource(ColorScheme::::new().foreground_color( ForegroundColor::TriSpectrum { - high: Color::LIME_GREEN, - moderate: Color::ORANGE_RED, - low: Color::PURPLE, + high: LIMEGREEN.into(), + moderate: ORANGE_RED.into(), + low: PURPLE.into(), }, )) .add_systems(Startup, setup) @@ -63,7 +65,7 @@ fn setup( commands.spawn(( PbrBundle { mesh: meshes.add(Sphere { radius }), - material: materials.add(Color::rgb(1., 0.2, 0.2)), + material: materials.add(Color::srgba(1., 0.2, 0.2, 1.)), transform: Transform::from_xyz(-2. * radius, 0.4 + i as f32 / 2., 0.0), ..Default::default() }, @@ -81,7 +83,7 @@ fn setup( commands.spawn(( PbrBundle { mesh: meshes.add(Sphere { radius }), - material: materials.add(Color::rgb(1., 0.2, 0.2)), + material: materials.add(Color::srgba(1., 0.2, 0.2, 1.)), transform: Transform::from_xyz(2. * radius, 0.4 + i as f32 / 2., 0.0), ..Default::default() }, diff --git a/examples/default.rs b/examples/default.rs index 56eaddc..044e3bc 100644 --- a/examples/default.rs +++ b/examples/default.rs @@ -37,7 +37,7 @@ fn setup( ) { commands.spawn(PbrBundle { mesh: meshes.add(Plane3d::default().mesh().size(5.0, 5.0)), - material: materials.add(Color::rgb(0.3, 0.5, 0.3)), + material: materials.add(Color::srgba(0.3, 0.5, 0.3, 1.)), ..Default::default() }); @@ -46,7 +46,7 @@ fn setup( commands.spawn(( PbrBundle { mesh: meshes.add(Sphere { radius }), - material: materials.add(Color::rgb(1., 0.2, 0.2)), + material: materials.add(Color::srgba(1., 0.2, 0.2, 1.)), transform: Transform::from_xyz(0.0, 1., 0.0), ..Default::default() }, @@ -64,7 +64,7 @@ fn setup( commands.spawn(( PbrBundle { mesh: meshes.add(Sphere { radius }), - material: materials.add(Color::rgb(1., 0.2, 0.2)), + material: materials.add(Color::srgba(1., 0.2, 0.2, 1.)), transform: Transform::from_xyz(0.0 + 3. * radius, 0.5, 0.0), ..Default::default() }, diff --git a/examples/dinosaurs.rs b/examples/dinosaurs.rs index 444a609..5c83854 100644 --- a/examples/dinosaurs.rs +++ b/examples/dinosaurs.rs @@ -1,12 +1,13 @@ //! Example with multiple tracked components, moving meshes, changing component values, and a moving camera. -use std::f32::consts::PI; -use std::time::Duration; - +use bevy::animation::RepeatAnimation; +use bevy::color::palettes::css::*; use bevy::pbr::*; use bevy::prelude::*; use bevy_tweening::lens::{TransformPositionLens, TransformRotationLens}; use bevy_tweening::{Animator, EaseFunction, Tracks, Tween, TweeningPlugin}; +use std::f32::consts::PI; +use std::time::Duration; use bevy_health_bar3d::prelude::{ BarHeight, BarSettings, ColorScheme, ForegroundColor, HealthBarPlugin, Percentage, @@ -56,60 +57,47 @@ fn main() { TweeningPlugin, )) .insert_resource( - ColorScheme::::new().foreground_color(ForegroundColor::Static(Color::BISQUE)), + ColorScheme::::new().foreground_color(ForegroundColor::Static(BISQUE.into())), ) .insert_resource( ColorScheme::::new() - .foreground_color(ForegroundColor::Static(Color::GREEN)) - .background_color(Color::RED), + .foreground_color(ForegroundColor::Static(GREEN.into())) + .background_color(RED.into()), ) .insert_resource(Msaa::Sample4) - .add_systems(Startup, setup) + .add_systems(Startup, (setup, setup_animations)) .add_systems( Update, - ( - move_camera, - link_animations, - setup_idle_animation, - setup_walking_animation, - move_trex, - kill_trex, - ), + (start_animations, move_camera, move_trex, kill_trex), ) .run(); } #[derive(Resource)] struct Animations { - walk: Handle, - idle: Handle, - die: Handle, + animations: Vec, + graph: Handle, } const TREX_GLTF: &str = "../examples/assets/models/trex.gltf"; +fn gltf_path(id: &str) -> String { + format!("{TREX_GLTF}#{id}") +} + fn setup( mut commands: Commands, mut meshes: ResMut>, mut materials: ResMut>, asset_server: Res, ) { - let gltf_path = |id: &str| format!("{TREX_GLTF}#{id}"); - // Ground commands.spawn(PbrBundle { mesh: meshes.add(Plane3d::default().mesh().size(1000.0, 1000.0)), - material: materials.add(Color::rgb(0.3, 0.5, 0.3)), + material: materials.add(Color::srgba(0.3, 0.5, 0.3, 1.)), ..Default::default() }); - // Animations - commands.insert_resource(Animations { - walk: asset_server.load(gltf_path("Animation5")), - idle: asset_server.load(gltf_path("Animation2")), - die: asset_server.load(gltf_path("Animation1")), - }); - let scene = asset_server.load(gltf_path("Scene0")); // T-Rex 1 @@ -174,7 +162,7 @@ fn setup( ..Default::default() }, FogSettings { - color: Color::rgba(1., 1., 1., 1.), + color: Color::srgba(1., 1., 1., 1.), falloff: FogFalloff::Linear { start: 200., end: 400., @@ -184,40 +172,41 @@ fn setup( )); } -fn setup_walking_animation( - animations: Res, - dinos: Query<&WithAnimationPlayer, (With, Added)>, - mut players: Query<&mut AnimationPlayer>, +fn setup_animations( + asset_server: Res, + mut commands: Commands, + mut graphs: ResMut>, ) { - for &WithAnimationPlayer(entity) in dinos.iter() { - players - .get_mut(entity) - .unwrap() - .play(animations.walk.clone()) - .repeat(); - } -} + let walk_animation = asset_server.load(gltf_path("Animation5")); + let idle_animation = asset_server.load(gltf_path("Animation2")); + let die_animation = asset_server.load(gltf_path("Animation1")); + + let mut graph = AnimationGraph::new(); + let animations = graph + .add_clips( + [ + idle_animation.clone(), + walk_animation.clone(), + die_animation.clone(), + ], + 1.0, + graph.root, + ) + .collect(); -fn setup_idle_animation( - animations: Res, - dinos: Query<&WithAnimationPlayer, (Without, Added)>, - mut players: Query<&mut AnimationPlayer>, -) { - for &WithAnimationPlayer(entity) in dinos.iter() { - players - .get_mut(entity) - .unwrap() - .play(animations.idle.clone()) - .repeat(); - } + let graph = graphs.add(graph); + commands.insert_resource(Animations { + animations, + graph: graph.clone(), + }); } fn kill_trex( animations: Res, + time: Res