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