Changeset View
Changeset View
Standalone View
Standalone View
tests/python/alembic_export_tests.py
| Show First 20 Lines • Show All 105 Lines • ▼ Show 20 Lines | def abcprop(self, filepath: pathlib.Path, proppath: str) -> dict: | ||||
| 'bool_t': int, | 'bool_t': int, | ||||
| 'uint8_t': int, | 'uint8_t': int, | ||||
| 'int16_t': int, | 'int16_t': int, | ||||
| 'int32_t': int, | 'int32_t': int, | ||||
| 'uint32_t': int, | 'uint32_t': int, | ||||
| 'uint64_t': int, | 'uint64_t': int, | ||||
| 'float64_t': float, | 'float64_t': float, | ||||
| 'float32_t': float, | 'float32_t': float, | ||||
| 'string': str, | |||||
| } | } | ||||
| result = {} | result = {} | ||||
| # Ideally we'd get abcls to output JSON, see https://github.com/alembic/alembic/issues/121 | # Ideally we'd get abcls to output JSON, see https://github.com/alembic/alembic/issues/121 | ||||
| lines = collections.deque(output.split('\n')) | lines = collections.deque(output.split('\n')) | ||||
| while lines: | while lines: | ||||
| info = lines.popleft() | info = lines.popleft() | ||||
| ▲ Show 20 Lines • Show All 459 Lines • ▼ Show 20 Lines | def test_hierarchical_export(self, tempdir: pathlib.Path): | ||||
| # depsgraph by the standard builder, only by the all-objects builder. | # depsgraph by the standard builder, only by the all-objects builder. | ||||
| test('InvisibleCube', False) | test('InvisibleCube', False) | ||||
| # This cube has animated visibility, and thus will be pulled into the | # This cube has animated visibility, and thus will be pulled into the | ||||
| # depsgraph by the standard builder as well as the all-objects builder. | # depsgraph by the standard builder as well as the all-objects builder. | ||||
| test('InvisibleAnimatedCube', False) | test('InvisibleAnimatedCube', False) | ||||
| class CustomPropertiesExportTest(AbstractAlembicTest): | |||||
| """Test export of custom properties.""" | |||||
| def _run_export(self, tempdir: pathlib.Path) -> pathlib.Path: | |||||
| abc = tempdir / 'custom-properties.abc' | |||||
| script = "import bpy; bpy.context.scene.frame_set(1); bpy.ops.wm.alembic_export(filepath='%s', start=1, end=1)" % abc.as_posix() | |||||
| self.run_blender('custom-properties.blend', script) | |||||
| return abc | |||||
| @with_tempdir | |||||
| def test_xform_props(self, tempdir: pathlib.Path) -> None: | |||||
| abc = self._run_export(tempdir) | |||||
| abcprop = self.abcprop(abc, '/Cube/.xform/.userProperties') | |||||
| # Simple, single values. | |||||
| self.assertEqual(abcprop['static_int'], [327]) | |||||
| self.assertEqual(abcprop['static_float'], [47.01]) | |||||
| self.assertEqual(abcprop['static_string'], ['Agents']) | |||||
| self.assertEqual(abcprop['keyed_float'], [-1]) | |||||
| self.assertEqual(abcprop['keyed_int'], [-47]) | |||||
| # Arrays. | |||||
| self.assertEqual(abcprop['keyed_array_float'], [-1.000, 0.000, 1.000]) | |||||
| self.assertEqual(abcprop['keyed_array_int'], [42, 47, 327]) | |||||
| # Multi-dimensional arrays. | |||||
| self.assertEqual(abcprop['array_of_strings'], ['ผัดไทย', 'Pad Thai']) | |||||
| self.assertEqual( | |||||
| abcprop['matrix_tuple'], | |||||
| [1.0, 0.0, 0.0, 3.33333, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0]) | |||||
| self.assertEqual( | |||||
| abcprop['static_matrix'], | |||||
| [1.0, 0.0, 0.0, 3.33333, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0]) | |||||
| self.assertEqual( | |||||
| abcprop['nonuniform_array'], | |||||
| [10, 20, 30, 1, 2, 47]) | |||||
| @with_tempdir | |||||
| def test_mesh_props(self, tempdir: pathlib.Path) -> None: | |||||
| abc = self._run_export(tempdir) | |||||
| abcprop = self.abcprop(abc, '/Cube/Cube/.geom/.userProperties') | |||||
| self.assertEqual(abcprop['mesh_tags'], ['cube', 'box', 'low-poly-sphere']) | |||||
| @with_tempdir | |||||
| def test_camera_props(self, tempdir: pathlib.Path) -> None: | |||||
| abc = self._run_export(tempdir) | |||||
| abcprop = self.abcprop(abc, '/Camera/Hasselblad/.geom/.userProperties') | |||||
| self.assertEqual(abcprop['type'], ['500c/m']) | |||||
| @with_tempdir | |||||
| def test_disabled_export_option(self, tempdir: pathlib.Path) -> None: | |||||
| abc = tempdir / 'custom-properties.abc' | |||||
| script = ( | |||||
| "import bpy; bpy.context.scene.frame_set(1); " | |||||
| "bpy.ops.wm.alembic_export(filepath='%s', start=1, end=1, export_custom_properties=False)" % abc.as_posix() | |||||
| ) | |||||
| self.run_blender('custom-properties.blend', script) | |||||
| abcprop = self.abcprop(abc, '/Camera/Hasselblad/.geom/.userProperties') | |||||
| self.assertIn('eyeSeparation', abcprop, 'Regular non-standard properties should still be written') | |||||
| self.assertNotIn('type', abcprop, 'Custom properties should not be written') | |||||
| if __name__ == '__main__': | if __name__ == '__main__': | ||||
| parser = argparse.ArgumentParser() | parser = argparse.ArgumentParser() | ||||
| parser.add_argument('--blender', required=True) | parser.add_argument('--blender', required=True) | ||||
| parser.add_argument('--testdir', required=True) | parser.add_argument('--testdir', required=True) | ||||
| parser.add_argument('--alembic-root', required=True) | parser.add_argument('--alembic-root', required=True) | ||||
| args, remaining = parser.parse_known_args() | args, remaining = parser.parse_known_args() | ||||
| unittest.main(argv=sys.argv[0:1] + remaining) | unittest.main(argv=sys.argv[0:1] + remaining) | ||||