From: Mikko Rasa Date: Wed, 29 May 2019 17:17:56 +0000 (+0300) Subject: Always export texture data inline if there's no image file X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=5be6340cbd5da619db56e1658da56840fcfd6293;p=libs%2Fgl.git Always export texture data inline if there's no image file This allows exporting packed or baked textures. --- diff --git a/blender/io_mspgl/export_material.py b/blender/io_mspgl/export_material.py index c3aa654e..956f51d4 100644 --- a/blender/io_mspgl/export_material.py +++ b/blender/io_mspgl/export_material.py @@ -48,8 +48,8 @@ class MaterialExporter: st = Statement("inherit", material.technique) for s, t in textures.items(): - if t.default_filter: - st.sub.append(Statement("texture", s, image_name(t.image))) + if t.default_filter and t.image.filepath: + st.sub.append(Statement("texture", s, os.path.basename(t.image.filepath))) else: st.sub.append(tech_res.create_reference_statement("texture", s, resources[t.name+".tex2d"])) if material.override_material: @@ -68,10 +68,10 @@ class MaterialExporter: ss = Statement("texunit", 0) 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("texture", tex_res)) + elif diffuse_tex.default_filter and diffuse_tex.image.filepath: + ss.sub.append(Statement("texture", os.path.basename(diffuse_tex.image.filepath))) else: - ss.sub.append(Statement("texture", image_name(diffuse_tex.image))) + ss.sub.append(tech_res.create_reference_statement("texture", tex_res)) st.sub.append(ss) tech_res.statements.append(st) diff --git a/blender/io_mspgl/export_texture.py b/blender/io_mspgl/export_texture.py index 23c5777d..0a43ce62 100644 --- a/blender/io_mspgl/export_texture.py +++ b/blender/io_mspgl/export_texture.py @@ -1,3 +1,5 @@ +import os + class TextureExporter: def __init__(self): self.inline_data = True @@ -20,9 +22,9 @@ class TextureExporter: else: tex_res.statements.append(Statement("min_filter", Token('NEAREST'))) - if not self.inline_data: + if not self.inline_data and texture.image.filepath: from .util import image_name - tex_res.statements.append(Statement("external_image", image_name(texture.image))) + tex_res.statements.append(Statement("external_image", os.path.basename(texture.image.filepath))) else: texdata = "" colorspace = texture.image.colorspace_settings.name diff --git a/blender/io_mspgl/util.py b/blender/io_mspgl/util.py index 70b005f6..6e8ec774 100644 --- a/blender/io_mspgl/util.py +++ b/blender/io_mspgl/util.py @@ -1,5 +1,3 @@ -import os - class Progress: def __init__(self, context): self.task = "" @@ -63,10 +61,3 @@ def get_colormap(srgb): return linear_to_srgb else: return lambda x: x - -def image_name(img): - fp = img.filepath - if fp: - return os.path.split(fp)[1] - else: - return img.name