Page MenuHome

Alembic: operator to set the Scene frame range from the Archive time information
Needs ReviewPublic

Authored by Kévin Dietrich (kevindietrich) on May 4 2021, 1:50 PM.

Details

Summary

This adds an operator accessible from the MeshSequenceCache modifiers or
the Transform Cache constraints to set the Scene frame range from the
Archive time information (either through the Alembic TimeSampling
pointers or from the filenames if the archive is in fact a file
sequence).

This is essentially the same procedure as what happens when setting the
Scene frame range during import, however, having this as an operator is
useful in cases where a cache is reloaded after an update to ensure that
the new Scene frame range matches that of the new archive's frame range,
as this is not updated during the file reload, which happens though a
dependency graph update.

To avoid retraversing the entire list of cache readers or Alembic
objects, this computes the frame range using the Alembic TimeSampling
pointers from the Archive's TimeSampling pool, and removes the existing
code to detect the min/max time from Alembic Schemas. As the Schemas'
TimeSampling pointers actually come from this very pool, we also avoid
recomputing the min/max time for the same TimeSampling as Alembic will
merge similar TimeSamplings during file writes.

Depends on D12411.

Diff Detail

Repository
rB Blender
Branch
abc_frame_range_refit_D11156 (branched from master)
Build Status
Buildable 21332
Build 21332: arc lint + arc unit

Event Timeline

Kévin Dietrich (kevindietrich) requested review of this revision.May 4 2021, 1:50 PM
Kévin Dietrich (kevindietrich) created this revision.
Sybren A. Stüvel (sybren) requested changes to this revision.Jul 12 2021, 5:14 PM

Nice improvement, I like the idea.

One other change is moving the code to detect the file sequence length
which was moved from io_alembic.c to cachefile.c. Maybe there is a
better place for it.

Hmmm this makes it a lot harder to actually see the functional changes. Isn't it possible to do the move and the functional changes in two commits/patches?

source/blender/blenkernel/BKE_cachefile.h
63 ↗(On Diff #36755)

This should have some comment that explains what the function does/returns.

I know you just copied the API from what there already was, but don't think it's a nice API to have the function return three things (error status, length in frames, and start frame) encoded as two values, which are then split up as one return value and one return parameter. Something like this would be much nicer IMO:

bool BKE_cachefile_get_sequence_len(const char *filename, int *r_start_frame, int *r_sequence_length_frames);
source/blender/blenkernel/intern/cachefile.c
361–367 ↗(On Diff #36755)

This is just signf(frame_a->framenr, frame_b->framenr).

source/blender/editors/io/io_cache.c
171

This entire block should be moved to some Alembic-specific function, and not be in the generic cachefile function.

176–177

These don't seem to be in use.

180

Include units, as offset = 0 doesn't mean anything.

189–191

Flip the condition and put the error handling with the error check. When moving things into their own function, you can just do a return from the error condition:

if (sequence_len < 0) {
  WM_report(RPT_ERROR, "Could not determine the time range of the Alembic archive.");
  return;
}
216

This probably should also have a poll function, to see if there is even a filename set.

source/blender/io/alembic/intern/abc_reader_archive.cc
155–159

Nice!

162

This could be a BLI_assert_msg(time_sampling_ptr, "could not get Alembic time sampling even though it was declared as available") or something along those lines.

166

Why should the default time sampling be avoided? This is not clear from the code.

source/blender/io/alembic/intern/abc_reader_archive.h
18

This should have a comment to explain what it's for.

It should also explain which side of the interval is open, i.e. does this encode [min_time, max_time] or [min_time, max_time) or any other combo of open/closed sides?

24

Why is min_time == max_time invalid?

25

This should probably be max_time != -std::numeric_limits<Alembic::Abc::chrono_t>::min();, but in that case min_time < max_time is guaranteed to return false anway. Is this check really required?

source/blender/io/alembic/intern/alembic_capi.cc
182–188

IMO this could be shortened to

if (!archive || !archive->valid()) {
  return false;
}

Just personal opinion, though. Feel free to ignore.

This revision now requires changes to proceed.Jul 12 2021, 5:14 PM
Kévin Dietrich (kevindietrich) marked 13 inline comments as done.
  • Adress requested changes.
  • Rebase with master.
  • The moving of get_sequence_len to cachefile.c was split into a separate patch (D12411).
Kévin Dietrich (kevindietrich) added inline comments.
source/blender/editors/io/io_cache.c
176–177

They are used, but only if cache_file->is_sequence is false. I moved them to the else branch.

source/blender/io/alembic/intern/abc_reader_archive.h
25

I don't know why -std::numeric_limits<Alembic::Abc::chrono_t>::min(); would be used (or even the positive version). std::numeric_limits<double>::min() is the smallest positive normal number which can be represented, so the negation would be the largest negative number, still close to 0.

std::numeric_limits::max() and -std::numeric_limits::max() are used to initialized the AbcTimeInfo. Now I realize that a constructor is missing, otherwise, this code is undefined behaviour:

AbcTimeInfo time_info;
if (time_info.is_valid()) {

}