Add Lerp trait impls for outline volume and stencil types.
This commit is contained in:
parent
20a9386437
commit
10f2d985d3
@ -18,6 +18,7 @@ bevy = { version = "0.9", default-features = false, features = [
|
|||||||
"bevy_core_pipeline",
|
"bevy_core_pipeline",
|
||||||
] }
|
] }
|
||||||
bitfield = "0.14"
|
bitfield = "0.14"
|
||||||
|
interpolation = "0.2"
|
||||||
thiserror = "1.0"
|
thiserror = "1.0"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
33
src/lib.rs
33
src/lib.rs
@ -32,6 +32,7 @@ use bevy::render::render_phase::{sort_phase_system, AddRenderCommand, DrawFuncti
|
|||||||
use bevy::render::render_resource::{SpecializedMeshPipelines, VertexFormat};
|
use bevy::render::render_resource::{SpecializedMeshPipelines, VertexFormat};
|
||||||
use bevy::render::{RenderApp, RenderStage};
|
use bevy::render::{RenderApp, RenderStage};
|
||||||
use bevy::transform::TransformSystem;
|
use bevy::transform::TransformSystem;
|
||||||
|
use interpolation::Lerp;
|
||||||
|
|
||||||
use crate::draw::{
|
use crate::draw::{
|
||||||
queue_outline_stencil_mesh, queue_outline_volume_mesh, DrawOutline, DrawStencil,
|
queue_outline_stencil_mesh, queue_outline_volume_mesh, DrawOutline, DrawStencil,
|
||||||
@ -86,6 +87,16 @@ impl ExtractComponent for OutlineStencil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Lerp for OutlineStencil {
|
||||||
|
type Scalar = f32;
|
||||||
|
|
||||||
|
fn lerp(&self, other: &Self, scalar: &Self::Scalar) -> Self {
|
||||||
|
OutlineStencil {
|
||||||
|
offset: self.offset.lerp(&other.offset, scalar),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// A component for rendering outlines around meshes.
|
/// A component for rendering outlines around meshes.
|
||||||
#[derive(Clone, Component, Default)]
|
#[derive(Clone, Component, Default)]
|
||||||
pub struct OutlineVolume {
|
pub struct OutlineVolume {
|
||||||
@ -97,6 +108,28 @@ pub struct OutlineVolume {
|
|||||||
pub colour: Color,
|
pub colour: Color,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Lerp for OutlineVolume {
|
||||||
|
type Scalar = f32;
|
||||||
|
|
||||||
|
fn lerp(&self, other: &Self, scalar: &Self::Scalar) -> Self {
|
||||||
|
OutlineVolume {
|
||||||
|
visible: if *scalar >= 0.5 {
|
||||||
|
other.visible
|
||||||
|
} else {
|
||||||
|
self.visible
|
||||||
|
},
|
||||||
|
width: self.width.lerp(&other.width, scalar),
|
||||||
|
colour: {
|
||||||
|
let [r, g, b, a] = self
|
||||||
|
.colour
|
||||||
|
.as_linear_rgba_f32()
|
||||||
|
.lerp(&other.colour.as_linear_rgba_f32(), scalar);
|
||||||
|
Color::rgba_linear(r, g, b, a)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// A bundle for rendering stenciled outlines around meshes.
|
/// A bundle for rendering stenciled outlines around meshes.
|
||||||
#[derive(Bundle, Clone, Default)]
|
#[derive(Bundle, Clone, Default)]
|
||||||
pub struct OutlineBundle {
|
pub struct OutlineBundle {
|
||||||
|
Loading…
Reference in New Issue
Block a user