7 return 1.055*(l**(1/2.4))-0.055
9 def get_colormap(srgb):
18 return os.path.split(fp)[1]
23 class MaterialExporter:
27 def export_technique_resources(self, material, resources):
28 from .export_texture import TextureExporter
29 texture_export = TextureExporter()
31 mat_name = material.name+".mat"
32 if mat_name not in resources:
33 resources[mat_name] = self.export_material(material)
35 if self.textures=='INLINE':
36 for s in material.texture_slots:
37 if s and s.texture.type=='IMAGE':
38 tex_name = s.texture.name+".tex2d"
39 if tex_name not in resources:
40 resources[tex_name] = texture_export.export_texture(s.texture)
42 def export_technique(self, material, *, resources):
43 from .datafile import Resource, Statement
44 tech_res = Resource(material.name+".tech")
46 mat_res = resources[material.name+".mat"]
47 image_texture_slots = [s for s in material.texture_slots if s and s.texture.type=='IMAGE']
49 if material.technique:
50 if not obj.inherit_tech:
53 st = Statement("inherit", material.technique)
54 for slot in image_texture_slots:
55 name = image_name(slot.texture.image)
56 if slot.use_map_color_diffuse:
57 st.sub.append(Statement("texture", "diffuse_map", name))
58 elif slot.use_map_normal:
59 st.sub.append(Statement("texture", "normal_map", name))
60 if material.override_material:
61 st.sub.append(tech_res.create_reference_statement("material", "surface", mat_res))
62 tech_res.statements.append(st)
64 st = Statement("pass", "")
65 st.sub.append(tech_res.create_embed_statement("material", mat_res))
67 if self.textures!='NONE':
69 for slot in image_texture_slots:
70 if slot.use_map_color_diffuse:
71 diffuse_tex = slot.texture
75 ss = Statement("texunit", 0)
76 if self.textures=='INLINE':
77 tex_res = resources[slot.texture.name+".tex2d"]
78 ss.sub.append(tech_res.create_embed_statement("texture2d", tex_res))
80 ss.sub.append(Statement("texture", image_name(tex.image)))
83 tech_res.statements.append(st)
87 def export_material(self, material):
88 from .datafile import Resource, Statement
89 mat_res = Resource(material.name+".mat")
90 statements = mat_res.statements
92 cm = get_colormap(material.srgb_colors)
93 if any(s.use_map_color_diffuse for s in material.texture_slots if s):
94 statements.append(Statement("diffuse", 1.0, 1.0, 1.0, 1.0))
95 amb = cm(material.ambient)
96 statements.append(Statement("ambient", amb, amb, amb, 1.0))
98 diff = material.diffuse_color*material.diffuse_intensity
99 statements.append(Statement("diffuse", cm(diff.r), cm(diff.g), cm(diff.b), 1.0))
100 amb = diff*material.ambient
101 statements.append(Statement("ambient", cm(amb.r), cm(amb.g), cm(amb.b), 1.0))
102 spec = material.specular_color*material.specular_intensity
103 statements.append(Statement("specular", cm(spec.r), cm(spec.g), cm(spec.g), 1.0))
104 statements.append(Statement("shininess", material.specular_hardness))