2023-11-20 00:58:26 +02:00
|
|
|
extends XRController3D
|
|
|
|
|
2024-05-06 19:22:12 +03:00
|
|
|
const Pointer = preload ("res://lib/utils/pointer/pointer.gd")
|
|
|
|
const Initiator = preload ("res://lib/utils/pointer/initiator.gd")
|
|
|
|
const Finger = preload ("res://lib/utils/touch/finger.gd")
|
|
|
|
const Touch = preload ("res://lib/utils/touch/touch.gd")
|
|
|
|
const Collide = preload ("res://lib/utils/touch/collide.gd")
|
2024-05-22 19:38:28 +03:00
|
|
|
const Miniature = preload ("res://content/system/miniature/miniature.gd")
|
2024-05-06 19:22:12 +03:00
|
|
|
|
|
|
|
@onready var hand = $hand_l
|
|
|
|
@onready var hand_mesh = $hand_l/Armature/Skeleton3D/mesh_Hand_L
|
2024-05-06 20:01:46 +03:00
|
|
|
@onready var auto_hand = $AutoHandtracker
|
2024-05-06 19:22:12 +03:00
|
|
|
|
|
|
|
@onready var index_tip = $IndexTip
|
|
|
|
@onready var thumb_tip = $ThumbTip
|
|
|
|
@onready var middle_tip = $MiddleTip
|
|
|
|
|
|
|
|
@onready var mini_view_button = $Palm/QuickActions/MiniView
|
|
|
|
@onready var temperature_button = $Palm/QuickActions/Temperature
|
|
|
|
@onready var humidity_button = $Palm/QuickActions/Humidity
|
|
|
|
|
|
|
|
@onready var palm = $Palm
|
|
|
|
@onready var ray: RayCast3D = $Raycast
|
|
|
|
@onready var quick_actions = $Palm/QuickActions
|
|
|
|
|
2024-05-23 15:18:21 +03:00
|
|
|
@export var show_grid = false:
|
|
|
|
set(value):
|
|
|
|
show_grid = value
|
|
|
|
|
|
|
|
if ray != null:
|
|
|
|
ray.with_grid = value
|
|
|
|
|
2024-05-23 01:36:49 +03:00
|
|
|
var hand_active = false:
|
|
|
|
set(value):
|
|
|
|
hand_active = value
|
|
|
|
|
|
|
|
if pointer != null:
|
|
|
|
pointer.set_physics_process(value)
|
|
|
|
|
2024-05-06 19:22:12 +03:00
|
|
|
var initiator: Initiator = Initiator.new()
|
|
|
|
var collide: Collide
|
|
|
|
var pointer: Pointer
|
|
|
|
var press_distance = 0.02
|
|
|
|
var grip_distance = 0.02
|
|
|
|
|
|
|
|
var pressed = false
|
|
|
|
var grabbed = false
|
2023-11-20 00:58:26 +02:00
|
|
|
|
|
|
|
func _ready():
|
2024-05-22 19:38:28 +03:00
|
|
|
button_pressed.connect(func(action_name):
|
|
|
|
EventSystem.emit_action(action_name, true, false)
|
|
|
|
)
|
|
|
|
|
|
|
|
button_released.connect(func(action_name):
|
|
|
|
EventSystem.emit_action(action_name, false, false)
|
|
|
|
)
|
2023-11-20 00:58:26 +02:00
|
|
|
|
2024-05-06 19:22:12 +03:00
|
|
|
_setup_hand()
|
|
|
|
|
|
|
|
func _process(_delta):
|
2024-05-06 20:01:46 +03:00
|
|
|
if !hand_active:
|
|
|
|
if quick_actions.is_inside_tree(): palm.remove_child(quick_actions)
|
|
|
|
return
|
|
|
|
|
2024-05-22 19:38:28 +03:00
|
|
|
if App.camera.global_transform.basis.z.dot(palm.global_transform.basis.x) > 0.85:
|
2024-05-06 19:22:12 +03:00
|
|
|
if quick_actions.is_inside_tree() == false: palm.add_child(quick_actions)
|
|
|
|
else:
|
|
|
|
if quick_actions.is_inside_tree(): palm.remove_child(quick_actions)
|
|
|
|
|
|
|
|
func _physics_process(_delta):
|
2024-05-06 20:01:46 +03:00
|
|
|
if !hand_active: return
|
|
|
|
|
2024-05-06 19:22:12 +03:00
|
|
|
var distance_trigger = index_tip.global_position.distance_to(thumb_tip.global_position)
|
|
|
|
var distance_grab = middle_tip.global_position.distance_to(thumb_tip.global_position)
|
|
|
|
|
|
|
|
var trigger_close = distance_trigger <= press_distance
|
|
|
|
var grab_close = distance_grab <= grip_distance
|
|
|
|
|
|
|
|
if trigger_close&&!pressed:
|
2024-05-09 13:40:41 +03:00
|
|
|
pointer.pressed(Initiator.EventType.TRIGGER)
|
2024-05-06 19:22:12 +03:00
|
|
|
pressed = true
|
|
|
|
elif !trigger_close&&pressed:
|
2024-05-09 13:40:41 +03:00
|
|
|
pointer.released(Initiator.EventType.TRIGGER)
|
2024-05-06 19:22:12 +03:00
|
|
|
pressed = false
|
|
|
|
|
|
|
|
if grab_close&&!grabbed:
|
2024-05-09 13:40:41 +03:00
|
|
|
pointer.pressed(Initiator.EventType.GRIP)
|
2024-05-06 19:22:12 +03:00
|
|
|
grabbed = true
|
|
|
|
elif !grab_close&&grabbed:
|
2024-05-09 13:40:41 +03:00
|
|
|
pointer.released(Initiator.EventType.GRIP)
|
2024-05-06 19:22:12 +03:00
|
|
|
grabbed = false
|
|
|
|
|
|
|
|
func _setup_hand():
|
|
|
|
TouchManager.add_finger(Finger.Type.INDEX_LEFT, $IndexTip/TouchArea)
|
|
|
|
|
2024-05-12 18:29:56 +03:00
|
|
|
collide = Collide.new(hand, hand_mesh, index_tip.get_node("Marker3D"))
|
2024-05-06 19:22:12 +03:00
|
|
|
add_child(collide)
|
|
|
|
|
2024-05-06 20:01:46 +03:00
|
|
|
auto_hand.hand_active_changed.connect(func(hand: int, active: bool):
|
|
|
|
if hand != 0: return
|
|
|
|
|
|
|
|
hand_active=active
|
|
|
|
|
|
|
|
$IndexTip/TouchArea/CollisionShape3D.disabled=!active
|
|
|
|
hand_mesh.visible=active
|
|
|
|
)
|
|
|
|
|
2024-05-06 19:22:12 +03:00
|
|
|
mini_view_button.on_button_up.connect(func():
|
2024-05-22 19:38:28 +03:00
|
|
|
App.miniature.small.value=!App.miniature.small.value
|
2024-05-06 19:22:12 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
temperature_button.on_button_up.connect(func():
|
2024-05-22 19:38:28 +03:00
|
|
|
if App.miniature.heatmap_type.value == Miniature.HeatmapType.TEMPERATURE:
|
|
|
|
App.miniature.heatmap_type.value=Miniature.HeatmapType.NONE
|
2024-05-06 19:22:12 +03:00
|
|
|
else:
|
2024-05-22 19:38:28 +03:00
|
|
|
App.miniature.heatmap_type.value=Miniature.HeatmapType.TEMPERATURE
|
2024-05-06 19:22:12 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
humidity_button.on_button_up.connect(func():
|
2024-05-22 19:38:28 +03:00
|
|
|
if App.miniature.heatmap_type.value == Miniature.HeatmapType.HUMIDITY:
|
|
|
|
App.miniature.heatmap_type.value=Miniature.HeatmapType.NONE
|
2024-05-06 19:22:12 +03:00
|
|
|
else:
|
2024-05-22 19:38:28 +03:00
|
|
|
App.miniature.heatmap_type.value=Miniature.HeatmapType.HUMIDITY
|
2024-05-06 19:22:12 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
initiator.type = Initiator.Type.HAND_LEFT
|
|
|
|
initiator.node = self
|
|
|
|
|
|
|
|
pointer = Pointer.new(initiator, ray)
|
2024-05-23 01:36:49 +03:00
|
|
|
add_child(pointer)
|