7 return 1.055*(l**(1/2.4))-0.055
12 return os.path.split(fp)[1]
19 self.material_tex = False
20 self.srgb_colors = True
22 self.separate_mesh = False
23 self.separate_tech = False
24 self.external_tech = True
25 self.shared_tech = True
27 def export(self, context, out_file, objs=None, progress=None):
29 obj = context.active_object
33 from .outfile import open_output
34 out_file = open_output(out_file)
36 from .export_mesh import MeshExporter
37 mesh_export = MeshExporter()
38 for k, v in self.__dict__.items():
39 setattr(mesh_export, k, v)
41 if self.separate_mesh:
42 path, base = os.path.split(out_file.filename)
43 base, ext = os.path.splitext(base)
44 mesh_out = open_output(os.path.join(path, base+".mesh"))
45 mesh = mesh_export.export(context, mesh_out, objs, progress)
46 out_file.write("mesh", '"{}.mesh"'.format(base))
48 out_file.begin("mesh")
49 mesh = mesh_export.export(context, out_file, objs, progress)
52 if self.external_tech and obj.technique:
53 out_file.write("technique", '"{}"'.format(obj.technique))
54 elif self.separate_tech:
55 path, base = os.path.split(out_file.filename)
56 if self.shared_tech and mesh.materials:
57 tech_name = mesh.materials[0].name+".tech"
59 base, ext = os.path.splitext(base)
60 tech_name = base+".tech"
61 tech_out = open_output(os.path.join(path, tech_name))
62 self.export_technique(mesh, tech_out)
63 out_file.write("technique", '"{}"'.format(tech_name))
65 out_file.begin("technique")
66 self.export_technique(mesh, out_file)
69 def export_technique(self, mesh, out_file):
70 out_file.begin("pass", '""')
78 out_file.begin("material")
79 out_file.write("diffuse", 1.0, 1.0, 1.0, 1.0)
82 for u in mesh.uv_layers:
83 if u.name=="material_tex":
85 out_file.begin("texunit", index)
86 out_file.begin("texture2d")
87 out_file.write("min_filter", "NEAREST")
88 out_file.write("mag_filter", "NEAREST")
89 out_file.write("storage", "RGB", len(mesh.materials), 1)
91 for m in mesh.materials:
92 color = [int(cm(c)*255) for c in m.diffuse_color*mat.diffuse_intensity]
93 texdata += "\\x%02X\\x%02X\\x%02X"%tuple(color)
95 out_file.write("raw_data", texdata)
99 mat = mesh.materials[0]
100 out_file.begin("material")
101 if any((s and s.use_map_color_diffuse) for s in mat.texture_slots):
102 out_file.write("diffuse", 1.0, 1.0, 1.0, 1.0)
103 amb = cm(mat.ambient)
104 out_file.write("ambient", amb, amb, amb, 1.0)
106 diff = mat.diffuse_color*mat.diffuse_intensity
107 out_file.write("diffuse", cm(diff.r), cm(diff.g), cm(diff.b), 1.0)
108 amb = diff*mat.ambient
109 out_file.write("ambient", cm(amb.r), cm(amb.g), cm(amb.b), 1.0)
110 spec = mat.specular_color*mat.specular_intensity
111 out_file.write("specular", spec.r, spec.g, spec.b, 1.0)
112 out_file.write("shininess", mat.specular_hardness);
115 if self.textures!="NONE":
116 for slot in mesh.materials[0].texture_slots:
121 if tex.type!="IMAGE":
125 for u in mesh.uv_layers:
126 if u.name==slot.uv_layer:
129 index = mesh.uv_layers[0].unit
131 out_file.begin("texunit", index)
132 if self.textures=="INLINE":
133 out_file.begin("texture2d")
134 out_file.write("min_filter", "LINEAR")
135 out_file.write("storage", "RGBA", tex.image.size[0], tex.image.size[1])
137 for p in tex.image.pixels:
138 texdata += "\\x%02X"%int(p*255)
140 out_file.write("raw_data", texdata)
143 out_file.write("texture", '"%s"'%image_name(tex.image))