From 81c86e8047d86d03e690948c68eb54c5b115f2ab Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Sun, 25 Nov 2018 16:56:49 -0300 Subject: [PATCH] Improved bindings and added documentation for AnimationNode, closes #20720 --- doc/classes/@GlobalScope.xml | 2 - doc/classes/AnimationNode.xml | 59 ++++++++++++++++++++++++++++++ doc/classes/ProjectSettings.xml | 8 ---- scene/animation/animation_tree.cpp | 34 +++++++++++++++++ 4 files changed, 93 insertions(+), 10 deletions(-) diff --git a/doc/classes/@GlobalScope.xml b/doc/classes/@GlobalScope.xml index e05af0f1acb..ba2eb35f8c4 100644 --- a/doc/classes/@GlobalScope.xml +++ b/doc/classes/@GlobalScope.xml @@ -29,8 +29,6 @@ [Geometry] singleton - - [IP] singleton diff --git a/doc/classes/AnimationNode.xml b/doc/classes/AnimationNode.xml index d9bad150df1..7b9d523acf2 100644 --- a/doc/classes/AnimationNode.xml +++ b/doc/classes/AnimationNode.xml @@ -1,8 +1,11 @@ + Base resource for [AnimationTree] nodes. + Base resource for [AnimationTree] nodes. In general it's not used directly but you can create custom ones with custom blending formulas. + Inherit this when creating nodes mainly for use in [AnimationNodeBlendTree], otherwise [AnimationRootNode] should be used instead. @@ -15,6 +18,7 @@ + Add an input to the node. This is only useful for nodes created for use in an [AnimationNodeBlendTree] @@ -31,6 +35,7 @@ + Blend an animation by "blend" amount (name must be valid in the linked [AnimationPlayer]). A time and delta mas be passed, as well as whether seek happened. @@ -49,6 +54,7 @@ + Blend an input. This is only useful for nodes created for an AnimationBlendTree. Time is a delta, unless "seek" is true, in which case it is absolute. A filter mode may be optionally passed. @@ -69,18 +75,37 @@ + Blend another animaiton node (in case this node contains children animation nodes). This function is only useful if you inherit from [AnimationRootNode] instead, else editors will not display your node for addition. + Get the text caption for this node (used by some editors) + + + + + + + + + Get the a child node by index (used by editors inheriting from [AnimationRootNode]). + + + + + + + Get all children nodes, in order as a name:node dictionary. Only useful when inheriting [AnimationRootNode]. + Amount of inputs in this node, only useful for nodes that go into [AnimationBlendTree]. @@ -89,6 +114,7 @@ + Get the name of an input by index. @@ -97,12 +123,31 @@ + Get the value of a parameter. Parameters are custom local memory used for your nodes, given a resource can be reused in multiple trees. + + + + + + + + + Get the default value of a parameter. Parameters are custom local memory used for your nodes, given a resource can be reused in multiple trees. + + + + + + + Get the property information for parameter. Parameters are custom local memory used for your nodes, given a resource can be reused in multiple trees. + Format is similar to [Object.get_property_list] + Return true whether you want the blend tree editor to display filter editing on this node. @@ -111,6 +156,7 @@ + Return true wether a given path is filtered. @@ -121,6 +167,10 @@ + Called when a custom node is processed. The argument "time" is relative, unless "seek" is true (in which case it is absolute). + Here, call the [method blend_input], [method blend_node] or [method blend_animation] functions. + You can also use [method get_parameter] and [method set_parameter] to modify local memory. + This function returns the time left for the current animation to finish (if unsure, just pass the value from the main blend being called). @@ -129,6 +179,7 @@ + Remove an input, call this only when inactive. @@ -139,6 +190,7 @@ + Add/Remove a path for the filter. @@ -149,16 +201,19 @@ + Set a custom parameter. These are used as local storage, because resources can be reused across the tree or scenes. + Return whether filtering is enabled. + Called when the node was removed from the graph. @@ -168,12 +223,16 @@ + Do not use filtering. + Paths matching the filter will be allowed to pass. + Paths matching the filter will be discarded. + Paths matching the filter will be blended (by the blend value). diff --git a/doc/classes/ProjectSettings.xml b/doc/classes/ProjectSettings.xml index 9706ea4e600..7a9918237f6 100644 --- a/doc/classes/ProjectSettings.xml +++ b/doc/classes/ProjectSettings.xml @@ -588,14 +588,6 @@ This is used by servers when used in multi threading mode (servers and visual). RIDs are preallocated to avoid stalling the server requesting them on threads. If servers get stalled too often when loading resources in a thread, increase this number. - - - - - - - - Maximum amount of characters allowed to send as output from the debugger. Over this value, content is dropped. This helps not to stall the debugger connection. diff --git a/scene/animation/animation_tree.cpp b/scene/animation/animation_tree.cpp index eb00f91bb3d..03c3c787686 100644 --- a/scene/animation/animation_tree.cpp +++ b/scene/animation/animation_tree.cpp @@ -37,9 +37,20 @@ #include "servers/audio/audio_stream.h" void AnimationNode::get_parameter_list(List *r_list) const { + if (get_script_instance()) { + Array parameters = get_script_instance()->call("get_parameter_list"); + for (int i = 0; i < parameters.size(); i++) { + Dictionary d = parameters[i]; + ERR_CONTINUE(d.empty()); + r_list->push_back(PropertyInfo::from_dict(d)); + } + } } Variant AnimationNode::get_parameter_default_value(const StringName &p_parameter) const { + if (get_script_instance()) { + return get_script_instance()->call("get_parameter_default_value"); + } return Variant(); } @@ -62,6 +73,18 @@ Variant AnimationNode::get_parameter(const StringName &p_name) const { } void AnimationNode::get_child_nodes(List *r_child_nodes) { + + if (get_script_instance()) { + Dictionary cn = get_script_instance()->call("get_child_nodes"); + List keys; + cn.get_key_list(&keys); + for (List::Element *E = keys.front(); E; E = E->next()) { + ChildNode child; + child.name = E->get(); + child.node = cn[E->get()]; + r_child_nodes->push_back(child); + } + } } void AnimationNode::blend_animation(const StringName &p_animation, float p_time, float p_delta, bool p_seeked, float p_blend) { @@ -373,6 +396,9 @@ void AnimationNode::_validate_property(PropertyInfo &property) const { } Ref AnimationNode::get_child_by_name(const StringName &p_name) { + if (get_script_instance()) { + return get_script_instance()->call("get_child_by_nane"); + } return Ref(); } @@ -403,6 +429,14 @@ void AnimationNode::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "filter_enabled", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_filter_enabled", "is_filter_enabled"); ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "filters", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "_set_filters", "_get_filters"); + BIND_VMETHOD(MethodInfo(Variant::DICTIONARY, "get_child_nodes")); + BIND_VMETHOD(MethodInfo(Variant::ARRAY, "get_parameter_list")); + BIND_VMETHOD(MethodInfo(Variant::OBJECT, "get_child_by_name", PropertyInfo(Variant::STRING, "name"))); + { + MethodInfo mi = MethodInfo(Variant::NIL, "get_parameter_default_value", PropertyInfo(Variant::STRING, "name")); + mi.return_val.usage = PROPERTY_USAGE_NIL_IS_VARIANT; + BIND_VMETHOD(mi); + } BIND_VMETHOD(MethodInfo("process", PropertyInfo(Variant::REAL, "time"), PropertyInfo(Variant::BOOL, "seek"))); BIND_VMETHOD(MethodInfo(Variant::STRING, "get_caption")); BIND_VMETHOD(MethodInfo(Variant::STRING, "has_filter"));