diff options
Diffstat (limited to 'scene/animation/animation_tree.cpp')
-rw-r--r-- | scene/animation/animation_tree.cpp | 118 |
1 files changed, 30 insertions, 88 deletions
diff --git a/scene/animation/animation_tree.cpp b/scene/animation/animation_tree.cpp index 56e224819f..466536db10 100644 --- a/scene/animation/animation_tree.cpp +++ b/scene/animation/animation_tree.cpp @@ -73,7 +73,6 @@ Variant AnimationNode::get_parameter(const StringName &p_name) const { } void AnimationNode::get_child_nodes(List<ChildNode> *r_child_nodes) { - if (get_script_instance()) { Dictionary cn = get_script_instance()->call("get_child_nodes"); List<Variant> keys; @@ -88,14 +87,12 @@ void AnimationNode::get_child_nodes(List<ChildNode> *r_child_nodes) { } void AnimationNode::blend_animation(const StringName &p_animation, float p_time, float p_delta, bool p_seeked, float p_blend) { - ERR_FAIL_COND(!state); ERR_FAIL_COND(!state->player->has_animation(p_animation)); Ref<Animation> animation = state->player->get_animation(p_animation); if (animation.is_null()) { - AnimationNodeBlendTree *btree = Object::cast_to<AnimationNodeBlendTree>(parent); if (btree) { String name = btree->get_node_name(Ref<AnimationNodeAnimation>(this)); @@ -120,7 +117,6 @@ void AnimationNode::blend_animation(const StringName &p_animation, float p_time, } float AnimationNode::_pre_process(const StringName &p_base_path, AnimationNode *p_parent, State *p_state, float p_time, bool p_seek, const Vector<StringName> &p_connections) { - base_path = p_base_path; parent = p_parent; connections = p_connections; @@ -176,12 +172,10 @@ float AnimationNode::blend_input(int p_input, float p_time, bool p_seek, float p } float AnimationNode::blend_node(const StringName &p_sub_path, Ref<AnimationNode> p_node, float p_time, bool p_seek, float p_blend, FilterAction p_filter, bool p_optimize) { - return _blend_node(p_sub_path, Vector<StringName>(), this, p_node, p_time, p_seek, p_blend, p_filter, p_optimize); } float AnimationNode::_blend_node(const StringName &p_subpath, const Vector<StringName> &p_connections, AnimationNode *p_new_parent, Ref<AnimationNode> p_node, float p_time, bool p_seek, float p_blend, FilterAction p_filter, bool p_optimize, float *r_max) { - ERR_FAIL_COND_V(!p_node.is_valid(), 0); ERR_FAIL_COND_V(!state, 0); @@ -197,7 +191,6 @@ float AnimationNode::_blend_node(const StringName &p_subpath, const Vector<Strin bool any_valid = false; if (has_filter() && is_filter_enabled() && p_filter != FILTER_IGNORE) { - for (int i = 0; i < blend_count; i++) { blendw[i] = 0.0; //all to zero by default } @@ -217,8 +210,9 @@ float AnimationNode::_blend_node(const StringName &p_subpath, const Vector<Strin case FILTER_PASS: { //values filtered pass, the rest don't for (int i = 0; i < blend_count; i++) { - if (blendw[i] == 0) //not filtered, does not pass + if (blendw[i] == 0) { //not filtered, does not pass continue; + } blendw[i] = blendr[i] * p_blend; if (blendw[i] > CMP_EPSILON) { @@ -228,12 +222,12 @@ float AnimationNode::_blend_node(const StringName &p_subpath, const Vector<Strin } break; case FILTER_STOP: { - //values filtered don't pass, the rest are blended for (int i = 0; i < blend_count; i++) { - if (blendw[i] > 0) //filtered, does not pass + if (blendw[i] > 0) { //filtered, does not pass continue; + } blendw[i] = blendr[i] * p_blend; if (blendw[i] > CMP_EPSILON) { @@ -243,7 +237,6 @@ float AnimationNode::_blend_node(const StringName &p_subpath, const Vector<Strin } break; case FILTER_BLEND: { - //filtered values are blended, the rest are passed without blending for (int i = 0; i < blend_count; i++) { @@ -262,7 +255,6 @@ float AnimationNode::_blend_node(const StringName &p_subpath, const Vector<Strin } } else { for (int i = 0; i < blend_count; i++) { - //regular blend blendw[i] = blendr[i] * p_blend; if (blendw[i] > CMP_EPSILON) { @@ -278,8 +270,9 @@ float AnimationNode::_blend_node(const StringName &p_subpath, const Vector<Strin } } - if (!p_seek && p_optimize && !any_valid) //pointless to go on, all are zero + if (!p_seek && p_optimize && !any_valid) { //pointless to go on, all are zero return 0; + } String new_path; AnimationNode *new_parent; @@ -297,16 +290,15 @@ float AnimationNode::_blend_node(const StringName &p_subpath, const Vector<Strin } int AnimationNode::get_input_count() const { - return inputs.size(); } + String AnimationNode::get_input_name(int p_input) { ERR_FAIL_INDEX_V(p_input, inputs.size(), String()); return inputs[p_input].name; } String AnimationNode::get_caption() const { - if (get_script_instance()) { return get_script_instance()->call("get_caption"); } @@ -338,7 +330,6 @@ void AnimationNode::remove_input(int p_index) { } float AnimationNode::process(float p_time, bool p_seek) { - if (get_script_instance()) { return get_script_instance()->call("process", p_time, p_seek); } @@ -371,7 +362,6 @@ bool AnimationNode::has_filter() const { } Array AnimationNode::_get_filters() const { - Array paths; const NodePath *K = nullptr; @@ -382,6 +372,7 @@ Array AnimationNode::_get_filters() const { return paths; } + void AnimationNode::_set_filters(const Array &p_filters) { filter.clear(); for (int i = 0; i < p_filters.size(); i++) { @@ -403,7 +394,6 @@ Ref<AnimationNode> AnimationNode::get_child_by_name(const StringName &p_name) { } void AnimationNode::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_input_count"), &AnimationNode::get_input_count); ClassDB::bind_method(D_METHOD("get_input_name", "input"), &AnimationNode::get_input_name); @@ -452,7 +442,6 @@ void AnimationNode::_bind_methods() { } AnimationNode::AnimationNode() { - state = nullptr; parent = nullptr; filter_enabled = false; @@ -461,7 +450,6 @@ AnimationNode::AnimationNode() { //////////////////// void AnimationTree::set_tree_root(const Ref<AnimationNode> &p_root) { - if (root.is_valid()) { root->disconnect("tree_changed", callable_mp(this, &AnimationTree::_tree_changed)); } @@ -482,9 +470,9 @@ Ref<AnimationNode> AnimationTree::get_tree_root() const { } void AnimationTree::set_active(bool p_active) { - - if (active == p_active) + if (active == p_active) { return; + } active = p_active; started = active; @@ -492,13 +480,11 @@ void AnimationTree::set_active(bool p_active) { if (process_mode == ANIMATION_PROCESS_IDLE) { set_process_internal(active); } else { - set_physics_process_internal(active); } if (!active && is_inside_tree()) { for (Set<TrackCache *>::Element *E = playing_caches.front(); E; E = E->next()) { - if (ObjectDB::get_instance(E->get()->object_id)) { E->get()->object->call("stop"); } @@ -509,14 +495,13 @@ void AnimationTree::set_active(bool p_active) { } bool AnimationTree::is_active() const { - return active; } void AnimationTree::set_process_mode(AnimationProcessMode p_mode) { - - if (process_mode == p_mode) + if (process_mode == p_mode) { return; + } bool was_active = is_active(); if (was_active) { @@ -539,7 +524,6 @@ void AnimationTree::_node_removed(Node *p_node) { } bool AnimationTree::_update_caches(AnimationPlayer *player) { - setup_pass++; if (!player->has_node(player->get_root())) { @@ -572,7 +556,6 @@ bool AnimationTree::_update_caches(AnimationPlayer *player) { } if (!track) { - RES resource; Vector<StringName> leftover_path; Node *child = parent->get_node_and_resource(path, resource, leftover_path); @@ -588,7 +571,6 @@ bool AnimationTree::_update_caches(AnimationPlayer *player) { switch (track_type) { case Animation::TYPE_VALUE: { - TrackCacheValue *track_value = memnew(TrackCacheValue); if (resource.is_valid()) { @@ -604,7 +586,6 @@ bool AnimationTree::_update_caches(AnimationPlayer *player) { } break; case Animation::TYPE_TRANSFORM: { - Node3D *spatial = Object::cast_to<Node3D>(child); if (!spatial) { @@ -619,11 +600,9 @@ bool AnimationTree::_update_caches(AnimationPlayer *player) { track_xform->bone_idx = -1; if (path.get_subname_count() == 1 && Object::cast_to<Skeleton3D>(spatial)) { - Skeleton3D *sk = Object::cast_to<Skeleton3D>(spatial); int bone_idx = sk->find_bone(path.get_subname(0)); if (bone_idx != -1) { - track_xform->skeleton = sk; track_xform->bone_idx = bone_idx; } @@ -636,7 +615,6 @@ bool AnimationTree::_update_caches(AnimationPlayer *player) { } break; case Animation::TYPE_METHOD: { - TrackCacheMethod *track_method = memnew(TrackCacheMethod); if (resource.is_valid()) { @@ -651,7 +629,6 @@ bool AnimationTree::_update_caches(AnimationPlayer *player) { } break; case Animation::TYPE_BEZIER: { - TrackCacheBezier *track_bezier = memnew(TrackCacheBezier); if (resource.is_valid()) { @@ -666,7 +643,6 @@ bool AnimationTree::_update_caches(AnimationPlayer *player) { track = track_bezier; } break; case Animation::TYPE_AUDIO: { - TrackCacheAudio *track_audio = memnew(TrackCacheAudio); track_audio->object = child; @@ -676,7 +652,6 @@ bool AnimationTree::_update_caches(AnimationPlayer *player) { } break; case Animation::TYPE_ANIMATION: { - TrackCacheAnimation *track_animation = memnew(TrackCacheAnimation); track_animation->object = child; @@ -732,7 +707,6 @@ bool AnimationTree::_update_caches(AnimationPlayer *player) { } void AnimationTree::_clear_caches() { - const NodePath *K = nullptr; while ((K = track_cache.next(K))) { memdelete(track_cache[*K]); @@ -744,7 +718,6 @@ void AnimationTree::_clear_caches() { } void AnimationTree::_process_graph(float p_delta) { - _update_properties(); //if properties need updating, update them //check all tracks, see if they need modification @@ -774,7 +747,6 @@ void AnimationTree::_process_graph(float p_delta) { } if (last_animation_player != current_animation_player) { - if (last_animation_player.is_valid()) { Object *old_player = ObjectDB::get_instance(last_animation_player); if (old_player) { @@ -826,7 +798,6 @@ void AnimationTree::_process_graph(float p_delta) { //process { - if (started) { //if started, seek root->_pre_process(SceneStringNames::get_singleton()->parameters_base_path, nullptr, &state, 0, true, Vector<StringName>()); @@ -842,11 +813,9 @@ void AnimationTree::_process_graph(float p_delta) { //apply value/transform/bezier blends to track caches and execute method/audio/animation tracks { - bool can_call = is_inside_tree() && !Engine::get_singleton()->is_editor_hint(); for (List<AnimationNode::AnimationState>::Element *E = state.animation_states.front(); E; E = E->next()) { - const AnimationNode::AnimationState &as = E->get(); Ref<Animation> a = as.animation; @@ -855,7 +824,6 @@ void AnimationTree::_process_graph(float p_delta) { bool seeked = as.seeked; for (int i = 0; i < a->get_track_count(); i++) { - NodePath path = a->track_get_path(i); ERR_CONTINUE(!track_cache.has(path)); @@ -874,19 +842,16 @@ void AnimationTree::_process_graph(float p_delta) { float blend = (*as.track_blends)[blend_idx]; - if (blend < CMP_EPSILON) + if (blend < CMP_EPSILON) { continue; //nothing to blend + } switch (track->type) { - case Animation::TYPE_TRANSFORM: { - TrackCacheTransform *t = static_cast<TrackCacheTransform *>(track); if (track->root_motion) { - if (t->process_pass != process_pass) { - t->process_pass = process_pass; t->loc = Vector3(); t->rot = Quat(); @@ -908,7 +873,6 @@ void AnimationTree::_process_graph(float p_delta) { Vector3 scale[2]; if (prev_time > time) { - Error err = a->transform_track_interpolate(i, prev_time, &loc[0], &rot[0], &scale[0]); if (err != OK) { continue; @@ -947,7 +911,6 @@ void AnimationTree::_process_graph(float p_delta) { //ERR_CONTINUE(err!=OK); //used for testing, should be removed if (t->process_pass != process_pass) { - t->process_pass = process_pass; t->loc = loc; t->rot = rot; @@ -955,8 +918,9 @@ void AnimationTree::_process_graph(float p_delta) { t->scale = scale; } - if (err != OK) + if (err != OK) { continue; + } t->loc = t->loc.lerp(loc, blend); if (t->rot_blend_accum == 0) { @@ -972,7 +936,6 @@ void AnimationTree::_process_graph(float p_delta) { } break; case Animation::TYPE_VALUE: { - TrackCacheValue *t = static_cast<TrackCacheValue *>(track); Animation::UpdateMode update_mode = a->value_track_get_update_mode(i); @@ -981,8 +944,9 @@ void AnimationTree::_process_graph(float p_delta) { Variant value = a->value_track_interpolate(i, time); - if (value == Variant()) + if (value == Variant()) { continue; + } if (t->process_pass != process_pass) { t->value = value; @@ -992,12 +956,10 @@ void AnimationTree::_process_graph(float p_delta) { Variant::interpolate(t->value, value, blend, t->value); } else if (delta != 0) { - List<int> indices; a->value_track_get_key_indices(i, time, delta, &indices); for (List<int>::Element *F = indices.front(); F; F = F->next()) { - Variant value = a->track_get_key_value(i, F->get()); t->object->set_indexed(t->subpath, value); } @@ -1005,7 +967,6 @@ void AnimationTree::_process_graph(float p_delta) { } break; case Animation::TYPE_METHOD: { - if (delta == 0) { continue; } @@ -1016,7 +977,6 @@ void AnimationTree::_process_graph(float p_delta) { a->method_track_get_key_indices(i, time, delta, &indices); for (List<int>::Element *F = indices.front(); F; F = F->next()) { - StringName method = a->method_track_get_name(i, F->get()); Vector<Variant> params = a->method_track_get_params(i, F->get()); @@ -1036,7 +996,6 @@ void AnimationTree::_process_graph(float p_delta) { } break; case Animation::TYPE_BEZIER: { - TrackCacheBezier *t = static_cast<TrackCacheBezier *>(track); float bezier = a->bezier_track_interpolate(i, time); @@ -1050,14 +1009,14 @@ void AnimationTree::_process_graph(float p_delta) { } break; case Animation::TYPE_AUDIO: { - TrackCacheAudio *t = static_cast<TrackCacheAudio *>(track); if (seeked) { //find whathever should be playing int idx = a->track_find_key(i, time); - if (idx < 0) + if (idx < 0) { continue; + } Ref<AudioStream> stream = a->audio_track_get_key_stream(i, idx); if (!stream.is_valid()) { @@ -1122,7 +1081,6 @@ void AnimationTree::_process_graph(float p_delta) { t->start = time; } } else if (t->playing) { - bool loop = a->has_loop(); bool stop = false; @@ -1154,25 +1112,27 @@ void AnimationTree::_process_graph(float p_delta) { } } break; case Animation::TYPE_ANIMATION: { - TrackCacheAnimation *t = static_cast<TrackCacheAnimation *>(track); AnimationPlayer *player2 = Object::cast_to<AnimationPlayer>(t->object); - if (!player2) + if (!player2) { continue; + } if (delta == 0 || seeked) { //seek int idx = a->track_find_key(i, time); - if (idx < 0) + if (idx < 0) { continue; + } float pos = a->track_get_key_time(i, idx); StringName anim_name = a->animation_track_get_key_animation(i, idx); - if (String(anim_name) == "[stop]" || !player2->has_animation(anim_name)) + if (String(anim_name) == "[stop]" || !player2->has_animation(anim_name)) { continue; + } Ref<Animation> anim = player2->get_animation(anim_name); @@ -1202,7 +1162,6 @@ void AnimationTree::_process_graph(float p_delta) { StringName anim_name = a->animation_track_get_key_animation(i, idx); if (String(anim_name) == "[stop]" || !player2->has_animation(anim_name)) { - if (playing_caches.has(t)) { playing_caches.erase(t); player2->stop(); @@ -1227,13 +1186,12 @@ void AnimationTree::_process_graph(float p_delta) { const NodePath *K = nullptr; while ((K = track_cache.next(K))) { TrackCache *track = track_cache[*K]; - if (track->process_pass != process_pass) + if (track->process_pass != process_pass) { continue; //not processed, ignore + } switch (track->type) { - case Animation::TYPE_TRANSFORM: { - TrackCacheTransform *t = static_cast<TrackCacheTransform *>(track); Transform xform; @@ -1242,31 +1200,26 @@ void AnimationTree::_process_graph(float p_delta) { xform.basis.set_quat_scale(t->rot, t->scale); if (t->root_motion) { - root_motion_transform = xform; if (t->skeleton && t->bone_idx >= 0) { root_motion_transform = (t->skeleton->get_bone_rest(t->bone_idx) * root_motion_transform) * t->skeleton->get_bone_rest(t->bone_idx).affine_inverse(); } } else if (t->skeleton && t->bone_idx >= 0) { - t->skeleton->set_bone_pose(t->bone_idx, xform); } else { - t->spatial->set_transform(xform); } } break; case Animation::TYPE_VALUE: { - TrackCacheValue *t = static_cast<TrackCacheValue *>(track); t->object->set_indexed(t->subpath, t->value); } break; case Animation::TYPE_BEZIER: { - TrackCacheBezier *t = static_cast<TrackCacheBezier *>(track); t->object->set_indexed(t->subpath, t->value); @@ -1280,12 +1233,10 @@ void AnimationTree::_process_graph(float p_delta) { } void AnimationTree::advance(float p_time) { - _process_graph(p_time); } void AnimationTree::_notification(int p_what) { - if (active && p_what == NOTIFICATION_INTERNAL_PHYSICS_PROCESS && process_mode == ANIMATION_PROCESS_PHYSICS) { _process_graph(get_physics_process_delta_time()); } @@ -1297,7 +1248,6 @@ void AnimationTree::_notification(int p_what) { 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)); @@ -1305,7 +1255,6 @@ void AnimationTree::_notification(int p_what) { } } 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)); @@ -1324,11 +1273,10 @@ NodePath AnimationTree::get_animation_player() const { } bool AnimationTree::is_state_invalid() const { - return !state.valid; } -String AnimationTree::get_invalid_state_reason() const { +String AnimationTree::get_invalid_state_reason() const { return state.invalid_reasons; } @@ -1337,7 +1285,6 @@ uint64_t AnimationTree::get_last_process_pass() const { } String AnimationTree::get_configuration_warning() const { - String warning = Node::get_configuration_warning(); if (!root.is_valid()) { @@ -1348,7 +1295,6 @@ String AnimationTree::get_configuration_warning() const { } if (!has_node(animation_player)) { - if (warning != String()) { warning += "\n\n"; } @@ -1402,13 +1348,11 @@ void AnimationTree::_tree_changed() { } void AnimationTree::_update_properties_for_node(const String &p_base_path, Ref<AnimationNode> node) { - if (!property_parent_map.has(p_base_path)) { property_parent_map[p_base_path] = HashMap<StringName, StringName>(); } if (node->get_input_count() && !input_activity_map.has(p_base_path)) { - Vector<Activity> activity; for (int i = 0; i < node->get_input_count(); i++) { Activity a; @@ -1492,6 +1436,7 @@ bool AnimationTree::_get(const StringName &p_name, Variant &r_ret) const { return false; } + void AnimationTree::_get_property_list(List<PropertyInfo> *p_list) const { if (properties_dirty) { const_cast<AnimationTree *>(this)->_update_properties(); @@ -1503,7 +1448,6 @@ void AnimationTree::_get_property_list(List<PropertyInfo> *p_list) const { } void AnimationTree::rename_parameter(const String &p_base, const String &p_new_base) { - //rename values first for (const List<PropertyInfo>::Element *E = properties.front(); E; E = E->next()) { if (E->get().name.begins_with(p_base)) { @@ -1518,7 +1462,6 @@ void AnimationTree::rename_parameter(const String &p_base, const String &p_new_b } float AnimationTree::get_connection_activity(const StringName &p_path, int p_connection) const { - if (!input_activity_map_get.has(p_path)) { return 0; } @@ -1572,7 +1515,6 @@ void AnimationTree::_bind_methods() { } AnimationTree::AnimationTree() { - process_mode = ANIMATION_PROCESS_IDLE; active = false; cache_valid = false; |