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

123 lines
3.9 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import maya.cmds as cmds
import maya.mel as mel
from Core import Descriptor
def define_joint_for_lod(lod):
"""
为指定LOD级别定义关节设置
参数:
lod (int): LOD级别
"""
# 重置所有控制器的位移属性
controllers = [
# 嘴部控制器
"CTRL_C_mouth", "CTRL_C_tongue_wideNarrow", "CTRL_C_jaw",
"CTRL_C_jaw_fwdBack", "CTRL_L_mouth_pushPullU", "CTRL_R_mouth_pushPullU",
"CTRL_L_mouth_pushPullD", "CTRL_R_mouth_pushPullD",
"CTRL_L_mouth_cornerPull", "CTRL_R_mouth_cornerPull",
"CTRL_L_mouth_cornerUD", "CTRL_R_mouth_cornerUD",
"CTRL_L_mouth_cornerFwdBack", "CTRL_R_mouth_cornerFwdBack",
"CTRL_L_mouth_lipRoll", "CTRL_R_mouth_lipRoll",
"CTRL_C_mouth_lipRollU", "CTRL_C_mouth_lipRollD",
# 舌头控制器
"CTRL_C_tongue_tip", "CTRL_C_tongue_middle", "CTRL_C_tongue_back",
"CTRL_C_tongue_curl", "CTRL_C_tongue_height",
# 眼睛控制器
"CTRL_L_eye", "CTRL_R_eye", "CTRL_C_eye",
"CTRL_L_eye_upperLid", "CTRL_R_eye_upperLid",
"CTRL_L_eye_lowerLid", "CTRL_R_eye_lowerLid",
# 眉毛控制器
"CTRL_L_brow_inner", "CTRL_R_brow_inner",
"CTRL_L_brow_middle", "CTRL_R_brow_middle",
"CTRL_L_brow_outer", "CTRL_R_brow_outer",
# 鼻子控制器
"CTRL_C_nose", "CTRL_C_nose_tip",
"CTRL_L_nose_nostril", "CTRL_R_nose_nostril",
# 脸颊控制器
"CTRL_L_cheek_raise", "CTRL_R_cheek_raise",
"CTRL_L_cheek_outer", "CTRL_R_cheek_outer",
# 下巴控制器
"CTRL_C_chin", "CTRL_C_chin_raise"
]
# 重置所有控制器的X轴和Y轴位移
for ctrl in controllers:
try:
cmds.setAttr(f"{ctrl}.translateX", 0)
cmds.setAttr(f"{ctrl}.translateY", 0)
except:
continue
# 清除选择
cmds.select(clear=True)
# 处理RL4节点
exists = False
rl4_nodes = cmds.ls(type="embeddedNodeRL4")
if rl4_nodes:
exists = True
cmds.delete(rl4_nodes)
# 修复LOD 0的关节
mel.eval('SGRepairJointForLOD 0')
# 如果存在RL4节点重新创建
if exists:
dna = Descriptor(wd=True)
if cmds.file(dna, query=True, exists=True):
name = f"rl4Embedded_{Descriptor(n=True)}_rl"
mel.eval(f'SGCreateRL4Node "{dna}" "{name}"')
# 处理蒙皮和关节
mel.eval('SGFastUnbindSkinCluster')
mel.eval(f'SGRepairJointForLOD {lod}')
mel.eval(f'SGDeleteJointForLOD {lod}')
mel.eval('SGFastBindSkinCluster')
def _get_control_list():
"""
获取需要重置的控制器列表
返回:
list: 控制器名称列表
"""
return [
# 嘴部控制器
"CTRL_C_mouth", "CTRL_C_tongue_wideNarrow", "CTRL_C_jaw",
"CTRL_L_mouth_pushPullU", "CTRL_R_mouth_pushPullU",
"CTRL_L_mouth_pushPullD", "CTRL_R_mouth_pushPullD",
# 眼睛控制器
"CTRL_L_eye", "CTRL_R_eye", "CTRL_C_eye",
"CTRL_L_eye_blink", "CTRL_R_eye_blink",
# 眉毛控制器
"CTRL_L_brow_raiseIn", "CTRL_R_brow_raiseIn",
"CTRL_L_brow_raiseOut", "CTRL_R_brow_raiseOut",
# 下巴控制器
"CTRL_C_jaw_fwdBack", "CTRL_C_jaw_openExtreme",
# 舌头控制器
"CTRL_C_tongue_move", "CTRL_C_tongue_bendTwist",
"CTRL_C_tongue_tipMove", "CTRL_C_tongue_inOut",
# 其他面部控制器
"CTRL_L_nose", "CTRL_R_nose",
"CTRL_L_mouth_corner", "CTRL_R_mouth_corner",
"CTRL_L_mouth_stretch", "CTRL_R_mouth_stretch",
# 系统控制器
"CTRL_lookAtSwitch", "CTRL_convergenceSwitch",
"CTRL_faceGUIfollowHead", "CTRL_eyesAimFollowHead"
]