From 6e520f0421ab21090b404cc1af083fe03dda1fb9 Mon Sep 17 00:00:00 2001 From: hiina Date: Sat, 15 Feb 2025 12:28:26 -0700 Subject: [PATCH] add haptic and highlight to manipulator pickups --- .../functions/function_pickup.gd | 3 +++ override.cfg | 2 +- scenes/manipulator/manipulator.gd | 15 ++++++++++++ scenes/manipulator/manipulator.tscn | 23 +++++++++++++++++-- 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/addons/godot-xr-tools/functions/function_pickup.gd b/addons/godot-xr-tools/functions/function_pickup.gd index 49af7f9..3452457 100644 --- a/addons/godot-xr-tools/functions/function_pickup.gd +++ b/addons/godot-xr-tools/functions/function_pickup.gd @@ -330,7 +330,10 @@ func _update_closest_object() -> void: closest_object = new_closest_obj if is_instance_valid(closest_object): closest_object.request_highlight(self, true) + _play_haptic_feedback() +func _play_haptic_feedback() -> void: + _controller.trigger_haptic_pulse("haptic", 1, 1, 0.1, 0.0) # Find the pickable object closest to our hand's grab location func _get_closest_grab() -> Node3D: diff --git a/override.cfg b/override.cfg index 0d1998e..4cd32b3 100644 --- a/override.cfg +++ b/override.cfg @@ -1,3 +1,3 @@ [xr] -openxr/enabled=false +openxr/enabled=true diff --git a/scenes/manipulator/manipulator.gd b/scenes/manipulator/manipulator.gd index 05624b3..ed19294 100644 --- a/scenes/manipulator/manipulator.gd +++ b/scenes/manipulator/manipulator.gd @@ -23,12 +23,19 @@ func _ready() -> void: super() picked_up.connect(_on_pickable_object_picked_up) dropped.connect(_on_pickable_object_dropped) + highlight_updated.connect(_on_highlight_updated) if Engine.is_editor_hint(): return attractor = $VisualAttractorSphere + # Make the material unique so each manipulator can have its own color + var visual = $Visual + if visual and visual.get_surface_override_material_count() > 0: + var material = visual.get_surface_override_material(0).duplicate() + visual.set_surface_override_material(0, material) + func _process(delta: float) -> void: if Engine.is_editor_hint(): return @@ -44,3 +51,11 @@ func _on_pickable_object_picked_up(pickable: XRToolsPickable) -> void: func _on_pickable_object_dropped(_pickable: XRToolsPickable) -> void: held_controller = null + +func _on_highlight_updated(_pickable: XRToolsPickable, enable: bool) -> void: + var visual = $Visual + if visual and visual.get_surface_override_material_count() > 0: + if enable: + visual.get_surface_override_material(0).emission_energy_multiplier = 1.0 + else: + visual.get_surface_override_material(0).emission_energy_multiplier = 0.20 diff --git a/scenes/manipulator/manipulator.tscn b/scenes/manipulator/manipulator.tscn index 7ff62b1..2dd3030 100644 --- a/scenes/manipulator/manipulator.tscn +++ b/scenes/manipulator/manipulator.tscn @@ -1,11 +1,16 @@ -[gd_scene load_steps=7 format=3 uid="uid://bifpsyvpcem3a"] +[gd_scene load_steps=14 format=3 uid="uid://bifpsyvpcem3a"] [ext_resource type="Script" path="res://scenes/manipulator/manipulator.gd" id="1_g7g3k"] [ext_resource type="PackedScene" uid="uid://c25yxb0vt53vc" path="res://addons/godot-xr-tools/objects/grab_points/grab_point_hand_left.tscn" id="2_nqt0c"] +[ext_resource type="Animation" uid="uid://dlxa6f6hwurka" path="res://addons/godot-xr-tools/hands/animations/left/Default pose.res" id="3_gcgym"] [ext_resource type="PackedScene" uid="uid://ctw7nbntd5pcj" path="res://addons/godot-xr-tools/objects/grab_points/grab_point_hand_right.tscn" id="3_luhd1"] +[ext_resource type="Animation" uid="uid://c0u2a3yc2vhg8" path="res://addons/godot-xr-tools/hands/animations/left/Sign_Point.res" id="3_opbxn"] +[ext_resource type="Script" path="res://addons/godot-xr-tools/hands/poses/hand_pose_settings.gd" id="4_hxnqj"] +[ext_resource type="Animation" uid="uid://ky28birj4su6" path="res://addons/godot-xr-tools/hands/animations/right/Default pose.res" id="6_2mx3j"] +[ext_resource type="Animation" uid="uid://ccy3e7a0hvxyl" path="res://addons/godot-xr-tools/hands/animations/right/Sign_Point.res" id="7_hs6vs"] [sub_resource type="SphereShape3D" id="SphereShape3D_f261g"] -radius = 0.1 +radius = 0.15 [sub_resource type="SphereMesh" id="SphereMesh_mou0a"] radius = 0.1 @@ -17,6 +22,16 @@ emission_enabled = true emission = Color(1.44392e-06, 0.591371, 0.38197, 1) emission_energy_multiplier = 0.22 +[sub_resource type="Resource" id="Resource_2ttqc"] +script = ExtResource("4_hxnqj") +open_pose = ExtResource("3_gcgym") +closed_pose = ExtResource("3_opbxn") + +[sub_resource type="Resource" id="Resource_vtbag"] +script = ExtResource("4_hxnqj") +open_pose = ExtResource("6_2mx3j") +closed_pose = ExtResource("7_hs6vs") + [node name="Manipulator" type="RigidBody3D"] collision_layer = 4 collision_mask = 196615 @@ -36,5 +51,9 @@ mesh = SubResource("SphereMesh_mou0a") surface_material_override/0 = SubResource("StandardMaterial3D_ljyno") [node name="GrabPointHandLeft" parent="." instance=ExtResource("2_nqt0c")] +visible = true +hand_pose = SubResource("Resource_2ttqc") [node name="GrabPointHandRight" parent="." instance=ExtResource("3_luhd1")] +visible = true +hand_pose = SubResource("Resource_vtbag")