]> git.tdb.fi Git - libs/gl.git/commitdiff
Some minor refactoring of the exporter
authorMikko Rasa <tdb@tdb.fi>
Sat, 17 Apr 2021 10:14:50 +0000 (13:14 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sat, 17 Apr 2021 10:31:27 +0000 (13:31 +0300)
Move scene resources export to a separate function and remove some
unused bits.

blender/io_mspgl/export_material.py
blender/io_mspgl/export_scene.py
blender/io_mspgl/export_texture.py
blender/io_mspgl/material.py

index 6abd78c2d05b8157a429405c02e8ad208a772448..696622183153a5b0d244d0eda3ca64dafdb74159 100644 (file)
@@ -27,13 +27,9 @@ def create_technique_resource(material, resources):
        return tech_res
 
 class MaterialExporter:
-       def __init__(self):
-               self.inline_texture_data = False
-
        def create_texture_exporter(self):
                from .export_texture import TextureExporter
                texture_export = TextureExporter()
-               texture_export.inline_data = self.inline_texture_data
                return texture_export
 
        def export_technique_resources(self, material, resources):
index 7f4c183aee3fe47011b1b292916e299b86e16e04..63ca1f38ec2717f61c403c363677f89f5ff151c2 100644 (file)
@@ -10,24 +10,20 @@ class SceneExporter:
                self.show_progress = True
 
        def export_to_file(self, context, out_fn):
-               from .scene import create_scene_from_current
-               scene = create_scene_from_current(context, selected_only=self.selected_only, visible_only=self.visible_only)
-
-               path, base = os.path.split(out_fn)
-               base, ext = os.path.splitext(base)
-
                from .util import Progress
                progress = Progress(self.show_progress and context)
 
-               from .export import DataExporter
-               data_exporter = DataExporter()
+               from .scene import create_scene_from_current
+               scene = create_scene_from_current(context, selected_only=self.selected_only, visible_only=self.visible_only)
 
                resources = {}
-               data_exporter.export_resources(context, scene.prototypes, resources, None, progress)
+               self.export_scene_resources(context, scene, resources, progress)
                scene_res = self.export_scene(scene, resources)
-               refs = scene_res.collect_references()
                progress.set_progress(1.0)
 
+               path, base = os.path.split(out_fn)
+               base, ext = os.path.splitext(base)
+
                if self.collection:
                        existing = None
                        if self.skip_existing:
@@ -35,9 +31,15 @@ class SceneExporter:
                        scene_res.write_collection(out_fn, filter=existing)
                else:
                        scene_res.write_to_file(out_fn)
-                       for r in refs:
+                       for r in scene_res.collect_references():
                                r.write_to_file(os.path.join(path, r.name))
 
+       def export_scene_resources(self, context, scene, resources, progress):
+               from .export import DataExporter
+               data_exporter = DataExporter()
+
+               data_exporter.export_resources(context, scene.prototypes, resources, None, progress)
+
        def export_scene(self, scene, resources):
                from .datafile import Resource, Statement, Token
                scene_res = Resource(scene.name+".scene", "scene")
index 8e3872b5c8646f1084c83324b73f15499c9d9e9a..7661b90b2fa5e1d91c5ba0410689904d29681bdb 100644 (file)
@@ -26,9 +26,6 @@ def pixels_to_gray(pixels):
                yield int((pixels[i]+pixels[i+1]+pixels[i+2])*255/3)
 
 class TextureExporter:
-       def __init__(self):
-               self.inline_data = True
-
        def export_texture(self, tex_node, usage='RGB', *, invert_green=False):
                image = tex_node.image
                from .datafile import Resource, Statement, Token
@@ -43,7 +40,7 @@ class TextureExporter:
 
                from .util import basename
                fn = basename(image.filepath)
-               if not self.inline_data and not invert_green and fn:
+               if not invert_green and fn:
                        srgb = "_srgb" if colorspace=='sRGB' else ""
                        tex_res.statements.append(Statement("external_image"+srgb, fn))
                else:
index cadfe75e09b5ef4589da97a5e99c8caec34e3538..a24c09e3b59dd59a05f9c3ba504afd398a1f7fbf 100644 (file)
@@ -215,6 +215,4 @@ def create_material_atlas(context, material):
                if m.material_atlas and m.shader==shader:
                        materials.append(m)
 
-       mat_map = MaterialAtlas(materials)
-
-       return mat_map
+       return MaterialAtlas(materials)