-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcsv_to_bvh.py
40 lines (28 loc) · 1.19 KB
/
csv_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
import csv
import os
import bpy
objects = bpy.context.scene.objects
empties = []
for object in objects:
if object.type == 'EMPTY':
empties.append(object)
print(empties)
with open("hmr.csv", 'r', newline='') as csvfile:
ofile = csv.reader(csvfile, delimiter=',')
next(ofile) # <-- skip the x,y,z header
for line in ofile:
f, *pts = line
for fnum in range(5):
fpts = [float(p) for p in pts]
coordinates = [fpts[0:3], fpts[3:6], fpts[6:9], fpts[9:12],
fpts[12:15], fpts[15:18], fpts[18:21], fpts[21:24],
fpts[24:27], fpts[27:30], fpts[30:33], fpts[33:36],
fpts[36:39], fpts[39:42],fpts[42:45], fpts[45:48],
fpts[48:51], fpts[51:54], fpts[54:57], fpts[57:60]]
bpy.context.scene.frame_set(fnum)
bpy.data.scenes['Scene'].frame_end = fnum + 1
for ob, position in zip(empties, coordinates):
ob.location = position
ob.keyframe_insert(data_path="location", index=-1)
target_file = 'result.bvh'
bpy.ops.export_anim.bvh(filepath=target_file)