Alembic import: changing cache modifier path no longer discards object paths
authorSybren A. Stüvel <sybren@stuvel.eu>
Fri, 21 Apr 2017 12:11:13 +0000 (14:11 +0200)
committerSybren A. Stüvel <sybren@stuvel.eu>
Fri, 21 Apr 2017 12:11:49 +0000 (14:11 +0200)
This allows, for example, the path of an Alembic file to be changed from
absolute to relative, without having to reconstruct all object paths.

source/blender/blenkernel/intern/cachefile.c
tests/python/bl_alembic_import_test.py

index ff0a776aa82c614285585b240835895831b5a8ed..67c66d4e40bdc2567d5292525de1b0bf6160da12 100644 (file)
@@ -221,7 +221,6 @@ void BKE_cachefile_clean(Scene *scene, CacheFile *cache_file)
                                }
 #endif
                                mcmd->reader = NULL;
-                               mcmd->object_path[0] = '\0';
                        }
                }
 
@@ -239,7 +238,6 @@ void BKE_cachefile_clean(Scene *scene, CacheFile *cache_file)
                                }
 #endif
                                data->reader = NULL;
-                               data->object_path[0] = '\0';
                        }
                }
        }
index cd23183ec0677d8d2d4489106cea44041e5a4f82..33ccc49f301fbfa639a8d2e0d66579d1f31cf762 100644 (file)
@@ -85,6 +85,43 @@ class SimpleImportTest(unittest.TestCase):
         for ob in bpy.data.objects:
             self.assertEqual('Cube' in ob.name, ob.select)
 
+    def test_change_path(self):
+        import math
+
+        fname = 'cube-rotating1.abc'
+        abc = self.testdir / fname
+        relpath = bpy.path.relpath(str(abc))
+
+        res = bpy.ops.wm.alembic_import(filepath=str(abc), as_background_job=False)
+        self.assertEqual({'FINISHED'}, res)
+        cube = bpy.context.active_object
+
+        # Check that the file loaded ok.
+        bpy.context.scene.frame_set(10)
+        x, y, z = cube.matrix_world.to_euler('XYZ')
+        self.assertAlmostEqual(x, 0)
+        self.assertAlmostEqual(y, 0)
+        self.assertAlmostEqual(z, math.pi / 2, places=5)
+
+        # Change path from absolute to relative. This should not break the animation.
+        bpy.context.scene.frame_set(1)
+        bpy.data.cache_files[fname].filepath = relpath
+        bpy.context.scene.frame_set(10)
+
+        x, y, z = cube.matrix_world.to_euler('XYZ')
+        self.assertAlmostEqual(x, 0)
+        self.assertAlmostEqual(y, 0)
+        self.assertAlmostEqual(z, math.pi / 2, places=5)
+
+        # Replace the Alembic file; this should apply new animation.
+        bpy.data.cache_files[fname].filepath = relpath.replace('1.abc', '2.abc')
+        bpy.context.scene.update()
+
+        x, y, z = cube.matrix_world.to_euler('XYZ')
+        self.assertAlmostEqual(x, math.pi / 2, places=5)
+        self.assertAlmostEqual(y, 0)
+        self.assertAlmostEqual(z, 0)
+
 
 def main():
     global args