[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [34028] trunk/blender/release/scripts: recent change to keyframe menu broke BVH import, now don' t use the operator at all, instead assign the action manually.

Campbell Barton ideasman42 at gmail.com
Mon Jan 3 09:28:23 CET 2011


Revision: 34028
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=34028
Author:   campbellbarton
Date:     2011-01-03 09:28:22 +0100 (Mon, 03 Jan 2011)

Log Message:
-----------
recent change to keyframe menu broke BVH import, now don't use the operator at all, instead assign the action manually.

Also added bpy.path.display_name_from_filepath(), since filepaths are not ensured to be utf8.
same as calling:  os.path.splitext(os.path.basename(name))[0].encode("utf8", "replace").decode("utf8")

Modified Paths:
--------------
    trunk/blender/release/scripts/modules/bpy/path.py
    trunk/blender/release/scripts/op/io_anim_bvh/import_bvh.py

Modified: trunk/blender/release/scripts/modules/bpy/path.py
===================================================================
--- trunk/blender/release/scripts/modules/bpy/path.py	2011-01-03 07:51:22 UTC (rev 34027)
+++ trunk/blender/release/scripts/modules/bpy/path.py	2011-01-03 08:28:22 UTC (rev 34028)
@@ -110,6 +110,13 @@
         return name_base
 
 
+def display_name_from_filepath(name):
+    """
+    Returns the path stripped of directort and extension, ensured to be utf8 compatible.
+    """
+    return _os.path.splitext(_os.path.basename(name))[0].encode("utf8", "replace").decode("utf8")
+
+
 def resolve_ncase(path):
     """
     Resolve a case insensitive path on a case sensitive system,

Modified: trunk/blender/release/scripts/op/io_anim_bvh/import_bvh.py
===================================================================
--- trunk/blender/release/scripts/op/io_anim_bvh/import_bvh.py	2011-01-03 07:51:22 UTC (rev 34027)
+++ trunk/blender/release/scripts/op/io_anim_bvh/import_bvh.py	2011-01-03 08:28:22 UTC (rev 34028)
@@ -274,18 +274,18 @@
     return bvh_nodes
 
 
-def bvh_node_dict2objects(context, bvh_nodes, IMPORT_START_FRAME=1, IMPORT_LOOP=False):
+def bvh_node_dict2objects(context, bvh_nodes, frame_start=1, IMPORT_LOOP=False):
 
-    if IMPORT_START_FRAME < 1:
-        IMPORT_START_FRAME = 1
+    if frame_start < 1:
+        frame_start = 1
 
-    scn = context.scene
-    scn.objects.selected = []
+    scene = context.scene
+    scene.objects.selected = []
 
     objects = []
 
     def add_ob(name):
-        ob = scn.objects.new('Empty', None)
+        ob = scene.objects.new('Empty', None)
         objects.append(ob)
         return ob
 
@@ -312,7 +312,7 @@
 
     # Animate the data, the last used bvh_node will do since they all have the same number of frames
     for frame_current in range(len(bvh_node.anim_data)):
-        Blender.Set('curframe', frame_current + IMPORT_START_FRAME)
+        Blender.Set('curframe', frame_current + frame_start)
 
         for bvh_node in bvh_nodes.values():
             lx, ly, lz, rx, ry, rz = bvh_node.anim_data[frame_current]
@@ -324,30 +324,27 @@
 
             bvh_node.temp.insertIpoKey(Blender.Object.IpoKeyTypes.LOCROT)  # XXX invalid
 
-    scn.update(1)
+    scene.update(1)
     return objects
 
 
-def bvh_node_dict2armature(context, bvh_nodes, rotate_mode='XYZ', IMPORT_START_FRAME=1, IMPORT_LOOP=False):
+def bvh_node_dict2armature(context, bvh_name, bvh_nodes, rotate_mode='XYZ', frame_start=1, IMPORT_LOOP=False):
 
-    if IMPORT_START_FRAME < 1:
-        IMPORT_START_FRAME = 1
+    if frame_start < 1:
+        frame_start = 1
 
     # Add the new armature,
-    scn = context.scene
-#XXX	scn.objects.selected = []
-    for ob in scn.objects:
-        ob.select = False
+    scene = context.scene
+    for obj in scene.objects:
+        obj.select = False
 
-    scn.frame_set(IMPORT_START_FRAME)
+    arm_data = bpy.data.armatures.new(bvh_name)
+    arm_ob = bpy.data.objects.new(bvh_name, arm_data)
 
-    arm_data = bpy.data.armatures.new("MyBVH")
-    arm_ob = bpy.data.objects.new("MyBVH", arm_data)
+    scene.objects.link(arm_ob)
 
-    scn.objects.link(arm_ob)
-
     arm_ob.select = True
-    scn.objects.active = arm_ob
+    scene.objects.active = arm_ob
 
     bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
     bpy.ops.object.mode_set(mode='EDIT', toggle=False)
@@ -413,13 +410,10 @@
     for bvh_node in bvh_nodes.values():
         bvh_node.temp = bvh_node.temp.name
 
-#XXX	arm_data.update()
-
     # Now Apply the animation to the armature
 
     # Get armature animation data
     bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
-    bpy.ops.object.mode_set(mode='POSE', toggle=False)
 
     pose = arm_ob.pose
     pose_bones = pose.bones
@@ -439,19 +433,10 @@
 
     context.scene.update()
 
-    bpy.ops.pose.select_all()  # set
-    bpy.ops.anim.keyframe_insert_menu(type=-4)  # XXX -     -4 ???
+    arm_ob.animation_data_create()
+    action = bpy.data.actions.new(name=bvh_name)
+    arm_ob.animation_data.action = action
 
-
-#XXX	action = Blender.Armature.NLA.NewAction("Action")
-#XXX	action.setActive(arm_ob)
-
-    #bpy.ops.action.new()
-    #action = bpy.data.actions[-1]
-
-    # arm_ob.animation_data.action = action
-    action = arm_ob.animation_data.action
-
     # Replace the bvh_node.temp (currently an editbone)
     # With a tuple  (pose_bone, armature_bone, bone_rest_matrix, bone_rest_matrix_inv)
     for bvh_node in bvh_nodes.values():
@@ -484,6 +469,8 @@
         # if frame_current==40: # debugging
         # 	break
 
+        scene.frame_set(frame_start + frame_current)
+
         # Dont neet to set the current frame
         for i, bvh_node in enumerate(bvh_nodes.values()):
             pose_bone, bone, bone_rest_matrix, bone_rest_matrix_inv = bvh_node.temp
@@ -511,10 +498,6 @@
                 else:
                     pose_bone.keyframe_insert("rotation_euler")
 
-
-        # bpy.ops.anim.keyframe_insert_menu(type=-4) # XXX -     -4 ???
-        bpy.ops.screen.frame_offset(delta=1)
-
     for cu in action.fcurves:
         if IMPORT_LOOP:
             pass  # 2.5 doenst have cyclic now?
@@ -535,14 +518,21 @@
             global_scale=global_scale)
 
     print('%.4f' % (time.time() - t1))
+    
+    frame_orig = context.scene.frame_current
+    
     t1 = time.time()
     print('\timporting to blender...', end="")
+    
+    bvh_name = bpy.path.display_name_from_filepath(filepath)
 
-    bvh_node_dict2armature(context, bvh_nodes,
+    bvh_node_dict2armature(context, bvh_name, bvh_nodes,
             rotate_mode=rotate_mode,
-            IMPORT_START_FRAME=frame_start,
+            frame_start=frame_start,
             IMPORT_LOOP=use_cyclic)
 
     print('Done in %.4f\n' % (time.time() - t1))
+    
+    context.scene.frame_set(frame_orig)
 
     return {'FINISHED'}





More information about the Bf-blender-cvs mailing list