+
+ def create_property_statement(self, mat_res, prop, keyword, resources, *, tex_only=False):
+ 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)
+ if self.single_file:
+ raise Exception("Can't export textures to a single file")
+ elif prop.texture.default_filter and fn:
+ return Statement(keyword+"_map", fn)
+ else:
+ return mat_res.create_reference_statement(keyword+"_map", tex_res)
+ elif type(prop.value)==tuple:
+ return Statement(keyword, *prop.value)
+ else:
+ return Statement(keyword, prop.value)
+
+
+class MaterialMapExporter:
+ def __init__(self):
+ self.single_file = True
+
+ def export_technique_resources(self, material_map, resources):
+ from .datafile import Resource, Statement, Token
+ base_color_name = material_map.name+"_base_color.tex2d"
+ if base_color_name not in resources:
+ base_color_res = Resource(base_color_name)
+
+ base_color_res.statements.append(Statement("min_filter", Token('NEAREST')))
+ base_color_res.statements.append(Statement("mag_filter", Token('NEAREST')))
+ 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))
+
+ resources[base_color_name] = base_color_res
+
+ mat_name = material_map.name+".mat"
+ if mat_name not in resources:
+ mat_res = Resource(mat_name)
+ st = Statement("pbr")
+ st.sub.append(mat_res.create_reference_statement("base_color_map", base_color_res))
+ mat_res.statements.append(st)
+
+ resources[mat_name] = mat_res
+
+ def export_technique(self, material_map, *, resources):
+ return create_technique_resource(material_map, resources, self.single_file)