more fixes

This commit is contained in:
2026-08-04 11:13:09 +08:00
parent bb3bf11914
commit 4f1d76227e
25 changed files with 157 additions and 29 deletions
@@ -5,6 +5,7 @@ from . import ctrl_bones_shape_struct
from . import ctrl_bones_color_struct
from . import ik_bones_struct
from . import deform_bones_struct
from . import ctrl_ik_struct
# Modify Control Bone Shape Function
@@ -41,6 +42,9 @@ def addIK(bone_name, ik_target, ik_pole_target, ik_chain, armature):
pose_bone = armature.pose.bones.get(bone_name)
if pose_bone:
for constraint in list(pose_bone.constraints):
pose_bone.constraints.remove(constraint)
ik_constraint = pose_bone.constraints.new(type='IK')
ik_constraint.target = armature
ik_constraint.subtarget = ik_target
@@ -58,11 +62,30 @@ def addCopyScale(bone_name, parent_bone, parent_influence, armature):
pose_bone = armature.pose.bones.get(bone_name)
if pose_bone:
for constraint in list(pose_bone.constraints):
pose_bone.constraints.remove(constraint)
constraint = pose_bone.constraints.new(type='COPY_SCALE')
constraint.target = armature
constraint.subtarget = parent_bone
constraint.power = parent_influence
print(f"Successfully added Copy Scale constraint to {bone_name}")
constraint.influence = parent_influence
# print(f"Successfully added Copy Scale constraint to {bone_name}")
# Add IK Controller Function
def addIKcontroller(bone_name, ctrl_empt, armature):
pose_bone = armature.pose.bones.get(bone_name)
if pose_bone:
for constraint in list(pose_bone.constraints):
pose_bone.constraints.remove(constraint)
ik_ctrl_constraint = pose_bone.constraints.new(type='CHILD_OF')
ik_ctrl_constraint.target = armature
ik_ctrl_constraint.subtarget = ctrl_empt
print(f"Successfully added ChildOf constraint to {bone_name}")
# # Calculate and apply the inverse matrix so the object doesn't jump position
# ik_ctrl_constraint.inverse_matrix = ctrl_empt.matrix_world.inverted()
@@ -89,7 +112,7 @@ def generatecontrolrig():
shape_color = item["color"]
shape_width = float(item["width"])
print(f"Modifying Bone Shape for: {b_name}")
# print(f"Modifying Bone Shape for: {b_name}")
modifyctrlbone(b_name, rotation_x, rotation_y, rotation_z, shape_scale, shape_obj, shape_width, shape_color, new_amt_obj) # Call Modify Control Bone Shape Function
@@ -100,9 +123,19 @@ def generatecontrolrig():
b_name = item["bone_name"]
shape_color = item["color"]
print(f"Modifying Bone Color for: {b_name}")
# print(f"Modifying Bone Color for: {b_name}")
modifyctrlbonecolor(b_name, shape_color, new_amt_obj) # Call Modify Bone Function
# =========== Setup IK Controls ===========
IK_controls = ctrl_ik_struct.ctrl_ik_data
for item in IK_controls:
b_name = item["bone_name"]
ctrl_name = item["ctrl_controller"]
print(f"Adding Child constraint for bone: {b_name}")
addIKcontroller(b_name, ctrl_name, new_amt_obj) # Call Add IK Controller Function
# =========== Setup IK Bones ===========
IK_bones = ik_bones_struct.IK_bones_data
@@ -114,7 +147,7 @@ def generatecontrolrig():
ik_chain = int(item["chain"])
print(f"Adding IK constraint for bone: {b_name}")
# print(f"Adding IK constraint for bone: {b_name}")
addIK(b_name, ik_target, ik_pole_target, ik_chain, new_amt_obj) # Call Add IK Function
@@ -127,7 +160,7 @@ def generatecontrolrig():
parent_influence = float(item["influence"])
print(f"Adding copy scale constraint for bone: {b_name}")
# print(f"Adding copy scale constraint for bone: {b_name}")
addCopyScale(b_name, parent_bone, parent_influence, new_amt_obj) # Call Copy Scale constraints Function