Ejemplo n.º 1
0
    def testChildNamesUpdateCrash(self):

        # build a scene with a reasonably large hierarchy:
        plane = GafferScene.Plane()
        plane["dimensions"].setValue(IECore.V2f(1000, 1000))
        seeds = GafferScene.Seeds()
        seeds["in"].setInput(plane["out"])
        seeds["parent"].setValue("/plane")
        seeds["density"].setValue(0.01)
        sphere = GafferScene.Sphere()

        instancer = GafferScene.Instancer()
        instancer["parent"].setValue("/plane/seeds")
        instancer["in"].setInput(seeds["out"])
        instancer["instance"].setInput(sphere["out"])

        r = GafferRenderMan.InteractiveRenderManRender()
        r["in"].setInput(instancer["out"])
        r["state"].setValue(r.State.Running)

        # change the child names a couple of times. There was a problem
        # where a childnames check was happening asynchronously, leading
        # to a crash, so we're gonna check this has been fixed:

        seeds["density"].setValue(0)
        seeds["density"].setValue(0.01)

        r["state"].setValue(r.State.Stopped)
Ejemplo n.º 2
0
    def testRenderingDuringScriptDeletion(self):

        s = Gaffer.ScriptNode()

        s["p"] = GafferScene.Plane()
        s["c"] = GafferScene.Camera()
        s["c"]["transform"]["translate"]["z"].setValue(1)

        s["g"] = GafferScene.Group()
        s["g"]["in"].setInput(s["p"]["out"])
        s["g"]["in1"].setInput(s["c"]["out"])

        s["d"] = GafferScene.Outputs()
        s["d"].addOutput(
            "beauty",
            IECore.Display(
                "test", "ieDisplay", "rgba", {
                    "driverType": "ClientDisplayDriver",
                    "displayHost": "localhost",
                    "displayPort": "1559",
                    "remoteDisplayType": "GafferImage::GafferDisplayDriver",
                    "quantize": IECore.IntVectorData([0, 0, 0, 0]),
                }))

        s["d"]["in"].setInput(s["g"]["out"])

        s["m"] = GafferImage.Display()

        # connect a python function to the Display node image and data
        # received signals. this emulates what the UI does.
        def __displayCallback(plug):
            pass

        c = (
            s["m"].imageReceivedSignal().connect(__displayCallback),
            s["m"].dataReceivedSignal().connect(__displayCallback),
        )

        s["o"] = GafferScene.StandardOptions()
        s["o"]["in"].setInput(s["d"]["out"])
        s["o"]["options"]["renderCamera"]["enabled"].setValue(True)
        s["o"]["options"]["renderCamera"]["value"].setValue("/group/plane")

        s["r"] = GafferRenderMan.InteractiveRenderManRender()
        s["r"]["in"].setInput(s["o"]["out"])

        s["r"]["state"].setValue(s["r"].State.Running)

        time.sleep(1)

        # delete the script while the render is still progressing. when
        # this occurs, deletion of the render node will be triggered, which
        # will in turn stop the render. this may flush data to the display,
        # in which case it will emit its data and image received signals
        # on a separate thread. if we're still holding the gil on the main
        # thread when this happens, we'll get a deadlock.
        del s
Ejemplo n.º 3
0
	def testRenderingDuringScriptDeletion( self ) :

		s = Gaffer.ScriptNode()

		s["p"] = GafferScene.Plane()
		s["c"] = GafferScene.Camera()
		s["c"]["transform"]["translate"]["z"].setValue( 1 )

		s["g"] = GafferScene.Group()
		s["g"]["in"][0].setInput( s["p"]["out"] )
		s["g"]["in"][1].setInput( s["c"]["out"] )

		s["d"] = GafferScene.Outputs()
		s["d"].addOutput(
			"beauty",
			IECore.Display(
				"test",
				"ieDisplay",
				"rgba",
				{
					"driverType" : "ClientDisplayDriver",
					"displayHost" : "localhost",
					"displayPort" : "1559",
					"remoteDisplayType" : "GafferImage::GafferDisplayDriver",
					"quantize" : IECore.IntVectorData( [ 0, 0, 0, 0 ] ),
				}
			)
		)

		s["d"]["in"].setInput( s["g"]["out"] )

		# Emulate the connection the UI makes, so the Display knows someone is listening and
		# it needs to actually make servers.
		executeOnUIThreadConnection = GafferImage.Display.executeOnUIThreadSignal().connect( lambda f : f() )

		s["m"] = GafferImage.Display()

		s["o"] = GafferScene.StandardOptions()
		s["o"]["in"].setInput( s["d"]["out"] )
		s["o"]["options"]["renderCamera"]["enabled"].setValue( True )
		s["o"]["options"]["renderCamera"]["value"].setValue( "/group/camera" )

		s["r"] = GafferRenderMan.InteractiveRenderManRender()
		s["r"]["in"].setInput( s["o"]["out"] )

		s["r"]["state"].setValue( s["r"].State.Running )

		time.sleep( 1 )

		# delete the script while the render is still progressing. when
		# this occurs, deletion of the render node will be triggered, which
		# will in turn stop the render. this may flush data to the display,
		# in which case it will emit its data and image received signals
		# on a separate thread. if we're still holding the gil on the main
		# thread when this happens, we'll get a deadlock.
		del s
	def testChangeInputWhilePaused( self ) :

		s = Gaffer.ScriptNode()

		s["p"] = GafferScene.Plane()

		s["c"] = GafferScene.Camera()
		s["c"]["transform"]["translate"]["z"].setValue( 1 )

		s["g"] = GafferScene.Group()
		s["g"]["in"][0].setInput( s["p"]["out"] )
		s["g"]["in"][1].setInput( s["c"]["out"] )

		s["d"] = GafferScene.Outputs()
		s["d"].addOutput(
			"beauty",
			IECore.Display(
				"test",
				"ieDisplay",
				"rgba",
				{
					"quantize" : IECore.FloatVectorData( [ 0, 0, 0, 0 ] ),
					"driverType" : "ImageDisplayDriver",
					"handle" : "myLovelyPlane",
				}
			)
		)
		s["d"]["in"].setInput( s["g"]["out"] )

		s["o"] = GafferScene.StandardOptions()
		s["o"]["options"]["renderCamera"]["value"].setValue( "/group/camera" )
		s["o"]["options"]["renderCamera"]["enabled"].setValue( True )
		s["o"]["in"].setInput( s["d"]["out"] )

		s["r"] = GafferRenderMan.InteractiveRenderManRender()
		s["r"]["in"].setInput( s["o"]["out"] )

		# start a render, give it time to get going, then pause it

		s["r"]["state"].setValue( s["r"].State.Running )
		time.sleep( 2 )
		s["r"]["state"].setValue( s["r"].State.Paused )

		# change the input to the render node, and check that we don't hang

		s["o2"] = GafferScene.StandardOptions()
		s["o2"]["in"].setInput( s["o"]["out"] )

		s["r"]["in"].setInput( s["o2"]["out"] )

		# start the render again, so we know we're not just testing
		# the same thing as testDeleteWhilePaused().
		s["r"]["state"].setValue( s["r"].State.Running )
Ejemplo n.º 5
0
    def testContext(self):

        s = Gaffer.ScriptNode()

        r = GafferRenderMan.InteractiveRenderManRender()

        self.assertNotEqual(r.getContext(), None)
        self.failIf(r.getContext().isSame(s.context()))

        s["r"] = r

        self.failUnless(r.getContext().isSame(s.context()))

        s.removeChild(r)

        self.failIf(r.getContext().isSame(s.context()))
Ejemplo n.º 6
0
    def testMoveCoordinateSystem(self):

        shader = self.compileShader(
            os.path.dirname(__file__) + "/shaders/coordSysDot.sl")

        s = Gaffer.ScriptNode()

        s["plane"] = GafferScene.Plane()

        s["shader"] = GafferRenderMan.RenderManShader()
        s["shader"].loadShader(shader)
        s["shader"]["parameters"]["coordSys"].setValue(
            "/group/coordinateSystem")

        s["shaderAssignment"] = GafferScene.ShaderAssignment()
        s["shaderAssignment"]["in"].setInput(s["plane"]["out"])
        s["shaderAssignment"]["shader"].setInput(s["shader"]["out"])

        s["camera"] = GafferScene.Camera()
        s["camera"]["transform"]["translate"]["z"].setValue(1)

        s["coordSys"] = GafferScene.CoordinateSystem()

        s["g"] = GafferScene.Group()
        s["g"]["in"].setInput(s["shaderAssignment"]["out"])
        s["g"]["in1"].setInput(s["camera"]["out"])
        s["g"]["in2"].setInput(s["coordSys"]["out"])

        s["d"] = GafferScene.Outputs()
        s["d"].addOutput(
            "beauty",
            IECore.Display(
                "test", "ieDisplay", "rgba", {
                    "quantize": IECore.FloatVectorData([0, 0, 0, 0]),
                    "driverType": "ImageDisplayDriver",
                    "handle": "myLovelyPlane",
                }))
        s["d"]["in"].setInput(s["g"]["out"])

        s["o"] = GafferScene.StandardOptions()
        s["o"]["options"]["renderCamera"]["value"].setValue("/group/camera")
        s["o"]["options"]["renderCamera"]["enabled"].setValue(True)
        s["o"]["in"].setInput(s["d"]["out"])

        s["r"] = GafferRenderMan.InteractiveRenderManRender()
        s["r"]["in"].setInput(s["o"]["out"])

        # start a render, give it time to finish, and check the output

        s["r"]["state"].setValue(s["r"].State.Running)

        time.sleep(2)

        c = self.__colorAtUV(
            IECore.ImageDisplayDriver.storedImage("myLovelyPlane"),
            IECore.V2f(0.5),
        )
        self.assertAlmostEqual(c[1], 1, delta=0.001)

        # move the coordinate system, and check the output

        s["coordSys"]["transform"]["translate"]["x"].setValue(0.1)

        time.sleep(2)

        c = self.__colorAtUV(
            IECore.ImageDisplayDriver.storedImage("myLovelyPlane"),
            IECore.V2f(0.6, 0.5),
        )
        self.assertAlmostEqual(c[0], 1)

        c = self.__colorAtUV(
            IECore.ImageDisplayDriver.storedImage("myLovelyPlane"),
            IECore.V2f(0.6, 0.7),
        )
        self.assertAlmostEqual(c[0], 0)

        # scale the coordinate system to cover everything, and check again

        s["coordSys"]["transform"]["scale"].setValue(IECore.V3f(100))

        time.sleep(2)

        for p in [
                IECore.V2f(0.5),
                IECore.V2f(0.1),
                IECore.V2f(0.9),
        ]:
            c = self.__colorAtUV(
                IECore.ImageDisplayDriver.storedImage("myLovelyPlane"),
                p,
            )
            self.assertAlmostEqual(c[0], 1, delta=0.001)
Ejemplo n.º 7
0
    def testMoveCamera(self):

        s = Gaffer.ScriptNode()

        s["p"] = GafferScene.Plane()

        s["c"] = GafferScene.Camera()
        s["c"]["transform"]["translate"]["z"].setValue(1)

        s["g"] = GafferScene.Group()
        s["g"]["in"].setInput(s["p"]["out"])
        s["g"]["in1"].setInput(s["c"]["out"])

        s["d"] = GafferScene.Outputs()
        s["d"].addOutput(
            "beauty",
            IECore.Display(
                "test", "ieDisplay", "rgba", {
                    "quantize": IECore.FloatVectorData([0, 0, 0, 0]),
                    "driverType": "ImageDisplayDriver",
                    "handle": "myLovelyPlane",
                }))
        s["d"]["in"].setInput(s["g"]["out"])

        s["o"] = GafferScene.StandardOptions()
        s["o"]["options"]["renderCamera"]["value"].setValue("/group/camera")
        s["o"]["options"]["renderCamera"]["enabled"].setValue(True)
        s["o"]["in"].setInput(s["d"]["out"])

        s["r"] = GafferRenderMan.InteractiveRenderManRender()
        s["r"]["in"].setInput(s["o"]["out"])

        # start a render, give it time to finish, and check the output

        s["r"]["state"].setValue(s["r"].State.Running)

        time.sleep(2)

        c = self.__colorAtUV(
            IECore.ImageDisplayDriver.storedImage("myLovelyPlane"),
            IECore.V2f(0.5),
        )
        self.assertAlmostEqual(c[1], 1, delta=0.001)

        # move the camera so it can't see the plane, and check the output

        s["c"]["transform"]["translate"]["x"].setValue(2)

        time.sleep(2)

        c = self.__colorAtUV(
            IECore.ImageDisplayDriver.storedImage("myLovelyPlane"),
            IECore.V2f(0.5),
        )
        self.assertAlmostEqual(c[0], 0)

        # move the camera back and recheck

        s["c"]["transform"]["translate"]["x"].setValue(0)

        time.sleep(2)

        c = self.__colorAtUV(
            IECore.ImageDisplayDriver.storedImage("myLovelyPlane"),
            IECore.V2f(0.5),
        )
        self.assertAlmostEqual(c[1], 1, delta=0.001)
Ejemplo n.º 8
0
    def testLights(self):

        s = Gaffer.ScriptNode()

        s["l"] = GafferRenderMan.RenderManLight()
        s["l"].loadShader("pointlight")
        s["l"]["parameters"]["lightcolor"].setValue(
            IECore.Color3f(1, 0.5, 0.25))
        s["l"]["transform"]["translate"]["z"].setValue(1)

        s["p"] = GafferScene.Plane()

        s["c"] = GafferScene.Camera()
        s["c"]["transform"]["translate"]["z"].setValue(1)

        s["g"] = GafferScene.Group()
        s["g"]["in"].setInput(s["l"]["out"])
        s["g"]["in1"].setInput(s["p"]["out"])
        s["g"]["in2"].setInput(s["c"]["out"])

        s["s"] = GafferRenderMan.RenderManShader()
        s["s"].loadShader("matte")
        s["a"] = GafferScene.ShaderAssignment()
        s["a"]["in"].setInput(s["g"]["out"])
        s["a"]["shader"].setInput(s["s"]["out"])

        s["d"] = GafferScene.Outputs()
        s["d"].addOutput(
            "beauty",
            IECore.Display(
                "test", "ieDisplay", "rgba", {
                    "quantize": IECore.FloatVectorData([0, 0, 0, 0]),
                    "driverType": "ImageDisplayDriver",
                    "handle": "myLovelyPlane",
                }))
        s["d"]["in"].setInput(s["a"]["out"])

        s["o"] = GafferScene.StandardOptions()
        s["o"]["options"]["renderCamera"]["value"].setValue("/group/camera")
        s["o"]["options"]["renderCamera"]["enabled"].setValue(True)
        s["o"]["in"].setInput(s["d"]["out"])

        s["r"] = GafferRenderMan.InteractiveRenderManRender()
        s["r"]["in"].setInput(s["o"]["out"])

        # start a render, give it time to finish, and check the output

        s["r"]["state"].setValue(s["r"].State.Running)

        time.sleep(2)

        c = self.__colorAtUV(
            IECore.ImageDisplayDriver.storedImage("myLovelyPlane"),
            IECore.V2f(0.5),
        )
        self.assertEqual(c / c[0], IECore.Color3f(1, 0.5, 0.25))

        # adjust a parameter, give it time to update, and check the output

        s["l"]["parameters"]["lightcolor"].setValue(
            IECore.Color3f(0.25, 0.5, 1))

        time.sleep(1)

        c = self.__colorAtUV(
            IECore.ImageDisplayDriver.storedImage("myLovelyPlane"),
            IECore.V2f(0.5),
        )
        self.assertEqual(c / c[2], IECore.Color3f(0.25, 0.5, 1))

        # pause it, adjust a parameter, wait, and check that nothing changed

        s["r"]["state"].setValue(s["r"].State.Paused)
        s["l"]["parameters"]["lightcolor"].setValue(
            IECore.Color3f(1, 0.5, 0.25))

        time.sleep(1)

        c = self.__colorAtUV(
            IECore.ImageDisplayDriver.storedImage("myLovelyPlane"),
            IECore.V2f(0.5),
        )
        self.assertEqual(c / c[2], IECore.Color3f(0.25, 0.5, 1))

        # unpause it, wait, and check that the update happened

        s["r"]["state"].setValue(s["r"].State.Running)
        time.sleep(1)

        c = self.__colorAtUV(
            IECore.ImageDisplayDriver.storedImage("myLovelyPlane"),
            IECore.V2f(0.5),
        )
        self.assertEqual(c / c[0], IECore.Color3f(1, 0.5, 0.25))

        # turn off light updates, adjust a parameter, wait, and check nothing happened

        s["r"]["updateLights"].setValue(False)
        s["l"]["parameters"]["lightcolor"].setValue(
            IECore.Color3f(0.25, 0.5, 1))

        time.sleep(1)

        c = self.__colorAtUV(
            IECore.ImageDisplayDriver.storedImage("myLovelyPlane"),
            IECore.V2f(0.5),
        )
        self.assertEqual(c / c[0], IECore.Color3f(1, 0.5, 0.25))

        # turn light updates back on and check that it updates

        s["r"]["updateLights"].setValue(True)

        time.sleep(1)

        c = self.__colorAtUV(
            IECore.ImageDisplayDriver.storedImage("myLovelyPlane"),
            IECore.V2f(0.5),
        )
        self.assertEqual(c / c[2], IECore.Color3f(0.25, 0.5, 1))

        # stop the render, tweak a parameter and check that nothing happened

        s["r"]["state"].setValue(s["r"].State.Stopped)
        s["l"]["parameters"]["lightcolor"].setValue(
            IECore.Color3f(1, 0.5, 0.25))
        time.sleep(1)

        c = self.__colorAtUV(
            IECore.ImageDisplayDriver.storedImage("myLovelyPlane"),
            IECore.V2f(0.5),
        )
        self.assertEqual(c / c[2], IECore.Color3f(0.25, 0.5, 1))
Ejemplo n.º 9
0
    def testHideLight(self):

        s = Gaffer.ScriptNode()

        s["l"] = GafferRenderMan.RenderManLight()
        s["l"].loadShader("pointlight")
        s["l"]["transform"]["translate"]["z"].setValue(1)

        s["v"] = GafferScene.StandardAttributes()
        s["v"]["attributes"]["visibility"]["enabled"].setValue(True)
        s["v"]["in"].setInput(s["l"]["out"])

        s["p"] = GafferScene.Plane()

        s["c"] = GafferScene.Camera()
        s["c"]["transform"]["translate"]["z"].setValue(1)

        s["g"] = GafferScene.Group()
        s["g"]["in"].setInput(s["v"]["out"])
        s["g"]["in1"].setInput(s["p"]["out"])
        s["g"]["in2"].setInput(s["c"]["out"])

        s["s"] = GafferRenderMan.RenderManShader()
        s["s"].loadShader("matte")
        s["a"] = GafferScene.ShaderAssignment()
        s["a"]["in"].setInput(s["g"]["out"])
        s["a"]["shader"].setInput(s["s"]["out"])

        s["d"] = GafferScene.Outputs()
        s["d"].addOutput(
            "beauty",
            IECore.Display(
                "test", "ieDisplay", "rgba", {
                    "quantize": IECore.FloatVectorData([0, 0, 0, 0]),
                    "driverType": "ImageDisplayDriver",
                    "handle": "myLovelyPlane",
                }))
        s["d"]["in"].setInput(s["a"]["out"])

        s["o"] = GafferScene.StandardOptions()
        s["o"]["options"]["renderCamera"]["value"].setValue("/group/camera")
        s["o"]["options"]["renderCamera"]["enabled"].setValue(True)
        s["o"]["in"].setInput(s["d"]["out"])

        s["r"] = GafferRenderMan.InteractiveRenderManRender()
        s["r"]["in"].setInput(s["o"]["out"])

        # start a render, give it time to finish, and check the output

        s["r"]["state"].setValue(s["r"].State.Running)

        time.sleep(2)

        c = self.__colorAtUV(
            IECore.ImageDisplayDriver.storedImage("myLovelyPlane"),
            IECore.V2f(0.5),
        )
        self.assertNotEqual(c[0], 0.0)

        # remove the light by hiding it

        s["v"]["attributes"]["visibility"]["value"].setValue(False)
        time.sleep(2)

        c = self.__colorAtUV(
            IECore.ImageDisplayDriver.storedImage("myLovelyPlane"),
            IECore.V2f(0.5),
        )
        self.assertEqual(c[0], 0.0)

        # put the light back by showing it

        s["v"]["attributes"]["visibility"]["value"].setValue(True)
        time.sleep(2)

        c = self.__colorAtUV(
            IECore.ImageDisplayDriver.storedImage("myLovelyPlane"),
            IECore.V2f(0.5),
        )
        self.assertNotEqual(c[0], 0.0)
Ejemplo n.º 10
0
    def testAddLight(self):

        s = Gaffer.ScriptNode()

        s["l"] = GafferRenderMan.RenderManLight()
        s["l"].loadShader("pointlight")
        s["l"]["parameters"]["lightcolor"].setValue(IECore.Color3f(1, 0, 0))
        s["l"]["transform"]["translate"]["z"].setValue(1)

        s["p"] = GafferScene.Plane()

        s["c"] = GafferScene.Camera()
        s["c"]["transform"]["translate"]["z"].setValue(1)

        s["g"] = GafferScene.Group()
        s["g"]["in"].setInput(s["l"]["out"])
        s["g"]["in1"].setInput(s["p"]["out"])
        s["g"]["in2"].setInput(s["c"]["out"])

        s["s"] = GafferRenderMan.RenderManShader()
        s["s"].loadShader("matte")
        s["a"] = GafferScene.ShaderAssignment()
        s["a"]["in"].setInput(s["g"]["out"])
        s["a"]["shader"].setInput(s["s"]["out"])

        s["d"] = GafferScene.Outputs()
        s["d"].addOutput(
            "beauty",
            IECore.Display(
                "test", "ieDisplay", "rgba", {
                    "quantize": IECore.FloatVectorData([0, 0, 0, 0]),
                    "driverType": "ImageDisplayDriver",
                    "handle": "myLovelyPlane",
                }))
        s["d"]["in"].setInput(s["a"]["out"])

        s["o"] = GafferScene.StandardOptions()
        s["o"]["options"]["renderCamera"]["value"].setValue("/group/camera")
        s["o"]["options"]["renderCamera"]["enabled"].setValue(True)
        s["o"]["in"].setInput(s["d"]["out"])

        s["r"] = GafferRenderMan.InteractiveRenderManRender()
        s["r"]["in"].setInput(s["o"]["out"])

        # start a render, give it time to finish, and check the output

        s["r"]["state"].setValue(s["r"].State.Running)

        time.sleep(2)

        c = self.__colorAtUV(
            IECore.ImageDisplayDriver.storedImage("myLovelyPlane"),
            IECore.V2f(0.5),
        )
        self.assertEqual(c / c[0], IECore.Color3f(1, 0, 0))

        # add a light

        s["l2"] = GafferRenderMan.RenderManLight()
        s["l2"].loadShader("pointlight")
        s["l2"]["parameters"]["lightcolor"].setValue(IECore.Color3f(0, 1, 0))
        s["l2"]["transform"]["translate"]["z"].setValue(1)

        s["g"]["in3"].setInput(s["l2"]["out"])

        # give it time to update, and check the output

        time.sleep(1)

        c = self.__colorAtUV(
            IECore.ImageDisplayDriver.storedImage("myLovelyPlane"),
            IECore.V2f(0.5),
        )
        self.assertEqual(c / c[0], IECore.Color3f(1, 1, 0))
Ejemplo n.º 11
0
    def testScopesDontLeak(self):

        s = Gaffer.ScriptNode()

        s["p"] = GafferScene.Plane()
        s["p"]["transform"]["translate"].setValue(IECore.V3f(-0.6, -0.1, 0))

        s["p1"] = GafferScene.Plane()
        s["p1"]["transform"]["translate"].setValue(IECore.V3f(0.6, 0.1, 0))

        s["c"] = GafferScene.Camera()
        s["c"]["transform"]["translate"]["z"].setValue(2)

        s["l"] = GafferRenderMan.RenderManLight()
        s["l"].loadShader("ambientlight")

        s["g"] = GafferScene.Group()
        s["g"]["in"].setInput(s["p"]["out"])
        s["g"]["in1"].setInput(s["p1"]["out"])
        s["g"]["in2"].setInput(s["c"]["out"])
        s["g"]["in3"].setInput(s["l"]["out"])

        s["s"] = GafferRenderMan.RenderManShader()
        s["s"].loadShader("checker")
        s["s"]["parameters"]["blackcolor"].setValue(IECore.Color3f(1, 0, 0))
        s["s"]["parameters"]["Ka"].setValue(1)
        s["s"]["parameters"]["frequency"].setValue(1)

        s["f"] = GafferScene.PathFilter()
        s["f"]["paths"].setValue(IECore.StringVectorData(["/group/plane"]))

        s["a"] = GafferScene.ShaderAssignment()
        s["a"]["in"].setInput(s["g"]["out"])
        s["a"]["shader"].setInput(s["s"]["out"])
        s["a"]["filter"].setInput(s["f"]["out"])

        s["d"] = GafferScene.Outputs()
        s["d"].addOutput(
            "beauty",
            IECore.Display(
                "test", "ieDisplay", "rgba", {
                    "quantize": IECore.FloatVectorData([0, 0, 0, 0]),
                    "driverType": "ImageDisplayDriver",
                    "handle": "myLovelyPlanes",
                }))
        s["d"]["in"].setInput(s["a"]["out"])

        s["o"] = GafferScene.StandardOptions()
        s["o"]["options"]["renderCamera"]["value"].setValue("/group/camera")
        s["o"]["options"]["renderCamera"]["enabled"].setValue(True)
        s["o"]["options"]["renderResolution"]["value"].setValue(
            IECore.V2i(512))
        s["o"]["options"]["renderResolution"]["enabled"].setValue(True)
        s["o"]["in"].setInput(s["d"]["out"])

        s["r"] = GafferRenderMan.InteractiveRenderManRender()
        s["r"]["in"].setInput(s["o"]["out"])

        # start a render, give it time to finish, and check the output.
        # we should have a red plane on the left, and a facing ratio
        # shaded plane on the right, because we attached no shader to the
        # second plane.

        s["r"]["state"].setValue(s["r"].State.Running)

        time.sleep(2)

        c = self.__colorAtUV(
            IECore.ImageDisplayDriver.storedImage("myLovelyPlanes"),
            IECore.V2f(0.25, 0.5),
        )
        self.assertEqual(c, IECore.Color3f(1, 0, 0))

        c1 = self.__colorAtUV(
            IECore.ImageDisplayDriver.storedImage("myLovelyPlanes"),
            IECore.V2f(0.75, 0.5),
        )
        self.assertTrue(c1[0] > 0.9)
        self.assertEqual(c1[0], c1[1])
        self.assertEqual(c1[0], c1[2])

        # adjust a shader parameter, wait, and check that the plane
        # on the left changed. check that the plane on the right didn't
        # change at all.

        s["s"]["parameters"]["blackcolor"].setValue(IECore.Color3f(0, 1, 0))
        time.sleep(2)

        c = self.__colorAtUV(
            IECore.ImageDisplayDriver.storedImage("myLovelyPlanes"),
            IECore.V2f(0.25, 0.5),
        )
        self.assertEqual(c, IECore.Color3f(0, 1, 0))

        c1 = self.__colorAtUV(
            IECore.ImageDisplayDriver.storedImage("myLovelyPlanes"),
            IECore.V2f(0.75, 0.5),
        )
        self.assertTrue(c1[0] > 0.9)
        self.assertEqual(c1[0], c1[1])
        self.assertEqual(c1[0], c1[2])
Ejemplo n.º 12
0
    def testAttributes(self):

        s = Gaffer.ScriptNode()

        s["p"] = GafferScene.Plane()
        s["p"]["transform"]["translate"].setValue(IECore.V3f(-0.1, -0.1, 0))

        s["c"] = GafferScene.Camera()
        s["c"]["transform"]["translate"]["z"].setValue(1)

        s["l"] = GafferRenderMan.RenderManLight()
        s["l"].loadShader("ambientlight")

        s["g"] = GafferScene.Group()
        s["g"]["in"].setInput(s["p"]["out"])
        s["g"]["in1"].setInput(s["c"]["out"])
        s["g"]["in2"].setInput(s["l"]["out"])

        s["s"] = GafferRenderMan.RenderManShader()
        s["s"].loadShader("checker")
        s["s"]["parameters"]["blackcolor"].setValue(
            IECore.Color3f(1, 0.5, 0.25))
        s["s"]["parameters"]["Ka"].setValue(1)
        s["s"]["parameters"]["frequency"].setValue(1)

        s["a"] = GafferScene.ShaderAssignment()
        s["a"]["in"].setInput(s["g"]["out"])
        s["a"]["shader"].setInput(s["s"]["out"])

        s["d"] = GafferScene.Outputs()
        s["d"].addOutput(
            "beauty",
            IECore.Display(
                "test", "ieDisplay", "rgba", {
                    "quantize": IECore.FloatVectorData([0, 0, 0, 0]),
                    "driverType": "ImageDisplayDriver",
                    "handle": "myLovelyPlane",
                }))
        s["d"]["in"].setInput(s["a"]["out"])

        s["o"] = GafferScene.StandardOptions()
        s["o"]["options"]["renderCamera"]["value"].setValue("/group/camera")
        s["o"]["options"]["renderCamera"]["enabled"].setValue(True)
        s["o"]["in"].setInput(s["d"]["out"])

        s["r"] = GafferRenderMan.InteractiveRenderManRender()
        s["r"]["in"].setInput(s["o"]["out"])

        # start a render, give it time to finish, and check the output

        s["r"]["state"].setValue(s["r"].State.Running)

        time.sleep(2)

        c = self.__colorAtUV(
            IECore.ImageDisplayDriver.storedImage("myLovelyPlane"),
            IECore.V2f(0.5),
        )
        self.assertEqual(c, IECore.Color3f(1, 0.5, 0.25))

        # adjust a shader parameter, wait, and check that it changed

        s["s"]["parameters"]["blackcolor"].setValue(IECore.Color3f(1, 1, 1))
        time.sleep(1)
        c = self.__colorAtUV(
            IECore.ImageDisplayDriver.storedImage("myLovelyPlane"),
            IECore.V2f(0.5),
        )
        self.assertEqual(c, IECore.Color3f(1))

        # turn off shader updates, do the same, and check that it hasn't changed

        s["r"]["updateAttributes"].setValue(False)
        s["s"]["parameters"]["blackcolor"].setValue(IECore.Color3f(0.5))
        time.sleep(1)
        c = self.__colorAtUV(
            IECore.ImageDisplayDriver.storedImage("myLovelyPlane"),
            IECore.V2f(0.5),
        )
        self.assertEqual(c, IECore.Color3f(1))

        # turn shader updates back on, and check that it updates

        s["r"]["updateAttributes"].setValue(True)
        time.sleep(1)
        c = self.__colorAtUV(
            IECore.ImageDisplayDriver.storedImage("myLovelyPlane"),
            IECore.V2f(0.5),
        )
        self.assertEqual(c, IECore.Color3f(0.5))