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)
35 path, base = os.path.split(out_file.filename)
37 from .export_mesh import MeshExporter
38 mesh_export = MeshExporter()
39 for k, v in self.__dict__.items():
40 setattr(mesh_export, k, v)
42 if self.separate_mesh:
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)
53 self.colormap = linear_to_srgb
55 self.colormap = lambda x: x
57 if self.external_tech and obj.technique:
58 if obj.inherit_tech and (obj.override_material or mesh.materials[0].texture_slots):
59 out_file.begin("technique")
60 out_file.begin("inherit", '"{}"'.format(obj.technique))
61 for slot in mesh.materials[0].texture_slots:
62 if slot and slot.texture.type=="IMAGE":
63 name = image_name(slot.texture.image)
64 if slot.use_map_color_diffuse:
65 out_file.write("texture", '"diffuse_map"', '"{}"'.format(name))
66 elif slot.use_map_normal:
67 out_file.write("texture", '"normal_map"', '"{}"'.format(name))
68 if obj.override_material:
69 mat_name = mesh.materials[0].name+".mat"
70 mat_out = open_output(os.path.join(path, mat_name))
71 self.export_material(mesh.materials[0], mat_out)
72 out_file.write("material", '""', '"{}"'.format(mat_name))
76 out_file.write("technique", '"{}"'.format(obj.technique))
77 elif self.separate_tech:
78 if self.shared_tech and mesh.materials:
79 tech_name = mesh.materials[0].name+".tech"
81 base, ext = os.path.splitext(base)
82 tech_name = base+".tech"
83 tech_out = open_output(os.path.join(path, tech_name))
84 self.export_technique(mesh, tech_out)
85 out_file.write("technique", '"{}"'.format(tech_name))
87 out_file.begin("technique")
88 self.export_technique(mesh, out_file)
91 def export_technique(self, mesh, out_file):
92 out_file.begin("pass", '""')
97 out_file.begin("material")
98 out_file.write("diffuse", 1.0, 1.0, 1.0, 1.0)
101 for u in mesh.uv_layers:
102 if u.name=="material_tex":
104 out_file.begin("texunit", index)
105 out_file.begin("texture2d")
106 out_file.write("min_filter", "NEAREST")
107 out_file.write("mag_filter", "NEAREST")
108 out_file.write("storage", "RGB", len(mesh.materials), 1)
110 for m in mesh.materials:
111 color = [int(cm(c)*255) for c in m.diffuse_color*mat.diffuse_intensity]
112 texdata += "\\x%02X\\x%02X\\x%02X"%tuple(color)
114 out_file.write("raw_data", texdata)
118 out_file.begin("material")
119 self.export_material(mesh.materials[0], out_file)
122 if self.textures!="NONE":
123 for slot in mesh.materials[0].texture_slots:
128 if tex.type!="IMAGE":
132 for u in mesh.uv_layers:
133 if u.name==slot.uv_layer:
136 index = mesh.uv_layers[0].unit
138 out_file.begin("texunit", index)
139 if self.textures=="INLINE":
140 out_file.begin("texture2d")
141 out_file.write("min_filter", "LINEAR")
142 out_file.write("storage", "RGBA", tex.image.size[0], tex.image.size[1])
144 for p in tex.image.pixels:
145 texdata += "\\x%02X"%int(p*255)
147 out_file.write("raw_data", texdata)
150 out_file.write("texture", '"%s"'%image_name(tex.image))
155 def export_material(self, mat, out_file):
157 if any((s and s.use_map_color_diffuse) for s in mat.texture_slots):
158 out_file.write("diffuse", 1.0, 1.0, 1.0, 1.0)
159 amb = cm(mat.ambient)
160 out_file.write("ambient", amb, amb, amb, 1.0)
162 diff = mat.diffuse_color*mat.diffuse_intensity
163 out_file.write("diffuse", cm(diff.r), cm(diff.g), cm(diff.b), 1.0)
164 amb = diff*mat.ambient
165 out_file.write("ambient", cm(amb.r), cm(amb.g), cm(amb.b), 1.0)
166 spec = mat.specular_color*mat.specular_intensity
167 out_file.write("specular", spec.r, spec.g, spec.b, 1.0)
168 out_file.write("shininess", mat.specular_hardness);