#!/usr/bin/env python # -*- coding: utf-8 -*- """ 版权所有: 深圳时光科技有限公司 联系方式: q.100@qq.com 创建日期: 2024/04/01 """ import maya.cmds as cmds def sg_supplement_meshes(): """ 补充和变形各个LOD级别的网格 """ # 遍历8个LOD级别 for i in range(8): # 获取当前LOD级别的网格列表 lod_list = cmds.SGGetMeshes(lod=i) head = cmds.SGGetMeshes(m=lod_list[0]) deformed = cmds.SGGetMeshes(m=0) if cmds.objExists(head): # 准备源模型 source = cmds.SGGetMeshes(cm=0) source_buffer = f"{source}_buffer" source_buffer = source_buffer[1:] # 移除第一个字符 source_buffer = cmds.rename(source, source_buffer) # 设置进度条标题 title = f"[LOD{i}] Please be patient and wait..." if cmds.SGDescriptor(l=True) == "ZH": title = f"[LOD{i}] 请耐心等待..." # 初始化进度条 cmds.SGProgressBar(sp=True) cmds.SGProgressBar(t=title) # 初始化网格列表 eye_mesh = [] eye = [] mouth_mesh = [] # 读取顶点信息 json_file = cmds.SGDescriptor(ti="vertexsInfo") eye_indices = cmds.SGReadJson(f=json_file, k="headEye", t="int") mouth_indices = cmds.SGReadJson(f=json_file, k="headMouth", t="int") # 处理每个网格 for j in range(1, len(lod_list)): if lod_list[j] < 50: mesh = cmds.SGGetMeshes(m=lod_list[j]) if not cmds.objExists(mesh): new_mesh = cmds.SGGetMeshes(cm=lod_list[j]) if cmds.objExists(new_mesh): # 根据名称分类网格 if any(x in new_mesh for x in ["eyeshell", "eyelashes", "eyeEdge", "cartilage"]): eye_mesh.append(new_mesh) elif any(x in new_mesh for x in ["eyeLeft", "eyeRight"]): eye.append(new_mesh) elif any(x in new_mesh for x in ["teeth", "saliva"]): mouth_mesh.append(new_mesh) # 设置进度条 cmds.SGProgressBar(max=3) # 应用RBF变形器 cmds.SGProgressBar(apr=1) if eye_mesh: cmds.SGRBFDeformer( r=0.01, rbf=1, m=[source_buffer, deformed], pi=eye_indices, t=eye_mesh ) cmds.SGProgressBar(apr=1) if eye: cmds.SGRBFDeformer( r=0.01, rbf=1, d="off", m=[source_buffer, deformed], pi=eye_indices, t=eye ) cmds.SGProgressBar(apr=1) if mouth_mesh: cmds.SGRBFDeformer( r=0.01, rbf=1, d="off", m=[source_buffer, deformed], pi=mouth_indices, t=mouth_mesh ) # 清理和结束 cmds.delete(source_buffer) cmds.SGProgressBar(ep=True) # 如果直接运行此脚本 if __name__ == '__main__': sg_supplement_meshes()