Alembic import: option to always add a cache reader

The current behavior of the Alembic importer is to only create a
`MeshSequenceCache` modifier or a `Transform Cache` constraint to imported
objects if they have some animated properties.

Since static objects do not have a cache reader, when reloading files those
objects are not updated. Currently, the only way to properly reload a file
because of this is to reimport it.

This adds an option to the importer to always add a cache reader, even if
there is no animated data, to ensure that all objects coming from Alembic
archive are linked to them and updated properly upon reloads.

Reviewed by: brecht, sybren

Ref D10197.
This commit is contained in:
Kévin Dietrich 2021-08-19 14:13:45 +02:00
parent 4db4123409
commit 5b97c00e9f
8 changed files with 20 additions and 5 deletions

View File

@ -615,6 +615,7 @@ static void ui_alembic_import_settings(uiLayout *layout, PointerRNA *imfptr)
uiItemR(col, imfptr, "set_frame_range", 0, NULL, ICON_NONE);
uiItemR(col, imfptr, "is_sequence", 0, NULL, ICON_NONE);
uiItemR(col, imfptr, "validate_meshes", 0, NULL, ICON_NONE);
uiItemR(col, imfptr, "always_add_cache_reader", 0, NULL, ICON_NONE);
}
static void wm_alembic_import_draw(bContext *UNUSED(C), wmOperator *op)
@ -645,6 +646,7 @@ static int wm_alembic_import_exec(bContext *C, wmOperator *op)
const bool is_sequence = RNA_boolean_get(op->ptr, "is_sequence");
const bool set_frame_range = RNA_boolean_get(op->ptr, "set_frame_range");
const bool validate_meshes = RNA_boolean_get(op->ptr, "validate_meshes");
const bool always_add_cache_reader = RNA_boolean_get(op->ptr, "always_add_cache_reader");
const bool as_background_job = RNA_boolean_get(op->ptr, "as_background_job");
int offset = 0;
@ -672,6 +674,7 @@ static int wm_alembic_import_exec(bContext *C, wmOperator *op)
sequence_len,
offset,
validate_meshes,
always_add_cache_reader,
as_background_job);
return as_background_job || ok ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
@ -721,6 +724,13 @@ void WM_OT_alembic_import(wmOperatorType *ot)
"Validate Meshes",
"Check imported mesh objects for invalid data (slow)");
RNA_def_boolean(ot->srna,
"always_add_cache_reader",
false,
"Always Add Cache Reader",
"Add cache modifiers and constraints to imported objects even if they are not "
"animated so that they can be updated when reloading the Alembic archive");
RNA_def_boolean(ot->srna,
"is_sequence",
false,

View File

@ -97,6 +97,7 @@ bool ABC_import(struct bContext *C,
int sequence_len,
int offset,
bool validate_meshes,
bool always_add_cache_reader,
bool as_background_job);
struct CacheArchiveHandle *ABC_create_handle(struct Main *bmain,

View File

@ -112,7 +112,7 @@ void AbcCurveReader::readObjectData(Main *bmain, const Alembic::Abc::ISampleSele
read_curve_sample(cu, m_curves_schema, sample_sel);
if (has_animations(m_curves_schema, m_settings)) {
if (m_settings->always_add_cache_reader || has_animations(m_curves_schema, m_settings)) {
addCacheModifier();
}
}

View File

@ -578,7 +578,7 @@ void AbcMeshReader::readObjectData(Main *bmain, const Alembic::Abc::ISampleSelec
readFaceSetsSample(bmain, mesh, sample_sel);
if (has_animations(m_schema, m_settings)) {
if (m_settings->always_add_cache_reader || has_animations(m_schema, m_settings)) {
addCacheModifier();
}
}
@ -928,7 +928,7 @@ void AbcSubDReader::readObjectData(Main *bmain, const Alembic::Abc::ISampleSelec
BKE_mesh_validate(mesh, false, false);
}
if (has_animations(m_schema, m_settings)) {
if (m_settings->always_add_cache_reader || has_animations(m_schema, m_settings)) {
addCacheModifier();
}
}

View File

@ -197,7 +197,7 @@ void AbcObjectReader::setupObjectTransform(const float time)
BKE_object_apply_mat4(m_object, transform_from_alembic, true, false);
BKE_object_to_mat4(m_object, m_object->obmat);
if (!is_constant) {
if (!is_constant || m_settings->always_add_cache_reader) {
bConstraint *con = BKE_constraint_add_for_object(
m_object, nullptr, CONSTRAINT_TYPE_TRANSFORM_CACHE);
bTransformCacheConstraint *data = static_cast<bTransformCacheConstraint *>(con->data);

View File

@ -51,6 +51,7 @@ struct ImportSettings {
int read_flag;
bool validate_meshes;
bool always_add_cache_reader;
CacheFile *cache_file;
@ -65,6 +66,7 @@ struct ImportSettings {
sequence_offset(0),
read_flag(0),
validate_meshes(false),
always_add_cache_reader(false),
cache_file(NULL)
{
}

View File

@ -95,7 +95,7 @@ void AbcPointsReader::readObjectData(Main *bmain, const Alembic::Abc::ISampleSel
m_object = BKE_object_add_only_object(bmain, OB_MESH, m_object_name.c_str());
m_object->data = mesh;
if (has_animations(m_schema, m_settings)) {
if (m_settings->always_add_cache_reader || has_animations(m_schema, m_settings)) {
addCacheModifier();
}
}

View File

@ -663,6 +663,7 @@ bool ABC_import(bContext *C,
int sequence_len,
int offset,
bool validate_meshes,
bool always_add_cache_reader,
bool as_background_job)
{
/* Using new here since MEM_* functions do not call constructor to properly initialize data. */
@ -681,6 +682,7 @@ bool ABC_import(bContext *C,
job->settings.sequence_len = sequence_len;
job->settings.sequence_offset = offset;
job->settings.validate_meshes = validate_meshes;
job->settings.always_add_cache_reader = always_add_cache_reader;
job->error_code = ABC_NO_ERROR;
job->was_cancelled = false;
job->archive = nullptr;