[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [3743] contrib/py/scripts/addons/ io_scene_x: Added support for texture coordinates, materials, and armature bones.

Chris Foster cdbfoster at gmail.com
Sun Sep 16 06:22:29 CEST 2012


Revision: 3743
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=3743
Author:   kiravakaan
Date:     2012-09-16 04:22:21 +0000 (Sun, 16 Sep 2012)
Log Message:
-----------
Added support for texture coordinates, materials, and armature bones.

Modified Paths:
--------------
    contrib/py/scripts/addons/io_scene_x/__init__.py
    contrib/py/scripts/addons/io_scene_x/export_x.py

Modified: contrib/py/scripts/addons/io_scene_x/__init__.py
===================================================================
--- contrib/py/scripts/addons/io_scene_x/__init__.py	2012-09-15 21:07:16 UTC (rev 3742)
+++ contrib/py/scripts/addons/io_scene_x/__init__.py	2012-09-16 04:22:21 UTC (rev 3743)
@@ -56,27 +56,48 @@
         name="Apply Modifiers",
         description="Apply object modifiers before export",
         default=False)
+        
+    # XXX Change this stuff to property groups if possible
+    ExportMeshes = BoolProperty(
+        name="Export Meshes",
+        description="Export mesh objects",
+        default=True)
+        
+    ExportNormals = BoolProperty(
+        name="    Export Normals",
+        description="Export mesh normals",
+        default=True)
+    
+    ExportUVCoordinates = BoolProperty(
+        name="    Export UV Coordinates",
+        description="Export mesh UV coordinates, if any",
+        default=True)
 
-    ExportArmatures = BoolProperty(
-        name="Export Armatures",
-        description="Export the bones armatures",
-        default=False)
-
-    ExportTextures = BoolProperty(
-        name="Export Textures",
-        description="Reference external image files to be used by the model",
+    ExportMaterials = BoolProperty(
+        name="    Export Materials",
+        description="Export material properties and reference image textures",
         default=True)
 
-    ExportVertexColors = BoolProperty(
-        name="Export Vertex Colors",
-        description="Export mesh vertex colors, if any",
+    #ExportVertexColors = BoolProperty(
+    #    name="    Export Vertex Colors",
+    #    description="Export mesh vertex colors, if any",
+    #    default=False)
+    
+    ExportSkinWeights = BoolProperty(
+        name="    Export Skin Weights",
+        description="Bind mesh vertices to armature bones",
         default=False)
-
-    IncludeFrameRate = BoolProperty(
-        name="Include Frame Rate",
-        description="Include the AnimTicksPerSecond template which is "\
-            "used by some engines to control animation speed",
+    
+    ExportArmatureBones = BoolProperty(
+        name="Export Armature Bones",
+        description="Export armatures bones",
         default=False)
+    
+    ExportRestBone = BoolProperty(
+        name="    Export Rest Position",
+        description="Export bones in their rest position (recommended for "\
+            "animation)",
+        default=False)
 
     ExportAnimation = EnumProperty(
         name="Animations",
@@ -88,14 +109,20 @@
             ('KEYS', "Keyframes Only", ""),
             ('FULL', "Full Animation", "")),
         default='NONE')
-
-    ExportActionsAsSets = BoolProperty(
-        name="Export Actions as AnimationSets",
-        description="Export each action of each object as a separate "\
-            "AnimationSet. Otherwise all current actions are lumped "\
-            "together into a single set",
+    
+    IncludeFrameRate = BoolProperty(
+        name="Include Frame Rate",
+        description="Include the AnimTicksPerSecond template which is "\
+            "used by some engines to control animation speed",
         default=False)
 
+    #ExportActionsAsSets = BoolProperty(
+    #    name="Export Actions as AnimationSets",
+    #    description="Export each action of each object as a separate "\
+    #        "AnimationSet. Otherwise all current actions are lumped "\
+    #        "together into a single set",
+    #    default=False)
+
     Verbose = BoolProperty(
         name="Verbose",
         description="Run the exporter in debug mode. Check the console for "\
@@ -107,7 +134,7 @@
 
         import export_x
         Exporter = export_x.DirectXExporter(self, context)
-        Exporter.Export() # XXX CHANGE THIS
+        Exporter.Export() # XXX Rename this
         return {'FINISHED'}
 
     def invoke(self, context, event):
@@ -135,3 +162,4 @@
 
 if __name__ == "__main__":
     register()
+

Modified: contrib/py/scripts/addons/io_scene_x/export_x.py
===================================================================
--- contrib/py/scripts/addons/io_scene_x/export_x.py	2012-09-15 21:07:16 UTC (rev 3742)
+++ contrib/py/scripts/addons/io_scene_x/export_x.py	2012-09-16 04:22:21 UTC (rev 3743)
@@ -59,6 +59,7 @@
         # not exporting
         self.RootExportList = [Object for Object in self.ExportMap.values()
             if Object.BlenderObject.parent not in ExportList]
+        self.RootExportList = Util.SortByNameField(self.RootExportList)
 
         # Determine each object's children from the pool of ExportObjects
         for Object in self.ExportMap.values():
@@ -112,7 +113,7 @@
   <9E415A43-7BA6-4a73-8743-B73D47E88476>\n\
   DWORD AnimTicksPerSecond;\n\
 }\n\n")
-        if self.Config.ExportArmatures:
+        if self.Config.ExportSkinWeights:
             self.File.Write("template XSkinMeshHeader {\n\
   <3cf169ce-ff7c-44ab-93c0-f78f62d172e2>\n\
   WORD nMaxSkinWeightsPerVertex;\n\
@@ -150,6 +151,7 @@
         self.Exporter = Exporter
         self.BlenderObject = BlenderObject
 
+        self.name = self.BlenderObject.name # Simple alias
         self.SafeName = Util.SafeName(self.BlenderObject.name)
         self.Children = []
 
@@ -182,7 +184,7 @@
         self.Exporter.File.Write("}} // End of {}\n".format(self.SafeName))
 
     def _WriteChildren(self):
-        for Child in self.Children:
+        for Child in Util.SortByNameField(self.Children):
             Child.Write()
 
 
@@ -190,8 +192,6 @@
     def __init__(self, Config, Exporter, BlenderObject):
         ExportObject.__init__(self, Config, Exporter, BlenderObject)
 
-        # Determine if this mesh has an armature
-
     def __repr__(self):
         return "[MeshExportObject: {}]".format(self.BlenderObject.name)
 
@@ -200,16 +200,18 @@
     def Write(self):
         self._OpenFrame()
 
-        # Generate the export mesh
-        if self.Config.ApplyModifiers:
-            Mesh = self.BlenderObject.to_mesh(self.Exporter.context.scene,
-                True, 'PREVIEW')
-        else:
-            Mesh = self.BlenderObject.to_mesh(self.Exporter.context.scene,
-                False, 'PREVIEW')
+        if self.Exporter.Config.ExportMeshes:
+            # Generate the export mesh
+            Mesh = None
+            if self.Config.ApplyModifiers:
+                Mesh = self.BlenderObject.to_mesh(self.Exporter.context.scene,
+                    True, 'PREVIEW')
+            else:
+                Mesh = self.BlenderObject.to_mesh(self.Exporter.context.scene,
+                    False, 'PREVIEW')
+                    
+            self.__WriteMesh(Mesh)
 
-        self.__WriteMesh(Mesh)
-
         self._WriteChildren()
 
         self._CloseFrame()
@@ -220,35 +222,78 @@
         self.Exporter.File.Write("Mesh {{ // {} mesh\n".format(self.SafeName))
         self.Exporter.File.Indent()
 
-        # Write vertex positions
-        self.Exporter.File.Write("{};\n".format(len(Mesh.vertices)))
-        for Index, Vertex in enumerate(Mesh.vertices):
-            Position = Vertex.co
-            self.Exporter.File.Write("{:9f};{:9f};{:9f};".format(Position[0],
-                Position[1], Position[2]))
-            if Index == len(Mesh.vertices) - 1:
-                self.Exporter.File.Write(";\n", Indent=False)
-            else:
-                self.Exporter.File.Write(",\n", Indent=False)
+        if (self.Exporter.Config.ExportUVCoordinates and Mesh.uv_textures):# or \
+           #self.Exporter.Config.ExportVertexColors: XXX
+            VertexCount = 0
+            for Polygon in Mesh.polygons:
+                VertexCount += len(Polygon.vertices)
+            
+            # Write vertex positions
+            Index = 0
+            self.Exporter.File.Write("{};\n".format(VertexCount))
+            for Polygon in Mesh.polygons:
+                Vertices = list(Polygon.vertices)[::-1]
+                
+                for Vertex in [Mesh.vertices[Vertex] for Vertex in Vertices]:
+                    Position = Vertex.co
+                    self.Exporter.File.Write("{:9f};{:9f};{:9f};".format(
+                        Position[0], Position[1], Position[2]))
+                    Index += 1
+                    if Index == VertexCount:
+                        self.Exporter.File.Write(";\n", Indent=False)
+                    else:
+                        self.Exporter.File.Write(",\n", Indent=False)
+            
+            # Write face definitions
+            Index = 0
+            self.Exporter.File.Write("{};\n".format(len(Mesh.polygons)))
+            for Polygon in Mesh.polygons:
+                self.Exporter.File.Write("{};".format(len(Polygon.vertices)))
+                for Vertex in Polygon.vertices:
+                    self.Exporter.File.Write("{};".format(Index), Indent=False)
+                    Index += 1
+                if Index == VertexCount:
+                    self.Exporter.File.Write(";\n", Indent=False)
+                else:
+                    self.Exporter.File.Write(",\n", Indent=False)
+        else:
+            # Write vertex positions
+            self.Exporter.File.Write("{};\n".format(len(Mesh.vertices)))
+            for Index, Vertex in enumerate(Mesh.vertices):
+                Position = Vertex.co
+                self.Exporter.File.Write("{:9f};{:9f};{:9f};".format(
+                    Position[0], Position[1], Position[2]))
+                if Index == len(Mesh.vertices) - 1:
+                    self.Exporter.File.Write(";\n", Indent=False)
+                else:
+                    self.Exporter.File.Write(",\n", Indent=False)
+    
+            # Write face definitions
+            self.Exporter.File.Write("{};\n".format(len(Mesh.polygons)))
+            for Index, Polygon in enumerate(Mesh.polygons):
+                # Change the winding order of the face
+                Vertices = list(Polygon.vertices)[::-1]
+    
+                self.Exporter.File.Write("{};".format(len(Vertices)))
+                for Vertex in Vertices:
+                    self.Exporter.File.Write("{};".format(Vertex), Indent=False)
+                if Index == len(Mesh.polygons) - 1:
+                    self.Exporter.File.Write(";\n", Indent=False)
+                else:
+                    self.Exporter.File.Write(",\n", Indent=False)
 
-        # Write face definitions
-        self.Exporter.File.Write("{};\n".format(len(Mesh.polygons)))

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-extensions-cvs mailing list