Skip to content

Commit 0d6b772

Browse files
authored
Merge pull request #1098 from BastiaanOlij/openxr_hand_tracking_demo_settings
Updated hand tracking demo based on Godot changes in PR 95153
2 parents 8be477c + dbe9f48 commit 0d6b772

File tree

8 files changed

+204
-74
lines changed

8 files changed

+204
-74
lines changed

xr/openxr_hand_tracking_demo/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Renderer: Compatibility
88

99
> [!NOTE]
1010
>
11-
> This demo requires Godot 4.3 or later
11+
> This demo requires Godot 4.4 or later
1212
1313
## Screenshots
1414

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
uid://djo0o7s7ix543

xr/openxr_hand_tracking_demo/hand_info.gd

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ extends Node3D
22

33
@export_enum("Left", "Right") var hand : int = 0
44

5+
@export var fallback_mesh : Node3D
56

67
# Called every frame. 'delta' is the elapsed time since the previous frame.
78
func _process(delta):
@@ -43,17 +44,23 @@ func _process(delta):
4344
if hand_tracker:
4445
text += "\nHand tracker found\n"
4546

46-
if hand_tracker.has_tracking_data:
47-
if hand_tracker.hand_tracking_source == XRHandTracker.HAND_TRACKING_SOURCE_UNKNOWN:
48-
text += "- Source: unknown\n"
49-
elif hand_tracker.hand_tracking_source == XRHandTracker.HAND_TRACKING_SOURCE_UNOBSTRUCTED:
50-
text += "- Source: optical hand tracking\n"
51-
elif hand_tracker.hand_tracking_source == XRHandTracker.HAND_TRACKING_SOURCE_CONTROLLER:
52-
text += "- Source: inferred from controller\n"
53-
else:
54-
text += "- Source: %d\n" % [ hand_tracker.hand_tracking_source ]
47+
# Report data source specified
48+
if hand_tracker.hand_tracking_source == XRHandTracker.HAND_TRACKING_SOURCE_UNKNOWN:
49+
text += "- Source: unknown\n"
50+
elif hand_tracker.hand_tracking_source == XRHandTracker.HAND_TRACKING_SOURCE_UNOBSTRUCTED:
51+
text += "- Source: optical hand tracking\n"
52+
elif hand_tracker.hand_tracking_source == XRHandTracker.HAND_TRACKING_SOURCE_CONTROLLER:
53+
text += "- Source: inferred from controller\n"
54+
elif hand_tracker.hand_tracking_source == XRHandTracker.HAND_TRACKING_SOURCE_NOT_TRACKED:
55+
text += "- Source: no source\n"
5556
else:
56-
text += "- No tracking data\n"
57+
text += "- Source: %d\n" % [ hand_tracker.hand_tracking_source ]
58+
59+
# If we're not tracking, show our fallback mesh on our controller tracking.
60+
# If we're also not controller tracking, we can't show anything.
61+
# Note: this is only a sphere in this example.
62+
if fallback_mesh:
63+
fallback_mesh.visible = not hand_tracker.has_tracking_data
5764
else:
5865
text += "\nNo hand tracker found!\n"
5966

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
uid://dxi1173oqpsr5

xr/openxr_hand_tracking_demo/main.tscn

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
[gd_scene load_steps=17 format=3 uid="uid://br3bss6kac8pa"]
1+
[gd_scene load_steps=18 format=3 uid="uid://br3bss6kac8pa"]
22

33
[ext_resource type="PackedScene" uid="uid://d22k0sp2hinew" path="res://assets/gltf/LeftHandHumanoid.gltf" id="2_3hxem"]
44
[ext_resource type="Script" uid="uid://dpqdbsepdkd4h" path="res://start_vr.gd" id="2_5rtkn"]
55
[ext_resource type="PackedScene" uid="uid://dlswhmq6s52gu" path="res://assets/gltf/RightHandHumanoid.gltf" id="3_oifi1"]
66
[ext_resource type="PackedScene" uid="uid://byif52d1xkl3u" path="res://pickup/pickup_handler.tscn" id="3_sg1io"]
77
[ext_resource type="Texture2D" uid="uid://b1waowk6l76ap" path="res://assets/images/pattern.png" id="4_3x0ea"]
88
[ext_resource type="PackedScene" uid="uid://dtabh705qyufu" path="res://hand_info.tscn" id="5_wlhtu"]
9-
[ext_resource type="Script" path="res://hand_controller.gd" id="6_e5cto"]
9+
[ext_resource type="Script" uid="uid://djo0o7s7ix543" path="res://hand_controller.gd" id="6_e5cto"]
1010
[ext_resource type="PackedScene" uid="uid://hanl00aqvu7u" path="res://objects/table.tscn" id="6_rfmma"]
1111
[ext_resource type="PackedScene" uid="uid://cerkxyasq8t8b" path="res://objects/box.tscn" id="7_6sqt7"]
12-
[ext_resource type="Script" path="res://hand_mesh.gd" id="7_yj2fr"]
13-
[ext_resource type="Script" path="res://xr_hand_fallback_modifier_3d.gd" id="8_gdsnk"]
12+
[ext_resource type="Script" uid="uid://dxi1173oqpsr5" path="res://hand_mesh.gd" id="7_yj2fr"]
13+
[ext_resource type="Script" uid="uid://bnt74t168r248" path="res://xr_hand_fallback_modifier_3d.gd" id="8_gdsnk"]
1414

1515
[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_eyx45"]
1616
sky_horizon_color = Color(0.64625, 0.65575, 0.67075, 1)
@@ -35,6 +35,10 @@ size = Vector2(1000, 1000)
3535
subdivide_width = 10
3636
subdivide_depth = 10
3737

38+
[sub_resource type="SphereMesh" id="SphereMesh_d5x0p"]
39+
radius = 0.01
40+
height = 0.02
41+
3842
[node name="Main" type="Node3D"]
3943

4044
[node name="StartVR" type="Node3D" parent="."]
@@ -76,12 +80,14 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.13752, 0.941084, 0)
7680
[node name="Box03" parent="Table" instance=ExtResource("7_6sqt7")]
7781
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.0746718, 1.06282, 0)
7882

79-
[node name="LeftHandInfo" parent="Table" instance=ExtResource("5_wlhtu")]
83+
[node name="LeftHandInfo" parent="Table" node_paths=PackedStringArray("fallback_mesh") instance=ExtResource("5_wlhtu")]
8084
transform = Transform3D(0.939693, -0.085635, 0.331126, 0, 0.968147, 0.25038, -0.34202, -0.23528, 0.909761, -0.713026, 0.8718, -0.309953)
85+
fallback_mesh = NodePath("../../XROrigin3D/LeftHandController/FullbackMesh")
8186

82-
[node name="RightHandInfo" parent="Table" instance=ExtResource("5_wlhtu")]
87+
[node name="RightHandInfo" parent="Table" node_paths=PackedStringArray("fallback_mesh") instance=ExtResource("5_wlhtu")]
8388
transform = Transform3D(0.939693, 0.085635, -0.331126, 0, 0.968147, 0.25038, 0.34202, -0.23528, 0.909761, 0.278022, 0.8718, -0.381943)
8489
hand = 1
90+
fallback_mesh = NodePath("../../XROrigin3D/RightHandController/FullbackMesh")
8591

8692
[node name="XROrigin3D" type="XROrigin3D" parent="."]
8793

@@ -95,6 +101,9 @@ pose = &"palm_pose"
95101
show_when_tracked = true
96102
script = ExtResource("6_e5cto")
97103

104+
[node name="FullbackMesh" type="MeshInstance3D" parent="XROrigin3D/LeftHandController"]
105+
mesh = SubResource("SphereMesh_d5x0p")
106+
98107
[node name="PickupHandler" parent="XROrigin3D/LeftHandController" instance=ExtResource("3_sg1io")]
99108
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.05, 0, 0)
100109
pickup_action = "pickup"
@@ -106,6 +115,10 @@ pose = &"palm_pose"
106115
show_when_tracked = true
107116
script = ExtResource("6_e5cto")
108117

118+
[node name="FullbackMesh" type="MeshInstance3D" parent="XROrigin3D/RightHandController"]
119+
mesh = SubResource("SphereMesh_d5x0p")
120+
skeleton = NodePath("../../LeftHandController")
121+
109122
[node name="PickupHandler" parent="XROrigin3D/RightHandController" instance=ExtResource("3_sg1io")]
110123
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.05, 0, 0)
111124
pickup_action = "pickup"

0 commit comments

Comments
 (0)