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