90 lines
2.8 KiB
Python
90 lines
2.8 KiB
Python
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import maya.cmds as cmds
|
|
from scripts.utils.Core import GetMeshes, Descriptor, SetMeshes
|
|
|
|
def meshes_list():
|
|
"""
|
|
获取网格列表
|
|
|
|
返回:
|
|
list: 网格名称列表
|
|
"""
|
|
meshes = []
|
|
edition = Descriptor(ed=True)
|
|
|
|
if edition >= 2:
|
|
# 获取LOD0的网格索引
|
|
mesh_indices = GetMeshes(lod=0)
|
|
for index in mesh_indices:
|
|
meshes.append(GetMeshes(i=index))
|
|
else:
|
|
# 获取所有网格
|
|
meshes = GetMeshes()
|
|
|
|
return meshes
|
|
|
|
def set_mesh_line_edit(index, mesh):
|
|
"""
|
|
设置网格选项变量
|
|
|
|
参数:
|
|
index (int): 网格索引
|
|
mesh (str): 网格名称
|
|
"""
|
|
meshes = GetMeshes()
|
|
|
|
if mesh:
|
|
# 设置选项变量
|
|
cmds.optionVar(stringValue=[meshes[index], mesh])
|
|
else:
|
|
# 移除选项变量
|
|
cmds.optionVar(remove=meshes[index])
|
|
|
|
def refresh_geo_line_edit():
|
|
"""刷新几何体行编辑器"""
|
|
meshes = meshes_list()
|
|
|
|
for i, mesh_name in enumerate(meshes):
|
|
if cmds.optionVar(exists=mesh_name):
|
|
# 如果存在选项变量
|
|
mesh = cmds.optionVar(query=mesh_name)
|
|
if cmds.objExists(mesh):
|
|
# 如果对象存在,设置网格
|
|
if mesh_name == "body_lod0_mesh":
|
|
SetMeshes(m=50, value=mesh)
|
|
else:
|
|
SetMeshes(m=i, value=mesh)
|
|
else:
|
|
# 如果对象不存在,尝试通过名称模式查找
|
|
selection = cmds.ls(f"*{mesh_name}*", type="transform")
|
|
if selection:
|
|
for sel in selection:
|
|
if cmds.objectType(sel) == "transform":
|
|
if mesh_name == "body_lod0_mesh":
|
|
SetMeshes(m=50, value=sel)
|
|
else:
|
|
SetMeshes(m=i, value=sel)
|
|
break
|
|
else:
|
|
# 如果找不到匹配的对象,清除设置
|
|
SetMeshes(m=i, value="")
|
|
else:
|
|
# 如果不存在选项变量,尝试通过名称模式查找
|
|
selection = cmds.ls(f"*{mesh_name}*", type="transform")
|
|
if selection:
|
|
for sel in selection:
|
|
if cmds.objectType(sel) == "transform":
|
|
if mesh_name == "body_lod0_mesh":
|
|
SetMeshes(m=50, value=sel)
|
|
else:
|
|
SetMeshes(m=i, value=sel)
|
|
break
|
|
else:
|
|
# 如果找不到匹配的对象,清除设置
|
|
SetMeshes(m=i, value="")
|
|
|
|
# 如果直接运行此脚本
|
|
if __name__ == '__main__':
|
|
pass |