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
29 fmt = 'SRGB_ALPHA' if colorspace=='sRGB' else 'RGBA'
31 if colorspace=='sRGB':
32 raise Exception("Grayscale textures with sRGB colorspace are not supported")
35 fmt = 'SRGB' if colorspace=='sRGB' else 'RGB'
37 tex_res.statements.append(Statement("storage", Token(fmt), image.size[0], image.size[1]))
39 fn = os.path.basename(image.filepath)
40 if not self.inline_data and fn:
41 tex_res.statements.append(Statement("external_image", fn))
45 for p in image.pixels:
46 texdata += "\\x{:02X}".format(int(p*255))
48 for i in range(0, len(image.pixels), 4):
49 texdata += "\\x{:02X}".format(image.pixels[i])
51 for i in range(0, len(image.pixels), 4):
53 texdata += "\\x{:02X}".format(int(image.pixels[i+j]*255))
54 tex_res.statements.append(Statement("raw_data", texdata))