From 87756bb5f2eb81f5b3a52456287165ba37a7fb33 Mon Sep 17 00:00:00 2001 From: John Haddon Date: Tue, 19 Sep 2023 18:12:07 +0100 Subject: [PATCH] OptionTweaks : Allow multiple tweaks to the same option --- Changes.md | 1 + python/GafferSceneTest/OptionTweaksTest.py | 9 +++++++++ src/GafferScene/OptionTweaks.cpp | 6 ++---- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Changes.md b/Changes.md index ce6c2e33bcf..a5978f613af 100644 --- a/Changes.md +++ b/Changes.md @@ -26,6 +26,7 @@ Fixes - DispatchDialogue : Changed the button label for the results display from "Ok" to "Close". - Viewer : Fixed display of infinite values in the pixel inspectors. These were being incorrectly displayed as `nan` instead of `inf`. +- OptionTweaks : Fixed bug that prevented multiple tweaks being made to the same option in one node. API --- diff --git a/python/GafferSceneTest/OptionTweaksTest.py b/python/GafferSceneTest/OptionTweaksTest.py index 2ae5a618fb2..bc117a2a5a2 100644 --- a/python/GafferSceneTest/OptionTweaksTest.py +++ b/python/GafferSceneTest/OptionTweaksTest.py @@ -139,6 +139,15 @@ def testCreateMode( self ) : self.assertEqual( tweaks["out"]["globals"].getValue()["option:test"], IECore.IntData( 10 ) ) + def testChainedTweaks( self ) : + + tweaks = GafferScene.OptionTweaks() + + tweaks["tweaks"].addChild( Gaffer.TweakPlug( "test", 1, Gaffer.TweakPlug.Mode.Create ) ) + tweaks["tweaks"].addChild( Gaffer.TweakPlug( "test", 10, Gaffer.TweakPlug.Mode.Multiply ) ) + tweaks["tweaks"].addChild( Gaffer.TweakPlug( "test", 2, Gaffer.TweakPlug.Mode.Add ) ) + + self.assertEqual( tweaks["out"].globals()["option:test"].value, 12 ) if __name__ == "__main__" : unittest.main() diff --git a/src/GafferScene/OptionTweaks.cpp b/src/GafferScene/OptionTweaks.cpp index 87993561811..8d76071cba3 100644 --- a/src/GafferScene/OptionTweaks.cpp +++ b/src/GafferScene/OptionTweaks.cpp @@ -120,12 +120,10 @@ IECore::ConstCompoundObjectPtr OptionTweaks::computeProcessedGlobals( CompoundObjectPtr result = new CompoundObject(); result->members() = inputGlobals->members(); - const CompoundObject *source = inputGlobals.get(); - tweaksPlug->applyTweaks( - [&source]( const std::string &valueName ) + [&result]( const std::string &valueName ) { - return source->member( g_namePrefix + valueName ); + return result->member( g_namePrefix + valueName ); }, [&result]( const std::string &valueName, DataPtr newData ) {