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)
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))
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]))
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 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 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 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 testConstantArrayPrimitiveVariable( self ) : p = IECore.PointsPrimitive( IECore.V3fVectorData( 10 ) ) p["myPrimVar"] = IECore.PrimitiveVariable( IECore.PrimitiveVariable.Interpolation.Constant, IECore.IntVectorData( range( 0, 10 ) ) ) with IECoreArnold.UniverseBlock( writable = True ) : n = IECoreArnold.NodeAlgo.convert( p ) a = arnold.AiNodeGetArray( n, "myPrimVar" ) self.assertEqual( a.contents.nelements, 10 ) for i in range( 0, 10 ) : self.assertEqual( arnold.AiArrayGetInt( a, i ), i )
def testUniformPrimitiveVariable( self ) : p = IECore.PointsPrimitive( IECore.V3fVectorData( 10 ) ) p["myPrimVar"] = IECore.PrimitiveVariable( IECore.PrimitiveVariable.Interpolation.Uniform, IECore.IntVectorData( range( 0, 10 ) ) ) with IECoreArnold.UniverseBlock() : n = IECoreArnold.ToArnoldPointsConverter( p ).convert() a = arnold.AiNodeGetArray( n, "user:myPrimVar" ) self.assertEqual( a.contents.nelements, 10 ) for i in range( 0, 10 ) : self.assertEqual( arnold.AiArrayGetInt( a, i ), i )
def testVertexPrimitiveVariable( self ) : for interpolation in ( "Vertex", "Varying", "FaceVarying" ) : p = IECore.PointsPrimitive( IECore.V3fVectorData( 10 ) ) p["myPrimVar"] = IECore.PrimitiveVariable( getattr( IECore.PrimitiveVariable.Interpolation, interpolation ), IECore.IntVectorData( range( 0, 10 ) ) ) self.assertTrue( p.arePrimitiveVariablesValid() ) with IECoreArnold.UniverseBlock( writable = True ) : n = IECoreArnold.NodeAlgo.convert( p ) a = arnold.AiNodeGetArray( n, "myPrimVar" ) self.assertEqual( a.contents.nelements, 10 ) for i in range( 0, 10 ) : self.assertEqual( arnold.AiArrayGetInt( a, i ), i )
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 ) uvs = arnold.AiNodeGetArray( n, "uvlist" ) self.assertEqual( uvs.contents.nelements, 4 ) uvIndices = arnold.AiNodeGetArray( n, "uvidxs" ) self.assertEqual( uvIndices.contents.nelements, 4 ) for i in range( 0, 4 ) : p = arnold.AiArrayGetPnt2( uvs, i ) self.assertEqual( arnold.AiArrayGetPnt2( uvs, i ), arnold.AtPoint2( uvData[i][0], uvData[i][1] ) ) self.assertEqual( arnold.AiArrayGetInt( uvIndices, i ), i )
def testAdditionalUVs(self): m = IECore.MeshPrimitive.createPlane( IECore.Box2f(IECore.V2f(-1), IECore.V2f(1))) m["myMap_s"] = m["s"] m["myMap_t"] = m["t"] s, t = m["s"].data, m["t"].data with IECoreArnold.UniverseBlock(): n = IECoreArnold.NodeAlgo.convert(m) uvs = arnold.AiNodeGetArray(n, "myMap") self.assertEqual(uvs.contents.nelements, 4) uvIndices = arnold.AiNodeGetArray(n, "myMapidxs") self.assertEqual(uvIndices.contents.nelements, 4) for i in range(0, 4): p = arnold.AiArrayGetPnt2(uvs, i) self.assertEqual(arnold.AiArrayGetPnt2(uvs, i), arnold.AtPoint2(s[i], 1 - t[i])) self.assertEqual(arnold.AiArrayGetInt(uvIndices, i), i)