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
17 def export(self, context, out_file):
18 from .outfile import open_output
19 out_file = open_output(out_file)
21 from .export_mesh import MeshExporter
22 mesh_export = MeshExporter()
23 for k, v in self.__dict__.items():
24 setattr(mesh_export, k, v)
26 if self.separate_mesh:
27 path, base = os.path.split(out_file.filename)
28 base, ext = os.path.splitext(base)
29 mesh_out = open_output(os.path.join(path, base+".mesh"))
30 mesh = mesh_export.export(context, mesh_out)
31 out_file.write("mesh", "\""+base+".mesh\"")
33 out_file.begin("mesh")
34 mesh = mesh_export.export(context, out_file)
37 out_file.begin("technique")
38 out_file.begin("pass", '""')
46 out_file.begin("material")
47 out_file.write("diffuse", 1.0, 1.0, 1.0, 1.0)
50 for u in mesh.uv_layers:
51 if u.name=="material_tex":
53 out_file.begin("texunit", index)
54 out_file.begin("texture2d")
55 out_file.write("min_filter", "NEAREST")
56 out_file.write("mag_filter", "NEAREST")
57 out_file.write("storage", "RGB", len(mesh.materials), 1)
59 for m in mesh.materials:
60 color = [int(cm(c)*255) for c in m.diffuse_color]
61 texdata += "\\x%02X\\x%02X\\x%02X"%tuple(color)
63 out_file.write("raw_data", texdata)
67 mat = mesh.materials[0]
68 out_file.begin("material")
69 if any((s and s.use_map_color_diffuse) for s in mat.texture_slots):
70 out_file.write("diffuse", 1.0, 1.0, 1.0, 1.0)
72 out_file.write("ambient", amb, amb, amb, 1.0)
74 diff = mat.diffuse_color
75 out_file.write("diffuse", cm(diff.r), cm(diff.g), cm(diff.b), 1.0)
76 amb = diff*mat.ambient
77 out_file.write("ambient", cm(amb.r), cm(amb.g), cm(amb.b), 1.0)
78 spec = mat.specular_color*mat.specular_intensity
79 out_file.write("specular", spec.r, spec.g, spec.b, 1.0)
80 out_file.write("shininess", mat.specular_hardness);
83 if self.textures!="NONE":
84 for slot in mesh.materials[0].texture_slots:
93 for u in mesh.uv_layers:
94 if u.name==slot.uv_layer:
97 index = mesh.uv_layers[0].unit
99 out_file.begin("texunit", index)
100 if self.textures=="INLINE":
101 out_file.begin("texture2d")
102 out_file.write("min_filter", "LINEAR")
103 out_file.write("storage", "RGBA", tex.image.size[0], tex.image.size[1])
105 for p in tex.image.pixels:
106 texdata += "\\x%02X"%int(p*255)
108 out_file.write("raw_data", texdata)
111 out_file.write("texture", '"%s"'%tex.image.name)