interperation of commands

1 -
in one of python tut there is theses lines
and i had to remove it because the script was crashing
can someone explain what it means

set the face materials of our triangle

we can set all faces the same color like this

for f in me2.faces:
f.mat = 0
note: me2 is the name i used

2 - color
what are the meaning of the red green blue parameters
in theses line
each color has 3 values ?

create some materials

red = B.Material.New(‘Red’)
red.rgbCol = 1,0,0 # red, green, blue values
green = B.Material.New(‘Green’)
green.rgbCol = 0,1,0 # red, green, blue values
blue = B.Material.New(‘Blue’)
blue.rgbCol = 0,0,1 # red, green, blue values

Thanks

For problem 1: Could we see how you assigned me2? That is, where did you get your Mesh object? All this code is doing is assigning the material index 0 to each face in a mesh. This works fine on the default cube:


import Blender 
from Blender import Mesh 
 
me2 = Mesh.Get("Cube") 
i = 0 
for f in me2.faces: 
    f.mat = 0 
    i += 1 
 
print i, " faces found" 

(The line with the f.mat assignment is indented, right? Consider wrapping code snippets in CODE tags to maintain the format.)

For question 2, Material.rgbCol is a triplet of floats in the range 0.0 … 1.0. So yes, each color has 3 values; this code creates material instances with the color name. Obviously, a material is much more than just its color so this is kind of naming is somewhat confusing in a tutorial.


# vertices 
pt1 = [0,0,0]
pt2 = [asidex,asidey,0]
pt3 = [asidex+bsidex, 0, 0]
verts = [pt1,pt2,pt3]
faces = [0,1,2]
# create Object
ob1 = B.Object.New('Mesh', 'MeshOb1')
# create ObData
me1 = B.Mesh.New('myMesh')
# add vertices
me1.verts.extend( verts )
# create faces
me1.faces.extend( faces )
ob1.link( me1 )
scene = B.Scene.GetCurrent()
scene.link( ob1 )
for v in me1.verts:
print v
print " &&&&&&&&&&&&&&&&"
 
# first object in selection list
#ob2 = B.Object.GetSelected()[0]
ob2 = B.Object.Get('MeshOb1')
# get the Mesh version of our triangle, not NMesh
me2 = B.Mesh.Get( ob2.data.name )
print "me2=",me2
# create some materials
red = B.Material.New('Red')
red.rgbCol = 1,0,0 # red, green, blue values
green = B.Material.New('Green')
green.rgbCol = 0,1,0 # red, green, blue values
blue = B.Material.New('Blue')
blue.rgbCol = 0,0,1 # red, green, blue values
 
# add the material list to our ObData
me2.materials = [red, green, blue ]
 
 

i’'v made a triangle isocele not a cube in this case
so a triangle has only one face
and what about the colors values - what are theses for
OK o got it this is an object with 3 material
each with it own color!
execpt you end up seeing only one color on one face?
don’t know what it would give on a cube ?

whe i run it i get a red color face?

Salutations