Skip to content

Commit 1530a1b

Browse files
committed
Replace ShapeMaterial
1 parent 673b1f8 commit 1530a1b

File tree

8 files changed

+20
-69
lines changed

8 files changed

+20
-69
lines changed

examples/readme_example.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ use bevy_prototype_lyon::prelude::*;
66

77
fn main() {
88
App::build()
9+
.insert_resource(Msaa { samples: 8 })
910
.add_plugins(DefaultPlugins)
1011
.add_plugin(ShapePlugin)
1112
.add_startup_system(setup.system())
1213
.run();
1314
}
1415

15-
fn setup(mut commands: Commands, mut materials: ResMut<Assets<ShapeMaterial>>) {
16+
fn setup(mut commands: Commands) {
1617
let circle = shapes::Circle {
1718
radius: 100.0,
1819
..shapes::Circle::default()
@@ -22,8 +23,11 @@ fn setup(mut commands: Commands, mut materials: ResMut<Assets<ShapeMaterial>>) {
2223
.spawn(OrthographicCameraBundle::new_2d())
2324
.spawn(GeometryBuilder::build_as(
2425
&circle,
25-
materials.add(ShapeMaterial::new(Color::AQUAMARINE)),
26-
DrawMode::Fill(FillOptions::default()),
26+
ShapeColors::outlined(Color::GOLD, Color::BLACK),
27+
DrawMode::Outlined {
28+
fill_options: FillOptions::default(),
29+
outline_options: StrokeOptions::default().with_line_width(5.0),
30+
},
2731
Transform::default(),
2832
));
2933
}

examples/svg_path_shape_example.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ struct BuildingBundle {
1919
transform: Transform,
2020
global_transform: GlobalTransform,
2121
}
22-
fn startup_system(mut commands: Commands, mut materials: ResMut<Assets<ShapeMaterial>>) {
22+
fn startup_system(mut commands: Commands) {
2323
commands.spawn(OrthographicCameraBundle::new_2d());
2424

2525
commands.spawn(BuildingBundle {
@@ -41,7 +41,7 @@ fn startup_system(mut commands: Commands, mut materials: ResMut<Assets<ShapeMate
4141
svg_doc_size_in_px:svg_doc_size.to_owned()
4242
},
4343

44-
materials.add(ShapeMaterial::new(Color::BLACK)),
44+
ShapeColors::new(Color::BLACK),
4545
DrawMode::Stroke(StrokeOptions::default().with_line_width(4.)),
4646
Transform::default()
4747
))
@@ -52,7 +52,7 @@ fn startup_system(mut commands: Commands, mut materials: ResMut<Assets<ShapeMate
5252
svg_doc_size_in_px:svg_doc_size.to_owned()
5353
},
5454

55-
materials.add(ShapeMaterial::new(Color::BLACK)),
55+
ShapeColors::new(Color::BLACK),
5656
DrawMode::Stroke(StrokeOptions::default().with_line_width(2.5)),
5757
Transform::default()
5858
))
@@ -77,7 +77,7 @@ fn startup_system(mut commands: Commands, mut materials: ResMut<Assets<ShapeMate
7777
svg_doc_size_in_px:svg_doc_size.to_owned()
7878
},
7979

80-
materials.add(ShapeMaterial::new(Color::BLACK)),
80+
ShapeColors::new(Color::BLACK),
8181
DrawMode::Stroke(StrokeOptions::default().with_line_width(20.)),
8282
Transform::default()
8383
))
@@ -88,7 +88,7 @@ fn startup_system(mut commands: Commands, mut materials: ResMut<Assets<ShapeMate
8888
svg_doc_size_in_px:svg_doc_size.to_owned()
8989
},
9090

91-
materials.add(ShapeMaterial::new(Color::BLACK)),
91+
ShapeColors::new(Color::BLACK),
9292
DrawMode::Stroke(StrokeOptions::default().with_line_width(17.5)),
9393
Transform::default()
9494
))

src/entity.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ pub struct ShapeBundle {
4848
pub mode: DrawMode,
4949
pub mesh: Handle<Mesh>,
5050
pub colors: ShapeColors,
51-
pub material: Handle<ShapeMaterial>,
5251
pub main_pass: MainPass,
5352
pub draw: Draw,
5453
pub visible: Visible,
@@ -76,25 +75,8 @@ impl Default for ShapeBundle {
7675
main: Color::WHITE,
7776
outline: Color::BLACK,
7877
},
79-
material: Handle::<ShapeMaterial>::default(),
8078
transform: Transform::default(),
8179
global_transform: GlobalTransform::default(),
8280
}
8381
}
8482
}
85-
86-
/// Defines the color of the shape
87-
#[derive(RenderResources, Default, TypeUuid)]
88-
#[uuid = "370d078f-e13b-48d8-b12a-954ba887afcb"]
89-
pub struct ShapeMaterial {
90-
#[allow(missing_docs)]
91-
pub color: Color,
92-
}
93-
94-
impl ShapeMaterial {
95-
/// Creates a `ShapeMaterial` with the specified `Color`.
96-
#[must_use]
97-
pub const fn new(color: Color) -> Self {
98-
Self { color }
99-
}
100-
}

src/geometry.rs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33
use bevy::{asset::Handle, transform::components::Transform};
44
use lyon_tessellation::path::{path::Builder, Path};
55

6-
use crate::{
7-
entity::{ShapeBundle, ShapeMaterial},
8-
utils::DrawMode,
9-
};
6+
use crate::{entity::ShapeBundle, prelude::ShapeColors, utils::DrawMode};
107

118
/// Structs that implement this trait can be drawn as a shape. See the
129
/// [`shapes`](crate::shapes) module for some examples.
@@ -104,15 +101,10 @@ impl GeometryBuilder {
104101
/// Generates a [`ShapeBundle`] using the data contained in the path
105102
/// builder.
106103
#[must_use]
107-
pub fn build(
108-
self,
109-
material: Handle<ShapeMaterial>,
110-
mode: DrawMode,
111-
transform: Transform,
112-
) -> ShapeBundle {
104+
pub fn build(self, colors: ShapeColors, mode: DrawMode, transform: Transform) -> ShapeBundle {
113105
ShapeBundle {
114106
path: self.0.build(),
115-
material,
107+
colors,
116108
mode,
117109
transform,
118110
..ShapeBundle::default()
@@ -140,13 +132,13 @@ impl GeometryBuilder {
140132
/// ```
141133
pub fn build_as(
142134
shape: &impl Geometry,
143-
material: Handle<ShapeMaterial>,
135+
colors: ShapeColors,
144136
mode: DrawMode,
145137
transform: Transform,
146138
) -> ShapeBundle {
147139
let mut multishape = Self::new();
148140
multishape.add(shape);
149-
multishape.build(material, mode, transform)
141+
multishape.build(colors, mode, transform)
150142
}
151143
}
152144

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub mod prelude {
4343
};
4444

4545
pub use crate::{
46-
entity::{ShapeColors, ShapeMaterial},
46+
entity::ShapeColors,
4747
geometry::{Geometry, GeometryBuilder},
4848
path::PathBuilder,
4949
plugin::ShapePlugin,

src/plugin.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,7 @@ use lyon_tessellation::{
3131
StrokeTessellator, StrokeVertex, StrokeVertexConstructor,
3232
};
3333

34-
use crate::{
35-
entity::{ShapeColors, ShapeMaterial},
36-
utils::DrawMode,
37-
};
34+
use crate::{entity::ShapeColors, utils::DrawMode};
3835

3936
/// Stages for this plugin.
4037
pub mod stage {
@@ -100,8 +97,7 @@ impl Plugin for ShapePlugin {
10097
fn build(&self, app: &mut AppBuilder) {
10198
let fill_tess = FillTessellator::new();
10299
let stroke_tess = StrokeTessellator::new();
103-
app.add_asset::<ShapeMaterial>()
104-
.insert_resource(fill_tess)
100+
app.insert_resource(fill_tess)
105101
.insert_resource(stroke_tess)
106102
.add_stage_after(
107103
bevy::app::CoreStage::Update,

src/render/mod.rs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ use bevy::{
1616
},
1717
};
1818

19-
use crate::prelude::ShapeMaterial;
20-
2119
#[allow(missing_docs, clippy::unreadable_literal)]
2220
pub const SHAPE_PIPELINE_HANDLE: HandleUntyped =
2321
HandleUntyped::weak_from_u64(PipelineDescriptor::TYPE_UUID, 3868147544761532180);
@@ -75,26 +73,9 @@ fn build_shape_pipeline(mut shaders: ResMut<Assets<Shader>>) -> PipelineDescript
7573
}
7674
}
7775

78-
/// Render nodes for this crate.
79-
pub mod node {
80-
#![allow(missing_docs)]
81-
82-
pub const SHAPE_MATERIAL: &str = "bevy_prototype_lyon:shape_material";
83-
}
84-
8576
pub(crate) fn add_shape_pipeline(
8677
mut pipelines: ResMut<Assets<PipelineDescriptor>>,
87-
mut render_graph: ResMut<RenderGraph>,
8878
shaders: ResMut<Assets<Shader>>,
8979
) {
9080
pipelines.set_untracked(SHAPE_PIPELINE_HANDLE, build_shape_pipeline(shaders));
91-
92-
render_graph.add_system_node(
93-
node::SHAPE_MATERIAL,
94-
AssetRenderResourcesNode::<ShapeMaterial>::new(true),
95-
);
96-
97-
render_graph
98-
.add_node_edge(node::SHAPE_MATERIAL, base::node::MAIN_PASS)
99-
.unwrap();
10081
}

src/render/shape.frag

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ layout(location = 0) in vec4 v_color;
44

55
layout(location = 0) out vec4 o_Target;
66

7-
layout(set = 2, binding = 0) uniform ShapeMaterial_color {
8-
vec4 color;
9-
};
10-
117
void main() {
128
o_Target = v_color;
139
}

0 commit comments

Comments
 (0)