1 # ##### BEGIN GPL LICENSE BLOCK #####
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software Foundation,
15 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 # ##### END GPL LICENSE BLOCK #####
24 def create_and_link_mesh(name
, faces
, points
):
26 Create a blender mesh and object called name from a list of
27 *points* and *faces* and link it in the current scene.
30 mesh
= bpy
.data
.meshes
.new(name
)
31 mesh
.from_pydata(points
, [], faces
)
33 # update mesh to allow proper display
37 scene
= bpy
.context
.scene
39 obj
= bpy
.data
.objects
.new(name
, mesh
)
40 scene
.objects
.link(obj
)
41 scene
.objects
.active
= obj
45 def faces_from_mesh(ob
, global_matrix
, use_mesh_modifiers
=False, triangulate
=True):
47 From an object, return a generator over a list of faces.
49 Each faces is a list of his vertexes. Each vertex is a tuple of
53 Apply the preview modifier to the returned liste
56 Split the quad into two triangles
59 # get the editmode data
60 ob
.update_from_editmode()
64 mesh
= ob
.to_mesh(bpy
.context
.scene
, use_mesh_modifiers
, "PREVIEW")
68 mesh
.transform(global_matrix
* ob
.matrix_world
)
71 # From a list of faces, return the face triangulated if needed.
72 def iter_face_index():
73 for face
in mesh
.tessfaces
:
74 vertices
= face
.vertices
[:]
75 if len(vertices
) == 4:
76 yield vertices
[0], vertices
[1], vertices
[2]
77 yield vertices
[2], vertices
[3], vertices
[0]
81 def iter_face_index():
82 for face
in mesh
.tessfaces
:
83 yield face
.vertices
[:]
85 vertices
= mesh
.vertices
87 for indexes
in iter_face_index():
88 yield [vertices
[index
].co
.copy() for index
in indexes
]
90 bpy
.data
.meshes
.remove(mesh
)