Alembic export: don't assume transform is always animated

Instead of always writing the transform on every frame, it's now checked
whether the object is animated at all. This could be made stricter to
reduce false positives, for example by checking FCurves and drivers to
see whether translation/rotation/scale is animated. However, this
approach is already better than the `return true` we had before.

This commit adds the BKE_animdata_id_is_animated(id) function, which
returns true if the ID datablock has non-empty animation data. This is
determined by checking the the active action's fcurves, the drivers, and
NLA tracks.
This commit is contained in:
Sybren A. Stüvel 2019-11-26 14:35:47 +01:00
parent a018a7fb0d
commit f18ad385df
Notes: blender-bot 2023-02-14 08:42:54 +01:00
Referenced by commit 9ea0eb0b95, Alembic export: assume that transforms are always animated
4 changed files with 26 additions and 11 deletions

View File

@ -304,14 +304,8 @@ AbcGenericMeshWriter::~AbcGenericMeshWriter()
bool AbcGenericMeshWriter::isAnimated() const
{
if (m_object->data != NULL) {
AnimData *adt = BKE_animdata_from_id(static_cast<ID *>(m_object->data));
/* TODO(Sybren): make this check more strict, as the AnimationData may
* actually be empty (no fcurves, drivers, etc.) and thus effectively
* have no animation at all. */
if (adt != NULL) {
return true;
}
if (BKE_animdata_id_is_animated(static_cast<ID *>(m_object->data))) {
return true;
}
if (BKE_key_from_object(m_object) != NULL) {
return true;

View File

@ -29,6 +29,7 @@ extern "C" {
#include "BLI_math.h"
#include "BKE_animsys.h"
#include "BKE_object.h"
#include "DEG_depsgraph_query.h"
@ -130,10 +131,9 @@ Imath::Box3d AbcTransformWriter::bounds()
return Imath::transform(bounds, m_matrix);
}
bool AbcTransformWriter::hasAnimation(Object * /*ob*/) const
bool AbcTransformWriter::hasAnimation(Object *ob) const
{
/* TODO(kevin): implement this. */
return true;
return BKE_animdata_id_is_animated(&ob->id);
}
/* ************************************************************************** */

View File

@ -60,6 +60,9 @@ bool BKE_animdata_set_action(struct ReportList *reports, struct ID *id, struct b
/* Free AnimData */
void BKE_animdata_free(struct ID *id, const bool do_id_user);
/* Return true if the ID-block has non-empty AnimData. */
bool BKE_animdata_id_is_animated(struct ID *id);
/* Copy AnimData */
struct AnimData *BKE_animdata_copy(struct Main *bmain, struct AnimData *adt, const int flag);

View File

@ -283,6 +283,24 @@ void BKE_animdata_free(ID *id, const bool do_id_user)
}
}
bool BKE_animdata_id_is_animated(struct ID *id)
{
if (id == NULL) {
return false;
}
AnimData *adt = BKE_animdata_from_id(id);
if (adt == NULL) {
return false;
}
if (adt->action != NULL && !BLI_listbase_is_empty(&adt->action->curves)) {
return true;
}
return !BLI_listbase_is_empty(&adt->drivers) || !BLI_listbase_is_empty(&adt->nla_tracks);
}
/* Copying -------------------------------------------- */
/**