载入中...
搜索中...
未找到
SpineSkeletonData.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
5#include <string>
6#include <unordered_map>
7#include <vector>
8
9namespace eve::animation {
10
27public:
29 SpineSkeletonData() = default;
31 ~SpineSkeletonData() = default;
32
35
37 bool loadFromJson(const std::string &json, std::string *error = nullptr);
39 bool loadFromFile(const std::string &path, std::string *error = nullptr);
41 void clear();
42
44 std::string getSpineVersion() const { return spineVersion_; }
45
47 int getBoneCount() const { return static_cast<int>(bones_.size()); }
49 int findBone(const std::string &name) const;
51 std::string getBoneName(int index) const;
53 int getBoneParent(int index) const;
55 float getBoneX(int index) const;
57 float getBoneY(int index) const;
59 float getBoneRotation(int index) const;
61 float getBoneScaleX(int index) const;
63 float getBoneScaleY(int index) const;
64
66 int getSlotCount() const { return static_cast<int>(slots_.size()); }
68 int findSlot(const std::string &name) const;
70 std::string getSlotName(int index) const;
72 int getSlotBone(int index) const;
74 std::string getSlotAttachment(int index) const;
75
77 int getSkinCount() const { return static_cast<int>(skins_.size()); }
79 int findSkin(const std::string &name) const;
81 std::string getSkinName(int index) const;
83 int getDefaultSkin() const { return defaultSkin_; }
84
86 int getAnimationCount() const { return static_cast<int>(anims_.size()); }
88 int findAnimation(const std::string &name) const;
90 std::string getAnimationName(int index) const;
92 float getAnimationDuration(int index) const;
93
94 // --- Internal data accessed by SpineSkeleton / SpineAnim ---
95
97 struct BoneData {
98 std::string name;
99 int parent = -1;
100 float x = 0.f, y = 0.f;
101 float rotation = 0.f;
102 float scaleX = 1.f, scaleY = 1.f;
103 };
104
105 struct SlotData {
106 std::string name;
107 int bone = 0;
108 std::string attachment; // setup pose attachment name (may be empty)
109 };
110
112 std::string name;
113 std::string path; // atlas region key (defaults to name)
114 float x = 0.f, y = 0.f;
115 float rotation = 0.f;
116 float width = 0.f, height = 0.f;
117 float scaleX = 1.f, scaleY = 1.f;
118 };
119
121 using SkinAttachments = std::unordered_map<int, std::unordered_map<std::string, RegionAttachment>>;
122
123 struct SkinData {
124 std::string name;
126 };
127
128 struct FloatKey {
129 float time = 0.f;
130 float value = 0.f;
131 bool stepped = false;
132 };
133
135 float time = 0.f;
136 float x = 0.f, y = 0.f;
137 bool stepped = false;
138 };
139
140 struct ScaleKey {
141 float time = 0.f;
142 float x = 1.f, y = 1.f;
143 bool stepped = false;
144 };
145
147 float time;
148 std::string name; // empty = detach
149 };
150
152 int boneIndex = -1;
153 std::vector<FloatKey> rotate;
154 std::vector<TranslateKey> translate;
155 std::vector<ScaleKey> scale;
156 };
157
159 int slotIndex = -1;
160 std::vector<AttachmentKey> attachment;
161 };
162
164 std::string name;
165 float duration = 0.f;
166 std::vector<BoneTimeline> bones;
167 std::vector<SlotTimeline> slots;
168 };
169
170 const BoneData &bone(int i) const { return bones_.at(static_cast<size_t>(i)); }
171 const SlotData &slot(int i) const { return slots_.at(static_cast<size_t>(i)); }
172 const SkinData &skin(int i) const { return skins_.at(static_cast<size_t>(i)); }
173 const AnimationData &animation(int i) const { return anims_.at(static_cast<size_t>(i)); }
174
175 const RegionAttachment *findAttachment(int skinIndex, int slotIndex,
176 const std::string &name) const;
177
178private:
179 void checkBone(int index) const;
180 void checkSlot(int index) const;
181 void checkSkin(int index) const;
182 void checkAnim(int index) const;
183
184 std::string spineVersion_;
185 std::vector<BoneData> bones_;
186 std::vector<SlotData> slots_;
187 std::vector<SkinData> skins_;
188 std::vector<AnimationData> anims_;
189 std::unordered_map<std::string, int> boneByName_;
190 std::unordered_map<std::string, int> slotByName_;
191 std::unordered_map<std::string, int> skinByName_;
192 std::unordered_map<std::string, int> animByName_;
193 int defaultSkin_ = -1;
194};
195
196} // namespace eve::animation
197
double y
double x
float duration
std::string name
Definition ECS.cpp:154
#define EVENGINE_API_WORLD
Definition Export.h:109
std::uint32_t height
std::uint32_t width
const ColourScope * parent
std::array< float, 4 > rotation
std::uint32_t bone
std::string error
Definition Package.cpp:174
std::string path
Definition PlayHost.cpp:111
Object::Ptr value
uint32_t index
Spine skeleton JSON data (bones / slots / skins / animations).
std::string getSpineVersion() const
Returns the spine version.
int getSkinCount() const
Returns the skin count.
SpineSkeletonData & operator=(const SpineSkeletonData &)=delete
const AnimationData & animation(int i) const
std::unordered_map< int, std::unordered_map< std::string, RegionAttachment > > SkinAttachments
slotIndex → attachmentName → region
SpineSkeletonData()=default
Spine skeleton data.
~SpineSkeletonData()=default
Spine skeleton data.
const SlotData & slot(int i) const
int getBoneCount() const
Returns the bone count.
SpineSkeletonData(const SpineSkeletonData &)=delete
const SkinData & skin(int i) const
int getDefaultSkin() const
Returns the default skin.
int getAnimationCount() const
Returns the animation count.
int getSlotCount() const
Returns the slot count.
const BoneData & bone(int i) const