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 | |
31 | #ifndef ANIMATION_BLEND_SPACE_1D_H |
32 | #define ANIMATION_BLEND_SPACE_1D_H |
33 | |
34 | #include "scene/animation/animation_tree.h" |
35 | |
36 | class AnimationNodeBlendSpace1D : public AnimationRootNode { |
37 | GDCLASS(AnimationNodeBlendSpace1D, AnimationRootNode); |
38 | |
39 | public: |
40 | enum BlendMode { |
41 | BLEND_MODE_INTERPOLATED, |
42 | BLEND_MODE_DISCRETE, |
43 | BLEND_MODE_DISCRETE_CARRY, |
44 | }; |
45 | |
46 | protected: |
47 | enum { |
48 | MAX_BLEND_POINTS = 64 |
49 | }; |
50 | |
51 | struct BlendPoint { |
52 | StringName name; |
53 | Ref<AnimationRootNode> node; |
54 | float position = 0.0; |
55 | }; |
56 | |
57 | BlendPoint blend_points[MAX_BLEND_POINTS]; |
58 | int blend_points_used = 0; |
59 | |
60 | float max_space = 1.0; |
61 | float min_space = -1.0; |
62 | |
63 | float snap = 0.1; |
64 | |
65 | String value_label = "value" ; |
66 | |
67 | void _add_blend_point(int p_index, const Ref<AnimationRootNode> &p_node); |
68 | |
69 | StringName blend_position = "blend_position" ; |
70 | StringName closest = "closest" ; |
71 | StringName length_internal = "length_internal" ; |
72 | |
73 | BlendMode blend_mode = BLEND_MODE_INTERPOLATED; |
74 | |
75 | bool sync = false; |
76 | |
77 | void _validate_property(PropertyInfo &p_property) const; |
78 | static void _bind_methods(); |
79 | |
80 | virtual void _tree_changed() override; |
81 | virtual void _animation_node_renamed(const ObjectID &p_oid, const String &p_old_name, const String &p_new_name) override; |
82 | virtual void _animation_node_removed(const ObjectID &p_oid, const StringName &p_node) override; |
83 | |
84 | public: |
85 | virtual void get_parameter_list(List<PropertyInfo> *r_list) const override; |
86 | virtual Variant get_parameter_default_value(const StringName &p_parameter) const override; |
87 | |
88 | virtual void get_child_nodes(List<ChildNode> *r_child_nodes) override; |
89 | |
90 | void add_blend_point(const Ref<AnimationRootNode> &p_node, float p_position, int p_at_index = -1); |
91 | void set_blend_point_position(int p_point, float p_position); |
92 | void set_blend_point_node(int p_point, const Ref<AnimationRootNode> &p_node); |
93 | |
94 | float get_blend_point_position(int p_point) const; |
95 | Ref<AnimationRootNode> get_blend_point_node(int p_point) const; |
96 | void remove_blend_point(int p_point); |
97 | int get_blend_point_count() const; |
98 | |
99 | void set_min_space(float p_min); |
100 | float get_min_space() const; |
101 | |
102 | void set_max_space(float p_max); |
103 | float get_max_space() const; |
104 | |
105 | void set_snap(float p_snap); |
106 | float get_snap() const; |
107 | |
108 | void set_value_label(const String &p_label); |
109 | String get_value_label() const; |
110 | |
111 | void set_blend_mode(BlendMode p_blend_mode); |
112 | BlendMode get_blend_mode() const; |
113 | |
114 | void set_use_sync(bool p_sync); |
115 | bool is_using_sync() const; |
116 | |
117 | virtual double _process(double p_time, bool p_seek, bool p_is_external_seeking, bool p_test_only = false) override; |
118 | String get_caption() const override; |
119 | |
120 | Ref<AnimationNode> get_child_by_name(const StringName &p_name) const override; |
121 | |
122 | AnimationNodeBlendSpace1D(); |
123 | ~AnimationNodeBlendSpace1D(); |
124 | }; |
125 | |
126 | VARIANT_ENUM_CAST(AnimationNodeBlendSpace1D::BlendMode) |
127 | |
128 | #endif // ANIMATION_BLEND_SPACE_1D_H |
129 | |