animation_blend_space_2d.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*************************************************************************/
  2. /* animation_blend_space_2d.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 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 ANIMATION_BLEND_SPACE_2D_H
  31. #define ANIMATION_BLEND_SPACE_2D_H
  32. #include "scene/animation/animation_tree.h"
  33. class AnimationNodeBlendSpace2D : public AnimationRootNode {
  34. GDCLASS(AnimationNodeBlendSpace2D, AnimationRootNode)
  35. public:
  36. enum BlendMode {
  37. BLEND_MODE_INTERPOLATED,
  38. BLEND_MODE_DISCRETE,
  39. BLEND_MODE_DISCRETE_CARRY,
  40. };
  41. protected:
  42. enum {
  43. MAX_BLEND_POINTS = 64
  44. };
  45. struct BlendPoint {
  46. StringName name;
  47. Ref<AnimationRootNode> node;
  48. Vector2 position;
  49. };
  50. BlendPoint blend_points[MAX_BLEND_POINTS];
  51. int blend_points_used;
  52. struct BlendTriangle {
  53. int points[3];
  54. };
  55. Vector<BlendTriangle> triangles;
  56. StringName blend_position;
  57. StringName closest;
  58. StringName length_internal;
  59. Vector2 max_space;
  60. Vector2 min_space;
  61. Vector2 snap;
  62. String x_label;
  63. String y_label;
  64. BlendMode blend_mode;
  65. void _add_blend_point(int p_index, const Ref<AnimationRootNode> &p_node);
  66. void _set_triangles(const Vector<int> &p_triangles);
  67. Vector<int> _get_triangles() const;
  68. void _blend_triangle(const Vector2 &p_pos, const Vector2 *p_points, float *r_weights);
  69. bool auto_triangles;
  70. bool trianges_dirty;
  71. void _update_triangles();
  72. void _tree_changed();
  73. protected:
  74. virtual void _validate_property(PropertyInfo &property) const;
  75. static void _bind_methods();
  76. public:
  77. virtual void get_parameter_list(List<PropertyInfo> *r_list) const;
  78. virtual Variant get_parameter_default_value(const StringName &p_parameter) const;
  79. virtual void get_child_nodes(List<ChildNode> *r_child_nodes);
  80. void add_blend_point(const Ref<AnimationRootNode> &p_node, const Vector2 &p_position, int p_at_index = -1);
  81. void set_blend_point_position(int p_point, const Vector2 &p_position);
  82. void set_blend_point_node(int p_point, const Ref<AnimationRootNode> &p_node);
  83. Vector2 get_blend_point_position(int p_point) const;
  84. Ref<AnimationRootNode> get_blend_point_node(int p_point) const;
  85. void remove_blend_point(int p_point);
  86. int get_blend_point_count() const;
  87. bool has_triangle(int p_x, int p_y, int p_z) const;
  88. void add_triangle(int p_x, int p_y, int p_z, int p_at_index = -1);
  89. int get_triangle_point(int p_triangle, int p_point);
  90. void remove_triangle(int p_triangle);
  91. int get_triangle_count() const;
  92. void set_min_space(const Vector2 &p_min);
  93. Vector2 get_min_space() const;
  94. void set_max_space(const Vector2 &p_max);
  95. Vector2 get_max_space() const;
  96. void set_snap(const Vector2 &p_snap);
  97. Vector2 get_snap() const;
  98. void set_x_label(const String &p_label);
  99. String get_x_label() const;
  100. void set_y_label(const String &p_label);
  101. String get_y_label() const;
  102. virtual float process(float p_time, bool p_seek);
  103. virtual String get_caption() const;
  104. Vector2 get_closest_point(const Vector2 &p_point);
  105. void set_auto_triangles(bool p_enable);
  106. bool get_auto_triangles() const;
  107. void set_blend_mode(BlendMode p_blend_mode);
  108. BlendMode get_blend_mode() const;
  109. virtual Ref<AnimationNode> get_child_by_name(const StringName &p_name);
  110. AnimationNodeBlendSpace2D();
  111. ~AnimationNodeBlendSpace2D();
  112. };
  113. VARIANT_ENUM_CAST(AnimationNodeBlendSpace2D::BlendMode)
  114. #endif // ANIMATION_BLEND_SPACE_2D_H