PDA

View Full Version : querying object material color


macrocosm
09-15-2005, 09:43 AM
Hi to all:-)

anyone knows how to read the RGB values of a lambert shader on a simple sphere??? I want to query them to be able to extract & control the red channel only..any ideas???

brubin
09-15-2005, 12:29 PM
{
// create a Lambert + SG
string $lamb = `shadingNode -asShader lambert` ;
sets -renderable true -noSurfaceShader true -empty -name ($lamb + "SG");
connectAttr -f ($lamb + ".outColor") ($lamb + "SG.surfaceShader") ;

// assign it a greenish color
setAttr ($lamb + ".color") -type double3 .133 .55 .123 ;

// query the color
// note: when you setAttr on a color you set 3 floats
// so this needs to be a float-array!
float $col[] = `getAttr ($lamb + ".color")` ;

// now see what we got:
print ("R: \<" + $col[0] + "\>\n") ;
print ("G: \<" + $col[1] + "\>\n") ;
print ("B: \<" + $col[2] + "\>\n") ;
// et voilá!
// hope it helps!
}

SajNT
09-17-2005, 04:00 AM
=== variable declarations =========================================
string $inputNodes[],$selObj[];
string $curObj,$shadingNode;
float $redVal;
vector $nodeColor;
//==============================================================

$redVal = 0.5; //this will be yr red value,btwn 0 - 1
$selObj = `ls -sl`; //get current selection
$selObj = `listRelatives -s $selObj[0]`; //get shapeNode of current selection
$selSG = `listConnections -t shadingEngine $selObj`; //get name of shader engine
$inputNodes = `listConnections -s 1 -d 0 $selSG`; //get material name
$shadingNode = $inputNodes[0];

$nodeColor = `getAttr ($shadingNode + ".color")`; //get color of material name
setAttr ($shadingNode + ".color") $redVal ($nodeColor.y) ($nodeColor.z); //assign it

CGTalk Moderation
09-17-2005, 04:00 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.