Hi all.
Lately I’ve faced a slight problem everyone who works with archviz probably know about - one does not simply get a parameter variation via random node in case of using Array modifier or after converting the particle system into single mesh. So the things like roof tiling, especially ones with complex slope geometry and all that stuff becoming just a pain a the… well, you know. If you using the flat elements, you have a solution - the addon called Random Vertex Colors will alternate the vertex color of an individual faces, so you can just use ngons on that and be cool. But if you’re using more complex elements like wavy roof tiles, or have a tree or a grass model with all the leaves / grass stems joined in single mesh this won’t help. So I decided to give a try and make something myself.
Important: I’m not a real coder, so it’s the best I can do after a couple of hours. Solution is pretty straightforward and dumb, but it works. If you see a possibility to make it better - please do not hesistate to do so!
# ADD RANDOM VERTEX COLOR TO INDIVIDUAL SUBOBJECTS
import bpy
from random import random
for i in range (0, 100):
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.select_all(action='DESELECT')
bpy.ops.mesh.select_random(percent=0.5, action='SELECT')
bpy.ops.mesh.select_linked()
bpy.ops.object.mode_set(mode='VERTEX_PAINT')
bpy.context.object.data.use_paint_mask = True
color=(random(), random(), random())
bpy.data.brushes["Draw"].color = color
bpy.ops.paint.vertex_color_set()
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.hide()
bpy.ops.mesh.reveal ()
bpy.ops.object.mode_set(mode='VERTEX_PAINT')
Here’s the result of running this script on a mesh after applying the Array modifier: