diff options
Diffstat (limited to 'scene/animation')
-rw-r--r-- | scene/animation/animation_node_state_machine.cpp | 3 | ||||
-rw-r--r-- | scene/animation/animation_node_state_machine.h | 1 | ||||
-rw-r--r-- | scene/animation/animation_player.cpp | 5 | ||||
-rw-r--r-- | scene/animation/animation_tree.cpp | 48 | ||||
-rw-r--r-- | scene/animation/root_motion_view.cpp | 127 |
5 files changed, 98 insertions, 86 deletions
diff --git a/scene/animation/animation_node_state_machine.cpp b/scene/animation/animation_node_state_machine.cpp index a68f7e037d..5ea7f4b7d9 100644 --- a/scene/animation/animation_node_state_machine.cpp +++ b/scene/animation/animation_node_state_machine.cpp @@ -807,9 +807,6 @@ String AnimationNodeStateMachine::get_caption() const { return "StateMachine"; } -void AnimationNodeStateMachine::_notification(int p_what) { -} - Ref<AnimationNode> AnimationNodeStateMachine::get_child_by_name(const StringName &p_name) { return get_node(p_name); } diff --git a/scene/animation/animation_node_state_machine.h b/scene/animation/animation_node_state_machine.h index b980556875..3bae0fcffa 100644 --- a/scene/animation/animation_node_state_machine.h +++ b/scene/animation/animation_node_state_machine.h @@ -164,7 +164,6 @@ private: void _tree_changed(); protected: - void _notification(int p_what); static void _bind_methods(); bool _set(const StringName &p_name, const Variant &p_value); diff --git a/scene/animation/animation_player.cpp b/scene/animation/animation_player.cpp index 4a3fd72080..7ad76e43a2 100644 --- a/scene/animation/animation_player.cpp +++ b/scene/animation/animation_player.cpp @@ -202,15 +202,16 @@ void AnimationPlayer::_notification(int p_what) { set_physics_process_internal(false); set_process_internal(false); } - //_set_process(false); clear_caches(); } break; + case NOTIFICATION_READY: { if (!Engine::get_singleton()->is_editor_hint() && animation_set.has(autoplay)) { play(autoplay); _animation_process(0); } } break; + case NOTIFICATION_INTERNAL_PROCESS: { if (process_callback == ANIMATION_PROCESS_PHYSICS) { break; @@ -220,6 +221,7 @@ void AnimationPlayer::_notification(int p_what) { _animation_process(get_process_delta_time()); } } break; + case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: { if (process_callback == ANIMATION_PROCESS_IDLE) { break; @@ -229,6 +231,7 @@ void AnimationPlayer::_notification(int p_what) { _animation_process(get_physics_process_delta_time()); } } break; + case NOTIFICATION_EXIT_TREE: { clear_caches(); } break; diff --git a/scene/animation/animation_tree.cpp b/scene/animation/animation_tree.cpp index f2f69fc439..a50618182d 100644 --- a/scene/animation/animation_tree.cpp +++ b/scene/animation/animation_tree.cpp @@ -1586,29 +1586,37 @@ void AnimationTree::advance(real_t p_time) { } void AnimationTree::_notification(int p_what) { - if (active && p_what == NOTIFICATION_INTERNAL_PHYSICS_PROCESS && process_callback == ANIMATION_PROCESS_PHYSICS) { - _process_graph(get_physics_process_delta_time()); - } - - if (active && p_what == NOTIFICATION_INTERNAL_PROCESS && process_callback == ANIMATION_PROCESS_IDLE) { - _process_graph(get_process_delta_time()); - } + switch (p_what) { + case NOTIFICATION_ENTER_TREE: { + if (last_animation_player.is_valid()) { + Object *player = ObjectDB::get_instance(last_animation_player); + if (player) { + player->connect("caches_cleared", callable_mp(this, &AnimationTree::_clear_caches)); + } + } + } break; + + case NOTIFICATION_EXIT_TREE: { + _clear_caches(); + if (last_animation_player.is_valid()) { + Object *player = ObjectDB::get_instance(last_animation_player); + if (player) { + player->disconnect("caches_cleared", callable_mp(this, &AnimationTree::_clear_caches)); + } + } + } break; - if (p_what == NOTIFICATION_EXIT_TREE) { - _clear_caches(); - if (last_animation_player.is_valid()) { - Object *player = ObjectDB::get_instance(last_animation_player); - if (player) { - player->disconnect("caches_cleared", callable_mp(this, &AnimationTree::_clear_caches)); + case NOTIFICATION_INTERNAL_PROCESS: { + if (active && process_callback == ANIMATION_PROCESS_IDLE) { + _process_graph(get_process_delta_time()); } - } - } else if (p_what == NOTIFICATION_ENTER_TREE) { - if (last_animation_player.is_valid()) { - Object *player = ObjectDB::get_instance(last_animation_player); - if (player) { - player->connect("caches_cleared", callable_mp(this, &AnimationTree::_clear_caches)); + } break; + + case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: { + if (active && process_callback == ANIMATION_PROCESS_PHYSICS) { + _process_graph(get_physics_process_delta_time()); } - } + } break; } } diff --git a/scene/animation/root_motion_view.cpp b/scene/animation/root_motion_view.cpp index 0d44687588..46fe832cf5 100644 --- a/scene/animation/root_motion_view.cpp +++ b/scene/animation/root_motion_view.cpp @@ -29,8 +29,10 @@ /*************************************************************************/ #include "root_motion_view.h" + #include "scene/animation/animation_tree.h" #include "scene/resources/material.h" + void RootMotionView::set_animation_path(const NodePath &p_path) { path = p_path; first = true; @@ -76,84 +78,87 @@ bool RootMotionView::get_zero_y() const { } void RootMotionView::_notification(int p_what) { - if (p_what == NOTIFICATION_ENTER_TREE) { - immediate_material = StandardMaterial3D::get_material_for_2d(false, true, false, false, false); - first = true; - } - - if (p_what == NOTIFICATION_INTERNAL_PROCESS || p_what == NOTIFICATION_INTERNAL_PHYSICS_PROCESS) { - Transform3D transform; - - if (has_node(path)) { - Node *node = get_node(path); - - AnimationTree *tree = Object::cast_to<AnimationTree>(node); - if (tree && tree->is_active() && tree->get_root_motion_track() != NodePath()) { - if (is_processing_internal() && tree->get_process_callback() == AnimationTree::ANIMATION_PROCESS_PHYSICS) { - set_process_internal(false); - set_physics_process_internal(true); + switch (p_what) { + case NOTIFICATION_ENTER_TREE: { + immediate_material = StandardMaterial3D::get_material_for_2d(false, true, false, false, false); + first = true; + } break; + + case NOTIFICATION_INTERNAL_PROCESS: + case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: { + Transform3D transform; + + if (has_node(path)) { + Node *node = get_node(path); + + AnimationTree *tree = Object::cast_to<AnimationTree>(node); + if (tree && tree->is_active() && tree->get_root_motion_track() != NodePath()) { + if (is_processing_internal() && tree->get_process_callback() == AnimationTree::ANIMATION_PROCESS_PHYSICS) { + set_process_internal(false); + set_physics_process_internal(true); + } + + if (is_physics_processing_internal() && tree->get_process_callback() == AnimationTree::ANIMATION_PROCESS_IDLE) { + set_process_internal(true); + set_physics_process_internal(false); + } + + transform = tree->get_root_motion_transform(); } - - if (is_physics_processing_internal() && tree->get_process_callback() == AnimationTree::ANIMATION_PROCESS_IDLE) { - set_process_internal(true); - set_physics_process_internal(false); - } - - transform = tree->get_root_motion_transform(); } - } - if (!first && transform == Transform3D()) { - return; - } + if (!first && transform == Transform3D()) { + return; + } - first = false; + first = false; - transform.orthonormalize(); //don't want scale, too imprecise - transform.affine_invert(); + transform.orthonormalize(); //don't want scale, too imprecise + transform.affine_invert(); - accumulated = transform * accumulated; - accumulated.origin.x = Math::fposmod(accumulated.origin.x, cell_size); - if (zero_y) { - accumulated.origin.y = 0; - } - accumulated.origin.z = Math::fposmod(accumulated.origin.z, cell_size); + accumulated = transform * accumulated; + accumulated.origin.x = Math::fposmod(accumulated.origin.x, cell_size); + if (zero_y) { + accumulated.origin.y = 0; + } + accumulated.origin.z = Math::fposmod(accumulated.origin.z, cell_size); - immediate->clear_surfaces(); + immediate->clear_surfaces(); - int cells_in_radius = int((radius / cell_size) + 1.0); + int cells_in_radius = int((radius / cell_size) + 1.0); - immediate->surface_begin(Mesh::PRIMITIVE_LINES, immediate_material); + immediate->surface_begin(Mesh::PRIMITIVE_LINES, immediate_material); - for (int i = -cells_in_radius; i < cells_in_radius; i++) { - for (int j = -cells_in_radius; j < cells_in_radius; j++) { - Vector3 from(i * cell_size, 0, j * cell_size); - Vector3 from_i((i + 1) * cell_size, 0, j * cell_size); - Vector3 from_j(i * cell_size, 0, (j + 1) * cell_size); - from = accumulated.xform(from); - from_i = accumulated.xform(from_i); - from_j = accumulated.xform(from_j); + for (int i = -cells_in_radius; i < cells_in_radius; i++) { + for (int j = -cells_in_radius; j < cells_in_radius; j++) { + Vector3 from(i * cell_size, 0, j * cell_size); + Vector3 from_i((i + 1) * cell_size, 0, j * cell_size); + Vector3 from_j(i * cell_size, 0, (j + 1) * cell_size); + from = accumulated.xform(from); + from_i = accumulated.xform(from_i); + from_j = accumulated.xform(from_j); - Color c = color, c_i = color, c_j = color; - c.a *= MAX(0, 1.0 - from.length() / radius); - c_i.a *= MAX(0, 1.0 - from_i.length() / radius); - c_j.a *= MAX(0, 1.0 - from_j.length() / radius); + Color c = color, c_i = color, c_j = color; + c.a *= MAX(0, 1.0 - from.length() / radius); + c_i.a *= MAX(0, 1.0 - from_i.length() / radius); + c_j.a *= MAX(0, 1.0 - from_j.length() / radius); - immediate->surface_set_color(c); - immediate->surface_add_vertex(from); + immediate->surface_set_color(c); + immediate->surface_add_vertex(from); - immediate->surface_set_color(c_i); - immediate->surface_add_vertex(from_i); + immediate->surface_set_color(c_i); + immediate->surface_add_vertex(from_i); - immediate->surface_set_color(c); - immediate->surface_add_vertex(from); + immediate->surface_set_color(c); + immediate->surface_add_vertex(from); - immediate->surface_set_color(c_j); - immediate->surface_add_vertex(from_j); + immediate->surface_set_color(c_j); + immediate->surface_add_vertex(from_j); + } } - } - immediate->surface_end(); + immediate->surface_end(); + } break; } } |