From 0c6617887e9e80f1f1fe1daf8cb4c8027e69be76 Mon Sep 17 00:00:00 2001 From: lawnjelly Date: Sat, 5 Jun 2021 19:14:36 +0100 Subject: [PATCH] Fix VisibilityEnabler to work with AnimationTree Although the visibility enabler worked to turn on and off AnimationPlayer as it enters and exits the view frustum, this was of little use as bones animation and especially software skinning still take place driven by the AnimationTree node. This PR adds the ability to turn on and off AnimationTree, and AnimationTreePlayer nodes as they enter or exit the view frustum, which achieves the intention of switching off expensive animation processing. --- scene/3d/visibility_notifier.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/scene/3d/visibility_notifier.cpp b/scene/3d/visibility_notifier.cpp index dffb31387b3..6317e655f66 100644 --- a/scene/3d/visibility_notifier.cpp +++ b/scene/3d/visibility_notifier.cpp @@ -34,6 +34,8 @@ #include "scene/3d/camera.h" #include "scene/3d/physics_body.h" #include "scene/animation/animation_player.h" +#include "scene/animation/animation_tree.h" +#include "scene/animation/animation_tree_player.h" #include "scene/scene_string_names.h" void VisibilityNotifier::_enter_camera(Camera *p_camera) { @@ -146,11 +148,8 @@ void VisibilityEnabler::_find_nodes(Node *p_node) { } } - { - AnimationPlayer *ap = Object::cast_to(p_node); - if (ap) { - add = true; - } + if (Object::cast_to(p_node) || Object::cast_to(p_node) || Object::cast_to(p_node)) { + add = true; } if (add) { @@ -212,9 +211,18 @@ void VisibilityEnabler::_change_node_state(Node *p_node, bool p_enabled) { if (enabler[ENABLER_PAUSE_ANIMATIONS]) { AnimationPlayer *ap = Object::cast_to(p_node); - if (ap) { ap->set_active(p_enabled); + } else { + AnimationTree *at = Object::cast_to(p_node); + if (at) { + at->set_active(p_enabled); + } else { + AnimationTreePlayer *atp = Object::cast_to(p_node); + if (atp) { + atp->set_active(p_enabled); + } + } } } }