From 20244753692b58dceee7827a99b54842075d840e Mon Sep 17 00:00:00 2001 From: nertsal Date: Mon, 14 Oct 2024 15:11:48 +0300 Subject: [PATCH] [editor] fix dashed move preview artifacts --- crates/ctl-core/src/interpolation/mod.rs | 18 +++++++++++------- src/render/editor/game.rs | 21 +++++++++++++-------- src/render/util.rs | 1 - 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/crates/ctl-core/src/interpolation/mod.rs b/crates/ctl-core/src/interpolation/mod.rs index f6d55cb6..d84f2d43 100644 --- a/crates/ctl-core/src/interpolation/mod.rs +++ b/crates/ctl-core/src/interpolation/mod.rs @@ -27,14 +27,18 @@ impl Interpolation { /// Get the full path of the interpolation with the given `resolution` per segment. pub fn get_path(&self, resolution: usize) -> impl Iterator + '_ { - self.segments.iter().flat_map(move |segment| { - (0..segment.num_intervals()).flat_map(move |interval| { - (0..resolution).flat_map(move |i| { - let t = i as f32 / resolution as f32; - segment.get(interval, r32(t)) + self.segments + .first() + .and_then(|segment| segment.get(0, Time::ZERO)) + .into_iter() + .chain(self.segments.iter().flat_map(move |segment| { + (0..segment.num_intervals()).flat_map(move |interval| { + (1..=resolution).flat_map(move |i| { + let t = i as f32 / resolution as f32; + segment.get(interval, r32(t)) + }) }) - }) - }) + })) } } diff --git a/src/render/editor/game.rs b/src/render/editor/game.rs index 01510bd3..6a1cc6b1 100644 --- a/src/render/editor/game.rs +++ b/src/render/editor/game.rs @@ -197,16 +197,16 @@ impl EditorRender { }; // A dashed line moving through the waypoints to show general direction - const RESOLUTION: usize = 10; + const RESOLUTION: usize = 5; // TODO: cache curve let curve = event.light.movement.bake(); let mut positions: Vec = curve .get_path(RESOLUTION) .enumerate() - .map(|(i, transform)| { + .filter_map(|(i, transform)| { let movement = &event.light.movement; let segment = i / RESOLUTION; - let t = (i % RESOLUTION) as f32 / RESOLUTION.saturating_sub(1) as f32; + let t = (i % RESOLUTION) as f32 / RESOLUTION as f32; let a = movement .get_time(WaypointId::Frame(segment).prev().unwrap()) .unwrap_or(Time::ZERO); @@ -214,20 +214,25 @@ impl EditorRender { .get_time(WaypointId::Frame(segment)) .unwrap_or(Time::ZERO); let beat = a + (b - a) * r32(t); - draw2d::ColoredVertex { + let alpha = visibility(beat); + (alpha > 0.01).then_some(draw2d::ColoredVertex { a_pos: transform.translation.as_f32(), - a_color: crate::util::with_alpha(color, visibility(beat)), - } + a_color: crate::util::with_alpha(color, alpha), + }) }) .collect(); - positions.dedup_by_key(|vertex| vertex.a_pos); let options = util::DashRenderOptions { width: 0.15, - color, dash_length: 0.1, space_length: 0.2, }; + + positions.dedup_by(|a, b| { + (a.a_pos - b.a_pos).len_sqr() + < (options.dash_length + options.space_length).sqr() + }); + if let Some(&to) = positions.get(1) { let pos = positions.first_mut().unwrap(); let period = options.dash_length + options.space_length; diff --git a/src/render/util.rs b/src/render/util.rs index f8976e2d..5ac05995 100644 --- a/src/render/util.rs +++ b/src/render/util.rs @@ -20,7 +20,6 @@ pub struct TextRenderOptions { #[derive(Debug, Clone, Copy)] pub struct DashRenderOptions { pub width: f32, - pub color: Color, pub dash_length: f32, pub space_length: f32, }