finally i have got 10 minutes to do the script.
to work properly, you must to select one complete leaf (and only one) in face selection mode
by this way, the script can know how many polys has each leaf
after that execute the script
it also works if each leaf has only one poly.
int $sys = 4;
if (`window -exists Div_Mesh`)
deleteUI Div_Mesh;
window -w 280 -h 600 -title "Dividir mesh" Div_Mesh;
columnLayout Ejes;
//Definir los ejes y la tolerancia
frameLayout -w 285 -bs "etchedIn" -borderVisible true -labelVisible true -labelAlign "center" -marginWidth 5 -marginHeight 5 -label "Define arrangement" -cll true HPlace;
columnLayout;
rowLayout -numberOfColumns 3 -columnWidth 1 100 -columnWidth 2 80 -columnWidth 3 80;
text -l "Matrix:";
radioCollection;
$Matr2 = `radioButton -sl -label "2x2"`;
$Matr3 = `radioButton -label "3x3"`;
setParent -u;
//intSliderGrp -label "N. porciones" -field true -maxValue 10 -value 1 -cw 1 60 -cal 1 left -cw 2 50 Perc;
text -l "";
radioButton -edit -onCommand "$sys = 4" $Matr2;
radioButton -edit -onCommand "$sys = 9" $Matr3;
string $botonaccion = `button -w 270 -h 20 -label "Process" proces`;
showWindow Div_Mesh;
button -edit -command "Seleccionar ($sys)" $botonaccion;
global proc Seleccionar (int $typo) {
print $typo;
float $scaleuv, $moveuv;
string $Locator_nodes[] = `ls -sl -fl`;
int $leafF = size ($Locator_nodes);
print ("Numero de poligonos por hoja: " + $leafF + "
");
string $tokens[];
int $numTokens = `tokenize $Locator_nodes[0] "." $tokens`;
select -r $tokens[0];
int $totalf[] = `polyEvaluate -f`;
string $object;
ConvertSelectionToUVs;
if ($typo == 4){
$scaleuv = 0.49;
$moveuv = 0.25;
}
if ($typo == 9){
$scaleuv = 0.32;
$moveuv = 0.3333333;
}
polyEditUV -pu 0.5 -pv 0.5 -su $scaleuv -sv $scaleuv ;
for ($Sn= 0; $Sn <$typo; $Sn++){
crearLambert ("lambert_" + $Sn);
}
int $f = 0;
selectMode -component;
selectType -pf true;
// int $time = $totalf[0];
// currentTime $time;
int $totalF = $totalf[0]/$leafF;
for ($f=0; $f< $totalF; $f++)
{
int $factor = (`rand 0 ($typo)`);
// select -r ($Locator_nodes[0] + ".f[" + $f +"]");
for ($fg=0; $fg < $leafF; $fg++){
sets -e -forceElement ("lambert_" + $factor + "SG") ($tokens[0] + ".f[" + (($f * $leafF) + $fg) +"]");
}
// $time--;
// currentTime $time;
}
for ($Sn= 0; $Sn <$typo; $Sn++){
switch ($Sn){
case 0:
select -r ("lambert_" + $Sn + "SG");
ConvertSelectionToUVs;
if ($typo == 4){
polyEditUV -u -0.25 -v -0.25 ;
} else {
polyEditUV -u -0.33333 -v -0.33333 ;
}
break;
case 1:
select -r ("lambert_" + $Sn + "SG");
ConvertSelectionToUVs;
if ($typo == 4){
polyEditUV -u 0.25 -v -0.25 ;
} else {
polyEditUV -u 0 -v -0.33333 ;
}
break;
case 2:
select -r ("lambert_" + $Sn + "SG");
ConvertSelectionToUVs;
if ($typo == 4){
polyEditUV -u 0.25 -v 0.25 ;
} else {
polyEditUV -u 0.33333 -v -0.33333 ;
}
break;
case 3:
select -r ("lambert_" + $Sn + "SG");
ConvertSelectionToUVs;
if ($typo == 4){
polyEditUV -u -0.25 -v 0.25 ;
} else {
polyEditUV -u -0.33333 -v 0 ;
}
break;
case 4:
select -r ("lambert_" + $Sn + "SG");
ConvertSelectionToUVs;
polyEditUV -u 0 -v 0 ;
break;
case 5:
select -r ("lambert_" + $Sn + "SG");
ConvertSelectionToUVs;
polyEditUV -u 0.33333 -v 0 ;
break;
case 6:
select -r ("lambert_" + $Sn + "SG");
ConvertSelectionToUVs;
polyEditUV -u -0.33333 -v 0.33333 ;
break;
case 7:
select -r ("lambert_" + $Sn + "SG");
ConvertSelectionToUVs;
polyEditUV -u 0 -v 0.33333 ;
break;
case 8:
select -r ("lambert_" + $Sn + "SG");
ConvertSelectionToUVs;
polyEditUV -u 0.33333 -v 0.33333 ;
break;
}
}
}
proc crearLambert (string $shaderName)
{
if (`objExists ($shaderName + "SG")` == 0){
sets -renderable true -noSurfaceShader true -empty -name ($shaderName + "SG");
shadingNode -asShader lambert - n $shaderName;
connectAttr ($shaderName + ".outColor") ($shaderName + "SG.surfaceShader");
}
}