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:
@@ -114,8 +114,10 @@ void CurveWidget::SetInput(NodeInput *input)
|
||||
connect(input_, &NodeInput::KeyframeAdded, view_, &CurveView::AddKeyframe);
|
||||
connect(input_, &NodeInput::KeyframeRemoved, view_, &CurveView::RemoveKeyframe);
|
||||
|
||||
foreach (NodeKeyframePtr key, input_->keyframes()) {
|
||||
view_->AddKeyframe(key);
|
||||
foreach (const NodeInput::KeyframeTrack& track, input_->keyframe_tracks()) {
|
||||
foreach (NodeKeyframePtr key, track) {
|
||||
view_->AddKeyframe(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -93,8 +93,10 @@ void NodeParamViewItem::SignalAllKeyframes()
|
||||
if (param->type() == NodeParam::kInput) {
|
||||
NodeInput* input = static_cast<NodeInput*>(param);
|
||||
|
||||
foreach (NodeKeyframePtr key, input->keyframes()) {
|
||||
InputAddedKeyframeInternal(input, key);
|
||||
foreach (const NodeInput::KeyframeTrack& track, input->keyframe_tracks()) {
|
||||
foreach (NodeKeyframePtr key, track) {
|
||||
InputAddedKeyframeInternal(input, key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -220,13 +222,15 @@ void NodeParamViewItem::InputKeyframeEnableChanged(bool e)
|
||||
{
|
||||
NodeInput* input = static_cast<NodeInput*>(sender());
|
||||
|
||||
foreach (NodeKeyframePtr key, input->keyframes()) {
|
||||
if (e) {
|
||||
// Add a keyframe item for each keyframe
|
||||
InputAddedKeyframeInternal(input, key);
|
||||
} else {
|
||||
// Remove each keyframe item
|
||||
emit KeyframeRemoved(key);
|
||||
foreach (const NodeInput::KeyframeTrack& track, input->keyframe_tracks()) {
|
||||
foreach (NodeKeyframePtr key, track) {
|
||||
if (e) {
|
||||
// Add a keyframe item for each keyframe
|
||||
InputAddedKeyframeInternal(input, key);
|
||||
} else {
|
||||
// Remove each keyframe item
|
||||
emit KeyframeRemoved(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -117,17 +117,19 @@ void NodeParamSetKeyframeTimeCommand::undo()
|
||||
key_->set_time(old_time_);
|
||||
}
|
||||
|
||||
NodeParamSetStandardValueCommand::NodeParamSetStandardValueCommand(NodeInput *input, const QVariant &value, QUndoCommand *parent) :
|
||||
NodeParamSetStandardValueCommand::NodeParamSetStandardValueCommand(NodeInput *input, int track, const QVariant &value, QUndoCommand *parent) :
|
||||
QUndoCommand(parent),
|
||||
input_(input),
|
||||
track_(track),
|
||||
old_value_(input_->get_standard_value()),
|
||||
new_value_(value)
|
||||
{
|
||||
}
|
||||
|
||||
NodeParamSetStandardValueCommand::NodeParamSetStandardValueCommand(NodeInput *input, const QVariant &new_value, const QVariant &old_value, QUndoCommand *parent) :
|
||||
NodeParamSetStandardValueCommand::NodeParamSetStandardValueCommand(NodeInput *input, int track, const QVariant &new_value, const QVariant &old_value, QUndoCommand *parent) :
|
||||
QUndoCommand(parent),
|
||||
input_(input),
|
||||
track_(track),
|
||||
old_value_(old_value),
|
||||
new_value_(new_value)
|
||||
{
|
||||
@@ -135,10 +137,10 @@ NodeParamSetStandardValueCommand::NodeParamSetStandardValueCommand(NodeInput *in
|
||||
|
||||
void NodeParamSetStandardValueCommand::redo()
|
||||
{
|
||||
input_->set_standard_value(new_value_);
|
||||
input_->set_standard_value(new_value_, track_);
|
||||
}
|
||||
|
||||
void NodeParamSetStandardValueCommand::undo()
|
||||
{
|
||||
input_->set_standard_value(old_value_);
|
||||
input_->set_standard_value(old_value_, track_);
|
||||
}
|
||||
|
||||
@@ -82,17 +82,19 @@ private:
|
||||
|
||||
class NodeParamSetStandardValueCommand : public QUndoCommand {
|
||||
public:
|
||||
NodeParamSetStandardValueCommand(NodeInput* input, const QVariant& value, QUndoCommand* parent = nullptr);
|
||||
NodeParamSetStandardValueCommand(NodeInput* input, const QVariant& new_value, const QVariant& old_value, QUndoCommand* parent = nullptr);
|
||||
NodeParamSetStandardValueCommand(NodeInput* input, int track, const QVariant& value, QUndoCommand* parent = nullptr);
|
||||
NodeParamSetStandardValueCommand(NodeInput* input, int track, const QVariant& new_value, const QVariant& old_value, QUndoCommand* parent = nullptr);
|
||||
|
||||
virtual void redo() override;
|
||||
virtual void undo() override;
|
||||
|
||||
private:
|
||||
NodeInput* input_;
|
||||
int track_;
|
||||
|
||||
QVariant old_value_;
|
||||
QVariant new_value_;
|
||||
|
||||
};
|
||||
|
||||
#endif // NODEPARAMVIEWUNDO_H
|
||||
|
||||
@@ -251,12 +251,12 @@ void NodeParamViewWidgetBridge::CreateWidgets()
|
||||
}
|
||||
}
|
||||
|
||||
void NodeParamViewWidgetBridge::SetInputValue(const QVariant &value)
|
||||
void NodeParamViewWidgetBridge::SetInputValue(const QVariant &value, int track)
|
||||
{
|
||||
QUndoCommand* command = new QUndoCommand();
|
||||
|
||||
if (input_->is_keyframing()) {
|
||||
NodeKeyframePtr existing_key = input_->get_keyframe_at_time(time_);
|
||||
NodeKeyframePtr existing_key = input_->get_keyframe_at_time_on_track(time_, track);
|
||||
|
||||
if (existing_key) {
|
||||
new NodeParamSetKeyframeValueCommand(existing_key, value, command);
|
||||
@@ -264,12 +264,13 @@ void NodeParamViewWidgetBridge::SetInputValue(const QVariant &value)
|
||||
// No existing key, create a new one
|
||||
NodeKeyframePtr new_key = NodeKeyframe::Create(time_,
|
||||
value,
|
||||
input_->get_best_keyframe_type_for_time(time_));
|
||||
input_->get_best_keyframe_type_for_time(time_, track),
|
||||
track);
|
||||
|
||||
new NodeParamInsertKeyframeCommand(input_, new_key, command);
|
||||
}
|
||||
} else {
|
||||
new NodeParamSetStandardValueCommand(input_, value, command);
|
||||
new NodeParamSetStandardValueCommand(input_, track, value, command);
|
||||
}
|
||||
|
||||
Core::instance()->undo_stack()->pushIfHasChildren(command);
|
||||
@@ -277,6 +278,8 @@ void NodeParamViewWidgetBridge::SetInputValue(const QVariant &value)
|
||||
|
||||
void NodeParamViewWidgetBridge::ProcessSlider(SliderBase *slider, const QVariant &value)
|
||||
{
|
||||
int slider_track = widgets_.indexOf(slider);
|
||||
|
||||
if (slider->IsDragging()) {
|
||||
|
||||
// While we're dragging, we block the input's normal signalling and create our own
|
||||
@@ -287,17 +290,18 @@ void NodeParamViewWidgetBridge::ProcessSlider(SliderBase *slider, const QVariant
|
||||
dragging_ = true;
|
||||
|
||||
// Cache current value
|
||||
drag_old_value_ = input_->get_value_at_time(time_);
|
||||
drag_old_value_ = input_->get_value_at_time_for_track(time_, slider_track);
|
||||
|
||||
// Determine whether we are creating a keyframe or not
|
||||
if (input_->is_keyframing()) {
|
||||
dragging_keyframe_ = input_->get_keyframe_at_time(time_);
|
||||
dragging_keyframe_ = input_->get_keyframe_at_time_on_track(time_, slider_track);
|
||||
drag_created_keyframe_ = !dragging_keyframe_;
|
||||
|
||||
if (drag_created_keyframe_) {
|
||||
dragging_keyframe_ = NodeKeyframe::Create(time_,
|
||||
value,
|
||||
input_->get_best_keyframe_type_for_time(time_));
|
||||
input_->get_best_keyframe_type_for_time(time_, slider_track),
|
||||
slider_track);
|
||||
|
||||
input_->insert_keyframe(dragging_keyframe_);
|
||||
|
||||
@@ -312,7 +316,7 @@ void NodeParamViewWidgetBridge::ProcessSlider(SliderBase *slider, const QVariant
|
||||
if (input_->is_keyframing()) {
|
||||
dragging_keyframe_->set_value(value);
|
||||
} else {
|
||||
input_->set_standard_value(value);
|
||||
input_->set_standard_value(value, slider_track);
|
||||
}
|
||||
|
||||
input_->blockSignals(false);
|
||||
@@ -337,14 +341,14 @@ void NodeParamViewWidgetBridge::ProcessSlider(SliderBase *slider, const QVariant
|
||||
new NodeParamSetKeyframeValueCommand(dragging_keyframe_, value, drag_old_value_, command);
|
||||
} else {
|
||||
// We just set the standard value
|
||||
new NodeParamSetStandardValueCommand(input_, value, drag_old_value_, command);
|
||||
new NodeParamSetStandardValueCommand(input_, slider_track, value, drag_old_value_, command);
|
||||
}
|
||||
|
||||
Core::instance()->undo_stack()->push(command);
|
||||
|
||||
} else {
|
||||
// No drag was involved, we can just push the value
|
||||
SetInputValue(value);
|
||||
SetInputValue(value, slider_track);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -387,12 +391,7 @@ void NodeParamViewWidgetBridge::WidgetCallback()
|
||||
// Widget is a FloatSlider
|
||||
FloatSlider* slider = static_cast<FloatSlider*>(sender());
|
||||
|
||||
QVector2D value(
|
||||
static_cast<float>(static_cast<FloatSlider*>(widgets_.at(0))->GetValue()),
|
||||
static_cast<float>(static_cast<FloatSlider*>(widgets_.at(1))->GetValue())
|
||||
);
|
||||
|
||||
ProcessSlider(slider, value);
|
||||
ProcessSlider(slider, slider->GetValue());
|
||||
break;
|
||||
}
|
||||
case NodeParam::kVec3:
|
||||
@@ -400,13 +399,7 @@ void NodeParamViewWidgetBridge::WidgetCallback()
|
||||
// Widget is a FloatSlider
|
||||
FloatSlider* slider = static_cast<FloatSlider*>(sender());
|
||||
|
||||
QVector3D value(
|
||||
static_cast<float>(static_cast<FloatSlider*>(widgets_.at(0))->GetValue()),
|
||||
static_cast<float>(static_cast<FloatSlider*>(widgets_.at(1))->GetValue()),
|
||||
static_cast<float>(static_cast<FloatSlider*>(widgets_.at(2))->GetValue())
|
||||
);
|
||||
|
||||
ProcessSlider(slider, value);
|
||||
ProcessSlider(slider, slider->GetValue());
|
||||
break;
|
||||
}
|
||||
case NodeParam::kVec4:
|
||||
@@ -414,14 +407,7 @@ void NodeParamViewWidgetBridge::WidgetCallback()
|
||||
// Widget is a FloatSlider
|
||||
FloatSlider* slider = static_cast<FloatSlider*>(sender());
|
||||
|
||||
QVector4D value(
|
||||
static_cast<float>(static_cast<FloatSlider*>(widgets_.at(0))->GetValue()),
|
||||
static_cast<float>(static_cast<FloatSlider*>(widgets_.at(1))->GetValue()),
|
||||
static_cast<float>(static_cast<FloatSlider*>(widgets_.at(2))->GetValue()),
|
||||
static_cast<float>(static_cast<FloatSlider*>(widgets_.at(3))->GetValue())
|
||||
);
|
||||
|
||||
ProcessSlider(slider, value);
|
||||
ProcessSlider(slider, slider->GetValue());
|
||||
break;
|
||||
}
|
||||
case NodeParam::kFile:
|
||||
@@ -433,25 +419,25 @@ void NodeParamViewWidgetBridge::WidgetCallback()
|
||||
case NodeParam::kText:
|
||||
{
|
||||
// Sender is a QLineEdit
|
||||
SetInputValue(static_cast<QLineEdit*>(sender())->text());
|
||||
SetInputValue(static_cast<QLineEdit*>(sender())->text(), 0);
|
||||
break;
|
||||
}
|
||||
case NodeParam::kBoolean:
|
||||
{
|
||||
// Widget is a QCheckBox
|
||||
SetInputValue(static_cast<QCheckBox*>(sender())->isChecked());
|
||||
SetInputValue(static_cast<QCheckBox*>(sender())->isChecked(), 0);
|
||||
break;
|
||||
}
|
||||
case NodeParam::kFont:
|
||||
{
|
||||
// Widget is a QFontComboBox
|
||||
SetInputValue(static_cast<QFontComboBox*>(sender())->currentFont());
|
||||
SetInputValue(static_cast<QFontComboBox*>(sender())->currentFont(), 0);
|
||||
break;
|
||||
}
|
||||
case NodeParam::kFootage:
|
||||
{
|
||||
// Widget is a FootageComboBox
|
||||
SetInputValue(QVariant::fromValue(static_cast<FootageComboBox*>(sender())->SelectedFootage()));
|
||||
SetInputValue(QVariant::fromValue(static_cast<FootageComboBox*>(sender())->SelectedFootage()), 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ public:
|
||||
private:
|
||||
void CreateWidgets();
|
||||
|
||||
void SetInputValue(const QVariant& value);
|
||||
void SetInputValue(const QVariant& value, int track);
|
||||
|
||||
void ProcessSlider(SliderBase* slider, const QVariant& value);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user