Skip to content
Snippets Groups Projects
Commit 3b18f026 authored by Campbell Barton's avatar Campbell Barton
Browse files

STL now always exports normals.

Normals are not optional for STL so remove the option from the UI.
parent 5da29460
No related branches found
No related tags found
No related merge requests found
...@@ -44,7 +44,6 @@ Import-Export STL files (binary or ascii) ...@@ -44,7 +44,6 @@ Import-Export STL files (binary or ascii)
Issues: Issues:
Import: Import:
- Does not handle the normal of the triangles
- Does not handle endien - Does not handle endien
""" """
...@@ -128,11 +127,6 @@ class ExportSTL(Operator, ExportHelper): ...@@ -128,11 +127,6 @@ class ExportSTL(Operator, ExportHelper):
description="Save the file in ASCII file format", description="Save the file in ASCII file format",
default=False, 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( use_mesh_modifiers = BoolProperty(
name="Apply Modifiers", name="Apply Modifiers",
description="Apply the modifiers before saving", description="Apply the modifiers before saving",
......
...@@ -157,7 +157,7 @@ def _ascii_read(data): ...@@ -157,7 +157,7 @@ def _ascii_read(data):
for l_item in (l, data.readline(), data.readline())] 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: with open(filepath, 'wb') as data:
fw = data.write fw = data.write
# header # header
...@@ -171,49 +171,31 @@ def _binary_write(filepath, faces, use_normals): ...@@ -171,49 +171,31 @@ def _binary_write(filepath, faces, use_normals):
# number of vertices written # number of vertices written
nb = 0 nb = 0
if use_normals: for face in faces:
for face in faces: # calculate face normal
# calculate face normal # write normal + vertexes + pad as attributes
# write normal + vertexes + pad as attributes fw(struct.pack('<3f', *normal(*face)) + pack(*itertools.chain.from_iterable(face)))
fw(struct.pack('<3f', *normal(*face)) + pack(*itertools.chain.from_iterable(face))) # attribute byte count (unused)
# attribute byte count (unused) fw(b'\0\0')
fw(b'\0\0') nb += 1
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
# header, with correct value now # header, with correct value now
data.seek(0) data.seek(0)
fw(struct.pack('<80sI', _header_version().encode('ascii'), nb)) 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: with open(filepath, 'w') as data:
fw = data.write fw = data.write
header = _header_version() header = _header_version()
fw('solid %s\n' % header) fw('solid %s\n' % header)
if use_normals: for face in faces:
for face in faces: # calculate face normal
# calculate face normal fw('facet normal %f %f %f\nouter loop\n' % normal(*face)[:])
fw('facet normal %f %f %f\nouter loop\n' % normal(*face)[:]) for vert in face:
for vert in face: fw('vertex %f %f %f\n' % vert[:])
fw('vertex %f %f %f\n' % vert[:]) fw('endloop\nendfacet\n')
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')
fw('endsolid %s\n' % header) fw('endsolid %s\n' % header)
...@@ -221,7 +203,6 @@ def _ascii_write(filepath, faces, use_normals): ...@@ -221,7 +203,6 @@ def _ascii_write(filepath, faces, use_normals):
def write_stl(filepath="", def write_stl(filepath="",
faces=(), faces=(),
ascii=False, ascii=False,
use_normals=False,
): ):
""" """
Write a stl file from faces, Write a stl file from faces,
...@@ -234,11 +215,8 @@ def write_stl(filepath="", ...@@ -234,11 +215,8 @@ def write_stl(filepath="",
ascii ascii
save the file in ascii format (very huge) 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): def read_stl(filepath):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment