Example #1
0
    def testForwardDeclarations(self):

        light1 = GafferSceneTest.TestLight()
        light2 = GafferSceneTest.TestLight()

        group = GafferScene.Group()
        group["in"].setInput(light1["out"])
        group["in1"].setInput(light2["out"])

        fd = group["out"]["globals"].getValue()["gaffer:forwardDeclarations"]
        self.assertEqual(set(fd.keys()), set(["/group/light",
                                              "/group/light1"]))

        isolate = GafferScene.Isolate()
        isolate["in"].setInput(group["out"])

        fd = isolate["out"]["globals"].getValue()["gaffer:forwardDeclarations"]
        self.assertEqual(set(fd.keys()), set(["/group/light",
                                              "/group/light1"]))

        filter = GafferScene.PathFilter()
        isolate["filter"].setInput(filter["match"])

        fd = isolate["out"]["globals"].getValue()["gaffer:forwardDeclarations"]
        self.assertEqual(set(fd.keys()), set([]))

        filter["paths"].setValue(IECore.StringVectorData(["/group/light"]))
        fd = isolate["out"]["globals"].getValue()["gaffer:forwardDeclarations"]
        self.assertEqual(set(fd.keys()), set(["/group/light"]))

        filter["paths"].setValue(IECore.StringVectorData(["/group/light*"]))
        fd = isolate["out"]["globals"].getValue()["gaffer:forwardDeclarations"]
        self.assertEqual(set(fd.keys()), set(["/group/light",
                                              "/group/light1"]))
Example #2
0
	def testSetsWhenAncestorPruned( self ) :

		light1 = GafferSceneTest.TestLight()
		light2 = GafferSceneTest.TestLight()

		group1 = GafferScene.Group()
		group2 = GafferScene.Group()

		group1["in"][0].setInput( light1["out"] )
		group2["in"][0].setInput( light1["out"] )

		topGroup = GafferScene.Group()
		topGroup["in"][0].setInput( group1["out"] )
		topGroup["in"][1].setInput( group2["out"] )

		lightSet = topGroup["out"].set( "__lights" )
		self.assertEqual( set( lightSet.value.paths() ), set( [ "/group/group/light", "/group/group1/light" ] ) )

		filter = GafferScene.PathFilter()
		filter["paths"].setValue( IECore.StringVectorData( [ "/group/group" ] ) )

		prune = GafferScene.Prune()
		prune["in"].setInput( topGroup["out"] )
		prune["filter"].setInput( filter["out"] )

		lightSet = prune["out"].set( "__lights" )
		self.assertEqual( set( lightSet.value.paths() ), set( [ "/group/group1/light" ] ) )
Example #3
0
	def testSetsWithRenaming( self ) :

		l1 = GafferSceneTest.TestLight()
		l2 = GafferSceneTest.TestLight()

		g = GafferScene.Group()
		g["in"][0].setInput( l1["out"] )
		g["in"][1].setInput( l2["out"] )

		lightSet = g["out"].set( "__lights" )
		self.assertEqual(
			set( lightSet.value.paths() ),
			set( [
				"/group/light",
				"/group/light1",
			] )
		)

		self.assertSceneValid( g["out"] )

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

		lightSet = g2["out"].set( "__lights" )
		self.assertEqual(
			set( lightSet.value.paths() ),
			set( [
				"/group/group/light",
				"/group/group/light1",
			] )
		)
Example #4
0
	def testSets( self ) :

		light1 = GafferSceneTest.TestLight()
		light2 = GafferSceneTest.TestLight()

		group = GafferScene.Group()
		group["in"].setInput( light1["out"] )
		group["in1"].setInput( light2["out"] )

		lightSet = group["out"]["globals"].getValue()["gaffer:sets"]["__lights"]
		self.assertEqual( set( lightSet.value.paths() ), set( [ "/group/light", "/group/light1" ] ) )

		prune = GafferScene.Prune()
		prune["in"].setInput( group["out"] )

		lightSet = prune["out"]["globals"].getValue()["gaffer:sets"]["__lights"]
		self.assertEqual( set( lightSet.value.paths() ), set( [ "/group/light", "/group/light1" ] ) )

		filter = GafferScene.PathFilter()
		prune["filter"].setInput( filter["match"] )

		lightSet = prune["out"]["globals"].getValue()["gaffer:sets"]["__lights"]
		self.assertEqual( set( lightSet.value.paths() ), set( [ "/group/light", "/group/light1" ] ) )

		filter["paths"].setValue( IECore.StringVectorData( [ "/group/light" ] ) )
		lightSet = prune["out"]["globals"].getValue()["gaffer:sets"]["__lights"]
		self.assertEqual( set( lightSet.value.paths() ), set( [ "/group/light1" ] ) )

		filter["paths"].setValue( IECore.StringVectorData( [ "/group/light*" ] ) )
		lightSet = prune["out"]["globals"].getValue()["gaffer:sets"]["__lights"]
		self.assertEqual( lightSet.value.paths(), [] )
Example #5
0
    def testSets(self):

        light1 = GafferSceneTest.TestLight()
        light2 = GafferSceneTest.TestLight()

        group = GafferScene.Group()
        group["in"][0].setInput(light1["out"])
        group["in"][1].setInput(light2["out"])

        lightSet = group["out"].set("__lights")
        self.assertEqual(set(lightSet.value.paths()),
                         set(["/group/light", "/group/light1"]))

        isolate = GafferScene.Isolate()
        isolate["in"].setInput(group["out"])

        lightSet = isolate["out"].set("__lights")
        self.assertEqual(set(lightSet.value.paths()),
                         set(["/group/light", "/group/light1"]))

        filter = GafferScene.PathFilter()
        isolate["filter"].setInput(filter["out"])

        lightSet = isolate["out"].set("__lights")
        self.assertEqual(set(lightSet.value.paths()), set([]))

        filter["paths"].setValue(IECore.StringVectorData(["/group/light"]))
        lightSet = isolate["out"].set("__lights")
        self.assertEqual(set(lightSet.value.paths()), set(["/group/light"]))

        filter["paths"].setValue(IECore.StringVectorData(["/group/light*"]))
        lightSet = isolate["out"].set("__lights")
        self.assertEqual(set(lightSet.value.paths()),
                         set(["/group/light", "/group/light1"]))
Example #6
0
    def testForwardDeclarationsWhenAncestorPruned(self):

        light1 = GafferSceneTest.TestLight()
        light2 = GafferSceneTest.TestLight()

        group1 = GafferScene.Group()
        group2 = GafferScene.Group()

        group1["in"].setInput(light1["out"])
        group2["in"].setInput(light1["out"])

        topGroup = GafferScene.Group()
        topGroup["in"].setInput(group1["out"])
        topGroup["in1"].setInput(group2["out"])

        fd = topGroup["out"]["globals"].getValue(
        )["gaffer:forwardDeclarations"]
        self.assertEqual(set(fd.keys()),
                         set(["/group/group/light", "/group/group1/light"]))

        filter = GafferScene.PathFilter()
        filter["paths"].setValue(IECore.StringVectorData(["/group/group"]))

        prune = GafferScene.Prune()
        prune["in"].setInput(topGroup["out"])
        prune["filter"].setInput(filter["match"])

        fd = prune["out"]["globals"].getValue()["gaffer:forwardDeclarations"]
        self.assertEqual(set(fd.keys()), set(["/group/group1/light"]))
    def testLightLinkPerformance(self):

        numSpheres = 10000
        numLights = 1000

        # Make a bunch of spheres

        sphere = GafferScene.Sphere()

        spherePlane = GafferScene.Plane()
        spherePlane["name"].setValue("spheres")
        spherePlane["divisions"].setValue(imath.V2i(1, numSpheres / 2 - 1))

        sphereInstancer = GafferScene.Instancer()
        sphereInstancer["in"].setInput(spherePlane["out"])
        sphereInstancer["prototypes"].setInput(sphere["out"])
        sphereInstancer["parent"].setValue("/spheres")

        # Make a bunch of lights

        light = GafferSceneTest.TestLight()

        lightPlane = GafferScene.Plane()
        lightPlane["name"].setValue("lights")
        lightPlane["divisions"].setValue(imath.V2i(1, numLights / 2 - 1))

        lightInstancer = GafferScene.Instancer()
        lightInstancer["in"].setInput(lightPlane["out"])
        lightInstancer["prototypes"].setInput(light["out"])
        lightInstancer["parent"].setValue("/lights")

        # Make a single non-default light. This
        # will trigger linking of all the others.

        nonDefaultLight = GafferSceneTest.TestLight()
        nonDefaultLight["defaultLight"].setValue(False)

        # Group everything into one scene

        group = GafferScene.Group()
        group["in"][0].setInput(sphereInstancer["out"])
        group["in"][1].setInput(lightInstancer["out"])
        group["in"][2].setInput(nonDefaultLight["out"])

        # See how quickly we can output those links

        renderer = GafferScene.Private.IECoreScenePreview.CapturingRenderer()
        controller = GafferScene.RenderController(group["out"],
                                                  Gaffer.Context(), renderer)
        controller.setMinimumExpansionDepth(10)

        with GafferTest.TestRunner.PerformanceScope():
            controller.update()

        # Sanity check that we did output links as expected.

        links = renderer.capturedObject(
            "/group/spheres/instances/sphere/0").capturedLinks("lights")
        self.assertEqual(len(links), numLights)
Example #8
0
	def testSetsWithWithRenaming( self ) :

		l1 = GafferSceneTest.TestLight()
		l2 = GafferSceneTest.TestLight()

		p = GafferScene.Parent()
		p["in"].setInput( l1["out"] )
		p["child"].setInput( l2["out"] )
		p["parent"].setValue( "/" )

		self.assertSceneValid( p["out"] )
		self.assertEqual( p["out"].childNames( "/" ), IECore.InternedStringVectorData( [ "light", "light1" ] ) )

		self.assertEqual( p["out"]["setNames"].getValue(), IECore.InternedStringVectorData( [ "__lights" ] ) )
		self.assertEqual( set(  p["out"].set( "__lights" ).value.paths() ), set( [ "/light", "/light1" ] ) )
Example #9
0
    def testForwardDeclarationPassThroughWhenNoRoot(self):

        l = GafferSceneTest.TestLight()
        g = GafferScene.Group()
        g["in"].setInput(l["out"])

        s = GafferScene.SubTree()
        s["in"].setInput(g["out"])

        forwardDeclarations = s["out"]["globals"].getValue(
        )["gaffer:forwardDeclarations"]
        self.assertEqual(forwardDeclarations.keys(), ["/group/light"])
        self.assertForwardDeclarationsValid(s["out"])

        s["root"].setValue("/")
        forwardDeclarations = s["out"]["globals"].getValue(
        )["gaffer:forwardDeclarations"]
        self.assertEqual(forwardDeclarations.keys(), ["/group/light"])
        self.assertForwardDeclarationsValid(s["out"])

        # with includeRoot == True

        s["includeRoot"].setValue(True)

        s["root"].setValue("")
        forwardDeclarations = s["out"]["globals"].getValue(
        )["gaffer:forwardDeclarations"]
        self.assertEqual(forwardDeclarations.keys(), ["/group/light"])
        self.assertForwardDeclarationsValid(s["out"])

        s["root"].setValue("/")
        forwardDeclarations = s["out"]["globals"].getValue(
        )["gaffer:forwardDeclarations"]
        self.assertEqual(forwardDeclarations.keys(), ["/group/light"])
        self.assertForwardDeclarationsValid(s["out"])
Example #10
0
	def testAreaLight( self ) :

		s = Gaffer.ScriptNode()
		s["fileName"].setValue( self.temporaryDirectory() + "/test.gfr" )

		s["l"] = GafferSceneTest.TestLight()
		s["l"]["parameters"]["areaLight"].setValue( True );

		s["g"] = GafferScene.Group()
		s["g"]["in"][0].setInput( s["l"]["out"] )

		self.assertSceneValid( s["g"]["out"] )

		s["r"] = GafferSceneTest.TestRender()
		s["r"]["in"].setInput( s["g"]["out"] )

		# CapturingRenderer outputs some spurious errors which
		# we suppress by capturing them.
		with IECore.CapturingMessageHandler() :
			s["r"].execute()

		w = s["r"].world()

		# Check that we get just one group with both attributes and the light when writing area lights,
		# instead of the extra attribute block
		self.assertEqual( w.children()[0].state()[0].attributes["name"].value, "/group/light" )
		self.assertEqual( w.children()[0].state()[1].handle, "/group/light" )
Example #11
0
	def testLightAttributes( self ) :

		s = Gaffer.ScriptNode()
		s["fileName"].setValue( self.temporaryDirectory() + "/test.gfr" )

		s["l"] = GafferSceneTest.TestLight()

		s["a"] = GafferScene.Attributes()
		s["a"]["in"].setInput( s["l"]["out"] )
		s["a"]["attributes"].addMember( "user:test", IECore.IntData( 10 ) )

		s["r"] = GafferSceneTest.TestRender()
		s["r"]["in"].setInput( s["a"]["out"] )

		# CapturingRenderer outputs some spurious errors which
		# we suppress by capturing them.
		with IECore.CapturingMessageHandler() :
			s["r"].execute()

		w = s["r"].world()
		l = w.children()[0].state()
		self.assertTrue( isinstance( l[0], IECore.AttributeState ) )
		self.assertEqual( l[0].attributes["user:test"], IECore.IntData( 10 ) )
		l2 = w.children()[0].children()[0].state()
		self.assertTrue( isinstance( l2[0], IECore.Light ) )
Example #12
0
    def testNullObjects(self):

        camera = GafferScene.Camera()
        sphere = GafferScene.Sphere()
        light = GafferSceneTest.TestLight()

        lightAttr = GafferScene.StandardAttributes()
        lightAttr["in"].setInput(sphere["out"])
        lightAttr["attributes"]["linkedLights"]["enabled"].setValue(True)
        lightAttr["attributes"]["linkedLights"]["value"].setValue(
            "defaultLights")

        group = GafferScene.Group()
        group["in"][0].setInput(camera["out"])
        group["in"][1].setInput(sphere["out"])
        group["in"][2].setInput(light["out"])

        allFilter = GafferScene.PathFilter()
        allFilter["paths"].setValue(IECore.StringVectorData(["..."]))

        attr = GafferScene.CustomAttributes()
        unrenderableAttrPlug = Gaffer.NameValuePlug(
            "cr:unrenderable",
            IECore.BoolData(True),
            flags=Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic)
        attr["attributes"].addChild(unrenderableAttrPlug)
        attr["filter"].setInput(allFilter["out"])
        attr["in"].setInput(group["out"])

        renderer = GafferScene.Private.IECoreScenePreview.CapturingRenderer()
        controller = GafferScene.RenderController(attr["out"],
                                                  Gaffer.Context(), renderer)
        controller.setMinimumExpansionDepth(10)
        controller.update()
Example #13
0
	def testSetsWithDiamondInput( self ) :

		#	l
		#	| \
		#	|  \
		#	lg1 lg2
		#	|  /
		#	| /
		#	g

		l = GafferSceneTest.TestLight()

		lg1 = GafferScene.Group()
		lg1["name"].setValue( "lightGroup1" )
		lg1["in"][0].setInput( l["out"] )

		lg2 = GafferScene.Group()
		lg2["name"].setValue( "lightGroup2" )
		lg2["in"][0].setInput( l["out"] )

		self.assertEqual( lg1["out"]["globals"].hash(), lg2["out"]["globals"].hash() )

		g = GafferScene.Group()
		g["in"][0].setInput( lg1["out"] )
		g["in"][1].setInput( lg2["out"] )

		lightSet = g["out"].set( "__lights" )
		self.assertEqual(
			set( lightSet.value.paths() ),
			set( [
				"/group/lightGroup1/light",
				"/group/lightGroup2/light",
			] )
		)
	def testParameterEditsDontAffectOtherAttributes( self ) :

		light = GafferSceneTest.TestLight()

		lightFilter = GafferScene.PathFilter()
		lightFilter["paths"].setValue( IECore.StringVectorData( [ "/light" ] ) )

		shuffleAttributes = GafferScene.ShuffleAttributes()
		shuffleAttributes["in"].setInput( light["out"] )
		shuffleAttributes["filter"].setInput( lightFilter["out"] )

		editScope = Gaffer.EditScope()
		editScope.setup( shuffleAttributes["out"] )
		editScope["in"].setInput( shuffleAttributes["out"] )

		# Make an edit for the "light" attribute.

		edit = GafferScene.EditScopeAlgo.acquireParameterEdit( editScope, "/light", "light", ( "", "intensity" ) )
		edit["enabled"].setValue( True )
		edit["value"].setValue( imath.Color3f( 1, 2, 3 ) )
		self.assertEqual(
			editScope["out"].attributes( "/light" )["light"].outputShader().parameters["intensity"].value,
			imath.Color3f( 1, 2, 3 )
		)

		# Shuffle the light shader to another attribute. It should not be affected
		# by the edit.

		shuffleAttributes["shuffles"].addChild( Gaffer.ShufflePlug( "light", "test:light" ) )
		self.assertEqual(
			editScope["out"].attributes( "/light" )["test:light"].outputShader().parameters["intensity"].value,
			imath.Color3f( 0 )
		)
	def testParameterEditReadOnlyReason( self ) :

		s = Gaffer.ScriptNode()

		s["light"] = GafferSceneTest.TestLight()

		s["scope"] = Gaffer.EditScope()
		s["scope"].setup( s["light"]["out"] )
		s["scope"]["in"].setInput( s["light"]["out"] )

		s["box"] = Gaffer.Box.create( s, Gaffer.StandardSet( [ s["light"], s["scope"] ] ) )

		self.assertIsNone( GafferScene.EditScopeAlgo.parameterEditReadOnlyReason( s["box"]["scope"], "/light", "light", ( "", "intensity" ) ) )

		for component in ( s["box"], s["box"]["scope"] ):
			Gaffer.MetadataAlgo.setReadOnly( component, True )
			self.assertEqual( GafferScene.EditScopeAlgo.parameterEditReadOnlyReason( s["box"]["scope"], "/light", "light", ( "", "intensity" ) ), s["box"] )

		Gaffer.MetadataAlgo.setReadOnly( s["box"], False )
		self.assertEqual( GafferScene.EditScopeAlgo.parameterEditReadOnlyReason( s["box"]["scope"], "/light", "light", ( "", "intensity" ) ), s["box"]["scope"] )

		Gaffer.MetadataAlgo.setReadOnly( s["box"]["scope"], False )
		GafferScene.EditScopeAlgo.acquireParameterEdit( s["box"]["scope"], "/light", "light", ( "", "intensity" ) )

		self.assertIsNone( GafferScene.EditScopeAlgo.parameterEditReadOnlyReason( s["box"]["scope"], "/light", "light", ( "", "intensity" ) ) )

		candidateComponents = (
			s["box"]["scope"]["LightEdits"]["edits"][1]["cells"]["intensity"]["value"]["value"][1],
			s["box"]["scope"]["LightEdits"]["edits"][1]["cells"]["intensity"]["value"]["mode"],
			s["box"]["scope"]["LightEdits"]["edits"][1]["cells"]["intensity"]["value"]["enabled"],
			s["box"]["scope"]["LightEdits"]["edits"][1]["cells"]["intensity"]["value"]["name"],
			s["box"]["scope"]["LightEdits"]["edits"][1]["cells"]["intensity"]["value"],
			s["box"]["scope"]["LightEdits"]["edits"][1]["cells"]["intensity"],
			s["box"]["scope"]["LightEdits"]["edits"][1]["cells"],
			s["box"]["scope"]["LightEdits"]["edits"][1],
			s["box"]["scope"]["LightEdits"]["edits"],
			s["box"]["scope"]["LightEdits"],
			s["box"]["scope"],
			s["box"]
		)

		for component in candidateComponents :
			Gaffer.MetadataAlgo.setReadOnly( component, True )
			self.assertEqual( GafferScene.EditScopeAlgo.parameterEditReadOnlyReason( s["box"]["scope"], "/light", "light", ( "", "intensity" ) ), component )

		for component in candidateComponents :
			Gaffer.MetadataAlgo.setReadOnly( component, False )

		# We can't remove parameter edits, they're just disabled (as the row is shared with other parameters),
		# so we try to create one for another light instead
		s["box"]["light"]["name"].setValue( "light2" )

		self.assertIsNone( GafferScene.EditScopeAlgo.acquireParameterEdit( s["box"]["scope"], "/light2", "light", ( "", "intensity" ), createIfNecessary = False ) )

		for component in (
			s["box"]["scope"]["LightEdits"]["edits"],
			s["box"]["scope"]["LightEdits"]
		) :
			Gaffer.MetadataAlgo.setReadOnly( component, True )
			self.assertEqual( GafferScene.EditScopeAlgo.parameterEditReadOnlyReason( s["box"]["scope"], "/light2", "light", ( "", "intensity" ) ), component )
Example #16
0
    def testDisabled(self):

        l = GafferSceneTest.TestLight()
        self.assertTrue("gaffer:sets" in l["out"]["globals"].getValue())

        l["enabled"].setValue(False)
        self.assertFalse("gaffer:sets" in l["out"]["globals"].getValue())
Example #17
0
	def testForwardDeclarationsWithDiamondInput( self ) :

		#	l
		#	| \
		#	|  \
		#	lg1 lg2
		#	|  /
		#	| /
		#	g

		l = GafferSceneTest.TestLight()

		lg1 = GafferScene.Group()
		lg1["name"].setValue( "lightGroup1" )
		lg1["in"].setInput( l["out"] )

		lg2 = GafferScene.Group()
		lg2["name"].setValue( "lightGroup2" )
		lg2["in"].setInput( l["out"] )

		self.assertNotEqual( lg1["out"]["globals"].hash(), lg2["out"]["globals"].hash() )

		g = GafferScene.Group()
		g["in"].setInput( lg1["out"] )
		g["in1"].setInput( lg2["out"] )

		forwardDeclarations = g["out"]["globals"].getValue()["gaffer:forwardDeclarations"]

		self.assertEqual( len( forwardDeclarations ), 2 )
		self.assertEqual( forwardDeclarations["/group/lightGroup1/light"]["type"].value, IECore.Light.staticTypeId() )
		self.assertEqual( forwardDeclarations["/group/lightGroup2/light"]["type"].value, IECore.Light.staticTypeId() )
Example #18
0
    def test(self):

        l = GafferSceneTest.TestLight()

        self.assertSceneValid(l["out"])

        self.assertEqual(l["out"].object("/"), IECore.NullObject())
        self.assertEqual(l["out"].transform("/"), IECore.M44f())
        self.assertEqual(l["out"].childNames("/"),
                         IECore.InternedStringVectorData(["light"]))

        self.assertTrue(isinstance(l["out"].object("/light"), IECore.Light))

        self.assertEqual(l["out"].transform("/light"), IECore.M44f())
        self.assertEqual(l["out"].childNames("/light"),
                         IECore.InternedStringVectorData())

        forwardDeclarations = l["out"]["globals"].getValue(
        )["gaffer:forwardDeclarations"]
        self.assertEqual(
            forwardDeclarations,
            IECore.CompoundData({
                "/light": {
                    "type": IECore.IntData(IECore.TypeId.Light),
                },
            }))
Example #19
0
    def test(self):

        l = GafferSceneTest.TestLight()

        self.assertSceneValid(l["out"])

        self.assertEqual(l["out"].object("/"), IECore.NullObject())
        self.assertEqual(l["out"].transform("/"), imath.M44f())
        self.assertEqual(l["out"].childNames("/"),
                         IECore.InternedStringVectorData(["light"]))

        self.assertTrue(
            isinstance(l["out"].object("/light"), IECore.NullObject))
        self.assertTrue(
            isinstance(l["out"].attributes("/light")["light"][-1],
                       IECoreScene.Shader))

        self.assertEqual(l["out"].transform("/light"), imath.M44f())
        self.assertEqual(l["out"].childNames("/light"),
                         IECore.InternedStringVectorData())

        self.assertEqual(l["out"]["setNames"].getValue(),
                         IECore.InternedStringVectorData(["__lights"]))
        lightSet = l["out"].set("__lights")
        self.assertEqual(
            lightSet, IECore.PathMatcherData(IECore.PathMatcher(["/light"])))
Example #20
0
    def testSetsPassThroughWhenNoRoot(self):

        l = GafferSceneTest.TestLight()
        g = GafferScene.Group()
        g["in"][0].setInput(l["out"])

        s = GafferScene.SubTree()
        s["in"].setInput(g["out"])

        lightSet = s["out"].set("__lights")
        self.assertEqual(lightSet.value.paths(), ["/group/light"])
        self.assertSetsValid(s["out"])

        s["root"].setValue("/")
        lightSet = s["out"].set("__lights")
        self.assertEqual(lightSet.value.paths(), ["/group/light"])
        self.assertSetsValid(s["out"])

        # with includeRoot == True

        s["includeRoot"].setValue(True)

        s["root"].setValue("")
        lightSet = s["out"].set("__lights")
        self.assertEqual(lightSet.value.paths(), ["/group/light"])
        self.assertSetsValid(s["out"])

        s["root"].setValue("/")
        lightSet = s["out"].set("__lights")
        self.assertEqual(lightSet.value.paths(), ["/group/light"])
        self.assertSetsValid(s["out"])
Example #21
0
    def testDisabled(self):

        l = GafferSceneTest.TestLight()
        self.assertTrue("__lights" in l["out"]["setNames"].getValue())

        l["enabled"].setValue(False)
        self.assertFalse("__lights" in l["out"]["setNames"].getValue())
Example #22
0
    def testForwardDeclarationsFromOmittedBranchAreOmitted(self):

        # /group
        #	/lightGroup1
        #		/light
        #	/lightGroup2
        #		/light
        #	/lightGroup
        #		/light
        #	/lightGroup10
        #		/light

        l = GafferSceneTest.TestLight()

        lg1 = GafferScene.Group()
        lg1["name"].setValue("lightGroup1")
        lg1["in"].setInput(l["out"])

        lg2 = GafferScene.Group()
        lg2["name"].setValue("lightGroup2")
        lg2["in"].setInput(l["out"])

        lg3 = GafferScene.Group()
        lg3["name"].setValue("lightGroup")
        lg3["in"].setInput(l["out"])

        lg4 = GafferScene.Group()
        lg4["name"].setValue("lightGroup10")
        lg4["in"].setInput(l["out"])

        g = GafferScene.Group()
        g["in"].setInput(lg1["out"])
        g["in1"].setInput(lg2["out"])
        g["in2"].setInput(lg3["out"])
        g["in3"].setInput(lg4["out"])

        self.assertForwardDeclarationsValid(g["out"])

        # /light

        s = GafferScene.SubTree()
        s["in"].setInput(g["out"])
        s["root"].setValue("/group/lightGroup1")

        forwardDeclarations = s["out"]["globals"].getValue(
        )["gaffer:forwardDeclarations"]
        self.assertEqual(forwardDeclarations.keys(), ["/light"])

        self.assertForwardDeclarationsValid(s["out"])

        # with includeRoot == True

        s["includeRoot"].setValue(True)

        forwardDeclarations = s["out"]["globals"].getValue(
        )["gaffer:forwardDeclarations"]
        self.assertEqual(forwardDeclarations.keys(), ["/lightGroup1/light"])

        self.assertForwardDeclarationsValid(s["out"])
Example #23
0
	def testDisabledHasNoSets( self ) :

		l = GafferSceneTest.TestLight()
		l["sets"].setValue( "A B")
		self.assertEqual( l["out"]["setNames"].getValue(), IECore.InternedStringVectorData( [ "A", "B", "__lights", "defaultLights" ] ) )

		l["enabled"].setValue( False )
		self.assertEqual( l["out"]["setNames"].getValue(), IECore.InternedStringVectorData() )
Example #24
0
    def testHideLinkedLight(self):

        # One default light and one non-default light, which will
        # result in light links being emitted to the renderer.

        defaultLight = GafferSceneTest.TestLight()
        defaultLight["name"].setValue("defaultLight")
        defaultLightAttributes = GafferScene.StandardAttributes()
        defaultLightAttributes["in"].setInput(defaultLight["out"])

        nonDefaultLight = GafferSceneTest.TestLight()
        nonDefaultLight["name"].setValue("nonDefaultLight")
        nonDefaultLight["defaultLight"].setValue(False)

        plane = GafferScene.Plane()

        group = GafferScene.Group()
        group["in"][0].setInput(defaultLightAttributes["out"])
        group["in"][1].setInput(nonDefaultLight["out"])
        group["in"][2].setInput(plane["out"])

        # Output a scene. Only the default light should be linked.

        renderer = GafferScene.Private.IECoreScenePreview.CapturingRenderer()
        controller = GafferScene.RenderController(group["out"],
                                                  Gaffer.Context(), renderer)
        controller.setMinimumExpansionDepth(10)
        controller.update()

        capturedPlane = renderer.capturedObject("/group/plane")

        self.assertEqual(capturedPlane.capturedLinks("lights"),
                         {renderer.capturedObject("/group/defaultLight")})

        # Hide the default light. It should be removed from the render,
        # and the plane should be linked to an empty light set.

        defaultLightAttributes["attributes"]["visibility"]["enabled"].setValue(
            True)
        defaultLightAttributes["attributes"]["visibility"]["value"].setValue(
            False)
        controller.update()

        self.assertIsNone(renderer.capturedObject("/group/defaultLight"))
        self.assertEqual(capturedPlane.capturedLinks("lights"), set())
Example #25
0
    def testForwardDeclarationsFromOmittedBranchAreOmitted(self):

        # /group
        #	/lightGroup1
        #		/light
        #	/lightGroup2
        #		/light
        #	/lightGroup
        #		/light
        #	/lightGroup10
        #		/light

        l = GafferSceneTest.TestLight()

        lg1 = GafferScene.Group()
        lg1["name"].setValue("lightGroup1")
        lg1["in"][0].setInput(l["out"])

        lg2 = GafferScene.Group()
        lg2["name"].setValue("lightGroup2")
        lg2["in"][0].setInput(l["out"])

        lg3 = GafferScene.Group()
        lg3["name"].setValue("lightGroup")
        lg3["in"][0].setInput(l["out"])

        lg4 = GafferScene.Group()
        lg4["name"].setValue("lightGroup10")
        lg4["in"][0].setInput(l["out"])

        g = GafferScene.Group()
        g["in"][0].setInput(lg1["out"])
        g["in"][1].setInput(lg2["out"])
        g["in"][2].setInput(lg3["out"])
        g["in"][3].setInput(lg4["out"])

        self.assertSetsValid(g["out"])

        # /light

        s = GafferScene.SubTree()
        s["in"].setInput(g["out"])
        s["root"].setValue("/group/lightGroup1")

        lightSet = s["out"].set("__lights")
        self.assertEqual(lightSet.value.paths(), ["/light"])

        self.assertSetsValid(s["out"])

        # with includeRoot == True

        s["includeRoot"].setValue(True)

        lightSet = s["out"].set("__lights")
        self.assertEqual(lightSet.value.paths(), ["/lightGroup1/light"])

        self.assertSetsValid(s["out"])
Example #26
0
    def test(self):

        light = GafferSceneTest.TestLight()
        camera = GafferScene.Camera()
        procedural = GafferScene.ExternalProcedural()
        group = GafferScene.Group()

        group["in"][0].setInput(light["out"])
        group["in"][1].setInput(camera["out"])
        group["in"][2].setInput(procedural["out"])

        parameters = GafferScene.Parameters()
        parameters["in"].setInput(group["out"])

        self.assertSceneValid(parameters["out"])
        self.assertScenesEqual(parameters["out"], group["out"])
        self.assertSceneHashesEqual(parameters["out"], group["out"])

        parameters["parameters"].addMember("test", 10)

        filter = GafferScene.PathFilter()
        filter["paths"].setValue(IECore.StringVectorData(["/group/*"]))
        parameters["filter"].setInput(filter["out"])

        self.assertSceneValid(parameters["out"])
        self.assertScenesEqual(parameters["out"],
                               group["out"],
                               childPlugNamesToIgnore=("object", ))
        self.assertSceneHashesEqual(parameters["out"],
                                    group["out"],
                                    childPlugNamesToIgnore=("object", ))

        lightIn = group["out"].object("/group/light")
        lightOut = parameters["out"].object("/group/light")
        self.assertNotEqual(lightIn, lightOut)
        self.assertEqual(lightOut.parameters["test"], IECore.IntData(10))
        del lightOut.parameters["test"]
        self.assertEqual(lightIn, lightOut)
        self.assertTrue(isinstance(lightOut, IECore.Light))

        cameraIn = group["out"].object("/group/camera")
        cameraOut = parameters["out"].object("/group/camera")
        self.assertNotEqual(cameraIn, cameraOut)
        self.assertEqual(cameraOut.parameters()["test"], IECore.IntData(10))
        del cameraOut.parameters()["test"]
        self.assertEqual(cameraIn, cameraOut)
        self.assertTrue(isinstance(cameraOut, IECore.Camera))

        proceduralIn = group["out"].object("/group/procedural")
        proceduralOut = parameters["out"].object("/group/procedural")
        self.assertNotEqual(proceduralIn, proceduralOut)
        self.assertEqual(proceduralOut.parameters()["test"],
                         IECore.IntData(10))
        del proceduralOut.parameters()["test"]
        self.assertEqual(proceduralIn, proceduralOut)
        self.assertTrue(isinstance(proceduralOut, IECore.ExternalProcedural))
Example #27
0
	def testTransformAffectsParentBound( self ) :

		l = GafferSceneTest.TestLight()

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

		# No transform

		self.assertEqual(
			l["out"].bound( "/" ),
			imath.Box3f( imath.V3f( -0.5 ), imath.V3f( 0.5 ) ),
		)
		self.assertEqual(
			l["out"].bound( "/light" ),
			imath.Box3f( imath.V3f( -0.5 ), imath.V3f( 0.5 ) ),
		)

		self.assertEqual(
			g["out"].bound( "/" ),
			imath.Box3f( imath.V3f( -0.5 ), imath.V3f( 0.5 ) ),
		)
		self.assertEqual(
			g["out"].bound( "/group" ),
			imath.Box3f( imath.V3f( -0.5 ), imath.V3f( 0.5 ) ),
		)
		self.assertEqual(
			g["out"].bound( "/group/light" ),
			imath.Box3f( imath.V3f( -0.5 ), imath.V3f( 0.5 ) ),
		)

		# Transform

		l["transform"]["translate"].setValue( imath.V3f( 1 ) )

		self.assertEqual(
			l["out"].bound( "/" ),
			imath.Box3f( imath.V3f( 0.5 ), imath.V3f( 1.5 ) ),
		)
		self.assertEqual(
			l["out"].bound( "/light" ),
			imath.Box3f( imath.V3f( -0.5 ), imath.V3f( 0.5 ) ),
		)

		self.assertEqual(
			g["out"].bound( "/" ),
			imath.Box3f( imath.V3f( 0.5 ), imath.V3f( 1.5 ) ),
		)
		self.assertEqual(
			g["out"].bound( "/group" ),
			imath.Box3f( imath.V3f( 0.5 ), imath.V3f( 1.5 ) ),
		)
		self.assertEqual(
			g["out"].bound( "/group/light" ),
			imath.Box3f( imath.V3f( -0.5 ), imath.V3f( 0.5 ) ),
		)
Example #28
0
	def testNonExistentSets( self ) :

		l = GafferSceneTest.TestLight()
		l["sets"].setValue( "A B")
		self.assertEqual( l["out"]["setNames"].getValue(), IECore.InternedStringVectorData( [ "A", "B", "__lights", "defaultLights" ] ) )

		self.assertEqual( l["out"].set( "" ), IECore.PathMatcherData() )
		self.assertEqual( l["out"].set( "nonexistent1" ), IECore.PathMatcherData() )
		self.assertEqual( l["out"].setHash( "nonexistent1" ), l["out"].setHash( "nonexistent2" ) )
		self.assertTrue( l["out"].set( "nonexistent1", _copy = False ).isSame( l["out"].set( "nonexistent2", _copy = False ) ) )
Example #29
0
	def testAdditionalSets( self ) :

		l = GafferSceneTest.TestLight()
		self.assertEqual( l["out"]["setNames"].getValue(), IECore.InternedStringVectorData( [ "__lights", "defaultLights" ] ) )

		l["sets"].setValue( "A B")
		self.assertEqual( l["out"]["setNames"].getValue(), IECore.InternedStringVectorData( [ "A", "B", "__lights", "defaultLights" ] ) )

		self.assertTrue( l["out"].set( "A", _copy = False ).isSame( l["out"].set( "B", _copy = False ) ) )
		self.assertTrue( l["out"].set( "B", _copy = False ).isSame( l["out"].set( "__lights", _copy = False ) ) )
Example #30
0
    def testDirtyPropagation(self):

        l = GafferSceneTest.TestLight()
        cs = GafferTest.CapturingSlot(l.plugDirtiedSignal())
        self.assertEqual(len(cs), 0)

        l["parameters"]["intensity"]["r"].setValue(10)

        dirtiedNames = [p[0].relativeName(p[0].node()) for p in cs]
        self.assertTrue("out.attributes" in dirtiedNames)
        self.assertTrue("out" in dirtiedNames)