MetaFusion/scripts/utils/RepairJointForLOD.py
2025-02-07 05:10:30 +08:00

43 lines
1.2 KiB
Python

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import maya.cmds as cmds
from scripts.utils.Core import GetJoints, GetNeutralJointTranslations
def repair_joint_for_lod(lod):
"""
修复指定LOD级别的关节
参数:
lod (int): LOD级别
"""
# 获取指定LOD级别的关节索引列表
joints = GetJoints(lod=lod, t="int")
# 遍历每个关节索引
for i, index in enumerate(joints):
# 获取关节名称
joint = GetJoints(i=index)
# 如果关节不存在,则创建并设置
if not cmds.objExists(joint):
# 创建新关节
cmds.joint(p=(0, 0, 0), name=joint)
# 获取并设置父关节
parent = GetJoints(p=index)
try:
cmds.parent(joint, parent)
except:
pass
# 获取并设置关节的中性位置
pos = GetNeutralJointTranslations(i=index)
# 设置平移和旋转
cmds.setAttr(f"{joint}.t", pos[0], pos[1], pos[2], type="float3")
cmds.setAttr(f"{joint}.jo", pos[3], pos[4], pos[5], type="float3")
# 如果直接运行此脚本
if __name__ == '__main__':
pass