def testSwitchWithComponentConnections( self ) : s = Gaffer.ScriptNode() s["n1"] = GafferSceneTest.TestShader( "n1" ) s["n2"] = GafferSceneTest.TestShader( "n2" ) s["n3"] = GafferSceneTest.TestShader( "n3" ) s["n3"]["type"].setValue( "test:surface" ) s["switch"] = Gaffer.Switch() s["switch"].setup( s["n3"]["parameters"]["c"] ) s["switch"]["in"][0].setInput( s["n1"]["out"] ) s["switch"]["in"][1].setInput( s["n2"]["out"] ) s["n3"]["parameters"]["c"]["r"].setInput( s["switch"]["out"]["r"] ) s["expression"] = Gaffer.Expression() s["expression"].setExpression( 'parent["switch"]["index"] = context["index"]' ) with Gaffer.Context() as context : for i in range( 0, 3 ) : context["index"] = i effectiveIndex = i % 2 network = s["n3"].attributes()["test:surface"] self.assertEqual( len( network ), 2 ) self.assertEqual( network.inputConnections( "n3" ), [ network.Connection( network.Parameter( "n{0}".format( effectiveIndex + 1 ), "r", ), network.Parameter( "n3", "c.r" ) ) ] )
def testNameSwitch( self ) : n1 = GafferSceneTest.TestShader( "n1" ) n2 = GafferSceneTest.TestShader( "n2" ) n3 = GafferSceneTest.TestShader( "n3" ) n3["type"].setValue( "test:surface" ) switch = Gaffer.NameSwitch() switch.setup( n3["parameters"]["c"] ) switch["in"].resize( 2 ) switch["in"][0]["value"].setInput( n1["out"] ) switch["in"][1]["value"].setInput( n2["out"] ) switch["in"][1]["name"].setValue( "n2" ) n3["parameters"]["c"].setInput( switch["out"]["value"] ) for n in ( "n1", "n2" ) : switch["selector"].setValue( n ) network = n3.attributes()["test:surface"] self.assertEqual( len( network ), 2 ) self.assertEqual( network.inputConnections( "n3" ), [ network.Connection( network.Parameter( n, "", ), network.Parameter( "n3", "c" ) ) ] )
def testLabelOverride(self): shader = GafferSceneTest.TestShader() shader["type"].setValue("test:surface") shader["name"].setValue("shader1") shader2 = GafferSceneTest.TestShader() shader2["type"].setValue("test:surface") shader2["name"].setValue("shader2") plane = GafferScene.Plane() planeFilter = GafferScene.PathFilter() planeFilter["paths"].setValue(IECore.StringVectorData(["/plane"])) assignment = GafferScene.ShaderAssignment() assignment["in"].setInput(plane["out"]) assignment["filter"].setInput(planeFilter["out"]) assignment["shader"].setInput(shader["out"]) output = assignment["out"].attributes( "/plane")["test:surface"].outputShader() self.assertEqual(output.name, "shader1") self.assertEqual(output.blindData()["label"], IECore.StringData("TestShader")) assignment["label"].setValue("glass") output = assignment["out"].attributes( "/plane")["test:surface"].outputShader() self.assertEqual(output.name, "shader1") self.assertEqual(output.blindData()["label"], IECore.StringData("glass"))
def testSetup( self ) : shader1 = GafferSceneTest.TestShader() shader2 = GafferSceneTest.TestShader() shader1["parameters"]["c"].setValue( imath.Color3f( 0 ) ) shader2["parameters"]["c"].setValue( imath.Color3f( 1 ) ) switch = GafferScene.ShaderSwitch() switch.setup( shader1["parameters"]["c"] ) switch["in"][0].setInput( shader1["out"] ) switch["in"][1].setInput( shader2["out"] ) shader3 = GafferSceneTest.TestShader() shader3["type"].setValue( "test:surface" ) shader3["parameters"]["c"].setInput( switch["out"] ) for i in range( 0, 2 ) : switch["index"].setValue( i ) network = shader3.attributes()["test:surface"] self.assertEqual( len( network ), 2 ) self.assertEqual( network[0].parameters["c"].value, imath.Color3f( i ) )
def testSwitch(self): n1 = GafferSceneTest.TestShader() n1["parameters"]["i"].setValue(1) n2 = GafferSceneTest.TestShader() n2["parameters"]["i"].setValue(2) n3 = GafferSceneTest.TestShader() n3["type"].setValue("test:surface") switch = Gaffer.SwitchComputeNode() switch.setup(n3["parameters"]["c"]) switch["in"][0].setInput(n1["out"]) switch["in"][1].setInput(n2["out"]) n3["parameters"]["c"].setInput(switch["out"]) for i in range(0, 3): switch["index"].setValue(i) effectiveIndex = i % 2 network = n3.attributes()["test:surface"] self.assertEqual(len(network), 2) self.assertEqual(network[0].parameters["i"].value, effectiveIndex + 1) self.assertEqual(network[1].parameters["c"].value, "link:" + network[0].parameters["__handle"].value)
def testShaderNodeColorMode( self ) : sphere = GafferScene.Sphere() group = GafferScene.Group() group["in"][0].setInput( sphere["out"] ) group["in"][1].setInput( sphere["out"] ) group["in"][2].setInput( sphere["out"] ) shader1 = GafferSceneTest.TestShader() shader1["name"].setValue( "test" ) shader1["type"].setValue( "gfr:surface" ) filter1 = GafferScene.PathFilter() filter1["paths"].setValue( IECore.StringVectorData( [ "/group/sphere1" ] ) ) assignment1 = GafferScene.ShaderAssignment() assignment1["in"].setInput( group["out"] ) assignment1["filter"].setInput( filter1["out"] ) assignment1["shader"].setInput( shader1["out"] ) shader2 = GafferSceneTest.TestShader() shader2["name"].setValue( "test" ) shader2["type"].setValue( "gfr:surface" ) Gaffer.Metadata.registerValue( shader2, "nodeGadget:color", imath.Color3f( 1, 0, 0 ) ) filter2 = GafferScene.PathFilter() filter2["paths"].setValue( IECore.StringVectorData( [ "/group/sphere2" ] ) ) assignment2 = GafferScene.ShaderAssignment() assignment2["in"].setInput( assignment1["out"] ) assignment2["filter"].setInput( filter2["out"] ) assignment2["shader"].setInput( shader2["out"] ) self.assertTrue( "gl:surface" not in assignment2["out"].attributes( "/group/sphere" ) ) self.assertTrue( "gl:surface" not in assignment2["out"].attributes( "/group/sphere1" ) ) self.assertTrue( "gl:surface" not in assignment2["out"].attributes( "/group/sphere2" ) ) visualiser = GafferScene.AttributeVisualiser() visualiser["in"].setInput( assignment2["out"] ) self.assertSceneValid( visualiser["out"] ) self.assertTrue( "gl:surface" not in visualiser["out"].attributes( "/group/sphere" ) ) self.assertTrue( "gl:surface" not in visualiser["out"].attributes( "/group/sphere1" ) ) self.assertTrue( "gl:surface" not in visualiser["out"].attributes( "/group/sphere2" ) ) visualiser["attributeName"].setValue( "gfr:surface" ) visualiser["mode"].setValue( visualiser.Mode.ShaderNodeColor ) self.assertSceneValid( visualiser["out"] ) self.assertTrue( "gl:surface" not in visualiser["out"].attributes( "/group/sphere" ) ) self.assertTrue( "gl:surface" in visualiser["out"].attributes( "/group/sphere1" ) ) self.assertTrue( "gl:surface" in visualiser["out"].attributes( "/group/sphere2" ) ) self.assertEqual( visualiser["out"].attributes( "/group/sphere1" )["gl:surface"].outputShader().parameters["Cs"].value, imath.Color3f( 0 ), ) self.assertEqual( visualiser["out"].attributes( "/group/sphere2" )["gl:surface"].outputShader().parameters["Cs"].value, imath.Color3f( 1, 0, 0 ), )
def testSerialisation(self): script = Gaffer.ScriptNode() script["shader1"] = GafferSceneTest.TestShader() script["shader2"] = GafferSceneTest.TestShader() script["shader1"]["parameters"]["i"].setValue(1) script["shader2"]["parameters"]["i"].setValue(2) script["switch"] = GafferScene.ShaderSwitch() script["switch"]["in"].setInput(script["shader1"]["out"]) script["switch"]["in1"].setInput(script["shader2"]["out"]) script2 = Gaffer.ScriptNode() script2.execute(script.serialise()) self.assertTrue(script2["switch"]["in"][0].getInput().isSame( script2["shader1"]["out"])) self.assertTrue(script2["switch"]["in1"].getInput().isSame( script2["shader2"]["out"])) self.assertTrue(script2["switch"]["in2"].getInput() is None) self.assertFalse("in3" in script2["switch"]) self.assertTrue(script2["switch"]["out"].source().isSame( script2["shader1"]["out"]))
def testAssignDisabledShader( self ) : s = Gaffer.ScriptNode() s["p"] = GafferScene.Plane() s["s"] = GafferSceneTest.TestShader() s["s"]["name"].setValue( "test" ) s["a"] = GafferScene.ShaderAssignment() s["a"]["in"].setInput( s["p"]["out"] ) s["a"]["shader"].setInput( s["s"]["out"] ) self.assertTrue( "shader" in s["a"]["out"].attributes( "/plane" ) ) self.assertEqual( s["a"]["out"].attributes( "/plane" )["shader"][-1].name, "test" ) s["s2"] = GafferSceneTest.TestShader() s["s2"]["name"].setValue( "test2" ) s["a2"] = GafferScene.ShaderAssignment() s["a2"]["in"].setInput( s["a"]["out"] ) s["a2"]["shader"].setInput( s["s2"]["out"] ) self.assertTrue( "shader" in s["a"]["out"].attributes( "/plane" ) ) self.assertEqual( s["a2"]["out"].attributes( "/plane" )["shader"][-1].name, "test2" ) s["s2"]["enabled"].setValue( False ) self.assertTrue( "shader" in s["a"]["out"].attributes( "/plane" ) ) self.assertEqual( s["a2"]["out"].attributes( "/plane" )["shader"][-1].name, "test" )
def test(self): shader1 = GafferSceneTest.TestShader() shader2 = GafferSceneTest.TestShader() shader1["type"].setValue("test:surface") shader2["type"].setValue("test:surface") shader1["parameters"]["i"].setValue(1) shader2["parameters"]["i"].setValue(2) switch = GafferScene.ShaderSwitch() switch["in"].setInput(shader1["out"]) switch["in1"].setInput(shader2["out"]) assignment = GafferScene.ShaderAssignment() assignment["shader"].setInput(switch["out"]) sphere = GafferScene.Sphere() assignment["in"].setInput(sphere["out"]) self.assertEqual( assignment["out"].attributes("/sphere")["test:surface"] [0].parameters["i"].value, 1) switch["index"].setValue(1) self.assertEqual( assignment["out"].attributes("/sphere")["test:surface"] [0].parameters["i"].value, 2) switch["enabled"].setValue(False) self.assertEqual( assignment["out"].attributes("/sphere")["test:surface"] [0].parameters["i"].value, 1)
def testSwitch( self ) : n1 = GafferSceneTest.TestShader( "n1" ) n2 = GafferSceneTest.TestShader( "n2" ) n3 = GafferSceneTest.TestShader( "n3" ) n3["type"].setValue( "test:surface" ) switch = Gaffer.Switch() switch.setup( n3["parameters"]["c"] ) switch["in"][0].setInput( n1["out"] ) switch["in"][1].setInput( n2["out"] ) n3["parameters"]["c"].setInput( switch["out"] ) for i in range( 0, 3 ) : switch["index"].setValue( i ) effectiveIndex = i % 2 network = n3.attributes()["test:surface"] self.assertEqual( len( network ), 2 ) self.assertEqual( network.inputConnections( "n3" ), [ network.Connection( network.Parameter( "n{0}".format( effectiveIndex + 1 ), "", ), network.Parameter( "n3", "c" ) ) ] )
def testInputAcceptanceFromBoxes(self): s = Gaffer.ScriptNode() s["n"] = Gaffer.Node() s["n"]["out"] = Gaffer.Plug(direction=Gaffer.Plug.Direction.Out) s["a"] = GafferScene.ShaderAssignment() s["b"] = Gaffer.Box() s["b"]["n"] = Gaffer.Node() s["b"]["a"] = GafferScene.ShaderAssignment() s["b"]["n"]["out"] = Gaffer.Plug(direction=Gaffer.Plug.Direction.Out) # This emulates old plugs which were promoted when the "shader" plug on a ShaderAssignment # was just a plain Plug rather than a ShaderPlug. s["b"]["in"] = Gaffer.Plug(flags=Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic) s["b"]["out"] = Gaffer.Plug(flags=Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic, direction=Gaffer.Plug.Direction.Out) # Shader assignments should accept connections speculatively # from unconnected box inputs and outputs. We use `execute()` for # this because the backwards compatibility is provided only when # a script is loading. s.execute( """script["b"]["a"]["shader"].setInput( script["b"]["in"] )""") s.execute("""script["a"]["shader"].setInput( script["b"]["out"] )""") # but should reject connections to connected box inputs and outputs # if they're unsuitable. s["b"]["a"]["shader"].setInput(None) s["b"]["in"].setInput(s["n"]["out"]) self.assertFalse(s["b"]["a"]["shader"].acceptsInput(s["b"]["in"])) s["a"]["shader"].setInput(None) s["b"]["out"].setInput(s["b"]["n"]["out"]) self.assertFalse(s["a"]["shader"].acceptsInput(s["b"]["out"])) # and accept them again if they provide indirect access to a shader s["s"] = GafferSceneTest.TestShader() s["b"]["in"].setInput(s["s"]["out"]) self.assertTrue(s["b"]["a"]["shader"].acceptsInput(s["b"]["in"])) s["b"]["s"] = GafferSceneTest.TestShader() s["b"]["out"].setInput(s["b"]["s"]["out"]) self.assertTrue(s["a"]["shader"].acceptsInput(s["b"]["out"]))
def testConnect(self): plane = GafferScene.Plane() shader = GafferSceneTest.TestShader("surface") shader["type"].setValue("surface") planeFilter = GafferScene.PathFilter() planeFilter["paths"].setValue(IECore.StringVectorData(["/plane"])) assignment = GafferScene.ShaderAssignment() assignment["in"].setInput(plane["out"]) assignment["filter"].setInput(planeFilter["out"]) assignment["shader"].setInput(shader["out"]) originalNetwork = assignment["out"].attributes("/plane")["surface"] self.assertEqual(len(originalNetwork), 1) textureShader = GafferSceneTest.TestShader("texture") tweaks = GafferScene.ShaderTweaks() tweaks["in"].setInput(assignment["out"]) tweaks["filter"].setInput(planeFilter["out"]) tweaks["shader"].setValue("surface") tweaks["tweaks"].addChild( GafferScene.TweakPlug("c", Gaffer.Color3fPlug())) tweaks["tweaks"][0]["value"].setInput(textureShader["out"]) tweakedNetwork = tweaks["out"].attributes("/plane")["surface"] self.assertEqual(len(tweakedNetwork), 2) self.assertEqual(tweakedNetwork.input(("surface", "c")), ("texture", "")) tweakedNetwork.removeShader("texture") self.assertEqual(tweakedNetwork, originalNetwork) textureShader["parameters"]["c"].setValue(imath.Color3f(1, 2, 3)) tweakedNetwork = tweaks["out"].attributes("/plane")["surface"] self.assertEqual( tweakedNetwork.getShader("texture").parameters["c"].value, imath.Color3f(1, 2, 3)) tweaks["tweaks"][0]["mode"].setValue( GafferScene.TweakPlug.Mode.Multiply) with self.assertRaisesRegexp( RuntimeError, "Mode must be \"Replace\" when inserting a connection"): tweaks["out"].attributes("/plane")
def testProcessorNames( self ) : plane = GafferScene.Plane() planeFilter = GafferScene.PathFilter() planeFilter["paths"].setValue( IECore.StringVectorData( [ "/plane" ]) ) shader = GafferSceneTest.TestShader() shaderAssignment = GafferScene.ShaderAssignment() shaderAssignment["in"].setInput( plane["out"] ) shaderAssignment["filter"].setInput( planeFilter["out"] ) shaderAssignment["shader"].setInput( shader["out"] ) editScope = Gaffer.EditScope() editScope.setup( shaderAssignment["out"] ) editScope["in"].setInput( shaderAssignment["out"] ) for attributeName, processorName in [ ( "gl:surface", "OpenGLSurfaceEdits" ), ( "gl:light", "OpenGLLightEdits" ), ( "surface", "SurfaceEdits" ), ( "displacement", "DisplacementEdits" ), ( "test:lightFilter:one", "TestLightFilterOneEdits" ), ( "test:lightFilter:bigGobo", "TestLightFilterBigGoboEdits" ), ] : shader["type"].setValue( attributeName ) edit = GafferScene.EditScopeAlgo.acquireParameterEdit( editScope, "/plane", attributeName, ( "", "i" ) ) self.assertEqual( edit.node().getName(), processorName )
def testRegisterReferenceScene(self): s = Gaffer.ScriptNode() s["b"] = Gaffer.Box() s["b"]["shader"] = GafferScene.ShaderPlug( flags=Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic) s["b"]["out"] = GafferScene.ScenePlug( direction=Gaffer.Plug.Direction.Out, flags=Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic) s["b"]["cube"] = GafferScene.Cube() s["b"]["assignment"] = GafferScene.ShaderAssignment() s["b"]["assignment"]["in"].setInput(s["b"]["cube"]["out"]) s["b"]["assignment"]["shader"].setInput(s["b"]["shader"]) s["b"]["out"].setInput(s["b"]["assignment"]["out"]) s["b"].exportForReference(self.temporaryDirectory() + "/test.grf") GafferSceneUI.ShaderView.registerScene( "test", "Default", self.temporaryDirectory() + "/test.grf") shader = GafferSceneTest.TestShader() shader["type"].setValue("test:surface") shader["name"].setValue("test") view = GafferUI.View.create(shader["out"]) self.assertTrue(isinstance(view.scene(), Gaffer.Reference)) self.assertEqual(view.scene().fileName(), self.temporaryDirectory() + "/test.grf") self.assertEqual(view.scene()["out"].childNames("/"), IECore.InternedStringVectorData(["cube"]))
def testShaderTypesInState(self): surface = GafferSceneTest.TestShader("surface") surface["name"].setValue("testSurface") surface["type"].setValue("test:surface") surface["parameters"]["t"] = Gaffer.Color3fPlug() texture = GafferSceneTest.TestShader("texture") texture["name"].setValue("testTexture") texture["type"].setValue("test:shader") surface["parameters"]["t"].setInput(texture["out"]) state = surface.state() self.assertEqual(state[0].type, "test:shader") self.assertEqual(state[1].type, "test:surface")
def testPromoteTweaksPlug(self): box = Gaffer.Box() box["plane"] = GafferScene.Plane() box["shader"] = GafferSceneTest.TestShader() box["shader"]["type"].setValue("surface") box["planeFilter"] = GafferScene.PathFilter() box["planeFilter"]["paths"].setValue( IECore.StringVectorData(["/plane"])) box["assignment"] = GafferScene.ShaderAssignment() box["assignment"]["in"].setInput(box["plane"]["out"]) box["assignment"]["filter"].setInput(box["planeFilter"]["out"]) box["assignment"]["shader"].setInput(box["shader"]["out"]) box["tweaks"] = GafferScene.ShaderTweaks() box["tweaks"]["in"].setInput(box["assignment"]["out"]) box["tweaks"]["filter"].setInput(box["planeFilter"]["out"]) box["tweaks"]["shader"].setValue("surface") p = Gaffer.PlugAlgo.promote(box["tweaks"]["tweaks"]) p.addChild(GafferScene.TweakPlug("c", imath.Color3f(0.1, 5, 9))) network = box["tweaks"]["out"].attributes("/plane")["surface"] self.assertEqual( network.getShader("shader").parameters["c"].value, imath.Color3f(0.1, 5, 9))
def testGlobalContext(self): script = Gaffer.ScriptNode() script["shader"] = GafferSceneTest.TestShader() script["shader"]["type"].setValue("shader") script["expression"] = Gaffer.Expression() script["expression"].setExpression( 'parent["shader"]["parameters"]["i"] = 1 if context.get( "scene:path", None ) else 0' ) script["sphere"] = GafferScene.Sphere() script["filter"] = GafferScene.PathFilter() script["filter"]["paths"].setValue(IECore.StringVectorData(["/sphere" ])) script["assignment"] = GafferScene.ShaderAssignment() script["assignment"]["in"].setInput(script["sphere"]["out"]) script["assignment"]["filter"].setInput(script["filter"]["out"]) script["assignment"]["shader"].setInput(script["shader"]["out"]) self.assertEqual( script["assignment"]["out"].attributes("/sphere") ["shader"].outputShader().parameters["i"].value, 0)
def testReregisterScene(self): def shaderBallCreator(resolution): result = GafferScene.ShaderBall() result["resolution"].setValue(resolution) return result GafferSceneUI.ShaderView.registerScene( "test", "Default", functools.partial(shaderBallCreator, 16)) shader = GafferSceneTest.TestShader() shader["type"].setValue("test:surface") shader["name"].setValue("test") view = GafferUI.View.create(shader["out"]) scene1 = view.scene() self.assertEqual(view.scene()["resolution"].getValue(), 16) GafferSceneUI.ShaderView.registerScene( "test", "Default", functools.partial(shaderBallCreator, 32)) self.assertFalse(view.scene().isSame(scene1)) self.assertEqual(view.scene()["resolution"].getValue(), 32) GafferSceneUI.ShaderView.registerScene( "test", "HiRes", functools.partial(shaderBallCreator, 2048)) view["scene"].setValue("HiRes") self.assertEqual(view.scene()["resolution"].getValue(), 2048) GafferSceneUI.ShaderView.registerScene( "test", "HiRes", functools.partial(shaderBallCreator, 4096)) self.assertEqual(view.scene()["resolution"].getValue(), 4096)
def testComponentToComponentConnections(self): n1 = GafferSceneTest.TestShader("n1") n2 = GafferSceneTest.TestShader("n2") n2["type"].setValue("test:surface") n2["parameters"]["c"]["r"].setInput(n1["out"]["g"]) n2["parameters"]["c"]["g"].setInput(n1["out"]["b"]) n2["parameters"]["c"]["b"].setInput(n1["out"]["r"]) network = n2.attributes()["test:surface"] self.assertEqual(network.inputConnections("n2"), [ (("n1", "r"), ("n2", "c.b")), (("n1", "b"), ("n2", "c.g")), (("n1", "g"), ("n2", "c.r")), ])
def testNodeColorBlindData(self): s = GafferSceneTest.TestShader("test") s["type"].setValue("test:surface") h1 = s.attributesHash() s1 = s.attributes()["test:surface"] cs = GafferTest.CapturingSlot(s.plugDirtiedSignal()) Gaffer.Metadata.registerValue(s, "nodeGadget:color", imath.Color3f(1, 0, 0)) self.assertTrue(s["out"] in [x[0] for x in cs]) self.assertNotEqual(s.attributesHash(), h1) s2 = s.attributes()["test:surface"] self.assertNotEqual(s2, s1) self.assertEqual( s1.getShader("test").blindData()["gaffer:nodeColor"], IECore.Color3fData(imath.Color3f(0))) self.assertEqual( s2.getShader("test").blindData()["gaffer:nodeColor"], IECore.Color3fData(imath.Color3f(1, 0, 0)))
def __init__(self, name="ShaderAndAttributes"): GafferScene.FilteredSceneProcessor.__init__( self, name, filterDefault=IECore.PathMatcher.Result.NoMatch) self["__shader"] = GafferSceneTest.TestShader() self["__shader"]["type"].setValue("test:surface") self["__shaderAssignment"] = GafferScene.ShaderAssignment() self["__shaderAssignment"]["in"].setInput(self["in"]) self["__shaderAssignment"]["shader"].setInput( self["__shader"]["out"]) self["__shaderAssignment"]["filter"].setInput(self["filter"]) self["__shaderAssignment"]["enabled"].setInput(self["enabled"]) self["__attributes"] = GafferScene.StandardAttributes() self["__attributes"]["in"].setInput( self["__shaderAssignment"]["out"]) self["__attributes"]["enabled"].setInput(self["enabled"]) self["__attributes"]["filter"].setInput(self["filter"]) self["__attributes"]["attributes"]["doubleSided"][ "enabled"].setValue(True) self["__attributes"]["attributes"]["doubleSided"][ "value"].setValue(True) self["out"].setInput(self["__attributes"]["out"])
def testParameterEditLocalisation( self ) : sphere = GafferScene.Sphere() group = GafferScene.Group() group["in"][0].setInput( sphere["out"] ) groupFilter = GafferScene.PathFilter() groupFilter["paths"].setValue( IECore.StringVectorData( [ "/group" ] ) ) shader = GafferSceneTest.TestShader() shader["type"].setValue( "test:surface" ) shaderAssignment = GafferScene.ShaderAssignment() shaderAssignment["in"].setInput( group["out"] ) shaderAssignment["filter"].setInput( groupFilter["out"] ) shaderAssignment["shader"].setInput( shader["out"] ) editScope = Gaffer.EditScope() editScope.setup( shaderAssignment["out"] ) editScope["in"].setInput( shaderAssignment["out"] ) self.assertIn( "test:surface", editScope["out"].attributes( "/group" ) ) self.assertNotIn( "test:surface", editScope["out"].attributes( "/group/sphere" ) ) edit = GafferScene.EditScopeAlgo.acquireParameterEdit( editScope, "/group/sphere", "test:surface", ( "", "i" ) ) edit["enabled"].setValue( True ) edit["value"].setValue( 10 ) self.assertEqual( editScope["out"].attributes( "/group" ), editScope["in"].attributes( "/group" ) ) self.assertIn( "test:surface", editScope["out"].attributes( "/group/sphere" ) ) self.assertEqual( editScope["out"].attributes( "/group/sphere" )["test:surface"].outputShader().parameters["i"].value, 10 )
def testAssignShaderFromOutsideBox(self): s = Gaffer.ScriptNode() s["p"] = GafferScene.Plane() s["s"] = GafferSceneTest.TestShader() s["s"]["type"].setValue("test:surface") s["a"] = GafferScene.ShaderAssignment() s["a"]["in"].setInput(s["p"]["out"]) s["a"]["shader"].setInput(s["s"]["out"]) s["o"] = GafferScene.Options() s["o"]["in"].setInput(s["a"]["out"]) b = Gaffer.Box.create(s, Gaffer.StandardSet([s["p"], s["a"]])) self.assertTrue("test:surface" in s["o"]["out"].attributes("/plane")) ss = s.serialise() s = Gaffer.ScriptNode() s.execute(ss) self.assertTrue(s["Box"]["a"]["shader"].getInput().isSame( s["Box"]["shader"]))
def testFilter(self): sphere = IECore.SpherePrimitive() input = GafferSceneTest.CompoundObjectSource() input["in"].setValue( IECore.CompoundObject({ "bound": IECore.Box3fData(sphere.bound()), "children": { "ball1": { "object": sphere, "bound": IECore.Box3fData(sphere.bound()), }, "ball2": { "object": sphere, "bound": IECore.Box3fData(sphere.bound()), }, }, })) a = GafferScene.ShaderAssignment() a["in"].setInput(input["out"]) s = GafferSceneTest.TestShader() s["type"].setValue("test:surface") a["shader"].setInput(s["out"]) f = GafferScene.PathFilter() f["paths"].setValue(IECore.StringVectorData(["/ball1"])) a["filter"].setInput(f["out"]) self.assertEqual(a["out"].attributes("/"), IECore.CompoundObject()) self.assertNotEqual(a["out"].attributes("/ball1"), IECore.CompoundObject()) self.assertEqual(a["out"].attributes("/ball2"), IECore.CompoundObject())
def testInputAcceptanceFromDots( self ) : script = Gaffer.ScriptNode() script["a"] = GafferScene.ShaderAssignment() script["s"] = GafferSceneTest.TestShader() script["d"] = Gaffer.Dot() script["d"].setup( script["s"]["out"] ) # The Dot doesn't know about Shaders, and just has a Color3fPlug # input, so it should accept input from any old Color3fPlug, not # merely shader outputs. script["r"] = Gaffer.Random() self.assertTrue( script["d"]["in"].acceptsInput( script["r"]["outColor"] ) ) # And we should be able to connect the Dot into the # ShaderAssignment even if the Dot doesn't have an input # yet. The user should be able to wire the graph up in any # order, provided we end up with a valid network. script["a"]["shader"].setInput( script["d"]["out"] ) self.assertTrue( script["a"]["shader"].getInput().isSame( script["d"]["out"] ) ) # But once that is done, the Dot should reject # inputs that the ShaderAssignment can't handle. self.assertFalse( script["d"]["in"].acceptsInput( script["r"]["outColor"] ) ) # And only accept inputs from a Shader. self.assertTrue( script["d"]["in"].acceptsInput( script["s"]["out"] ) )
def testShaderTypesInAttributes(self): surface = GafferSceneTest.TestShader("surface") surface["name"].setValue("testSurface") surface["type"].setValue("test:surface") surface["parameters"]["t"] = Gaffer.Color3fPlug() texture = GafferSceneTest.TestShader("texture") texture["name"].setValue("testTexture") texture["type"].setValue("test:shader") surface["parameters"]["t"].setInput(texture["out"]) network = surface.attributes()["test:surface"] self.assertEqual(network[0].type, "test:shader") self.assertEqual(network[1].type, "test:surface")
def testApplyReturnValuesNetworkEdits(self): network = IECoreScene.ShaderNetwork(shaders={ "surface": IECoreScene.Shader("lambert", "surface", {"c": imath.Color3f(1.0)}) }, output="surface") textureShader = GafferSceneTest.TestShader("texture") tweaks = GafferScene.TweaksPlug() tweaks.addChild( GafferScene.TweakPlug("c", Gaffer.Color3fPlug(), GafferScene.TweakPlug.Mode.Replace, False)) tweaks[0]["value"].setInput(textureShader["out"]) # Test none to apply tweakedNetwork = network.copy() self.assertFalse(tweaks.applyTweaks(tweakedNetwork)) self.assertEqual(tweakedNetwork, network) # Test enabled tweaks[0]["enabled"].setValue(True) tweakedNetwork = network.copy() self.assertTrue(tweaks.applyTweaks(tweakedNetwork)) self.assertEqual(tweakedNetwork.inputConnections("surface"), [(("texture", ""), ("surface", "c"))])
def testReconnect(self): plane = GafferScene.Plane() shader = GafferSceneTest.TestShader("surface") shader["type"].setValue("surface") textureShader1 = GafferSceneTest.TestShader("texture1") shader["parameters"]["c"].setInput(textureShader1["out"]) planeFilter = GafferScene.PathFilter() planeFilter["paths"].setValue(IECore.StringVectorData(["/plane"])) assignment = GafferScene.ShaderAssignment() assignment["in"].setInput(plane["out"]) assignment["filter"].setInput(planeFilter["out"]) assignment["shader"].setInput(shader["out"]) originalNetwork = assignment["out"].attributes("/plane")["surface"] self.assertEqual(len(originalNetwork), 2) self.assertEqual(originalNetwork.input(("surface", "c")), ("texture1", "")) textureShader2 = GafferSceneTest.TestShader("texture2") tweaks = GafferScene.ShaderTweaks() tweaks["in"].setInput(assignment["out"]) tweaks["filter"].setInput(planeFilter["out"]) tweaks["shader"].setValue("surface") tweaks["tweaks"].addChild( GafferScene.TweakPlug("c", Gaffer.Color3fPlug())) tweaks["tweaks"][0]["value"].setInput(textureShader2["out"]) tweakedNetwork = tweaks["out"].attributes("/plane")["surface"] self.assertEqual(len(tweakedNetwork), 2) self.assertEqual(tweakedNetwork.input(("surface", "c")), ("texture2", "")) textureShader2["enabled"].setValue(False) tweakedNetwork = tweaks["out"].attributes("/plane")["surface"] self.assertEqual(len(tweakedNetwork), 1) self.assertFalse(tweakedNetwork.input(("surface", "c"))) textureShader2["enabled"].setValue(True) tweaks["tweaks"][0]["enabled"].setValue(False) self.assertEqual(tweaks["out"].attributes("/plane")["surface"], originalNetwork)
def testFactory(self): shader = GafferSceneTest.TestShader() shader["type"].setValue("test:surface") shader["name"].setValue("test") view = GafferUI.View.create(shader["out"]) self.assertTrue(isinstance(view, GafferSceneUI.ShaderView))
def testConnectSpecificOutputParameter(self): plane = GafferScene.Plane() shader = GafferSceneTest.TestShader("surface") shader["type"].setValue("surface") planeFilter = GafferScene.PathFilter() planeFilter["paths"].setValue(IECore.StringVectorData(["/plane"])) assignment = GafferScene.ShaderAssignment() assignment["in"].setInput(plane["out"]) assignment["filter"].setInput(planeFilter["out"]) assignment["shader"].setInput(shader["out"]) originalNetwork = assignment["out"].attributes("/plane")["surface"] self.assertEqual(len(originalNetwork), 1) textureShader = GafferSceneTest.TestShader("texture") textureShader["out"] = Gaffer.Plug(direction=Gaffer.Plug.Direction.Out) textureShader["out"]["color"] = Gaffer.Color3fPlug( direction=Gaffer.Plug.Direction.Out) textureShader["out"]["opacity"] = Gaffer.Color3fPlug( direction=Gaffer.Plug.Direction.Out) tweaks = GafferScene.ShaderTweaks() tweaks["in"].setInput(assignment["out"]) tweaks["filter"].setInput(planeFilter["out"]) tweaks["shader"].setValue("surface") tweaks["tweaks"].addChild( GafferScene.TweakPlug("c", Gaffer.Color3fPlug())) tweaks["tweaks"][0]["value"].setInput(textureShader["out"]["opacity"]) tweakedNetwork = tweaks["out"].attributes("/plane")["surface"] self.assertEqual(len(tweakedNetwork), 2) self.assertEqual(tweakedNetwork.input(("surface", "c")), ("texture", "opacity")) tweakedNetwork.removeShader("texture") self.assertEqual(tweakedNetwork, originalNetwork) textureShader["parameters"]["c"].setValue(imath.Color3f(1, 2, 3)) tweakedNetwork = tweaks["out"].attributes("/plane")["surface"] self.assertEqual( tweakedNetwork.getShader("texture").parameters["c"].value, imath.Color3f(1, 2, 3))