From: Mikko Rasa Date: Sat, 13 Feb 2021 18:53:41 +0000 (+0200) Subject: Support exporting "empty" materials with only a technique or shader X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=commitdiff_plain;h=63f2a2ab4e13392b3add0cefcb65c193451ee4d3 Support exporting "empty" materials with only a technique or shader --- diff --git a/blender/io_mspgl/export_material.py b/blender/io_mspgl/export_material.py index 2df04ff6..266790f2 100644 --- a/blender/io_mspgl/export_material.py +++ b/blender/io_mspgl/export_material.py @@ -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: diff --git a/blender/io_mspgl/material.py b/blender/io_mspgl/material.py index e8a9089a..3b790361 100644 --- a/blender/io_mspgl/material.py +++ b/blender/io_mspgl/material.py @@ -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)