disable hands when not used
This commit is contained in:
parent
812b82d234
commit
933210bbc9
|
@ -8,6 +8,8 @@ extends Node3D
|
|||
@export var visiblehandtrackskeleton: bool = true
|
||||
@export var enableautotracker: bool = true
|
||||
|
||||
signal hand_active_changed(hand: int, active: bool)
|
||||
|
||||
# Hand tracking data access object
|
||||
var xr_interface: OpenXRInterface
|
||||
|
||||
|
@ -22,7 +24,6 @@ var xr_aimpose : XRPose = null
|
|||
var xr_headtracker: XRPositionalTracker = null
|
||||
var xr_camera_node: XRCamera3D = null
|
||||
|
||||
|
||||
# Note the that the enumerations disagree
|
||||
# XRPositionalTracker.TrackerHand.TRACKER_HAND_LEFT = 1
|
||||
# OpenXRInterface.Hand.HAND_LEFT = 0
|
||||
|
@ -34,7 +35,6 @@ var handnode = null
|
|||
var skel = null
|
||||
var handanimationtree = null
|
||||
|
||||
|
||||
# values calculated from the hand skeleton itself
|
||||
var handtoskeltransform
|
||||
var wristboneindex
|
||||
|
@ -62,7 +62,6 @@ static func rotationtoalignScaled(a, b):
|
|||
return Basis(axis, angle_rads).scaled(Vector3(sca, sca, sca))
|
||||
return Basis().scaled(Vector3(sca, sca, sca))
|
||||
|
||||
|
||||
func extractrestfingerbones():
|
||||
print(handnode.name)
|
||||
var lr = "L" if hand == 0 else "R"
|
||||
|
@ -88,7 +87,6 @@ func _xr_controller_node_tracking_changed(tracking):
|
|||
var xr_pose = xr_controller_node.get_pose()
|
||||
print("_xr_controller_node_tracking_changed ", xr_pose.name if xr_pose else "<none>")
|
||||
|
||||
|
||||
func findxrnodes():
|
||||
# first go up the tree to find the controller and origin
|
||||
var nd = self
|
||||
|
@ -160,7 +158,6 @@ func findxrtrackerobjects():
|
|||
print("action_sets: ", xr_interface.get_action_sets())
|
||||
$AutoTracker.setupautotracker(tracker_nhand, islefthand, xr_controller_node)
|
||||
|
||||
|
||||
func _ready():
|
||||
findxrnodes()
|
||||
findxrtrackerobjects()
|
||||
|
@ -174,7 +171,6 @@ func _ready():
|
|||
findhandnodes()
|
||||
set_process(xr_interface != null)
|
||||
|
||||
|
||||
func getoxrjointpositions():
|
||||
var oxrjps = [ ]
|
||||
for j in range(OpenXRInterface.HAND_JOINT_MAX):
|
||||
|
@ -258,7 +254,6 @@ func copyouttransformstoskel(fingerbonetransformsOut):
|
|||
skel.set_bone_pose_position(ix, t.origin)
|
||||
skel.set_bone_pose_scale(ix, t.basis.get_scale())
|
||||
|
||||
|
||||
func _process(delta):
|
||||
var handjointflagswrist = xr_interface.get_hand_joint_flags(hand, OpenXRInterface.HAND_JOINT_WRIST);
|
||||
var lhandtrackingactive = (handjointflagswrist&OpenXRInterface.HAND_JOINT_POSITION_VALID) != 0
|
||||
|
@ -269,6 +264,7 @@ func _process(delta):
|
|||
if handanimationtree:
|
||||
handanimationtree.active = not handtrackingactive
|
||||
print("setting hand " + str(hand) + " active: ", handtrackingactive)
|
||||
hand_active_changed.emit(hand, handtrackingactive)
|
||||
$VisibleHandTrackSkeleton.visible = visiblehandtrackskeleton and handtrackingactive
|
||||
if handtrackingactive:
|
||||
if enableautotracker:
|
||||
|
@ -297,6 +293,3 @@ func _process(delta):
|
|||
print("...xr_aimpose ", xr_aimpose)
|
||||
if xr_aimpose != null and $AutoTracker.autotrackeractive:
|
||||
$AutoTracker.xr_autotracker.set_pose(xr_controller_node.pose, xr_aimpose.transform, xr_aimpose.linear_velocity, xr_aimpose.angular_velocity, xr_aimpose.tracking_confidence)
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -42,6 +42,9 @@ transform = Transform3D(0.967043, 0.24582, -0.0663439, -0.0663439, 0.494837, 0.8
|
|||
[node name="MiddleTip" parent="XROrigin3D/XRControllerLeft" index="8"]
|
||||
transform = Transform3D(0.98042, 0.196912, 0.00149799, 0.001498, -0.015065, 0.999885, 0.196912, -0.980305, -0.0150651, -0.00327212, -0.00771427, -0.176318)
|
||||
|
||||
[node name="Palm" parent="XROrigin3D/XRControllerLeft" index="9"]
|
||||
transform = Transform3D(1, 3.12361e-06, -3.13859e-06, -3.12371e-06, 1, -1.97886e-05, 3.13859e-06, 1.97889e-05, 1, 0.0307807, -0.0419722, -0.0399505)
|
||||
|
||||
[node name="XRControllerRight" parent="XROrigin3D" instance=ExtResource("7_0b3tc")]
|
||||
transform = Transform3D(0.999999, -1.39635e-11, 0, 1.31553e-10, 1, 0, 0, 0, 1, 0.336726, 0.575093, -0.437942)
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ const Miniature = preload ("res://content/system/house/mini/miniature.gd")
|
|||
@onready var main = $"/root/Main"
|
||||
@onready var hand = $hand_l
|
||||
@onready var hand_mesh = $hand_l/Armature/Skeleton3D/mesh_Hand_L
|
||||
@onready var auto_hand = $AutoHandtracker
|
||||
|
||||
@onready var index_tip = $IndexTip
|
||||
@onready var thumb_tip = $ThumbTip
|
||||
|
@ -27,6 +28,7 @@ const Miniature = preload ("res://content/system/house/mini/miniature.gd")
|
|||
@onready var animation = $AnimationPlayer
|
||||
@onready var quick_actions = $Palm/QuickActions
|
||||
|
||||
var hand_active = false
|
||||
var initiator: Initiator = Initiator.new()
|
||||
var collide: Collide
|
||||
var pointer: Pointer
|
||||
|
@ -103,12 +105,18 @@ func _ready():
|
|||
)
|
||||
|
||||
func _process(_delta):
|
||||
if !hand_active:
|
||||
if quick_actions.is_inside_tree(): palm.remove_child(quick_actions)
|
||||
return
|
||||
|
||||
if main.camera.global_transform.basis.z.dot(palm.global_transform.basis.x) > 0.85:
|
||||
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):
|
||||
if !hand_active: return
|
||||
|
||||
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)
|
||||
|
||||
|
@ -144,6 +152,15 @@ func _setup_hand():
|
|||
collide = Collide.new(hand, hand_mesh, index_tip)
|
||||
add_child(collide)
|
||||
|
||||
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
|
||||
)
|
||||
|
||||
mini_view_button.on_button_up.connect(func():
|
||||
House.body.mini_view.small.value=!House.body.mini_view.small.value
|
||||
)
|
||||
|
|
|
@ -11,11 +11,13 @@ const Miniature = preload ("res://content/system/house/mini/miniature.gd")
|
|||
@onready var ray: RayCast3D = $Raycast
|
||||
@onready var hand: Node3D = $hand_r
|
||||
@onready var hand_mesh = $hand_r/Armature/Skeleton3D/mesh_Hand_R
|
||||
@onready var auto_hand = $AutoHandtracker
|
||||
|
||||
@onready var index_tip = $IndexTip
|
||||
@onready var thumb_tip = $ThumbTip
|
||||
@onready var middle_tip = $MiddleTip
|
||||
|
||||
var hand_active = false
|
||||
var initiator: Initiator = Initiator.new()
|
||||
var collide: Collide
|
||||
var pointer: Pointer
|
||||
|
@ -37,7 +39,18 @@ func _ready():
|
|||
pointer = Pointer.new(initiator, ray)
|
||||
add_child(pointer)
|
||||
|
||||
auto_hand.hand_active_changed.connect(func(hand: int, active: bool):
|
||||
if hand != 1: return
|
||||
|
||||
hand_active=active
|
||||
|
||||
$IndexTip/TouchArea/CollisionShape3D.disabled=!active
|
||||
hand_mesh.visible=active
|
||||
)
|
||||
|
||||
func _physics_process(_delta):
|
||||
if !hand_active: return
|
||||
|
||||
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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user