#!/usr/bin/env python # -*- coding: utf-8 -*- import maya.cmds as cmds from Core import GetMeshes def copy_meshes(name): """ 复制网格体并组织到指定组中 参数: name (str): 组名称 """ # 获取所有需要处理的网格体 meshes = [GetMeshes(m=i) for i in range(9)] # 创建组 if not cmds.objExists(name): cmds.group(empty=True, name=name) if name != "defaults": cmds.setAttr(f"{name}.visibility", 0) # 复制每个网格体并放入组中 for mesh in meshes: if cmds.objExists(mesh): duplicate = f"{mesh}_{name}" cmds.duplicate(mesh, returnRootsOnly=True, name=duplicate) cmds.parent(duplicate, name) def merge_blend_shape(arkit_list): """ 合并混合变形目标 参数: arkit_list (list): ARKit表情目标列表 """ # 获取所有需要处理的网格体 meshes = [GetMeshes(m=i) for i in range(9)] # 处理每个网格体 for mesh in meshes: if cmds.objExists(mesh): # 清除选择并选择所有目标 cmds.select(clear=True) for target in arkit_list: duplicate = f"{mesh}_{target}" cmds.select(duplicate, add=True) # 选择默认形状 cmds.select(f"{mesh}_defaults", add=True) # 创建混合变形器 blend_shape = cmds.blendShape(automatic=True)[0] # 设置混合变形目标的别名 for i, target in enumerate(arkit_list): cmds.aliasAttr(target, f"{blend_shape}.w[{i}]") def go_to_build_pose(index): """ 设置指定索引的构建姿势 参数: index (int): 姿势索引 """ # 定义控制器设置字典 pose_settings = { 0: {"CTRL_L_eye_blink.translateY": 1}, 1: {"CTRL_L_eye_blink.translateY": 0, "CTRL_L_eye.translateY": -1}, 2: {"CTRL_L_eye.translateY": 0, "CTRL_L_eye.translateX": -1}, 3: {"CTRL_L_eye.translateX": 1}, 4: {"CTRL_L_eye.translateX": 0, "CTRL_L_eye.translateY": 1}, # ... 更多姿势设置 } # 如果存在该索引的设置,则应用设置 if index in pose_settings: for ctrl, value in pose_settings[index].items(): try: cmds.setAttr(ctrl, value) except: pass def go_to_build_face_pose(): """ 重置所有面部控制器到默认位置 """ # 定义需要重置的控制器列表 controls = [ "CTRL_C_jaw.translateY", "CTRL_C_jaw.translateX", "CTRL_R_eyelashes_tweakerOut.translateX", # ... 更多控制器 ] # 重置所有控制器 for ctrl in controls: try: cmds.setAttr(ctrl, 0) except: pass def create_arkit(): """ 创建ARKit表情系统 """ # ARKit表情目标列表 arkit_list = [ "eyeBlinkLeft", "eyeLookDownLeft", "eyeLookInLeft", "eyeLookOutLeft", "eyeLookUpLeft", "eyeSquintLeft", "eyeWideLeft", "eyeBlinkRight", "eyeLookDownRight", "eyeLookInRight", "eyeLookOutRight", "eyeLookUpRight", "eyeSquintRight", "eyeWideRight", "jawForward", "jawLeft", "jawRight", "jawOpen", "mouthClose", "mouthFunnel", "mouthPucker", "mouthLeft", "mouthRight", "mouthSmileLeft", "mouthSmileRight", "mouthFrownLeft", "mouthFrownRight", "mouthDimpleLeft", "mouthDimpleRight", "mouthStretchLeft", "mouthStretchRight", "mouthRollLower", "mouthRollUpper", "mouthShrugLower", "mouthShrugUpper", "mouthPressLeft", "mouthPressRight", "mouthLowerDownLeft", "mouthLowerDownRight", "mouthUpperUpLeft", "mouthUpperUpRight", "browDownLeft", "browDownRight", "browInnerUp", "browOuterUpLeft", "browOuterUpRight", "cheekPuff", "cheekSquintLeft", "cheekSquintRight", "noseSneerLeft", "noseSneerRight", "tongueOut" ] # 重置到构建姿势 go_to_build_face_pose() # 复制默认网格体 copy_meshes("defaults") # 创建每个表情目标 for i, target in enumerate(arkit_list): go_to_build_pose(i) copy_meshes(target) # 合并混合变形目标 merge_blend_shape(arkit_list) # 返回到构建姿势 go_to_build_face_pose() # 执行主函数 if __name__ == "__main__": create_arkit()