关联文章,自动重命名刚体:https://blog.csdn.net/ONE_SIX_MIX/article/details/125002698
和刚体一样,但Joint点就更多了,要全部手动修改那心态可就炸裂了。
命名规则:
Joint对象名:Joint编号.joint.引用刚体名1->引用刚体名2<.引用编号>
mmd joint名:引用刚体名1->引用刚体名2<.引用编号>
其中,只有多个Joint点按相同顺序链接同样的两个刚体才会有<.引用编号>后缀,不然就没有这个后缀
命名示例:
注意,使用此脚本时,必须先显示 Joint点 对象,这个脚本只会对非隐藏的 Joint点 对象进行操作
import bpy
# rb1->rb2->joint
paired_joints = {}
name_to_rb = {}
for obj in bpy.context.visible_objects:
if obj.rigid_body_constraint is not None and \
hasattr(obj, 'mmd_joint') and obj.mmd_joint is not None and \
obj.rigid_body_constraint.object1 is not None and obj.rigid_body_constraint.object2 is not None:
rb1_name = obj.rigid_body_constraint.object1.name
rb2_name = obj.rigid_body_constraint.object2.name
name_to_rb[rb1_name] = obj.rigid_body_constraint.object1
name_to_rb[rb2_name] = obj.rigid_body_constraint.object2
paired_joints.setdefault(rb1_name, {})
paired_joints[rb1_name].setdefault(rb2_name, [])
paired_joints[rb1_name][rb2_name].append(obj)
idx = 0
for rb1_name in sorted(list(paired_joints.keys())):
for rb2_name in sorted(list(paired_joints[rb1_name].keys())):
is_append_joint_i = len(paired_joints[rb1_name][rb2_name]) > 1
for joint_i, joint in enumerate(paired_joints[rb1_name][rb2_name]):
old_obj_name = joint.name
old_joint_name = joint.mmd_joint.name_j
rb1_name_2 = name_to_rb[rb1_name].mmd_rigid.name_j
rb2_name_2 = name_to_rb[rb2_name].mmd_rigid.name_j
new_obj_name = f'{idx}.joint.{rb1_name_2}->{rb2_name_2}'
if is_append_joint_i:
new_obj_name += f'.{joint_i}'
joint.name = new_obj_name
new_joint_name = f'{rb1_name_2}->{rb2_name_2}'
if is_append_joint_i:
new_joint_name += f'.{joint_i}'
joint.mmd_joint.name_j = new_joint_name
print(f'rename {old_obj_name}->{new_obj_name} | {old_joint_name}->{new_joint_name}')
idx += 1
print('Success')