From fcdc70624618488c514676874006f5eddc4e63df Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 12 Aug 2012 19:06:29 +0300 Subject: [PATCH] Restructure the exporter to make room for new stuff --- .../{io_mesh_mspgl => io_mspgl}/__init__.py | 16 ++++----- .../export_mesh.py} | 33 ++----------------- blender/{io_mesh_mspgl => io_mspgl}/mesh.py | 0 blender/io_mspgl/outfile.py | 30 +++++++++++++++++ blender/{io_mesh_mspgl => io_mspgl}/util.py | 0 5 files changed, 40 insertions(+), 39 deletions(-) rename blender/{io_mesh_mspgl => io_mspgl}/__init__.py (92%) rename blender/{io_mesh_mspgl/export_mspgl.py => io_mspgl/export_mesh.py} (94%) rename blender/{io_mesh_mspgl => io_mspgl}/mesh.py (100%) create mode 100644 blender/io_mspgl/outfile.py rename blender/{io_mesh_mspgl => io_mspgl}/util.py (100%) diff --git a/blender/io_mesh_mspgl/__init__.py b/blender/io_mspgl/__init__.py similarity index 92% rename from blender/io_mesh_mspgl/__init__.py rename to blender/io_mspgl/__init__.py index e7fa07ce..2ac3bd19 100644 --- a/blender/io_mesh_mspgl/__init__.py +++ b/blender/io_mspgl/__init__.py @@ -1,20 +1,20 @@ bl_info = { - "name": "Msp GL format", + "name": "Msp GL datafiles", "author": "Mikko Rasa", "location": "File > Export", - "description": "Export Msp GL meshes and objects", + "description": "Export Msp GL data", "category": "Import-Export" } if "bpy" in locals(): import imp - for sub in "export_mspgl", "mesh", "util": + for sub in "export_mesh", "mesh", "outfile", "util": if sub in locals(): imp.reload(locals()[sub]) import bpy from bpy_extras.io_utils import ExportHelper -class ExportMspGLBase(ExportHelper): +class ExportMspGLMeshBase(ExportHelper): 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) max_strip_len = bpy.props.IntProperty(name="Max strip length", description="Maximum length for a triangle strip", default=1024, min=4, max=16384) @@ -34,8 +34,8 @@ class ExportMspGLBase(ExportHelper): ("MSPGL", "MspGL", "Compute vertex normals internally"))) def execute(self, context): - from . import export_mspgl - exporter = export_mspgl.Exporter() + from .export_mesh import MeshExporter + exporter = MeshExporter() self.prepare_exporter(exporter) exporter.export(context, self.filepath) return {"FINISHED"} @@ -66,13 +66,13 @@ class ExportMspGLBase(ExportHelper): col.prop(self, "tbn_vecs") col.prop(self, "tbn_uvtex") -class ExportMspGLMesh(bpy.types.Operator, ExportMspGLBase): +class ExportMspGLMesh(bpy.types.Operator, ExportMspGLMeshBase): bl_idname = "export_mesh.mspgl_mesh" bl_label = "Export Msp GL mesh" filename_ext = ".mesh" -class ExportMspGLObject(bpy.types.Operator, ExportMspGLBase): +class ExportMspGLObject(bpy.types.Operator, ExportMspGLMeshBase): bl_idname = "export_mesh.mspgl_object" bl_label = "Export Msp GL object" diff --git a/blender/io_mesh_mspgl/export_mspgl.py b/blender/io_mspgl/export_mesh.py similarity index 94% rename from blender/io_mesh_mspgl/export_mspgl.py rename to blender/io_mspgl/export_mesh.py index c0fd96e9..3f0771fe 100644 --- a/blender/io_mesh_mspgl/export_mspgl.py +++ b/blender/io_mspgl/export_mesh.py @@ -1,4 +1,5 @@ import bpy +from .outfile import OutFile class VertexCache: def __init__(self, size): @@ -31,37 +32,7 @@ class VertexCache: return hits -class OutFile: - def __init__(self, fn): - if fn==None: - self.file = sys.stdout - else: - self.file = open(fn, "w") - self.indent = 0 - - def make(self, kwd, *params): - pstr = "" - for p in params: - if type(p)==float: - pstr += " %.6g"%p - else: - pstr += " %s"%p - return "%s%s"%(kwd, pstr) - - def write(self, kwd, *params): - self.file.write("%s%s;\n"%('\t'*self.indent, self.make(kwd, *params))) - - def begin(self, kwd, *params): - i = '\t'*self.indent - self.file.write("%s%s\n%s{\n"%(i, self.make(kwd, *params), i)) - self.indent += 1 - - def end(self): - self.indent -= 1 - self.file.write("%s};\n"%('\t'*self.indent)) - - -class Exporter: +class MeshExporter: def __init__(self): self.use_strips = True self.use_degen_tris = True diff --git a/blender/io_mesh_mspgl/mesh.py b/blender/io_mspgl/mesh.py similarity index 100% rename from blender/io_mesh_mspgl/mesh.py rename to blender/io_mspgl/mesh.py diff --git a/blender/io_mspgl/outfile.py b/blender/io_mspgl/outfile.py new file mode 100644 index 00000000..ca7abcf9 --- /dev/null +++ b/blender/io_mspgl/outfile.py @@ -0,0 +1,30 @@ +import sys + +class OutFile: + def __init__(self, fn): + if fn==None: + self.file = sys.stdout + else: + self.file = open(fn, "w") + self.indent = 0 + + def make(self, kwd, *params): + pstr = "" + for p in params: + if type(p)==float: + pstr += " %.6g"%p + else: + pstr += " %s"%p + return "%s%s"%(kwd, pstr) + + def write(self, kwd, *params): + self.file.write("%s%s;\n"%('\t'*self.indent, self.make(kwd, *params))) + + def begin(self, kwd, *params): + i = '\t'*self.indent + self.file.write("%s%s\n%s{\n"%(i, self.make(kwd, *params), i)) + self.indent += 1 + + def end(self): + self.indent -= 1 + self.file.write("%s};\n"%('\t'*self.indent)) diff --git a/blender/io_mesh_mspgl/util.py b/blender/io_mspgl/util.py similarity index 100% rename from blender/io_mesh_mspgl/util.py rename to blender/io_mspgl/util.py -- 2.45.2