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)
def testLightFiltersMany(self): # \todo: this can easily be turned into a performance test s = Gaffer.ScriptNode() s["lightFilter"] = GafferArnold.ArnoldLightFilter() s["lightFilter"].loadShader("light_blocker") s["lightFilter"]["filteredLights"].setValue("defaultLights") s["planeFilters"] = GafferScene.Plane("Plane") s["planeFilters"]["divisions"].setValue(imath.V2i(9)) s["instancerFilters"] = GafferScene.Instancer("Instancer") s["instancerFilters"]["in"].setInput(s["planeFilters"]["out"]) s["instancerFilters"]["instances"].setInput(s["lightFilter"]["out"]) s["instancerFilters"]["parent"].setValue("/plane") s["light"] = GafferArnold.ArnoldLight() s["light"].loadShader("point_light") s["planeLights"] = GafferScene.Plane("Plane") s["planeLights"]["divisions"].setValue(imath.V2i(9)) s["instancerLights"] = GafferScene.Instancer("Instancer") s["instancerLights"]["in"].setInput(s["planeLights"]["out"]) s["instancerLights"]["instances"].setInput(s["light"]["out"]) s["instancerLights"]["parent"].setValue("/plane") s["group"] = GafferScene.Group("Group") s["group"]["in"][0].setInput(s["instancerFilters"]["out"]) s["group"]["in"][1].setInput(s["instancerLights"]["out"]) s["render"] = GafferArnold.ArnoldRender() s["render"]["in"].setInput(s["group"]["out"]) s["render"]["mode"].setValue(s["render"].Mode.SceneDescriptionMode) s["render"]["fileName"].setValue(self.temporaryDirectory() + "/testMany.ass") s["render"]["task"].execute() with IECoreArnold.UniverseBlock(writable=True): foo = self.temporaryDirectory() + "/testMany.ass" print foo arnold.AiASSLoad(foo) for i in range(100): light = arnold.AiNodeLookUpByName( "light:/group/plane1/instances/light/%s" % i) linkedFilters = arnold.AiNodeGetArray(light, "filters") numFilters = arnold.AiArrayGetNumElements( linkedFilters.contents) self.assertEqual(numFilters, 100)
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)
def testLoadReferenceAndGIL( self ) : script = Gaffer.ScriptNode() script["plane"] = GafferScene.Plane() script["plane"]["divisions"].setValue( imath.V2i( 20 ) ) script["sphere"] = GafferScene.Sphere() script["expression"] = Gaffer.Expression() script["expression"].setExpression( "parent['sphere']['radius'] = 0.1 + context.getFrame()" ) script["instancer"] = GafferScene.Instancer() script["instancer"]["in"].setInput( script["plane"]["out"] ) script["instancer"]["instances"].setInput( script["sphere"]["out"] ) script["instancer"]["parent"].setValue( "/plane" ) script["box"] = Gaffer.Box() script["box"]["in"] = GafferScene.ScenePlug( flags = Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic ) script["box"]["out"] = GafferScene.ScenePlug( direction = Gaffer.Plug.Direction.Out, flags = Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic ) script["box"]["out"].setInput( script["box"]["in"] ) script["box"].exportForReference( self.temporaryDirectory() + "/test.grf" ) script["reference"] = Gaffer.Reference() script["reference"].load( self.temporaryDirectory() + "/test.grf" ) script["reference"]["in"].setInput( script["instancer"]["out"] ) script["attributes"] = GafferScene.CustomAttributes() script["attributes"]["in"].setInput( script["reference"]["out"] ) traverseConnection = Gaffer.ScopedConnection( GafferSceneTest.connectTraverseSceneToPlugDirtiedSignal( script["attributes"]["out"] ) ) with Gaffer.Context() as c : script["reference"].load( self.temporaryDirectory() + "/test.grf" )
def testDuplicateIds(self): points = IECoreScene.PointsPrimitive( IECore.V3fVectorData([imath.V3f(x, 0, 0) for x in range(6)])) points["id"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, IECore.IntVectorData([0, 0, 2, 2, 4, 4]), ) objectToScene = GafferScene.ObjectToScene() objectToScene["object"].setValue(points) sphere = GafferScene.Sphere() instancer = GafferScene.Instancer() instancer["in"].setInput(objectToScene["out"]) instancer["instances"].setInput(sphere["out"]) instancer["parent"].setValue("/object") instancer["id"].setValue("id") self.assertSceneValid(instancer["out"]) self.assertEqual( instancer["out"].childNames("/object/instances/sphere"), IECore.InternedStringVectorData(["0", "2", "4"])) self.assertEqual( instancer["out"].transform("/object/instances/sphere/0"), imath.M44f().translate(imath.V3f(0, 0, 0))) self.assertEqual( instancer["out"].transform("/object/instances/sphere/2"), imath.M44f().translate(imath.V3f(2, 0, 0))) self.assertEqual( instancer["out"].transform("/object/instances/sphere/4"), imath.M44f().translate(imath.V3f(4, 0, 0)))
def test(self): sphere = GafferScene.Sphere() plane = GafferScene.Plane() group = GafferScene.Group() group["in"][0].setInput(sphere["out"]) group["in"][1].setInput(plane["out"]) plane2 = GafferScene.Plane() plane2["divisions"].setValue(imath.V2i(99, 99)) # 10000 instances instancer = GafferScene.Instancer() instancer["in"].setInput(plane2["out"]) instancer["parent"].setValue("/plane") instancer["instances"].setInput(group["out"]) filter = GafferScene.PathFilter() filter["paths"].setValue( IECore.StringVectorData(["/plane/instances/group/*1/plane"])) matchingPaths = IECore.PathMatcher() GafferScene.SceneAlgo.matchingPaths(filter, instancer["out"], matchingPaths) self.assertEqual(len(matchingPaths.paths()), 1000) self.assertEqual(matchingPaths.match("/plane/instances/group/1/plane"), IECore.PathMatcher.Result.ExactMatch) self.assertEqual( matchingPaths.match("/plane/instances/group/1121/plane"), IECore.PathMatcher.Result.ExactMatch) self.assertEqual( matchingPaths.match("/plane/instances/group/1121/sphere"), IECore.PathMatcher.Result.NoMatch)
def testDispatchAndGIL(self): script = Gaffer.ScriptNode() script["plane"] = GafferScene.Plane() script["plane"]["divisions"].setValue(imath.V2i(20)) script["sphere"] = GafferScene.Sphere() script["expression"] = Gaffer.Expression() script["expression"].setExpression( "parent['sphere']['radius'] = context.get( 'minRadius', 0.1 ) + context.getFrame()" ) script["instancer"] = GafferScene.Instancer() script["instancer"]["in"].setInput(script["plane"]["out"]) script["instancer"]["instances"].setInput(script["sphere"]["out"]) script["instancer"]["parent"].setValue("/plane") script["pythonCommand"] = GafferDispatch.PythonCommand() script["pythonCommand"]["command"].setValue("pass") traverseConnection = Gaffer.ScopedConnection( GafferSceneTest.connectTraverseSceneToPreDispatchSignal( script["instancer"]["out"])) dispatcher = GafferDispatch.LocalDispatcher() dispatcher["jobsDirectory"].setValue(self.temporaryDirectory()) with Gaffer.Context() as c: for i in range(1, 10): c.setFrame(i) dispatcher.dispatch([script["pythonCommand"]])
def testAffects(self): n = GafferScene.Instancer() a = n.affects(n["name"]) self.assertGreaterEqual({x.relativeName(n) for x in a}, {"out.childNames", "out.bound", "out.set"})
def testOutputIntoExpression( self ) : script = Gaffer.ScriptNode() script["plane"] = GafferScene.Plane() script["sphere"] = GafferScene.Sphere() script["instancer"] = GafferScene.Instancer() script["instancer"]["in"].setInput( script["plane"]["out"] ) script["instancer"]["instance"].setInput( script["sphere"]["out"] ) script["instancer"]["parent"].setValue( "/plane" ) script["filter"] = GafferScene.PathFilter() script["filter"]["paths"].setValue( IECore.StringVectorData( [ "/plane/instances/*/sphere" ] ) ) script["filterResults"] = GafferScene.FilterResults() script["filterResults"]["scene"].setInput( script["instancer"]["out"] ) script["filterResults"]["filter"].setInput( script["filter"]["out"] ) script["filterResults"]["user"]["strings"] = Gaffer.StringVectorDataPlug( defaultValue = IECore.StringVectorData() ) script["expression"] = Gaffer.Expression() script["expression"].setExpression( "parent['filterResults']['user']['strings'] = IECore.StringVectorData( sorted( parent['filterResults']['out'].value.paths() ) )" ) self.assertEqual( script["filterResults"]["user"]["strings"].getValue(), IECore.StringVectorData( [ "/plane/instances/0/sphere", "/plane/instances/1/sphere", "/plane/instances/2/sphere", "/plane/instances/3/sphere", ] ) )
def testMonitorMatchingPaths(self): plane = GafferScene.Plane() plane["divisions"].setValue(imath.V2i(1000, 100)) sphere = GafferScene.Sphere() instancer = GafferScene.Instancer() instancer["in"].setInput(plane["out"]) instancer["instances"].setInput(sphere["out"]) instancer["parent"].setValue("/plane") filter = GafferScene.PathFilter() filter["paths"].setValue( IECore.StringVectorData(["/plane/instances/sphere/*"])) paths = IECore.PathMatcher() with Gaffer.PerformanceMonitor() as m: GafferScene.SceneAlgo.matchingPaths(filter["out"], instancer["out"], paths) self.assertEqual( m.plugStatistics(filter["out"]).computeCount, len(instancer["out"].childNames("/plane/instances/sphere")) + 4, )
def testNegativeIdsAndIndices(self): points = IECoreScene.PointsPrimitive( IECore.V3fVectorData([imath.V3f(x, 0, 0) for x in range(0, 2)])) points["id"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, IECore.IntVectorData([-10, -5]), ) points["index"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, IECore.IntVectorData([-1, -2]), ) objectToScene = GafferScene.ObjectToScene() objectToScene["object"].setValue(points) sphere = GafferScene.Sphere() cube = GafferScene.Cube() instances = GafferScene.Parent() instances["in"].setInput(sphere["out"]) instances["child"].setInput(cube["out"]) instances["parent"].setValue("/") instancer = GafferScene.Instancer() instancer["in"].setInput(objectToScene["out"]) instancer["instances"].setInput(instances["out"]) instancer["parent"].setValue("/object") instancer["index"].setValue("index") instancer["id"].setValue("id") self.assertEqual(instancer["out"].childNames("/object/instances"), IECore.InternedStringVectorData(["sphere", "cube"])) self.assertEqual( instancer["out"].childNames("/object/instances/sphere"), IECore.InternedStringVectorData(["-5"])) self.assertEqual(instancer["out"].childNames("/object/instances/cube"), IECore.InternedStringVectorData(["-10"])) self.assertEqual( instancer["out"].childNames("/object/instances/sphere/-5"), IECore.InternedStringVectorData()) self.assertEqual( instancer["out"].childNames("/object/instances/cube/-10"), IECore.InternedStringVectorData()) self.assertEqual(instancer["out"].object("/object/instances"), IECore.NullObject.defaultNullObject()) self.assertEqual(instancer["out"].object("/object/instances/sphere"), IECore.NullObject.defaultNullObject()) self.assertEqual(instancer["out"].object("/object/instances/cube"), IECore.NullObject.defaultNullObject()) self.assertEqual( instancer["out"].object("/object/instances/sphere/-5"), sphere["out"].object("/sphere")) self.assertEqual(instancer["out"].object("/object/instances/cube/-10"), cube["out"].object("/cube")) self.assertSceneValid(instancer["out"])
def testObjectsAt( self ) : plane = GafferScene.Plane() sphere = GafferScene.Sphere() sphere["radius"].setValue( 0.25 ) instancer = GafferScene.Instancer() instancer["in"].setInput( plane["out"] ) instancer["instances"].setInput( sphere["out"] ) instancer["parent"].setValue( "/plane" ) subTree = GafferScene.SubTree() subTree["in"].setInput( instancer["out"] ) subTree["root"].setValue( "/plane" ) sg = GafferSceneUI.SceneGadget() sg.setScene( subTree["out"] ) sg.setMinimumExpansionDepth( 100 ) with GafferUI.Window() as w : gw = GafferUI.GadgetWidget( sg ) w.setVisible( True ) self.waitForIdle( 10000 ) gw.getViewportGadget().frame( sg.bound() ) self.waitForIdle( 10000 ) self.assertObjectsAt( sg, imath.Box2f( imath.V2f( 0 ), imath.V2f( 1 ) ), [ "/instances/sphere/{}".format( i ) for i in range( 0, 4 ) ] ) self.assertObjectsAt( sg, imath.Box2f( imath.V2f( 0 ), imath.V2f( 0.5 ) ), [ "/instances/sphere/2" ] ) self.assertObjectsAt( sg, imath.Box2f( imath.V2f( 0.5, 0 ), imath.V2f( 1, 0.5 ) ), [ "/instances/sphere/3" ] ) self.assertObjectsAt( sg, imath.Box2f( imath.V2f( 0, 0.5 ), imath.V2f( 0.5, 1 ) ), [ "/instances/sphere/0" ] ) self.assertObjectsAt( sg, imath.Box2f( imath.V2f( 0.5 ), imath.V2f( 1 ) ), [ "/instances/sphere/1" ] )
def testThreading(self): sphere = IECore.SpherePrimitive() instanceInput = GafferSceneTest.CompoundObjectSource() instanceInput["in"].setValue( IECore.CompoundObject({ "bound": IECore.Box3fData(IECore.Box3f(IECore.V3f(-2), IECore.V3f(2))), "children": { "sphere": { "object": sphere, "bound": IECore.Box3fData(sphere.bound()), "transform": IECore.M44fData(IECore.M44f.createScaled( IECore.V3f(2))), }, } })) seeds = IECore.PointsPrimitive( IECore.V3fVectorData([ IECore.V3f(1, 0, 0), IECore.V3f(1, 1, 0), IECore.V3f(0, 1, 0), IECore.V3f(0, 0, 0) ])) seedsInput = GafferSceneTest.CompoundObjectSource() seedsInput["in"].setValue( IECore.CompoundObject( { "bound": IECore.Box3fData( IECore.Box3f(IECore.V3f(1, 0, 0), IECore.V3f(2, 1, 0))), "children": { "seeds": { "bound": IECore.Box3fData(seeds.bound()), "transform": IECore.M44fData( IECore.M44f.createTranslated( IECore.V3f(1, 0, 0))), "object": seeds, }, }, }, )) instancer = GafferScene.Instancer() instancer["in"].setInput(seedsInput["out"]) instancer["instance"].setInput(instanceInput["out"]) instancer["parent"].setValue("/seeds") instancer["name"].setValue("instances") GafferSceneTest.traverseScene(instancer["out"])
def testContextChangedAndGIL( self ) : script = Gaffer.ScriptNode() script["plane"] = GafferScene.Plane() script["plane"]["divisions"].setValue( imath.V2i( 20 ) ) script["sphere"] = GafferScene.Sphere() script["expression"] = Gaffer.Expression() script["expression"].setExpression( "parent['sphere']['radius'] = context.get( 'minRadius', 0.1 ) + context.getFrame()" ) script["instancer"] = GafferScene.Instancer() script["instancer"]["in"].setInput( script["plane"]["out"] ) script["instancer"]["instances"].setInput( script["sphere"]["out"] ) script["instancer"]["parent"].setValue( "/plane" ) context = Gaffer.Context() traverseConnection = Gaffer.ScopedConnection( GafferSceneTest.connectTraverseSceneToContextChangedSignal( script["instancer"]["out"], context ) ) with context : context.setFrame( 10 ) context.setFramesPerSecond( 50 ) context.setTime( 1 ) context.set( "a", 1 ) context.set( "a", 2.0 ) context.set( "a", "a" ) context.set( "a", imath.V2i() ) context.set( "a", imath.V3i() ) context.set( "a", imath.V2f() ) context.set( "a", imath.V3f() ) context.set( "a", imath.Color3f() ) context.set( "a", IECore.BoolData( True ) ) context["b"] = 1 context["b"] = 2.0 context["b"] = "b" context["b"] = imath.V2i() context["b"] = imath.V3i() context["b"] = imath.V2f() context["b"] = imath.V3f() context["b"] = imath.Color3f() context["b"] = IECore.BoolData( True ) with Gaffer.BlockedConnection( traverseConnection ) : # Must add it with the connection disabled, otherwise # the addition causes a traversal, and then remove() gets # all its results from the cache. context["minRadius"] = 0.2 context.remove( "minRadius" ) with Gaffer.BlockedConnection( traverseConnection ) : context["minRadius"] = 0.3 del context["minRadius"]
def testEmptyName(self): plane = GafferScene.Plane() instancer = GafferScene.Instancer() instancer["in"].setInput(plane["out"]) instancer["parent"].setValue("/plane") instancer["name"].setValue("") self.assertScenesEqual(instancer["out"], plane["out"])
def testUnconnectedInstanceInput(self): plane = GafferScene.Plane() plane["sets"].setValue("A") plane["divisions"].setValue(imath.V2i(1, 500)) instancer = GafferScene.Instancer() instancer["in"].setInput(plane["out"]) instancer["parent"].setValue("/plane") self.assertEqual(instancer["out"].set("A").value.paths(), ["/plane"])
def testIds( self ) : points = IECoreScene.PointsPrimitive( IECore.V3fVectorData( [ imath.V3f( x, 0, 0 ) for x in range( 0, 4 ) ] ) ) points["id"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, IECore.IntVectorData( [ 10, 100, 111, 5 ] ), ) points["index"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, IECore.IntVectorData( [ 0, 1, 0, 1 ] ), ) objectToScene = GafferScene.ObjectToScene() objectToScene["object"].setValue( points ) sphere = GafferScene.Sphere() cube = GafferScene.Cube() instances = GafferScene.Parent() instances["in"].setInput( sphere["out"] ) instances["child"].setInput( cube["out"] ) instances["parent"].setValue( "/" ) instancer = GafferScene.Instancer() instancer["in"].setInput( objectToScene["out"] ) instancer["instances"].setInput( instances["out"] ) instancer["parent"].setValue( "/object" ) instancer["index"].setValue( "index" ) instancer["id"].setValue( "id" ) self.assertEqual( instancer["out"].childNames( "/object/instances" ), IECore.InternedStringVectorData( [ "sphere", "cube" ] ) ) self.assertEqual( instancer["out"].childNames( "/object/instances/sphere" ), IECore.InternedStringVectorData( [ "10", "111" ] ) ) self.assertEqual( instancer["out"].childNames( "/object/instances/cube" ), IECore.InternedStringVectorData( [ "100", "5" ] ) ) self.assertEqual( instancer["out"].childNames( "/object/instances/sphere/10" ), IECore.InternedStringVectorData() ) self.assertEqual( instancer["out"].childNames( "/object/instances/sphere/111" ), IECore.InternedStringVectorData() ) self.assertEqual( instancer["out"].childNames( "/object/instances/cube/100" ), IECore.InternedStringVectorData() ) self.assertEqual( instancer["out"].childNames( "/object/instances/cube/5" ), IECore.InternedStringVectorData() ) self.assertEqual( instancer["out"].object( "/object/instances" ), IECore.NullObject.defaultNullObject() ) self.assertEqual( instancer["out"].object( "/object/instances/sphere" ), IECore.NullObject.defaultNullObject() ) self.assertEqual( instancer["out"].object( "/object/instances/cube" ), IECore.NullObject.defaultNullObject() ) self.assertEqual( instancer["out"].object( "/object/instances/sphere/10" ), sphere["out"].object( "/sphere" ) ) self.assertEqual( instancer["out"].object( "/object/instances/sphere/111" ), sphere["out"].object( "/sphere" ) ) self.assertEqual( instancer["out"].object( "/object/instances/cube/100" ), cube["out"].object( "/cube" ) ) self.assertEqual( instancer["out"].object( "/object/instances/cube/5" ), cube["out"].object( "/cube" ) ) self.assertEqual( instancer["out"].transform( "/object/instances" ), imath.M44f() ) self.assertEqual( instancer["out"].transform( "/object/instances/sphere" ), imath.M44f() ) self.assertEqual( instancer["out"].transform( "/object/instances/cube" ), imath.M44f() ) self.assertEqual( instancer["out"].transform( "/object/instances/sphere/10" ), imath.M44f() ) self.assertEqual( instancer["out"].transform( "/object/instances/sphere/111" ), imath.M44f().translate( imath.V3f( 2, 0, 0 ) ) ) self.assertEqual( instancer["out"].transform( "/object/instances/cube/100" ), imath.M44f().translate( imath.V3f( 1, 0, 0 ) ) ) self.assertEqual( instancer["out"].transform( "/object/instances/cube/5" ), imath.M44f().translate( imath.V3f( 3, 0, 0 ) ) ) self.assertSceneValid( instancer["out"] )
def testLightFiltersMany(self): numLights = 10000 numLightFilters = 10000 s = Gaffer.ScriptNode() s["lightFilter"] = GafferArnold.ArnoldLightFilter() s["lightFilter"].loadShader("light_blocker") s["lightFilter"]["filteredLights"].setValue("defaultLights") s["planeFilters"] = GafferScene.Plane("Plane") s["planeFilters"]["divisions"].setValue( imath.V2i(1, numLightFilters / 2 - 1)) s["instancerFilters"] = GafferScene.Instancer("Instancer") s["instancerFilters"]["in"].setInput(s["planeFilters"]["out"]) s["instancerFilters"]["instances"].setInput(s["lightFilter"]["out"]) s["instancerFilters"]["parent"].setValue("/plane") s["light"] = GafferArnold.ArnoldLight() s["light"].loadShader("point_light") s["planeLights"] = GafferScene.Plane("Plane") s["planeLights"]["divisions"].setValue(imath.V2i(1, numLights / 2 - 1)) s["instancerLights"] = GafferScene.Instancer("Instancer") s["instancerLights"]["in"].setInput(s["planeLights"]["out"]) s["instancerLights"]["instances"].setInput(s["light"]["out"]) s["instancerLights"]["parent"].setValue("/plane") s["group"] = GafferScene.Group("Group") s["group"]["in"][0].setInput(s["instancerFilters"]["out"]) s["group"]["in"][1].setInput(s["instancerLights"]["out"]) s["render"] = GafferArnold.ArnoldRender() s["render"]["in"].setInput(s["group"]["out"]) with Gaffer.Context() as c: c["scene:render:sceneTranslationOnly"] = IECore.BoolData(True) s["render"]["task"].execute()
def testGILManagement(self): script = Gaffer.ScriptNode() # Build a contrived scene that will cause `childNames` queries to spawn # a threaded compute that will execute a Python expression. script["plane"] = GafferScene.Plane() script["plane"]["divisions"].setValue(imath.V2i(50)) script["planeFilter"] = GafferScene.PathFilter() script["planeFilter"]["paths"].setValue( IECore.StringVectorData(["/plane"])) script["sphere"] = GafferScene.Sphere() script["instancer"] = GafferScene.Instancer() script["instancer"]["in"].setInput(script["plane"]["out"]) script["instancer"]["prototypes"].setInput(script["sphere"]["out"]) script["instancer"]["filter"].setInput(script["planeFilter"]["out"]) script["instanceFilter"] = GafferScene.PathFilter() script["instanceFilter"]["paths"].setValue( IECore.StringVectorData(["/plane/instances/*/*"])) script["cube"] = GafferScene.Cube() script["parent"] = GafferScene.Parent() script["parent"]["in"].setInput(script["instancer"]["out"]) script["parent"]["children"][0].setInput(script["cube"]["out"]) script["parent"]["filter"].setInput(script["instanceFilter"]["out"]) script["expression"] = Gaffer.Expression() script["expression"].setExpression( 'parent["sphere"]["name"] = context["sphereName"]') # Test that the `SourceSet` constructor releases the GIL so that the compute # doesn't hang. If we're lucky, the expression executes on the main # thread anyway, so loop to give it plenty of chances to fail. for i in range(0, 100): context = Gaffer.Context() context["sphereName"] = "sphere{}".format(i) GafferSceneUI.ContextAlgo.setSelectedPaths( context, IECore.PathMatcher([ "/plane/instances/{}/2410/cube".format( context["sphereName"]) ])) sourceSet = GafferSceneUI.SourceSet( context, Gaffer.StandardSet([script["parent"]]))
def testEditAttributes( self ) : points = IECoreScene.PointsPrimitive( IECore.V3fVectorData( [ imath.V3f( x, 0, 0 ) for x in range( 0, 2 ) ] ) ) points["testFloat"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, IECore.FloatVectorData( [ 0, 1 ] ), ) objectToScene = GafferScene.ObjectToScene() objectToScene["object"].setValue( points ) sphere = GafferScene.Sphere() instancer = GafferScene.Instancer() instancer["in"].setInput( objectToScene["out"] ) instancer["instances"].setInput( sphere["out"] ) instancer["parent"].setValue( "/object" ) instancer["attributes"].setValue( "test*" ) self.assertEqual( instancer["out"].attributes( "/object/instances/sphere/0" ), IECore.CompoundObject( { "testFloat" : IECore.FloatData( 0.0 ), } ) ) self.assertEqual( instancer["out"].attributes( "/object/instances/sphere/1" ), IECore.CompoundObject( { "testFloat" : IECore.FloatData( 1.0 ), } ) ) points["testFloat"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, IECore.FloatVectorData( [ 1, 2 ] ), ) objectToScene["object"].setValue( points ) self.assertEqual( instancer["out"].attributes( "/object/instances/sphere/0" ), IECore.CompoundObject( { "testFloat" : IECore.FloatData( 1.0 ), } ) ) self.assertEqual( instancer["out"].attributes( "/object/instances/sphere/1" ), IECore.CompoundObject( { "testFloat" : IECore.FloatData( 2.0 ), } ) )
def testParentBoundsWhenNoInstances( self ) : sphere = GafferScene.Sphere() sphere["type"].setValue( sphere.Type.Primitive ) # no points, so we can't instance onto it instancer = GafferScene.Instancer() instancer["in"].setInput( sphere["out"] ) instancer["parent"].setValue( "/sphere" ) instancer["instances"].setInput( sphere["out"] ) self.assertSceneValid( instancer["out"] ) self.assertEqual( instancer["out"].bound( "/sphere" ), sphere["out"].bound( "/sphere" ) )
def testEmptyParent(self): plane = GafferScene.Plane() sphere = GafferScene.Sphere() instancer = GafferScene.Instancer() instancer["in"].setInput(plane["out"]) instancer["instances"].setInput(sphere["out"]) instancer["parent"].setValue("") self.assertScenesEqual(instancer["out"], plane["out"]) self.assertSceneHashesEqual(instancer["out"], plane["out"])
def testTransform( self ) : point = IECoreScene.PointsPrimitive( IECore.V3fVectorData( [ imath.V3f( 4, 0, 0 ) ] ) ) point["orientation"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, IECore.QuatfVectorData( [ imath.Quatf().setAxisAngle( imath.V3f( 0, 1, 0 ), math.pi / 2.0 ) ] ) ) point["scale"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, IECore.V3fVectorData( [ imath.V3f( 2, 3, 4 ) ] ) ) point["uniformScale"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, IECore.FloatVectorData( [ 10 ] ) ) objectToScene = GafferScene.ObjectToScene() objectToScene["object"].setValue( point ) sphere = GafferScene.Sphere() instancer = GafferScene.Instancer() instancer["in"].setInput( objectToScene["out"] ) instancer["instances"].setInput( sphere["out"] ) instancer["parent"].setValue( "/object" ) self.assertEqual( instancer["out"].transform( "/object/instances/sphere/0" ), imath.M44f().translate( imath.V3f( 4, 0, 0 ) ) ) instancer["orientation"].setValue( "orientation" ) self.assertTrue( imath.V3f( 4, 0, -1 ).equalWithAbsError( imath.V3f( 1, 0, 0 ) * instancer["out"].transform( "/object/instances/sphere/0" ), 0.00001 ) ) instancer["scale"].setValue( "scale" ) self.assertTrue( imath.V3f( 4, 0, -2 ).equalWithAbsError( imath.V3f( 1, 0, 0 ) * instancer["out"].transform( "/object/instances/sphere/0" ), 0.00001 ) ) instancer["scale"].setValue( "uniformScale" ) self.assertTrue( imath.V3f( 4, 0, -10 ).equalWithAbsError( imath.V3f( 1, 0, 0 ) * instancer["out"].transform( "/object/instances/sphere/0" ), 0.00001 ) )
def testSets( self ) : points = IECoreScene.PointsPrimitive( IECore.V3fVectorData( [ imath.V3f( x, 0, 0 ) for x in range( 0, 4 ) ] ) ) points["index"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, IECore.IntVectorData( [ 0, 1, 1, 0 ] ), ) objectToScene = GafferScene.ObjectToScene() objectToScene["object"].setValue( points ) sphere = GafferScene.Sphere() sphere["sets"].setValue( "sphereSet" ) cube = GafferScene.Cube() cube["sets"].setValue( "cubeSet" ) cubeGroup = GafferScene.Group() cubeGroup["name"].setValue( "cubeGroup" ) cubeGroup["in"][0].setInput( cube["out"] ) instances = GafferScene.Parent() instances["in"].setInput( sphere["out"] ) instances["child"].setInput( cubeGroup["out"] ) instances["parent"].setValue( "/" ) instancer = GafferScene.Instancer() instancer["in"].setInput( objectToScene["out"] ) instancer["instances"].setInput( instances["out"] ) instancer["parent"].setValue( "/object" ) instancer["index"].setValue( "index" ) self.assertEqual( instancer["out"]["setNames"].getValue(), IECore.InternedStringVectorData( [ "sphereSet", "cubeSet" ] ) ) self.assertEqual( set( instancer["out"].set( "sphereSet" ).value.paths() ), { "/object/instances/sphere/0", "/object/instances/sphere/3", } ) self.assertEqual( set( instancer["out"].set( "cubeSet" ).value.paths() ), { "/object/instances/cubeGroup/1/cube", "/object/instances/cubeGroup/2/cube", } )
def testBoundHashIsStable(self): plane = GafferScene.Plane() sphere = GafferScene.Sphere() instancer = GafferScene.Instancer() instancer["in"].setInput(plane["out"]) instancer["instances"].setInput(sphere["out"]) instancer["parent"].setValue("/plane") h = instancer["out"].boundHash("/plane/instances") for i in range(0, 100): self.assertEqual(instancer["out"].boundHash("/plane/instances"), h)
def testDirtyPropagation(self): plane = GafferScene.Plane() instancer = GafferScene.Instancer() instancer["in"].setInput(plane["out"]) instancer["instances"].setInput(plane["out"]) cs = GafferTest.CapturingSlot(instancer.plugDirtiedSignal()) instancer["parent"].setValue("plane") self.assertIn(instancer["out"]["childNames"], {x[0] for x in cs}) del cs[:] filter = GafferScene.PathFilter() instancer["filter"].setInput(filter["out"]) self.assertIn(instancer["out"]["childNames"], {x[0] for x in cs})
def testObjectAffectsChildNames(self): plane = GafferScene.Plane() sphere = GafferScene.Sphere() instancer = GafferScene.Instancer() instancer["in"].setInput(plane["out"]) instancer["instances"].setInput(sphere["out"]) instancer["parent"].setValue("/plane") cs = GafferTest.CapturingSlot(instancer.plugDirtiedSignal()) plane["divisions"]["x"].setValue(2) dirtiedPlugs = [s[0] for s in cs] self.assertTrue(instancer["out"]["childNames"] in dirtiedPlugs) self.assertTrue(instancer["out"]["bound"] in dirtiedPlugs) self.assertTrue(instancer["out"]["transform"] in dirtiedPlugs)
def testSelectionRefersToCorrectPlug(self): script = Gaffer.ScriptNode() script["sphere"] = GafferScene.Sphere() script["cube"] = GafferScene.Cube() script["freeze"] = GafferScene.FreezeTransform() script["freezeFilter"] = GafferScene.PathFilter() script["freezeFilter"]["paths"].setValue( IECore.StringVectorData(["/sphere"])) script["freeze"]["in"].setInput(script["sphere"]["out"]) script["freeze"]["filter"].setInput(script["freezeFilter"]["out"]) script["instancer"] = GafferScene.Instancer() script["instancerFilter"] = GafferScene.PathFilter() script["instancerFilter"]["paths"].setValue( IECore.StringVectorData(["/sphere"])) script["instancer"]["in"].setInput(script["freeze"]["out"]) script["instancer"]["prototypes"].setInput(script["cube"]["out"]) script["instancer"]["filter"].setInput( script["instancerFilter"]["out"]) script["subTree"] = GafferScene.SubTree() script["subTree"]["root"].setValue("/sphere/instances") script["subTree"]["in"].setInput(script["instancer"]["out"]) script["plane"] = GafferScene.Plane() script["group"] = GafferScene.Group() script["group"]["in"][0].setInput(script["subTree"]["out"]) script["group"]["in"][1].setInput(script["plane"]["out"]) view = GafferSceneUI.SceneView() tool = GafferSceneUI.TranslateTool(view) tool["active"].setValue(True) self.assertEqual(tool.selection(), []) view["in"].setInput(script["group"]["out"]) self.assertEqual(tool.selection(), []) GafferSceneUI.ContextAlgo.setSelectedPaths( view.getContext(), IECore.PathMatcher(["/group/plane"])) self.assertEqual(len(tool.selection()), 1) self.assertEqual(tool.selection()[0].editTarget(), script["plane"]["transform"])
def testSeedsAffectBound(self): plane = GafferScene.Plane() sphere = GafferScene.Sphere() instancer = GafferScene.Instancer() instancer["in"].setInput(plane["out"]) instancer["instances"].setInput(sphere["out"]) instancer["parent"].setValue("/plane") h1 = instancer["out"].boundHash("/plane/instances") b1 = instancer["out"].bound("/plane/instances") plane["dimensions"].setValue(plane["dimensions"].getValue() * 2) h2 = instancer["out"].boundHash("/plane/instances") b2 = instancer["out"].bound("/plane/instances") self.assertNotEqual(h1, h2) self.assertNotEqual(b1, b2)
def testManyPaths(self): plane = GafferScene.Plane() plane["divisions"].setValue(imath.V2i(500)) sphere = GafferScene.Sphere() instancer = GafferScene.Instancer() instancer["in"].setInput(plane["out"]) instancer["parent"].setValue("/plane") instancer["prototypes"].setInput(sphere["out"]) scenePathFilter = GafferScene.PathFilter() scenePathFilter["paths"].setValue( IECore.StringVectorData(["/plane/instances/sphere/*"])) path = GafferScene.ScenePath( instancer["out"], Gaffer.Context(), "/plane/instances/sphere", GafferScene.SceneFilterPathFilter(scenePathFilter)) self.assertEqual(len(path.children()), 251001)