Beispiel #1
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]))
    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])
    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)
    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]))
Beispiel #5
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)
Beispiel #6
0
	def testMotion( self ) :

		p1 = IECoreScene.PointsPrimitive( IECore.V3fVectorData( [ imath.V3f( 10 ) ] * 10 ) )
		p1["width"] = IECoreScene.PrimitiveVariable(
			IECoreScene.PrimitiveVariable.Interpolation.Vertex,
			IECore.FloatVectorData( [ 1 ] * 10 ),
		)

		p2 = IECoreScene.PointsPrimitive( IECore.V3fVectorData( [ imath.V3f( 20 ) ] * 10 ) )
		p2["width"] = IECoreScene.PrimitiveVariable(
			IECoreScene.PrimitiveVariable.Interpolation.Vertex,
			IECore.FloatVectorData( [ 2 ] * 10 ),
		)

		with IECoreArnold.UniverseBlock( writable = True ) :

			n = IECoreArnold.NodeAlgo.convert( [ p1, p2 ], -0.25, 0.25, "testPoints" )

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

			r = arnold.AiNodeGetArray( n, "radius" )
			self.assertEqual( arnold.AiArrayGetNumElements( r.contents ), 10 )
			self.assertEqual( arnold.AiArrayGetNumKeys( r.contents ), 2 )

			for i in range( 0, 10 ) :
				self.assertEqual( arnold.AiArrayGetVec( a, i ), arnold.AtVector( 10 ) )
				self.assertEqual( arnold.AiArrayGetFlt( r, i ), 0.5 )
			for i in range( 11, 20 ) :
				self.assertEqual( arnold.AiArrayGetVec( a, i ), arnold.AtVector( 20 ) )
				self.assertEqual( arnold.AiArrayGetFlt( r, i ), 1 )

			self.assertEqual( arnold.AiNodeGetFlt( n, "motion_start" ), -0.25 )
			self.assertEqual( arnold.AiNodeGetFlt( n, "motion_end" ), 0.25 )
    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])
    def testExpandVertexIndexedUVs(self):

        vertsPerFace = IECore.IntVectorData([4, 4])
        vertexIds = IECore.IntVectorData([0, 1, 4, 3, 1, 2, 5, 4])
        positions = IECore.V3fVectorData([
            imath.V3f(0, 0, 0),
            imath.V3f(1, 0, 0),
            imath.V3f(2, 0, 0),
            imath.V3f(0, 1, 0),
            imath.V3f(1, 1, 0),
            imath.V3f(2, 1, 0)
        ])

        m = IECoreScene.MeshPrimitive(vertsPerFace, vertexIds, "linear",
                                      positions)
        m["uv"] = IECoreScene.PrimitiveVariable(
            IECoreScene.PrimitiveVariable.Interpolation.Vertex,
            IECore.V2fVectorData([
                imath.V2f(0, 0),
                imath.V2f(1, 0),
                imath.V2f(0, 1),
                imath.V2f(1, 1)
            ], IECore.GeometricData.Interpretation.UV),
            IECore.IntVectorData([0, 1, 1, 2, 3, 3]))

        self.assertTrue(m.arePrimitiveVariablesValid())

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

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

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

            self.assertEqual(arnold.AiArrayGetVec2(uvArray, 0),
                             arnold.AtVector2(0, 0))
            self.assertEqual(arnold.AiArrayGetVec2(uvArray, 1),
                             arnold.AtVector2(1, 0))
            self.assertEqual(arnold.AiArrayGetVec2(uvArray, 2),
                             arnold.AtVector2(0, 1))
            self.assertEqual(arnold.AiArrayGetVec2(uvArray, 3),
                             arnold.AtVector2(1, 1))

            uvIndicesArray = arnold.AiNodeGetArray(n, "uvidxs")
            self.assertEqual(
                arnold.AiArrayGetNumElements(uvIndicesArray.contents), 8)

            self.assertEqual(arnold.AiArrayGetInt(uvIndicesArray, 0), 0)
            self.assertEqual(arnold.AiArrayGetInt(uvIndicesArray, 1), 1)
            self.assertEqual(arnold.AiArrayGetInt(uvIndicesArray, 2), 3)
            self.assertEqual(arnold.AiArrayGetInt(uvIndicesArray, 3), 2)

            self.assertEqual(arnold.AiArrayGetInt(uvIndicesArray, 4), 1)
            self.assertEqual(arnold.AiArrayGetInt(uvIndicesArray, 5), 1)
            self.assertEqual(arnold.AiArrayGetInt(uvIndicesArray, 6), 3)
            self.assertEqual(arnold.AiArrayGetInt(uvIndicesArray, 7), 3)
    def testConvertShutterCurve(self):

        with IECoreArnold.UniverseBlock(writable=True):

            camera = IECoreScene.Camera()
            camera.setProjection("perspective")
            camera.parameters()["shutter_curve"] = IECore.Splineff(
                IECore.CubicBasisf.linear(),
                [
                    (0, -0.1),
                    (0.25, 1),
                    (0.75, 1.1),
                    (1.1, 0),
                ],
            )

            node = IECoreArnold.NodeAlgo.convert(camera, "camera")
            curve = arnold.AiNodeGetArray(node, "shutter_curve")
            self.assertEqual(arnold.AiArrayGetNumElements(curve), 4)
            self.assertEqual(arnold.AiArrayGetVec2(curve, 0),
                             arnold.AtVector2(0, 0))
            self.assertEqual(arnold.AiArrayGetVec2(curve, 1),
                             arnold.AtVector2(0.25, 1))
            self.assertEqual(arnold.AiArrayGetVec2(curve, 2),
                             arnold.AtVector2(0.75, 1))
            self.assertEqual(arnold.AiArrayGetVec2(curve, 3),
                             arnold.AtVector2(1, 0))

            camera.parameters()["shutter_curve"] = IECore.Splineff(
                IECore.CubicBasisf.catmullRom(),
                [
                    (0, 0),
                    (0, 0),
                    (0.25, 1),
                    (0.75, 1),
                    (1, 0),
                    (1, 0),
                ],
            )

            node = IECoreArnold.NodeAlgo.convert(camera, "camera")
            curve = arnold.AiNodeGetArray(node, "shutter_curve")
            self.assertEqual(arnold.AiArrayGetNumElements(curve), 25)
            for i in range(0, 25):
                point = arnold.AiArrayGetVec2(curve, i)
                self.assertAlmostEqual(min(
                    camera.parameters()["shutter_curve"].value(point.x), 1),
                                       point.y,
                                       delta=0.0001)
Beispiel #10
0
	def testNPrimitiveVariable( self ) :

		c = IECore.CurvesPrimitive( IECore.IntVectorData( [ 4 ] ), IECore.CubicBasisf.catmullRom() )
		c["P"] = IECore.PrimitiveVariable(
			IECore.PrimitiveVariable.Interpolation.Vertex,
			IECore.V3fVectorData( [ IECore.V3f( x, 0, 0 ) for x in range( 0, 4 ) ] )
		)

		with IECoreArnold.UniverseBlock( writable = True ) :

			# No N - should be a ribbon

			n = IECoreArnold.NodeAlgo.convert( c, "testCurve" )
			self.assertEqual( arnold.AiNodeGetStr( n, "mode" ), "ribbon" )
			self.assertEqual( arnold.AiArrayGetNumElements( arnold.AiNodeGetArray( n, "orientations" ).contents ), 0 )

			# N - should be oriented

			c["N"] = IECore.PrimitiveVariable(
				IECore.PrimitiveVariable.Interpolation.Vertex,
				IECore.V3fVectorData( [ IECore.V3f( 0, math.sin( x ), math.cos( x ) ) for x in range( 0, 4 ) ] )
			)

			n = IECoreArnold.NodeAlgo.convert( c, "testCurve" )
			self.assertEqual( arnold.AiNodeGetStr( n, "mode" ), "oriented" )
			orientations = arnold.AiNodeGetArray( n, "orientations" )
			self.assertEqual( arnold.AiArrayGetNumElements( orientations.contents ), 4 )

			for i in range( 0, 4 ) :
				self.assertEqual( arnold.AiArrayGetVec( orientations, i ), arnold.AtVector( 0, math.sin( i ), math.cos( i ) ) )

			# Motion blurred N - should be oriented and deforming

			c2 = c.copy()
			c2["N"] = IECore.PrimitiveVariable(
				IECore.PrimitiveVariable.Interpolation.Vertex,
				IECore.V3fVectorData( [ IECore.V3f( 0, math.sin( x + 0.2 ), math.cos( x + 0.2 ) ) for x in range( 0, 4 ) ] )
			)

			n = IECoreArnold.NodeAlgo.convert( [ c, c2 ], 0.0, 1.0, "testCurve" )
			self.assertEqual( arnold.AiNodeGetStr( n, "mode" ), "oriented" )

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

			for i in range( 0, 4 ) :
				self.assertEqual( arnold.AiArrayGetVec( orientations, i ), arnold.AtVector( 0, math.sin( i ), math.cos( i ) ) )
				self.assertEqual( arnold.AiArrayGetVec( orientations, i + 4 ), arnold.AtVector( 0, math.sin( i + 0.2 ), math.cos( i + 0.2 ) ) )
Beispiel #11
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")
Beispiel #12
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))
Beispiel #13
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)
Beispiel #14
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))
Beispiel #15
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)
Beispiel #16
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]])
Beispiel #17
0
    def testNormals(self):

        m = IECoreScene.MeshPrimitive.createPlane(
            imath.Box2f(imath.V2f(-0.9), imath.V2f(0.9)))
        m["N"] = IECoreScene.PrimitiveVariable(
            IECoreScene.PrimitiveVariable.Interpolation.Vertex,
            IECore.V3fVectorData([
                imath.V3f(1, 0, 0),
                imath.V3f(1, 0, 0),
                imath.V3f(1, 0, 0),
                imath.V3f(1, 0, 0)
            ]))

        mFaceVaryingIndexed = IECoreScene.MeshPrimitive.createBox(
            imath.Box3f(imath.V3f(-0.9), imath.V3f(0.9)))

        mVertexIndexed = IECoreScene.MeshPrimitive.createPlane(
            imath.Box2f(imath.V2f(-0.9), imath.V2f(0.9)), imath.V2i(3))
        mVertexIndexed["N"] = IECoreScene.PrimitiveVariable(
            IECoreScene.PrimitiveVariable.Interpolation.Vertex,
            IECore.V3fVectorData([imath.V3f(1, 0, 0),
                                  imath.V3f(-1, 0, 0)]),
            IECore.IntVectorData([0] * 8 + [1] * 8))

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

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

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

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

            n = IECoreArnold.NodeAlgo.convert(mFaceVaryingIndexed, universe,
                                              "testMesh2")
            normals = arnold.AiNodeGetArray(n, "nlist")
            normalIndices = arnold.AiNodeGetArray(n, "nidxs")

            refNormals = [(0, 0, -1), (1, 0, 0), (0, 0, 1), (-1, 0, 0),
                          (0, 1, 0), (0, -1, 0)]
            for i in range(0, 24):
                self.assertEqual(
                    arnold.AiArrayGetVec(
                        normals, arnold.AiArrayGetInt(normalIndices, i)),
                    arnold.AtVector(*refNormals[i // 4]))

            n = IECoreArnold.NodeAlgo.convert(mVertexIndexed, universe,
                                              "testMesh3")
            normals = arnold.AiNodeGetArray(n, "nlist")
            normalIndices = arnold.AiNodeGetArray(n, "nidxs")
            for i in range(0, 36):
                s = [0, (i // 2) % 2, 1][i // 12]
                self.assertEqual(
                    arnold.AiArrayGetVec(
                        normals, arnold.AiArrayGetInt(normalIndices, i)),
                    arnold.AtVector(-1 if s else 1, 0, 0))
Beispiel #18
0
	def __arrayToSet( self, a ) :

		result = set()
		for i in range( 0,  arnold.AiArrayGetNumElements( a.contents ) ) :
			if arnold.AiArrayGetType( a.contents ) == arnold.AI_TYPE_STRING :
				result.add( arnold.AiArrayGetStr( a, i ) )
			else :
				raise TypeError

		return result
Beispiel #19
0
    def testLightFiltersMany(self):

        # \todo: this can easily be turned into a performance test

        s = Gaffer.ScriptNode()

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

        s["planeFilters"] = GafferScene.Plane("Plane")
        s["planeFilters"]["divisions"].setValue(imath.V2i(9))

        s["instancerFilters"] = GafferScene.Instancer("Instancer")
        s["instancerFilters"]["in"].setInput(s["planeFilters"]["out"])
        s["instancerFilters"]["instances"].setInput(s["lightFilter"]["out"])
        s["instancerFilters"]["parent"].setValue("/plane")

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

        s["planeLights"] = GafferScene.Plane("Plane")
        s["planeLights"]["divisions"].setValue(imath.V2i(9))

        s["instancerLights"] = GafferScene.Instancer("Instancer")
        s["instancerLights"]["in"].setInput(s["planeLights"]["out"])
        s["instancerLights"]["instances"].setInput(s["light"]["out"])
        s["instancerLights"]["parent"].setValue("/plane")

        s["group"] = GafferScene.Group("Group")
        s["group"]["in"][0].setInput(s["instancerFilters"]["out"])
        s["group"]["in"][1].setInput(s["instancerLights"]["out"])

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

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

        with IECoreArnold.UniverseBlock(writable=True):

            foo = self.temporaryDirectory() + "/testMany.ass"
            print foo
            arnold.AiASSLoad(foo)

            for i in range(100):
                light = arnold.AiNodeLookUpByName(
                    "light:/group/plane1/instances/light/%s" % i)
                linkedFilters = arnold.AiNodeGetArray(light, "filters")
                numFilters = arnold.AiArrayGetNumElements(
                    linkedFilters.contents)

                self.assertEqual(numFilters, 100)
Beispiel #20
0
	def testStringArray( self ) :

		with IECoreArnold.UniverseBlock( writable = True ) :

			n = arnold.AiNode( "polymesh" )
			IECoreArnold.ParameterAlgo.setParameter( n, "trace_sets", IECore.StringVectorData( [ "a", "b" ] ) )

			a = arnold.AiNodeGetArray( n, "trace_sets" )
			self.assertEqual( arnold.AiArrayGetNumElements( a.contents ), 2 )
			self.assertEqual( arnold.AiArrayGetStr( a, 0 ), "a" )
			self.assertEqual( arnold.AiArrayGetStr( a, 1 ), "b" )
Beispiel #21
0
	def testConstantArrayPrimitiveVariable( self ) :

		p = IECoreScene.PointsPrimitive( IECore.V3fVectorData( 10 ) )
		p["myPrimVar"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Constant, IECore.IntVectorData( range( 0, 10 ) ) )

		with IECoreArnold.UniverseBlock( writable = True ) :

			n = IECoreArnold.NodeAlgo.convert( p, "testPoints" )
			a = arnold.AiNodeGetArray( n, "myPrimVar" )
			self.assertEqual( arnold.AiArrayGetNumElements( a.contents ), 10 )
			for i in range( 0, 10 ) :
				self.assertEqual( arnold.AiArrayGetInt( a, i ), i )
Beispiel #22
0
    def testMotion(self):

        m1 = IECore.MeshPrimitive.createPlane(
            IECore.Box2f(IECore.V2f(-1), IECore.V2f(1)))
        IECore.MeshNormalsOp()(input=m1, copyInput=False)

        m2 = m1.copy()
        m2["P"].data[0] -= IECore.V3f(0, 0, 1)
        m2["P"].data[1] -= IECore.V3f(0, 0, 1)
        IECore.MeshNormalsOp()(input=m2, copyInput=False)

        with IECoreArnold.UniverseBlock(writable=True):

            node = IECoreArnold.NodeAlgo.convert([m1, m2], -0.25, 0.25,
                                                 "testMesh")

            vList = arnold.AiNodeGetArray(node, "vlist")
            self.assertEqual(arnold.AiArrayGetNumElements(vList.contents), 4)
            self.assertEqual(arnold.AiArrayGetNumKeys(vList.contents), 2)

            nList = arnold.AiNodeGetArray(node, "nlist")
            self.assertEqual(arnold.AiArrayGetNumElements(nList.contents), 4)
            self.assertEqual(arnold.AiArrayGetNumKeys(nList.contents), 2)

            for i in range(0, 4):
                p = arnold.AiArrayGetVec(vList, i)
                self.assertEqual(IECore.V3f(p.x, p.y, p.z), m1["P"].data[i])
                n = arnold.AiArrayGetVec(nList, i)
                self.assertEqual(IECore.V3f(n.x, n.y, n.z), m1["N"].data[i])

            for i in range(4, 8):
                p = arnold.AiArrayGetVec(vList, i)
                self.assertEqual(IECore.V3f(p.x, p.y, p.z),
                                 m2["P"].data[i - 4])
                n = arnold.AiArrayGetVec(nList, i)
                self.assertEqual(IECore.V3f(n.x, n.y, n.z),
                                 m2["N"].data[i - 4])

            self.assertEqual(arnold.AiNodeGetFlt(node, "motion_start"), -0.25)
            self.assertEqual(arnold.AiNodeGetFlt(node, "motion_end"), 0.25)
Beispiel #23
0
    def testUVs(self):

        m = IECore.MeshPrimitive.createPlane(
            IECore.Box2f(IECore.V2f(-1), IECore.V2f(1)))
        uvData = m["uv"].data

        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):
                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)
Beispiel #24
0
    def testFaceVaryingPrimitiveVariables(self):

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

        m["myPrimVar"] = IECoreScene.PrimitiveVariable(
            IECoreScene.PrimitiveVariable.Interpolation.FaceVarying,
            IECore.FloatVectorData(range(0, 16)))

        with IECoreArnold.UniverseBlock(writable=True):

            n = IECoreArnold.NodeAlgo.convert(m, "testMesh")
            a = arnold.AiNodeGetArray(n, "myPrimVar")
            ia = arnold.AiNodeGetArray(n, "myPrimVaridxs")
            self.assertEqual(arnold.AiArrayGetNumElements(a.contents), 16)
            self.assertEqual(arnold.AiArrayGetNumElements(ia.contents), 16)
            for i in range(0, 16):
                self.assertEqual(arnold.AiArrayGetFlt(a, i), i)
                self.assertEqual(arnold.AiArrayGetUInt(ia, i), i)
Beispiel #25
0
    def testNoLinkedLightsOnLights(self):

        sphere = GafferScene.Sphere()

        meshLightShader = GafferArnold.ArnoldShader()
        meshLightShader.loadShader("flat")

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

        meshLight = GafferArnold.ArnoldMeshLight()
        meshLight["in"].setInput(sphere["out"])
        meshLight["filter"].setInput(meshLightFilter["out"])
        meshLight["parameters"]["color"].setInput(meshLightShader["out"])

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

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

        # Trigger light linking by unlinking a light
        light2["defaultLight"].setValue(False)

        group = GafferScene.Group()

        group["in"][0].setInput(meshLight["out"])
        group["in"][1].setInput(light1["out"])
        group["in"][2].setInput(light2["out"])

        render = GafferArnold.ArnoldRender()
        render["in"].setInput(group["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")

            sphere = arnold.AiNodeLookUpByName("/group/sphere")
            self.assertIsNotNone(sphere)

            self.assertEqual(
                arnold.AiArrayGetNumElements(
                    arnold.AiNodeGetArray(sphere, "light_group")), 0)
            self.assertFalse(arnold.AiNodeGetBool(sphere, "use_light_group"))
Beispiel #26
0
	def testVertexPrimitiveVariable( self ) :

		for interpolation in ( "Vertex", "Varying", "FaceVarying" ) :

			p = IECoreScene.PointsPrimitive( IECore.V3fVectorData( 10 ) )
			p["myPrimVar"] = IECoreScene.PrimitiveVariable( getattr( IECoreScene.PrimitiveVariable.Interpolation, interpolation ), IECore.IntVectorData( range( 0, 10 ) ) )

			self.assertTrue( p.arePrimitiveVariablesValid() )

			with IECoreArnold.UniverseBlock( writable = True ) :

				n = IECoreArnold.NodeAlgo.convert( p, "testPoints" )
				a = arnold.AiNodeGetArray( n, "myPrimVar" )
				self.assertEqual( arnold.AiArrayGetNumElements( a.contents ), 10 )
				for i in range( 0, 10 ) :
					self.assertEqual( arnold.AiArrayGetInt( a, i ), i )
Beispiel #27
0
    def testBoolVectorPrimitiveVariables(self):

        m = IECoreScene.MeshPrimitive.createPlane(
            imath.Box2f(imath.V2f(-1), imath.V2f(1)))
        m["myBoolPrimVar"] = IECoreScene.PrimitiveVariable(
            IECoreScene.PrimitiveVariable.Interpolation.Vertex,
            IECore.BoolVectorData([True, False, True, False]))

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

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

            self.assertEqual(arnold.AiArrayGetNumElements(a.contents), 4)
            self.assertEqual(arnold.AiArrayGetBool(a, 0), True)
            self.assertEqual(arnold.AiArrayGetBool(a, 1), False)
            self.assertEqual(arnold.AiArrayGetBool(a, 2), True)
            self.assertEqual(arnold.AiArrayGetBool(a, 3), False)
Beispiel #28
0
    def testVertexPrimitiveVariables(self):

        m = IECoreScene.MeshPrimitive.createPlane(
            imath.Box2f(imath.V2f(-1), imath.V2f(1)))
        m["myPrimVar"] = IECoreScene.PrimitiveVariable(
            IECoreScene.PrimitiveVariable.Interpolation.Vertex,
            IECore.FloatVectorData([0, 1, 2, 3]))
        m["myV3fPrimVar"] = IECoreScene.PrimitiveVariable(
            IECoreScene.PrimitiveVariable.Interpolation.Vertex,
            IECore.V3fVectorData([imath.V3f(v) for v in range(0, 4)]))

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

            n = IECoreArnold.NodeAlgo.convert(m, universe, "testMesh")
            a = arnold.AiNodeGetArray(n, "myPrimVar")
            v = arnold.AiNodeGetArray(n, "myV3fPrimVar")
            self.assertEqual(arnold.AiArrayGetNumElements(a.contents), 4)
            for i in range(0, 4):
                self.assertEqual(arnold.AiArrayGetFlt(a, i), i)
                self.assertEqual(arnold.AiArrayGetVec(v, i), i)
Beispiel #29
0
    def testDefaultLightsMistakesDontForceLinking(self):

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

        sphere = GafferScene.Sphere()

        # It doesn't make sense to add a non-light to the "defaultLights"
        # set like this, but in the event of user error, we don't want to
        # emit light links unnecessarily.
        sphereSet = GafferScene.Set()
        sphereSet["in"].setInput(sphere["out"])
        sphereSet["name"].setValue("defaultLights")
        sphereSet["paths"].setValue(IECore.StringVectorData(["/sphere"]))

        group = GafferScene.Group()

        group["in"][0].setInput(light["out"])
        group["in"][1].setInput(sphereSet["out"])

        render = GafferArnold.ArnoldRender()
        render["in"].setInput(group["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")

            sphere = arnold.AiNodeLookUpByName("/group/sphere")
            self.assertIsNotNone(sphere)

            self.assertEqual(
                arnold.AiArrayGetNumElements(
                    arnold.AiNodeGetArray(sphere, "light_group")), 0)
            self.assertFalse(arnold.AiNodeGetBool(sphere, "use_light_group"))
Beispiel #30
0
    def testNormals(self):

        m = IECoreScene.MeshPrimitive.createPlane(
            imath.Box2f(imath.V2f(-0.9), imath.V2f(0.9)))
        m["N"] = IECoreScene.PrimitiveVariable(
            IECoreScene.PrimitiveVariable.Interpolation.Vertex,
            IECore.V3fVectorData([
                imath.V3f(1, 0, 0),
                imath.V3f(1, 0, 0),
                imath.V3f(1, 0, 0),
                imath.V3f(1, 0, 0)
            ]))

        with IECoreArnold.UniverseBlock(writable=True):

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

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

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