- resources[mat_name] = self.export_material(material)
-
- if self.textures=='INLINE':
- for s in material.texture_slots:
- if s and s.texture.type=='IMAGE' and s.texture.image:
- tex_name = s.texture.name+".tex2d"
- if tex_name not in resources:
- resources[tex_name] = texture_export.export_texture(s.texture)
-
- def export_technique(self, material, *, resources):
- from .datafile import Resource, Statement
- 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)
+ if material.type:
+ resources[mat_name] = self.export_material(material, resources)
+ else:
+ resources[mat_name] = None
+
+ def export_technique(self, material, resources):
+ from .material import Material
+ if type(material)!=Material:
+ material = Material(material)
+
+ 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])]))
+
+ return mat_res
+
+ def create_property_statement(self, mat_res, prop, resources):
+ from .datafile import Statement
+ if prop.texture:
+ from .export_texture import TextureExporter
+ texture_export = TextureExporter()
+ tex_res = resources[texture_export.get_texture_name(prop.texture, prop.tex_channels)]
+ return mat_res.create_reference_statement(prop.tex_keyword, tex_res)
+ elif not prop.keyword:
+ return
+ elif type(prop.value)==tuple:
+ return Statement(prop.keyword, *prop.value)