Skip to content

OpenToonz - An open-source full-featured 2D animation creation software

C

Add Reset FX option

Rodney4cc175ad5127
diff --git a/toonz/sources/include/toonz/fxcommand.h b/toonz/sources/include/toonz/fxcommand.h
index 8cd918be0..a0f87d861 100644
--- a/toonz/sources/include/toonz/fxcommand.h
+++ b/toonz/sources/include/toonz/fxcommand.h
@@ -67,6 +67,9 @@ DVAPI void addFx(TFx *newFx, const QList<TFxP> &fxs, TApplication *app,
int colunIndex, int rowIndex, bool attachSource = true);
DVAPI void replaceFx(TFx *newFx, const QList<TFxP> &fxs,
TXsheetHandle *xshHandle, TFxHandle *fxHandle);
+// Reset animatable values at one frame without replacing the FX.
+DVAPI void resetFxFrame(TFx *fx, TFx *defaults, int frame,
+ TXsheetHandle *xshHandle, TFxHandle *fxHandle);
DVAPI void duplicateFx(TFx *src, TXsheetHandle *xshHandle, TFxHandle *fxHandle);
DVAPI void unlinkFx(TFx *fx, TFxHandle *fxHandle, TXsheetHandle *xshHandle);
DVAPI void makeMacroFx(const std::vector<TFxP> &fxs, TApplication *app);
diff --git a/toonz/sources/toonzlib/fxcommand.cpp b/toonz/sources/toonzlib/fxcommand.cpp
index aecc4c273..a759e27bb 100644
--- a/toonz/sources/toonzlib/fxcommand.cpp
+++ b/toonz/sources/toonzlib/fxcommand.cpp
@@ -21,6 +21,9 @@
// TnzBase includes
#include "tparamcontainer.h"
#include "tparamset.h"
+#include "tdoubleparam.h"
+#include "tspectrumparam.h"
+#include "ttonecurveparam.h"
#include "tfxattributes.h"
#include "tmacrofx.h"
#include "tpassivecachemanager.h"
@@ -1336,6 +1339,105 @@ void TFxCommand::replaceFx(TFx *newFx, const QList<TFxP> &fxs,
undoManager->endBlock();
}
+// Reset numeric leaves so composite parameters retain their topology and
+// non-animatable settings. Snapshots retain all key and interpolation metadata.
+class ResetFxFrameUndo final : public FxCommandUndo {
+ struct Channel {
+ TParamP param, before, after;
+ };
+ TFxP m_fx;
+ int m_frame;
+ TXsheetHandle *m_xshHandle;
+ TFxHandle *m_fxHandle;
+ std::vector<Channel> m_channels;
+
+ void collect(TParam *param, TParam *defaults) {
+ if (!param || !defaults || !param->isAnimatable()) return;
+ if (auto value = dynamic_cast<TDoubleParam *>(param)) {
+ auto defaultValue = dynamic_cast<TDoubleParam *>(defaults);
+ if (!defaultValue) return;
+ TParamP before = value->clone();
+ TParamP after = value->clone();
+ auto result = static_cast<TDoubleParam *>(after.getPointer());
+ double resetValue = defaultValue->getValue(0);
+ result->setValue(m_frame, resetValue);
+ // setValue refuses expression/file-driven keys or segments. Leave those
+ // channels intact rather than silently replacing their interpolation.
+ if (result->isKeyframe(m_frame) &&
+ result->getValue(m_frame) == resetValue)
+ m_channels.push_back({TParamP(param), before, after});
+ } else if (auto values = dynamic_cast<TParamSet *>(param)) {
+ auto defaultValues = dynamic_cast<TParamSet *>(defaults);
+ if (!defaultValues ||
+ values->getParamCount() != defaultValues->getParamCount())
+ return;
+ for (int i = 0; i < values->getParamCount(); ++i)
+ collect(values->getParam(i).getPointer(),
+ defaultValues->getParam(i).getPointer());
+ } else if (auto spectrum = dynamic_cast<TSpectrumParam *>(param)) {
+ auto defaultSpectrum = dynamic_cast<TSpectrumParam *>(defaults);
+ if (!defaultSpectrum ||
+ spectrum->getKeyCount() != defaultSpectrum->getKeyCount())
+ return;
+ for (int i = 0; i < spectrum->getKeyCount(); ++i) {
+ collect(spectrum->getPosition(i).getPointer(),
+ defaultSpectrum->getPosition(i).getPointer());
+ collect(spectrum->getColor(i).getPointer(),
+ defaultSpectrum->getColor(i).getPointer());
+ }
+ } else if (auto curve = dynamic_cast<TToneCurveParam *>(param)) {
+ auto defaultCurve = dynamic_cast<TToneCurveParam *>(defaults);
+ if (!defaultCurve) return;
+ // RGBA, RGB, Red, Green, Blue and Alpha; do not change the UI channel
+ // selection or the global Linear setting.
+ for (int i = 0; i < 6; ++i) {
+ auto channel = static_cast<decltype(curve->getCurrentChannel())>(i);
+ collect(curve->getParamSet(channel).getPointer(),
+ defaultCurve->getParamSet(channel).getPointer());
+ }
+ }
+ }
+
+ void apply(bool undoing) const {
+ for (const auto &channel : m_channels)
+ channel.param->copy(
+ (undoing ? channel.before : channel.after).getPointer());
+ m_fxHandle->notifyFxChanged();
+ m_xshHandle->notifyXsheetChanged();
+ }
+
+public:
+ ResetFxFrameUndo(TFx *fx, TFx *defaults, int frame, TXsheetHandle *xshHandle,
+ TFxHandle *fxHandle)
+ : m_fx(fx), m_frame(frame), m_xshHandle(xshHandle), m_fxHandle(fxHandle) {
+ TParamContainer *params = fx->getParams();
+ for (int i = 0; i < params->getParamCount(); ++i)
+ collect(params->getParam(i),
+ defaults->getParams()->getParam(params->getParamName(i)));
+ }
+
+ bool isConsistent() const override { return !m_channels.empty(); }
+ void undo() const override { apply(true); }
+ void redo() const override { apply(false); }
+ int getSize() const override { return sizeof(*this); }
+ QString getHistoryString() override {
+ return QObject::tr("Reset FX at Frame : %1 : %2")
+ .arg(QString::fromStdWString(m_fx->getName()))
+ .arg(m_frame + 1);
+ }
+};
+
+void TFxCommand::resetFxFrame(TFx *fx, TFx *defaults, int frame,
+ TXsheetHandle *xshHandle, TFxHandle *fxHandle) {
+ if (!fx || !defaults || frame < 0) return;
+ std::unique_ptr<ResetFxFrameUndo> undo(
+ new ResetFxFrameUndo(fx, defaults, frame, xshHandle, fxHandle));
+ if (undo->isConsistent()) {
+ undo->redo();
+ TUndoManager::manager()->add(undo.release());
+ }
+}
+
//**********************************************************************
// Unlink Fx command
//**********************************************************************
diff --git a/toonz/sources/toonzqt/fxschematicnode.cpp b/toonz/sources/toonzqt/fxschematicnode.cpp
index 0ccda7277..a8ecfed70 100644
--- a/toonz/sources/toonzqt/fxschematicnode.cpp
+++ b/toonz/sources/toonzqt/fxschematicnode.cpp
@@ -41,6 +41,8 @@
#include "tfxattributes.h"
#include "tmacrofx.h"
#include "trasterfx.h"
+#include "texternfx.h"
+#include "pluginhost.h"
#include "tpassivecachemanager.h"
// TnzCore includes
@@ -868,6 +870,44 @@ void FxPainter::contextMenuEvent(QGraphicsSceneContextMenuEvent *cme) {
menu.addMenu(addMenu);
if (m_type != eGroupedFx) menu.addMenu(replacefxMenu);
}
+ // Reset only the clicked, standalone factory FX. Reuse replacement so
+ // connections, position, grouping and Undo/Redo follow Replace FX behavior.
+ if (enableInsertAction && m_type != eGroupedFx &&
+ !dynamic_cast<TMacroFx *>(fx) && !dynamic_cast<TColumnFx *>(fx) &&
+ !dynamic_cast<TExternFx *>(fx) &&
+ !dynamic_cast<RasterFxPluginHost *>(fx) &&
+ !isAInnerMacroFx(fx, fxScene->getXsheet())) {
+ TFxP defaults = TFx::create(fx->getFxType());
+ bool compatible =
+ defaults && defaults->getInputPortCount() == fx->getInputPortCount();
+ // Replacement matches input ports by index. Do not drop or misroute
+ // connections when a dynamic port layout differs from a fresh instance.
+ for (int p = 0; compatible && p < fx->getInputPortCount(); ++p)
+ compatible = defaults->getInputPortName(p) == fx->getInputPortName(p);
+ if (compatible) {
+ QAction *resetFx = menu.addAction(tr("Reset FX"));
+ resetFx->setToolTip(tr(
+ "Reset all FX settings. Hold Shift when triggering to reset animated "
+ "values at the current frame only."));
+ TFxP target = fx;
+ connect(resetFx, &QAction::triggered, fxScene,
+ [fxScene, target, defaults]() {
+ if (QApplication::keyboardModifiers() & Qt::ShiftModifier) {
+ TFxCommand::resetFxFrame(
+ target.getPointer(), defaults.getPointer(),
+ fxScene->getFrameHandle()->getFrameIndex(),
+ fxScene->getXsheetHandle(), fxScene->getFxHandle());
+ return;
+ }
+ defaults->setName(target->getName());
+ QList<TFxP> fxs;
+ fxs.append(target);
+ TFxCommand::replaceFx(defaults.getPointer(), fxs,
+ fxScene->getXsheetHandle(),
+ fxScene->getFxHandle());
+ });
+ }
+ }
if (m_type != eGroupedFx) menu.addAction(fxEditorPopup);
if (enableInsertAction) {
menu.addSeparator();