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 #####
22 This script exports a Mesh to a RAW triangle format file.
24 The raw triangle format is very simple; it has no verts or faces lists.
25 It's just a simple ascii text file with the vertices of each triangle
26 listed on each line. In addition, also quads can be exported as a line
27 of 12 values (this was the default before blender 2.5). Now default
28 settings will triangulate the mesh.
31 Execute this script from the "File->Export" menu. You can select
32 whether modifiers should be applied and if the mesh is triangulated.
39 def faceToTriangles(face
):
42 triangles
.append([face
[0], face
[1], face
[2]])
43 triangles
.append([face
[2], face
[3], face
[0]])
45 triangles
.append(face
)
50 def faceValues(face
, mesh
, matrix
):
52 for verti
in face
.vertices
:
53 fv
.append((matrix
* mesh
.vertices
[verti
].co
)[:])
58 return " ".join([("%.6f %.6f %.6f" % v
) for v
in face
] + ["\n"])
66 scene
= bpy
.context
.scene
69 for obj
in bpy
.context
.selected_objects
:
70 if applyMods
or obj
.type != 'MESH':
72 me
= obj
.to_mesh(scene
, True, "PREVIEW")
78 if not me
.tessfaces
and me
.polygons
:
83 matrix
= obj
.matrix_world
.copy()
84 for face
in me
.tessfaces
:
85 fv
= faceValues(face
, me
, matrix
)
87 faces
.extend(faceToTriangles(fv
))
92 bpy
.data
.meshes
.remove(me
)
94 # write the faces to a file
95 file = open(filepath
, "w")
97 file.write(faceToLine(face
))