From 74ff9632637c44fddd06863968b38e12f18b1860 Mon Sep 17 00:00:00 2001
From: Chris Foster <cdbfoster@gmail.com>
Date: Mon, 9 Dec 2013 13:32:06 -0500
Subject: [PATCH] Re-added the Coordinate System and Up Axis options. 
 Apparently XNA uses a right handed system and the option was useful for some
 users.  Oops!

---
 io_scene_x/__init__.py | 14 ++++++++++++++
 io_scene_x/export_x.py | 18 +++++++++++-------
 2 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/io_scene_x/__init__.py b/io_scene_x/__init__.py
index 519ca16cd..394954e6d 100644
--- a/io_scene_x/__init__.py
+++ b/io_scene_x/__init__.py
@@ -53,6 +53,20 @@ class ExportDirectX(bpy.types.Operator):
         description="Export only selected objects",
         default=True)
         
+    CoordinateSystem = EnumProperty(
+        name="Coordinate System",
+        description="Use the selected coordinate system for export",
+        items=(('LEFT_HANDED', "Left-Handed", "Use a Y up, Z forward system or a Z up, -Y forward system"),
+               ('RIGHT_HANDED', "Right-Handed", "Use a Y up, -Z forward system or a Z up, Y forward system")),
+        default='LEFT_HANDED')
+        
+    UpAxis = EnumProperty(
+        name="Up Axis",
+        description="The selected axis points upward",
+        items=(('Y', "Y", "The Y axis points up"),
+               ('Z', "Z", "The Z axis points up")),
+        default='Y')
+        
     ExportMeshes = BoolProperty(
         name="Export Meshes",
         description="Export mesh objects",
diff --git a/io_scene_x/export_x.py b/io_scene_x/export_x.py
index f8ccdef2c..dcaf22064 100644
--- a/io_scene_x/export_x.py
+++ b/io_scene_x/export_x.py
@@ -34,9 +34,16 @@ class DirectXExporter:
         self.File = File(self.Config.filepath)
 
         self.Log("Setting up coordinate system...")
-        # SystemMatrix converts from right-handed, z-up to left-handed, y-up
-        self.SystemMatrix = (Matrix.Scale(-1, 4, Vector((0, 0, 1))) *
-            Matrix.Rotation(radians(-90), 4, 'X'))
+        
+        # SystemMatrix converts from right-handed, z-up to the target coordinate system
+        self.SystemMatrix = Matrix()
+        
+        if self.Config.CoordinateSystem == 'LEFT_HANDED':
+            self.SystemMatrix *= Matrix.Scale(-1, 4, Vector((0, 0, 1)))
+        
+        if self.Config.UpAxis == 'Y':
+            self.SystemMatrix *= Matrix.Rotation(radians(-90), 4, 'X')
+            
         self.Log("Done")
 
         self.Log("Generating object lists for export...")
@@ -469,8 +476,6 @@ class MeshExportObject(ExportObject):
             
             self.Exporter.File.Write("{};".format(len(PolygonVertexIndexes)))
             
-            PolygonVertexIndexes = PolygonVertexIndexes[::-1]
-            
             for VertexCountIndex, VertexIndex in \
                 enumerate(PolygonVertexIndexes):
 
@@ -574,8 +579,7 @@ class MeshExportObject(ExportObject):
         for Index, Polygon in enumerate(MeshEnumerator.PolygonVertexIndexes):
             self.Exporter.File.Write("{};".format(len(Polygon)))
             
-            # Reverse the winding order
-            for VertexCountIndex, VertexIndex in enumerate(Polygon[::-1]):
+            for VertexCountIndex, VertexIndex in enumerate(Polygon):
                 if VertexCountIndex == len(Polygon) - 1:
                     self.Exporter.File.Write("{};".format(VertexIndex),
                         Indent=False)
-- 
GitLab