保存顶点/面片
下面得脚本在当前已选中的对象中,提取形如
mesh.vtx[123]
中的序号123,并统一保存到指定文件中。
$object_list = `ls -sl -fl`;
$count = `size $object_list`;
$filename = `fileDialog -mode 1 -title "保存文件"`;
$file = `fopen $filename "w"`;
if ($file) {
for ($i = 0; $i < $count; $i++) {
$index_with_bracket = `match "\\[[0-9]+\\]" $object_list[$i]`;
$index = `match "[0-9]+" $index_with_bracket`;
fprint $file $index;
fprint $file "\n";
}
fclose($file);
}
读取顶点
下面得脚本从指定文件中读取顶点序号(0-based),再在当前已选中的对象中选中这些顶点。
$object_list = `ls -sl`;
$count = `size $object_list`;
if ($count > 0) {
$object = $object_list[0];
string $filename = `fileDialog -mode 0 -title "读取文件"`;
$file = `fopen $filename "r"`;
if ($file) {
int $vertex_list[];
int $vertex_count = 0;
string $line = `fgetline $file`;
while (size($line) > 0) {
$vertex_list[$vertex_count++] = `match "[0-9]+" $line`;
$line = `fgetline $file`;
}
fclose $file;
select -cl;
for ($i = 0; $i < $vertex_count; $i++) {
$selection = $object + ".vtx[" + $vertex_list[$i] + "]";
select -add $selection;
}
}
}
读取面片
下面得脚本从指定文件中读取面片序号(0-based),再在当前已选中的对象中选中这些面片。
总体来说和读取顶点差不多一样。
$object_list = `ls -sl`;
$count = `size $object_list`;
if ($count > 0) {
$object = $object_list[0];
string $filename = `fileDialog -mode 0 -title "读取文件"`;
$file = `fopen $filename "r"`;
if ($file) {
int $vertex_list[];
int $vertex_count = 0;
string $line = `fgetline $file`;
while (size($line) > 0) {
$vertex_list[$vertex_count++] = `match "[0-9]+" $line`;
$line = `fgetline $file`;
}
fclose $file;
select -cl;
for ($i = 0; $i < $vertex_count; $i++) {
$selection = $object + ".f[" + $vertex_list[$i] + "]";
select -add $selection;
}
}
}