Function addKeyframe

Synopsis

#include <Source/Falcor/Scene/Animation/Animation.h>

void addKeyframe(uint32_t channelID, const Keyframe &keyframe)

Description

Add a keyframe. If there's already a keyframe at the requested time, this call will override the existing frame

Source

Lines 201-241 in Source/Falcor/Scene/Animation/Animation.cpp. Line 79 in Source/Falcor/Scene/Animation/Animation.h.

void Animation::addKeyframe(uint32_t channelID, const Keyframe& keyframe)
{
    assert(channelID < mChannels.size());
    assert(keyframe.time <= mDurationInSeconds);
    mChannels[channelID].lastKeyframeUsed = 0;
    auto& channelFrames = mChannels[channelID].keyframes;
    if (channelFrames.size() == 0 || channelFrames[0].time > keyframe.time)
    {
        channelFrames.insert(channelFrames.begin(), keyframe);
        return;
    }
    else
    {
        for (size_t i = 0; i < channelFrames.size(); i++)
        {
            auto& current = channelFrames[i];
            // If we already have a key-frame at the same time, replace it
            if (current.time == keyframe.time)
            {
                current = keyframe;
                return;
            }
            // If this is not the last frame, Check if we are in between frames
            if (i < channelFrames.size() - 1)
            {
                auto& Next = channelFrames[i + 1];
                if (current.time < keyframe.time && Next.time > keyframe.time)
                {
                    channelFrames.insert(channelFrames.begin() + i + 1, keyframe);
                    return;
                }
            }
        }
        // If we got here, need to push it to the end of the list
        channelFrames.push_back(keyframe);
    }
}





Add Discussion as Guest

Log in to DocsForge