[Bf-python] Creating/assigning a materials list for a mesh

Lone Wolf lone_wolf at ureach.com
Wed Apr 14 04:10:13 CEST 2004


I'm playing with Blender python scripts. I did the tuts on
jmsoler, and searched the knowledge base and google ... but I'm
still wondering how to do the following:
Take a mesh that I have created in Blender and color faces on
it. Should be simple, but ...

Just to keep it really simple, lets assume that the mesh is a
plane with 9 vertices and 4 square faces:

v1 ---- v2 ---- v3
| face 1 | face 2 |
v4 ---- v5 ---- v6
| face 3 | face 4 |
v7 ---- v8 ---- v9

Before the script runs, I want the mesh to be entirely
white/blank. At the beginning of the script, I want to set a
color variable for each face to red or white. After the script
runs the faces are colored according to this variable.

Does anybody know of a tut that explains this? Maybe somebody
could do a quick example? I'd really appreciate it.

So far, I have tried (unsuccessfully) to get even one face
colored. I posted this code I was using on elysiun.com but no
one had any suggestions:

import Blender
from Blender import NMesh, Material
me=NMesh.GetRaw()

#Create vertices

v=NMesh.Vert(1.0,0.0,0.0)
me.verts.append(v)
v=NMesh.Vert(1.0,1.0,0.0)
me.verts.append(v)
v=NMesh.Vert(0.0,1.0,0.0)
me.verts.append(v)
v=NMesh.Vert(0.0,0.0,0.0)
me.verts.append(v)

#Create face

f=NMesh.Face()
f.v.append(me.verts[0])
f.v.append(me.verts[1])
f.v.append(me.verts[2])
f.v.append(me.verts[3])
me.faces.append(f)

NMesh.PutRaw(me, "plane",1)

mat1=Material.New('red')
mat1.setRGBCol(1,0,0)
me.addMaterial(mat1)

Blender.Redraw()

The face1.materialIndex(0) generated an error, so I took it out.

With this code, a material is created, but does not show up on
the face. 


________________________________________________
Get your own "800" number
Voicemail, fax, email, and a lot more
http://www.ureach.com/reg/tag



More information about the Bf-python mailing list