Alembic: add support for reading override layers

Override layers are a standard feature of Alembic, where archives can override
data from other archives, provided that the hierarchies match.

This is useful for modifying a UV map, updating an animation, or even creating
some sort of LOD system where low resolution meshes are swapped by high resolution
versions.

It is possible to add UV maps and vertex colors using this system, however, they
will only appear in the spreadsheet editor when viewing evaluated data, as the UV
map and Vertex color UI only show data present on the original mesh.

Implementation wise, this adds a `CacheFileLayer` data structure to the `CacheFile`
DNA, as well as some operators and UI to present and manage the layers. For both
the Alembic importer and the Cycles procedural, the main change is creating an
archive from a list of filepaths, instead of a single one.

After importing the base file through the regular import operator, layers can be added
to or removed from the `CacheFile` via the UI list under the `Override Layers` panel
located in the Mesh Sequence Cache modifier. Layers can also be moved around or
hidden.

See differential page for tests files and demos.

Reviewed by: brecht, sybren

Differential Revision: https://developer.blender.org/D13603
This commit is contained in:
2022-01-17 14:50:47 +01:00
parent 9d3f35a0bf
commit 0a08ac2528
23 changed files with 712 additions and 11 deletions

View File

@@ -357,6 +357,58 @@ class CameraExportImportTest(unittest.TestCase):
self.assertAlmostEqual(1, actual_scale.z, delta=delta_scale)
class OverrideLayersTest(AbstractAlembicTest):
def test_import_layer(self):
fname = 'cube-base-file.abc'
fname_layer = 'cube-hi-res.abc'
abc = self.testdir / fname
abc_layer = self.testdir / fname_layer
# We need a cache reader to ensure that the data will be updated after adding a layer.
res = bpy.ops.wm.alembic_import(filepath=str(abc), as_background_job=False, always_add_cache_reader=True)
self.assertEqual({'FINISHED'}, res)
# Check that the file loaded ok.
cube = bpy.context.active_object
depsgraph = bpy.context.evaluated_depsgraph_get()
scene = bpy.context.scene
cube_eval = cube.evaluated_get(depsgraph)
mesh = cube_eval.to_mesh()
# The base file should be a default cube.
self.assertEqual(len(mesh.vertices), 8)
self.assertEqual(len(mesh.edges), 12)
self.assertEqual(len(mesh.polygons), 6)
# Add a layer.
cache_file = bpy.data.cache_files[fname]
self.assertEqual(len(cache_file.layers), 0)
layer = cache_file.layers.new(filepath=str(abc_layer))
self.assertEqual(len(cache_file.layers), 1)
self.assertIsNotNone(layer)
# The layer added a higher res version of the mesh.
depsgraph = bpy.context.evaluated_depsgraph_get()
cube_eval = cube.evaluated_get(depsgraph)
mesh = cube_eval.to_mesh()
self.assertEqual(len(mesh.vertices), 26)
self.assertEqual(len(mesh.edges), 48)
self.assertEqual(len(mesh.polygons), 24)
# Remove the layer.
cache_file.layers.remove(layer)
self.assertEqual(len(cache_file.layers), 0)
# We should have reverted to the default cube.
depsgraph = bpy.context.evaluated_depsgraph_get()
cube_eval = cube.evaluated_get(depsgraph)
mesh = cube_eval.to_mesh()
self.assertEqual(len(mesh.vertices), 8)
self.assertEqual(len(mesh.edges), 12)
self.assertEqual(len(mesh.polygons), 6)
def main():
global args
import argparse