Fix #72203: collection instances not exported for stl #104460
@ -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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user