"export_animation", "export_armature", "export_camera", "export_light",
"export_material", "export_mesh", "export_object", "export_scene",
"export_texture", "material", "mesh", "operators", "properties", "scene",
- "util")
+ "texture", "util")
if "bpy" in locals():
import imp
if tex_node.use_mipmap:
tex_res.statements.append(Statement("generate_mipmap", True))
- colorspace = image.colorspace_settings.name
- if len(channels)==1 and colorspace=='sRGB':
- raise Exception("Unsupported configuration on texture {}: Grayscale with sRGB".format(image.name))
+ from .texture import Texture
+ texture = Texture(tex_node, channels)
invert_mask = sum(1<<i for i, c in enumerate(channels) if c[0]=='~')
if not invert_mask and channels==native_channels:
if not tex_node.use_mipmap:
tex_res.statements.append(Statement("mipmap_levels", 1))
- srgb = "_srgb" if colorspace=='sRGB' else ""
+ srgb = "_srgb" if texture.srgb else ""
tex_res.statements.append(Statement("external_image"+srgb, fn))
else:
- if len(channels)==4:
- fmt = 'SRGB8_ALPHA8' if colorspace=='sRGB' else 'RGBA8'
- elif len(channels)==1:
- fmt = 'LUMINANCE8' if channels[0]=='Y' else 'R8'
- else:
- fmt = 'SRGB8' if colorspace=='sRGB' else 'RGB8'
-
- tex_res.statements.append(Statement("storage", Token(fmt), image.size[0], image.size[1]))
+ tex_res.statements.append(Statement("storage", Token(texture.pixelformat), texture.width, texture.height))
pixels = tuple(image.pixels)
texdata = ""
--- /dev/null
+class Texture:
+ def __init__(self, tex_node, channels):
+ self.image = tex_node.image
+
+ self.srgb = self.image.colorspace_settings.name=='sRGB'
+ if len(channels)==1 and self.srgb:
+ raise Exception("Unsupported configuration on texture {}: Grayscale with sRGB".format(self.image.name))
+
+ if len(channels)==4:
+ self.pixelformat = 'SRGB8_ALPHA8' if self.srgb else 'RGBA8'
+ elif len(channels)==1:
+ self.pixelformat = 'LUMINANCE8' if channels[0]=='Y' else 'R8'
+ else:
+ self.pixelformat = 'SRGB8' if self.srgb else 'RGB8'
+
+ self.width = self.image.size[0]
+ self.height = self.image.size[1]