[Bf-scripts-user] assigning material to each face, not singing

Johan Meskens CS3 jmcs3 johanmeskenscs3 at chromaticspaceandworld.com
Wed May 18 15:21:24 CEST 2005


hello

i just started out with blender/python
and trying to get comfortable with the heap

here under
i would like to assign a random material( color )
to each new face

any other comment or advice concerning other problems
are welcome too ofcourse

thank you and kind regards
jmcs3


##############################

import Blender
from Blender import NMesh
from Blender import Material

import random

yellow = Blender.Material.New( 'Yellow' )
orange = Blender.Material.New( 'Orange' )
red = Blender.Material.New( 'Red' )
purple = Blender.Material.New( 'Purple' )
blue = Blender.Material.New( 'Blue' )
green = Blender.Material.New( 'Green' )

yellow.rgbCol = [ 1.0, 1.0, 0.0 ]
orange.rgbCol = [ 1.0, 0.4, 0.0 ]
red.rgbCol = [ 1.0, 0.0, 0.0 ]
purple.rgbCol = [ 1.0, 0.0, 0.4 ]
blue.rgbCol = [ 0.0, 0.0, 1.0 ]
green.rgbCol = [ 0.0, 0.6, 0.05 ]

colors = [ yellow, orange, red, purple, blue, green ]

def dpoint():
	x = ( random.random() * 6 ) - 3
	y = ( random.random() * 6 ) - 3
	z = ( random.random() * 6 ) - 3
	return( x, y, z )

me = NMesh.GetRaw()


if not me.materials:
	"""
	me.materials.append( yellow )
	me.materials.append( orange )
	me.materials.append( red )
	me.materials.append( purple )
	me.materials.append( blue )
	me.materials.append( green )
	"""
	me.addMaterial( yellow )
	me.addMaterial( orange )
	me.addMaterial( red )
	me.addMaterial( purple )
	me.addMaterial( blue )
	me.addMaterial( green )
	
for i in range( 3 ):
	for j in range( 9 ):
		apoint = dpoint()
		v = NMesh.Vert( apoint[0], apoint[1], apoint[2] )
		me.verts.append( v )

def drand():
	return random.randint( 0, 26 )

for i in range( 9 ):
	for j in range( 3 ):
		f = NMesh.Face()
		f.v.append( me.verts[ drand() ] )
		f.v.append( me.verts[ drand() ] )
		f.v.append( me.verts[ drand() ] )
		f.v.append( me.verts[ drand() ] )
		#
		#f.mat = 4 #random.randint( 0, 5 )
		# how do assign a random color to each face ?
		#
		print f.mat
		me.faces.append( f )
		
NMesh.PutRaw( me, "Struct", 1 )
Blender.Redraw()

print me.materials



More information about the Bf-scripts-user mailing list