added signalling to button and demo

This commit is contained in:
Hartmut Seichter 2025-07-08 21:25:46 +02:00
parent af27e657f6
commit 7987fa3c8a
2 changed files with 31 additions and 2 deletions

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=6 format=3 uid="uid://bj5ykdjle10tt"] [gd_scene load_steps=8 format=3 uid="uid://bj5ykdjle10tt"]
[ext_resource type="Script" uid="uid://dmq3i7qmo1qe0" path="res://addons/vrpn/scripts/VRPN_Client.gd" id="2_24d08"] [ext_resource type="Script" uid="uid://dmq3i7qmo1qe0" path="res://addons/vrpn/scripts/VRPN_Client.gd" id="2_24d08"]
[ext_resource type="Script" uid="uid://dpj1wrvfsiq4v" path="res://addons/vrpn/scripts/VRPN_Tracker.gd" id="2_170dk"] [ext_resource type="Script" uid="uid://dpj1wrvfsiq4v" path="res://addons/vrpn/scripts/VRPN_Tracker.gd" id="2_170dk"]
@ -8,6 +8,22 @@
[sub_resource type="PlaneMesh" id="PlaneMesh_24d08"] [sub_resource type="PlaneMesh" id="PlaneMesh_24d08"]
size = Vector2(6, 2) size = Vector2(6, 2)
[sub_resource type="SphereMesh" id="SphereMesh_j4l28"]
radius = 0.25
height = 0.5
radial_segments = 32
rings = 16
[sub_resource type="GDScript" id="GDScript_j4l28"]
resource_name = "ButtonReact"
script/source = "extends Node3D
func _on_button_0_on_vrpn_button(data):
if 0 in data['changes']:
self.visible = (data['changes'][0] == 1)
"
[node name="Node3D" type="Node3D"] [node name="Node3D" type="Node3D"]
[node name="Camera3D" type="Camera3D" parent="."] [node name="Camera3D" type="Camera3D" parent="."]
@ -73,5 +89,16 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.769847, 0)
text = "X-Axis" text = "X-Axis"
[node name="Button0" type="Node3D" parent="Root/SpinTracker" node_paths=PackedStringArray("vrpn_client")] [node name="Button0" type="Node3D" parent="Root/SpinTracker" node_paths=PackedStringArray("vrpn_client")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.21693, 0)
script = ExtResource("4_j4l28") script = ExtResource("4_j4l28")
vrpn_client = NodePath("../../VRPN") vrpn_client = NodePath("../../VRPN")
[node name="MeshInstance3D" type="MeshInstance3D" parent="Root/SpinTracker/Button0"]
mesh = SubResource("SphereMesh_j4l28")
script = SubResource("GDScript_j4l28")
[node name="Label3D" type="Label3D" parent="Root/SpinTracker/Button0/MeshInstance3D"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.431905, 0)
text = "Button"
[connection signal="on_vrpn_button" from="Root/SpinTracker/Button0" to="Root/SpinTracker/Button0/MeshInstance3D" method="_on_button_0_on_vrpn_button"]

View file

@ -7,6 +7,8 @@ extends Node
var state : int = 0 var state : int = 0
signal on_vrpn_button(data:Dictionary)
func _ready(): func _ready():
if not vrpn_client: if not vrpn_client:
push_warning("No VRPN client for button on '%s' given." % [self.name]) push_warning("No VRPN client for button on '%s' given." % [self.name])
@ -15,4 +17,4 @@ func _ready():
func _on_vrpn(vrpn_data : Dictionary) -> void: func _on_vrpn(vrpn_data : Dictionary) -> void:
if vrpn_data['sensor'] == button_sensor: if vrpn_data['sensor'] == button_sensor:
pass on_vrpn_button.emit(vrpn_data)