skeleton.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*************************************************************************/
  2. /* skeleton.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #ifndef SKELETON_H
  31. #define SKELETON_H
  32. #include "rid.h"
  33. #include "scene/3d/spatial.h"
  34. /**
  35. @author Juan Linietsky <reduzio@gmail.com>
  36. */
  37. class Skeleton : public Spatial {
  38. GDCLASS(Skeleton, Spatial);
  39. struct Bone {
  40. String name;
  41. bool enabled;
  42. int parent;
  43. bool disable_rest;
  44. Transform rest;
  45. Transform rest_global_inverse;
  46. Transform pose;
  47. Transform pose_global;
  48. bool custom_pose_enable;
  49. Transform custom_pose;
  50. List<uint32_t> nodes_bound;
  51. Bone() {
  52. parent = -1;
  53. enabled = true;
  54. custom_pose_enable = false;
  55. disable_rest = false;
  56. }
  57. };
  58. bool rest_global_inverse_dirty;
  59. Vector<Bone> bones;
  60. RID skeleton;
  61. void _make_dirty();
  62. bool dirty;
  63. //bind helpers
  64. Array _get_bound_child_nodes_to_bone(int p_bone) const {
  65. Array bound;
  66. List<Node *> childs;
  67. get_bound_child_nodes_to_bone(p_bone, &childs);
  68. for (int i = 0; i < childs.size(); i++) {
  69. bound.push_back(childs[i]);
  70. }
  71. return bound;
  72. }
  73. protected:
  74. bool _get(const StringName &p_path, Variant &r_ret) const;
  75. bool _set(const StringName &p_path, const Variant &p_value);
  76. void _get_property_list(List<PropertyInfo> *p_list) const;
  77. void _notification(int p_what);
  78. static void _bind_methods();
  79. public:
  80. enum {
  81. NOTIFICATION_UPDATE_SKELETON = 50
  82. };
  83. RID get_skeleton() const;
  84. // skeleton creation api
  85. void add_bone(const String &p_name);
  86. int find_bone(String p_name) const;
  87. String get_bone_name(int p_bone) const;
  88. void set_bone_parent(int p_bone, int p_parent);
  89. int get_bone_parent(int p_bone) const;
  90. void unparent_bone_and_rest(int p_bone);
  91. void set_bone_disable_rest(int p_bone, bool p_disable);
  92. bool is_bone_rest_disabled(int p_bone) const;
  93. int get_bone_count() const;
  94. void set_bone_rest(int p_bone, const Transform &p_rest);
  95. Transform get_bone_rest(int p_bone) const;
  96. Transform get_bone_transform(int p_bone) const;
  97. Transform get_bone_global_pose(int p_bone) const;
  98. void set_bone_global_pose(int p_bone, const Transform &p_pose);
  99. void set_bone_enabled(int p_bone, bool p_enabled);
  100. bool is_bone_enabled(int p_bone) const;
  101. void bind_child_node_to_bone(int p_bone, Node *p_node);
  102. void unbind_child_node_from_bone(int p_bone, Node *p_node);
  103. void get_bound_child_nodes_to_bone(int p_bone, List<Node *> *p_bound) const;
  104. void clear_bones();
  105. // posing api
  106. void set_bone_pose(int p_bone, const Transform &p_pose);
  107. Transform get_bone_pose(int p_bone) const;
  108. void set_bone_custom_pose(int p_bone, const Transform &p_custom_pose);
  109. Transform get_bone_custom_pose(int p_bone) const;
  110. void localize_rests(); // used for loaders and tools
  111. Skeleton();
  112. ~Skeleton();
  113. };
  114. #endif