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, objs=None, progress=None):
22 obj = context.active_object
26 from .outfile import open_output
27 out_file = open_output(out_file)
29 from .export_mesh import MeshExporter
30 mesh_export = MeshExporter()
31 for k, v in self.__dict__.items():
32 setattr(mesh_export, k, v)
34 if self.separate_mesh:
35 path, base = os.path.split(out_file.filename)
36 base, ext = os.path.splitext(base)
37 mesh_out = open_output(os.path.join(path, base+".mesh"))
38 mesh = mesh_export.export(context, mesh_out, objs, progress)
39 out_file.write("mesh", '"{}.mesh"'.format(base))
41 out_file.begin("mesh")
42 mesh = mesh_export.export(context, out_file, objs, progress)
45 if self.external_tech and obj.technique:
46 out_file.write("technique", '"{}"'.format(obj.technique))
47 elif self.separate_tech:
48 path, base = os.path.split(out_file.filename)
49 if self.shared_tech and mesh.materials:
50 tech_name = mesh.materials[0].name+".tech"
52 base, ext = os.path.splitext(base)
53 tech_name = base+".tech"
54 tech_out = open_output(os.path.join(path, tech_name))
55 self.export_technique(mesh, tech_out)
56 out_file.write("technique", '"{}"'.format(tech_name))
58 out_file.begin("technique")
59 self.export_technique(mesh, out_file)
62 def export_technique(self, mesh, out_file):
63 out_file.begin("pass", '""')
71 out_file.begin("material")
72 out_file.write("diffuse", 1.0, 1.0, 1.0, 1.0)
75 for u in mesh.uv_layers:
76 if u.name=="material_tex":
78 out_file.begin("texunit", index)
79 out_file.begin("texture2d")
80 out_file.write("min_filter", "NEAREST")
81 out_file.write("mag_filter", "NEAREST")
82 out_file.write("storage", "RGB", len(mesh.materials), 1)
84 for m in mesh.materials:
85 color = [int(cm(c)*255) for c in m.diffuse_color]
86 texdata += "\\x%02X\\x%02X\\x%02X"%tuple(color)
88 out_file.write("raw_data", texdata)
92 mat = mesh.materials[0]
93 out_file.begin("material")
94 if any((s and s.use_map_color_diffuse) for s in mat.texture_slots):
95 out_file.write("diffuse", 1.0, 1.0, 1.0, 1.0)
97 out_file.write("ambient", amb, amb, amb, 1.0)
99 diff = mat.diffuse_color
100 out_file.write("diffuse", cm(diff.r), cm(diff.g), cm(diff.b), 1.0)
101 amb = diff*mat.ambient
102 out_file.write("ambient", cm(amb.r), cm(amb.g), cm(amb.b), 1.0)
103 spec = mat.specular_color*mat.specular_intensity
104 out_file.write("specular", spec.r, spec.g, spec.b, 1.0)
105 out_file.write("shininess", mat.specular_hardness);
108 if self.textures!="NONE":
109 for slot in mesh.materials[0].texture_slots:
114 if tex.type!="IMAGE":
118 for u in mesh.uv_layers:
119 if u.name==slot.uv_layer:
122 index = mesh.uv_layers[0].unit
124 out_file.begin("texunit", index)
125 if self.textures=="INLINE":
126 out_file.begin("texture2d")
127 out_file.write("min_filter", "LINEAR")
128 out_file.write("storage", "RGBA", tex.image.size[0], tex.image.size[1])
130 for p in tex.image.pixels:
131 texdata += "\\x%02X"%int(p*255)
133 out_file.write("raw_data", texdata)
136 out_file.write("texture", '"%s"'%tex.image.name)