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

43 lines
1.1 KiB
Python

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import maya.cmds as cmds
def sg_reset_target(target_ids, blend_shape):
"""
重置混合变形目标的点位置
Args:
target_ids (list): 目标索引列表
blend_shape (str): 混合变形器名称
"""
# 清除选择
cmds.select(clear=True)
# 处理每个目标
for target_id in target_ids:
# 重新生成目标
target = cmds.sculptTarget(
blend_shape,
edit=True,
regenerate=True,
target=target_id
)[0]
# 获取形状节点
shape = cmds.listRelatives(target, shapes=True)[0]
# 获取顶点数量
vertex_count = cmds.polyEvaluate(target, vertex=True)
# 重置所有点的位置为原点
for i in range(vertex_count):
cmds.setAttr(f"{shape}.pnts[{i}].pntx", 0)
cmds.setAttr(f"{shape}.pnts[{i}].pnty", 0)
cmds.setAttr(f"{shape}.pnts[{i}].pntz", 0)
# 删除临时目标
cmds.delete(target)
# 如果直接运行此脚本
if __name__ == '__main__':
pass