]> git.tdb.fi Git - libs/gl.git/commitdiff
Simplify the resource separation options
authorMikko Rasa <tdb@tdb.fi>
Sat, 18 May 2019 07:45:23 +0000 (10:45 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sat, 18 May 2019 07:59:13 +0000 (10:59 +0300)
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
blender/io_mspgl/export_material.py
blender/io_mspgl/export_object.py
blender/io_mspgl/export_scene.py
blender/io_mspgl/export_texture.py

index b24f28d988578c1b17637f18b69c901367723134..133b844c2a7d6152f833c58f320f2b54b3c94779 100644 (file)
@@ -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):
index 3f0117d40a210909ce5075ec9b952e68619d661a..289fb8810d4beff83826d4a4905c11bdd71e3b39 100644 (file)
@@ -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))
index bcd2c6ecfb05c70a0646a603cc0a6456ebd52317..ad76336b3c09d41197c9c9fa73b6a1e8adad4090 100644 (file)
@@ -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))
index b4b9c2365bc22ea14b7f11fec5c06120c74fb870..d4e6b78f021154cba46388c53cc2c28ad5f1cf1b 100644 (file)
@@ -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))
index fea02a7d7e3d885cc606be138bdb01dda93f58f8..1cf32afeb59072a58f67fc4fe8b529b8549cd522 100644 (file)
@@ -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: