Color

Object Hierarchy | Related C++ Class: CColor

Introduced

v1.0

Description

This object represents an RGBA color. The RBGA component values are stored as double precision numbers.

Note: if a component value is greater than a signed, single-precision value, the component value is interpreted as a negative value. In most cases, the component values are normalized to the range 0 to 1. TrianglePoint.Color is an exception, and returns values in the range 0 to 255.

Other Softimage objects and properties store colors differently:

- Shaders and Softimage objects have separate Parameter objects for each color component (for example, "Scene_Material.Phong.diffuse.Green"). These component values are normalized and use double precision.

- Vertex Color properties store color component values as arrays of doubles inside a ClusterProperty.

- Wireframe colors are encoded as 10-bit values (0 to 1023), with the least significant bit ignored. Each of the R,G,B channels is 3 bits (a number from 0 to 7), and the wireframe color is encoded as B2|B1|B0|G2|G1|G0|R2|R1|R0|0|

Properties

Alpha Blue Green Red

Examples

1. JScript Example

/*
	This example shows how to create a tool for changing the
	wireframe color of an object and how to map an RGB color to
	a wireframe color.
*/ 
CreateColorizeTool();
function CreateColorizeTool()
{
	var color_tool = ActiveSceneRoot.Properties("ColorizeTool");
	if (!color_tool)
	{
		var color_tool = ActiveSceneRoot.AddCustomProperty( "ColorizeTool" );
		var wirecolor = color_tool.AddParameter( "wirecolor", siInt4 );
		wirecolor.ReadOnly = true;
		var r = color_tool.AddParameter( "R", siDouble );
		var g = color_tool.AddParameter( "G", siDouble );
		var b = color_tool.AddParameter( "B", siDouble );
		var a = color_tool.AddParameter( "A", siDouble );
		var layout = color_tool.PPGLayout ;
		layout.AddRow();
		var item = layout.AddItem( "wirecolor", "wirecolor" );
		item.SetAttribute( "NoSlider", true );
		layout.AddButton( "ColorizeObject", "Colorize object" );
		layout.EndRow();
		layout.AddGroup( "Color" );
		item = layout.AddColor( "R", "",true );
		item.SetAttribute( "NoLabel", true );
		layout.EndGroup();
		layout.Language = "JScript" ;
		layout.Logic = 
			ColorizeTool_R_OnChanged.toString() + 
			ColorizeTool_G_OnChanged.toString() + 
			ColorizeTool_B_OnChanged.toString() + 
			RGBToWireframeColor.toString() + 
			ColorizeTool_ColorizeObject_OnClicked.toString();
		layout.SetAttribute( "LogicPrefix", "ColorizeTool_" ) ;
	}
	InspectObj( color_tool, "Colorize Tool", "", siLock ); 
}
function ColorizeTool_R_OnChanged()
{
	PSet.wirecolor.ReadOnly = false;
	PSet.wirecolor.Value = RGBToWireframeColor(PSet.R.Value,PSet.G.Value,PSet.B.Value);
	PSet.wirecolor.ReadOnly = true;
}
function ColorizeTool_G_OnChanged()
{
	PSet.wirecolor.ReadOnly = false;
	PSet.wirecolor.Value = RGBToWireframeColor(PSet.R.Value,PSet.G.Value,PSet.B.Value);
	PSet.wirecolor.ReadOnly = true;
}
function ColorizeTool_B_OnChanged()
{
	PSet.wirecolor.ReadOnly = false;
	PSet.wirecolor.Value = RGBToWireframeColor(PSet.R.Value,PSet.G.Value,PSet.B.Value);
	PSet.wirecolor.ReadOnly = true;
}
function ColorizeTool_ColorizeObject_OnClicked()
{
	var color = PSet.wirecolor.Value;
	var o = null;
	var siRMB = 0;
	var button = -1, modifier;
	while ( o==null && button != siRMB )
	{
		Application.StatusBar ="Pick object to colorize";
		var rtn = PickObject( "Select object", "");
		o = rtn.Value("PickedElement");
		button = rtn.Value("ButtonPressed");
		modifier = rtn.Value("ModifierPressed");
	}
	if ( button == siRMB )
		return;
	var display = o.Properties("Display");
	if (display.isa(siSharedPSet))
	{
		display = MakeLocal( display, siNodePropagation )(0);
	}
	display.wirecol.Value = color;
	return color;
}
// Convert wireframe color index to double-precision RGB color
function WireframeColorToRGB(lWireframeColor)
{
	var aColor = new Array(3);
	aColor[0] = ((lWireframeColor >>> 1) & 0x7)/7;
	aColor[1] = ((lWireframeColor >>> 4) & 0x7)/7;
	aColor[2] = ((lWireframeColor >>> 7) & 0x7)/7;
	return aColor;
}
// Convert double-precision RGB color to wireframe color index
function RGBToWireframeColor(dR,dG,dB)
{
	// Convert RGB to wirecolor
	var wirecolR, wirecolG, wirecolB;
	wirecolR = (Math.round(dR * 7)) << 1
	wirecolG = (Math.round(dG * 7)) << 4
	wirecolB = (Math.round(dB * 7)) << 7
	return wirecolR | wirecolG | wirecolB;
}

2. VBScript Example

set oSpot = GetValue("Scene_Root").AddLightRig("Spot").Light
set oColor = oSpot.OGLLight.Color
Application.LogMessage "color: " & oColor.Red & ", " & oColor.Green & ", " & oColor.Blue & ", " & oColor.Alpha

See Also

ColorizeObject TrianglePoint.Color Triangle OGLLight.Color OGLMaterial Light Envelope.GetDeformerColor