Gradientcontrol Example

The Maya docs have quite a lack of explanations for creating the gradientControl item. There are no examples and its tricky to dig it all by yourself. So maybe we can put forces together here and work out a good and solid solution.: Is really something I'm not completely familiar with, so please correct me if I'm talking crap .

We use these controls for particle-System attributes so I can only talk about 1 of the 3 in the docs described modes of the gradientControl: But I think its the most common one:

  1. the one where the control will automatically detect if it has to be a ramp or graph accordingly.

The first important thing about the gradientControl is that you can only run it connected to an attribute. Plus: The attribute has to have special children attributes.

Here an example for a graph-gradientControl:
CODE
{
   // first we need any object to add the attribute to:
   string $obj[] = polyCube;
   string $attrName = "test";

   // then we add this to the object:
   addAttr -ln ($attrName) -numberOfChildren 3 -at compound -multi $obj[0];
   addAttr -sn ($attrName + "Pos") -at "float" -parent $attrName $obj[0];
   addAttr -sn ($attrName + "Value") -at "float" -parent $attrName $obj[0];
   addAttr -sn ($attrName + "Interpolation") -at "enum" -parent $attrName $obj[0];
   addAttr -sn ($attrName + "MinVal") -at "float" $obj[0];
   addAttr -sn ($attrName + "MaxVal") -at "float" $obj[0];

   // now we can open a simple window that contains a control for this attributes:
   if (window -ex testWin) deleteUI testWin;
   window testWin;
   columnLayout;
   gradientControl -at ($obj[0] + "." + $attrName) -h 75 testRamp;
   showWindow testWin;
}
Now you should be able to make something like this:
400) {this.resized=true; this.width=400; this.alt='Click here to open new window';}" onmouseover="if(this.resized) this.style.cursor='hand';" onclick="if(this.resized) {window.open('http://show.imagehosting.us/show/796268/0/nouser_796/T0_-1_796268.gif');}" />

If you want to have other interpolations than stepped. You got to add an -enumName argument to the "Interpolation"-attribute you set before. I don't know what else you can do but for instance withCODE
addAttr -sn ($attrName + "Interpolation") -at "enum" -enumName "Linear:Spline" -parent $attrName $obj[0];
you have linear interpolation.

Now here an example for a ramp-gradientControl:
We can have exactly the same code and only change the attributes we add to see the difference.:
CODE
{
   string $obj[] = polyCube;
   string $attrName = "test";

   addAttr -ln ($attrName) -numberOfChildren 3 -at compound -multi $obj[0];
   addAttr -sn ($attrName + "Pos") -at "float" -parent $attrName $obj[0];
   addAttr -sn ($attrName + "Value") -at "float3" -parent $attrName -storable 1 $obj[0];
   addAttr -sn ($attrName + "ValueR") -at "float" -parent ($attrName + "Value") $obj[0];
   addAttr -sn ($attrName + "ValueG") -at "float" -parent ($attrName + "Value") $obj[0];
   addAttr -sn ($attrName + "ValueB") -at "float" -parent ($attrName + "Value") $obj[0];
   addAttr -sn ($attrName + "Interpolation") -at "enum" -enumName "Linear:Spline" -parent $attrName $obj[0];

   if (window -ex testWin) deleteUI testWin;
   window testWin;
   columnLayout;
   gradientControl -at ($obj[0] + "." + $attrName) -h 75 testRamp;
   showWindow testWin;
}
This should create something like this:
400) {this.resized=true; this.width=400; this.alt='Click here to open new window';}" onmouseover="if(this.resized) this.style.cursor='hand';" onclick="if(this.resized) {window.open('http://show.imagehosting.us/show/796400/0/nouser_796/T0_-1_796400.gif');}" />

Now the problem here is we can define where in the ramp a "color" can be, but not what color. We need an extra control thats connected to the marker you just selected: Add a attrColorSliderGrp before the gradientControl:CODE
string $colorControl = attrColorSliderGrp -label "color";
and connect the gradientControl to it this way: CODE
gradientControl -at ($obj[0] + "." + $attrName) -selectedColorControl $colorControl testRamp;

now this could be the result:
400) {this.resized=true; this.width=400; this.alt='Click here to open new window';}" onmouseover="if(this.resized) this.style.cursor='hand';" onclick="if(this.resized) {window.open('http://show.imagehosting.us/show/796433/0/nouser_796/T0_-1_796433.jpg');}" />
You can have nice Jamaica-color-gradients and everything else.
Of course you can add such extra controls for every other attribute at the graph-gradientControl (e.g. position of a marker) as well. See the docs for this. It should be simple now.

hope that helps a little. And please comment on this! I'm talking to you geeks

Nice. Make it a bit more elaborate and put it into tutorials section.

an API example....

http://robthebloke.org/mayaapi.html#7

(the ramp attribute example)

QUOTE(failure @ 10/13/05, 05:00 AM)
Nice. Make it a bit more elaborate and put it into tutorials section.
[snapback]217218[/snapback]

hmm.. yea.. that would be cool to have. Hope I have time soon. This was quite fast hacked together. You are right there's still a lot to tell about this stuff.

Maybe you have some ideas what to do with it in Maya, so we can add a "practical" example instead of "how to just show it the fast way"