axmol/extensions/DragonBones/model/ArmatureData.h

482 lines
11 KiB
C
Raw Normal View History

/**
* 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:
2021-12-25 10:04:45 +08:00
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
2021-12-25 10:04:45 +08:00
*
* 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
*/
/**
2021-12-24 21:11:44 +08:00
* -
* @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
*/
/**
2021-12-24 21:11:44 +08:00
* -
* @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
*/
/**
2021-12-24 21:11:44 +08:00
* -
* @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
*/
/**
2021-12-24 21:11:44 +08:00
* -
* @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
*/
hlookup::string_map<BoneData*> bones;
/**
* @private
*/
hlookup::string_map<SlotData*> slots;
/**
* @private
*/
hlookup::string_map<ConstraintData*> constraints;
/**
* @private
*/
hlookup::string_map<SkinData*> skins;
/**
* @private
*/
hlookup::string_map<AnimationData*> animations;
/**
* - The default skin data.
* @version DragonBones 4.5
* @language en_US
*/
/**
2021-12-24 21:11:44 +08:00
* -
* @version DragonBones 4.5
* @language zh_CN
*/
SkinData* defaultSkin;
/**
* - The default animation data.
* @version DragonBones 4.5
* @language en_US
*/
/**
2021-12-24 21:11:44 +08:00
* -
* @version DragonBones 4.5
* @language zh_CN
*/
AnimationData* defaultAnimation;
/**
* @private
*/
CanvasData* canvas;
/**
* @private
*/
UserData* userData;
/**
* @private
*/
DragonBonesData* parent;
2021-12-25 10:04:45 +08:00
ArmatureData() : canvas(nullptr), userData(nullptr) { _onClear(); }
~ArmatureData() { _onClear(); }
protected:
2021-12-25 10:04:45 +08:00
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
*/
/**
2021-12-24 21:11:44 +08:00
* -
* @param boneName -
* @version DragonBones 3.0
* @language zh_CN
*/
inline BoneData* getBone(std::string_view boneName) const { return mapFind(bones, boneName); }
/**
* - Get a specific slot data.
* @param slotName - The slot name.
* @version DragonBones 3.0
* @language en_US
*/
/**
2021-12-24 21:11:44 +08:00
* -
* @param slotName -
* @version DragonBones 3.0
* @language zh_CN
*/
inline SlotData* getSlot(std::string_view slotName) const { return mapFind(slots, slotName); }
/**
* @private
*/
inline ConstraintData* getConstraint(std::string_view constraintName) const
{
return mapFind(constraints, constraintName);
}
/**
* - Get a specific skin data.
* @param skinName - The skin name.
* @version DragonBones 3.0
* @language en_US
*/
/**
2021-12-24 21:11:44 +08:00
* -
* @param skinName -
* @version DragonBones 3.0
* @language zh_CN
*/
inline SkinData* getSkin(std::string_view skinName) const { return mapFind(skins, skinName); }
/**
* @private
*/
MeshDisplayData* getMesh(std::string_view skinName, std::string_view slotName, std::string_view meshName) const;
/**
* - Get a specific animation data.
* @param animationName - The animation animationName.
* @version DragonBones 3.0
* @language en_US
*/
/**
2021-12-24 21:11:44 +08:00
* -
* @param animationName -
* @version DragonBones 3.0
* @language zh_CN
*/
inline AnimationData* getAnimation(std::string_view animationName) const
{
return mapFind(animations, animationName);
}
2021-12-25 10:04:45 +08:00
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
*/
/**
2021-12-24 21:11:44 +08:00
* -
* @version DragonBones 3.0
* @language zh_CN
*/
2021-12-25 10:04:45 +08:00
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
*/
/**
2021-12-24 21:11:44 +08:00
* -
* @version DragonBones 3.0
* @language zh_CN
*/
float length;
/**
* - The bone name.
* @version DragonBones 3.0
* @language en_US
*/
/**
2021-12-24 21:11:44 +08:00
* -
* @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
*/
/**
2021-12-24 21:11:44 +08:00
* -
* @version DragonBones 3.0
* @language zh_CN
*/
BoneData* parent;
2021-12-25 10:04:45 +08:00
BoneData() : userData(nullptr) { _onClear(); }
~BoneData() { _onClear(); }
protected:
virtual void _onClear() override;
2021-12-25 10:04:45 +08:00
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
*/
/**
2021-12-24 21:11:44 +08:00
* -
* @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
*/
/**
2021-12-24 21:11:44 +08:00
* -
* @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
*/
/**
2021-12-24 21:11:44 +08:00
* -
* @version DragonBones 3.0
* @language zh_CN
*/
BoneData* parent;
2021-12-25 10:04:45 +08:00
SlotData() : color(nullptr), userData(nullptr) { _onClear(); }
~SlotData() { _onClear(); }
protected:
virtual void _onClear() override;
2021-12-25 10:04:45 +08:00
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
2021-12-25 10:04:45 +08:00
#endif // DRAGONBONES_ARMATURE_DATA_H