blender script mmd_tool 自动重命名刚体到合适的名字

关联文章,自动重命名Joint点:https://blog.csdn.net/ONE_SIX_MIX/article/details/125002920

改模的素材来自各个模型,手动改骨骼名还行,改刚体就要命了,实在太多了。

或许,未来有空的时候,单独弄个mmd_tool扩展工具来更加便于使用

写了个脚本来自动重命名刚体。

命名规则如下:
刚体对象名:刚体编号.rigid.引用骨骼名<.引用编号>
mmd刚体名:引用骨骼名<.引用编号>
其中,只有多个刚体同时引用同一个骨骼才会有<.引用编号>后缀,不然就没有这个后缀

命名示例:
在这里插入图片描述

注意,使用此脚本时,必须先显示刚体对象,这个脚本只会对非隐藏的刚体对象进行操作

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')

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值