Skip to content

Commit 3860766

Browse files
author
Saeki-M
committed
added write function
1 parent b7e0058 commit 3860766

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

bvh.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,3 +215,38 @@ def frame_time(self):
215215
return float(next(self.root.filter('Frame')).value[2])
216216
except StopIteration:
217217
raise LookupError('frame time not found')
218+
219+
@property
220+
def raw_data(self):
221+
_, root, _, _, _ = self.root
222+
data = "HIERARCHY\n"
223+
224+
data, depth = self.write_node(root, data, 0)
225+
226+
data += "MOTION\n"
227+
data += f"Frames:\t{self.nframes}\n"
228+
data += f"Frame Time:\t{self.frame_time}\n"
229+
230+
for frame in self.frames:
231+
data += "\t".join(frame)+"\n"
232+
233+
return data
234+
235+
def write_node(self, node, data, depth):
236+
n_type = node.value[0]
237+
238+
data += "\t"*depth + "\t".join(node.value) + "\n"
239+
data += "\t"*depth + "{\n"
240+
data += "\t"*(depth+1) + "\t".join(node.children[0].value) + "\n"
241+
if n_type != 'End':
242+
data += "\t"*(depth+1) + "\t".join(node.children[1].value) + "\n"
243+
for child in node.children[2:]:
244+
depth += 1
245+
data, depth = self.write_node(child, data, depth)
246+
data += "\t"*depth + "}\n"
247+
depth -= 1
248+
return data, depth
249+
250+
def save(self, save_path):
251+
with open(save_path, 'w') as f:
252+
f.write(self.raw_data)

0 commit comments

Comments
 (0)