13 Commits

Author SHA1 Message Date
lenn
4d0e65c02b toml config support 2026-07-17 13:55:22 +08:00
lenn
ca6ca377df Skip spatial force below display threshold 2026-07-14 15:30:32 +08:00
lenn
801a909c64 Update hand force calibration 2026-07-14 13:51:50 +08:00
lenn
bf7907ce6f Adjust pressure color response 2026-07-14 11:16:17 +08:00
lenn
466bb5dec7 Tune hand pressure visualization 2026-07-14 11:08:00 +08:00
lenn
5af3c2862b 重构手部分段查表逻辑并新增 Excel 数据提取脚本
- src/app.rs: 将 update_hand_signal_histories 改为返回总力作为汇总路径;新增 raw_to_g6/raw_to_g7 与 raw_to_hand_segment_g 索引映射,把 segment 5/6 从兜底 raw_to_gd 拆出,并按 H 版本校准数据更新 g1~g5 的查表数组
2026-07-08 17:45:27 +08:00
lenn
9fb4c0edf4 对五个手指分别进行查表插值 2026-07-07 21:13:37 +08:00
lenn
1e3cfdcf21 shader: collapse palm chip background pass and refine dot rendering 2026-07-07 16:35:19 +08:00
lenn
a04b903e96 Integrate hand fingertip force overlays 2026-07-07 09:43:25 +08:00
lenn
c4bccc1747 refactor: 配置面板改造为顶部固定栏 + 压力归一化优化 2026-07-06 14:07:23 +08:00
lenn
5264f0c247 Tune hand-tip and palm chip layout coordinates
Adjust HandTipMatrix / HandPalmChip center, angle, and size in render.rs and propagate the spacing tweak through shader.wgsl.
2026-07-03 15:30:25 +08:00
lenn
a999d9c064 Refactor to hand-mode UI and reorganize WGSL shader
Replace spatial force / stats panels with unified hand force panels; simplify app.rs wiring and reorganize shader.wgsl for the hand rendering layout.
2026-07-03 13:41:02 +08:00
lenn
71d314ac44 Add finger mode UI and refine breakout/serial integration 2026-07-02 15:22:13 +08:00
29 changed files with 2231 additions and 877 deletions

43
Cargo.lock generated
View File

@@ -1318,8 +1318,11 @@ dependencies = [
"gltf",
"image",
"log",
"serde",
"serialport",
"tobj",
"toml",
"winresource",
]
[[package]]
@@ -3645,6 +3648,15 @@ dependencies = [
"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]]
name = "serialport"
version = "4.9.0"
@@ -3989,6 +4001,21 @@ dependencies = [
"ahash",
]
[[package]]
name = "toml"
version = "1.1.3+spec-1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "53c96ecdfa941c8fc4fcaed14f99ada8ebed502eef533015095a07e3301d4c3c"
dependencies = [
"indexmap",
"serde_core",
"serde_spanned",
"toml_datetime",
"toml_parser",
"toml_writer",
"winnow",
]
[[package]]
name = "toml_datetime"
version = "1.1.1+spec-1.1.0"
@@ -4019,6 +4046,12 @@ dependencies = [
"winnow",
]
[[package]]
name = "toml_writer"
version = "1.1.2+spec-1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7d56353a2a665ad0f41a421187180aab746c8c325620617ad883a99a1cbe66d2"
[[package]]
name = "tracing"
version = "0.1.44"
@@ -5017,6 +5050,16 @@ dependencies = [
"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]]
name = "wit-bindgen"
version = "0.51.0"

View File

@@ -23,11 +23,14 @@ crc = "3.4.0"
log = "0.4.29"
tobj = "4.0.4"
gltf = "1.4.1"
toml = "1.1.3"
serde = { version = "1.0.228", features = ["derive"] }
[build-dependencies]
anyhow = "1.0.102"
fs_extra = "1.3.0"
winresource = "0.1.31"
[[bin]]
name = "ESkinPlayer"

View File

@@ -27,6 +27,14 @@ fn main() -> Result<()> {
copy_items(&items, &resource_dir, &copy_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());
Ok(())

59
config.toml Normal file
View File

@@ -0,0 +1,59 @@
[thumb]
"0.57" = 35694
"2.57" = 226640
"3.57" = 319868
"4.57" = 398021
"5.57" = 450448
"6.57" = 510506
"8.57" = 592075
"10.57" = 655760
"15.57" = 771671
"20.57" = 813967
[index]
"0.57" = 45490
"2.57" = 267579
"3.57" = 352066
"4.57" = 431681
"5.57" = 457605
"6.57" = 550875
"8.57" = 624327
"10.57" = 732735
"15.57" = 883397
"20.57" = 899338
[middle]
"0.57" = 51562
"2.57" = 252840
"3.57" = 326531
"4.57" = 386571
"5.57" = 415819
"6.57" = 514679
"8.57" = 631745
"10.57" = 678945
"15.57" = 810847
"20.57" = 900422
[ring]
"0.57" = 33213
"2.57" = 220611
"3.57" = 307383
"4.57" = 369637
"5.57" = 430462
"6.57" = 489659
"8.57" = 584789
"10.57" = 664960
"15.57" = 802749
"20.57" = 926907
[little]
"0.57" = 44291
"2.57" = 216657
"3.57" = 301950
"4.57" = 366186
"5.57" = 384791
"6.57" = 496521
"8.57" = 566189
"10.57" = 701459
"15.57" = 845608
"20.57" = 940796

BIN
res/128x128@2x.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

BIN
res/icon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

View File

@@ -0,0 +1,275 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
提取 展会数据-H版本.xlsx 中每一组数据并按指定格式输出。
数据组织5 个数据组1#、3#、7#、8#、10#),由空行分隔。
每组包含 10 行指标:
指标 / 1s 均值 / 240s 输出值 / 240s 均值 / 误差(%) /
精度 / b值平均值 / AD值增幅 / AD值漂移 / 增幅/漂移
每行有 12 个数值列C~N与 指标 行的 12 个挡位一一对应。
输出格式(示例):
1#, 115181, 365308, 485911, ...,
3#, 116825, 371568, 475160, ...,
用法:
python extract_excel_data.py [xlsx_path] [选项]
--row LABEL 只输出指定指标行(如 "1s 均值"),可多次指定
--skip-indicators V 跳过指定挡位(按 指标 行数值匹配),可多次指定
--with-title 在每行首部加上组编号(如 "1#, 115181, ..."
--raw 保留原始数值(不取整)
--annotate 在每行末尾附加 " // 组号 指标名" 注释
-o FILE 输出到文件(默认输出到标准输出)
"""
import argparse
import os
import sys
import openpyxl
# 默认 Excel 文件路径
DEFAULT_XLSX = os.path.join(
os.path.dirname(os.path.abspath(__file__)),
"..",
"展会数据-H版本.xlsx",
)
def is_blank_row(row_values):
"""判断是否为空白行(全为 None 或空字符串)。"""
for v in row_values:
if v is None:
continue
if isinstance(v, str) and v.strip() == "":
continue
return False
return True
def is_group_header(row_values):
"""判断是否为组标题行A 列为类似 '1#' '3#' 的编号)。"""
first = row_values[0]
if first is None:
return False
return isinstance(first, str) and first.strip().endswith("#")
def extract_data_rows(ws):
"""
返回一个列表,每个元素是 (group_name, row_label, [12 个数值])。
group_name 为当前组编号row_label 为 B 列标签;数值列表为 C~N 列。
"""
results = []
current_group = None
for row in ws.iter_rows(min_row=1, max_row=ws.max_row, values_only=True):
row = list(row[:14]) # 仅取前 14 列
if is_blank_row(row):
continue
if is_group_header(row):
current_group = row[0]
label = row[1] if len(row) > 1 and row[1] is not None else "指标"
values = row[2:]
results.append((current_group, label, values))
continue
label = row[1] if len(row) > 1 and row[1] is not None else ""
values = row[2:]
if current_group is None:
continue
results.append((current_group, label, values))
return results
def parse_skip_indicators(values):
"""
把命令行传入的 --skip-indicators 值解析为浮点数集合。
支持 "0.97""0.97,1.97" 形式。
"""
out = set()
if not values:
return out
for raw in values:
for token in str(raw).split(","):
token = token.strip()
if not token:
continue
try:
out.add(float(token))
except ValueError:
print(f"警告:无法解析指标值 '{token}',已忽略。", file=sys.stderr)
return out
def indicators_match(a, b, tol=1e-9):
"""浮点数比较(容忍微小误差)。"""
if a is None or b is None:
return False
try:
return abs(float(a) - float(b)) < tol
except (TypeError, ValueError):
return False
def format_value(v, raw=False):
"""
将单元格值格式化为字符串。
raw=False: 数值四舍五入到整数(匹配示例样式)。
raw=True : 保留原始数值。
"""
if v is None:
return "0"
if isinstance(v, bool):
return "1" if v else "0"
if isinstance(v, (int,)):
return str(v)
if isinstance(v, float):
if raw:
if v.is_integer():
return str(int(v))
return f"{v:g}" if abs(v) >= 1e-4 else repr(v)
return str(int(round(v)))
s = str(v).strip()
if s == "":
return "0"
try:
f = float(s)
if raw:
if f.is_integer():
return str(int(f))
return f"{f:g}"
return str(int(round(f)))
except ValueError:
return s
def format_line(values, raw=False):
"""把数值列表格式化为 'v1, v2, ..., vn,' 形式。"""
return ", ".join(format_value(v, raw=raw) for v in values) + ","
def parse_args():
p = argparse.ArgumentParser(
description="提取展会数据 Excel 中的每一行数据。",
)
p.add_argument(
"xlsx",
nargs="?",
default=DEFAULT_XLSX,
help="Excel 文件路径(默认: 展会数据-H版本.xlsx",
)
p.add_argument(
"--row",
action="append",
default=None,
metavar="LABEL",
help='只输出指定指标行(如 "1s 均值"),可多次指定。'
"未指定时输出全部行。",
)
p.add_argument(
"--skip-indicators",
action="append",
default=None,
metavar="V",
help="跳过指定挡位(按 指标 行数值匹配)。可多次指定,"
"也支持逗号分隔。例: --skip-indicators 0.97 --skip-indicators 1.97",
)
p.add_argument(
"--with-title",
action="store_true",
help="在每行首部加上组编号(如 \"1#, 115181, 365308, ...\"",
)
p.add_argument(
"--raw",
action="store_true",
help="保留原始数值(不取整)",
)
p.add_argument(
"--annotate",
action="store_true",
help="在每行末尾附加 // 组号 指标名 注释",
)
p.add_argument(
"-o",
"--output",
default=None,
help="输出文件路径(默认输出到标准输出)",
)
return p.parse_args()
def main():
args = parse_args()
xlsx_path = os.path.abspath(args.xlsx)
if not os.path.exists(xlsx_path):
print(f"错误:找不到文件 {xlsx_path}", file=sys.stderr)
return 1
wb = openpyxl.load_workbook(xlsx_path, data_only=True)
ws = wb.active
rows = extract_data_rows(ws)
if not rows:
print("未找到任何数据。", file=sys.stderr)
return 1
# ===== 列筛选(先做,依赖 指标 行) =====
skip_set = parse_skip_indicators(args.skip_indicators)
if skip_set:
filtered = []
current_indicators = None
for group, label, values in rows:
if label == "指标":
current_indicators = values
if current_indicators is None:
# 没有任何组提供 指标 行作对照,原样保留
filtered.append((group, label, values))
continue
kept = [
v for v, ind in zip(values, current_indicators)
if not any(indicators_match(ind, s) for s in skip_set)
]
filtered.append((group, label, kept))
rows = filtered
# ===== 行筛选(在列筛选之后) =====
if args.row:
wanted = {name.strip() for name in args.row}
rows = [(g, l, v) for (g, l, v) in rows if l in wanted]
if not rows:
print(
f"未找到匹配的行 {args.row}。可用行名请参考 Excel 文件 B 列。",
file=sys.stderr,
)
return 1
out_lines = []
last_group = None
for group, label, values in rows:
if last_group is not None and group != last_group:
out_lines.append("") # 组之间插入空行
last_group = group
line = format_line(values, raw=args.raw)
if args.with_title:
line = f"{group}, {line}"
if args.annotate:
line = f"{line} // {group} {label}"
out_lines.append(line)
text = "\n".join(out_lines) + "\n"
if args.output:
with open(args.output, "w", encoding="utf-8") as f:
f.write(text)
print(f"已写入 {len(rows)} 行数据到 {args.output}", file=sys.stderr)
else:
sys.stdout.write(text)
return 0
if __name__ == "__main__":
sys.exit(main())

File diff suppressed because it is too large Load Diff

View File

@@ -20,6 +20,7 @@ enum BreakoutPhase {
Idle,
Running,
Paused,
Won,
Over,
}
@@ -46,7 +47,6 @@ pub struct BreakoutGame {
score: u32,
combo: u32,
lives: u32,
level: u32,
last_time: Option<f64>,
previous_pause_gesture: bool,
pause_locked_until: f64,
@@ -63,7 +63,6 @@ impl Default for BreakoutGame {
score: 0,
combo: 0,
lives: 3,
level: 1,
last_time: None,
previous_pause_gesture: false,
pause_locked_until: 0.0,
@@ -150,7 +149,6 @@ impl BreakoutGame {
status_chip(ui, "分数", self.score.to_string(), ACCENT_GREEN);
status_chip(ui, "连击", self.combo.to_string(), ACCENT_ORANGE);
status_chip(ui, "生命", self.lives.to_string(), ACCENT_RED);
status_chip(ui, "关卡", self.level.to_string(), ACCENT_BLUE);
});
ui.add_space(7.0);
@@ -191,12 +189,11 @@ impl BreakoutGame {
self.score = 0;
self.combo = 0;
self.lives = 3;
self.level = 1;
self.rebuild_bricks();
}
fn start(&mut self) {
if self.phase == BreakoutPhase::Over {
if self.phase == BreakoutPhase::Over || self.phase == BreakoutPhase::Won {
self.reset();
}
if self.phase != BreakoutPhase::Running {
@@ -219,7 +216,10 @@ impl BreakoutGame {
let threshold = pressure_pause_threshold();
let active = top_force >= threshold;
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();
} else {
self.toggle_pause();
@@ -249,11 +249,7 @@ impl BreakoutGame {
}
fn launch_ball(&mut self) {
let direction = if self.level.is_multiple_of(2) {
-0.24
} else {
0.24
};
let direction = 0.24;
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;
}
@@ -328,9 +324,8 @@ impl BreakoutGame {
}
if self.bricks.iter().all(|brick| !brick.alive) {
self.level += 1;
self.rebuild_bricks();
self.launch_ball();
self.phase = BreakoutPhase::Won;
self.ball_vel = egui::Vec2::ZERO;
}
}
@@ -362,6 +357,7 @@ impl BreakoutGame {
BreakoutPhase::Idle => "待机",
BreakoutPhase::Running => "运行",
BreakoutPhase::Paused => "暂停",
BreakoutPhase::Won => "过关",
BreakoutPhase::Over => "结束",
}
}
@@ -376,7 +372,7 @@ impl BreakoutGame {
painter.rect_stroke(
rect,
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,
);
@@ -391,6 +387,7 @@ impl BreakoutGame {
if self.phase == BreakoutPhase::Idle
|| self.phase == BreakoutPhase::Paused
|| self.phase == BreakoutPhase::Won
|| self.phase == BreakoutPhase::Over
{
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 sample_rows = rows.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 mut sum = 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 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 raw_axis = ((right_force - left_force) / span).clamp(-1.0, 1.0);
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) {
egui::Frame::new()
.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))
.inner_margin(egui::Margin::symmetric(8, 4))
.show(ui, |ui| {
@@ -489,6 +495,7 @@ fn status_color(phase: BreakoutPhase) -> egui::Color32 {
BreakoutPhase::Idle => ONE_DARK_PRO.text_dim,
BreakoutPhase::Running => ACCENT_GREEN,
BreakoutPhase::Paused => ACCENT_ORANGE,
BreakoutPhase::Won => ACCENT_GREEN,
BreakoutPhase::Over => ACCENT_RED,
}
}
@@ -518,7 +525,7 @@ fn paint_arena_grid(painter: &egui::Painter, rect: egui::Rect) {
painter.rect_stroke(
rect,
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,
);
}
@@ -535,7 +542,7 @@ fn paint_brick(painter: &egui::Painter, arena: egui::Rect, brick: &Brick, index:
painter.rect_stroke(
rect.expand(4.0 * brick.flash),
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,
);
}
@@ -568,7 +575,7 @@ fn paint_control_meter(painter: &egui::Painter, arena: egui::Rect, control: Brea
painter.rect_stroke(
meter,
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,
);
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.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;
painter.circle_filled(
@@ -611,6 +618,7 @@ fn paint_center_overlay(painter: &egui::Painter, rect: egui::Rect, phase: Breako
let (title, detail) = match phase {
BreakoutPhase::Idle => ("按压顶部或点击开始", "左右分区压力控制挡板"),
BreakoutPhase::Paused => ("已暂停", "再次按压顶部、P 或点击暂停继续"),
BreakoutPhase::Won => ("恭喜过关", "按压顶部、点击或空格重新开始"),
BreakoutPhase::Over => ("游戏结束", "点击或空格重开"),
BreakoutPhase::Running => ("", ""),
};

70
src/config.rs Normal file
View File

@@ -0,0 +1,70 @@
use serde::Deserialize;
use std::{
collections::BTreeMap,
fs,
path::{Path, PathBuf},
};
#[derive(Debug, Deserialize)]
pub struct HandForceConfig {
pub thumb: BTreeMap<String, u32>,
pub index: BTreeMap<String, u32>,
pub middle: BTreeMap<String, u32>,
pub ring: BTreeMap<String, u32>,
pub little: BTreeMap<String, u32>,
}
pub fn try_load_hand_force_config() -> Option<HandForceConfig> {
let path: PathBuf = std::env::current_exe().ok()?.parent()?.join("config.toml");
load_hand_force_config(&path)
}
fn load_hand_force_config(path: &Path) -> Option<HandForceConfig> {
let content = fs::read_to_string(path).ok()?;
toml::from_str(&content).ok()
}
#[cfg(test)]
mod tests {
use super::*;
use std::time::{SystemTime, UNIX_EPOCH};
#[test]
fn loads_hand_force_config_toml() {
let path = std::env::temp_dir().join(format!(
"eskin-hand-force-config-{}-{}.toml",
std::process::id(),
SystemTime::now()
.duration_since(UNIX_EPOCH)
.expect("system clock should be after Unix epoch")
.as_nanos()
));
fs::write(
&path,
r#"
[thumb]
"0.57" = 35694
"2.57" = 226640
[index]
"0.57" = 45490
[middle]
"0.57" = 51562
[ring]
"0.57" = 33213
[little]
"0.57" = 44291
"#,
)
.expect("test config should be writable");
let config = load_hand_force_config(&path).expect("valid TOML should load");
fs::remove_file(&path).expect("test config should be removable");
assert_eq!(config.thumb["2.57"], 226640);
assert_eq!(config.index["0.57"], 45490);
}
}

View File

@@ -179,7 +179,6 @@ impl Default for ConnectionManager {
}
/// The blocking device loop that runs on a background thread.
#[allow(clippy::too_many_arguments)]
fn run_device_loop(
port_name: &str,
rows: u32,

View File

@@ -1,7 +1,8 @@
use crate::serial_core::multi_dim_force::PztProcessor;
const FINGER_SAMPLE_COUNT: usize = 84;
const MIN_TANGENTIAL_MAGNITUDE: f32 = 0.02;
pub const FINGER_SAMPLE_COUNT: usize = 84;
pub const HAND_FINGERTIP_COUNT: usize = 5;
const MIN_TANGENTIAL_MAGNITUDE: f32 = 0.1;
#[derive(Debug, Clone, Copy)]
pub struct HudSpatialForce {
@@ -11,17 +12,22 @@ pub struct HudSpatialForce {
pub struct ForceEstimatorState {
pzt_processor: PztProcessor,
fingertip_processors: [PztProcessor; HAND_FINGERTIP_COUNT],
}
impl ForceEstimatorState {
pub fn new() -> Self {
Self {
pzt_processor: PztProcessor::new(),
fingertip_processors: std::array::from_fn(|_| PztProcessor::new()),
}
}
pub fn reset(&mut self) {
self.pzt_processor.reset_baseline();
self.fingertip_processors
.iter_mut()
.for_each(PztProcessor::reset_baseline);
}
pub fn analyze(&mut self, values: &[u32]) -> Option<HudSpatialForce> {
@@ -40,6 +46,49 @@ impl ForceEstimatorState {
magnitude: analysis.magnitude,
})
}
pub fn analyze_fingertips(
&mut self,
values: &[u32],
) -> [Option<HudSpatialForce>; HAND_FINGERTIP_COUNT] {
self.analyze_fingertips_masked(values, &[true; HAND_FINGERTIP_COUNT])
}
pub fn analyze_fingertips_masked(
&mut self,
values: &[u32],
enabled: &[bool; HAND_FINGERTIP_COUNT],
) -> [Option<HudSpatialForce>; HAND_FINGERTIP_COUNT] {
let mut forces = [None; HAND_FINGERTIP_COUNT];
for (tip_index, processor) in self.fingertip_processors.iter_mut().enumerate() {
if !enabled[tip_index] {
continue;
}
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 {

View File

@@ -2,6 +2,7 @@
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
mod app;
mod breakout;
mod config;
mod connection;
mod force;
mod matrix;
@@ -20,12 +21,15 @@ use eframe::egui;
fn main() -> eframe::Result<()> {
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 {
renderer: eframe::Renderer::Wgpu,
viewport: egui::ViewportBuilder::default()
.with_inner_size([1920.0, 1080.0])
.with_min_inner_size([1280.0, 720.0])
.with_decorations(false),
.with_decorations(false)
.with_icon(window_icon),
..Default::default()
};

View File

@@ -1,7 +1,5 @@
pub const MATRIX_ROWS: u32 = 12;
pub const MATRIX_COLS: u32 = 7;
pub const UNFOLDED_SENSOR_COUNT: usize = 104;
pub const UNFOLDED_SENSOR_SEGMENT_COUNTS: [usize; 10] = [8, 3, 5, 8, 10, 44, 3, 5, 8, 10];
const BASE_MATRIX_SPAN: f32 = 24.0;
const MATRIX_SPAN_GROWTH: f32 = 0.6;

View File

@@ -145,10 +145,10 @@ impl Recorder {
r.state == RecordingState::Recording || r.state == RecordingState::Paused,
"nothing to stop"
);
if r.state == RecordingState::Paused
&& let Some(ps) = r.pause_start.take()
{
r.paused_duration_ms += ps.elapsed().as_millis() as u64;
if r.state == RecordingState::Paused {
if let Some(ps) = r.pause_start.take() {
r.paused_duration_ms += ps.elapsed().as_millis() as u64;
}
}
r.state = RecordingState::Idle;
Ok(())
@@ -317,14 +317,15 @@ impl Recorder {
}
// Set the start instant so duration_ms() reports the imported span
if !r.frames.is_empty()
&& let Some(last) = r.frames.last()
{
// Pretend the recording happened `last.timestamp_ms` ago
// so that elapsed_ms() would return that value.
// We store a "fake" start by noting the offset.
r.start = Some(Instant::now() - std::time::Duration::from_millis(last.timestamp_ms));
r.paused_duration_ms = 0;
if !r.frames.is_empty() {
if let Some(last) = r.frames.last() {
// Pretend the recording happened `last.timestamp_ms` ago
// so that elapsed_ms() would return that value.
// We store a "fake" start by noting the offset.
r.start =
Some(Instant::now() - std::time::Duration::from_millis(last.timestamp_ms));
r.paused_duration_ms = 0;
}
}
Ok(())

View File

@@ -1,5 +1,5 @@
use crate::{
matrix::{MatrixLayout, UNFOLDED_SENSOR_COUNT, build_view_projection, glyph_world_position},
matrix::{MatrixLayout, build_view_projection, glyph_world_position},
model::{AlphaMode, InstanceRaw, ModelVertex, Vertex},
resources, texture,
};
@@ -44,122 +44,53 @@ pub struct HandGatewayMode {
const HAND_TIP_MATRICES: [HandTipMatrix; 5] = [
HandTipMatrix {
center_px: [260.0, 490.0],
center_px: [263.5, 495.0],
size_px: [70.0, 120.0],
angle_rad: -0.45,
angle_rad: -0.40,
},
HandTipMatrix {
center_px: [360.0, 255.0],
center_px: [362.0, 260.0],
size_px: [70.0, 120.0],
angle_rad: -0.05,
angle_rad: -0.158,
},
HandTipMatrix {
center_px: [485.0, 225.0],
center_px: [480.5, 228.0],
size_px: [70.0, 120.0],
angle_rad: 0.0,
angle_rad: -0.02,
},
HandTipMatrix {
center_px: [595.0, 260.0],
center_px: [594.0, 265.0],
size_px: [70.0, 120.0],
angle_rad: 0.12,
angle_rad: 0.10,
},
HandTipMatrix {
center_px: [705.0, 385.0],
center_px: [693.0, 370.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 UNFOLDED_CELL_SPACING_PX: f32 = 42.0;
const UNFOLDED_SENSOR_CHIPS: [HandPalmChip; 10] = [
// Top cap: 2 rows x 4 columns.
const HAND_PALM_CHIPS: [HandPalmChip; 2] = [
HandPalmChip {
center_px: [425.0, 165.0],
size_px: [176.0, 88.0],
angle_rad: 0.0,
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,
center_px: [530.0, 593.0],
size_px: [258.0, 88.0],
angle_rad: 0.12,
rows: 5,
cols: 1,
sample_offset: 11,
cols: 14,
},
HandPalmChip {
center_px: [236.0, 468.0],
size_px: [46.0, 352.0],
angle_rad: 0.0,
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,
center_px: [610.0, 778.0],
size_px: [82.0, 228.0],
angle_rad: 0.05,
rows: 11,
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_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.
// Coordinates are authored in source-image pixels so they are easy to tune by eye.
@@ -170,15 +101,14 @@ struct HandTipMatrix {
angle_rad: f32,
}
// One block in the flat 270-degree sensor layout. Coordinates use a dedicated
// 850x750 canvas so the unfolded shape stays prominent across window sizes.
// Palm chips follow the hand layout: one horizontal 5x14 matrix and one vertical
// 11x4 matrix, rendered as dark inset chip tiles on the palm.
struct HandPalmChip {
center_px: [f32; 2],
size_px: [f32; 2],
angle_rad: f32,
rows: u32,
cols: u32,
sample_offset: usize,
}
impl egui_wgpu::CallbackTrait for WgpuBackgroundCallback {
@@ -227,6 +157,7 @@ pub struct BackgroundRenderResources {
dot_pipeline: wgpu::RenderPipeline,
hand_membrane_pipeline: wgpu::RenderPipeline,
hand_dot_pipeline: wgpu::RenderPipeline,
hand_palm_chip_pipeline: wgpu::RenderPipeline,
hand_palm_dot_pipeline: wgpu::RenderPipeline,
hand_image_bind_group: wgpu::BindGroup,
hand_image_texture: texture::Texture,
@@ -238,6 +169,8 @@ pub struct BackgroundRenderResources {
hand_membrane_instances: Vec<GlyphInstance>,
hand_dot_instance_buffer: wgpu::Buffer,
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_instances: Vec<GlyphInstance>,
render_options: RenderOptions,
@@ -345,7 +278,10 @@ impl BackgroundRenderResources {
build_view_projection(1.0, &layout),
surface_is_srgb,
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 {
label: Some("Pressure Matrix Uniform Buffer"),
@@ -562,6 +498,8 @@ impl BackgroundRenderResources {
create_hand_membrane_pipeline(device, target_format, &shader, &pipeline_layout);
let hand_dot_pipeline =
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 =
create_hand_palm_dot_pipeline(device, target_format, &shader, &pipeline_layout);
@@ -594,12 +532,13 @@ impl BackgroundRenderResources {
let hand_membrane_instances = build_hand_membrane_instances(
hand_image_texture.width as f32,
hand_image_texture.height as f32,
&[],
);
let hand_membrane_instance_buffer =
device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
label: Some("Hand Fingertip Membrane Instance Buffer"),
contents: bytemuck::cast_slice(&hand_membrane_instances),
usage: wgpu::BufferUsages::VERTEX,
usage: wgpu::BufferUsages::VERTEX | wgpu::BufferUsages::COPY_DST,
});
let hand_dot_instances = build_hand_dot_instances(
rows,
@@ -614,8 +553,23 @@ impl BackgroundRenderResources {
contents: bytemuck::cast_slice(&hand_dot_instances),
usage: wgpu::BufferUsages::VERTEX | wgpu::BufferUsages::COPY_DST,
});
let hand_palm_dot_instances =
build_hand_palm_dot_instances(rows, cols, &[[0.0, 0.0]; PRESSURE_CELL_COUNT]);
let hand_palm_chip_instances = build_hand_palm_chip_instances(
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 =
device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
label: Some("Hand Palm Chip Dot Instance Buffer"),
@@ -637,6 +591,7 @@ impl BackgroundRenderResources {
dot_pipeline,
hand_membrane_pipeline,
hand_dot_pipeline,
hand_palm_chip_pipeline,
hand_palm_dot_pipeline,
hand_image_bind_group,
hand_image_texture,
@@ -647,6 +602,8 @@ impl BackgroundRenderResources {
hand_membrane_instances,
hand_dot_instance_buffer,
hand_dot_instances,
hand_palm_chip_instance_buffer,
hand_palm_chip_instances,
hand_palm_dot_instance_buffer,
hand_palm_dot_instances,
render_options,
@@ -668,7 +625,10 @@ impl BackgroundRenderResources {
build_view_projection(aspect, &self.layout),
self.surface_is_srgb,
self.render_options,
UNFOLDED_CANVAS_SIZE,
[
self.hand_image_texture.width as f32,
self.hand_image_texture.height as f32,
],
);
queue.write_buffer(
&self.uniform_buffer,
@@ -695,8 +655,19 @@ impl BackgroundRenderResources {
hand_pressure
};
// Keep legacy fingertip buffers current while both hardware modes share
// the same renderer resources.
self.hand_membrane_instances = build_hand_membrane_instances(
self.hand_image_texture.width as f32,
self.hand_image_texture.height as f32,
hand_pressure,
);
queue.write_buffer(
&self.hand_membrane_instance_buffer,
0,
bytemuck::cast_slice(&self.hand_membrane_instances),
);
// Hand mode uses UV-anchored fingertip matrices over hand.png.
// Rebuild their instance positions here so pressure colors update every frame.
self.hand_dot_instances = build_hand_dot_instances(
self.rows,
self.cols,
@@ -710,9 +681,15 @@ impl BackgroundRenderResources {
bytemuck::cast_slice(&self.hand_dot_instances),
);
// Rebuild the 104-cell unfolded layout with the latest gateway samples.
self.hand_palm_dot_instances =
build_hand_palm_dot_instances(self.rows, self.cols, hand_pressure);
// Palm chips reuse the same live 12x7 pressure frame, but draw it as
// embedded micro-pixels inside dark chip tiles.
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(
&self.hand_palm_dot_instance_buffer,
0,
@@ -728,7 +705,12 @@ impl BackgroundRenderResources {
match active_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);
}
}
}
@@ -750,7 +732,22 @@ impl BackgroundRenderResources {
fn paint_hand(&self, render_pass: &mut wgpu::RenderPass<'_>, mode: &HandGatewayMode) {
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_vertex_buffer(0, self.glyph_vertex_buffer.slice(..));
render_pass.set_vertex_buffer(1, self.hand_palm_dot_instance_buffer.slice(..));
@@ -1088,6 +1085,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(
device: &wgpu::Device,
target_format: &wgpu::TextureFormat,
@@ -1121,19 +1151,65 @@ fn create_hand_palm_dot_pipeline(
})
}
fn build_hand_membrane_instances(image_width: f32, image_height: f32) -> Vec<GlyphInstance> {
fn build_hand_membrane_instances(
image_width: f32,
image_height: f32,
pressure: &[[f32; 2]],
) -> Vec<GlyphInstance> {
HAND_TIP_MATRICES
.iter()
.map(|tip| {
.enumerate()
.map(|(tip_index, tip)| {
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 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];
let tip_intensity = hand_tip_peak_intensity(pressure, tip_index);
GlyphInstance {
// Membrane shaders read xy as hand.png UV.
world_position: [uv_x, uv_y, 0.0, 1.0],
// Store angle and an oversized source-image pixel size for the floating sensor film.
style: [tip.angle_rad, membrane_size[0], membrane_size[1], 0.0],
// Store angle, source-image pixel size, and the live fingertip peak intensity.
style: [
tip.angle_rad,
membrane_size[0],
membrane_size[1],
tip_intensity,
],
}
})
.collect()
}
fn hand_tip_peak_intensity(pressure: &[[f32; 2]], tip_index: usize) -> f32 {
let start = tip_index * HAND_FINGER_SENSOR_CELLS;
let end = start + HAND_FINGER_SENSOR_CELLS;
pressure
.get(start..end)
.unwrap_or(&[])
.iter()
.map(|sample| sample[0])
.fold(0.0, f32::max)
.clamp(0.0, 1.0)
}
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()
@@ -1163,7 +1239,8 @@ fn build_hand_dot_instances(
// 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_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.
let x = tip.center_px[0] + local_x * cos - local_y * sin;
@@ -1186,27 +1263,44 @@ fn build_hand_dot_instances(
fn build_hand_palm_dot_instances(
_rows: u32,
_cols: u32,
image_width: f32,
image_height: f32,
pressure: &[[f32; 2]],
) -> Vec<GlyphInstance> {
let chip_dot_count: usize = UNFOLDED_SENSOR_CHIPS
let chip_dot_count: usize = HAND_PALM_CHIPS
.iter()
.map(|chip| (chip.rows * chip.cols) as usize)
.sum();
debug_assert_eq!(chip_dot_count, UNFOLDED_SENSOR_COUNT);
let mut instances = Vec::with_capacity(chip_dot_count);
for chip in UNFOLDED_SENSOR_CHIPS {
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 col in 0..chip.cols {
let index = (row * chip.cols + col) as usize;
let offset = match chip_index {
0 => HAND_PALM_HORIZONTAL_OFFSET,
_ => 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, chip.sample_offset + index, index);
let [x, y] = unfolded_cell_position(&chip, row, col);
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 {
world_position: [
x / UNFOLDED_CANVAS_SIZE[0],
y / UNFOLDED_CANVAS_SIZE[1],
x / image_width.max(1.0),
y / image_height.max(1.0),
0.0,
1.0,
],
@@ -1219,20 +1313,12 @@ fn build_hand_palm_dot_instances(
instances
}
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 hand_palm_pressure_index(chip_index: usize, row: u32, col: u32, rows: u32, cols: u32) -> usize {
if chip_index == 0 {
(col * rows + (rows - 1 - row)) as usize
} else {
(row * cols + col) as usize
}
}
fn sample_pressure_at(pressure: &[[f32; 2]], index: usize, fallback_index: usize) -> [f32; 2] {
@@ -1243,122 +1329,6 @@ fn sample_pressure_at(pressure: &[[f32; 2]], index: usize, fallback_index: usize
.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_has_104_contiguous_samples() {
let mut expected_offset = 0usize;
for chip in UNFOLDED_SENSOR_CHIPS {
assert_eq!(chip.sample_offset, expected_offset);
expected_offset += (chip.rows * chip.cols) as usize;
}
assert_eq!(expected_offset, UNFOLDED_SENSOR_COUNT);
}
#[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(
rows: u32,
cols: u32,
@@ -1482,3 +1452,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);
}
}

View File

@@ -38,8 +38,9 @@ pub fn load_texture(
device: &wgpu::Device,
queue: &wgpu::Queue,
) -> anyhow::Result<texture::Texture> {
let data = load_binary(file_name)?;
texture::Texture::from_bytes(device, queue, &data, file_name)
// let data = load_binary(file_name)?;
let data = include_bytes!("../res/hand.png");
texture::Texture::from_bytes(device, queue, data, file_name)
}
pub fn load_model(
@@ -457,7 +458,6 @@ fn create_color_material(
))
}
#[allow(clippy::too_many_arguments)]
fn create_material(
device: &wgpu::Device,
texture_bind_group_layout: &wgpu::BindGroupLayout,
@@ -703,7 +703,6 @@ fn append_gltf_node_meshes(
Ok(())
}
#[allow(clippy::too_many_arguments)]
fn append_gltf_primitive_mesh(
mesh_name: &str,
primitive_index: usize,
@@ -971,7 +970,7 @@ fn rgba_from_chunks(
read_component: fn(&[u8]) -> u8,
) -> anyhow::Result<Vec<u8>> {
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");
}

View File

@@ -127,14 +127,14 @@ pub struct HandGatewayCodec {
}
impl HandGatewayCodec {
pub fn new(node_sample_counts: &[usize]) -> Self {
pub fn new(node_sample_counts: &[u16]) -> Self {
let nodes = node_sample_counts
.iter()
.enumerate()
.map(|(index, &sample_count)| {
HandGatewayNodeConfig::new(
1u32.checked_shl(index as u32).unwrap_or(0),
sample_count,
sample_count as usize,
)
})
.collect();
@@ -146,7 +146,7 @@ impl HandGatewayCodec {
}
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);
}

View File

@@ -31,7 +31,7 @@ impl TactileACodec {
}
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);
}
@@ -132,7 +132,7 @@ impl Codec<TactileAFrame> for TactileACodec {
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 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 {
log::debug!(
"checksum mismatch: expected {:02X}, got {:02X}, frame_len={}",

View File

@@ -5,7 +5,7 @@ const SENSOR_COUNT: usize = SENSOR_ROWS * SENSOR_COLS;
const TOTAL_PRESSURE_LOW_THRESHOLD: f32 = 500.0;
const COP_STABILITY_FRAMES_REQUIRED: usize = 15;
const POST_INIT_WINDOW_CNT: usize = 100;
const POST_INIT_WINDOW_CNT: usize = 50;
const POST_INIT_STABLE_CNT: usize = 50;
const POST_INIT_STABLE_THRESH: f32 = 0.1;
@@ -87,7 +87,7 @@ impl PztProcessor {
return 0.0;
}
if n.is_multiple_of(2) {
if n % 2 == 0 {
(sorted[n / 2 - 1] + sorted[n / 2]) / 2.0
} else {
sorted[n / 2]

View File

@@ -1,4 +1,3 @@
use crate::matrix::UNFOLDED_SENSOR_SEGMENT_COUNTS;
use crate::recording::Recorder;
use crate::serial_core::codec::Codec;
use crate::serial_core::codecs::hand_gateway::{HandGatewayCodec, HandGatewayFrame};
@@ -9,14 +8,13 @@ use std::io::{Read, Write};
use std::time::{Duration, Instant};
const POLL_INTERVAL_MS: u64 = 5;
// 270-degree flat layout:
// top 2x4, left 3/5/8/10x1, center 11x4, right 3/5/8/10x1.
const DEFAULT_HAND_GATEWAY_NODE_SAMPLE_COUNTS: &[usize] = &UNFOLDED_SENSOR_SEGMENT_COUNTS;
const DEFAULT_HAND_GATEWAY_NODE_SAMPLE_COUNTS: &[u16] = &[84, 84, 84, 84, 84, 70, 44];
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
pub struct SerialIoStats {
pub rx_bytes: u64,
pub tx_bytes: u64,
pub rx_frames: u64,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
@@ -27,7 +25,6 @@ pub enum SerialProtocol {
/// Runs the serial polling loop on the calling (background) thread.
/// Sends decoded pressure matrix data (Vec<i32>) to the output channel.
#[allow(clippy::too_many_arguments)]
pub fn run_serial_loop(
port: &mut dyn ReadWrite,
rows: usize,
@@ -77,11 +74,11 @@ fn run_tactile_a_loop(
}
// Send poll request
if let Ok(req_bytes) = codec.encode(&req_frame)
&& port.write_all(&req_bytes).is_ok()
{
io_stats.tx_bytes += req_bytes.len() as u64;
publish_stats(stats_tx, io_stats);
if let Ok(req_bytes) = codec.encode(&req_frame) {
if port.write_all(&req_bytes).is_ok() {
io_stats.tx_bytes += req_bytes.len() as u64;
publish_stats(stats_tx, io_stats);
}
}
// Read response with poll interval
@@ -97,15 +94,17 @@ fn run_tactile_a_loop(
publish_stats(stats_tx, io_stats);
if let Ok(frames) = codec.decode(&buffer[..n], session_started_at) {
for frame in frames {
if let TactileAFrame::Rep(rep) = frame
&& let Ok(vals) = TactileACodec::parse_data_frame(&rep.payload)
{
if let Some(recorder) = recorder {
let pressures: Vec<u32> =
vals.iter().map(|v| (*v).max(0) as u32).collect();
recorder.add_frame(&pressures);
if let TactileAFrame::Rep(rep) = frame {
if let Ok(vals) = TactileACodec::parse_data_frame(&rep.payload) {
if let Some(recorder) = recorder {
let pressures: Vec<u32> =
vals.iter().map(|v| (*v).max(0) as u32).collect();
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);
}
}
}
@@ -195,6 +194,8 @@ fn run_hand_gateway_loop(
recorder.add_frame(&pressures);
}
let _ = sample_tx.try_send(vals);
io_stats.rx_frames += 1;
publish_stats(stats_tx, io_stats);
}
}
}

View File

@@ -61,7 +61,7 @@ pub const METRICS: DesignMetrics = DesignMetrics {
pub mod layout {
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 LEFT_X: f32 = 24.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.panel_fill = theme.bg;
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.faint_bg_color = theme.panel_strong;
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.widgets.noninteractive.bg_fill = theme.panel_strong;
visuals.widgets.noninteractive.bg_stroke = egui::Stroke::new(1.0_f32, theme.border_soft);
visuals.widgets.noninteractive.fg_stroke = egui::Stroke::new(1.0_f32, theme.text);
visuals.widgets.noninteractive.bg_stroke = egui::Stroke::new(1.0, theme.border_soft);
visuals.widgets.noninteractive.fg_stroke = egui::Stroke::new(1.0, theme.text);
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.fg_stroke = egui::Stroke::new(1.0_f32, theme.text);
visuals.widgets.inactive.bg_stroke = egui::Stroke::new(1.0, theme.border_soft);
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_stroke = egui::Stroke::new(1.0_f32, theme.accent);
visuals.widgets.hovered.fg_stroke = egui::Stroke::new(1.0_f32, egui::Color32::WHITE);
visuals.widgets.hovered.bg_stroke = egui::Stroke::new(1.0, theme.accent);
visuals.widgets.hovered.fg_stroke = egui::Stroke::new(1.0, egui::Color32::WHITE);
visuals.widgets.active.bg_fill = theme.accent;
visuals.widgets.active.bg_stroke = egui::Stroke::new(1.0_f32, theme.accent_hot);
visuals.widgets.active.fg_stroke = egui::Stroke::new(1.0_f32, egui::Color32::WHITE);
visuals.widgets.active.bg_stroke = egui::Stroke::new(1.0, theme.accent_hot);
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_stroke = egui::Stroke::new(1.0_f32, theme.accent);
visuals.widgets.open.fg_stroke = egui::Stroke::new(1.0_f32, theme.text);
visuals.widgets.open.bg_stroke = egui::Stroke::new(1.0, theme.accent);
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.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;
ctx.set_visuals(visuals);
@@ -127,8 +127,8 @@ pub fn apply_fonts(ctx: &egui::Context) {
let mut fonts = egui::FontDefinitions::default();
fonts.font_data.insert(
"MapleMono-NF-CN-Bold".to_owned(),
egui::FontData::from_static(include_bytes!("../static/MapleMono-NF-CN-Bold.ttf")).into(),
"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")
@@ -145,7 +145,7 @@ pub fn apply_fonts(ctx: &egui::Context) {
.families
.entry(egui::FontFamily::Proportional)
.or_default()
.insert(0, "MapleMono-NF-CN-Bold".to_owned());
.insert(0, "Hack-Bold".to_owned());
if has_yahei {
fonts
.families
@@ -158,7 +158,7 @@ pub fn apply_fonts(ctx: &egui::Context) {
.families
.entry(egui::FontFamily::Monospace)
.or_default()
.insert(0, "MapleMono-NF-CN-Bold".to_owned());
.insert(0, "Hack-Bold".to_owned());
if has_yahei {
fonts
.families
@@ -174,7 +174,7 @@ pub fn panel_frame(ctx: &egui::Context) -> egui::Frame {
let style = ctx.global_style();
egui::Frame::window(&style)
.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))
.inner_margin(egui::Margin::same(METRICS.panel_padding))
.shadow(egui::epaint::Shadow {
@@ -198,7 +198,7 @@ pub fn center_panel_frame() -> egui::Frame {
pub fn group_frame() -> egui::Frame {
egui::Frame::new()
.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))
.inner_margin(egui::Margin::symmetric(
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> {
egui::Button::new(label)
.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))
.min_size(egui::vec2(0.0, METRICS.button_height))
}
@@ -222,7 +222,7 @@ pub fn rich_tag_button(
egui::Button::new(text)
.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))
.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> {
egui::Button::new(label)
.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))
.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)
.fill(ACCENT_RED)
.stroke(egui::Stroke::new(
1.0_f32,
1.0,
egui::Color32::from_rgb(255, 138, 126),
))
.corner_radius(egui::CornerRadius::same(4))
@@ -252,7 +252,7 @@ pub fn accent_button(
) -> egui::Button<'static> {
egui::Button::new(label)
.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))
.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))
.fill(fill)
.stroke(egui::Stroke::new(1.0_f32, stroke))
.stroke(egui::Stroke::new(1.0, stroke))
.corner_radius(egui::CornerRadius::same(4))
.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> {
egui::Button::new(icon)
.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))
.min_size(size)
}

View File

@@ -187,7 +187,6 @@ impl Texture {
)
}
#[allow(clippy::too_many_arguments)]
pub fn from_rgba8_with_sampler(
device: &wgpu::Device,
queue: &wgpu::Queue,

View File

@@ -83,6 +83,53 @@ pub fn apply_theme(ctx: &egui::Context, theme: &AppTheme) {
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 {
let style = ctx.global_style();
egui::Frame::window(&style)

731
src/ui.rs

File diff suppressed because it is too large Load Diff

View File

@@ -1,3 +1,4 @@
use anyhow;
use serialport::available_ports;
pub fn serial_enum() -> anyhow::Result<Vec<String>> {

Binary file not shown.

Binary file not shown.

View File

@@ -63,7 +63,7 @@ fn linear_to_srgb(linear: vec3f) -> vec3f {
fn output_color(linear_rgb: vec3f, alpha: f32) -> vec4f {
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);
}
@@ -91,21 +91,20 @@ fn range_stop_color(index: u32) -> vec3f {
fn sample_range_color(value: f32) -> vec3f {
let t = saturate(value);
if (t <= 0.33) {
if t <= 0.33 {
let local = smoothstep(0.0, 0.33, t);
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);
return mix(range_stop_color(1u), range_stop_color(2u), local);
}
let local = smoothstep(0.66, 1.0, t);
let local = smoothstep(0.66, 0.92, t);
return mix(range_stop_color(2u), range_stop_color(3u), local);
}
// background
struct BackgroundVertexOutput {
@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);
}
// hand image background
struct HandImageVertexOutput {
@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);
var uv = in.screen_uv;
if (viewport_aspect > image_aspect) {
if viewport_aspect > image_aspect {
let image_width = image_aspect / viewport_aspect;
uv.x = (uv.x - (1.0 - image_width) * 0.5) / image_width;
} 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;
}
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;
}
@@ -183,7 +181,6 @@ fn fs_hand_image(in: HandImageVertexOutput) -> @location(0) vec4f {
return output_color(color.rgb, color.a);
}
// glyph
struct GlyphVertexInput {
@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 {
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)));
}
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)));
}
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)));
}
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)));
}
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)));
}
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)));
}
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)));
}
return alpha;
}
fn digit_count(value: u32) -> u32 {
if (value >= 1000u) {
if value >= 1000u {
return 4u;
}
if (value >= 100u) {
if value >= 100u {
return 3u;
}
if (value >= 10u) {
if value >= 10u {
return 2u;
}
return 1u;
}
fn digit_at(value: u32, slot: u32, count: u32) -> u32 {
if (count == 4u) {
if count == 4u {
switch slot {
case 0u: { return (value / 1000u) % 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; }
}
}
if (count == 3u) {
if count == 3u {
switch slot {
case 0u: { return (value / 100u) % 10u; }
case 1u: { return (value / 10u) % 10u; }
default: { return value % 10u; }
}
}
if (count == 2u) {
if count == 2u {
return select(value % 10u, (value / 10u) % 10u, slot == 0u);
}
return value % 10u;
@@ -294,7 +291,7 @@ fn number_alpha(local: vec2f, display_value: f32) -> f32 {
var alpha = 0.0;
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 digit_local = vec2f((local.x - center_x) / (slot_width * 0.78), local.y / 0.92);
let digit = digit_at(value, slot, count);
@@ -335,8 +332,7 @@ struct DotVertexInput {
struct DotInstanceInput {
@location(1) world_position: vec4f,
@location(2) style: vec4f
}
@location(2) style: vec4f}
struct DotVertexOutput {
@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);
}
// Convert a point authored in sensor-canvas UV space into aspect-fitted clip space.
fn sensor_canvas_uv_to_clip(image_uv: vec2f) -> vec2f {
// Convert a point authored in hand.png UV space into clip space.
// 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 image_aspect = u.image.x / max(u.image.y, 1.0);
var screen_uv = image_uv;
if (viewport_aspect > image_aspect) {
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 {
@@ -370,6 +368,7 @@ fn sensor_canvas_uv_to_clip(image_uv: vec2f) -> vec2f {
struct HandMembraneVertexOutput {
@builtin(position) clip_position: vec4f,
@location(0) local: vec2f,
@location(1) intensity: f32,
}
fn rotate_2d(point: vec2f, angle: f32) -> vec2f {
@@ -384,12 +383,15 @@ fn rounded_rect_alpha(local: vec2f, radius: f32, softness: f32) -> f32 {
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(
local: vec2f,
half_width: f32,
cap_center_y: f32,
rear_edge_y: f32,
rear_bulge: f32,
softness: f32,
) -> f32 {
// Top/front of the film is a closed round fingertip cap.
@@ -397,14 +399,10 @@ fn fingertip_film_alpha(
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));
// The rear half keeps nearly parallel sides and ends with a shallow arc;
// 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);
// The rear remains open; the carrier quad clips the membrane at its end.
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 = side * rear * body_gate;
let body = side * body_gate;
return max(cap, body);
}
@@ -418,47 +416,112 @@ 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));
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.intensity = saturate(instance.style.w);
return out;
}
@fragment
fn fs_hand_membrane(in: HandMembraneVertexOutput) -> @location(0) vec4f {
// The film shape matches the fingertip: closed round front, parallel rear sides,
// 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);
let p = in.local;
let live = saturate(in.intensity);
let response = smoothstep(0.03, 0.96, live);
let hot = smoothstep(0.72, 0.96, live);
let live_color = sample_range_color(live);
// Dense mesh: the live 12x7 pressure dots sit over this finer sensor lattice.
let uv = clamp(in.local * 0.5 + vec2f(0.5, 0.5), vec2f(0.0, 0.0), vec2f(1.0, 1.0));
let grid = vec2f(18.0, 34.0);
let cell = uv * grid - vec2f(0.5, 0.5);
let nearest = abs(fract(cell + vec2f(0.5, 0.5)) - vec2f(0.5, 0.5));
let grid_line = max(
1.0 - smoothstep(0.014, 0.038, nearest.x),
1.0 - smoothstep(0.014, 0.038, nearest.y),
let halo_shape = fingertip_film_alpha(p, 0.72, -0.20, 0.055);
let panel = fingertip_film_alpha(p, 0.66, -0.22, 0.035);
let inner = fingertip_film_alpha(p, 0.58, -0.25, 0.045);
let clear_inner = fingertip_film_alpha(p, 0.48, -0.24, 0.160);
let halo = clamp(halo_shape - panel, 0.0, 1.0);
let rim = clamp(panel - inner, 0.0, 1.0);
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 side_glow = smoothstep(0.30, 0.70, abs(in.local.x)) * 0.26;
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 scan = (0.5 + 0.5 * sin((uv.y * 76.0 + uv.x * 9.0) * 6.28318)) * 0.030;
let grid = vec2f(18.0, 34.0);
let cell_uv = fract(uv * grid) - vec2f(0.5, 0.5);
let dot_dist = length(cell_uv * vec2f(1.0, 1.06));
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 line_color = vec3f(0.12, 0.72, 0.88);
let rim_color = vec3f(0.18, 0.98, 1.0);
let color = membrane_color * (0.68 + top_light + side_glow + scan)
+ line_color * (grid_line * 0.20 + joint * 0.42)
+ rim_color * (border * 0.92 + side_glow * 0.18)
- vec3f(0.0, 0.16, 0.24) * center_shadow * 0.30
- vec3f(0.0, 0.10, 0.16) * lift_shadow;
let alpha = panel * (0.24 + grid_line * 0.10 + joint * 0.23 + border * 0.42);
let sheen_axis = p.x * 0.88 + p.y * 0.22 + 0.16;
let sheen = (1.0 - smoothstep(0.018, 0.105, abs(sheen_axis))) * panel;
let shell_sheen = sheen * (0.26 + edge_fade * 0.74);
return output_color(color, alpha);
// Temporary synthetic pressure hotspot. Real hand pressure dots are drawn above this pass.
let pressure_center = vec2f(-0.08, -0.12);
let pressure_dist = length((p - pressure_center) * vec2f(1.0, 0.74));
let pressure = (1.0 - smoothstep(0.05, 0.36, pressure_dist)) * inner;
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 glass_live = mix(glass_cyan, live_color * 0.58, response);
let rim_color = mix(vec3f(0.10, 0.88, 1.00), live_color, response);
let extrusion_color = vec3f(0.004, 0.080, 0.110);
let extrusion_edge_color = mix(vec3f(0.015, 0.30, 0.38), live_color * 0.72, response);
let bevel_highlight = mix(vec3f(0.48, 1.00, 1.00), live_color, response * 0.82);
let bevel_dark_color = vec3f(0.004, 0.035, 0.060);
let dot_color = mix(vec3f(0.08, 0.48, 0.58), live_color, response);
let pressure_color = mix(dot_color, live_color, response);
let pressure_hot_color = live_color;
let membrane_color = extrusion_color * extrusion * 0.90
+ extrusion_edge_color * extrusion * halo_shape * 0.32
+ glass_base * panel * 0.26
+ glass_live * edge_fade * 0.46
+ glass_live * 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 live_wash = live_color * response * (inner * 0.12 + dots * 0.72 + rim * 0.30)
+ live_color * hot * (inner * 0.08 + dots * 0.22);
let color = membrane_color + live_wash;
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,
) + response * (dots * 0.07 + rim * 0.035) + hot * dots * 0.04;
return output_color(color, clamp(alpha, 0.0, 0.96));
}
@vertex
@@ -468,7 +531,7 @@ fn vs_hand_dot(vertex: DotVertexInput, instance: DotInstanceInput) -> DotVertexO
let shaped = smoothstep(0.0, 1.0, intensity);
// 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.
// 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);
@@ -498,14 +561,52 @@ fn fs_hand_dot(in: DotVertexOutput) -> @location(0) vec4f {
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
fn vs_hand_palm_dot(vertex: DotVertexInput, instance: DotInstanceInput) -> DotVertexOutput {
let intensity = saturate(instance.style.x);
let shaped = smoothstep(0.0, 1.0, intensity);
// Use the same on-screen point size as Finger mode.
let center = sensor_canvas_uv_to_clip(instance.world_position.xy);
let pixel_size = u.glyph.x * mix(1.07, 2.23, shaped);
let center = hand_image_uv_to_clip(instance.world_position.xy);
// Palm boards have more tightly packed cells than the fingertips, so use
// a larger circular mask to keep each sensor visibly readable.
let pixel_size = u.glyph.x * mix(0.40, 0.54, shaped);
let ndc_offset = vertex.local * vec2f(pixel_size / u.viewport.x, pixel_size / u.viewport.y) * 2.0;
var out: DotVertexOutput;
@@ -518,12 +619,16 @@ fn vs_hand_palm_dot(vertex: DotVertexInput, instance: DotInstanceInput) -> DotVe
@fragment
fn fs_hand_palm_dot(in: DotVertexOutput) -> @location(0) vec4f {
let intensity = saturate(in.intensity);
let base_color = sample_range_color(intensity);
let alpha = circle_alpha(in.local, 0.46, 0.045);
let color = base_color * mix(0.86, 1.06, intensity);
let core = circle_alpha(in.local, 0.48, 0.07);
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
@@ -553,7 +658,6 @@ fn fs_dot(in: DotVertexOutput) -> @location(0) vec4f {
return output_color(color, alpha);
}
// model
struct ModelVertexInput {
@location(0) position: vec3f,
@@ -672,11 +776,11 @@ fn aces_tonemap(x: vec3f) -> vec3f {
fn material_normal(in: ModelVertexOutput, front_facing: bool) -> vec3f {
var n = normalize(in.world_normal);
if (!front_facing && material.flags.w > 0.5) {
if !front_facing && material.flags.w > 0.5 {
n = -n;
}
if (material.flags.z < 0.5) {
if material.flags.z < 0.5 {
return n;
}
@@ -696,17 +800,17 @@ fn fs_model(in: ModelVertexOutput, @builtin(front_facing) front_facing: bool) ->
let base_color = base_sample * material.base_color * in.color;
let alpha_mode = material.emissive_alpha.w;
var alpha = base_color.a;
if (alpha_mode < 0.5) {
if alpha_mode < 0.5 {
alpha = 1.0;
} else if (alpha_mode < 1.5) {
if (alpha < material.flags.x) {
} else if alpha_mode < 1.5 {
if alpha < material.flags.x {
discard;
}
alpha = 1.0;
}
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);
}
@@ -772,7 +876,7 @@ fn fs_model(in: ModelVertexOutput, @builtin(front_facing) front_facing: bool) ->
let ambient_strength = 0.08;
// Temporary neutral linear ambient term until a real IBL/HDR environment is added.
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_specular = f_ambient * ambient_color * ambient_strength * (1.0 - roughness * 0.55);
ambient = (ambient_diffuse + ambient_specular) * ao;
@@ -780,7 +884,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);
var color = exposed_color;
if (u.render_options.z > 0.5) {
if u.render_options.z > 0.5 {
color = aces_tonemap(exposed_color);
}