mirror of
https://github.com/smallmain/cocos-enhance-kit.git
synced 2025-10-09 22:05:24 +00:00
初始化
This commit is contained in:
@@ -0,0 +1,141 @@
|
||||
#include "AnimationConfig.h"
|
||||
#include "../armature/Armature.h"
|
||||
#include "../armature/Bone.h"
|
||||
|
||||
DRAGONBONES_NAMESPACE_BEGIN
|
||||
|
||||
void AnimationConfig::_onClear()
|
||||
{
|
||||
pauseFadeOut = true;
|
||||
fadeOutMode = AnimationFadeOutMode::All;
|
||||
fadeOutTweenType = TweenType::Line;
|
||||
fadeOutTime = -1.0f;
|
||||
|
||||
actionEnabled = true;
|
||||
additiveBlending = false;
|
||||
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)
|
||||
{
|
||||
pauseFadeOut = value->pauseFadeOut;
|
||||
fadeOutMode = value->fadeOutMode;
|
||||
autoFadeOutTime = value->autoFadeOutTime;
|
||||
fadeOutTweenType = value->fadeOutTweenType;
|
||||
|
||||
actionEnabled = value->actionEnabled;
|
||||
additiveBlending = value->additiveBlending;
|
||||
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(const std::string& boneName) const
|
||||
{
|
||||
return boneMask.empty() || std::find(boneMask.cbegin(), boneMask.cend(), boneName) != boneMask.cend();
|
||||
}
|
||||
|
||||
void AnimationConfig::addBoneMask(Armature* armature, const std::string& boneName, bool recursive)
|
||||
{
|
||||
const auto currentBone = armature->getBone(boneName);
|
||||
if (currentBone == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (std::find(boneMask.cbegin(), boneMask.cend(), boneName) == boneMask.cend()) // Add mixing
|
||||
{
|
||||
boneMask.push_back(boneName);
|
||||
}
|
||||
|
||||
if (recursive) // Add recursive mixing.
|
||||
{
|
||||
for (const auto bone : armature->getBones())
|
||||
{
|
||||
if (std::find(boneMask.cbegin(), boneMask.cend(), bone->getName()) == boneMask.cend() && currentBone->contains(bone))
|
||||
{
|
||||
boneMask.push_back(bone->getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AnimationConfig::removeBoneMask(Armature* armature, const std::string& boneName, bool recursive)
|
||||
{
|
||||
{
|
||||
auto iterator = std::find(boneMask.begin(), boneMask.end(), boneName);
|
||||
if (iterator != boneMask.end()) // Remove mixing.
|
||||
{
|
||||
boneMask.erase(iterator);
|
||||
}
|
||||
}
|
||||
|
||||
if (recursive)
|
||||
{
|
||||
const auto currentBone = armature->getBone(boneName);
|
||||
if (currentBone != nullptr)
|
||||
{
|
||||
if (!boneMask.empty()) // Remove recursive mixing.
|
||||
{
|
||||
for (const auto bone : armature->getBones())
|
||||
{
|
||||
auto iterator = std::find(boneMask.begin(), boneMask.end(), bone->getName());
|
||||
if (iterator != boneMask.end() && currentBone->contains(bone))
|
||||
{
|
||||
boneMask.erase(iterator);
|
||||
}
|
||||
}
|
||||
}
|
||||
else // Add unrecursive mixing.
|
||||
{
|
||||
for (const auto bone : armature->getBones())
|
||||
{
|
||||
if (bone == currentBone)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!currentBone->contains(bone))
|
||||
{
|
||||
boneMask.push_back(bone->getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DRAGONBONES_NAMESPACE_END
|
@@ -0,0 +1,320 @@
|
||||
/**
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2012-2018 DragonBones team and other contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef DRAGONBONES_ANIMATION_CONFIG_H
|
||||
#define DRAGONBONES_ANIMATION_CONFIG_H
|
||||
|
||||
#include "../core/BaseObject.h"
|
||||
|
||||
DRAGONBONES_NAMESPACE_BEGIN
|
||||
/**
|
||||
* - The animation config is used to describe all the information needed to play an animation state.
|
||||
* The API is still in the experimental phase and may encounter bugs or stability or compatibility issues when used.
|
||||
* @see dragonBones.AnimationState
|
||||
* @beta
|
||||
* @version DragonBones 5.0
|
||||
* @language en_US
|
||||
*/
|
||||
/**
|
||||
* - 动画配置用来描述播放一个动画状态所需要的全部信息。
|
||||
* 该 API 仍在实验阶段,使用时可能遭遇 bug 或稳定性或兼容性问题。
|
||||
* @see dragonBones.AnimationState
|
||||
* @beta
|
||||
* @version DragonBones 5.0
|
||||
* @language zh_CN
|
||||
*/
|
||||
class AnimationConfig : public BaseObject
|
||||
{
|
||||
BIND_CLASS_TYPE_A(AnimationConfig);
|
||||
|
||||
public:
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
bool pauseFadeOut;
|
||||
/**
|
||||
* - Fade out the pattern of other animation states when the animation state is fade in.
|
||||
* This property is typically used to specify the substitution of multiple animation states blend.
|
||||
* @default dragonBones.AnimationFadeOutMode.All
|
||||
* @version DragonBones 5.0
|
||||
* @language en_US
|
||||
*/
|
||||
/**
|
||||
* - 淡入动画状态时淡出其他动画状态的模式。
|
||||
* 该属性通常用来指定多个动画状态混合时的相互替换关系。
|
||||
* @default dragonBones.AnimationFadeOutMode.All
|
||||
* @version DragonBones 5.0
|
||||
* @language zh_CN
|
||||
*/
|
||||
AnimationFadeOutMode fadeOutMode;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
TweenType fadeOutTweenType;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
float fadeOutTime;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
bool actionEnabled;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
bool additiveBlending;
|
||||
/**
|
||||
* - Whether the animation state has control over the display property of the slots.
|
||||
* Sometimes blend a animation state does not want it to control the display properties of the slots,
|
||||
* especially if other animation state are controlling the display properties of the slots.
|
||||
* @default true
|
||||
* @version DragonBones 5.0
|
||||
* @language en_US
|
||||
*/
|
||||
/**
|
||||
* - 动画状态是否对插槽的显示对象属性有控制权。
|
||||
* 有时混合一个动画状态并不希望其控制插槽的显示对象属性,
|
||||
* 尤其是其他动画状态正在控制这些插槽的显示对象属性时。
|
||||
* @default true
|
||||
* @version DragonBones 5.0
|
||||
* @language zh_CN
|
||||
*/
|
||||
bool displayControl;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
bool pauseFadeIn;
|
||||
/**
|
||||
* - Whether to reset the objects without animation to the armature pose when the animation state is start to play.
|
||||
* This property should usually be set to false when blend multiple animation states.
|
||||
* @default true
|
||||
* @version DragonBones 5.1
|
||||
* @language en_US
|
||||
*/
|
||||
/**
|
||||
* - 开始播放动画状态时是否将没有动画的对象重置为骨架初始值。
|
||||
* 通常在混合多个动画状态时应该将该属性设置为 false。
|
||||
* @default true
|
||||
* @version DragonBones 5.1
|
||||
* @language zh_CN
|
||||
*/
|
||||
bool resetToPose;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
TweenType fadeInTweenType;
|
||||
/**
|
||||
* - The play times. [0: Loop play, [1~N]: Play N times]
|
||||
* @version DragonBones 3.0
|
||||
* @language en_US
|
||||
*/
|
||||
/**
|
||||
* - 播放次数。 [0: 无限循环播放, [1~N]: 循环播放 N 次]
|
||||
* @version DragonBones 3.0
|
||||
* @language zh_CN
|
||||
*/
|
||||
int playTimes;
|
||||
/**
|
||||
* - The blend layer.
|
||||
* High layer animation state will get the blend weight first.
|
||||
* When the blend weight is assigned more than 1, the remaining animation states will no longer get the weight assigned.
|
||||
* @readonly
|
||||
* @version DragonBones 5.0
|
||||
* @language en_US
|
||||
*/
|
||||
/**
|
||||
* - 混合图层。
|
||||
* 图层高的动画状态会优先获取混合权重。
|
||||
* 当混合权重分配超过 1 时,剩余的动画状态将不再获得权重分配。
|
||||
* @readonly
|
||||
* @version DragonBones 5.0
|
||||
* @language zh_CN
|
||||
*/
|
||||
int layer;
|
||||
/**
|
||||
* - The start time of play. (In seconds)
|
||||
* @default 0.0
|
||||
* @version DragonBones 5.0
|
||||
* @language en_US
|
||||
*/
|
||||
/**
|
||||
* - 播放的开始时间。 (以秒为单位)
|
||||
* @default 0.0
|
||||
* @version DragonBones 5.0
|
||||
* @language zh_CN
|
||||
*/
|
||||
float position;
|
||||
/**
|
||||
* - The duration of play.
|
||||
* [-1: Use the default value of the animation data, 0: Stop play, (0~N]: The duration] (In seconds)
|
||||
* @default -1.0
|
||||
* @version DragonBones 5.0
|
||||
* @language en_US
|
||||
*/
|
||||
/**
|
||||
* - 播放的持续时间。
|
||||
* [-1: 使用动画数据默认值, 0: 动画停止, (0~N]: 持续时间] (以秒为单位)
|
||||
* @default -1.0
|
||||
* @version DragonBones 5.0
|
||||
* @language zh_CN
|
||||
*/
|
||||
float duration;
|
||||
/**
|
||||
* - The play speed.
|
||||
* The value is an overlay relationship with {@link dragonBones.Animation#timeScale}.
|
||||
* [(-N~0): Reverse play, 0: Stop play, (0~1): Slow play, 1: Normal play, (1~N): Fast play]
|
||||
* @default 1.0
|
||||
* @version DragonBones 3.0
|
||||
* @language en_US
|
||||
*/
|
||||
/**
|
||||
* - 播放速度。
|
||||
* 该值与 {@link dragonBones.Animation#timeScale} 是叠加关系。
|
||||
* [(-N~0): 倒转播放, 0: 停止播放, (0~1): 慢速播放, 1: 正常播放, (1~N): 快速播放]
|
||||
* @default 1.0
|
||||
* @version DragonBones 3.0
|
||||
* @language zh_CN
|
||||
*/
|
||||
float timeScale;
|
||||
/**
|
||||
* - The blend weight.
|
||||
* @default 1.0
|
||||
* @version DragonBones 5.0
|
||||
* @language en_US
|
||||
*/
|
||||
/**
|
||||
* - 混合权重。
|
||||
* @default 1.0
|
||||
* @version DragonBones 5.0
|
||||
* @language zh_CN
|
||||
*/
|
||||
float weight;
|
||||
/**
|
||||
* - The fade in time.
|
||||
* [-1: Use the default value of the animation data, [0~N]: The fade in time] (In seconds)
|
||||
* @default -1.0
|
||||
* @version DragonBones 5.0
|
||||
* @language en_US
|
||||
*/
|
||||
/**
|
||||
* - 淡入时间。
|
||||
* [-1: 使用动画数据默认值, [0~N]: 淡入时间] (以秒为单位)
|
||||
* @default -1.0
|
||||
* @version DragonBones 5.0
|
||||
* @language zh_CN
|
||||
*/
|
||||
float fadeInTime;
|
||||
/**
|
||||
* - The auto fade out time when the animation state play completed.
|
||||
* [-1: Do not fade out automatically, [0~N]: The fade out time] (In seconds)
|
||||
* @default -1.0
|
||||
* @version DragonBones 5.0
|
||||
* @language en_US
|
||||
*/
|
||||
/**
|
||||
* - 动画状态播放完成后的自动淡出时间。
|
||||
* [-1: 不自动淡出, [0~N]: 淡出时间] (以秒为单位)
|
||||
* @default -1.0
|
||||
* @version DragonBones 5.0
|
||||
* @language zh_CN
|
||||
*/
|
||||
float autoFadeOutTime;
|
||||
/**
|
||||
* - The name of the animation state. (Can be different from the name of the animation data)
|
||||
* @version DragonBones 5.0
|
||||
* @language en_US
|
||||
*/
|
||||
/**
|
||||
* - 动画状态名称。 (可以不同于动画数据)
|
||||
* @version DragonBones 5.0
|
||||
* @language zh_CN
|
||||
*/
|
||||
std::string name;
|
||||
/**
|
||||
* - The animation data name.
|
||||
* @version DragonBones 5.0
|
||||
* @language en_US
|
||||
*/
|
||||
/**
|
||||
* - 动画数据名称。
|
||||
* @version DragonBones 5.0
|
||||
* @language zh_CN
|
||||
*/
|
||||
std::string animation;
|
||||
/**
|
||||
* - The blend group name of the animation state.
|
||||
* This property is typically used to specify the substitution of multiple animation states blend.
|
||||
* @readonly
|
||||
* @version DragonBones 5.0
|
||||
* @language en_US
|
||||
*/
|
||||
/**
|
||||
* - 混合组名称。
|
||||
* 该属性通常用来指定多个动画状态混合时的相互替换关系。
|
||||
* @readonly
|
||||
* @version DragonBones 5.0
|
||||
* @language zh_CN
|
||||
*/
|
||||
std::string group;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
std::vector<std::string> boneMask;
|
||||
|
||||
protected:
|
||||
virtual void _onClear() override;
|
||||
|
||||
public:
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
void clear();
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
void copyFrom(AnimationConfig* value);
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
bool containsBoneMask(const std::string& boneName) const;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
void addBoneMask(Armature* armature, const std::string& boneName, bool recursive);
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
void removeBoneMask(Armature* armature, const std::string& boneName, bool recursive);
|
||||
|
||||
public: // For WebAssembly.
|
||||
int getFadeOutMode() const { return (int)fadeOutMode; }
|
||||
void setFadeOutMode(int value) { fadeOutMode = (AnimationFadeOutMode)value; }
|
||||
|
||||
int getFadeOutTweenType() const { return (int)fadeOutTweenType; }
|
||||
void setFadeOutTweenType(int value) { fadeOutTweenType = (TweenType)value; }
|
||||
|
||||
int getFadeInTweenType() const { return (int)fadeInTweenType; }
|
||||
void setFadeInTweenType(int value) { fadeInTweenType = (TweenType)value; }
|
||||
};
|
||||
|
||||
DRAGONBONES_NAMESPACE_END
|
||||
#endif // DRAGONBONES_ANIMATION_CONFIG_H
|
@@ -0,0 +1,121 @@
|
||||
#include "AnimationData.h"
|
||||
#include "ArmatureData.h"
|
||||
#include "ConstraintData.h"
|
||||
|
||||
DRAGONBONES_NAMESPACE_BEGIN
|
||||
|
||||
void AnimationData::_onClear()
|
||||
{
|
||||
for (const auto& pair : boneTimelines)
|
||||
{
|
||||
for (const auto timeline : pair.second)
|
||||
{
|
||||
timeline->returnToPool();
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto& pair : slotTimelines)
|
||||
{
|
||||
for (const auto timeline : pair.second)
|
||||
{
|
||||
timeline->returnToPool();
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto& pair : constraintTimelines)
|
||||
{
|
||||
for (const auto timeline : pair.second)
|
||||
{
|
||||
timeline->returnToPool();
|
||||
}
|
||||
}
|
||||
|
||||
if (actionTimeline != nullptr)
|
||||
{
|
||||
actionTimeline->returnToPool();
|
||||
}
|
||||
|
||||
if (zOrderTimeline != nullptr)
|
||||
{
|
||||
zOrderTimeline->returnToPool();
|
||||
}
|
||||
|
||||
frameIntOffset = 0;
|
||||
frameFloatOffset = 0;
|
||||
frameOffset = 0;
|
||||
frameCount = 0;
|
||||
playTimes = 0;
|
||||
duration = 0.0f;
|
||||
scale = 1.0f;
|
||||
fadeInTime = 0.0f;
|
||||
cacheFrameRate = 0.0f;
|
||||
name = "";
|
||||
cachedFrames.clear();
|
||||
boneTimelines.clear();
|
||||
slotTimelines.clear();
|
||||
constraintTimelines.clear();
|
||||
boneCachedFrameIndices.clear();
|
||||
slotCachedFrameIndices.clear();
|
||||
parent = nullptr;
|
||||
actionTimeline = nullptr;
|
||||
zOrderTimeline = nullptr;
|
||||
}
|
||||
|
||||
void AnimationData::cacheFrames(unsigned frameRate)
|
||||
{
|
||||
if (cacheFrameRate > 0.0f) // TODO clear cache.
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
cacheFrameRate = std::max(std::ceil(frameRate * scale), 1.0f);
|
||||
const auto cacheFrameCount = std::ceil(cacheFrameRate * duration) + 1; // Cache one more frame.
|
||||
|
||||
cachedFrames.resize(cacheFrameCount, false);
|
||||
|
||||
for (const auto bone : parent->sortedBones)
|
||||
{
|
||||
boneCachedFrameIndices[bone->name].resize(cacheFrameCount, -1);
|
||||
}
|
||||
|
||||
for (const auto slot : parent->sortedSlots)
|
||||
{
|
||||
slotCachedFrameIndices[slot->name].resize(cacheFrameCount, -1);
|
||||
}
|
||||
}
|
||||
|
||||
void AnimationData::addBoneTimeline(BoneData* bone, TimelineData* value)
|
||||
{
|
||||
auto& timelines = boneTimelines[bone->name];
|
||||
if(std::find(timelines.cbegin(), timelines.cend(), value) == timelines.cend())
|
||||
{
|
||||
timelines.push_back(value);
|
||||
}
|
||||
}
|
||||
|
||||
void AnimationData::addSlotTimeline(SlotData* slot, TimelineData* value)
|
||||
{
|
||||
auto& timelines = slotTimelines[slot->name];
|
||||
if (std::find(timelines.cbegin(), timelines.cend(), value) == timelines.cend())
|
||||
{
|
||||
timelines.push_back(value);
|
||||
}
|
||||
}
|
||||
|
||||
void AnimationData::addConstraintTimeline(ConstraintData* constraint, TimelineData* value)
|
||||
{
|
||||
auto& timelines = constraintTimelines[constraint->name];
|
||||
if (std::find(timelines.cbegin(), timelines.cend(), value) == timelines.cend())
|
||||
{
|
||||
timelines.push_back(value);
|
||||
}
|
||||
}
|
||||
|
||||
void TimelineData::_onClear()
|
||||
{
|
||||
type = TimelineType::BoneAll;
|
||||
offset = 0;
|
||||
frameIndicesOffset = -1;
|
||||
}
|
||||
|
||||
DRAGONBONES_NAMESPACE_END
|
256
cocos2d-x/cocos/editor-support/dragonbones/model/AnimationData.h
Normal file
256
cocos2d-x/cocos/editor-support/dragonbones/model/AnimationData.h
Normal file
@@ -0,0 +1,256 @@
|
||||
/**
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2012-2018 DragonBones team and other contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef DRAGONBONES_ANIMATION_DATA_H
|
||||
#define DRAGONBONES_ANIMATION_DATA_H
|
||||
|
||||
#include "ArmatureData.h"
|
||||
|
||||
DRAGONBONES_NAMESPACE_BEGIN
|
||||
/**
|
||||
* - The animation data.
|
||||
* @version DragonBones 3.0
|
||||
* @language en_US
|
||||
*/
|
||||
/**
|
||||
* - 动画数据。
|
||||
* @version DragonBones 3.0
|
||||
* @language zh_CN
|
||||
*/
|
||||
class AnimationData : public BaseObject
|
||||
{
|
||||
BIND_CLASS_TYPE_B(AnimationData);
|
||||
|
||||
public:
|
||||
/**
|
||||
* - FrameIntArray.
|
||||
* @internal
|
||||
*/
|
||||
unsigned frameIntOffset;
|
||||
/**
|
||||
* - FrameFloatArray.
|
||||
* @internal
|
||||
*/
|
||||
unsigned frameFloatOffset;
|
||||
/**
|
||||
* - FrameArray.
|
||||
* @internal
|
||||
*/
|
||||
unsigned frameOffset;
|
||||
/**
|
||||
* - The frame count of the animation.
|
||||
* @version DragonBones 3.0
|
||||
* @language en_US
|
||||
*/
|
||||
/**
|
||||
* - 动画的帧数。
|
||||
* @version DragonBones 3.0
|
||||
* @language zh_CN
|
||||
*/
|
||||
unsigned frameCount;
|
||||
/**
|
||||
* - The play times of the animation. [0: Loop play, [1~N]: Play N times]
|
||||
* @version DragonBones 3.0
|
||||
* @language en_US
|
||||
*/
|
||||
/**
|
||||
* - 动画的播放次数。 [0: 无限循环播放, [1~N]: 循环播放 N 次]
|
||||
* @version DragonBones 3.0
|
||||
* @language zh_CN
|
||||
*/
|
||||
unsigned playTimes;
|
||||
/**
|
||||
* - The duration of the animation. (In seconds)
|
||||
* @version DragonBones 3.0
|
||||
* @language en_US
|
||||
*/
|
||||
/**
|
||||
* - 动画的持续时间。 (以秒为单位)
|
||||
* @version DragonBones 3.0
|
||||
* @language zh_CN
|
||||
*/
|
||||
float duration;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
float scale;
|
||||
/**
|
||||
* - The fade in time of the animation. (In seconds)
|
||||
* @version DragonBones 3.0
|
||||
* @language en_US
|
||||
*/
|
||||
/**
|
||||
* - 动画的淡入时间。 (以秒为单位)
|
||||
* @version DragonBones 3.0
|
||||
* @language zh_CN
|
||||
*/
|
||||
float fadeInTime;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
float cacheFrameRate;
|
||||
/**
|
||||
* - The animation name.
|
||||
* @version DragonBones 3.0
|
||||
* @language en_US
|
||||
*/
|
||||
/**
|
||||
* - 动画名称。
|
||||
* @version DragonBones 3.0
|
||||
* @language zh_CN
|
||||
*/
|
||||
std::string name;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
std::vector<bool> cachedFrames;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
std::map<std::string, std::vector<TimelineData*>> boneTimelines;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
std::map<std::string, std::vector<TimelineData*>> slotTimelines;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
std::map<std::string, std::vector<TimelineData*>> constraintTimelines;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
std::map<std::string, std::vector<int>> boneCachedFrameIndices;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
std::map<std::string, std::vector<int>> slotCachedFrameIndices;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
TimelineData* actionTimeline;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
TimelineData* zOrderTimeline;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
ArmatureData* parent;
|
||||
AnimationData() :
|
||||
actionTimeline(nullptr),
|
||||
zOrderTimeline(nullptr)
|
||||
{
|
||||
_onClear();
|
||||
}
|
||||
~AnimationData()
|
||||
{
|
||||
_onClear();
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void _onClear() override;
|
||||
|
||||
public:
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
void cacheFrames(unsigned frameRate);
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
void addBoneTimeline(BoneData* bone, TimelineData* value);
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
void addSlotTimeline(SlotData* slot, TimelineData* value);
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
void addConstraintTimeline(ConstraintData* constraint, TimelineData* value);
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
std::vector<TimelineData*>* getBoneTimelines(const std::string& timelineName)
|
||||
{
|
||||
return mapFindB(boneTimelines, timelineName);
|
||||
}
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
inline std::vector<TimelineData*>* getSlotTimelines(const std::string& timelineName)
|
||||
{
|
||||
return mapFindB(slotTimelines, timelineName);
|
||||
}
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
inline std::vector<TimelineData*>* getConstraintTimelines(const std::string& timelineName)
|
||||
{
|
||||
return mapFindB(constraintTimelines, timelineName);
|
||||
}
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
inline std::vector<int>* getBoneCachedFrameIndices(const std::string& boneName)
|
||||
{
|
||||
return mapFindB(boneCachedFrameIndices, boneName);
|
||||
}
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
inline std::vector<int>* getSlotCachedFrameIndices(const std::string& slotName)
|
||||
{
|
||||
return mapFindB(slotCachedFrameIndices, slotName);
|
||||
}
|
||||
|
||||
public: // For WebAssembly.
|
||||
TimelineData* getActionTimeline() const { return actionTimeline; }
|
||||
void setActionTimeline(TimelineData* pactionTimeline) { actionTimeline = pactionTimeline; }
|
||||
|
||||
TimelineData* getZOrderTimeline() const { return zOrderTimeline; }
|
||||
void setZOrderTimeline(TimelineData* value) { zOrderTimeline = value; }
|
||||
|
||||
ArmatureData* getParent() const { return parent; }
|
||||
void setParent(ArmatureData* value) { parent = value; }
|
||||
};
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
class TimelineData : public BaseObject
|
||||
{
|
||||
BIND_CLASS_TYPE_A(TimelineData);
|
||||
|
||||
public:
|
||||
TimelineType type;
|
||||
unsigned offset;
|
||||
int frameIndicesOffset;
|
||||
|
||||
protected:
|
||||
virtual void _onClear() override;
|
||||
|
||||
public: // For WebAssembly.
|
||||
int getType() const { return (int)type; }
|
||||
void setType(int value) { type = (TimelineType)value; }
|
||||
};
|
||||
|
||||
DRAGONBONES_NAMESPACE_END
|
||||
#endif // DRAGONBONES_ANIMATION_DATA_H
|
@@ -0,0 +1,320 @@
|
||||
#include "ArmatureData.h"
|
||||
#include "UserData.h"
|
||||
#include "DragonBonesData.h"
|
||||
#include "ConstraintData.h"
|
||||
#include "CanvasData.h"
|
||||
#include "SkinData.h"
|
||||
#include "DisplayData.h"
|
||||
#include "AnimationData.h"
|
||||
|
||||
DRAGONBONES_NAMESPACE_BEGIN
|
||||
|
||||
void ArmatureData::_onClear()
|
||||
{
|
||||
for (const auto action : defaultActions)
|
||||
{
|
||||
action->returnToPool();
|
||||
}
|
||||
|
||||
for (const auto action : actions)
|
||||
{
|
||||
action->returnToPool();
|
||||
}
|
||||
|
||||
for (const auto& pair : bones)
|
||||
{
|
||||
pair.second->returnToPool();
|
||||
}
|
||||
|
||||
for (const auto& pair : slots)
|
||||
{
|
||||
pair.second->returnToPool();
|
||||
}
|
||||
|
||||
for (const auto& pair : constraints)
|
||||
{
|
||||
pair.second->returnToPool();
|
||||
}
|
||||
|
||||
for (const auto& pair : skins)
|
||||
{
|
||||
pair.second->returnToPool();
|
||||
}
|
||||
|
||||
for (const auto& pair : animations)
|
||||
{
|
||||
pair.second->returnToPool();
|
||||
}
|
||||
|
||||
if (canvas != nullptr)
|
||||
{
|
||||
canvas->returnToPool();
|
||||
}
|
||||
|
||||
if (userData != nullptr)
|
||||
{
|
||||
userData->returnToPool();
|
||||
}
|
||||
|
||||
type = ArmatureType::Armature;
|
||||
frameRate = 0;
|
||||
cacheFrameRate = 0;
|
||||
scale = 1.0f;
|
||||
name = "";
|
||||
aabb.clear();
|
||||
animationNames.clear();
|
||||
sortedBones.clear();
|
||||
sortedSlots.clear();
|
||||
defaultActions.clear();
|
||||
actions.clear();
|
||||
bones.clear();
|
||||
slots.clear();
|
||||
constraints.clear();
|
||||
skins.clear();
|
||||
animations.clear();
|
||||
parent = nullptr;
|
||||
defaultSkin = nullptr;
|
||||
defaultAnimation = nullptr;
|
||||
canvas = nullptr;
|
||||
userData = nullptr;
|
||||
}
|
||||
|
||||
void ArmatureData::sortBones()
|
||||
{
|
||||
const auto total = sortedBones.size();
|
||||
if (total <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const auto sortHelper = sortedBones; // Copy.
|
||||
unsigned index = 0;
|
||||
unsigned count = 0;
|
||||
sortedBones.clear();
|
||||
while (count < total)
|
||||
{
|
||||
const auto bone = sortHelper[index++];
|
||||
if (index >= total)
|
||||
{
|
||||
index = 0;
|
||||
}
|
||||
|
||||
if (std::find(sortedBones.cbegin(), sortedBones.cend(), bone) != sortedBones.cend())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
auto flag = false;
|
||||
for(const auto& pair : constraints)
|
||||
{
|
||||
const auto constrait = pair.second;
|
||||
if(constrait->root == bone && std::find(sortedBones.cbegin(), sortedBones.cend(), constrait->target) == sortedBones.cend())
|
||||
{
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(flag)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (bone->parent != nullptr && std::find(sortedBones.cbegin(), sortedBones.cend(), bone->parent) == sortedBones.cend())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
sortedBones.push_back(bone);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
void ArmatureData::cacheFrames(unsigned value)
|
||||
{
|
||||
if (cacheFrameRate > value) // TODO clear cache.
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
cacheFrameRate = value;
|
||||
for (const auto& pair : animations)
|
||||
{
|
||||
pair.second->cacheFrames(cacheFrameRate);
|
||||
}
|
||||
}
|
||||
|
||||
int ArmatureData::setCacheFrame(const Matrix& globalTransformMatrix, const Transform& transform)
|
||||
{
|
||||
auto& dataArray = *&parent->cachedFrames;
|
||||
auto arrayOffset = dataArray.size();
|
||||
|
||||
dataArray.resize(arrayOffset + 10);
|
||||
dataArray[arrayOffset] = globalTransformMatrix.a;
|
||||
dataArray[arrayOffset + 1] = globalTransformMatrix.b;
|
||||
dataArray[arrayOffset + 2] = globalTransformMatrix.c;
|
||||
dataArray[arrayOffset + 3] = globalTransformMatrix.d;
|
||||
dataArray[arrayOffset + 4] = globalTransformMatrix.tx;
|
||||
dataArray[arrayOffset + 5] = globalTransformMatrix.ty;
|
||||
dataArray[arrayOffset + 6] = transform.rotation;
|
||||
dataArray[arrayOffset + 7] = transform.skew;
|
||||
dataArray[arrayOffset + 8] = transform.scaleX;
|
||||
dataArray[arrayOffset + 9] = transform.scaleY;
|
||||
|
||||
return arrayOffset;
|
||||
}
|
||||
|
||||
void ArmatureData::getCacheFrame(Matrix& globalTransformMatrix, Transform& transform, unsigned arrayOffset) const
|
||||
{
|
||||
auto& dataArray = *&parent->cachedFrames;
|
||||
globalTransformMatrix.a = dataArray[arrayOffset];
|
||||
globalTransformMatrix.b = dataArray[arrayOffset + 1];
|
||||
globalTransformMatrix.c = dataArray[arrayOffset + 2];
|
||||
globalTransformMatrix.d = dataArray[arrayOffset + 3];
|
||||
globalTransformMatrix.tx = dataArray[arrayOffset + 4];
|
||||
globalTransformMatrix.ty = dataArray[arrayOffset + 5];
|
||||
transform.rotation = dataArray[arrayOffset + 6];
|
||||
transform.skew = dataArray[arrayOffset + 7];
|
||||
transform.scaleX = dataArray[arrayOffset + 8];
|
||||
transform.scaleY = dataArray[arrayOffset + 9];
|
||||
transform.x = globalTransformMatrix.tx;
|
||||
transform.y = globalTransformMatrix.ty;
|
||||
}
|
||||
|
||||
void ArmatureData::addBone(BoneData* value)
|
||||
{
|
||||
if (bones.find(value->name) != bones.cend())
|
||||
{
|
||||
DRAGONBONES_ASSERT(false, "Same bone: " + value->name);
|
||||
return;
|
||||
}
|
||||
|
||||
bones[value->name] = value;
|
||||
sortedBones.push_back(value);
|
||||
}
|
||||
|
||||
void ArmatureData::addSlot(SlotData* value)
|
||||
{
|
||||
if (slots.find(value->name) != slots.cend())
|
||||
{
|
||||
DRAGONBONES_ASSERT(false, "Same slot: " + value->name);
|
||||
return;
|
||||
}
|
||||
|
||||
slots[value->name] = value;
|
||||
sortedSlots.push_back(value);
|
||||
}
|
||||
|
||||
void ArmatureData::addConstraint(ConstraintData * value)
|
||||
{
|
||||
if (constraints.find(value->name) != constraints.cend())
|
||||
{
|
||||
DRAGONBONES_ASSERT(false, "Same constaint: " + value->name);
|
||||
return;
|
||||
}
|
||||
|
||||
constraints[value->name] = value;
|
||||
}
|
||||
|
||||
void ArmatureData::addSkin(SkinData* value)
|
||||
{
|
||||
if (skins.find(value->name) != skins.cend())
|
||||
{
|
||||
DRAGONBONES_ASSERT(false, "Same skin: " + value->name);
|
||||
return;
|
||||
}
|
||||
|
||||
value->parent = this;
|
||||
skins[value->name] = value;
|
||||
|
||||
if (defaultSkin == nullptr)
|
||||
{
|
||||
defaultSkin = value;
|
||||
}
|
||||
}
|
||||
|
||||
void ArmatureData::addAnimation(AnimationData* value)
|
||||
{
|
||||
if (animations.find(value->name) != animations.cend())
|
||||
{
|
||||
DRAGONBONES_ASSERT(false, "Same animation: " + value->name);
|
||||
return;
|
||||
}
|
||||
|
||||
value->parent = this;
|
||||
animations[value->name] = value;
|
||||
animationNames.push_back(value->name);
|
||||
if (defaultAnimation == nullptr)
|
||||
{
|
||||
defaultAnimation = value;
|
||||
}
|
||||
}
|
||||
|
||||
void ArmatureData::addAction(ActionData* value, bool isDefault)
|
||||
{
|
||||
if (isDefault)
|
||||
{
|
||||
defaultActions.push_back(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
actions.push_back(value);
|
||||
}
|
||||
}
|
||||
|
||||
MeshDisplayData* ArmatureData::getMesh(const std::string& skinName, const std::string& slotName, const std::string& meshName) const
|
||||
{
|
||||
const auto skin = getSkin(skinName);
|
||||
if (skin == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return static_cast<MeshDisplayData*>(skin->getDisplay(slotName, meshName));
|
||||
}
|
||||
|
||||
void BoneData::_onClear()
|
||||
{
|
||||
if (userData != nullptr)
|
||||
{
|
||||
userData->returnToPool();
|
||||
}
|
||||
|
||||
inheritTranslation = false;
|
||||
inheritRotation = false;
|
||||
inheritScale = false;
|
||||
inheritReflection = false;
|
||||
length = 0.0f;
|
||||
name = "";
|
||||
transform.identity();
|
||||
parent = nullptr;
|
||||
userData = nullptr;
|
||||
}
|
||||
|
||||
ColorTransform SlotData::DEFAULT_COLOR;
|
||||
ColorTransform* SlotData::createColor()
|
||||
{
|
||||
return new ColorTransform();
|
||||
}
|
||||
|
||||
void SlotData::_onClear()
|
||||
{
|
||||
if (userData != nullptr)
|
||||
{
|
||||
userData->returnToPool();
|
||||
}
|
||||
|
||||
if (color != nullptr && color != &DEFAULT_COLOR)
|
||||
{
|
||||
delete color;
|
||||
}
|
||||
|
||||
blendMode = BlendMode::Normal;
|
||||
displayIndex = 0;
|
||||
zOrder = 0;
|
||||
name = "";
|
||||
parent = nullptr;
|
||||
color = nullptr;
|
||||
userData = nullptr;
|
||||
}
|
||||
|
||||
DRAGONBONES_NAMESPACE_END
|
513
cocos2d-x/cocos/editor-support/dragonbones/model/ArmatureData.h
Normal file
513
cocos2d-x/cocos/editor-support/dragonbones/model/ArmatureData.h
Normal file
@@ -0,0 +1,513 @@
|
||||
/**
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2012-2018 DragonBones team and other contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef DRAGONBONES_ARMATURE_DATA_H
|
||||
#define DRAGONBONES_ARMATURE_DATA_H
|
||||
|
||||
#include "../core/BaseObject.h"
|
||||
#include "../geom/Matrix.h"
|
||||
#include "../geom/Transform.h"
|
||||
#include "../geom/ColorTransform.h"
|
||||
#include "../geom/Rectangle.h"
|
||||
|
||||
DRAGONBONES_NAMESPACE_BEGIN
|
||||
/**
|
||||
* - The armature data.
|
||||
* @version DragonBones 3.0
|
||||
* @language en_US
|
||||
*/
|
||||
/**
|
||||
* - 骨架数据。
|
||||
* @version DragonBones 3.0
|
||||
* @language zh_CN
|
||||
*/
|
||||
class ArmatureData : public BaseObject
|
||||
{
|
||||
BIND_CLASS_TYPE_B(ArmatureData);
|
||||
|
||||
public:
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
ArmatureType type;
|
||||
/**
|
||||
* - The animation frame rate.
|
||||
* @version DragonBones 3.0
|
||||
* @language en_US
|
||||
*/
|
||||
/**
|
||||
* - 动画帧率。
|
||||
* @version DragonBones 3.0
|
||||
* @language zh_CN
|
||||
*/
|
||||
unsigned frameRate;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
unsigned cacheFrameRate;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
float scale;
|
||||
/**
|
||||
* - The armature name.
|
||||
* @version DragonBones 3.0
|
||||
* @language en_US
|
||||
*/
|
||||
/**
|
||||
* - 骨架名称。
|
||||
* @version DragonBones 3.0
|
||||
* @language zh_CN
|
||||
*/
|
||||
std::string name;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
Rectangle aabb;
|
||||
/**
|
||||
* - The names of all the animation data.
|
||||
* @version DragonBones 3.0
|
||||
* @language en_US
|
||||
*/
|
||||
/**
|
||||
* - 所有的动画数据名称。
|
||||
* @version DragonBones 3.0
|
||||
* @language zh_CN
|
||||
*/
|
||||
std::vector<std::string> animationNames;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
std::vector<BoneData*> sortedBones;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
std::vector<SlotData*> sortedSlots;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
std::vector<ActionData*> defaultActions;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
std::vector<ActionData*> actions;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
std::map<std::string, BoneData*> bones;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
std::map<std::string, SlotData*> slots;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
std::map<std::string, ConstraintData*> constraints;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
std::map<std::string, SkinData*> skins;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
std::map<std::string, AnimationData*> animations;
|
||||
/**
|
||||
* - The default skin data.
|
||||
* @version DragonBones 4.5
|
||||
* @language en_US
|
||||
*/
|
||||
/**
|
||||
* - 默认插槽数据。
|
||||
* @version DragonBones 4.5
|
||||
* @language zh_CN
|
||||
*/
|
||||
SkinData* defaultSkin;
|
||||
/**
|
||||
* - The default animation data.
|
||||
* @version DragonBones 4.5
|
||||
* @language en_US
|
||||
*/
|
||||
/**
|
||||
* - 默认动画数据。
|
||||
* @version DragonBones 4.5
|
||||
* @language zh_CN
|
||||
*/
|
||||
AnimationData* defaultAnimation;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
CanvasData* canvas;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
UserData* userData;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
DragonBonesData* parent;
|
||||
ArmatureData() :
|
||||
canvas(nullptr),
|
||||
userData(nullptr)
|
||||
{
|
||||
_onClear();
|
||||
}
|
||||
~ArmatureData()
|
||||
{
|
||||
_onClear();
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void _onClear() override;
|
||||
|
||||
public:
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
void sortBones();
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
void cacheFrames(unsigned frameRate);
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
int setCacheFrame(const Matrix& globalTransformMatrix, const Transform& transform);
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
void getCacheFrame(Matrix& globalTransformMatrix, Transform& transform, unsigned arrayOffset) const;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
void addBone(BoneData* value);
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
void addSlot(SlotData* value);
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
void addConstraint(ConstraintData* value);
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
void addSkin(SkinData* value);
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
void addAnimation(AnimationData* value);
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
void addAction(ActionData* value, bool isDefault);
|
||||
/**
|
||||
* - Get a specific done data.
|
||||
* @param boneName - The bone name.
|
||||
* @version DragonBones 3.0
|
||||
* @language en_US
|
||||
*/
|
||||
/**
|
||||
* - 获取特定的骨骼数据。
|
||||
* @param boneName - 骨骼名称。
|
||||
* @version DragonBones 3.0
|
||||
* @language zh_CN
|
||||
*/
|
||||
inline BoneData* getBone(const std::string& boneName) const
|
||||
{
|
||||
return mapFind<BoneData>(bones, boneName);
|
||||
}
|
||||
/**
|
||||
* - Get a specific slot data.
|
||||
* @param slotName - The slot name.
|
||||
* @version DragonBones 3.0
|
||||
* @language en_US
|
||||
*/
|
||||
/**
|
||||
* - 获取特定的插槽数据。
|
||||
* @param slotName - 插槽名称。
|
||||
* @version DragonBones 3.0
|
||||
* @language zh_CN
|
||||
*/
|
||||
inline SlotData* getSlot(const std::string& slotName) const
|
||||
{
|
||||
return mapFind<SlotData>(slots, slotName);
|
||||
}
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
inline ConstraintData* getConstraint(const std::string& constraintName) const
|
||||
{
|
||||
return mapFind<ConstraintData>(constraints, constraintName);
|
||||
}
|
||||
/**
|
||||
* - Get a specific skin data.
|
||||
* @param skinName - The skin name.
|
||||
* @version DragonBones 3.0
|
||||
* @language en_US
|
||||
*/
|
||||
/**
|
||||
* - 获取特定皮肤数据。
|
||||
* @param skinName - 皮肤名称。
|
||||
* @version DragonBones 3.0
|
||||
* @language zh_CN
|
||||
*/
|
||||
inline SkinData* getSkin(const std::string& skinName) const
|
||||
{
|
||||
return mapFind(skins, skinName);
|
||||
}
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
MeshDisplayData* getMesh(const std::string& skinName, const std::string& slotName, const std::string& meshName) const;
|
||||
/**
|
||||
* - Get a specific animation data.
|
||||
* @param animationName - The animation animationName.
|
||||
* @version DragonBones 3.0
|
||||
* @language en_US
|
||||
*/
|
||||
/**
|
||||
* - 获取特定的动画数据。
|
||||
* @param animationName - 动画名称。
|
||||
* @version DragonBones 3.0
|
||||
* @language zh_CN
|
||||
*/
|
||||
inline AnimationData* getAnimation(const std::string& animationName) const
|
||||
{
|
||||
return mapFind(animations, animationName);
|
||||
}
|
||||
|
||||
public: // For WebAssembly.
|
||||
int getType() const { return (int)type; }
|
||||
void setType(int value) { type = (ArmatureType)value; }
|
||||
|
||||
Rectangle* getAABB() { return &aabb; }
|
||||
const std::vector<std::string>& getAnimationNames() const { return animationNames; }
|
||||
const std::vector<BoneData*>& getSortedBones() const { return sortedBones; }
|
||||
const std::vector<SlotData*>& getSortedSlots() const { return sortedSlots; }
|
||||
const std::vector<ActionData*>& getDefaultActions() const { return defaultActions; }
|
||||
const std::vector<ActionData*>& getActions() const { return actions; }
|
||||
|
||||
SkinData* getDefaultSkin() const { return defaultSkin; }
|
||||
void setDefaultSkin(SkinData* value) { defaultSkin = value; }
|
||||
|
||||
AnimationData* getDefaultAnimation() const { return defaultAnimation; }
|
||||
void setDefaultAnimation(AnimationData* value) { defaultAnimation = value; }
|
||||
|
||||
const UserData* getUserData() const { return userData; }
|
||||
void setUserData(UserData* value) { userData = value; }
|
||||
|
||||
const DragonBonesData* getParent() const { return parent; }
|
||||
void setParent(DragonBonesData* value) { parent = value; }
|
||||
};
|
||||
/**
|
||||
* - The bone data.
|
||||
* @version DragonBones 3.0
|
||||
* @language en_US
|
||||
*/
|
||||
/**
|
||||
* - 骨骼数据。
|
||||
* @version DragonBones 3.0
|
||||
* @language zh_CN
|
||||
*/
|
||||
class BoneData : public BaseObject
|
||||
{
|
||||
BIND_CLASS_TYPE_B(BoneData);
|
||||
|
||||
public:
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
bool inheritTranslation;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
bool inheritRotation;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
bool inheritScale;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
bool inheritReflection;
|
||||
/**
|
||||
* - The bone length.
|
||||
* @version DragonBones 3.0
|
||||
* @language en_US
|
||||
*/
|
||||
/**
|
||||
* - 骨骼长度。
|
||||
* @version DragonBones 3.0
|
||||
* @language zh_CN
|
||||
*/
|
||||
float length;
|
||||
/**
|
||||
* - The bone name.
|
||||
* @version DragonBones 3.0
|
||||
* @language en_US
|
||||
*/
|
||||
/**
|
||||
* - 骨骼名称。
|
||||
* @version DragonBones 3.0
|
||||
* @language zh_CN
|
||||
*/
|
||||
std::string name;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
Transform transform;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
UserData* userData;
|
||||
/**
|
||||
* - The parent bone data.
|
||||
* @version DragonBones 3.0
|
||||
* @language en_US
|
||||
*/
|
||||
/**
|
||||
* - 父骨骼数据。
|
||||
* @version DragonBones 3.0
|
||||
* @language zh_CN
|
||||
*/
|
||||
BoneData* parent;
|
||||
BoneData() :
|
||||
userData(nullptr)
|
||||
{
|
||||
_onClear();
|
||||
}
|
||||
~BoneData()
|
||||
{
|
||||
_onClear();
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void _onClear() override;
|
||||
|
||||
public: // For WebAssembly.
|
||||
Transform* getTransfrom() { return &transform; }
|
||||
|
||||
const UserData* getUserData() const { return userData; }
|
||||
void setUserData(UserData* value) { userData = value; }
|
||||
|
||||
const BoneData* getParent() const { return parent; }
|
||||
void setParent(BoneData* value) { parent = value; }
|
||||
};
|
||||
/**
|
||||
* - The slot data.
|
||||
* @version DragonBones 3.0
|
||||
* @language en_US
|
||||
*/
|
||||
/**
|
||||
* - 插槽数据。
|
||||
* @version DragonBones 3.0
|
||||
* @language zh_CN
|
||||
*/
|
||||
class SlotData : public BaseObject
|
||||
{
|
||||
BIND_CLASS_TYPE_B(SlotData);
|
||||
|
||||
public:
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
static ColorTransform DEFAULT_COLOR;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
static ColorTransform* createColor();
|
||||
|
||||
public:
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
BlendMode blendMode;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
int displayIndex;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
int zOrder;
|
||||
/**
|
||||
* - The slot name.
|
||||
* @version DragonBones 3.0
|
||||
* @language en_US
|
||||
*/
|
||||
/**
|
||||
* - 插槽名称。
|
||||
* @version DragonBones 3.0
|
||||
* @language zh_CN
|
||||
*/
|
||||
std::string name;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
ColorTransform* color;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
UserData* userData;
|
||||
/**
|
||||
* - The parent bone data.
|
||||
* @version DragonBones 3.0
|
||||
* @language en_US
|
||||
*/
|
||||
/**
|
||||
* - 父骨骼数据。
|
||||
* @version DragonBones 3.0
|
||||
* @language zh_CN
|
||||
*/
|
||||
BoneData* parent;
|
||||
SlotData() :
|
||||
color(nullptr),
|
||||
userData(nullptr)
|
||||
{
|
||||
_onClear();
|
||||
}
|
||||
~SlotData()
|
||||
{
|
||||
_onClear();
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void _onClear() override;
|
||||
|
||||
public: // For WebAssembly.
|
||||
static ColorTransform* getDefaultColor() { return &DEFAULT_COLOR; }
|
||||
|
||||
int getBlendMode() const { return (int)blendMode; }
|
||||
void setBlendMode(int value) { blendMode = (BlendMode)value; }
|
||||
|
||||
ColorTransform* getColor() const { return color; }
|
||||
void setColor(ColorTransform* value) { color = value; }
|
||||
|
||||
const BoneData* getParent() const { return parent; }
|
||||
void setParent(BoneData* value) { parent = value; }
|
||||
|
||||
const UserData* getUserData() const { return userData; }
|
||||
void setUserData(UserData* value) { userData = value; }
|
||||
};
|
||||
|
||||
DRAGONBONES_NAMESPACE_END
|
||||
#endif // DRAGONBONES_ARMATURE_DATA_H
|
@@ -0,0 +1,644 @@
|
||||
|
||||
#include "BoundingBoxData.h"
|
||||
#include "DisplayData.h"
|
||||
|
||||
|
||||
DRAGONBONES_NAMESPACE_BEGIN
|
||||
|
||||
void BoundingBoxData::_onClear()
|
||||
{
|
||||
color = 0x000000;
|
||||
width = 0.0f;
|
||||
height = 0.0f;
|
||||
}
|
||||
|
||||
int RectangleBoundingBoxData::_computeOutCode(float x, float y, float xMin, float yMin, float xMax, float yMax)
|
||||
{
|
||||
int code = OutCode::InSide; // initialised as being inside of [[clip window]]
|
||||
|
||||
if (x < xMin) // to the left of clip window
|
||||
{
|
||||
code |= OutCode::Left;
|
||||
}
|
||||
else if (x > xMax) // to the right of clip window
|
||||
{
|
||||
code |= OutCode::Right;
|
||||
}
|
||||
|
||||
if (y < yMin) // below the clip window
|
||||
{
|
||||
code |= OutCode::Top;
|
||||
}
|
||||
else if (y > yMax) // above the clip window
|
||||
{
|
||||
code |= OutCode::Bottom;
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
int RectangleBoundingBoxData::rectangleIntersectsSegment(
|
||||
float xA, float yA, float xB, float yB,
|
||||
float xMin, float yMin, float xMax, float yMax,
|
||||
Point* intersectionPointA,
|
||||
Point* intersectionPointB,
|
||||
Point* normalRadians
|
||||
)
|
||||
{
|
||||
const auto inSideA = xA > xMin && xA < xMax && yA > yMin && yA < yMax;
|
||||
const auto inSideB = xB > xMin && xB < xMax && yB > yMin && yB < yMax;
|
||||
|
||||
if (inSideA && inSideB)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
auto intersectionCount = 0;
|
||||
auto outcode0 = RectangleBoundingBoxData::_computeOutCode(xA, yA, xMin, yMin, xMax, yMax);
|
||||
auto outcode1 = RectangleBoundingBoxData::_computeOutCode(xB, yB, xMin, yMin, xMax, yMax);
|
||||
|
||||
while (true)
|
||||
{
|
||||
if ((outcode0 | outcode1) == 0) // Bitwise OR is 0. Trivially accept and get out of loop
|
||||
{
|
||||
intersectionCount = 2;
|
||||
break;
|
||||
}
|
||||
else if ((outcode0 & outcode1) != 0) // Bitwise AND is not 0. Trivially reject and get out of loop
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
// failed both tests, so calculate the line segment to clip
|
||||
// from an outside point to an intersection with clip edge
|
||||
auto x = 0.0f;
|
||||
auto y = 0.0f;
|
||||
auto normalRadian = 0.0f;
|
||||
|
||||
// At least one endpoint is outside the clip rectangle; pick it.
|
||||
const auto outcodeOut = outcode0 != 0 ? outcode0 : outcode1;
|
||||
|
||||
// Now find the intersection point;
|
||||
if ((outcodeOut & OutCode::Top) != 0) // point is above the clip rectangle
|
||||
{
|
||||
x = xA + (xB - xA) * (yMin - yA) / (yB - yA);
|
||||
y = yMin;
|
||||
|
||||
if (normalRadians != nullptr)
|
||||
{
|
||||
normalRadian = -Transform::PI * 0.5f;
|
||||
}
|
||||
}
|
||||
else if ((outcodeOut & OutCode::Bottom) != 0) // point is below the clip rectangle
|
||||
{
|
||||
x = xA + (xB - xA) * (yMax - yA) / (yB - yA);
|
||||
y = yMax;
|
||||
|
||||
if (normalRadians != nullptr)
|
||||
{
|
||||
normalRadian = Transform::PI * 0.5;
|
||||
}
|
||||
}
|
||||
else if ((outcodeOut & OutCode::Right) != 0) // point is to the right of clip rectangle
|
||||
{
|
||||
y = yA + (yB - yA) * (xMax - xA) / (xB - xA);
|
||||
x = xMax;
|
||||
|
||||
if (normalRadians != nullptr)
|
||||
{
|
||||
normalRadian = 0;
|
||||
}
|
||||
}
|
||||
else if ((outcodeOut & OutCode::Left) != 0) // point is to the left of clip rectangle
|
||||
{
|
||||
y = yA + (yB - yA) * (xMin - xA) / (xB - xA);
|
||||
x = xMin;
|
||||
|
||||
if (normalRadians != nullptr)
|
||||
{
|
||||
normalRadian = Transform::PI;
|
||||
}
|
||||
}
|
||||
|
||||
// Now we move outside point to intersection point to clip
|
||||
// and get ready for next pass.
|
||||
if (outcodeOut == outcode0)
|
||||
{
|
||||
xA = x;
|
||||
yA = y;
|
||||
outcode0 = RectangleBoundingBoxData::_computeOutCode(xA, yA, xMin, yMin, xMax, yMax);
|
||||
|
||||
if (normalRadians != nullptr)
|
||||
{
|
||||
normalRadians->x = normalRadian;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
xB = x;
|
||||
yB = y;
|
||||
outcode1 = RectangleBoundingBoxData::_computeOutCode(xB, yB, xMin, yMin, xMax, yMax);
|
||||
|
||||
if (normalRadians != nullptr)
|
||||
{
|
||||
normalRadians->y = normalRadian;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (intersectionCount)
|
||||
{
|
||||
if (inSideA)
|
||||
{
|
||||
intersectionCount = 2; // 10
|
||||
|
||||
if (intersectionPointA != nullptr)
|
||||
{
|
||||
intersectionPointA->x = xB;
|
||||
intersectionPointA->y = yB;
|
||||
}
|
||||
|
||||
if (intersectionPointB != nullptr)
|
||||
{
|
||||
intersectionPointB->x = xB;
|
||||
intersectionPointB->y = xB;
|
||||
}
|
||||
|
||||
if (normalRadians != nullptr)
|
||||
{
|
||||
normalRadians->x = normalRadians->y + Transform::PI;
|
||||
}
|
||||
}
|
||||
else if (inSideB)
|
||||
{
|
||||
intersectionCount = 1; // 01
|
||||
|
||||
if (intersectionPointA != nullptr)
|
||||
{
|
||||
intersectionPointA->x = xA;
|
||||
intersectionPointA->y = yA;
|
||||
}
|
||||
|
||||
if (intersectionPointB != nullptr)
|
||||
{
|
||||
intersectionPointB->x = xA;
|
||||
intersectionPointB->y = yA;
|
||||
}
|
||||
|
||||
if (normalRadians != nullptr)
|
||||
{
|
||||
normalRadians->y = normalRadians->x + Transform::PI;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
intersectionCount = 3; // 11
|
||||
if (intersectionPointA != nullptr)
|
||||
{
|
||||
intersectionPointA->x = xA;
|
||||
intersectionPointA->y = yA;
|
||||
}
|
||||
|
||||
if (intersectionPointB != nullptr)
|
||||
{
|
||||
intersectionPointB->x = xB;
|
||||
intersectionPointB->y = yB;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return intersectionCount;
|
||||
}
|
||||
|
||||
void RectangleBoundingBoxData::_onClear()
|
||||
{
|
||||
BoundingBoxData::_onClear();
|
||||
|
||||
type = BoundingBoxType::Rectangle;
|
||||
}
|
||||
|
||||
bool RectangleBoundingBoxData::containsPoint(float pX, float pY)
|
||||
{
|
||||
const auto widthH = width * 0.5f;
|
||||
if (pX >= -widthH && pX <= widthH)
|
||||
{
|
||||
const auto heightH = height * 0.5f;
|
||||
if (pY >= -heightH && pY <= heightH)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
int RectangleBoundingBoxData::intersectsSegment(
|
||||
float xA, float yA, float xB, float yB,
|
||||
Point* intersectionPointA,
|
||||
Point* intersectionPointB,
|
||||
Point* normalRadians
|
||||
)
|
||||
{
|
||||
const auto widthH = width * 0.5f;
|
||||
const auto heightH = height * 0.5f;
|
||||
const auto intersectionCount = RectangleBoundingBoxData::rectangleIntersectsSegment(
|
||||
xA, yA, xB, yB,
|
||||
-widthH, -heightH, widthH, heightH,
|
||||
intersectionPointA, intersectionPointB, normalRadians
|
||||
);
|
||||
|
||||
return intersectionCount;
|
||||
}
|
||||
|
||||
int EllipseBoundingBoxData::ellipseIntersectsSegment(
|
||||
float xA, float yA, float xB, float yB,
|
||||
float xC, float yC, float widthH, float heightH,
|
||||
Point* intersectionPointA,
|
||||
Point* intersectionPointB,
|
||||
Point* normalRadians
|
||||
)
|
||||
{
|
||||
const auto d = widthH / heightH;
|
||||
const auto dd = d * d;
|
||||
|
||||
yA *= d;
|
||||
yB *= d;
|
||||
|
||||
const auto dX = xB - xA;
|
||||
const auto dY = yB - yA;
|
||||
const auto lAB = sqrt(dX * dX + dY * dY);
|
||||
const auto xD = dX / lAB;
|
||||
const auto yD = dY / lAB;
|
||||
const auto a = (xC - xA) * xD + (yC - yA) * yD;
|
||||
const auto aa = a * a;
|
||||
const auto ee = xA * xA + yA * yA;
|
||||
const auto rr = widthH * widthH;
|
||||
const auto dR = rr - ee + aa;
|
||||
auto intersectionCount = 0;
|
||||
|
||||
if (dR >= 0.0f)
|
||||
{
|
||||
const auto dT = sqrt(dR);
|
||||
const auto sA = a - dT;
|
||||
const auto sB = a + dT;
|
||||
const auto inSideA = sA < 0.0f ? -1 : (sA <= lAB ? 0 : 1);
|
||||
const auto inSideB = sB < 0.0f ? -1 : (sB <= lAB ? 0 : 1);
|
||||
const auto sideAB = inSideA * inSideB;
|
||||
|
||||
if (sideAB < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
else if (sideAB == 0)
|
||||
{
|
||||
if (inSideA == -1)
|
||||
{
|
||||
intersectionCount = 2; // 10
|
||||
xB = xA + sB * xD;
|
||||
yB = (yA + sB * yD) / d;
|
||||
|
||||
if (intersectionPointA != nullptr)
|
||||
{
|
||||
intersectionPointA->x = xB;
|
||||
intersectionPointA->y = yB;
|
||||
}
|
||||
|
||||
if (intersectionPointB != nullptr)
|
||||
{
|
||||
intersectionPointB->x = xB;
|
||||
intersectionPointB->y = yB;
|
||||
}
|
||||
|
||||
if (normalRadians != nullptr)
|
||||
{
|
||||
normalRadians->x = atan2(yB / rr * dd, xB / rr);
|
||||
normalRadians->y = normalRadians->x + Transform::PI;
|
||||
}
|
||||
}
|
||||
else if (inSideB == 1)
|
||||
{
|
||||
intersectionCount = 1; // 01
|
||||
xA = xA + sA * xD;
|
||||
yA = (yA + sA * yD) / d;
|
||||
|
||||
if (intersectionPointA != nullptr)
|
||||
{
|
||||
intersectionPointA->x = xA;
|
||||
intersectionPointA->y = yA;
|
||||
}
|
||||
|
||||
if (intersectionPointB != nullptr)
|
||||
{
|
||||
intersectionPointB->x = xA;
|
||||
intersectionPointB->y = yA;
|
||||
}
|
||||
|
||||
if (normalRadians != nullptr)
|
||||
{
|
||||
normalRadians->x = atan2(yA / rr * dd, xA / rr);
|
||||
normalRadians->y = normalRadians->x + Transform::PI;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
intersectionCount = 3; // 11
|
||||
|
||||
if (intersectionPointA != nullptr)
|
||||
{
|
||||
intersectionPointA->x = xA + sA * xD;
|
||||
intersectionPointA->y = (yA + sA * yD) / d;
|
||||
|
||||
if (normalRadians != nullptr)
|
||||
{
|
||||
normalRadians->x = atan2(intersectionPointA->y / rr * dd, intersectionPointA->x / rr);
|
||||
}
|
||||
}
|
||||
|
||||
if (intersectionPointB != nullptr)
|
||||
{
|
||||
intersectionPointB->x = xA + sB * xD;
|
||||
intersectionPointB->y = (yA + sB * yD) / d;
|
||||
|
||||
if (normalRadians != nullptr)
|
||||
{
|
||||
normalRadians->y = atan2(intersectionPointB->y / rr * dd, intersectionPointB->x / rr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return intersectionCount;
|
||||
}
|
||||
|
||||
void EllipseBoundingBoxData::_onClear()
|
||||
|
||||
{
|
||||
BoundingBoxData::_onClear();
|
||||
|
||||
type = BoundingBoxType::Ellipse;
|
||||
}
|
||||
|
||||
bool EllipseBoundingBoxData::containsPoint(float pX, float pY)
|
||||
{
|
||||
const auto widthH = width * 0.5f;
|
||||
if (pX >= -widthH && pX <= widthH)
|
||||
{
|
||||
const auto heightH = height * 0.5f;
|
||||
if (pY >= -heightH && pY <= heightH)
|
||||
{
|
||||
pY *= widthH / heightH;
|
||||
return sqrt(pX * pX + pY * pY) <= widthH;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
int EllipseBoundingBoxData::intersectsSegment(
|
||||
float xA, float yA, float xB, float yB,
|
||||
Point* intersectionPointA,
|
||||
Point* intersectionPointB,
|
||||
Point* normalRadians
|
||||
)
|
||||
{
|
||||
const auto intersectionCount = EllipseBoundingBoxData::ellipseIntersectsSegment(
|
||||
xA, yA, xB, yB,
|
||||
0.0f, 0.0f, width * 0.5f, height * 0.5f,
|
||||
intersectionPointA, intersectionPointB, normalRadians
|
||||
);
|
||||
|
||||
return intersectionCount;
|
||||
}
|
||||
|
||||
int PolygonBoundingBoxData::polygonIntersectsSegment(
|
||||
float xA, float yA, float xB, float yB,
|
||||
const std::vector<float>& vertices,
|
||||
Point* intersectionPointA,
|
||||
Point* intersectionPointB,
|
||||
Point* normalRadians)
|
||||
{
|
||||
if (xA == xB)
|
||||
{
|
||||
xA = xB + 0.000001f;
|
||||
}
|
||||
|
||||
if (yA == yB)
|
||||
{
|
||||
yA = yB + 0.000001f;
|
||||
}
|
||||
|
||||
const auto count = vertices.size();
|
||||
const auto dXAB = xA - xB;
|
||||
const auto dYAB = yA - yB;
|
||||
const auto llAB = xA * yB - yA * xB;
|
||||
auto intersectionCount = 0;
|
||||
auto xC = vertices[count - 2];
|
||||
auto yC = vertices[count - 1];
|
||||
auto dMin = 0.0f;
|
||||
auto dMax = 0.0f;
|
||||
auto xMin = 0.0f;
|
||||
auto yMin = 0.0f;
|
||||
auto xMax = 0.0f;
|
||||
auto yMax = 0.0f;
|
||||
|
||||
for (std::size_t i = 0; i < count; i += 2)
|
||||
{
|
||||
const auto xD = vertices[i];
|
||||
const auto yD = vertices[i + 1];
|
||||
|
||||
if (xC == xD)
|
||||
{
|
||||
xC = xD + 0.000001f;
|
||||
}
|
||||
|
||||
if (yC == yD)
|
||||
{
|
||||
yC = yD + 0.000001f;
|
||||
}
|
||||
|
||||
const auto dXCD = xC - xD;
|
||||
const auto dYCD = yC - yD;
|
||||
const auto llCD = xC * yD - yC * xD;
|
||||
const auto ll = dXAB * dYCD - dYAB * dXCD;
|
||||
const auto x = (llAB * dXCD - dXAB * llCD) / ll;
|
||||
|
||||
if (((x >= xC && x <= xD) || (x >= xD && x <= xC)) && (dXAB == 0.0f || (x >= xA && x <= xB) || (x >= xB && x <= xA)))
|
||||
{
|
||||
const auto y = (llAB * dYCD - dYAB * llCD) / ll;
|
||||
if (((y >= yC && y <= yD) || (y >= yD && y <= yC)) && (dYAB == 0.0f || (y >= yA && y <= yB) || (y >= yB && y <= yA)))
|
||||
{
|
||||
if (intersectionPointB != nullptr)
|
||||
{
|
||||
float d = x - xA;
|
||||
if (d < 0.0f)
|
||||
{
|
||||
d = -d;
|
||||
}
|
||||
|
||||
if (intersectionCount == 0)
|
||||
{
|
||||
dMin = d;
|
||||
dMax = d;
|
||||
xMin = x;
|
||||
yMin = y;
|
||||
xMax = x;
|
||||
yMax = y;
|
||||
|
||||
if (normalRadians != nullptr)
|
||||
{
|
||||
normalRadians->x = atan2(yD - yC, xD - xC) - Transform::PI * 0.5f;
|
||||
normalRadians->y = normalRadians->x;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (d < dMin)
|
||||
{
|
||||
dMin = d;
|
||||
xMin = x;
|
||||
yMin = y;
|
||||
|
||||
if (normalRadians != nullptr)
|
||||
{
|
||||
normalRadians->x = atan2(yD - yC, xD - xC) - Transform::PI * 0.5f;
|
||||
}
|
||||
}
|
||||
|
||||
if (d > dMax)
|
||||
{
|
||||
dMax = d;
|
||||
xMax = x;
|
||||
yMax = y;
|
||||
|
||||
if (normalRadians != nullptr) {
|
||||
normalRadians->y = atan2(yD - yC, xD - xC) - Transform::PI * 0.5f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
intersectionCount++;
|
||||
}
|
||||
else
|
||||
{
|
||||
xMin = x;
|
||||
yMin = y;
|
||||
xMax = x;
|
||||
yMax = y;
|
||||
intersectionCount++;
|
||||
|
||||
if (normalRadians != nullptr)
|
||||
{
|
||||
normalRadians->x = atan2(yD - yC, xD - xC) - Transform::PI * 0.5f;
|
||||
normalRadians->y = normalRadians->x;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
xC = xD;
|
||||
yC = yD;
|
||||
}
|
||||
|
||||
if (intersectionCount == 1)
|
||||
{
|
||||
if (intersectionPointA != nullptr)
|
||||
{
|
||||
intersectionPointA->x = xMin;
|
||||
intersectionPointA->y = yMin;
|
||||
}
|
||||
|
||||
if (intersectionPointB != nullptr)
|
||||
{
|
||||
intersectionPointB->x = xMin;
|
||||
intersectionPointB->y = yMin;
|
||||
}
|
||||
|
||||
if (normalRadians != nullptr)
|
||||
{
|
||||
normalRadians->y = normalRadians->x + Transform::PI;
|
||||
}
|
||||
}
|
||||
else if (intersectionCount > 1)
|
||||
{
|
||||
intersectionCount++;
|
||||
|
||||
if (intersectionPointA != nullptr)
|
||||
{
|
||||
intersectionPointA->x = xMin;
|
||||
intersectionPointA->y = yMin;
|
||||
}
|
||||
|
||||
if (intersectionPointB != nullptr)
|
||||
{
|
||||
intersectionPointB->x = xMax;
|
||||
intersectionPointB->y = yMax;
|
||||
}
|
||||
}
|
||||
|
||||
return intersectionCount;
|
||||
}
|
||||
|
||||
void PolygonBoundingBoxData::_onClear()
|
||||
{
|
||||
BoundingBoxData::_onClear();
|
||||
|
||||
if (weight != nullptr)
|
||||
{
|
||||
weight->returnToPool();
|
||||
}
|
||||
|
||||
type = BoundingBoxType::Polygon;
|
||||
x = 0.0f;
|
||||
y = 0.0f;
|
||||
vertices.clear();
|
||||
weight = nullptr;
|
||||
}
|
||||
|
||||
bool PolygonBoundingBoxData::containsPoint(float pX, float pY)
|
||||
{
|
||||
auto isInSide = false;
|
||||
if (pX >= x && pX <= width && pY >= y && pY <= height)
|
||||
{
|
||||
for (std::size_t i = 0, l = vertices.size(), iP = l - 2; i < l; i += 2)
|
||||
{
|
||||
const auto yA = vertices[iP + 1];
|
||||
const auto yB = vertices[i + 1];
|
||||
if ((yB < pY && yA >= pY) || (yA < pY && yB >= pY))
|
||||
{
|
||||
const auto xA = vertices[iP];
|
||||
const auto xB = vertices[i];
|
||||
if ((pY - yB) * (xA - xB) / (yA - yB) + xB < pX)
|
||||
{
|
||||
isInSide = !isInSide;
|
||||
}
|
||||
}
|
||||
|
||||
iP = i;
|
||||
}
|
||||
}
|
||||
|
||||
return isInSide;
|
||||
}
|
||||
|
||||
int PolygonBoundingBoxData::intersectsSegment(
|
||||
float xA, float yA, float xB, float yB,
|
||||
Point* intersectionPointA,
|
||||
Point* intersectionPointB,
|
||||
Point* normalRadians
|
||||
)
|
||||
{
|
||||
auto intersectionCount = 0;
|
||||
if (RectangleBoundingBoxData::rectangleIntersectsSegment(xA, yA, xB, yB, x, y, x + width, y + height, nullptr, nullptr, nullptr) != 0) {
|
||||
intersectionCount = PolygonBoundingBoxData::polygonIntersectsSegment(
|
||||
xA, yA, xB, yB,
|
||||
vertices,
|
||||
intersectionPointA, intersectionPointB, normalRadians
|
||||
);
|
||||
}
|
||||
|
||||
return intersectionCount;
|
||||
}
|
||||
|
||||
DRAGONBONES_NAMESPACE_END
|
@@ -0,0 +1,289 @@
|
||||
/**
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2012-2018 DragonBones team and other contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef DRAGONBONESCPP_BOUNDINGBOXDATA_H
|
||||
#define DRAGONBONESCPP_BOUNDINGBOXDATA_H
|
||||
|
||||
#include "../core/BaseObject.h"
|
||||
#include "../geom/Point.h"
|
||||
|
||||
DRAGONBONES_NAMESPACE_BEGIN
|
||||
/**
|
||||
* - The base class of bounding box data.
|
||||
* @see dragonBones.RectangleData
|
||||
* @see dragonBones.EllipseData
|
||||
* @see dragonBones.PolygonData
|
||||
* @version DragonBones 5.0
|
||||
* @language en_US
|
||||
*/
|
||||
/**
|
||||
* - 边界框数据基类。
|
||||
* @see dragonBones.RectangleData
|
||||
* @see dragonBones.EllipseData
|
||||
* @see dragonBones.PolygonData
|
||||
* @version DragonBones 5.0
|
||||
* @language zh_CN
|
||||
*/
|
||||
class BoundingBoxData : public BaseObject
|
||||
{
|
||||
ABSTRACT_CLASS(BoundingBoxData);
|
||||
|
||||
public:
|
||||
/**
|
||||
* - The bounding box type.
|
||||
* @version DragonBones 5.0
|
||||
* @language en_US
|
||||
*/
|
||||
/**
|
||||
* - 边界框类型。
|
||||
* @version DragonBones 5.0
|
||||
* @language zh_CN
|
||||
*/
|
||||
BoundingBoxType type;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
unsigned color;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
float width;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
float height;
|
||||
|
||||
protected:
|
||||
virtual void _onClear() override;
|
||||
|
||||
public:
|
||||
/**
|
||||
* - Check whether the bounding box contains a specific point. (Local coordinate system)
|
||||
* @version DragonBones 5.0
|
||||
* @language en_US
|
||||
*/
|
||||
/**
|
||||
* - 检查边界框是否包含特定点。(本地坐标系)
|
||||
* @version DragonBones 5.0
|
||||
* @language zh_CN
|
||||
*/
|
||||
virtual bool containsPoint(float pX, float pY) = 0;
|
||||
/**
|
||||
* - Check whether the bounding box intersects a specific segment. (Local coordinate system)
|
||||
* @version DragonBones 5.0
|
||||
* @language en_US
|
||||
*/
|
||||
/**
|
||||
* - 检查边界框是否与特定线段相交。(本地坐标系)
|
||||
* @version DragonBones 5.0
|
||||
* @language zh_CN
|
||||
*/
|
||||
virtual int intersectsSegment(
|
||||
float xA, float yA, float xB, float yB,
|
||||
Point* intersectionPointA = nullptr,
|
||||
Point* intersectionPointB = nullptr,
|
||||
Point* normalRadians = nullptr
|
||||
) = 0;
|
||||
|
||||
public: // For WebAssembly.
|
||||
int getType() const { return (int)type; }
|
||||
void setType(int value) { type = (BoundingBoxType)value; }
|
||||
};
|
||||
/**
|
||||
* - The rectangle bounding box data.
|
||||
* @version DragonBones 5.1
|
||||
* @language en_US
|
||||
*/
|
||||
/**
|
||||
* - 矩形边界框数据。
|
||||
* @version DragonBones 5.1
|
||||
* @language zh_CN
|
||||
*/
|
||||
class RectangleBoundingBoxData : public BoundingBoxData
|
||||
{
|
||||
BIND_CLASS_TYPE_A(RectangleBoundingBoxData);
|
||||
|
||||
private:
|
||||
enum OutCode {
|
||||
InSide = 0, // 0000
|
||||
Left = 1, // 0001
|
||||
Right = 2, // 0010
|
||||
Top = 4, // 0100
|
||||
Bottom = 8 // 1000
|
||||
};
|
||||
/**
|
||||
* - Compute the bit code for a point (x, y) using the clip rectangle
|
||||
*/
|
||||
static int _computeOutCode(float x, float y, float xMin, float yMin, float xMax, float yMax);
|
||||
|
||||
public:
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
static int rectangleIntersectsSegment(
|
||||
float xA, float yA, float xB, float yB,
|
||||
float xMin, float yMin, float xMax, float yMax,
|
||||
Point* intersectionPointA = nullptr,
|
||||
Point* intersectionPointB = nullptr,
|
||||
Point* normalRadians = nullptr
|
||||
);
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
virtual bool containsPoint(float pX, float pY) override;
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
virtual int intersectsSegment(
|
||||
float xA, float yA, float xB, float yB,
|
||||
Point* intersectionPointA = nullptr,
|
||||
Point* intersectionPointB = nullptr,
|
||||
Point* normalRadians = nullptr
|
||||
) override;
|
||||
|
||||
protected:
|
||||
virtual void _onClear() override;
|
||||
};
|
||||
/**
|
||||
* - The ellipse bounding box data.
|
||||
* @version DragonBones 5.1
|
||||
* @language en_US
|
||||
*/
|
||||
/**
|
||||
* - 椭圆边界框数据。
|
||||
* @version DragonBones 5.1
|
||||
* @language zh_CN
|
||||
*/
|
||||
class EllipseBoundingBoxData : public BoundingBoxData
|
||||
{
|
||||
BIND_CLASS_TYPE_A(EllipseBoundingBoxData);
|
||||
|
||||
public:
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
static int ellipseIntersectsSegment(
|
||||
float xA, float yA, float xB, float yB,
|
||||
float xC, float yC, float widthH, float heightH,
|
||||
Point* intersectionPointA = nullptr,
|
||||
Point* intersectionPointB = nullptr,
|
||||
Point* normalRadians = nullptr
|
||||
);
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
virtual bool containsPoint(float pX, float pY) override;
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
virtual int intersectsSegment(
|
||||
float xA, float yA, float xB, float yB,
|
||||
Point* intersectionPointA = nullptr,
|
||||
Point* intersectionPointB = nullptr,
|
||||
Point* normalRadians = nullptr
|
||||
) override;
|
||||
|
||||
protected:
|
||||
virtual void _onClear() override;
|
||||
};
|
||||
/**
|
||||
* - The polygon bounding box data.
|
||||
* @version DragonBones 5.1
|
||||
* @language en_US
|
||||
*/
|
||||
/**
|
||||
* - 多边形边界框数据。
|
||||
* @version DragonBones 5.1
|
||||
* @language zh_CN
|
||||
*/
|
||||
class PolygonBoundingBoxData : public BoundingBoxData
|
||||
{
|
||||
BIND_CLASS_TYPE_B(PolygonBoundingBoxData);
|
||||
|
||||
public:
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
static int polygonIntersectsSegment(
|
||||
float xA, float yA, float xB, float yB,
|
||||
const std::vector<float>& vertices,
|
||||
Point* intersectionPointA = nullptr,
|
||||
Point* intersectionPointB = nullptr,
|
||||
Point* normalRadians = nullptr
|
||||
);
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
float x;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
float y;
|
||||
/**
|
||||
* - The polygon vertices.
|
||||
* @version DragonBones 5.1
|
||||
* @language en_US
|
||||
*/
|
||||
/**
|
||||
* - 多边形顶点。
|
||||
* @version DragonBones 5.1
|
||||
* @language zh_CN
|
||||
*/
|
||||
std::vector<float> vertices;
|
||||
WeightData* weight;
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
virtual bool containsPoint(float pX, float pY) override;
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
virtual int intersectsSegment(
|
||||
float xA, float yA, float xB, float yB,
|
||||
Point* intersectionPointA = nullptr,
|
||||
Point* intersectionPointB = nullptr,
|
||||
Point* normalRadians = nullptr
|
||||
) override;
|
||||
|
||||
PolygonBoundingBoxData() :
|
||||
weight(nullptr)
|
||||
{
|
||||
_onClear();
|
||||
}
|
||||
~PolygonBoundingBoxData()
|
||||
{
|
||||
_onClear();
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void _onClear() override;
|
||||
|
||||
public: // For WebAssembly.
|
||||
std::vector<float>* getVertices() { return &vertices; }
|
||||
|
||||
/*WeightData* getWeight() const { return weight; }
|
||||
void setWeight(WeightData* value) { weight = value; }
|
||||
*/
|
||||
};
|
||||
|
||||
DRAGONBONES_NAMESPACE_END
|
||||
#endif //DRAGONBONESCPP_BOUNDINGBOXDATA_H
|
@@ -0,0 +1,12 @@
|
||||
#include "CanvasData.h"
|
||||
|
||||
DRAGONBONES_NAMESPACE_BEGIN
|
||||
|
||||
void CanvasData::_onClear()
|
||||
{
|
||||
hasBackground = false;
|
||||
color = 0x000000;
|
||||
aabb.clear();
|
||||
}
|
||||
|
||||
DRAGONBONES_NAMESPACE_END
|
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2012-2018 DragonBones team and other contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef DRAGONBONES_CANVAS_DATA_H
|
||||
#define DRAGONBONES_CANVAS_DATA_H
|
||||
|
||||
#include "../core/BaseObject.h"
|
||||
#include "../geom/Rectangle.h"
|
||||
|
||||
DRAGONBONES_NAMESPACE_BEGIN
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
class CanvasData : public BaseObject
|
||||
{
|
||||
BIND_CLASS_TYPE_A(CanvasData);
|
||||
|
||||
public:
|
||||
bool hasBackground;
|
||||
unsigned color;
|
||||
Rectangle aabb;
|
||||
|
||||
protected:
|
||||
virtual void _onClear() override;
|
||||
};
|
||||
DRAGONBONES_NAMESPACE_END
|
||||
#endif // DRAGONBONES_CANVAS_DATA_H
|
@@ -0,0 +1,27 @@
|
||||
//
|
||||
// Created by liangshuochen on 09/06/2017.
|
||||
//
|
||||
|
||||
#include "ConstraintData.h"
|
||||
|
||||
DRAGONBONES_NAMESPACE_BEGIN
|
||||
|
||||
void ConstraintData::_onClear()
|
||||
{
|
||||
order = 0;
|
||||
name = "";
|
||||
target = nullptr;
|
||||
root = nullptr;
|
||||
bone = nullptr;
|
||||
}
|
||||
|
||||
void IKConstraintData::_onClear()
|
||||
{
|
||||
ConstraintData::_onClear();
|
||||
|
||||
scaleEnabled = false;
|
||||
bendPositive = false;
|
||||
weight = 1.0f;
|
||||
}
|
||||
|
||||
DRAGONBONES_NAMESPACE_END
|
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2012-2018 DragonBones team and other contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
//
|
||||
// Created by liangshuochen on 09/06/2017.
|
||||
//
|
||||
|
||||
#ifndef DRAGONBONESCPP_CONSTRAINTDATA_H
|
||||
#define DRAGONBONESCPP_CONSTRAINTDATA_H
|
||||
|
||||
#include "../core/BaseObject.h"
|
||||
|
||||
DRAGONBONES_NAMESPACE_BEGIN
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
class ConstraintData : public BaseObject
|
||||
{
|
||||
ABSTRACT_CLASS(ConstraintData)
|
||||
|
||||
public:
|
||||
int order;
|
||||
std::string name;
|
||||
const BoneData* target;
|
||||
const BoneData* root;
|
||||
const BoneData* bone;
|
||||
|
||||
protected:
|
||||
virtual void _onClear() override;
|
||||
|
||||
public: // For WebAssembly.
|
||||
const BoneData* getTarget() const { return target; }
|
||||
void setTarget(const BoneData* value) { target = value; }
|
||||
|
||||
const BoneData* getBone() const { return bone; }
|
||||
void setBone(const BoneData* value) { bone = value; }
|
||||
|
||||
const BoneData* getRoot() const { return root; }
|
||||
void setRoot(const BoneData* value) { root = value; }
|
||||
};
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
class IKConstraintData : public ConstraintData
|
||||
{
|
||||
BIND_CLASS_TYPE_A(IKConstraintData);
|
||||
|
||||
public:
|
||||
bool scaleEnabled;
|
||||
bool bendPositive;
|
||||
float weight;
|
||||
|
||||
protected:
|
||||
virtual void _onClear() override;
|
||||
};
|
||||
|
||||
DRAGONBONES_NAMESPACE_END
|
||||
#endif //DRAGONBONESCPP_CONSTRAINTDATA_H
|
103
cocos2d-x/cocos/editor-support/dragonbones/model/DisplayData.cpp
Normal file
103
cocos2d-x/cocos/editor-support/dragonbones/model/DisplayData.cpp
Normal file
@@ -0,0 +1,103 @@
|
||||
//
|
||||
// Created by liangshuochen on 08/06/2017.
|
||||
//
|
||||
|
||||
#include "DisplayData.h"
|
||||
#include "UserData.h"
|
||||
#include "BoundingBoxData.h"
|
||||
|
||||
DRAGONBONES_NAMESPACE_BEGIN
|
||||
|
||||
void VerticesData::clear()
|
||||
{
|
||||
if (!isShared && weight != nullptr)
|
||||
{
|
||||
weight->returnToPool();
|
||||
}
|
||||
|
||||
isShared = false;
|
||||
inheritDeform = false;
|
||||
offset = 0;
|
||||
data = nullptr;
|
||||
weight = nullptr;
|
||||
}
|
||||
|
||||
void VerticesData::shareFrom(const VerticesData& value)
|
||||
{
|
||||
isShared = true;
|
||||
offset = value.offset;
|
||||
weight = value.weight;
|
||||
}
|
||||
|
||||
void DisplayData::_onClear()
|
||||
{
|
||||
name = "";
|
||||
path = "";
|
||||
transform.identity();
|
||||
parent = nullptr;
|
||||
}
|
||||
|
||||
void ImageDisplayData::_onClear()
|
||||
{
|
||||
DisplayData::_onClear();
|
||||
|
||||
type = DisplayType::Image;
|
||||
pivot.clear();
|
||||
texture = nullptr;
|
||||
}
|
||||
|
||||
void ArmatureDisplayData::_onClear()
|
||||
{
|
||||
DisplayData::_onClear();
|
||||
|
||||
for(const auto action : actions)
|
||||
{
|
||||
action->returnToPool();
|
||||
}
|
||||
|
||||
type = DisplayType::Armature;
|
||||
inheritAnimation = false;
|
||||
actions.clear();
|
||||
armature = nullptr;
|
||||
}
|
||||
|
||||
void ArmatureDisplayData::addAction(ActionData* value)
|
||||
{
|
||||
actions.push_back(value);
|
||||
}
|
||||
|
||||
void MeshDisplayData::_onClear()
|
||||
{
|
||||
DisplayData::_onClear();
|
||||
|
||||
type = DisplayType::Mesh;
|
||||
vertices.clear();
|
||||
texture = nullptr;
|
||||
}
|
||||
|
||||
void BoundingBoxDisplayData::_onClear()
|
||||
{
|
||||
DisplayData::_onClear();
|
||||
|
||||
if(boundingBox != nullptr)
|
||||
{
|
||||
boundingBox->returnToPool();
|
||||
}
|
||||
|
||||
type = DisplayType::BoundingBox;
|
||||
boundingBox = nullptr;
|
||||
}
|
||||
|
||||
void WeightData::_onClear()
|
||||
{
|
||||
count = 0;
|
||||
offset = 0;
|
||||
bones.clear();
|
||||
}
|
||||
|
||||
void WeightData::addBone(BoneData* value)
|
||||
{
|
||||
bones.push_back(value);
|
||||
}
|
||||
|
||||
DRAGONBONES_NAMESPACE_END
|
192
cocos2d-x/cocos/editor-support/dragonbones/model/DisplayData.h
Normal file
192
cocos2d-x/cocos/editor-support/dragonbones/model/DisplayData.h
Normal file
@@ -0,0 +1,192 @@
|
||||
/**
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2012-2018 DragonBones team and other contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef DRAGONBONESCPP_DISPLAYDATA_H
|
||||
#define DRAGONBONESCPP_DISPLAYDATA_H
|
||||
|
||||
#include "../core/BaseObject.h"
|
||||
#include "../geom/Transform.h"
|
||||
#include "BoundingBoxData.h"
|
||||
|
||||
DRAGONBONES_NAMESPACE_BEGIN
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
class VerticesData
|
||||
{
|
||||
public:
|
||||
bool isShared;
|
||||
bool inheritDeform;
|
||||
unsigned offset;
|
||||
DragonBonesData* data;
|
||||
WeightData* weight;
|
||||
|
||||
VerticesData() :
|
||||
weight(nullptr)
|
||||
{
|
||||
}
|
||||
~VerticesData()
|
||||
{
|
||||
}
|
||||
|
||||
void clear();
|
||||
void shareFrom(const VerticesData& value);
|
||||
};
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
class DisplayData : public BaseObject
|
||||
{
|
||||
ABSTRACT_CLASS(DisplayData)
|
||||
|
||||
public:
|
||||
DisplayType type;
|
||||
std::string name;
|
||||
std::string path;
|
||||
Transform transform;
|
||||
SkinData* parent;
|
||||
|
||||
protected:
|
||||
virtual void _onClear() override;
|
||||
|
||||
public: // For WebAssembly.
|
||||
int getType() const { return (int)type; }
|
||||
void setType(int value) { type = (DisplayType)value; }
|
||||
|
||||
Transform* getTransform() { return &transform; }
|
||||
|
||||
SkinData* getParent() const { return parent; }
|
||||
void setParent(SkinData* value) { parent = value; }
|
||||
};
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
class ImageDisplayData : public DisplayData
|
||||
{
|
||||
BIND_CLASS_TYPE_A(ImageDisplayData);
|
||||
|
||||
public:
|
||||
Point pivot;
|
||||
TextureData* texture;
|
||||
|
||||
protected:
|
||||
virtual void _onClear() override;
|
||||
|
||||
public: // For WebAssembly.
|
||||
Point* getPivot() { return &pivot; }
|
||||
|
||||
TextureData* getTexture() const { return texture; }
|
||||
void setTexture(TextureData* value) { texture = value; }
|
||||
};
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
class ArmatureDisplayData : public DisplayData
|
||||
{
|
||||
BIND_CLASS_TYPE_A(ArmatureDisplayData);
|
||||
|
||||
public:
|
||||
bool inheritAnimation;
|
||||
std::vector<ActionData*> actions;
|
||||
ArmatureData* armature;
|
||||
|
||||
protected:
|
||||
virtual void _onClear() override;
|
||||
|
||||
public:
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
void addAction(ActionData* value);
|
||||
|
||||
public: // For WebAssembly.
|
||||
const std::vector<ActionData*>& getActions() const { return actions; }
|
||||
|
||||
ArmatureData* getArmature() const { return armature; }
|
||||
void setArmature(ArmatureData* value) { armature = value; }
|
||||
};
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
class MeshDisplayData : public DisplayData
|
||||
{
|
||||
BIND_CLASS_TYPE_A(MeshDisplayData);
|
||||
|
||||
public:
|
||||
VerticesData vertices;
|
||||
TextureData* texture;
|
||||
|
||||
protected:
|
||||
virtual void _onClear() override;
|
||||
};
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
class BoundingBoxDisplayData : public DisplayData
|
||||
{
|
||||
BIND_CLASS_TYPE_B(BoundingBoxDisplayData);
|
||||
|
||||
public:
|
||||
BoundingBoxData* boundingBox;
|
||||
|
||||
BoundingBoxDisplayData() :
|
||||
boundingBox(nullptr)
|
||||
{
|
||||
_onClear();
|
||||
}
|
||||
~BoundingBoxDisplayData()
|
||||
{
|
||||
_onClear();
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void _onClear() override;
|
||||
|
||||
public: // For WebAssembly.
|
||||
const BoundingBoxData* getBoundingBox() const { return boundingBox; }
|
||||
void setBoundingBox(BoundingBoxData* value) { boundingBox = value; }
|
||||
};
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
class WeightData : public BaseObject
|
||||
{
|
||||
BIND_CLASS_TYPE_A(WeightData);
|
||||
|
||||
public:
|
||||
unsigned count;
|
||||
unsigned offset;
|
||||
std::vector<BoneData*> bones;
|
||||
|
||||
protected:
|
||||
virtual void _onClear() override;
|
||||
|
||||
public:
|
||||
void addBone(BoneData* value);
|
||||
|
||||
public: // For WebAssembly.
|
||||
const std::vector<BoneData*>& getBones() const { return bones; }
|
||||
};
|
||||
|
||||
DRAGONBONES_NAMESPACE_END
|
||||
|
||||
#endif //DRAGONBONESCPP_DISPLAYDATA_H
|
@@ -0,0 +1,56 @@
|
||||
#include "DragonBonesData.h"
|
||||
#include "UserData.h"
|
||||
#include "ArmatureData.h"
|
||||
|
||||
|
||||
DRAGONBONES_NAMESPACE_BEGIN
|
||||
|
||||
void DragonBonesData::_onClear()
|
||||
{
|
||||
for (const auto& pair : armatures)
|
||||
{
|
||||
pair.second->returnToPool();
|
||||
}
|
||||
|
||||
if (binary != nullptr)
|
||||
{
|
||||
delete binary;
|
||||
}
|
||||
|
||||
if (userData != nullptr)
|
||||
{
|
||||
userData->returnToPool();
|
||||
}
|
||||
|
||||
autoSearch = false;
|
||||
frameRate = 0;
|
||||
version = "";
|
||||
name = "";
|
||||
frameIndices.clear();
|
||||
cachedFrames.clear();
|
||||
armatureNames.clear();
|
||||
armatures.clear();
|
||||
binary = nullptr;
|
||||
intArray = nullptr;
|
||||
floatArray = nullptr;
|
||||
frameIntArray = nullptr;
|
||||
frameFloatArray = nullptr;
|
||||
frameArray = nullptr;
|
||||
timelineArray = nullptr;
|
||||
userData = nullptr;
|
||||
}
|
||||
|
||||
void DragonBonesData::addArmature(ArmatureData* value)
|
||||
{
|
||||
if (armatures.find(value->name) != armatures.end())
|
||||
{
|
||||
DRAGONBONES_ASSERT(false, "Same armature: " + value->name);
|
||||
return;
|
||||
}
|
||||
|
||||
value->parent = this;
|
||||
armatures[value->name] = value;
|
||||
armatureNames.push_back(value->name);
|
||||
}
|
||||
|
||||
DRAGONBONES_NAMESPACE_END
|
@@ -0,0 +1,193 @@
|
||||
/**
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2012-2018 DragonBones team and other contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef DRAGONBONES_DRAGONBONES_DATA_H
|
||||
#define DRAGONBONES_DRAGONBONES_DATA_H
|
||||
|
||||
#include "../core/BaseObject.h"
|
||||
#include "ArmatureData.h"
|
||||
|
||||
DRAGONBONES_NAMESPACE_BEGIN
|
||||
/**
|
||||
* - The DragonBones data.
|
||||
* A DragonBones data contains multiple armature data.
|
||||
* @see dragonBones.ArmatureData
|
||||
* @version DragonBones 3.0
|
||||
* @language en_US
|
||||
*/
|
||||
/**
|
||||
* - 龙骨数据。
|
||||
* 一个龙骨数据包含多个骨架数据。
|
||||
* @see dragonBones.ArmatureData
|
||||
* @version DragonBones 3.0
|
||||
* @language zh_CN
|
||||
*/
|
||||
class DragonBonesData : public BaseObject
|
||||
{
|
||||
BIND_CLASS_TYPE_B(DragonBonesData);
|
||||
|
||||
public:
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
bool autoSearch;
|
||||
/**
|
||||
* - The animation frame rate.
|
||||
* @version DragonBones 3.0
|
||||
* @language en_US
|
||||
*/
|
||||
/**
|
||||
* - 动画帧频。
|
||||
* @version DragonBones 3.0
|
||||
* @language zh_CN
|
||||
*/
|
||||
unsigned frameRate;
|
||||
/**
|
||||
* - The data version.
|
||||
* @version DragonBones 3.0
|
||||
* @language en_US
|
||||
*/
|
||||
/**
|
||||
* - 数据版本。
|
||||
* @version DragonBones 3.0
|
||||
* @language zh_CN
|
||||
*/
|
||||
std::string version;
|
||||
/**
|
||||
* - The DragonBones data name.
|
||||
* The name is consistent with the DragonBones project name.
|
||||
* @version DragonBones 3.0
|
||||
* @language en_US
|
||||
*/
|
||||
/**
|
||||
* - 龙骨数据名称。
|
||||
* 该名称与龙骨项目名保持一致。
|
||||
* @version DragonBones 3.0
|
||||
* @language zh_CN
|
||||
*/
|
||||
std::string name;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
std::vector<unsigned> frameIndices;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
std::vector<float> cachedFrames;
|
||||
/**
|
||||
* - All armature data names.
|
||||
* @version DragonBones 3.0
|
||||
* @language en_US
|
||||
*/
|
||||
/**
|
||||
* - 所有的骨架数据名称。
|
||||
* @version DragonBones 3.0
|
||||
* @language zh_CN
|
||||
*/
|
||||
std::vector<std::string> armatureNames;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
std::map<std::string, ArmatureData*> armatures;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
const char* binary;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
const int16_t* intArray;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
const float* floatArray;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
const int16_t* frameIntArray;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
const float* frameFloatArray;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
const int16_t* frameArray;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
const uint16_t* timelineArray;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
UserData* userData;
|
||||
DragonBonesData() :
|
||||
binary(nullptr),
|
||||
userData(nullptr)
|
||||
{
|
||||
_onClear();
|
||||
}
|
||||
~DragonBonesData()
|
||||
{
|
||||
_onClear();
|
||||
}
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
void addArmature(ArmatureData* value);
|
||||
/**
|
||||
* - Get a specific armature data.
|
||||
* @param armatureName - The armature data name.
|
||||
* @version DragonBones 3.0
|
||||
* @language en_US
|
||||
*/
|
||||
/**
|
||||
* - 获取特定的骨架数据。
|
||||
* @param armatureName - 骨架数据名称。
|
||||
* @version DragonBones 3.0
|
||||
* @language zh_CN
|
||||
*/
|
||||
inline ArmatureData* getArmature(const std::string& armatureName) const
|
||||
{
|
||||
return mapFind<ArmatureData>(armatures, armatureName);
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void _onClear() override;
|
||||
|
||||
public: // For WebAssembly.
|
||||
std::vector<unsigned>* getFrameIndices() { return &frameIndices; }
|
||||
const std::vector<std::string>& getArmatureNames() const { return armatureNames; }
|
||||
|
||||
#if EGRET_WASM
|
||||
unsigned getBinary() const
|
||||
{
|
||||
return (unsigned)binary;
|
||||
}
|
||||
#endif // EGRET_WASM
|
||||
|
||||
const UserData* getUserData() const { return userData; }
|
||||
void setUserData(UserData* value) { userData = value; }
|
||||
};
|
||||
|
||||
DRAGONBONES_NAMESPACE_END
|
||||
#endif // DRAGONBONES_DRAGONBONES_DATA_H
|
@@ -0,0 +1,51 @@
|
||||
#include "SkinData.h"
|
||||
#include "DisplayData.h"
|
||||
|
||||
DRAGONBONES_NAMESPACE_BEGIN
|
||||
|
||||
void SkinData::_onClear()
|
||||
{
|
||||
for (const auto& pair : displays)
|
||||
{
|
||||
for (const auto display : pair.second)
|
||||
{
|
||||
if (display != nullptr)
|
||||
{
|
||||
display->returnToPool();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
name = "";
|
||||
displays.clear();
|
||||
parent = nullptr;
|
||||
}
|
||||
|
||||
void SkinData::addDisplay(const std::string& slotName, DisplayData* value)
|
||||
{
|
||||
if (value != nullptr)
|
||||
{
|
||||
value->parent = this;
|
||||
}
|
||||
|
||||
displays[slotName].push_back(value); // TODO clear prev
|
||||
}
|
||||
|
||||
DisplayData* SkinData::getDisplay(const std::string& slotName, const std::string& displayName)
|
||||
{
|
||||
const auto slotDisplays = getDisplays(slotName);
|
||||
if (slotDisplays != nullptr)
|
||||
{
|
||||
for (const auto display : *slotDisplays)
|
||||
{
|
||||
if (display != nullptr && display->name == displayName)
|
||||
{
|
||||
return display;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
DRAGONBONES_NAMESPACE_END
|
89
cocos2d-x/cocos/editor-support/dragonbones/model/SkinData.h
Normal file
89
cocos2d-x/cocos/editor-support/dragonbones/model/SkinData.h
Normal file
@@ -0,0 +1,89 @@
|
||||
/**
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2012-2018 DragonBones team and other contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef DRAGONBONES_SKIN_DATA_H
|
||||
#define DRAGONBONES_SKIN_DATA_H
|
||||
|
||||
#include "../core/BaseObject.h"
|
||||
|
||||
DRAGONBONES_NAMESPACE_BEGIN
|
||||
/**
|
||||
* - The skin data, typically a armature data instance contains at least one skinData.
|
||||
* @version DragonBones 3.0
|
||||
* @language en_US
|
||||
*/
|
||||
/**
|
||||
* - 皮肤数据,通常一个骨架数据至少包含一个皮肤数据。
|
||||
* @version DragonBones 3.0
|
||||
* @language zh_CN
|
||||
*/
|
||||
class SkinData : public BaseObject
|
||||
{
|
||||
BIND_CLASS_TYPE_A(SkinData);
|
||||
|
||||
public:
|
||||
/**
|
||||
* - The skin name.
|
||||
* @version DragonBones 3.0
|
||||
* @language en_US
|
||||
*/
|
||||
/**
|
||||
* - 皮肤名称。
|
||||
* @version DragonBones 3.0
|
||||
* @language zh_CN
|
||||
*/
|
||||
std::string name;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
std::map<std::string, std::vector<DisplayData*>> displays;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
ArmatureData* parent;
|
||||
|
||||
protected:
|
||||
virtual void _onClear() override;
|
||||
|
||||
public:
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
void addDisplay(const std::string& slotName, DisplayData* value);
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
DisplayData* getDisplay(const std::string& slotName, const std::string& displayName);
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
std::vector<DisplayData*>* getDisplays(const std::string& slotName)
|
||||
{
|
||||
return mapFindB(displays, slotName);
|
||||
}
|
||||
|
||||
public: // For WebAssembly. TODO parent
|
||||
const std::map<std::string, std::vector<DisplayData*>>& getSlotDisplays() const { return displays; }
|
||||
};
|
||||
|
||||
DRAGONBONES_NAMESPACE_END
|
||||
#endif // DRAGONBONES_SKIN_DATA_H
|
@@ -0,0 +1,105 @@
|
||||
#include "TextureAtlasData.h"
|
||||
|
||||
DRAGONBONES_NAMESPACE_BEGIN
|
||||
|
||||
void TextureAtlasData::_onClear()
|
||||
{
|
||||
for (const auto& pair : textures)
|
||||
{
|
||||
pair.second->returnToPool();
|
||||
}
|
||||
|
||||
autoSearch = false;
|
||||
format = TextureFormat::DEFAULT;
|
||||
width = 0;
|
||||
height = 0;
|
||||
scale = 1.0f;
|
||||
name = "";
|
||||
imagePath.clear();
|
||||
textures.clear();
|
||||
}
|
||||
|
||||
void TextureAtlasData::copyFrom(const TextureAtlasData& value)
|
||||
{
|
||||
autoSearch = value.autoSearch;
|
||||
format = value.format;
|
||||
width = value.width;
|
||||
height = value.height;
|
||||
scale = value.scale;
|
||||
name = value.name;
|
||||
imagePath = value.imagePath;
|
||||
|
||||
for (const auto& pair : textures)
|
||||
{
|
||||
pair.second->returnToPool();
|
||||
}
|
||||
|
||||
textures.clear();
|
||||
|
||||
for (const auto& pair : value.textures)
|
||||
{
|
||||
const auto texture = createTexture();
|
||||
texture->copyFrom(*(pair.second));
|
||||
textures[pair.first] = texture;
|
||||
}
|
||||
}
|
||||
|
||||
void TextureAtlasData::addTexture(TextureData* value)
|
||||
{
|
||||
if (textures.find(value->name) != textures.cend())
|
||||
{
|
||||
DRAGONBONES_ASSERT(false, "Same texture: " + value->name);
|
||||
return;
|
||||
}
|
||||
|
||||
textures[value->name] = value;
|
||||
value->parent = this;
|
||||
}
|
||||
|
||||
Rectangle* TextureData::createRectangle()
|
||||
{
|
||||
return new Rectangle();
|
||||
}
|
||||
|
||||
TextureData::~TextureData()
|
||||
{
|
||||
}
|
||||
|
||||
void TextureData::_onClear()
|
||||
{
|
||||
if (frame != nullptr)
|
||||
{
|
||||
delete frame;
|
||||
}
|
||||
|
||||
rotated = false;
|
||||
name = "";
|
||||
region.clear();
|
||||
parent = nullptr;
|
||||
frame = nullptr;
|
||||
}
|
||||
|
||||
void TextureData::copyFrom(const TextureData &value)
|
||||
{
|
||||
rotated = value.rotated;
|
||||
name = value.name;
|
||||
region = value.region; // Copy.
|
||||
parent = value.parent;
|
||||
|
||||
if (frame == nullptr && value.frame != nullptr)
|
||||
{
|
||||
frame = TextureData::createRectangle();
|
||||
}
|
||||
else if (frame != nullptr && value.frame == nullptr)
|
||||
{
|
||||
delete frame;
|
||||
frame = nullptr;
|
||||
}
|
||||
|
||||
if (frame != nullptr && value.frame != nullptr)
|
||||
{
|
||||
*frame = *(value.frame); // Copy.
|
||||
}
|
||||
}
|
||||
|
||||
DRAGONBONES_NAMESPACE_END
|
@@ -0,0 +1,148 @@
|
||||
/**
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2012-2018 DragonBones team and other contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef DRAGONBONES_TEXTUREATLAS_DATA_H
|
||||
#define DRAGONBONES_TEXTUREATLAS_DATA_H
|
||||
|
||||
#include "../core/BaseObject.h"
|
||||
#include "../geom/Rectangle.h"
|
||||
|
||||
DRAGONBONES_NAMESPACE_BEGIN
|
||||
/**
|
||||
* - The texture atlas data.
|
||||
* @version DragonBones 3.0
|
||||
* @language en_US
|
||||
*/
|
||||
/**
|
||||
* - 贴图集数据。
|
||||
* @version DragonBones 3.0
|
||||
* @language zh_CN
|
||||
*/
|
||||
class TextureAtlasData : public BaseObject
|
||||
{
|
||||
ABSTRACT_CLASS(TextureAtlasData);
|
||||
|
||||
public:
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
bool autoSearch;
|
||||
TextureFormat format;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
unsigned width;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
unsigned height;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
float scale;
|
||||
/**
|
||||
* - The texture atlas name.
|
||||
* @version DragonBones 3.0
|
||||
* @language en_US
|
||||
*/
|
||||
/**
|
||||
* - 贴图集名称。
|
||||
* @version DragonBones 3.0
|
||||
* @language zh_CN
|
||||
*/
|
||||
std::string name;
|
||||
/**
|
||||
* - The image path of the texture atlas.
|
||||
* @version DragonBones 3.0
|
||||
* @language en_US
|
||||
*/
|
||||
/**
|
||||
* - 贴图集图片路径。
|
||||
* @version DragonBones 3.0
|
||||
* @language zh_CN
|
||||
*/
|
||||
std::string imagePath;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
std::map<std::string, TextureData*> textures;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
void copyFrom(const TextureAtlasData& value);
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
virtual TextureData* createTexture() const = 0;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
virtual void addTexture(TextureData* value);
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
inline TextureData* getTexture(const std::string& textureName) const
|
||||
{
|
||||
return mapFind(textures, textureName);
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void _onClear() override;
|
||||
|
||||
public: // For WebAssembly.
|
||||
const std::map<std::string, TextureData*>& getTextures() const { return textures; }
|
||||
};
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
class TextureData : public BaseObject
|
||||
{
|
||||
public:
|
||||
static Rectangle* createRectangle();
|
||||
|
||||
public:
|
||||
bool rotated;
|
||||
std::string name;
|
||||
Rectangle region;
|
||||
Rectangle* frame;
|
||||
TextureAtlasData* parent;
|
||||
|
||||
TextureData() :
|
||||
frame(nullptr)
|
||||
{}
|
||||
virtual ~TextureData() = 0;
|
||||
|
||||
void copyFrom(const TextureData& value);
|
||||
|
||||
protected:
|
||||
virtual void _onClear() override;
|
||||
|
||||
public: // For WebAssembly.
|
||||
Rectangle* getRegion() { return ®ion; }
|
||||
const Rectangle* getFrame() const { return frame; }
|
||||
void setFrame(Rectangle* value) { frame = value; }
|
||||
const TextureAtlasData* getParent() const { return parent; }
|
||||
void setParent(TextureAtlasData* value) { parent = value; }
|
||||
};
|
||||
|
||||
DRAGONBONES_NAMESPACE_END
|
||||
#endif // DRAGONBONES_TEXTUREATLAS_DATA_H
|
@@ -0,0 +1,56 @@
|
||||
#include "UserData.h"
|
||||
|
||||
DRAGONBONES_NAMESPACE_BEGIN
|
||||
|
||||
void UserData::_onClear()
|
||||
{
|
||||
ints.clear();
|
||||
floats.clear();
|
||||
strings.clear();
|
||||
}
|
||||
|
||||
void UserData::addInt(int value)
|
||||
{
|
||||
ints.push_back(value);
|
||||
}
|
||||
|
||||
void UserData::addFloat(float value)
|
||||
{
|
||||
floats.push_back(value);
|
||||
}
|
||||
|
||||
void UserData::addString(std::string value)
|
||||
{
|
||||
strings.push_back(value);
|
||||
}
|
||||
|
||||
int UserData::getInt(unsigned index) const
|
||||
{
|
||||
return index < ints.size() ? ints[index] : 0;
|
||||
}
|
||||
|
||||
float UserData::getFloat(unsigned index) const
|
||||
{
|
||||
return index < floats.size() ? floats[index] : 0;
|
||||
}
|
||||
|
||||
std::string UserData::getString(unsigned index) const
|
||||
{
|
||||
return index < strings.size() ? strings[index] : 0;
|
||||
}
|
||||
|
||||
void ActionData::_onClear()
|
||||
{
|
||||
if (data != nullptr)
|
||||
{
|
||||
data->returnToPool();
|
||||
}
|
||||
|
||||
type = ActionType::Play;
|
||||
name = "";
|
||||
bone = nullptr;
|
||||
slot = nullptr;
|
||||
data = nullptr;
|
||||
}
|
||||
|
||||
DRAGONBONES_NAMESPACE_END
|
175
cocos2d-x/cocos/editor-support/dragonbones/model/UserData.h
Normal file
175
cocos2d-x/cocos/editor-support/dragonbones/model/UserData.h
Normal file
@@ -0,0 +1,175 @@
|
||||
/**
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2012-2018 DragonBones team and other contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef DRAGONBONES_USER_DATA_H
|
||||
#define DRAGONBONES_USER_DATA_H
|
||||
|
||||
#include "../core/BaseObject.h"
|
||||
|
||||
DRAGONBONES_NAMESPACE_BEGIN
|
||||
/**
|
||||
* - The user custom data.
|
||||
* @version DragonBones 5.0
|
||||
* @language en_US
|
||||
*/
|
||||
/**
|
||||
* - 用户自定义数据。
|
||||
* @version DragonBones 5.0
|
||||
* @language zh_CN
|
||||
*/
|
||||
class UserData : public BaseObject
|
||||
{
|
||||
BIND_CLASS_TYPE_A(UserData);
|
||||
|
||||
public:
|
||||
/**
|
||||
* - The custom int numbers.
|
||||
* @version DragonBones 5.0
|
||||
* @language en_US
|
||||
*/
|
||||
/**
|
||||
* - 自定义整数。
|
||||
* @version DragonBones 5.0
|
||||
* @language zh_CN
|
||||
*/
|
||||
std::vector<int> ints;
|
||||
/**
|
||||
* - The custom float numbers.
|
||||
* @version DragonBones 5.0
|
||||
* @language en_US
|
||||
*/
|
||||
/**
|
||||
* - 自定义浮点数。
|
||||
* @version DragonBones 5.0
|
||||
* @language zh_CN
|
||||
*/
|
||||
std::vector<float> floats;
|
||||
/**
|
||||
* - The custom strings.
|
||||
* @version DragonBones 5.0
|
||||
* @language en_US
|
||||
*/
|
||||
/**
|
||||
* - 自定义字符串。
|
||||
* @version DragonBones 5.0
|
||||
* @language zh_CN
|
||||
*/
|
||||
std::vector<std::string> strings;
|
||||
|
||||
protected:
|
||||
virtual void _onClear() override;
|
||||
|
||||
public:
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
void addInt(int value);
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
void addFloat(float value);
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
void addString(std::string value);
|
||||
/**
|
||||
* - Get the custom int number.
|
||||
* @version DragonBones 5.0
|
||||
* @language en_US
|
||||
*/
|
||||
/**
|
||||
* - 获取自定义整数。
|
||||
* @version DragonBones 5.0
|
||||
* @language zh_CN
|
||||
*/
|
||||
int getInt(unsigned index) const;
|
||||
/**
|
||||
* - Get the custom float number.
|
||||
* @version DragonBones 5.0
|
||||
* @language en_US
|
||||
*/
|
||||
/**
|
||||
* - 获取自定义浮点数。
|
||||
* @version DragonBones 5.0
|
||||
* @language zh_CN
|
||||
*/
|
||||
float getFloat(unsigned index) const;
|
||||
/**
|
||||
* - Get the custom string.
|
||||
* @version DragonBones 5.0
|
||||
* @language en_US
|
||||
*/
|
||||
/**
|
||||
* - 获取自定义字符串。
|
||||
* @version DragonBones 5.0
|
||||
* @language zh_CN
|
||||
*/
|
||||
std::string getString(unsigned index) const;
|
||||
|
||||
public: // For WebAssembly.
|
||||
const std::vector<int>& getInts() const { return ints; }
|
||||
const std::vector<float>& getFloats() const { return floats; }
|
||||
const std::vector<std::string>& getStrings() const { return strings; }
|
||||
};
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
class ActionData : public BaseObject
|
||||
{
|
||||
BIND_CLASS_TYPE_B(ActionData);
|
||||
|
||||
public:
|
||||
ActionType type;
|
||||
std::string name;
|
||||
const BoneData* bone;
|
||||
const SlotData* slot;
|
||||
UserData* data;
|
||||
|
||||
ActionData() :
|
||||
data(nullptr)
|
||||
{
|
||||
_onClear();
|
||||
}
|
||||
virtual ~ActionData()
|
||||
{
|
||||
_onClear();
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void _onClear() override;
|
||||
|
||||
public: // For WebAssembly.
|
||||
int getType() const { return (int)type; }
|
||||
void setType(int value) { type = (ActionType)value; }
|
||||
|
||||
const BoneData* getBone() const { return bone; }
|
||||
void setBone(const BoneData* value) { bone = value; }
|
||||
|
||||
const SlotData* getSlot() const { return slot; }
|
||||
void setSlot(const SlotData* value) { slot = value; }
|
||||
|
||||
const UserData* getData() const { return data; }
|
||||
void setData(UserData* value) { data = value; }
|
||||
};
|
||||
|
||||
DRAGONBONES_NAMESPACE_END
|
||||
#endif // DRAGONBONES_USER_DATA_H
|
Reference in New Issue
Block a user