-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathdae_fbx_to_bvh.py
65 lines (48 loc) · 1.79 KB
/
dae_fbx_to_bvh.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import bpy
import os
def export_bvh(file):
bpy.ops.object.select_all(action='TOGGLE')
obj = scene.objects.get(bpy.data.armatures[0].name)
if obj != None:
obj.select = True
scene.objects.active = obj
#cont = bpy.context.area.type
#print(str(cont))
frame_start = 1
frame_end = 100
if bpy.data.actions:
# get all actions
action_list = [action.frame_range for action in bpy.data.actions]
frame_end = action_list[-1][-1]
bpy.ops.export_anim.bvh(filepath=directory + '\\' +
file[:-4] + '.bvh', frame_start=frame_start, frame_end=frame_end)
bpy.ops.object.select_all(action='TOGGLE')
bpy.ops.object.select_all(action='TOGGLE')
bpy.ops.object.delete(use_global=False)
print('Exported:'+file)
scene = bpy.context.scene
filepath = bpy.data.filepath
directory = os.path.dirname(filepath)
for obj in bpy.context.scene.objects:
if obj.type == 'ARMATURE':
obj.select = True
else:
obj.select = False
bpy.ops.object.delete()
for block in bpy.data.armatures:
if block.users == 0:
bpy.data.armatures.remove(block)
for block in bpy.data.actions:
if block.users == 0:
bpy.data.actions.remove(block)
for file in os.listdir(directory):
if file.endswith('.dae'):
bpy.ops.wm.collada_import(filepath=directory+'\\' + file,
fix_orientation=True,
find_chains=True)
export_bvh(file)
elif file.endswith('.fbx'):
bpy.ops.import_scene.fbx(filepath=directory+'\\' + file,
automatic_bone_orientation=True,
ignore_leaf_bones=True)
export_bvh(file)