载入中...
搜索中...
未找到
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
24public:
26 SpineSkeletonData() = default;
28 ~SpineSkeletonData() = default;
29
32
34 bool loadFromJson(const std::string &json, std::string *error = nullptr);
36 bool loadFromFile(const std::string &path, std::string *error = nullptr);
38 void clear();
39
41 std::string getSpineVersion() const { return spineVersion_; }
42
44 int getBoneCount() const { return static_cast<int>(bones_.size()); }
46 int findBone(const std::string &name) const;
48 std::string getBoneName(int index) const;
50 int getBoneParent(int index) const;
52 float getBoneX(int index) const;
54 float getBoneY(int index) const;
56 float getBoneRotation(int index) const;
58 float getBoneScaleX(int index) const;
60 float getBoneScaleY(int index) const;
61
63 int getSlotCount() const { return static_cast<int>(slots_.size()); }
65 int findSlot(const std::string &name) const;
67 std::string getSlotName(int index) const;
69 int getSlotBone(int index) const;
71 std::string getSlotAttachment(int index) const;
72
74 int getSkinCount() const { return static_cast<int>(skins_.size()); }
76 int findSkin(const std::string &name) const;
78 std::string getSkinName(int index) const;
80 int getDefaultSkin() const { return defaultSkin_; }
81
83 int getAnimationCount() const { return static_cast<int>(anims_.size()); }
85 int findAnimation(const std::string &name) const;
87 std::string getAnimationName(int index) const;
89 float getAnimationDuration(int index) const;
90
91 // --- Internal data accessed by SpineSkeleton / SpineAnim ---
92
94 struct BoneData {
95 std::string name;
96 int parent = -1;
97 float x = 0.f, y = 0.f;
98 float rotation = 0.f;
99 float scaleX = 1.f, scaleY = 1.f;
100 };
101
102 struct SlotData {
103 std::string name;
104 int bone = 0;
105 std::string attachment; // setup pose attachment name (may be empty)
106 };
107
109 std::string name;
110 std::string path; // atlas region key (defaults to name)
111 float x = 0.f, y = 0.f;
112 float rotation = 0.f;
113 float width = 0.f, height = 0.f;
114 float scaleX = 1.f, scaleY = 1.f;
115 };
116
118 using SkinAttachments = std::unordered_map<int, std::unordered_map<std::string, RegionAttachment>>;
119
120 struct SkinData {
121 std::string name;
123 };
124
125 struct FloatKey {
126 float time = 0.f;
127 float value = 0.f;
128 bool stepped = false;
129 };
130
132 float time = 0.f;
133 float x = 0.f, y = 0.f;
134 bool stepped = false;
135 };
136
137 struct ScaleKey {
138 float time = 0.f;
139 float x = 1.f, y = 1.f;
140 bool stepped = false;
141 };
142
144 float time;
145 std::string name; // empty = detach
146 };
147
149 int boneIndex = -1;
150 std::vector<FloatKey> rotate;
151 std::vector<TranslateKey> translate;
152 std::vector<ScaleKey> scale;
153 };
154
156 int slotIndex = -1;
157 std::vector<AttachmentKey> attachment;
158 };
159
161 std::string name;
162 float duration = 0.f;
163 std::vector<BoneTimeline> bones;
164 std::vector<SlotTimeline> slots;
165 };
166
167 const BoneData &bone(int i) const { return bones_.at(static_cast<size_t>(i)); }
168 const SlotData &slot(int i) const { return slots_.at(static_cast<size_t>(i)); }
169 const SkinData &skin(int i) const { return skins_.at(static_cast<size_t>(i)); }
170 const AnimationData &animation(int i) const { return anims_.at(static_cast<size_t>(i)); }
171
172 const RegionAttachment *findAttachment(int skinIndex, int slotIndex,
173 const std::string &name) const;
174
175private:
176 void checkBone(int index) const;
177 void checkSlot(int index) const;
178 void checkSkin(int index) const;
179 void checkAnim(int index) const;
180
181 std::string spineVersion_;
182 std::vector<BoneData> bones_;
183 std::vector<SlotData> slots_;
184 std::vector<SkinData> skins_;
185 std::vector<AnimationData> anims_;
186 std::unordered_map<std::string, int> boneByName_;
187 std::unordered_map<std::string, int> slotByName_;
188 std::unordered_map<std::string, int> skinByName_;
189 std::unordered_map<std::string, int> animByName_;
190 int defaultSkin_ = -1;
191};
192
193} // namespace eve::animation
double value
float y
Definition AnimClip.cpp:738
float x
Definition AnimClip.cpp:738
float duration
#define EVENGINE_API_WORLD
Definition Export.h:109
std::uint32_t height
std::uint32_t width
std::array< float, 4 > rotation
std::uint32_t bone
std::int32_t parent
std::string name
std::string error
Definition Package.cpp:60
std::string path
Definition PlayHost.cpp:110
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