Make blend animation to use ResetTrack as default value
This commit is contained in:
parent
bf153b82c7
commit
860fac4e6f
6 changed files with 172 additions and 6 deletions
|
|
@ -540,6 +540,11 @@ bool AnimationTree::_update_caches(AnimationPlayer *player) {
|
|||
List<StringName> sname;
|
||||
player->get_animation_list(&sname);
|
||||
|
||||
Ref<Animation> reset_anim;
|
||||
bool has_reset_anim = player->has_animation("RESET");
|
||||
if (has_reset_anim) {
|
||||
reset_anim = player->get_animation("RESET");
|
||||
}
|
||||
for (const StringName &E : sname) {
|
||||
Ref<Animation> anim = player->get_animation(E);
|
||||
for (int i = 0; i < anim->get_track_count(); i++) {
|
||||
|
|
@ -593,6 +598,12 @@ bool AnimationTree::_update_caches(AnimationPlayer *player) {
|
|||
|
||||
track = track_value;
|
||||
|
||||
if (has_reset_anim) {
|
||||
int rt = reset_anim->find_track(path, track_type);
|
||||
if (rt >= 0 && reset_anim->track_get_key_count(rt) > 0) {
|
||||
track_value->init_value = reset_anim->track_get_key_value(rt, 0);
|
||||
}
|
||||
}
|
||||
} break;
|
||||
case Animation::TYPE_POSITION_3D:
|
||||
case Animation::TYPE_ROTATION_3D:
|
||||
|
|
@ -645,6 +656,25 @@ bool AnimationTree::_update_caches(AnimationPlayer *player) {
|
|||
}
|
||||
}
|
||||
|
||||
if (has_reset_anim) {
|
||||
int rt = reset_anim->find_track(path, track_type);
|
||||
if (rt >= 0 && reset_anim->track_get_key_count(rt) > 0) {
|
||||
switch (track_type) {
|
||||
case Animation::TYPE_POSITION_3D: {
|
||||
track_xform->init_loc = reset_anim->track_get_key_value(rt, 0);
|
||||
} break;
|
||||
case Animation::TYPE_ROTATION_3D: {
|
||||
track_xform->ref_rot = reset_anim->track_get_key_value(rt, 0);
|
||||
track_xform->init_rot = track_xform->ref_rot.log();
|
||||
} break;
|
||||
case Animation::TYPE_SCALE_3D: {
|
||||
track_xform->init_scale = reset_anim->track_get_key_value(rt, 0);
|
||||
} break;
|
||||
default: {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // _3D_DISABLED
|
||||
} break;
|
||||
case Animation::TYPE_BLEND_SHAPE: {
|
||||
|
|
@ -675,6 +705,13 @@ bool AnimationTree::_update_caches(AnimationPlayer *player) {
|
|||
track_bshape->object = mesh_3d;
|
||||
track_bshape->object_id = mesh_3d->get_instance_id();
|
||||
track = track_bshape;
|
||||
|
||||
if (has_reset_anim) {
|
||||
int rt = reset_anim->find_track(path, track_type);
|
||||
if (rt >= 0 && reset_anim->track_get_key_count(rt) > 0) {
|
||||
track_bshape->init_value = reset_anim->track_get_key_value(rt, 0);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
} break;
|
||||
case Animation::TYPE_METHOD: {
|
||||
|
|
@ -704,6 +741,13 @@ bool AnimationTree::_update_caches(AnimationPlayer *player) {
|
|||
track_bezier->object_id = track_bezier->object->get_instance_id();
|
||||
|
||||
track = track_bezier;
|
||||
|
||||
if (has_reset_anim) {
|
||||
int rt = reset_anim->find_track(path, track_type);
|
||||
if (rt >= 0 && reset_anim->track_get_key_count(rt) > 0) {
|
||||
track_bezier->init_value = reset_anim->track_get_key_value(rt, 0);
|
||||
}
|
||||
}
|
||||
} break;
|
||||
case Animation::TYPE_AUDIO: {
|
||||
TrackCacheAudio *track_audio = memnew(TrackCacheAudio);
|
||||
|
|
@ -1226,7 +1270,7 @@ void AnimationTree::_process_graph(double p_delta) {
|
|||
|
||||
if (t->process_pass != process_pass) {
|
||||
t->process_pass = process_pass;
|
||||
t->value = 0;
|
||||
t->value = t->init_value;
|
||||
}
|
||||
|
||||
float value;
|
||||
|
|
@ -1238,7 +1282,7 @@ void AnimationTree::_process_graph(double p_delta) {
|
|||
continue;
|
||||
}
|
||||
|
||||
t->value += value * blend;
|
||||
t->value += (value - t->init_value) * blend;
|
||||
#endif // _3D_DISABLED
|
||||
} break;
|
||||
case Animation::TYPE_VALUE: {
|
||||
|
|
@ -1256,10 +1300,15 @@ void AnimationTree::_process_graph(double p_delta) {
|
|||
|
||||
if (t->process_pass != process_pass) {
|
||||
t->process_pass = process_pass;
|
||||
t->value = value;
|
||||
t->value.zero();
|
||||
if (!t->init_value) {
|
||||
t->init_value = value;
|
||||
t->init_value.zero();
|
||||
} else {
|
||||
t->value = t->init_value;
|
||||
}
|
||||
}
|
||||
|
||||
Variant::sub(value, t->init_value, value);
|
||||
Variant::blend(t->value, value, blend, t->value);
|
||||
} else {
|
||||
if (blend < CMP_EPSILON) {
|
||||
|
|
@ -1303,10 +1352,10 @@ void AnimationTree::_process_graph(double p_delta) {
|
|||
|
||||
if (t->process_pass != process_pass) {
|
||||
t->process_pass = process_pass;
|
||||
t->value = 0;
|
||||
t->value = t->init_value;
|
||||
}
|
||||
|
||||
t->value += bezier * blend;
|
||||
t->value += (bezier - t->init_value) * blend;
|
||||
} break;
|
||||
case Animation::TYPE_AUDIO: {
|
||||
if (blend < CMP_EPSILON) {
|
||||
|
|
|
|||
|
|
@ -212,12 +212,14 @@ private:
|
|||
|
||||
struct TrackCacheBlendShape : public TrackCache {
|
||||
MeshInstance3D *mesh_3d = nullptr;
|
||||
float init_value = 0;
|
||||
float value = 0;
|
||||
int shape_index = -1;
|
||||
TrackCacheBlendShape() { type = Animation::TYPE_BLEND_SHAPE; }
|
||||
};
|
||||
|
||||
struct TrackCacheValue : public TrackCache {
|
||||
Variant init_value;
|
||||
Variant value;
|
||||
Vector<StringName> subpath;
|
||||
TrackCacheValue() { type = Animation::TYPE_VALUE; }
|
||||
|
|
@ -228,6 +230,7 @@ private:
|
|||
};
|
||||
|
||||
struct TrackCacheBezier : public TrackCache {
|
||||
real_t init_value = 0.0;
|
||||
real_t value = 0.0;
|
||||
Vector<StringName> subpath;
|
||||
TrackCacheBezier() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue