]> git.tdb.fi Git - libs/gl.git/blobdiff - blender/io_mspgl/material.py
Remove default sampler from Texture
[libs/gl.git] / blender / io_mspgl / material.py
index cadfe75e09b5ef4589da97a5e99c8caec34e3538..1d6a06a0b0730974365d21e65a3f19760b566bea 100644 (file)
@@ -1,14 +1,8 @@
 import os
 
-def get_linked_node_and_socket(node_tree, socket):
-       for l in node_tree.links:
-               if socket==l.to_socket:
-                       return (l.from_node, l.from_socket)
-               elif socket==l.from_socket:
-                       return (l.to_node, l.to_socket)
-       return (None, None)
-
 def check_group(node_tree, group, func):
+       from .util import get_linked_node_and_socket
+
        output = group.node_tree.nodes["Group Output"]
        from_node, _ = get_linked_node_and_socket(group.node_tree, output.inputs[0])
        if from_node:
@@ -23,6 +17,8 @@ def check_invert_green(node_tree, node):
        elif node.type!='COMBRGB':
                return (None, None)
 
+       from .util import get_linked_node_and_socket
+
        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)
@@ -55,6 +51,8 @@ class MaterialProperty:
                                self.value = input_socket.default_value
 
                if self.tex_keyword:
+                       from .util import get_linked_node_and_socket
+
                        from_node, _ = get_linked_node_and_socket(node_tree, input_socket)
                        alpha_from = None
                        if from_node:
@@ -96,25 +94,25 @@ class Material:
                self.render_mode = material.render_mode
                self.technique = material.technique
                self.shader = material.shader
+               self.receive_shadows = material.receive_shadows
+               self.cast_shadows = (material.shadow_method!='NONE')
+               self.image_based_lighting = material.image_based_lighting
 
                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")
-
-               out_node = None
-               for n in material.node_tree.nodes:
-                       if n.type=='OUTPUT_MATERIAL':
-                               out_node = n
-                               break
+                       raise Exception("Invalid configuration on material {}: No shader for custom rendering".format(self.name))
 
+               out_node = next((n for n in material.node_tree.nodes if n.type=='OUTPUT_MATERIAL'), None)
                if not out_node:
-                       raise Exception("No material output node found")
+                       raise Exception("No output node found on material {}".format(self.name))
+
+               from .util import get_linked_node_and_socket
 
                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"
@@ -137,16 +135,16 @@ 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:
                        if p.texture:
-                               settings = (p.texture.default_filter, p.texture.interpolation, p.texture.use_mipmap, p.texture.max_anisotropy)
+                               settings = (p.texture.interpolation, p.texture.use_mipmap, p.texture.max_anisotropy)
                                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
@@ -171,6 +169,8 @@ class MaterialAtlas:
                        self.name = "material_atlas_"+os.path.splitext(self.shader)[0]
                else:
                        self.name = "material_atlas"
+               self.receive_shadows = materials[0].receive_shadows
+               self.cast_shadows = (materials[0].shadow_method!='NONE')
                self.materials = materials
                self.material_names = [m.name for m in self.materials]
                for m in self.materials:
@@ -178,6 +178,8 @@ class MaterialAtlas:
                                raise Exception("Conflicting render modes in MaterialAtlas constructor")
                        if self.render_mode=='CUSTOM' and m.shader!=self.shader:
                                raise Exception("Conflicting shaders in MaterialAtlas constructor")
+                       if m.receive_shadows!=self.receive_shadows or m.shadow_method!=materials[0].shadow_method:
+                               raise Exception("Conflicting shadow settings in MaterialAtlas constructor")
 
                count = len(self.materials)
                size = 1
@@ -215,6 +217,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)