Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKévin Dietrich <kevin.dietrich@mailoo.org>2022-01-17 16:50:47 +0300
committerKévin Dietrich <kevin.dietrich@mailoo.org>2022-01-17 16:51:04 +0300
commit0a08ac2528eee972c4dc23554ffd088305e6ae92 (patch)
tree2ef9014dc16053ce6d249d877110766b0972a2ac /source/blender/io
parent9d3f35a0bf1bf5776363bfd61d53a7c85b5827a4 (diff)
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
Diffstat (limited to 'source/blender/io')
-rw-r--r--source/blender/io/alembic/ABC_alembic.h2
-rw-r--r--source/blender/io/alembic/intern/abc_reader_archive.cc49
-rw-r--r--source/blender/io/alembic/intern/abc_reader_archive.h10
-rw-r--r--source/blender/io/alembic/intern/alembic_capi.cc22
4 files changed, 78 insertions, 5 deletions
diff --git a/source/blender/io/alembic/ABC_alembic.h b/source/blender/io/alembic/ABC_alembic.h
index c1f3add377b..18b0c91b67c 100644
--- a/source/blender/io/alembic/ABC_alembic.h
+++ b/source/blender/io/alembic/ABC_alembic.h
@@ -26,6 +26,7 @@ extern "C" {
#endif
struct CacheArchiveHandle;
+struct CacheFileLayer;
struct CacheReader;
struct ListBase;
struct Main;
@@ -102,6 +103,7 @@ bool ABC_import(struct bContext *C,
struct CacheArchiveHandle *ABC_create_handle(struct Main *bmain,
const char *filename,
+ const struct CacheFileLayer *layers,
struct ListBase *object_paths);
void ABC_free_handle(struct CacheArchiveHandle *handle);
diff --git a/source/blender/io/alembic/intern/abc_reader_archive.cc b/source/blender/io/alembic/intern/abc_reader_archive.cc
index 4951dc0e035..94def041285 100644
--- a/source/blender/io/alembic/intern/abc_reader_archive.cc
+++ b/source/blender/io/alembic/intern/abc_reader_archive.cc
@@ -23,6 +23,8 @@
#include "abc_reader_archive.h"
+#include "Alembic/AbcCoreLayer/Read.h"
+
#include "BKE_main.h"
#include "BLI_path_util.h"
@@ -76,6 +78,46 @@ static IArchive open_archive(const std::string &filename,
return IArchive();
}
+ArchiveReader *ArchiveReader::get(struct Main *bmain, const std::vector<const char *> &filenames)
+{
+ std::vector<ArchiveReader *> readers;
+
+ for (const char *filename : filenames) {
+ auto reader = new ArchiveReader(bmain, filename);
+
+ if (!reader->valid()) {
+ delete reader;
+ continue;
+ }
+
+ readers.push_back(reader);
+ }
+
+ if (readers.size() == 0) {
+ return nullptr;
+ }
+
+ if (readers.size() == 1) {
+ return readers[0];
+ }
+
+ return new ArchiveReader(readers);
+}
+
+ArchiveReader::ArchiveReader(const std::vector<ArchiveReader *> &readers) : m_readers(readers)
+{
+ Alembic::AbcCoreLayer::ArchiveReaderPtrs archives;
+
+ for (auto &reader : readers) {
+ archives.push_back(reader->m_archive.getPtr());
+ }
+
+ Alembic::AbcCoreLayer::ReadArchive layer;
+ Alembic::AbcCoreAbstract::ArchiveReaderPtr arPtr = layer(archives);
+
+ m_archive = IArchive(arPtr, kWrapExisting, ErrorHandler::kThrowPolicy);
+}
+
ArchiveReader::ArchiveReader(struct Main *bmain, const char *filename)
{
char abs_filename[FILE_MAX];
@@ -96,6 +138,13 @@ ArchiveReader::ArchiveReader(struct Main *bmain, const char *filename)
m_archive = open_archive(abs_filename, m_streams);
}
+ArchiveReader::~ArchiveReader()
+{
+ for (ArchiveReader *reader : m_readers) {
+ delete reader;
+ }
+}
+
bool ArchiveReader::valid() const
{
return m_archive.valid();
diff --git a/source/blender/io/alembic/intern/abc_reader_archive.h b/source/blender/io/alembic/intern/abc_reader_archive.h
index 67000194aa1..937e3a190cf 100644
--- a/source/blender/io/alembic/intern/abc_reader_archive.h
+++ b/source/blender/io/alembic/intern/abc_reader_archive.h
@@ -41,9 +41,17 @@ class ArchiveReader {
std::ifstream m_infile;
std::vector<std::istream *> m_streams;
- public:
+ std::vector<ArchiveReader *> m_readers;
+
+ ArchiveReader(const std::vector<ArchiveReader *> &readers);
+
ArchiveReader(struct Main *bmain, const char *filename);
+ public:
+ static ArchiveReader *get(struct Main *bmain, const std::vector<const char *> &filenames);
+
+ ~ArchiveReader();
+
bool valid() const;
Alembic::Abc::IObject getTop();
diff --git a/source/blender/io/alembic/intern/alembic_capi.cc b/source/blender/io/alembic/intern/alembic_capi.cc
index d7b176eea50..58fc4dd599d 100644
--- a/source/blender/io/alembic/intern/alembic_capi.cc
+++ b/source/blender/io/alembic/intern/alembic_capi.cc
@@ -159,11 +159,25 @@ static bool gather_objects_paths(const IObject &object, ListBase *object_paths)
CacheArchiveHandle *ABC_create_handle(struct Main *bmain,
const char *filename,
+ const CacheFileLayer *layers,
ListBase *object_paths)
{
- ArchiveReader *archive = new ArchiveReader(bmain, filename);
+ std::vector<const char *> filenames;
+ filenames.push_back(filename);
- if (!archive->valid()) {
+ while (layers) {
+ if ((layers->flag & CACHEFILE_LAYER_HIDDEN) == 0) {
+ filenames.push_back(layers->filepath);
+ }
+ layers = layers->next;
+ }
+
+ /* We need to reverse the order as overriding archives should come first. */
+ std::reverse(filenames.begin(), filenames.end());
+
+ ArchiveReader *archive = ArchiveReader::get(bmain, filenames);
+
+ if (!archive || !archive->valid()) {
delete archive;
return nullptr;
}
@@ -447,9 +461,9 @@ static void import_startjob(void *user_data, short *stop, short *do_update, floa
WM_set_locked_interface(data->wm, true);
- ArchiveReader *archive = new ArchiveReader(data->bmain, data->filename);
+ ArchiveReader *archive = ArchiveReader::get(data->bmain, {data->filename});
- if (!archive->valid()) {
+ if (!archive || !archive->valid()) {
data->error_code = ABC_ARCHIVE_FAIL;
delete archive;
return;