How to Randomly assign specified colors from Styles to faces & edges?
I found the following script that comes close to what I need.
Randomly assign colors from Styles to faces & edges:
http://moi3d.com/forum/lmessages.php?webtag=MOI&msg=3876.10
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); } }
But is there a way to specify just a subset of colors from the Styles?
This is because some Styles may already be assigned to other objects in the scene and need to remain unique.
A use case, for example, would be a wooden ship where perhaps a hundred wood planks are used. To give a more natural look in the render program, say 5 unique wood shades & textures are pre-defined in the render program. These 5 wood variations get assigned based on 5 pre-defined colors assigned randomly throughout all the planks in MoI.
Taking it one step further, making a more universal script, how about if the user “seeds” the model with perhaps up to 20 unique Style colors before running the script? So you assign Style Red to one plank, Blue to another plank, and Green to a third plank. The remaining 97 planks are the default Style Black. The script sees 3 unique colors in the Selected Faces, and then randomly assigns those 3 colors to the remaining selected 97 faces (planks).
Other use cases come to mind for adding random pre-defined color / texture variations (subtle or not subtle) in the render program: Concrete blocks. Roof tiles. Wood floors. Windows on a skyscraper (yellow = lights on, blue=dark).
Ed Ferguson
|