Posts tagged ‘random’

luglio 23, 2012

Blender: Random Material Assigner (to BMesh N-gons)

This is a simple script for assignement of random materials to different faces (n-gons) of a single object. It works differently to the existing Random Material Assigner and the mine is a version very rough. I wrote this script because for the particular job that I had to do it was more comfortable handling a single object to be fixed as a random mosaic, rather than a very large number of different objects. Here is the code:

import bpy
import bmesh
import random

obj = bpy.context.active_object
mesh =

bm =

for f in bm.faces:
    f.material_index = int(random.random()*len(obj.material_slots))