maya批量操作mel_MAYA对多个模型使用当前设置批量渲染并保存图片的MEL脚本
更新日志
2018-10-23:添加了對文件名為定長數字(0000, 0001, 0002, ect.)的模型的支持;輸出圖片擴展名使用渲染設置中的擴展名。
有時候需要對一組模型使用相同的材質和相同的渲染設置渲染并保存為圖片,以往只能一個個手動導入、替換材質、渲染、移除,直到前陣子需要一次性這樣渲染上百張圖片……
于是終于咬牙寫了一個批量渲染的MEL腳本——
下面的腳本會自動讀取一系列文件路徑只有序號差異的模型,使用給定的材質并設置線框顏色為RGB(0,0,0),然后使用當前渲染設置、當前攝像機位置,進行渲染并保存為和模型同名的圖片。
//選擇渲染的材質
//默認為lambert1
string $mat;
string $result = `promptDialog
-title "材質選擇"
-message "輸入渲染的材質:"
-button "OK"`;
if ($result == "OK") {
$mat = `promptDialog -query -text`;
} else {
$mat = "lambert1";
}
//打開第1個模型
string $fileFirst;
$fileFirst = `fileDialog -mode 0 -title "打開要渲染的第1個模型(模型全路徑必須出現1處整數表示序號)"`;
//獲取第1個模型的序號
string $idFirst = `match "[0-9]+" $fileFirst`;
int $idLength = `size $idFirst`;
if ($fileFirst == "") {
} else if ($idFirst == "") {
confirmDialog -title "錯誤" -message "模型全路徑必須出現1處整數表示序號";
} else {
for ($id = (int)$idFirst; $id < 1000; $id++) {
string $idCurrent = (string)$id;
string $fileCurrent = `substitute "[0-9]+" $fileFirst $idCurrent`;
string $imageCurrent = `substitute "\.[^\.]+$" $fileCurrent ""`;
//檢測文件是否存在
int $fid = `fopen $fileCurrent "r"`;
if ($fid == 0) {
//嘗試定長數字
for ($i = `size $idCurrent`; $i < $idLength; $i++) $idCurrent = "0" + $idCurrent;
$fileCurrent = `substitute "[0-9]+" $fileFirst $idCurrent`;
$imageCurrent = `substitute "\.[^\.]+$" $fileCurrent ""`;
$fid = `fopen $fileCurrent "r"`;
if ($fid == 0) break;
}
fclose $fid;
//導入模型并獲取對象名$newObj
string $before[] = `ls`;
file -import $fileCurrent;
string $after[] = `ls`;
string $newObjs[] = stringArrayRemove($before, $after);
string $newObj = $newObjs[0];
select -r $newObj;
color -rgb 0 0 0 $newObj;//設置黑色線框
hyperShade -assign $mat;//設置材質
select -d;
//使用當前設置渲染并保存圖片
RenderIntoNewWindow;
renderWindowEditor -e -wi($imageCurrent) renderView;
//移除模型
select -r $newObj;
doDelete;
}
}
總結
以上是生活随笔為你收集整理的maya批量操作mel_MAYA对多个模型使用当前设置批量渲染并保存图片的MEL脚本的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: duration转为时间戳_Flink
- 下一篇: 发现了imageio文档中有代替scip