载入中...
搜索中...
未找到
SpineSkeletonData.h
浏览该文件的文档.
1#pragma once
2
3#include <string>
4#include <unordered_map>
5#include <vector>
6
7namespace eve::animation {
8
22public:
23 SpineSkeletonData() = default;
24 ~SpineSkeletonData() = default;
25
28
29 bool loadFromJson(const std::string &json, std::string *error = nullptr);
30 bool loadFromFile(const std::string &path, std::string *error = nullptr);
31 void clear();
32
33 std::string getSpineVersion() const { return spineVersion_; }
34
35 int getBoneCount() const { return static_cast<int>(bones_.size()); }
36 int findBone(const std::string &name) const;
37 std::string getBoneName(int index) const;
38 int getBoneParent(int index) const;
39 float getBoneX(int index) const;
40 float getBoneY(int index) const;
41 float getBoneRotation(int index) const;
42 float getBoneScaleX(int index) const;
43 float getBoneScaleY(int index) const;
44
45 int getSlotCount() const { return static_cast<int>(slots_.size()); }
46 int findSlot(const std::string &name) const;
47 std::string getSlotName(int index) const;
48 int getSlotBone(int index) const;
49 std::string getSlotAttachment(int index) const;
50
51 int getSkinCount() const { return static_cast<int>(skins_.size()); }
52 int findSkin(const std::string &name) const;
53 std::string getSkinName(int index) const;
54 int getDefaultSkin() const { return defaultSkin_; }
55
56 int getAnimationCount() const { return static_cast<int>(anims_.size()); }
57 int findAnimation(const std::string &name) const;
58 std::string getAnimationName(int index) const;
59 float getAnimationDuration(int index) const;
60
61 // --- Internal data accessed by SpineSkeleton / SpineAnim ---
62
63 struct BoneData {
64 std::string name;
65 int parent = -1;
66 float x = 0.f, y = 0.f;
67 float rotation = 0.f;
68 float scaleX = 1.f, scaleY = 1.f;
69 };
70
71 struct SlotData {
72 std::string name;
73 int bone = 0;
74 std::string attachment; // setup pose attachment name (may be empty)
75 };
76
78 std::string name;
79 std::string path; // atlas region key (defaults to name)
80 float x = 0.f, y = 0.f;
81 float rotation = 0.f;
82 float width = 0.f, height = 0.f;
83 float scaleX = 1.f, scaleY = 1.f;
84 };
85
87 using SkinAttachments = std::unordered_map<int, std::unordered_map<std::string, RegionAttachment>>;
88
89 struct SkinData {
90 std::string name;
92 };
93
94 struct FloatKey {
95 float time = 0.f;
96 float value = 0.f;
97 bool stepped = false;
98 };
99
101 float time = 0.f;
102 float x = 0.f, y = 0.f;
103 bool stepped = false;
104 };
105
106 struct ScaleKey {
107 float time = 0.f;
108 float x = 1.f, y = 1.f;
109 bool stepped = false;
110 };
111
113 float time;
114 std::string name; // empty = detach
115 };
116
118 int boneIndex = -1;
119 std::vector<FloatKey> rotate;
120 std::vector<TranslateKey> translate;
121 std::vector<ScaleKey> scale;
122 };
123
125 int slotIndex = -1;
126 std::vector<AttachmentKey> attachment;
127 };
128
130 std::string name;
131 float duration = 0.f;
132 std::vector<BoneTimeline> bones;
133 std::vector<SlotTimeline> slots;
134 };
135
136 const BoneData &bone(int i) const { return bones_.at(static_cast<size_t>(i)); }
137 const SlotData &slot(int i) const { return slots_.at(static_cast<size_t>(i)); }
138 const SkinData &skin(int i) const { return skins_.at(static_cast<size_t>(i)); }
139 const AnimationData &animation(int i) const { return anims_.at(static_cast<size_t>(i)); }
140
141 const RegionAttachment *findAttachment(int skinIndex, int slotIndex,
142 const std::string &name) const;
143
144private:
145 void checkBone(int index) const;
146 void checkSlot(int index) const;
147 void checkSkin(int index) const;
148 void checkAnim(int index) const;
149
150 std::string spineVersion_;
151 std::vector<BoneData> bones_;
152 std::vector<SlotData> slots_;
153 std::vector<SkinData> skins_;
154 std::vector<AnimationData> anims_;
155 std::unordered_map<std::string, int> boneByName_;
156 std::unordered_map<std::string, int> slotByName_;
157 std::unordered_map<std::string, int> skinByName_;
158 std::unordered_map<std::string, int> animByName_;
159 int defaultSkin_ = -1;
160};
161
162} // namespace eve::animation
std::string error
const char * name
Definition RockMesh.cpp:21
Spine skeleton JSON data (bones / slots / skins / animations).
float getAnimationDuration(int index) const
SpineSkeletonData & operator=(const SpineSkeletonData &)=delete
bool loadFromFile(const std::string &path, std::string *error=nullptr)
int findSkin(const std::string &name) const
std::string getSkinName(int index) const
bool loadFromJson(const std::string &json, std::string *error=nullptr)
const AnimationData & animation(int i) const
const RegionAttachment * findAttachment(int skinIndex, int slotIndex, const std::string &name) const
int findAnimation(const std::string &name) const
std::unordered_map< int, std::unordered_map< std::string, RegionAttachment > > SkinAttachments
slotIndex → attachmentName → region
std::string getSlotAttachment(int index) const
const SlotData & slot(int i) const
std::string getSlotName(int index) const
int findSlot(const std::string &name) const
SpineSkeletonData(const SpineSkeletonData &)=delete
std::string getBoneName(int index) const
const SkinData & skin(int i) const
std::string getAnimationName(int index) const
int findBone(const std::string &name) const
const BoneData & bone(int i) const