Skip to main content

lips_weight_rig

import pymel.core as pm


'''
# Define the parent and children variables
parent_a = 'FKJaw_M'
parent_b = 'FKHead_M'
# children = ['lip_top_R_00_jaw_offset_jnt_grp', 'lip_top_R_01_jaw_offset_jnt_grp', 'lip_top_R_02_jaw_offset_jnt_grp', 'lip_top_R_03_jaw_offset_jnt_grp', 'lip_top_R_04_jaw_offset_jnt_grp', 'lip_top_M_jaw_offset_jnt_grp']


children = ['lip_side_R_jaw_offset_jnt_grp', 'lip_bot_R_00_jaw_offset_jnt_grp', 'lip_bot_R_01_jaw_offset_jnt_grp', 'lip_bot_R_02_jaw_offset_jnt_grp', 'lip_bot_R_03_jaw_offset_jnt_grp', 'lip_bot_R_04_jaw_offset_jnt_grp', 'lip_bot_R_05_jaw_offset_jnt_grp', 'lip_bot_M_jnt_offset_grp']

# Initialize the initial weights
weight_a = 0.5
weight_b = 0.5

# Loop through each child
for i, child in enumerate(children):
# Create the parent constraint with maintain offset
constraint = pm.parentConstraint(parent_a, parent_b, child, maintainOffset=True)


# Clamp the weights to be within the range of 0 to 1
clamped_weight_a = min(max(weight_a, 0), 1)
clamped_weight_b = min(max(weight_b, 0), 1)

# Set the weights for the parent constraint
constraintWeightAttrA = constraint.getWeightAliasList()[0]
constraintWeightAttrB = constraint.getWeightAliasList()[1]

constraintWeightAttrA.set(clamped_weight_a)
constraintWeightAttrB.set(clamped_weight_b)

# Print the constraint and the weights (for debugging purposes)


print(f'Constraint: {constraint}, {constraintWeightAttrA}: {clamped_weight_a}, {constraintWeightAttrB}: {clamped_weight_b}')

# Update the weights for the next child
weight_a += 0.08
weight_b -= 0.08

print (weight_a, weight_b)
'''

def weighted_parent_child_constraint (parent_a, parent_b, initial_weight_a, initial_weight_b, increment, children_list):


weight_a = initial_weight_a
weight_b = initial_weight_b

for i, child in enumerate(children_list):
constraint = pm.parentConstraint(parent_a, parent_b, child, maintainOffset=True)


# Clamp the weights to be within the range of 0 to 1
clamped_weight_a = min(max(weight_a, 0), 1)
clamped_weight_b = min(max(weight_b, 0), 1)

# Set the weights for the parent constraint
constraintWeightAttrA = constraint.getWeightAliasList()[0]
constraintWeightAttrB = constraint.getWeightAliasList()[1]

constraintWeightAttrA.set(clamped_weight_a)
constraintWeightAttrB.set(clamped_weight_b)

# Print the constraint and the weights (for debugging purposes)


# print(f'Constraint: {constraint}, {constraintWeightAttrA}: {clamped_weight_a}, {constraintWeightAttrB}: {clamped_weight_b}')

# Update the weights for the next child
weight_a += increment
weight_b -= increment


parent_a = 'FKJaw_M'
parent_b = 'FKHead_M'
initial_weight_a = 0.5
initial_weight_b = 0.5
increment = 0.1
children_list = ['lip_side_R_jaw_offset_jnt_grp', 'lip_bot_R_00_jaw_offset_jnt_grp', 'lip_bot_R_01_jaw_offset_jnt_grp', 'lip_bot_R_02_jaw_offset_jnt_grp', 'lip_bot_R_03_jaw_offset_jnt_grp', 'lip_bot_R_04_jaw_offset_jnt_grp', 'lip_bot_R_05_jaw_offset_jnt_grp', 'lip_bot_M_jnt_offset_grp']


children_list = ['lip_side_R_jaw_offset_jnt_grp', 'lip_bot_R_00_jaw_offset_jnt_grp', 'lip_bot_R_01_jaw_offset_jnt_grp', 'lip_bot_R_02_jaw_offset_jnt_grp', 'lip_bot_R_03_jaw_offset_jnt_grp', 'lip_bot_R_04_jaw_offset_jnt_grp', 'lip_bot_R_05_jaw_offset_jnt_grp', 'lip_bot_M_jnt_offset_grp']


#weighted_parent_child_constraint(parent_a, parent_b, initial_weight_a, initial_weight_b, increment, children_list)

parent_a = 'FKJaw_M'
parent_b = 'FKHead_M'
initial_weight_a = 0.5
initial_weight_b = 0.5

children_list = ['lip_side_L_jaw_offset_jnt_grp', 'lip_bot_L_00_jaw_offset_jnt_grp', 'lip_bot_L_01_jaw_offset_jnt_grp', 'lip_bot_L_02_jaw_offset_jnt_grp', 'lip_bot_L_03_jaw_offset_jnt_grp', 'lip_bot_L_04_jaw_offset_jnt_grp', 'lip_bot_L_05_jaw_offset_jnt_grp']


#weighted_parent_child_constraint(parent_a, parent_b, initial_weight_a, initial_weight_b, increment, children_list)


parent_a = 'FKHead_M'
parent_b = 'FKJaw_M'
initial_weight_a = 0.5
initial_weight_b = 0.5
children_list = ['lip_top_R_00_jaw_offset_jnt_grp', 'lip_top_R_01_jaw_offset_jnt_grp', 'lip_top_R_02_jaw_offset_jnt_grp', 'lip_top_R_03_jaw_offset_jnt_grp', 'lip_top_R_04_jaw_offset_jnt_grp', 'lip_top_M_jnt_offset_grp']

#weighted_parent_child_constraint(parent_a, parent_b, initial_weight_a, initial_weight_b, increment, children_list)

parent_a = 'FKHead_M'
parent_b = 'FKJaw_M'
initial_weight_a = 0.5
initial_weight_b = 0.5
children_list = ['lip_top_L_00_jaw_offset_jnt_grp', 'lip_top_L_01_jaw_offset_jnt_grp', 'lip_top_L_02_jaw_offset_jnt_grp', 'lip_top_L_03_jaw_offset_jnt_grp', 'lip_top_L_04_jaw_offset_jnt_grp', 'lip_top_M_jnt_offset_grp']

#weighted_parent_child_constraint(parent_a, parent_b, initial_weight_a, initial_weight_b, increment, children_list)



def weighted_parent_child_constraint_MOD (parent_a, parent_b, initial_weight_a, initial_weight_b, increment, children_list):




# weight_a = initial_weight_a
# weight_b = initial_weight_b

for i, (child, weight) in enumerate(children_list):
constraint = pm.parentConstraint(parent_a, parent_b, child, maintainOffset=True)
constraint.interpType.set(2)


# Clamp the weights to be within the range of 0 to 1
# clamped_weight_a = min(max(weight_a, 0), 1)
# clamped_weight_b = min(max(weight_b, 0), 1)

# Set the weights for the parent constraint
constraintWeightAttrA = constraint.getWeightAliasList()[0]
constraintWeightAttrB = constraint.getWeightAliasList()[1]

weight_a = weight
weight_b = 1 - weight
constraintWeightAttrA.set(weight_a)
constraintWeightAttrB.set(weight_b)

# Print the constraint and the weights (for debugging purposes)


# print(f'Constraint: {constraint}, {constraintWeightAttrA}: {weight_a}, {constraintWeightAttrB}: {weight_b}')

# Update the weights for the next child
weight_a += increment
weight_b -= increment





parent_a = 'FKJaw_M'
parent_b = 'lip_side_R_con'
initial_weight_a = 0.5
initial_weight_b = 0.5
increment = 0.1
children_list = [
('lip_side_R_jaw_offset_jnt_grp', 0.5),
('lip_bot_R_00_jaw_offset_jnt_grp', 0.5),
('lip_bot_R_01_jaw_offset_jnt_grp', 0.7),
('lip_bot_R_02_jaw_offset_jnt_grp', 0.8),
('lip_bot_R_03_jaw_offset_jnt_grp', 0.88),
('lip_bot_R_04_jaw_offset_jnt_grp', 0.95),
('lip_bot_R_05_jaw_offset_jnt_grp', 1.0),
('lip_bot_M_jaw_offset_jnt_grp', 1.0),
]


weighted_parent_child_constraint_MOD (parent_a, parent_b, initial_weight_a, initial_weight_b, increment, children_list)


parent_a = 'FKJaw_M'
parent_b = 'lip_side_L_con'
initial_weight_a = 0.5
initial_weight_b = 0.5
increment = 0.1
children_list = [
('lip_side_L_jaw_offset_jnt_grp', 0.5),
('lip_bot_L_00_jaw_offset_jnt_grp', 0.5),
('lip_bot_L_01_jaw_offset_jnt_grp', 0.7),
('lip_bot_L_02_jaw_offset_jnt_grp', 0.8),
('lip_bot_L_03_jaw_offset_jnt_grp', 0.88),
('lip_bot_L_04_jaw_offset_jnt_grp', 0.95),
('lip_bot_L_05_jaw_offset_jnt_grp', 1.0),
]


weighted_parent_child_constraint_MOD (parent_a, parent_b, initial_weight_a, initial_weight_b, increment, children_list)


parent_a = 'lip_side_R_con'
parent_b = 'FKJaw_M'
initial_weight_a = 0.5
initial_weight_b = 0.5
increment = 0.1
children_list = [
('lip_top_R_00_jaw_offset_jnt_grp', 0.5),
('lip_top_R_01_jaw_offset_jnt_grp', 0.7),
('lip_top_R_02_jaw_offset_jnt_grp', 0.8),
('lip_top_R_03_jaw_offset_jnt_grp', 0.9),
('lip_top_R_04_jaw_offset_jnt_grp', 0.95),
('lip_top_M_jaw_offset_jnt_grp', 0.98),
]


weighted_parent_child_constraint_MOD (parent_a, parent_b, initial_weight_a, initial_weight_b, increment, children_list)

parent_a = 'lip_side_L_con'
parent_b = 'FKJaw_M'
initial_weight_a = 0.5
initial_weight_b = 0.5
increment = 0.1
children_list = [
('lip_top_L_00_jaw_offset_jnt_grp', 0.5),
('lip_top_L_01_jaw_offset_jnt_grp', 0.7),
('lip_top_L_02_jaw_offset_jnt_grp', 0.8),
('lip_top_L_03_jaw_offset_jnt_grp', 0.9),
('lip_top_L_04_jaw_offset_jnt_grp', 0.95),
]


weighted_parent_child_constraint_MOD (parent_a, parent_b, initial_weight_a, initial_weight_b, increment, children_list)


'''

# CONNECTION FOR SMILE AND FROWN

parent_a = 'lip_side_R_con'
parent_b = 'FKHead_M'
initial_weight_a = 0.5
initial_weight_b = 0.5
increment = 0.1
children_list = [
('lip_side_R_side_offset_jnt_grp', 1.0),
('lip_bot_R_00_side_offset_jnt_grp', 1.0),
('lip_bot_R_01_side_offset_jnt_grp', 0.8),
('lip_bot_R_02_side_offset_jnt_grp', 0.7),
('lip_bot_R_03_side_offset_jnt_grp', 0.5),
('lip_bot_R_04_side_offset_jnt_grp', 0.2),
('lip_bot_R_05_side_offset_jnt_grp', 0.05),
('lip_bot_M_side_offset_jnt_grp', 0.0),
]


weighted_parent_child_constraint_MOD (parent_a, parent_b, initial_weight_a, initial_weight_b, increment, children_list)


parent_a = 'lip_side_R_con'
parent_b = 'FKHead_M'
initial_weight_a = 0.5
initial_weight_b = 0.5
increment = 0.1


children_list = [
('lip_top_R_00_side_offset_jnt_grp', 1.0),
('lip_top_R_01_side_offset_jnt_grp', 0.7),
('lip_top_R_02_side_offset_jnt_grp', 0.5),
('lip_top_R_03_side_offset_jnt_grp', 0.25),
('lip_top_R_04_side_offset_jnt_grp', 0.05),
('lip_top_M_side_offset_jnt_grp', 0.0),
]

weighted_parent_child_constraint_MOD (parent_a, parent_b, initial_weight_a, initial_weight_b, increment, children_list)

parent_a = 'lip_side_L_con'
parent_b = 'FKHead_M'
initial_weight_a = 0.5
initial_weight_b = 0.5
increment = 0.1
children_list = [
('lip_side_L_side_offset_jnt_grp', 1.0),
('lip_bot_L_00_side_offset_jnt_grp', 1.0),
('lip_bot_L_01_side_offset_jnt_grp', 0.8),
('lip_bot_L_02_side_offset_jnt_grp', 0.7),
('lip_bot_L_03_side_offset_jnt_grp', 0.5),
('lip_bot_L_04_side_offset_jnt_grp', 0.2),
('lip_bot_L_05_side_offset_jnt_grp', 0.05),
]


weighted_parent_child_constraint_MOD (parent_a, parent_b, initial_weight_a, initial_weight_b, increment, children_list)


parent_a = 'lip_side_L_con'
parent_b = 'FKHead_M'
initial_weight_a = 0.5
initial_weight_b = 0.5
increment = 0.1


children_list = [
('lip_top_L_00_side_offset_jnt_grp', 1.0),
('lip_top_L_01_side_offset_jnt_grp', 0.7),
('lip_top_L_02_side_offset_jnt_grp', 0.5),
('lip_top_L_03_side_offset_jnt_grp', 0.25),
('lip_top_L_04_side_offset_jnt_grp', 0.05),
]

weighted_parent_child_constraint_MOD (parent_a, parent_b, initial_weight_a, initial_weight_b, increment, children_list)
'''