//////////////////////////////////////// //////////////////////////////////////// global proc changePopSizeCB() { global int $g_popSize; $g_popSize = `intFieldGrp -q -value1 "evolveWindow|params|popSizeIntFieldGrp"`; } //////////////////////////////////////// global proc initPopCB() { deleteBodies(); initPopulation(); makeBackgroundGrid(); viewFit -all front; } //////////////////////////////////////// // generate a new population of offspring based on selected few global proc nextPopCB() { deleteBodies(); generateNewGenotypes(); createPhenotypes(); makeBackgroundGrid(); viewFit -all front; } //////////////////////////////////////// // show population from a profile or front view by rotating each 90degrees global proc profileCB() { global int $g_popSize; int $state = `checkBox -q -v "evolveWindow|params|profileCheckBox"`; float $r = 0; if($state) { $r = 90; } int $i; for($i=0; $i<$g_popSize; $i++) { if($i < ($g_popSize-1)) { string $atName = "body_"+$i+".rotateY"; // CBunlockAttr $atName; // was necessary in 2.0, broke in 2.5 setAttr $atName $r; } else { setAttr "humanoidRoot.rotateY" $r; } } } //////////////////////////////////////// global proc mutationRateCB() { global float $g_mutationRate; float $val = `floatFieldGrp -q -v1 "evolveWindow|params|mutationRateFloatFieldGrp"`; //print($val+"\n"); $g_mutationRate = $val; } //////////////////////////////////////// global proc mutationChanceCB() { global float $g_mutationChance; float $val = `floatFieldGrp -q -v1 "evolveWindow|params|mutationChanceFloatFieldGrp"`; //print($val+"\n"); $g_mutationChance = $val; } //////////////////////////////////////// global proc crossoverChanceCB() { global float $g_crossoverChance; float $val = `floatFieldGrp -q -v1 "evolveWindow|params|crossoverChanceFloatFieldGrp"`; //print($val+"\n"); $g_crossoverChance = $val; } //////////////////////////////////////// // record indices of genotypes of selected bodies global proc makeSelCB() { global int $g_selection[]; // indices of selected genotypes clear($g_selection); string $selected[] = `selectedNodes`; //print("sel0="+$selected[0]+"\n"); string $regExp = "body_.*"; string $tokens[]; string $node; int $i = 0; for($node in $selected) { //print("node="+$node+"\n"); string $match = match($regExp, $node); // e.g. match = "body_12" //print("match="+$match+"\n"); tokenize($match, "_", $tokens); $g_selection[$i] = $tokens[1]; // e.g. 12; //print("added "+$g_selection[$i]+" to selection list\n"); ++$i; } } //////////////////////////////////////// global proc chooseOtherChanceCB() { global float $g_chooseOtherChance; $g_chooseOtherChance = `floatFieldGrp -q -v1 "evolveWindow|params|chooseOtherChanceFloatFieldGrp"`; } //////////////////////////////////////// global proc evolveWindow() { global float $g_mutationRate; global float $g_mutationChance; global float $g_crossoverChance; global float $g_chooseOtherChance; if((`window -ex evolveWindow`)==true) { deleteUI evolveWindow; } window -rtf true -title "Evolve Control" evolveWindow; columnLayout params; button -label "Initialize Population" -command "initPopCB" initPopButton; button -label "Make Selection" -command "makeSelCB" makeSelButton; button -label "Next Population" -command "nextPopCB" nextPopButton; checkBox -label "Profile" -cc "profileCB" profileCheckBox; intFieldGrp -cl2 "left" "left" -ct2 "left" "left" -cw2 150 25 -l "Pop Size" -v1 9 -cc "changePopSizeCB" popSizeIntFieldGrp; floatFieldGrp -cl2 "left" "left" -ct2 "left" "left" -cw2 150 25 -l "Mutation Rate" -v1 $g_mutationRate -cc "mutationRateCB" mutationRateFloatFieldGrp; floatFieldGrp -cl2 "left" "left" -ct2 "left" "left" -cw2 150 25 -l "Mutation Chance" -v1 $g_mutationChance -cc "mutationChanceCB" mutationChanceFloatFieldGrp; floatFieldGrp -cl2 "left" "left" -ct2 "left" "left" -cw2 150 25 -l "Crossover Chance" -v1 $g_crossoverChance -cc "crossoverChanceCB" crossoverChanceFloatFieldGrp; floatFieldGrp -cl2 "left" "left" -ct2 "left" "left" -cw2 150 25 -l "Choose Other Chance" -v1 $g_chooseOtherChance -cc "chooseOtherChanceCB" chooseOtherChanceFloatFieldGrp; setParent ..; showWindow evolveWindow; } evolveWindow; //////////////////////////////////////// ////////////////////////////////////////