forked from bartvdbraak/blender
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")
This commit is contained in:
parent
e6d1f25842
commit
dacdfbe6f3
@ -110,6 +110,13 @@ def display_name(name):
|
|||||||
return name_base
|
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):
|
def resolve_ncase(path):
|
||||||
"""
|
"""
|
||||||
Resolve a case insensitive path on a case sensitive system,
|
Resolve a case insensitive path on a case sensitive system,
|
||||||
|
@ -274,18 +274,18 @@ def read_bvh(context, file_path, rotate_mode='XYZ', global_scale=1.0):
|
|||||||
return bvh_nodes
|
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:
|
if frame_start < 1:
|
||||||
IMPORT_START_FRAME = 1
|
frame_start = 1
|
||||||
|
|
||||||
scn = context.scene
|
scene = context.scene
|
||||||
scn.objects.selected = []
|
scene.objects.selected = []
|
||||||
|
|
||||||
objects = []
|
objects = []
|
||||||
|
|
||||||
def add_ob(name):
|
def add_ob(name):
|
||||||
ob = scn.objects.new('Empty', None)
|
ob = scene.objects.new('Empty', None)
|
||||||
objects.append(ob)
|
objects.append(ob)
|
||||||
return ob
|
return ob
|
||||||
|
|
||||||
@ -312,7 +312,7 @@ def bvh_node_dict2objects(context, bvh_nodes, IMPORT_START_FRAME=1, IMPORT_LOOP=
|
|||||||
|
|
||||||
# Animate the data, the last used bvh_node will do since they all have the same number of frames
|
# 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)):
|
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():
|
for bvh_node in bvh_nodes.values():
|
||||||
lx, ly, lz, rx, ry, rz = bvh_node.anim_data[frame_current]
|
lx, ly, lz, rx, ry, rz = bvh_node.anim_data[frame_current]
|
||||||
@ -324,30 +324,27 @@ def bvh_node_dict2objects(context, bvh_nodes, IMPORT_START_FRAME=1, IMPORT_LOOP=
|
|||||||
|
|
||||||
bvh_node.temp.insertIpoKey(Blender.Object.IpoKeyTypes.LOCROT) # XXX invalid
|
bvh_node.temp.insertIpoKey(Blender.Object.IpoKeyTypes.LOCROT) # XXX invalid
|
||||||
|
|
||||||
scn.update(1)
|
scene.update(1)
|
||||||
return objects
|
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:
|
if frame_start < 1:
|
||||||
IMPORT_START_FRAME = 1
|
frame_start = 1
|
||||||
|
|
||||||
# Add the new armature,
|
# Add the new armature,
|
||||||
scn = context.scene
|
scene = context.scene
|
||||||
#XXX scn.objects.selected = []
|
for obj in scene.objects:
|
||||||
for ob in scn.objects:
|
obj.select = False
|
||||||
ob.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")
|
scene.objects.link(arm_ob)
|
||||||
arm_ob = bpy.data.objects.new("MyBVH", arm_data)
|
|
||||||
|
|
||||||
scn.objects.link(arm_ob)
|
|
||||||
|
|
||||||
arm_ob.select = True
|
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='OBJECT', toggle=False)
|
||||||
bpy.ops.object.mode_set(mode='EDIT', toggle=False)
|
bpy.ops.object.mode_set(mode='EDIT', toggle=False)
|
||||||
@ -413,13 +410,10 @@ def bvh_node_dict2armature(context, bvh_nodes, rotate_mode='XYZ', IMPORT_START_F
|
|||||||
for bvh_node in bvh_nodes.values():
|
for bvh_node in bvh_nodes.values():
|
||||||
bvh_node.temp = bvh_node.temp.name
|
bvh_node.temp = bvh_node.temp.name
|
||||||
|
|
||||||
#XXX arm_data.update()
|
|
||||||
|
|
||||||
# Now Apply the animation to the armature
|
# Now Apply the animation to the armature
|
||||||
|
|
||||||
# Get armature animation data
|
# Get armature animation data
|
||||||
bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
|
bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
|
||||||
bpy.ops.object.mode_set(mode='POSE', toggle=False)
|
|
||||||
|
|
||||||
pose = arm_ob.pose
|
pose = arm_ob.pose
|
||||||
pose_bones = pose.bones
|
pose_bones = pose.bones
|
||||||
@ -439,18 +433,9 @@ def bvh_node_dict2armature(context, bvh_nodes, rotate_mode='XYZ', IMPORT_START_F
|
|||||||
|
|
||||||
context.scene.update()
|
context.scene.update()
|
||||||
|
|
||||||
bpy.ops.pose.select_all() # set
|
arm_ob.animation_data_create()
|
||||||
bpy.ops.anim.keyframe_insert_menu(type=-4) # XXX - -4 ???
|
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)
|
# Replace the bvh_node.temp (currently an editbone)
|
||||||
# With a tuple (pose_bone, armature_bone, bone_rest_matrix, bone_rest_matrix_inv)
|
# With a tuple (pose_bone, armature_bone, bone_rest_matrix, bone_rest_matrix_inv)
|
||||||
@ -484,6 +469,8 @@ def bvh_node_dict2armature(context, bvh_nodes, rotate_mode='XYZ', IMPORT_START_F
|
|||||||
# if frame_current==40: # debugging
|
# if frame_current==40: # debugging
|
||||||
# break
|
# break
|
||||||
|
|
||||||
|
scene.frame_set(frame_start + frame_current)
|
||||||
|
|
||||||
# Dont neet to set the current frame
|
# Dont neet to set the current frame
|
||||||
for i, bvh_node in enumerate(bvh_nodes.values()):
|
for i, bvh_node in enumerate(bvh_nodes.values()):
|
||||||
pose_bone, bone, bone_rest_matrix, bone_rest_matrix_inv = bvh_node.temp
|
pose_bone, bone, bone_rest_matrix, bone_rest_matrix_inv = bvh_node.temp
|
||||||
@ -511,10 +498,6 @@ def bvh_node_dict2armature(context, bvh_nodes, rotate_mode='XYZ', IMPORT_START_F
|
|||||||
else:
|
else:
|
||||||
pose_bone.keyframe_insert("rotation_euler")
|
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:
|
for cu in action.fcurves:
|
||||||
if IMPORT_LOOP:
|
if IMPORT_LOOP:
|
||||||
pass # 2.5 doenst have cyclic now?
|
pass # 2.5 doenst have cyclic now?
|
||||||
@ -535,14 +518,21 @@ def load(operator, context, filepath="", rotate_mode='NATIVE', global_scale=1.0,
|
|||||||
global_scale=global_scale)
|
global_scale=global_scale)
|
||||||
|
|
||||||
print('%.4f' % (time.time() - t1))
|
print('%.4f' % (time.time() - t1))
|
||||||
|
|
||||||
|
frame_orig = context.scene.frame_current
|
||||||
|
|
||||||
t1 = time.time()
|
t1 = time.time()
|
||||||
print('\timporting to blender...', end="")
|
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,
|
rotate_mode=rotate_mode,
|
||||||
IMPORT_START_FRAME=frame_start,
|
frame_start=frame_start,
|
||||||
IMPORT_LOOP=use_cyclic)
|
IMPORT_LOOP=use_cyclic)
|
||||||
|
|
||||||
print('Done in %.4f\n' % (time.time() - t1))
|
print('Done in %.4f\n' % (time.time() - t1))
|
||||||
|
|
||||||
|
context.scene.frame_set(frame_orig)
|
||||||
|
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
Loading…
Reference in New Issue
Block a user