| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "scene/animation/animation_tree.h" |
| 34 |
#include "scene/resources/curve.h" |
| 35 |
|
| 36 |
class AnimationNodeAnimation : public AnimationRootNode { |
| 37 |
GDCLASS(AnimationNodeAnimation, AnimationRootNode); |
| 38 |
|
| 39 |
StringName backward = "backward"; |
| 40 |
|
| 41 |
StringName animation; |
| 42 |
|
| 43 |
bool advance_on_start = false; |
| 44 |
|
| 45 |
bool use_custom_timeline = false; |
| 46 |
double timeline_length = 1.0; |
| 47 |
Animation::LoopMode loop_mode = Animation::LOOP_NONE; |
| 48 |
bool stretch_time_scale = true; |
| 49 |
double start_offset = 0.0; |
| 50 |
|
| 51 |
public: |
| 52 |
enum PlayMode { |
| 53 |
PLAY_MODE_FORWARD, |
| 54 |
PLAY_MODE_BACKWARD |
| 55 |
}; |
| 56 |
|
| 57 |
void get_parameter_list(List<PropertyInfo> *r_list) const override; |
| 58 |
virtual Variant get_parameter_default_value(const StringName &p_parameter) const override; |
| 59 |
|
| 60 |
virtual NodeTimeInfo get_node_time_info() const override; |
| 61 |
|
| 62 |
static Vector<String> (*get_editable_animation_list)(); |
| 63 |
|
| 64 |
virtual String get_caption() const override; |
| 65 |
virtual NodeTimeInfo process(const AnimationMixer::PlaybackInfo p_playback_info, bool p_test_only = false) override; |
| 66 |
virtual NodeTimeInfo _process(const AnimationMixer::PlaybackInfo p_playback_info, bool p_test_only = false) override; |
| 67 |
|
| 68 |
void set_animation(const StringName &p_name); |
| 69 |
StringName get_animation() const; |
| 70 |
|
| 71 |
void set_play_mode(PlayMode p_play_mode); |
| 72 |
PlayMode get_play_mode() const; |
| 73 |
|
| 74 |
void set_backward(bool p_backward); |
| 75 |
bool is_backward() const; |
| 76 |
|
| 77 |
void set_advance_on_start(bool p_advance_on_start); |
| 78 |
bool is_advance_on_start() const; |
| 79 |
|
| 80 |
void set_use_custom_timeline(bool p_use_custom_timeline); |
| 81 |
bool is_using_custom_timeline() const; |
| 82 |
|
| 83 |
void set_timeline_length(double p_length); |
| 84 |
double get_timeline_length() const; |
| 85 |
|
| 86 |
void set_stretch_time_scale(bool p_stretch_time_scale); |
| 87 |
bool is_stretching_time_scale() const; |
| 88 |
|
| 89 |
void set_start_offset(double p_offset); |
| 90 |
double get_start_offset() const; |
| 91 |
|
| 92 |
void set_loop_mode(Animation::LoopMode p_loop_mode); |
| 93 |
Animation::LoopMode get_loop_mode() const; |
| 94 |
|
| 95 |
AnimationNodeAnimation(); |
| 96 |
|
| 97 |
protected: |
| 98 |
void _validate_property(PropertyInfo &p_property) const; |
| 99 |
static void _bind_methods(); |
| 100 |
|
| 101 |
private: |
| 102 |
PlayMode play_mode = PLAY_MODE_FORWARD; |
| 103 |
}; |
| 104 |
|
| 105 |
VARIANT_ENUM_CAST(AnimationNodeAnimation::PlayMode) |
| 106 |
|
| 107 |
class AnimationNodeSync : public AnimationNode { |
| 108 |
GDCLASS(AnimationNodeSync, AnimationNode); |
| 109 |
|
| 110 |
protected: |
| 111 |
bool sync = false; |
| 112 |
|
| 113 |
static void _bind_methods(); |
| 114 |
|
| 115 |
public: |
| 116 |
void set_use_sync(bool p_sync); |
| 117 |
bool is_using_sync() const; |
| 118 |
|
| 119 |
AnimationNodeSync(); |
| 120 |
}; |
| 121 |
|
| 122 |
class AnimationNodeOneShot : public AnimationNodeSync { |
| 123 |
GDCLASS(AnimationNodeOneShot, AnimationNodeSync); |
| 124 |
|
| 125 |
public: |
| 126 |
enum OneShotRequest { |
| 127 |
ONE_SHOT_REQUEST_NONE, |
| 128 |
ONE_SHOT_REQUEST_FIRE, |
| 129 |
ONE_SHOT_REQUEST_ABORT, |
| 130 |
ONE_SHOT_REQUEST_FADE_OUT, |
| 131 |
}; |
| 132 |
|
| 133 |
enum MixMode { |
| 134 |
MIX_MODE_BLEND, |
| 135 |
MIX_MODE_ADD |
| 136 |
}; |
| 137 |
|
| 138 |
private: |
| 139 |
double fade_in = 0.0; |
| 140 |
Ref<Curve> fade_in_curve; |
| 141 |
double fade_out = 0.0; |
| 142 |
Ref<Curve> fade_out_curve; |
| 143 |
|
| 144 |
bool auto_restart = false; |
| 145 |
double auto_restart_delay = 1.0; |
| 146 |
double auto_restart_random_delay = 0.0; |
| 147 |
MixMode mix = MIX_MODE_BLEND; |
| 148 |
bool break_loop_at_end = false; |
| 149 |
bool abort_on_reset = false; |
| 150 |
|
| 151 |
StringName request = PNAME("request"); |
| 152 |
StringName active = PNAME("active"); |
| 153 |
StringName internal_active = PNAME("internal_active"); |
| 154 |
StringName fade_in_remaining = "fade_in_remaining"; |
| 155 |
StringName fade_out_remaining = "fade_out_remaining"; |
| 156 |
StringName time_to_restart = "time_to_restart"; |
| 157 |
|
| 158 |
protected: |
| 159 |
static void _bind_methods(); |
| 160 |
|
| 161 |
public: |
| 162 |
virtual void get_parameter_list(List<PropertyInfo> *r_list) const override; |
| 163 |
virtual Variant get_parameter_default_value(const StringName &p_parameter) const override; |
| 164 |
virtual bool is_parameter_read_only(const StringName &p_parameter) const override; |
| 165 |
|
| 166 |
virtual String get_caption() const override; |
| 167 |
|
| 168 |
void set_fade_in_time(double p_time); |
| 169 |
double get_fade_in_time() const; |
| 170 |
|
| 171 |
void set_fade_in_curve(const Ref<Curve> &p_curve); |
| 172 |
Ref<Curve> get_fade_in_curve() const; |
| 173 |
|
| 174 |
void set_fade_out_time(double p_time); |
| 175 |
double get_fade_out_time() const; |
| 176 |
|
| 177 |
void set_fade_out_curve(const Ref<Curve> &p_curve); |
| 178 |
Ref<Curve> get_fade_out_curve() const; |
| 179 |
|
| 180 |
void set_auto_restart_enabled(bool p_enabled); |
| 181 |
void set_auto_restart_delay(double p_time); |
| 182 |
void set_auto_restart_random_delay(double p_time); |
| 183 |
|
| 184 |
bool is_auto_restart_enabled() const; |
| 185 |
double get_auto_restart_delay() const; |
| 186 |
double get_auto_restart_random_delay() const; |
| 187 |
|
| 188 |
void set_mix_mode(MixMode p_mix); |
| 189 |
MixMode get_mix_mode() const; |
| 190 |
|
| 191 |
void set_break_loop_at_end(bool p_enable); |
| 192 |
bool is_loop_broken_at_end() const; |
| 193 |
|
| 194 |
void set_abort_on_reset(bool p_enable); |
| 195 |
bool is_aborted_on_reset() const; |
| 196 |
|
| 197 |
virtual bool has_filter() const override; |
| 198 |
virtual NodeTimeInfo _process(const AnimationMixer::PlaybackInfo p_playback_info, bool p_test_only = false) override; |
| 199 |
|
| 200 |
AnimationNodeOneShot(); |
| 201 |
}; |
| 202 |
|
| 203 |
VARIANT_ENUM_CAST(AnimationNodeOneShot::OneShotRequest) |
| 204 |
VARIANT_ENUM_CAST(AnimationNodeOneShot::MixMode) |
| 205 |
|
| 206 |
class AnimationNodeAdd2 : public AnimationNodeSync { |
| 207 |
GDCLASS(AnimationNodeAdd2, AnimationNodeSync); |
| 208 |
|
| 209 |
StringName add_amount = PNAME("add_amount"); |
| 210 |
|
| 211 |
public: |
| 212 |
void get_parameter_list(List<PropertyInfo> *r_list) const override; |
| 213 |
virtual Variant get_parameter_default_value(const StringName &p_parameter) const override; |
| 214 |
|
| 215 |
virtual String get_caption() const override; |
| 216 |
|
| 217 |
virtual bool has_filter() const override; |
| 218 |
virtual NodeTimeInfo _process(const AnimationMixer::PlaybackInfo p_playback_info, bool p_test_only = false) override; |
| 219 |
|
| 220 |
AnimationNodeAdd2(); |
| 221 |
}; |
| 222 |
|
| 223 |
class AnimationNodeAdd3 : public AnimationNodeSync { |
| 224 |
GDCLASS(AnimationNodeAdd3, AnimationNodeSync); |
| 225 |
|
| 226 |
StringName add_amount = PNAME("add_amount"); |
| 227 |
|
| 228 |
public: |
| 229 |
void get_parameter_list(List<PropertyInfo> *r_list) const override; |
| 230 |
virtual Variant get_parameter_default_value(const StringName &p_parameter) const override; |
| 231 |
|
| 232 |
virtual String get_caption() const override; |
| 233 |
|
| 234 |
virtual bool has_filter() const override; |
| 235 |
virtual NodeTimeInfo _process(const AnimationMixer::PlaybackInfo p_playback_info, bool p_test_only = false) override; |
| 236 |
|
| 237 |
AnimationNodeAdd3(); |
| 238 |
}; |
| 239 |
|
| 240 |
class AnimationNodeBlend2 : public AnimationNodeSync { |
| 241 |
GDCLASS(AnimationNodeBlend2, AnimationNodeSync); |
| 242 |
|
| 243 |
StringName blend_amount = PNAME("blend_amount"); |
| 244 |
|
| 245 |
public: |
| 246 |
virtual void get_parameter_list(List<PropertyInfo> *r_list) const override; |
| 247 |
virtual Variant get_parameter_default_value(const StringName &p_parameter) const override; |
| 248 |
|
| 249 |
virtual String get_caption() const override; |
| 250 |
virtual NodeTimeInfo _process(const AnimationMixer::PlaybackInfo p_playback_info, bool p_test_only = false) override; |
| 251 |
|
| 252 |
virtual bool has_filter() const override; |
| 253 |
AnimationNodeBlend2(); |
| 254 |
}; |
| 255 |
|
| 256 |
class AnimationNodeBlend3 : public AnimationNodeSync { |
| 257 |
GDCLASS(AnimationNodeBlend3, AnimationNodeSync); |
| 258 |
|
| 259 |
StringName blend_amount = PNAME("blend_amount"); |
| 260 |
|
| 261 |
public: |
| 262 |
virtual void get_parameter_list(List<PropertyInfo> *r_list) const override; |
| 263 |
virtual Variant get_parameter_default_value(const StringName &p_parameter) const override; |
| 264 |
|
| 265 |
virtual String get_caption() const override; |
| 266 |
|
| 267 |
virtual NodeTimeInfo _process(const AnimationMixer::PlaybackInfo p_playback_info, bool p_test_only = false) override; |
| 268 |
AnimationNodeBlend3(); |
| 269 |
}; |
| 270 |
|
| 271 |
class AnimationNodeSub2 : public AnimationNodeSync { |
| 272 |
GDCLASS(AnimationNodeSub2, AnimationNodeSync); |
| 273 |
|
| 274 |
StringName sub_amount = PNAME("sub_amount"); |
| 275 |
|
| 276 |
public: |
| 277 |
void get_parameter_list(List<PropertyInfo> *r_list) const override; |
| 278 |
virtual Variant get_parameter_default_value(const StringName &p_parameter) const override; |
| 279 |
|
| 280 |
virtual String get_caption() const override; |
| 281 |
|
| 282 |
virtual bool has_filter() const override; |
| 283 |
virtual NodeTimeInfo _process(const AnimationMixer::PlaybackInfo p_playback_info, bool p_test_only = false) override; |
| 284 |
|
| 285 |
AnimationNodeSub2(); |
| 286 |
}; |
| 287 |
|
| 288 |
class AnimationNodeTimeScale : public AnimationNode { |
| 289 |
GDCLASS(AnimationNodeTimeScale, AnimationNode); |
| 290 |
|
| 291 |
StringName scale = PNAME("scale"); |
| 292 |
|
| 293 |
public: |
| 294 |
virtual void get_parameter_list(List<PropertyInfo> *r_list) const override; |
| 295 |
virtual Variant get_parameter_default_value(const StringName &p_parameter) const override; |
| 296 |
|
| 297 |
virtual String get_caption() const override; |
| 298 |
|
| 299 |
virtual NodeTimeInfo _process(const AnimationMixer::PlaybackInfo p_playback_info, bool p_test_only = false) override; |
| 300 |
|
| 301 |
AnimationNodeTimeScale(); |
| 302 |
}; |
| 303 |
|
| 304 |
class AnimationNodeTimeSeek : public AnimationNode { |
| 305 |
GDCLASS(AnimationNodeTimeSeek, AnimationNode); |
| 306 |
|
| 307 |
StringName seek_pos_request = PNAME("seek_request"); |
| 308 |
bool explicit_elapse = true; |
| 309 |
|
| 310 |
protected: |
| 311 |
static void _bind_methods(); |
| 312 |
|
| 313 |
public: |
| 314 |
virtual void get_parameter_list(List<PropertyInfo> *r_list) const override; |
| 315 |
virtual Variant get_parameter_default_value(const StringName &p_parameter) const override; |
| 316 |
|
| 317 |
virtual String get_caption() const override; |
| 318 |
|
| 319 |
virtual NodeTimeInfo _process(const AnimationMixer::PlaybackInfo p_playback_info, bool p_test_only = false) override; |
| 320 |
|
| 321 |
void set_explicit_elapse(bool p_enable); |
| 322 |
bool is_explicit_elapse() const; |
| 323 |
|
| 324 |
AnimationNodeTimeSeek(); |
| 325 |
}; |
| 326 |
|
| 327 |
class AnimationNodeTransition : public AnimationNodeSync { |
| 328 |
GDCLASS(AnimationNodeTransition, AnimationNodeSync); |
| 329 |
|
| 330 |
struct InputData { |
| 331 |
bool auto_advance = false; |
| 332 |
bool break_loop_at_end = false; |
| 333 |
bool reset = true; |
| 334 |
}; |
| 335 |
LocalVector<InputData> input_data; |
| 336 |
|
| 337 |
StringName prev_xfading = "prev_xfading"; |
| 338 |
StringName prev_index = "prev_index"; |
| 339 |
StringName current_index = PNAME("current_index"); |
| 340 |
StringName current_state = PNAME("current_state"); |
| 341 |
StringName transition_request = PNAME("transition_request"); |
| 342 |
|
| 343 |
double xfade_time = 0.0; |
| 344 |
Ref<Curve> xfade_curve; |
| 345 |
bool allow_transition_to_self = false; |
| 346 |
|
| 347 |
bool pending_update = false; |
| 348 |
|
| 349 |
protected: |
| 350 |
bool _get(const StringName &p_path, Variant &r_ret) const; |
| 351 |
bool _set(const StringName &p_path, const Variant &p_value); |
| 352 |
static void _bind_methods(); |
| 353 |
void _get_property_list(List<PropertyInfo> *p_list) const; |
| 354 |
|
| 355 |
public: |
| 356 |
virtual void get_parameter_list(List<PropertyInfo> *r_list) const override; |
| 357 |
virtual Variant get_parameter_default_value(const StringName &p_parameter) const override; |
| 358 |
virtual bool is_parameter_read_only(const StringName &p_parameter) const override; |
| 359 |
|
| 360 |
virtual String get_caption() const override; |
| 361 |
|
| 362 |
void set_input_count(int p_inputs); |
| 363 |
|
| 364 |
virtual bool add_input(const String &p_name) override; |
| 365 |
virtual void remove_input(int p_index) override; |
| 366 |
virtual bool set_input_name(int p_input, const String &p_name) override; |
| 367 |
|
| 368 |
void set_input_as_auto_advance(int p_input, bool p_enable); |
| 369 |
bool is_input_set_as_auto_advance(int p_input) const; |
| 370 |
|
| 371 |
void set_input_break_loop_at_end(int p_input, bool p_enable); |
| 372 |
bool is_input_loop_broken_at_end(int p_input) const; |
| 373 |
|
| 374 |
void set_input_reset(int p_input, bool p_enable); |
| 375 |
bool is_input_reset(int p_input) const; |
| 376 |
|
| 377 |
void set_xfade_time(double p_fade); |
| 378 |
double get_xfade_time() const; |
| 379 |
|
| 380 |
void set_xfade_curve(const Ref<Curve> &p_curve); |
| 381 |
Ref<Curve> get_xfade_curve() const; |
| 382 |
|
| 383 |
void set_allow_transition_to_self(bool p_enable); |
| 384 |
bool is_allow_transition_to_self() const; |
| 385 |
|
| 386 |
virtual NodeTimeInfo _process(const AnimationMixer::PlaybackInfo p_playback_info, bool p_test_only = false) override; |
| 387 |
|
| 388 |
AnimationNodeTransition(); |
| 389 |
}; |
| 390 |
|
| 391 |
class AnimationNodeOutput : public AnimationNode { |
| 392 |
GDCLASS(AnimationNodeOutput, AnimationNode); |
| 393 |
|
| 394 |
public: |
| 395 |
virtual String get_caption() const override; |
| 396 |
virtual NodeTimeInfo _process(const AnimationMixer::PlaybackInfo p_playback_info, bool p_test_only = false) override; |
| 397 |
AnimationNodeOutput(); |
| 398 |
}; |
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
class AnimationNodeBlendTree : public AnimationRootNode { |
| 403 |
GDCLASS(AnimationNodeBlendTree, AnimationRootNode); |
| 404 |
|
| 405 |
struct Node { |
| 406 |
Ref<AnimationNode> node; |
| 407 |
Vector2 position; |
| 408 |
Vector<StringName> connections; |
| 409 |
}; |
| 410 |
|
| 411 |
AHashMap<StringName, Node> nodes; |
| 412 |
|
| 413 |
Vector2 graph_offset; |
| 414 |
|
| 415 |
void _node_changed(const StringName &p_node); |
| 416 |
|
| 417 |
void _initialize_node_tree(); |
| 418 |
|
| 419 |
protected: |
| 420 |
static void _bind_methods(); |
| 421 |
bool _set(const StringName &p_name, const Variant &p_value); |
| 422 |
bool _get(const StringName &p_name, Variant &r_ret) const; |
| 423 |
void _get_property_list(List<PropertyInfo> *p_list) const; |
| 424 |
|
| 425 |
virtual void _tree_changed() override; |
| 426 |
virtual void _animation_node_renamed(const ObjectID &p_oid, const String &p_old_name, const String &p_new_name) override; |
| 427 |
virtual void _animation_node_removed(const ObjectID &p_oid, const StringName &p_node) override; |
| 428 |
|
| 429 |
virtual void reset_state() override; |
| 430 |
|
| 431 |
public: |
| 432 |
enum ConnectionError { |
| 433 |
CONNECTION_OK, |
| 434 |
CONNECTION_ERROR_NO_INPUT, |
| 435 |
CONNECTION_ERROR_NO_INPUT_INDEX, |
| 436 |
CONNECTION_ERROR_NO_OUTPUT, |
| 437 |
CONNECTION_ERROR_SAME_NODE, |
| 438 |
CONNECTION_ERROR_CONNECTION_EXISTS, |
| 439 |
|
| 440 |
}; |
| 441 |
|
| 442 |
void add_node(const StringName &p_name, Ref<AnimationNode> p_node, const Vector2 &p_position = Vector2()); |
| 443 |
Ref<AnimationNode> get_node(const StringName &p_name) const; |
| 444 |
void remove_node(const StringName &p_name); |
| 445 |
void rename_node(const StringName &p_name, const StringName &p_new_name); |
| 446 |
bool has_node(const StringName &p_name) const; |
| 447 |
StringName get_node_name(const Ref<AnimationNode> &p_node) const; |
| 448 |
Vector<StringName> get_node_connection_array(const StringName &p_name) const; |
| 449 |
|
| 450 |
void set_node_position(const StringName &p_node, const Vector2 &p_position); |
| 451 |
Vector2 get_node_position(const StringName &p_node) const; |
| 452 |
|
| 453 |
virtual void get_child_nodes(List<ChildNode> *r_child_nodes) override; |
| 454 |
|
| 455 |
void connect_node(const StringName &p_input_node, int p_input_index, const StringName &p_output_node); |
| 456 |
void disconnect_node(const StringName &p_node, int p_input_index); |
| 457 |
|
| 458 |
struct NodeConnection { |
| 459 |
StringName input_node; |
| 460 |
int input_index = 0; |
| 461 |
StringName output_node; |
| 462 |
}; |
| 463 |
|
| 464 |
ConnectionError can_connect_node(const StringName &p_input_node, int p_input_index, const StringName &p_output_node) const; |
| 465 |
void get_node_connections(List<NodeConnection> *r_connections) const; |
| 466 |
|
| 467 |
virtual String get_caption() const override; |
| 468 |
virtual NodeTimeInfo _process(const AnimationMixer::PlaybackInfo p_playback_info, bool p_test_only = false) override; |
| 469 |
|
| 470 |
LocalVector<StringName> get_node_list() const; |
| 471 |
TypedArray<StringName> get_node_list_as_typed_array() const; |
| 472 |
|
| 473 |
void set_graph_offset(const Vector2 &p_graph_offset); |
| 474 |
Vector2 get_graph_offset() const; |
| 475 |
|
| 476 |
virtual Ref<AnimationNode> get_child_by_name(const StringName &p_name) const override; |
| 477 |
|
| 478 |
#ifdef TOOLS_ENABLED |
| 479 |
virtual void get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const override; |
| 480 |
#endif |
| 481 |
|
| 482 |
AnimationNodeBlendTree(); |
| 483 |
~AnimationNodeBlendTree(); |
| 484 |
}; |
| 485 |
|
| 486 |
VARIANT_ENUM_CAST(AnimationNodeBlendTree::ConnectionError) |