Example #1
0
AnimationChannel* createAnimationChannel(FbxNode* fbxNode, unsigned int targetAttrib, const vector<float>& keyTimes, const vector<float>& keyValues)
{
    AnimationChannel* channel = new AnimationChannel();
    channel->setTargetId(fbxNode->GetName());
    channel->setKeyTimes(keyTimes);
    channel->setKeyValues(keyValues);
    channel->setInterpolation(AnimationChannel::LINEAR);
    channel->setTargetAttribute(targetAttrib);
    return channel;
}
Example #2
0
void GPBFile::decomposeTransformAnimationChannel(Animation* animation, const AnimationChannel* channel)
{
    const std::vector<float>& keyTimes = channel->getKeyTimes();
    const std::vector<float>& keyValues = channel->getKeyValues();
    const size_t keyTimesSize = keyTimes.size();
    const size_t keyValuesSize = keyValues.size();

    std::vector<float> scaleKeyValues;
    std::vector<float> rotateKeyValues;
    std::vector<float> translateKeyValues;
                    
    scaleKeyValues.reserve(keyTimesSize * 3);
    rotateKeyValues.reserve(keyTimesSize * 4);
    translateKeyValues.reserve(keyTimesSize * 3);

    for (size_t kv = 0; kv < keyValuesSize; kv += 10)
    {
        scaleKeyValues.push_back(keyValues[kv]);
        scaleKeyValues.push_back(keyValues[kv+1]);
        scaleKeyValues.push_back(keyValues[kv+2]);

        rotateKeyValues.push_back(keyValues[kv+3]);
        rotateKeyValues.push_back(keyValues[kv+4]);
        rotateKeyValues.push_back(keyValues[kv+5]);
        rotateKeyValues.push_back(keyValues[kv+6]);

        translateKeyValues.push_back(keyValues[kv+7]);
        translateKeyValues.push_back(keyValues[kv+8]);
        translateKeyValues.push_back(keyValues[kv+9]);
    }

    // replace transform animation channel with translate, rotate and scale animation channels

    // Don't add the scale channel if all the key values are close to 1.0
    size_t oneCount = (size_t)std::count_if(scaleKeyValues.begin(), scaleKeyValues.end(), isAlmostOne);
    if (scaleKeyValues.size() != oneCount)
    {
        AnimationChannel* scaleChannel = new AnimationChannel();
        scaleChannel->setTargetId(channel->getTargetId());
        scaleChannel->setKeyTimes(channel->getKeyTimes());
        scaleChannel->setTangentsIn(channel->getTangentsIn());
        scaleChannel->setTangentsOut(channel->getTangentsOut());
        scaleChannel->setInterpolations(channel->getInterpolationTypes());
        scaleChannel->setTargetAttribute(Transform::ANIMATE_SCALE);
        scaleChannel->setKeyValues(scaleKeyValues);
        scaleChannel->removeDuplicates();
        animation->add(scaleChannel);
    }

    AnimationChannel* rotateChannel = new AnimationChannel();
    rotateChannel->setTargetId(channel->getTargetId());
    rotateChannel->setKeyTimes(channel->getKeyTimes());
    rotateChannel->setTangentsIn(channel->getTangentsIn());
    rotateChannel->setTangentsOut(channel->getTangentsOut());
    rotateChannel->setInterpolations(channel->getInterpolationTypes());
    rotateChannel->setTargetAttribute(Transform::ANIMATE_ROTATE);
    rotateChannel->setKeyValues(rotateKeyValues);
    rotateChannel->removeDuplicates();
    animation->add(rotateChannel);

    AnimationChannel* translateChannel = new AnimationChannel();
    translateChannel->setTargetId(channel->getTargetId());
    translateChannel->setKeyTimes(channel->getKeyTimes());
    translateChannel->setTangentsIn(channel->getTangentsIn());
    translateChannel->setTangentsOut(channel->getTangentsOut());
    translateChannel->setInterpolations(channel->getInterpolationTypes());
    translateChannel->setTargetAttribute(Transform::ANIMATE_TRANSLATE);
    translateChannel->setKeyValues(translateKeyValues);
    translateChannel->removeDuplicates();
    animation->add(translateChannel);
}