Changeset View
Changeset View
Standalone View
Standalone View
tests/python/bl_alembic_import_test.py
| Show First 20 Lines • Show All 86 Lines • ▼ Show 20 Lines | def test_inherit_or_not(self): | ||||
| # ABC parent is top-level object, which translates to nothing in Blender | # ABC parent is top-level object, which translates to nothing in Blender | ||||
| self.assertIsNone(objects['locator1'].parent) | self.assertIsNone(objects['locator1'].parent) | ||||
| # ABC parent is locator1, but locator2 has "inherits Xforms" = false, which | # ABC parent is locator1, but locator2 has "inherits Xforms" = false, which | ||||
| # translates to "no parent" in Blender. | # translates to "no parent" in Blender. | ||||
| self.assertIsNone(objects['locator2'].parent) | self.assertIsNone(objects['locator2'].parent) | ||||
| depsgraph = bpy.context.evaluated_depsgraph_get() | |||||
| # Shouldn't have inherited the ABC parent's transform. | # Shouldn't have inherited the ABC parent's transform. | ||||
| loc2 = bpy.context.depsgraph.id_eval_get(objects['locator2']) | loc2 = depsgraph.id_eval_get(objects['locator2']) | ||||
| x, y, z = objects['locator2'].matrix_world.to_translation() | x, y, z = objects['locator2'].matrix_world.to_translation() | ||||
| self.assertAlmostEqual(0, x) | self.assertAlmostEqual(0, x) | ||||
| self.assertAlmostEqual(0, y) | self.assertAlmostEqual(0, y) | ||||
| self.assertAlmostEqual(2, z) | self.assertAlmostEqual(2, z) | ||||
| # ABC parent is inherited and translates to normal parent in Blender. | # ABC parent is inherited and translates to normal parent in Blender. | ||||
| self.assertEqual(objects['locator2'], objects['locatorShape2'].parent) | self.assertEqual(objects['locator2'], objects['locatorShape2'].parent) | ||||
| # Should have inherited its ABC parent's transform. | # Should have inherited its ABC parent's transform. | ||||
| locshp2 = bpy.context.depsgraph.id_eval_get(objects['locatorShape2']) | locshp2 = depsgraph.id_eval_get(objects['locatorShape2']) | ||||
| x, y, z = locshp2.matrix_world.to_translation() | x, y, z = locshp2.matrix_world.to_translation() | ||||
| self.assertAlmostEqual(0, x) | self.assertAlmostEqual(0, x) | ||||
| self.assertAlmostEqual(0, y) | self.assertAlmostEqual(0, y) | ||||
| self.assertAlmostEqual(2, z) | self.assertAlmostEqual(2, z) | ||||
| def test_select_after_import(self): | def test_select_after_import(self): | ||||
| # Add a sphere, so that there is something in the scene, selected, and active, | # Add a sphere, so that there is something in the scene, selected, and active, | ||||
| # before we do the Alembic import. | # before we do the Alembic import. | ||||
| Show All 22 Lines | def test_change_path_constraint(self): | ||||
| fname = 'cube-rotating1.abc' | fname = 'cube-rotating1.abc' | ||||
| abc = self.testdir / fname | abc = self.testdir / fname | ||||
| relpath = bpy.path.relpath(str(abc)) | relpath = bpy.path.relpath(str(abc)) | ||||
| res = bpy.ops.wm.alembic_import(filepath=str(abc), as_background_job=False) | res = bpy.ops.wm.alembic_import(filepath=str(abc), as_background_job=False) | ||||
| self.assertEqual({'FINISHED'}, res) | self.assertEqual({'FINISHED'}, res) | ||||
| cube = bpy.context.active_object | cube = bpy.context.active_object | ||||
| depsgraph = bpy.context.evaluated_depsgraph_get() | |||||
| # Check that the file loaded ok. | # Check that the file loaded ok. | ||||
| bpy.context.scene.frame_set(10) | bpy.context.scene.frame_set(10) | ||||
| cube = bpy.context.depsgraph.id_eval_get(cube) | cube = depsgraph.id_eval_get(cube) | ||||
| x, y, z = cube.matrix_world.to_euler('XYZ') | x, y, z = cube.matrix_world.to_euler('XYZ') | ||||
| self.assertAlmostEqual(x, 0) | self.assertAlmostEqual(x, 0) | ||||
| self.assertAlmostEqual(y, 0) | self.assertAlmostEqual(y, 0) | ||||
| self.assertAlmostEqual(z, math.pi / 2, places=5) | self.assertAlmostEqual(z, math.pi / 2, places=5) | ||||
| # Change path from absolute to relative. This should not break the animation. | # Change path from absolute to relative. This should not break the animation. | ||||
| bpy.context.scene.frame_set(1) | bpy.context.scene.frame_set(1) | ||||
| bpy.data.cache_files[fname].filepath = relpath | bpy.data.cache_files[fname].filepath = relpath | ||||
| bpy.context.scene.frame_set(10) | bpy.context.scene.frame_set(10) | ||||
| cube = bpy.context.depsgraph.id_eval_get(cube) | cube = depsgraph.id_eval_get(cube) | ||||
| x, y, z = cube.matrix_world.to_euler('XYZ') | x, y, z = cube.matrix_world.to_euler('XYZ') | ||||
| self.assertAlmostEqual(x, 0) | self.assertAlmostEqual(x, 0) | ||||
| self.assertAlmostEqual(y, 0) | self.assertAlmostEqual(y, 0) | ||||
| self.assertAlmostEqual(z, math.pi / 2, places=5) | self.assertAlmostEqual(z, math.pi / 2, places=5) | ||||
| # Replace the Alembic file; this should apply new animation. | # Replace the Alembic file; this should apply new animation. | ||||
| bpy.data.cache_files[fname].filepath = relpath.replace('1.abc', '2.abc') | bpy.data.cache_files[fname].filepath = relpath.replace('1.abc', '2.abc') | ||||
| bpy.context.scene.update() | depsgraph.update() | ||||
| cube = bpy.context.depsgraph.id_eval_get(cube) | cube = depsgraph.id_eval_get(cube) | ||||
| x, y, z = cube.matrix_world.to_euler('XYZ') | x, y, z = cube.matrix_world.to_euler('XYZ') | ||||
| self.assertAlmostEqual(x, math.pi / 2, places=5) | self.assertAlmostEqual(x, math.pi / 2, places=5) | ||||
| self.assertAlmostEqual(y, 0) | self.assertAlmostEqual(y, 0) | ||||
| self.assertAlmostEqual(z, 0) | self.assertAlmostEqual(z, 0) | ||||
| def test_change_path_modifier(self): | def test_change_path_modifier(self): | ||||
| fname = 'animated-mesh.abc' | fname = 'animated-mesh.abc' | ||||
| abc = self.testdir / fname | abc = self.testdir / fname | ||||
| relpath = bpy.path.relpath(str(abc)) | relpath = bpy.path.relpath(str(abc)) | ||||
| res = bpy.ops.wm.alembic_import(filepath=str(abc), as_background_job=False) | res = bpy.ops.wm.alembic_import(filepath=str(abc), as_background_job=False) | ||||
| self.assertEqual({'FINISHED'}, res) | self.assertEqual({'FINISHED'}, res) | ||||
| plane = bpy.context.active_object | plane = bpy.context.active_object | ||||
| depsgraph = bpy.context.evaluated_depsgraph_get() | |||||
| # Check that the file loaded ok. | # Check that the file loaded ok. | ||||
| bpy.context.scene.frame_set(6) | bpy.context.scene.frame_set(6) | ||||
| scene = bpy.context.scene | scene = bpy.context.scene | ||||
| mesh = plane.to_mesh(bpy.context.depsgraph, apply_modifiers=True, calc_undeformed=False) | plane_eval = plane.evaluated_get(depsgraph) | ||||
| mesh = plane_eval.to_mesh() | |||||
| self.assertAlmostEqual(-1, mesh.vertices[0].co.x) | self.assertAlmostEqual(-1, mesh.vertices[0].co.x) | ||||
| self.assertAlmostEqual(-1, mesh.vertices[0].co.y) | self.assertAlmostEqual(-1, mesh.vertices[0].co.y) | ||||
| self.assertAlmostEqual(0.5905638933181763, mesh.vertices[0].co.z) | self.assertAlmostEqual(0.5905638933181763, mesh.vertices[0].co.z) | ||||
| # Change path from absolute to relative. This should not break the animation. | # Change path from absolute to relative. This should not break the animation. | ||||
| scene.frame_set(1) | scene.frame_set(1) | ||||
| bpy.data.cache_files[fname].filepath = relpath | bpy.data.cache_files[fname].filepath = relpath | ||||
| scene.frame_set(6) | scene.frame_set(6) | ||||
| mesh = plane.to_mesh(bpy.context.depsgraph, apply_modifiers=True, calc_undeformed=False) | plane_eval = plane.evaluated_get(depsgraph) | ||||
| mesh = plane_eval.to_mesh() | |||||
| self.assertAlmostEqual(1, mesh.vertices[3].co.x) | self.assertAlmostEqual(1, mesh.vertices[3].co.x) | ||||
| self.assertAlmostEqual(1, mesh.vertices[3].co.y) | self.assertAlmostEqual(1, mesh.vertices[3].co.y) | ||||
| self.assertAlmostEqual(0.5905638933181763, mesh.vertices[3].co.z) | self.assertAlmostEqual(0.5905638933181763, mesh.vertices[3].co.z) | ||||
| def test_import_long_names(self): | def test_import_long_names(self): | ||||
| # This file contains very long names. The longest name is 4047 chars. | # This file contains very long names. The longest name is 4047 chars. | ||||
| bpy.ops.wm.alembic_import( | bpy.ops.wm.alembic_import( | ||||
| filepath=str(self.testdir / "long-names.abc"), | filepath=str(self.testdir / "long-names.abc"), | ||||
| ▲ Show 20 Lines • Show All 64 Lines • Show Last 20 Lines | |||||