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

        s = GafferTest.SphereNode()

        o = GafferScene.ObjectToScene()

        o["__inputSource"].setInput(s["out"])

        g = GafferScene.Group()
        g["in"].setInput(o["out"])

        g["transform"]["translate"]["x"].setValue(5)
        g["transform"]["translate"]["z"].setValue(2)

        script = Gaffer.ScriptNode()

        writer = GafferScene.SceneWriter()
        script["writer"] = writer
        writer["in"].setInput(g["out"])
        writer["fileName"].setValue(self.__testFile)

        writer.execute()

        sc = IECore.SceneCache(self.__testFile, IECore.IndexedIO.OpenMode.Read)

        t = sc.child("group")

        self.assertEqual(t.readTransformAsMatrix(0),
                         IECore.M44d.createTranslated(IECore.V3d(5, 0, 2)))
    def testExecuteObjectWriter(self):

        s = Gaffer.ScriptNode()

        s["sphere"] = GafferTest.SphereNode()
        s["write"] = Gaffer.ObjectWriter()
        s["write"]["in"].setInput(s["sphere"]["out"])
        s["write"]["fileName"].setValue(self.__outputFileSeq.fileName)

        s["fileName"].setValue(self.__scriptFileName)
        s.save()

        self.failIf(os.path.exists(self.__outputFileSeq.fileNameForFrame(1)))
        p = subprocess.Popen(
            "gaffer execute " + self.__scriptFileName,
            shell=True,
            stderr=subprocess.PIPE,
        )
        p.wait()

        error = "".join(p.stderr.readlines())
        self.failUnless(error == "")
        self.failUnless(
            os.path.exists(self.__outputFileSeq.fileNameForFrame(1)))
        self.failIf(p.returncode)
    def testFramesParameter(self):

        s = Gaffer.ScriptNode()
        s["sphere"] = GafferTest.SphereNode()
        s["write"] = Gaffer.ObjectWriter()
        s["write"]["in"].setInput(s["sphere"]["out"])
        s["write"]["fileName"].setValue(self.__outputFileSeq.fileName)

        s["fileName"].setValue(self.__scriptFileName)
        s.save()

        frames = IECore.FrameList.parse("1-5")
        for f in frames.asList():
            self.failIf(
                os.path.exists(self.__outputFileSeq.fileNameForFrame(f)))

        p = subprocess.Popen(
            "gaffer execute " + self.__scriptFileName + " -frames " +
            str(frames),
            shell=True,
            stderr=subprocess.PIPE,
        )
        p.wait()

        error = "".join(p.stderr.readlines())
        self.failUnless(error == "")
        self.failIf(p.returncode)
        for f in frames.asList():
            self.failUnless(
                os.path.exists(self.__outputFileSeq.fileNameForFrame(f)))
Пример #4
0
	def testPlugFlagsOnReload( self ):

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

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

		# import it into a script.

		s2 = Gaffer.ScriptNode()
		s2["r"] = Gaffer.Reference()
		s2["r"].load( self.temporaryDirectory() + "/test.grf" )
		s2["r"]["__pluggy"] = Gaffer.CompoundPlug( flags = Gaffer.Plug.Flags.Dynamic | Gaffer.Plug.Flags.Default )
		s2["r"]["__pluggy"]["int"] = Gaffer.IntPlug( flags = Gaffer.Plug.Flags.Dynamic | Gaffer.Plug.Flags.Default )
		s2["r"]["__pluggy"]["compound"] = Gaffer.CompoundPlug( flags = Gaffer.Plug.Flags.Dynamic | Gaffer.Plug.Flags.Default )
		s2["r"]["__pluggy"]["compound"]["int"] = Gaffer.IntPlug( flags = Gaffer.Plug.Flags.Dynamic | Gaffer.Plug.Flags.Default )

		self.assertEqual( s2["r"]["__pluggy"].getFlags(), Gaffer.Plug.Flags.Dynamic | Gaffer.Plug.Flags.Default )
		self.assertEqual( s2["r"]["__pluggy"]["int"].getFlags(), Gaffer.Plug.Flags.Dynamic | Gaffer.Plug.Flags.Default )
		self.assertEqual( s2["r"]["__pluggy"]["compound"].getFlags(), Gaffer.Plug.Flags.Dynamic | Gaffer.Plug.Flags.Default )
		self.assertEqual( s2["r"]["__pluggy"]["compound"]["int"].getFlags(), Gaffer.Plug.Flags.Dynamic | Gaffer.Plug.Flags.Default )

		s2["r"].load( self.temporaryDirectory() + "/test.grf" )

		self.assertEqual( s2["r"]["__pluggy"].getFlags(), Gaffer.Plug.Flags.Dynamic | Gaffer.Plug.Flags.Default )
		self.assertEqual( s2["r"]["__pluggy"]["int"].getFlags(), Gaffer.Plug.Flags.Dynamic | Gaffer.Plug.Flags.Default )
		self.assertEqual( s2["r"]["__pluggy"]["compound"].getFlags(), Gaffer.Plug.Flags.Dynamic | Gaffer.Plug.Flags.Default )
		self.assertEqual( s2["r"]["__pluggy"]["compound"]["int"].getFlags(), Gaffer.Plug.Flags.Dynamic | Gaffer.Plug.Flags.Default )
Пример #5
0
    def testDeriving(self):
        class MyView(GafferImageUI.ImageView):
            def __init__(self, viewedPlug=None):

                GafferImageUI.ImageView.__init__(self, "MyView")

                converter = Gaffer.Node()
                converter["in"] = Gaffer.ObjectPlug(
                    defaultValue=IECore.NullObject.defaultNullObject())
                converter["out"] = GafferImage.ImagePlug(
                    direction=Gaffer.Plug.Direction.Out)
                converter["constant"] = GafferImage.Constant()
                converter["constant"]["format"].setValue(
                    GafferImage.Format(20, 20, 1))
                converter["out"].setInput(converter["constant"]["out"])

                self._insertConverter(converter)

                self["in"].setInput(viewedPlug)

        GafferUI.View.registerView(GafferTest.SphereNode.staticTypeId(), "out",
                                   MyView)

        sphere = GafferTest.SphereNode()

        view = GafferUI.View.create(sphere["out"])
        self.assertTrue(isinstance(view, MyView))
        self.assertTrue(view["in"].getInput().isSame(sphere["out"]))
        self.assertTrue(isinstance(view["in"], Gaffer.ObjectPlug))
        view["exposure"].setValue(1)
        view["gamma"].setValue(0.5)

        view._update()
Пример #6
0
    def testFactory(self):

        sphere = GafferTest.SphereNode()
        view = GafferUI.View.create(sphere["out"])

        self.assertTrue(isinstance(view, GafferUI.ObjectView))
        self.assertTrue(view["in"].getInput().isSame(sphere["out"]))

        # check that we can make our own view and register it for the node

        class MyView(GafferUI.ObjectView):
            def __init__(self, viewedPlug=None):

                GafferUI.ObjectView.__init__(self)

                self["in"].setInput(viewedPlug)

        GafferUI.View.registerView(GafferTest.SphereNode, "out", MyView)

        view = GafferUI.View.create(sphere["out"])
        self.assertTrue(isinstance(view, MyView))
        self.assertTrue(view["in"].getInput().isSame(sphere["out"]))

        # and check that that registration leaves other nodes alone

        n = Gaffer.Node()
        n["out"] = Gaffer.ObjectPlug(
            direction=Gaffer.Plug.Direction.Out,
            defaultValue=IECore.NullObject.defaultNullObject())

        view = GafferUI.View.create(n["out"])

        self.assertTrue(isinstance(view, GafferUI.ObjectView))
        self.assertTrue(view["in"].getInput().isSame(n["out"]))
Пример #7
0
    def testHash(self):

        c = Gaffer.Context()
        c.setFrame(1)
        c2 = Gaffer.Context()
        c2.setFrame(2)

        s = Gaffer.ScriptNode()
        s["n"] = GafferCortex.ObjectWriter()

        # no file produces no effect
        self.assertEqual(s["n"].hash(c), IECore.MurmurHash())

        # no input object produces no effect
        s["n"]["fileName"].setValue(self.__exrFileName)
        self.assertEqual(s["n"].hash(c), IECore.MurmurHash())

        # now theres a file and object, we get some output
        s["sphere"] = GafferTest.SphereNode()
        s["n"]["in"].setInput(s["sphere"]["out"])
        self.assertNotEqual(s["n"].hash(c), IECore.MurmurHash())

        # output doesn't vary by time
        self.assertEqual(s["n"].hash(c), s["n"].hash(c2))

        # output varies by time since the file name does
        s["n"]["fileName"].setValue(self.__exrSequence.fileName)
        self.assertNotEqual(s["n"].hash(c), s["n"].hash(c2))
Пример #8
0
	def testContextParameter( self ) :
		
		s = Gaffer.ScriptNode()
		s["sphere"] = GafferTest.SphereNode()
		s["e"] = Gaffer.Expression()
		s["e"]["engine"].setValue( "python" )
		s["e"]["expression"].setValue( "parent['sphere']['radius'] = context.get( 'sphere:radius', 1 )" )
		s["e2"] = Gaffer.Expression()
		s["e2"]["engine"].setValue( "python" )
		s["e2"]["expression"].setValue( "parent['sphere']['theta'] = context.get( 'sphere:theta', 360 )" )
		s["write"] = Gaffer.ObjectWriter()
		s["write"]["in"].setInput( s["sphere"]["out"] )
		s["write"]["fileName"].setValue( self.__outputFileSeq.fileName )
		
		s["fileName"].setValue( self.__scriptFileName )
		s.save()		
		
		self.failIf( os.path.exists( self.__outputFileSeq.fileNameForFrame( 1 ) ) )
		p = subprocess.Popen(
			"gaffer execute " + self.__scriptFileName + " -context -sphere:radius 5 -sphere:theta 180",
			shell=True,
			stderr = subprocess.PIPE,
		)
		p.wait()
		
		error = "".join( p.stderr.readlines() )
		self.failUnless( error == "" )
		self.failIf( p.returncode )
		self.failUnless( os.path.exists( self.__outputFileSeq.fileNameForFrame( 1 ) ) )
		
		prim = IECore.ObjectReader( self.__outputFileSeq.fileNameForFrame( 1 ) ).read()
		self.failUnless( prim.isInstanceOf( IECore.SpherePrimitive.staticTypeId() ) )
		self.assertEqual( prim.bound(), IECore.Box3f( IECore.V3f( -5 ), IECore.V3f( 5 ) ) )
		self.assertEqual( prim.thetaMax(), 180 )
Пример #9
0
    def testClassPath(self):

        self.assertEqual(Gaffer.Serialisation.classPath(Gaffer.Node()),
                         "Gaffer.Node")
        self.assertEqual(Gaffer.Serialisation.classPath(Gaffer.Node),
                         "Gaffer.Node")

        self.assertEqual(
            Gaffer.Serialisation.classPath(GafferTest.SphereNode()),
            "GafferTest.SphereNode")
        self.assertEqual(Gaffer.Serialisation.classPath(GafferTest.SphereNode),
                         "GafferTest.SphereNode")
Пример #10
0
    def testModulePath(self):

        self.assertEqual(Gaffer.Serialisation.modulePath(Gaffer.Node()),
                         "Gaffer")
        self.assertEqual(Gaffer.Serialisation.modulePath(Gaffer.Node),
                         "Gaffer")

        self.assertEqual(
            Gaffer.Serialisation.modulePath(GafferTest.SphereNode()),
            "GafferTest")
        self.assertEqual(
            Gaffer.Serialisation.modulePath(GafferTest.SphereNode),
            "GafferTest")
Пример #11
0
    def testLoadThrowsExceptionsOnError(self):

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

        s["b"].exportForReference("/tmp/test.grf")

        del GafferTest.SphereNode  # induce a failure during loading

        s2 = Gaffer.ScriptNode()
        s2["r"] = Gaffer.Reference()

        self.assertRaises(Exception, s2["r"].load, "/tmp/test.grf")
Пример #12
0
	def testLoadThrowsExceptionsOnError( self ) :

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

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

		del GafferTest.SphereNode # induce a failure during loading

		s2 = Gaffer.ScriptNode()
		s2["r"] = Gaffer.Reference()

		with IECore.CapturingMessageHandler() as mh :
			self.assertRaises( Exception, s2["r"].load, self.temporaryDirectory() + "/test.grf" )

		self.assertEqual( len( mh.messages ), 2 )
		self.assertTrue( "has no attribute 'SphereNode'" in mh.messages[0].message )
		self.assertTrue( "KeyError: 'n'" in mh.messages[1].message )
Пример #13
0
    def testErrorTolerantLoading(self):

        # make a box containing 2 nodes, and export it.

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

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

        # import it into a script.

        s2 = Gaffer.ScriptNode()
        s2["r"] = Gaffer.Reference()
        s2["r"].load(self.temporaryDirectory() + "/test.grf")

        self.assertTrue("a" in s2["r"])
        self.assertTrue(isinstance(s2["r"]["a"], GafferTest.AddNode))

        # save that script, and then mysteriously
        # disable GafferTest.SphereNode.

        s2["fileName"].setValue(self.temporaryDirectory() + "/test.gfr")
        s2.save()

        del GafferTest.SphereNode

        # load the script, and check that we could at least
        # load in the other referenced node.

        s3 = Gaffer.ScriptNode()
        s3["fileName"].setValue(self.temporaryDirectory() + "/test.gfr")
        with IECore.CapturingMessageHandler() as mh:
            s3.load(continueOnError=True)

        self.assertTrue(len(mh.messages))

        self.assertTrue("a" in s3["r"])
        self.assertTrue(isinstance(s3["r"]["a"], GafferTest.AddNode))