From f77259ba680e73daee6008f53dafe92e84a0b5f5 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sat, 18 May 2019 10:45:23 +0300 Subject: [PATCH] Simplify the resource separation options Having different options for each resource type was getting unmanageable. I don't see much value in such fine-grained control either. --- blender/io_mspgl/__init__.py | 22 ++++++---------------- blender/io_mspgl/export_material.py | 20 +++++++++++++------- blender/io_mspgl/export_object.py | 12 ++++++------ blender/io_mspgl/export_scene.py | 3 +-- blender/io_mspgl/export_texture.py | 4 ++-- 5 files changed, 28 insertions(+), 33 deletions(-) diff --git a/blender/io_mspgl/__init__.py b/blender/io_mspgl/__init__.py index b24f28d9..133b844c 100644 --- a/blender/io_mspgl/__init__.py +++ b/blender/io_mspgl/__init__.py @@ -58,16 +58,11 @@ class ExportMspGLObject(bpy.types.Operator, ExportMspGLMeshBase): filename_ext = ".object" - textures = bpy.props.EnumProperty(name="Textures", description="Export textures", default="REF", - items=(("NONE", "None", "Ignore textures"), - ("REF", "Referenced", "Reference external data"), - ("INLINE", "Inline", "Embed textures in the object"))) - - separate_mesh = bpy.props.BoolProperty(name="Separate mesh", description="Write mesh data into a separate file", default=False) - separate_tech = bpy.props.BoolProperty(name="Separate technique", description="Write technique data into a separate file", default=False) + single_file = bpy.props.BoolProperty(name="Single file", description="Write all data into a single file", default=True) 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 create_exporter(self): from .export_object import ObjectExporter @@ -76,18 +71,13 @@ class ExportMspGLObject(bpy.types.Operator, ExportMspGLMeshBase): def draw(self, context): super().draw(context) - col = self.general_col - col.prop(self, "export_lods") - col.prop(self, "textures") - col.separator() - - self.layout.separator() + self.general_col.prop(self, "export_lods") + self.general_col.prop(self, "use_textures") col = self.layout.column() col.label("Files") - col.prop(self, "separate_mesh") - col.prop(self, "separate_tech") - if self.separate_mesh or self.separate_tech: + col.prop(self, "single_file") + if not self.single_file: col.prop(self, "shared_resources") class ExportMspGLArmature(bpy.types.Operator, ExportMspGLBase): diff --git a/blender/io_mspgl/export_material.py b/blender/io_mspgl/export_material.py index 3f0117d4..289fb881 100644 --- a/blender/io_mspgl/export_material.py +++ b/blender/io_mspgl/export_material.py @@ -15,13 +15,13 @@ def get_colormap(srgb): class MaterialExporter: def __init__(self): - self.textures = 'REF' + self.single_file = True + self.use_textures = True def create_texture_exporter(self): from .export_texture import TextureExporter texture_export = TextureExporter() - if self.textures=='INLINE': - texture_export.pixels = 'INLINE' + texture_export.inline_data = self.single_file return texture_export def export_technique_resources(self, material, resources): @@ -31,7 +31,7 @@ class MaterialExporter: if mat_name not in resources: resources[mat_name] = self.export_material(material) - if self.textures!='NONE': + if self.use_textures: for s in material.texture_slots: if s and s.texture.type=='IMAGE' and s.texture.image: tex_name = s.texture.name+".tex2d" @@ -44,7 +44,7 @@ class MaterialExporter: mat_res = resources[material.name+".mat"] textures = {} - if self.textures!='NONE': + if self.use_textures: image_texture_slots = [s for s in material.texture_slots if s and s.texture.type=='IMAGE' and s.texture.image] for s in image_texture_slots: if s.use_map_color_diffuse: @@ -56,6 +56,9 @@ class MaterialExporter: if not obj.inherit_tech: return [] + if self.single_file: + raise Exception("Can't export inherited technique to a single file") + st = Statement("inherit", material.technique) for s, t in textures.items(): if t.default_filter: @@ -67,13 +70,16 @@ class MaterialExporter: tech_res.statements.append(st) else: st = Statement("pass", "") - st.sub.append(tech_res.create_embed_statement("material", mat_res)) + if self.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)) if "diffuse_map" in textures: diffuse_tex = textures["diffuse_map"] tex_res = resources[diffuse_tex.name+".tex2d"] ss = Statement("texunit", 0) - if self.textures=='INLINE': + if self.single_file: ss.sub.append(tech_res.create_embed_statement("texture2d", tex_res)) elif not diffuse_tex.default_filter: ss.sub.append(tech_res.create_reference_statement("texture2d", tex_res)) diff --git a/blender/io_mspgl/export_object.py b/blender/io_mspgl/export_object.py index bcd2c6ec..ad76336b 100644 --- a/blender/io_mspgl/export_object.py +++ b/blender/io_mspgl/export_object.py @@ -6,9 +6,8 @@ class ObjectExporter: self.show_progress = True self.use_strips = True self.use_degen_tris = False - self.textures = "REF" - self.separate_mesh = False - self.separate_tech = False + self.use_textures = True + self.single_file = True self.shared_resources = True self.export_lods = True @@ -45,7 +44,8 @@ class ObjectExporter: def create_material_exporter(self): from .export_material import MaterialExporter material_export = MaterialExporter() - material_export.textures = self.textures + material_export.single_file = self.single_file + material_export.use_textures = self.use_textures return material_export def export_to_file(self, context, out_fn): @@ -131,7 +131,7 @@ class ObjectExporter: if l.data.name!=prev_mesh: mesh_res = resources[l.data.name+".mesh"] - if self.separate_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)) @@ -149,7 +149,7 @@ class ObjectExporter: if tech_res.name!=prev_tech: if material and material.technique and not material.inherit_tech: lod_st.append(Statement("technique", material.technique)) - elif self.separate_tech: + 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)) diff --git a/blender/io_mspgl/export_scene.py b/blender/io_mspgl/export_scene.py index b4b9c236..d4e6b78f 100644 --- a/blender/io_mspgl/export_scene.py +++ b/blender/io_mspgl/export_scene.py @@ -76,8 +76,7 @@ class SceneExporter: def export_scene_resources(self, context, objs, resources, progress): from .export_object import ObjectExporter object_export = ObjectExporter() - object_export.separate_mesh = True - object_export.separate_tech = True + object_export.single_file = False for i, o in enumerate(objs): progress.push_task_slice(o.name, i, len(objs)) diff --git a/blender/io_mspgl/export_texture.py b/blender/io_mspgl/export_texture.py index fea02a7d..1cf32afe 100644 --- a/blender/io_mspgl/export_texture.py +++ b/blender/io_mspgl/export_texture.py @@ -1,6 +1,6 @@ class TextureExporter: def __init__(self): - self.pixels = 'REF' + self.inline_data = True def export_texture(self, texture): from .datafile import Resource, Statement, Token @@ -20,7 +20,7 @@ class TextureExporter: else: tex_res.statements.append(Statement("min_filter", Token('NEAREST'))) - if self.pixels=='REF': + if not self.inline_data: from .util import image_name tex_res.statements.append(Statement("image_data", image_name(texture.image))) else: -- 2.43.0