This commit is contained in:
Guillaume Vern
2025-10-09 16:03:18 +02:00
parent 4693cfb552
commit 80a4c128cc
16 changed files with 1029 additions and 179 deletions
+32
View File
@@ -30,6 +30,9 @@ signal released(pickable, by)
# Signal emitted when the user presses the action button while holding this object
signal action_pressed(pickable)
# Signal emitted when the user releases the action button while holding this object
signal action_released(pickable)
# Signal emitted when the highlight state changes
signal highlight_updated(pickable, enable)
@@ -107,6 +110,10 @@ var _highlight_requests : Dictionary = {}
# Is this node highlighted
var _highlighted : bool = false
var _controller : XRController3D
@onready var _gpu_particles: GPUParticles3D = get_node("GPUParticles3D")
# Remember some state so we can return to it when the user drops the object
@onready var original_collision_mask : int = collision_mask
@@ -120,12 +127,29 @@ func is_xr_class(name : String) -> bool:
# Called when the node enters the scene tree for the first time.
func _ready():
if _gpu_particles != null:
_gpu_particles.amount_ratio = 0.0
# Get all grab points
for child in get_children():
var grab_point := child as XRToolsGrabPoint
if grab_point:
_grab_points.push_back(grab_point)
@onready var rumble_timer = 0.0
func _process(delta):
if _controller:
var trigger_level = _controller.get_float("trigger")
if _gpu_particles != null and is_picked_up():
_gpu_particles.amount_ratio = trigger_level
rumble_timer -= delta
if rumble_timer <= 0.0:
_controller.trigger_haptic_pulse(&"haptic", 30, trigger_level, 0.11, 0.0)
rumble_timer = 0.1
else:
rumble_timer = 0.0
# Called when the node exits the tree
func _exit_tree():
@@ -203,6 +227,7 @@ func drop():
if not is_picked_up():
return
# Request secondary grabber to drop
if _grab_driver.secondary:
_grab_driver.secondary.by.drop_object()
@@ -292,6 +317,9 @@ func let_go(by: Node3D, p_linear_velocity: Vector3, p_angular_velocity: Vector3)
# Skip if not picked up
if not is_picked_up():
return
if _gpu_particles != null:
_gpu_particles.amount_ratio = 0.0
# Get the grab information
var grab := _grab_driver.get_grab(by)
@@ -398,3 +426,7 @@ func _get_grab_point(grabber : Node3D, current : XRToolsGrabPoint) -> XRToolsGra
func _set_ranged_grab_method(new_value: int) -> void:
ranged_grab_method = new_value
can_ranged_grab = new_value != RangedMethod.NONE
func _on_action_pressed(variant: Variant):
_controller = get_picked_up_by_controller()