maya拼图随机打乱工具插件
作者:快盘下载 人气:以前做的一个小案例;拼图打乱工具;效果如下图所示;
打乱前需要record一下原始位置;之后;点击random打乱后的效果如下;
点击reset可以还原原始位置;
代码分享如下;
//coded by JingHai Tian in 2015 //this procedure can order the select objects randomly. global proc tjh_random_order_proc() { if (;windowPref -exists tjh_random_order_proc_window ;) windowPref -remove tjh_random_order_proc_window; if (;window -exists tjh_random_order_proc_window ;) deleteUI tjh_random_order_proc_window; window -title ;南无阿弥陀佛; -w 300 -h 100 tjh_random_order_proc_window ; columnLayout -w 100 ; text -h 50 -l ; 随机顺序排列工具 Random Order Tool 1.0 ;; rowLayout -numberOfColumns 3 -columnWidth3 100 100 100 -adjustableColumn 2 -columnAlign 1 ;right; -columnAttach 1 ;both; 0 -columnAttach 2 ;both; 0; button -w 100 -l ;record; -c ;tjh_random_order__recordOld;; button -w 100 -l ;reset; -c ;tjh_random_order__restore;; button -w 100 -l ;random; -c ;tjh_random_order__random;; setParent ..; showWindow tjh_random_order_proc_window; } //record the old order ids. global proc tjh_random_order__recordOld() { global float $oldPosArrays_x[]; global float $oldPosArrays_y[]; global float $oldPosArrays_z[]; global string $oldSelects[]; string $selects[]= ; ls -sl ;; $oldSelects = $selects; for($i=0; $i<size($selects);$i;;) { $oldPosArrays_x[$i]= ; getAttr ($selects[$i];;.tx;) ;; $oldPosArrays_y[$i]= ; getAttr ($selects[$i];;.ty;) ;; $oldPosArrays_z[$i]= ; getAttr ($selects[$i];;.tz;) ;; } } global proc tjh_random_order__restore() { global float $oldPosArrays_x[]; global float $oldPosArrays_y[]; global float $oldPosArrays_z[]; global string $oldSelects[]; select -r $oldSelects; for($i=0; $i<size($oldSelects);$i;;) { setAttr ($oldSelects[$i];;.tx;) $oldPosArrays_x[$i]; setAttr ($oldSelects[$i];;.ty;) $oldPosArrays_y[$i]; setAttr ($oldSelects[$i];;.tz;) $oldPosArrays_z[$i]; } } global proc tjh_random_order__random() // { string $selects[] =;ls -sl;; string $oldOrderIds[]= $selects; //print $oldOrderIds; string $newOrderIds[]; int $newIndex=0; int $i,$j,$k; int $selectTimes = size($oldOrderIds); float $mx[],$my[],$mz[]; //random order & select method while($selectTimes) { int $randselect = rand($selectTimes); string $orderIdsTemp[]; int $tmpIndex=0; for($k=0;$k<$selectTimes;$k;;) { if($k==$randselect){ $newOrderIds[$newIndex]=$oldOrderIds[$k]; $newIndex;;; }; //print $oldOrderIds; //remove the select id from the old list. if($k!=$randselect){ $orderIdsTemp[$tmpIndex]=$oldOrderIds[$k]; $tmpIndex;;; }; } clear $oldOrderIds; $oldOrderIds = $orderIdsTemp; clear $orderIdsTemp; $selectTimes --; } print $selects; print $newOrderIds; print (size($newOrderIds)); //transform the new list objects. for($k=0;$k<size($selects);$k;;) { $mx[$k] = ; getAttr ($selects[$k];;.tx;);; $my[$k] = ; getAttr ($selects[$k];;.ty;);; $mz[$k] = ; getAttr ($selects[$k];;.tz;);; } //transform the new list objects. for($k=0;$k<size($selects);$k;;) { setAttr ($newOrderIds[$k];;.tx;) $mx[$k]; setAttr ($newOrderIds[$k];;.ty;) $my[$k]; setAttr ($newOrderIds[$k];;.tz;) $mz[$k]; } } tjh_random_order_proc;
加载全部内容