Add Lerp trait impls for outline volume and stencil types.

This commit is contained in:
Robin KAY 2022-12-31 04:57:13 +00:00
parent 20a9386437
commit 10f2d985d3
2 changed files with 34 additions and 0 deletions

View File

@ -18,6 +18,7 @@ bevy = { version = "0.9", default-features = false, features = [
"bevy_core_pipeline",
] }
bitfield = "0.14"
interpolation = "0.2"
thiserror = "1.0"
[dev-dependencies]

View File

@ -32,6 +32,7 @@ use bevy::render::render_phase::{sort_phase_system, AddRenderCommand, DrawFuncti
use bevy::render::render_resource::{SpecializedMeshPipelines, VertexFormat};
use bevy::render::{RenderApp, RenderStage};
use bevy::transform::TransformSystem;
use interpolation::Lerp;
use crate::draw::{
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.
#[derive(Clone, Component, Default)]
pub struct OutlineVolume {
@ -97,6 +108,28 @@ pub struct OutlineVolume {
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.
#[derive(Bundle, Clone, Default)]
pub struct OutlineBundle {