X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=blender%2Fio_mspgl%2Fexport_material.py;h=c7ca765cb0736c9387c5742b0b9e76a3f0e7c106;hb=c3ebbcb56c1ca9bb3022a7f49aab1da5e09150ba;hp=1e5ebe6266f387000802d7f1827e7e0661d2ecac;hpb=cf6eec94b7d02885c00c6b8d79380aae7d7669f5;p=libs%2Fgl.git diff --git a/blender/io_mspgl/export_material.py b/blender/io_mspgl/export_material.py index 1e5ebe62..c7ca765c 100644 --- a/blender/io_mspgl/export_material.py +++ b/blender/io_mspgl/export_material.py @@ -11,7 +11,16 @@ def create_technique_resource(material, resources): 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)) + + if material.uniforms: + ss = Statement("uniforms") + for u in material.uniforms: + ss.sub.append(Statement("uniform", u.name, *u.values[:u.size])) + st.sub.append(ss) tech_res.statements.append(st) @@ -37,7 +46,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: @@ -61,55 +70,55 @@ class MaterialExporter: from .datafile import Resource, Statement mat_res = Resource(material.name+".mat", "material") - if material.type!="pbr": + if material.type!="pbr" and material.type!="unlit": 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) + 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"] 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 @@ -122,7 +131,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") @@ -132,5 +141,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)