- st.sub.append(tech_res.create_reference_statement("material", mat_res))
-
- if "diffuse_map" in textures:
- diffuse_tex = textures["diffuse_map"]
- tex_res = resources[diffuse_tex.name+".tex2d"]
- ss = Statement("texunit", 0)
- if self.single_file:
- ss.sub.append(tech_res.create_embed_statement("texture2d", tex_res))
- elif diffuse_tex.default_filter and diffuse_tex.image.filepath:
- ss.sub.append(Statement("texture", os.path.basename(diffuse_tex.image.filepath)))
- else:
- ss.sub.append(tech_res.create_reference_statement("texture", tex_res))
- st.sub.append(ss)
-
- tech_res.statements.append(st)
-
- return tech_res
-
- def export_material(self, material):
- from .datafile import Resource, Statement
- mat_res = Resource(material.name+".mat")
- statements = mat_res.statements
-
- from .util import get_colormap
- cm = get_colormap(material.srgb_colors)
-
- if any(s.use_map_color_diffuse for s in material.texture_slots if s):
- statements.append(Statement("diffuse", 1.0, 1.0, 1.0, 1.0))
- amb = cm(material.ambient)
- statements.append(Statement("ambient", amb, amb, amb, 1.0))
- else:
- diff = material.diffuse_color*material.diffuse_intensity
- statements.append(Statement("diffuse", cm(diff.r), cm(diff.g), cm(diff.b), 1.0))
- amb = diff*material.ambient
- statements.append(Statement("ambient", cm(amb.r), cm(amb.g), cm(amb.b), 1.0))
- spec = material.specular_color*material.specular_intensity
- statements.append(Statement("specular", cm(spec.r), cm(spec.g), cm(spec.g), 1.0))
- statements.append(Statement("shininess", material.specular_hardness))
+ resources[mat_name] = None
+
+ def export_technique(self, material, resources):
+ return create_technique_resource(material, resources)
+
+ def export_material(self, material, resources):
+ from .datafile import Resource, Statement, Token
+ mat_res = Resource(material.name+".mat", "material")
+
+ if material.type!="pbr" and material.type!="unlit":
+ raise Exception("Can't export material {} of unknown type {}".format(material.name, material.type))
+
+ mat_res.statements.append(Statement("type", Token(material.type)));
+ for p in material.properties:
+ st = self.create_property_statement(mat_res, p, resources)
+ if st:
+ mat_res.statements.append(st)
+ textures = [p.texture for p in material.properties if p.texture]
+ if textures:
+ from .export_texture import SamplerExporter
+ sampler_export = SamplerExporter()
+ mat_res.statements.append(mat_res.create_reference_statement("sampler", resources[sampler_export.get_sampler_name(textures[0])]))