Spaces:
Running on Zero
Running on Zero
| import tempfile | |
| import unittest | |
| from pathlib import Path | |
| import numpy as np | |
| from ardy.exports.bvh import write_bvh | |
| class BvhExportTests(unittest.TestCase): | |
| def test_writes_blender_readable_hierarchy_and_motion(self): | |
| rotations = np.repeat(np.eye(3)[None, None], 4, axis=0) | |
| rotations = np.repeat(rotations, 2, axis=1) | |
| roots = np.array( | |
| [ | |
| [0.0, 0.0, 0.0], | |
| [0.1, 0.0, 0.0], | |
| [0.2, 0.0, 0.0], | |
| [0.3, 0.0, 0.0], | |
| ] | |
| ) | |
| with tempfile.TemporaryDirectory() as folder: | |
| output = Path(folder) / "motion.bvh" | |
| write_bvh( | |
| output, | |
| joint_names=["Hips", "Spine"], | |
| parents=[-1, 0], | |
| rest_positions=np.array([[0.0, 0.0, 0.0], [0.0, 0.5, 0.0]]), | |
| local_rot_mats=rotations, | |
| root_positions=roots, | |
| fps=20, | |
| ) | |
| text = output.read_text(encoding="utf-8") | |
| self.assertIn("ROOT Hips", text) | |
| self.assertIn("JOINT Spine", text) | |
| self.assertIn("Frames: 4", text) | |
| self.assertIn("Frame Time: 0.050000000", text) | |
| motion_lines = text.split("Frame Time: 0.050000000\n", 1)[1].strip().splitlines() | |
| self.assertEqual(len(motion_lines), 4) | |
| self.assertTrue(motion_lines[-1].startswith("0.3000000 0.0000000 0.0000000")) | |
| if __name__ == "__main__": | |
| unittest.main() | |