Example #1
0
    def testPartialConnectionSerialisation(self):

        s = IECore.Splineff(IECore.CubicBasisf.catmullRom(), (
            (0, 0),
            (0, 0),
            (0.2, 0.3),
            (0.4, 0.9),
            (1, 1),
            (1, 1),
        ))

        script = Gaffer.ScriptNode()
        script["n"] = Gaffer.Node()
        script["n"]["user"]["s"] = Gaffer.SplineffPlug(
            defaultValue=s,
            flags=Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic)
        script["n"]["user"]["x"] = Gaffer.FloatPlug(
            flags=Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic)
        script["n"]["user"]["y"] = Gaffer.FloatPlug(
            flags=Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic)

        script["n"]["user"]["s"].pointXPlug(0).setInput(
            script["n"]["user"]["x"])
        script["n"]["user"]["s"].pointYPlug(2).setInput(
            script["n"]["user"]["y"])

        def assertConnection(script):

            self.assertTrue(script["n"]["user"]["s"].getInput() is None)
            self.assertTrue(
                script["n"]["user"]["s"]["basis"].getInput() is None)
            for i in range(0, 4):

                if i == 0:
                    self.assertTrue(script["n"]["user"]["s"].pointXPlug(
                        i).getInput().isSame(script["n"]["user"]["x"]))
                else:
                    self.assertTrue(script["n"]["user"]["s"].pointXPlug(
                        i).getInput() is None)

                if i == 2:
                    self.assertTrue(script["n"]["user"]["s"].pointYPlug(
                        i).getInput().isSame(script["n"]["user"]["y"]))
                else:
                    self.assertTrue(script["n"]["user"]["s"].pointYPlug(
                        i).getInput() is None)

        assertConnection(script)

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

        assertConnection(script2)
Example #2
0
	def testFloatPlugs( self ) :

		s = Gaffer.ScriptNode()
		s["n"] = Gaffer.Node()
		s["n"]["user"]["i"] = Gaffer.FloatPlug( flags = Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic )
		s["n"]["user"]["o"] = Gaffer.FloatPlug( flags = Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic )

		s["e"] = Gaffer.Expression()
		s["e"].setExpression( "parent.n.user.o = parent.n.user.i + 1;", "OSL" )

		s["n"]["user"]["i"].setValue( 1 )
		self.assertEqual( s["n"]["user"]["o"].getValue(), 2 )
	def __init__( self, name = "_Camera" ) :

		Gaffer.Node.__init__( self, name )

		self["in"] = GafferScene.ScenePlug()
		self["addCamera"] = Gaffer.BoolPlug( defaultValue = False )
		self["lookAt"] = Gaffer.StringPlug( defaultValue = "/" )
		self["depth"] = Gaffer.FloatPlug( defaultValue = 20, minValue = 0 )
		self["angle"] = Gaffer.FloatPlug()
		self["elevation"] = Gaffer.FloatPlug( defaultValue = 10, minValue = -90, maxValue = 90 )

		self["camera"] = GafferScene.Camera()
		self["camera"]["name"].setValue( "previewCamera" )

		self["parent"] = GafferScene.Parent()
		self["parent"]["in"].setInput( self["in"] )
		self["parent"]["parent"].setValue( "/" )
		self["parent"]["child"].setInput( self["camera"]["out"] )

		self["cameraFilter"] = GafferScene.PathFilter()
		self["cameraFilter"]["paths"].setValue( IECore.StringVectorData( [ "/previewCamera" ] ) )

		self["parentConstraint"] = GafferScene.ParentConstraint()
		self["parentConstraint"]["in"].setInput( self["parent"]["out"] )
		self["parentConstraint"]["target"].setInput( self["lookAt"] )
		self["parentConstraint"]["targetMode"].setValue( self["parentConstraint"].TargetMode.BoundCenter )
		self["parentConstraint"]["filter"].setInput( self["cameraFilter"]["out"] )

		self["cameraRotate"] = GafferScene.Transform()
		self["cameraRotate"]["in"].setInput( self["parentConstraint"]["out"] )
		self["cameraRotate"]["transform"]["rotate"]["y"].setInput( self["angle"] )
		self["cameraRotate"]["filter"].setInput( self["cameraFilter"]["out"] )

		self["elevationExpression"] = Gaffer.Expression()
		self["elevationExpression"].setExpression( 'parent["cameraRotate"]["transform"]["rotate"]["x"] = -parent["elevation"]' )

		self["cameraTranslate"] = GafferScene.Transform()
		self["cameraTranslate"]["in"].setInput( self["cameraRotate"]["out"] )
		self["cameraTranslate"]["transform"]["translate"]["z"].setInput( self["depth"] )
		self["cameraTranslate"]["filter"].setInput( self["cameraFilter"]["out"] )

		self["options"] = GafferScene.StandardOptions()
		self["options"]["options"]["renderCamera"]["enabled"].setValue( True )
		self["options"]["options"]["renderCamera"]["value"].setValue( "/previewCamera" )
		self["options"]["in"].setInput( self["cameraTranslate"]["out"] )

		self["switch"] = GafferScene.SceneSwitch()
		self["switch"]["in"].setInput( self["in"] )
		self["switch"]["in1"].setInput( self["options"]["out"] )
		self["switch"]["index"].setInput( self["addCamera"] )

		self["out"] = GafferScene.ScenePlug( direction = Gaffer.Plug.Direction.Out )
		self["out"].setInput( self["switch"]["out"] )
    def testChildRemovalPropagatesToOutputs(self):

        s = Gaffer.ScriptNode()

        s["n1"] = Gaffer.Node()
        s["n2"] = Gaffer.Node()

        s["n1"]["c"] = Gaffer.Plug()
        s["n2"]["c"] = Gaffer.Plug()

        s["n1"]["c"]["f"] = Gaffer.FloatPlug()
        s["n2"]["c"]["f"] = Gaffer.FloatPlug()

        s["n1"]["c"]["i"] = Gaffer.FloatPlug()
        s["n2"]["c"]["i"] = Gaffer.FloatPlug()

        s["n2"]["c"].setInput(s["n1"]["c"])

        def assertPreconditions():

            self.assertEqual(s["n1"]["c"].keys(), ["f", "i"])
            self.assertEqual(s["n2"]["c"].keys(), ["f", "i"])

            self.assertTrue(s["n2"]["c"].getInput().isSame(s["n1"]["c"]))
            self.assertTrue(s["n2"]["c"]["i"].getInput().isSame(
                s["n1"]["c"]["i"]))
            self.assertTrue(s["n2"]["c"]["f"].getInput().isSame(
                s["n1"]["c"]["f"]))

        def assertPostconditions():

            self.assertEqual(s["n1"]["c"].keys(), [])
            self.assertEqual(s["n2"]["c"].keys(), [])

            self.assertTrue(s["n2"]["c"].getInput().isSame(s["n1"]["c"]))

        assertPreconditions()

        with Gaffer.UndoContext(s):

            del s["n1"]["c"]["i"]
            del s["n1"]["c"]["f"]

        assertPostconditions()

        s.undo()

        assertPreconditions()

        s.redo()

        assertPostconditions()
    def testHaveMinMaxValues(self):

        f = Gaffer.FloatPlug()
        self.assertEqual(f.hasMinValue(), False)
        self.assertEqual(f.hasMaxValue(), False)

        f = Gaffer.FloatPlug(minValue=1)
        self.assertEqual(f.hasMinValue(), True)
        self.assertEqual(f.hasMaxValue(), False)

        f = Gaffer.FloatPlug(maxValue=1)
        self.assertEqual(f.hasMinValue(), False)
        self.assertEqual(f.hasMaxValue(), True)
Example #6
0
    def testIntermediateConversions(self):

        f1 = Gaffer.FloatPlug()
        i = Gaffer.IntPlug()
        f2 = Gaffer.FloatPlug()

        i.setInput(f1)
        f2.setInput(i)

        f1.setValue(10.2)
        self.assertEqual(f2.getValue(), 10)

        f1.setValue(100.8)
        self.assertEqual(f2.getValue(), 100)
    def __createSpreadsheet(numRows=10):

        s = Gaffer.Spreadsheet()

        rowsPlug = s["rows"]

        # N = row number, starting at 1
        # Rows named 'rowN'
        # Column 0 - string - 'sN'
        # Column 1 - int - N
        # Column 2 - int - 10N - even rows disabled
        # Column 3 - float - 100N
        # Column 4 - int - 1000N
        # Column 5 - compound plug
        # Column 6 - Non-adopted NameValuePlug
        # Column 7 - Adopted NameValuePlug

        compoundPlug = Gaffer.ValuePlug()
        compoundPlug["a"] = Gaffer.FloatPlug()
        compoundPlug["b"] = Gaffer.StringPlug()
        nameValuePlug = Gaffer.NameValuePlug("nvp", IECore.FloatData(0), True)

        for i, columnPlug in enumerate((
                Gaffer.StringPlug(),  # 0
                Gaffer.IntPlug(),  # 1
                Gaffer.IntPlug(),  # 2
                Gaffer.FloatPlug(),  # 3
                Gaffer.IntPlug(),  # 4
                compoundPlug,  # 5
                nameValuePlug  # 6
        )):
            rowsPlug.addColumn(columnPlug,
                               "column%d" % i,
                               adoptEnabledPlug=False)

        rowsPlug.addColumn(nameValuePlug, "column7", adoptEnabledPlug=True)

        for i in range(1, numRows + 1):
            rowsPlug.addRow()["name"].setValue("row%d" % i)
            rowsPlug[i]["cells"][0]["value"].setValue("s%d" % (i))
            rowsPlug[i]["cells"][2]["enabled"].setValue(i % 2)
            for c in range(1, 5):
                rowsPlug[i]["cells"][c]["value"].setValue(i * pow(10, c - 1))
            rowsPlug[i]["cells"][5]["value"]["a"].setValue(i * 0.1)
            rowsPlug[i]["cells"][5]["value"]["b"].setValue("string %f" %
                                                           (i * 0.1))
            rowsPlug[i]["cells"][6]["value"]["value"].setValue(i * 0.01)

        return s
Example #8
0
    def testSerialisationRoundTripsExactly(self):

        s = Gaffer.ScriptNode()

        s["n"] = Gaffer.Node()
        s["n"]["user"]["f"] = Gaffer.FloatPlug(flags=Gaffer.Plug.Flags.Default
                                               | Gaffer.Plug.Flags.Dynamic)

        curve = Gaffer.Animation.acquire(s["n"]["user"]["f"])

        context = Gaffer.Context()
        for frame in range(0, 10000):
            context.setFrame(frame)
            curve.addKey(
                Gaffer.Animation.Key(context.getTime(), context.getTime(),
                                     Gaffer.Animation.Type.Linear))

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

        curve = Gaffer.Animation.acquire(s2["n"]["user"]["f"])

        for frame in range(0, 10000):
            context.setFrame(frame)
            self.assertEqual(
                curve.getKey(context.getTime()),
                Gaffer.Animation.Key(context.getTime(), context.getTime(),
                                     Gaffer.Animation.Type.Linear))
Example #9
0
    def testNextAndPreviousKeys(self):

        s = Gaffer.ScriptNode()

        s["n"] = Gaffer.Node()
        s["n"]["user"]["f"] = Gaffer.FloatPlug(flags=Gaffer.Plug.Flags.Default
                                               | Gaffer.Plug.Flags.Dynamic)

        key1 = Gaffer.Animation.Key(0, 0)
        key2 = Gaffer.Animation.Key(1, 1)
        key3 = Gaffer.Animation.Key(2, 2)

        curve = Gaffer.Animation.acquire(s["n"]["user"]["f"])
        curve.addKey(key1)
        curve.addKey(key2)
        curve.addKey(key3)

        self.assertEqual(curve.nextKey(-1), key1)
        self.assertEqual(curve.nextKey(0), key2)
        self.assertEqual(curve.nextKey(0.5), key2)
        self.assertEqual(curve.nextKey(1), key3)
        self.assertEqual(curve.nextKey(1.5), key3)
        self.assertFalse(curve.nextKey(2))

        self.assertFalse(curve.previousKey(-1))
        self.assertFalse(curve.previousKey(0))
        self.assertEqual(curve.previousKey(0.5), key1)
        self.assertEqual(curve.previousKey(1), key1)
        self.assertEqual(curve.previousKey(1.5), key2)
        self.assertEqual(curve.previousKey(2), key2)
        self.assertEqual(curve.previousKey(2.5), key3)
Example #10
0
    def testIdenticalExpressionWithDifferentPlugTypes(self):

        # IntPlug -> FloatPlug

        s1 = Gaffer.ScriptNode()

        s1["n"] = Gaffer.Node()
        s1["n"]["user"]["a"] = Gaffer.IntPlug(flags=Gaffer.Plug.Flags.Default
                                              | Gaffer.Plug.Flags.Dynamic)
        s1["n"]["user"]["b"] = Gaffer.FloatPlug(flags=Gaffer.Plug.Flags.Default
                                                | Gaffer.Plug.Flags.Dynamic)

        s1["e"] = Gaffer.Expression()
        s1["e"].setExpression(
            'parent["n"]["user"]["b"] = parent["n"]["user"]["a"]')

        s1["n"]["user"]["a"].setValue(1001)
        self.assertEqual(s1["n"]["user"]["b"].getValue(), 1001)

        # IntPlug -> IntPlug

        s2 = Gaffer.ScriptNode()

        s2["n"] = Gaffer.Node()
        s2["n"]["user"]["a"] = Gaffer.IntPlug(flags=Gaffer.Plug.Flags.Default
                                              | Gaffer.Plug.Flags.Dynamic)
        s2["n"]["user"]["b"] = Gaffer.IntPlug(flags=Gaffer.Plug.Flags.Default
                                              | Gaffer.Plug.Flags.Dynamic)

        s2["e"] = Gaffer.Expression()
        s2["e"].setExpression(
            'parent["n"]["user"]["b"] = parent["n"]["user"]["a"]')

        s2["n"]["user"]["a"].setValue(1001)
        self.assertEqual(s2["n"]["user"]["b"].getValue(), 1001)
Example #11
0
    def testCollaboratePerf(self):
        # Test an expensive OSLImage, with many output tiles depending on the same input tiles,
        # which should give TaskCollaborate a chance to show some benefit

        constant = GafferImage.Constant()
        constant["format"].setValue(GafferImage.Format(128, 128))

        deleteChannels = GafferImage.DeleteChannels("DeleteChannels")
        deleteChannels["in"].setInput(constant["out"])
        deleteChannels["mode"].setValue(GafferImage.DeleteChannels.Mode.Keep)
        deleteChannels["channels"].setValue('R')

        mandelbrotCode = self.mandelbrotNode()
        mandelbrotCode["parameters"]["iterations"].setValue(500000)

        oslImage = GafferOSL.OSLImage()
        oslImage["in"].setInput(deleteChannels["out"])
        oslImage["channels"].addChild(
            Gaffer.NameValuePlug("R", Gaffer.FloatPlug("value"), True,
                                 "channel"))
        oslImage["channels"]["channel"]["value"].setInput(
            mandelbrotCode["out"]["outFloat"])

        resize = GafferImage.Resize()
        resize["in"].setInput(oslImage["out"])
        resize["format"].setValue(
            GafferImage.Format(imath.Box2i(imath.V2i(0), imath.V2i(2048)), 1))
        # We use a resize because it pulls the input tiles repeatedly, we don't want to spend time on resizing
        # pixels, so use a fast filter
        resize["filter"].setValue('box')

        with GafferTest.TestRunner.PerformanceScope():
            GafferImage.ImageAlgo.image(resize["out"])
Example #12
0
    def __addPlug(self, name, defaultData):

        alphaValue = None

        if isinstance(defaultData, IECore.Color4fData):
            alphaValue = Gaffer.FloatPlug("value", Gaffer.Plug.Direction.In,
                                          defaultData.value.a)
            defaultData = IECore.Color3fData(
                imath.Color3f(defaultData.value.r, defaultData.value.g,
                              defaultData.value.b))

        if defaultData == None:
            plugName = "closure"
            name = ""
            valuePlug = GafferOSL.ClosurePlug("value")
        else:
            plugName = "channel"
            valuePlug = Gaffer.PlugAlgo.createPlugFromData(
                "value", Gaffer.Plug.Direction.In, Gaffer.Plug.Flags.Default,
                defaultData)

        with Gaffer.UndoScope(self.getPlug().ancestor(Gaffer.ScriptNode)):
            self.getPlug().addChild(
                Gaffer.NameValuePlug(
                    name, valuePlug, True, plugName,
                    Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic))
            if alphaValue:
                self.getPlug().addChild(
                    Gaffer.NameValuePlug(
                        name + ".A" if name else "A", alphaValue, True,
                        plugName,
                        Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic))
Example #13
0
	def testReloadPreservesConnectionsWhenMinMaxOrDefaultChanges( self ) :
	
		shader1 = self.compileShader( os.path.dirname( __file__ ) + "/shaders/version1.sl", shaderName = "unversioned" )
		n = GafferRenderMan.RenderManShader()
		n.loadShader( shader1 )
		
		self.assertFalse( n["parameters"]["float1"].hasMinValue() )
		self.assertFalse( n["parameters"]["float1"].hasMaxValue() )
		self.assertEqual( n["parameters"]["string1"].defaultValue(), "" )
		
		nn = Gaffer.Node()
		nn["outFloat"] = Gaffer.FloatPlug( direction = Gaffer.Plug.Direction.Out )
		nn["outString"] = Gaffer.StringPlug( direction = Gaffer.Plug.Direction.Out )
		
		n["parameters"]["float1"].setInput( nn["outFloat"] )
		n["parameters"]["string1"].setInput( nn["outString"] )
		
		shader2 = self.compileShader( os.path.dirname( __file__ ) + "/shaders/version2.sl", shaderName = "unversioned" )
				
		GafferRenderMan.RenderManShader.shaderLoader().clear()
		n.loadShader( shader1, keepExistingValues=True )
		
		self.assertTrue( n["parameters"]["float1"].hasMinValue() )
		self.assertTrue( n["parameters"]["float1"].hasMaxValue() )
		self.assertEqual( n["parameters"]["float1"].minValue(), -1 )
		self.assertEqual( n["parameters"]["float1"].maxValue(), 2 )
		self.assertEqual( n["parameters"]["string1"].defaultValue(), "newDefaultValue" )
		
		self.assertTrue( n["parameters"]["float1"].getInput().isSame( nn["outFloat"] ) )
		self.assertTrue( n["parameters"]["string1"].getInput().isSame( nn["outString"] ) )
Example #14
0
    def testExpectedResult(self):

        ramp = GafferImage.Ramp()
        ramp["format"].setValue(GafferImage.Format(128, 128))
        ramp["transform"]["rotate"].setValue(45)
        ramp["transform"]["scale"]["x"].setValue(.5)

        ramp["startPosition"].setValue(imath.V2f(0, 64))
        ramp["endPosition"].setValue(imath.V2f(128, 64))
        ramp["ramp"].addChild(Gaffer.ValuePlug("p2"))
        ramp["ramp"]["p2"].addChild(
            Gaffer.FloatPlug("x", defaultValue=0.5308765172958374))
        ramp["ramp"]["p2"].addChild(
            Gaffer.Color4fPlug("y",
                               defaultValue=imath.Color4f(
                                   0.530900002, 0, 0, 0.50999999)))

        reader = GafferImage.ImageReader()
        reader["fileName"].setValue(
            os.path.dirname(__file__) + "/images/GafferRamp.exr")

        self.assertImagesEqual(ramp["out"],
                               reader["out"],
                               ignoreMetadata=True,
                               maxDifference=0.001)
Example #15
0
    def testClosestKey(self):

        s = Gaffer.ScriptNode()

        s["n"] = Gaffer.Node()
        s["n"]["user"]["f"] = Gaffer.FloatPlug(flags=Gaffer.Plug.Flags.Default
                                               | Gaffer.Plug.Flags.Dynamic)

        curve = Gaffer.Animation.acquire(s["n"]["user"]["f"])

        key0 = Gaffer.Animation.Key(0, 0)
        key1 = Gaffer.Animation.Key(1, 1)
        curve.addKey(key0)
        curve.addKey(key1)

        self.assertEqual(curve.closestKey(-1), key0)
        self.assertEqual(curve.closestKey(-0.1), key0)
        self.assertEqual(curve.closestKey(0), key0)
        self.assertEqual(curve.closestKey(0.1), key0)
        self.assertEqual(curve.closestKey(0.49), key0)
        self.assertEqual(curve.closestKey(0.51), key1)
        self.assertEqual(curve.closestKey(0.75), key1)
        self.assertEqual(curve.closestKey(1), key1)
        self.assertEqual(curve.closestKey(1.1), key1)

        self.assertEqual(curve.closestKey(-1, 1), key0)
        self.assertEqual(curve.closestKey(-1, 0.9), None)

        self.assertEqual(curve.closestKey(0.75, 1), key1)
        self.assertEqual(curve.closestKey(0.75, 0.2), None)
Example #16
0
    def testPlugTypes(self):

        box = Gaffer.Box("PlugTypes")
        box["int"] = Gaffer.IntPlug(flags=Gaffer.Plug.Flags.Default
                                    | Gaffer.Plug.Flags.Dynamic)
        box["float"] = Gaffer.FloatPlug(flags=Gaffer.Plug.Flags.Default
                                        | Gaffer.Plug.Flags.Dynamic)
        box["string"] = Gaffer.StringPlug(flags=Gaffer.Plug.Flags.Default
                                          | Gaffer.Plug.Flags.Dynamic)
        box["v2i"] = Gaffer.V2iPlug(flags=Gaffer.Plug.Flags.Default
                                    | Gaffer.Plug.Flags.Dynamic)
        box["v3i"] = Gaffer.V3iPlug(flags=Gaffer.Plug.Flags.Default
                                    | Gaffer.Plug.Flags.Dynamic)
        box["color4f"] = Gaffer.Color4fPlug(flags=Gaffer.Plug.Flags.Default
                                            | Gaffer.Plug.Flags.Dynamic)
        box["spline"] = Gaffer.SplinefColor3fPlug(
            flags=Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic)

        Gaffer.ExtensionAlgo.exportExtension("PlugTypesExtension", [box],
                                             self.temporaryDirectory())
        sys.path.append(os.path.join(self.temporaryDirectory(), "python"))

        import PlugTypesExtension
        node = PlugTypesExtension.PlugTypes()

        for plug in Gaffer.Plug.Range(node):
            self.assertIsInstance(plug, type(box[plug.getName()]))
            if hasattr(plug, "getValue"):
                self.assertEqual(plug.getValue(),
                                 box[plug.getName()].getValue())

        for plug in Gaffer.Plug.RecursiveRange(node):
            self.assertFalse(plug.getFlags(Gaffer.Plug.Flags.Dynamic))
Example #17
0
    def testStep(self):

        s = Gaffer.ScriptNode()

        s["n"] = Gaffer.Node()
        s["n"]["user"]["f"] = Gaffer.FloatPlug(flags=Gaffer.Plug.Flags.Default
                                               | Gaffer.Plug.Flags.Dynamic)

        curve = Gaffer.Animation.acquire(s["n"]["user"]["f"])
        curve.addKey(Gaffer.Animation.Key(0, 0))
        curve.addKey(Gaffer.Animation.Key(1, 1, Gaffer.Animation.Type.Linear))
        curve.addKey(Gaffer.Animation.Key(2, 2, Gaffer.Animation.Type.Step))

        with Gaffer.Context() as c:
            # Linear interpolation from 0 to 1.
            for i in range(0, 10):
                c.setTime(i / 9.0)
                self.assertAlmostEqual(s["n"]["user"]["f"].getValue(),
                                       c.getTime())
            # Step interpolation from 1 to 2
            for i in range(0, 10):
                c.setTime(1 + i / 10.0)
                self.assertEqual(s["n"]["user"]["f"].getValue(), 1)
            c.setTime(2)
            self.assertEqual(s["n"]["user"]["f"].getValue(), 2)
Example #18
0
	def testDefaultExpressionForSupportedPlugs( self ) :

		s = Gaffer.ScriptNode()

		s["n"] = Gaffer.Node()
		s["n"]["user"].addChild( Gaffer.IntPlug( flags = Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic ) )
		s["n"]["user"].addChild( Gaffer.FloatPlug( flags = Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic ) )
		s["n"]["user"].addChild( Gaffer.StringPlug( flags = Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic ) )
		s["n"]["user"].addChild( Gaffer.BoolPlug( flags = Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic ) )
		s["n"]["user"].addChild( Gaffer.V2fPlug( flags = Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic ) )
		s["n"]["user"].addChild( Gaffer.V2iPlug( flags = Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic ) )
		s["n"]["user"].addChild( Gaffer.V3fPlug( flags = Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic ) )
		s["n"]["user"].addChild( Gaffer.V3iPlug( flags = Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic ) )
		s["n"]["user"].addChild( Gaffer.Color3fPlug( flags = Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic ) )
		s["n"]["user"].addChild( Gaffer.Color4fPlug( flags = Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic ) )
		s["n"]["user"].addChild( Gaffer.Box2fPlug( flags = Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic ) )
		s["n"]["user"].addChild( Gaffer.Box2iPlug( flags = Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic ) )
		s["n"]["user"].addChild( Gaffer.Box3fPlug( flags = Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic ) )
		s["n"]["user"].addChild( Gaffer.Box3iPlug( flags = Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic ) )
		s["n"]["user"].addChild( Gaffer.IntVectorDataPlug( defaultValue = IECore.IntVectorData( [ 0, 1 ] ), flags = Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic ) )
		s["n"]["user"].addChild( Gaffer.FloatVectorDataPlug( defaultValue = IECore.FloatVectorData( [ 0, 1 ] ), flags = Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic ) )
		s["n"]["user"].addChild( Gaffer.StringVectorDataPlug( defaultValue = IECore.StringVectorData( [ "a", "b" ] ), flags = Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic ) )
		s["n"]["user"].addChild( Gaffer.V3fVectorDataPlug( defaultValue = IECore.V3fVectorData( [ IECore.V3f( 1 ) ] ), flags = Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic ) )
		s["n"]["user"].addChild( Gaffer.Color3fVectorDataPlug( defaultValue = IECore.Color3fVectorData( [ IECore.Color3f( 1 ) ] ), flags = Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic ) )
		s["n"]["user"].addChild( Gaffer.M44fVectorDataPlug( defaultValue = IECore.M44fVectorData( [ IECore.M44f() ] ), flags = Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic ) )
		s["n"]["user"].addChild( Gaffer.V2iVectorDataPlug( defaultValue = IECore.V2iVectorData( [ IECore.V2i() ] ), flags = Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic ) )

		s["e"] = Gaffer.Expression()

		for plug in s["n"]["user"] :

			value = plug.getValue()
			s["e"].setExpression( s["e"].defaultExpression( plug, "python" ) )
			self.assertTrue( plug.getInput().node().isSame( s["e"] ) )
			self.assertEqual( plug.getValue(), value )
Example #19
0
    def testSerialisation(self):

        s = Gaffer.ScriptNode()

        s["n"] = Gaffer.Node()
        s["n"]["user"]["f"] = Gaffer.FloatPlug(flags=Gaffer.Plug.Flags.Default
                                               | Gaffer.Plug.Flags.Dynamic)

        curve = Gaffer.Animation.acquire(s["n"]["user"]["f"])
        curve.addKey(Gaffer.Animation.Key(0, 0, Gaffer.Animation.Type.Linear))
        curve.addKey(Gaffer.Animation.Key(1, 1, Gaffer.Animation.Type.Linear))

        def assertAnimation(script):

            curve = Gaffer.Animation.acquire(script["n"]["user"]["f"])
            self.assertEqual(
                curve.getKey(0),
                Gaffer.Animation.Key(0, 0, Gaffer.Animation.Type.Linear))
            self.assertEqual(
                curve.getKey(1),
                Gaffer.Animation.Key(1, 1, Gaffer.Animation.Type.Linear))
            with Gaffer.Context() as c:
                for i in range(0, 10):
                    c.setTime(i / 9.0)
                    self.assertAlmostEqual(script["n"]["user"]["f"].getValue(),
                                           c.getTime())

        assertAnimation(s)

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

        assertAnimation(s2)
Example #20
0
    def mandelbrotNode(self):
        mandelbrotCode = GafferOSL.OSLCode()
        mandelbrotCode["parameters"].addChild(
            Gaffer.IntPlug(
                "iterations",
                defaultValue=0,
                flags=Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic,
            ))
        mandelbrotCode["out"].addChild(
            Gaffer.FloatPlug("outFloat", direction=Gaffer.Plug.Direction.Out))
        mandelbrotCode["code"].setValue(
            inspect.cleandoc("""
			// Basic mandelbrot adapted from surface shader here:
			// https://github.com/AcademySoftwareFoundation/OpenShadingLanguage/blob/master/src/shaders/mandelbrot.osl
			point center = point (0,0,0);
			float scale = 2;
			point cent = center;
			point c = scale * point(2*(u-0.5), 2*((1-v)-0.5), 0) + cent;
			point z = c;
			int i;
			for (i = 1; i < iterations && dot(z,z) < 4.0; ++i) {
			float x = z[0], y = z[1];
			z = point (x*x - y*y, 2*x*y, 0) + c;
			}
			if (i < iterations) {
				float f = pow(float(i)/iterations, 1/log10(float(iterations)));
				outFloat = f;
			} else {
				outFloat = 0;
			}
			"""))
        return mandelbrotCode
Example #21
0
    def testUndoAddKey(self):

        s = Gaffer.ScriptNode()

        s["n"] = Gaffer.Node()
        s["n"]["user"]["f"] = Gaffer.FloatPlug(flags=Gaffer.Plug.Flags.Default
                                               | Gaffer.Plug.Flags.Dynamic)

        curve = Gaffer.Animation.acquire(s["n"]["user"]["f"])
        self.assertFalse(curve.getKey(0))

        key1 = Gaffer.Animation.Key(1, 0)
        key2 = Gaffer.Animation.Key(1, 1)

        with Gaffer.UndoScope(s):
            curve.addKey(key1)
            self.assertEqual(curve.getKey(1), key1)

        with Gaffer.UndoScope(s):
            curve.addKey(key2)
            self.assertEqual(curve.getKey(1), key2)

        s.undo()
        self.assertEqual(curve.getKey(1), key1)

        s.undo()
        self.assertFalse(curve.getKey(1))

        s.redo()
        self.assertEqual(curve.getKey(1), key1)

        s.redo()
        self.assertEqual(curve.getKey(1), key2)
Example #22
0
    def testExpressionChangedSignal(self):

        s = Gaffer.ScriptNode()

        s["n"] = Gaffer.Node()
        s["n"]["user"]["p"] = Gaffer.FloatPlug(flags=Gaffer.Plug.Flags.Default
                                               | Gaffer.Plug.Flags.Dynamic)

        expressions = []

        def f(node):

            expressions.append(node.getExpression())

        s["e"] = Gaffer.Expression()
        self.assertEqual(s["e"].getExpression(), ("", ""))

        c = s["e"].expressionChangedSignal().connect(f)

        with Gaffer.UndoContext(s):
            s["e"].setExpression('parent["n"]["user"]["p"] = 10')
            self.assertEqual(len(expressions), 1)
            self.assertEqual(expressions[0],
                             ('parent["n"]["user"]["p"] = 10', "python"))

        s.undo()
        self.assertEqual(len(expressions), 2)
        self.assertEqual(expressions[1], ("", ""))

        s.redo()
        self.assertEqual(len(expressions), 3)
        self.assertEqual(expressions[2], expressions[0])
Example #23
0
    def testUndoRemoveKey(self):

        s = Gaffer.ScriptNode()

        s["n"] = Gaffer.Node()
        s["n"]["user"]["f"] = Gaffer.FloatPlug(flags=Gaffer.Plug.Flags.Default
                                               | Gaffer.Plug.Flags.Dynamic)

        curve = Gaffer.Animation.acquire(s["n"]["user"]["f"])
        key = Gaffer.Animation.Key(0, 0)
        curve.addKey(key)
        self.assertTrue(curve.getKey(key.getTime()).isSame(key))

        with Gaffer.UndoScope(s):
            curve.removeKey(key)
            self.assertFalse(curve.hasKey(key.getTime()))
            self.assertEqual(key.parent(), None)

        s.undo()
        self.assertEqual(curve.getKey(key.getTime()), key)
        self.assertTrue(key.parent().isSame(curve))

        s.redo()
        self.assertFalse(curve.hasKey(key.getTime()))
        self.assertEqual(key.parent(), None)
Example #24
0
    def testDefaultExpression(self):

        s = Gaffer.ScriptNode()
        s["n"] = Gaffer.Node()
        s["n"]["user"]["f"] = Gaffer.FloatPlug(flags=Gaffer.Plug.Flags.Default
                                               | Gaffer.Plug.Flags.Dynamic)
        s["n"]["user"]["i"] = Gaffer.IntPlug(flags=Gaffer.Plug.Flags.Default
                                             | Gaffer.Plug.Flags.Dynamic)
        s["n"]["user"]["c"] = Gaffer.Color3fPlug(
            flags=Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic)
        s["n"]["user"]["v"] = Gaffer.V3fPlug(flags=Gaffer.Plug.Flags.Default
                                             | Gaffer.Plug.Flags.Dynamic)
        s["n"]["user"]["s"] = Gaffer.StringPlug(flags=Gaffer.Plug.Flags.Default
                                                | Gaffer.Plug.Flags.Dynamic)

        s["n"]["user"]["f"].setValue(10)
        s["n"]["user"]["i"].setValue(10)
        s["n"]["user"]["c"].setValue(IECore.Color3f(1, 2, 3))
        s["n"]["user"]["v"].setValue(IECore.V3f(1, 2, 3))
        s["n"]["user"]["s"].setValue("s")

        defaultExpressions = [
            Gaffer.Expression.defaultExpression(p, "OSL")
            for p in s["n"]["user"].children()
        ]
        expectedValues = [p.getValue() for p in s["n"]["user"].children()]

        for p in s["n"]["user"].children():
            p.setToDefault()

        s["e"] = Gaffer.Expression()
        for p, e, v in zip(s["n"]["user"].children(), defaultExpressions,
                           expectedValues):
            s["e"].setExpression(e, "OSL")
            self.assertEqual(p.getValue(), v)
    def __init__(self, name="LDTGetBoundingBox"):
        super(LDTGetBoundingBox, self).__init__(name)
        # create a Gaffer scene reader
        # connect the reader's output to the output
        self.setName("BoundBoxReader")
        self["in"] = GafferScene.ScenePlug(direction=Gaffer.Plug.Direction.In)

        # Make path read only for now
        # TODO: check if path exists
        # TODO: get bounding box in world space
        self["path"] = Gaffer.StringPlug()
        self["path"].setValue("/")
        self["bound"] = Gaffer.Box3fPlug()
        Gaffer.Metadata.registerValue(self["bound"], 'readOnly', True)
        self["boundDiagonalLength"] = Gaffer.FloatPlug()
        Gaffer.Metadata.registerValue(self["boundDiagonalLength"], 'readOnly',
                                      True)
        self["boundSize"] = Gaffer.V3fPlug()
        Gaffer.Metadata.registerValue(self["boundSize"], 'readOnly', True)

        self["boundCenter"] = Gaffer.V3fPlug()
        Gaffer.Metadata.registerValue(self["boundCenter"], 'readOnly', True)

        self["out"] = GafferScene.ScenePlug(
            direction=Gaffer.Plug.Direction.Out)
        self["out"].setFlags(Gaffer.Plug.Flags.Serialisable, False)
        self["out"].setInput(self["in"])
        self.__plugInputChanged = self.plugInputChangedSignal().connect(
            self.get_bound)
        self.__plugValueChanged = self.plugSetSignal().connect(self.get_bound)
Example #26
0
	def testRanges( self ) :

		n = Gaffer.Node()
		n["c1"] = Gaffer.Plug()
		n["c2"] = Gaffer.Node()
		n["c3"] = Gaffer.IntPlug()
		n["c4"] = Gaffer.Plug()
		n["c4"]["gc1"] = Gaffer.Plug()
		n["c4"]["gc2"] = Gaffer.FloatPlug()

		self.assertEqual(
			list( Gaffer.IntPlug.Range( n ) ),
			[ n["c3"] ]
		)

		self.assertEqual(
			list( Gaffer.FloatPlug.Range( n ) ),
			[]
		)

		self.assertEqual(
			list( Gaffer.IntPlug.RecursiveRange( n ) ),
			[ n["c3"] ]
		)

		self.assertEqual(
			list( Gaffer.FloatPlug.RecursiveRange( n ) ),
			[ n["c4"]["gc2"] ]
		)
Example #27
0
    def testDirtyPropagation(self):

        s = Gaffer.Spreadsheet()
        s["rows"].addColumn(Gaffer.V3fPlug("v"))
        s["rows"].addColumn(Gaffer.FloatPlug("f"))
        r = s["rows"].addRow()

        cs = GafferTest.CapturingSlot(s.plugDirtiedSignal())

        s["enabled"].setValue(False)
        self.assertTrue(set(s["out"].children()).issubset({x[0] for x in cs}))
        del cs[:]

        r["cells"]["v"]["value"]["x"].setValue(2)
        self.assertIn(s["out"]["v"]["x"], {x[0] for x in cs})
        self.assertNotIn(s["out"]["v"]["z"], {x[0] for x in cs})
        self.assertNotIn(s["out"]["f"], {x[0] for x in cs})
        del cs[:]

        r["cells"]["v"]["enabled"].setValue(False)
        self.assertTrue(
            set(s["out"]["v"].children()).issubset({x[0]
                                                    for x in cs}))
        self.assertNotIn(s["out"]["f"], {x[0] for x in cs})
        del cs[:]

        s["rows"].addRow()
        self.assertTrue(set(s["out"].children()).issubset({x[0] for x in cs}))
        del cs[:]

        s["rows"].removeChild(s["rows"][-1])
        self.assertTrue(set(s["out"].children()).issubset({x[0] for x in cs}))
        del cs[:]
Example #28
0
    def testImageProcessingFunctions(self):

        oslCode = GafferOSL.OSLCode()
        oslCode["out"]["out"] = Gaffer.FloatPlug(
            direction=Gaffer.Plug.Direction.Out,
            flags=Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic)
        self.__assertNoError(oslCode, oslCode["code"].setValue,
                             'out = inChannel( "R", 0 );')
Example #29
0
	def __init__( self, name = "Wedge" ) :

		GafferDispatch.TaskContextProcessor.__init__( self, name )

		self["variable"] = Gaffer.StringPlug( defaultValue = "wedge:value" )
		self["indexVariable"] = Gaffer.StringPlug( defaultValue = "wedge:index" )

		self["mode"] = Gaffer.IntPlug(
			defaultValue = int( self.Mode.FloatRange ),
			minValue = int( self.Mode.FloatRange ),
			maxValue = int( self.Mode.StringList ),
		)

		# float range

		self["floatMin"] = Gaffer.FloatPlug( defaultValue = 0 )
		self["floatMax"] = Gaffer.FloatPlug( defaultValue = 1 )
		self["floatSteps"] = Gaffer.IntPlug( minValue = 2, defaultValue = 11 )

		# int range

		self["intMin"] = Gaffer.IntPlug( defaultValue = 0 )
		self["intMax"] = Gaffer.IntPlug( defaultValue = 5 )
		self["intStep"] = Gaffer.IntPlug( minValue = 1, defaultValue = 1 )

		# color range

		self["ramp"] = Gaffer.SplinefColor3fPlug(
			defaultValue = IECore.SplinefColor3f(
				IECore.CubicBasisf.catmullRom(),
				(
					( 0, imath.Color3f( 0 ) ),
					( 0, imath.Color3f( 0 ) ),
					( 1, imath.Color3f( 1 ) ),
					( 1, imath.Color3f( 1 ) ),
				)
			)
		)

		self["colorSteps"] = Gaffer.IntPlug( defaultValue = 5, minValue = 2 )

		# lists

		self["floats"] = Gaffer.FloatVectorDataPlug( defaultValue = IECore.FloatVectorData() )
		self["ints"] = Gaffer.IntVectorDataPlug( defaultValue = IECore.IntVectorData() )
		self["strings"] = Gaffer.StringVectorDataPlug( defaultValue = IECore.StringVectorData() )
Example #30
0
    def testRemoveMiddleColumn(self):

        s = Gaffer.ScriptNode()

        s["s"] = Gaffer.Spreadsheet()
        s["s"]["rows"].addRow()

        c1 = s["s"]["rows"].addColumn(Gaffer.IntPlug("c1"))
        c2 = s["s"]["rows"].addColumn(Gaffer.FloatPlug("c2"))
        c3 = s["s"]["rows"].addColumn(Gaffer.StringPlug("c3"))

        def assertPreconditions():

            for row in s["s"]["rows"]:
                self.assertEqual(row["cells"].keys(), ["c1", "c2", "c3"])
                self.assertIsInstance(row["cells"]["c1"]["value"],
                                      Gaffer.IntPlug)
                self.assertIsInstance(row["cells"]["c2"]["value"],
                                      Gaffer.FloatPlug)
                self.assertIsInstance(row["cells"]["c3"]["value"],
                                      Gaffer.StringPlug)

            self.assertEqual(s["s"]["out"].keys(), ["c1", "c2", "c3"])
            self.assertIsInstance(s["s"]["out"]["c1"], Gaffer.IntPlug)
            self.assertIsInstance(s["s"]["out"]["c2"], Gaffer.FloatPlug)
            self.assertIsInstance(s["s"]["out"]["c3"], Gaffer.StringPlug)

        assertPreconditions()

        with Gaffer.UndoScope(s):
            s["s"]["rows"].removeColumn(c2)

        def assertPostConditions():

            for row in s["s"]["rows"]:
                self.assertEqual(row["cells"].keys(), ["c1", "c3"])
                self.assertIsInstance(row["cells"]["c1"]["value"],
                                      Gaffer.IntPlug)
                self.assertIsInstance(row["cells"]["c3"]["value"],
                                      Gaffer.StringPlug)

            self.assertEqual(s["s"]["out"].keys(), ["c1", "c3"])
            self.assertIsInstance(s["s"]["out"]["c1"], Gaffer.IntPlug)
            self.assertIsInstance(s["s"]["out"]["c3"], Gaffer.StringPlug)

        assertPostConditions()

        s.undo()
        assertPreconditions()

        s.redo()
        assertPostConditions()

        s.undo()
        assertPreconditions()

        s.redo()
        assertPostConditions()