- if material:
- st = Statement("material")
- st.sub = self.export_material(material)
- pass_st.sub.append(st)
-
- if self.textures!="NONE":
- diffuse_tex = None
- for slot in material.texture_slots:
- if slot and slot.texture.type=="IMAGE" and slot.use_map_color_diffuse:
- diffuse_tex = slot.texture
- break
-
- if diffuse_tex:
- st = Statement("texunit", 0)
- if self.textures=="INLINE":
- ss = Statement("texture2d")
- ss.sub.append(Statement("min_filter", Token("LINEAR")))
- ss.sub.append(Statement("storage", Token("RGBA"), tex.image.size[0], tex.image.size[1]))
- texdata = ""
- for p in tex.image.pixels:
- texdata += "\\x%02X"%int(p*255)
- ss.sub.append(Statement("raw_data", texdata))
- st.sub.append(ss)
- elif tex.image:
- st.sub.append(Statement("texture", image_name(tex.image)))
- pass_st.sub.append(st)
- statements.append(pass_st)
-
- return statements
-
- def export_material(self, material):
- from .datafile import Statement
- statements = []
-
- cm = get_colormap(material.srgb_colors)
- if any(s.use_map_color_diffuse for s in material.texture_slots if s):
- statements.append(Statement("diffuse", 1.0, 1.0, 1.0, 1.0))
- amb = cm(material.ambient)
- statements.append(Statement("ambient", amb, amb, amb, 1.0))
- else:
- diff = material.diffuse_color*material.diffuse_intensity
- statements.append(Statement("diffuse", cm(diff.r), cm(diff.g), cm(diff.b), 1.0))
- amb = diff*material.ambient
- statements.append(Statement("ambient", cm(amb.r), cm(amb.g), cm(amb.b), 1.0))
- spec = material.specular_color*material.specular_intensity
- statements.append(Statement("specular", cm(spec.r), cm(spec.g), cm(spec.g), 1.0))
- statements.append(Statement("shininess", material.specular_hardness))
-
- return statements