summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
Diffstat (limited to 'scene')
-rw-r--r--scene/animation/animation_blend_space_2d.cpp40
-rw-r--r--scene/animation/animation_blend_space_2d.h1
2 files changed, 31 insertions, 10 deletions
diff --git a/scene/animation/animation_blend_space_2d.cpp b/scene/animation/animation_blend_space_2d.cpp
index 8b26044805..d744d6cc8e 100644
--- a/scene/animation/animation_blend_space_2d.cpp
+++ b/scene/animation/animation_blend_space_2d.cpp
@@ -80,18 +80,15 @@ void AnimationNodeBlendSpace2D::add_blend_point(const Ref<AnimationRootNode> &p_
blend_points[p_at_index].node->connect("tree_changed", this, "_tree_changed", varray(), CONNECT_REFERENCE_COUNTED);
blend_points_used++;
- if (auto_triangles) {
- trianges_dirty = true;
- }
+ _queue_auto_triangles();
+
emit_signal("tree_changed");
}
void AnimationNodeBlendSpace2D::set_blend_point_position(int p_point, const Vector2 &p_position) {
ERR_FAIL_INDEX(p_point, blend_points_used);
blend_points[p_point].position = p_position;
- if (auto_triangles) {
- trianges_dirty = true;
- }
+ _queue_auto_triangles();
}
void AnimationNodeBlendSpace2D::set_blend_point_node(int p_point, const Ref<AnimationRootNode> &p_node) {
ERR_FAIL_INDEX(p_point, blend_points_used);
@@ -309,15 +306,27 @@ Vector<int> AnimationNodeBlendSpace2D::_get_triangles() const {
return t;
}
+void AnimationNodeBlendSpace2D::_queue_auto_triangles() {
+ if (!auto_triangles || trianges_dirty) {
+ return;
+ }
+
+ trianges_dirty = true;
+ call_deferred("_update_triangles");
+}
+
void AnimationNodeBlendSpace2D::_update_triangles() {
if (!auto_triangles || !trianges_dirty)
return;
+ print_line("updating triangles");
trianges_dirty = false;
triangles.clear();
- if (blend_points_used < 3)
+ if (blend_points_used < 3) {
+ emit_signal("triangles_updated");
return;
+ }
Vector<Vector2> points;
points.resize(blend_points_used);
@@ -327,9 +336,12 @@ void AnimationNodeBlendSpace2D::_update_triangles() {
Vector<Delaunay2D::Triangle> triangles = Delaunay2D::triangulate(points);
+ print_line("triangles generated: " + itos(triangles.size()));
+
for (int i = 0; i < triangles.size(); i++) {
add_triangle(triangles[i].points[0], triangles[i].points[1], triangles[i].points[2]);
}
+ emit_signal("triangles_updated");
}
Vector2 AnimationNodeBlendSpace2D::get_closest_point(const Vector2 &p_point) {
@@ -546,6 +558,10 @@ String AnimationNodeBlendSpace2D::get_caption() const {
}
void AnimationNodeBlendSpace2D::_validate_property(PropertyInfo &property) const {
+
+ if (auto_triangles && property.name == "triangles") {
+ property.usage = 0;
+ }
if (property.name.begins_with("blend_point_")) {
String left = property.name.get_slicec('/', 0);
int idx = left.get_slicec('_', 2).to_int();
@@ -557,10 +573,12 @@ void AnimationNodeBlendSpace2D::_validate_property(PropertyInfo &property) const
}
void AnimationNodeBlendSpace2D::set_auto_triangles(bool p_enable) {
- auto_triangles = p_enable;
- if (auto_triangles) {
- trianges_dirty = true;
+ if (auto_triangles == p_enable) {
+ return;
}
+
+ auto_triangles = p_enable;
+ _queue_auto_triangles();
}
bool AnimationNodeBlendSpace2D::get_auto_triangles() const {
@@ -625,6 +643,7 @@ void AnimationNodeBlendSpace2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_blend_mode"), &AnimationNodeBlendSpace2D::get_blend_mode);
ClassDB::bind_method(D_METHOD("_tree_changed"), &AnimationNodeBlendSpace2D::_tree_changed);
+ ClassDB::bind_method(D_METHOD("_update_triangles"), &AnimationNodeBlendSpace2D::_update_triangles);
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "auto_triangles", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_auto_triangles", "get_auto_triangles");
@@ -642,6 +661,7 @@ void AnimationNodeBlendSpace2D::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::STRING, "y_label", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_y_label", "get_y_label");
ADD_PROPERTY(PropertyInfo(Variant::INT, "blend_mode", PROPERTY_HINT_ENUM, "Interpolated,Discrete,Carry", PROPERTY_USAGE_NOEDITOR), "set_blend_mode", "get_blend_mode");
+ ADD_SIGNAL(MethodInfo("triangles_updated"));
BIND_ENUM_CONSTANT(BLEND_MODE_INTERPOLATED);
BIND_ENUM_CONSTANT(BLEND_MODE_DISCRETE);
BIND_ENUM_CONSTANT(BLEND_MODE_DISCRETE_CARRY);
diff --git a/scene/animation/animation_blend_space_2d.h b/scene/animation/animation_blend_space_2d.h
index 53885d4ad2..c21360beb9 100644
--- a/scene/animation/animation_blend_space_2d.h
+++ b/scene/animation/animation_blend_space_2d.h
@@ -82,6 +82,7 @@ protected:
bool trianges_dirty;
void _update_triangles();
+ void _queue_auto_triangles();
void _tree_changed();