]> git.tdb.fi Git - libs/gl.git/commitdiff
Replace single file mode in object exporter with collection
authorMikko Rasa <tdb@tdb.fi>
Sat, 27 Jun 2020 08:57:58 +0000 (11:57 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sat, 27 Jun 2020 09:02:17 +0000 (12:02 +0300)
blender/io_mspgl/__init__.py
blender/io_mspgl/export_material.py
blender/io_mspgl/export_object.py

index a1869e3ecd74ee7ca2efb5e8c79477483c0c44b4..bcb196c3a87db1128cebec1f1045577b8a8dfa1f 100644 (file)
@@ -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"
index 8f9bdd40ba31a72c7c7c8d61add3a8a11c67f02d..0a75c47a761e929bbd5bf1c4485406357b99eb61 100644 (file)
@@ -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)
index 6cc0be31bf93217d90014c83e8ef95311615757b..a86ee26b878dd67596c5fba58a01f8d545136a4b 100644 (file)
@@ -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: