def get_object_by_name(name, namespace=''):
component_list = pyfbsdk.FBComponentList()
pyfbsdk.FBFindObjectsByName(name, component_list, True, False)
pyfbsdk.FBFindObjectsByName(name, component_list, False, False)
component_list = set(component_list)
if namespace:
component_list = [i for i in component_list if (namespace + ':') in i.FullName]
return list(component_list)
def create_parent_constraint(name='constraint', source_list=[], target='', namespace=''):
constraint = pyfbsdk.FBConstraintManager().TypeCreateConstraint('Parent/Child')
constraint.Name = name
target_node = get_object_by_name(target, namespace=namespace)
if target_node:
constraint.ReferenceAdd(0, target_node[0])
for source in source_list:
for i in get_object_by_name(source, namespace=namespace):
constraint.ReferenceAdd(1, i)
constraint.Active = True
return constraint
def create_ik_constraint(namespace=''):
"""
创建基本的IK约束,如果有有不完整的则删除
Returns:
"""
ik_constraint_list = ['IK_Hd_2_HdSk_L', 'IK_Hd_2_HdSk_R',
'IK_Ft_2_FtSk_L', 'IK_Ft_2_FtSk_R',
'IK_Hd_2_gun']
_delete = False
for ik_constraint in ik_constraint_list:
if ik_constraint not in [i.Name for i in
pyfbsdk.FBSystem().Scene.Constraints]:
_delete = True
break
if _delete:
for ik_constraint in ik_constraint_list:
componentList = get_object_by_name(ik_constraint,
namespace=namespace)
for i in componentList:
if type(i) == pyfbsdk.FBConstraint:
pyfbsdk.FBComponent.FBDelete(i)
ik_constraint_list = [['IK_Hd_2_HdSk_L', 'hand_l', 'ik_hand_l'],
['IK_Hd_2_HdSk_R', 'hand_r', 'ik_hand_r'],
['IK_Ft_2_FtSk_L', 'foot_l', 'ik_foot_l'],
['IK_Ft_2_FtSk_R', 'foot_r', 'ik_foot_r'],
['IK_Hd_2_gun', 'hand_r', 'ik_hand_gun']]
for constraint_data in ik_constraint_list:
constraint_name, bone, ik_bone = constraint_data
create_parent_constraint(constraint_name, [bone], ik_bone, namespace)
create_ik_constraint()
发布日期:
2024-05-10
文章字数:
191
阅读时长:
1 分
评论