animation_blend_space_1d.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /**************************************************************************/
  2. /* animation_blend_space_1d.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_1D_H
  31. #define ANIMATION_BLEND_SPACE_1D_H
  32. #include "scene/animation/animation_tree.h"
  33. class AnimationNodeBlendSpace1D : public AnimationRootNode {
  34. GDCLASS(AnimationNodeBlendSpace1D, 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. float position = 0.0;
  49. };
  50. BlendPoint blend_points[MAX_BLEND_POINTS];
  51. int blend_points_used = 0;
  52. float max_space = 1.0;
  53. float min_space = -1.0;
  54. float snap = 0.1;
  55. String value_label = "value";
  56. void _add_blend_point(int p_index, const Ref<AnimationRootNode> &p_node);
  57. StringName blend_position = "blend_position";
  58. StringName closest = "closest";
  59. BlendMode blend_mode = BLEND_MODE_INTERPOLATED;
  60. bool sync = false;
  61. void _validate_property(PropertyInfo &p_property) const;
  62. static void _bind_methods();
  63. virtual void _tree_changed() override;
  64. virtual void _animation_node_renamed(const ObjectID &p_oid, const String &p_old_name, const String &p_new_name) override;
  65. virtual void _animation_node_removed(const ObjectID &p_oid, const StringName &p_node) override;
  66. public:
  67. virtual void get_parameter_list(List<PropertyInfo> *r_list) const override;
  68. virtual Variant get_parameter_default_value(const StringName &p_parameter) const override;
  69. virtual void get_child_nodes(List<ChildNode> *r_child_nodes) override;
  70. void add_blend_point(const Ref<AnimationRootNode> &p_node, float p_position, int p_at_index = -1);
  71. void set_blend_point_position(int p_point, float p_position);
  72. void set_blend_point_node(int p_point, const Ref<AnimationRootNode> &p_node);
  73. float get_blend_point_position(int p_point) const;
  74. Ref<AnimationRootNode> get_blend_point_node(int p_point) const;
  75. void remove_blend_point(int p_point);
  76. int get_blend_point_count() const;
  77. void set_min_space(float p_min);
  78. float get_min_space() const;
  79. void set_max_space(float p_max);
  80. float get_max_space() const;
  81. void set_snap(float p_snap);
  82. float get_snap() const;
  83. void set_value_label(const String &p_label);
  84. String get_value_label() const;
  85. void set_blend_mode(BlendMode p_blend_mode);
  86. BlendMode get_blend_mode() const;
  87. void set_use_sync(bool p_sync);
  88. bool is_using_sync() const;
  89. virtual NodeTimeInfo _process(const AnimationMixer::PlaybackInfo p_playback_info, bool p_test_only = false) override;
  90. String get_caption() const override;
  91. Ref<AnimationNode> get_child_by_name(const StringName &p_name) const override;
  92. AnimationNodeBlendSpace1D();
  93. ~AnimationNodeBlendSpace1D();
  94. };
  95. VARIANT_ENUM_CAST(AnimationNodeBlendSpace1D::BlendMode)
  96. #endif // ANIMATION_BLEND_SPACE_1D_H