Skip to content
Snippets Groups Projects
io_export_directx_x.py 51.7 KiB
Newer Older
from bpy.props import *

class DirectXExporter(bpy.types.Operator):
    """Export to the DirectX model format (.x)"""

    bl_idname = "export.directx"
    bl_label = "Export DirectX"

    filepath = StringProperty()
    filename = StringProperty()
    directory = StringProperty()

    #Coordinate System
    CoordinateSystem = EnumProperty(name="System", description="Select a coordinate system to export to", items=CoordinateSystems, default="1")

    #General Options
    RotateX = BoolProperty(name="Rotate X 90 Degrees", description="Rotate the entire scene 90 degrees around the X axis so Y is up.", default=True)
    FlipNormals = BoolProperty(name="Flip Normals", description="", default=False)
    ApplyModifiers = BoolProperty(name="Apply Modifiers", description="Apply object modifiers before export.", default=False)
    IncludeFrameRate = BoolProperty(name="Include Frame Rate", description="Include the AnimTicksPerSecond template which is used by some engines to control animation speed.", default=False)
    ExportTextures = BoolProperty(name="Export Textures", description="Reference external image files to be used by the model.", default=True)
    ExportArmatures = BoolProperty(name="Export Armatures", description="Export the bones of any armatures to deform meshes.", default=False)
    ExportAnimation = EnumProperty(name="Animations", description="Select the type of animations to export.  Only object and armature bone animations can be exported.  Full Animation exports every frame.", items=AnimationModes, default="0")
    ExportMode = EnumProperty(name="Export", description="Select which objects to export.  Only Mesh, Empty, and Armature objects will be exported.", items=ExportModes, default="1")

    Verbose = BoolProperty(name="Verbose", description="Run the exporter in debug mode.  Check the console for output.", default=False)

    def execute(self, context):
        #Append .x if needed
        FilePath = self.properties.filepath
        if not FilePath.lower().endswith(".x"):
            FilePath += ".x"

        Config = DirectXExporterSettings(context,
                                         FilePath,
                                         CoordinateSystem=self.properties.CoordinateSystem,
                                         RotateX=self.properties.RotateX,
                                         FlipNormals=self.properties.FlipNormals,
                                         ApplyModifiers=self.properties.ApplyModifiers,
                                         IncludeFrameRate=self.properties.IncludeFrameRate,
                                         ExportTextures=self.properties.ExportTextures,
                                         ExportArmatures=self.properties.ExportArmatures,
                                         ExportAnimation=self.properties.ExportAnimation,
                                         ExportMode=self.properties.ExportMode,
                                         Verbose=self.properties.Verbose)
        ExportDirectX(Config)
        return {"FINISHED"}

    def invoke(self, context, event):
        WindowManager = context.manager
        WindowManager.add_fileselect(self)
        return {"RUNNING_MODAL"}


def menu_func(self, context):
    default_path = os.path.splitext(bpy.data.filepath)[0] + ".x"
    self.layout.operator(DirectXExporter.bl_idname, text="DirectX (.x)").filepath = default_path

def register():
    bpy.types.INFO_MT_file_export.append(menu_func)

def unregister():
    bpy.types.INFO_MT_file_export.remove(menu_func)


if __name__ == "__main__":