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 ) )
def test(self): p = GafferScene.Plane() a = GafferScene.Attributes() a["in"].setInput(p["out"]) a["attributes"].addMember("user:something", IECore.StringData("$a")) d = Gaffer.DeleteContextVariables() d.setup(GafferScene.ScenePlug()) d["in"].setInput(a["out"]) c = Gaffer.ContextVariables() c.setup(GafferScene.ScenePlug()) c["in"].setInput(d["out"]) c["variables"].addMember("a", IECore.StringData("aardvark")) self.assertEqual(a["out"].attributes("/plane")["user:something"], IECore.StringData("")) self.assertEqual(c["out"].attributes("/plane")["user:something"], IECore.StringData("aardvark")) d["variables"].setValue("a") self.assertEqual(c["out"].attributes("/plane")["user:something"], IECore.StringData(""))
def testOverrideAttributes(self): sphere = IECore.SpherePrimitive() input = GafferSceneTest.CompoundObjectSource() input["in"].setValue( IECore.CompoundObject({ "bound": IECore.Box3fData(sphere.bound()), "children": { "ball1": { "object": sphere, "bound": IECore.Box3fData(sphere.bound()), }, }, })) a = GafferScene.Attributes() a["in"].setInput(input["out"]) a["attributes"].addMember("ri:shadingRate", IECore.FloatData(0.25)) a["attributes"].addMember("user:something", IECore.IntData(1)) self.assertEqual( a["out"].attributes("/ball1"), IECore.CompoundObject({ "ri:shadingRate": IECore.FloatData(0.25), "user:something": IECore.IntData(1), })) a2 = GafferScene.Attributes() a2["in"].setInput(a["out"]) self.assertEqual( a2["out"].attributes("/ball1"), IECore.CompoundObject({ "ri:shadingRate": IECore.FloatData(0.25), "user:something": IECore.IntData(1), })) a2["attributes"].addMember("ri:shadingRate", IECore.FloatData(.5)) a2["attributes"].addMember("user:somethingElse", IECore.IntData(10)) self.assertEqual( a2["out"].attributes("/ball1"), IECore.CompoundObject({ "ri:shadingRate": IECore.FloatData(0.5), "user:something": IECore.IntData(1), "user:somethingElse": IECore.IntData(10), }))
def testHashPassThrough(self): sphere = IECore.SpherePrimitive() input = GafferSceneTest.CompoundObjectSource() input["in"].setValue( IECore.CompoundObject({ "bound": IECore.Box3fData(sphere.bound()), "children": { "ball1": { "object": sphere, "bound": IECore.Box3fData(sphere.bound()), }, "ball2": { "object": sphere, "bound": IECore.Box3fData(sphere.bound()), }, }, })) a = GafferScene.Attributes() a["in"].setInput(input["out"]) # when we have no attributes at all, everything should be a pass-through self.assertSceneHashesEqual(input["out"], a["out"]) # when we have some attributes, everything except the attributes plug should # be a pass-through. a["attributes"].addMember("ri:shadingRate", IECore.FloatData(2.0)) self.assertSceneHashesEqual(input["out"], a["out"], childPlugNames=("globals", "childNames", "transform", "bound", "object")) self.assertSceneHashesNotEqual(input["out"], a["out"], childPlugNames=("attributes", )) # when we add a filter, non-matching objects should become pass-throughs f = GafferScene.PathFilter() f["paths"].setValue(IECore.StringVectorData(["/ball1"])) a["filter"].setInput(f["match"]) self.assertSceneHashesEqual(input["out"], a["out"], pathsToIgnore=("/ball1", )) c = Gaffer.Context() c["scene:path"] = IECore.InternedStringVectorData(["ball1"]) with c: self.assertEqual(a["out"]["childNames"].hash(), input["out"]["childNames"].hash()) self.assertEqual(a["out"]["transform"].hash(), input["out"]["transform"].hash()) self.assertEqual(a["out"]["bound"].hash(), input["out"]["bound"].hash()) self.assertEqual(a["out"]["object"].hash(), input["out"]["object"].hash()) self.assertNotEqual(a["out"]["attributes"].hash(), input["out"]["attributes"].hash())
def testSerialisation(self): s = Gaffer.ScriptNode() s["a"] = GafferScene.Attributes() s["a"]["attributes"].addMember("ri:shadingRate", IECore.FloatData(1.0)) s2 = Gaffer.ScriptNode() s2.execute(s.serialise()) self.assertEqual(len(s2["a"]["attributes"]), 1) self.assertTrue("attributes1" not in s2["a"])
def testBox( self ) : s = Gaffer.ScriptNode() s["p"] = GafferScene.Plane() s["a"] = GafferScene.Attributes() s["a"]["in"].setInput( s["p"]["out"] ) s["f"] = GafferScene.PathFilter() s["a"]["filter"].setInput( s["f"]["out"] ) b = Gaffer.Box.create( s, Gaffer.StandardSet( [ s["a"] ] ) )
def test(self): sphere = IECore.SpherePrimitive() input = GafferSceneTest.CompoundObjectSource() input["in"].setValue( IECore.CompoundObject({ "bound": IECore.Box3fData(sphere.bound()), "children": { "ball1": { "object": sphere, "bound": IECore.Box3fData(sphere.bound()), }, "ball2": { "object": sphere, "bound": IECore.Box3fData(sphere.bound()), }, }, })) a = GafferScene.Attributes() a["in"].setInput(input["out"]) # should be no attributes until we've specified any self.assertEqual(a["out"].attributes("/"), IECore.CompoundObject()) self.assertEqual(a["out"].attributes("/ball1"), IECore.CompoundObject()) self.assertEqual(a["out"].attributes("/ball2"), IECore.CompoundObject()) # when we specify some, they should be applied to everything because # we haven't specified a filter yet. but not to the root because it # isn't allowed attributes. a["attributes"].addMember("ri:shadingRate", IECore.FloatData(0.25)) self.assertEqual(a["out"].attributes("/"), IECore.CompoundObject()) self.assertEqual( a["out"].attributes("/ball1"), IECore.CompoundObject({"ri:shadingRate": IECore.FloatData(0.25)})) self.assertEqual( a["out"].attributes("/ball2"), IECore.CompoundObject({"ri:shadingRate": IECore.FloatData(0.25)})) # finally once we've applied a filter, we should get some attributes. f = GafferScene.PathFilter() f["paths"].setValue(IECore.StringVectorData(["/ball1"])) a["filter"].setInput(f["match"]) self.assertEqual(a["out"].attributes("/"), IECore.CompoundObject()) self.assertEqual( a["out"].attributes("/ball1"), IECore.CompoundObject({"ri:shadingRate": IECore.FloatData(0.25)})) self.assertEqual(a["out"].attributes("/ball2"), IECore.CompoundObject())
def testCopyPaste( self ) : s = Gaffer.ScriptNode() s["f"] = GafferScene.PathFilter() s["a"] = GafferScene.Attributes() s["a"]["filter"].setInput( s["f"]["out"] ) ss = s.serialise( s, Gaffer.StandardSet( [ s["a"] ] ) ) s.execute( ss ) self.assertTrue( isinstance( s["a1"], GafferScene.Attributes ) ) self.assertEqual( s["a1"]["filter"].getInput(), None )
def testRendering(self): sphere = IECore.SpherePrimitive() input = GafferSceneTest.CompoundObjectSource() input["in"].setValue( IECore.CompoundObject({ "bound": IECore.Box3fData(sphere.bound()), "children": { "ball1": { "object": sphere, "bound": IECore.Box3fData(sphere.bound()), }, }, })) a = GafferScene.Attributes() a["in"].setInput(input["out"]) a["attributes"].addMember("ri:shadingRate", IECore.FloatData(0.25)) a["attributes"].addMember("user:something", IECore.IntData(1)) r = IECore.CapturingRenderer() with IECore.WorldBlock(r): r.procedural( GafferScene.SceneProcedural(a["out"], Gaffer.Context(), "/")) g = r.world() attributes = g.children()[0].children()[0].children()[0].children( )[0].state()[0] self.assertEqual( attributes.attributes, IECore.CompoundData({ "name": IECore.StringData("/ball1"), "ri:shadingRate": IECore.FloatData(0.25), "user:something": IECore.IntData(1), }))