Showing posts with label Scripting. Show all posts
Showing posts with label Scripting. Show all posts

Sunday, August 10, 2008

Maya MEL Script - Random modifier


It helps to transform each of the selected object in a random position, rotation or scale. It can be use in an absolute or a relative transformation.



//Ventana
window -w 500 -h 700 -title "Objetos al azar" Azar1;
columnLayout -cal "left" -columnAttach "left" 5 -rowSpacing 5 -columnWidth 500;
text -l "1: Seleccionar los objetos que se quieren modificar al azar...";
text -l "2: Seleccionar le tipo de azar a aplicar.";
optionMenu -l "Aplicar azar " tipo;
menuItem -label "Relativo";
menuItem -label "Absoluto";
text -l "3: Agregar los valores MIN y MAX a modificar,\nValores 0 en los MAX no los modifica.";
text -l "Translate XYZ";
rowLayout -nc 3;
floatField -w 80 -value 0.0 mintx;
floatField -w 80 -value 0.0 minty;
floatField -w 80 -value 0.0 mintz;
setParent ..;
rowLayout -nc 3;
floatField -w 80 -value 0.0 maxtx;
floatField -w 80 -value 0.0 maxty;
floatField -w 80 -value 0.0 maxtz;
setParent ..;
text -l "Rotate XYZ";
rowLayout -nc 3;
floatField -w 80 -value 0.0 minrx;
floatField -w 80 -value 0.0 minry;
floatField -w 80 -value 0.0 minrz;
setParent ..;
rowLayout -nc 3;
floatField -w 80 -value 0.0 maxrx;
floatField -w 80 -value 0.0 maxry;
floatField -w 80 -value 0.0 maxrz;
setParent ..;
text -l "Scale XYZ";
checkBox -label "Mantener Proporciones (Valores de X)" -align "left" prop;
rowLayout -nc 3;
floatField -w 80 -value 0.0 minsx;
floatField -w 80 -value 0.0 minsy;
floatField -w 80 -value 0.0 minsz;
setParent ..;
rowLayout -nc 3;
floatField -w 80 -value 0.0 maxsx;
floatField -w 80 -value 0.0 maxsy;
floatField -w 80 -value 0.0 maxsz;
setParent ..;
setParent ..;
columnLayout -columnAttach "both" 5 -columnWidth 500;
button -label "Aplicar" -command ("aplica()");
button -label "Close" -command ("deleteUI -window Azar1");
setParent ..;
showWindow;


// Secuencia
global proc aplica() {

float $mintx = `floatField -q -value "mintx"`;
float $minty = `floatField -q -value "minty"`;
float $mintz = `floatField -q -value "mintz"`;
float $maxtx = `floatField -q -value "maxtx"`;
float $maxty = `floatField -q -value "maxty"`;
float $maxtz = `floatField -q -value "maxtz"`;

float $minrx = `floatField -q -value "minrx"`;
float $minry = `floatField -q -value "minry"`;
float $minrz = `floatField -q -value "minrz"`;
float $maxrx = `floatField -q -value "maxrx"`;
float $maxry = `floatField -q -value "maxry"`;
float $maxrz = `floatField -q -value "maxrz"`;

float $minsx = `floatField -q -value "minsx"`;
float $minsy = `floatField -q -value "minsy"`;
float $minsz = `floatField -q -value "minsz"`;
float $maxsx = `floatField -q -value "maxsx"`;
float $maxsy = `floatField -q -value "maxsy"`;
float $maxsz = `floatField -q -value "maxsz"`;

int $tipo = `optionMenu -q -select tipo`; // 1 Rel 2 Abs
int $prop = `checkBox -q -value prop`; // SI 0 NO
string $selection[] = `ls -selection`;
int $a = size($selection);

if ($tipo == 1){
for( $i = 0; $i < $a; $i++ ){
if ($maxtx == 0 && $maxty == 0 && $maxtz == 0){} else { move -r (rand($mintx, $maxtx)) (rand($minty, $maxty)) (rand($mintz, $maxtz)) $selection[$i]; }
if ($maxrx == 0 && $maxry == 0 && $maxrz == 0){} else { rotate -r (rand($minrx, $maxrx)) (rand($minry, $maxry)) (rand($minrz, $maxrz)) $selection[$i]; }
if ($maxsx == 0 && $maxsy == 0 && $maxsz == 0){} else {
if ($prop == 0){ scale -r (rand($minsx, $maxsx)) (rand($minsy, $maxsy)) (rand($minsz, $maxsz)) $selection[$i]; } else { float $rand = rand($minsx, $maxsx); scale -r $rand $rand $rand $selection[$i]; }
}
};
}

if ($tipo == 2){
for( $i = 0; $i < $a; $i++ ){
if ($maxtx == 0 && $maxty == 0 && $maxtz == 0){} else { move (rand($mintx, $maxtx)) (rand($minty, $maxty)) (rand($mintz, $maxtz)) $selection[$i]; }
if ($maxrx == 0 && $maxry == 0 && $maxrz == 0){} else { rotate (rand($minrx, $maxrx)) (rand($minry, $maxry)) (rand($minrz, $maxrz)) $selection[$i]; }
if ($maxsx == 0 && $maxsy == 0 && $maxsz == 0){} else {
if ($prop == 0){ scale (rand($minsx, $maxsx)) (rand($minsy, $maxsy)) (rand($minsz, $maxsz)) $selection[$i]; } else { float $rand = rand($minsx, $maxsx); scale $rand $rand $rand $selection[$i]; }
}
};
}

};

Wednesday, July 23, 2008

Maya MEL Script - Key Mover


Script that moves all de keys of each selected object an specific number of frames. It helps to create a sequence movements.

//Ventana
window -title "Desplazador de keys" Desplaza1;
columnLayout -columnAttach "both" 5 -rowSpacing 10 -columnWidth 250;
text -l "1. Selecciona los objetos a modificar.";
text -l "2. Cuanto se desplazan los keys";
intField -w 80 -value 1 -minValue 0 mueve;
button -label "Aplicar" -command ("aplica()");
button -label "Close" -command ("deleteUI -window Desplaza1");
showWindow;

// Secuencia de Cerecer
global proc aplica() {
string $selection[] = `ls -selection`;
int $a = size($selection);
int $mueve = `intField -q -value "mueve"`;
for( $i = 0; $i < $a; $i++ ){ select ($selection[$i]); selectKey -clear; selectKey; keyframe -e -iub true -r -o over -tc ($i * $mueve); }; };

Tuesday, May 23, 2006

2DGIF 2 3D


This is an script for 3D Studio Max v5 or near that. It takes a simple GIF image and analizes by colors, creates a 3d mesh with the differents heights depending on the pixels colors.




For example these low res GIF image like the map of Santiago de Chile.
Creates a mesh with altitude information.
Then the image can be set as material o color the vertex with the same information.