7 return 1.055*(l**(1/2.4))-0.055
12 self.material_tex = False
13 self.srgb_colors = True
15 self.separate_mesh = False
16 self.separate_tech = False
17 self.external_tech = True
18 self.shared_tech = True
20 def export(self, context, out_file):
21 obj = context.active_object
23 from .outfile import open_output
24 out_file = open_output(out_file)
26 from .export_mesh import MeshExporter
27 mesh_export = MeshExporter()
28 for k, v in self.__dict__.items():
29 setattr(mesh_export, k, v)
31 if self.separate_mesh:
32 path, base = os.path.split(out_file.filename)
33 base, ext = os.path.splitext(base)
34 mesh_out = open_output(os.path.join(path, base+".mesh"))
35 mesh = mesh_export.export(context, mesh_out)
36 out_file.write("mesh", '"{}.mesh"'.format(base))
38 out_file.begin("mesh")
39 mesh = mesh_export.export(context, out_file)
42 if self.external_tech and obj.technique:
43 out_file.write("technique", '"{}"'.format(obj.technique))
44 elif self.separate_tech:
45 path, base = os.path.split(out_file.filename)
46 if self.shared_tech and mesh.materials:
47 tech_name = mesh.materials[0].name+".tech"
49 base, ext = os.path.splitext(base)
50 tech_name = base+".tech"
51 tech_out = open_output(os.path.join(path, tech_name))
52 self.export_technique(mesh, tech_out)
53 out_file.write("technique", '"{}"'.format(tech_name))
55 out_file.begin("technique")
56 self.export_technique(mesh, out_file)
59 def export_technique(self, mesh, out_file):
60 out_file.begin("pass", '""')
68 out_file.begin("material")
69 out_file.write("diffuse", 1.0, 1.0, 1.0, 1.0)
72 for u in mesh.uv_layers:
73 if u.name=="material_tex":
75 out_file.begin("texunit", index)
76 out_file.begin("texture2d")
77 out_file.write("min_filter", "NEAREST")
78 out_file.write("mag_filter", "NEAREST")
79 out_file.write("storage", "RGB", len(mesh.materials), 1)
81 for m in mesh.materials:
82 color = [int(cm(c)*255) for c in m.diffuse_color]
83 texdata += "\\x%02X\\x%02X\\x%02X"%tuple(color)
85 out_file.write("raw_data", texdata)
89 mat = mesh.materials[0]
90 out_file.begin("material")
91 if any((s and s.use_map_color_diffuse) for s in mat.texture_slots):
92 out_file.write("diffuse", 1.0, 1.0, 1.0, 1.0)
94 out_file.write("ambient", amb, amb, amb, 1.0)
96 diff = mat.diffuse_color
97 out_file.write("diffuse", cm(diff.r), cm(diff.g), cm(diff.b), 1.0)
98 amb = diff*mat.ambient
99 out_file.write("ambient", cm(amb.r), cm(amb.g), cm(amb.b), 1.0)
100 spec = mat.specular_color*mat.specular_intensity
101 out_file.write("specular", spec.r, spec.g, spec.b, 1.0)
102 out_file.write("shininess", mat.specular_hardness);
105 if self.textures!="NONE":
106 for slot in mesh.materials[0].texture_slots:
111 if tex.type!="IMAGE":
115 for u in mesh.uv_layers:
116 if u.name==slot.uv_layer:
119 index = mesh.uv_layers[0].unit
121 out_file.begin("texunit", index)
122 if self.textures=="INLINE":
123 out_file.begin("texture2d")
124 out_file.write("min_filter", "LINEAR")
125 out_file.write("storage", "RGBA", tex.image.size[0], tex.image.size[1])
127 for p in tex.image.pixels:
128 texdata += "\\x%02X"%int(p*255)
130 out_file.write("raw_data", texdata)
133 out_file.write("texture", '"%s"'%tex.image.name)