Пример #1
0
    def testDeleteRemovesPromotedPlugs(self):

        s = Gaffer.ScriptNode()

        s["b"] = Gaffer.Box()
        s["b"]["n"] = GafferTest.AddNode()

        s["b"]["i"] = Gaffer.BoxIn()
        s["b"]["i"]["name"].setValue("op1")
        s["b"]["i"].setup(s["b"]["n"]["op1"])
        s["b"]["n"]["op1"].setInput(s["b"]["i"]["out"])

        self.assertTrue("op1" in s["b"])
        self.assertTrue(s["b"]["n"]["op1"].source().isSame(s["b"]["op1"]))

        with Gaffer.UndoScope(s):
            del s["b"]["i"]

        self.assertFalse("op1" in s["b"])
        self.assertTrue(s["b"]["n"]["op1"].getInput() is None)

        s.undo()

        self.assertTrue("op1" in s["b"])
        self.assertTrue(s["b"]["n"]["op1"].source().isSame(s["b"]["op1"]))
Пример #2
0
    def testCreateWithBoxIOInSelection(self):

        s = Gaffer.ScriptNode()

        # Make a Box containing BoxIn -> n -> BoxOut

        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"]["o"]["name"].setValue("sum")
        s["b"]["o"].setup(s["b"]["n"]["sum"])
        s["b"]["o"]["in"].setInput(s["b"]["n"]["sum"])

        # 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.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"]))
Пример #3
0
	def testLoadPromotedChildrenPlug( self ) :

		s = Gaffer.ScriptNode()

		s["b1"] = Gaffer.Box()
		s["b1"]["p"] = GafferScene.Parent()
		Gaffer.PlugAlgo.promote( s["b1"]["p"]["children"] )

		s["b2"] = Gaffer.Box()
		s["b2"]["p"] = GafferScene.Parent()
		s["b2"]["pi"] = Gaffer.BoxIn()
		s["b2"]["pi"].setup( s["b2"]["p"]["children"] )
		s["b2"]["p"]["children"].setInput( s["b2"]["pi"]["out"] )

		s2 = Gaffer.ScriptNode()
		s2.execute( s.serialise() )

		self.assertEqual(
			s["b1"]["p"]["children"].getInput().fullName(),
			s2["b1"]["p"]["children"].getInput().fullName()
		)

		self.assertEqual(
			s["b2"]["p"]["children"].getInput().fullName(),
			s2["b2"]["p"]["children"].getInput().fullName()
		)
Пример #4
0
    def testPassThrough(self):

        s = Gaffer.ScriptNode()
        s["b"] = Gaffer.Box()
        s["b"]["a"] = GafferTest.AddNode()

        s["b"]["i"] = Gaffer.BoxIn()
        s["b"]["i"].setup(s["b"]["a"]["op1"])

        s["b"]["o"] = Gaffer.BoxOut()
        s["b"]["o"].setup(s["b"]["a"]["op1"])
        self.assertTrue(isinstance(s["b"]["o"]["passThrough"], Gaffer.IntPlug))
        self.assertFalse(s["b"]["o"]["passThrough"].acceptsInput(
            s["b"]["a"]["sum"]))

        s["b"]["a"]["op1"].setInput(s["b"]["i"]["out"])
        s["b"]["o"]["in"].setInput(s["b"]["a"]["sum"])
        s["b"]["o"]["passThrough"].setInput(s["b"]["i"]["out"])

        self.assertTrue("enabled" in s["b"])
        self.assertEqual(s["b"]["out"].source(), s["b"]["a"]["sum"])
        s["b"]["enabled"].setValue(False)
        self.assertEqual(s["b"]["out"].source(), s["b"]["in"])

        self.assertEqual(s["b"].correspondingInput(s["b"]["out"]),
                         s["b"]["in"])
Пример #5
0
    def testNameTracking(self):

        s = Gaffer.ScriptNode()
        s["b"] = Gaffer.Box()
        s["b"]["n"] = GafferTest.AddNode()

        s["b"]["i"] = Gaffer.BoxIn()
        s["b"]["i"]["name"].setValue("test")
        s["b"]["i"].setup(s["b"]["n"]["op1"])
        promoted = s["b"]["i"].promotedPlug()

        self.assertEqual(s["b"]["i"]["name"].getValue(), "test")
        self.assertEqual(promoted.getName(), s["b"]["i"]["name"].getValue())

        with Gaffer.UndoScope(s):
            promoted.setName("bob")

        self.assertEqual(promoted.getName(), "bob")
        self.assertEqual(s["b"]["i"]["name"].getValue(), "bob")

        s.undo()

        self.assertEqual(s["b"]["i"]["name"].getValue(), "test")
        self.assertEqual(promoted.getName(), s["b"]["i"]["name"].getValue())

        with Gaffer.UndoScope(s):
            s["b"]["i"]["name"].setValue("jim")

        self.assertEqual(promoted.getName(), "jim")
        self.assertEqual(s["b"]["i"]["name"].getValue(), "jim")

        s.undo()

        self.assertEqual(s["b"]["i"]["name"].getValue(), "test")
        self.assertEqual(promoted.getName(), s["b"]["i"]["name"].getValue())
Пример #6
0
    def testMetadata(self):

        s = Gaffer.ScriptNode()
        s["b1"] = Gaffer.Box()
        s["b1"]["n"] = GafferTest.AddNode()

        Gaffer.Metadata.registerValue(s["b1"]["n"]["op1"], "test", "testValue")
        Gaffer.Metadata.registerValue(s["b1"]["n"]["op1"], "layout:section",
                                      "sectionName")

        s["b1"]["i"] = Gaffer.BoxIn()
        s["b1"]["i"].setup(s["b1"]["n"]["op1"])

        self.assertEqual(
            Gaffer.Metadata.value(s["b1"]["i"].promotedPlug(), "test"),
            "testValue")
        self.assertNotIn(
            "layout:section",
            Gaffer.Metadata.registeredValues(s["b1"]["i"].promotedPlug(),
                                             instanceOnly=True))

        s["b2"] = Gaffer.Box()
        s.execute(
            s.serialise(parent=s["b1"],
                        filter=Gaffer.StandardSet([s["b1"]["i"]])),
            parent=s["b2"],
        )

        self.assertEqual(
            Gaffer.Metadata.value(s["b2"]["i"].promotedPlug(), "test"),
            "testValue")
        self.assertNotIn(
            "layout:section",
            Gaffer.Metadata.registeredValues(s["b2"]["i"].promotedPlug(),
                                             instanceOnly=True))
Пример #7
0
    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"]))
Пример #8
0
    def testPlugMetadataSerialisation(self):

        s1 = Gaffer.ScriptNode()
        s1["b"] = Gaffer.BoxIn()
        s1["b"].setup(Gaffer.IntPlug())

        Gaffer.Metadata.registerValue(s1["b"]["out"], "test", 1)

        s2 = Gaffer.ScriptNode()
        s2.execute(s1.serialise())

        self.assertEqual(Gaffer.Metadata.value(s2["b"]["out"], "test"), 1)
Пример #9
0
    def testSerialisationUsesSetup(self):

        s = Gaffer.ScriptNode()

        s["b"] = Gaffer.BoxIn()
        s["b"].setup(Gaffer.IntPlug())

        ss = s.serialise()
        self.assertIn("setup", ss)
        self.assertNotIn("setInput", ss)
        self.assertNotIn("__in", ss)
        self.assertEqual(ss.count("addChild"), 1)
Пример #10
0
    def testDuplicateNames(self):

        b = Gaffer.Box()
        b["n1"] = GafferTest.AddNode()
        b["n2"] = GafferTest.AddNode()

        b["i1"] = Gaffer.BoxIn()
        b["i2"] = Gaffer.BoxIn()

        b["i1"].setup(b["n1"]["op1"])
        b["i2"].setup(b["n2"]["op1"])

        self.assertEqual(b["i1"].promotedPlug().getName(), "in")
        self.assertEqual(b["i1"]["name"].getValue(), "in")

        self.assertEqual(b["i2"].promotedPlug().getName(), "in1")
        self.assertEqual(b["i2"]["name"].getValue(), "in1")

        b["i2"]["name"].setValue("in")
        self.assertEqual(b["i2"].promotedPlug().getName(), "in1")
        self.assertEqual(b["i2"]["name"].getValue(), "in1")
Пример #11
0
	def testNoduleSectionMetadata( self ) :

		s = Gaffer.ScriptNode()
		s["b"] = Gaffer.Box()
		s["b"]["n"] = GafferTest.AddNode()

		Gaffer.Metadata.registerValue( s["b"]["n"]["op1"], "noduleLayout:section", "left" )

		s["b"]["i"] = Gaffer.BoxIn()
		s["b"]["i"].setup( s["b"]["n"]["op1"] )

		self.assertEqual( Gaffer.Metadata.value( s["b"]["i"].promotedPlug(), "noduleLayout:section" ), "left" )
		self.assertEqual( Gaffer.Metadata.value( s["b"]["i"].plug(), "noduleLayout:section" ), "right" )
Пример #12
0
    def testCopyBareNodesIntoNewBox(self):

        s = Gaffer.ScriptNode()
        s["b1"] = Gaffer.Box()
        s["b1"]["i"] = Gaffer.BoxIn()
        s["b1"]["o"] = Gaffer.BoxOut()

        s["b2"] = Gaffer.Box()
        s.execute(s.serialise(parent=s["b1"]), parent=s["b2"])

        self.assertEqual(s["b2"].keys(), s["b1"].keys())
        self.assertEqual(s["b2"]["i"].keys(), s["b1"]["i"].keys())
        self.assertEqual(s["b2"]["o"].keys(), s["b1"]["o"].keys())
Пример #13
0
    def testSerialisationWithReferenceSibling(self):

        s1 = Gaffer.ScriptNode()

        s1["b"] = Gaffer.Box()
        s1["b"]["i"] = Gaffer.BoxIn()
        s1["b"]["i"].setup(Gaffer.IntPlug())

        s1["r"] = Gaffer.Reference()
        s1["r"].load(os.path.dirname(__file__) + "/references/empty.grf")

        s2 = Gaffer.ScriptNode()
        s2.execute(s1.serialise())

        self.assertEqual(s1["b"].keys(), s2["b"].keys())
Пример #14
0
    def testSetup(self):

        s = Gaffer.ScriptNode()
        s["b"] = Gaffer.Box()
        s["b"]["n"] = GafferTest.AddNode()

        s["b"]["i"] = Gaffer.BoxIn()
        self.assertEqual(s["b"]["i"]["name"].getValue(), "in")
        self.assertEqual(s["b"]["i"]["name"].defaultValue(), "in")

        s["b"]["i"]["name"].setValue("op1")
        s["b"]["i"].setup(s["b"]["n"]["op1"])
        s["b"]["n"]["op1"].setInput(s["b"]["i"]["out"])

        self.assertTrue("op1" in s["b"])
        self.assertTrue(s["b"]["n"]["op1"].source().isSame(s["b"]["op1"]))
Пример #15
0
    def testArrayPlugSerialisation(self):

        s = Gaffer.ScriptNode()

        s["b"] = Gaffer.Box()
        s["b"]["n"] = GafferTest.ArrayPlugNode()

        s["b"]["i"] = Gaffer.BoxIn()
        s["b"]["i"]["name"].setValue("in")
        s["b"]["i"].setup(s["b"]["n"]["in"])
        s["b"]["n"]["in"].setInput(s["b"]["i"]["out"])

        s2 = Gaffer.ScriptNode()
        s2.execute(s.serialise())

        self.assertTrue(s2["b"]["n"]["in"].source().isSame(s2["b"]["in"]))
Пример #16
0
    def testNonSerialisableInput(self):

        s = Gaffer.ScriptNode()
        s["a"] = GafferTest.AddNode()
        s["a"]["sum"].setFlags(Gaffer.Plug.Flags.Serialisable, False)

        s["b"] = Gaffer.Box()
        s["b"]["i"] = Gaffer.BoxIn()
        s["b"]["i"].setup(s["a"]["sum"])

        s["b"]["i"].promotedPlug().setInput(s["a"]["sum"])

        self.assertTrue(s["b"]["i"]["out"].source().isSame(s["a"]["sum"]))

        s2 = Gaffer.ScriptNode()
        s2.execute(s.serialise())

        self.assertTrue(s2["b"]["i"]["out"].source().isSame(s2["a"]["sum"]))
Пример #17
0
    def testReloadWithBoxIO(self):

        s = Gaffer.ScriptNode()

        s["b"] = Gaffer.Box()
        s["b"]["a"] = GafferTest.AddNode()

        s["b"]["i"] = Gaffer.BoxIn()
        s["b"]["i"]["name"].setValue("in")
        s["b"]["i"].setup(s["b"]["a"]["op1"])
        s["b"]["a"]["op1"].setInput(s["b"]["i"]["out"])

        s["b"]["o"] = Gaffer.BoxOut()
        s["b"]["o"]["name"].setValue("out")
        s["b"]["o"].setup(s["b"]["a"]["sum"])
        s["b"]["o"]["in"].setInput(s["b"]["a"]["sum"])

        referenceFileName = self.temporaryDirectory() + "/test.grf"
        s["b"].exportForReference(referenceFileName)

        s["a1"] = GafferTest.AddNode()

        s["r"] = Gaffer.Reference()
        s["r"].load(referenceFileName)
        s["r"]["in"].setInput(s["a1"]["sum"])

        s["a2"] = GafferTest.AddNode()
        s["a2"]["op1"].setInput(s["r"]["out"])

        def assertReferenceConnections():

            self.assertTrue(s["a2"]["op1"].source().isSame(s["r"]["a"]["sum"]))
            self.assertTrue(s["r"]["a"]["op1"].source().isSame(s["a1"]["sum"]))

            self.assertEqual(
                set(s["r"].keys()),
                set(["in", "out", "user", "a", "i", "o"]),
            )

        assertReferenceConnections()

        s["r"].load(referenceFileName)

        assertReferenceConnections()
Пример #18
0
	def testPaste( self ) :

		s = Gaffer.ScriptNode()
		s["b1"] = Gaffer.Box()
		s["b1"]["n"] = GafferTest.AddNode()

		s["b1"]["i"] = Gaffer.BoxIn()
		s["b1"]["i"]["name"].setValue( "test" )
		s["b1"]["i"].setup( s["b1"]["n"]["op1"] )
		s["b1"]["n"]["op1"].setInput( s["b1"]["i"]["out"] )

		s["b2"] = Gaffer.Box()
		s.execute(
			s.serialise( parent = s["b1"], filter = Gaffer.StandardSet( [ s["b1"]["n"], s["b1"]["i"] ] ) ),
			parent = s["b2"],
		)

		self.assertTrue( "test" in s["b2"] )
		self.assertTrue( s["b2"]["n"]["op1"].source().isSame( s["b2"]["test"] ) )
Пример #19
0
    def testUndoCreation(self):

        s = Gaffer.ScriptNode()

        s["b"] = Gaffer.Box()
        s["a"] = GafferTest.AddNode()

        def assertPreconditions():

            self.assertEqual(len(s["b"].children(Gaffer.Node)), 0)
            self.assertEqual(len(s["b"].children(Gaffer.Plug)), 1)
            self.assertEqual(len(s["a"]["sum"].outputs()), 0)

        assertPreconditions()

        with Gaffer.UndoScope(s):

            s["b"]["i"] = Gaffer.BoxIn()
            s["b"]["i"].setup(s["a"]["sum"])
            s["b"]["i"].promotedPlug().setInput(s["a"]["sum"])

        def assertPostconditions():

            self.assertEqual(len(s["b"].children(Gaffer.Node)), 1)
            self.assertEqual(len(s["b"].children(Gaffer.Plug)), 2)
            self.assertTrue(isinstance(s["b"]["i"], Gaffer.BoxIn))
            self.assertTrue(s["b"]["i"]["out"].source().isSame(s["a"]["sum"]))

        assertPostconditions()

        s.undo()
        assertPreconditions()

        s.redo()
        assertPostconditions()

        s.undo()
        assertPreconditions()

        s.redo()
        assertPostconditions()
Пример #20
0
	def testCorrespondingInputWithBoxIO( self ) :

		b = Gaffer.Box()

		b["a"] = GafferTest.AddNode()
		b["i"] = Gaffer.BoxIn()
		b["i"].setup( b["a"]["op1"] )
		b["a"]["op1"].setInput( b["i"].plug() )
		self.assertEqual( b["a"]["op1"].source(), b["i"].promotedPlug() )

		b["s"] = Gaffer.SwitchComputeNode()
		b["s"].setup( b["i"].plug() )
		b["s"]["in"][0].setInput( b["i"].plug() )
		b["s"]["in"][1].setInput( b["a"]["sum"] )

		Gaffer.PlugAlgo.promote( b["s"]["enabled"] )

		b["o"] = Gaffer.BoxOut()
		b["o"].setup( b["s"]["out"] )
		b["o"].plug().setInput( b["s"]["out"] )

		self.assertEqual( b.correspondingInput( b["o"].promotedPlug() ), b["i"].promotedPlug() )
Пример #21
0
    def testPromotedArrayPlugRemovalDeletesBoxIn(self):

        s = Gaffer.ScriptNode()

        s["b"] = Gaffer.Box()
        s["b"]["n"] = GafferTest.ArrayPlugNode()

        s["b"]["i"] = Gaffer.BoxIn()
        s["b"]["i"]["name"].setValue("in")
        s["b"]["i"].setup(s["b"]["n"]["in"])
        s["b"]["n"]["in"].setInput(s["b"]["i"]["out"])

        def assertPreconditions():

            self.assertTrue("in" in s["b"])
            self.assertTrue("i" in s["b"])
            self.assertTrue(len(s["b"]["i"]["out"].outputs()), 1)
            self.assertTrue(s["b"]["n"]["in"].source().isSame(s["b"]["in"]))

        assertPreconditions()

        with Gaffer.UndoScope(s):
            del s["b"]["in"]

        def assertPostconditions():

            self.assertFalse("in" in s["b"])
            self.assertFalse("i" in s["b"])
            self.assertTrue(s["b"]["n"]["in"].getInput() is None)

        assertPostconditions()

        s.undo()

        assertPreconditions()

        s.redo()

        assertPostconditions()
Пример #22
0
	def testBrokenInternalConnection( self ) :

		e = Gaffer.EditScope()
		e.setup( Gaffer.IntPlug() )

		p = e.acquireProcessor( "Test" )
		self.assertEqual( e.processors(), [ p ] )

		p["in"].setInput( None )
		with six.assertRaisesRegex( self, RuntimeError, "Output not linked to input" ) :
			e.processors()

		with six.assertRaisesRegex( self, RuntimeError, "Output not linked to input" ) :
			e.acquireProcessor( "Test" )

		# Check internal connections of children

		box = Gaffer.Box()
		box["BoxIn"] = Gaffer.BoxIn()
		box["BoxOut"] = Gaffer.BoxOut()
		box["BoxIn"].setup( e["in"] )
		box["BoxOut"].setup( e["out"] )

		e["b"] = box
		e["b"]["in"].setInput( e["BoxIn"]["out"] )
		e["BoxOut"]["in"].setInput( e["b"]["out"] )

		with six.assertRaisesRegex( self, RuntimeError, "Node 'b' has no corresponding input" ) :
			e.processors()

		box["BoxOut"]["in"].setInput( box["BoxIn"]["out"] )

		with six.assertRaisesRegex( self, RuntimeError, "Node 'b' has no corresponding input" ) :
			e.processors()

		e["b"]["BoxOut"]["passThrough"].setInput( e["b"]["BoxIn"]["out"] )
		self.assertEqual( e.processors(), [] )
Пример #23
0
    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())
Пример #24
0
    def testManualSetup(self):

        # Because we used to serialise BoxIO nodes without nice `setup()` calls,
        # people have copied that in their own code and we have nasty manual setup
        # code like this in the wild. Make sure we can cope with it.

        box = Gaffer.Box()

        box["in"] = Gaffer.IntPlug(flags=Gaffer.Plug.Flags.Default
                                   | Gaffer.Plug.Flags.Dynamic)

        box["boxIn"] = Gaffer.BoxIn()
        box["boxIn"].addChild(
            Gaffer.IntPlug("__in",
                           flags=Gaffer.Plug.Flags.Default
                           | Gaffer.Plug.Flags.Dynamic))
        box["boxIn"].addChild(
            Gaffer.IntPlug("out",
                           direction=Gaffer.Plug.Direction.Out,
                           flags=Gaffer.Plug.Flags.Default
                           | Gaffer.Plug.Flags.Dynamic))
        box["boxIn"]["out"].setInput(box["boxIn"]["__in"])
        box["boxIn"]["__in"].setInput(box["in"])

        box["add"] = GafferTest.AddNode()
        box["add"]["op1"].setInput(box["boxIn"]["out"])
        box["add"]["op2"].setValue(2)

        box["boxOut"] = Gaffer.BoxOut()
        box["boxOut"].addChild(
            Gaffer.IntPlug("in",
                           flags=Gaffer.Plug.Flags.Default
                           | Gaffer.Plug.Flags.Dynamic))
        box["boxOut"].addChild(
            Gaffer.IntPlug("__out",
                           direction=Gaffer.Plug.Direction.Out,
                           flags=Gaffer.Plug.Flags.Default
                           | Gaffer.Plug.Flags.Dynamic))
        box["boxOut"]["__out"].setInput(box["boxOut"]["in"])
        box["boxOut"]["in"].setInput(box["add"]["sum"])

        box["out"] = Gaffer.IntPlug(direction=Gaffer.Plug.Direction.Out,
                                    flags=Gaffer.Plug.Flags.Default
                                    | Gaffer.Plug.Flags.Dynamic)
        box["out"].setInput(box["boxOut"]["__out"])

        box["in"].setValue(1)
        self.assertEqual(box["out"].getValue(), 3)

        self.assertIsNone(box.correspondingInput(box["out"]))

        # Also make sure that the new pass-through functionality is available, even
        # though the manual setup above omitted it.

        box["boxOut"]["passThrough"].setInput(box["boxIn"]["out"])
        self.assertEqual(box.correspondingInput(box["out"]), box["in"])

        box["enabled"].setValue(False)
        self.assertEqual(box["out"].getValue(), 1)

        box["enabled"].setValue(True)
        self.assertEqual(box["out"].getValue(), 3)
Пример #25
0
    def setup_materials(self):
        """
        Creates Materials, Shaders and sets Input values
        @return: None
        """
        x = time.time()
        shader_count = 0

        # Creates Materials
        for material in self.mtlx_doc.getMaterials():

            material_name = fix_str(material.getName())

            box_in = Gaffer.BoxIn()
            box_out = Gaffer.BoxOut()
            material_box = Gaffer.Box(material_name)

            # Creates shader reference nodes
            for shader_ref in material.getShaderRefs():

                shader_name = fix_str(shader_ref.getName())

                shader = GafferArnold.ArnoldShader(shader_name)
                shader.loadShader(shader_ref.getNodeString())

                shader_assignment = GafferScene.ShaderAssignment()
                shader_assignment['shader'].setInput(shader["out"])

                box_in.setup(shader_assignment["in"])
                box_out.setup(shader_assignment["out"])

                shader_assignment["in"].setInput(box_in["out"])
                box_out["in"].setInput(shader_assignment["out"])

                path_filter = GafferScene.PathFilter()
                shader_assignment['filter'].setInput(path_filter["out"])

                # Displacement Shader
                if shader_ref.getAttribute("context") == "displacementshader":
                    dsp_shader =  GafferArnold.ArnoldDisplacement()
                    shader_assignment['shader'].setInput(dsp_shader["out"])
                    dsp_shader['map'].setInput(shader["out"])
                    material_box.addChild(dsp_shader)

                material_box.addChild(shader)
                material_box.addChild(box_in)
                material_box.addChild(box_out)
                material_box.addChild(path_filter)
                material_box.addChild(shader_assignment)

                box_in.setupPromotedPlug()
                box_out.setupPromotedPlug()

                material_list = self.material_list()

                if material_list:
                    if material_box != material_list[-1]:
                        material_box["in"].setInput(material_list[-1]["out"])

                    material_list[0]["in"].setInput(self["in"])
                    self["out"].setInput(material_box["out"])

                self.addChild(material_box)

                # Sets shader reference input values
                for bind_input in shader_ref.getBindInputs():
                    value = bind_input.getValue()

                    if value is not None:

                        shader_parm = shader['parameters']
                        input_name = str(bind_input.getName())

                        if input_name in shader_parm:
                            self.set_input_value(shader_parm[input_name], value)

                # Create shader nodes
                for graph in shader_ref.traverseGraph(material):

                    node = graph.getUpstreamElement()

                    if node.isA(mx.Node):

                        shader_list = [i.getName() for i in material_box.children()
                                   if isinstance(i, GafferArnold.ArnoldShader)]

                        node_name = fix_str(node.getName())

                        if node_name not in shader_list:

                            shader = GafferArnold.ArnoldShader(node_name)
                            shader.loadShader(node.getCategory())
                            material_box.addChild(shader)
                            shader_count += 1

                            # Sets shader input values
                            for input_parm in node.getInputs():

                                input_name = str(input_parm.getName())

                                if shader is not None:

                                    shader_parm = shader['parameters']

                                    if input_name in shader_parm:

                                        value = input_parm.getValue()

                                        if value is not None:
                                            self.set_input_value(shader_parm[input_name], value)
        # Sets Connections
        for material in self.mtlx_doc.getMaterials():

            material_box = self[fix_str(material.getName())]

            for shader_ref in material.getShaderRefs():

                shader_name = fix_str(shader_ref.getName())
                shader = material_box[shader_name]
                shader_parm = shader['parameters']

                for bind_input in shader_ref.getBindInputs():

                    input_name = str(bind_input.getName())
                    output = bind_input.getConnectedOutput()

                    if output is not None:

                        node_name = fix_str(output.getNodeName())

                        if node_name:
                            if input_name in shader_parm:
                                self.set_input_connection(shader_parm[input_name],
                                                          material_box[node_name]["out"])

                for graph in shader_ref.traverseGraph():

                    shader_node = graph.getUpstreamElement()

                    if shader_node.isA(mx.Node):

                        shader_name = fix_str(shader_node.getName())
                        shader = material_box[shader_name]
                        shader_parm = shader['parameters']

                        for input_parm in shader_node.getInputs():

                            input_name = str(input_parm.getName())
                            node_name = fix_str(input_parm.getNodeName())

                            if node_name:
                                if input_name in shader_parm:

                                    channel_out = str(input_parm.getAttribute("channels"))
                                    self.set_input_connection(shader_parm[input_name],
                                                              material_box[node_name]["out"],
                                                              channel_out)

        logger.info("%s Loaded %d shaders in %.2f seconds" % (self.getName(), shader_count, time.time() - x))
Пример #26
0
	def testSetupNone( self ) :

		b = Gaffer.BoxIn()
		with self.assertRaisesRegexp( Exception, "Python argument types" ) :
			b.setup( None )
Пример #27
0
    def testSetupNoArgument(self):

        b = Gaffer.BoxIn()
        with six.assertRaisesRegex(self, Exception, "Python argument types"):
            b.setup()