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 = obj.data

bm = bmesh.new()
bm.from_mesh(mesh)

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

bm.to_mesh(mesh)

Image

Lascia un commento

Inserisci i tuoi dati qui sotto o clicca su un'icona per effettuare l'accesso:

Logo WordPress.com

Stai commentando usando il tuo account WordPress.com. Chiudi sessione / Modifica )

Foto Twitter

Stai commentando usando il tuo account Twitter. Chiudi sessione / Modifica )

Foto di Facebook

Stai commentando usando il tuo account Facebook. Chiudi sessione / Modifica )

Google+ photo

Stai commentando usando il tuo account Google+. Chiudi sessione / Modifica )

Connessione a %s...

%d blogger cliccano Mi Piace per questo: