Exemplo n.º 1
0
	def testUserSuppliedHash( self ) :

		with IECoreArnold.UniverseBlock( writable = True ) :

			c = IECoreArnold.InstancingConverter()

			m1 = IECoreScene.MeshPrimitive.createPlane( imath.Box2f( imath.V2f( -1 ), imath.V2f( 1 ) ) )
			m2 = IECoreScene.MeshPrimitive.createPlane( imath.Box2f( imath.V2f( -2 ), imath.V2f( 2 ) ) )

			h1 = IECore.MurmurHash()
			h2 = IECore.MurmurHash()

			h1.append( 10 )
			h2.append( 10 )

			am1a = c.convert( m1, h1, "testMesh" )
			self.assertEqual( arnold.AiNodeEntryGetName( arnold.AiNodeGetNodeEntry( am1a ) ), "polymesh" )
			am1b = c.convert( m1, h1, "testInstance" )
			self.assertEqual( arnold.AiNodeEntryGetName( arnold.AiNodeGetNodeEntry( am1b ) ), "ginstance" )
			self.assertEqual( arnold.AiNodeGetPtr( am1b, "node" ), ctypes.addressof( am1a.contents ) )

			am2a = c.convert( m2, h2, "testMesh" )
			self.assertEqual( arnold.AiNodeEntryGetName( arnold.AiNodeGetNodeEntry( am2a ) ), "polymesh" )
			am2b = c.convert( m2, h2, "testInstance" )
			self.assertEqual( arnold.AiNodeEntryGetName( arnold.AiNodeGetNodeEntry( am2b ) ), "ginstance" )
			self.assertEqual( arnold.AiNodeGetPtr( am2b, "node" ), ctypes.addressof( am2a.contents ) )
Exemplo n.º 2
0
    def test(self):

        with IECoreArnold.UniverseBlock(writable=True):

            c = IECoreArnold.InstancingConverter()

            m1 = IECore.MeshPrimitive.createPlane(
                IECore.Box2f(IECore.V2f(-1), IECore.V2f(1)))
            m2 = m1.copy()
            m3 = IECore.MeshPrimitive.createPlane(
                IECore.Box2f(IECore.V2f(-2), IECore.V2f(2)))

            am1 = c.convert(m1)
            self.assertEqual(
                arnold.AiNodeEntryGetName(arnold.AiNodeGetNodeEntry(am1)),
                "polymesh")

            am2 = c.convert(m2)
            self.assertEqual(
                arnold.AiNodeEntryGetName(arnold.AiNodeGetNodeEntry(am2)),
                "ginstance")
            self.assertEqual(arnold.AiNodeGetPtr(am2, "node"),
                             ctypes.addressof(am1.contents))

            am3 = c.convert(m3)
            self.assertEqual(
                arnold.AiNodeEntryGetName(arnold.AiNodeGetNodeEntry(am3)),
                "polymesh")
Exemplo n.º 3
0
    def test(self):

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

        with IECoreArnold.UniverseBlock(writable=True):

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

            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))
Exemplo n.º 4
0
    def testLightFilters(self):

        s = Gaffer.ScriptNode()

        s["lightFilter"] = GafferArnold.ArnoldLightFilter()
        s["lightFilter"].loadShader("light_blocker")

        s["attributes"] = GafferScene.StandardAttributes()
        s["attributes"]["in"].setInput(s["lightFilter"]["out"])
        s["attributes"]["attributes"]["filteredLights"]["enabled"].setValue(
            True)
        s["attributes"]["attributes"]["filteredLights"]["value"].setValue(
            "defaultLights")

        s["light"] = GafferArnold.ArnoldLight()
        s["light"].loadShader("point_light")

        s["gobo"] = GafferArnold.ArnoldShader()
        s["gobo"].loadShader("gobo")

        s["assignment"] = GafferScene.ShaderAssignment()
        s["assignment"]["in"].setInput(s["light"]["out"])
        s["assignment"]["shader"].setInput(s["gobo"]["out"])

        s["group"] = GafferScene.Group()

        s["group"]["in"][0].setInput(s["attributes"]["out"])
        s["group"]["in"][1].setInput(s["assignment"]["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() +
                                         "/test.ass")

        s["render"]["task"].execute()

        with IECoreArnold.UniverseBlock(writable=True):

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

            light = arnold.AiNodeLookUpByName("light:/group/light")
            linkedFilters = arnold.AiNodeGetArray(light, "filters")
            numFilters = arnold.AiArrayGetNumElements(linkedFilters.contents)

            self.assertEqual(numFilters, 2)

            linkedFilter = arnold.cast(arnold.AiArrayGetPtr(linkedFilters, 0),
                                       arnold.POINTER(arnold.AtNode))
            linkedGobo = arnold.cast(arnold.AiArrayGetPtr(linkedFilters, 1),
                                     arnold.POINTER(arnold.AtNode))

            self.assertEqual(arnold.AiNodeGetName(linkedFilter),
                             "lightFilter:/group/lightFilter")
            self.assertEqual(
                arnold.AiNodeEntryGetName(
                    arnold.AiNodeGetNodeEntry(linkedFilter)), "light_blocker")
            self.assertEqual(
                arnold.AiNodeEntryGetName(
                    arnold.AiNodeGetNodeEntry(linkedGobo)), "gobo")
Exemplo n.º 5
0
    def testBlindData(self):

        flat = IECoreScene.Shader("flat")
        flat.blindData().update({
            "user:testInt":
            IECore.IntData(1),
            "user:testFloat":
            IECore.FloatData(2.5),
            "user:testV3f":
            IECore.V3fData(imath.V3f(1, 2, 3)),
            "user:testColor3f":
            IECore.Color3fData(imath.Color3f(4, 5, 6)),
            "user:testString":
            IECore.StringData("we're all doomed"),
        })

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

        with IECoreArnold.UniverseBlock(writable=True) as universe:

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

            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(arnold.AiNodeGetInt(nodes[1], "user:testInt"), 1)
            self.assertEqual(arnold.AiNodeGetFlt(nodes[1], "user:testFloat"),
                             2.5)
            self.assertEqual(arnold.AiNodeGetVec(nodes[1], "user:testV3f"),
                             arnold.AtVector(1, 2, 3))
            self.assertEqual(arnold.AiNodeGetRGB(nodes[1], "user:testColor3f"),
                             arnold.AtRGB(4, 5, 6))
            self.assertEqual(arnold.AiNodeGetStr(nodes[1], "user:testString"),
                             "we're all doomed")
			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 )
				)
Exemplo n.º 7
0
    def testEnabling(self):

        r = IECoreArnold.Renderer()

        with IECore.WorldBlock(r):

            r.setAttribute("ai:automaticInstancing", IECore.BoolData(True))

            m = IECore.MeshPrimitive.createPlane(
                IECore.Box2f(IECore.V2f(-1), IECore.V2f(1)))

            m.render(r)
            m.render(r)

            nodes = self.__allNodes(type=arnold.AI_NODE_SHAPE)
            self.assertEqual(len(nodes), 2)

            nodeTypes = [
                arnold.AiNodeEntryGetName(arnold.AiNodeGetNodeEntry(n))
                for n in nodes
            ]
            mesh = nodes[nodeTypes.index("polymesh")]
            instance = nodes[nodeTypes.index("ginstance")]

            self.assertEqual(arnold.AiNodeGetPtr(instance, "node"),
                             ctypes.addressof(mesh.contents))
Exemplo n.º 8
0
    def testConvertPerspective(self):

        with IECoreArnold.UniverseBlock(writable=True):

            n = IECoreArnold.NodeAlgo.convert(
                IECoreScene.Camera(
                    parameters={
                        "projection":
                        "perspective",
                        "projection:fov":
                        45.0,
                        "resolution":
                        imath.V2i(512),
                        "screenWindow":
                        imath.Box2f(imath.V2f(-1, -0.5), imath.V2f(1, 0.5))
                    }), "testCamera")

            self.assertTrue(
                arnold.AiNodeEntryGetName(arnold.AiNodeGetNodeEntry(n)),
                "persp_camera")
            self.assertEqual(arnold.AiNodeGetFlt(n, "fov"), 45.0)

            self.assertEqual(arnold.AiNodeGetVec2(n, "screen_window_min"),
                             arnold.AtVector2(-1, -0.5))
            self.assertEqual(arnold.AiNodeGetVec2(n, "screen_window_max"),
                             arnold.AtVector2(1, 0.5))
Exemplo n.º 9
0
    def testProcedural(self):

        r = IECoreArnold.Renderer("/tmp/test.ass")

        with IECore.WorldBlock(r):

            r.procedural(
                r.ExternalProcedural(
                    "someVolumeThing.so",
                    IECore.Box3f(IECore.V3f(-1, -2, -3), IECore.V3f(4, 5, 6)),
                    {
                        "ai:nodeType": "volume",
                        "testFloat": 0.5
                    }))

            volume = self.__allNodes(type=arnold.AI_NODE_SHAPE)[-1]
            self.assertEqual(
                arnold.AiNodeEntryGetName(arnold.AiNodeGetNodeEntry(volume)),
                "volume")

            self.assertEqual(arnold.AiNodeGetPnt(volume, "min"),
                             arnold.AtPoint(-1, -2, -3))
            self.assertEqual(arnold.AiNodeGetPnt(volume, "max"),
                             arnold.AtPoint(4, 5, 6))
            self.assertEqual(arnold.AiNodeGetStr(volume, "dso"),
                             "someVolumeThing.so")
            self.assertEqual(arnold.AiNodeGetFlt(volume, "testFloat"), 0.5)
Exemplo n.º 10
0
	def testConvertPerspective( self ) :

		with IECoreArnold.UniverseBlock( writable = True ) :

			c = IECoreScene.Camera(
				parameters = {
					"projection" : "perspective",
					"focalLength" : 1 / ( 2.0 * math.tan( 0.5 * math.radians( 45 ) ) ),
					"resolution" : imath.V2i( 512 ),
					"aperture" : imath.V2f( 2, 1 )
				}
			)

			n = IECoreArnold.NodeAlgo.convert( c, "testCamera" )
			screenWindow = c.frustum()

			self.assertTrue( arnold.AiNodeEntryGetName( arnold.AiNodeGetNodeEntry( n ) ), "persp_camera" )

			screenWindowMult = math.tan( 0.5 * math.radians( arnold.AiNodeGetFlt( n, "fov" ) ) )

			self.assertAlmostEqual( screenWindowMult * arnold.AiNodeGetVec2( n, "screen_window_min" ).x, screenWindow.min()[0], 6 )
			self.assertAlmostEqual( screenWindowMult * arnold.AiNodeGetVec2( n, "screen_window_min" ).y, screenWindow.min()[1], 6 )
			self.assertAlmostEqual( screenWindowMult * arnold.AiNodeGetVec2( n, "screen_window_max" ).x, screenWindow.max()[0], 6 )
			self.assertAlmostEqual( screenWindowMult * arnold.AiNodeGetVec2( n, "screen_window_max" ).y, screenWindow.max()[1], 6 )
			
			# For perspective cameras, we set a FOV value that drives the effective screen window.
			# As long as pixels aren't distorted, and there is no aperture offset,
			# applying Arnold's automatic screen window computation to a default screen window
			# should give us the correct result
			self.assertEqual( arnold.AiNodeGetVec2( n, "screen_window_min" ).x, -1.0 )
			self.assertEqual( arnold.AiNodeGetVec2( n, "screen_window_min" ).y, -1.0 )
			self.assertEqual( arnold.AiNodeGetVec2( n, "screen_window_max" ).x, 1.0 )
			self.assertEqual( arnold.AiNodeGetVec2( n, "screen_window_max" ).y, 1.0 )
Exemplo n.º 11
0
	def testConvert( self ) :

		s = IECore.SpherePrimitive( 0.25 )
		with IECoreArnold.UniverseBlock() :

			n = IECoreArnold.NodeAlgo.convert( s )
			self.assertEqual( arnold.AiNodeEntryGetName( arnold.AiNodeGetNodeEntry( n ) ), "sphere" )
			self.assertEqual( arnold.AiNodeGetFlt( n, "radius" ), 0.25 )
Exemplo n.º 12
0
	def testConvert( self ) :

		s = IECoreScene.SpherePrimitive( 0.25 )
		with IECoreArnold.UniverseBlock( writable = True ) as universe :

			n = IECoreArnold.NodeAlgo.convert( s, universe, "testSphere" )
			self.assertEqual( arnold.AiNodeEntryGetName( arnold.AiNodeGetNodeEntry( n ) ), "sphere" )
			self.assertEqual( arnold.AiNodeGetFlt( n, "radius" ), 0.25 )
Exemplo n.º 13
0
    def testThreading(self):

        with IECoreArnold.UniverseBlock(writable=True):

            converter = IECoreArnold.InstancingConverter()

            meshes = []
            for i in range(0, 1000):
                meshes.append(
                    IECore.MeshPrimitive.createPlane(
                        IECore.Box2f(IECore.V2f(-i), IECore.V2f(i))))

            def f(nodeList):
                for i in range(0, 10000):
                    nodeList.append(
                        converter.convert(random.choice(meshes), "testMesh"))

            nodeLists = []
            threads = []
            for i in range(0, 10):
                nodeList = []
                nodeLists.append(nodeList)
                t = threading.Thread(target=f, args=(nodeList, ))
                threads.append(t)
                t.start()

            for t in threads:
                t.join()

            numPolyMeshNodes = 0
            numInstanceNodes = 0
            polyMeshAddresses = set()
            instancedNodeAddresses = []
            for nodeList in nodeLists:

                self.assertEqual(len(nodeList), 10000)

                for node in nodeList:

                    nodeType = arnold.AiNodeEntryGetName(
                        arnold.AiNodeGetNodeEntry(node))
                    self.failUnless(nodeType in ("ginstance", "polymesh"))

                    if nodeType == "ginstance":
                        numInstanceNodes += 1
                        instancedNodeAddresses.append(
                            arnold.AiNodeGetPtr(node, "node"))
                    else:
                        numPolyMeshNodes += 1
                        polyMeshAddresses.add(ctypes.addressof(node.contents))

            self.assertEqual(numInstanceNodes + numPolyMeshNodes, 10000 * 10)
            for address in instancedNodeAddresses:
                self.failUnless(address in polyMeshAddresses)
Exemplo n.º 14
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
Exemplo n.º 15
0
    def testMotion(self):

        with IECoreArnold.UniverseBlock(writable=True):

            c = IECoreArnold.InstancingConverter()

            m1 = IECore.MeshPrimitive.createPlane(
                IECore.Box2f(IECore.V2f(-1), IECore.V2f(1)))
            m2 = IECore.MeshPrimitive.createPlane(
                IECore.Box2f(IECore.V2f(-2), IECore.V2f(2)))

            n1 = c.convert([m1, m2], -0.25, 0.25, "testMesh")
            self.assertEqual(
                arnold.AiNodeEntryGetName(arnold.AiNodeGetNodeEntry(n1)),
                "polymesh")
            self.assertEqual(
                arnold.AiArrayGetNumKeys(
                    arnold.AiNodeGetArray(n1, "vlist").contents), 2)

            n2 = c.convert([m1, m2], -0.25, 0.25, "testInstance")
            self.assertEqual(
                arnold.AiNodeEntryGetName(arnold.AiNodeGetNodeEntry(n2)),
                "ginstance")
            self.assertEqual(arnold.AiNodeGetPtr(n2, "node"),
                             ctypes.addressof(n1.contents))

            n3 = c.convert([m2, m1], -0.25, 0.25, "testMesh")
            self.assertEqual(
                arnold.AiNodeEntryGetName(arnold.AiNodeGetNodeEntry(n1)),
                "polymesh")
            self.assertEqual(
                arnold.AiArrayGetNumKeys(
                    arnold.AiNodeGetArray(n1, "vlist").contents), 2)

            n4 = c.convert([m1, m2], -0.5, 0.5, "testInstance")
            self.assertEqual(
                arnold.AiNodeEntryGetName(arnold.AiNodeGetNodeEntry(n1)),
                "polymesh")
            self.assertEqual(
                arnold.AiArrayGetNumKeys(
                    arnold.AiNodeGetArray(n1, "vlist").contents), 2)
Exemplo n.º 16
0
	def testConvertWithMotion( self ) :

		s = [ IECore.SpherePrimitive( 0.25 ), IECore.SpherePrimitive( 0.5 ) ]

		with IECoreArnold.UniverseBlock( writable = True ) :

			n = IECoreArnold.NodeAlgo.convert( s, 0, 1, "testSphere" )
			self.assertEqual( arnold.AiNodeEntryGetName( arnold.AiNodeGetNodeEntry( n ) ), "sphere" )

			a = arnold.AiNodeGetArray( n, "radius" )
			self.assertEqual( arnold.AiArrayGetFlt( a, 0 ), 0.25 )
			self.assertEqual( arnold.AiArrayGetFlt( a, 1 ), 0.5 )

			self.assertEqual( arnold.AiNodeGetFlt( n, "motion_start" ), 0 )
			self.assertEqual( arnold.AiNodeGetFlt( n, "motion_end" ), 1 )
Exemplo n.º 17
0
	def testConvertWithMotion( self ) :

		s = [ IECore.SpherePrimitive( 0.25 ), IECore.SpherePrimitive( 0.5 ) ]

		with IECoreArnold.UniverseBlock() :

			n = IECoreArnold.NodeAlgo.convert( s, [ 0, 1 ] )
			self.assertEqual( arnold.AiNodeEntryGetName( arnold.AiNodeGetNodeEntry( n ) ), "sphere" )

			a = arnold.AiNodeGetArray( n, "radius" )
			self.assertEqual( arnold.AiArrayGetFlt( a, 0 ), 0.25 )
			self.assertEqual( arnold.AiArrayGetFlt( a, 1 ), 0.5 )

			a = arnold.AiNodeGetArray( n, "deform_time_samples" )
			self.assertEqual( arnold.AiArrayGetFlt( a, 0 ), 0 )
			self.assertEqual( arnold.AiArrayGetFlt( a, 1 ), 1 )
Exemplo n.º 18
0
    def testConvertCustomProjection(self):

        with IECoreArnold.UniverseBlock(writable=True):

            n = IECoreArnold.NodeAlgo.convert(
                IECoreScene.Camera(
                    parameters={
                        "projection": "cyl_camera",
                        "horizontal_fov": 45.0,
                        "vertical_fov": 80.0,
                    }), "testCamera")

            self.assertTrue(
                arnold.AiNodeEntryGetName(arnold.AiNodeGetNodeEntry(n)),
                "cyl_camera")
            self.assertEqual(arnold.AiNodeGetFlt(n, "horizontal_fov"), 45.0)
            self.assertEqual(arnold.AiNodeGetFlt(n, "vertical_fov"), 80.0)
	def testDisabling( self ) :
	
		r = IECoreArnold.Renderer()
		
		with IECore.WorldBlock( r ) :
		
			r.setAttribute( "ai:automaticInstancing", IECore.BoolData( False ) )
			
			m = IECore.MeshPrimitive.createPlane( IECore.Box2f( IECore.V2f( -1 ), IECore.V2f( 1 ) ) )
			
			m.render( r )
			m.render( r )
			
			nodes = self.__allNodes( type = arnold.AI_NODE_SHAPE )
			self.assertEqual( len( nodes ), 2 )
			
			nodeTypes = [ arnold.AiNodeEntryGetName( arnold.AiNodeGetNodeEntry( n ) ) for n in nodes ]
			self.assertEqual( nodeTypes, [ "polymesh", "polymesh" ] )
Exemplo n.º 20
0
	def testProcedural( self ) :

		r = IECoreArnold.Renderer( "/tmp/test.ass" )

		with IECore.WorldBlock( r ) :

			# In Arnold 5, external procedurals register node types that look just like the built-in
			# ones.  So we need to be able to use ExternalProcedural to create an arbitrary node type,
			# instead of passing in a filename. Test with a volume, because this node type exists by default.
			r.procedural(
				r.ExternalProcedural(
					"volume",
					IECore.Box3f( IECore.V3f( -1, -2, -3 ), IECore.V3f( 4, 5, 6 ) ),
					{
						"testFloat" : 0.5
					}
				)
			)

			volume = self.__allNodes( type = arnold.AI_NODE_SHAPE )[-1]
			self.assertEqual( arnold.AiNodeEntryGetName( arnold.AiNodeGetNodeEntry( volume ) ), "volume" )

			self.assertEqual( arnold.AiNodeGetFlt( volume, "testFloat" ), 0.5 )
Exemplo n.º 21
0
	def testConvertPerspective( self ) :

		with IECoreArnold.UniverseBlock( writable = True ) :

			c = IECoreScene.Camera(
				parameters = {
					"projection" : "perspective",
					"focalLength" : 1 / ( 2.0 * math.tan( 0.5 * math.radians( 45 ) ) ),
					"resolution" : imath.V2i( 512 ),
					"aperture" : imath.V2f( 2, 1 )
				}
			)

			n = IECoreArnold.NodeAlgo.convert( c, "testCamera" )
			screenWindow = c.frustum()

			self.assertTrue( arnold.AiNodeEntryGetName( arnold.AiNodeGetNodeEntry( n ) ), "persp_camera" )

			screenWindowMult = math.tan( 0.5 * math.radians( arnold.AiNodeGetFlt( n, "fov" ) ) )

			self.assertAlmostEqual( screenWindowMult * arnold.AiNodeGetVec2( n, "screen_window_min" ).x, screenWindow.min()[0] )
			self.assertAlmostEqual( screenWindowMult * arnold.AiNodeGetVec2( n, "screen_window_min" ).y, screenWindow.min()[1] )
			self.assertAlmostEqual( screenWindowMult * arnold.AiNodeGetVec2( n, "screen_window_max" ).x, screenWindow.max()[0] )
			self.assertAlmostEqual( screenWindowMult * arnold.AiNodeGetVec2( n, "screen_window_max" ).y, screenWindow.max()[1] )
Exemplo n.º 22
0
    def testSceneDescription(self):

        r = GafferScene.Private.IECoreScenePreview.Renderer.create(
            "IECoreArnold::Renderer", GafferScene.Private.IECoreScenePreview.
            Renderer.RenderType.SceneDescription,
            self.temporaryDirectory() + "/test.ass")

        o = r.object(
            "testPlane",
            IECore.MeshPrimitive.createPlane(
                IECore.Box2f(IECore.V2f(-1), IECore.V2f(1))))
        o.transform(IECore.M44f().translate(IECore.V3f(1, 2, 3)))

        r.render()
        del r

        with IECoreArnold.UniverseBlock():

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

            n = arnold.AiNodeLookUpByName("testPlane")
            self.assertTrue(
                arnold.AiNodeEntryGetType(arnold.AiNodeGetNodeEntry(n)),
                arnold.AI_NODE_SHAPE)
Exemplo n.º 23
0
def GetNode(user_data, i):
    ptype, pval = user_data.get("type")
    n = arnold.AiNode(pval)
    if n:
        name = "sample_%s" % pval
        arnold.AiNodeSetStr(n, "name", name)
        ne = arnold.AiNodeGetNodeEntry(n)
        for k, v in user_data.iteritems():
            if k == "type":
                continue
            ptype, pval = v
            pe = arnold.AiNodeEntryLookUpParameter(ne, k)
            if pe:
                if ptype == arnold.AI_TYPE_BOOLEAN:
                    arnold.AiNodeSetBool(n, k, pval)
                elif ptype == arnold.AI_TYPE_INT:
                    arnold.AiNodeSetInt(n, k, pval)
                elif ptype == arnold.AI_TYPE_UINT:
                    arnold.AiNodeSetUInt(n, k, pval)
                elif ptype == arnold.AI_TYPE_FLOAT:
                    arnold.AiNodeSetFlt(n, k, pval)
                elif ptype == arnold.AI_TYPE_POINT:
                    arnold.AiNodeSetPnt(n, k, pval.x, pval.y, pval.z)
                elif ptype == arnold.AI_TYPE_POINT2:
                    arnold.AiNodeSetPnt2(n, k, pval.x, pval.y)
                elif ptype == arnold.AI_TYPE_VECTOR:
                    arnold.AiNodeSetVec(n, k, pval.x, pval.y, pval.z)
                elif ptype == arnold.AI_TYPE_RGB:
                    arnold.AiNodeSetRGB(n, k, pval.r, pval.g, pval.b)
                elif ptype == arnold.AI_TYPE_RGBA:
                    arnold.AiNodeSetRGBA(n, k, pval.r, pval.g, pval.b, pval.a)
                elif ptype == arnold.AI_TYPE_STRING:
                    arnold.AiNodeSetStr(n, k, pval)
        return name
    else:
        return None
Exemplo n.º 24
0
    def testOldRandomCamera(self):

        random.seed(42)

        with IECoreArnold.UniverseBlock(writable=True):
            for i in range(40):
                resolution = imath.V2i(random.randint(10, 1000),
                                       random.randint(10, 1000))
                pixelAspectRatio = random.uniform(0.5, 2)
                screenWindow = imath.Box2f(
                    imath.V2f(-random.uniform(0, 2), -random.uniform(0, 2)),
                    imath.V2f(random.uniform(0, 2), random.uniform(0, 2)))

                screenWindowAspectScale = imath.V2f(
                    1.0, (screenWindow.size()[0] / screenWindow.size()[1]) *
                    (resolution[1] / float(resolution[0])) / pixelAspectRatio)
                screenWindow.setMin(screenWindow.min() *
                                    screenWindowAspectScale)
                screenWindow.setMax(screenWindow.max() *
                                    screenWindowAspectScale)

                c = IECoreScene.Camera(
                    parameters={
                        "projection":
                        "orthographic"
                        if random.random() > 0.5 else "perspective",
                        "projection:fov":
                        random.uniform(1, 100),
                        "clippingPlanes":
                        imath.V2f(random.uniform(0.001, 100)) +
                        imath.V2f(0, random.uniform(0, 1000)),
                        "resolution":
                        resolution,
                        "pixelAspectRatio":
                        pixelAspectRatio
                    })

                if i < 20:
                    c.parameters()["screenWindow"] = screenWindow

                n = IECoreArnold.NodeAlgo.convert(c, "testCamera")

                arnoldType = "persp_camera"
                if c.parameters()["projection"].value == "orthographic":
                    arnoldType = "ortho_camera"

                self.assertEqual(
                    arnold.AiNodeEntryGetName(arnold.AiNodeGetNodeEntry(n)),
                    arnoldType)

                cortexClip = c.parameters()["clippingPlanes"].value
                self.assertEqual(arnold.AiNodeGetFlt(n, "near_clip"),
                                 cortexClip[0])
                self.assertEqual(arnold.AiNodeGetFlt(n, "far_clip"),
                                 cortexClip[1])

                resolution = c.parameters()["resolution"].value
                aspect = c.parameters(
                )["pixelAspectRatio"].value * resolution.x / float(
                    resolution.y)

                if "screenWindow" in c.parameters():
                    cortexWindow = c.parameters()["screenWindow"].value
                else:
                    if aspect > 1.0:
                        cortexWindow = imath.Box2f(imath.V2f(-aspect, -1),
                                                   imath.V2f(aspect, 1))
                    else:
                        cortexWindow = imath.Box2f(imath.V2f(-1, -1 / aspect),
                                                   imath.V2f(1, 1 / aspect))

                if c.parameters()["projection"].value != "orthographic":
                    windowScale = math.tan(
                        math.radians(0.5 * arnold.AiNodeGetFlt(n, "fov")))
                    cortexWindowScale = math.tan(
                        math.radians(0.5 *
                                     c.parameters()["projection:fov"].value))
                else:
                    windowScale = 1.0
                    cortexWindowScale = 1.0

                self.assertAlmostEqual(
                    windowScale *
                    arnold.AiNodeGetVec2(n, "screen_window_min").x,
                    cortexWindowScale * cortexWindow.min()[0],
                    places=4)
                self.assertAlmostEqual(
                    windowScale *
                    arnold.AiNodeGetVec2(n, "screen_window_min").y,
                    cortexWindowScale * cortexWindow.min()[1] * aspect,
                    places=4)
                self.assertAlmostEqual(
                    windowScale *
                    arnold.AiNodeGetVec2(n, "screen_window_max").x,
                    cortexWindowScale * cortexWindow.max()[0],
                    places=4)
                self.assertAlmostEqual(
                    windowScale *
                    arnold.AiNodeGetVec2(n, "screen_window_max").y,
                    cortexWindowScale * cortexWindow.max()[1] * aspect,
                    places=4)

                if c.parameters()["projection"].value == "perspective":
                    self.assertAlmostEqual(
                        arnold.AiNodeGetVec2(n, "screen_window_max").x -
                        arnold.AiNodeGetVec2(n, "screen_window_min").x,
                        2.0,
                        places=6)
                    self.assertAlmostEqual(
                        arnold.AiNodeGetVec2(n, "screen_window_max").y -
                        arnold.AiNodeGetVec2(n, "screen_window_min").y,
                        2.0,
                        places=6)
Exemplo n.º 25
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))