Skip to content

Commit

Permalink
Update to Bevy 0.12 (#228)
Browse files Browse the repository at this point in the history
* Suggest to use `cargo add` in README.md (#222)

* Use `SpatialBundle` (#221)

* Use `configure_sets` API (#223)

* Use `MaterialMesh2dBundle` with `ColorMaterial` (#224)

* Use `MaterialMesh2dBundle` with `ColorMaterial`

* clippy

* Fix green channel filtering bug

* Clippy again

* Update svgtypes to 0.12

* Update Bevy to 0.12

* Update to version 0.10.0

* Use diff-friendly markdown column format

---------

Co-authored-by: Federico Rinaldi <gisquerin@gmail.com>
  • Loading branch information
Weasy666 and Nilirad committed Nov 6, 2023
1 parent 2d4de13 commit 0f23422
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 114 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Changelog
## 0.10.0
- Support for Bevy 0.12.
- `ShapeBundle` now contains the `spatial: SpatialBundle` field, which bundles together `Transform`, `GlobalTransform`, `Visibility` and `InheritedVisibility`.

## 0.9.0
- Support for Bevy 0.11.
Expand Down
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ license = "MIT OR Apache-2.0"
name = "bevy_prototype_lyon"
readme = "README.md"
repository = "https://github.com/Nilirad/bevy_prototype_lyon/"
version = "0.9.0"
version = "0.10.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bevy = { version = "0.11", default-features = false, features = ["bevy_sprite", "bevy_render", "bevy_core_pipeline", "bevy_asset"] }
bevy = { version = "0.12", default-features = false, features = ["bevy_sprite", "bevy_render", "bevy_core_pipeline", "bevy_asset"] }
lyon_tessellation = "1"
lyon_algorithms = "1"
svgtypes = "0.8"
svgtypes = "0.12"

[dev-dependencies]
bevy = { version = "0.11", default-features = false, features = ["x11", "bevy_asset"] }
bevy = { version = "0.12", default-features = false, features = ["x11", "bevy_asset"] }
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Currently Bevy does not support drawing custom shapes in an easy way. This crate

## Usage

Add `bevy_prototype_lyon` to your package's dependencies:
Add `bevy_prototype_lyon` to your cargo project:

```shell
cargo add bevy_prototype_lyon
Expand Down Expand Up @@ -67,15 +67,16 @@ I strive to support the latest version of Bevy. Support for a version of Bevy is
The following table shows the latest version of `bevy_prototype_lyon` that supports a certain version of Bevy.

|bevy|bevy_prototype_lyon|license|
|---|---|---|
|----|---|---|
|0.12|0.10|MIT/Apache 2.0|
|0.11|0.9|MIT/Apache 2.0|
|0.10|0.8|MIT/Apache 2.0|
|0.9|0.7|MIT/Apache 2.0|
|0.8|0.6|MIT/Apache 2.0|
|0.7|0.5|MIT/Apache 2.0|
|0.6|0.4|MIT/Apache 2.0|
|0.5|0.3|MIT |
|0.4|0.2|MIT |
|0.9 |0.7|MIT/Apache 2.0|
|0.8 |0.6|MIT/Apache 2.0|
|0.7 |0.5|MIT/Apache 2.0|
|0.6 |0.4|MIT/Apache 2.0|
|0.5 |0.3|MIT|
|0.4 |0.2|MIT|

***

Expand Down
5 changes: 4 additions & 1 deletion examples/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ fn setup_system(mut commands: Commands) {
commands.spawn((
ShapeBundle {
path,
transform: Transform::from_xyz(0., 75., 0.),
spatial: SpatialBundle {
transform: Transform::from_xyz(0., 75., 0.),
..default()
},
..default()
},
Stroke::new(Color::BLACK, 10.0),
Expand Down
28 changes: 9 additions & 19 deletions src/entity.rs
Original file line number Diff line number Diff line change
@@ -1,43 +1,33 @@
//! Custom Bevy ECS bundle for shapes.

use bevy::{
ecs::{bundle::Bundle, component::Component},
prelude::{ComputedVisibility, GlobalTransform, Handle, Transform, Visibility},
sprite::Mesh2dHandle,
};
use bevy::{prelude::*, sprite::Mesh2dHandle};
use lyon_tessellation::{self as tess};

use crate::{prelude::Geometry, render::ShapeMaterial};
use crate::{geometry::Geometry, plugin::COLOR_MATERIAL_HANDLE};

/// A Bevy `Bundle` to represent a shape.
#[allow(missing_docs)]
#[derive(Bundle)]
pub struct ShapeBundle {
pub path: Path,
pub mesh: Mesh2dHandle,
pub material: Handle<ShapeMaterial>,
pub transform: Transform,
pub global_transform: GlobalTransform,
pub visibility: Visibility,
pub computed_visibility: ComputedVisibility,
pub material: Handle<ColorMaterial>,
pub spatial: SpatialBundle,
}

impl Default for ShapeBundle {
fn default() -> Self {
Self {
path: Path(tess::path::Path::new()),
mesh: Mesh2dHandle::default(),
material: Handle::<ShapeMaterial>::default(),
transform: Transform::default(),
global_transform: GlobalTransform::default(),
visibility: Visibility::default(),
computed_visibility: ComputedVisibility::default(),
path: default(),
mesh: default(),
material: COLOR_MATERIAL_HANDLE,
spatial: default(),
}
}
}

#[allow(missing_docs)]
#[derive(Component)]
#[derive(Component, Default)]
pub struct Path(pub tess::path::Path);

impl Geometry for Path {
Expand Down
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ pub mod entity;
pub mod geometry;
pub mod path;
pub mod plugin;
pub mod render;
pub mod shapes;

mod utils;
Expand Down
37 changes: 17 additions & 20 deletions src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,47 +12,44 @@
//! `ShapeBundle`.

use bevy::{
app::{App, Plugin},
asset::Assets,
ecs::{
query::{Changed, Or},
system::{Query, ResMut, Resource},
},
log::error,
prelude::{
Color, Deref, DerefMut, IntoSystemConfigs, IntoSystemSetConfig, PostUpdate, SystemSet,
},
render::{
mesh::{Indices, Mesh},
render_resource::PrimitiveTopology,
},
prelude::*,
render::{mesh::Indices, render_resource::PrimitiveTopology},
sprite::Mesh2dHandle,

Check failure on line 17 in src/plugin.rs

View workflow job for this annotation

GitHub Actions / clippy

unresolved import `bevy::render::render_asset::RenderAssetPersistencePolicy`

error[E0432]: unresolved import `bevy::render::render_asset::RenderAssetPersistencePolicy` --> src/plugin.rs:17:24 | 17 | mesh::Indices, render_asset::RenderAssetPersistencePolicy, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `RenderAssetPersistencePolicy` in `render_asset`

Check failure on line 17 in src/plugin.rs

View workflow job for this annotation

GitHub Actions / clippy

unresolved import `bevy::render::render_asset::RenderAssetPersistencePolicy`

error[E0432]: unresolved import `bevy::render::render_asset::RenderAssetPersistencePolicy` --> src/plugin.rs:17:24 | 17 | mesh::Indices, render_asset::RenderAssetPersistencePolicy, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `RenderAssetPersistencePolicy` in `render_asset`
};
use lyon_tessellation::{self as tess, BuffersBuilder};

use crate::{
draw::{Fill, Stroke},
entity::Path,
render::ShapeMaterialPlugin,
vertex::{VertexBuffers, VertexConstructor},
};

pub(crate) const COLOR_MATERIAL_HANDLE: Handle<ColorMaterial> =
Handle::weak_from_u128(0x7CC6_61A1_0CD6_C147_129A_2C01_882D_9580);

/// A plugin that provides resources and a system to draw shapes in Bevy with
/// less boilerplate.
pub struct ShapePlugin;

impl Plugin for ShapePlugin {
fn build(&self, app: &mut App) {
let fill_tess = lyon_tessellation::FillTessellator::new();
let stroke_tess = lyon_tessellation::StrokeTessellator::new();
let fill_tess = tess::FillTessellator::new();
let stroke_tess = tess::StrokeTessellator::new();
app.insert_resource(FillTessellator(fill_tess))
.insert_resource(StrokeTessellator(stroke_tess))
.configure_set(
.configure_sets(
PostUpdate,
BuildShapes.after(bevy::transform::TransformSystem::TransformPropagate),
)
.add_systems(PostUpdate, mesh_shapes_system.in_set(BuildShapes))
.add_plugins(ShapeMaterialPlugin);
.add_systems(PostUpdate, mesh_shapes_system.in_set(BuildShapes));

app.world.resource_mut::<Assets<ColorMaterial>>().insert(
COLOR_MATERIAL_HANDLE,
ColorMaterial {
color: Color::WHITE,
..default()
},
);
}
}

Expand Down
46 changes: 0 additions & 46 deletions src/render/mod.rs

This file was deleted.

15 changes: 0 additions & 15 deletions src/render/shape_material.wgsl

This file was deleted.

0 comments on commit 0f23422

Please sign in to comment.