Skip to content

Commit 2eb9e68

Browse files
author
Saeki-M
committed
added export of bvh
1 parent 3860766 commit 2eb9e68

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

bvh.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import re
2+
import copy
23

34

45
class BvhNode:
@@ -75,6 +76,20 @@ def tokenize(self):
7576
node_stack[-1].add_child(node)
7677
if item[0] == 'Frame' and item[1] == 'Time:':
7778
frame_time_found = True
79+
80+
def __getitem__(self, x):
81+
if type(x) is int:
82+
frames = self.frames[[round(x/(1000*self.frame_time))]]
83+
elif type(x) is slice:
84+
start_frame = round(x.start/(1000*self.frame_time))
85+
end_frame = round(x.stop/(1000*self.frame_time))
86+
frames = self.frames[start_frame:end_frame:x.step]
87+
else:
88+
raise KeyError
89+
90+
new_bvh = copy.deepcopy(self)
91+
new_bvh.frames = frames
92+
return new_bvh
7893

7994
def search(self, *items):
8095
found_nodes = []
@@ -247,6 +262,7 @@ def write_node(self, node, data, depth):
247262
depth -= 1
248263
return data, depth
249264

250-
def save(self, save_path):
251-
with open(save_path, 'w') as f:
252-
f.write(self.raw_data)
265+
def save(self, out_f):
266+
with open(out_f, 'w') as f:
267+
f.write(self.raw_data)
268+

0 commit comments

Comments
 (0)