MoI discussion forum
MoI discussion forum

Full Version: Random color script

Show messages: All  1  2-18

From: Michael Gibson
25 Nov 2010   [#2] In reply to [#1]
Hi Pilou, I'm not actually sure what you are describing, because you mention both assigning a color randomly and at the same time you seem to be asking about assigning specific colors to types which then does not sound random to me.

There is a script that will randomize the colors of your styles though if that is of any help, that's available here:
http://moi3d.com/forum/index.php?webtag=MOI&msg=2987.2

- Michael
From: Frenchy Pilou (PILOU)
25 Nov 2010   [#3] In reply to [#2]
< a color randomly and at the same time you seem to be asking about assigning specific colors to types which then does not sound random to me.

look at the previous cube : it has different colors for the edges, and different colors for the faces
so each types has different colors in the same time ;)

In some program no random colors gives for example axes direction : red, green, blue as X,Y, Z
so you can easily see if your volumes is // to the axes :)

here it's just for artistic purpose like a Mondrian over steroïded :)

PS Thx for the remember color post :)
From: Michael Gibson
25 Nov 2010   [#4] In reply to [#3]
Hi Pilou, well right now colors in MoI are defined by styles. So if you wanted a different random color for every single edge within a solid that would mean creating a huge number of styles - one for every single edge. That's not really a very good structure...


> In some program no random colors gives for example
> axes direction : red, green, blue as X,Y, Z

Well, one problem with that is that many kinds of objects may be made up of curved edges, not only straight lines. A curved edge does not have any single direction to it like a line does.

So speaking of the "axis direction" of an edge does not really apply to the general case of any kind of edge - it's only some special subset of edges that have such a concept associated with them.

- Michael
From: Frenchy Pilou (PILOU)
25 Nov 2010   [#5] In reply to [#4]
< That's not really a very good structure

Yes but not important, it's just for "artistic purpose" result ;)
so only face or surface will be sufficient :)

Image Attachments:
exoo.jpg 


From: Michael Gibson
26 Nov 2010   [#6] In reply to [#5]
Hi Pilou, right now MoI is not really set up to generate images directly...

Is it possible for you to export your MoI model into SketchUp and then assign random colors for a screenshot inside of there? It kind of looks like you might have some method in SketchUp for that already.

- Michael
From: Frenchy Pilou (PILOU)
26 Nov 2010   [#7] In reply to [#6]
Of course yes I can ;)
It was for win a step :)
From: Michael Gibson
26 Nov 2010   [#8] In reply to [#7]
Hi Pilou, so exporting to SketchUp is probably your best bet for this - the script that would be created in MoI for full color randomization of every single sub-object would be awkward since it would involve creating a huge number of styles.

Maybe in the future there will be some way to assign a color to an object directly overriding its style assignment but currently it is not set up that way.

- Michael
From: Frenchy Pilou (PILOU)
26 Nov 2010   [#9] In reply to [#8]
No problem :)
And just one random color for a solid or by object or by object?
From: Michael Gibson
26 Nov 2010   [#10] In reply to [#9]
Hi Pilou, so I was thinking - do you really need a completely different random color for every single thing? What if it was more like 20 different base colors which were then randomly assigned? That would be a lot easier to set up because that would only involve creating 20 styles.

So the way that would work would be to first set up 20 different styles, and you can assign them the colors that you want, or use the script from here to randomize their colors:
http://moi3d.com/forum/index.php?webtag=MOI&msg=2987.2


Then you can use the following script on a shortcut key to randomly assign each face or edge to one of those styles:

script: /* Assign random styles to faces and edges */ var styles = moi.geometryDatabase.getObjectStyles(); var breps = moi.geometryDatabase.getObjects().getBReps(); for ( var i = 0; i < breps.length; ++i ) { var brep = breps.item(i); var edges = brep.getEdges(); for ( var j = 0; j < edges.length; ++j ) { edges.item(j).styleIndex = Math.floor(Math.random() * styles.length); } var faces = brep.getFaces(); for ( var j = 0; j < faces.length; ++j ) { faces.item(j).styleIndex = Math.floor(Math.random() * styles.length); } }


You can also just use this with the default set of styles as well, it will randomly assign each face or edge to one of the current style colors. Then if you want more variety add more styles.

- Michael
From: Frenchy Pilou (PILOU)
26 Nov 2010   [#11] In reply to [#10]
Thx I will see that as soon as possible :)
From: Frenchy Pilou (PILOU)
28 Nov 2010   [#12]
Works like a charme! You rocks!
http://moiscript.weebly.com/randomcolor.html
Speedy test!
Ps No problem but there is a white color who is not inside the default Style


Image Attachments:
speedytest.jpg 


From: Michael Gibson
28 Nov 2010   [#13] In reply to [#12]
Hi Pilou, I'm glad that will work for you!

> Ps No problem but there is a white color who is
> not inside the default Style

What options do you have enabled under Options > View > Lighting options, did you turn on the option for "Specular highlights" in there?

That option makes white shiny spots on objects, so turn that off.

- Michael
From: Frenchy Pilou (PILOU)
28 Nov 2010   [#14] In reply to [#13]
Yes it was some enable Metallic Lights :)
From: Frenchy Pilou (PILOU)
28 Nov 2010   [#15]
Seems Styles are losted when you export as SKP file
Is that normal?
From: Michael Gibson
28 Nov 2010   [#16] In reply to [#15]
Hi Pilou, yes currently styles are not exported to SKP format.

One reason for that was that I wasn't sure how they should be exported - SketchUp has a couple of different ways for assigning colors, there are both Layers and Materials.

I think with the previous discussion here:
http://moi3d.com/forum/index.php?webtag=MOI&msg=3790.16 it was resolved that Layers are not generally used in SketchUp so that styles should be exported as Materials. That's something that I will be trying to add in for MoI v3.

- Michael
From: Frenchy Pilou (PILOU)
28 Nov 2010   [#17] In reply to [#16]
Cool :)
From: NightCabbage
29 Nov 2010   [#18]
Hehe, yes, I'm also very interesting in coaxing Michael into adding basic rendering into MoI :)

(even for 2d stuff)

Would cut out 2 or 3 programs in my workflow LOL

Show messages: All  1  2-18