コード例 #1
0
ファイル: stats-1.py プロジェクト: lucienfostier/gaffer
	def __writeScene( self, script, args ) :

		import GafferScene
		import GafferSceneTest

		scene = script.descendant( args["scene"].value )
		if isinstance( scene, Gaffer.Node ) :
			scene = next( ( x for x in scene.children( GafferScene.ScenePlug ) ), None )

		if scene is None :
			IECore.msg( IECore.Msg.Level.Error, "stats", "Scene \"%s\" does not exist" % args["scene"].value )
			return

		if args["preCache"].value :
			GafferSceneTest.traverseScene( scene )

		memory = _Memory.maxRSS()
		with _Timer() as sceneTimer :
			with self.__performanceMonitor or _NullContextManager(), self.__contextMonitor or _NullContextManager() :
				with Gaffer.Context( script.context() ) as context :
					for frame in self.__frames( script, args ) :
						context.setFrame( frame )
						GafferSceneTest.traverseScene( scene )

		self.__timers["Scene generation"] = sceneTimer
		self.__memory["Scene generation"] = _Memory.maxRSS() - memory
コード例 #2
0
ファイル: stats-1.py プロジェクト: appleseedhq/gaffer
		def computeScene() :

			with self.__context( script, args ) as context :
				for frame in self.__frames( script, args ) :
					context.setFrame( frame )
					if args["sets"] :
						GafferScene.SceneAlgo.sets( scene, args["sets"] )
					else :
						GafferSceneTest.traverseScene( scene )
コード例 #3
0
ファイル: stats-1.py プロジェクト: andrewkaufman/gaffer
		def computeScene() :

			with self.__context( script, args ) as context :
				for frame in self.__frames( script, args ) :
					context.setFrame( frame )

					if isinstance( scene, GafferDispatch.TaskNode.TaskPlug ) :
						context["scene:render:sceneTranslationOnly"] = IECore.BoolData( True )
						scene.execute()
					else :
						if args["sets"] :
							GafferScene.SceneAlgo.sets( scene, args["sets"] )
						else :
							GafferSceneTest.traverseScene( scene )
コード例 #4
0
ファイル: InstancerTest.py プロジェクト: lucienfostier/gaffer
	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() + float( context['instancer:id'] )" )

		script["instancer"] = GafferScene.Instancer()
		script["instancer"]["in"].setInput( script["plane"]["out"] )
		script["instancer"]["instance"].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"] ] )
コード例 #5
0
ファイル: InstancerTest.py プロジェクト: lucienfostier/gaffer
	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() + float( context['instancer:id'] )" )

		script["instancer"] = GafferScene.Instancer()
		script["instancer"]["in"].setInput( script["plane"]["out"] )
		script["instancer"]["instance"].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" )
コード例 #6
0
ファイル: InstancerTest.py プロジェクト: mor-vfx/gaffer
    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"])
コード例 #7
0
ファイル: InstancerTest.py プロジェクト: lucienfostier/gaffer
	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() + float( context['instancer:id'] )" )

		script["instancer"] = GafferScene.Instancer()
		script["instancer"]["in"].setInput( script["plane"]["out"] )
		script["instancer"]["instance"].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"]
コード例 #8
0
ファイル: stats-1.py プロジェクト: HughMacdonald/gaffer
    def __printScene(self, script, args):

        import GafferScene
        import GafferSceneTest

        scene = script.descendant(args["scene"].value)
        if isinstance(scene, Gaffer.Node):
            scene = next((x for x in scene.children(GafferScene.ScenePlug)), None)

        if scene is None:
            IECore.msg(IECore.Msg.Level.Error, "stats", 'Scene "%s" does not exist' % args["scene"].value)
            return

        memory = _Memory.maxRSS()
        with _Timer() as sceneTimer:
            with self.__performanceMonitor or _NullContextManager():
                GafferSceneTest.traverseScene(scene)
        self.__timers["Scene generation"] = sceneTimer
        self.__memory["Scene generation"] = _Memory.maxRSS() - memory
コード例 #9
0
	def testAlembicThreading( self ) :

		mesh = IECoreScene.MeshPrimitive.createPlane( imath.Box2f( imath.V2f( -1 ), imath.V2f( 1 ) ) )
		fileName = self.temporaryDirectory() + "/test.abc"

		root = IECoreScene.SceneInterface.create( fileName, IECore.IndexedIO.OpenMode.Write )
		root.writeBound( imath.Box3d( mesh.bound() ), 0 )
		for i in range( 0, 1000 ) :
			child = root.createChild( str( i ) )
			child.writeObject( mesh, 0 )
			child.writeBound( imath.Box3d( mesh.bound() ), 0 )

		del root, child

		sceneReader = GafferScene.SceneReader()
		sceneReader["fileName"].setValue( fileName )

		for i in range( 0, 20 ) :
			sceneReader["refreshCount"].setValue( sceneReader["refreshCount"].getValue() + 1 )
			GafferSceneTest.traverseScene( sceneReader["out"] )
コード例 #10
0
ファイル: GroupTest.py プロジェクト: mattigruener/gaffer
	def testNameClashesWithThreading( self ) :

		sphere = IECoreScene.SpherePrimitive()
		input1 = GafferSceneTest.CompoundObjectSource()
		input1["in"].setValue(
			IECore.CompoundObject( {
				"bound" : IECore.Box3fData( sphere.bound() ),
				"children" : {
					"myLovelyObject1" : {
						"bound" : IECore.Box3fData( sphere.bound() ),
						"object" : sphere,
					},
				},
			} ),
		)

		plane = IECoreScene.MeshPrimitive.createPlane( imath.Box2f( imath.V2f( -1 ), imath.V2f( 1 ) ) )
		input2 = GafferSceneTest.CompoundObjectSource()
		input2["in"].setValue(
			IECore.CompoundObject( {
				"bound" : IECore.Box3fData( plane.bound() ),
				"children" : {
					"myLovelyObject1" : {
						"bound" : IECore.Box3fData( plane.bound() ),
						"object" : plane,
					},
				},
			} ),
		)

		group = GafferScene.Group()
		group["name"].setValue( "topLevel" )
		group["in"][0].setInput( input1["out"] )
		group["in"][1].setInput( input2["out"] )

		GafferSceneTest.traverseScene( group["out"] )
コード例 #11
0
ファイル: RenderTest.py プロジェクト: Eryckz/gaffer
    def testGlobalAttributes(self):

        s = Gaffer.ScriptNode()

        s["p"] = GafferScene.Plane()
        s["a"] = GafferScene.StandardAttributes()
        s["a"]["in"].setInput(s["p"]["out"])
        s["a"]["attributes"]["doubleSided"]["enabled"].setValue(True)
        s["a"]["attributes"]["doubleSided"]["value"].setValue(False)
        s["a"]["global"].setValue(True)

        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()

        self.assertEqual(s["r"].world().state()[0].attributes["doubleSided"],
                         IECore.BoolData(False))
コード例 #12
0
ファイル: ParentTest.py プロジェクト: wubugui/gaffer
    def testSetsWithDeepNesting(self):

        c = GafferScene.Cube()

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

        p = GafferScene.Parent()
        p["in"].setInput(c["out"])
        p["child"].setInput(g2["out"])
        p["parent"].setValue("/cube")

        self.assertSceneValid(p["out"])

        self.assertEqual(p["out"]["setNames"].getValue(),
                         IECore.InternedStringVectorData(["__lights"]))
        self.assertEqual(p["out"].set("__lights").value.paths(),
                         ["/cube/group/group/light"])
コード例 #13
0
    def testChangeScene(self):

        GafferSceneUI.ShaderView.registerScene("sceneTest", "A",
                                               GafferScene.ShaderBall)
        GafferSceneUI.ShaderView.registerScene("sceneTest", "B",
                                               GafferScene.ShaderBall)

        shader = GafferSceneTest.TestShader()
        shader["type"].setValue("sceneTest:surface")
        shader["name"].setValue("test")

        view = GafferUI.View.create(shader["out"])
        view["scene"].setValue("A")

        sceneA = view.scene()
        self.assertTrue(isinstance(sceneA, GafferScene.ShaderBall))

        view["scene"].setValue("B")
        sceneB = view.scene()
        self.assertTrue(isinstance(sceneB, GafferScene.ShaderBall))
        self.assertFalse(sceneA.isSame(sceneB))
コード例 #14
0
    def testBoxNodulePositions(self):

        s = Gaffer.ScriptNode()
        g = GafferUI.GraphGadget(s)

        s["p"] = GafferScene.Plane()
        s["s"] = GafferSceneTest.TestShader()
        s["a"] = GafferScene.ShaderAssignment()

        s["a"]["in"].setInput(s["p"]["out"])
        s["a"]["shader"].setInput(s["s"]["out"])

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

        boxGadget = g.nodeGadget(box)

        self.assertEqual(boxGadget.noduleTangent(boxGadget.nodule(box["in"])),
                         IECore.V3f(0, 1, 0))
        self.assertEqual(
            boxGadget.noduleTangent(boxGadget.nodule(box["shader"])),
            IECore.V3f(-1, 0, 0))
コード例 #15
0
ファイル: ShaderTest.py プロジェクト: alexwheezy/gaffer
	def testDirtyPropagationThroughShaderAssignment( self ) :

		n = GafferSceneTest.TestShader()

		p = GafferScene.Plane()
		a = GafferScene.ShaderAssignment()
		a["in"].setInput( p["out"] )
		a["shader"].setInput( n["out"] )

		cs = GafferTest.CapturingSlot( a.plugDirtiedSignal() )

		n["parameters"]["i"].setValue( 1 )

		self.assertEqual(
			[ c[0] for c in cs ],
			[
				a["shader"],
				a["out"]["attributes"],
				a["out"],
			],
		)
コード例 #16
0
ファイル: ShaderTest.py プロジェクト: alexwheezy/gaffer
	def testNodeColorBlindData( self ) :

		s = GafferSceneTest.TestShader( "test" )
		s["type"].setValue( "test:surface" )

		h1 = s.attributesHash()
		s1 = s.attributes()["test:surface"]

		cs = GafferTest.CapturingSlot( s.plugDirtiedSignal() )

		Gaffer.Metadata.registerValue( s, "nodeGadget:color", imath.Color3f( 1, 0, 0 ) )

		self.assertTrue( s["out"] in [ x[0] for x in cs ] )

		self.assertNotEqual( s.attributesHash(), h1 )

		s2 = s.attributes()["test:surface"]
		self.assertNotEqual( s2, s1 )

		self.assertEqual( s1.getShader( "test" ).blindData()["gaffer:nodeColor"], IECore.Color3fData( imath.Color3f( 0 ) ) )
		self.assertEqual( s2.getShader( "test" ).blindData()["gaffer:nodeColor"], IECore.Color3fData( imath.Color3f( 1, 0, 0 ) ) )
コード例 #17
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())

        lightSet = l["out"]["globals"].getValue()["gaffer:sets"]["__lights"]
        self.assertEqual(
            lightSet,
            GafferScene.PathMatcherData(GafferScene.PathMatcher(["/light"])))
コード例 #18
0
			def __init__( self, name = "ShaderAndAttributes" ) :

				GafferScene.FilteredSceneProcessor.__init__( self, name, filterDefault = GafferScene.Filter.Result.NoMatch )

				self["__shader"] = GafferSceneTest.TestShader()
				self["__shader"]["type"].setValue( "test:surface" )

				self["__shaderAssignment"] = GafferScene.ShaderAssignment()
				self["__shaderAssignment"]["in"].setInput( self["in"] )
				self["__shaderAssignment"]["shader"].setInput( self["__shader"]["out"] )
				self["__shaderAssignment"]["filter"].setInput( self["filter"] )
				self["__shaderAssignment"]["enabled"].setInput( self["enabled"] )

				self["__attributes"] = GafferScene.StandardAttributes()
				self["__attributes"]["in"].setInput( self["__shaderAssignment"]["out"] )
				self["__attributes"]["enabled"].setInput( self["enabled"] )
				self["__attributes"]["filter"].setInput( self["filter"] )
				self["__attributes"]["attributes"]["doubleSided"]["enabled"].setValue( True )
				self["__attributes"]["attributes"]["doubleSided"]["value"].setValue( True )

				self["out"].setInput( self["__attributes"]["out"] )
コード例 #19
0
    def testInputAcceptanceFromBoxesViaBoxIO(self):

        s = Gaffer.ScriptNode()

        s["s"] = GafferSceneTest.TestShader()
        s["a"] = GafferScene.ShaderAssignment()
        s["a"]["shader"].setInput(s["s"]["out"])

        Gaffer.Metadata.registerValue(s["s"]["out"], "nodule:type",
                                      "GafferUI::StandardNodule")
        Gaffer.Metadata.registerValue(s["a"]["shader"], "nodule:type",
                                      "GafferUI::StandardNodule")

        box = Gaffer.Box.create(s, Gaffer.StandardSet({s["s"]}))
        Gaffer.BoxIO.insert(box)

        s2 = Gaffer.ScriptNode()
        s2.execute(s.serialise())

        self.assertTrue(s2["a"]["shader"].source().isSame(
            s2["Box"]["s"]["out"]))
コード例 #20
0
    def testInputAcceptanceInsideBoxes(self):

        s = Gaffer.ScriptNode()

        s["s"] = GafferSceneTest.TestShader()
        s["n"] = Gaffer.Node()
        s["n"]["out"] = Gaffer.Plug(direction=Gaffer.Plug.Direction.Out)
        s["a"] = GafferScene.ShaderAssignment()

        # the shader assignment shouldn't accept inputs from any old
        # node - it should be a shader node.

        self.assertTrue(s["a"]["shader"].acceptsInput(s["s"]["out"]))
        self.assertFalse(s["a"]["shader"].acceptsInput(s["n"]["out"]))

        # and that shouldn't change just because we happen to be inside a box

        b = Gaffer.Box.create(s, Gaffer.StandardSet([s["s"], s["n"], s["a"]]))

        self.assertTrue(b["a"]["shader"].acceptsInput(b["s"]["out"]))
        self.assertFalse(b["a"]["shader"].acceptsInput(b["n"]["out"]))
コード例 #21
0
ファイル: ScenePlugTest.py プロジェクト: mor-vfx/gaffer
	def testFullAttributes( self ) :

		n = GafferSceneTest.CompoundObjectSource()
		n["in"].setValue(
			IECore.CompoundObject( {
				"children" : {
					"group" : {
						"attributes" : {
							"a" : IECore.StringData( "a" ),
							"b" : IECore.StringData( "b" ),
						},
						"children" : {
							"ball" : {
								"attributes" : {
									 "b" : IECore.StringData( "bOverride" ),
									 "c" : IECore.StringData( "c" ),
								 },
							}
						}
					},
				},
			} )
		)

		self.assertEqual(
			n["out"].fullAttributes( "/group" ),
			IECore.CompoundObject( {
				"a" : IECore.StringData( "a" ),
				"b" : IECore.StringData( "b" ),
			} )
		)

		self.assertEqual(
			n["out"].fullAttributes( "/group/ball" ),
			IECore.CompoundObject( {
				"a" : IECore.StringData( "a" ),
				"b" : IECore.StringData( "bOverride" ),
				"c" : IECore.StringData( "c" ),
			} )
		)
コード例 #22
0
    def testSetsWithDeepNesting(self):

        c = GafferScene.Cube()

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

        p = GafferScene.Parent()
        p["in"].setInput(c["out"])
        p["child"].setInput(g2["out"])
        p["parent"].setValue("/cube")

        self.assertSceneValid(p["out"])

        sets = p["out"]["globals"].getValue()["gaffer:sets"]
        self.assertEqual(sets.keys(), ["__lights"])

        self.assertEqual(sets["__lights"].value.paths(),
                         ["/cube/group/group/light"])
コード例 #23
0
	def testOSLAssignmentPrefix( self ) :

		script = Gaffer.ScriptNode()

		script["shader"] = GafferSceneTest.TestShader()
		script["shader"]["type"].setValue( "osl:shader" )

		script["sphere"] = GafferScene.Sphere()

		script["assignment"] = GafferScene.ShaderAssignment()
		script["assignment"]["in"].setInput( script["sphere"]["out"] )
		script["assignment"]["shader"].setInput( script["shader"]["out"] )

		script["writer"] = GafferScene.SceneWriter()
		script["writer"]["in"].setInput( script["assignment"]["out"] )
		script["writer"]["fileName"].setValue( os.path.join( self.temporaryDirectory(), "test.scc" ) )

		script["fileName"].setValue( os.path.join( self.temporaryDirectory(), "test.gfr" ) )
		script.save()


		def assertAssignment( expected, envVar ) :

			env = os.environ.copy()
			if envVar is not None :
				env["GAFFERSCENE_SHADERASSIGNMENT_OSL_PREFIX"] = envVar

			o = subprocess.check_output(
				[ "gaffer", "execute", script["fileName"].getValue(), "-nodes", "writer" ],
				env = env
			)

			scene = IECoreScene.SceneCache( script["writer"]["fileName"].getValue(), IECore.IndexedIO.OpenMode.Read )
			sphere = scene.child( "sphere" )

			self.assertEqual( [ i for i in sphere.attributeNames() if ":surface" in i ], [ expected ] )

		assertAssignment( "osl:surface", envVar = None )
		assertAssignment( "foo:surface", envVar = "foo" )
コード例 #24
0
    def testNodeNameBlindData(self):

        s = GafferSceneTest.TestShader("node1")
        s["type"].setValue("test:surface")

        h1 = s.attributesHash()
        s1 = s.attributes()["test:surface"]
        cs = GafferTest.CapturingSlot(s.plugDirtiedSignal())

        s.setName("node2")

        self.assertTrue(s["out"] in [x[0] for x in cs])

        self.assertNotEqual(s.attributesHash(), h1)

        s2 = s.attributes()["test:surface"]
        self.assertNotEqual(s2, s1)

        self.assertEqual(s1[0].blindData()["gaffer:nodeName"],
                         IECore.StringData("node1"))
        self.assertEqual(s2[0].blindData()["gaffer:nodeName"],
                         IECore.StringData("node2"))
コード例 #25
0
    def testSets(self):

        light = GafferSceneTest.TestLight()
        light["sets"].setValue("A B C")

        sets = GafferScene.SceneAlgo.sets(light["out"])
        self.assertEqual(set(sets.keys()), {"__lights", "A", "B", "C"})
        for n in sets.keys():
            self.assertEqual(sets[n], light["out"].set(n))
            self.assertFalse(sets[n].isSame(light["out"].set(n, _copy=False)))

        sets = GafferScene.SceneAlgo.sets(light["out"], _copy=False)
        self.assertEqual(set(sets.keys()), {"__lights", "A", "B", "C"})
        for n in sets.keys():
            self.assertTrue(sets[n].isSame(light["out"].set(n, _copy=False)))

        someSets = GafferScene.SceneAlgo.sets(light["out"], ("A", "B"),
                                              _copy=False)
        self.assertEqual(set(someSets.keys()), {"A", "B"})
        for n in someSets.keys():
            self.assertTrue(someSets[n].isSame(light["out"].set(n,
                                                                _copy=False)))
コード例 #26
0
ファイル: LightTest.py プロジェクト: alexwheezy/gaffer
    def testVisualisationAttributes(self):

        l = GafferSceneTest.TestLight()

        # Test not set by default

        a = l["out"].attributes("/light")

        self.assertFalse("gl:light:drawingMode" in a.keys())
        self.assertFalse("gl:visualiser:scale" in a.keys())
        self.assertFalse("gl:visualiser:maxTextureResolution" in a.keys())
        self.assertFalse("gl:visualiser:frustum" in a.keys())
        self.assertFalse("gl:light:frustumScale" in a.keys())

        # Test attribute mapping

        l["visualiserAttributes"]["lightDrawingMode"]["enabled"].setValue(True)
        l["visualiserAttributes"]["lightDrawingMode"]["value"].setValue(
            "color")
        l["visualiserAttributes"]["scale"]["enabled"].setValue(True)
        l["visualiserAttributes"]["scale"]["value"].setValue(12.3)
        l["visualiserAttributes"]["maxTextureResolution"]["enabled"].setValue(
            True)
        l["visualiserAttributes"]["maxTextureResolution"]["value"].setValue(
            123)
        l["visualiserAttributes"]["frustum"]["enabled"].setValue(True)
        l["visualiserAttributes"]["frustum"]["value"].setValue(False)
        l["visualiserAttributes"]["lightFrustumScale"]["enabled"].setValue(
            True)
        l["visualiserAttributes"]["lightFrustumScale"]["value"].setValue(1.23)

        a = l["out"].attributes("/light")

        self.assertEqual(a["gl:light:drawingMode"], IECore.StringData("color"))
        self.assertEqual(a["gl:visualiser:scale"], IECore.FloatData(12.3))
        self.assertEqual(a["gl:visualiser:maxTextureResolution"],
                         IECore.IntData(123))
        self.assertEqual(a["gl:visualiser:frustum"], IECore.BoolData(False))
        self.assertEqual(a["gl:light:frustumScale"], IECore.FloatData(1.23))
コード例 #27
0
    def testEditScopeNesting(self):

        light = GafferSceneTest.TestLight()
        editScope1 = Gaffer.EditScope("EditScope1")

        editScope1.setup(light["out"])
        editScope1["in"].setInput(light["out"])

        def inspector(scene, path, parameter, editScope, attribute="light"):

            history = GafferScene.SceneAlgo.history(scene["attributes"], path)
            attributeHistory = GafferScene.SceneAlgo.attributeHistory(
                history, attribute)
            return GafferSceneUI.SceneViewUI._ParameterInspector(
                attributeHistory, parameter, editScope)

        i = inspector(editScope1["out"], "/light", "intensity", editScope1)
        scope1Edit = i.acquireEdit()
        scope1Edit["enabled"].setValue(True)
        self.assertEqual(scope1Edit.ancestor(Gaffer.EditScope), editScope1)

        editScope2 = Gaffer.EditScope("EditScope2")
        editScope2.setup(light["out"])
        editScope1.addChild(editScope2)
        editScope2["in"].setInput(
            scope1Edit.ancestor(GafferScene.SceneProcessor)["out"])
        editScope1["BoxOut"]["in"].setInput(editScope2["out"])

        i = inspector(editScope1["out"], "/light", "intensity", editScope2)
        scope2Edit = i.acquireEdit()
        scope2Edit["enabled"].setValue(True)
        self.assertEqual(scope2Edit.ancestor(Gaffer.EditScope), editScope2)

        # Check we still find the edit in scope 1

        i = inspector(editScope1["out"], "/light", "intensity", editScope1)
        self.assertEqual(i.acquireEdit().ancestor(Gaffer.EditScope),
                         editScope1)
コード例 #28
0
    def testShaderTweaksWithSetFilter(self):

        shader = GafferSceneTest.TestShader()
        shader["type"].setValue("test:surface")

        plane = GafferScene.Plane()
        plane["sets"].setValue("A")

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

        setFilter = GafferScene.SetFilter()
        setFilter["set"].setValue("A")

        planeTweaks = GafferScene.ShaderTweaks()
        planeTweaks["in"].setInput(planeShaderAssignment["out"])
        planeTweaks["filter"].setInput(setFilter["out"])
        planeTweaks["shader"].setValue("test:surface")

        self.assertEqual(
            GafferScene.SceneAlgo.shaderTweaks(planeTweaks["out"], "/plane",
                                               "test:surface"), planeTweaks)
コード例 #29
0
	def testGlobalContext( self ) :

		script = Gaffer.ScriptNode()

		script["shader"] = GafferSceneTest.TestShader()
		script["shader"]["type"].setValue( "shader" )

		script["expression"] = Gaffer.Expression()
		script["expression"].setExpression( 'parent["shader"]["parameters"]["i"] = 1 if context.get( "scene:path", None ) else 0' )

		script["sphere"] = GafferScene.Sphere()

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

		script["assignment"] = GafferScene.ShaderAssignment()
		script["assignment"]["in"].setInput( script["sphere"]["out"] )
		script["assignment"]["filter"].setInput( script["filter"]["out"] )
		script["assignment"]["shader"].setInput( script["shader"]["out"] )

		self.assertEqual(
			script["assignment"]["out"].attributes( "/sphere" )["shader"].outputShader().parameters["i"].value, 0
		)
コード例 #30
0
    def testNodeColorBlindData(self):

        s = GafferSceneTest.TestShader()

        h1 = s.stateHash()
        s1 = s.state()

        cs = GafferTest.CapturingSlot(s.plugDirtiedSignal())

        Gaffer.Metadata.registerNodeValue(s, "nodeGadget:color",
                                          IECore.Color3f(1, 0, 0))

        self.assertTrue(s["out"] in [x[0] for x in cs])

        self.assertNotEqual(s.stateHash(), h1)

        s2 = s.state()
        self.assertNotEqual(s2, s1)

        self.assertEqual(s1[0].blindData()["gaffer:nodeColor"],
                         IECore.Color3fData(IECore.Color3f(0)))
        self.assertEqual(s2[0].blindData()["gaffer:nodeColor"],
                         IECore.Color3fData(IECore.Color3f(1, 0, 0)))
コード例 #31
0
	def testParameterEditExceptions( self ) :

		light = GafferSceneTest.TestLight()
		editScope = Gaffer.EditScope()
		editScope.setup( light["out"] )
		editScope["in"].setInput( light["out"] )
		emptyKeys = editScope.keys()

		with six.assertRaisesRegex( self, RuntimeError, 'Location "/bogus" does not exist' ) :
			GafferScene.EditScopeAlgo.acquireParameterEdit( editScope, "/bogus", "light", ( "", "intensity" ) )
		self.assertEqual( editScope.keys(), emptyKeys )

		with six.assertRaisesRegex( self, RuntimeError, 'Attribute "bogus" does not exist' ) :
			GafferScene.EditScopeAlgo.acquireParameterEdit( editScope, "/light", "bogus", ( "", "intensity" ) )
		self.assertEqual( editScope.keys(), emptyKeys )

		with six.assertRaisesRegex( self, RuntimeError, 'Shader "bogus" does not exist' ) :
			GafferScene.EditScopeAlgo.acquireParameterEdit( editScope, "/light", "light", ( "bogus", "intensity" ) )
		self.assertEqual( editScope.keys(), emptyKeys )

		with six.assertRaisesRegex( self, RuntimeError, 'Parameter "bogus" does not exist' ) :
			GafferScene.EditScopeAlgo.acquireParameterEdit( editScope, "/light", "light", ( "", "bogus" ) )
		self.assertEqual( editScope.keys(), emptyKeys )
コード例 #32
0
	def testAssignShaderFromOutsideBox( self ) :
	
		s = Gaffer.ScriptNode()
		
		s["p"] = GafferScene.Plane()
		s["s"] = GafferSceneTest.TestShader()
		s["a"] = GafferScene.ShaderAssignment()
		s["a"]["in"].setInput( s["p"]["out"] )
		s["a"]["shader"].setInput( s["s"]["out"] )
		
		s["o"] = GafferScene.Options()
		s["o"]["in"].setInput( s["a"]["out"] )
		
		b = Gaffer.Box.create( s, Gaffer.StandardSet( [ s["p"], s["a"] ] ) )
		
		self.assertTrue( "shader" in s["o"]["out"].attributes( "/plane" ) )
		
		ss = s.serialise()
				
		s = Gaffer.ScriptNode()
		s.execute( ss )
		
		self.assertTrue( s["Box"]["a"]["shader"].getInput().isSame( s["Box"]["in"] ) )
コード例 #33
0
	def testCompute( self ) :
		crowd_input = GafferSceneTest.CompoundObjectSource()
		crowd_input["in"].setValue( buildCrowdTest() )

		node = AtomsGaffer.AtomsMetadata()
		node["in"].setInput( crowd_input["out"] )

		node["metadata"].addMember( "tint", IECore.V3fData( imath.V3f( 1.0, 0.0, 0.0 ) ) )
		node["metadata"].addMember( "variation", IECore.StringData( "Robot1" ) )

		output = node["out"].object( "/crowd" )
		self.assertEqual( output.typeId(), IECoreScene.PointsPrimitive.staticTypeId() )

		self.assertTrue( "P" in output )
		self.assertTrue( "atoms:agentId" in output )
		self.assertTrue( "atoms:agentType" in output )
		self.assertTrue( "atoms:variation" in output )
		self.assertTrue( "atoms:lod" in output )
		self.assertTrue( "atoms:velocity" in output )
		self.assertTrue( "atoms:direction" in output )
		self.assertTrue( "atoms:scale" in output )
		self.assertTrue( "atoms:orientation" in output )
		self.assertTrue( "atoms:tint" in output )

		tint_data = output["atoms:tint"].data
		self.assertEqual( len(tint_data), 4 )
		self.assertEqual( tint_data[0], imath.V3f( 1.0, 0.0, 0.0 ) )
		self.assertEqual( tint_data[1], imath.V3f( 1.0, 0.0, 0.0 ) )
		self.assertEqual( tint_data[2], imath.V3f( 1.0, 0.0, 0.0 ) )
		self.assertEqual( tint_data[3], imath.V3f( 1.0, 0.0, 0.0 ) )

		variation_data = output["atoms:variation"].data
		self.assertEqual( len(variation_data), 4 )
		self.assertEqual( variation_data[0], "Robot1" )
		self.assertEqual( variation_data[1], "Robot1" )
		self.assertEqual( variation_data[2], "Robot1" )
		self.assertEqual( variation_data[3], "Robot1" )
コード例 #34
0
    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.CustomAttributes()
        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),
            }))
コード例 #35
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" ] )
			)
		)
コード例 #36
0
ファイル: RenderManRenderTest.py プロジェクト: Eryckz/gaffer
    def testPreWorldRenderables(self):

        s = Gaffer.ScriptNode()

        s["g"] = GafferSceneTest.CompoundObjectSource()
        s["g"]["in"].setValue(
            IECore.CompoundObject({
                "bound": IECore.Box3fData(IECore.Box3f()),
                "globals": {
                    "option:user:blah": IECore.ClippingPlane(),
                },
            }))

        s["r"] = GafferRenderMan.RenderManRender()
        s["r"]["mode"].setValue("generate")
        s["r"]["ribFileName"].setValue("/tmp/test.rib")
        s["r"]["in"].setInput(s["g"]["out"])

        s["r"].execute()

        # node should have inserted a ClippingPlane into the rib by putting it
        # in the options:
        rib = "\n".join(file("/tmp/test.rib").readlines())
        self.assertTrue("ClippingPlane" in rib)
コード例 #37
0
    def testInputAcceptanceFromDots(self):

        script = Gaffer.ScriptNode()

        script["a"] = GafferScene.ShaderAssignment()

        script["s"] = GafferSceneTest.TestShader()
        script["d"] = Gaffer.Dot()
        script["d"].setup(script["s"]["out"])

        # The Dot doesn't know about Shaders, and just has a Color3fPlug
        # input, so it should accept input from any old Color3fPlug, not
        # merely shader outputs.

        script["r"] = Gaffer.Random()
        self.assertTrue(script["d"]["in"].acceptsInput(
            script["r"]["outColor"]))

        # And we should be able to connect the Dot into the
        # ShaderAssignment even if the Dot doesn't have an input
        # yet. The user should be able to wire the graph up in any
        # order, provided we end up with a valid network.

        script["a"]["shader"].setInput(script["d"]["out"])
        self.assertTrue(script["a"]["shader"].getInput().isSame(
            script["d"]["out"]))

        # But once that is done, the Dot should reject
        # inputs that the ShaderAssignment can't handle.

        self.assertFalse(script["d"]["in"].acceptsInput(
            script["r"]["outColor"]))

        # And only accept inputs from a Shader.

        self.assertTrue(script["d"]["in"].acceptsInput(script["s"]["out"]))
コード例 #38
0
ファイル: ScenePlugTest.py プロジェクト: mor-vfx/gaffer
	def testManyStringToPathCalls( self ) :

		GafferSceneTest.testManyStringToPathCalls()
コード例 #39
0
ファイル: SceneNodeTest.py プロジェクト: HughMacdonald/gaffer
		def traverser() :

			try :
				GafferSceneTest.traverseScene( g["out"] )
			except Exception, e :
				exceptions.append( e )
コード例 #40
0
ファイル: PathMatcherTest.py プロジェクト: mor-vfx/gaffer
    def testIteratorPrune(self):

        GafferSceneTest.testPathMatcherIteratorPrune()
コード例 #41
0
ファイル: InstancerTest.py プロジェクト: lucienfostier/gaffer
	def testDynamicPlugsAndGIL( 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.getFrame() + float( context['instancer:id'] )" )

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

		script["attributes"] = GafferScene.CustomAttributes()
		script["attributes"]["in"].setInput( script["instancer"]["out"] )

		script["outputs"] = GafferScene.Outputs()
		script["outputs"]["in"].setInput( script["attributes"]["out"] )

		# Simulate an InteractiveRender or Viewer traversal of the scene
		# every time it is dirtied. If the GIL isn't released when dirtiness
		# is signalled, we'll end up with a deadlock as the traversal enters
		# python on another thread to evaluate the expression. We increment the frame
		# between each test to ensure the expression result is not cached and
		# we do truly enter python.
		traverseConnection = Gaffer.ScopedConnection( GafferSceneTest.connectTraverseSceneToPlugDirtiedSignal( script["outputs"]["out"] ) )
		with Gaffer.Context() as c :

			c.setFrame( 1 )
			script["attributes"]["attributes"].addMember( "test1", IECore.IntData( 10 ) )

			c.setFrame( 2 )
			script["attributes"]["attributes"].addOptionalMember( "test2", IECore.IntData( 20 ) )

			c.setFrame( 3 )
			script["attributes"]["attributes"].addMembers(
				IECore.CompoundData( {
					"test3" : 30,
					"test4" : 40,
				} )
			)

			c.setFrame( 4 )
			p = script["attributes"]["attributes"][0]
			del script["attributes"]["attributes"][p.getName()]

			c.setFrame( 5 )
			script["attributes"]["attributes"].addChild( p )

			c.setFrame( 6 )
			script["attributes"]["attributes"].removeChild( p )

			c.setFrame( 7 )
			script["attributes"]["attributes"].setChild( p.getName(), p )

			c.setFrame( 8 )
			script["attributes"]["attributes"].removeChild( p )

			c.setFrame( 9 )
			script["attributes"]["attributes"][p.getName()] = p

			c.setFrame( 10 )
			script["outputs"].addOutput( "test", IECoreScene.Output( "beauty.exr", "exr", "rgba" ) )
コード例 #42
0
ファイル: PathMatcherTest.py プロジェクト: chippey/gaffer
	def testFind( self ) :

		GafferSceneTest.testPathMatcherFind()
コード例 #43
0
ファイル: PathMatcherTest.py プロジェクト: mor-vfx/gaffer
    def testRawIterator(self):

        GafferSceneTest.testPathMatcherRawIterator()
コード例 #44
0
ファイル: PathMatcherTest.py プロジェクト: chippey/gaffer
	def testRawIterator( self ) :

		GafferSceneTest.testPathMatcherRawIterator()
コード例 #45
0
        def traverser():

            try:
                GafferSceneTest.traverseScene(g["out"])
            except Exception as e:
                exceptions.append(e)
コード例 #46
0
ファイル: PathMatcherTest.py プロジェクト: chippey/gaffer
	def testIteratorPrune( self ) :

		GafferSceneTest.testPathMatcherIteratorPrune()