Skip to content

Commit

Permalink
Bevy 0.6 (#6)
Browse files Browse the repository at this point in the history
Bevy 0.6
  • Loading branch information
ManevilleF authored Mar 4, 2022
1 parent 56d9ee1 commit 7cbf4f6
Show file tree
Hide file tree
Showing 17 changed files with 123 additions and 98 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased

- Bevy 0.6
- Rust 2021 edition
- Clippy extra restrictions

Expand Down
30 changes: 25 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,36 @@ debug = ["bevy_prototype_debug_lines"]
[dependencies]

[dependencies.bevy]
version = "0.5"
version = "0.6"
default-features = false

[dependencies.bevy_prototype_debug_lines]
version = "0.3"
version = "0.6"
optional = true

[dev-dependencies]

[dev-dependencies.bevy]
version = "0.5"
features = ["render", "bevy_winit", "png", "x11", "bevy_wgpu"]
default-features = false
version = "0.6"
features = ["render", "bevy_winit", "x11"]
default-features = false

[[example]]
name = "2d_cloth"
required-features = ["debug"]

[[example]]
name = "2d_cloth_cutter"
required-features = ["debug"]

[[example]]
name = "2d_line"
required-features = ["debug"]

[[example]]
name = "3d_cloth"
required-features = ["debug"]

[[example]]
name = "3d_line"
required-features = ["debug"]
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<!-- cargo-sync-readme start -->

# bevy_verlet
# Verlet Integration for Bevy

[![workflow](https://github.com/ManevilleF/bevy_verlet/actions/workflows/rust.yml/badge.svg)](https://github.com/ManevilleF/bevy_verlet/actions/workflows/rust.yml)

[![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE)
[![unsafe forbidden](https://img.shields.io/badge/unsafe-forbidden-success.svg)](https://github.com/rust-secure-code/safety-dance/)
[![Crates.io](https://img.shields.io/crates/v/bevy_verlet.svg)](https://crates.io/crates/bevy_verlet)
[![Docs.rs](https://docs.rs/bevy_verlet/badge.svg)](https://docs.rs/bevy_verlet)
[![dependency status](https://deps.rs/crate/bevy_verlet/0.1.0/status.svg)](https://deps.rs/crate/bevy_verlet)
[![dependency status](https://deps.rs/crate/bevy_verlet/0.1.1/status.svg)](https://deps.rs/crate/bevy_verlet)

Simple Verlet points and sticks implementation for bevy.

Expand All @@ -28,7 +28,7 @@ Customize *friction* and *gravity* with the `VerletConfig` resource.

1. `debug`

This feature will add a *system* drawing debug lines for every stick using [bevy_prototype_debug_lines](https://crates.io/crates/bevy_prototype_debug_lines)
This feature will add a *system* drawing debug lines for every stick using [`bevy_prototype_debug_lines`](https://crates.io/crates/bevy_prototype_debug_lines)


<!-- cargo-sync-readme end -->
Expand Down
17 changes: 9 additions & 8 deletions examples/2d_cloth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use bevy::prelude::*;
use bevy_verlet::{BevyVerletPlugin, VerletLocked, VerletPoint, VerletStick};

fn main() {
App::build()
App::new()
.insert_resource(WindowDescriptor {
title: "2D cloth".to_string(),
width: 1000.,
Expand All @@ -11,23 +11,24 @@ fn main() {
})
.add_plugins(DefaultPlugins)
.add_plugin(BevyVerletPlugin::default())
.add_startup_system(setup.system())
.add_startup_system(setup)
.run();
}

fn setup(mut commands: Commands, mut materials: ResMut<Assets<ColorMaterial>>) {
fn setup(mut commands: Commands) {
commands.spawn_bundle(OrthographicCameraBundle::new_2d());
let material = materials.add(Color::WHITE.into());
let fixed_material = materials.add(Color::RED.into());
let stick_length: f32 = 35.;
let (origin_x, origin_y) = (-450., 350.);
let (points_x_count, points_y_count) = (30, 15);
let mut entities = Vec::new();
for j in 0..points_y_count {
for i in 0..points_x_count {
let mut cmd = commands.spawn_bundle(SpriteBundle {
sprite: Sprite::new(Vec2::splat(10.)),
material: material.clone(),
sprite: Sprite {
color: if j == 0 { Color::RED } else { Color::WHITE },
custom_size: Some(Vec2::splat(10.)),
..Default::default()
},
transform: Transform::from_xyz(
origin_x + (30. * i as f32),
origin_y + (-30. * (j + i / 3) as f32),
Expand All @@ -38,7 +39,7 @@ fn setup(mut commands: Commands, mut materials: ResMut<Assets<ColorMaterial>>) {
cmd.insert(VerletPoint::default())
.insert(Name::new(format!("Point {}", i)));
if j == 0 {
cmd.insert(VerletLocked {}).insert(fixed_material.clone());
cmd.insert(VerletLocked);
}
entities.push(cmd.id());
}
Expand Down
8 changes: 4 additions & 4 deletions examples/2d_cloth_cutter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use bevy_verlet::{
};

fn main() {
App::build()
App::new()
.insert_resource(VerletConfig {
parallel_processing_batch_size: Some(1000),
sticks_computation_depth: 2,
Expand All @@ -18,8 +18,8 @@ fn main() {
})
.add_plugins(DefaultPlugins)
.add_plugin(BevyVerletPlugin::default())
.add_startup_system(setup.system())
.add_system(cut_sticks.system())
.add_startup_system(setup)
.add_system(cut_sticks)
.run();
}

Expand All @@ -41,7 +41,7 @@ fn setup(mut commands: Commands) {
.insert(VerletPoint::default())
.insert(Name::new(format!("Point {}", i)));
if j == 0 && i % 2 == 0 {
cmd.insert(VerletLocked {});
cmd.insert(VerletLocked);
}
entities.push(cmd.id());
}
Expand Down
37 changes: 17 additions & 20 deletions examples/2d_line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use bevy::prelude::*;
use bevy_verlet::{BevyVerletPlugin, VerletLocked, VerletPoint, VerletStick};

fn main() {
App::build()
App::new()
.insert_resource(WindowDescriptor {
title: "2D line".to_string(),
width: 1000.,
Expand All @@ -11,31 +11,27 @@ fn main() {
})
.add_plugins(DefaultPlugins)
.add_plugin(BevyVerletPlugin::default())
.add_startup_system(setup_camera.system())
.add_startup_system(setup_free_line.system())
.add_startup_system(setup_fixed_line.system())
.add_startup_system(setup_camera)
.add_startup_system(setup_free_line)
.add_startup_system(setup_fixed_line)
.run();
}

fn setup_camera(mut commands: Commands) {
commands.spawn_bundle(OrthographicCameraBundle::new_2d());
}

fn setup_free_line(mut commands: Commands, mut materials: ResMut<Assets<ColorMaterial>>) {
let material = materials.add(Color::WHITE.into());
let fixed_material = materials.add(Color::RED.into());
fn setup_free_line(mut commands: Commands) {
let stick_length: f32 = 50.;
let points_count = 10;
let mut previous_entity = None;
for i in 0..=points_count {
let mut cmd = commands.spawn_bundle(sprite_bundle(
material.clone(),
Vec2::new(50. * i as f32, 300.),
));
let mut cmd =
commands.spawn_bundle(sprite_bundle(Color::WHITE, Vec2::new(50. * i as f32, 300.)));
cmd.insert(VerletPoint::default())
.insert(Name::new(format!("Point {}", i)));
if previous_entity.is_none() {
cmd.insert(VerletLocked {}).insert(fixed_material.clone());
cmd.insert(VerletLocked);
}
let entity = cmd.id();
if let Some(e) = previous_entity {
Expand All @@ -52,22 +48,20 @@ fn setup_free_line(mut commands: Commands, mut materials: ResMut<Assets<ColorMat
}
}

fn setup_fixed_line(mut commands: Commands, mut materials: ResMut<Assets<ColorMaterial>>) {
let material = materials.add(Color::WHITE.into());
let fixed_material = materials.add(Color::RED.into());
fn setup_fixed_line(mut commands: Commands) {
let stick_length: f32 = 35.;
let points_count = 20;
let start_pos = -450.;
let mut previous_entity = None;
for i in 0..=points_count {
let mut cmd = commands.spawn_bundle(sprite_bundle(
material.clone(),
Color::WHITE,
Vec2::new(start_pos + 30. * i as f32, 0.),
));
cmd.insert(VerletPoint::default())
.insert(Name::new(format!("Point {}", i)));
if previous_entity.is_none() || i == points_count {
cmd.insert(VerletLocked {}).insert(fixed_material.clone());
cmd.insert(VerletLocked);
}
let entity = cmd.id();
if let Some(e) = previous_entity {
Expand All @@ -84,10 +78,13 @@ fn setup_fixed_line(mut commands: Commands, mut materials: ResMut<Assets<ColorMa
}
}

fn sprite_bundle(material: Handle<ColorMaterial>, pos: Vec2) -> SpriteBundle {
fn sprite_bundle(color: Color, pos: Vec2) -> SpriteBundle {
SpriteBundle {
sprite: Sprite::new(Vec2::splat(10.)),
material,
sprite: Sprite {
color,
custom_size: Some(Vec2::splat(10.)),
..Default::default()
},
transform: Transform::from_xyz(pos.x, pos.y, 0.),
..Default::default()
}
Expand Down
6 changes: 3 additions & 3 deletions examples/3d_cloth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use bevy::prelude::*;
use bevy_verlet::{BevyVerletPlugin, VerletConfig, VerletLocked, VerletPoint, VerletStick};

fn main() {
App::build()
App::new()
.insert_resource(WindowDescriptor {
title: "3D cloth".to_string(),
width: 1000.,
Expand All @@ -11,7 +11,7 @@ fn main() {
})
.add_plugins(DefaultPlugins)
.add_plugin(BevyVerletPlugin::default())
.add_startup_system(setup.system())
.add_startup_system(setup)
.insert_resource(VerletConfig {
sticks_computation_depth: 5,
..Default::default()
Expand Down Expand Up @@ -50,7 +50,7 @@ fn setup(
cmd.insert(VerletPoint::default())
.insert(Name::new(format!("Point {}", i)));
if j == 0 {
cmd.insert(VerletLocked {}).insert(fixed_material.clone());
cmd.insert(VerletLocked).insert(fixed_material.clone());
}
entities.push(cmd.id());
}
Expand Down
12 changes: 6 additions & 6 deletions examples/3d_line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use bevy::prelude::*;
use bevy_verlet::{BevyVerletPlugin, VerletConfig, VerletLocked, VerletPoint, VerletStick};

fn main() {
App::build()
App::new()
.insert_resource(WindowDescriptor {
title: "3D line".to_string(),
width: 1000.,
Expand All @@ -11,9 +11,9 @@ fn main() {
})
.add_plugins(DefaultPlugins)
.add_plugin(BevyVerletPlugin::default())
.add_startup_system(setup_camera.system())
.add_startup_system(setup_free_line.system())
.add_startup_system(setup_fixed_line.system())
.add_startup_system(setup_camera)
.add_startup_system(setup_free_line)
.add_startup_system(setup_fixed_line)
.insert_resource(VerletConfig {
sticks_computation_depth: 5,
..Default::default()
Expand Down Expand Up @@ -48,7 +48,7 @@ fn setup_free_line(
cmd.insert(VerletPoint::default())
.insert(Name::new(format!("Point {}", i)));
if previous_entity.is_none() {
cmd.insert(VerletLocked {}).insert(fixed_material.clone());
cmd.insert(VerletLocked).insert(fixed_material.clone());
}
let entity = cmd.id();
if let Some(e) = previous_entity {
Expand Down Expand Up @@ -86,7 +86,7 @@ fn setup_fixed_line(
cmd.insert(VerletPoint::default())
.insert(Name::new(format!("Point {}", i)));
if previous_entity.is_none() || i == points_count {
cmd.insert(VerletLocked {}).insert(fixed_material.clone());
cmd.insert(VerletLocked).insert(fixed_material.clone());
}
let entity = cmd.id();
if let Some(e) = previous_entity {
Expand Down
6 changes: 4 additions & 2 deletions src/components/locked.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use bevy::prelude::{Component, Reflect};

/// Component preventing application of [`VerletPoint`][VerletPoint] physics.
///
/// [VerletPoint]: struct.VerletPoint.html
#[derive(Debug, Copy, Clone)]
pub struct VerletLocked {}
#[derive(Debug, Copy, Clone, Component, Reflect)]
pub struct VerletLocked;
10 changes: 2 additions & 8 deletions src/components/point.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
use bevy::math::Vec3;
use bevy::prelude::{Component, Reflect, Vec3};

/// Main verlet physics component.
/// Any entity with this component will have physics applied to it
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Component, Default, Reflect)]
pub struct VerletPoint {
pub(crate) old_position: Option<Vec3>,
}

impl Default for VerletPoint {
fn default() -> Self {
Self { old_position: None }
}
}
4 changes: 2 additions & 2 deletions src/components/stick.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use bevy::prelude::Entity;
use bevy::prelude::{Component, Entity, Reflect};

/// Constraint component between two [`VerletPoint`][VerletPoint].
///
/// [VerletPoint]: struct.VerletPoint.html
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Component, Reflect)]
pub struct VerletStick {
/// Start `VerletPoint` entity
pub point_a_entity: Entity,
Expand Down
4 changes: 3 additions & 1 deletion src/components/stick_max_tension.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use bevy::prelude::{Component, Reflect};

/// Component adding a maximum tension to a [`VerletStick`][VerletStick]
///
/// The stick will break when its size becomes bigger than its `length` multiplied by this factor
Expand All @@ -6,5 +8,5 @@
/// If you set it to `2.0` the stick will break when stretched to twice its `length`
///
/// [VerletStick]: struct.VerletStick.html
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Component, Reflect)]
pub struct VerletStickMaxTension(pub f32);
Loading

0 comments on commit 7cbf4f6

Please sign in to comment.