Skip to content

Commit cb0dea3

Browse files
fixup! AttributeQuery : Support inheriting global attributes
UI and test for ShaderQuery
1 parent 6351706 commit cb0dea3

File tree

3 files changed

+69
-2
lines changed

3 files changed

+69
-2
lines changed

Changes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Improvements
77
- RenderMan : Added dedicated viewport visualisers for RenderMan lights.
88
- LocaliseAttributes : Added support for localising global attributes, controlled by the new `includeGlobalAttributes` plug.
99
- AttributeTweaks : Added support for localising global attributes when `localise` is enabled.
10-
- AttributeQuery : Added support for querying global attributes when `inherit` is enabled.
10+
- AttributeQuery, ShaderQuery : Added support for querying global attributes when `inherit` is enabled.
1111

1212
API
1313
---

python/GafferSceneTest/ShaderQueryTest.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,73 @@ def testSerialisation( self ) :
475475
self.assertIsNone( scriptNode["target"]["parameters"]["b1"].getInput() )
476476
self.assertEqual( str( scriptNode["target"]["parameters"]["b2"].getInput() ), str( q["out"][1]["exists"] ) )
477477

478+
def testInheritedGlobalShader( self ) :
479+
480+
sphere = GafferScene.Sphere()
481+
482+
globalSurface = GafferSceneTest.TestShader( "surface" )
483+
globalSurface["type"].setValue( "test:surface" )
484+
globalSurface["parameters"]["i"].setValue( 2 )
485+
globalSurface["parameters"]["c"].setValue( imath.Color3f( 0.3, 0.4, 0.5 ) )
486+
487+
globalAttributes = GafferScene.CustomAttributes()
488+
globalAttributes["in"].setInput( sphere["out"] )
489+
globalAttributes["global"].setValue( True )
490+
globalAttributes["extraAttributes"].setValue( IECore.CompoundObject( { "test:surface" : globalSurface.attributes()["test:surface"] } ) )
491+
492+
surface = GafferSceneTest.TestShader( "surface" )
493+
surface["type"].setValue( "test:surface" )
494+
surface["parameters"]["i"].setValue( 3 )
495+
surface["parameters"]["c"].setValue( imath.Color3f( 0.6, 0.7, 0.8 ) )
496+
497+
shaderAssignment = GafferScene.ShaderAssignment()
498+
shaderAssignment["in"].setInput( globalAttributes["out"] )
499+
shaderAssignment["shader"].setInput( surface["out"] )
500+
shaderAssignment["enabled"].setValue( False )
501+
502+
query = GafferScene.ShaderQuery()
503+
query["scene"].setInput( shaderAssignment["out"] )
504+
query["location"].setValue( "/sphere" )
505+
query["shader"].setValue( "test:surface" )
506+
507+
v1 = query.addQuery( Gaffer.IntPlug( "i", Gaffer.Plug.Direction.Out, 1 ), "i" )
508+
v2 = query.addQuery( Gaffer.Color3fPlug( "c3f", Gaffer.Plug.Direction.Out, imath.Color3f( 0.1, 0.2, 0.3 ) ), "c" )
509+
510+
self.assertFalse( query["out"][0]["exists"].getValue() )
511+
self.assertFalse( query["out"][1]["exists"].getValue() )
512+
513+
query["inherit"].setValue( True )
514+
515+
self.assertTrue( query["out"][0]["exists"].getValue() )
516+
self.assertTrue( query["out"][1]["exists"].getValue() )
517+
518+
self.assertEqual( query["out"][0]["value"].getValue(), 2 )
519+
self.assertEqual( query["out"][1]["value"].getValue(), imath.Color3f( 0.3, 0.4, 0.5 ) )
520+
521+
globalSurface["parameters"]["i"].setValue( 10 )
522+
globalAttributes["extraAttributes"].setValue( IECore.CompoundObject( { "test:surface" : globalSurface.attributes()["test:surface"] } ) )
523+
524+
self.assertTrue( query["out"][0]["exists"].getValue() )
525+
self.assertTrue( query["out"][1]["exists"].getValue() )
526+
527+
self.assertEqual( query["out"][0]["value"].getValue(), 10 )
528+
self.assertEqual( query["out"][1]["value"].getValue(), imath.Color3f( 0.3, 0.4, 0.5 ) )
529+
530+
shaderAssignment["enabled"].setValue( True )
531+
532+
self.assertTrue( query["out"][0]["exists"].getValue() )
533+
self.assertTrue( query["out"][1]["exists"].getValue() )
534+
535+
self.assertEqual( query["out"][0]["value"].getValue(), 3 )
536+
self.assertEqual( query["out"][1]["value"].getValue(), imath.Color3f( 0.6, 0.7, 0.8 ) )
537+
538+
query["inherit"].setValue( False )
539+
540+
self.assertTrue( query["out"][0]["exists"].getValue() )
541+
self.assertTrue( query["out"][1]["exists"].getValue() )
542+
543+
self.assertEqual( query["out"][0]["value"].getValue(), 3 )
544+
self.assertEqual( query["out"][1]["value"].getValue(), imath.Color3f( 0.6, 0.7, 0.8 ) )
478545

479546
if __name__ == "__main__":
480547
unittest.main()

python/GafferSceneUI/ShaderQueryUI.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ def _shaderAttributes( plugValueWidget, paths, affectedOnly ) :
402402
attributeNamePatterns = node["shader"].getValue() if affectedOnly else "*"
403403

404404
for path in paths :
405-
attributes = node["scene"].fullAttributes( path ) if useFullAttr else node["scene"].attributes( path )
405+
attributes = node["scene"].fullAttributes( path, withGlobalAttributes = True ) if useFullAttr else node["scene"].attributes( path )
406406
for name, attribute in attributes.items() :
407407
if not IECore.StringAlgo.matchMultiple( name, attributeNamePatterns ) :
408408
continue

0 commit comments

Comments
 (0)