From 1bad86b461abd4fe2a1cb1c6c5685adf5db13935 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Wed, 7 May 2014 00:02:39 +0300 Subject: [PATCH] More options for exporting techniques --- blender/io_mspgl/__init__.py | 11 +++++++++++ blender/io_mspgl/export_object.py | 25 +++++++++++++++++++++++-- blender/io_mspgl/properties.py | 2 ++ 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/blender/io_mspgl/__init__.py b/blender/io_mspgl/__init__.py index 9f7c48e1..a8cdb4c1 100644 --- a/blender/io_mspgl/__init__.py +++ b/blender/io_mspgl/__init__.py @@ -54,6 +54,7 @@ class ExportMspGLMeshBase(ExportMspGLBase): col.prop(self, "compound") col.prop(self, "smoothing") col.prop(self, "export_groups") + self.general_col = col self.layout.separator() @@ -95,6 +96,8 @@ class ExportMspGLObject(bpy.types.Operator, ExportMspGLMeshBase): filename_ext = ".object" + external_tech = bpy.props.BoolProperty(name="External technique", description="Use an external technique specified in the object", default=True) + textures = bpy.props.EnumProperty(name="Textures", description="Export textures", default="REF", items=(("NONE", "None", "Ignore textures"), ("REF", "Referenced", "Reference external data"), @@ -103,6 +106,8 @@ class ExportMspGLObject(bpy.types.Operator, ExportMspGLMeshBase): srgb_colors = bpy.props.BoolProperty(name="sRGB colors", description="Export material colors as sRGB instead of linear", default=True) separate_mesh = bpy.props.BoolProperty(name="Separate mesh", description="Write mesh data into a separate file", default=False) + separate_tech = bpy.props.BoolProperty(name="Separate technique", description="Write technique data into a separate file", default=False) + shared_tech = bpy.props.BoolProperty(name="Shared technique", description="Use material name for technique file to enable sharing", default=True) def create_exporter(self): from .export_object import ObjectExporter @@ -111,6 +116,9 @@ class ExportMspGLObject(bpy.types.Operator, ExportMspGLMeshBase): def draw(self, context): super().draw(context) + col = self.general_col + col.prop(self, "external_tech") + col = self.texturing_col col.prop(self, "textures") col.prop(self, "material_tex") @@ -121,6 +129,9 @@ class ExportMspGLObject(bpy.types.Operator, ExportMspGLMeshBase): col = self.layout.column() col.label("Files") col.prop(self, "separate_mesh") + col.prop(self, "separate_tech") + if self.separate_tech: + col.prop(self, "shared_tech") class ExportMspGLArmature(bpy.types.Operator, ExportMspGLBase): bl_idname = "export.mspgl_armature" diff --git a/blender/io_mspgl/export_object.py b/blender/io_mspgl/export_object.py index 8065c09a..7b9ee6a4 100644 --- a/blender/io_mspgl/export_object.py +++ b/blender/io_mspgl/export_object.py @@ -13,8 +13,13 @@ class ObjectExporter: self.srgb_colors = True self.textures = "REF" self.separate_mesh = False + self.separate_tech = False + self.external_tech = True + self.shared_tech = True def export(self, context, out_file): + obj = context.active_object + from .outfile import open_output out_file = open_output(out_file) @@ -34,7 +39,24 @@ class ObjectExporter: mesh = mesh_export.export(context, out_file) out_file.end() - out_file.begin("technique") + if self.external_tech and obj.technique: + out_file.write("technique", '"{}"'.format(obj.technique)) + elif self.separate_tech: + path, base = os.path.split(out_file.filename) + if self.shared_tech and mesh.materials: + tech_name = mesh.materials[0].name+".tech" + else: + base, ext = os.path.splitext(base) + tech_name = base+".tech" + tech_out = open_output(os.path.join(path, tech_name)) + self.export_technique(mesh, tech_out) + out_file.write("technique", '"{}"'.format(tech_name)) + else: + out_file.begin("technique") + self.export_technique(mesh, out_file) + out_file.end() + + def export_technique(self, mesh, out_file): out_file.begin("pass", '""') if mesh.materials: if self.srgb_colors: @@ -112,4 +134,3 @@ class ObjectExporter: out_file.end() out_file.end() - out_file.end() diff --git a/blender/io_mspgl/properties.py b/blender/io_mspgl/properties.py index d2d36cb9..dcc8cc34 100644 --- a/blender/io_mspgl/properties.py +++ b/blender/io_mspgl/properties.py @@ -10,7 +10,9 @@ class MspGLProperties(bpy.types.Panel): def draw(self, context): obj = context.active_object + self.layout.prop(obj, "technique"); self.layout.prop(obj, "compound"); def register_properties(): + bpy.types.Object.technique = bpy.props.StringProperty(name="Technique", description="Name of the technique to use for rendering") bpy.types.Object.compound = bpy.props.BoolProperty(name="Compound with parent", description="Join this object to its parent when exporting") -- 2.45.2