5 self.inline_data = True
7 def export_texture(self, tex_node, usage='RGB'):
9 from .datafile import Resource, Statement, Token
10 tex_res = Resource(image.name+".tex2d", "texture2d")
12 use_interpolation = tex_node.interpolation!='Closest'
14 if tex_node.use_mipmap:
15 tex_res.statements.append(Statement("filter", Token('LINEAR_MIPMAP_LINEAR')))
16 tex_res.statements.append(Statement("generate_mipmap", True))
18 tex_res.statements.append(Statement("filter", Token('LINEAR')))
19 tex_res.statements.append(Statement("max_anisotropy", tex_node.max_anisotropy))
21 if tex_node.use_mipmap:
22 tex_res.statements.append(Statement("filter", Token('NEAREST_MIPMAP_NEAREST')))
23 tex_res.statements.append(Statement("generate_mipmap", True))
25 tex_res.statements.append(Statement("filter", Token('NEAREST')))
27 colorspace = image.colorspace_settings.name
28 if usage=='GRAY' and colorspace=='sRGB':
29 raise Exception("Grayscale textures with sRGB colorspace are not supported")
31 fn = os.path.basename(image.filepath)
32 if not self.inline_data and fn:
33 srgb = "_srgb" if colorspace=='sRGB' else ""
34 tex_res.statements.append(Statement("external_image"+srgb, fn))
37 fmt = 'SRGB8_ALPHA8' if colorspace=='sRGB' else 'RGBA8'
41 fmt = 'SRGB8' if colorspace=='sRGB' else 'RGB8'
43 tex_res.statements.append(Statement("storage", Token(fmt), image.size[0], image.size[1]))
47 for p in image.pixels:
48 texdata += "\\x{:02X}".format(int(p*255))
50 for i in range(0, len(image.pixels), 4):
51 texdata += "\\x{:02X}".format(image.pixels[i])
53 for i in range(0, len(image.pixels), 4):
55 texdata += "\\x{:02X}".format(int(image.pixels[i+j]*255))
56 tex_res.statements.append(Statement("raw_data", texdata))