addMaterial / setMaterial


(jmcs3) #1

hi

… in reduction

how can i add and set
, for example a random material from the available ones
one two three

in the reducode below ?

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

import Blender
from Blender import NMesh
from Blender import Material

import random

one = Blender.Material.New( ‘One’ )
two = Blender.Material.New( ‘Two’ )
three = Blender.Material.New( ‘Three’ )

one.rgbCol = [ 0.1, 0.1, 0.1 ]
two.rgbCol = [ 0.2, 0.2, 0.2 ]
three.rgbCol = [ 0.3, 0.3, 0.3 ]

spheremesh = Blender.NMesh.GetRawFromObject( “Sphere” )

newmesh = Blender.NMesh.PutRaw( spheremesh )
newmesh.setName( namestring )
newmesh.setLocation( x, y, z )
newmesh.addMaterial( ? )
newmesh.setMaterials( ? )

Blender.Redraw()

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

thanks
jmcs3


(amorilia) #2

This should get you started:
http://docs.python.org/lib/module-random.html


(jms) #3

use :

from Blender import  Noise
rnd=Noise.random()

instead .


(jmcs3) #4

hi

thanks for your answers
but that was not my problem

i admit on rereading
that my phrasing was really bad

my actual problem is after
spheremesh = Blender.NMesh.GetRawFromObject( “Sphere” )

newmesh = Blender.NMesh.PutRaw( spheremesh )

i am incapable of adding and setting a material

does anyone have a working simple example ?

i am working with the latest builds
where the dox are not in sync with the latest changes…

thanks
jmcs3


(jmcs3) #5

jms wrote:

use

from Blender import Noise
rnd=Noise.random()

instead .

########

why is it preferable to use the Noise module ?

thanks
jmcs3


(jms) #6

In this case, and it is a valid situation especially for windows users, Noise is a Blender submodule : it will always work even if the python24.zip (where the random module is packed) can’t be opened like in the blender 240alpha1 ap,i for instance.