Update utils_geometry.py
This commit is contained in:
@@ -47,338 +47,44 @@ from scripts.ui import localization
|
||||
TEXT = localization.TEXT
|
||||
#========================================== FUNCTIONS ========================================
|
||||
|
||||
# 左侧面板功能
|
||||
# LOD相关功能
|
||||
def lod_selected(item):
|
||||
"""
|
||||
LOD项目被选中
|
||||
"""
|
||||
print(f"LOD项目被选中: {item.text()}")
|
||||
# 这里实现LOD项目选中的功能
|
||||
return True
|
||||
|
||||
def update_lod_selection():
|
||||
"""
|
||||
更新LOD选择
|
||||
"""
|
||||
print("更新LOD选择")
|
||||
# 这里实现更新LOD选择的功能
|
||||
return True
|
||||
|
||||
def add_lod():
|
||||
"""
|
||||
添加LOD
|
||||
"""
|
||||
print("添加LOD")
|
||||
# 这里实现添加LOD的功能
|
||||
return True
|
||||
|
||||
def remove_lod():
|
||||
"""
|
||||
移除LOD
|
||||
"""
|
||||
print("移除LOD")
|
||||
# 这里实现移除LOD的功能
|
||||
return True
|
||||
|
||||
def duplicate_lod():
|
||||
"""
|
||||
复制LOD
|
||||
"""
|
||||
print("复制LOD")
|
||||
# 这里实现复制LOD的功能
|
||||
return True
|
||||
|
||||
# 模型相关功能
|
||||
def model_selected(item):
|
||||
"""
|
||||
模型项目被选中
|
||||
"""
|
||||
print(f"模型项目被选中: {item.text()}")
|
||||
# 这里实现模型项目选中的功能
|
||||
return True
|
||||
|
||||
def update_model_selection():
|
||||
"""
|
||||
更新模型选择
|
||||
"""
|
||||
print("更新模型选择")
|
||||
# 这里实现更新模型选择的功能
|
||||
return True
|
||||
|
||||
def add_model():
|
||||
"""
|
||||
添加模型
|
||||
"""
|
||||
print("添加模型")
|
||||
# 这里实现添加模型的功能
|
||||
return True
|
||||
|
||||
def remove_model():
|
||||
"""
|
||||
移除模型
|
||||
"""
|
||||
print("移除模型")
|
||||
# 这里实现移除模型的功能
|
||||
return True
|
||||
|
||||
def duplicate_model():
|
||||
"""
|
||||
复制模型
|
||||
"""
|
||||
print("复制模型")
|
||||
# 这里实现复制模型的功能
|
||||
return True
|
||||
|
||||
# 右侧面板功能
|
||||
# 模型属性相关功能
|
||||
def update_model_name(text):
|
||||
"""
|
||||
更新模型名称
|
||||
"""
|
||||
print(f"更新模型名称: {text}")
|
||||
# 这里实现更新模型名称的功能
|
||||
return True
|
||||
|
||||
def update_model_type(index):
|
||||
"""
|
||||
更新模型类型
|
||||
"""
|
||||
print(f"更新模型类型: {index}")
|
||||
# 这里实现更新模型类型的功能
|
||||
return True
|
||||
|
||||
def toggle_model_visibility(state):
|
||||
"""
|
||||
切换模型可见性
|
||||
"""
|
||||
print(f"切换模型可见性: {state}")
|
||||
# 这里实现切换模型可见性的功能
|
||||
return True
|
||||
|
||||
def apply_properties():
|
||||
"""
|
||||
应用属性
|
||||
"""
|
||||
print("应用属性")
|
||||
# 这里实现应用属性的功能
|
||||
return True
|
||||
|
||||
def reset_properties():
|
||||
"""
|
||||
重置属性
|
||||
"""
|
||||
print("重置属性")
|
||||
# 这里实现重置属性的功能
|
||||
return True
|
||||
|
||||
# 模型工具相关功能
|
||||
def standardize_names():
|
||||
"""
|
||||
标准化命名
|
||||
"""
|
||||
print("标准化命名")
|
||||
# 这里实现标准化命名的功能
|
||||
return True
|
||||
|
||||
def auto_group():
|
||||
"""
|
||||
自动分组
|
||||
"""
|
||||
print("自动分组")
|
||||
# 这里实现自动分组的功能
|
||||
return True
|
||||
|
||||
def generate_accessories():
|
||||
"""
|
||||
生成配件
|
||||
"""
|
||||
print("生成配件")
|
||||
# 这里实现生成配件的功能
|
||||
return True
|
||||
|
||||
def fix_seams():
|
||||
"""
|
||||
修复接缝
|
||||
"""
|
||||
print("修复接缝")
|
||||
# 这里实现修复接缝的功能
|
||||
return True
|
||||
|
||||
def fix_vertex_order():
|
||||
"""
|
||||
修复点序
|
||||
"""
|
||||
print("修复点序")
|
||||
# 这里实现修复点序的功能
|
||||
return True
|
||||
|
||||
# 底部工具面板功能
|
||||
# 导入相关功能
|
||||
def import_model():
|
||||
"""
|
||||
导入模型
|
||||
"""
|
||||
print("导入模型")
|
||||
try:
|
||||
file_path = cmds.fileDialog2(
|
||||
fileFilter="Maya Files (*.ma *.mb);;All Files (*.*)",
|
||||
dialogStyle=2,
|
||||
fileMode=1
|
||||
)
|
||||
if file_path:
|
||||
# 这里实现导入模型的功能
|
||||
print(f"将从{file_path[0]}导入模型")
|
||||
except Exception as e:
|
||||
print(f"导入模型时出错: {e}")
|
||||
return True
|
||||
|
||||
def import_fbx():
|
||||
"""
|
||||
导入FBX
|
||||
"""
|
||||
print("导入FBX")
|
||||
try:
|
||||
file_path = cmds.fileDialog2(
|
||||
fileFilter="FBX Files (*.fbx);;All Files (*.*)",
|
||||
dialogStyle=2,
|
||||
fileMode=1
|
||||
)
|
||||
if file_path:
|
||||
# 这里实现导入FBX的功能
|
||||
print(f"将从{file_path[0]}导入FBX")
|
||||
mel.eval(f'FBXImport -file "{file_path[0]}";')
|
||||
except Exception as e:
|
||||
print(f"导入FBX时出错: {e}")
|
||||
return True
|
||||
|
||||
def import_obj():
|
||||
"""
|
||||
导入OBJ
|
||||
"""
|
||||
print("导入OBJ")
|
||||
try:
|
||||
file_path = cmds.fileDialog2(
|
||||
fileFilter="OBJ Files (*.obj);;All Files (*.*)",
|
||||
dialogStyle=2,
|
||||
fileMode=1
|
||||
)
|
||||
if file_path:
|
||||
# 这里实现导入OBJ的功能
|
||||
print(f"将从{file_path[0]}导入OBJ")
|
||||
cmds.file(file_path[0], i=True, type="OBJ", ignoreVersion=True, options="mo=1")
|
||||
except Exception as e:
|
||||
print(f"导入OBJ时出错: {e}")
|
||||
return True
|
||||
|
||||
# 导出相关功能
|
||||
def export_model():
|
||||
"""
|
||||
导出模型
|
||||
"""
|
||||
print("导出模型")
|
||||
try:
|
||||
file_path = cmds.fileDialog2(
|
||||
fileFilter="Maya Files (*.ma *.mb);;All Files (*.*)",
|
||||
dialogStyle=2,
|
||||
fileMode=2
|
||||
)
|
||||
if file_path:
|
||||
# 这里实现导出模型的功能
|
||||
print(f"将模型导出到{file_path[0]}")
|
||||
except Exception as e:
|
||||
print(f"导出模型时出错: {e}")
|
||||
return True
|
||||
|
||||
def export_fbx():
|
||||
"""
|
||||
导出 FBX
|
||||
"""
|
||||
print("导出 FBX")
|
||||
try:
|
||||
file_path = cmds.fileDialog2(
|
||||
fileFilter="FBX Files (*.fbx);;All Files (*.*)",
|
||||
dialogStyle=2,
|
||||
fileMode=2
|
||||
)
|
||||
if file_path:
|
||||
# 这里实现导出 FBX的功能
|
||||
print(f"将模型导出到{file_path[0]}")
|
||||
mel.eval('FBXExportSmoothingGroups -v true;')
|
||||
mel.eval('FBXExportHardEdges -v false;')
|
||||
mel.eval('FBXExportTangents -v false;')
|
||||
mel.eval('FBXExportSmoothMesh -v true;')
|
||||
mel.eval('FBXExportInstances -v false;')
|
||||
mel.eval('FBXExportReferencedContainersContent -v false;')
|
||||
mel.eval('FBXExportBakeComplexAnimation -v false;')
|
||||
mel.eval('FBXExportUseSceneName -v false;')
|
||||
mel.eval('FBXExportQuaternion -v euler;')
|
||||
mel.eval('FBXExportShapes -v true;')
|
||||
mel.eval('FBXExportSkins -v true;')
|
||||
mel.eval('FBXExportConstraints -v false;')
|
||||
mel.eval('FBXExportCameras -v false;')
|
||||
mel.eval('FBXExportLights -v false;')
|
||||
mel.eval('FBXExportEmbeddedTextures -v false;')
|
||||
mel.eval('FBXExportInputConnections -v false;')
|
||||
mel.eval('FBXExportUpAxis y;')
|
||||
mel.eval(f'FBXExport -f "{file_path[0]}" -s;')
|
||||
except Exception as e:
|
||||
print(f"导出 FBX时出错: {e}")
|
||||
return True
|
||||
|
||||
def export_obj():
|
||||
"""
|
||||
导出 OBJ
|
||||
"""
|
||||
print("导出 OBJ")
|
||||
try:
|
||||
file_path = cmds.fileDialog2(
|
||||
fileFilter="OBJ Files (*.obj);;All Files (*.*)",
|
||||
dialogStyle=2,
|
||||
fileMode=2
|
||||
)
|
||||
if file_path:
|
||||
# 这里实现导出 OBJ的功能
|
||||
print(f"将模型导出到{file_path[0]}")
|
||||
cmds.file(file_path[0], force=True, options="groups=1;ptgroups=1;materials=1;smoothing=1;normals=1", type="OBJexport", pr=True, exportSelected=True)
|
||||
except Exception as e:
|
||||
print(f"导出 OBJ时出错: {e}")
|
||||
return True
|
||||
|
||||
# 工具相关功能
|
||||
def check_model():
|
||||
"""
|
||||
检查模型
|
||||
"""
|
||||
print("检查模型")
|
||||
# 这里实现检查模型的功能
|
||||
return True
|
||||
|
||||
def optimize_model():
|
||||
"""
|
||||
优化模型
|
||||
"""
|
||||
print("优化模型")
|
||||
# 这里实现优化模型的功能
|
||||
return True
|
||||
|
||||
def clean_model():
|
||||
"""
|
||||
清理模型
|
||||
"""
|
||||
print("清理模型")
|
||||
# 这里实现清理模型的功能
|
||||
return True
|
||||
|
||||
def uv_tools():
|
||||
"""
|
||||
UV工具
|
||||
"""
|
||||
print("UV工具")
|
||||
# 这里实现UV工具的功能
|
||||
return True
|
||||
|
||||
#========================================== LOD相关功能 ========================================
|
||||
def clean():
|
||||
"""
|
||||
删除当前选中的LOD
|
||||
"""
|
||||
print("删除LOD")
|
||||
try:
|
||||
# 获取当前选中的LOD标签页
|
||||
tab_widget = cmds.getParent("geometryTabWidget")
|
||||
if tab_widget:
|
||||
current_index = cmds.tabLayout(tab_widget, q=True, selectTabIndex=True) - 1
|
||||
lod_name = f"LOD{current_index}"
|
||||
|
||||
# 确认删除
|
||||
result = cmds.confirmDialog(
|
||||
title=TEXT("confirm_delete", "确认删除"),
|
||||
message=TEXT("delete_lod_confirm", f"确定要删除LOD吗?"),
|
||||
button=[TEXT("yes", "是"), TEXT("no", "否")],
|
||||
defaultButton=TEXT("no", "否"),
|
||||
cancelButton=TEXT("no", "否"),
|
||||
dismissString=TEXT("no", "否")
|
||||
)
|
||||
|
||||
if result == TEXT("yes", "是"):
|
||||
# 删除与该LOD相关的所有模型
|
||||
nodes_to_delete = cmds.ls(f"{lod_name}_*")
|
||||
if nodes_to_delete:
|
||||
cmds.delete(nodes_to_delete)
|
||||
|
||||
print(f"{lod_name}已删除")
|
||||
return True
|
||||
except Exception as e:
|
||||
print(f"删除LOD时出错: {e}")
|
||||
return False
|
||||
|
||||
def load_model_for_lod(lod_name, part_name):
|
||||
"""
|
||||
为指定LOD的身体部位加载模型
|
||||
@@ -425,39 +131,23 @@ def load_model_for_lod(lod_name, part_name):
|
||||
print(f"加载模型时出错: {e}")
|
||||
return False
|
||||
|
||||
def clean():
|
||||
# 模型工具相关功能
|
||||
def standardize_names():
|
||||
"""
|
||||
删除当前选中的LOD
|
||||
标准化命名
|
||||
"""
|
||||
print("删除LOD")
|
||||
try:
|
||||
# 获取当前选中的LOD标签页
|
||||
tab_widget = cmds.getParent("geometryTabWidget")
|
||||
if tab_widget:
|
||||
current_index = cmds.tabLayout(tab_widget, q=True, selectTabIndex=True) - 1
|
||||
lod_name = f"LOD{current_index}"
|
||||
|
||||
# 确认删除
|
||||
result = cmds.confirmDialog(
|
||||
title=TEXT("confirm_delete", "确认删除"),
|
||||
message=TEXT("delete_lod_confirm", f"确定要删除LOD吗?"),
|
||||
button=[TEXT("yes", "是"), TEXT("no", "否")],
|
||||
defaultButton=TEXT("no", "否"),
|
||||
cancelButton=TEXT("no", "否"),
|
||||
dismissString=TEXT("no", "否")
|
||||
)
|
||||
|
||||
if result == TEXT("yes", "是"):
|
||||
# 删除与该LOD相关的所有模型
|
||||
nodes_to_delete = cmds.ls(f"{lod_name}_*")
|
||||
if nodes_to_delete:
|
||||
cmds.delete(nodes_to_delete)
|
||||
|
||||
print(f"{lod_name}已删除")
|
||||
return True
|
||||
except Exception as e:
|
||||
print(f"删除LOD时出错: {e}")
|
||||
return False
|
||||
print("标准化命名")
|
||||
# 这里实现标准化命名的功能
|
||||
return True
|
||||
|
||||
|
||||
def auto_group():
|
||||
"""
|
||||
自动分组
|
||||
"""
|
||||
print("自动分组")
|
||||
# 这里实现自动分组的功能
|
||||
return True
|
||||
|
||||
#========================================== 底部功能按钮 ========================================
|
||||
# 拓扑结构相关功能
|
||||
@@ -562,83 +252,6 @@ def separate_model():
|
||||
print(f"模型分离时出错: {e}")
|
||||
return False
|
||||
|
||||
def fix_normals():
|
||||
"""
|
||||
修复法线
|
||||
修复选中模型的法线方向
|
||||
"""
|
||||
print("修复法线")
|
||||
try:
|
||||
# 获取当前选中的模型
|
||||
selected_models = cmds.ls(selection=True, type="transform")
|
||||
if not selected_models:
|
||||
cmds.warning(TEXT("no_model_selected", "未选中模型"))
|
||||
return False
|
||||
|
||||
# 对每个选中的模型修复法线
|
||||
for model in selected_models:
|
||||
# 先解锁法线
|
||||
cmds.polyNormalPerVertex(model, unFreezeNormal=True)
|
||||
# 然后计算法线
|
||||
cmds.polyNormal(model, normalMode=0, userNormalMode=0, ch=1)
|
||||
# 最后让法线平滑
|
||||
cmds.polySoftEdge(model, angle=30, ch=1)
|
||||
|
||||
print("法线修复完成")
|
||||
return True
|
||||
except Exception as e:
|
||||
print(f"修复法线时出错: {e}")
|
||||
return False
|
||||
|
||||
def optimize_scene():
|
||||
"""
|
||||
优化场景
|
||||
清理场景中的未使用节点和历史记录
|
||||
"""
|
||||
print("优化场景")
|
||||
try:
|
||||
# 清理未使用的节点
|
||||
mel.eval('MLdeleteUnused;')
|
||||
|
||||
# 删除所有历史记录
|
||||
cmds.delete(constructionHistory=True, all=True)
|
||||
|
||||
# 优化场景大小
|
||||
cmds.file(cleanReference=True)
|
||||
cmds.file(removeReference=True)
|
||||
cmds.file(optimizeReference=True)
|
||||
|
||||
# 清理未使用的材质和纹理
|
||||
mel.eval('hyperShadePanelMenuCommand("hyperShadePanel1", "deleteUnusedNodes");')
|
||||
|
||||
print("场景优化完成")
|
||||
return True
|
||||
except Exception as e:
|
||||
print(f"优化场景时出错: {e}")
|
||||
return False
|
||||
|
||||
def modify_topology():
|
||||
"""
|
||||
修改模型拓扑
|
||||
"""
|
||||
print("修改模型拓扑")
|
||||
try:
|
||||
# 获取当前选中的模型
|
||||
selected_models = cmds.ls(selection=True, type="transform")
|
||||
if not selected_models:
|
||||
cmds.warning(TEXT("no_model_selected", "未选中模型"))
|
||||
return False
|
||||
|
||||
# 切换到多边形编辑模式
|
||||
cmds.selectMode(component=True)
|
||||
cmds.selectType(polymesh=True)
|
||||
|
||||
print("进入拓扑编辑模式")
|
||||
return True
|
||||
except Exception as e:
|
||||
print(f"修改模型拓扑时出错: {e}")
|
||||
return False
|
||||
|
||||
def generate_face_components():
|
||||
"""
|
||||
生成面部配件
|
||||
@@ -667,11 +280,12 @@ def generate_face_components():
|
||||
print(f"生成面部配件时出错: {e}")
|
||||
return False
|
||||
|
||||
def generate_uvs():
|
||||
def fix_normals():
|
||||
"""
|
||||
生成模型UV
|
||||
修复法线
|
||||
修复选中模型的法线方向
|
||||
"""
|
||||
print("生成模型UV")
|
||||
print("修复法线")
|
||||
try:
|
||||
# 获取当前选中的模型
|
||||
selected_models = cmds.ls(selection=True, type="transform")
|
||||
@@ -679,22 +293,60 @@ def generate_uvs():
|
||||
cmds.warning(TEXT("no_model_selected", "未选中模型"))
|
||||
return False
|
||||
|
||||
# 为每个选中的模型生成UV
|
||||
# 对每个选中的模型修复法线
|
||||
for model in selected_models:
|
||||
# 使用Maya的自动UV展开功能
|
||||
cmds.polyAutoProjection(model, constructionHistory=True, layout=2, optimize=1, percentageSpace=0.2)
|
||||
# 先解锁法线
|
||||
cmds.polyNormalPerVertex(model, unFreezeNormal=True)
|
||||
# 然后计算法线
|
||||
cmds.polyNormal(model, normalMode=0, userNormalMode=0, ch=1)
|
||||
# 最后让法线平滑
|
||||
cmds.polySoftEdge(model, angle=30, ch=1)
|
||||
|
||||
print("UV生成完成")
|
||||
print("法线修复完成")
|
||||
return True
|
||||
except Exception as e:
|
||||
print(f"生成UV时出错: {e}")
|
||||
print(f"修复法线时出错: {e}")
|
||||
return False
|
||||
|
||||
# 保留原来的函数作为兼容性考虑
|
||||
def geometry_temp_utils_function():
|
||||
def fix_vertex_order():
|
||||
"""
|
||||
Placeholder function for geometry module
|
||||
This function will be replaced with actual functionality in future updates
|
||||
修复点序
|
||||
"""
|
||||
print("Geometry module initialized with placeholder function")
|
||||
return True
|
||||
print("修复点序")
|
||||
# 这里实现修复点序的功能
|
||||
return True
|
||||
|
||||
def fix_seams():
|
||||
"""
|
||||
修复接缝
|
||||
"""
|
||||
print("修复接缝")
|
||||
# 这里实现修复接缝的功能
|
||||
return True
|
||||
|
||||
def optimize_scene():
|
||||
"""
|
||||
优化场景
|
||||
清理场景中的未使用节点和历史记录
|
||||
"""
|
||||
print("优化场景")
|
||||
try:
|
||||
# 清理未使用的节点
|
||||
mel.eval('MLdeleteUnused;')
|
||||
|
||||
# 删除所有历史记录
|
||||
cmds.delete(constructionHistory=True, all=True)
|
||||
|
||||
# 优化场景大小
|
||||
cmds.file(cleanReference=True)
|
||||
cmds.file(removeReference=True)
|
||||
cmds.file(optimizeReference=True)
|
||||
|
||||
# 清理未使用的材质和纹理
|
||||
mel.eval('hyperShadePanelMenuCommand("hyperShadePanel1", "deleteUnusedNodes");')
|
||||
|
||||
print("场景优化完成")
|
||||
return True
|
||||
except Exception as e:
|
||||
print(f"优化场景时出错: {e}")
|
||||
return False
|
Reference in New Issue
Block a user