Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated hand tracking demo based on Godot changes in PR 95153 #1098

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,5 @@ animation/remove_immutable_tracks=true
animation/import_rest_as_RESET=false
import_script/path=""
_subresources={}
fbx/importer=0
fbx/allow_geometry_helper_nodes=false
fbx/embedded_image_handling=1
gltf/naming_version=1
gltf/embedded_image_handling=1
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,5 @@ animation/remove_immutable_tracks=true
animation/import_rest_as_RESET=false
import_script/path=""
_subresources={}
fbx/importer=0
fbx/allow_geometry_helper_nodes=false
fbx/embedded_image_handling=1
gltf/naming_version=1
gltf/embedded_image_handling=1
27 changes: 17 additions & 10 deletions xr/openxr_hand_tracking_demo/hand_info.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ extends Node3D

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

@export var fallback_mesh : Node3D

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
Expand Down Expand Up @@ -36,17 +37,23 @@ func _process(delta):
if hand_tracker:
text += "\nHand tracker found\n"

if hand_tracker.has_tracking_data:
if hand_tracker.hand_tracking_source == XRHandTracker.HAND_TRACKING_SOURCE_UNKNOWN:
text += "- Source: unknown\n"
elif hand_tracker.hand_tracking_source == XRHandTracker.HAND_TRACKING_SOURCE_UNOBSTRUCTED:
text += "- Source: optical hand tracking\n"
elif hand_tracker.hand_tracking_source == XRHandTracker.HAND_TRACKING_SOURCE_CONTROLLER:
text += "- Source: inferred from controller\n"
else:
text += "- Source: %d\n" % [ hand_tracker.hand_tracking_source ]
# Report data source specified
if hand_tracker.hand_tracking_source == XRHandTracker.HAND_TRACKING_SOURCE_UNKNOWN:
text += "- Source: unknown\n"
elif hand_tracker.hand_tracking_source == XRHandTracker.HAND_TRACKING_SOURCE_UNOBSTRUCTED:
text += "- Source: optical hand tracking\n"
elif hand_tracker.hand_tracking_source == XRHandTracker.HAND_TRACKING_SOURCE_CONTROLLER:
text += "- Source: inferred from controller\n"
elif hand_tracker.hand_tracking_source == XRHandTracker.HAND_TRACKING_SOURCE_NOT_TRACKED:
text += "- Source: no source\n"
else:
text += "- No tracking data\n"
text += "- Source: %d\n" % [ hand_tracker.hand_tracking_source ]

# If we're not tracking, show our fallback mesh on our controller tracking.
# If we're also not controller tracking, we can't show anything.
# Note: this is only a sphere in this example.
if fallback_mesh:
fallback_mesh.visible = not hand_tracker.has_tracking_data
else:
text += "\nNo hand tracker found!\n"

Expand Down
19 changes: 16 additions & 3 deletions xr/openxr_hand_tracking_demo/main.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=14 format=3 uid="uid://br3bss6kac8pa"]
[gd_scene load_steps=15 format=3 uid="uid://br3bss6kac8pa"]

[ext_resource type="PackedScene" uid="uid://d22k0sp2hinew" path="res://assets/gltf/LeftHandHumanoid.gltf" id="2_3hxem"]
[ext_resource type="Script" path="res://start_vr.gd" id="2_5rtkn"]
Expand Down Expand Up @@ -32,6 +32,10 @@ size = Vector2(1000, 1000)
subdivide_width = 10
subdivide_depth = 10

[sub_resource type="SphereMesh" id="SphereMesh_d5x0p"]
radius = 0.01
height = 0.02

[node name="Main" type="Node3D"]

[node name="StartVR" type="Node3D" parent="."]
Expand Down Expand Up @@ -73,12 +77,14 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.13752, 0.941084, 0)
[node name="Box03" parent="Table" instance=ExtResource("7_6sqt7")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.0746718, 1.06282, 0)

[node name="LeftHandInfo" parent="Table" instance=ExtResource("5_wlhtu")]
[node name="LeftHandInfo" parent="Table" node_paths=PackedStringArray("fallback_mesh") instance=ExtResource("5_wlhtu")]
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)
fallback_mesh = NodePath("../../XROrigin3D/LeftHandController/FallbackMesh")

[node name="RightHandInfo" parent="Table" instance=ExtResource("5_wlhtu")]
[node name="RightHandInfo" parent="Table" node_paths=PackedStringArray("fallback_mesh") instance=ExtResource("5_wlhtu")]
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)
hand = 1
fallback_mesh = NodePath("../../XROrigin3D/RightHandController/FallbackMesh")

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

Expand All @@ -91,6 +97,9 @@ tracker = &"left_hand"
pose = &"pose"
show_when_tracked = true

[node name="FallbackMesh" type="MeshInstance3D" parent="XROrigin3D/LeftHandController"]
mesh = SubResource("SphereMesh_d5x0p")

[node name="PickupHandler" parent="XROrigin3D/LeftHandController" instance=ExtResource("3_sg1io")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.05, 0, 0)
pickup_action = "pickup"
Expand All @@ -101,6 +110,10 @@ tracker = &"right_hand"
pose = &"pose"
show_when_tracked = true

[node name="FallbackMesh" type="MeshInstance3D" parent="XROrigin3D/RightHandController"]
mesh = SubResource("SphereMesh_d5x0p")
skeleton = NodePath("../../LeftHandController")

[node name="PickupHandler" parent="XROrigin3D/RightHandController" instance=ExtResource("3_sg1io")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.05, 0, 0)
pickup_action = "pickup"
Expand Down
3 changes: 3 additions & 0 deletions xr/openxr_hand_tracking_demo/project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,8 @@ openxr/enabled=true
openxr/reference_space=2
openxr/foveation_level=2
openxr/foveation_dynamic=true
openxr/extensions/hand_tracking=true
openxr/extensions/hand_interaction_profile=true
shaders/enabled=true
openxr/extensions/hand_tracking_unobstructed_data_source=true
openxr/extensions/hand_tracking_controller_data_source=true