Skeleton.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /******************************************************************************
  2. * Spine Runtimes Software License v2.5
  3. *
  4. * Copyright (c) 2013-2016, Esoteric Software
  5. * All rights reserved.
  6. *
  7. * You are granted a perpetual, non-exclusive, non-sublicensable, and
  8. * non-transferable license to use, install, execute, and perform the Spine
  9. * Runtimes software and derivative works solely for personal or internal
  10. * use. Without the written permission of Esoteric Software (see Section 2 of
  11. * the Spine Software License Agreement), you may not (a) modify, translate,
  12. * adapt, or develop new applications using the Spine Runtimes or otherwise
  13. * create derivative works or improvements of the Spine Runtimes or (b) remove,
  14. * delete, alter, or obscure any trademarks or any copyright, trademark, patent,
  15. * or other intellectual property or proprietary rights notices on or in the
  16. * Software, including any copy thereof. Redistributions in binary or source
  17. * form must include this license and terms.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE "AS IS" AND ANY EXPRESS OR
  20. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  21. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
  22. * EVENT SHALL ESOTERIC SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  24. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, BUSINESS INTERRUPTION, OR LOSS OF
  25. * USE, DATA, OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
  26. * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  27. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  28. * POSSIBILITY OF SUCH DAMAGE.
  29. *****************************************************************************/
  30. #ifndef SPINE_SKELETON_H_
  31. #define SPINE_SKELETON_H_
  32. #include <spine/SkeletonData.h>
  33. #include <spine/Slot.h>
  34. #include <spine/Skin.h>
  35. #include <spine/IkConstraint.h>
  36. #include <spine/TransformConstraint.h>
  37. #include <spine/PathConstraint.h>
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41. typedef struct spSkeleton {
  42. spSkeletonData* const data;
  43. int bonesCount;
  44. spBone** bones;
  45. spBone* const root;
  46. int slotsCount;
  47. spSlot** slots;
  48. spSlot** drawOrder;
  49. int ikConstraintsCount;
  50. spIkConstraint** ikConstraints;
  51. int transformConstraintsCount;
  52. spTransformConstraint** transformConstraints;
  53. int pathConstraintsCount;
  54. spPathConstraint** pathConstraints;
  55. spSkin* const skin;
  56. float r, g, b, a;
  57. float time;
  58. int/*bool*/flipX, flipY;
  59. float x, y;
  60. #ifdef __cplusplus
  61. spSkeleton() :
  62. data(0),
  63. bonesCount(0),
  64. bones(0),
  65. root(0),
  66. slotsCount(0),
  67. slots(0),
  68. drawOrder(0),
  69. ikConstraintsCount(0),
  70. ikConstraints(0),
  71. transformConstraintsCount(0),
  72. transformConstraints(0),
  73. skin(0),
  74. r(0), g(0), b(0), a(0),
  75. time(0),
  76. flipX(0),
  77. flipY(0),
  78. x(0), y(0) {
  79. }
  80. #endif
  81. } spSkeleton;
  82. spSkeleton* spSkeleton_create (spSkeletonData* data);
  83. void spSkeleton_dispose (spSkeleton* self);
  84. /* Caches information about bones and constraints. Must be called if bones or constraints, or weighted path attachments
  85. * are added or removed. */
  86. void spSkeleton_updateCache (spSkeleton* self);
  87. void spSkeleton_updateWorldTransform (const spSkeleton* self);
  88. /* Sets the bones, constraints, and slots to their setup pose values. */
  89. void spSkeleton_setToSetupPose (const spSkeleton* self);
  90. /* Sets the bones and constraints to their setup pose values. */
  91. void spSkeleton_setBonesToSetupPose (const spSkeleton* self);
  92. void spSkeleton_setSlotsToSetupPose (const spSkeleton* self);
  93. /* Returns 0 if the bone was not found. */
  94. spBone* spSkeleton_findBone (const spSkeleton* self, const char* boneName);
  95. /* Returns -1 if the bone was not found. */
  96. int spSkeleton_findBoneIndex (const spSkeleton* self, const char* boneName);
  97. /* Returns 0 if the slot was not found. */
  98. spSlot* spSkeleton_findSlot (const spSkeleton* self, const char* slotName);
  99. /* Returns -1 if the slot was not found. */
  100. int spSkeleton_findSlotIndex (const spSkeleton* self, const char* slotName);
  101. /* Sets the skin used to look up attachments before looking in the SkeletonData defaultSkin. Attachments from the new skin are
  102. * attached if the corresponding attachment from the old skin was attached. If there was no old skin, each slot's setup mode
  103. * attachment is attached from the new skin.
  104. * @param skin May be 0.*/
  105. void spSkeleton_setSkin (spSkeleton* self, spSkin* skin);
  106. /* Returns 0 if the skin was not found. See spSkeleton_setSkin.
  107. * @param skinName May be 0. */
  108. int spSkeleton_setSkinByName (spSkeleton* self, const char* skinName);
  109. /* Returns 0 if the slot or attachment was not found. */
  110. spAttachment* spSkeleton_getAttachmentForSlotName (const spSkeleton* self, const char* slotName, const char* attachmentName);
  111. /* Returns 0 if the slot or attachment was not found. */
  112. spAttachment* spSkeleton_getAttachmentForSlotIndex (const spSkeleton* self, int slotIndex, const char* attachmentName);
  113. /* Returns 0 if the slot or attachment was not found.
  114. * @param attachmentName May be 0. */
  115. int spSkeleton_setAttachment (spSkeleton* self, const char* slotName, const char* attachmentName);
  116. /* Returns 0 if the IK constraint was not found. */
  117. spIkConstraint* spSkeleton_findIkConstraint (const spSkeleton* self, const char* constraintName);
  118. /* Returns 0 if the transform constraint was not found. */
  119. spTransformConstraint* spSkeleton_findTransformConstraint (const spSkeleton* self, const char* constraintName);
  120. /* Returns 0 if the path constraint was not found. */
  121. spPathConstraint* spSkeleton_findPathConstraint (const spSkeleton* self, const char* constraintName);
  122. void spSkeleton_update (spSkeleton* self, float deltaTime);
  123. #ifdef SPINE_SHORT_NAMES
  124. typedef spSkeleton Skeleton;
  125. #define Skeleton_create(...) spSkeleton_create(__VA_ARGS__)
  126. #define Skeleton_dispose(...) spSkeleton_dispose(__VA_ARGS__)
  127. #define Skeleton_updateWorldTransform(...) spSkeleton_updateWorldTransform(__VA_ARGS__)
  128. #define Skeleton_setToSetupPose(...) spSkeleton_setToSetupPose(__VA_ARGS__)
  129. #define Skeleton_setBonesToSetupPose(...) spSkeleton_setBonesToSetupPose(__VA_ARGS__)
  130. #define Skeleton_setSlotsToSetupPose(...) spSkeleton_setSlotsToSetupPose(__VA_ARGS__)
  131. #define Skeleton_findBone(...) spSkeleton_findBone(__VA_ARGS__)
  132. #define Skeleton_findBoneIndex(...) spSkeleton_findBoneIndex(__VA_ARGS__)
  133. #define Skeleton_findSlot(...) spSkeleton_findSlot(__VA_ARGS__)
  134. #define Skeleton_findSlotIndex(...) spSkeleton_findSlotIndex(__VA_ARGS__)
  135. #define Skeleton_setSkin(...) spSkeleton_setSkin(__VA_ARGS__)
  136. #define Skeleton_setSkinByName(...) spSkeleton_setSkinByName(__VA_ARGS__)
  137. #define Skeleton_getAttachmentForSlotName(...) spSkeleton_getAttachmentForSlotName(__VA_ARGS__)
  138. #define Skeleton_getAttachmentForSlotIndex(...) spSkeleton_getAttachmentForSlotIndex(__VA_ARGS__)
  139. #define Skeleton_setAttachment(...) spSkeleton_setAttachment(__VA_ARGS__)
  140. #define Skeleton_update(...) spSkeleton_update(__VA_ARGS__)
  141. #endif
  142. #ifdef __cplusplus
  143. }
  144. #endif
  145. #endif /* SPINE_SKELETON_H_*/