X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=blender%2Fio_mspgl%2Fexport_material.py;h=5411280d3832596616ace8ea36608fd85e55dedc;hb=5bf3c7175c359ad8509702a4e0790609b39e6aec;hp=2df04ff6e4b5512228697d48c92ea2580e9f9707;hpb=f33612ba5ad6c65cc5cd1c101a816188e5955969;p=libs%2Fgl.git diff --git a/blender/io_mspgl/export_material.py b/blender/io_mspgl/export_material.py index 2df04ff6..5411280d 100644 --- a/blender/io_mspgl/export_material.py +++ b/blender/io_mspgl/export_material.py @@ -7,10 +7,14 @@ 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)) + shader = material.shader + if shader.endswith(".glsl"): + shader += ".shader" + st.sub.append(Statement("shader", shader)) tech_res.statements.append(st) @@ -36,7 +40,7 @@ class MaterialExporter: material = Material(material) if self.use_textures: - for p in material.properties.values(): + for p in material.properties: if p.texture: tex_name = p.texture.image.name+".tex2d" if tex_name not in resources: @@ -48,7 +52,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,51 +64,55 @@ class MaterialExporter: from .datafile import Resource, Statement mat_res = Resource(material.name+".mat", "material") - st = Statement("pbr") - for kw, p in material.properties.items(): - ss = self.create_property_statement(mat_res, p, kw, resources) + if material.type!="pbr" and material.type!="unlit": + raise Exception("Can't export unknown material type "+material.type) + + st = Statement(material.type) + for p in material.properties: + ss = self.create_property_statement(mat_res, p, resources) if ss: st.sub.append(ss) if self.use_textures: - first_tex = (p.texture for p in material.properties.values() if p.texture).__next__() - if first_tex and not first_tex.default_filter: + textures = [p.texture for p in material.properties if p.texture] + if textures and not textures[0].default_filter: from .export_texture import SamplerExporter sampler_export = SamplerExporter() - st.sub.append(mat_res.create_reference_statement("sampler", resources[sampler_export.get_sampler_name(first_tex)])) + st.sub.append(mat_res.create_reference_statement("sampler", resources[sampler_export.get_sampler_name(textures[0])])) mat_res.statements.append(st) return mat_res - def create_property_statement(self, mat_res, prop, keyword, resources): + def create_property_statement(self, mat_res, prop, resources): from .datafile import Statement if self.use_textures and prop.texture: tex_res = resources[prop.texture.image.name+".tex2d"] - fn = os.path.basename(prop.texture.image.filepath) + from .util import basename + fn = basename(prop.texture.image.filepath) if prop.texture.default_filter and fn: - return Statement(keyword+"_map", fn) + return Statement(prop.tex_keyword, fn) else: - return mat_res.create_reference_statement(keyword+"_map", tex_res) - elif prop.value is None: + return mat_res.create_reference_statement(prop.tex_keyword, tex_res) + elif not prop.keyword: return elif type(prop.value)==tuple: - return Statement(keyword, *prop.value) + return Statement(prop.keyword, *prop.value) else: - return Statement(keyword, prop.value) + return Statement(prop.keyword, prop.value) -class MaterialMapExporter: +class MaterialAtlasExporter: def __init__(self): pass - def export_technique_resources(self, material_map, resources): + def export_technique_resources(self, material_atlas, resources): from .datafile import Resource, Statement, Token - base_color_name = material_map.name+"_base_color.tex2d" + base_color_name = material_atlas.name+"_base_color.tex2d" base_color_res = resources.get(base_color_name) if not base_color_res: base_color_res = Resource(base_color_name, "texture2d") - base_color_res.statements.append(Statement("storage", Token('SRGB_ALPHA'), *material_map.size)) - base_color_res.statements.append(Statement("raw_data", material_map.base_color_data)) + base_color_res.statements.append(Statement("storage", Token('SRGB_ALPHA'), *material_atlas.size)) + base_color_res.statements.append(Statement("raw_data", material_atlas.base_color_data)) resources[base_color_name] = base_color_res @@ -114,7 +125,7 @@ class MaterialMapExporter: resources[sampler_name] = sampler_res - mat_name = material_map.name+".mat" + mat_name = material_atlas.name+".mat" if mat_name not in resources: mat_res = Resource(mat_name, "material") st = Statement("pbr") @@ -124,5 +135,5 @@ class MaterialMapExporter: resources[mat_name] = mat_res - def export_technique(self, material_map, *, resources): - return create_technique_resource(material_map, resources) + def export_technique(self, material_atlas, *, resources): + return create_technique_resource(material_atlas, resources)