4 def create_and_link_mesh(name
, faces
, points
):
6 Create a blender mesh and object called name from a list of
7 *points* and *faces* and link it in the current scene.
10 mesh
= bpy
.data
.meshes
.new(name
)
11 mesh
.from_pydata(points
, [], faces
)
13 ob
= bpy
.data
.objects
.new(name
, mesh
)
14 bpy
.context
.scene
.objects
.link(ob
)
16 # update mesh to allow proper display
20 def faces_from_mesh(ob
, apply_modifier
=False, triangulate
=True):
22 From an object, return a generator over a list of faces.
24 Each faces is a list of his vertexes. Each vertex is a tuple of
28 Apply the preview modifier to the returned liste
31 Split the quad into two triangles
36 mesh
= ob
.create_mesh(bpy
.context
.scene
,
37 apply_modifier
, "PREVIEW")
41 def iter_face_index():
43 From a list of faces, return the face triangulated if needed.
45 for face
in mesh
.faces
:
46 if triangulate
and len(face
.vertices
) == 4:
47 yield face
.vertices
[:3]
48 yield face
.vertices
[2:] + [face
.vertices
[0]]
50 yield list(face
.vertices
)
52 return ([tuple(mesh
.vertices
[index
].co
* ob
.matrix_world
)
53 for index
in indexes
] for indexes
in iter_face_index())