From 0a08ac2528eee972c4dc23554ffd088305e6ae92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dietrich?= Date: Mon, 17 Jan 2022 14:50:47 +0100 Subject: 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 --- intern/cycles/blender/object.cpp | 11 +++++++++++ intern/cycles/scene/alembic.cpp | 17 +++++++++++++++-- intern/cycles/scene/alembic.h | 4 ++++ 3 files changed, 30 insertions(+), 2 deletions(-) (limited to 'intern') diff --git a/intern/cycles/blender/object.cpp b/intern/cycles/blender/object.cpp index 86314d3b196..65a04a39660 100644 --- a/intern/cycles/blender/object.cpp +++ b/intern/cycles/blender/object.cpp @@ -529,6 +529,17 @@ void BlenderSync::sync_procedural(BL::Object &b_ob, string absolute_path = blender_absolute_path(b_data, b_ob, b_mesh_cache.cache_file().filepath()); procedural->set_filepath(ustring(absolute_path)); + array layers; + for (BL::CacheFileLayer &layer : cache_file.layers) { + if (layer.hide_layer()) { + continue; + } + + absolute_path = blender_absolute_path(b_data, b_ob, layer.filepath()); + layers.push_back_slow(ustring(absolute_path)); + } + procedural->set_layers(layers); + procedural->set_scale(cache_file.scale()); procedural->set_use_prefetch(cache_file.use_prefetch()); diff --git a/intern/cycles/scene/alembic.cpp b/intern/cycles/scene/alembic.cpp index 71fa1863b8b..7780b13eecb 100644 --- a/intern/cycles/scene/alembic.cpp +++ b/intern/cycles/scene/alembic.cpp @@ -742,6 +742,7 @@ NODE_DEFINE(AlembicProcedural) NodeType *type = NodeType::add("alembic", create); SOCKET_STRING(filepath, "Filename", ustring()); + SOCKET_STRING_ARRAY(layers, "Layers", array()); SOCKET_FLOAT(frame, "Frame", 1.0f); SOCKET_FLOAT(start_frame, "Start Frame", 1.0f); SOCKET_FLOAT(end_frame, "End Frame", 1.0f); @@ -839,14 +840,26 @@ void AlembicProcedural::generate(Scene *scene, Progress &progress) return; } - if (!archive.valid()) { + if (!archive.valid() || filepath_is_modified() || layers_is_modified()) { Alembic::AbcCoreFactory::IFactory factory; factory.setPolicy(Alembic::Abc::ErrorHandler::kQuietNoopPolicy); - archive = factory.getArchive(filepath.c_str()); + + std::vector filenames; + filenames.push_back(filepath.c_str()); + + for (const ustring &layer : layers) { + filenames.push_back(layer.c_str()); + } + + /* We need to reverse the order as overriding archives should come first. */ + std::reverse(filenames.begin(), filenames.end()); + + archive = factory.getArchive(filenames); if (!archive.valid()) { /* avoid potential infinite update loops in viewport synchronization */ filepath.clear(); + layers.clear(); clear_modified(); return; } diff --git a/intern/cycles/scene/alembic.h b/intern/cycles/scene/alembic.h index 3a4d37da3ff..6068ea3ef03 100644 --- a/intern/cycles/scene/alembic.h +++ b/intern/cycles/scene/alembic.h @@ -479,6 +479,10 @@ class AlembicProcedural : public Procedural { /* The file path to the Alembic archive */ NODE_SOCKET_API(ustring, filepath) + /* Layers for the Alembic archive. Layers are in the order in which they override data, with the + * latter elements overriding the former ones. */ + NODE_SOCKET_API_ARRAY(array, layers) + /* The current frame to render. */ NODE_SOCKET_API(float, frame) -- cgit v1.2.3