#!/usr/bin/env python # -*- coding: utf-8 -*- import maya.cmds as cmds import maya.mel as mel def blend_shape_mirror_target(direction, axis, target_ids, blend_shape): """ 镜像混合变形目标 参数: direction (int): 镜像方向 axis (int): 镜像轴向 (1=X, 2=Y, 3=Z, 4=Topology) target_ids (list): 要镜像的目标ID列表 blend_shape (str): 混合变形节点名称 """ # 检查混合变形节点是否存在 if not cmds.objExists(blend_shape): cmds.warning(f"No Exists BlendShape: {blend_shape}") return # 获取当前对称建模设置 original_symmetry = cmds.symmetricModelling(query=True, symmetry=True) symmetry_space = None symmetry_axis = None if original_symmetry: symmetry_space = cmds.symmetricModelling(query=True, about=True) if symmetry_space == "topo": symmetry_axis = mel.eval('blendShapeGetTopoSymmetryEdge()') else: symmetry_axis = cmds.symmetricModelling(query=True, axis=True) # 获取几何体索引 geometry_indices = cmds.blendShape(blend_shape, query=True, geometryIndices=True) # 构建命令字符串 cmd_parts = [] # 为每个几何体构建镜像命令 for geometry in geometry_indices: cmd = f"blendShape -e " for target_id in target_ids: cmd += f"-mt {geometry} {target_id} " # 设置镜像方向 cmd += f"-md {direction} " # 设置对称选项 if axis == 4: cmd += "-ss 0 " else: cmd += "-ss 1 " if axis == 1: cmd += "-sa x " elif axis == 2: cmd += "-sa y " elif axis == 3: cmd += "-sa z " cmd += f"{blend_shape};" cmd_parts.append(cmd) # 添加对称设置恢复命令 if not original_symmetry or not symmetry_axis: cmd_parts.append('symmetricModelling -s 0') elif symmetry_space == "topo": cmd_parts.append(f'symmetricModelling -e -about {symmetry_space} -s 1 {symmetry_axis}') else: cmd_parts.append(f'symmetricModelling -e -about {symmetry_space} -axis {symmetry_axis} -s 1') # 执行命令 for cmd in cmd_parts: mel.eval(cmd)