bl_info = {
"name": "Msp GL datafiles",
+ "blender": (2, 80, 0),
"author": "Mikko Rasa",
"location": "File > Export",
"description": "Export Msp GL data",
self.general_col = self.layout.column()
col = self.layout.column()
- col.label("Triangle strips")
+ col.label(text="Triangle strips")
col.prop(self, "use_strips")
col.prop(self, "use_degen_tris")
self.general_col.prop(self, "use_textures")
col = self.layout.column()
- col.label("Files")
+ col.label(text="Files")
col.prop(self, "single_file")
if not self.single_file:
col.prop(self, "shared_resources")
filename_ext = ".scene"
selected_only = bpy.props.BoolProperty(name="Selected objects only", description="Only export the selected objects")
- active_layers = bpy.props.BoolProperty(name="Active layers only", description="Only export objects on the active layers", default=True)
+ visible_collections = bpy.props.BoolProperty(name="Visible collections only", description="Only export objects in visible collections", default=True)
resource_collection = bpy.props.BoolProperty(name="Resource collection", description="Put resources to a single collection file", default=True)
skip_existing = bpy.props.BoolProperty(name="Skip existing files", description="Skip resources that already exist as files", default=True)
def draw(self, context):
col = self.layout.column()
col.prop(self, "selected_only")
- col.prop(self, "active_layers")
+ col.prop(self, "visible_collections")
col.prop(self, "resource_collection")
if self.resource_collection:
col.prop(self, "skip_existing")
self.layout.operator(ExportMspGLScene.bl_idname, text="Msp GL scene")
self.layout.operator(ExportMspGLCamera.bl_idname, text="Msp GL camera")
-from .properties import MspGLMeshProperties, MspGLObjectProperties
+classes = [ExportMspGLMesh, ExportMspGLObject, ExportMspGLArmature, ExportMspGLAnimation, ExportMspGLScene, ExportMspGLCamera]
def register():
- bpy.utils.register_module(__name__)
+ for c in classes:
+ bpy.utils.register_class(c)
- bpy.types.INFO_MT_file_export.append(menu_func_export)
+ bpy.types.TOPBAR_MT_file_export.append(menu_func_export)
from .properties import register_properties
register_properties()
def unregister():
- bpy.utils.unregister_module(__name__)
+ for c in classes:
+ bpy.utils.unregister_class(c)
- bpy.types.INFO_MT_file_export.remove(menu_func_export)
+ bpy.types.TOPBAR_MT_file_export.remove(menu_func_export)
-if __name__=="__main__":
- register()
+ from .properties import unregister_properties
+ unregister_properties()
if mat_name not in resources:
resources[mat_name] = self.export_material(material)
- if self.use_textures:
+ if False and self.use_textures:
for s in material.texture_slots:
if s and s.texture.type=='IMAGE' and s.texture.image:
tex_name = s.texture.name+".tex2d"
mat_res = resources[material.name+".mat"]
textures = {}
- if self.use_textures:
+ if False and self.use_textures:
image_texture_slots = [s for s in material.texture_slots if s and s.texture.type=='IMAGE' and s.texture.image]
for s in image_texture_slots:
if s.use_map_color_diffuse:
from .util import get_colormap
cm = get_colormap(material.srgb_colors)
- if any(s.use_map_color_diffuse for s in material.texture_slots if s):
+ if False and 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))
+ diff = material.diffuse_color
+ statements.append(Statement("diffuse", cm(diff[0]), cm(diff[1]), cm(diff[2]), 1.0))
+ statements.append(Statement("ambient", cm(diff[0]), cm(diff[1]), cm(diff[2]), 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))
+ statements.append(Statement("shininess", min(2/material.roughness**2-2, 250)))
return mat_res
class SceneExporter:
def __init__(self):
self.selected_only = False
- self.active_layers = True
+ self.visible_collections = True
self.resource_collection = True
self.skip_existing = True
self.show_progress = True
objs = context.selected_objects
else:
objs = context.scene.objects
- if self.active_layers:
- layers = context.scene.layers
- objs = [o for o in objs if any(a and b for a, b in zip(layers, o.layers))]
+ if self.visible_collections:
+ collections = [c.collection for c in context.view_layer.layer_collection.children if not (c.hide_viewport or c.collection.hide_viewport)]
+ objs = [o for o in objs if any((o.name in c.all_objects) for c in collections)]
objs = [o for o in objs if o.type=="MESH" and not o.lod_for_parent]
objs = [o for o in objs if (not o.compound or o.parent not in objs)]
objs.sort(key=lambda x:x.name)
else:
self.name = "material_map"
self.materials = materials
+ self.material_names = [m.name for m in self.materials]
self.srgb_colors = materials[0].srgb_colors
for m in self.materials:
if m.technique!=self.technique:
cm = get_colormap(self.srgb_colors)
self.diffuse_data = ""
for m in self.materials:
- diff = [int(cm(c)*255) for c in m.diffuse_color*m.diffuse_intensity]
- self.diffuse_data += "\\x{:02X}\\x{:02X}\\x{:02X}\\x{:02X}".format(*diff, int(m.ambient*255))
+ diff = [int(cm(c)*255) for c in m.diffuse_color]
+ self.diffuse_data += "\\x{:02X}\\x{:02X}\\x{:02X}\\xFF".format(*diff)
self.diffuse_data += "\\x00\\x00\\x00\\x00"*(self.size[0]*self.size[1]-count)
def get_material_uv(self, material):
- index = self.materials.index(material)
+ index = self.material_names.index(material.name)
x = index%self.size[0]
y = index//self.size[0]
return ((x+0.5)/self.size[0], (y+0.5)/self.size[1])
def transform(self, matrix):
for v in self.vertices:
- v.co = matrix*v.co
+ v.co = matrix@v.co
def splice(self, other):
if len(self.uv_layers)!=len(other.uv_layers):
self.faces += other.faces
for f in self.faces[offset:]:
f.index += offset
- f.loop_start += loop_offset
- f.loop_indices = range(f.loop_start, f.loop_start+f.loop_total)
+ f.loop_indices = range(f.loop_indices.start+offset, f.loop_indices.stop+offset)
if other.materials:
f.material_index = material_map[f.material_index]
def apply_material_map(self, material_map):
for m in self.materials:
- if m not in material_map.materials:
+ if m.name not in material_map.material_names:
raise Exception("Material map is not compatible with Mesh")
if self.use_uv=='NONE':
def prepare_uv(self, progress):
# Form a list of UV layers referenced by materials with the array atlas
# property set
- array_uv_layers = [t.uv_layer for m in self.materials if m.array_atlas for t in m.texture_slots if t and t.texture_coords=='UV']
+ array_uv_layers = [] #[t.uv_layer for m in self.materials if m.array_atlas for t in m.texture_slots if t and t.texture_coords=='UV']
array_uv_layers = [u for u in self.uv_layers if u.name in array_uv_layers]
if array_uv_layers:
if c.type=="MESH" and c.compound:
objs.append((c, m*c.matrix_local))
+ dg = context.evaluated_depsgraph_get()
+
mesh = None
- bmeshes = []
for o, m in objs:
- bmesh = o.to_mesh(context.scene, True, "PREVIEW")
- bmeshes.append(bmesh)
+ eval_obj = o.evaluated_get(dg)
+ bmesh = eval_obj.to_mesh()
# Object.to_mesh does not copy custom properties
bmesh.winding_test = o.data.winding_test
me = Mesh(bmesh)
me.transform(m)
+ for i, s in enumerate(eval_obj.material_slots):
+ if s.link=='OBJECT':
+ me.materials[i] = s.material
+
if mesh:
mesh.splice(me)
else:
# Discard the temporary Blender meshes after making sure there's no
# references to the data
mesh.drop_references()
- for m in bmeshes:
- bpy.data.meshes.remove(m)
progress.pop_task()
self.layout.separator()
col = self.layout.column()
- col.label("Data selection")
+ col.label(text="Data selection")
col.prop(mesh, "use_lines")
col.prop(mesh, "vertex_groups")
col.prop(mesh, "max_groups_per_vertex")
self.layout.separator()
col = self.layout.column()
- col.label("Texturing")
+ col.label(text="Texturing")
col.prop(mesh, "use_uv")
col.prop(mesh, "tbn_vecs")
col.prop(mesh, "tbn_uvtex")
self.layout.prop(tex, "default_filter")
+classes = [MspGLMeshProperties, MspGLObjectProperties, MspGLMaterialProperties, MspGLTextureProperties]
+
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.material_map = bpy.props.BoolProperty(name="Material map", description="Make this material part of a material map")
bpy.types.Texture.default_filter = bpy.props.BoolProperty(name="Default filter", description="Let the loading program determine filtering options")
+
+ for c in classes:
+ bpy.utils.register_class(c)
+
+def unregister_properties():
+ for c in classes:
+ bpy.utils.unregister_class(c)