示例#1
0
	def testMetadataLoading( self ) :

		os.environ["ARNOLD_PLUGIN_PATH"] = os.path.join( os.path.dirname( __file__ ), "metadata" )
		with IECoreArnold.UniverseBlock( writable = True ) :
			pass

		with IECoreArnold.UniverseBlock( writable = False ) :

			e = arnold.AiNodeEntryLookUp( "options" )

			s = arnold.AtStringReturn()
			i = ctypes.c_int()


			arnold.AiMetaDataGetStr( e, "", "cortex.testString", s )
			self.assertEqual( arnold.AtStringToStr( s ), "test" )

			arnold.AiMetaDataGetInt( e, "", "cortex.testInt", i )
			self.assertEqual( i.value, 25 )

			arnold.AiMetaDataGetStr( e, "AA_samples", "cortex.testString", s )
			self.assertEqual( arnold.AtStringToStr( s ), "test2" )

			arnold.AiMetaDataGetInt( e, "AA_samples", "cortex.testInt", i )
			self.assertEqual( i.value, 12 )
示例#2
0
    def testReadOnlyUniverseDoesntPreventWritableUniverseCleanup(self):

        with IECoreArnold.UniverseBlock(writable=False):

            with IECoreArnold.UniverseBlock(writable=True):

                node = arnold.AiNode("polymesh")
                arnold.AiNodeSetStr(node, "name", "test")

            self.assertEqual(arnold.AiNodeLookUpByName("test"), None)
示例#3
0
	def test( self ) :

		self.failIf( arnold.AiUniverseIsActive() )

		with IECoreArnold.UniverseBlock( writable = False ) :

			self.failUnless( arnold.AiUniverseIsActive() )

			with IECoreArnold.UniverseBlock( writable = False ) :

				self.failUnless( arnold.AiUniverseIsActive() )

			self.failUnless( arnold.AiUniverseIsActive() )
示例#4
0
    def test(self):

        self.assertFalse(arnold.AiUniverseIsActive())

        with IECoreArnold.UniverseBlock(writable=False):

            self.assertTrue(arnold.AiUniverseIsActive())

            with IECoreArnold.UniverseBlock(writable=False):

                self.assertTrue(arnold.AiUniverseIsActive())

            self.assertTrue(arnold.AiUniverseIsActive())
示例#5
0
    def test(self):

        if not self.__usingMultipleUniverses:
            self.assertFalse(arnold.AiUniverseIsActive())

        with IECoreArnold.UniverseBlock(writable=False):

            self.assertTrue(arnold.AiUniverseIsActive())

            with IECoreArnold.UniverseBlock(writable=False):

                self.assertTrue(arnold.AiUniverseIsActive())

            self.assertTrue(arnold.AiUniverseIsActive())
示例#6
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 )
示例#7
0
    def testAdditionalUVs(self):

        m = IECoreScene.MeshPrimitive.createPlane(
            imath.Box2f(imath.V2f(-1), imath.V2f(1)))
        m["myMap"] = m["uv"]
        uvData = m["myMap"].data
        indicesData = m["myMap"].indices

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

            n = IECoreArnold.NodeAlgo.convert(m, universe, "testMesh")

            uvs = arnold.AiNodeGetArray(n, "myMap")
            self.assertEqual(arnold.AiArrayGetNumElements(uvs.contents), 4)

            uvIndices = arnold.AiNodeGetArray(n, "myMapidxs")
            self.assertEqual(arnold.AiArrayGetNumElements(uvIndices.contents),
                             4)

            for i in range(0, 4):
                p = arnold.AiArrayGetVec2(uvs, i)
                self.assertEqual(arnold.AiArrayGetVec2(uvs, i),
                                 arnold.AtVector2(uvData[i][0], uvData[i][1]))
                self.assertEqual(arnold.AiArrayGetInt(uvIndices, i),
                                 indicesData[i])
示例#8
0
    def testVertexUVs(self):

        c = IECoreScene.CurvesPrimitive(IECore.IntVectorData([2, 2]),
                                        IECore.CubicBasisf.linear())
        c["P"] = IECoreScene.PrimitiveVariable(
            IECoreScene.PrimitiveVariable.Interpolation.Vertex,
            IECore.V3fVectorData([imath.V3f(x, 0, 0) for x in range(0, 4)]))
        c["uv"] = IECoreScene.PrimitiveVariable(
            IECoreScene.PrimitiveVariable.Interpolation.Vertex,
            IECore.V2fVectorData([
                imath.V2f(1, 2),
                imath.V2f(3, 4),
                imath.V2f(5, 6),
                imath.V2f(7, 8),
            ], IECore.GeometricData.Interpretation.UV))

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

            n = IECoreArnold.NodeAlgo.convert(c, universe, "testCurve")

            uvs = arnold.AiNodeGetArray(n, "uvs").contents
            self.assertEqual(arnold.AiArrayGetNumElements(uvs), 4)

            self.assertEqual(arnold.AiArrayGetVec2(uvs, 0),
                             arnold.AtVector2(1, 2))
            self.assertEqual(arnold.AiArrayGetVec2(uvs, 1),
                             arnold.AtVector2(3, 4))
            self.assertEqual(arnold.AiArrayGetVec2(uvs, 2),
                             arnold.AtVector2(5, 6))
            self.assertEqual(arnold.AiArrayGetVec2(uvs, 3),
                             arnold.AtVector2(7, 8))
示例#9
0
    def testMotion(self):

        c1 = IECoreScene.CurvesPrimitive(IECore.IntVectorData([4]))
        c2 = IECoreScene.CurvesPrimitive(IECore.IntVectorData([4]))

        c1["P"] = IECoreScene.PrimitiveVariable(
            IECoreScene.PrimitiveVariable.Interpolation.Vertex,
            IECore.V3fVectorData([imath.V3f(1)] * 4),
        )

        c2["P"] = IECoreScene.PrimitiveVariable(
            IECoreScene.PrimitiveVariable.Interpolation.Vertex,
            IECore.V3fVectorData([imath.V3f(2)] * 4),
        )

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

            n = IECoreArnold.NodeAlgo.convert([c1, c2], -0.25, 0.25, universe,
                                              "testCurve")

            a = arnold.AiNodeGetArray(n, "points")
            self.assertEqual(arnold.AiArrayGetNumElements(a.contents), 4)
            self.assertEqual(arnold.AiArrayGetNumKeys(a.contents), 2)

            for i in range(0, 4):
                self.assertEqual(arnold.AiArrayGetVec(a, i),
                                 arnold.AtVector(1))
            for i in range(4, 8):
                self.assertEqual(arnold.AiArrayGetVec(a, i),
                                 arnold.AtVector(2))

            self.assertEqual(arnold.AiNodeGetFlt(n, "motion_start"), -0.25)
            self.assertEqual(arnold.AiNodeGetFlt(n, "motion_end"), 0.25)
示例#10
0
    def testUVs(self):

        m = IECoreScene.MeshPrimitive.createPlane(
            imath.Box2f(imath.V2f(-1), imath.V2f(1)))
        m["uv"] = IECoreScene.PrimitiveVariable(
            IECoreScene.PrimitiveVariable.Interpolation.FaceVarying,
            m["uv"].expandedData())
        uvData = m["uv"].data

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

            n = IECoreArnold.NodeAlgo.convert(m, universe, "testMesh")

            uvs = arnold.AiNodeGetArray(n, "uvlist")
            self.assertEqual(arnold.AiArrayGetNumElements(uvs.contents), 4)

            uvIndices = arnold.AiNodeGetArray(n, "uvidxs")
            self.assertEqual(arnold.AiArrayGetNumElements(uvIndices.contents),
                             4)

            for i in range(0, 4):
                p = arnold.AiArrayGetVec2(uvs, i)
                self.assertEqual(arnold.AiArrayGetVec2(uvs, i),
                                 arnold.AtVector2(uvData[i][0], uvData[i][1]))
                self.assertEqual(arnold.AiArrayGetInt(uvIndices, i), i)
示例#11
0
    def testDoubleData(self):

        with IECoreArnold.UniverseBlock(writable=True):

            n = arnold.AiNode("standard_surface")

            IECoreArnold.ParameterAlgo.setParameter(n, "base",
                                                    IECore.DoubleData(0.25))
            self.assertEqual(arnold.AiNodeGetFlt(n, "base"), 0.25)

            IECoreArnold.ParameterAlgo.setParameter(n, "customFloat",
                                                    IECore.DoubleData(0.25))
            self.assertEqual(arnold.AiNodeGetFlt(n, "customFloat"), 0.25)

            IECoreArnold.ParameterAlgo.setParameter(
                n, "customMatrix",
                IECore.M44dData(
                    imath.M44d(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
                               15, 16)))
            m = arnold.AiNodeGetMatrix(n, "customMatrix")
            self.assertEqual(
                [list(i) for i in m.data],
                [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]
                 ],
            )
示例#12
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")
示例#13
0
    def testPointTypePrimitiveVariables(self):
        # make sure that we can add prim vars of both vector and point type, and differentiate between the two.
        m = IECoreScene.MeshPrimitive.createPlane(
            imath.Box2f(imath.V2f(-1), imath.V2f(1)))

        points = IECore.V3fVectorData([])
        IECore.setGeometricInterpretation(
            points, IECore.GeometricData.Interpretation.Point)
        m["points"] = IECoreScene.PrimitiveVariable(
            IECoreScene.PrimitiveVariable.Interpolation.Vertex, points)

        vectors = IECore.V3fVectorData([])
        IECore.setGeometricInterpretation(
            vectors, IECore.GeometricData.Interpretation.Vector)
        m["vectors"] = IECoreScene.PrimitiveVariable(
            IECoreScene.PrimitiveVariable.Interpolation.Vertex, vectors)

        with IECoreArnold.UniverseBlock(writable=True) as universe:
            node = IECoreArnold.NodeAlgo.convert(m, universe, "testMesh")
            p = arnold.AiNodeGetArray(node, "points")
            self.assertEqual(arnold.AiArrayGetType(p.contents),
                             arnold.AI_TYPE_VECTOR)

            v = arnold.AiNodeGetArray(node, "vectors")
            self.assertEqual(arnold.AiArrayGetType(v.contents),
                             arnold.AI_TYPE_VECTOR)
示例#14
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))
示例#15
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 ) )
示例#16
0
    def testIndexedUVs(self):

        m = IECore.MeshPrimitive.createPlane(
            IECore.Box2f(IECore.V2f(-1), IECore.V2f(1)))
        m["uv"] = IECore.PrimitiveVariable(
            IECore.PrimitiveVariable.Interpolation.FaceVarying, m["uv"].data,
            IECore.IntVectorData([0, 3, 1, 2]))
        uvData = m["uv"].data
        uvIds = m["uv"].indices

        with IECoreArnold.UniverseBlock(writable=True):

            n = IECoreArnold.NodeAlgo.convert(m, "testMesh")

            uvs = arnold.AiNodeGetArray(n, "uvlist")
            self.assertEqual(arnold.AiArrayGetNumElements(uvs.contents), 4)

            uvIndices = arnold.AiNodeGetArray(n, "uvidxs")
            self.assertEqual(arnold.AiArrayGetNumElements(uvIndices.contents),
                             4)

            for i in range(0, 4):
                aiUv = arnold.AiArrayGetVec2(uvs, i)
                aiUVId = arnold.AiArrayGetInt(uvIndices, i)
                aiIndexedUV = arnold.AiArrayGetVec2(uvs, aiUVId)
                self.assertEqual(aiUVId, uvIds[i])
                self.assertEqual(aiUv,
                                 arnold.AtVector2(uvData[i][0], uvData[i][1]))
                self.assertEqual(
                    aiIndexedUV,
                    arnold.AtVector2(uvData[uvIds[i]][0], uvData[uvIds[i]][1]))
示例#17
0
    def testDoubleData(self):

        with IECoreArnold.UniverseBlock(writable=True):

            n = arnold.AiNode("standard")

            IECoreArnold.ParameterAlgo.setParameter(n, "Kd",
                                                    IECore.DoubleData(0.25))
            self.assertEqual(arnold.AiNodeGetFlt(n, "Kd"), 0.25)

            IECoreArnold.ParameterAlgo.setParameter(n, "customFloat",
                                                    IECore.DoubleData(0.25))
            self.assertEqual(arnold.AiNodeGetFlt(n, "customFloat"), 0.25)

            IECoreArnold.ParameterAlgo.setParameter(
                n, "customMatrix",
                IECore.M44dData(
                    IECore.M44d(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
                                15, 16)))
            m = arnold.AtMatrix()
            arnold.AiNodeGetMatrix(n, "customMatrix", m)
            self.assertEqual(
                [getattr(m, f[0]) for f in m._fields_],
                [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],
            )
示例#18
0
	def testMotion( self ) :

		c1 = IECore.CurvesPrimitive( IECore.IntVectorData( [ 4 ] ) )
		c2 = IECore.CurvesPrimitive( IECore.IntVectorData( [ 4 ] ) )

		c1["P"] = IECore.PrimitiveVariable(
			IECore.PrimitiveVariable.Interpolation.Vertex,
			IECore.V3fVectorData( [ IECore.V3f( 1 ) ] * 4 ),
		)

		c2["P"] = IECore.PrimitiveVariable(
			IECore.PrimitiveVariable.Interpolation.Vertex,
			IECore.V3fVectorData( [ IECore.V3f( 2 ) ] * 4 ),
		)

		with IECoreArnold.UniverseBlock() :

			n = IECoreArnold.NodeAlgo.convert( [ c1, c2 ], [ -0.25, 0.25 ] )

			a = arnold.AiNodeGetArray( n, "points" )
			self.assertEqual( a.contents.nelements, 4 )
			self.assertEqual( a.contents.nkeys, 2 )

			for i in range( 0, 4 ) :
				self.assertEqual( arnold.AiArrayGetPnt( a, i ), arnold.AtPoint( 1 ) )
			for i in range( 4, 8 ) :
				self.assertEqual( arnold.AiArrayGetPnt( a, i ), arnold.AtPoint( 2 ) )

			a = arnold.AiNodeGetArray( n, "deform_time_samples" )
			self.assertEqual( a.contents.nelements, 2 )
			self.assertEqual( a.contents.nkeys, 1 )
			self.assertEqual( arnold.AiArrayGetFlt( a, 0 ), -0.25 )
			self.assertEqual( arnold.AiArrayGetFlt( a, 1 ), 0.25 )
示例#19
0
    def testIndexedFaceVaryingPrimitiveVariables(self):

        m = IECoreScene.MeshPrimitive.createPlane(
            imath.Box2f(imath.V2f(-1), imath.V2f(1)),
            imath.V2i(2, 1),
        )
        self.assertEqual(
            m.variableSize(
                IECoreScene.PrimitiveVariable.Interpolation.FaceVarying), 8)

        m["myPrimVar"] = IECoreScene.PrimitiveVariable(
            IECoreScene.PrimitiveVariable.Interpolation.FaceVarying,
            IECore.FloatVectorData([5, 10]),
            IECore.IntVectorData([0, 0, 0, 0, 1, 1, 1, 1]))

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

            n = IECoreArnold.NodeAlgo.convert(m, universe, "testMesh")
            a = arnold.AiNodeGetArray(n, "myPrimVar")
            ia = arnold.AiNodeGetArray(n, "myPrimVaridxs")
            self.assertEqual(arnold.AiArrayGetNumElements(a.contents), 2)
            self.assertEqual(arnold.AiArrayGetNumElements(ia.contents), 8)

            for i in range(0, len(m["myPrimVar"].data)):
                self.assertEqual(arnold.AiArrayGetFlt(a, i),
                                 m["myPrimVar"].data[i])

            for i in range(0, len(m["myPrimVar"].indices)):
                self.assertEqual(arnold.AiArrayGetUInt(ia, i),
                                 m["myPrimVar"].indices[i])
示例#20
0
    def testSampleDeduplication(self):

        camera = IECoreScene.Camera()
        camera.setProjection("perspective")

        with IECoreArnold.UniverseBlock(writable=True):

            animatedNode = IECoreArnold.NodeAlgo.convert([camera, camera], 1.0,
                                                         2.0, "samples")
            node = IECoreArnold.NodeAlgo.convert(camera, "sample")

            for parameter in [
                    "screen_window_min",
                    "screen_window_max",
                    "fov",
                    "aperture_size",
                    "focus_distance",
            ]:

                if parameter.startswith("screen_"):
                    self.assertEqual(
                        arnold.AiNodeGetVec2(animatedNode, parameter).x,
                        arnold.AiNodeGetVec2(node, parameter).x)
                    self.assertEqual(
                        arnold.AiNodeGetVec2(animatedNode, parameter).y,
                        arnold.AiNodeGetVec2(node, parameter).y)
                else:
                    self.assertEqual(
                        arnold.AiNodeGetFlt(animatedNode, parameter),
                        arnold.AiNodeGetFlt(node, parameter))

                array = arnold.AiNodeGetArray(animatedNode, parameter)
                self.assertEqual(arnold.AiArrayGetNumElements(array), 1)
                self.assertEqual(arnold.AiArrayGetNumKeys(array), 1)
示例#21
0
    def testIndexedUniformPrimitiveVariables(self):

        # We expect uniform indexed variables to be expanded out fully
        # when converting to Arnold, because Arnold only supports indexing
        # for FaceVarying variables.

        m = IECoreScene.MeshPrimitive.createPlane(
            imath.Box2f(imath.V2f(-1), imath.V2f(1)),
            imath.V2i(4, 1),
        )
        self.assertEqual(
            m.variableSize(
                IECoreScene.PrimitiveVariable.Interpolation.Uniform), 4)

        m["myPrimVar"] = IECoreScene.PrimitiveVariable(
            IECoreScene.PrimitiveVariable.Interpolation.Uniform,
            IECore.FloatVectorData([5, 10]), IECore.IntVectorData([0, 1, 0,
                                                                   1]))

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

            n = IECoreArnold.NodeAlgo.convert(m, universe, "testMesh")

            self.assertEqual(
                arnold.AiNodeLookUpUserParameter(n, "myPrimVaridxs"), None)

            a = arnold.AiNodeGetArray(n, "myPrimVar")
            self.assertEqual(arnold.AiArrayGetNumElements(a.contents), 4)

            for i in range(0, 4):
                self.assertEqual(
                    arnold.AiArrayGetFlt(a, i),
                    m["myPrimVar"].data[m["myPrimVar"].indices[i]])
示例#22
0
	def testAdaptors( self ) :

		sphere = GafferScene.Sphere()

		def a() :

			result = GafferArnold.ArnoldAttributes()
			result["attributes"]["matte"]["enabled"].setValue( True )
			result["attributes"]["matte"]["value"].setValue( True )

			return result

		GafferScene.RendererAlgo.registerAdaptor( "Test", a )

		sphere = GafferScene.Sphere()

		render = GafferArnold.ArnoldRender()
		render["in"].setInput( sphere["out"] )
		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" )
			node = arnold.AiNodeLookUpByName( "/sphere" )

			self.assertEqual( arnold.AiNodeGetBool( node, "matte" ), True )
示例#23
0
    def testColor4fVectorDataPrimimitiveVariable(self):

        m = IECoreScene.MeshPrimitive.createPlane(
            imath.Box2f(imath.V2f(-1), imath.V2f(1)))
        m["myColor"] = IECoreScene.PrimitiveVariable(
            IECoreScene.PrimitiveVariable.Interpolation.Vertex,
            IECore.Color4fVectorData([
                imath.Color4f(1, 0, 0, 1),
                imath.Color4f(0, 2, 0, 0),
                imath.Color4f(0, 0, 3, 0.25),
                imath.Color4f(4, 0, 0, 1),
            ]))

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

            n = IECoreArnold.NodeAlgo.convert(m, universe, "testMesh")
            a = arnold.AiNodeGetArray(n, "myColor")

            self.assertEqual(arnold.AiArrayGetType(a.contents),
                             arnold.AI_TYPE_RGBA)
            self.assertEqual(arnold.AiArrayGetNumElements(a.contents), 4)

            self.assertEqual(arnold.AiArrayGetRGBA(a, 0),
                             arnold.AtRGBA(1, 0, 0, 1))
            self.assertEqual(arnold.AiArrayGetRGBA(a, 1),
                             arnold.AtRGBA(0, 2, 0, 0))
            self.assertEqual(arnold.AiArrayGetRGBA(a, 2),
                             arnold.AtRGBA(0, 0, 3, 0.25))
            self.assertEqual(arnold.AiArrayGetRGBA(a, 3),
                             arnold.AtRGBA(4, 0, 0, 1))
示例#24
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")
示例#25
0
    def testIndexedUVs(self):

        m = IECoreScene.MeshPrimitive.createPlane(
            imath.Box2f(imath.V2f(-1), imath.V2f(1)))
        uvData = m["uv"].data
        uvIds = m["uv"].indices

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

            n = IECoreArnold.NodeAlgo.convert(m, universe, "testMesh")

            uvs = arnold.AiNodeGetArray(n, "uvlist")
            self.assertEqual(arnold.AiArrayGetNumElements(uvs.contents), 4)

            uvIndices = arnold.AiNodeGetArray(n, "uvidxs")
            self.assertEqual(arnold.AiArrayGetNumElements(uvIndices.contents),
                             4)

            for i in range(0, 4):
                aiUv = arnold.AiArrayGetVec2(uvs, i)
                aiUVId = arnold.AiArrayGetInt(uvIndices, i)
                aiIndexedUV = arnold.AiArrayGetVec2(uvs, aiUVId)
                self.assertEqual(aiUVId, uvIds[i])
                self.assertEqual(aiUv,
                                 arnold.AtVector2(uvData[i][0], uvData[i][1]))
                self.assertEqual(
                    aiIndexedUV,
                    arnold.AtVector2(uvData[uvIds[i]][0], uvData[uvIds[i]][1]))
示例#26
0
    def testIntData(self):

        with IECoreArnold.UniverseBlock(writable=True):

            n = arnold.AiNode("standard_surface")
            IECoreArnold.ParameterAlgo.setParameter(n, "customInt",
                                                    IECore.IntData(42))
            IECoreArnold.ParameterAlgo.setParameter(n, "customUInt",
                                                    IECore.UIntData(43))
            IECoreArnold.ParameterAlgo.setParameter(
                n, "customIntVectorData", IECore.IntVectorData([5, 6, 7]))
            IECoreArnold.ParameterAlgo.setParameter(
                n, "customUIntVectorData",
                IECore.UIntVectorData([12, 2147483649]))

            self.assertEqual(arnold.AiNodeGetInt(n, "customInt"), 42)
            self.assertEqual(arnold.AiNodeGetUInt(n, "customUInt"), 43)
            a = arnold.AiNodeGetArray(n, "customIntVectorData")
            self.assertEqual(arnold.AiArrayGetNumElements(a.contents), 3)
            self.assertEqual(arnold.AiArrayGetInt(a, 0), 5)
            self.assertEqual(arnold.AiArrayGetInt(a, 1), 6)
            self.assertEqual(arnold.AiArrayGetInt(a, 2), 7)
            a = arnold.AiNodeGetArray(n, "customUIntVectorData")
            self.assertEqual(arnold.AiArrayGetNumElements(a.contents), 2)
            self.assertEqual(arnold.AiArrayGetUInt(a, 0), 12)
            self.assertEqual(arnold.AiArrayGetUInt(a, 1), 2147483649)
示例#27
0
	def testFrameAndAASeed( self ) :

		options = GafferArnold.ArnoldOptions()

		render = GafferArnold.ArnoldRender()
		render["in"].setInput( options["out"] )
		render["mode"].setValue( render.Mode.SceneDescriptionMode )
		render["fileName"].setValue( self.temporaryDirectory() + "/test.ass" )

		for frame in ( 1, 2, 2.8, 3.2 ) :
			for seed in ( None, 3, 4 ) :
				with Gaffer.Context() as c :

					c.setFrame( frame )

					options["options"]["aaSeed"]["enabled"].setValue( seed is not None )
					options["options"]["aaSeed"]["value"].setValue( seed or 1 )

					render["task"].execute()

					with IECoreArnold.UniverseBlock( writable = True ) :

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

						self.assertEqual(
							arnold.AiNodeGetInt( arnold.AiUniverseGetOptions(), "AA_seed" ),
							seed or round( frame )
						)
示例#28
0
    def testMode(self):

        with IECoreArnold.UniverseBlock(writable=True):

            p = IECore.PointsPrimitive(
                IECore.V3fVectorData([IECore.V3f(i) for i in range(0, 10)]))

            n = IECoreArnold.NodeAlgo.convert(p)
            self.assertEqual(arnold.AiNodeGetStr(n, "mode"), "disk")

            p["type"] = IECore.PrimitiveVariable(
                IECore.PrimitiveVariable.Interpolation.Constant, "particle")
            n = IECoreArnold.NodeAlgo.convert(p)
            self.assertEqual(arnold.AiNodeGetStr(n, "mode"), "disk")

            p["type"] = IECore.PrimitiveVariable(
                IECore.PrimitiveVariable.Interpolation.Constant, "disk")
            n = IECoreArnold.NodeAlgo.convert(p)
            self.assertEqual(arnold.AiNodeGetStr(n, "mode"), "disk")

            p["type"] = IECore.PrimitiveVariable(
                IECore.PrimitiveVariable.Interpolation.Constant, "sphere")
            n = IECoreArnold.NodeAlgo.convert(p)
            self.assertEqual(arnold.AiNodeGetStr(n, "mode"), "sphere")

            p["type"] = IECore.PrimitiveVariable(
                IECore.PrimitiveVariable.Interpolation.Constant, "patch")
            n = IECoreArnold.NodeAlgo.convert(p)
            self.assertEqual(arnold.AiNodeGetStr(n, "mode"), "quad")
示例#29
0
def appendShaders(menuDefinition, prefix="/Arnold"):

    with IECoreArnold.UniverseBlock():

        it = arnold.AiUniverseGetNodeEntryIterator(arnold.AI_NODE_SHADER
                                                   | arnold.AI_NODE_LIGHT)

        while not arnold.AiNodeEntryIteratorFinished(it):

            nodeEntry = arnold.AiNodeEntryIteratorGetNext(it)
            shaderName = arnold.AiNodeEntryGetName(nodeEntry)
            displayName = " ".join(
                [IECore.CamelCase.toSpaced(x) for x in shaderName.split("_")])

            if arnold.AiNodeEntryGetType(nodeEntry) == arnold.AI_NODE_SHADER:
                menuPath = prefix + "/Shader/" + displayName
                nodeType = GafferArnold.ArnoldShader
            else:
                menuPath = prefix + "/Light/" + displayName
                nodeType = GafferArnold.ArnoldLight

            menuDefinition.append(
                menuPath, {
                    "command":
                    GafferUI.NodeMenu.nodeCreatorWrapper(
                        IECore.curry(__shaderCreator, shaderName, nodeType)),
                })

        arnold.AiNodeEntryIteratorDestroy(it)

        arnold.AiEnd()
示例#30
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))