From 5722bc15cd193bf8c083e282c3ad36344aab3832 Mon Sep 17 00:00:00 2001 From: Campbell Barton <ideasman42@gmail.com> Date: Fri, 14 Jan 2011 19:31:42 +0000 Subject: [PATCH] bugfix [#25635] STL export results in error also made some pep8 corrections --- io_mesh_stl/blender_utils.py | 28 ++++++++++++++++------------ io_mesh_stl/stl_utils.py | 2 ++ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/io_mesh_stl/blender_utils.py b/io_mesh_stl/blender_utils.py index a043a8f34..751f25863 100644 --- a/io_mesh_stl/blender_utils.py +++ b/io_mesh_stl/blender_utils.py @@ -38,16 +38,20 @@ def faces_from_mesh(ob, apply_modifier=False, triangulate=True): except SystemError: return () - def iter_face_index(): - ''' - From a list of faces, return the face triangulated if needed. - ''' - for face in mesh.faces: - if triangulate and len(face.vertices) == 4: - yield face.vertices[:3] - yield face.vertices[2:] + [face.vertices[0]] - else: - yield list(face.vertices) - - return ([tuple(mesh.vertices[index].co * ob.matrix_world) + if triangulate: + # From a list of faces, return the face triangulated if needed. + def iter_face_index(): + for face in mesh.faces: + vertices = face.vertices[:] + if len(vertices) == 4: + yield vertices[0], vertices[1], vertices[2] + yield vertices[2], vertices[3], vertices[0] + else: + yield vertices + else: + def iter_face_index(): + for face in mesh.faces: + yield face.vertices[:] + + return ([(mesh.vertices[index].co * ob.matrix_world)[:] for index in indexes] for indexes in iter_face_index()) diff --git a/io_mesh_stl/stl_utils.py b/io_mesh_stl/stl_utils.py index 734204b8d..9524ecb3d 100644 --- a/io_mesh_stl/stl_utils.py +++ b/io_mesh_stl/stl_utils.py @@ -65,6 +65,7 @@ class ListDict(dict): BINARY_HEADER = 80 BINARY_STRIDE = 12 * 4 + 2 + def _is_ascii_file(data): ''' This function returns True if the data represents an ASCII file. @@ -77,6 +78,7 @@ def _is_ascii_file(data): return not data.size() == BINARY_HEADER + 4 + BINARY_STRIDE * size + def _binary_read(data): # an stl binary file is # - 80 bytes of description -- GitLab