Display and allow setting name/index of BlendSpace points
This commit is contained in:
@@ -17,8 +17,17 @@
|
||||
<param index="0" name="node" type="AnimationRootNode" />
|
||||
<param index="1" name="pos" type="float" />
|
||||
<param index="2" name="at_index" type="int" default="-1" />
|
||||
<param index="3" name="name" type="StringName" default="&""" />
|
||||
<description>
|
||||
Adds a new point that represents a [param node] on the virtual axis at a given position set by [param pos]. You can insert it at a specific index using the [param at_index] argument. If you use the default value for [param at_index], the point is inserted at the end of the blend points array.
|
||||
Adds a new point with [param name] that represents a [param node] on the virtual axis at a given position set by [param pos]. You can insert it at a specific index using the [param at_index] argument. If you use the default value for [param at_index], the point is inserted at the end of the blend points array.
|
||||
[b]Note:[/b] If no name is provided, safe index is used as reference. In the future, empty names will be deprecated, so explicitly passing a name is recommended.
|
||||
</description>
|
||||
</method>
|
||||
<method name="find_blend_point_by_name" qualifiers="const">
|
||||
<return type="int" />
|
||||
<param index="0" name="name" type="StringName" />
|
||||
<description>
|
||||
Returns the index of the blend point with the given [param name]. Returns [code]-1[/code] if no blend point with that name is found.
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_blend_point_count" qualifiers="const">
|
||||
@@ -27,6 +36,13 @@
|
||||
Returns the number of points on the blend axis.
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_blend_point_name" qualifiers="const">
|
||||
<return type="StringName" />
|
||||
<param index="0" name="point" type="int" />
|
||||
<description>
|
||||
Returns the name of the blend point at index [param point].
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_blend_point_node" qualifiers="const">
|
||||
<return type="AnimationRootNode" />
|
||||
<param index="0" name="point" type="int" />
|
||||
@@ -48,6 +64,22 @@
|
||||
Removes the point at index [param point] from the blend axis.
|
||||
</description>
|
||||
</method>
|
||||
<method name="reorder_blend_point">
|
||||
<return type="void" />
|
||||
<param index="0" name="from_index" type="int" />
|
||||
<param index="1" name="to_index" type="int" />
|
||||
<description>
|
||||
Swaps the blend points at indices [param from_index] and [param to_index], exchanging their positions and properties.
|
||||
</description>
|
||||
</method>
|
||||
<method name="set_blend_point_name">
|
||||
<return type="void" />
|
||||
<param index="0" name="point" type="int" />
|
||||
<param index="1" name="name" type="StringName" />
|
||||
<description>
|
||||
Sets the name of the blend point at index [param point]. If the name conflicts with an existing point, a unique name will be generated automatically.
|
||||
</description>
|
||||
</method>
|
||||
<method name="set_blend_point_node">
|
||||
<return type="void" />
|
||||
<param index="0" name="point" type="int" />
|
||||
|
||||
@@ -18,8 +18,10 @@
|
||||
<param index="0" name="node" type="AnimationRootNode" />
|
||||
<param index="1" name="pos" type="Vector2" />
|
||||
<param index="2" name="at_index" type="int" default="-1" />
|
||||
<param index="3" name="name" type="StringName" default="&""" />
|
||||
<description>
|
||||
Adds a new point that represents a [param node] at the position set by [param pos]. You can insert it at a specific index using the [param at_index] argument. If you use the default value for [param at_index], the point is inserted at the end of the blend points array.
|
||||
Adds a new point with [param name] that represents a [param node] at the position set by [param pos]. You can insert it at a specific index using the [param at_index] argument. If you use the default value for [param at_index], the point is inserted at the end of the blend points array.
|
||||
[b]Note:[/b] If no name is provided, safe index is used as reference. In the future, empty names will be deprecated, so explicitly passing a name is recommended.
|
||||
</description>
|
||||
</method>
|
||||
<method name="add_triangle">
|
||||
@@ -32,12 +34,26 @@
|
||||
Creates a new triangle using three points [param x], [param y], and [param z]. Triangles can overlap. You can insert the triangle at a specific index using the [param at_index] argument. If you use the default value for [param at_index], the point is inserted at the end of the blend points array.
|
||||
</description>
|
||||
</method>
|
||||
<method name="find_blend_point_by_name" qualifiers="const">
|
||||
<return type="int" />
|
||||
<param index="0" name="name" type="StringName" />
|
||||
<description>
|
||||
Returns the index of the blend point with the given [param name]. Returns [code]-1[/code] if no blend point with that name is found.
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_blend_point_count" qualifiers="const">
|
||||
<return type="int" />
|
||||
<description>
|
||||
Returns the number of points in the blend space.
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_blend_point_name" qualifiers="const">
|
||||
<return type="StringName" />
|
||||
<param index="0" name="point" type="int" />
|
||||
<description>
|
||||
Returns the name of the blend point at index [param point].
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_blend_point_node" qualifiers="const">
|
||||
<return type="AnimationRootNode" />
|
||||
<param index="0" name="point" type="int" />
|
||||
@@ -80,6 +96,22 @@
|
||||
Removes the triangle at index [param triangle] from the blend space.
|
||||
</description>
|
||||
</method>
|
||||
<method name="reorder_blend_point">
|
||||
<return type="void" />
|
||||
<param index="0" name="from_index" type="int" />
|
||||
<param index="1" name="to_index" type="int" />
|
||||
<description>
|
||||
Swaps the blend points at indices [param from_index] and [param to_index], exchanging their positions and properties.
|
||||
</description>
|
||||
</method>
|
||||
<method name="set_blend_point_name">
|
||||
<return type="void" />
|
||||
<param index="0" name="point" type="int" />
|
||||
<param index="1" name="name" type="StringName" />
|
||||
<description>
|
||||
Sets the name of the blend point at index [param point]. If the name conflicts with an existing point, a unique name will be generated automatically.
|
||||
</description>
|
||||
</method>
|
||||
<method name="set_blend_point_node">
|
||||
<return type="void" />
|
||||
<param index="0" name="point" type="int" />
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -41,6 +41,7 @@ class LineEdit;
|
||||
class OptionButton;
|
||||
class PanelContainer;
|
||||
class SpinBox;
|
||||
class Timer;
|
||||
class VSeparator;
|
||||
|
||||
class AnimationNodeBlendSpace1DEditor : public AnimationTreeNodeEditorPlugin {
|
||||
@@ -68,6 +69,8 @@ class AnimationNodeBlendSpace1DEditor : public AnimationTreeNodeEditorPlugin {
|
||||
HBoxContainer *edit_hb = nullptr;
|
||||
SpinBox *edit_value = nullptr;
|
||||
Button *open_editor = nullptr;
|
||||
VSeparator *open_editor_sep = nullptr;
|
||||
SpinBox *index_edit = nullptr;
|
||||
|
||||
int selected_point = -1;
|
||||
|
||||
@@ -101,15 +104,36 @@ class AnimationNodeBlendSpace1DEditor : public AnimationTreeNodeEditorPlugin {
|
||||
Vector2 drag_from;
|
||||
Vector2 drag_ofs;
|
||||
|
||||
Vector<Rect2> text_rects;
|
||||
int editing_point = -1;
|
||||
LineEdit *inline_editor = nullptr;
|
||||
float inline_editor_point_x = 0.0f;
|
||||
bool index_edit_has_focus = false;
|
||||
bool show_indices = false;
|
||||
Timer *index_focus_cooldown_timer = nullptr;
|
||||
|
||||
void _add_menu_type(int p_index);
|
||||
void _add_animation_type(int p_index);
|
||||
|
||||
void _tool_switch(int p_tool);
|
||||
void _update_edited_point_pos();
|
||||
void _update_edited_point_name();
|
||||
void _update_tool_erase();
|
||||
void _erase_selected();
|
||||
void _edit_point_pos(double);
|
||||
void _edit_point_name(const String &p_name);
|
||||
void _edit_point_index(double p_index);
|
||||
void _set_selected_point(int p_index);
|
||||
void _start_inline_edit(int p_point);
|
||||
void _finish_inline_edit();
|
||||
void _finish_inline_edit_with_text(const String &p_text);
|
||||
void _cancel_inline_edit();
|
||||
void _inline_editor_text_changed(const String &p_text);
|
||||
void _open_editor();
|
||||
void _index_edit_focus_entered();
|
||||
void _index_edit_focus_exited();
|
||||
void _index_focus_cooldown_timeout();
|
||||
void _show_indices_with_cooldown();
|
||||
|
||||
EditorFileDialog *open_file = nullptr;
|
||||
Ref<AnimationNode> file_loaded;
|
||||
@@ -122,6 +146,7 @@ class AnimationNodeBlendSpace1DEditor : public AnimationTreeNodeEditorPlugin {
|
||||
};
|
||||
|
||||
StringName get_blend_position_path() const;
|
||||
String _get_safe_name(const Ref<AnimationNodeBlendSpace1D> &p_blend_space, const String &p_name);
|
||||
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
@@ -129,6 +154,7 @@ protected:
|
||||
|
||||
public:
|
||||
static AnimationNodeBlendSpace1DEditor *get_singleton() { return singleton; }
|
||||
void refresh_editor() { _update_space(); }
|
||||
virtual bool can_edit(const Ref<AnimationNode> &p_node) override;
|
||||
virtual void edit(const Ref<AnimationNode> &p_node) override;
|
||||
AnimationNodeBlendSpace1DEditor();
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -41,6 +41,7 @@ class LineEdit;
|
||||
class OptionButton;
|
||||
class PanelContainer;
|
||||
class SpinBox;
|
||||
class Timer;
|
||||
class VSeparator;
|
||||
|
||||
class AnimationNodeBlendSpace2DEditor : public AnimationTreeNodeEditorPlugin {
|
||||
@@ -75,6 +76,8 @@ class AnimationNodeBlendSpace2DEditor : public AnimationTreeNodeEditorPlugin {
|
||||
SpinBox *edit_x = nullptr;
|
||||
SpinBox *edit_y = nullptr;
|
||||
Button *open_editor = nullptr;
|
||||
VSeparator *open_editor_sep = nullptr;
|
||||
SpinBox *index_edit = nullptr;
|
||||
|
||||
int selected_point;
|
||||
int selected_triangle;
|
||||
@@ -109,6 +112,14 @@ class AnimationNodeBlendSpace2DEditor : public AnimationTreeNodeEditorPlugin {
|
||||
Vector2 drag_from;
|
||||
Vector2 drag_ofs;
|
||||
|
||||
Vector<Rect2> text_rects;
|
||||
int editing_point = -1;
|
||||
LineEdit *inline_editor = nullptr;
|
||||
float inline_editor_point_x = 0.0f;
|
||||
bool index_edit_has_focus = false;
|
||||
bool show_indices = false;
|
||||
Timer *index_focus_cooldown_timer = nullptr;
|
||||
|
||||
Vector<int> making_triangle;
|
||||
|
||||
void _add_menu_type(int p_index);
|
||||
@@ -116,14 +127,28 @@ class AnimationNodeBlendSpace2DEditor : public AnimationTreeNodeEditorPlugin {
|
||||
|
||||
void _tool_switch(int p_tool);
|
||||
void _update_edited_point_pos();
|
||||
void _update_edited_point_name();
|
||||
void _update_tool_erase();
|
||||
void _erase_selected();
|
||||
void _edit_point_pos(double);
|
||||
void _edit_point_name(const String &p_name);
|
||||
void _edit_point_index(double p_index);
|
||||
void _set_selected_point(int p_index);
|
||||
void _start_inline_edit(int p_point);
|
||||
void _finish_inline_edit();
|
||||
void _finish_inline_edit_with_text(const String &p_text);
|
||||
void _cancel_inline_edit();
|
||||
void _inline_editor_text_changed(const String &p_text);
|
||||
void _open_editor();
|
||||
void _index_edit_focus_entered();
|
||||
void _index_edit_focus_exited();
|
||||
void _index_focus_cooldown_timeout();
|
||||
void _show_indices_with_cooldown();
|
||||
|
||||
void _auto_triangles_toggled();
|
||||
|
||||
StringName get_blend_position_path() const;
|
||||
String _get_safe_name(const Ref<AnimationNodeBlendSpace2D> &p_blend_space, const String &p_name);
|
||||
|
||||
EditorFileDialog *open_file = nullptr;
|
||||
Ref<AnimationNode> file_loaded;
|
||||
@@ -143,6 +168,7 @@ protected:
|
||||
|
||||
public:
|
||||
static AnimationNodeBlendSpace2DEditor *get_singleton() { return singleton; }
|
||||
void refresh_editor() { _update_space(); }
|
||||
virtual bool can_edit(const Ref<AnimationNode> &p_node) override;
|
||||
virtual void edit(const Ref<AnimationNode> &p_node) override;
|
||||
AnimationNodeBlendSpace2DEditor();
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
GH-110369
|
||||
--------------
|
||||
Validate extension JSON: Error: Field 'classes/AnimationNodeBlendSpace2D/methods/add_blend_point/arguments': size changed value in new API, from 3 to 4.
|
||||
Validate extension JSON: Error: Field 'classes/AnimationNodeBlendSpace1D/methods/add_blend_point/arguments': size changed value in new API, from 3 to 4.
|
||||
|
||||
Added "name" parameter, to functionally replace index reference for points. Compatibility methods registered.
|
||||
@@ -0,0 +1,49 @@
|
||||
/**************************************************************************/
|
||||
/* animation_blend_space_1d.compat.inc */
|
||||
/**************************************************************************/
|
||||
/* 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 DISABLE_DEPRECATED
|
||||
|
||||
#include "animation_blend_space_1d.h"
|
||||
|
||||
#include "core/object/class_db.h"
|
||||
|
||||
void AnimationNodeBlendSpace1D::_add_blend_point_bind_compat_110369(const Ref<AnimationRootNode> &p_node, float p_position, int p_at_index) {
|
||||
int n = p_at_index == -1 ? blend_points_used : p_at_index;
|
||||
while (find_blend_point_by_name(itos(n)) != -1) {
|
||||
n++;
|
||||
}
|
||||
add_blend_point(p_node, p_position, p_at_index, StringName(itos(n)));
|
||||
}
|
||||
|
||||
void AnimationNodeBlendSpace1D::_bind_compatibility_methods() {
|
||||
ClassDB::bind_compatibility_method(D_METHOD("add_blend_point", "node", "pos", "at_index"), &AnimationNodeBlendSpace1D::_add_blend_point_bind_compat_110369, DEFVAL(-1));
|
||||
}
|
||||
|
||||
#endif // DISABLE_DEPRECATED
|
||||
@@ -29,6 +29,7 @@
|
||||
/**************************************************************************/
|
||||
|
||||
#include "animation_blend_space_1d.h"
|
||||
#include "animation_blend_space_1d.compat.inc"
|
||||
|
||||
#include "animation_blend_tree.h"
|
||||
|
||||
@@ -54,17 +55,11 @@ Variant AnimationNodeBlendSpace1D::get_parameter_default_value(const StringName
|
||||
}
|
||||
|
||||
Ref<AnimationNode> AnimationNodeBlendSpace1D::get_child_by_name(const StringName &p_name) const {
|
||||
return get_blend_point_node(p_name.operator String().to_int());
|
||||
}
|
||||
|
||||
void AnimationNodeBlendSpace1D::_validate_property(PropertyInfo &p_property) const {
|
||||
if (p_property.name.begins_with("blend_point_")) {
|
||||
String left = p_property.name.get_slicec('/', 0);
|
||||
int idx = left.get_slicec('_', 2).to_int();
|
||||
if (idx >= blend_points_used) {
|
||||
p_property.usage = PROPERTY_USAGE_NONE;
|
||||
}
|
||||
int point_index = find_blend_point_by_name(p_name);
|
||||
if (point_index != -1) {
|
||||
return get_blend_point_node(point_index);
|
||||
}
|
||||
return Ref<AnimationRootNode>();
|
||||
}
|
||||
|
||||
void AnimationNodeBlendSpace1D::_tree_changed() {
|
||||
@@ -80,13 +75,17 @@ void AnimationNodeBlendSpace1D::_animation_node_removed(const ObjectID &p_oid, c
|
||||
}
|
||||
|
||||
void AnimationNodeBlendSpace1D::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("add_blend_point", "node", "pos", "at_index"), &AnimationNodeBlendSpace1D::add_blend_point, DEFVAL(-1));
|
||||
ClassDB::bind_method(D_METHOD("add_blend_point", "node", "pos", "at_index", "name"), &AnimationNodeBlendSpace1D::add_blend_point, DEFVAL(-1), DEFVAL(StringName()));
|
||||
ClassDB::bind_method(D_METHOD("set_blend_point_position", "point", "pos"), &AnimationNodeBlendSpace1D::set_blend_point_position);
|
||||
ClassDB::bind_method(D_METHOD("get_blend_point_position", "point"), &AnimationNodeBlendSpace1D::get_blend_point_position);
|
||||
ClassDB::bind_method(D_METHOD("set_blend_point_node", "point", "node"), &AnimationNodeBlendSpace1D::set_blend_point_node);
|
||||
ClassDB::bind_method(D_METHOD("get_blend_point_node", "point"), &AnimationNodeBlendSpace1D::get_blend_point_node);
|
||||
ClassDB::bind_method(D_METHOD("set_blend_point_name", "point", "name"), &AnimationNodeBlendSpace1D::set_blend_point_name);
|
||||
ClassDB::bind_method(D_METHOD("get_blend_point_name", "point"), &AnimationNodeBlendSpace1D::get_blend_point_name);
|
||||
ClassDB::bind_method(D_METHOD("find_blend_point_by_name", "name"), &AnimationNodeBlendSpace1D::find_blend_point_by_name);
|
||||
ClassDB::bind_method(D_METHOD("remove_blend_point", "point"), &AnimationNodeBlendSpace1D::remove_blend_point);
|
||||
ClassDB::bind_method(D_METHOD("get_blend_point_count"), &AnimationNodeBlendSpace1D::get_blend_point_count);
|
||||
ClassDB::bind_method(D_METHOD("reorder_blend_point", "from_index", "to_index"), &AnimationNodeBlendSpace1D::reorder_blend_point);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_min_space", "min_space"), &AnimationNodeBlendSpace1D::set_min_space);
|
||||
ClassDB::bind_method(D_METHOD("get_min_space"), &AnimationNodeBlendSpace1D::get_min_space);
|
||||
@@ -106,13 +105,6 @@ void AnimationNodeBlendSpace1D::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_use_sync", "enable"), &AnimationNodeBlendSpace1D::set_use_sync);
|
||||
ClassDB::bind_method(D_METHOD("is_using_sync"), &AnimationNodeBlendSpace1D::is_using_sync);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("_add_blend_point", "index", "node"), &AnimationNodeBlendSpace1D::_add_blend_point);
|
||||
|
||||
for (int i = 0; i < MAX_BLEND_POINTS; i++) {
|
||||
ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "blend_point_" + itos(i) + "/node", PROPERTY_HINT_RESOURCE_TYPE, AnimationRootNode::get_class_static(), PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL), "_add_blend_point", "get_blend_point_node", i);
|
||||
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "blend_point_" + itos(i) + "/pos", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL), "set_blend_point_position", "get_blend_point_position", i);
|
||||
}
|
||||
|
||||
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "min_space", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "set_min_space", "get_min_space");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "max_space", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "set_max_space", "get_max_space");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "snap", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "set_snap", "get_snap");
|
||||
@@ -128,18 +120,25 @@ void AnimationNodeBlendSpace1D::_bind_methods() {
|
||||
void AnimationNodeBlendSpace1D::get_child_nodes(List<ChildNode> *r_child_nodes) {
|
||||
for (int i = 0; i < blend_points_used; i++) {
|
||||
ChildNode cn;
|
||||
cn.name = itos(i);
|
||||
cn.name = blend_points[i].name;
|
||||
cn.node = blend_points[i].node;
|
||||
r_child_nodes->push_back(cn);
|
||||
}
|
||||
}
|
||||
|
||||
void AnimationNodeBlendSpace1D::add_blend_point(const Ref<AnimationRootNode> &p_node, float p_position, int p_at_index) {
|
||||
void AnimationNodeBlendSpace1D::add_blend_point(const Ref<AnimationRootNode> &p_node, float p_position, int p_at_index, const StringName &p_name) {
|
||||
ERR_FAIL_COND(blend_points_used >= MAX_BLEND_POINTS);
|
||||
ERR_FAIL_COND(p_node.is_null());
|
||||
|
||||
ERR_FAIL_COND(p_at_index < -1 || p_at_index > blend_points_used);
|
||||
|
||||
#ifndef DISABLE_DEPRECATED
|
||||
if (p_name == StringName()) {
|
||||
_add_blend_point_bind_compat_110369(p_node, p_position, p_at_index);
|
||||
WARN_PRINT_ED("AnimationNodeBlendSpace1D::add_blend_point: No name provided, using safe index as reference. In the future, empty names will be deprecated, so explicitly passing a name is recommended.");
|
||||
return;
|
||||
}
|
||||
#else
|
||||
ERR_FAIL_COND(p_name == StringName());
|
||||
#endif
|
||||
if (p_at_index == -1 || p_at_index == blend_points_used) {
|
||||
p_at_index = blend_points_used;
|
||||
} else {
|
||||
@@ -150,6 +149,7 @@ void AnimationNodeBlendSpace1D::add_blend_point(const Ref<AnimationRootNode> &p_
|
||||
|
||||
blend_points[p_at_index].node = p_node;
|
||||
blend_points[p_at_index].position = p_position;
|
||||
blend_points[p_at_index].name = p_name;
|
||||
|
||||
blend_points[p_at_index].node->connect("tree_changed", callable_mp(this, &AnimationNodeBlendSpace1D::_tree_changed), CONNECT_REFERENCE_COUNTED);
|
||||
blend_points[p_at_index].node->connect("animation_node_renamed", callable_mp(this, &AnimationNodeBlendSpace1D::_animation_node_renamed), CONNECT_REFERENCE_COUNTED);
|
||||
@@ -193,6 +193,32 @@ Ref<AnimationRootNode> AnimationNodeBlendSpace1D::get_blend_point_node(int p_poi
|
||||
return blend_points[p_point].node;
|
||||
}
|
||||
|
||||
void AnimationNodeBlendSpace1D::set_blend_point_name(int p_point, const StringName &p_name) {
|
||||
ERR_FAIL_INDEX(p_point, blend_points_used);
|
||||
String new_name = p_name;
|
||||
ERR_FAIL_COND(new_name.is_empty() || new_name.contains_char('.') || new_name.contains_char('/'));
|
||||
|
||||
String old_name = blend_points[p_point].name;
|
||||
if (new_name != old_name) {
|
||||
blend_points[p_point].name = p_name;
|
||||
emit_signal(SNAME("animation_node_renamed"), get_instance_id(), old_name, new_name);
|
||||
}
|
||||
}
|
||||
|
||||
StringName AnimationNodeBlendSpace1D::get_blend_point_name(int p_point) const {
|
||||
ERR_FAIL_INDEX_V(p_point, blend_points_used, StringName());
|
||||
return blend_points[p_point].name;
|
||||
}
|
||||
|
||||
int AnimationNodeBlendSpace1D::find_blend_point_by_name(const StringName &p_name) const {
|
||||
for (int i = 0; i < blend_points_used; i++) {
|
||||
if (blend_points[i].name == p_name) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void AnimationNodeBlendSpace1D::remove_blend_point(int p_point) {
|
||||
ERR_FAIL_INDEX(p_point, blend_points_used);
|
||||
|
||||
@@ -207,6 +233,8 @@ void AnimationNodeBlendSpace1D::remove_blend_point(int p_point) {
|
||||
|
||||
blend_points_used--;
|
||||
|
||||
blend_points[blend_points_used].name = StringName();
|
||||
|
||||
emit_signal(SNAME("animation_node_removed"), get_instance_id(), itos(p_point));
|
||||
emit_signal(SNAME("tree_changed"));
|
||||
}
|
||||
@@ -215,6 +243,22 @@ int AnimationNodeBlendSpace1D::get_blend_point_count() const {
|
||||
return blend_points_used;
|
||||
}
|
||||
|
||||
void AnimationNodeBlendSpace1D::reorder_blend_point(int p_from_index, int p_to_index) {
|
||||
ERR_FAIL_INDEX(p_from_index, blend_points_used);
|
||||
ERR_FAIL_INDEX(p_to_index, blend_points_used);
|
||||
|
||||
if (p_from_index == p_to_index) {
|
||||
return;
|
||||
}
|
||||
|
||||
BlendPoint temp = blend_points[p_from_index];
|
||||
|
||||
blend_points[p_from_index] = blend_points[p_to_index];
|
||||
blend_points[p_to_index] = temp;
|
||||
|
||||
emit_signal(SNAME("tree_changed"));
|
||||
}
|
||||
|
||||
void AnimationNodeBlendSpace1D::set_min_space(float p_min) {
|
||||
min_space = p_min;
|
||||
|
||||
@@ -271,11 +315,62 @@ bool AnimationNodeBlendSpace1D::is_using_sync() const {
|
||||
return sync;
|
||||
}
|
||||
|
||||
void AnimationNodeBlendSpace1D::_add_blend_point(int p_index, const Ref<AnimationRootNode> &p_node) {
|
||||
if (p_index == blend_points_used) {
|
||||
add_blend_point(p_node, 0);
|
||||
} else {
|
||||
set_blend_point_node(p_index, p_node);
|
||||
bool AnimationNodeBlendSpace1D::_set(const StringName &p_name, const Variant &p_value) {
|
||||
String prop = p_name;
|
||||
if (prop.begins_with("blend_point_")) {
|
||||
int idx = prop.get_slicec('_', 2).to_int();
|
||||
String what = prop.get_slicec('/', 1);
|
||||
if (what == "node") {
|
||||
Ref<AnimationRootNode> node = p_value;
|
||||
#ifndef DISABLE_DEPRECATED
|
||||
if (idx == blend_points_used) {
|
||||
add_blend_point(node, 0, -1, blend_points[idx].name.is_empty() ? StringName(itos(idx)) : blend_points[idx].name);
|
||||
} else {
|
||||
set_blend_point_node(idx, node);
|
||||
}
|
||||
#else
|
||||
if (idx == blend_points_used) {
|
||||
add_blend_point(node, 0, -1, blend_points[idx].name);
|
||||
} else {
|
||||
set_blend_point_node(idx, node);
|
||||
}
|
||||
#endif // DISABLE_DEPRECATED
|
||||
} else if (what == "pos") {
|
||||
set_blend_point_position(idx, p_value);
|
||||
} else if (what == "name") {
|
||||
set_blend_point_name(idx, p_value);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AnimationNodeBlendSpace1D::_get(const StringName &p_name, Variant &r_ret) const {
|
||||
String prop = p_name;
|
||||
if (prop.begins_with("blend_point_")) {
|
||||
int idx = prop.get_slicec('_', 2).to_int();
|
||||
String what = prop.get_slicec('/', 1);
|
||||
if (what == "node") {
|
||||
r_ret = get_blend_point_node(idx);
|
||||
} else if (what == "pos") {
|
||||
r_ret = get_blend_point_position(idx);
|
||||
} else if (what == "name") {
|
||||
r_ret = get_blend_point_name(idx);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void AnimationNodeBlendSpace1D::_get_property_list(List<PropertyInfo> *p_list) const {
|
||||
for (int i = 0; i < blend_points_used; i++) {
|
||||
p_list->push_back(PropertyInfo(Variant::OBJECT, "blend_point_" + itos(i) + "/node", PROPERTY_HINT_RESOURCE_TYPE, AnimationRootNode::get_class_static(), PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL));
|
||||
p_list->push_back(PropertyInfo(Variant::FLOAT, "blend_point_" + itos(i) + "/pos", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL));
|
||||
p_list->push_back(PropertyInfo(Variant::STRING, "blend_point_" + itos(i) + "/name", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -289,7 +384,7 @@ AnimationNode::NodeTimeInfo AnimationNodeBlendSpace1D::_process(const AnimationM
|
||||
if (blend_points_used == 1) {
|
||||
// only one point available, just play that animation
|
||||
pi.weight = 1.0;
|
||||
return blend_node(blend_points[0].node, blend_points[0].name, pi, FILTER_IGNORE, true, p_test_only);
|
||||
return blend_node(blend_points[0].node, get_blend_point_name(0), pi, FILTER_IGNORE, true, p_test_only);
|
||||
}
|
||||
|
||||
double blend_pos = get_parameter(blend_position);
|
||||
@@ -352,7 +447,7 @@ AnimationNode::NodeTimeInfo AnimationNodeBlendSpace1D::_process(const AnimationM
|
||||
for (int i = 0; i < blend_points_used; i++) {
|
||||
if (i == point_lower || i == point_higher) {
|
||||
pi.weight = weights[i];
|
||||
NodeTimeInfo t = blend_node(blend_points[i].node, blend_points[i].name, pi, FILTER_IGNORE, true, p_test_only);
|
||||
NodeTimeInfo t = blend_node(blend_points[i].node, get_blend_point_name(i), pi, FILTER_IGNORE, true, p_test_only);
|
||||
if (first || pi.weight > max_weight) {
|
||||
max_weight = pi.weight;
|
||||
mind = t;
|
||||
@@ -360,7 +455,7 @@ AnimationNode::NodeTimeInfo AnimationNodeBlendSpace1D::_process(const AnimationM
|
||||
}
|
||||
} else if (sync) {
|
||||
pi.weight = 0;
|
||||
blend_node(blend_points[i].node, blend_points[i].name, pi, FILTER_IGNORE, true, p_test_only);
|
||||
blend_node(blend_points[i].node, get_blend_point_name(i), pi, FILTER_IGNORE, true, p_test_only);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -393,16 +488,16 @@ AnimationNode::NodeTimeInfo AnimationNodeBlendSpace1D::_process(const AnimationM
|
||||
// See how much animation remains.
|
||||
pi.seeked = false;
|
||||
pi.weight = 0;
|
||||
from = blend_node(blend_points[cur_closest].node, blend_points[cur_closest].name, pi, FILTER_IGNORE, true, true);
|
||||
from = blend_node(blend_points[cur_closest].node, get_blend_point_name(cur_closest), pi, FILTER_IGNORE, true, true);
|
||||
pi.time = from.position;
|
||||
}
|
||||
pi.seeked = true;
|
||||
pi.weight = 1.0;
|
||||
mind = blend_node(blend_points[new_closest].node, blend_points[new_closest].name, pi, FILTER_IGNORE, true, p_test_only);
|
||||
mind = blend_node(blend_points[new_closest].node, get_blend_point_name(new_closest), pi, FILTER_IGNORE, true, p_test_only);
|
||||
cur_closest = new_closest;
|
||||
} else {
|
||||
pi.weight = 1.0;
|
||||
mind = blend_node(blend_points[cur_closest].node, blend_points[cur_closest].name, pi, FILTER_IGNORE, true, p_test_only);
|
||||
mind = blend_node(blend_points[cur_closest].node, get_blend_point_name(cur_closest), pi, FILTER_IGNORE, true, p_test_only);
|
||||
}
|
||||
|
||||
if (sync) {
|
||||
@@ -410,7 +505,7 @@ AnimationNode::NodeTimeInfo AnimationNodeBlendSpace1D::_process(const AnimationM
|
||||
pi.weight = 0;
|
||||
for (int i = 0; i < blend_points_used; i++) {
|
||||
if (i != cur_closest) {
|
||||
blend_node(blend_points[i].node, blend_points[i].name, pi, FILTER_IGNORE, true, p_test_only);
|
||||
blend_node(blend_points[i].node, get_blend_point_name(i), pi, FILTER_IGNORE, true, p_test_only);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -425,9 +520,6 @@ String AnimationNodeBlendSpace1D::get_caption() const {
|
||||
}
|
||||
|
||||
AnimationNodeBlendSpace1D::AnimationNodeBlendSpace1D() {
|
||||
for (int i = 0; i < MAX_BLEND_POINTS; i++) {
|
||||
blend_points[i].name = itos(i);
|
||||
}
|
||||
}
|
||||
|
||||
AnimationNodeBlendSpace1D::~AnimationNodeBlendSpace1D() {
|
||||
|
||||
@@ -63,7 +63,9 @@ protected:
|
||||
|
||||
String value_label = "value";
|
||||
|
||||
void _add_blend_point(int p_index, const Ref<AnimationRootNode> &p_node);
|
||||
bool _set(const StringName &p_name, const Variant &p_value);
|
||||
bool _get(const StringName &p_name, Variant &r_ret) const;
|
||||
void _get_property_list(List<PropertyInfo> *p_list) const;
|
||||
|
||||
StringName blend_position = "blend_position";
|
||||
StringName closest = "closest";
|
||||
@@ -72,28 +74,37 @@ protected:
|
||||
|
||||
bool sync = false;
|
||||
|
||||
void _validate_property(PropertyInfo &p_property) const;
|
||||
static void _bind_methods();
|
||||
|
||||
virtual void _tree_changed() override;
|
||||
virtual void _animation_node_renamed(const ObjectID &p_oid, const String &p_old_name, const String &p_new_name) override;
|
||||
virtual void _animation_node_removed(const ObjectID &p_oid, const StringName &p_node) override;
|
||||
|
||||
#ifndef DISABLE_DEPRECATED
|
||||
void _add_blend_point_bind_compat_110369(const Ref<AnimationRootNode> &p_node, float p_position, int p_at_index = -1);
|
||||
static void _bind_compatibility_methods();
|
||||
#endif
|
||||
|
||||
public:
|
||||
virtual void get_parameter_list(List<PropertyInfo> *r_list) const override;
|
||||
virtual Variant get_parameter_default_value(const StringName &p_parameter) const override;
|
||||
|
||||
virtual void get_child_nodes(List<ChildNode> *r_child_nodes) override;
|
||||
|
||||
void add_blend_point(const Ref<AnimationRootNode> &p_node, float p_position, int p_at_index = -1);
|
||||
void add_blend_point(const Ref<AnimationRootNode> &p_node, float p_position, int p_at_index = -1, const StringName &p_name = "");
|
||||
void set_blend_point_position(int p_point, float p_position);
|
||||
void set_blend_point_node(int p_point, const Ref<AnimationRootNode> &p_node);
|
||||
|
||||
float get_blend_point_position(int p_point) const;
|
||||
Ref<AnimationRootNode> get_blend_point_node(int p_point) const;
|
||||
void set_blend_point_name(int p_point, const StringName &p_name);
|
||||
StringName get_blend_point_name(int p_point) const;
|
||||
int find_blend_point_by_name(const StringName &p_name) const;
|
||||
void remove_blend_point(int p_point);
|
||||
int get_blend_point_count() const;
|
||||
|
||||
void reorder_blend_point(int p_from_index, int p_to_index);
|
||||
|
||||
void set_min_space(float p_min);
|
||||
float get_min_space() const;
|
||||
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
/**************************************************************************/
|
||||
/* animation_blend_space_2d.compat.inc */
|
||||
/**************************************************************************/
|
||||
/* 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 DISABLE_DEPRECATED
|
||||
|
||||
#include "animation_blend_space_2d.h"
|
||||
|
||||
#include "core/object/class_db.h"
|
||||
|
||||
void AnimationNodeBlendSpace2D::_add_blend_point_bind_compat_110369(const Ref<AnimationRootNode> &p_node, const Vector2 &p_position, int p_at_index) {
|
||||
int n = p_at_index == -1 ? blend_points_used : p_at_index;
|
||||
while (find_blend_point_by_name(itos(n)) != -1) {
|
||||
n++;
|
||||
}
|
||||
add_blend_point(p_node, p_position, p_at_index, StringName(itos(n)));
|
||||
}
|
||||
|
||||
void AnimationNodeBlendSpace2D::_bind_compatibility_methods() {
|
||||
ClassDB::bind_compatibility_method(D_METHOD("add_blend_point", "node", "pos", "at_index"), &AnimationNodeBlendSpace2D::_add_blend_point_bind_compat_110369, DEFVAL(-1));
|
||||
}
|
||||
|
||||
#endif // DISABLE_DEPRECATED
|
||||
@@ -29,6 +29,7 @@
|
||||
/**************************************************************************/
|
||||
|
||||
#include "animation_blend_space_2d.h"
|
||||
#include "animation_blend_space_2d.compat.inc"
|
||||
|
||||
#include "animation_blend_tree.h"
|
||||
|
||||
@@ -58,16 +59,25 @@ Variant AnimationNodeBlendSpace2D::get_parameter_default_value(const StringName
|
||||
void AnimationNodeBlendSpace2D::get_child_nodes(List<ChildNode> *r_child_nodes) {
|
||||
for (int i = 0; i < blend_points_used; i++) {
|
||||
ChildNode cn;
|
||||
cn.name = itos(i);
|
||||
cn.name = blend_points[i].name;
|
||||
cn.node = blend_points[i].node;
|
||||
r_child_nodes->push_back(cn);
|
||||
}
|
||||
}
|
||||
|
||||
void AnimationNodeBlendSpace2D::add_blend_point(const Ref<AnimationRootNode> &p_node, const Vector2 &p_position, int p_at_index) {
|
||||
void AnimationNodeBlendSpace2D::add_blend_point(const Ref<AnimationRootNode> &p_node, const Vector2 &p_position, int p_at_index, const StringName &p_name) {
|
||||
ERR_FAIL_COND(blend_points_used >= MAX_BLEND_POINTS);
|
||||
ERR_FAIL_COND(p_node.is_null());
|
||||
ERR_FAIL_COND(p_at_index < -1 || p_at_index > blend_points_used);
|
||||
#ifndef DISABLE_DEPRECATED
|
||||
if (p_name == StringName()) {
|
||||
_add_blend_point_bind_compat_110369(p_node, p_position, p_at_index);
|
||||
WARN_PRINT_ED("AnimationNodeBlendSpace2D::add_blend_point: No name provided, using safe index as reference. In the future, empty names will be deprecated, so explicitly passing a name is recommended.");
|
||||
return;
|
||||
}
|
||||
#else
|
||||
ERR_FAIL_COND(p_name == StringName());
|
||||
#endif
|
||||
|
||||
if (p_at_index == -1 || p_at_index == blend_points_used) {
|
||||
p_at_index = blend_points_used;
|
||||
@@ -85,6 +95,7 @@ void AnimationNodeBlendSpace2D::add_blend_point(const Ref<AnimationRootNode> &p_
|
||||
}
|
||||
blend_points[p_at_index].node = p_node;
|
||||
blend_points[p_at_index].position = p_position;
|
||||
blend_points[p_at_index].name = p_name;
|
||||
|
||||
blend_points[p_at_index].node->connect("tree_changed", callable_mp(this, &AnimationNodeBlendSpace2D::_tree_changed), CONNECT_REFERENCE_COUNTED);
|
||||
blend_points[p_at_index].node->connect("animation_node_renamed", callable_mp(this, &AnimationNodeBlendSpace2D::_animation_node_renamed), CONNECT_REFERENCE_COUNTED);
|
||||
@@ -129,6 +140,32 @@ Ref<AnimationRootNode> AnimationNodeBlendSpace2D::get_blend_point_node(int p_poi
|
||||
return blend_points[p_point].node;
|
||||
}
|
||||
|
||||
void AnimationNodeBlendSpace2D::set_blend_point_name(int p_point, const StringName &p_name) {
|
||||
ERR_FAIL_INDEX(p_point, blend_points_used);
|
||||
String new_name = p_name;
|
||||
ERR_FAIL_COND(new_name.is_empty() || new_name.contains_char('.') || new_name.contains_char('/'));
|
||||
|
||||
String old_name = blend_points[p_point].name;
|
||||
if (new_name != old_name) {
|
||||
blend_points[p_point].name = p_name;
|
||||
emit_signal(SNAME("animation_node_renamed"), get_instance_id(), old_name, p_name);
|
||||
}
|
||||
}
|
||||
|
||||
StringName AnimationNodeBlendSpace2D::get_blend_point_name(int p_point) const {
|
||||
ERR_FAIL_INDEX_V(p_point, blend_points_used, StringName());
|
||||
return blend_points[p_point].name;
|
||||
}
|
||||
|
||||
int AnimationNodeBlendSpace2D::find_blend_point_by_name(const StringName &p_name) const {
|
||||
for (int i = 0; i < blend_points_used; i++) {
|
||||
if (blend_points[i].name == p_name) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void AnimationNodeBlendSpace2D::remove_blend_point(int p_point) {
|
||||
ERR_FAIL_INDEX(p_point, blend_points_used);
|
||||
|
||||
@@ -159,6 +196,8 @@ void AnimationNodeBlendSpace2D::remove_blend_point(int p_point) {
|
||||
}
|
||||
blend_points_used--;
|
||||
|
||||
blend_points[blend_points_used].name = StringName();
|
||||
|
||||
emit_signal(SNAME("animation_node_removed"), get_instance_id(), itos(p_point));
|
||||
emit_signal(SNAME("tree_changed"));
|
||||
}
|
||||
@@ -167,6 +206,38 @@ int AnimationNodeBlendSpace2D::get_blend_point_count() const {
|
||||
return blend_points_used;
|
||||
}
|
||||
|
||||
void AnimationNodeBlendSpace2D::reorder_blend_point(int p_from_index, int p_to_index) {
|
||||
ERR_FAIL_INDEX(p_from_index, blend_points_used);
|
||||
ERR_FAIL_INDEX(p_to_index, blend_points_used);
|
||||
|
||||
if (p_from_index == p_to_index) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Update triangle indices for swap operation
|
||||
for (int i = 0; i < triangles.size(); i++) {
|
||||
for (int j = 0; j < 3; j++) {
|
||||
int point_ref = triangles[i].points[j];
|
||||
|
||||
if (point_ref == p_from_index) {
|
||||
triangles.write[i].points[j] = p_to_index;
|
||||
} else if (point_ref == p_to_index) {
|
||||
triangles.write[i].points[j] = p_from_index;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BlendPoint temp = blend_points[p_from_index];
|
||||
|
||||
blend_points[p_from_index] = blend_points[p_to_index];
|
||||
blend_points[p_to_index] = temp;
|
||||
|
||||
_queue_auto_triangles();
|
||||
|
||||
emit_signal(SNAME("tree_changed"));
|
||||
emit_signal(SNAME("triangles_updated"));
|
||||
}
|
||||
|
||||
bool AnimationNodeBlendSpace2D::has_triangle(int p_x, int p_y, int p_z) const {
|
||||
ERR_FAIL_INDEX_V(p_x, blend_points_used, false);
|
||||
ERR_FAIL_INDEX_V(p_y, blend_points_used, false);
|
||||
@@ -299,14 +370,6 @@ String AnimationNodeBlendSpace2D::get_y_label() const {
|
||||
return y_label;
|
||||
}
|
||||
|
||||
void AnimationNodeBlendSpace2D::_add_blend_point(int p_index, const Ref<AnimationRootNode> &p_node) {
|
||||
if (p_index == blend_points_used) {
|
||||
add_blend_point(p_node, Vector2());
|
||||
} else {
|
||||
set_blend_point_node(p_index, p_node);
|
||||
}
|
||||
}
|
||||
|
||||
void AnimationNodeBlendSpace2D::_set_triangles(const Vector<int> &p_triangles) {
|
||||
if (auto_triangles) {
|
||||
return;
|
||||
@@ -332,6 +395,65 @@ Vector<int> AnimationNodeBlendSpace2D::_get_triangles() const {
|
||||
return t;
|
||||
}
|
||||
|
||||
bool AnimationNodeBlendSpace2D::_set(const StringName &p_name, const Variant &p_value) {
|
||||
String prop = p_name;
|
||||
if (prop.begins_with("blend_point_")) {
|
||||
int idx = prop.get_slicec('_', 2).to_int();
|
||||
String what = prop.get_slicec('/', 1);
|
||||
if (what == "node") {
|
||||
Ref<AnimationRootNode> node = p_value;
|
||||
#ifndef DISABLE_DEPRECATED
|
||||
if (idx == blend_points_used) {
|
||||
add_blend_point(node, Vector2(), -1, blend_points[idx].name.is_empty() ? StringName(itos(idx)) : blend_points[idx].name);
|
||||
} else {
|
||||
set_blend_point_node(idx, node);
|
||||
}
|
||||
#else
|
||||
if (idx == blend_points_used) {
|
||||
add_blend_point(node, Vector2(), -1, blend_points[idx].name);
|
||||
} else {
|
||||
set_blend_point_node(idx, node);
|
||||
}
|
||||
#endif // DISABLE_DEPRECATED
|
||||
} else if (what == "pos") {
|
||||
set_blend_point_position(idx, p_value);
|
||||
} else if (what == "name") {
|
||||
set_blend_point_name(idx, p_value);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AnimationNodeBlendSpace2D::_get(const StringName &p_name, Variant &r_ret) const {
|
||||
String prop = p_name;
|
||||
if (prop.begins_with("blend_point_")) {
|
||||
int idx = prop.get_slicec('_', 2).to_int();
|
||||
String what = prop.get_slicec('/', 1);
|
||||
if (what == "node") {
|
||||
r_ret = get_blend_point_node(idx);
|
||||
} else if (what == "pos") {
|
||||
r_ret = get_blend_point_position(idx);
|
||||
} else if (what == "name") {
|
||||
r_ret = get_blend_point_name(idx);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void AnimationNodeBlendSpace2D::_get_property_list(List<PropertyInfo> *p_list) const {
|
||||
for (int i = 0; i < blend_points_used; i++) {
|
||||
p_list->push_back(PropertyInfo(Variant::OBJECT, "blend_point_" + itos(i) + "/node", PROPERTY_HINT_RESOURCE_TYPE, AnimationRootNode::get_class_static(), PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL));
|
||||
p_list->push_back(PropertyInfo(Variant::VECTOR2, "blend_point_" + itos(i) + "/pos", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL));
|
||||
p_list->push_back(PropertyInfo(Variant::STRING, "blend_point_" + itos(i) + "/name", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL));
|
||||
}
|
||||
}
|
||||
|
||||
void AnimationNodeBlendSpace2D::_queue_auto_triangles() {
|
||||
if (!auto_triangles || triangles_dirty) {
|
||||
return;
|
||||
@@ -521,7 +643,7 @@ AnimationNode::NodeTimeInfo AnimationNodeBlendSpace2D::_process(const AnimationM
|
||||
if (i == triangle_points[j]) {
|
||||
//blend with the given weight
|
||||
pi.weight = blend_weights[j];
|
||||
NodeTimeInfo t = blend_node(blend_points[i].node, blend_points[i].name, pi, FILTER_IGNORE, true, p_test_only);
|
||||
NodeTimeInfo t = blend_node(blend_points[i].node, get_blend_point_name(i), pi, FILTER_IGNORE, true, p_test_only);
|
||||
if (first || pi.weight > max_weight) {
|
||||
mind = t;
|
||||
max_weight = pi.weight;
|
||||
@@ -534,7 +656,7 @@ AnimationNode::NodeTimeInfo AnimationNodeBlendSpace2D::_process(const AnimationM
|
||||
|
||||
if (sync && !found) {
|
||||
pi.weight = 0;
|
||||
blend_node(blend_points[i].node, blend_points[i].name, pi, FILTER_IGNORE, true, p_test_only);
|
||||
blend_node(blend_points[i].node, get_blend_point_name(i), pi, FILTER_IGNORE, true, p_test_only);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -567,16 +689,16 @@ AnimationNode::NodeTimeInfo AnimationNodeBlendSpace2D::_process(const AnimationM
|
||||
// See how much animation remains.
|
||||
pi.seeked = false;
|
||||
pi.weight = 0;
|
||||
from = blend_node(blend_points[cur_closest].node, blend_points[cur_closest].name, pi, FILTER_IGNORE, true, true);
|
||||
from = blend_node(blend_points[cur_closest].node, get_blend_point_name(cur_closest), pi, FILTER_IGNORE, true, true);
|
||||
pi.time = from.position;
|
||||
}
|
||||
pi.seeked = true;
|
||||
pi.weight = 1.0;
|
||||
mind = blend_node(blend_points[new_closest].node, blend_points[new_closest].name, pi, FILTER_IGNORE, true, p_test_only);
|
||||
mind = blend_node(blend_points[new_closest].node, get_blend_point_name(new_closest), pi, FILTER_IGNORE, true, p_test_only);
|
||||
cur_closest = new_closest;
|
||||
} else {
|
||||
pi.weight = 1.0;
|
||||
mind = blend_node(blend_points[cur_closest].node, blend_points[cur_closest].name, pi, FILTER_IGNORE, true, p_test_only);
|
||||
mind = blend_node(blend_points[cur_closest].node, get_blend_point_name(cur_closest), pi, FILTER_IGNORE, true, p_test_only);
|
||||
}
|
||||
|
||||
if (sync) {
|
||||
@@ -584,7 +706,7 @@ AnimationNode::NodeTimeInfo AnimationNodeBlendSpace2D::_process(const AnimationM
|
||||
pi.weight = 0;
|
||||
for (int i = 0; i < blend_points_used; i++) {
|
||||
if (i != cur_closest) {
|
||||
blend_node(blend_points[i].node, blend_points[i].name, pi, FILTER_IGNORE, true, p_test_only);
|
||||
blend_node(blend_points[i].node, get_blend_point_name(i), pi, FILTER_IGNORE, true, p_test_only);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -601,12 +723,6 @@ String AnimationNodeBlendSpace2D::get_caption() const {
|
||||
void AnimationNodeBlendSpace2D::_validate_property(PropertyInfo &p_property) const {
|
||||
if (auto_triangles && p_property.name == "triangles") {
|
||||
p_property.usage = PROPERTY_USAGE_NONE;
|
||||
} else if (p_property.name.begins_with("blend_point_")) {
|
||||
String left = p_property.name.get_slicec('/', 0);
|
||||
int idx = left.get_slicec('_', 2).to_int();
|
||||
if (idx >= blend_points_used) {
|
||||
p_property.usage = PROPERTY_USAGE_NONE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -624,7 +740,11 @@ bool AnimationNodeBlendSpace2D::get_auto_triangles() const {
|
||||
}
|
||||
|
||||
Ref<AnimationNode> AnimationNodeBlendSpace2D::get_child_by_name(const StringName &p_name) const {
|
||||
return get_blend_point_node(p_name.operator String().to_int());
|
||||
int point_index = find_blend_point_by_name(p_name);
|
||||
if (point_index != -1) {
|
||||
return get_blend_point_node(point_index);
|
||||
}
|
||||
return Ref<AnimationRootNode>();
|
||||
}
|
||||
|
||||
void AnimationNodeBlendSpace2D::set_blend_mode(BlendMode p_blend_mode) {
|
||||
@@ -656,13 +776,17 @@ void AnimationNodeBlendSpace2D::_animation_node_removed(const ObjectID &p_oid, c
|
||||
}
|
||||
|
||||
void AnimationNodeBlendSpace2D::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("add_blend_point", "node", "pos", "at_index"), &AnimationNodeBlendSpace2D::add_blend_point, DEFVAL(-1));
|
||||
ClassDB::bind_method(D_METHOD("add_blend_point", "node", "pos", "at_index", "name"), &AnimationNodeBlendSpace2D::add_blend_point, DEFVAL(-1), DEFVAL(StringName()));
|
||||
ClassDB::bind_method(D_METHOD("set_blend_point_position", "point", "pos"), &AnimationNodeBlendSpace2D::set_blend_point_position);
|
||||
ClassDB::bind_method(D_METHOD("get_blend_point_position", "point"), &AnimationNodeBlendSpace2D::get_blend_point_position);
|
||||
ClassDB::bind_method(D_METHOD("set_blend_point_node", "point", "node"), &AnimationNodeBlendSpace2D::set_blend_point_node);
|
||||
ClassDB::bind_method(D_METHOD("get_blend_point_node", "point"), &AnimationNodeBlendSpace2D::get_blend_point_node);
|
||||
ClassDB::bind_method(D_METHOD("set_blend_point_name", "point", "name"), &AnimationNodeBlendSpace2D::set_blend_point_name);
|
||||
ClassDB::bind_method(D_METHOD("get_blend_point_name", "point"), &AnimationNodeBlendSpace2D::get_blend_point_name);
|
||||
ClassDB::bind_method(D_METHOD("find_blend_point_by_name", "name"), &AnimationNodeBlendSpace2D::find_blend_point_by_name);
|
||||
ClassDB::bind_method(D_METHOD("remove_blend_point", "point"), &AnimationNodeBlendSpace2D::remove_blend_point);
|
||||
ClassDB::bind_method(D_METHOD("get_blend_point_count"), &AnimationNodeBlendSpace2D::get_blend_point_count);
|
||||
ClassDB::bind_method(D_METHOD("reorder_blend_point", "from_index", "to_index"), &AnimationNodeBlendSpace2D::reorder_blend_point);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("add_triangle", "x", "y", "z", "at_index"), &AnimationNodeBlendSpace2D::add_triangle, DEFVAL(-1));
|
||||
ClassDB::bind_method(D_METHOD("get_triangle_point", "triangle", "point"), &AnimationNodeBlendSpace2D::get_triangle_point);
|
||||
@@ -684,8 +808,6 @@ void AnimationNodeBlendSpace2D::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_y_label", "text"), &AnimationNodeBlendSpace2D::set_y_label);
|
||||
ClassDB::bind_method(D_METHOD("get_y_label"), &AnimationNodeBlendSpace2D::get_y_label);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("_add_blend_point", "index", "node"), &AnimationNodeBlendSpace2D::_add_blend_point);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("_set_triangles", "triangles"), &AnimationNodeBlendSpace2D::_set_triangles);
|
||||
ClassDB::bind_method(D_METHOD("_get_triangles"), &AnimationNodeBlendSpace2D::_get_triangles);
|
||||
|
||||
@@ -699,12 +821,6 @@ void AnimationNodeBlendSpace2D::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("is_using_sync"), &AnimationNodeBlendSpace2D::is_using_sync);
|
||||
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "auto_triangles", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "set_auto_triangles", "get_auto_triangles");
|
||||
|
||||
for (int i = 0; i < MAX_BLEND_POINTS; i++) {
|
||||
ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "blend_point_" + itos(i) + "/node", PROPERTY_HINT_RESOURCE_TYPE, AnimationRootNode::get_class_static(), PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL), "_add_blend_point", "get_blend_point_node", i);
|
||||
ADD_PROPERTYI(PropertyInfo(Variant::VECTOR2, "blend_point_" + itos(i) + "/pos", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL), "set_blend_point_position", "get_blend_point_position", i);
|
||||
}
|
||||
|
||||
ADD_PROPERTY(PropertyInfo(Variant::PACKED_INT32_ARRAY, "triangles", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL), "_set_triangles", "_get_triangles");
|
||||
|
||||
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "min_space", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "set_min_space", "get_min_space");
|
||||
@@ -722,9 +838,6 @@ void AnimationNodeBlendSpace2D::_bind_methods() {
|
||||
}
|
||||
|
||||
AnimationNodeBlendSpace2D::AnimationNodeBlendSpace2D() {
|
||||
for (int i = 0; i < MAX_BLEND_POINTS; i++) {
|
||||
blend_points[i].name = itos(i);
|
||||
}
|
||||
}
|
||||
|
||||
AnimationNodeBlendSpace2D::~AnimationNodeBlendSpace2D() {
|
||||
|
||||
@@ -71,7 +71,10 @@ protected:
|
||||
String y_label = "y";
|
||||
BlendMode blend_mode = BLEND_MODE_INTERPOLATED;
|
||||
|
||||
void _add_blend_point(int p_index, const Ref<AnimationRootNode> &p_node);
|
||||
bool _set(const StringName &p_name, const Variant &p_value);
|
||||
bool _get(const StringName &p_name, Variant &r_ret) const;
|
||||
void _get_property_list(List<PropertyInfo> *p_list) const;
|
||||
|
||||
void _set_triangles(const Vector<int> &p_triangles);
|
||||
Vector<int> _get_triangles() const;
|
||||
|
||||
@@ -92,20 +95,30 @@ protected:
|
||||
virtual void _animation_node_renamed(const ObjectID &p_oid, const String &p_old_name, const String &p_new_name) override;
|
||||
virtual void _animation_node_removed(const ObjectID &p_oid, const StringName &p_node) override;
|
||||
|
||||
#ifndef DISABLE_DEPRECATED
|
||||
void _add_blend_point_bind_compat_110369(const Ref<AnimationRootNode> &p_node, const Vector2 &p_position, int p_at_index = -1);
|
||||
static void _bind_compatibility_methods();
|
||||
#endif
|
||||
|
||||
public:
|
||||
virtual void get_parameter_list(List<PropertyInfo> *r_list) const override;
|
||||
virtual Variant get_parameter_default_value(const StringName &p_parameter) const override;
|
||||
|
||||
virtual void get_child_nodes(List<ChildNode> *r_child_nodes) override;
|
||||
|
||||
void add_blend_point(const Ref<AnimationRootNode> &p_node, const Vector2 &p_position, int p_at_index = -1);
|
||||
void add_blend_point(const Ref<AnimationRootNode> &p_node, const Vector2 &p_position, int p_at_index = -1, const StringName &p_name = StringName());
|
||||
void set_blend_point_position(int p_point, const Vector2 &p_position);
|
||||
void set_blend_point_node(int p_point, const Ref<AnimationRootNode> &p_node);
|
||||
void set_blend_point_name(int p_point, const StringName &p_name);
|
||||
StringName get_blend_point_name(int p_point) const;
|
||||
int find_blend_point_by_name(const StringName &p_name) const;
|
||||
Vector2 get_blend_point_position(int p_point) const;
|
||||
Ref<AnimationRootNode> get_blend_point_node(int p_point) const;
|
||||
void remove_blend_point(int p_point);
|
||||
int get_blend_point_count() const;
|
||||
|
||||
void reorder_blend_point(int p_from_index, int p_to_index);
|
||||
|
||||
bool has_triangle(int p_x, int p_y, int p_z) const;
|
||||
void add_triangle(int p_x, int p_y, int p_z, int p_at_index = -1);
|
||||
int get_triangle_point(int p_triangle, int p_point);
|
||||
|
||||
Reference in New Issue
Block a user