Compare commits
1 Commits
waic-hand-
...
waic-finge
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9efe360a1d |
43
Cargo.lock
generated
43
Cargo.lock
generated
@@ -1318,11 +1318,8 @@ dependencies = [
|
|||||||
"gltf",
|
"gltf",
|
||||||
"image",
|
"image",
|
||||||
"log",
|
"log",
|
||||||
"serde",
|
|
||||||
"serialport",
|
"serialport",
|
||||||
"tobj",
|
"tobj",
|
||||||
"toml",
|
|
||||||
"winresource",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -3648,15 +3645,6 @@ 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"
|
||||||
@@ -4001,21 +3989,6 @@ dependencies = [
|
|||||||
"ahash",
|
"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]]
|
[[package]]
|
||||||
name = "toml_datetime"
|
name = "toml_datetime"
|
||||||
version = "1.1.1+spec-1.1.0"
|
version = "1.1.1+spec-1.1.0"
|
||||||
@@ -4046,12 +4019,6 @@ dependencies = [
|
|||||||
"winnow",
|
"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]]
|
[[package]]
|
||||||
name = "tracing"
|
name = "tracing"
|
||||||
version = "0.1.44"
|
version = "0.1.44"
|
||||||
@@ -5050,16 +5017,6 @@ 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"
|
||||||
|
|||||||
@@ -23,14 +23,11 @@ crc = "3.4.0"
|
|||||||
log = "0.4.29"
|
log = "0.4.29"
|
||||||
tobj = "4.0.4"
|
tobj = "4.0.4"
|
||||||
gltf = "1.4.1"
|
gltf = "1.4.1"
|
||||||
toml = "1.1.3"
|
|
||||||
serde = { version = "1.0.228", features = ["derive"] }
|
|
||||||
|
|
||||||
|
|
||||||
[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,14 +27,6 @@ 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(())
|
||||||
|
|||||||
59
config.toml
59
config.toml
@@ -1,59 +0,0 @@
|
|||||||
[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
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 28 KiB |
BIN
res/icon.ico
BIN
res/icon.ico
Binary file not shown.
|
Before Width: | Height: | Size: 41 KiB |
@@ -1,275 +0,0 @@
|
|||||||
#!/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())
|
|
||||||
749
src/app.rs
749
src/app.rs
@@ -1,7 +1,6 @@
|
|||||||
use crate::breakout::{BreakoutGame, control_from_matrix};
|
use crate::breakout::{BreakoutGame, control_from_matrix};
|
||||||
use crate::config::{HandForceConfig, try_load_hand_force_config};
|
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::{ONE_DARK_PRO, apply_fonts, apply_theme, layout};
|
use crate::style::{ONE_DARK_PRO, apply_fonts, apply_theme, layout};
|
||||||
@@ -14,11 +13,10 @@ use crate::{
|
|||||||
},
|
},
|
||||||
ui::{
|
ui::{
|
||||||
ConfigPanelState, ConnectPanelState, FloatingPanelState, MatrixConfigState,
|
ConfigPanelState, ConnectPanelState, FloatingPanelState, MatrixConfigState,
|
||||||
draw_config_panel, draw_hand_force_panels, panel_restore_item,
|
draw_config_panel, draw_spatial_force_panel, draw_stats_panel, panel_restore_item,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use eframe::{egui, egui_wgpu};
|
use eframe::{egui, egui_wgpu};
|
||||||
use std::collections::BTreeMap;
|
|
||||||
use std::{
|
use std::{
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
time::{Duration, Instant},
|
time::{Duration, Instant},
|
||||||
@@ -27,17 +25,7 @@ use std::{
|
|||||||
const SUMMARY_POINTS_PER_SERIES: usize = 42;
|
const SUMMARY_POINTS_PER_SERIES: usize = 42;
|
||||||
const HAND_FORCE_PANEL_COUNT: usize = 7;
|
const HAND_FORCE_PANEL_COUNT: usize = 7;
|
||||||
const HAND_FORCE_SEGMENT_COUNTS: [usize; HAND_FORCE_PANEL_COUNT] = [84, 84, 84, 84, 84, 70, 44];
|
const HAND_FORCE_SEGMENT_COUNTS: [usize; HAND_FORCE_PANEL_COUNT] = [84, 84, 84, 84, 84, 70, 44];
|
||||||
const HAND_FORCE_DISPLAY_THRESHOLD_N: f32 = 0.05;
|
|
||||||
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 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,
|
||||||
@@ -59,20 +47,16 @@ 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>,
|
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>,
|
|
||||||
last_color_debug_at: Option<Instant>,
|
|
||||||
breakout_visible: bool,
|
breakout_visible: bool,
|
||||||
breakout_game: BreakoutGame,
|
breakout_game: BreakoutGame,
|
||||||
live_rates: LiveRateMeters,
|
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,
|
||||||
hand_force_config: Option<HandForceConfig>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct LiveRateMeters {
|
struct LiveRateMeters {
|
||||||
@@ -140,7 +124,6 @@ impl EskinDesktopApp {
|
|||||||
MATRIX_COLS,
|
MATRIX_COLS,
|
||||||
));
|
));
|
||||||
|
|
||||||
let hand_force_config = try_load_hand_force_config();
|
|
||||||
Self {
|
Self {
|
||||||
connect_panel: FloatingPanelState::new([0.0, 0.0], [layout::RIGHT_TAG_X, 48.0]),
|
connect_panel: FloatingPanelState::new([0.0, 0.0], [layout::RIGHT_TAG_X, 48.0]),
|
||||||
connect_state: ConnectPanelState::default(),
|
connect_state: ConnectPanelState::default(),
|
||||||
@@ -175,20 +158,21 @@ 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,
|
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,
|
|
||||||
last_color_debug_at: None,
|
|
||||||
breakout_visible: false,
|
breakout_visible: false,
|
||||||
breakout_game: BreakoutGame::default(),
|
breakout_game: BreakoutGame::default(),
|
||||||
live_rates: LiveRateMeters::new(),
|
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::Hand(HandGatewayMode { range: 0..7000 }),
|
active_mode: ActiveMode::Finger(FingerMode {
|
||||||
hand_force_config,
|
rows: 12,
|
||||||
|
cols: 7,
|
||||||
|
range: 0..7000,
|
||||||
|
dot: true,
|
||||||
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -210,105 +194,52 @@ 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();
|
||||||
paint_spatial_force_arrow(ui.painter(), center, force, 34.0, 54.0);
|
let magnitude = force.magnitude.clamp(0.0, 1.8);
|
||||||
}
|
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);
|
||||||
|
|
||||||
fn paint_hand_spatial_force_overlay(&self, ui: &egui::Ui, rect: egui::Rect) {
|
painter.line_segment([center, end], egui::Stroke::new(9.0, glow));
|
||||||
for (force, anchor_px) in self
|
painter.line_segment([center, end], egui::Stroke::new(2.4, color));
|
||||||
.latest_hand_spatial_forces
|
painter.line_segment(
|
||||||
.iter()
|
[end, end - direction * 14.0 + side * 7.0],
|
||||||
.zip(HAND_FINGERTIP_FORCE_ANCHORS_PX)
|
egui::Stroke::new(2.4, color),
|
||||||
{
|
);
|
||||||
let Some(force) = force else {
|
painter.line_segment(
|
||||||
continue;
|
[end, end - direction * 14.0 - side * 7.0],
|
||||||
};
|
egui::Stroke::new(2.4, color),
|
||||||
|
);
|
||||||
let center = hand_image_pixel_to_screen(rect, anchor_px);
|
painter.circle_filled(center, 4.2, color);
|
||||||
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) {
|
|
||||||
let enabled = std::array::from_fn(|tip_index| {
|
|
||||||
hand_segment_force(values, tip_index, self.hand_force_config.as_ref())
|
|
||||||
> HAND_FORCE_DISPLAY_THRESHOLD_N
|
|
||||||
});
|
|
||||||
self.latest_hand_spatial_forces = self
|
|
||||||
.force_estimator
|
|
||||||
.analyze_fingertips_masked(values, &enabled);
|
|
||||||
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) {
|
||||||
let screen = ui.max_rect();
|
let screen = ui.max_rect();
|
||||||
let workspace = egui::Rect::from_min_max(
|
let workspace = egui::Rect::from_min_max(
|
||||||
screen.left_top()
|
screen.left_top() + egui::vec2(0.0, layout::WORKSPACE_TOP),
|
||||||
+ egui::vec2(0.0, layout::TITLE_BAR_HEIGHT + layout::CONFIG_BAR_HEIGHT),
|
|
||||||
screen.right_bottom(),
|
screen.right_bottom(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if self.breakout_visible {
|
||||||
|
self.draw_split_workspace(ui, workspace);
|
||||||
|
} else {
|
||||||
|
ui.painter()
|
||||||
|
.rect_filled(screen, egui::CornerRadius::ZERO, ONE_DARK_PRO.bg);
|
||||||
self.draw_wgpu_background_rect(ui, workspace);
|
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, content: egui::Rect) {
|
||||||
let screen = ui.max_rect();
|
let screen = ui.max_rect();
|
||||||
let content = egui::Rect::from_min_max(
|
|
||||||
screen.left_top() + egui::vec2(0.0, layout::TITLE_BAR_HEIGHT),
|
|
||||||
screen.right_bottom(),
|
|
||||||
);
|
|
||||||
let gutter = 10.0;
|
let gutter = 10.0;
|
||||||
let half_width = (content.width() - gutter).max(1.0) * 0.5;
|
let half_width = (content.width() - gutter).max(1.0) * 0.5;
|
||||||
let left = egui::Rect::from_min_size(content.min, egui::vec2(half_width, content.height()));
|
let left = egui::Rect::from_min_size(content.min, egui::vec2(half_width, content.height()));
|
||||||
@@ -341,7 +272,6 @@ 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() {
|
||||||
self.last_sample_at = Some(Instant::now());
|
|
||||||
normalize_pressure_sample(
|
normalize_pressure_sample(
|
||||||
&sample.matrix,
|
&sample.matrix,
|
||||||
sample.rows,
|
sample.rows,
|
||||||
@@ -353,20 +283,25 @@ impl EskinDesktopApp {
|
|||||||
self.latest_raw_matrix.extend_from_slice(&sample.matrix);
|
self.latest_raw_matrix.extend_from_slice(&sample.matrix);
|
||||||
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.log_hand_color_mapping_debug(&sample.matrix);
|
|
||||||
|
|
||||||
self.analyze_spatial_force(&sample.matrix);
|
self.latest_spatial_force = self.force_estimator.analyze(&sample.matrix);
|
||||||
|
|
||||||
let force = update_hand_signal_histories(
|
// Keep JE-Skin's summary path separate from the optional spatial-force vector.
|
||||||
&mut self.hand_signal_histories,
|
let raw_total = sample
|
||||||
&sample.matrix,
|
.matrix
|
||||||
self.hand_force_config.as_ref(),
|
.iter()
|
||||||
)
|
.fold(0_u64, |sum, value| sum + *value as u64)
|
||||||
.min(25.6);
|
.min(u32::MAX as u64) as u32;
|
||||||
|
let force = raw_to_g1(raw_total).min(25.6);
|
||||||
|
let force = if force <= 0.1 { 0.0 } else { force };
|
||||||
self.signal_history.push(force);
|
self.signal_history.push(force);
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if self.config_state.mode == SerialMode::Hand {
|
||||||
|
update_hand_signal_histories(&mut self.hand_signal_histories, &sample.matrix);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -502,15 +437,44 @@ impl EskinDesktopApp {
|
|||||||
self.live_rates.sample_rate_hz,
|
self.live_rates.sample_rate_hz,
|
||||||
self.live_rates.render_rate_hz,
|
self.live_rates.render_rate_hz,
|
||||||
) {
|
) {
|
||||||
|
if next_mode == SerialMode::Hand {
|
||||||
|
self.config_state.mode = SerialMode::Finger;
|
||||||
|
self.connect_state.mode = SerialMode::Finger;
|
||||||
|
self.config_state.baud_rate = SerialMode::Finger.baud_rate();
|
||||||
|
self.active_mode = ActiveMode::Finger(FingerMode {
|
||||||
|
rows: self.matrix_config.rows,
|
||||||
|
cols: self.matrix_config.cols,
|
||||||
|
range: 0..7000,
|
||||||
|
dot: true,
|
||||||
|
});
|
||||||
|
self.breakout_visible = true;
|
||||||
|
} else {
|
||||||
self.switch_mode(next_mode);
|
self.switch_mode(next_mode);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.breakout_visible {
|
||||||
self.stats_panel.visible = false;
|
self.stats_panel.visible = false;
|
||||||
draw_hand_force_panels(
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.config_state.mode == SerialMode::Finger {
|
||||||
|
self.stats_panel.visible = true;
|
||||||
|
draw_stats_panel(
|
||||||
ctx,
|
ctx,
|
||||||
self.hand_force_panels_visible(),
|
&mut self.stats_panel,
|
||||||
&self.hand_signal_histories,
|
&self.signal_history,
|
||||||
|
self.latest_spatial_force,
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
self.stats_panel.visible = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(force) = self.latest_spatial_force {
|
||||||
|
self.spatial_force_panel_force = Some(force);
|
||||||
|
}
|
||||||
|
|
||||||
|
draw_spatial_force_panel(ctx, self.spatial_force_panel_force, &self.signal_history);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw_panel_context_menu(&mut self, ctx: &egui::Context) {
|
fn draw_panel_context_menu(&mut self, ctx: &egui::Context) {
|
||||||
@@ -560,6 +524,17 @@ 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
|
||||||
@@ -573,6 +548,7 @@ 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;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -597,11 +573,8 @@ impl EskinDesktopApp {
|
|||||||
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.last_color_debug_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.spatial_force_panel_force = None;
|
||||||
self.signal_history.clear();
|
self.signal_history.clear();
|
||||||
self.hand_signal_histories
|
self.hand_signal_histories
|
||||||
@@ -618,347 +591,38 @@ impl EskinDesktopApp {
|
|||||||
SerialMode::Hand => ActiveMode::Hand(HandGatewayMode { range: 0..7000 }),
|
SerialMode::Hand => ActiveMode::Hand(HandGatewayMode { range: 0..7000 }),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn log_hand_color_mapping_debug(&mut self, raw: &[u32]) {
|
|
||||||
let now = Instant::now();
|
|
||||||
if self
|
|
||||||
.last_color_debug_at
|
|
||||||
.is_some_and(|last| now.duration_since(last) < Duration::from_secs(1))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
self.last_color_debug_at = Some(now);
|
|
||||||
|
|
||||||
let mut parts = Vec::with_capacity(HAND_FORCE_PANEL_COUNT);
|
|
||||||
let mut start = 0;
|
|
||||||
for (panel_index, (range, cell_count)) in HAND_SENSOR_PANEL_COLOR_RANGES
|
|
||||||
.iter()
|
|
||||||
.copied()
|
|
||||||
.zip(HAND_SENSOR_PANEL_CELL_COUNTS)
|
|
||||||
.enumerate()
|
|
||||||
{
|
|
||||||
let end = start + cell_count;
|
|
||||||
let peak = raw
|
|
||||||
.get(start..end)
|
|
||||||
.unwrap_or(&[])
|
|
||||||
.iter()
|
|
||||||
.copied()
|
|
||||||
.max()
|
|
||||||
.unwrap_or(0);
|
|
||||||
let cell_range = range.per_cell(cell_count);
|
|
||||||
let [intensity, _] = cell_range.normalize(peak);
|
|
||||||
parts.push(format!(
|
|
||||||
"{} raw_peak={} range_total_max={:.0} cell_range_max={:.0} intensity={:.3}",
|
|
||||||
match panel_index {
|
|
||||||
0..=4 => format!("F{}", panel_index + 1),
|
|
||||||
5 => "Palm-H".to_owned(),
|
|
||||||
_ => "Palm-V".to_owned(),
|
|
||||||
},
|
|
||||||
peak,
|
|
||||||
range.max,
|
|
||||||
cell_range.max,
|
|
||||||
intensity
|
|
||||||
));
|
|
||||||
start = end;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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],
|
||||||
config: Option<&HandForceConfig>,
|
) {
|
||||||
) -> f32 {
|
let mut offset = 0usize;
|
||||||
let mut total_force = 0.0;
|
for (history, sample_count) in histories.iter_mut().zip(HAND_FORCE_SEGMENT_COUNTS) {
|
||||||
for (index, history) in histories.iter_mut().enumerate() {
|
|
||||||
let force = hand_segment_force(raw_values, index, config);
|
|
||||||
let force = if force <= HAND_FORCE_DISPLAY_THRESHOLD_N {
|
|
||||||
0.0
|
|
||||||
} else {
|
|
||||||
force
|
|
||||||
};
|
|
||||||
total_force += force;
|
|
||||||
history.push(force);
|
|
||||||
if history.len() > SUMMARY_POINTS_PER_SERIES {
|
|
||||||
history.remove(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
total_force
|
|
||||||
}
|
|
||||||
|
|
||||||
fn hand_segment_force(raw_values: &[u32], index: usize, config: Option<&HandForceConfig>) -> f32 {
|
|
||||||
let offset: usize = HAND_FORCE_SEGMENT_COUNTS[..index.min(HAND_FORCE_PANEL_COUNT)]
|
|
||||||
.iter()
|
|
||||||
.sum();
|
|
||||||
let sample_count = HAND_FORCE_SEGMENT_COUNTS
|
|
||||||
.get(index)
|
|
||||||
.copied()
|
|
||||||
.unwrap_or_default();
|
|
||||||
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 = if force <= 0.1 { 0.0 } else { force };
|
||||||
|
|
||||||
raw_to_hand_segment_g(index, raw_total, config).min(20.6)
|
history.push(force);
|
||||||
}
|
if history.len() > SUMMARY_POINTS_PER_SERIES {
|
||||||
|
history.remove(0);
|
||||||
|
}
|
||||||
|
|
||||||
fn raw_to_hand_segment_g(index: usize, raw: u32, config: Option<&HandForceConfig>) -> f32 {
|
offset += sample_count;
|
||||||
match index {
|
|
||||||
0 => raw_to_g1(raw, config),
|
|
||||||
1 => raw_to_g2(raw, config),
|
|
||||||
2 => raw_to_g3(raw, config),
|
|
||||||
3 => raw_to_g4(raw, config),
|
|
||||||
4 => raw_to_g5(raw, config),
|
|
||||||
5 => raw_to_g6(raw),
|
|
||||||
6 => raw_to_g7(raw),
|
|
||||||
_ => raw_to_gd(raw),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn to_force_table(values: &BTreeMap<String, u32>) -> Vec<(u32, f32)> {
|
fn raw_to_g1(raw: u32) -> f32 {
|
||||||
let mut table = values
|
const RAW: [u32; 12] = [
|
||||||
.iter()
|
0, 21382, 108507, 123183, 147405, 171105, 192395, 250443, 231423, 350560, 396616, 429444,
|
||||||
.filter_map(|(force_n, raw)| force_n.parse::<f32>().ok().map(|force| (*raw, force)))
|
|
||||||
.collect::<Vec<_>>();
|
|
||||||
table.sort_by(|a, b| a.1.total_cmp(&b.1));
|
|
||||||
table.insert(0, (0, 0.0));
|
|
||||||
table
|
|
||||||
}
|
|
||||||
|
|
||||||
fn interpolate_force(raw: u32, table: &[(u32, f32)]) -> f32 {
|
|
||||||
let Some(&(first_raw, first_force)) = table.first() else {
|
|
||||||
return 0.0;
|
|
||||||
};
|
|
||||||
let Some(&(last_raw, last_force)) = table.last() else {
|
|
||||||
return 0.0;
|
|
||||||
};
|
|
||||||
|
|
||||||
if raw <= first_raw {
|
|
||||||
return first_force;
|
|
||||||
}
|
|
||||||
if raw >= last_raw {
|
|
||||||
return last_force;
|
|
||||||
}
|
|
||||||
|
|
||||||
let right = table.partition_point(|(raw_point, _)| *raw_point <= raw);
|
|
||||||
let (raw_left, force_left) = table[right - 1];
|
|
||||||
let (raw_right, force_right) = table[right];
|
|
||||||
let ratio = (raw - raw_left) as f32 / (raw_right - raw_left).max(1) as f32;
|
|
||||||
force_left + ratio * (force_right - force_left)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn force_from_config_or_fallback(
|
|
||||||
raw: u32,
|
|
||||||
config_values: Option<&BTreeMap<String, u32>>,
|
|
||||||
fallback_raw: &[u32],
|
|
||||||
fallback_force_centi_n: &[f32],
|
|
||||||
) -> f32 {
|
|
||||||
if let Some(config_values) = config_values {
|
|
||||||
let table = to_force_table(config_values);
|
|
||||||
if table.len() >= 2 && table.windows(2).all(|pair| pair[0].0 <= pair[1].0) {
|
|
||||||
return interpolate_force(raw, &table);
|
|
||||||
}
|
|
||||||
log::warn!(
|
|
||||||
"Hand force config raw values are not monotonically increasing; using fallback table"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
let fallback = fallback_raw
|
|
||||||
.iter()
|
|
||||||
.copied()
|
|
||||||
.zip(fallback_force_centi_n.iter().map(|force| force / 100.0))
|
|
||||||
.collect::<Vec<_>>();
|
|
||||||
interpolate_force(raw, &fallback)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn raw_to_gd(raw: u32) -> f32 {
|
|
||||||
const RAW: [u32; 11] = [
|
|
||||||
0, 486, 5310, 8130, 10005, 12883, 14700, 18141, 19877, 26270, 32648,
|
|
||||||
];
|
];
|
||||||
const FORCE_CENTI_N: [f32; 11] = [
|
const FORCE_CENTI_N: [f32; 12] = [
|
||||||
0.0, 57.0, 257.0, 357.0, 457.0, 557.0, 657.0, 857.0, 1057.0, 1557.0, 2057.0,
|
0.0, 57.0, 257.0, 357.0, 457.0, 557.0, 657.0, 857.0, 1057.0, 1557.0, 2057.0, 2557.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_g1(raw: u32, config: Option<&HandForceConfig>) -> f32 {
|
|
||||||
const RAW: [u32; 11] = [
|
|
||||||
0, 35694, 226640, 319868, 398021, 450448, 510506, 592075, 655760, 771671, 813967,
|
|
||||||
];
|
|
||||||
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,
|
|
||||||
];
|
|
||||||
|
|
||||||
force_from_config_or_fallback(raw, config.map(|cfg| &cfg.thumb), &RAW, &FORCE_CENTI_N)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn raw_to_g2(raw: u32, config: Option<&HandForceConfig>) -> f32 {
|
|
||||||
const RAW: [u32; 11] = [
|
|
||||||
0, 45490, 267579, 352066, 431681, 457605, 550875, 624327, 732735, 883397, 899338,
|
|
||||||
];
|
|
||||||
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,
|
|
||||||
];
|
|
||||||
|
|
||||||
force_from_config_or_fallback(raw, config.map(|cfg| &cfg.index), &RAW, &FORCE_CENTI_N)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn raw_to_g3(raw: u32, config: Option<&HandForceConfig>) -> f32 {
|
|
||||||
const RAW: [u32; 11] = [
|
|
||||||
0, 51562, 252840, 326531, 386571, 415819, 514679, 631745, 678945, 810847, 900422,
|
|
||||||
];
|
|
||||||
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,
|
|
||||||
];
|
|
||||||
|
|
||||||
force_from_config_or_fallback(raw, config.map(|cfg| &cfg.middle), &RAW, &FORCE_CENTI_N)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn raw_to_g4(raw: u32, config: Option<&HandForceConfig>) -> f32 {
|
|
||||||
const RAW: [u32; 11] = [
|
|
||||||
0, 33213, 220611, 307383, 369637, 430462, 489659, 584789, 664960, 802749, 926907,
|
|
||||||
];
|
|
||||||
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,
|
|
||||||
];
|
|
||||||
|
|
||||||
force_from_config_or_fallback(raw, config.map(|cfg| &cfg.ring), &RAW, &FORCE_CENTI_N)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn raw_to_g5(raw: u32, config: Option<&HandForceConfig>) -> f32 {
|
|
||||||
const RAW: [u32; 11] = [
|
|
||||||
0, 44291, 216657, 301950, 366186, 384791, 496521, 566189, 701459, 845608, 940796,
|
|
||||||
];
|
|
||||||
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,
|
|
||||||
];
|
|
||||||
|
|
||||||
force_from_config_or_fallback(raw, config.map(|cfg| &cfg.little), &RAW, &FORCE_CENTI_N)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn raw_to_g6(raw: u32) -> f32 {
|
|
||||||
const RAW: [u32; 11] = [
|
|
||||||
0, 0, 2532, 5122, 7256, 11525, 13544, 16044, 18504, 29778, 41845,
|
|
||||||
];
|
|
||||||
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_g7(raw: u32) -> f32 {
|
|
||||||
const RAW: [u32; 11] = [
|
|
||||||
0, 233, 9000, 12067, 14311, 16297, 18113, 27918, 32559, 50861, 65857,
|
|
||||||
];
|
|
||||||
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] {
|
if raw <= RAW[0] {
|
||||||
@@ -1036,79 +700,6 @@ fn split_viewport_body(rect: egui::Rect) -> egui::Rect {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy)]
|
|
||||||
struct PressureColorRange {
|
|
||||||
min: f32,
|
|
||||||
max: f32,
|
|
||||||
gamma: f32,
|
|
||||||
}
|
|
||||||
|
|
||||||
// Controls the pressure-to-color response curve. Higher values reserve warmer
|
|
||||||
// colors for larger fractions of each panel's configured raw range.
|
|
||||||
const PRESSURE_COLOR_GAMMA: f32 = 1.5;
|
|
||||||
|
|
||||||
impl PressureColorRange {
|
|
||||||
const fn new(min: u32, max: u32) -> Self {
|
|
||||||
Self {
|
|
||||||
min: min as f32,
|
|
||||||
max: max as f32,
|
|
||||||
gamma: PRESSURE_COLOR_GAMMA,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn normalize(self, value: u32) -> [f32; 2] {
|
|
||||||
let raw = value as f32;
|
|
||||||
let span = (self.max - self.min).max(1.0);
|
|
||||||
let mapped = ((raw - self.min) / span).clamp(0.0, 1.0);
|
|
||||||
|
|
||||||
let intensity = if raw <= self.min + 4.0 {
|
|
||||||
0.0
|
|
||||||
} else {
|
|
||||||
mapped.powf(self.gamma)
|
|
||||||
};
|
|
||||||
|
|
||||||
let display_value = if raw <= self.min + 4.0 {
|
|
||||||
0.0
|
|
||||||
} else {
|
|
||||||
raw.round().min(9999.0)
|
|
||||||
};
|
|
||||||
|
|
||||||
[intensity, display_value]
|
|
||||||
}
|
|
||||||
|
|
||||||
fn per_cell(self, cell_count: usize) -> Self {
|
|
||||||
let cells = cell_count.max(1) as f32;
|
|
||||||
Self {
|
|
||||||
min: self.min / cells,
|
|
||||||
max: self.max / cells,
|
|
||||||
gamma: self.gamma,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const DEFAULT_COLOR_RANGE: PressureColorRange = PressureColorRange::new(0, 7000);
|
|
||||||
|
|
||||||
const HAND_SENSOR_PANEL_COLOR_RANGES: [PressureColorRange; HAND_FORCE_PANEL_COUNT] = [
|
|
||||||
PressureColorRange::new(0, 813967),
|
|
||||||
PressureColorRange::new(0, 899338),
|
|
||||||
PressureColorRange::new(0, 900422),
|
|
||||||
PressureColorRange::new(0, 926907),
|
|
||||||
PressureColorRange::new(0, 940796),
|
|
||||||
PressureColorRange::new(0, 41845),
|
|
||||||
PressureColorRange::new(0, 65857),
|
|
||||||
];
|
|
||||||
|
|
||||||
const HAND_FINGER_SENSOR_CELLS: usize = 12 * 7;
|
|
||||||
const HAND_SENSOR_PANEL_CELL_COUNTS: [usize; HAND_FORCE_PANEL_COUNT] = [
|
|
||||||
HAND_FINGER_SENSOR_CELLS,
|
|
||||||
HAND_FINGER_SENSOR_CELLS,
|
|
||||||
HAND_FINGER_SENSOR_CELLS,
|
|
||||||
HAND_FINGER_SENSOR_CELLS,
|
|
||||||
HAND_FINGER_SENSOR_CELLS,
|
|
||||||
5 * 14,
|
|
||||||
11 * 4,
|
|
||||||
];
|
|
||||||
|
|
||||||
fn normalize_pressure_sample(raw: &[u32], rows: u32, cols: u32, normalized: &mut PressureFrame) {
|
fn normalize_pressure_sample(raw: &[u32], rows: u32, cols: u32, normalized: &mut PressureFrame) {
|
||||||
normalized.fill([0.0, 0.0]);
|
normalized.fill([0.0, 0.0]);
|
||||||
|
|
||||||
@@ -1128,119 +719,22 @@ fn normalize_pressure_sample(raw: &[u32], rows: u32, cols: u32, normalized: &mut
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn normalize_pressure_samples(raw: &[u32]) -> PressureSamples {
|
fn normalize_pressure_samples(raw: &[u32]) -> PressureSamples {
|
||||||
raw.iter()
|
raw.iter().copied().map(normalize_pressure_value).collect()
|
||||||
.copied()
|
|
||||||
.enumerate()
|
|
||||||
.map(|(index, value)| {
|
|
||||||
hand_sensor_panel_for_index(index)
|
|
||||||
.map(|(range, cell_count)| range.per_cell(cell_count).normalize(value))
|
|
||||||
.unwrap_or_else(|| DEFAULT_COLOR_RANGE.normalize(value))
|
|
||||||
})
|
|
||||||
.collect()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn hand_sensor_panel_for_index(index: usize) -> Option<(PressureColorRange, usize)> {
|
|
||||||
let mut start = 0;
|
|
||||||
|
|
||||||
for (range, cell_count) in HAND_SENSOR_PANEL_COLOR_RANGES
|
|
||||||
.iter()
|
|
||||||
.copied()
|
|
||||||
.zip(HAND_SENSOR_PANEL_CELL_COUNTS)
|
|
||||||
{
|
|
||||||
let end = start + cell_count;
|
|
||||||
if index < end {
|
|
||||||
return Some((range, cell_count));
|
|
||||||
}
|
|
||||||
start = end;
|
|
||||||
}
|
|
||||||
|
|
||||||
None
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn normalize_pressure_value(value: u32) -> [f32; 2] {
|
fn normalize_pressure_value(value: u32) -> [f32; 2] {
|
||||||
DEFAULT_COLOR_RANGE.normalize(value)
|
const RANGE_MIN: f32 = 0.0;
|
||||||
}
|
const RANGE_MAX: f32 = 7000.0;
|
||||||
|
|
||||||
#[cfg(test)]
|
let raw_value = value as f32;
|
||||||
mod tests {
|
let mapped = ((raw_value - RANGE_MIN) / (RANGE_MAX - RANGE_MIN)).clamp(0.0, 1.0);
|
||||||
use super::*;
|
let display_value = if raw_value <= RANGE_MIN + 4.0 {
|
||||||
|
0.0
|
||||||
|
} else {
|
||||||
|
raw_value.round().min(9999.0)
|
||||||
|
};
|
||||||
|
|
||||||
#[test]
|
[mapped, display_value]
|
||||||
fn raw_to_g1_uses_loaded_thumb_config() {
|
|
||||||
let config: HandForceConfig = toml::from_str(
|
|
||||||
r#"
|
|
||||||
[thumb]
|
|
||||||
"0.57" = 10
|
|
||||||
"2.57" = 20
|
|
||||||
|
|
||||||
[index]
|
|
||||||
"0.57" = 1
|
|
||||||
[middle]
|
|
||||||
"0.57" = 1
|
|
||||||
[ring]
|
|
||||||
"0.57" = 1
|
|
||||||
[little]
|
|
||||||
"0.57" = 1
|
|
||||||
"#,
|
|
||||||
)
|
|
||||||
.expect("test config should parse");
|
|
||||||
|
|
||||||
assert_eq!(raw_to_g1(20, Some(&config)), 2.57);
|
|
||||||
assert_ne!(raw_to_g1(20, None), 2.57);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn pressure_normalization_makes_low_hand_values_visible() {
|
|
||||||
let [zero_intensity, zero_label] = normalize_pressure_value(4);
|
|
||||||
assert_eq!(zero_intensity, 0.0);
|
|
||||||
assert_eq!(zero_label, 0.0);
|
|
||||||
|
|
||||||
let [low_intensity, low_label] = normalize_pressure_value(100);
|
|
||||||
assert!(
|
|
||||||
low_intensity > 0.0,
|
|
||||||
"low hand-gateway values should retain a non-zero response"
|
|
||||||
);
|
|
||||||
assert_eq!(low_label, 100.0);
|
|
||||||
|
|
||||||
let [max_intensity, max_label] = normalize_pressure_value(7000);
|
|
||||||
assert_eq!(max_intensity, 1.0);
|
|
||||||
assert_eq!(max_label, 7000.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn pressure_normalization_applies_configured_gamma() {
|
|
||||||
let range = PressureColorRange::new(0, 10_000);
|
|
||||||
let [intensity, _] = range.normalize(8_000);
|
|
||||||
let expected = 0.8_f32.powf(PRESSURE_COLOR_GAMMA);
|
|
||||||
|
|
||||||
assert!(
|
|
||||||
(intensity - expected).abs() < 0.002,
|
|
||||||
"the normalized response should follow the configured gamma"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn hand_panel_ranges_cover_both_palm_boards() {
|
|
||||||
let total_cells: usize = HAND_SENSOR_PANEL_CELL_COUNTS.iter().sum();
|
|
||||||
let mut raw = vec![0; total_cells];
|
|
||||||
let mut start = 0;
|
|
||||||
|
|
||||||
for (range, cell_count) in HAND_SENSOR_PANEL_COLOR_RANGES
|
|
||||||
.iter()
|
|
||||||
.copied()
|
|
||||||
.zip(HAND_SENSOR_PANEL_CELL_COUNTS)
|
|
||||||
{
|
|
||||||
raw[start] = (range.max / cell_count as f32).ceil() as u32;
|
|
||||||
start += cell_count;
|
|
||||||
}
|
|
||||||
|
|
||||||
let normalized = normalize_pressure_samples(&raw);
|
|
||||||
let palm_horizontal_start = HAND_SENSOR_PANEL_CELL_COUNTS[..5].iter().sum::<usize>();
|
|
||||||
let palm_vertical_start = palm_horizontal_start + HAND_SENSOR_PANEL_CELL_COUNTS[5];
|
|
||||||
|
|
||||||
assert_eq!(normalized[palm_horizontal_start][0], 1.0);
|
|
||||||
assert_eq!(normalized[palm_vertical_start][0], 1.0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl eframe::App for EskinDesktopApp {
|
impl eframe::App for EskinDesktopApp {
|
||||||
@@ -1250,7 +744,6 @@ impl eframe::App for EskinDesktopApp {
|
|||||||
self.live_rates.tick_render(stats.rx_frames);
|
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);
|
||||||
|
|||||||
@@ -1,70 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
53
src/force.rs
53
src/force.rs
@@ -1,8 +1,7 @@
|
|||||||
use crate::serial_core::multi_dim_force::PztProcessor;
|
use crate::serial_core::multi_dim_force::PztProcessor;
|
||||||
|
|
||||||
pub const FINGER_SAMPLE_COUNT: usize = 84;
|
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.1;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub struct HudSpatialForce {
|
pub struct HudSpatialForce {
|
||||||
@@ -12,22 +11,17 @@ 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> {
|
||||||
@@ -46,49 +40,6 @@ impl ForceEstimatorState {
|
|||||||
magnitude: analysis.magnitude,
|
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 {
|
impl Default for ForceEstimatorState {
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||||
mod app;
|
mod app;
|
||||||
mod breakout;
|
mod breakout;
|
||||||
mod config;
|
|
||||||
mod connection;
|
mod connection;
|
||||||
mod force;
|
mod force;
|
||||||
mod matrix;
|
mod matrix;
|
||||||
@@ -21,15 +20,12 @@ 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()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
117
src/render.rs
117
src/render.rs
@@ -44,43 +44,43 @@ pub struct HandGatewayMode {
|
|||||||
|
|
||||||
const HAND_TIP_MATRICES: [HandTipMatrix; 5] = [
|
const HAND_TIP_MATRICES: [HandTipMatrix; 5] = [
|
||||||
HandTipMatrix {
|
HandTipMatrix {
|
||||||
center_px: [263.5, 495.0],
|
center_px: [260.0, 490.0],
|
||||||
size_px: [70.0, 120.0],
|
size_px: [70.0, 120.0],
|
||||||
angle_rad: -0.40,
|
angle_rad: -0.45,
|
||||||
},
|
},
|
||||||
HandTipMatrix {
|
HandTipMatrix {
|
||||||
center_px: [362.0, 260.0],
|
center_px: [360.0, 255.0],
|
||||||
size_px: [70.0, 120.0],
|
size_px: [70.0, 120.0],
|
||||||
angle_rad: -0.158,
|
angle_rad: -0.05,
|
||||||
},
|
},
|
||||||
HandTipMatrix {
|
HandTipMatrix {
|
||||||
center_px: [480.5, 228.0],
|
center_px: [485.0, 225.0],
|
||||||
size_px: [70.0, 120.0],
|
size_px: [70.0, 120.0],
|
||||||
angle_rad: -0.02,
|
angle_rad: 0.0,
|
||||||
},
|
},
|
||||||
HandTipMatrix {
|
HandTipMatrix {
|
||||||
center_px: [594.0, 265.0],
|
center_px: [595.0, 260.0],
|
||||||
size_px: [70.0, 120.0],
|
size_px: [70.0, 120.0],
|
||||||
angle_rad: 0.10,
|
angle_rad: 0.12,
|
||||||
},
|
},
|
||||||
HandTipMatrix {
|
HandTipMatrix {
|
||||||
center_px: [693.0, 370.0],
|
center_px: [705.0, 385.0],
|
||||||
size_px: [70.0, 120.0],
|
size_px: [70.0, 120.0],
|
||||||
angle_rad: 0.22,
|
angle_rad: 0.28,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const HAND_PALM_CHIPS: [HandPalmChip; 2] = [
|
const HAND_PALM_CHIPS: [HandPalmChip; 2] = [
|
||||||
HandPalmChip {
|
HandPalmChip {
|
||||||
center_px: [530.0, 593.0],
|
center_px: [538.0, 608.0],
|
||||||
size_px: [258.0, 88.0],
|
size_px: [248.0, 82.0],
|
||||||
angle_rad: 0.12,
|
angle_rad: 0.06,
|
||||||
rows: 5,
|
rows: 5,
|
||||||
cols: 14,
|
cols: 14,
|
||||||
},
|
},
|
||||||
HandPalmChip {
|
HandPalmChip {
|
||||||
center_px: [610.0, 778.0],
|
center_px: [606.0, 780.0],
|
||||||
size_px: [82.0, 228.0],
|
size_px: [72.0, 214.0],
|
||||||
angle_rad: 0.05,
|
angle_rad: 0.05,
|
||||||
rows: 11,
|
rows: 11,
|
||||||
cols: 4,
|
cols: 4,
|
||||||
@@ -90,7 +90,6 @@ const HAND_PALM_CHIPS: [HandPalmChip; 2] = [
|
|||||||
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_HORIZONTAL_OFFSET: usize = HAND_FINGER_SENSOR_CELLS * 5;
|
||||||
const HAND_PALM_VERTICAL_OFFSET: usize = HAND_PALM_HORIZONTAL_OFFSET + 5 * 14;
|
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.
|
||||||
@@ -532,13 +531,12 @@ impl BackgroundRenderResources {
|
|||||||
let hand_membrane_instances = build_hand_membrane_instances(
|
let hand_membrane_instances = build_hand_membrane_instances(
|
||||||
hand_image_texture.width as f32,
|
hand_image_texture.width as f32,
|
||||||
hand_image_texture.height as f32,
|
hand_image_texture.height as f32,
|
||||||
&[],
|
|
||||||
);
|
);
|
||||||
let hand_membrane_instance_buffer =
|
let hand_membrane_instance_buffer =
|
||||||
device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||||
label: Some("Hand Fingertip Membrane Instance Buffer"),
|
label: Some("Hand Fingertip Membrane Instance Buffer"),
|
||||||
contents: bytemuck::cast_slice(&hand_membrane_instances),
|
contents: bytemuck::cast_slice(&hand_membrane_instances),
|
||||||
usage: wgpu::BufferUsages::VERTEX | wgpu::BufferUsages::COPY_DST,
|
usage: wgpu::BufferUsages::VERTEX,
|
||||||
});
|
});
|
||||||
let hand_dot_instances = build_hand_dot_instances(
|
let hand_dot_instances = build_hand_dot_instances(
|
||||||
rows,
|
rows,
|
||||||
@@ -655,17 +653,6 @@ impl BackgroundRenderResources {
|
|||||||
hand_pressure
|
hand_pressure
|
||||||
};
|
};
|
||||||
|
|
||||||
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.
|
// Hand mode uses UV-anchored fingertip matrices over hand.png.
|
||||||
// Rebuild their instance positions here so pressure colors update every frame.
|
// 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(
|
||||||
@@ -1151,48 +1138,24 @@ fn create_hand_palm_dot_pipeline(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_hand_membrane_instances(
|
fn build_hand_membrane_instances(image_width: f32, image_height: f32) -> Vec<GlyphInstance> {
|
||||||
image_width: f32,
|
|
||||||
image_height: f32,
|
|
||||||
pressure: &[[f32; 2]],
|
|
||||||
) -> Vec<GlyphInstance> {
|
|
||||||
HAND_TIP_MATRICES
|
HAND_TIP_MATRICES
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.map(|tip| {
|
||||||
.map(|(tip_index, 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.44, tip.size_px[1] * 1.36];
|
let membrane_size = [tip.size_px[0] * 1.62, tip.size_px[1] * 1.56];
|
||||||
let tip_intensity = hand_tip_peak_intensity(pressure, tip_index);
|
|
||||||
|
|
||||||
GlyphInstance {
|
GlyphInstance {
|
||||||
// Membrane shaders read xy as hand.png UV.
|
// Membrane shaders read xy as hand.png UV.
|
||||||
world_position: [uv_x, uv_y, 0.0, 1.0],
|
world_position: [uv_x, uv_y, 0.0, 1.0],
|
||||||
// Store angle, source-image pixel size, and the live fingertip peak intensity.
|
// Store angle and an oversized source-image pixel size for the floating sensor film.
|
||||||
style: [
|
style: [tip.angle_rad, membrane_size[0], membrane_size[1], 0.0],
|
||||||
tip.angle_rad,
|
|
||||||
membrane_size[0],
|
|
||||||
membrane_size[1],
|
|
||||||
tip_intensity,
|
|
||||||
],
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect()
|
.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> {
|
fn build_hand_palm_chip_instances(image_width: f32, image_height: f32) -> Vec<GlyphInstance> {
|
||||||
HAND_PALM_CHIPS
|
HAND_PALM_CHIPS
|
||||||
.iter()
|
.iter()
|
||||||
@@ -1239,8 +1202,7 @@ 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;
|
||||||
@@ -1276,16 +1238,16 @@ fn build_hand_palm_dot_instances(
|
|||||||
for (chip_index, chip) in HAND_PALM_CHIPS.into_iter().enumerate() {
|
for (chip_index, chip) in HAND_PALM_CHIPS.into_iter().enumerate() {
|
||||||
let cos = chip.angle_rad.cos();
|
let cos = chip.angle_rad.cos();
|
||||||
let sin = chip.angle_rad.sin();
|
let sin = chip.angle_rad.sin();
|
||||||
// Palm films can float slightly beyond the hand artwork, similar to fingertip membranes.
|
// Leave a bevel around the chip so the matrix reads as embedded pixels.
|
||||||
let active_size = [chip.size_px[0] * 0.86, chip.size_px[1] * 0.86];
|
let active_size = [chip.size_px[0] * 0.72, chip.size_px[1] * 0.76];
|
||||||
|
|
||||||
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 = (row * chip.cols + col) as usize;
|
||||||
let offset = match chip_index {
|
let offset = match chip_index {
|
||||||
0 => HAND_PALM_HORIZONTAL_OFFSET,
|
0 => HAND_PALM_HORIZONTAL_OFFSET,
|
||||||
_ => HAND_PALM_VERTICAL_OFFSET,
|
_ => HAND_PALM_VERTICAL_OFFSET,
|
||||||
};
|
};
|
||||||
let index = hand_palm_pressure_index(chip_index, row, col, chip.rows, chip.cols);
|
|
||||||
let [normalized, display_value] =
|
let [normalized, display_value] =
|
||||||
sample_pressure_at(pressure, offset + index, index);
|
sample_pressure_at(pressure, offset + index, index);
|
||||||
|
|
||||||
@@ -1313,14 +1275,6 @@ fn build_hand_palm_dot_instances(
|
|||||||
instances
|
instances
|
||||||
}
|
}
|
||||||
|
|
||||||
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] {
|
fn sample_pressure_at(pressure: &[[f32; 2]], index: usize, fallback_index: usize) -> [f32; 2] {
|
||||||
pressure
|
pressure
|
||||||
.get(index)
|
.get(index)
|
||||||
@@ -1452,24 +1406,3 @@ 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -38,9 +38,8 @@ pub fn load_texture(
|
|||||||
device: &wgpu::Device,
|
device: &wgpu::Device,
|
||||||
queue: &wgpu::Queue,
|
queue: &wgpu::Queue,
|
||||||
) -> anyhow::Result<texture::Texture> {
|
) -> anyhow::Result<texture::Texture> {
|
||||||
// let data = load_binary(file_name)?;
|
let data = load_binary(file_name)?;
|
||||||
let data = include_bytes!("../res/hand.png");
|
texture::Texture::from_bytes(device, queue, &data, file_name)
|
||||||
texture::Texture::from_bytes(device, queue, data, file_name)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn load_model(
|
pub fn load_model(
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ const SENSOR_COUNT: usize = SENSOR_ROWS * SENSOR_COLS;
|
|||||||
const TOTAL_PRESSURE_LOW_THRESHOLD: f32 = 500.0;
|
const TOTAL_PRESSURE_LOW_THRESHOLD: f32 = 500.0;
|
||||||
const COP_STABILITY_FRAMES_REQUIRED: usize = 15;
|
const COP_STABILITY_FRAMES_REQUIRED: usize = 15;
|
||||||
|
|
||||||
const POST_INIT_WINDOW_CNT: usize = 50;
|
const POST_INIT_WINDOW_CNT: usize = 100;
|
||||||
const POST_INIT_STABLE_CNT: usize = 50;
|
const POST_INIT_STABLE_CNT: usize = 50;
|
||||||
const POST_INIT_STABLE_THRESH: f32 = 0.1;
|
const POST_INIT_STABLE_THRESH: f32 = 0.1;
|
||||||
|
|
||||||
|
|||||||
@@ -61,7 +61,8 @@ 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 = 38.0;
|
pub const CONFIG_BAR_HEIGHT: f32 = 48.0;
|
||||||
|
pub const WORKSPACE_TOP: f32 = TITLE_BAR_HEIGHT + CONFIG_BAR_HEIGHT;
|
||||||
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;
|
||||||
|
|||||||
270
src/ui.rs
270
src/ui.rs
@@ -104,10 +104,10 @@ impl Default for ConfigPanelState {
|
|||||||
.unwrap_or_else(|| "COM3".to_owned());
|
.unwrap_or_else(|| "COM3".to_owned());
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
mode: SerialMode::Hand,
|
mode: SerialMode::Finger,
|
||||||
port,
|
port,
|
||||||
available_ports,
|
available_ports,
|
||||||
baud_rate: SerialMode::Hand.baud_rate(),
|
baud_rate: 921_600,
|
||||||
data_bits: 8,
|
data_bits: 8,
|
||||||
stop_bits: 1,
|
stop_bits: 1,
|
||||||
parity: Parity::None,
|
parity: Parity::None,
|
||||||
@@ -126,7 +126,7 @@ impl Default for ConnectPanelState {
|
|||||||
let port = serial_enum().unwrap_or_default();
|
let port = serial_enum().unwrap_or_default();
|
||||||
let selected_port = port.first().cloned().unwrap_or_default();
|
let selected_port = port.first().cloned().unwrap_or_default();
|
||||||
Self {
|
Self {
|
||||||
mode: SerialMode::Hand,
|
mode: SerialMode::Finger,
|
||||||
port,
|
port,
|
||||||
selected_port,
|
selected_port,
|
||||||
duration: 10,
|
duration: 10,
|
||||||
@@ -157,7 +157,7 @@ fn responsive_panel_width(ctx: &egui::Context, preferred: f32, min_width: f32) -
|
|||||||
|
|
||||||
fn responsive_panel_height(ctx: &egui::Context, preferred: f32, min_height: f32) -> f32 {
|
fn responsive_panel_height(ctx: &egui::Context, preferred: f32, min_height: f32) -> f32 {
|
||||||
let screen = ctx.content_rect();
|
let screen = ctx.content_rect();
|
||||||
let available = (screen.height() - layout::TITLE_BAR_HEIGHT - PANEL_VIEWPORT_MARGIN * 2.0)
|
let available = (screen.height() - layout::WORKSPACE_TOP - PANEL_VIEWPORT_MARGIN * 2.0)
|
||||||
.max(min_height.min(screen.height()));
|
.max(min_height.min(screen.height()));
|
||||||
let height_cap = (screen.height() * 0.72).max(min_height.min(available));
|
let height_cap = (screen.height() * 0.72).max(min_height.min(available));
|
||||||
|
|
||||||
@@ -173,7 +173,7 @@ fn responsive_panel_pos(
|
|||||||
panel_width: f32,
|
panel_width: f32,
|
||||||
) -> egui::Pos2 {
|
) -> egui::Pos2 {
|
||||||
let rect = viewport_panel_rect(ctx);
|
let rect = viewport_panel_rect(ctx);
|
||||||
let min_y = rect.top() + layout::TITLE_BAR_HEIGHT + PANEL_VIEWPORT_MARGIN;
|
let min_y = rect.top() + layout::WORKSPACE_TOP + PANEL_VIEWPORT_MARGIN;
|
||||||
let max_x = (rect.right() - panel_width).max(rect.left());
|
let max_x = (rect.right() - panel_width).max(rect.left());
|
||||||
let preferred_right_side = preferred.x > rect.center().x;
|
let preferred_right_side = preferred.x > rect.center().x;
|
||||||
let x = if preferred_right_side {
|
let x = if preferred_right_side {
|
||||||
@@ -387,65 +387,94 @@ fn draw_connect_action_row(
|
|||||||
|
|
||||||
pub fn draw_config_panel(
|
pub fn draw_config_panel(
|
||||||
ctx: &egui::Context,
|
ctx: &egui::Context,
|
||||||
_panel: &mut FloatingPanelState,
|
panel: &mut FloatingPanelState,
|
||||||
config: &mut ConfigPanelState,
|
config: &mut ConfigPanelState,
|
||||||
connection: &ConnectionManager,
|
connection: &ConnectionManager,
|
||||||
recorder: &Recorder,
|
recorder: &Recorder,
|
||||||
_stats: SerialIoStats,
|
stats: SerialIoStats,
|
||||||
sample_rate_hz: f32,
|
sample_rate_hz: f32,
|
||||||
render_rate_hz: f32,
|
render_rate_hz: f32,
|
||||||
) -> Option<SerialMode> {
|
) -> Option<SerialMode> {
|
||||||
let changed_mode = None;
|
let mut changed_mode = None;
|
||||||
let conn_state = connection.state();
|
let conn_state = connection.state();
|
||||||
|
let screen = ctx.content_rect();
|
||||||
|
let bar_rect = egui::Rect::from_min_size(
|
||||||
|
screen.left_top() + egui::vec2(0.0, layout::TITLE_BAR_HEIGHT),
|
||||||
|
egui::vec2(screen.width(), layout::CONFIG_BAR_HEIGHT),
|
||||||
|
);
|
||||||
|
|
||||||
config.connected = matches!(
|
config.connected = matches!(
|
||||||
conn_state,
|
conn_state,
|
||||||
ConnectionState::Connected | ConnectionState::Streaming
|
ConnectionState::Connected | ConnectionState::Streaming
|
||||||
);
|
);
|
||||||
|
panel.visible = true;
|
||||||
|
|
||||||
let screen = ctx.content_rect();
|
egui::Area::new(egui::Id::new("config_panel_bar"))
|
||||||
let bar_rect = egui::Rect::from_min_size(
|
|
||||||
egui::pos2(screen.left(), screen.top() + layout::TITLE_BAR_HEIGHT),
|
|
||||||
egui::vec2(screen.width(), layout::CONFIG_BAR_HEIGHT),
|
|
||||||
);
|
|
||||||
|
|
||||||
egui::Area::new(egui::Id::new("config_top_bar"))
|
|
||||||
.fixed_pos(bar_rect.min)
|
.fixed_pos(bar_rect.min)
|
||||||
.order(egui::Order::Foreground)
|
.order(egui::Order::Foreground)
|
||||||
.show(ctx, |ui| {
|
.show(ctx, |ui| {
|
||||||
ui.set_min_size(bar_rect.size());
|
ui.set_min_size(bar_rect.size());
|
||||||
ui.painter().rect_filled(
|
ui.set_max_size(bar_rect.size());
|
||||||
ui.max_rect(),
|
|
||||||
egui::CornerRadius::ZERO,
|
config_bar_frame().show(ui, |ui| {
|
||||||
ONE_DARK_PRO.panel_deep,
|
ui.set_min_width(bar_rect.width());
|
||||||
);
|
ui.set_max_width(bar_rect.width());
|
||||||
ui.painter().line_segment(
|
ui.spacing_mut().item_spacing = egui::vec2(METRICS.item_gap, 6.0);
|
||||||
[ui.max_rect().left_top(), ui.max_rect().right_top()],
|
|
||||||
egui::Stroke::new(1.0, ONE_DARK_PRO.border_soft),
|
|
||||||
);
|
|
||||||
ui.painter().line_segment(
|
|
||||||
[ui.max_rect().left_bottom(), ui.max_rect().right_bottom()],
|
|
||||||
egui::Stroke::new(1.0, ONE_DARK_PRO.border_soft),
|
|
||||||
);
|
|
||||||
|
|
||||||
ui.add_space(5.0);
|
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
ui.add_space(8.0);
|
ui.label(style::panel_title("配置面板"));
|
||||||
ui.spacing_mut().item_spacing = egui::vec2(8.0, 0.0);
|
ui.add_space(12.0);
|
||||||
config.mode = SerialMode::Hand;
|
|
||||||
config.baud_rate = SerialMode::Hand.baud_rate();
|
|
||||||
|
|
||||||
ui.colored_label(dim_text(), "配置面板");
|
if let Some(mode) = draw_config_bar_mode(ui, config) {
|
||||||
ui.add_space(8.0);
|
changed_mode = Some(mode);
|
||||||
ui.colored_label(dim_text(), "模式");
|
}
|
||||||
ui.add_sized(
|
|
||||||
egui::vec2(102.0, 28.0),
|
|
||||||
style::mode_button("手掌模块", true),
|
|
||||||
);
|
|
||||||
|
|
||||||
ui.add_space(12.0);
|
ui.add_space(12.0);
|
||||||
ui.label(style::field_label("端口"));
|
draw_config_bar_connection(ui, config, connection, recorder, conn_state);
|
||||||
egui::ComboBox::from_id_salt("config_top_bar_ports")
|
|
||||||
.width(180.0)
|
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||||
|
draw_config_bar_rates(ui, stats, sample_rate_hz, render_rate_hz);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
changed_mode
|
||||||
|
}
|
||||||
|
|
||||||
|
fn config_bar_frame() -> egui::Frame {
|
||||||
|
egui::Frame::new()
|
||||||
|
.fill(ONE_DARK_PRO.panel_deep)
|
||||||
|
.inner_margin(egui::Margin::symmetric(8, 6))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn draw_config_bar_mode(ui: &mut egui::Ui, config: &mut ConfigPanelState) -> Option<SerialMode> {
|
||||||
|
let mut changed_to = None;
|
||||||
|
|
||||||
|
ui.horizontal(|ui| {
|
||||||
|
ui.colored_label(dim_text(), "模式");
|
||||||
|
|
||||||
|
if mode_button(ui, &mut config.mode, SerialMode::Finger, "指尖模块") {
|
||||||
|
changed_to = Some(SerialMode::Finger);
|
||||||
|
}
|
||||||
|
if mode_button(ui, &mut config.mode, SerialMode::Hand, "游戏体验") {
|
||||||
|
changed_to = Some(SerialMode::Hand);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
changed_to
|
||||||
|
}
|
||||||
|
|
||||||
|
fn draw_config_bar_connection(
|
||||||
|
ui: &mut egui::Ui,
|
||||||
|
config: &mut ConfigPanelState,
|
||||||
|
connection: &ConnectionManager,
|
||||||
|
recorder: &Recorder,
|
||||||
|
conn_state: ConnectionState,
|
||||||
|
) {
|
||||||
|
ui.colored_label(dim_text(), "端口");
|
||||||
|
egui::ComboBox::from_id_salt("config_bar_ports")
|
||||||
|
.width(170.0)
|
||||||
.selected_text(if config.port.is_empty() {
|
.selected_text(if config.port.is_empty() {
|
||||||
"无可用串口".to_owned()
|
"无可用串口".to_owned()
|
||||||
} else {
|
} else {
|
||||||
@@ -460,7 +489,7 @@ pub fn draw_config_panel(
|
|||||||
if ui
|
if ui
|
||||||
.add(style::icon_button(
|
.add(style::icon_button(
|
||||||
egui::RichText::new("⟳").color(ONE_DARK_PRO.text).size(16.0),
|
egui::RichText::new("⟳").color(ONE_DARK_PRO.text).size(16.0),
|
||||||
METRICS.icon_button,
|
egui::vec2(30.0, METRICS.field_height),
|
||||||
))
|
))
|
||||||
.on_hover_text("刷新串口")
|
.on_hover_text("刷新串口")
|
||||||
.clicked()
|
.clicked()
|
||||||
@@ -468,16 +497,19 @@ pub fn draw_config_panel(
|
|||||||
refresh_config_ports(config);
|
refresh_config_ports(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
ui.add_space(10.0);
|
ui.add_space(4.0);
|
||||||
ui.label(style::value_text(format!("波特率 {}", config.baud_rate)));
|
ui.colored_label(dim_text(), "波特率");
|
||||||
ui.add_space(10.0);
|
ui.label(style::value_text(config.baud_rate.to_string()));
|
||||||
|
|
||||||
|
ui.add_space(4.0);
|
||||||
ui.colored_label(dim_text(), "状态");
|
ui.colored_label(dim_text(), "状态");
|
||||||
ui.colored_label(
|
ui.colored_label(
|
||||||
connection_status_color(conn_state),
|
connection_status_color(conn_state),
|
||||||
connection_status_text(conn_state),
|
connection_status_text(conn_state),
|
||||||
);
|
);
|
||||||
|
|
||||||
ui.add_space(8.0);
|
ui.add_space(6.0);
|
||||||
|
|
||||||
let is_connected = matches!(
|
let is_connected = matches!(
|
||||||
conn_state,
|
conn_state,
|
||||||
ConnectionState::Connected | ConnectionState::Streaming
|
ConnectionState::Connected | ConnectionState::Streaming
|
||||||
@@ -485,7 +517,7 @@ pub fn draw_config_panel(
|
|||||||
let button_text = if is_connected { "断开" } else { "连接" };
|
let button_text = if is_connected { "断开" } else { "连接" };
|
||||||
if ui
|
if ui
|
||||||
.add_sized(
|
.add_sized(
|
||||||
egui::vec2(118.0, 28.0),
|
egui::vec2(88.0, METRICS.button_height),
|
||||||
if is_connected {
|
if is_connected {
|
||||||
style::danger_button(button_text)
|
style::danger_button(button_text)
|
||||||
} else {
|
} else {
|
||||||
@@ -507,18 +539,19 @@ pub fn draw_config_panel(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
fn draw_config_bar_rates(
|
||||||
|
ui: &mut egui::Ui,
|
||||||
|
_stats: SerialIoStats,
|
||||||
|
sample_rate_hz: f32,
|
||||||
|
render_rate_hz: f32,
|
||||||
|
) {
|
||||||
ui.label(style::value_text(format!("{render_rate_hz:.1} Hz")));
|
ui.label(style::value_text(format!("{render_rate_hz:.1} Hz")));
|
||||||
ui.colored_label(dim_text(), "画面刷新率");
|
ui.colored_label(dim_text(), "画面刷新率");
|
||||||
ui.add_space(18.0);
|
ui.add_space(14.0);
|
||||||
ui.label(style::value_text(format!("{sample_rate_hz:.1} Hz")));
|
ui.label(style::value_text(format!("{sample_rate_hz:.1} Hz")));
|
||||||
ui.colored_label(dim_text(), "采样率");
|
ui.colored_label(dim_text(), "采样率");
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
changed_mode
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn draw_spatial_force_panel(
|
pub fn draw_spatial_force_panel(
|
||||||
@@ -589,14 +622,27 @@ pub fn draw_spatial_force_panel(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn draw_mode_row(ui: &mut egui::Ui, config: &mut ConfigPanelState) -> Option<SerialMode> {
|
fn draw_mode_row(ui: &mut egui::Ui, config: &mut ConfigPanelState) -> Option<SerialMode> {
|
||||||
config.mode = SerialMode::Hand;
|
let mut changed_to = None;
|
||||||
config.baud_rate = SerialMode::Hand.baud_rate();
|
|
||||||
ui.horizontal_wrapped(|ui| {
|
ui.horizontal_wrapped(|ui| {
|
||||||
ui.colored_label(dim_text(), "Mode");
|
ui.colored_label(dim_text(), "模式");
|
||||||
ui.add_space(12.0);
|
ui.add_space(12.0);
|
||||||
ui.label(style::panel_title("Hand Gateway"));
|
|
||||||
|
if mode_button(ui, &mut config.mode, SerialMode::Finger, "指尖模块") {
|
||||||
|
changed_to = Some(SerialMode::Finger)
|
||||||
|
}
|
||||||
|
if mode_button(ui, &mut config.mode, SerialMode::Hand, "游戏体验") {
|
||||||
|
changed_to = Some(SerialMode::Hand)
|
||||||
|
}
|
||||||
|
// mode_button(ui, &mut config.mode, SerialMode::Model, "模型");
|
||||||
|
|
||||||
|
// Legacy reconnect controls. Current sensors run fixed 921600 baud without auto-reconnect UI.
|
||||||
|
// ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||||
|
// ui.checkbox(&mut config.auto_reconnect, "自动");
|
||||||
|
// ui.colored_label(dim_text(), "重连");
|
||||||
|
// });
|
||||||
});
|
});
|
||||||
None
|
|
||||||
|
changed_to
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw_connection_row(
|
fn draw_connection_row(
|
||||||
@@ -928,7 +974,7 @@ pub fn draw_stats_panel(
|
|||||||
let target_pos = egui::pos2(
|
let target_pos = egui::pos2(
|
||||||
viewport.left(),
|
viewport.left(),
|
||||||
(viewport.bottom() - panel_height - PANEL_VIEWPORT_MARGIN * 2.0)
|
(viewport.bottom() - panel_height - PANEL_VIEWPORT_MARGIN * 2.0)
|
||||||
.max(viewport.top() + layout::TITLE_BAR_HEIGHT + PANEL_VIEWPORT_MARGIN),
|
.max(viewport.top() + layout::WORKSPACE_TOP + PANEL_VIEWPORT_MARGIN),
|
||||||
);
|
);
|
||||||
let target_x = target_pos.x;
|
let target_x = target_pos.x;
|
||||||
let hidden_x = if target_x < screen.center().x {
|
let hidden_x = if target_x < screen.center().x {
|
||||||
@@ -957,17 +1003,14 @@ pub fn draw_stats_panel(
|
|||||||
const FORCE_CHART_MAX_N: f32 = 25.6;
|
const FORCE_CHART_MAX_N: f32 = 25.6;
|
||||||
const FORCE_CHART_SAMPLE_SECONDS: f32 = 0.1;
|
const FORCE_CHART_SAMPLE_SECONDS: f32 = 0.1;
|
||||||
const FORCE_PANEL_ACTIVE_TAIL: usize = 8;
|
const FORCE_PANEL_ACTIVE_TAIL: usize = 8;
|
||||||
const FORCE_PANEL_EXIT_DELAY_SECONDS: f64 = 3.0;
|
|
||||||
|
|
||||||
const HAND_FORCE_PANEL_MIN_WIDTH: f32 = 160.0;
|
const HAND_FORCE_PANEL_MIN_WIDTH: f32 = 220.0;
|
||||||
const HAND_FORCE_PANEL_MAX_WIDTH: f32 = 560.0;
|
const HAND_FORCE_PANEL_MAX_WIDTH: f32 = 500.0;
|
||||||
const HAND_FORCE_PANEL_MIN_HEIGHT: f32 = 72.0;
|
const HAND_FORCE_PANEL_MIN_HEIGHT: f32 = 104.0;
|
||||||
const HAND_FORCE_PANEL_MAX_HEIGHT: f32 = 230.0;
|
const HAND_FORCE_PANEL_MAX_HEIGHT: f32 = 190.0;
|
||||||
const HAND_FORCE_PANEL_GAP: f32 = 20.0;
|
const HAND_FORCE_PANEL_GAP: f32 = 12.0;
|
||||||
const HAND_FORCE_PANEL_SIDE_MARGIN: f32 = 24.0;
|
const HAND_FORCE_PANEL_SIDE_MARGIN: f32 = 24.0;
|
||||||
const HAND_FORCE_PANEL_VERTICAL_MARGIN: f32 = 28.0;
|
const HAND_FORCE_PANEL_VERTICAL_MARGIN: f32 = 28.0;
|
||||||
const HAND_FORCE_CENTER_MIN_WIDTH: f32 = 420.0;
|
|
||||||
const HAND_FORCE_CENTER_MAX_WIDTH: f32 = 820.0;
|
|
||||||
const HAND_FORCE_PANEL_TITLES: [(&str, &str); 7] = [
|
const HAND_FORCE_PANEL_TITLES: [(&str, &str); 7] = [
|
||||||
("T1", "拇指"),
|
("T1", "拇指"),
|
||||||
("T2", "食指"),
|
("T2", "食指"),
|
||||||
@@ -987,14 +1030,15 @@ fn has_recent_resultant_force(values: &[f32]) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn draw_hand_force_panels(ctx: &egui::Context, visible: bool, histories: &[Vec<f32>]) {
|
pub fn draw_hand_force_panels(ctx: &egui::Context, visible: bool, histories: &[Vec<f32>]) {
|
||||||
|
let hand_active = histories
|
||||||
|
.iter()
|
||||||
|
.any(|history| has_recent_resultant_force(history));
|
||||||
|
let target_visible = visible && hand_active;
|
||||||
let screen = ctx.content_rect();
|
let screen = ctx.content_rect();
|
||||||
let side_margin = HAND_FORCE_PANEL_SIDE_MARGIN.min((screen.width() * 0.025).max(10.0));
|
let side_margin = HAND_FORCE_PANEL_SIDE_MARGIN.min((screen.width() * 0.025).max(10.0));
|
||||||
let vertical_margin = HAND_FORCE_PANEL_VERTICAL_MARGIN.min((screen.height() * 0.04).max(10.0));
|
let vertical_margin = HAND_FORCE_PANEL_VERTICAL_MARGIN.min((screen.height() * 0.04).max(10.0));
|
||||||
let gap = HAND_FORCE_PANEL_GAP.min((screen.height() * 0.024).max(12.0));
|
let gap = HAND_FORCE_PANEL_GAP.min((screen.height() * 0.018).max(6.0));
|
||||||
let reserved_center_width = (screen.width() * 0.42)
|
let side_width = ((screen.width() - side_margin * 4.0) * 0.25).max(0.0);
|
||||||
.clamp(HAND_FORCE_CENTER_MIN_WIDTH, HAND_FORCE_CENTER_MAX_WIDTH)
|
|
||||||
.min((screen.width() - side_margin * 2.0).max(0.0));
|
|
||||||
let side_width = ((screen.width() - reserved_center_width - side_margin * 2.0) * 0.5).max(0.0);
|
|
||||||
let panel_width = side_width
|
let panel_width = side_width
|
||||||
.min(HAND_FORCE_PANEL_MAX_WIDTH)
|
.min(HAND_FORCE_PANEL_MAX_WIDTH)
|
||||||
.max(HAND_FORCE_PANEL_MIN_WIDTH.min(side_width));
|
.max(HAND_FORCE_PANEL_MIN_WIDTH.min(side_width));
|
||||||
@@ -1002,16 +1046,17 @@ pub fn draw_hand_force_panels(ctx: &egui::Context, visible: bool, histories: &[V
|
|||||||
let right_x = screen.right() - side_margin - panel_width;
|
let right_x = screen.right() - side_margin - panel_width;
|
||||||
let left_count = 4usize;
|
let left_count = 4usize;
|
||||||
let right_count = HAND_FORCE_PANEL_TITLES.len() - left_count;
|
let right_count = HAND_FORCE_PANEL_TITLES.len() - left_count;
|
||||||
let chrome_height = layout::TITLE_BAR_HEIGHT + layout::CONFIG_BAR_HEIGHT;
|
let available_height =
|
||||||
let available_height = (screen.height() - chrome_height - vertical_margin * 2.0).max(0.0);
|
(screen.height() - layout::WORKSPACE_TOP - vertical_margin * 2.0).max(0.0);
|
||||||
let panel_height = ((available_height - (left_count - 1) as f32 * gap) / left_count as f32)
|
let panel_height = ((available_height - (left_count - 1) as f32 * gap) / left_count as f32)
|
||||||
.max(0.0)
|
.clamp(
|
||||||
.min(HAND_FORCE_PANEL_MAX_HEIGHT)
|
HAND_FORCE_PANEL_MIN_HEIGHT.min(available_height),
|
||||||
.max(HAND_FORCE_PANEL_MIN_HEIGHT.min(available_height / left_count as f32));
|
HAND_FORCE_PANEL_MAX_HEIGHT,
|
||||||
|
);
|
||||||
let left_height = left_count as f32 * panel_height + (left_count - 1) as f32 * gap;
|
let left_height = left_count as f32 * panel_height + (left_count - 1) as f32 * gap;
|
||||||
let right_height =
|
let right_height =
|
||||||
right_count as f32 * panel_height + (right_count.saturating_sub(1)) as f32 * gap;
|
right_count as f32 * panel_height + (right_count.saturating_sub(1)) as f32 * gap;
|
||||||
let min_top = screen.top() + chrome_height + vertical_margin;
|
let min_top = screen.top() + layout::WORKSPACE_TOP + vertical_margin;
|
||||||
let left_top = (screen.center().y - left_height * 0.5).max(min_top);
|
let left_top = (screen.center().y - left_height * 0.5).max(min_top);
|
||||||
let right_top = (screen.center().y - right_height * 0.5).max(min_top);
|
let right_top = (screen.center().y - right_height * 0.5).max(min_top);
|
||||||
|
|
||||||
@@ -1033,8 +1078,7 @@ pub fn draw_hand_force_panels(ctx: &egui::Context, visible: bool, histories: &[V
|
|||||||
egui::Id::new(format!("hand_force_panel_{index}")),
|
egui::Id::new(format!("hand_force_panel_{index}")),
|
||||||
egui::pos2(target_x, target_y),
|
egui::pos2(target_x, target_y),
|
||||||
egui::vec2(panel_width, panel_height),
|
egui::vec2(panel_width, panel_height),
|
||||||
index < left_count,
|
target_visible,
|
||||||
visible,
|
|
||||||
code,
|
code,
|
||||||
title,
|
title,
|
||||||
history,
|
history,
|
||||||
@@ -1047,35 +1091,12 @@ fn draw_force_chart_area(
|
|||||||
id: egui::Id,
|
id: egui::Id,
|
||||||
target_pos: egui::Pos2,
|
target_pos: egui::Pos2,
|
||||||
size: egui::Vec2,
|
size: egui::Vec2,
|
||||||
from_left: bool,
|
|
||||||
target_visible: bool,
|
target_visible: bool,
|
||||||
code: &'static str,
|
code: &'static str,
|
||||||
title: &'static str,
|
title: &'static str,
|
||||||
values: &[f32],
|
values: &[f32],
|
||||||
) {
|
) {
|
||||||
let now = ctx.input(|input| input.time);
|
let anim = ctx.animate_bool(id.with("enter"), target_visible);
|
||||||
let active = target_visible && has_recent_resultant_force(values);
|
|
||||||
let state_id = id.with("active_state");
|
|
||||||
let mut last_active_at = ctx.data_mut(|data| data.get_temp::<f64>(state_id));
|
|
||||||
if active {
|
|
||||||
last_active_at = Some(now);
|
|
||||||
ctx.data_mut(|data| data.insert_temp(state_id, now));
|
|
||||||
} else if !target_visible {
|
|
||||||
last_active_at = None;
|
|
||||||
ctx.data_mut(|data| data.remove::<f64>(state_id));
|
|
||||||
}
|
|
||||||
|
|
||||||
let target_visible =
|
|
||||||
last_active_at.is_some_and(|active_at| now - active_at <= FORCE_PANEL_EXIT_DELAY_SECONDS);
|
|
||||||
let anim_id = id.with("enter");
|
|
||||||
let anim_seeded_id = id.with("enter_seeded");
|
|
||||||
let anim_seeded = ctx.data_mut(|data| data.get_temp::<bool>(anim_seeded_id).unwrap_or(false));
|
|
||||||
if target_visible && !anim_seeded {
|
|
||||||
ctx.animate_bool(anim_id, false);
|
|
||||||
ctx.data_mut(|data| data.insert_temp(anim_seeded_id, true));
|
|
||||||
}
|
|
||||||
|
|
||||||
let anim = ctx.animate_bool(anim_id, target_visible);
|
|
||||||
|
|
||||||
if anim <= 0.01 {
|
if anim <= 0.01 {
|
||||||
return;
|
return;
|
||||||
@@ -1087,27 +1108,20 @@ fn draw_force_chart_area(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let eased = ease_in_out(anim);
|
let eased = ease_in_out(anim);
|
||||||
let hidden_x = if from_left {
|
let hidden_y = ctx.content_rect().bottom() + HAND_FORCE_PANEL_GAP;
|
||||||
ctx.content_rect().left() - size.x - HAND_FORCE_PANEL_GAP
|
let y = egui::lerp(hidden_y..=target_pos.y, eased);
|
||||||
} else {
|
|
||||||
ctx.content_rect().right() + HAND_FORCE_PANEL_GAP
|
|
||||||
};
|
|
||||||
let x = egui::lerp(hidden_x..=target_pos.x, eased);
|
|
||||||
|
|
||||||
egui::Area::new(id)
|
egui::Area::new(id)
|
||||||
.fixed_pos(egui::pos2(x, target_pos.y))
|
.fixed_pos(egui::pos2(target_pos.x, y))
|
||||||
.constrain_to(viewport_panel_rect(ctx))
|
.constrain_to(viewport_panel_rect(ctx))
|
||||||
.order(egui::Order::Foreground)
|
.order(egui::Order::Foreground)
|
||||||
.show(ctx, |ui| {
|
.show(ctx, |ui| {
|
||||||
panel_frame(ctx).show(ui, |ui| {
|
panel_frame(ctx).show(ui, |ui| {
|
||||||
let padding = METRICS.panel_padding as f32;
|
|
||||||
let inner_width = (size.x - padding * 2.0).max(80.0);
|
|
||||||
let inner_height = (size.y - padding * 2.0).max(48.0);
|
|
||||||
ui.spacing_mut().item_spacing = egui::vec2(METRICS.item_gap, 6.0);
|
ui.spacing_mut().item_spacing = egui::vec2(METRICS.item_gap, 6.0);
|
||||||
ui.set_min_width(inner_width);
|
ui.set_min_width(size.x);
|
||||||
ui.set_max_width(inner_width);
|
ui.set_max_width(size.x);
|
||||||
ui.set_min_height(inner_height);
|
ui.set_min_height(size.y);
|
||||||
draw_force_chart_panel_contents(ui, code, title, values, inner_height);
|
draw_force_chart_panel_contents(ui, code, title, values, size.y);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -1130,7 +1144,7 @@ fn draw_force_chart_panel_contents(
|
|||||||
});
|
});
|
||||||
|
|
||||||
ui.add_space(6.0);
|
ui.add_space(6.0);
|
||||||
let chart_height = (content_height - 32.0).max(36.0);
|
let chart_height = (content_height - 32.0).max(90.0);
|
||||||
paint_resultant_force_chart(ui, values, chart_height);
|
paint_resultant_force_chart(ui, values, chart_height);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1138,7 +1152,7 @@ fn paint_resultant_force_chart(ui: &mut egui::Ui, values: &[f32], chart_height:
|
|||||||
const CHART_POINTS: usize = 42;
|
const CHART_POINTS: usize = 42;
|
||||||
const CHART_WINDOW_SECONDS: f32 = CHART_POINTS as f32 * FORCE_CHART_SAMPLE_SECONDS;
|
const CHART_WINDOW_SECONDS: f32 = CHART_POINTS as f32 * FORCE_CHART_SAMPLE_SECONDS;
|
||||||
|
|
||||||
let width = ui.available_width().max(80.0);
|
let width = ui.available_width().max(180.0);
|
||||||
let (rect, _) = ui.allocate_exact_size(egui::vec2(width, chart_height), egui::Sense::hover());
|
let (rect, _) = ui.allocate_exact_size(egui::vec2(width, chart_height), egui::Sense::hover());
|
||||||
let painter = ui.painter_at(rect);
|
let painter = ui.painter_at(rect);
|
||||||
let radius = egui::CornerRadius::same(5);
|
let radius = egui::CornerRadius::same(5);
|
||||||
@@ -1383,7 +1397,7 @@ fn paint_spatial_force_gauge(
|
|||||||
|
|
||||||
fn draw_pinned_panel(
|
fn draw_pinned_panel(
|
||||||
ctx: &egui::Context,
|
ctx: &egui::Context,
|
||||||
_panel: &mut FloatingPanelState,
|
panel: &mut FloatingPanelState,
|
||||||
title: &'static str,
|
title: &'static str,
|
||||||
id: &'static str,
|
id: &'static str,
|
||||||
preferred_width: f32,
|
preferred_width: f32,
|
||||||
@@ -1392,13 +1406,7 @@ fn draw_pinned_panel(
|
|||||||
) {
|
) {
|
||||||
let panel_width = responsive_panel_width(ctx, preferred_width, min_width);
|
let panel_width = responsive_panel_width(ctx, preferred_width, min_width);
|
||||||
let max_height = responsive_panel_height(ctx, ctx.content_rect().height(), 180.0);
|
let max_height = responsive_panel_height(ctx, ctx.content_rect().height(), 180.0);
|
||||||
let viewport = viewport_panel_rect(ctx);
|
let pos = responsive_panel_pos(ctx, panel.default_pos, panel_width);
|
||||||
let x = (viewport.center().x - panel_width * 0.5).clamp(
|
|
||||||
viewport.left(),
|
|
||||||
(viewport.right() - panel_width).max(viewport.left()),
|
|
||||||
);
|
|
||||||
let y = viewport.top() + layout::TITLE_BAR_HEIGHT + PANEL_VIEWPORT_MARGIN;
|
|
||||||
let pos = egui::pos2(x, y);
|
|
||||||
|
|
||||||
egui::Window::new(title)
|
egui::Window::new(title)
|
||||||
.id(egui::Id::new(id))
|
.id(egui::Id::new(id))
|
||||||
|
|||||||
@@ -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,20 +91,21 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
let local = smoothstep(0.66, 0.92, t);
|
let local = smoothstep(0.66, 1.0, t);
|
||||||
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,
|
||||||
@@ -128,6 +129,7 @@ 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,
|
||||||
@@ -165,7 +167,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 {
|
||||||
@@ -173,7 +175,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,6 +183,7 @@ 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,
|
||||||
@@ -223,45 +226,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; }
|
||||||
@@ -269,14 +272,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;
|
||||||
@@ -291,7 +294,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);
|
||||||
@@ -332,7 +335,8 @@ 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,
|
||||||
@@ -354,7 +358,7 @@ fn hand_image_uv_to_clip(image_uv: vec2f) -> vec2f {
|
|||||||
|
|
||||||
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 {
|
||||||
@@ -368,7 +372,6 @@ fn hand_image_uv_to_clip(image_uv: vec2f) -> vec2f {
|
|||||||
struct HandMembraneVertexOutput {
|
struct HandMembraneVertexOutput {
|
||||||
@builtin(position) clip_position: vec4f,
|
@builtin(position) clip_position: vec4f,
|
||||||
@location(0) local: vec2f,
|
@location(0) local: vec2f,
|
||||||
@location(1) intensity: f32,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn rotate_2d(point: vec2f, angle: f32) -> vec2f {
|
fn rotate_2d(point: vec2f, angle: f32) -> vec2f {
|
||||||
@@ -383,15 +386,12 @@ 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.
|
||||||
@@ -399,10 +399,14 @@ 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 remains open; the carrier quad clips the membrane at its end.
|
// 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);
|
||||||
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 * body_gate;
|
let body = side * rear * body_gate;
|
||||||
|
|
||||||
return max(cap, body);
|
return max(cap, body);
|
||||||
}
|
}
|
||||||
@@ -418,110 +422,45 @@ fn vs_hand_membrane(vertex: DotVertexInput, instance: DotInstanceInput) -> HandM
|
|||||||
var out: HandMembraneVertexOutput;
|
var out: HandMembraneVertexOutput;
|
||||||
out.clip_position = vec4f(hand_image_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;
|
||||||
out.intensity = saturate(instance.style.w);
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@fragment
|
@fragment
|
||||||
fn fs_hand_membrane(in: HandMembraneVertexOutput) -> @location(0) vec4f {
|
fn fs_hand_membrane(in: HandMembraneVertexOutput) -> @location(0) vec4f {
|
||||||
let p = in.local;
|
// The film shape matches the fingertip: closed round front, parallel rear sides,
|
||||||
let live = saturate(in.intensity);
|
// and a shallow rear arc instead of a second capsule end.
|
||||||
let response = smoothstep(0.03, 0.96, live);
|
let panel = fingertip_film_alpha(in.local, 0.66, -0.38, 0.72, 0.18, 0.045);
|
||||||
let hot = smoothstep(0.72, 0.96, live);
|
let inner = fingertip_film_alpha(in.local, 0.54, -0.36, 0.64, 0.12, 0.060);
|
||||||
let live_color = sample_range_color(live);
|
let border = clamp(panel - inner * 0.52, 0.0, 1.0);
|
||||||
|
|
||||||
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),
|
|
||||||
);
|
|
||||||
|
|
||||||
|
// 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 grid = vec2f(18.0, 34.0);
|
||||||
let cell_uv = fract(uv * grid) - vec2f(0.5, 0.5);
|
let cell = uv * grid - vec2f(0.5, 0.5);
|
||||||
let dot_dist = length(cell_uv * vec2f(1.0, 1.06));
|
let nearest = abs(fract(cell + vec2f(0.5, 0.5)) - vec2f(0.5, 0.5));
|
||||||
let dot_aa = max(fwidth(dot_dist) * 1.35, 0.006);
|
let grid_line = max(
|
||||||
let dots = (1.0 - smoothstep(0.105 - dot_aa, 0.105 + dot_aa, dot_dist)) * inner;
|
1.0 - smoothstep(0.014, 0.038, nearest.x),
|
||||||
|
1.0 - smoothstep(0.014, 0.038, nearest.y),
|
||||||
|
);
|
||||||
|
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 sheen_axis = p.x * 0.88 + p.y * 0.22 + 0.16;
|
let top_light = smoothstep(-0.52, 0.16, -in.local.y) * 0.20;
|
||||||
let sheen = (1.0 - smoothstep(0.018, 0.105, abs(sheen_axis))) * panel;
|
let side_glow = smoothstep(0.30, 0.70, abs(in.local.x)) * 0.26;
|
||||||
let shell_sheen = sheen * (0.26 + edge_fade * 0.74);
|
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;
|
||||||
|
|
||||||
// Temporary synthetic pressure hotspot. Real hand pressure dots are drawn above this pass.
|
let membrane_color = vec3f(0.006, 0.28, 0.38);
|
||||||
let pressure_center = vec2f(-0.08, -0.12);
|
let line_color = vec3f(0.12, 0.72, 0.88);
|
||||||
let pressure_dist = length((p - pressure_center) * vec2f(1.0, 0.74));
|
let rim_color = vec3f(0.18, 0.98, 1.0);
|
||||||
let pressure = (1.0 - smoothstep(0.05, 0.36, pressure_dist)) * inner;
|
let color = membrane_color * (0.68 + top_light + side_glow + scan)
|
||||||
let pressure_hot = (1.0 - smoothstep(0.02, 0.13, pressure_dist)) * inner;
|
+ 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 glass_base = vec3f(0.006, 0.055, 0.105);
|
return output_color(color, alpha);
|
||||||
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
|
@vertex
|
||||||
@@ -593,9 +532,33 @@ fn vs_hand_palm_chip(vertex: DotVertexInput, instance: DotInstanceInput) -> Hand
|
|||||||
|
|
||||||
@fragment
|
@fragment
|
||||||
fn fs_hand_palm_chip(in: HandPalmChipVertexOutput) -> @location(0) vec4f {
|
fn fs_hand_palm_chip(in: HandPalmChipVertexOutput) -> @location(0) vec4f {
|
||||||
// The live palm-dot pass draws every chip cell, including the idle dots.
|
// Dark rounded tile: this is the inset chip body sitting inside the palm surface.
|
||||||
// Keeping this background pass transparent prevents a second offset dot grid.
|
let panel = rounded_rect_alpha(in.local, 0.10, 0.040);
|
||||||
return output_color(vec3f(0.0, 0.0, 0.0), 0.0);
|
let inset = rounded_rect_alpha(in.local * vec2f(1.10, 1.08), 0.08, 0.052);
|
||||||
|
let rim = clamp(panel - inset * 0.72, 0.0, 1.0);
|
||||||
|
|
||||||
|
// Inactive chip pixels use the chip's real hand layout:
|
||||||
|
// horizontal 14 columns x 5 rows, or vertical 4 columns x 11 rows.
|
||||||
|
let uv = clamp(in.local * 0.5 + vec2f(0.5, 0.5), vec2f(0.0, 0.0), vec2f(1.0, 1.0));
|
||||||
|
let cell = abs(fract(uv * in.grid) - vec2f(0.5, 0.5));
|
||||||
|
let micro_pixel = 1.0 - smoothstep(0.105, 0.178, length(cell * vec2f(1.04, 0.94)));
|
||||||
|
|
||||||
|
let top_bevel = smoothstep(-0.96, -0.18, -in.local.y) * 0.16;
|
||||||
|
let lower_shadow = smoothstep(0.20, 0.92, in.local.y) * 0.22;
|
||||||
|
let side_bevel = smoothstep(0.58, 0.96, abs(in.local.x)) * 0.12;
|
||||||
|
let scan = (0.5 + 0.5 * sin((uv.y * 36.0 + uv.x * 7.0) * 6.28318)) * 0.026;
|
||||||
|
|
||||||
|
let base = vec3f(0.004, 0.012, 0.018);
|
||||||
|
let glass = vec3f(0.012, 0.048, 0.064);
|
||||||
|
let pixel_color = vec3f(0.075, 0.300, 0.360);
|
||||||
|
let rim_color = vec3f(0.060, 0.560, 0.670);
|
||||||
|
let color = base * (0.92 - lower_shadow)
|
||||||
|
+ glass * (0.52 + top_bevel + side_bevel + scan)
|
||||||
|
+ pixel_color * micro_pixel * 0.70
|
||||||
|
+ rim_color * rim * 0.60;
|
||||||
|
|
||||||
|
let alpha = panel * (0.64 + micro_pixel * 0.18 + rim * 0.20);
|
||||||
|
return output_color(color, alpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
@vertex
|
@vertex
|
||||||
@@ -603,10 +566,9 @@ fn vs_hand_palm_dot(vertex: DotVertexInput, instance: DotInstanceInput) -> DotVe
|
|||||||
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);
|
||||||
|
|
||||||
|
// Palm chip pixels are deliberately smaller than fingertip beads so they read as a chip matrix.
|
||||||
let center = hand_image_uv_to_clip(instance.world_position.xy);
|
let center = hand_image_uv_to_clip(instance.world_position.xy);
|
||||||
// Palm boards have more tightly packed cells than the fingertips, so use
|
let pixel_size = u.glyph.x * mix(0.13, 0.25, shaped);
|
||||||
// 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;
|
let ndc_offset = vertex.local * vec2f(pixel_size / u.viewport.x, pixel_size / u.viewport.y) * 2.0;
|
||||||
|
|
||||||
var out: DotVertexOutput;
|
var out: DotVertexOutput;
|
||||||
@@ -619,16 +581,17 @@ 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 pixel = chip_pixel_alpha(in.local, 0.52, 0.070);
|
||||||
|
let glow = circle_alpha(in.local, 0.95, 0.22) * intensity * 0.36;
|
||||||
|
|
||||||
let core = circle_alpha(in.local, 0.48, 0.07);
|
let cold = vec3f(0.070, 0.340, 0.360);
|
||||||
let halo = circle_alpha(in.local, 0.74, 0.14) * (0.10 + intensity * 0.26);
|
|
||||||
|
|
||||||
let idle = vec3f(0.060, 0.250, 0.320);
|
|
||||||
let gradient = sample_range_color(intensity);
|
let gradient = sample_range_color(intensity);
|
||||||
let color = mix(idle, gradient, smoothstep(0.0, 0.18, intensity))
|
let color = mix(cold, gradient, smoothstep(0.0, 0.20, intensity))
|
||||||
* mix(0.78, 1.18, intensity);
|
* (0.58 + intensity * 1.04)
|
||||||
|
+ gradient * glow * 0.72;
|
||||||
|
|
||||||
return output_color(color, max(core, halo));
|
let alpha = max(pixel * (0.20 + intensity * 0.76), glow);
|
||||||
|
return output_color(color, alpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
@vertex
|
@vertex
|
||||||
@@ -658,6 +621,7 @@ 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,
|
||||||
@@ -776,11 +740,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -800,17 +764,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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -876,7 +840,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;
|
||||||
@@ -884,7 +848,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