MAYA --MEL 复制成一堆杂乱的物体
先自行创建一物体,并选中它,执行此MEL即可复制成一堆杂乱的物体。<br><br><br><br><br><br><br><br>proc scatterObject(int $numOfDuplicates,<br> float $withinMinX,<br> float $withinMinY,<br> float $withinMinZ,<br> float $withinMaxX,<br> float $withinMaxY,<br> float $withinMaxZ,<br> float $rotateMinX,<br> float $rotateMinY,<br> float $rotateMinZ,<br> float $rotateMaxX,<br> float $rotateMaxY,<br> float $rotateMaxZ) {<br><br>vector $newpos;<br>vector $newrot;<br>int $numOfDuplicates = $numOfDuplicates;<br>int $i = 0;<br>string $selectedSurface[] = `ls -sl`;<br>string $newSurface[];<br>float $x;<br>float $y;<br>float $z;<br><br>//print("Scatter object(s): " + $selectedSurface + "\n");<br>for($i = 0; $i < $numOfDuplicates;$i++) {<br> $newpos = `rand <<$withinMinX,$withinMinY,$withinMinZ>> <<$withinMaxX,$withinMaxY,$withinMaxZ>>`;<br> $newrot = `rand <<$rotateMinX,$rotateMinY,$rotateMinZ>> <<$rotateMaxX,$rotateMaxY,$rotateMaxZ>>`;<br> $newSurface = `duplicate $selectedSurface`;<br> print("New duplicates position: " + $newpos.x + ":" + $newpos.y + ":" + $newpos.z + "\n");<br> $x = $newpos.x;<br> $y = $newpos.y;<br> $z = $newpos.z;<br> move -a $x $y $z $newSurface;<br> $x = $newrot.x;<br> $y = $newrot.y;<br> $z = $newrot.z;<br> rotate $x $y $z $newSurface;<br>}<br>}<br><br>// e.g. 100 duplicates (of selected object) within a 10 by 10 by 10 cube <br>// all duplicates are rotated randomly within -45 to +45 on all axis <br>scatterObject(100, 0, 0, 0, 10, 10, 10, -45, -45, -45, 45, 45, 45);<br>