]> git.tdb.fi Git - libs/gl.git/commitdiff
Support exporting "empty" materials with only a technique or shader
authorMikko Rasa <tdb@tdb.fi>
Sat, 13 Feb 2021 18:53:41 +0000 (20:53 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sat, 13 Feb 2021 18:54:23 +0000 (20:54 +0200)
blender/io_mspgl/export_material.py
blender/io_mspgl/material.py

index 2df04ff6e4b5512228697d48c92ea2580e9f9707..266790f22d1dd4af80275e638c5565ebaf235c9b 100644 (file)
@@ -7,7 +7,8 @@ def create_technique_resource(material, resources):
        mat_res = resources[material.name+".mat"]
 
        st = Statement("pass", "")
-       st.sub.append(tech_res.create_embed_statement("material", mat_res))
+       if mat_res:
+               st.sub.append(tech_res.create_embed_statement("material", mat_res))
 
        if material.render_mode=='CUSTOM':
                st.sub.append(Statement("shader", material.shader))
@@ -48,7 +49,10 @@ class MaterialExporter:
 
                mat_name = material.name+".mat"
                if mat_name not in resources:
-                       resources[mat_name] = self.export_material(material, resources=resources)
+                       if material.type:
+                               resources[mat_name] = self.export_material(material, resources=resources)
+                       else:
+                               resources[mat_name] = None
 
        def export_technique(self, material, *, resources):
                return create_technique_resource(material, resources)
@@ -57,7 +61,10 @@ class MaterialExporter:
                from .datafile import Resource, Statement
                mat_res = Resource(material.name+".mat", "material")
 
-               st = Statement("pbr")
+               if material.type!="pbr":
+                       raise Exception("Can't export unknown material type "+material.type)
+
+               st = Statement(material.type)
                for kw, p in material.properties.items():
                        ss = self.create_property_statement(mat_res, p, kw, resources)
                        if ss:
index e8a9089adb3ffed538856da4fc3772403a7b018e..3b79036181d0d45ab6af0da226ef39cecb59e2d6 100644 (file)
@@ -48,6 +48,7 @@ class MaterialProperty:
 class Material:
        def __init__(self, material):
                self.name = material.name
+               self.type = None
                self.properties = {}
 
                self.render_mode = material.render_mode
@@ -70,10 +71,14 @@ class Material:
 
                surface_node, _ = get_linked_node_and_socket(material.node_tree, out_node.inputs["Surface"])
                if not surface_node:
-                       raise Exception("Material has no surface node")
+                       if self.render_mode=='BUILTIN':
+                               raise Exception("Empty material can't use builtin rendering mode")
+                       return
                elif surface_node.type!='BSDF_PRINCIPLED':
                        raise Exception("Unsupported surface node type "+surface_node.type)
 
+               self.type = "pbr"
+
                base_color = self.properties["base_color"] = MaterialProperty((0.8, 0.8, 0.8, 1.0))
                metalness = self.properties["metalness"] = MaterialProperty(0.0)
                roughness = self.properties["roughness"] = MaterialProperty(0.5)