Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ license = "MIT OR Apache-2.0"
name = "bevy_prototype_lyon"
readme = "README.md"
repository = "https://github.com/Nilirad/bevy_prototype_lyon/"
version = "0.13.0"
version = "0.15.0"

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

[dependencies]
bevy = { version = "0.15.0", default-features = false, features = [
"bevy_sprite",
"bevy_render",
"bevy_core_pipeline",
"bevy_asset",
bevy = { version = "0.17.0", default-features = false, features = [
"bevy_asset",
"bevy_render",
"bevy_sprite_render",
"bevy_log",
] }
lyon_tessellation = "1"
lyon_algorithms = "1"
svgtypes = "0.15"

[dev-dependencies]
bevy = "0.15.0"
bevy = "0.17.0"
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ The following table shows the latest version of `bevy_prototype_lyon` that suppo

|bevy|bevy_prototype_lyon|license|
|---|---|---|
|0.17|0.15|MIT/Apache 2.0|
|0.15|0.13|MIT/Apache 2.0|
|0.14|0.12|MIT/Apache 2.0|
|0.13|0.11|MIT/Apache 2.0|
Expand Down
7 changes: 5 additions & 2 deletions deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ allow = [
"CC0-1.0",
]
exceptions = [
{ name = "unicode-ident", allow = ["Unicode-DFS-2016", "Unicode-3.0"] },
{ name = "unicode-ident", allow = [
"Unicode-DFS-2016",
"Unicode-3.0",
] },
]

[[licenses.clarify]]
Expand All @@ -32,7 +35,7 @@ license-files = []
name = "stretch"

[bans]
multiple-versions = "allow"
multiple-versions = "allow"
wildcards = "allow"

[sources]
Expand Down
5 changes: 2 additions & 3 deletions examples/dynamic_shape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn rotate_shape_system(mut query: Query<&mut Transform, With<ExampleShape>>, tim
}
}

fn redraw_shape(mut query: Query<&mut Shape, With<ExampleShape>>, time: Res<Time>) {
fn redraw_shape(mut shape: Single<&mut Shape, With<ExampleShape>>, time: Res<Time>) {
let hue = (time.elapsed_secs_f64() * 50.0) % 360.0;
let color = Color::hsl(hue as f32, 1.0, 0.5);
let outline_width = 2.0 + time.elapsed_secs_f64().sin().abs() * 10.0;
Expand All @@ -34,8 +34,7 @@ fn redraw_shape(mut query: Query<&mut Shape, With<ExampleShape>>, time: Res<Time
..shapes::RegularPolygon::default()
};

let mut shape = query.single_mut();
*shape = ShapeBuilder::with(&polygon)
**shape = ShapeBuilder::with(&polygon)
.fill(color)
.stroke((BLACK, outline_width as f32))
.build();
Expand Down
6 changes: 2 additions & 4 deletions examples/dynamic_stroke_size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,20 @@ fn rotate_shape_by_size(mut query: Query<(&mut Transform, &Shape)>, time: Res<Ti
}

/// Change line width of the hexagon over time.
fn redraw_line_width(mut query: Query<&mut Shape, With<HexagonShape>>, time: Res<Time>) {
fn redraw_line_width(mut shape: Single<&mut Shape, With<HexagonShape>>, time: Res<Time>) {
let outline_width = 2.0 + time.elapsed_secs_f64().sin().abs() * 10.0;

let mut shape = query.single_mut();
shape.stroke = shape.stroke.map(|mut s| {
s.options.line_width = outline_width as f32;
s
});
}

/// Change fill color of the triangle over time.
fn redraw_fill(mut query: Query<&mut Shape, With<TriangleShape>>, time: Res<Time>) {
fn redraw_fill(mut shape: Single<&mut Shape, With<TriangleShape>>, time: Res<Time>) {
let hue = (time.elapsed_secs_f64() * 50.0) % 360.0;
let color = Color::hsl(hue as f32, 1.0, 0.5);

let mut shape = query.single_mut();
shape.fill = shape.fill.map(|mut f| {
f.color = color;
f
Expand Down
6 changes: 1 addition & 5 deletions src/entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl Default for ShapeBundle {
///
/// It can be constructed using `ShapeBuilder`.
#[derive(Component, Default, Clone)]
#[require(Mesh2d, MeshMaterial2d<ColorMaterial>(color_material_handle), Transform, Visibility)]
#[require(Mesh2d, MeshMaterial2d::<ColorMaterial>(COLOR_MATERIAL_HANDLE), Transform, Visibility)]
#[non_exhaustive]
pub struct Shape {
/// Geometry of a shape.
Expand All @@ -61,7 +61,3 @@ impl Geometry<Builder> for Shape {
b.extend_from_paths(&[self.path.as_slice()]);
}
}

fn color_material_handle() -> MeshMaterial2d<ColorMaterial> {
MeshMaterial2d(COLOR_MATERIAL_HANDLE)
}
2 changes: 1 addition & 1 deletion src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,5 +135,5 @@ fn match_action(action: Action, b: &mut WithSvg<BuilderImpl>) {
Action::Close => {
b.close();
}
};
}
}
29 changes: 21 additions & 8 deletions src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@
//! boilerplate.

use bevy::{
asset::{uuid_handle, RenderAssetUsages},
prelude::*,
render::{mesh::Indices, render_asset::RenderAssetUsages, render_resource::PrimitiveTopology},
camera::primitives::{Aabb, MeshAabb},
mesh::Indices,
render::{
render_resource::PrimitiveTopology,
},
};
use lyon_tessellation::{self as tess, BuffersBuilder};

Expand All @@ -16,7 +21,7 @@ use crate::{
};

pub(crate) const COLOR_MATERIAL_HANDLE: Handle<ColorMaterial> =
Handle::weak_from_u128(0x7CC6_61A1_0CD6_C147_129A_2C01_882D_9580);
uuid_handle!("7cc661a1-0cd6-c147-129a-2c01882d9580");

/// A plugin that provides resources and a system to draw shapes in Bevy with
/// less boilerplate.
Expand All @@ -30,19 +35,23 @@ impl Plugin for ShapePlugin {
.insert_resource(StrokeTessellator(stroke_tess))
.configure_sets(
PostUpdate,
BuildShapes.after(bevy::transform::TransformSystem::TransformPropagate),
BuildShapes
.after(bevy::transform::TransformSystems::Propagate)
.before(bevy::asset::AssetEventSystems),
)
.add_systems(PostUpdate, mesh_shapes_system.in_set(BuildShapes));

app.world_mut()
if let Err(e) = app.world_mut()
.resource_mut::<Assets<ColorMaterial>>()
.insert(
&COLOR_MATERIAL_HANDLE,
ColorMaterial {
color: Color::WHITE,
..default()
},
);
) {
error!("Failed to add resource: {:?}", e);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error message is inaccurate, the error is coming from insert on Assets.

The docs mention that this method will not fail for uuid assets, so the error could be safely ignored.

Although it might be appropriate to use the fallible version of resource_mut. I think this could be missing if a user fails to add rendering features/plugins.

if let Some(mut materials) = app.world_mut().get_resource_mut::<Assets<ColorMaterial>>() {
    // `insert` will not fail for uuid assets
    let _ = materials.insert(
        &COLOR_MATERIAL_HANDLE,
        ColorMaterial {
            color: Color::WHITE,
            ..default()
        },
    );
} else {
    error!("Failed to get Assets<ColorMaterial> resource");
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the code compiling without errors for you?

Copy link
Owner

@rparrett rparrett Oct 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you referencing the error you commented about earlier, or something about this particular review feedback?

I suppose either way, the answer is yes.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

never mind, seems to have fixed itself

}
}
}

Expand All @@ -59,17 +68,21 @@ fn mesh_shapes_system(
mut meshes: ResMut<Assets<Mesh>>,
mut fill_tess: ResMut<FillTessellator>,
mut stroke_tess: ResMut<StrokeTessellator>,
mut query: Query<(&Shape, &mut Mesh2d), Changed<Shape>>,
mut query: Query<(&Shape, &mut Mesh2d, Option<&mut Aabb>), Changed<Shape>>,
) {
for (shape, mut mesh) in &mut query {
for (shape, mut mesh, aabb) in &mut query {
let mut buffers = VertexBuffers::new();
if let Some(fill_mode) = shape.fill {
fill(&mut fill_tess, &shape.path, fill_mode, &mut buffers);
}
if let Some(stroke_mode) = shape.stroke {
stroke(&mut stroke_tess, &shape.path, stroke_mode, &mut buffers);
}
mesh.0 = meshes.add(build_mesh(&buffers));
let m = build_mesh(&buffers);
if let (Some(mut aabb), Some(new_aabb)) = (aabb, m.compute_aabb()) {
*aabb = new_aabb;
}
mesh.0 = meshes.add(m);
Comment on lines +81 to +85
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this fixing or working around a bug that's documented somewhere? I'm surprised that modern Bevy isn't automatically recomputing the Aabb.

}
}

Expand Down
2 changes: 1 addition & 1 deletion src/shapes/svg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub struct SvgPathShape {
pub svg_path_string: String,
}
fn get_y_in_bevy_orientation(y: f64) -> f32 {
y as f32 * -1.
-(y as f32)
}
fn get_y_after_offset(y: f64, offset_y: f32) -> f32 {
get_y_in_bevy_orientation(y) + offset_y
Expand Down