-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add animation node extension #99181
Merged
Repiteo
merged 1 commit into
godotengine:master
from
GuilhermeGSousa:animation-node-extension
Dec 13, 2024
+210
−1
Merged
Add animation node extension #99181
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<class name="AnimationNodeExtension" inherits="AnimationRootNode" experimental="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd"> | ||
<brief_description> | ||
Base class for extending [AnimationRootNode]s from GDScript, C#, or C++. | ||
</brief_description> | ||
<description> | ||
[AnimationNodeExtension] exposes the APIs of [AnimationRootNode] to allow users to extend it from GDScript, C#, or C++. This class is not meant to be used directly, but to be extended by other classes. It is used to create custom nodes for the [AnimationTree] system. | ||
</description> | ||
<tutorials> | ||
</tutorials> | ||
<methods> | ||
<method name="_process" qualifiers="virtual"> | ||
<return type="PackedFloat32Array" /> | ||
<param index="0" name="playback_info" type="PackedFloat64Array" /> | ||
<param index="1" name="test_only" type="bool" /> | ||
<description> | ||
A version of the [method AnimationNode._process] method that is meant to be overridden by custom nodes. It returns a [PackedFloat32Array] with the processed animation data. | ||
The [PackedFloat64Array] parameter contains the playback information, containing the following values encoded as floating point numbers (in order): playback time and delta, start and end times, whether a seek was requested (encoded as a float greater than [code]0[/code]), whether the seek request was externally requested (encoded as a float greater than [code]0[/code]), the current [enum Animation.LoopedFlag] (encoded as a float), and the current blend weight. | ||
The function must return a [PackedFloat32Array] of the node's time info, containing the following values (in order): animation length, time position, delta, [enum Animation.LoopMode] (encoded as a float), whether the animation is about to end (encoded as a float greater than [code]0[/code]) and whether the animation is infinite (encoded as a float greater than [code]0[/code]). All values must be included in the returned array. | ||
</description> | ||
</method> | ||
<method name="get_remaining_time" qualifiers="static"> | ||
<return type="float" /> | ||
<param index="0" name="node_info" type="PackedFloat32Array" /> | ||
<param index="1" name="break_loop" type="bool" /> | ||
<description> | ||
Returns the animation's remaining time for the given node info. For looping animations, it will only return the remaining time if [param break_loop] is [code]true[/code], a large integer value will be returned otherwise. | ||
</description> | ||
</method> | ||
<method name="is_looping" qualifiers="static"> | ||
<return type="bool" /> | ||
<param index="0" name="node_info" type="PackedFloat32Array" /> | ||
<description> | ||
Returns [code]true[/code] if the animation for the given [param node_info] is looping. | ||
</description> | ||
</method> | ||
</methods> | ||
</class> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/**************************************************************************/ | ||
/* animation_node_extension.cpp */ | ||
/**************************************************************************/ | ||
/* This file is part of: */ | ||
/* GODOT ENGINE */ | ||
/* https://godotengine.org */ | ||
/**************************************************************************/ | ||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ | ||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ | ||
/* */ | ||
/* Permission is hereby granted, free of charge, to any person obtaining */ | ||
/* a copy of this software and associated documentation files (the */ | ||
/* "Software"), to deal in the Software without restriction, including */ | ||
/* without limitation the rights to use, copy, modify, merge, publish, */ | ||
/* distribute, sublicense, and/or sell copies of the Software, and to */ | ||
/* permit persons to whom the Software is furnished to do so, subject to */ | ||
/* the following conditions: */ | ||
/* */ | ||
/* The above copyright notice and this permission notice shall be */ | ||
/* included in all copies or substantial portions of the Software. */ | ||
/* */ | ||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ | ||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ | ||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ | ||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ | ||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ | ||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ | ||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ | ||
/**************************************************************************/ | ||
|
||
#include "animation_node_extension.h" | ||
|
||
AnimationNode::NodeTimeInfo AnimationNodeExtension::_process(const AnimationMixer::PlaybackInfo p_playback_info, bool p_test_only) { | ||
PackedFloat32Array r_ret; | ||
|
||
GDVIRTUAL_CALL( | ||
_process, | ||
_playback_info_to_array(p_playback_info), | ||
p_test_only, | ||
r_ret); | ||
|
||
return _array_to_node_time_info(r_ret); | ||
} | ||
|
||
bool AnimationNodeExtension::is_looping(const PackedFloat32Array &p_node_info) { | ||
return _array_to_node_time_info(p_node_info).is_looping(); | ||
} | ||
|
||
double AnimationNodeExtension::get_remaining_time(const PackedFloat32Array &p_node_info, bool p_break_loop) { | ||
return _array_to_node_time_info(p_node_info).get_remain(p_break_loop); | ||
} | ||
|
||
void AnimationNodeExtension::_bind_methods() { | ||
ClassDB::bind_static_method("AnimationNodeExtension", D_METHOD("is_looping", "node_info"), &AnimationNodeExtension::is_looping); | ||
ClassDB::bind_static_method("AnimationNodeExtension", D_METHOD("get_remaining_time", "node_info", "break_loop"), &AnimationNodeExtension::get_remaining_time); | ||
GDVIRTUAL_BIND(_process, "playback_info", "test_only"); | ||
} | ||
|
||
AnimationNode::NodeTimeInfo AnimationNodeExtension::_array_to_node_time_info(const PackedFloat32Array &p_node_info) { | ||
ERR_FAIL_COND_V_MSG(p_node_info.size() != 6, AnimationNode::NodeTimeInfo(), "Invalid node info."); | ||
AnimationNode::NodeTimeInfo ret_val; | ||
ret_val.length = p_node_info[0]; | ||
ret_val.position = p_node_info[1]; | ||
ret_val.delta = p_node_info[2]; | ||
ret_val.loop_mode = static_cast<Animation::LoopMode>(p_node_info[3]); | ||
ret_val.will_end = p_node_info[4] > 0.0; | ||
ret_val.is_infinity = p_node_info[5] > 0.0; | ||
return ret_val; | ||
} | ||
|
||
PackedFloat64Array AnimationNodeExtension::_playback_info_to_array(const AnimationMixer::PlaybackInfo &p_playback_info) { | ||
PackedFloat64Array playback_info_array; | ||
playback_info_array.push_back(p_playback_info.time); | ||
playback_info_array.push_back(p_playback_info.delta); | ||
playback_info_array.push_back(p_playback_info.start); | ||
playback_info_array.push_back(p_playback_info.end); | ||
playback_info_array.push_back(p_playback_info.seeked); | ||
playback_info_array.push_back(p_playback_info.is_external_seeking); | ||
playback_info_array.push_back(p_playback_info.looped_flag); | ||
playback_info_array.push_back(p_playback_info.weight); | ||
|
||
return playback_info_array; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/**************************************************************************/ | ||
/* animation_node_extension.h */ | ||
/**************************************************************************/ | ||
/* This file is part of: */ | ||
/* GODOT ENGINE */ | ||
/* https://godotengine.org */ | ||
/**************************************************************************/ | ||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ | ||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ | ||
/* */ | ||
/* Permission is hereby granted, free of charge, to any person obtaining */ | ||
/* a copy of this software and associated documentation files (the */ | ||
/* "Software"), to deal in the Software without restriction, including */ | ||
/* without limitation the rights to use, copy, modify, merge, publish, */ | ||
/* distribute, sublicense, and/or sell copies of the Software, and to */ | ||
/* permit persons to whom the Software is furnished to do so, subject to */ | ||
/* the following conditions: */ | ||
/* */ | ||
/* The above copyright notice and this permission notice shall be */ | ||
/* included in all copies or substantial portions of the Software. */ | ||
/* */ | ||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ | ||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ | ||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ | ||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ | ||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ | ||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ | ||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ | ||
/**************************************************************************/ | ||
|
||
#ifndef ANIMATION_NODE_EXTENSION_H | ||
#define ANIMATION_NODE_EXTENSION_H | ||
|
||
#include "scene/animation/animation_tree.h" | ||
|
||
class AnimationNodeExtension : public AnimationRootNode { | ||
GDCLASS(AnimationNodeExtension, AnimationRootNode); | ||
|
||
public: | ||
virtual NodeTimeInfo _process(const AnimationMixer::PlaybackInfo p_playback_info, bool p_test_only = false) override; | ||
|
||
static bool is_looping(const PackedFloat32Array &p_node_info); | ||
static double get_remaining_time(const PackedFloat32Array &p_node_info, bool p_break_loop = false); | ||
|
||
protected: | ||
static void _bind_methods(); | ||
|
||
GDVIRTUAL2R_REQUIRED(PackedFloat32Array, _process, PackedFloat64Array, bool); | ||
|
||
private: | ||
static AnimationNode::NodeTimeInfo _array_to_node_time_info(const PackedFloat32Array &p_array); | ||
static PackedFloat64Array _playback_info_to_array(const AnimationMixer::PlaybackInfo &p_playback_info); | ||
}; | ||
|
||
#endif // ANIMATION_NODE_EXTENSION_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Related to the comment above, AnimationNodeExtention should replace AnimationNode, not AnimationRootNode.
The AnimationRootNode does not need an input port and can be placed in a StateMachine. If not, it is because that would imply that an input port is required.
I guess you want it to be the AnimationRootNode for placing it in the BlendSpace or StateMachine purposes, but if you replace it and replace the AnimationNode with the AnimationNodeExtention, the AnimationRootNode will extend it, thus solving this classification problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw, was this comment overlooked?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I think if it is an Extension, we will need two (or three) Extensions, AnimationRootNodeExtension and AnimationNodeSyncExtension (and AnimationNodeExtention). If it is not an Extension by replacement, then only the AnimationNode needs to be replaced. cc @GuilhermeGSousa
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#100416
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Completely missed this comment, my bad @TokageItLab. I agree with you, do you want me to make PRs for those other extension nodes as well?