[Bf-extensions-cvs] [74ff963] master: 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!

Chris Foster noreply at git.blender.org
Mon Dec 9 19:47:01 CET 2013


Commit: 74ff9632637c44fddd06863968b38e12f18b1860
Author: Chris Foster
Date:   Mon Dec 9 13:32:06 2013 -0500
http://developer.blender.org/rBA74ff9632637c44fddd06863968b38e12f18b1860

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!

===================================================================

M	io_scene_x/__init__.py
M	io_scene_x/export_x.py

===================================================================

diff --git a/io_scene_x/__init__.py b/io_scene_x/__init__.py
index 519ca16..394954e 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 f8ccdef..dcaf220 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)



More information about the Bf-extensions-cvs mailing list