#!/usr/bin/env python # -*- coding: utf-8 -*- """ 版权所有: 深圳时光科技有限公司 联系方式: q.100@qq.com 创建日期: 2024/03/01 """ import maya.cmds as cmds def sg_meta_human_normals(): """ 返回MetaHuman模型的法线顶点对应关系 Returns: list: 顶点索引列表,每两个值为一组,分别对应头部和身体的顶点 """ return [ 2805,9, 2806,8, 2807,7, 2808,10, 2809,6, 2810,5, 2811,2, 2812,1, 2813,0, 2814,4, 2815,12, 2816,14, 2817,15, 2818,16, 2819,17, 2820,18, 2821,19, 2822,20, 2823,21, 2824,11, 2873,22, 2876,23, 2965,3, 2997,13, 5876,3818, 5877,30, 5878,31, 5879,32, 5880,29, 5881,28, 5882,26, 5883,24, 5884,25, 5885,27, 5886,34, 5887,35, 5888,36, 5889,37, 5890,38, 5891,39, 5892,40, 5893,41, 5894,42, 5895,33, 5944,43, 5947,44, 11560,16789, 11564,16786, 11567,16795, 11569,16794, 11572,16784, 11575,7645, 11578,22814, 11582,16779, 11585,22833, 11587,22824, 11600,22801, 11795,21578, 11798,21577, 11799,21575, 11802,21573, 11803,21571, 11805,21569, 11807,21566, 11809,21564, 11811,21540, 11899,16775, 11909,16774, 11910,21542, 17607,9206, 17610,9203, 17614,9211, 17617,9207, 17619,9198, 17622,15227, 17626,15170, 17629,9195, 17632,15189, 17635,15180, 17647,15158, 17854,13968, 17856,13966, 17859,13964, 17860,13962, 17863,13960, 17865,13958, 17867,13957, 17869,13955, 17871,13927, 17962,9192, 17968,9186, 17972,13931 ] def sg_repair_normals(index): """ 修复模型法线 Args: index (int): 模型索引,目前只支持0(头部模型) """ # 只处理头部模型 if index != 0: return # 获取顶点对应关系 vtxs = sg_meta_human_normals() # 获取头部和身体模型 head = cmds.SGGetMeshes(m=0) body = cmds.SGGetMeshes(m=50) # 计算需要处理的顶点对数量 count = len(vtxs) // 2 # 初始化进度条 cmds.SGProgressBar(sp=True) cmds.SGProgressBar(max=count) cmds.SGProgressBar(t="Repair Normals...") # 处理每对对应的顶点 for i in range(count): # 更新进度条 cmds.SGProgressBar(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])) # 结束进度条 cmds.SGProgressBar(ep=True) # 清除选择并选择身体模型 cmds.select(clear=True) cmds.select(body, replace=True) # 烘焙历史记录 cmds.BakeAllNonDefHistory() # 如果直接运行此脚本 if __name__ == '__main__': pass