From 859f8b99ee65bb52c7a44194420a156ef5be3413 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Thu, 15 Apr 2021 21:03:30 +0300 Subject: [PATCH] Adjust scene export code Resources are no longer exported as a collection by default. If collection export is enabled, the scene itself is put in the collection too. --- blender/io_mspgl/__init__.py | 17 +++++++++++++---- blender/io_mspgl/export_scene.py | 20 ++++++++------------ 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/blender/io_mspgl/__init__.py b/blender/io_mspgl/__init__.py index 13375e24..02afb148 100644 --- a/blender/io_mspgl/__init__.py +++ b/blender/io_mspgl/__init__.py @@ -110,11 +110,20 @@ class ExportMspGLScene(bpy.types.Operator, ExportMspGLBase): filename_ext = ".scene" - selected_only: bpy.props.BoolProperty(name="Selected objects only", description="Only export the selected objects") + selected_only: bpy.props.BoolProperty(name="Selected objects only", description="Only export the selected objects", default=False) visible_only: bpy.props.BoolProperty(name="Visible only", description="Only export objects in visible collections", default=True) - resource_collection: bpy.props.BoolProperty(name="Resource collection", description="Put resources to a single collection file", default=True) + collection: bpy.props.BoolProperty(name="As a collection", description="Export the scene and all resources as a single collection file", default=False) skip_existing: bpy.props.BoolProperty(name="Skip existing files", description="Skip resources that already exist as files", default=True) + def invoke(self, context, event): + self.filepath = context.scene.name+".scene" + return super().invoke(context, event) + + def check(self, context): + ext_changed = self.set_extension(".mdc" if self.collection else ".scene") + super_result = super().check(context) + return ext_changed or super_result + def create_exporter(self): from .export_scene import SceneExporter return SceneExporter() @@ -123,8 +132,8 @@ class ExportMspGLScene(bpy.types.Operator, ExportMspGLBase): col = self.layout.column() col.prop(self, "selected_only") col.prop(self, "visible_only") - col.prop(self, "resource_collection") - if self.resource_collection: + col.prop(self, "collection") + if self.collection: col.prop(self, "skip_existing") class AddUniform(bpy.types.Operator): diff --git a/blender/io_mspgl/export_scene.py b/blender/io_mspgl/export_scene.py index 9590fc17..02566ef6 100644 --- a/blender/io_mspgl/export_scene.py +++ b/blender/io_mspgl/export_scene.py @@ -5,7 +5,7 @@ class SceneExporter: def __init__(self): self.selected_only = False self.visible_only = True - self.resource_collection = True + self.collection = True self.skip_existing = True self.show_progress = True @@ -84,23 +84,19 @@ class SceneExporter: scene_res = self.export_scene(context, objs, resources, object_prototypes, progress) refs = scene_res.collect_references() - if self.resource_collection: - filter = None + if self.collection: + existing = None if self.skip_existing: - filter = lambda r: not os.path.exists(os.path.join(path, r.name)) - scene_res.write_collection(os.path.join(path, base+"_resources.mdc"), exclude_self=True, filter=filter) + existing = lambda r: not os.path.exists(os.path.join(path, r.name)) + scene_res.write_collection(out_fn, filter=existing) else: - res_dir = os.path.join(path, base+"_resources") - if not os.path.exists(res_dir): - os.makedirs(res_dir) + scene_res.write_to_file(out_fn) for r in refs: - r.write_to_file(os.path.join(res_dir, r.name)) - - scene_res.write_to_file(out_fn) + r.write_to_file(os.path.join(path, r.name)) def export_scene(self, context, objs, resources, prototypes, progress): from .datafile import Resource, Statement, Token - scene_res = Resource("scene.scene", "scene") + scene_res = Resource(context.scene.name+".scene", "scene") scene_res.statements.append(Statement("type", Token(context.scene.scene_type.lower()))) -- 2.43.0