nanoblock_mel();//-----------------------------------------------------------------------------------------//------- 所有的颗粒类型 --------------------------------------------//-----------------------------------------------------------------------------------------global string $arrayTypeAC[]={"1x1y","1x1","1x2","1x3","1x4","1x6","1x8","1x10","1x3g","3x1y", "2x2","2x3","2x4","2x6","2x8","2x10", "1x1p","1x2p","1x3p","1x4p","1x6p","1x8p","2x2p","2x3p","2x4p", "1x1z","1x2z","1x3z","1x4z","2x1z","1x3l","1x3t", "1x2y","1x3y","1x4y","2x2y", "1x2ao","1x2tu","2x2ao","2x2tu","1x2ti","2x1ti", "1x2x","2x1x","1x2o","1x3x","2x3x","2x4x","2x2x", "1x1c","1x1h","2x2z","3x3g", "4x4","4x6","4x8","6x8","8x8","10x10","14x14","7x25","20x20","36x36" };global int $allColor=92;global string $allSelectA[];//-----------------------------------------------------------------------------------------//------- 所有的颗粒颜色 --------------------------------------------------------------//-----------------------------------------------------------------------------------------global proc nanoblock_mel(){ //定义全局变量 global string $arrayTypeAC[]; print("arrayTypeAC:"+size($arrayTypeAC)); global int $allColor; //创建工具窗口 if (`window -q -ex createNanoblockUI`)deleteUI createNanoblockUI; window -t "SCBlock 2015年10月新版" -w 200 -h 30 createNanoblockUI; string $tabs=`tabLayout`; /// string $child0=`rowColumnLayout -nc 1 `; text -l "D:/Work/nanoblock/maya/Mel_1009/" path; text -l ""; //添加颜色和摄像机 button -c "onImport Color" -l "Color"; //添加线段 text -l ""; button -l "快速选择" -c "onQuickSelectUI"; button -l "去除小数点" -c "onDel"; button -l "打组镜像" -c "onMirr"; button -l "快速打组" -c "onGroup"; text -l ""; button -c "onImport Line" -l "Line"; text -l ""; button -l " 红线 " -bgc 1 0 0 -c "onLineR"; button -l " 蓝线 " -bgc 0 0.5 1 -c "onLineB"; button -l " 绿线 " -bgc 0 1 0 -c "onLineG" ; text -l ""; button -l "统计颗粒" -c "onKeli"; text -l ""; button -l "打开渲染目录" -c "openRenderFile"; button -l "渲染前合并模型" -c "preRender"; setParent..; /// string $child1=`rowColumnLayout -nc 10 `; string $pathFile=`text -q -l path`; string $tt; for($tt in $arrayTypeAC){ //print($tt+" "); iconTextButton -style "iconAndTextVertical" -image1 ($pathFile+"type/"+$tt+"_0.png") -label ($tt+"") -c ("onImport SC_"+$tt); } setParent..; /// string $child2=`rowColumnLayout -nc 13 `; string $pathFile=`text -q -l path`; //根据 全局变量 颗粒颜色 创建颗粒按钮 for($t=0;$t<$allColor;$t++){ iconTextButton -style "iconAndTextVertical" -image1 ($pathFile+"color/"+$t+".png") -label ($t+"") -c ("onColor vray_"+$t+" "+$t); if($t==29){text -l "森宝→" -bgc 0.2 0.2 0.2 ;} } setParent..; /// string $child3=`rowColumnLayout -nc 7 -bgc 0 1 1`; setParent..; tabLayout -edit -tabLabel $child0 "准备" -tabLabel $child1 "颗粒" -tabLabel $child2 "颜色" -tabLabel $child3 "工具" $tabs; showWindow createNanoblockUI;}//打开渲染目录-----------------------------------------proc openRenderFile(){ string $pro=`internalVar -userWorkspaceDir`; $pro+="default/images/"; system("load " + $pro);}//打组镜像------------------------------------------------------------------------------------------------------proc onMirr(){ Group; duplicate -rr; string $sel[]=`ls -sl`; setAttr ($sel[0]+".scaleX") -1;}//导入颗粒------------------------------------------------------------------------------------------------------proc onImport(string $_name){ string $pathFile=`text -q -l path`; print("导入文件:"+($pathFile+"mc/"+$_name+".mb")); file -import -type "mayaBinary" -gr -ra true -options "v=0" -pr -loadReferenceDepth "all" ($pathFile+"mc/"+$_name+".mb"); }//给颗粒上颜色-------------------------------------------------------------------------------proc onColor(string $_name,int $_num){ string $sel[]=`ls -sl`; for ($ppName in $sel){ if(`attributeQuery -node $ppName -ex "Color"`){ setAttr ($ppName+".Color") $_num; }else{ addAttr -ln "Color" -at long $ppName; //setAttr -k on ($ppName+".Color"); setAttr -e -channelBox true ($ppName+".Color"); setAttr ($ppName+".Color") $_num; } //defaultNavigation -source ("Color_"+$_name) -destination ($ppName+"Shape.instObjGroups[0]") -connectToExisting; hyperShade -assign ("Color_"+$_name); } //hyperShade -assign ("Color_"+$_name); //print("Color_"+$_name);}//获取场景中所有颗粒的类型 并计算颗粒的数量-----------------------------------------------------------------proc onKeli(){ global string $allSelectA[]; select -all; select -hi; string $selAll[]=`ls -sl`; string $obj; select -cl; //--创建类型 和颜色 的数值 //string $mcType[]; string $mc_Type_Color[]; int $mcTypeNum=0; float $mcWeight; float $mcPrice; for($obj in $selAll){ if(`nodeType $obj`=="transform"){ if(`attributeQuery -node $obj -ex "Type"`){ print("mcTpyeNum:"+$mcTpyeNum); string $getType=`getAttr -as ($obj+".Type")`; string $getColor=`getAttr -as ($obj+".Color")`; $mc_Type_Color[$mcTypeNum]=$getType+"_"+$getColor; $mcTypeNum++; $mcWeight+=`getAttr -as ($obj+".Weight")`; } if(`attributeQuery -node $obj -ex "Price"`){ $mcPrice+=`getAttr -as ($obj+".Price")`; } } } ArrangeB($mc_Type_Color); print(size($mc_Type_Color)); //print("--------产品总重量约:"+$mcWeight+"克"+"\n"); //获取场景中类型与颜色的数组 --------------$mcTypeA-----$mcColorA string $mcType_rd[]=stringArrayRemoveDuplicates($mc_Type_Color); int $mcType_count[]; print($mcType_rd); for($i=0;$i-1;$i--){ for($a in $array){ string $arraySTSA[]; $arraySTSA = stringToStringArray($a, "_"); string $name=$arraySTSA[1]; if($name==$arrIndex[$i]){ $arr_0[$int_0]=$a; $int_0 ++; } } $newArray=stringArrayCatenate($arr_0,$newArray); clear $arr_0; $int_0=0; } clear $array; $array=$newArray; } //重新排列类型-------------------------------------------------------------------proc ArrangeB(string $array[]){ global string $arrayTypeAC[]; global string $arrayColor[]; string $arrIndex[]=$arrayTypeAC; //定义临时数组 string $arr_0[]; //定义临时数组索引 int $int_0=0; string $newArray[]; //执行前清空数组 clear $arr_0; clear $newArray; string $a; for($i=size($arrIndex)-1;$i>-1;$i--){ for($a in $array){ string $arraySTSA[]; $arraySTSA = stringToStringArray($a, "_"); string $name=$arraySTSA[0]; print("$name:"+$name+"\n"); if($name==$arrIndex[$i]){ $arr_0[$int_0]=$a; $int_0 ++; } } $newArray=stringArrayCatenate($arr_0,$newArray); clear $arr_0; $int_0=0; } clear $array; $array=$newArray; Arrange($array);} //自动处理渲染所需要的模型proc preRender(){ global string $allSelectA[]; select -all; select -hi; string $selAll[]=`ls -sl`; string $obj; select -cl; //--创建类型 和颜色 的数值 //string $mcType[]; string $mc_Type_Color[]; int $mcTypeNum=0; for($obj in $selAll){ if(`nodeType $obj`=="transform"){ if(`attributeQuery -node $obj -ex "Type"`){ print("mcTpyeNum:"+$mcTpyeNum); string $getColor=`getAttr -as ($obj+".Color")`; $mc_Type_Color[$mcTypeNum]=$getColor; $mcTypeNum++; } } } //print("--------产品总重量约:"+$mcWeight+"克"+"\n"); //获取场景中类型与颜色的数组 --------------$mcTypeA-----$mcColorA string $mcType_rd[]=stringArrayRemoveDuplicates($mc_Type_Color); int $mcType_count[]; print("_____"+size($mcType_rd)); //-------------- for($i in $mcType_rd) { select -all; select -hi; string $selAll[]=`ls -sl`; string $obj; select -cl; for($obj in $selAll){ if(`nodeType $obj`=="transform"){ if(`attributeQuery -node $obj -ex "Type"`){ string $getColor=`getAttr -as ($obj+".Color")`; if($getColor==$i){ select -add $obj; } } } } print("$i"+$i); string $selAllB[]=`ls -sl`; for($i in $selAllB){ polyBevel -com 0 -fraction 1.5 -offsetAsFraction 1 -autoFit 1 -segments 2 -worldSpace 1 -uvAssignment 1 -smoothingAngle 30 -fillNgons 1 -mergeVertices 1 -mergeVertexTolerance 0.0001 -miteringAngle 180 -angleTolerance 180 -ch 1 $i; } if(size($selAllB)>1){ CombinePolygons; string $ss[]=`ls -sl`; rename $ss[0] ("n_"+$i); DeleteHistory; }else{ parent -w; string $ss[]=`ls -sl`; rename $ss[0] ("n_"+$i); DeleteHistory; } } }