50 lines
1.6 KiB
Python
50 lines
1.6 KiB
Python
|
#!/usr/bin/env python
|
|||
|
# -*- coding: utf-8 -*-
|
|||
|
|
|||
|
import os
|
|||
|
import maya.cmds as cmds
|
|||
|
from Core import SkinCluster
|
|||
|
|
|||
|
def import_skin_cluster():
|
|||
|
"""
|
|||
|
导入蒙皮权重数据
|
|||
|
支持两种模式:
|
|||
|
1. 选中单个模型时,通过文件对话框选择单个权重文件导入
|
|||
|
2. 未选中或选中多个模型时,可以选择多个权重文件,根据文件名自动匹配模型
|
|||
|
"""
|
|||
|
# 获取当前选中的物体
|
|||
|
selection = cmds.ls(sl=True)
|
|||
|
|
|||
|
# 设置文件过滤器
|
|||
|
basic_filter = "Maya Skin (*.skin)"
|
|||
|
|
|||
|
# 打开文件选择对话框
|
|||
|
skin_files = cmds.fileDialog2(fileFilter=basic_filter,
|
|||
|
fileMode=4, # 允许选择多个文件
|
|||
|
dialogStyle=1)
|
|||
|
|
|||
|
# 如果用户取消了选择,直接返回
|
|||
|
if not skin_files:
|
|||
|
return
|
|||
|
|
|||
|
# 处理单个选中物体的情况
|
|||
|
if len(selection) == 1:
|
|||
|
SkinCluster(selection[0], import_file=skin_files[0])
|
|||
|
else:
|
|||
|
# 处理多个文件的情况
|
|||
|
for skin_file in skin_files:
|
|||
|
# 从文件路径中提取模型名称
|
|||
|
file_name = os.path.basename(skin_file)
|
|||
|
mesh_name = os.path.splitext(file_name)[0]
|
|||
|
|
|||
|
# 检查模型是否存在
|
|||
|
if cmds.objExists(mesh_name):
|
|||
|
# 检查是否已经存在蒙皮变形器
|
|||
|
skin_cluster = cmds.findRelatedSkinCluster(mesh_name)
|
|||
|
if not skin_cluster:
|
|||
|
# 导入权重数据
|
|||
|
SkinCluster(mesh_name, import_file=skin_file)
|
|||
|
|
|||
|
# 如果直接运行此脚本
|
|||
|
if __name__ == '__main__':
|
|||
|
import_skin_cluster()
|