SpriterData2D.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. //
  2. // Copyright (c) 2008-2017 the Urho3D project.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #pragma once
  23. namespace pugi
  24. {
  25. class xml_node;
  26. }
  27. namespace Atomic
  28. {
  29. namespace Spriter
  30. {
  31. struct Animation;
  32. struct BoneTimelineKey;
  33. struct CharacterMap;
  34. struct Entity;
  35. struct File;
  36. struct Folder;
  37. struct MainlineKey;
  38. struct MapInstruction;
  39. struct Ref;
  40. struct SpatialInfo;
  41. struct SpatialTimelineKey;
  42. struct SpriterData;
  43. struct SpriteTimelineKey;
  44. struct Timeline;
  45. struct TimelineKey;
  46. /// Spriter data.
  47. struct SpriterData
  48. {
  49. SpriterData();
  50. ~SpriterData();
  51. void Reset();
  52. bool Load(const pugi::xml_node& node);
  53. bool Load(const void* data, size_t size);
  54. int scmlVersion_;
  55. String generator_;
  56. String generatorVersion_;
  57. PODVector<Folder*> folders_;
  58. PODVector<Entity*> entities_;
  59. };
  60. /// Folder.
  61. struct Folder
  62. {
  63. Folder();
  64. ~Folder();
  65. void Reset();
  66. bool Load(const pugi::xml_node& node);
  67. int id_;
  68. String name_;
  69. PODVector<File*> files_;
  70. };
  71. /// File.
  72. struct File
  73. {
  74. File(Folder* folder);
  75. ~File();
  76. bool Load(const pugi::xml_node& node);
  77. Folder* folder_;
  78. int id_;
  79. String name_;
  80. float width_;
  81. float height_;
  82. float pivotX_;
  83. float pivotY_;
  84. };
  85. /// Entity.
  86. struct Entity
  87. {
  88. Entity();
  89. ~Entity();
  90. void Reset();
  91. bool Load(const pugi::xml_node& node);
  92. int id_;
  93. String name_;
  94. PODVector<CharacterMap*> characterMaps_;
  95. PODVector<Animation*> animations_;
  96. };
  97. /// Character map.
  98. struct CharacterMap
  99. {
  100. CharacterMap();
  101. ~CharacterMap();
  102. void Reset();
  103. bool Load(const pugi::xml_node& node);
  104. int id_;
  105. String name_;
  106. PODVector<MapInstruction*> maps_;
  107. };
  108. /// Map instruction.
  109. struct MapInstruction
  110. {
  111. MapInstruction();
  112. ~MapInstruction();
  113. bool Load(const pugi::xml_node& node);
  114. int folder_;
  115. int file_;
  116. int targetFolder_;
  117. int targetFile_;
  118. };
  119. /// Animation.
  120. struct Animation
  121. {
  122. Animation();
  123. ~Animation();
  124. void Reset();
  125. bool Load(const pugi::xml_node& node);
  126. int id_;
  127. String name_;
  128. float length_;
  129. bool looping_;
  130. PODVector<MainlineKey*> mainlineKeys_;
  131. PODVector<Timeline*> timelines_;
  132. };
  133. /// Mainline key.
  134. struct MainlineKey
  135. {
  136. MainlineKey();
  137. ~MainlineKey();
  138. void Reset();
  139. bool Load(const pugi::xml_node& node);
  140. int id_;
  141. float time_;
  142. PODVector<Ref*> boneRefs_;
  143. PODVector<Ref*> objectRefs_;
  144. };
  145. /// Ref.
  146. struct Ref
  147. {
  148. Ref();
  149. ~Ref();
  150. bool Load(const pugi::xml_node& node);
  151. int id_;
  152. int parent_;
  153. int timeline_;
  154. int key_;
  155. int zIndex_;
  156. };
  157. /// Object type.
  158. enum ObjectType
  159. {
  160. BONE = 0,
  161. SPRITE
  162. };
  163. /// Timeline.
  164. struct Timeline
  165. {
  166. Timeline();
  167. ~Timeline();
  168. void Reset();
  169. bool Load(const pugi::xml_node& node);
  170. int id_;
  171. String name_;
  172. ObjectType objectType_;
  173. PODVector<SpatialTimelineKey*> keys_;
  174. };
  175. /// Curve type.
  176. enum CurveType
  177. {
  178. INSTANT = 0,
  179. LINEAR,
  180. QUADRATIC,
  181. CUBIC
  182. };
  183. /// Timeline key.
  184. struct TimelineKey
  185. {
  186. TimelineKey(Timeline* timeline);
  187. virtual ~TimelineKey();
  188. virtual ObjectType GetObjectType() const = 0;
  189. virtual TimelineKey* Clone() const = 0;
  190. virtual bool Load(const pugi::xml_node& node);
  191. virtual void Interpolate(const TimelineKey& other, float t) = 0;
  192. TimelineKey& operator=(const TimelineKey& rhs);
  193. float GetTByCurveType(float currentTime, float nextTimelineTime) const;
  194. Timeline* timeline_;
  195. int id_;
  196. float time_;
  197. CurveType curveType_;
  198. float c1_;
  199. float c2_;
  200. };
  201. /// Spatial info.
  202. struct SpatialInfo
  203. {
  204. float x_;
  205. float y_;
  206. float angle_;
  207. float scaleX_;
  208. float scaleY_;
  209. float alpha_;
  210. int spin;
  211. SpatialInfo(float x = 0.0f, float y = 0.0f, float angle = 0.0f, float scale_x = 1, float scale_y = 1, float a = 1, int spin = 1);
  212. SpatialInfo UnmapFromParent(const SpatialInfo& parentInfo) const;
  213. void Interpolate(const SpatialInfo& other, float t);
  214. };
  215. /// Spatial timeline key.
  216. struct SpatialTimelineKey : TimelineKey
  217. {
  218. SpatialInfo info_;
  219. SpatialTimelineKey(Timeline* timeline);
  220. virtual ~SpatialTimelineKey();
  221. virtual bool Load(const pugi::xml_node& node);
  222. virtual void Interpolate(const TimelineKey& other, float t);
  223. SpatialTimelineKey& operator=(const SpatialTimelineKey& rhs);
  224. };
  225. /// Bone timeline key.
  226. struct BoneTimelineKey : SpatialTimelineKey
  227. {
  228. float length_;
  229. float width_;
  230. BoneTimelineKey(Timeline* timeline);
  231. virtual ~BoneTimelineKey();
  232. virtual ObjectType GetObjectType() const { return BONE; }
  233. virtual TimelineKey* Clone() const;
  234. virtual bool Load(const pugi::xml_node& node);
  235. virtual void Interpolate(const TimelineKey& other, float t);
  236. BoneTimelineKey& operator=(const BoneTimelineKey& rhs);
  237. };
  238. /// Sprite timeline key.
  239. struct SpriteTimelineKey : SpatialTimelineKey
  240. {
  241. int folderId_;
  242. int fileId_;
  243. bool useDefaultPivot_;
  244. float pivotX_;
  245. float pivotY_;
  246. /// Run time data.
  247. int zIndex_;
  248. SpriteTimelineKey(Timeline* timeline);
  249. virtual ~SpriteTimelineKey();
  250. virtual ObjectType GetObjectType() const { return SPRITE; }
  251. virtual TimelineKey* Clone() const;
  252. virtual bool Load(const pugi::xml_node& node);
  253. virtual void Interpolate(const TimelineKey& other, float t);
  254. SpriteTimelineKey& operator=(const SpriteTimelineKey& rhs);
  255. };
  256. }
  257. }