Update
This commit is contained in:
@@ -358,6 +358,189 @@ def uv_tools():
|
||||
# 这里实现UV工具的功能
|
||||
return True
|
||||
|
||||
#========================================== LOD相关功能 ========================================
|
||||
def load_model_for_lod(lod_name, part_name):
|
||||
"""
|
||||
为指定LOD的身体部位加载模型
|
||||
参数:
|
||||
lod_name: LOD名称,如"LOD0"
|
||||
part_name: 身体部位名称,如"头部"
|
||||
"""
|
||||
print(f"为{lod_name}的{part_name}加载模型")
|
||||
try:
|
||||
# 打开文件选择对话框
|
||||
file_path = cmds.fileDialog2(
|
||||
fileFilter="Maya Files (*.ma *.mb);;OBJ Files (*.obj);;FBX Files (*.fbx);;All Files (*.*)",
|
||||
dialogStyle=2,
|
||||
fileMode=1,
|
||||
caption=f"选择{lod_name}的{part_name}模型"
|
||||
)
|
||||
|
||||
if file_path and len(file_path) > 0:
|
||||
# 根据文件类型导入模型
|
||||
file_ext = os.path.splitext(file_path[0])[1].lower()
|
||||
|
||||
if file_ext in [".ma", ".mb"]:
|
||||
# 导入Maya文件
|
||||
cmds.file(file_path[0], i=True, type="mayaAscii" if file_ext == ".ma" else "mayaBinary",
|
||||
ignoreVersion=True, mergeNamespacesOnClash=False, namespace=f"{lod_name}_{part_name}")
|
||||
elif file_ext == ".obj":
|
||||
# 导入OBJ文件
|
||||
cmds.file(file_path[0], i=True, type="OBJ", ignoreVersion=True,
|
||||
options="mo=1", namespace=f"{lod_name}_{part_name}")
|
||||
elif file_ext == ".fbx":
|
||||
# 导入FBX文件
|
||||
mel.eval(f'FBXImport -file "{file_path[0]}";')
|
||||
|
||||
# 重命名导入的模型
|
||||
imported_nodes = cmds.ls(sl=True)
|
||||
if imported_nodes:
|
||||
for node in imported_nodes:
|
||||
new_name = f"{lod_name}_{part_name}_{os.path.basename(node)}"
|
||||
cmds.rename(node, new_name)
|
||||
|
||||
print(f"成功为{lod_name}的{part_name}加载模型: {file_path[0]}")
|
||||
return True
|
||||
except Exception as e:
|
||||
print(f"加载模型时出错: {e}")
|
||||
return False
|
||||
|
||||
def delete():
|
||||
"""
|
||||
删除当前选中的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=LANG.get("confirm_delete", "确认删除"),
|
||||
message=LANG.get("delete_lod_confirm", f"确定要删除{lod_name}吗?"),
|
||||
button=[LANG.get("yes", "是"), LANG.get("no", "否")],
|
||||
defaultButton=LANG.get("no", "否"),
|
||||
cancelButton=LANG.get("no", "否"),
|
||||
dismissString=LANG.get("no", "否")
|
||||
)
|
||||
|
||||
if result == LANG.get("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 auto_model():
|
||||
"""
|
||||
自动化模型功能
|
||||
自动处理模型的各种设置
|
||||
"""
|
||||
print("自动化模型")
|
||||
try:
|
||||
# 获取当前选中的模型
|
||||
selected_models = cmds.ls(selection=True, type="transform")
|
||||
if not selected_models:
|
||||
cmds.warning(LANG.get("no_model_selected", "未选中模型"))
|
||||
return False
|
||||
|
||||
# 执行标准化命名
|
||||
standardize_names()
|
||||
|
||||
# 执行自动分组
|
||||
auto_group()
|
||||
|
||||
# 执行优化模型
|
||||
optimize_model()
|
||||
|
||||
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(LANG.get("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():
|
||||
"""
|
||||
生成面部配件
|
||||
如眉毛、睡毛、泪腺等
|
||||
"""
|
||||
print("生成面部配件")
|
||||
try:
|
||||
# 获取当前选中的模型
|
||||
selected_models = cmds.ls(selection=True, type="transform")
|
||||
if not selected_models:
|
||||
cmds.warning(LANG.get("no_model_selected", "未选中模型"))
|
||||
return False
|
||||
|
||||
# 生成眉毛
|
||||
# 这里只是示例代码,实际实现需要更复杂的逻辑
|
||||
eyebrow_curve = cmds.curve(d=3, p=[(0,0,0), (0.5,0.1,0), (1,0,0)])
|
||||
cmds.rename(eyebrow_curve, "eyebrow_curve")
|
||||
|
||||
# 生成睡毛
|
||||
eyelash_curve = cmds.curve(d=3, p=[(0,0,0), (0.5,-0.1,0), (1,0,0)])
|
||||
cmds.rename(eyelash_curve, "eyelash_curve")
|
||||
|
||||
print("面部配件生成完成")
|
||||
return True
|
||||
except Exception as e:
|
||||
print(f"生成面部配件时出错: {e}")
|
||||
return False
|
||||
|
||||
def generate_uvs():
|
||||
"""
|
||||
生成模型UV
|
||||
"""
|
||||
print("生成模型UV")
|
||||
try:
|
||||
# 获取当前选中的模型
|
||||
selected_models = cmds.ls(selection=True, type="transform")
|
||||
if not selected_models:
|
||||
cmds.warning(LANG.get("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)
|
||||
|
||||
print("UV生成完成")
|
||||
return True
|
||||
except Exception as e:
|
||||
print(f"生成UV时出错: {e}")
|
||||
return False
|
||||
|
||||
# 保留原来的函数作为兼容性考虑
|
||||
def geometry_temp_utils_function():
|
||||
"""
|
||||
|
Reference in New Issue
Block a user