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

64 lines
1.6 KiB
Python
Raw Permalink 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
from scripts.utils.Core import GetMeshes, ProgressBar, MetaHumanNormals
def repair_normals(index):
"""
修复模型法线
参数:
index (int): 模型索引目前只支持0头部模型
"""
# 只处理头部模型
if index != 0:
return
# 获取顶点对应关系
vtxs = MetaHumanNormals()
# 获取头部和身体模型
head = GetMeshes(m=0)
body = GetMeshes(m=50)
# 计算需要处理的顶点对数量
count = len(vtxs) // 2
# 初始化进度条
ProgressBar(sp=True)
ProgressBar(max_value=count)
ProgressBar(t="Repair Normals...")
# 处理每对对应的顶点
for i in range(count):
# 更新进度条
ProgressBar(apr=1)
# 获取头部和身体对应的顶点索引
h = vtxs[i*2]
b = vtxs[i*2+1]
# 构建顶点名称
head_vtx = f"{head}.vtx[{h}]"
body_vtx = f"{body}.vtx[{b}]"
# 获取头部顶点的法线
pos = cmds.polyNormalPerVertex(head_vtx, q=True, xyz=True)
# 将法线应用到身体顶点
cmds.polyNormalPerVertex(body_vtx, xyz=(pos[0], pos[1], pos[2]))
# 结束进度条
ProgressBar(ep=True)
# 清除选择并选择身体模型
cmds.select(clear=True)
cmds.select(body, replace=True)
# 烘焙历史记录
cmds.BakeAllNonDefHistory()
# 如果直接运行此脚本
if __name__ == '__main__':
pass