Always export texture data inline if there's no image file
authorMikko Rasa <tdb@tdb.fi>
Wed, 29 May 2019 17:17:56 +0000 (20:17 +0300)
committerMikko Rasa <tdb@tdb.fi>
Wed, 29 May 2019 17:17:56 +0000 (20:17 +0300)
This allows exporting packed or baked textures.

blender/io_mspgl/export_material.py
blender/io_mspgl/export_texture.py
blender/io_mspgl/util.py

index c3aa654e41ed16ffb6a84e20b93e490f84fdac8e..956f51d430b41acb8e48f2fdc42376971c2f3453 100644 (file)
@@ -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)
index 23c5777d39ce4b2e92401bacda2ebc0da4e74c68..0a43ce624cfb296348e9a08c2cf4ada186f8068f 100644 (file)
@@ -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
index 70b005f6df60e84db38ea8c35c03fc0bbcc79123..6e8ec7746bde7c41b5c4791dfca602d7dd65503b 100644 (file)
@@ -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