Migrated to bevy 0.10

This commit is contained in:
Bram Buurlage 2023-03-10 20:46:38 +01:00
parent 927910bf63
commit 9184bef570
6 changed files with 33 additions and 29 deletions

View File

@ -8,3 +8,6 @@
# Version 0.2.0 # Version 0.2.0
- Migrated to bevy 0.9 - Migrated to bevy 0.9
- Removed debug_lines feature, to not have a third party bevy dependency. - Removed debug_lines feature, to not have a third party bevy dependency.
# Version 0.3.0
- Migrated to bevy 0.10

View File

@ -1,6 +1,6 @@
[package] [package]
name = "bevy_mod_inverse_kinematics" name = "bevy_mod_inverse_kinematics"
version = "0.2.0" version = "0.3.0"
authors = ["Bram Buurlage <brambuurlage@gmail.com>"] authors = ["Bram Buurlage <brambuurlage@gmail.com>"]
edition = "2021" edition = "2021"
categories = ["game-engines", "graphics", "rendering"] categories = ["game-engines", "graphics", "rendering"]
@ -10,7 +10,7 @@ keywords = ["gamedev", "graphics", "bevy", "animation"]
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"
[dependencies] [dependencies]
bevy = "0.9.0" bevy = "0.10"
#bevy_prototype_debug_lines = { version = "0.9.1", features = ["3d"], optional = true } #bevy_prototype_debug_lines = { version = "0.9.1", features = ["3d"], optional = true }
[features] [features]

View File

@ -12,9 +12,10 @@ A [Bevy](https://github.com/bevyengine/bevy) plugin for inverse kinematics. Supp
I intend to track the latest releases of Bevy. I intend to track the latest releases of Bevy.
| bevy | bevy_mod_inverse_kinematics | | bevy | bevy_mod_inverse_kinematics |
| ----- | --------------------------- | | ------ | --------------------------- |
| 0.8.1 | 0.1 | | 0.8.1 | 0.1 |
| 0.9.0 | 0.2 | | 0.9.0 | 0.2 |
| 0.10.0 | 0.3 |
## Examples ## Examples

View File

@ -1,4 +1,4 @@
use bevy::prelude::*; use bevy::{prelude::*, window::WindowResolution};
use bevy_mod_inverse_kinematics::*; use bevy_mod_inverse_kinematics::*;
#[derive(Component)] #[derive(Component)]
@ -7,11 +7,10 @@ pub struct ManuallyTarget(Vec4);
fn main() { fn main() {
App::new() App::new()
.add_plugins(DefaultPlugins.set(WindowPlugin { .add_plugins(DefaultPlugins.set(WindowPlugin {
window: WindowDescriptor { primary_window: Some(Window {
width: 800.0, resolution: WindowResolution::new(800.0, 600.0),
height: 600.0,
..default() ..default()
}, }),
..default() ..default()
})) }))
.add_plugin(InverseKinematicsPlugin) .add_plugin(InverseKinematicsPlugin)
@ -43,21 +42,11 @@ fn setup(
}); });
}); });
let size = 30.0;
commands.spawn(DirectionalLightBundle { commands.spawn(DirectionalLightBundle {
directional_light: DirectionalLight { directional_light: DirectionalLight {
color: Color::WHITE, color: Color::WHITE,
illuminance: 10000.0, illuminance: 10000.0,
shadows_enabled: true, shadows_enabled: true,
shadow_projection: OrthographicProjection {
left: -size,
right: size,
bottom: -size,
top: size,
near: -size,
far: size,
..default()
},
..default() ..default()
}, },
transform: Transform::from_xyz(-8.0, 8.0, 8.0).looking_at(Vec3::ZERO, Vec3::Y), transform: Transform::from_xyz(-8.0, 8.0, 8.0).looking_at(Vec3::ZERO, Vec3::Y),
@ -65,7 +54,10 @@ fn setup(
}); });
commands.spawn(PbrBundle { commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Plane { size: 5.0 })), mesh: meshes.add(Mesh::from(shape::Plane {
size: 5.0,
subdivisions: 0,
})),
material: materials.add(StandardMaterial { material: materials.add(StandardMaterial {
base_color: Color::WHITE, base_color: Color::WHITE,
..default() ..default()
@ -113,9 +105,10 @@ fn setup_ik(
.spawn(( .spawn((
PbrBundle { PbrBundle {
transform: Transform::from_xyz(0.3, 0.8, 0.2), transform: Transform::from_xyz(0.3, 0.8, 0.2),
mesh: meshes.add(Mesh::from(shape::Icosphere { mesh: meshes.add(Mesh::from(shape::UVSphere {
radius: 0.05, radius: 0.05,
subdivisions: 1, sectors: 7,
stacks: 7,
})), })),
material: materials.add(StandardMaterial { material: materials.add(StandardMaterial {
base_color: Color::RED, base_color: Color::RED,
@ -130,9 +123,10 @@ fn setup_ik(
let pole_target = commands let pole_target = commands
.spawn(PbrBundle { .spawn(PbrBundle {
transform: Transform::from_xyz(-1.0, 0.4, -0.2), transform: Transform::from_xyz(-1.0, 0.4, -0.2),
mesh: meshes.add(Mesh::from(shape::Icosphere { mesh: meshes.add(Mesh::from(shape::UVSphere {
radius: 0.05, radius: 0.05,
subdivisions: 1, sectors: 7,
stacks: 7,
})), })),
material: materials.add(StandardMaterial { material: materials.add(StandardMaterial {
base_color: Color::GREEN, base_color: Color::GREEN,
@ -149,6 +143,7 @@ fn setup_ik(
target, target,
pole_target: Some(pole_target), pole_target: Some(pole_target),
pole_angle: -std::f32::consts::FRAC_PI_2, pole_angle: -std::f32::consts::FRAC_PI_2,
enabled: true,
}); });
} }
} }

View File

@ -24,14 +24,15 @@ pub struct IkConstraint {
/// If a pole target is set, the bone will roll toward the pole target. /// If a pole target is set, the bone will roll toward the pole target.
/// This angle is the offset to apply to the roll. /// This angle is the offset to apply to the roll.
pub pole_angle: f32, pub pole_angle: f32,
/// Whether this constraint is enabled. Disabled constraints will be skipped.
pub enabled: bool,
} }
impl Plugin for InverseKinematicsPlugin { impl Plugin for InverseKinematicsPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.add_system_to_stage( app.add_system(
CoreStage::PostUpdate,
solver::inverse_kinematics_system solver::inverse_kinematics_system
.after(bevy::transform::TransformSystem::TransformPropagate), //.after(bevy::transform::TransformSystem::TransformPropagate),
); );
} }
} }

View File

@ -16,6 +16,10 @@ pub fn inverse_kinematics_system(
mut transforms: Query<(&mut Transform, &mut GlobalTransform)>, mut transforms: Query<(&mut Transform, &mut GlobalTransform)>,
) { ) {
for (entity, constraint) in query.iter() { for (entity, constraint) in query.iter() {
if !constraint.enabled {
continue;
}
if let Err(e) = constraint.solve( if let Err(e) = constraint.solve(
entity, entity,
&parents, &parents,