Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9fb4c0edf4 | ||
|
|
1e3cfdcf21 | ||
|
|
a04b903e96 | ||
|
|
c4bccc1747 | ||
|
|
5264f0c247 | ||
|
|
a999d9c064 | ||
|
|
71d314ac44 |
41
Cargo.lock
generated
41
Cargo.lock
generated
@@ -1320,6 +1320,7 @@ dependencies = [
|
|||||||
"log",
|
"log",
|
||||||
"serialport",
|
"serialport",
|
||||||
"tobj",
|
"tobj",
|
||||||
|
"winresource",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -3645,6 +3646,15 @@ dependencies = [
|
|||||||
"syn",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde_spanned"
|
||||||
|
version = "1.1.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6662b5879511e06e8999a8a235d848113e942c9124f211511b16466ee2995f26"
|
||||||
|
dependencies = [
|
||||||
|
"serde_core",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serialport"
|
name = "serialport"
|
||||||
version = "4.9.0"
|
version = "4.9.0"
|
||||||
@@ -3989,6 +3999,21 @@ dependencies = [
|
|||||||
"ahash",
|
"ahash",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "toml"
|
||||||
|
version = "1.1.2+spec-1.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "81f3d15e84cbcd896376e6730314d59fb5a87f31e4b038454184435cd57defee"
|
||||||
|
dependencies = [
|
||||||
|
"indexmap",
|
||||||
|
"serde_core",
|
||||||
|
"serde_spanned",
|
||||||
|
"toml_datetime",
|
||||||
|
"toml_parser",
|
||||||
|
"toml_writer",
|
||||||
|
"winnow",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "toml_datetime"
|
name = "toml_datetime"
|
||||||
version = "1.1.1+spec-1.1.0"
|
version = "1.1.1+spec-1.1.0"
|
||||||
@@ -4019,6 +4044,12 @@ dependencies = [
|
|||||||
"winnow",
|
"winnow",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "toml_writer"
|
||||||
|
version = "1.1.1+spec-1.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "756daf9b1013ebe47a8776667b466417e2d4c5679d441c26230efd9ef78692db"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tracing"
|
name = "tracing"
|
||||||
version = "0.1.44"
|
version = "0.1.44"
|
||||||
@@ -5017,6 +5048,16 @@ dependencies = [
|
|||||||
"memchr",
|
"memchr",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "winresource"
|
||||||
|
version = "0.1.31"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0986a8b1d586b7d3e4fe3d9ea39fb451ae22869dcea4aa109d287a374d866087"
|
||||||
|
dependencies = [
|
||||||
|
"toml",
|
||||||
|
"version_check",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wit-bindgen"
|
name = "wit-bindgen"
|
||||||
version = "0.51.0"
|
version = "0.51.0"
|
||||||
|
|||||||
@@ -24,10 +24,11 @@ log = "0.4.29"
|
|||||||
tobj = "4.0.4"
|
tobj = "4.0.4"
|
||||||
gltf = "1.4.1"
|
gltf = "1.4.1"
|
||||||
|
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
anyhow = "1.0.102"
|
anyhow = "1.0.102"
|
||||||
fs_extra = "1.3.0"
|
fs_extra = "1.3.0"
|
||||||
|
winresource = "0.1.31"
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "ESkinPlayer"
|
name = "ESkinPlayer"
|
||||||
|
|||||||
8
build.rs
8
build.rs
@@ -27,6 +27,14 @@ fn main() -> Result<()> {
|
|||||||
copy_items(&items, &resource_dir, ©_options)?;
|
copy_items(&items, &resource_dir, ©_options)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if std::env::var("CARGO_CFG_TARGET_OS").as_deref() == Ok("windows") {
|
||||||
|
let mut resource = winresource::WindowsResource::new();
|
||||||
|
|
||||||
|
resource.set_icon("res/icon.ico");
|
||||||
|
|
||||||
|
resource.compile().expect("compile windows icon failed");
|
||||||
|
}
|
||||||
|
|
||||||
println!("cargo:rustc-env=RESOURCE_DIR={}", resource_dir.display());
|
println!("cargo:rustc-env=RESOURCE_DIR={}", resource_dir.display());
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
BIN
res/128x128@2x.png
Normal file
BIN
res/128x128@2x.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 28 KiB |
BIN
res/icon.ico
Normal file
BIN
res/icon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 41 KiB |
584
src/app.rs
584
src/app.rs
@@ -1,28 +1,40 @@
|
|||||||
use crate::breakout::{BreakoutGame, control_from_matrix};
|
use crate::breakout::{BreakoutGame, control_from_matrix};
|
||||||
use crate::connection::ConnectionManager;
|
use crate::connection::{ConnectionManager, ConnectionState};
|
||||||
use crate::force::{ForceEstimatorState, HudSpatialForce};
|
use crate::force::{ForceEstimatorState, HAND_FINGERTIP_COUNT, HudSpatialForce};
|
||||||
use crate::recording::Recorder;
|
use crate::recording::Recorder;
|
||||||
use crate::render::{ActiveMode, FingerMode, HandGatewayMode};
|
use crate::render::{ActiveMode, FingerMode, HandGatewayMode};
|
||||||
use crate::style::{self, ONE_DARK_PRO, apply_fonts, apply_theme, dim_text, layout};
|
use crate::style::{ONE_DARK_PRO, apply_fonts, apply_theme, layout};
|
||||||
use crate::ui::SerialMode;
|
use crate::ui::SerialMode;
|
||||||
use crate::{
|
use crate::{
|
||||||
matrix::{MATRIX_COLS, MATRIX_ROWS, UNFOLDED_SENSOR_SEGMENT_COUNTS},
|
matrix::{MATRIX_COLS, MATRIX_ROWS},
|
||||||
render::{
|
render::{
|
||||||
BackgroundRenderResources, PRESSURE_CELL_COUNT, PressureFrame, PressureSamples,
|
BackgroundRenderResources, PRESSURE_CELL_COUNT, PressureFrame, PressureSamples,
|
||||||
WgpuBackgroundCallback,
|
WgpuBackgroundCallback,
|
||||||
},
|
},
|
||||||
ui::{
|
ui::{
|
||||||
ConfigPanelState, ConnectPanelState, FloatingPanelState, MatrixConfigState,
|
ConfigPanelState, ConnectPanelState, FloatingPanelState, MatrixConfigState,
|
||||||
draw_config_panel, draw_export_panel, draw_hand_force_panels, draw_stats_panel,
|
draw_config_panel, draw_hand_force_panels, panel_restore_item,
|
||||||
panel_restore_item,
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use eframe::{egui, egui_wgpu};
|
use eframe::{egui, egui_wgpu};
|
||||||
use std::sync::Arc;
|
use std::{
|
||||||
|
sync::Arc,
|
||||||
|
time::{Duration, Instant},
|
||||||
|
};
|
||||||
|
|
||||||
const SUMMARY_POINTS_PER_SERIES: usize = 42;
|
const SUMMARY_POINTS_PER_SERIES: usize = 42;
|
||||||
const HAND_FORCE_PANEL_COUNT: usize = UNFOLDED_SENSOR_SEGMENT_COUNTS.len();
|
const HAND_FORCE_PANEL_COUNT: usize = 7;
|
||||||
const HAND_FORCE_SEGMENT_COUNTS: [usize; HAND_FORCE_PANEL_COUNT] = UNFOLDED_SENSOR_SEGMENT_COUNTS;
|
const HAND_FORCE_SEGMENT_COUNTS: [usize; HAND_FORCE_PANEL_COUNT] = [84, 84, 84, 84, 84, 70, 44];
|
||||||
|
const HAND_IMAGE_SIZE_PX: [f32; 2] = [971.0, 1117.0];
|
||||||
|
const HAND_FINGERTIP_FORCE_ANCHORS_PX: [[f32; 2]; HAND_FINGERTIP_COUNT] = [
|
||||||
|
[265.0, 495.0],
|
||||||
|
[359.0, 260.0],
|
||||||
|
[482.0, 228.0],
|
||||||
|
[596.0, 265.0],
|
||||||
|
[693.0, 370.0],
|
||||||
|
];
|
||||||
|
const RATE_UPDATE_INTERVAL: Duration = Duration::from_millis(500);
|
||||||
|
const DATA_IDLE_PANEL_EXIT_DELAY: Duration = Duration::from_secs(3);
|
||||||
|
|
||||||
pub struct EskinDesktopApp {
|
pub struct EskinDesktopApp {
|
||||||
connect_panel: FloatingPanelState,
|
connect_panel: FloatingPanelState,
|
||||||
@@ -44,16 +56,63 @@ pub struct EskinDesktopApp {
|
|||||||
hand_signal_histories: [Vec<f32>; HAND_FORCE_PANEL_COUNT],
|
hand_signal_histories: [Vec<f32>; HAND_FORCE_PANEL_COUNT],
|
||||||
force_estimator: ForceEstimatorState,
|
force_estimator: ForceEstimatorState,
|
||||||
latest_spatial_force: Option<HudSpatialForce>,
|
latest_spatial_force: Option<HudSpatialForce>,
|
||||||
|
latest_hand_spatial_forces: [Option<HudSpatialForce>; HAND_FINGERTIP_COUNT],
|
||||||
|
spatial_force_panel_force: Option<HudSpatialForce>,
|
||||||
latest_raw_matrix: Vec<u32>,
|
latest_raw_matrix: Vec<u32>,
|
||||||
latest_matrix_rows: u32,
|
latest_matrix_rows: u32,
|
||||||
latest_matrix_cols: u32,
|
latest_matrix_cols: u32,
|
||||||
|
last_sample_at: Option<Instant>,
|
||||||
breakout_visible: bool,
|
breakout_visible: bool,
|
||||||
breakout_game: BreakoutGame,
|
breakout_game: BreakoutGame,
|
||||||
|
live_rates: LiveRateMeters,
|
||||||
context_menu_open: bool,
|
context_menu_open: bool,
|
||||||
context_menu_pos: egui::Pos2,
|
context_menu_pos: egui::Pos2,
|
||||||
active_mode: ActiveMode,
|
active_mode: ActiveMode,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct LiveRateMeters {
|
||||||
|
window_started_at: Instant,
|
||||||
|
window_rx_frames: u64,
|
||||||
|
window_render_frames: u32,
|
||||||
|
sample_rate_hz: f32,
|
||||||
|
render_rate_hz: f32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl LiveRateMeters {
|
||||||
|
fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
window_started_at: Instant::now(),
|
||||||
|
window_rx_frames: 0,
|
||||||
|
window_render_frames: 0,
|
||||||
|
sample_rate_hz: 0.0,
|
||||||
|
render_rate_hz: 0.0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn tick_render(&mut self, total_rx_frames: u64) {
|
||||||
|
if total_rx_frames < self.window_rx_frames {
|
||||||
|
self.window_rx_frames = total_rx_frames;
|
||||||
|
self.sample_rate_hz = 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.window_render_frames = self.window_render_frames.saturating_add(1);
|
||||||
|
|
||||||
|
let now = Instant::now();
|
||||||
|
let elapsed = now.duration_since(self.window_started_at);
|
||||||
|
if elapsed < RATE_UPDATE_INTERVAL {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let seconds = elapsed.as_secs_f32().max(0.001);
|
||||||
|
let rx_delta = total_rx_frames.saturating_sub(self.window_rx_frames);
|
||||||
|
self.sample_rate_hz = rx_delta as f32 / seconds;
|
||||||
|
self.render_rate_hz = self.window_render_frames as f32 / seconds;
|
||||||
|
self.window_started_at = now;
|
||||||
|
self.window_rx_frames = total_rx_frames;
|
||||||
|
self.window_render_frames = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl EskinDesktopApp {
|
impl EskinDesktopApp {
|
||||||
pub fn new(cc: &eframe::CreationContext<'_>) -> Self {
|
pub fn new(cc: &eframe::CreationContext<'_>) -> Self {
|
||||||
egui_extras::install_image_loaders(&cc.egui_ctx);
|
egui_extras::install_image_loaders(&cc.egui_ctx);
|
||||||
@@ -110,19 +169,18 @@ impl EskinDesktopApp {
|
|||||||
hand_signal_histories: std::array::from_fn(|_| Vec::with_capacity(128)),
|
hand_signal_histories: std::array::from_fn(|_| Vec::with_capacity(128)),
|
||||||
force_estimator: ForceEstimatorState::new(),
|
force_estimator: ForceEstimatorState::new(),
|
||||||
latest_spatial_force: None,
|
latest_spatial_force: None,
|
||||||
|
latest_hand_spatial_forces: [None; HAND_FINGERTIP_COUNT],
|
||||||
|
spatial_force_panel_force: None,
|
||||||
latest_raw_matrix: Vec::new(),
|
latest_raw_matrix: Vec::new(),
|
||||||
latest_matrix_rows: MATRIX_ROWS,
|
latest_matrix_rows: MATRIX_ROWS,
|
||||||
latest_matrix_cols: MATRIX_COLS,
|
latest_matrix_cols: MATRIX_COLS,
|
||||||
|
last_sample_at: None,
|
||||||
breakout_visible: false,
|
breakout_visible: false,
|
||||||
breakout_game: BreakoutGame::default(),
|
breakout_game: BreakoutGame::default(),
|
||||||
|
live_rates: LiveRateMeters::new(),
|
||||||
context_menu_open: false,
|
context_menu_open: false,
|
||||||
context_menu_pos: egui::pos2(24.0, 48.0),
|
context_menu_pos: egui::pos2(24.0, 48.0),
|
||||||
active_mode: ActiveMode::Finger(FingerMode {
|
active_mode: ActiveMode::Hand(HandGatewayMode { range: 0..7000 }),
|
||||||
rows: 12,
|
|
||||||
cols: 7,
|
|
||||||
range: 0..7000,
|
|
||||||
dot: true,
|
|
||||||
}),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,40 +202,91 @@ impl EskinDesktopApp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn paint_spatial_force_overlay(&self, ui: &egui::Ui, rect: egui::Rect) {
|
fn paint_spatial_force_overlay(&self, ui: &egui::Ui, rect: egui::Rect) {
|
||||||
|
if !self.recent_sample_is_fresh() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if matches!(self.active_mode, ActiveMode::Hand(_)) {
|
||||||
|
self.paint_hand_spatial_force_overlay(ui, rect);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let Some(force) = self.latest_spatial_force else {
|
let Some(force) = self.latest_spatial_force else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
let painter = ui.painter();
|
|
||||||
let center = rect.center();
|
let center = rect.center();
|
||||||
let magnitude = force.magnitude.clamp(0.0, 1.8);
|
paint_spatial_force_arrow(ui.painter(), center, force, 34.0, 54.0);
|
||||||
let length = 34.0 + magnitude * 54.0;
|
}
|
||||||
let angle = force.angle_deg.to_radians();
|
|
||||||
let direction = egui::vec2(angle.cos(), angle.sin());
|
|
||||||
let end = center + direction * length;
|
|
||||||
let side = egui::vec2(-direction.y, direction.x);
|
|
||||||
let color = egui::Color32::from_rgb(255, 196, 54);
|
|
||||||
let glow = egui::Color32::from_rgba_unmultiplied(255, 196, 54, 58);
|
|
||||||
|
|
||||||
painter.line_segment([center, end], egui::Stroke::new(9.0_f32, glow));
|
fn paint_hand_spatial_force_overlay(&self, ui: &egui::Ui, rect: egui::Rect) {
|
||||||
painter.line_segment([center, end], egui::Stroke::new(2.4_f32, color));
|
for (force, anchor_px) in self
|
||||||
painter.line_segment(
|
.latest_hand_spatial_forces
|
||||||
[end, end - direction * 14.0 + side * 7.0],
|
.iter()
|
||||||
egui::Stroke::new(2.4_f32, color),
|
.zip(HAND_FINGERTIP_FORCE_ANCHORS_PX)
|
||||||
);
|
{
|
||||||
painter.line_segment(
|
let Some(force) = force else {
|
||||||
[end, end - direction * 14.0 - side * 7.0],
|
continue;
|
||||||
egui::Stroke::new(2.4_f32, color),
|
};
|
||||||
);
|
|
||||||
painter.circle_filled(center, 4.2, color);
|
let center = hand_image_pixel_to_screen(rect, anchor_px);
|
||||||
|
paint_spatial_force_arrow(ui.painter(), center, *force, 20.0, 34.0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn strongest_hand_spatial_force(&self) -> Option<HudSpatialForce> {
|
||||||
|
self.latest_hand_spatial_forces
|
||||||
|
.iter()
|
||||||
|
.flatten()
|
||||||
|
.copied()
|
||||||
|
.max_by(|a, b| a.magnitude.total_cmp(&b.magnitude))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn analyze_spatial_force(&mut self, values: &[u32]) {
|
||||||
|
if matches!(self.config_state.mode, SerialMode::Hand) {
|
||||||
|
self.latest_hand_spatial_forces = self.force_estimator.analyze_fingertips(values);
|
||||||
|
self.latest_spatial_force = self.strongest_hand_spatial_force();
|
||||||
|
} else {
|
||||||
|
self.latest_spatial_force = self.force_estimator.analyze(values);
|
||||||
|
self.latest_hand_spatial_forces = [None; HAND_FINGERTIP_COUNT];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn connection_has_live_data(&self) -> bool {
|
||||||
|
matches!(
|
||||||
|
self.connection.state(),
|
||||||
|
ConnectionState::Connected | ConnectionState::Streaming
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn recent_sample_is_fresh(&self) -> bool {
|
||||||
|
self.last_sample_at
|
||||||
|
.is_some_and(|sample_at| sample_at.elapsed() <= DATA_IDLE_PANEL_EXIT_DELAY)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn hand_force_panels_visible(&self) -> bool {
|
||||||
|
self.connection_has_live_data() && self.recent_sample_is_fresh()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn sync_disconnected_live_state(&mut self) {
|
||||||
|
if self.connection_has_live_data() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.last_sample_at = None;
|
||||||
|
self.latest_spatial_force = None;
|
||||||
|
self.latest_hand_spatial_forces = [None; HAND_FINGERTIP_COUNT];
|
||||||
|
self.spatial_force_panel_force = None;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw_workspace(&mut self, ui: &mut egui::Ui) {
|
fn draw_workspace(&mut self, ui: &mut egui::Ui) {
|
||||||
if self.breakout_visible {
|
let screen = ui.max_rect();
|
||||||
self.draw_split_workspace(ui);
|
let workspace = egui::Rect::from_min_max(
|
||||||
} else {
|
screen.left_top()
|
||||||
self.draw_wgpu_background_rect(ui, ui.max_rect());
|
+ egui::vec2(0.0, layout::TITLE_BAR_HEIGHT + layout::CONFIG_BAR_HEIGHT),
|
||||||
}
|
screen.right_bottom(),
|
||||||
|
);
|
||||||
|
self.draw_wgpu_background_rect(ui, workspace);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw_split_workspace(&mut self, ui: &mut egui::Ui) {
|
fn draw_split_workspace(&mut self, ui: &mut egui::Ui) {
|
||||||
@@ -218,12 +327,7 @@ impl EskinDesktopApp {
|
|||||||
|
|
||||||
fn update_pressure_matrix(&mut self) {
|
fn update_pressure_matrix(&mut self) {
|
||||||
if let Some(sample) = self.connection.take_latest_sample() {
|
if let Some(sample) = self.connection.take_latest_sample() {
|
||||||
if self.config_state.mode == SerialMode::Finger3D {
|
self.last_sample_at = Some(Instant::now());
|
||||||
eprintln!(
|
|
||||||
"[3d-rawdata] rows={} cols={} values={:?}",
|
|
||||||
sample.rows, sample.cols, sample.matrix
|
|
||||||
);
|
|
||||||
}
|
|
||||||
normalize_pressure_sample(
|
normalize_pressure_sample(
|
||||||
&sample.matrix,
|
&sample.matrix,
|
||||||
sample.rows,
|
sample.rows,
|
||||||
@@ -236,7 +340,7 @@ impl EskinDesktopApp {
|
|||||||
self.latest_matrix_rows = sample.rows;
|
self.latest_matrix_rows = sample.rows;
|
||||||
self.latest_matrix_cols = sample.cols;
|
self.latest_matrix_cols = sample.cols;
|
||||||
|
|
||||||
self.latest_spatial_force = self.force_estimator.analyze(&sample.matrix);
|
self.analyze_spatial_force(&sample.matrix);
|
||||||
|
|
||||||
// Keep JE-Skin's summary path separate from the optional spatial-force vector.
|
// Keep JE-Skin's summary path separate from the optional spatial-force vector.
|
||||||
let raw_total = sample
|
let raw_total = sample
|
||||||
@@ -250,6 +354,8 @@ impl EskinDesktopApp {
|
|||||||
if self.signal_history.len() > SUMMARY_POINTS_PER_SERIES {
|
if self.signal_history.len() > SUMMARY_POINTS_PER_SERIES {
|
||||||
self.signal_history.remove(0);
|
self.signal_history.remove(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
update_hand_signal_histories(&mut self.hand_signal_histories, &sample.matrix);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -267,7 +373,7 @@ impl EskinDesktopApp {
|
|||||||
);
|
);
|
||||||
ui.painter().line_segment(
|
ui.painter().line_segment(
|
||||||
[title_bar_rect.left_bottom(), title_bar_rect.right_bottom()],
|
[title_bar_rect.left_bottom(), title_bar_rect.right_bottom()],
|
||||||
egui::Stroke::new(1.0_f32, ONE_DARK_PRO.border),
|
egui::Stroke::new(1.0, ONE_DARK_PRO.border),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Drag-to-move: double-click to maximize, drag to move
|
// Drag-to-move: double-click to maximize, drag to move
|
||||||
@@ -308,14 +414,14 @@ impl EskinDesktopApp {
|
|||||||
btn_close_center + egui::vec2(-3.0, -3.0),
|
btn_close_center + egui::vec2(-3.0, -3.0),
|
||||||
btn_close_center + egui::vec2(3.0, 3.0),
|
btn_close_center + egui::vec2(3.0, 3.0),
|
||||||
],
|
],
|
||||||
egui::Stroke::new(1.5_f32, egui::Color32::from_rgb(80, 0, 0)),
|
egui::Stroke::new(1.5, egui::Color32::from_rgb(80, 0, 0)),
|
||||||
);
|
);
|
||||||
ui.painter().line_segment(
|
ui.painter().line_segment(
|
||||||
[
|
[
|
||||||
btn_close_center + egui::vec2(3.0, -3.0),
|
btn_close_center + egui::vec2(3.0, -3.0),
|
||||||
btn_close_center + egui::vec2(-3.0, 3.0),
|
btn_close_center + egui::vec2(-3.0, 3.0),
|
||||||
],
|
],
|
||||||
egui::Stroke::new(1.5_f32, egui::Color32::from_rgb(80, 0, 0)),
|
egui::Stroke::new(1.5, egui::Color32::from_rgb(80, 0, 0)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if close_resp.clicked() {
|
if close_resp.clicked() {
|
||||||
@@ -334,7 +440,7 @@ impl EskinDesktopApp {
|
|||||||
btn_min_center + egui::vec2(-3.0, 0.0),
|
btn_min_center + egui::vec2(-3.0, 0.0),
|
||||||
btn_min_center + egui::vec2(3.0, 0.0),
|
btn_min_center + egui::vec2(3.0, 0.0),
|
||||||
],
|
],
|
||||||
egui::Stroke::new(1.5_f32, egui::Color32::from_rgb(120, 80, 0)),
|
egui::Stroke::new(1.5, egui::Color32::from_rgb(120, 80, 0)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if min_resp.clicked() {
|
if min_resp.clicked() {
|
||||||
@@ -353,7 +459,7 @@ impl EskinDesktopApp {
|
|||||||
ui.painter().rect_stroke(
|
ui.painter().rect_stroke(
|
||||||
egui::Rect::from_center_size(btn_max_center, egui::vec2(s * 2.0, s * 2.0)),
|
egui::Rect::from_center_size(btn_max_center, egui::vec2(s * 2.0, s * 2.0)),
|
||||||
egui::CornerRadius::same(1),
|
egui::CornerRadius::same(1),
|
||||||
egui::Stroke::new(1.5_f32, egui::Color32::from_rgb(0, 80, 10)),
|
egui::Stroke::new(1.5, egui::Color32::from_rgb(0, 80, 10)),
|
||||||
egui::StrokeKind::Outside,
|
egui::StrokeKind::Outside,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -369,12 +475,11 @@ impl EskinDesktopApp {
|
|||||||
ctx: &egui::Context,
|
ctx: &egui::Context,
|
||||||
stats: crate::serial_core::serial::SerialIoStats,
|
stats: crate::serial_core::serial::SerialIoStats,
|
||||||
) {
|
) {
|
||||||
// draw_scene_panel(ctx, &mut self.scene_panel);
|
self.scene_panel.visible = false;
|
||||||
// if self.config_state.mode == SerialMode::Hand && self.stats_panel.visible {
|
self.connect_panel.visible = false;
|
||||||
// self.config_panel.visible = false;
|
self.export_panel.visible = false;
|
||||||
// self.export_panel.visible = false;
|
self.matrix_config_panel.visible = false;
|
||||||
// self.matrix_config_panel.visible = false;
|
self.context_menu_open = false;
|
||||||
// }
|
|
||||||
|
|
||||||
if let Some(next_mode) = draw_config_panel(
|
if let Some(next_mode) = draw_config_panel(
|
||||||
ctx,
|
ctx,
|
||||||
@@ -383,39 +488,18 @@ impl EskinDesktopApp {
|
|||||||
&self.connection,
|
&self.connection,
|
||||||
&self.recorder,
|
&self.recorder,
|
||||||
stats,
|
stats,
|
||||||
100.0,
|
self.live_rates.sample_rate_hz,
|
||||||
100.0,
|
self.live_rates.render_rate_hz,
|
||||||
) {
|
) {
|
||||||
self.switch_mode(next_mode);
|
self.switch_mode(next_mode);
|
||||||
}
|
}
|
||||||
match self.config_state.mode {
|
|
||||||
SerialMode::Finger => {
|
self.stats_panel.visible = false;
|
||||||
draw_stats_panel(
|
draw_hand_force_panels(
|
||||||
ctx,
|
|
||||||
&mut self.stats_panel,
|
|
||||||
&self.signal_history,
|
|
||||||
self.latest_spatial_force,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
SerialMode::Finger3D => {
|
|
||||||
draw_stats_panel(
|
|
||||||
ctx,
|
|
||||||
&mut self.stats_panel,
|
|
||||||
&self.signal_history,
|
|
||||||
self.latest_spatial_force,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
SerialMode::Hand => {
|
|
||||||
draw_hand_force_panels(ctx, self.stats_panel.visible, &self.hand_signal_histories);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
draw_export_panel(
|
|
||||||
ctx,
|
ctx,
|
||||||
&mut self.export_panel,
|
self.hand_force_panels_visible(),
|
||||||
&self.recorder,
|
&self.hand_signal_histories,
|
||||||
&mut self.export_path,
|
|
||||||
);
|
);
|
||||||
// draw_matrix_config_panel(ctx, &mut self.matrix_config_panel, &mut self.matrix_config);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw_panel_context_menu(&mut self, ctx: &egui::Context) {
|
fn draw_panel_context_menu(&mut self, ctx: &egui::Context) {
|
||||||
@@ -465,17 +549,6 @@ impl EskinDesktopApp {
|
|||||||
} else {
|
} else {
|
||||||
panel_restore_item(ui, "统计", &mut self.stats_panel);
|
panel_restore_item(ui, "统计", &mut self.stats_panel);
|
||||||
}
|
}
|
||||||
if ui
|
|
||||||
.add_sized(
|
|
||||||
egui::vec2(ui.available_width(), 0.0),
|
|
||||||
egui::Button::new("打砖块"),
|
|
||||||
)
|
|
||||||
.clicked()
|
|
||||||
{
|
|
||||||
self.breakout_visible = true;
|
|
||||||
close_menu = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
ui.separator();
|
ui.separator();
|
||||||
|
|
||||||
if ui
|
if ui
|
||||||
@@ -489,7 +562,6 @@ impl EskinDesktopApp {
|
|||||||
self.export_panel.visible = true;
|
self.export_panel.visible = true;
|
||||||
self.matrix_config_panel.visible = true;
|
self.matrix_config_panel.visible = true;
|
||||||
self.stats_panel.visible = true;
|
self.stats_panel.visible = true;
|
||||||
self.breakout_visible = true;
|
|
||||||
close_menu = true;
|
close_menu = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -508,23 +580,17 @@ impl EskinDesktopApp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn switch_mode(&mut self, next: SerialMode) {
|
fn switch_mode(&mut self, next: SerialMode) {
|
||||||
if next == SerialMode::Finger3D {
|
|
||||||
// The 3D fingertip PCB sends one 12x9 TactileA frame (108 cells).
|
|
||||||
self.matrix_config = MatrixConfigState {
|
|
||||||
rows: 12,
|
|
||||||
cols: 9,
|
|
||||||
color_min: 0.0,
|
|
||||||
color_max: 7000.0,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
self.connect_state.mode = next;
|
self.connect_state.mode = next;
|
||||||
self.config_state.mode = next;
|
self.config_state.mode = next;
|
||||||
self.config_state.baud_rate = next.baud_rate();
|
self.config_state.baud_rate = next.baud_rate();
|
||||||
self.connection.disconnect();
|
self.connection.disconnect();
|
||||||
self.pressure_matrix.fill([0.0, 0.0]);
|
self.pressure_matrix.fill([0.0, 0.0]);
|
||||||
self.hand_pressure.clear();
|
self.hand_pressure.clear();
|
||||||
|
self.last_sample_at = None;
|
||||||
self.force_estimator.reset();
|
self.force_estimator.reset();
|
||||||
self.latest_spatial_force = None;
|
self.latest_spatial_force = None;
|
||||||
|
self.latest_hand_spatial_forces = [None; HAND_FINGERTIP_COUNT];
|
||||||
|
self.spatial_force_panel_force = None;
|
||||||
self.signal_history.clear();
|
self.signal_history.clear();
|
||||||
self.hand_signal_histories
|
self.hand_signal_histories
|
||||||
.iter_mut()
|
.iter_mut()
|
||||||
@@ -537,26 +603,86 @@ impl EskinDesktopApp {
|
|||||||
range: 0..7000,
|
range: 0..7000,
|
||||||
dot: true,
|
dot: true,
|
||||||
}),
|
}),
|
||||||
SerialMode::Finger3D | SerialMode::Hand => {
|
SerialMode::Hand => ActiveMode::Hand(HandGatewayMode { range: 0..7000 }),
|
||||||
ActiveMode::Hand(HandGatewayMode { range: 0..7000 })
|
}
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn hand_image_pixel_to_screen(rect: egui::Rect, point_px: [f32; 2]) -> egui::Pos2 {
|
||||||
|
let image_uv = egui::vec2(
|
||||||
|
point_px[0] / HAND_IMAGE_SIZE_PX[0].max(1.0),
|
||||||
|
point_px[1] / HAND_IMAGE_SIZE_PX[1].max(1.0),
|
||||||
|
);
|
||||||
|
let viewport_aspect = rect.width() / rect.height().max(1.0);
|
||||||
|
let image_aspect = HAND_IMAGE_SIZE_PX[0] / HAND_IMAGE_SIZE_PX[1].max(1.0);
|
||||||
|
let mut screen_uv = image_uv;
|
||||||
|
|
||||||
|
if viewport_aspect > image_aspect {
|
||||||
|
let image_width = image_aspect / viewport_aspect;
|
||||||
|
screen_uv.x = image_uv.x * image_width + (1.0 - image_width) * 0.5;
|
||||||
|
} else {
|
||||||
|
let image_height = viewport_aspect / image_aspect;
|
||||||
|
screen_uv.y = image_uv.y * image_height + (1.0 - image_height) * 0.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
egui::pos2(
|
||||||
|
rect.left() + screen_uv.x * rect.width(),
|
||||||
|
rect.top() + screen_uv.y * rect.height(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn paint_spatial_force_arrow(
|
||||||
|
painter: &egui::Painter,
|
||||||
|
center: egui::Pos2,
|
||||||
|
force: HudSpatialForce,
|
||||||
|
base_length: f32,
|
||||||
|
magnitude_scale: f32,
|
||||||
|
) {
|
||||||
|
let magnitude = force.magnitude.clamp(0.0, 1.8);
|
||||||
|
let length = base_length + magnitude * magnitude_scale;
|
||||||
|
let angle = force.angle_deg.to_radians();
|
||||||
|
let direction = egui::vec2(angle.cos(), angle.sin());
|
||||||
|
let end = center + direction * length;
|
||||||
|
let side = egui::vec2(-direction.y, direction.x);
|
||||||
|
let head_length = (length * 0.24).clamp(8.0, 14.0);
|
||||||
|
let head_width = head_length * 0.5;
|
||||||
|
let color = egui::Color32::from_rgb(255, 196, 54);
|
||||||
|
let glow = egui::Color32::from_rgba_unmultiplied(255, 196, 54, 58);
|
||||||
|
|
||||||
|
painter.line_segment([center, end], egui::Stroke::new(8.0, glow));
|
||||||
|
painter.line_segment([center, end], egui::Stroke::new(2.4, color));
|
||||||
|
painter.line_segment(
|
||||||
|
[end, end - direction * head_length + side * head_width],
|
||||||
|
egui::Stroke::new(2.4, color),
|
||||||
|
);
|
||||||
|
painter.line_segment(
|
||||||
|
[end, end - direction * head_length - side * head_width],
|
||||||
|
egui::Stroke::new(2.4, color),
|
||||||
|
);
|
||||||
|
painter.circle_filled(center, 3.8, color);
|
||||||
|
}
|
||||||
|
|
||||||
fn update_hand_signal_histories(
|
fn update_hand_signal_histories(
|
||||||
histories: &mut [Vec<f32>; HAND_FORCE_PANEL_COUNT],
|
histories: &mut [Vec<f32>; HAND_FORCE_PANEL_COUNT],
|
||||||
raw_values: &[u32],
|
raw_values: &[u32],
|
||||||
) {
|
) {
|
||||||
let mut offset = 0usize;
|
let mut offset = 0usize;
|
||||||
for (history, sample_count) in histories.iter_mut().zip(HAND_FORCE_SEGMENT_COUNTS) {
|
for (index, (history, sample_count)) in histories.iter_mut().zip(HAND_FORCE_SEGMENT_COUNTS).enumerate() {
|
||||||
let raw_total = raw_values
|
let raw_total = raw_values
|
||||||
.get(offset..offset + sample_count)
|
.get(offset..offset + sample_count)
|
||||||
.unwrap_or(&[])
|
.unwrap_or(&[])
|
||||||
.iter()
|
.iter()
|
||||||
.fold(0_u64, |sum, value| sum + *value as u64)
|
.fold(0_u64, |sum, value| sum + *value as u64)
|
||||||
.min(u32::MAX as u64) as u32;
|
.min(u32::MAX as u64) as u32;
|
||||||
let force = raw_to_g1(raw_total).min(25.6);
|
let force = match index {
|
||||||
|
0 => raw_to_g1(raw_total).min(20.6),
|
||||||
|
1 => raw_to_g2(raw_total).min(20.6),
|
||||||
|
2 => raw_to_g3(raw_total).min(20.6),
|
||||||
|
3 => raw_to_g4(raw_total).min(20.6),
|
||||||
|
4 => raw_to_g5(raw_total).min(20.6),
|
||||||
|
_ => raw_to_gd(raw_total).min(20.6),
|
||||||
|
};
|
||||||
|
// let force = raw_to_g1(raw_total).min(25.6);
|
||||||
let force = if force <= 0.1 { 0.0 } else { force };
|
let force = if force <= 0.1 { 0.0 } else { force };
|
||||||
|
|
||||||
history.push(force);
|
history.push(force);
|
||||||
@@ -568,7 +694,7 @@ fn update_hand_signal_histories(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn raw_to_g1(raw: u32) -> f32 {
|
fn raw_to_gd(raw: u32) -> f32 {
|
||||||
const RAW: [u32; 12] = [
|
const RAW: [u32; 12] = [
|
||||||
0, 21382, 108507, 123183, 147405, 171105, 192395, 250443, 231423, 350560, 396616, 429444,
|
0, 21382, 108507, 123183, 147405, 171105, 192395, 250443, 231423, 350560, 396616, 429444,
|
||||||
];
|
];
|
||||||
@@ -603,6 +729,181 @@ fn raw_to_g1(raw: u32) -> f32 {
|
|||||||
(FORCE_CENTI_N[left] + ratio * (FORCE_CENTI_N[right] - FORCE_CENTI_N[left])) / 100.0
|
(FORCE_CENTI_N[left] + ratio * (FORCE_CENTI_N[right] - FORCE_CENTI_N[left])) / 100.0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn raw_to_g1(raw: u32) -> f32 {
|
||||||
|
const RAW: [u32; 11] = [
|
||||||
|
0, 20239, 121454, 171532, 223968, 241467, 293500, 322744, 436294, 523275, 633083,
|
||||||
|
];
|
||||||
|
const FORCE_CENTI_N: [f32; 11] = [
|
||||||
|
0.0, 57.0, 257.0, 357.0, 457.0, 557.0, 657.0, 857.0, 1057.0, 1557.0, 2057.0,
|
||||||
|
];
|
||||||
|
|
||||||
|
if raw <= RAW[0] {
|
||||||
|
return FORCE_CENTI_N[0] / 100.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if raw >= RAW[RAW.len() - 1] {
|
||||||
|
return FORCE_CENTI_N[FORCE_CENTI_N.len() - 1] / 100.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut left = 0usize;
|
||||||
|
let mut right = RAW.len() - 1;
|
||||||
|
while left + 1 < right {
|
||||||
|
let mid = (left + right) / 2;
|
||||||
|
if RAW[mid] <= raw {
|
||||||
|
left = mid;
|
||||||
|
} else {
|
||||||
|
right = mid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let raw_left = RAW[left] as f32;
|
||||||
|
let raw_right = RAW[right] as f32;
|
||||||
|
let span = (raw_right - raw_left).max(1.0);
|
||||||
|
let ratio = (raw as f32 - raw_left) / span;
|
||||||
|
|
||||||
|
(FORCE_CENTI_N[left] + ratio * (FORCE_CENTI_N[right] - FORCE_CENTI_N[left])) / 100.0
|
||||||
|
}
|
||||||
|
|
||||||
|
fn raw_to_g2(raw: u32) -> f32 {
|
||||||
|
const RAW: [u32; 11] = [
|
||||||
|
0, 5398, 52896, 86945, 122546, 145001, 165933, 220575, 241578, 350285, 449530,
|
||||||
|
];
|
||||||
|
const FORCE_CENTI_N: [f32; 11] = [
|
||||||
|
0.0, 57.0, 257.0, 357.0, 457.0, 557.0, 657.0, 857.0, 1057.0, 1557.0, 2057.0,
|
||||||
|
];
|
||||||
|
|
||||||
|
if raw <= RAW[0] {
|
||||||
|
return FORCE_CENTI_N[0] / 100.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if raw >= RAW[RAW.len() - 1] {
|
||||||
|
return FORCE_CENTI_N[FORCE_CENTI_N.len() - 1] / 100.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut left = 0usize;
|
||||||
|
let mut right = RAW.len() - 1;
|
||||||
|
while left + 1 < right {
|
||||||
|
let mid = (left + right) / 2;
|
||||||
|
if RAW[mid] <= raw {
|
||||||
|
left = mid;
|
||||||
|
} else {
|
||||||
|
right = mid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let raw_left = RAW[left] as f32;
|
||||||
|
let raw_right = RAW[right] as f32;
|
||||||
|
let span = (raw_right - raw_left).max(1.0);
|
||||||
|
let ratio = (raw as f32 - raw_left) / span;
|
||||||
|
|
||||||
|
(FORCE_CENTI_N[left] + ratio * (FORCE_CENTI_N[right] - FORCE_CENTI_N[left])) / 100.0
|
||||||
|
}
|
||||||
|
|
||||||
|
fn raw_to_g3(raw: u32) -> f32 {
|
||||||
|
const RAW: [u32; 11] = [
|
||||||
|
0, 4920, 35945, 46499, 65566, 69613, 89971, 122321, 146384, 203426, 269474,
|
||||||
|
];
|
||||||
|
const FORCE_CENTI_N: [f32; 11] = [
|
||||||
|
0.0, 57.0, 257.0, 357.0, 457.0, 557.0, 657.0, 857.0, 1057.0, 1557.0, 2057.0,
|
||||||
|
];
|
||||||
|
|
||||||
|
if raw <= RAW[0] {
|
||||||
|
return FORCE_CENTI_N[0] / 100.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if raw >= RAW[RAW.len() - 1] {
|
||||||
|
return FORCE_CENTI_N[FORCE_CENTI_N.len() - 1] / 100.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut left = 0usize;
|
||||||
|
let mut right = RAW.len() - 1;
|
||||||
|
while left + 1 < right {
|
||||||
|
let mid = (left + right) / 2;
|
||||||
|
if RAW[mid] <= raw {
|
||||||
|
left = mid;
|
||||||
|
} else {
|
||||||
|
right = mid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let raw_left = RAW[left] as f32;
|
||||||
|
let raw_right = RAW[right] as f32;
|
||||||
|
let span = (raw_right - raw_left).max(1.0);
|
||||||
|
let ratio = (raw as f32 - raw_left) / span;
|
||||||
|
|
||||||
|
(FORCE_CENTI_N[left] + ratio * (FORCE_CENTI_N[right] - FORCE_CENTI_N[left])) / 100.0
|
||||||
|
}
|
||||||
|
|
||||||
|
fn raw_to_g4(raw: u32) -> f32 {
|
||||||
|
const RAW: [u32; 11] = [
|
||||||
|
0, 11346, 92229, 139822, 182282, 220004, 259898, 307303, 377922, 460755, 587834,
|
||||||
|
];
|
||||||
|
const FORCE_CENTI_N: [f32; 11] = [
|
||||||
|
0.0, 57.0, 257.0, 357.0, 457.0, 557.0, 657.0, 857.0, 1057.0, 1557.0, 2057.0,
|
||||||
|
];
|
||||||
|
|
||||||
|
if raw <= RAW[0] {
|
||||||
|
return FORCE_CENTI_N[0] / 100.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if raw >= RAW[RAW.len() - 1] {
|
||||||
|
return FORCE_CENTI_N[FORCE_CENTI_N.len() - 1] / 100.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut left = 0usize;
|
||||||
|
let mut right = RAW.len() - 1;
|
||||||
|
while left + 1 < right {
|
||||||
|
let mid = (left + right) / 2;
|
||||||
|
if RAW[mid] <= raw {
|
||||||
|
left = mid;
|
||||||
|
} else {
|
||||||
|
right = mid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let raw_left = RAW[left] as f32;
|
||||||
|
let raw_right = RAW[right] as f32;
|
||||||
|
let span = (raw_right - raw_left).max(1.0);
|
||||||
|
let ratio = (raw as f32 - raw_left) / span;
|
||||||
|
|
||||||
|
(FORCE_CENTI_N[left] + ratio * (FORCE_CENTI_N[right] - FORCE_CENTI_N[left])) / 100.0
|
||||||
|
}
|
||||||
|
|
||||||
|
fn raw_to_g5(raw: u32) -> f32 {
|
||||||
|
const RAW: [u32; 11] = [
|
||||||
|
0, 10081, 40910, 49944, 64291, 68299, 79282, 97767, 113567, 140520, 167132,
|
||||||
|
];
|
||||||
|
const FORCE_CENTI_N: [f32; 11] = [
|
||||||
|
0.0, 57.0, 257.0, 357.0, 457.0, 557.0, 657.0, 857.0, 1057.0, 1557.0, 2057.0,
|
||||||
|
];
|
||||||
|
|
||||||
|
if raw <= RAW[0] {
|
||||||
|
return FORCE_CENTI_N[0] / 100.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if raw >= RAW[RAW.len() - 1] {
|
||||||
|
return FORCE_CENTI_N[FORCE_CENTI_N.len() - 1] / 100.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut left = 0usize;
|
||||||
|
let mut right = RAW.len() - 1;
|
||||||
|
while left + 1 < right {
|
||||||
|
let mid = (left + right) / 2;
|
||||||
|
if RAW[mid] <= raw {
|
||||||
|
left = mid;
|
||||||
|
} else {
|
||||||
|
right = mid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let raw_left = RAW[left] as f32;
|
||||||
|
let raw_right = RAW[right] as f32;
|
||||||
|
let span = (raw_right - raw_left).max(1.0);
|
||||||
|
let ratio = (raw as f32 - raw_left) / span;
|
||||||
|
|
||||||
|
(FORCE_CENTI_N[left] + ratio * (FORCE_CENTI_N[right] - FORCE_CENTI_N[left])) / 100.0
|
||||||
|
}
|
||||||
|
|
||||||
fn paint_split_viewport_shell(
|
fn paint_split_viewport_shell(
|
||||||
ui: &egui::Ui,
|
ui: &egui::Ui,
|
||||||
rect: egui::Rect,
|
rect: egui::Rect,
|
||||||
@@ -618,7 +919,7 @@ fn paint_split_viewport_shell(
|
|||||||
painter.rect_stroke(
|
painter.rect_stroke(
|
||||||
rect,
|
rect,
|
||||||
egui::CornerRadius::same(8),
|
egui::CornerRadius::same(8),
|
||||||
egui::Stroke::new(1.0_f32, ONE_DARK_PRO.border_soft),
|
egui::Stroke::new(1.0, ONE_DARK_PRO.border_soft),
|
||||||
egui::StrokeKind::Outside,
|
egui::StrokeKind::Outside,
|
||||||
);
|
);
|
||||||
painter.line_segment(
|
painter.line_segment(
|
||||||
@@ -626,7 +927,7 @@ fn paint_split_viewport_shell(
|
|||||||
rect.left_top() + egui::vec2(12.0, 34.0),
|
rect.left_top() + egui::vec2(12.0, 34.0),
|
||||||
rect.right_top() + egui::vec2(-12.0, 34.0),
|
rect.right_top() + egui::vec2(-12.0, 34.0),
|
||||||
],
|
],
|
||||||
egui::Stroke::new(1.0_f32, ONE_DARK_PRO.border_soft),
|
egui::Stroke::new(1.0, ONE_DARK_PRO.border_soft),
|
||||||
);
|
);
|
||||||
painter.text(
|
painter.text(
|
||||||
rect.left_top() + egui::vec2(14.0, 16.0),
|
rect.left_top() + egui::vec2(14.0, 16.0),
|
||||||
@@ -676,44 +977,44 @@ fn normalize_pressure_samples(raw: &[u32]) -> PressureSamples {
|
|||||||
fn normalize_pressure_value(value: u32) -> [f32; 2] {
|
fn normalize_pressure_value(value: u32) -> [f32; 2] {
|
||||||
const RANGE_MIN: f32 = 0.0;
|
const RANGE_MIN: f32 = 0.0;
|
||||||
const RANGE_MAX: f32 = 7000.0;
|
const RANGE_MAX: f32 = 7000.0;
|
||||||
|
const DISPLAY_GAMMA: f32 = 0.45;
|
||||||
|
|
||||||
let raw_value = value as f32;
|
let raw_value = value as f32;
|
||||||
let mapped = ((raw_value - RANGE_MIN) / (RANGE_MAX - RANGE_MIN)).clamp(0.0, 1.0);
|
let mapped = ((raw_value - RANGE_MIN) / (RANGE_MAX - RANGE_MIN)).clamp(0.0, 1.0);
|
||||||
|
let intensity = if raw_value <= RANGE_MIN + 4.0 {
|
||||||
|
0.0
|
||||||
|
} else {
|
||||||
|
mapped.powf(DISPLAY_GAMMA)
|
||||||
|
};
|
||||||
let display_value = if raw_value <= RANGE_MIN + 4.0 {
|
let display_value = if raw_value <= RANGE_MIN + 4.0 {
|
||||||
0.0
|
0.0
|
||||||
} else {
|
} else {
|
||||||
raw_value.round().min(9999.0)
|
raw_value.round().min(9999.0)
|
||||||
};
|
};
|
||||||
|
|
||||||
[mapped, display_value]
|
[intensity, display_value]
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw_config_bar_mode(ui: &mut egui::Ui, config: &mut ConfigPanelState) -> Option<SerialMode> {
|
#[cfg(test)]
|
||||||
let mut changed_to = None;
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
ui.horizontal(|ui| {
|
#[test]
|
||||||
ui.colored_label(dim_text(), "单面指尖");
|
fn pressure_normalization_makes_low_hand_values_visible() {
|
||||||
if mode_button(ui, &mut config.mode, SerialMode::Finger, "单面指尖") {
|
let [zero_intensity, zero_label] = normalize_pressure_value(4);
|
||||||
changed_to = Some(SerialMode::Finger);
|
assert_eq!(zero_intensity, 0.0);
|
||||||
}
|
assert_eq!(zero_label, 0.0);
|
||||||
});
|
|
||||||
|
|
||||||
changed_to
|
let [low_intensity, low_label] = normalize_pressure_value(100);
|
||||||
}
|
assert!(
|
||||||
|
low_intensity > 0.10,
|
||||||
|
"low hand-gateway values should be visible in the wgpu dot matrix"
|
||||||
|
);
|
||||||
|
assert_eq!(low_label, 100.0);
|
||||||
|
|
||||||
fn mode_button(
|
let [max_intensity, max_label] = normalize_pressure_value(7000);
|
||||||
ui: &mut egui::Ui,
|
assert_eq!(max_intensity, 1.0);
|
||||||
mode: &mut SerialMode,
|
assert_eq!(max_label, 7000.0);
|
||||||
value: SerialMode,
|
|
||||||
label: &'static str,
|
|
||||||
) -> bool {
|
|
||||||
let clicked = ui.add(style::mode_button(label, *mode == value)).clicked();
|
|
||||||
|
|
||||||
if clicked && *mode != value {
|
|
||||||
*mode = value;
|
|
||||||
true
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -721,12 +1022,13 @@ impl eframe::App for EskinDesktopApp {
|
|||||||
fn ui(&mut self, ui: &mut egui::Ui, frame: &mut eframe::Frame) {
|
fn ui(&mut self, ui: &mut egui::Ui, frame: &mut eframe::Frame) {
|
||||||
let ctx = ui.ctx().clone();
|
let ctx = ui.ctx().clone();
|
||||||
let stats = self.connection.stats();
|
let stats = self.connection.stats();
|
||||||
|
self.live_rates.tick_render(stats.rx_frames);
|
||||||
|
|
||||||
self.update_pressure_matrix();
|
self.update_pressure_matrix();
|
||||||
|
self.sync_disconnected_live_state();
|
||||||
self.draw_workspace(ui);
|
self.draw_workspace(ui);
|
||||||
self.draw_title_bar(ui, frame);
|
self.draw_title_bar(ui, frame);
|
||||||
self.draw_floating_panels(&ctx, stats);
|
self.draw_floating_panels(&ctx, stats);
|
||||||
self.draw_panel_context_menu(&ctx);
|
|
||||||
|
|
||||||
// Keep repainting while the wgpu background is a realtime viewport.
|
// Keep repainting while the wgpu background is a realtime viewport.
|
||||||
ctx.request_repaint();
|
ctx.request_repaint();
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ enum BreakoutPhase {
|
|||||||
Idle,
|
Idle,
|
||||||
Running,
|
Running,
|
||||||
Paused,
|
Paused,
|
||||||
|
Won,
|
||||||
Over,
|
Over,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,7 +47,6 @@ pub struct BreakoutGame {
|
|||||||
score: u32,
|
score: u32,
|
||||||
combo: u32,
|
combo: u32,
|
||||||
lives: u32,
|
lives: u32,
|
||||||
level: u32,
|
|
||||||
last_time: Option<f64>,
|
last_time: Option<f64>,
|
||||||
previous_pause_gesture: bool,
|
previous_pause_gesture: bool,
|
||||||
pause_locked_until: f64,
|
pause_locked_until: f64,
|
||||||
@@ -63,7 +63,6 @@ impl Default for BreakoutGame {
|
|||||||
score: 0,
|
score: 0,
|
||||||
combo: 0,
|
combo: 0,
|
||||||
lives: 3,
|
lives: 3,
|
||||||
level: 1,
|
|
||||||
last_time: None,
|
last_time: None,
|
||||||
previous_pause_gesture: false,
|
previous_pause_gesture: false,
|
||||||
pause_locked_until: 0.0,
|
pause_locked_until: 0.0,
|
||||||
@@ -150,7 +149,6 @@ impl BreakoutGame {
|
|||||||
status_chip(ui, "分数", self.score.to_string(), ACCENT_GREEN);
|
status_chip(ui, "分数", self.score.to_string(), ACCENT_GREEN);
|
||||||
status_chip(ui, "连击", self.combo.to_string(), ACCENT_ORANGE);
|
status_chip(ui, "连击", self.combo.to_string(), ACCENT_ORANGE);
|
||||||
status_chip(ui, "生命", self.lives.to_string(), ACCENT_RED);
|
status_chip(ui, "生命", self.lives.to_string(), ACCENT_RED);
|
||||||
status_chip(ui, "关卡", self.level.to_string(), ACCENT_BLUE);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
ui.add_space(7.0);
|
ui.add_space(7.0);
|
||||||
@@ -191,12 +189,11 @@ impl BreakoutGame {
|
|||||||
self.score = 0;
|
self.score = 0;
|
||||||
self.combo = 0;
|
self.combo = 0;
|
||||||
self.lives = 3;
|
self.lives = 3;
|
||||||
self.level = 1;
|
|
||||||
self.rebuild_bricks();
|
self.rebuild_bricks();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn start(&mut self) {
|
fn start(&mut self) {
|
||||||
if self.phase == BreakoutPhase::Over {
|
if self.phase == BreakoutPhase::Over || self.phase == BreakoutPhase::Won {
|
||||||
self.reset();
|
self.reset();
|
||||||
}
|
}
|
||||||
if self.phase != BreakoutPhase::Running {
|
if self.phase != BreakoutPhase::Running {
|
||||||
@@ -219,7 +216,10 @@ impl BreakoutGame {
|
|||||||
let threshold = pressure_pause_threshold();
|
let threshold = pressure_pause_threshold();
|
||||||
let active = top_force >= threshold;
|
let active = top_force >= threshold;
|
||||||
if active && !self.previous_pause_gesture && now >= self.pause_locked_until {
|
if active && !self.previous_pause_gesture && now >= self.pause_locked_until {
|
||||||
if self.phase == BreakoutPhase::Idle || self.phase == BreakoutPhase::Over {
|
if matches!(
|
||||||
|
self.phase,
|
||||||
|
BreakoutPhase::Idle | BreakoutPhase::Over | BreakoutPhase::Won
|
||||||
|
) {
|
||||||
self.start();
|
self.start();
|
||||||
} else {
|
} else {
|
||||||
self.toggle_pause();
|
self.toggle_pause();
|
||||||
@@ -249,11 +249,7 @@ impl BreakoutGame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn launch_ball(&mut self) {
|
fn launch_ball(&mut self) {
|
||||||
let direction = if self.level.is_multiple_of(2) {
|
let direction = 0.24;
|
||||||
-0.24
|
|
||||||
} else {
|
|
||||||
0.24
|
|
||||||
};
|
|
||||||
self.ball_pos = egui::pos2(self.paddle_x, PADDLE_Y - PADDLE_H - BALL_RADIUS);
|
self.ball_pos = egui::pos2(self.paddle_x, PADDLE_Y - PADDLE_H - BALL_RADIUS);
|
||||||
self.ball_vel = egui::vec2(direction, -1.0).normalized() * BALL_SPEED;
|
self.ball_vel = egui::vec2(direction, -1.0).normalized() * BALL_SPEED;
|
||||||
}
|
}
|
||||||
@@ -328,9 +324,8 @@ impl BreakoutGame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if self.bricks.iter().all(|brick| !brick.alive) {
|
if self.bricks.iter().all(|brick| !brick.alive) {
|
||||||
self.level += 1;
|
self.phase = BreakoutPhase::Won;
|
||||||
self.rebuild_bricks();
|
self.ball_vel = egui::Vec2::ZERO;
|
||||||
self.launch_ball();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -362,6 +357,7 @@ impl BreakoutGame {
|
|||||||
BreakoutPhase::Idle => "待机",
|
BreakoutPhase::Idle => "待机",
|
||||||
BreakoutPhase::Running => "运行",
|
BreakoutPhase::Running => "运行",
|
||||||
BreakoutPhase::Paused => "暂停",
|
BreakoutPhase::Paused => "暂停",
|
||||||
|
BreakoutPhase::Won => "过关",
|
||||||
BreakoutPhase::Over => "结束",
|
BreakoutPhase::Over => "结束",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -376,7 +372,7 @@ impl BreakoutGame {
|
|||||||
painter.rect_stroke(
|
painter.rect_stroke(
|
||||||
rect,
|
rect,
|
||||||
egui::CornerRadius::same(6),
|
egui::CornerRadius::same(6),
|
||||||
egui::Stroke::new(1.0_f32, color_alpha(ONE_DARK_PRO.accent, 110)),
|
egui::Stroke::new(1.0, color_alpha(ONE_DARK_PRO.accent, 110)),
|
||||||
egui::StrokeKind::Outside,
|
egui::StrokeKind::Outside,
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -391,6 +387,7 @@ impl BreakoutGame {
|
|||||||
|
|
||||||
if self.phase == BreakoutPhase::Idle
|
if self.phase == BreakoutPhase::Idle
|
||||||
|| self.phase == BreakoutPhase::Paused
|
|| self.phase == BreakoutPhase::Paused
|
||||||
|
|| self.phase == BreakoutPhase::Won
|
||||||
|| self.phase == BreakoutPhase::Over
|
|| self.phase == BreakoutPhase::Over
|
||||||
{
|
{
|
||||||
paint_center_overlay(&painter, rect, self.phase);
|
paint_center_overlay(&painter, rect, self.phase);
|
||||||
@@ -407,6 +404,10 @@ pub fn control_from_matrix(raw: &[u32], rows: u32, cols: u32) -> BreakoutControl
|
|||||||
let cols = cols.max(1) as usize;
|
let cols = cols.max(1) as usize;
|
||||||
let sample_rows = rows.min(2);
|
let sample_rows = rows.min(2);
|
||||||
let sample_cols = cols.min(2);
|
let sample_cols = cols.min(2);
|
||||||
|
let top_gesture_rows = rows.min(1);
|
||||||
|
let top_gesture_cols = (cols / 3).clamp(1, cols);
|
||||||
|
let top_gesture_col_start = (cols - top_gesture_cols) / 2;
|
||||||
|
let top_gesture_col_end = top_gesture_col_start + top_gesture_cols;
|
||||||
let avg = |row_start: usize, row_end: usize, col_start: usize, col_end: usize| -> f32 {
|
let avg = |row_start: usize, row_end: usize, col_start: usize, col_end: usize| -> f32 {
|
||||||
let mut sum = 0.0;
|
let mut sum = 0.0;
|
||||||
let mut count = 0.0;
|
let mut count = 0.0;
|
||||||
@@ -434,7 +435,12 @@ pub fn control_from_matrix(raw: &[u32], rows: u32, cols: u32) -> BreakoutControl
|
|||||||
|
|
||||||
let left_force = tl + bl;
|
let left_force = tl + bl;
|
||||||
let right_force = tr + br;
|
let right_force = tr + br;
|
||||||
let top_force = tl + tr;
|
let top_force = avg(
|
||||||
|
0,
|
||||||
|
top_gesture_rows,
|
||||||
|
top_gesture_col_start,
|
||||||
|
top_gesture_col_end,
|
||||||
|
);
|
||||||
let span = 1200.0_f32.max((PRESSURE_RANGE_MAX - PRESSURE_RANGE_MIN) * 0.22);
|
let span = 1200.0_f32.max((PRESSURE_RANGE_MAX - PRESSURE_RANGE_MIN) * 0.22);
|
||||||
let raw_axis = ((right_force - left_force) / span).clamp(-1.0, 1.0);
|
let raw_axis = ((right_force - left_force) / span).clamp(-1.0, 1.0);
|
||||||
let axis = if raw_axis.abs() < 0.045 {
|
let axis = if raw_axis.abs() < 0.045 {
|
||||||
@@ -473,7 +479,7 @@ fn circle_hits_rect(center: egui::Pos2, radius: f32, rect: egui::Rect) -> bool {
|
|||||||
fn status_chip(ui: &mut egui::Ui, label: &'static str, value: impl ToString, color: egui::Color32) {
|
fn status_chip(ui: &mut egui::Ui, label: &'static str, value: impl ToString, color: egui::Color32) {
|
||||||
egui::Frame::new()
|
egui::Frame::new()
|
||||||
.fill(color_alpha(ONE_DARK_PRO.panel_deep, 190))
|
.fill(color_alpha(ONE_DARK_PRO.panel_deep, 190))
|
||||||
.stroke(egui::Stroke::new(1.0_f32, color_alpha(color, 92)))
|
.stroke(egui::Stroke::new(1.0, color_alpha(color, 92)))
|
||||||
.corner_radius(egui::CornerRadius::same(4))
|
.corner_radius(egui::CornerRadius::same(4))
|
||||||
.inner_margin(egui::Margin::symmetric(8, 4))
|
.inner_margin(egui::Margin::symmetric(8, 4))
|
||||||
.show(ui, |ui| {
|
.show(ui, |ui| {
|
||||||
@@ -489,6 +495,7 @@ fn status_color(phase: BreakoutPhase) -> egui::Color32 {
|
|||||||
BreakoutPhase::Idle => ONE_DARK_PRO.text_dim,
|
BreakoutPhase::Idle => ONE_DARK_PRO.text_dim,
|
||||||
BreakoutPhase::Running => ACCENT_GREEN,
|
BreakoutPhase::Running => ACCENT_GREEN,
|
||||||
BreakoutPhase::Paused => ACCENT_ORANGE,
|
BreakoutPhase::Paused => ACCENT_ORANGE,
|
||||||
|
BreakoutPhase::Won => ACCENT_GREEN,
|
||||||
BreakoutPhase::Over => ACCENT_RED,
|
BreakoutPhase::Over => ACCENT_RED,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -518,7 +525,7 @@ fn paint_arena_grid(painter: &egui::Painter, rect: egui::Rect) {
|
|||||||
painter.rect_stroke(
|
painter.rect_stroke(
|
||||||
rect,
|
rect,
|
||||||
egui::CornerRadius::same(6),
|
egui::CornerRadius::same(6),
|
||||||
egui::Stroke::new(1.0_f32, color_alpha(ONE_DARK_PRO.accent, 70)),
|
egui::Stroke::new(1.0, color_alpha(ONE_DARK_PRO.accent, 70)),
|
||||||
egui::StrokeKind::Inside,
|
egui::StrokeKind::Inside,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -535,7 +542,7 @@ fn paint_brick(painter: &egui::Painter, arena: egui::Rect, brick: &Brick, index:
|
|||||||
painter.rect_stroke(
|
painter.rect_stroke(
|
||||||
rect.expand(4.0 * brick.flash),
|
rect.expand(4.0 * brick.flash),
|
||||||
egui::CornerRadius::same(4),
|
egui::CornerRadius::same(4),
|
||||||
egui::Stroke::new(1.4_f32, color_alpha(ONE_DARK_PRO.accent_hot, alpha)),
|
egui::Stroke::new(1.4, color_alpha(ONE_DARK_PRO.accent_hot, alpha)),
|
||||||
egui::StrokeKind::Outside,
|
egui::StrokeKind::Outside,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -568,7 +575,7 @@ fn paint_control_meter(painter: &egui::Painter, arena: egui::Rect, control: Brea
|
|||||||
painter.rect_stroke(
|
painter.rect_stroke(
|
||||||
meter,
|
meter,
|
||||||
egui::CornerRadius::same(4),
|
egui::CornerRadius::same(4),
|
||||||
egui::Stroke::new(1.0_f32, color_alpha(ONE_DARK_PRO.border, 120)),
|
egui::Stroke::new(1.0, color_alpha(ONE_DARK_PRO.border, 120)),
|
||||||
egui::StrokeKind::Outside,
|
egui::StrokeKind::Outside,
|
||||||
);
|
);
|
||||||
let center_x = meter.center().x;
|
let center_x = meter.center().x;
|
||||||
@@ -577,7 +584,7 @@ fn paint_control_meter(painter: &egui::Painter, arena: egui::Rect, control: Brea
|
|||||||
egui::pos2(center_x, meter.top()),
|
egui::pos2(center_x, meter.top()),
|
||||||
egui::pos2(center_x, meter.bottom()),
|
egui::pos2(center_x, meter.bottom()),
|
||||||
],
|
],
|
||||||
egui::Stroke::new(1.0_f32, ONE_DARK_PRO.border_soft),
|
egui::Stroke::new(1.0, ONE_DARK_PRO.border_soft),
|
||||||
);
|
);
|
||||||
let marker_x = center_x + control.axis.clamp(-1.0, 1.0) * meter.width() * 0.45;
|
let marker_x = center_x + control.axis.clamp(-1.0, 1.0) * meter.width() * 0.45;
|
||||||
painter.circle_filled(
|
painter.circle_filled(
|
||||||
@@ -611,6 +618,7 @@ fn paint_center_overlay(painter: &egui::Painter, rect: egui::Rect, phase: Breako
|
|||||||
let (title, detail) = match phase {
|
let (title, detail) = match phase {
|
||||||
BreakoutPhase::Idle => ("按压顶部或点击开始", "左右分区压力控制挡板"),
|
BreakoutPhase::Idle => ("按压顶部或点击开始", "左右分区压力控制挡板"),
|
||||||
BreakoutPhase::Paused => ("已暂停", "再次按压顶部、P 或点击暂停继续"),
|
BreakoutPhase::Paused => ("已暂停", "再次按压顶部、P 或点击暂停继续"),
|
||||||
|
BreakoutPhase::Won => ("恭喜过关", "按压顶部、点击或空格重新开始"),
|
||||||
BreakoutPhase::Over => ("游戏结束", "点击或空格重开"),
|
BreakoutPhase::Over => ("游戏结束", "点击或空格重开"),
|
||||||
BreakoutPhase::Running => ("", ""),
|
BreakoutPhase::Running => ("", ""),
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -179,7 +179,6 @@ impl Default for ConnectionManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// The blocking device loop that runs on a background thread.
|
/// The blocking device loop that runs on a background thread.
|
||||||
#[allow(clippy::too_many_arguments)]
|
|
||||||
fn run_device_loop(
|
fn run_device_loop(
|
||||||
port_name: &str,
|
port_name: &str,
|
||||||
rows: u32,
|
rows: u32,
|
||||||
|
|||||||
39
src/force.rs
39
src/force.rs
@@ -1,6 +1,7 @@
|
|||||||
use crate::serial_core::multi_dim_force::PztProcessor;
|
use crate::serial_core::multi_dim_force::PztProcessor;
|
||||||
|
|
||||||
const FINGER_SAMPLE_COUNT: usize = 84;
|
pub const FINGER_SAMPLE_COUNT: usize = 84;
|
||||||
|
pub const HAND_FINGERTIP_COUNT: usize = 5;
|
||||||
const MIN_TANGENTIAL_MAGNITUDE: f32 = 0.02;
|
const MIN_TANGENTIAL_MAGNITUDE: f32 = 0.02;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
@@ -11,17 +12,22 @@ pub struct HudSpatialForce {
|
|||||||
|
|
||||||
pub struct ForceEstimatorState {
|
pub struct ForceEstimatorState {
|
||||||
pzt_processor: PztProcessor,
|
pzt_processor: PztProcessor,
|
||||||
|
fingertip_processors: [PztProcessor; HAND_FINGERTIP_COUNT],
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ForceEstimatorState {
|
impl ForceEstimatorState {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
pzt_processor: PztProcessor::new(),
|
pzt_processor: PztProcessor::new(),
|
||||||
|
fingertip_processors: std::array::from_fn(|_| PztProcessor::new()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reset(&mut self) {
|
pub fn reset(&mut self) {
|
||||||
self.pzt_processor.reset_baseline();
|
self.pzt_processor.reset_baseline();
|
||||||
|
self.fingertip_processors
|
||||||
|
.iter_mut()
|
||||||
|
.for_each(PztProcessor::reset_baseline);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn analyze(&mut self, values: &[u32]) -> Option<HudSpatialForce> {
|
pub fn analyze(&mut self, values: &[u32]) -> Option<HudSpatialForce> {
|
||||||
@@ -40,6 +46,37 @@ impl ForceEstimatorState {
|
|||||||
magnitude: analysis.magnitude,
|
magnitude: analysis.magnitude,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn analyze_fingertips(
|
||||||
|
&mut self,
|
||||||
|
values: &[u32],
|
||||||
|
) -> [Option<HudSpatialForce>; HAND_FINGERTIP_COUNT] {
|
||||||
|
let mut forces = [None; HAND_FINGERTIP_COUNT];
|
||||||
|
|
||||||
|
for (tip_index, processor) in self.fingertip_processors.iter_mut().enumerate() {
|
||||||
|
let start = tip_index * FINGER_SAMPLE_COUNT;
|
||||||
|
let end = start + FINGER_SAMPLE_COUNT;
|
||||||
|
let Some(segment) = values.get(start..end) else {
|
||||||
|
break;
|
||||||
|
};
|
||||||
|
|
||||||
|
let pzt_values = segment
|
||||||
|
.iter()
|
||||||
|
.map(|value| *value as f32)
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
forces[tip_index] = processor
|
||||||
|
.get_pzt_analysis(&pzt_values)
|
||||||
|
.ok()
|
||||||
|
.filter(|analysis| analysis.magnitude > MIN_TANGENTIAL_MAGNITUDE)
|
||||||
|
.map(|analysis| HudSpatialForce {
|
||||||
|
angle_deg: analysis.angle_deg,
|
||||||
|
magnitude: analysis.magnitude,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
forces
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for ForceEstimatorState {
|
impl Default for ForceEstimatorState {
|
||||||
|
|||||||
@@ -20,12 +20,15 @@ use eframe::egui;
|
|||||||
fn main() -> eframe::Result<()> {
|
fn main() -> eframe::Result<()> {
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
|
|
||||||
|
let window_icon = eframe::icon_data::from_png_bytes(include_bytes!("../res/128x128@2x.png"))
|
||||||
|
.expect("load window icon failed");
|
||||||
let options = eframe::NativeOptions {
|
let options = eframe::NativeOptions {
|
||||||
renderer: eframe::Renderer::Wgpu,
|
renderer: eframe::Renderer::Wgpu,
|
||||||
viewport: egui::ViewportBuilder::default()
|
viewport: egui::ViewportBuilder::default()
|
||||||
.with_inner_size([1920.0, 1080.0])
|
.with_inner_size([1920.0, 1080.0])
|
||||||
.with_min_inner_size([1280.0, 720.0])
|
.with_min_inner_size([1280.0, 720.0])
|
||||||
.with_decorations(false),
|
.with_decorations(false)
|
||||||
|
.with_icon(window_icon),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,31 +1,5 @@
|
|||||||
pub const MATRIX_ROWS: u32 = 12;
|
pub const MATRIX_ROWS: u32 = 12;
|
||||||
pub const MATRIX_COLS: u32 = 7;
|
pub const MATRIX_COLS: u32 = 7;
|
||||||
pub const UNFOLDED_L_CHANNEL_COUNT: usize = 8;
|
|
||||||
pub const UNFOLDED_H_CHANNEL_COUNT: usize = 13;
|
|
||||||
pub const UNFOLDED_SENSOR_COUNT: usize = UNFOLDED_L_CHANNEL_COUNT * UNFOLDED_H_CHANNEL_COUNT;
|
|
||||||
pub const UNFOLDED_SENSOR_SEGMENT_COUNTS: [usize; 10] = [8, 3, 5, 8, 10, 44, 3, 5, 8, 10];
|
|
||||||
|
|
||||||
pub const fn unfolded_lh_sample_index(l: usize, h: usize) -> usize {
|
|
||||||
debug_assert!(l < UNFOLDED_L_CHANNEL_COUNT);
|
|
||||||
debug_assert!(h < UNFOLDED_H_CHANNEL_COUNT);
|
|
||||||
h * UNFOLDED_L_CHANNEL_COUNT + l
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod adc_scan_tests {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn scan_changes_l_before_advancing_h() {
|
|
||||||
let first_h0_scan = (0..UNFOLDED_L_CHANNEL_COUNT)
|
|
||||||
.map(|l| unfolded_lh_sample_index(l, 0))
|
|
||||||
.collect::<Vec<_>>();
|
|
||||||
|
|
||||||
assert_eq!(first_h0_scan, (0..8).collect::<Vec<_>>());
|
|
||||||
assert_eq!(unfolded_lh_sample_index(0, 1), 8);
|
|
||||||
assert_eq!(unfolded_lh_sample_index(7, 12), 103);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const BASE_MATRIX_SPAN: f32 = 24.0;
|
const BASE_MATRIX_SPAN: f32 = 24.0;
|
||||||
const MATRIX_SPAN_GROWTH: f32 = 0.6;
|
const MATRIX_SPAN_GROWTH: f32 = 0.6;
|
||||||
|
|||||||
@@ -145,10 +145,10 @@ impl Recorder {
|
|||||||
r.state == RecordingState::Recording || r.state == RecordingState::Paused,
|
r.state == RecordingState::Recording || r.state == RecordingState::Paused,
|
||||||
"nothing to stop"
|
"nothing to stop"
|
||||||
);
|
);
|
||||||
if r.state == RecordingState::Paused
|
if r.state == RecordingState::Paused {
|
||||||
&& let Some(ps) = r.pause_start.take()
|
if let Some(ps) = r.pause_start.take() {
|
||||||
{
|
r.paused_duration_ms += ps.elapsed().as_millis() as u64;
|
||||||
r.paused_duration_ms += ps.elapsed().as_millis() as u64;
|
}
|
||||||
}
|
}
|
||||||
r.state = RecordingState::Idle;
|
r.state = RecordingState::Idle;
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -317,14 +317,15 @@ impl Recorder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set the start instant so duration_ms() reports the imported span
|
// Set the start instant so duration_ms() reports the imported span
|
||||||
if !r.frames.is_empty()
|
if !r.frames.is_empty() {
|
||||||
&& let Some(last) = r.frames.last()
|
if let Some(last) = r.frames.last() {
|
||||||
{
|
// Pretend the recording happened `last.timestamp_ms` ago
|
||||||
// Pretend the recording happened `last.timestamp_ms` ago
|
// so that elapsed_ms() would return that value.
|
||||||
// so that elapsed_ms() would return that value.
|
// We store a "fake" start by noting the offset.
|
||||||
// We store a "fake" start by noting the offset.
|
r.start =
|
||||||
r.start = Some(Instant::now() - std::time::Duration::from_millis(last.timestamp_ms));
|
Some(Instant::now() - std::time::Duration::from_millis(last.timestamp_ms));
|
||||||
r.paused_duration_ms = 0;
|
r.paused_duration_ms = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
577
src/render.rs
577
src/render.rs
@@ -1,8 +1,5 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
matrix::{
|
matrix::{MatrixLayout, build_view_projection, glyph_world_position},
|
||||||
MatrixLayout, UNFOLDED_SENSOR_COUNT, build_view_projection, glyph_world_position,
|
|
||||||
unfolded_lh_sample_index,
|
|
||||||
},
|
|
||||||
model::{AlphaMode, InstanceRaw, ModelVertex, Vertex},
|
model::{AlphaMode, InstanceRaw, ModelVertex, Vertex},
|
||||||
resources, texture,
|
resources, texture,
|
||||||
};
|
};
|
||||||
@@ -47,122 +44,53 @@ pub struct HandGatewayMode {
|
|||||||
|
|
||||||
const HAND_TIP_MATRICES: [HandTipMatrix; 5] = [
|
const HAND_TIP_MATRICES: [HandTipMatrix; 5] = [
|
||||||
HandTipMatrix {
|
HandTipMatrix {
|
||||||
center_px: [260.0, 490.0],
|
center_px: [265.0, 495.0],
|
||||||
size_px: [70.0, 120.0],
|
size_px: [70.0, 120.0],
|
||||||
angle_rad: -0.45,
|
angle_rad: -0.40,
|
||||||
},
|
},
|
||||||
HandTipMatrix {
|
HandTipMatrix {
|
||||||
center_px: [360.0, 255.0],
|
center_px: [359.0, 260.0],
|
||||||
size_px: [70.0, 120.0],
|
size_px: [70.0, 120.0],
|
||||||
angle_rad: -0.05,
|
angle_rad: -0.17,
|
||||||
},
|
},
|
||||||
HandTipMatrix {
|
HandTipMatrix {
|
||||||
center_px: [485.0, 225.0],
|
center_px: [482.0, 228.0],
|
||||||
size_px: [70.0, 120.0],
|
size_px: [70.0, 120.0],
|
||||||
angle_rad: 0.0,
|
angle_rad: -0.03,
|
||||||
},
|
},
|
||||||
HandTipMatrix {
|
HandTipMatrix {
|
||||||
center_px: [595.0, 260.0],
|
center_px: [596.0, 265.0],
|
||||||
size_px: [70.0, 120.0],
|
size_px: [70.0, 120.0],
|
||||||
angle_rad: 0.12,
|
angle_rad: 0.10,
|
||||||
},
|
},
|
||||||
HandTipMatrix {
|
HandTipMatrix {
|
||||||
center_px: [705.0, 385.0],
|
center_px: [693.0, 370.0],
|
||||||
size_px: [70.0, 120.0],
|
size_px: [70.0, 120.0],
|
||||||
angle_rad: 0.28,
|
angle_rad: 0.22,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const UNFOLDED_CANVAS_SIZE: [f32; 2] = [850.0, 750.0];
|
const HAND_PALM_CHIPS: [HandPalmChip; 2] = [
|
||||||
const UNFOLDED_CELL_SPACING_PX: f32 = 42.0;
|
|
||||||
const UNFOLDED_SENSOR_CHIPS: [HandPalmChip; 10] = [
|
|
||||||
// Top cap: 2 rows x 4 columns.
|
|
||||||
HandPalmChip {
|
HandPalmChip {
|
||||||
center_px: [425.0, 165.0],
|
center_px: [530.0, 593.0],
|
||||||
size_px: [176.0, 88.0],
|
size_px: [258.0, 88.0],
|
||||||
angle_rad: 0.0,
|
angle_rad: 0.12,
|
||||||
rows: 2,
|
|
||||||
cols: 4,
|
|
||||||
sample_offset: 0,
|
|
||||||
},
|
|
||||||
// Left wing, authored from the outside towards the 11x4 center block.
|
|
||||||
HandPalmChip {
|
|
||||||
center_px: [140.0, 578.0],
|
|
||||||
size_px: [46.0, 132.0],
|
|
||||||
angle_rad: 0.0,
|
|
||||||
rows: 3,
|
|
||||||
cols: 1,
|
|
||||||
sample_offset: 8,
|
|
||||||
},
|
|
||||||
HandPalmChip {
|
|
||||||
center_px: [188.0, 534.0],
|
|
||||||
size_px: [46.0, 220.0],
|
|
||||||
angle_rad: 0.0,
|
|
||||||
rows: 5,
|
rows: 5,
|
||||||
cols: 1,
|
cols: 14,
|
||||||
sample_offset: 11,
|
|
||||||
},
|
},
|
||||||
HandPalmChip {
|
HandPalmChip {
|
||||||
center_px: [236.0, 468.0],
|
center_px: [610.0, 778.0],
|
||||||
size_px: [46.0, 352.0],
|
size_px: [82.0, 228.0],
|
||||||
angle_rad: 0.0,
|
angle_rad: 0.05,
|
||||||
rows: 8,
|
|
||||||
cols: 1,
|
|
||||||
sample_offset: 16,
|
|
||||||
},
|
|
||||||
HandPalmChip {
|
|
||||||
center_px: [284.0, 424.0],
|
|
||||||
size_px: [46.0, 440.0],
|
|
||||||
angle_rad: 0.0,
|
|
||||||
rows: 10,
|
|
||||||
cols: 1,
|
|
||||||
sample_offset: 24,
|
|
||||||
},
|
|
||||||
// Center spine: 11 rows x 4 columns.
|
|
||||||
HandPalmChip {
|
|
||||||
center_px: [425.0, 444.0],
|
|
||||||
size_px: [176.0, 484.0],
|
|
||||||
angle_rad: 0.0,
|
|
||||||
rows: 11,
|
rows: 11,
|
||||||
cols: 4,
|
cols: 4,
|
||||||
sample_offset: 34,
|
|
||||||
},
|
|
||||||
// Right wing mirrors the left wing. Data remains ordered 3, 5, 8, 10.
|
|
||||||
HandPalmChip {
|
|
||||||
center_px: [710.0, 578.0],
|
|
||||||
size_px: [46.0, 132.0],
|
|
||||||
angle_rad: 0.0,
|
|
||||||
rows: 3,
|
|
||||||
cols: 1,
|
|
||||||
sample_offset: 78,
|
|
||||||
},
|
|
||||||
HandPalmChip {
|
|
||||||
center_px: [662.0, 534.0],
|
|
||||||
size_px: [46.0, 220.0],
|
|
||||||
angle_rad: 0.0,
|
|
||||||
rows: 5,
|
|
||||||
cols: 1,
|
|
||||||
sample_offset: 81,
|
|
||||||
},
|
|
||||||
HandPalmChip {
|
|
||||||
center_px: [614.0, 468.0],
|
|
||||||
size_px: [46.0, 352.0],
|
|
||||||
angle_rad: 0.0,
|
|
||||||
rows: 8,
|
|
||||||
cols: 1,
|
|
||||||
sample_offset: 86,
|
|
||||||
},
|
|
||||||
HandPalmChip {
|
|
||||||
center_px: [566.0, 424.0],
|
|
||||||
size_px: [46.0, 440.0],
|
|
||||||
angle_rad: 0.0,
|
|
||||||
rows: 10,
|
|
||||||
cols: 1,
|
|
||||||
sample_offset: 94,
|
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const HAND_FINGER_SENSOR_CELLS: usize = 12 * 7;
|
const HAND_FINGER_SENSOR_CELLS: usize = 12 * 7;
|
||||||
|
const HAND_PALM_HORIZONTAL_OFFSET: usize = HAND_FINGER_SENSOR_CELLS * 5;
|
||||||
|
const HAND_PALM_VERTICAL_OFFSET: usize = HAND_PALM_HORIZONTAL_OFFSET + 5 * 14;
|
||||||
|
const HAND_TIP_DOT_LOCAL_Y_OFFSET_PX: f32 = 14.0;
|
||||||
|
|
||||||
// Each entry pins one miniature matrix to a fingertip in hand.png.
|
// Each entry pins one miniature matrix to a fingertip in hand.png.
|
||||||
// Coordinates are authored in source-image pixels so they are easy to tune by eye.
|
// Coordinates are authored in source-image pixels so they are easy to tune by eye.
|
||||||
@@ -173,15 +101,14 @@ struct HandTipMatrix {
|
|||||||
angle_rad: f32,
|
angle_rad: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
// One block in the flat 270-degree sensor layout. Coordinates use a dedicated
|
// Palm chips follow the hand layout: one horizontal 5x14 matrix and one vertical
|
||||||
// 850x750 canvas so the unfolded shape stays prominent across window sizes.
|
// 11x4 matrix, rendered as dark inset chip tiles on the palm.
|
||||||
struct HandPalmChip {
|
struct HandPalmChip {
|
||||||
center_px: [f32; 2],
|
center_px: [f32; 2],
|
||||||
size_px: [f32; 2],
|
size_px: [f32; 2],
|
||||||
angle_rad: f32,
|
angle_rad: f32,
|
||||||
rows: u32,
|
rows: u32,
|
||||||
cols: u32,
|
cols: u32,
|
||||||
sample_offset: usize,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl egui_wgpu::CallbackTrait for WgpuBackgroundCallback {
|
impl egui_wgpu::CallbackTrait for WgpuBackgroundCallback {
|
||||||
@@ -230,6 +157,7 @@ pub struct BackgroundRenderResources {
|
|||||||
dot_pipeline: wgpu::RenderPipeline,
|
dot_pipeline: wgpu::RenderPipeline,
|
||||||
hand_membrane_pipeline: wgpu::RenderPipeline,
|
hand_membrane_pipeline: wgpu::RenderPipeline,
|
||||||
hand_dot_pipeline: wgpu::RenderPipeline,
|
hand_dot_pipeline: wgpu::RenderPipeline,
|
||||||
|
hand_palm_chip_pipeline: wgpu::RenderPipeline,
|
||||||
hand_palm_dot_pipeline: wgpu::RenderPipeline,
|
hand_palm_dot_pipeline: wgpu::RenderPipeline,
|
||||||
hand_image_bind_group: wgpu::BindGroup,
|
hand_image_bind_group: wgpu::BindGroup,
|
||||||
hand_image_texture: texture::Texture,
|
hand_image_texture: texture::Texture,
|
||||||
@@ -241,6 +169,8 @@ pub struct BackgroundRenderResources {
|
|||||||
hand_membrane_instances: Vec<GlyphInstance>,
|
hand_membrane_instances: Vec<GlyphInstance>,
|
||||||
hand_dot_instance_buffer: wgpu::Buffer,
|
hand_dot_instance_buffer: wgpu::Buffer,
|
||||||
hand_dot_instances: Vec<GlyphInstance>,
|
hand_dot_instances: Vec<GlyphInstance>,
|
||||||
|
hand_palm_chip_instance_buffer: wgpu::Buffer,
|
||||||
|
hand_palm_chip_instances: Vec<GlyphInstance>,
|
||||||
hand_palm_dot_instance_buffer: wgpu::Buffer,
|
hand_palm_dot_instance_buffer: wgpu::Buffer,
|
||||||
hand_palm_dot_instances: Vec<GlyphInstance>,
|
hand_palm_dot_instances: Vec<GlyphInstance>,
|
||||||
render_options: RenderOptions,
|
render_options: RenderOptions,
|
||||||
@@ -348,7 +278,10 @@ impl BackgroundRenderResources {
|
|||||||
build_view_projection(1.0, &layout),
|
build_view_projection(1.0, &layout),
|
||||||
surface_is_srgb,
|
surface_is_srgb,
|
||||||
render_options,
|
render_options,
|
||||||
UNFOLDED_CANVAS_SIZE,
|
[
|
||||||
|
hand_image_texture.width as f32,
|
||||||
|
hand_image_texture.height as f32,
|
||||||
|
],
|
||||||
);
|
);
|
||||||
let uniform_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
let uniform_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||||
label: Some("Pressure Matrix Uniform Buffer"),
|
label: Some("Pressure Matrix Uniform Buffer"),
|
||||||
@@ -565,6 +498,8 @@ impl BackgroundRenderResources {
|
|||||||
create_hand_membrane_pipeline(device, target_format, &shader, &pipeline_layout);
|
create_hand_membrane_pipeline(device, target_format, &shader, &pipeline_layout);
|
||||||
let hand_dot_pipeline =
|
let hand_dot_pipeline =
|
||||||
create_hand_dot_pipeline(device, target_format, &shader, &pipeline_layout);
|
create_hand_dot_pipeline(device, target_format, &shader, &pipeline_layout);
|
||||||
|
let hand_palm_chip_pipeline =
|
||||||
|
create_hand_palm_chip_pipeline(device, target_format, &shader, &pipeline_layout);
|
||||||
let hand_palm_dot_pipeline =
|
let hand_palm_dot_pipeline =
|
||||||
create_hand_palm_dot_pipeline(device, target_format, &shader, &pipeline_layout);
|
create_hand_palm_dot_pipeline(device, target_format, &shader, &pipeline_layout);
|
||||||
|
|
||||||
@@ -617,8 +552,23 @@ impl BackgroundRenderResources {
|
|||||||
contents: bytemuck::cast_slice(&hand_dot_instances),
|
contents: bytemuck::cast_slice(&hand_dot_instances),
|
||||||
usage: wgpu::BufferUsages::VERTEX | wgpu::BufferUsages::COPY_DST,
|
usage: wgpu::BufferUsages::VERTEX | wgpu::BufferUsages::COPY_DST,
|
||||||
});
|
});
|
||||||
let hand_palm_dot_instances =
|
let hand_palm_chip_instances = build_hand_palm_chip_instances(
|
||||||
build_hand_palm_dot_instances(rows, cols, &[[0.0, 0.0]; PRESSURE_CELL_COUNT]);
|
hand_image_texture.width as f32,
|
||||||
|
hand_image_texture.height as f32,
|
||||||
|
);
|
||||||
|
let hand_palm_chip_instance_buffer =
|
||||||
|
device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||||
|
label: Some("Hand Palm Chip Instance Buffer"),
|
||||||
|
contents: bytemuck::cast_slice(&hand_palm_chip_instances),
|
||||||
|
usage: wgpu::BufferUsages::VERTEX,
|
||||||
|
});
|
||||||
|
let hand_palm_dot_instances = build_hand_palm_dot_instances(
|
||||||
|
rows,
|
||||||
|
cols,
|
||||||
|
hand_image_texture.width as f32,
|
||||||
|
hand_image_texture.height as f32,
|
||||||
|
&[[0.0, 0.0]; PRESSURE_CELL_COUNT],
|
||||||
|
);
|
||||||
let hand_palm_dot_instance_buffer =
|
let hand_palm_dot_instance_buffer =
|
||||||
device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||||
label: Some("Hand Palm Chip Dot Instance Buffer"),
|
label: Some("Hand Palm Chip Dot Instance Buffer"),
|
||||||
@@ -640,6 +590,7 @@ impl BackgroundRenderResources {
|
|||||||
dot_pipeline,
|
dot_pipeline,
|
||||||
hand_membrane_pipeline,
|
hand_membrane_pipeline,
|
||||||
hand_dot_pipeline,
|
hand_dot_pipeline,
|
||||||
|
hand_palm_chip_pipeline,
|
||||||
hand_palm_dot_pipeline,
|
hand_palm_dot_pipeline,
|
||||||
hand_image_bind_group,
|
hand_image_bind_group,
|
||||||
hand_image_texture,
|
hand_image_texture,
|
||||||
@@ -650,6 +601,8 @@ impl BackgroundRenderResources {
|
|||||||
hand_membrane_instances,
|
hand_membrane_instances,
|
||||||
hand_dot_instance_buffer,
|
hand_dot_instance_buffer,
|
||||||
hand_dot_instances,
|
hand_dot_instances,
|
||||||
|
hand_palm_chip_instance_buffer,
|
||||||
|
hand_palm_chip_instances,
|
||||||
hand_palm_dot_instance_buffer,
|
hand_palm_dot_instance_buffer,
|
||||||
hand_palm_dot_instances,
|
hand_palm_dot_instances,
|
||||||
render_options,
|
render_options,
|
||||||
@@ -671,7 +624,10 @@ impl BackgroundRenderResources {
|
|||||||
build_view_projection(aspect, &self.layout),
|
build_view_projection(aspect, &self.layout),
|
||||||
self.surface_is_srgb,
|
self.surface_is_srgb,
|
||||||
self.render_options,
|
self.render_options,
|
||||||
UNFOLDED_CANVAS_SIZE,
|
[
|
||||||
|
self.hand_image_texture.width as f32,
|
||||||
|
self.hand_image_texture.height as f32,
|
||||||
|
],
|
||||||
);
|
);
|
||||||
queue.write_buffer(
|
queue.write_buffer(
|
||||||
&self.uniform_buffer,
|
&self.uniform_buffer,
|
||||||
@@ -698,8 +654,8 @@ impl BackgroundRenderResources {
|
|||||||
hand_pressure
|
hand_pressure
|
||||||
};
|
};
|
||||||
|
|
||||||
// Keep legacy fingertip buffers current while both hardware modes share
|
// Hand mode uses UV-anchored fingertip matrices over hand.png.
|
||||||
// the same renderer resources.
|
// Rebuild their instance positions here so pressure colors update every frame.
|
||||||
self.hand_dot_instances = build_hand_dot_instances(
|
self.hand_dot_instances = build_hand_dot_instances(
|
||||||
self.rows,
|
self.rows,
|
||||||
self.cols,
|
self.cols,
|
||||||
@@ -713,9 +669,15 @@ impl BackgroundRenderResources {
|
|||||||
bytemuck::cast_slice(&self.hand_dot_instances),
|
bytemuck::cast_slice(&self.hand_dot_instances),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Rebuild the 104-cell unfolded layout with the latest gateway samples.
|
// Palm chips reuse the same live 12x7 pressure frame, but draw it as
|
||||||
self.hand_palm_dot_instances =
|
// embedded micro-pixels inside dark chip tiles.
|
||||||
build_hand_palm_dot_instances(self.rows, self.cols, hand_pressure);
|
self.hand_palm_dot_instances = build_hand_palm_dot_instances(
|
||||||
|
self.rows,
|
||||||
|
self.cols,
|
||||||
|
self.hand_image_texture.width as f32,
|
||||||
|
self.hand_image_texture.height as f32,
|
||||||
|
hand_pressure,
|
||||||
|
);
|
||||||
queue.write_buffer(
|
queue.write_buffer(
|
||||||
&self.hand_palm_dot_instance_buffer,
|
&self.hand_palm_dot_instance_buffer,
|
||||||
0,
|
0,
|
||||||
@@ -731,7 +693,12 @@ impl BackgroundRenderResources {
|
|||||||
|
|
||||||
match active_mode {
|
match active_mode {
|
||||||
ActiveMode::Finger(mode) => self.paint_finger(render_pass, mode),
|
ActiveMode::Finger(mode) => self.paint_finger(render_pass, mode),
|
||||||
ActiveMode::Hand(mode) => self.paint_hand(render_pass, mode),
|
ActiveMode::Hand(mode) => {
|
||||||
|
render_pass.set_pipeline(&self.hand_image_pipeline);
|
||||||
|
render_pass.set_bind_group(1, &self.hand_image_bind_group, &[]);
|
||||||
|
render_pass.draw(0..6, 0..1);
|
||||||
|
self.paint_hand(render_pass, mode);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -753,7 +720,22 @@ impl BackgroundRenderResources {
|
|||||||
fn paint_hand(&self, render_pass: &mut wgpu::RenderPass<'_>, mode: &HandGatewayMode) {
|
fn paint_hand(&self, render_pass: &mut wgpu::RenderPass<'_>, mode: &HandGatewayMode) {
|
||||||
let _range = mode.range.clone();
|
let _range = mode.range.clone();
|
||||||
|
|
||||||
// Match Finger mode: draw only the 104 independent pressure dots.
|
// First draw the translucent sensor membranes, then draw live pressure beads on their grid.
|
||||||
|
render_pass.set_pipeline(&self.hand_membrane_pipeline);
|
||||||
|
render_pass.set_vertex_buffer(0, self.glyph_vertex_buffer.slice(..));
|
||||||
|
render_pass.set_vertex_buffer(1, self.hand_membrane_instance_buffer.slice(..));
|
||||||
|
render_pass.draw(0..6, 0..self.hand_membrane_instances.len() as u32);
|
||||||
|
|
||||||
|
render_pass.set_pipeline(&self.hand_dot_pipeline);
|
||||||
|
render_pass.set_vertex_buffer(0, self.glyph_vertex_buffer.slice(..));
|
||||||
|
render_pass.set_vertex_buffer(1, self.hand_dot_instance_buffer.slice(..));
|
||||||
|
render_pass.draw(0..6, 0..self.hand_dot_instances.len() as u32);
|
||||||
|
|
||||||
|
render_pass.set_pipeline(&self.hand_palm_chip_pipeline);
|
||||||
|
render_pass.set_vertex_buffer(0, self.glyph_vertex_buffer.slice(..));
|
||||||
|
render_pass.set_vertex_buffer(1, self.hand_palm_chip_instance_buffer.slice(..));
|
||||||
|
render_pass.draw(0..6, 0..self.hand_palm_chip_instances.len() as u32);
|
||||||
|
|
||||||
render_pass.set_pipeline(&self.hand_palm_dot_pipeline);
|
render_pass.set_pipeline(&self.hand_palm_dot_pipeline);
|
||||||
render_pass.set_vertex_buffer(0, self.glyph_vertex_buffer.slice(..));
|
render_pass.set_vertex_buffer(0, self.glyph_vertex_buffer.slice(..));
|
||||||
render_pass.set_vertex_buffer(1, self.hand_palm_dot_instance_buffer.slice(..));
|
render_pass.set_vertex_buffer(1, self.hand_palm_dot_instance_buffer.slice(..));
|
||||||
@@ -1091,6 +1073,39 @@ fn create_hand_dot_pipeline(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn create_hand_palm_chip_pipeline(
|
||||||
|
device: &wgpu::Device,
|
||||||
|
target_format: &wgpu::TextureFormat,
|
||||||
|
shader: &wgpu::ShaderModule,
|
||||||
|
layout: &wgpu::PipelineLayout,
|
||||||
|
) -> wgpu::RenderPipeline {
|
||||||
|
device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
|
||||||
|
label: Some("Hand Palm Embedded Chip Pipeline"),
|
||||||
|
layout: Some(layout),
|
||||||
|
vertex: wgpu::VertexState {
|
||||||
|
module: shader,
|
||||||
|
entry_point: Some("vs_hand_palm_chip"),
|
||||||
|
compilation_options: Default::default(),
|
||||||
|
buffers: &[GlyphVertex::desc(), GlyphInstance::desc()],
|
||||||
|
},
|
||||||
|
fragment: Some(wgpu::FragmentState {
|
||||||
|
module: shader,
|
||||||
|
entry_point: Some("fs_hand_palm_chip"),
|
||||||
|
compilation_options: Default::default(),
|
||||||
|
targets: &[Some(wgpu::ColorTargetState {
|
||||||
|
format: *target_format,
|
||||||
|
blend: Some(wgpu::BlendState::ALPHA_BLENDING),
|
||||||
|
write_mask: wgpu::ColorWrites::ALL,
|
||||||
|
})],
|
||||||
|
}),
|
||||||
|
primitive: wgpu::PrimitiveState::default(),
|
||||||
|
depth_stencil: None,
|
||||||
|
multisample: wgpu::MultisampleState::default(),
|
||||||
|
multiview_mask: None,
|
||||||
|
cache: None,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
fn create_hand_palm_dot_pipeline(
|
fn create_hand_palm_dot_pipeline(
|
||||||
device: &wgpu::Device,
|
device: &wgpu::Device,
|
||||||
target_format: &wgpu::TextureFormat,
|
target_format: &wgpu::TextureFormat,
|
||||||
@@ -1130,7 +1145,7 @@ fn build_hand_membrane_instances(image_width: f32, image_height: f32) -> Vec<Gly
|
|||||||
.map(|tip| {
|
.map(|tip| {
|
||||||
let uv_x = tip.center_px[0] / image_width.max(1.0);
|
let uv_x = tip.center_px[0] / image_width.max(1.0);
|
||||||
let uv_y = tip.center_px[1] / image_height.max(1.0);
|
let uv_y = tip.center_px[1] / image_height.max(1.0);
|
||||||
let membrane_size = [tip.size_px[0] * 1.62, tip.size_px[1] * 1.56];
|
let membrane_size = [tip.size_px[0] * 1.44, tip.size_px[1] * 1.36];
|
||||||
|
|
||||||
GlyphInstance {
|
GlyphInstance {
|
||||||
// Membrane shaders read xy as hand.png UV.
|
// Membrane shaders read xy as hand.png UV.
|
||||||
@@ -1142,6 +1157,28 @@ fn build_hand_membrane_instances(image_width: f32, image_height: f32) -> Vec<Gly
|
|||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn build_hand_palm_chip_instances(image_width: f32, image_height: f32) -> Vec<GlyphInstance> {
|
||||||
|
HAND_PALM_CHIPS
|
||||||
|
.iter()
|
||||||
|
.map(|chip| {
|
||||||
|
let uv_x = chip.center_px[0] / image_width.max(1.0);
|
||||||
|
let uv_y = chip.center_px[1] / image_height.max(1.0);
|
||||||
|
|
||||||
|
GlyphInstance {
|
||||||
|
// Palm chip shaders read xy as hand.png UV.
|
||||||
|
world_position: [uv_x, uv_y, 0.0, 1.0],
|
||||||
|
// Store chip angle, source-image pixel size, and matrix shape for the shader grid.
|
||||||
|
style: [
|
||||||
|
chip.angle_rad,
|
||||||
|
chip.size_px[0],
|
||||||
|
chip.size_px[1],
|
||||||
|
(chip.rows * 100 + chip.cols) as f32,
|
||||||
|
],
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
fn build_hand_dot_instances(
|
fn build_hand_dot_instances(
|
||||||
rows: u32,
|
rows: u32,
|
||||||
cols: u32,
|
cols: u32,
|
||||||
@@ -1166,7 +1203,8 @@ fn build_hand_dot_instances(
|
|||||||
|
|
||||||
// Lay out a rows x cols matrix in fingertip-local pixel space.
|
// Lay out a rows x cols matrix in fingertip-local pixel space.
|
||||||
let local_x = (col as f32 - cols as f32 / 2.0 + 0.5) / cols as f32 * tip.size_px[0];
|
let local_x = (col as f32 - cols as f32 / 2.0 + 0.5) / cols as f32 * tip.size_px[0];
|
||||||
let local_y = (row as f32 - rows as f32 / 2.0 + 0.5) / rows as f32 * tip.size_px[1];
|
let local_y = (row as f32 - rows as f32 / 2.0 + 0.5) / rows as f32 * tip.size_px[1]
|
||||||
|
+ HAND_TIP_DOT_LOCAL_Y_OFFSET_PX;
|
||||||
|
|
||||||
// Rotate the local matrix so it follows the direction of the finger.
|
// Rotate the local matrix so it follows the direction of the finger.
|
||||||
let x = tip.center_px[0] + local_x * cos - local_y * sin;
|
let x = tip.center_px[0] + local_x * cos - local_y * sin;
|
||||||
@@ -1189,26 +1227,44 @@ fn build_hand_dot_instances(
|
|||||||
fn build_hand_palm_dot_instances(
|
fn build_hand_palm_dot_instances(
|
||||||
_rows: u32,
|
_rows: u32,
|
||||||
_cols: u32,
|
_cols: u32,
|
||||||
|
image_width: f32,
|
||||||
|
image_height: f32,
|
||||||
pressure: &[[f32; 2]],
|
pressure: &[[f32; 2]],
|
||||||
) -> Vec<GlyphInstance> {
|
) -> Vec<GlyphInstance> {
|
||||||
let chip_dot_count: usize = UNFOLDED_SENSOR_CHIPS
|
let chip_dot_count: usize = HAND_PALM_CHIPS
|
||||||
.iter()
|
.iter()
|
||||||
.map(|chip| (chip.rows * chip.cols) as usize)
|
.map(|chip| (chip.rows * chip.cols) as usize)
|
||||||
.sum();
|
.sum();
|
||||||
debug_assert_eq!(chip_dot_count, UNFOLDED_SENSOR_COUNT);
|
|
||||||
let mut instances = Vec::with_capacity(chip_dot_count);
|
let mut instances = Vec::with_capacity(chip_dot_count);
|
||||||
|
|
||||||
for (chip_index, chip) in UNFOLDED_SENSOR_CHIPS.iter().enumerate() {
|
for (chip_index, chip) in HAND_PALM_CHIPS.into_iter().enumerate() {
|
||||||
|
let cos = chip.angle_rad.cos();
|
||||||
|
let sin = chip.angle_rad.sin();
|
||||||
|
// Palm films can float slightly beyond the hand artwork, similar to fingertip membranes.
|
||||||
|
let active_size = [chip.size_px[0] * 0.86, chip.size_px[1] * 0.86];
|
||||||
|
|
||||||
for row in 0..chip.rows {
|
for row in 0..chip.rows {
|
||||||
for col in 0..chip.cols {
|
for col in 0..chip.cols {
|
||||||
let index = unfolded_adc_sample_index(chip_index, row, col);
|
let offset = match chip_index {
|
||||||
let [normalized, display_value] = sample_pressure_at(pressure, index, index);
|
0 => HAND_PALM_HORIZONTAL_OFFSET,
|
||||||
let [x, y] = unfolded_cell_position(&chip, row, col);
|
_ => HAND_PALM_VERTICAL_OFFSET,
|
||||||
|
};
|
||||||
|
let index = hand_palm_pressure_index(chip_index, row, col, chip.rows, chip.cols);
|
||||||
|
let [normalized, display_value] =
|
||||||
|
sample_pressure_at(pressure, offset + index, index);
|
||||||
|
|
||||||
|
let local_x =
|
||||||
|
(col as f32 - chip.cols as f32 / 2.0 + 0.5) / chip.cols as f32 * active_size[0];
|
||||||
|
let local_y =
|
||||||
|
(row as f32 - chip.rows as f32 / 2.0 + 0.5) / chip.rows as f32 * active_size[1];
|
||||||
|
|
||||||
|
let x = chip.center_px[0] + local_x * cos - local_y * sin;
|
||||||
|
let y = chip.center_px[1] + local_x * sin + local_y * cos;
|
||||||
|
|
||||||
instances.push(GlyphInstance {
|
instances.push(GlyphInstance {
|
||||||
world_position: [
|
world_position: [
|
||||||
x / UNFOLDED_CANVAS_SIZE[0],
|
x / image_width.max(1.0),
|
||||||
y / UNFOLDED_CANVAS_SIZE[1],
|
y / image_height.max(1.0),
|
||||||
0.0,
|
0.0,
|
||||||
1.0,
|
1.0,
|
||||||
],
|
],
|
||||||
@@ -1221,45 +1277,12 @@ fn build_hand_palm_dot_instances(
|
|||||||
instances
|
instances
|
||||||
}
|
}
|
||||||
|
|
||||||
fn unfolded_adc_sample_index(chip_index: usize, row: u32, col: u32) -> usize {
|
fn hand_palm_pressure_index(chip_index: usize, row: u32, col: u32, rows: u32, cols: u32) -> usize {
|
||||||
// Raw sample 0 is L0H0. The scan advances L first:
|
if chip_index == 0 {
|
||||||
// L0H0, L1H0, …, L7H0, L0H1, …, L7H12.
|
(col * rows + (rows - 1 - row)) as usize
|
||||||
// The PCB unfolds those channel pairs into the ten visual regions below.
|
} else {
|
||||||
let (l, h) = match chip_index {
|
(row * cols + col) as usize
|
||||||
0 => (5 - col, 12 - row), // top cap: L5…L2 × H12…H11
|
}
|
||||||
1 => (6, row), // left outer tip: L6 × H0…H2
|
|
||||||
2 => (7, folded_five_row_h(row)), // left folded wing
|
|
||||||
3 => (7, 10 - row), // left inner wing: L7 × H10…H3
|
|
||||||
4 => (6, 12 - row), // left inner spine: L6 × H12…H3
|
|
||||||
5 => (5 - col, 10 - row), // center: L5…L2 × H10…H0
|
|
||||||
6 => (1, row), // right outer tip: L1 × H0…H2
|
|
||||||
7 => (0, folded_five_row_h(row)), // right folded wing
|
|
||||||
8 => (0, 10 - row), // right inner wing: L0 × H10…H3
|
|
||||||
9 => (1, 12 - row), // right inner spine: L1 × H12…H3
|
|
||||||
_ => unreachable!("invalid unfolded PCB region"),
|
|
||||||
};
|
|
||||||
|
|
||||||
unfolded_lh_sample_index(l as usize, h as usize)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn folded_five_row_h(row: u32) -> u32 {
|
|
||||||
const PCB_H_ROUTE: [u32; 5] = [12, 11, 0, 1, 2];
|
|
||||||
PCB_H_ROUTE[row as usize]
|
|
||||||
}
|
|
||||||
fn unfolded_cell_position(chip: &HandPalmChip, row: u32, col: u32) -> [f32; 2] {
|
|
||||||
let cos = chip.angle_rad.cos();
|
|
||||||
let sin = chip.angle_rad.sin();
|
|
||||||
// Author every region on the same point grid. Using the last row as the
|
|
||||||
// vertical anchor keeps the stepped wing columns exactly bottom-aligned.
|
|
||||||
let bottom_center_y = chip.center_px[1] + chip.size_px[1] * 0.5 - 22.0;
|
|
||||||
let local_x = (col as f32 - chip.cols as f32 / 2.0 + 0.5) * UNFOLDED_CELL_SPACING_PX;
|
|
||||||
let y_from_bottom = (chip.rows.saturating_sub(row + 1)) as f32 * UNFOLDED_CELL_SPACING_PX;
|
|
||||||
let local_y = -y_from_bottom;
|
|
||||||
|
|
||||||
[
|
|
||||||
chip.center_px[0] + local_x * cos - local_y * sin,
|
|
||||||
bottom_center_y + local_x * sin + local_y * cos,
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sample_pressure_at(pressure: &[[f32; 2]], index: usize, fallback_index: usize) -> [f32; 2] {
|
fn sample_pressure_at(pressure: &[[f32; 2]], index: usize, fallback_index: usize) -> [f32; 2] {
|
||||||
@@ -1270,225 +1293,6 @@ fn sample_pressure_at(pressure: &[[f32; 2]], index: usize, fallback_index: usize
|
|||||||
.unwrap_or([0.0, 0.0])
|
.unwrap_or([0.0, 0.0])
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod unfolded_layout_tests {
|
|
||||||
use super::*;
|
|
||||||
use crate::matrix::UNFOLDED_SENSOR_SEGMENT_COUNTS;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn unfolded_layout_maps_every_lh_adc_channel_once() {
|
|
||||||
let mut seen = [false; UNFOLDED_SENSOR_COUNT];
|
|
||||||
|
|
||||||
for (chip_index, chip) in UNFOLDED_SENSOR_CHIPS.iter().enumerate() {
|
|
||||||
for row in 0..chip.rows {
|
|
||||||
for col in 0..chip.cols {
|
|
||||||
let index = unfolded_adc_sample_index(chip_index, row, col);
|
|
||||||
assert!(index < UNFOLDED_SENSOR_COUNT);
|
|
||||||
assert!(!seen[index], "duplicate ADC sample index {index}");
|
|
||||||
seen[index] = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
assert!(seen.into_iter().all(|mapped| mapped));
|
|
||||||
assert_eq!(unfolded_lh_sample_index(0, 0), 0); // first raw sample
|
|
||||||
assert_eq!(unfolded_lh_sample_index(1, 0), 1); // L changes first
|
|
||||||
assert_eq!(unfolded_lh_sample_index(7, 0), 7);
|
|
||||||
assert_eq!(unfolded_lh_sample_index(0, 1), 8); // then H advances
|
|
||||||
assert_eq!(unfolded_adc_sample_index(7, 0, 0), 96); // L0H12
|
|
||||||
assert_eq!(unfolded_adc_sample_index(6, 0, 0), 1); // L1H0
|
|
||||||
assert_eq!(unfolded_lh_sample_index(7, 12), 103); // last rendered sample
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn unfolded_layout_matches_annotated_adc_intersections() {
|
|
||||||
// Right folded/outer intersections: 1=L0H0, 2=L1H0,
|
|
||||||
// 9=L0H1, 10=L1H1, 17=L0H2, 18=L1H2.
|
|
||||||
assert_eq!(unfolded_adc_sample_index(7, 2, 0) + 1, 1);
|
|
||||||
assert_eq!(unfolded_adc_sample_index(6, 0, 0) + 1, 2);
|
|
||||||
assert_eq!(unfolded_adc_sample_index(7, 3, 0) + 1, 9);
|
|
||||||
assert_eq!(unfolded_adc_sample_index(6, 1, 0) + 1, 10);
|
|
||||||
assert_eq!(unfolded_adc_sample_index(7, 4, 0) + 1, 17);
|
|
||||||
assert_eq!(unfolded_adc_sample_index(6, 2, 0) + 1, 18);
|
|
||||||
|
|
||||||
// Right inner routes continue upward from H3.
|
|
||||||
assert_eq!(
|
|
||||||
(0..8)
|
|
||||||
.map(|row| unfolded_adc_sample_index(8, row, 0) + 1)
|
|
||||||
.collect::<Vec<_>>(),
|
|
||||||
vec![81, 73, 65, 57, 49, 41, 33, 25]
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
(0..10)
|
|
||||||
.map(|row| unfolded_adc_sample_index(9, row, 0) + 1)
|
|
||||||
.collect::<Vec<_>>(),
|
|
||||||
vec![98, 90, 82, 74, 66, 58, 50, 42, 34, 26]
|
|
||||||
);
|
|
||||||
|
|
||||||
// Left routes mirror the right side's PCB continuation.
|
|
||||||
assert_eq!(
|
|
||||||
(0..3)
|
|
||||||
.map(|row| unfolded_adc_sample_index(1, row, 0) + 1)
|
|
||||||
.collect::<Vec<_>>(),
|
|
||||||
vec![7, 15, 23]
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
(0..5)
|
|
||||||
.map(|row| unfolded_adc_sample_index(2, row, 0) + 1)
|
|
||||||
.collect::<Vec<_>>(),
|
|
||||||
vec![104, 96, 8, 16, 24]
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
(0..8)
|
|
||||||
.map(|row| unfolded_adc_sample_index(3, row, 0) + 1)
|
|
||||||
.collect::<Vec<_>>(),
|
|
||||||
vec![88, 80, 72, 64, 56, 48, 40, 32]
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
(0..10)
|
|
||||||
.map(|row| unfolded_adc_sample_index(4, row, 0) + 1)
|
|
||||||
.collect::<Vec<_>>(),
|
|
||||||
vec![103, 95, 87, 79, 71, 63, 55, 47, 39, 31]
|
|
||||||
);
|
|
||||||
|
|
||||||
// Center rows H0…H7, each ordered L5, L4, L3, L2.
|
|
||||||
for h in 0..=7 {
|
|
||||||
let row = 10 - h;
|
|
||||||
let expected = (2..=5)
|
|
||||||
.rev()
|
|
||||||
.map(|l| unfolded_lh_sample_index(l, h as usize) + 1)
|
|
||||||
.collect::<Vec<_>>();
|
|
||||||
let rendered = (0..4)
|
|
||||||
.map(|col| unfolded_adc_sample_index(5, row, col) + 1)
|
|
||||||
.collect::<Vec<_>>();
|
|
||||||
assert_eq!(rendered, expected);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn annotated_folded_points_share_the_same_physical_rows() {
|
|
||||||
let same_y = |left_chip: usize, left_row: u32, right_chip: usize, right_row: u32| {
|
|
||||||
let left = unfolded_cell_position(&UNFOLDED_SENSOR_CHIPS[left_chip], left_row, 0)[1];
|
|
||||||
let right = unfolded_cell_position(&UNFOLDED_SENSOR_CHIPS[right_chip], right_row, 0)[1];
|
|
||||||
assert!((left - right).abs() < 0.01);
|
|
||||||
};
|
|
||||||
|
|
||||||
// Left outer pairs: 7/8, 15/16, 23/24.
|
|
||||||
for row in 0..3 {
|
|
||||||
same_y(1, row, 2, row + 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Right outer pairs: 2/1, 10/9, 18/17.
|
|
||||||
for row in 0..3 {
|
|
||||||
same_y(6, row, 7, row + 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Inner continuations align by H despite belonging to different strips.
|
|
||||||
for row in 0..8 {
|
|
||||||
same_y(3, row, 4, row + 2);
|
|
||||||
same_y(8, row, 9, row + 2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn unfolded_layout_matches_requested_shapes() {
|
|
||||||
let shapes = UNFOLDED_SENSOR_CHIPS.map(|chip| (chip.rows, chip.cols));
|
|
||||||
let sample_counts = UNFOLDED_SENSOR_CHIPS.map(|chip| (chip.rows * chip.cols) as usize);
|
|
||||||
|
|
||||||
assert_eq!(
|
|
||||||
shapes,
|
|
||||||
[
|
|
||||||
(2, 4),
|
|
||||||
(3, 1),
|
|
||||||
(5, 1),
|
|
||||||
(8, 1),
|
|
||||||
(10, 1),
|
|
||||||
(11, 4),
|
|
||||||
(3, 1),
|
|
||||||
(5, 1),
|
|
||||||
(8, 1),
|
|
||||||
(10, 1),
|
|
||||||
]
|
|
||||||
);
|
|
||||||
assert_eq!(sample_counts, UNFOLDED_SENSOR_SEGMENT_COUNTS);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn unfolded_wings_are_mirrored_around_center() {
|
|
||||||
let center_x = UNFOLDED_SENSOR_CHIPS[5].center_px[0];
|
|
||||||
|
|
||||||
for (left, right) in UNFOLDED_SENSOR_CHIPS[1..5]
|
|
||||||
.iter()
|
|
||||||
.zip(UNFOLDED_SENSOR_CHIPS[6..10].iter())
|
|
||||||
{
|
|
||||||
assert_eq!((left.rows, left.cols), (right.rows, right.cols));
|
|
||||||
assert_eq!(left.center_px[1], right.center_px[1]);
|
|
||||||
assert!(
|
|
||||||
((center_x - left.center_px[0]) - (right.center_px[0] - center_x)).abs() < 0.01
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn unfolded_layout_fits_its_canvas() {
|
|
||||||
for chip in UNFOLDED_SENSOR_CHIPS {
|
|
||||||
let half_width = chip.size_px[0] * 0.5;
|
|
||||||
let half_height = chip.size_px[1] * 0.5;
|
|
||||||
|
|
||||||
assert!(chip.center_px[0] - half_width >= 0.0);
|
|
||||||
assert!(chip.center_px[0] + half_width <= UNFOLDED_CANVAS_SIZE[0]);
|
|
||||||
assert!(chip.center_px[1] - half_height >= 0.0);
|
|
||||||
assert!(chip.center_px[1] + half_height <= UNFOLDED_CANVAS_SIZE[1]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn unfolded_wing_rows_share_one_bottom_baseline() {
|
|
||||||
let wing_indices = [1usize, 2, 3, 4, 6, 7, 8, 9];
|
|
||||||
let expected_y = unfolded_cell_position(
|
|
||||||
&UNFOLDED_SENSOR_CHIPS[wing_indices[0]],
|
|
||||||
UNFOLDED_SENSOR_CHIPS[wing_indices[0]].rows - 1,
|
|
||||||
0,
|
|
||||||
)[1];
|
|
||||||
|
|
||||||
for index in wing_indices {
|
|
||||||
let chip = &UNFOLDED_SENSOR_CHIPS[index];
|
|
||||||
let bottom_y = unfolded_cell_position(chip, chip.rows - 1, 0)[1];
|
|
||||||
assert!((bottom_y - expected_y).abs() < 0.01);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn unfolded_wings_are_compact_with_more_space_at_center() {
|
|
||||||
let left_x = UNFOLDED_SENSOR_CHIPS[1..5]
|
|
||||||
.iter()
|
|
||||||
.map(|chip| chip.center_px[0])
|
|
||||||
.collect::<Vec<_>>();
|
|
||||||
let wing_gap = left_x[1] - left_x[0];
|
|
||||||
assert!((wing_gap - 48.0).abs() < 0.01);
|
|
||||||
assert!(
|
|
||||||
left_x
|
|
||||||
.windows(2)
|
|
||||||
.all(|pair| (pair[1] - pair[0] - wing_gap).abs() < 0.01)
|
|
||||||
);
|
|
||||||
|
|
||||||
let center_left_x = unfolded_cell_position(&UNFOLDED_SENSOR_CHIPS[5], 0, 0)[0];
|
|
||||||
let left_inner_x = unfolded_cell_position(&UNFOLDED_SENSOR_CHIPS[4], 0, 0)[0];
|
|
||||||
assert!(center_left_x - left_inner_x > wing_gap);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn unfolded_top_block_sits_close_to_center_block() {
|
|
||||||
let top = &UNFOLDED_SENSOR_CHIPS[0];
|
|
||||||
let center = &UNFOLDED_SENSOR_CHIPS[5];
|
|
||||||
let top_bottom_y = unfolded_cell_position(top, top.rows - 1, 0)[1];
|
|
||||||
let center_top_y = unfolded_cell_position(center, 0, 0)[1];
|
|
||||||
|
|
||||||
assert!(center_top_y > top_bottom_y);
|
|
||||||
assert!(center_top_y - top_bottom_y < UNFOLDED_CELL_SPACING_PX * 2.0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn build_glyph_instances(
|
fn build_glyph_instances(
|
||||||
rows: u32,
|
rows: u32,
|
||||||
cols: u32,
|
cols: u32,
|
||||||
@@ -1612,3 +1416,24 @@ impl GlyphInstance {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn hand_palm_horizontal_uses_column_major_pressure_order() {
|
||||||
|
assert_eq!(hand_palm_pressure_index(0, 0, 0, 5, 14), 4);
|
||||||
|
assert_eq!(hand_palm_pressure_index(0, 1, 0, 5, 14), 3);
|
||||||
|
assert_eq!(hand_palm_pressure_index(0, 0, 1, 5, 14), 9);
|
||||||
|
assert_eq!(hand_palm_pressure_index(0, 4, 13, 5, 14), 65);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn hand_palm_vertical_keeps_row_major_pressure_order() {
|
||||||
|
assert_eq!(hand_palm_pressure_index(1, 0, 0, 11, 4), 0);
|
||||||
|
assert_eq!(hand_palm_pressure_index(1, 0, 1, 11, 4), 1);
|
||||||
|
assert_eq!(hand_palm_pressure_index(1, 1, 0, 11, 4), 4);
|
||||||
|
assert_eq!(hand_palm_pressure_index(1, 10, 3, 11, 4), 43);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -457,7 +457,6 @@ fn create_color_material(
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
|
||||||
fn create_material(
|
fn create_material(
|
||||||
device: &wgpu::Device,
|
device: &wgpu::Device,
|
||||||
texture_bind_group_layout: &wgpu::BindGroupLayout,
|
texture_bind_group_layout: &wgpu::BindGroupLayout,
|
||||||
@@ -703,7 +702,6 @@ fn append_gltf_node_meshes(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
|
||||||
fn append_gltf_primitive_mesh(
|
fn append_gltf_primitive_mesh(
|
||||||
mesh_name: &str,
|
mesh_name: &str,
|
||||||
primitive_index: usize,
|
primitive_index: usize,
|
||||||
@@ -971,7 +969,7 @@ fn rgba_from_chunks(
|
|||||||
read_component: fn(&[u8]) -> u8,
|
read_component: fn(&[u8]) -> u8,
|
||||||
) -> anyhow::Result<Vec<u8>> {
|
) -> anyhow::Result<Vec<u8>> {
|
||||||
let pixel_width = channels * component_width;
|
let pixel_width = channels * component_width;
|
||||||
if pixel_width == 0 || !pixels.len().is_multiple_of(pixel_width) {
|
if pixel_width == 0 || pixels.len() % pixel_width != 0 {
|
||||||
bail!("invalid glTF image byte length for {channels} channels");
|
bail!("invalid glTF image byte length for {channels} channels");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -146,7 +146,7 @@ impl HandGatewayCodec {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_node_payload(data: &[u8]) -> Result<Vec<u16>, CodecError> {
|
pub fn parse_node_payload(data: &[u8]) -> Result<Vec<u16>, CodecError> {
|
||||||
if !data.len().is_multiple_of(2) {
|
if data.len() % 2 != 0 {
|
||||||
return Err(CodecError::InvalidLength);
|
return Err(CodecError::InvalidLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ impl TactileACodec {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_data_frame(data: &[u8]) -> Result<Vec<i32>, CodecError> {
|
pub fn parse_data_frame(data: &[u8]) -> Result<Vec<i32>, CodecError> {
|
||||||
if !data.len().is_multiple_of(2) {
|
if data.len() % 2 != 0 {
|
||||||
return Err(CodecError::InvalidLength);
|
return Err(CodecError::InvalidLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,7 +132,7 @@ impl Codec<TactileAFrame> for TactileACodec {
|
|||||||
let need_check_data = self.buffer[0..14 + except_data_len].to_vec();
|
let need_check_data = self.buffer[0..14 + except_data_len].to_vec();
|
||||||
let payload = self.buffer[14..14 + except_data_len].to_vec();
|
let payload = self.buffer[14..14 + except_data_len].to_vec();
|
||||||
let crc8_itu_alg = crc::Crc::<u8>::new(&crc::CRC_8_I_432_1);
|
let crc8_itu_alg = crc::Crc::<u8>::new(&crc::CRC_8_I_432_1);
|
||||||
let checksum = crc8_itu_alg.checksum(need_check_data.as_slice());
|
let checksum = crc8_itu_alg.checksum(&need_check_data.as_slice());
|
||||||
if self.buffer[frame_length - 1] != checksum {
|
if self.buffer[frame_length - 1] != checksum {
|
||||||
log::debug!(
|
log::debug!(
|
||||||
"checksum mismatch: expected {:02X}, got {:02X}, frame_len={}",
|
"checksum mismatch: expected {:02X}, got {:02X}, frame_len={}",
|
||||||
@@ -188,61 +188,3 @@ impl Codec<TactileAFrame> for TactileACodec {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use super::*;
|
|
||||||
use crate::serial_core::codec::Codec;
|
|
||||||
use std::time::Instant;
|
|
||||||
|
|
||||||
const FINGER_3D_ROWS: usize = 12;
|
|
||||||
const FINGER_3D_COLS: usize = 9;
|
|
||||||
const FINGER_3D_DATA_LEN: usize = FINGER_3D_ROWS * FINGER_3D_COLS * 2;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn finger_3d_request_asks_for_108_samples() {
|
|
||||||
let codec = TactileACodec::new(FINGER_3D_COLS, FINGER_3D_ROWS);
|
|
||||||
let frame = TactileACodec::build_req_frame(FINGER_3D_COLS, FINGER_3D_ROWS).unwrap();
|
|
||||||
let encoded = codec.encode(&frame).unwrap();
|
|
||||||
|
|
||||||
assert_eq!(
|
|
||||||
u16::from_le_bytes([encoded[11], encoded[12]]) as usize,
|
|
||||||
FINGER_3D_DATA_LEN
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn finger_3d_decode_accepts_108_samples_across_reads() {
|
|
||||||
let mut codec = TactileACodec::new(FINGER_3D_COLS, FINGER_3D_ROWS);
|
|
||||||
let payload = (0..FINGER_3D_ROWS * FINGER_3D_COLS)
|
|
||||||
.flat_map(|value| (value as u16).to_le_bytes())
|
|
||||||
.collect::<Vec<_>>();
|
|
||||||
let mut response = Vec::new();
|
|
||||||
response.extend_from_slice(&[0xAA, 0x55]);
|
|
||||||
response.extend_from_slice(&9_u16.to_le_bytes());
|
|
||||||
response.extend_from_slice(&[0x34, 0x00, 0xFB]);
|
|
||||||
response.extend_from_slice(&7168_u32.to_le_bytes());
|
|
||||||
response.extend_from_slice(&(FINGER_3D_DATA_LEN as u16).to_le_bytes());
|
|
||||||
response.push(0);
|
|
||||||
response.extend_from_slice(&payload);
|
|
||||||
response.push(calc_crc8_itu(&response));
|
|
||||||
|
|
||||||
let split = response.len() / 2;
|
|
||||||
assert!(
|
|
||||||
codec
|
|
||||||
.decode(&response[..split], Instant::now())
|
|
||||||
.unwrap()
|
|
||||||
.is_empty()
|
|
||||||
);
|
|
||||||
let frames = codec.decode(&response[split..], Instant::now()).unwrap();
|
|
||||||
|
|
||||||
let TactileAFrame::Rep(rep) = &frames[0] else {
|
|
||||||
panic!("expected response frame");
|
|
||||||
};
|
|
||||||
assert_eq!(rep.payload.len(), FINGER_3D_DATA_LEN);
|
|
||||||
assert_eq!(
|
|
||||||
TactileACodec::parse_data_frame(&rep.payload).unwrap().len(),
|
|
||||||
108
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ impl PztProcessor {
|
|||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if n.is_multiple_of(2) {
|
if n % 2 == 0 {
|
||||||
(sorted[n / 2 - 1] + sorted[n / 2]) / 2.0
|
(sorted[n / 2 - 1] + sorted[n / 2]) / 2.0
|
||||||
} else {
|
} else {
|
||||||
sorted[n / 2]
|
sorted[n / 2]
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ const DEFAULT_HAND_GATEWAY_NODE_SAMPLE_COUNTS: &[u16] = &[84, 84, 84, 84, 84, 70
|
|||||||
pub struct SerialIoStats {
|
pub struct SerialIoStats {
|
||||||
pub rx_bytes: u64,
|
pub rx_bytes: u64,
|
||||||
pub tx_bytes: u64,
|
pub tx_bytes: u64,
|
||||||
|
pub rx_frames: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
@@ -24,7 +25,6 @@ pub enum SerialProtocol {
|
|||||||
|
|
||||||
/// Runs the serial polling loop on the calling (background) thread.
|
/// Runs the serial polling loop on the calling (background) thread.
|
||||||
/// Sends decoded pressure matrix data (Vec<i32>) to the output channel.
|
/// Sends decoded pressure matrix data (Vec<i32>) to the output channel.
|
||||||
#[allow(clippy::too_many_arguments)]
|
|
||||||
pub fn run_serial_loop(
|
pub fn run_serial_loop(
|
||||||
port: &mut dyn ReadWrite,
|
port: &mut dyn ReadWrite,
|
||||||
rows: usize,
|
rows: usize,
|
||||||
@@ -74,11 +74,11 @@ fn run_tactile_a_loop(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Send poll request
|
// Send poll request
|
||||||
if let Ok(req_bytes) = codec.encode(&req_frame)
|
if let Ok(req_bytes) = codec.encode(&req_frame) {
|
||||||
&& port.write_all(&req_bytes).is_ok()
|
if port.write_all(&req_bytes).is_ok() {
|
||||||
{
|
io_stats.tx_bytes += req_bytes.len() as u64;
|
||||||
io_stats.tx_bytes += req_bytes.len() as u64;
|
publish_stats(stats_tx, io_stats);
|
||||||
publish_stats(stats_tx, io_stats);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read response with poll interval
|
// Read response with poll interval
|
||||||
@@ -94,15 +94,17 @@ fn run_tactile_a_loop(
|
|||||||
publish_stats(stats_tx, io_stats);
|
publish_stats(stats_tx, io_stats);
|
||||||
if let Ok(frames) = codec.decode(&buffer[..n], session_started_at) {
|
if let Ok(frames) = codec.decode(&buffer[..n], session_started_at) {
|
||||||
for frame in frames {
|
for frame in frames {
|
||||||
if let TactileAFrame::Rep(rep) = frame
|
if let TactileAFrame::Rep(rep) = frame {
|
||||||
&& let Ok(vals) = TactileACodec::parse_data_frame(&rep.payload)
|
if let Ok(vals) = TactileACodec::parse_data_frame(&rep.payload) {
|
||||||
{
|
if let Some(recorder) = recorder {
|
||||||
if let Some(recorder) = recorder {
|
let pressures: Vec<u32> =
|
||||||
let pressures: Vec<u32> =
|
vals.iter().map(|v| (*v).max(0) as u32).collect();
|
||||||
vals.iter().map(|v| (*v).max(0) as u32).collect();
|
recorder.add_frame(&pressures);
|
||||||
recorder.add_frame(&pressures);
|
}
|
||||||
|
let _ = sample_tx.try_send(vals);
|
||||||
|
io_stats.rx_frames += 1;
|
||||||
|
publish_stats(stats_tx, io_stats);
|
||||||
}
|
}
|
||||||
let _ = sample_tx.try_send(vals);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -192,6 +194,8 @@ fn run_hand_gateway_loop(
|
|||||||
recorder.add_frame(&pressures);
|
recorder.add_frame(&pressures);
|
||||||
}
|
}
|
||||||
let _ = sample_tx.try_send(vals);
|
let _ = sample_tx.try_send(vals);
|
||||||
|
io_stats.rx_frames += 1;
|
||||||
|
publish_stats(stats_tx, io_stats);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
52
src/style.rs
52
src/style.rs
@@ -61,7 +61,7 @@ pub const METRICS: DesignMetrics = DesignMetrics {
|
|||||||
|
|
||||||
pub mod layout {
|
pub mod layout {
|
||||||
pub const TITLE_BAR_HEIGHT: f32 = 36.0;
|
pub const TITLE_BAR_HEIGHT: f32 = 36.0;
|
||||||
pub const CONFIG_BAR_HEIGHT: f32 = 48.0;
|
pub const CONFIG_BAR_HEIGHT: f32 = 38.0;
|
||||||
pub const CENTER_PANEL_TOP: f32 = 48.0;
|
pub const CENTER_PANEL_TOP: f32 = 48.0;
|
||||||
pub const LEFT_X: f32 = 24.0;
|
pub const LEFT_X: f32 = 24.0;
|
||||||
pub const RIGHT_X: f32 = 1328.0;
|
pub const RIGHT_X: f32 = 1328.0;
|
||||||
@@ -77,7 +77,7 @@ pub fn apply_theme(ctx: &egui::Context, theme: &AppTheme) {
|
|||||||
visuals.override_text_color = Some(theme.text);
|
visuals.override_text_color = Some(theme.text);
|
||||||
visuals.panel_fill = theme.bg;
|
visuals.panel_fill = theme.bg;
|
||||||
visuals.window_fill = theme.panel;
|
visuals.window_fill = theme.panel;
|
||||||
visuals.window_stroke = egui::Stroke::new(1.0_f32, theme.border);
|
visuals.window_stroke = egui::Stroke::new(1.0, theme.border);
|
||||||
visuals.extreme_bg_color = theme.panel_deep;
|
visuals.extreme_bg_color = theme.panel_deep;
|
||||||
visuals.faint_bg_color = theme.panel_strong;
|
visuals.faint_bg_color = theme.panel_strong;
|
||||||
visuals.code_bg_color = theme.panel_deep;
|
visuals.code_bg_color = theme.panel_deep;
|
||||||
@@ -85,23 +85,23 @@ pub fn apply_theme(ctx: &egui::Context, theme: &AppTheme) {
|
|||||||
visuals.error_fg_color = ACCENT_RED;
|
visuals.error_fg_color = ACCENT_RED;
|
||||||
|
|
||||||
visuals.widgets.noninteractive.bg_fill = theme.panel_strong;
|
visuals.widgets.noninteractive.bg_fill = theme.panel_strong;
|
||||||
visuals.widgets.noninteractive.bg_stroke = egui::Stroke::new(1.0_f32, theme.border_soft);
|
visuals.widgets.noninteractive.bg_stroke = egui::Stroke::new(1.0, theme.border_soft);
|
||||||
visuals.widgets.noninteractive.fg_stroke = egui::Stroke::new(1.0_f32, theme.text);
|
visuals.widgets.noninteractive.fg_stroke = egui::Stroke::new(1.0, theme.text);
|
||||||
visuals.widgets.inactive.bg_fill = theme.panel_strong;
|
visuals.widgets.inactive.bg_fill = theme.panel_strong;
|
||||||
visuals.widgets.inactive.bg_stroke = egui::Stroke::new(1.0_f32, theme.border_soft);
|
visuals.widgets.inactive.bg_stroke = egui::Stroke::new(1.0, theme.border_soft);
|
||||||
visuals.widgets.inactive.fg_stroke = egui::Stroke::new(1.0_f32, theme.text);
|
visuals.widgets.inactive.fg_stroke = egui::Stroke::new(1.0, theme.text);
|
||||||
visuals.widgets.hovered.bg_fill = egui::Color32::from_rgb(44, 57, 70);
|
visuals.widgets.hovered.bg_fill = egui::Color32::from_rgb(44, 57, 70);
|
||||||
visuals.widgets.hovered.bg_stroke = egui::Stroke::new(1.0_f32, theme.accent);
|
visuals.widgets.hovered.bg_stroke = egui::Stroke::new(1.0, theme.accent);
|
||||||
visuals.widgets.hovered.fg_stroke = egui::Stroke::new(1.0_f32, egui::Color32::WHITE);
|
visuals.widgets.hovered.fg_stroke = egui::Stroke::new(1.0, egui::Color32::WHITE);
|
||||||
visuals.widgets.active.bg_fill = theme.accent;
|
visuals.widgets.active.bg_fill = theme.accent;
|
||||||
visuals.widgets.active.bg_stroke = egui::Stroke::new(1.0_f32, theme.accent_hot);
|
visuals.widgets.active.bg_stroke = egui::Stroke::new(1.0, theme.accent_hot);
|
||||||
visuals.widgets.active.fg_stroke = egui::Stroke::new(1.0_f32, egui::Color32::WHITE);
|
visuals.widgets.active.fg_stroke = egui::Stroke::new(1.0, egui::Color32::WHITE);
|
||||||
visuals.widgets.open.bg_fill = egui::Color32::from_rgb(39, 50, 62);
|
visuals.widgets.open.bg_fill = egui::Color32::from_rgb(39, 50, 62);
|
||||||
visuals.widgets.open.bg_stroke = egui::Stroke::new(1.0_f32, theme.accent);
|
visuals.widgets.open.bg_stroke = egui::Stroke::new(1.0, theme.accent);
|
||||||
visuals.widgets.open.fg_stroke = egui::Stroke::new(1.0_f32, theme.text);
|
visuals.widgets.open.fg_stroke = egui::Stroke::new(1.0, theme.text);
|
||||||
|
|
||||||
visuals.selection.bg_fill = egui::Color32::from_rgb(35, 123, 140);
|
visuals.selection.bg_fill = egui::Color32::from_rgb(35, 123, 140);
|
||||||
visuals.selection.stroke = egui::Stroke::new(1.0_f32, egui::Color32::WHITE);
|
visuals.selection.stroke = egui::Stroke::new(1.0, egui::Color32::WHITE);
|
||||||
visuals.hyperlink_color = theme.accent_hot;
|
visuals.hyperlink_color = theme.accent_hot;
|
||||||
ctx.set_visuals(visuals);
|
ctx.set_visuals(visuals);
|
||||||
|
|
||||||
@@ -127,8 +127,8 @@ pub fn apply_fonts(ctx: &egui::Context) {
|
|||||||
let mut fonts = egui::FontDefinitions::default();
|
let mut fonts = egui::FontDefinitions::default();
|
||||||
|
|
||||||
fonts.font_data.insert(
|
fonts.font_data.insert(
|
||||||
"MapleMono-NF-CN-Bold".to_owned(),
|
"Hack-Bold".to_owned(),
|
||||||
egui::FontData::from_static(include_bytes!("../static/MapleMono-NF-CN-Bold.ttf")).into(),
|
egui::FontData::from_static(include_bytes!("../static/Hack-Bold.ttf")).into(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let has_yahei = std::fs::read(r"C:\Windows\Fonts\msyh.ttc")
|
let has_yahei = std::fs::read(r"C:\Windows\Fonts\msyh.ttc")
|
||||||
@@ -145,7 +145,7 @@ pub fn apply_fonts(ctx: &egui::Context) {
|
|||||||
.families
|
.families
|
||||||
.entry(egui::FontFamily::Proportional)
|
.entry(egui::FontFamily::Proportional)
|
||||||
.or_default()
|
.or_default()
|
||||||
.insert(0, "MapleMono-NF-CN-Bold".to_owned());
|
.insert(0, "Hack-Bold".to_owned());
|
||||||
if has_yahei {
|
if has_yahei {
|
||||||
fonts
|
fonts
|
||||||
.families
|
.families
|
||||||
@@ -158,7 +158,7 @@ pub fn apply_fonts(ctx: &egui::Context) {
|
|||||||
.families
|
.families
|
||||||
.entry(egui::FontFamily::Monospace)
|
.entry(egui::FontFamily::Monospace)
|
||||||
.or_default()
|
.or_default()
|
||||||
.insert(0, "MapleMono-NF-CN-Bold".to_owned());
|
.insert(0, "Hack-Bold".to_owned());
|
||||||
if has_yahei {
|
if has_yahei {
|
||||||
fonts
|
fonts
|
||||||
.families
|
.families
|
||||||
@@ -174,7 +174,7 @@ pub fn panel_frame(ctx: &egui::Context) -> egui::Frame {
|
|||||||
let style = ctx.global_style();
|
let style = ctx.global_style();
|
||||||
egui::Frame::window(&style)
|
egui::Frame::window(&style)
|
||||||
.fill(ONE_DARK_PRO.panel)
|
.fill(ONE_DARK_PRO.panel)
|
||||||
.stroke(egui::Stroke::new(1.0_f32, ONE_DARK_PRO.border))
|
.stroke(egui::Stroke::new(1.0, ONE_DARK_PRO.border))
|
||||||
.corner_radius(egui::CornerRadius::same(ONE_DARK_PRO.radius))
|
.corner_radius(egui::CornerRadius::same(ONE_DARK_PRO.radius))
|
||||||
.inner_margin(egui::Margin::same(METRICS.panel_padding))
|
.inner_margin(egui::Margin::same(METRICS.panel_padding))
|
||||||
.shadow(egui::epaint::Shadow {
|
.shadow(egui::epaint::Shadow {
|
||||||
@@ -198,7 +198,7 @@ pub fn center_panel_frame() -> egui::Frame {
|
|||||||
pub fn group_frame() -> egui::Frame {
|
pub fn group_frame() -> egui::Frame {
|
||||||
egui::Frame::new()
|
egui::Frame::new()
|
||||||
.fill(ONE_DARK_PRO.panel_deep)
|
.fill(ONE_DARK_PRO.panel_deep)
|
||||||
.stroke(egui::Stroke::new(1.0_f32, ONE_DARK_PRO.border_soft))
|
.stroke(egui::Stroke::new(1.0, ONE_DARK_PRO.border_soft))
|
||||||
.corner_radius(egui::CornerRadius::same(4))
|
.corner_radius(egui::CornerRadius::same(4))
|
||||||
.inner_margin(egui::Margin::symmetric(
|
.inner_margin(egui::Margin::symmetric(
|
||||||
METRICS.group_padding_x,
|
METRICS.group_padding_x,
|
||||||
@@ -209,7 +209,7 @@ pub fn group_frame() -> egui::Frame {
|
|||||||
pub fn tag_button(label: impl Into<egui::WidgetText>) -> egui::Button<'static> {
|
pub fn tag_button(label: impl Into<egui::WidgetText>) -> egui::Button<'static> {
|
||||||
egui::Button::new(label)
|
egui::Button::new(label)
|
||||||
.fill(ONE_DARK_PRO.panel_strong)
|
.fill(ONE_DARK_PRO.panel_strong)
|
||||||
.stroke(egui::Stroke::new(1.0_f32, ONE_DARK_PRO.border))
|
.stroke(egui::Stroke::new(1.0, ONE_DARK_PRO.border))
|
||||||
.corner_radius(egui::CornerRadius::same(4))
|
.corner_radius(egui::CornerRadius::same(4))
|
||||||
.min_size(egui::vec2(0.0, METRICS.button_height))
|
.min_size(egui::vec2(0.0, METRICS.button_height))
|
||||||
}
|
}
|
||||||
@@ -222,7 +222,7 @@ pub fn rich_tag_button(
|
|||||||
|
|
||||||
egui::Button::new(text)
|
egui::Button::new(text)
|
||||||
.fill(ONE_DARK_PRO.panel_strong)
|
.fill(ONE_DARK_PRO.panel_strong)
|
||||||
.stroke(egui::Stroke::new(1.0_f32, ONE_DARK_PRO.border))
|
.stroke(egui::Stroke::new(1.0, ONE_DARK_PRO.border))
|
||||||
.corner_radius(egui::CornerRadius::same(4))
|
.corner_radius(egui::CornerRadius::same(4))
|
||||||
.min_size(egui::vec2(0.0, METRICS.button_height))
|
.min_size(egui::vec2(0.0, METRICS.button_height))
|
||||||
}
|
}
|
||||||
@@ -230,7 +230,7 @@ pub fn rich_tag_button(
|
|||||||
pub fn primary_button(label: impl Into<egui::WidgetText>) -> egui::Button<'static> {
|
pub fn primary_button(label: impl Into<egui::WidgetText>) -> egui::Button<'static> {
|
||||||
egui::Button::new(label)
|
egui::Button::new(label)
|
||||||
.fill(ONE_DARK_PRO.accent)
|
.fill(ONE_DARK_PRO.accent)
|
||||||
.stroke(egui::Stroke::new(1.0_f32, ONE_DARK_PRO.accent_hot))
|
.stroke(egui::Stroke::new(1.0, ONE_DARK_PRO.accent_hot))
|
||||||
.corner_radius(egui::CornerRadius::same(4))
|
.corner_radius(egui::CornerRadius::same(4))
|
||||||
.min_size(egui::vec2(112.0, METRICS.button_height))
|
.min_size(egui::vec2(112.0, METRICS.button_height))
|
||||||
}
|
}
|
||||||
@@ -239,7 +239,7 @@ pub fn danger_button(label: impl Into<egui::WidgetText>) -> egui::Button<'static
|
|||||||
egui::Button::new(label)
|
egui::Button::new(label)
|
||||||
.fill(ACCENT_RED)
|
.fill(ACCENT_RED)
|
||||||
.stroke(egui::Stroke::new(
|
.stroke(egui::Stroke::new(
|
||||||
1.0_f32,
|
1.0,
|
||||||
egui::Color32::from_rgb(255, 138, 126),
|
egui::Color32::from_rgb(255, 138, 126),
|
||||||
))
|
))
|
||||||
.corner_radius(egui::CornerRadius::same(4))
|
.corner_radius(egui::CornerRadius::same(4))
|
||||||
@@ -252,7 +252,7 @@ pub fn accent_button(
|
|||||||
) -> egui::Button<'static> {
|
) -> egui::Button<'static> {
|
||||||
egui::Button::new(label)
|
egui::Button::new(label)
|
||||||
.fill(fill)
|
.fill(fill)
|
||||||
.stroke(egui::Stroke::new(1.0_f32, ONE_DARK_PRO.border))
|
.stroke(egui::Stroke::new(1.0, ONE_DARK_PRO.border))
|
||||||
.corner_radius(egui::CornerRadius::same(4))
|
.corner_radius(egui::CornerRadius::same(4))
|
||||||
.min_size(egui::vec2(0.0, METRICS.button_height))
|
.min_size(egui::vec2(0.0, METRICS.button_height))
|
||||||
}
|
}
|
||||||
@@ -271,7 +271,7 @@ pub fn mode_button(label: &'static str, selected: bool) -> egui::Button<'static>
|
|||||||
|
|
||||||
egui::Button::new(egui::RichText::new(label).color(egui::Color32::WHITE))
|
egui::Button::new(egui::RichText::new(label).color(egui::Color32::WHITE))
|
||||||
.fill(fill)
|
.fill(fill)
|
||||||
.stroke(egui::Stroke::new(1.0_f32, stroke))
|
.stroke(egui::Stroke::new(1.0, stroke))
|
||||||
.corner_radius(egui::CornerRadius::same(4))
|
.corner_radius(egui::CornerRadius::same(4))
|
||||||
.min_size(egui::vec2(96.0, METRICS.button_height))
|
.min_size(egui::vec2(96.0, METRICS.button_height))
|
||||||
}
|
}
|
||||||
@@ -279,7 +279,7 @@ pub fn mode_button(label: &'static str, selected: bool) -> egui::Button<'static>
|
|||||||
pub fn icon_button<'a>(icon: impl Into<egui::WidgetText>, size: egui::Vec2) -> egui::Button<'a> {
|
pub fn icon_button<'a>(icon: impl Into<egui::WidgetText>, size: egui::Vec2) -> egui::Button<'a> {
|
||||||
egui::Button::new(icon)
|
egui::Button::new(icon)
|
||||||
.fill(ONE_DARK_PRO.panel_strong)
|
.fill(ONE_DARK_PRO.panel_strong)
|
||||||
.stroke(egui::Stroke::new(1.0_f32, ONE_DARK_PRO.border))
|
.stroke(egui::Stroke::new(1.0, ONE_DARK_PRO.border))
|
||||||
.corner_radius(egui::CornerRadius::same(4))
|
.corner_radius(egui::CornerRadius::same(4))
|
||||||
.min_size(size)
|
.min_size(size)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -187,7 +187,6 @@ impl Texture {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
|
||||||
pub fn from_rgba8_with_sampler(
|
pub fn from_rgba8_with_sampler(
|
||||||
device: &wgpu::Device,
|
device: &wgpu::Device,
|
||||||
queue: &wgpu::Queue,
|
queue: &wgpu::Queue,
|
||||||
|
|||||||
47
src/theme.rs
47
src/theme.rs
@@ -83,6 +83,53 @@ pub fn apply_theme(ctx: &egui::Context, theme: &AppTheme) {
|
|||||||
ctx.set_global_style(style);
|
ctx.set_global_style(style);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn apply_fonts(ctx: &egui::Context) {
|
||||||
|
let mut fonts = egui::FontDefinitions::default();
|
||||||
|
|
||||||
|
fonts.font_data.insert(
|
||||||
|
"Hack-Bold".to_owned(),
|
||||||
|
egui::FontData::from_static(include_bytes!("../static/Hack-Bold.ttf")).into(),
|
||||||
|
);
|
||||||
|
|
||||||
|
let has_yahei = std::fs::read(r"C:\Windows\Fonts\msyh.ttc")
|
||||||
|
.or_else(|_| std::fs::read(r"C:\Windows\Fonts\msyhbd.ttc"))
|
||||||
|
.map(|font_data| {
|
||||||
|
fonts.font_data.insert(
|
||||||
|
"Microsoft-YaHei".to_owned(),
|
||||||
|
egui::FontData::from_owned(font_data).into(),
|
||||||
|
);
|
||||||
|
})
|
||||||
|
.is_ok();
|
||||||
|
|
||||||
|
fonts
|
||||||
|
.families
|
||||||
|
.entry(egui::FontFamily::Proportional)
|
||||||
|
.or_default()
|
||||||
|
.insert(0, "Hack-Bold".to_owned());
|
||||||
|
if has_yahei {
|
||||||
|
fonts
|
||||||
|
.families
|
||||||
|
.entry(egui::FontFamily::Proportional)
|
||||||
|
.or_default()
|
||||||
|
.push("Microsoft-YaHei".to_owned());
|
||||||
|
}
|
||||||
|
|
||||||
|
fonts
|
||||||
|
.families
|
||||||
|
.entry(egui::FontFamily::Monospace)
|
||||||
|
.or_default()
|
||||||
|
.insert(0, "Hack-Bold".to_owned());
|
||||||
|
if has_yahei {
|
||||||
|
fonts
|
||||||
|
.families
|
||||||
|
.entry(egui::FontFamily::Monospace)
|
||||||
|
.or_default()
|
||||||
|
.push("Microsoft-YaHei".to_owned());
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.set_fonts(fonts);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn panel_frame(ctx: &egui::Context) -> egui::Frame {
|
pub fn panel_frame(ctx: &egui::Context) -> egui::Frame {
|
||||||
let style = ctx.global_style();
|
let style = ctx.global_style();
|
||||||
egui::Frame::window(&style)
|
egui::Frame::window(&style)
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
use anyhow;
|
||||||
use serialport::available_ports;
|
use serialport::available_ports;
|
||||||
|
|
||||||
pub fn serial_enum() -> anyhow::Result<Vec<String>> {
|
pub fn serial_enum() -> anyhow::Result<Vec<String>> {
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@@ -63,7 +63,7 @@ fn linear_to_srgb(linear: vec3f) -> vec3f {
|
|||||||
|
|
||||||
fn output_color(linear_rgb: vec3f, alpha: f32) -> vec4f {
|
fn output_color(linear_rgb: vec3f, alpha: f32) -> vec4f {
|
||||||
let clamped = clamp(linear_rgb, vec3f(0.0), vec3f(1.0));
|
let clamped = clamp(linear_rgb, vec3f(0.0), vec3f(1.0));
|
||||||
if (u.color.w > 0.5) {
|
if u.color.w > 0.5 {
|
||||||
return vec4f(clamped, alpha);
|
return vec4f(clamped, alpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,12 +91,12 @@ fn range_stop_color(index: u32) -> vec3f {
|
|||||||
fn sample_range_color(value: f32) -> vec3f {
|
fn sample_range_color(value: f32) -> vec3f {
|
||||||
let t = saturate(value);
|
let t = saturate(value);
|
||||||
|
|
||||||
if (t <= 0.33) {
|
if t <= 0.33 {
|
||||||
let local = smoothstep(0.0, 0.33, t);
|
let local = smoothstep(0.0, 0.33, t);
|
||||||
return mix(range_stop_color(0u), range_stop_color(1u), local);
|
return mix(range_stop_color(0u), range_stop_color(1u), local);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (t <= 0.66) {
|
if t <= 0.66 {
|
||||||
let local = smoothstep(0.33, 0.66, t);
|
let local = smoothstep(0.33, 0.66, t);
|
||||||
return mix(range_stop_color(1u), range_stop_color(2u), local);
|
return mix(range_stop_color(1u), range_stop_color(2u), local);
|
||||||
}
|
}
|
||||||
@@ -105,7 +105,6 @@ fn sample_range_color(value: f32) -> vec3f {
|
|||||||
return mix(range_stop_color(2u), range_stop_color(3u), local);
|
return mix(range_stop_color(2u), range_stop_color(3u), local);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// background
|
// background
|
||||||
struct BackgroundVertexOutput {
|
struct BackgroundVertexOutput {
|
||||||
@builtin(position) clip_position: vec4f,
|
@builtin(position) clip_position: vec4f,
|
||||||
@@ -129,7 +128,6 @@ fn fs_background(@builtin(position) frag_coord: vec4f) -> @location(0) vec4f {
|
|||||||
return output_color(vec3f(0.0, 0.0, 0.0), 1.0);
|
return output_color(vec3f(0.0, 0.0, 0.0), 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// hand image background
|
// hand image background
|
||||||
struct HandImageVertexOutput {
|
struct HandImageVertexOutput {
|
||||||
@builtin(position) clip_position: vec4f,
|
@builtin(position) clip_position: vec4f,
|
||||||
@@ -167,7 +165,7 @@ fn fs_hand_image(in: HandImageVertexOutput) -> @location(0) vec4f {
|
|||||||
let image_aspect = u.image.x / max(u.image.y, 1.0);
|
let image_aspect = u.image.x / max(u.image.y, 1.0);
|
||||||
|
|
||||||
var uv = in.screen_uv;
|
var uv = in.screen_uv;
|
||||||
if (viewport_aspect > image_aspect) {
|
if viewport_aspect > image_aspect {
|
||||||
let image_width = image_aspect / viewport_aspect;
|
let image_width = image_aspect / viewport_aspect;
|
||||||
uv.x = (uv.x - (1.0 - image_width) * 0.5) / image_width;
|
uv.x = (uv.x - (1.0 - image_width) * 0.5) / image_width;
|
||||||
} else {
|
} else {
|
||||||
@@ -175,7 +173,7 @@ fn fs_hand_image(in: HandImageVertexOutput) -> @location(0) vec4f {
|
|||||||
uv.y = (uv.y - (1.0 - image_height) * 0.5) / image_height;
|
uv.y = (uv.y - (1.0 - image_height) * 0.5) / image_height;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uv.x < 0.0 || uv.x > 1.0 || uv.y < 0.0 || uv.y > 1.0) {
|
if uv.x < 0.0 || uv.x > 1.0 || uv.y < 0.0 || uv.y > 1.0 {
|
||||||
discard;
|
discard;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -183,7 +181,6 @@ fn fs_hand_image(in: HandImageVertexOutput) -> @location(0) vec4f {
|
|||||||
return output_color(color.rgb, color.a);
|
return output_color(color.rgb, color.a);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// glyph
|
// glyph
|
||||||
struct GlyphVertexInput {
|
struct GlyphVertexInput {
|
||||||
@location(0) local: vec2f,
|
@location(0) local: vec2f,
|
||||||
@@ -226,45 +223,45 @@ fn digit_segment_on(digit: u32, segment: u32) -> bool {
|
|||||||
|
|
||||||
fn seven_segment_digit_alpha(local: vec2f, digit: u32) -> f32 {
|
fn seven_segment_digit_alpha(local: vec2f, digit: u32) -> f32 {
|
||||||
var alpha = 0.0;
|
var alpha = 0.0;
|
||||||
if (digit_segment_on(digit, 0u)) {
|
if digit_segment_on(digit, 0u) {
|
||||||
alpha = max(alpha, rect_alpha(local, vec2f(0.0, 0.70), vec2f(0.38, 0.078)));
|
alpha = max(alpha, rect_alpha(local, vec2f(0.0, 0.70), vec2f(0.38, 0.078)));
|
||||||
}
|
}
|
||||||
if (digit_segment_on(digit, 1u)) {
|
if digit_segment_on(digit, 1u) {
|
||||||
alpha = max(alpha, rect_alpha(local, vec2f(0.39, 0.36), vec2f(0.078, 0.335)));
|
alpha = max(alpha, rect_alpha(local, vec2f(0.39, 0.36), vec2f(0.078, 0.335)));
|
||||||
}
|
}
|
||||||
if (digit_segment_on(digit, 2u)) {
|
if digit_segment_on(digit, 2u) {
|
||||||
alpha = max(alpha, rect_alpha(local, vec2f(0.39, -0.36), vec2f(0.078, 0.335)));
|
alpha = max(alpha, rect_alpha(local, vec2f(0.39, -0.36), vec2f(0.078, 0.335)));
|
||||||
}
|
}
|
||||||
if (digit_segment_on(digit, 3u)) {
|
if digit_segment_on(digit, 3u) {
|
||||||
alpha = max(alpha, rect_alpha(local, vec2f(0.0, -0.70), vec2f(0.38, 0.078)));
|
alpha = max(alpha, rect_alpha(local, vec2f(0.0, -0.70), vec2f(0.38, 0.078)));
|
||||||
}
|
}
|
||||||
if (digit_segment_on(digit, 4u)) {
|
if digit_segment_on(digit, 4u) {
|
||||||
alpha = max(alpha, rect_alpha(local, vec2f(-0.39, -0.36), vec2f(0.078, 0.335)));
|
alpha = max(alpha, rect_alpha(local, vec2f(-0.39, -0.36), vec2f(0.078, 0.335)));
|
||||||
}
|
}
|
||||||
if (digit_segment_on(digit, 5u)) {
|
if digit_segment_on(digit, 5u) {
|
||||||
alpha = max(alpha, rect_alpha(local, vec2f(-0.39, 0.36), vec2f(0.078, 0.335)));
|
alpha = max(alpha, rect_alpha(local, vec2f(-0.39, 0.36), vec2f(0.078, 0.335)));
|
||||||
}
|
}
|
||||||
if (digit_segment_on(digit, 6u)) {
|
if digit_segment_on(digit, 6u) {
|
||||||
alpha = max(alpha, rect_alpha(local, vec2f(0.0, 0.0), vec2f(0.35, 0.075)));
|
alpha = max(alpha, rect_alpha(local, vec2f(0.0, 0.0), vec2f(0.35, 0.075)));
|
||||||
}
|
}
|
||||||
return alpha;
|
return alpha;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn digit_count(value: u32) -> u32 {
|
fn digit_count(value: u32) -> u32 {
|
||||||
if (value >= 1000u) {
|
if value >= 1000u {
|
||||||
return 4u;
|
return 4u;
|
||||||
}
|
}
|
||||||
if (value >= 100u) {
|
if value >= 100u {
|
||||||
return 3u;
|
return 3u;
|
||||||
}
|
}
|
||||||
if (value >= 10u) {
|
if value >= 10u {
|
||||||
return 2u;
|
return 2u;
|
||||||
}
|
}
|
||||||
return 1u;
|
return 1u;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn digit_at(value: u32, slot: u32, count: u32) -> u32 {
|
fn digit_at(value: u32, slot: u32, count: u32) -> u32 {
|
||||||
if (count == 4u) {
|
if count == 4u {
|
||||||
switch slot {
|
switch slot {
|
||||||
case 0u: { return (value / 1000u) % 10u; }
|
case 0u: { return (value / 1000u) % 10u; }
|
||||||
case 1u: { return (value / 100u) % 10u; }
|
case 1u: { return (value / 100u) % 10u; }
|
||||||
@@ -272,14 +269,14 @@ fn digit_at(value: u32, slot: u32, count: u32) -> u32 {
|
|||||||
default: { return value % 10u; }
|
default: { return value % 10u; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (count == 3u) {
|
if count == 3u {
|
||||||
switch slot {
|
switch slot {
|
||||||
case 0u: { return (value / 100u) % 10u; }
|
case 0u: { return (value / 100u) % 10u; }
|
||||||
case 1u: { return (value / 10u) % 10u; }
|
case 1u: { return (value / 10u) % 10u; }
|
||||||
default: { return value % 10u; }
|
default: { return value % 10u; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (count == 2u) {
|
if count == 2u {
|
||||||
return select(value % 10u, (value / 10u) % 10u, slot == 0u);
|
return select(value % 10u, (value / 10u) % 10u, slot == 0u);
|
||||||
}
|
}
|
||||||
return value % 10u;
|
return value % 10u;
|
||||||
@@ -294,7 +291,7 @@ fn number_alpha(local: vec2f, display_value: f32) -> f32 {
|
|||||||
var alpha = 0.0;
|
var alpha = 0.0;
|
||||||
|
|
||||||
for (var slot = 0u; slot < 4u; slot = slot + 1u) {
|
for (var slot = 0u; slot < 4u; slot = slot + 1u) {
|
||||||
if (slot < count) {
|
if slot < count {
|
||||||
let center_x = start_x + f32(slot) * slot_width;
|
let center_x = start_x + f32(slot) * slot_width;
|
||||||
let digit_local = vec2f((local.x - center_x) / (slot_width * 0.78), local.y / 0.92);
|
let digit_local = vec2f((local.x - center_x) / (slot_width * 0.78), local.y / 0.92);
|
||||||
let digit = digit_at(value, slot, count);
|
let digit = digit_at(value, slot, count);
|
||||||
@@ -335,8 +332,7 @@ struct DotVertexInput {
|
|||||||
|
|
||||||
struct DotInstanceInput {
|
struct DotInstanceInput {
|
||||||
@location(1) world_position: vec4f,
|
@location(1) world_position: vec4f,
|
||||||
@location(2) style: vec4f
|
@location(2) style: vec4f}
|
||||||
}
|
|
||||||
|
|
||||||
struct DotVertexOutput {
|
struct DotVertexOutput {
|
||||||
@builtin(position) clip_position: vec4f,
|
@builtin(position) clip_position: vec4f,
|
||||||
@@ -349,14 +345,16 @@ fn circle_alpha(local: vec2f, radius: f32, softness: f32) -> f32 {
|
|||||||
return 1.0 - smoothstep(radius, radius + softness, dist);
|
return 1.0 - smoothstep(radius, radius + softness, dist);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert a point authored in sensor-canvas UV space into aspect-fitted clip space.
|
// Convert a point authored in hand.png UV space into clip space.
|
||||||
fn sensor_canvas_uv_to_clip(image_uv: vec2f) -> vec2f {
|
// This mirrors fs_hand_image's aspect-fit math, so fingertip dots stay attached
|
||||||
|
// to the same image pixels when the app window changes shape.
|
||||||
|
fn hand_image_uv_to_clip(image_uv: vec2f) -> vec2f {
|
||||||
let viewport_aspect = u.viewport.x / max(u.viewport.y, 1.0);
|
let viewport_aspect = u.viewport.x / max(u.viewport.y, 1.0);
|
||||||
let image_aspect = u.image.x / max(u.image.y, 1.0);
|
let image_aspect = u.image.x / max(u.image.y, 1.0);
|
||||||
|
|
||||||
var screen_uv = image_uv;
|
var screen_uv = image_uv;
|
||||||
|
|
||||||
if (viewport_aspect > image_aspect) {
|
if viewport_aspect > image_aspect {
|
||||||
let image_width = image_aspect / viewport_aspect;
|
let image_width = image_aspect / viewport_aspect;
|
||||||
screen_uv.x = image_uv.x * image_width + (1.0 - image_width) * 0.5;
|
screen_uv.x = image_uv.x * image_width + (1.0 - image_width) * 0.5;
|
||||||
} else {
|
} else {
|
||||||
@@ -384,12 +382,15 @@ fn rounded_rect_alpha(local: vec2f, radius: f32, softness: f32) -> f32 {
|
|||||||
return 1.0 - smoothstep(0.0, softness, dist);
|
return 1.0 - smoothstep(0.0, softness, dist);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn dot_matrix(uv: vec2f, grid: vec2f, dot_radius: f32, dot_softness: f32) -> f32 {
|
||||||
|
let cell = fract(uv * grid) - vec2f(0.5, 0.5);
|
||||||
|
return 1.0 - smoothstep(dot_radius, dot_radius + dot_softness, length(cell));
|
||||||
|
}
|
||||||
|
|
||||||
fn fingertip_film_alpha(
|
fn fingertip_film_alpha(
|
||||||
local: vec2f,
|
local: vec2f,
|
||||||
half_width: f32,
|
half_width: f32,
|
||||||
cap_center_y: f32,
|
cap_center_y: f32,
|
||||||
rear_edge_y: f32,
|
|
||||||
rear_bulge: f32,
|
|
||||||
softness: f32,
|
softness: f32,
|
||||||
) -> f32 {
|
) -> f32 {
|
||||||
// Top/front of the film is a closed round fingertip cap.
|
// Top/front of the film is a closed round fingertip cap.
|
||||||
@@ -397,14 +398,10 @@ fn fingertip_film_alpha(
|
|||||||
let cap = (1.0 - smoothstep(half_width, half_width + softness, cap_dist))
|
let cap = (1.0 - smoothstep(half_width, half_width + softness, cap_dist))
|
||||||
* (1.0 - smoothstep(cap_center_y - softness, cap_center_y + softness, local.y));
|
* (1.0 - smoothstep(cap_center_y - softness, cap_center_y + softness, local.y));
|
||||||
|
|
||||||
// The rear half keeps nearly parallel sides and ends with a shallow arc;
|
// The rear remains open; the carrier quad clips the membrane at its end.
|
||||||
// it deliberately does not converge back into another capsule end.
|
|
||||||
let x_norm = clamp(abs(local.x) / max(half_width, 0.001), 0.0, 1.0);
|
|
||||||
let rear_curve_y = rear_edge_y + rear_bulge * (1.0 - x_norm * x_norm);
|
|
||||||
let side = 1.0 - smoothstep(half_width, half_width + softness, abs(local.x));
|
let side = 1.0 - smoothstep(half_width, half_width + softness, abs(local.x));
|
||||||
let rear = 1.0 - smoothstep(rear_curve_y, rear_curve_y + softness, local.y);
|
|
||||||
let body_gate = smoothstep(cap_center_y - softness, cap_center_y + softness, local.y);
|
let body_gate = smoothstep(cap_center_y - softness, cap_center_y + softness, local.y);
|
||||||
let body = side * rear * body_gate;
|
let body = side * body_gate;
|
||||||
|
|
||||||
return max(cap, body);
|
return max(cap, body);
|
||||||
}
|
}
|
||||||
@@ -418,45 +415,100 @@ fn vs_hand_membrane(vertex: DotVertexInput, instance: DotInstanceInput) -> HandM
|
|||||||
let image_uv = (center_px + rotate_2d(local_px, angle)) / max(u.image.xy, vec2f(1.0, 1.0));
|
let image_uv = (center_px + rotate_2d(local_px, angle)) / max(u.image.xy, vec2f(1.0, 1.0));
|
||||||
|
|
||||||
var out: HandMembraneVertexOutput;
|
var out: HandMembraneVertexOutput;
|
||||||
out.clip_position = vec4f(sensor_canvas_uv_to_clip(image_uv), 0.0, 1.0);
|
out.clip_position = vec4f(hand_image_uv_to_clip(image_uv), 0.0, 1.0);
|
||||||
out.local = vertex.local;
|
out.local = vertex.local;
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@fragment
|
@fragment
|
||||||
fn fs_hand_membrane(in: HandMembraneVertexOutput) -> @location(0) vec4f {
|
fn fs_hand_membrane(in: HandMembraneVertexOutput) -> @location(0) vec4f {
|
||||||
// The film shape matches the fingertip: closed round front, parallel rear sides,
|
let p = in.local;
|
||||||
// and a shallow rear arc instead of a second capsule end.
|
|
||||||
let panel = fingertip_film_alpha(in.local, 0.66, -0.38, 0.72, 0.18, 0.045);
|
|
||||||
let inner = fingertip_film_alpha(in.local, 0.54, -0.36, 0.64, 0.12, 0.060);
|
|
||||||
let border = clamp(panel - inner * 0.52, 0.0, 1.0);
|
|
||||||
|
|
||||||
// Dense mesh: the live 12x7 pressure dots sit over this finer sensor lattice.
|
let halo_shape = fingertip_film_alpha(p, 0.72, -0.20, 0.055);
|
||||||
let uv = clamp(in.local * 0.5 + vec2f(0.5, 0.5), vec2f(0.0, 0.0), vec2f(1.0, 1.0));
|
let panel = fingertip_film_alpha(p, 0.66, -0.22, 0.035);
|
||||||
let grid = vec2f(18.0, 34.0);
|
let inner = fingertip_film_alpha(p, 0.58, -0.25, 0.045);
|
||||||
let cell = uv * grid - vec2f(0.5, 0.5);
|
let clear_inner = fingertip_film_alpha(p, 0.48, -0.24, 0.160);
|
||||||
let nearest = abs(fract(cell + vec2f(0.5, 0.5)) - vec2f(0.5, 0.5));
|
|
||||||
let grid_line = max(
|
let halo = clamp(halo_shape - panel, 0.0, 1.0);
|
||||||
1.0 - smoothstep(0.014, 0.038, nearest.x),
|
let rim = clamp(panel - inner, 0.0, 1.0);
|
||||||
1.0 - smoothstep(0.014, 0.038, nearest.y),
|
let edge_fade = pow(clamp(1.0 - clear_inner, 0.0, 1.0), 1.20) * panel;
|
||||||
|
|
||||||
|
// Strong pseudo extrusion / bevel.
|
||||||
|
let depth_offset = vec2f(0.045, 0.055);
|
||||||
|
let back_shape_1 = fingertip_film_alpha(p - depth_offset * 0.55, 0.66, -0.22, 0.045);
|
||||||
|
let back_shape_2 = fingertip_film_alpha(p - depth_offset, 0.66, -0.22, 0.060);
|
||||||
|
let extrusion = clamp(max(back_shape_1, back_shape_2) - panel, 0.0, 1.0);
|
||||||
|
|
||||||
|
let bevel_offset = vec2f(0.028, 0.034);
|
||||||
|
let shifted_down_right = fingertip_film_alpha(p - bevel_offset, 0.66, -0.22, 0.035);
|
||||||
|
let bevel_light = clamp(panel - shifted_down_right, 0.0, 1.0);
|
||||||
|
let shifted_up_left = fingertip_film_alpha(p + bevel_offset, 0.66, -0.22, 0.035);
|
||||||
|
let bevel_dark = clamp(panel - shifted_up_left, 0.0, 1.0);
|
||||||
|
|
||||||
|
let broad_bevel = edge_fade * clamp(0.58 - p.x * 0.20 - p.y * 0.18, 0.0, 1.0);
|
||||||
|
|
||||||
|
// Micro lattice.
|
||||||
|
let uv = clamp(
|
||||||
|
p * vec2f(0.52, 0.46) + vec2f(0.5, 0.46),
|
||||||
|
vec2f(0.0, 0.0),
|
||||||
|
vec2f(1.0, 1.0),
|
||||||
);
|
);
|
||||||
let joint = 1.0 - smoothstep(0.070, 0.150, length(nearest * vec2f(1.18, 1.0)));
|
|
||||||
let center_shadow = 1.0 - smoothstep(0.10, 0.76, length(in.local * vec2f(0.92, 0.66)));
|
|
||||||
|
|
||||||
let top_light = smoothstep(-0.52, 0.16, -in.local.y) * 0.20;
|
let grid = vec2f(18.0, 34.0);
|
||||||
let side_glow = smoothstep(0.30, 0.70, abs(in.local.x)) * 0.26;
|
let cell_uv = fract(uv * grid) - vec2f(0.5, 0.5);
|
||||||
let lift_shadow = smoothstep(0.48, 0.86, in.local.y) * (1.0 - smoothstep(0.50, 0.86, abs(in.local.x))) * 0.13;
|
let dot_dist = length(cell_uv * vec2f(1.0, 1.06));
|
||||||
let scan = (0.5 + 0.5 * sin((uv.y * 76.0 + uv.x * 9.0) * 6.28318)) * 0.030;
|
let dot_aa = max(fwidth(dot_dist) * 1.35, 0.006);
|
||||||
|
let dots = (1.0 - smoothstep(0.105 - dot_aa, 0.105 + dot_aa, dot_dist)) * inner;
|
||||||
|
|
||||||
let membrane_color = vec3f(0.006, 0.28, 0.38);
|
let sheen_axis = p.x * 0.88 + p.y * 0.22 + 0.16;
|
||||||
let line_color = vec3f(0.12, 0.72, 0.88);
|
let sheen = (1.0 - smoothstep(0.018, 0.105, abs(sheen_axis))) * panel;
|
||||||
let rim_color = vec3f(0.18, 0.98, 1.0);
|
let shell_sheen = sheen * (0.26 + edge_fade * 0.74);
|
||||||
let color = membrane_color * (0.68 + top_light + side_glow + scan)
|
|
||||||
+ line_color * (grid_line * 0.20 + joint * 0.42)
|
// Temporary synthetic pressure hotspot. Real hand pressure dots are drawn above this pass.
|
||||||
+ rim_color * (border * 0.92 + side_glow * 0.18)
|
let pressure_center = vec2f(-0.08, -0.12);
|
||||||
- vec3f(0.0, 0.16, 0.24) * center_shadow * 0.30
|
let pressure_dist = length((p - pressure_center) * vec2f(1.0, 0.74));
|
||||||
- vec3f(0.0, 0.10, 0.16) * lift_shadow;
|
let pressure = (1.0 - smoothstep(0.05, 0.36, pressure_dist)) * inner;
|
||||||
let alpha = panel * (0.24 + grid_line * 0.10 + joint * 0.23 + border * 0.42);
|
let pressure_hot = (1.0 - smoothstep(0.02, 0.13, pressure_dist)) * inner;
|
||||||
|
|
||||||
|
let glass_base = vec3f(0.006, 0.055, 0.105);
|
||||||
|
let glass_cyan = vec3f(0.025, 0.42, 0.58);
|
||||||
|
let rim_color = vec3f(0.10, 0.88, 1.00);
|
||||||
|
let extrusion_color = vec3f(0.004, 0.080, 0.110);
|
||||||
|
let extrusion_edge_color = vec3f(0.015, 0.30, 0.38);
|
||||||
|
let bevel_highlight = vec3f(0.48, 1.00, 1.00);
|
||||||
|
let bevel_dark_color = vec3f(0.004, 0.035, 0.060);
|
||||||
|
let dot_color = vec3f(0.08, 0.48, 0.58);
|
||||||
|
let pressure_color = dot_color;
|
||||||
|
let pressure_hot_color = dot_color;
|
||||||
|
|
||||||
|
let color = extrusion_color * extrusion * 0.90
|
||||||
|
+ extrusion_edge_color * extrusion * halo_shape * 0.32
|
||||||
|
+ glass_base * panel * 0.26
|
||||||
|
+ glass_cyan * edge_fade * 0.46
|
||||||
|
+ glass_cyan * broad_bevel * 0.24
|
||||||
|
+ rim_color * rim * 0.88
|
||||||
|
+ bevel_highlight * bevel_light * 1.35
|
||||||
|
+ bevel_dark_color * bevel_dark * 0.95
|
||||||
|
+ bevel_highlight * shell_sheen * 0.28
|
||||||
|
+ rim_color * halo * 0.16
|
||||||
|
+ dot_color * dots * 0.68
|
||||||
|
+ pressure_color * dots * pressure * 0.82
|
||||||
|
+ pressure_hot_color * dots * pressure_hot * 0.90;
|
||||||
|
|
||||||
|
let alpha = clamp(
|
||||||
|
extrusion * 0.44
|
||||||
|
+ panel * 0.055
|
||||||
|
+ edge_fade * 0.30
|
||||||
|
+ rim * 0.34
|
||||||
|
+ bevel_light * 0.34
|
||||||
|
+ bevel_dark * 0.20
|
||||||
|
+ shell_sheen * 0.09
|
||||||
|
+ halo * 0.045
|
||||||
|
+ dots * 0.09
|
||||||
|
+ dots * pressure * 0.10,
|
||||||
|
0.0,
|
||||||
|
0.90,
|
||||||
|
);
|
||||||
|
|
||||||
return output_color(color, alpha);
|
return output_color(color, alpha);
|
||||||
}
|
}
|
||||||
@@ -468,7 +520,7 @@ fn vs_hand_dot(vertex: DotVertexInput, instance: DotInstanceInput) -> DotVertexO
|
|||||||
let shaped = smoothstep(0.0, 1.0, intensity);
|
let shaped = smoothstep(0.0, 1.0, intensity);
|
||||||
|
|
||||||
// Hand instances store hand.png UV in world_position.xy instead of 3D world space.
|
// Hand instances store hand.png UV in world_position.xy instead of 3D world space.
|
||||||
let center = sensor_canvas_uv_to_clip(instance.world_position.xy);
|
let center = hand_image_uv_to_clip(instance.world_position.xy);
|
||||||
// Hand fingertip matrices are much smaller than the full Finger view.
|
// Hand fingertip matrices are much smaller than the full Finger view.
|
||||||
// Keep each bead below the local cell spacing so the 12x7 matrix remains visibly separated.
|
// Keep each bead below the local cell spacing so the 12x7 matrix remains visibly separated.
|
||||||
let pixel_size = u.glyph.x * mix(0.22, 0.34, shaped);
|
let pixel_size = u.glyph.x * mix(0.22, 0.34, shaped);
|
||||||
@@ -498,14 +550,50 @@ fn fs_hand_dot(in: DotVertexOutput) -> @location(0) vec4f {
|
|||||||
return output_color(color, max(core, halo));
|
return output_color(color, max(core, halo));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn chip_pixel_alpha(local: vec2f, half_size: f32, softness: f32) -> f32 {
|
||||||
|
let q = abs(local) - vec2f(half_size, half_size);
|
||||||
|
let dist = length(max(q, vec2f(0.0, 0.0))) + min(max(q.x, q.y), 0.0);
|
||||||
|
return 1.0 - smoothstep(0.0, softness, dist);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct HandPalmChipVertexOutput {
|
||||||
|
@builtin(position) clip_position: vec4f,
|
||||||
|
@location(0) local: vec2f,
|
||||||
|
@location(1) grid: vec2f,
|
||||||
|
}
|
||||||
|
|
||||||
|
@vertex
|
||||||
|
fn vs_hand_palm_chip(vertex: DotVertexInput, instance: DotInstanceInput) -> HandPalmChipVertexOutput {
|
||||||
|
let center_px = instance.world_position.xy * u.image.xy;
|
||||||
|
let size_px = instance.style.yz;
|
||||||
|
let angle = instance.style.x;
|
||||||
|
let packed_shape = instance.style.w;
|
||||||
|
let shape_rows = floor(packed_shape / 100.0);
|
||||||
|
let shape_cols = max(packed_shape - shape_rows * 100.0, 1.0);
|
||||||
|
let local_px = vertex.local * size_px * 0.5;
|
||||||
|
let image_uv = (center_px + rotate_2d(local_px, angle)) / max(u.image.xy, vec2f(1.0, 1.0));
|
||||||
|
|
||||||
|
var out: HandPalmChipVertexOutput;
|
||||||
|
out.clip_position = vec4f(hand_image_uv_to_clip(image_uv), 0.0, 1.0);
|
||||||
|
out.local = vertex.local;
|
||||||
|
out.grid = vec2f(shape_cols, max(shape_rows, 1.0));
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
@fragment
|
||||||
|
fn fs_hand_palm_chip(in: HandPalmChipVertexOutput) -> @location(0) vec4f {
|
||||||
|
// The live palm-dot pass draws every chip cell, including the idle dots.
|
||||||
|
// Keeping this background pass transparent prevents a second offset dot grid.
|
||||||
|
return output_color(vec3f(0.0, 0.0, 0.0), 0.0);
|
||||||
|
}
|
||||||
|
|
||||||
@vertex
|
@vertex
|
||||||
fn vs_hand_palm_dot(vertex: DotVertexInput, instance: DotInstanceInput) -> DotVertexOutput {
|
fn vs_hand_palm_dot(vertex: DotVertexInput, instance: DotInstanceInput) -> DotVertexOutput {
|
||||||
let intensity = saturate(instance.style.x);
|
let intensity = saturate(instance.style.x);
|
||||||
let shaped = smoothstep(0.0, 1.0, intensity);
|
let shaped = smoothstep(0.0, 1.0, intensity);
|
||||||
|
|
||||||
// Use the same on-screen point size as Finger mode.
|
let center = hand_image_uv_to_clip(instance.world_position.xy);
|
||||||
let center = sensor_canvas_uv_to_clip(instance.world_position.xy);
|
let pixel_size = u.glyph.x * mix(0.22, 0.34, shaped);
|
||||||
let pixel_size = u.glyph.x * mix(1.07, 2.23, shaped);
|
|
||||||
let ndc_offset = vertex.local * vec2f(pixel_size / u.viewport.x, pixel_size / u.viewport.y) * 2.0;
|
let ndc_offset = vertex.local * vec2f(pixel_size / u.viewport.x, pixel_size / u.viewport.y) * 2.0;
|
||||||
|
|
||||||
var out: DotVertexOutput;
|
var out: DotVertexOutput;
|
||||||
@@ -518,12 +606,16 @@ fn vs_hand_palm_dot(vertex: DotVertexInput, instance: DotInstanceInput) -> DotVe
|
|||||||
@fragment
|
@fragment
|
||||||
fn fs_hand_palm_dot(in: DotVertexOutput) -> @location(0) vec4f {
|
fn fs_hand_palm_dot(in: DotVertexOutput) -> @location(0) vec4f {
|
||||||
let intensity = saturate(in.intensity);
|
let intensity = saturate(in.intensity);
|
||||||
let base_color = sample_range_color(intensity);
|
|
||||||
|
|
||||||
let alpha = circle_alpha(in.local, 0.46, 0.045);
|
let core = circle_alpha(in.local, 0.48, 0.07);
|
||||||
let color = base_color * mix(0.86, 1.06, intensity);
|
let halo = circle_alpha(in.local, 0.74, 0.14) * (0.10 + intensity * 0.26);
|
||||||
|
|
||||||
return output_color(color, alpha);
|
let idle = vec3f(0.060, 0.250, 0.320);
|
||||||
|
let gradient = sample_range_color(intensity);
|
||||||
|
let color = mix(idle, gradient, smoothstep(0.0, 0.18, intensity))
|
||||||
|
* mix(0.78, 1.18, intensity);
|
||||||
|
|
||||||
|
return output_color(color, max(core, halo));
|
||||||
}
|
}
|
||||||
|
|
||||||
@vertex
|
@vertex
|
||||||
@@ -553,7 +645,6 @@ fn fs_dot(in: DotVertexOutput) -> @location(0) vec4f {
|
|||||||
return output_color(color, alpha);
|
return output_color(color, alpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// model
|
// model
|
||||||
struct ModelVertexInput {
|
struct ModelVertexInput {
|
||||||
@location(0) position: vec3f,
|
@location(0) position: vec3f,
|
||||||
@@ -672,11 +763,11 @@ fn aces_tonemap(x: vec3f) -> vec3f {
|
|||||||
|
|
||||||
fn material_normal(in: ModelVertexOutput, front_facing: bool) -> vec3f {
|
fn material_normal(in: ModelVertexOutput, front_facing: bool) -> vec3f {
|
||||||
var n = normalize(in.world_normal);
|
var n = normalize(in.world_normal);
|
||||||
if (!front_facing && material.flags.w > 0.5) {
|
if !front_facing && material.flags.w > 0.5 {
|
||||||
n = -n;
|
n = -n;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (material.flags.z < 0.5) {
|
if material.flags.z < 0.5 {
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -696,17 +787,17 @@ fn fs_model(in: ModelVertexOutput, @builtin(front_facing) front_facing: bool) ->
|
|||||||
let base_color = base_sample * material.base_color * in.color;
|
let base_color = base_sample * material.base_color * in.color;
|
||||||
let alpha_mode = material.emissive_alpha.w;
|
let alpha_mode = material.emissive_alpha.w;
|
||||||
var alpha = base_color.a;
|
var alpha = base_color.a;
|
||||||
if (alpha_mode < 0.5) {
|
if alpha_mode < 0.5 {
|
||||||
alpha = 1.0;
|
alpha = 1.0;
|
||||||
} else if (alpha_mode < 1.5) {
|
} else if alpha_mode < 1.5 {
|
||||||
if (alpha < material.flags.x) {
|
if alpha < material.flags.x {
|
||||||
discard;
|
discard;
|
||||||
}
|
}
|
||||||
alpha = 1.0;
|
alpha = 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
let debug_mode = u32(u.render_options.x + 0.5);
|
let debug_mode = u32(u.render_options.x + 0.5);
|
||||||
if (debug_mode == 1u) {
|
if debug_mode == 1u {
|
||||||
return output_color(base_color.rgb, alpha);
|
return output_color(base_color.rgb, alpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -772,7 +863,7 @@ fn fs_model(in: ModelVertexOutput, @builtin(front_facing) front_facing: bool) ->
|
|||||||
let ambient_strength = 0.08;
|
let ambient_strength = 0.08;
|
||||||
// Temporary neutral linear ambient term until a real IBL/HDR environment is added.
|
// Temporary neutral linear ambient term until a real IBL/HDR environment is added.
|
||||||
var ambient = vec3f(0.0);
|
var ambient = vec3f(0.0);
|
||||||
if (u.render_options.y > 0.5) {
|
if u.render_options.y > 0.5 {
|
||||||
let ambient_diffuse = albedo * (1.0 - metallic) * ambient_color * ambient_strength;
|
let ambient_diffuse = albedo * (1.0 - metallic) * ambient_color * ambient_strength;
|
||||||
let ambient_specular = f_ambient * ambient_color * ambient_strength * (1.0 - roughness * 0.55);
|
let ambient_specular = f_ambient * ambient_color * ambient_strength * (1.0 - roughness * 0.55);
|
||||||
ambient = (ambient_diffuse + ambient_specular) * ao;
|
ambient = (ambient_diffuse + ambient_specular) * ao;
|
||||||
@@ -780,7 +871,7 @@ fn fs_model(in: ModelVertexOutput, @builtin(front_facing) front_facing: bool) ->
|
|||||||
|
|
||||||
let exposed_color = (ambient + key + fill + emissive) * max(u.render_options.w, 0.0);
|
let exposed_color = (ambient + key + fill + emissive) * max(u.render_options.w, 0.0);
|
||||||
var color = exposed_color;
|
var color = exposed_color;
|
||||||
if (u.render_options.z > 0.5) {
|
if u.render_options.z > 0.5 {
|
||||||
color = aces_tonemap(exposed_color);
|
color = aces_tonemap(exposed_color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user