Skip to content

Commit

Permalink
PlugAlgo : Fix promotion of CompoundDataPlugs with non-dynamic children
Browse files Browse the repository at this point in the history
  • Loading branch information
johnhaddon committed Feb 1, 2024
1 parent 5e5808b commit 2d21714
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 4 deletions.
1 change: 1 addition & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ Fixes
- 3Delight : Fixed loading of surface shaders such as `dlStandard` so that they can be connected to the inputs of shaders such as `dlLayeredMaterial`.
- DeepState : Fixed handling of `NaN` values and samples where `ZBack` is less than `Z`.
- Premultiply : Fixed handling of non-existent alpha channel.
- PlugAlgo : Fixed promotion of CompoundDataPlugs with non-dynamic children, such as the `Camera.renderSettingOverrides` plug.

API
---
Expand Down
12 changes: 12 additions & 0 deletions python/GafferSceneTest/CameraTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,5 +241,17 @@ def testFrustum( self ) :
c["orthographicAperture"].setValue( imath.V2f( 0.1, 12 ) )
self.assertEqual( c["out"].object( "/camera" ).frustum( IECoreScene.Camera.FilmFit.Distort ).max() * 2.0, c["orthographicAperture"].getValue() )

def testPromoteRenderOverrides( self ) :

script = Gaffer.ScriptNode()
script["box"] = Gaffer.Box()
script["box"]["camera"] = GafferScene.Camera()
Gaffer.PlugAlgo.promote( script["box"]["camera"]["renderSettingOverrides"] )

script2 = Gaffer.ScriptNode()
script2.execute( script.serialise() )
self.assertEqual( script2["box"]["renderSettingOverrides"].keys(), script["box"]["renderSettingOverrides"].keys() )
self.assertTrue( Gaffer.PlugAlgo.isPromoted( script2["box"]["camera"]["renderSettingOverrides"] ) )

if __name__ == "__main__":
unittest.main()
33 changes: 33 additions & 0 deletions python/GafferTest/PlugAlgoTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1099,5 +1099,38 @@ def testNumericDataConversions( self ) :
value = ord( data.value ) if isinstance( data, IECore.CharData ) else data.value
self.assertEqual( plug.getValue(), plugType.ValueType( value ) )

class CompoundDataNode( Gaffer.Node ) :

def __init__( self, name = "CompoundDataNode" ) :

Gaffer.Node.__init__( self, name )

self["plug"] = Gaffer.CompoundDataPlug()
self["plug"]["child1"] = Gaffer.NameValuePlug( "value1", 10 )
self["plug"]["child2"] = Gaffer.NameValuePlug( "value2", 20 )

IECore.registerRunTimeTyped( CompoundDataNode )

def testPromoteCompoundDataPlug( self ) :

script = Gaffer.ScriptNode()
script["box"] = Gaffer.Box()
script["box"]["node"] = self.CompoundDataNode()

Gaffer.PlugAlgo.promote( script["box"]["node"]["plug"] )
script["box"]["plug"]["child1"]["value"].setValue( 100 )
script["box"]["plug"]["child2"]["value"].setInput( script["box"]["plug"]["child1"]["value"] )

script2 = Gaffer.ScriptNode()
script2.execute( script.serialise() )

self.assertEqual( script2["box"]["plug"].keys(), script["box"]["plug"].keys() )
self.assertTrue( Gaffer.PlugAlgo.isPromoted( script2["box"]["node"]["plug"] ) )
self.assertEqual( script2["box"]["node"]["plug"]["child1"]["value"].getValue(), 100 )
self.assertEqual(
script2["box"]["node"]["plug"]["child2"]["value"].source(),
script2["box"]["plug"]["child1"]["value"].source()
)

if __name__ == "__main__":
unittest.main()
9 changes: 5 additions & 4 deletions src/Gaffer/PlugAlgo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@

#include "fmt/format.h"

#include <array>

using namespace std;
using namespace IECore;
using namespace Gaffer;
Expand Down Expand Up @@ -1177,14 +1179,13 @@ void applyDynamicFlag( Plug *plug )
// for types like CompoundNumericPlug that create children in their constructors.
// Or, even better, abolish the Dynamic flag entirely and deal with everything
// via serialisers.
const Gaffer::TypeId compoundTypes[] = { PlugTypeId, ValuePlugTypeId, ArrayPlugTypeId };
const Gaffer::TypeId *compoundTypesEnd = compoundTypes + 3;
if( find( compoundTypes, compoundTypesEnd, (Gaffer::TypeId)plug->typeId() ) != compoundTypesEnd )
std::array<Gaffer::TypeId, 4> compoundTypes = { PlugTypeId, ValuePlugTypeId, ArrayPlugTypeId, CompoundDataPlugTypeId };
if( find( compoundTypes.begin(), compoundTypes.end(), (Gaffer::TypeId)plug->typeId() ) != compoundTypes.end() )
{
for( Plug::RecursiveIterator it( plug ); !it.done(); ++it )
{
(*it)->setFlags( Plug::Dynamic, true );
if( find( compoundTypes, compoundTypesEnd, (Gaffer::TypeId)(*it)->typeId() ) == compoundTypesEnd )
if( find( compoundTypes.begin(), compoundTypes.end(), (Gaffer::TypeId)plug->typeId() ) != compoundTypes.end() )
{
it.prune();
}
Expand Down

0 comments on commit 2d21714

Please sign in to comment.