def testAcceptsDots(self): sf = GafferScene.SetFilter() dot = Gaffer.Dot() dot.setup(sf["match"]) dot["in"].setInput(sf["match"]) uf = GafferScene.UnionFilter() self.assertTrue(uf["in"][0].acceptsInput(dot["out"])) dot["in"].setInput(None) self.assertTrue(uf["in"][0].acceptsInput(dot["out"])) uf["in"][0].setInput(dot["out"]) dot["in"].setInput(sf["match"]) a = GafferTest.AddNode() dot2 = Gaffer.Dot() dot2.setup(a["sum"]) dot2["in"].setInput(a["sum"]) self.assertFalse(uf["in"][0].acceptsInput(dot2["out"])) dot2["in"].setInput(None) self.assertTrue(uf["in"][0].acceptsInput(dot2["out"]))
def testPassThroughInputAcceptance(self): s = Gaffer.ScriptNode() s["a"] = GafferTest.AddNode() s["b"] = Gaffer.Box() s["b"]["a"] = GafferTest.AddNode() s["b"]["o"] = Gaffer.BoxOut() s["b"]["o"].setup(s["b"]["a"]["op1"]) # Don't accept input from any old node self.assertFalse(s["b"]["o"]["passThrough"].acceptsInput( s["b"]["a"]["sum"])) self.assertFalse(s["b"]["o"]["passThrough"].acceptsInput( s["a"]["sum"])) # Do accept input from BoxIn s["b"]["i"] = Gaffer.BoxIn() s["b"]["i"].setup(s["b"]["a"]["op1"]) self.assertTrue(s["b"]["o"]["passThrough"].acceptsInput( s["b"]["i"]["out"])) # Do accept input from unconnected Dot s["b"]["d"] = Gaffer.Dot() s["b"]["d"].setup(s["b"]["a"]["op1"]) self.assertTrue(s["b"]["o"]["passThrough"].acceptsInput( s["b"]["d"]["out"])) # And Dot connected to BoxIn s["b"]["d"]["in"].setInput(s["b"]["i"]["out"]) self.assertTrue(s["b"]["o"]["passThrough"].acceptsInput( s["b"]["d"]["out"])) # And Dot connected to unconnected Dot s["b"]["d2"] = Gaffer.Dot() s["b"]["d2"].setup(s["b"]["a"]["op1"]) s["b"]["d"]["in"].setInput(s["b"]["d2"]["out"]) self.assertTrue(s["b"]["o"]["passThrough"].acceptsInput( s["b"]["d"]["out"])) # But not Dot connected to something else s["b"]["d"]["in"].setInput(s["b"]["a"]["sum"]) self.assertFalse(s["b"]["o"]["passThrough"].acceptsInput( s["b"]["d"]["out"]))
def testCutAndPasteKeepsTangents(self): s = Gaffer.ScriptNode() s["n"] = GafferTest.AddNode() Gaffer.Metadata.registerValue(s["n"]["sum"], "nodeGadget:nodulePosition", "right") graphGadget = GafferUI.GraphGadget(s) s["d"] = Gaffer.Dot() s["d"].setup(s["n"]["sum"]) s["d"]["in"].setInput(s["n"]["sum"]) dotNodeGadget = graphGadget.nodeGadget(s["d"]) self.assertEqual( dotNodeGadget.noduleTangent(dotNodeGadget.nodule(s["d"]["in"])), IECore.V3f(-1, 0, 0)) s.execute(s.serialise(filter=Gaffer.StandardSet([s["n"], s["d"]]))) dot1NodeGadget = graphGadget.nodeGadget(s["d1"]) self.assertEqual( dot1NodeGadget.noduleTangent(dot1NodeGadget.nodule(s["d1"]["in"])), IECore.V3f(-1, 0, 0))
def testUndo( self ) : s = Gaffer.ScriptNode() s["n1"] = GafferTest.AddNode() s["n2"] = GafferTest.AddNode() s["d"] = Gaffer.Dot() self.assertTrue( "in" not in s["d"] ) self.assertTrue( "out" not in s["d"] ) with Gaffer.UndoScope( s ) : s["d"].setup( s["n2"]["op1"] ) s["d"]["in"].setInput( s["n1"]["sum"] ) s["n2"]["op1"].setInput( s["d"]["out"] ) self.assertTrue( s["n2"]["op1"].source().isSame( s["n1"]["sum"] ) ) s.undo() self.assertTrue( "in" not in s["d"] ) self.assertTrue( "out" not in s["d"] ) s.redo() self.assertTrue( s["n2"]["op1"].source().isSame( s["n1"]["sum"] ) )
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 __createLoop(node): edges = ["top", "right", "bottom", "left"] def opposite(edge): return edges[(edges.index(edge) + 2) % 4] def rotate(edge): return edges[(edges.index(edge) + 1) % 4] with Gaffer.UndoContext(node.scriptNode()): plug = node["previous"] edge = Gaffer.Metadata.value(plug, "noduleLayout:section") or "bottom" for i in range(0, 4): dot = Gaffer.Dot() dot.setup(plug) dot["in"].setInput(plug) node.parent().addChild(dot) edge = opposite(edge) Gaffer.Metadata.registerValue(dot["in"], "noduleLayout:section", edge) edge = rotate(edge) Gaffer.Metadata.registerValue(dot["out"], "noduleLayout:section", edge) plug = dot["out"] node["next"].setInput(plug)
def testArrayPlug( self ) : n1 = Gaffer.Node() n1["a"] = Gaffer.ArrayPlug( element = Gaffer.IntPlug() ) n2 = Gaffer.Node() n2["a"] = Gaffer.ArrayPlug( element = Gaffer.IntPlug() ) d = Gaffer.Dot() d.setup( n1["a"] ) d["in"].setInput( n1["a"] ) n2["a"].setInput( d["out"] ) self.assertEqual( len( d["out"] ), 1 ) self.assertTrue( d["out"].source().isSame( n1["a"] ) ) self.assertTrue( d["out"][0].source().isSame( n1["a"][0] ) ) i = Gaffer.IntPlug() n1["a"][0].setInput( i ) self.assertEqual( len( n1["a"] ), 2 ) self.assertEqual( len( d["in"] ), 2 ) self.assertEqual( len( d["out"] ), 2 ) self.assertTrue( d["out"].source().isSame( n1["a"] ) ) self.assertTrue( d["out"][0].source().isSame( i ) ) self.assertTrue( d["out"][1].source().isSame( n1["a"][1] ) )
def testAcceptsDot(self): object = GafferOSL.OSLImage() switch = GafferScene.ShaderSwitch() dot = Gaffer.Dot() dot.setup(switch["out"]) self.assertTrue(object["shader"].acceptsInput(dot["out"]))
def testInputAcceptanceFromDots(self): a = GafferScene.ShaderAssignment() s = GafferSceneTest.TestShader() d = Gaffer.Dot() d.setup(s["out"]) self.assertTrue(a["shader"].acceptsInput(d["out"]))
def testConnectDot(self): s = Gaffer.ScriptNode() s["n"] = GafferTest.AddNode() s["d"] = Gaffer.Dot() g = GafferUI.GraphGadget(s) g.getLayout().connectNode(g, s["d"], Gaffer.StandardSet([s["n"]])) self.assertTrue(s["d"]["out"].source().isSame(s["n"]["sum"]))
def testAcceptsDot( self ) : script = Gaffer.ScriptNode() script["image"] = GafferOSL.OSLImage() script["switch"] = GafferScene.ShaderSwitch() script["dot"] = Gaffer.Dot() script["dot"].setup( script["switch"]["out"] ) # We're testing a backwards compatibility special case that is # only enabled when loading a script, hence the use of `execute()`. script.execute( """script["image"]["shader"].setInput( script["dot"]["out"] )""" ) self.assertTrue( script["image"]["shader"].getInput().isSame( script["dot"]["out"] ) )
def testInputAcceptanceFromDots(self): e1 = GafferTest.TextWriter() e2 = GafferTest.TextWriter() d1 = Gaffer.Dot() d1.setup(e1["requirement"]) self.assertTrue(e2["requirements"][0].acceptsInput(d1["out"])) d1["in"].setInput(e1["requirement"]) self.assertTrue(e2["requirements"][0].acceptsInput(d1["out"]))
def testAcceptsDot( self ) : script = Gaffer.ScriptNode() script["object"] = GafferOSL.OSLObject() script["switch"] = Gaffer.Switch() script["switch"].setup( Gaffer.Plug() ) script["dot"] = Gaffer.Dot() script["dot"].setup( script["switch"]["out"] ) # We're testing a backwards compatibility special case that is # only enabled when loading a script, hence the use of `execute()`. script.execute( """script["object"]["shader"].setInput( script["dot"]["out"] )""" ) self.assertTrue( script["object"]["primitiveVariables"]["legacyClosure"]["value"].getInput().isSame( script["dot"]["out"] ) )
def testInputAcceptanceFromDots(self): e1 = GafferDispatchTest.TextWriter() e2 = GafferDispatchTest.TextWriter() d1 = Gaffer.Dot() d1.setup(e1["task"]) self.assertTrue(e2["preTasks"][0].acceptsInput(d1["out"])) d1["in"].setInput(e1["task"]) self.assertTrue(e2["preTasks"][0].acceptsInput(d1["out"]))
def testInputAcceptanceFromDots( self ) : script = Gaffer.ScriptNode() script["a"] = GafferScene.ShaderAssignment() script["s"] = GafferSceneTest.TestShader() script["d"] = Gaffer.Dot() script["d"].setup( script["s"]["out"] ) # Input only accepted during execution, for backwards compatibility # when loading old scripts. script.execute( """script["a"]["shader"].setInput( script["d"]["out"] )""" ) self.assertTrue( script["a"]["shader"].getInput().isSame( script["d"]["out"] ) )
def testPlugMetadataSerialisation( self ) : s1 = Gaffer.ScriptNode() s1["d"] = Gaffer.Dot() s1["d"].setup( Gaffer.IntPlug() ) Gaffer.Metadata.registerValue( s1["d"]["in"], "test", 1 ) Gaffer.Metadata.registerValue( s1["d"]["out"], "test", 2 ) s2 = Gaffer.ScriptNode() s2.execute( s1.serialise() ) self.assertEqual( Gaffer.Metadata.value( s2["d"]["in"], "test" ), 1 ) self.assertEqual( Gaffer.Metadata.value( s2["d"]["out"], "test" ), 2 )
def testDot(self): # n1 # | # d1 # | # n2 s = Gaffer.ScriptNode() s["n1"] = GafferDispatchTest.LoggingTaskNode() s["n1"]["frame"] = Gaffer.StringPlug( defaultValue="${frame}", flags=Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic ) s["n1"]["dispatcher"]["batchSize"].setValue(10) s["n2"] = GafferDispatchTest.LoggingTaskNode() s["n2"]["frame"] = Gaffer.StringPlug( defaultValue="${frame}", flags=Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic ) s["n2"]["dispatcher"]["batchSize"].setValue(13) s["d1"] = Gaffer.Dot() s["d1"].setup(s["n2"]["preTasks"][0]) s["d1"]["in"].setInput(s["n1"]["task"]) s["n2"]["preTasks"][0].setInput(s["d1"]["out"]) dispatcher = self.__dispatcher() dispatcher["framesMode"].setValue(dispatcher.FramesMode.CustomRange) dispatcher["frameRange"].setValue("1-50") with mock.patch( "GafferDeadline.DeadlineTools.submitJob", return_value=("testID", "testMessage") ): jobs = self.__job([s["n2"]], dispatcher) self.assertEqual(len(jobs), 2) for j in jobs: if j.getJobProperties()["Name"] == "n2": self.assertEqual(len(j.getDependencies()), 8) self.assertEqual(len(j.getTasks()), 4) elif j.getJobProperties()["Name"] == "n1": self.assertEqual(len(j.getDependencies()), 0) self.assertEqual(len(j.getTasks()), 5) self.assertEqual( j.getDependencyType(), GafferDeadline.GafferDeadlineJob.DeadlineDependencyType._None )
def test( self ) : s = Gaffer.ScriptNode() s["n1"] = GafferTest.AddNode() s["n2"] = GafferTest.AddNode() s["d"] = Gaffer.Dot() s["d"].setup( s["n2"]["op1"] ) s["d"]["in"].setInput( s["n1"]["sum"] ) s["n2"]["op1"].setInput( s["d"]["out"] ) self.assertTrue( s["n2"]["op1"].source().isSame( s["n1"]["sum"] ) )
def testHistoryIncludesConnections(self): plane = GafferScene.Plane() dot1 = Gaffer.Dot() dot1.setup(plane["out"]) dot1["in"].setInput(plane["out"]) standardOptions = GafferScene.StandardOptions() standardOptions["in"].setInput(dot1["out"]) dot2 = Gaffer.Dot() dot2.setup(standardOptions["out"]) dot2["in"].setInput(standardOptions["out"]) shaderAssignment = GafferScene.ShaderAssignment() shaderAssignment["in"].setInput(dot2["out"]) history = GafferScene.SceneAlgo.history( shaderAssignment["out"]["transform"], "/plane") for plug in [ shaderAssignment["out"], shaderAssignment["in"], dot2["out"], dot2["in"], standardOptions["out"], standardOptions["in"], dot1["out"], dot1["in"], plane["out"], ]: self.assertEqual(history.scene, plug) history = history.predecessors[0] if history.predecessors else None self.assertIsNone(history)
def testCorrespondingInputWithBoxOutAndDots(self): b = Gaffer.Box() b["n"] = GafferTest.AddNode() b["i"] = Gaffer.BoxIn() b["i"].setup(b["n"]["sum"]) b["n"]["op1"].setInput(b["i"]["out"]) b["d1"] = Gaffer.Dot() b["d1"].setup(b["n"]["sum"]) b["d1"]["in"].setInput(b["i"]["out"]) b["d2"] = Gaffer.Dot() b["d2"].setup(b["n"]["sum"]) b["d2"]["in"].setInput(b["d1"]["out"]) b["o"] = Gaffer.BoxOut() b["o"].setup(b["n"]["sum"]) b["o"]["in"].setInput(b["n"]["sum"]) b["o"]["passThrough"].setInput(b["d2"]["out"]) self.assertEqual(b.correspondingInput(b["o"].promotedPlug()), b["i"].promotedPlug())
def testDeletion( self ) : s = Gaffer.ScriptNode() s["n1"] = GafferTest.AddNode() s["n2"] = GafferTest.AddNode() s["d"] = Gaffer.Dot() s["d"].setup( s["n2"]["op1"] ) s["d"]["in"].setInput( s["n1"]["sum"] ) s["n2"]["op1"].setInput( s["d"]["out"] ) s.deleteNodes( filter = Gaffer.StandardSet( [ s["d"] ] ) ) self.assertTrue( s["n2"]["op1"].getInput().isSame( s["n1"]["sum"] ) )
def testCompatibilityWithIntPlugs(self): s = Gaffer.ScriptNode() s["p"] = GafferScene.PathFilter() s["d"] = Gaffer.Dot() s["d"].setup(Gaffer.IntPlug()) s["d"]["in"].setInput(s["p"]["out"]) s["s"] = GafferScene.FilterSwitch() s["s"]["in"][0].setInput(s["d"]["out"]) s["b"] = Gaffer.Box() s["b"]["filter"] = Gaffer.IntPlug() s["b"]["filter"].setInput(s["p"]["out"]) s["b"]["s"] = GafferScene.FilterSwitch() s["b"]["s"]["in"][0].setInput(s["b"]["filter"])
def testDefaultNoduleTangents( self ) : s = Gaffer.ScriptNode() s["n"] = GafferTest.AddNode() s["d"] = Gaffer.Dot() g = GafferUI.NodeGadget.create( s["d"] ) self.assertTrue( isinstance( g, GafferUI.DotNodeGadget ) ) s["d"].setup( s["n"]["op1"] ) self.assertTrue( g.nodule( s["d"]["in"] ) is not None ) self.assertTrue( g.nodule( s["d"]["out"] ) is not None ) self.assertEqual( g.noduleTangent( g.nodule( s["d"]["in"] ) ), IECore.V3f( 0, 1, 0 ) ) self.assertEqual( g.noduleTangent( g.nodule( s["d"]["out"] ) ), IECore.V3f( 0, -1, 0 ) )
def testSerialisation( self ) : s = Gaffer.ScriptNode() s["n1"] = GafferTest.AddNode() s["n2"] = GafferTest.AddNode() s["d"] = Gaffer.Dot() s["d"].setup( s["n2"]["op1"] ) s["d"]["in"].setInput( s["n1"]["sum"] ) s["n2"]["op1"].setInput( s["d"]["out"] ) s2 = Gaffer.ScriptNode() s2.execute( s.serialise() ) self.assertTrue( s2["n2"]["op1"].source().isSame( s2["n1"]["sum"] ) )
def testCreateWithBoxIOPassThroughInSelection(self): s = Gaffer.ScriptNode() # Make a Box containing BoxIn -> n -> BoxOut # and BoxIn -> dot -> BoxOut.passThrough s["b"] = Gaffer.Box() s["b"]["i"] = Gaffer.BoxIn() s["b"]["n"] = GafferTest.AddNode() s["b"]["o"] = Gaffer.BoxOut() s["b"]["i"]["name"].setValue("op1") s["b"]["i"].setup(s["b"]["n"]["op1"]) s["b"]["n"]["op1"].setInput(s["b"]["i"]["out"]) s["b"]["dot"] = Gaffer.Dot() s["b"]["dot"].setup(s["b"]["n"]["sum"]) s["b"]["dot"]["in"].setInput(s["b"]["i"]["out"]) s["b"]["o"]["name"].setValue("sum") s["b"]["o"].setup(s["b"]["n"]["sum"]) s["b"]["o"]["in"].setInput(s["b"]["n"]["sum"]) s["b"]["o"]["passThrough"].setInput(s["b"]["dot"]["out"]) # Ask to move all that (including the BoxIOs) into a # nested Box. This doesn't really make sense, because # the BoxIOs exist purely to build a bridge to the # outer parent. So we expect them to remain where they # were. innerBox = Gaffer.Box.create( s["b"], Gaffer.StandardSet(s["b"].children(Gaffer.Node))) self.assertEqual(len(innerBox.children(Gaffer.Node)), 1) self.assertTrue("n" in innerBox) self.assertFalse("n" in s["b"]) self.assertFalse("dot" in innerBox) self.assertTrue("dot" in s["b"]) self.assertTrue("i" in s["b"]) self.assertTrue("o" in s["b"]) self.assertTrue(s["b"]["sum"].source().isSame(innerBox["n"]["sum"])) self.assertTrue(innerBox["n"]["op1"].source().isSame(s["b"]["op1"])) self.assertTrue(s["b"]["o"]["passThrough"].source().isSame( s["b"]["i"].promotedPlug()))
def testSerialisationUsesSetup( self ) : s1 = Gaffer.ScriptNode() s1["d"] = Gaffer.Dot() s1["d"].setup( Gaffer.IntPlug() ) ss = s1.serialise() self.assertIn( "setup", ss ) self.assertEqual( ss.count( "addChild" ), 1 ) self.assertNotIn( "Dynamic", ss ) self.assertNotIn( "setInput", ss ) s2 = Gaffer.ScriptNode() s2.execute( ss ) self.assertIn( "in", s2["d"] ) self.assertIn( "out", s2["d"] ) self.assertIsInstance( s2["d"]["in"], Gaffer.IntPlug ) self.assertIsInstance( s2["d"]["out"], Gaffer.IntPlug )
def testCustomNoduleTangentsFromInput( self ) : s = Gaffer.ScriptNode() s["n"] = GafferTest.AddNode() Gaffer.Metadata.registerValue( s["n"]["sum"], "noduleLayout:section", "right" ) s["d"] = Gaffer.Dot() g = GafferUI.NodeGadget.create( s["d"] ) s["d"].setup( s["n"]["sum"] ) self.assertTrue( g.nodule( s["d"]["in"] ) is not None ) self.assertTrue( g.nodule( s["d"]["out"] ) is not None ) self.assertEqual( g.noduleTangent( g.nodule( s["d"]["in"] ) ), IECore.V3f( -1, 0, 0 ) ) self.assertEqual( g.noduleTangent( g.nodule( s["d"]["out"] ) ), IECore.V3f( 1, 0, 0 ) )
def testCustomNoduleTangentsFromOutput( self ) : s = Gaffer.ScriptNode() s["n"] = GafferTest.AddNode() Gaffer.Metadata.registerPlugValue( s["n"]["op1"], "nodeGadget:nodulePosition", "left" ) s["d"] = Gaffer.Dot() g = GafferUI.NodeGadget.create( s["d"] ) s["d"].setup( s["n"]["op1"] ) self.assertTrue( g.nodule( s["d"]["in"] ) is not None ) self.assertTrue( g.nodule( s["d"]["out"] ) is not None ) self.assertEqual( g.noduleTangent( g.nodule( s["d"]["in"] ) ), IECore.V3f( -1, 0, 0 ) ) self.assertEqual( g.noduleTangent( g.nodule( s["d"]["out"] ) ), IECore.V3f( 1, 0, 0 ) )
def testSerialisationWithNonSerialisableConnections( self ) : s = Gaffer.ScriptNode() s["n1"] = GafferTest.AddNode() s["n2"] = GafferTest.AddNode() s["n1"]["sum"].setFlags( Gaffer.Plug.Flags.Serialisable, False ) s["d"] = Gaffer.Dot() s["d"].setup( s["n1"]["sum"] ) s["d"]["in"].setInput( s["n1"]["sum"] ) s["n2"]["op1"].setInput( s["d"]["out"] ) s2 = Gaffer.ScriptNode() s2.execute( s.serialise() ) self.assertTrue( s2["n2"]["op1"].source().isSame( s2["n1"]["sum"] ) )
def testFilterInputAcceptanceFromReferencesViaDot( self ) : s = Gaffer.ScriptNode() s["b"] = Gaffer.Box() s["b"]["a"] = GafferScene.ShaderAssignment() s["b"]["d"] = Gaffer.Dot() s["b"]["d"].setup( s["b"]["a"]["filter"] ) s["b"]["a"]["filter"].setInput( s["b"]["d"]["out"] ) p = Gaffer.PlugAlgo.promote( s["b"]["d"]["in"] ) s["b"].exportForReference( self.temporaryDirectory() + "/test.grf" ) s["r"] = Gaffer.Reference() s["r"].load( self.temporaryDirectory() + "/test.grf" ) self.assertTrue( s["r"]["a"]["filter"].source().isSame( s["r"][p.getName()] ) ) s["f"] = GafferScene.PathFilter() s["r"][p.getName()].setInput( s["f"]["out"] )