Adverti horiz upsell

Noise modifier 1.0.0 for Maya (maya script)

an interactive full of options noise modifier for Maya

License
Button download
1,245 Downloads

Compatibility

  • 2010

Operating Systems

  • Windows

History

Created:12/26/2009
Last Modified:12/26/2009
File Size: 1.98 MB

Keywords

modifier

Bugs

Fix the upload

Statuspending
Priorityhigh
Date02/08/2010
Submitted bypants duck pants duck
I'm new to scripting (so I might be doing something wrong), but it took some effort to get this to actually work. The script doesn't work as-is because it's in RTF format. If you copy the text from the RTF file into a plain text file, rename it to *.mel, and delete the excess characters it works just fine. I'm using an older version of Maya, so this might not be an issue with newer versions at all.

Here's the working script, which you can copy directly:

/*
 NOISE MODIFIER
    BY MAX
*/


// MAIN WINDOW CREATION

string $NoiseMainWindow = "NoiseMainWindow";
if(`window -exists $NoiseMainWindow` == 1) deleteUI $NoiseMainWindow;
window -title "Noise v 1.0 by Max" $NoiseMainWindow;

string $windowFormLayout = `formLayout -numberOfDivisions 100`;

 text -label "Displace X" "ldispx0";
 floatField -value -1.0 "fdispx0";
 floatField -value 1.0 "fdispx1";

 text -label "Displace Y" "ldispy0";
 floatField -value -1.0 "fdispy0";
 floatField -value 1.0 "fdispy1";

 text -label "Displace Z" "ldispz0";
 floatField -value -1.0 "fdispz0";
 floatField -value 1.0 "fdispz1";

 checkBox -label "Along Normal" -value 0 "cbNormal";

 separator -style "in" "sep1";

 checkBox -label "Pin Selected Vertices" -value 1 "cbPinSel";

 checkBox -label "Pin Override Maps" -value 1 "cbPinOM";

 separator -style "in" "sep1_2";

 text -l "X Map" "lxmap";

 textField -text "" "tfxm";

 button -l "open" -command ("nmw_Button_OpenMap(0)") "bxmo";

 text -l "Y Map" "lymap";

 textField -text "" "tfym";

 button -l "open" -command ("nmw_Button_OpenMap(1)") "bymo";

 text -l "Z Map" "lzmap";

 textField -text "" "tfzm";

 button -l "open" -command ("nmw_Button_OpenMap(2)") "bzmo";

 checkBox -l "Image-Based Displace" -v 0 "cbibd";

 separator -style "in" "sep1_3";

 button -label "Noise" -command ("nmw_Button_Noise") "bnoise";

 separator -style "in" "sep2";

 attrFieldSliderGrp -en 0 -cat 1 "left" 0 -cw 1 10 -min 0.0 -max 1.0 -l "X" "fsgDX"; 
 attrFieldSliderGrp -en 0 -cat 1 "left" 0 -cw 1 10 -min 0.0 -max 1.0 -l "Y" "fsgDY"; 
 attrFieldSliderGrp -en 0 -cat 1 "left" 0 -cw 1 10 -min 0.0 -max 1.0 -l "Z" "fsgDZ"; 

 formLayout -edit

 -attachForm "ldispx0" "top" 0
 -attachForm "ldispx0" "left" 0
 -attachNone "ldispx0" "right"
 -attachNone "ldispx0" "bottom"

 -attachForm "fdispx0" "top" 0
 -attachControl "fdispx0" "left" 5 "ldispx0"
 -attachNone "fdispx0" "right"
 -attachNone "fdispx0" "bottom"

 -attachForm "fdispx1" "top" 0
 -attachControl "fdispx1" "left" 5 "fdispx0"
 -attachNone "fdispx1" "right"
 -attachNone "fdispx1" "bottom"

 -attachControl "ldispy0" "top" 5 "ldispx0"
 -attachForm "ldispy0" "left" 0
 -attachNone "ldispy0" "right"
 -attachNone "ldispy0" "bottom"

 -attachOppositeControl "fdispy0" "top" 0 "ldispy0"
 -attachControl "fdispy0" "left" 5 "ldispy0"
 -attachNone "fdispy0" "right"
 -attachNone "fdispy0" "bottom"

 -attachOppositeControl "fdispy1" "top" 0 "fdispy0"
 -attachControl "fdispy1" "left" 5 "fdispy0"
 -attachNone "fdispy1" "right"
 -attachNone "fdispy1" "bottom"

 -attachControl "ldispz0" "top" 5 "ldispy0"
 -attachForm "ldispz0" "left" 0
 -attachNone "ldispz0" "right"
 -attachNone "ldispz0" "bottom"

 -attachOppositeControl "fdispz0" "top" 0 "ldispz0"
 -attachControl "fdispz0" "left" 5 "ldispz0"
 -attachNone "fdispz0" "right"
 -attachNone "fdispz0" "bottom"

 -attachOppositeControl "fdispz1" "top" 0 "fdispz0"
 -attachControl "fdispz1" "left" 5 "fdispz0"
 -attachNone "fdispz1" "right"
 -attachNone "fdispz1" "bottom"

 -attachControl "cbNormal" "top" 10 "ldispz0"
 -attachForm "cbNormal" "left" 5
 -attachNone "cbNormal" "right"
 -attachNone "cbNormal" "bottom"

 -attachControl "sep1" "top" 5 "cbNormal"
 -attachForm "sep1" "left" 0
 -attachForm "sep1" "right" 0
 -attachNone "sep1" "bottom"

 -attachControl "cbPinSel" "top" 5 "sep1"
 -attachForm "cbPinSel" "left" 5
 -attachNone "cbPinSel" "right"
 -attachNone "cbPinSel" "bottom"

 -attachControl "cbPinOM" "top" 5 "cbPinSel"
 -attachForm "cbPinOM" "left" 5
 -attachForm "cbPinOM" "right" 0
 -attachNone "cbPinOM" "bottom"

 -attachControl "sep1_2" "top" 5 "cbPinOM"
 -attachForm "sep1_2" "left" 0
 -attachForm "sep1_2" "right" 0
 -attachNone "sep1_2" "bottom"




 -attachControl "lxmap" "top" 5 "sep1_2"
 -attachForm "lxmap" "left" 10
 -attachNone "lxmap" "right"
 -attachNone "lxmap" "bottom"

 -attachOppositeControl "tfxm" "top" 0 "lxmap"
 -attachControl "tfxm" "left" 5 "lxmap"
 -attachControl "tfxm" "right" 5 "bxmo"
 -attachNone "tfxm" "bottom"

 -attachOppositeControl "bxmo" "top" 0 "lxmap"
 -attachNone "bxmo" "left"
 -attachForm "bxmo" "right" 5
 -attachNone "bxmo" "bottom"

 -attachControl "lymap" "top" 15 "lxmap"
 -attachForm "lymap" "left" 10
 -attachNone "lymap" "right"
 -attachNone "lymap" "bottom"

 -attachOppositeControl "tfym" "top" 0 "lymap"
 -attachControl "tfym" "left" 5 "lymap"
 -attachControl "tfym" "right" 5 "bymo"
 -attachNone "tfym" "bottom"

 -attachOppositeControl "bymo" "top" 0 "lymap"
 -attachNone "bymo" "left"
 -attachForm "bymo" "right" 5
 -attachNone "bymo" "bottom"

 -attachControl "lzmap" "top" 15 "lymap"
 -attachForm "lzmap" "left" 10
 -attachNone "lzmap" "right"
 -attachNone "lzmap" "bottom"

 -attachOppositeControl "tfzm" "top" 0 "lzmap"
 -attachControl "tfzm" "left" 5 "lzmap"
 -attachControl "tfzm" "right" 5 "bzmo"
 -attachNone "tfzm" "bottom"

 -attachOppositeControl "bzmo" "top" 0 "lzmap"
 -attachNone "bzmo" "left"
 -attachForm "bzmo" "right" 5
 -attachNone "bzmo" "bottom"

 -attachControl "cbibd" "top" 15 "lzmap"
 -attachForm "cbibd" "left" 5
 -attachNone "cbibd" "right"
 -attachNone "cbibd" "bottom"

 -attachControl "sep1_3" "top" 15 "cbibd"
 -attachForm "sep1_3" "left" 0
 -attachForm "sep1_3" "right" 0
 -attachNone "sep1_3" "bottom"




 -attachControl "bnoise" "top" 5 "sep1_3"
 -attachForm "bnoise" "left" 0
 -attachNone "bnoise" "right"
 -attachNone "bnoise" "bottom"

 -attachControl "sep2" "top" 5 "bnoise"
 -attachForm "sep2" "left" 0
 -attachForm "sep2" "right" 0
 -attachNone "sep2" "bottom"

 -attachControl "fsgDX" "top" 5 "sep2"
 -attachForm "fsgDX" "left" 0
 -attachNone "fsgDX" "right"
 -attachNone "fsgDX" "bottom"

 -attachControl "fsgDY" "top" 0 "fsgDX"
 -attachForm "fsgDY" "left" 0
 -attachNone "fsgDY" "right"
 -attachNone "fsgDY" "bottom"

 -attachControl "fsgDZ" "top" 0 "fsgDY"
 -attachForm "fsgDZ" "left" 0
 -attachNone "fsgDZ" "right"
 -attachNone "fsgDZ" "bottom"

 $windowFormLayout;

showWindow $NoiseMainWindow;

////////////////////////////////////////////////////////////////////////////////////////////////////


proc nmw_Button_Noise() {

 // GET SELECTION

 string $AllObjects[] = `ls -sl -fl`;
 int $objs = size($AllObjects);
 if($objs == 0) error "Please select at least one object or a vertex";

 int $Pin_a[];
 clear $Pin_a;

 int $verticesselected = 0;

 // GET PARAMS FROM MAIN WINDOW

 int $pinselected = `checkBox -q -value "cbPinSel"`;
 int $normalmove = `checkBox -q -value "cbNormal"`;
 int $pinovermap = `checkBox -q -value "cbPinOM"`;
 int $ibd = `checkBox -q -value "cbibd"`;

 // CHECK IF WE HAVE SELECTED AN OBJECT OR ITS VERTICES

 string $buffer[];
 int $tokens = `tokenize $AllObjects[0] "." $buffer`;

 string $obj;

 int $i;

 // WITH VERTICES SELECTED SAVE THEM IN AN ARRAY

 if($tokens > 1) {
 $verticesselected = 1;
 $obj = $buffer[0];

 for($i = 0; $i < $objs; $i++) {
 tokenize $AllObjects[$i] "." $buffer;
 $Pin_a[$i] = `substring $buffer[1] 5 (size($buffer[1]) - 1)`;
}

} else $obj = $AllObjects[0];

 // GET DISPLACEMENT VALUES FROM MAIN WINDOW

 float $dispx0 = `floatField -q -v "fdispx0"`;
 float $dispy0 = `floatField -q -v "fdispy0"`;
 float $dispz0 = `floatField -q -v "fdispz0"`;

 float $dispx1 = `floatField -q -v "fdispx1"`;
 float $dispy1 = `floatField -q -v "fdispy1"`;
 float $dispz1 = `floatField -q -v "fdispz1"`;

 // CREATE 3 DUPLICATES OF OBJECT AND HIDE THEM

 string $target[3];

 string $temptarget[] = `duplicate -rr -n "Xdisp" $obj`;
 $target[0] = $temptarget[0];
 hide $target[0];

 $temptarget = `duplicate -rr -n "Ydisp" $obj`;
 $target[1] = $temptarget[0];
 hide $target[1];

 $temptarget = `duplicate -rr -n "Zdisp" $obj`;
 $target[2] = $temptarget[0];
 hide $target[2];

 int $vtcs_a[] = `polyEvaluate -v $obj`;
 int $vtcs = $vtcs_a[0];

 // MOVE VERTICES OF DUPLICATES ACCORDING TO CHOOSEN KIND OF MODIFIER
 // 1) ALL 3 AXES, ONE AXES EACH DUPLICATE
 // 2) NORMAL ONLY FIRST DUPLICATE
 // 3) NORMAL FOR FIRST TARGET, -NORMAL FOR SECOND

 if($ibd == 0) {
 for($i = 0; $i < $vtcs; $i++) {

 float $fx = `rand $dispx0 $dispx1`;

 if($normalmove == 0) {
 float $fy = `rand $dispy0 $dispy1`;
 float $fz = `rand $dispz0 $dispz1`;

 move -r $fx 0 0 ($target[0] + ".vtx[" + $i + "]");
 move -r 0 $fy 0 ($target[1] + ".vtx[" + $i + "]");
 move -r 0 0 $fz ($target[2] + ".vtx[" + $i + "]");

} else moveVertexAlongDirection -n $fx ($target[0] + ".vtx[" + $i + "]");
}
} else {
 for($i = 0; $i < $vtcs; $i++) {
 moveVertexAlongDirection -n $dispx0 ($target[0] + ".vtx[" + $i + "]");
 moveVertexAlongDirection -n (-1 * $dispx0) ($target[1] + ".vtx[" + $i + "]");
}
}

 // ASSIGN DUPLICATES TO MAIN OBJECT AS BLEND SHAPES

 string $tempblendshape[] = `blendShape -tc 0 $target[0] $target[1] $target[2] $obj`;
 string $blendshape = $tempblendshape[0];
 blendShape -e -w 0 1 -w 1 1 -w 2 1 $blendshape;


 // IF WE HAVE CHOOSEN MAPS LOAD THEM

 int $mapused = 0;

 if(`textField -q -text "tfxm"` != "") {
 $mapused = 1;
 select -r $obj;
 source "artAttrBlendShapeCallback";
 ArtPaintBlendShapeWeightsTool;
 string $tool = "artAttrBlendShapeContext";
 setToolTo $tool;
 artBlendShapeSelectTarget "artAttrCtx" "Xdisp";
 artImportAttrMapCB artAttrCtx (`textField -q -text "tfxm"`) "image";
}

 if(`textField -q -text "tfym"` != "") {
 if($mapused == 0) {
 $mapused = 1;
 select -r $obj;
 source "artAttrBlendShapeCallback";
 ArtPaintBlendShapeWeightsTool;
 string $tool = "artAttrBlendShapeContext";
 setToolTo $tool;
}
 artBlendShapeSelectTarget "artAttrCtx" "Ydisp";
 artImportAttrMapCB artAttrCtx (`textField -q -text "tfym"`) "image";
}

 if(`textField -q -text "tfzm"` != "") {
 if($mapused == 0) {
 $mapused = 1;
 select -r $obj;
 source "artAttrBlendShapeCallback";
 ArtPaintBlendShapeWeightsTool;
 string $tool = "artAttrBlendShapeContext";
 setToolTo $tool;
}
 artBlendShapeSelectTarget "artAttrCtx" "Zdisp";
 artImportAttrMapCB artAttrCtx (`textField -q -text "tfzm"`) "image";
}

 // IF WE HAVE CHOOSEN IMAGE BASED DISPLACEMENT ADJUST WEIGHTS ON FIRST TWO BLEND TARGETS' VERTICES
 // FIRST ACCORDING TO CHOOSEN MAP
 // SECOND AS INVERSE

 if($ibd == 1) {

 for($i = 0; $i < $vtcs; $i++) {
 float $exval = `getAttr ($blendshape + ".inputTarget[0].inputTargetGroup[0].targetWeights[" + $i + "]")`;
 $exval = 1.0 - $exval;
 setAttr -size 1 ($blendshape + ".inputTarget[0].inputTargetGroup[1].targetWeights[" + $i + "]") $exval;
}
}

 // PIN SELECTED VERTICES IF WE WANTED TO

 if($verticesselected == 1 && $pinselected == 1) {
 if(($mapused == 1 && $pinovermap == 1) || $mapused == 0) {
 for($i = 0; $i < $objs; $i++) {
 setAttr -size 1 ($blendshape + ".inputTarget[0].inputTargetGroup[0].targetWeights[" + $Pin_a[$i] + "]") 0.0;
 setAttr -size 1 ($blendshape + ".inputTarget[0].inputTargetGroup[1].targetWeights[" + $Pin_a[$i] + "]") 0.0;
 setAttr -size 1 ($blendshape + ".inputTarget[0].inputTargetGroup[2].targetWeights[" + $Pin_a[$i] + "]") 0.0;
}
}
}

 // SET THE 3 SLIDERS AND DELETE BLEND TARGETS

 attrFieldSliderGrp -e -en 1 -at ($blendshape + "." + $target[0]) "fsgDX"; 
 attrFieldSliderGrp -e -en 1 -at ($blendshape + "." + $target[1]) "fsgDY"; 
 attrFieldSliderGrp -e -en 1 -at ($blendshape + "." + $target[2]) "fsgDZ"; 
 delete $target[0];
 delete $target[1];
 delete $target[2];
}


// A SIMPLE FILE CHOOSE DIALOG

proc nmw_Button_OpenMap(int $whichMap) {

 string $ts = `fileDialog -m 0`;

 switch($whichMap) {
 case 0:
 textField -e -text $ts "tfxm";
 break;
 case 1:
 textField -e -text $ts "tfym";
 break;
 default:
 textField -e -text $ts "tfzm";
 break;
}


}

Post a comment: