class ExportMspGLMeshBase(ExportMspGLBase):
export_all: bpy.props.BoolProperty(name="Export all selected", description="Export all selected objects (use generated filenames)", default=False)
- use_strips: bpy.props.BoolProperty(name="Use strips", description="Combine faces into triangle strips", default=True)
- use_degen_tris: bpy.props.BoolProperty(name="Use degen tris", description="Concatenate triangle strips with degenerate triangles", default=False)
def draw(self, context):
self.general_col = self.layout.column()
if len(context.selected_objects)>1:
col.label(text="Object selection")
col.prop(self, "export_all")
- col.label(text="Triangle strips")
- col.prop(self, "use_strips")
- col.prop(self, "use_degen_tris")
class ExportMspGLMesh(bpy.types.Operator, ExportMspGLMeshBase):
bl_idname = "export_mesh.mspgl_mesh"
collection: bpy.props.BoolProperty(name="As a collection", description="Write all data into a single collection file", default=False)
shared_resources: bpy.props.BoolProperty(name="Shared resources", description="Use global names for resource files to enable sharing", default=True)
- export_lods: bpy.props.BoolProperty(name="Export LoDs", description="Export all levels of detail", default=True)
- use_textures: bpy.props.BoolProperty(name="Use textures", description="Use textures in the exported object", default=True)
-
def check(self, context):
ext_changed = self.set_extension(".mdc" if self.collection else ".object")
super_result = super().check(context)
def draw(self, context):
super().draw(context)
- self.general_col.prop(self, "export_lods")
- self.general_col.prop(self, "use_textures")
-
col = self.layout.column()
col.label(text="Files")
col.prop(self, "collection")
class MaterialExporter:
def __init__(self):
- self.use_textures = True
self.inline_texture_data = False
def create_texture_exporter(self):
from .material import Material
material = Material(material)
- if self.use_textures:
- for p in material.properties:
- if p.texture:
- tex_name = p.texture.image.name+".tex2d"
- if tex_name not in resources:
- resources[tex_name] = texture_export.export_texture(p.texture, p.tex_usage, invert_green=p.invert_green)
+ for p in material.properties:
+ if p.texture:
+ tex_name = p.texture.image.name+".tex2d"
+ if tex_name not in resources:
+ resources[tex_name] = texture_export.export_texture(p.texture, p.tex_usage, invert_green=p.invert_green)
- samp_name = sampler_export.get_sampler_name(p.texture)
- if samp_name not in resources:
- resources[samp_name] = sampler_export.export_sampler(p.texture)
+ samp_name = sampler_export.get_sampler_name(p.texture)
+ if samp_name not in resources:
+ resources[samp_name] = sampler_export.export_sampler(p.texture)
mat_name = material.name+".mat"
if mat_name not in resources:
st = self.create_property_statement(mat_res, p, resources)
if st:
mat_res.statements.append(st)
- if self.use_textures:
- textures = [p.texture for p in material.properties if p.texture]
- if textures and not all(t.default_filter for t in textures):
- from .export_texture import SamplerExporter
- sampler_tex = next(t for t in textures if not t.default_filter)
- sampler_export = SamplerExporter()
- mat_res.statements.append(mat_res.create_reference_statement("sampler", resources[sampler_export.get_sampler_name(sampler_tex)]))
+ textures = [p.texture for p in material.properties if p.texture]
+ if textures and not all(t.default_filter for t in textures):
+ from .export_texture import SamplerExporter
+ sampler_tex = next(t for t in textures if not t.default_filter)
+ sampler_export = SamplerExporter()
+ mat_res.statements.append(mat_res.create_reference_statement("sampler", resources[sampler_export.get_sampler_name(sampler_tex)]))
return mat_res
def create_property_statement(self, mat_res, prop, resources):
from .datafile import Statement
- if self.use_textures and prop.texture:
+ if prop.texture:
tex_res = resources[prop.texture.image.name+".tex2d"]
from .util import basename
fn = basename(prop.texture.image.filepath)
class MeshExporter:
def __init__(self):
self.show_progress = True
- self.use_strips = True
- self.use_degen_tris = False
self.export_all = False
- def join_strips(self, strips):
- big_strip = []
-
- for s in strips:
- if big_strip:
- # Generate glue elements, ensuring that the next strip begins at
- # an even position
- glue = [big_strip[-1], s[0]]
- if len(big_strip)%2:
- glue += [s[0]]
-
- big_strip += glue
-
- big_strip += s
-
- return big_strip
-
def export_to_file(self, context, out_fn):
if self.export_all:
objs = [o for o in context.selected_objects if o.type=="MESH"]
statements.append(st)
- if self.use_strips:
- strips = mesh.vertex_sequence
- if self.use_degen_tris:
- strips = [self.join_strips(strips)]
-
- for s in strips:
+ if mesh.use_strips:
+ for s in mesh.vertex_sequence:
st = Statement("batch", Token("TRIANGLE_STRIP"))
for i in range(0, len(s), 32):
st.sub.append(Statement("indices", *(v.index for v in s[i:i+32])))
class ObjectExporter:
def __init__(self):
self.show_progress = True
- self.use_strips = True
- self.use_degen_tris = False
- self.use_textures = True
self.export_all = False
self.collection = False
self.shared_resources = True
- self.export_lods = True
def compute_bounding_sphere(self, obj):
p1 = max(((v.co, v.co.length) for v in obj.data.vertices), key=lambda x:x[1])[0]
def collect_object_lods(self, obj):
lods = [obj]
- if self.export_lods:
- lods += sorted([c for c in obj.children if c.lod_for_parent], key=(lambda l: l.lod_index))
- for i, l in enumerate(lods):
- if i>0 and l.lod_index!=i:
- raise Exception("Inconsistent LOD indices")
+ lods += sorted([c for c in obj.children if c.lod_for_parent], key=(lambda l: l.lod_index))
+ for i, l in enumerate(lods):
+ if i>0 and l.lod_index!=i:
+ raise Exception("Inconsistent LOD indices")
return lods
def create_mesh_exporter(self):
from .export_mesh import MeshExporter
mesh_export = MeshExporter()
- mesh_export.use_strips = self.use_strips
- mesh_export.use_degen_tris = self.use_degen_tris
return mesh_export
def create_material_exporter(self):
from .export_material import MaterialExporter
material_export = MaterialExporter()
- material_export.use_textures = self.use_textures
return material_export
def create_material_atlas_exporter(self):
self.smoothing = mesh.smoothing
self.use_uv = mesh.use_uv
self.tangent_uvtex = mesh.tangent_uvtex
+ self.use_strips = mesh.use_strips
self.vertex_groups = mesh.vertex_groups
# Clone basic data
self.layout.prop(mesh, "winding_test")
self.layout.prop(mesh, "smoothing")
+ self.layout.prop(mesh, "use_strips")
self.layout.separator()
("BLENDER", "Blender", "Use Blender's vertex normals"),
("MSPGL", "MspGL", "Compute vertex normals internally")))
bpy.types.Mesh.use_lines = bpy.props.BoolProperty(name="Include lines", description="Include edges without faces as lines", default=False)
+ bpy.types.Mesh.use_strips = bpy.props.BoolProperty(name="Use strips", description="Combine the mesh's triangles into triangle strips", default=True)
bpy.types.Mesh.vertex_groups = bpy.props.BoolProperty(name="Vertex groups", description="Include vertex groups and weights", default=False)
bpy.types.Mesh.max_groups_per_vertex = bpy.props.IntProperty(name="Max groups", description="Maximum amount of groups per vertex", min=1, max=4, default=2)
bpy.types.Mesh.use_uv = bpy.props.EnumProperty(name="Use UV", description="Use UV coordinates", default="UNIT0",