From ce228d1c2d6c689f21ba00aa3842dc40d658455d Mon Sep 17 00:00:00 2001 From: Robin KAY Date: Mon, 8 Aug 2022 22:53:27 +0100 Subject: [PATCH] Add OutlineBundle. --- examples/shapes.rs | 24 ++++++++++++++---------- src/lib.rs | 11 +++++++++-- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/examples/shapes.rs b/examples/shapes.rs index 42ddf9f..dafaf74 100644 --- a/examples/shapes.rs +++ b/examples/shapes.rs @@ -46,12 +46,14 @@ fn setup( transform: Transform::from_xyz(0.0, 1.0, 0.0), ..default() }) - .insert(Outline { - visible: true, - colour: Color::rgba(0.0, 1.0, 0.0, 1.0), - width: 25.0, + .insert_bundle(OutlineBundle { + outline: Outline { + visible: true, + colour: Color::rgba(0.0, 1.0, 0.0, 1.0), + width: 25.0, + }, + ..default() }) - .insert(OutlineStencil) .insert(Wobbles); commands @@ -67,12 +69,14 @@ fn setup( .with_rotation(Quat::from_rotation_x(0.5 * PI)), ..default() }) - .insert(Outline { - visible: true, - colour: Color::rgba(1.0, 0.0, 1.0, 0.3), - width: 15.0, + .insert_bundle(OutlineBundle { + outline: Outline { + visible: true, + colour: Color::rgba(1.0, 0.0, 1.0, 0.3), + width: 15.0, + }, + ..default() }) - .insert(OutlineStencil) .insert(Orbits); commands.spawn_bundle(PointLightBundle { point_light: PointLight { diff --git a/src/lib.rs b/src/lib.rs index c128def..8f4232e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -40,7 +40,7 @@ pub const ATTRIBUTE_OUTLINE_NORMAL: MeshVertexAttribute = MeshVertexAttribute::n ); /// A component for stenciling meshes during outline rendering. -#[derive(Component, Default)] +#[derive(Clone, Component, Default)] pub struct OutlineStencil; impl ExtractComponent for OutlineStencil { @@ -53,7 +53,7 @@ impl ExtractComponent for OutlineStencil { } /// A component for rendering outlines around meshes. -#[derive(Clone, Component)] +#[derive(Clone, Component, Default)] pub struct Outline { /// Enable rendering of the outline pub visible: bool, @@ -63,6 +63,13 @@ pub struct Outline { pub colour: Color, } +/// A bundle for rendering stenciled outlines around meshes. +#[derive(Bundle, Clone, Component, Default)] +pub struct OutlineBundle { + pub outline: Outline, + pub stencil: OutlineStencil, +} + /// Failed to generate outline normals for the mesh. #[derive(thiserror::Error, Debug)] pub enum GenerateOutlineNormalsError {