[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [1118] trunk/py/scripts/addons/ io_export_directx_x.py: Whew, a lot of changes.

Chris Foster cdbfoster at gmail.com
Sun Oct 24 21:05:34 CEST 2010


Revision: 1118
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-extensions&revision=1118
Author:   kiravakaan
Date:     2010-10-24 21:05:34 +0200 (Sun, 24 Oct 2010)

Log Message:
-----------
Whew, a lot of changes.  Ditched efforts to translate matrices/quaternions between systems and instead applied a root matrix at the beginning of the exported file.  Fixed nasty bug in Full Animation with armatures.  Fixed Verbose mode output formatting.  Fixed issue with animating parented objects.  Checked with revision 32681.  Now version 1.9.  Version 2.0 if no new bugs are found.

Revision Links:
--------------
    http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-extensions&revision=32681

Modified Paths:
--------------
    trunk/py/scripts/addons/io_export_directx_x.py

Modified: trunk/py/scripts/addons/io_export_directx_x.py
===================================================================
--- trunk/py/scripts/addons/io_export_directx_x.py	2010-10-24 14:03:03 UTC (rev 1117)
+++ trunk/py/scripts/addons/io_export_directx_x.py	2010-10-24 19:05:34 UTC (rev 1118)
@@ -18,9 +18,9 @@
 bl_addon_info = {
     "name": "Export DirectX Model Format (.x)",
     "author": "Chris Foster (Kira Vakaan)",
-    "version": (1,6),
+    "version": (1,9),
     "blender": (2, 5, 3),
-    "api": 31847,
+    "api": 32681,
     "location": "File > Export",
     "description": "Export to the DirectX Model Format (.x)",
     "warning": "",
@@ -91,13 +91,13 @@
 def ExportDirectX(Config):
     print("----------\nExporting to {}".format(Config.FilePath))
     if Config.Verbose:
-        print("Opening File...", end=" ")
+        print("Opening File...")
     Config.File = open(Config.FilePath, "w")
     if Config.Verbose:
         print("Done")
 
     if Config.Verbose:
-        print("Generating Object list for export...", end=" ")
+        print("Generating Object list for export...")
     if Config.ExportMode == 1:
         Config.ExportList = [Object for Object in Config.context.scene.objects
                              if Object.type in ("ARMATURE", "EMPTY", "MESH")
@@ -111,20 +111,12 @@
         print("Done")
 
     if Config.Verbose:
-        print("Setting up...", end=" ")
+        print("Setting up...")
     Config.SystemMatrix = Matrix()
     if Config.RotateX:
         Config.SystemMatrix *= Matrix.Rotation(radians(-90), 4, "X")
     if Config.CoordinateSystem == 1:
         Config.SystemMatrix *= Matrix.Scale(-1, 4, Vector((0, 1, 0)))
-    Config.InverseSystemMatrix = Config.SystemMatrix.copy().invert()
-    
-    #Used for animating rotations
-    Config.SystemQuaternion = Quaternion((1,0,0,0))
-    if Config.RotateX:
-        Config.SystemQuaternion = Matrix.Rotation(radians(-90), 3, "X").to_quat()
-    Config.InverseSystemQuaternion = Config.SystemQuaternion.copy().inverse()
-    Config.FlipZ = -1 if Config.CoordinateSystem == 1 else 1
 
     if Config.ExportAnimation:
         CurrentFrame = bpy.context.scene.frame_current
@@ -133,23 +125,32 @@
         print("Done")
 
     if Config.Verbose:
-        print("Writing Header...", end=" ")
+        print("Writing Header...")
     WriteHeader(Config)
     if Config.Verbose:
         print("Done")
 
     Config.Whitespace = 0
+    if Config.Verbose:
+        print("Writing Root Frame...")
+    WriteRootFrame(Config)
+    if Config.Verbose:
+        print("Done")
+    
     Config.ObjectList = []
     if Config.Verbose:
         print("Writing Objects...")
     WriteObjects(Config, Config.ExportList)
     if Config.Verbose:
         print("Done")
+    
+    Config.Whitespace -= 1
+    Config.File.write("{}}} //End of Root Frame\n".format("  " * Config.Whitespace))
 
     if Config.ExportAnimation:
         if Config.IncludeFrameRate:
             if Config.Verbose:
-                print("Writing Frame Rate...", end=" ")
+                print("Writing Frame Rate...")
             Config.File.write("{}AnimTicksPerSecond {{\n".format("  " * Config.Whitespace))
             Config.Whitespace += 1
             Config.File.write("{}{};\n".format("  " * Config.Whitespace, int(bpy.context.scene.render.fps / bpy.context.scene.render.fps_base)))
@@ -212,6 +213,18 @@
   Matrix4x4 matrixOffset;\n\
 }\n\n")
 
+def WriteRootFrame(Config):
+    Config.File.write("{}Frame Root {{\n".format("  " * Config.Whitespace))
+    Config.Whitespace += 1
+    
+    Config.File.write("{}FrameTransformMatrix {{\n".format("  " * Config.Whitespace))
+    Config.Whitespace += 1
+    Config.File.write("{}{:9f},{:9f},{:9f},{:9f},\n".format("  " * Config.Whitespace, Config.SystemMatrix[0][0], Config.SystemMatrix[0][1], Config.SystemMatrix[0][2], Config.SystemMatrix[0][3]))
+    Config.File.write("{}{:9f},{:9f},{:9f},{:9f},\n".format("  " * Config.Whitespace, Config.SystemMatrix[1][0], Config.SystemMatrix[1][1], Config.SystemMatrix[1][2], Config.SystemMatrix[1][3]))
+    Config.File.write("{}{:9f},{:9f},{:9f},{:9f},\n".format("  " * Config.Whitespace, Config.SystemMatrix[2][0], Config.SystemMatrix[2][1], Config.SystemMatrix[2][2], Config.SystemMatrix[2][3]))
+    Config.File.write("{}{:9f},{:9f},{:9f},{:9f};;\n".format("  " * Config.Whitespace, Config.SystemMatrix[3][0], Config.SystemMatrix[3][1], Config.SystemMatrix[3][2], Config.SystemMatrix[3][3]))
+    Config.Whitespace -= 1
+    Config.File.write("{}}}\n".format("  " * Config.Whitespace))
 
 def WriteObjects(Config, ObjectList):
     Config.ObjectList += ObjectList
@@ -223,10 +236,10 @@
 
         Config.Whitespace += 1
         if Config.Verbose:
-            print("    Writing Local Matrix...", end=" ")
+            print("    Writing Local Matrix...")
         WriteLocalMatrix(Config, Object)
         if Config.Verbose:
-            print("Done")
+            print("    Done")
 
         if Config.ExportArmatures and Object.type == "ARMATURE":
             Armature = Object.data
@@ -246,7 +259,7 @@
 
         if Object.type == "MESH":
             if Config.Verbose:
-                print("    Generating Mesh...", end=" ")
+                print("    Generating Mesh...")
             if Config.ApplyModifiers:
                 if Config.ExportArmatures:
                     #Create a copy of the object and remove all armature modifiers so an unshaped
@@ -260,7 +273,7 @@
             else:
                 Mesh = Object.create_mesh(bpy.context.scene, False, "PREVIEW")
             if Config.Verbose:
-                print("Done")
+                print("    Done")
                 print("    Writing Mesh...")
             WriteMesh(Config, Object, Mesh)
             if Config.Verbose:
@@ -276,7 +289,7 @@
 
 
 def WriteLocalMatrix(Config, Object):
-    LocalMatrix = Config.SystemMatrix * Object.matrix_local * Config.InverseSystemMatrix
+    LocalMatrix = Object.matrix_local
 
     Config.File.write("{}FrameTransformMatrix {{\n".format("  " * Config.Whitespace))
     Config.Whitespace += 1
@@ -292,21 +305,19 @@
     PoseBones = Object.pose.bones
     for Bone in ChildList:
         if Config.Verbose:
-            print("      Writing Bone: {}...".format(Bone.name), end=" ")
+            print("      Writing Bone: {}...".format(Bone.name))
         Config.File.write("{}Frame {} {{\n".format("  " * Config.Whitespace, LegalName(Object.name) + "_" + LegalName(Bone.name)))
         Config.Whitespace += 1
 
         PoseBone = PoseBones[Bone.name]
 
         if Bone.parent:
-            BoneMatrix = (PoseBone.parent.matrix *
-                          Matrix.Rotation(radians(-90), 4, "X")).invert()
+            BoneMatrix = PoseBone.parent.matrix.copy().invert()
         else:
             BoneMatrix = Matrix()
 
-        BoneMatrix *= PoseBone.matrix * Matrix.Rotation(radians(-90), 4, "X")
-        BoneMatrix = Config.SystemMatrix * BoneMatrix * Config.InverseSystemMatrix
-
+        BoneMatrix *= PoseBone.matrix
+        
         Config.File.write("{}FrameTransformMatrix {{\n".format("  " * Config.Whitespace))
         Config.Whitespace += 1
         Config.File.write("{}{:9f},{:9f},{:9f},{:9f},\n".format("  " * Config.Whitespace, BoneMatrix[0][0], BoneMatrix[0][1], BoneMatrix[0][2], BoneMatrix[0][3]))
@@ -317,7 +328,7 @@
         Config.File.write("{}}}\n".format("  " * Config.Whitespace))
 
         if Config.Verbose:
-            print("Done")
+            print("      Done")
         WriteArmatureBones(Config, Object, Bone.children)
         Config.Whitespace -= 1
 
@@ -329,28 +340,28 @@
     Config.Whitespace += 1
 
     if Config.Verbose:
-        print("      Writing Mesh Vertices...", end=" ")
+        print("      Writing Mesh Vertices...")
     WriteMeshVertices(Config, Mesh)
     if Config.Verbose:
-        print("Done\n      Writing Mesh Normals...", end=" ")
+        print("      Done\n      Writing Mesh Normals...")
     WriteMeshNormals(Config, Mesh)
     if Config.Verbose:
-        print("Done\n      Writing Mesh Materials...", end=" ")
+        print("      Done\n      Writing Mesh Materials...")
     WriteMeshMaterials(Config, Mesh)
     if Config.Verbose:
-        print("Done")
+        print("      Done")
     if Mesh.uv_textures:
         if Config.Verbose:
-            print("      Writing Mesh UV Coordinates...", end=" ")
+            print("      Writing Mesh UV Coordinates...")
         WriteMeshUVCoordinates(Config, Mesh)
         if Config.Verbose:
-            print("Done")
+            print("      Done")
     if Config.ExportArmatures:
         if Config.Verbose:
-            print("      Writing Mesh Skin Weights...", end=" ")
+            print("      Writing Mesh Skin Weights...")
         WriteMeshSkinWeights(Config, Object, Mesh)
         if Config.Verbose:
-            print("Done")
+            print("      Done")
 
     Config.Whitespace -= 1
     Config.File.write("{}}} //End of {} Mesh\n".format("  " * Config.Whitespace, LegalName(Mesh.name)))
@@ -367,7 +378,7 @@
         if Config.CoordinateSystem == 1:
             Vertices = Vertices[::-1]
         for Vertex in [Mesh.vertices[Vertex] for Vertex in Vertices]:
-            Position = Config.SystemMatrix * Vertex.co
+            Position = Vertex.co
             Config.File.write("{}{:9f};{:9f};{:9f};".format("  " * Config.Whitespace, Position[0], Position[1], Position[2]))
             Index += 1
             if Index == VertexCount:
@@ -404,9 +415,9 @@
             Vertices = Vertices[::-1]
         for Vertex in [Mesh.vertices[Vertex] for Vertex in Vertices]:
             if Face.use_smooth:
-                Normal = Config.SystemMatrix * Vertex.normal
+                Normal = Vertex.normal
             else:
-                Normal = Config.SystemMatrix * Face.normal
+                Normal = Face.normal
             if Config.FlipNormals:
                 Normal = -Normal
             Config.File.write("{}{:9f};{:9f};{:9f};".format("  " * Config.Whitespace, Normal[0], Normal[1], Normal[2]))
@@ -614,12 +625,10 @@
             #  - Armature Space to Bone Space (The bone matrix needs to be rotated 90 degrees to align with Blender's world axes)
             #This way, when BoneMatrix is transformed by the bone's Frame matrix, the vertices will be in their final world position.
             
-            BoneMatrix = (RestBone.matrix_local * Matrix.Rotation(radians(-90), 4, "X")).invert()

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list