Skip to content

Commit

Permalink
Refactor bone constraints setup and cleanup
Browse files Browse the repository at this point in the history
Aligned the rotation so the bone front is not the MODEL_TOP but is the MODEL_front.
  • Loading branch information
fire committed Nov 4, 2023
1 parent 1d96861 commit 08329ef
Showing 1 changed file with 77 additions and 71 deletions.
148 changes: 77 additions & 71 deletions sample/many_bone_ik_setup.gd
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ func _run():
var skeleton_profile: SkeletonProfileHumanoid = SkeletonProfileHumanoid.new()
many_bone_ik.reset_constraints()
for bone_name_i in skeleton.get_bone_count():
break
var bone_name = skeleton.get_bone_name(bone_name_i)
var swing_limit_cones = []
var bone_i = skeleton_profile.find_bone(bone_name)
Expand All @@ -86,88 +85,95 @@ func _run():
if bone_name == "Hips":
twist_from = deg_to_rad(0.0)
twist_range = deg_to_rad(360)
swing_limit_cones.append(LimitCone.new(Vector3.MODEL_REAR, deg_to_rad(3.0)))
swing_limit_cones.append(LimitCone.new(Vector3.MODEL_FRONT, deg_to_rad(3.0)))
resistance = 0.5
elif bone_name == "Spine":
twist_from = deg_to_rad(4.0)
twist_range = deg_to_rad(360)
swing_limit_cones.append(LimitCone.new(Vector3.MODEL_REAR, deg_to_rad(3.0)))
resistance = 0.5
#elif bone_name == "Chest":
#twist_from = deg_to_rad(5.0)
#twist_range = deg_to_rad(-10.0)
#swing_limit_cones.append(LimitCone.new(Vector3.MODEL_FRONT, deg_to_rad(3.0)))
#resistance = 0.5
#elif bone_name == "UpperChest":
#twist_from = deg_to_rad(10.0)
#twist_range = deg_to_rad(40.0)
#swing_limit_cones.append(LimitCone.new(Vector3.MODEL_FRONT, deg_to_rad(10.0)))
#resistance = 0.6
#elif bone_name == "Neck":
#twist_from = deg_to_rad(15.0)
#twist_range = deg_to_rad(15.0)
#swing_limit_cones.append(LimitCone.new(Vector3.MODEL_FRONT, deg_to_rad(10.0)))
#resistance = 0.6
#elif bone_name == "Head":
#twist_from = deg_to_rad(15.0)
#twist_range = deg_to_rad(15.0)
#swing_limit_cones.append(LimitCone.new(Vector3.MODEL_FRONT, deg_to_rad(15.0)))
#resistance = 0.7
#elif bone_name.ends_with("Eye"):
#pass
#elif bone_name == "LeftUpperLeg":
#twist_from = deg_to_rad(300.0)
#twist_range = deg_to_rad(10.0)
#swing_limit_cones.append(LimitCone.new(Vector3.MODEL_FRONT, deg_to_rad(25.0)))
#resistance = 0.8
#elif bone_name == "LeftLowerLeg":
#swing_limit_cones.append(LimitCone.new(Vector3.MODEL_FRONT, deg_to_rad(2.5)))
#swing_limit_cones.append(LimitCone.new(Vector3.MODEL_REAR, deg_to_rad(2.5)))
#swing_limit_cones.append(LimitCone.new(Vector3.MODEL_FRONT, deg_to_rad(2.5)))
#elif bone_name == "RightUpperLeg":
#twist_from = deg_to_rad(300.0)
#twist_range = deg_to_rad(10.0)
#swing_limit_cones.append(LimitCone.new(Vector3.MODEL_FRONT, deg_to_rad(25.0)))
#resistance = 0.8
#elif bone_name == "RightLowerLeg":
#swing_limit_cones.append(LimitCone.new(Vector3.MODEL_FRONT, deg_to_rad(2.5)))
#swing_limit_cones.append(LimitCone.new(Vector3.MODEL_REAR, deg_to_rad(2.5)))
#swing_limit_cones.append(LimitCone.new(Vector3.MODEL_REAR, deg_to_rad(2.5)))
#elif bone_name in ["LeftFoot", "RightFoot"]:
#swing_limit_cones.append(LimitCone.new(Vector3.MODEL_BOTTOM, deg_to_rad(5.0)))
#elif bone_name in ["LeftShoulder", "RightShoulder"]:
#swing_limit_cones.append(LimitCone.new(Vector3.MODEL_FRONT, deg_to_rad(30.0)))
#elif bone_name in ["LeftUpperArm", "RightUpperArm"]:
#twist_from = deg_to_rad(80.0)
#twist_range = deg_to_rad(12.0)
#swing_limit_cones.append(LimitCone.new(Vector3.MODEL_FRONT, deg_to_rad(90.0)))
#resistance = 0.3
#elif bone_name == "LeftLowerArm":
#twist_from = deg_to_rad(-55.0)
#twist_range = deg_to_rad(50.0)
#swing_limit_cones.append(LimitCone.new(Vector3.MODEL_FRONT, deg_to_rad(2.5)))
#swing_limit_cones.append(LimitCone.new(Vector3.MODEL_FRONT, deg_to_rad(2.5)))
#swing_limit_cones.append(LimitCone.new(Vector3.MODEL_REAR, deg_to_rad(2.5)))
#resistance = 0.4
#elif bone_name == "RightLowerArm":
#twist_from = deg_to_rad(-145.0)
#twist_range = deg_to_rad(50.0)
#swing_limit_cones.append(LimitCone.new(Vector3.MODEL_FRONT, deg_to_rad(2.5)))
#swing_limit_cones.append(LimitCone.new(Vector3.MODEL_FRONT, deg_to_rad(2.5)))
#swing_limit_cones.append(LimitCone.new(Vector3.MODEL_REAR, deg_to_rad(2.5)))
#resistance = 0.4
#elif bone_name in ["LeftHand", "RightHand"]:
#swing_limit_cones.append(LimitCone.new(Vector3.MODEL_FRONT, deg_to_rad(60.0)))
##elif bone_name in ["LeftThumb", "RightThumb"]:
##swing_limit_cones.append(LimitCone.new(y_up, deg_to_rad(90.0)))
elif bone_name == "Chest":
twist_from = deg_to_rad(5.0)
twist_range = deg_to_rad(-10.0)
swing_limit_cones.append(LimitCone.new(Vector3.MODEL_FRONT, deg_to_rad(3.0)))
resistance = 0.5
elif bone_name == "UpperChest":
twist_from = deg_to_rad(10.0)
twist_range = deg_to_rad(40.0)
swing_limit_cones.append(LimitCone.new(Vector3.MODEL_FRONT, deg_to_rad(10.0)))
resistance = 0.6
elif bone_name == "Neck":
twist_from = deg_to_rad(15.0)
twist_range = deg_to_rad(15.0)
swing_limit_cones.append(LimitCone.new(Vector3.MODEL_FRONT, deg_to_rad(10.0)))
resistance = 0.6
elif bone_name == "Head":
twist_from = deg_to_rad(15.0)
twist_range = deg_to_rad(15.0)
swing_limit_cones.append(LimitCone.new(Vector3.MODEL_FRONT, deg_to_rad(15.0)))
resistance = 0.7
elif bone_name.find("Eye") != -1:
continue
elif bone_name == "LeftUpperLeg":
twist_from = deg_to_rad(300.0)
twist_range = deg_to_rad(10.0)
swing_limit_cones.append(LimitCone.new(Vector3.MODEL_FRONT, deg_to_rad(25.0)))
resistance = 0.8
elif bone_name == "LeftLowerLeg":
swing_limit_cones.append(LimitCone.new(Vector3.MODEL_FRONT, deg_to_rad(2.5)))
swing_limit_cones.append(LimitCone.new(Vector3.MODEL_TOP, deg_to_rad(2.5)))
swing_limit_cones.append(LimitCone.new(Vector3.MODEL_REAR, deg_to_rad(2.5)))
elif bone_name == "RightUpperLeg":
twist_from = deg_to_rad(300.0)
twist_range = deg_to_rad(10.0)
swing_limit_cones.append(LimitCone.new(Vector3.MODEL_FRONT, deg_to_rad(25.0)))
resistance = 0.8
elif bone_name == "RightLowerLeg":
swing_limit_cones.append(LimitCone.new(Vector3.MODEL_FRONT, deg_to_rad(2.5)))
swing_limit_cones.append(LimitCone.new(Vector3.MODEL_TOP, deg_to_rad(2.5)))
swing_limit_cones.append(LimitCone.new(Vector3.MODEL_REAR, deg_to_rad(2.5)))
elif bone_name in ["LeftFoot", "RightFoot"]:
swing_limit_cones.append(LimitCone.new(Vector3.MODEL_REAR, deg_to_rad(5.0)))
elif bone_name in ["LeftShoulder", "RightShoulder"]:
swing_limit_cones.append(LimitCone.new(Vector3.MODEL_FRONT, deg_to_rad(30.0)))
elif bone_name in ["LeftUpperArm", "RightUpperArm"]:
twist_from = deg_to_rad(80.0)
twist_range = deg_to_rad(12.0)
swing_limit_cones.append(LimitCone.new(Vector3.MODEL_FRONT, deg_to_rad(90.0)))
resistance = 0.3
elif bone_name == "LeftLowerArm":
twist_from = deg_to_rad(-55.0)
twist_range = deg_to_rad(50.0)
swing_limit_cones.append(LimitCone.new(Vector3.MODEL_FRONT, deg_to_rad(2.5)))
swing_limit_cones.append(LimitCone.new(Vector3.MODEL_RIGHT, deg_to_rad(2.5)))
swing_limit_cones.append(LimitCone.new(Vector3.MODEL_REAR, deg_to_rad(2.5)))
resistance = 0.4
elif bone_name == "RightLowerArm":
twist_from = deg_to_rad(-145.0)
twist_range = deg_to_rad(50.0)
swing_limit_cones.append(LimitCone.new(Vector3.MODEL_FRONT, deg_to_rad(2.5)))
swing_limit_cones.append(LimitCone.new(Vector3.MODEL_FRONT, deg_to_rad(2.5)))
swing_limit_cones.append(LimitCone.new(Vector3.MODEL_REAR, deg_to_rad(2.5)))
resistance = 0.4
elif bone_name in ["LeftHand", "RightHand"]:
swing_limit_cones.append(LimitCone.new(Vector3.MODEL_FRONT, deg_to_rad(60.0)))
#elif bone_name in ["LeftThumb", "RightThumb"]:
#swing_limit_cones.append(LimitCone.new(y_up, deg_to_rad(90.0)))
else:
continue
set_bone_constraint(many_bone_ik, bone_name, twist_from, twist_range, swing_limit_cones, resistance)
var bones: Array = [
"Root",
"Chest",
"Head",
"LeftShoulder",
"LeftHand",
"RightShoulder",
"RightHand",
"LeftLowerLeg",
"LeftFoot",
"RightFoot"
"RightLowerLeg",
"RightFoot",
]

many_bone_ik.set_pin_count(0)
Expand All @@ -176,7 +182,7 @@ func _run():
var children: Array[Node] = root.find_children("*", "Marker3D")
for i in range(children.size()):
var node: Node = children[i] as Node
node.queue_free()
node.free()

for pin_i in range(bones.size()):
var bone_name: String = bones[pin_i]
Expand Down

0 comments on commit 08329ef

Please sign in to comment.