From d64a5b87ad4800276c15179ac641586c560f6bda Mon Sep 17 00:00:00 2001 From: shun-iwasawa Date: Sep 28 2021 07:23:29 +0000 Subject: fix fx intensity --- diff --git a/toonz/sources/toonzlib/scenefx.cpp b/toonz/sources/toonzlib/scenefx.cpp index 072dcd4..33c10d0 100644 --- a/toonz/sources/toonzlib/scenefx.cpp +++ b/toonz/sources/toonzlib/scenefx.cpp @@ -551,7 +551,12 @@ public: // (at least) of a particle Fx int m_particleDescendentCount; - QList m_globalControlledFx; + // fxid and pointer to the correspondent blend fx for the global + // control. Boolean is the flag indicating that the makePF is just called + // from the blend fx. If the flag is true then just compute the + // global controlled Fx without inserting the same blend fx in order to + // prevent infinite loop. + QMap> m_globalControlledFx; public: FxBuilder(ToonzScene *scene, TXsheet *xsh, double frame, int whichLevels, @@ -1006,20 +1011,27 @@ PlacedFx FxBuilder::makePFfromUnaryFx(TFx *fx) { if (!inputFx) return PlacedFx(); // global controllable fx - if (fx->getAttributes()->hasGlobalControl() && - !m_globalControlledFx.contains(fx->getFxId())) { - GlobalControllableFx *gcFx = dynamic_cast(fx); - double val = gcFx->getGrobalControlValue(m_frame); - if (val < 1.0) { - m_globalControlledFx.append(fx->getFxId()); - // insert cross disolve fx and mix with the input fx - TFxP blendFx = TFx::create("blendFx"); - blendFx->connect("Source1", fx); - blendFx->connect("Source2", inputFx); - // set the global intensity value to the cross disolve fx - dynamic_cast(blendFx->getParams()->getParam("value")) - ->setDefaultValue(val * 100.0); - return makePF(blendFx.getPointer()); + if (fx->getAttributes()->hasGlobalControl()) { + if (!m_globalControlledFx.contains(fx->getFxId())) { + GlobalControllableFx *gcFx = dynamic_cast(fx); + double val = gcFx->getGrobalControlValue(m_frame); + if (val < 1.0) { + // insert cross disolve fx and mix with the input fx + TFxP blendFx = TFx::create("blendFx"); + blendFx->connect("Source1", fx); + blendFx->connect("Source2", inputFx); + // set the global intensity value to the cross disolve fx + dynamic_cast(blendFx->getParams()->getParam("value")) + ->setDefaultValue(val * 100.0); + m_globalControlledFx.insert(fx->getFxId(), {blendFx, true}); + return makePF(blendFx.getPointer()); + } + } else if (m_globalControlledFx.value(fx->getFxId()).second) + m_globalControlledFx[fx->getFxId()].second = false; + else { + m_globalControlledFx[fx->getFxId()].second = true; + return makePF( + m_globalControlledFx.value(fx->getFxId()).first.getPointer()); } } @@ -1090,22 +1102,29 @@ PlacedFx FxBuilder::makePFfromGenericFx(TFx *fx) { } // global controllable fx - if (fx->getAttributes()->hasGlobalControl() && - !m_globalControlledFx.contains(fx->getFxId())) { - GlobalControllableFx *gcFx = dynamic_cast(fx); - double val = gcFx->getGrobalControlValue(m_frame); - if (val < 1.0) { - TFxP inputFx = fx->getInputPort(fx->getPreferredInputPort())->getFx(); - if (!inputFx) return pf; - m_globalControlledFx.append(fx->getFxId()); - // insert cross disolve fx and mix with the input fx - TFxP blendFx = TFx::create("blendFx"); - blendFx->connect("Source1", fx); - blendFx->connect("Source2", inputFx.getPointer()); - // set the global intensity value to the cross disolve fx - dynamic_cast(blendFx->getParams()->getParam("value")) - ->setDefaultValue(val * 100.0); - return makePF(blendFx.getPointer()); + if (fx->getAttributes()->hasGlobalControl()) { + if (!m_globalControlledFx.contains(fx->getFxId())) { + GlobalControllableFx *gcFx = dynamic_cast(fx); + double val = gcFx->getGrobalControlValue(m_frame); + if (val < 1.0) { + TFxP inputFx = fx->getInputPort(fx->getPreferredInputPort())->getFx(); + if (!inputFx) return pf; + // insert cross disolve fx and mix with the input fx + TFxP blendFx = TFx::create("blendFx"); + blendFx->connect("Source1", fx); + blendFx->connect("Source2", inputFx.getPointer()); + m_globalControlledFx.insert(fx->getFxId(), {blendFx, true}); + // set the global intensity value to the cross disolve fx + dynamic_cast(blendFx->getParams()->getParam("value")) + ->setDefaultValue(val * 100.0); + return makePF(blendFx.getPointer()); + } + } else if (m_globalControlledFx.value(fx->getFxId()).second) + m_globalControlledFx[fx->getFxId()].second = false; + else { + m_globalControlledFx[fx->getFxId()].second = true; + return makePF( + m_globalControlledFx.value(fx->getFxId()).first.getPointer()); } }