| Module: Mesh | ./Mesh.py | |||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
The Blender Mesh moduleThis module provides routines for more extensive mesh manipulation. Later, this Mesh type will also allow interactive access (like in EditMode). In the Publisher, Ngons will also be supported (and converted to triangles on mesh.update(). The following code demonstrates creation of an Ngon. Example:
from Blender import Mesh, Object, Scene
m = Mesh.New() # new empty mesh
vlist = []
vlist.append(m.addVert((-0.0, -1.0, 0.0)))
vlist.append(m.addVert((1.0, 0.0, 0.0)))
vlist.append(m.addVert((1.0, 1.0, 0.0)))
vlist.append(m.addVert((0.0, 3.0, 0.0)))
vlist.append(m.addVert((-1.0, 2.0, 0.0)))
vlist.append(m.addVert((-3.0, 1.0, 0.0)))
vlist.append(m.addVert((-3.0, 3.0, 0.0)))
vlist.append(m.addVert((-4.0, 3.0, 0.0)))
vlist.append(m.addVert((-4.0, 0.0, 0.0)))
f = m.addFace(vlist)
# do some calculations: top project vertex coordinates to
# UV coordinates and normalize them to the square [0.0, 1.0]*[0.0, 1.0]
uvlist = map(lambda x: (x.co[0], x.co[1]), vlist)
maxx = max(map(lambda x: x[0], uvlist))
maxy = max(map(lambda x: x[1], uvlist))
minx = min(map(lambda x: x[0], uvlist))
miny = min(map(lambda x: x[1], uvlist))
len = max((maxx - minx), (maxy - miny))
offx = -minx / len
offy = -miny / len
f.uv = map(lambda x: (x[0]/len + offx, x[1]/len + offy), uvlist) # assign UV coordinates by 'top' projection
m.update() # update and triangulate mesh
ob = Object.New('Mesh') # create new Object
ob.link(m) # link mesh data
sc = Scene.getCurrent() # get current Scene
sc.link(ob) # link Object to scene
|