From 0892be8d1c872eb400f6130ffdb1e477958c124c Mon Sep 17 00:00:00 2001 From: Elabajaba Date: Sat, 14 Dec 2024 17:56:49 -0500 Subject: [PATCH 1/2] bevy 0.15 --- demo/Cargo.toml | 4 +- demo/src/blend.rs | 2 +- demo/src/main.rs | 133 +++++++++++++++------------------------- demo/src/playback.rs | 2 +- demo/src/two_bone_ik.rs | 2 +- 5 files changed, 56 insertions(+), 87 deletions(-) diff --git a/demo/Cargo.toml b/demo/Cargo.toml index 0346efc..fd99cf6 100644 --- a/demo/Cargo.toml +++ b/demo/Cargo.toml @@ -6,6 +6,6 @@ edition = "2021" resolver = "2" [dependencies] -bevy = "0.14" +bevy = "0.15" ozz-animation-rs = { path = "../" } -reqwest = "0.11" +reqwest = "0.12" diff --git a/demo/src/blend.rs b/demo/src/blend.rs index bc51a5b..ade75c5 100644 --- a/demo/src/blend.rs +++ b/demo/src/blend.rs @@ -122,7 +122,7 @@ impl OzzExample for OzzBlend { fn update(&mut self, time: Time) { let duration = self.sample_job1.animation().unwrap().duration(); - let scaled_time = time.elapsed_seconds() * 0.5; + let scaled_time = time.elapsed_secs() * 0.5; let ratio = (scaled_time % duration) / duration; self.sample_job1.set_ratio(ratio); diff --git a/demo/src/main.rs b/demo/src/main.rs index 555e4a7..4890752 100644 --- a/demo/src/main.rs +++ b/demo/src/main.rs @@ -20,12 +20,8 @@ const BONE_COUNT: usize = 256; fn main() { App::new() .add_plugins(DefaultPlugins) - .add_systems(Startup, setup) - .add_systems(Startup, setup_ui) - .add_systems(Update, update_ozz_animation) - .add_systems(Update, update_camera) - .add_systems(Update, update_bones) - .add_systems(Update, draw_spines) + .add_systems(Startup, (setup, setup_ui)) + .add_systems(Update, (update_ozz_animation, update_camera, update_bones, draw_spines)) .run(); } @@ -85,81 +81,73 @@ fn setup(mut commands: Commands, mut meshes: ResMut>, mut materials commands.spawn(oc); // ground - commands.spawn(PbrBundle { - mesh: meshes.add(Rectangle::new(20.0, 30.0)), - material: materials.add(Color::srgb(1.0, 0.96, 0.95)), - transform: Transform::from_rotation(Quat::from_rotation_x(-std::f32::consts::FRAC_PI_2)) + commands.spawn(( + Mesh3d(meshes.add(Rectangle::new(20.0, 30.0))), + MeshMaterial3d(materials.add(Color::srgb(1.0, 0.96, 0.95))), + Transform::from_rotation(Quat::from_rotation_x(-std::f32::consts::FRAC_PI_2)) .with_translation(Vec3::new(-2.0, 0.0, -5.0)), - ..default() - }); + )); // bones let bone_mesh = meshes.add(build_bone_mesh()); let bone_material = materials.add(Color::srgb(0.68, 0.68, 0.8)); for i in 0..BONE_COUNT { commands.spawn(( - PbrBundle { - mesh: bone_mesh.clone(), - material: bone_material.clone(), - transform: Transform::from_xyz(0.0, 0.0, 0.0), - visibility: Visibility::Hidden, - ..default() - }, + Mesh3d(bone_mesh.clone()), + MeshMaterial3d(bone_material.clone()), + Transform::from_xyz(0.0, 0.0, 0.0), + Visibility::Hidden, BoneIndex(i), )); } // camera - commands.spawn(Camera3dBundle { - transform: Transform::from_xyz(1.5, 1.0, 3.0).looking_at(Vec3::new(0.0, 1.0, -0.0), Vec3::Y), - ..default() - }); + commands.spawn(( + Camera3d::default(), + Transform::from_xyz(1.5, 1.0, 3.0).looking_at(Vec3::new(0.0, 1.0, -0.0), Vec3::Y), + )); // Sky commands.spawn(( - PbrBundle { - mesh: meshes.add(Cuboid::new(2.0, 1.0, 1.0)), - material: materials.add(StandardMaterial { - base_color: Color::srgb(0.4, 0.61, 0.98), - unlit: true, - cull_mode: None, - ..default() - }), - transform: Transform::from_scale(Vec3::splat(30.0)), + Mesh3d(meshes.add(Cuboid::new(2.0, 1.0, 1.0))), + MeshMaterial3d(materials.add(StandardMaterial { + base_color: Color::srgb(0.4, 0.61, 0.98), + unlit: true, + cull_mode: None, ..default() - }, + })), + Transform::from_scale(Vec3::splat(30.0)), NotShadowCaster, )); // Sun - commands.spawn(DirectionalLightBundle { - directional_light: DirectionalLight { + commands.spawn(( + DirectionalLight { color: Color::WHITE, illuminance: 10000.0, shadows_enabled: true, shadow_depth_bias: 0.05, shadow_normal_bias: 0.9, }, - transform: Transform::from_xyz(-3.0, 1.6, -4.0).looking_at(Vec3::new(0.0, 0.0, 0.0), Vec3::Y), - ..default() - }); + Transform::from_xyz(-3.0, 1.6, -4.0).looking_at(Vec3::new(0.0, 0.0, 0.0), Vec3::Y), + )); // light - commands.spawn(PointLightBundle { - point_light: PointLight { + commands.spawn(( + PointLight { shadows_enabled: false, color: Color::WHITE, ..default() }, - transform: Transform::from_xyz(0.0, 5.0, 3.0), - ..default() - }); + Transform::from_xyz(0.0, 5.0, 3.0), + )); } fn update_ozz_animation( keycode: Res>, mut oc_query: Query<&mut OzzComponent>, - mut text_query: Query<&mut Text, With>, + text_query: Query>, + mut writer: TextUiWriter, time: Res