implemented support for multilayered keyframes

This adds the ability to keyframe more than one value per input (e.g. a vec2,
vec3, etc.) so that you can animate, for example, an X axis separately from a
Y axis.
This commit is contained in:
itsmattkc
2019-12-30 04:47:23 +11:00
parent ae84067084
commit 245aa44efc
11 changed files with 444 additions and 251 deletions
@@ -111,24 +111,32 @@ void NodeParamViewKeyframeControl::ShowButtonsFromKeyframeEnable(bool e)
void NodeParamViewKeyframeControl::ToggleKeyframe(bool e)
{
NodeKeyframePtr key = input_->get_keyframe_at_time(time_);
QList<NodeKeyframePtr> keys = input_->get_keyframe_at_time(time_);
QUndoCommand* command = new QUndoCommand();
if (e && !key) {
// Add a keyframe here
key = NodeKeyframe::Create(time_,
input_->get_value_at_time(time_),
input_->get_best_keyframe_type_for_time(time_));
if (e && keys.isEmpty()) {
// Add a keyframe here (one for each track)
for (int i=0;i<input_->get_number_of_keyframe_tracks();i++) {
NodeKeyframePtr key = NodeKeyframe::Create(time_,
input_->get_value_at_time_for_track(time_, i),
input_->get_best_keyframe_type_for_time(time_, i),
i);
new NodeParamInsertKeyframeCommand(input_, key, command);
} else if (!e && key) {
// Remove a keyframe here
new NodeParamRemoveKeyframeCommand(input_, key, command);
new NodeParamInsertKeyframeCommand(input_, key, command);
}
} else if (!e && !keys.isEmpty()) {
// Remove all keyframes at this time
foreach (NodeKeyframePtr key, keys) {
new NodeParamRemoveKeyframeCommand(input_, key, command);
// If this was the last keyframe, we'll set the standard value to the value at this time too
if (input_->keyframes().size() == 1) {
new NodeParamSetStandardValueCommand(input_, key->value(), command);
if (input_->keyframe_tracks().at(key->track()).size() == 1) {
// If this was the last keyframe on this track, set the standard value to the value at this time too
new NodeParamSetStandardValueCommand(input_,
key->track(),
input_->get_value_at_time_for_track(time_, key->track()),
command);
}
}
}
@@ -141,34 +149,29 @@ void NodeParamViewKeyframeControl::UpdateState()
return;
}
prev_key_btn_->setEnabled(!input_->keyframes().isEmpty() && time_ > input_->keyframes().first()->time());
next_key_btn_->setEnabled(!input_->keyframes().isEmpty() && time_ < input_->keyframes().last()->time());
NodeKeyframePtr earliest_key = input_->get_earliest_keyframe();
NodeKeyframePtr latest_key = input_->get_latest_keyframe();
prev_key_btn_->setEnabled(earliest_key && time_ > earliest_key->time());
next_key_btn_->setEnabled(latest_key && time_ < latest_key->time());
toggle_key_btn_->setChecked(input_->has_keyframe_at_time(time_));
}
void NodeParamViewKeyframeControl::GoToPreviousKey()
{
for (int i=input_->keyframes().size()-1;i>=0;i--) {
// Find closest keyframe that is before this time
const rational& this_key_time = input_->keyframes().at(i)->time();
NodeKeyframePtr previous_key = input_->get_closest_keyframe_before_time(time_);
if (this_key_time < time_) {
emit RequestSetTime(this_key_time);
break;
}
if (previous_key) {
emit RequestSetTime(previous_key->time());
}
}
void NodeParamViewKeyframeControl::GoToNextKey()
{
for (int i=0;i<input_->keyframes().size();i++) {
// Find closest keyframe that is before this time
const rational& this_key_time = input_->keyframes().at(i)->time();
NodeKeyframePtr next_key = input_->get_closest_keyframe_after_time(time_);
if (this_key_time > time_) {
emit RequestSetTime(this_key_time);
break;
}
if (next_key) {
emit RequestSetTime(next_key->time());
}
}
@@ -185,9 +188,17 @@ void NodeParamViewKeyframeControl::KeyframeEnableChanged(bool e)
// Enable keyframing
new NodeParamSetKeyframingCommand(input_, true, command);
// NodeInputs already have one keyframe by default, we move it to the current time here
NodeKeyframePtr key = NodeKeyframe::Create(time_, input_->get_standard_value(), NodeKeyframe::kDefaultType);
new NodeParamInsertKeyframeCommand(input_, key, command);
// Create one keyframe across all tracks here
QVector<QVariant> key_vals = input_->get_split_standard_value();
for (int i=0;i<key_vals.size();i++) {
NodeKeyframePtr key = NodeKeyframe::Create(time_,
key_vals.at(i),
NodeKeyframe::kDefaultType,
i);
new NodeParamInsertKeyframeCommand(input_, key, command);
}
} else {
// Confirm the user wants to clear all keyframes
if (QMessageBox::warning(this,
@@ -196,15 +207,19 @@ void NodeParamViewKeyframeControl::KeyframeEnableChanged(bool e)
QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
// Store value at this time, we'll set this as the persistent value later
QVariant stored_val = input_->get_value_at_time(time_);
QVector<QVariant> stored_vals = input_->get_split_values_at_time(time_);
// Delete all keyframes
for (int i=input_->keyframes().size()-1;i>=0;i--) {
new NodeParamRemoveKeyframeCommand(input_, input_->keyframes().at(i), command);
foreach (const NodeInput::KeyframeTrack& track, input_->keyframe_tracks()) {
for (int i=track.size()-1;i>=0;i--) {
new NodeParamRemoveKeyframeCommand(input_, track.at(i), command);
}
}
// Update standard value
new NodeParamSetStandardValueCommand(input_, stored_val, command);
for (int i=0;i<stored_vals.size();i++) {
new NodeParamSetStandardValueCommand(input_, i, stored_vals.at(i), command);
}
// Disable keyframing
new NodeParamSetKeyframingCommand(input_, false, command);