前回のスクリプトを少し改良して岩・石を自動生成するスクリプトを作ってみる。
(ポリゴンの分割数を変えて、最後にスムースをかけている。)
まず、1個岩石を作るスクリプトを作ってみる。
global proc makeRock4()
{
string $poly[] = `polySphere -subdivisionsX 5 -subdivisionsY 5`;
$x = rand(1, 2);
$y = rand(1, 2);
$z = rand(1, 2);
scale $x $y $z;
string $ver[] = `polyListComponentConversion -toVertex $poly[0]`;
string $verE[] = `filterExpand -selectionMask 31 $ver`;
for($obj in $verE)
{
select -r $obj;
$x = rand(-0.2, 0.2);
$y = rand(-0.2, 0.2);
$z = rand(-0.2, 0.2);
move -r $x $y $z;
}
string $polyS[] = `listRelatives -shapes $poly[0]`;
polySmooth -divisions 2 -continuity 0.5 $polyS[0];
}
string $poly[] = `polySphere -subdivisionsX 5 -subdivisionsY 5`;
ポリゴンの球を作る。
$x = rand(1.0, 2.0);
乱数の値(1.0から2.0)を$xに代入。
$y = rand(1.0, 2.0);
乱数の値(1.0から2.0)を$yに代入。
$z = rand(1.0, 2.0);
乱数の値(1.0から2.0)を$zに代入。
scale $x $y $z;
ポリゴンの球にスケールをかける。
string $ver[] = `polyListComponentConversion -toVertex $poly[0]`;
ポリゴンの球から頂点を取り出して$ver[]に代入。
string $verE[] = `filterExpand -selectionMask 31 $ver`;
$verの中から頂点(31で表される)を配列に展開して$verE[]に代入。
for($obj in $verE)
$verE[]から、ひとつづつ頂点を取り出して$objに代入してループの中の処理を行なう。
select -r $obj;
$obj(頂点)だけをセレクトする。
$x = rand(-0.2, 0.2);
乱数の値(-0.2から0.2)を$xに代入。
$y = rand(-0.2, 0.2);
乱数の値(-0.2から0.2)を$yに代入。
$z = rand(-0.2, 0.2);
乱数の値(-0.2から0.2)を$zに代入。
move -r $x $y $z;
セレクトされている頂点を、その位置から$x, $y, $zだけ移動する。
string $polyS[] = `listRelatives -shapes $poly[0]`;
ポリゴンのトランスフォームノードの子ノードからシェープノード(メッシュ)を得る。
polySmooth -divisions 2 -continuity 0.5 $polyS[0];
ポリゴンメッシュにスムースをかける。