]> git.tdb.fi Git - libs/gl.git/blob - blender/io_mspgl/export_texture.py
Use transform blocks to specify object transforms in exported scenes
[libs/gl.git] / blender / io_mspgl / export_texture.py
1 import os
2
3 class TextureExporter:
4         def __init__(self):
5                 self.inline_data = True
6
7         def export_texture(self, texture):
8                 from .datafile import Resource, Statement, Token
9                 tex_res = Resource(texture.name+".tex2d")
10
11                 if texture.use_interpolation:
12                         if texture.use_mipmap:
13                                 tex_res.statements.append(Statement("min_filter", Token('LINEAR_MIPMAP_LINEAR')))
14                                 tex_res.statements.append(Statement("generate_mipmap", True))
15                         else:
16                                 tex_res.statements.append(Statement("min_filter", Token('LINEAR')))
17                         tex_res.statements.append(Statement("max_anisotropy", texture.filter_eccentricity))
18                 else:
19                         if texture.use_mipmap:
20                                 tex_res.statements.append(Statement("min_filter", Token('NEAREST_MIPMAP_NEAREST')))
21                                 tex_res.statements.append(Statement("generate_mipmap", True))
22                         else:
23                                 tex_res.statements.append(Statement("min_filter", Token('NEAREST')))
24
25                 if not self.inline_data and texture.image.filepath:
26                         from .util import image_name
27                         tex_res.statements.append(Statement("external_image", os.path.basename(texture.image.filepath)))
28                 else:
29                         texdata = ""
30                         colorspace = texture.image.colorspace_settings.name
31                         if texture.use_alpha:
32                                 fmt = 'SRGB_ALPHA' if colorspace=='sRGB' else 'RGBA'
33                                 for p in texture.image.pixels:
34                                         texdata += "\\x{:02X}".format(int(p*255))
35                         else:
36                                 fmt = 'SRGB' if colorspace=='sRGB' else 'RGB'
37                                 for i in range(0, len(texture.image.pixels), 4):
38                                         for j in range(3):
39                                                 texdata += "\\x{:02X}".format(int(texture.image.pixels[i+j]*255))
40                         tex_res.statements.append(Statement("storage", Token(fmt), texture.image.size[0], texture.image.size[1]))
41                         tex_res.statements.append(Statement("raw_data", texdata))
42
43                 return tex_res