diff options
Diffstat (limited to 'scene/animation/animation_tree.cpp')
| -rw-r--r-- | scene/animation/animation_tree.cpp | 79 | 
1 files changed, 46 insertions, 33 deletions
diff --git a/scene/animation/animation_tree.cpp b/scene/animation/animation_tree.cpp index c32001dbcd..d1d3582c9d 100644 --- a/scene/animation/animation_tree.cpp +++ b/scene/animation/animation_tree.cpp @@ -883,16 +883,16 @@ void AnimationTree::_process_graph(float p_delta) {  						TrackCacheTransform *t = static_cast<TrackCacheTransform *>(track); -						if (t->process_pass != process_pass) { +						if (track->root_motion) { -							t->process_pass = process_pass; -							t->loc = Vector3(); -							t->rot = Quat(); -							t->rot_blend_accum = 0; -							t->scale = Vector3(); -						} +							if (t->process_pass != process_pass) { -						if (track->root_motion) { +								t->process_pass = process_pass; +								t->loc = Vector3(); +								t->rot = Quat(); +								t->rot_blend_accum = 0; +								t->scale = Vector3(1, 1, 1); +							}  							float prev_time = time - delta;  							if (prev_time < 0) { @@ -946,7 +946,14 @@ void AnimationTree::_process_graph(float p_delta) {  							Error err = a->transform_track_interpolate(i, time, &loc, &rot, &scale);  							//ERR_CONTINUE(err!=OK); //used for testing, should be removed -							scale -= Vector3(1.0, 1.0, 1.0); //helps make it work properly with Add nodes +							if (t->process_pass != process_pass) { + +								t->process_pass = process_pass; +								t->loc = loc; +								t->rot = rot; +								t->rot_blend_accum = 0; +								t->scale = scale; +							}  							if (err != OK)  								continue; @@ -978,8 +985,7 @@ void AnimationTree::_process_graph(float p_delta) {  								continue;  							if (t->process_pass != process_pass) { -								Variant::CallError ce; -								t->value = Variant::construct(value.get_type(), NULL, 0, ce); //reset +								t->value = value;  								t->process_pass = process_pass;  							} @@ -1009,10 +1015,10 @@ void AnimationTree::_process_graph(float p_delta) {  						a->method_track_get_key_indices(i, time, delta, &indices); -						for (List<int>::Element *E = indices.front(); E; E = E->next()) { +						for (List<int>::Element *F = indices.front(); F; F = F->next()) { -							StringName method = a->method_track_get_name(i, E->get()); -							Vector<Variant> params = a->method_track_get_params(i, E->get()); +							StringName method = a->method_track_get_name(i, F->get()); +							Vector<Variant> params = a->method_track_get_params(i, F->get());  							int s = params.size(); @@ -1036,7 +1042,7 @@ void AnimationTree::_process_graph(float p_delta) {  						float bezier = a->bezier_track_interpolate(i, time);  						if (t->process_pass != process_pass) { -							t->value = 0; +							t->value = bezier;  							t->process_pass = process_pass;  						} @@ -1151,9 +1157,9 @@ void AnimationTree::_process_graph(float p_delta) {  						TrackCacheAnimation *t = static_cast<TrackCacheAnimation *>(track); -						AnimationPlayer *player = Object::cast_to<AnimationPlayer>(t->object); +						AnimationPlayer *player2 = Object::cast_to<AnimationPlayer>(t->object); -						if (!player) +						if (!player2)  							continue;  						if (delta == 0 || seeked) { @@ -1165,10 +1171,10 @@ void AnimationTree::_process_graph(float p_delta) {  							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]" || !player->has_animation(anim_name)) +							if (String(anim_name) == "[stop]" || !player2->has_animation(anim_name))  								continue; -							Ref<Animation> anim = player->get_animation(anim_name); +							Ref<Animation> anim = player2->get_animation(anim_name);  							float at_anim_pos; @@ -1178,14 +1184,14 @@ void AnimationTree::_process_graph(float p_delta) {  								at_anim_pos = MAX(anim->get_length(), time - pos); //seek to end  							} -							if (player->is_playing() || seeked) { -								player->play(anim_name); -								player->seek(at_anim_pos); +							if (player2->is_playing() || seeked) { +								player2->play(anim_name); +								player2->seek(at_anim_pos);  								t->playing = true;  								playing_caches.insert(t);  							} else { -								player->set_assigned_animation(anim_name); -								player->seek(at_anim_pos, true); +								player2->set_assigned_animation(anim_name); +								player2->seek(at_anim_pos, true);  							}  						} else {  							//find stuff to play @@ -1195,15 +1201,15 @@ void AnimationTree::_process_graph(float p_delta) {  								int idx = to_play.back()->get();  								StringName anim_name = a->animation_track_get_key_animation(i, idx); -								if (String(anim_name) == "[stop]" || !player->has_animation(anim_name)) { +								if (String(anim_name) == "[stop]" || !player2->has_animation(anim_name)) {  									if (playing_caches.has(t)) {  										playing_caches.erase(t); -										player->stop(); +										player2->stop();  										t->playing = false;  									}  								} else { -									player->play(anim_name); +									player2->play(anim_name);  									t->playing = true;  									playing_caches.insert(t);  								} @@ -1233,8 +1239,6 @@ void AnimationTree::_process_graph(float p_delta) {  					Transform xform;  					xform.origin = t->loc; -					t->scale += Vector3(1.0, 1.0, 1.0); //helps make it work properly with Add nodes and root motion -  					xform.basis.set_quat_scale(t->rot, t->scale);  					if (t->root_motion) { @@ -1268,7 +1272,8 @@ void AnimationTree::_process_graph(float p_delta) {  					t->object->set_indexed(t->subpath, t->value);  				} break; -				default: {} //the rest don't matter +				default: { +				} //the rest don't matter  			}  		}  	} @@ -1293,9 +1298,17 @@ void AnimationTree::_notification(int p_what) {  		_clear_caches();  		if (last_animation_player) { -			Object *old_player = ObjectDB::get_instance(last_animation_player); -			if (old_player) { -				old_player->disconnect("caches_cleared", this, "_clear_caches"); +			Object *player = ObjectDB::get_instance(last_animation_player); +			if (player) { +				player->disconnect("caches_cleared", this, "_clear_caches"); +			} +		} +	} else if (p_what == NOTIFICATION_ENTER_TREE) { +		if (last_animation_player) { + +			Object *player = ObjectDB::get_instance(last_animation_player); +			if (player) { +				player->connect("caches_cleared", this, "_clear_caches");  			}  		}  	}  |