From a25ac71f574649a95cf7f05f3ccad1b5d8ef2655 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sat, 27 Jun 2020 11:57:58 +0300 Subject: [PATCH] Replace single file mode in object exporter with collection --- blender/io_mspgl/__init__.py | 12 ++++++++---- blender/io_mspgl/export_material.py | 21 ++++++++------------- blender/io_mspgl/export_object.py | 22 +++++++++------------- 3 files changed, 25 insertions(+), 30 deletions(-) diff --git a/blender/io_mspgl/__init__.py b/blender/io_mspgl/__init__.py index a1869e3e..bcb196c3 100644 --- a/blender/io_mspgl/__init__.py +++ b/blender/io_mspgl/__init__.py @@ -67,12 +67,17 @@ class ExportMspGLObject(bpy.types.Operator, ExportMspGLMeshBase): filename_ext = ".object" - single_file = bpy.props.BoolProperty(name="Single file", description="Write all data into a single file", default=True) + collection = bpy.props.BoolProperty(name="As a collection", description="Write all data into a single collection file", default=False) shared_resources = bpy.props.BoolProperty(name="Shared resources", description="Use global names for resource files to enable sharing", default=True) export_lods = bpy.props.BoolProperty(name="Export LoDs", description="Export all levels of detail", default=True) use_textures = bpy.props.BoolProperty(name="Use textures", description="Use textures in the exported object", default=True) + def check(self, context): + ext_changed = self.set_extension(".mdc" if self.collection else ".object") + super_result = super().check(context) + return ext_changed or super_result + def create_exporter(self): from .export_object import ObjectExporter return ObjectExporter() @@ -85,9 +90,8 @@ class ExportMspGLObject(bpy.types.Operator, ExportMspGLMeshBase): col = self.layout.column() col.label(text="Files") - col.prop(self, "single_file") - if not self.single_file: - col.prop(self, "shared_resources") + col.prop(self, "collection") + col.prop(self, "shared_resources") class ExportMspGLArmature(bpy.types.Operator, ExportMspGLBase): bl_idname = "export.mspgl_armature" diff --git a/blender/io_mspgl/export_material.py b/blender/io_mspgl/export_material.py index 8f9bdd40..0a75c47a 100644 --- a/blender/io_mspgl/export_material.py +++ b/blender/io_mspgl/export_material.py @@ -1,16 +1,13 @@ import os -def create_technique_resource(material, resources, single_file): +def create_technique_resource(material, resources): from .datafile import Resource, Statement tech_res = Resource(material.name+".tech", "technique") mat_res = resources[material.name+".mat"] st = Statement("pass", "") - if single_file: - st.sub.append(tech_res.create_embed_statement("material", mat_res)) - else: - st.sub.append(tech_res.create_reference_statement("material", mat_res)) + st.sub.append(tech_res.create_embed_statement("material", mat_res)) if material.render_mode=='CUSTOM': st.sub.append(Statement("shader", material.shader)) @@ -21,13 +18,13 @@ def create_technique_resource(material, resources, single_file): class MaterialExporter: def __init__(self): - self.single_file = True self.use_textures = True + self.inline_texture_data = False def create_texture_exporter(self): from .export_texture import TextureExporter texture_export = TextureExporter() - texture_export.inline_data = self.single_file + texture_export.inline_data = self.inline_texture_data return texture_export def export_technique_resources(self, material, resources): @@ -48,7 +45,7 @@ class MaterialExporter: resources[mat_name] = self.export_material(material, resources=resources) def export_technique(self, material, *, resources): - return create_technique_resource(material, resources, self.single_file) + return create_technique_resource(material, resources) def export_material(self, material, *, resources): from .datafile import Resource, Statement @@ -69,9 +66,7 @@ class MaterialExporter: if self.use_textures and prop.texture: tex_res = resources[prop.texture.image.name+".tex2d"] fn = os.path.basename(prop.texture.image.filepath) - if self.single_file: - raise Exception("Can't export textures to a single file") - elif prop.texture.default_filter and fn: + if prop.texture.default_filter and fn: return Statement(keyword+"_map", fn) else: return mat_res.create_reference_statement(keyword+"_map", tex_res) @@ -83,7 +78,7 @@ class MaterialExporter: class MaterialMapExporter: def __init__(self): - self.single_file = True + pass def export_technique_resources(self, material_map, resources): from .datafile import Resource, Statement, Token @@ -108,4 +103,4 @@ class MaterialMapExporter: resources[mat_name] = mat_res def export_technique(self, material_map, *, resources): - return create_technique_resource(material_map, resources, self.single_file) + return create_technique_resource(material_map, resources) diff --git a/blender/io_mspgl/export_object.py b/blender/io_mspgl/export_object.py index 6cc0be31..a86ee26b 100644 --- a/blender/io_mspgl/export_object.py +++ b/blender/io_mspgl/export_object.py @@ -7,7 +7,7 @@ class ObjectExporter: self.use_strips = True self.use_degen_tris = False self.use_textures = True - self.single_file = True + self.collection = False self.shared_resources = True self.export_lods = True @@ -44,14 +44,12 @@ class ObjectExporter: def create_material_exporter(self): from .export_material import MaterialExporter material_export = MaterialExporter() - material_export.single_file = self.single_file material_export.use_textures = self.use_textures return material_export def create_material_map_exporter(self): from .export_material import MaterialMapExporter material_map_export = MaterialMapExporter() - material_map_export.single_file = self.single_file return material_map_export def export_to_file(self, context, out_fn): @@ -79,9 +77,12 @@ class ObjectExporter: r.name = base+ext numbers[ext] = n+1 - for r in refs: - r.write_to_file(os.path.join(path, r.name)) - obj_res.write_to_file(out_fn) + if self.collection: + obj_res.write_collection(out_fn) + else: + for r in refs: + r.write_to_file(os.path.join(path, r.name)) + obj_res.write_to_file(out_fn) def export_object_resources(self, context, obj, resources, progress, material_maps=None): if material_maps is None: @@ -157,10 +158,7 @@ class ObjectExporter: if l.data.name!=prev_mesh: mesh_res = resources[l.data.name+".mesh"] - if not self.single_file: - lod_st.append(obj_res.create_reference_statement("mesh", mesh_res)) - else: - lod_st.append(obj_res.create_embed_statement("mesh", mesh_res)) + lod_st.append(obj_res.create_reference_statement("mesh", mesh_res)) prev_mesh = l.data.name @@ -178,10 +176,8 @@ class ObjectExporter: if tech_res.name!=prev_tech: if material and material.render_mode=='EXTERNAL': lod_st.append(Statement("technique", material.technique)) - elif not self.single_file: - lod_st.append(obj_res.create_reference_statement("technique", tech_res)) else: - lod_st.append(obj_res.create_embed_statement("technique", tech_res)) + lod_st.append(obj_res.create_reference_statement("technique", tech_res)) prev_tech = tech_res.name if i>0: -- 2.45.2