Skip to content

Commit

Permalink
Bevy 0.11 (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
ManevilleF authored Jul 13, 2023
1 parent 8ed71ce commit 37a7b89
Show file tree
Hide file tree
Showing 11 changed files with 102 additions and 75 deletions.
25 changes: 19 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,37 @@ rapier_collisions = ["bevy_rapier3d"]
thiserror = "1.0"

[dependencies.bevy]
version = "0.10"
version = "0.11"
default-features = false
features = ["bevy_render", "bevy_asset"]

[dependencies.bevy_rapier3d]
version = "0.21"
version = "0.22"
optional = true
default-features = false
features = ["dim3", "async-collider"]

[dev-dependencies]
bevy-inspector-egui = "0.18"
bevy_rapier3d = "0.21"
bevy-inspector-egui = "0.19"
bevy_rapier3d = "0.22"
rand = "0.8"

[dev-dependencies.bevy]
version = "0.10"
features = ["bevy_render", "bevy_pbr", "bevy_core_pipeline", "bevy_asset", "bevy_winit", "x11", "png"]
version = "0.11"
features = [
"bevy_asset",
"bevy_winit",
"bevy_core_pipeline",
"bevy_pbr",
"bevy_render",
"bevy_sprite",
"png",
"x11",
# The following features are required because of https://github.com/bevyengine/bevy/discussions/9100
"ktx2",
"zstd",
"tonemapping_luts",
]
default-features = false

[[example]]
Expand Down
11 changes: 5 additions & 6 deletions examples/anchors_example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ fn main() {
brightness: 1.0,
})
.add_plugins(DefaultPlugins)
.add_plugin(ResourceInspectorPlugin::<ClothConfig>::new())
.add_plugin(WorldInspectorPlugin::default())
.add_plugin(camera_plugin::CameraPlugin)
.add_plugin(ClothPlugin)
.add_startup_system(spawn_cloth)
.add_startup_system(setup)
.add_plugins(ResourceInspectorPlugin::<ClothConfig>::new())
.add_plugins(WorldInspectorPlugin::default())
.add_plugins(camera_plugin::CameraPlugin)
.add_plugins(ClothPlugin)
.add_systems(Startup, (spawn_cloth, setup))
.run();
}

Expand Down
11 changes: 5 additions & 6 deletions examples/balloon_example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,15 @@ fn main() {
brightness: 1.0,
})
.add_plugins(DefaultPlugins)
.add_plugin(WorldInspectorPlugin::default())
.add_plugin(ResourceInspectorPlugin::<ClothConfig>::new())
.add_plugin(camera_plugin::CameraPlugin)
.add_plugin(ClothPlugin)
.add_plugins(WorldInspectorPlugin::default())
.add_plugins(ResourceInspectorPlugin::<ClothConfig>::new())
.add_plugins(camera_plugin::CameraPlugin)
.add_plugins(ClothPlugin)
.insert_resource(ClothConfig {
friction: 0.1,
..Default::default()
})
.add_startup_system(spawn_cloth)
.add_startup_system(setup)
.add_systems(Startup, (spawn_cloth, setup))
.run();
}

Expand Down
3 changes: 2 additions & 1 deletion examples/camera_plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ pub struct CameraController;

impl Plugin for CameraPlugin {
fn build(&self, app: &mut App) {
app.add_startup_system(setup).add_system(handle_camera);
app.add_systems(Startup, setup)
.add_systems(PostUpdate, handle_camera);
log::info!("Camera Plugin loaded");
}
}
Expand Down
13 changes: 6 additions & 7 deletions examples/flag_example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ fn main() {
brightness: 1.0,
})
.add_plugins(DefaultPlugins)
.add_plugin(WorldInspectorPlugin::default())
.add_plugin(ResourceInspectorPlugin::<Winds>::new())
.add_plugin(ResourceInspectorPlugin::<ClothConfig>::new())
.add_plugin(camera_plugin::CameraPlugin)
.add_plugins(WorldInspectorPlugin::default())
.add_plugins(ResourceInspectorPlugin::<Winds>::new())
.add_plugins(ResourceInspectorPlugin::<ClothConfig>::new())
.add_plugins(camera_plugin::CameraPlugin)
.insert_resource(Winds::from(vec![
Wind::SinWave {
max_velocity: Vec3::new(20.0, 15.0, 0.0),
Expand All @@ -29,9 +29,8 @@ fn main() {
abs: false,
},
]))
.add_plugin(ClothPlugin)
.add_startup_system(spawn_cloth)
.add_startup_system(setup)
.add_plugins(ClothPlugin)
.add_systems(Startup, (spawn_cloth, setup))
.run();
}

Expand Down
15 changes: 7 additions & 8 deletions examples/moving_example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,13 @@ fn main() {
brightness: 1.0,
})
.add_plugins(DefaultPlugins)
.add_plugin(WorldInspectorPlugin::default())
.add_plugin(ResourceInspectorPlugin::<ClothConfig>::new())
.add_plugin(ResourceInspectorPlugin::<MovingAnimation>::new())
.add_plugin(camera_plugin::CameraPlugin)
.add_plugin(ClothPlugin)
.add_startup_system(spawn_cloth)
.add_startup_system(setup)
.add_system(animate_cube)
.add_plugins(WorldInspectorPlugin::default())
.add_plugins(ResourceInspectorPlugin::<ClothConfig>::new())
.add_plugins(ResourceInspectorPlugin::<MovingAnimation>::new())
.add_plugins(camera_plugin::CameraPlugin)
.add_plugins(ClothPlugin)
.add_systems(Startup, (spawn_cloth, setup))
.add_systems(Update, animate_cube)
.run();
}

Expand Down
22 changes: 13 additions & 9 deletions examples/rapier_collision_example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,20 @@ fn main() {
brightness: 1.0,
})
.add_plugins(DefaultPlugins)
.add_plugin(RapierPhysicsPlugin::<NoUserData>::default())
.add_plugin(ResourceInspectorPlugin::<ClothConfig>::new())
.add_plugin(WorldInspectorPlugin::default())
.add_plugin(ClothPlugin)
.add_plugin(camera_plugin::CameraPlugin)
.add_plugins(RapierPhysicsPlugin::<NoUserData>::default())
.add_plugins(ResourceInspectorPlugin::<ClothConfig>::new())
.add_plugins(WorldInspectorPlugin::default())
.add_plugins(ClothPlugin)
.add_plugins(camera_plugin::CameraPlugin)
.insert_resource(ClothMovement { sign: -1.0, t: 0.0 })
.add_startup_system(spawn_cloth)
.add_startup_system(setup)
.add_system(shoot_balls.run_if(on_timer(Duration::from_secs(6))))
.add_system(move_cloth)
.add_systems(Startup, (spawn_cloth, setup))
.add_systems(
Update,
(
shoot_balls.run_if(on_timer(Duration::from_secs(6))),
move_cloth,
),
)
.run();
}

Expand Down
46 changes: 27 additions & 19 deletions src/components/cloth_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,16 +315,20 @@ impl ClothBuilder {
),
_ => None,
});
vertex_colors.map_or_else(|| {
log::warn!("ClothBuilder has anchored vertex colors but the associated mesh doesn't have a valid Vertex_Color attribute");
}, |colors| {
res.extend(colors.into_iter().enumerate().filter_map(|(i, color)| {
self.anchored_vertex_colors
.iter()
.find(|(c, _)| *c == color)
.map(|(_, anchor)| (i, *anchor))
}));
});
#[allow(clippy::option_if_let_else)]
match vertex_colors {
Some(colors) => {
res.extend(colors.into_iter().enumerate().filter_map(|(i, color)| {
self.anchored_vertex_colors
.iter()
.find(|(c, _)| *c == color)
.map(|(_, anchor)| (i, *anchor))
}));
}
None => {
log::warn!("ClothBuilder has anchored vertex colors but the associated mesh doesn't have a valid Vertex_Color attribute");
}
};
}
if !self.anchored_position_conditions.is_empty() {
let vertex_positions: Option<Vec<Vec3>> = mesh
Expand All @@ -335,15 +339,19 @@ impl ClothBuilder {
}
_ => None,
});
vertex_positions.map_or_else(|| {
log::warn!("ClothBuilder has anchored vertex positions but the associated mesh doesn't have a valid Vertex_Position attribute");
}, |positions| {
res.extend(positions.into_iter().enumerate().flat_map(|(i, pos)| {
self.anchored_position_conditions
.iter()
.filter_map(move |(c, anchor)| c(pos).then_some((i, *anchor)))
}));
});
#[allow(clippy::option_if_let_else)]
match vertex_positions {
Some(positions) => {
res.extend(positions.into_iter().enumerate().flat_map(|(i, pos)| {
self.anchored_position_conditions
.iter()
.filter_map(move |(c, anchor)| c(pos).then_some((i, *anchor)))
}));
}
None => {
log::warn!("ClothBuilder has anchored vertex positions but the associated mesh doesn't have a valid Vertex_Position attribute");
}
};
}
res
}
Expand Down
23 changes: 14 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,16 +307,21 @@ impl Plugin for ClothPlugin {
.register_type::<Wind>()
.register_type::<Winds>()
.register_type::<ClothBuilder>();
app.add_systems((
systems::cloth::init,
systems::cloth::update,
systems::cloth::render.after(systems::cloth::update),
));
app.add_systems(
Update,
(
systems::cloth::init,
(systems::cloth::update, systems::cloth::render).chain(),
),
);
#[cfg(feature = "rapier_collisions")]
app.register_type::<ClothCollider>().add_systems((
systems::collisions::init_cloth_collider,
systems::collisions::handle_collisions.before(systems::cloth::render),
));
app.register_type::<ClothCollider>().add_systems(
Update,
(
systems::collisions::init_cloth_collider,
systems::collisions::handle_collisions.before(systems::cloth::render),
),
);
bevy::log::info!("Loaded Cloth Plugin");
}
}
4 changes: 2 additions & 2 deletions src/vertex_anchor.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use bevy::math::Vec3;
use bevy::prelude::{Entity, GlobalTransform};
use bevy::reflect::{FromReflect, Reflect};
use bevy::reflect::Reflect;

/// Defines a cloth vertex anchor through a `target` and `offset`
///
/// The default anchor will link the cloth vertices to the cloth entity's `GlobalTransform`,
/// you can anchor them to a specific entity by defining a `custom_target`.
#[derive(Debug, Copy, Clone, Default, Reflect, FromReflect)]
#[derive(Debug, Copy, Clone, Default, Reflect)]
#[must_use]
pub struct VertexAnchor {
/// Optional custom anchor target entity. If not set, the cloth entity will be used
Expand Down
4 changes: 2 additions & 2 deletions src/wind.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use bevy::ecs::prelude::Resource;
use bevy::math::Vec3;
use bevy::reflect::{FromReflect, Reflect};
use bevy::reflect::Reflect;

/// Wind definition for cloth physics
#[derive(Debug, Clone, Reflect, FromReflect)]
#[derive(Debug, Clone, Reflect)]
pub enum Wind {
/// Constant Wind force
ConstantWind {
Expand Down

0 comments on commit 37a7b89

Please sign in to comment.