Changeset View
Changeset View
Standalone View
Standalone View
io_mesh_stl/__init__.py
| Show First 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | |||||
| import bpy | import bpy | ||||
| from bpy.props import ( | from bpy.props import ( | ||||
| StringProperty, | StringProperty, | ||||
| BoolProperty, | BoolProperty, | ||||
| CollectionProperty, | CollectionProperty, | ||||
| EnumProperty, | EnumProperty, | ||||
| FloatProperty, | FloatProperty, | ||||
| FloatVectorProperty, | |||||
| ) | ) | ||||
| from bpy_extras.io_utils import ( | from bpy_extras.io_utils import ( | ||||
| ImportHelper, | ImportHelper, | ||||
| ExportHelper, | ExportHelper, | ||||
| orientation_helper, | orientation_helper, | ||||
| axis_conversion, | axis_conversion, | ||||
| ) | ) | ||||
| from bpy.types import ( | from bpy.types import ( | ||||
| ▲ Show 20 Lines • Show All 168 Lines • ▼ Show 20 Lines | class ExportSTL(Operator, ExportHelper): | ||||
| ) | ) | ||||
| batch_mode: EnumProperty( | batch_mode: EnumProperty( | ||||
| name="Batch Mode", | name="Batch Mode", | ||||
| items=( | items=( | ||||
| ('OFF', "Off", "All data in one file"), | ('OFF', "Off", "All data in one file"), | ||||
| ('OBJECT', "Object", "Each object as a file"), | ('OBJECT', "Object", "Each object as a file"), | ||||
| ), | ), | ||||
| ) | ) | ||||
| global_space: FloatVectorProperty( | |||||
| name="Global Space", | |||||
| description="Export in this reference frame", | |||||
| subtype="MATRIX", | |||||
| size=16, | |||||
| default=[1.0, 0.0, 0.0, 0.0, | |||||
| 0.0, 1.0, 0.0, 0.0, | |||||
| 0.0, 0.0, 1.0, 0.0, | |||||
| 0.0, 0.0, 0.0, 1.0] | |||||
campbellbarton: No need for a default. The property should only be used when it's set. | |||||
| ) | |||||
| @property | @property | ||||
| def check_extension(self): | def check_extension(self): | ||||
| return self.batch_mode == 'OFF' | return self.batch_mode == 'OFF' | ||||
| def execute(self, context): | def execute(self, context): | ||||
| import os | import os | ||||
| import itertools | import itertools | ||||
| from mathutils import Matrix | from mathutils import Matrix | ||||
| from . import stl_utils | from . import stl_utils | ||||
| from . import blender_utils | from . import blender_utils | ||||
| keywords = self.as_keywords( | keywords = self.as_keywords( | ||||
| ignore=( | ignore=( | ||||
| "axis_forward", | "axis_forward", | ||||
| "axis_up", | "axis_up", | ||||
| "use_selection", | "use_selection", | ||||
| "global_scale", | "global_scale", | ||||
| "check_existing", | "check_existing", | ||||
| "filter_glob", | "filter_glob", | ||||
| "use_scene_unit", | "use_scene_unit", | ||||
| "use_mesh_modifiers", | "use_mesh_modifiers", | ||||
| "batch_mode" | "batch_mode", | ||||
| "global_space" | |||||
| ), | ), | ||||
| ) | ) | ||||
| scene = context.scene | scene = context.scene | ||||
| if self.use_selection: | if self.use_selection: | ||||
| data_seq = context.selected_objects | data_seq = context.selected_objects | ||||
| else: | else: | ||||
| data_seq = scene.objects | data_seq = scene.objects | ||||
| # Take into account scene's unit scale, so that 1 inch in Blender gives 1 inch elsewhere! See T42000. | # Take into account scene's unit scale, so that 1 inch in Blender gives 1 inch elsewhere! See T42000. | ||||
| global_scale = self.global_scale | global_scale = self.global_scale | ||||
| if scene.unit_settings.system != 'NONE' and self.use_scene_unit: | if scene.unit_settings.system != 'NONE' and self.use_scene_unit: | ||||
| global_scale *= scene.unit_settings.scale_length | global_scale *= scene.unit_settings.scale_length | ||||
| global_matrix = axis_conversion( | global_matrix = axis_conversion( | ||||
| to_forward=self.axis_forward, | to_forward=self.axis_forward, | ||||
| to_up=self.axis_up, | to_up=self.axis_up, | ||||
| ).to_4x4() @ Matrix.Scale(global_scale, 4) | ).to_4x4() @ Matrix.Scale(global_scale, 4) | ||||
| global_matrix = global_matrix @ self.global_space.inverted() | |||||
| if self.batch_mode == 'OFF': | if self.batch_mode == 'OFF': | ||||
| faces = itertools.chain.from_iterable( | faces = itertools.chain.from_iterable( | ||||
| blender_utils.faces_from_mesh(ob, global_matrix, self.use_mesh_modifiers) | blender_utils.faces_from_mesh(ob, global_matrix, self.use_mesh_modifiers) | ||||
| for ob in data_seq) | for ob in data_seq) | ||||
| stl_utils.write_stl(faces=faces, **keywords) | stl_utils.write_stl(faces=faces, **keywords) | ||||
| elif self.batch_mode == 'OBJECT': | elif self.batch_mode == 'OBJECT': | ||||
| prefix = os.path.splitext(self.filepath)[0] | prefix = os.path.splitext(self.filepath)[0] | ||||
| ▲ Show 20 Lines • Show All 152 Lines • Show Last 20 Lines | |||||
No need for a default. The property should only be used when it's set.