axmol/extensions/DragonBones/model/AnimationConfig.cpp

143 lines
4.1 KiB
C++
Raw Normal View History

#include "AnimationConfig.h"
#include "../armature/Armature.h"
#include "../armature/Bone.h"
DRAGONBONES_NAMESPACE_BEGIN
void AnimationConfig::_onClear()
{
2021-12-25 10:04:45 +08:00
pauseFadeOut = true;
fadeOutMode = AnimationFadeOutMode::All;
fadeOutTweenType = TweenType::Line;
2021-12-25 10:04:45 +08:00
fadeOutTime = -1.0f;
2021-12-25 10:04:45 +08:00
actionEnabled = true;
additiveBlending = false;
2021-12-25 10:04:45 +08:00
displayControl = true;
pauseFadeIn = true;
resetToPose = true;
fadeInTweenType = TweenType::Line;
playTimes = -1;
layer = 0;
position = 0.0f;
duration = -1.0f;
timeScale = -100.0f;
weight = 1.0f;
fadeInTime = -1.0f;
autoFadeOutTime = -1.0f;
name = "";
animation = "";
group = "";
boneMask.clear();
}
void AnimationConfig::clear()
{
_onClear();
}
void AnimationConfig::copyFrom(AnimationConfig* value)
{
2021-12-25 10:04:45 +08:00
pauseFadeOut = value->pauseFadeOut;
fadeOutMode = value->fadeOutMode;
autoFadeOutTime = value->autoFadeOutTime;
fadeOutTweenType = value->fadeOutTweenType;
2021-12-25 10:04:45 +08:00
actionEnabled = value->actionEnabled;
additiveBlending = value->additiveBlending;
2021-12-25 10:04:45 +08:00
displayControl = value->displayControl;
pauseFadeIn = value->pauseFadeIn;
resetToPose = value->resetToPose;
playTimes = value->playTimes;
layer = value->layer;
position = value->position;
duration = value->duration;
timeScale = value->timeScale;
weight = value->weight;
fadeInTime = value->fadeInTime;
fadeOutTime = value->fadeOutTime;
fadeInTweenType = value->fadeInTweenType;
name = value->name;
animation = value->animation;
group = value->group;
boneMask = value->boneMask;
}
bool AnimationConfig::containsBoneMask(std::string_view boneName) const
{
return boneMask.empty() || std::find(boneMask.cbegin(), boneMask.cend(), boneName) != boneMask.cend();
}
void AnimationConfig::addBoneMask(Armature* armature, std::string_view boneName, bool recursive)
{
const auto currentBone = armature->getBone(boneName);
if (currentBone == nullptr)
{
return;
}
2021-12-25 10:04:45 +08:00
if (std::find(boneMask.cbegin(), boneMask.cend(), boneName) == boneMask.cend()) // Add mixing
{
boneMask.push_back(std::string{boneName});
}
2021-12-25 10:04:45 +08:00
if (recursive) // Add recursive mixing.
{
2021-12-25 10:04:45 +08:00
for (const auto bone : armature->getBones())
{
2021-12-25 10:04:45 +08:00
if (std::find(boneMask.cbegin(), boneMask.cend(), bone->getName()) == boneMask.cend() &&
currentBone->contains(bone))
{
boneMask.push_back(std::string{bone->getName()});
}
}
}
}
void AnimationConfig::removeBoneMask(Armature* armature, std::string_view boneName, bool recursive)
{
{
auto iterator = std::find(boneMask.begin(), boneMask.end(), boneName);
2021-12-25 10:04:45 +08:00
if (iterator != boneMask.end()) // Remove mixing.
{
boneMask.erase(iterator);
}
}
2021-12-25 10:04:45 +08:00
if (recursive)
{
const auto currentBone = armature->getBone(boneName);
if (currentBone != nullptr)
{
2021-12-25 10:04:45 +08:00
if (!boneMask.empty()) // Remove recursive mixing.
{
for (const auto bone : armature->getBones())
{
auto iterator = std::find(boneMask.begin(), boneMask.end(), bone->getName());
2021-12-25 10:04:45 +08:00
if (iterator != boneMask.end() && currentBone->contains(bone))
{
boneMask.erase(iterator);
}
}
}
2021-12-25 10:04:45 +08:00
else // Add unrecursive mixing.
{
for (const auto bone : armature->getBones())
{
2021-12-25 10:04:45 +08:00
if (bone == currentBone)
{
continue;
}
2021-12-25 10:04:45 +08:00
if (!currentBone->contains(bone))
{
boneMask.push_back(std::string{bone->getName()});
}
}
}
}
}
}
DRAGONBONES_NAMESPACE_END