Skip to content

Commit

Permalink
ik test for index finger
Browse files Browse the repository at this point in the history
does not work yet due to bug in Godot: godotengine/godot#60180
  • Loading branch information
patrykkalinowski committed Apr 4, 2023
1 parent eab7a51 commit 1bb9ee1
Show file tree
Hide file tree
Showing 2 changed files with 383 additions and 30 deletions.
334 changes: 330 additions & 4 deletions addons/godot-xr-physical-movement-kit/scenes/Player.tscn

Large diffs are not rendered by default.

79 changes: 53 additions & 26 deletions addons/godot-xr-physical-movement-kit/scripts/Hand.gd
Original file line number Diff line number Diff line change
Expand Up @@ -179,38 +179,65 @@ func process_bones(bone_id, delta):

if bone_id == 0:
# wrist bone uses global override as we always need it to be exactly on Wrist RigidBody
physical_skeleton.set_bone_global_pose_override(bone_id, wrist.global_transform, 1.0, false)
# physical_skeleton.set_bone_global_pose_override(bone_id, wrist.global_transform, 1.0, false)
physical_skeleton.set_bone_pose_position(bone_id, wrist.global_transform.origin)
physical_skeleton.set_bone_pose_rotation(bone_id, Quaternion(wrist.global_transform.basis))
else:
physical_skeleton.set_bone_pose_position(bone_id, controller_skeleton.get_bone_pose_position(bone_id))
physical_skeleton.set_bone_pose_rotation(bone_id, controller_skeleton.get_bone_pose_rotation(bone_id))

# freezing fingers around grabbed objects
var bone_raycasts = physical_bone_collider.get_node("RayCasts").get_children()
# for every raycast in physical bone
for raycast in bone_raycasts:
# check if any of them is detecting collision
raycast.force_raycast_update()
if raycast.get_collider():
# if yes, we will freeze this bone and backward bones
# first, we check which finger this bone belongs to
var finger = finger_from_bone[bone_id]

# we iterate through every bone in this finger
for finger_bone in finger_bones[finger]:
# only process bones which are backwards from colliding bone (or the colliding bone itself)
if finger_bone <= bone_id:
# check if we already have frozen pose for this bone
if !freezed_poses.has(finger_bone):
# if not, save current bone pose to freezed poses
freezed_poses[finger_bone] = controller_skeleton.get_bone_global_pose(finger_bone)
# IK Skeleton
if bone_id == 9:
if physical_skeleton.get_node_or_null("BoneAttachment3D " + String.num_int64(bone_id)):
var skeletonik: SkeletonIK3D = physical_skeleton.get_node("SkeletonIK3D " + String.num_int64(bone_id))
var finger_tip_raycasts = physical_skeleton.get_node("BoneAttachment3D " + String.num_int64(bone_id)).get_children()
var target_ik_node = physical_skeleton.get_node_or_null("BoneAttachment 0/TargetIK " + String.num_int64(bone_id))
var apply_ik: bool = false

for raycast in finger_tip_raycasts:
raycast.force_raycast_update()
if raycast.get_collider():
apply_ik = true

# if player is grabbing, only then we freeze fingers on previously detected collision points
if state.grabbing:
# apply freezed pose to current bone
controller_skeleton.set_bone_global_pose_override(finger_bone, freezed_poses[finger_bone], 1.0, true)
skeletonik.set_target_transform(Transform3D(Basis.IDENTITY, raycast.get_collision_point()))
skeletonik.set_interpolation(0.5)
skeletonik.start()
break

# if !apply_ik:
# skeletonik.stop()

# if one raycast is detecting collision already, we don't need to check others
break




# freezing fingers around grabbed objects
# var bone_raycasts = physical_bone_collider.get_node("RayCasts").get_children()
# # for every raycast in physical bone
# for raycast in bone_raycasts:
# # check if any of them is detecting collision
# raycast.force_raycast_update()
# if raycast.get_collider():
# # if yes, we will freeze this bone and backward bones
# # first, we check which finger this bone belongs to
# var finger = finger_from_bone[bone_id]
#
# # we iterate through every bone in this finger
# for finger_bone in finger_bones[finger]:
# # only process bones which are backwards from colliding bone (or the colliding bone itself)
# if finger_bone <= bone_id:
# # check if we already have frozen pose for this bone
# if !freezed_poses.has(finger_bone):
# # if not, save current bone pose to freezed poses
# freezed_poses[finger_bone] = controller_skeleton.get_bone_global_pose(finger_bone)
#
# # if player is grabbing, only then we freeze fingers on previously detected collision points
# if state.grabbing:
# # apply freezed pose to current bone
# controller_skeleton.set_bone_global_pose_override(finger_bone, freezed_poses[finger_bone], 1.0, true)
#
# # if one raycast is detecting collision already, we don't need to check others
# break

func unfreeze_bones():
controller_skeleton.clear_bones_global_pose_override()
Expand Down

0 comments on commit 1bb9ee1

Please sign in to comment.