From 893c0645802c46eb60b04a87e79a5a4d69e32ea2 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 6 Mar 2022 13:21:28 +0200 Subject: [PATCH] Handle certain shader graph patterns that occur in imported glTF files --- blender/io_mspgl/export_material.py | 6 +++-- blender/io_mspgl/export_texture.py | 34 +++++++++++++++++++++++++---- blender/io_mspgl/material.py | 31 +++++++++++++++++++++++++- 3 files changed, 64 insertions(+), 7 deletions(-) diff --git a/blender/io_mspgl/export_material.py b/blender/io_mspgl/export_material.py index 8560984e..b0df347f 100644 --- a/blender/io_mspgl/export_material.py +++ b/blender/io_mspgl/export_material.py @@ -75,7 +75,7 @@ class MaterialExporter: for p in textured_props: ctx.next_slice(p.texture.image) - tex_name = p.texture.image.name+".tex" + tex_name = texture_export.get_texture_name(p.texture, p.tex_channels) if tex_name not in resources: resources[tex_name] = texture_export.export_texture(p.texture, p.tex_channels) @@ -121,7 +121,9 @@ class MaterialExporter: def create_property_statement(self, mat_res, prop, resources): from .datafile import Statement if prop.texture: - tex_res = resources[prop.texture.image.name+".tex"] + from .export_texture import TextureExporter + texture_export = TextureExporter() + tex_res = resources[texture_export.get_texture_name(prop.texture, prop.tex_channels)] return mat_res.create_reference_statement(prop.tex_keyword, tex_res) elif not prop.keyword: return diff --git a/blender/io_mspgl/export_texture.py b/blender/io_mspgl/export_texture.py index 3194edae..2860d461 100644 --- a/blender/io_mspgl/export_texture.py +++ b/blender/io_mspgl/export_texture.py @@ -23,11 +23,15 @@ 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) +def pixels_to_single_channel(pixels, channel): + for i in range(0, len(pixels), 4): + yield int(pixels[i+channel]*255) + class TextureExporter: 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") + tex_res = Resource(self.get_texture_name(tex_node, channels), "texture") tex_res.statements.append(Statement("type", Token("\\2d"))) @@ -41,7 +45,20 @@ class TextureExporter: invert_mask = sum(1<