X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=blender%2Fio_mspgl%2Fmaterial.py;h=ba5fc3e2c6cb7567b0563b391cf8d4a3c0c21cf2;hb=160293feec7b0b976856685153cd24c7f1ce9492;hp=e69cab844e3f2aa7cb4649eca55e2291e3da922f;hpb=b5a249d7f4dbbbf91c970993eb0eb949797c5565;p=libs%2Fgl.git diff --git a/blender/io_mspgl/material.py b/blender/io_mspgl/material.py index e69cab84..ba5fc3e2 100644 --- a/blender/io_mspgl/material.py +++ b/blender/io_mspgl/material.py @@ -8,6 +8,33 @@ def get_linked_node_and_socket(node_tree, socket): return (l.to_node, l.to_socket) return (None, None) +def check_group(node_tree, group, func): + output = group.node_tree.nodes["Group Output"] + from_node, _ = get_linked_node_and_socket(group.node_tree, output.inputs[0]) + if from_node: + from_node, _ = func(group.node_tree, from_node) + if from_node and from_node.type=='GROUP_INPUT': + return get_linked_node_and_socket(node_tree, group.inputs[0]) + return (None, None) + +def check_invert_green(node_tree, node): + if node.type=='GROUP': + return check_group(node_tree, node, check_invert_green) + elif node.type!='COMBRGB': + return (None, None) + + green, g_sock = get_linked_node_and_socket(node_tree, node.inputs["G"]) + if not green or green.type!='MATH' or green.operation!='SUBTRACT': + return (None, None) + green, g_sock = get_linked_node_and_socket(node_tree, green.inputs[1]) + + red, r_sock = get_linked_node_and_socket(node_tree, node.inputs["R"]) + blue, b_sock = get_linked_node_and_socket(node_tree, node.inputs["B"]) + if not red or red.type!='SEPRGB' or blue!=red or green!=red: + return (None, None) + + return get_linked_node_and_socket(node_tree, red.inputs["Image"]) + class MaterialProperty: def __init__(self, keyword, tex_keyword, value): self.keyword = keyword @@ -15,6 +42,7 @@ class MaterialProperty: self.value = value self.texture = None self.tex_usage = None + self.invert_green = False def set_from_input(self, node_tree, input_socket, alpha_socket=None): if self.keyword: @@ -33,6 +61,10 @@ class MaterialProperty: usage = None if from_node.type=='NORMAL_MAP': from_node, _ = get_linked_node_and_socket(node_tree, from_node.inputs["Color"]) + invert, _ = check_invert_green(node_tree, from_node) + if invert: + from_node = invert + self.invert_green = True usage = 'RGB' elif from_node.type=='RGBTOBW': from_node, _ = get_linked_node_and_socket(node_tree, from_node.inputs["Color"]) @@ -66,9 +98,9 @@ class Material: self.shader = material.shader if self.render_mode=='EXTERNAL' and not self.technique: - raise Exception("Missing technique with external rendering mode") + raise Exception("Invalid configuration on material {}: No technique for external rendering".format(self.name)) elif self.render_mode=='CUSTOM' and not self.shader: - raise Exception("Missing shader with custom rendering mode") + raise Exception("Invalid configuration on material {}: No shader for custom rendering".format(self.name)) out_node = None for n in material.node_tree.nodes: @@ -77,12 +109,12 @@ class Material: break if not out_node: - raise Exception("No material output node found") + raise Exception("No output node found on material {}".format(self.name)) surface_node, _ = get_linked_node_and_socket(material.node_tree, out_node.inputs["Surface"]) if not surface_node: if self.render_mode=='BUILTIN': - raise Exception("Empty material can't use builtin rendering mode") + raise Exception("Invalid configuration on material {}: Empty material with builtin rendering".format(self.name)) return elif surface_node.type=='BSDF_PRINCIPLED': self.type = "pbr" @@ -105,7 +137,7 @@ class Material: color.set_from_input(material.node_tree, surface_node.inputs["Color"]) else: - raise Exception("Unsupported surface node type "+surface_node.type) + raise Exception("Unsupported surface node type {} on material {}".format(surface_node.type, self.name)) sampler_settings = None for p in self.properties: @@ -114,7 +146,7 @@ class Material: if sampler_settings is None: sampler_settings = settings elif settings!=sampler_settings: - raise Exception("Conflicting sampler settings in material textures") + raise Exception("Material {} has conflicting texture sampler settings".format(self.name)) def create_property(self, *args): prop = None @@ -183,6 +215,4 @@ def create_material_atlas(context, material): if m.material_atlas and m.shader==shader: materials.append(m) - mat_map = MaterialAtlas(materials) - - return mat_map + return MaterialAtlas(materials)