PDA

View Full Version : Stuck on connecting shader attributes in an array


micalclark
10-07-2010, 12:43 AM
I'm trying to write a script that I would think isn't that complex, but I'm not much of a programmer. I've got a character in Maya that has a lot of materials set up that just contain color info on the ambient channel. I'd like to be able to apply a toon shader to the color input that derives it's color from the ambient channel that is already set up.

So on a step by step basis I am creating an array using the existing shaders, creating the toon shader for each. Connecting the toon shader output to the color channel of the original shader (this is where I'm stuck)

Hoping to eventually connect the ambientColor output of the original shader to the ramp color inputs of the toon shaders using various percentages of the color to create the light to dark gradient, but haven't gotten anywhere near that far yet.

My code so far:

string $materials[ ] = `ls -sl`; //having selected the original shaders sets up an array
string $i; //a variable for incrementing through the array

for ($i in $materials)
{
assignToonShader "threeToneBrightness"; //creates the toon shader(this works fine up to here)
connectAttr -f "threeToneBrightnessShader.outColor" "$materials[$i].color";
};

I'm not sure how to get the connection into the original shader. Have tried several variations on the $materials[$i].color input like just putting the $i or just the $i in brackets. Even tried simplifying it to the point where there's only one item in the array and using "$materials[0].color" but always get an error. Usually to the effect of cannot find input "whatever I tried here.color".

Anyway, if someone's more familiar than me with scripting shaders I'd appreciate any help. Thanks and all the best.

rahulsg2901
10-07-2010, 05:52 AM
string $materials[ ] = `ls -sl`; //having selected the original shaders sets up an array
string $i; //a variable for incrementing through the array

for ($i in $materials)
{
assignToonShader "threeToneBrightness"; //creates the toon shader(this works fine up to here)
connectAttr -f "threeToneBrightnessShader.outColor" ($i + ".color");
};



You quote the variable right syntax is this & for loop you donít have to put $materials[$i] just put $i

micalclark
10-07-2010, 09:05 PM
Thanks so much Rahul. That was definitely helpful, and figured out most of the rest of it from there. Cheers,

Mike

rahulsg2901
10-08-2010, 07:34 AM
welcome :beer:

CGTalk Moderation
10-08-2010, 07:34 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.