animation_blend_space_1d.h 4.8 KB

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