Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 7 additions & 14 deletions bvh.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,12 @@ def __init__(self, data):
self.tokenize()

def tokenize(self):
first_round = []
accumulator = ''
for char in self.data:
if char not in ('\n', '\r'):
accumulator += char
elif accumulator:
first_round.append(re.split('\\s+', accumulator.strip()))
accumulator = ''
lines = re.split('\n|\r', self.data)
first_round = [re.split('\\s+', line.strip()) for line in lines[:-1]]
node_stack = [self.root]
frame_time_found = False
node = None
for item in first_round:
if frame_time_found:
self.frames.append(item)
continue
data_start_idx = 0
for line, item in enumerate(first_round):
key = item[0]
if key == '{':
node_stack.append(node)
Expand All @@ -74,7 +65,9 @@ def tokenize(self):
node = BvhNode(item)
node_stack[-1].add_child(node)
if item[0] == 'Frame' and item[1] == 'Time:':
frame_time_found = True
data_start_idx = line
break
self.frames = [[float(scalar) for scalar in line] for line in first_round[data_start_idx+1:]]

def search(self, *items):
found_nodes = []
Expand Down