Add per-pod orientation gizmo to the API demo.

Shows live accel attitude with a front-view cylinder (flat / facing / steer) and a TOP marker that rotates with the mesh.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-09-26 13:41:07 +02:00
co-authored by Cursor
parent a32a223881
commit 54d42dade9
5 changed files with 172 additions and 5 deletions
+23 -4
View File
@@ -12,6 +12,7 @@ const PANEL_BORDER_FLASH := Color(1.0, 0.82, 0.15, 1.0)
const LED_MODES: PackedStringArray = ["color", "clear", "progress", "digit", "blink", "find-me"]
const LED_MODES_COLOR_INTENSITY: PackedStringArray = ["color", "progress", "digit", "blink"]
const ORIENTATION_GIZMO_SCENE := preload("res://scenes/orientation_gizmo.tscn")
@onready var status_label: Label = $UiLayer/TopBar/StatusLabel
@onready var log_output: TextEdit = $UiLayer/MainSplit/LogPanel/LogOutput
@@ -122,6 +123,7 @@ func _stop_stream() -> void:
"triple": false,
})
ui["values_label"].text = "—"
ui["orient_gizmo"].clear()
_streaming = false
start_stream_btn.disabled = _client_ui.is_empty()
@@ -328,14 +330,26 @@ func _populate_clients(clients: Array) -> void:
_add_led_preset_btn(led_presets, "Blau", cid, available, func() -> void: _led_apply_preset(cid, "color", Color(0.2, 0.4, 1), 128))
_add_led_preset_btn(led_presets, "Find", cid, available, func() -> void: _led_apply_preset(cid, "find-me"))
var accel_row := HBoxContainer.new()
accel_row.add_theme_constant_override("separation", 12)
accel_row.size_flags_horizontal = Control.SIZE_EXPAND_FILL
vbox.add_child(accel_row)
var values_label := Label.new()
values_label.text = "—"
values_label.add_theme_font_size_override("font_size", 12)
values_label.add_theme_color_override("font_color", Color(0.65, 0.85, 0.75))
values_label.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
vbox.add_child(values_label)
values_label.size_flags_horizontal = Control.SIZE_EXPAND_FILL
values_label.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
accel_row.add_child(values_label)
var orient_gizmo: OrientationGizmo = ORIENTATION_GIZMO_SCENE.instantiate()
accel_row.add_child(orient_gizmo)
clients_list.add_child(panel)
# clear() after enter_tree so @onready nodes exist; _ready also clears.
orient_gizmo.clear()
_client_ui[cid] = {
"available": available,
@@ -360,6 +374,7 @@ func _populate_clients(clients: Array) -> void:
"led_digit_row": led_digit_row,
"led_blink_row": led_blink_row,
"values_label": values_label,
"orient_gizmo": orient_gizmo,
}
_update_led_fields(cid)
@@ -443,14 +458,18 @@ func _on_input(data: Dictionary) -> void:
var ui: Dictionary = _client_ui[cid]
var lines: PackedStringArray = []
if client.get("valid", false):
var ax := int(client.get("x", 0))
var ay := int(client.get("y", 0))
var az := int(client.get("z", 0))
lines.append(
"x=%d y=%d z=%d (age %sms)" % [
int(client.get("x", 0)),
int(client.get("y", 0)),
int(client.get("z", 0)),
ax, ay, az,
str(client.get("accel_age_ms", "?")),
]
)
ui["orient_gizmo"].set_accel(Vector3(float(ax), float(ay), float(az)))
else:
ui["orient_gizmo"].clear()
var tap_kind := str(client.get("tap_kind", "none"))
if tap_kind != "none":