Add OutlineBundle.

This commit is contained in:
Robin KAY 2022-08-08 22:53:27 +01:00
parent 75dcc9077c
commit ce228d1c2d
2 changed files with 23 additions and 12 deletions

View File

@ -46,12 +46,14 @@ fn setup(
transform: Transform::from_xyz(0.0, 1.0, 0.0),
..default()
})
.insert(Outline {
.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 {
.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 {

View File

@ -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 {