-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhud_binding.py
More file actions
67 lines (44 loc) · 1.71 KB
/
hud_binding.py
File metadata and controls
67 lines (44 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
class HUDBinding:
def __init__(self):
self.bindings = []
def bind(self, shape_name, signal, mode="mid", sensitivity=1.0):
self.bindings.append({
"shape": shape_name,
"signal": signal,
"mode": mode,
"sensitivity": sensitivity
})
# ---------------------------------
# RESOLVE ACTIVE VISUALS
# ---------------------------------
def resolve(self, inventory, signals):
active = []
for b in self.bindings:
value = signals.get(b["signal"], 0)
shape = inventory.get(b["shape"])
if not shape:
continue
threshold_low = 0.3 * b["sensitivity"]
threshold_high = 0.7 * b["sensitivity"]
if value < threshold_low and b["mode"] == "low":
active.append(shape)
elif threshold_low <= value <= threshold_high and b["mode"] == "mid":
active.append(shape)
elif value > threshold_high and b["mode"] == "high":
active.append(shape)
return active
def adapt(self, signals, learning_rate=0.05):
for b in self.bindings:
value = signals.get(b["signal"], 0)
# -----------------------------
# LOW SIGNAL RESPONSE
# -----------------------------
if value < 0.3:
b["sensitivity"] -= learning_rate
# -----------------------------
# HIGH SIGNAL RESPONSE
# -----------------------------
elif value > 0.7:
b["sensitivity"] += learning_rate
# clamp
b["sensitivity"] = max(0.1, min(2.0, b["sensitivity"]))