[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [4375] contrib/py/scripts/addons/ io_scene_x: - All pre-rewrite functionality has been restored! ... except for verbose logging, which will come soon, along with vertex color support.

Chris Foster cdbfoster at gmail.com
Thu Mar 14 21:41:38 CET 2013


Revision: 4375
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=4375
Author:   kiravakaan
Date:     2013-03-14 20:41:37 +0000 (Thu, 14 Mar 2013)
Log Message:
-----------
- All pre-rewrite functionality has been restored! ...except for verbose logging, which will come soon, along with vertex color support.
- Animation export has been enhanced and now provides an option to export each action as its own AnimationSet, as well as attach unused actions to the first armature.

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-14 17:16:45 UTC (rev 4374)
+++ contrib/py/scripts/addons/io_scene_x/__init__.py	2013-03-14 20:41:37 UTC (rev 4375)
@@ -99,29 +99,30 @@
             "animation)",
         default=False)
 
-    ExportAnimation = EnumProperty(
-        name="Animations",
-        description="Select the type of animations to export. Only object "\
-            "and armature bone animations can be exported. Full Animation "\
-            "exports every frame",
-        items=(
-            ('NONE', "None", ""),
-            ('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",
-    #    default=False)
+    ExportAnimation = BoolProperty(
+        name="Export Animations",
+        description="Export object and bone animations.  Data is exported for "\
+            "every frame",
+        default=False)
 
     IncludeFrameRate = BoolProperty(
-        name="Include Frame Rate",
+        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)
+    
+    AttachToFirstArmature = BoolProperty(
+        name="        Attach Extra Actions to First Armature",
+        description="Export each unused action as if used by the first "\
+            "armature object",
+        default=False)
 
     Verbose = BoolProperty(
         name="Verbose",

Modified: contrib/py/scripts/addons/io_scene_x/export_x.py
===================================================================
--- contrib/py/scripts/addons/io_scene_x/export_x.py	2013-03-14 17:16:45 UTC (rev 4374)
+++ contrib/py/scripts/addons/io_scene_x/export_x.py	2013-03-14 20:41:37 UTC (rev 4375)
@@ -60,6 +60,8 @@
         self.RootExportList = [Object for Object in self.ExportMap.values()
             if Object.BlenderObject.parent not in ExportList]
         self.RootExportList = Util.SortByNameField(self.RootExportList)
+        
+        self.ExportList = Util.SortByNameField(self.ExportMap.values())
 
         # Determine each object's children from the pool of ExportObjects
         for Object in self.ExportMap.values():
@@ -69,6 +71,16 @@
                 if Child in self.ExportMap:
                     Object.Children.append(self.ExportMap[Child])
         self.Log("Done")
+        
+        if self.Config.ExportAnimation:
+            AnimationGenerators = self.__GatherAnimationGenerators()
+            
+            if self.Config.ExportActionsAsSets:
+                self.AnimationWriter = SplitSetAnimationWriter(self.Config,
+                    self, AnimationGenerators)
+            else:
+                self.AnimationWriter = JoinedSetAnimationWriter(self.Config,
+                    self, AnimationGenerators)
 
     # "Public" Interface
 
@@ -96,6 +108,9 @@
         self.Log("Closing Root frame...")
         self.__CloseRootFrame()
         self.Log("Done")
+        
+        if self.AnimationWriter is not None:
+            self.AnimationWriter.WriteAnimationSets()
 
         self.File.Close()
 
@@ -143,8 +158,81 @@
     def __CloseRootFrame(self):
         self.File.Unindent()
         self.File.Write("} // End of Root\n")
+    
+    def __GatherAnimationGenerators(self):
+        Generators = []
+        
+        if not self.Config.ExportActionsAsSets:
+            for Object in self.ExportList:
+                if Object.BlenderObject.type == 'ARMATURE':
+                    Generators.append(ArmatureAnimationGenerator(self.Config, 
+                        None, Object))
+                else:
+                    Generators.append(GenericAnimationGenerator(self.Config,
+                        None, Object))
+        else:
+            ActionlessObjects = []
+            
+            for Object in self.ExportList:
+                if Object.BlenderObject.animation_data is None:
+                    ActionlessObjects.append(Object)
+                    continue
+                else:
+                    if Object.BlenderObject.animation_data.action is None:
+                        ActionlessObjects.append(Object)
+                        continue
+                
+                if Object.BlenderObject.type == 'ARMATURE':
+                    Generators.append(ArmatureAnimationGenerator(self.Config,
+                        Util.SafeName(Object.BlenderObject.animation_data.action.name),
+                        Object))
+                else:
+                    Generators.append(GenericAnimationGenerator(self.Config,
+                        Util.SafeName(Object.BlenderObject.animation_data.action.name),
+                        Object))
+            
+            if self.Config.AttachToFirstArmature:
+                FirstArmature = None
+                for Object in self.ExportList:
+                    if Object.BlenderObject.type == 'ARMATURE':
+                        FirstArmature = Object
+                        break
+                    
+                if FirstArmature is not None:
+                    UsedActions = [BlenderObject.animation_data.action
+                        for BlenderObject in bpy.data.objects
+                        if BlenderObject.animation_data is not None]
+                    FreeActions = [Action for Action in bpy.data.actions
+                        if Action not in UsedActions]
+                    
+                    if FirstArmature in ActionlessObjects and len(FreeActions):
+                        ActionlessObjects.remove(FirstArmature)
+                    
+                    OldAction = None
+                    NoData = False
+                    if FirstArmature.BlenderObject.animation_data is not None:
+                        OldAction = FirstArmature.BlenderObject.animation_data.action
+                    else:
+                        NoData = True
+                        FirstArmature.BlenderObject.animation_data_create()
+                    
+                    for Action in FreeActions:
+                        FirstArmature.BlenderObject.animation_data.action = Action
+                        
+                        Generators.append(ArmatureAnimationGenerator(self.Config,
+                            Util.SafeName(Action.name), FirstArmature))
+                    
+                    FirstArmature.BlenderObject.animation_data.action = OldAction
+                    if NoData:
+                        FirstArmature.BlenderObject.animation_data_clear()
+            
+            if len(ActionlessObjects):
+                Generators.append(GroupAnimationGenerator(self.Config,
+                    "Default_Action", ActionlessObjects))
 
+        return Generators        
 
+
 class ExportObject:
     def __init__(self, Config, Exporter, BlenderObject):
         self.Config = Config
@@ -255,7 +343,7 @@
             MeshExportObject._MeshEnumerator.__init__(self, Mesh)
             
             self.vertices = Mesh.vertices
-            self.polygons = Mesh.polygons # Needed?
+            self.polygons = Mesh.polygons # Needed? XXX
             
             self.VertexIndexes = tuple(range(0, len(self.vertices))) # Needed?
             self.PolygonVertexIndexes = tuple(tuple(Polygon.vertices)
@@ -283,13 +371,6 @@
                     Index + len(Polygon.vertices))))
                 Index += len(Polygon.vertices)
             
-            
-            
-            
-            
-            
-            
-
     # "Private" Methods
 
     def __WriteMesh(self, Mesh):
@@ -539,7 +620,7 @@
                     self.BoneMatrix *= ArmatureObject.matrix_world.inverted()
                     self.BoneMatrix *= BlenderObject.matrix_world
                 
-                def AddVertex(self, Index, Vertex, Weight):
+                def AddVertex(self, Index, Weight):
                     self.Indexes.append(Index)
                     self.Weights.append(Weight)
         
@@ -605,7 +686,7 @@
                 self.Exporter.File.Indent()
                 self.Exporter.File.Write("\"{}\";\n".format(BoneVertexGroup.SafeName))
                 
-                GroupVertexCount = len(BoneVertexGroup.Vertices)
+                GroupVertexCount = len(BoneVertexGroup.Indexes)
                 self.Exporter.File.Write("{};\n".format(GroupVertexCount))
                 
                 # Write the indexes of the vertices this bone affects.
@@ -633,13 +714,6 @@
                 self.Exporter.File.Write("}} // End of {} skin weights\n".format(BoneVertexGroup.SafeName))
             
             
-            
-            
-                
-                
-        
-
-
 class ArmatureExportObject(ExportObject):
     def __init__(self, Config, Exporter, BlenderObject):
         ExportObject.__init__(self, Config, Exporter, BlenderObject)
@@ -704,6 +778,242 @@
         self.__WriteBones(Util.SortByNameField(Bone.children))
 
 
+class Animation:
+    def __init__(self, SafeName):
+        self.SafeName = SafeName
+        
+        self.RotationKeys = []
+        self.ScaleKeys = []
+        self.PositionKeys = []
+        
+    # "Public" Interface
+    
+    def GetKeyCount(self):
+        return len(self.RotationKeys)
+
+
+class AnimationGenerator:
+    def __init__(self, Config, SafeName, ExportObject):
+        self.Config = Config
+        self.SafeName = SafeName
+        self.ExportObject = ExportObject
+        
+        self.Animations = []
+
+
+class GenericAnimationGenerator(AnimationGenerator):
+    def __init__(self, Config, SafeName, ExportObject):
+        AnimationGenerator.__init__(self, Config, SafeName, ExportObject)
+        
+        self._GenerateKeys()
+    
+    # "Protected" Interface
+    
+    def _GenerateKeys(self):

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-extensions-cvs mailing list