[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [4357] contrib/py/scripts/addons/ io_scene_x: - Meshes are now enumerated in a consistent way.

Chris Foster cdbfoster at gmail.com
Mon Mar 11 17:07:44 CET 2013


Revision: 4357
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=4357
Author:   kiravakaan
Date:     2013-03-11 16:07:43 +0000 (Mon, 11 Mar 2013)
Log Message:
-----------
- Meshes are now enumerated in a consistent way.
- Implemented the option to export bones in their rest positions.
- Finished export of armature skin weights
- Updated Blender version to (2, 66, 0)

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	2013-03-11 13:51:54 UTC (rev 4356)
+++ contrib/py/scripts/addons/io_scene_x/__init__.py	2013-03-11 16:07:43 UTC (rev 4357)
@@ -22,7 +22,7 @@
     "name": "DirectX X Format",
     "author": "Chris Foster",
     "version": (3, 0, 0),
-    "blender": (2, 63, 0),
+    "blender": (2, 66, 0),
     "location": "File > Export > DirectX (.x)",
     "description": "Export mesh vertices, UV's, materials, textures, "\
         "vertex colors, armatures, empties, and actions.",
@@ -110,12 +110,6 @@
             ('FULL', "Full Animation", "")),
         default='NONE')
     
-    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 "\
@@ -123,6 +117,12 @@
     #        "together into a single set",
     #    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)
+
     Verbose = BoolProperty(
         name="Verbose",
         description="Run the exporter in debug mode. Check the console for "\

Modified: contrib/py/scripts/addons/io_scene_x/export_x.py
===================================================================
--- contrib/py/scripts/addons/io_scene_x/export_x.py	2013-03-11 13:51:54 UTC (rev 4356)
+++ contrib/py/scripts/addons/io_scene_x/export_x.py	2013-03-11 16:07:43 UTC (rev 4357)
@@ -47,7 +47,7 @@
         self.ExportMap = {} # XXX Do we keep ExportMap around in self?  Or should it be local?
         for Object in ExportList:
             if Object.type == 'EMPTY':
-                self.ExportMap[Object] = ExportObject(self.Config, self, Object)
+                self.ExportMap[Object] = EmptyExportObject(self.Config, self, Object)
             elif Object.type == 'MESH':
                 self.ExportMap[Object] = MeshExportObject(self.Config, self,
                     Object)
@@ -188,173 +188,222 @@
             Child.Write()
 
 
+class EmptyExportObject(ExportObject):
+    def __init__(self, Config, Exporter, BlenderObject):
+        ExportObject.__init__(self, Config, Exporter, BlenderObject)
+
+    def __repr__(self):
+        return "[EmptyExportObject: {}]".format(self.name)
+    
+
 class MeshExportObject(ExportObject):
     def __init__(self, Config, Exporter, BlenderObject):
         ExportObject.__init__(self, Config, Exporter, BlenderObject)
 
     def __repr__(self):
-        return "[MeshExportObject: {}]".format(self.BlenderObject.name)
+        return "[MeshExportObject: {}]".format(self.name)
 
     # "Public" Interface
 
     def Write(self):
         self._OpenFrame()
 
-        if self.Exporter.Config.ExportMeshes:
+        if self.Config.ExportMeshes:
             # Generate the export mesh
             Mesh = None
             if self.Config.ApplyModifiers:
+                DeactivatedModifierList = []
+                
+                if self.Config.ExportSkinWeights:
+                    DeactivatedModifierList = [Modifier
+                        for Modifier in self.BlenderObject.modifiers
+                        if Modifier.type == 'ARMATURE' and Modifier.show_viewport]
+                
+                for Modifier in DeactivatedModifierList:
+                    Modifier.show_viewport = False
+                        
                 Mesh = self.BlenderObject.to_mesh(self.Exporter.context.scene,
                     True, 'PREVIEW')
+                
+                for Modifier in DeactivatedModifierList:
+                    Modifier.show_viewport = True   
             else:
                 Mesh = self.BlenderObject.to_mesh(self.Exporter.context.scene,
                     False, 'PREVIEW')
                     
             self.__WriteMesh(Mesh)
+            bpy.data.meshes.remove(Mesh)
 
         self._WriteChildren()
 
         self._CloseFrame()
 
-    # "Private" Methods
+    # "Protected"
+    
+    class _MeshEnumerator:
+        def __init__(self, Mesh):
+            self.Mesh = Mesh
+            
+            self.vertices = None 
+            self.polygons = None
+            
+            self.VertexIndexes = None # self.vertices[x] == Mesh.vertices[self.VertexIndexes[x]]
+            self.PolygonVertexIndexes = None # Mesh.vertices[Mesh.polygons[x].vertices[y]] == self.vertices[self.PolygonVertexIndexes[x][y]]
+    
+    class _OneToOneMeshEnumerator(_MeshEnumerator):
+        def __init__(self, Mesh):
+            MeshExportObject._MeshEnumerator.__init__(self, Mesh)
+            
+            self.vertices = Mesh.vertices
+            self.polygons = Mesh.polygons # Needed?
+            
+            self.VertexIndexes = tuple(range(0, len(self.vertices))) # Needed?
+            self.PolygonVertexIndexes = tuple(tuple(Polygon.vertices)
+                for Polygon in Mesh.polygons)
 
-    def __WriteMesh(self, Mesh):
-        self.Exporter.File.Write("Mesh {{ // {} mesh\n".format(self.SafeName))
-        self.Exporter.File.Indent()
-
-        if (self.Exporter.Config.ExportUVCoordinates and Mesh.uv_textures):# or \
-           #self.Exporter.Config.ExportVertexColors: XXX
-            VertexCount = 0
+    class _UnrolledFacesMeshEnumerator(_MeshEnumerator):
+        def __init__(self, Mesh):
+            MeshExportObject._MeshEnumerator.__init__(self, Mesh)
+            
+            self.vertices = tuple()
             for Polygon in Mesh.polygons:
-                VertexCount += len(Polygon.vertices)
+                self.vertices += tuple(Mesh.vertices[VertexIndex]
+                    for VertexIndex in Polygon.vertices)
             
-            # Write vertex positions
-            Index = 0
-            self.Exporter.File.Write("{};\n".format(VertexCount))
+            self.polygons = Mesh.polygons
+            
+            self.VertexIndexes = tuple()
             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)
+                self.VertexIndexes += tuple(Polygon.vertices)
             
-            # Write face definitions
+            self.PolygonVertexIndexes = []
             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)
+                self.PolygonVertexIndexes.append(tuple(range(Index, 
+                    Index + len(Polygon.vertices))))
+                Index += len(Polygon.vertices)
+            
+            
+            
+            
+            
+            
+            
+
+    # "Private" Methods
+
+    def __WriteMesh(self, Mesh):
+        self.Exporter.File.Write("Mesh {{ // {} mesh\n".format(self.SafeName))
+        self.Exporter.File.Indent()
+        
+        MeshEnumerator = None
+        if (self.Config.ExportUVCoordinates and Mesh.uv_textures):
+            MeshEnumerator = MeshExportObject._UnrolledFacesMeshEnumerator(Mesh)
         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)
-
-        if self.Exporter.Config.ExportNormals:
+            MeshEnumerator = MeshExportObject._OneToOneMeshEnumerator(Mesh)
+        
+        # Write vertex positions
+        VertexCount = len(MeshEnumerator.vertices)
+        self.Exporter.File.Write("{};\n".format(VertexCount))
+        for Index, Vertex in enumerate(MeshEnumerator.vertices):
+            Position = Vertex.co
+            self.Exporter.File.Write("{:9f};{:9f};{:9f};".format(
+                        Position[0], Position[1], Position[2]))
+            
+            if Index == VertexCount - 1:
+                self.Exporter.File.Write(";\n", Indent=False)
+            else:
+                self.Exporter.File.Write(",\n", Indent=False)
+        
+        # Write face definitions
+        PolygonCount = len(MeshEnumerator.polygons)

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-extensions-cvs mailing list