MoI discussion forum
MoI discussion forum

Full Version: Array color shades possibe?

From: Matadem
30 Mar   [#1]
Good day.
Anyone might know if it possible....lets say I have 5 objects
the first is white and the last one is black.....is there a way to get the shades in between
That the next one is 20% darker and so on until it becomes black?

Tnx!
From: Michael Gibson
30 Mar   [#2] In reply to [#1]
Hi Matadem,

re:
> lets say I have 5 objects
> the first is white and the last one is black.....is there a way to get the shades in between
> That the next one is 20% darker and so on until it becomes black?

Paste this in as the "Command" part of a shortcut key:

code:
script:
/* Set color to gradient between first and last selected objects */
var start_r = 255;
var start_g = 255;
var start_b = 255;

var end_r = 0;
var end_g = 0;
var end_b = 0;

var objs = moi.geometryDatabase.getSelectedObjects();

if ( objs.length >= 2 )
{
	var start_obj = objs.item(0);
	var end_obj = objs.item( objs.length-1 );
	var styles = moi.geometryDatabase.getObjectStyles();

	var start_color = styles.item( start_obj.styleIndex ).color;
	var end_color = styles.item( end_obj.styleIndex ).color;

	start_r = ((start_color >> 16) & 0xFF);
	start_g = ((start_color >> 8) & 0xFF);
	start_b = ((start_color >> 0) & 0xFF);

	end_r = ((end_color >> 16) & 0xFF);
	end_g = ((end_color >> 8) & 0xFF);
	end_b = ((end_color >> 0) & 0xFF);
}

function Lerp( t, low, high )
{
	return low + ((high - low) * t);
}

function GetStyle( r, g, b )
{
	var styles = moi.geometryDatabase.getObjectStyles();
	for ( var i = 0; i < styles.length; ++i )
	{
		var style = styles.item(i);
		this_r = ((style.color >> 16) & 0xFF);
		this_g = ((style.color >> 8) & 0xFF);
		this_b = ((style.color >> 0) & 0xFF);

		if ( this_r == r && this_g == g && this_b == b )
		{
			return style;
		}
	}

	return moi.geometryDatabase.addStyle( '', (r << 16) | (g << 8) | (b << 0) );
}

for ( var i = 0; i < objs.length; ++i )
{
	var t = i / (objs.length-1);
	var r = Math.round( Lerp( t, start_r, end_r ) );
	var g = Math.round( Lerp( t, start_g, end_g ) );
	var b = Math.round( Lerp( t, start_b, end_b ) );

	if ( r == 0 && g == 0 && b == 0 )
	{
		r = 1;
	}

	var style = GetStyle( r, g, b );
	var obj = objs.item(i);

	obj.styleIndex = style.index;
}


- Michael
From: Matadem
30 Mar   [#3] In reply to [#2]
Good day.
Nice! works with other colors too!
Question on the black it seems in Moi...I cannot choose black all the way it stays the default color...I always have to move it a tad up so it becomes black?

Tnx!

Image Attachments:
Nice.JPG 


From: Michael Gibson
30 Mar   [#4] In reply to [#3]
Hi Matadem, in MOI style colors control both wire color (for curves and edges) and shaded surface color.

When the color is full black it will use that for the wire color but full black for a shaded surface is usually not good it is difficult to see details.

So for the case of r,g,b = all zeros it will use wire color of r,g,b 0,0,0 but shaded surface will use white.

If you want a black shaded surface you will need to use something other than r,g,b 0,0,0 like 1,1,1 for example.

- Michael
From: BurrMan
31 Mar   [#5] In reply to [#4]
Michael,
Can you show me how to use the script?

I tried loading it and created and selected 5 spheres and ran the script and got 5 black objects. Not a gradient shade through the 5

I also set the first color default and last one black and got 5 black objects.

I think i am doing something wrong?
From: Michael Gibson
31 Mar   [#6] In reply to [#5]
Hi Burr, it might be that your spheres are not ordered in "database order".

If you draw in 5 new spheres going from left to right does that work?

- Michael
From: BurrMan
31 Mar   [#7] In reply to [#6]
Hi Michael,
It wasnt that. It was I was setting the first object to "Default" and the script turns that black.

So default to black "looks" like all objects are black

I set a new style of "Very Light Black" to Black, and the gradient appeared. If i set First to default and something like Blue, I get Black to Blue...

Anyway, figured out how to use it pproperly. Has something to do with the default color and the "Black, not really Black" Shading vs Lines thing.......
From: BurrMan
31 Mar   [#8] In reply to [#6]
"""""" "database order""""""""

Regarding this, is there a way to force a reorder in any way?
From: Michael Gibson
31 Mar   [#9] In reply to [#8]
Hi Burr,

re:
> Regarding this, is there a way to force a reorder in any way?

If you delete an object and then undo it will be at the end of the database.

- Michael