From: Mikko Rasa Date: Sat, 5 Mar 2022 09:00:58 +0000 (+0200) Subject: Make texture channel handling in the Blender exporter more flexible X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=1ebae998eb54c3f33900dc76de3b34c2d5252e58;p=libs%2Fgl.git Make texture channel handling in the Blender exporter more flexible Any channel can now be inverted (though the shader graph inspection does not detect this yet), so a separate invert_green channel is no longer needed. --- diff --git a/blender/io_mspgl/export_material.py b/blender/io_mspgl/export_material.py index a109ed24..ffdae1cc 100644 --- a/blender/io_mspgl/export_material.py +++ b/blender/io_mspgl/export_material.py @@ -79,7 +79,7 @@ class MaterialExporter: tex_name = p.texture.image.name+".tex2d" if tex_name not in resources: - resources[tex_name] = texture_export.export_texture(p.texture, p.tex_usage, invert_green=p.invert_green) + resources[tex_name] = texture_export.export_texture(p.texture, p.tex_channels) samp_name = sampler_export.get_sampler_name(p.texture) if samp_name not in resources: diff --git a/blender/io_mspgl/export_texture.py b/blender/io_mspgl/export_texture.py index c304fd7e..eb6fa223 100644 --- a/blender/io_mspgl/export_texture.py +++ b/blender/io_mspgl/export_texture.py @@ -11,18 +11,21 @@ def pixels_to_rgb(pixels): yield int(pixels[i+1]*255) yield int(pixels[i+2]*255) -def pixels_to_rgb_invert_green(pixels): +def pixels_to_rgb_invert(pixels, mask): for i in range(0, len(pixels), 4): - yield int(pixels[i]*255) - yield 255-int(pixels[i+1]*255) - yield int(pixels[i+2]*255) + r = int(pixels[i]*255) + yield 255-r if mask&1 else r + g = int(pixels[i+1]*255) + yield 255-g if mask&2 else g + b = int(pixels[i+2]*255) + yield 255-b if mask&4 else b def pixels_to_gray(pixels): for i in range(0, len(pixels), 4): yield int((pixels[i]+pixels[i+1]+pixels[i+2])*255/3) class TextureExporter: - def export_texture(self, tex_node, usage='RGB', *, invert_green=False): + def export_texture(self, tex_node, channels=['R', 'G', 'B']): image = tex_node.image from .datafile import RawData, Resource, Statement, Token tex_res = Resource(image.name+".tex", "texture") @@ -33,20 +36,22 @@ class TextureExporter: tex_res.statements.append(Statement("generate_mipmap", True)) colorspace = image.colorspace_settings.name - if usage=='GRAY' and colorspace=='sRGB': + if len(channels)==1 and colorspace=='sRGB': raise Exception("Unsupported configuration on texture {}: Grayscale with sRGB".format(image.name)) + invert_mask = sum(1<