Fix #72203: collection instances not exported for stl #104460

Open
Konstantin-Koch wants to merge 1 commits from Konstantin-Koch/blender-addons:stl_collection_export into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.

View File

@ -240,10 +240,13 @@ class ExportSTL(Operator, ExportHelper):
def execute(self, context): def execute(self, context):
import os import os
import itertools import itertools
import bpy
from mathutils import Matrix from mathutils import Matrix
from . import stl_utils from . import stl_utils
from . import blender_utils from . import blender_utils
depsgraph = bpy.context.evaluated_depsgraph_get()
keywords = self.as_keywords( keywords = self.as_keywords(
ignore=( ignore=(
"axis_forward", "axis_forward",
@ -265,6 +268,15 @@ class ExportSTL(Operator, ExportHelper):
else: else:
data_seq = scene.objects 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. # 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:
@ -280,15 +292,15 @@ class ExportSTL(Operator, ExportHelper):
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_tuple[0], global_matrix @ ob_tuple[1], self.use_mesh_modifiers)
for ob in data_seq) for ob_tuple in resolved_objs)
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]
keywords_temp = keywords.copy() keywords_temp = keywords.copy()
for ob in data_seq: for ob_tuple in resolved_objs:
faces = blender_utils.faces_from_mesh(ob, global_matrix, self.use_mesh_modifiers) 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" keywords_temp["filepath"] = prefix + bpy.path.clean_name(ob.name) + ".stl"
stl_utils.write_stl(faces=faces, **keywords_temp) stl_utils.write_stl(faces=faces, **keywords_temp)