FORUMS: list search recent posts

Mel Gui

COW Forums : Autodesk Maya

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
Jacqueline Johnsen
Mel Gui
on Aug 18, 2011 at 1:01:34 pm

Hey guys,

I’m working on this project where I’ll have an adjustable low poly female who’ll eventually have adjustable hair, clothes , body proportions and textures.

Now I want to create a gui with melscript so I’m testing it with adjusting the color of my skin material:

{
// window
window -title "GUI";
columnLayout;

// attach colors to skin material
attrColorSliderGrp -label "Hue" - hsv 1 0 0 -at ("SkinMat.color");
attrColorSliderGrp -label "Saturation" - hsv 0 1 0 -at ("SkinMat.color");

showWindow;

}


But I ran into 2 major problems.
1: the gui treads both sliders as the same. (the can't move separately)
2: It doesn’t like me adding a third attribute which would be:
attrcolorSliderGrp -label "Value" -hsv 0 0 1 -at ("SkinMat.color");

Why?? I don’t get it. And yes I’m a n00b with melscript. I’m actually happy I got this far. XD
But yeah, really stuck now and the interweb’s not really helping either…

If anyone can shed some light it be greatly appreciated! ^^


Return to posts index

Steve Sayer
Re: Mel Gui
on Aug 18, 2011 at 2:40:55 pm

Hi, Jacqueline. Congrats on making it this far with MEL! Interfaces can be daunting.

The problem is that you have specified the same attribute, 'SkinMat.color', for both sliders. This hooks them both up to the same attribute, so when one changes, the other changes. Maya is expecting to use a single colour slider to control the colour, not a group of three.

You've also slightly misunderstood the '-hsv' flag. It's not used to choose which colour property the slider should control; rather, it is used to set the default colour of the attribute. So "-hsv 1 0 0" would be black... "-hsv 0 0 1" would be white (the first digit is Hue, the second is Saturation, and the last one is Value). It's generally a little easier to use the "-rgb" flag instead, and specify default values for Red, Green and Blue channels.

Can you live with just one slider? Keep in mind that if a user clicks on the color swatch, that will open the Color Picker window, which allows better freedom when choosing colours.

Hope that helps,

-Steve


Return to posts index

Jacqueline Johnsen
Re: Mel Gui
on Aug 18, 2011 at 3:51:25 pm

Ah, that explain a lot. ^^ Thanks Steve!
However I want to have full control! Eventually I want to get rid of the color swatch and limit the 0-1 range.
For now I’ll settle with a working color slide though. I’ve changed the usv to rgb and I added a specular slide (who doesn’t give me grief). However the rgb slide doesn’t work. I can set the initial color to any color I’d like. But when I use the slide it goes to white and black and will leave all colors out. So the slider is pretty much useless…

{
// create window
window -title "Attribute Controls";
columnLayout;

// sliders
attrColorSliderGrp -label "Color" - rgb 1 .8 .6 -at ("SkinMat.color");
attrColorSliderGrp -label "Specular" -at ("SkinMat.specularColor ");


showWindow;
}

Changing SkinMat (shader material) into a variable won’t help me, will it? Is that even possible?
Maybe I need to use something else then the attrColorSliderGrp…
Well… at least the specular works.. ^^
*continues fighting Maya*


Return to posts index



Steve Sayer
Re: Mel Gui
on Aug 18, 2011 at 6:22:38 pm

Hmm, your code seems to work fine for me when I test it... Nothing is limited to black and white. I wonder if the problem is that you still have an older version of the window floating around in Maya's memory somewhere, creating a conflict? Try restarting Maya if you haven't done so lately.

Regarding your desire to have 'full control,' do keep in mind that clicking on the swatch brings up the Color Picker interface, which gives your user all the control they could need. It's good to explore different challenges as a way of learning MEL, but don't beat your head against a brick wall for too long!

If you are determined to accomplish this... here's the route I would take. The problem is that Maya stores all colour attributes in RGB format. So you won't be able to just hook up those sliders directly. You'll need a node to convert from the HSV values of your 3 custom sliders to the RGB values of the actual colour attribute.

Such a node does exist, and it is called 'hsvToRgb', found under the 'Color Utilities' section. Map one of these nodes to the color channel of your skin material, then create your custom sliders and hook them up to the hsvToRgb node instead of hooking them directly to the material node. Your code should look like this:

attrFieldSliderGrp -label "Hue" -at ("hsvToRgb1.inHsvR");
attrFieldSliderGrp -label "Sat" -at ("hsvToRgb1.inHsvG");
attrFieldSliderGrp -label "Val" -at ("hsvToRgb1.inHsvB");

Hope that helps.

-Steve


Return to posts index

Jacqueline Johnsen
Re: Mel Gui
on Aug 30, 2011 at 1:25:58 pm

Thank you so much! I finaly got it! Full controll of the skin color!
However turns out the attrColorSliderGrp for the specular can't have min and max values. I don't think I can use the HSV Trick... any suggestions?

{
// create window
window -title "GUI";
columnLayout;

// Skin attributes
attrFieldSliderGrp -label "Red-Yellow" -minValue 15 -maxValue 40 -at ("hsvToRgb1.inHsvR");
attrFieldSliderGrp -label "Gray-Saturated" -minValue 0.2 -maxValue 0.5 -at ("hsvToRgb1.inHsvG");
attrFieldSliderGrp -label "Dark-Light" -minValue 0.2 -maxValue 1 -at ("hsvToRgb1.inHsvB");
attrColorSliderGrp -label "Skin Specular" -at ("SkinMat.specularColor ");


// Cloth attributes
attrColorSliderGrp -label "ClothColor" - rgb 0.5 0.5 1 -at ("ClothMat.color");

showWindow;
}


Return to posts index

Steve Sayer
Re: Mel Gui
on Aug 30, 2011 at 1:44:54 pm

It seems you're correct, Jacqueline; since the colour slider is expected to be used with colour attributes specifically, its built-in default min and max are 0 and 1.

Yes, there are some workarounds you could try, if it's really important to you to be able to specify those values.

First, I don't see why you couldn't use the same HSV trick for the specular colour that you did for the base colour. This would give you three sliders for specular just as you have three sliders for colour.

Second, you could decide that the user doesn't really need to specify the saturation or hue of the specular colour; just the value (brightness). Then you could provide just a single slider to control the value, leaving the hue and saturation at preset values. Optionally, you could actually build some connections between the base colour and the spec colour, so that as the base colour hue shifts towards red, for example, the spec colour hue does as well. The user wouldn't control this, but it might result in a better look for the shader.

Finally, you could look into using 'clamp' nodes to limit slider values, and/or try to program in some expressions to limit the values involved. I don't know if either of these solutions will result in a good experience for the user, though. I'm picturing a slider that restricts values to, say, the 0.5-0.8 range, so that if you drag the slider too far to the left or right, it snaps back to those extremes. That's not very good interface design.

Hope something in there helps! Good luck!

-Steve


Return to posts index


Jacqueline Johnsen
Re: Mel Gui
on Aug 31, 2011 at 10:02:27 am

That helps alot. Haven't looked at the clamp nodes yet, but I added another HSVtoRGB and that worked fine... I forgot you link it with color so that's why I couldn't use it. But just create another node and link it through specular and voila!
My skin controlls are done!!

I'll post them here for other people who might want to use it. It's:

if ( `window -exists MyGuiWindow` ) {
deleteUI MyGuiWindow;
}

{
// create window
window -title "GUI" MyGuiWindow;
columnLayout;

// Skin attributes
text -l "Skin";
attrFieldSliderGrp -label "Red Skin – Yellow Skin" -minValue 15 -maxValue 40 -at ("hsvToRgb1.inHsvR");
attrFieldSliderGrp -label "Saturation" -minValue 0.2 -maxValue 0.5 -at ("hsvToRgb1.inHsvG");
attrFieldSliderGrp -label "Dark-Light Skin" -minValue 0.2 -maxValue 1 -at ("hsvToRgb1.inHsvB");
attrFieldSliderGrp -label " Dry – Greasy Skin " -minValue 0.0 -maxValue .3 -at ("hsvToRgb3.inHsvB");

showWindow MyGuiWindow;
}

(Yeah also added some text and a remove the old window script.)

Remember if you use this: don't forget to add 2 HSVToRGB nodes to your skin material and link them by color and by specular.
Think that should work! Thank you Steve Sayer!!
And on to the next challenge!!


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]