animation_blend_space_2d.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  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 = 0;
  52. struct BlendTriangle {
  53. int points[3] = {};
  54. };
  55. Vector<BlendTriangle> triangles;
  56. StringName blend_position = "blend_position";
  57. StringName closest = "closest";
  58. Vector2 max_space = Vector2(1, 1);
  59. Vector2 min_space = Vector2(-1, -1);
  60. Vector2 snap = Vector2(0.1, 0.1);
  61. String x_label = "x";
  62. String y_label = "y";
  63. BlendMode blend_mode = BLEND_MODE_INTERPOLATED;
  64. void _add_blend_point(int p_index, const Ref<AnimationRootNode> &p_node);
  65. void _set_triangles(const Vector<int> &p_triangles);
  66. Vector<int> _get_triangles() const;
  67. void _blend_triangle(const Vector2 &p_pos, const Vector2 *p_points, float *r_weights);
  68. bool auto_triangles = true;
  69. bool trianges_dirty = false;
  70. void _update_triangles();
  71. void _queue_auto_triangles();
  72. bool sync = false;
  73. void _validate_property(PropertyInfo &p_property) const;
  74. static void _bind_methods();
  75. virtual void _tree_changed() override;
  76. virtual void _animation_node_renamed(const ObjectID &p_oid, const String &p_old_name, const String &p_new_name) override;
  77. virtual void _animation_node_removed(const ObjectID &p_oid, const StringName &p_node) override;
  78. public:
  79. virtual void get_parameter_list(List<PropertyInfo> *r_list) const override;
  80. virtual Variant get_parameter_default_value(const StringName &p_parameter) const override;
  81. virtual void get_child_nodes(List<ChildNode> *r_child_nodes) override;
  82. void add_blend_point(const Ref<AnimationRootNode> &p_node, const Vector2 &p_position, int p_at_index = -1);
  83. void set_blend_point_position(int p_point, const Vector2 &p_position);
  84. void set_blend_point_node(int p_point, const Ref<AnimationRootNode> &p_node);
  85. Vector2 get_blend_point_position(int p_point) const;
  86. Ref<AnimationRootNode> get_blend_point_node(int p_point) const;
  87. void remove_blend_point(int p_point);
  88. int get_blend_point_count() const;
  89. bool has_triangle(int p_x, int p_y, int p_z) const;
  90. void add_triangle(int p_x, int p_y, int p_z, int p_at_index = -1);
  91. int get_triangle_point(int p_triangle, int p_point);
  92. void remove_triangle(int p_triangle);
  93. int get_triangle_count() const;
  94. void set_min_space(const Vector2 &p_min);
  95. Vector2 get_min_space() const;
  96. void set_max_space(const Vector2 &p_max);
  97. Vector2 get_max_space() const;
  98. void set_snap(const Vector2 &p_snap);
  99. Vector2 get_snap() const;
  100. void set_x_label(const String &p_label);
  101. String get_x_label() const;
  102. void set_y_label(const String &p_label);
  103. String get_y_label() const;
  104. virtual NodeTimeInfo _process(const AnimationMixer::PlaybackInfo p_playback_info, bool p_test_only = false) override;
  105. virtual String get_caption() const override;
  106. Vector2 get_closest_point(const Vector2 &p_point);
  107. void set_auto_triangles(bool p_enable);
  108. bool get_auto_triangles() const;
  109. void set_blend_mode(BlendMode p_blend_mode);
  110. BlendMode get_blend_mode() const;
  111. void set_use_sync(bool p_sync);
  112. bool is_using_sync() const;
  113. virtual Ref<AnimationNode> get_child_by_name(const StringName &p_name) const override;
  114. AnimationNodeBlendSpace2D();
  115. ~AnimationNodeBlendSpace2D();
  116. };
  117. VARIANT_ENUM_CAST(AnimationNodeBlendSpace2D::BlendMode)
  118. #endif // ANIMATION_BLEND_SPACE_2D_H