From 555324246952f5d680f446bbb030a2e187bcedf6 Mon Sep 17 00:00:00 2001 From: Konstantin Date: Wed, 1 Mar 2023 12:54:30 +0100 Subject: [PATCH] Fix #72203: collection instances not exported for stl --- io_mesh_stl/__init__.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/io_mesh_stl/__init__.py b/io_mesh_stl/__init__.py index e68a262bb..af494c4f1 100644 --- a/io_mesh_stl/__init__.py +++ b/io_mesh_stl/__init__.py @@ -240,10 +240,13 @@ class ExportSTL(Operator, ExportHelper): def execute(self, context): import os import itertools + import bpy from mathutils import Matrix from . import stl_utils from . import blender_utils + depsgraph = bpy.context.evaluated_depsgraph_get() + keywords = self.as_keywords( ignore=( "axis_forward", @@ -265,6 +268,15 @@ class ExportSTL(Operator, ExportHelper): else: data_seq = scene.objects + resolved_objs = [] + for ob in data_seq: + if ob.is_instancer: + resolved_objs += [(dup.instance_object.original, ob.matrix_world.copy()) + for dup in depsgraph.object_instances + if dup.parent and dup.parent.original == ob] + else: + resolved_objs.append((ob, Matrix())) + # Take into account scene's unit scale, so that 1 inch in Blender gives 1 inch elsewhere! See T42000. global_scale = self.global_scale if scene.unit_settings.system != 'NONE' and self.use_scene_unit: @@ -280,15 +292,15 @@ class ExportSTL(Operator, ExportHelper): if self.batch_mode == 'OFF': faces = itertools.chain.from_iterable( - blender_utils.faces_from_mesh(ob, global_matrix, self.use_mesh_modifiers) - for ob in data_seq) + blender_utils.faces_from_mesh(ob_tuple[0], global_matrix @ ob_tuple[1], self.use_mesh_modifiers) + for ob_tuple in resolved_objs) stl_utils.write_stl(faces=faces, **keywords) elif self.batch_mode == 'OBJECT': prefix = os.path.splitext(self.filepath)[0] keywords_temp = keywords.copy() - for ob in data_seq: - faces = blender_utils.faces_from_mesh(ob, global_matrix, self.use_mesh_modifiers) + for ob_tuple in resolved_objs: + faces = blender_utils.faces_from_mesh(ob_tuple[0], global_matrix @ ob_tuple[1], self.use_mesh_modifiers) keywords_temp["filepath"] = prefix + bpy.path.clean_name(ob.name) + ".stl" stl_utils.write_stl(faces=faces, **keywords_temp) -- 2.30.2