Magnum::Trade::AnimationData class

Animation clip data.

Provides access to animation data and track properties of given clip. The instance is commonly returned from AbstractImporter::animation() and a typical usage is feeding all the tracks directly to Animation::Player. For every track, you need to query its concrete type and then feed the resulting Animation::TrackView of correct type to Animation::Player::add(), for example.

Note that this class owns the animation track data and the tracks are only views on it. In order to be able to destroy the AnimationData instance and keep using the animations later, you need to take ownership of the data using release().

In the following snippet all animated positions are stored in an array. The array is then updated during calls to Animation::Player::advance().

Containers::Optional<Trade::AnimationData> data = importer->animation(id);

Animation::Player<Float> player;
Containers::Array<Vector3> positions; /* Translations for all objects */
for(UnsignedInt i = 0; i != data->trackCount(); ++i) {
    if(data->trackTargetType(i) == Trade::AnimationTrackTargetType::Translation3D) {
        CORRADE_INTERNAL_ASSERT(data->trackType(i) ==
            Trade::AnimationTrackType::Vector3);
        player.add(data->track<Vector3>(i), positions[data->trackTarget(i)]);
    }

    // similarly for rotation / scaling ...
}

Containers::Array<char> animationData = data->release(); /* Take ownership */

It's also possible to directly update object transformations using callbacks, among other things. See documentation of the Animation::Player class for more information.

Constructors, destructors, conversion operators

AnimationData(Containers::Array<char>&& data, Containers::Array<AnimationTrackData>&& tracks, const void* importerState = nullptr) explicit noexcept
Construct with implicit duration.
AnimationData(Containers::Array<char>&& data, Containers::Array<AnimationTrackData>&& tracks, const Range1D& duration, const void* importerState = nullptr) explicit noexcept
Construct with explicit duration.
AnimationData(const AnimationData&) deleted
Copying is not allowed.
AnimationData(AnimationData&&) noexcept
Move constructor.

Public functions

auto operator=(const AnimationData&) -> AnimationData& deleted
Copying is not allowed.
auto operator=(AnimationData&&) -> AnimationData& noexcept
Move assignment.
auto data() & -> Containers::ArrayView<char>
Raw data.
auto data() && -> Containers::ArrayView<char> deleted
auto data() const & -> Containers::ArrayView<const char>
auto data() const && -> Containers::ArrayView<const char> deleted
auto duration() const -> Range1D
Duration.
auto trackCount() const -> UnsignedInt
Track count.
auto trackType(UnsignedInt id) const -> AnimationTrackType
Track value type.
auto trackResultType(UnsignedInt id) const -> AnimationTrackType
Track result type.
auto trackTargetType(UnsignedInt id) const -> AnimationTrackTargetType
Track target type.
auto trackTarget(UnsignedInt id) const -> UnsignedInt
Track target.
auto track(UnsignedInt id) const -> const Animation::TrackViewStorage<Float>&
Track data storage.
template<class V, class R = Animation::ResultOf<V>>
auto track(UnsignedInt id) const -> const Animation::TrackView<Float, V, R>&
Track data.
auto release() -> Containers::Array<char>
Release data storage.
auto importerState() const -> const void*
Importer-specific state.

Function documentation

Magnum::Trade::AnimationData::AnimationData(Containers::Array<char>&& data, Containers::Array<AnimationTrackData>&& tracks, const void* importerState = nullptr) explicit noexcept

Construct with implicit duration.

Parameters
data Buffer containing all keyframe data for this animation clip
tracks Track data
importerState Importer-specific state

Each item of track should have an Animation::TrackView instance pointing its key/value views to data. The duration() is automatically calculated from durations of all tracks.

Magnum::Trade::AnimationData::AnimationData(Containers::Array<char>&& data, Containers::Array<AnimationTrackData>&& tracks, const Range1D& duration, const void* importerState = nullptr) explicit noexcept

Construct with explicit duration.

Parameters
data Buffer containing all keyframe data for this animation clip
tracks Track data
duration Animation track duration
importerState Importer-specific state

Each item of track should have an Animation::TrackView instance pointing its key/value views to data.

Containers::ArrayView<char> Magnum::Trade::AnimationData::data() &

Raw data.

Contains data for all tracks contained in this clip.

Containers::ArrayView<char> Magnum::Trade::AnimationData::data() && deleted

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Containers::ArrayView<const char> Magnum::Trade::AnimationData::data() const &

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Containers::ArrayView<const char> Magnum::Trade::AnimationData::data() const && deleted

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

AnimationTrackType Magnum::Trade::AnimationData::trackType(UnsignedInt id) const

Track value type.

Parameters
id Track index

Data types are usually closely related to trackTargetType(), see AnimationTrackTargetType documentation for more information.

AnimationTrackType Magnum::Trade::AnimationData::trackResultType(UnsignedInt id) const

Track result type.

Parameters
id Track index

In case track values are packed, track result type is different from trackType(). Data types are usually closely related to trackTargetType(), see AnimationTrackTargetType documentation for more information.

AnimationTrackTargetType Magnum::Trade::AnimationData::trackTargetType(UnsignedInt id) const

Track target type.

Parameters
id Track index

Particular animation targets usually correspond to a common trackType(), see AnimationTrackTargetType documentation for more information.

const Animation::TrackViewStorage<Float>& Magnum::Trade::AnimationData::track(UnsignedInt id) const

Track data storage.

Returns the untyped base of a Animation::TrackView, which allows access only to some track properties. Use the templated and checked version below to access a concrete Animation::TrackView type.

template<class V, class R = Animation::ResultOf<V>>
const Animation::TrackView<Float, V, R>& Magnum::Trade::AnimationData::track(UnsignedInt id) const

Track data.

Template parameters
V Track value type
R Track result type

Expects that requested types are correct for given trackType() and trackResultType(). Note that the returned view is onto data(), meaning you either need to ensure that the AnimationData instance stays in scope for as long as you use the view or you need to release the data array using release() and manage its lifetime yourself.

Containers::Array<char> Magnum::Trade::AnimationData::release()

Release data storage.

Releases the ownership of the data array and resets internal state to default.

const void* Magnum::Trade::AnimationData::importerState() const

Importer-specific state.

See AbstractImporter::importerState() for more information.

template<class V, class R = Animation::ResultOf<V>>
auto animationInterpolatorFor(Animation::Interpolation interpolation)

Animation interpolator function for given interpolation behavior.

To be used from importer plugins — wrapper around Animation::interpolatorFor(), guaranteeing that the returned function pointer is not instantiated inside the plugin binary to avoid dangling function pointers on plugin unload.