From 03d2f0d7f4673b5262f396fda430e766eec4549b Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sat, 17 Apr 2021 13:14:50 +0300 Subject: [PATCH] Some minor refactoring of the exporter Move scene resources export to a separate function and remove some unused bits. --- blender/io_mspgl/export_material.py | 4 ---- blender/io_mspgl/export_scene.py | 24 +++++++++++++----------- blender/io_mspgl/export_texture.py | 5 +---- blender/io_mspgl/material.py | 4 +--- 4 files changed, 15 insertions(+), 22 deletions(-) diff --git a/blender/io_mspgl/export_material.py b/blender/io_mspgl/export_material.py index 6abd78c2..69662218 100644 --- a/blender/io_mspgl/export_material.py +++ b/blender/io_mspgl/export_material.py @@ -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): diff --git a/blender/io_mspgl/export_scene.py b/blender/io_mspgl/export_scene.py index 7f4c183a..63ca1f38 100644 --- a/blender/io_mspgl/export_scene.py +++ b/blender/io_mspgl/export_scene.py @@ -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") diff --git a/blender/io_mspgl/export_texture.py b/blender/io_mspgl/export_texture.py index 8e3872b5..7661b90b 100644 --- a/blender/io_mspgl/export_texture.py +++ b/blender/io_mspgl/export_texture.py @@ -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: diff --git a/blender/io_mspgl/material.py b/blender/io_mspgl/material.py index cadfe75e..a24c09e3 100644 --- a/blender/io_mspgl/material.py +++ b/blender/io_mspgl/material.py @@ -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) -- 2.45.2