From 927910bf638ba1114a52f164ae239939ff612360 Mon Sep 17 00:00:00 2001 From: Bram Buurlage Date: Sun, 13 Nov 2022 10:20:21 +0100 Subject: [PATCH] Migrated to bevy 0.9 --- CHANGELOG.MD | 4 ++++ Cargo.toml | 8 +++---- README.MD | 6 +----- examples/skin_mesh.rs | 50 +++++++++++++++++++++++-------------------- src/lib.rs | 2 -- src/solver.rs | 42 +----------------------------------- 6 files changed, 37 insertions(+), 75 deletions(-) diff --git a/CHANGELOG.MD b/CHANGELOG.MD index 902deed..696caa3 100644 --- a/CHANGELOG.MD +++ b/CHANGELOG.MD @@ -4,3 +4,7 @@ # Version 0.1.1 - Fixed build issue when using the debug_lines feature - Fixed transforms giong to NaN when an exact match is found + +# Version 0.2.0 +- Migrated to bevy 0.9 +- Removed debug_lines feature, to not have a third party bevy dependency. diff --git a/Cargo.toml b/Cargo.toml index 446a234..780ac5a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bevy_mod_inverse_kinematics" -version = "0.1.1" +version = "0.2.0" authors = ["Bram Buurlage "] edition = "2021" categories = ["game-engines", "graphics", "rendering"] @@ -10,8 +10,8 @@ keywords = ["gamedev", "graphics", "bevy", "animation"] license = "MIT OR Apache-2.0" [dependencies] -bevy = "0.8.1" -bevy_prototype_debug_lines = { version = "0.8.1", features = ["3d"], optional = true } +bevy = "0.9.0" +#bevy_prototype_debug_lines = { version = "0.9.1", features = ["3d"], optional = true } [features] -debug_lines = ["bevy_prototype_debug_lines"] \ No newline at end of file +#debug_lines = ["bevy_prototype_debug_lines"] \ No newline at end of file diff --git a/README.MD b/README.MD index 6f5b775..aac48d5 100644 --- a/README.MD +++ b/README.MD @@ -14,6 +14,7 @@ I intend to track the latest releases of Bevy. | bevy | bevy_mod_inverse_kinematics | | ----- | --------------------------- | | 0.8.1 | 0.1 | +| 0.9.0 | 0.2 | ## Examples @@ -23,11 +24,6 @@ Have the right arm of a skinned mesh follow the mouse cursor: cargo run --example skin_mesh ``` -Turn on the debug_lines feature to see how the bone rotations are calculated: -```shell -cargo run --example skin_mesh --features debug_lines -``` - ## Licensing This project is dual-licensed under either diff --git a/examples/skin_mesh.rs b/examples/skin_mesh.rs index 790ffc9..12b68e8 100644 --- a/examples/skin_mesh.rs +++ b/examples/skin_mesh.rs @@ -6,12 +6,14 @@ pub struct ManuallyTarget(Vec4); fn main() { App::new() - .insert_resource(WindowDescriptor { - width: 800.0, - height: 600.0, + .add_plugins(DefaultPlugins.set(WindowPlugin { + window: WindowDescriptor { + width: 800.0, + height: 600.0, + ..default() + }, ..default() - }) - .add_plugins(DefaultPlugins) + })) .add_plugin(InverseKinematicsPlugin) .add_startup_system(setup) .add_system(setup_ik) @@ -26,9 +28,9 @@ fn setup( mut materials: ResMut>, ) { commands - .spawn_bundle(SpatialBundle::default()) + .spawn(SpatialBundle::default()) .with_children(|parent| { - parent.spawn_bundle(Camera3dBundle { + parent.spawn(Camera3dBundle { transform: Transform::from_xyz(-0.5, 1.5, 2.5) .looking_at(Vec3::new(0.0, 1.0, 0.0), Vec3::Y), projection: bevy::render::camera::Projection::Perspective(PerspectiveProjection { @@ -42,7 +44,7 @@ fn setup( }); let size = 30.0; - commands.spawn_bundle(DirectionalLightBundle { + commands.spawn(DirectionalLightBundle { directional_light: DirectionalLight { color: Color::WHITE, illuminance: 10000.0, @@ -62,7 +64,7 @@ fn setup( ..default() }); - commands.spawn_bundle(PbrBundle { + commands.spawn(PbrBundle { mesh: meshes.add(Mesh::from(shape::Plane { size: 5.0 })), material: materials.add(StandardMaterial { base_color: Color::WHITE, @@ -71,7 +73,7 @@ fn setup( ..default() }); - commands.spawn_bundle(SceneBundle { + commands.spawn(SceneBundle { scene: assets.load("skin.gltf#Scene0"), transform: Transform::from_xyz(0.0, 0.0, 0.0), ..default() @@ -108,23 +110,25 @@ fn setup_ik( .unwrap(); let target = commands - .spawn_bundle(PbrBundle { - transform: Transform::from_xyz(0.3, 0.8, 0.2), - mesh: meshes.add(Mesh::from(shape::Icosphere { - radius: 0.05, - subdivisions: 1, - })), - material: materials.add(StandardMaterial { - base_color: Color::RED, + .spawn(( + PbrBundle { + transform: Transform::from_xyz(0.3, 0.8, 0.2), + mesh: meshes.add(Mesh::from(shape::Icosphere { + radius: 0.05, + subdivisions: 1, + })), + material: materials.add(StandardMaterial { + base_color: Color::RED, + ..default() + }), ..default() - }), - ..default() - }) - .insert(ManuallyTarget(Vec4::new(0.0, 0.0, 1.0, 0.3))) + }, + ManuallyTarget(Vec4::new(0.0, 0.0, 1.0, 0.3)), + )) .id(); let pole_target = commands - .spawn_bundle(PbrBundle { + .spawn(PbrBundle { transform: Transform::from_xyz(-1.0, 0.4, -0.2), mesh: meshes.add(Mesh::from(shape::Icosphere { radius: 0.05, diff --git a/src/lib.rs b/src/lib.rs index ff079ed..3f0229a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -28,8 +28,6 @@ pub struct IkConstraint { impl Plugin for InverseKinematicsPlugin { fn build(&self, app: &mut App) { - #[cfg(feature = "debug_lines")] - app.add_plugin(bevy_prototype_debug_lines::DebugLinesPlugin::default()); app.add_system_to_stage( CoreStage::PostUpdate, solver::inverse_kinematics_system diff --git a/src/solver.rs b/src/solver.rs index c94e7e7..3939a0a 100644 --- a/src/solver.rs +++ b/src/solver.rs @@ -1,7 +1,5 @@ use bevy::ecs::query::QueryEntityError; use bevy::prelude::*; -#[cfg(feature = "debug_lines")] -use bevy_prototype_debug_lines::{DebugLines, DebugLinesPlugin}; use super::IkConstraint; @@ -16,15 +14,12 @@ pub fn inverse_kinematics_system( query: Query<(Entity, &IkConstraint)>, parents: Query<&Parent>, mut transforms: Query<(&mut Transform, &mut GlobalTransform)>, - #[cfg(feature = "debug_lines")] mut debug_lines: ResMut, ) { for (entity, constraint) in query.iter() { if let Err(e) = constraint.solve( entity, &parents, &mut transforms, - #[cfg(feature = "debug_lines")] - &mut debug_lines, ) { bevy::log::warn!("Failed to solve IK constraint: {e}"); } @@ -37,7 +32,6 @@ impl IkConstraint { entity: Entity, parents: &Query<&Parent>, transforms: &mut Query<(&mut Transform, &mut GlobalTransform)>, - #[cfg(feature = "debug_lines")] debug_lines: &mut DebugLines, ) -> Result<(), QueryEntityError> { if self.chain_length == 0 { return Ok(()); @@ -56,9 +50,6 @@ impl IkConstraint { let start = transforms.get(joints[self.chain_length])?.1.translation(); let pole_target = transforms.get(pole_target)?.1.translation(); - #[cfg(feature = "debug_lines")] - debug_lines.line_colored(start, target, 0.0, Color::WHITE); - let tangent = (target - start).normalize(); let axis = (pole_target - start).cross(tangent); let normal = tangent.cross(axis).normalize(); @@ -80,11 +71,9 @@ impl IkConstraint { target, pole_target.as_ref(), transforms, - #[cfg(feature = "debug_lines")] - debug_lines, )?; - if result.mul_vec3(normal).distance_squared(target) < 0.001 { + if result.transform_point(normal).distance_squared(target) < 0.001 { return Ok(()); } } @@ -98,27 +87,8 @@ impl IkConstraint { target: Vec3, pole_target: Option<&PoleTarget>, transforms: &mut Query<(&mut Transform, &mut GlobalTransform)>, - #[cfg(feature = "debug_lines")] debug_lines: &mut DebugLines, ) -> Result { let (&transform, &global_transform) = transforms.get(chain[0])?; - #[cfg(feature = "debug_lines")] - { - let p = global_transform.translation(); - debug_lines.line_colored(p, global_transform.mul_vec3(Vec3::X * 0.1), 0.0, Color::RED); - debug_lines.line_colored( - p, - global_transform.mul_vec3(Vec3::Y * 0.1), - 0.0, - Color::GREEN, - ); - debug_lines.line_colored( - p, - global_transform.mul_vec3(Vec3::Z * 0.1), - 0.0, - Color::BLUE, - ); - debug_lines.line_colored(p, global_transform.mul_vec3(normal), 0.0, Color::YELLOW); - } if chain.len() == 1 { return Ok(global_transform); @@ -160,8 +130,6 @@ impl IkConstraint { translation, pole_target, transforms, - #[cfg(feature = "debug_lines")] - debug_lines, )?; // apply constraints on the way back from recursing @@ -172,14 +140,6 @@ impl IkConstraint { * rotation; *global_transform = parent_global_transform.mul_transform(*transform); - #[cfg(feature = "debug_lines")] - debug_lines.line_colored( - global_transform.translation(), - global_transform.mul_vec3(normal), - 0.0, - Color::CYAN, - ); - Ok(*global_transform) } }