diff options
author | Kévin Dietrich <kevin.dietrich@mailoo.org> | 2021-04-07 03:33:47 +0300 |
---|---|---|
committer | Kévin Dietrich <kevin.dietrich@mailoo.org> | 2021-04-07 03:33:47 +0300 |
commit | 3683aa2154eaa1e4e4bf2ea15fbfc3180d98cb08 (patch) | |
tree | 38e517e471a10b5c3b5d3c24e899a405621313fd /source/blender/io/alembic | |
parent | 2f337e6378bb9a82ea38b6056bd8dd07ef9b989b (diff) |
Basic operator to update the Scene frame range from an Alembic cache.
Diffstat (limited to 'source/blender/io/alembic')
-rw-r--r-- | source/blender/io/alembic/ABC_alembic.h | 2 | ||||
-rw-r--r-- | source/blender/io/alembic/intern/abc_reader_archive.cc | 36 | ||||
-rw-r--r-- | source/blender/io/alembic/intern/abc_reader_archive.h | 7 | ||||
-rw-r--r-- | source/blender/io/alembic/intern/alembic_capi.cc | 25 |
4 files changed, 70 insertions, 0 deletions
diff --git a/source/blender/io/alembic/ABC_alembic.h b/source/blender/io/alembic/ABC_alembic.h index ca503c35d80..83628704110 100644 --- a/source/blender/io/alembic/ABC_alembic.h +++ b/source/blender/io/alembic/ABC_alembic.h @@ -104,6 +104,8 @@ AbcArchiveHandle *ABC_create_handle(struct Main *bmain, const char *filename, struct ListBase *object_paths); +bool ABC_get_min_max_time(AbcArchiveHandle *handle, double *r_min_time, double *r_max_time); + void ABC_free_handle(AbcArchiveHandle *handle); void ABC_get_transform(struct CacheReader *reader, diff --git a/source/blender/io/alembic/intern/abc_reader_archive.cc b/source/blender/io/alembic/intern/abc_reader_archive.cc index 4951dc0e035..c232665d5b7 100644 --- a/source/blender/io/alembic/intern/abc_reader_archive.cc +++ b/source/blender/io/alembic/intern/abc_reader_archive.cc @@ -38,6 +38,9 @@ using Alembic::Abc::ErrorHandler; using Alembic::Abc::Exception; using Alembic::Abc::IArchive; using Alembic::Abc::kWrapExisting; +using Alembic::Abc::TimeSamplingPtr; +using Alembic::Abc::TimeSamplingType; +using Alembic::Abc::chrono_t; namespace blender::io::alembic { @@ -106,4 +109,37 @@ Alembic::Abc::IObject ArchiveReader::getTop() return m_archive.getTop(); } +TimeInfo ArchiveReader::getTimeInfo() +{ + const uint32_t num_time_sampling_ptrs = m_archive.getNumTimeSamplings(); + + chrono_t min_time = std::numeric_limits<chrono_t>::max(); + chrono_t max_time = -std::numeric_limits<chrono_t>::max(); + + for (uint32_t i = 0; i < num_time_sampling_ptrs; ++i) { + const Alembic::Abc::index_t max_samples = m_archive.getMaxNumSamplesForTimeSamplingIndex(i); + + /* This can only happen in very old files, predating the original Blender Alembic support, + * however let's make sure this case is handled. */ + if (max_samples == INDEX_UNKNOWN) { + continue; + } + + const TimeSamplingPtr time_sampling_ptr = m_archive.getTimeSampling(i); + assert(time_sampling_ptr); + + const TimeSamplingType &time_sampling_type = time_sampling_ptr->getTimeSamplingType(); + + /* Avoid the default time sampling, it should be at index 0, but we never know. */ + if (time_sampling_ptr->getNumStoredTimes() == 1 && time_sampling_ptr->getStoredTimes()[0] == 0.0 && time_sampling_type.getTimePerCycle() == 1.0) { + continue; + } + + min_time = std::min(min_time, time_sampling_ptr->getSampleTime(0)); + max_time = std::max(max_time, time_sampling_ptr->getSampleTime(max_samples - 1)); + } + + return {min_time, max_time}; +} + } // namespace blender::io::alembic diff --git a/source/blender/io/alembic/intern/abc_reader_archive.h b/source/blender/io/alembic/intern/abc_reader_archive.h index 67000194aa1..56177187775 100644 --- a/source/blender/io/alembic/intern/abc_reader_archive.h +++ b/source/blender/io/alembic/intern/abc_reader_archive.h @@ -31,6 +31,11 @@ struct Main; namespace blender::io::alembic { +struct TimeInfo { + Alembic::Abc::chrono_t min_time; + Alembic::Abc::chrono_t max_time; +}; + /* Wrappers around input and output archives. The goal is to be able to use * streams so that unicode paths work on Windows (T49112), and to make sure that * the stream objects remain valid as long as the archives are open. @@ -47,6 +52,8 @@ class ArchiveReader { bool valid() const; Alembic::Abc::IObject getTop(); + + TimeInfo getTimeInfo(); }; } // namespace blender::io::alembic diff --git a/source/blender/io/alembic/intern/alembic_capi.cc b/source/blender/io/alembic/intern/alembic_capi.cc index edef76ad98d..7e40c70dc6b 100644 --- a/source/blender/io/alembic/intern/alembic_capi.cc +++ b/source/blender/io/alembic/intern/alembic_capi.cc @@ -178,6 +178,31 @@ AbcArchiveHandle *ABC_create_handle(struct Main *bmain, return handle_from_archive(archive); } +bool ABC_get_min_max_time(AbcArchiveHandle *handle, double *r_min_time, double *r_max_time) +{ + ArchiveReader *archive = archive_from_handle(handle); + + if (!archive) { + return false; + } + + if (!archive->valid()) { + return false; + } + + const TimeInfo time_info = archive->getTimeInfo(); + + if (r_min_time) { + *r_min_time = time_info.min_time; + } + + if (r_max_time) { + *r_max_time = time_info.max_time; + } + + return true; +} + void ABC_free_handle(AbcArchiveHandle *handle) { delete archive_from_handle(handle); |