Merge pull request #20665 from SaracenOne/animation_tree_control

Add method to manually advance AnimationTree and manual process mode.
This commit is contained in:
Rémi Verschelde 2018-08-14 15:54:20 +02:00 committed by GitHub
commit c0137db762
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 28 additions and 2 deletions

View file

@ -283,5 +283,8 @@
<constant name="ANIMATION_PROCESS_IDLE" value="1" enum="AnimationProcessMode"> <constant name="ANIMATION_PROCESS_IDLE" value="1" enum="AnimationProcessMode">
Process animation during the idle process. Process animation during the idle process.
</constant> </constant>
<constant name="ANIMATION_PROCESS_MANUAL" value="2" enum="AnimationProcessMode">
Do not process animation. Use the 'advance' method to process the animation manually.
</constant>
</constants> </constants>
</class> </class>

View file

@ -9,6 +9,14 @@
<demos> <demos>
</demos> </demos>
<methods> <methods>
<method name="advance">
<return type="void">
</return>
<argument index="0" name="delta" type="float">
</argument>
<description>
</description>
</method>
<method name="get_root_motion_transform" qualifiers="const"> <method name="get_root_motion_transform" qualifiers="const">
<return type="Transform"> <return type="Transform">
</return> </return>
@ -33,5 +41,7 @@
</constant> </constant>
<constant name="ANIMATION_PROCESS_IDLE" value="1" enum="AnimationProcessMode"> <constant name="ANIMATION_PROCESS_IDLE" value="1" enum="AnimationProcessMode">
</constant> </constant>
<constant name="ANIMATION_PROCESS_MANUAL" value="2" enum="AnimationProcessMode">
</constant>
</constants> </constants>
</class> </class>

View file

@ -1644,7 +1644,7 @@ void AnimationPlayer::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::REAL, "current_animation_position", PROPERTY_HINT_NONE, "", 0), "", "get_current_animation_position"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "current_animation_position", PROPERTY_HINT_NONE, "", 0), "", "get_current_animation_position");
ADD_GROUP("Playback Options", "playback_"); ADD_GROUP("Playback Options", "playback_");
ADD_PROPERTY(PropertyInfo(Variant::INT, "playback_process_mode", PROPERTY_HINT_ENUM, "Physics,Idle"), "set_animation_process_mode", "get_animation_process_mode"); ADD_PROPERTY(PropertyInfo(Variant::INT, "playback_process_mode", PROPERTY_HINT_ENUM, "Physics,Idle,Manual"), "set_animation_process_mode", "get_animation_process_mode");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "playback_default_blend_time", PROPERTY_HINT_RANGE, "0,4096,0.01"), "set_default_blend_time", "get_default_blend_time"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "playback_default_blend_time", PROPERTY_HINT_RANGE, "0,4096,0.01"), "set_default_blend_time", "get_default_blend_time");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "playback_active", PROPERTY_HINT_NONE, "", 0), "set_active", "is_active"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "playback_active", PROPERTY_HINT_NONE, "", 0), "set_active", "is_active");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "playback_speed", PROPERTY_HINT_RANGE, "-64,64,0.01"), "set_speed_scale", "get_speed_scale"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "playback_speed", PROPERTY_HINT_RANGE, "-64,64,0.01"), "set_speed_scale", "get_speed_scale");
@ -1656,6 +1656,7 @@ void AnimationPlayer::_bind_methods() {
BIND_ENUM_CONSTANT(ANIMATION_PROCESS_PHYSICS); BIND_ENUM_CONSTANT(ANIMATION_PROCESS_PHYSICS);
BIND_ENUM_CONSTANT(ANIMATION_PROCESS_IDLE); BIND_ENUM_CONSTANT(ANIMATION_PROCESS_IDLE);
BIND_ENUM_CONSTANT(ANIMATION_PROCESS_MANUAL);
} }
AnimationPlayer::AnimationPlayer() { AnimationPlayer::AnimationPlayer() {

View file

@ -65,6 +65,7 @@ public:
enum AnimationProcessMode { enum AnimationProcessMode {
ANIMATION_PROCESS_PHYSICS, ANIMATION_PROCESS_PHYSICS,
ANIMATION_PROCESS_IDLE, ANIMATION_PROCESS_IDLE,
ANIMATION_PROCESS_MANUAL,
}; };
private: private:

View file

@ -1199,6 +1199,11 @@ void AnimationTree::_process_graph(float p_delta) {
} }
} }
void AnimationTree::advance(float p_time) {
_process_graph(p_time);
}
void AnimationTree::_notification(int p_what) { void AnimationTree::_notification(int p_what) {
if (active && p_what == NOTIFICATION_INTERNAL_PHYSICS_PROCESS && process_mode == ANIMATION_PROCESS_PHYSICS) { if (active && p_what == NOTIFICATION_INTERNAL_PHYSICS_PROCESS && process_mode == ANIMATION_PROCESS_PHYSICS) {
@ -1310,17 +1315,20 @@ void AnimationTree::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_root_motion_transform"), &AnimationTree::get_root_motion_transform); ClassDB::bind_method(D_METHOD("get_root_motion_transform"), &AnimationTree::get_root_motion_transform);
ClassDB::bind_method(D_METHOD("advance", "delta"), &AnimationTree::advance);
ClassDB::bind_method(D_METHOD("_node_removed"), &AnimationTree::_node_removed); ClassDB::bind_method(D_METHOD("_node_removed"), &AnimationTree::_node_removed);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "tree_root", PROPERTY_HINT_RESOURCE_TYPE, "AnimationRootNode", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_DO_NOT_SHARE_ON_DUPLICATE), "set_tree_root", "get_tree_root"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "tree_root", PROPERTY_HINT_RESOURCE_TYPE, "AnimationRootNode", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_DO_NOT_SHARE_ON_DUPLICATE), "set_tree_root", "get_tree_root");
ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "anim_player", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "AnimationPlayer"), "set_animation_player", "get_animation_player"); ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "anim_player", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "AnimationPlayer"), "set_animation_player", "get_animation_player");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "active"), "set_active", "is_active"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "active"), "set_active", "is_active");
ADD_PROPERTY(PropertyInfo(Variant::INT, "process_mode", PROPERTY_HINT_ENUM, "Physics,Idle"), "set_process_mode", "get_process_mode"); ADD_PROPERTY(PropertyInfo(Variant::INT, "process_mode", PROPERTY_HINT_ENUM, "Physics,Idle,Manual"), "set_process_mode", "get_process_mode");
ADD_GROUP("Root Motion", "root_motion_"); ADD_GROUP("Root Motion", "root_motion_");
ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "root_motion_track"), "set_root_motion_track", "get_root_motion_track"); ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "root_motion_track"), "set_root_motion_track", "get_root_motion_track");
BIND_ENUM_CONSTANT(ANIMATION_PROCESS_PHYSICS); BIND_ENUM_CONSTANT(ANIMATION_PROCESS_PHYSICS);
BIND_ENUM_CONSTANT(ANIMATION_PROCESS_IDLE); BIND_ENUM_CONSTANT(ANIMATION_PROCESS_IDLE);
BIND_ENUM_CONSTANT(ANIMATION_PROCESS_MANUAL);
} }
AnimationTree::AnimationTree() { AnimationTree::AnimationTree() {

View file

@ -133,6 +133,7 @@ public:
enum AnimationProcessMode { enum AnimationProcessMode {
ANIMATION_PROCESS_PHYSICS, ANIMATION_PROCESS_PHYSICS,
ANIMATION_PROCESS_IDLE, ANIMATION_PROCESS_IDLE,
ANIMATION_PROCESS_MANUAL,
}; };
private: private:
@ -271,6 +272,8 @@ public:
Transform get_root_motion_transform() const; Transform get_root_motion_transform() const;
void advance(float p_time);
uint64_t get_last_process_pass() const; uint64_t get_last_process_pass() const;
AnimationTree(); AnimationTree();
~AnimationTree(); ~AnimationTree();