예제 #1
0
	def testLightAndShadowLinking( self ) :

		sphere1 = GafferScene.Sphere()
		sphere2 = GafferScene.Sphere()

		attributes = GafferScene.StandardAttributes()
		arnoldAttributes = GafferArnold.ArnoldAttributes()

		light1 = GafferArnold.ArnoldLight()
		light1.loadShader( "point_light" )

		light2 = GafferArnold.ArnoldLight()
		light2.loadShader( "point_light" )

		group = GafferScene.Group()
		group["in"].addChild( GafferScene.ScenePlug( "in1" ) )
		group["in"].addChild( GafferScene.ScenePlug( "in2" ) )
		group["in"].addChild( GafferScene.ScenePlug( "in3" ) )
		group["in"].addChild( GafferScene.ScenePlug( "in4" ) )

		evaluate = GafferScene.EvaluateLightLinks()

		render = GafferArnold.ArnoldRender()

		attributes["in"].setInput( sphere1["out"] )
		arnoldAttributes["in"].setInput( attributes["out"] )
		group["in"]["in1"].setInput( arnoldAttributes["out"] )
		group["in"]["in2"].setInput( light1["out"] )
		group["in"]["in3"].setInput( light2["out"] )
		group["in"]["in4"].setInput( sphere2["out"] )
		evaluate["in"].setInput( group["out"] )
		render["in"].setInput( evaluate["out"] )

		# Illumination
		attributes["attributes"]["linkedLights"]["enabled"].setValue( True )
		attributes["attributes"]["linkedLights"]["value"].setValue( "/group/light /group/light1" )

		# Shadows
		arnoldAttributes["attributes"]["shadowGroup"]["enabled"].setValue( True )
		arnoldAttributes["attributes"]["shadowGroup"]["value"].setValue( "/group/light /group/light1" )

		# make sure we pass correct data into the renderer
		self.assertEqual(
			set( render["in"].attributes( "/group/sphere" )["linkedLights"] ),
			set( IECore.StringVectorData( ["/group/light", "/group/light1"] ) )
		)

		self.assertEqual(
			set( render["in"].attributes( "/group/sphere" )["ai:visibility:shadow_group"] ),
			set( IECore.StringVectorData( ["/group/light", "/group/light1"] ) )
		)

		render["mode"].setValue( render.Mode.SceneDescriptionMode )
		render["fileName"].setValue( self.temporaryDirectory() + "/test.ass" )
		render["task"].execute()

		with IECoreArnold.UniverseBlock( writable = True ) :

			arnold.AiASSLoad( self.temporaryDirectory() + "/test.ass" )

			# the first sphere had linked lights
			sphere = arnold.AiNodeLookUpByName( "/group/sphere" )

			# check illumination
			lights = arnold.AiNodeGetArray( sphere, "light_group" )
			lightNames = []
			for i in range( arnold.AiArrayGetNumElements( lights.contents ) ):
				light = arnold.cast(arnold.AiArrayGetPtr(lights, i), arnold.POINTER(arnold.AtNode))
				lightNames.append( arnold.AiNodeGetName(light.contents)  )

			doLinking = arnold.AiNodeGetBool( sphere, "use_light_group" )

			self.assertEqual( set( lightNames ), { "light:/group/light", "light:/group/light1" } )
			self.assertEqual( doLinking, True )

			# check shadows
			shadows = arnold.AiNodeGetArray( sphere, "shadow_group" )
			lightNames = []
			for i in range( arnold.AiArrayGetNumElements( shadows.contents ) ):
				light = arnold.cast(arnold.AiArrayGetPtr(shadows, i), arnold.POINTER(arnold.AtNode))
				lightNames.append( arnold.AiNodeGetName(light.contents)  )

			doLinking = arnold.AiNodeGetBool( sphere, "use_shadow_group" )

			self.assertEqual( set( lightNames ), { "light:/group/light", "light:/group/light1" } )
			self.assertEqual( doLinking, True )

			# the second sphere does not have any light linking enabled
			sphere1 = arnold.AiNodeLookUpByName( "/group/sphere1" )

			# check illumination
			lights = arnold.AiNodeGetArray( sphere1, "light_group" )
			lightNames = []
			for i in range( arnold.AiArrayGetNumElements( lights.contents ) ):
				light = arnold.cast(arnold.AiArrayGetPtr(lights, i), arnold.POINTER(arnold.AtNode))
				lightNames.append( arnold.AiNodeGetName(light.contents)  )

			doLinking = arnold.AiNodeGetBool( sphere1, "use_light_group" )

			self.assertEqual( lightNames, [] )
			self.assertEqual( doLinking, False )

			# check shadows
			shadows = arnold.AiNodeGetArray( sphere1, "shadow_group" )
			lightNames = []
			for i in range( arnold.AiArrayGetNumElements( shadows.contents ) ):
				light = arnold.cast(arnold.AiArrayGetPtr(shadows, i), arnold.POINTER(arnold.AtNode))
				lightNames.append( arnold.AiNodeGetName(light.contents)  )

			doLinking = arnold.AiNodeGetBool( sphere1, "use_shadow_group" )

			self.assertEqual( lightNames, [] )
			self.assertEqual( doLinking, False )
예제 #2
0
	def testLightAndShadowLinking( self ) :

		sphere1 = GafferScene.Sphere()
		sphere2 = GafferScene.Sphere()

		attributes = GafferScene.StandardAttributes()
		arnoldAttributes = GafferArnold.ArnoldAttributes()

		light1 = GafferArnold.ArnoldLight()
		light1.loadShader( "point_light" )

		light2 = GafferArnold.ArnoldLight()
		light2.loadShader( "point_light" )

		group = GafferScene.Group()

		render = GafferArnold.ArnoldRender()

		attributes["in"].setInput( sphere1["out"] )
		arnoldAttributes["in"].setInput( attributes["out"] )
		group["in"][0].setInput( arnoldAttributes["out"] )
		group["in"][1].setInput( light1["out"] )
		group["in"][2].setInput( light2["out"] )
		group["in"][3].setInput( sphere2["out"] )

		render["in"].setInput( group["out"] )

		# Illumination
		attributes["attributes"]["linkedLights"]["enabled"].setValue( True )
		attributes["attributes"]["linkedLights"]["value"].setValue( "/group/light" )

		# Shadows
		arnoldAttributes["attributes"]["shadowGroup"]["enabled"].setValue( True )
		arnoldAttributes["attributes"]["shadowGroup"]["value"].setValue( "/group/light1" )

		render["mode"].setValue( render.Mode.SceneDescriptionMode )
		render["fileName"].setValue( self.temporaryDirectory() + "/test.ass" )
		render["task"].execute()

		with IECoreArnold.UniverseBlock( writable = True ) :

			arnold.AiASSLoad( self.temporaryDirectory() + "/test.ass" )

			# the first sphere had linked lights
			sphere = arnold.AiNodeLookUpByName( "/group/sphere" )

			# check illumination
			self.assertTrue( arnold.AiNodeGetBool( sphere, "use_light_group" ) )
			lights = arnold.AiNodeGetArray( sphere, "light_group" )
			self.assertEqual( arnold.AiArrayGetNumElements( lights ), 1 )
			self.assertEqual(
				arnold.AiNodeGetName( arnold.AiArrayGetPtr( lights, 0 ) ),
				"light:/group/light"
			)

			# check shadows
			self.assertTrue( arnold.AiNodeGetBool( sphere, "use_shadow_group" ) )
			shadows = arnold.AiNodeGetArray( sphere, "shadow_group" )
			self.assertEqual( arnold.AiArrayGetNumElements( shadows ), 1 )
			self.assertEqual(
				arnold.AiNodeGetName( arnold.AiArrayGetPtr( shadows, 0 ) ),
				"light:/group/light1"
			)

			# the second sphere does not have any light linking enabled
			sphere1 = arnold.AiNodeLookUpByName( "/group/sphere1" )

			# check illumination
			self.assertFalse( arnold.AiNodeGetBool( sphere1, "use_light_group" ) )
			lights = arnold.AiNodeGetArray( sphere1, "light_group" )
			self.assertEqual( arnold.AiArrayGetNumElements( lights ), 0 )

			# check shadows
			self.assertFalse( arnold.AiNodeGetBool( sphere1, "use_shadow_group" ) )
			shadows = arnold.AiNodeGetArray( sphere1, "shadow_group" )
			self.assertEqual( arnold.AiArrayGetNumElements( shadows ), 0 )
예제 #3
0
    def testUpdate(self):

        network = IECoreScene.ShaderNetwork(shaders={
            "noiseHandle":
            IECoreScene.Shader("noise"),
            "flatHandle":
            IECoreScene.Shader("flat"),
        },
                                            connections=[
                                                (("noiseHandle", ""),
                                                 ("flatHandle", "color")),
                                            ],
                                            output="flatHandle")

        with IECoreArnold.UniverseBlock(writable=True):

            # Convert

            nodes = IECoreArnoldPreview.ShaderNetworkAlgo.convert(
                network, "test")

            def assertNoiseAndFlatNodes():

                self.assertEqual(len(nodes), 2)
                self.assertEqual(
                    arnold.AiNodeEntryGetName(
                        arnold.AiNodeGetNodeEntry(nodes[0])), "noise")
                self.assertEqual(
                    arnold.AiNodeEntryGetName(
                        arnold.AiNodeGetNodeEntry(nodes[1])), "flat")

                self.assertEqual(arnold.AiNodeGetName(nodes[0]),
                                 "test:noiseHandle")
                self.assertEqual(arnold.AiNodeGetName(nodes[1]), "test")

                self.assertEqual(
                    ctypes.addressof(
                        arnold.AiNodeGetLink(nodes[1], "color").contents),
                    ctypes.addressof(nodes[0].contents))

            assertNoiseAndFlatNodes()

            # Convert again with no changes at all. We want to see the same nodes reused.

            originalNodes = nodes[:]
            self.assertTrue(
                IECoreArnoldPreview.ShaderNetworkAlgo.update(nodes, network))
            assertNoiseAndFlatNodes()

            self.assertEqual(ctypes.addressof(nodes[0].contents),
                             ctypes.addressof(originalNodes[0].contents))
            self.assertEqual(ctypes.addressof(nodes[1].contents),
                             ctypes.addressof(originalNodes[1].contents))

            # Convert again with a tweak to a noise parameter. We want to see the same nodes
            # reused, with the new parameter value taking hold.

            noise = network.getShader("noiseHandle")
            noise.parameters["octaves"] = IECore.IntData(3)
            network.setShader("noiseHandle", noise)

            originalNodes = nodes[:]
            self.assertTrue(
                IECoreArnoldPreview.ShaderNetworkAlgo.update(nodes, network))
            assertNoiseAndFlatNodes()

            self.assertEqual(ctypes.addressof(nodes[0].contents),
                             ctypes.addressof(originalNodes[0].contents))
            self.assertEqual(ctypes.addressof(nodes[1].contents),
                             ctypes.addressof(originalNodes[1].contents))
            self.assertEqual(arnold.AiNodeGetInt(nodes[0], "octaves"), 3)

            # Remove the noise shader, and replace it with an image. Make sure the new network is as we expect, and
            # the old noise node has been destroyed.

            network.removeShader("noiseHandle")
            network.setShader("imageHandle", IECoreScene.Shader("image"))
            network.addConnection(
                (("imageHandle", ""), ("flatHandle", "color")))

            originalNodes = nodes[:]
            self.assertTrue(
                IECoreArnoldPreview.ShaderNetworkAlgo.update(nodes, network))

            self.assertEqual(ctypes.addressof(nodes[1].contents),
                             ctypes.addressof(originalNodes[1].contents))

            self.assertEqual(
                arnold.AiNodeEntryGetName(arnold.AiNodeGetNodeEntry(nodes[0])),
                "image")
            self.assertEqual(
                arnold.AiNodeEntryGetName(arnold.AiNodeGetNodeEntry(nodes[1])),
                "flat")

            self.assertEqual(arnold.AiNodeGetName(nodes[0]),
                             "test:imageHandle")
            self.assertEqual(arnold.AiNodeGetName(nodes[1]), "test")

            self.assertEqual(
                ctypes.addressof(
                    arnold.AiNodeGetLink(nodes[1], "color").contents),
                ctypes.addressof(nodes[0].contents))

            self.assertIsNone(arnold.AiNodeLookUpByName("test:noiseHandle"))

            # Replace the output shader with something else.

            network.removeShader("flatHandle")
            network.setShader("lambertHandle", IECoreScene.Shader("lambert"))
            network.addConnection(
                (("imageHandle", ""), ("lambertHandle", "Kd_color")))
            network.setOutput(("lambertHandle", ""))

            originalNodes = nodes[:]
            self.assertFalse(
                IECoreArnoldPreview.ShaderNetworkAlgo.update(nodes, network))

            self.assertEqual(ctypes.addressof(nodes[0].contents),
                             ctypes.addressof(originalNodes[0].contents))

            self.assertEqual(
                arnold.AiNodeEntryGetName(arnold.AiNodeGetNodeEntry(nodes[0])),
                "image")
            self.assertEqual(
                arnold.AiNodeEntryGetName(arnold.AiNodeGetNodeEntry(nodes[1])),
                "lambert")

            self.assertEqual(arnold.AiNodeGetName(nodes[0]),
                             "test:imageHandle")
            self.assertEqual(arnold.AiNodeGetName(nodes[1]), "test")

            self.assertEqual(
                ctypes.addressof(
                    arnold.AiNodeGetLink(nodes[1], "Kd_color").contents),
                ctypes.addressof(nodes[0].contents))
예제 #4
0
	def __allNodes( self, type = arnold.AI_NODE_ALL, ignoreRoot = True ) :

		result = []
		i = arnold.AiUniverseGetNodeIterator( type )
		while not arnold.AiNodeIteratorFinished( i ) :
			node = arnold.AiNodeIteratorGetNext( i )
			if ignoreRoot and arnold.AiNodeEntryGetName( arnold.AiNodeGetNodeEntry( node ) ) == "list_aggregate" and arnold.AiNodeGetName( node ) == "root" :
				continue
			result.append( node )

		return result