diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-04-15 21:21:17 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-04-15 21:21:17 +0400 |
commit | e88ccb06cc638467174f8b2e0ad3af1828db2c68 (patch) | |
tree | abb90f6cdfd7f294e3d45fadb633a736eaf9ad82 /io_mesh_stl | |
parent | 81507f54080373b9f23f212e23e3ea6299490140 (diff) |
option to apply scale on export. also add global scale options for exporters. OBJ/X3D/VRML/PLY/STL
Diffstat (limited to 'io_mesh_stl')
-rw-r--r-- | io_mesh_stl/__init__.py | 47 | ||||
-rw-r--r-- | io_mesh_stl/blender_utils.py | 4 |
2 files changed, 46 insertions, 5 deletions
diff --git a/io_mesh_stl/__init__.py b/io_mesh_stl/__init__.py index cb0badc5..5260b5c0 100644 --- a/io_mesh_stl/__init__.py +++ b/io_mesh_stl/__init__.py @@ -58,8 +58,16 @@ if "bpy" in locals(): import os import bpy -from bpy.props import StringProperty, BoolProperty, CollectionProperty -from bpy_extras.io_utils import ExportHelper, ImportHelper +from bpy.props import (StringProperty, + BoolProperty, + CollectionProperty, + EnumProperty, + FloatProperty, + ) +from bpy_extras.io_utils import (ImportHelper, + ExportHelper, + axis_conversion, + ) from bpy.types import Operator, OperatorFileListElement @@ -126,13 +134,46 @@ class ExportSTL(Operator, ExportHelper): default=True, ) + axis_forward = EnumProperty( + name="Forward", + items=(('X', "X Forward", ""), + ('Y', "Y Forward", ""), + ('Z', "Z Forward", ""), + ('-X', "-X Forward", ""), + ('-Y', "-Y Forward", ""), + ('-Z', "-Z Forward", ""), + ), + default='Y', + ) + axis_up = EnumProperty( + name="Up", + items=(('X', "X Up", ""), + ('Y', "Y Up", ""), + ('Z', "Z Up", ""), + ('-X', "-X Up", ""), + ('-Y', "-Y Up", ""), + ('-Z', "-Z Up", ""), + ), + default='Z', + ) + global_scale = FloatProperty( + name="Scale", + min=0.01, max=1000.0, + default=1.0, + ) + def execute(self, context): from . import stl_utils from . import blender_utils import itertools + from mathutils import Matrix + + global_matrix = axis_conversion(to_forward=self.axis_forward, + to_up=self.axis_up, + ).to_4x4() * Matrix.Scale(self.global_scale, 4) faces = itertools.chain.from_iterable( - blender_utils.faces_from_mesh(ob, self.use_mesh_modifiers) + blender_utils.faces_from_mesh(ob, global_matrix, self.use_mesh_modifiers) for ob in context.selected_objects) stl_utils.write_stl(self.filepath, faces, self.ascii) diff --git a/io_mesh_stl/blender_utils.py b/io_mesh_stl/blender_utils.py index 1de66f20..a13277ad 100644 --- a/io_mesh_stl/blender_utils.py +++ b/io_mesh_stl/blender_utils.py @@ -42,7 +42,7 @@ def create_and_link_mesh(name, faces, points): obj.select = True -def faces_from_mesh(ob, use_mesh_modifiers=False, triangulate=True): +def faces_from_mesh(ob, global_matrix, use_mesh_modifiers=False, triangulate=True): """ From an object, return a generator over a list of faces. @@ -65,7 +65,7 @@ def faces_from_mesh(ob, use_mesh_modifiers=False, triangulate=True): except RuntimeError: raise StopIteration - mesh.transform(ob.matrix_world) + mesh.transform(global_matrix * ob.matrix_world) if triangulate: # From a list of faces, return the face triangulated if needed. |