I having having trouble with parts of my script that I am making. The script that I am making allows you to select multiple objects with the same file texture and change the color of all them only by a slight bit to make it more realistic. For example, I have 30 plants with the same green leave texture on them, it looks a bit unrealistic as they all have the same shade of green. I can select them and change the hue, saturation, value of them by slight bit and they all have slight different shades of green to make it more realistic.
I'm having trouble with select the object and applying the effect as I want to select the objects and then have Maya also select the SG and disconnect the SG from the objects and apply a new material to them. I also want Maya to assign all other files/nodes that are not attached to the color to the new material back to the same place.
Here is the code:
// Finds material of selected objects then select material of the selected object(s). hyperShade -smn; string $getMaterial[] = `ls -sl` ; select (`ls -sl`); // Create shading nodes for modification. string $myRgb = `shadingNode -asUtility rgbToHsv`; string $MD = `shadingNode -asUtility multiplyDivide`; string $myHSV = `shadingNode -asUtility hsvToRgb`; /* Figure out a way to change it to same material as selected object instead of only Blinn material. */ string $Material = `shadingNode -asShader blinn`; // Connect attribute of the new shading nodes together. connectAttr -force ($myRgb + ".outHsv") ($MD + ".input1"); connectAttr -f ($MD + ".output") ($myHSV + ".inHsv"); connectAttr -force ($myHSV + ".outRgb") ($Material + ".color"); // Disconnect material from surface shader and then connect new material to surface shader. $myMaterial = $getMaterial; select $myMaterial; /* select objects with material connected to it...(WIP) */ string $myObjectInfo[] = `ls -selection -dagObjects`; string $mySG[] = `listConnections -source true -type shadingEngine $myObjectInfo`; /* select shading group of the selected object... (WIP) */ /* disconnect shading group from material... (WIP) */ /* connect new $Material to shading group */ /* Then connect any files/nodes other than file/node that is connect to color to new material */ // Connect old material to RGB to HSV. connectAttr -force moss_blinn_shader.outColor rgbToHsv3.inRgb; // Change Hue, Saturation, and Value (XYZ) to random values (via Multiply Divide Node Input 2). select -r $MD; float $Hue = rand (0.7, 1.7); float $Saturation = rand (0.7, 1.5); float $Value = rand (0.8, 1.3); setAttr $MD+ ".input2X" $Hue; setAttr $MD+ ".input2Y" $Saturation; setAttr $MD+ ".input2Z" $Value;
Here's the image to explain more of my problem: