From 3b18f026d0918ecd51a0c79343b8221769806e9e Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 22 Apr 2014 15:17:50 +1000 Subject: STL now always exports normals. Normals are not optional for STL so remove the option from the UI. --- io_mesh_stl/__init__.py | 6 ------ io_mesh_stl/stl_utils.py | 54 ++++++++++++++---------------------------------- 2 files changed, 16 insertions(+), 44 deletions(-) (limited to 'io_mesh_stl') diff --git a/io_mesh_stl/__init__.py b/io_mesh_stl/__init__.py index 6994fcef..9de8c02d 100644 --- a/io_mesh_stl/__init__.py +++ b/io_mesh_stl/__init__.py @@ -44,7 +44,6 @@ Import-Export STL files (binary or ascii) Issues: Import: - - Does not handle the normal of the triangles - Does not handle endien """ @@ -128,11 +127,6 @@ class ExportSTL(Operator, ExportHelper): description="Save the file in ASCII file format", default=False, ) - use_normals = BoolProperty( - name="Write Normals", - description="Export one normal per face, to represent flat faces and sharp edges", - default=False, - ) use_mesh_modifiers = BoolProperty( name="Apply Modifiers", description="Apply the modifiers before saving", diff --git a/io_mesh_stl/stl_utils.py b/io_mesh_stl/stl_utils.py index 1145ab41..67478ba8 100644 --- a/io_mesh_stl/stl_utils.py +++ b/io_mesh_stl/stl_utils.py @@ -157,7 +157,7 @@ def _ascii_read(data): for l_item in (l, data.readline(), data.readline())] -def _binary_write(filepath, faces, use_normals): +def _binary_write(filepath, faces): with open(filepath, 'wb') as data: fw = data.write # header @@ -171,49 +171,31 @@ def _binary_write(filepath, faces, use_normals): # number of vertices written nb = 0 - if use_normals: - for face in faces: - # calculate face normal - # write normal + vertexes + pad as attributes - fw(struct.pack('<3f', *normal(*face)) + pack(*itertools.chain.from_iterable(face))) - # attribute byte count (unused) - fw(b'\0\0') - nb += 1 - else: - # pad is to remove normal, we do use them - pad = b'\0' * struct.calcsize('<3f') - - for face in faces: - # write pad as normal + vertexes + pad as attributes - fw(pad + pack(*itertools.chain.from_iterable(face))) - # attribute byte count (unused) - fw(b'\0\0') - nb += 1 + for face in faces: + # calculate face normal + # write normal + vertexes + pad as attributes + fw(struct.pack('<3f', *normal(*face)) + pack(*itertools.chain.from_iterable(face))) + # attribute byte count (unused) + fw(b'\0\0') + nb += 1 # header, with correct value now data.seek(0) fw(struct.pack('<80sI', _header_version().encode('ascii'), nb)) -def _ascii_write(filepath, faces, use_normals): +def _ascii_write(filepath, faces): with open(filepath, 'w') as data: fw = data.write header = _header_version() fw('solid %s\n' % header) - if use_normals: - for face in faces: - # calculate face normal - fw('facet normal %f %f %f\nouter loop\n' % normal(*face)[:]) - for vert in face: - fw('vertex %f %f %f\n' % vert[:]) - fw('endloop\nendfacet\n') - else: - for face in faces: - fw('outer loop\n') - for vert in face: - fw('vertex %f %f %f\n' % vert[:]) - fw('endloop\nendfacet\n') + for face in faces: + # calculate face normal + fw('facet normal %f %f %f\nouter loop\n' % normal(*face)[:]) + for vert in face: + fw('vertex %f %f %f\n' % vert[:]) + fw('endloop\nendfacet\n') fw('endsolid %s\n' % header) @@ -221,7 +203,6 @@ def _ascii_write(filepath, faces, use_normals): def write_stl(filepath="", faces=(), ascii=False, - use_normals=False, ): """ Write a stl file from faces, @@ -234,11 +215,8 @@ def write_stl(filepath="", ascii save the file in ascii format (very huge) - - use_normals - calculate face normals and write them """ - (_ascii_write if ascii else _binary_write)(filepath, faces, use_normals) + (_ascii_write if ascii else _binary_write)(filepath, faces) def read_stl(filepath): -- cgit v1.2.3