]> git.tdb.fi Git - libs/gl.git/commitdiff
More options for exporting techniques
authorMikko Rasa <tdb@tdb.fi>
Tue, 6 May 2014 21:02:39 +0000 (00:02 +0300)
committerMikko Rasa <tdb@tdb.fi>
Tue, 6 May 2014 21:06:49 +0000 (00:06 +0300)
blender/io_mspgl/__init__.py
blender/io_mspgl/export_object.py
blender/io_mspgl/properties.py

index 9f7c48e1ed38493cb846397f3a3bc4cf5bfe43e8..a8cdb4c1d4f10cb3e80fbc9dddaaf4af204351d7 100644 (file)
@@ -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"
index 8065c09ad4a2bac0219eb7ed2254b4c3dfcb6ab8..7b9ee6a44cfb2c8eb888c237b7e1579e358c1fff 100644 (file)
@@ -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()
index d2d36cb9762d428137b06a3e8148c02e3a50af8e..dcc8cc34d55a81b0fd38c16c9bf43a6f6dca5add 100644 (file)
@@ -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")