else:
return lambda x: x
-def image_name(i):
- fp = i.filepath
- if fp:
- return os.path.split(fp)[1]
- else:
- return i.name
-
class MaterialExporter:
def __init__(self):
self.textures = 'REF'
- def export_technique_resources(self, material, resources):
+ def create_texture_exporter(self):
from .export_texture import TextureExporter
texture_export = TextureExporter()
+ if self.textures=='INLINE':
+ texture_export.pixels = 'INLINE'
+ return texture_export
+
+ def export_technique_resources(self, material, resources):
+ texture_export = self.create_texture_exporter()
mat_name = material.name+".mat"
if mat_name not in resources:
resources[mat_name] = self.export_material(material)
- if self.textures=='INLINE':
+ if self.textures!='NONE':
for s in material.texture_slots:
if s and s.texture.type=='IMAGE' and s.texture.image:
tex_name = s.texture.name+".tex2d"
st = Statement("inherit", material.technique)
for s, t in textures.items():
- st.sub.append(Statement("texture", s, image_name(t.image)))
+ if t.default_filter:
+ st.sub.append(Statement("texture", s, image_name(t.image)))
+ else:
+ st.sub.append(tech_res.create_reference_statement("texture", s, resources[t.name+".tex2d"]))
if material.override_material:
st.sub.append(tech_res.create_reference_statement("material", "surface", mat_res))
tech_res.statements.append(st)
if "diffuse_map" in textures:
diffuse_tex = textures["diffuse_map"]
+ tex_res = resources[diffuse_tex.name+".tex2d"]
ss = Statement("texunit", 0)
if self.textures=='INLINE':
- ss.sub.append(tech_res.create_embed_statement("texture2d", resources[diffuse_tex.name+".tex2d"]))
+ ss.sub.append(tech_res.create_embed_statement("texture2d", tex_res))
+ elif not diffuse_tex.default_filter:
+ ss.sub.append(tech_res.create_reference_statement("texture2d", tex_res))
else:
ss.sub.append(Statement("texture", image_name(diffuse_tex.image)))
st.sub.append(ss)
class TextureExporter:
+ def __init__(self):
+ self.pixels = 'REF'
+
def export_texture(self, texture):
from .datafile import Resource, Statement, Token
tex_res = Resource(texture.name+".tex2d")
- tex_res.statements.append(Statement("min_filter", Token("LINEAR")))
- tex_res.statements.append(Statement("storage", Token("RGBA"), texture.image.size[0], texture.image.size[1]))
- texdata = ""
- for p in texture.image.pixels:
- texdata += "\\x%02X"%int(p*255)
- tex_res.statements.append(Statement("raw_data", texdata))
+ if texture.use_interpolation:
+ if texture.use_mipmap:
+ tex_res.statements.append(Statement("min_filter", Token('LINEAR_MIPMAP_LINEAR')))
+ tex_res.statements.append(Statement("generate_mipmap", True))
+ else:
+ tex_res.statements.append(Statement("min_filter", Token('LINEAR')))
+ tex_res.statements.append(Statement("max_anisotropy", texture.filter_eccentricity))
+ else:
+ if texture.use_mipmap:
+ tex_res.statements.append(Statement("min_filter", Token('NEAREST_MIPMAP_NEAREST')))
+ tex_res.statements.append(Statement("generate_mipmap", True))
+ else:
+ tex_res.statements.append(Statement("min_filter", Token('NEAREST')))
+
+ if self.pixels=='REF':
+ from .util import image_name
+ tex_res.statements.append(Statement("image_data", image_name(texture.image)))
+ else:
+ texdata = ""
+ if texture.use_alpha:
+ fmt = 'RGBA'
+ for p in texture.image.pixels:
+ texdata += "\\x{:02X}".format(int(p*255))
+ else:
+ fmt = 'RGB'
+ for i in range(0, len(texture.image.pixels), 4):
+ for j in range(3):
+ texdata += "\\x{:02X}".format(int(texture.image.pixels[i+j]*255))
+ tex_res.statements.append(Statement("storage", Token(fmt), texture.image.size[0], texture.image.size[1]))
+ tex_res.statements.append(Statement("raw_data", texdata))
return tex_res
if mat.array_atlas:
self.layout.prop(mat, "array_layer")
+class MspGLTextureProperties(bpy.types.Panel):
+ bl_idname = "TEXTURE_PT_mspgl_properties"
+ bl_label = "MspGL properties"
+ bl_space_type = "PROPERTIES"
+ bl_region_type = "WINDOW"
+ bl_context = "texture"
+
+ @classmethod
+ def poll(cls, context):
+ mat = context.active_object.active_material
+ return mat is not None and mat.active_texture is not None
+
+ def draw(self, context):
+ tex = context.active_object.active_material.active_texture
+ if not tex:
+ return
+
+ self.layout.prop(tex, "default_filter")
+
def register_properties():
bpy.types.Mesh.winding_test = bpy.props.BoolProperty(name="Winding test", description="Perform winding test to skip back faces")
bpy.types.Mesh.smoothing = bpy.props.EnumProperty(name="Smoothing", description="Smoothing method to use", default="MSPGL",
bpy.types.Material.srgb_colors = bpy.props.BoolProperty(name="sRGB colors", description="Export material colors as sRGB instead of linear", default=True)
bpy.types.Material.array_atlas = bpy.props.BoolProperty(name="Texture array atlas", description="The material is stored in a texture array")
bpy.types.Material.array_layer = bpy.props.IntProperty("Texture array layer", description="Layer of the texture array atlas to use")
+
+ bpy.types.Texture.default_filter = bpy.props.BoolProperty(name="Default filter", description="Let the loading program determine filtering options")
+import os
+
class Progress:
def __init__(self, context):
self.task = ""
if self.window_manager:
self.window_manager.progress_update(value)
self.last = value
+
+
+def image_name(img):
+ fp = img.filepath
+ if fp:
+ return os.path.split(fp)[1]
+ else:
+ return img.name