- tech_res = Resource(material.name+".tech")
-
- mat_res = resources[material.name+".mat"]
- textures = {}
- if self.textures!='NONE':
- image_texture_slots = [s for s in material.texture_slots if s and s.texture.type=='IMAGE' and s.texture.image]
- for s in image_texture_slots:
- if s.use_map_color_diffuse:
- textures["diffuse_map"] = s.texture
- elif s.use_map_normal:
- textures["normal_map"] = s.texture
-
- if material.technique:
- if not obj.inherit_tech:
- return []
-
- st = Statement("inherit", material.technique)
- for s, t in textures.items():
- st.sub.append(Statement("texture", s, image_name(t.image)))
- if material.override_material:
- st.sub.append(tech_res.create_reference_statement("material", "surface", mat_res))
- tech_res.statements.append(st)
+ mat_res = Resource(material.name+".mat")
+
+ st = Statement("pbr")
+ st.sub.append(self.create_property_statement(mat_res, material.base_color, "base_color", resources))
+ st.sub.append(self.create_property_statement(mat_res, material.metalness, "metalness", resources))
+ st.sub.append(self.create_property_statement(mat_res, material.roughness, "roughness", resources))
+ st.sub.append(self.create_property_statement(mat_res, material.normal, "normal", resources, tex_only=True))
+ st.sub.append(self.create_property_statement(mat_res, material.emission, "emission", resources))
+ mat_res.statements.append(st)
+
+ return mat_res
+
+ 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)